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:
icarus 2025-09-18 22:52:46 +08:00
parent d0b64dabc2
commit 369cc37071
2 changed files with 23 additions and 1 deletions

View File

@ -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.')
}
}
}

View File

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