Runtime Hooks

MessageRuntime

Hooks for accessing message state, utilities, and edit composer.

useMessage

Retrieve the message object:

import { useMessage } from "@assistant-ui/react";

const { message } = useMessage();
const msg = useMessage((m) => m.message);
MessageState
messagerequired: Readonly<ThreadMessage>

The current message.

parentIdrequired: string | null

The parent message id.

branchesrequired: readonly string[]

The branches for the message.

isLastrequired: boolean

Whether the message is the last in the thread.

useMessageUtils

Provides utility functions for a message (e.g., copy status):

import { useMessageUtils } from "@assistant-ui/react";

const messageUtils = useMessageUtils();
const isCopied = useMessageUtils((m) => m.isCopied);
MessageUtilsState
isCopiedrequired: boolean

Whether the message is copied.

setIsCopiedrequired: (value: boolean) => void

A function to set the is copied.

isHoveringrequired: boolean

Whether the message is being hovered.

setIsHoveringrequired: (value: boolean) => void

A function to set the is hovering.

isSpeakingrequired: boolean

Whether the message is currently being spoken.

stopSpeakingrequired: () => void

A function to stop the message from being spoken.

addUtterancerequired: (utterance: SpeechSynthesisAdapter.Utterance) => void

A function to add a speech utterance.

useEditComposer

Access the edit composer state (used when editing a message):

import { useEditComposer } from "@assistant-ui/react";

const editComposer = useEditComposer();
const text = useEditComposer((m) => m.text);
EditComposerState
textrequired: string

The current text of the composer.

setTextrequired: (text: string) => void

A function to set the text of the composer.

attachmentsrequired: readonly Attachment[]

The current attachments of the composer.

addAttachmentrequired: (file: File | CreateAttachment) => Promise<void>

A function to add an attachment to the composer. Accepts a File (processed through the AttachmentAdapter) or a CreateAttachment descriptor for external-source attachments.

removeAttachmentrequired: (attachmentId: string) => void

A function to remove an attachment from the composer.

resetrequired: () => void

A function to reset the composer.

canCancelrequired: boolean

Whether the composer can be canceled.

isEditingrequired: boolean

Whether the composer is in edit mode.

editrequired: () => void

A function to enter edit mode.

sendrequired: () => void

A function to send the message.

cancelrequired: () => void

A function to exit the edit mode.