Second revision: MCP servers, shared-link AI, flashcard modes, document previews
All checks were successful
Verify and publish V2 container / build-and-push (push) Successful in 30s

Generation
- Every quiz is NCLEX style; "Practice exam" writes 50 questions.
- Calculation questions only when the material involves calculations (max 5 per exam).
- Broad topics: the class's topics are listed in the prompt, a quick grouping call maps
  narrow labels onto broad ones, and leftover variants are merged.
- Exact select-all count per batch; option order shuffled.
- Python check: at most 3 runs, fixed problems count as passed, cosmetic remarks ignored.

Assistant
- Text, tool steps and cards appear in the order they happen, with paragraph breaks
  between steps.
- Optional thinking box: fixed height, follows the newest text, can be scrolled back.
- "+" opens a material picker listing recent items; items can be dragged in from class
  pages; shorter placeholder.

MCP servers
- Streamable HTTP client; encrypted headers.
- Per-server instructions and switches for chat, Explain, generation and the quiz check.
- Settings UI.

Share links
- Optional "Explain this" and "Ask about this material" per link, off by default.
- Items are loaded on the server and checked against the share; no tools; rate-limited.
- Migration 4 stores the switches.

Study and documents
- Standard flashcard mode (optionally repeat missed cards until known) next to spaced
  repetition.
- Streak visuals restyled in the app palette.
- Side by side / Original document views, with sandboxed previews of Word and PowerPoint
  files.

Other
- Built-in embedding model baked into the image; sharp stubbed if it cannot load; real
  load error shown in Settings.
- Python runner blocks network and process modules in JavaScript too.
- "View questions and answers" removed from the quiz start screen.
- Docs updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Elijah 2026-11-15 15:48:54 -07:00
parent 5ea61c882c
commit 031f7bec31
45 changed files with 2918 additions and 397 deletions

View file

