fix(useSessions): correct session fetching logic to use API call

Previously the getSession hook was only searching local data. Now it properly fetches from the API and updates the cache. This ensures data consistency when sessions are modified elsewhere.
This commit is contained in:
icarus 2025-09-18 22:46:24 +08:00
parent 77df6fd58e
commit 4c4039283f

View File

@ -30,9 +30,11 @@ export const useSessions = (agent: AgentEntity) => {
// TODO: including messages field
const getSession = useCallback(
async (id: string) => {
return data?.find((session) => session.id === id)
const result = await client.getSession(agent.id, id)
mutate((prev) => prev?.map((session) => (session.id === result.id ? result : session)))
return result
},
[data]
[agent.id, client, mutate]
)
return {