Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 20 additions & 0 deletions .changeset/ag-ui-events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
'@tanstack/ai': minor
'@tanstack/ai-client': minor
'@tanstack/ai-openai': minor
'@tanstack/ai-anthropic': minor
'@tanstack/ai-gemini': minor
'@tanstack/ai-grok': minor
'@tanstack/ai-ollama': minor
'@tanstack/ai-openrouter': minor
Comment on lines +2 to +9
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

BREAKING: This must be a major version bump, not minor.

The change explicitly states "previous legacy chunk formats are no longer accepted" (line 20), which is a breaking API change. Per semantic versioning, breaking changes require a major version bump, not minor.

📋 Proposed fix
 ---
-'@tanstack/ai': minor
-'@tanstack/ai-client': minor
-'@tanstack/ai-openai': minor
-'@tanstack/ai-anthropic': minor
-'@tanstack/ai-gemini': minor
-'@tanstack/ai-grok': minor
-'@tanstack/ai-ollama': minor
-'@tanstack/ai-openrouter': minor
+'@tanstack/ai': major
+'@tanstack/ai-client': major
+'@tanstack/ai-openai': major
+'@tanstack/ai-anthropic': major
+'@tanstack/ai-gemini': major
+'@tanstack/ai-grok': major
+'@tanstack/ai-ollama': major
+'@tanstack/ai-openrouter': major
 ---
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
'@tanstack/ai': minor
'@tanstack/ai-client': minor
'@tanstack/ai-openai': minor
'@tanstack/ai-anthropic': minor
'@tanstack/ai-gemini': minor
'@tanstack/ai-grok': minor
'@tanstack/ai-ollama': minor
'@tanstack/ai-openrouter': minor
---
'@tanstack/ai': major
'@tanstack/ai-client': major
'@tanstack/ai-openai': major
'@tanstack/ai-anthropic': major
'@tanstack/ai-gemini': major
'@tanstack/ai-grok': major
'@tanstack/ai-ollama': major
'@tanstack/ai-openrouter': major
🤖 Prompt for AI Agents
In @.changeset/ag-ui-events.md around lines 2 - 9, The changeset currently marks
several packages ('@tanstack/ai', '@tanstack/ai-client', '@tanstack/ai-openai',
'@tanstack/ai-anthropic', '@tanstack/ai-gemini', '@tanstack/ai-grok',
'@tanstack/ai-ollama', '@tanstack/ai-openrouter') as "minor" but the diff and
content state that legacy chunk formats are no longer accepted (breaking API),
so update the changeset to mark each of those package entries as "major" instead
of "minor" and ensure the changeset message reflects the breaking change so the
release tooling will perform a major bump for these packages.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

# First, let's understand the repository structure
find . -maxdepth 3 -type d -name "packages" | head -5
ls -la packages/typescript/ 2>/dev/null | grep "ai" || echo "Checking alternate structure..."

Repository: TanStack/ai

Length of output: 1433


🏁 Script executed:

#!/bin/bash
# Description: Verify AG-UI event implementation in all listed adapters.

# Search for AG-UI event type usage in each adapter package
for pkg in ai ai-client ai-openai ai-anthropic ai-gemini ai-grok ai-ollama ai-openrouter; do
  echo "=== Checking `@tanstack/`$pkg ==="
  
  # Look for AG-UI event emissions (RUN_STARTED, TEXT_MESSAGE_START, etc.)
  rg -n --type=ts -C2 'RUN_STARTED|TEXT_MESSAGE_START|TOOL_CALL_START|RUN_FINISHED|RUN_ERROR' \
    "packages/typescript/$pkg/src/" 2>/dev/null || echo "  ⚠️  No AG-UI events found"
  
  echo ""
done

Repository: TanStack/ai

Length of output: 47126


Remove @tanstack/ai-client from the changeset or add AG-UI event implementations.

Verification found that @tanstack/ai-client does not contain AG-UI event implementations (RUN_STARTED, TEXT_MESSAGE_START, TOOL_CALL_START, RUN_FINISHED, RUN_ERROR), unlike the other 8 adapter packages. Either this package should be removed from the changeset, or the missing AG-UI event handling should be implemented before release.

The initially questioned packages (@tanstack/ai-grok and @tanstack/ai-openrouter) do have AG-UI event implementations and can remain in the changeset.

