ui: Settings navigation cleanup (#27241)
* ui : rework the settings registry into ordered raw-data sections SETTINGS_REGISTRY becomes an ordered SettingsSectionEntry[] array; the array order is the sidebar display order. Section titles, color mode options and title radio options are declared inline in their section or entry. Entries gain showInUi; MCP servers, the system-message toggle and the title LLM flag become hidden entries of their own section. Derived values (config defaults, help info, chat sections, numeric field lists, syncable parameters) are still derived here; they move to their actual consumers in follow-up commits. * ui : extract settings localStorage persistence into SettingsService Stateless load/save of the settings config and user-override keys, plus the legacy theme key migration. Business logic (default merging, mobile sendOnEnter default, applying the migrated theme) stays in the store. * ui : move the settings exit route into ROUTES SETTINGS_FALLBACK_EXIT_ROUTE is just a route, so it lives with the other routes as ROUTES.SETTINGS_EXIT. * ui : derive the syncable parameter list in the parameter sync service The syncable parameter mapping is only consumed by the sync service, so derive it there from the registry instead of exporting it from the constants file. * ui : restore isPrivate for API key masking * ui : clean up settings registry and router fetch guard Drop the per-entry section field (duplicates the parent slug and is never read) and guard the router model fetch on fields?.length so the Tools/Import-Export pages with empty fields are excluded again. Assisted-by: pi * ui : merge sampling and penalties settings into one section Assisted-by: pi
This commit is contained in:
@@ -340,3 +340,13 @@ export { RouterService } from './router.service';
|
||||
* @see migration.service.ts — full implementation (non-destructive)
|
||||
*/
|
||||
export { MigrationService } from './migration.service';
|
||||
|
||||
/**
|
||||
* **SettingsService** - localStorage persistence layer for settings
|
||||
*
|
||||
* Stateless read/write of the settings config and user-override keys. Business
|
||||
* logic (default merging, mobile defaults, theme migration) stays in the store.
|
||||
*
|
||||
* @see settingsStore in stores/settings/index.svelte.ts - reactive state + business logic
|
||||
*/
|
||||
export { SettingsService } from './settings.service';
|
||||
|
||||
@@ -6,11 +6,23 @@
|
||||
* No reactive state; consumed by settingsStore.
|
||||
*/
|
||||
|
||||
import { SETTINGS_KEYS, SYNCABLE_PARAMETERS } from '$lib/constants';
|
||||
import { SETTINGS_KEYS, SETTINGS_REGISTRY } from '$lib/constants';
|
||||
import { ParameterSource, SyncableParameterType } from '$lib/enums';
|
||||
import type { ParameterInfo, ParameterRecord, ParameterValue } from '$lib/types';
|
||||
import type { ParameterInfo, ParameterRecord, ParameterValue, SyncableParameter } from '$lib/types';
|
||||
import { normalizeFloatingPoint } from '$lib/utils';
|
||||
|
||||
/** Mapping of UI setting keys to server parameter keys, derived from the registry. */
|
||||
export const SYNCABLE_PARAMETERS: SyncableParameter[] = SETTINGS_REGISTRY.flatMap(
|
||||
(section) => section.settings
|
||||
)
|
||||
.filter((s) => s.sync !== undefined)
|
||||
.map((s) => ({
|
||||
canSync: true,
|
||||
key: s.key,
|
||||
serverKey: s.sync!.serverKey,
|
||||
type: s.sync!.paramType
|
||||
}));
|
||||
|
||||
export class ParameterSyncService {
|
||||
/**
|
||||
* Check if a parameter can be synced from server.
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
import { browser } from '$app/environment';
|
||||
import { CONFIG_LOCALSTORAGE_KEY, USER_OVERRIDES_LOCALSTORAGE_KEY } from '$lib/constants';
|
||||
|
||||
/**
|
||||
* SettingsService - localStorage persistence layer for settings
|
||||
*
|
||||
* Stateless read/write of the settings config and user-override keys. Business
|
||||
* logic (default merging, mobile defaults, theme migration) stays in the store.
|
||||
*
|
||||
* **Architecture & Relationships:**
|
||||
* - **settingsStore**: Primary consumer - loads config on init and persists on change
|
||||
*
|
||||
* @see settingsStore in stores/settings/index.svelte.ts - reactive state + business logic
|
||||
*/
|
||||
export class SettingsService {
|
||||
/**
|
||||
* Read the raw config and user overrides from localStorage.
|
||||
* @returns Parsed values, or empty defaults when nothing is stored or parsing fails.
|
||||
*/
|
||||
static loadConfig(): {
|
||||
config: Record<string, unknown>;
|
||||
userOverrides: string[];
|
||||
isFirstVisit: boolean;
|
||||
} {
|
||||
if (!browser) {
|
||||
return { config: {}, isFirstVisit: false, userOverrides: [] };
|
||||
}
|
||||
|
||||
try {
|
||||
const storedConfigRaw = localStorage.getItem(CONFIG_LOCALSTORAGE_KEY);
|
||||
const isFirstVisit = storedConfigRaw === null;
|
||||
const config = JSON.parse(storedConfigRaw || '{}') as Record<string, unknown>;
|
||||
const userOverrides = JSON.parse(
|
||||
localStorage.getItem(USER_OVERRIDES_LOCALSTORAGE_KEY) || '[]'
|
||||
) as string[];
|
||||
|
||||
return { config, isFirstVisit, userOverrides };
|
||||
} catch (error) {
|
||||
console.warn('Failed to parse config from localStorage, using defaults:', error);
|
||||
|
||||
return { config: {}, isFirstVisit: false, userOverrides: [] };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrate the legacy un-namespaced "theme" localStorage key.
|
||||
* Returns the legacy theme value (and removes the key) when present, else null.
|
||||
*/
|
||||
static migrateLegacyTheme(): string | null {
|
||||
if (!browser) return null;
|
||||
|
||||
const legacyTheme = localStorage.getItem('theme');
|
||||
|
||||
if (legacyTheme) {
|
||||
localStorage.removeItem('theme');
|
||||
|
||||
return legacyTheme;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Persist the config and user overrides to localStorage.
|
||||
*/
|
||||
static saveConfig(config: Record<string, unknown>, userOverrides: string[]): void {
|
||||
if (!browser) return;
|
||||
|
||||
try {
|
||||
localStorage.setItem(CONFIG_LOCALSTORAGE_KEY, JSON.stringify(config));
|
||||
localStorage.setItem(USER_OVERRIDES_LOCALSTORAGE_KEY, JSON.stringify(userOverrides));
|
||||
} catch (error) {
|
||||
console.error('Failed to save config to localStorage:', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user