From 369cc37071c0327ce3004476b1a6058279e0ec4d Mon Sep 17 00:00:00 2001 From: icarus Date: Thu, 18 Sep 2025 22:52:46 +0800 Subject: [PATCH] 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. --- src/renderer/src/api/agent.ts | 9 +++++++++ src/renderer/src/hooks/agents/useSessions.ts | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/renderer/src/api/agent.ts b/src/renderer/src/api/agent.ts index 96fdcb58ed..0ca16b984a 100644 --- a/src/renderer/src/api/agent.ts +++ b/src/renderer/src/api/agent.ts @@ -176,4 +176,13 @@ export class AgentApiClient { throw processError(error, 'Failed to get session.') } } + + public async deleteSession(agentId: string, sessionId: string): Promise { + const url = this.getSessionPaths(agentId).withId(sessionId) + try { + await this.axios.delete(url) + } catch (error) { + throw processError(error, 'Failed to delete session.') + } + } } diff --git a/src/renderer/src/hooks/agents/useSessions.ts b/src/renderer/src/hooks/agents/useSessions.ts index 818eba7cc2..6aa17a216d 100644 --- a/src/renderer/src/hooks/agents/useSessions.ts +++ b/src/renderer/src/hooks/agents/useSessions.ts @@ -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 } }