'use client'; import { Button } from '@shadcn/ui/button'; import { cn } from '@shadcn/ui/lib/utils'; import 'katex/dist/katex.min.css'; import { Check, Copy } from 'lucide-react'; import { useCallback, useState } from 'react'; import ReactMarkdown, { Components } from 'react-markdown'; import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'; import { oneDark } from 'react-syntax-highlighter/dist/esm/styles/prism'; import rehypeKatex from 'rehype-katex'; import rehypeRaw from 'rehype-raw'; import remarkGfm from 'remark-gfm'; import remarkMath from 'remark-math'; import remarkToc from 'remark-toc'; interface CodeBlockProps { className?: string; children?: React.ReactNode; [key: string]: unknown; } function CodeBlock({ className, children, ...props }: CodeBlockProps) { const [copied, setCopied] = useState(false); const match = className?.startsWith('language-') ? /language-(\w+)/.exec(className) : null; const handleCopy = useCallback((text: string) => { navigator.clipboard .writeText(text) .then(() => { setCopied(true); setTimeout(() => setCopied(false), 3000); }) .catch(() => { alert('Failed to copy text. Please try again.'); }); }, []); if (match) { return (
{match[1]}
{String(children).replace(/\n$/, '')}
); } return ( {children} ); } interface MarkdownProps { children: string; components?: Components; } export function Markdown({ children, components }: MarkdownProps) { return ( (

), h2: ({ node, className, ...props }) => (

), h3: ({ node, className, ...props }) => (

), h4: ({ node, className, ...props }) => (

), h5: ({ node, className, ...props }) => (

), h6: ({ node, className, ...props }) => (
), p: ({ node, className, ...props }) => (

), a: ({ node, className, ...props }) => ( ), blockquote: ({ node, className, ...props }) => (

), ul: ({ node, className, ...props }) => (
    li]:mt-2', className)} {...props} /> ), ol: ({ node, className, ...props }) => (
      li]:mt-2', className)} {...props} /> ), hr: ({ node, className, ...props }) => (
      ), table: ({ node, className, ...props }) => ( ), th: ({ node, className, ...props }) => ( td:first-child]:rounded-bl-lg [&:last-child>td:last-child]:rounded-br-lg', className, )} {...props} /> ), sup: ({ node, className, ...props }) => ( a]:text-xs [&>a]:no-underline', className)} {...props} /> ), pre: ({ node, className, ...props }) => (
              ),
              code(props) {
                return ;
              },
              ...components,
            }}
          >
            {children}
          
        );
      }
      
      ), td: ({ node, className, ...props }) => ( ), tr: ({ node, className, ...props }) => (