import { memo } from 'react'; import { Streamdown } from 'streamdown'; import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'; import { Bot, User, Square, Wrench } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { AIMessage } from '@/hooks/useAIChat'; interface AIMessageItemProps { message: AIMessage; userDisplayName?: string; userProfileImage?: string; isCurrentlyLoading?: boolean; onStopGeneration?: () => void; } export const AIMessageItem = memo(({ message, userDisplayName = 'You', userProfileImage, isCurrentlyLoading = false, onStopGeneration }: AIMessageItemProps) => { // Get display name based on role const getDisplayName = () => { switch (message.role) { case 'user': return userDisplayName; case 'assistant': return 'Assistant'; case 'system': return 'System'; case 'tool': return 'Tool'; default: return 'Unknown'; } }; // Get role label for display const getRoleLabel = () => { switch (message.role) { case 'user': return 'User'; case 'assistant': return 'AI'; case 'system': return 'System'; case 'tool': return 'Tool'; default: return message.role; } }; // Get content to display const getContent = () => { if (typeof message.content === 'string') { return message.content; } if (Array.isArray(message.content)) { // Handle array content (like images, text blocks) return message.content .map(item => { if (typeof item === 'string') return item; if (item.type === 'text') return item.text; if (item.type === 'image_url') return `[Image: ${item.image_url.url}]`; return '[Unknown content]'; }) .join('\n'); } return ''; }; return (