mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-20 23:21:06 +02:00
feat(model-connections): warn when a mutation disables workspace chat
This commit is contained in:
parent
ad91a3bfa5
commit
3dd41670ad
1 changed files with 24 additions and 2 deletions
|
|
@ -30,6 +30,24 @@ function invalidateModelConnections(workspaceId: number) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// After a mutation that can remove the workspace's last usable chat model,
|
||||||
|
// surface immediate feedback. The composer's inline notice covers the state on
|
||||||
|
// its own; this just makes the consequence obvious at the moment of the action.
|
||||||
|
async function warnIfWorkspaceChatDisabled(workspaceId: number) {
|
||||||
|
if (workspaceId <= 0) return;
|
||||||
|
try {
|
||||||
|
const status = await queryClient.fetchQuery({
|
||||||
|
queryKey: cacheKeys.modelConnections.setupStatus(workspaceId),
|
||||||
|
queryFn: () => modelConnectionsApiService.getLlmSetupStatus(workspaceId),
|
||||||
|
});
|
||||||
|
if (status?.status === "needs_setup") {
|
||||||
|
toast.warning("Chat is now disabled. Connect a language model to start chatting again.");
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// Non-fatal: the inline composer notice still reflects the state.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function upsertModelConnection(workspaceId: number, connection: ConnectionRead) {
|
function upsertModelConnection(workspaceId: number, connection: ConnectionRead) {
|
||||||
queryClient.setQueryData<ConnectionRead[]>(
|
queryClient.setQueryData<ConnectionRead[]>(
|
||||||
cacheKeys.modelConnections.all(workspaceId),
|
cacheKeys.modelConnections.all(workspaceId),
|
||||||
|
|
@ -81,9 +99,10 @@ export const deleteModelConnectionMutationAtom = atomWithMutation((get) => {
|
||||||
return {
|
return {
|
||||||
mutationKey: ["model-connections", "delete"],
|
mutationKey: ["model-connections", "delete"],
|
||||||
mutationFn: (id: number) => modelConnectionsApiService.deleteConnection(id),
|
mutationFn: (id: number) => modelConnectionsApiService.deleteConnection(id),
|
||||||
onSuccess: () => {
|
onSuccess: async () => {
|
||||||
toast.success("Connection deleted");
|
toast.success("Connection deleted");
|
||||||
invalidateModelConnections(workspaceId);
|
invalidateModelConnections(workspaceId);
|
||||||
|
await warnIfWorkspaceChatDisabled(workspaceId);
|
||||||
},
|
},
|
||||||
onError: (error: Error) => toast.error(error.message || "Failed to delete connection"),
|
onError: (error: Error) => toast.error(error.message || "Failed to delete connection"),
|
||||||
};
|
};
|
||||||
|
|
@ -182,7 +201,10 @@ export const bulkUpdateModelsMutationAtom = atomWithMutation((get) => {
|
||||||
mutationKey: ["models", "bulk-update"],
|
mutationKey: ["models", "bulk-update"],
|
||||||
mutationFn: ({ connectionId, data }: { connectionId: number; data: ModelsBulkUpdateRequest }) =>
|
mutationFn: ({ connectionId, data }: { connectionId: number; data: ModelsBulkUpdateRequest }) =>
|
||||||
modelConnectionsApiService.bulkUpdateModels(connectionId, data),
|
modelConnectionsApiService.bulkUpdateModels(connectionId, data),
|
||||||
onSuccess: () => invalidateModelConnections(workspaceId),
|
onSuccess: async () => {
|
||||||
|
invalidateModelConnections(workspaceId);
|
||||||
|
await warnIfWorkspaceChatDisabled(workspaceId);
|
||||||
|
},
|
||||||
onError: (error: Error) => toast.error(error.message || "Failed to update models"),
|
onError: (error: Error) => toast.error(error.message || "Failed to update models"),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue