34
apps/web/src/lib/teacher/teacher-content.ts
Normal file
34
apps/web/src/lib/teacher/teacher-content.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import type { AiFallbackReason, AiContentSource } from "@/lib/services/ai";
|
||||
import type { TeacherLessonContent } from "@adventureos/shared";
|
||||
|
||||
const META_KEY = "_meta";
|
||||
|
||||
type StoredTeacherMeta = {
|
||||
source?: AiContentSource;
|
||||
fallbackReason?: AiFallbackReason;
|
||||
};
|
||||
|
||||
export type StoredTeacherContent = TeacherLessonContent & {
|
||||
[META_KEY]?: StoredTeacherMeta;
|
||||
};
|
||||
|
||||
export function wrapTeacherContent(
|
||||
content: TeacherLessonContent,
|
||||
meta: StoredTeacherMeta
|
||||
): StoredTeacherContent {
|
||||
return { ...content, [META_KEY]: meta };
|
||||
}
|
||||
|
||||
export function unwrapTeacherContent(stored: Record<string, unknown>): {
|
||||
content: TeacherLessonContent;
|
||||
source?: AiContentSource;
|
||||
fallbackReason?: AiFallbackReason;
|
||||
} {
|
||||
const meta = stored[META_KEY] as StoredTeacherMeta | undefined;
|
||||
const { [META_KEY]: _, ...rest } = stored;
|
||||
return {
|
||||
content: rest as TeacherLessonContent,
|
||||
source: meta?.source,
|
||||
fallbackReason: meta?.fallbackReason,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user