import { useEffect, useRef, useState } from 'react'; import { Button } from '@/components/ui/button'; import { cloudAgentsApi } from '@/lib/cloud-agents-api'; import type { CloudAgentEntry, CloudThread } from '../../../shared/cloud-agents'; import { cloudStatus } from './CloudChat'; export function CloudOverview({ section, onAgent, onThread }: { section: 'received' | 'activity'; onAgent: (entry: CloudAgentEntry) => void; onThread: (thread: CloudThread) => void; }) { const [agents, setAgents] = useState([]); const [threads, setThreads] = useState([]); const [error, setError] = useState(''); const [loading, setLoading] = useState(true); const [offset, setOffset] = useState(null); const [refresh, setRefresh] = useState(0); const paged = useRef(false); useEffect(() => { let live = true; paged.current = false; setLoading(true); const load = async () => { try { if (section === 'received') { const result = await cloudAgentsApi.call('received', {}); if (live) setAgents(result.agents); } else { const result = await cloudAgentsApi.call('threads', {}); if (live) { setThreads(result.threads); setOffset(result.next_offset); } } if (live) setError(''); } catch(e) { if (live) setError(e instanceof Error ? e.message : '暂时无法读取'); } finally { if (live) setLoading(false); } }; void load(); const timer = window.setInterval(() => { if (!paged.current) void load(); }, 15000); return () => { live = false; window.clearInterval(timer); }; }, [section, refresh]); const more = async () => { if (offset === null) return; paged.current = true; setLoading(true); try { const page = await cloudAgentsApi.call('threads', { offset }); setThreads(v => [...v, ...page.threads]); setOffset(page.next_offset); } catch(e) { setError(e instanceof Error ? e.message : '加载失败'); } finally { setLoading(false); } }; return
{error &&

{error}

} {section === 'received' ? <>

这里显示其他创作者授权你使用的智能体。由创建者承担费用,你的会话和文件仅属于你。

{!loading && !agents.length &&

还没有收到分享

}
{agents.map(agent => )}
: <>

查看自己的对话、自动任务结果和待确认事项。

{!loading && !threads.length &&

还没有运行记录

} {threads.map(thread => )} {offset !== null && } }
; }