Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

ag-ui-foreign-client.spec.ts

111 lines3.1 KB

1import { test, expect } from './fixtures'
2​
3test.describe('AG-UI foreign client compatibility', () => {
4 test('TanStack server accepts pure RunAgentInput with fan-out tool messages', async ({
5 request,
6 testId,
7 aimockPort,
8 }) => {
9 const body = {
10 threadId: 'thread-foreign-1',
11 runId: 'run-foreign-1',
12 state: {},
13 messages: [
14 { id: 'u1', role: 'user', content: '[chat] recommend a guitar' },
15 ],
16 tools: [],
17 context: [],
18 forwardedProps: {
19 provider: 'openai',
20 feature: 'chat',
21 testId,
22 aimockPort,
23 },
24 }
25 const response = await request.post('/api/chat', {
26 data: body,
27 headers: { 'Content-Type': 'application/json' },
28 })
29 expect(
30 response.ok(),
31 `expected 200, got ${response.status()}: ${await response.text()}`,
32 ).toBe(true)
33 const text = await response.text()
34 expect(text).toContain('RUN_FINISHED')
35 })
36​
37 test('encrypted reasoning names a reasoning message the client can find', async ({
38 request,
39 testId,
40 aimockPort,
41 }) => {
42 const response = await request.post('/api/chat', {
43 data: {
44 threadId: 'thread-foreign-3',
45 runId: 'run-foreign-3',
46 state: {},
47 messages: [
48 {
49 id: 'u1',
50 role: 'user',
51 content: '[reasoning] recommend a guitar for a beginner',
52 },
53 ],
54 tools: [],
55 context: [],
56 forwardedProps: {
57 provider: 'openai',
58 feature: 'reasoning',
59 testId,
60 aimockPort,
61 },
62 },
63 headers: { 'Content-Type': 'application/json' },
64 })
65 expect(response.ok()).toBe(true)
66​
67 const events: Array<Record<string, unknown>> = (await response.text())
68 .split('\n')
69 .filter((line) => line.startsWith('data: {'))
70 .map((line) => JSON.parse(line.slice('data: '.length)))
71 const reasoningIds = events
72 .filter((event) => event.type === 'REASONING_MESSAGE_START')
73 .map((event) => event.messageId)
74 const targets = events
75 .filter((event) => event.type === 'REASONING_ENCRYPTED_VALUE')
76 .map((event) => event.entityId)
77​
78 expect(targets.length).toBeGreaterThan(0)
79 // An AG-UI client attaches each value to the message with this id.
80 for (const id of targets) expect(reasoningIds).toContain(id)
81 })
82​
83 test('developer role is collapsed to system without breaking the run', async ({
84 request,
85 testId,
86 aimockPort,
87 }) => {
88 const body = {
89 threadId: 'thread-foreign-2',
90 runId: 'run-foreign-2',
91 state: {},
92 messages: [
93 { id: 'd1', role: 'developer', content: 'You only speak in haiku.' },
94 { id: 'u1', role: 'user', content: '[chat] recommend a guitar' },
95 ],
96 tools: [],
97 context: [],
98 forwardedProps: {
99 provider: 'openai',
100 feature: 'chat',
101 testId,
102 aimockPort,
103 },
104 }
105 const response = await request.post('/api/chat', {
106 data: body,
107 headers: { 'Content-Type': 'application/json' },
108 })
109 expect(response.ok()).toBe(true)
110 })
111})