okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
a1cc285fa
main
1import type { Hardware , MonitorState , RuntimeModel , RuntimeModels , ServeRequest } from './types' ; 2import { gpuId } from './monitor-hardware' ; 3export function deviceLabel ( ids :string [], hardware :Hardware | null ){ 4if ( ! ids . length ) return 'CPU only' ; 5return 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 { 8if ( ! live || ! runtime ) return live ; 9const selected = runtime . instances . find ( i => i . id === id ); 10const entries = selected ?[ selected ] :runtime . instances ; 11const ids = new Set ( entries . map ( i => i . id )); 12const log = selected ?requests . filter ( r => r . instanceId === selected . id ) :requests ; 13if ( runtime . mode === 'real' ) return { ...live , requests :log }; 14const current = entries . find ( i => [ 'generating' , 'thinking' ]. includes ( i . phase )) ?? entries . find ( i => i . phase === 'reading' ); 15const done = log . filter ( r => r . state === 'done' ); 16const phase = current ?. phase ?? 'idle' ; 17const instance = selected ?? ( entries . length === 1 ?entries [ 0 ] :undefined ); 18const prompt = instance ?. prompt ?? { done :0 , total :0 , pct :0 }; 19const count = ( key :'tokensIn' | 'tokensOut' ) => done . reduce (( n , r ) => n + ( r [ key ] ?? 0 ), 0 ); 20return { ...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 , 21queue :{ running :requests . filter ( r => ids . has ( r . instanceId ?? '' ) && r . state === 'generating' ). length , waiting :requests . filter ( r => ids . has ( r . instanceId ?? '' ) && r . state === 'queued' ). length }, 22context :instance ?. context ?? { usedTokens :0 , maxTokens :0 , pct :0 }, 23telemetry :{ thermals :'unavailable' , memory :'unavailable' , ...live . telemetry , throughput :current ?'unavailable' :done . length ?'demo' :'unavailable' , context :instance && instance . context . usedTokens > 0 ?'demo' :'unavailable' }, 24expertCache :{ used :0 , total :0 , source :'unavailable' }, conversationCache :undefined , 25history :live . history . map ( s => ({ ...s , outputTps :null , promptTps :null })), requests :log , 26totals :{ ...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` : "" } ` ;