okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
9caf39495
main
1import type { ModelLibrary , ModelVariant } from './types' ; 2 3export function pickerVersionState ( version :ModelVariant , loaded :string | null ) { 4const busy = [ 'downloading' , 'loading' , 'unloading' ]. includes ( version . state ); 5const installed = [ 'installed' , 'loaded' , 'loading' , 'unloading' ]. includes ( version . state ) || !! version . installedAt ; 6const running = version . id === loaded && ! [ 'loading' , 'unloading' , 'error' ]. includes ( version . state ); 7const labels = { available :'Download' , downloading :`Downloading ${ Math . round ( version . progress ?. pct ?? 0 )} %` , installed :'Downloaded' , loading :'Loading…' , loaded :'Downloaded' , unloading :'Unloading…' , error :'Retry' }; 8return { busy, installed, running, label :running ?'Running' :labels [ version . state ], action :version . state === 'error' ?installed ?'Retry loading' :'Retry download' :installed ?'Switch version' :'Download version' }; 9} 10export function pickerVersions ( library :ModelLibrary , versions :ModelVariant []) { 11return [ ...versions ]. sort (( a , b ) => Number ( b . id === library . loaded ) - Number ( a . id === library . loaded ) || a . diskGb - b . diskGb ); 12} 13 14/** Keep downloadable catalog entries in the library; the chat picker uses files already on this PC. */ 15export function pickerGroups ( library :ModelLibrary ) { 16const groups = new Map < string , ModelVariant []>(); 17for ( const version of pickerVersions ( library , library . variants )) { 18if ( ! pickerVersionState ( version , library . loaded ). installed ) continue ; 19const versions = groups . get ( version . family ) ?? []; 20versions . push ( version ); 21groups . set ( version . family , versions ); 22} 23return Array . from ( groups , ([ family , versions ]) => ({ family, versions})); 24} 25 26/** Optimized models that are on this PC but not loaded yet: the chat picker must list them, or it says "none downloaded" while Storage shows them (#3814). */ 27export function pickerNativeModels < M extends { model :string ; model_name ?:string ; ready ?:boolean } > ( installed :M [] | undefined | null , instances :{ label :string }[] | undefined | null ) :M [] { 28const loaded = new Set (( instances ?? []). map ( i => i . label )); 29return ( installed ?? []). filter ( m => m . ready !== false && ! loaded . has ( m . model_name ?? m . model )); 30}