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
|
|
@ -105,13 +105,13 @@ export function uploadWithProgress<T>(url: string, form: FormData, onProgress: (
|
|||
});
|
||||
}
|
||||
|
||||
/** POSTs JSON and reads a server-sent event stream of JSON objects. */
|
||||
/** POSTs JSON (or GETs, when `body` is undefined) and reads a server-sent event stream of JSON objects. */
|
||||
export async function streamEvents<T extends { type: string }>(url: string, body: unknown, onEvent: (event: T) => void, signal?: AbortSignal): Promise<void> {
|
||||
const res = await fetch(url, {
|
||||
method: 'POST',
|
||||
method: body === undefined ? 'GET' : 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: { ...BASE_HEADERS, 'Content-Type': 'application/json', Accept: 'text/event-stream' },
|
||||
body: JSON.stringify(body),
|
||||
headers: body === undefined ? { ...BASE_HEADERS, Accept: 'text/event-stream' } : { ...BASE_HEADERS, 'Content-Type': 'application/json', Accept: 'text/event-stream' },
|
||||
body: body === undefined ? undefined : JSON.stringify(body),
|
||||
signal,
|
||||
});
|
||||
if (!res.ok || !res.body) {
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ const set = (patch: Partial<State>) => {
|
|||
listeners.forEach((fn) => fn());
|
||||
};
|
||||
let seedId = 0;
|
||||
/** The drawer's conversation, kept while the drawer is closed so reopening continues it. */
|
||||
let drawerConversation: string | null = null;
|
||||
|
||||
export const assistant = {
|
||||
/** Opens the assistant, optionally with a prepared prompt. */
|
||||
|
|
@ -39,6 +41,12 @@ export const assistant = {
|
|||
consumeSeed() {
|
||||
if (state.seed) set({ seed: null });
|
||||
},
|
||||
get drawerConversation() {
|
||||
return drawerConversation;
|
||||
},
|
||||
rememberDrawerConversation(id: string | null) {
|
||||
drawerConversation = id;
|
||||
},
|
||||
setContext(context: State['context']) {
|
||||
const cur = state.context;
|
||||
if (cur.classId === context.classId && cur.label === context.label && cur.documentIds.join() === context.documentIds.join()) return;
|
||||
|
|
|
|||
|
|
@ -339,7 +339,7 @@ export interface ShareListItem extends Share {
|
|||
|
||||
/* ------------------------------ AI ------------------------------ */
|
||||
|
||||
export type ProviderKind = 'openai' | 'anthropic' | 'gemini' | 'openai_compatible' | 'ollama';
|
||||
export type ProviderKind = 'openai' | 'anthropic' | 'gemini' | 'deepseek' | 'openai_compatible' | 'ollama';
|
||||
export interface AdapterMeta {
|
||||
kind: ProviderKind;
|
||||
label: string;
|
||||
|
|
@ -386,12 +386,26 @@ export interface AiModel {
|
|||
maxOutput: number | null;
|
||||
priceIn: number | null;
|
||||
priceOut: number | null;
|
||||
/** USD per million cached input tokens; null = the provider's usual cache discount. */
|
||||
priceCachedIn: number | null;
|
||||
}
|
||||
export type TaskName = 'chat' | 'generate' | 'vision' | 'quick';
|
||||
/** Reasoning effort levels, lowest to highest. Each provider maps them onto what it accepts. */
|
||||
export const REASONING_EFFORTS = [
|
||||
{ value: 'none', label: 'Off' },
|
||||
{ value: 'minimal', label: 'Minimal' },
|
||||
{ value: 'low', label: 'Low' },
|
||||
{ value: 'medium', label: 'Medium' },
|
||||
{ value: 'high', label: 'High' },
|
||||
{ value: 'xhigh', label: 'Extra high' },
|
||||
{ value: 'max', label: 'Max' },
|
||||
] as const;
|
||||
export type ReasoningEffort = (typeof REASONING_EFFORTS)[number]['value'];
|
||||
|
||||
export interface TaskConfig {
|
||||
modelId: string | null;
|
||||
temperature: number | null;
|
||||
reasoningEffort: 'none' | 'low' | 'medium' | 'high' | null;
|
||||
reasoningEffort: ReasoningEffort | null;
|
||||
maxOutputTokens: number | null;
|
||||
}
|
||||
export type TaskSettings = Record<TaskName | 'default', TaskConfig>;
|
||||
|
|
@ -444,10 +458,22 @@ export interface ToolActivity {
|
|||
status: 'running' | 'done' | 'error';
|
||||
summary?: string;
|
||||
}
|
||||
export type TagKind = 'quiz' | 'deck' | 'note' | 'document' | 'folder';
|
||||
export interface TaggedItem {
|
||||
kind: TagKind;
|
||||
id: string;
|
||||
title: string;
|
||||
}
|
||||
export interface Mentionable extends TaggedItem {
|
||||
className: string;
|
||||
classColor: string;
|
||||
folderName?: string;
|
||||
}
|
||||
export interface ChatMessage {
|
||||
id: number | string;
|
||||
role: 'user' | 'assistant';
|
||||
text: string;
|
||||
tags?: TaggedItem[];
|
||||
tools: ToolActivity[];
|
||||
ui: UiItem[];
|
||||
model?: string;
|
||||
|
|
@ -472,6 +498,8 @@ export interface Template {
|
|||
description: string;
|
||||
payload: Record<string, any>;
|
||||
builtin: boolean;
|
||||
/** A built-in template the user has changed. */
|
||||
edited?: boolean;
|
||||
updatedAt: number;
|
||||
}
|
||||
|
||||
|
|
@ -514,6 +542,6 @@ export interface PublicCollection {
|
|||
description?: string;
|
||||
color: ClassColor;
|
||||
folders: { id: string; name: string }[];
|
||||
items: { kind: 'quiz' | 'deck' | 'note'; id: string; title: string; description: string; folderId: string | null; count: number }[];
|
||||
items: { kind: 'quiz' | 'deck' | 'note' | 'document'; id: string; title: string; description: string; folderId: string | null; count: number }[];
|
||||
}
|
||||
export type PublicPayload = PublicQuiz | PublicDeck | PublicNote | PublicDocument | PublicCollection;
|
||||
|
|
|
|||
|
|
@ -72,10 +72,12 @@ export function formatCost(n: number | null | undefined): string {
|
|||
return `$${n.toFixed(2)}`;
|
||||
}
|
||||
|
||||
/** Tone on the 7-point scale: A/B (85+) good, C (77-84) passing, D/F failing. */
|
||||
export function gradeTone(percent: number | null): 'good' | 'warn' | 'bad' | 'none' {
|
||||
if (percent === null) return 'none';
|
||||
if (percent >= 80) return 'good';
|
||||
if (percent >= 60) return 'warn';
|
||||
const p = Math.round(percent);
|
||||
if (p >= 85) return 'good';
|
||||
if (p >= 77) return 'warn';
|
||||
return 'bad';
|
||||
}
|
||||
|
||||
|
|
@ -100,25 +102,43 @@ export function downloadText(filename: string, text: string, mime = 'application
|
|||
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies text to the clipboard. The async Clipboard API only exists on secure origins
|
||||
* (HTTPS or localhost), so a self-hosted server opened over plain HTTP falls back to a hidden
|
||||
* textarea and `execCommand('copy')`. That textarea is placed inside the open dialog, if any:
|
||||
* dialogs trap focus, and a textarea outside the trap cannot be focused or selected, which
|
||||
* made every copy button inside a dialog silently fail.
|
||||
*/
|
||||
export async function copyText(text: string): Promise<boolean> {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
return true;
|
||||
} catch {
|
||||
if (navigator.clipboard?.writeText && window.isSecureContext) {
|
||||
try {
|
||||
const ta = document.createElement('textarea');
|
||||
ta.value = text;
|
||||
ta.style.position = 'fixed';
|
||||
ta.style.opacity = '0';
|
||||
document.body.appendChild(ta);
|
||||
ta.select();
|
||||
const ok = document.execCommand('copy');
|
||||
ta.remove();
|
||||
return ok;
|
||||
await navigator.clipboard.writeText(text);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
/* permission denied or document not focused: try the fallback */
|
||||
}
|
||||
}
|
||||
const previous = document.activeElement as HTMLElement | null;
|
||||
const host = (previous?.closest('[role="dialog"], [role="alertdialog"]') as HTMLElement | null) ?? document.querySelector<HTMLElement>('[role="dialog"][data-state="open"]') ?? document.body;
|
||||
const ta = document.createElement('textarea');
|
||||
ta.value = text;
|
||||
ta.setAttribute('readonly', '');
|
||||
ta.setAttribute('aria-hidden', 'true');
|
||||
Object.assign(ta.style, { position: 'fixed', top: '0', left: '0', width: '1px', height: '1px', padding: '0', border: '0', opacity: '0', pointerEvents: 'none' });
|
||||
host.appendChild(ta);
|
||||
let ok = false;
|
||||
try {
|
||||
ta.focus({ preventScroll: true });
|
||||
ta.select();
|
||||
ta.setSelectionRange(0, text.length);
|
||||
ok = document.execCommand('copy');
|
||||
} catch {
|
||||
ok = false;
|
||||
} finally {
|
||||
ta.remove();
|
||||
previous?.focus?.({ preventScroll: true });
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
export function shuffle<T>(items: readonly T[]): T[] {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue