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
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:
parent
5ea61c882c
commit
031f7bec31
45 changed files with 2918 additions and 397 deletions
129
web/src/features/SharedAssistant.tsx
Normal file
129
web/src/features/SharedAssistant.tsx
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
import { CornerDownLeft, MessageCircleQuestion, Sparkles, Square, X } from 'lucide-react';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { errorMessage, streamEvents } from '@/lib/api';
|
||||
import { cx } from '@/lib/util';
|
||||
import { Markdown } from '@/ui/Markdown';
|
||||
import { Button, Callout, IconButton, Spinner } from '@/ui';
|
||||
|
||||
type Event = { type: 'text'; delta: string } | { type: 'error'; message: string } | { type: 'done' };
|
||||
interface Turn {
|
||||
role: 'user' | 'assistant';
|
||||
text: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* The visitor-facing assistant on a share link (when the owner allows it). It answers from the
|
||||
* shared material only; the conversation lives in this tab and is never saved on the server.
|
||||
*/
|
||||
export function SharedAssistant({ token, title, item }: { token: string; title: string; item?: { kind: 'quiz' | 'deck' | 'note' | 'document'; id: string } }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [turns, setTurns] = useState<Turn[]>([]);
|
||||
const [input, setInput] = useState('');
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
const abort = useRef<AbortController | null>(null);
|
||||
const list = useRef<HTMLDivElement>(null);
|
||||
|
||||
useEffect(() => () => abort.current?.abort(), []);
|
||||
useEffect(() => {
|
||||
const el = list.current;
|
||||
if (el) el.scrollTop = el.scrollHeight;
|
||||
}, [turns, open]);
|
||||
|
||||
const send = async (text: string) => {
|
||||
// The server accepts the last 16 turns; older ones are dropped from the request.
|
||||
const history: Turn[] = [...turns, { role: 'user' as const, text }].slice(-15);
|
||||
setTurns([...turns, { role: 'user', text }, { role: 'assistant', text: '' }]);
|
||||
setBusy(true);
|
||||
setError('');
|
||||
const controller = new AbortController();
|
||||
abort.current = controller;
|
||||
try {
|
||||
await streamEvents<Event>(
|
||||
`/api/public/${token}/chat`,
|
||||
{ messages: history.filter((t) => t.text.trim()), item },
|
||||
(e) => {
|
||||
if (e.type === 'text') setTurns((t) => t.map((x, i) => (i === t.length - 1 ? { ...x, text: x.text + e.delta } : x)));
|
||||
else if (e.type === 'error') setError(e.message);
|
||||
},
|
||||
controller.signal,
|
||||
);
|
||||
} catch (e) {
|
||||
if ((e as Error)?.name !== 'AbortError') setError(errorMessage(e));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
// Drop an empty reply so the next request stays valid.
|
||||
setTurns((t) => (t[t.length - 1]?.role === 'assistant' && !t[t.length - 1].text ? t.slice(0, -1) : t));
|
||||
}
|
||||
};
|
||||
|
||||
if (!open) {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setOpen(true)}
|
||||
className="fixed right-4 bottom-28 z-40 flex h-11 items-center gap-2 rounded-full bg-ink px-4 text-sm font-semibold text-paper shadow-2 hover:bg-ink/90 sm:right-6"
|
||||
>
|
||||
<MessageCircleQuestion className="size-[18px]" /> Ask about this
|
||||
</button>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<section aria-label="Study assistant" className="fixed right-4 bottom-4 z-40 flex h-[min(560px,calc(100dvh-2rem))] w-[min(420px,calc(100vw-2rem))] flex-col overflow-hidden rounded-[18px] border border-line bg-surface shadow-2 sm:right-6">
|
||||
<header className="flex items-center gap-2 border-b border-line px-4 py-2.5">
|
||||
<Sparkles className="size-4 text-accent" />
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="text-sm font-semibold">Ask about this</div>
|
||||
<div className="truncate text-xs text-ink-3">{title}</div>
|
||||
</div>
|
||||
<IconButton label="Close" onClick={() => setOpen(false)}>
|
||||
<X />
|
||||
</IconButton>
|
||||
</header>
|
||||
<div ref={list} className="flex-1 space-y-3 overflow-y-auto px-4 py-3">
|
||||
{turns.length === 0 && <p className="text-[13.5px] text-ink-2">Ask a question about this material: what something means, why an answer is right, or for a quick recap.</p>}
|
||||
{turns.map((t, i) =>
|
||||
t.role === 'user' ? (
|
||||
<div key={i} className="ml-8 rounded-[14px] bg-accent-soft px-3 py-2 text-[14px] whitespace-pre-wrap">
|
||||
{t.text}
|
||||
</div>
|
||||
) : t.text ? (
|
||||
<Markdown key={i} className="text-[14px]">
|
||||
{t.text}
|
||||
</Markdown>
|
||||
) : busy && i === turns.length - 1 ? (
|
||||
<Spinner key={i} className="size-4" label="Thinking" />
|
||||
) : null,
|
||||
)}
|
||||
{error && (
|
||||
<Callout tone="bad" className="py-2">
|
||||
{error}
|
||||
</Callout>
|
||||
)}
|
||||
</div>
|
||||
<form
|
||||
className="flex gap-2 border-t border-line p-3"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
if (busy) return abort.current?.abort();
|
||||
const text = input.trim();
|
||||
if (!text) return;
|
||||
setInput('');
|
||||
void send(text.slice(0, 4000));
|
||||
}}
|
||||
>
|
||||
<input
|
||||
value={input}
|
||||
onChange={(e) => setInput(e.target.value)}
|
||||
placeholder="Ask a question…"
|
||||
aria-label="Your question"
|
||||
className={cx('h-10 min-w-0 flex-1 rounded-[10px] border border-line-strong bg-paper px-3 text-sm outline-none focus:border-accent')}
|
||||
/>
|
||||
<Button type="submit" variant={busy ? 'secondary' : 'primary'} icon={busy ? <Square className="fill-current" /> : <CornerDownLeft />} aria-label={busy ? 'Stop' : 'Send'}>
|
||||
{busy ? 'Stop' : 'Send'}
|
||||
</Button>
|
||||
</form>
|
||||
<p className="px-4 pb-2.5 text-[11px] text-ink-3">AI can be wrong. Nothing you type here is saved.</p>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue