Document editor & generation¶
When a trainer asks the chat for a lesson plan or question bank, the output opens in a dedicated two-pane editor instead of staying a read-only markdown blob in a chat bubble. The left pane is the prompt and refine controls; the right pane is an editable block document with DOCX, PDF, and Markdown export.
How it works¶
Chat stays the entry point. A trainer picks a document mode (lesson_plan, question_bank, module, or assignment), prompts, and the chatbot microservice streams the generation. An artifact card renders inline with an "Open in editor" action that routes to /documents/:id.
flowchart TD
A[Chat: pick mode + prompt] --> B[Chatbot microservice generates]
B --> C[Inline artifact card]
C -->|Open in editor| D[/documents/:id two-pane]
D --> E[Left: prompt + refine actions]
D --> F[Right: TipTap block editor]
F --> G[Edit + autosave json/html]
E --> H[Block-level refine: regenerate one block]
F --> I[Export DOCX / PDF / MD]
The editor is the existing TipTap NotionEditor configured for documents. Edits autosave as { json, html }. Block-level refine ("regenerate this question", "make it harder", "add 5 more MCQs") sends one block to the microservice and replaces it in place, so the rest of the document is untouched.
All LLM generation, including block-level refine, lives in the chatbot microservice. The FastAPI backend is a thin persistence and proxy layer: it stores documents and forwards refine requests, holding no generation prompts. Documents persist in a dedicated documents table (type, title, body_json, body_html, nullable conversation_id, owner) and reappear in a Documents list for reuse.
Document blocks support math (KaTeX), chart (Recharts), table, image, and diagram (Mermaid) kinds.
Document types¶
| Type | Behavior |
|---|---|
lesson_plan |
Free-form document, editable then exportable |
question_bank |
Editable blocks with per-question refine |
module |
Lesson/module authoring document |
assignment |
Structured and gradeable. Flow: enter details → AI generates → editor → review/edit → Publish to Assignment. Question blocks map back to Assignment.questions, settings, and targets so grading and submissions are preserved. The sidebar Assignments entry stays as the management surface. |
For B2C free tier, lesson_plan and question_bank stay Pro-gated; export is download-gated via the existing renderDownload / DownloadLockButton.
Where it lives¶
- Route:
/documents/:id; entry from/ai-tutorand/chat - Editor:
apps/web/src/components/content-editor/NotionEditor.tsxplus the AI panel - Generation proxy:
apps/backend/src/services/chatbot_client.py(stream_chat_sse) - Presentations are out of scope: they keep
/presentations/:id