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
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:
parent
ccdad9728b
commit
f0aabe4d5d
63 changed files with 3892 additions and 488 deletions
|
|
@ -2,7 +2,7 @@ import { ArrowDown, ArrowUp, BookOpen, Check, ChevronRight, ClipboardList, Copy,
|
|||
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { Link, useNavigate, useParams, useSearchParams } from 'react-router';
|
||||
import { toast } from 'sonner';
|
||||
import { blankQuestion, optionLetter, QUESTION_TYPE_LABEL, questionToDraft, validateDraftQuestion, type DraftCard, type DraftQuestion, type Question } from '@shared/content';
|
||||
import { blankQuestion, letterGrade, optionLetter, QUESTION_TYPE_LABEL, questionToDraft, validateDraftQuestion, type DraftCard, type DraftQuestion, type Question } from '@shared/content';
|
||||
import { parseImport } from '@shared/importer';
|
||||
import { MoveDialog, RenameDialog, ShareDialog } from '@/features/dialogs';
|
||||
import { QuestionEditor } from '@/features/editors';
|
||||
|
|
@ -22,19 +22,20 @@ interface StartPrefs {
|
|||
shuffleOptions: boolean;
|
||||
}
|
||||
|
||||
export function StartSessionDialog({ open, onClose, quizId, total, title }: { open: boolean; onClose: () => void; quizId: string; total: number; title: string }) {
|
||||
/** Session options (mode, length, shuffling, exam time limit), shared by the start screen and the start dialog. */
|
||||
function useStartOptions(quizId: string, total: number, active: boolean) {
|
||||
const { start, starting } = useStartSession();
|
||||
const [prefs, setPrefs] = useLocalStorage<StartPrefs>('sd.startPrefs', { mode: 'practice', shuffleQuestions: true, shuffleOptions: true });
|
||||
const [count, setCount] = useState(total);
|
||||
const [timed, setTimed] = useState(false);
|
||||
const [minutes, setMinutes] = useState(30);
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
if (active) {
|
||||
setCount(total);
|
||||
setMinutes(Math.max(5, Math.round(total * 1.2)));
|
||||
setTimed(false);
|
||||
}
|
||||
}, [open, total]);
|
||||
}, [active, total]);
|
||||
const go = () =>
|
||||
start({
|
||||
mode: prefs.mode,
|
||||
|
|
@ -42,25 +43,15 @@ export function StartSessionDialog({ open, onClose, quizId, total, title }: { op
|
|||
shuffleQuestions: prefs.shuffleQuestions,
|
||||
shuffleOptions: prefs.shuffleOptions,
|
||||
count: count < total ? count : undefined,
|
||||
// A time limit is an exam option only; practice sessions are never timed.
|
||||
timeLimitMin: prefs.mode === 'exam' && timed ? minutes : null,
|
||||
});
|
||||
return { prefs, setPrefs, count, setCount, timed, setTimed, minutes, setMinutes, go, starting, total };
|
||||
}
|
||||
|
||||
function StartOptionsFields({ o }: { o: ReturnType<typeof useStartOptions> }) {
|
||||
const { prefs, setPrefs, count, setCount, timed, setTimed, minutes, setMinutes, total } = o;
|
||||
return (
|
||||
<Dialog
|
||||
open={open}
|
||||
onOpenChange={(o) => !o && onClose()}
|
||||
title="Start a session"
|
||||
description={title}
|
||||
footer={
|
||||
<>
|
||||
<Button variant="ghost" onClick={onClose}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button variant="primary" icon={<Play className="fill-current" />} loading={starting} onClick={go}>
|
||||
Start
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<div className="space-y-5">
|
||||
<div className="grid grid-cols-2 gap-2" role="radiogroup" aria-label="Mode">
|
||||
{(
|
||||
|
|
@ -102,10 +93,75 @@ export function StartSessionDialog({ open, onClose, quizId, total, title }: { op
|
|||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function StartSessionDialog({ open, onClose, quizId, total, title }: { open: boolean; onClose: () => void; quizId: string; total: number; title: string }) {
|
||||
const o = useStartOptions(quizId, total, open);
|
||||
return (
|
||||
<Dialog
|
||||
open={open}
|
||||
onOpenChange={(v) => !v && onClose()}
|
||||
title="Start a session"
|
||||
description={title}
|
||||
footer={
|
||||
<>
|
||||
<Button variant="ghost" onClick={onClose}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button variant="primary" icon={<Play className="fill-current" />} loading={o.starting} onClick={o.go}>
|
||||
Start
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<StartOptionsFields o={o} />
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
/** The quiz start screen: how to take it, without showing any questions or answers. */
|
||||
function StartPanel({ quizId, total, resume, onShowQuestions }: { quizId: string; total: number; resume: { id: string; answeredCount: number; questionCount: number } | null; onShowQuestions: () => void }) {
|
||||
const o = useStartOptions(quizId, total, true);
|
||||
if (total === 0) {
|
||||
return (
|
||||
<div className="card border-dashed">
|
||||
<EmptyState icon={<BookOpen />} title="No questions yet" action={<Button variant="primary" icon={<Plus />} onClick={onShowQuestions}>Add questions</Button>}>
|
||||
Add questions to this quiz before taking it.
|
||||
</EmptyState>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<section className="card p-5 sm:p-6">
|
||||
{resume && (
|
||||
<Callout
|
||||
tone="warn"
|
||||
icon={<Play />}
|
||||
className="mb-5"
|
||||
title="You have a session in progress"
|
||||
action={
|
||||
<Button to={`/session/${resume.id}`} variant="marker" size="sm">
|
||||
Resume ({resume.answeredCount}/{resume.questionCount})
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
Pick up where you left off, or start a new session below.
|
||||
</Callout>
|
||||
)}
|
||||
<StartOptionsFields o={o} />
|
||||
<div className="mt-6 flex flex-wrap items-center gap-2 border-t border-line pt-5">
|
||||
<Button variant="primary" size="lg" icon={<Play className="fill-current" />} loading={o.starting} onClick={o.go} className="min-w-40">
|
||||
{resume ? 'Start new session' : 'Start'}
|
||||
</Button>
|
||||
<Button variant="ghost" size="lg" icon={<ClipboardList />} onClick={onShowQuestions} className="ml-auto">
|
||||
View questions and answers
|
||||
</Button>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
/** Paste several questions (or cards) as text or JSON and add them to an existing item. */
|
||||
export function BulkAddDialog({ open, onClose, kind, onAdd }: { open: boolean; onClose: () => void; kind: 'quiz' | 'deck'; onAdd: (items: unknown[]) => Promise<void> }) {
|
||||
const [text, setText] = useState('');
|
||||
|
|
@ -230,7 +286,8 @@ export default function QuizPage() {
|
|||
useAssistantContext(data?.quiz.classId, data?.quiz.title);
|
||||
const { start, starting } = useStartSession();
|
||||
|
||||
const [tab, setTab] = useState<'questions' | 'history'>('questions');
|
||||
// The start screen comes first, so opening a quiz never reveals its answers.
|
||||
const [tab, setTab] = useState<'start' | 'questions' | 'history'>(() => (params.get('q') || params.get('edit') ? 'questions' : 'start'));
|
||||
const [editing, setEditing] = useState<string | 'new' | null>(null);
|
||||
const [draft, setDraft] = useState<DraftQuestion>(blankQuestion());
|
||||
const [saving, setSaving] = useState(false);
|
||||
|
|
@ -252,8 +309,10 @@ export default function QuizPage() {
|
|||
if (params.get('edit')) {
|
||||
setDraft(blankQuestion());
|
||||
setEditing('new');
|
||||
setTab('questions');
|
||||
}
|
||||
const target = params.get('q');
|
||||
if (target) setTab('questions');
|
||||
if (target) setTimeout(() => document.getElementById(`q-${target}`)?.scrollIntoView({ block: 'center', behavior: 'smooth' }), 120);
|
||||
if (params.get('start') || params.get('edit')) {
|
||||
next.delete('start');
|
||||
|
|
@ -299,6 +358,7 @@ export default function QuizPage() {
|
|||
setEditing(question.id);
|
||||
};
|
||||
const beginNew = () => {
|
||||
setTab('questions');
|
||||
setDraft({ ...blankQuestion(), topic: questions[questions.length - 1]?.topic ?? '' });
|
||||
setEditing('new');
|
||||
setTimeout(() => newRef.current?.scrollIntoView({ block: 'center', behavior: 'smooth' }), 60);
|
||||
|
|
@ -358,7 +418,7 @@ export default function QuizPage() {
|
|||
|
||||
const editorFooter = (isNew: boolean) => (
|
||||
<div className="mt-5 flex flex-wrap items-center justify-end gap-2 border-t border-line pt-4">
|
||||
<span className="mr-auto hidden text-xs text-ink-3 sm:block">Ctrl+Enter to save</span>
|
||||
<span className="mr-auto" />
|
||||
<Button variant="ghost" onClick={() => setEditing(null)}>
|
||||
Cancel
|
||||
</Button>
|
||||
|
|
@ -393,10 +453,16 @@ export default function QuizPage() {
|
|||
{full.length > 0 && (
|
||||
<>
|
||||
<span>
|
||||
Last <strong className="num text-ink">{last}%</strong>
|
||||
Last{' '}
|
||||
<strong className="num text-ink">
|
||||
{last !== null ? `${letterGrade(last)} · ${last}%` : '—'}
|
||||
</strong>
|
||||
</span>
|
||||
<span>
|
||||
Best <strong className="num text-ink">{best}%</strong>
|
||||
Best{' '}
|
||||
<strong className="num text-ink">
|
||||
{best !== null ? `${letterGrade(best)} · ${best}%` : '—'}
|
||||
</strong>
|
||||
</span>
|
||||
<span>{plural(history.length, 'attempt')}</span>
|
||||
</>
|
||||
|
|
@ -414,9 +480,11 @@ export default function QuizPage() {
|
|||
Resume ({data.activeAttempt.answeredCount}/{data.activeAttempt.questionCount})
|
||||
</Button>
|
||||
) : null}
|
||||
<Button variant={data.activeAttempt ? 'secondary' : 'primary'} size="lg" icon={<Play className="fill-current" />} disabled={questions.length === 0} onClick={() => setStartOpen(true)}>
|
||||
{data.activeAttempt ? 'Start new' : 'Start'}
|
||||
</Button>
|
||||
{tab !== 'start' && (
|
||||
<Button variant={data.activeAttempt ? 'secondary' : 'primary'} size="lg" icon={<Play className="fill-current" />} disabled={questions.length === 0} onClick={() => setStartOpen(true)}>
|
||||
{data.activeAttempt ? 'Start new' : 'Start'}
|
||||
</Button>
|
||||
)}
|
||||
<Menu
|
||||
trigger={
|
||||
<IconButton label="Quiz options" tooltip={false}>
|
||||
|
|
@ -488,6 +556,7 @@ export default function QuizPage() {
|
|||
onChange={setTab}
|
||||
label="View"
|
||||
options={[
|
||||
{ value: 'start', label: 'Start', icon: <Play /> },
|
||||
{ value: 'questions', label: `Questions`, icon: <ClipboardList /> },
|
||||
{ value: 'history', label: `History${history.length ? ` (${history.length})` : ''}`, icon: <History /> },
|
||||
]}
|
||||
|
|
@ -509,7 +578,14 @@ export default function QuizPage() {
|
|||
)}
|
||||
</div>
|
||||
|
||||
{tab === 'questions' ? (
|
||||
{tab === 'start' ? (
|
||||
<StartPanel
|
||||
quizId={quiz.id}
|
||||
total={questions.length}
|
||||
resume={data.activeAttempt ? { id: data.activeAttempt.id, answeredCount: data.activeAttempt.answeredCount, questionCount: data.activeAttempt.questionCount } : null}
|
||||
onShowQuestions={() => (questions.length === 0 ? beginNew() : setTab('questions'))}
|
||||
/>
|
||||
) : tab === 'questions' ? (
|
||||
<>
|
||||
{questions.length === 0 && editing !== 'new' ? (
|
||||
<div className="card border-dashed">
|
||||
|
|
@ -634,7 +710,7 @@ export default function QuizPage() {
|
|||
<>
|
||||
{full.length >= 2 && (
|
||||
<Callout className="mb-3" tone={last !== null && best !== null && last >= best ? 'good' : 'neutral'}>
|
||||
{last !== null && best !== null && last >= best ? `Your latest attempt (${last}%) is your best so far.` : `Latest ${last}%, best ${best}% across ${plural(full.length, 'full attempt')}.`}
|
||||
{last !== null && best !== null && last >= best ? `Your latest attempt (${letterGrade(last)}, ${last}%) is your best so far.` : `Latest ${last !== null ? `${letterGrade(last)} (${last}%)` : '—'}, best ${best !== null ? `${letterGrade(best)} (${best}%)` : '—'} across ${plural(full.length, 'full attempt')}.`}
|
||||
</Callout>
|
||||
)}
|
||||
<ul className="card divide-y divide-line">
|
||||
|
|
@ -644,7 +720,16 @@ export default function QuizPage() {
|
|||
return (
|
||||
<li key={h.id}>
|
||||
<Link to={`/session/${h.id}`} className="flex items-center gap-3 px-4 py-3 hover:bg-ink/4">
|
||||
<span className={cx('num grid h-10 w-14 shrink-0 place-items-center rounded-[10px] text-[15px] font-semibold', tone === 'good' ? 'bg-good-soft text-good' : tone === 'warn' ? 'bg-warn-soft text-warn' : tone === 'bad' ? 'bg-bad-soft text-bad' : 'bg-sunken text-ink-3')}>{p === null ? '—' : `${p}%`}</span>
|
||||
<span className={cx('num grid h-11 w-14 shrink-0 place-items-center rounded-[10px] leading-none font-semibold', tone === 'good' ? 'bg-good-soft text-good' : tone === 'warn' ? 'bg-warn-soft text-warn' : tone === 'bad' ? 'bg-bad-soft text-bad' : 'bg-sunken text-ink-3')}>
|
||||
{p === null ? (
|
||||
'—'
|
||||
) : (
|
||||
<span className="flex flex-col items-center gap-0.5">
|
||||
<span className="text-[16px]">{letterGrade(p)}</span>
|
||||
<span className="text-[11px] font-medium opacity-80">{p}%</span>
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="block text-sm font-medium">
|
||||
{h.completedAt ? formatDateTime(h.completedAt) : ''}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue