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 } }