mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-20 23:21:06 +02:00
feat(model-connections): add llmSetupStatusAtomFamily and invalidate on mutations
This commit is contained in:
parent
ad28bd912c
commit
5efd4291bf
2 changed files with 19 additions and 0 deletions
|
|
@ -25,6 +25,9 @@ function invalidateModelConnections(workspaceId: number) {
|
|||
queryClient.invalidateQueries({
|
||||
queryKey: cacheKeys.modelConnections.roles(workspaceId),
|
||||
});
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: cacheKeys.modelConnections.setupStatus(workspaceId),
|
||||
});
|
||||
}
|
||||
|
||||
function upsertModelConnection(workspaceId: number, connection: ConnectionRead) {
|
||||
|
|
@ -208,6 +211,9 @@ export const updateModelRolesMutationAtom = atomWithMutation((get) => {
|
|||
queryClient.invalidateQueries({
|
||||
queryKey: cacheKeys.modelConnections.roles(workspaceId),
|
||||
});
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: cacheKeys.modelConnections.setupStatus(workspaceId),
|
||||
});
|
||||
},
|
||||
onError: (error: Error) => toast.error(error.message || "Failed to update model roles"),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { atomWithQuery } from "jotai-tanstack-query";
|
||||
import { atomFamily } from "jotai/utils";
|
||||
import { modelConnectionsApiService } from "@/lib/apis/model-connections-api.service";
|
||||
import { isAuthenticated } from "@/lib/auth-utils";
|
||||
import { cacheKeys } from "@/lib/query-client/cache-keys";
|
||||
|
|
@ -44,3 +45,15 @@ export const modelRolesAtom = atomWithQuery((get) => {
|
|||
queryFn: () => modelConnectionsApiService.getModelRoles(workspaceId),
|
||||
};
|
||||
});
|
||||
|
||||
// Keyed by the route workspaceId (not activeWorkspaceIdAtom) so the onboarding
|
||||
// gate's verdict can never be computed against a stale workspace during a
|
||||
// workspace switch.
|
||||
export const llmSetupStatusAtomFamily = atomFamily((workspaceId: number) =>
|
||||
atomWithQuery(() => ({
|
||||
queryKey: cacheKeys.modelConnections.setupStatus(workspaceId),
|
||||
enabled: workspaceId > 0 && isAuthenticated(),
|
||||
staleTime: 5 * 60 * 1000,
|
||||
queryFn: () => modelConnectionsApiService.getLlmSetupStatus(workspaceId),
|
||||
}))
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue