import { useEffect, useState } from 'react'; import { useAppStore } from '@/store'; import { useChat } from '@/hooks/useChat'; import { ChatMessage } from './ChatMessage'; import { ChatInput } from './ChatInput'; import { PipelineProgress } from './PipelineProgress'; import { ScrollArea } from '@/components/ui/scroll-area'; import { Button } from '@/components/ui/button'; import { RefreshCw, Loader2 } from 'lucide-react'; export function ChatView() { const { activeConversationId, setConversations, selectedAccountId } = useAppStore(); const { messages, connected, thinking, toolStatus, send, createConversation } = useChat(activeConversationId); const [manifestPath, setManifestPath] = useState(null); useEffect(() => { fetch('/api/pipeline/conversations') .then((r) => r.json()) .then(setConversations) .catch(() => {}); }, [messages]); useEffect(() => { const toolMsgs = messages.filter((m) => m.role === 'tool'); if (toolMsgs.length > 0) { try { const lastTool = JSON.parse(toolMsgs[toolMsgs.length - 1].content); if (lastTool.manifest) setManifestPath(lastTool.manifest); } catch {} } }, [messages]); const handleNewConversation = () => { createConversation('新对话', selectedAccountId || undefined); setTimeout(() => { fetch('/api/pipeline/conversations') .then((r) => r.json()) .then(setConversations); }, 300); }; const handleResume = async () => { if (!manifestPath) return; try { await fetch('/api/pipeline/resume', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ manifest: manifestPath }), }); } catch (e) { console.error('Resume failed:', e); } }; if (!activeConversationId) { return (

选择对话或开始新对话

); } return (
{connected ? '已连接' : '连接中...'}
{manifestPath && ( )}
{messages.map((msg) => ( ))} {thinking && (
{toolStatus || '思考中...'}
)}
); }