// src/AssistantMessage.jsx import React, { useState } from "react"; import ReactMarkdown from "react-markdown"; import remarkGfm from "remark-gfm"; import remarkMath from "remark-math"; import rehypeKatex from "rehype-katex"; export default function AssistantMessage({ content, theme, timestamp }) { return (
( ), th: (props) =>
, code: CodeWithCopy }} > {content} {timestamp && (
{formatDateTime(timestamp)}
)} ); } function CodeWithCopy({ inline, className = "", children, ...props }) { const [copied, setCopied] = useState(false); const codeText = String(children).replace(/\n$/, ""); // Only show copy button for fenced code with language const isFencedBlock = !inline && /^language-/.test(className); if (!isFencedBlock) { return ( {children} ); } const handleCopy = async () => { try { await navigator.clipboard.writeText(codeText); setCopied(true); setTimeout(() => setCopied(false), 1500); } catch (err) { console.error("Copy failed", err); } }; return (
        {codeText}
      
{copied && ( Copied! )}
); } // Utility to format timestamp nicely function formatDateTime(dateTime) { try { const date = new Date(dateTime); return date.toLocaleString(undefined, { year: "numeric", month: "short", day: "numeric", hour: "2-digit", minute: "2-digit", second: "2-digit" }); } catch { return dateTime; } }