import Markdown from 'react-markdown' import remarkGfm from 'remark-gfm' import { Match } from './mentions_editor'; export default function MarkdownContent({ content, atValues = [], onMentionNavigate, }: { content: string; atValues?: Match[]; onMentionNavigate?: (type: 'agent' | 'tool' | 'prompt', name: string) => void; }) { return
{children}
}, ul({ children }) { return{children}; }, a(props) { const { children, href, className, node, ...rest } = props; // If this is a mention link, render it with mention styling if (href === '#mention') { let label: string = ''; // Check if children is an array and get the first text element if (Array.isArray(children) && children.length > 0) { const text = children[0]; if (typeof text === 'string') { const parts = text.split('@'); if (parts.length === 2) { label = parts[1]; } } } else if (typeof children === 'string') { // Fallback for direct string children const parts = children.split('@'); if (parts.length === 2) { label = parts[1]; } } // Parse type and name for display let displayLabel = label; const typeMatch = label.match(/^(agent|tool|prompt):(.*)$/); let type: 'agent' | 'tool' | 'prompt' | undefined; let name: string | undefined; if (typeMatch) { type = typeMatch[1] as 'agent' | 'tool' | 'prompt'; name = typeMatch[2]; if (type === 'agent') displayLabel = `Agent: ${name}`; else if (type === 'tool') displayLabel = `Tool: ${name}`; else if (type === 'prompt') displayLabel = `Prompt: ${name}`; } // check if the the mention is valid const invalid = !atValues.some(atValue => atValue.id === label); const handleMentionClick = (e: React.MouseEvent) => { if (onMentionNavigate && type && name) { e.preventDefault(); onMentionNavigate(type, name); } }; if (atValues.length > 0 && invalid) { return ( {displayLabel} (!) ); } return ( {displayLabel} ); } // Otherwise render normal link (your existing link component) return {children} }, }} > {content}