okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
261145baa
main
1/** The checks of a hand-edited run config (server/run-config-check.mjs) as sentences in the person's language. */ 2import { tr } from './i18n' ; 3 4export interface RunConfigIssue { level :'error' | 'warning' ; code :string ; key :string | null ; line :number | null ; params :Record < string , string | number >; message :string } 5export interface SettingsFileInfo { model :string ; path :string ; name :string ; ok :boolean ; issues :RunConfigIssue []; note :string } 6 7/** One issue as a sentence. Every sentence is a fixed string so every language has it; names and numbers are slots. */ 8export function issueText ( issue :RunConfigIssue ) :string { 9const p = issue . params ; 10const text = (() => { 11switch ( issue . code ) { 12case 'json' :return p . line ?tr ( 'The settings file is not valid JSON; look near line {0}. Check for a missing comma between two entries, a comma after the last entry, or a missing quote.' , [ p . line ]) :tr ( 'The settings file is not valid JSON. Check for a missing comma between two entries, a comma after the last entry, or a missing quote.' ); 13case 'not-object' :return tr ( 'The settings file must hold one object, { … }, with the settings inside.' ); 14case 'unknown-key-near' :return tr ( '"{0}" is not a setting Strata reads, so it is ignored. Did you mean "{1}"?' , [ p . key , p . near ]); 15case 'unknown-key' :return tr ( '"{0}" is not a setting Strata reads, so it is ignored.' , [ p . key ]); 16case 'args-type' :return tr ( '"args" must be a list of quoted text entries, for example ["--ple-io", "mmap"]. Numbers need quotes too.' ); 17case 'args-managed' :return tr ( 'Strata manages the network address, port and API key itself, so --host, --port and --api-key in "args" are not honoured.' ); 18case 'env-type' :return tr ( '"env" must be an object of STRATA_ names with quoted text values.' ); 19case 'env-value' :return tr ( '"env" entry {0} must be quoted text, for example "1".' , [ p . name ]); 20case 'sampling-type' :return tr ( '"sampling" must be an object such as { "temperature": 0.7 }.' ); 21case 'bool' :return tr ( '"{0}" must be true or false, not {1}.' , [ p . key , p . value ?? '' ]); 22case 'number-range' :return tr ( '"{0}" must be a number from {1} to {2}, not {3}.' , [ p . key , p . min , p . max , p . value ]); 23case 'whole-range' :return tr ( '"{0}" must be a whole number from {1} to {2}, not {3}.' , [ p . key , p . min , p . max , p . value ]); 24case 'choice' :return tr ( '"{0}" must be one of {1}, not {2}.' , [ p . key , p . choices , p . value ]); 25case 'text' :return tr ( '"{0}" must be short text, or a list of short names.' , [ p . key ]); 26case 'layer-split' :return tr ( '"layer_split" points must increase from 1 to 47, for example "16,32", or be "auto".' ); 27case 'gpu' :return tr ( '"gpu" must be a graphics card number such as 0, or a list such as [0, 1].' ); 28default :return issue . message ; 29} 30})(); 31return issue . line ?tr ( 'Line {0}: {1}' , [ issue . line , text ]) :text ; 32}