Skip to content

useChat hooks drop ChatClient.sendMessage's per-call body (preact, react, vue) #1225

Closed

Description

@rickylabs

Describe the bug

ChatClient.sendMessage accepts a per-call body as its second argument, documented as "Optional body parameters to merge with the client's base body for this request. Uses shallow merge with per-message body taking priority."

Every framework useChat hook hard-codes that argument to undefined, so per-send body is unreachable from the hooks. packages/ai-preact/src/use-chat.ts on main:

const sendMessage = useCallback(
  async (
    content: string | MultimodalContent,
    sendOptions?: SendMessageOptions,
  ) => {
    try {
      await client.sendMessage(content, undefined, sendOptions)

Identical in packages/ai-react/src/use-chat.ts and packages/ai-vue/src/use-chat.ts:

client.sendMessage(content, undefined, sendOptions)

The hooks' public type stops at (content, sendOptions?), and UseChatReturn does not expose the underlying client, so there is no supported way to reach the parameter.

Why this looks unintended rather than a deliberate narrowing

use-mcp-app-bridge.ts — in the same package — forwards it:

chat: { sendMessage: (content, body) => chatRef.current.sendMessage(content, body) },

So within @tanstack/ai-preact one hook can attach per-send body and the other cannot. ChatClient already implements the merge (mergedBody = {...bodyOption, ...forwardedPropsOption, ...pendingMessageBody}), so the hooks are pure passthroughs that drop an argument.

Why it matters

Per-send body is the natural channel for per-turn application data that the model must not see — the thing your own docs guarantee for metadata ("Adapters never forward this field onto the provider wire request"). Without it, the options from a hook are:

  1. forwardedProps on the useChat config — but that is per-render, not per-send. Computing a value inside a submit handler and calling sendMessage in the same tick races the commit, because useChat re-applies forwardedProps from an effect keyed on identity.
  2. Mutating a stable forwardedProps ref just before sendMessage — works, but depends on updateOptions storing the reference without copying. An implementation detail.
  3. Putting the data in the message text — which is what we did, and it cost us a production incident: a model read an instruction meant for our server, emitted a tool call for a tool that did not exist as literal text, and the turn died. The text is persisted, so it replayed on every subsequent turn of that session.

Option 3 is the one people reach for when 1 and 2 look fragile, and it is the worst one.

Expected behaviour

The hooks forward the argument, matching ChatClient and use-mcp-app-bridge:

const sendMessage = useCallback(
  async (
    content: string | MultimodalContent,
    body?: Record<string, unknown>,
    sendOptions?: SendMessageOptions,
  ) => {
    await client.sendMessage(content, body, sendOptions)

with UseChatReturn['sendMessage'] widened to match.

Ordering is the one design question: ChatClient has body second and sendOptions third, but the hooks currently expose sendOptions second, so a straight passthrough is a breaking change for anyone passing sendOptions positionally. If that is unacceptable, sendOptions.body would be non-breaking, at the cost of diverging from ChatClient.

Happy to open the PR either way — just say which shape you prefer.

Versions

  • @tanstack/ai-preact 0.13.2 (also verified on main)
  • @tanstack/ai-client 0.26.0
  • @tanstack/ai 0.48.0
  • Reproduced originally on @tanstack/ai-preact 0.10.1 / ai-client 0.19.1

Affected packages

ai-preact, ai-react, ai-vue (ai-solid and ai-svelte have no use-chat.ts at that path — not checked further).

Activity

  1. added
    waiting-on: maintainer
    on Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    waiting-on: maintainer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions