logoassistant-ui
API ReferenceRuntime Hooks

MessageRuntime

useMessage

Retrieve the message object:

import { useMessage } from "@assistant-ui/react";
 
const { message } = useMessage();
const msg = useMessage((m) => m.message);

MessageState

message:

Readonly<ThreadMessage>

The current message.

parentId:

string | null

The parent message id.

branches:

readonly string[]

The branches for the message.

isLast:

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

isCopied:

boolean

Whether the message is copied.

setIsCopied:

(value: boolean) => void

A function to set the is copied.

isHovering:

boolean

Whether the message is being hovered.

setIsHovering:

(value: boolean) => void

A function to set the is hovering.

isSpeaking:

boolean

Whether the message is currently being spoken.

stopSpeaking:

() => void

A function to stop the message from being spoken.

addUtterance:

(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

text:

string

The current text of the composer.

setText:

(text: string) => void

A function to set the text of the composer.

attachments:

readonly Attachment[]

The current attachments of the composer.

addAttachment:

(attachment: Attachment) => void

A function to add an attachment to the composer.

removeAttachment:

(attachmentId: string) => void

A function to remove an attachment from the composer.

reset:

() => void

A function to reset the composer.

canCancel:

boolean

Whether the composer can be canceled.

isEditing:

boolean

Whether the composer is in edit mode.

edit:

() => void

A function to enter edit mode.

send:

() => void

A function to send the message.

cancel:

() => void

A function to exit the edit mode.

On this page

Edit on Github