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
|
|
@ -37,6 +37,7 @@ import {
|
|||
updateQuestion,
|
||||
} from '../services/content.ts';
|
||||
import { chunkById, formatExcerpts, searchChunks, selectContext, sourceLabel, type ChunkHit } from '../services/documents.ts';
|
||||
import { hybridSearch } from '../services/semantic.ts';
|
||||
import { weakTopics } from '../services/stats.ts';
|
||||
import { newId, now, parseJson } from '../util.ts';
|
||||
import { generateStructured, resolveModel, runChat } from './service.ts';
|
||||
|
|
@ -403,7 +404,7 @@ interface Sources {
|
|||
totalTokens: number;
|
||||
}
|
||||
|
||||
function gatherSources(app: AppContext, req: GenerateRequest, budgetTokens: number, groups: number): Sources {
|
||||
async function gatherSources(app: AppContext, req: GenerateRequest, budgetTokens: number, groups: number): Promise<Sources> {
|
||||
const { db } = app;
|
||||
const src = req.source;
|
||||
const out: Sources = { groups: [], inline: '', docs: [], refs: new Map(), totalTokens: 0 };
|
||||
|
|
@ -423,7 +424,9 @@ function gatherSources(app: AppContext, req: GenerateRequest, budgetTokens: numb
|
|||
throw badRequest(rows.some((r) => r.status !== 'ready') ? 'Those documents are still being processed. Try again in a moment.' : 'Those documents have no readable text yet.');
|
||||
}
|
||||
out.docs = usable.map((r) => ({ documentId: r.id, title: r.title }));
|
||||
out.groups = selectContext(db, { documentIds: usable.map((r) => r.id) }, { focus: req.focus, budgetTokens, groups });
|
||||
const scope = { documentIds: usable.map((r) => r.id) };
|
||||
const ranked = req.focus?.trim() ? await hybridSearch(app, req.focus, scope, 400) : undefined;
|
||||
out.groups = selectContext(db, scope, { focus: req.focus, budgetTokens, groups, ranked });
|
||||
}
|
||||
|
||||
if (src.text?.trim()) inline.push(`Notes provided by the student:\n${src.text.trim()}`);
|
||||
|
|
@ -466,7 +469,7 @@ function gatherSources(app: AppContext, req: GenerateRequest, budgetTokens: numb
|
|||
// Pull supporting passages from the class documents for those topics.
|
||||
if (req.classId && out.groups.length === 0) {
|
||||
const query = [...topics.map((t) => t.topic), ...missed.slice(0, 10).map((q) => q.topic)].filter(Boolean).join(' ');
|
||||
const hits = query ? searchChunks(db, query, { classId: req.classId }, 24) : [];
|
||||
const hits = query ? await hybridSearch(app, query, { classId: req.classId }, 24) : [];
|
||||
if (hits.length > 0) {
|
||||
const perGroup = Math.max(1, Math.ceil(hits.length / groups));
|
||||
for (let i = 0; i < hits.length; i += perGroup) out.groups.push(hits.slice(i, i + perGroup));
|
||||
|
|
@ -583,7 +586,7 @@ async function runGeneration(app: AppContext, draftId: string, req: GenerateRequ
|
|||
count = Math.min(Math.max(count, 1), 100);
|
||||
}
|
||||
const batches = Math.ceil(count / perBatch);
|
||||
const sources = gatherSources(app, req, budgetTokens, batches);
|
||||
const sources = await gatherSources(app, req, budgetTokens, batches);
|
||||
const hasSources = sources.groups.length > 0 || Boolean(sources.inline);
|
||||
if (!hasSources && !req.focus && !req.instructions) throw badRequest('Choose source material or describe a topic to generate from.');
|
||||
|
||||
|
|
@ -696,7 +699,7 @@ async function generateNote(app: AppContext, draftId: string, req: GenerateReque
|
|||
const style = req.noteStyle ?? 'study_guide';
|
||||
// A guide reads the material in as few passes as possible; allow a bigger slice per pass than item generation.
|
||||
const perPass = Math.max(budgetTokens, Math.min(Math.floor(window * 0.55), 90_000));
|
||||
const sources = gatherSources(app, req, perPass, 12);
|
||||
const sources = await gatherSources(app, req, perPass, 12);
|
||||
const hasSources = sources.groups.length > 0 || Boolean(sources.inline);
|
||||
if (!hasSources && !req.focus) throw badRequest('Choose source material or describe a topic to write about.');
|
||||
const title = defaultTitle(app, req, sources);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue