ThreadRuntime
useThreadRuntime
Get the thread runtime object:
import { useThreadRuntime } from "@assistant-ui/react";
const thread = 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:
unstable_resumeRun:
Resume a run with the given configuration.
subscribe:
cancelRun:
getModelContext:
getModelConfig:
export:
import:
getMesssageByIndex:
getMesssageById:
stopSpeaking:
unstable_on:
useThread
Access the thread state directly:
import { useThread } from "@assistant-ui/react";
const thread = useThread();
const isRunning = useThread((m) => m.isRunning);
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.
state:
The thread state.
suggestions:
Follow up message suggestions to show the user.
extras:
Custom extra information provided by the runtime.
speech:
useThreadViewport
Manage thread viewport state (e.g., scrolling):
import { useThreadViewport } from "@assistant-ui/react";
const threadViewport = useThreadViewport();
const isAtBottom = useThreadViewport((m) => m.isAtBottom);
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.