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

responses-answer-items-wire.spec.ts

39 lines1.3 KB

1import { test, expect } from './fixtures'
2​
3/**
4 * An OpenAI Responses answer item keeps its `id` and `phase` through the
5 * client and the wire. The same model gets them back. Another model gets
6 * plain text. `/api/responses-answer-items-wire` returns the assistant items
7 * of each request.
8 */
9test.describe('OpenAI Responses answer items on replay', () => {
10 test('sends id and phase to the same model and plain text to another model', async ({
11 request,
12 }) => {
13 const response = await request.post('/api/responses-answer-items-wire')
14 expect(response.ok()).toBe(true)
15 const result = (await response.json()) as {
16 ok: boolean
17 error?: string
18 calls: number
19 sameModel: Array<Record<string, unknown>>
20 otherModel: Array<Record<string, unknown>>
21 }
22 if (!result.ok) throw new Error(`Route failed: ${result.error}`)
23​
24 expect(result.calls).toBe(3)
25 expect(result.sameModel).toEqual([
26 {
27 type: 'message',
28 role: 'assistant',
29 id: 'msg_answer_1',
30 status: 'completed',
31 phase: 'final_answer',
32 content: [{ type: 'output_text', text: 'Hi there', annotations: [] }],
33 },
34 ])
35 expect(result.otherModel).toEqual([
36 { type: 'message', role: 'assistant', content: 'Hi there' },
37 ])
38 })
39})