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.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(sampling): der Sampling-Regler oeffnet ein Popup und laesst das Prompt-Fenster stehen
purpled0cdc5e8babf
diff --git a/e2e/sampling-popup.spec.ts b/e2e/sampling-popup.spec.tsnew file mode 100644index 00000000..903369e3--- /dev/null+++ b/e2e/sampling-popup.spec.ts@@ -0,0 +1,134 @@+import { test, expect, type Page } from '@playwright/test'+import { tauriMockInit, DEFAULT_ASSISTANT_REPLY, DEFAULT_MODEL_NAME } from './support/tauri-mock'+import { seedOnboardingDone } from './support/cloud-mock'+import { openNewChat } from './support/ui'++/**+ * The sampling control opens a popup and leaves the prompt window alone.+ *+ * David, 2026-09-11: "der sample anklickbar im prompt fenster muss ein pop up+ * sein, und nicht das prompt fenster veraendern. mit einem sauberen x zum+ * wegklicken und nicht einfach wieder auf den text klicken zum entfernen, soll+ * windows mac und webapp ueberall gleich sein."+ *+ * The fields used to render as a sibling below the trigger, inside the action+ * row, so opening them grew the composer by the height of the panel and moved+ * the text field with it. The unit tests can only say that the panel is out of+ * the flow: jsdom has no layout, every box there measures 0, and a height+ * comparison would pass whatever the component did. This file is where the+ * pixels are actually compared, in a real engine with real layout.+ *+ * Measured, before and after opening: the text field, the action row the+ * trigger sits in, and the send button at the end of that row. If any of the+ * three moves or changes size, the popup is not a popup.+ */++interface Kasten { x: number; y: number; w: number; h: number }+interface Masse { textarea: Kasten; row: Kasten; send: Kasten }++async function boot(page: Page) {+ await page.addInitScript(tauriMockInit, {+ assistantReply: DEFAULT_ASSISTANT_REPLY,+ modelName: DEFAULT_MODEL_NAME,+ })+ await seedOnboardingDone(page)+ await page.goto('/')+ await openNewChat(page)+}++/** The composer's geometry, rounded to whole pixels: sub-pixel jitter from the+ * font stack is not a layout change and must not fail this. */+async function masse(page: Page): Promise<Masse> {+ return page.evaluate(() => {+ const runden = (el: Element | null): { x: number; y: number; w: number; h: number } => {+ if (!el) return { x: -1, y: -1, w: -1, h: -1 }+ const b = el.getBoundingClientRect()+ return { x: Math.round(b.x), y: Math.round(b.y), w: Math.round(b.width), h: Math.round(b.height) }+ }+ const send = document.querySelector('[data-testid="composer-send-slot"]')+ return {+ textarea: runden(document.querySelector('textarea')),+ row: runden(send?.parentElement ?? null),+ send: runden(send),+ }+ })+}++test('the popup opens over the composer and moves nothing in it', async ({ page }) => {+ await boot(page)++ const trigger = page.getByTestId('sampling-trigger')+ await expect(trigger).toBeVisible({ timeout: 15_000 })++ const vorher = await masse(page)+ // Sanity: the measurement found real boxes. Without this the comparison+ // below could compare two rows of -1 and pass by reading nothing.+ expect(vorher.textarea.w).toBeGreaterThan(0)+ expect(vorher.row.h).toBeGreaterThan(0)+ expect(vorher.send.w).toBeGreaterThan(0)++ await trigger.click()+ const panel = page.getByTestId('sampling-panel')+ await expect(panel).toBeVisible()++ const nachher = await masse(page)+ expect(nachher).toEqual(vorher)++ // And it really is a popup: it hangs above its trigger and reaches up over+ // the transcript, instead of taking room inside the row.+ const kasten = await panel.boundingBox()+ const ausloeser = await trigger.boundingBox()+ expect(kasten).not.toBeNull()+ expect(ausloeser).not.toBeNull()+ expect(kasten!.y + kasten!.height).toBeLessThanOrEqual(ausloeser!.y + 1)+ expect(kasten!.y).toBeLessThan(vorher.row.y)+})++test('a second press on the trigger leaves the popup standing', async ({ page }) => {+ await boot(page)++ const trigger = page.getByTestId('sampling-trigger')+ await trigger.click()+ await expect(page.getByTestId('sampling-panel')).toBeVisible()++ await trigger.click()+ await expect(page.getByTestId('sampling-panel')).toBeVisible()+ await expect(trigger).toHaveAttribute('aria-expanded', 'true')+})++test('the X closes it, and so does Escape', async ({ page }) => {+ await boot(page)++ const trigger = page.getByTestId('sampling-trigger')+ await trigger.click()+ const x = page.getByRole('button', { name: 'Close sampling settings' })+ await expect(x).toBeVisible()+ await x.click()+ await expect(page.getByTestId('sampling-panel')).toHaveCount(0)+ // The keyboard comes back to the trigger, so the popup can be reopened+ // without reaching for the mouse again.+ await expect(trigger).toBeFocused()++ await trigger.click()+ await expect(page.getByTestId('sampling-panel')).toBeVisible()+ await page.keyboard.press('Escape')+ await expect(page.getByTestId('sampling-panel')).toHaveCount(0)+ await expect(trigger).toBeFocused()+})++test('a value set in the popup is still there when it is opened again', async ({ page }) => {+ await boot(page)++ const trigger = page.getByTestId('sampling-trigger')+ await trigger.click()+ const temperature = page.getByLabel('Temperature')+ await temperature.fill('1.45')+ await page.getByRole('button', { name: 'Close sampling settings' }).click()++ await trigger.click()+ await expect(page.getByLabel('Temperature')).toHaveValue('1.45')+ // The closed trigger shows the same number, which is how the row says that+ // something is on the wire without the popup being open.+ await page.keyboard.press('Escape')+ await expect(trigger).toContainText('1.45')+})diff --git a/src/components/chat/SamplingControls.tsx b/src/components/chat/SamplingControls.tsxindex b67a79c1..617f3ce0 100644--- a/src/components/chat/SamplingControls.tsx+++ b/src/components/chat/SamplingControls.tsx@@ -1,18 +1,45 @@-import { useState } from 'react'+import { useCallback, useEffect, useId, useRef, useState } from 'react'+import { X } from 'lucide-react'import { useSettingsStore } from '../../stores/settingsStore'import { DEFAULT_SETTINGS } from '../../lib/constants'import { HINWEIS_TEXT } from '../../lib/hinweis'+import { useDismissOnEscape } from '../../hooks/useDismissOnEscape'/*** Sampling controls next to the composer.** The values already existed in settings and already reached the request; they* were just buried in the settings page, where nobody adjusts them per- * conversation. Collapsed by default so the composer stays quiet.+ * conversation. Closed by default so the composer stays quiet.** Every catalogue model accepts these parameters (measured 2026-09-10, no* request was rejected for one). Reasoning models accept them and react less,* which the help line says instead of hiding the control.+ *+ * ## Why this is a popup and not an inline panel+ *+ * David, 2026-09-11: "der sample anklickbar im prompt fenster muss ein pop up+ * sein, und nicht das prompt fenster veraendern. mit einem sauberen x zum+ * wegklicken und nicht einfach wieder auf den text klicken zum entfernen, soll+ * windows mac und webapp ueberall gleich sein."+ *+ * The first version rendered the fields as a sibling below the trigger, inside+ * the composer's flow. Opening them therefore grew the whole prompt window by+ * the height of the panel and pushed the text field down under the cursor,+ * which is the one thing the prompt window may not do. The panel is now taken+ * out of the flow (absolute, anchored to the top edge of the trigger, the same+ * placement the model picker next to it uses), so the row it hangs off keeps+ * its size and position to the pixel.+ *+ * Three rules follow from the same sentence, and the web app implements them+ * word for word:+ * - closing is the X, or Escape, or a press outside. SAMPLING_CLOSE_LABEL is+ * the accessible name of that button in BOTH apps.+ * - the trigger opens and only opens. A second click on it used to make the+ * panel vanish under the pointer, which is what "nicht einfach wieder auf+ * den text klicken zum entfernen" asks to stop.+ * - the keyboard goes into the popup when it opens and back to the trigger+ * when it closes.*/const FIELDS = [{ key: 'temperature', label: 'Temperature', min: 0, max: 2, step: 0.05 },@@ -20,20 +47,80 @@ const FIELDS = [{ key: 'topK', label: 'Top K', min: 0, max: 200, step: 1 },] as const+/** 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 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])|| settings.maxTokens !== DEFAULT_SETTINGS.maxTokens+ /** Give the keyboard back to the trigger, but only while it is still in the+ * popup: on an outside press the browser is already moving it somewhere the+ * user chose, and taking it back from them is worse than a lost menu. */+ const close = useCallback(() => {+ const panel = panelRef.current+ if (panel && panel.contains(document.activeElement)) {+ wrapRef.current?.querySelector('button')?.focus()+ }+ setOpen(false)+ }, [])++ const onEscape = useCallback(() => {+ close()+ wrapRef.current?.querySelector('button')?.focus()+ }, [close])+ useDismissOnEscape(open, onEscape)++ // pointerdown, not mousedown or click: a touch screen never sends mousedown+ // before the tap completes. The panel lives inside the wrapper, so one+ // containment test covers the trigger and the popup together.+ useEffect(() => {+ if (!open) return+ const aus = (e: Event) => {+ const target = e.target as Node | null+ if (!target) return+ if (wrapRef.current?.contains(target)) return+ close()+ }+ document.addEventListener('pointerdown', aus)+ return () => document.removeEventListener('pointerdown', aus)+ }, [open, close])++ // The keyboard follows the popup. The X is the first control in it, which is+ // where a dialog's focus conventionally lands and, more to the point, is the+ // way out for someone who never reaches for Escape.+ useEffect(() => {+ if (!open) return+ panelRef.current?.querySelector<HTMLElement>(FOCUSABLE)?.focus()+ }, [open])+return (- <div className="text-xs" data-testid="sampling-controls">+ <div className="relative text-xs" ref={wrapRef} data-testid="sampling-controls"><buttontype="button"className="text-gray-500 hover:text-gray-300"aria-expanded={open}- onClick={() => setOpen((v) => !v)}+ aria-controls={panelId}+ data-testid="sampling-trigger"+ // Opens, never closes. A trigger that also closed made the panel+ // disappear under the pointer on the second click.+ onClick={() => setOpen(true)}>Sampling: {settings.temperature.toFixed(2)}{/* Ein geaenderter Regler ist kein Zwischenfall, also traegt der@@ -42,13 +129,43 @@ export function SamplingControls() {</button>{open && (- <div className="mt-2 space-y-2 rounded border border-gray-700 p-2" data-testid="sampling-panel">+ <div+ ref={panelRef}+ id={panelId}+ role="dialog"+ aria-label={SAMPLING_DIALOG_LABEL}+ data-testid="sampling-panel"+ // Placed with an inline style rather than utility classes, for the+ // same reason the web app does: `position` is then a fact a test can+ // read, instead of a class name a test would have to believe.+ style={{+ position: 'absolute',+ right: 0,+ bottom: '100%',+ marginBottom: 6,+ width: PANEL_WIDTH,+ }}+ className="z-50 space-y-2 rounded-lg p-2.5 lu-elevated"+ >+ <div className="flex justify-end">+ <button+ type="button"+ aria-label={SAMPLING_CLOSE_LABEL}+ title={SAMPLING_CLOSE_LABEL}+ data-testid="sampling-close"+ className="rounded p-0.5 text-gray-500 hover:text-gray-300"+ onClick={close}+ >+ <X size={11} />+ </button>+ </div>+{FIELDS.map((f) => (<label key={f.key} className="flex items-center gap-2">- <span className="w-20 text-gray-400">{f.label}</span>+ <span className="w-20 shrink-0 text-gray-400">{f.label}</span><inputtype="range"- className="flex-1"+ className="min-w-0 flex-1"min={f.min}max={f.max}step={f.step}@@ -56,22 +173,22 @@ export function SamplingControls() {aria-label={f.label}onChange={(e) => update({ [f.key]: Number(e.target.value) })}/>- <span className="w-10 text-right tabular-nums text-gray-300">{settings[f.key]}</span>+ <span className="w-10 shrink-0 text-right tabular-nums text-gray-300">{settings[f.key]}</span></label>))}<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><inputtype="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}aria-label="Max tokens"onChange={(e) => update({ maxTokens: Math.max(0, Number(e.target.value) || 0) })}/>- <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">diff --git a/src/components/chat/__tests__/sampling-controls.test.tsx b/src/components/chat/__tests__/sampling-controls.test.tsxindex 97cd9f0a..afbf97eb 100644--- a/src/components/chat/__tests__/sampling-controls.test.tsx+++ b/src/components/chat/__tests__/sampling-controls.test.tsx@@ -3,10 +3,11 @@ import { beforeEach, describe, expect, it } from 'vitest'import { cleanup, fireEvent, render, screen } from '@testing-library/react'import { useSettingsStore } from '../../../stores/settingsStore'import { DEFAULT_SETTINGS } from '../../../lib/constants'-import { SamplingControls } from '../SamplingControls'+import { SAMPLING_CLOSE_LABEL, SAMPLING_DIALOG_LABEL, SamplingControls } from '../SamplingControls'const settings = () => useSettingsStore.getState().settings-const open = () => fireEvent.click(screen.getByRole('button', { name: /Sampling/ }))+const trigger = () => screen.getByTestId('sampling-trigger')+const open = () => fireEvent.click(trigger())beforeEach(() => {cleanup()@@ -73,3 +74,106 @@ describe('SamplingControls', () => {expect(screen.getByText(/Reasoning models accept these/)).toBeTruthy()})})++/**+ * David, 2026-09-11: "der sample anklickbar im prompt fenster muss ein pop up+ * sein, und nicht das prompt fenster veraendern. mit einem sauberen x zum+ * wegklicken und nicht einfach wieder auf den text klicken zum entfernen, soll+ * windows mac und webapp ueberall gleich sein."+ *+ * The old panel was a sibling in the composer's flow, so opening it grew the+ * prompt window and pushed the text field down. jsdom has no layout at all+ * (every box measures 0), so a height comparison here would pass whatever the+ * component did. What jsdom CAN answer is the fact the layout follows from:+ * whether the panel is in the flow. The pixels are measured for real in+ * e2e/sampling-popup.spec.ts, against the bounding box of the composer row.+ */+describe('the sampling popup', () => {+ it('is a popup over the row, not a panel inside it', () => {+ render(<SamplingControls />)+ open()+ const panel = screen.getByTestId('sampling-panel')+ // Out of the flow: nothing around it can be moved by its height.+ expect(panel.style.position).toBe('absolute')+ // Anchored to the top edge of the trigger, so it opens upward over the+ // transcript and never downward into the send row.+ expect(panel.style.bottom).toBe('100%')+ expect(panel.getAttribute('role')).toBe('dialog')+ expect(panel.getAttribute('aria-label')).toBe(SAMPLING_DIALOG_LABEL)+ })++ it('says on the trigger whether it is open, and which panel it owns', () => {+ render(<SamplingControls />)+ expect(trigger().getAttribute('aria-expanded')).toBe('false')+ open()+ expect(trigger().getAttribute('aria-expanded')).toBe('true')+ expect(trigger().getAttribute('aria-controls')).toBe(screen.getByTestId('sampling-panel').id)+ })++ it('closes on the X, which is what the X is for', () => {+ render(<SamplingControls />)+ open()+ fireEvent.click(screen.getByRole('button', { name: SAMPLING_CLOSE_LABEL }))+ expect(screen.queryByTestId('sampling-panel')).toBeNull()+ })++ it('closes on Escape', () => {+ render(<SamplingControls />)+ open()+ fireEvent.keyDown(document, { key: 'Escape' })+ expect(screen.queryByTestId('sampling-panel')).toBeNull()+ })++ it('closes on a press outside, the way a phone sends it', () => {+ render(<SamplingControls />)+ open()+ fireEvent.pointerDown(document.body)+ expect(screen.queryByTestId('sampling-panel')).toBeNull()+ })++ it('stays open when its own contents are pressed', () => {+ render(<SamplingControls />)+ open()+ fireEvent.pointerDown(screen.getByTestId('sampling-panel'))+ expect(screen.queryByTestId('sampling-panel')).not.toBeNull()+ })++ // The half of David's sentence that is easiest to lose again: a trigger that+ // toggles makes the popup vanish under the pointer on the second press.+ it('does NOT close when the trigger is pressed a second time', () => {+ render(<SamplingControls />)+ open()+ open()+ expect(screen.getByTestId('sampling-panel')).toBeTruthy()+ expect(trigger().getAttribute('aria-expanded')).toBe('true')+ })++ it('still holds the values after closing and opening again', () => {+ render(<SamplingControls />)+ open()+ fireEvent.change(screen.getByLabelText('Temperature'), { target: { value: '1.45' } })+ fireEvent.change(screen.getByLabelText('Max tokens'), { target: { value: '2048' } })+ fireEvent.click(screen.getByRole('button', { name: SAMPLING_CLOSE_LABEL }))+ open()+ expect((screen.getByLabelText('Temperature') as HTMLInputElement).value).toBe('1.45')+ expect((screen.getByLabelText('Max tokens') as HTMLInputElement).value).toBe('2048')+ expect(settings().temperature).toBe(1.45)+ expect(settings().maxTokens).toBe(2048)+ })++ it('takes the keyboard into the popup and hands it back to the trigger', () => {+ render(<SamplingControls />)+ open()+ const x = screen.getByRole('button', { name: SAMPLING_CLOSE_LABEL })+ expect(document.activeElement).toBe(x)+ fireEvent.click(x)+ expect(document.activeElement).toBe(trigger())+ })++ it('hands the keyboard back on Escape too', () => {+ render(<SamplingControls />)+ open()+ fireEvent.keyDown(document, { key: 'Escape' })+ expect(document.activeElement).toBe(trigger())+ })+})