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:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user