diff --git a/packages/webui/src/public/bus.js b/packages/webui/src/public/bus.js index 24d36d654..b0ffec0ce 100644 --- a/packages/webui/src/public/bus.js +++ b/packages/webui/src/public/bus.js @@ -574,14 +574,14 @@ const providerRows=[...providers].map(p=>field(['providers',p],p,limits.providers?.[p],usage.providers?.[p])).join(''); const modelRows=[...pairs.values()].map(([p,m])=>field(['models',p,m],`${p} / ${m}`,limits.models?.[p]?.[m],usage.models?.[p]?.[m])).join(''); const table=Object.entries(modelTable).map(([key,m])=>`
${txt(key)}
`).join(''); - const selections=Object.entries(v.instances||{}).map(([instance,entry])=>``).join(''); - return `

Agent limits

Leave a limit blank for no limit. Zero stops new launches. Running sessions keep running when limits or models change.

All sessions${field(['total'],'Total',limits.total,usage.total)}
By provider
${providerRows}
By provider and model
${modelRows}
Model table${table}
Role models
${selections}

${canSend?'Changes are checked and logged with your identity.':'Saving requires signed-in send mode.'}

${txt(settingsReceipt)}

`; + // Row 65 (mos-0840): each instance's model moved to the routing table below. + return `

Agent limits

Leave a limit blank for no limit. Zero stops new launches. Running sessions keep running when limits or models change.

All sessions${field(['total'],'Total',limits.total,usage.total)}
By provider
${providerRows}
By provider and model
${modelRows}
Model table${table}

${canSend?'Changes are checked and logged with your identity.':'Saving requires signed-in send mode.'}

${txt(settingsReceipt)}

`; } function settingDraft(form){const values={};for(const el of form.querySelectorAll('[data-setting]'))values[el.dataset.setting]=el.value;return values;} - function settingPayload(){const v=settingsSnapshot, limits={providers:Object.create(null),models:Object.create(null)},models=structuredClone(v.models),instances={};for(const [encoded,text]of Object.entries(settingsInputs)){const [kind,p,m]=JSON.parse(encoded);if(kind==='table'){models[p][m]=text;continue;}if(kind==='instances'){instances[p]=text;continue;}if(text==='')continue;if(!/^\d+$/.test(text)||!Number.isSafeInteger(Number(text)))throw Error('Limits need whole numbers of zero or more.');const n=Number(text);if(kind==='total')limits.total=n;else if(kind==='providers')limits.providers[p]=n;else {limits.models[p]??=Object.create(null);limits.models[p][m]=n;}} + function settingPayload(){const v=settingsSnapshot, limits={providers:Object.create(null),models:Object.create(null)},models=structuredClone(v.models);for(const [encoded,text]of Object.entries(settingsInputs)){const [kind,p,m]=JSON.parse(encoded);if(kind==='table'){models[p][m]=text;continue;}if(text==='')continue;if(!/^\d+$/.test(text)||!Number.isSafeInteger(Number(text)))throw Error('Limits need whole numbers of zero or more.');const n=Number(text);if(kind==='total')limits.total=n;else if(kind==='providers')limits.providers[p]=n;else {limits.models[p]??=Object.create(null);limits.models[p][m]=n;}} // Row 125 (#1619): the form doesn't edit token limits; a save keeps them as read. if(v.limits?.tokens)limits.tokens=structuredClone(v.limits.tokens); - return {revision:v.revision,limits,models,instances}; + return {revision:v.revision,limits,models}; } document.addEventListener('input',e=>{const form=e.target.closest?.('#launch-settings-form');if(form)settingsInputs=settingDraft(form);}); document.addEventListener('change',e=>{const form=e.target.closest?.('#launch-settings-form');if(form)settingsInputs=settingDraft(form);}); @@ -727,6 +727,59 @@ else instanceReceipt=response.ok||result?.sent==='unknown'?unknownInstance:`${result?.message||'Refused.'} Draft kept.`;}} catch{instanceReceipt=unknownInstance;}finally{instanceBusy=false;if(!out())render(false);} }); + // Row 65 (mos-0840): the routing table. One row per instance: harness, model and thinking, and + // the fallback's three. Each cell offers the switched-on harnesses, the model table's keys and the + // levels that harness applies; a value the file holds that isn't offered stays, marked, so a save + // sends it and the bus says why it refuses. A fallback is set by choosing all three or cleared by + // choosing none for all three. Save sends the changed rows through routes.set. Drafts survive + // polling and refusals; nothing retries. + let routesView=null, routesDraft=null, routesBusy=false, routesReceipt=''; + const ROUTE_CELLS=[['harness','Harness'],['model','Model'],['thinking','Thinking'],['fallback.harness','Fallback harness'],['fallback.model','Fallback model'],['fallback.thinking','Fallback thinking']]; + const routeCells=r=>({harness:r.harness??'',model:r.model??'',thinking:r.thinking??'','fallback.harness':r.fallback?.harness??'','fallback.model':r.fallback?.model??'','fallback.thinking':r.fallback?.thinking??''}); + const sameCells=(a,b)=>ROUTE_CELLS.every(([k])=>a[k]===b[k]); + function routesSection(view){ + const title='

Routing

'; + if(!view)return `
${title}

