import { User, Bot, Wrench, CheckCircle, AlertCircle, Terminal } from 'lucide-react'
import ReactMarkdown from 'react-markdown'
import remarkGfm from 'remark-gfm'
import type { ChatMessage } from '../../types/protocol'
interface MessageBubbleProps {
message: ChatMessage
}
export function MessageBubble({ message }: MessageBubbleProps) {
const isUser = message.role === 'user'
const isTool = message.role === 'tool'
const getIcon = () => {
if (isUser) return
if (isTool) {
if (message.type === 'tool_call') return
if (message.type === 'tool_result') return
if (message.type === 'tool_pending') return
return
}
return
}
const getContainerStyles = () => {
if (isUser) {
return 'bg-gradient-to-br from-[#00f0ff]/20 to-[#3b82f6]/20 border-[#00f0ff]/30 text-white'
}
if (isTool) {
if (message.type === 'tool_call') return 'bg-amber-500/10 border-amber-500/30 text-amber-100'
if (message.type === 'tool_result') return 'bg-emerald-500/10 border-emerald-500/30 text-emerald-100'
if (message.type === 'tool_pending') return 'bg-orange-500/10 border-orange-500/30 text-orange-100'
return 'bg-zinc-800/50 border-zinc-700 text-zinc-300'
}
return 'bg-[#1a1a25] border-white/10 text-white'
}
const getAvatarStyles = () => {
if (isUser) return 'bg-gradient-to-br from-[#00f0ff] to-[#3b82f6]'
if (isTool) {
if (message.type === 'tool_call') return 'bg-amber-500'
if (message.type === 'tool_result') return 'bg-emerald-500'
if (message.type === 'tool_pending') return 'bg-orange-500'
return 'bg-zinc-700'
}
return 'bg-gradient-to-br from-[#8b5cf6] to-[#ec4899]'
}
const formatTime = (timestamp: number) => {
return new Date(timestamp).toLocaleTimeString('zh-CN', {
hour: '2-digit',
minute: '2-digit',
})
}
return (
{getIcon()}
{isUser ? 'You' : isTool ? message.toolName || 'Tool' : 'Assistant'}
{formatTime(message.timestamp)}
{isTool && message.toolName && (
{message.toolName}
)}
{isUser ? (
// 用户消息保持纯文本
{message.content}
) : (
// AI 和工具消息使用 Markdown 渲染
{children}
)
}
return (
{children}
)
},
// 标题样式
h1: ({ children }) => (
{children}
),
h2: ({ children }) => (
{children}
),
h3: ({ children }) => (
{children}
),
// 段落
p: ({ children }) => {children}
,
// 列表
ul: ({ children }) => ,
ol: ({ children }) => {children}
,
// 链接
a: ({ href, children }) => (
{children}
),
// 表格
table: ({ children }) => (
),
thead: ({ children }) => {children},
th: ({ children }) => (
{children} |
),
td: ({ children }) => (
{children} |
),
// 引用块
blockquote: ({ children }) => (
{children}
),
// 分隔线
hr: () =>
,
// 加粗和斜体
strong: ({ children }) => {children},
em: ({ children }) => {children},
}}
>
{message.content}
)}
)
}