Skip to content

refactor: change CustomEvent property from 'data' to 'value' for AG-UI#307

Merged
jherr merged 3 commits intomainfrom
ag-ui-customevents-fresh
Feb 21, 2026
Merged

refactor: change CustomEvent property from 'data' to 'value' for AG-UI#307
jherr merged 3 commits intomainfrom
ag-ui-customevents-fresh

Conversation

@jherr
Copy link
Contributor

@jherr jherr commented Feb 20, 2026

🎯 Changes

Changing data to value for AG-UI

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Bug Fixes
    • Standardized custom event payloads: renamed the payload property from data to value for custom events (including approval-requested and tool-input-available) across Python and TypeScript packages.
  • Tests
    • Updated tests and test helpers to expect the new value payload field for custom event scenarios.

…I compliance

Co-Authored-By: Warp <agent@warp.dev>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 20, 2026

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

Refactors the CustomEvent payload field from data to value across Python and TypeScript packages, updating type definitions, emitters, stream processing, tests, and a changeset declaring patch bumps.

Changes

Cohort / File(s) Summary
Changeset
.changeset/wicked-humans-shop.md
Adds a changeset declaring patch bumps for @tanstack/ai-client and @tanstack/ai, noting the CustomEvent payload field rename.
Python — types & events
packages/python/tanstack-ai/src/tanstack_ai/types.py, packages/python/tanstack-ai/src/tanstack_ai/chat.py
Renamed CustomEvent payload field datavalue; updated CUSTOM event emissions (approval-requested, tool-input-available) to use value.
TypeScript — public types
packages/typescript/ai/src/types.ts
Changed CustomEvent.data?: unknownCustomEvent.value?: unknown; updated ToolExecutionContext.emitCustomEvent parameter name from data to value.
TypeScript — event creation & tools
packages/typescript/ai/src/activities/chat/index.ts, packages/typescript/ai/src/activities/chat/tools/tool-calls.ts
Updated createCustomEventChunk signature and call sites to accept/spread value instead of data; adjusted emitted CUSTOM chunk shape.
TypeScript — stream processing
packages/typescript/ai/src/activities/chat/stream/processor.ts
Stream processor now reads custom payloads from chunk.value (tool-input-available, approval-requested, and fallback forwarding) instead of chunk.data.
Tests — TypeScript client & core
packages/typescript/ai-client/tests/*, packages/typescript/ai/tests/*, packages/typescript/ai-client/tests/test-utils.ts
Updated test fixtures, helpers, and assertions to use value in CUSTOM chunks and helper signatures; adjusted expectations across multiple test files and SSE/stream round-trip tests.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Tools/custom events dispatch #293: Refactors the CustomEvent payload field name across TypeScript and related event dispatch/handling code paths.
  • AG-UI Support #244: Similar cross-language change renaming CustomEvent payload from data to value in Python and TypeScript sources and tests.

Suggested reviewers

  • jherr
  • AlemTuzlak
  • harry-whorlow

Poem

🐰 I swapped the hops of data for value so neat,
From Python to TypeScript I made it complete,
Events now carry the new little prize,
Through tests and streams I bound and I rise,
A tiny refactor—quick paws and a beat. 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: refactoring the CustomEvent property from 'data' to 'value' for AG-UI compliance, which is reflected across all modified files.
Description check ✅ Passed The description follows the template structure with completed checklist items and release impact declaration. However, the 'Changes' section is minimal and lacks detail about the scope and motivation.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ag-ui-customevents-fresh

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud
Copy link

nx-cloud bot commented Feb 20, 2026

View your CI Pipeline Execution ↗ for commit 7064598

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 3m 15s View ↗
nx run-many --targets=build --exclude=examples/** ✅ Succeeded 1m 15s View ↗

☁️ Nx Cloud last updated this comment at 2026-02-21 00:57:14 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 20, 2026

Open in StackBlitz

@tanstack/ai

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai@307

@tanstack/ai-anthropic

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-anthropic@307

@tanstack/ai-client

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-client@307

@tanstack/ai-devtools-core

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-devtools-core@307

@tanstack/ai-fal

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-fal@307

@tanstack/ai-gemini

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-gemini@307

@tanstack/ai-grok

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-grok@307

@tanstack/ai-ollama

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-ollama@307

@tanstack/ai-openai

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-openai@307

@tanstack/ai-openrouter

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-openrouter@307

@tanstack/ai-preact

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-preact@307

@tanstack/ai-react

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-react@307

@tanstack/ai-react-ui

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-react-ui@307

@tanstack/ai-solid

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-solid@307

@tanstack/ai-solid-ui

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-solid-ui@307

@tanstack/ai-svelte

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-svelte@307

@tanstack/ai-vue

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vue@307

@tanstack/ai-vue-ui

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vue-ui@307

@tanstack/preact-ai-devtools

npm i https://pkg.pr.new/TanStack/ai/@tanstack/preact-ai-devtools@307

@tanstack/react-ai-devtools

npm i https://pkg.pr.new/TanStack/ai/@tanstack/react-ai-devtools@307

@tanstack/solid-ai-devtools

npm i https://pkg.pr.new/TanStack/ai/@tanstack/solid-ai-devtools@307

commit: 7064598

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
packages/typescript/ai/src/activities/chat/stream/processor.ts (1)

76-81: ⚠️ Potential issue | 🟡 Minor

onCustomEvent callback parameter name is now inconsistent with CustomEvent.value.

The second parameter data (line 79) is forwarded directly from chunk.value (line 866). Since this is a public-facing events API, callers who name their callback parameter after the interface field will have a mismatch between the callback declaration and the CustomEvent type they imported.

✏️ Suggested fix
   onCustomEvent?: (
     eventType: string,
-    data: unknown,
+    value: unknown,
     context: { toolCallId?: string },
   ) => void
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/typescript/ai/src/activities/chat/stream/processor.ts` around lines
76 - 81, The onCustomEvent callback's second parameter is named "data" but is
forwarded from chunk.value and should match the public CustomEvent.value name;
update the onCustomEvent signature to use "value" instead of "data" (and adjust
any internal references) so it aligns with CustomEvent.value and the value
forwarded from chunk.value in the stream processor.
packages/typescript/ai/src/types.ts (1)

356-373: ⚠️ Potential issue | 🟡 Minor

ToolExecutionContext.emitCustomEvent parameter name and JSDoc are now stale.

The second parameter is still named data (line 372) and the JSDoc still says @param data - Event payload data (line 359), but the payload it produces lands in CustomEvent.value. This is a public API method, so the inconsistency will confuse callers who see the emitter call emitCustomEvent(name, data) but observe the event with .value.

✏️ Suggested fix
   /**
    * `@param` eventName - Name of the custom event
-   * `@param` data - Event payload data
+   * `@param` value - Event payload value
    */
