// Client-held storage for the user's own public-provider API key (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 key, // 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"). A fuller Paperclip-style key-management UI (multiple // providers, masking, rotation) is good follow-up work, not built tonight. const KEY_PREFIX = 'vncmail:ai:key:'; export function getAiApiKey(provider: 'public'): string | null { if (typeof window === 'undefined') return null; return window.localStorage.getItem(KEY_PREFIX + provider); } export function setAiApiKey(provider: 'public', key: string): void { if (typeof window === 'undefined') return; window.localStorage.setItem(KEY_PREFIX + provider, key); } export function clearAiApiKey(provider: 'public'): void { if (typeof window === 'undefined') return; window.localStorage.removeItem(KEY_PREFIX + provider); }