@browserbasehq/orca 3.2.0-preview.5 → 3.2.1-preview.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/cjs/lib/inference.js +1 -1
- package/dist/cjs/lib/inference.js.map +1 -1
- package/dist/cjs/lib/prompt.js +13 -16
- package/dist/cjs/lib/prompt.js.map +1 -1
- package/dist/cjs/lib/v3/agent/AgentProvider.js +1 -0
- package/dist/cjs/lib/v3/agent/AgentProvider.js.map +1 -1
- package/dist/cjs/lib/v3/agent/AnthropicCUAClient.d.ts +3 -1
- package/dist/cjs/lib/v3/agent/AnthropicCUAClient.js +60 -9
- package/dist/cjs/lib/v3/agent/AnthropicCUAClient.js.map +1 -1
- package/dist/cjs/lib/v3/agent/MicrosoftCUAClient.js +15 -0
- package/dist/cjs/lib/v3/agent/MicrosoftCUAClient.js.map +1 -1
- package/dist/cjs/lib/v3/agent/OpenAICUAClient.d.ts +8 -2
- package/dist/cjs/lib/v3/agent/OpenAICUAClient.js +103 -49
- package/dist/cjs/lib/v3/agent/OpenAICUAClient.js.map +1 -1
- package/dist/cjs/lib/v3/agent/tools/index.js +1 -1
- package/dist/cjs/lib/v3/agent/tools/index.js.map +1 -1
- package/dist/cjs/lib/v3/agent/tools/keys.d.ts +2 -1
- package/dist/cjs/lib/v3/agent/tools/keys.js +57 -49
- package/dist/cjs/lib/v3/agent/tools/keys.js.map +1 -1
- package/dist/cjs/lib/v3/agent/utils/coordinateNormalization.js +3 -5
- package/dist/cjs/lib/v3/agent/utils/coordinateNormalization.js.map +1 -1
- package/dist/cjs/lib/v3/api.d.ts +5 -3
- package/dist/cjs/lib/v3/api.js +3 -6
- package/dist/cjs/lib/v3/api.js.map +1 -1
- package/dist/cjs/lib/v3/cache/AgentCache.js +5 -3
- package/dist/cjs/lib/v3/cache/AgentCache.js.map +1 -1
- package/dist/cjs/lib/v3/handlers/v3CuaAgentHandler.js +6 -15
- package/dist/cjs/lib/v3/handlers/v3CuaAgentHandler.js.map +1 -1
- package/dist/cjs/lib/v3/index.d.ts +1 -1
- package/dist/cjs/lib/v3/llm/LLMProvider.d.ts +5 -2
- package/dist/cjs/lib/v3/llm/LLMProvider.js +14 -6
- package/dist/cjs/lib/v3/llm/LLMProvider.js.map +1 -1
- package/dist/cjs/lib/v3/llm/OpenAIClient.js +1 -0
- package/dist/cjs/lib/v3/llm/OpenAIClient.js.map +1 -1
- package/dist/cjs/lib/v3/llm/aisdk.d.ts +3 -1
- package/dist/cjs/lib/v3/llm/aisdk.js +67 -17
- package/dist/cjs/lib/v3/llm/aisdk.js.map +1 -1
- package/dist/cjs/lib/v3/types/public/agent.d.ts +8 -3
- package/dist/cjs/lib/v3/types/public/agent.js +1 -0
- package/dist/cjs/lib/v3/types/public/agent.js.map +1 -1
- package/dist/cjs/lib/v3/types/public/api.d.ts +30 -0
- package/dist/cjs/lib/v3/types/public/api.js +6 -2
- package/dist/cjs/lib/v3/types/public/api.js.map +1 -1
- package/dist/cjs/lib/v3/types/public/model.d.ts +32 -2
- package/dist/cjs/lib/v3/types/public/model.js.map +1 -1
- package/dist/cjs/lib/v3/understudy/context.js +11 -3
- package/dist/cjs/lib/v3/understudy/context.js.map +1 -1
- package/dist/cjs/lib/v3/understudy/page.js +1 -1
- package/dist/cjs/lib/v3/understudy/page.js.map +1 -1
- package/dist/cjs/lib/v3/v3.d.ts +18 -2
- package/dist/cjs/lib/v3/v3.js +92 -9
- package/dist/cjs/lib/v3/v3.js.map +1 -1
- package/dist/cjs/tests/integration/chrome-newtab-page-tracking.spec.d.ts +1 -0
- package/dist/cjs/tests/integration/chrome-newtab-page-tracking.spec.js +56 -0
- package/dist/cjs/tests/integration/chrome-newtab-page-tracking.spec.js.map +1 -0
- package/dist/cjs/tests/unit/agent-captcha-hooks.test.js +56 -0
- package/dist/cjs/tests/unit/agent-captcha-hooks.test.js.map +1 -1
- package/dist/cjs/tests/unit/agent-metrics.test.d.ts +1 -0
- package/dist/cjs/tests/unit/agent-metrics.test.js +112 -0
- package/dist/cjs/tests/unit/agent-metrics.test.js.map +1 -0
- package/dist/cjs/tests/unit/aisdk-clients.test.d.ts +1 -0
- package/dist/cjs/tests/unit/aisdk-clients.test.js +90 -0
- package/dist/cjs/tests/unit/aisdk-clients.test.js.map +1 -0
- package/dist/cjs/tests/unit/anthropic-cua-adaptive-thinking.test.d.ts +1 -0
- package/dist/cjs/tests/unit/anthropic-cua-adaptive-thinking.test.js +250 -0
- package/dist/cjs/tests/unit/anthropic-cua-adaptive-thinking.test.js.map +1 -0
- package/dist/cjs/tests/unit/api-optional-model-api-key.test.d.ts +1 -0
- package/dist/cjs/tests/unit/api-optional-model-api-key.test.js +95 -0
- package/dist/cjs/tests/unit/api-optional-model-api-key.test.js.map +1 -0
- package/dist/cjs/tests/unit/browserbase-session-accessors.test.js +20 -0
- package/dist/cjs/tests/unit/browserbase-session-accessors.test.js.map +1 -1
- package/dist/cjs/tests/unit/llm-middleware.test.d.ts +1 -0
- package/dist/cjs/tests/unit/llm-middleware.test.js +495 -0
- package/dist/cjs/tests/unit/llm-middleware.test.js.map +1 -0
- package/dist/cjs/tests/unit/microsoft-cua-client.test.d.ts +1 -0
- package/dist/cjs/tests/unit/microsoft-cua-client.test.js +86 -0
- package/dist/cjs/tests/unit/microsoft-cua-client.test.js.map +1 -0
- package/dist/cjs/tests/unit/public-api/llm-and-agents.test.js +1 -0
- package/dist/cjs/tests/unit/public-api/llm-and-agents.test.js.map +1 -1
- package/dist/esm/lib/inference.js +1 -1
- package/dist/esm/lib/inference.js.map +1 -1
- package/dist/esm/lib/prompt.js +13 -16
- package/dist/esm/lib/prompt.js.map +1 -1
- package/dist/esm/lib/v3/agent/AgentProvider.js +1 -0
- package/dist/esm/lib/v3/agent/AgentProvider.js.map +1 -1
- package/dist/esm/lib/v3/agent/AnthropicCUAClient.d.ts +3 -1
- package/dist/esm/lib/v3/agent/AnthropicCUAClient.js +60 -9
- package/dist/esm/lib/v3/agent/AnthropicCUAClient.js.map +1 -1
- package/dist/esm/lib/v3/agent/MicrosoftCUAClient.js +15 -0
- package/dist/esm/lib/v3/agent/MicrosoftCUAClient.js.map +1 -1
- package/dist/esm/lib/v3/agent/OpenAICUAClient.d.ts +8 -2
- package/dist/esm/lib/v3/agent/OpenAICUAClient.js +103 -49
- package/dist/esm/lib/v3/agent/OpenAICUAClient.js.map +1 -1
- package/dist/esm/lib/v3/agent/tools/index.js +1 -1
- package/dist/esm/lib/v3/agent/tools/index.js.map +1 -1
- package/dist/esm/lib/v3/agent/tools/keys.d.ts +2 -1
- package/dist/esm/lib/v3/agent/tools/keys.js +57 -49
- package/dist/esm/lib/v3/agent/tools/keys.js.map +1 -1
- package/dist/esm/lib/v3/agent/utils/coordinateNormalization.js +3 -5
- package/dist/esm/lib/v3/agent/utils/coordinateNormalization.js.map +1 -1
- package/dist/esm/lib/v3/api.d.ts +5 -3
- package/dist/esm/lib/v3/api.js +3 -6
- package/dist/esm/lib/v3/api.js.map +1 -1
- package/dist/esm/lib/v3/cache/AgentCache.js +5 -3
- package/dist/esm/lib/v3/cache/AgentCache.js.map +1 -1
- package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.js +6 -15
- package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.js.map +1 -1
- package/dist/esm/lib/v3/index.d.ts +1 -1
- package/dist/esm/lib/v3/llm/LLMProvider.d.ts +5 -2
- package/dist/esm/lib/v3/llm/LLMProvider.js +15 -7
- package/dist/esm/lib/v3/llm/LLMProvider.js.map +1 -1
- package/dist/esm/lib/v3/llm/OpenAIClient.js +1 -0
- package/dist/esm/lib/v3/llm/OpenAIClient.js.map +1 -1
- package/dist/esm/lib/v3/llm/aisdk.d.ts +3 -1
- package/dist/esm/lib/v3/llm/aisdk.js +67 -17
- package/dist/esm/lib/v3/llm/aisdk.js.map +1 -1
- package/dist/esm/lib/v3/types/public/agent.d.ts +8 -3
- package/dist/esm/lib/v3/types/public/agent.js +1 -0
- package/dist/esm/lib/v3/types/public/agent.js.map +1 -1
- package/dist/esm/lib/v3/types/public/api.d.ts +30 -0
- package/dist/esm/lib/v3/types/public/api.js +6 -2
- package/dist/esm/lib/v3/types/public/api.js.map +1 -1
- package/dist/esm/lib/v3/types/public/model.d.ts +32 -2
- package/dist/esm/lib/v3/types/public/model.js.map +1 -1
- package/dist/esm/lib/v3/understudy/context.js +11 -3
- package/dist/esm/lib/v3/understudy/context.js.map +1 -1
- package/dist/esm/lib/v3/understudy/page.js +1 -1
- package/dist/esm/lib/v3/understudy/page.js.map +1 -1
- package/dist/esm/lib/v3/v3.d.ts +18 -2
- package/dist/esm/lib/v3/v3.js +92 -10
- package/dist/esm/lib/v3/v3.js.map +1 -1
- package/dist/esm/tests/integration/chrome-newtab-page-tracking.spec.d.ts +1 -0
- package/dist/esm/tests/integration/chrome-newtab-page-tracking.spec.js +54 -0
- package/dist/esm/tests/integration/chrome-newtab-page-tracking.spec.js.map +1 -0
- package/dist/esm/tests/unit/agent-captcha-hooks.test.js +56 -0
- package/dist/esm/tests/unit/agent-captcha-hooks.test.js.map +1 -1
- package/dist/esm/tests/unit/agent-metrics.test.d.ts +1 -0
- package/dist/esm/tests/unit/agent-metrics.test.js +110 -0
- package/dist/esm/tests/unit/agent-metrics.test.js.map +1 -0
- package/dist/esm/tests/unit/aisdk-clients.test.d.ts +1 -0
- package/dist/esm/tests/unit/aisdk-clients.test.js +88 -0
- package/dist/esm/tests/unit/aisdk-clients.test.js.map +1 -0
- package/dist/esm/tests/unit/anthropic-cua-adaptive-thinking.test.d.ts +1 -0
- package/dist/esm/tests/unit/anthropic-cua-adaptive-thinking.test.js +245 -0
- package/dist/esm/tests/unit/anthropic-cua-adaptive-thinking.test.js.map +1 -0
- package/dist/esm/tests/unit/api-optional-model-api-key.test.d.ts +1 -0
- package/dist/esm/tests/unit/api-optional-model-api-key.test.js +93 -0
- package/dist/esm/tests/unit/api-optional-model-api-key.test.js.map +1 -0
- package/dist/esm/tests/unit/browserbase-session-accessors.test.js +20 -0
- package/dist/esm/tests/unit/browserbase-session-accessors.test.js.map +1 -1
- package/dist/esm/tests/unit/llm-middleware.test.d.ts +1 -0
- package/dist/esm/tests/unit/llm-middleware.test.js +460 -0
- package/dist/esm/tests/unit/llm-middleware.test.js.map +1 -0
- package/dist/esm/tests/unit/microsoft-cua-client.test.d.ts +1 -0
- package/dist/esm/tests/unit/microsoft-cua-client.test.js +84 -0
- package/dist/esm/tests/unit/microsoft-cua-client.test.js.map +1 -0
- package/dist/esm/tests/unit/public-api/llm-and-agents.test.js +1 -0
- package/dist/esm/tests/unit/public-api/llm-and-agents.test.js.map +1 -1
- package/package.json +4 -8
- package/dist/cjs/lib/v3/dom/build/rerender-index.js +0 -1
- package/dist/cjs/lib/v3/dom/build/v3-index.js +0 -1
- package/dist/esm/lib/v3/dom/build/rerender-index.js +0 -1
- package/dist/esm/lib/v3/dom/build/v3-index.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MicrosoftCUAClient.js","sourceRoot":"","sources":["../../../../../lib/v3/agent/MicrosoftCUAClient.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAS5B,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,4BAA4B,EAAE,MAAM,8BAA8B,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AA+B9D;;;GAGG;AACH,MAAM,OAAO,kBAAmB,SAAQ,WAAW;IACzC,MAAM,CAAS;IACf,OAAO,CAAS;IAChB,MAAM,CAAS;IACf,eAAe,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;IAC/C,UAAU,CAAU;IACpB,kBAAkB,CAAyB;IAC3C,aAAa,CAA0C;IAE/D,sBAAsB;IACd,mBAAmB,GAAkB,EAAE,CAAC,CAAC,kBAAkB;IAC3D,aAAa,GAAkB,EAAE,CAAC,CAA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oBAC9B,aAAa,EAAE,iBAAiB;oBAChC,iBAAiB,EAAE,kBAAkB;iBACtC;aACF,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC;gBACL,QAAQ,EAAE,OAAO;gBACjB,OAAO,EAAE,2BAA2B,KAAK,EAAE;gBAC3C,KAAK,EAAE,CAAC;aACT,CAAC,CAAC;YAEH,wEAAwE;YACxE,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF","sourcesContent":["import OpenAI from \"openai\";\nimport { LogLine } from \"../types/public/logs.js\";\nimport {\n AgentAction,\n AgentResult,\n AgentType,\n AgentExecutionOptions,\n} from \"../types/public/agent.js\";\nimport { ClientOptions } from \"../types/public/model.js\";\nimport { AgentClient } from \"./AgentClient.js\";\nimport { AgentScreenshotProviderError } from \"../types/public/sdkErrors.js\";\nimport { mapKeyToPlaywright } from \"./utils/cuaKeyMapping.js\";\nimport { ChatCompletionMessageParam } from \"openai/resources/chat/completions\";\n\n/**\n * Message types for FARA agent\n */\ninterface FaraMessage {\n role: \"system\" | \"user\" | \"assistant\";\n content: string | FaraMessageContent[];\n}\n\ninterface FaraMessageContent {\n type: \"text\" | \"image_url\";\n text?: string;\n image_url?: {\n url: string; // data:image/png;base64,...\n };\n}\n\n/**\n * FARA function call structure (parsed from XML tags)\n */\ninterface FaraFunctionCall {\n name: string; // Always \"computer_use\"\n arguments: {\n action: string;\n thoughts?: string;\n [key: string]: unknown;\n };\n}\n\n/**\n * Client for FARA (Function-based Autonomous Research Agent) by Microsoft\n * This implementation uses OpenAI-compatible API with XML-based tool calling\n */\nexport class MicrosoftCUAClient extends AgentClient {\n private apiKey: string;\n private baseURL: string;\n private client: OpenAI;\n private currentViewport = { width: 1288, height: 711 };\n private currentUrl?: string;\n private screenshotProvider?: () => Promise<string>;\n private actionHandler?: (action: AgentAction) => Promise<void>;\n\n // Dual history system\n private conversationHistory: FaraMessage[] = []; // Conceptual flow\n private actionHistory: FaraMessage[] = []; // Raw model responses\n\n private maxImages: number = 3;\n private temperature: number = 0;\n private facts: string[] = [];\n\n // FARA-specific MLM processor config\n private readonly MLM_PROCESSOR_IM_CFG = {\n min_pixels: 3136,\n max_pixels: 12845056,\n patch_size: 14,\n merge_size: 2,\n };\n\n // Resized dimensions for model input\n private resizedViewport = { width: 1288, height: 711 };\n\n constructor(\n type: AgentType,\n modelName: string,\n userProvidedInstructions?: string,\n clientOptions?: ClientOptions,\n ) {\n super(type, modelName || \"fara-7b\", userProvidedInstructions);\n\n // Process client options\n this.apiKey =\n (clientOptions?.apiKey as string) ||\n process.env.AZURE_API_KEY ||\n process.env.FIREWORKS_API_KEY ||\n \"\";\n this.baseURL =\n (clientOptions?.baseURL as string) ||\n process.env.AZURE_ENDPOINT ||\n process.env.FIREWORKS_ENDPOINT ||\n \"\";\n\n // Store client options for reference\n this.clientOptions = {\n apiKey: this.apiKey,\n baseURL: this.baseURL,\n };\n\n // Validate API key\n if (!this.apiKey || this.apiKey === \"\") {\n throw new Error(\n \"API key is required. Please provide it via clientOptions.apiKey or AZURE_API_KEY or FIREWORKS_API_KEY environment variables.\",\n );\n }\n\n // Initialize the OpenAI client (FARA uses OpenAI-compatible API)\n this.client = new OpenAI({\n apiKey: this.apiKey,\n baseURL: this.baseURL,\n });\n\n // Max images to keep in history\n if (clientOptions?.maxImages !== undefined) {\n this.maxImages = clientOptions.maxImages as number;\n }\n\n // Temperature\n if (clientOptions?.temperature !== undefined) {\n this.temperature = clientOptions.temperature as number;\n }\n }\n\n setViewport(width: number, height: number): void {\n this.currentViewport = { width, height };\n // Compute resized viewport using smart_resize logic\n this.resizedViewport = this.smartResize(width, height);\n }\n\n setCurrentUrl(url: string): void {\n this.currentUrl = url;\n }\n\n setScreenshotProvider(provider: () => Promise<string>): void {\n this.screenshotProvider = provider;\n }\n\n setActionHandler(handler: (action: AgentAction) => Promise<void>): void {\n this.actionHandler = handler;\n }\n\n /**\n * Smart resize algorithm from FARA\n * Ensures dimensions are divisible by factor and within pixel limits\n */\n private smartResize(\n width: number,\n height: number,\n ): { width: number; height: number } {\n const { patch_size, merge_size, min_pixels, max_pixels } =\n this.MLM_PROCESSOR_IM_CFG;\n const factor = patch_size * merge_size;\n\n const roundByFactor = (num: number, f: number) => Math.round(num / f) * f;\n const ceilByFactor = (num: number, f: number) => Math.ceil(num / f) * f;\n const floorByFactor = (num: number, f: number) => Math.floor(num / f) * f;\n\n let h_bar = Math.max(factor, roundByFactor(height, factor));\n let w_bar = Math.max(factor, roundByFactor(width, factor));\n\n if (h_bar * w_bar > max_pixels) {\n const beta = Math.sqrt((height * width) / max_pixels);\n h_bar = floorByFactor(height / beta, factor);\n w_bar = floorByFactor(width / beta, factor);\n } else if (h_bar * w_bar < min_pixels) {\n const beta = Math.sqrt(min_pixels / (height * width));\n h_bar = ceilByFactor(height * beta, factor);\n w_bar = ceilByFactor(width * beta, factor);\n }\n\n return { width: w_bar, height: h_bar };\n }\n\n /**\n * Generate system prompt with tool description\n * Simplified to match Python's minimal approach\n */\n private generateSystemPrompt(): string {\n const { width, height } = this.resizedViewport;\n\n // Base prompt - Minimalist like Python\n let basePrompt = \"You are a helpful assistant.\";\n\n // Add user-provided instructions if available\n if (this.userProvidedInstructions) {\n basePrompt = `${basePrompt}\\n\\n${this.userProvidedInstructions}`;\n }\n\n // Tool description from FaraComputerUse\n const toolDescription = `Use a mouse and keyboard to interact with a computer, and take screenshots.\n* This is an interface to a desktop GUI. You do not have access to a terminal or applications menu. You must click on desktop icons to start applications.\n* Some applications may take time to start or process actions, so you may need to wait and take successive screenshots to see the results of your actions. E.g. if you click on Firefox and a window doesn't open, try wait and taking another screenshot.\n* The screen's resolution is ${width}x${height}.\n* Whenever you intend to move the cursor to click on an element like an icon, you should consult a screenshot to determine the coordinates of the element before moving the cursor.\n* If you tried clicking on a program or link but it failed to load, even after waiting, try adjusting your cursor position so that the tip of the cursor visually falls on the element that you want to click.\n* Make sure to click any buttons, links, icons, etc with the cursor tip in the center of the element. Don't click boxes on their edges unless asked.\n* When a separate scrollable container prominently overlays the webpage, if you want to scroll within it, you typically need to mouse_move() over it first and then scroll().\n* If a popup window appears that you want to close, if left_click() on the 'X' or close button doesn't work, try key(keys=['Escape']) to close it.\n* On some search bars, when you type(), you may need to press_enter=False and instead separately call left_click() on the search button to submit the search query. This is especially true of search bars that have auto-suggest popups for e.g. locations\n* For calendar widgets, you usually need to left_click() on arrows to move between months and left_click() on dates to select them; type() is not typically used to input dates there.`;\n\n // Tool parameters description\n const actionsDescription = `The action to perform. The available actions are:\n* \\`key\\`: Performs key down presses on the arguments passed in order, then performs key releases in reverse order. Includes \"Enter\", \"Alt\", \"Shift\", \"Tab\", \"Control\", \"Backspace\", \"Delete\", \"Escape\", \"ArrowUp\", \"ArrowDown\", \"ArrowLeft\", \"ArrowRight\", \"PageDown\", \"PageUp\", \"Shift\", etc.\n* \\`type\\`: Type a string of text on the keyboard.\n* \\`mouse_move\\`: Move the cursor to a specified (x, y) pixel coordinate on the screen.\n* \\`left_click\\`: Click the left mouse button.\n* \\`scroll\\`: Performs a scroll of the mouse scroll wheel.\n* \\`history_back\\`: Go back to the previous page in the browser history.\n* \\`pause_and_memorize_fact\\`: Pause and memorize a fact for future reference.\n* \\`visit_url\\`: Visit a specified URL.\n* \\`web_search\\`: Perform a web search with a specified query.\n* \\`wait\\`: Wait specified seconds for the change to happen.\n* \\`terminate\\`: Terminate the current task and report its completion status.`;\n\n // Tool JSON schema\n const toolSchema = {\n name: \"computer_use\",\n description: toolDescription,\n parameters: {\n type: \"object\",\n required: [\"action\"],\n properties: {\n action: {\n type: \"string\",\n description: actionsDescription,\n enum: [\n \"key\",\n \"type\",\n \"mouse_move\",\n \"left_click\",\n \"scroll\",\n \"visit_url\",\n \"web_search\",\n \"history_back\",\n \"pause_and_memorize_fact\",\n \"wait\",\n \"terminate\",\n ],\n },\n keys: {\n type: \"array\",\n description: \"Required only by `action=key`.\",\n },\n text: {\n type: \"string\",\n description: \"Required only by `action=type`.\",\n },\n press_enter: {\n type: \"boolean\",\n description:\n \"Whether to press the Enter key after typing. Required only by `action=type`.\",\n },\n delete_existing_text: {\n type: \"boolean\",\n description:\n \"Whether to delete existing text before typing. Required only by `action=type`.\",\n },\n coordinate: {\n type: \"array\",\n description:\n \"(x, y): The x (pixels from the left edge) and y (pixels from the top edge) coordinates to move the mouse to. Required only by `action=left_click`, `action=mouse_move`, and `action=type`.\",\n },\n pixels: {\n type: \"number\",\n description:\n \"The amount of scrolling to perform. Positive values scroll up, negative values scroll down. Required only by `action=scroll`.\",\n },\n fact: {\n type: \"string\",\n description:\n \"The fact to remember for the future. Required only by `action=pause_and_memorize_fact`.\",\n },\n time: {\n type: \"number\",\n description: \"The seconds to wait. Required only by `action=wait`.\",\n },\n status: {\n type: \"string\",\n description:\n \"The status of the task. Required only by `action=terminate`.\",\n enum: [\"success\", \"failure\"],\n },\n },\n },\n };\n\n // Format as FARA function calling template (FN_CALL_TEMPLATE format)\n const toolDescs = JSON.stringify(toolSchema, null, 2);\n const functionCallTemplate = `\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>\n${toolDescs}\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{{\"name\": <function-name>, \"arguments\": <args-json-object>}}\n</tool_call>`;\n\n return `${basePrompt}\\n\\n${functionCallTemplate}`;\n }\n\n /**\n * Parse thoughts and action from model response\n * FARA uses XML-based tool calling: <tool_call>\\n{...}\\n</tool_call>\n */\n private parseThoughtsAndAction(response: string): {\n thoughts: string;\n functionCall: FaraFunctionCall;\n } {\n try {\n const parts = response.split(\"<tool_call>\\n\");\n const thoughts = parts[0].trim();\n const actionText = parts[1].split(\"\\n</tool_call>\")[0].trim();\n\n let parsedAction;\n try {\n parsedAction = JSON.parse(actionText);\n } catch (jsonError) {\n // Fix common malformed JSON: double opening brackets {{\"name\": ...}}\n // This happens when the model adds an extra opening brace\n if (actionText.startsWith(\"{{\") && actionText.endsWith(\"}\")) {\n // Remove the extra opening brace\n const fixedText = actionText.slice(1);\n try {\n parsedAction = JSON.parse(fixedText);\n } catch (retryError) {\n throw new Error(\n `Failed to parse action text even after fixing double brackets. Original: ${actionText}. Fixed: ${fixedText}. Error: ${retryError}`,\n { cause: retryError },\n );\n }\n } else {\n throw new Error(\n `Failed to parse action text as JSON: ${actionText}. Error: ${jsonError}`,\n { cause: jsonError },\n );\n }\n }\n\n return {\n thoughts,\n functionCall: {\n name: parsedAction.name || \"computer_use\",\n arguments: {\n ...parsedAction.arguments,\n thoughts,\n },\n },\n };\n } catch (error) {\n throw new Error(\n `Failed to parse FARA tool call from response: ${response}. Error: ${error}`,\n { cause: error },\n );\n }\n }\n\n /**\n * Convert FARA function call to Stagehand AgentAction\n */\n private convertFunctionCallToAction(\n functionCall: FaraFunctionCall,\n ): AgentAction {\n const args = functionCall.arguments;\n const action = args.action as string;\n\n // Transform coordinates from resized to original viewport\n const transformCoordinate = (coord: number[]): number[] => {\n if (!coord || coord.length !== 2) return coord;\n const [x, y] = coord;\n const scaleX = this.currentViewport.width / this.resizedViewport.width;\n const scaleY = this.currentViewport.height / this.resizedViewport.height;\n return [Math.round(x * scaleX), Math.round(y * scaleY)];\n };\n\n const baseAction = {\n type: action,\n reasoning: args.thoughts as string,\n };\n\n switch (action) {\n case \"left_click\": {\n const clickCoord = transformCoordinate(args.coordinate as number[]);\n return {\n ...baseAction,\n type: \"click\",\n x: clickCoord[0],\n y: clickCoord[1],\n button: \"left\" as const,\n };\n }\n\n case \"mouse_move\": {\n const moveCoord = transformCoordinate(args.coordinate as number[]);\n return {\n ...baseAction,\n type: \"move\",\n coordinate: moveCoord,\n };\n }\n\n case \"type\": {\n const typeCoord = args.coordinate\n ? transformCoordinate(args.coordinate as number[])\n : undefined;\n return {\n ...baseAction,\n text: args.text as string,\n ...(typeCoord && { x: typeCoord[0], y: typeCoord[1] }),\n press_enter:\n args.press_enter !== undefined\n ? (args.press_enter as boolean)\n : true,\n ...(args.delete_existing_text !== undefined && {\n delete_existing_text: args.delete_existing_text as boolean,\n }),\n };\n }\n\n case \"key\":\n case \"keypress\": {\n const keys = (args.keys as string[]) || [];\n // Normalize keys to Playwright format\n const normalizedKeys = keys.map((k) => mapKeyToPlaywright(k));\n return {\n ...baseAction,\n type: \"keypress\",\n keys: normalizedKeys,\n };\n }\n\n case \"scroll\": {\n const pixels = (args.pixels as number) || 0;\n // FARA: positive = scroll up, negative = scroll down\n // Convert to scroll_x/scroll_y\n return {\n ...baseAction,\n scroll_x: 0,\n scroll_y: -pixels, // Invert: negative pixels = scroll down\n };\n }\n\n case \"visit_url\": {\n let url = args.url as string;\n // Enhanced URL processing like Python\n if (\n !url.startsWith(\"https://\") &&\n !url.startsWith(\"http://\") &&\n !url.startsWith(\"file://\") &&\n !url.startsWith(\"about:\")\n ) {\n // If URL contains space, treat as search query\n if (url.includes(\" \")) {\n url = `https://www.bing.com/search?q=${encodeURIComponent(url)}&FORM=QBLH`;\n } else {\n // Otherwise prefix with https://\n url = \"https://\" + url;\n }\n }\n return {\n ...baseAction,\n type: \"goto\",\n url,\n };\n }\n\n case \"web_search\": {\n // Convert web search to visit_url with Bing search\n const query = args.query as string;\n const searchUrl = `https://www.bing.com/search?q=${encodeURIComponent(query)}&FORM=QBLH`;\n return {\n ...baseAction,\n type: \"goto\",\n url: searchUrl,\n };\n }\n\n case \"history_back\":\n return {\n ...baseAction,\n type: \"back\",\n };\n\n case \"wait\": {\n // Support both 'time' and 'duration' parameters with default (matches Python)\n const durationSeconds =\n (args.time as number) || (args.duration as number) || 3.0;\n return {\n ...baseAction,\n timeMs: durationSeconds * 1000, // Convert seconds to ms\n };\n }\n\n case \"pause_and_memorize_fact\": {\n // Store the fact for future reference (matches Python)\n const fact = args.fact as string;\n this.facts.push(fact);\n return {\n ...baseAction,\n fact,\n };\n }\n\n case \"terminate\":\n return {\n ...baseAction,\n status: args.status as string,\n };\n\n default:\n return {\n ...baseAction,\n ...args,\n };\n }\n }\n\n /**\n * Capture a screenshot and return as base64 data URL\n */\n async captureScreenshot(): Promise<string> {\n if (!this.screenshotProvider) {\n throw new AgentScreenshotProviderError(\"Screenshot provider not set\");\n }\n\n const base64Screenshot = await this.screenshotProvider();\n return `data:image/png;base64,${base64Screenshot}`;\n }\n\n /**\n * Remove old screenshots from history\n * Matches Python's maybe_remove_old_screenshots\n */\n private maybeRemoveOldScreenshots(\n history: FaraMessage[],\n includesCurrent: boolean = false,\n ): FaraMessage[] {\n if (this.maxImages <= 0) {\n return history;\n }\n\n const maxImages = includesCurrent ? this.maxImages : this.maxImages - 1;\n const newHistory: FaraMessage[] = [];\n let nImages = 0;\n\n // Iterate backwards\n for (let i = history.length - 1; i >= 0; i--) {\n const msg = history[i];\n\n // Check if message has image\n let hasImage = false;\n if (Array.isArray(msg.content)) {\n hasImage = msg.content.some((c) => c.type === \"image_url\");\n }\n\n if (i === 0 && nImages >= maxImages) {\n // First message (task) - preserve text, remove image\n if (Array.isArray(msg.content)) {\n const newContent = msg.content.filter((c) => c.type !== \"image_url\");\n // If no content left, skip (unless it's the only message, but Python logic says continue)\n if (newContent.length === 0) {\n continue;\n }\n newHistory.push({ ...msg, content: newContent });\n } else {\n newHistory.push(msg);\n }\n continue;\n }\n\n if (hasImage) {\n if (nImages < maxImages) {\n newHistory.push(msg);\n nImages++;\n } else {\n // Remove image, keep text\n if (Array.isArray(msg.content)) {\n const newContent = msg.content.filter(\n (c) => c.type !== \"image_url\",\n );\n // If content becomes empty, we can skip this message entirely (unless it's meaningful text)\n // Python logic: if msg is None continue.\n if (newContent.length > 0) {\n newHistory.push({ ...msg, content: newContent });\n }\n } else {\n newHistory.push(msg);\n }\n }\n } else {\n newHistory.push(msg);\n }\n }\n\n return newHistory.reverse();\n }\n\n /**\n * Reconstruct history for API call\n * Merges conceptual chat history with raw action history\n */\n private reconstructHistory(): FaraMessage[] {\n const history: FaraMessage[] = [];\n let actionTurn = 0;\n\n for (let i = 0; i < this.conversationHistory.length; i++) {\n const m = this.conversationHistory[i];\n if (m.role === \"assistant\") {\n if (actionTurn >= this.actionHistory.length) {\n // Should not happen if synced correctly\n console.warn(\"OUT OF SYNC: Action history shorter than chat history\");\n history.push(m);\n } else {\n history.push(this.actionHistory[actionTurn]);\n actionTurn++;\n }\n } else {\n history.push(m);\n }\n }\n\n return this.maybeRemoveOldScreenshots(history);\n }\n\n /**\n * Execute a single step\n */\n private async executeStep(\n logger: (message: LogLine) => void,\n isFirstRound: boolean = false,\n ): Promise<{\n actions: AgentAction[];\n completed: boolean;\n usage: {\n input_tokens: number;\n output_tokens: number;\n inference_time_ms: number;\n };\n }> {\n // Capture screenshot\n const screenshotDataUrl = await this.captureScreenshot();\n\n // Update conversation history with new screenshot/message\n if (isFirstRound) {\n // First round: modify the last message (initial user instruction) to include screenshot\n const lastMessage =\n this.conversationHistory[this.conversationHistory.length - 1];\n if (lastMessage && lastMessage.role === \"user\") {\n const originalContent =\n typeof lastMessage.content === \"string\"\n ? lastMessage.content\n : (lastMessage.content.find((c) => c.type === \"text\")?.text ??\n \"Start task\");\n\n lastMessage.content = [\n {\n type: \"image_url\",\n image_url: { url: screenshotDataUrl },\n },\n {\n type: \"text\",\n text: originalContent,\n },\n ];\n }\n } else {\n // Subsequent rounds: add new user message with screenshot\n const userContent: FaraMessageContent[] = [\n {\n type: \"image_url\",\n image_url: { url: screenshotDataUrl },\n },\n ];\n\n // Add current URL if available\n let textPrompt =\n \"Here is the next screenshot. Think about what to do next.\";\n if (this.currentUrl) {\n const trimmedUrl =\n this.currentUrl.length > 100\n ? this.currentUrl.slice(0, 100) + \"...\"\n : this.currentUrl;\n textPrompt = `Current URL: ${trimmedUrl}\\n${textPrompt}`;\n }\n\n userContent.push({\n type: \"text\",\n text: textPrompt,\n });\n\n this.conversationHistory.push({\n role: \"user\",\n content: userContent,\n });\n }\n\n // Reconstruct history for model call\n let history = this.reconstructHistory();\n\n // Prepend system prompt (generated fresh)\n const systemMessage: FaraMessage = {\n role: \"system\",\n content: this.generateSystemPrompt(),\n };\n history = [systemMessage, ...history];\n\n // Make API call\n logger({\n category: \"agent\",\n message: `Making API call to FARA model with ${history.length} messages`,\n level: 2,\n });\n\n const startTime = Date.now();\n let response;\n try {\n response = await this.client.chat.completions.create({\n model: this.modelName,\n messages: history as unknown as ChatCompletionMessageParam[],\n temperature: this.temperature,\n });\n } catch (apiError) {\n logger({\n category: \"agent\",\n message: `API call failed: ${apiError instanceof Error ? apiError.message : String(apiError)}`,\n level: 0,\n });\n throw apiError;\n }\n const inferenceTime = Date.now() - startTime;\n\n logger({\n category: \"agent\",\n message: `API call completed in ${inferenceTime}ms`,\n level: 2,\n });\n\n const content = response.choices[0].message.content || \"\";\n const usage = response.usage || {\n prompt_tokens: 0,\n completion_tokens: 0,\n total_tokens: 0,\n };\n\n // Add assistant response to both histories\n const assistantMsg: FaraMessage = {\n role: \"assistant\",\n content,\n };\n this.conversationHistory.push(assistantMsg);\n this.actionHistory.push(assistantMsg);\n\n logger({\n category: \"agent\",\n message: `Model response: ${content}`,\n level: 2,\n });\n\n // Parse tool call\n const { thoughts, functionCall } = this.parseThoughtsAndAction(content);\n\n logger({\n category: \"agent\",\n message: `Thoughts: ${thoughts}`,\n level: 2,\n });\n\n logger({\n category: \"agent\",\n message: `Action: ${JSON.stringify(functionCall.arguments)}`,\n level: 2,\n });\n\n // Convert to AgentAction\n const agentAction = this.convertFunctionCallToAction(functionCall);\n\n // Expand type action into multiple actions if it has coordinates\n const actions: AgentAction[] = [];\n if (\n agentAction.type === \"type\" &&\n typeof agentAction.x === \"number\" &&\n typeof agentAction.y === \"number\"\n ) {\n // First, click at the coordinates to focus the field\n actions.push({\n type: \"click\",\n x: agentAction.x,\n y: agentAction.y,\n button: \"left\",\n });\n\n // If delete_existing_text is true, clear the field first\n if (agentAction.delete_existing_text) {\n actions.push({\n type: \"keypress\",\n keys: [\"Command+A\"],\n });\n actions.push({\n type: \"keypress\",\n keys: [\"Backspace\"],\n });\n }\n\n // Add the type action (without coordinates since we already clicked)\n actions.push({\n type: \"type\",\n text: agentAction.text,\n });\n\n // If press_enter is true (default), press Enter after typing\n if (agentAction.press_enter !== false) {\n actions.push({\n type: \"keypress\",\n keys: [\"Enter\"],\n });\n }\n } else {\n // For all other actions, just add as-is\n actions.push(agentAction);\n }\n\n // Execute all actions if handler is available\n if (this.actionHandler && agentAction.type !== \"terminate\") {\n for (const action of actions) {\n await this.actionHandler(action);\n }\n }\n\n // Check if completed\n const completed = functionCall.arguments.action === \"terminate\";\n\n return {\n actions,\n completed,\n usage: {\n input_tokens: usage.prompt_tokens,\n output_tokens: usage.completion_tokens,\n inference_time_ms: inferenceTime,\n },\n };\n }\n\n /**\n * Execute a task with the FARA CUA\n * This is the main entry point for the agent\n * @implements AgentClient.execute\n */\n async execute(executionOptions: AgentExecutionOptions): Promise<AgentResult> {\n const { options, logger } = executionOptions;\n const { instruction } = options;\n const maxSteps = options.maxSteps || 10;\n\n let currentStep = 0;\n let completed = false;\n const actions: AgentAction[] = [];\n const messageList: string[] = [];\n let finalMessage: string;\n let totalInputTokens = 0;\n let totalOutputTokens = 0;\n let totalInferenceTime = 0;\n\n // Initialize conversation with user instruction\n // System prompt is NOT added here, it's added dynamically in executeStep\n this.conversationHistory = [\n {\n role: \"user\",\n content: instruction,\n },\n ];\n this.actionHistory = [];\n\n try {\n // Execute steps until completion or max steps reached\n while (!completed && currentStep < maxSteps) {\n await this.preStepHook?.();\n\n logger({\n category: \"agent\",\n message: `Executing step ${currentStep + 1}/${maxSteps}`,\n level: 1,\n });\n\n const isFirstRound = currentStep === 0;\n const result = await this.executeStep(logger, isFirstRound);\n totalInputTokens += result.usage.input_tokens;\n totalOutputTokens += result.usage.output_tokens;\n totalInferenceTime += result.usage.inference_time_ms;\n\n // Add actions to the list\n actions.push(...result.actions);\n\n // Update completion status\n completed = result.completed;\n\n currentStep++;\n\n // Record message for this step\n const lastAction = result.actions[result.actions.length - 1];\n if (lastAction?.reasoning) {\n messageList.push(lastAction.reasoning);\n }\n }\n\n // Generate final message\n if (completed) {\n const lastAction = actions[actions.length - 1];\n finalMessage =\n (lastAction as { status?: string })?.status === \"success\"\n ? \"Task completed successfully.\"\n : \"Task completed with failures.\";\n } else {\n finalMessage = `Reached maximum steps (${maxSteps}) without completion.`;\n }\n\n if (messageList.length > 0) {\n finalMessage = `${messageList.join(\"\\n\\n\")}\\n\\n${finalMessage}`;\n }\n\n return {\n success: completed,\n completed,\n message: finalMessage,\n actions,\n usage: {\n input_tokens: totalInputTokens,\n output_tokens: totalOutputTokens,\n inference_time_ms: totalInferenceTime,\n },\n };\n } catch (error) {\n logger({\n category: \"agent\",\n message: `Error during execution: ${error}`,\n level: 0,\n });\n\n // Rethrow to allow eval runner's retry logic to handle transient errors\n throw error;\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"MicrosoftCUAClient.js","sourceRoot":"","sources":["../../../../../lib/v3/agent/MicrosoftCUAClient.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAS5B,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,4BAA4B,EAAE,MAAM,8BAA8B,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D,OAAO,EACL,UAAU,EACV,0BAA0B,EAC1B,4BAA4B,GAC7B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AA8BpC;;;GAGG;AACH,MAAM,OAAO,kBAAmB,SAAQ,WAAW;IACzC,MAAM,CAAS;IACf,OAAO,CAAS;IAChB,MAAM,CAAS;IACf,eAAe,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;IAC/C,UAAU,CAAU;IACpB,kBAAkB,CAAyB;IAC3C,aAAa,CAA0C;IAE/D,sBAAsB;IACd,mBAAmB,GAAkB,EAAE,CAAC,CAAC,kBAAkB;IAC3D,aAAa,GAAkB,EAAE,CAA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oBACT,UAAkC,EAAE,MAAM,KAAK,SAAS;wBACvD,CAAC,CAAC,8BAA8B;wBAChC,CAAC,CAAC,+BAA+B,CAAC;YACxC,CAAC;iBAAM,CAAC;gBACN,YAAY,GAAG,0BAA0B,QAAQ,uBAAuB,CAAC;YAC3E,CAAC;YAED,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC3B,YAAY,GAAG,GAAG,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,YAAY,EAAE,CAAC;YAClE,CAAC;YAED,OAAO;gBACL,OAAO,EAAE,SAAS;gBAClB,SAAS;gBACT,OAAO,EAAE,YAAY;gBACrB,OAAO;gBACP,KAAK,EAAE;oBACL,YAAY,EAAE,gBAAgB;oBAC9B,aAAa,EAAE,iBAAiB;oBAChC,iBAAiB,EAAE,kBAAkB;iBACtC;aACF,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC;gBACL,QAAQ,EAAE,OAAO;gBACjB,OAAO,EAAE,2BAA2B,KAAK,EAAE;gBAC3C,KAAK,EAAE,CAAC;aACT,CAAC,CAAC;YAEH,wEAAwE;YACxE,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF","sourcesContent":["import OpenAI from \"openai\";\nimport { LogLine } from \"../types/public/logs.js\";\nimport {\n AgentAction,\n AgentResult,\n AgentType,\n AgentExecutionOptions,\n} from \"../types/public/agent.js\";\nimport { ClientOptions } from \"../types/public/model.js\";\nimport { AgentClient } from \"./AgentClient.js\";\nimport { AgentScreenshotProviderError } from \"../types/public/sdkErrors.js\";\nimport { mapKeyToPlaywright } from \"./utils/cuaKeyMapping.js\";\nimport { ChatCompletionMessageParam } from \"openai/resources/chat/completions\";\nimport {\n FlowLogger,\n extractLlmCuaPromptSummary,\n extractLlmCuaResponseSummary,\n} from \"../flowlogger/FlowLogger.js\";\nimport { v7 as uuidv7 } from \"uuid\";\n\n/**\n * Message types for FARA agent\n */\ninterface FaraMessage {\n role: \"system\" | \"user\" | \"assistant\";\n content: string | FaraMessageContent[];\n}\n\ninterface FaraMessageContent {\n type: \"text\" | \"image_url\";\n text?: string;\n image_url?: {\n url: string; // data:image/png;base64,...\n };\n}\n\n/**\n * FARA function call structure (parsed from XML tags)\n */\ninterface FaraFunctionCall {\n name: string; // Always \"computer_use\"\n arguments: {\n action: string;\n thoughts?: string;\n [key: string]: unknown;\n };\n}\n\n/**\n * Client for FARA (Function-based Autonomous Research Agent) by Microsoft\n * This implementation uses OpenAI-compatible API with XML-based tool calling\n */\nexport class MicrosoftCUAClient extends AgentClient {\n private apiKey: string;\n private baseURL: string;\n private client: OpenAI;\n private currentViewport = { width: 1288, height: 711 };\n private currentUrl?: string;\n private screenshotProvider?: () => Promise<string>;\n private actionHandler?: (action: AgentAction) => Promise<void>;\n\n // Dual history system\n private conversationHistory: FaraMessage[] = []; // Conceptual flow\n private actionHistory: FaraMessage[] = []; // Raw model responses\n\n private maxImages: number = 3;\n private temperature: number = 0;\n private facts: string[] = [];\n\n // FARA-specific MLM processor config\n private readonly MLM_PROCESSOR_IM_CFG = {\n min_pixels: 3136,\n max_pixels: 12845056,\n patch_size: 14,\n merge_size: 2,\n };\n\n // Resized dimensions for model input\n private resizedViewport = { width: 1288, height: 711 };\n\n constructor(\n type: AgentType,\n modelName: string,\n userProvidedInstructions?: string,\n clientOptions?: ClientOptions,\n ) {\n super(type, modelName || \"fara-7b\", userProvidedInstructions);\n\n // Process client options\n this.apiKey =\n (clientOptions?.apiKey as string) ||\n process.env.AZURE_API_KEY ||\n process.env.FIREWORKS_API_KEY ||\n \"\";\n this.baseURL =\n (clientOptions?.baseURL as string) ||\n process.env.AZURE_ENDPOINT ||\n process.env.FIREWORKS_ENDPOINT ||\n \"\";\n\n // Store client options for reference\n this.clientOptions = {\n apiKey: this.apiKey,\n baseURL: this.baseURL,\n };\n\n // Validate API key\n if (!this.apiKey || this.apiKey === \"\") {\n throw new Error(\n \"API key is required. Please provide it via clientOptions.apiKey or AZURE_API_KEY or FIREWORKS_API_KEY environment variables.\",\n );\n }\n\n // Initialize the OpenAI client (FARA uses OpenAI-compatible API)\n this.client = new OpenAI({\n apiKey: this.apiKey,\n baseURL: this.baseURL,\n });\n\n // Max images to keep in history\n if (clientOptions?.maxImages !== undefined) {\n this.maxImages = clientOptions.maxImages as number;\n }\n\n // Temperature\n if (clientOptions?.temperature !== undefined) {\n this.temperature = clientOptions.temperature as number;\n }\n }\n\n setViewport(width: number, height: number): void {\n this.currentViewport = { width, height };\n // Compute resized viewport using smart_resize logic\n this.resizedViewport = this.smartResize(width, height);\n }\n\n setCurrentUrl(url: string): void {\n this.currentUrl = url;\n }\n\n setScreenshotProvider(provider: () => Promise<string>): void {\n this.screenshotProvider = provider;\n }\n\n setActionHandler(handler: (action: AgentAction) => Promise<void>): void {\n this.actionHandler = handler;\n }\n\n /**\n * Smart resize algorithm from FARA\n * Ensures dimensions are divisible by factor and within pixel limits\n */\n private smartResize(\n width: number,\n height: number,\n ): { width: number; height: number } {\n const { patch_size, merge_size, min_pixels, max_pixels } =\n this.MLM_PROCESSOR_IM_CFG;\n const factor = patch_size * merge_size;\n\n const roundByFactor = (num: number, f: number) => Math.round(num / f) * f;\n const ceilByFactor = (num: number, f: number) => Math.ceil(num / f) * f;\n const floorByFactor = (num: number, f: number) => Math.floor(num / f) * f;\n\n let h_bar = Math.max(factor, roundByFactor(height, factor));\n let w_bar = Math.max(factor, roundByFactor(width, factor));\n\n if (h_bar * w_bar > max_pixels) {\n const beta = Math.sqrt((height * width) / max_pixels);\n h_bar = floorByFactor(height / beta, factor);\n w_bar = floorByFactor(width / beta, factor);\n } else if (h_bar * w_bar < min_pixels) {\n const beta = Math.sqrt(min_pixels / (height * width));\n h_bar = ceilByFactor(height * beta, factor);\n w_bar = ceilByFactor(width * beta, factor);\n }\n\n return { width: w_bar, height: h_bar };\n }\n\n /**\n * Generate system prompt with tool description\n * Simplified to match Python's minimal approach\n */\n private generateSystemPrompt(): string {\n const { width, height } = this.resizedViewport;\n\n // Base prompt - Minimalist like Python\n let basePrompt = \"You are a helpful assistant.\";\n\n // Add user-provided instructions if available\n if (this.userProvidedInstructions) {\n basePrompt = `${basePrompt}\\n\\n${this.userProvidedInstructions}`;\n }\n\n // Tool description from FaraComputerUse\n const toolDescription = `Use a mouse and keyboard to interact with a computer, and take screenshots.\n* This is an interface to a desktop GUI. You do not have access to a terminal or applications menu. You must click on desktop icons to start applications.\n* Some applications may take time to start or process actions, so you may need to wait and take successive screenshots to see the results of your actions. E.g. if you click on Firefox and a window doesn't open, try wait and taking another screenshot.\n* The screen's resolution is ${width}x${height}.\n* Whenever you intend to move the cursor to click on an element like an icon, you should consult a screenshot to determine the coordinates of the element before moving the cursor.\n* If you tried clicking on a program or link but it failed to load, even after waiting, try adjusting your cursor position so that the tip of the cursor visually falls on the element that you want to click.\n* Make sure to click any buttons, links, icons, etc with the cursor tip in the center of the element. Don't click boxes on their edges unless asked.\n* When a separate scrollable container prominently overlays the webpage, if you want to scroll within it, you typically need to mouse_move() over it first and then scroll().\n* If a popup window appears that you want to close, if left_click() on the 'X' or close button doesn't work, try key(keys=['Escape']) to close it.\n* On some search bars, when you type(), you may need to press_enter=False and instead separately call left_click() on the search button to submit the search query. This is especially true of search bars that have auto-suggest popups for e.g. locations\n* For calendar widgets, you usually need to left_click() on arrows to move between months and left_click() on dates to select them; type() is not typically used to input dates there.`;\n\n // Tool parameters description\n const actionsDescription = `The action to perform. The available actions are:\n* \\`key\\`: Performs key down presses on the arguments passed in order, then performs key releases in reverse order. Includes \"Enter\", \"Alt\", \"Shift\", \"Tab\", \"Control\", \"Backspace\", \"Delete\", \"Escape\", \"ArrowUp\", \"ArrowDown\", \"ArrowLeft\", \"ArrowRight\", \"PageDown\", \"PageUp\", \"Shift\", etc.\n* \\`type\\`: Type a string of text on the keyboard.\n* \\`mouse_move\\`: Move the cursor to a specified (x, y) pixel coordinate on the screen.\n* \\`left_click\\`: Click the left mouse button.\n* \\`scroll\\`: Performs a scroll of the mouse scroll wheel.\n* \\`history_back\\`: Go back to the previous page in the browser history.\n* \\`pause_and_memorize_fact\\`: Pause and memorize a fact for future reference.\n* \\`visit_url\\`: Visit a specified URL.\n* \\`web_search\\`: Perform a web search with a specified query.\n* \\`wait\\`: Wait specified seconds for the change to happen.\n* \\`terminate\\`: Terminate the current task and report its completion status.`;\n\n // Tool JSON schema\n const toolSchema = {\n name: \"computer_use\",\n description: toolDescription,\n parameters: {\n type: \"object\",\n required: [\"action\"],\n properties: {\n action: {\n type: \"string\",\n description: actionsDescription,\n enum: [\n \"key\",\n \"type\",\n \"mouse_move\",\n \"left_click\",\n \"scroll\",\n \"visit_url\",\n \"web_search\",\n \"history_back\",\n \"pause_and_memorize_fact\",\n \"wait\",\n \"terminate\",\n ],\n },\n keys: {\n type: \"array\",\n description: \"Required only by `action=key`.\",\n },\n text: {\n type: \"string\",\n description: \"Required only by `action=type`.\",\n },\n press_enter: {\n type: \"boolean\",\n description:\n \"Whether to press the Enter key after typing. Required only by `action=type`.\",\n },\n delete_existing_text: {\n type: \"boolean\",\n description:\n \"Whether to delete existing text before typing. Required only by `action=type`.\",\n },\n coordinate: {\n type: \"array\",\n description:\n \"(x, y): The x (pixels from the left edge) and y (pixels from the top edge) coordinates to move the mouse to. Required only by `action=left_click`, `action=mouse_move`, and `action=type`.\",\n },\n pixels: {\n type: \"number\",\n description:\n \"The amount of scrolling to perform. Positive values scroll up, negative values scroll down. Required only by `action=scroll`.\",\n },\n fact: {\n type: \"string\",\n description:\n \"The fact to remember for the future. Required only by `action=pause_and_memorize_fact`.\",\n },\n time: {\n type: \"number\",\n description: \"The seconds to wait. Required only by `action=wait`.\",\n },\n status: {\n type: \"string\",\n description:\n \"The status of the task. Required only by `action=terminate`.\",\n enum: [\"success\", \"failure\"],\n },\n },\n },\n };\n\n // Format as FARA function calling template (FN_CALL_TEMPLATE format)\n const toolDescs = JSON.stringify(toolSchema, null, 2);\n const functionCallTemplate = `\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>\n${toolDescs}\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{{\"name\": <function-name>, \"arguments\": <args-json-object>}}\n</tool_call>`;\n\n return `${basePrompt}\\n\\n${functionCallTemplate}`;\n }\n\n /**\n * Parse thoughts and action from model response\n * FARA uses XML-based tool calling: <tool_call>\\n{...}\\n</tool_call>\n */\n private parseThoughtsAndAction(response: string): {\n thoughts: string;\n functionCall: FaraFunctionCall;\n } {\n try {\n const parts = response.split(\"<tool_call>\\n\");\n const thoughts = parts[0].trim();\n const actionText = parts[1].split(\"\\n</tool_call>\")[0].trim();\n\n let parsedAction;\n try {\n parsedAction = JSON.parse(actionText);\n } catch (jsonError) {\n // Fix common malformed JSON: double opening brackets {{\"name\": ...}}\n // This happens when the model adds an extra opening brace\n if (actionText.startsWith(\"{{\") && actionText.endsWith(\"}\")) {\n // Remove the extra opening brace\n const fixedText = actionText.slice(1);\n try {\n parsedAction = JSON.parse(fixedText);\n } catch (retryError) {\n throw new Error(\n `Failed to parse action text even after fixing double brackets. Original: ${actionText}. Fixed: ${fixedText}. Error: ${retryError}`,\n { cause: retryError },\n );\n }\n } else {\n throw new Error(\n `Failed to parse action text as JSON: ${actionText}. Error: ${jsonError}`,\n { cause: jsonError },\n );\n }\n }\n\n return {\n thoughts,\n functionCall: {\n name: parsedAction.name || \"computer_use\",\n arguments: {\n ...parsedAction.arguments,\n thoughts,\n },\n },\n };\n } catch (error) {\n throw new Error(\n `Failed to parse FARA tool call from response: ${response}. Error: ${error}`,\n { cause: error },\n );\n }\n }\n\n /**\n * Convert FARA function call to Stagehand AgentAction\n */\n private convertFunctionCallToAction(\n functionCall: FaraFunctionCall,\n ): AgentAction {\n const args = functionCall.arguments;\n const action = args.action as string;\n\n // Transform coordinates from resized to original viewport\n const transformCoordinate = (coord: number[]): number[] => {\n if (!coord || coord.length !== 2) return coord;\n const [x, y] = coord;\n const scaleX = this.currentViewport.width / this.resizedViewport.width;\n const scaleY = this.currentViewport.height / this.resizedViewport.height;\n return [Math.round(x * scaleX), Math.round(y * scaleY)];\n };\n\n const baseAction = {\n type: action,\n reasoning: args.thoughts as string,\n };\n\n switch (action) {\n case \"left_click\": {\n const clickCoord = transformCoordinate(args.coordinate as number[]);\n return {\n ...baseAction,\n type: \"click\",\n x: clickCoord[0],\n y: clickCoord[1],\n button: \"left\" as const,\n };\n }\n\n case \"mouse_move\": {\n const moveCoord = transformCoordinate(args.coordinate as number[]);\n return {\n ...baseAction,\n type: \"move\",\n coordinate: moveCoord,\n };\n }\n\n case \"type\": {\n const typeCoord = args.coordinate\n ? transformCoordinate(args.coordinate as number[])\n : undefined;\n return {\n ...baseAction,\n text: args.text as string,\n ...(typeCoord && { x: typeCoord[0], y: typeCoord[1] }),\n press_enter:\n args.press_enter !== undefined\n ? (args.press_enter as boolean)\n : true,\n ...(args.delete_existing_text !== undefined && {\n delete_existing_text: args.delete_existing_text as boolean,\n }),\n };\n }\n\n case \"key\":\n case \"keypress\": {\n const keys = (args.keys as string[]) || [];\n // Normalize keys to Playwright format\n const normalizedKeys = keys.map((k) => mapKeyToPlaywright(k));\n return {\n ...baseAction,\n type: \"keypress\",\n keys: normalizedKeys,\n };\n }\n\n case \"scroll\": {\n const pixels = (args.pixels as number) || 0;\n // FARA: positive = scroll up, negative = scroll down\n // Convert to scroll_x/scroll_y\n return {\n ...baseAction,\n scroll_x: 0,\n scroll_y: -pixels, // Invert: negative pixels = scroll down\n };\n }\n\n case \"visit_url\": {\n let url = args.url as string;\n // Enhanced URL processing like Python\n if (\n !url.startsWith(\"https://\") &&\n !url.startsWith(\"http://\") &&\n !url.startsWith(\"file://\") &&\n !url.startsWith(\"about:\")\n ) {\n // If URL contains space, treat as search query\n if (url.includes(\" \")) {\n url = `https://www.bing.com/search?q=${encodeURIComponent(url)}&FORM=QBLH`;\n } else {\n // Otherwise prefix with https://\n url = \"https://\" + url;\n }\n }\n return {\n ...baseAction,\n type: \"goto\",\n url,\n };\n }\n\n case \"web_search\": {\n // Convert web search to visit_url with Bing search\n const query = args.query as string;\n const searchUrl = `https://www.bing.com/search?q=${encodeURIComponent(query)}&FORM=QBLH`;\n return {\n ...baseAction,\n type: \"goto\",\n url: searchUrl,\n };\n }\n\n case \"history_back\":\n return {\n ...baseAction,\n type: \"back\",\n };\n\n case \"wait\": {\n // Support both 'time' and 'duration' parameters with default (matches Python)\n const durationSeconds =\n (args.time as number) || (args.duration as number) || 3.0;\n return {\n ...baseAction,\n timeMs: durationSeconds * 1000, // Convert seconds to ms\n };\n }\n\n case \"pause_and_memorize_fact\": {\n // Store the fact for future reference (matches Python)\n const fact = args.fact as string;\n this.facts.push(fact);\n return {\n ...baseAction,\n fact,\n };\n }\n\n case \"terminate\":\n return {\n ...baseAction,\n status: args.status as string,\n };\n\n default:\n return {\n ...baseAction,\n ...args,\n };\n }\n }\n\n /**\n * Capture a screenshot and return as base64 data URL\n */\n async captureScreenshot(): Promise<string> {\n if (!this.screenshotProvider) {\n throw new AgentScreenshotProviderError(\"Screenshot provider not set\");\n }\n\n const base64Screenshot = await this.screenshotProvider();\n return `data:image/png;base64,${base64Screenshot}`;\n }\n\n /**\n * Remove old screenshots from history\n * Matches Python's maybe_remove_old_screenshots\n */\n private maybeRemoveOldScreenshots(\n history: FaraMessage[],\n includesCurrent: boolean = false,\n ): FaraMessage[] {\n if (this.maxImages <= 0) {\n return history;\n }\n\n const maxImages = includesCurrent ? this.maxImages : this.maxImages - 1;\n const newHistory: FaraMessage[] = [];\n let nImages = 0;\n\n // Iterate backwards\n for (let i = history.length - 1; i >= 0; i--) {\n const msg = history[i];\n\n // Check if message has image\n let hasImage = false;\n if (Array.isArray(msg.content)) {\n hasImage = msg.content.some((c) => c.type === \"image_url\");\n }\n\n if (i === 0 && nImages >= maxImages) {\n // First message (task) - preserve text, remove image\n if (Array.isArray(msg.content)) {\n const newContent = msg.content.filter((c) => c.type !== \"image_url\");\n // If no content left, skip (unless it's the only message, but Python logic says continue)\n if (newContent.length === 0) {\n continue;\n }\n newHistory.push({ ...msg, content: newContent });\n } else {\n newHistory.push(msg);\n }\n continue;\n }\n\n if (hasImage) {\n if (nImages < maxImages) {\n newHistory.push(msg);\n nImages++;\n } else {\n // Remove image, keep text\n if (Array.isArray(msg.content)) {\n const newContent = msg.content.filter(\n (c) => c.type !== \"image_url\",\n );\n // If content becomes empty, we can skip this message entirely (unless it's meaningful text)\n // Python logic: if msg is None continue.\n if (newContent.length > 0) {\n newHistory.push({ ...msg, content: newContent });\n }\n } else {\n newHistory.push(msg);\n }\n }\n } else {\n newHistory.push(msg);\n }\n }\n\n return newHistory.reverse();\n }\n\n /**\n * Reconstruct history for API call\n * Merges conceptual chat history with raw action history\n */\n private reconstructHistory(): FaraMessage[] {\n const history: FaraMessage[] = [];\n let actionTurn = 0;\n\n for (let i = 0; i < this.conversationHistory.length; i++) {\n const m = this.conversationHistory[i];\n if (m.role === \"assistant\") {\n if (actionTurn >= this.actionHistory.length) {\n // Should not happen if synced correctly\n console.warn(\"OUT OF SYNC: Action history shorter than chat history\");\n history.push(m);\n } else {\n history.push(this.actionHistory[actionTurn]);\n actionTurn++;\n }\n } else {\n history.push(m);\n }\n }\n\n return this.maybeRemoveOldScreenshots(history);\n }\n\n /**\n * Execute a single step\n */\n private async executeStep(\n logger: (message: LogLine) => void,\n isFirstRound: boolean = false,\n ): Promise<{\n actions: AgentAction[];\n completed: boolean;\n usage: {\n input_tokens: number;\n output_tokens: number;\n inference_time_ms: number;\n };\n }> {\n // Capture screenshot\n const screenshotDataUrl = await this.captureScreenshot();\n\n // Update conversation history with new screenshot/message\n if (isFirstRound) {\n // First round: modify the last message (initial user instruction) to include screenshot\n const lastMessage =\n this.conversationHistory[this.conversationHistory.length - 1];\n if (lastMessage && lastMessage.role === \"user\") {\n const originalContent =\n typeof lastMessage.content === \"string\"\n ? lastMessage.content\n : (lastMessage.content.find((c) => c.type === \"text\")?.text ??\n \"Start task\");\n\n lastMessage.content = [\n {\n type: \"image_url\",\n image_url: { url: screenshotDataUrl },\n },\n {\n type: \"text\",\n text: originalContent,\n },\n ];\n }\n } else {\n // Subsequent rounds: add new user message with screenshot\n const userContent: FaraMessageContent[] = [\n {\n type: \"image_url\",\n image_url: { url: screenshotDataUrl },\n },\n ];\n\n // Add current URL if available\n let textPrompt =\n \"Here is the next screenshot. Think about what to do next.\";\n if (this.currentUrl) {\n const trimmedUrl =\n this.currentUrl.length > 100\n ? this.currentUrl.slice(0, 100) + \"...\"\n : this.currentUrl;\n textPrompt = `Current URL: ${trimmedUrl}\\n${textPrompt}`;\n }\n\n userContent.push({\n type: \"text\",\n text: textPrompt,\n });\n\n this.conversationHistory.push({\n role: \"user\",\n content: userContent,\n });\n }\n\n // Reconstruct history for model call\n let history = this.reconstructHistory();\n\n // Prepend system prompt (generated fresh)\n const systemMessage: FaraMessage = {\n role: \"system\",\n content: this.generateSystemPrompt(),\n };\n history = [systemMessage, ...history];\n\n // Make API call\n logger({\n category: \"agent\",\n message: `Making API call to FARA model with ${history.length} messages`,\n level: 2,\n });\n\n const llmRequestId = uuidv7();\n FlowLogger.logLlmRequest({\n requestId: llmRequestId,\n model: this.modelName,\n prompt: extractLlmCuaPromptSummary(history),\n });\n\n const startTime = Date.now();\n let response;\n try {\n response = await this.client.chat.completions.create({\n model: this.modelName,\n messages: history as unknown as ChatCompletionMessageParam[],\n temperature: this.temperature,\n });\n } catch (apiError) {\n logger({\n category: \"agent\",\n message: `API call failed: ${apiError instanceof Error ? apiError.message : String(apiError)}`,\n level: 0,\n });\n throw apiError;\n }\n const inferenceTime = Date.now() - startTime;\n\n logger({\n category: \"agent\",\n message: `API call completed in ${inferenceTime}ms`,\n level: 2,\n });\n\n const content = response.choices[0].message.content || \"\";\n const usage = response.usage || {\n prompt_tokens: 0,\n completion_tokens: 0,\n total_tokens: 0,\n };\n\n FlowLogger.logLlmResponse({\n requestId: llmRequestId,\n model: this.modelName,\n output: extractLlmCuaResponseSummary([{ text: content }]),\n inputTokens: usage.prompt_tokens,\n outputTokens: usage.completion_tokens,\n });\n\n // Add assistant response to both histories\n const assistantMsg: FaraMessage = {\n role: \"assistant\",\n content,\n };\n this.conversationHistory.push(assistantMsg);\n this.actionHistory.push(assistantMsg);\n\n logger({\n category: \"agent\",\n message: `Model response: ${content}`,\n level: 2,\n });\n\n // Parse tool call\n const { thoughts, functionCall } = this.parseThoughtsAndAction(content);\n\n logger({\n category: \"agent\",\n message: `Thoughts: ${thoughts}`,\n level: 2,\n });\n\n logger({\n category: \"agent\",\n message: `Action: ${JSON.stringify(functionCall.arguments)}`,\n level: 2,\n });\n\n // Convert to AgentAction\n const agentAction = this.convertFunctionCallToAction(functionCall);\n\n // Expand type action into multiple actions if it has coordinates\n const actions: AgentAction[] = [];\n if (\n agentAction.type === \"type\" &&\n typeof agentAction.x === \"number\" &&\n typeof agentAction.y === \"number\"\n ) {\n // First, click at the coordinates to focus the field\n actions.push({\n type: \"click\",\n x: agentAction.x,\n y: agentAction.y,\n button: \"left\",\n });\n\n // If delete_existing_text is true, clear the field first\n if (agentAction.delete_existing_text) {\n actions.push({\n type: \"keypress\",\n keys: [\"Command+A\"],\n });\n actions.push({\n type: \"keypress\",\n keys: [\"Backspace\"],\n });\n }\n\n // Add the type action (without coordinates since we already clicked)\n actions.push({\n type: \"type\",\n text: agentAction.text,\n });\n\n // If press_enter is true (default), press Enter after typing\n if (agentAction.press_enter !== false) {\n actions.push({\n type: \"keypress\",\n keys: [\"Enter\"],\n });\n }\n } else {\n // For all other actions, just add as-is\n actions.push(agentAction);\n }\n\n // Execute all actions if handler is available\n if (this.actionHandler && agentAction.type !== \"terminate\") {\n for (const action of actions) {\n await this.actionHandler(action);\n }\n }\n\n // Check if completed\n const completed = functionCall.arguments.action === \"terminate\";\n\n return {\n actions,\n completed,\n usage: {\n input_tokens: usage.prompt_tokens,\n output_tokens: usage.completion_tokens,\n inference_time_ms: inferenceTime,\n },\n };\n }\n\n /**\n * Execute a task with the FARA CUA\n * This is the main entry point for the agent\n * @implements AgentClient.execute\n */\n async execute(executionOptions: AgentExecutionOptions): Promise<AgentResult> {\n const { options, logger } = executionOptions;\n const { instruction } = options;\n const maxSteps = options.maxSteps || 10;\n\n let currentStep = 0;\n let completed = false;\n const actions: AgentAction[] = [];\n const messageList: string[] = [];\n let finalMessage: string;\n let totalInputTokens = 0;\n let totalOutputTokens = 0;\n let totalInferenceTime = 0;\n\n // Initialize conversation with user instruction\n // System prompt is NOT added here, it's added dynamically in executeStep\n this.conversationHistory = [\n {\n role: \"user\",\n content: instruction,\n },\n ];\n this.actionHistory = [];\n\n try {\n // Execute steps until completion or max steps reached\n while (!completed && currentStep < maxSteps) {\n await this.preStepHook?.();\n\n logger({\n category: \"agent\",\n message: `Executing step ${currentStep + 1}/${maxSteps}`,\n level: 1,\n });\n\n const isFirstRound = currentStep === 0;\n const result = await this.executeStep(logger, isFirstRound);\n totalInputTokens += result.usage.input_tokens;\n totalOutputTokens += result.usage.output_tokens;\n totalInferenceTime += result.usage.inference_time_ms;\n\n // Add actions to the list\n actions.push(...result.actions);\n\n // Update completion status\n completed = result.completed;\n\n currentStep++;\n\n // Record message for this step\n const lastAction = result.actions[result.actions.length - 1];\n if (lastAction?.reasoning) {\n messageList.push(lastAction.reasoning);\n }\n }\n\n // Generate final message\n if (completed) {\n const lastAction = actions[actions.length - 1];\n finalMessage =\n (lastAction as { status?: string })?.status === \"success\"\n ? \"Task completed successfully.\"\n : \"Task completed with failures.\";\n } else {\n finalMessage = `Reached maximum steps (${maxSteps}) without completion.`;\n }\n\n if (messageList.length > 0) {\n finalMessage = `${messageList.join(\"\\n\\n\")}\\n\\n${finalMessage}`;\n }\n\n return {\n success: completed,\n completed,\n message: finalMessage,\n actions,\n usage: {\n input_tokens: totalInputTokens,\n output_tokens: totalOutputTokens,\n inference_time_ms: totalInferenceTime,\n },\n };\n } catch (error) {\n logger({\n category: \"agent\",\n message: `Error during execution: ${error}`,\n level: 0,\n });\n\n // Rethrow to allow eval runner's retry logic to handle transient errors\n throw error;\n }\n }\n}\n"]}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import type { EasyInputMessage } from "openai/resources/responses/responses";
|
|
1
2
|
import { LogLine } from "../types/public/logs.js";
|
|
2
3
|
import { AgentAction, AgentResult, AgentType, AgentExecutionOptions, ResponseInputItem, ResponseItem, SafetyConfirmationHandler } from "../types/public/agent.js";
|
|
3
4
|
import { ClientOptions } from "../types/public/model.js";
|
|
4
5
|
import { AgentClient } from "./AgentClient.js";
|
|
5
6
|
import { ToolSet } from "ai";
|
|
7
|
+
type OpenAIRequestInputItem = ResponseInputItem | EasyInputMessage;
|
|
6
8
|
export declare class OpenAICUAClient extends AgentClient {
|
|
7
9
|
private pendingContextNotes;
|
|
8
10
|
private captchaSolvedToolActive;
|
|
@@ -19,6 +21,7 @@ export declare class OpenAICUAClient extends AgentClient {
|
|
|
19
21
|
private environment;
|
|
20
22
|
private tools?;
|
|
21
23
|
private safetyConfirmationHandler?;
|
|
24
|
+
private get usesNewComputerTool();
|
|
22
25
|
constructor(type: AgentType, modelName: string, userProvidedInstructions?: string, clientOptions?: ClientOptions, tools?: ToolSet);
|
|
23
26
|
setViewport(width: number, height: number): void;
|
|
24
27
|
setCurrentUrl(url: string): void;
|
|
@@ -37,7 +40,7 @@ export declare class OpenAICUAClient extends AgentClient {
|
|
|
37
40
|
* Execute a single step of the agent
|
|
38
41
|
* This coordinates the flow: Request → Get Action → Execute Action
|
|
39
42
|
*/
|
|
40
|
-
executeStep(inputItems:
|
|
43
|
+
executeStep(inputItems: OpenAIRequestInputItem[], previousResponseId: string | undefined, logger: (message: LogLine) => void): Promise<{
|
|
41
44
|
actions: AgentAction[];
|
|
42
45
|
message: string;
|
|
43
46
|
completed: boolean;
|
|
@@ -53,7 +56,7 @@ export declare class OpenAICUAClient extends AgentClient {
|
|
|
53
56
|
private handleSafetyConfirmation;
|
|
54
57
|
private isFunctionCallItem;
|
|
55
58
|
private createInitialInputItems;
|
|
56
|
-
getAction(inputItems:
|
|
59
|
+
getAction(inputItems: OpenAIRequestInputItem[], previousResponseId?: string): Promise<{
|
|
57
60
|
output: ResponseItem[];
|
|
58
61
|
responseId: string;
|
|
59
62
|
usage: Record<string, number>;
|
|
@@ -61,9 +64,12 @@ export declare class OpenAICUAClient extends AgentClient {
|
|
|
61
64
|
takeAction(output: ResponseItem[], logger: (message: LogLine) => void): Promise<ResponseInputItem[]>;
|
|
62
65
|
private convertComputerCallToAction;
|
|
63
66
|
private drainContextNotes;
|
|
67
|
+
private captureInitialScreenshot;
|
|
68
|
+
private convertComputerCallToActions;
|
|
64
69
|
private convertFunctionCallToAction;
|
|
65
70
|
captureScreenshot(options?: {
|
|
66
71
|
base64Image?: string;
|
|
67
72
|
currentUrl?: string;
|
|
68
73
|
}): Promise<string>;
|
|
69
74
|
}
|
|
75
|
+
export {};
|
|
@@ -24,6 +24,9 @@ export class OpenAICUAClient extends AgentClient {
|
|
|
24
24
|
environment = "browser"; // "browser", "mac", "windows", or "ubuntu"
|
|
25
25
|
tools;
|
|
26
26
|
safetyConfirmationHandler;
|
|
27
|
+
get usesNewComputerTool() {
|
|
28
|
+
return this.modelName.startsWith("gpt-5");
|
|
29
|
+
}
|
|
27
30
|
constructor(type, modelName, userProvidedInstructions, clientOptions, tools) {
|
|
28
31
|
super(type, modelName, userProvidedInstructions);
|
|
29
32
|
// Process client options
|
|
@@ -91,7 +94,7 @@ export class OpenAICUAClient extends AgentClient {
|
|
|
91
94
|
let finalMessage = "";
|
|
92
95
|
this.reasoningItems.clear(); // Clear any previous reasoning items
|
|
93
96
|
// Start with the initial instruction
|
|
94
|
-
let inputItems = this.createInitialInputItems(instruction);
|
|
97
|
+
let inputItems = await this.createInitialInputItems(instruction);
|
|
95
98
|
let previousResponseId = undefined;
|
|
96
99
|
let totalInputTokens = 0;
|
|
97
100
|
let totalOutputTokens = 0;
|
|
@@ -202,15 +205,15 @@ export class OpenAICUAClient extends AgentClient {
|
|
|
202
205
|
if (item.type === "computer_call" && this.isComputerCallItem(item)) {
|
|
203
206
|
logger({
|
|
204
207
|
category: "agent",
|
|
205
|
-
message: `Found computer_call
|
|
208
|
+
message: `Found computer_call with call_id: ${item.call_id}`,
|
|
206
209
|
level: 2,
|
|
207
210
|
});
|
|
208
|
-
const
|
|
209
|
-
|
|
211
|
+
const actions = this.convertComputerCallToActions(item);
|
|
212
|
+
for (const action of actions) {
|
|
210
213
|
stepActions.push(action);
|
|
211
214
|
logger({
|
|
212
215
|
category: "agent",
|
|
213
|
-
message: `
|
|
216
|
+
message: `Found computer_call action: ${action.type}, payload: ${JSON.stringify(action)}, call_id: ${item.call_id}`,
|
|
214
217
|
level: 2,
|
|
215
218
|
});
|
|
216
219
|
}
|
|
@@ -283,8 +286,8 @@ export class OpenAICUAClient extends AgentClient {
|
|
|
283
286
|
isComputerCallItem(item) {
|
|
284
287
|
return (item.type === "computer_call" &&
|
|
285
288
|
"call_id" in item &&
|
|
286
|
-
"action" in item &&
|
|
287
|
-
|
|
289
|
+
(("action" in item && typeof item.action === "object") ||
|
|
290
|
+
("actions" in item && Array.isArray(item.actions))));
|
|
288
291
|
}
|
|
289
292
|
async handleSafetyConfirmation(pendingSafetyChecks, logger) {
|
|
290
293
|
if (this.safetyConfirmationHandler) {
|
|
@@ -324,34 +327,54 @@ export class OpenAICUAClient extends AgentClient {
|
|
|
324
327
|
"name" in item &&
|
|
325
328
|
"arguments" in item);
|
|
326
329
|
}
|
|
327
|
-
createInitialInputItems(instruction) {
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
{
|
|
330
|
+
async createInitialInputItems(instruction) {
|
|
331
|
+
const inputItems = [];
|
|
332
|
+
if (this.userProvidedInstructions) {
|
|
333
|
+
const systemMessage = {
|
|
331
334
|
role: "system",
|
|
332
335
|
content: this.userProvidedInstructions,
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
336
|
+
};
|
|
337
|
+
inputItems.push(systemMessage);
|
|
338
|
+
}
|
|
339
|
+
const textInput = {
|
|
340
|
+
type: "input_text",
|
|
341
|
+
text: instruction,
|
|
342
|
+
};
|
|
343
|
+
const userContent = [
|
|
344
|
+
textInput,
|
|
338
345
|
];
|
|
346
|
+
const initialScreenshot = await this.captureInitialScreenshot();
|
|
347
|
+
if (initialScreenshot) {
|
|
348
|
+
const screenshotInput = {
|
|
349
|
+
type: "input_image",
|
|
350
|
+
image_url: initialScreenshot,
|
|
351
|
+
detail: "high",
|
|
352
|
+
};
|
|
353
|
+
userContent.push(screenshotInput);
|
|
354
|
+
}
|
|
355
|
+
const userMessage = {
|
|
356
|
+
role: "user",
|
|
357
|
+
content: userContent,
|
|
358
|
+
};
|
|
359
|
+
inputItems.push(userMessage);
|
|
360
|
+
return inputItems;
|
|
339
361
|
}
|
|
340
362
|
async getAction(inputItems, previousResponseId) {
|
|
341
363
|
try {
|
|
342
|
-
// Create the request parameters
|
|
364
|
+
// Create the request parameters, branching on tool format
|
|
365
|
+
const computerTool = this.usesNewComputerTool
|
|
366
|
+
? { type: "computer" }
|
|
367
|
+
: {
|
|
368
|
+
type: "computer_use_preview",
|
|
369
|
+
display_width: this.currentViewport.width,
|
|
370
|
+
display_height: this.currentViewport.height,
|
|
371
|
+
environment: this.environment,
|
|
372
|
+
};
|
|
343
373
|
const requestParams = {
|
|
344
374
|
model: this.modelName,
|
|
345
|
-
tools: [
|
|
346
|
-
{
|
|
347
|
-
type: "computer_use_preview",
|
|
348
|
-
display_width: this.currentViewport.width,
|
|
349
|
-
display_height: this.currentViewport.height,
|
|
350
|
-
environment: this.environment,
|
|
351
|
-
},
|
|
352
|
-
],
|
|
375
|
+
tools: [computerTool],
|
|
353
376
|
input: inputItems,
|
|
354
|
-
truncation: "auto",
|
|
377
|
+
...(this.usesNewComputerTool ? {} : { truncation: "auto" }),
|
|
355
378
|
};
|
|
356
379
|
// Add custom tools if available
|
|
357
380
|
if (this.tools && Object.keys(this.tools).length > 0) {
|
|
@@ -438,26 +461,34 @@ export class OpenAICUAClient extends AgentClient {
|
|
|
438
461
|
// Process each output item
|
|
439
462
|
for (const item of output) {
|
|
440
463
|
if (item.type === "computer_call" && this.isComputerCallItem(item)) {
|
|
441
|
-
// Handle computer calls
|
|
464
|
+
// Handle computer calls (both single-action and batched-actions formats)
|
|
442
465
|
try {
|
|
443
|
-
const
|
|
444
|
-
if (
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
466
|
+
const actions = this.convertComputerCallToActions(item);
|
|
467
|
+
if (this.actionHandler) {
|
|
468
|
+
for (const action of actions) {
|
|
469
|
+
logger({
|
|
470
|
+
category: "agent",
|
|
471
|
+
message: `Executing computer action: ${action.type}`,
|
|
472
|
+
level: 1,
|
|
473
|
+
});
|
|
474
|
+
await this.actionHandler(action);
|
|
475
|
+
}
|
|
451
476
|
}
|
|
452
|
-
// Capture a screenshot
|
|
477
|
+
// Capture a screenshot after all actions in the batch
|
|
453
478
|
const screenshot = await this.captureScreenshot();
|
|
454
|
-
//
|
|
479
|
+
// Build the output — use "computer_screenshot" for new format, "input_image" for legacy
|
|
480
|
+
const outputType = this.usesNewComputerTool
|
|
481
|
+
? "computer_screenshot"
|
|
482
|
+
: "input_image";
|
|
455
483
|
const outputItem = {
|
|
456
484
|
type: "computer_call_output",
|
|
457
485
|
call_id: item.call_id,
|
|
458
486
|
output: {
|
|
459
|
-
type:
|
|
487
|
+
type: outputType,
|
|
460
488
|
image_url: screenshot,
|
|
489
|
+
...(this.usesNewComputerTool
|
|
490
|
+
? { detail: "original" }
|
|
491
|
+
: {}),
|
|
461
492
|
},
|
|
462
493
|
};
|
|
463
494
|
logger({
|
|
@@ -465,8 +496,8 @@ export class OpenAICUAClient extends AgentClient {
|
|
|
465
496
|
message: `Added computer_call_output for call_id: ${item.call_id}`,
|
|
466
497
|
level: 2,
|
|
467
498
|
});
|
|
468
|
-
//
|
|
469
|
-
if (this.currentUrl) {
|
|
499
|
+
// Legacy format supports current_url on the output; new format does not
|
|
500
|
+
if (!this.usesNewComputerTool && this.currentUrl) {
|
|
470
501
|
const computerCallOutput = outputItem;
|
|
471
502
|
computerCallOutput.output.current_url = this.currentUrl;
|
|
472
503
|
}
|
|
@@ -492,19 +523,23 @@ export class OpenAICUAClient extends AgentClient {
|
|
|
492
523
|
level: 0,
|
|
493
524
|
});
|
|
494
525
|
try {
|
|
495
|
-
// Capture a screenshot even on error
|
|
496
526
|
const screenshot = await this.captureScreenshot();
|
|
527
|
+
const outputType = this.usesNewComputerTool
|
|
528
|
+
? "computer_screenshot"
|
|
529
|
+
: "input_image";
|
|
497
530
|
const errorOutputItem = {
|
|
498
531
|
type: "computer_call_output",
|
|
499
532
|
call_id: item.call_id,
|
|
500
533
|
output: {
|
|
501
|
-
type:
|
|
534
|
+
type: outputType,
|
|
502
535
|
image_url: screenshot,
|
|
503
536
|
error: errorMessage,
|
|
537
|
+
...(this.usesNewComputerTool
|
|
538
|
+
? { detail: "original" }
|
|
539
|
+
: {}),
|
|
504
540
|
},
|
|
505
541
|
};
|
|
506
|
-
|
|
507
|
-
if (this.currentUrl) {
|
|
542
|
+
if (!this.usesNewComputerTool && this.currentUrl) {
|
|
508
543
|
const computerCallOutput = errorOutputItem;
|
|
509
544
|
computerCallOutput.output.current_url = this.currentUrl;
|
|
510
545
|
}
|
|
@@ -523,13 +558,11 @@ export class OpenAICUAClient extends AgentClient {
|
|
|
523
558
|
if (screenshotError instanceof StagehandClosedError) {
|
|
524
559
|
throw screenshotError;
|
|
525
560
|
}
|
|
526
|
-
// If we can't capture a screenshot, just send the error
|
|
527
561
|
logger({
|
|
528
562
|
category: "agent",
|
|
529
563
|
message: `Error capturing screenshot: ${String(screenshotError)}`,
|
|
530
564
|
level: 0,
|
|
531
565
|
});
|
|
532
|
-
// For error cases without a screenshot, we need to use a string output
|
|
533
566
|
nextInputItems.push({
|
|
534
567
|
type: "computer_call_output",
|
|
535
568
|
call_id: item.call_id,
|
|
@@ -623,11 +656,11 @@ export class OpenAICUAClient extends AgentClient {
|
|
|
623
656
|
}
|
|
624
657
|
convertComputerCallToAction(call) {
|
|
625
658
|
const { action } = call;
|
|
626
|
-
|
|
627
|
-
|
|
659
|
+
if (!action)
|
|
660
|
+
return null;
|
|
628
661
|
return {
|
|
629
662
|
type: action.type,
|
|
630
|
-
...action,
|
|
663
|
+
...action,
|
|
631
664
|
};
|
|
632
665
|
}
|
|
633
666
|
drainContextNotes() {
|
|
@@ -638,6 +671,27 @@ export class OpenAICUAClient extends AgentClient {
|
|
|
638
671
|
this.pendingContextNotes = [];
|
|
639
672
|
return notes;
|
|
640
673
|
}
|
|
674
|
+
async captureInitialScreenshot() {
|
|
675
|
+
if (!this.screenshotProvider) {
|
|
676
|
+
return undefined;
|
|
677
|
+
}
|
|
678
|
+
try {
|
|
679
|
+
return await this.captureScreenshot();
|
|
680
|
+
}
|
|
681
|
+
catch {
|
|
682
|
+
return undefined;
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
convertComputerCallToActions(call) {
|
|
686
|
+
if (call.actions && Array.isArray(call.actions)) {
|
|
687
|
+
return call.actions.map((action) => ({
|
|
688
|
+
type: action.type,
|
|
689
|
+
...action,
|
|
690
|
+
}));
|
|
691
|
+
}
|
|
692
|
+
const single = this.convertComputerCallToAction(call);
|
|
693
|
+
return single ? [single] : [];
|
|
694
|
+
}
|
|
641
695
|
convertFunctionCallToAction(call) {
|
|
642
696
|
try {
|
|
643
697
|
const args = JSON.parse(call.arguments);
|