Messages and code
The renderers the thread draws text with, for a message, a note or a block of output outside it.
import { Markdown, MessageMarkdown, ReplyMarkdown } from '@adecore/agents-react/chat/ui';import { Markdown, MessageMarkdown, ReplyMarkdown } from '@adecore/agents-react/chat/ui';
const REPLY = `The retry lives in \`fetchJson\`:
\`\`\`ts
await wait(250 * 2 ** attempt);
\`\`\`
| Status | Retried |
| --- | --- |
| 503 | Yes |
| 404 | No |`;
export default function MarkdownDemo() {
return (
<div className="flex w-full max-w-xl flex-col gap-4">
<MessageMarkdown text={'Review @src/http.ts with $review\nand keep the <Reading> type.'} mentions={['src/http.ts']} skills={['review']} />
<ReplyMarkdown text={REPLY} streaming={false} />
<Markdown text={'A note from the app,\nwith the line break kept.'} breaks fileLinks={false} />
</div>
);
}Markdown
Three renderers of GitHub-flavored Markdown with the typography plugin's prose styles. None renders raw HTML.
MessageMarkdown({ text, mentions?, skills? })draws what a person sent. Line breaks stay, a typed tag stays text, and picked files and skills become chips.ReplyMarkdown({ text, streaming, arriving? })draws a reply, parsing one block at a time. Whilestreaming, new words fade in and an open code fence highlights as it grows;arrivingfades in whole blocks instead.- The rows of a reply read the CLI and chat they belong to (
{ provider, chatId? }) from the reply they are in; a subagent's conversation sets its own. Markdown({ text, breaks?, fileLinks?, muted?, rehypePlugins?, componentOverrides? })draws any other text.breakskeeps line breaks,fileLinks(on by default) links paths through the host'sfileLinks, andmuteddims the text like a thought.
A path becomes a link when the host's fileLinks.target(text, cwd) finds one. FileLinkContext sets the folder for relative paths; the thread sets it to the chat's cwd.
CodeBlock
A fenced block, highlighted with Shiki in the theme of the host's code. The block keeps its size while the grammar loads. An unknown language stays plain text.
import { CodeBlock } from '@adecore/agents-react/chat/ui';
const CODE = `export async function fetchJson<T>(url: string, attempts = 3): Promise<T> {
for (let attempt = 1; ; attempt++) {
const response = await fetch(url);
if (response.ok) {
return response.json() as Promise<T>;
}
}
}`;
export default function CodeBlockDemo() {
return (
<div className="w-full max-w-xl">
<CodeBlock code={CODE} lang="ts" />
</div>
);
}<CodeBlock code={source} lang="ts" />useCodeTheme() returns the theme id in use. CodeStreamingContext marks a fence as still open; ReplyMarkdown sets it.
view replaces the code inside the same frame, such as with what the code draws, while Copy still copies code.
The controls show on hover or focus, and always without hover. The optional actions node adds your own controls beside Copy. In the chat's own replies, the host's shell action goes there.
Mermaid diagrams
Pele (MIT) draws a ```mermaid fence as a diagram, and reads Mermaid 12.1 syntax. Pele loads lazily with the first closed fence. An open fence shows its source; text Pele cannot draw stays source with a note.
A button beside Copy switches between diagram and source; Copy copies the source either way. The diagram uses the theme's tokens and follows theme changes.
The drawing is an SVG data: image without links, images or scripts. A Content Security Policy needs data: in img-src, and no 'unsafe-eval'.
AnsiOutput and FadingWords
AnsiOutput({ text, limit?, tailLines? }) draws command output with its colors, bold, italics and underlines, and drops other control sequences. tailLines keeps the last lines and limit the first characters, with a line saying how much was left out. The colors come from the --term-ansi-* tokens; see CSS.
FadingWords({ text }) fades in each word as text grows.
import { AnsiOutput, FadingWords } from '@adecore/agents-react/chat/ui';
import { ScrollArea } from '@adecore/ui';
import { useEffect, useState } from 'react';
const OUTPUT =
'\u001b[1mbun test\u001b[0m v1.2.0\n\u001b[32m✓\u001b[0m returns the parsed body\n\u001b[32m✓\u001b[0m retries a 503 twice\n\u001b[31m✗\u001b[0m throws on a 404 at once\n\n \u001b[32m2 pass\u001b[0m\n \u001b[31m1 fail\u001b[0m';
const SENTENCE = 'Each word fades in as it arrives, the way a streamed reply does.';
export default function AnsiOutputDemo() {
const [shown, setShown] = useState(0);
const words = SENTENCE.split(' ');
useEffect(() => {
const timer = setInterval(() => setShown((count) => (count >= words.length + 6 ? 0 : count + 1)), 180);
return () => clearInterval(timer);
}, [words.length]);
return (
<div className="flex w-full max-w-xl flex-col gap-4">
<ScrollArea axis="x" render={<pre />} className="rounded-md bg-surface-sunken" viewportClassName="px-3 py-2 font-mono text-xs whitespace-pre-wrap">
<AnsiOutput text={OUTPUT} />
</ScrollArea>
<p className="min-h-6 text-sm">
<FadingWords text={words.slice(0, shown).join(' ')} />
</p>
</div>
);
}parseAnsi(text, options) and stripAnsi(text) are the parser alone. wordSegments, rehypeFadeWords, rehypeChips and remarkHtmlAsText are the renderers' plugins. splitMarkdownBlocks splits text into MarkdownBlocks as ReplyMarkdown does; a top-level fence carries a MarkdownFence with its marker, info string and body.