🤖 Prompt for AI Agents
In @.changeset/ag-ui-events.md around lines 2 - 9, The changeset erroneously
includes '@tanstack/ai-client' which lacks AG-UI event implementations; either
remove '@tanstack/ai-client' from the changeset or implement the missing AG-UI
event handlers (RUN_STARTED, TEXT_MESSAGE_START, TOOL_CALL_START, RUN_FINISHED,
RUN_ERROR) inside the '@tanstack/ai-client' adapter (add the corresponding
event-emission or handling code and tests to match the other adapters such as
'@tanstack/ai-grok' and '@tanstack/ai-openrouter'); ensure the adapter exports
or wires the same event constants/handlers so the release contains consistent
AG-UI support.

---

feat: Add AG-UI protocol events to streaming system

All text adapters now emit AG-UI protocol events only:

- `RUN_STARTED` / `RUN_FINISHED` - Run lifecycle events
- `TEXT_MESSAGE_START` / `TEXT_MESSAGE_CONTENT` / `TEXT_MESSAGE_END` - Text message streaming
- `TOOL_CALL_START` / `TOOL_CALL_ARGS` / `TOOL_CALL_END` - Tool call streaming

Comment on lines +14 to +19
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Document all AG-UI event types introduced in this PR.

The changeset omits several event types mentioned in the broader PR changes. Based on the AI summary, the following event types are also part of the AG-UI protocol but are not documented here:

  • RUN_ERROR — error lifecycle event
  • STEP_STARTED / STEP_FINISHED — step lifecycle events
  • STATE_SNAPSHOT / STATE_DELTA — state events
  • CUSTOM — custom events

Include all introduced event types in the changeset description to provide a complete changelog for users.

🤖 Prompt for AI Agents
In @.changeset/ag-ui-events.md around lines 14 - 19, Update the changeset text
to document all AG-UI protocol events introduced in the PR by adding the missing
event types and short descriptions: include RUN_ERROR (error lifecycle event),
STEP_STARTED and STEP_FINISHED (step lifecycle events), STATE_SNAPSHOT and
STATE_DELTA (state events), and CUSTOM (custom events), alongside the already
listed RUN_STARTED/RUN_FINISHED, TEXT_MESSAGE_*, and TOOL_CALL_* entries; ensure
each event name (e.g., RUN_ERROR, STEP_STARTED, STATE_SNAPSHOT, CUSTOM) appears
in the list with a one-line description so the changelog fully reflects the
protocol surface.

Only AG-UI event types are supported; previous legacy chunk formats (`content`, `tool_call`, `done`, etc.) are no longer accepted.
23 changes: 13 additions & 10 deletions docs/guides/streaming.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,30 +63,33 @@ messages.forEach((message) => {
});
```

## Stream Chunks
## Stream Events (AG-UI Protocol)

Stream chunks contain different types of data:
TanStack AI implements the [AG-UI Protocol](https://docs.ag-ui.com/introduction) for streaming. Stream events contain different types of data:

- **Content chunks** - Text content being generated
- **Thinking chunks** - Model's internal reasoning process (when supported)
- **Tool call chunks** - When the model calls a tool
- **Tool result chunks** - Results from tool execution
- **Done chunks** - Stream completion
### AG-UI Events

- **RUN_STARTED** - Emitted when a run begins
- **TEXT_MESSAGE_START/CONTENT/END** - Text content streaming lifecycle
- **TOOL_CALL_START/ARGS/END** - Tool invocation lifecycle
- **STEP_STARTED/STEP_FINISHED** - Thinking/reasoning steps
- **RUN_FINISHED** - Run completion with finish reason and usage
- **RUN_ERROR** - Error occurred during the run

### Thinking Chunks

Thinking chunks represent the model's reasoning process. They stream separately from the final response text:
Thinking/reasoning is represented by AG-UI events `STEP_STARTED` and `STEP_FINISHED`. They stream separately from the final response text:

```typescript
for await (const chunk of stream) {
if (chunk.type === "thinking") {
if (chunk.type === "STEP_FINISHED") {
console.log("Thinking:", chunk.content); // Accumulated thinking content
console.log("Delta:", chunk.delta); // Incremental thinking token
}
}
```

Thinking chunks are automatically converted to `ThinkingPart` in `UIMessage` objects. They are UI-only and excluded from messages sent back to the model.
Thinking content is automatically converted to `ThinkingPart` in `UIMessage` objects. It is UI-only and excluded from messages sent back to the model.

## Connection Adapters

Expand Down
Loading
Loading