mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-27 12:51:26 +08:00
feat(agents): add deleteAgent hook to useAgents
Implement agent deletion functionality with optimistic updates and error handling
This commit is contained in:
parent
34c95ca787
commit
3b0995c8ef
@ -40,11 +40,27 @@ export const useAgents = () => {
|
||||
[client, mutate, t]
|
||||
)
|
||||
|
||||
const deleteAgent = useCallback(
|
||||
async (id: string) => {
|
||||
try {
|
||||
await client.deleteAgent(id)
|
||||
mutate((prev) => ({
|
||||
agents: prev?.agents.filter((a) => a.id !== id) ?? [],
|
||||
total: prev ? prev.total - 1 : 0
|
||||
}))
|
||||
} catch (error) {
|
||||
window.toast.error(formatErrorMessageWithPrefix(error, t('agent.delete.error.failed')))
|
||||
}
|
||||
},
|
||||
[client, mutate, t]
|
||||
)
|
||||
|
||||
return {
|
||||
agents: data?.agents ?? [],
|
||||
error,
|
||||
isLoading,
|
||||
addAgent,
|
||||
updateAgent
|
||||
updateAgent,
|
||||
deleteAgent
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user