diff --git a/.changeset/shy-sides-crash.md b/.changeset/shy-sides-crash.md new file mode 100644 index 000000000..0c83fecfe --- /dev/null +++ b/.changeset/shy-sides-crash.md @@ -0,0 +1,5 @@ +--- +"@browserbasehq/stagehand": patch +--- + +Fix key action mapping in Anthropic CUA diff --git a/packages/core/lib/v3/agent/AnthropicCUAClient.ts b/packages/core/lib/v3/agent/AnthropicCUAClient.ts index e1fbe5a1a..e425b8f98 100644 --- a/packages/core/lib/v3/agent/AnthropicCUAClient.ts +++ b/packages/core/lib/v3/agent/AnthropicCUAClient.ts @@ -15,7 +15,6 @@ import { AgentScreenshotProviderError } from "../types/public/sdkErrors"; import Anthropic from "@anthropic-ai/sdk"; import { ToolSet } from "ai"; import { AgentClient } from "./AgentClient"; -import { mapKeyToPlaywright } from "./utils/cuaKeyMapping"; import { compressConversationImages } from "./utils/imageCompression"; import { toJsonSchema } from "../zodCompat"; import type { StagehandZodSchema } from "../zodCompat"; @@ -772,10 +771,10 @@ export class AnthropicCUAClient extends AgentClient { text: input.text as string, ...input, }; - } else if (action === "keypress") { + } else if (action === "keypress" || action === "key") { return { type: "keypress", - keys: input.keys as string[], + keys: [input.text as string], ...input, }; } else if (action === "double_click" || action === "doubleClick") { @@ -865,15 +864,6 @@ export class AnthropicCUAClient extends AgentClient { type: "wait", ...input, }; - } else if (action === "key") { - const text = input.text as string; - const mappedKey = mapKeyToPlaywright(text); - - return { - type: "key", - text: mappedKey, - ...input, - }; } else if (action === "left_click") { // Convert left_click to regular click const coordinates = input.coordinate as number[] | undefined;