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(models): Runde 2 Nachbesserung 5 - Standby-Karte warnt vor Schluesselverlust

purple3f58dacbd3b6
diff --git a/src/components/settings/ProviderConfig.tsx b/src/components/settings/ProviderConfig.tsx
index bee6d256..8796bb81 100644
--- a/src/components/settings/ProviderConfig.tsx
+++ b/src/components/settings/ProviderConfig.tsx
@@ -120,6 +120,9 @@ export function ProviderSettings() {
const [showKey, setShowKey] = useState<Record<string, boolean>>({})
const [showCloudWarning, setShowCloudWarning] = useState(false)
const [pendingPreset, setPendingPreset] = useState<typeof PROVIDER_PRESETS[0] | null>(null)
+ // Review-Runde 2, Punkt 5: a takeover the OS keychain cannot durably park.
+ // See wouldLoseApiKeyOnRestart below for why this exists.
+ const [showKeyLossWarning, setShowKeyLossWarning] = useState(false)
const [expandedProvider, setExpandedProvider] = useState<ProviderId | null>(null)
@@ -292,6 +295,21 @@ export function ProviderSettings() {
setExpandedProvider('openai')
}
+ // Review-Runde 2, Punkt 5: whether accepting `preset` into the shared
+ // `openai` slot would destroy a currently-set, non-empty API key with no
+ // way to bring it back. The displaced key only survives in
+ // `displaced.apiKey` for the running session (F3 Nachbesserung 6); a
+ // restart between takeover and handback still loses it, because the OS
+ // keychain layer (src-tauri/src/commands/secret.rs) only accepts a fixed,
+ // exact-match set of account names and refuses a synthetic per-backend
+ // "parked key" entry by design. Told up front, so the loss is a choice
+ // made with eyes open instead of a 401 the next time the backend returns.
+ function wouldLoseApiKeyOnRestart(preset: typeof PROVIDER_PRESETS[0]): boolean {
+ if (preset.providerId === 'ollama' || preset.providerId === 'anthropic') return false
+ const incoming = { name: preset.name, baseUrl: preset.baseUrl, isLocal: preset.isLocal, managed: preset.managed }
+ return takeoverClearsApiKey(providers.openai, incoming) && getProviderApiKey('openai') !== ''
+ }
+
// Add a preset (enable a provider without disabling others)
function selectPreset(preset: typeof PROVIDER_PRESETS[0]) {
if (!preset.isLocal) {
@@ -299,6 +317,11 @@ export function ProviderSettings() {
setShowCloudWarning(true)
return
}
+ if (wouldLoseApiKeyOnRestart(preset)) {
+ setPendingPreset(preset)
+ setShowKeyLossWarning(true)
+ return
+ }
applyPreset(preset)
}
@@ -826,8 +849,12 @@ export function ProviderSettings() {
</button>
<button
onClick={() => {
- if (pendingPreset) applyPreset(pendingPreset)
setShowCloudWarning(false)
+ if (pendingPreset && wouldLoseApiKeyOnRestart(pendingPreset)) {
+ setShowKeyLossWarning(true)
+ return
+ }
+ if (pendingPreset) applyPreset(pendingPreset)
setPendingPreset(null)
}}
className="px-4 py-1.5 rounded-lg text-[0.7rem] font-medium bg-white/5 border border-white/10 text-gray-300 hover:bg-white/10 transition-colors"
@@ -837,6 +864,37 @@ export function ProviderSettings() {
</div>
</div>
</Modal>
+
+ {/* Review-Runde 2, Punkt 5: standby key not surviving a restart */}
+ <Modal open={showKeyLossWarning} onClose={() => { setShowKeyLossWarning(false); setPendingPreset(null) }} title="">
+ <div className="space-y-4 text-center" data-testid="key-loss-warning-modal">
+ <h3 className="text-base font-semibold text-white">API Key Will Be Lost</h3>
+ <p className="text-[12px] text-gray-400 leading-relaxed">
+ The current OpenAI-compatible backend has an API key set. Switching backends clears it from this slot, and it will NOT survive an app restart while parked.
+ </p>
+ <p className="text-[12px] text-gray-400 leading-relaxed">
+ If you switch back to this backend later, you will need to enter the key again.
+ </p>
+ <div className="flex items-center justify-center gap-3 pt-2">
+ <button
+ onClick={() => { setShowKeyLossWarning(false); setPendingPreset(null) }}
+ className="px-4 py-1.5 rounded-lg text-[0.7rem] text-gray-400 hover:text-white hover:bg-white/10 transition-colors"
+ >
+ Cancel
+ </button>
+ <button
+ onClick={() => {
+ if (pendingPreset) applyPreset(pendingPreset)
+ setShowKeyLossWarning(false)
+ setPendingPreset(null)
+ }}
+ className="px-4 py-1.5 rounded-lg text-[0.7rem] font-medium bg-white/5 border border-white/10 text-gray-300 hover:bg-white/10 transition-colors"
+ >
+ Switch Anyway
+ </button>
+ </div>
+ </div>
+ </Modal>
</div>
)
}
diff --git a/src/lib/__tests__/builtin-card-survives-add-provider.test.ts b/src/lib/__tests__/builtin-card-survives-add-provider.test.ts
index 3e323dd6..6a7d2aaa 100644
--- a/src/lib/__tests__/builtin-card-survives-add-provider.test.ts
+++ b/src/lib/__tests__/builtin-card-survives-add-provider.test.ts
@@ -281,4 +281,52 @@ describe('the wiring, so the rule reaches the screen', () => {
const body = pane.slice(start, end)
expect(body).toMatch(/setProviderApiKey\('openai', parkedObfuscated !== undefined \? deobfuscate\(parkedObfuscated\) : ''\)/)
})
+
+ // Review-Runde 2, Punkt 5: displaced.apiKey only survives in memory for the
+ // running session (Nachbesserung 6). The OS keychain layer
+ // (src-tauri/src/commands/secret.rs) enforces a fixed, exact-match account
+ // allowlist and refuses a synthetic "parked key" entry, so a restart
+ // between takeover and handback still loses the displaced key. Since a
+ // durable per-backend keychain entry needs a Rust change out of scope
+ // here, the takeover instead warns before it happens.
+ it('a takeover that would clear a non-empty key is guarded before it runs', () => {
+ const start = pane.indexOf('function wouldLoseApiKeyOnRestart(')
+ const end = pane.indexOf('\n }', start)
+ const body = pane.slice(start, end)
+ expect(body).toMatch(/takeoverClearsApiKey\(providers\.openai, incoming\)/)
+ expect(body).toMatch(/getProviderApiKey\('openai'\) !== ''/)
+ })
+
+ it('selectPreset asks before a local preset takeover that would lose the key', () => {
+ const start = pane.indexOf('function selectPreset(')
+ const end = pane.indexOf('\n }', start)
+ const body = pane.slice(start, end)
+ expect(body).toMatch(/if \(wouldLoseApiKeyOnRestart\(preset\)\)/)
+ expect(body).toMatch(/setShowKeyLossWarning\(true\)/)
+ })
+
+ it('the cloud warning Continue button checks key loss before applying too', () => {
+ const cloudModalStart = pane.indexOf('{/* Cloud privacy warning popup */}')
+ const keyLossModalStart = pane.indexOf('{/* Review-Runde 2, Punkt 5')
+ expect(cloudModalStart).toBeGreaterThan(-1)
+ expect(keyLossModalStart).toBeGreaterThan(cloudModalStart)
+ const between = pane.slice(cloudModalStart, keyLossModalStart)
+ expect(between).toMatch(/if \(pendingPreset && wouldLoseApiKeyOnRestart\(pendingPreset\)\)/)
+ expect(between).toMatch(/setShowKeyLossWarning\(true\)/)
+ })
+
+ it('the key loss card is visible and in English, and asks for confirmation', () => {
+ const keyLossModalStart = pane.indexOf('{/* Review-Runde 2, Punkt 5')
+ const end = pane.indexOf('</Modal>', keyLossModalStart)
+ const body = pane.slice(keyLossModalStart, end)
+ expect(body).toMatch(/API Key Will Be Lost/)
+ expect(body).toMatch(/will NOT survive an app restart/)
+ expect(body).toMatch(/Switch Anyway/)
+ })
+
+ it('NEGATIVE CONTROL: no em dash in the key loss warning copy', () => {
+ const keyLossModalStart = pane.indexOf('{/* Review-Runde 2, Punkt 5')
+ const end = pane.indexOf('</Modal>', keyLossModalStart)
+ expect(pane.slice(keyLossModalStart, end)).not.toMatch(/[\u2013\u2014]/)
+ })
})