mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-29 05:51:26 +08:00
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:
parent
100801821f
commit
77df6fd58e
@ -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.')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user