feat(hooks): add useSessions hook for agent session management

This commit is contained in:
icarus 2025-09-18 21:57:18 +08:00
parent db2042800b
commit da61500e34

View File

@ -0,0 +1,20 @@
import { AgentEntity } from '@renderer/types'
import useSWR from 'swr'
import { useAgentClient } from './useAgentClient'
export const useSessions = (agent: AgentEntity) => {
const client = useAgentClient()
const key = client.agentPaths.base
const fetcher = async () => {
const data = await client.listSessions(agent.id)
return data.data
}
const { data, error, isLoading } = useSWR(key, fetcher)
return {
sessions: data ?? [],
error,
isLoading
}
}