First revision: DeepSeek, numeric questions, background assistant, UI fixes
All checks were successful
Verify and publish V2 container / build-and-push (push) Successful in 1m2s

Providers and pricing
- Add a DeepSeek provider: thinking mode with low/high/max effort, reasoning_content
  replayed between tool steps, cache-hit usage, /models discovery and catalog prices.
- Fix "does not support tool calling": a rejected forced tool_choice (DeepSeek thinking
  mode) now asks for the call in the prompt; only a genuine no-tools 400 is "unsupported".
- Seven reasoning-effort levels (Off to Max) mapped per adapter.
- Cached-input price per model, cache-write and DeepSeek off-peak aware cost estimates.
- Built-in bge-small embedding model (transformers.js) as the semantic search default.

Quizzes
- Numeric (type-the-answer) questions: units ignored, optional ± tolerance; editor,
  runner, importer, templates and generation prompts.
- Quiz start screen instead of showing answers; navigator ring no longer clipped and
  key legend removed; clock only for timed exams; 7-point letter grades.

Assistant and generation
- Assistant turns run on the server independently of the browser, with re-attach and
  an explicit stop; drafts tray shows generations in progress.
- Per-chat model switcher, @-tagging of class materials, full-width assistant page and
  a smaller assistant button.
- Editable generation instructions and built-in presets, separate from the chatbot
  import instructions.

Other
- Dialog footer padding, keyboard hints removed, copy buttons work over plain HTTP,
  class and folder shares include documents.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Elijah 2026-11-15 12:48:17 -07:00
parent ccdad9728b
commit f0aabe4d5d
63 changed files with 3892 additions and 488 deletions

View file

