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);MessageStatemessagerequired: Readonly<ThreadMessage>The current message.
parentIdrequired: string | nullThe parent message id.
branchesrequired: readonly string[]The branches for the message.
isLastrequired: booleanWhether 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);MessageUtilsStateisCopiedrequired: booleanWhether the message is copied.
setIsCopiedrequired: (value: boolean) => voidA function to set the is copied.
isHoveringrequired: booleanWhether the message is being hovered.
setIsHoveringrequired: (value: boolean) => voidA function to set the is hovering.
isSpeakingrequired: booleanWhether the message is currently being spoken.
stopSpeakingrequired: () => voidA function to stop the message from being spoken.
addUtterancerequired: (utterance: SpeechSynthesisAdapter.Utterance) => voidA 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);EditComposerStatetextrequired: stringThe current text of the composer.
setTextrequired: (text: string) => voidA 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) => voidA function to remove an attachment from the composer.
resetrequired: () => voidA function to reset the composer.
canCancelrequired: booleanWhether the composer can be canceled.
isEditingrequired: booleanWhether the composer is in edit mode.
editrequired: () => voidA function to enter edit mode.
sendrequired: () => voidA function to send the message.
cancelrequired: () => voidA function to exit the edit mode.