import React from 'react'; import './MessageBubble.css'; /** * Parse simple markdown into React elements. * Supports: **bold**, numbered lists (1. 2. 3.), and line breaks. */ function formatMessage(text) { if (!text) return null; const paragraphs = text.split(/\n\n+/); return paragraphs.map((para, i) => { const trimmed = para.trim(); if (!trimmed) return null; const stepMatch = trimmed.match(/^(\d+)\.\s*(.*)/s); if (stepMatch) { const num = stepMatch[1]; const content = stepMatch[2]; return (
{num} {renderInline(content)}
); } return

{renderInline(trimmed)}

; }); } /** * Render inline markdown: **bold** text. */ function renderInline(text) { if (!text) return null; const parts = text.split(/(\*\*[^*]+\*\*)/g); return parts.map((part, i) => { if (part.startsWith('**') && part.endsWith('**')) { return {part.slice(2, -2)}; } return {part}; }); } /** * MessageBubble — displays a single chat message with formatted text and images. */ function MessageBubble({ message }) { const { role, text, timestamp, safetyAlert, images } = message; const isUser = role === 'user'; const formattedTime = timestamp ? new Date(timestamp).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }) : ''; return (
{safetyAlert && (
{safetyAlert}
)}
{isUser ? (

{text}

) : (
{formatMessage(text)}
)} {/* Annotated device screenshots */} {images && images.length > 0 && (
{images.map((img, i) => (
{img.alt}

{img.alt}

))}
)}
{!isUser && ( )}
); } export default MessageBubble;