import { Paperclip } from 'lucide-react'; import { Badge } from '@/components/ui/badge'; import type OpenAI from 'openai'; interface UserMessageProps { content: string | Array; } /** * Component to render user messages nicely * Handles both string content and array content (text parts) * Detects "Added file: /tmp/" patterns and renders them as badges */ export function UserMessage({ content }: UserMessageProps) { // Convert content to array format for uniform processing const parts = typeof content === 'string' ? [{ type: 'text' as const, text: content }] : content.filter(part => part.type === 'text'); // If no content, return empty if (parts.length === 0) { return null; } const getFileName = (filepath: string) => { return filepath.split('/').pop() || filepath; }; return (
{parts.map((part, index) => { if (part.type === 'text') { // Only render text if it has content if (!part.text.trim()) return null; // Detect "Added file: " pattern const fileAddedMatch = /^Added file: (\/[^\s\n]+$)/g.exec(part.text); console.log('fileAddedMatch', part, fileAddedMatch); if (fileAddedMatch && fileAddedMatch[1]) { const path = fileAddedMatch[1]; const filename = getFileName(path); return (
{filename}
); } // Regular text rendering return (
{part.text}
); } else { // Unsupported content type return (
[Unsupported content type]
); } })}
); }