mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-26 17:26:23 +02:00
feat: add LLM config cache keys and create mutation atom
This commit is contained in:
parent
03279a2836
commit
2200d7b63c
3 changed files with 38 additions and 1 deletions
29
surfsense_web/atoms/llm-config/llm-config-mutation.atoms.ts
Normal file
29
surfsense_web/atoms/llm-config/llm-config-mutation.atoms.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import { atomWithMutation } from "jotai-tanstack-query";
|
||||
import { toast } from "sonner";
|
||||
import { activeSearchSpaceIdAtom } from "@/atoms/seach-spaces/seach-space-queries.atom";
|
||||
import type { CreateLLMConfigRequest } from "@/contracts/types/llm-config.types";
|
||||
import { llmConfigApiService } from "@/lib/apis/llm-config-api.service";
|
||||
import { cacheKeys } from "@/lib/query-client/cache-keys";
|
||||
import { queryClient } from "@/lib/query-client/client";
|
||||
|
||||
export const createLLMConfigMutationAtom = atomWithMutation((get) => {
|
||||
const searchSpaceId = get(activeSearchSpaceIdAtom);
|
||||
|
||||
return {
|
||||
mutationKey: cacheKeys.llmConfigs.all(searchSpaceId!),
|
||||
enabled: !!searchSpaceId,
|
||||
mutationFn: async (request: CreateLLMConfigRequest) => {
|
||||
return llmConfigApiService.createLLMConfig(request);
|
||||
},
|
||||
|
||||
onSuccess: () => {
|
||||
toast.success("LLM configuration created successfully");
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: cacheKeys.llmConfigs.all(searchSpaceId!),
|
||||
});
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: cacheKeys.llmConfigs.global(),
|
||||
});
|
||||
},
|
||||
};
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue