Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/wicked-humans-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@tanstack/ai-client': patch
'@tanstack/ai': patch
---

Refactor CustomEvent property from 'data' to 'value' for AG-UI compliance
4 changes: 2 additions & 2 deletions packages/python/tanstack-ai/src/tanstack_ai/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ async def _emit_approval_requests(
"timestamp": int(time.time() * 1000),
"model": finish_event.get("model"),
"name": "approval-requested",
"data": {
"value": {
"toolCallId": approval.tool_call_id,
"toolName": approval.tool_name,
"input": approval.input,
Expand All @@ -410,7 +410,7 @@ async def _emit_client_tool_inputs(
"timestamp": int(time.time() * 1000),
"model": finish_event.get("model"),
"name": "tool-input-available",
"data": {
"value": {
"toolCallId": client_tool.tool_call_id,
"toolName": client_tool.tool_name,
"input": client_tool.input,
Expand Down
2 changes: 1 addition & 1 deletion packages/python/tanstack-ai/src/tanstack_ai/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ class CustomEvent(TypedDict, total=False):
timestamp: int
model: Optional[str]
name: str
data: Optional[Any]
value: Optional[Any]


# Union of all AG-UI events
Expand Down
8 changes: 4 additions & 4 deletions packages/typescript/ai/src/activities/chat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ class TextEngine<
timestamp: Date.now(),
model: finishEvent.model,
name: 'approval-requested',
data: {
value: {
toolCallId: approval.toolCallId,
toolName: approval.toolName,
input: approval.input,
Expand Down Expand Up @@ -879,7 +879,7 @@ class TextEngine<
timestamp: Date.now(),
model: finishEvent.model,
name: 'tool-input-available',
data: {
value: {
toolCallId: clientTool.toolCallId,
toolName: clientTool.toolName,
input: clientTool.input,
Expand Down Expand Up @@ -1094,14 +1094,14 @@ class TextEngine<

private createCustomEventChunk(
eventName: string,
data: Record<string, any>,
value: Record<string, any>,
): CustomEvent {
return {
type: 'CUSTOM',
timestamp: Date.now(),
model: this.params.model,
name: eventName,
data,
value,
}
}

Expand Down
12 changes: 6 additions & 6 deletions packages/typescript/ai/src/activities/chat/stream/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -814,8 +814,8 @@ export class StreamProcessor {
chunk: Extract<StreamChunk, { type: 'CUSTOM' }>,
): void {
// Handle client tool input availability - trigger client-side execution
if (chunk.name === 'tool-input-available' && chunk.data) {
const { toolCallId, toolName, input } = chunk.data as {
if (chunk.name === 'tool-input-available' && chunk.value) {
const { toolCallId, toolName, input } = chunk.value as {
toolCallId: string
toolName: string
input: any
Expand All @@ -832,8 +832,8 @@ export class StreamProcessor {
}

// Handle approval requests
if (chunk.name === 'approval-requested' && chunk.data) {
const { toolCallId, toolName, input, approval } = chunk.data as {
if (chunk.name === 'approval-requested' && chunk.value) {
const { toolCallId, toolName, input, approval } = chunk.value as {
toolCallId: string
toolName: string
input: any
Expand Down Expand Up @@ -863,8 +863,8 @@ export class StreamProcessor {
}

// Forward all other custom events to the callback
this.events.onCustomEvent?.(chunk.name, chunk.data, {
toolCallId: (chunk.data as any)?.toolCallId,
this.events.onCustomEvent?.(chunk.name, chunk.value, {
toolCallId: (chunk.value as any)?.toolCallId,
})
}

Expand Down
4 changes: 2 additions & 2 deletions packages/typescript/ai/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -922,8 +922,8 @@ export interface CustomEvent extends BaseAGUIEvent {
type: 'CUSTOM'
/** Custom event name */
name: string
/** Custom event data */
data?: unknown
/** Custom event value */
value?: unknown
}

/**
Expand Down
Loading