// Client-held storage for the user's own public-provider API keys (BYOK). // // Decision 2026-08-05 (reverses docs/AI-ASSISTANT-CONCEPT.md decision #1's // server-side-custody design): the user brings and holds their own keys, // client-side, not VNC. This is the same custody model as // vncmail-native's lib/ai-key-store.ts (expo-secure-store there; this repo // has no OS keychain access from a browser tab, so localStorage is the // honest equivalent here — plain, not hidden behind a false sense of // "secure storage"). // // Decision 2026-08-05 (later same night): several keys, not one — a user may // hold multiple named provider profiles (different models, different // providers) and pick which one answers a given question. Keys are stored // separately from `lib/ai/local-settings.ts`'s profile metadata (name, base // URL, model) so a profile can be exported/shared without its secret, and so // clearing one key can't accidentally corrupt the profile list. const KEY_PREFIX = 'vncmail:ai:key:'; export function getAiApiKey(profileId: string): string | null { if (typeof window === 'undefined') return null; return window.localStorage.getItem(KEY_PREFIX + profileId); } export function setAiApiKey(profileId: string, key: string): void { if (typeof window === 'undefined') return; window.localStorage.setItem(KEY_PREFIX + profileId, key); } export function clearAiApiKey(profileId: string): void { if (typeof window === 'undefined') return; window.localStorage.removeItem(KEY_PREFIX + profileId); }