okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
261145baa
main
1/** 2* Does the installed engine read a model's files? The catalog (tools/strata_mcp.py, from setup.py's MODELS) names the first engine 3* that does (`engine_min`, e.g. Gyro: 0.1.45.1, because its expert files are native_experts v5 and the released 0.1.45 stops at v4). 4* An older engine would start the download and then fail on the files, so the app says "needs a newer engine" first. 5*/ 6export function parseEngineVersion ( value ) { 7const m = / ^\s * v ? ( \d + (?: \.\d + ){ 0 , 3 }) / . exec ( String ( value ?? '' )); 8return m ?m [ 1 ]. split ( '.' ). map ( Number ) :null ; 9} 10 11/** True when `installed` is known and older than `minimum`. An engine built from this checkout ('local') or one whose version cannot be read is never called too old. */ 12export function engineTooOld ( installed , minimum , source = null ) { 13if ( ! minimum || source === 'local' ) return false ; 14const have = parseEngineVersion ( installed ), need = parseEngineVersion ( minimum ); 15if ( ! have || ! need ) return false ; 16for ( let i = 0 ; i < 4 ; i ++ ) { 17const a = have [ i ] ?? 0 , b = need [ i ] ?? 0 ; 18if ( a !== b ) return a < b ; 19} 20return false ; 21} 22 23/** The catalog with `needsNewerEngine` on every size the installed engine cannot read. */ 24export function markEngine ( catalog , engine ) { 25if ( ! catalog || ! Array . isArray ( catalog . families )) return catalog ; 26const version = engine ?. version ?? null , source = engine ?. source ?? null ; 27return { ...catalog , families :catalog . families . map ( f => ({ ...f , sizes :( f . sizes ?? []). map ( s => ({ ...s , needsNewerEngine :engineTooOld ( version , s . engine_min , source ) })) })) }; 28} 29 30/** The plain sentence for a refused install or load, or null when the engine is new enough. */ 31export function engineRefusal ( catalog , modelId , engine ) { 32const size = catalog ?. families ?. flatMap ( f => f . sizes ?? []). find ( s => s . id === modelId ); 33if ( ! size ?. needsNewerEngine ) return null ; 34return `This model needs a newer engine: ${ size . model } needs engine ${ size . engine_min } or newer, and this one is ${ engine ?. version } . Update the engine in Settings, then try again.` ; 35}