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
feat(ai-client): accept a per-call body via SendMessageOptions
ChatClient.sendMessage already took a per-call body as its positional
second argument, but every framework hook (useChat, injectChat,
createChat, ...) exposes sendMessage(content, options) and forwards
undefined for it — leaving no race-free way to send per-message data
(e.g. attachment ids) through a hook: updating a reactive chat-level
body/forwardedProps option right before sending can flush after the
send.
SendMessageOptions gains an optional body that ChatClient resolves as a
fallback to the positional argument (positional wins), so every wrapper
inherits the capability with no wrapper code changes. Queued sends
preserve it exactly like the positional form.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Add `body` to `SendMessageOptions`: a per-call body shallow-merged into the request's `forwardedProps` with the highest priority.
6
+
7
+
`ChatClient.sendMessage` already accepted a per-call body as its positional second argument, but the framework hooks (`useChat`, `injectChat`, `createChat`, …) expose `sendMessage(content, options)` and forwarded `undefined` for it — leaving no race-free way to send per-message data (e.g. attachment ids) through a hook. Updating a reactive chat-level `body`/`forwardedProps` option right before sending is racy because reactive option changes can flush after the send.
8
+
9
+
`sendMessage(content, { body: { ... } })` now works through every framework hook and on `ChatClient` directly. The positional argument wins if both are provided. Queued sends preserve their per-call `body` exactly like the positional form.
Copy file name to clipboardExpand all lines: docs/chat/connection-adapters.md
+18Lines changed: 18 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -80,6 +80,24 @@ const { messages } = useChat({
80
80
81
81
> **Tip:**`body` and `forwardedProps` populate the same wire field. Use `body` for static defaults, the `forwardedProps` constructor option (or per-`sendMessage``data`) for dynamic values. Runtime values always win.
82
82
83
+
**Per-call body.** For data that belongs to one specific message (attachment ids, a one-off flag), pass `body` in `sendMessage`'s options — it is shallow-merged into `forwardedProps` with the highest priority, for that request only:
// forwardedProps for this request: { provider: "openai", attachmentIds: [...] }
94
+
awaitsendMessage("Summarize the attached files", {
95
+
body: { attachmentIds: ["att_1", "att_2"] },
96
+
});
97
+
```
98
+
99
+
This is race-free where updating a reactive chat-level `body`/`forwardedProps` option right before sending is not (reactive option changes can flush after the send). On `ChatClient` directly, the positional `body` argument does the same thing and wins if both are provided.
100
+
83
101
### Resumable SSE
84
102
85
103
`fetchServerSentEvents` watches SSE `id:` values. If a connection drops after
0 commit comments