Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.
C++
Response settings: a number outside its range (Max output tokens -1) is refused with a plain sentence in the dialog and by the host
Niko1221337c70d3c238
diff --git a/apps/host/server/engine.mjs b/apps/host/server/engine.mjsindex 605be5619..63be845b3 100644--- a/apps/host/server/engine.mjs+++ b/apps/host/server/engine.mjs@@ -247,7 +247,7 @@ export async function validate(draft = {}) {if (typeof beginner.readImages !== 'boolean' || beginner.readImages) addError('readImages', 'image input is not supported by this host.');const limits = {'sample.temp': [0, 2], 'sample.topP': [0, 1], 'sample.topK': [0, 10000], 'sample.repeat': [0.5, 3],- 'sample.seed': [-1, 2147483647], 'perf.threads': [1, 1024], 'perf.batch': [1, 65536],+ 'sample.seed': [-1, 2147483647], 'sample.maxTokens': [0, 1048576], 'perf.threads': [1, 1024], 'perf.batch': [1, 65536],'perf.draftDepth': [1, 64], 'mem.expertCache': [0, 10000], 'server.port': [1, 65535],'server.parallel': [1, 64], 'server.queue': [0, 10000], 'server.timeout': [1, 86400],'adv.rope': [0.01, 100], 'adv.ropeBase': [1, 1000000000],diff --git a/apps/host/src/app/SamplingDrawer.tsx b/apps/host/src/app/SamplingDrawer.tsxindex 83088a639..2294ac39a 100644--- a/apps/host/src/app/SamplingDrawer.tsx+++ b/apps/host/src/app/SamplingDrawer.tsx@@ -1,4 +1,5 @@-import { tr } from '../lib/i18n';+import { tr, localeTag } from '../lib/i18n';+import { checkWholeNumber, numberProblem } from '../lib/number-field';/** Response defaults used for the next chat or API request. */import { useEffect, useState } from 'react';import { Btn, Dialog } from '../components/ui';@@ -11,16 +12,23 @@ export function SamplingDrawer({ open, onClose }: {const modelId = useStore(s => s.library?.loaded);const [tab, setTab] = useState<'sampling' | 'advanced'>('sampling');const [local, setLocal] = useState<Record<string, number | boolean>>({});+ // What was typed in a number field, kept as text so a half-typed or wrong number can be said so in words (the save stays off until it is right).+ const [typed, setTyped] = useState<Record<string, string>>({});const [pending, setPending] = useState(false), [error, setError] = useState('');useEffect(() => { if (open) {setLocal({});+ setTyped({});setError('');setTab('sampling');} }, [open, modelId]);const value = (id: string) => local[id] ?? engine?.expert.find(p => p.id === id)?.value ?? 0;const dirty = Object.entries(local).some(([id, v]) => v !== engine?.expert.find(p => p.id === id)?.value);+ const numberFields = [{ id: 'sample.seed', label: 'Seed', min: -1, max: 2147483647 }, { id: 'sample.maxTokens', label: 'Max output tokens', min: 0, max: 1048576 }];+ const formatNumber = (n: number) => n.toLocaleString(localeTag());+ const problemOf = (field: { id: string; min: number; max: number }) => typed[field.id] === undefined ? null : numberProblem(checkWholeNumber(typed[field.id], field.min, field.max), field.min, field.max, formatNumber);+ const invalid = numberFields.some(field => problemOf(field));async function save() {- if (!dirty || pending)+ if (!dirty || pending || invalid)return;setPending(true);setError('');@@ -37,6 +45,7 @@ export function SamplingDrawer({ open, onClose }: {}function reset() {setLocal(Object.fromEntries((engine?.expert ?? []).filter(p => p.id.startsWith('sample.')).map(p => [p.id, p.type === 'toggle' ? Boolean(p.recommended) : Number(p.recommended)])));+ setTyped({});setError('');}function slider(id: string, label: string, min: number, max: number, step: number, hint: string) {@@ -46,7 +55,7 @@ export function SamplingDrawer({ open, onClose }: {<p className="small muted" id={`response-hint-${id}`}>{tr(hint)}</p></div>;}- return <Dialog open={open} title={tr("Response settings")} onClose={() => !pending && onClose()} actions={<><Btn disabled={pending || !engine} onClick={reset}>{tr("Reset defaults")}</Btn><Btn disabled={pending} onClick={onClose}>{tr("Cancel")}</Btn><Btn variant="primary" disabled={pending || !dirty} onClick={() => void save()}>{tr(pending ? 'Saving…' : 'Save changes')}</Btn></>}>+ return <Dialog open={open} title={tr("Response settings")} onClose={() => !pending && onClose()} actions={<><Btn disabled={pending || !engine} onClick={reset}>{tr("Reset defaults")}</Btn><Btn disabled={pending} onClick={onClose}>{tr("Cancel")}</Btn><Btn variant="primary" disabled={pending || !dirty || invalid} onClick={() => void save()}>{tr(pending ? 'Saving…' : 'Save changes')}</Btn></>}><div className="editor-tabs" role="tablist" aria-label={tr("Response settings sections")}>{tr((['sampling', 'advanced'] as const).map(t => <button key={t} id={`response-tab-${t}`} role="tab" aria-selected={tab === t} aria-controls={`response-panel-${t}`} tabIndex={tab === t ? 0 : -1} onClick={() => setTab(t)} onKeyDown={e => { if (['ArrowLeft', 'ArrowRight'].includes(e.key)) {e.preventDefault();@@ -62,7 +71,7 @@ export function SamplingDrawer({ open, onClose }: {{tr(slider('sample.topK', 'Top-k', 0, 200, 1, 'Candidate tokens. Zero removes this limit.'))}</div> : <div className="stack">{tr(slider('sample.repeat', 'Repetition penalty', .5, 3, .01, 'Above 1 discourages repeated text.'))}- <div className="sampling-number-grid">{tr([{ id: 'sample.seed', label: 'Seed', min: -1, max: 2147483647 }, { id: 'sample.maxTokens', label: 'Max output tokens', min: 0, max: 1048576 }].map(field => <label className="input-field" key={field.id}><span>{tr(field.label)}</span><input className="st-input" type="number" min={field.min} max={field.max} step={1} disabled={pending || !engine} value={Number(value(field.id))} onChange={e => setLocal(prev => ({ ...prev, [field.id]: Number(e.target.value) }))}/><small className="muted">{tr(field.id === 'sample.seed' ? '−1 chooses a random seed.' : '0 uses the engine default.')}</small></label>))}</div>+ <div className="sampling-number-grid">{tr(numberFields.map(field => { const problem = problemOf(field); const note = problem ? tr(problem.text, problem.args) : null; return <label className="input-field" key={field.id}><span>{tr(field.label)}</span><input className="st-input" type="number" inputMode="numeric" min={field.min} max={field.max} step={1} disabled={pending || !engine} value={typed[field.id] ?? String(Number(value(field.id)))} aria-invalid={problem ? true : undefined} aria-describedby={`response-note-${field.id}`} onChange={e => { const text = e.target.value; setTyped(prev => ({ ...prev, [field.id]: text })); const check = checkWholeNumber(text, field.min, field.max); if (check.ok) setLocal(prev => ({ ...prev, [field.id]: check.value })); }}/><small id={`response-note-${field.id}`} className={problem ? 'field-problem' : 'muted'} role={problem ? 'alert' : undefined}>{note ?? tr(field.id === 'sample.seed' ? '−1 chooses a random seed.' : '0 uses the engine default.')}</small></label>; }))}</div><div className="response-projection"><div><strong>{tr("Speed projection")}</strong><p className="small muted">{tr("Experimental control vector. Requires a compatible engine with the vector loaded.")}</p></div><button className="st-toggle" role="switch" aria-label={tr("Speed projection")} aria-checked={Boolean(value('sample.speedProjection'))} disabled={pending || !engine} onClick={() => setLocal(prev => ({ ...prev, 'sample.speedProjection': !Boolean(value('sample.speedProjection')) }))}/></div></div>)}</div>diff --git a/apps/host/src/lib/number-field.ts b/apps/host/src/lib/number-field.tsnew file mode 100644index 000000000..53b97a762--- /dev/null+++ b/apps/host/src/lib/number-field.ts@@ -0,0 +1,21 @@+/**+ * A number typed into a settings field (QA report F05: "Max output tokens" took -1 below its minimum of 0 and saved it).+ * The field keeps what the person typed, says in plain words what is wrong, and the save stays off until it is right.+ */+export type NumberCheck = { ok: true; value: number } | { ok: false; problem: 'empty' | 'range' };++/** A whole number between `min` and `max` (both included). Spaces around it are ignored; "1e3", "0.5" and "-" are not whole numbers. */+export function checkWholeNumber(raw: string, min: number, max: number): NumberCheck {+ const text = String(raw ?? '').trim();+ if (!text) return { ok: false, problem: 'empty' };+ if (!/^[+-]?\d+$/.test(text)) return { ok: false, problem: 'range' };+ const value = Number(text);+ if (!Number.isSafeInteger(value) || value < min || value > max) return { ok: false, problem: 'range' };+ return { ok: true, value };+}++/** The sentence under a field that does not hold a good number. `format` writes a number the way the person's language does. */+export function numberProblem(check: NumberCheck, min: number, max: number, format: (n: number) => string): { text: string; args: string[] } | null {+ if (check.ok) return null;+ return check.problem === 'empty' ? { text: 'Enter a number.', args: [] } : { text: 'Enter a whole number from {0} to {1}.', args: [format(min), format(max)] };+}diff --git a/apps/host/src/styles/annotation-fixes.css b/apps/host/src/styles/annotation-fixes.cssindex de2da8c88..5f35e31db 100644--- a/apps/host/src/styles/annotation-fixes.css+++ b/apps/host/src/styles/annotation-fixes.css@@ -57,6 +57,8 @@ input:focus, textarea:focus, [contenteditable]:focus { outline: none; box-shadow.sampling-field p { margin: 1px 0 0; }#response-panel-sampling > .stack { gap: 12px; }.sampling-number-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }+.field-problem { color: var(--st-danger-text); font-size: var(--st-fs-sm); }+.input-field input[aria-invalid="true"] { border-color: var(--st-danger); }.response-projection { display: flex; align-items: center; gap: 20px; }.response-projection > div { flex: 1; }.response-projection p { margin: 6px 0 0; }diff --git a/apps/host/tests/split-qa2-fields.test.mjs b/apps/host/tests/split-qa2-fields.test.mjsnew file mode 100644index 000000000..d6f2cada5--- /dev/null+++ b/apps/host/tests/split-qa2-fields.test.mjs@@ -0,0 +1,40 @@+// QA report F05: a number typed into Response settings is checked against the field's own range.+import test from 'node:test';+import assert from 'node:assert/strict';+import { readFile } from 'node:fs/promises';+import { transform } from 'esbuild';+async function loadTs(path) {+ const { code } = await transform(await readFile(new URL(path, import.meta.url), 'utf8'), { loader: 'ts', format: 'esm' });+ return import(`data:text/javascript;base64,${Buffer.from(code).toString('base64')}`);+}+const { checkWholeNumber, numberProblem } = await loadTs('../src/lib/number-field.ts');++test('Max output tokens: -1 and other numbers outside 0 to 1048576 are refused, whole numbers inside are taken', () => {+ assert.deepEqual(checkWholeNumber('-1', 0, 1048576), { ok: false, problem: 'range' });+ assert.deepEqual(checkWholeNumber('1048577', 0, 1048576), { ok: false, problem: 'range' });+ assert.deepEqual(checkWholeNumber('0', 0, 1048576), { ok: true, value: 0 });+ assert.deepEqual(checkWholeNumber(' 4096 ', 0, 1048576), { ok: true, value: 4096 });+ assert.deepEqual(checkWholeNumber('1048576', 0, 1048576), { ok: true, value: 1048576 });+});++test('Seed accepts -1 (random) and refuses what is not a whole number', () => {+ assert.deepEqual(checkWholeNumber('-1', -1, 2147483647), { ok: true, value: -1 });+ assert.equal(checkWholeNumber('-2', -1, 2147483647).ok, false);+ for (const bad of ['', ' ', '-', '1.5', '1e3', 'abc', '12abc', '99999999999999999999']) assert.equal(checkWholeNumber(bad, -1, 2147483647).ok, false, JSON.stringify(bad));+ assert.deepEqual(checkWholeNumber('', 0, 5), { ok: false, problem: 'empty' });+});++test('the sentence says what is wrong in plain words, with the range written the reader\'s way', () => {+ const fmt = n => n.toLocaleString('en');+ assert.equal(numberProblem(checkWholeNumber('7', 0, 10), 0, 10, fmt), null);+ assert.deepEqual(numberProblem(checkWholeNumber('', 0, 10), 0, 10, fmt), { text: 'Enter a number.', args: [] });+ assert.deepEqual(numberProblem(checkWholeNumber('-1', 0, 1048576), 0, 1048576, fmt), { text: 'Enter a whole number from {0} to {1}.', args: ['0', '1,048,576'] });+});++test('the Response settings dialog uses it: wrong numbers show the sentence and the save stays off', async () => {+ const source = (await readFile(new URL('../src/app/SamplingDrawer.tsx', import.meta.url), 'utf8')).replace(/\r\n/g, '\n');+ assert.match(source, /checkWholeNumber\(text, field\.min, field\.max\)/);+ assert.match(source, /disabled=\{pending \|\| !dirty \|\| invalid\}/);+ assert.match(source, /if \(!dirty \|\| pending \|\| invalid\)/);+ assert.match(source, /aria-invalid=\{problem \? true : undefined\}/);+});diff --git a/apps/host/tests/split-qa2-skills.test.mjs b/apps/host/tests/split-qa2-skills.test.mjsindex 6681be76e..f7db23ad8 100644--- a/apps/host/tests/split-qa2-skills.test.mjs+++ b/apps/host/tests/split-qa2-skills.test.mjs@@ -45,3 +45,18 @@ test('a skill created with Skill enabled off is saved off, kept after a restart,assert.equal(again.find(s => s.id === on.data.id).enabled, true);} finally { await host.stop(); await rm(home, { recursive: true, force: true, maxRetries: 3 }).catch(() => {}); }});++test('F05: the host refuses an output limit below 0 or above its maximum, and keeps the saved one', { timeout: 60000 }, async () => {+ const home = await mkdtemp(join(tmpdir(), 'strata-qa2-tokens-'));+ const host = await startHost(home);+ try {+ const value = async () => (await host.call('/api/engine')).data.expert.find(p => p.id === 'sample.maxTokens').value;+ assert.equal(await value(), 0);+ assert.equal((await host.call('/api/engine', 'PATCH', { expert: [{ id: 'sample.maxTokens', value: -1 }] })).status, 400);+ assert.equal((await host.call('/api/engine', 'PATCH', { expert: [{ id: 'sample.maxTokens', value: 1048577 }] })).status, 400);+ assert.equal((await host.call('/api/engine', 'PATCH', { expert: [{ id: 'sample.maxTokens', value: 2.5 }] })).status, 400);+ assert.equal(await value(), 0, 'nothing was saved');+ assert.equal((await host.call('/api/engine', 'PATCH', { expert: [{ id: 'sample.maxTokens', value: 4096 }] })).status, 200);+ assert.equal(await value(), 4096);+ } finally { await host.stop(); await rm(home, { recursive: true, force: true, maxRetries: 3 }).catch(() => {}); }+});