From 780a69b41b50d04421ebb2014486bef4b951a329 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Sat, 24 Oct 2026 13:47:18 +0200 Subject: [PATCH] Expert settings: decimals can be typed in sampling and number fields; Ctrl+V of a screenshot reads clipboard items (#3736, #3748) --- apps/host/src/components/DecimalInput.tsx | 28 +++++++++++++++++++++ apps/host/src/components/DropZone.tsx | 11 +------- apps/host/src/components/NativeSettings.tsx | 14 ++++------- apps/host/src/lib/decimal.ts | 9 +++++++ apps/host/src/lib/pasted-files.ts | 19 ++++++++++++++ apps/host/tests/typed-and-pasted.test.mjs | 24 ++++++++++++++++++ 6 files changed, 86 insertions(+), 19 deletions(-) create mode 100644 apps/host/src/components/DecimalInput.tsx create mode 100644 apps/host/src/lib/decimal.ts create mode 100644 apps/host/src/lib/pasted-files.ts create mode 100644 apps/host/tests/typed-and-pasted.test.mjs diff --git a/apps/host/src/components/DecimalInput.tsx b/apps/host/src/components/DecimalInput.tsx new file mode 100644 index 00000000..e48f9689 --- /dev/null +++ b/apps/host/src/components/DecimalInput.tsx @@ -0,0 +1,28 @@ +import { useEffect, useState } from 'react'; +import { parseDecimal, partialDecimal } from '../lib/decimal'; + +/** A number field that lets the person type a decimal point: it keeps the text while it is typed and tells the page the number once it is one (#3736). */ +export function DecimalInput({ value, onChange, ariaLabel, className = 'st-input', placeholder, disabled }: { + value: number | null | undefined; + onChange: (value: number | null) => void; + ariaLabel: string; + className?: string; + placeholder?: string; + disabled?: boolean; +}) { + const [text, setText] = useState(value === null || value === undefined ? '' : String(value)); + // A change that came from elsewhere (Restore saved, another tab) replaces the text, but never while the typed text already means this number. + useEffect(() => { + const shown = text === '' ? null : parseDecimal(text); + if ((value ?? null) !== shown) setText(value === null || value === undefined ? '' : String(value)); + }, [value]); + return { + const next = e.target.value; + if (!partialDecimal(next)) return; + setText(next); + if (next.trim() === '') onChange(null); + else { const n = parseDecimal(next); if (n !== null) onChange(n); } + }} + onBlur={() => { const n = text.trim() === '' ? null : parseDecimal(text); setText(n === null ? '' : String(n)); }}/>; +} diff --git a/apps/host/src/components/DropZone.tsx b/apps/host/src/components/DropZone.tsx index c0b1f976..d9a3ed46 100644 --- a/apps/host/src/components/DropZone.tsx +++ b/apps/host/src/components/DropZone.tsx @@ -6,16 +6,7 @@ import { Icon } from './ui'; /** Files dropped on the chat go where the attach button would put them: the composer reads the 'strata:drop-files' event. */ export const DROP_EVENT = 'strata:drop-files'; -/** The pictures on the clipboard, named so each one is told apart in the composer (a pasted screenshot arrives as "image.png"). */ -export function pastedFiles(data: DataTransfer | null | undefined): File[] { - const out: File[] = []; - for (const file of Array.from(data?.files ?? [])) { - if (!file.type.startsWith('image/')) continue; - const extension = file.type.split('/')[1]?.replace('jpeg', 'jpg').replace(/[+].*/, '') || 'png'; - out.push(new File([file], `Pasted picture ${new Date().toLocaleTimeString().replace(/[^0-9]+/g, '-').replace(/-$/, '')}${out.length ? `-${out.length + 1}` : ''}.${extension}`, { type: file.type })); - } - return out; -} +export { pastedFiles } from '../lib/pasted-files'; const hasFiles = (e: React.DragEvent) => Array.from(e.dataTransfer?.types ?? []).includes('Files'); /** A file dropped outside the chat must not take the window to that file: the page ignores it (called once at start). */ diff --git a/apps/host/src/components/NativeSettings.tsx b/apps/host/src/components/NativeSettings.tsx index 8b1e39bb..53eac3e6 100644 --- a/apps/host/src/components/NativeSettings.tsx +++ b/apps/host/src/components/NativeSettings.tsx @@ -1,3 +1,4 @@ +import { DecimalInput } from './DecimalInput'; import { tr } from '../lib/i18n'; import {nativeSettingsResponse,nativeSettingsValues} from '../lib/native-settings-response'; import { describeChange, type TunedChange } from '../lib/tune-values'; @@ -92,14 +93,7 @@ export function NativeSettings({ model }: { ; const rows = (native?.fields ?? []).filter(f => `${tr(f.label)} ${f.id} ${tr(f.group)}`.toLowerCase().includes(query.toLowerCase())); return
{tr("Native engine settings")}{tr(tuned?.changed?.length ?

{tr("Your tuning '{0}' sets", [tuned.preset?.name ?? ''])}

    {tuned.changed.map(c => { const d = describeChange(c); return
  • {d.name}{d.now || tr('off')}{d.was !== null ? {tr("was {0}", [d.was])} : null}
  • ; })}
: null)}

{tr(!original ? 'Reading saved settings… ' : '')}{tr("Settings for this model. Blank values use Strata\u2019s defaults.")}

{tr(['fields', 'json', 'tools'].map(t => ))}
- {tr(tab === 'fields' ? <> setQuery(e.target.value)}/>{tr(['Responses', 'GPU & memory', 'Serving', 'Image reading', 'Tools', 'Recovery'].map(group => rows.some(f => f.group === group) ?

{tr(group)}

{tr(rows.filter(f => f.group === group).map(f => ))}
: null))}

{tr("Sampling")}

{tr([['temperature', 'Temperature'], ['top_p', 'Top-p'], ['top_k', 'Top-k'], ['min_p', 'Min-p'], ['repetition_penalty', 'Repetition penalty'], ['presence_penalty', 'Presence penalty'], ['frequency_penalty', 'Frequency penalty'], ['penalty_last_n', 'Penalty window'], ['seed', 'Seed']].map(([id, label]) => ))}
: tab === 'json' ? <>

{tr("Engine arguments and STRATA environment flags are editable here. Program paths and network access remain managed by the host.")}