okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
aff3a132f
main
1/** 2* Plain words for failures. The host and Control speak in codes and log lines (`server_exited`, exit codes, "component-missing", 3* a Python message); a person needs what happened and what to do next. Every message the UI shows through ErrorNotice or a toast 4* passes through here: a known failure becomes a sentence and a next step, and the original text stays one click away under 5* "Details" for experts. Strings are fixed so every language has them. 6*/ 7import { tr } from './i18n' ; 8 9export interface PlainFailure { message :string ; next ?:string ; detail ?:string ; kind :string } 10 11interface Rule { kind :string ; match :RegExp ; message :string | (( m :RegExpMatchArray ) => string ); next ?:string ; detail ?:( m :RegExpMatchArray , raw :string ) => string | undefined } 12 13const MEMORY = 'The model stopped while starting, most likely because the PC ran low on memory.' ; 14const MEMORY_NEXT = 'Close other programs and try again, or choose “Leave room for my work”. In Expert mode you can also turn on the low-RAM option, so part of the model is read from the SSD.' ; 15 16/** Order matters: the first rule that matches wins. */ 17const RULES :Rule [] = [ 18// A DeepSeek model of an earlier Strata (strata_control/retired.py, the owner's words of 11-11): Control's own sentences, with the model's name and where 19// its files are and how large, filled in by Control; the next step is the third sentence. Before every other rule (its words name files and deleting). 20// [DRAFT] translations: these sentences stay English in every language (no locale key yet) until the owner has read the wording list; then 21// the next step and the two templated sentences get keys in the nine bundles. 22{ kind :'deepseek-retired' , match :/ (\S.*? is a DeepSeek model\. This version of Strata no longer runs DeepSeek models, so it was not started\.(?: Its files are still on this computer: .+? in .+?\. Nothing was changed or deleted\.)?) / , message :m => m [ 1 ], next :'Choose a Qwen model to run instead. If you no longer need the DeepSeek files, you can delete that folder to free the space.' }, 23// The host names the files it could not find (#3478). The sentence with the names is a template in every language: tr() fills it. 24{ kind :'model-files-missing' , match :/ Some model files are missing: (.+?)\. Use Download / i , message :m => `These model files are missing: ${ m [ 1 ]} .` , next :'Press Download & load again to fetch them. Files that are already there are kept. If the same files are listed again, open Details and share them when you ask for help.' }, 25{ kind :'tunnel-own-running' , match :/ Strata’s tunnel for this address is already running \(PID / i , message :'Strata’s tunnel for this address is already running.' , next :'Stop it first, or use it as it is, then connect again here.' }, 26{ kind :'gpu-shared' , match :/ GPU \d+ is already used by .*, so this model did not fit there / i , message :'Another model on the same graphics card left no room for this one.' , next :'Load it on a different GPU, or unload the other model first.' }, 27{ kind :'gpu-no-code' , match :/ none of this computer.s graphics cards has code in this Strata engine|not an architecture this Strata engine was compiled for / i , message :'This Strata engine has no code for the graphics card it tried to use.' , next :'Pick another card under Run on, or open Details to see which cards were found and what the engine is built for.' }, 28{ kind :'engine-too-old' , match :/ needs a newer engine: .* needs engine / i , message :'This model needs a newer engine.' , next :'Update the engine (Settings, About), then try again.' }, 29{ kind :'settings-file' , match :/ settings file for this model has a mistake / i , message :'Your settings file has a mistake, so the model was not started.' , next :'Open the settings file under Expert settings, fix the line shown under Details, then load the model again.' }, 30{ kind :'connector-missing' , match :/ connector \(cloudflared\) is not installed / i , message :'Strata could not find Cloudflare’s connector (cloudflared) on this computer.' , next :'Install cloudflared (with your package manager, or from Cloudflare’s website), then press Retry setup. Strata finds it on your PATH and in the usual places.' }, 31{ kind :'connector-old' , match :/ cloudflared at .* is version .* too old / i , message :'The Cloudflare connector on this computer is too old.' , next :'Update cloudflared to a newer version, then press Retry setup.' }, 32{ kind :'connector-broken' , match :/ did not run as cloudflared / i , message :'The file found as cloudflared did not run.' , next :'Reinstall cloudflared, then press Retry setup.' }, 33{ kind :'picture-reading' , match :/ vision files|enabling picture reading / i , message :'Picture reading isn’t available for this model.' , next :'Turn off picture reading and try again.' }, 34{ kind :'access' , match :/ PermissionError|access is denied|can.t open its settings file / i , message :'Strata can’t open its settings file.' , next :'Run Strata once as yourself (not as administrator) or press Repair.' }, 35// A start that died: the exit code or the engine's own last line says why. Say "low on memory" only when that evidence is there 36// (2026-10-17: a missing DLL, 0xC0000135, was reported as "ran low on memory" and told the tester to free RAM). 37{ kind :'dll-missing' , match :/ 0xC0000135|3221225781|-1073741515|STATUS_DLL_NOT_FOUND|error while loading shared libraries|cannot open shared object file|Library not loaded / i , message :'The engine could not start because one of its program files is missing on this computer.' , next :'Reinstall Strata (the installer includes it) or press Repair. Closing other programs will not help.' }, 38{ kind :'dll-bad' , match :/ 0xC000007B|3221225595|-1073741701|0xC0000142|3221225794|0xC000012F|bad image / i , message :'The engine could not start because one of its program files does not fit this computer or is damaged.' , next :'Reinstall Strata or press Repair. If it keeps happening, update your graphics driver.' }, 39{ kind :'cpu-unsupported' , match :/ 0xC000001D|3221225501|illegal instruction|SIGILL / i , message :'The engine needs a newer processor feature than this computer has.' , next :'Open Details and share them when you ask for help.' }, 40{ kind :'crash' , match :/ 0xC0000005|3221225477|0xC0000409|3221226505|segmentation fault|SIGSEGV|exit code 139 / i , message :'The engine crashed while starting.' , next :'Restart the PC and try again. If it keeps happening, update your graphics driver and open Details when you ask for help.' }, 41{ kind :'blocked' , match :/ 0xC0000022|3221225506|\bEACCES\b|\bEPERM\b|operation not permitted / i , message :'Windows or your security software stopped the engine from starting.' , next :'Allow Strata in your security software, then try again.' }, 42{ kind :'file-missing' , match :/ \bENOENT\b|no such file or directory|cannot find the (?:file|path)|0x80070002|exit code 127|file not found / i , message :'Strata could not find a file it needs to start the engine.' , next :'Reinstall Strata or press Repair.' }, 43// The engine says it in its own log (the start error carries the last lines): no room left on the card after the weights and the conversation cache (#3723). 44{ kind :'vram' , match :/ no VRAM is left|not enough (?:free )?(?:VRAM|graphics memory|GPU memory|video memory)|out of (?:VRAM|GPU memory|video memory)|VRAM (?:is )?(?:full|exhausted) / i , message :'The model did not fit in your graphics card’s memory.' , next :'Lower the conversation context, or set Context memory to Q4 in Expert settings, then try again.' }, 45{ kind :'memory' , match :/ out of memory|memory guard|\boom\b|\bkilled\b|exit code 137|cannot allocate memory|not enough memory|bad_alloc|pinned-memory-exhausted|mapped staging|cudaErrorMemoryAllocation|insufficient memory / i , message :MEMORY , next :MEMORY_NEXT }, 46{ kind :'previous-session' , match :/ lost host child is still present|retry after it exits / i , message :'The last Strata session is still closing down.' , next :'Wait a moment and try again. If it keeps happening, restart the computer.' }, 47{ kind :'start-failed' , match :/ server_exited|engine stopped|exited before|died before / i , message :'The model stopped while starting.' , next :'Try again. If it keeps happening, open Details and share them when you ask for help.' }, 48{ kind :'slow-load' , match :/ loading took more than / i , message :'Loading is taking too long.' , next :'The PC may be short on memory. Close other programs and try again.' }, 49{ kind :'engine-missing' , match :/ no engine for this pc|engine component|never downloads an engine|engine .*not installed|no strata engine / i , message :'Strata’s engine for this computer isn’t installed yet.' , next :'It is added when you download a model. Download your model again to add it.' }, 50{ kind :'network' , match :/ cannot reach|could not reach|can't reach|timed out|econn|enotfound|getaddrinfo|urlopen|connection (?:reset|refused|aborted)|network is unreachable / i , message :'The download couldn’t reach the internet.' , next :'Check your connection, then press Resume download.' }, 51{ kind :'integrity' , match :/ sha-?256|checksum|does not match|did not match|hash mismatch|safety check / i , message :'A downloaded file didn’t pass Strata’s safety check.' , next :'Press Resume download and Strata will fetch it again.' }, 52{ kind :'assistant-missing' , match :/ agent component|deepseek harness|component-missing|harness .*not (?:installed|found) / i , message :'The coding assistant isn’t installed on this computer yet.' , next :'Chat works without it.' }, 53{ kind :'control' , match :/ strata control (?:could not start|did not answer|stopped)|control did not answer / i , message :'Strata couldn’t read its own components.' , next :'Close and reopen Strata. If this keeps happening, reinstall the app.' }, 54{ kind :'technical' , match :/ traceback|\bexit(?:ed)?(?: code)? \d+|errno|ERR_[A-Z_]+|\bat \S+:\d+|\[X\]|\bENOENT\b|\bEPERM\b|\bEACCES\b / i , message :'Something went wrong.' , next :'Try again. If it keeps happening, open Details and share them when you ask for help.' }, 55]; 56 57/** The message as a person should read it, its next step, and the original text for the Details disclosure. */ 58export function plainFailure ( raw :string | null | undefined ) :PlainFailure { 59const text = unwrapErrorPayload ( String ( raw ?? '' ). replace ( / ^\s*Fixture:\s* / i , '' ). trim ()); 60for ( const rule of RULES ) { 61const m = text . match ( rule . match ); 62if ( ! m ) continue ; 63return { kind :rule . kind , message :typeof rule . message === 'function' ?rule . message ( m ) :rule . message , next :rule . next , detail :rule . detail ?rule . detail ( m , text ) :text }; 64} 65return { kind :'plain' , message :text . replace ( / ^. / , c => c . toUpperCase ()) }; 66} 67 68/** 69* Reduce an error body to the sentence inside it. 70* 71* The host answers a refused request with `{"error":"…"}` and the fetch layer 72* forwards `HTTP 400: {"error":"…"}`; both reached the screen verbatim, so a 73* person was shown a JSON object where a sentence belonged. The wrapper is 74* peeled here — before the rules run, so a wrapped message still matches its 75* own rule — and anything that is not a recognisable error body is returned 76* untouched. 77*/ 78function unwrapErrorPayload ( text :string ) :string { 79// `HTTP 400: {…}` or a bare `{…}` body. 80const body = text . replace ( / ^HTTP\s+\d{3}\s*:\s* / i , '' ). trim (); 81if ( ! body . startsWith ( '{' )) return text ; 82try { 83const parsed = JSON . parse ( body ) as Record < string , unknown >; 84// FastAPI and the host both use `detail`/`error`/`message`, and `detail` 85// is itself sometimes an object with a `message`. 86const detail = parsed . detail ; 87const candidate = [ parsed . error , parsed . message , typeof detail === 'string' ?detail :( detail as Record < string , unknown > | undefined )?. message ] 88. find (( value ) :value isstring => typeof value === 'string' && value . trim (). length > 0 ); 89return candidate ?candidate . trim () :text ; 90} catch { 91return text ; 92} 93} 94 95/** Translated copy of a failure, ready to show. */ 96export function plainFailureText ( raw :string | null | undefined ) { 97const f = plainFailure ( raw ); 98return { ...f , message :tr ( f . message ), next :f . next ?tr ( f . next ) :undefined }; 99}