import React from 'react' import ReactMarkdown from 'react-markdown' import remarkGfm from 'remark-gfm' import rehypeHighlight from 'rehype-highlight' import rehypeRaw from 'rehype-raw' import { Copy, Check } from 'lucide-react' import type { components } from '@/api/opencode-types' import 'highlight.js/styles/github-dark.css' type TextPart = components['schemas']['TextPart'] interface TextPartProps { part: TextPart } interface CodeBlockProps { children?: React.ReactNode className?: string [key: string]: unknown } function CodeBlock({ children, className, ...props }: CodeBlockProps) { const [copied, setCopied] = React.useState(false) const extractTextContent = (node: React.ReactNode): string => { if (typeof node === 'string') return node if (typeof node === 'number') return node.toString() if (Array.isArray(node)) return node.map(extractTextContent).join('') if (React.isValidElement(node)) { const element = node as React.ReactElement> if (element.props.children) { return extractTextContent(element.props.children as React.ReactNode) } } return '' } const codeContent = extractTextContent(children) const handleCopyCode = async () => { try { await navigator.clipboard.writeText(codeContent) setCopied(true) setTimeout(() => setCopied(false), 2000) } catch (error) { console.error('Failed to copy code:', error) } } return (
        {children}
      
) } export function TextPart({ part }: TextPartProps) { if (!part.text || part.text.trim() === '') { return (
[Empty message content]
) } return (
{children} ) } return ( {children} ) }, pre({ children }) { return ( {children} ) }, p({ children }) { return

{children}

}, strong({ children }) { return {children} }, ul({ children }) { return
    {children}
}, ol({ children }) { return
    {children}
}, li({ children }) { return
  • {children}
  • } }} > {part.text}
    ) }