mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-08 22:39:36 +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,
|
CreateSessionResponseSchema,
|
||||||
GetAgentResponse,
|
GetAgentResponse,
|
||||||
GetAgentResponseSchema,
|
GetAgentResponseSchema,
|
||||||
|
GetAgentSessionResponse,
|
||||||
|
GetAgentSessionResponseSchema,
|
||||||
ListAgentSessionsResponse,
|
ListAgentSessionsResponse,
|
||||||
ListAgentSessionsResponseSchema,
|
ListAgentSessionsResponseSchema,
|
||||||
type ListAgentsResponse,
|
type ListAgentsResponse,
|
||||||
@ -154,4 +156,15 @@ export class AgentApiClient {
|
|||||||
throw processError(error, 'Failed to add session.')
|
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]
|
[agent.id, client, mutate, t]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TODO: including messages field
|
||||||
|
const getSession = useCallback(
|
||||||
|
async (id: string) => {
|
||||||
|
return data?.find((session) => session.id === id)
|
||||||
|
},
|
||||||
|
[data]
|
||||||
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
sessions: data ?? [],
|
sessions: data ?? [],
|
||||||
error,
|
error,
|
||||||
isLoading,
|
isLoading,
|
||||||
createSession
|
createSession,
|
||||||
|
getSession
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user