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

@ -0,0 +1,112 @@
/**
* DeepSeek — Chat Completions at https://api.deepseek.com.
* https://api-docs.deepseek.com/api/create-chat-completion/
* https://api-docs.deepseek.com/guides/thinking_mode/
*
* The wire format is OpenAI-compatible, so this reuses the compatible adapter's engine with
* the differences DeepSeek documents:
* - Thinking is ON by default. `thinking: {type: "disabled"}` turns it off;
* `reasoning_effort` accepts none / low / high / max.
* - In thinking mode `tool_choice: "required"` and named tool choices are rejected with a
* 400. Structured generation keeps thinking on (answer keys are noticeably more accurate
* with it) and asks for the tool call in the prompt with `tool_choice: "auto"`. Only when
* the effort is set to "none" is thinking off, and then the tool choice is forced.
* - When tools are present, the `reasoning_content` of every earlier assistant turn must be
* sent back, or the API answers 400. It is kept in `providerData` and replayed.
* - Usage reports `prompt_cache_hit_tokens`; cache hits are billed at a much lower rate.
* - `/models` lists context window, output limit, input modalities and effort levels.
*/
import { AIError, type ChatRequest, type DiscoveredModel, type ModelCapabilities, type ProviderAdapter, type ProviderConfig, type TestResult } from '../types.ts';
import { isChatModelId, nearestEffort, num, runTest, str, TEST_TIMEOUT_MS, withCatalogDefaults } from './common.ts';
import { isRecord, requestJson, trimBaseUrl } from './http.ts';
import { streamChatCompletions, type CompatOptions } from './openaiCompatible.ts';
export const DEEPSEEK_BASE_URL = 'https://api.deepseek.com';
const LABEL = 'DeepSeek';
const EFFORTS = ['low', 'high', 'max'] as const;
function base(cfg: ProviderConfig): string {
return trimBaseUrl(cfg.baseUrl?.trim() || DEEPSEEK_BASE_URL);
}
/** "none" turns thinking off; a model marked as not reasoning is treated the same way. */
function effortOf(req: ChatRequest): ChatRequest['reasoningEffort'] {
return req.capabilities?.reasoning === false ? 'none' : req.reasoningEffort;
}
function options(cfg: ProviderConfig): CompatOptions {
if (!cfg.apiKey) throw new AIError('not_configured', `Add your DeepSeek API key for "${cfg.name}" in Settings.`);
return {
kind: 'deepseek',
label: cfg.name || LABEL,
// DeepSeek serves the same API at the root and under /v1; the explicit /v1 keeps the
// compatible engine from guessing.
baseUrl: `${base(cfg)}/v1`,
apiKey: cfg.apiKey,
headers: cfg.headers,
replayReasoning: true,
forcedToolChoice: (req) => effortOf(req) === 'none',
adjustBody: (body, req) => {
const effort = effortOf(req);
delete body.reasoning_effort;
if (effort === 'none' || body.tool_choice === 'required' || isRecord(body.tool_choice)) {
// Non-thinking mode (also the only mode that accepts a forced tool choice).
body.thinking = { type: 'disabled' };
} else {
body.thinking = { type: 'enabled' };
if (effort) body.reasoning_effort = nearestEffort(effort, EFFORTS);
// Sampling parameters have no effect in thinking mode; leave them out.
delete body.temperature;
}
},
};
}
async function listModels(cfg: ProviderConfig, signal?: AbortSignal, timeoutMs?: number): Promise<DiscoveredModel[]> {
const o = options(cfg);
const res = await requestJson(`${base(cfg)}/models`, {
provider: o.label,
secrets: [o.apiKey, ...Object.values(o.headers ?? {})],
headers: { ...o.headers, Authorization: `Bearer ${o.apiKey}` },
signal,
firstByteTimeoutMs: timeoutMs,
totalTimeoutMs: timeoutMs,
});
const list = isRecord(res) && Array.isArray(res.data) ? res.data : [];
const found: DiscoveredModel[] = [];
for (const m of list) {
if (!isRecord(m)) continue;
const id = str(m.id);
if (!id || !isChatModelId(id)) continue;
const model: DiscoveredModel = { id };
if (str(m.name) && str(m.name) !== id) model.label = str(m.name);
if (num(m.context_window)) model.contextWindow = num(m.context_window);
if (num(m.max_output_tokens)) model.maxOutput = num(m.max_output_tokens);
const caps: Partial<ModelCapabilities> = { tools: true, pdf: false };
if (Array.isArray(m.input_modalities)) caps.vision = m.input_modalities.includes('image');
if (isRecord(m.effort)) caps.reasoning = true;
model.capabilities = caps;
found.push(model);
}
return withCatalogDefaults('deepseek', found);
}
async function test(cfg: ProviderConfig): Promise<TestResult> {
return runTest(cfg.name || LABEL, async () => ({ modelCount: (await listModels(cfg, undefined, TEST_TIMEOUT_MS)).length }));
}
export const deepseekAdapter: ProviderAdapter = {
kind: 'deepseek',
meta: {
label: 'DeepSeek',
defaultBaseUrl: DEEPSEEK_BASE_URL,
requiresApiKey: true,
requiresBaseUrl: false,
supportsDiscovery: true,
docsUrl: 'https://platform.deepseek.com/api_keys',
keyHint: 'Starts with sk-',
},
stream: (cfg, req) => streamChatCompletions(options(cfg), req),
listModels: (cfg, signal) => listModels(cfg, signal),
test,
};