Skip to content

Commit a7919d2

Browse files
committed
Fix URL-read side effects in computer-use templates.
Avoid destructive per-turn URL reads in the TypeScript loop and restore page focus after clipboard URL capture by sending Escape in both TypeScript and Python helpers. Made-with: Cursor
1 parent a611a9f commit a7919d2

3 files changed

Lines changed: 5 additions & 11 deletions

File tree

pkg/templates/python/openai-computer-use/computers/kernel_computer.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ def _current_url_batch_actions() -> List[Dict[str, Any]]:
263263
"type": "press_key",
264264
"press_key": {"hold_keys": ["Ctrl"], "keys": ["c"]},
265265
},
266+
{
267+
"type": "press_key",
268+
"press_key": {"keys": ["Escape"]},
269+
},
266270
]
267271

268272

pkg/templates/typescript/openai-computer-use/lib/agent.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -325,17 +325,6 @@ export class Agent {
325325
turns += 1;
326326
const inputMessages = [...opts.messages];
327327

328-
// Append current URL context to system message
329-
const currentUrl = await this.computer.getCurrentUrl();
330-
const sysIndex = inputMessages.findIndex((msg) => 'role' in msg && msg.role === 'system');
331-
if (sysIndex >= 0) {
332-
const msg = inputMessages[sysIndex];
333-
const urlInfo = `\n- Current URL: ${currentUrl}`;
334-
if (msg && 'content' in msg && typeof msg.content === 'string') {
335-
inputMessages[sysIndex] = { ...msg, content: msg.content + urlInfo } as typeof msg;
336-
}
337-
}
338-
339328
this.debugPrint(...inputMessages, ...newItems);
340329
this.modelRequestStartedAt = Date.now();
341330
const response = await utils.createResponse({

pkg/templates/typescript/openai-computer-use/lib/kernel-computer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ function currentUrlBatchActions(): BatchAction[] {
263263
{ type: 'press_key', press_key: { hold_keys: ['Ctrl'], keys: ['l'] } },
264264
{ type: 'press_key', press_key: { hold_keys: ['Ctrl'], keys: ['a'] } },
265265
{ type: 'press_key', press_key: { hold_keys: ['Ctrl'], keys: ['c'] } },
266+
{ type: 'press_key', press_key: { keys: ['Escape'] } },
266267
];
267268
}
268269

0 commit comments

Comments
 (0)