feat(web): add global settings and simplify sidebar
This commit is contained in:
@@ -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; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user