Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

Merge branch 'fix/300-sampling-popup' into release/3.0.0

purple9b3754d1397b
diff --cc src/components/chat/SamplingControls.tsx
index 033667a1,617f3ce0..454190b5
--- a/src/components/chat/SamplingControls.tsx
+++ b/src/components/chat/SamplingControls.tsx
@@@ -20,28 -47,24 +47,44 @@@ const FIELDS =
{ key: 'topK', label: 'Top K', min: 0, max: 200, step: 1 },
] as const
+/**
+ * Why "Max tokens" carries a draft string instead of the plain number.
+ *
+ * React keeps a controlled `<input type="number">` in step with a LOOSE
+ * comparison (`node.value != value`). With a number on the prop side that
+ * comparison coerces, so "0512" and 512 count as equal and the DOM keeps the
+ * string it already had. Typing 512 into a field showing 0 therefore left
+ * `0512` on screen forever, and the field looked like it appended instead of
+ * replacing (measured on the box, T1 nebenfund 5). Handing React a STRING
+ * turns the same comparison into a string comparison, so the normalised text
+ * really lands in the DOM. The draft covers the other half: while the field is
+ * focused an empty box must stay empty, otherwise nobody can clear it to type
+ * a new number.
+ */
+export function normalizeMaxTokens(raw: string): number {
+ if (raw.trim() === '') return DEFAULT_SETTINGS.maxTokens
+ return Math.max(0, Math.trunc(Number(raw)) || 0)
+}
+
+ /** The close button's accessible name. Word for word the same string as in the
+ * web app (apps/web/lib/sampling.ts), which a parity test there re-reads from
+ * this file: one close button on Windows, Mac and the web app. */
+ export const SAMPLING_CLOSE_LABEL = 'Close sampling settings'
+
+ /** What the popup is called for a screen reader. Same string in both apps. */
+ export const SAMPLING_DIALOG_LABEL = 'Sampling settings'
+
+ /** Panel width, in the same 248 px the web app gives it. */
+ const PANEL_WIDTH = 248
+
+ const FOCUSABLE = 'button:not([disabled]), input:not([disabled]), [tabindex]:not([tabindex="-1"])'
+
export function SamplingControls() {
const [open, setOpen] = useState(false)
+ const [draft, setDraft] = useState<string | null>(null)
+ const wrapRef = useRef<HTMLDivElement>(null)
+ const panelRef = useRef<HTMLDivElement>(null)
+ const panelId = useId()
const settings = useSettingsStore((s) => s.settings)
const update = useSettingsStore((s) => s.updateSettings)
const changed = FIELDS.some((f) => settings[f.key] !== DEFAULT_SETTINGS[f.key])
@@@ -81,23 -178,17 +198,23 @@@
))}
<label className="flex items-center gap-2">
- <span className="w-20 text-gray-400">Max tokens</span>
+ <span className="w-20 shrink-0 text-gray-400">Max tokens</span>
<input
type="number"
- className="flex-1 rounded border border-gray-700 bg-transparent px-1 py-0.5"
+ className="min-w-0 flex-1 rounded border border-gray-700 bg-transparent px-1 py-0.5"
min={0}
step={128}
- value={settings.maxTokens}
+ value={draft ?? String(settings.maxTokens)}
aria-label="Max tokens"
- onChange={(e) => update({ maxTokens: Math.max(0, Number(e.target.value) || 0) })}
+ onChange={(e) => {
+ const raw = e.target.value
+ const next = normalizeMaxTokens(raw)
+ setDraft(raw.trim() === '' ? raw : String(next))
+ update({ maxTokens: next })
+ }}
+ onBlur={() => setDraft(null)}
/>
- <span className="w-10 text-right text-gray-500">{settings.maxTokens === 0 ? 'auto' : ''}</span>
+ <span className="w-10 shrink-0 text-right text-gray-500">{settings.maxTokens === 0 ? 'auto' : ''}</span>
</label>
<div className="flex items-center justify-between pt-1">