okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
1306424be
main
1import { api } from './client' ; 2 3/** A saved tuning, as Strata Control reports it (the same store the Terminal uses). */ 4export interface TunePreset { 5id :string ; 6name :string ; 7active :boolean ; 8created ?:string ; 9answers ?:{ class :'exact' | 'placement' | 'nonrepeatable' | 'quality' ; fields :string []; default_repeatable ?:boolean }; 10settings ?:{ args :Record < string , unknown >; env :Record < string , unknown >; per_request :Record < string , unknown > }; 11gain_pct ?:number | null ; 12decode_tok_s ?:number | null ; 13baseline_decode_tok_s ?:number | null ; 14recheck ?:{ last_ok ?:string | null ; last_result ?:{ verdict ?:string ; reason ?:string } | null } | null ; 15slot ?:string ; 16} 17 18export interface TuneStatus { 19ok :boolean ; 20slot :string ; 21suggested_name :string ; 22active :TunePreset | null ; 23/** fresh, soft (a short check is offered) or hard (the settings are not applied; tune again). */ 24state :'fresh' | 'soft' | 'hard' | null ; 25reasons :string []; 26presets :TunePreset []; 27can_undo :boolean ; 28/** the tuning was switched off for these choices (it is kept: last_active can be switched on again) */ 29switched_off ?:boolean ; 30last_active ?:TunePreset | null ; 31} 32 33export interface TuneProgress { stage :string ; text :string | null ; minutesLeft :number | null ; runsDone :number ; runsPlanned :number ; elapsedS :number ; step :string ; /** each measurement so far, as decode tokens per second */ speeds ?:{ label :string ; tok_s :number }[] } 34 35export interface TuneResult { 36summary :string ; 37outcome ?:'improved' | 'default_confirmed' | 'inconclusive' | 'base_failed' | 'cancelled' ; 38message ?:string ; 39gain_pct ?:number ; 40seconds ?:number ; 41pairs ?:number ; 42faster_pairs ?:number ; 43base ?:{ decode_tok_s ?:number | null }; 44chosen ?:{ decode_tok_s ?:number | null }; 45answers ?:{ class :'exact' | 'placement' | 'nonrepeatable' | 'quality' ; fields :string []; default_repeatable ?:boolean }; 46preset ?:{ id :string ; name :string } | null ; 47notes ?:string []; 48/** what the screen shows: faster | already_fastest | busy_pc | failed | stopped */ 49code ?:'faster' | 'already_fastest' | 'busy_pc' | 'failed' | 'stopped' ; 50/** busy_pc: noisy | drift | not_tried; failed: start_failed | no_memory */ 51reason_code ?:string ; 52values ?:{ gain_pct ?:number ; gain_decode_pct ?:number ; base_tok_s ?:number | null ; tuned_tok_s ?:number | null ; noise_pct ?:number | null ; drift_pct ?:number | null ; minutes ?:number ; pairs ?:number ; faster_pairs ?:number ; preset_name ?:string | null }; 53verdict ?:'keep' | 'retune' | 'inconclusive' ; 54reason ?:string ; 55} 56 57const q = ( o :Record < string , string | undefined >) => Object . entries ( o ). filter (([, v ]) => v ). map (([ k , v ]) => ` ${ k } = ${ encodeURIComponent ( v as string )} ` ). join ( '&' ); 58 59export const tuneStatus = ( model :string , resourceProfile :string , vision :string ) => 60api . get < TuneStatus >( `/api/native/tune/status? ${ q ({ model , resourceProfile , vision })} ` ); 61export const tunePresetAction = ( id :string , action :'apply' | 'rename' | 'delete' | 'undo' , body :Record < string , unknown > = {}) => 62api . post ( `/api/native/tune/presets/ ${ id } / ${ action } ` , body ); 63export const tuneOff = ( model :string , resourceProfile :string , vision :string ) => 64api . post ( '/api/native/tune/off' , { model, resourceProfile, vision}); 65/** What a start will really run: the saved tuning's values on top of the configuration (Expert mode shows these). */ 66export const tuneEffective = ( model :string , resourceProfile :string , vision :string ) => 67api . get <{ applied :boolean ; preset :{ id :string ; name :string } | null ; args :string []; env :Record < string , string >; changed :{ flag :string ; was :string | null ; now :string | null }[]; why_not ?:string | null }>( `/api/native/tune/effective? ${ q ({ model , resourceProfile , vision })} ` ); 68export const tuneUndo = ( model :string , resourceProfile :string , vision :string ) => 69api . post ( '/api/native/tune/undo' , { model, resourceProfile, vision}); 70 71/** The four answer classes, in the words the app uses (the Terminal prints the same sentences). */ 72export const ANSWER_NOTICE :Record < string , string > = { 73exact :'Answers are identical to the standard setup.' , 74placement :'Answers may differ slightly from the standard setup.' , 75nonrepeatable :'Answers are not repeatable run to run.' , 76quality :'Includes a quality setting that changes the numbers.' , 77}; 78 79/** Where the standard setup is itself not repeatable (RTX 3060 in low-RAM mode, Arc A750), an exact setting cannot promise identical answers. */ 80export const answerNotice = ( cls ?:string , defaultRepeatable ?:boolean ) => 81cls === 'exact' && defaultRepeatable === false ?'Answers can differ from run to run on this PC even with the standard setup; this setting does not add to that.' :ANSWER_NOTICE [ cls ?? '' ] ?? '' ; 82 83/** 84* Why Start tuning is greyed out (#4804). Every condition that disables it, in the order they are checked: 85* - 'other' another operation (a download, a load, a first-run step) is running: tuning unloads the model, so it waits; 86* - 'loading' the saved tunings of this model have not been read yet (the first read after a download can take a few seconds); 87* - 'unreadable' reading them failed, so there is nothing to tune from until the window is opened again; 88* - 'busy' the last click is still being carried out: a moment, so it gets no sentence; 89* and null when the button works. Only the first three are long enough for a person to wonder, so only they have words. 90*/ 91export type TuneBlock = 'other' | 'loading' | 'unreadable' | 'busy' | null ; 92export function tuneStartBlock ( input :{ busy :boolean ; otherRunning :boolean ; status :unknown ; error :string }) :TuneBlock { 93if ( input . otherRunning ) return 'other' ; 94if ( ! input . status ) return input . error ?'unreadable' :'loading' ; 95if ( input . busy ) return 'busy' ; 96return null ; 97} 98export const TUNE_BLOCK_TEXT :Record < 'other' | 'loading' | 'unreadable' , string > = { 99other :'Finish the current operation first.' , 100loading :'Strata is still checking this model for saved tunings. Start tuning works as soon as that is done.' , 101unreadable :'Strata could not read the tuning details for this model, so tuning cannot start. Close this window and open it again.' , 102};