// src/components/ChatMessage.tsx import React, { useState, useMemo } from 'react' import ReactMarkdown from 'react-markdown' import remarkGfm from 'remark-gfm' import rehypeRaw from 'rehype-raw' import { cn } from '@/lib/utils' import { toast } from '../ui/sonner' interface ChatMessageProps { content: string className?: string } export const ChatMessage: React.FC = ({ content, className, }) => { // Process thinking tags const processedContent = useMemo(() => { // Replace ... tags with a special format const contentWithProcessedThinking = content.replace( /([\s\S]*?)<\/think>/g, (_, thinkContent) => { return `
${thinkContent}
`; } ); // Continue processing source tags as before return contentWithProcessedThinking.replace( //g, (_match, path) => { const filename = path .split('/') .pop()! .replace(/\.[^/.]+$/, '') // embed your ExternalLink SVG inline so you get the icon return ` ${filename} ` } ); }, [content]); return (
href && href.endsWith('.md') ? ( {children} ) : ( {children} ), }} > {processedContent}
) }