From 77df6fd58eba6e0fdee6c2650a2ea536c24c6f0b Mon Sep 17 00:00:00 2001 From: icarus Date: Thu, 18 Sep 2025 22:37:02 +0800 Subject: [PATCH] feat(sessions): add getSession method to retrieve specific session Implement session retrieval functionality in both hook and API client to enable fetching individual sessions by ID --- src/renderer/src/api/agent.ts | 13 +++++++++++++ src/renderer/src/hooks/agents/useSessions.ts | 11 ++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/renderer/src/api/agent.ts b/src/renderer/src/api/agent.ts index 99b051d9d0..29b688e5be 100644 --- a/src/renderer/src/api/agent.ts +++ b/src/renderer/src/api/agent.ts @@ -12,6 +12,8 @@ import { CreateSessionResponseSchema, GetAgentResponse, GetAgentResponseSchema, + GetAgentSessionResponse, + GetAgentSessionResponseSchema, ListAgentSessionsResponse, ListAgentSessionsResponseSchema, type ListAgentsResponse, @@ -154,4 +156,15 @@ export class AgentApiClient { throw processError(error, 'Failed to add session.') } } + + public async getSession(agentId: string, sessionId: string): Promise { + const url = this.getSessionPaths(agentId).withId(sessionId) + try { + const response = await this.axios.get(url) + const data = GetAgentSessionResponseSchema.parse(response.data) + return data + } catch (error) { + throw processError(error, 'Failed to get session.') + } + } } diff --git a/src/renderer/src/hooks/agents/useSessions.ts b/src/renderer/src/hooks/agents/useSessions.ts index 5791ced138..b84cda5aaf 100644 --- a/src/renderer/src/hooks/agents/useSessions.ts +++ b/src/renderer/src/hooks/agents/useSessions.ts @@ -27,10 +27,19 @@ export const useSessions = (agent: AgentEntity) => { [agent.id, client, mutate, t] ) + // TODO: including messages field + const getSession = useCallback( + async (id: string) => { + return data?.find((session) => session.id === id) + }, + [data] + ) + return { sessions: data ?? [], error, isLoading, - createSession + createSession, + getSession } }