35 lines
945 B
TypeScript
35 lines
945 B
TypeScript
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,
|
|
};
|
|
}
|