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.

fix(settings): reset all also restores the AI Backends

purpleda8bd452f36b
diff --git a/src/components/settings/SettingsPage.tsx b/src/components/settings/SettingsPage.tsx
index 7aa5a683..dc98a220 100644
--- a/src/components/settings/SettingsPage.tsx
+++ b/src/components/settings/SettingsPage.tsx
@@ -6,14 +6,14 @@ import { withDetail } from '../../lib/error-text'
// traegt ihn neben dem Wort.
import { ArrowLeft, RotateCcw, Sun, Moon, Check, X, Loader2, Shield, ChevronRight, GraduationCap, Lock, Sliders, Plug, Bot, Phone, User, Download, AlertTriangle } from 'lucide-react'
import { motion, AnimatePresence } from 'framer-motion'
-import { SETTINGS_TAB_RESET_KEYS, type SettingsTab } from '../../lib/settings-reset'
+import { type SettingsTab } from '../../lib/settings-reset'
+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 { HowItWorks } from '../ui/HowItWorks'
import { HOWTO } from '../../lib/howto'
import { useSettingsStore } from '../../stores/settingsStore'
-import { usePermissionStore } from '../../stores/permissionStore'
import { useUIStore } from '../../stores/uiStore'
import { SliderControl } from './SliderControl'
import { THINK_BUDGET_STEP, normalizeThinkBudget } from '../../lib/think-budget'
@@ -23,7 +23,6 @@ import { SpeechSettings } from './SpeechSettings'
import { LogFileSettings } from './LogFileSettings'
import { PersonaPanel } from '../personas/PersonaPanel'
import { AccountPanel } from '../auth/AccountPanel'
-import { useVoiceStore } from '../../stores/voiceStore'
import { downloadSuffix } from '../../lib/formatters'
// Der Satz zum Startfehler kommt fuer beide Oberflaechen aus dieser Stelle
// (Ticket 007). Statisch geladen, weil ihn der Beobachter unten in dem
@@ -1621,10 +1620,6 @@ const SETTINGS_TABS: { id: SettingsTab; label: string; icon: ReactNode }[] = [
// visible signals are pinned by
// src/lib/__tests__/reset-arming-is-visible.test.ts.
function ResetSection({ tab }: { tab: SettingsTab }) {
- const resetSettingsKeys = useSettingsStore((s) => s.resetSettingsKeys)
- const resetSettings = useSettingsStore((s) => s.resetSettings)
- const resetVoiceDefaults = useVoiceStore((s) => s.resetVoiceDefaults)
- const resetPermissions = usePermissionStore((s) => s.resetToDefaults)
// The arm records the tab it was made on, so "still armed?" is a question
// that can be answered while rendering. Switching tabs while armed must
// disarm, otherwise a click armed on General would confirm-fire on Agent,
@@ -1654,22 +1649,8 @@ function ResetSection({ tab }: { tab: SettingsTab }) {
}
if (armTimer.current) window.clearTimeout(armTimer.current)
setArmed(null)
- if (which === 'all') {
- resetSettings()
- resetVoiceDefaults()
- resetPermissions()
- setDone('All settings restored to defaults')
- } else {
- resetSettingsKeys(SETTINGS_TAB_RESET_KEYS[tab])
- if (tab === 'agent') resetPermissions()
- if (tab === 'voice-remote') resetVoiceDefaults()
- // G20: "Reset AI Backends" only reset settings KEYS and never touched
- // the provider store, so it could not hand the openai slot back to the
- // Built-in Engine once LM Studio had adopted it. Now it restores the
- // shipped slots too (API keys and the cloud account flag are kept).
- if (tab === 'backends') useProviderStore.getState().resetProvidersToDefaults()
- setDone(`${tabLabel} settings restored to defaults`)
- }
+ runSettingsReset(which, tab)
+ setDone(which === 'all' ? 'All settings restored to defaults' : `${tabLabel} settings restored to defaults`)
if (doneTimer.current) window.clearTimeout(doneTimer.current)
doneTimer.current = window.setTimeout(() => setDone(null), 3000)
}
diff --git a/src/lib/__tests__/g20-builtin-return-path.test.ts b/src/lib/__tests__/g20-builtin-return-path.test.ts
index ea00780b..cc129152 100644
--- a/src/lib/__tests__/g20-builtin-return-path.test.ts
+++ b/src/lib/__tests__/g20-builtin-return-path.test.ts
@@ -53,8 +53,10 @@ describe('resetProvidersToDefaults hands the slot back to the Built-in Engine',
describe('wiring and the second G20 leftover', () => {
it('the backends tab reset actually calls the store reset', () => {
+ // The two reset buttons live in lib/run-settings-reset.ts since B2.
const page = read('../../components/settings/SettingsPage.tsx')
- expect(page).toContain("if (tab === 'backends') useProviderStore.getState().resetProvidersToDefaults()")
+ expect(page).toContain('runSettingsReset(which, tab)')
+ expect(read('../run-settings-reset.ts')).toContain("if (tab === 'backends') useProviderStore.getState().resetProvidersToDefaults()")
})
it('the Add Provider path to the Built-in Engine exists as a preset', () => {
diff --git a/src/lib/__tests__/reset-all-covers-every-section.test.ts b/src/lib/__tests__/reset-all-covers-every-section.test.ts
new file mode 100644
index 00000000..7c7ffbe3
--- /dev/null
+++ b/src/lib/__tests__/reset-all-covers-every-section.test.ts
@@ -0,0 +1,75 @@
+/**
+ * Jaeger B, B2: "Reset all settings" left the AI Backends as they were,
+ * while "Reset AI Backends to defaults" restored them. "Everything" has to
+ * cover at least what every section reset covers, and still keep content.
+ *
+ * Run: npx vitest run src/lib/__tests__/reset-all-covers-every-section.test.ts
+ */
+import { describe, it, expect, beforeEach } from 'vitest'
+import { useSettingsStore } from '../../stores/settingsStore'
+import { useProviderStore } from '../../stores/providerStore'
+import { usePermissionStore } from '../../stores/permissionStore'
+import { useVoiceStore } from '../../stores/voiceStore'
+import { useMCPStore } from '../../stores/mcpStore'
+import { DEFAULT_SETTINGS } from '../constants'
+
+const { runSettingsReset } = await import('../run-settings-reset')
+
+const ollama = () => useProviderStore.getState().providers.ollama
+
+beforeEach(() => {
+ useSettingsStore.setState({ settings: { ...DEFAULT_SETTINGS } })
+ useProviderStore.getState().resetProvidersToDefaults()
+ usePermissionStore.getState().resetToDefaults()
+ useVoiceStore.getState().resetVoiceDefaults()
+})
+
+/** A state that differs from the shipped one in every store a reset owns. */
+function dirty() {
+ useSettingsStore.getState().updateSettings({ temperature: 1.9, agentMaxToolCalls: 3, remotePageTitle: 'mine' })
+ useProviderStore.getState().setProviderConfig('ollama', { baseUrl: 'http://127.0.0.1:18903' })
+ usePermissionStore.getState().setToolOverride('shell_execute', 'blocked')
+ useVoiceStore.setState({ ttsRate: 1.7 })
+}
+
+/** What each store looks like, for comparing one reset with the other. */
+const snapshot = () => JSON.stringify({
+ settings: useSettingsStore.getState().settings,
+ providers: useProviderStore.getState().providers,
+ permissions: usePermissionStore.getState().perToolOverrides,
+ voice: useVoiceStore.getState().ttsRate,
+})
+
+describe('Reset all settings', () => {
+ it('restores the AI Backends like the backends section reset does', () => {
+ dirty()
+ runSettingsReset('section', 'backends')
+ const afterSection = ollama().baseUrl
+
+ dirty()
+ runSettingsReset('all', 'general')
+ expect(ollama().baseUrl).toBe(afterSection)
+ expect(ollama().baseUrl).toBe('http://localhost:11434')
+ expect(useSettingsStore.getState().settings.temperature).toBe(DEFAULT_SETTINGS.temperature)
+ })
+
+ it('restores at least what every section reset restores, from any tab', () => {
+ const tabs = ['general', 'backends', 'agent', 'voice-remote'] as const
+ dirty()
+ for (const t of tabs) runSettingsReset('section', t)
+ const allSections = snapshot()
+ for (const pressedOn of tabs) {
+ dirty()
+ runSettingsReset('all', pressedOn)
+ expect(snapshot(), `Reset all on ${pressedOn}`).toBe(allSections)
+ }
+ })
+
+ it('keeps content: personas and MCP servers', () => {
+ useSettingsStore.setState({ personas: [{ id: 'p1', name: 'Mine', icon: 'x', systemPrompt: 's', isCustom: true }] } as never)
+ useMCPStore.setState({ servers: [{ id: 'm1', name: 'fs', command: 'npx', args: [], enabled: true }] })
+ runSettingsReset('all', 'agent')
+ expect(useSettingsStore.getState().personas.map((p) => p.id)).toContain('p1')
+ expect(useMCPStore.getState().servers.map((s) => s.id)).toEqual(['m1'])
+ })
+})
diff --git a/src/lib/__tests__/reset-arming-is-visible.test.ts b/src/lib/__tests__/reset-arming-is-visible.test.ts
index df40c5b5..2f9b2704 100644
--- a/src/lib/__tests__/reset-arming-is-visible.test.ts
+++ b/src/lib/__tests__/reset-arming-is-visible.test.ts
@@ -129,15 +129,16 @@ describe('the same mechanic the Cloud switch uses, on purpose', () => {
})
it('NEGATIVE CONTROL: the reset still needs the SECOND click to fire', () => {
- // resetSettingsKeys must sit AFTER the arm-and-return guard, never before.
+ // The reset must sit AFTER the arm-and-return guard, never before. Since
+ // B2 both buttons fire through lib/run-settings-reset.ts.
const guard = settingsPage.indexOf('if (armed !== which)')
- const fires = settingsPage.indexOf('resetSettingsKeys(SETTINGS_TAB_RESET_KEYS[tab])')
+ const fires = settingsPage.indexOf('runSettingsReset(which, tab)')
expect(guard).toBeGreaterThan(-1)
expect(fires).toBeGreaterThan(guard)
})
it('NEGATIVE CONTROL: the backends reset still hands the slot back to the engine', () => {
- expect(settingsPage).toContain(
+ expect(read('src/lib/run-settings-reset.ts')).toContain(
"if (tab === 'backends') useProviderStore.getState().resetProvidersToDefaults()",
)
})
diff --git a/src/lib/run-settings-reset.ts b/src/lib/run-settings-reset.ts
new file mode 100644
index 00000000..1603c8ec
--- /dev/null
+++ b/src/lib/run-settings-reset.ts
@@ -0,0 +1,39 @@
+import { SETTINGS_TAB_RESET_KEYS, type SettingsTab } from './settings-reset'
+import { useSettingsStore } from '../stores/settingsStore'
+import { useVoiceStore } from '../stores/voiceStore'
+import { usePermissionStore } from '../stores/permissionStore'
+import { useProviderStore } from '../stores/providerStore'
+
+/**
+ * What the two reset buttons at the foot of every Settings tab do (GitHub
+ * #59). One place for both, because they drifted: "Reset all settings" reset
+ * the settings, the voice and the permissions, but not the AI Backends, while
+ * "Reset AI Backends to defaults" did (Jaeger B, B2). The bigger button did
+ * less than the smaller one, and a broken backend state stayed broken after
+ * "everything" was reset.
+ *
+ * "all" is every tab's section reset at once, so anything a section reset
+ * adds below is covered by "all" without a second line to remember. Content
+ * is kept either way (personas, memories, conversations, workflows, MCP
+ * servers), and the provider reset keeps API keys and the cloud account flag.
+ */
+export function runSettingsReset(scope: 'section' | 'all', tab: SettingsTab): void {
+ if (scope === 'all') {
+ useSettingsStore.getState().resetSettings()
+ for (const t of Object.keys(SETTINGS_TAB_RESET_KEYS) as SettingsTab[]) resetSectionStores(t)
+ return
+ }
+ useSettingsStore.getState().resetSettingsKeys(SETTINGS_TAB_RESET_KEYS[tab])
+ resetSectionStores(tab)
+}
+
+/** The stores outside settingsStore that a tab's reset also restores. */
+function resetSectionStores(tab: SettingsTab): void {
+ if (tab === 'agent') usePermissionStore.getState().resetToDefaults()
+ if (tab === 'voice-remote') useVoiceStore.getState().resetVoiceDefaults()
+ // G20: "Reset AI Backends" only reset settings KEYS and never touched
+ // the provider store, so it could not hand the openai slot back to the
+ // Built-in Engine once LM Studio had adopted it. Now it restores the
+ // shipped slots too (API keys and the cloud account flag are kept).
+ if (tab === 'backends') useProviderStore.getState().resetProvidersToDefaults()
+}