Skip to content

Commit 9acfbf5

Browse files
authored
Fix computer use tool call (screenshot) problem and add smarter waiting (#74)
* Fix computer use tool call (screenshot) problem and add smarter waiting * Add changeset * Import order
1 parent 61cd26d commit 9acfbf5

File tree

9 files changed

+78
-49
lines changed

9 files changed

+78
-49
lines changed

.changeset/heavy-buckets-occur.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"@trymeka/computer-provider-anchor-browser": patch
3+
"@trymeka/computer-provider-scrapybara": patch
4+
"@trymeka/computer-provider-core": patch
5+
"@trymeka/computer-provider-e2b": patch
6+
"@trymeka/ai-provider-vercel": patch
7+
"@trymeka/core": patch
8+
---
9+
10+
Fix computer use "screenshot" tool call problem and add smarter waiting between steps

packages/ai-provider-vercel/package.json

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,15 @@
66
"access": "public"
77
},
88
"description": "TODO: Add description",
9-
"keywords": [
10-
"trymeka"
11-
],
9+
"keywords": ["trymeka"],
1210
"repository": {
1311
"type": "git",
1412
"url": "git+https://github.com/trymeka/agent.git",
1513
"directory": "packages/ai-provider-vercel"
1614
},
1715
"license": "MIT",
1816
"homepage": "https://github.com/trymeka/agent/tree/main/packages/ai-provider-vercel#readme",
19-
"files": [
20-
"dist",
21-
"!dist/**/*.map",
22-
"README.md"
23-
],
17+
"files": ["dist", "!dist/**/*.map", "README.md"],
2418
"exports": {
2519
".": {
2620
"types": "./dist/index.d.ts",

packages/computer-provider-anchor-browser/package.json

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,15 @@
66
"access": "public"
77
},
88
"description": "TODO: Add description",
9-
"keywords": [
10-
"trymeka"
11-
],
9+
"keywords": ["trymeka"],
1210
"repository": {
1311
"type": "git",
1412
"url": "git+https://github.com/trymeka/agent.git",
1513
"directory": "packages/computer-provider-anchor-browser"
1614
},
1715
"license": "MIT",
1816
"homepage": "https://github.com/trymeka/agent/tree/main/packages/computer-provider-anchor-browser#readme",
19-
"files": [
20-
"dist",
21-
"!dist/**/*.map",
22-
"README.md"
23-
],
17+
"files": ["dist", "!dist/**/*.map", "README.md"],
2418
"exports": {
2519
".": {
2620
"types": "./dist/index.d.ts",

packages/computer-provider-core/package.json

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,15 @@
66
"access": "public"
77
},
88
"description": "TODO: Add description",
9-
"keywords": [
10-
"trymeka"
11-
],
9+
"keywords": ["trymeka"],
1210
"repository": {
1311
"type": "git",
1412
"url": "git+https://github.com/trymeka/agent.git",
1513
"directory": "packages/computer-provider-core"
1614
},
1715
"license": "MIT",
1816
"homepage": "https://github.com/trymeka/agent/tree/main/packages/computer-provider-core#readme",
19-
"files": [
20-
"dist",
21-
"!dist/**/*.map",
22-
"README.md"
23-
],
17+
"files": ["dist", "!dist/**/*.map", "README.md"],
2418
"exports": {
2519
".": {
2620
"types": "./dist/index.d.ts",

packages/computer-provider-e2b/package.json

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,15 @@
66
"access": "public"
77
},
88
"description": "TODO: Add description",
9-
"keywords": [
10-
"trymeka"
11-
],
9+
"keywords": ["trymeka"],
1210
"repository": {
1311
"type": "git",
1412
"url": "git+https://github.com/trymeka/agent.git",
1513
"directory": "packages/computer-provider-e2b"
1614
},
1715
"license": "MIT",
1816
"homepage": "https://github.com/trymeka/agent/tree/main/packages/computer-provider-e2b#readme",
19-
"files": [
20-
"dist",
21-
"!dist/**/*.map",
22-
"README.md"
23-
],
17+
"files": ["dist", "!dist/**/*.map", "README.md"],
2418
"exports": {
2519
".": {
2620
"types": "./dist/index.d.ts",

packages/computer-provider-scrapybara/package.json

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,15 @@
66
"access": "public"
77
},
88
"description": "TODO: Add description",
9-
"keywords": [
10-
"trymeka"
11-
],
9+
"keywords": ["trymeka"],
1210
"repository": {
1311
"type": "git",
1412
"url": "git+https://github.com/trymeka/agent.git",
1513
"directory": "packages/computer-provider-scrapybara"
1614
},
1715
"license": "MIT",
1816
"homepage": "https://github.com/trymeka/agent/tree/main/packages/computer-provider-scrapybara#readme",
19-
"files": [
20-
"dist",
21-
"!dist/**/*.map",
22-
"README.md"
23-
],
17+
"files": ["dist", "!dist/**/*.map", "README.md"],
2418
"exports": {
2519
".": {
2620
"types": "./dist/index.d.ts",

packages/core/package.json

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,15 @@
66
"access": "public"
77
},
88
"description": "TODO: Add description",
9-
"keywords": [
10-
"trymeka"
11-
],
9+
"keywords": ["trymeka"],
1210
"repository": {
1311
"type": "git",
1412
"url": "git+https://github.com/trymeka/agent.git",
1513
"directory": "packages/agent"
1614
},
1715
"license": "MIT",
1816
"homepage": "https://github.com/trymeka/agent/tree/main/packages/agent#readme",
19-
"files": [
20-
"dist",
21-
"!dist/**/*.map",
22-
"README.md"
23-
],
17+
"files": ["dist", "!dist/**/*.map", "README.md"],
2418
"exports": {
2519
".": {
2620
"typescript": "./src/index.ts",
@@ -54,8 +48,12 @@
5448
"dependencies": {
5549
"zod": "^3.24.4"
5650
},
51+
"peerDependencies": {
52+
"playwright-core": "^1.54.1"
53+
},
5754
"devDependencies": {
5855
"@trymeka/typescript": "workspace:*",
56+
"playwright-core": "^1.54.1",
5957
"tsup": "^8.5.0",
6058
"typescript": "^5.8.3"
6159
}

packages/core/src/tools/computer.ts

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { Page } from "playwright-core";
12
import z from "zod";
23
import type { Tool } from ".";
34
import { createAgentLogUpdate } from "../utils/agent-log";
@@ -67,7 +68,26 @@ export const parseComputerToolArgs = (args: string | object) => {
6768
if (actionString.includes("wait")) {
6869
return { schema: waitActionSchema, args: parsedArgs };
6970
}
70-
return null;
71+
72+
// Handle screenshot action specifically - screenshots should be automatic, not manual
73+
if (actionString.includes("screenshot")) {
74+
console.warn(
75+
"[parseComputerToolArgs] LLM requested screenshot action - screenshots should be automatic",
76+
);
77+
return {
78+
schema: waitActionSchema,
79+
args: { ...parsedArgs, action: { type: "wait", duration: 0 } },
80+
};
81+
}
82+
83+
// Fallback for any other unrecognized actions - don't return null
84+
console.warn(
85+
`[parseComputerToolArgs] Unrecognized computer action: ${actionString}`,
86+
);
87+
return {
88+
schema: waitActionSchema,
89+
args: { ...parsedArgs, action: { type: "wait", duration: 0 } },
90+
};
7191
};
7292

7393
const clickActionSchema = z
@@ -344,6 +364,34 @@ export function createComputerTool<T, R>({
344364
},
345365
execute: async (args, context) => {
346366
const result = await computerProvider.performAction(args.action, context);
367+
368+
// Smart delay with network idle support
369+
if (args.action.type === "click" || args.action.type === "double_click") {
370+
try {
371+
const instance = await computerProvider.getInstance(
372+
context.sessionId,
373+
);
374+
const page = (instance as { page?: Page })?.page;
375+
376+
if (page?.waitForLoadState) {
377+
await page.waitForLoadState("networkidle", { timeout: 1500 });
378+
} else {
379+
await new Promise((resolve) => setTimeout(resolve, 1500));
380+
}
381+
} catch {
382+
await new Promise((resolve) => setTimeout(resolve, 1500));
383+
}
384+
} else {
385+
// Other action types get fixed delays
386+
const delay =
387+
args.action.type === "type"
388+
? 300
389+
: args.action.type === "scroll"
390+
? 800
391+
: 500;
392+
await new Promise((resolve) => setTimeout(resolve, delay));
393+
}
394+
347395
const screenshot = await computerProvider.takeScreenshot(
348396
context.sessionId,
349397
);

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)