diff --git a/packages/webui/src/public/display.js b/packages/webui/src/public/display.js index e7fc6606e..b94ddf27c 100644 --- a/packages/webui/src/public/display.js +++ b/packages/webui/src/public/display.js @@ -288,6 +288,18 @@ window.MosaicLocalTime = value => Number.isFinite(Date.parse(value)) ? new Date( entry.focus(); } + const harnessRefused = h => h + ? `Not sent. The model Triage uses doesn't run with ${h}, the program its route says runs it. Choose a model that runs with ${h}, or another program, in Triage settings.` + : 'Not sent. The model Triage uses doesn\'t run with the program its route says runs it. Choose a model and a program that run together in Triage settings.'; + // The route read (Settings > Triage's own read) names the harness; any failure keeps the line without it. + async function routeHarness() { + try { + const r = await systemFetch('/api/triage/route', { cache: 'no-store', redirect: 'manual' }); + const h = r.ok ? (await r.json())?.route?.harness : null; + return typeof h === 'string' && h ? clean(h, 64) : null; + } catch { return null; } + } + // Plain words for each answer. A refused send keeps the draft; an unknown outcome is never resent. function answer(status, body) { const code = body && typeof body.error === 'string' ? body.error : ''; @@ -300,7 +312,8 @@ window.MosaicLocalTime = value => Number.isFinite(Date.parse(value)) ? new Date( // Slice 1 has no way to issue a Triage key, so that line ends at what is missing. if (status === 409 && code === 'triage-key-missing') return { text: 'Not sent. Triage isn\'t turned on yet: it needs a Triage key, and none is issued on this instance.' }; if (status === 409 && code === 'triage-proxy-down') return { text: 'Not sent. The model service isn\'t running, so Triage can\'t start.', link: SERVICE_FIX }; - if (status === 409 && code === 'triage-harness-incompatible') return { text: 'Not sent. Triage runs only with Claude Code, and the chosen model doesn\'t run with it. Choose a model that runs with Claude Code in Triage settings.', link: TRIAGE_FIX }; + // The harness is named as its module declares it, from the route read in send(); no list of names lives here. + if (status === 409 && code === 'triage-harness-incompatible') return { text: harnessRefused(null), harnessRefused: true, link: TRIAGE_FIX }; if (status === 409 && code === 'triage-model-not-offered') return { text: 'Not sent. The model Triage uses is no longer offered. Choose another model in Triage settings.', link: TRIAGE_FIX }; if (status === 409 && code === 'triage-catalogue-unavailable') return { text: 'Not sent. The model service can\'t confirm Triage\'s model right now, so Triage can\'t start.', link: SERVICE_FIX }; // Any other route refusal (an unsafe key file, ...) carries its own plain line. @@ -331,6 +344,7 @@ window.MosaicLocalTime = value => Number.isFinite(Date.parse(value)) ? new Date( try { const r = await systemFetch('/api/triage/message', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ text }), cache: 'no-store', redirect: 'manual' }); result = answer(r.status, await r.json().catch(() => null)); + if (result.harnessRefused) { const h = await routeHarness(); if (h) result.text = harnessRefused(h); } } catch { result = { unknown: true, text: 'The Console did not answer. The message may or may not have arrived. It was not sent again: check the conversation before you send it again.' }; } diff --git a/packages/webui/src/public/triage-settings.js b/packages/webui/src/public/triage-settings.js index c64de1507..6af4d58ce 100644 --- a/packages/webui/src/public/triage-settings.js +++ b/packages/webui/src/public/triage-settings.js @@ -33,15 +33,12 @@ const models = () => (Array.isArray(data?.choices?.models) ? data.choices.models : []); const harnessesOf = key => models().find(m => m.key === key)?.harnesses ?? []; - // #1873 settings slice 1 (section 9): the owner reads a harness by its product name; the id stays the value. - const HARNESS_NAMES = { 'claude-code': 'Claude Code', codex: 'Codex', opencode: 'OpenCode' }; - const harnessName = h => HARNESS_NAMES[h] ?? h; const savedAt = v => (Number.isFinite(Date.parse(v)) ? window.MosaicLocalTime(v) : 'at an unknown time'); function stored() { const r = data?.route; if (!r) return `

