// Domain models - pure types, with no framework dependency. export type ExerciseType = 'mcq' | 'true_false' | 'open'; type ExerciseDifficulty = 'easy' | 'medium' | 'hard'; type ExerciseSource = 'ai' | 'manual'; export type AiProvider = 'claude' | 'openai' | 'local'; export type UserRole = 'admin' | 'user'; // A user account. `provider` is the auth method that owns the identity // ('local' for password accounts; a strategy name like 'oidc' otherwise). // password_hash is set only for local accounts; external identities carry an // external_id instead. export interface User { id: string; username: string; password_hash: string | null; role: UserRole; provider: string; external_id: string | null; created_at: string; } // The user shape safe to hand to the client / attach to a request: never // includes the password hash. export interface PublicUser { id: string; username: string; role: UserRole; provider: string; } export interface Session { id: string; user_id: string; created_at: string; expires_at: string; } // AI configuration held server-side. The apiKey is never sent to the client; // the API exposes only `hasKey`. export interface AiSettings { enabled: boolean; provider: AiProvider; model: string; apiKey: string; baseUrl: string; // for the OpenAI-compatible local provider } export interface DocumentRow { id: string; user_id: string | null; original_name: string; filename: string; filepath: string; extracted_text: string | null; page_count: number | null; uploaded_at: string; render_path: string | null; content_hash?: string | null; render_hash?: string | null; text_hash?: string | null; } // The shape generation answers with; rows are inserted into the clients' // workspace docs, never into a server table. export interface Exercise { id: string; document_id: string | null; course_id: string; topic_id: string | null; type: ExerciseType; question: string; options: string | null; // JSON string of a string[] correct_answer: string; explanation: string | null; difficulty: ExerciseDifficulty; source: ExerciseSource; created_at: string; } // Upload formats beyond PDF. Office files (incl. pptx) render through // headless LibreOffice when available (docx/odt/rtf fall back to pandoc // without it; the other office formats are rejected with an install hint); // markup formats go through pandoc (see the composite converter adapter). export const CONVERTIBLE_EXTENSIONS = [ '.doc', '.pptx', '.docx', '.odt', '.odp', '.ppt', '.rtf', '.xls', '.xlsx', '.ods', '.csv', '.md', '.markdown', '.txt', '.html', '.htm', '.epub', '.tex', '.rst', '.org', '.ipynb', '.typ', ] as const; // An exercise "generated" by the AI before it is handed back to the client. export interface GeneratedExercise { type: ExerciseType; question: string; options?: string[]; correct_answer: string; explanation: string; difficulty: ExerciseDifficulty; }