Open History to see the last commit
1import { test, expect } from '@playwright/test'
2import {
3 EventType,
4 INTERRUPT_PAYLOAD_METADATA_KEY,
5 chat,
6 genericInterruptContinuationFromDescriptor,
7 wrapGenericInterruptContinuation,
8} from '@tanstack/ai'
9import { createAnthropicChat } from '@tanstack/ai-anthropic'
10import { createComputerUse } from '@tanstack/ai-computer-use'
11import { computerUse } from '@tanstack/ai-computer-use/harness'
12import { createHarnessHost, defineHarness } from '@tanstack/ai-harness'
13import { permissions } from '@tanstack/ai-harness/plugins'
14import { memoryPersistence } from '@tanstack/ai-persistence'
15import {
16 createPlaywrightComputerDriver,
17 playwrightComputer,
18} from '@tanstack/ai-computer-playwright'
19import { localComputer } from '@tanstack/ai-computer-local'
20import { createOpenaiChat } from '@tanstack/ai-openai'
21import type { Browser, BrowserContext, Locator, Page } from '@playwright/test'
22import type { ModelMessage, StreamChunk } from '@tanstack/ai'
23import type { RobotLike } from '@tanstack/ai-computer-local'
24
25/**
26 * Computer use from end to end. A real Playwright page is the computer.
27 * `createComputerUse` with the Playwright driver runs the actions on it.
28 * `playwrightComputer` makes one page for each thread from the `browser`
29 * fixture. `localComputer` runs on a fake robot, because CI has no desktop.
30 *
31 * `chat()` runs in the spec process. A mock `fetch` sends the model streams
32 * and keeps each request body. No app server and no API key are used.
33 */
34
35const PAGE_HTML = `
36 <button id="go" onclick="document.getElementById('status').textContent = 'clicked'">Go</button>
37 <p id="status">idle</p>
38 <input id="name" />
39`
40
41const START_URL = 'https://computer.test/start'
42const FORM_URL = 'https://computer.test/form'
43
44const USER_MESSAGE: ModelMessage = { role: 'user', content: 'Fill the form.' }
45
46const SAFETY_CHECK = {
47 id: 'sc_e2e',
48 code: 'malicious_instructions',
49 message: 'The page asks the model to do something else.',
50}
51
52/** The `navigate` function tool in an OpenAI request body. */
53const OPENAI_NAVIGATE_TOOL = { type: 'function', name: 'navigate' }
54
55type MockModel = ReturnType<typeof mockModel>
56type ComputerUse = ReturnType<typeof createComputerUse>
57
58/** A mock `fetch` that sends one stream per request, in order. */
59function mockModel(streams: Array<() => ReadableStream<Uint8Array>>) {
60 const bodies: Array<unknown> = []
61 const fetch: typeof globalThis.fetch = async (input, init) => {
62 const request = input instanceof Request ? input : new Request(input, init)
63 bodies.push(JSON.parse(await request.text()))
64 const stream = streams[bodies.length - 1]
65 if (!stream)
66 throw new Error(`No model response for request ${bodies.length}`)
67 return new Response(stream(), {
68 status: 200,
69 headers: { 'Content-Type': 'text/event-stream' },
70 })
71 }
72 return { fetch, bodies }
73}
74
75function sse(lines: Array<string>) {
76 const encoder = new TextEncoder()
77 return new ReadableStream<Uint8Array>({
78 start(controller) {
79 for (const line of lines) controller.enqueue(encoder.encode(line))
80 controller.close()
81 },
82 })
83}
84
85/** An OpenAI Responses stream that completes with `output`. */
86function openaiStream(id: string, output: Array<unknown>) {
87 const events = [
88 {
89 type: 'response.created',
90 response: { id, object: 'response', status: 'in_progress', output: [] },
91 },
92 {
93 type: 'response.completed',
94 response: {
95 id,
96 object: 'response',
97 status: 'completed',
98 output,
99 usage: { input_tokens: 5, output_tokens: 2, total_tokens: 7 },
100 },
101 },
102 ]
103 return () =>
104 sse([
105 ...events.map((event) => `data: ${JSON.stringify(event)}\n\n`),
106 'data: [DONE]\n\n',
107 ])
108}
109
110/** An OpenAI `computer_call` item with one action and no safety checks. */
111function computerCall(
112 name: string,
113 action: { type: string; [field: string]: unknown },
114) {
115 return {
116 type: 'computer_call',
117 id: `cu_${name}`,
118 call_id: `call_cu_${name}`,
119 status: 'completed',
120 action,
121 pending_safety_checks: [],
122 }
123}
124
125const OPENAI_ANSWER = {
126 type: 'message',
127 id: 'msg_cu_e2e',
128 role: 'assistant',
129 status: 'completed',
130 content: [{ type: 'output_text', text: 'Done.', annotations: [] }],
131}
132
133/** An Anthropic Messages stream. */
134function anthropicStream(events: Array<{ type: string }>) {
135 return () =>
136 sse(
137 events.map(
138 (event) => `event: ${event.type}\ndata: ${JSON.stringify(event)}\n\n`,
139 ),
140 )
141}
142
143const ANTHROPIC_START = {
144 type: 'message_start',
145 message: {
146 id: 'msg_cu_e2e',
147 type: 'message',
148 role: 'assistant',
149 content: [],
150 model: 'claude-opus-5-5',
151 stop_reason: null,
152 stop_sequence: null,
153 usage: { input_tokens: 5, output_tokens: 0 },
154 },
155}
156
157function anthropicEnd(stopReason: string) {
158 return [
159 {
160 type: 'message_delta',
161 delta: { stop_reason: stopReason, stop_sequence: null },
162 usage: { output_tokens: 1 },
163 },
164 { type: 'message_stop' },
165 ]
166}
167
168/** The blocks of one toolset call of the `computer` toolset. */
169function toolsetCall(index: number, id: string, name: string, input: unknown) {
170 return [
171 {
172 type: 'content_block_start',
173 index,
174 content_block: {
175 type: 'tool_use',
176 id,
177 name,
178 toolset_name: 'computer',
179 input: {},
180 },
181 },
182 {
183 type: 'content_block_delta',
184 index,
185 delta: { type: 'input_json_delta', partial_json: JSON.stringify(input) },
186 },
187 { type: 'content_block_stop', index },
188 ]
189}
190
191async function openForm(page: Page) {
192 await page.setContent(PAGE_HTML)
193 return {
194 button: await centerOf(page.locator('#go')),
195 input: await centerOf(page.locator('#name')),
196 }
197}
198
199async function centerOf(locator: Locator) {
200 const box = await locator.boundingBox()
201 if (!box) throw new Error('The element has no bounding box.')
202 return {
203 x: Math.round(box.x + box.width / 2),
204 y: Math.round(box.y + box.height / 2),
205 }
206}
207
208function computerUseFor(page: Page) {
209 return createComputerUse({
210 driver: createPlaywrightComputerDriver({ page }),
211 screenshotDelay: 0,
212 })
213}
214
215/**
216 * Computer use with `playwrightComputer` on the `browser` fixture. Each new
217 * context serves `PAGE_HTML` for every `https://computer.test` URL. The
218 * contexts stay in `contexts` in the order the threads open them.
219 */
220function routedComputerUse(browser: Browser) {
221 const contexts: Array<BrowserContext> = []
222 const computerUse = createComputerUse({
223 driver: playwrightComputer({
224 startUrl: START_URL,
225 browser: {
226 async newContext(options) {
227 const context = await browser.newContext(options)
228 await context.route('https://computer.test/**', (route) =>
229 route.fulfill({ contentType: 'text/html', body: PAGE_HTML }),
230 )
231 contexts.push(context)
232 return context
233 },
234 close: () => browser.close(),
235 },
236 }),
237 screenshotDelay: 0,
238 })
239 return { computerUse, contexts }
240}
241
242/** The one page that the factory opens in a context. */
243function pageOf(context: BrowserContext) {
244 const [page] = context.pages()
245 if (!page) throw new Error('The context has no page.')
246 return page
247}
248
249function openaiAdapter(model: MockModel) {
250 return createOpenaiChat('gpt-6.1-sol', 'sk-e2e-dummy', {
251 fetch: model.fetch,
252 })
253}
254
255/** Run one OpenAI chat with computer use in a thread, to the end. */
256function runOpenai(
257 computerUse: ComputerUse,
258 model: MockModel,
259 threadId: string,
260) {
261 return drain(
262 chat({
263 adapter: openaiAdapter(model),
264 messages: [USER_MESSAGE],
265 threadId,
266 tools: computerUse.tools,
267 middleware: [computerUse.middleware],
268 interrupts: [computerUse.interrupt],
269 }),
270 )
271}
272
273async function drain(stream: AsyncIterable<StreamChunk>) {
274 const chunks: Array<StreamChunk> = []
275 for await (const chunk of stream) chunks.push(chunk)
276 return chunks
277}
278
279/** The assistant message with the tool calls of a paused run. */
280function assistantFromChunks(chunks: Array<StreamChunk>): ModelMessage {
281 const toolCalls = chunks.flatMap((chunk) => {
282 if (chunk.type !== EventType.TOOL_CALL_START) return []
283 const end = chunks.find(
284 (item) =>
285 item.type === EventType.TOOL_CALL_END &&
286 item.toolCallId === chunk.toolCallId,
287 )
288 const input = end?.type === EventType.TOOL_CALL_END ? end.input : {}
289 return [
290 {
291 id: chunk.toolCallId,
292 type: 'function' as const,
293 function: {
294 name: chunk.toolCallName,
295 arguments: JSON.stringify(input),
296 },
297 metadata: chunk.metadata,
298 },
299 ]
300 })
301 return { role: 'assistant', content: null, toolCalls }
302}
303
304function interruptOutcome(chunks: Array<StreamChunk>) {
305 const finished = chunks.find((chunk) => chunk.type === EventType.RUN_FINISHED)
306 const outcome =
307 finished?.type === EventType.RUN_FINISHED ? finished.outcome : undefined
308 if (outcome?.type !== 'interrupt') {
309 throw new Error('The run did not end with an interrupt.')
310 }
311 return outcome.interrupts
312}
313
314test.describe('computer use with a Playwright page', () => {
315 test('openai computer tool runs a batch of actions on the page', async ({
316 page,
317 }) => {
318 const { button, input } = await openForm(page)
319 const computerUse = computerUseFor(page)
320 const model = mockModel([
321 openaiStream('resp_cu_1', [
322 {
323 type: 'computer_call',
324 id: 'cu_batch',
325 call_id: 'call_cu_batch',
326 status: 'completed',
327 actions: [
328 { type: 'click', button: 'left', ...button },
329 { type: 'click', button: 'left', ...input },
330 { type: 'type', text: 'hello' },
331 ],
332 pending_safety_checks: [],
333 },
334 ]),
335 openaiStream('resp_cu_2', [OPENAI_ANSWER]),
336 ])
337
338 await runOpenai(computerUse, model, 'thread-cu-batch')
339
340 await expect(page.locator('#status')).toHaveText('clicked')
341 await expect(page.locator('#name')).toHaveValue('hello')
342 expect(model.bodies).toHaveLength(2)
343 // The Playwright driver can navigate, so the `navigate` tool goes too.
344 expect(model.bodies[0]).toMatchObject({
345 tools: [{ type: 'computer' }, OPENAI_NAVIGATE_TOOL],
346 })
347 expect(model.bodies[1]).toMatchObject({
348 input: expect.arrayContaining([
349 expect.objectContaining({
350 type: 'computer_call_output',
351 call_id: 'call_cu_batch',
352 output: expect.objectContaining({
353 type: 'computer_screenshot',
354 image_url: expect.stringMatching(/^data:image\/png;base64,./),
355 }),
356 }),
357 ]),
358 })
359 })
360
361 test('anthropic computer toolset runs each call on the page', async ({
362 page,
363 }) => {
364 const { button, input } = await openForm(page)
365 const computerUse = computerUseFor(page)
366 const model = mockModel([
367 anthropicStream([
368 ANTHROPIC_START,
369 ...toolsetCall(0, 'toolu_button', 'left_click', {
370 coordinate: [button.x, button.y],
371 }),
372 ...toolsetCall(1, 'toolu_input', 'left_click', {
373 coordinate: [input.x, input.y],
374 }),
375 ...toolsetCall(2, 'toolu_type', 'type', { text: 'hello' }),
376 ...anthropicEnd('tool_use'),
377 ]),
378 anthropicStream([ANTHROPIC_START, ...anthropicEnd('end_turn')]),
379 ])
380
381 await drain(
382 chat({
383 adapter: createAnthropicChat('claude-opus-5-5', 'sk-ant-e2e-dummy', {
384 fetch: model.fetch,
385 }),
386 messages: [USER_MESSAGE],
387 threadId: 'thread-cu-toolset',
388 tools: computerUse.tools,
389 middleware: [computerUse.middleware],
390 interrupts: [computerUse.interrupt],
391 }),
392 )
393
394 await expect(page.locator('#status')).toHaveText('clicked')
395 await expect(page.locator('#name')).toHaveValue('hello')
396 expect(model.bodies).toHaveLength(2)
397 // The Playwright driver has zoom and no cursor position. It can
398 // navigate, so the `navigate` tool goes too, as a custom tool.
399 expect(model.bodies[0]).toMatchObject({
400 tools: [
401 {
402 type: 'computer_toolset_20260801',
403 configs: {
404 zoom: { enabled: true },
405 cursor_position: { enabled: false },
406 },
407 },
408 { type: 'custom', name: 'navigate' },
409 ],
410 })
411 const screenshotResult = (toolUseId: string) =>
412 expect.objectContaining({
413 type: 'tool_result',
414 tool_use_id: toolUseId,
415 content: expect.arrayContaining([
416 expect.objectContaining({
417 type: 'image',
418 source: expect.objectContaining({
419 type: 'base64',
420 data: expect.stringMatching(/^./),
421 }),
422 }),
423 ]),
424 })
425 expect(model.bodies[1]).toMatchObject({
426 messages: expect.arrayContaining([
427 expect.objectContaining({
428 role: 'user',
429 content: expect.arrayContaining([
430 screenshotResult('toolu_button'),
431 screenshotResult('toolu_input'),
432 screenshotResult('toolu_type'),
433 ]),
434 }),
435 ]),
436 })
437 })
438
439 test('openai safety check pauses the action until a person approves it', async ({
440 page,
441 }) => {
442 const { button } = await openForm(page)
443 const computerUse = computerUseFor(page)
444 const click = { type: 'click', button: 'left', ...button }
445 const model = mockModel([
446 openaiStream('resp_cu_1', [
447 {
448 ...computerCall('checked', click),
449 pending_safety_checks: [SAFETY_CHECK],
450 },
451 ]),
452 openaiStream('resp_cu_2', [OPENAI_ANSWER]),
453 ])
454 const adapter = openaiAdapter(model)
455 // `createComputerUse` keeps the approvals per thread. So both runs use
456 // the same thread.
457 const threadId = 'thread-cu-safety'
458
459 // Run 1 ends with the safety-check interrupt. The click waits.
460 const first = await drain(
461 chat({
462 adapter,
463 messages: [USER_MESSAGE],
464 tools: computerUse.tools,
465 middleware: [computerUse.middleware],
466 interrupts: [computerUse.interrupt],
467 threadId,
468 runId: 'run-cu-safety-1',
469 }),
470 )
471 const [paused, ...others] = interruptOutcome(first)
472 expect(others).toEqual([])
473 if (!paused) throw new Error('No interrupt in the outcome.')
474 expect(paused.metadata?.[INTERRUPT_PAYLOAD_METADATA_KEY]).toEqual({
475 checks: [SAFETY_CHECK],
476 action: click,
477 })
478 await expect(page.locator('#status')).toHaveText('idle')
479 expect(model.bodies).toHaveLength(1)
480
481 const continuation = genericInterruptContinuationFromDescriptor(paused)
482 if (!continuation) throw new Error('The interrupt has no continuation.')
483 expect(continuation).toMatchObject({
484 definitionId: 'computer-safety-check',
485 key: 'call_cu_checked',
486 })
487
488 // Run 2 approves the check. The click runs, and the model gets the result.
489 await drain(
490 chat({
491 adapter,
492 messages: [USER_MESSAGE, assistantFromChunks(first)],
493 tools: computerUse.tools,
494 middleware: [computerUse.middleware],
495 interrupts: [computerUse.interrupt],
496 threadId,
497 runId: 'run-cu-safety-2',
498 parentRunId: 'run-cu-safety-1',
499 resume: [
500 {
501 interruptId: paused.id,
502 status: 'resolved',
503 payload: { approved: true },
504 metadata: wrapGenericInterruptContinuation(continuation),
505 },
506 ],
507 }),
508 )
509
510 await expect(page.locator('#status')).toHaveText('clicked')
511 expect(model.bodies).toHaveLength(2)
512 expect(model.bodies[1]).toMatchObject({
513 input: expect.arrayContaining([
514 expect.objectContaining({
515 type: 'computer_call',
516 call_id: 'call_cu_checked',
517 action: click,
518 }),
519 expect.objectContaining({
520 type: 'computer_call_output',
521 call_id: 'call_cu_checked',
522 output: expect.objectContaining({
523 image_url: expect.stringMatching(/^data:image\/png;base64,./),
524 }),
525 acknowledged_safety_checks: [SAFETY_CHECK],
526 }),
527 ]),
528 })
529 })
530})
531
532test.describe('computer use in a harness', () => {
533 test('the harness asks about an openai safety check, clicks after a yes, and stores the screenshot', async ({
534 page,
535 }) => {
536 const { button } = await openForm(page)
537 const click = { type: 'click', button: 'left', ...button }
538 const model = mockModel([
539 openaiStream('resp_cu_harness_1', [
540 {
541 ...computerCall('harness', click),
542 pending_safety_checks: [SAFETY_CHECK],
543 },
544 ]),
545 openaiStream('resp_cu_harness_2', [OPENAI_ANSWER]),
546 ])
547 const plugin = computerUse({
548 driver: createPlaywrightComputerDriver({ page }),
549 screenshotDelay: 0,
550 })
551 const host = createHarnessHost({ persistence: memoryPersistence() })
552 try {
553 const session = await host.open(
554 defineHarness({
555 name: 'e2e/computer-use',
556 adapter: openaiAdapter(model),
557 plugins: () => [permissions(), plugin],
558 }),
559 { threadId: 'thread-cu-harness' },
560 )
561
562 // The turn stops at the approval. The click waits.
563 await session.send('Click Go.')
564 await expect.poll(() => session.snapshot().pendingWaits.length).toBe(1)
565 await expect(page.locator('#status')).toHaveText('idle')
566
567 const [wait] = session.snapshot().pendingWaits
568 if (!wait) throw new Error('No approval.')
569 expect(wait.message).toContain('Allow computer')
570 const inputId = `answer:${wait.waitId}`
571 await session.resolve({
572 resume: [
573 {
574 interruptId: wait.waitId,
575 status: 'resolved',
576 payload: { answer: 'once' },
577 },
578 ],
579 inputId,
580 })
581 await session.settled({ inputId })
582
583 await expect(page.locator('#status')).toHaveText('clicked')
584 // The model gets the bytes of the screenshot, and the acknowledged check.
585 expect(model.bodies[1]).toMatchObject({
586 input: expect.arrayContaining([
587 expect.objectContaining({
588 type: 'computer_call_output',
589 call_id: 'call_cu_harness',
590 output: expect.objectContaining({
591 image_url: expect.stringMatching(/^data:image\/png;base64,./),
592 }),
593 acknowledged_safety_checks: [SAFETY_CHECK],
594 }),
595 ]),
596 })
597 // The transcript keeps a small reference to the media store.
598 const transcript = await session.transcript()
599 const result = transcript.find((message) => message.role === 'tool')
600 expect(JSON.stringify(result?.content)).toContain('harness-media:')
601 } finally {
602 await host.close()
603 }
604 })
605})
606
607test.describe('computer use with playwrightComputer', () => {
608 test('playwrightComputer navigates, then clicks', async ({
609 browser,
610 page,
611 }) => {
612 // The fixture page has the same HTML and width as the factory pages.
613 // So the button has the same center there.
614 const { button } = await openForm(page)
615 const { computerUse, contexts } = routedComputerUse(browser)
616 const model = mockModel([
617 openaiStream('resp_cu_1', [
618 {
619 type: 'function_call',
620 id: 'fc_cu_navigate',
621 call_id: 'call_cu_navigate',
622 name: 'navigate',
623 arguments: JSON.stringify({ url: FORM_URL }),
624 status: 'completed',
625 },
626 ]),
627 openaiStream('resp_cu_2', [
628 computerCall('click', { type: 'click', button: 'left', ...button }),
629 ]),
630 openaiStream('resp_cu_3', [OPENAI_ANSWER]),
631 ])
632
633 await runOpenai(computerUse, model, 'thread-cu-navigate')
634
635 expect(contexts).toHaveLength(1)
636 const [formPage] = contexts.map(pageOf)
637 expect(formPage.url()).toBe(FORM_URL)
638 await expect(formPage.locator('#status')).toHaveText('clicked')
639 expect(model.bodies).toHaveLength(3)
640 expect(model.bodies[0]).toMatchObject({
641 tools: [{ type: 'computer' }, OPENAI_NAVIGATE_TOOL],
642 })
643 expect(model.bodies[1]).toMatchObject({
644 input: expect.arrayContaining([
645 expect.objectContaining({
646 type: 'function_call_output',
647 call_id: 'call_cu_navigate',
648 output: [
649 expect.objectContaining({
650 type: 'input_image',
651 image_url: expect.stringMatching(/^data:image\/png;base64,./),
652 }),
653 ],
654 }),
655 ]),
656 })
657
658 await computerUse.close()
659 })
660
661 test('two threads get two pages', async ({ browser, page }) => {
662 const { button } = await openForm(page)
663 const { computerUse, contexts } = routedComputerUse(browser)
664 // Thread A clicks Go. Thread B only takes a screenshot.
665 const clickModel = mockModel([
666 openaiStream('resp_cu_a1', [
667 computerCall('click', { type: 'click', button: 'left', ...button }),
668 ]),
669 openaiStream('resp_cu_a2', [OPENAI_ANSWER]),
670 ])
671 const lookModel = mockModel([
672 openaiStream('resp_cu_b1', [
673 computerCall('look', { type: 'screenshot' }),
674 ]),
675 openaiStream('resp_cu_b2', [OPENAI_ANSWER]),
676 ])
677
678 await runOpenai(computerUse, clickModel, 'a')
679 await runOpenai(computerUse, lookModel, 'b')
680
681 expect(contexts).toHaveLength(2)
682 const [pageA, pageB] = contexts.map(pageOf)
683 await expect(pageA.locator('#status')).toHaveText('clicked')
684 await expect(pageB.locator('#status')).toHaveText('idle')
685
686 // `close('a')` closes the context of thread A. Thread B keeps its page.
687 await computerUse.close('a')
688 expect(pageA.isClosed()).toBe(true)
689 expect(pageB.isClosed()).toBe(false)
690
691 await computerUse.close()
692 expect(pageB.isClosed()).toBe(true)
693 })
694})
695
696/** A fake robot on a 2560 x 1600 screen. Each call adds one line to `calls`. */
697function fakeRobot() {
698 const screen = { width: 2560, height: 1600 }
699 const calls: Array<string> = []
700 const record =
701 (name: string) =>
702 (...args: Array<string | number | boolean | undefined>) => {
703 calls.push([name, ...args].join(' ').trim())
704 }
705 const robot: RobotLike = {
706 getScreenSize: () => screen,
707 getMousePos: () => ({ x: 0, y: 0 }),
708 moveMouse: record('moveMouse'),
709 mouseClick: record('mouseClick'),
710 mouseToggle: record('mouseToggle'),
711 scrollMouse: record('scrollMouse'),
712 keyToggle: record('keyToggle'),
713 typeString: record('typeString'),
714 screen: {
715 capture: () => ({
716 ...screen,
717 byteWidth: screen.width * 4,
718 bytesPerPixel: 4,
719 image: new Uint8Array(screen.width * screen.height * 4),
720 }),
721 },
722 }
723 return { robot, calls }
724}
725
726/** The size of the first PNG screenshot in a request body. */
727function screenshotSize(body: unknown) {
728 const match = /data:image\/png;base64,([A-Za-z0-9+/=]+)/.exec(
729 JSON.stringify(body),
730 )
731 if (!match?.[1]) throw new Error('The request has no PNG screenshot.')
732 const png = Buffer.from(match[1], 'base64')
733 return { width: png.readUInt32BE(16), height: png.readUInt32BE(20) }
734}
735
736test.describe('computer use with localComputer', () => {
737 test('localComputer clicks on the screen and sends a display-size screenshot', async () => {
738 const { robot, calls } = fakeRobot()
739 const computerUse = createComputerUse({
740 driver: localComputer({ robot }),
741 screenshotDelay: 0,
742 })
743 const model = mockModel([
744 openaiStream('resp_cu_1', [
745 {
746 type: 'computer_call',
747 id: 'cu_local',
748 call_id: 'call_cu_local',
749 status: 'completed',
750 actions: [
751 { type: 'click', button: 'left', x: 640, y: 400 },
752 { type: 'type', text: 'hello' },
753 ],
754 pending_safety_checks: [],
755 },
756 ]),
757 openaiStream('resp_cu_2', [OPENAI_ANSWER]),
758 ])
759
760 await runOpenai(computerUse, model, 'thread-cu-local')
761
762 // The 2560 x 1600 screen fits in 1280 x 800, so each point doubles.
763 expect(calls).toEqual([
764 'moveMouse 1280 800',
765 'mouseClick left',
766 'typeString hello',
767 ])
768 expect(model.bodies).toHaveLength(2)
769 // A desktop has no address, so the `navigate` tool does not go.
770 expect(model.bodies[0]).toMatchObject({ tools: [{ type: 'computer' }] })
771 expect(screenshotSize(model.bodies[1])).toEqual({
772 width: 1280,
773 height: 800,
774 })
775 })
776})