@ -1,5 +1,5 @@
import { useInfiniteQuery, useQuery } from '@tanstack/react-query';
import { BookOpen, ChevronRight, Download, FileText, FolderInput, Layers, MessageSquare, MoreHorizontal, NotebookPen, Pencil, RefreshCw, ScanText, Share2, Sparkles, Trash2, TriangleAlert } from 'lucide-react';
import { BookOpen, ChevronRight, Columns2, Download, FileText, FolderInput, Layers, MessageSquare, MoreHorizontal, NotebookPen, Pencil, RefreshCw, ScanText, Share2, Sparkles, Trash2, TriangleAlert } from 'lucide-react';
import { useEffect, useState } from 'react';
import { Link, useNavigate, useParams, useSearchParams } from 'react-router';
import { toast } from 'sonner';
@ -9,7 +9,7 @@ import { api, errorMessage } from '@/lib/api';
import { assistant, useAssistantContext } from '@/lib/assistantStore';
import { qk, useAiStatus, useRefresh } from '@/lib/queries';
import type { ClassInfo, DocChunk, DocumentInfo, Share } from '@/lib/types';
import { cx, downloadFile, formatBytes, formatTokens, plural, useDocumentTitle } from '@/lib/util';
import { cx, downloadFile, formatBytes, formatTokens, plural, useDocumentTitle, useLocalStorage } from '@/lib/util';
import { Markdown } from '@/ui/Markdown';
import { Badge, Button, Callout, ClassDot, EmptyState, ErrorState, IconButton, Menu, MenuItem, MenuSeparator, ProgressBar, Segmented, Skeleton, Spinner, useConfirm } from '@/ui';
@ -36,7 +36,7 @@ export default function DocumentPage() {
const refresh = useRefresh();
const confirm = useConfirm();
const ai = useAiStatus();
const [view, setView] = useState<'text' | 'original'>('text');
const [view, setView] = useLocalStorage<'text' | 'side' | 'original'>('sd.documentView', 'text');
const [rename, setRename] = useState(false);
const [move, setMove] = useState(false);
const [share, setShare] = useState(false);
@ -77,7 +77,7 @@ export default function DocumentPage() {
}
const cls = q.data.class;
const busy = doc.status === 'pending' || doc.status === 'processing';
const hasOriginal = doc.docKind === 'pdf' || doc.docKind === 'image';
const hasOriginal = doc.docKind === 'pdf' || doc.docKind === 'image' || doc.docKind === 'docx' || doc.docKind === 'pptx';
const fileUrl = `/api/documents/${doc.id}/file`;
const reprocess = async (ocr: boolean) => {
@ -99,6 +99,65 @@ export default function DocumentPage() {
}
};
const all = chunks.data?.pages.flatMap((p) => p.chunks) ?? [];
const office = doc.docKind === 'docx' || doc.docKind === 'pptx';
const originalView = (height: string) =>
doc.docKind === 'image' ? (
<div className="card grid place-items-center p-4">
<img src={fileUrl} alt={doc.title} className="max-h-[80vh] max-w-full rounded-lg" />
</div>
) : (
// Office previews are self-contained HTML; the server sandboxes them with its Content-Security-Policy.
<iframe src={office ? `/api/documents/${doc.id}/preview` : fileUrl} title={`${doc.title} (original)`} className={cx('card w-full bg-surface', height)} />
);
const noText = !ready ? null : doc.chunkCount === 0 ? (
<div className="card">
<EmptyState icon={<FileText />} title="No text to show">
{doc.needsOcr ? 'Use "Read with AI" above to transcribe this file.' : 'Nothing readable was found in this file.'}
</EmptyState>
</div>
) : null;
const articleView = (
<div className="min-w-0">
{firstOffset > 0 && <div className="mb-3 rounded-xl border border-dashed border-line-strong px-4 py-2.5 text-[13px] text-ink-3">Showing from section {firstOffset + 1}. <Link to={`/documents/${doc.id}`} className="font-medium text-accent hover:underline">Start from the beginning</Link></div>}
<article className="card divide-y divide-line">
{chunks.isLoading && (
<div className="space-y-3 p-6">
<Skeleton className="h-4 w-3/4" />
<Skeleton className="h-4" />
<Skeleton className="h-4 w-5/6" />
</div>
)}
{all.map((ch, i) => {
const prev = all[i - 1];
const showHeading = ch.heading && ch.heading !== prev?.heading;
const showPage = ch.pageStart !== null && ch.pageStart !== prev?.pageStart;
return (
<section key={ch.id} id={`chunk-${ch.id}`} className={cx('scroll-mt-24 px-5 py-4 sm:px-8', focusChunk === ch.id && 'bg-marker/25')}>
{(showHeading || showPage) && (
<div className="mb-2 flex flex-wrap items-baseline justify-between gap-2">
{showHeading ? <h2 className="display text-[19px]">{ch.heading}</h2> : <span />}
{showPage && (
<span className="num text-[11px] text-ink-3">
{doc.docKind === 'pptx' ? 'Slide' : 'Page'} {ch.pageStart}
{ch.pageEnd && ch.pageEnd !== ch.pageStart ? `–${ch.pageEnd}` : ''}
</span>
)}
</div>
)}
<Markdown className="text-[15px] text-ink">{ch.text}</Markdown>
</section>
);
})}
</article>
{chunks.hasNextPage && (
<div className="mt-4 flex justify-center">
<Button loading={chunks.isFetchingNextPage} onClick={() => chunks.fetchNextPage()}>
Show more
</Button>
</div>
)}
</div>
);
return (
<div className={cx('animate-in', `tab-${cls.color}`)}>
@ -239,6 +298,7 @@ export default function DocumentPage() {
onChange={setView}
options={[
{ value: 'text', label: 'Extracted text', icon: <FileText /> },
{ value: 'side', label: 'Side by side', icon: <Columns2 /> },
{ value: 'original', label: 'Original', icon: <ScanText /> },
]}
/>
@ -246,94 +306,50 @@ export default function DocumentPage() {
)}
{view === 'original' && hasOriginal ? (
doc.docKind === 'image' ? (
<div className="card grid place-items-center p-4">
<img src={fileUrl} alt={doc.title} className="max-h-[80vh] max-w-full rounded-lg" />
</div>
) : (
<iframe src={fileUrl} title={doc.title} className="card h-[82vh] w-full" />
)
) : !ready ? null : doc.chunkCount === 0 ? (
<div className="card">
<EmptyState icon={<FileText />} title="No text to show">
{doc.needsOcr ? 'Use "Read with AI" above to transcribe this file.' : 'Nothing readable was found in this file.'}
</EmptyState>
originalView('h-[82vh]')
) : view === 'side' && hasOriginal ? (
<div className="grid items-start gap-4 lg:grid-cols-2">
<div className="lg:sticky lg:top-4">{originalView('h-[60vh] lg:h-[calc(100dvh-2rem)]')}</div>
<div className="min-w-0">{ready ? (noText ?? articleView) : null}</div>
</div>
) : (
<div className="grid gap-6 lg:grid-cols-[1fr_220px]">
<div className="min-w-0">
{firstOffset > 0 && <div className="mb-3 rounded-xl border border-dashed border-line-strong px-4 py-2.5 text-[13px] text-ink-3">Showing from section {firstOffset + 1}. <Link to={`/documents/${doc.id}`} className="font-medium text-accent hover:underline">Start from the beginning</Link></div>}
<article className="card divide-y divide-line">
{chunks.isLoading && (
<div className="space-y-3 p-6">
<Skeleton className="h-4 w-3/4" />
<Skeleton className="h-4" />
<Skeleton className="h-4 w-5/6" />
) : !ready ? null : (
noText ?? (
<div className="grid gap-6 lg:grid-cols-[1fr_220px]">
{articleView}
{q.data.outline.length > 1 && (
<aside className="hidden lg:block">
<div className="sticky top-8">
<div className="eyebrow mb-2">Outline</div>
<ul className="max-h-[70vh] space-y-0.5 overflow-y-auto text-[13px]">
{q.data.outline.map((o) => (
<li key={o.seq}>
<button
type="button"
onClick={async () => {
// Load forward until the section is on the page, then scroll to it.
let pages = chunks.data?.pages ?? [];
let guard = 0;
while (!pages.some((p) => p.chunks.some((c) => c.seq === o.seq)) && pages[pages.length - 1]?.nextOffset !== null && guard < 40) {
const res = await chunks.fetchNextPage();
pages = res.data?.pages ?? [];
guard += 1;
}
const hit = pages.flatMap((p) => p.chunks).find((c) => c.seq === o.seq);
if (hit) document.getElementById(`chunk-${hit.id}`)?.scrollIntoView({ block: 'start', behavior: 'smooth' });
}}
className="block w-full truncate rounded-md px-2 py-1 text-left text-ink-2 hover:bg-ink/5 hover:text-ink"
title={o.heading}
>
{o.heading}
</button>
</li>
))}
</ul>
</div>
)}
{all.map((ch, i) => {
const prev = all[i - 1];
const showHeading = ch.heading && ch.heading !== prev?.heading;
const showPage = ch.pageStart !== null && ch.pageStart !== prev?.pageStart;
return (
<section key={ch.id} id={`chunk-${ch.id}`} className={cx('scroll-mt-24 px-5 py-4 sm:px-8', focusChunk === ch.id && 'bg-marker/25')}>
{(showHeading || showPage) && (
<div className="mb-2 flex flex-wrap items-baseline justify-between gap-2">
{showHeading ? <h2 className="display text-[19px]">{ch.heading}</h2> : <span />}
{showPage && (
<span className="num text-[11px] text-ink-3">
{doc.docKind === 'pptx' ? 'Slide' : 'Page'} {ch.pageStart}
{ch.pageEnd && ch.pageEnd !== ch.pageStart ? `–${ch.pageEnd}` : ''}
</span>
)}
</div>
)}
<Markdown className="text-[15px] text-ink">{ch.text}</Markdown>
</section>
);
})}
</article>
{chunks.hasNextPage && (
<div className="mt-4 flex justify-center">
<Button loading={chunks.isFetchingNextPage} onClick={() => chunks.fetchNextPage()}>
Show more
</Button>
</div>
</aside>
)}
</div>
{q.data.outline.length > 1 && (
<aside className="hidden lg:block">
<div className="sticky top-8">
<div className="eyebrow mb-2">Outline</div>
<ul className="max-h-[70vh] space-y-0.5 overflow-y-auto text-[13px]">
{q.data.outline.map((o) => (
<li key={o.seq}>
<button
type="button"
onClick={async () => {
// Load forward until the section is on the page, then scroll to it.
let pages = chunks.data?.pages ?? [];
let guard = 0;
while (!pages.some((p) => p.chunks.some((c) => c.seq === o.seq)) && pages[pages.length - 1]?.nextOffset !== null && guard < 40) {
const res = await chunks.fetchNextPage();
pages = res.data?.pages ?? [];
guard += 1;
}
const hit = pages.flatMap((p) => p.chunks).find((c) => c.seq === o.seq);
if (hit) document.getElementById(`chunk-${hit.id}`)?.scrollIntoView({ block: 'start', behavior: 'smooth' });
}}
className="block w-full truncate rounded-md px-2 py-1 text-left text-ink-2 hover:bg-ink/5 hover:text-ink"
title={o.heading}
>
{o.heading}
</button>
</li>
))}
</ul>
</div>
</aside>
)}
</div>
)
)}
<RenameDialog target={rename ? { kind: 'document', id: doc.id, title: doc.title } : null} onClose={() => setRename(false)} />