mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-03 11:19:10 +08:00
feat(sessions): add delete session functionality to agent api and hook
Implement session deletion by adding deleteSession method to AgentApiClient and corresponding hook in useSessions. This enables removing sessions from the UI with proper error handling and cache invalidation.
This commit is contained in:
parent
d0b64dabc2
commit
369cc37071
@ -176,4 +176,13 @@ export class AgentApiClient {
|
||||
throw processError(error, 'Failed to get session.')
|
||||
}
|
||||
}
|
||||
|
||||
public async deleteSession(agentId: string, sessionId: string): Promise<void> {
|
||||
const url = this.getSessionPaths(agentId).withId(sessionId)
|
||||
try {
|
||||
await this.axios.delete(url)
|
||||
} catch (error) {
|
||||
throw processError(error, 'Failed to delete session.')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,11 +37,24 @@ export const useSessions = (agent: AgentEntity) => {
|
||||
[agent.id, client, mutate]
|
||||
)
|
||||
|
||||
const deleteSession = useCallback(
|
||||
async (id: string) => {
|
||||
try {
|
||||
await client.deleteSession(agent.id, id)
|
||||
mutate((prev) => prev?.filter((session) => session.id !== id))
|
||||
} catch (error) {
|
||||
window.toast.error(t('agent.session.delete.error.failed'))
|
||||
}
|
||||
},
|
||||
[agent.id, client, mutate, t]
|
||||
)
|
||||
|
||||
return {
|
||||
sessions: data ?? [],
|
||||
error,
|
||||
isLoading,
|
||||
createSession,
|
||||
getSession
|
||||
getSession,
|
||||
deleteSession
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user