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
This commit is contained in:
icarus 2025-09-18 22:37:02 +08:00
parent 100801821f
commit 77df6fd58e
2 changed files with 23 additions and 1 deletions

View File

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

View File

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