Skip to content

Commit 6aa9d45

Browse files
miguelg719seanmcguire12greptile-apps[bot]
authored
Fix key mapping in Anthropic CUA Client (#1374)
# why Anthropic agents in CUA mode are unable to issue key presses (not to be confused with `type` actions) # what changed The format for the anthropic tool `computer_20250124` replies with: ```ts { "action":"key", "text":"BackSpace" } ``` wasn't properly mapped to our internal action abstraction: `keypress`, which accepts parameter `keys`. It was issued directly from the anthropic format. Updated `AnthropicCUAClient.ts` to account for this and map appropriately # test plan - [x] Tested on sample eval <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes key action mapping in Anthropic CUA so agents can send key presses (e.g., Backspace) correctly instead of failing on the "key" action. - **Bug Fixes** - Map Anthropic "key" to internal "keypress" and pass keys from input.text. - Remove the old "key" path and Playwright key mapping to avoid mismatches. <sup>Written for commit b9716b9. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. --> --------- Co-authored-by: Sean McGuire <75873287+seanmcguire12@users.noreply.github.com> Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
1 parent 13c66dc commit 6aa9d45

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

.changeset/shy-sides-crash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@browserbasehq/stagehand": patch
3+
---
4+
5+
Fix key action mapping in Anthropic CUA

packages/core/lib/v3/agent/AnthropicCUAClient.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { AgentScreenshotProviderError } from "../types/public/sdkErrors";
1515
import Anthropic from "@anthropic-ai/sdk";
1616
import { ToolSet } from "ai";
1717
import { AgentClient } from "./AgentClient";
18-
import { mapKeyToPlaywright } from "./utils/cuaKeyMapping";
1918
import { compressConversationImages } from "./utils/imageCompression";
2019
import { toJsonSchema } from "../zodCompat";
2120
import type { StagehandZodSchema } from "../zodCompat";
@@ -772,10 +771,10 @@ export class AnthropicCUAClient extends AgentClient {
772771
text: input.text as string,
773772
...input,
774773
};
775-
} else if (action === "keypress") {
774+
} else if (action === "keypress" || action === "key") {
776775
return {
777776
type: "keypress",
778-
keys: input.keys as string[],
777+
keys: [input.text as string],
779778
...input,
780779
};
781780
} else if (action === "double_click" || action === "doubleClick") {
@@ -865,15 +864,6 @@ export class AnthropicCUAClient extends AgentClient {
865864
type: "wait",
866865
...input,
867866
};
868-
} else if (action === "key") {
869-
const text = input.text as string;
870-
const mappedKey = mapKeyToPlaywright(text);
871-
872-
return {
873-
type: "key",
874-
text: mappedKey,
875-
...input,
876-
};
877867
} else if (action === "left_click") {
878868
// Convert left_click to regular click
879869
const coordinates = input.coordinate as number[] | undefined;

0 commit comments

Comments
 (0)