Open History to see the last commit
1import { test, expect } from './fixtures'
2import { sendMessage, waitForResponse, featureUrl } from './helpers'
3
4test.describe('AG-UI message metadata', () => {
5 test('stamps user metadata onto the UIMessage and the RunAgentInput wire', async ({
6 page,
7 testId,
8 aimockPort,
9 }) => {
10 const requestBodies: Array<any> = []
11 page.on('request', (request) => {
12 if (request.url().includes('/api/chat') && request.method() === 'POST') {
13 const body = request.postDataJSON()
14 if (body) requestBodies.push(body)
15 }
16 })
17
18 await page.goto(
19 featureUrl('openai', 'chat', testId, aimockPort) + '&stampMetadata=1',
20 )
21
22 await sendMessage(page, '[chat] hello')
23 await waitForResponse(page)
24
25 await expect(page.getByTestId('user-metadata')).toContainText('user-42')
26
27 expect(requestBodies.length).toBeGreaterThanOrEqual(1)
28 const first = requestBodies[0]!
29 const user = first.messages.find((m: any) => m.role === 'user')
30 expect(user).toBeDefined()
31 expect(user.metadata.author.id).toBe('user-42')
32 expect(user).not.toHaveProperty('parts')
33 })
34})