The routes could not be read, so there is nothing to change. Read again to retry; they come from the bus host with your identity.

`; + if(!routesDraft)routesView=view; + const v=routesView, disabled=!canSend||out()||routesBusy?' disabled':''; + const cells=name=>routesDraft?.[name]??routeCells(v.instances[name]); + const select=(name,key,list,current,why)=>{const offered=current===''||list.includes(current)?list:[...list,current]; + return ``;}; + const levelsOf=h=>Array.isArray(v.levels[h])?v.levels[h]:[]; + const rows=Object.keys(v.instances).map(name=>{const c=cells(name); + const harness=(key)=>select(name,key,v.harnesses,c[key],'not switched on'); + const model=(key)=>select(name,key,v.models,c[key],'not in the model table'); + const thinking=(key,h)=>select(name,key,levelsOf(c[h]),c[key],c[h]?`not applied by ${c[h]}`:'no harness'); + return `${txt(name)}${harness('harness')}${model('model')}${thinking('thinking','harness')}${harness('fallback.harness')}${model('fallback.model')}${thinking('fallback.thinking','fallback.harness')}`;}).join(''); + const off=v.harnesses.length?'':'

No harness is switched on in the business file\'s plugins.harness, so every launch refuses harness-off and a save that changes a harness refuses too. mosaic plugins set switches one on.

'; + return `
${title}

Each instance's harness, model and thinking, and the fallback a launch takes when the primary harness fails its preflight. A fallback sets all three or none. Running sessions keep their route; the next launch reads the change.

${off}
${ROUTE_CELLS.map(([,l])=>``).join('')}${rows}
Instance${l}

${canSend?'Changes are checked and logged with your identity.':'Saving requires signed-in send mode.'}

${txt(routesReceipt)}

