feat(web): add global settings and simplify sidebar

This commit is contained in:
2026-11-12 15:25:12 -08:00
parent b7fdf7a89c
commit d88018fd64
13 changed files with 853 additions and 242 deletions
+21 -2
View File
@@ -50,8 +50,10 @@ export const BASE_PROVIDERS: Provider[] = ["openai", "anthropic", "xai", "gemini
export const ALL_PROVIDERS: Provider[] = [...BASE_PROVIDERS, "hermes-agent"];
export const MODEL_PREFERENCES_STORAGE_KEY = "sybil:modelPreferencesByProvider";
export const QUICK_QUESTION_MODEL_SELECTION_STORAGE_KEY = "sybil:quickQuestionModelSelection";
export type ProviderModelPreferences = Record<Provider, string | null>;
export type QuickQuestionModelSelection = { provider: Provider; modelPreferences: ProviderModelPreferences };
export const EMPTY_MODEL_PREFERENCES: ProviderModelPreferences = {
openai: null,
@@ -155,6 +157,23 @@ export function buildCompletionMessages(messages: Message[], content: string, at
}
export function saveModelPreferences(preferences: ProviderModelPreferences) {
try { window.localStorage.setItem(MODEL_PREFERENCES_STORAGE_KEY, JSON.stringify(preferences)); }
catch { /* Browsers with unavailable storage can still use this session. */ }
try { window.localStorage.setItem(MODEL_PREFERENCES_STORAGE_KEY, JSON.stringify(preferences)); return true; }
catch { return false; /* Browsers with unavailable storage can still use this session. */ }
}
export function loadStoredQuickQuestionModelSelection(): QuickQuestionModelSelection {
const fallback = { provider: "openai" as const, modelPreferences: EMPTY_MODEL_PREFERENCES };
if (typeof window === "undefined") return fallback;
try {
const raw = window.localStorage.getItem(QUICK_QUESTION_MODEL_SELECTION_STORAGE_KEY);
if (!raw) return fallback;
const parsed = JSON.parse(raw);
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return fallback;
return { provider: normalizeStoredProvider(parsed.provider), modelPreferences: normalizeStoredModelPreferences(parsed.modelPreferences) };
} catch { return fallback; }
}
export function saveQuickQuestionModelSelection(selection: QuickQuestionModelSelection) {
try { window.localStorage.setItem(QUICK_QUESTION_MODEL_SELECTION_STORAGE_KEY, JSON.stringify(selection)); return true; }
catch { return false; }
}