import { useEffect, useRef, useState } from "react"; import { useOfficeStore } from "@/store/office-store"; import { resetChat, sendChat } from "@/gateway/live"; /** * Two-way chat with one project — each message runs headless and is stitched * to the previous with --resume. Shared by the side panel and the full-screen * overlay via the `variant` prop. */ export function ChatConversation({ agentId, variant, }: { agentId: string; variant: "panel" | "full"; }) { const thread = useOfficeStore((s) => s.chats.get(agentId)); const setChatFullscreen = useOfficeStore((s) => s.setChatFullscreen); const isFull = useOfficeStore((s) => s.chatFullscreen); const [input, setInput] = useState(""); const [fromProject, setFromProject] = useState(false); const listRef = useRef(null); const busy = thread?.busy ?? false; const messages = thread?.messages ?? []; const started = messages.length > 0; useEffect(() => { listRef.current?.scrollTo({ top: listRef.current.scrollHeight }); }, [messages.length, busy]); const send = () => { const text = input.trim(); if (!text || busy) return; sendChat(agentId, text, fromProject); setInput(""); }; return (

對話

{started && ( )}
{started && (
{messages.map((m, i) => (
{m.text}
))} {busy &&
⋯ 執行中,過程看辦公室裡的小人
}
)}