@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":"AnthropicCUAClient.js","sourceRoot":"","sources":["../../../../../lib/v3/agent/AnthropicCUAClient.ts"],"names":[],"mappings":";;;;;;AAaA,+DAGsC;AACtC,4DAA0C;AAE1C,qDAA+C;AAC/C,qEAAyE;AACzE,kDAA+C;AAE/C,+DAIqC;AACrC,+BAAoC;AAIpC;;;GAGG;AACH,MAAa,kBAAmB,SAAQ,4BAAW;IACzC,MAAM,CAAS;IACf,OAAO,CAAU;IACjB,MAAM,CAAY;IACnB,aAAa,CAAU;IACtB,eAAe,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;IAC/C,UAAU,CAAU;IACpB,kBAAkB,CAAyB;IAC3C,aAAa,CAA0C;IACvD,cAAc,GAAkB,IAAI,CAAC;IACrC,KAAK,CAAW;IAExB,YACE,IAAe,EACf,SAAiB,EACjB,wBAAiC,EACjC,aAA6B,EAC7B,KAAe;QAEf,KAAK,CAAC,IAAI,EAAE,SAAS,EAAE,wBAAwB,CAAC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Aj7BD,gDAi7BC","sourcesContent":["import {\n AgentAction,\n AgentResult,\n AgentType,\n AnthropicContentBlock,\n AnthropicMessage,\n AnthropicTextBlock,\n AnthropicToolResult,\n AgentExecutionOptions,\n ToolUseItem,\n} from \"../types/public/agent.js\";\nimport { LogLine } from \"../types/public/logs.js\";\nimport { ClientOptions } from \"../types/public/model.js\";\nimport {\n AgentScreenshotProviderError,\n StagehandClosedError,\n} from \"../types/public/sdkErrors.js\";\nimport Anthropic from \"@anthropic-ai/sdk\";\nimport { ToolSet } from \"ai\";\nimport { AgentClient } from \"./AgentClient.js\";\nimport { compressConversationImages } from \"./utils/imageCompression.js\";\nimport { toJsonSchema } from \"../zodCompat.js\";\nimport type { StagehandZodSchema } from \"../zodCompat.js\";\nimport {\n FlowLogger,\n extractLlmCuaPromptSummary,\n extractLlmCuaResponseSummary,\n} from \"../flowlogger/FlowLogger.js\";\nimport { v7 as uuidv7 } from \"uuid\";\n\nexport type ResponseInputItem = AnthropicMessage | AnthropicToolResult;\n\n/**\n * Client for Anthropic's Computer Use API\n * This implementation uses the official Anthropic Messages API for Computer Use\n */\nexport class AnthropicCUAClient extends AgentClient {\n private apiKey: string;\n private baseURL?: string;\n private client: Anthropic;\n public lastMessageId?: string;\n private currentViewport = { width: 1288, height: 711 };\n private currentUrl?: string;\n private screenshotProvider?: () => Promise<string>;\n private actionHandler?: (action: AgentAction) => Promise<void>;\n private thinkingBudget: number | null = null;\n private tools?: ToolSet;\n\n constructor(\n type: AgentType,\n modelName: string,\n userProvidedInstructions?: string,\n clientOptions?: ClientOptions,\n tools?: ToolSet,\n ) {\n super(type, modelName, userProvidedInstructions);\n\n // Process client options\n this.apiKey =\n (clientOptions?.apiKey as string) || process.env.ANTHROPIC_API_KEY || \"\";\n this.baseURL = (clientOptions?.baseURL as string) || undefined;\n\n // Get thinking budget if specified\n if (\n clientOptions?.thinkingBudget &&\n typeof clientOptions.thinkingBudget === \"number\"\n ) {\n this.thinkingBudget = clientOptions.thinkingBudget;\n }\n\n // Store client options for reference\n this.clientOptions = {\n apiKey: this.apiKey,\n };\n\n if (this.baseURL) {\n this.clientOptions.baseURL = this.baseURL;\n }\n\n // Initialize the Anthropic client\n this.client = new Anthropic(this.clientOptions);\n\n this.tools = tools;\n }\n\n setViewport(width: number, height: number): void {\n this.currentViewport = { 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 setTools(tools: ToolSet): void {\n this.tools = tools;\n }\n\n /**\n * Execute a task with the Anthropic 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 = \"\";\n\n // Start with the initial instruction\n let inputItems: ResponseInputItem[] =\n this.createInitialInputItems(instruction);\n\n logger({\n category: \"agent\",\n message: `Starting Anthropic agent execution with instruction: ${instruction}`,\n level: 1,\n });\n\n let totalInputTokens = 0;\n let totalOutputTokens = 0;\n let totalInferenceTime = 0;\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 result = await this.executeStep(inputItems, logger);\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 if (result.actions.length > 0) {\n logger({\n category: \"agent\",\n message: `Step ${currentStep + 1} performed ${result.actions.length} actions`,\n level: 2,\n });\n actions.push(...result.actions);\n }\n\n // Update completion status\n completed = result.completed;\n\n // Update the input items for the next step if we're continuing\n if (!completed) {\n inputItems = result.nextInputItems;\n }\n\n // Record any message for this step\n if (result.message) {\n messageList.push(result.message);\n finalMessage = result.message;\n }\n\n // Increment step counter\n currentStep++;\n }\n\n logger({\n category: \"agent\",\n message: `Anthropic agent execution completed: ${completed}, with ${actions.length} total actions performed`,\n level: 1,\n });\n\n // Return the final result\n return {\n success: completed,\n actions,\n message: finalMessage,\n completed,\n usage: {\n input_tokens: totalInputTokens,\n output_tokens: totalOutputTokens,\n inference_time_ms: totalInferenceTime,\n },\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n logger({\n category: \"agent\",\n message: `Error executing agent task: ${errorMessage}`,\n level: 0,\n });\n\n return {\n success: false,\n actions,\n message: `Failed to execute task: ${errorMessage}`,\n completed: false,\n usage: {\n input_tokens: totalInputTokens,\n output_tokens: totalOutputTokens,\n inference_time_ms: totalInferenceTime,\n },\n };\n }\n }\n\n async executeStep(\n inputItems: ResponseInputItem[],\n logger: (message: LogLine) => void,\n ): Promise<{\n actions: AgentAction[];\n message: string;\n completed: boolean;\n nextInputItems: ResponseInputItem[];\n usage: {\n input_tokens: number;\n output_tokens: number;\n inference_time_ms: number;\n };\n }> {\n try {\n // Get response from the model\n const result = await this.getAction(inputItems);\n const content = result.content;\n const usage = {\n input_tokens: result.usage.input_tokens,\n output_tokens: result.usage.output_tokens,\n inference_time_ms: result.usage.inference_time_ms,\n };\n\n logger({\n category: \"agent\",\n message: `Received response with ${content.length} content blocks`,\n level: 2,\n });\n\n // Extract actions from the content\n const stepActions: AgentAction[] = [];\n const toolUseItems: ToolUseItem[] = [];\n let message = \"\";\n\n // Process content blocks to find tool use items and text content\n for (const block of content) {\n logger({\n category: \"agent\",\n message: `Processing block type: ${block.type}, id: ${block.id || \"unknown\"}`,\n level: 2,\n });\n\n if (block.type === \"tool_use\") {\n // Direct handling of tool_use type\n logger({\n category: \"agent\",\n message: `Found tool_use block: ${JSON.stringify(block)}`,\n level: 2,\n });\n\n // Cast to ToolUseItem and add to list\n const toolUseItem = block as ToolUseItem;\n toolUseItems.push(toolUseItem);\n\n logger({\n category: \"agent\",\n message: `Added tool_use item: ${toolUseItem.name}, action: ${JSON.stringify(toolUseItem.input)}`,\n level: 2,\n });\n\n // Convert tool use to action and add to actions list\n const action = this.convertToolUseToAction(toolUseItem);\n if (action) {\n logger({\n category: \"agent\",\n message: `Created action from tool_use: ${toolUseItem.name}, action: ${action.type}`,\n level: 2,\n });\n stepActions.push(action);\n } else if (this.tools && toolUseItem.name in this.tools) {\n stepActions.push({\n type: \"custom_tool\",\n tool: toolUseItem.name,\n input: toolUseItem.input,\n } as AgentAction);\n }\n } else if (block.type === \"text\") {\n // Safe to cast here since we've verified it's a text block\n const textBlock = block as unknown as AnthropicTextBlock;\n message += textBlock.text + \"\\n\";\n\n logger({\n category: \"agent\",\n message: `Found text block: ${textBlock.text}`,\n level: 2,\n });\n } else {\n logger({\n category: \"agent\",\n message: `Found unknown block type: ${block.type}`,\n level: 2,\n });\n }\n }\n\n // Execute actions if an action handler is provided\n if (this.actionHandler && stepActions.length > 0) {\n for (const action of stepActions) {\n try {\n logger({\n category: \"agent\",\n message: `Executing action: ${action.type}`,\n level: 1,\n });\n await this.actionHandler(action);\n } catch (error) {\n if (error instanceof StagehandClosedError) {\n throw error;\n }\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n logger({\n category: \"agent\",\n message: `Error executing action ${action.type}: ${errorMessage}`,\n level: 0,\n });\n }\n }\n }\n\n // Create the assistant response message with all content blocks\n const assistantMessage: AnthropicMessage = {\n role: \"assistant\",\n content: content as unknown as AnthropicContentBlock[],\n };\n\n // Keep track of the conversation history by preserving all previous messages\n // and adding new messages at the end\n const nextInputItems: ResponseInputItem[] = [...inputItems];\n\n // Add the assistant message with tool_use blocks to the history\n compressConversationImages(nextInputItems);\n\n nextInputItems.push(assistantMessage);\n\n // Generate tool results and add them as a user message\n if (toolUseItems.length > 0) {\n const toolResults = await this.takeAction(toolUseItems, logger);\n\n if (toolResults.length > 0) {\n // Tool results are AnthropicToolResult[] which are compatible with AnthropicContentBlock[]\n const userToolResultsMessage: AnthropicMessage = {\n role: \"user\",\n content: toolResults as unknown as AnthropicContentBlock[],\n };\n nextInputItems.push(userToolResultsMessage);\n }\n }\n\n // The step is completed only if there were no tool_use items\n const completed = toolUseItems.length === 0;\n\n logger({\n category: \"agent\",\n message: `Step processed ${toolUseItems.length} tool use items, completed: ${completed}`,\n level: 2,\n });\n\n return {\n actions: stepActions,\n message: message.trim(),\n completed,\n nextInputItems,\n usage: usage,\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n logger({\n category: \"agent\",\n message: `Error executing step: ${errorMessage}`,\n level: 0,\n });\n\n throw error;\n }\n }\n\n private createInitialInputItems(instruction: string): AnthropicMessage[] {\n // For the initial request, we use a simple array with the user's instruction\n return [\n {\n role: \"system\",\n content: this.userProvidedInstructions,\n },\n {\n role: \"user\",\n content: instruction,\n },\n ];\n }\n\n async getAction(inputItems: ResponseInputItem[]): Promise<{\n content: AnthropicContentBlock[];\n id: string;\n usage: Record<string, number>;\n }> {\n try {\n // For the API request, we use the inputItems directly\n // These should already be properly formatted as a sequence of user/assistant messages\n const messages: AnthropicMessage[] = [];\n\n for (const item of inputItems) {\n if (\"role\" in item) {\n // Skip system messages as Anthropic requires system as a top-level parameter\n if (item.role !== \"system\") {\n messages.push(item);\n }\n }\n // Note: We don't need special handling for tool_result items here anymore\n // as they should already be properly wrapped in user messages\n }\n\n // Configure thinking capability if available\n const thinking = this.thinkingBudget\n ? { type: \"enabled\" as const, budget_tokens: this.thinkingBudget }\n : undefined;\n\n // Claude 4.6+ models require the newer computer_20251124 tool version\n const modelBase = this.modelName.includes(\"/\")\n ? this.modelName.split(\"/\")[1]\n : this.modelName;\n const shouldUseNewToolVersion = [\n \"claude-opus-4-6\",\n \"claude-sonnet-4-6\",\n \"claude-opus-4-5-20251101\",\n ].includes(modelBase);\n\n const computerToolType = shouldUseNewToolVersion\n ? \"computer_20251124\"\n : \"computer_20250124\";\n const betaFlag = shouldUseNewToolVersion\n ? \"computer-use-2025-11-24\"\n : \"computer-use-2025-01-24\";\n\n // Create the request parameters\n const requestParams: Record<string, unknown> = {\n model: this.modelName,\n max_tokens: 4096,\n messages: messages,\n tools: [\n {\n type: computerToolType,\n name: \"computer\",\n display_width_px: this.currentViewport.width,\n display_height_px: this.currentViewport.height,\n display_number: 1,\n },\n ],\n betas: [betaFlag],\n };\n\n // Add custom tools if available\n if (this.tools && Object.keys(this.tools).length > 0) {\n const customTools = Object.entries(this.tools).map(([name, tool]) => {\n const schema = tool.inputSchema as StagehandZodSchema;\n\n // Convert Zod schema to proper JSON schema format for Anthropic\n const jsonSchema = toJsonSchema(schema) as {\n properties?: Record<string, unknown>;\n required?: string[];\n };\n\n const inputSchema = {\n type: \"object\",\n properties: jsonSchema.properties || {},\n required: jsonSchema.required || [],\n };\n\n return {\n name,\n description: tool.description,\n input_schema: inputSchema,\n };\n });\n\n requestParams.tools = [\n ...(requestParams.tools as Record<string, unknown>[]),\n ...customTools,\n ];\n }\n\n // Add system parameter if provided\n if (this.userProvidedInstructions) {\n requestParams.system = this.userProvidedInstructions;\n }\n\n // Add thinking parameter if available\n if (thinking) {\n requestParams.thinking = thinking;\n }\n\n // Log LLM request\n const llmRequestId = uuidv7();\n FlowLogger.logLlmRequest({\n requestId: llmRequestId,\n model: this.modelName,\n prompt: extractLlmCuaPromptSummary(messages),\n });\n\n const startTime = Date.now();\n // Create the message using the Anthropic Messages API\n // @ts-expect-error - The Anthropic SDK types are stricter than what we need\n const response = await this.client.beta.messages.create(requestParams);\n const endTime = Date.now();\n const elapsedMs = endTime - startTime;\n const usage = {\n input_tokens: response.usage.input_tokens,\n output_tokens: response.usage.output_tokens,\n inference_time_ms: elapsedMs,\n };\n\n // Log LLM response\n FlowLogger.logLlmResponse({\n requestId: llmRequestId,\n model: this.modelName,\n output: extractLlmCuaResponseSummary(response.content),\n inputTokens: response.usage.input_tokens,\n outputTokens: response.usage.output_tokens,\n });\n\n // Store the message ID for future use\n this.lastMessageId = response.id;\n\n // Return the content and message ID\n return {\n // Cast the response content to our internal type\n content: response.content as unknown as AnthropicContentBlock[],\n id: response.id,\n usage,\n };\n } catch (error) {\n console.error(\"Error getting action from Anthropic:\", error);\n throw error;\n }\n }\n\n async takeAction(\n toolUseItems: ToolUseItem[],\n logger: (message: LogLine) => void,\n ): Promise<AnthropicToolResult[]> {\n const toolResults: AnthropicToolResult[] = [];\n\n logger({\n category: \"agent\",\n message: `Taking action on ${toolUseItems.length} tool use items`,\n level: 2,\n });\n\n // Process each tool use item\n for (const item of toolUseItems) {\n try {\n logger({\n category: \"agent\",\n message: `Processing tool use: ${item.name}, id: ${item.id}, action: ${JSON.stringify(item.input)}`,\n level: 2,\n });\n\n // TODO: Normalize and migrate to agentHandler\n\n // For computer tool, capture screenshot and return image\n if (item.name === \"computer\") {\n // Get action type\n const action = item.input.action as string;\n logger({\n category: \"agent\",\n message: `Computer action type: ${action}`,\n level: 2,\n });\n\n // Capture a screenshot for the response\n const screenshot = await this.captureScreenshot();\n logger({\n category: \"agent\",\n message: `Screenshot captured, length: ${screenshot.length}`,\n level: 2,\n });\n\n // Create proper image content block for Anthropic\n const imageContent = [\n {\n type: \"image\",\n source: {\n type: \"base64\",\n media_type: \"image/png\",\n data: screenshot.replace(/^data:image\\/png;base64,/, \"\"),\n },\n },\n ];\n\n // Add current URL if available\n if (this.currentUrl) {\n toolResults.push({\n type: \"tool_result\",\n tool_use_id: item.id,\n content: [\n ...imageContent,\n {\n type: \"text\",\n text: `Current URL: ${this.currentUrl}`,\n },\n ],\n });\n } else {\n toolResults.push({\n type: \"tool_result\",\n tool_use_id: item.id,\n content: imageContent,\n });\n }\n\n logger({\n category: \"agent\",\n message: `Added computer tool result for tool_use_id: ${item.id}`,\n level: 2,\n });\n } else {\n // Handle custom tools\n let toolResult = \"Tool executed successfully\";\n if (this.tools && item.name in this.tools) {\n try {\n const tool = this.tools[item.name];\n\n logger({\n category: \"agent\",\n message: `Executing tool call: ${item.name} with args: ${JSON.stringify(item.input)}`,\n level: 1,\n });\n\n const result = await tool.execute(item.input, {\n toolCallId: item.id,\n messages: [],\n });\n toolResult = JSON.stringify(result);\n\n logger({\n category: \"agent\",\n message: `Tool ${item.name} completed successfully. Result: ${toolResult}`,\n level: 1,\n });\n } catch (toolError) {\n const errorMessage =\n toolError instanceof Error\n ? toolError.message\n : String(toolError);\n toolResult = `Error executing tool: ${errorMessage}`;\n\n logger({\n category: \"agent\",\n message: `Error executing tool ${item.name}: ${errorMessage}`,\n level: 0,\n });\n }\n }\n\n toolResults.push({\n type: \"tool_result\",\n tool_use_id: item.id,\n content: [\n {\n type: \"text\",\n text: toolResult,\n },\n ],\n });\n\n logger({\n category: \"agent\",\n message: `Added custom tool result for tool ${item.name}, tool_use_id: ${item.id}`,\n level: 2,\n });\n }\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n\n logger({\n category: \"agent\",\n message: `Error executing tool use: ${errorMessage}`,\n level: 0,\n });\n\n try {\n // For computer tool, try to capture a screenshot even on error\n if (item.name === \"computer\") {\n const screenshot = await this.captureScreenshot();\n\n toolResults.push({\n type: \"tool_result\",\n tool_use_id: item.id,\n content: [\n {\n type: \"image\",\n source: {\n type: \"base64\",\n media_type: \"image/png\",\n data: screenshot.replace(/^data:image\\/png;base64,/, \"\"),\n },\n },\n {\n type: \"text\",\n text: `Error: ${errorMessage}`,\n },\n ],\n });\n\n logger({\n category: \"agent\",\n message: `Added error tool result with screenshot for tool_use_id: ${item.id}`,\n level: 1,\n });\n } else {\n // For other tools, return an error message as a text content block\n toolResults.push({\n type: \"tool_result\",\n tool_use_id: item.id,\n content: [\n {\n type: \"text\",\n text: `Error: ${errorMessage}`,\n },\n ],\n });\n\n logger({\n category: \"agent\",\n message: `Added error tool result for tool_use_id: ${item.id}`,\n level: 1,\n });\n }\n } catch (screenshotError) {\n // If we can't capture a screenshot, just send the error\n logger({\n category: \"agent\",\n message: `Error capturing screenshot: ${String(screenshotError)}`,\n level: 0,\n });\n\n toolResults.push({\n type: \"tool_result\",\n tool_use_id: item.id,\n content: [\n {\n type: \"text\",\n text: `Error: ${errorMessage}`,\n },\n ],\n });\n\n logger({\n category: \"agent\",\n message: `Added text error tool result for tool_use_id: ${item.id}`,\n level: 1,\n });\n }\n }\n }\n\n logger({\n category: \"agent\",\n message: `Prepared ${toolResults.length} tool results for next request`,\n level: 2,\n });\n\n return toolResults;\n }\n\n private convertToolUseToAction(item: ToolUseItem): AgentAction | null {\n try {\n const { name, input } = item;\n\n if (name === \"computer\") {\n // For computer actions, format according to the action type\n const action = input.action as string;\n\n if (!action) {\n console.warn(\"Missing action in tool use item:\", item);\n return null;\n }\n\n // Handle different action types specifically\n if (action === \"screenshot\") {\n return {\n type: \"screenshot\",\n ...input,\n };\n } else if (action === \"click\") {\n return {\n type: \"click\",\n x: input.x as number,\n y: input.y as number,\n button: (input.button as string) || \"left\",\n ...input,\n };\n } else if (action === \"type\") {\n return {\n type: \"type\",\n text: input.text as string,\n ...input,\n };\n } else if (action === \"keypress\" || action === \"key\") {\n return {\n type: \"keypress\",\n keys: [input.text as string],\n ...input,\n };\n } else if (action === \"double_click\" || action === \"doubleClick\") {\n return {\n type: \"doubleClick\",\n x:\n (input.x as number) ||\n (input.coordinate ? (input.coordinate as number[])[0] : 0),\n y:\n (input.y as number) ||\n (input.coordinate ? (input.coordinate as number[])[1] : 0),\n ...input,\n };\n } else if (action === \"scroll\") {\n // Convert Anthropic's coordinate, scroll_amount and scroll_direction into scroll_x and scroll_y\n const x =\n (input.x as number) ||\n (input.coordinate ? (input.coordinate as number[])[0] : 0);\n const y =\n (input.y as number) ||\n (input.coordinate ? (input.coordinate as number[])[1] : 0);\n\n // Calculate scroll_x and scroll_y based on scroll_amount and scroll_direction\n let scroll_x = 0;\n let scroll_y = 0;\n\n const scrollAmount = (input.scroll_amount as number) || 5;\n const scrollMultiplier = 100; // Pixels per unit of scroll_amount\n\n if (input.scroll_direction) {\n const direction = input.scroll_direction as string;\n if (direction === \"down\") {\n scroll_y = scrollAmount * scrollMultiplier;\n } else if (direction === \"up\") {\n scroll_y = -scrollAmount * scrollMultiplier;\n } else if (direction === \"right\") {\n scroll_x = scrollAmount * scrollMultiplier;\n } else if (direction === \"left\") {\n scroll_x = -scrollAmount * scrollMultiplier;\n }\n } else {\n // Use direct scroll_x and scroll_y if provided\n scroll_x = (input.scroll_x as number) || 0;\n scroll_y = (input.scroll_y as number) || 0;\n }\n\n return {\n type: \"scroll\",\n x: x,\n y: y,\n scroll_x: scroll_x,\n scroll_y: scroll_y,\n ...input,\n };\n } else if (action === \"move\") {\n // Handle Anthropic's coordinate format\n const coordinates = input.coordinate as number[] | undefined;\n const x = coordinates ? coordinates[0] : (input.x as number) || 0;\n const y = coordinates ? coordinates[1] : (input.y as number) || 0;\n\n return {\n type: \"move\",\n x: x,\n y: y,\n ...input,\n };\n } else if (action === \"drag\" || action === \"left_click_drag\") {\n // Make sure path is properly formatted\n const path =\n (input.path as { x: number; y: number }[]) ||\n (input.coordinate\n ? [\n {\n x: (input.start_coordinate as number[])[0],\n y: (input.start_coordinate as number[])[1],\n },\n {\n x: (input.coordinate as number[])[0],\n y: (input.coordinate as number[])[1],\n },\n ]\n : []);\n\n return {\n type: \"drag\",\n path: path,\n ...input,\n };\n } else if (action === \"wait\") {\n return {\n type: \"wait\",\n ...input,\n };\n } else if (action === \"left_click\") {\n // Convert left_click to regular click\n const coordinates = input.coordinate as number[] | undefined;\n const x = coordinates ? coordinates[0] : (input.x as number) || 0;\n const y = coordinates ? coordinates[1] : (input.y as number) || 0;\n\n return {\n type: \"click\",\n x: x,\n y: y,\n button: \"left\",\n ...input,\n };\n } else {\n // For other computer actions, use the action type directly\n return {\n type: action,\n ...input,\n };\n }\n } else if (name === \"str_replace_editor\" || name === \"bash\") {\n // For editor or bash tools\n return {\n type: name,\n params: input,\n };\n } else if (this.tools && name in this.tools) {\n return null;\n }\n\n console.warn(`Unknown tool name: ${name}`);\n return null;\n } catch (error) {\n console.error(\"Error converting tool use to action:\", error);\n return null;\n }\n }\n\n async captureScreenshot(options?: {\n base64Image?: string;\n currentUrl?: string;\n }): Promise<string> {\n // Use provided options if available\n if (options?.base64Image) {\n return `data:image/png;base64,${options.base64Image}`;\n }\n\n // Use the screenshot provider if available\n if (this.screenshotProvider) {\n try {\n const base64Image = await this.screenshotProvider();\n return `data:image/png;base64,${base64Image}`;\n } catch (error) {\n console.error(\"Error capturing screenshot:\", error);\n throw error;\n }\n }\n\n throw new AgentScreenshotProviderError(\n \"`screenshotProvider` has not been set. \" +\n \"Please call `setScreenshotProvider()` with a valid function that returns a base64-encoded image\",\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"AnthropicCUAClient.js","sourceRoot":"","sources":["../../../../../lib/v3/agent/AnthropicCUAClient.ts"],"names":[],"mappings":";;;;;;AAaA,+DAGsC;AACtC,4DAA0C;AAE1C,qDAA+C;AAC/C,qEAAyE;AACzE,kDAA+C;AAE/C,+DAIqC;AACrC,+BAAoC;AAIpC;;;GAGG;AACH,MAAa,kBAAmB,SAAQ,4BAAW;IACzC,MAAM,CAAS;IACf,OAAO,CAAU;IACjB,MAAM,CAAY;IACnB,aAAa,CAAU;IACtB,eAAe,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;IAC/C,UAAU,CAAU;IACpB,kBAAkB,CAAyB;IAC3C,aAAa,CAA0C;IACvD,cAAc,GAAkB,IAAI,CAAC;IACrC,cAAc,GAA0B,IAAI,CAAC;IAC7C,eAAe,CAAqB;IACpC,KAAK,CAAW;IAExB,YACE,IAAe,EACf,SAAiB,EACjB,wBAAiC,EACjC,aAA6B,EAC7B,KAAe;QAEf,KAAK,CAAC,IAAI,EAAE,SAAS,EAAE,wBAAwB,CAAC,CAAC;QAEjD,yBAAyB;QACzB,IAAI,CAAC,MAAM;YACR,aAAa,EAAE,MAAiB,IAAI,OAAO,CAAC,G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gBACpD,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;QAED,MAAM,IAAI,2CAA4B,CACpC,yCAAyC;YACvC,iGAAiG,CACpG,CAAC;IACJ,CAAC;CACF;AAl/BD,gDAk/BC","sourcesContent":["import {\n AgentAction,\n AgentResult,\n AgentType,\n AnthropicContentBlock,\n AnthropicMessage,\n AnthropicTextBlock,\n AnthropicToolResult,\n AgentExecutionOptions,\n ToolUseItem,\n} from \"../types/public/agent.js\";\nimport { LogLine } from \"../types/public/logs.js\";\nimport { ClientOptions, ThinkingEffort } from \"../types/public/model.js\";\nimport {\n AgentScreenshotProviderError,\n StagehandClosedError,\n} from \"../types/public/sdkErrors.js\";\nimport Anthropic from \"@anthropic-ai/sdk\";\nimport { ToolSet } from \"ai\";\nimport { AgentClient } from \"./AgentClient.js\";\nimport { compressConversationImages } from \"./utils/imageCompression.js\";\nimport { toJsonSchema } from \"../zodCompat.js\";\nimport type { StagehandZodSchema } from \"../zodCompat.js\";\nimport {\n FlowLogger,\n extractLlmCuaPromptSummary,\n extractLlmCuaResponseSummary,\n} from \"../flowlogger/FlowLogger.js\";\nimport { v7 as uuidv7 } from \"uuid\";\n\nexport type ResponseInputItem = AnthropicMessage | AnthropicToolResult;\n\n/**\n * Client for Anthropic's Computer Use API\n * This implementation uses the official Anthropic Messages API for Computer Use\n */\nexport class AnthropicCUAClient extends AgentClient {\n private apiKey: string;\n private baseURL?: string;\n private client: Anthropic;\n public lastMessageId?: string;\n private currentViewport = { width: 1288, height: 711 };\n private currentUrl?: string;\n private screenshotProvider?: () => Promise<string>;\n private actionHandler?: (action: AgentAction) => Promise<void>;\n private thinkingBudget: number | null = null;\n private thinkingEffort: ThinkingEffort | null = null;\n private userTemperature: number | undefined;\n private tools?: ToolSet;\n\n constructor(\n type: AgentType,\n modelName: string,\n userProvidedInstructions?: string,\n clientOptions?: ClientOptions,\n tools?: ToolSet,\n ) {\n super(type, modelName, userProvidedInstructions);\n\n // Process client options\n this.apiKey =\n (clientOptions?.apiKey as string) || process.env.ANTHROPIC_API_KEY || \"\";\n this.baseURL = (clientOptions?.baseURL as string) || undefined;\n\n // Get thinking budget if specified (deprecated for 4.6 models)\n if (\n clientOptions?.thinkingBudget &&\n typeof clientOptions.thinkingBudget === \"number\"\n ) {\n this.thinkingBudget = clientOptions.thinkingBudget;\n }\n\n // Get thinking effort for adaptive thinking (Claude 4.6+ models)\n if (clientOptions?.thinkingEffort) {\n this.thinkingEffort = clientOptions.thinkingEffort;\n }\n\n // Track user-specified temperature so we can warn if adaptive thinking overrides it\n this.userTemperature = clientOptions?.temperature;\n\n // Store client options for reference\n this.clientOptions = {\n apiKey: this.apiKey,\n };\n\n if (this.baseURL) {\n this.clientOptions.baseURL = this.baseURL;\n }\n\n // Initialize the Anthropic client\n this.client = new Anthropic(this.clientOptions);\n\n this.tools = tools;\n }\n\n setViewport(width: number, height: number): void {\n this.currentViewport = { 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 setTools(tools: ToolSet): void {\n this.tools = tools;\n }\n\n /**\n * Execute a task with the Anthropic 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 = \"\";\n\n // Start with the initial instruction\n let inputItems: ResponseInputItem[] =\n this.createInitialInputItems(instruction);\n\n logger({\n category: \"agent\",\n message: `Starting Anthropic agent execution with instruction: ${instruction}`,\n level: 1,\n });\n\n let totalInputTokens = 0;\n let totalOutputTokens = 0;\n let totalInferenceTime = 0;\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 result = await this.executeStep(inputItems, logger);\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 if (result.actions.length > 0) {\n logger({\n category: \"agent\",\n message: `Step ${currentStep + 1} performed ${result.actions.length} actions`,\n level: 2,\n });\n actions.push(...result.actions);\n }\n\n // Update completion status\n completed = result.completed;\n\n // Update the input items for the next step if we're continuing\n if (!completed) {\n inputItems = result.nextInputItems;\n }\n\n // Record any message for this step\n if (result.message) {\n messageList.push(result.message);\n finalMessage = result.message;\n }\n\n // Increment step counter\n currentStep++;\n }\n\n logger({\n category: \"agent\",\n message: `Anthropic agent execution completed: ${completed}, with ${actions.length} total actions performed`,\n level: 1,\n });\n\n // Return the final result\n return {\n success: completed,\n actions,\n message: finalMessage,\n completed,\n usage: {\n input_tokens: totalInputTokens,\n output_tokens: totalOutputTokens,\n inference_time_ms: totalInferenceTime,\n },\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n logger({\n category: \"agent\",\n message: `Error executing agent task: ${errorMessage}`,\n level: 0,\n });\n\n return {\n success: false,\n actions,\n message: `Failed to execute task: ${errorMessage}`,\n completed: false,\n usage: {\n input_tokens: totalInputTokens,\n output_tokens: totalOutputTokens,\n inference_time_ms: totalInferenceTime,\n },\n };\n }\n }\n\n async executeStep(\n inputItems: ResponseInputItem[],\n logger: (message: LogLine) => void,\n ): Promise<{\n actions: AgentAction[];\n message: string;\n completed: boolean;\n nextInputItems: ResponseInputItem[];\n usage: {\n input_tokens: number;\n output_tokens: number;\n inference_time_ms: number;\n };\n }> {\n try {\n // Get response from the model\n const result = await this.getAction(inputItems, logger);\n const content = result.content;\n const usage = {\n input_tokens: result.usage.input_tokens,\n output_tokens: result.usage.output_tokens,\n inference_time_ms: result.usage.inference_time_ms,\n };\n\n logger({\n category: \"agent\",\n message: `Received response with ${content.length} content blocks`,\n level: 2,\n });\n\n // Extract actions from the content\n const stepActions: AgentAction[] = [];\n const toolUseItems: ToolUseItem[] = [];\n let message = \"\";\n\n // Process content blocks to find tool use items and text content\n for (const block of content) {\n logger({\n category: \"agent\",\n message: `Processing block type: ${block.type}, id: ${block.id || \"unknown\"}`,\n level: 2,\n });\n\n if (block.type === \"tool_use\") {\n // Direct handling of tool_use type\n logger({\n category: \"agent\",\n message: `Found tool_use block: ${JSON.stringify(block)}`,\n level: 2,\n });\n\n // Cast to ToolUseItem and add to list\n const toolUseItem = block as ToolUseItem;\n toolUseItems.push(toolUseItem);\n\n logger({\n category: \"agent\",\n message: `Added tool_use item: ${toolUseItem.name}, action: ${JSON.stringify(toolUseItem.input)}`,\n level: 2,\n });\n\n // Convert tool use to action and add to actions list\n const action = this.convertToolUseToAction(toolUseItem);\n if (action) {\n logger({\n category: \"agent\",\n message: `Created action from tool_use: ${toolUseItem.name}, action: ${action.type}`,\n level: 2,\n });\n stepActions.push(action);\n } else if (this.tools && toolUseItem.name in this.tools) {\n stepActions.push({\n type: \"custom_tool\",\n tool: toolUseItem.name,\n input: toolUseItem.input,\n } as AgentAction);\n }\n } else if (block.type === \"text\") {\n // Safe to cast here since we've verified it's a text block\n const textBlock = block as unknown as AnthropicTextBlock;\n message += textBlock.text + \"\\n\";\n\n logger({\n category: \"agent\",\n message: `Found text block: ${textBlock.text}`,\n level: 2,\n });\n } else {\n logger({\n category: \"agent\",\n message: `Found unknown block type: ${block.type}`,\n level: 2,\n });\n }\n }\n\n // Execute actions if an action handler is provided\n if (this.actionHandler && stepActions.length > 0) {\n for (const action of stepActions) {\n try {\n logger({\n category: \"agent\",\n message: `Executing action: ${action.type}`,\n level: 1,\n });\n await this.actionHandler(action);\n } catch (error) {\n if (error instanceof StagehandClosedError) {\n throw error;\n }\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n logger({\n category: \"agent\",\n message: `Error executing action ${action.type}: ${errorMessage}`,\n level: 0,\n });\n }\n }\n }\n\n // Create the assistant response message with all content blocks\n const assistantMessage: AnthropicMessage = {\n role: \"assistant\",\n content: content as unknown as AnthropicContentBlock[],\n };\n\n // Keep track of the conversation history by preserving all previous messages\n // and adding new messages at the end\n const nextInputItems: ResponseInputItem[] = [...inputItems];\n\n // Add the assistant message with tool_use blocks to the history\n compressConversationImages(nextInputItems);\n\n nextInputItems.push(assistantMessage);\n\n // Generate tool results and add them as a user message\n if (toolUseItems.length > 0) {\n const toolResults = await this.takeAction(toolUseItems, logger);\n\n if (toolResults.length > 0) {\n // Tool results are AnthropicToolResult[] which are compatible with AnthropicContentBlock[]\n const userToolResultsMessage: AnthropicMessage = {\n role: \"user\",\n content: toolResults as unknown as AnthropicContentBlock[],\n };\n nextInputItems.push(userToolResultsMessage);\n }\n }\n\n // The step is completed only if there were no tool_use items\n const completed = toolUseItems.length === 0;\n\n logger({\n category: \"agent\",\n message: `Step processed ${toolUseItems.length} tool use items, completed: ${completed}`,\n level: 2,\n });\n\n return {\n actions: stepActions,\n message: message.trim(),\n completed,\n nextInputItems,\n usage: usage,\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n logger({\n category: \"agent\",\n message: `Error executing step: ${errorMessage}`,\n level: 0,\n });\n\n throw error;\n }\n }\n\n private createInitialInputItems(instruction: string): AnthropicMessage[] {\n // For the initial request, we use a simple array with the user's instruction\n return [\n {\n role: \"system\",\n content: this.userProvidedInstructions,\n },\n {\n role: \"user\",\n content: instruction,\n },\n ];\n }\n\n async getAction(\n inputItems: ResponseInputItem[],\n logger?: (message: LogLine) => void,\n ): Promise<{\n content: AnthropicContentBlock[];\n id: string;\n usage: Record<string, number>;\n }> {\n try {\n // For the API request, we use the inputItems directly\n // These should already be properly formatted as a sequence of user/assistant messages\n const messages: AnthropicMessage[] = [];\n\n for (const item of inputItems) {\n if (\"role\" in item) {\n // Skip system messages as Anthropic requires system as a top-level parameter\n if (item.role !== \"system\") {\n messages.push(item);\n }\n }\n // Note: We don't need special handling for tool_result items here anymore\n // as they should already be properly wrapped in user messages\n }\n\n // Claude 4.6+ models require the newer computer_20251124 tool version\n // and support adaptive thinking instead of budget_tokens\n const modelBase = this.modelName.includes(\"/\")\n ? this.modelName.split(\"/\")[1]\n : this.modelName;\n\n // Check if this is a Claude 4.6+ model that supports adaptive thinking\n const isAdaptiveThinkingModel = [\n \"claude-opus-4-6\",\n \"claude-sonnet-4-6\",\n ].includes(modelBase);\n\n // claude-opus-4-5-20251101 uses the newer computer tool version but does\n // NOT support adaptive thinking — it still requires budget_tokens.\n const shouldUseNewToolVersion =\n isAdaptiveThinkingModel || modelBase === \"claude-opus-4-5-20251101\";\n\n // Configure thinking capability based on model version\n // - For 4.6 models: Use adaptive thinking with effort (recommended, defaults to \"medium\")\n // - For older models: Use enabled thinking with budget_tokens (deprecated)\n let thinking:\n | { type: \"adaptive\" }\n | { type: \"enabled\"; budget_tokens: number }\n | undefined;\n let outputConfig: { effort: Exclude<ThinkingEffort, \"none\"> } | undefined;\n let useAdaptiveThinking = false;\n\n if (isAdaptiveThinkingModel) {\n if (this.thinkingBudget) {\n logger?.({\n category: \"agent\",\n message: `thinkingBudget is ignored for ${this.modelName}; use thinkingEffort instead`,\n level: 2,\n });\n }\n\n if (this.thinkingEffort !== \"none\") {\n // Claude 4.6+ models use adaptive thinking with output_config.effort\n // Default to \"medium\" effort if not explicitly specified\n // See: https://platform.claude.com/docs/en/build-with-claude/adaptive-thinking\n thinking = { type: \"adaptive\" };\n outputConfig = { effort: this.thinkingEffort || \"medium\" };\n useAdaptiveThinking = true;\n }\n } else if (this.thinkingBudget) {\n // Older models use enabled thinking with budget_tokens (deprecated for 4.6)\n thinking = { type: \"enabled\", budget_tokens: this.thinkingBudget };\n }\n\n const computerToolType = shouldUseNewToolVersion\n ? \"computer_20251124\"\n : \"computer_20250124\";\n const betaFlag = shouldUseNewToolVersion\n ? \"computer-use-2025-11-24\"\n : \"computer-use-2025-01-24\";\n\n // Create the request parameters\n const requestParams: Record<string, unknown> = {\n model: this.modelName,\n max_tokens: 4096,\n messages: messages,\n tools: [\n {\n type: computerToolType,\n name: \"computer\",\n display_width_px: this.currentViewport.width,\n display_height_px: this.currentViewport.height,\n display_number: 1,\n },\n ],\n betas: [betaFlag],\n };\n\n // Add custom tools if available\n if (this.tools && Object.keys(this.tools).length > 0) {\n const customTools = Object.entries(this.tools).map(([name, tool]) => {\n const schema = tool.inputSchema as StagehandZodSchema;\n\n // Convert Zod schema to proper JSON schema format for Anthropic\n const jsonSchema = toJsonSchema(schema) as {\n properties?: Record<string, unknown>;\n required?: string[];\n };\n\n const inputSchema = {\n type: \"object\",\n properties: jsonSchema.properties || {},\n required: jsonSchema.required || [],\n };\n\n return {\n name,\n description: tool.description,\n input_schema: inputSchema,\n };\n });\n\n requestParams.tools = [\n ...(requestParams.tools as Record<string, unknown>[]),\n ...customTools,\n ];\n }\n\n // Add system parameter if provided\n if (this.userProvidedInstructions) {\n requestParams.system = this.userProvidedInstructions;\n }\n\n // Add thinking parameter if available\n if (thinking) {\n requestParams.thinking = thinking;\n }\n\n // Add output_config for adaptive thinking (Claude 4.6+ models)\n if (outputConfig) {\n requestParams.output_config = outputConfig;\n }\n\n // Adaptive thinking requires temperature to be set to 1\n // See: https://platform.claude.com/docs/en/build-with-claude/adaptive-thinking\n if (useAdaptiveThinking) {\n if (this.userTemperature !== undefined && this.userTemperature !== 1) {\n logger?.({\n category: \"agent\",\n message: `Adaptive thinking requires temperature=1; overriding user-specified temperature=${this.userTemperature}`,\n level: 2,\n });\n }\n requestParams.temperature = 1;\n }\n\n // Log LLM request\n const llmRequestId = uuidv7();\n FlowLogger.logLlmRequest({\n requestId: llmRequestId,\n model: this.modelName,\n prompt: extractLlmCuaPromptSummary(messages),\n });\n\n const startTime = Date.now();\n // Create the message using the Anthropic Messages API\n // @ts-expect-error - The Anthropic SDK types are stricter than what we need\n const response = await this.client.beta.messages.create(requestParams);\n const endTime = Date.now();\n const elapsedMs = endTime - startTime;\n const usage = {\n input_tokens: response.usage.input_tokens,\n output_tokens: response.usage.output_tokens,\n inference_time_ms: elapsedMs,\n };\n\n // Log LLM response\n FlowLogger.logLlmResponse({\n requestId: llmRequestId,\n model: this.modelName,\n output: extractLlmCuaResponseSummary(response.content),\n inputTokens: response.usage.input_tokens,\n outputTokens: response.usage.output_tokens,\n });\n\n // Store the message ID for future use\n this.lastMessageId = response.id;\n\n // Return the content and message ID\n return {\n // Cast the response content to our internal type\n content: response.content as unknown as AnthropicContentBlock[],\n id: response.id,\n usage,\n };\n } catch (error) {\n console.error(\"Error getting action from Anthropic:\", error);\n throw error;\n }\n }\n\n async takeAction(\n toolUseItems: ToolUseItem[],\n logger: (message: LogLine) => void,\n ): Promise<AnthropicToolResult[]> {\n const toolResults: AnthropicToolResult[] = [];\n\n logger({\n category: \"agent\",\n message: `Taking action on ${toolUseItems.length} tool use items`,\n level: 2,\n });\n\n // Process each tool use item\n for (const item of toolUseItems) {\n try {\n logger({\n category: \"agent\",\n message: `Processing tool use: ${item.name}, id: ${item.id}, action: ${JSON.stringify(item.input)}`,\n level: 2,\n });\n\n // TODO: Normalize and migrate to agentHandler\n\n // For computer tool, capture screenshot and return image\n if (item.name === \"computer\") {\n // Get action type\n const action = item.input.action as string;\n logger({\n category: \"agent\",\n message: `Computer action type: ${action}`,\n level: 2,\n });\n\n // Capture a screenshot for the response\n const screenshot = await this.captureScreenshot();\n logger({\n category: \"agent\",\n message: `Screenshot captured, length: ${screenshot.length}`,\n level: 2,\n });\n\n // Create proper image content block for Anthropic\n const imageContent = [\n {\n type: \"image\",\n source: {\n type: \"base64\",\n media_type: \"image/png\",\n data: screenshot.replace(/^data:image\\/png;base64,/, \"\"),\n },\n },\n ];\n\n // Add current URL if available\n if (this.currentUrl) {\n toolResults.push({\n type: \"tool_result\",\n tool_use_id: item.id,\n content: [\n ...imageContent,\n {\n type: \"text\",\n text: `Current URL: ${this.currentUrl}`,\n },\n ],\n });\n } else {\n toolResults.push({\n type: \"tool_result\",\n tool_use_id: item.id,\n content: imageContent,\n });\n }\n\n logger({\n category: \"agent\",\n message: `Added computer tool result for tool_use_id: ${item.id}`,\n level: 2,\n });\n } else {\n // Handle custom tools\n let toolResult = \"Tool executed successfully\";\n if (this.tools && item.name in this.tools) {\n try {\n const tool = this.tools[item.name];\n\n logger({\n category: \"agent\",\n message: `Executing tool call: ${item.name} with args: ${JSON.stringify(item.input)}`,\n level: 1,\n });\n\n const result = await tool.execute(item.input, {\n toolCallId: item.id,\n messages: [],\n });\n toolResult = JSON.stringify(result);\n\n logger({\n category: \"agent\",\n message: `Tool ${item.name} completed successfully. Result: ${toolResult}`,\n level: 1,\n });\n } catch (toolError) {\n const errorMessage =\n toolError instanceof Error\n ? toolError.message\n : String(toolError);\n toolResult = `Error executing tool: ${errorMessage}`;\n\n logger({\n category: \"agent\",\n message: `Error executing tool ${item.name}: ${errorMessage}`,\n level: 0,\n });\n }\n }\n\n toolResults.push({\n type: \"tool_result\",\n tool_use_id: item.id,\n content: [\n {\n type: \"text\",\n text: toolResult,\n },\n ],\n });\n\n logger({\n category: \"agent\",\n message: `Added custom tool result for tool ${item.name}, tool_use_id: ${item.id}`,\n level: 2,\n });\n }\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n\n logger({\n category: \"agent\",\n message: `Error executing tool use: ${errorMessage}`,\n level: 0,\n });\n\n try {\n // For computer tool, try to capture a screenshot even on error\n if (item.name === \"computer\") {\n const screenshot = await this.captureScreenshot();\n\n toolResults.push({\n type: \"tool_result\",\n tool_use_id: item.id,\n content: [\n {\n type: \"image\",\n source: {\n type: \"base64\",\n media_type: \"image/png\",\n data: screenshot.replace(/^data:image\\/png;base64,/, \"\"),\n },\n },\n {\n type: \"text\",\n text: `Error: ${errorMessage}`,\n },\n ],\n });\n\n logger({\n category: \"agent\",\n message: `Added error tool result with screenshot for tool_use_id: ${item.id}`,\n level: 1,\n });\n } else {\n // For other tools, return an error message as a text content block\n toolResults.push({\n type: \"tool_result\",\n tool_use_id: item.id,\n content: [\n {\n type: \"text\",\n text: `Error: ${errorMessage}`,\n },\n ],\n });\n\n logger({\n category: \"agent\",\n message: `Added error tool result for tool_use_id: ${item.id}`,\n level: 1,\n });\n }\n } catch (screenshotError) {\n // If we can't capture a screenshot, just send the error\n logger({\n category: \"agent\",\n message: `Error capturing screenshot: ${String(screenshotError)}`,\n level: 0,\n });\n\n toolResults.push({\n type: \"tool_result\",\n tool_use_id: item.id,\n content: [\n {\n type: \"text\",\n text: `Error: ${errorMessage}`,\n },\n ],\n });\n\n logger({\n category: \"agent\",\n message: `Added text error tool result for tool_use_id: ${item.id}`,\n level: 1,\n });\n }\n }\n }\n\n logger({\n category: \"agent\",\n message: `Prepared ${toolResults.length} tool results for next request`,\n level: 2,\n });\n\n return toolResults;\n }\n\n private convertToolUseToAction(item: ToolUseItem): AgentAction | null {\n try {\n const { name, input } = item;\n\n if (name === \"computer\") {\n // For computer actions, format according to the action type\n const action = input.action as string;\n\n if (!action) {\n console.warn(\"Missing action in tool use item:\", item);\n return null;\n }\n\n // Handle different action types specifically\n if (action === \"screenshot\") {\n return {\n type: \"screenshot\",\n ...input,\n };\n } else if (action === \"click\") {\n return {\n type: \"click\",\n x: input.x as number,\n y: input.y as number,\n button: (input.button as string) || \"left\",\n ...input,\n };\n } else if (action === \"type\") {\n return {\n type: \"type\",\n text: input.text as string,\n ...input,\n };\n } else if (action === \"keypress\" || action === \"key\") {\n return {\n type: \"keypress\",\n keys: [input.text as string],\n ...input,\n };\n } else if (action === \"double_click\" || action === \"doubleClick\") {\n return {\n type: \"doubleClick\",\n x:\n (input.x as number) ||\n (input.coordinate ? (input.coordinate as number[])[0] : 0),\n y:\n (input.y as number) ||\n (input.coordinate ? (input.coordinate as number[])[1] : 0),\n ...input,\n };\n } else if (action === \"scroll\") {\n // Convert Anthropic's coordinate, scroll_amount and scroll_direction into scroll_x and scroll_y\n const x =\n (input.x as number) ||\n (input.coordinate ? (input.coordinate as number[])[0] : 0);\n const y =\n (input.y as number) ||\n (input.coordinate ? (input.coordinate as number[])[1] : 0);\n\n // Calculate scroll_x and scroll_y based on scroll_amount and scroll_direction\n let scroll_x = 0;\n let scroll_y = 0;\n\n const scrollAmount = (input.scroll_amount as number) || 5;\n const scrollMultiplier = 100; // Pixels per unit of scroll_amount\n\n if (input.scroll_direction) {\n const direction = input.scroll_direction as string;\n if (direction === \"down\") {\n scroll_y = scrollAmount * scrollMultiplier;\n } else if (direction === \"up\") {\n scroll_y = -scrollAmount * scrollMultiplier;\n } else if (direction === \"right\") {\n scroll_x = scrollAmount * scrollMultiplier;\n } else if (direction === \"left\") {\n scroll_x = -scrollAmount * scrollMultiplier;\n }\n } else {\n // Use direct scroll_x and scroll_y if provided\n scroll_x = (input.scroll_x as number) || 0;\n scroll_y = (input.scroll_y as number) || 0;\n }\n\n return {\n type: \"scroll\",\n x: x,\n y: y,\n scroll_x: scroll_x,\n scroll_y: scroll_y,\n ...input,\n };\n } else if (action === \"move\") {\n // Handle Anthropic's coordinate format\n const coordinates = input.coordinate as number[] | undefined;\n const x = coordinates ? coordinates[0] : (input.x as number) || 0;\n const y = coordinates ? coordinates[1] : (input.y as number) || 0;\n\n return {\n type: \"move\",\n x: x,\n y: y,\n ...input,\n };\n } else if (action === \"drag\" || action === \"left_click_drag\") {\n // Make sure path is properly formatted\n const path =\n (input.path as { x: number; y: number }[]) ||\n (input.coordinate\n ? [\n {\n x: (input.start_coordinate as number[])[0],\n y: (input.start_coordinate as number[])[1],\n },\n {\n x: (input.coordinate as number[])[0],\n y: (input.coordinate as number[])[1],\n },\n ]\n : []);\n\n return {\n type: \"drag\",\n path: path,\n ...input,\n };\n } else if (action === \"wait\") {\n return {\n type: \"wait\",\n ...input,\n };\n } else if (action === \"left_click\") {\n // Convert left_click to regular click\n const coordinates = input.coordinate as number[] | undefined;\n const x = coordinates ? coordinates[0] : (input.x as number) || 0;\n const y = coordinates ? coordinates[1] : (input.y as number) || 0;\n\n return {\n type: \"click\",\n x: x,\n y: y,\n button: \"left\",\n ...input,\n };\n } else {\n // For other computer actions, use the action type directly\n return {\n type: action,\n ...input,\n };\n }\n } else if (name === \"str_replace_editor\" || name === \"bash\") {\n // For editor or bash tools\n return {\n type: name,\n params: input,\n };\n } else if (this.tools && name in this.tools) {\n return null;\n }\n\n console.warn(`Unknown tool name: ${name}`);\n return null;\n } catch (error) {\n console.error(\"Error converting tool use to action:\", error);\n return null;\n }\n }\n\n async captureScreenshot(options?: {\n base64Image?: string;\n currentUrl?: string;\n }): Promise<string> {\n // Use provided options if available\n if (options?.base64Image) {\n return `data:image/png;base64,${options.base64Image}`;\n }\n\n // Use the screenshot provider if available\n if (this.screenshotProvider) {\n try {\n const base64Image = await this.screenshotProvider();\n return `data:image/png;base64,${base64Image}`;\n } catch (error) {\n console.error(\"Error capturing screenshot:\", error);\n throw error;\n }\n }\n\n throw new AgentScreenshotProviderError(\n \"`screenshotProvider` has not been set. \" +\n \"Please call `setScreenshotProvider()` with a valid function that returns a base64-encoded image\",\n );\n }\n}\n"]}
|
|
@@ -8,6 +8,8 @@ const openai_1 = __importDefault(require("openai"));
|
|
|
8
8
|
const AgentClient_js_1 = require("./AgentClient.js");
|
|
9
9
|
const sdkErrors_js_1 = require("../types/public/sdkErrors.js");
|
|
10
10
|
const cuaKeyMapping_js_1 = require("./utils/cuaKeyMapping.js");
|
|
11
|
+
const FlowLogger_js_1 = require("../flowlogger/FlowLogger.js");
|
|
12
|
+
const uuid_1 = require("uuid");
|
|
11
13
|
/**
|
|
12
14
|
* Client for FARA (Function-based Autonomous Research Agent) by Microsoft
|
|
13
15
|
* This implementation uses OpenAI-compatible API with XML-based tool calling
|
|
@@ -573,6 +575,12 @@ For each function call, return a json object with function name and arguments wi
|
|
|
573
575
|
message: `Making API call to FARA model with ${history.length} messages`,
|
|
574
576
|
level: 2,
|
|
575
577
|
});
|
|
578
|
+
const llmRequestId = (0, uuid_1.v7)();
|
|
579
|
+
FlowLogger_js_1.FlowLogger.logLlmRequest({
|
|
580
|
+
requestId: llmRequestId,
|
|
581
|
+
model: this.modelName,
|
|
582
|
+
prompt: (0, FlowLogger_js_1.extractLlmCuaPromptSummary)(history),
|
|
583
|
+
});
|
|
576
584
|
const startTime = Date.now();
|
|
577
585
|
let response;
|
|
578
586
|
try {
|
|
@@ -602,6 +610,13 @@ For each function call, return a json object with function name and arguments wi
|
|
|
602
610
|
completion_tokens: 0,
|
|
603
611
|
total_tokens: 0,
|
|
604
612
|
};
|
|
613
|
+
FlowLogger_js_1.FlowLogger.logLlmResponse({
|
|
614
|
+
requestId: llmRequestId,
|
|
615
|
+
model: this.modelName,
|
|
616
|
+
output: (0, FlowLogger_js_1.extractLlmCuaResponseSummary)([{ text: content }]),
|
|
617
|
+
inputTokens: usage.prompt_tokens,
|
|
618
|
+
outputTokens: usage.completion_tokens,
|
|
619
|
+
});
|
|
605
620
|
// Add assistant response to both histories
|
|
606
621
|
const assistantMsg = {
|
|
607
622
|
role: "assistant",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MicrosoftCUAClient.js","sourceRoot":"","sources":["../../../../../lib/v3/agent/MicrosoftCUAClient.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAS5B,qDAA+C;AAC/C,+DAA4E;AAC5E,+DAA8D;AA+B9D;;;GAGG;AACH,MAAa,kBAAmB,SAAQ,4BAAW;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,CAAC,sBAAsB;IAEzD,SAAS,GAAW,CAAC,CAAC;IACtB,WAAW,GAAW,CAAC,CAAC;IAC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ACF,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;AAj4BD,gDAi4BC","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,oDAA4B;AAS5B,qDAA+C;AAC/C,+DAA4E;AAC5E,+DAA8D;AAE9D,+DAIqC;AACrC,+BAAoC;AA8BpC;;;GAGG;AACH,MAAa,kBAAmB,SAAQ,4BAAW;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,CAAC,sBAAsB;IAEzD,SAAS,GAAW,CAAC,CAAC;IACtB,WAAW,GAAW,CAAC,CAAC;IACxB,KAAK,GAAa,EAAE,CAAC;IAE7B,qCAAqC;IACpB,oBAAoB,GAAG;QACtC,UAAU,EAAE,IAAI;QAChB,UAAU,EAAE,QAAQ;QACpB,UAAU,EAAE,EAAE;QACd,UAAU,EAAE,CAAC;KACd,CAAC;IAEF,qCAAqC;IAC7B,eAAe,GAAG,EAAE,KAA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AW,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;AAh5BD,gDAg5BC","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"]}
|