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 (