Add the V2 web app: design system, shell, study flows, AI, settings, sharing

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Elijah 2026-11-11 08:53:01 -07:00
parent eae109c166
commit 74a98ac1f1
52 changed files with 11976 additions and 1 deletions

View file

@ -71,12 +71,19 @@ export function documentRoutes(app: AppContext): Hono {
r.get('/documents/:id/chunks', (c) => {
const doc = getDocument(db, idParam(c));
const offset = Math.max(0, Number(c.req.query('offset') ?? 0) || 0);
let offset = Math.max(0, Number(c.req.query('offset') ?? 0) || 0);
const limit = Math.min(100, Math.max(1, Number(c.req.query('limit') ?? 40) || 40));
// Deep link to one passage (from search or a citation): start just before it.
const around = Number(c.req.query('around'));
if (Number.isFinite(around) && around > 0) {
const hit = db.get<{ seq: number }>('SELECT seq FROM chunks WHERE id = ? AND document_id = ?', around, doc.id);
if (hit) offset = Math.max(0, hit.seq - 1);
}
const chunks = listChunks(db, doc.id, offset, limit);
return c.json({
chunks: chunks.map((ch) => ({ id: ch.id, seq: ch.seq, text: ch.text, heading: ch.heading, pageStart: ch.pageStart, pageEnd: ch.pageEnd, label: sourceLabel(ch) })),
total: doc.chunk_count,
offset,
nextOffset: chunks.length === limit && offset + limit < doc.chunk_count ? offset + limit : null,
});
});