import { Button, Dropdown, Space, Tag, Tooltip, Avatar } from 'antd'; import type { BranchInfo, ChatMessage } from '../../../../api'; import type { Agent } from '../../../../api/agents'; import Markdown from '../../../../components/Markdown'; import { ProductCopyIcon } from '../../../../components/icons'; import type { CopyMode } from '../../utils/copy'; import { ReasoningView, RetrievedView, ToolCallView } from './MetaViews'; export default function MessageItem(props: { message: ChatMessage; agentList: Agent[]; currentAgentId: string; highlighted?: boolean; branch?: BranchInfo; busy?: boolean; onRegenerate?: (id: string) => void; onSwitchBranch?: (userMsgId: string, branchId: string) => void; onCopy?: (text: string, mode: CopyMode) => void; }) { const { message, agentList, currentAgentId, highlighted, branch, busy, onRegenerate, onSwitchBranch, onCopy } = props; // 获取回答者 Agent 信息 const answerAgentId = message.agent_id || (message.role === 'assistant' ? currentAgentId : undefined); const answerAgent = answerAgentId ? agentList.find(a => a.id === answerAgentId) : undefined; const hasBranches = !!branch && branch.total > 1; const activeIdx = branch?.activeIndex ?? 0; const total = branch?.total ?? 1; const goPrev = () => { if (!branch || !message.parentId) return; const i = Math.max(0, activeIdx - 1); onSwitchBranch?.(message.parentId, branch.ids[i]); }; const goNext = () => { if (!branch || !message.parentId) return; const i = Math.min(total - 1, activeIdx + 1); onSwitchBranch?.(message.parentId, branch.ids[i]); }; return (
{message.role === 'assistant' ? (
{/* AGENT: 头像在左侧,内容在右侧(靠左对齐) */} {answerAgent?.name?.charAt(0)?.toUpperCase() || 'A'}
{answerAgent?.name || 'AI'}
{message.content}
{hasBranches && ( {activeIdx + 1} / {total} )} {message.meta?.aborted && 已停止} onCopy?.(message.content, 'plain') }, { key: 'markdown', label: '复制 Markdown', onClick: () => onCopy?.(message.content, 'markdown') } ] }} >
{message.meta && (
{!!message.meta.reasoning && } {!!message.meta.retrieved?.length && } {!!message.meta.toolCalls?.length && }
)}
) : (
{/* 用户: 头像在右侧,内容在左侧(靠右对齐) */}
{message.content.includes('![image](') ? ( {message.content} ) : ( @$1') }} /> )}
)}
); }