Files
deer-flow/frontend/src/core/settings/local.ts

65 lines
1.5 KiB
TypeScript
Raw Normal View History

2026-01-16 09:55:02 +08:00
import type { AgentThreadContext } from "../threads";
export const DEFAULT_LOCAL_SETTINGS: LocalSettings = {
2026-01-31 11:08:27 +08:00
notification: {
enabled: true,
},
2026-01-16 09:55:02 +08:00
context: {
model_name: undefined,
mode: undefined,
2026-01-16 09:55:02 +08:00
},
2026-01-16 23:03:39 +08:00
layout: {
sidebar_collapsed: false,
},
2026-01-16 09:55:02 +08:00
};
const LOCAL_SETTINGS_KEY = "deerflow.local-settings";
export interface LocalSettings {
2026-01-31 11:08:27 +08:00
notification: {
enabled: boolean;
};
context: Omit<
AgentThreadContext,
"thread_id" | "is_plan_mode" | "thinking_enabled"
> & {
mode: "flash" | "thinking" | "pro" | undefined;
};
2026-01-16 23:03:39 +08:00
layout: {
sidebar_collapsed: boolean;
};
2026-01-16 09:55:02 +08:00
}
export function getLocalSettings(): LocalSettings {
if (typeof window === "undefined") {
return DEFAULT_LOCAL_SETTINGS;
}
const json = localStorage.getItem(LOCAL_SETTINGS_KEY);
try {
if (json) {
2026-01-16 23:03:39 +08:00
const settings = JSON.parse(json);
2026-01-22 00:26:11 +08:00
const mergedSettings = {
2026-01-16 23:03:39 +08:00
...DEFAULT_LOCAL_SETTINGS,
2026-01-22 00:26:11 +08:00
context: {
...DEFAULT_LOCAL_SETTINGS.context,
...settings.context,
},
layout: {
...DEFAULT_LOCAL_SETTINGS.layout,
...settings.layout,
},
2026-01-31 11:08:27 +08:00
notification: {
...DEFAULT_LOCAL_SETTINGS.notification,
...settings.notification,
},
2026-01-16 23:03:39 +08:00
};
2026-01-22 00:26:11 +08:00
return mergedSettings;
2026-01-16 09:55:02 +08:00
}
} catch {}
return DEFAULT_LOCAL_SETTINGS;
}
export function saveLocalSettings(settings: LocalSettings) {
localStorage.setItem(LOCAL_SETTINGS_KEY, JSON.stringify(settings));
}