Fourth revision: OpenRouter, live tool stages, Explain layout, share sections
All checks were successful
Verify and publish V2 container / build-and-push (push) Successful in 29s
All checks were successful
Verify and publish V2 container / build-and-push (push) Successful in 29s
- Interactive blocks are encouraged by default; Explain gets a reduced library and never writes practice questions. - Assistant tool steps breathe while running, show live stages from generation and the Python check, and read in the past tense when done. - The assistant asks before searching the web when class materials do not cover a question; clarifying questions list every class's exams and never ask about format (always NCLEX). - Explain opens beside the question from 900px wide, moving the question left while open and back on the next one. - Generate dialog drops the practice set/exam switch (presets cover it) and the Generate buttons lose their icon. - Python check notes are green when every check passed, applied fixes neutral. - Share pages group by exam, then Quizzes, Flashcards, Notes, Class Materials, hiding empty groups; the class page uses the same order. "Documents" is now "Class Materials". - OpenRouter provider replaces the Ollama type; migration 6 turns Ollama connections into OpenAI-compatible ones at /v1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
c595e0ff2c
commit
25bc03ea75
45 changed files with 663 additions and 329 deletions
|
|
@ -11,7 +11,7 @@ import { nearestEffort } from './common.ts';
|
|||
import { deepseekAdapter } from './deepseek.ts';
|
||||
import { toGeminiSchema, geminiAdapter } from './gemini.ts';
|
||||
import { parseSSE } from './http.ts';
|
||||
import { ollamaAdapter } from './ollama.ts';
|
||||
import { openrouterAdapter } from './openrouter.ts';
|
||||
import { openaiAdapter } from './openai.ts';
|
||||
import { normalizeCompatBase, openaiCompatibleAdapter } from './openaiCompatible.ts';
|
||||
|
||||
|
|
@ -368,16 +368,16 @@ const compatKit = chatCompletionsKit({
|
|||
model: 'meta/llama-3',
|
||||
streamUrl: 'https://router.example.com/api/v1/chat/completions',
|
||||
});
|
||||
const ollamaKit = chatCompletionsKit({
|
||||
name: 'ollama',
|
||||
adapter: ollamaAdapter,
|
||||
key: 'ollama-proxy-secret-1234',
|
||||
cfg: cfgOf('ollama', 'ollama-proxy-secret-1234'),
|
||||
model: 'llama3',
|
||||
streamUrl: 'http://localhost:11434/v1/chat/completions',
|
||||
const openrouterKit = chatCompletionsKit({
|
||||
name: 'openrouter',
|
||||
adapter: openrouterAdapter,
|
||||
key: 'sk-or-v1-TESTKEY-0987654321',
|
||||
cfg: cfgOf('openrouter', 'sk-or-v1-TESTKEY-0987654321'),
|
||||
model: 'meta-llama/llama-4-maverick',
|
||||
streamUrl: 'https://openrouter.ai/api/v1/chat/completions',
|
||||
});
|
||||
|
||||
const kits = [anthropicKit, openaiKit, geminiKit, compatKit, ollamaKit];
|
||||
const kits = [anthropicKit, openaiKit, geminiKit, compatKit, openrouterKit];
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* Shared behaviour across all five adapters */
|
||||
|
|
@ -728,7 +728,7 @@ describe('toGeminiSchema', () => {
|
|||
});
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* OpenAI-compatible and Ollama specifics */
|
||||
/* OpenAI-compatible specifics */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
describe('openai-compatible stream_options fallback', () => {
|
||||
|
|
@ -930,46 +930,57 @@ describe('openai-compatible listModels', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('ollama listModels', () => {
|
||||
it('uses /api/tags + /api/show, drops embedding-only models and keeps models whose /show fails', async () => {
|
||||
stubFetch((c) => {
|
||||
if (c.url.endsWith('/api/tags')) {
|
||||
return jsonResponse({
|
||||
models: [
|
||||
{ name: 'old:1b', model: 'old:1b' },
|
||||
{ name: 'nomic-embed-text:latest', model: 'nomic-embed-text:latest' },
|
||||
{ name: 'llama3:latest', model: 'llama3:latest' },
|
||||
],
|
||||
});
|
||||
}
|
||||
if (c.url.endsWith('/api/show')) {
|
||||
if (c.body.model === 'llama3:latest') return jsonResponse({ capabilities: ['completion', 'tools'], model_info: { 'llama.context_length': 8192 } });
|
||||
if (c.body.model === 'nomic-embed-text:latest') return jsonResponse({ capabilities: ['embedding'] });
|
||||
return jsonResponse({ error: 'unsupported' }, 404);
|
||||
}
|
||||
return new Response('?', { status: 404 });
|
||||
});
|
||||
const models = await ollamaAdapter.listModels(ollamaKit.cfg);
|
||||
expect(calls[0]!.url).toBe('http://localhost:11434/api/tags');
|
||||
expect(calls.filter((c) => c.url.endsWith('/api/show')).map((c) => c.method)).toEqual(['POST', 'POST', 'POST']);
|
||||
ollamaKit.assertAuth(calls[0]!.headers);
|
||||
expect(models).toEqual([
|
||||
{
|
||||
id: 'llama3:latest',
|
||||
label: 'llama3:latest',
|
||||
priceIn: 0,
|
||||
priceOut: 0,
|
||||
contextWindow: 8192,
|
||||
capabilities: { tools: true, vision: false, reasoning: false, pdf: false, temperature: true },
|
||||
},
|
||||
{ id: 'old:1b', label: 'old:1b', priceIn: 0, priceOut: 0 },
|
||||
]);
|
||||
describe('openrouter adapter', () => {
|
||||
it('sends reasoning as reasoning.effort, names the app and uses the default endpoint', async () => {
|
||||
stubFetch(queue(() => sseResponse(compatKit.text(['ok']))));
|
||||
await run(openrouterAdapter, openrouterKit.cfg, { model: 'deepseek/deepseek-v4-flash', messages: [user('hi')], reasoningEffort: 'high', capabilities: { reasoning: true } });
|
||||
expect(calls[0]!.url).toBe('https://openrouter.ai/api/v1/chat/completions');
|
||||
expect(calls[0]!.headers['X-Title']).toBe('Study Desk');
|
||||
expect(calls[0]!.body.reasoning).toEqual({ effort: 'high' });
|
||||
expect(calls[0]!.body.reasoning_effort).toBeUndefined();
|
||||
});
|
||||
|
||||
it('strips /v1 from a configured base URL', async () => {
|
||||
stubFetch(queue(() => jsonResponse({ models: [] })));
|
||||
await ollamaAdapter.listModels({ ...ollamaKit.cfg, baseUrl: 'http://box:11434/v1/' });
|
||||
expect(calls[0]!.url).toBe('http://box:11434/api/tags');
|
||||
it('sends no reasoning settings when the effort is "none"', async () => {
|
||||
stubFetch(queue(() => sseResponse(compatKit.text(['ok']))));
|
||||
await run(openrouterAdapter, openrouterKit.cfg, { model: 'x/y', messages: [user('hi')], reasoningEffort: 'none', capabilities: { reasoning: true } });
|
||||
expect(calls[0]!.body.reasoning).toBeUndefined();
|
||||
expect(calls[0]!.body.reasoning_effort).toBeUndefined();
|
||||
});
|
||||
|
||||
it('reads context, output limit, prices (with cache reads), tools and vision from /models', async () => {
|
||||
stubFetch(
|
||||
queue(() =>
|
||||
jsonResponse({
|
||||
data: [
|
||||
{
|
||||
id: 'anthropic/claude-sonnet-5-5',
|
||||
name: 'Anthropic: Claude Sonnet 5.5',
|
||||
context_length: 1_000_000,
|
||||
top_provider: { max_completion_tokens: 64_000 },
|
||||
pricing: { prompt: '0.000003', completion: '0.000015', input_cache_read: '0.0000003' },
|
||||
supported_parameters: ['tools', 'reasoning', 'max_tokens'],
|
||||
architecture: { input_modalities: ['text', 'image', 'file'] },
|
||||
},
|
||||
{ id: 'openai/text-embedding-3-small', name: 'Embedding', pricing: { prompt: '0.00000002', completion: '0' } },
|
||||
],
|
||||
}),
|
||||
),
|
||||
);
|
||||
const models = await openrouterAdapter.listModels(openrouterKit.cfg);
|
||||
expect(calls[0]!.url).toBe('https://openrouter.ai/api/v1/models');
|
||||
expect(models).toHaveLength(1);
|
||||
expect(models[0]).toMatchObject({ id: 'anthropic/claude-sonnet-5-5', label: 'Anthropic: Claude Sonnet 5.5', contextWindow: 1_000_000, maxOutput: 64_000, priceIn: 3, priceOut: 15, priceCachedIn: 0.3 });
|
||||
expect(models[0]!.capabilities).toMatchObject({ tools: true, reasoning: true, vision: true });
|
||||
});
|
||||
|
||||
it('tests the key with /key before counting models, and needs a key', async () => {
|
||||
stubFetch((c) => (c.url.endsWith('/key') ? jsonResponse({ data: { label: 'sk-or-v1-abc...', limit_remaining: 4.2 } }) : jsonResponse({ data: [{ id: 'a/b' }, { id: 'c/d' }] })));
|
||||
const result = await openrouterAdapter.test(openrouterKit.cfg);
|
||||
expect(calls.map((c) => c.url)).toEqual(['https://openrouter.ai/api/v1/key', 'https://openrouter.ai/api/v1/models']);
|
||||
expect(calls[0]!.headers.Authorization).toBe(`Bearer ${openrouterKit.key}`);
|
||||
expect(result).toMatchObject({ ok: true, modelCount: 2 });
|
||||
const missing = await failure(openrouterAdapter.listModels({ ...openrouterKit.cfg, apiKey: null }));
|
||||
expect(missing.code).toBe('not_configured');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -1012,7 +1023,7 @@ describe('lookupModelDefaults', () => {
|
|||
it('returns {} for unknown models and for kinds without a table', () => {
|
||||
expect(lookupModelDefaults('openai', 'totally-unknown-model')).toEqual({});
|
||||
expect(lookupModelDefaults('anthropic', '')).toEqual({});
|
||||
expect(lookupModelDefaults('ollama', 'llama3')).toEqual({});
|
||||
expect(lookupModelDefaults('openrouter', 'meta-llama/llama-4-maverick')).toEqual({});
|
||||
});
|
||||
it('borrows capabilities but not prices or temperature for router ids', () => {
|
||||
const d = lookupModelDefaults('openai_compatible', 'anthropic/claude-sonnet-5-5');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue