// Small, isolated persistence for AI Assistant settings — deliberately NOT // folded into stores/settings-store.ts tonight. That store's export/import // feature enumerates every field by hand; this is prototype-scope UI state // (docs/AI-ASSISTANT-CONCEPT.md §12's P0/P5), and migrating it into the // shared store belongs with whichever phase makes these settings real // product config rather than a local-AI test harness. export type AiProvider = 'local' | 'public'; export interface AiLocalSettings { provider: AiProvider | null; localBaseUrl: string; localModel: string | null; publicBaseUrl: string; publicModel: string; publicConsentAccepted: boolean; } const STORAGE_KEY = 'vncmail:ai:settings'; export const DEFAULT_AI_SETTINGS: AiLocalSettings = { provider: null, localBaseUrl: 'http://127.0.0.1:11434', localModel: null, publicBaseUrl: 'https://openrouter.ai/api/v1', publicModel: '', publicConsentAccepted: false, }; export function loadAiSettings(): AiLocalSettings { if (typeof window === 'undefined') return { ...DEFAULT_AI_SETTINGS }; try { const raw = window.localStorage.getItem(STORAGE_KEY); if (!raw) return { ...DEFAULT_AI_SETTINGS }; return { ...DEFAULT_AI_SETTINGS, ...JSON.parse(raw) }; } catch { return { ...DEFAULT_AI_SETTINGS }; } } export function saveAiSettings(settings: AiLocalSettings): void { if (typeof window === 'undefined') return; window.localStorage.setItem(STORAGE_KEY, JSON.stringify(settings)); }