Start Study Desk V2: remove V1 sources, add backend foundation
V1 remains intact on main and in history. This branch replaces it with a new application: node:sqlite storage with migrations, scrypt auth and sessions, content/SRS/attempt/stats services, document extraction and chunking, a provider-neutral AI layer (OpenAI, Anthropic, Gemini, OpenAI-compatible, Ollama), the generation pipeline and the tool-using assistant. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
parent
7bd0a9aad4
commit
3e74ecd843
268 changed files with 17740 additions and 55423 deletions
206
server/ai/providers/catalog.ts
Normal file
206
server/ai/providers/catalog.ts
Normal file
|
|
@ -0,0 +1,206 @@
|
|||
/**
|
||||
* Static defaults for well-known models: capabilities, limits and list prices.
|
||||
*
|
||||
* Discovery APIs return ids (and sometimes limits) but almost never prices or
|
||||
* feature flags, so `listModels` merges its results with this table. Unknown
|
||||
* models simply get no defaults — nothing here is required for a model to work.
|
||||
*
|
||||
* Everything below was read from the official pages listed per provider on the
|
||||
* dates noted. Prices are USD per million tokens, standard (non-batch,
|
||||
* non-priority) tier, short-context tier where a provider has several. A field
|
||||
* is omitted when it could not be confirmed from the page — do not guess.
|
||||
*/
|
||||
import type { DiscoveredModel, ModelCapabilities, ProviderKind } from '../types.ts';
|
||||
|
||||
export const CATALOG_UPDATED = '2026-11-10';
|
||||
|
||||
type Entry = Omit<DiscoveredModel, 'id' | 'capabilities'> & { capabilities?: Partial<ModelCapabilities> };
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* OpenAI */
|
||||
/* Prices: https://developers.openai.com/api/docs/pricing (fetched 2026-11-11)
|
||||
/* Limits: https://developers.openai.com/api/docs/models (fetched 2026-11-11;
|
||||
/* only the four current flagship models list limits there — the
|
||||
/* limits on older models below are the long-published values and were
|
||||
/* not re-fetched)
|
||||
/* Reasoning models reject a custom `temperature`, hence temperature:false.
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
const OA_REASONING: Partial<ModelCapabilities> = { tools: true, vision: true, pdf: true, reasoning: true, temperature: false };
|
||||
const OA_CLASSIC: Partial<ModelCapabilities> = { tools: true, vision: true, pdf: true, reasoning: false, temperature: true };
|
||||
const OA_FLAGSHIP_LIMITS = { contextWindow: 1_050_000, maxOutput: 128_000 };
|
||||
|
||||
const OPENAI: Record<string, Entry> = {
|
||||
'gpt-6-astra': { label: 'GPT-6 Astra', ...OA_FLAGSHIP_LIMITS, priceIn: 10, priceOut: 50, capabilities: OA_REASONING },
|
||||
'gpt-6.1-sol': { label: 'GPT-6.1 Sol', ...OA_FLAGSHIP_LIMITS, priceIn: 2, priceOut: 10, capabilities: OA_REASONING },
|
||||
'gpt-6.1-terra': { label: 'GPT-6.1 Terra', ...OA_FLAGSHIP_LIMITS, priceIn: 1, priceOut: 5, capabilities: OA_REASONING },
|
||||
'gpt-6-luna': { label: 'GPT-6 Luna', ...OA_FLAGSHIP_LIMITS, priceIn: 0.1, priceOut: 0.5, capabilities: OA_REASONING },
|
||||
'gpt-6-sol': { label: 'GPT-6 Sol', priceIn: 2, priceOut: 10, capabilities: OA_REASONING },
|
||||
'gpt-5.6-sol': { label: 'GPT-5.6 Sol', priceIn: 4, priceOut: 20, capabilities: OA_REASONING },
|
||||
'gpt-5.6-terra': { label: 'GPT-5.6 Terra', priceIn: 2, priceOut: 12, capabilities: OA_REASONING },
|
||||
'gpt-5.6-luna': { label: 'GPT-5.6 Luna', priceIn: 0.2, priceOut: 1.2, capabilities: OA_REASONING },
|
||||
'gpt-5.5': { label: 'GPT-5.5', priceIn: 5, priceOut: 30, capabilities: OA_REASONING },
|
||||
'gpt-5.5-pro': { label: 'GPT-5.5 Pro', priceIn: 30, priceOut: 180, capabilities: OA_REASONING },
|
||||
'gpt-5.4': { label: 'GPT-5.4', priceIn: 2.5, priceOut: 15, capabilities: OA_REASONING },
|
||||
'gpt-5.4-pro': { label: 'GPT-5.4 Pro', priceIn: 30, priceOut: 180, capabilities: OA_REASONING },
|
||||
'gpt-5.4-mini': { label: 'GPT-5.4 mini', priceIn: 0.75, priceOut: 4.5, capabilities: OA_REASONING },
|
||||
'gpt-5.4-nano': { label: 'GPT-5.4 nano', priceIn: 0.2, priceOut: 1.25, capabilities: OA_REASONING },
|
||||
'gpt-5.3-codex': { label: 'GPT-5.3 Codex', priceIn: 1.75, priceOut: 14, capabilities: OA_REASONING },
|
||||
'gpt-5.2': { label: 'GPT-5.2', priceIn: 1.75, priceOut: 14, capabilities: OA_REASONING },
|
||||
'gpt-5.2-pro': { label: 'GPT-5.2 Pro', priceIn: 21, priceOut: 168, capabilities: OA_REASONING },
|
||||
'gpt-5.1': { label: 'GPT-5.1', priceIn: 1.25, priceOut: 10, capabilities: OA_REASONING },
|
||||
'gpt-5': { label: 'GPT-5', contextWindow: 400_000, maxOutput: 128_000, priceIn: 1.25, priceOut: 10, capabilities: OA_REASONING },
|
||||
'gpt-5-mini': { label: 'GPT-5 mini', contextWindow: 400_000, maxOutput: 128_000, priceIn: 0.25, priceOut: 2, capabilities: OA_REASONING },
|
||||
'gpt-5-nano': { label: 'GPT-5 nano', contextWindow: 400_000, maxOutput: 128_000, priceIn: 0.05, priceOut: 0.4, capabilities: OA_REASONING },
|
||||
'gpt-5-pro': { label: 'GPT-5 Pro', priceIn: 15, priceOut: 120, capabilities: OA_REASONING },
|
||||
'chat-latest': { label: 'ChatGPT (latest)', priceIn: 5, priceOut: 30, capabilities: OA_CLASSIC },
|
||||
'gpt-4.1': { label: 'GPT-4.1', contextWindow: 1_047_576, maxOutput: 32_768, priceIn: 2, priceOut: 8, capabilities: OA_CLASSIC },
|
||||
'gpt-4.1-mini': { label: 'GPT-4.1 mini', contextWindow: 1_047_576, maxOutput: 32_768, priceIn: 0.4, priceOut: 1.6, capabilities: OA_CLASSIC },
|
||||
'gpt-4o': { label: 'GPT-4o', contextWindow: 128_000, maxOutput: 16_384, priceIn: 2.5, priceOut: 10, capabilities: OA_CLASSIC },
|
||||
'gpt-4o-mini': { label: 'GPT-4o mini', contextWindow: 128_000, maxOutput: 16_384, priceIn: 0.15, priceOut: 0.6, capabilities: OA_CLASSIC },
|
||||
o3: { label: 'o3', contextWindow: 200_000, maxOutput: 100_000, priceIn: 2, priceOut: 8, capabilities: OA_REASONING },
|
||||
'o3-pro': { label: 'o3-pro', contextWindow: 200_000, maxOutput: 100_000, priceIn: 20, priceOut: 80, capabilities: OA_REASONING },
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* Anthropic */
|
||||
/* Prices: https://platform.claude.com/docs/en/about-claude/pricing (fetched 2026-11-11)
|
||||
/* Ids and limits: https://platform.claude.com/docs/en/about-claude/models/overview
|
||||
/* (via Anthropic's Claude API reference, cached 2026-11-03)
|
||||
/* temperature:false for every Claude model: the adapter speaks API version
|
||||
/* 2026-10-21, which rejects temperature/top_p/top_k on all models
|
||||
/* (https://platform.claude.com/docs/en/api/migration-2026-10-21).
|
||||
/* Claude Haiku 5.5 prices are for prompts up to 100K tokens ($0.50/$2.50 above).
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
const CLAUDE: Partial<ModelCapabilities> = { tools: true, vision: true, pdf: true, reasoning: true, temperature: false };
|
||||
const CLAUDE_1M = { contextWindow: 1_000_000, maxOutput: 128_000 };
|
||||
|
||||
const ANTHROPIC: Record<string, Entry> = {
|
||||
'claude-fable-5-2': { label: 'Claude Fable 5.2', ...CLAUDE_1M, priceIn: 8, priceOut: 40, capabilities: CLAUDE },
|
||||
'claude-mythos-5-2': { label: 'Claude Mythos 5.2', ...CLAUDE_1M, priceIn: 8, priceOut: 40, capabilities: CLAUDE },
|
||||
'claude-fable-5-1': { label: 'Claude Fable 5.1', ...CLAUDE_1M, priceIn: 10, priceOut: 50, capabilities: CLAUDE },
|
||||
'claude-mythos-5-1': { label: 'Claude Mythos 5.1', ...CLAUDE_1M, priceIn: 10, priceOut: 50, capabilities: CLAUDE },
|
||||
'claude-fable-5': { label: 'Claude Fable 5', ...CLAUDE_1M, priceIn: 10, priceOut: 50, capabilities: CLAUDE },
|
||||
'claude-mythos-5': { label: 'Claude Mythos 5', ...CLAUDE_1M, priceIn: 10, priceOut: 50, capabilities: CLAUDE },
|
||||
'claude-opus-5-5': { label: 'Claude Opus 5.5', ...CLAUDE_1M, priceIn: 4, priceOut: 20, capabilities: CLAUDE },
|
||||
'claude-opus-5': { label: 'Claude Opus 5', ...CLAUDE_1M, priceIn: 5, priceOut: 25, capabilities: CLAUDE },
|
||||
'claude-opus-4-8': { label: 'Claude Opus 4.8', ...CLAUDE_1M, priceIn: 5, priceOut: 25, capabilities: CLAUDE },
|
||||
'claude-opus-4-7': { label: 'Claude Opus 4.7', ...CLAUDE_1M, priceIn: 5, priceOut: 25, capabilities: CLAUDE },
|
||||
'claude-opus-4-6': { label: 'Claude Opus 4.6', ...CLAUDE_1M, priceIn: 5, priceOut: 25, capabilities: CLAUDE },
|
||||
'claude-opus-4-5': { label: 'Claude Opus 4.5', priceIn: 5, priceOut: 25, capabilities: CLAUDE },
|
||||
'claude-sonnet-5-5': { label: 'Claude Sonnet 5.5', ...CLAUDE_1M, priceIn: 2, priceOut: 10, capabilities: CLAUDE },
|
||||
'claude-sonnet-5': { label: 'Claude Sonnet 5', ...CLAUDE_1M, priceIn: 2, priceOut: 10, capabilities: CLAUDE },
|
||||
'claude-sonnet-4-6': { label: 'Claude Sonnet 4.6', ...CLAUDE_1M, priceIn: 3, priceOut: 15, capabilities: CLAUDE },
|
||||
'claude-sonnet-4-5': { label: 'Claude Sonnet 4.5', priceIn: 3, priceOut: 15, capabilities: CLAUDE },
|
||||
'claude-haiku-5-5': { label: 'Claude Haiku 5.5', ...CLAUDE_1M, priceIn: 0.1, priceOut: 0.5, capabilities: CLAUDE },
|
||||
'claude-haiku-4-5': { label: 'Claude Haiku 4.5', contextWindow: 200_000, maxOutput: 64_000, priceIn: 1, priceOut: 5, capabilities: CLAUDE },
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* Google Gemini */
|
||||
/* Prices: https://ai.google.dev/gemini-api/docs/pricing (fetched 2026-11-11,
|
||||
/* now served from https://aistudio.google.com/docs/pricing)
|
||||
/* Limits: https://ai.google.dev/gemini-api/docs/models (fetched 2026-11-11;
|
||||
/* only the Gemini 4 models list limits — `GET /v1beta/models`
|
||||
/* supplies inputTokenLimit/outputTokenLimit for the rest at runtime)
|
||||
/* Scheduled changes announced on the pricing page (NOT applied here):
|
||||
/* - gemini-4-carbon / gemini-4-argon: $4 / $20 from 2026-12-01
|
||||
/* - gemini-3.8-flash / gemini-3.6-flash: $1.50 / $7.50 from 2027-01-01
|
||||
/* - gemini-2.5-pro / gemini-2.5-flash are deprecated and are routed to
|
||||
/* gemini-3.8-flash / gemini-3.5-flash-lite (and billed as such) from 2026-12-01
|
||||
/* Pro-tier prices are for prompts up to 200K tokens.
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
const GEMINI_CAPS: Partial<ModelCapabilities> = { tools: true, vision: true, pdf: true, reasoning: true, temperature: true };
|
||||
const GEMINI_4_LIMITS = { contextWindow: 1_048_576, maxOutput: 65_536 };
|
||||
|
||||
const GEMINI: Record<string, Entry> = {
|
||||
'gemini-4-carbon': { label: 'Gemini 4 Carbon', ...GEMINI_4_LIMITS, priceIn: 2, priceOut: 10, capabilities: GEMINI_CAPS },
|
||||
'gemini-4-argon': { label: 'Gemini 4 Argon', ...GEMINI_4_LIMITS, priceIn: 2, priceOut: 10, capabilities: GEMINI_CAPS },
|
||||
'gemini-3.8-flash': { label: 'Gemini 3.8 Flash', priceIn: 0.75, priceOut: 3.75, capabilities: GEMINI_CAPS },
|
||||
'gemini-3.6-flash': { label: 'Gemini 3.6 Flash', priceIn: 0.75, priceOut: 3.75, capabilities: GEMINI_CAPS },
|
||||
'gemini-3.5-flash-lite': { label: 'Gemini 3.5 Flash-Lite', priceIn: 0.3, priceOut: 2.5, capabilities: GEMINI_CAPS },
|
||||
'gemini-3.1-pro-preview': { label: 'Gemini 3.1 Pro (preview)', priceIn: 2, priceOut: 12, capabilities: GEMINI_CAPS },
|
||||
'gemini-3.1-flash-lite': { label: 'Gemini 3.1 Flash-Lite', priceIn: 0.25, priceOut: 1.5, capabilities: GEMINI_CAPS },
|
||||
'gemini-3-flash-preview': { label: 'Gemini 3 Flash (preview)', priceIn: 0.5, priceOut: 3, capabilities: GEMINI_CAPS },
|
||||
'gemini-2.5-pro': { label: 'Gemini 2.5 Pro', priceIn: 1.25, priceOut: 10, capabilities: GEMINI_CAPS },
|
||||
'gemini-2.5-flash': { label: 'Gemini 2.5 Flash', priceIn: 0.3, priceOut: 2.5, capabilities: GEMINI_CAPS },
|
||||
'gemini-2.5-flash-lite': { label: 'Gemini 2.5 Flash-Lite', priceIn: 0.1, priceOut: 0.4, capabilities: GEMINI_CAPS },
|
||||
};
|
||||
|
||||
const TABLES: Record<ProviderKind, Record<string, Entry>> = {
|
||||
openai: OPENAI,
|
||||
anthropic: ANTHROPIC,
|
||||
gemini: GEMINI,
|
||||
// Aggregators and local servers host arbitrary models at their own prices.
|
||||
openai_compatible: {},
|
||||
ollama: {},
|
||||
};
|
||||
|
||||
/**
|
||||
* What may follow a known id for it to still be "the same model at the same
|
||||
* price": a dated snapshot or a moving alias, e.g. `gpt-5-2025-08-07`,
|
||||
* `claude-haiku-4-5-20251001`, `claude-opus-4-5@20251101`, `gemini-2.5-flash-latest`.
|
||||
*/
|
||||
const SNAPSHOT_SUFFIX = /^[-@:](\d{4}-\d{2}-\d{2}|\d{6,8}|\d{3,4}|latest|preview|preview-\d{2}-\d{2,4}|v\d+(:\d+)?)$/;
|
||||
|
||||
function clone(e: Entry): Partial<DiscoveredModel> {
|
||||
return { ...e, ...(e.capabilities ? { capabilities: { ...e.capabilities } } : {}) };
|
||||
}
|
||||
|
||||
function lookupIn(table: Record<string, Entry>, id: string): Partial<DiscoveredModel> {
|
||||
const exact = table[id];
|
||||
if (exact) return clone(exact);
|
||||
|
||||
// Longest known id that is a prefix of `id` and ends on a separator.
|
||||
let best = '';
|
||||
for (const key of Object.keys(table)) {
|
||||
if (key.length > best.length && id.startsWith(key) && /[-@:]/.test(id.charAt(key.length))) best = key;
|
||||
}
|
||||
if (!best) return {};
|
||||
const entry = table[best];
|
||||
if (!entry) return {};
|
||||
const out = clone(entry);
|
||||
delete out.label; // the label names the base model, not this variant
|
||||
if (!SNAPSHOT_SUFFIX.test(id.slice(best.length))) {
|
||||
// A genuinely different variant (`o3-deep-research`, `gpt-4o-audio-...`):
|
||||
// capabilities are a fair guess, the price is not.
|
||||
delete out.priceIn;
|
||||
delete out.priceOut;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defaults for a model: exact id first, then the longest known id that prefixes
|
||||
* it (so dated snapshots match their base model). Returns `{}` when unknown.
|
||||
*/
|
||||
export function lookupModelDefaults(kind: ProviderKind, modelId: string): Partial<DiscoveredModel> {
|
||||
// Gemini's listing names models "models/<id>".
|
||||
const id = modelId.trim().replace(/^models\//, '');
|
||||
if (!id) return {};
|
||||
|
||||
if (kind === 'openai_compatible') {
|
||||
// Routers name models "<vendor>/<model>" (`anthropic/claude-sonnet-5-5`).
|
||||
// Borrow capabilities and limits from the vendor's table, never its prices.
|
||||
const bare = id.slice(id.lastIndexOf('/') + 1).replace(/:[a-z]+$/, '');
|
||||
for (const table of [OPENAI, ANTHROPIC, GEMINI]) {
|
||||
const hit = lookupIn(table, bare);
|
||||
if (Object.keys(hit).length > 0) {
|
||||
delete hit.priceIn;
|
||||
delete hit.priceOut;
|
||||
// Temperature limits are properties of the first-party APIs, not of the router.
|
||||
if (hit.capabilities) delete hit.capabilities.temperature;
|
||||
return hit;
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
return lookupIn(TABLES[kind], id);
|
||||
}
|
||||
|
||||
/** Every catalogued model id for a provider (used as a fallback list when discovery is unavailable). */
|
||||
export function catalogModelIds(kind: ProviderKind): string[] {
|
||||
return Object.keys(TABLES[kind]);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue