@browserbasehq/orca 3.2.0-preview.1 → 3.2.0-preview.2
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/dist/cjs/lib/utils.d.ts +1 -0
- package/dist/cjs/lib/utils.js +4 -0
- package/dist/cjs/lib/utils.js.map +1 -1
- package/dist/cjs/lib/v3/agent/AnthropicCUAClient.js +4 -6
- package/dist/cjs/lib/v3/agent/AnthropicCUAClient.js.map +1 -1
- package/dist/cjs/lib/v3/agent/GoogleCUAClient.js +4 -6
- package/dist/cjs/lib/v3/agent/GoogleCUAClient.js.map +1 -1
- package/dist/cjs/lib/v3/agent/OpenAICUAClient.js +4 -6
- package/dist/cjs/lib/v3/agent/OpenAICUAClient.js.map +1 -1
- package/dist/cjs/lib/v3/agent/prompts/agentSystemPrompt.d.ts +2 -0
- package/dist/cjs/lib/v3/agent/prompts/agentSystemPrompt.js +2 -2
- package/dist/cjs/lib/v3/agent/prompts/agentSystemPrompt.js.map +1 -1
- package/dist/cjs/lib/v3/agent/tools/{search.js → braveSearch.js} +1 -1
- package/dist/cjs/lib/v3/agent/tools/braveSearch.js.map +1 -0
- package/dist/cjs/lib/v3/agent/tools/browserbaseSearch.d.ts +13 -0
- package/dist/cjs/lib/v3/agent/tools/browserbaseSearch.js +70 -0
- package/dist/cjs/lib/v3/agent/tools/browserbaseSearch.js.map +1 -0
- package/dist/cjs/lib/v3/agent/tools/index.d.ts +14 -3
- package/dist/cjs/lib/v3/agent/tools/index.js +7 -3
- package/dist/cjs/lib/v3/agent/tools/index.js.map +1 -1
- package/dist/cjs/lib/v3/eventStore.d.ts +41 -0
- package/dist/cjs/lib/v3/eventStore.js +375 -0
- package/dist/cjs/lib/v3/eventStore.js.map +1 -0
- package/dist/cjs/lib/v3/flowLogger.d.ts +62 -103
- package/dist/cjs/lib/v3/flowLogger.js +362 -773
- package/dist/cjs/lib/v3/flowLogger.js.map +1 -1
- package/dist/cjs/lib/v3/handlers/handlerUtils/actHandlerUtils.js +21 -33
- package/dist/cjs/lib/v3/handlers/handlerUtils/actHandlerUtils.js.map +1 -1
- package/dist/cjs/lib/v3/handlers/v3AgentHandler.d.ts +0 -4
- package/dist/cjs/lib/v3/handlers/v3AgentHandler.js +14 -34
- package/dist/cjs/lib/v3/handlers/v3AgentHandler.js.map +1 -1
- package/dist/cjs/lib/v3/handlers/v3CuaAgentHandler.js +10 -12
- package/dist/cjs/lib/v3/handlers/v3CuaAgentHandler.js.map +1 -1
- package/dist/cjs/lib/v3/llm/aisdk.js +10 -16
- package/dist/cjs/lib/v3/llm/aisdk.js.map +1 -1
- package/dist/cjs/lib/v3/types/public/agent.d.ts +16 -2
- package/dist/cjs/lib/v3/types/public/agent.js.map +1 -1
- package/dist/cjs/lib/v3/types/public/options.d.ts +5 -0
- package/dist/cjs/lib/v3/types/public/options.js.map +1 -1
- package/dist/cjs/lib/v3/understudy/cdp.d.ts +3 -12
- package/dist/cjs/lib/v3/understudy/cdp.js +83 -10
- package/dist/cjs/lib/v3/understudy/cdp.js.map +1 -1
- package/dist/cjs/lib/v3/understudy/page.js +32 -17
- package/dist/cjs/lib/v3/understudy/page.js.map +1 -1
- package/dist/cjs/lib/v3/v3.d.ts +10 -0
- package/dist/cjs/lib/v3/v3.js +181 -157
- package/dist/cjs/lib/v3/v3.js.map +1 -1
- package/dist/cjs/tests/unit/public-api/public-types.test.js.map +1 -1
- package/dist/esm/lib/utils.d.ts +1 -0
- package/dist/esm/lib/utils.js +3 -0
- package/dist/esm/lib/utils.js.map +1 -1
- package/dist/esm/lib/v3/agent/AnthropicCUAClient.js +5 -7
- package/dist/esm/lib/v3/agent/AnthropicCUAClient.js.map +1 -1
- package/dist/esm/lib/v3/agent/GoogleCUAClient.js +5 -7
- package/dist/esm/lib/v3/agent/GoogleCUAClient.js.map +1 -1
- package/dist/esm/lib/v3/agent/OpenAICUAClient.js +5 -7
- package/dist/esm/lib/v3/agent/OpenAICUAClient.js.map +1 -1
- package/dist/esm/lib/v3/agent/prompts/agentSystemPrompt.d.ts +2 -0
- package/dist/esm/lib/v3/agent/prompts/agentSystemPrompt.js +2 -2
- package/dist/esm/lib/v3/agent/prompts/agentSystemPrompt.js.map +1 -1
- package/dist/esm/lib/v3/agent/tools/{search.js → braveSearch.js} +1 -1
- package/dist/esm/lib/v3/agent/tools/braveSearch.js.map +1 -0
- package/dist/esm/lib/v3/agent/tools/browserbaseSearch.d.ts +13 -0
- package/dist/esm/lib/v3/agent/tools/browserbaseSearch.js +66 -0
- package/dist/esm/lib/v3/agent/tools/browserbaseSearch.js.map +1 -0
- package/dist/esm/lib/v3/agent/tools/index.d.ts +14 -3
- package/dist/esm/lib/v3/agent/tools/index.js +7 -3
- package/dist/esm/lib/v3/agent/tools/index.js.map +1 -1
- package/dist/esm/lib/v3/eventStore.d.ts +41 -0
- package/dist/esm/lib/v3/eventStore.js +363 -0
- package/dist/esm/lib/v3/eventStore.js.map +1 -0
- package/dist/esm/lib/v3/flowLogger.d.ts +62 -103
- package/dist/esm/lib/v3/flowLogger.js +356 -762
- package/dist/esm/lib/v3/flowLogger.js.map +1 -1
- package/dist/esm/lib/v3/handlers/handlerUtils/actHandlerUtils.js +22 -34
- package/dist/esm/lib/v3/handlers/handlerUtils/actHandlerUtils.js.map +1 -1
- package/dist/esm/lib/v3/handlers/v3AgentHandler.d.ts +0 -4
- package/dist/esm/lib/v3/handlers/v3AgentHandler.js +16 -36
- package/dist/esm/lib/v3/handlers/v3AgentHandler.js.map +1 -1
- package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.js +11 -13
- package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.js.map +1 -1
- package/dist/esm/lib/v3/llm/aisdk.js +11 -17
- package/dist/esm/lib/v3/llm/aisdk.js.map +1 -1
- package/dist/esm/lib/v3/types/public/agent.d.ts +16 -2
- package/dist/esm/lib/v3/types/public/agent.js.map +1 -1
- package/dist/esm/lib/v3/types/public/options.d.ts +5 -0
- package/dist/esm/lib/v3/types/public/options.js.map +1 -1
- package/dist/esm/lib/v3/understudy/cdp.d.ts +3 -12
- package/dist/esm/lib/v3/understudy/cdp.js +83 -10
- package/dist/esm/lib/v3/understudy/cdp.js.map +1 -1
- package/dist/esm/lib/v3/understudy/page.js +33 -18
- package/dist/esm/lib/v3/understudy/page.js.map +1 -1
- package/dist/esm/lib/v3/v3.d.ts +10 -0
- package/dist/esm/lib/v3/v3.js +182 -158
- package/dist/esm/lib/v3/v3.js.map +1 -1
- package/dist/esm/tests/unit/public-api/public-types.test.js.map +1 -1
- package/package.json +1 -3
- package/dist/cjs/lib/v3/agent/tools/search.js.map +0 -1
- package/dist/cjs/tests/unit/rerender-missing-shadows.test.d.ts +0 -1
- package/dist/cjs/tests/unit/rerender-missing-shadows.test.js +0 -209
- package/dist/cjs/tests/unit/rerender-missing-shadows.test.js.map +0 -1
- package/dist/esm/lib/v3/agent/tools/search.js.map +0 -1
- package/dist/esm/tests/unit/rerender-missing-shadows.test.d.ts +0 -1
- package/dist/esm/tests/unit/rerender-missing-shadows.test.js +0 -207
- package/dist/esm/tests/unit/rerender-missing-shadows.test.js.map +0 -1
- /package/dist/cjs/lib/v3/agent/tools/{search.d.ts → braveSearch.d.ts} +0 -0
- /package/dist/esm/lib/v3/agent/tools/{search.d.ts → braveSearch.d.ts} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenAICUAClient.js","sourceRoot":"","sources":["../../../../../lib/v3/agent/OpenAICUAClient.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAe5B,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EACL,4BAA4B,EAC5B,oBAAoB,GACrB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,wBAAwB,GACzB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC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AK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,wCAAwC,EAAE,KAAK,CAAC,CAAC;YAC/D,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAC,OAGvB;QACC,oCAAoC;QACpC,IAAI,OAAO,EAAE,WAAW,EAAE,CAAC;YACzB,OAAO,yBAAyB,OAAO,CAAC,WAAW,EAAE,CAAC;QACxD,CAAC;QAED,2CAA2C;QAC3C,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC5B,IAAI,CAAC;gBACH,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,kBAAkB,EAAE,CAAC;gBACpD,OAAO,yBAAyB,WAAW,EAAE,CAAC;YAChD,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAC;gBACpD,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;QAED,MAAM,IAAI,4BAA4B,CACpC,yCAAyC;YACvC,iGAAiG,CACpG,CAAC;IACJ,CAAC;CACF","sourcesContent":["import OpenAI from \"openai\";\nimport { LogLine } from \"../types/public/logs.js\";\nimport {\n AgentAction,\n AgentResult,\n AgentType,\n AgentExecutionOptions,\n ResponseInputItem,\n ResponseItem,\n ComputerCallItem,\n FunctionCallItem,\n SafetyCheck,\n SafetyConfirmationHandler,\n} from \"../types/public/agent.js\";\nimport { ClientOptions } from \"../types/public/model.js\";\nimport { AgentClient } from \"./AgentClient.js\";\nimport {\n AgentScreenshotProviderError,\n StagehandClosedError,\n} from \"../types/public/sdkErrors.js\";\nimport { ToolSet } from \"ai\";\nimport {\n SessionFileLogger,\n formatCuaPromptPreview,\n formatCuaResponsePreview,\n} from \"../flowLogger.js\";\nimport { v7 as uuidv7 } from \"uuid\";\n\n/**\n * Client for OpenAI's Computer Use Assistant API\n * This implementation uses the official OpenAI Responses API for Computer Use\n */\nexport class OpenAICUAClient extends AgentClient {\n private apiKey: string;\n private organization?: string;\n private baseURL: string;\n private client: OpenAI;\n public lastResponseId?: 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 reasoningItems: Map<string, ResponseItem> = new Map();\n private environment: string = \"browser\"; // \"browser\", \"mac\", \"windows\", or \"ubuntu\"\n private tools?: ToolSet;\n private safetyConfirmationHandler?: SafetyConfirmationHandler;\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.OPENAI_API_KEY || \"\";\n this.baseURL = (clientOptions?.baseURL as string) || undefined;\n this.organization =\n (clientOptions?.organization as string) || process.env.OPENAI_ORG;\n\n // Get environment if specified\n if (\n clientOptions?.environment &&\n typeof clientOptions.environment === \"string\"\n ) {\n this.environment = clientOptions.environment;\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 OpenAI client\n this.client = new OpenAI(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 setSafetyConfirmationHandler(handler?: SafetyConfirmationHandler): void {\n this.safetyConfirmationHandler = handler;\n }\n\n /**\n * Execute a task with the OpenAI 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 this.reasoningItems.clear(); // Clear any previous reasoning items\n\n // Start with the initial instruction\n let inputItems = this.createInitialInputItems(instruction);\n let previousResponseId: string | undefined = undefined;\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 logger({\n category: \"agent\",\n message: `Executing step ${currentStep + 1}/${maxSteps}`,\n level: 1,\n });\n\n const result = await this.executeStep(\n inputItems,\n previousResponseId,\n logger,\n );\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 // Store the previous response ID for the next request\n previousResponseId = result.responseId;\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 // 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 /**\n * Execute a single step of the agent\n * This coordinates the flow: Request → Get Action → Execute Action\n */\n async executeStep(\n inputItems: ResponseInputItem[],\n previousResponseId: string | undefined,\n logger: (message: LogLine) => void,\n ): Promise<{\n actions: AgentAction[];\n message: string;\n completed: boolean;\n nextInputItems: ResponseInputItem[];\n responseId: string;\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, previousResponseId);\n const output = result.output;\n const responseId = result.responseId;\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 // Add any reasoning items to our map\n for (const item of output) {\n if (item.type === \"reasoning\") {\n this.reasoningItems.set(item.id, item);\n logger({\n category: \"agent\",\n message: `Reasoning: ${String(item.content || \"\")}`,\n level: 1,\n });\n }\n }\n\n // Extract actions from the output\n const stepActions: AgentAction[] = [];\n for (const item of output) {\n if (item.type === \"computer_call\" && this.isComputerCallItem(item)) {\n logger({\n category: \"agent\",\n message: `Found computer_call: ${item.action.type}, call_id: ${item.call_id}`,\n level: 2,\n });\n const action = this.convertComputerCallToAction(item);\n if (action) {\n stepActions.push(action);\n logger({\n category: \"agent\",\n message: `Converted computer_call to action: ${action.type}`,\n level: 2,\n });\n }\n } else if (\n item.type === \"function_call\" &&\n this.isFunctionCallItem(item)\n ) {\n logger({\n category: \"agent\",\n message: `Found function_call: ${item.name}, call_id: ${item.call_id}`,\n level: 2,\n });\n const action = this.convertFunctionCallToAction(item);\n if (action) {\n stepActions.push(action);\n logger({\n category: \"agent\",\n message: `Converted function_call to action: ${action.type}`,\n level: 2,\n });\n }\n }\n }\n\n // Extract message text\n let message = \"\";\n for (const item of output) {\n if (item.type === \"message\") {\n logger({\n category: \"agent\",\n message: `Found message block`,\n level: 2,\n });\n if (item.content && Array.isArray(item.content)) {\n for (const content of item.content) {\n if (content.type === \"output_text\" && content.text) {\n message += content.text + \"\\n\";\n logger({\n category: \"agent\",\n message: `Message text: ${String(content.text || \"\")}`,\n level: 1,\n });\n }\n }\n }\n }\n }\n\n // Take actions and get results\n const nextInputItems = await this.takeAction(output, logger);\n\n // Check if completed\n const completed =\n output.length === 0 ||\n output.every(\n (item) => item.type === \"message\" || item.type === \"reasoning\",\n );\n\n return {\n actions: stepActions,\n message: message.trim(),\n completed,\n nextInputItems,\n responseId,\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 isComputerCallItem(item: ResponseItem): item is ComputerCallItem {\n return (\n item.type === \"computer_call\" &&\n \"call_id\" in item &&\n \"action\" in item &&\n typeof item.action === \"object\"\n );\n }\n\n private async handleSafetyConfirmation(\n pendingSafetyChecks: SafetyCheck[],\n logger: (message: LogLine) => void,\n ): Promise<SafetyCheck[] | undefined> {\n if (this.safetyConfirmationHandler) {\n logger({\n category: \"agent\",\n message: `Requesting safety confirmation for ${pendingSafetyChecks.length} check(s): ${pendingSafetyChecks.map((c) => c.code).join(\", \")}`,\n level: 1,\n });\n\n const response =\n await this.safetyConfirmationHandler(pendingSafetyChecks);\n\n if (response.acknowledged) {\n logger({\n category: \"agent\",\n message: `Safety checks acknowledged by user`,\n level: 1,\n });\n return pendingSafetyChecks;\n } else {\n logger({\n category: \"agent\",\n message: `Safety checks rejected by user`,\n level: 1,\n });\n return undefined;\n }\n }\n\n logger({\n category: \"agent\",\n message: `Auto-acknowledging ${pendingSafetyChecks.length} safety check(s)`,\n level: 2,\n });\n return pendingSafetyChecks;\n }\n\n private isFunctionCallItem(item: ResponseItem): item is FunctionCallItem {\n return (\n item.type === \"function_call\" &&\n \"call_id\" in item &&\n \"name\" in item &&\n \"arguments\" in item\n );\n }\n\n private createInitialInputItems(instruction: string): ResponseInputItem[] {\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 previousResponseId?: string,\n ): Promise<{\n output: ResponseItem[];\n responseId: string;\n usage: Record<string, number>;\n }> {\n try {\n // Create the request parameters\n const requestParams: Record<string, unknown> = {\n model: this.modelName,\n tools: [\n {\n type: \"computer_use_preview\",\n display_width: this.currentViewport.width,\n display_height: this.currentViewport.height,\n environment: this.environment,\n },\n ],\n input: inputItems,\n truncation: \"auto\",\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 type: \"function\" as const,\n name,\n function: {\n name,\n description: tool.description,\n parameters: tool.inputSchema,\n },\n }));\n\n requestParams.tools = [\n ...(requestParams.tools as Record<string, unknown>[]),\n ...customTools,\n ];\n }\n\n // Add previous_response_id if available\n if (previousResponseId) {\n requestParams.previous_response_id = previousResponseId;\n }\n\n // Log LLM request\n const llmRequestId = uuidv7();\n SessionFileLogger.logLlmRequest({\n requestId: llmRequestId,\n model: this.modelName,\n operation: \"CUA.getAction\",\n prompt: formatCuaPromptPreview(inputItems),\n });\n\n const startTime = Date.now();\n // Create the response using the OpenAI Responses API\n // @ts-expect-error - Force type to match what the OpenAI SDK expects\n const response = await this.client.responses.create(requestParams);\n const endTime = Date.now();\n const elapsedMs = endTime - startTime;\n\n // Extract only the input_tokens and output_tokens\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 SessionFileLogger.logLlmResponse({\n requestId: llmRequestId,\n model: this.modelName,\n operation: \"CUA.getAction\",\n output: formatCuaResponsePreview(response.output),\n inputTokens: response.usage.input_tokens,\n outputTokens: response.usage.output_tokens,\n });\n\n // Store the response ID for future use\n this.lastResponseId = response.id;\n\n // Return the output and response ID\n return {\n output: response.output as unknown as ResponseItem[],\n responseId: response.id,\n usage,\n };\n } catch (error) {\n console.error(\"Error getting action from OpenAI:\", error);\n throw error;\n }\n }\n\n async takeAction(\n output: ResponseItem[],\n logger: (message: LogLine) => void,\n ): Promise<ResponseInputItem[]> {\n const nextInputItems: ResponseInputItem[] = [];\n\n // Process each output item\n for (const item of output) {\n if (item.type === \"computer_call\" && this.isComputerCallItem(item)) {\n // Handle computer calls\n try {\n const action = this.convertComputerCallToAction(item);\n\n if (action && this.actionHandler) {\n logger({\n category: \"agent\",\n message: `Executing computer action: ${action.type}`,\n level: 1,\n });\n await this.actionHandler(action);\n }\n\n // Capture a screenshot\n const screenshot = await this.captureScreenshot();\n\n // Create a computer_call_output for the next request\n const outputItem = {\n type: \"computer_call_output\" as const,\n call_id: item.call_id,\n output: {\n type: \"input_image\" as const,\n image_url: screenshot,\n },\n } as ResponseInputItem;\n\n logger({\n category: \"agent\",\n message: `Added computer_call_output for call_id: ${item.call_id}`,\n level: 2,\n });\n\n // Add current URL if available\n if (this.currentUrl) {\n const computerCallOutput = outputItem as {\n type: \"computer_call_output\";\n call_id: string;\n output: {\n type: \"input_image\";\n image_url: string;\n current_url?: string;\n };\n acknowledged_safety_checks?: SafetyCheck[];\n };\n computerCallOutput.output.current_url = this.currentUrl;\n }\n\n if (\n item.pending_safety_checks &&\n item.pending_safety_checks.length > 0\n ) {\n const acknowledgedChecks = await this.handleSafetyConfirmation(\n item.pending_safety_checks,\n logger,\n );\n\n if (acknowledgedChecks) {\n const computerCallOutput = outputItem as {\n type: \"computer_call_output\";\n call_id: string;\n output: {\n type: \"input_image\";\n image_url: string;\n };\n acknowledged_safety_checks?: SafetyCheck[];\n };\n computerCallOutput.acknowledged_safety_checks =\n acknowledgedChecks;\n }\n }\n\n nextInputItems.push(outputItem);\n } catch (error) {\n if (error instanceof StagehandClosedError) {\n throw error;\n }\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n\n logger({\n category: \"agent\",\n message: `Error executing computer call: ${errorMessage}`,\n level: 0,\n });\n\n try {\n // Capture a screenshot even on error\n const screenshot = await this.captureScreenshot();\n\n const errorOutputItem = {\n type: \"computer_call_output\" as const,\n call_id: item.call_id,\n output: {\n type: \"input_image\" as const,\n image_url: screenshot,\n error: errorMessage,\n },\n } as ResponseInputItem;\n\n // Add current URL if available\n if (this.currentUrl) {\n const computerCallOutput = errorOutputItem as {\n type: \"computer_call_output\";\n call_id: string;\n output: {\n type: \"input_image\";\n image_url: string;\n current_url?: string;\n };\n acknowledged_safety_checks?: SafetyCheck[];\n };\n computerCallOutput.output.current_url = this.currentUrl;\n }\n\n if (\n item.pending_safety_checks &&\n item.pending_safety_checks.length > 0\n ) {\n const acknowledgedChecks = await this.handleSafetyConfirmation(\n item.pending_safety_checks,\n logger,\n );\n\n if (acknowledgedChecks) {\n const computerCallOutput = errorOutputItem as {\n type: \"computer_call_output\";\n call_id: string;\n output: {\n type: \"input_image\";\n image_url: string;\n };\n acknowledged_safety_checks?: SafetyCheck[];\n };\n computerCallOutput.acknowledged_safety_checks =\n acknowledgedChecks;\n }\n }\n\n nextInputItems.push(errorOutputItem);\n } catch (screenshotError) {\n if (screenshotError instanceof StagehandClosedError) {\n throw screenshotError;\n }\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 // For error cases without a screenshot, we need to use a string output\n nextInputItems.push({\n type: \"computer_call_output\",\n call_id: item.call_id,\n output: `Error: ${errorMessage}`,\n } as ResponseInputItem);\n }\n }\n } else if (\n item.type === \"function_call\" &&\n this.isFunctionCallItem(item)\n ) {\n // Handle function calls (tool calls)\n try {\n const action = this.convertFunctionCallToAction(item);\n\n if (action && this.actionHandler) {\n await this.actionHandler(action);\n }\n\n // Execute the tool if available\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 const args = JSON.parse(item.arguments);\n\n logger({\n category: \"agent\",\n message: `Executing tool call: ${item.name} with args: ${item.arguments}`,\n level: 1,\n });\n\n const result = await tool.execute(args, {\n toolCallId: item.call_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 // Create a function_call_output for the next request\n const outputItem: ResponseInputItem = {\n type: \"function_call_output\",\n call_id: item.call_id,\n output: toolResult,\n };\n\n nextInputItems.push(outputItem);\n } catch (error) {\n if (error instanceof StagehandClosedError) {\n throw error;\n }\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n\n logger({\n category: \"agent\",\n message: `Error executing function call: ${errorMessage}`,\n level: 0,\n });\n\n // Send error result back\n const errorOutputItem: ResponseInputItem = {\n type: \"function_call_output\",\n call_id: item.call_id,\n output: `Error: ${errorMessage}`,\n };\n\n nextInputItems.push(errorOutputItem);\n }\n }\n }\n\n return nextInputItems;\n }\n\n private convertComputerCallToAction(\n call: ComputerCallItem,\n ): AgentAction | null {\n const { action } = call;\n\n // Instead of wrapping the action in a params object, spread the action properties directly\n // This ensures properties like x, y, button, etc. are directly accessible on the AgentAction\n return {\n type: action.type as string,\n ...action, // Spread all properties from the action\n };\n }\n\n private convertFunctionCallToAction(\n call: FunctionCallItem,\n ): AgentAction | null {\n try {\n const args = JSON.parse(call.arguments);\n\n return {\n type: call.name,\n params: args,\n };\n } catch (error) {\n console.error(\"Error parsing function call arguments:\", 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":"OpenAICUAClient.js","sourceRoot":"","sources":["../../../../../lib/v3/agent/OpenAICUAClient.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAe5B,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EACL,4BAA4B,EAC5B,oBAAoB,GACrB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EACL,UAAU,EACV,0BAA0B,EAC1B,4BAA4B,GAC7B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAEpC;;;GAGG;AACH,MAAM,OAAO,eAAgB,SAAQ,WAAW;IACtC,MAAM,CAAS;IACf,YAAY,CAAU;IACtB,OAAO,CAAS;IAChB,MAAM,CAAS;IAChB,cAAc,CAAU;IACvB,eAAe,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;IAC/C,UAAU,CAAU;IACpB,kBAAkB,CAAyB;IAC3C,aAAa,CAA0C;IACvD,cAAc,GAA8B,IAAI,GAAG,EAAE,CAAC;IACtD,WAAW,GAAW,SAAS,CAAC,CAAC,2CAA2C;IAC5E,KAAK,CAAW;IAChB,yBAAyB,CAA6B;IAE9D,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,GAAG,CAAC,cAAc,IAAI,EAAE,CAAC;QACxE,IAAI,CAAC,OAAO,GAAI,aAAa,EAAE,OAAkB,IAAI,SAAS,CAAC;QAC/D,IAAI,CAAC,YAAY;YACd,aAAa,EAAE,YAAu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,EAAE,GAAG,IAAI,CAAC;QAExB,2FAA2F;QAC3F,6FAA6F;QAC7F,OAAO;YACL,IAAI,EAAE,MAAM,CAAC,IAAc;YAC3B,GAAG,MAAM,EAAE,wCAAwC;SACpD,CAAC;IACJ,CAAC;IAEO,2BAA2B,CACjC,IAAsB;QAEtB,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAExC,OAAO;gBACL,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,MAAM,EAAE,IAAI;aACb,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,wCAAwC,EAAE,KAAK,CAAC,CAAC;YAC/D,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAC,OAGvB;QACC,oCAAoC;QACpC,IAAI,OAAO,EAAE,WAAW,EAAE,CAAC;YACzB,OAAO,yBAAyB,OAAO,CAAC,WAAW,EAAE,CAAC;QACxD,CAAC;QAED,2CAA2C;QAC3C,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC5B,IAAI,CAAC;gBACH,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,kBAAkB,EAAE,CAAC;gBACpD,OAAO,yBAAyB,WAAW,EAAE,CAAC;YAChD,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAC;gBACpD,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;QAED,MAAM,IAAI,4BAA4B,CACpC,yCAAyC;YACvC,iGAAiG,CACpG,CAAC;IACJ,CAAC;CACF","sourcesContent":["import OpenAI from \"openai\";\nimport { LogLine } from \"../types/public/logs.js\";\nimport {\n AgentAction,\n AgentResult,\n AgentType,\n AgentExecutionOptions,\n ResponseInputItem,\n ResponseItem,\n ComputerCallItem,\n FunctionCallItem,\n SafetyCheck,\n SafetyConfirmationHandler,\n} from \"../types/public/agent.js\";\nimport { ClientOptions } from \"../types/public/model.js\";\nimport { AgentClient } from \"./AgentClient.js\";\nimport {\n AgentScreenshotProviderError,\n StagehandClosedError,\n} from \"../types/public/sdkErrors.js\";\nimport { ToolSet } from \"ai\";\nimport {\n FlowLogger,\n extractLlmCuaPromptSummary,\n extractLlmCuaResponseSummary,\n} from \"../flowLogger.js\";\nimport { v7 as uuidv7 } from \"uuid\";\n\n/**\n * Client for OpenAI's Computer Use Assistant API\n * This implementation uses the official OpenAI Responses API for Computer Use\n */\nexport class OpenAICUAClient extends AgentClient {\n private apiKey: string;\n private organization?: string;\n private baseURL: string;\n private client: OpenAI;\n public lastResponseId?: 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 reasoningItems: Map<string, ResponseItem> = new Map();\n private environment: string = \"browser\"; // \"browser\", \"mac\", \"windows\", or \"ubuntu\"\n private tools?: ToolSet;\n private safetyConfirmationHandler?: SafetyConfirmationHandler;\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.OPENAI_API_KEY || \"\";\n this.baseURL = (clientOptions?.baseURL as string) || undefined;\n this.organization =\n (clientOptions?.organization as string) || process.env.OPENAI_ORG;\n\n // Get environment if specified\n if (\n clientOptions?.environment &&\n typeof clientOptions.environment === \"string\"\n ) {\n this.environment = clientOptions.environment;\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 OpenAI client\n this.client = new OpenAI(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 setSafetyConfirmationHandler(handler?: SafetyConfirmationHandler): void {\n this.safetyConfirmationHandler = handler;\n }\n\n /**\n * Execute a task with the OpenAI 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 this.reasoningItems.clear(); // Clear any previous reasoning items\n\n // Start with the initial instruction\n let inputItems = this.createInitialInputItems(instruction);\n let previousResponseId: string | undefined = undefined;\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 logger({\n category: \"agent\",\n message: `Executing step ${currentStep + 1}/${maxSteps}`,\n level: 1,\n });\n\n const result = await this.executeStep(\n inputItems,\n previousResponseId,\n logger,\n );\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 // Store the previous response ID for the next request\n previousResponseId = result.responseId;\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 // 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 /**\n * Execute a single step of the agent\n * This coordinates the flow: Request → Get Action → Execute Action\n */\n async executeStep(\n inputItems: ResponseInputItem[],\n previousResponseId: string | undefined,\n logger: (message: LogLine) => void,\n ): Promise<{\n actions: AgentAction[];\n message: string;\n completed: boolean;\n nextInputItems: ResponseInputItem[];\n responseId: string;\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, previousResponseId);\n const output = result.output;\n const responseId = result.responseId;\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 // Add any reasoning items to our map\n for (const item of output) {\n if (item.type === \"reasoning\") {\n this.reasoningItems.set(item.id, item);\n logger({\n category: \"agent\",\n message: `Reasoning: ${String(item.content || \"\")}`,\n level: 1,\n });\n }\n }\n\n // Extract actions from the output\n const stepActions: AgentAction[] = [];\n for (const item of output) {\n if (item.type === \"computer_call\" && this.isComputerCallItem(item)) {\n logger({\n category: \"agent\",\n message: `Found computer_call: ${item.action.type}, call_id: ${item.call_id}`,\n level: 2,\n });\n const action = this.convertComputerCallToAction(item);\n if (action) {\n stepActions.push(action);\n logger({\n category: \"agent\",\n message: `Converted computer_call to action: ${action.type}`,\n level: 2,\n });\n }\n } else if (\n item.type === \"function_call\" &&\n this.isFunctionCallItem(item)\n ) {\n logger({\n category: \"agent\",\n message: `Found function_call: ${item.name}, call_id: ${item.call_id}`,\n level: 2,\n });\n const action = this.convertFunctionCallToAction(item);\n if (action) {\n stepActions.push(action);\n logger({\n category: \"agent\",\n message: `Converted function_call to action: ${action.type}`,\n level: 2,\n });\n }\n }\n }\n\n // Extract message text\n let message = \"\";\n for (const item of output) {\n if (item.type === \"message\") {\n logger({\n category: \"agent\",\n message: `Found message block`,\n level: 2,\n });\n if (item.content && Array.isArray(item.content)) {\n for (const content of item.content) {\n if (content.type === \"output_text\" && content.text) {\n message += content.text + \"\\n\";\n logger({\n category: \"agent\",\n message: `Message text: ${String(content.text || \"\")}`,\n level: 1,\n });\n }\n }\n }\n }\n }\n\n // Take actions and get results\n const nextInputItems = await this.takeAction(output, logger);\n\n // Check if completed\n const completed =\n output.length === 0 ||\n output.every(\n (item) => item.type === \"message\" || item.type === \"reasoning\",\n );\n\n return {\n actions: stepActions,\n message: message.trim(),\n completed,\n nextInputItems,\n responseId,\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 isComputerCallItem(item: ResponseItem): item is ComputerCallItem {\n return (\n item.type === \"computer_call\" &&\n \"call_id\" in item &&\n \"action\" in item &&\n typeof item.action === \"object\"\n );\n }\n\n private async handleSafetyConfirmation(\n pendingSafetyChecks: SafetyCheck[],\n logger: (message: LogLine) => void,\n ): Promise<SafetyCheck[] | undefined> {\n if (this.safetyConfirmationHandler) {\n logger({\n category: \"agent\",\n message: `Requesting safety confirmation for ${pendingSafetyChecks.length} check(s): ${pendingSafetyChecks.map((c) => c.code).join(\", \")}`,\n level: 1,\n });\n\n const response =\n await this.safetyConfirmationHandler(pendingSafetyChecks);\n\n if (response.acknowledged) {\n logger({\n category: \"agent\",\n message: `Safety checks acknowledged by user`,\n level: 1,\n });\n return pendingSafetyChecks;\n } else {\n logger({\n category: \"agent\",\n message: `Safety checks rejected by user`,\n level: 1,\n });\n return undefined;\n }\n }\n\n logger({\n category: \"agent\",\n message: `Auto-acknowledging ${pendingSafetyChecks.length} safety check(s)`,\n level: 2,\n });\n return pendingSafetyChecks;\n }\n\n private isFunctionCallItem(item: ResponseItem): item is FunctionCallItem {\n return (\n item.type === \"function_call\" &&\n \"call_id\" in item &&\n \"name\" in item &&\n \"arguments\" in item\n );\n }\n\n private createInitialInputItems(instruction: string): ResponseInputItem[] {\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 previousResponseId?: string,\n ): Promise<{\n output: ResponseItem[];\n responseId: string;\n usage: Record<string, number>;\n }> {\n try {\n // Create the request parameters\n const requestParams: Record<string, unknown> = {\n model: this.modelName,\n tools: [\n {\n type: \"computer_use_preview\",\n display_width: this.currentViewport.width,\n display_height: this.currentViewport.height,\n environment: this.environment,\n },\n ],\n input: inputItems,\n truncation: \"auto\",\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 type: \"function\" as const,\n name,\n function: {\n name,\n description: tool.description,\n parameters: tool.inputSchema,\n },\n }));\n\n requestParams.tools = [\n ...(requestParams.tools as Record<string, unknown>[]),\n ...customTools,\n ];\n }\n\n // Add previous_response_id if available\n if (previousResponseId) {\n requestParams.previous_response_id = previousResponseId;\n }\n\n // Log LLM request\n const llmRequestId = uuidv7();\n FlowLogger.logLlmRequest({\n requestId: llmRequestId,\n model: this.modelName,\n prompt: extractLlmCuaPromptSummary(inputItems),\n });\n\n const startTime = Date.now();\n // Create the response using the OpenAI Responses API\n // @ts-expect-error - Force type to match what the OpenAI SDK expects\n const response = await this.client.responses.create(requestParams);\n const endTime = Date.now();\n const elapsedMs = endTime - startTime;\n\n // Extract only the input_tokens and output_tokens\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.output),\n inputTokens: response.usage.input_tokens,\n outputTokens: response.usage.output_tokens,\n });\n\n // Store the response ID for future use\n this.lastResponseId = response.id;\n\n // Return the output and response ID\n return {\n output: response.output as unknown as ResponseItem[],\n responseId: response.id,\n usage,\n };\n } catch (error) {\n console.error(\"Error getting action from OpenAI:\", error);\n throw error;\n }\n }\n\n async takeAction(\n output: ResponseItem[],\n logger: (message: LogLine) => void,\n ): Promise<ResponseInputItem[]> {\n const nextInputItems: ResponseInputItem[] = [];\n\n // Process each output item\n for (const item of output) {\n if (item.type === \"computer_call\" && this.isComputerCallItem(item)) {\n // Handle computer calls\n try {\n const action = this.convertComputerCallToAction(item);\n\n if (action && this.actionHandler) {\n logger({\n category: \"agent\",\n message: `Executing computer action: ${action.type}`,\n level: 1,\n });\n await this.actionHandler(action);\n }\n\n // Capture a screenshot\n const screenshot = await this.captureScreenshot();\n\n // Create a computer_call_output for the next request\n const outputItem = {\n type: \"computer_call_output\" as const,\n call_id: item.call_id,\n output: {\n type: \"input_image\" as const,\n image_url: screenshot,\n },\n } as ResponseInputItem;\n\n logger({\n category: \"agent\",\n message: `Added computer_call_output for call_id: ${item.call_id}`,\n level: 2,\n });\n\n // Add current URL if available\n if (this.currentUrl) {\n const computerCallOutput = outputItem as {\n type: \"computer_call_output\";\n call_id: string;\n output: {\n type: \"input_image\";\n image_url: string;\n current_url?: string;\n };\n acknowledged_safety_checks?: SafetyCheck[];\n };\n computerCallOutput.output.current_url = this.currentUrl;\n }\n\n if (\n item.pending_safety_checks &&\n item.pending_safety_checks.length > 0\n ) {\n const acknowledgedChecks = await this.handleSafetyConfirmation(\n item.pending_safety_checks,\n logger,\n );\n\n if (acknowledgedChecks) {\n const computerCallOutput = outputItem as {\n type: \"computer_call_output\";\n call_id: string;\n output: {\n type: \"input_image\";\n image_url: string;\n };\n acknowledged_safety_checks?: SafetyCheck[];\n };\n computerCallOutput.acknowledged_safety_checks =\n acknowledgedChecks;\n }\n }\n\n nextInputItems.push(outputItem);\n } catch (error) {\n if (error instanceof StagehandClosedError) {\n throw error;\n }\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n\n logger({\n category: \"agent\",\n message: `Error executing computer call: ${errorMessage}`,\n level: 0,\n });\n\n try {\n // Capture a screenshot even on error\n const screenshot = await this.captureScreenshot();\n\n const errorOutputItem = {\n type: \"computer_call_output\" as const,\n call_id: item.call_id,\n output: {\n type: \"input_image\" as const,\n image_url: screenshot,\n error: errorMessage,\n },\n } as ResponseInputItem;\n\n // Add current URL if available\n if (this.currentUrl) {\n const computerCallOutput = errorOutputItem as {\n type: \"computer_call_output\";\n call_id: string;\n output: {\n type: \"input_image\";\n image_url: string;\n current_url?: string;\n };\n acknowledged_safety_checks?: SafetyCheck[];\n };\n computerCallOutput.output.current_url = this.currentUrl;\n }\n\n if (\n item.pending_safety_checks &&\n item.pending_safety_checks.length > 0\n ) {\n const acknowledgedChecks = await this.handleSafetyConfirmation(\n item.pending_safety_checks,\n logger,\n );\n\n if (acknowledgedChecks) {\n const computerCallOutput = errorOutputItem as {\n type: \"computer_call_output\";\n call_id: string;\n output: {\n type: \"input_image\";\n image_url: string;\n };\n acknowledged_safety_checks?: SafetyCheck[];\n };\n computerCallOutput.acknowledged_safety_checks =\n acknowledgedChecks;\n }\n }\n\n nextInputItems.push(errorOutputItem);\n } catch (screenshotError) {\n if (screenshotError instanceof StagehandClosedError) {\n throw screenshotError;\n }\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 // For error cases without a screenshot, we need to use a string output\n nextInputItems.push({\n type: \"computer_call_output\",\n call_id: item.call_id,\n output: `Error: ${errorMessage}`,\n } as ResponseInputItem);\n }\n }\n } else if (\n item.type === \"function_call\" &&\n this.isFunctionCallItem(item)\n ) {\n // Handle function calls (tool calls)\n try {\n const action = this.convertFunctionCallToAction(item);\n\n if (action && this.actionHandler) {\n await this.actionHandler(action);\n }\n\n // Execute the tool if available\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 const args = JSON.parse(item.arguments);\n\n logger({\n category: \"agent\",\n message: `Executing tool call: ${item.name} with args: ${item.arguments}`,\n level: 1,\n });\n\n const result = await tool.execute(args, {\n toolCallId: item.call_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 // Create a function_call_output for the next request\n const outputItem: ResponseInputItem = {\n type: \"function_call_output\",\n call_id: item.call_id,\n output: toolResult,\n };\n\n nextInputItems.push(outputItem);\n } catch (error) {\n if (error instanceof StagehandClosedError) {\n throw error;\n }\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n\n logger({\n category: \"agent\",\n message: `Error executing function call: ${errorMessage}`,\n level: 0,\n });\n\n // Send error result back\n const errorOutputItem: ResponseInputItem = {\n type: \"function_call_output\",\n call_id: item.call_id,\n output: `Error: ${errorMessage}`,\n };\n\n nextInputItems.push(errorOutputItem);\n }\n }\n }\n\n return nextInputItems;\n }\n\n private convertComputerCallToAction(\n call: ComputerCallItem,\n ): AgentAction | null {\n const { action } = call;\n\n // Instead of wrapping the action in a params object, spread the action properties directly\n // This ensures properties like x, y, button, etc. are directly accessible on the AgentAction\n return {\n type: action.type as string,\n ...action, // Spread all properties from the action\n };\n }\n\n private convertFunctionCallToAction(\n call: FunctionCallItem,\n ): AgentAction | null {\n try {\n const args = JSON.parse(call.arguments);\n\n return {\n type: call.name,\n params: args,\n };\n } catch (error) {\n console.error(\"Error parsing function call arguments:\", 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"]}
|
|
@@ -10,5 +10,7 @@ export interface AgentSystemPromptOptions {
|
|
|
10
10
|
excludeTools?: string[];
|
|
11
11
|
/** Variables available to the agent for use in act/type tools */
|
|
12
12
|
variables?: Variables;
|
|
13
|
+
/** Whether the search tool is enabled for this execution */
|
|
14
|
+
useSearch?: boolean;
|
|
13
15
|
}
|
|
14
16
|
export declare function buildAgentSystemPrompt(options: AgentSystemPromptOptions): string;
|
|
@@ -71,12 +71,12 @@ function buildToolsSection(isHybridMode, hasSearch, excludeTools) {
|
|
|
71
71
|
return `<tools>\n${toolLines}\n </tools>`;
|
|
72
72
|
}
|
|
73
73
|
export function buildAgentSystemPrompt(options) {
|
|
74
|
-
const { url, executionInstruction, mode, systemInstructions, isBrowserbase = false, excludeTools, variables, } = options;
|
|
74
|
+
const { url, executionInstruction, mode, systemInstructions, isBrowserbase = false, excludeTools, variables, useSearch = false, } = options;
|
|
75
75
|
const localeDate = new Date().toLocaleDateString();
|
|
76
76
|
const isoDate = new Date().toISOString();
|
|
77
77
|
const cdata = (text) => `<![CDATA[${text}]]>`;
|
|
78
78
|
const isHybridMode = mode === "hybrid";
|
|
79
|
-
const hasSearch = Boolean(process.env.BRAVE_API_KEY);
|
|
79
|
+
const hasSearch = useSearch || Boolean(process.env.BRAVE_API_KEY);
|
|
80
80
|
// Tools section differs based on mode and excluded tools
|
|
81
81
|
const toolsSection = buildToolsSection(isHybridMode, hasSearch, excludeTools);
|
|
82
82
|
// Strategy differs based on mode
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agentSystemPrompt.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/prompts/agentSystemPrompt.ts"],"names":[],"mappings":"AA0BA,SAAS,iBAAiB,CACxB,YAAqB,EACrB,SAAkB,EAClB,YAAuB;IAEvB,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC;IAE/C,MAAM,WAAW,GAAqB;QACpC;YACE,IAAI,EAAE,YAAY;YAClB,WAAW,EAAE,4DAA4D;SAC1E;QACD;YACE,IAAI,EAAE,UAAU;YAChB,WAAW,EACT,+DAA+D;SAClE;QACD;YACE,IAAI,EAAE,OAAO;YACb,WAAW,EACT,qFAAqF;SACxF;QACD;YACE,IAAI,EAAE,MAAM;YACZ,WAAW,EACT,2FAA2F;SAC9F;QACD;YACE,IAAI,EAAE,KAAK;YACX,WAAW,EACT,0LAA0L;SAC7L;QACD,EAAE,IAAI,EAAE,aAAa,EAAE,WAAW,EAAE,0BAA0B,EAAE;QAChE,EAAE,IAAI,EAAE,cAAc,EAAE,WAAW,EAAE,8BAA8B,EAAE;QACrE,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,sBAAsB,EAAE;QACrD;YACE,IAAI,EAAE,gBAAgB;YACtB,WAAW,EAAE,mCAAmC;SACjD;QACD,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE;QACtD,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,yBAAyB,EAAE;QAC3D,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,mBAAmB,EAAE;QAClD,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,2BAA2B,EAAE;QAC1D,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EA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BAAyB;;;MAGvB,SAAS,CAAC,CAAC,CAAC,mFAAmF,CAAC,CAAC,CAAC,EAAE;;IAEtG,YAAY;;MAEV,eAAe;MACf,mBAAmB;;IAErB,iBAAiB;IACjB,gBAAgB;;;;;;;;UAQV,CAAC;AACX,CAAC","sourcesContent":["import type { AgentToolMode, Variables } from \"../../types/public/agent.js\";\n\nexport interface AgentSystemPromptOptions {\n url: string;\n executionInstruction: string;\n mode: AgentToolMode;\n systemInstructions?: string;\n /** Whether running on Browserbase (enables captcha solver messaging) */\n isBrowserbase?: boolean;\n /** Tools to exclude from the system prompt */\n excludeTools?: string[];\n /** Variables available to the agent for use in act/type tools */\n variables?: Variables;\n}\n\n/**\n * Builds the system prompt for the agent based on the tool mode.\n *\n * @param options - The prompt configuration options\n * @returns The formatted system prompt string\n */\ninterface ToolDefinition {\n name: string;\n description: string;\n}\n\nfunction buildToolsSection(\n isHybridMode: boolean,\n hasSearch: boolean,\n excludeTools?: string[],\n): string {\n const excludeSet = new Set(excludeTools ?? []);\n\n const hybridTools: ToolDefinition[] = [\n {\n name: \"screenshot\",\n description: \"Take a compressed JPEG screenshot for quick visual context\",\n },\n {\n name: \"ariaTree\",\n description:\n \"Get an accessibility (ARIA) hybrid tree for full page context\",\n },\n {\n name: \"click\",\n description:\n \"Click on an element (PREFERRED - more reliable when element is visible in viewport)\",\n },\n {\n name: \"type\",\n description:\n \"Type text into an element (PREFERRED - more reliable when element is visible in viewport)\",\n },\n {\n name: \"act\",\n description:\n \"Perform a specific atomic action (click, type, etc.) - ONLY use when element is in ariaTree but NOT visible in screenshot. Less reliable but can interact with out-of-viewport elements.\",\n },\n { name: \"dragAndDrop\", description: \"Drag and drop an element\" },\n { name: \"clickAndHold\", description: \"Click and hold on an element\" },\n { name: \"keys\", description: \"Press a keyboard key\" },\n {\n name: \"fillFormVision\",\n description: \"Fill out a form using coordinates\",\n },\n { name: \"think\", description: \"Think about the task\" },\n { name: \"extract\", description: \"Extract structured data\" },\n { name: \"goto\", description: \"Navigate to a URL\" },\n { name: \"wait\", description: \"Wait for a specified time\" },\n { name: \"navback\", description: \"Navigate back in browser history\" },\n { name: \"scroll\", description: \"Scroll the page x pixels up or down\" },\n ];\n\n const domTools: ToolDefinition[] = [\n {\n name: \"screenshot\",\n description: \"Take a compressed JPEG screenshot for quick visual context\",\n },\n {\n name: \"ariaTree\",\n description:\n \"Get an accessibility (ARIA) hybrid tree for full page context\",\n },\n {\n name: \"act\",\n description: \"Perform a specific atomic action (click, type)\",\n },\n { name: \"keys\", description: \"Press a keyboard key\" },\n { name: \"fillForm\", description: \"Fill out a form\" },\n { name: \"think\", description: \"Think about the task\" },\n { name: \"extract\", description: \"Extract structured data\" },\n { name: \"goto\", description: \"Navigate to a URL\" },\n { name: \"wait\", description: \"Wait for a specified time\" },\n { name: \"navback\", description: \"Navigate back in browser history\" },\n { name: \"scroll\", description: \"Scroll the page x pixels up or down\" },\n ];\n\n const baseTools = isHybridMode ? hybridTools : domTools;\n\n if (hasSearch) {\n baseTools.push({\n name: \"search\",\n description:\n \"Perform a web search and return results. Prefer this over navigating to Google and searching within the page for reliability and efficiency.\",\n });\n }\n\n const filteredTools = baseTools.filter((tool) => !excludeSet.has(tool.name));\n\n const toolLines = filteredTools\n .map((tool) => ` <tool name=\"${tool.name}\">${tool.description}</tool>`)\n .join(\"\\n\");\n\n return `<tools>\\n${toolLines}\\n </tools>`;\n}\n\nexport function buildAgentSystemPrompt(\n options: AgentSystemPromptOptions,\n): string {\n const {\n url,\n executionInstruction,\n mode,\n systemInstructions,\n isBrowserbase = false,\n excludeTools,\n variables,\n } = options;\n const localeDate = new Date().toLocaleDateString();\n const isoDate = new Date().toISOString();\n const cdata = (text: string) => `<![CDATA[${text}]]>`;\n\n const isHybridMode = mode === \"hybrid\";\n const hasSearch = Boolean(process.env.BRAVE_API_KEY);\n\n // Tools section differs based on mode and excluded tools\n const toolsSection = buildToolsSection(isHybridMode, hasSearch, excludeTools);\n\n // Strategy differs based on mode\n const strategyItems = isHybridMode\n ? [\n `<item>Tool selection priority: Use specific tools (click, type) when elements are visible in viewport for maximum reliability.</item>`,\n `<item>Always use screenshot to get proper grounding of the coordinates you want to type/click into.</item>`,\n `<item>When interacting with an input, always use the type tool to type into the input, over clicking and then typing into it.</item>`,\n `<item>Use ariaTree as a secondary tool when elements aren't visible in screenshot or to get full page context.</item>`,\n `<item>Only use act when element is in ariaTree but NOT visible in screenshot.</item>`,\n ]\n : [\n `<item>Tool selection priority: Use act tool for all clicking and typing on a page.</item>`,\n `<item>Always check ariaTree first to understand full page content without scrolling - it shows all elements including those below the fold.</item>`,\n `<item>When interacting with an input, always use the act tool to type into the input, over clicking and then typing.</item>`,\n `<item>If an element is present in the ariaTree, use act to interact with it directly - this eliminates the need to scroll.</item>`,\n `<item>Use screenshot for visual confirmation when needed, but rely primarily on ariaTree for element detection.</item>`,\n ];\n\n const strategySection = strategyItems.join(\"\\n \");\n\n const commonStrategyItems = `\n <item>CRITICAL: Use extract ONLY when the task explicitly requires structured data output (e.g., \"get job listings\", \"extract product details\"). For reading page content or understanding elements, always use ${isHybridMode ? \"screenshot or ariaTree\" : \"ariaTree\"} instead - it's faster and more reliable.</item>\n <item>Keep actions atomic and verify outcomes before proceeding.</item>\n <item>For each action, provide clear reasoning about why you're taking that step.</item>\n <item>When you need to input text that could be entered character-by-character or through multiple separate inputs, prefer using the keys tool to type the entire sequence at once. This is more efficient for scenarios like verification codes split across multiple fields, or when virtual keyboards are present but direct typing would be faster.</item>\n `;\n\n // Page understanding protocol differs based on mode\n const pageUnderstandingProtocol = isHybridMode\n ? `<page_understanding_protocol>\n <step_1>\n <title>UNDERSTAND THE PAGE</title>\n <primary_tool>\n <name>screenshot</name>\n <usage>Visual confirmation when needed. Ideally after navigating to a new page.</usage>\n </primary_tool>\n <secondary_tool>\n <name>ariaTree</name>\n <usage>Get complete page context before taking actions</usage>\n <benefit>Eliminates the need to scroll and provides full accessible content</benefit>\n </secondary_tool>\n </step_1>\n </page_understanding_protocol>`\n : `<page_understanding_protocol>\n <step_1>\n <title>UNDERSTAND THE PAGE</title>\n <primary_tool>\n <name>ariaTree</name>\n <usage>Get complete page context before taking actions</usage>\n <benefit>Eliminates the need to scroll and provides full accessible content</benefit>\n </primary_tool>\n <secondary_tool>\n <name>screenshot</name>\n <usage>Visual confirmation when needed. Ideally after navigating to a new page.</usage>\n </secondary_tool>\n </step_1>\n </page_understanding_protocol>`;\n\n // Roadblocks section only shown when running on Browserbase (has captcha solver)\n const roadblocksSection = isBrowserbase\n ? `<roadblocks>\n <note>captchas, popups, etc.</note>\n <captcha>If you see a captcha, use the wait tool. It will automatically be solved by our internal solver.</captcha>\n </roadblocks>`\n : \"\";\n\n // Build customInstructions block only if provided\n const customInstructionsBlock = systemInstructions\n ? `<customInstructions>${cdata(systemInstructions)}</customInstructions>\\n `\n : \"\";\n\n // Build variables section only if variables are provided\n const hasVariables = variables && Object.keys(variables).length > 0;\n const variableToolsNote = isHybridMode\n ? \"Use %variableName% syntax in the type, fillFormVision, or act tool's value/text/action fields.\"\n : \"Use %variableName% syntax in the act or fillForm tool's value/action fields.\";\n const variablesSection = hasVariables\n ? `<variables>\n <note>You have access to the following variables. Use %variableName% syntax to substitute variable values. This is especially important for sensitive data like passwords.</note>\n <usage>${variableToolsNote}</usage>\n <example>To type a password, use: type %password% into the password field</example>\n ${Object.entries(variables)\n .map(([name, v]) => {\n const description =\n typeof v === \"object\" && v !== null && \"value\" in v\n ? v.description\n : undefined;\n return description\n ? `<variable name=\"${name}\">${description}</variable>`\n : `<variable name=\"${name}\" />`;\n })\n .join(\"\\n \")}\n </variables>`\n : \"\";\n\n return `<system>\n <identity>You are a web automation assistant using browser automation tools to accomplish the user's goal.</identity>\n ${customInstructionsBlock}<task>\n <goal>${cdata(executionInstruction)}</goal>\n <date display=\"local\" iso=\"${isoDate}\">${localeDate}</date>\n <note>You may think the date is different due to knowledge cutoff, but this is the actual date.</note>\n </task>\n <page>\n <startingUrl>you are starting your task on this url: ${url}</startingUrl>\n </page>\n <mindset>\n <note>Be very intentional about your action. The initial instruction is very important, and slight variations of the actual goal can lead to failures.</note>\n <importantNote>If something fails to meet a single condition of the task, move on from it rather than seeing if it meets other criteria. We only care that it meets all of it</importantNote>\n <note>When the task is complete, do not seek more information; you have completed the task.</note>\n </mindset>\n <guidelines>\n <item>Always start by understanding the current page state</item>\n <item>Use the screenshot tool to verify page state when needed</item>\n <item>Use appropriate tools for each action</item>\n </guidelines>\n ${pageUnderstandingProtocol}\n <navigation>\n <rule>If you are confident in the URL, navigate directly to it.</rule>\n ${hasSearch ? `<rule>If you are not confident in the URL, use the search tool to find it.</rule>` : ``}\n </navigation>\n ${toolsSection}\n <strategy>\n ${strategySection}\n ${commonStrategyItems}\n </strategy>\n ${roadblocksSection}\n ${variablesSection}\n <completion>\n <note>When you complete the task, explain any information that was found that was relevant to the original task.</note>\n <examples>\n <example>If you were asked for specific flights, list the flights you found.</example>\n <example>If you were asked for information about a product, list the product information you were asked for.</example>\n </examples>\n </completion>\n</system>`;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"agentSystemPrompt.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/prompts/agentSystemPrompt.ts"],"names":[],"mappings":"AA4BA,SAAS,iBAAiB,CACxB,YAAqB,EACrB,SAAkB,EAClB,YAAuB;IAEvB,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC;IAE/C,MAAM,WAAW,GAAqB;QACpC;YACE,IAAI,EAAE,YAAY;YAClB,WAAW,EAAE,4DAA4D;SAC1E;QACD;YACE,IAAI,EAAE,UAAU;YAChB,WAAW,EACT,+DAA+D;SAClE;QACD;YACE,IAAI,EAAE,OAAO;YACb,WAAW,EACT,qFAAqF;SACxF;QACD;YACE,IAAI,EAAE,MAAM;YACZ,WAAW,EACT,2FAA2F;SAC9F;QACD;YACE,IAAI,EAAE,KAAK;YACX,WAAW,EACT,0LAA0L;SAC7L;QACD,EAAE,IAAI,EAAE,aAA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S,CAAC;aACxB,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE;YACjB,MAAM,WAAW,GACf,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAI,OAAO,IAAI,CAAC;gBACjD,CAAC,CAAC,CAAC,CAAC,WAAW;gBACf,CAAC,CAAC,SAAS,CAAC;YAChB,OAAO,WAAW;gBAChB,CAAC,CAAC,mBAAmB,IAAI,KAAK,WAAW,aAAa;gBACtD,CAAC,CAAC,mBAAmB,IAAI,MAAM,CAAC;QACpC,CAAC,CAAC;aACD,IAAI,CAAC,QAAQ,CAAC;eACN;QACX,CAAC,CAAC,EAAE,CAAC;IAEP,OAAO;;IAEL,uBAAuB;YACf,KAAK,CAAC,oBAAoB,CAAC;iCACN,OAAO,KAAK,UAAU;;;;2DAII,GAAG;;;;;;;;;;;;IAY1D,yBAAyB;;;MAGvB,SAAS,CAAC,CAAC,CAAC,mFAAmF,CAAC,CAAC,CAAC,EAAE;;IAEtG,YAAY;;MAEV,eAAe;MACf,mBAAmB;;IAErB,iBAAiB;IACjB,gBAAgB;;;;;;;;UAQV,CAAC;AACX,CAAC","sourcesContent":["import type { AgentToolMode, Variables } from \"../../types/public/agent.js\";\n\nexport interface AgentSystemPromptOptions {\n url: string;\n executionInstruction: string;\n mode: AgentToolMode;\n systemInstructions?: string;\n /** Whether running on Browserbase (enables captcha solver messaging) */\n isBrowserbase?: boolean;\n /** Tools to exclude from the system prompt */\n excludeTools?: string[];\n /** Variables available to the agent for use in act/type tools */\n variables?: Variables;\n /** Whether the search tool is enabled for this execution */\n useSearch?: boolean;\n}\n\n/**\n * Builds the system prompt for the agent based on the tool mode.\n *\n * @param options - The prompt configuration options\n * @returns The formatted system prompt string\n */\ninterface ToolDefinition {\n name: string;\n description: string;\n}\n\nfunction buildToolsSection(\n isHybridMode: boolean,\n hasSearch: boolean,\n excludeTools?: string[],\n): string {\n const excludeSet = new Set(excludeTools ?? []);\n\n const hybridTools: ToolDefinition[] = [\n {\n name: \"screenshot\",\n description: \"Take a compressed JPEG screenshot for quick visual context\",\n },\n {\n name: \"ariaTree\",\n description:\n \"Get an accessibility (ARIA) hybrid tree for full page context\",\n },\n {\n name: \"click\",\n description:\n \"Click on an element (PREFERRED - more reliable when element is visible in viewport)\",\n },\n {\n name: \"type\",\n description:\n \"Type text into an element (PREFERRED - more reliable when element is visible in viewport)\",\n },\n {\n name: \"act\",\n description:\n \"Perform a specific atomic action (click, type, etc.) - ONLY use when element is in ariaTree but NOT visible in screenshot. Less reliable but can interact with out-of-viewport elements.\",\n },\n { name: \"dragAndDrop\", description: \"Drag and drop an element\" },\n { name: \"clickAndHold\", description: \"Click and hold on an element\" },\n { name: \"keys\", description: \"Press a keyboard key\" },\n {\n name: \"fillFormVision\",\n description: \"Fill out a form using coordinates\",\n },\n { name: \"think\", description: \"Think about the task\" },\n { name: \"extract\", description: \"Extract structured data\" },\n { name: \"goto\", description: \"Navigate to a URL\" },\n { name: \"wait\", description: \"Wait for a specified time\" },\n { name: \"navback\", description: \"Navigate back in browser history\" },\n { name: \"scroll\", description: \"Scroll the page x pixels up or down\" },\n ];\n\n const domTools: ToolDefinition[] = [\n {\n name: \"screenshot\",\n description: \"Take a compressed JPEG screenshot for quick visual context\",\n },\n {\n name: \"ariaTree\",\n description:\n \"Get an accessibility (ARIA) hybrid tree for full page context\",\n },\n {\n name: \"act\",\n description: \"Perform a specific atomic action (click, type)\",\n },\n { name: \"keys\", description: \"Press a keyboard key\" },\n { name: \"fillForm\", description: \"Fill out a form\" },\n { name: \"think\", description: \"Think about the task\" },\n { name: \"extract\", description: \"Extract structured data\" },\n { name: \"goto\", description: \"Navigate to a URL\" },\n { name: \"wait\", description: \"Wait for a specified time\" },\n { name: \"navback\", description: \"Navigate back in browser history\" },\n { name: \"scroll\", description: \"Scroll the page x pixels up or down\" },\n ];\n\n const baseTools = isHybridMode ? hybridTools : domTools;\n\n if (hasSearch) {\n baseTools.push({\n name: \"search\",\n description:\n \"Perform a web search and return results. Prefer this over navigating to Google and searching within the page for reliability and efficiency.\",\n });\n }\n\n const filteredTools = baseTools.filter((tool) => !excludeSet.has(tool.name));\n\n const toolLines = filteredTools\n .map((tool) => ` <tool name=\"${tool.name}\">${tool.description}</tool>`)\n .join(\"\\n\");\n\n return `<tools>\\n${toolLines}\\n </tools>`;\n}\n\nexport function buildAgentSystemPrompt(\n options: AgentSystemPromptOptions,\n): string {\n const {\n url,\n executionInstruction,\n mode,\n systemInstructions,\n isBrowserbase = false,\n excludeTools,\n variables,\n useSearch = false,\n } = options;\n const localeDate = new Date().toLocaleDateString();\n const isoDate = new Date().toISOString();\n const cdata = (text: string) => `<![CDATA[${text}]]>`;\n\n const isHybridMode = mode === \"hybrid\";\n const hasSearch = useSearch || Boolean(process.env.BRAVE_API_KEY);\n\n // Tools section differs based on mode and excluded tools\n const toolsSection = buildToolsSection(isHybridMode, hasSearch, excludeTools);\n\n // Strategy differs based on mode\n const strategyItems = isHybridMode\n ? [\n `<item>Tool selection priority: Use specific tools (click, type) when elements are visible in viewport for maximum reliability.</item>`,\n `<item>Always use screenshot to get proper grounding of the coordinates you want to type/click into.</item>`,\n `<item>When interacting with an input, always use the type tool to type into the input, over clicking and then typing into it.</item>`,\n `<item>Use ariaTree as a secondary tool when elements aren't visible in screenshot or to get full page context.</item>`,\n `<item>Only use act when element is in ariaTree but NOT visible in screenshot.</item>`,\n ]\n : [\n `<item>Tool selection priority: Use act tool for all clicking and typing on a page.</item>`,\n `<item>Always check ariaTree first to understand full page content without scrolling - it shows all elements including those below the fold.</item>`,\n `<item>When interacting with an input, always use the act tool to type into the input, over clicking and then typing.</item>`,\n `<item>If an element is present in the ariaTree, use act to interact with it directly - this eliminates the need to scroll.</item>`,\n `<item>Use screenshot for visual confirmation when needed, but rely primarily on ariaTree for element detection.</item>`,\n ];\n\n const strategySection = strategyItems.join(\"\\n \");\n\n const commonStrategyItems = `\n <item>CRITICAL: Use extract ONLY when the task explicitly requires structured data output (e.g., \"get job listings\", \"extract product details\"). For reading page content or understanding elements, always use ${isHybridMode ? \"screenshot or ariaTree\" : \"ariaTree\"} instead - it's faster and more reliable.</item>\n <item>Keep actions atomic and verify outcomes before proceeding.</item>\n <item>For each action, provide clear reasoning about why you're taking that step.</item>\n <item>When you need to input text that could be entered character-by-character or through multiple separate inputs, prefer using the keys tool to type the entire sequence at once. This is more efficient for scenarios like verification codes split across multiple fields, or when virtual keyboards are present but direct typing would be faster.</item>\n `;\n\n // Page understanding protocol differs based on mode\n const pageUnderstandingProtocol = isHybridMode\n ? `<page_understanding_protocol>\n <step_1>\n <title>UNDERSTAND THE PAGE</title>\n <primary_tool>\n <name>screenshot</name>\n <usage>Visual confirmation when needed. Ideally after navigating to a new page.</usage>\n </primary_tool>\n <secondary_tool>\n <name>ariaTree</name>\n <usage>Get complete page context before taking actions</usage>\n <benefit>Eliminates the need to scroll and provides full accessible content</benefit>\n </secondary_tool>\n </step_1>\n </page_understanding_protocol>`\n : `<page_understanding_protocol>\n <step_1>\n <title>UNDERSTAND THE PAGE</title>\n <primary_tool>\n <name>ariaTree</name>\n <usage>Get complete page context before taking actions</usage>\n <benefit>Eliminates the need to scroll and provides full accessible content</benefit>\n </primary_tool>\n <secondary_tool>\n <name>screenshot</name>\n <usage>Visual confirmation when needed. Ideally after navigating to a new page.</usage>\n </secondary_tool>\n </step_1>\n </page_understanding_protocol>`;\n\n // Roadblocks section only shown when running on Browserbase (has captcha solver)\n const roadblocksSection = isBrowserbase\n ? `<roadblocks>\n <note>captchas, popups, etc.</note>\n <captcha>If you see a captcha, use the wait tool. It will automatically be solved by our internal solver.</captcha>\n </roadblocks>`\n : \"\";\n\n // Build customInstructions block only if provided\n const customInstructionsBlock = systemInstructions\n ? `<customInstructions>${cdata(systemInstructions)}</customInstructions>\\n `\n : \"\";\n\n // Build variables section only if variables are provided\n const hasVariables = variables && Object.keys(variables).length > 0;\n const variableToolsNote = isHybridMode\n ? \"Use %variableName% syntax in the type, fillFormVision, or act tool's value/text/action fields.\"\n : \"Use %variableName% syntax in the act or fillForm tool's value/action fields.\";\n const variablesSection = hasVariables\n ? `<variables>\n <note>You have access to the following variables. Use %variableName% syntax to substitute variable values. This is especially important for sensitive data like passwords.</note>\n <usage>${variableToolsNote}</usage>\n <example>To type a password, use: type %password% into the password field</example>\n ${Object.entries(variables)\n .map(([name, v]) => {\n const description =\n typeof v === \"object\" && v !== null && \"value\" in v\n ? v.description\n : undefined;\n return description\n ? `<variable name=\"${name}\">${description}</variable>`\n : `<variable name=\"${name}\" />`;\n })\n .join(\"\\n \")}\n </variables>`\n : \"\";\n\n return `<system>\n <identity>You are a web automation assistant using browser automation tools to accomplish the user's goal.</identity>\n ${customInstructionsBlock}<task>\n <goal>${cdata(executionInstruction)}</goal>\n <date display=\"local\" iso=\"${isoDate}\">${localeDate}</date>\n <note>You may think the date is different due to knowledge cutoff, but this is the actual date.</note>\n </task>\n <page>\n <startingUrl>you are starting your task on this url: ${url}</startingUrl>\n </page>\n <mindset>\n <note>Be very intentional about your action. The initial instruction is very important, and slight variations of the actual goal can lead to failures.</note>\n <importantNote>If something fails to meet a single condition of the task, move on from it rather than seeing if it meets other criteria. We only care that it meets all of it</importantNote>\n <note>When the task is complete, do not seek more information; you have completed the task.</note>\n </mindset>\n <guidelines>\n <item>Always start by understanding the current page state</item>\n <item>Use the screenshot tool to verify page state when needed</item>\n <item>Use appropriate tools for each action</item>\n </guidelines>\n ${pageUnderstandingProtocol}\n <navigation>\n <rule>If you are confident in the URL, navigate directly to it.</rule>\n ${hasSearch ? `<rule>If you are not confident in the URL, use the search tool to find it.</rule>` : ``}\n </navigation>\n ${toolsSection}\n <strategy>\n ${strategySection}\n ${commonStrategyItems}\n </strategy>\n ${roadblocksSection}\n ${variablesSection}\n <completion>\n <note>When you complete the task, explain any information that was found that was relevant to the original task.</note>\n <examples>\n <example>If you were asked for specific flights, list the flights you found.</example>\n <example>If you were asked for information about a product, list the product information you were asked for.</example>\n </examples>\n </completion>\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AAO,EACL,MAAM,CAAC,KAAK,IAAI,SAAS,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,IAAI,CAAC,UAAU;SACtE,CAAC,CAAC;QAEH,OAAO;YACL,GAAG,MAAM;YACT,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;SACtB,CAAC;IACJ,CAAC;CACF,CAAC,CAAC","sourcesContent":["import { tool } from \"ai\";\nimport { z } from \"zod\";\nimport type { V3 } from \"../../v3.js\";\n\nexport interface BraveSearchResult {\n title: string;\n url: string;\n description?: string;\n}\n\ninterface SearchResponse {\n data?: {\n results: BraveSearchResult[];\n };\n error?: string;\n}\n\ninterface BraveWebResult {\n title?: string;\n url?: string;\n description?: string;\n age?: string;\n meta_url?: {\n favicon?: string;\n };\n}\n\ninterface BraveApiResponse {\n web?: {\n results?: BraveWebResult[];\n };\n}\n\nasync function performBraveSearch(query: string): Promise<SearchResponse> {\n try {\n const encodedQuery = encodeURIComponent(query);\n const response = await fetch(\n `https://api.search.brave.com/res/v1/web/search?q=${encodedQuery}`,\n {\n method: \"GET\",\n headers: {\n Accept: \"application/json\",\n \"Accept-Encoding\": \"gzip\",\n \"X-Subscription-Token\": process.env.BRAVE_API_KEY!,\n },\n },\n );\n\n if (!response.ok) {\n return {\n error: `Brave API error: ${response.status} ${response.statusText}`,\n data: { results: [] },\n };\n }\n\n const data = (await response.json()) as BraveApiResponse;\n const results: BraveSearchResult[] = [];\n\n if (data?.web?.results && Array.isArray(data.web.results)) {\n for (const item of data.web.results.slice(0, 5)) {\n if (item.title && item.url) {\n results.push({\n title: item.title,\n url: item.url,\n description: item.description,\n });\n }\n }\n }\n\n return { data: { results } };\n } catch (error) {\n console.error(\"Search error\", error);\n return {\n error: `Error performing search: ${(error as Error).message}`,\n data: { results: [] },\n };\n }\n}\n\nexport const searchTool = (v3: V3) =>\n tool({\n description:\n \"Perform a web search and returns results. Use this tool when you need information from the web or when you are unsure of the exact URL you want to navigate to. This can be used to find the ideal entry point, resulting in a task that is easier to complete due to starting further in the process.\",\n inputSchema: z.object({\n query: z.string().describe(\"The search query to look for on the web\"),\n }),\n execute: async ({ query }) => {\n v3.logger({\n category: \"agent\",\n message: `Agent calling tool: search`,\n level: 1,\n auxiliary: {\n arguments: {\n value: JSON.stringify({ query }),\n type: \"object\",\n },\n },\n });\n\n const result = await performBraveSearch(query);\n\n v3.recordAgentReplayStep({\n type: \"search\",\n instruction: query,\n playwrightArguments: { query },\n message:\n result.error ?? `Found ${result.data?.results.length ?? 0} results`,\n });\n\n return {\n ...result,\n timestamp: Date.now(),\n };\n },\n });\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { V3 } from "../../v3.js";
|
|
2
|
+
export interface SearchResult {
|
|
3
|
+
title: string;
|
|
4
|
+
url: string;
|
|
5
|
+
publishedDate?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const searchTool: (v3: V3, apiKey: string) => import("ai").Tool<{
|
|
8
|
+
query: string;
|
|
9
|
+
}, {
|
|
10
|
+
timestamp: number;
|
|
11
|
+
results: SearchResult[];
|
|
12
|
+
error?: string;
|
|
13
|
+
}>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { tool } from "ai";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
async function performBrowserbaseSearch(v3, query, apiKey, numResults = 5) {
|
|
4
|
+
try {
|
|
5
|
+
const response = await fetch("https://api.browserbase.com/v1/search", {
|
|
6
|
+
method: "POST",
|
|
7
|
+
headers: {
|
|
8
|
+
"Content-Type": "application/json",
|
|
9
|
+
"x-bb-api-key": apiKey,
|
|
10
|
+
},
|
|
11
|
+
body: JSON.stringify({ query, numResults }),
|
|
12
|
+
});
|
|
13
|
+
if (!response.ok) {
|
|
14
|
+
return {
|
|
15
|
+
results: [],
|
|
16
|
+
error: `Browserbase Search API error: ${response.status} ${response.statusText}`,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const data = (await response.json());
|
|
20
|
+
const results = (data?.results ?? []).map(({ title, url, publishedDate }) => ({
|
|
21
|
+
title: title,
|
|
22
|
+
url: url,
|
|
23
|
+
...(publishedDate && { publishedDate }),
|
|
24
|
+
}));
|
|
25
|
+
return { results };
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
v3.logger({
|
|
29
|
+
category: "agent",
|
|
30
|
+
message: `Search error: ${error.message}`,
|
|
31
|
+
level: 0,
|
|
32
|
+
});
|
|
33
|
+
return {
|
|
34
|
+
results: [],
|
|
35
|
+
error: `Error performing search: ${error.message}`,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export const searchTool = (v3, apiKey) => tool({
|
|
40
|
+
description: "Perform a web search and returns results. Use this tool when you need information from the web or when you are unsure of the exact URL you want to navigate to. This can be used to find the ideal entry point, resulting in a task that is easier to complete due to starting further in the process.",
|
|
41
|
+
inputSchema: z.object({
|
|
42
|
+
query: z.string().describe("The search query to look for on the web"),
|
|
43
|
+
}),
|
|
44
|
+
execute: async ({ query }) => {
|
|
45
|
+
v3.logger({
|
|
46
|
+
category: "agent",
|
|
47
|
+
message: `Agent calling tool: search`,
|
|
48
|
+
level: 1,
|
|
49
|
+
auxiliary: {
|
|
50
|
+
arguments: {
|
|
51
|
+
value: JSON.stringify({ query }),
|
|
52
|
+
type: "object",
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
const result = await performBrowserbaseSearch(v3, query, apiKey);
|
|
57
|
+
v3.recordAgentReplayStep({
|
|
58
|
+
type: "search",
|
|
59
|
+
instruction: query,
|
|
60
|
+
playwrightArguments: { query },
|
|
61
|
+
message: result.error ?? `Found ${result.results.length} results`,
|
|
62
|
+
});
|
|
63
|
+
return { ...result, timestamp: Date.now() };
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
//# sourceMappingURL=browserbaseSearch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browserbaseSearch.js","sourceRoot":"","sources":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AAK,EAAE,CAAC;SACT,CAAC,CAAC;QACH,OAAO;YACL,OAAO,EAAE,EAAE;YACX,KAAK,EAAE,4BAA6B,KAAe,CAAC,OAAO,EAAE;SAC9D,CAAC;IACJ,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,EAAM,EAAE,MAAc,EAAE,EAAE,CACnD,IAAI,CAAC;IACH,WAAW,EACT,wSAAwS;IAC1S,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;QACpB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,yCAAyC,CAAC;KACtE,CAAC;IACF,OAAO,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE;QAC3B,EAAE,CAAC,MAAM,CAAC;YACR,QAAQ,EAAE,OAAO;YACjB,OAAO,EAAE,4BAA4B;YACrC,KAAK,EAAE,CAAC;YACR,SAAS,EAAE;gBACT,SAAS,EAAE;oBACT,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,CAAC;oBAChC,IAAI,EAAE,QAAQ;iBACf;aACF;SACF,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,MAAM,wBAAwB,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;QAEjE,EAAE,CAAC,qBAAqB,CAAC;YACvB,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,KAAK;YAClB,mBAAmB,EAAE,EAAE,KAAK,EAAE;YAC9B,OAAO,EAAE,MAAM,CAAC,KAAK,IAAI,SAAS,MAAM,CAAC,OAAO,CAAC,MAAM,UAAU;SAClE,CAAC,CAAC;QAEH,OAAO,EAAE,GAAG,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;IAC9C,CAAC;CACF,CAAC,CAAC","sourcesContent":["import { tool } from \"ai\";\nimport { z } from \"zod\";\nimport type { V3 } from \"../../v3.js\";\n\nexport interface SearchResult {\n title: string;\n url: string;\n publishedDate?: string;\n}\n\ninterface BrowserbaseRawResult {\n title?: string;\n url?: string;\n publishedDate?: string;\n}\n\ninterface BrowserbaseApiResponse {\n results?: BrowserbaseRawResult[];\n}\n\nasync function performBrowserbaseSearch(\n v3: V3,\n query: string,\n apiKey: string,\n numResults: number = 5,\n): Promise<{ results: SearchResult[]; error?: string }> {\n try {\n const response = await fetch(\"https://api.browserbase.com/v1/search\", {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-bb-api-key\": apiKey,\n },\n body: JSON.stringify({ query, numResults }),\n });\n\n if (!response.ok) {\n return {\n results: [],\n error: `Browserbase Search API error: ${response.status} ${response.statusText}`,\n };\n }\n\n const data = (await response.json()) as BrowserbaseApiResponse;\n const results: SearchResult[] = (data?.results ?? []).map(\n ({ title, url, publishedDate }) => ({\n title: title,\n url: url,\n ...(publishedDate && { publishedDate }),\n }),\n );\n\n return { results };\n } catch (error) {\n v3.logger({\n category: \"agent\",\n message: `Search error: ${(error as Error).message}`,\n level: 0,\n });\n return {\n results: [],\n error: `Error performing search: ${(error as Error).message}`,\n };\n }\n}\n\nexport const searchTool = (v3: V3, apiKey: string) =>\n tool({\n description:\n \"Perform a web search and returns results. Use this tool when you need information from the web or when you are unsure of the exact URL you want to navigate to. This can be used to find the ideal entry point, resulting in a task that is easier to complete due to starting further in the process.\",\n inputSchema: z.object({\n query: z.string().describe(\"The search query to look for on the web\"),\n }),\n execute: async ({ query }) => {\n v3.logger({\n category: \"agent\",\n message: `Agent calling tool: search`,\n level: 1,\n auxiliary: {\n arguments: {\n value: JSON.stringify({ query }),\n type: \"object\",\n },\n },\n });\n\n const result = await performBrowserbaseSearch(v3, query, apiKey);\n\n v3.recordAgentReplayStep({\n type: \"search\",\n instruction: query,\n playwrightArguments: { query },\n message: result.error ?? `Found ${result.results.length} results`,\n });\n\n return { ...result, timestamp: Date.now() };\n },\n });\n"]}
|
|
@@ -14,7 +14,8 @@ import { clickAndHoldTool } from "./clickAndHold.js";
|
|
|
14
14
|
import { keysTool } from "./keys.js";
|
|
15
15
|
import { fillFormVisionTool } from "./fillFormVision.js";
|
|
16
16
|
import { thinkTool } from "./think.js";
|
|
17
|
-
import { searchTool } from "./
|
|
17
|
+
import { searchTool as browserbaseSearchTool } from "./browserbaseSearch.js";
|
|
18
|
+
import { searchTool as braveSearchTool } from "./braveSearch.js";
|
|
18
19
|
import type { ToolSet, InferUITools } from "ai";
|
|
19
20
|
import type { V3 } from "../../v3.js";
|
|
20
21
|
import type { LogLine } from "../../types/public/logs.js";
|
|
@@ -47,12 +48,22 @@ export interface V3AgentToolOptions {
|
|
|
47
48
|
* Forwarded to the underlying v3 call's `timeout` option.
|
|
48
49
|
*/
|
|
49
50
|
toolTimeout?: number;
|
|
51
|
+
/**
|
|
52
|
+
* Whether to enable the Browserbase-powered web search tool.
|
|
53
|
+
* Requires a valid Browserbase API key.
|
|
54
|
+
*/
|
|
55
|
+
useSearch?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* The Browserbase API key used for the search tool.
|
|
58
|
+
* Resolved from BROWSERBASE_API_KEY env var or the Stagehand constructor.
|
|
59
|
+
*/
|
|
60
|
+
browserbaseApiKey?: string;
|
|
50
61
|
}
|
|
51
62
|
export declare function createAgentTools(v3: V3, options?: V3AgentToolOptions): ToolSet;
|
|
52
63
|
export type AgentTools = ReturnType<typeof createAgentTools>;
|
|
53
64
|
/**
|
|
54
65
|
* Type map of all agent tools for strong typing of tool calls and results.
|
|
55
|
-
* Note: `search` is optional
|
|
66
|
+
* Note: `search` is optional — enabled via useSearch: true (Browserbase) or BRAVE_API_KEY env var (legacy).
|
|
56
67
|
*/
|
|
57
68
|
export type AgentToolTypesMap = {
|
|
58
69
|
act: ReturnType<typeof actTool>;
|
|
@@ -68,7 +79,7 @@ export type AgentToolTypesMap = {
|
|
|
68
79
|
navback: ReturnType<typeof navBackTool>;
|
|
69
80
|
screenshot: ReturnType<typeof screenshotTool>;
|
|
70
81
|
scroll: ReturnType<typeof scrollTool> | ReturnType<typeof scrollVisionTool>;
|
|
71
|
-
search?: ReturnType<typeof
|
|
82
|
+
search?: ReturnType<typeof browserbaseSearchTool> | ReturnType<typeof braveSearchTool>;
|
|
72
83
|
think: ReturnType<typeof thinkTool>;
|
|
73
84
|
type: ReturnType<typeof typeTool>;
|
|
74
85
|
wait: ReturnType<typeof waitTool>;
|
|
@@ -14,7 +14,8 @@ import { clickAndHoldTool } from "./clickAndHold.js";
|
|
|
14
14
|
import { keysTool } from "./keys.js";
|
|
15
15
|
import { fillFormVisionTool } from "./fillFormVision.js";
|
|
16
16
|
import { thinkTool } from "./think.js";
|
|
17
|
-
import { searchTool } from "./
|
|
17
|
+
import { searchTool as browserbaseSearchTool } from "./browserbaseSearch.js";
|
|
18
|
+
import { searchTool as braveSearchTool } from "./braveSearch.js";
|
|
18
19
|
/**
|
|
19
20
|
* Filters tools based on mode and explicit exclusions.
|
|
20
21
|
* - 'dom' mode: Removes coordinate-based tools (click, type, dragAndDrop, clickAndHold, fillFormVision)
|
|
@@ -67,8 +68,11 @@ export function createAgentTools(v3, options) {
|
|
|
67
68
|
type: typeTool(v3, provider, variables),
|
|
68
69
|
wait: waitTool(v3, mode),
|
|
69
70
|
};
|
|
70
|
-
if (
|
|
71
|
-
allTools.search =
|
|
71
|
+
if (options?.useSearch && options.browserbaseApiKey) {
|
|
72
|
+
allTools.search = browserbaseSearchTool(v3, options.browserbaseApiKey);
|
|
73
|
+
}
|
|
74
|
+
else if (process.env.BRAVE_API_KEY) {
|
|
75
|
+
allTools.search = braveSearchTool(v3);
|
|
72
76
|
}
|
|
73
77
|
return filterTools(allTools, mode, excludeTools);
|
|
74
78
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,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AE,QAAQ,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,CAAC;QACvC,IAAI,EAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;KACzB,CAAC;IAEF,IAAI,OAAO,EAAE,SAAS,IAAI,OAAO,CAAC,iBAAiB,EAAE,CAAC;QACpD,QAAQ,CAAC,MAAM,GAAG,qBAAqB,CAAC,EAAE,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACzE,CAAC;SAAM,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC;QACrC,QAAQ,CAAC,MAAM,GAAG,eAAe,CAAC,EAAE,CAAC,CAAC;IACxC,CAAC;IAED,OAAO,WAAW,CAAC,QAAQ,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;AACnD,CAAC","sourcesContent":["import { gotoTool } from \"./goto.js\";\nimport { actTool } from \"./act.js\";\nimport { screenshotTool } from \"./screenshot.js\";\nimport { waitTool } from \"./wait.js\";\nimport { navBackTool } from \"./navback.js\";\nimport { ariaTreeTool } from \"./ariaTree.js\";\nimport { fillFormTool } from \"./fillform.js\";\nimport { scrollTool, scrollVisionTool } from \"./scroll.js\";\nimport { extractTool } from \"./extract.js\";\nimport { clickTool } from \"./click.js\";\nimport { typeTool } from \"./type.js\";\nimport { dragAndDropTool } from \"./dragAndDrop.js\";\nimport { clickAndHoldTool } from \"./clickAndHold.js\";\nimport { keysTool } from \"./keys.js\";\nimport { fillFormVisionTool } from \"./fillFormVision.js\";\nimport { thinkTool } from \"./think.js\";\nimport { searchTool as browserbaseSearchTool } from \"./browserbaseSearch.js\";\nimport { searchTool as braveSearchTool } from \"./braveSearch.js\";\n\nimport type { ToolSet, InferUITools } from \"ai\";\nimport type { V3 } from \"../../v3.js\";\nimport type { LogLine } from \"../../types/public/logs.js\";\nimport type {\n AgentToolMode,\n AgentModelConfig,\n Variables,\n} from \"../../types/public/agent.js\";\n\nexport interface V3AgentToolOptions {\n executionModel?: string | AgentModelConfig;\n logger?: (message: LogLine) => void;\n /**\n * Tool mode determines which set of tools are available.\n * - 'dom' (default): Uses DOM-based tools (act, fillForm) - removes coordinate-based tools\n * - 'hybrid': Uses coordinate-based tools (click, type, dragAndDrop, etc.) - removes fillForm\n */\n mode?: AgentToolMode;\n /**\n * The model provider. Used for model-specific coordinate handling\n */\n provider?: string;\n /**\n * Tools to exclude from the available toolset.\n * These tools will be filtered out after mode-based filtering.\n */\n excludeTools?: string[];\n /**\n * Variables available to the agent for use in act/type tools.\n * When provided, these tools will have an optional useVariable field.\n */\n variables?: Variables;\n /**\n * Timeout in milliseconds for tool calls that invoke v3 methods (act, extract, fillForm, ariaTree).\n * Forwarded to the underlying v3 call's `timeout` option.\n */\n toolTimeout?: number;\n /**\n * Whether to enable the Browserbase-powered web search tool.\n * Requires a valid Browserbase API key.\n */\n useSearch?: boolean;\n /**\n * The Browserbase API key used for the search tool.\n * Resolved from BROWSERBASE_API_KEY env var or the Stagehand constructor.\n */\n browserbaseApiKey?: string;\n}\n\n/**\n * Filters tools based on mode and explicit exclusions.\n * - 'dom' mode: Removes coordinate-based tools (click, type, dragAndDrop, clickAndHold, fillFormVision)\n * - 'hybrid' mode: Removes DOM-based form tool (fillForm) in favor of coordinate-based fillFormVision\n * - excludeTools: Additional tools to remove from the toolset\n */\nfunction filterTools(\n tools: ToolSet,\n mode: AgentToolMode,\n excludeTools?: string[],\n): ToolSet {\n const filtered: ToolSet = { ...tools };\n\n // Mode-based filtering\n if (mode === \"hybrid\") {\n delete filtered.fillForm;\n } else {\n // DOM mode (default)\n delete filtered.click;\n delete filtered.type;\n delete filtered.dragAndDrop;\n delete filtered.clickAndHold;\n delete filtered.fillFormVision;\n }\n\n if (excludeTools) {\n for (const toolName of excludeTools) {\n delete filtered[toolName];\n }\n }\n\n return filtered;\n}\n\nexport function createAgentTools(v3: V3, options?: V3AgentToolOptions) {\n const executionModel = options?.executionModel;\n const mode = options?.mode ?? \"dom\";\n const provider = options?.provider;\n const excludeTools = options?.excludeTools;\n const variables = options?.variables;\n const toolTimeout = options?.toolTimeout;\n\n const allTools: ToolSet = {\n act: actTool(v3, executionModel, variables, toolTimeout),\n ariaTree: ariaTreeTool(v3, toolTimeout),\n click: clickTool(v3, provider),\n clickAndHold: clickAndHoldTool(v3, provider),\n dragAndDrop: dragAndDropTool(v3, provider),\n extract: extractTool(v3, executionModel, toolTimeout),\n fillForm: fillFormTool(v3, executionModel, variables, toolTimeout),\n fillFormVision: fillFormVisionTool(v3, provider, variables),\n goto: gotoTool(v3),\n keys: keysTool(v3),\n navback: navBackTool(v3),\n screenshot: screenshotTool(v3),\n scroll: mode === \"hybrid\" ? scrollVisionTool(v3, provider) : scrollTool(v3),\n think: thinkTool(),\n type: typeTool(v3, provider, variables),\n wait: waitTool(v3, mode),\n };\n\n if (options?.useSearch && options.browserbaseApiKey) {\n allTools.search = browserbaseSearchTool(v3, options.browserbaseApiKey);\n } else if (process.env.BRAVE_API_KEY) {\n allTools.search = braveSearchTool(v3);\n }\n\n return filterTools(allTools, mode, excludeTools);\n}\n\nexport type AgentTools = ReturnType<typeof createAgentTools>;\n\n/**\n * Type map of all agent tools for strong typing of tool calls and results.\n * Note: `search` is optional — enabled via useSearch: true (Browserbase) or BRAVE_API_KEY env var (legacy).\n */\nexport type AgentToolTypesMap = {\n act: ReturnType<typeof actTool>;\n ariaTree: ReturnType<typeof ariaTreeTool>;\n click: ReturnType<typeof clickTool>;\n clickAndHold: ReturnType<typeof clickAndHoldTool>;\n dragAndDrop: ReturnType<typeof dragAndDropTool>;\n extract: ReturnType<typeof extractTool>;\n fillForm: ReturnType<typeof fillFormTool>;\n fillFormVision: ReturnType<typeof fillFormVisionTool>;\n goto: ReturnType<typeof gotoTool>;\n keys: ReturnType<typeof keysTool>;\n navback: ReturnType<typeof navBackTool>;\n screenshot: ReturnType<typeof screenshotTool>;\n scroll: ReturnType<typeof scrollTool> | ReturnType<typeof scrollVisionTool>;\n search?:\n | ReturnType<typeof browserbaseSearchTool>\n | ReturnType<typeof braveSearchTool>;\n think: ReturnType<typeof thinkTool>;\n type: ReturnType<typeof typeTool>;\n wait: ReturnType<typeof waitTool>;\n};\n\n/**\n * Inferred UI tools type for type-safe tool inputs and outputs.\n * Use with UIMessage for full type safety in UI contexts.\n */\nexport type AgentUITools = InferUITools<AgentToolTypesMap>;\n\n/**\n * Union type for all possible agent tool calls.\n * Provides type-safe access to tool call arguments.\n */\nexport type AgentToolCall = {\n [K in keyof AgentToolTypesMap]: {\n toolName: K;\n toolCallId: string;\n args: AgentUITools[K][\"input\"];\n };\n}[keyof AgentToolTypesMap];\n\n/**\n * Union type for all possible agent tool results.\n * Provides type-safe access to tool result values.\n */\nexport type AgentToolResult = {\n [K in keyof AgentToolTypesMap]: {\n toolName: K;\n toolCallId: string;\n result: AgentUITools[K][\"output\"];\n };\n}[keyof AgentToolTypesMap];\n"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { EventEmitter } from "node:events";
|
|
2
|
+
import type { V3Options } from "./types/public/index.js";
|
|
3
|
+
import { type FlowEvent } from "./flowLogger.js";
|
|
4
|
+
export interface FlowEventAggregateMetrics {
|
|
5
|
+
llmRequests: number;
|
|
6
|
+
inputTokens: number;
|
|
7
|
+
outputTokens: number;
|
|
8
|
+
cdpEvents: number;
|
|
9
|
+
}
|
|
10
|
+
export interface EventStoreQuery {
|
|
11
|
+
sessionId?: string;
|
|
12
|
+
eventId?: string;
|
|
13
|
+
eventType?: string;
|
|
14
|
+
limit?: number;
|
|
15
|
+
}
|
|
16
|
+
export type EventStoreListener = (event: FlowEvent) => void;
|
|
17
|
+
export interface EventStore {
|
|
18
|
+
initializeSession(sessionId: string, v3Options?: V3Options): Promise<void>;
|
|
19
|
+
appendEvent(event: FlowEvent): Promise<void>;
|
|
20
|
+
attachBus(sessionId: string, bus: EventEmitter): () => void;
|
|
21
|
+
listEvents(query: EventStoreQuery): Promise<FlowEvent[]>;
|
|
22
|
+
subscribe(query: EventStoreQuery, listener: EventStoreListener): () => void;
|
|
23
|
+
destroy(): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export declare function aggregateFlowEventMetrics(events: FlowEvent[]): FlowEventAggregateMetrics;
|
|
26
|
+
export declare function getConfigDir(): string;
|
|
27
|
+
export declare class FileEventStore implements EventStore {
|
|
28
|
+
private readonly sessionContexts;
|
|
29
|
+
private readonly eventsBySession;
|
|
30
|
+
private readonly subscribers;
|
|
31
|
+
initializeSession(sessionId: string, v3Options?: V3Options): Promise<void>;
|
|
32
|
+
private initSessionContext;
|
|
33
|
+
appendEvent(event: FlowEvent): Promise<void>;
|
|
34
|
+
attachBus(sessionId: string, bus: EventEmitter): () => void;
|
|
35
|
+
listEvents(query: EventStoreQuery): Promise<FlowEvent[]>;
|
|
36
|
+
subscribe(query: EventStoreQuery, listener: EventStoreListener): () => void;
|
|
37
|
+
destroy(): Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
export declare function setEventStore(store: EventStore): void;
|
|
40
|
+
export declare function getEventStore(): EventStore;
|
|
41
|
+
export declare function destroyEventStore(): Promise<void>;
|