Not set. Triage has no model chosen yet, so it will not start.

`; - return `

Saved route: ${esc(r.model)}, runs with ${esc(harnessName(r.harness))}. Daily token limit ${esc(Number(r.cap).toLocaleString('en-US'))}, resets at ${esc(r.reset)} ${esc(r.timeZone)}. Saved ${esc(savedAt(r.updatedAt))}.

`; + return `

Saved route: ${esc(r.model)}, runs with ${esc(r.harness)}. Daily token limit ${esc(Number(r.cap).toLocaleString('en-US'))}, resets at ${esc(r.reset)} ${esc(r.timeZone)}. Saved ${esc(savedAt(r.updatedAt))}.

`; } function form() { @@ -55,14 +52,14 @@ + list.map(m => ``).join(''); const hs = harnessesOf(d.model); const harnessOptions = `` - + (d.harness && !hs.includes(d.harness) ? `` : '') - + hs.map(h => ``).join(''); + + (d.harness && !hs.includes(d.harness) ? `` : '') + + hs.map(h => ``).join(''); const status = data?.choices?.status; const catalogue = status === 'ready' ? '' : `

No organization can show your models right now, so no route can be saved. Open Model setup to see why each organization can't see your models.

`; const conflictButton = conflict ? ' ' : ''; return `${catalogue}
` + `` - + `` + + `` + `` + `` + `` diff --git a/packages/webui/tests/triage-drawer-browser.test.mjs b/packages/webui/tests/triage-drawer-browser.test.mjs index f484be322..43f391c9a 100644 --- a/packages/webui/tests/triage-drawer-browser.test.mjs +++ b/packages/webui/tests/triage-drawer-browser.test.mjs @@ -472,17 +472,21 @@ test('triage-cap: a read without the usage fields shows no usage line', async t assert.equal(await f.b.evaluate('document.querySelector("#triage-usage").hidden'), true); }); +// The Triage route read this test server does not mount: the route names its harness as the module is installed. +const ROUTE_READ = `(()=>{const prev=window.fetch;window.fetch=(i,init)=>{if(new URL(typeof i==="string"?i:i.url,location.href).pathname==="/api/triage/route")return Promise.resolve(new Response(JSON.stringify({route:{model:"sonnet",harness:"claude-code",cap:150000,reset:"00:00",timeZone:"UTC",revision:1,updatedAt:"2026-11-18T12:00:00.000Z"},revision:1,choices:{status:"ready",models:[]},send:true,note:""}),{status:200,headers:{"content-type":"application/json"}}));return prev(i,init);};})()`; + // #1873 settings slice 1, bullet 5 (DESIGN.md section 5): a route refusal is a plain line that says what is -// missing, with a link to the Settings page that fixes it. The harness refusal names Claude Code. The key -// refusal has no fix page in slice 1, so it ends at what is missing and offers no link. -test('settings-s1 B5: route refusals read as plain lines with the fix link; the harness line names Claude Code', async t => { +// missing, with a link to the Settings page that fixes it. The harness refusal names the route's harness as +// its module declares it, read from the route; no harness name is written into the page. The key refusal has +// no fix page in slice 1, so it ends at what is missing and offers no link. +test('settings-s1 B5: route refusals read as plain lines with the fix link; the harness line names the route\'s harness', async t => { const host = fakeHost({ running: false }); - const f = await setup(t, { host, proxyAdmin: {} }); + const f = await setup(t, { host, proxyAdmin: {}, init: ROUTE_READ }); await open(f); await type(f, 'is acme healthy?'); const { ROUTE_REFUSALS } = await import('../src/triage-host.mjs'); const cases = [ - ['triage-harness-incompatible', /^Not sent\. Triage runs only with Claude Code, and the chosen model doesn't run with it\. Choose a model that runs with Claude Code in Triage settings\. Open Triage settings$/, '#/settings/triage'], + ['triage-harness-incompatible', /^Not sent\. The model Triage uses doesn't run with claude-code, the program its route says runs it\. Choose a model that runs with claude-code, or another program, in Triage settings\. Open Triage settings$/, '#/settings/triage'], ['triage-proxy-down', /^Not sent\. The model service isn't running, so Triage can't start\. Open Model setup$/, '#/settings/model-proxy'], ['triage-model-not-offered', /^Not sent\. The model Triage uses is no longer offered\./, '#/settings/triage'], ['triage-key-missing', /^Not sent\. Triage isn't turned on yet: it needs a Triage key, and none is issued on this instance\.$/, null], @@ -508,6 +512,20 @@ test('settings-s1 B5: route refusals read as plain lines with the fix link; the assert.notEqual(await f.text('h1'), 'Not found'); }); +// When the route read gives no harness (here the server does not mount it), the line stays plain without a name. +test('settings-s1 B5: the harness refusal without a readable route keeps a plain line and its fix link', async t => { + const host = fakeHost({ running: false }); + const f = await setup(t, { host, proxyAdmin: {} }); + await open(f); + await type(f, 'is acme healthy?'); + const { ROUTE_REFUSALS } = await import('../src/triage-host.mjs'); + host.h.next = new TriageError('triage-harness-incompatible', ROUTE_REFUSALS['triage-harness-incompatible']); + const status = await sendAndWait(f, ''); + assert.equal(status, "Not sent. The model Triage uses doesn't run with the program its route says runs it. Choose a model and a program that run together in Triage settings. Open Triage settings"); + assert.equal(await f.b.evaluate('document.querySelector("#triage-send-status a")?.getAttribute("href") ?? null'), '#/settings/triage'); + assert.equal(await f.b.evaluate('document.querySelector("#triage-text").value'), 'is acme healthy?', 'the draft stays'); +}); + // Settings > Triage exists only where /api/config says proxyAdmin, so without it no line links there. test('settings-s1 B5: without the Triage settings page the refusal keeps its line and offers no link to it', async t => { const host = fakeHost({ route: 'not set' }); diff --git a/packages/webui/tests/triage-settings-browser.test.mjs b/packages/webui/tests/triage-settings-browser.test.mjs index 3e77c65ad..aff0022e2 100644 --- a/packages/webui/tests/triage-settings-browser.test.mjs +++ b/packages/webui/tests/triage-settings-browser.test.mjs @@ -46,6 +46,8 @@ test('the owner sees Triage in Settings, "not set" before a first save, the cata assert.equal(await text(b, 'settings-page-title'), 'Triage'); assert.deepEqual(await options(b, 'triage-route-model'), [['', 'Choose a model', false], ['down', 'Down (down) (unavailable)', true], ['glm-flash', 'GLM Flash (glm-flash)', false], ['sonnet', 'Sonnet (sonnet)', false]]); assert.deepEqual(await options(b, 'triage-route-harness'), [['', 'Choose a model first', false]]); + // The help line names no harness: the list carries each harness's id as its module is installed. + assert.equal(await text(b, 'triage-route-harness-help'), 'The program that runs the model, named as its module is installed. The list shows only the programs this model runs with.'); assert.equal(await value(b, 'triage-route-cap'), '', 'no default cap'); assert.equal(await value(b, 'triage-route-zone'), '', 'no default time zone'); assert.equal(await value(b, 'triage-route-reset'), '00:00'); @@ -76,7 +78,7 @@ test('Save posts the fields and the read revision once, then shows the stored ro await wait('/^Saved .+\\.$/.test(document.getElementById("triage-route-line")?.textContent) && document.getElementById("triage-route-stored")?.dataset.revision==="1"'); assert.equal(await b.evaluate('document.activeElement?.id'), 'triage-route-line', 'focus lands on the saved line, not the page body'); assert.deepEqual(await writes(b), [{ method: 'POST', body: { model: 'sonnet', harness: 'claude-code', cap: 150000, timeZone: 'America/Chicago', revision: 0 } }]); - assert.match(await text(b, 'triage-route-stored'), /^Saved route: sonnet, runs with Claude Code\. Daily token limit 150,000, resets at 00:00 America\/Chicago\. Saved .+\.$/); + assert.match(await text(b, 'triage-route-stored'), /^Saved route: sonnet, runs with claude-code\. Daily token limit 150,000, resets at 00:00 America\/Chicago\. Saved .+\.$/); assert.equal(await value(b, 'triage-route-cap'), '150000'); // The next save carries the new revision. await type(b, 'triage-route-cap', '9000');