Runtime API
The runtime API allows you to interact with the runtime in a standardized way. This API is used internaly by the components. You can also use it to build your own UI components or functionality.
AssistantRuntime
The AssistantRuntime
is the root runtime.
useAssistantRuntime
AssistantRuntime
thread:
The currently selected main thread.
threadList:
The thread manager, to rename, archive and delete threads.
switchToNewThread:
Switch to a new thread.
switchToThread:
Switch to a thread.
registerModelConfigProvider:
Register a model config provider. Model config providers are configuration such as system message, temperature, etc. that are set in the frontend.
Tool UI Registry
The tool UI registry is used to display custom UI for tool calls, enabling generative UI.
useToolUIs
AssistantToolUIsState
getToolUI:
Get the tool UI configured for a given tool name.
setToolUI:
Registers a tool UI for a given tool name. Returns an unsubscribe function to remove the tool UI.
ThreadListRuntime
threadList
ThreadListRuntime
getState:
subscribe:
getThreadListItemById:
getThreadListItemByIndex:
getThreadListArchivedItemByIndex:
useThreadList
ThreadListItemRuntime
useThreadListItemRuntime
ThreadListItemRuntime
path:
getState:
switchTo:
rename:
archive:
unarchive:
delete:
subscribe:
useThreadListItem
ThreadListItemState
threadId:
state:
title?:
isMain:
Thread Context
useThreadRuntime
ThreadRuntime
path:
The selector for the thread runtime.
composer:
The thread composer runtime.
getState:
Gets a snapshot of the thread state.
append:
Append a new message to the thread.
startRun:
subscribe:
cancelRun:
getModelConfig:
export:
import:
getMesssageByIndex:
getMesssageById:
stopSpeaking:
unstable_on:
useThread
ThreadState
threadId:
The thread ID.
metadata:
The thread metadata.
isDisabled:
Whether the thread is disabled. Disabled threads cannot receive new messages.
isRunning:
Whether the thread is running. A thread is considered running when there is an active stream connection to the backend.
capabilities:
The capabilities of the thread, such as whether the thread supports editing, branch switching, etc.
messages:
The messages in the currently selected branch of the thread.
suggestions:
Follow up message suggestions to show the user.
extras:
Custom extra information provided by the runtime.
speech:
useThreadMessages
ThreadMessagesState
messages:
The messages in the thread.
useThreadComposer
ComposerState
text:
The current text of the composer.
setText:
A function to set the text of the composer.
attachments:
The current attachments of the composer.
addAttachment:
A function to add an attachment to the composer.
removeAttachment:
A function to remove an attachment from the composer.
reset:
A function to reset the composer.
canCancel:
Whether the composer can be canceled.
isEditing:
Whether the composer is in edit mode.
send:
A function to send the message.
cancel:
A function to cancel the run.
focus:
A function to focus the composer.
onFocus:
A function to subscribe to focus events.
useThreadViewport
ThreadViewportState
isAtBottom:
Whether the thread is at the bottom.
scrollToBottom:
A function to scroll to the bottom.
onScrollToBottom:
A function to subscribe to scroll to bottom events.
Message Context
useMessage
MessageState
message:
The current message.
parentId:
The parent message id.
branches:
The branches for the message.
isLast:
Whether the message is the last in the thread.
useMessageUtils
MessageUtilsState
isCopied:
Whether the message is copied.
setIsCopied:
A function to set the is copied.
isHovering:
Whether the message is being hovered.
setIsHovering:
A function to set the is hovering.
isSpeaking:
Whether the message is currently being spoken.
stopSpeaking:
A function to stop the message from being spoken.
addUtterance:
A function to add a speech utterance.
useEditComposer
EditComposerState
text:
The current text of the composer.
setText:
A function to set the text of the composer.
attachments:
The current attachments of the composer.
addAttachment:
A function to add an attachment to the composer.
removeAttachment:
A function to remove an attachment from the composer.
reset:
A function to reset the composer.
canCancel:
Whether the composer can be canceled.
isEditing:
Whether the composer is in edit mode.
edit:
A function to enter edit mode.
send:
A function to send the message.
cancel:
A function to exit the edit mode.
Content Part Context
useContentPart
ContentPartState
part:
The current content part.
status:
The current content part status.
MessageStatus
type:
The status.
finish-reason?:
The finish reason if the status is 'incomplete'.
error?:
The error object if the status is 'error'.
Composer Context
Grabs the nearest composer state (either the edit composer or the thread's new message composer).
useComposer
Attachment Context
Grabs the attachment state (either the composer or message attachment).
useAttachment
useComposerAttachment
(Composer)
ComposerAttachmentState
attachment:
The current composer attachment.
useMessageAttachment
(Message)
MessageAttachmentState
attachment:
The current message attachment.