Skip to content

Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.

C++

App: the composer's effort (Off, Low, Medium, High, Max) reaches saved API models that support reasoning, with the OpenRouter mapping; unknown support keeps the provider default (PR #3363 by medking82)

medking82f4999223795d
diff --git a/apps/host/server/index.mjs b/apps/host/server/index.mjs
index b9640e1db..d28418c8c 100644
--- a/apps/host/server/index.mjs
+++ b/apps/host/server/index.mjs
@@ -115,7 +115,7 @@ const WORKSPACE_NAME = process.env.STRATA_WORKSPACE ? basename(WORKSPACE) : 'Str
const insideApp = path => { const rel = relative(ROOT, resolve(path)); return rel === '' || (!rel.startsWith('..') && !isAbsolute(rel)); };
const hub = new EventHub();
-const modelProviders = createModelProviders({ directory: store.DATA_DIR, changed: value => hub.send('providers', withPictureAnswers(value)) });
+const modelProviders = createModelProviders({ directory: store.DATA_DIR, knownThinks: (connection, modelId) => visionProbe.knownThinks(connection, modelId), changed: value => hub.send('providers', withPictureAnswers(value)) });
const imageModels = createImageModels({ dataDir: store.DATA_DIR, modelsDir: () => store.MODELS_DIR, real: models.REAL, changed: value => hub.send('image-models', value) });
/* The installed app ships Strata Control (python + strata_control) next to the host; a source checkout has none and keeps its older paths. */
const CONTROL = findControl();
@@ -558,17 +558,18 @@ function clientName(req) {
return 'Local client';
}
-async function runRemoteTurn({ selection, message, history, images = [], onFrame, signal, workspaceId }) {
+async function runRemoteTurn({ selection, message, history, images = [], thinking, onFrame, signal, workspaceId }) {
const controller = new AbortController();
const requestSignal = signal ? AbortSignal.any([signal, controller.signal]) : controller.signal;
let entry;
const started = Date.now();
try {
const { connection, model } = modelProviders.resolve(selection);
+ if (connection.protocol === 'openai-chat' && model.reasoning == null) await visionProbe.check(connection, model.id);
const appliedSkills = selectSkills(skillState, message, workspaceId);
entry = serving.open({ client: 'Strata chat', endpoint: connection.protocol === 'anthropic' ? '/messages' : connection.protocol === 'openai-responses' ? '/responses' : '/chat/completions', model: `${connection.name} · ${model.name}`, cancel: () => controller.abort(new DOMException('Cancelled by the user', 'AbortError')) });
serving.mark(entry.id, { state: 'generating' });
- const result = await modelProviders.stream({ selection, message, history, images, signal: requestSignal, systemPrompt: ['You are Strata, a helpful assistant. Answer clearly. Do not claim to have read files or performed actions unless their results are included in the conversation.', skillInstructions(appliedSkills)].filter(Boolean).join('\n\n'), onFrame: frame => {
+ const result = await modelProviders.stream({ selection, message, history, images, thinking, signal: requestSignal, systemPrompt: ['You are Strata, a helpful assistant. Answer clearly. Do not claim to have read files or performed actions unless their results are included in the conversation.', skillInstructions(appliedSkills)].filter(Boolean).join('\n\n'), onFrame: frame => {
if (frame.type === 'start') noteSkillUse(appliedSkills);
if (frame.type === 'done') serving.mark(entry.id, { tokensIn: frame.tokensIn, tokensOut: frame.tokensOut, usageSource: frame.usageSource });
onFrame({ ...frame, requestId: entry.id, model: model.name, contextMax: model.contextMax, remoteModel: true, ...(frame.type === 'start' ? { skills: appliedSkills.map(s => s.name) } : {}) });
@@ -631,7 +632,7 @@ async function runAgentTurn({ res, controller, chatId, body, message, workspaceI
}
async function runTurn({ message, history = [], onFrame, signal, client, workspaceId = null, sessionId = null, remoteModel = null, runtimeModelId = undefined, nativeModelId, images=[], useTools=false, thinking='medium', thinkingBudget=0 }) {
- if (remoteModel) return runRemoteTurn({ selection: remoteModel, message, history, images, onFrame, signal, workspaceId });
+ if (remoteModel) return runRemoteTurn({ selection: remoteModel, message, history, images, thinking, onFrame, signal, workspaceId });
if(native.hasLive()||nativeModelId){
let instance;try{instance=native.resolveInstance(nativeModelId??native.state().defaultId);}catch(e){const message=plainNoModel(e.message);onFrame({type:'error',message});return {error:message};}const started=Date.now(),cancel=new AbortController();
const entry=serving.open({client:client??'Strata chat',endpoint:'/chat/completions',model:instance.apiModelId,instanceId:instance.id,gpuIds:instance.gpus.map(String),cancel:()=>cancel.abort()});
diff --git a/apps/host/server/model-providers.mjs b/apps/host/server/model-providers.mjs
index 30fa6fbd2..3c6bf33e9 100644
--- a/apps/host/server/model-providers.mjs
+++ b/apps/host/server/model-providers.mjs
@@ -1,5 +1,6 @@
/** Saved API connections. Secrets never leave the host's private credentials file. */
import { modelReadsPictures, modelSupportsReasoning } from './vision-probe.mjs';
+import { isOpenRouter, OPENROUTER_EFFORTS } from './agent/profile.mjs';
import { existsSync, readFileSync, writeFileSync, renameSync, mkdirSync } from 'node:fs';
import { join } from 'node:path';
import { randomUUID } from 'node:crypto';
@@ -49,7 +50,7 @@ export function normalizeBaseUrl(value) {
const publicConnection = ({ apiKey, ...connection }) => ({ ...connection, apiKeySet: !!apiKey });
const numeric = value => typeof value === 'number' && Number.isFinite(value) && value >= 0 ? value : null;
-export function createModelProviders({ directory, changed = () => {}, fetchImpl = fetch }) {
+export function createModelProviders({ directory, changed = () => {}, fetchImpl = fetch, knownThinks = () => null }) {
mkdirSync(directory, { recursive: true });
const file = join(directory, 'model-providers.json');
let connections = [];
@@ -142,7 +143,7 @@ export function createModelProviders({ directory, changed = () => {}, fetchImpl
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 }) {
+ async function stream({ selection, message, history = [], systemPrompt = '', images = [], thinking, signal, onFrame }) {
const { connection, model } = resolve(selection);
const started = Date.now();
const messages = history.filter(m => ['user', 'assistant'].includes(m.role) && typeof m.content === 'string').slice(-40).map(m => ({ role: m.role, content: m.content }));
@@ -155,6 +156,12 @@ export function createModelProviders({ directory, changed = () => {}, fetchImpl
: protocol === 'openai-responses'
? { model: model.id, input: messages, instructions: systemPrompt, stream: true, store: false }
: { model: model.id, messages: [...(systemPrompt ? [{ role: 'system', content: systemPrompt }] : []), ...messages], stream: true, ...(['openai', 'deepseek', 'openrouter', 'google', 'moonshotai'].includes(connection.provider) ? { stream_options: { include_usage: true } } : {}) };
+ // Match the native composer's effort names. Unknown support and other protocols keep provider defaults.
+ const choice = typeof thinking === 'string' ? thinking.toLowerCase() : '';
+ if (protocol === 'openai-chat' && (model.reasoning ?? knownThinks(connection, model.id)) === true && ['off', 'low', 'medium', 'high', 'max'].includes(choice)) {
+ if (isOpenRouter(connection)) payload.reasoning = { effort: OPENROUTER_EFFORTS[choice] };
+ else payload.reasoning_effort = ({ off: 'none', max: 'high' })[choice] ?? choice;
+ }
const requestSignal = signal ? AbortSignal.any([signal, AbortSignal.timeout(10 * 60 * 1000)]) : AbortSignal.timeout(10 * 60 * 1000);
const res = await request(connection, protocol === 'anthropic' ? 'messages' : protocol === 'openai-responses' ? 'responses' : 'chat/completions', { method: 'POST', body: JSON.stringify(payload), signal: requestSignal });
if (!res.body) fail('The model API returned an empty response.');
diff --git a/apps/host/tests/api-reasoning-effort.test.mjs b/apps/host/tests/api-reasoning-effort.test.mjs
new file mode 100644
index 000000000..6fda28edd
--- /dev/null
+++ b/apps/host/tests/api-reasoning-effort.test.mjs
@@ -0,0 +1,96 @@
+/** Behavioral checks use only disposable files and a loopback mock API. */
+import test from 'node:test';
+import assert from 'node:assert/strict';
+import {mkdtempSync,mkdirSync,readFileSync,writeFileSync,rmSync} from 'node:fs';
+import {tmpdir} from 'node:os';
+import {join} from 'node:path';
+import {spawn} from 'node:child_process';
+import {once} from 'node:events';
+import {createServer} from 'node:net';
+import {createModelProviders} from '../server/model-providers.mjs';
+import {createMockModelApi} from './mock-model-api.mjs';
+import {createVisionProbe} from '../server/vision-probe.mjs';
+import {ROOMY_HOST} from './helpers/hardware.mjs';
+const choices={Off:'none',Low:'low',Medium:'medium',High:'high',Max:'high'};
+const history=[{role:'user',content:'Earlier question'},{role:'assistant',content:'Earlier answer'}];
+async function fixture(t,options={}){
+ const mock=await createMockModelApi(),directory=mkdtempSync(join(tmpdir(),'strata-api-effort-'));
+ t.after(async()=>{await mock.close();rmSync(directory,{recursive:true,force:true});});
+ const probe=createVisionProbe(),service=createModelProviders({directory,knownThinks:(c,id)=>probe.knownThinks(c,id)});
+ const connection=service.save({kind:'custom',name:'Fixture',baseUrl:mock.baseUrl,protocol:'openai-chat',apiKey:'fixture-key',models:[{id:'mock-reasoning',reasoning:true}],...options}).connections[0];
+ return {mock,service,connection,probe,selection:{connectionId:connection.id,modelId:connection.models[0].id}};
+}
+test('saved reasoning models receive all official composer choices with the remaining request unchanged',async t=>{
+ const f=await fixture(t);
+ for(const [thinking,effort] of Object.entries(choices)){
+ const frames=[];await f.service.stream({selection:f.selection,message:'Next question',history,systemPrompt:'Fixture instructions',thinking,thinkingBudget:1234,onFrame:f=>frames.push(f)});
+ const request=f.mock.requests.at(-1);
+ assert.equal(request.path,'/v1/chat/completions');assert.equal(request.headers.authorization,'Bearer fixture-key');
+ assert.deepEqual(request.body,{model:'mock-reasoning',messages:[{role:'system',content:'Fixture instructions'},...history,{role:'user',content:'Next question'}],stream:true,reasoning_effort:effort});
+ assert.equal(frames.at(-1).type,'done');
+ }
+});
+test('invalid or omitted efforts keep the provider default',async t=>{
+ const f=await fixture(t);
+ for(const thinking of [undefined,null,false,1,{},'','Default','Provider Default','ultra','none','__proto__']){
+ await f.service.stream({selection:f.selection,message:'Test',thinking,onFrame:()=>{}});
+ assert.equal(Object.hasOwn(f.mock.requests.at(-1).body,'reasoning_effort'),false);
+ }
+});
+
+test('direct OpenRouter chat uses the same effort format and Max mapping as agent chat',async t=>{
+ const f=await fixture(t,{kind:'provider',provider:'openrouter'});
+ for(const [thinking,effort] of Object.entries({...choices,Max:'xhigh'})){
+ await f.service.stream({selection:f.selection,message:'Test',thinking,onFrame:()=>{}});
+ const payload=f.mock.requests.at(-1).body;
+ assert.deepEqual(payload.reasoning,{effort});
+ assert.equal(Object.hasOwn(payload,'reasoning_effort'),false);
+ }
+});
+test('saved false and unknown support cannot be overridden by request capability fields',async t=>{
+ for(const reasoning of [false,null]){
+ const f=await fixture(t,{models:[{id:'mock-chat',reasoning}]});
+ await f.service.stream({selection:{...f.selection,reasoning:true,thinks:true},message:'Test',thinking:'High',reasoning:true,thinks:true,onFrame:()=>{}});
+ assert.equal(Object.hasOwn(f.mock.requests.at(-1).body,'reasoning_effort'),false);
+ }
+});
+test('host-owned probe support is used only when the saved answer is unknown',async t=>{
+ for(const reasoning of [null,false]){
+ const f=await fixture(t,{models:[{id:'mock-reasoning',reasoning}]});
+ await f.probe.check(f.service.resolve(f.selection).connection,'mock-reasoning');assert.equal(f.probe.knownThinks(f.connection,'mock-reasoning'),true);
+ await f.service.stream({selection:f.selection,message:'Test',thinking:'Low',onFrame:()=>{}});
+ assert.equal(f.mock.requests.at(-1).body.reasoning_effort,reasoning===false?undefined:'low');
+ }
+});
+test('Responses and Anthropic retain their existing payloads even for reasoning models',async t=>{
+ for(const protocol of ['openai-responses','anthropic']){
+ const f=await fixture(t,{protocol});await f.service.stream({selection:f.selection,message:'Test',onFrame:()=>{}});const before=f.mock.requests.at(-1).body;
+ await f.service.stream({selection:f.selection,message:'Test',thinking:'Max',thinkingBudget:1234,onFrame:()=>{}});assert.deepEqual(f.mock.requests.at(-1).body,before);
+ }
+});
+async function freePort(){const s=createServer();await new Promise(r=>s.listen(0,'127.0.0.1',r));const p=s.address().port;await new Promise(r=>s.close(r));return p;}
+test('host forwards incoming composer choices using saved and probed support without trusting client capabilities',{timeout:30000},async t=>{
+ const mock=await createMockModelApi(),home=mkdtempSync(join(tmpdir(),'strata-api-effort-host-'));
+ let child,exited;
+ t.after(async()=>{if(child&&child.exitCode===null){child.kill();await exited;}await mock.close();rmSync(home,{recursive:true,force:true,maxRetries:3});});
+ mkdirSync(join(home,'data'));writeFileSync(join(home,'spy.log'),'');
+ // No picker/discovery call precedes the first chat: this also exercises cold probe routing.
+ const models=[{id:'mock-chat',reasoning:true},{id:'mock-reasoning',reasoning:null},{id:'plain',reasoning:false},{id:'unknown',reasoning:null}];
+ writeFileSync(join(home,'data','model-providers.json'),JSON.stringify([{id:'fixture',kind:'custom',name:'Fixture',baseUrl:mock.baseUrl,protocol:'openai-chat',apiKey:'fixture-key',models}]));
+ const port=await freePort(),base=`http://127.0.0.1:${port}`;
+ const env={...process.env,STRATA_HOME:home,STRATA_MODELS_DIR:join(home,'models'),STRATA_WORKSPACE:join(home,'work'),STRATA_SETTINGS_FILE:join(home,'settings.json'),STRATA_COMPONENTS_DIR:join(home,'components'),STRATA_CONTROL_DIR:join(home,'no-control'),STRATA_HARNESS_DIR:join(home,'no-harness'),STRATA_NATIVE_REPO:join(home,'no-repo'),STRATA_PORT:String(port),STRATA_SHARE_PORT:String(await freePort()),STRATA_TUNNEL_PORT:String(await freePort()),STRATA_BIND:'127.0.0.1',STRATA_REAL_ENGINE:'0',STRATA_TEST_HARDWARE:ROOMY_HOST,STRATA_AGENT:'off',STRATA_NO_ACQUIRE:'1',ACQUIRE_SPY_LOG:join(home,'spy.log')};
+ child=spawn(process.execPath,['--import','./tests/helpers/acquire-spy.mjs','server/index.mjs'],{cwd:join(import.meta.dirname,'..'),windowsHide:true,stdio:'ignore',env});
+ exited=once(child,'exit');
+ let up=false;for(let n=0;n<100&&!up;n++){try{up=(await fetch(base+'/api/health')).ok;}catch{}if(!up)await new Promise(r=>setTimeout(r,100));}assert.ok(up,'fixture host started');
+ const before=readFileSync(join(home,'data','model-providers.json'),'utf8');
+ for(const model of models)for(const [thinking,effort] of Object.entries(choices)){
+ const res=await fetch(base+'/api/chat/stream',{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify({message:'Next question',history,thinking,thinkingBudget:1234,agent:false,useTools:false,mode:'bypass',remoteModel:{connectionId:'fixture',modelId:model.id,reasoning:true,thinks:true}})});
+ assert.equal(res.status,200);const frames=(await res.text()).trim().split('\n').map(JSON.parse);
+ assert.equal(frames.some(f=>f.type==='error'),false,JSON.stringify(frames));assert.equal(frames.at(-1).type,'done');
+ const request=mock.requests.filter(r=>r.path==='/v1/chat/completions').at(-1);
+ assert.equal(request.body.model,model.id);assert.equal(request.headers.authorization,'Bearer fixture-key');assert.deepEqual(request.body.messages.slice(-3),[...history,{role:'user',content:'Next question'}]);
+ assert.equal(request.body.reasoning_effort,['plain','unknown'].includes(model.id)?undefined:effort);assert.equal(Object.hasOwn(request.body,'reasoning_budget_tokens'),false);
+ }
+ assert.equal(readFileSync(join(home,'data','model-providers.json'),'utf8'),before);
+ assert.equal(readFileSync(join(home,'spy.log'),'utf8'),'','no external requests or software acquisition');
+});
diff --git a/apps/host/tests/mock-model-api.mjs b/apps/host/tests/mock-model-api.mjs
index 0fa24ec29..c6991ff80 100644
--- a/apps/host/tests/mock-model-api.mjs
+++ b/apps/host/tests/mock-model-api.mjs
@@ -12,8 +12,9 @@ export async function createMockModelApi(port = 0) {
if (req.url.includes('/models')) {
res.setHeader('content-type', 'application/json');
const paginated = req.url.includes('limit=100');
- res.end(JSON.stringify({ data: req.url.includes('after_id=') ? [{ id: 'second-model', display_name: 'Second model' }] : [{ id: 'mock-chat', name: 'Test chat model', context_length: 32768 }, { id: 'mock-reasoning', name: 'Test reasoning model', context_length: 65536 }], ...(paginated ? { has_more: !req.url.includes('after_id='), last_id: 'mock-reasoning' } : {}) })); return;
+ res.end(JSON.stringify({ data: req.url.includes('after_id=') ? [{ id: 'second-model', display_name: 'Second model' }] : [{ id: 'mock-chat', name: 'Test chat model', context_length: 32768 }, { id: 'mock-reasoning', name: 'Test reasoning model', context_length: 65536, input_modalities: ['text'], supported_parameters: ['reasoning'] }], ...(paginated ? { has_more: !req.url.includes('after_id='), last_id: 'mock-reasoning' } : {}) })); return;
}
+ if (req.url === '/props') { res.setHeader('content-type', 'application/json'); res.end(JSON.stringify({ modalities: { vision: false } })); return; }
res.writeHead(200, { 'content-type': 'text/event-stream' });
const send = value => res.write(`data: ${JSON.stringify(value)}\r\n\r\n`);
if (body.model === 'truncated') { send({ choices: [{ index: 0, delta: { content: 'Partial' } }] }); res.end(); return; }