okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221rc1 merge tui-update (3165c2e8a)a1cc285fa

main
2.7 KiB33 linesraw
1import type { Hardware, MonitorState, RuntimeModel, RuntimeModels, ServeRequest } from './types';
2import { gpuId } from './monitor-hardware';
3export function deviceLabel(ids:string[],hardware:Hardware|null){
4  if(!ids.length)return 'CPU only';
5  return ids.map(id=>{const index=hardware?.gpus.findIndex(g=>gpuId(g)===id)??-1;return index>=0?`GPU ${index+1}`:'GPU unavailable';}).join(' + ');
6}
7export function scopedMonitor(live:MonitorState|null,runtime:RuntimeModels|null,id:string,requests:ServeRequest[]):MonitorState|null{
8  if(!live || !runtime)return live;
9  const selected=runtime.instances.find(i=>i.id===id);
10  const entries=selected?[selected]:runtime.instances;
11  const ids=new Set(entries.map(i=>i.id));
12  const log=selected?requests.filter(r=>r.instanceId===selected.id):requests;
13  if(runtime.mode==='real')return {...live,requests:log};
14  const current=entries.find(i=>['generating','thinking'].includes(i.phase))??entries.find(i=>i.phase==='reading');
15  const done=log.filter(r=>r.state==='done');
16  const phase=current?.phase??'idle';
17  const instance=selected??(entries.length===1?entries[0]:undefined);
18  const prompt=instance?.prompt??{done:0,total:0,pct:0};
19  const count=(key:'tokensIn'|'tokensOut')=>done.reduce((n,r)=>n+(r[key]??0),0);
20  return {...live,variantId:instance?.variantId??null,phase,phaseLabel:current?`${current.family} · ${phase==='reading'?'Reading':'Generating'}`:'Waiting for a request',prompt,generation:{done:null,total:null},outputTps:0,promptTps:0,
21    queue:{running:requests.filter(r=>ids.has(r.instanceId??'')&&r.state==='generating').length,waiting:requests.filter(r=>ids.has(r.instanceId??'')&&r.state==='queued').length},
22    context:instance?.context??{usedTokens:0,maxTokens:0,pct:0},
23    telemetry:{thermals:'unavailable',memory:'unavailable',...live.telemetry,throughput:current?'unavailable':done.length?'demo':'unavailable',context:instance&&instance.context.usedTokens>0?'demo':'unavailable'},
24    expertCache:{used:0,total:0,source:'unavailable'},conversationCache:undefined,
25    history:live.history.map(s=>({...s,outputTps:null,promptTps:null})),requests:log,
26    totals:{...live.totals,tokensIn:count('tokensIn'),tokensOut:count('tokensOut'),requests:done.length,cachedTokens:0,uncachedTokens:count('tokensIn'),promptMs:undefined,decodeMs:undefined,avgTps:0}
27  };
28}
29// A quantisation tag is written the way the rest of the app writes it: Q2_0, not q2_0.
30// The catalogue stores the id in lower case, so labels read as a typo beside the
31// Models screen without this.
32const quantLabel=(name:string)=>/^q\d/i.test(name)?name.toUpperCase():name;
33export const instanceLabel=(i:RuntimeModel)=>`${i.family}${i.family.toLowerCase().endsWith(i.name.toLowerCase())?"":` · ${quantLabel(i.name)}`}${i.memory.context>0?` · ${i.memory.context/1024}K`:""}`;