Radix UI Primitives
ContentPart
Each message can have any number of content parts.
Content parts are usually one of text, audio or tool-call.
Anatomy
Primitives
Plain Text
Markdown Text
Renders the message's text as Markdown.
Audio
Coming soon.
InProgress
Renders children only if the content part is in progress.
Tool UI
You can map tool calls to UI components. We provide a few utility functions to make this easier, such as makeAssistantToolUI
.
Context Provider
Content part context is provided by MessagePrimitive.Content
or TextContentPartProvider
MessagePrimitive.Content
TextContentPartProvider
This is a helper context provider to allow you to reuse the content part components outside a message content part.
Runtime API
useContentPartRuntime
ContentPartRuntime
addToolResult:
(result: any) => void
Add tool result to a tool call content part that has no tool result yet. This is useful when you are collecting a tool result via user input ("human tool calls").
path:
ContentPartRuntimePath
getState:
() => ContentPartState
subscribe:
(callback: () => void) => Unsubscribe
useContentPart
TextContentPartState
type:
"text"
text:
string
status:
{ readonly type: "running"; } | { readonly type: "complete"; } | { readonly type: "incomplete"; readonly reason: "length" | "cancelled" | "content-filter" | "other" | "error"; readonly error?: unknown; } | { readonly type: "requires-action"; readonly reason: "tool-calls"; }
AudioContentPartState
type:
"audio"
audio:
{ readonly data: string; readonly format: "mp3" | "wav"; }
status:
{ readonly type: "running"; } | { readonly type: "complete"; } | { readonly type: "incomplete"; readonly reason: "length" | "cancelled" | "content-filter" | "other" | "error"; readonly error?: unknown; } | { readonly type: "requires-action"; readonly reason: "tool-calls"; }
ToolCallContentPartState
type:
"tool-call"
toolCallId:
string
toolName:
string
args:
ReadonlyJSONObject
result?:
unknown
isError?:
boolean | undefined
argsText:
string
status:
{ readonly type: "running"; } | { readonly type: "complete"; } | { readonly type: "incomplete"; readonly reason: "length" | "cancelled" | "content-filter" | "other" | "error"; readonly error?: unknown; } | { readonly type: "requires-action"; readonly reason: "tool-calls"; }
useContentPartText
TextContentPartState
type:
"text"
text:
string
status:
{ readonly type: "running"; } | { readonly type: "complete"; } | { readonly type: "incomplete"; readonly reason: "length" | "cancelled" | "content-filter" | "other" | "error"; readonly error?: unknown; } | { readonly type: "requires-action"; readonly reason: "tool-calls"; }