import { useEffect, useState, useCallback, useRef } from 'react'; import { App as AntApp, Empty, Modal } from 'antd'; import type { ChatPageLogicOutput } from './ChatPageLogic'; import { markdownToPlainText } from './utils/copy'; import { useChatPageLogic } from './ChatPageLogic'; import ChatBody from './components/ChatBody'; import ChatDrawers from './components/ChatDrawers'; import ChatHeader from './components/ChatHeader'; import ChatInput from './components/ChatInput'; import ChatOutline from './components/ChatOutline'; import type { ModelOverrides } from '../../api'; import { useAuth } from '../../store/auth'; import './styles/chat-page-pure.css'; /** * 纯会话页面组件 * 仅保留聊天主区域(section.chat-main),去掉全局 Sidebar 和 AgentSidebar(chat-side) * 会话功能与原聊天页面完全一致 */ export default function ChatPagePure() { const logic = useChatPageLogic(); const { message } = AntApp.useApp(); const { logout } = useAuth(); const [outlineCollapsed, setOutlineCollapsed] = useState(true); const isAutoScrolling = useRef(false); const { id, roomId, highlightId, historyDrawerOpen, mcpDrawerOpen, paramsDrawerOpen, tplDrawerOpen, agent, agentList, messages, branches, bodyRef, sender, navigate, overrides, setOverrides, setRoomId, setHighlightId, setHistoryDrawerOpen, setMcpDrawerOpen, setParamsDrawerOpen, setTplDrawerOpen, handleNewSession, } = logic; // 初始化时,如果有历史消息,激活最后一条 Agent 消息 useEffect(() => { if (messages.length > 0 && !highlightId) { const agentMsgs = messages.filter(m => m.role === 'assistant' || m.role === 'agent' || m.speaker?.type === 'agent'); if (agentMsgs.length > 0) { setHighlightId(agentMsgs[agentMsgs.length - 1].id); } } }, [messages.length]); const handleJump = useCallback((msgId: string) => { isAutoScrolling.current = true; setHighlightId(msgId); const el = document.getElementById('msg-' + msgId); if (el) { el.scrollIntoView({ block: 'start', behavior: 'smooth' }); setTimeout(() => { isAutoScrolling.current = false; }, 800); } }, [setHighlightId]); // 退出登录 const handleLogout = () => { Modal.confirm({ title: '确定要退出登录吗?', onOk: async () => { await logout(); window.location.href = '/login'; }, }); }; return (
{!agent ? (
) : (
setHistoryDrawerOpen(true)} onOpenParams={() => setParamsDrawerOpen(true)} onOpenMcp={() => setMcpDrawerOpen(true)} onManageAgent={() => navigate(`/agents/${id}`)} onClear={sender.handleClear} onLogout={handleLogout} /> { const content = mode === 'markdown' ? text : markdownToPlainText(text); navigator.clipboard?.writeText(content).then(() => { message.success(mode === 'markdown' ? '已复制(Markdown)' : '已复制(纯文本)'); }); }} /> setTplDrawerOpen(true)} modelOptions={sender.modelOptions} activeModelValue={sender.activeModelValue} onChangeModel={(modelId) => { const picked = sender.modelOptions.find((o) => o.value === modelId); setOverrides((o: ModelOverrides) => ({ ...o, model_id: modelId, model: picked?.label ?? o.model })); }} agentList={agentList} onInsertMention={() => {}} onOpenHistory={() => setHistoryDrawerOpen(true)} onNewSession={handleNewSession} />
setOutlineCollapsed(!outlineCollapsed)} onJump={handleJump} />
)}
sender.setInput(updater)} overrides={overrides} setOverrides={setOverrides} roomId={roomId} setRoomId={setRoomId} setHighlightId={setHighlightId} sessionRefresh={sender.sessionRefresh} mcpDrawerOpen={mcpDrawerOpen} setMcpDrawerOpen={setMcpDrawerOpen} tplDrawerOpen={tplDrawerOpen} setTplDrawerOpen={setTplDrawerOpen} paramsDrawerOpen={paramsDrawerOpen} setParamsDrawerOpen={setParamsDrawerOpen} historyDrawerOpen={historyDrawerOpen} setHistoryDrawerOpen={setHistoryDrawerOpen} notify={{ success: (t) => message.success(t) }} />
); }