import type { ComponentProps } from 'react' import Markdown, { type Components, type ExtraProps } from 'react-markdown' import { viewerBus } from './viewerBus' // The agent's answer as Markdown. Only `paper:` and `https:` links survive; `paper:` links // (I4: the agent writes `[Title](paper:pmid:1)`) become buttons that focus this viewer's canvas. // Raw HTML is shown as text (react-markdown's default without rehype-raw), images are dropped. const keepSafeUrls = (url: string, key: string) => (key === 'href' && /^(paper|https):/i.test(url) ? url : null) function Link({ href, children }: ComponentProps<'a'> & ExtraProps) { if (href && /^paper:/i.test(href)) { const paperId = decode(href.slice('paper:'.length)) return ( ) } if (href) { return ( {children} ) } return {children} } const components: Components = { a: Link } export function AgentMessage({ text }: { text: string }) { return (
{text}
) } function decode(s: string) { try { return decodeURIComponent(s) } catch { return s } }