ComposerRuntime state and actions for controlling assistant-ui composer text, attachments, submission, cancellation, and pending input.
API Reference
ComposerRuntime
ComposerRuntimepath: ComposerRuntimePathref: stringthreadSelector: ComposerRuntimePath["threadSelector"]type: "main"
composerSource: "thread"
type: "edit" | "thread"getState: () => ComposerStateGet the current state of the composer. Includes any data that has been added to the composer.
addAttachment: (fileOrAttachment: File | CreateAttachment) => Promise<void>Add an attachment to the composer. Accepts either a standard File object (processed through the AttachmentAdapter) or a CreateAttachment descriptor for external-source attachments (URLs, API data, CMS references). External descriptors bypass the adapter's `add()` step but still respect `adapter.accept` when an adapter is configured; without an adapter they are added as-is.
setText: (text: string) => voidSet the text of the composer.
setRole: (role: MessageRole) => voidSet the role of the composer. For instance, if you'd like a specific message to have the 'assistant' role, you can do so here.
setRunConfig: (runConfig: RunConfig) => voidSet the run config of the composer. This is used to send custom configuration data to the model. Within your backend, you can use the `runConfig` object. Example: ```ts composerRuntime.setRunConfig({ custom: { customField: "customValue" } }); ```
reset: () => Promise<void>Reset the composer. This will clear the entire state of the composer, including all text and attachments.
clearAttachments: () => Promise<void>Clear all attachments from the composer.
send: (options?: SendOptions) => voidSend a message. This will send whatever text or attachments are in the composer.
cancel: () => voidCancel the current run. In edit mode, this will exit edit mode.
subscribe: (callback: () => void) => UnsubscribeListens for changes to the composer state.
getAttachmentByIndex: (idx: number) => AttachmentRuntimeGet an attachment by index.
startDictation: () => voidStart dictation to convert voice to text input. Requires a DictationAdapter to be configured.
stopDictation: () => voidStop the current dictation session.
setQuote: (quote: QuoteInfo | undefined) => voidSet a quote for the next message. Pass undefined to clear.
unstable_ondeprecatedunstable: <E extends ComposerRuntimeEventType>(event: E, callback: ComposerRuntimeEventCallback<E>) => UnsubscribeDeprecated: This API is still under active development and might change without notice.
ComposerState
ComposerStatecanCancel: booleancanSend: booleanisEditing: booleanisEmpty: booleantext: stringrole: MessageRoleattachments: readonly Attachment[]runConfig: RunConfigcustom?: Record<string, unknown>
attachmentAccept: stringdictation?: DictationStateThe current state of dictation. Undefined when dictation is not active.
status: DictationAdapter.Statustype: "starting" | "running"
transcript?: stringinputDisabled?: boolean
quote?: QuoteInfoThe currently quoted text, if any. Undefined when no quote is set.
text: stringmessageId: string
type: "thread"
EditComposerRuntime
EditComposerRuntimepath: ComposerRuntimePathref: stringthreadSelector: EditComposerRuntime["path"]["threadSelector"]type: "main"
messageSelector: EditComposerRuntime["path"]["messageSelector"]type: "messageId"
composerSource: "edit"
type: "edit" | "thread"addAttachment: (fileOrAttachment: File | CreateAttachment) => Promise<void>Add an attachment to the composer. Accepts either a standard File object (processed through the AttachmentAdapter) or a CreateAttachment descriptor for external-source attachments (URLs, API data, CMS references). External descriptors bypass the adapter's `add()` step but still respect `adapter.accept` when an adapter is configured; without an adapter they are added as-is.
setText: (text: string) => voidSet the text of the composer.
setRole: (role: MessageRole) => voidSet the role of the composer. For instance, if you'd like a specific message to have the 'assistant' role, you can do so here.
setRunConfig: (runConfig: RunConfig) => voidSet the run config of the composer. This is used to send custom configuration data to the model. Within your backend, you can use the `runConfig` object. Example: ```ts composerRuntime.setRunConfig({ custom: { customField: "customValue" } }); ```
reset: () => Promise<void>Reset the composer. This will clear the entire state of the composer, including all text and attachments.
clearAttachments: () => Promise<void>Clear all attachments from the composer.
send: (options?: SendOptions) => voidSend a message. This will send whatever text or attachments are in the composer.
cancel: () => voidCancel the current run. In edit mode, this will exit edit mode.
subscribe: (callback: () => void) => UnsubscribeListens for changes to the composer state.
startDictation: () => voidStart dictation to convert voice to text input. Requires a DictationAdapter to be configured.
stopDictation: () => voidStop the current dictation session.
setQuote: (quote: QuoteInfo | undefined) => voidSet a quote for the next message. Pass undefined to clear.
unstable_ondeprecatedunstable: <E extends ComposerRuntimeEventType>(event: E, callback: ComposerRuntimeEventCallback<E>) => UnsubscribeDeprecated: This API is still under active development and might change without notice.
getState: () => EditComposerStatebeginEdit: () => voidgetAttachmentByIndex: (idx: number) => AttachmentRuntime & { source: "edit-composer"; }
EditComposerState
EditComposerStatecanCancel: booleancanSend: booleanisEditing: booleanisEmpty: booleantext: stringrole: MessageRoleattachments: readonly Attachment[]runConfig: RunConfigcustom?: Record<string, unknown>
attachmentAccept: stringdictation?: DictationStateThe current state of dictation. Undefined when dictation is not active.
status: DictationAdapter.Statustype: "starting" | "running"
transcript?: stringinputDisabled?: boolean
quote?: QuoteInfoThe currently quoted text, if any. Undefined when no quote is set.
text: stringmessageId: string
type: "edit"parentId: string | nullsourceId: string | null