The result object-type returned by the useStructuredChat hook that provides functions and state for interacting with the chat.
API
interface UseStructuredChatResult<Output, Tools extends Chat.AnyTool, State = unknown> {error: Error | undefined;exhaustedRetries: boolean;generatingError: Error | undefined;isGenerating: boolean;isLoading: boolean;isReceiving: boolean;readonly isResuming: boolean;isRunningToolCalls: boolean;isSending: boolean;lastAssistantMessage: Chat.AssistantMessage <
Output,
Tools
> | undefined;messages: (Chat.Message < Output, Tools > []);readonly pendingInterrupts: PendingInterruptBatch | undefined;reload: () => void;resendMessages: () => void;resume(options: ResumeOptions): void;sendingError: Error | undefined;sendMessage: (message: Chat.Message<Output, Tools>) => void;setMessages: (messages: Chat.Message<Output, Tools>[]) => void;setState(state: State): void;readonly state: State | undefined;stop: (clearStreamingMessage?: boolean) => void;}@typeOutput@typeToolsChat.AnyTool@typeStateError | undefinedThe error encountered during chat operations, if any.
booleanWhether the current request has exhausted retries.
Error | undefinedError emitted during generation events.
booleanWhether the chat is currently generating.
booleanAggregate loading flag across transport, generation, and tool calls.
booleanWhether the chat is receiving a response.
booleanWhether the resumed interaction is still running.
booleanWhether the chat is running tool calls.
booleanWhether the chat is sending a response.
Chat.AssistantMessage<Output, Tools> | undefinedThe last assistant message.
Chat.Message<Output, Tools>[]An array of chat messages.
PendingInterruptBatch | undefinedThe complete pending interrupt batch, including while claimed.
() => voidReload the chat, useful for retrying when an error occurs.
() => voidFunction to cause current messages to be resent. Can be used after an error in chat.
Error | undefinedTransport/request failure before generation events arrive.
(message: Chat.Message<Output, Tools>) => voidFunction to send a new chat message.
(messages: Chat.Message<Output, Tools>[]) => voidFunction to update the chat messages.
State | undefinedThe currently visible shared agent state.
(clearStreamingMessage?: boolean) => voidFunction to stop the chat.