okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
0b3299a01
main
1/** One conservative policy for operations affecting the shared loaded model. */ 2export function lifecyclePolicy ( input :{ 3connected :boolean ; 4streaming :boolean ; 5stats ?:{ running ?:number ; waiting ?:number } | null ; 6busy :Record < string , boolean | undefined >; 7}) { 8const { running, waiting} = input . stats ?? {}; 9if ( ! input . connected || ! Number . isFinite ( running ) || ! Number . isFinite ( waiting )) 10return { allowed :false , reason :'Request status unavailable. Reconnect before changing the loaded model.' }; 11if ( input . streaming || running ! > 0 || waiting ! > 0 ) 12return { allowed :false , reason :` ${ running ! > 0 ? running : input . streaming ? 'A' : 0 } active · ${ waiting } queued. Finish or cancel requests first.` }; 13if ( Object . entries ( input . busy ). some (([ key , value ]) => value && ( key === 'restart' || key === 'unload' || key === 'modelDirectory' || key . startsWith ( 'load:' )))) 14return { allowed :false , reason :'A model operation is in progress.' }; 15return { allowed :true , reason :'' }; 16}