Open History to see the last commit
1import { test, expect } from './fixtures'
2
3/**
4 * Wire format of OpenAI computer use. The model sends a `computer_call`, the
5 * app runs it, and the next request sends the call back with its
6 * `computer_call_output`.
7 *
8 * `/api/openai-computer-use-wire` serves the model responses with a custom
9 * `fetch` and returns the tool inputs and the request bodies as JSON.
10 */
11test.describe('openai — computer use wire format', () => {
12 test('runs the batched actions of the computer tool', async ({ request }) => {
13 const res = await request.post('/api/openai-computer-use-wire')
14 expect(res.ok()).toBe(true)
15 const { ok, error, toolInputs, requestBodies } = (await res.json()) as {
16 ok: boolean
17 error?: string
18 toolInputs: Array<unknown>
19 requestBodies: Array<{ tools?: Array<unknown>; input: Array<unknown> }>
20 }
21
22 if (!ok) {
23 throw new Error(`Route failed: ${error}`)
24 }
25
26 const safetyCheck = {
27 id: 'sc_e2e',
28 code: 'malicious_instructions',
29 message: 'The page asks the model to do something else.',
30 }
31 const actions = [
32 { type: 'click', button: 'left', x: 10, y: 20 },
33 { type: 'type', text: 'hello' },
34 ]
35 expect(toolInputs).toEqual([
36 { actions, pending_safety_checks: [safetyCheck] },
37 ])
38 expect(requestBodies).toHaveLength(2)
39 expect(requestBodies[0]!.tools).toEqual([{ type: 'computer' }])
40 expect(requestBodies[1]!.input).toEqual(
41 expect.arrayContaining([
42 expect.objectContaining({
43 type: 'computer_call',
44 call_id: 'call_cu_e2e_batch',
45 actions,
46 }),
47 {
48 type: 'computer_call_output',
49 call_id: 'call_cu_e2e_batch',
50 output: {
51 type: 'computer_screenshot',
52 image_url: 'data:image/png;base64,iVBORw0KGgo=',
53 detail: 'original',
54 },
55 acknowledged_safety_checks: [safetyCheck],
56 },
57 ]),
58 )
59 })
60})