feat(ai-chat): forward custom body fields to onChatMessage options#886
Conversation
Custom data sent via prepareSendMessagesRequest or the AI SDK body option in sendMessage was being silently dropped on the server side. Extract all non-internal fields (everything except messages and clientTools) from the parsed request body and pass them through as options.body in onChatMessage, so users can send dynamic context like model selection or metadata from client to server.
🦋 Changeset detectedLatest commit: 3e0eb90 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
|
/bonk review this PR |
Co-authored-by: whoiskatrin <whoiskatrin@users.noreply.github.com>
|
Here's my review of this PR: PR Review: feat(ai-chat): forward custom body fields to onChatMessage optionsVerdict: Looks good overall. One issue with the changeset needs fixing before merge. What it doesThe PR adds a Code changes review
Issue: Changeset bump levelThe changeset at Nit (non-blocking)The TestsAll 40 Workers tests pass (7 test files), including the 3 new |
|
bonk is right, let's make this a patch, and then ship it |
|
wait why is it showing as major |
|
sigh I'll fix it. but also let's make this a patch? |
threepointone
left a comment
There was a problem hiding this comment.
pending making changeset a patch
|
/bonk can you make a changeset a patch please? |
Co-authored-by: whoiskatrin <whoiskatrin@users.noreply.github.com>
|
Done — changed the changeset from |
|
/bonk can you file an issue to followup on the nit |
|
Filed: #887 The issue tracks the nit from the review — |
Summary
sendMessage/prepareSendMessagesRequestto the server-sideonChatMessagehandler viaoptions.bodymessagesandclientTools) were silently dropped during parsingbody?: Record<string, unknown>toOnChatMessageOptionstype and extract custom fields using rest destructuringMotivation
Users sending custom data alongside chat messages (e.g. model selection, temperature, metadata) had no way to access it server-side. The data was parsed but only
messagesandclientToolswere extracted — everything else was discarded.Ref: https://discord.com/channels/595317990191398933/1344688586146189475/1470897271649341491
Usage
Changes
packages/ai-chat/src/index.ts— AddbodytoOnChatMessageOptions; extract custom fields via rest destructuring and pass toonChatMessagepackages/ai-chat/src/tests/worker.ts— Captureoptions.bodyin test agent for verificationpackages/ai-chat/src/tests/custom-body.test.ts— Tests for body forwarding, exclusion of internal fields, and undefined when empty