@browserbasehq/orca 3.1.0-patch.4 → 3.2.0-preview.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/lib/inference.js +1 -4
- package/dist/cjs/lib/inference.js.map +1 -1
- package/dist/cjs/lib/utils.d.ts +1 -0
- package/dist/cjs/lib/utils.js +4 -0
- package/dist/cjs/lib/utils.js.map +1 -1
- package/dist/cjs/lib/v3/agent/AgentProvider.js +0 -1
- package/dist/cjs/lib/v3/agent/AgentProvider.js.map +1 -1
- package/dist/cjs/lib/v3/agent/AnthropicCUAClient.js +4 -6
- package/dist/cjs/lib/v3/agent/AnthropicCUAClient.js.map +1 -1
- package/dist/cjs/lib/v3/agent/GoogleCUAClient.js +4 -6
- package/dist/cjs/lib/v3/agent/GoogleCUAClient.js.map +1 -1
- package/dist/cjs/lib/v3/agent/OpenAICUAClient.js +4 -6
- package/dist/cjs/lib/v3/agent/OpenAICUAClient.js.map +1 -1
- package/dist/cjs/lib/v3/agent/prompts/agentSystemPrompt.d.ts +2 -0
- package/dist/cjs/lib/v3/agent/prompts/agentSystemPrompt.js +2 -2
- package/dist/cjs/lib/v3/agent/prompts/agentSystemPrompt.js.map +1 -1
- package/dist/cjs/lib/v3/agent/tools/act.d.ts +1 -1
- package/dist/cjs/lib/v3/agent/tools/act.js +20 -4
- package/dist/cjs/lib/v3/agent/tools/act.js.map +1 -1
- package/dist/cjs/lib/v3/agent/tools/ariaTree.d.ts +8 -1
- package/dist/cjs/lib/v3/agent/tools/ariaTree.js +60 -22
- package/dist/cjs/lib/v3/agent/tools/ariaTree.js.map +1 -1
- package/dist/cjs/lib/v3/agent/tools/{search.js → braveSearch.js} +1 -1
- package/dist/cjs/lib/v3/agent/tools/braveSearch.js.map +1 -0
- package/dist/cjs/lib/v3/agent/tools/browserbaseSearch.d.ts +13 -0
- package/dist/cjs/lib/v3/agent/tools/browserbaseSearch.js +70 -0
- package/dist/cjs/lib/v3/agent/tools/browserbaseSearch.js.map +1 -0
- package/dist/cjs/lib/v3/agent/tools/click.js +23 -31
- package/dist/cjs/lib/v3/agent/tools/click.js.map +1 -1
- package/dist/cjs/lib/v3/agent/tools/dragAndDrop.js +22 -30
- package/dist/cjs/lib/v3/agent/tools/dragAndDrop.js.map +1 -1
- package/dist/cjs/lib/v3/agent/tools/extract.d.ts +2 -2
- package/dist/cjs/lib/v3/agent/tools/extract.js +16 -3
- package/dist/cjs/lib/v3/agent/tools/extract.js.map +1 -1
- package/dist/cjs/lib/v3/agent/tools/fillFormVision.js +30 -30
- package/dist/cjs/lib/v3/agent/tools/fillFormVision.js.map +1 -1
- package/dist/cjs/lib/v3/agent/tools/fillform.d.ts +7 -1
- package/dist/cjs/lib/v3/agent/tools/fillform.js +60 -37
- package/dist/cjs/lib/v3/agent/tools/fillform.js.map +1 -1
- package/dist/cjs/lib/v3/agent/tools/index.d.ts +19 -3
- package/dist/cjs/lib/v3/agent/tools/index.js +12 -8
- package/dist/cjs/lib/v3/agent/tools/index.js.map +1 -1
- package/dist/cjs/lib/v3/agent/tools/screenshot.d.ts +8 -0
- package/dist/cjs/lib/v3/agent/tools/screenshot.js +32 -15
- package/dist/cjs/lib/v3/agent/tools/screenshot.js.map +1 -1
- package/dist/cjs/lib/v3/agent/tools/scroll.js +12 -0
- package/dist/cjs/lib/v3/agent/tools/scroll.js.map +1 -1
- package/dist/cjs/lib/v3/agent/tools/type.js +23 -31
- package/dist/cjs/lib/v3/agent/tools/type.js.map +1 -1
- package/dist/cjs/lib/v3/agent/tools/wait.js +6 -0
- package/dist/cjs/lib/v3/agent/tools/wait.js.map +1 -1
- package/dist/cjs/lib/v3/agent/utils/handleDoneToolCall.js +4 -0
- package/dist/cjs/lib/v3/agent/utils/handleDoneToolCall.js.map +1 -1
- package/dist/cjs/lib/v3/api.d.ts +2 -2
- package/dist/cjs/lib/v3/api.js +1 -1
- package/dist/cjs/lib/v3/api.js.map +1 -1
- package/dist/cjs/lib/v3/cache/ActCache.d.ts +0 -1
- package/dist/cjs/lib/v3/cache/ActCache.js +2 -18
- package/dist/cjs/lib/v3/cache/ActCache.js.map +1 -1
- package/dist/cjs/lib/v3/eventStore.d.ts +41 -0
- package/dist/cjs/lib/v3/eventStore.js +375 -0
- package/dist/cjs/lib/v3/eventStore.js.map +1 -0
- package/dist/cjs/lib/v3/flowLogger.d.ts +62 -103
- package/dist/cjs/lib/v3/flowLogger.js +362 -773
- package/dist/cjs/lib/v3/flowLogger.js.map +1 -1
- package/dist/cjs/lib/v3/handlers/actHandler.js +1 -2
- package/dist/cjs/lib/v3/handlers/actHandler.js.map +1 -1
- package/dist/cjs/lib/v3/handlers/extractHandler.js +2 -2
- package/dist/cjs/lib/v3/handlers/extractHandler.js.map +1 -1
- package/dist/cjs/lib/v3/handlers/handlerUtils/actHandlerUtils.js +21 -33
- package/dist/cjs/lib/v3/handlers/handlerUtils/actHandlerUtils.js.map +1 -1
- package/dist/cjs/lib/v3/handlers/observeHandler.js +1 -2
- package/dist/cjs/lib/v3/handlers/observeHandler.js.map +1 -1
- package/dist/cjs/lib/v3/handlers/v3AgentHandler.d.ts +0 -4
- package/dist/cjs/lib/v3/handlers/v3AgentHandler.js +23 -48
- package/dist/cjs/lib/v3/handlers/v3AgentHandler.js.map +1 -1
- package/dist/cjs/lib/v3/handlers/v3CuaAgentHandler.js +10 -12
- package/dist/cjs/lib/v3/handlers/v3CuaAgentHandler.js.map +1 -1
- package/dist/cjs/lib/v3/index.d.ts +2 -1
- package/dist/cjs/lib/v3/launch/browserbase.d.ts +1 -1
- package/dist/cjs/lib/v3/launch/browserbase.js +4 -9
- package/dist/cjs/lib/v3/launch/browserbase.js.map +1 -1
- package/dist/cjs/lib/v3/llm/LLMProvider.js +0 -5
- package/dist/cjs/lib/v3/llm/LLMProvider.js.map +1 -1
- package/dist/cjs/lib/v3/llm/aisdk.js +10 -16
- package/dist/cjs/lib/v3/llm/aisdk.js.map +1 -1
- package/dist/cjs/lib/v3/runtimePaths.js +2 -1
- package/dist/cjs/lib/v3/runtimePaths.js.map +1 -1
- package/dist/cjs/lib/v3/shutdown/supervisor.js +2 -2
- package/dist/cjs/lib/v3/shutdown/supervisor.js.map +1 -1
- package/dist/cjs/lib/v3/timeoutConfig.d.ts +1 -1
- package/dist/cjs/lib/v3/timeoutConfig.js +5 -0
- package/dist/cjs/lib/v3/timeoutConfig.js.map +1 -1
- package/dist/cjs/lib/v3/types/private/shutdown.d.ts +1 -1
- package/dist/cjs/lib/v3/types/private/shutdown.js.map +1 -1
- package/dist/cjs/lib/v3/types/public/agent.d.ts +28 -3
- package/dist/cjs/lib/v3/types/public/agent.js +0 -1
- package/dist/cjs/lib/v3/types/public/agent.js.map +1 -1
- package/dist/cjs/lib/v3/types/public/api.d.ts +3 -0
- package/dist/cjs/lib/v3/types/public/api.js +1 -0
- package/dist/cjs/lib/v3/types/public/api.js.map +1 -1
- package/dist/cjs/lib/v3/types/public/model.d.ts +4 -2
- package/dist/cjs/lib/v3/types/public/model.js.map +1 -1
- package/dist/cjs/lib/v3/types/public/options.d.ts +6 -0
- package/dist/cjs/lib/v3/types/public/options.js.map +1 -1
- package/dist/cjs/lib/v3/understudy/cdp.d.ts +8 -13
- package/dist/cjs/lib/v3/understudy/cdp.js +137 -17
- package/dist/cjs/lib/v3/understudy/cdp.js.map +1 -1
- package/dist/cjs/lib/v3/understudy/context.d.ts +1 -0
- package/dist/cjs/lib/v3/understudy/context.js +142 -60
- package/dist/cjs/lib/v3/understudy/context.js.map +1 -1
- package/dist/cjs/lib/v3/understudy/frame.js +23 -6
- package/dist/cjs/lib/v3/understudy/frame.js.map +1 -1
- package/dist/cjs/lib/v3/understudy/page.d.ts +13 -0
- package/dist/cjs/lib/v3/understudy/page.js +88 -20
- package/dist/cjs/lib/v3/understudy/page.js.map +1 -1
- package/dist/cjs/lib/v3/understudy/screenshotUtils.d.ts +0 -1
- package/dist/cjs/lib/v3/understudy/screenshotUtils.js +0 -18
- package/dist/cjs/lib/v3/understudy/screenshotUtils.js.map +1 -1
- package/dist/cjs/lib/v3/v3.d.ts +10 -0
- package/dist/cjs/lib/v3/v3.js +210 -172
- package/dist/cjs/lib/v3/v3.js.map +1 -1
- package/dist/cjs/tests/integration/cdp-session-detached.spec.js +1 -1
- package/dist/cjs/tests/integration/cdp-session-detached.spec.js.map +1 -1
- package/dist/cjs/tests/integration/context-addInitScript.spec.js +104 -11
- package/dist/cjs/tests/integration/context-addInitScript.spec.js.map +1 -1
- package/dist/cjs/tests/integration/iframe-ctx-addInitScript-race.spec.js +219 -0
- package/dist/cjs/tests/integration/iframe-ctx-addInitScript-race.spec.js.map +1 -0
- package/dist/cjs/tests/integration/page-extra-http-headers.spec.js +85 -0
- package/dist/cjs/tests/integration/page-extra-http-headers.spec.js.map +1 -0
- package/dist/cjs/tests/integration/page-screenshot.spec.js +1 -1
- package/dist/cjs/tests/integration/page-screenshot.spec.js.map +1 -1
- package/dist/cjs/tests/integration/timeouts.spec.js +168 -0
- package/dist/cjs/tests/integration/timeouts.spec.js.map +1 -1
- package/dist/cjs/tests/unit/model-deprecation.test.js +5 -8
- package/dist/cjs/tests/unit/model-deprecation.test.js.map +1 -1
- package/dist/cjs/tests/unit/page-extra-http-headers.test.d.ts +1 -0
- package/dist/cjs/tests/unit/page-extra-http-headers.test.js +92 -0
- package/dist/cjs/tests/unit/page-extra-http-headers.test.js.map +1 -0
- package/dist/cjs/tests/unit/public-api/llm-and-agents.test.js +13 -1
- package/dist/cjs/tests/unit/public-api/llm-and-agents.test.js.map +1 -1
- package/dist/cjs/tests/unit/public-api/public-types.test.js.map +1 -1
- package/dist/esm/lib/inference.js +1 -4
- package/dist/esm/lib/inference.js.map +1 -1
- package/dist/esm/lib/utils.d.ts +1 -0
- package/dist/esm/lib/utils.js +3 -0
- package/dist/esm/lib/utils.js.map +1 -1
- package/dist/esm/lib/v3/agent/AgentProvider.js +0 -1
- package/dist/esm/lib/v3/agent/AgentProvider.js.map +1 -1
- package/dist/esm/lib/v3/agent/AnthropicCUAClient.js +5 -7
- package/dist/esm/lib/v3/agent/AnthropicCUAClient.js.map +1 -1
- package/dist/esm/lib/v3/agent/GoogleCUAClient.js +5 -7
- package/dist/esm/lib/v3/agent/GoogleCUAClient.js.map +1 -1
- package/dist/esm/lib/v3/agent/OpenAICUAClient.js +5 -7
- package/dist/esm/lib/v3/agent/OpenAICUAClient.js.map +1 -1
- package/dist/esm/lib/v3/agent/prompts/agentSystemPrompt.d.ts +2 -0
- package/dist/esm/lib/v3/agent/prompts/agentSystemPrompt.js +2 -2
- package/dist/esm/lib/v3/agent/prompts/agentSystemPrompt.js.map +1 -1
- package/dist/esm/lib/v3/agent/tools/act.d.ts +1 -1
- package/dist/esm/lib/v3/agent/tools/act.js +20 -4
- package/dist/esm/lib/v3/agent/tools/act.js.map +1 -1
- package/dist/esm/lib/v3/agent/tools/ariaTree.d.ts +8 -1
- package/dist/esm/lib/v3/agent/tools/ariaTree.js +60 -22
- package/dist/esm/lib/v3/agent/tools/ariaTree.js.map +1 -1
- package/dist/esm/lib/v3/agent/tools/{search.js → braveSearch.js} +1 -1
- package/dist/esm/lib/v3/agent/tools/braveSearch.js.map +1 -0
- package/dist/esm/lib/v3/agent/tools/browserbaseSearch.d.ts +13 -0
- package/dist/esm/lib/v3/agent/tools/browserbaseSearch.js +66 -0
- package/dist/esm/lib/v3/agent/tools/browserbaseSearch.js.map +1 -0
- package/dist/esm/lib/v3/agent/tools/click.js +23 -31
- package/dist/esm/lib/v3/agent/tools/click.js.map +1 -1
- package/dist/esm/lib/v3/agent/tools/dragAndDrop.js +22 -30
- package/dist/esm/lib/v3/agent/tools/dragAndDrop.js.map +1 -1
- package/dist/esm/lib/v3/agent/tools/extract.d.ts +2 -2
- package/dist/esm/lib/v3/agent/tools/extract.js +16 -3
- package/dist/esm/lib/v3/agent/tools/extract.js.map +1 -1
- package/dist/esm/lib/v3/agent/tools/fillFormVision.js +30 -30
- package/dist/esm/lib/v3/agent/tools/fillFormVision.js.map +1 -1
- package/dist/esm/lib/v3/agent/tools/fillform.d.ts +7 -1
- package/dist/esm/lib/v3/agent/tools/fillform.js +60 -37
- package/dist/esm/lib/v3/agent/tools/fillform.js.map +1 -1
- package/dist/esm/lib/v3/agent/tools/index.d.ts +19 -3
- package/dist/esm/lib/v3/agent/tools/index.js +12 -8
- package/dist/esm/lib/v3/agent/tools/index.js.map +1 -1
- package/dist/esm/lib/v3/agent/tools/screenshot.d.ts +8 -0
- package/dist/esm/lib/v3/agent/tools/screenshot.js +32 -15
- package/dist/esm/lib/v3/agent/tools/screenshot.js.map +1 -1
- package/dist/esm/lib/v3/agent/tools/scroll.js +12 -0
- package/dist/esm/lib/v3/agent/tools/scroll.js.map +1 -1
- package/dist/esm/lib/v3/agent/tools/type.js +23 -31
- package/dist/esm/lib/v3/agent/tools/type.js.map +1 -1
- package/dist/esm/lib/v3/agent/tools/wait.js +6 -0
- package/dist/esm/lib/v3/agent/tools/wait.js.map +1 -1
- package/dist/esm/lib/v3/agent/utils/handleDoneToolCall.js +4 -0
- package/dist/esm/lib/v3/agent/utils/handleDoneToolCall.js.map +1 -1
- package/dist/esm/lib/v3/api.d.ts +2 -2
- package/dist/esm/lib/v3/api.js +1 -1
- package/dist/esm/lib/v3/api.js.map +1 -1
- package/dist/esm/lib/v3/cache/ActCache.d.ts +0 -1
- package/dist/esm/lib/v3/cache/ActCache.js +2 -18
- package/dist/esm/lib/v3/cache/ActCache.js.map +1 -1
- package/dist/esm/lib/v3/eventStore.d.ts +41 -0
- package/dist/esm/lib/v3/eventStore.js +363 -0
- package/dist/esm/lib/v3/eventStore.js.map +1 -0
- package/dist/esm/lib/v3/flowLogger.d.ts +62 -103
- package/dist/esm/lib/v3/flowLogger.js +356 -762
- package/dist/esm/lib/v3/flowLogger.js.map +1 -1
- package/dist/esm/lib/v3/handlers/actHandler.js +1 -2
- package/dist/esm/lib/v3/handlers/actHandler.js.map +1 -1
- package/dist/esm/lib/v3/handlers/extractHandler.js +2 -2
- package/dist/esm/lib/v3/handlers/extractHandler.js.map +1 -1
- package/dist/esm/lib/v3/handlers/handlerUtils/actHandlerUtils.js +22 -34
- package/dist/esm/lib/v3/handlers/handlerUtils/actHandlerUtils.js.map +1 -1
- package/dist/esm/lib/v3/handlers/observeHandler.js +1 -2
- package/dist/esm/lib/v3/handlers/observeHandler.js.map +1 -1
- package/dist/esm/lib/v3/handlers/v3AgentHandler.d.ts +0 -4
- package/dist/esm/lib/v3/handlers/v3AgentHandler.js +25 -50
- package/dist/esm/lib/v3/handlers/v3AgentHandler.js.map +1 -1
- package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.js +11 -13
- package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.js.map +1 -1
- package/dist/esm/lib/v3/index.d.ts +2 -1
- package/dist/esm/lib/v3/launch/browserbase.d.ts +1 -1
- package/dist/esm/lib/v3/launch/browserbase.js +4 -9
- package/dist/esm/lib/v3/launch/browserbase.js.map +1 -1
- package/dist/esm/lib/v3/llm/LLMProvider.js +0 -5
- package/dist/esm/lib/v3/llm/LLMProvider.js.map +1 -1
- package/dist/esm/lib/v3/llm/aisdk.js +11 -17
- package/dist/esm/lib/v3/llm/aisdk.js.map +1 -1
- package/dist/esm/lib/v3/runtimePaths.js +2 -1
- package/dist/esm/lib/v3/runtimePaths.js.map +1 -1
- package/dist/esm/lib/v3/shutdown/supervisor.js +2 -2
- package/dist/esm/lib/v3/shutdown/supervisor.js.map +1 -1
- package/dist/esm/lib/v3/timeoutConfig.d.ts +1 -1
- package/dist/esm/lib/v3/timeoutConfig.js +5 -0
- package/dist/esm/lib/v3/timeoutConfig.js.map +1 -1
- package/dist/esm/lib/v3/types/private/shutdown.d.ts +1 -1
- package/dist/esm/lib/v3/types/private/shutdown.js.map +1 -1
- package/dist/esm/lib/v3/types/public/agent.d.ts +28 -3
- package/dist/esm/lib/v3/types/public/agent.js +0 -1
- package/dist/esm/lib/v3/types/public/agent.js.map +1 -1
- package/dist/esm/lib/v3/types/public/api.d.ts +3 -0
- package/dist/esm/lib/v3/types/public/api.js +1 -0
- package/dist/esm/lib/v3/types/public/api.js.map +1 -1
- package/dist/esm/lib/v3/types/public/model.d.ts +4 -2
- package/dist/esm/lib/v3/types/public/model.js.map +1 -1
- package/dist/esm/lib/v3/types/public/options.d.ts +6 -0
- package/dist/esm/lib/v3/types/public/options.js.map +1 -1
- package/dist/esm/lib/v3/understudy/cdp.d.ts +8 -13
- package/dist/esm/lib/v3/understudy/cdp.js +138 -18
- package/dist/esm/lib/v3/understudy/cdp.js.map +1 -1
- package/dist/esm/lib/v3/understudy/context.d.ts +1 -0
- package/dist/esm/lib/v3/understudy/context.js +142 -60
- package/dist/esm/lib/v3/understudy/context.js.map +1 -1
- package/dist/esm/lib/v3/understudy/frame.js +23 -6
- package/dist/esm/lib/v3/understudy/frame.js.map +1 -1
- package/dist/esm/lib/v3/understudy/page.d.ts +13 -0
- package/dist/esm/lib/v3/understudy/page.js +91 -23
- package/dist/esm/lib/v3/understudy/page.js.map +1 -1
- package/dist/esm/lib/v3/understudy/screenshotUtils.d.ts +0 -1
- package/dist/esm/lib/v3/understudy/screenshotUtils.js +0 -17
- package/dist/esm/lib/v3/understudy/screenshotUtils.js.map +1 -1
- package/dist/esm/lib/v3/v3.d.ts +10 -0
- package/dist/esm/lib/v3/v3.js +211 -173
- package/dist/esm/lib/v3/v3.js.map +1 -1
- package/dist/esm/tests/integration/cdp-session-detached.spec.js +1 -1
- package/dist/esm/tests/integration/cdp-session-detached.spec.js.map +1 -1
- package/dist/esm/tests/integration/context-addInitScript.spec.js +104 -11
- package/dist/esm/tests/integration/context-addInitScript.spec.js.map +1 -1
- package/dist/esm/tests/integration/iframe-ctx-addInitScript-race.spec.d.ts +1 -0
- package/dist/esm/tests/integration/iframe-ctx-addInitScript-race.spec.js +217 -0
- package/dist/esm/tests/integration/iframe-ctx-addInitScript-race.spec.js.map +1 -0
- package/dist/esm/tests/integration/page-extra-http-headers.spec.d.ts +1 -0
- package/dist/esm/tests/integration/page-extra-http-headers.spec.js +83 -0
- package/dist/esm/tests/integration/page-extra-http-headers.spec.js.map +1 -0
- package/dist/esm/tests/integration/page-screenshot.spec.js +1 -1
- package/dist/esm/tests/integration/page-screenshot.spec.js.map +1 -1
- package/dist/esm/tests/integration/timeouts.spec.js +168 -0
- package/dist/esm/tests/integration/timeouts.spec.js.map +1 -1
- package/dist/esm/tests/unit/model-deprecation.test.js +5 -8
- package/dist/esm/tests/unit/model-deprecation.test.js.map +1 -1
- package/dist/esm/tests/unit/page-extra-http-headers.test.d.ts +1 -0
- package/dist/esm/tests/unit/page-extra-http-headers.test.js +90 -0
- package/dist/esm/tests/unit/page-extra-http-headers.test.js.map +1 -0
- package/dist/esm/tests/unit/public-api/llm-and-agents.test.js +13 -1
- package/dist/esm/tests/unit/public-api/llm-and-agents.test.js.map +1 -1
- package/dist/esm/tests/unit/public-api/public-types.test.js.map +1 -1
- package/package.json +2 -2
- package/dist/cjs/lib/v3/agent/tools/search.js.map +0 -1
- package/dist/cjs/tests/unit/rerender-missing-shadows.test.js +0 -209
- package/dist/cjs/tests/unit/rerender-missing-shadows.test.js.map +0 -1
- package/dist/esm/lib/v3/agent/tools/search.js.map +0 -1
- package/dist/esm/tests/unit/rerender-missing-shadows.test.js +0 -207
- package/dist/esm/tests/unit/rerender-missing-shadows.test.js.map +0 -1
- /package/dist/cjs/lib/v3/agent/tools/{search.d.ts → braveSearch.d.ts} +0 -0
- /package/dist/cjs/tests/{unit/rerender-missing-shadows.test.d.ts → integration/iframe-ctx-addInitScript-race.spec.d.ts} +0 -0
- /package/dist/{esm/tests/unit/rerender-missing-shadows.test.d.ts → cjs/tests/integration/page-extra-http-headers.spec.d.ts} +0 -0
- /package/dist/esm/lib/v3/agent/tools/{search.d.ts → braveSearch.d.ts} +0 -0
package/dist/esm/lib/v3/v3.js
CHANGED
|
@@ -63,11 +63,13 @@ import { resolveModel } from "../modelUtils.js";
|
|
|
63
63
|
import { StagehandAPIClient } from "./api.js";
|
|
64
64
|
import { validateExperimentalFeatures } from "./agent/utils/validateExperimentalFeatures.js";
|
|
65
65
|
import { flattenVariables } from "./agent/utils/variables.js";
|
|
66
|
-
import {
|
|
66
|
+
import { FlowLogger } from "./flowLogger.js";
|
|
67
|
+
import { getEventStore } from "./eventStore.js";
|
|
67
68
|
import { createTimeoutGuard } from "./handlers/handlerUtils/timeoutGuard.js";
|
|
68
69
|
import { ActTimeoutError } from "./types/public/sdkErrors.js";
|
|
69
70
|
const DEFAULT_MODEL_NAME = "openai/gpt-4.1-mini";
|
|
70
71
|
const DEFAULT_VIEWPORT = { width: 1288, height: 711 };
|
|
72
|
+
const DEFAULT_AGENT_TOOL_TIMEOUT_MS = 45000;
|
|
71
73
|
function resolveModelConfiguration(model) {
|
|
72
74
|
if (!model) {
|
|
73
75
|
return { modelName: DEFAULT_MODEL_NAME };
|
|
@@ -110,9 +112,18 @@ let V3 = (() => {
|
|
|
110
112
|
return class V3 {
|
|
111
113
|
static {
|
|
112
114
|
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
113
|
-
_act_decorators = [
|
|
114
|
-
|
|
115
|
-
|
|
115
|
+
_act_decorators = [FlowLogger.wrapWithLogging({
|
|
116
|
+
eventType: "StagehandAct",
|
|
117
|
+
eventIdSuffix: "4",
|
|
118
|
+
})];
|
|
119
|
+
_extract_decorators = [FlowLogger.wrapWithLogging({
|
|
120
|
+
eventType: "StagehandExtract",
|
|
121
|
+
eventIdSuffix: "4",
|
|
122
|
+
})];
|
|
123
|
+
_observe_decorators = [FlowLogger.wrapWithLogging({
|
|
124
|
+
eventType: "StagehandObserve",
|
|
125
|
+
eventIdSuffix: "4",
|
|
126
|
+
})];
|
|
116
127
|
__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);
|
|
117
128
|
__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);
|
|
118
129
|
__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);
|
|
@@ -197,6 +208,8 @@ let V3 = (() => {
|
|
|
197
208
|
stagehandLogger;
|
|
198
209
|
_history = [];
|
|
199
210
|
instanceId;
|
|
211
|
+
sessionId;
|
|
212
|
+
flowLoggerContext;
|
|
200
213
|
static _processGuardsInstalled = false;
|
|
201
214
|
static _instances = new Set();
|
|
202
215
|
cacheStorage;
|
|
@@ -205,6 +218,10 @@ let V3 = (() => {
|
|
|
205
218
|
apiClient = null;
|
|
206
219
|
keepAlive;
|
|
207
220
|
shutdownSupervisor = null;
|
|
221
|
+
detachEventStoreListener = null;
|
|
222
|
+
withLoggingContext(fn) {
|
|
223
|
+
return withInstanceLogContext(this.instanceId, fn);
|
|
224
|
+
}
|
|
208
225
|
stagehandMetrics = {
|
|
209
226
|
actPromptTokens: 0,
|
|
210
227
|
actCompletionTokens: 0,
|
|
@@ -236,6 +253,7 @@ let V3 = (() => {
|
|
|
236
253
|
this.externalLogger = opts.logger;
|
|
237
254
|
this.verbose = opts.verbose ?? 1;
|
|
238
255
|
this.instanceId = uuidv7();
|
|
256
|
+
this.sessionId = opts.sessionId ?? this.instanceId;
|
|
239
257
|
this.keepAlive =
|
|
240
258
|
opts.keepAlive ?? opts.browserbaseSessionCreateParams?.keepAlive;
|
|
241
259
|
// Create per-instance StagehandLogger (handles usePino, verbose, externalLogger)
|
|
@@ -328,8 +346,9 @@ let V3 = (() => {
|
|
|
328
346
|
act: this.act.bind(this),
|
|
329
347
|
});
|
|
330
348
|
this.opts = opts;
|
|
331
|
-
|
|
332
|
-
|
|
349
|
+
void getEventStore().initializeSession(this.sessionId, opts);
|
|
350
|
+
this.flowLoggerContext = FlowLogger.init(this.sessionId, this.bus);
|
|
351
|
+
this.detachEventStoreListener = getEventStore().attachBus(this.sessionId, this.bus);
|
|
333
352
|
// Track instance for global process guard handling
|
|
334
353
|
V3._instances.add(this);
|
|
335
354
|
}
|
|
@@ -536,7 +555,7 @@ let V3 = (() => {
|
|
|
536
555
|
*/
|
|
537
556
|
async init() {
|
|
538
557
|
try {
|
|
539
|
-
return await
|
|
558
|
+
return await this.withLoggingContext(async () => {
|
|
540
559
|
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);
|
|
541
560
|
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));
|
|
542
561
|
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));
|
|
@@ -552,6 +571,13 @@ let V3 = (() => {
|
|
|
552
571
|
}
|
|
553
572
|
}
|
|
554
573
|
const lbo = this.opts.localBrowserLaunchOptions ?? {};
|
|
574
|
+
if (lbo.cdpHeaders && !lbo.cdpUrl) {
|
|
575
|
+
this.logger({
|
|
576
|
+
category: "init",
|
|
577
|
+
message: "`cdpHeaders` was provided but `cdpUrl` is not set — cdpHeaders will be ignored. Set `cdpUrl` to connect to an existing browser via CDP.",
|
|
578
|
+
level: 2,
|
|
579
|
+
});
|
|
580
|
+
}
|
|
555
581
|
// If a CDP URL is provided, attach instead of launching.
|
|
556
582
|
if (lbo.cdpUrl) {
|
|
557
583
|
this.logger({
|
|
@@ -561,10 +587,9 @@ let V3 = (() => {
|
|
|
561
587
|
});
|
|
562
588
|
this.ctx = await V3Context.create(lbo.cdpUrl, {
|
|
563
589
|
env: "LOCAL",
|
|
590
|
+
cdpHeaders: lbo.cdpHeaders,
|
|
564
591
|
});
|
|
565
|
-
|
|
566
|
-
this.ctx.conn.cdpLogger = (info) => SessionFileLogger.logCdpCallEvent(info, logCtx);
|
|
567
|
-
this.ctx.conn.cdpEventLogger = (info) => SessionFileLogger.logCdpMessageEvent(info, logCtx);
|
|
592
|
+
this.ctx.conn.flowLoggerContext = this.flowLoggerContext;
|
|
568
593
|
this.ctx.conn.onTransportClosed(this._onCdpClosed);
|
|
569
594
|
this.state = {
|
|
570
595
|
kind: "LOCAL",
|
|
@@ -660,9 +685,7 @@ let V3 = (() => {
|
|
|
660
685
|
env: "LOCAL",
|
|
661
686
|
localBrowserLaunchOptions: lbo,
|
|
662
687
|
});
|
|
663
|
-
|
|
664
|
-
this.ctx.conn.cdpLogger = (info) => SessionFileLogger.logCdpCallEvent(info, logCtx);
|
|
665
|
-
this.ctx.conn.cdpEventLogger = (info) => SessionFileLogger.logCdpMessageEvent(info, logCtx);
|
|
688
|
+
this.ctx.conn.flowLoggerContext = this.flowLoggerContext;
|
|
666
689
|
this.ctx.conn.onTransportClosed(this._onCdpClosed);
|
|
667
690
|
this.state = {
|
|
668
691
|
kind: "LOCAL",
|
|
@@ -689,9 +712,6 @@ let V3 = (() => {
|
|
|
689
712
|
}
|
|
690
713
|
if (this.opts.env === "BROWSERBASE") {
|
|
691
714
|
const { apiKey, projectId } = this.requireBrowserbaseCreds();
|
|
692
|
-
if (!apiKey || !projectId) {
|
|
693
|
-
throw new MissingEnvironmentVariableError("BROWSERBASE_API_KEY and BROWSERBASE_PROJECT_ID", "Browserbase environment");
|
|
694
|
-
}
|
|
695
715
|
this.logger({
|
|
696
716
|
category: "init",
|
|
697
717
|
message: "Starting browserbase session",
|
|
@@ -710,18 +730,20 @@ let V3 = (() => {
|
|
|
710
730
|
logger: this.logger,
|
|
711
731
|
serverCache: this.opts.serverCache,
|
|
712
732
|
});
|
|
733
|
+
const { projectId: overrideProjectId, browserSettings, userMetadata, ...restSessionParams } = effectiveSessionParams;
|
|
734
|
+
const resolvedProjectId = overrideProjectId ?? projectId;
|
|
713
735
|
const createSessionPayload = {
|
|
714
|
-
projectId:
|
|
715
|
-
...
|
|
736
|
+
...(resolvedProjectId ? { projectId: resolvedProjectId } : {}),
|
|
737
|
+
...restSessionParams,
|
|
716
738
|
browserSettings: {
|
|
717
|
-
...(
|
|
718
|
-
viewport:
|
|
739
|
+
...(browserSettings ?? {}),
|
|
740
|
+
viewport: browserSettings?.viewport ?? {
|
|
719
741
|
width: 1288,
|
|
720
742
|
height: 711,
|
|
721
743
|
},
|
|
722
744
|
},
|
|
723
745
|
userMetadata: {
|
|
724
|
-
...(
|
|
746
|
+
...(userMetadata ?? {}),
|
|
725
747
|
stagehand: "true",
|
|
726
748
|
},
|
|
727
749
|
};
|
|
@@ -745,9 +767,7 @@ let V3 = (() => {
|
|
|
745
767
|
env: "BROWSERBASE",
|
|
746
768
|
apiClient: this.apiClient,
|
|
747
769
|
});
|
|
748
|
-
|
|
749
|
-
this.ctx.conn.cdpLogger = (info) => SessionFileLogger.logCdpCallEvent(info, logCtx);
|
|
750
|
-
this.ctx.conn.cdpEventLogger = (info) => SessionFileLogger.logCdpMessageEvent(info, logCtx);
|
|
770
|
+
this.ctx.conn.flowLoggerContext = this.flowLoggerContext;
|
|
751
771
|
this.ctx.conn.onTransportClosed(this._onCdpClosed);
|
|
752
772
|
this.state = { kind: "BROWSERBASE", sessionId, ws, bb };
|
|
753
773
|
this.browserbaseSessionId = sessionId;
|
|
@@ -809,6 +829,13 @@ let V3 = (() => {
|
|
|
809
829
|
// ignore cleanup errors
|
|
810
830
|
}
|
|
811
831
|
}
|
|
832
|
+
try {
|
|
833
|
+
this.detachEventStoreListener?.();
|
|
834
|
+
this.detachEventStoreListener = null;
|
|
835
|
+
}
|
|
836
|
+
catch {
|
|
837
|
+
// ignore cleanup errors
|
|
838
|
+
}
|
|
812
839
|
throw error;
|
|
813
840
|
}
|
|
814
841
|
}
|
|
@@ -852,7 +879,7 @@ let V3 = (() => {
|
|
|
852
879
|
this.browserbaseDebugUrl = undefined;
|
|
853
880
|
}
|
|
854
881
|
async act(input, options) {
|
|
855
|
-
return await
|
|
882
|
+
return await this.withLoggingContext(async () => {
|
|
856
883
|
if (!this.actHandler)
|
|
857
884
|
throw new StagehandNotInitializedError("act()");
|
|
858
885
|
let actResult;
|
|
@@ -869,10 +896,7 @@ let V3 = (() => {
|
|
|
869
896
|
});
|
|
870
897
|
}
|
|
871
898
|
else {
|
|
872
|
-
const
|
|
873
|
-
? options.timeout
|
|
874
|
-
: undefined;
|
|
875
|
-
const ensureTimeRemaining = createTimeoutGuard(effectiveTimeoutMs, (ms) => new ActTimeoutError(ms));
|
|
899
|
+
const ensureTimeRemaining = createTimeoutGuard(options?.timeout, (ms) => new ActTimeoutError(ms));
|
|
876
900
|
actResult = await this.actHandler.takeDeterministicAction({ ...input, selector }, v3Page, this.domSettleTimeoutMs, this.resolveLlmClient(options?.model), ensureTimeRemaining, options?.variables);
|
|
877
901
|
}
|
|
878
902
|
// history: record ObserveResult-based act call
|
|
@@ -939,7 +963,7 @@ let V3 = (() => {
|
|
|
939
963
|
});
|
|
940
964
|
}
|
|
941
965
|
async extract(a, b, c) {
|
|
942
|
-
return await
|
|
966
|
+
return await this.withLoggingContext(async () => {
|
|
943
967
|
if (!this.extractHandler) {
|
|
944
968
|
throw new StagehandNotInitializedError("extract()");
|
|
945
969
|
}
|
|
@@ -1007,7 +1031,7 @@ let V3 = (() => {
|
|
|
1007
1031
|
});
|
|
1008
1032
|
}
|
|
1009
1033
|
async observe(a, b) {
|
|
1010
|
-
return await
|
|
1034
|
+
return await this.withLoggingContext(async () => {
|
|
1011
1035
|
if (!this.observeHandler) {
|
|
1012
1036
|
throw new StagehandNotInitializedError("observe()");
|
|
1013
1037
|
}
|
|
@@ -1093,7 +1117,7 @@ let V3 = (() => {
|
|
|
1093
1117
|
try {
|
|
1094
1118
|
// Close session file logger
|
|
1095
1119
|
try {
|
|
1096
|
-
await
|
|
1120
|
+
await FlowLogger.close(this.flowLoggerContext);
|
|
1097
1121
|
}
|
|
1098
1122
|
catch {
|
|
1099
1123
|
// ignore
|
|
@@ -1129,6 +1153,13 @@ let V3 = (() => {
|
|
|
1129
1153
|
catch {
|
|
1130
1154
|
// ignore
|
|
1131
1155
|
}
|
|
1156
|
+
try {
|
|
1157
|
+
this.detachEventStoreListener?.();
|
|
1158
|
+
this.detachEventStoreListener = null;
|
|
1159
|
+
}
|
|
1160
|
+
catch {
|
|
1161
|
+
// ignore
|
|
1162
|
+
}
|
|
1132
1163
|
try {
|
|
1133
1164
|
this.bus.removeAllListeners();
|
|
1134
1165
|
}
|
|
@@ -1142,6 +1173,13 @@ let V3 = (() => {
|
|
|
1142
1173
|
V3._instances.delete(this);
|
|
1143
1174
|
}
|
|
1144
1175
|
}
|
|
1176
|
+
/**
|
|
1177
|
+
* Resolves the Browserbase API key from options or environment variables.
|
|
1178
|
+
* Returns undefined if no key is found (does not throw).
|
|
1179
|
+
*/
|
|
1180
|
+
get browserbaseApiKey() {
|
|
1181
|
+
return this.opts.apiKey || process.env.BROWSERBASE_API_KEY;
|
|
1182
|
+
}
|
|
1145
1183
|
/** Guard: ensure Browserbase credentials exist in options. */
|
|
1146
1184
|
requireBrowserbaseCreds() {
|
|
1147
1185
|
let { apiKey, projectId } = this.opts;
|
|
@@ -1151,17 +1189,13 @@ let V3 = (() => {
|
|
|
1151
1189
|
if (!projectId)
|
|
1152
1190
|
projectId =
|
|
1153
1191
|
process.env.BROWSERBASE_PROJECT_ID ?? process.env.BB_PROJECT_ID;
|
|
1154
|
-
if (!apiKey
|
|
1155
|
-
|
|
1156
|
-
if (!apiKey)
|
|
1157
|
-
missing.push("BROWSERBASE_API_KEY");
|
|
1158
|
-
if (!projectId)
|
|
1159
|
-
missing.push("BROWSERBASE_PROJECT_ID");
|
|
1160
|
-
throw new MissingEnvironmentVariableError(missing.join(", "), "Browserbase");
|
|
1192
|
+
if (!apiKey) {
|
|
1193
|
+
throw new MissingEnvironmentVariableError("BROWSERBASE_API_KEY", "Browserbase");
|
|
1161
1194
|
}
|
|
1162
1195
|
// Cache resolved values back into opts for consistency
|
|
1163
1196
|
this.opts.apiKey = apiKey;
|
|
1164
|
-
|
|
1197
|
+
if (projectId)
|
|
1198
|
+
this.opts.projectId = projectId;
|
|
1165
1199
|
// Informational log
|
|
1166
1200
|
this.logger({
|
|
1167
1201
|
category: "init",
|
|
@@ -1305,8 +1339,14 @@ let V3 = (() => {
|
|
|
1305
1339
|
const resolvedExecutionModel = options?.executionModel ?? options?.model;
|
|
1306
1340
|
const handler = new V3AgentHandler(this, this.logger, agentLlmClient, resolvedExecutionModel, options?.systemPrompt, tools, options?.mode);
|
|
1307
1341
|
const resolvedOptions = typeof instructionOrOptions === "string"
|
|
1308
|
-
? {
|
|
1309
|
-
|
|
1342
|
+
? {
|
|
1343
|
+
instruction: instructionOrOptions,
|
|
1344
|
+
toolTimeout: DEFAULT_AGENT_TOOL_TIMEOUT_MS,
|
|
1345
|
+
}
|
|
1346
|
+
: {
|
|
1347
|
+
...instructionOrOptions,
|
|
1348
|
+
toolTimeout: instructionOrOptions.toolTimeout ?? DEFAULT_AGENT_TOOL_TIMEOUT_MS,
|
|
1349
|
+
};
|
|
1310
1350
|
const callbacksWithSafety = resolvedOptions.callbacks;
|
|
1311
1351
|
if (callbacksWithSafety?.onSafetyConfirmation) {
|
|
1312
1352
|
throw new StagehandInvalidArgumentError('onSafetyConfirmation callback is only supported when using mode: "cua" agents.');
|
|
@@ -1386,145 +1426,59 @@ let V3 = (() => {
|
|
|
1386
1426
|
throw new CuaModelRequiredError(AVAILABLE_CUA_MODELS);
|
|
1387
1427
|
}
|
|
1388
1428
|
const agentConfigSignature = this.agentCache.buildConfigSignature(options);
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
agentConfig: options,
|
|
1394
|
-
executeOptions: typeof instructionOrOptions === "object"
|
|
1395
|
-
? instructionOrOptions
|
|
1396
|
-
: null,
|
|
1397
|
-
});
|
|
1398
|
-
SessionFileLogger.logAgentTaskStarted({
|
|
1399
|
-
invocation: "Agent.execute",
|
|
1400
|
-
args: [instructionOrOptions],
|
|
1401
|
-
});
|
|
1402
|
-
const tools = options?.integrations
|
|
1403
|
-
? await resolveTools(options.integrations, options.tools)
|
|
1404
|
-
: (options?.tools ?? {});
|
|
1405
|
-
const handler = new V3CuaAgentHandler(this, this.logger, {
|
|
1406
|
-
modelName,
|
|
1407
|
-
clientOptions,
|
|
1408
|
-
userProvidedInstructions: options.systemPrompt ??
|
|
1409
|
-
`You are a helpful assistant that can use a web browser.\nDo not ask follow up questions, the user will trust your judgement.`,
|
|
1410
|
-
}, tools);
|
|
1411
|
-
const resolvedOptions = typeof instructionOrOptions === "string"
|
|
1412
|
-
? { instruction: instructionOrOptions }
|
|
1413
|
-
: instructionOrOptions;
|
|
1414
|
-
if (resolvedOptions.page) {
|
|
1415
|
-
const normalizedPage = await this.normalizeToV3Page(resolvedOptions.page);
|
|
1416
|
-
this.ctx.setActivePage(normalizedPage);
|
|
1417
|
-
}
|
|
1418
|
-
const instruction = resolvedOptions.instruction.trim();
|
|
1419
|
-
const sanitizedOptions = this.agentCache.sanitizeExecuteOptions(resolvedOptions);
|
|
1420
|
-
const cacheVariables = flattenVariables(resolvedOptions.variables);
|
|
1421
|
-
let cacheContext = null;
|
|
1422
|
-
if (this.agentCache.shouldAttemptCache(instruction)) {
|
|
1423
|
-
const startPage = await this.ctx.awaitActivePage();
|
|
1424
|
-
cacheContext = await this.agentCache.prepareContext({
|
|
1425
|
-
instruction,
|
|
1426
|
-
options: sanitizedOptions,
|
|
1427
|
-
configSignature: agentConfigSignature,
|
|
1428
|
-
page: startPage,
|
|
1429
|
-
variables: cacheVariables,
|
|
1430
|
-
});
|
|
1431
|
-
if (cacheContext) {
|
|
1432
|
-
const replayed = await this.agentCache.tryReplay(cacheContext);
|
|
1433
|
-
if (replayed) {
|
|
1434
|
-
SessionFileLogger.logAgentTaskCompleted({ cacheHit: true });
|
|
1435
|
-
return replayed;
|
|
1436
|
-
}
|
|
1437
|
-
}
|
|
1438
|
-
}
|
|
1439
|
-
let agentSteps = [];
|
|
1440
|
-
const shouldRecordLocally = !!cacheContext && (!this.apiClient || this.experimental);
|
|
1441
|
-
if (shouldRecordLocally) {
|
|
1442
|
-
this.beginAgentReplayRecording();
|
|
1443
|
-
}
|
|
1444
|
-
let result;
|
|
1445
|
-
try {
|
|
1446
|
-
if (this.apiClient && !this.experimental) {
|
|
1447
|
-
const page = await this.ctx.awaitActivePage();
|
|
1448
|
-
result = await this.apiClient.agentExecute(options, resolvedOptions, page.mainFrameId(), !!cacheContext);
|
|
1449
|
-
if (cacheContext) {
|
|
1450
|
-
const transferredEntry = this.apiClient.consumeLatestAgentCacheEntry();
|
|
1451
|
-
await this.agentCache.storeTransferredEntry(transferredEntry);
|
|
1452
|
-
}
|
|
1453
|
-
}
|
|
1454
|
-
else {
|
|
1455
|
-
result = await handler.execute(instructionOrOptions);
|
|
1456
|
-
}
|
|
1457
|
-
if (shouldRecordLocally) {
|
|
1458
|
-
agentSteps = this.endAgentReplayRecording();
|
|
1459
|
-
}
|
|
1460
|
-
if (shouldRecordLocally &&
|
|
1461
|
-
cacheContext &&
|
|
1462
|
-
result.success &&
|
|
1463
|
-
agentSteps.length > 0) {
|
|
1464
|
-
await this.agentCache.store(cacheContext, agentSteps, result);
|
|
1465
|
-
}
|
|
1466
|
-
return result;
|
|
1467
|
-
}
|
|
1468
|
-
catch (err) {
|
|
1469
|
-
if (shouldRecordLocally)
|
|
1470
|
-
this.discardAgentReplayRecording();
|
|
1471
|
-
throw err;
|
|
1472
|
-
}
|
|
1473
|
-
finally {
|
|
1474
|
-
if (shouldRecordLocally) {
|
|
1475
|
-
this.discardAgentReplayRecording();
|
|
1476
|
-
}
|
|
1477
|
-
SessionFileLogger.logAgentTaskCompleted();
|
|
1478
|
-
}
|
|
1479
|
-
}),
|
|
1480
|
-
};
|
|
1481
|
-
}
|
|
1482
|
-
// Default: AISDK tools-based agent
|
|
1483
|
-
const agentConfigSignature = this.agentCache.buildConfigSignature(options);
|
|
1484
|
-
const isStreaming = options?.stream ?? false;
|
|
1485
|
-
return {
|
|
1486
|
-
execute: async (instructionOrOptions) => withInstanceLogContext(this.instanceId, async () => {
|
|
1429
|
+
const execute = FlowLogger.wrapWithLogging({
|
|
1430
|
+
eventType: "AgentExecute",
|
|
1431
|
+
eventIdSuffix: "3",
|
|
1432
|
+
})(async (instructionOrOptions) => this.withLoggingContext(async () => {
|
|
1487
1433
|
validateExperimentalFeatures({
|
|
1488
1434
|
isExperimental: this.experimental,
|
|
1489
1435
|
agentConfig: options,
|
|
1490
1436
|
executeOptions: typeof instructionOrOptions === "object"
|
|
1491
1437
|
? instructionOrOptions
|
|
1492
1438
|
: null,
|
|
1493
|
-
isStreaming,
|
|
1494
1439
|
});
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1440
|
+
const tools = options?.integrations
|
|
1441
|
+
? await resolveTools(options.integrations, options.tools)
|
|
1442
|
+
: (options?.tools ?? {});
|
|
1443
|
+
const handler = new V3CuaAgentHandler(this, this.logger, {
|
|
1444
|
+
modelName,
|
|
1445
|
+
clientOptions,
|
|
1446
|
+
userProvidedInstructions: options.systemPrompt ??
|
|
1447
|
+
`You are a helpful assistant that can use a web browser.\nDo not ask follow up questions, the user will trust your judgement.`,
|
|
1448
|
+
}, tools);
|
|
1449
|
+
const resolvedOptions = typeof instructionOrOptions === "string"
|
|
1450
|
+
? {
|
|
1451
|
+
instruction: instructionOrOptions,
|
|
1452
|
+
toolTimeout: DEFAULT_AGENT_TOOL_TIMEOUT_MS,
|
|
1453
|
+
}
|
|
1454
|
+
: {
|
|
1455
|
+
...instructionOrOptions,
|
|
1456
|
+
toolTimeout: instructionOrOptions.toolTimeout ??
|
|
1457
|
+
DEFAULT_AGENT_TOOL_TIMEOUT_MS,
|
|
1458
|
+
};
|
|
1459
|
+
if (resolvedOptions.page) {
|
|
1460
|
+
const normalizedPage = await this.normalizeToV3Page(resolvedOptions.page);
|
|
1461
|
+
this.ctx.setActivePage(normalizedPage);
|
|
1462
|
+
}
|
|
1463
|
+
const instruction = resolvedOptions.instruction.trim();
|
|
1464
|
+
const sanitizedOptions = this.agentCache.sanitizeExecuteOptions(resolvedOptions);
|
|
1465
|
+
const cacheVariables = flattenVariables(resolvedOptions.variables);
|
|
1466
|
+
let cacheContext = null;
|
|
1467
|
+
if (this.agentCache.shouldAttemptCache(instruction)) {
|
|
1468
|
+
const startPage = await this.ctx.awaitActivePage();
|
|
1469
|
+
cacheContext = await this.agentCache.prepareContext({
|
|
1470
|
+
instruction,
|
|
1471
|
+
options: sanitizedOptions,
|
|
1472
|
+
configSignature: agentConfigSignature,
|
|
1473
|
+
page: startPage,
|
|
1474
|
+
variables: cacheVariables,
|
|
1475
|
+
});
|
|
1502
1476
|
if (cacheContext) {
|
|
1503
|
-
const replayed = await this.agentCache.
|
|
1477
|
+
const replayed = await this.agentCache.tryReplay(cacheContext);
|
|
1504
1478
|
if (replayed) {
|
|
1505
|
-
SessionFileLogger.logAgentTaskCompleted({ cacheHit: true });
|
|
1506
1479
|
return replayed;
|
|
1507
1480
|
}
|
|
1508
1481
|
}
|
|
1509
|
-
const streamResult = await handler.stream(resolvedOptions);
|
|
1510
|
-
if (cacheContext) {
|
|
1511
|
-
const wrappedStream = this.agentCache.wrapStreamForCaching(cacheContext, streamResult, () => this.beginAgentReplayRecording(), () => this.endAgentReplayRecording(), () => this.discardAgentReplayRecording());
|
|
1512
|
-
// Log completion when stream is returned (stream completes asynchronously)
|
|
1513
|
-
SessionFileLogger.logAgentTaskCompleted();
|
|
1514
|
-
return wrappedStream;
|
|
1515
|
-
}
|
|
1516
|
-
// Log completion when stream is returned (stream completes asynchronously)
|
|
1517
|
-
SessionFileLogger.logAgentTaskCompleted();
|
|
1518
|
-
return streamResult;
|
|
1519
|
-
}
|
|
1520
|
-
// Non-streaming mode (default)
|
|
1521
|
-
const { handler, resolvedOptions, cacheContext, llmClient } = await this.prepareAgentExecution(options, instructionOrOptions, agentConfigSignature);
|
|
1522
|
-
if (cacheContext) {
|
|
1523
|
-
const replayed = await this.agentCache.tryReplay(cacheContext, llmClient);
|
|
1524
|
-
if (replayed) {
|
|
1525
|
-
SessionFileLogger.logAgentTaskCompleted({ cacheHit: true });
|
|
1526
|
-
return replayed;
|
|
1527
|
-
}
|
|
1528
1482
|
}
|
|
1529
1483
|
let agentSteps = [];
|
|
1530
1484
|
const shouldRecordLocally = !!cacheContext && (!this.apiClient || this.experimental);
|
|
@@ -1535,14 +1489,14 @@ let V3 = (() => {
|
|
|
1535
1489
|
try {
|
|
1536
1490
|
if (this.apiClient && !this.experimental) {
|
|
1537
1491
|
const page = await this.ctx.awaitActivePage();
|
|
1538
|
-
result = await this.apiClient.agentExecute(options
|
|
1492
|
+
result = await this.apiClient.agentExecute(options, resolvedOptions, page.mainFrameId(), !!cacheContext);
|
|
1539
1493
|
if (cacheContext) {
|
|
1540
1494
|
const transferredEntry = this.apiClient.consumeLatestAgentCacheEntry();
|
|
1541
1495
|
await this.agentCache.storeTransferredEntry(transferredEntry);
|
|
1542
1496
|
}
|
|
1543
1497
|
}
|
|
1544
1498
|
else {
|
|
1545
|
-
result = await handler.execute(
|
|
1499
|
+
result = await handler.execute(instructionOrOptions);
|
|
1546
1500
|
}
|
|
1547
1501
|
if (shouldRecordLocally) {
|
|
1548
1502
|
agentSteps = this.endAgentReplayRecording();
|
|
@@ -1564,9 +1518,93 @@ let V3 = (() => {
|
|
|
1564
1518
|
if (shouldRecordLocally) {
|
|
1565
1519
|
this.discardAgentReplayRecording();
|
|
1566
1520
|
}
|
|
1567
|
-
SessionFileLogger.logAgentTaskCompleted();
|
|
1568
1521
|
}
|
|
1569
|
-
})
|
|
1522
|
+
}));
|
|
1523
|
+
return {
|
|
1524
|
+
execute,
|
|
1525
|
+
};
|
|
1526
|
+
}
|
|
1527
|
+
// Default: AISDK tools-based agent
|
|
1528
|
+
const agentConfigSignature = this.agentCache.buildConfigSignature(options);
|
|
1529
|
+
const isStreaming = options?.stream ?? false;
|
|
1530
|
+
const execute = FlowLogger.wrapWithLogging({
|
|
1531
|
+
eventType: "AgentExecute",
|
|
1532
|
+
eventIdSuffix: "3",
|
|
1533
|
+
})(async (instructionOrOptions) => this.withLoggingContext(async () => {
|
|
1534
|
+
validateExperimentalFeatures({
|
|
1535
|
+
isExperimental: this.experimental,
|
|
1536
|
+
agentConfig: options,
|
|
1537
|
+
executeOptions: typeof instructionOrOptions === "object"
|
|
1538
|
+
? instructionOrOptions
|
|
1539
|
+
: null,
|
|
1540
|
+
isStreaming,
|
|
1541
|
+
});
|
|
1542
|
+
// Streaming mode
|
|
1543
|
+
if (isStreaming) {
|
|
1544
|
+
const { handler, resolvedOptions, cacheContext, llmClient } = await this.prepareAgentExecution(options, instructionOrOptions, agentConfigSignature);
|
|
1545
|
+
if (cacheContext) {
|
|
1546
|
+
const replayed = await this.agentCache.tryReplayAsStream(cacheContext, llmClient);
|
|
1547
|
+
if (replayed) {
|
|
1548
|
+
return replayed;
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
const streamResult = await handler.stream(resolvedOptions);
|
|
1552
|
+
if (cacheContext) {
|
|
1553
|
+
const wrappedStream = this.agentCache.wrapStreamForCaching(cacheContext, streamResult, () => this.beginAgentReplayRecording(), () => this.endAgentReplayRecording(), () => this.discardAgentReplayRecording());
|
|
1554
|
+
return wrappedStream;
|
|
1555
|
+
}
|
|
1556
|
+
return streamResult;
|
|
1557
|
+
}
|
|
1558
|
+
// Non-streaming mode (default)
|
|
1559
|
+
const { handler, resolvedOptions, cacheContext, llmClient } = await this.prepareAgentExecution(options, instructionOrOptions, agentConfigSignature);
|
|
1560
|
+
if (cacheContext) {
|
|
1561
|
+
const replayed = await this.agentCache.tryReplay(cacheContext, llmClient);
|
|
1562
|
+
if (replayed) {
|
|
1563
|
+
return replayed;
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
let agentSteps = [];
|
|
1567
|
+
const shouldRecordLocally = !!cacheContext && (!this.apiClient || this.experimental);
|
|
1568
|
+
if (shouldRecordLocally) {
|
|
1569
|
+
this.beginAgentReplayRecording();
|
|
1570
|
+
}
|
|
1571
|
+
let result;
|
|
1572
|
+
try {
|
|
1573
|
+
if (this.apiClient && !this.experimental) {
|
|
1574
|
+
const page = await this.ctx.awaitActivePage();
|
|
1575
|
+
result = await this.apiClient.agentExecute(options ?? {}, resolvedOptions, page.mainFrameId(), !!cacheContext);
|
|
1576
|
+
if (cacheContext) {
|
|
1577
|
+
const transferredEntry = this.apiClient.consumeLatestAgentCacheEntry();
|
|
1578
|
+
await this.agentCache.storeTransferredEntry(transferredEntry);
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
else {
|
|
1582
|
+
result = await handler.execute(resolvedOptions);
|
|
1583
|
+
}
|
|
1584
|
+
if (shouldRecordLocally) {
|
|
1585
|
+
agentSteps = this.endAgentReplayRecording();
|
|
1586
|
+
}
|
|
1587
|
+
if (shouldRecordLocally &&
|
|
1588
|
+
cacheContext &&
|
|
1589
|
+
result.success &&
|
|
1590
|
+
agentSteps.length > 0) {
|
|
1591
|
+
await this.agentCache.store(cacheContext, agentSteps, result);
|
|
1592
|
+
}
|
|
1593
|
+
return result;
|
|
1594
|
+
}
|
|
1595
|
+
catch (err) {
|
|
1596
|
+
if (shouldRecordLocally)
|
|
1597
|
+
this.discardAgentReplayRecording();
|
|
1598
|
+
throw err;
|
|
1599
|
+
}
|
|
1600
|
+
finally {
|
|
1601
|
+
if (shouldRecordLocally) {
|
|
1602
|
+
this.discardAgentReplayRecording();
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
}));
|
|
1606
|
+
return {
|
|
1607
|
+
execute,
|
|
1570
1608
|
};
|
|
1571
1609
|
}
|
|
1572
1610
|
};
|