diff --git a/surfsense_web/atoms/llm-config/llm-config-mutation.atoms.ts b/surfsense_web/atoms/llm-config/llm-config-mutation.atoms.ts index 9b484e0de..6e0c18d73 100644 --- a/surfsense_web/atoms/llm-config/llm-config-mutation.atoms.ts +++ b/surfsense_web/atoms/llm-config/llm-config-mutation.atoms.ts @@ -6,6 +6,7 @@ import type { UpdateLLMConfigRequest, DeleteLLMConfigRequest, GetLLMConfigsResponse, + UpdateLLMPreferencesRequest, } from "@/contracts/types/llm-config.types"; import { llmConfigApiService } from "@/lib/apis/llm-config-api.service"; import { cacheKeys } from "@/lib/query-client/cache-keys"; @@ -91,3 +92,22 @@ export const deleteLLMConfigMutationAtom = atomWithMutation((get) => { }, }; }); + +export const updateLLMPreferencesMutationAtom = atomWithMutation((get) => { + const searchSpaceId = get(activeSearchSpaceIdAtom); + + return { + mutationKey: cacheKeys.llmConfigs.preferences(searchSpaceId!), + enabled: !!searchSpaceId, + mutationFn: async (request: UpdateLLMPreferencesRequest) => { + return llmConfigApiService.updateLLMPreferences(request); + }, + + onSuccess: () => { + toast.success("LLM preferences updated successfully"); + queryClient.invalidateQueries({ + queryKey: cacheKeys.llmConfigs.preferences(searchSpaceId!), + }); + }, + }; +});