@ -1,10 +1,10 @@
import { ArrowLeft, ArrowRight, Check, CircleCheck, CircleX, Clock, Flag, LayoutGrid, RotateCcw, X } from 'lucide-react';
import { useEffect, useMemo, useRef, useState, type ReactNode } from 'react';
import { isFullyCorrect, optionLetter, scoreQuestion, type SataScoring } from '@shared/content';
import { isFullyCorrect, letterGrade, optionLetter, parseNumericAnswer, scoreQuestion, type SataScoring } from '@shared/content';
import type { AnswerState, SnapshotQuestion } from '@/lib/types';
import { cx, formatDuration, formatMinutes, plural, useHotkeys, useLatest } from '@/lib/util';
import { Markdown } from '@/ui/Markdown';
import { Badge, Button, Dialog, IconButton, Kbd, ProgressBar, Segmented, useConfirm } from '@/ui';
import { Badge, Button, Dialog, IconButton, Input, ProgressBar, Segmented, useConfirm } from '@/ui';
import { Ring } from './charts';
/* ------------------------------ option list ------------------------------ */
@ -71,6 +71,87 @@ function OptionList({
);
}
/* ------------------------------ numeric answer ------------------------------ */
/** The accepted answer(s) of a numeric question, for display. */
function acceptedAnswers(question: SnapshotQuestion): string {
return question.options
.filter((o) => o.correct !== false)
.map((o) => o.text)
.join(' or ');
}
/** A calculation: the student types the number. Units are optional; only the number is checked. */
function NumericAnswer({
question,
value,
revealed,
onChange,
onSubmit,
autoFocus,
}: {
question: SnapshotQuestion;
value: string;
revealed: boolean;
onChange?: (text: string) => void;
onSubmit?: () => void;
autoFocus?: boolean;
}) {
const right = revealed && isFullyCorrect(scoreQuestion(question, value ? [value] : []));
const unreadable = value.trim() !== '' && parseNumericAnswer(value) === null;
const why = question.options.find((o) => o.why)?.why;
return (
<div className="space-y-2.5">
<label className="block">
<span className="sr-only">Your answer</span>
<Input
value={value}
autoFocus={autoFocus}
inputMode="decimal"
autoComplete="off"
spellCheck={false}
readOnly={revealed || !onChange}
onChange={(e) => onChange?.(e.target.value)}
onKeyDown={(e) => {
if (e.key === 'Enter' && !e.nativeEvent.isComposing) {
e.preventDefault();
onSubmit?.();
}
}}
placeholder="Type your answer, e.g. 12.5"
aria-invalid={unreadable || undefined}
className={cx(
'num h-14 max-w-sm rounded-[14px] px-4 text-[20px]',
revealed && (right ? 'border-good bg-good-soft ring-1 ring-good' : 'border-bad bg-bad-soft ring-1 ring-bad'),
)}
/>
</label>
{!revealed && <p className="text-[13px] text-ink-3">{unreadable ? 'Enter a number. Units are optional.' : 'Only the number is checked, so units are optional.'}</p>}
{revealed && (
<div className="rounded-[14px] border border-good/60 border-dashed px-3.5 py-2.5">
<div className="flex flex-wrap items-baseline gap-x-2 text-[15px]">
<span className="text-[13px] font-medium text-good">Correct answer</span>
<span className="num font-semibold">{acceptedAnswers(question)}</span>
</div>
{why && <div className="mt-1 text-[13.5px] leading-snug text-ink-2">{why}</div>}
</div>
)}
</div>
);
}
/** What the student answered, as text (for the AI explanation). */
function answerTexts(question: SnapshotQuestion, selected: string[]): string[] {
if (question.type === 'numeric') return selected.slice(0, 1);
return question.options.filter((o) => selected.includes(o.id)).map((o) => o.text);
}
/** Tone for a percentage on the 7-point scale: A and B good, C passing, D and F failing. */
export function gradeToneFor(percent: number): 'good' | 'warn' | 'bad' {
const letter = letterGrade(percent);
return letter === 'A' || letter === 'B' ? 'good' : letter === 'C' ? 'warn' : 'bad';
}
/** "2 of 3" style credit for a select-all question, so partial credit is never a mystery. */
function creditDetail(question: SnapshotQuestion, selected: string[], sata: SataScoring): string | null {
if (question.type !== 'multi') return null;
@ -194,12 +275,21 @@ export function QuizRunner(p: RunnerProps) {
topRef.current?.scrollIntoView({ block: 'start' });
}, [index]);
const numeric = question.type === 'numeric';
const toggle = (id: string) => {
if (checked) return;
if (checked || numeric) return;
const next = question.type === 'single' ? [id] : selected.includes(id) ? selected.filter((x) => x !== id) : [...selected, id];
p.onAnswer(question.id, next, false);
};
const check = () => selected.length > 0 && p.onAnswer(question.id, selected, true);
const typed = numeric ? (selected[0] ?? '') : '';
const setTyped = (text: string) => !checked && p.onAnswer(question.id, text.trim() ? [text] : [], false);
const canCheck = numeric ? parseNumericAnswer(typed) !== null : selected.length > 0;
const check = () => {
if (!canCheck) return;
// Let the typed answer show its correct/incorrect colour instead of the focus ring.
if (numeric) (document.activeElement as HTMLElement | null)?.blur();
p.onAnswer(question.id, numeric ? [typed.trim()] : selected, true);
};
const go = (i: number) => p.onIndex(Math.max(0, Math.min(total - 1, i)));
const toggleFlag = () => p.onFlags(flagged ? p.flags.filter((f) => f !== question.id) : [...p.flags, question.id]);
@ -223,8 +313,8 @@ export function QuizRunner(p: RunnerProps) {
};
useHotkeys({
...Object.fromEntries(question.options.map((o, i) => [String(i + 1), () => toggle(o.id)])),
...Object.fromEntries(question.options.map((o, i) => [optionLetter(i).toLowerCase(), () => toggle(o.id)])),
...(numeric ? {} : Object.fromEntries(question.options.map((o, i) => [String(i + 1), () => toggle(o.id)]))),
...(numeric ? {} : Object.fromEntries(question.options.map((o, i) => [optionLetter(i).toLowerCase(), () => toggle(o.id)]))),
Enter: primary,
ArrowRight: () => go(index + 1),
ArrowLeft: () => go(index - 1),
@ -253,7 +343,7 @@ export function QuizRunner(p: RunnerProps) {
</div>
{live && (
<div
className={cx('num flex items-center gap-1.5 rounded-full px-2.5 py-1 text-[13px] font-semibold', live.percent >= 80 ? 'bg-good-soft text-good' : live.percent >= 60 ? 'bg-warn-soft text-warn' : 'bg-bad-soft text-bad')}
className={cx('num flex items-center gap-1.5 rounded-full px-2.5 py-1 text-[13px] font-semibold', { good: 'bg-good-soft text-good', warn: 'bg-warn-soft text-warn', bad: 'bg-bad-soft text-bad' }[gradeToneFor(live.percent)])}
aria-label={`Score so far: ${fmtPoints(live.points)} of ${live.n} correct, ${live.percent} percent`}
>
<span className="hidden sm:inline">
@ -262,10 +352,13 @@ export function QuizRunner(p: RunnerProps) {
{live.percent}%
</div>
)}
<div className={cx('num flex items-center gap-1.5 rounded-full px-2.5 py-1 text-[13px] font-medium', remaining !== null && remaining < 60 ? 'bg-bad-soft text-bad' : 'text-ink-2')} aria-label={remaining !== null ? 'Time remaining' : 'Time elapsed'}>
<Clock className="size-3.5" />
{formatDuration(remaining ?? clock)}
</div>
{/* The clock is a timed-exam feature; untimed sessions track time quietly for the results. */}
{remaining !== null && (
<div className={cx('num flex items-center gap-1.5 rounded-full px-2.5 py-1 text-[13px] font-medium', remaining < 60 ? 'bg-bad-soft text-bad' : 'text-ink-2')} aria-label="Time remaining">
<Clock className="size-3.5" />
{formatDuration(remaining)}
</div>
)}
<button type="button" onClick={() => setNavOpen(true)} className="num flex h-9 items-center gap-1.5 rounded-[9px] border border-line-strong bg-surface px-2.5 text-[13px] font-medium shadow-1 hover:border-ink-3" aria-label="Question navigator">
<LayoutGrid className="size-3.5 text-ink-3" />
{index + 1}/{total}
@ -289,8 +382,12 @@ export function QuizRunner(p: RunnerProps) {
<Markdown serif className="text-[20px] leading-[1.45] sm:text-[22px]">
{question.stem}
</Markdown>
<p className="mt-3 mb-4 text-[13px] font-medium text-ink-3">{question.type === 'multi' ? 'Select all that apply.' : 'Choose one answer.'}</p>
<OptionList question={question} selected={selected} revealed={checked} onToggle={toggle} />
<p className="mt-3 mb-4 text-[13px] font-medium text-ink-3">{question.type === 'multi' ? 'Select all that apply.' : numeric ? 'Enter your answer.' : 'Choose one answer.'}</p>
{numeric ? (
<NumericAnswer key={question.id} question={question} value={typed} revealed={checked} onChange={setTyped} onSubmit={primary} />
) : (
<OptionList question={question} selected={selected} revealed={checked} onToggle={toggle} />
)}
{checked && (
<div className="mt-5 animate-in space-y-4">
@ -301,10 +398,7 @@ export function QuizRunner(p: RunnerProps) {
<Markdown className="text-[15px]">{question.rationale}</Markdown>
</div>
)}
{p.renderExtra?.(
question,
question.options.filter((o) => selected.includes(o.id)).map((o) => o.text),
)}
{p.renderExtra?.(question, answerTexts(question, selected))}
</div>
)}
</div>
@ -324,11 +418,8 @@ export function QuizRunner(p: RunnerProps) {
<Button size="lg" variant="ghost" onClick={() => (isLast ? requestFinish() : go(index + 1))}>
{isLast ? 'Finish' : 'Skip'}
</Button>
<Button size="lg" variant="primary" disabled={selected.length === 0} onClick={check} className="min-w-32">
<Button size="lg" variant="primary" disabled={!canCheck} onClick={check} className="min-w-32">
Check
<span className="hidden sm:inline">
<Kbd>↵</Kbd>
</span>
</Button>
</>
) : isLast ? (
@ -361,7 +452,8 @@ export function QuizRunner(p: RunnerProps) {
</Button>
}
>
<div className="grid grid-cols-6 gap-2 sm:grid-cols-8">
{/* Padding keeps the current-question ring (and its offset) inside the scroll area. */}
<div className="grid grid-cols-6 gap-2 p-1.5 sm:grid-cols-8">
{p.questions.map((q, i) => {
const s = statusOf(q);
return (
@ -383,21 +475,6 @@ export function QuizRunner(p: RunnerProps) {
);
})}
</div>
<div className="mt-5 hidden flex-wrap gap-x-4 gap-y-2 text-xs text-ink-3 sm:flex">
<span className="flex items-center gap-1.5">
<Kbd>1</Kbd>–<Kbd>9</Kbd> or <Kbd>A</Kbd>–<Kbd>E</Kbd> choose
</span>
<span className="flex items-center gap-1.5">
<Kbd>Enter</Kbd> check / next
</span>
<span className="flex items-center gap-1.5">
<Kbd>←</Kbd>
<Kbd>→</Kbd> move
</span>
<span className="flex items-center gap-1.5">
<Kbd>M</Kbd> flag
</span>
</div>
</Dialog>
</div>
);
@ -440,7 +517,8 @@ export function QuizResults(p: ResultsProps) {
const partial = scored.filter((r) => !r.correct && r.score > 0).length;
const wrong = scored.length - right - partial;
const skipped = rows.length - scored.length;
const tone = percent >= 80 ? 'good' : percent >= 60 ? 'warn' : 'bad';
const tone = gradeToneFor(percent);
const grade = letterGrade(percent);
const topics = useMemo(() => {
const map = new Map<string, { n: number; s: number }>();
@ -455,7 +533,7 @@ export function QuizResults(p: ResultsProps) {
}, [scored]);
const visible = rows.filter((r) => (filter === 'all' ? true : filter === 'wrong' ? r.scored && !r.correct : p.flags.includes(r.q.id)));
const headline = percent >= 90 ? 'Excellent work' : percent >= 80 ? 'Strong result' : percent >= 60 ? 'Getting there' : 'Worth another pass';
const headline = { A: 'Excellent work', B: 'Strong result', C: 'Passing', D: 'Just below passing', F: 'Worth another pass' }[grade];
return (
<div className="min-h-dvh bg-paper">
@ -471,13 +549,13 @@ export function QuizResults(p: ResultsProps) {
<section className="card p-6 sm:p-8">
<div className="flex flex-col items-center gap-6 text-center sm:flex-row sm:text-left">
<Ring value={percent / 100} size={128} stroke={11} tone={tone}>
<div className="leading-none">
<span className="display num text-[38px] font-medium">{percent}</span>
<span className="text-lg text-ink-3">%</span>
<div className="flex flex-col items-center leading-none">
<span className="display text-[40px] font-medium">{grade}</span>
<span className="num mt-1 text-[13px] font-medium text-ink-3">{percent}%</span>
</div>
</Ring>
<div className="min-w-0 flex-1">
<div className="eyebrow mb-1">{p.mode === 'exam' ? 'Exam result' : 'Practice result'}</div>
<div className="eyebrow mb-1">{p.mode === 'exam' ? 'Exam result' : 'Practice result'} · grade {grade}</div>
<h1 className="display text-[30px]">{headline}</h1>
<p className="mt-1.5 text-[15px] text-ink-2">
<span className="num font-semibold text-ink">{fmtPoints(points)}</span> of <span className="num font-semibold text-ink">{scored.length}</span> points
@ -506,7 +584,7 @@ export function QuizResults(p: ResultsProps) {
<span className="min-w-0 flex-1 truncate text-sm font-medium">{t.topic}</span>
<span className="text-xs text-ink-3">{plural(t.n, 'question')}</span>
<div className="h-1.5 w-24 overflow-hidden rounded-full bg-ink/8 sm:w-36">
<div className={cx('h-full rounded-full', pc >= 80 ? 'bg-good' : pc >= 60 ? 'bg-warn' : 'bg-bad')} style={{ width: `${Math.max(4, pc)}%` }} />
<div className={cx('h-full rounded-full', { good: 'bg-good', warn: 'bg-warn', bad: 'bg-bad' }[gradeToneFor(pc)])} style={{ width: `${Math.max(4, pc)}%` }} />
</div>
<span className="num w-10 text-right text-[13px] font-medium">{pc}%</span>
</div>
@ -550,7 +628,7 @@ export function QuizResults(p: ResultsProps) {
<Markdown serif className="mb-3.5 text-[17px]">
{r.q.stem}
</Markdown>
<OptionList question={r.q} selected={r.selected} revealed />
{r.q.type === 'numeric' ? <NumericAnswer question={r.q} value={r.selected[0] ?? ''} revealed /> : <OptionList question={r.q} selected={r.selected} revealed />}
{r.scored && !r.correct && r.answered && creditDetail(r.q, r.selected, p.sataScoring) && <p className="mt-2.5 text-[13px] text-ink-2">{creditDetail(r.q, r.selected, p.sataScoring)}</p>}
{r.q.rationale && (
<div className="mt-3.5 rounded-xl bg-sunken px-4 py-3">
@ -560,10 +638,7 @@ export function QuizResults(p: ResultsProps) {
)}
{p.renderExtra && (
<div className="mt-3">
{p.renderExtra(
r.q,
r.q.options.filter((o) => r.selected.includes(o.id)).map((o) => o.text),
)}
{p.renderExtra(r.q, answerTexts(r.q, r.selected))}
</div>
)}
</li>