Skip to content
Open
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
6 changes: 6 additions & 0 deletions .changeset/run-input-protocol-version.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@tanstack/ai': patch
'@tanstack/ai-client': patch
---

Connection adapters now send the AG-UI `protocolVersion` (`"1.0"`) in the `RunAgentInput` request body, as the AG-UI spec asks. `@tanstack/ai/client` re-exports `PROTOCOL_VERSION`.
2 changes: 2 additions & 0 deletions packages/ai-client/src/connection-adapters.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
EventType,
PROTOCOL_VERSION,
getChunkRunId as getNormalizedChunkRunId,
restoreInboundChunk,
uiMessagesToWire,
Expand Down Expand Up @@ -1416,6 +1417,7 @@ function buildRunAgentInputBody(
return {
threadId: runContext.threadId,
runId: runContext.runId,
protocolVersion: PROTOCOL_VERSION,
...(runContext.parentRunId !== undefined && {
parentRunId: runContext.parentRunId,
}),
Expand Down
25 changes: 25 additions & 0 deletions packages/ai-client/tests/connection-adapters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,31 @@ describe('connection-adapters', () => {
expect(body.forwardedProps).toMatchObject({ key: 'value' })
})

it('should send the AG-UI protocolVersion in the request body', async () => {
fetchMock.mockResolvedValue({
ok: true,
body: {
getReader: () => ({
read: vi.fn().mockResolvedValue({ done: true, value: undefined }),
releaseLock: vi.fn(),
}),
},
} as any)

const adapter = fetchServerSentEvents('/api/chat')
for await (const _ of adapter.connect(
[{ role: 'user', content: 'Hello' }],
undefined,
undefined,
RUN_CONTEXT,
)) {
// Consume
}

const body = JSON.parse(fetchMock.mock.calls[0]?.[1]?.body as string)
expect(body.protocolVersion).toBe('1.0')
})

it('should use custom fetchClient when provided', async () => {
const customFetch = vi.fn()
const mockReader = {
Expand Down
2 changes: 1 addition & 1 deletion packages/ai/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export async function generationParamsFromRequest<TKind extends GenerationKind>(
return generationParamsFromBody(kind, body)
}

export { EventType } from '@ag-ui/core'
export { EventType, PROTOCOL_VERSION } from '@ag-ui/core'
export type { RunAgentInput } from '@ag-ui/core'

export {
Expand Down
2 changes: 2 additions & 0 deletions testing/e2e/tests/ag-ui-compliance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ test.describe('AG-UI client-to-server compliance', () => {
expect(body).toHaveProperty('tools')
expect(body).toHaveProperty('context')
expect(body).toHaveProperty('forwardedProps')
// AG-UI 1.0: the client states its protocol version in-band.
expect(body.protocolVersion).toBe('1.0')
expect(Array.isArray(body.messages)).toBe(true)
expect(Array.isArray(body.tools)).toBe(true)
}
Expand Down