@browserbasehq/orca 3.0.9-alpha-4 → 3.1.0-patch.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/lib/inference.d.ts +65 -0
- package/dist/esm/lib/inference.js +333 -0
- package/dist/esm/lib/inference.js.map +1 -0
- package/dist/esm/lib/inferenceLogUtils.d.ts +12 -0
- package/dist/esm/lib/inferenceLogUtils.js +92 -0
- package/dist/esm/lib/inferenceLogUtils.js.map +1 -0
- package/dist/esm/lib/logger.d.ts +69 -0
- package/dist/esm/lib/logger.js +323 -0
- package/dist/esm/lib/logger.js.map +1 -0
- package/dist/esm/lib/modelUtils.d.ts +14 -0
- package/dist/esm/lib/modelUtils.js +48 -0
- package/dist/esm/lib/modelUtils.js.map +1 -0
- package/dist/esm/lib/prompt.d.ts +14 -0
- package/dist/esm/lib/prompt.js +230 -0
- package/dist/esm/lib/prompt.js.map +1 -0
- package/dist/esm/lib/utils.d.ts +68 -0
- package/dist/esm/lib/utils.js +654 -0
- package/dist/esm/lib/utils.js.map +1 -0
- package/dist/esm/lib/v3/agent/AgentClient.d.ts +19 -0
- package/dist/esm/lib/v3/agent/AgentClient.js +17 -0
- package/dist/esm/lib/v3/agent/AgentClient.js.map +1 -0
- package/dist/esm/lib/v3/agent/AgentProvider.d.ts +20 -0
- package/dist/esm/lib/v3/agent/AgentProvider.js +77 -0
- package/dist/esm/lib/v3/agent/AgentProvider.js.map +1 -0
- package/dist/esm/lib/v3/agent/AnthropicCUAClient.d.ts +57 -0
- package/dist/esm/lib/v3/agent/AnthropicCUAClient.js +822 -0
- package/dist/esm/lib/v3/agent/AnthropicCUAClient.js.map +1 -0
- package/dist/esm/lib/v3/agent/GoogleCUAClient.d.ts +74 -0
- package/dist/esm/lib/v3/agent/GoogleCUAClient.js +799 -0
- package/dist/esm/lib/v3/agent/GoogleCUAClient.js.map +1 -0
- package/dist/esm/lib/v3/agent/MicrosoftCUAClient.d.ts +71 -0
- package/dist/esm/lib/v3/agent/MicrosoftCUAClient.js +770 -0
- package/dist/esm/lib/v3/agent/MicrosoftCUAClient.js.map +1 -0
- package/dist/esm/lib/v3/agent/OpenAICUAClient.d.ts +69 -0
- package/dist/esm/lib/v3/agent/OpenAICUAClient.js +615 -0
- package/dist/esm/lib/v3/agent/OpenAICUAClient.js.map +1 -0
- package/dist/esm/lib/v3/agent/prompts/agentSystemPrompt.d.ts +12 -0
- package/dist/esm/lib/v3/agent/prompts/agentSystemPrompt.js +186 -0
- package/dist/esm/lib/v3/agent/prompts/agentSystemPrompt.js.map +1 -0
- package/dist/esm/lib/v3/agent/tools/act.d.ts +13 -0
- package/dist/esm/lib/v3/agent/tools/act.js +49 -0
- package/dist/esm/lib/v3/agent/tools/act.js.map +1 -0
- package/dist/esm/lib/v3/agent/tools/ariaTree.d.ts +5 -0
- package/dist/esm/lib/v3/agent/tools/ariaTree.js +31 -0
- package/dist/esm/lib/v3/agent/tools/ariaTree.js.map +1 -0
- package/dist/esm/lib/v3/agent/tools/click.d.ts +6 -0
- package/dist/esm/lib/v3/agent/tools/click.js +104 -0
- package/dist/esm/lib/v3/agent/tools/click.js.map +1 -0
- package/dist/esm/lib/v3/agent/tools/clickAndHold.d.ts +14 -0
- package/dist/esm/lib/v3/agent/tools/clickAndHold.js +68 -0
- package/dist/esm/lib/v3/agent/tools/clickAndHold.js.map +1 -0
- package/dist/esm/lib/v3/agent/tools/dragAndDrop.d.ts +7 -0
- package/dist/esm/lib/v3/agent/tools/dragAndDrop.js +105 -0
- package/dist/esm/lib/v3/agent/tools/dragAndDrop.js.map +1 -0
- package/dist/esm/lib/v3/agent/tools/extract.d.ts +21 -0
- package/dist/esm/lib/v3/agent/tools/extract.js +93 -0
- package/dist/esm/lib/v3/agent/tools/extract.js.map +1 -0
- package/dist/esm/lib/v3/agent/tools/fillFormVision.d.ts +12 -0
- package/dist/esm/lib/v3/agent/tools/fillFormVision.js +143 -0
- package/dist/esm/lib/v3/agent/tools/fillFormVision.js.map +1 -0
- package/dist/esm/lib/v3/agent/tools/fillform.d.ts +13 -0
- package/dist/esm/lib/v3/agent/tools/fillform.js +56 -0
- package/dist/esm/lib/v3/agent/tools/fillform.js.map +1 -0
- package/dist/esm/lib/v3/agent/tools/goto.d.ts +12 -0
- package/dist/esm/lib/v3/agent/tools/goto.js +31 -0
- package/dist/esm/lib/v3/agent/tools/goto.js.map +1 -0
- package/dist/esm/lib/v3/agent/tools/index.d.ts +92 -0
- package/dist/esm/lib/v3/agent/tools/index.js +74 -0
- package/dist/esm/lib/v3/agent/tools/index.js.map +1 -0
- package/dist/esm/lib/v3/agent/tools/keys.d.ts +24 -0
- package/dist/esm/lib/v3/agent/tools/keys.js +60 -0
- package/dist/esm/lib/v3/agent/tools/keys.js.map +1 -0
- package/dist/esm/lib/v3/agent/tools/navback.d.ts +6 -0
- package/dist/esm/lib/v3/agent/tools/navback.js +23 -0
- package/dist/esm/lib/v3/agent/tools/navback.js.map +1 -0
- package/dist/esm/lib/v3/agent/tools/screenshot.d.ts +6 -0
- package/dist/esm/lib/v3/agent/tools/screenshot.js +26 -0
- package/dist/esm/lib/v3/agent/tools/screenshot.js.map +1 -0
- package/dist/esm/lib/v3/agent/tools/scroll.d.ts +19 -0
- package/dist/esm/lib/v3/agent/tools/scroll.js +142 -0
- package/dist/esm/lib/v3/agent/tools/scroll.js.map +1 -0
- package/dist/esm/lib/v3/agent/tools/search.d.ts +15 -0
- package/dist/esm/lib/v3/agent/tools/search.js +73 -0
- package/dist/esm/lib/v3/agent/tools/search.js.map +1 -0
- package/dist/esm/lib/v3/agent/tools/think.d.ts +6 -0
- package/dist/esm/lib/v3/agent/tools/think.js +24 -0
- package/dist/esm/lib/v3/agent/tools/think.js.map +1 -0
- package/dist/esm/lib/v3/agent/tools/type.d.ts +7 -0
- package/dist/esm/lib/v3/agent/tools/type.js +106 -0
- package/dist/esm/lib/v3/agent/tools/type.js.map +1 -0
- package/dist/esm/lib/v3/agent/tools/wait.d.ts +5 -0
- package/dist/esm/lib/v3/agent/tools/wait.js +53 -0
- package/dist/esm/lib/v3/agent/tools/wait.js.map +1 -0
- package/dist/esm/lib/v3/agent/utils/actionMapping.d.ts +3 -0
- package/dist/esm/lib/v3/agent/utils/actionMapping.js +100 -0
- package/dist/esm/lib/v3/agent/utils/actionMapping.js.map +1 -0
- package/dist/esm/lib/v3/agent/utils/coordinateNormalization.d.ts +13 -0
- package/dist/esm/lib/v3/agent/utils/coordinateNormalization.js +28 -0
- package/dist/esm/lib/v3/agent/utils/coordinateNormalization.js.map +1 -0
- package/dist/esm/lib/v3/agent/utils/cuaKeyMapping.d.ts +10 -0
- package/dist/esm/lib/v3/agent/utils/cuaKeyMapping.js +62 -0
- package/dist/esm/lib/v3/agent/utils/cuaKeyMapping.js.map +1 -0
- package/dist/esm/lib/v3/agent/utils/googleCustomToolHandler.d.ts +25 -0
- package/dist/esm/lib/v3/agent/utils/googleCustomToolHandler.js +145 -0
- package/dist/esm/lib/v3/agent/utils/googleCustomToolHandler.js.map +1 -0
- package/dist/esm/lib/v3/agent/utils/handleDoneToolCall.d.ts +22 -0
- package/dist/esm/lib/v3/agent/utils/handleDoneToolCall.js +101 -0
- package/dist/esm/lib/v3/agent/utils/handleDoneToolCall.js.map +1 -0
- package/dist/esm/lib/v3/agent/utils/imageCompression.d.ts +53 -0
- package/dist/esm/lib/v3/agent/utils/imageCompression.js +204 -0
- package/dist/esm/lib/v3/agent/utils/imageCompression.js.map +1 -0
- package/dist/esm/lib/v3/agent/utils/messageProcessing.d.ts +12 -0
- package/dist/esm/lib/v3/agent/utils/messageProcessing.js +164 -0
- package/dist/esm/lib/v3/agent/utils/messageProcessing.js.map +1 -0
- package/dist/esm/lib/v3/agent/utils/screenshotHandler.d.ts +10 -0
- package/dist/esm/lib/v3/agent/utils/screenshotHandler.js +26 -0
- package/dist/esm/lib/v3/agent/utils/screenshotHandler.js.map +1 -0
- package/dist/esm/lib/v3/agent/utils/validateExperimentalFeatures.d.ts +26 -0
- package/dist/esm/lib/v3/agent/utils/validateExperimentalFeatures.js +79 -0
- package/dist/esm/lib/v3/agent/utils/validateExperimentalFeatures.js.map +1 -0
- package/dist/esm/lib/v3/agent/utils/xpath.d.ts +11 -0
- package/dist/esm/lib/v3/agent/utils/xpath.js +19 -0
- package/dist/esm/lib/v3/agent/utils/xpath.js.map +1 -0
- package/dist/esm/lib/v3/api.d.ts +86 -0
- package/dist/esm/lib/v3/api.js +484 -0
- package/dist/esm/lib/v3/api.js.map +1 -0
- package/dist/esm/lib/v3/cache/ActCache.d.ts +23 -0
- package/dist/esm/lib/v3/cache/ActCache.js +292 -0
- package/dist/esm/lib/v3/cache/ActCache.js.map +1 -0
- package/dist/esm/lib/v3/cache/AgentCache.d.ts +109 -0
- package/dist/esm/lib/v3/cache/AgentCache.js +640 -0
- package/dist/esm/lib/v3/cache/AgentCache.js.map +1 -0
- package/dist/esm/lib/v3/cache/CacheStorage.d.ts +17 -0
- package/dist/esm/lib/v3/cache/CacheStorage.js +98 -0
- package/dist/esm/lib/v3/cache/CacheStorage.js.map +1 -0
- package/dist/esm/lib/v3/cache/serverAgentCache.d.ts +7 -0
- package/dist/esm/lib/v3/cache/serverAgentCache.js +49 -0
- package/dist/esm/lib/v3/cache/serverAgentCache.js.map +1 -0
- package/dist/esm/lib/v3/cache/utils.d.ts +15 -0
- package/dist/esm/lib/v3/cache/utils.js +39 -0
- package/dist/esm/lib/v3/cache/utils.js.map +1 -0
- package/dist/esm/lib/v3/dom/a11yScripts/index.d.ts +11 -0
- package/dist/esm/lib/v3/dom/a11yScripts/index.js +117 -0
- package/dist/esm/lib/v3/dom/a11yScripts/index.js.map +1 -0
- package/dist/esm/lib/v3/dom/build/a11yScripts.generated.d.ts +16 -0
- package/dist/esm/lib/v3/dom/build/a11yScripts.generated.js +20 -0
- package/dist/esm/lib/v3/dom/build/a11yScripts.generated.js.map +1 -0
- package/dist/esm/lib/v3/dom/build/locatorScripts.generated.d.ts +52 -0
- package/dist/esm/lib/v3/dom/build/locatorScripts.generated.js +56 -0
- package/dist/esm/lib/v3/dom/build/locatorScripts.generated.js.map +1 -0
- package/dist/esm/lib/v3/dom/build/reRenderScriptContent.d.ts +1 -0
- package/dist/esm/lib/v3/dom/build/reRenderScriptContent.js +2 -0
- package/dist/esm/lib/v3/dom/build/reRenderScriptContent.js.map +1 -0
- package/dist/esm/lib/v3/dom/build/rerender-index.js +1 -0
- package/dist/esm/lib/v3/dom/build/screenshotScripts.generated.d.ts +4 -0
- package/dist/esm/lib/v3/dom/build/screenshotScripts.generated.js +8 -0
- package/dist/esm/lib/v3/dom/build/screenshotScripts.generated.js.map +1 -0
- package/dist/esm/lib/v3/dom/build/scriptV3Content.d.ts +1 -0
- package/dist/esm/lib/v3/dom/build/scriptV3Content.js +2 -0
- package/dist/esm/lib/v3/dom/build/scriptV3Content.js.map +1 -0
- package/dist/esm/lib/v3/dom/build/v3-index.js +1 -0
- package/dist/esm/lib/v3/dom/genA11yScripts.d.ts +1 -0
- package/dist/esm/lib/v3/dom/genA11yScripts.js +54 -0
- package/dist/esm/lib/v3/dom/genA11yScripts.js.map +1 -0
- package/dist/esm/lib/v3/dom/genDomScripts.d.ts +1 -0
- package/dist/esm/lib/v3/dom/genDomScripts.js +38 -0
- package/dist/esm/lib/v3/dom/genDomScripts.js.map +1 -0
- package/dist/esm/lib/v3/dom/genLocatorScripts.d.ts +1 -0
- package/dist/esm/lib/v3/dom/genLocatorScripts.js +51 -0
- package/dist/esm/lib/v3/dom/genLocatorScripts.js.map +1 -0
- package/dist/esm/lib/v3/dom/genScreenshotScripts.d.ts +1 -0
- package/dist/esm/lib/v3/dom/genScreenshotScripts.js +37 -0
- package/dist/esm/lib/v3/dom/genScreenshotScripts.js.map +1 -0
- package/dist/esm/lib/v3/dom/index.d.ts +1 -0
- package/dist/esm/lib/v3/dom/index.js +2 -0
- package/dist/esm/lib/v3/dom/index.js.map +1 -0
- package/dist/esm/lib/v3/dom/locatorScripts/counts.d.ts +15 -0
- package/dist/esm/lib/v3/dom/locatorScripts/counts.js +272 -0
- package/dist/esm/lib/v3/dom/locatorScripts/counts.js.map +1 -0
- package/dist/esm/lib/v3/dom/locatorScripts/index.d.ts +4 -0
- package/dist/esm/lib/v3/dom/locatorScripts/index.js +5 -0
- package/dist/esm/lib/v3/dom/locatorScripts/index.js.map +1 -0
- package/dist/esm/lib/v3/dom/locatorScripts/scripts.d.ts +37 -0
- package/dist/esm/lib/v3/dom/locatorScripts/scripts.js +458 -0
- package/dist/esm/lib/v3/dom/locatorScripts/scripts.js.map +1 -0
- package/dist/esm/lib/v3/dom/locatorScripts/selectors.d.ts +4 -0
- package/dist/esm/lib/v3/dom/locatorScripts/selectors.js +283 -0
- package/dist/esm/lib/v3/dom/locatorScripts/selectors.js.map +1 -0
- package/dist/esm/lib/v3/dom/locatorScripts/waitForSelector.d.ts +19 -0
- package/dist/esm/lib/v3/dom/locatorScripts/waitForSelector.js +283 -0
- package/dist/esm/lib/v3/dom/locatorScripts/waitForSelector.js.map +1 -0
- package/dist/esm/lib/v3/dom/locatorScripts/xpathParser.d.ts +76 -0
- package/dist/esm/lib/v3/dom/locatorScripts/xpathParser.js +376 -0
- package/dist/esm/lib/v3/dom/locatorScripts/xpathParser.js.map +1 -0
- package/dist/esm/lib/v3/dom/locatorScripts/xpathResolver.d.ts +9 -0
- package/dist/esm/lib/v3/dom/locatorScripts/xpathResolver.js +196 -0
- package/dist/esm/lib/v3/dom/locatorScripts/xpathResolver.js.map +1 -0
- package/dist/esm/lib/v3/dom/piercer.entry.d.ts +1 -0
- package/dist/esm/lib/v3/dom/piercer.entry.js +3 -0
- package/dist/esm/lib/v3/dom/piercer.entry.js.map +1 -0
- package/dist/esm/lib/v3/dom/piercer.runtime.d.ts +23 -0
- package/dist/esm/lib/v3/dom/piercer.runtime.js +90 -0
- package/dist/esm/lib/v3/dom/piercer.runtime.js.map +1 -0
- package/dist/esm/lib/v3/dom/rerenderMissingShadows.entry.d.ts +1 -0
- package/dist/esm/lib/v3/dom/rerenderMissingShadows.entry.js +3 -0
- package/dist/esm/lib/v3/dom/rerenderMissingShadows.entry.js.map +1 -0
- package/dist/esm/lib/v3/dom/rerenderMissingShadows.runtime.d.ts +1 -0
- package/dist/esm/lib/v3/dom/rerenderMissingShadows.runtime.js +40 -0
- package/dist/esm/lib/v3/dom/rerenderMissingShadows.runtime.js.map +1 -0
- package/dist/esm/lib/v3/dom/screenshotScripts/index.d.ts +1 -0
- package/dist/esm/lib/v3/dom/screenshotScripts/index.js +2 -0
- package/dist/esm/lib/v3/dom/screenshotScripts/index.js.map +1 -0
- package/dist/esm/lib/v3/dom/screenshotScripts/resolveMaskRect.d.ts +8 -0
- package/dist/esm/lib/v3/dom/screenshotScripts/resolveMaskRect.js +82 -0
- package/dist/esm/lib/v3/dom/screenshotScripts/resolveMaskRect.js.map +1 -0
- package/dist/esm/lib/v3/external_clients/aisdk.d.ts +11 -0
- package/dist/esm/lib/v3/external_clients/aisdk.js +103 -0
- package/dist/esm/lib/v3/external_clients/aisdk.js.map +1 -0
- package/dist/esm/lib/v3/external_clients/customOpenAI.d.ts +18 -0
- package/dist/esm/lib/v3/external_clients/customOpenAI.js +220 -0
- package/dist/esm/lib/v3/external_clients/customOpenAI.js.map +1 -0
- package/dist/esm/lib/v3/flowLogger.d.ts +139 -0
- package/dist/esm/lib/v3/flowLogger.js +868 -0
- package/dist/esm/lib/v3/flowLogger.js.map +1 -0
- package/dist/esm/lib/v3/handlers/actHandler.d.ts +21 -0
- package/dist/esm/lib/v3/handlers/actHandler.js +340 -0
- package/dist/esm/lib/v3/handlers/actHandler.js.map +1 -0
- package/dist/esm/lib/v3/handlers/extractHandler.d.ts +31 -0
- package/dist/esm/lib/v3/handlers/extractHandler.js +139 -0
- package/dist/esm/lib/v3/handlers/extractHandler.js.map +1 -0
- package/dist/esm/lib/v3/handlers/handlerUtils/actHandlerUtils.d.ts +24 -0
- package/dist/esm/lib/v3/handlers/handlerUtils/actHandlerUtils.js +623 -0
- package/dist/esm/lib/v3/handlers/handlerUtils/actHandlerUtils.js.map +1 -0
- package/dist/esm/lib/v3/handlers/handlerUtils/timeoutGuard.d.ts +2 -0
- package/dist/esm/lib/v3/handlers/handlerUtils/timeoutGuard.js +14 -0
- package/dist/esm/lib/v3/handlers/handlerUtils/timeoutGuard.js.map +1 -0
- package/dist/esm/lib/v3/handlers/observeHandler.d.ts +17 -0
- package/dist/esm/lib/v3/handlers/observeHandler.js +156 -0
- package/dist/esm/lib/v3/handlers/observeHandler.js.map +1 -0
- package/dist/esm/lib/v3/handlers/v3AgentHandler.d.ts +32 -0
- package/dist/esm/lib/v3/handlers/v3AgentHandler.js +461 -0
- package/dist/esm/lib/v3/handlers/v3AgentHandler.js.map +1 -0
- package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.d.ts +33 -0
- package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.js +528 -0
- package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.js.map +1 -0
- package/dist/esm/lib/v3/index.d.ts +17 -0
- package/dist/esm/lib/v3/index.js +13 -0
- package/dist/esm/lib/v3/index.js.map +1 -0
- package/dist/esm/lib/v3/launch/browserbase.d.ts +7 -0
- package/dist/esm/lib/v3/launch/browserbase.js +46 -0
- package/dist/esm/lib/v3/launch/browserbase.js.map +1 -0
- package/dist/esm/lib/v3/launch/local.d.ts +15 -0
- package/dist/esm/lib/v3/launch/local.js +98 -0
- package/dist/esm/lib/v3/launch/local.js.map +1 -0
- package/dist/esm/lib/v3/llm/AnthropicClient.d.ts +16 -0
- package/dist/esm/lib/v3/llm/AnthropicClient.js +239 -0
- package/dist/esm/lib/v3/llm/AnthropicClient.js.map +1 -0
- package/dist/esm/lib/v3/llm/CerebrasClient.d.ts +17 -0
- package/dist/esm/lib/v3/llm/CerebrasClient.js +235 -0
- package/dist/esm/lib/v3/llm/CerebrasClient.js.map +1 -0
- package/dist/esm/lib/v3/llm/GoogleClient.d.ts +19 -0
- package/dist/esm/lib/v3/llm/GoogleClient.js +369 -0
- package/dist/esm/lib/v3/llm/GoogleClient.js.map +1 -0
- package/dist/esm/lib/v3/llm/GroqClient.d.ts +17 -0
- package/dist/esm/lib/v3/llm/GroqClient.js +236 -0
- package/dist/esm/lib/v3/llm/GroqClient.js.map +1 -0
- package/dist/esm/lib/v3/llm/LLMClient.d.ts +121 -0
- package/dist/esm/lib/v3/llm/LLMClient.js +23 -0
- package/dist/esm/lib/v3/llm/LLMClient.js.map +1 -0
- package/dist/esm/lib/v3/llm/LLMProvider.d.ts +13 -0
- package/dist/esm/lib/v3/llm/LLMProvider.js +194 -0
- package/dist/esm/lib/v3/llm/LLMProvider.js.map +1 -0
- package/dist/esm/lib/v3/llm/OpenAIClient.d.ts +15 -0
- package/dist/esm/lib/v3/llm/OpenAIClient.js +329 -0
- package/dist/esm/lib/v3/llm/OpenAIClient.js.map +1 -0
- package/dist/esm/lib/v3/llm/aisdk.d.ts +15 -0
- package/dist/esm/lib/v3/llm/aisdk.js +348 -0
- package/dist/esm/lib/v3/llm/aisdk.js.map +1 -0
- package/dist/esm/lib/v3/logger.d.ts +9 -0
- package/dist/esm/lib/v3/logger.js +96 -0
- package/dist/esm/lib/v3/logger.js.map +1 -0
- package/dist/esm/lib/v3/mcp/connection.d.ts +11 -0
- package/dist/esm/lib/v3/mcp/connection.js +49 -0
- package/dist/esm/lib/v3/mcp/connection.js.map +1 -0
- package/dist/esm/lib/v3/mcp/utils.d.ts +3 -0
- package/dist/esm/lib/v3/mcp/utils.js +36 -0
- package/dist/esm/lib/v3/mcp/utils.js.map +1 -0
- package/dist/esm/lib/v3/shutdown/cleanupLocal.d.ts +14 -0
- package/dist/esm/lib/v3/shutdown/cleanupLocal.js +30 -0
- package/dist/esm/lib/v3/shutdown/cleanupLocal.js.map +1 -0
- package/dist/esm/lib/v3/shutdown/supervisor.d.ts +9 -0
- package/dist/esm/lib/v3/shutdown/supervisor.js +156 -0
- package/dist/esm/lib/v3/shutdown/supervisor.js.map +1 -0
- package/dist/esm/lib/v3/shutdown/supervisorClient.d.ts +15 -0
- package/dist/esm/lib/v3/shutdown/supervisorClient.js +97 -0
- package/dist/esm/lib/v3/shutdown/supervisorClient.js.map +1 -0
- package/dist/esm/lib/v3/tests/agent-abort-signal.spec.js +113 -0
- package/dist/esm/lib/v3/tests/agent-abort-signal.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/agent-cache-self-heal.spec.js +80 -0
- package/dist/esm/lib/v3/tests/agent-cache-self-heal.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/agent-callbacks.spec.js +374 -0
- package/dist/esm/lib/v3/tests/agent-callbacks.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/agent-experimental-validation.spec.js +357 -0
- package/dist/esm/lib/v3/tests/agent-experimental-validation.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/agent-hybrid-mode.spec.js +247 -0
- package/dist/esm/lib/v3/tests/agent-hybrid-mode.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/agent-message-continuation.spec.js +105 -0
- package/dist/esm/lib/v3/tests/agent-message-continuation.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/agent-streaming.spec.js +126 -0
- package/dist/esm/lib/v3/tests/agent-streaming.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/cdp-session-detached.spec.js +44 -0
- package/dist/esm/lib/v3/tests/cdp-session-detached.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/click-count.spec.js +112 -0
- package/dist/esm/lib/v3/tests/click-count.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/connect-to-existing-browser.spec.js +54 -0
- package/dist/esm/lib/v3/tests/connect-to-existing-browser.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/context-addInitScript.spec.js +176 -0
- package/dist/esm/lib/v3/tests/context-addInitScript.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/default-page-tracking.spec.js +53 -0
- package/dist/esm/lib/v3/tests/default-page-tracking.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/downloads.spec.js +58 -0
- package/dist/esm/lib/v3/tests/downloads.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/envReporter.js +57 -0
- package/dist/esm/lib/v3/tests/envReporter.js.map +7 -0
- package/dist/esm/lib/v3/tests/frame-get-location-and-click.spec.js +53 -0
- package/dist/esm/lib/v3/tests/frame-get-location-and-click.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/iframe-ctx-addInitScript.spec.js +447 -0
- package/dist/esm/lib/v3/tests/iframe-ctx-addInitScript.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/keep-alive.child.js +92 -0
- package/dist/esm/lib/v3/tests/keep-alive.child.js.map +7 -0
- package/dist/esm/lib/v3/tests/keep-alive.helpers.js +532 -0
- package/dist/esm/lib/v3/tests/keep-alive.helpers.js.map +7 -0
- package/dist/esm/lib/v3/tests/keep-alive.spec.js +19 -0
- package/dist/esm/lib/v3/tests/keep-alive.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/keyboard.spec.js +296 -0
- package/dist/esm/lib/v3/tests/keyboard.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/locator-backend-node-id.spec.js +159 -0
- package/dist/esm/lib/v3/tests/locator-backend-node-id.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/locator-content-methods.spec.js +191 -0
- package/dist/esm/lib/v3/tests/locator-content-methods.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/locator-count-iframe.spec.js +108 -0
- package/dist/esm/lib/v3/tests/locator-count-iframe.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/locator-count.spec.js +71 -0
- package/dist/esm/lib/v3/tests/locator-count.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/locator-fill.spec.js +118 -0
- package/dist/esm/lib/v3/tests/locator-fill.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/locator-input-methods.spec.js +136 -0
- package/dist/esm/lib/v3/tests/locator-input-methods.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/locator-nth.spec.js +157 -0
- package/dist/esm/lib/v3/tests/locator-nth.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/locator-select-option.spec.js +242 -0
- package/dist/esm/lib/v3/tests/locator-select-option.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/logger-initialization.spec.js +552 -0
- package/dist/esm/lib/v3/tests/logger-initialization.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/multi-instance-logger.spec.js +269 -0
- package/dist/esm/lib/v3/tests/multi-instance-logger.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/nested-div.spec.js +23 -0
- package/dist/esm/lib/v3/tests/nested-div.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/page-addInitScript.spec.js +90 -0
- package/dist/esm/lib/v3/tests/page-addInitScript.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/page-console.spec.js +56 -0
- package/dist/esm/lib/v3/tests/page-console.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/page-drag-and-drop.spec.js +418 -0
- package/dist/esm/lib/v3/tests/page-drag-and-drop.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/page-goto-response.spec.js +35 -0
- package/dist/esm/lib/v3/tests/page-goto-response.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/page-hover.spec.js +167 -0
- package/dist/esm/lib/v3/tests/page-hover.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/page-screenshot.spec.js +273 -0
- package/dist/esm/lib/v3/tests/page-screenshot.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/page-scroll.spec.js +182 -0
- package/dist/esm/lib/v3/tests/page-scroll.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/page-send-cdp.spec.js +46 -0
- package/dist/esm/lib/v3/tests/page-send-cdp.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/perform-understudy-method.spec.js +98 -0
- package/dist/esm/lib/v3/tests/perform-understudy-method.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/setinputfiles.spec.js +126 -0
- package/dist/esm/lib/v3/tests/setinputfiles.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/shadow-iframe-oopif.spec.js +134 -0
- package/dist/esm/lib/v3/tests/shadow-iframe-oopif.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/shadow-iframe-spif.spec.js +134 -0
- package/dist/esm/lib/v3/tests/shadow-iframe-spif.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/testUtils.js +31 -0
- package/dist/esm/lib/v3/tests/testUtils.js.map +7 -0
- package/dist/esm/lib/v3/tests/text-selector-innermost.spec.js +100 -0
- package/dist/esm/lib/v3/tests/text-selector-innermost.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/timeouts.spec.js +32 -0
- package/dist/esm/lib/v3/tests/timeouts.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/user-data-dir.spec.js +43 -0
- package/dist/esm/lib/v3/tests/user-data-dir.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/v3.config.js +15 -0
- package/dist/esm/lib/v3/tests/v3.config.js.map +7 -0
- package/dist/esm/lib/v3/tests/v3.dynamic.config.js +43 -0
- package/dist/esm/lib/v3/tests/v3.dynamic.config.js.map +7 -0
- package/dist/esm/lib/v3/tests/v3.playwright.config.js +98 -0
- package/dist/esm/lib/v3/tests/v3.playwright.config.js.map +7 -0
- package/dist/esm/lib/v3/tests/wait-for-selector.spec.js +593 -0
- package/dist/esm/lib/v3/tests/wait-for-selector.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/wait-for-timeout.spec.js +97 -0
- package/dist/esm/lib/v3/tests/wait-for-timeout.spec.js.map +7 -0
- package/dist/esm/lib/v3/tests/xpath-for-location-deep.spec.js +77 -0
- package/dist/esm/lib/v3/tests/xpath-for-location-deep.spec.js.map +7 -0
- package/dist/esm/lib/v3/timeoutConfig.d.ts +2 -0
- package/dist/esm/lib/v3/timeoutConfig.js +27 -0
- package/dist/esm/lib/v3/timeoutConfig.js.map +1 -0
- package/dist/esm/lib/v3/types/private/agent.d.ts +6 -0
- package/dist/esm/lib/v3/types/private/agent.js +2 -0
- package/dist/esm/lib/v3/types/private/agent.js.map +1 -0
- package/dist/esm/lib/v3/types/private/api.d.ts +11 -0
- package/dist/esm/lib/v3/types/private/api.js +2 -0
- package/dist/esm/lib/v3/types/private/api.js.map +1 -0
- package/dist/esm/lib/v3/types/private/cache.d.ts +128 -0
- package/dist/esm/lib/v3/types/private/cache.js +2 -0
- package/dist/esm/lib/v3/types/private/cache.js.map +1 -0
- package/dist/esm/lib/v3/types/private/evaluator.d.ts +40 -0
- package/dist/esm/lib/v3/types/private/evaluator.js +2 -0
- package/dist/esm/lib/v3/types/private/evaluator.js.map +1 -0
- package/dist/esm/lib/v3/types/private/handlers.d.ts +38 -0
- package/dist/esm/lib/v3/types/private/handlers.js +16 -0
- package/dist/esm/lib/v3/types/private/handlers.js.map +1 -0
- package/dist/esm/lib/v3/types/private/index.d.ts +7 -0
- package/dist/esm/lib/v3/types/private/index.js +8 -0
- package/dist/esm/lib/v3/types/private/index.js.map +1 -0
- package/dist/esm/lib/v3/types/private/internal.d.ts +39 -0
- package/dist/esm/lib/v3/types/private/internal.js +2 -0
- package/dist/esm/lib/v3/types/private/internal.js.map +1 -0
- package/dist/esm/lib/v3/types/private/locator.d.ts +9 -0
- package/dist/esm/lib/v3/types/private/locator.js +2 -0
- package/dist/esm/lib/v3/types/private/locator.js.map +1 -0
- package/dist/esm/lib/v3/types/private/network.d.ts +34 -0
- package/dist/esm/lib/v3/types/private/network.js +3 -0
- package/dist/esm/lib/v3/types/private/network.js.map +1 -0
- package/dist/esm/lib/v3/types/private/shutdown.d.ts +31 -0
- package/dist/esm/lib/v3/types/private/shutdown.js +5 -0
- package/dist/esm/lib/v3/types/private/shutdown.js.map +1 -0
- package/dist/esm/lib/v3/types/private/shutdownErrors.d.ts +12 -0
- package/dist/esm/lib/v3/types/private/shutdownErrors.js +22 -0
- package/dist/esm/lib/v3/types/private/shutdownErrors.js.map +1 -0
- package/dist/esm/lib/v3/types/private/snapshot.d.ts +117 -0
- package/dist/esm/lib/v3/types/private/snapshot.js +2 -0
- package/dist/esm/lib/v3/types/private/snapshot.js.map +1 -0
- package/dist/esm/lib/v3/types/public/agent.d.ts +595 -0
- package/dist/esm/lib/v3/types/public/agent.js +15 -0
- package/dist/esm/lib/v3/types/public/agent.js.map +1 -0
- package/dist/esm/lib/v3/types/public/api.d.ts +1211 -0
- package/dist/esm/lib/v3/types/public/api.js +915 -0
- package/dist/esm/lib/v3/types/public/api.js.map +1 -0
- package/dist/esm/lib/v3/types/public/apiErrors.d.ts +18 -0
- package/dist/esm/lib/v3/types/public/apiErrors.js +32 -0
- package/dist/esm/lib/v3/types/public/apiErrors.js.map +1 -0
- package/dist/esm/lib/v3/types/public/index.d.ts +12 -0
- package/dist/esm/lib/v3/types/public/index.js +14 -0
- package/dist/esm/lib/v3/types/public/index.js.map +1 -0
- package/dist/esm/lib/v3/types/public/locator.d.ts +9 -0
- package/dist/esm/lib/v3/types/public/locator.js +2 -0
- package/dist/esm/lib/v3/types/public/locator.js.map +1 -0
- package/dist/esm/lib/v3/types/public/logs.d.ts +23 -0
- package/dist/esm/lib/v3/types/public/logs.js +13 -0
- package/dist/esm/lib/v3/types/public/logs.js.map +1 -0
- package/dist/esm/lib/v3/types/public/methods.d.ts +56 -0
- package/dist/esm/lib/v3/types/public/methods.js +15 -0
- package/dist/esm/lib/v3/types/public/methods.js.map +1 -0
- package/dist/esm/lib/v3/types/public/metrics.d.ts +27 -0
- package/dist/esm/lib/v3/types/public/metrics.js +2 -0
- package/dist/esm/lib/v3/types/public/metrics.js.map +1 -0
- package/dist/esm/lib/v3/types/public/model.d.ts +65 -0
- package/dist/esm/lib/v3/types/public/model.js +2 -0
- package/dist/esm/lib/v3/types/public/model.js.map +1 -0
- package/dist/esm/lib/v3/types/public/options.d.ts +70 -0
- package/dist/esm/lib/v3/types/public/options.js +4 -0
- package/dist/esm/lib/v3/types/public/options.js.map +1 -0
- package/dist/esm/lib/v3/types/public/page.d.ts +18 -0
- package/dist/esm/lib/v3/types/public/page.js +3 -0
- package/dist/esm/lib/v3/types/public/page.js.map +1 -0
- package/dist/esm/lib/v3/types/public/screenshotTypes.d.ts +25 -0
- package/dist/esm/lib/v3/types/public/screenshotTypes.js +2 -0
- package/dist/esm/lib/v3/types/public/screenshotTypes.js.map +1 -0
- package/dist/esm/lib/v3/types/public/sdkErrors.d.ts +152 -0
- package/dist/esm/lib/v3/types/public/sdkErrors.js +305 -0
- package/dist/esm/lib/v3/types/public/sdkErrors.js.map +1 -0
- package/dist/esm/lib/v3/understudy/a11y/snapshot/a11yTree.d.ts +15 -0
- package/dist/esm/lib/v3/understudy/a11y/snapshot/a11yTree.js +196 -0
- package/dist/esm/lib/v3/understudy/a11y/snapshot/a11yTree.js.map +1 -0
- package/dist/esm/lib/v3/understudy/a11y/snapshot/activeElement.d.ts +8 -0
- package/dist/esm/lib/v3/understudy/a11y/snapshot/activeElement.js +121 -0
- package/dist/esm/lib/v3/understudy/a11y/snapshot/activeElement.js.map +1 -0
- package/dist/esm/lib/v3/understudy/a11y/snapshot/capture.d.ts +77 -0
- package/dist/esm/lib/v3/understudy/a11y/snapshot/capture.js +336 -0
- package/dist/esm/lib/v3/understudy/a11y/snapshot/capture.js.map +1 -0
- package/dist/esm/lib/v3/understudy/a11y/snapshot/coordinateResolver.d.ts +7 -0
- package/dist/esm/lib/v3/understudy/a11y/snapshot/coordinateResolver.js +129 -0
- package/dist/esm/lib/v3/understudy/a11y/snapshot/coordinateResolver.js.map +1 -0
- package/dist/esm/lib/v3/understudy/a11y/snapshot/domTree.d.ts +46 -0
- package/dist/esm/lib/v3/understudy/a11y/snapshot/domTree.js +274 -0
- package/dist/esm/lib/v3/understudy/a11y/snapshot/domTree.js.map +1 -0
- package/dist/esm/lib/v3/understudy/a11y/snapshot/focusSelectors.d.ts +24 -0
- package/dist/esm/lib/v3/understudy/a11y/snapshot/focusSelectors.js +216 -0
- package/dist/esm/lib/v3/understudy/a11y/snapshot/focusSelectors.js.map +1 -0
- package/dist/esm/lib/v3/understudy/a11y/snapshot/index.d.ts +4 -0
- package/dist/esm/lib/v3/understudy/a11y/snapshot/index.js +5 -0
- package/dist/esm/lib/v3/understudy/a11y/snapshot/index.js.map +1 -0
- package/dist/esm/lib/v3/understudy/a11y/snapshot/sessions.d.ts +16 -0
- package/dist/esm/lib/v3/understudy/a11y/snapshot/sessions.js +22 -0
- package/dist/esm/lib/v3/understudy/a11y/snapshot/sessions.js.map +1 -0
- package/dist/esm/lib/v3/understudy/a11y/snapshot/treeFormatUtils.d.ts +28 -0
- package/dist/esm/lib/v3/understudy/a11y/snapshot/treeFormatUtils.js +135 -0
- package/dist/esm/lib/v3/understudy/a11y/snapshot/treeFormatUtils.js.map +1 -0
- package/dist/esm/lib/v3/understudy/a11y/snapshot/xpathUtils.d.ts +26 -0
- package/dist/esm/lib/v3/understudy/a11y/snapshot/xpathUtils.js +102 -0
- package/dist/esm/lib/v3/understudy/a11y/snapshot/xpathUtils.js.map +1 -0
- package/dist/esm/lib/v3/understudy/a11yInvocation.d.ts +8 -0
- package/dist/esm/lib/v3/understudy/a11yInvocation.js +12 -0
- package/dist/esm/lib/v3/understudy/a11yInvocation.js.map +1 -0
- package/dist/esm/lib/v3/understudy/cdp.d.ts +69 -0
- package/dist/esm/lib/v3/understudy/cdp.js +251 -0
- package/dist/esm/lib/v3/understudy/cdp.js.map +1 -0
- package/dist/esm/lib/v3/understudy/consoleMessage.d.ts +22 -0
- package/dist/esm/lib/v3/understudy/consoleMessage.js +66 -0
- package/dist/esm/lib/v3/understudy/consoleMessage.js.map +1 -0
- package/dist/esm/lib/v3/understudy/context.d.ts +132 -0
- package/dist/esm/lib/v3/understudy/context.js +687 -0
- package/dist/esm/lib/v3/understudy/context.js.map +1 -0
- package/dist/esm/lib/v3/understudy/deepLocator.d.ts +87 -0
- package/dist/esm/lib/v3/understudy/deepLocator.js +218 -0
- package/dist/esm/lib/v3/understudy/deepLocator.js.map +1 -0
- package/dist/esm/lib/v3/understudy/executionContextRegistry.d.ts +15 -0
- package/dist/esm/lib/v3/understudy/executionContextRegistry.js +83 -0
- package/dist/esm/lib/v3/understudy/executionContextRegistry.js.map +1 -0
- package/dist/esm/lib/v3/understudy/fileUploadUtils.d.ts +13 -0
- package/dist/esm/lib/v3/understudy/fileUploadUtils.js +81 -0
- package/dist/esm/lib/v3/understudy/fileUploadUtils.js.map +1 -0
- package/dist/esm/lib/v3/understudy/frame.d.ts +69 -0
- package/dist/esm/lib/v3/understudy/frame.js +211 -0
- package/dist/esm/lib/v3/understudy/frame.js.map +1 -0
- package/dist/esm/lib/v3/understudy/frameLocator.d.ts +50 -0
- package/dist/esm/lib/v3/understudy/frameLocator.js +255 -0
- package/dist/esm/lib/v3/understudy/frameLocator.js.map +1 -0
- package/dist/esm/lib/v3/understudy/frameRegistry.d.ts +101 -0
- package/dist/esm/lib/v3/understudy/frameRegistry.js +298 -0
- package/dist/esm/lib/v3/understudy/frameRegistry.js.map +1 -0
- package/dist/esm/lib/v3/understudy/initScripts.d.ts +2 -0
- package/dist/esm/lib/v3/understudy/initScripts.js +33 -0
- package/dist/esm/lib/v3/understudy/initScripts.js.map +1 -0
- package/dist/esm/lib/v3/understudy/lifecycleWatcher.d.ts +64 -0
- package/dist/esm/lib/v3/understudy/lifecycleWatcher.js +245 -0
- package/dist/esm/lib/v3/understudy/lifecycleWatcher.js.map +1 -0
- package/dist/esm/lib/v3/understudy/locator.d.ts +194 -0
- package/dist/esm/lib/v3/understudy/locator.js +753 -0
- package/dist/esm/lib/v3/understudy/locator.js.map +1 -0
- package/dist/esm/lib/v3/understudy/locatorInvocation.d.ts +8 -0
- package/dist/esm/lib/v3/understudy/locatorInvocation.js +12 -0
- package/dist/esm/lib/v3/understudy/locatorInvocation.js.map +1 -0
- package/dist/esm/lib/v3/understudy/navigationResponseTracker.d.ts +84 -0
- package/dist/esm/lib/v3/understudy/navigationResponseTracker.js +224 -0
- package/dist/esm/lib/v3/understudy/navigationResponseTracker.js.map +1 -0
- package/dist/esm/lib/v3/understudy/networkManager.d.ts +53 -0
- package/dist/esm/lib/v3/understudy/networkManager.js +306 -0
- package/dist/esm/lib/v3/understudy/networkManager.js.map +1 -0
- package/dist/esm/lib/v3/understudy/page.d.ts +354 -0
- package/dist/esm/lib/v3/understudy/page.js +1941 -0
- package/dist/esm/lib/v3/understudy/page.js.map +1 -0
- package/dist/esm/lib/v3/understudy/piercer.d.ts +4 -0
- package/dist/esm/lib/v3/understudy/piercer.js +61 -0
- package/dist/esm/lib/v3/understudy/piercer.js.map +1 -0
- package/dist/esm/lib/v3/understudy/response.d.ts +137 -0
- package/dist/esm/lib/v3/understudy/response.js +330 -0
- package/dist/esm/lib/v3/understudy/response.js.map +1 -0
- package/dist/esm/lib/v3/understudy/screenshotUtils.d.ts +16 -0
- package/dist/esm/lib/v3/understudy/screenshotUtils.js +352 -0
- package/dist/esm/lib/v3/understudy/screenshotUtils.js.map +1 -0
- package/dist/esm/lib/v3/understudy/selectorResolver.d.ts +38 -0
- package/dist/esm/lib/v3/understudy/selectorResolver.js +296 -0
- package/dist/esm/lib/v3/understudy/selectorResolver.js.map +1 -0
- package/dist/esm/lib/v3/v3.d.ts +191 -0
- package/dist/esm/lib/v3/v3.js +1572 -0
- package/dist/esm/lib/v3/v3.js.map +1 -0
- package/dist/esm/lib/v3/zodCompat.d.ts +12 -0
- package/dist/esm/lib/v3/zodCompat.js +17 -0
- package/dist/esm/lib/v3/zodCompat.js.map +1 -0
- package/dist/esm/lib/v3Evaluator.d.ts +19 -0
- package/dist/esm/lib/v3Evaluator.js +210 -0
- package/dist/esm/lib/v3Evaluator.js.map +1 -0
- package/dist/esm/lib/version.d.ts +5 -0
- package/dist/esm/lib/version.js +6 -0
- package/dist/esm/lib/version.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/tests/agent-execution-model.test.js +139 -0
- package/dist/esm/tests/agent-execution-model.test.js.map +7 -0
- package/dist/esm/tests/browserbase-session-accessors.test.js +101 -0
- package/dist/esm/tests/browserbase-session-accessors.test.js.map +7 -0
- package/dist/esm/tests/cache-llm-resolution.test.js +187 -0
- package/dist/esm/tests/cache-llm-resolution.test.js.map +7 -0
- package/dist/esm/tests/helpers/mockCDPSession.js +27 -0
- package/dist/esm/tests/helpers/mockCDPSession.js.map +7 -0
- package/dist/esm/tests/llm-provider.test.js +57 -0
- package/dist/esm/tests/llm-provider.test.js.map +7 -0
- package/dist/esm/tests/model-deprecation.test.js +135 -0
- package/dist/esm/tests/model-deprecation.test.js.map +7 -0
- package/dist/esm/tests/model-utils.test.js +43 -0
- package/dist/esm/tests/model-utils.test.js.map +7 -0
- package/dist/esm/tests/page-snapshot.test.js +36 -0
- package/dist/esm/tests/page-snapshot.test.js.map +7 -0
- package/dist/esm/tests/public-api/export-surface.test.js +53 -0
- package/dist/esm/tests/public-api/export-surface.test.js.map +7 -0
- package/dist/esm/tests/public-api/llm-and-agents.test.js +128 -0
- package/dist/esm/tests/public-api/llm-and-agents.test.js.map +7 -0
- package/dist/esm/tests/public-api/public-error-types.test.js +71 -0
- package/dist/esm/tests/public-api/public-error-types.test.js.map +7 -0
- package/dist/esm/tests/public-api/public-types.test.js +74 -0
- package/dist/esm/tests/public-api/public-types.test.js.map +7 -0
- package/dist/esm/tests/public-api/runtime-utils.test.js +31 -0
- package/dist/esm/tests/public-api/runtime-utils.test.js.map +7 -0
- package/dist/esm/tests/public-api/schema-utils.test.js +78 -0
- package/dist/esm/tests/public-api/schema-utils.test.js.map +7 -0
- package/dist/esm/tests/public-api/timeout-error-types.test.js +81 -0
- package/dist/esm/tests/public-api/timeout-error-types.test.js.map +7 -0
- package/dist/esm/tests/public-api/tool-type-export.test.js +25 -0
- package/dist/esm/tests/public-api/tool-type-export.test.js.map +7 -0
- package/dist/esm/tests/public-api/v3-core.test.js +82 -0
- package/dist/esm/tests/public-api/v3-core.test.js.map +7 -0
- package/dist/esm/tests/safety-confirmation.test.js +134 -0
- package/dist/esm/tests/safety-confirmation.test.js.map +7 -0
- package/dist/esm/tests/snapshot-a11y-resolvers.test.js +348 -0
- package/dist/esm/tests/snapshot-a11y-resolvers.test.js.map +7 -0
- package/dist/esm/tests/snapshot-a11y-tree-utils.test.js +300 -0
- package/dist/esm/tests/snapshot-a11y-tree-utils.test.js.map +7 -0
- package/dist/esm/tests/snapshot-capture-orchestration.test.js +381 -0
- package/dist/esm/tests/snapshot-capture-orchestration.test.js.map +7 -0
- package/dist/esm/tests/snapshot-cbor.test.js +197 -0
- package/dist/esm/tests/snapshot-cbor.test.js.map +7 -0
- package/dist/esm/tests/snapshot-dom-session-builders.test.js +251 -0
- package/dist/esm/tests/snapshot-dom-session-builders.test.js.map +7 -0
- package/dist/esm/tests/snapshot-dom-tree-utils.test.js +109 -0
- package/dist/esm/tests/snapshot-dom-tree-utils.test.js.map +7 -0
- package/dist/esm/tests/snapshot-focus-selectors-utils.test.js +49 -0
- package/dist/esm/tests/snapshot-focus-selectors-utils.test.js.map +7 -0
- package/dist/esm/tests/snapshot-frame-merge.test.js +391 -0
- package/dist/esm/tests/snapshot-frame-merge.test.js.map +7 -0
- package/dist/esm/tests/snapshot-tree-format-utils.test.js +113 -0
- package/dist/esm/tests/snapshot-tree-format-utils.test.js.map +7 -0
- package/dist/esm/tests/snapshot-xpath-utils.test.js +79 -0
- package/dist/esm/tests/snapshot-xpath-utils.test.js.map +7 -0
- package/dist/esm/tests/timeout-handlers.test.js +850 -0
- package/dist/esm/tests/timeout-handlers.test.js.map +7 -0
- package/dist/esm/tests/xpath-parser.test.js +317 -0
- package/dist/esm/tests/xpath-parser.test.js.map +7 -0
- package/dist/esm/tests/xpath-resolver.test.js +73 -0
- package/dist/esm/tests/xpath-resolver.test.js.map +7 -0
- package/dist/esm/tests/zod-enum-compatibility.test.js +97 -0
- package/dist/esm/tests/zod-enum-compatibility.test.js.map +7 -0
- package/package.json +37 -24
- package/dist/index.d.ts +0 -4363
- package/dist/index.js +0 -76530
|
@@ -0,0 +1,1572 @@
|
|
|
1
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
2
|
+
var useValue = arguments.length > 2;
|
|
3
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
4
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
5
|
+
}
|
|
6
|
+
return useValue ? value : void 0;
|
|
7
|
+
};
|
|
8
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
9
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
10
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
11
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
12
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
13
|
+
var _, done = false;
|
|
14
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
15
|
+
var context = {};
|
|
16
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
17
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
18
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
19
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
20
|
+
if (kind === "accessor") {
|
|
21
|
+
if (result === void 0) continue;
|
|
22
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
23
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
24
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
25
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
26
|
+
}
|
|
27
|
+
else if (_ = accept(result)) {
|
|
28
|
+
if (kind === "field") initializers.unshift(_);
|
|
29
|
+
else descriptor[key] = _;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
33
|
+
done = true;
|
|
34
|
+
};
|
|
35
|
+
import { EventEmitter } from "events";
|
|
36
|
+
import fs from "fs";
|
|
37
|
+
import os from "os";
|
|
38
|
+
import path from "path";
|
|
39
|
+
import process from "process";
|
|
40
|
+
import { v7 as uuidv7 } from "uuid";
|
|
41
|
+
import { toJsonSchema, } from "./zodCompat.js";
|
|
42
|
+
import { loadApiKeyFromEnv } from "../utils.js";
|
|
43
|
+
import { extractModelName } from "../modelUtils.js";
|
|
44
|
+
import { StagehandLogger } from "../logger.js";
|
|
45
|
+
import { ActCache } from "./cache/ActCache.js";
|
|
46
|
+
import { AgentCache } from "./cache/AgentCache.js";
|
|
47
|
+
import { CacheStorage } from "./cache/CacheStorage.js";
|
|
48
|
+
import { ActHandler } from "./handlers/actHandler.js";
|
|
49
|
+
import { ExtractHandler } from "./handlers/extractHandler.js";
|
|
50
|
+
import { ObserveHandler } from "./handlers/observeHandler.js";
|
|
51
|
+
import { V3AgentHandler } from "./handlers/v3AgentHandler.js";
|
|
52
|
+
import { V3CuaAgentHandler } from "./handlers/v3CuaAgentHandler.js";
|
|
53
|
+
import { createBrowserbaseSession } from "./launch/browserbase.js";
|
|
54
|
+
import { launchLocalChrome } from "./launch/local.js";
|
|
55
|
+
import { LLMProvider } from "./llm/LLMProvider.js";
|
|
56
|
+
import { bindInstanceLogger, unbindInstanceLogger, withInstanceLogContext, } from "./logger.js";
|
|
57
|
+
import { cleanupLocalBrowser } from "./shutdown/cleanupLocal.js";
|
|
58
|
+
import { startShutdownSupervisor } from "./shutdown/supervisorClient.js";
|
|
59
|
+
import { resolveTools } from "./mcp/utils.js";
|
|
60
|
+
import { AVAILABLE_CUA_MODELS, defaultExtractSchema, V3FunctionName, CuaModelRequiredError, StagehandInvalidArgumentError, StagehandNotInitializedError, MissingEnvironmentVariableError, StagehandInitError, } from "./types/public/index.js";
|
|
61
|
+
import { V3Context } from "./understudy/context.js";
|
|
62
|
+
import { resolveModel } from "../modelUtils.js";
|
|
63
|
+
import { StagehandAPIClient } from "./api.js";
|
|
64
|
+
import { validateExperimentalFeatures } from "./agent/utils/validateExperimentalFeatures.js";
|
|
65
|
+
import { SessionFileLogger, logStagehandStep } from "./flowLogger.js";
|
|
66
|
+
import { createTimeoutGuard } from "./handlers/handlerUtils/timeoutGuard.js";
|
|
67
|
+
import { ActTimeoutError } from "./types/public/sdkErrors.js";
|
|
68
|
+
const DEFAULT_MODEL_NAME = "openai/gpt-4.1-mini";
|
|
69
|
+
const DEFAULT_VIEWPORT = { width: 1288, height: 711 };
|
|
70
|
+
function resolveModelConfiguration(model) {
|
|
71
|
+
if (!model) {
|
|
72
|
+
return { modelName: DEFAULT_MODEL_NAME };
|
|
73
|
+
}
|
|
74
|
+
if (typeof model === "string") {
|
|
75
|
+
return { modelName: model };
|
|
76
|
+
}
|
|
77
|
+
if (model && typeof model === "object") {
|
|
78
|
+
const { modelName, ...clientOptions } = model;
|
|
79
|
+
if (!modelName) {
|
|
80
|
+
throw new StagehandInvalidArgumentError("model.modelName is required when providing client options.");
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
modelName,
|
|
84
|
+
clientOptions: clientOptions,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
return { modelName: DEFAULT_MODEL_NAME };
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* V3
|
|
91
|
+
*
|
|
92
|
+
* Purpose:
|
|
93
|
+
* A high-level orchestrator for Stagehand V3. Abstracts away whether the browser
|
|
94
|
+
* runs **locally via Chrome** or remotely on **Browserbase**, and exposes simple
|
|
95
|
+
* entrypoints (`act`, `extract`, `observe`) that delegate to the corresponding
|
|
96
|
+
* handler classes.
|
|
97
|
+
*
|
|
98
|
+
* Responsibilities:
|
|
99
|
+
* - Bootstraps Chrome or Browserbase, ensures a working CDP WebSocket, and builds a `V3Context`.
|
|
100
|
+
* - Manages lifecycle: init, context access, cleanup.
|
|
101
|
+
* - Bridges external page objects (Playwright/Puppeteer) into internal frameIds for handlers.
|
|
102
|
+
* - Provides a stable API surface for downstream code regardless of runtime environment.
|
|
103
|
+
*/
|
|
104
|
+
let V3 = (() => {
|
|
105
|
+
let _instanceExtraInitializers = [];
|
|
106
|
+
let _act_decorators;
|
|
107
|
+
let _extract_decorators;
|
|
108
|
+
let _observe_decorators;
|
|
109
|
+
return class V3 {
|
|
110
|
+
static {
|
|
111
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
112
|
+
_act_decorators = [logStagehandStep("Stagehand.act", "ACT")];
|
|
113
|
+
_extract_decorators = [logStagehandStep("Stagehand.extract", "EXTRACT")];
|
|
114
|
+
_observe_decorators = [logStagehandStep("Stagehand.observe", "OBSERVE")];
|
|
115
|
+
__esDecorate(this, null, _act_decorators, { kind: "method", name: "act", static: false, private: false, access: { has: obj => "act" in obj, get: obj => obj.act }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
116
|
+
__esDecorate(this, null, _extract_decorators, { kind: "method", name: "extract", static: false, private: false, access: { has: obj => "extract" in obj, get: obj => obj.extract }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
117
|
+
__esDecorate(this, null, _observe_decorators, { kind: "method", name: "observe", static: false, private: false, access: { has: obj => "observe" in obj, get: obj => obj.observe }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
118
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
119
|
+
}
|
|
120
|
+
opts = __runInitializers(this, _instanceExtraInitializers);
|
|
121
|
+
state = { kind: "UNINITIALIZED" };
|
|
122
|
+
actHandler = null;
|
|
123
|
+
extractHandler = null;
|
|
124
|
+
observeHandler = null;
|
|
125
|
+
ctx = null;
|
|
126
|
+
llmClient;
|
|
127
|
+
/**
|
|
128
|
+
* Event bus for internal communication.
|
|
129
|
+
* Emits events like 'screenshot' when screenshots are captured during agent execution.
|
|
130
|
+
*/
|
|
131
|
+
bus = new EventEmitter();
|
|
132
|
+
modelName;
|
|
133
|
+
modelClientOptions;
|
|
134
|
+
llmProvider;
|
|
135
|
+
overrideLlmClients = new Map();
|
|
136
|
+
domSettleTimeoutMs;
|
|
137
|
+
_isClosing = false;
|
|
138
|
+
browserbaseSessionId;
|
|
139
|
+
browserbaseSessionUrl;
|
|
140
|
+
browserbaseDebugUrl;
|
|
141
|
+
get browserbaseSessionID() {
|
|
142
|
+
return this.browserbaseSessionId;
|
|
143
|
+
}
|
|
144
|
+
get browserbaseSessionURL() {
|
|
145
|
+
return this.browserbaseSessionUrl;
|
|
146
|
+
}
|
|
147
|
+
get browserbaseDebugURL() {
|
|
148
|
+
return this.browserbaseDebugUrl;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Returns true if the browser is running on Browserbase.
|
|
152
|
+
*/
|
|
153
|
+
get isBrowserbase() {
|
|
154
|
+
return this.state.kind === "BROWSERBASE";
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Returns true if advancedStealth is enabled in Browserbase settings.
|
|
158
|
+
*/
|
|
159
|
+
get isAdvancedStealth() {
|
|
160
|
+
return (this.opts.browserbaseSessionCreateParams?.browserSettings
|
|
161
|
+
?.advancedStealth === true);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Returns the configured viewport dimensions from launch options.
|
|
165
|
+
* Falls back to default 1288x711 if not configured.
|
|
166
|
+
*/
|
|
167
|
+
get configuredViewport() {
|
|
168
|
+
const defaultWidth = 1288;
|
|
169
|
+
const defaultHeight = 711;
|
|
170
|
+
if (this.opts.env === "BROWSERBASE") {
|
|
171
|
+
const vp = this.opts.browserbaseSessionCreateParams?.browserSettings?.viewport;
|
|
172
|
+
return {
|
|
173
|
+
width: vp?.width ?? defaultWidth,
|
|
174
|
+
height: vp?.height ?? defaultHeight,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
// LOCAL env
|
|
178
|
+
const vp = this.opts.localBrowserLaunchOptions?.viewport;
|
|
179
|
+
return {
|
|
180
|
+
width: vp?.width ?? defaultWidth,
|
|
181
|
+
height: vp?.height ?? defaultHeight,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
_onCdpClosed = (why) => {
|
|
185
|
+
if (this.state.kind === "BROWSERBASE") {
|
|
186
|
+
void this._logBrowserbaseSessionStatus();
|
|
187
|
+
}
|
|
188
|
+
// Single place to react to the transport closing
|
|
189
|
+
this._immediateShutdown(`CDP transport closed: ${why}`).catch(() => { });
|
|
190
|
+
};
|
|
191
|
+
experimental = false;
|
|
192
|
+
logInferenceToFile = false;
|
|
193
|
+
disableAPI = false;
|
|
194
|
+
externalLogger;
|
|
195
|
+
verbose = 1;
|
|
196
|
+
stagehandLogger;
|
|
197
|
+
_history = [];
|
|
198
|
+
instanceId;
|
|
199
|
+
static _processGuardsInstalled = false;
|
|
200
|
+
static _instances = new Set();
|
|
201
|
+
cacheStorage;
|
|
202
|
+
actCache;
|
|
203
|
+
agentCache;
|
|
204
|
+
apiClient = null;
|
|
205
|
+
keepAlive;
|
|
206
|
+
shutdownSupervisor = null;
|
|
207
|
+
stagehandMetrics = {
|
|
208
|
+
actPromptTokens: 0,
|
|
209
|
+
actCompletionTokens: 0,
|
|
210
|
+
actReasoningTokens: 0,
|
|
211
|
+
actCachedInputTokens: 0,
|
|
212
|
+
actInferenceTimeMs: 0,
|
|
213
|
+
extractPromptTokens: 0,
|
|
214
|
+
extractCompletionTokens: 0,
|
|
215
|
+
extractReasoningTokens: 0,
|
|
216
|
+
extractCachedInputTokens: 0,
|
|
217
|
+
extractInferenceTimeMs: 0,
|
|
218
|
+
observePromptTokens: 0,
|
|
219
|
+
observeCompletionTokens: 0,
|
|
220
|
+
observeReasoningTokens: 0,
|
|
221
|
+
observeCachedInputTokens: 0,
|
|
222
|
+
observeInferenceTimeMs: 0,
|
|
223
|
+
agentPromptTokens: 0,
|
|
224
|
+
agentCompletionTokens: 0,
|
|
225
|
+
agentReasoningTokens: 0,
|
|
226
|
+
agentCachedInputTokens: 0,
|
|
227
|
+
agentInferenceTimeMs: 0,
|
|
228
|
+
totalPromptTokens: 0,
|
|
229
|
+
totalCompletionTokens: 0,
|
|
230
|
+
totalReasoningTokens: 0,
|
|
231
|
+
totalCachedInputTokens: 0,
|
|
232
|
+
totalInferenceTimeMs: 0,
|
|
233
|
+
};
|
|
234
|
+
constructor(opts) {
|
|
235
|
+
this.externalLogger = opts.logger;
|
|
236
|
+
this.verbose = opts.verbose ?? 1;
|
|
237
|
+
this.instanceId = uuidv7();
|
|
238
|
+
this.keepAlive =
|
|
239
|
+
opts.keepAlive ?? opts.browserbaseSessionCreateParams?.keepAlive;
|
|
240
|
+
// Create per-instance StagehandLogger (handles usePino, verbose, externalLogger)
|
|
241
|
+
// This gives each V3 instance independent logger configuration
|
|
242
|
+
// while still sharing the underlying Pino worker thread via StagehandLogger.sharedPinoLogger
|
|
243
|
+
const loggerOptions = {
|
|
244
|
+
pretty: true,
|
|
245
|
+
level: "info", // Most permissive - filtering happens at instance level
|
|
246
|
+
};
|
|
247
|
+
if (opts.disablePino !== undefined) {
|
|
248
|
+
loggerOptions.usePino = !opts.disablePino;
|
|
249
|
+
}
|
|
250
|
+
this.stagehandLogger = new StagehandLogger(loggerOptions, opts.logger);
|
|
251
|
+
this.stagehandLogger.setVerbosity(this.verbose);
|
|
252
|
+
// Also bind to AsyncLocalStorage for v3Logger() calls from handlers
|
|
253
|
+
// This maintains backward compatibility with code that uses v3Logger() directly
|
|
254
|
+
try {
|
|
255
|
+
if (this.externalLogger) {
|
|
256
|
+
// Use external logger directly when provided
|
|
257
|
+
bindInstanceLogger(this.instanceId, this.externalLogger);
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
// Fall back to stagehandLogger when no external logger
|
|
261
|
+
bindInstanceLogger(this.instanceId, (line) => {
|
|
262
|
+
this.stagehandLogger.log(line);
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
catch {
|
|
267
|
+
// ignore
|
|
268
|
+
}
|
|
269
|
+
const { modelName, clientOptions } = resolveModelConfiguration(opts.model);
|
|
270
|
+
this.modelName = modelName;
|
|
271
|
+
this.experimental = opts.experimental ?? false;
|
|
272
|
+
this.logInferenceToFile = opts.logInferenceToFile ?? false;
|
|
273
|
+
this.llmProvider = new LLMProvider(this.logger);
|
|
274
|
+
this.domSettleTimeoutMs = opts.domSettleTimeout;
|
|
275
|
+
this.disableAPI = opts.disableAPI ?? false;
|
|
276
|
+
const baseClientOptions = clientOptions
|
|
277
|
+
? { ...clientOptions }
|
|
278
|
+
: {};
|
|
279
|
+
if (opts.llmClient) {
|
|
280
|
+
this.llmClient = opts.llmClient;
|
|
281
|
+
this.modelClientOptions = baseClientOptions;
|
|
282
|
+
this.disableAPI = true;
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
// Ensure API key is set
|
|
286
|
+
let apiKey = baseClientOptions.apiKey;
|
|
287
|
+
if (!apiKey) {
|
|
288
|
+
try {
|
|
289
|
+
apiKey = loadApiKeyFromEnv(this.modelName.split("/")[0], // "openai", "anthropic", etc
|
|
290
|
+
this.logger);
|
|
291
|
+
}
|
|
292
|
+
catch (error) {
|
|
293
|
+
this.logger({
|
|
294
|
+
category: "init",
|
|
295
|
+
message: `Error loading API key for model ${this.modelName}: ${error}. Continuing without LLM client.`,
|
|
296
|
+
level: 0,
|
|
297
|
+
});
|
|
298
|
+
throw error;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
this.modelClientOptions = {
|
|
302
|
+
...baseClientOptions,
|
|
303
|
+
apiKey,
|
|
304
|
+
};
|
|
305
|
+
// Get the default client for this model
|
|
306
|
+
this.llmClient = this.llmProvider.getClient(this.modelName, this.modelClientOptions, { experimental: this.experimental, disableAPI: this.disableAPI });
|
|
307
|
+
}
|
|
308
|
+
this.cacheStorage = CacheStorage.create(opts.cacheDir, this.logger, {
|
|
309
|
+
label: "cache directory",
|
|
310
|
+
});
|
|
311
|
+
this.actCache = new ActCache({
|
|
312
|
+
storage: this.cacheStorage,
|
|
313
|
+
logger: this.logger,
|
|
314
|
+
getActHandler: () => this.actHandler,
|
|
315
|
+
getDefaultLlmClient: () => this.resolveLlmClient(),
|
|
316
|
+
domSettleTimeoutMs: this.domSettleTimeoutMs,
|
|
317
|
+
});
|
|
318
|
+
this.agentCache = new AgentCache({
|
|
319
|
+
storage: this.cacheStorage,
|
|
320
|
+
logger: this.logger,
|
|
321
|
+
getActHandler: () => this.actHandler,
|
|
322
|
+
getContext: () => this.ctx,
|
|
323
|
+
getDefaultLlmClient: () => this.resolveLlmClient(),
|
|
324
|
+
getBaseModelName: () => this.modelName,
|
|
325
|
+
getSystemPrompt: () => opts.systemPrompt,
|
|
326
|
+
domSettleTimeoutMs: this.domSettleTimeoutMs,
|
|
327
|
+
act: this.act.bind(this),
|
|
328
|
+
});
|
|
329
|
+
this.opts = opts;
|
|
330
|
+
// Initialize session file logger
|
|
331
|
+
SessionFileLogger.init(this.instanceId, opts);
|
|
332
|
+
// Track instance for global process guard handling
|
|
333
|
+
V3._instances.add(this);
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Async property for metrics so callers can `await v3.metrics`.
|
|
337
|
+
* When using API mode, fetches metrics from the API. Otherwise returns local metrics.
|
|
338
|
+
*/
|
|
339
|
+
get metrics() {
|
|
340
|
+
if (this.apiClient) {
|
|
341
|
+
// Fetch metrics from the API
|
|
342
|
+
return this.apiClient.getReplayMetrics().catch((error) => {
|
|
343
|
+
this.logger({
|
|
344
|
+
category: "metrics",
|
|
345
|
+
message: `Failed to fetch metrics from API: ${error}`,
|
|
346
|
+
level: 0,
|
|
347
|
+
});
|
|
348
|
+
// Fall back to local metrics on error
|
|
349
|
+
return this.stagehandMetrics;
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
// Return local metrics wrapped in a Promise for consistency
|
|
353
|
+
return Promise.resolve(this.stagehandMetrics);
|
|
354
|
+
}
|
|
355
|
+
resolveLlmClient(model) {
|
|
356
|
+
if (!model) {
|
|
357
|
+
return this.llmClient;
|
|
358
|
+
}
|
|
359
|
+
let modelName;
|
|
360
|
+
let clientOptions;
|
|
361
|
+
if (typeof model === "string") {
|
|
362
|
+
modelName = model;
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
const { modelName: overrideModelName, ...rest } = model;
|
|
366
|
+
modelName = overrideModelName;
|
|
367
|
+
clientOptions = rest;
|
|
368
|
+
}
|
|
369
|
+
if (modelName === this.modelName &&
|
|
370
|
+
(!clientOptions || Object.keys(clientOptions).length === 0)) {
|
|
371
|
+
return this.llmClient;
|
|
372
|
+
}
|
|
373
|
+
const overrideProvider = String(modelName).split("/")[0];
|
|
374
|
+
const baseProvider = String(this.modelName).split("/")[0];
|
|
375
|
+
const mergedOptions = {
|
|
376
|
+
...(overrideProvider === baseProvider ? this.modelClientOptions : {}),
|
|
377
|
+
...(clientOptions ?? {}),
|
|
378
|
+
};
|
|
379
|
+
const providerKey = overrideProvider;
|
|
380
|
+
if (!mergedOptions.apiKey) {
|
|
381
|
+
const apiKey = loadApiKeyFromEnv(providerKey, this.logger);
|
|
382
|
+
if (apiKey) {
|
|
383
|
+
mergedOptions.apiKey = apiKey;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
const cacheKey = JSON.stringify({
|
|
387
|
+
modelName,
|
|
388
|
+
clientOptions: mergedOptions,
|
|
389
|
+
});
|
|
390
|
+
const cached = this.overrideLlmClients.get(cacheKey);
|
|
391
|
+
if (cached) {
|
|
392
|
+
return cached;
|
|
393
|
+
}
|
|
394
|
+
const client = this.llmProvider.getClient(modelName, mergedOptions, { experimental: this.experimental, disableAPI: this.disableAPI });
|
|
395
|
+
this.overrideLlmClients.set(cacheKey, client);
|
|
396
|
+
return client;
|
|
397
|
+
}
|
|
398
|
+
beginAgentReplayRecording() {
|
|
399
|
+
this.agentCache.beginRecording();
|
|
400
|
+
}
|
|
401
|
+
endAgentReplayRecording() {
|
|
402
|
+
return this.agentCache.endRecording();
|
|
403
|
+
}
|
|
404
|
+
discardAgentReplayRecording() {
|
|
405
|
+
this.agentCache.discardRecording();
|
|
406
|
+
}
|
|
407
|
+
isAgentReplayRecording() {
|
|
408
|
+
return this.agentCache.isRecording();
|
|
409
|
+
}
|
|
410
|
+
isAgentReplayActive() {
|
|
411
|
+
return this.agentCache.isReplayActive();
|
|
412
|
+
}
|
|
413
|
+
recordAgentReplayStep(step) {
|
|
414
|
+
this.agentCache.recordStep(step);
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Async property for history so callers can `await v3.history`.
|
|
418
|
+
* Returns a frozen copy to avoid external mutation.
|
|
419
|
+
*/
|
|
420
|
+
get history() {
|
|
421
|
+
return Promise.resolve(Object.freeze([...this._history]));
|
|
422
|
+
}
|
|
423
|
+
addToHistory(method, parameters, result) {
|
|
424
|
+
this._history.push({
|
|
425
|
+
method,
|
|
426
|
+
parameters,
|
|
427
|
+
result: result ?? null,
|
|
428
|
+
timestamp: new Date().toISOString(),
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
updateMetrics(functionName, promptTokens, completionTokens, reasoningTokens, cachedInputTokens, inferenceTimeMs) {
|
|
432
|
+
switch (functionName) {
|
|
433
|
+
case V3FunctionName.ACT:
|
|
434
|
+
this.stagehandMetrics.actPromptTokens += promptTokens;
|
|
435
|
+
this.stagehandMetrics.actCompletionTokens += completionTokens;
|
|
436
|
+
this.stagehandMetrics.actReasoningTokens += reasoningTokens;
|
|
437
|
+
this.stagehandMetrics.actCachedInputTokens += cachedInputTokens;
|
|
438
|
+
this.stagehandMetrics.actInferenceTimeMs += inferenceTimeMs;
|
|
439
|
+
break;
|
|
440
|
+
case V3FunctionName.EXTRACT:
|
|
441
|
+
this.stagehandMetrics.extractPromptTokens += promptTokens;
|
|
442
|
+
this.stagehandMetrics.extractCompletionTokens += completionTokens;
|
|
443
|
+
this.stagehandMetrics.extractReasoningTokens += reasoningTokens;
|
|
444
|
+
this.stagehandMetrics.extractCachedInputTokens += cachedInputTokens;
|
|
445
|
+
this.stagehandMetrics.extractInferenceTimeMs += inferenceTimeMs;
|
|
446
|
+
break;
|
|
447
|
+
case V3FunctionName.OBSERVE:
|
|
448
|
+
this.stagehandMetrics.observePromptTokens += promptTokens;
|
|
449
|
+
this.stagehandMetrics.observeCompletionTokens += completionTokens;
|
|
450
|
+
this.stagehandMetrics.observeReasoningTokens += reasoningTokens;
|
|
451
|
+
this.stagehandMetrics.observeCachedInputTokens += cachedInputTokens;
|
|
452
|
+
this.stagehandMetrics.observeInferenceTimeMs += inferenceTimeMs;
|
|
453
|
+
break;
|
|
454
|
+
case V3FunctionName.AGENT:
|
|
455
|
+
this.stagehandMetrics.agentPromptTokens += promptTokens;
|
|
456
|
+
this.stagehandMetrics.agentCompletionTokens += completionTokens;
|
|
457
|
+
this.stagehandMetrics.agentReasoningTokens += reasoningTokens;
|
|
458
|
+
this.stagehandMetrics.agentCachedInputTokens += cachedInputTokens;
|
|
459
|
+
this.stagehandMetrics.agentInferenceTimeMs += inferenceTimeMs;
|
|
460
|
+
break;
|
|
461
|
+
}
|
|
462
|
+
this.updateTotalMetrics(promptTokens, completionTokens, reasoningTokens, cachedInputTokens, inferenceTimeMs);
|
|
463
|
+
}
|
|
464
|
+
updateTotalMetrics(promptTokens, completionTokens, reasoningTokens, cachedInputTokens, inferenceTimeMs) {
|
|
465
|
+
this.stagehandMetrics.totalPromptTokens += promptTokens;
|
|
466
|
+
this.stagehandMetrics.totalCompletionTokens += completionTokens;
|
|
467
|
+
this.stagehandMetrics.totalReasoningTokens += reasoningTokens;
|
|
468
|
+
this.stagehandMetrics.totalCachedInputTokens += cachedInputTokens;
|
|
469
|
+
this.stagehandMetrics.totalInferenceTimeMs += inferenceTimeMs;
|
|
470
|
+
}
|
|
471
|
+
async _immediateShutdown(reason) {
|
|
472
|
+
try {
|
|
473
|
+
this.logger({
|
|
474
|
+
category: "v3",
|
|
475
|
+
message: `initiating shutdown → ${reason}`,
|
|
476
|
+
level: 0,
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
catch {
|
|
480
|
+
//
|
|
481
|
+
}
|
|
482
|
+
try {
|
|
483
|
+
this.logger({
|
|
484
|
+
category: "v3",
|
|
485
|
+
message: `closing resources → ${reason}`,
|
|
486
|
+
level: 0,
|
|
487
|
+
});
|
|
488
|
+
await this.close({ force: true });
|
|
489
|
+
}
|
|
490
|
+
catch {
|
|
491
|
+
// swallow — already shutting down
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
/** Spawn a crash-only supervisor that cleans up when this process dies. */
|
|
495
|
+
startShutdownSupervisor(config) {
|
|
496
|
+
if (this.shutdownSupervisor)
|
|
497
|
+
return this.shutdownSupervisor;
|
|
498
|
+
this.shutdownSupervisor = startShutdownSupervisor(config, {
|
|
499
|
+
onError: (error, context) => {
|
|
500
|
+
try {
|
|
501
|
+
this.logger({
|
|
502
|
+
category: "v3",
|
|
503
|
+
message: "Shutdown supervisor unavailable; crash cleanup disabled. " +
|
|
504
|
+
"If this process exits unexpectedly, local Chrome or Browserbase " +
|
|
505
|
+
"sessions may remain running even with keepAlive=false.",
|
|
506
|
+
level: 0,
|
|
507
|
+
auxiliary: {
|
|
508
|
+
context: { value: context, type: "string" },
|
|
509
|
+
error: { value: error.message, type: "string" },
|
|
510
|
+
},
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
catch {
|
|
514
|
+
// ignore logging failures
|
|
515
|
+
}
|
|
516
|
+
},
|
|
517
|
+
});
|
|
518
|
+
return this.shutdownSupervisor;
|
|
519
|
+
}
|
|
520
|
+
/** Stop the supervisor during a normal shutdown. */
|
|
521
|
+
stopShutdownSupervisor() {
|
|
522
|
+
if (!this.shutdownSupervisor)
|
|
523
|
+
return;
|
|
524
|
+
try {
|
|
525
|
+
this.shutdownSupervisor.stop();
|
|
526
|
+
}
|
|
527
|
+
catch {
|
|
528
|
+
// best-effort
|
|
529
|
+
}
|
|
530
|
+
this.shutdownSupervisor = null;
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Entrypoint: initializes handlers, launches Chrome or Browserbase,
|
|
534
|
+
* and sets up a CDP context.
|
|
535
|
+
*/
|
|
536
|
+
async init() {
|
|
537
|
+
try {
|
|
538
|
+
return await withInstanceLogContext(this.instanceId, async () => {
|
|
539
|
+
this.actHandler = new ActHandler(this.llmClient, this.modelName, this.modelClientOptions, (model) => this.resolveLlmClient(model), this.opts.systemPrompt ?? "", this.logInferenceToFile, this.opts.selfHeal ?? true, (functionName, promptTokens, completionTokens, reasoningTokens, cachedInputTokens, inferenceTimeMs) => this.updateMetrics(functionName, promptTokens, completionTokens, reasoningTokens, cachedInputTokens, inferenceTimeMs), this.domSettleTimeoutMs);
|
|
540
|
+
this.extractHandler = new ExtractHandler(this.llmClient, this.modelName, this.modelClientOptions, (model) => this.resolveLlmClient(model), this.opts.systemPrompt ?? "", this.logInferenceToFile, this.experimental, (functionName, promptTokens, completionTokens, reasoningTokens, cachedInputTokens, inferenceTimeMs) => this.updateMetrics(functionName, promptTokens, completionTokens, reasoningTokens, cachedInputTokens, inferenceTimeMs));
|
|
541
|
+
this.observeHandler = new ObserveHandler(this.llmClient, this.modelName, this.modelClientOptions, (model) => this.resolveLlmClient(model), this.opts.systemPrompt ?? "", this.logInferenceToFile, this.experimental, (functionName, promptTokens, completionTokens, reasoningTokens, cachedInputTokens, inferenceTimeMs) => this.updateMetrics(functionName, promptTokens, completionTokens, reasoningTokens, cachedInputTokens, inferenceTimeMs));
|
|
542
|
+
if (this.opts.env === "LOCAL") {
|
|
543
|
+
// chrome-launcher conditionally adds --headless when the environment variable
|
|
544
|
+
// HEADLESS is set, without parsing its value.
|
|
545
|
+
// if it is not equal to true, then we delete it from the process
|
|
546
|
+
const envHeadless = process.env.HEADLESS;
|
|
547
|
+
if (envHeadless !== undefined) {
|
|
548
|
+
const normalized = envHeadless.trim().toLowerCase();
|
|
549
|
+
if (normalized !== "true") {
|
|
550
|
+
delete process.env.HEADLESS;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
const lbo = this.opts.localBrowserLaunchOptions ?? {};
|
|
554
|
+
// If a CDP URL is provided, attach instead of launching.
|
|
555
|
+
if (lbo.cdpUrl) {
|
|
556
|
+
this.logger({
|
|
557
|
+
category: "init",
|
|
558
|
+
message: "Connecting to local browser",
|
|
559
|
+
level: 1,
|
|
560
|
+
});
|
|
561
|
+
this.ctx = await V3Context.create(lbo.cdpUrl, {
|
|
562
|
+
env: "LOCAL",
|
|
563
|
+
});
|
|
564
|
+
const logCtx = SessionFileLogger.getContext();
|
|
565
|
+
this.ctx.conn.cdpLogger = (info) => SessionFileLogger.logCdpCallEvent(info, logCtx);
|
|
566
|
+
this.ctx.conn.cdpEventLogger = (info) => SessionFileLogger.logCdpMessageEvent(info, logCtx);
|
|
567
|
+
this.ctx.conn.onTransportClosed(this._onCdpClosed);
|
|
568
|
+
this.state = {
|
|
569
|
+
kind: "LOCAL",
|
|
570
|
+
// no LaunchedChrome when attaching externally; create a stub kill
|
|
571
|
+
chrome: {
|
|
572
|
+
kill: async () => { },
|
|
573
|
+
},
|
|
574
|
+
ws: lbo.cdpUrl,
|
|
575
|
+
};
|
|
576
|
+
this.resetBrowserbaseSessionMetadata();
|
|
577
|
+
// Post-connect settings (downloads and viewport) if provided
|
|
578
|
+
await this._applyPostConnectLocalOptions(lbo);
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
581
|
+
this.logger({
|
|
582
|
+
category: "init",
|
|
583
|
+
message: "Launching local browser",
|
|
584
|
+
level: 1,
|
|
585
|
+
});
|
|
586
|
+
// Determine or create user data dir
|
|
587
|
+
let userDataDir = lbo.userDataDir;
|
|
588
|
+
let createdTemp = false;
|
|
589
|
+
if (!userDataDir) {
|
|
590
|
+
const base = path.join(os.tmpdir(), "stagehand-v3");
|
|
591
|
+
fs.mkdirSync(base, { recursive: true });
|
|
592
|
+
userDataDir = fs.mkdtempSync(path.join(base, "profile-"));
|
|
593
|
+
createdTemp = true;
|
|
594
|
+
}
|
|
595
|
+
// Build chrome flags
|
|
596
|
+
const defaults = [
|
|
597
|
+
"--remote-allow-origins=*",
|
|
598
|
+
"--no-first-run",
|
|
599
|
+
"--no-default-browser-check",
|
|
600
|
+
"--disable-dev-shm-usage",
|
|
601
|
+
"--site-per-process",
|
|
602
|
+
];
|
|
603
|
+
let chromeFlags = [];
|
|
604
|
+
const ignore = lbo.ignoreDefaultArgs;
|
|
605
|
+
if (ignore === true) {
|
|
606
|
+
// drop defaults
|
|
607
|
+
chromeFlags = [];
|
|
608
|
+
}
|
|
609
|
+
else if (Array.isArray(ignore)) {
|
|
610
|
+
chromeFlags = defaults.filter((f) => !ignore.some((ex) => f.includes(ex)));
|
|
611
|
+
}
|
|
612
|
+
else {
|
|
613
|
+
chromeFlags = [...defaults];
|
|
614
|
+
}
|
|
615
|
+
// headless handled by launchLocalChrome
|
|
616
|
+
if (lbo.devtools)
|
|
617
|
+
chromeFlags.push("--auto-open-devtools-for-tabs");
|
|
618
|
+
if (lbo.locale)
|
|
619
|
+
chromeFlags.push(`--lang=${lbo.locale}`);
|
|
620
|
+
if (!lbo.viewport) {
|
|
621
|
+
lbo.viewport = DEFAULT_VIEWPORT;
|
|
622
|
+
}
|
|
623
|
+
if (lbo.viewport?.width && lbo.viewport?.height) {
|
|
624
|
+
chromeFlags.push(`--window-size=${lbo.viewport.width},${lbo.viewport.height + 87}`);
|
|
625
|
+
}
|
|
626
|
+
if (typeof lbo.deviceScaleFactor === "number") {
|
|
627
|
+
chromeFlags.push(`--force-device-scale-factor=${Math.max(0.1, lbo.deviceScaleFactor)}`);
|
|
628
|
+
}
|
|
629
|
+
if (lbo.hasTouch)
|
|
630
|
+
chromeFlags.push("--touch-events=enabled");
|
|
631
|
+
if (lbo.ignoreHTTPSErrors)
|
|
632
|
+
chromeFlags.push("--ignore-certificate-errors");
|
|
633
|
+
if (lbo.proxy?.server)
|
|
634
|
+
chromeFlags.push(`--proxy-server=${lbo.proxy.server}`);
|
|
635
|
+
if (lbo.proxy?.bypass)
|
|
636
|
+
chromeFlags.push(`--proxy-bypass-list=${lbo.proxy.bypass}`);
|
|
637
|
+
// add user-supplied args last
|
|
638
|
+
if (Array.isArray(lbo.args))
|
|
639
|
+
chromeFlags.push(...lbo.args);
|
|
640
|
+
const keepAlive = this.keepAlive === true;
|
|
641
|
+
const { ws, chrome } = await launchLocalChrome({
|
|
642
|
+
chromePath: lbo.executablePath,
|
|
643
|
+
chromeFlags,
|
|
644
|
+
port: lbo.port,
|
|
645
|
+
headless: lbo.headless,
|
|
646
|
+
userDataDir,
|
|
647
|
+
connectTimeoutMs: lbo.connectTimeoutMs,
|
|
648
|
+
handleSIGINT: !keepAlive,
|
|
649
|
+
});
|
|
650
|
+
if (keepAlive) {
|
|
651
|
+
try {
|
|
652
|
+
chrome.process?.unref?.();
|
|
653
|
+
}
|
|
654
|
+
catch {
|
|
655
|
+
// best-effort: avoid keeping the event loop alive
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
this.ctx = await V3Context.create(ws, {
|
|
659
|
+
env: "LOCAL",
|
|
660
|
+
localBrowserLaunchOptions: lbo,
|
|
661
|
+
});
|
|
662
|
+
const logCtx = SessionFileLogger.getContext();
|
|
663
|
+
this.ctx.conn.cdpLogger = (info) => SessionFileLogger.logCdpCallEvent(info, logCtx);
|
|
664
|
+
this.ctx.conn.cdpEventLogger = (info) => SessionFileLogger.logCdpMessageEvent(info, logCtx);
|
|
665
|
+
this.ctx.conn.onTransportClosed(this._onCdpClosed);
|
|
666
|
+
this.state = {
|
|
667
|
+
kind: "LOCAL",
|
|
668
|
+
chrome,
|
|
669
|
+
ws,
|
|
670
|
+
userDataDir,
|
|
671
|
+
createdTempProfile: createdTemp,
|
|
672
|
+
preserveUserDataDir: !!lbo.preserveUserDataDir,
|
|
673
|
+
};
|
|
674
|
+
this.resetBrowserbaseSessionMetadata();
|
|
675
|
+
const chromePid = chrome.process?.pid ?? chrome.pid;
|
|
676
|
+
if (!keepAlive && chromePid) {
|
|
677
|
+
const supervisor = this.startShutdownSupervisor({
|
|
678
|
+
kind: "LOCAL",
|
|
679
|
+
keepAlive: false,
|
|
680
|
+
pid: chromePid,
|
|
681
|
+
userDataDir,
|
|
682
|
+
createdTempProfile: createdTemp,
|
|
683
|
+
preserveUserDataDir: !!lbo.preserveUserDataDir,
|
|
684
|
+
});
|
|
685
|
+
await supervisor?.ready;
|
|
686
|
+
}
|
|
687
|
+
// Post-connect settings (downloads and viewport) if provided
|
|
688
|
+
await this._applyPostConnectLocalOptions(lbo);
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
691
|
+
if (this.opts.env === "BROWSERBASE") {
|
|
692
|
+
const { apiKey, projectId } = this.requireBrowserbaseCreds();
|
|
693
|
+
if (!apiKey || !projectId) {
|
|
694
|
+
throw new MissingEnvironmentVariableError("BROWSERBASE_API_KEY and BROWSERBASE_PROJECT_ID", "Browserbase environment");
|
|
695
|
+
}
|
|
696
|
+
this.logger({
|
|
697
|
+
category: "init",
|
|
698
|
+
message: "Starting browserbase session",
|
|
699
|
+
level: 1,
|
|
700
|
+
});
|
|
701
|
+
const baseSessionParams = this.opts.browserbaseSessionCreateParams ?? {};
|
|
702
|
+
const resolvedKeepAlive = this.keepAlive;
|
|
703
|
+
const keepAlive = this.keepAlive === true;
|
|
704
|
+
const effectiveSessionParams = resolvedKeepAlive !== undefined
|
|
705
|
+
? { ...baseSessionParams, keepAlive: resolvedKeepAlive }
|
|
706
|
+
: baseSessionParams;
|
|
707
|
+
if (!this.disableAPI && !this.experimental) {
|
|
708
|
+
this.apiClient = new StagehandAPIClient({
|
|
709
|
+
apiKey,
|
|
710
|
+
projectId,
|
|
711
|
+
logger: this.logger,
|
|
712
|
+
});
|
|
713
|
+
const createSessionPayload = {
|
|
714
|
+
projectId: effectiveSessionParams.projectId ?? projectId,
|
|
715
|
+
...effectiveSessionParams,
|
|
716
|
+
browserSettings: {
|
|
717
|
+
...(effectiveSessionParams.browserSettings ?? {}),
|
|
718
|
+
viewport: effectiveSessionParams.browserSettings?.viewport ?? {
|
|
719
|
+
width: 1288,
|
|
720
|
+
height: 711,
|
|
721
|
+
},
|
|
722
|
+
},
|
|
723
|
+
userMetadata: {
|
|
724
|
+
...(effectiveSessionParams.userMetadata ?? {}),
|
|
725
|
+
stagehand: "true",
|
|
726
|
+
},
|
|
727
|
+
};
|
|
728
|
+
const { sessionId, available } = await this.apiClient.init({
|
|
729
|
+
modelName: this.modelName,
|
|
730
|
+
modelApiKey: this.modelClientOptions.apiKey,
|
|
731
|
+
domSettleTimeoutMs: this.domSettleTimeoutMs,
|
|
732
|
+
verbose: this.verbose,
|
|
733
|
+
systemPrompt: this.opts.systemPrompt,
|
|
734
|
+
selfHeal: this.opts.selfHeal,
|
|
735
|
+
browserbaseSessionCreateParams: createSessionPayload,
|
|
736
|
+
browserbaseSessionID: this.opts.browserbaseSessionID,
|
|
737
|
+
});
|
|
738
|
+
if (!available) {
|
|
739
|
+
this.apiClient = null;
|
|
740
|
+
}
|
|
741
|
+
this.opts.browserbaseSessionID = sessionId;
|
|
742
|
+
}
|
|
743
|
+
const { ws, sessionId, bb } = await createBrowserbaseSession(apiKey, projectId, effectiveSessionParams, this.opts.browserbaseSessionID);
|
|
744
|
+
this.ctx = await V3Context.create(ws, {
|
|
745
|
+
env: "BROWSERBASE",
|
|
746
|
+
apiClient: this.apiClient,
|
|
747
|
+
});
|
|
748
|
+
const logCtx = SessionFileLogger.getContext();
|
|
749
|
+
this.ctx.conn.cdpLogger = (info) => SessionFileLogger.logCdpCallEvent(info, logCtx);
|
|
750
|
+
this.ctx.conn.cdpEventLogger = (info) => SessionFileLogger.logCdpMessageEvent(info, logCtx);
|
|
751
|
+
this.ctx.conn.onTransportClosed(this._onCdpClosed);
|
|
752
|
+
this.state = { kind: "BROWSERBASE", sessionId, ws, bb };
|
|
753
|
+
this.browserbaseSessionId = sessionId;
|
|
754
|
+
if (!keepAlive && !this.disableAPI) {
|
|
755
|
+
const supervisor = this.startShutdownSupervisor({
|
|
756
|
+
kind: "STAGEHAND_API",
|
|
757
|
+
keepAlive: false,
|
|
758
|
+
sessionId,
|
|
759
|
+
apiKey,
|
|
760
|
+
projectId,
|
|
761
|
+
});
|
|
762
|
+
await supervisor?.ready;
|
|
763
|
+
}
|
|
764
|
+
await this._ensureBrowserbaseDownloadsEnabled();
|
|
765
|
+
const resumed = !!this.opts.browserbaseSessionID;
|
|
766
|
+
let debugUrl;
|
|
767
|
+
try {
|
|
768
|
+
const dbg = (await bb.sessions.debug(sessionId));
|
|
769
|
+
debugUrl = dbg?.debuggerUrl;
|
|
770
|
+
}
|
|
771
|
+
catch {
|
|
772
|
+
// Ignore debug fetch failures; continue with sessionUrl only
|
|
773
|
+
}
|
|
774
|
+
const sessionUrl = `https://www.browserbase.com/sessions/${sessionId}`;
|
|
775
|
+
this.browserbaseSessionUrl = sessionUrl;
|
|
776
|
+
this.browserbaseDebugUrl = debugUrl;
|
|
777
|
+
try {
|
|
778
|
+
this.logger({
|
|
779
|
+
category: "init",
|
|
780
|
+
message: resumed
|
|
781
|
+
? this.apiClient
|
|
782
|
+
? "Browserbase session started"
|
|
783
|
+
: "Browserbase session resumed"
|
|
784
|
+
: "Browserbase session started",
|
|
785
|
+
level: 1,
|
|
786
|
+
auxiliary: {
|
|
787
|
+
sessionUrl: { value: sessionUrl, type: "string" },
|
|
788
|
+
...(debugUrl && {
|
|
789
|
+
debugUrl: { value: debugUrl, type: "string" },
|
|
790
|
+
}),
|
|
791
|
+
sessionId: { value: sessionId, type: "string" },
|
|
792
|
+
},
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
catch {
|
|
796
|
+
// best-effort logging — ignore failures
|
|
797
|
+
}
|
|
798
|
+
return;
|
|
799
|
+
}
|
|
800
|
+
const neverEnv = this.opts.env;
|
|
801
|
+
throw new StagehandInitError(`Unsupported env: ${neverEnv}`);
|
|
802
|
+
});
|
|
803
|
+
}
|
|
804
|
+
catch (error) {
|
|
805
|
+
// Cleanup instanceLoggers map on init failure to prevent memory leak
|
|
806
|
+
if (this.externalLogger) {
|
|
807
|
+
try {
|
|
808
|
+
unbindInstanceLogger(this.instanceId);
|
|
809
|
+
}
|
|
810
|
+
catch {
|
|
811
|
+
// ignore cleanup errors
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
throw error;
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
/** Apply post-connect local browser options that require CDP. */
|
|
818
|
+
async _applyPostConnectLocalOptions(lbo) {
|
|
819
|
+
try {
|
|
820
|
+
// Downloads behavior
|
|
821
|
+
if (lbo.downloadsPath || lbo.acceptDownloads !== undefined) {
|
|
822
|
+
const behavior = lbo.acceptDownloads === false ? "deny" : "allow";
|
|
823
|
+
await this.ctx?.conn
|
|
824
|
+
.send("Browser.setDownloadBehavior", {
|
|
825
|
+
behavior,
|
|
826
|
+
downloadPath: lbo.downloadsPath,
|
|
827
|
+
eventsEnabled: true,
|
|
828
|
+
})
|
|
829
|
+
.catch(() => { });
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
catch {
|
|
833
|
+
// best-effort only
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
async _ensureBrowserbaseDownloadsEnabled() {
|
|
837
|
+
const conn = this.ctx?.conn;
|
|
838
|
+
if (!conn)
|
|
839
|
+
return;
|
|
840
|
+
try {
|
|
841
|
+
await conn.send("Browser.setDownloadBehavior", {
|
|
842
|
+
behavior: "allow",
|
|
843
|
+
downloadPath: "downloads",
|
|
844
|
+
eventsEnabled: true,
|
|
845
|
+
});
|
|
846
|
+
}
|
|
847
|
+
catch {
|
|
848
|
+
// best-effort only
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
resetBrowserbaseSessionMetadata() {
|
|
852
|
+
this.browserbaseSessionId = undefined;
|
|
853
|
+
this.browserbaseSessionUrl = undefined;
|
|
854
|
+
this.browserbaseDebugUrl = undefined;
|
|
855
|
+
}
|
|
856
|
+
async act(input, options) {
|
|
857
|
+
return await withInstanceLogContext(this.instanceId, async () => {
|
|
858
|
+
if (!this.actHandler)
|
|
859
|
+
throw new StagehandNotInitializedError("act()");
|
|
860
|
+
let actResult;
|
|
861
|
+
if (isObserveResult(input)) {
|
|
862
|
+
// Resolve page: use provided page if any, otherwise default active page
|
|
863
|
+
const v3Page = await this.resolvePage(options?.page);
|
|
864
|
+
// Use selector as provided to support XPath, CSS, and other engines
|
|
865
|
+
const selector = input.selector;
|
|
866
|
+
if (this.apiClient) {
|
|
867
|
+
actResult = await this.apiClient.act({
|
|
868
|
+
input,
|
|
869
|
+
options,
|
|
870
|
+
frameId: v3Page.mainFrameId(),
|
|
871
|
+
});
|
|
872
|
+
}
|
|
873
|
+
else {
|
|
874
|
+
const effectiveTimeoutMs = typeof options?.timeout === "number" && options.timeout > 0
|
|
875
|
+
? options.timeout
|
|
876
|
+
: undefined;
|
|
877
|
+
const ensureTimeRemaining = createTimeoutGuard(effectiveTimeoutMs, (ms) => new ActTimeoutError(ms));
|
|
878
|
+
actResult = await this.actHandler.takeDeterministicAction({ ...input, selector }, v3Page, this.domSettleTimeoutMs, this.resolveLlmClient(options?.model), ensureTimeRemaining, options?.variables);
|
|
879
|
+
}
|
|
880
|
+
// history: record ObserveResult-based act call
|
|
881
|
+
this.addToHistory("act", {
|
|
882
|
+
observeResult: input,
|
|
883
|
+
}, actResult);
|
|
884
|
+
return actResult;
|
|
885
|
+
}
|
|
886
|
+
// instruction path
|
|
887
|
+
if (typeof input !== "string" || !input.trim()) {
|
|
888
|
+
throw new StagehandInvalidArgumentError("act(): instruction string is required unless passing an Action");
|
|
889
|
+
}
|
|
890
|
+
// Resolve page from options or default
|
|
891
|
+
const page = await this.resolvePage(options?.page);
|
|
892
|
+
const actCacheLlmClient = options?.model
|
|
893
|
+
? this.resolveLlmClient(options.model)
|
|
894
|
+
: undefined;
|
|
895
|
+
let actCacheContext = null;
|
|
896
|
+
const canUseCache = typeof input === "string" &&
|
|
897
|
+
!this.isAgentReplayRecording() &&
|
|
898
|
+
this.actCache.enabled;
|
|
899
|
+
if (canUseCache) {
|
|
900
|
+
actCacheContext = await this.actCache.prepareContext(input, page, options?.variables);
|
|
901
|
+
if (actCacheContext) {
|
|
902
|
+
const cachedResult = await this.actCache.tryReplay(actCacheContext, page, options?.timeout, actCacheLlmClient);
|
|
903
|
+
if (cachedResult) {
|
|
904
|
+
this.addToHistory("act", {
|
|
905
|
+
instruction: input,
|
|
906
|
+
variables: options?.variables,
|
|
907
|
+
timeout: options?.timeout,
|
|
908
|
+
cacheHit: true,
|
|
909
|
+
}, cachedResult);
|
|
910
|
+
return cachedResult;
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
const handlerParams = {
|
|
915
|
+
instruction: input,
|
|
916
|
+
page,
|
|
917
|
+
variables: options?.variables,
|
|
918
|
+
timeout: options?.timeout,
|
|
919
|
+
model: options?.model,
|
|
920
|
+
};
|
|
921
|
+
if (this.apiClient) {
|
|
922
|
+
const frameId = page.mainFrameId();
|
|
923
|
+
actResult = await this.apiClient.act({ input, options, frameId });
|
|
924
|
+
}
|
|
925
|
+
else {
|
|
926
|
+
actResult = await this.actHandler.act(handlerParams);
|
|
927
|
+
}
|
|
928
|
+
// history: record instruction-based act call (omit page object)
|
|
929
|
+
this.addToHistory("act", {
|
|
930
|
+
instruction: input,
|
|
931
|
+
variables: options?.variables,
|
|
932
|
+
timeout: options?.timeout,
|
|
933
|
+
}, actResult);
|
|
934
|
+
if (actCacheContext &&
|
|
935
|
+
actResult.success &&
|
|
936
|
+
Array.isArray(actResult.actions) &&
|
|
937
|
+
actResult.actions.length > 0) {
|
|
938
|
+
await this.actCache.store(actCacheContext, actResult);
|
|
939
|
+
}
|
|
940
|
+
return actResult;
|
|
941
|
+
});
|
|
942
|
+
}
|
|
943
|
+
async extract(a, b, c) {
|
|
944
|
+
return await withInstanceLogContext(this.instanceId, async () => {
|
|
945
|
+
if (!this.extractHandler) {
|
|
946
|
+
throw new StagehandNotInitializedError("extract()");
|
|
947
|
+
}
|
|
948
|
+
// Normalize args
|
|
949
|
+
let instruction;
|
|
950
|
+
let schema;
|
|
951
|
+
let options;
|
|
952
|
+
if (typeof a === "string") {
|
|
953
|
+
instruction = a;
|
|
954
|
+
const isZodSchema = (val) => !!val &&
|
|
955
|
+
typeof val === "object" &&
|
|
956
|
+
"parse" in val &&
|
|
957
|
+
"safeParse" in val;
|
|
958
|
+
if (isZodSchema(b)) {
|
|
959
|
+
schema = b;
|
|
960
|
+
options = c;
|
|
961
|
+
}
|
|
962
|
+
else {
|
|
963
|
+
options = b;
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
else {
|
|
967
|
+
// a is options or undefined
|
|
968
|
+
options = a || undefined;
|
|
969
|
+
}
|
|
970
|
+
if (!instruction && schema) {
|
|
971
|
+
throw new StagehandInvalidArgumentError("extract(): schema provided without instruction");
|
|
972
|
+
}
|
|
973
|
+
// If instruction without schema → defaultExtractSchema
|
|
974
|
+
const effectiveSchema = instruction && !schema ? defaultExtractSchema : schema;
|
|
975
|
+
// Resolve page from options or use active page
|
|
976
|
+
const page = await this.resolvePage(options?.page);
|
|
977
|
+
const handlerParams = {
|
|
978
|
+
instruction,
|
|
979
|
+
schema: effectiveSchema,
|
|
980
|
+
model: options?.model,
|
|
981
|
+
timeout: options?.timeout,
|
|
982
|
+
selector: options?.selector,
|
|
983
|
+
page,
|
|
984
|
+
};
|
|
985
|
+
let result;
|
|
986
|
+
if (this.apiClient) {
|
|
987
|
+
const frameId = page.mainFrameId();
|
|
988
|
+
result = await this.apiClient.extract({
|
|
989
|
+
instruction: handlerParams.instruction,
|
|
990
|
+
schema: handlerParams.schema,
|
|
991
|
+
options,
|
|
992
|
+
frameId,
|
|
993
|
+
});
|
|
994
|
+
}
|
|
995
|
+
else {
|
|
996
|
+
result =
|
|
997
|
+
await this.extractHandler.extract(handlerParams);
|
|
998
|
+
}
|
|
999
|
+
const historySchemaDescriptor = effectiveSchema
|
|
1000
|
+
? toJsonSchema(effectiveSchema)
|
|
1001
|
+
: undefined;
|
|
1002
|
+
this.addToHistory("extract", {
|
|
1003
|
+
instruction,
|
|
1004
|
+
selector: options?.selector,
|
|
1005
|
+
timeout: options?.timeout,
|
|
1006
|
+
schema: historySchemaDescriptor,
|
|
1007
|
+
}, result);
|
|
1008
|
+
return result;
|
|
1009
|
+
});
|
|
1010
|
+
}
|
|
1011
|
+
async observe(a, b) {
|
|
1012
|
+
return await withInstanceLogContext(this.instanceId, async () => {
|
|
1013
|
+
if (!this.observeHandler) {
|
|
1014
|
+
throw new StagehandNotInitializedError("observe()");
|
|
1015
|
+
}
|
|
1016
|
+
// Normalize args
|
|
1017
|
+
let instruction;
|
|
1018
|
+
let options;
|
|
1019
|
+
if (typeof a === "string") {
|
|
1020
|
+
instruction = a;
|
|
1021
|
+
options = b;
|
|
1022
|
+
}
|
|
1023
|
+
else {
|
|
1024
|
+
options = a;
|
|
1025
|
+
}
|
|
1026
|
+
// Resolve to our internal Page type
|
|
1027
|
+
const page = await this.resolvePage(options?.page);
|
|
1028
|
+
const handlerParams = {
|
|
1029
|
+
instruction,
|
|
1030
|
+
model: options?.model,
|
|
1031
|
+
timeout: options?.timeout,
|
|
1032
|
+
selector: options?.selector,
|
|
1033
|
+
page: page,
|
|
1034
|
+
};
|
|
1035
|
+
let results;
|
|
1036
|
+
if (this.apiClient) {
|
|
1037
|
+
const frameId = page.mainFrameId();
|
|
1038
|
+
results = await this.apiClient.observe({
|
|
1039
|
+
instruction,
|
|
1040
|
+
options,
|
|
1041
|
+
frameId,
|
|
1042
|
+
});
|
|
1043
|
+
}
|
|
1044
|
+
else {
|
|
1045
|
+
results = await this.observeHandler.observe(handlerParams);
|
|
1046
|
+
}
|
|
1047
|
+
// history: record observe call (omit page object)
|
|
1048
|
+
this.addToHistory("observe", {
|
|
1049
|
+
instruction,
|
|
1050
|
+
timeout: options?.timeout,
|
|
1051
|
+
}, results);
|
|
1052
|
+
return results;
|
|
1053
|
+
});
|
|
1054
|
+
}
|
|
1055
|
+
/** Return the browser-level CDP WebSocket endpoint. */
|
|
1056
|
+
connectURL() {
|
|
1057
|
+
if (this.state.kind === "UNINITIALIZED") {
|
|
1058
|
+
throw new StagehandNotInitializedError("connectURL()");
|
|
1059
|
+
}
|
|
1060
|
+
return this.state.ws;
|
|
1061
|
+
}
|
|
1062
|
+
/** Expose the current CDP-backed context. */
|
|
1063
|
+
get context() {
|
|
1064
|
+
return this.ctx;
|
|
1065
|
+
}
|
|
1066
|
+
/** Best-effort cleanup of context and launched resources. */
|
|
1067
|
+
async close(opts) {
|
|
1068
|
+
// If we're already closing and this isn't a forced close, no-op.
|
|
1069
|
+
if (this._isClosing && !opts?.force)
|
|
1070
|
+
return;
|
|
1071
|
+
this._isClosing = true;
|
|
1072
|
+
const keepAlive = this.keepAlive === true;
|
|
1073
|
+
// End Browserbase session via API when keepAlive is not enabled
|
|
1074
|
+
if (!keepAlive && this.apiClient) {
|
|
1075
|
+
try {
|
|
1076
|
+
await this.apiClient.end();
|
|
1077
|
+
}
|
|
1078
|
+
catch {
|
|
1079
|
+
// best-effort cleanup
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
try {
|
|
1083
|
+
// Close session file logger
|
|
1084
|
+
try {
|
|
1085
|
+
await SessionFileLogger.close();
|
|
1086
|
+
}
|
|
1087
|
+
catch {
|
|
1088
|
+
// ignore
|
|
1089
|
+
}
|
|
1090
|
+
// Unhook CDP transport close handler
|
|
1091
|
+
try {
|
|
1092
|
+
if (this.ctx?.conn && this._onCdpClosed) {
|
|
1093
|
+
this.ctx.conn.offTransportClosed?.(this._onCdpClosed);
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
catch {
|
|
1097
|
+
// ignore
|
|
1098
|
+
}
|
|
1099
|
+
// Close CDP context
|
|
1100
|
+
try {
|
|
1101
|
+
await this.ctx?.close();
|
|
1102
|
+
}
|
|
1103
|
+
catch {
|
|
1104
|
+
// ignore
|
|
1105
|
+
}
|
|
1106
|
+
// Kill local Chrome and clean up temp profile when keepAlive is not enabled
|
|
1107
|
+
if (!keepAlive && this.state.kind === "LOCAL") {
|
|
1108
|
+
const localState = this.state;
|
|
1109
|
+
await cleanupLocalBrowser({
|
|
1110
|
+
killChrome: () => localState.chrome.kill(),
|
|
1111
|
+
userDataDir: localState.userDataDir,
|
|
1112
|
+
createdTempProfile: localState.createdTempProfile,
|
|
1113
|
+
preserveUserDataDir: localState.preserveUserDataDir,
|
|
1114
|
+
});
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
finally {
|
|
1118
|
+
this.stopShutdownSupervisor();
|
|
1119
|
+
// Reset internal state
|
|
1120
|
+
this.state = { kind: "UNINITIALIZED" };
|
|
1121
|
+
this.ctx = null;
|
|
1122
|
+
this._isClosing = false;
|
|
1123
|
+
this.resetBrowserbaseSessionMetadata();
|
|
1124
|
+
try {
|
|
1125
|
+
unbindInstanceLogger(this.instanceId);
|
|
1126
|
+
}
|
|
1127
|
+
catch {
|
|
1128
|
+
// ignore
|
|
1129
|
+
}
|
|
1130
|
+
try {
|
|
1131
|
+
this.bus.removeAllListeners();
|
|
1132
|
+
}
|
|
1133
|
+
catch {
|
|
1134
|
+
// ignore
|
|
1135
|
+
}
|
|
1136
|
+
this._history = [];
|
|
1137
|
+
this.actHandler = null;
|
|
1138
|
+
this.extractHandler = null;
|
|
1139
|
+
this.observeHandler = null;
|
|
1140
|
+
V3._instances.delete(this);
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
/** Guard: ensure Browserbase credentials exist in options. */
|
|
1144
|
+
requireBrowserbaseCreds() {
|
|
1145
|
+
let { apiKey, projectId } = this.opts;
|
|
1146
|
+
// Fall back to environment variables if not explicitly provided
|
|
1147
|
+
if (!apiKey)
|
|
1148
|
+
apiKey = process.env.BROWSERBASE_API_KEY ?? process.env.BB_API_KEY;
|
|
1149
|
+
if (!projectId)
|
|
1150
|
+
projectId =
|
|
1151
|
+
process.env.BROWSERBASE_PROJECT_ID ?? process.env.BB_PROJECT_ID;
|
|
1152
|
+
if (!apiKey || !projectId) {
|
|
1153
|
+
const missing = [];
|
|
1154
|
+
if (!apiKey)
|
|
1155
|
+
missing.push("BROWSERBASE_API_KEY");
|
|
1156
|
+
if (!projectId)
|
|
1157
|
+
missing.push("BROWSERBASE_PROJECT_ID");
|
|
1158
|
+
throw new MissingEnvironmentVariableError(missing.join(", "), "Browserbase");
|
|
1159
|
+
}
|
|
1160
|
+
// Cache resolved values back into opts for consistency
|
|
1161
|
+
this.opts.apiKey = apiKey;
|
|
1162
|
+
this.opts.projectId = projectId;
|
|
1163
|
+
// Informational log
|
|
1164
|
+
this.logger({
|
|
1165
|
+
category: "init",
|
|
1166
|
+
message: "Using Browserbase credentials",
|
|
1167
|
+
level: 1,
|
|
1168
|
+
});
|
|
1169
|
+
return { apiKey, projectId };
|
|
1170
|
+
}
|
|
1171
|
+
get logger() {
|
|
1172
|
+
// Delegate to per-instance StagehandLogger
|
|
1173
|
+
// StagehandLogger handles: verbosity filtering, usePino selection, external logger routing
|
|
1174
|
+
// This provides per-instance configuration while maintaining shared Pino optimization
|
|
1175
|
+
return (logLine) => {
|
|
1176
|
+
const line = { ...logLine, level: logLine.level ?? 1 };
|
|
1177
|
+
this.stagehandLogger.log(line);
|
|
1178
|
+
};
|
|
1179
|
+
}
|
|
1180
|
+
/**
|
|
1181
|
+
* Normalize a Playwright/Puppeteer page object into its top frame id,
|
|
1182
|
+
* so handlers can resolve it to a `Page` within our V3Context.
|
|
1183
|
+
*/
|
|
1184
|
+
async resolveTopFrameId(page) {
|
|
1185
|
+
if (this.isPlaywrightPage(page)) {
|
|
1186
|
+
const cdp = await page.context().newCDPSession(page);
|
|
1187
|
+
const { frameTree } = await cdp.send("Page.getFrameTree");
|
|
1188
|
+
return frameTree.frame.id;
|
|
1189
|
+
}
|
|
1190
|
+
if (this.isPatchrightPage(page)) {
|
|
1191
|
+
const cdp = await page.context().newCDPSession(page);
|
|
1192
|
+
const { frameTree } = await cdp.send("Page.getFrameTree");
|
|
1193
|
+
return frameTree.frame.id;
|
|
1194
|
+
}
|
|
1195
|
+
if (this.isPuppeteerPage(page)) {
|
|
1196
|
+
const cdp = await page.createCDPSession();
|
|
1197
|
+
const { frameTree } = await cdp.send("Page.getFrameTree");
|
|
1198
|
+
this.logger({
|
|
1199
|
+
category: "v3",
|
|
1200
|
+
message: "Puppeteer frame id",
|
|
1201
|
+
level: 2,
|
|
1202
|
+
auxiliary: { frameId: { value: frameTree.frame.id, type: "string" } },
|
|
1203
|
+
});
|
|
1204
|
+
return frameTree.frame.id;
|
|
1205
|
+
}
|
|
1206
|
+
throw new StagehandInvalidArgumentError("Unsupported page object passed to V3.act()");
|
|
1207
|
+
}
|
|
1208
|
+
isPlaywrightPage(p) {
|
|
1209
|
+
return (typeof p === "object" &&
|
|
1210
|
+
p !== null &&
|
|
1211
|
+
typeof p.context === "function");
|
|
1212
|
+
}
|
|
1213
|
+
isPatchrightPage(p) {
|
|
1214
|
+
return (typeof p === "object" &&
|
|
1215
|
+
p !== null &&
|
|
1216
|
+
typeof p.context === "function");
|
|
1217
|
+
}
|
|
1218
|
+
isPuppeteerPage(p) {
|
|
1219
|
+
return (typeof p === "object" &&
|
|
1220
|
+
p !== null &&
|
|
1221
|
+
typeof p.target === "function");
|
|
1222
|
+
}
|
|
1223
|
+
/** Resolve an external page reference or fall back to the active V3 page. */
|
|
1224
|
+
async resolvePage(page) {
|
|
1225
|
+
if (page) {
|
|
1226
|
+
return await this.normalizeToV3Page(page);
|
|
1227
|
+
}
|
|
1228
|
+
const ctx = this.ctx;
|
|
1229
|
+
if (!ctx) {
|
|
1230
|
+
throw new StagehandNotInitializedError("resolvePage()");
|
|
1231
|
+
}
|
|
1232
|
+
return await ctx.awaitActivePage();
|
|
1233
|
+
}
|
|
1234
|
+
async normalizeToV3Page(input) {
|
|
1235
|
+
if (input instanceof (await import("./understudy/page.js")).Page) {
|
|
1236
|
+
return input;
|
|
1237
|
+
}
|
|
1238
|
+
if (this.isPlaywrightPage(input)) {
|
|
1239
|
+
const frameId = await this.resolveTopFrameId(input);
|
|
1240
|
+
const page = this.ctx.resolvePageByMainFrameId(frameId);
|
|
1241
|
+
if (!page)
|
|
1242
|
+
throw new StagehandInitError("Failed to resolve V3 Page from Playwright page.");
|
|
1243
|
+
return page;
|
|
1244
|
+
}
|
|
1245
|
+
if (this.isPatchrightPage(input)) {
|
|
1246
|
+
const frameId = await this.resolveTopFrameId(input);
|
|
1247
|
+
const page = this.ctx.resolvePageByMainFrameId(frameId);
|
|
1248
|
+
if (!page)
|
|
1249
|
+
throw new StagehandInitError("Failed to resolve V3 Page from Patchright page.");
|
|
1250
|
+
return page;
|
|
1251
|
+
}
|
|
1252
|
+
if (this.isPuppeteerPage(input)) {
|
|
1253
|
+
const frameId = await this.resolveTopFrameId(input);
|
|
1254
|
+
const page = this.ctx.resolvePageByMainFrameId(frameId);
|
|
1255
|
+
if (!page)
|
|
1256
|
+
throw new StagehandInitError("Failed to resolve V3 Page from Puppeteer page.");
|
|
1257
|
+
return page;
|
|
1258
|
+
}
|
|
1259
|
+
throw new StagehandInvalidArgumentError("Unsupported page object.");
|
|
1260
|
+
}
|
|
1261
|
+
async _logBrowserbaseSessionStatus() {
|
|
1262
|
+
if (this.state.kind !== "BROWSERBASE") {
|
|
1263
|
+
return;
|
|
1264
|
+
}
|
|
1265
|
+
try {
|
|
1266
|
+
const snapshot = (await this.state.bb.sessions.retrieve(this.state.sessionId));
|
|
1267
|
+
if (!snapshot?.status)
|
|
1268
|
+
return;
|
|
1269
|
+
const sessionId = snapshot.id ?? this.state.sessionId;
|
|
1270
|
+
const message = snapshot.status === "TIMED_OUT"
|
|
1271
|
+
? `Browserbase session timed out (sessionId: ${sessionId})`
|
|
1272
|
+
: `Browserbase session status: ${snapshot.status}`;
|
|
1273
|
+
this.logger({
|
|
1274
|
+
category: "v3",
|
|
1275
|
+
message,
|
|
1276
|
+
level: 0,
|
|
1277
|
+
});
|
|
1278
|
+
}
|
|
1279
|
+
catch {
|
|
1280
|
+
// Ignore failures; nothing to log
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
/**
|
|
1284
|
+
* Prepares shared context for agent execution (both execute and stream).
|
|
1285
|
+
* Extracts duplicated setup logic into a single helper.
|
|
1286
|
+
*/
|
|
1287
|
+
async prepareAgentExecution(options, instructionOrOptions, agentConfigSignature) {
|
|
1288
|
+
// Note: experimental validation is done at the call site before this method
|
|
1289
|
+
// Warn if mode is not explicitly set (defaults to "dom")
|
|
1290
|
+
if (options?.mode === undefined) {
|
|
1291
|
+
this.logger({
|
|
1292
|
+
category: "agent",
|
|
1293
|
+
message: "Using agent in default DOM mode (legacy). Agent will default to 'hybrid' on an upcoming release for improved performance.\n → https://docs.stagehand.dev/v3/basics/agent\n",
|
|
1294
|
+
level: 0,
|
|
1295
|
+
});
|
|
1296
|
+
}
|
|
1297
|
+
const tools = options?.integrations
|
|
1298
|
+
? await resolveTools(options.integrations, options.tools)
|
|
1299
|
+
: (options?.tools ?? {});
|
|
1300
|
+
const agentLlmClient = options?.model
|
|
1301
|
+
? this.resolveLlmClient(options.model)
|
|
1302
|
+
: this.llmClient;
|
|
1303
|
+
const resolvedExecutionModel = options?.executionModel ?? options?.model;
|
|
1304
|
+
const handler = new V3AgentHandler(this, this.logger, agentLlmClient, resolvedExecutionModel, options?.systemPrompt, tools, options?.mode);
|
|
1305
|
+
const resolvedOptions = typeof instructionOrOptions === "string"
|
|
1306
|
+
? { instruction: instructionOrOptions }
|
|
1307
|
+
: instructionOrOptions;
|
|
1308
|
+
const callbacksWithSafety = resolvedOptions.callbacks;
|
|
1309
|
+
if (callbacksWithSafety?.onSafetyConfirmation) {
|
|
1310
|
+
throw new StagehandInvalidArgumentError('onSafetyConfirmation callback is only supported when using mode: "cua" agents.');
|
|
1311
|
+
}
|
|
1312
|
+
if (resolvedOptions.page) {
|
|
1313
|
+
const normalizedPage = await this.normalizeToV3Page(resolvedOptions.page);
|
|
1314
|
+
this.ctx.setActivePage(normalizedPage);
|
|
1315
|
+
}
|
|
1316
|
+
const instruction = resolvedOptions.instruction.trim();
|
|
1317
|
+
const sanitizedOptions = this.agentCache.sanitizeExecuteOptions(resolvedOptions);
|
|
1318
|
+
const cacheContext = this.agentCache.shouldAttemptCache(instruction)
|
|
1319
|
+
? await this.agentCache.prepareContext({
|
|
1320
|
+
instruction,
|
|
1321
|
+
options: sanitizedOptions,
|
|
1322
|
+
configSignature: agentConfigSignature,
|
|
1323
|
+
page: await this.ctx.awaitActivePage(),
|
|
1324
|
+
})
|
|
1325
|
+
: null;
|
|
1326
|
+
return {
|
|
1327
|
+
handler,
|
|
1328
|
+
resolvedOptions,
|
|
1329
|
+
instruction,
|
|
1330
|
+
cacheContext,
|
|
1331
|
+
llmClient: agentLlmClient,
|
|
1332
|
+
};
|
|
1333
|
+
}
|
|
1334
|
+
agent(options) {
|
|
1335
|
+
// Determine if CUA mode is enabled (via mode: "cua" or deprecated cua: true)
|
|
1336
|
+
const isCuaMode = options?.mode !== undefined
|
|
1337
|
+
? options.mode === "cua"
|
|
1338
|
+
: options?.cua === true;
|
|
1339
|
+
// Emit deprecation warning for cua: true
|
|
1340
|
+
if (options?.cua === true) {
|
|
1341
|
+
this.logger({
|
|
1342
|
+
category: "agent",
|
|
1343
|
+
message: '[DEPRECATED] The "cua: true" option is deprecated. Use "mode: \'cua\'" instead. This option will be removed in a future version.',
|
|
1344
|
+
level: 0,
|
|
1345
|
+
});
|
|
1346
|
+
console.warn('[Stagehand] DEPRECATED: The "cua: true" option is deprecated. Use "mode: \'cua\'" instead.');
|
|
1347
|
+
}
|
|
1348
|
+
this.logger({
|
|
1349
|
+
category: "agent",
|
|
1350
|
+
message: "Creating v3 agent instance",
|
|
1351
|
+
level: 1,
|
|
1352
|
+
auxiliary: {
|
|
1353
|
+
cua: { value: isCuaMode ? "true" : "false", type: "boolean" },
|
|
1354
|
+
mode: { value: options?.mode ?? "dom", type: "string" },
|
|
1355
|
+
model: {
|
|
1356
|
+
value: extractModelName(options?.model) ?? this.llmClient.modelName,
|
|
1357
|
+
type: "string",
|
|
1358
|
+
},
|
|
1359
|
+
systemPrompt: { value: options?.systemPrompt ?? "", type: "string" },
|
|
1360
|
+
tools: { value: JSON.stringify(options?.tools ?? {}), type: "object" },
|
|
1361
|
+
...(options?.integrations && {
|
|
1362
|
+
integrations: {
|
|
1363
|
+
value: JSON.stringify(options.integrations),
|
|
1364
|
+
type: "object",
|
|
1365
|
+
},
|
|
1366
|
+
}),
|
|
1367
|
+
},
|
|
1368
|
+
});
|
|
1369
|
+
// If CUA mode is enabled (via mode: "cua" or deprecated cua: true), use the computer-use agent path
|
|
1370
|
+
if (isCuaMode) {
|
|
1371
|
+
// Validate agent config at creation time (includes CUA+streaming conflict check)
|
|
1372
|
+
validateExperimentalFeatures({
|
|
1373
|
+
isExperimental: this.experimental,
|
|
1374
|
+
agentConfig: options,
|
|
1375
|
+
});
|
|
1376
|
+
const modelToUse = options?.model || {
|
|
1377
|
+
modelName: this.modelName,
|
|
1378
|
+
...this.modelClientOptions,
|
|
1379
|
+
};
|
|
1380
|
+
const { modelName, isCua, clientOptions } = resolveModel(modelToUse);
|
|
1381
|
+
if (!isCua) {
|
|
1382
|
+
throw new CuaModelRequiredError(AVAILABLE_CUA_MODELS);
|
|
1383
|
+
}
|
|
1384
|
+
const agentConfigSignature = this.agentCache.buildConfigSignature(options);
|
|
1385
|
+
return {
|
|
1386
|
+
execute: async (instructionOrOptions) => withInstanceLogContext(this.instanceId, async () => {
|
|
1387
|
+
validateExperimentalFeatures({
|
|
1388
|
+
isExperimental: this.experimental,
|
|
1389
|
+
agentConfig: options,
|
|
1390
|
+
executeOptions: typeof instructionOrOptions === "object"
|
|
1391
|
+
? instructionOrOptions
|
|
1392
|
+
: null,
|
|
1393
|
+
});
|
|
1394
|
+
SessionFileLogger.logAgentTaskStarted({
|
|
1395
|
+
invocation: "Agent.execute",
|
|
1396
|
+
args: [instructionOrOptions],
|
|
1397
|
+
});
|
|
1398
|
+
const tools = options?.integrations
|
|
1399
|
+
? await resolveTools(options.integrations, options.tools)
|
|
1400
|
+
: (options?.tools ?? {});
|
|
1401
|
+
const handler = new V3CuaAgentHandler(this, this.logger, {
|
|
1402
|
+
modelName,
|
|
1403
|
+
clientOptions,
|
|
1404
|
+
userProvidedInstructions: options.systemPrompt ??
|
|
1405
|
+
`You are a helpful assistant that can use a web browser.\nDo not ask follow up questions, the user will trust your judgement.`,
|
|
1406
|
+
}, tools);
|
|
1407
|
+
const resolvedOptions = typeof instructionOrOptions === "string"
|
|
1408
|
+
? { instruction: instructionOrOptions }
|
|
1409
|
+
: instructionOrOptions;
|
|
1410
|
+
if (resolvedOptions.page) {
|
|
1411
|
+
const normalizedPage = await this.normalizeToV3Page(resolvedOptions.page);
|
|
1412
|
+
this.ctx.setActivePage(normalizedPage);
|
|
1413
|
+
}
|
|
1414
|
+
const instruction = resolvedOptions.instruction.trim();
|
|
1415
|
+
const sanitizedOptions = this.agentCache.sanitizeExecuteOptions(resolvedOptions);
|
|
1416
|
+
let cacheContext = null;
|
|
1417
|
+
if (this.agentCache.shouldAttemptCache(instruction)) {
|
|
1418
|
+
const startPage = await this.ctx.awaitActivePage();
|
|
1419
|
+
cacheContext = await this.agentCache.prepareContext({
|
|
1420
|
+
instruction,
|
|
1421
|
+
options: sanitizedOptions,
|
|
1422
|
+
configSignature: agentConfigSignature,
|
|
1423
|
+
page: startPage,
|
|
1424
|
+
});
|
|
1425
|
+
if (cacheContext) {
|
|
1426
|
+
const replayed = await this.agentCache.tryReplay(cacheContext);
|
|
1427
|
+
if (replayed) {
|
|
1428
|
+
SessionFileLogger.logAgentTaskCompleted({ cacheHit: true });
|
|
1429
|
+
return replayed;
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
let agentSteps = [];
|
|
1434
|
+
const shouldRecordLocally = !!cacheContext && (!this.apiClient || this.experimental);
|
|
1435
|
+
if (shouldRecordLocally) {
|
|
1436
|
+
this.beginAgentReplayRecording();
|
|
1437
|
+
}
|
|
1438
|
+
let result;
|
|
1439
|
+
try {
|
|
1440
|
+
if (this.apiClient && !this.experimental) {
|
|
1441
|
+
const page = await this.ctx.awaitActivePage();
|
|
1442
|
+
result = await this.apiClient.agentExecute(options, resolvedOptions, page.mainFrameId(), !!cacheContext);
|
|
1443
|
+
if (cacheContext) {
|
|
1444
|
+
const transferredEntry = this.apiClient.consumeLatestAgentCacheEntry();
|
|
1445
|
+
await this.agentCache.storeTransferredEntry(transferredEntry);
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
else {
|
|
1449
|
+
result = await handler.execute(instructionOrOptions);
|
|
1450
|
+
}
|
|
1451
|
+
if (shouldRecordLocally) {
|
|
1452
|
+
agentSteps = this.endAgentReplayRecording();
|
|
1453
|
+
}
|
|
1454
|
+
if (shouldRecordLocally &&
|
|
1455
|
+
cacheContext &&
|
|
1456
|
+
result.success &&
|
|
1457
|
+
agentSteps.length > 0) {
|
|
1458
|
+
await this.agentCache.store(cacheContext, agentSteps, result);
|
|
1459
|
+
}
|
|
1460
|
+
return result;
|
|
1461
|
+
}
|
|
1462
|
+
catch (err) {
|
|
1463
|
+
if (shouldRecordLocally)
|
|
1464
|
+
this.discardAgentReplayRecording();
|
|
1465
|
+
throw err;
|
|
1466
|
+
}
|
|
1467
|
+
finally {
|
|
1468
|
+
if (shouldRecordLocally) {
|
|
1469
|
+
this.discardAgentReplayRecording();
|
|
1470
|
+
}
|
|
1471
|
+
SessionFileLogger.logAgentTaskCompleted();
|
|
1472
|
+
}
|
|
1473
|
+
}),
|
|
1474
|
+
};
|
|
1475
|
+
}
|
|
1476
|
+
// Default: AISDK tools-based agent
|
|
1477
|
+
const agentConfigSignature = this.agentCache.buildConfigSignature(options);
|
|
1478
|
+
const isStreaming = options?.stream ?? false;
|
|
1479
|
+
return {
|
|
1480
|
+
execute: async (instructionOrOptions) => withInstanceLogContext(this.instanceId, async () => {
|
|
1481
|
+
validateExperimentalFeatures({
|
|
1482
|
+
isExperimental: this.experimental,
|
|
1483
|
+
agentConfig: options,
|
|
1484
|
+
executeOptions: typeof instructionOrOptions === "object"
|
|
1485
|
+
? instructionOrOptions
|
|
1486
|
+
: null,
|
|
1487
|
+
isStreaming,
|
|
1488
|
+
});
|
|
1489
|
+
SessionFileLogger.logAgentTaskStarted({
|
|
1490
|
+
invocation: "Agent.execute",
|
|
1491
|
+
args: [instructionOrOptions],
|
|
1492
|
+
});
|
|
1493
|
+
// Streaming mode
|
|
1494
|
+
if (isStreaming) {
|
|
1495
|
+
const { handler, resolvedOptions, cacheContext, llmClient } = await this.prepareAgentExecution(options, instructionOrOptions, agentConfigSignature);
|
|
1496
|
+
if (cacheContext) {
|
|
1497
|
+
const replayed = await this.agentCache.tryReplayAsStream(cacheContext, llmClient);
|
|
1498
|
+
if (replayed) {
|
|
1499
|
+
SessionFileLogger.logAgentTaskCompleted({ cacheHit: true });
|
|
1500
|
+
return replayed;
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
const streamResult = await handler.stream(resolvedOptions);
|
|
1504
|
+
if (cacheContext) {
|
|
1505
|
+
const wrappedStream = this.agentCache.wrapStreamForCaching(cacheContext, streamResult, () => this.beginAgentReplayRecording(), () => this.endAgentReplayRecording(), () => this.discardAgentReplayRecording());
|
|
1506
|
+
// Log completion when stream is returned (stream completes asynchronously)
|
|
1507
|
+
SessionFileLogger.logAgentTaskCompleted();
|
|
1508
|
+
return wrappedStream;
|
|
1509
|
+
}
|
|
1510
|
+
// Log completion when stream is returned (stream completes asynchronously)
|
|
1511
|
+
SessionFileLogger.logAgentTaskCompleted();
|
|
1512
|
+
return streamResult;
|
|
1513
|
+
}
|
|
1514
|
+
// Non-streaming mode (default)
|
|
1515
|
+
const { handler, resolvedOptions, cacheContext, llmClient } = await this.prepareAgentExecution(options, instructionOrOptions, agentConfigSignature);
|
|
1516
|
+
if (cacheContext) {
|
|
1517
|
+
const replayed = await this.agentCache.tryReplay(cacheContext, llmClient);
|
|
1518
|
+
if (replayed) {
|
|
1519
|
+
SessionFileLogger.logAgentTaskCompleted({ cacheHit: true });
|
|
1520
|
+
return replayed;
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
let agentSteps = [];
|
|
1524
|
+
const shouldRecordLocally = !!cacheContext && (!this.apiClient || this.experimental);
|
|
1525
|
+
if (shouldRecordLocally) {
|
|
1526
|
+
this.beginAgentReplayRecording();
|
|
1527
|
+
}
|
|
1528
|
+
let result;
|
|
1529
|
+
try {
|
|
1530
|
+
if (this.apiClient && !this.experimental) {
|
|
1531
|
+
const page = await this.ctx.awaitActivePage();
|
|
1532
|
+
result = await this.apiClient.agentExecute(options ?? {}, resolvedOptions, page.mainFrameId(), !!cacheContext);
|
|
1533
|
+
if (cacheContext) {
|
|
1534
|
+
const transferredEntry = this.apiClient.consumeLatestAgentCacheEntry();
|
|
1535
|
+
await this.agentCache.storeTransferredEntry(transferredEntry);
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
else {
|
|
1539
|
+
result = await handler.execute(resolvedOptions);
|
|
1540
|
+
}
|
|
1541
|
+
if (shouldRecordLocally) {
|
|
1542
|
+
agentSteps = this.endAgentReplayRecording();
|
|
1543
|
+
}
|
|
1544
|
+
if (shouldRecordLocally &&
|
|
1545
|
+
cacheContext &&
|
|
1546
|
+
result.success &&
|
|
1547
|
+
agentSteps.length > 0) {
|
|
1548
|
+
await this.agentCache.store(cacheContext, agentSteps, result);
|
|
1549
|
+
}
|
|
1550
|
+
return result;
|
|
1551
|
+
}
|
|
1552
|
+
catch (err) {
|
|
1553
|
+
if (shouldRecordLocally)
|
|
1554
|
+
this.discardAgentReplayRecording();
|
|
1555
|
+
throw err;
|
|
1556
|
+
}
|
|
1557
|
+
finally {
|
|
1558
|
+
if (shouldRecordLocally) {
|
|
1559
|
+
this.discardAgentReplayRecording();
|
|
1560
|
+
}
|
|
1561
|
+
SessionFileLogger.logAgentTaskCompleted();
|
|
1562
|
+
}
|
|
1563
|
+
}),
|
|
1564
|
+
};
|
|
1565
|
+
}
|
|
1566
|
+
};
|
|
1567
|
+
})();
|
|
1568
|
+
export { V3 };
|
|
1569
|
+
function isObserveResult(v) {
|
|
1570
|
+
return (!!v && typeof v === "object" && "selector" in v);
|
|
1571
|
+
}
|
|
1572
|
+
//# sourceMappingURL=v3.js.map
|