Conversation
🦋 Changeset detectedLatest commit: 08fa18f The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
I think I handled this in my pr, can you check? |
|
Oh this is different |
commit: |
Yes, I think your PR is missing data parts but you have added a compression for messages too large and I added a simpler size check to skip persistence. Should I remove that? |
|
Yeah don't skip persistence |
|
/bonk review this PR |
|
Now I have a thorough understanding of the PR. Here's my review: PR Review: Handle data parts in AIChatSummaryThis PR adds server-side persistence for Core SDK Changes (
|
|
/bonk review again |
|
Good. Now I have a full picture. Let me write the review. PR Review: Handle data parts in AIChat (re-review)Previous blocker — resolvedThe Remaining issues1. Stray whitespace change (nit) The diff removes a blank line between 2. Transient parts are still broadcast AND stored as stream chunks Transient parts are correctly excluded from 3. The cast at line 1777 is still there. // Cast needed because UIMessage["parts"] doesn't include data-* part shapes.
// Safe at runtime — parts is a plain array and data-* types are pass-through.4. The find predicate at line 1764: (p) =>
p.type === dataChunk.type &&
"id" in p &&
(p as { id?: string }).id === dataChunk.idThe const existing = message.parts.find(
(p) =>
p.type === dataChunk.type &&
"id" in p &&
(p as Record<string, unknown>).id === dataChunk.id
);Or just cast once at the top since you're already in the Example changes — look good
One observation: the VerdictNo blockers remaining. The main feedback from the previous review (skip persistence) has been addressed. The remaining items are minor — the |
|
cursor told me this: What's still NOT covered even after this PR: |
|
I'll review this later this evening, let's get it in shape by then? |
d8895f7 to
16def7b
Compare
|
what parts of that feedback I shared were addressed? could you update the pr description? could you add tests (unit/e2e as relevant) thanks! I'll review tomorrow morning before landing. |
I've added tests too 🫡 |
Add a clarifying comment in message-builder explaining that chunk.data should always be provided because a persisted part with data: undefined will be dropped by JSON.stringify (resulting in no data field on reload). Add unit tests to cover: transient parts with the same id are skipped (not reconciled) and handling of undefined data (part persisted without a data field).
|
love this, banger. will land once CI passes. |
- Add Data Parts section to docs/chat-agents.md covering server-side writer.write(), three patterns (reconciliation, append, transient), typed client access, and onData callback - Update docs/AGENTS.md to reflect that the sync-docs workflow has been removed — docs must be manually ported to cloudflare-docs Co-authored-by: Cursor <cursoragent@cursor.com>
Adjust Markdown table spacing and column alignment in the "Three Patterns" section of docs/chat-agents.md to improve readability and rendering. No semantic changes to content or behavior.
* feat(ai-chat): handle data-* stream parts and forward onData callback (cloudflare#900) * typed data parts in example * add data parts in message builder test * Clarify chunk.data and add tests Add a clarifying comment in message-builder explaining that chunk.data should always be provided because a persisted part with data: undefined will be dropped by JSON.stringify (resulting in no data field on reload). Add unit tests to cover: transient parts with the same id are skipped (not reconciled) and handling of undefined data (part persisted without a data field). * docs: add data parts section to chat-agents, update AGENTS.md - Add Data Parts section to docs/chat-agents.md covering server-side writer.write(), three patterns (reconciliation, append, transient), typed client access, and onData callback - Update docs/AGENTS.md to reflect that the sync-docs workflow has been removed — docs must be manually ported to cloudflare-docs Co-authored-by: Cursor <cursoragent@cursor.com> * Reformat table in chat-agents.md Adjust Markdown table spacing and column alignment in the "Three Patterns" section of docs/chat-agents.md to improve readability and rendering. No semantic changes to content or behavior. --------- Co-authored-by: Sunil Pai <spai@cloudflare.com> Co-authored-by: Cursor <cursoragent@cursor.com>
Add support for
data-*stream parts in the shared message builder. Data parts are developer-defined typed JSON blobs that the AI SDK attaches to messages alongside text — they were previously silently dropped.What changed
packages/ai-chat/src/message-builder.ts— Handledata-*chunk types inapplyChunkToParts. This is the shared parser used by both the server (_streamSSEReply) and client (stream resume / cross-tab broadcast), so data parts are handled consistently everywhere. Transient parts (transient: true) are broadcast but not persisted. Non-transient parts support reconciliation by type+id — a second chunk with the same composite key updates.datain-place.packages/ai-chat/src/react.tsx— Forward theonDatacallback fordata-*chunks on the stream resume and cross-tab broadcast codepaths. The transport path (new messages from this tab) already goes through the AI SDK's internal pipeline which invokesonData. This is the correct way to consume transient data parts on the client since they are not inmessage.parts.packages/ai-chat/src/tests/message-builder.test.ts— 9 new tests covering append, id preservation, type+id reconciliation, non-matching ids/types, id-less parts, transient skip, and coexistence with other part types.examples/resumable-stream-chat/— Updated to demonstrate three data part patterns:data-sources(reconciliation),data-thinking(transient viaonData), anddata-usage(persisted metadata). The client usesUIMessage<unknown, { sources; thinking; usage }>for fully typed data parts — no manual casts needed.What about the items from this comment?
onDatacallback — Addressed. Extracted from options, stored in a ref, forwarded touseChat, and explicitly called for the resume/broadcast paths.useAgentChat— Already works. TheChatMessagegeneric flows throughuseAgentChat→useChatend-to-end.dataPartSchemasis available via the inheritedChatInitoptions. The example now demonstrates this —part.type === "data-sources"narrowspart.datato the correct shape automatically.Closes #575