Initial commit: deerflow-server (frontend-web + offline-backend-20260512)
This commit is contained in:
commit
e7a455f22e
560 files changed
+101331
No files matched your search
@@ -0,0 +1,59 @@
|
||||
import { useCallback, useMemo, useSyncExternalStore } from "react";
|
||||
|
||||
import {
|
||||
DEFAULT_LOCAL_SETTINGS,
|
||||
applyThreadModelOverride,
|
||||
type LocalSettings,
|
||||
} from "./local";
|
||||
import {
|
||||
getBaseSettingsSnapshot,
|
||||
getThreadModelSnapshot,
|
||||
subscribe,
|
||||
updateLocalSettings,
|
||||
updateThreadSettings,
|
||||
type LocalSettingsSetter,
|
||||
} from "./store";
|
||||
|
||||
export function useLocalSettings(): [LocalSettings, LocalSettingsSetter] {
|
||||
const settings = useSyncExternalStore(
|
||||
subscribe,
|
||||
getBaseSettingsSnapshot,
|
||||
() => DEFAULT_LOCAL_SETTINGS,
|
||||
);
|
||||
|
||||
const setSettings = useCallback<LocalSettingsSetter>((key, value) => {
|
||||
updateLocalSettings(key, value);
|
||||
}, []);
|
||||
|
||||
return [settings, setSettings];
|
||||
}
|
||||
|
||||
export function useThreadSettings(
|
||||
threadId: string,
|
||||
): [LocalSettings, LocalSettingsSetter] {
|
||||
const baseSettings = useSyncExternalStore(
|
||||
subscribe,
|
||||
getBaseSettingsSnapshot,
|
||||
() => DEFAULT_LOCAL_SETTINGS,
|
||||
);
|
||||
|
||||
const threadModelName = useSyncExternalStore(
|
||||
subscribe,
|
||||
() => getThreadModelSnapshot(threadId),
|
||||
() => undefined,
|
||||
);
|
||||
|
||||
const settings = useMemo(
|
||||
() => applyThreadModelOverride(baseSettings, threadModelName),
|
||||
[baseSettings, threadModelName],
|
||||
);
|
||||
|
||||
const setSettings = useCallback<LocalSettingsSetter>(
|
||||
(key, value) => {
|
||||
updateThreadSettings(threadId, key, value);
|
||||
},
|
||||
[threadId],
|
||||
);
|
||||
|
||||
return [settings, setSettings];
|
||||
}
|
||||
Reference in new issue
Block a user