You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs(ai-chat): document the clientData validation error timing options
The chat.withClientData reference still carried the older signature with
only schema, so reportErrorAt and onValidationError were missing from the
page that defines the function. clientDataReportErrorAt, the flat option
on chat.customAgent, was absent from the docs entirely while its sibling
callback was documented in six places.
Adds both to the reference with types and defaults, states what
reportErrorAt does and does not govern, names the flat equivalents for
callers who pass options directly, and cross-links from the types page.
Copy file name to clipboardExpand all lines: docs/ai-chat/reference.mdx
+14-4Lines changed: 14 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -550,15 +550,25 @@ Use this when you need [`InferChatUIMessage`](#inferchatuimessage) / typed `data
550
550
Returns a [`ChatBuilder`](/ai-chat/types#chatbuilder) with a fixed client data schema. Managed-agent hooks and `run` get typed `clientData` without passing `clientDataSchema` in `.agent()` options. Custom agents parse `payload.metadata` on the initial payload and later input frames before passing it to user code.
|`schema`|`TaskSchema`| required | Zod, ArkType, Valibot, or any supported schema lib |
563
+
|`reportErrorAt`|`"turn-end" \| "arrival"`|`"turn-end"`| When the client-visible `Invalid client data` error is written for a frame that failed validation mid-turn |
564
+
|`onValidationError`|`(event) => void`| — | Called when an input fails validation. Composes with the task-level `onClientDataValidationError` rather than replacing it |
565
+
566
+
`reportErrorAt` governs only the stream-visible error. `"turn-end"` holds it until the turn closes, so a bad send cannot truncate an answer the user is already reading; `"arrival"` writes it as soon as validation fails, ending the response in progress. `onValidationError` and the task log fire on arrival in both modes, and the frame is never delivered as a turn either way.
559
567
560
568
For `chat.customAgent()`, invalid client data is skipped. Async reads emit an error chunk followed by `turn-complete`. A `chat.messages.on()` subscription uses the task's `onClientDataValidationError` callback and task log instead, so an active response is not ended early. Without a schema, metadata is passed through unchanged.
561
569
570
+
Passing options directly to `chat.customAgent()` instead of through the builder uses the flat equivalents: `clientDataSchema`, `clientDataReportErrorAt`, and `onClientDataValidationError`.
571
+
562
572
Full guide: [Typed client data](/ai-chat/types#typed-client-data-with-chatwithclientdata).
Copy file name to clipboardExpand all lines: docs/ai-chat/types.mdx
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -169,6 +169,8 @@ export const myChat = chat
169
169
170
170
The schema runs at runtime for both `.agent()` and `.customAgent()`. Custom agents validate the initial payload and later `chat.messages` frames. Invalid frames are not passed to user code. Async reads emit an error chunk followed by `turn-complete`; `chat.messages.on()` reports through `onClientDataValidationError` and the task log so it does not end an active response. Without a schema, metadata is passed through unchanged.
171
171
172
+
`withClientData` also takes `reportErrorAt` and `onValidationError` alongside `schema`. See [chat.withClientData](/ai-chat/reference#chatwithclientdata) for both, and [Validating client data](/ai-chat/custom-agents#validating-client-data) for the custom-agent walkthrough.
173
+
172
174
## ChatBuilder
173
175
174
176
Both `chat.withUIMessage()` and `chat.withClientData()` return a **ChatBuilder** — a chainable object that accumulates configuration before creating the agent with `.agent()`.
0 commit comments