mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-31 00:10:22 +08:00
feat(hooks): add useSessions hook for agent session management
This commit is contained in:
parent
db2042800b
commit
da61500e34
20
src/renderer/src/hooks/agents/useSessions.ts
Normal file
20
src/renderer/src/hooks/agents/useSessions.ts
Normal 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
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user