From 3e8cdabd7396a096c198673dd4d3033e75e8220a Mon Sep 17 00:00:00 2001 From: CREDO23 Date: Wed, 10 Dec 2025 11:34:01 +0000 Subject: [PATCH] refactor: complete migration of useLLMPreferences hook to jotai atoms - Migrated llm-role-manager.tsx to use jotai atoms - Fixed TypeScript errors in llm-role-manager.tsx - Deleted unused use-llm-configs.ts file - All LLM preferences now use centralized jotai + tanstack query atoms --- .../components/settings/llm-role-manager.tsx | 53 ++++--- surfsense_web/hooks/use-llm-configs.ts | 137 ------------------ 2 files changed, 29 insertions(+), 161 deletions(-) delete mode 100644 surfsense_web/hooks/use-llm-configs.ts diff --git a/surfsense_web/components/settings/llm-role-manager.tsx b/surfsense_web/components/settings/llm-role-manager.tsx index 601dbf65e..92d2e6f16 100644 --- a/surfsense_web/components/settings/llm-role-manager.tsx +++ b/surfsense_web/components/settings/llm-role-manager.tsx @@ -27,10 +27,11 @@ import { SelectTrigger, SelectValue, } from "@/components/ui/select"; -import { useLLMPreferences } from "@/hooks/use-llm-configs"; import { useAtomValue } from "jotai"; -import { llmConfigsAtom, globalLLMConfigsAtom } from "@/atoms/llm-config/llm-config-query.atoms"; +import { llmConfigsAtom, globalLLMConfigsAtom, llmPreferencesAtom } from "@/atoms/llm-config/llm-config-query.atoms"; +import { updateLLMPreferencesMutationAtom } from "@/atoms/llm-config/llm-config-mutation.atoms"; + const ROLE_DESCRIPTIONS = { long_context: { icon: Brain, @@ -76,12 +77,13 @@ export function LLMRoleManager({ searchSpaceId }: LLMRoleManagerProps) { refetch: refreshGlobalConfigs, } = useAtomValue(globalLLMConfigsAtom); const { - preferences, - loading: preferencesLoading, + data: preferences = {}, + isFetching: preferencesLoading, error: preferencesError, - updatePreferences, - refreshPreferences, - } = useLLMPreferences(searchSpaceId); + refetch: refreshPreferences, + } = useAtomValue(llmPreferencesAtom); + + const { mutateAsync: updatePreferences } = useAtomValue(updateLLMPreferencesMutationAtom); const [assignments, setAssignments] = useState({ long_context_llm_id: preferences.long_context_llm_id || "", @@ -148,14 +150,15 @@ export function LLMRoleManager({ searchSpaceId }: LLMRoleManagerProps) { ? parseInt(assignments.strategic_llm_id) : undefined : assignments.strategic_llm_id, - }; + }; - const success = await updatePreferences(numericAssignments); + await updatePreferences({ + search_space_id: searchSpaceId, + data: numericAssignments + }); - if (success) { - setHasChanges(false); - toast.success("LLM role assignments saved successfully!"); - } + setHasChanges(false); + toast.success("LLM role assignments saved successfully!"); setIsSaving(false); }; @@ -214,12 +217,12 @@ export function LLMRoleManager({ searchSpaceId }: LLMRoleManagerProps) { Configs