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++
Chat with no model: plain words from the host, nothing sent before the engine's first state is known; tests for every state
Niko1221267f35f77749
diff --git a/apps/host/server/index.mjs b/apps/host/server/index.mjsindex 514a21e35..fbd8480c9 100644--- a/apps/host/server/index.mjs+++ b/apps/host/server/index.mjs@@ -58,6 +58,7 @@ import { createForkTimeskip } from './timeskip-fork.mjs';import { createChatFolders, chatRootOf, openFile, resolveChatFile, previewFile, rawFile, createAttachments, withAttachments } from './chat-files.mjs';import { createLlmProxy, samplingFromExpert } from './agent/llm-shape.mjs';import { checkUpdates, checkComponentUpdates } from './updates.mjs';+import { plainNoModel } from './no-model-text.mjs';import { createAppUi } from './app-ui.mjs';import { appVersionFrom, appVersionToShow } from './app-version.mjs';import { createImageModels } from './image-models.mjs';@@ -572,7 +573,7 @@ async function runAgentTurn({ res, controller, chatId, body, message, workspaceI}else {try { instance = native.resolveInstance(body.nativeModelId ?? native.state().defaultId); }- catch (e) { write({ type: 'error', message: e.message }); return; }+ catch (e) { write({ type: 'error', message: plainNoModel(e.message) }); return; }choice = { instanceId: instance.id };}const started = Date.now();@@ -604,7 +605,7 @@ async function runAgentTurn({ res, controller, chatId, body, message, workspaceIasync 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(native.hasLive()||nativeModelId){- let instance;try{instance=native.resolveInstance(nativeModelId??native.state().defaultId);}catch(e){onFrame({type:'error',message:e.message});return {error:e.message};}const started=Date.now(),cancel=new AbortController();+ 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()});try{serving.mark(entry.id,{state:'generating'});const applied=selectSkills(skillState,message,workspaceId);const result=await proxyCompletion({baseUrl:`http://127.0.0.1:${instance.port}/v1`,modelId:instance.apiModelId,authorization:instance.key,message,history,images,extra:{strata_mcp:useTools===true,...(thinkingBudget>0&&String(thinking).toLowerCase()!=='off'?{reasoning_budget_tokens:thinkingBudget}:{}),reasoning_effort:({off:'none',max:'high'}[String(thinking).toLowerCase()]??String(thinking).toLowerCase())},systemPrompt:[SYSTEM_PROMPT,skillInstructions(applied)].filter(Boolean).join('\n\n'),signal:signal?AbortSignal.any([signal,cancel.signal]):cancel.signal,onFrame:frame=>onFrame({...frame,requestId:entry.id,model:instance.label,contextMax:instance.metrics?.engine?.max_context??instance.context,skills:applied.map(s=>s.name)})});serving.mark(entry.id,{...result,usageSource:result.usageSource});serving.finish(entry.id,{tokensOut:result.tokensOut,durationMs:Date.now()-started});return result;}catch(e){serving.finish(entry.id,{durationMs:Date.now()-started,error:e.message});onFrame({type:'error',message:e.message,requestId:entry.id});return {error:e.message};}}diff --git a/apps/host/server/no-model-text.mjs b/apps/host/server/no-model-text.mjsnew file mode 100644index 000000000..06202a1f7--- /dev/null+++ b/apps/host/server/no-model-text.mjs@@ -0,0 +1,3 @@+/** A chat sent while no model can answer: the engine's own wording ("Choose a loaded model ID.") said nothing to a person. */+export const plainNoModel = message => /not ready/i.test(message) ? 'Your model is still loading. You can chat in a moment.'+ : /choose a loaded model/i.test(message) ? 'No model is loaded. Load one in Models first.' : message;diff --git a/apps/host/src/lib/store.ts b/apps/host/src/lib/store.tsindex 5a8ee73b7..6613a8d98 100644--- a/apps/host/src/lib/store.ts+++ b/apps/host/src/lib/store.ts@@ -1526,6 +1526,8 @@ export async function sendMessage(text: string, options: { fromLoop?: boolean; g}// Whatever sent this (the box, a loop, a plan): with no model to answer, say so in plain words and start nothing.if (state.connection === 'live') {+ // The first read of the engine's state has not come back yet: do not say "no model" about something not known yet, and do not send.+ if (!nativeState() && !state.remoteModel && !state.library?.loaded) { pushToast('info', 'Still starting up', 'Strata is still checking your models. Try again in a moment.'); return; }const why = noModelNotice(nativeState(), { remote: !!state.remoteModel, libraryLoaded: !!state.library?.loaded });if (why) { pushToast('info', why.title, why.message); return; }}diff --git a/apps/host/tests/no-model-chat.test.mjs b/apps/host/tests/no-model-chat.test.mjsnew file mode 100644index 000000000..4983acc62--- /dev/null+++ b/apps/host/tests/no-model-chat.test.mjs@@ -0,0 +1,63 @@+import test from 'node:test';+import assert from 'node:assert/strict';+import { spawn } from 'node:child_process';+import { readFile } from 'node:fs/promises';+import { mkdtemp, rm } from 'node:fs/promises';+import { createServer } from 'node:net';+import { tmpdir } from 'node:os';+import { join } from 'node:path';+import { fileURLToPath } from 'node:url';+import { transform } from 'esbuild';+import { ROOMY_HOST } from './helpers/hardware.mjs';+import { plainNoModel } from '../server/no-model-text.mjs';++/** Sending a chat while no model can answer: say so in plain words, with the one next step, and start no run. */+const root = fileURLToPath(new URL('..', import.meta.url));+const delay = ms => new Promise(r => setTimeout(r, ms));+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('the engine\'s own "no model" wording is turned into plain words with the next step', () => {+ assert.equal(plainNoModel('Choose a loaded model ID.'), 'No model is loaded. Load one in Models first.');+ assert.equal(plainNoModel('This model is not ready.'), 'Your model is still loading. You can chat in a moment.');+ assert.equal(plainNoModel('Something else happened.'), 'Something else happened.');+});++test('the composer\'s notice covers every state: downloading, loading, none, and a model that can answer', async () => {+ const { noModelNotice } = await import(`data:text/javascript;base64,${Buffer.from((await transform(await readFile(new URL('../src/lib/no-model.ts', import.meta.url), 'utf8'), { loader: 'ts', format: 'esm' })).code).toString('base64')}`);+ const none = noModelNotice({ instances: [], jobs: [] });+ assert.deepEqual(none, { title: 'No model is loaded', message: 'No model is loaded. Load one in Models first.' });+ assert.match(noModelNotice({ instances: [], jobs: [{ kind: 'install', state: 'running', result: { install: { download: { percent: 76 } } } }] }).message, /downloading \(76%\)\. You can chat when it has finished/);+ assert.match(noModelNotice({ instances: [{ status: 'loading' }], jobs: [] }).message, /still loading/);+ assert.match(noModelNotice({ instances: [{ status: 'error' }, { status: 'stopped' }], jobs: [] }).title, /No model is loaded/, 'a model that failed or stopped cannot answer');+ assert.equal(noModelNotice({ instances: [{ status: 'loading' }, { status: 'ready' }], jobs: [] }), null);+});++test('sendMessage checks for a model before it adds the message, picks a chat or calls the host, and waits for the first read of the engine', async () => {+ const source = (await readFile(new URL('../src/lib/store.ts', import.meta.url), 'utf8')).replace(/\r\n/g, '\n');+ const start = source.indexOf('export async function sendMessage');+ const body = source.slice(start, source.indexOf('\n}\n', start));+ const guard = body.indexOf('noModelNotice(');+ assert.ok(guard > 0, 'the guard is in sendMessage, the one entry for typed messages, loops, plans, goals and Resume');+ for (const later of ['newSession()', 'api.', 'fetch(', 'streamReal', 'appendMessage', 'takeChatPhotos']) {+ const at = body.indexOf(later);+ assert.ok(at < 0 || at > guard, `${later} comes after the guard`);+ }+ assert.match(body, /!nativeState\(\) && !state\.remoteModel && !state\.library\?\.loaded\) \{ pushToast\('info', 'Still starting up'/, 'before the first read of the engine nothing is claimed and nothing is sent');+});++test('over HTTP, a chat with no model loaded gets one plain error and no reply', async t => {+ const home = await mkdtemp(join(tmpdir(), 'strata-nomodel-'));+ const port = await freePort();+ const host = spawn(process.execPath, ['server/index.mjs'], { cwd: root, stdio: 'ignore', env: { ...process.env, STRATA_HOME: home, STRATA_MODELS_DIR: join(home, 'models'), STRATA_PORT: String(port), STRATA_SHARE_PORT: String(await freePort()), STRATA_TUNNEL_PORT: String(await freePort()), STRATA_REAL_ENGINE: '0', STRATA_TEST_HARDWARE: ROOMY_HOST } });+ t.after(async () => { host.kill(); await new Promise(r => host.once('exit', r)); await rm(home, { recursive: true, force: true }).catch(() => {}); });+ let up = false;+ for (let i = 0; i < 150 && !up; i++) { try { up = (await fetch(`http://127.0.0.1:${port}/api/health`)).ok; } catch { await delay(100); } }+ assert.ok(up, 'host started');+ const response = await fetch(`http://127.0.0.1:${port}/api/chat/stream`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ message: 'hello', sessionId: 'chat-1', mode: 'manual' }) });+ const frames = (await response.text()).split('\n').filter(Boolean).map(line => JSON.parse(line));+ assert.ok(!frames.some(f => f.type === 'start' || f.type === 'delta'), `no reply started: ${JSON.stringify(frames)}`);+ const failure = frames.find(f => f.type === 'error');+ assert.ok(failure, `an error frame: ${JSON.stringify(frames)}`);+ assert.match(failure.message, /No model is loaded|still loading/);+ assert.doesNotMatch(failure.message, /model ID|Choose a loaded/);+});