From 79e94f37f044bc4504e2d38f1dcbdbc78ab50001 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Sun, 18 Oct 2026 13:07:03 +0200 Subject: [PATCH] OpenRouter reasoning from the model list (supported_parameters), effort sent as reasoning.effort; API pictures on by default --- apps/host/server/agent/profile.mjs | 18 +++-- apps/host/server/index.mjs | 19 +++-- apps/host/server/model-providers.mjs | 6 +- apps/host/server/vision-probe.mjs | 35 +++++++-- apps/host/src/components/ComposerControls.tsx | 6 +- apps/host/src/lib/types.ts | 2 +- apps/host/tests/agent-shape.test.mjs | 6 +- apps/host/tests/openrouter-reasoning.test.mjs | 77 +++++++++++++++++++ apps/host/tests/vision-probe.test.mjs | 4 +- 9 files changed, 140 insertions(+), 33 deletions(-) create mode 100644 apps/host/tests/openrouter-reasoning.test.mjs diff --git a/apps/host/server/agent/profile.mjs b/apps/host/server/agent/profile.mjs index fc25fb3b..b82be830 100644 --- a/apps/host/server/agent/profile.mjs +++ b/apps/host/server/agent/profile.mjs @@ -130,6 +130,13 @@ export function compactionHeadroom(context, outputBudget) { export const LOCAL_EFFORTS = Object.freeze({ off: null, low: 'low', medium: 'medium', high: 'high', max: 'high' }); /** The menu's words to the Harness's level names. */ export const EFFORT_LEVEL = Object.freeze({ off: 'off', low: 'low', medium: 'medium', high: 'high', max: 'max' }); +/** + * The thinking levels for a model on OpenRouter: its `reasoning.effort` words (none, low, medium, high, xhigh). A model takes them when its entry in + * OpenRouter's model list names `reasoning` among its supported parameters; the Harness (pi-ai) writes `reasoning: { effort }` into the request. + */ +export const OPENROUTER_EFFORTS = Object.freeze({ off: 'none', low: 'low', medium: 'medium', high: 'high', max: 'xhigh' }); +/** Whether a connection is OpenRouter (the catalog entry, or its address), whatever address it is reached at. */ +export const isOpenRouter = conn => conn?.provider === 'openrouter' || (() => { try { return /(^|.)openrouter.ai$/i.test(new URL(conn.baseUrl).hostname); } catch { return false; } })(); export const effortOf = value => EFFORT_LEVEL[String(value ?? '').toLowerCase()] ?? null; /** @@ -221,7 +228,8 @@ export function buildProfile({ local = [], connections = [], gate = true, tools if (protocol === 'anthropic-messages') baseURL = baseURL.replace(/\/v1\/?$/, ''); // A model server on this computer or network (another Strata PC, llama.cpp, LM Studio) takes the same thinking vocabulary as a local model: // without it the Reasoning menu did nothing for a connection to another Strata machine. - const ownServer = protocol === 'openai-completions' && isPrivateHost(baseURL); + const openRouter = protocol === 'openai-completions' && isOpenRouter(conn); + const ownServer = protocol === 'openai-completions' && !openRouter && isPrivateHost(baseURL); // A model server on this computer or network has a window of its own size like a local model: the reply keeps half of it, so the Harness can compact the conversation // before the window is full (with nearly all of it reserved for the reply a long task ended with "the prompt leaves no room to answer"). const reply = m => (ownServer && Number.isFinite(m.contextMax) && m.contextMax > 0 && !m.maxOutput ? localOutputBudget(m.contextMax) : outputBudget(m.contextMax ?? ASSUMED_API_CONTEXT, m.maxOutput)); @@ -230,14 +238,14 @@ export function buildProfile({ local = [], connections = [], gate = true, tools api: protocol, baseURL, ...(conn.apiKey || keyless ? { apiKeyEnv: keyEnv } : {}), - ...(ownServer ? { compat: THINKING_COMPAT } : {}), + ...(ownServer ? { compat: THINKING_COMPAT } : openRouter ? { compat: { thinkingFormat: 'openrouter' } } : {}), models: conn.models.map(m => ({ id: m.id, name: m.name || m.id, contextWindow: m.contextMax ?? ASSUMED_API_CONTEXT, maxTokens: reply(m), - // Pictures only when the server itself says it reads them (the host asks its model list): a server started without a vision encoder refuses the whole request when a picture is in it. + // Pictures are on by default (owner rule): only an explicit no (the person's switch, or the server's own model list or /props) leaves them out. // (any OpenAI-style API: a cloud model the person marked, or whose model list says it reads pictures, takes image_url the same way) - input: protocol === 'openai-completions' && m.vision === true ? ['text', 'image'] : ['text'], - ...(ownServer ? { reasoning: true, reasoningEfforts: LOCAL_EFFORTS } : {}), + input: protocol === 'openai-completions' && m.vision !== false ? ['text', 'image'] : ['text'], + ...(ownServer ? { reasoning: true, reasoningEfforts: LOCAL_EFFORTS } : openRouter && m.reasoning === true ? { reasoning: true, reasoningEfforts: OPENROUTER_EFFORTS } : {}), })), }; const fp = fingerprint(providers[route], conn.apiKey ?? ''); diff --git a/apps/host/server/index.mjs b/apps/host/server/index.mjs index cf3c8336..a4f8d67f 100644 --- a/apps/host/server/index.mjs +++ b/apps/host/server/index.mjs @@ -48,7 +48,7 @@ import { CONTEXT_TOKENS, VARIANTS, localModels, variant } from './catalog.mjs'; import { browseLocalModels, inspectLocalModel } from './local-models.mjs'; import { EventHub, error, json, readBody, readRaw, uid } from './util.mjs'; import { createUploads } from './chat-uploads.mjs'; -import { createVisionProbe, effectiveVision } from './vision-probe.mjs'; +import { createVisionProbe, effectiveVision, readsPicturesByDefault } from './vision-probe.mjs'; import { RequestQueue } from './request-queue.mjs'; import { selectSkills, skillInstructions } from './skill-selection.mjs'; import { createModelProviders } from './model-providers.mjs'; @@ -136,8 +136,9 @@ function withPictureAnswers(list) { const secrets = new Map(modelProviders.withSecrets().map(c => [c.id, c])); const connections = (list.connections ?? []).map(c => ({ ...c, models: c.models.map(m => { const asked = visionProbe.known(c, m.id); - if (m.vision == null && asked === undefined && c.protocol === 'openai-chat' && secrets.has(c.id)) void visionProbe.check(secrets.get(c.id), m.id).catch(() => {}); - return { ...m, reads: effectiveVision(m, asked) ?? null }; + if ((m.vision == null || m.reasoning == null) && asked === undefined && c.protocol === 'openai-chat' && secrets.has(c.id)) void visionProbe.check(secrets.get(c.id), m.id).catch(() => {}); + // Pictures are on unless the person or the server says no; a model that thinks says so too (OpenRouter's supported_parameters). + return { ...m, reads: readsPicturesByDefault(m, asked), thinks: m.reasoning ?? visionProbe.knownThinks(c, m.id) ?? null }; }) })); return { ...list, connections }; } @@ -145,12 +146,10 @@ function withPictureAnswers(list) { async function pictureRefusal(connection, model) { if (!connection || !model) return 'This API model is no longer available. Choose another model in the chat picker.'; if (connection.protocol !== 'openai-chat') return `Pictures can only be sent to model APIs that use the OpenAI chat style. "${connection.name}" uses a different style, so the picture stays in the preview. Add the model through an OpenAI-compatible address (a /v1 address) to send pictures.`; - const answer = effectiveVision(model, await visionProbe.check(connection, model.id)); - if (answer === true) return null; - const fix = `open Settings → Models, edit "${connection.name}" and tick "This model reads pictures"`; - return answer === false - ? `"${model.name}" does not read pictures, as far as its server says (a llama-server started without --mmproj, or a text-only model). If that is wrong, ${fix}. Otherwise choose a model that reads pictures.` - : `Strata cannot tell that "${model.name}" reads pictures. If it does, ${fix}. Otherwise choose a model that reads pictures.`; + // Pictures are on by default: only an explicit no (the person's switch, or the server's own list) stops one. + if (readsPicturesByDefault(model, await visionProbe.check(connection, model.id))) return null; + const fix = `open Settings → Models, edit "${connection.name}" and turn on "Read pictures with this model"`; + return `"${model.name}" is set not to read pictures (or its server says it cannot: a llama-server started without --mmproj, or a text-only model). If that is wrong, ${fix}. Otherwise choose a model that reads pictures.`; } const agent = createAgentBridge({ tools: () => agentTools.profileView(), @@ -173,7 +172,7 @@ const agent = createAgentBridge({ // The tool servers set up for this model (Settings, Tools): the agent connects to the same ones. mcpServers: i.mcpServers, })), - connections: () => modelProviders.withSecrets().map(c => ({ ...c, models: c.models.map(m => ({ ...m, vision: effectiveVision(m, visionProbe.known(c, m.id)) })) })), + connections: () => modelProviders.withSecrets().map(c => ({ ...c, models: c.models.map(m => ({ ...m, vision: readsPicturesByDefault(m, visionProbe.known(c, m.id)), reasoning: m.reasoning ?? visionProbe.knownThinks(c, m.id) ?? null })) })), log: line => console.log(line), }); let storageChanging = false; diff --git a/apps/host/server/model-providers.mjs b/apps/host/server/model-providers.mjs index cd4ea882..2bb1c0f8 100644 --- a/apps/host/server/model-providers.mjs +++ b/apps/host/server/model-providers.mjs @@ -1,5 +1,5 @@ /** Saved API connections. Secrets never leave the host's private credentials file. */ -import { modelReadsPictures } from './vision-probe.mjs'; +import { modelReadsPictures, modelSupportsReasoning } from './vision-probe.mjs'; import { existsSync, readFileSync, writeFileSync, renameSync, mkdirSync } from 'node:fs'; import { join } from 'node:path'; import { randomUUID } from 'node:crypto'; @@ -76,7 +76,7 @@ export function createModelProviders({ directory, changed = () => {}, fetchImpl if (rows.length > 100) fail('Add up to 100 models to one connection.'); const models = rows.map(row => { const id = text(row.id, 256); if (!id || /[\r\n]/.test(id)) fail('Every model needs a model ID.'); - return { id, name: text(row.name) || id, contextMax: numeric(row.contextMax), maxOutput: numeric(row.maxOutput), vision: row.vision === true ? true : row.vision === false ? false : null }; + return { id, name: text(row.name) || id, contextMax: numeric(row.contextMax), maxOutput: numeric(row.maxOutput), vision: row.vision === true ? true : row.vision === false ? false : null, reasoning: row.reasoning === true ? true : row.reasoning === false ? false : null }; }); if (new Set(models.map(m => m.id)).size !== models.length) fail('Each model ID must be unique within this connection.'); return { id: existing?.id ?? randomUUID(), kind, provider: catalog?.id ?? null, name, baseUrl, protocol, apiKey, models }; @@ -129,7 +129,7 @@ export function createModelProviders({ directory, changed = () => {}, fetchImpl if (connection.protocol !== 'anthropic' || !data.has_more) break; after = data.last_id; if (!after) break; } - const models = [...new Map(rows.filter(m => text(m.id, 256)).map(m => [m.id, { id: text(m.id, 256), name: text(m.display_name ?? m.name) || text(m.id, 256), contextMax: numeric(m.context_length ?? m.max_context_length ?? m.context_window), maxOutput: numeric(m.max_output_tokens ?? m.max_completion_tokens ?? m.top_provider?.max_completion_tokens), vision: modelReadsPictures(m) }])).values()]; + const models = [...new Map(rows.filter(m => text(m.id, 256)).map(m => [m.id, { id: text(m.id, 256), name: text(m.display_name ?? m.name) || text(m.id, 256), contextMax: numeric(m.context_length ?? m.max_context_length ?? m.context_window), maxOutput: numeric(m.max_output_tokens ?? m.max_completion_tokens ?? m.top_provider?.max_completion_tokens), vision: modelReadsPictures(m), reasoning: modelSupportsReasoning(m) }])).values()]; return { models: models.sort((a, b) => a.name.localeCompare(b.name)) }; } async function stream({ selection, message, history = [], systemPrompt = '', images = [], signal, onFrame }) { diff --git a/apps/host/server/vision-probe.mjs b/apps/host/server/vision-probe.mjs index e81f79cc..482e79f9 100644 --- a/apps/host/server/vision-probe.mjs +++ b/apps/host/server/vision-probe.mjs @@ -19,6 +19,24 @@ export function modelReadsPictures(row) { return null; } +/** + * Does a model list row say the model can think (reasoning)? OpenRouter lists `supported_parameters` per model: `reasoning` or + * `include_reasoning` in it means the model takes a reasoning effort. True / false / null (the row does not say). + */ +export function modelSupportsReasoning(row) { + const list = row?.supported_parameters ?? row?.supportedParameters; + if (!Array.isArray(list)) return null; + return list.some(x => /^(include_)?reasoning$/i.test(String(x))); +} + +/** + * Pictures are ON by default (owner rule): a model whose server does not say either way is sent pictures; only an explicit "no" (the person's + * own switch, or the server's own list or /props) turns them off. + */ +export function readsPicturesByDefault(model, asked) { + return effectiveVision(model, asked) ?? true; +} + /** The effective answer for a saved model: what the person ticked, else what the server said (undefined: never asked). */ export function effectiveVision(model, asked) { if (model?.vision === true) return true; @@ -32,26 +50,29 @@ export function createVisionProbe({ fetcher = fetch, now = Date.now } = {}) { return { /** Last known answer for a model (true / false), or undefined when never asked. */ known: (conn, modelId) => { const e = cache.get(keyOf(conn, modelId)); return e ? e.value : undefined; }, - /** Ask now (at most once per TTL per model). */ + /** Whether the model takes a reasoning effort, as its server's list said (true / false), null when it did not say, undefined when never asked. */ + knownThinks: (conn, modelId) => { const e = cache.get(keyOf(conn, modelId)); return e ? e.thinks : undefined; }, + /** Ask now (at most once per TTL per model). Answers true / false / null (the server did not say). */ async check(conn, modelId) { const k = keyOf(conn, modelId); const hit = cache.get(k); if (hit && now() - hit.at < TTL_MS) return hit.value; - let value = false; + let value = null, thinks = null; const base = String(conn.baseUrl).replace(/\/+$/, ''); const headers = conn.apiKey ? { authorization: `Bearer ${conn.apiKey}` } : {}; const get = async path => { const res = await fetcher(base + path, { headers, signal: AbortSignal.timeout(4000) }); return res.ok ? res.json() : null; }; try { const list = (await get('/models'))?.data ?? []; const row = list.find(m => m?.id === modelId) ?? (list.length === 1 ? list[0] : null); - value = modelReadsPictures(row) === true; - if (!value && modelReadsPictures(row) !== false) { // the list did not say: a llama-server tells in /props (next to /v1, not under it) + value = modelReadsPictures(row); + thinks = modelSupportsReasoning(row); + if (value === null) { // the list did not say: a llama-server tells in /props (next to /v1, not under it) try { const props = await (async () => { const res = await fetcher(base.replace(/\/v1$/, '') + '/props', { headers, signal: AbortSignal.timeout(4000) }); return res.ok ? res.json() : null; })(); - value = props?.modalities?.vision === true; + value = props?.modalities?.vision === true ? true : props?.modalities?.vision === false ? false : null; } catch { /* no /props: not a llama-server */ } } - } catch { value = false; } - cache.set(k, { at: now(), value }); + } catch { value = null; } + cache.set(k, { at: now(), value, thinks }); return value; }, }; diff --git a/apps/host/src/components/ComposerControls.tsx b/apps/host/src/components/ComposerControls.tsx index b8bbe140..2a9f5fb0 100644 --- a/apps/host/src/components/ComposerControls.tsx +++ b/apps/host/src/components/ComposerControls.tsx @@ -49,6 +49,8 @@ export function ComposerControls({ session, onPreview, onAttach, onError, onSlas const attachLatest = useRef(onAttach); attachLatest.current = onAttach; const addFilesLatest = useRef<(files: File[]) => Promise>(async () => { }); + // A model on an API takes a reasoning effort when its provider says it can think (OpenRouter's model list); otherwise the provider decides. + const apiOnlyDefault = !!apiModel && apiModel.thinks !== true; const mode = modes.find(m => m.value === session?.preferences?.mode) ?? modes[0]; const effort = efforts.includes(session?.preferences?.thinking ?? '') ? session!.preferences!.thinking! : 'Medium'; const budget = session?.preferences?.thinkingBudget ?? 0; @@ -160,14 +162,14 @@ export function ComposerControls({ session, onPreview, onAttach, onError, onSlas - + {tr(menu ? setMenu(false)}> : null)} {tr(preferences ? setPreferences(null)}> - {tr(preferences === 'mode' ? <>{tr(modes.map((option, index) => ))} : <>
{tr(apiModel?.name ?? (nativeModel && nativeModel.status === 'ready' ? nativeModel.label : null) ?? loaded?.family ?? 'No model loaded')}

{tr("Reasoning effort")}

{tr(efforts.map(option => ))}

{tr("Thinking budget")}

{tr(THINKING_BUDGETS.map(([value, label]) => ))})} + {tr(preferences === 'mode' ? <>{tr(modes.map((option, index) => ))} : <>
{tr(apiModel?.name ?? (nativeModel && nativeModel.status === 'ready' ? nativeModel.label : null) ?? loaded?.family ?? 'No model loaded')}

{tr("Reasoning effort")}

{tr(efforts.map(option => ))}{tr(apiModel ? null : <>

{tr("Thinking budget")}

{tr(THINKING_BUDGETS.map(([value, label]) => ))})})}
: null)} setUrlOpen(false)} actions={<> setUrlOpen(false)}>{tr("Cancel")} { diff --git a/apps/host/src/lib/types.ts b/apps/host/src/lib/types.ts index 3fd64504..fac118a1 100644 --- a/apps/host/src/lib/types.ts +++ b/apps/host/src/lib/types.ts @@ -125,7 +125,7 @@ export interface ImageModelLibrary { } export type ModelProtocol = 'openai-chat' | 'openai-responses' | 'anthropic'; -export interface ApiModel { id: string; name: string; contextMax?: number | null; /** What the person ticked ("This model reads pictures"): true, false, or null for not set. */ vision?: boolean | null; /** The answer in use: the tick, else what the server said; null when nobody knows. */ reads?: boolean | null } +export interface ApiModel { id: string; name: string; contextMax?: number | null; /** What the person ticked ("This model reads pictures"): true, false, or null for not set. */ vision?: boolean | null; /** The answer in use: the tick, else what the server said; null when nobody knows. */ reads?: boolean | null; /** The provider says the model can think (OpenRouter's supported_parameters): the Reasoning menu then works. */ reasoning?: boolean | null; thinks?: boolean | null } export interface ModelProviderPreset { id: string; name: string; baseUrl: string; protocol: ModelProtocol; baseUrlHint?: string } export interface ModelConnection { id: string; kind: 'provider' | 'custom'; provider: string | null; name: string; diff --git a/apps/host/tests/agent-shape.test.mjs b/apps/host/tests/agent-shape.test.mjs index 37d81862..efa904dd 100644 --- a/apps/host/tests/agent-shape.test.mjs +++ b/apps/host/tests/agent-shape.test.mjs @@ -128,7 +128,7 @@ test('a turn uses the response-settings route only when a setting is changed: th assert.equal(last().temperature, undefined, 'back to defaults: straight to the model again'); }); -test('a model server on this network gets picture input only when its own model list says it reads pictures', async () => { +test('a model server on this network gets picture input unless its own model list or the person says it does not read pictures', async () => { const lists = { yes: { data: [{ id: 'm', architecture: { input_modalities: ['text', 'image'] } }] }, no: { data: [{ id: 'm', architecture: { input_modalities: ['text'] } }] } }; let which = 'yes'; const probe = createVisionProbe({ fetcher: async () => ({ ok: true, json: async () => lists[which] }) }); @@ -136,7 +136,7 @@ test('a model server on this network gets picture input only when its own model assert.equal(probe.known(conn, 'm'), undefined); assert.equal(await probe.check(conn, 'm'), true); assert.equal(probe.known(conn, 'm'), true); which = 'no'; assert.equal(await probe.check(conn, 'm'), true, 'cached for a few minutes'); - assert.equal(await createVisionProbe({ fetcher: async () => { throw new Error('down'); } }).check(conn, 'm'), false, 'unreachable counts as no'); + assert.equal(await createVisionProbe({ fetcher: async () => { throw new Error('down'); } }).check(conn, 'm'), null, 'unreachable is unknown: pictures stay on by default'); const build = vision => JSON.parse(buildProfile({ local: [], connections: [{ id: 'own', name: 'Own', baseUrl: 'http://127.0.0.1:18798/v1', protocol: 'openai-chat', apiKey: '', models: [{ id: 'm', contextMax: 32768, vision }] }] }).patch.slice(buildProfile({ local: [], connections: [] }).patch.indexOf('['))).find(e => e.id === 'llm-pi-ai').config.providers['api-own'].models[0].input; - assert.deepEqual(build(true), ['text', 'image']); assert.deepEqual(build(false), ['text']); assert.deepEqual(build(undefined), ['text']); + assert.deepEqual(build(true), ['text', 'image']); assert.deepEqual(build(false), ['text']); assert.deepEqual(build(undefined), ['text', 'image'], 'pictures are on by default'); }); diff --git a/apps/host/tests/openrouter-reasoning.test.mjs b/apps/host/tests/openrouter-reasoning.test.mjs new file mode 100644 index 00000000..82dc7cc4 --- /dev/null +++ b/apps/host/tests/openrouter-reasoning.test.mjs @@ -0,0 +1,77 @@ +/** + * OpenRouter models: the Reasoning menu works when OpenRouter's own model list says the model can think, and the chosen effort reaches + * OpenRouter in its own words (`reasoning: { effort }`). The server is a mock; no key exists and none is stored. + */ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import { mkdtempSync, mkdirSync, rmSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; +import { startScriptedWorker } from './helpers/scripted-worker.mjs'; +import { createAgentBridge } from '../server/agent/agent-bridge.mjs'; +import { resolveHarness } from '../server/agent/harness-runtime.mjs'; +import { buildProfile, OPENROUTER_EFFORTS } from '../server/agent/profile.mjs'; +import { createModelProviders } from '../server/model-providers.mjs'; +import { createVisionProbe, modelSupportsReasoning, readsPicturesByDefault } from '../server/vision-probe.mjs'; + +const HARNESS = process.env.STRATA_HARNESS_DIR; +const skip = !HARNESS || !resolveHarness({ env: process.env }).ok ? 'STRATA_HARNESS_DIR is not set to a built Harness' : false; + +const LIST = { data: [ + { id: 'deepseek/deepseek-v3.2', name: 'DeepSeek: DeepSeek V3.2', context_length: 163840, architecture: { input_modalities: ['text'] }, supported_parameters: ['tools', 'reasoning', 'include_reasoning', 'temperature'] }, + { id: 'meta/plain', name: 'Plain', context_length: 8192, architecture: { input_modalities: ['text', 'image'] }, supported_parameters: ['tools', 'temperature'] }, + { id: 'unlisted/x', name: 'No parameters listed' }, +] }; + +test('a model list row says whether the model can think', () => { + assert.equal(modelSupportsReasoning(LIST.data[0]), true); + assert.equal(modelSupportsReasoning({ supported_parameters: ['include_reasoning'] }), true); + assert.equal(modelSupportsReasoning(LIST.data[1]), false); + assert.equal(modelSupportsReasoning(LIST.data[2]), null); +}); + +test('fetching the model list keeps the reasoning answer, and a saved connection keeps it', async t => { + const directory = mkdtempSync(join(tmpdir(), 'strata-or-')); t.after(() => rmSync(directory, { recursive: true, force: true })); + const fetchImpl = async () => ({ ok: true, status: 200, json: async () => LIST, body: { cancel() {} } }); + const service = createModelProviders({ directory, fetchImpl }); + const found = await service.discover({ kind: 'provider', provider: 'openrouter', apiKey: 'mock-key', models: [] }); + assert.deepEqual(found.models.map(m => [m.id, m.reasoning]), [['meta/plain', false], ['deepseek/deepseek-v3.2', true], ['unlisted/x', null]].sort((a, b) => a[0].localeCompare(b[0])).sort((x, y) => found.models.findIndex(m => m.id === x[0]) - found.models.findIndex(m => m.id === y[0]))); + const saved = service.save({ kind: 'provider', provider: 'openrouter', apiKey: 'mock-key', models: found.models }).connections[0]; + assert.equal(saved.models.find(m => m.id === 'deepseek/deepseek-v3.2').reasoning, true); + assert.equal(createModelProviders({ directory }).list().connections[0].models.find(m => m.id === 'meta/plain').reasoning, false); +}); + +test('the probe asks the list once for pictures and thinking, and pictures are on unless something says no', async () => { + const probe = createVisionProbe({ fetcher: async () => ({ ok: true, json: async () => LIST }) }); + const conn = { id: 'c', baseUrl: 'https://openrouter.ai/api/v1', apiKey: 'k' }; + assert.equal(await probe.check(conn, 'deepseek/deepseek-v3.2'), false); + assert.equal(probe.knownThinks(conn, 'deepseek/deepseek-v3.2'), true); + assert.equal(await probe.check(conn, 'unlisted/x'), null); + assert.equal(readsPicturesByDefault({}, null), true, 'unknown: on'); + assert.equal(readsPicturesByDefault({ vision: false }, true), false, 'the person switched it off'); + assert.equal(readsPicturesByDefault({}, false), false, 'the server says no'); +}); + +test('the profile gives a thinking model the OpenRouter efforts and the OpenRouter format, even at another address', () => { + const conn = { id: 'or', name: 'OpenRouter', provider: 'openrouter', baseUrl: 'http://127.0.0.1:1/v1', protocol: 'openai-chat', apiKey: 'k', models: [{ id: 'a/think', reasoning: true }, { id: 'a/plain', reasoning: false }, { id: 'a/unknown' }] }; + const entries = JSON.parse(buildProfile({ local: [], connections: [conn] }).patch.split('\n').slice(1).join('\n')); + const provider = Object.values(entries.find(e => e.id === 'llm-pi-ai').config.providers)[0]; + assert.equal(provider.compat.thinkingFormat, 'openrouter'); + const [think, plain, unknown] = provider.models; + assert.deepEqual(think.reasoningEfforts, OPENROUTER_EFFORTS); assert.equal(think.reasoning, true); + assert.equal(plain.reasoning, undefined); assert.equal(unknown.reasoning, undefined); + assert.deepEqual(unknown.input, ['text', 'image'], 'pictures on by default'); +}); + +test('the real Harness: the chosen effort is sent to OpenRouter as reasoning.effort', { skip }, async t => { + const worker = await startScriptedWorker({ model: 'a/think' }); + const dir = mkdtempSync(join(tmpdir(), 'strata-or-run-')); const ws = join(dir, 'ws'); mkdirSync(ws, { recursive: true }); + const bridge = createAgentBridge({ dataDir: dir, env: process.env, startTimeoutMs: 90_000, localInstances: () => [], connections: () => [{ id: 'or-conn-1', name: 'OpenRouter', provider: 'openrouter', baseUrl: worker.url, protocol: 'openai-chat', apiKey: 'mock', models: [{ id: 'a/think', name: 'Think', contextMax: 32768, reasoning: true }] }] }); + t.after(async () => { await bridge.close(); await worker.close(); try { rmSync(dir, { recursive: true, force: true, maxRetries: 3 }); } catch { /* best effort */ } }); + const seen = {}; + for (const level of ['High', 'Max', 'Off']) { + await bridge.runTurn({ chatId: `or-${level}`, message: 'SCRIPT:echo hi', workspacePath: ws, mode: 'bypass', thinking: level, choice: { connectionId: 'or-conn-1', modelId: 'a/think' }, onFrame: () => {} }); + seen[level] = worker.requests.at(-1).params.reasoning; + } + assert.deepEqual(seen, { High: { effort: 'high' }, Max: { effort: 'xhigh' }, Off: { effort: 'none' } }); +}); diff --git a/apps/host/tests/vision-probe.test.mjs b/apps/host/tests/vision-probe.test.mjs index 86418e6f..1a8c0105 100644 --- a/apps/host/tests/vision-probe.test.mjs +++ b/apps/host/tests/vision-probe.test.mjs @@ -41,11 +41,11 @@ test('a llama-server started with --mmproj says so in /props, next to /v1, and t assert.deepEqual(seen, ['/v1/models', '/props']); }); -test('a text-only server, and an unreachable one, count as not reading pictures', async () => { +test('a text-only server counts as not reading pictures; an unreachable one is unknown (pictures stay on by default)', async () => { const text = createVisionProbe({ fetcher: answer({ '/v1/models': { data: [{ id: 'm' }] }, '/props': { modalities: { vision: false } } }) }); assert.equal(await text.check({ id: 'c', baseUrl: 'http://h/v1' }, 'm'), false); const down = createVisionProbe({ fetcher: async () => { throw new Error('refused'); } }); - assert.equal(await down.check({ id: 'c', baseUrl: 'http://h/v1' }, 'm'), false); + assert.equal(await down.check({ id: 'c', baseUrl: 'http://h/v1' }, 'm'), null); }); test('a provider list that names image input is believed without asking /props', async () => {