ContentPart Each message can have any number of content parts.
Content parts are usually one of text, audio or tool-call.
Additionally, image and file content parts are available, but rarely used, since these are usually included as content parts of message attachments.
Plain text is usually used for user messages.
Markdown text is usually used for assistant messages.
import { ContentPart } from "@assistant/react" ;
< ContentPart.Text /> ;
import { makeMarkdownText } from "@assistant-ui/react-markdown" ;
const MarkdownText = makeMarkdownText () ;
< MarkdownText /> ;
The <Thread />
compoonent allows customization of content part UI in the following ways:
< Thread
tools = { [MyToolUI] }
assistantMessage = {{
components : { Text : MarkdownText , ToolFallback : MyToolFallback }
}}
/>
import { ContentPartPrimitive } from "@assistant/react" ;
< ContentPartPrimitive.Text /> ;
import { MarkdownTextPrimitive } from "@assistant-ui/react-markdown" ;
const MarkdownTextPrimitive = makeMarkdownTextPrimitive () ;
< MarkdownTextPrimitive /> ;
Content part context is provided by MessagePrimitive.Content
or TextContentPartProvider
import { MessagePrimitive } from "@assistant/react" ;
< MessagePrimitive.Content
components = {{
Text : MyText ,
Audio : MyAudio ,
tools : {
by_name : {
get_weather : MyWeatherToolUI ,
},
Fallback : MyFallbackToolUI ,
},
}}
/> ;
This is a helper context provider to allow you to reuse the content part components outside of a message content part.
import { TextContentPartProvider } from "@assistant/react" ;
< TextContentPartProvider text = "Hello world" isRunning = { false } >
< ContentPart.Text />
</ TextContentPartProvider > ;
import { useContentPartRuntime } from "@assistant/react" ;
const contentPartRuntime = 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
import { useContentPart } from "@assistant/react" ;
const contentPart = useContentPart () ;
TextContentPartState status: { readonly type: "running"; } | { readonly type: "complete"; } | { readonly type: "incomplete"; readonly reason: "cancelled" | "length" | "content-filter" | "other" | "error"; readonly error?: unknown; } | { readonly type: "requires-action"; readonly reason: "tool-calls"; }
AudioContentPartState audio: { readonly data: string; readonly format: "mp3" | "wav"; }
status: { readonly type: "running"; } | { readonly type: "complete"; } | { readonly type: "incomplete"; readonly reason: "cancelled" | "length" | "content-filter" | "other" | "error"; readonly error?: unknown; } | { readonly type: "requires-action"; readonly reason: "tool-calls"; }
ImageContentPartState status: { readonly type: "running"; } | { readonly type: "complete"; } | { readonly type: "incomplete"; readonly reason: "cancelled" | "length" | "content-filter" | "other" | "error"; readonly error?: unknown; } | { readonly type: "requires-action"; readonly reason: "tool-calls"; }
UIContentPartState status: { readonly type: "running"; } | { readonly type: "complete"; } | { readonly type: "incomplete"; readonly reason: "cancelled" | "length" | "content-filter" | "other" | "error"; readonly error?: unknown; } | { readonly type: "requires-action"; readonly reason: "tool-calls"; }
ToolCallContentPartState args: Record<string | number, unknown>
isError?: boolean | undefined
status: { readonly type: "running"; } | { readonly type: "complete"; } | { readonly type: "incomplete"; readonly reason: "cancelled" | "length" | "content-filter" | "other" | "error"; readonly error?: unknown; } | { readonly type: "requires-action"; readonly reason: "tool-calls"; }
import { useContentPartText } from "@assistant/react" ;
const contentPartText = useContentPartText () ;
TextContentPartState status: { readonly type: "running"; } | { readonly type: "complete"; } | { readonly type: "incomplete"; readonly reason: "cancelled" | "length" | "content-filter" | "other" | "error"; readonly error?: unknown; } | { readonly type: "requires-action"; readonly reason: "tool-calls"; }