-  emitCustomEvent: (eventName: string, data: Record<string, any>) => void
+  emitCustomEvent: (eventName: string, value: Record<string, any>) => void
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/typescript/ai/src/types.ts` around lines 356 - 373,
ToolExecutionContext.emitCustomEvent's second parameter and JSDoc are out of
sync with the emitted CustomEvent payload — update the method signature and docs
so the param is named "value" (not "data") and the JSDoc `@param` reflects that
this becomes CustomEvent.value; update the example usage in the JSDoc to call
emitCustomEvent(name, value) and ensure the type remains Record<string, any> for
the "value" parameter so callers and runtime behavior match (refer to
ToolExecutionContext.emitCustomEvent and the example block in the same comment).
🧹 Nitpick comments (1)
packages/typescript/ai/src/activities/chat/index.ts (1)

610-611: Lambda parameter data is inconsistent with the renamed value parameter.

Both executeToolCalls callbacks at lines 610 and 673 pass a local data variable directly to createCustomEventChunk's value parameter. This is a harmless nitpick but creates a naming disconnect that could confuse a future reader of the call chain.

✏️ Suggested fix
-      (eventName, data) => this.createCustomEventChunk(eventName, data),
+      (eventName, value) => this.createCustomEventChunk(eventName, value),

(Apply to both occurrences at lines 610 and 673.)

Also applies to: 672-674

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/typescript/ai/src/activities/chat/index.ts` around lines 610 - 611,
The lambda parameter name `data` passed into executeToolCalls should match the
renamed parameter `value` expected by createCustomEventChunk to avoid confusion;
update both callback lambdas (the ones that call
this.createCustomEventChunk(...)) to use `value` as the parameter name instead
of `data` so the call becomes (value) => this.createCustomEventChunk(eventName,
value) in both occurrences referencing createCustomEventChunk and the
executeToolCalls callbacks.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@packages/typescript/ai/src/activities/chat/stream/processor.ts`:
- Around line 76-81: The onCustomEvent callback's second parameter is named
"data" but is forwarded from chunk.value and should match the public
CustomEvent.value name; update the onCustomEvent signature to use "value"
instead of "data" (and adjust any internal references) so it aligns with
CustomEvent.value and the value forwarded from chunk.value in the stream
processor.

In `@packages/typescript/ai/src/types.ts`:
- Around line 356-373: ToolExecutionContext.emitCustomEvent's second parameter
and JSDoc are out of sync with the emitted CustomEvent payload — update the
method signature and docs so the param is named "value" (not "data") and the
JSDoc `@param` reflects that this becomes CustomEvent.value; update the example
usage in the JSDoc to call emitCustomEvent(name, value) and ensure the type
remains Record<string, any> for the "value" parameter so callers and runtime
behavior match (refer to ToolExecutionContext.emitCustomEvent and the example
block in the same comment).

---

Nitpick comments:
In `@packages/typescript/ai/src/activities/chat/index.ts`:
- Around line 610-611: The lambda parameter name `data` passed into
executeToolCalls should match the renamed parameter `value` expected by
createCustomEventChunk to avoid confusion; update both callback lambdas (the
ones that call this.createCustomEventChunk(...)) to use `value` as the parameter
name instead of `data` so the call becomes (value) =>
this.createCustomEventChunk(eventName, value) in both occurrences referencing
createCustomEventChunk and the executeToolCalls callbacks.

@jherr jherr merged commit 1f800aa into main Feb 21, 2026
6 checks passed
@jherr jherr deleted the ag-ui-customevents-fresh branch February 21, 2026 01:10
@github-actions github-actions bot mentioned this pull request Feb 21, 2026
dhamivibez pushed a commit to dhamivibez/tanstack-ai that referenced this pull request Feb 22, 2026
TanStack#307)

* refactor: change CustomEvent property from 'data' to 'value' for AG-UI compliance

Co-Authored-By: Warp <agent@warp.dev>

* fixing the oh so lovely tests

* ci: apply automated fixes

---------

Co-authored-by: Warp <agent@warp.dev>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant