Reference

SendMessageCallbacks

Type
Defines the named callbacks `sendMessage` invokes while a turn streams in.

The handlers sendMessage fires as a turn arrives. The named ones cover the common cases (text, thinking, tool start and result, and client tool calls), while onEvent receives every raw AgentChatEvent for logging or lower-level events like tool_input_delta. onText receives deltas to append, the opposite of the method client's accumulated onToken.

SendMessageCallbacks.ts
interface SendMessageCallbacks {
  onText?: (text: string) => void
  onThinking?: (text: string) => void
  onThinkingComplete?: (thinking: string, signature: string) => void
  onToolCallStart?: (id: string, name: string) => void
  onToolCallResult?: (id: string, output: unknown) => void
  onClientToolCall?: (name: string, input: unknown, id: string) => void
  onError?: (error: string) => void
  onEvent?: (event: AgentChatEvent) => void
  signal?: AbortSignal
}
Fields
onText?
(text: string) => void
Called with each text delta; append it, do not replace.
onThinking?
(text: string) => void
Called with each extended-thinking delta.
onThinkingComplete?
(thinking, signature) => void
Called once thinking is complete, with its full text and signature.
onToolCallStart?
(id, name) => void
Called when a tool call begins executing; show an inline activity indicator.
onToolCallResult?
(id, output) => void
Called when a tool call returns its result.
onClientToolCall?
(name, input, id) => void
Called when the agent invokes a browser-side client tool; run the on-screen action here.
onError?
(error: string) => void
Called on a stream-level error.
onEvent?
(event: AgentChatEvent) => void
Called for every event, including ones with a named callback; use it for logging or low-level events.
signal?
AbortSignal
Cancels the stream.
Wire the common handlers
chat.sendMessage(threadId, text, {
  onText: (delta) => setText((p) => p + delta),
  onToolCallStart: (id, name) => showActivity(name),
  onClientToolCall: (name, input) => runClientTool(name, input),
});