import React, { useMemo, useState, useEffect } from 'react'; import MDEditor from '@uiw/react-md-editor'; import remarkMath from 'remark-math'; import rehypeKatex from 'rehype-katex'; import katex from 'katex'; import 'katex/dist/katex.css'; import { MCPClient } from '../mcp/client'; /** * Custom Code component that handles: * - Language "katex" or "math": live KaTeX math display * - Language "svg": live SVG rendering * - Standard code blocks with syntax highlighting */ const CodeRenderer = ({ node, className, children, ...props }) => { const codeString = String(children || '').replace(/\n$/, ''); const match = /language-(\w+)/.exec(className || ''); const language = match ? match[1].toLowerCase() : ''; if (language === 'katex' || language === 'math') { try { const html = katex.renderToString(codeString, { displayMode: true, throwOnError: false, strict: false }); return (
); } catch (err) { return (Failed to render KaTeX: {err.message}
{children}
);
};
/**
* Custom Image component that safely renders SVGs and normal images
*/
const ImageRenderer = ({ node, src, alt, ...props }) => {
const isSvg = src && (src.endsWith('.svg') || src.includes('.svg?') || src.startsWith('data:image/svg+xml'));
return (