/** * Markdown renders agent text (GitHub-flavoured: tables, task lists, ...). * Kept as the single markdown entry point so styling and plugins stay * consistent everywhere agent content appears. * * @example * */ import ReactMarkdown from "react-markdown"; import remarkGfm from "remark-gfm"; import type { Components } from "react-markdown"; import { CopyButton } from "./CopyButton"; export function Markdown({ text }: { text: string }) { const components: Components = { pre: ({ children, ...props }) => { // Extract code content from pre > code structure // react-markdown hands `pre` its rendered child; type its props so // the string body can be extracted for the copy button. const codeElement = children as React.ReactElement<{ children?: unknown; }>; const codeContent = codeElement?.props?.children && typeof codeElement.props.children === "string" ? codeElement.props.children : ""; return (
{codeContent && ( )}
{children}
); }, }; return (
{text}
); }