Add drag reordering, exam deadlines, frozen shared quizzes, batched OCR and semantic search
All checks were successful
Verify and publish V2 container / build-and-push (push) Successful in 33s
All checks were successful
Verify and publish V2 container / build-and-push (push) Successful in 33s
- Drag-to-reorder for class materials, folders, quiz questions and deck cards. Pointer-based so touch works, plus keyboard (arrows/Home/End) with screen-reader announcements. - Timed exams get a wall-clock deadline. The server refuses late answers, submits overdue exams with what was saved, and the countdown keeps running while the page is closed. - Shared quiz sessions keep a frozen copy of their questions and flag later owner edits. - Scanned PDFs are read in cached 8-page batches with real page numbers (pdf-lib), removing the 30 MB whole-file limit. Compatible providers now receive PDFs as file parts. - Semantic search: embeddings for OpenAI, Gemini, Ollama and compatible servers, background indexing into chunk_vectors (migration 2), hybrid keyword + vector ranking for search, the assistant and focused generation, and a Settings -> AI section. 181 tests pass locally and in the Docker test stage on Node 24. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
3046e46d1c
commit
ccdad9728b
39 changed files with 1772 additions and 121 deletions
|
|
@ -375,3 +375,56 @@ describe('assistant', () => {
|
|||
expect(bogus.at(-1).type).toBe('done');
|
||||
});
|
||||
});
|
||||
|
||||
describe('reading long scanned PDFs', () => {
|
||||
async function scannedPdf(pages: number) {
|
||||
const { PDFDocument } = await import('pdf-lib');
|
||||
const doc = await PDFDocument.create();
|
||||
for (let i = 0; i < pages; i++) doc.addPage([612, 792]);
|
||||
return doc.save();
|
||||
}
|
||||
const ocrCalls = () => mock.requests.filter((r) => r.path.endsWith('/chat/completions') && JSON.stringify(r.body?.messages ?? '').includes('Transcribe this study material'));
|
||||
|
||||
it('reads the PDF in page batches, keeps real page numbers and caches finished batches', async () => {
|
||||
const { models } = await connectAi();
|
||||
for (const m of models) await t.api('PATCH', `/api/ai/models/${m.id}`, { capabilities: { vision: true, pdf: true } });
|
||||
const cls = (await t.api('POST', '/api/classes', { name: 'Med-Surg' })).body.class;
|
||||
|
||||
const up = await upload(cls.id, 'scanned-textbook.pdf', await scannedPdf(20), 'application/pdf');
|
||||
expect(up.status).toBe(201);
|
||||
const id = up.body.documents[0].id;
|
||||
const doc = (await t.api('GET', `/api/documents/${id}`)).body.document;
|
||||
expect(doc).toMatchObject({ status: 'ready', needsOcr: false, pageCount: 20 });
|
||||
|
||||
// 20 pages at 8 per batch: pages 1-8, 9-16, 17-20, each sent as its own PDF.
|
||||
const calls = ocrCalls();
|
||||
expect(calls).toHaveLength(3);
|
||||
const prompts = calls.map((c) => JSON.stringify(c.body.messages));
|
||||
expect(prompts[0]).toContain('pages 1-8 of a 20-page document');
|
||||
expect(prompts[2]).toContain('pages 17-20 of a 20-page document');
|
||||
expect(prompts[1]).toContain('data:application/pdf;base64,');
|
||||
|
||||
const chunks = (await t.api('GET', `/api/documents/${id}/chunks`)).body.chunks as { text: string; pageStart: number | null; pageEnd: number | null }[];
|
||||
const text = chunks.map((c) => c.text).join('\n');
|
||||
for (const n of [1, 8, 9, 20]) expect(text).toContain(`page ${n}:`);
|
||||
expect(Math.min(...chunks.map((c) => c.pageStart ?? 99))).toBe(1);
|
||||
expect(Math.max(...chunks.map((c) => c.pageEnd ?? 0))).toBe(20);
|
||||
expect(fs.readdirSync(path.join(t.dir, 'uploads')).some((f) => f.endsWith('.ocr.json'))).toBe(true);
|
||||
|
||||
// Reprocessing without asking for a fresh read reuses the cached batches: no new AI calls.
|
||||
mock.requests.length = 0;
|
||||
await t.api('POST', `/api/documents/${id}/reprocess`, {});
|
||||
await queueIdle(t.ctx);
|
||||
expect(ocrCalls()).toHaveLength(0);
|
||||
expect((await t.api('GET', `/api/documents/${id}`)).body.document.needsOcr).toBe(false);
|
||||
|
||||
// "Read with AI" asks for a fresh read and sends every batch again.
|
||||
await t.api('POST', `/api/documents/${id}/reprocess`, { ocr: true });
|
||||
await queueIdle(t.ctx);
|
||||
expect(ocrCalls()).toHaveLength(3);
|
||||
|
||||
// Deleting the document removes the cache with the file.
|
||||
await t.api('DELETE', `/api/documents/${id}`);
|
||||
expect(fs.readdirSync(path.join(t.dir, 'uploads')).some((f) => f.endsWith('.ocr.json'))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue