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(settings): Compact at can be typed and stepped again
purplee14874cd0c7b
diff --git a/src/components/settings/CompactThresholdInput.tsx b/src/components/settings/CompactThresholdInput.tsxnew file mode 100644index 00000000..879d2a11--- /dev/null+++ b/src/components/settings/CompactThresholdInput.tsx@@ -0,0 +1,75 @@+import { useState, type ChangeEvent, type KeyboardEvent } from 'react'+import { useSettingsStore } from '../../stores/settingsStore'+import { compactThresholdFromPercent, stepCompactPercent } from '../../lib/settings-catalog'++/**+ * The "Compact at" field under Settings, General, Generation. Shown in+ * percent, stored as a fraction; 0 (fit the model) or 30 to 95.+ *+ * Jaeger B, B1: every keystroke used to be saved through the 0-or-30-95 rule,+ * so the first digit of "50" became 0 before the second could follow, and an+ * arrow step went 0 to 5, which the rule turned back into 0. The field now+ * keeps what is typed until it loses focus or Enter is pressed, the same way+ * the chat reply timeout does (ChatReplyTimeoutSettings.tsx), and a step+ * jumps the gap between 0 and 30 instead of landing in it.+ */+export function CompactThresholdInput() {+ const threshold = useSettingsStore((s) => s.settings.autoCompactThreshold)+ const disabled = useSettingsStore((s) => s.settings.autoCompact === false)+ const updateSettings = useSettingsStore((s) => s.updateSettings)+ const [draft, setDraft] = useState<string | null>(null)+ const stored = Math.round((threshold || 0) * 100)++ // Same rule as set_setting from the chat (lib/settings-catalog.ts).+ const save = (pct: number) => updateSettings({ autoCompactThreshold: compactThresholdFromPercent(pct) })+ const commit = () => {+ if (draft === null) return+ save(parseInt(draft, 10) || 0)+ setDraft(null)+ }+ const step = (dir: 1 | -1) => {+ const from = draft === null ? stored : compactThresholdFromPercent(parseInt(draft, 10) || 0) * 100+ save(stepCompactPercent(from, dir))+ setDraft(null)+ }++ const onChange = (e: ChangeEvent<HTMLInputElement>) => {+ // The spin buttons change the value without typing: the browser sends a+ // plain input event, typing sends an InputEvent with an inputType.+ const native = e.nativeEvent as Partial<InputEvent>+ const typed = typeof native.inputType === 'string' && native.inputType !== ''+ const n = parseInt(e.target.value, 10)+ const shown = draft === null ? stored : parseInt(draft, 10)+ if (!typed && draft === null && Number.isFinite(n) && Math.abs(n - shown) === 5) {+ step(n > shown ? 1 : -1)+ return+ }+ setDraft(e.target.value)+ }++ const onKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {+ if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {+ e.preventDefault()+ step(e.key === 'ArrowUp' ? 1 : -1)+ } else if (e.key === 'Enter') {+ commit()+ }+ }++ return (+ <input+ aria-label="Auto-compact at"+ type="number"+ value={draft ?? String(stored)}+ disabled={disabled}+ onChange={onChange}+ onKeyDown={onKeyDown}+ onBlur={commit}+ min={0}+ max={95}+ step={5}+ placeholder="0"+ className="w-20 px-1.5 py-0.5 rounded bg-transparent border border-white/8 t-mono text-right text-gray-300 focus:outline-none focus:border-white/20 disabled:opacity-40"+ />+ )+}diff --git a/src/components/settings/SettingsPage.tsx b/src/components/settings/SettingsPage.tsxindex dc98a220..8e3cc215 100644--- a/src/components/settings/SettingsPage.tsx+++ b/src/components/settings/SettingsPage.tsx@@ -1,5 +1,4 @@import { useState, useEffect, useRef, type ReactNode, type ChangeEvent } from 'react'-import { compactThresholdFromPercent } from '../../lib/settings-catalog'import { withDetail } from '../../lib/error-text'// `X` steht hier weiterhin, obwohl der Sprachabschnitt mit seinen Symbolen// nach ./SpeechSettings.tsx gezogen ist: der Dismiss-Knopf der ComfyUI-Notiz@@ -11,6 +10,7 @@ import { runSettingsReset } from '../../lib/run-settings-reset'import { armedScopeFor, type ResetArm, type ResetArmScope } from '../../lib/reset-arming'import { sectionAnchorId, sectionsFor, type SettingsSectionFlags } from './settings-nav'import { ChatReplyTimeoutSettings } from './ChatReplyTimeoutSettings'+import { CompactThresholdInput } from './CompactThresholdInput'import { HowItWorks } from '../ui/HowItWorks'import { HOWTO } from '../../lib/howto'import { useSettingsStore } from '../../stores/settingsStore'@@ -2109,21 +2109,7 @@ export function SettingsPage() {title="When the conversation or a running tool chain fills this much of the window, the model writes a summary of the older part and that part stops being sent. 0 = fit the model's context window, from 32K up. The full history stays in the chat either way; only what is sent changes.">Compact at</span><div className="flex items-center gap-1">- <input- aria-label="Auto-compact at"- type="number"- value={Math.round((settings.autoCompactThreshold || 0) * 100)}- disabled={settings.autoCompact === false}- onChange={(e) => {- // Same rule as set_setting from the chat (lib/settings-catalog.ts).- updateSettings({ autoCompactThreshold: compactThresholdFromPercent(parseInt(e.target.value) || 0) })- }}- min={0}- max={95}- step={5}- placeholder="0"- className="w-20 px-1.5 py-0.5 rounded bg-transparent border border-white/8 t-mono text-right text-gray-300 focus:outline-none focus:border-white/20 disabled:opacity-40"- />+ <CompactThresholdInput /><span className="t-mono text-gray-500 w-3">%</span></div></div>diff --git a/src/components/settings/__tests__/compact-at-field.test.tsx b/src/components/settings/__tests__/compact-at-field.test.tsxnew file mode 100644index 00000000..215154b2--- /dev/null+++ b/src/components/settings/__tests__/compact-at-field.test.tsx@@ -0,0 +1,89 @@+/**+ * @vitest-environment jsdom+ *+ * Jaeger B, B1: Settings, General, Generation, "Compact at". Typing 50 saved+ * the 5 first, which the 0-or-30-95 rule turned into 0, and an arrow step+ * went 0, 5, 0. The field keeps a draft while typing and saves on blur or+ * Enter; a step jumps the gap between 0 and 30.+ *+ * Run: npx vitest run src/components/settings/__tests__/compact-at-field.test.tsx+ */+import { describe, it, expect, beforeEach, afterEach } from 'vitest'+import { createElement } from 'react'+import { render, screen, fireEvent, cleanup } from '@testing-library/react'+import { useSettingsStore } from '../../../stores/settingsStore'+import { DEFAULT_SETTINGS } from '../../../lib/constants'+import { stepCompactPercent } from '../../../lib/settings-catalog'++const { CompactThresholdInput } = await import('../CompactThresholdInput')++const field = () => screen.getByLabelText('Auto-compact at') as HTMLInputElement+const stored = () => useSettingsStore.getState().settings.autoCompactThreshold++/** What a keystroke does: set the value and send an InputEvent that says it was typed. */+function type(el: HTMLInputElement, value: string) {+ const setter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')!.set!+ setter.call(el, value)+ el.dispatchEvent(new InputEvent('input', { bubbles: true, inputType: 'insertText', data: value.slice(-1) }))+}++/** What a spin button does: the value moves by the step, with a plain input event. */+function spin(el: HTMLInputElement, value: string) {+ fireEvent.change(el, { target: { value } })+}++beforeEach(() => useSettingsStore.setState({ settings: { ...DEFAULT_SETTINGS, autoCompact: true, autoCompactThreshold: 0 } }))+afterEach(() => cleanup())++describe('Compact at', () => {+ it('typing 5 then 50 keeps the digits and saves 50 % on blur', () => {+ render(createElement(CompactThresholdInput))+ type(field(), '5')+ expect(field().value).toBe('5')+ type(field(), '50')+ expect(field().value).toBe('50')+ fireEvent.blur(field())+ expect(stored()).toBe(0.5)+ expect(field().value).toBe('50')+ })++ it('Enter saves what was typed; a value in the gap becomes 0', () => {+ render(createElement(CompactThresholdInput))+ type(field(), '80')+ fireEvent.keyDown(field(), { key: 'Enter' })+ expect(stored()).toBe(0.8)+ type(field(), '12')+ fireEvent.blur(field())+ expect(stored()).toBe(0)+ expect(field().value).toBe('0')+ })++ it('arrow up goes 0, 30, 35 and arrow down comes back to 0', () => {+ render(createElement(CompactThresholdInput))+ fireEvent.keyDown(field(), { key: 'ArrowUp' })+ expect(stored()).toBe(0.3)+ fireEvent.keyDown(field(), { key: 'ArrowUp' })+ expect(stored()).toBe(0.35)+ fireEvent.keyDown(field(), { key: 'ArrowDown' })+ fireEvent.keyDown(field(), { key: 'ArrowDown' })+ expect(stored()).toBe(0)+ expect(field().value).toBe('0')+ })++ it('the spin buttons jump the gap too', () => {+ render(createElement(CompactThresholdInput))+ spin(field(), '5')+ expect(stored()).toBe(0.3)+ expect(field().value).toBe('30')+ spin(field(), '25')+ expect(stored()).toBe(0)+ })++ it('stepCompactPercent stays inside 0 and 30 to 95', () => {+ expect(stepCompactPercent(0, 1)).toBe(30)+ expect(stepCompactPercent(95, 1)).toBe(95)+ expect(stepCompactPercent(30, -1)).toBe(0)+ expect(stepCompactPercent(0, -1)).toBe(0)+ expect(stepCompactPercent(50, -1)).toBe(45)+ })+})diff --git a/src/lib/settings-catalog.ts b/src/lib/settings-catalog.tsindex 4ab07aae..8f7f6d02 100644--- a/src/lib/settings-catalog.ts+++ b/src/lib/settings-catalog.ts@@ -123,6 +123,17 @@ export function compactThresholdFromPercent(pct: number): number {return p < 30 ? 0 : p / 100}+/**+ * One arrow step on the "Compact at" field, in percent. Only 0 and 30 to 95+ * are values, so a step skips the gap: up from 0 is 30, down from 30 is 0.+ * The plain step of 5 went 0 to 5, which the rule above turned back into 0.+ */+export function stepCompactPercent(pct: number, dir: 1 | -1): number {+ const p = Math.max(0, Math.min(95, Math.round(pct)))+ if (dir > 0) return p < 30 ? 30 : Math.min(95, p + 5)+ return p <= 30 ? 0 : p - 5+}+const compactThreshold: Pick<CatalogEntry, 'parse' | 'show' | 'allowed'> = {allowed: '0 (auto, fits the model) or 30–95 %',parse: (v) => {