import React from "react"; import { Button } from "@/components/ui/button"; import { ClipboardCopy } from "lucide-react"; import { toast } from "sonner"; import { MessageProps } from "../types"; import ReactMarkdown from "react-markdown"; import { Prism as SyntaxHighlighter } from "react-syntax-highlighter"; import { oneDark } from "react-syntax-highlighter/dist/esm/styles/prism"; import remarkMath from "remark-math"; import rehypeKatex from "rehype-katex"; import remarkGfm from "remark-gfm"; import { Badge } from "@/components/ui/badge"; import "katex/dist/katex.min.css"; export const AIMessageComponent = React.memo(({ message }: MessageProps) => { const handleCopy = React.useCallback(() => { const content = String(message.content); navigator.clipboard.writeText(content) .then(() => toast.success("Response copied to clipboard")) .catch(() => toast.error("Failed to copy response")); }, [message.content]); return (
; }, h1(props) { return

; }, h2(props) { return

; }, h3(props) { return

; }, h4(props) { return

; }, code(props) { const {children, className, ...rest} = props; const match = /language-(\w+)/.exec(className || ''); const language = match ? match[1] : ''; const code = String(children).replace(/\n$/, ''); const copyToClipboard = () => { navigator.clipboard.writeText(code); toast.success("Code copied to clipboard"); }; return match ? (
{language && ( {language} )}
{code}
) : ( {children} ); }, a(props) { return ; }, table(props) { return
; }, th(props) { return
; }, td(props) { return ; }, blockquote(props) { return
; }, ul(props) { return
    ; }, ol(props) { return
      ; }, li(props) { return
    1. ; }, hr(props) { return
      ; } }} > {String(message.content)}
      ); }); AIMessageComponent.displayName = "AIMessageComponent";