assistant-ui/skills

markdown

Renders assistant message text as markdown in assistant-ui.

Voir la source
Document Skill original

Rendu depuis le dépôt source en conservant titres, exemples, code, tableaux, liens et images.

assistant-ui Markdown

Always consult [assistant-ui.com/llms.txt](https://www.assistant-ui.com/llms.txt) for the latest API.

Assistant-ui has two renderers for an assistant text part. MarkdownTextPrimitive is the lightweight react-markdown path and the installed MarkdownText element is its styled implementation. StreamdownTextPrimitive is the alternative when block-aware streaming and optional Shiki, KaTeX, Mermaid, or CJK support are worth the larger renderer.

References

Choose the renderer

Use markdown-text when the app needs a small renderer, a custom react-markdown component map, or per-language SyntaxHighlighter and CodeHeader overrides. Add highlighting, math, and Mermaid only when the message format requires them.

Use StreamdownTextPrimitive when a text part needs block-based streaming, incomplete markdown repair, or the optional code, math, Mermaid, and CJK plugins. It replaces the markdown renderer for that text part. Do not mount both renderers for the same part.

Install and wire MarkdownText

Install the renderer, which lands at components/assistant-ui/elements/markdown-text.tsx.

bash
npx assistant-ui@latest add markdown-text

MarkdownText reads the active message part itself. Render it only in the text branch, while other part kinds keep their own renderers.

tsx
"use client";

import { MessagePrimitive } from "@assistant-ui/react";
import { MarkdownText } from "@/components/assistant-ui/elements/markdown-text";

export function AssistantMessageText() {
  return (
    <MessagePrimitive.Parts>
      {({ part }) => (part.type === "text" ? <MarkdownText /> : null)}
    </MessagePrimitive.Parts>
  );
}

The thread element already includes this renderer. Compose it directly only when replacing the thread's message layout.

Customize the primitive

MarkdownTextPrimitive reads the surrounding text part through context, so it receives no text child or value prop. Its components map controls normal markdown tags plus SyntaxHighlighter and CodeHeader; componentsByLanguage replaces either slot for one fenced language. See markdown-text.md for a direct primitive implementation.

preprocess runs on the full accumulated text before smoothing and parsing. It is the seam for model-specific delimiter repair. smooth defaults to true; defer defaults to false. Set defer for large, rapidly growing messages when React should prioritize input and scrolling over intermediate parses. Keep its value constant while the renderer is mounted because toggling it remounts the parsed tree.

Highlight fenced code

MarkdownText displays fenced code as plain code until a SyntaxHighlighter is registered. Prefer the runtime-aware Shiki element, which waits for its active part to settle before tokenizing.

bash
npx assistant-ui@latest add shiki-highlighter
tsx
import { SyntaxHighlighter } from "@/components/assistant-ui/elements/shiki-highlighter.aui";

const defaultComponents = memoizeMarkdownComponents({
  SyntaxHighlighter,
});

The Prism-based syntax-highlighter element remains useful for apps that already depend on react-syntax-highlighter.

bash
npx assistant-ui@latest add syntax-highlighter
tsx
import { SyntaxHighlighter } from "@/components/assistant-ui/elements/syntax-highlighter";

Edit the installed markdown-text component's default map, or pass a components override where the element is rendered. See syntax-highlighting.md for the exact renderer contracts.

Render math and diagrams

KaTeX needs remark-math, rehype-katex, and the KaTeX stylesheet. The markdown package exports normalizeMathDelimiters, rewriteCustomMathTags, rewriteLatexBracketDelimiters, and escapeCurrencyDollars for preprocessing model output. The helpers rewrite outside inline code and fenced code, so examples in code stay literal.

Install mermaid-diagram and register its .aui renderer as the mermaid language override. It reads the message part status and shows a skeleton while the stream is running rather than parsing incomplete Mermaid source. See latex-mermaid.md.

Use Streamdown instead

StreamdownTextPrimitive reads the same text-part context and can be wired into the same MessagePrimitive.Parts branch. It defaults to mode="streaming", which holds completed blocks stable while the final block grows. Supply optional plugins explicitly, and add Tailwind @source entries for Streamdown and each installed plugin so its controls and caret receive styles.

Both defer and smooth are available here. defer defaults to false and may skip intermediate states under load while still rendering the final text. smooth also defaults to false; use Streamdown's native animated prop for entrance animation unless a typewriter reveal is specifically wanted. The full setup and migration seams are in streamdown.md.

Common Gotchas

Markdown renders as plain text

  • Render MarkdownText or StreamdownTextPrimitive in the text branch. Rendering part.text directly bypasses markdown parsing.

Fenced code has no syntax colors

  • markdown-text includes a label and copy control, but no highlighter. Install and register shiki-highlighter or syntax-highlighter.

Math has unstyled output or prices become math

  • Import katex/dist/katex.min.css once for KaTeX. Compose escapeCurrencyDollars(normalizeMathDelimiters(text)) when messages include both single-dollar math and currency.

Mermaid redraws while a response streams

  • Use @/components/assistant-ui/elements/mermaid-diagram.aui in componentsByLanguage. Its runtime wrapper holds parsing until the message part completes.

Deferred parsing causes a visual reset

  • Do not toggle defer after mount. Both primitives select a different deferred renderer path when that prop changes.

Streamdown controls or caret look unstyled

  • Add the required Tailwind @source directives for streamdown and every installed @streamdown/* plugin.

Related Skills

  • primitives -- compose MessagePrimitive.Parts and the surrounding message UI
  • elements -- install and customize the copied markdown-text, highlighter, and Mermaid element sources
du même dépôt

Autres Skills

Tous les Skills
assistant-ui
Communauté

assistant-ui

Overview and router for assistant-ui, the React library for building AI chat interfaces from composable primitives and a styled elements catalog. Use for high-level, cross-cutting, or architecture questions: choosing packages, picking a runtime, or understanding the layers (elements, primitives, the aui client with AuiConfig and AuiProvider, the runtime, adapters) and the message model. Covers @assistant-ui/react 0.15.x, the framework-neutral @assistant-ui/ai-sdk integration for AI SDK v7 (useChatRuntime, AssistantChatTransport; @assistant-ui/react-ai-sdk re-exports it), @assistant-ui/core, @assistant-ui/store, assistant-stream, assistant-cloud, the adapters for LangGraph, LangChain, Google ADK, A2A, AG-UI, Eve, OpenCode, and Pi, and the platform bindings @assistant-ui/react-native and @assistant-ui/react-ink; AssistantRuntimeProvider; the primitives ThreadPrimitive, MessagePrimitive, ComposerPrimitive; the hooks useAui, useAuiState, useAuiEvent; and runtime selection across useChatRuntime, useExternalStoreRuntime, useLangGraphRuntime, useLocalRuntime. For a specific area route to a focused sibling instead: setup, elements, primitives, runtime, tools, generative-ui, streaming, cloud, thread-list, copilots, markdown, react-mcp, observability, react-native, ink, or update.

installations
1
GitHub Stars
26
Mis à jour
4 sept.
assistant-ui
Communauté

cloud

Adds AssistantCloud backed persistence, authorization, and telemetry to assistant-ui apps. Use when wiring cross-session thread and message history, multi-device chat, message feedback, file uploads, or auth: passing cloud to useChatRuntime from @assistant-ui/ai-sdk, AISDKThreads({ cloud }) for AuiConfig hosts, the standalone useCloudChat/useThreads hooks from @assistant-ui/cloud-ai-sdk, or cloud on useLangGraphRuntime. Covers constructing AssistantCloud with authToken (JWT), apiKey plus userId/workspaceId (server-side), or anonymous; direct provider integrations (Clerk, Auth0, Supabase, Firebase) and a backend token endpoint; and the client surface verified against source: cloud.threads.{list,get,create,update,delete}, cloud.threads.messages.{list,create,update,feedback}, cloud.files.{generatePresignedUploadUrl,pdfToImages}, cloud.runs.{stream,report}, cloud.projects.threads, cloud.auth.tokens.create, and cloud.telemetry. Also covers a custom ThreadHistoryAdapter built on CloudMessagePersistence/createFormattedPersistence, run telemetry (beforeReport, sub-agent tracking with wrapSamplingHandler), and the NEXTPUBLICASSISTANTBASEURL/ASSISTANTAPIKEY env vars. Route here for threads that do not persist, 401s against the cloud API, or feedback buttons that do not save. For the sidebar UI itself use thread-list; for the general RemoteThreadListAdapter/ThreadHistoryAdapter contract use runtime.

installations
1
GitHub Stars
26
Mis à jour
4 sept.
assistant-ui
Communauté

copilots

Grounding an assistant in your app with assistant-ui copilots (@assistant-ui/react). Use when steering assistant behavior with useAssistantInstructions, feeding lazy send-time app state through useAssistantContext({ getContext }), exposing rendered components to the assistant with makeAssistantVisible(Component, { clickable, editable }), giving the model two-way component state through interactables (unstableuseInteractable for app-scoped panels, unstableinteractableTool inside defineToolkit for thread-scoped artifacts, both mounted via AuiConfig({ unstableinteractables: unstableInteractables() })), registering instructions and tools together imperatively with aui.modelContext.register({ getModelContext }), or bridging model context across an iframe boundary with AssistantFrameProvider and useAssistantFrameHost. The legacy Interactables() scope, useAssistantInteractable, and useInteractableState are deprecated since 2026-06-14 and scheduled for removal on or after 2026-09-14; new code uses the unstable API. Reach for this when the assistant should read the current page, click or edit UI, read and update component state through auto-generated update{name} tools, or receive tools and instructions from a sandboxed iframe. For LLM tools and tool-call UI use the tools skill; for runtime and thread state use the runtime skill.

installations
1
GitHub Stars
26
Mis à jour
4 sept.
assistant-ui
Communauté

elements

Installs and customizes assistant-ui elements, the styled shadcn-style component catalog at assistant-ui.com/elements served from the r.assistant-ui.com registry through npx assistant-ui@latest add . Use when adding a prebuilt chat surface or widget (Thread, ThreadList, AssistantModal, AssistantSidebar, ToolFallback, ToolGroup, MarkdownText, Reasoning, Sources, Attachment, ModelSelector, Voice orb, McpConfig) or one of the 120 standalone elements (approval card, agent plan, code diff, data table, chart, trace waterfall, message queue, composer variants, and so on), choosing between runtime-connected .aui.tsx files and props-driven standalone files, overriding Thread slots through the components prop, editing the copied source under components/assistant-ui/elements/, using the shared surfaces.tsx tokens, or picking the Radix versus Base UI flavor through the style-aware registry URL in components.json. Route here when an import from @/components/assistant-ui/... fails, an element renders unstyled, or the CLI installs the wrong flavor. For unstyled building blocks use primitives; for the CLI scaffold itself use setup.

installations
1
GitHub Stars
26
Mis à jour
4 sept.