Root React provider that connects an assistant-ui runtime to primitives, hooks, threads, and composer state.
API Reference
AssistantRuntimeProvider
import { AssistantRuntimeProvider } from "@assistant-ui/react";
import { useChatRuntime, AssistantChatTransport } from "@assistant-ui/react-ai-sdk";
const MyApp = () => {
const runtime = useChatRuntime({
transport: new AssistantChatTransport({
api: "/api/chat",
}),
});
return (
<AssistantRuntimeProvider runtime={runtime}>
{/* your app */}
</AssistantRuntimeProvider>
);
};AssistantRuntimeProviderruntime: AssistantRuntimeThe assistant runtime to expose to descendants. Build one with `useLocalRuntime`, `useExternalStoreRuntime`, or `useAssistantTransportRuntime`.
threads: ThreadListRuntimeThe threads in this assistant.
getState: () => ThreadListStatesubscribe: (callback: () => void) => Unsubscribemain: ThreadRuntimepath: ThreadRuntimePathThe selector for the thread runtime.
composer: ThreadComposerRuntimeThe thread composer runtime.
getState: () => ThreadStateGets a snapshot of the thread state.
append: (message: CreateAppendMessage) => voidAppend a new message to the thread.
startRun: (config: CreateStartRunConfig) => voidStart a new run with the given configuration.
resumeRun: (config: CreateResumeRunConfig) => voidResume a run with the given configuration.
exportExternalState: () => anyExport the thread state in the external store format. For AI SDK runtimes, this returns the AI SDK message format. For other runtimes, this may return different formats or throw an error.
importExternalState: (state: any) => voidImport thread state from the external store format. For AI SDK runtimes, this accepts AI SDK messages. For other runtimes, this may accept different formats or throw an error.
subscribe: (callback: () => void) => UnsubscribecancelRun: () => voidgetModelContext: () => ModelContextexport: () => ExportedMessageRepositoryimport: (repository: ExportedMessageRepository) => voidreset: (initialMessages?: readonly ThreadMessageLike[]) => voidReset the thread with optional initial messages.
getMessageByIndex: (idx: number) => MessageRuntimegetMessageById: (messageId: string) => MessageRuntimestopSpeakingdeprecated: () => voidDeprecated: This API is still under active development and might change without notice.
connectVoice: () => voiddisconnectVoice: () => voidgetVoiceVolume: () => numbersubscribeVoiceVolume: (callback: () => void) => UnsubscribemuteVoice: () => voidunmuteVoice: () => voidunstable_onunstable: <E extends ThreadRuntimeEventType>(event: E, callback: ThreadRuntimeEventCallback<E>) => Unsubscribe
getById: (threadId: string) => ThreadRuntimemainItem: ThreadListItemRuntimepath: ThreadListItemRuntimePathgetState: () => ThreadListItemStateinitialize: () => Promise<{ remoteId: string; externalId: string | undefined; }>generateTitle: () => Promise<void>switchTo: (options?: { unarchive?: boolean; }) => Promise<void>rename: (newTitle: string) => Promise<void>archive: () => Promise<void>unarchive: () => Promise<void>delete: () => Promise<void>detach: () => voidsubscribe: (callback: () => void) => Unsubscribeunstable_onunstable: <E extends ThreadListItemEventType>(event: E, callback: ThreadListItemEventCallback<E>) => Unsubscribe
getItemById: (threadId: string) => ThreadListItemRuntimegetItemByIndex: (idx: number) => ThreadListItemRuntimegetArchivedItemByIndex: (idx: number) => ThreadListItemRuntimeswitchToThread: (threadId: string, options?: { unarchive?: boolean; }) => Promise<void>switchToNewThread: () => Promise<void>getLoadThreadsPromise: () => Promise<void>reload: () => Promise<void>loadMore: () => Promise<void>
thread: ThreadRuntimeThe currently selected main thread. Equivalent to `threads.main`.
path: ThreadRuntimePathThe selector for the thread runtime.
ref: stringthreadSelector: { readonly type: "main" } | { readonly type: "threadId"; readonly threadId: string; }
composer: ThreadComposerRuntimeThe thread composer runtime.
path: ComposerRuntimePathtype: "edit" | "thread"addAttachment: (fileOrAttachment: File | CreateAttachment) => Promise<void>Add an attachment to the composer. Accepts either a standard File object (processed through the AttachmentAdapter) or a CreateAttachment descriptor for external-source attachments (URLs, API data, CMS references). External descriptors bypass the adapter's `add()` step but still respect `adapter.accept` when an adapter is configured; without an adapter they are added as-is.
setText: (text: string) => voidSet the text of the composer.
setRole: (role: MessageRole) => voidSet the role of the composer. For instance, if you'd like a specific message to have the 'assistant' role, you can do so here.
setRunConfig: (runConfig: RunConfig) => voidSet the run config of the composer. This is used to send custom configuration data to the model. Within your backend, you can use the `runConfig` object. Example: ```ts composerRuntime.setRunConfig({ custom: { customField: "customValue" } }); ```
reset: () => Promise<void>Reset the composer. This will clear the entire state of the composer, including all text and attachments.
clearAttachments: () => Promise<void>Clear all attachments from the composer.
send: (options?: SendOptions) => voidSend a message. This will send whatever text or attachments are in the composer.
cancel: () => voidCancel the current run. In edit mode, this will exit edit mode.
subscribe: (callback: () => void) => UnsubscribeListens for changes to the composer state.
startDictation: () => voidStart dictation to convert voice to text input. Requires a DictationAdapter to be configured.
stopDictation: () => voidStop the current dictation session.
setQuote: (quote: QuoteInfo | undefined) => voidSet a quote for the next message. Pass undefined to clear.
unstable_ondeprecatedunstable: <E extends ComposerRuntimeEventType>(event: E, callback: ComposerRuntimeEventCallback<E>) => UnsubscribeDeprecated: This API is still under active development and might change without notice.
getState: () => ThreadComposerStategetAttachmentByIndex: (idx: number) => AttachmentRuntime & { source: "thread-composer"; }
getState: () => ThreadStateGets a snapshot of the thread state.
append: (message: CreateAppendMessage) => voidAppend a new message to the thread.
startRun: (config: CreateStartRunConfig) => voidStart a new run with the given configuration.
resumeRun: (config: CreateResumeRunConfig) => voidResume a run with the given configuration.
exportExternalState: () => anyExport the thread state in the external store format. For AI SDK runtimes, this returns the AI SDK message format. For other runtimes, this may return different formats or throw an error.
importExternalState: (state: any) => voidImport thread state from the external store format. For AI SDK runtimes, this accepts AI SDK messages. For other runtimes, this may accept different formats or throw an error.
subscribe: (callback: () => void) => UnsubscribecancelRun: () => voidgetModelContext: () => ModelContextexport: () => ExportedMessageRepositoryimport: (repository: ExportedMessageRepository) => voidreset: (initialMessages?: readonly ThreadMessageLike[]) => voidReset the thread with optional initial messages.
getMessageByIndex: (idx: number) => MessageRuntimegetMessageById: (messageId: string) => MessageRuntimestopSpeakingdeprecated: () => voidDeprecated: This API is still under active development and might change without notice.
connectVoice: () => voiddisconnectVoice: () => voidgetVoiceVolume: () => numbersubscribeVoiceVolume: (callback: () => void) => UnsubscribemuteVoice: () => voidunmuteVoice: () => voidunstable_onunstable: <E extends ThreadRuntimeEventType>(event: E, callback: ThreadRuntimeEventCallback<E>) => Unsubscribe
registerModelContextProvider: (provider: ModelContextProvider) => UnsubscribeRegister a model context provider. Model context providers are configuration such as system message, temperature, etc. that are set in the frontend.
aui?: AssistantClientOptional parent `AssistantClient` whose scopes are inherited by the client created for this runtime. Use this when nesting an `AssistantRuntimeProvider` inside another assistant context. Omit this prop when there is no parent client.
thread: AssistantClientAccessor<"thread">message: AssistantClientAccessor<"message">threads: AssistantClientAccessor<"threads">threadListItem: AssistantClientAccessor<"threadListItem">part: AssistantClientAccessor<"part">composer: AssistantClientAccessor<"composer">attachment: AssistantClientAccessor<"attachment">modelContext: AssistantClientAccessor<"modelContext">suggestions: AssistantClientAccessor<"suggestions">suggestion: AssistantClientAccessor<"suggestion">chainOfThought: AssistantClientAccessor<"chainOfThought">queueItem: AssistantClientAccessor<"queueItem">tools: AssistantClientAccessor<"tools">dataRenderers: AssistantClientAccessor<"dataRenderers">interactables: AssistantClientAccessor<"interactables">subscribe: (listener: () => void) => Unsubscribeon: <TEvent extends AssistantEventName>(selector: AssistantEventSelector<TEvent>, callback: AssistantEventCallback<TEvent>) => Unsubscribe
AuiProvider
Supplies an AssistantClient to the React tree.
Place near the root of any subtree that uses useAui or the
primitives built on it. Components rendered outside an AuiProvider
receive a default client whose scope accessors throw on use, so
missing-provider mistakes surface at the point of use.
When mounting a runtime built with one of the runtime hooks, use
AssistantRuntimeProvider — it installs an AuiProvider
internally — rather than wiring AuiProvider yourself.
function ScopedAssistant({ children, scopes }) {
const aui = useAui(scopes);
return <AuiProvider value={aui}>{children}</AuiProvider>;
}AuiProvider propsvalue: AssistantClientAssistant client to expose to descendants.
thread: AssistantClientAccessor<"thread">message: AssistantClientAccessor<"message">threads: AssistantClientAccessor<"threads">threadListItem: AssistantClientAccessor<"threadListItem">part: AssistantClientAccessor<"part">composer: AssistantClientAccessor<"composer">attachment: AssistantClientAccessor<"attachment">modelContext: AssistantClientAccessor<"modelContext">suggestions: AssistantClientAccessor<"suggestions">suggestion: AssistantClientAccessor<"suggestion">chainOfThought: AssistantClientAccessor<"chainOfThought">queueItem: AssistantClientAccessor<"queueItem">tools: AssistantClientAccessor<"tools">dataRenderers: AssistantClientAccessor<"dataRenderers">interactables: AssistantClientAccessor<"interactables">subscribe: (listener: () => void) => Unsubscribeon: <TEvent extends AssistantEventName>(selector: AssistantEventSelector<TEvent>, callback: AssistantEventCallback<TEvent>) => Unsubscribe
children?: React.ReactNodeSubtree that may read from the client.