`; + } + function routesFields(form){const draft=Object.fromEntries(Object.keys(routesView.instances).map(name=>[name,routeCells(routesView.instances[name])]));for(const el of form.querySelectorAll('[data-route]')){const [name,key]=JSON.parse(el.dataset.route);if(draft[name])draft[name][key]=el.value;}return draft;} + // The changed rows only. A fallback with all three cells empty is cleared; one with some set goes + // as it is, and the bus refuses it as partial. + function routesPayload(draft){ + const routes={}; + for(const [name,c]of Object.entries(draft)){if(sameCells(c,routeCells(routesView.instances[name])))continue; + const set=['harness','model','thinking'].filter(k=>c[`fallback.${k}`]!==''); + routes[name]={harness:c.harness,model:c.model,thinking:c.thinking,fallback:set.length===0?null:Object.fromEntries(set.map(k=>[k,c[`fallback.${k}`]]))};} + if(!Object.keys(routes).length)throw Error('Nothing changed.'); + return {revision:routesView.revision,routes}; + } + const unknownRoutes='Outcome unknown. Read the routes again before trying. Draft kept.'; + const routesAnswer=r=>/^[a-f0-9]{64}$/.test(r?.revision??'')&&Array.isArray(r.harnesses)&&Array.isArray(r.models)&&[r.levels,r.instances].every(o=>o&&typeof o==='object'&&!Array.isArray(o)); + for(const kind of ['input','change'])document.addEventListener(kind,e=>{const form=e.target?.closest?.('#routes-form');if(!form||!routesView)return;routesDraft=routesFields(form); + // A harness change redraws the row so its thinking cell offers that harness's levels. + if(kind==='change'&&/harness"\]$/.test(e.target.dataset?.route??''))render(false);}); + document.addEventListener('click',e=>{if(e.target.id!=='routes-reload')return;routesDraft=null;routesView=null;routesReceipt='';last.delete('routes');render(true);}); + document.addEventListener('submit',async e=>{ + if(e.target.id!=='routes-form')return;e.preventDefault();if(!canSend||out()||routesBusy||!routesView)return; + routesDraft=routesFields(e.target);let payload;try{payload=routesPayload(routesDraft);}catch(err){routesReceipt=err.message;render(false);return;} + routesBusy=true;routesReceipt='';render(false); + try{const response=await fetch('/api/routes',{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify(payload),cache:'no-store',redirect:'manual'});if(response.type==='opaqueredirect'){routesReceipt='Sign in again. Draft kept.';signOut();}else{const result=await response.json(); + if(response.ok&&routesAnswer(result)){routesDraft=null;routesView=result;const prior=last.get('routes');if(prior)last.set('routes',{...prior,rows:[result]});routesReceipt=`Routes saved for ${Object.keys(payload.routes).join(', ')}. The next launch of each uses the new route.`;} + else routesReceipt=response.ok||result?.sent==='unknown'?unknownRoutes:`${result?.message||'Refused.'} Draft kept.`;}} + catch{routesReceipt=unknownRoutes;}finally{routesBusy=false;if(!out())render(false);} + }); async function settingsView(get) { const s = await get.api('settings'), n = s.notifier || {}; let usage, names = null; @@ -734,12 +787,14 @@ try { names = await get('names'); } catch (err) { if (err.status === 403 || err.code === 'signed-out') throw err; /* the section says the name could not be read */ } let instances = null; try { [instances] = await get('instances'); } catch (err) { if (err.status === 403 || err.code === 'signed-out') throw err; } + let routes = null; + try { [routes] = await get('routes'); } catch (err) { if (err.status === 403 || err.code === 'signed-out') throw err; } let limitRows = [], limitsRefused = false; try { limitRows = await get('limits'); } catch (err) { if (err.status === 403 || err.code === 'signed-out') throw err; limitsRefused = true; } const notify = typeof n.binding === 'string' ? `
Binding
${txt(n.binding)}

The binding name only. Its channels, server and user ids stay in the binding file.

` : empty('No notifier binding to show.', `${n.refused ? `${txt(n.refused)}: ` : ''}${txt(n.message || 'the notifier settings could not be read')}`); - return `${head('Settings', `${readLine()} Agent limits and appearance.`)}${appearance()}${launchForm(s.launch)}${assistantSection(s.launch, names)}${instancesSection(instances)}${tokenLimits(limitRows, limitsRefused)}${tokenUsage(usage)} + return `${head('Settings', `${readLine()} Agent limits and appearance.`)}${appearance()}${launchForm(s.launch)}${routesSection(routes)}${assistantSection(s.launch, names)}${instancesSection(instances)}${tokenLimits(limitRows, limitsRefused)}${tokenUsage(usage)}

Notifications

${notify}

About

Address
${txt(s.address) || 'unknown'}
Release
${s.release ? `${txt(s.release)}` : 'unknown: no RELEASE file was read'}
Business
${txt(s.business) || none}
Board
${txt(s.board) || 'unknown'}
`; }