Markdown
Render the agent's markdown as it streams in, with code blocks and tables.
Use Markdown for the text of an assistant's reply. Pass the text so far as source, and it parses only the blocks that changed, so a long answer costs no more per chunk than a short one.
Retry with backoff
Wait a little longer after each failure, and give up after a few tries. Retry only idempotent requests.
await sleep(2 ** attempt * 250);| Attempt | Delay |
|---|---|
| 1 | 250 ms |
| 2 | 500 ms |
| 3 | 1 s |
Read the
Retry-Afterheader first when the server sends one.
Installation
npx shadcn@latest add @kind-ui/markdownUsage
Streaming
Set streaming while the reply is still arriving, and pass the whole text each time it grows:
<Markdown source={text} streaming={status === "streaming"} />While it streams, the last block is repaired before it renders, so an unclosed ** or link shows as formatted text instead of flashing its markup. A block is final once more text follows it, and final blocks don't render again. Turn streaming off when the reply ends, and the last block becomes final too.
What It Renders
Markdown follows GitHub Flavored Markdown: headings, paragraphs, emphasis, strikethrough, quotes, lists, task lists, links, images, rules, tables and fenced code. Fenced code renders in a Code Block labeled "Code", and tables in a Markdown Table labeled "Table", each with its own buttons.
Raw HTML shows as text. Links and images keep relative, http, https and mailto URLs; any other URL renders as its text, with no link.
Highlighting
No highlighter ships with Markdown. Pass a highlight function and every code block uses it to color its code; Code Block explains what it returns.
API Reference
Prop
Type
Agent
Markdown has no role, so an agent connected with createAgent sees it by kind, with no name and no actions of its own. The code blocks and tables inside it show up as their own components, with their actions.
Runs in React and Web Components. On <kind-markdown>, source and streaming are attributes, and highlight and engine are properties you set from script.