import React, { useState } from 'react'; import './Message.css'; function renderMarkdown(text) { // Bold let html = text.replace(/\*\*(.*?)\*\*/g, '$1'); // Inline code html = html.replace(/`([^`]+)`/g, '$1'); // Headers html = html.replace(/^### (.+)$/gm, '

$1

'); html = html.replace(/^## (.+)$/gm, '

$1

'); html = html.replace(/^# (.+)$/gm, '

$1

'); // Lists html = html.replace(/^\* (.+)$/gm, '
  • $1
  • '); html = html.replace(/^\d+\. (.+)$/gm, '
  • $1
  • '); // Paragraphs html = html .split('\n\n') .map(para => { if (para.includes('
  • ')) return ``; if (para.match(/^${para.replace(/\n/g, '
    ')}

    `; }) .join(''); return html; } function formatTime(date) { return new Date(date).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); } export default function Message({ message }) { const isUser = message.role === 'user'; const [showChunks, setShowChunks] = useState(false); return (
    {!isUser && (
    QAI
    )}
    {isUser ? (

    {message.content}

    ) : (
    )}
    {formatTime(message.timestamp)} {!isUser && message.chunksRetrieved > 0 && ( )}
    {showChunks && message.chunksPreview && (

    Retrieved Context

    {message.chunksPreview.map((chunk, i) => (
    {i + 1}

    {chunk}…

    ))}
    )}
    {isUser && (
    )}
    ); }