mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-19 12:24:46 +08:00
feat: store the local settings
This commit is contained in:
@@ -17,11 +17,8 @@ import {
|
|||||||
WorkspaceFooter,
|
WorkspaceFooter,
|
||||||
} from "@/components/workspace/workspace-container";
|
} from "@/components/workspace/workspace-container";
|
||||||
import { getLangGraphClient } from "@/core/api";
|
import { getLangGraphClient } from "@/core/api";
|
||||||
import type {
|
import { useLocalSettings } from "@/core/settings";
|
||||||
AgentThread,
|
import type { AgentThread, AgentThreadState } from "@/core/threads";
|
||||||
AgentThreadContext,
|
|
||||||
AgentThreadState,
|
|
||||||
} from "@/core/threads";
|
|
||||||
import { titleOfThread } from "@/core/threads/utils";
|
import { titleOfThread } from "@/core/threads/utils";
|
||||||
import { uuid } from "@/core/utils/uuid";
|
import { uuid } from "@/core/utils/uuid";
|
||||||
|
|
||||||
@@ -36,11 +33,8 @@ export default function ChatPage() {
|
|||||||
[threadIdFromPath],
|
[threadIdFromPath],
|
||||||
);
|
);
|
||||||
const [threadId, setThreadId] = useState<string | null>(null);
|
const [threadId, setThreadId] = useState<string | null>(null);
|
||||||
const [threadContext, setThreadContext] = useState<AgentThreadContext>({
|
const { threadContext, setThreadContext } = useLocalSettings();
|
||||||
thread_id: "",
|
|
||||||
model: "deepseek-v3.2",
|
|
||||||
thinking_enabled: true,
|
|
||||||
});
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (threadIdFromPath !== "new") {
|
if (threadIdFromPath !== "new") {
|
||||||
setThreadId(threadIdFromPath);
|
setThreadId(threadIdFromPath);
|
||||||
|
|||||||
@@ -49,8 +49,8 @@ export function InputBox({
|
|||||||
}: Omit<ComponentProps<typeof PromptInput>, "onSubmit"> & {
|
}: Omit<ComponentProps<typeof PromptInput>, "onSubmit"> & {
|
||||||
assistantId?: string | null;
|
assistantId?: string | null;
|
||||||
status?: ChatStatus;
|
status?: ChatStatus;
|
||||||
context: AgentThreadContext;
|
context: Omit<AgentThreadContext, "thread_id">;
|
||||||
onContextChange?: (context: AgentThreadContext) => void;
|
onContextChange?: (context: Omit<AgentThreadContext, "thread_id">) => void;
|
||||||
onSubmit?: (message: PromptInputMessage) => void;
|
onSubmit?: (message: PromptInputMessage) => void;
|
||||||
onStop?: () => void;
|
onStop?: () => void;
|
||||||
}) {
|
}) {
|
||||||
|
|||||||
34
frontend/src/core/settings/hooks.ts
Normal file
34
frontend/src/core/settings/hooks.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import { useCallback, useState } from "react";
|
||||||
|
import { useEffect } from "react";
|
||||||
|
|
||||||
|
import type { AgentThreadContext } from "../threads";
|
||||||
|
|
||||||
|
import {
|
||||||
|
DEFAULT_LOCAL_SETTINGS,
|
||||||
|
getLocalSettings,
|
||||||
|
updateContextOfLocalSettings,
|
||||||
|
} from "./local";
|
||||||
|
|
||||||
|
export function useLocalSettings() {
|
||||||
|
const [mounted, setMounted] = useState(false);
|
||||||
|
const [threadContextState, setThreadContextState] = useState<
|
||||||
|
Omit<AgentThreadContext, "thread_id">
|
||||||
|
>(DEFAULT_LOCAL_SETTINGS.context);
|
||||||
|
useEffect(() => {
|
||||||
|
if (!mounted) {
|
||||||
|
setThreadContextState(getLocalSettings().context);
|
||||||
|
}
|
||||||
|
setMounted(true);
|
||||||
|
}, [mounted]);
|
||||||
|
const setThreadContext = useCallback(
|
||||||
|
(context: Omit<AgentThreadContext, "thread_id">) => {
|
||||||
|
setThreadContextState(context);
|
||||||
|
updateContextOfLocalSettings(context);
|
||||||
|
},
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
threadContext: threadContextState,
|
||||||
|
setThreadContext,
|
||||||
|
};
|
||||||
|
}
|
||||||
2
frontend/src/core/settings/index.ts
Normal file
2
frontend/src/core/settings/index.ts
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
export * from "./hooks";
|
||||||
|
export * from "./local";
|
||||||
44
frontend/src/core/settings/local.ts
Normal file
44
frontend/src/core/settings/local.ts
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
import type { AgentThreadContext } from "../threads";
|
||||||
|
|
||||||
|
export const DEFAULT_LOCAL_SETTINGS: LocalSettings = {
|
||||||
|
context: {
|
||||||
|
model: "deepseek-v3.2",
|
||||||
|
thinking_enabled: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const LOCAL_SETTINGS_KEY = "deerflow.local-settings";
|
||||||
|
|
||||||
|
export interface LocalSettings {
|
||||||
|
context: Omit<AgentThreadContext, "thread_id">;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getLocalSettings(): LocalSettings {
|
||||||
|
if (typeof window === "undefined") {
|
||||||
|
return DEFAULT_LOCAL_SETTINGS;
|
||||||
|
}
|
||||||
|
const json = localStorage.getItem(LOCAL_SETTINGS_KEY);
|
||||||
|
try {
|
||||||
|
if (json) {
|
||||||
|
return JSON.parse(json);
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
|
return DEFAULT_LOCAL_SETTINGS;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function saveLocalSettings(settings: LocalSettings) {
|
||||||
|
localStorage.setItem(LOCAL_SETTINGS_KEY, JSON.stringify(settings));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function updateContextOfLocalSettings(
|
||||||
|
context: LocalSettings["context"],
|
||||||
|
) {
|
||||||
|
const settings = getLocalSettings();
|
||||||
|
saveLocalSettings({
|
||||||
|
...settings,
|
||||||
|
context: {
|
||||||
|
...settings.context,
|
||||||
|
...context,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user