模块以 pages/Agent.tsx 为唯一页面入口,组合 stores/agent.ts(基于 Zustand 的全局状态)与 components/chat/*(纯展示型 UI 组件)。 - 数据层:stores/agent.ts 通过 create<AgentState> 暴露 messages、toolCalls、activity、swarmRuns、streamingText、reasoningTail 等状态,并提供 addMessage、appendDelta、startActivity、updateRunningToolCall、upsertSwarmStatus、cacheSession 等动作;内部维护 _sessionCache(LRU,上限 5)和 _swarmSessionCache 做跨会话缓存。 - 事件层:Agent.tsx 通过 useSSE hook 连接后端 SSE,按事件类型(text_delta、reasoning_delta、thinking_done、tool_call、tool_result、tool_progress、tool_heartbeat、attempt.*、message.received、compact 等)分派到对应回调,统一经 identifyActivity 关联 attempt_id 并驱动 store 更新;文本增量通过 queueStreamUpdate + STREAM_FLUSH_INTERVAL_MS 节流合并后写入 store。 - 视图层:ConversationTimeline / ThinkingTimeline / MessageBubble / ModelRuntimeBar / LiveRuntimePanel / SwarmDashboard / MandateProposalCard / RunCompleteCard 等组件消费 store 中的消息与活动状态进行渲染;Composer 负责用户输入并通过 api.sendMessage 触发新 attempt。 - 依赖方向:Agent.tsx → stores/agent.ts + @/lib/api + @/hooks/useSSE + @/components/chat/*;chat 组件之间仅通过 props 通信,不直接访问 store,保持单向数据流。 - 特殊通道:提案与 live action 走独立的 liveItems 状态而非消息列表,作为特权表面(SPEC Consent §1/§4/§5),由 MandateProposalCard 与 LiveRuntimePanel 单独渲染。