@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/cjs/lib/v3/v3.js
CHANGED
|
@@ -103,10 +103,12 @@ const api_js_1 = require("./api.js");
|
|
|
103
103
|
const validateExperimentalFeatures_js_1 = require("./agent/utils/validateExperimentalFeatures.js");
|
|
104
104
|
const variables_js_1 = require("./agent/utils/variables.js");
|
|
105
105
|
const flowLogger_js_1 = require("./flowLogger.js");
|
|
106
|
+
const eventStore_js_1 = require("./eventStore.js");
|
|
106
107
|
const timeoutGuard_js_1 = require("./handlers/handlerUtils/timeoutGuard.js");
|
|
107
108
|
const sdkErrors_js_1 = require("./types/public/sdkErrors.js");
|
|
108
109
|
const DEFAULT_MODEL_NAME = "openai/gpt-4.1-mini";
|
|
109
110
|
const DEFAULT_VIEWPORT = { width: 1288, height: 711 };
|
|
111
|
+
const DEFAULT_AGENT_TOOL_TIMEOUT_MS = 45000;
|
|
110
112
|
function resolveModelConfiguration(model) {
|
|
111
113
|
if (!model) {
|
|
112
114
|
return { modelName: DEFAULT_MODEL_NAME };
|
|
@@ -149,9 +151,18 @@ let V3 = (() => {
|
|
|
149
151
|
return class V3 {
|
|
150
152
|
static {
|
|
151
153
|
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
152
|
-
_act_decorators = [
|
|
153
|
-
|
|
154
|
-
|
|
154
|
+
_act_decorators = [flowLogger_js_1.FlowLogger.wrapWithLogging({
|
|
155
|
+
eventType: "StagehandAct",
|
|
156
|
+
eventIdSuffix: "4",
|
|
157
|
+
})];
|
|
158
|
+
_extract_decorators = [flowLogger_js_1.FlowLogger.wrapWithLogging({
|
|
159
|
+
eventType: "StagehandExtract",
|
|
160
|
+
eventIdSuffix: "4",
|
|
161
|
+
})];
|
|
162
|
+
_observe_decorators = [flowLogger_js_1.FlowLogger.wrapWithLogging({
|
|
163
|
+
eventType: "StagehandObserve",
|
|
164
|
+
eventIdSuffix: "4",
|
|
165
|
+
})];
|
|
155
166
|
__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);
|
|
156
167
|
__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);
|
|
157
168
|
__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);
|
|
@@ -236,6 +247,8 @@ let V3 = (() => {
|
|
|
236
247
|
stagehandLogger;
|
|
237
248
|
_history = [];
|
|
238
249
|
instanceId;
|
|
250
|
+
sessionId;
|
|
251
|
+
flowLoggerContext;
|
|
239
252
|
static _processGuardsInstalled = false;
|
|
240
253
|
static _instances = new Set();
|
|
241
254
|
cacheStorage;
|
|
@@ -244,6 +257,10 @@ let V3 = (() => {
|
|
|
244
257
|
apiClient = null;
|
|
245
258
|
keepAlive;
|
|
246
259
|
shutdownSupervisor = null;
|
|
260
|
+
detachEventStoreListener = null;
|
|
261
|
+
withLoggingContext(fn) {
|
|
262
|
+
return (0, logger_js_2.withInstanceLogContext)(this.instanceId, fn);
|
|
263
|
+
}
|
|
247
264
|
stagehandMetrics = {
|
|
248
265
|
actPromptTokens: 0,
|
|
249
266
|
actCompletionTokens: 0,
|
|
@@ -275,6 +292,7 @@ let V3 = (() => {
|
|
|
275
292
|
this.externalLogger = opts.logger;
|
|
276
293
|
this.verbose = opts.verbose ?? 1;
|
|
277
294
|
this.instanceId = (0, uuid_1.v7)();
|
|
295
|
+
this.sessionId = opts.sessionId ?? this.instanceId;
|
|
278
296
|
this.keepAlive =
|
|
279
297
|
opts.keepAlive ?? opts.browserbaseSessionCreateParams?.keepAlive;
|
|
280
298
|
// Create per-instance StagehandLogger (handles usePino, verbose, externalLogger)
|
|
@@ -367,8 +385,9 @@ let V3 = (() => {
|
|
|
367
385
|
act: this.act.bind(this),
|
|
368
386
|
});
|
|
369
387
|
this.opts = opts;
|
|
370
|
-
|
|
371
|
-
flowLogger_js_1.
|
|
388
|
+
void (0, eventStore_js_1.getEventStore)().initializeSession(this.sessionId, opts);
|
|
389
|
+
this.flowLoggerContext = flowLogger_js_1.FlowLogger.init(this.sessionId, this.bus);
|
|
390
|
+
this.detachEventStoreListener = (0, eventStore_js_1.getEventStore)().attachBus(this.sessionId, this.bus);
|
|
372
391
|
// Track instance for global process guard handling
|
|
373
392
|
V3._instances.add(this);
|
|
374
393
|
}
|
|
@@ -575,7 +594,7 @@ let V3 = (() => {
|
|
|
575
594
|
*/
|
|
576
595
|
async init() {
|
|
577
596
|
try {
|
|
578
|
-
return await
|
|
597
|
+
return await this.withLoggingContext(async () => {
|
|
579
598
|
this.actHandler = new actHandler_js_1.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);
|
|
580
599
|
this.extractHandler = new extractHandler_js_1.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));
|
|
581
600
|
this.observeHandler = new observeHandler_js_1.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));
|
|
@@ -591,6 +610,13 @@ let V3 = (() => {
|
|
|
591
610
|
}
|
|
592
611
|
}
|
|
593
612
|
const lbo = this.opts.localBrowserLaunchOptions ?? {};
|
|
613
|
+
if (lbo.cdpHeaders && !lbo.cdpUrl) {
|
|
614
|
+
this.logger({
|
|
615
|
+
category: "init",
|
|
616
|
+
message: "`cdpHeaders` was provided but `cdpUrl` is not set — cdpHeaders will be ignored. Set `cdpUrl` to connect to an existing browser via CDP.",
|
|
617
|
+
level: 2,
|
|
618
|
+
});
|
|
619
|
+
}
|
|
594
620
|
// If a CDP URL is provided, attach instead of launching.
|
|
595
621
|
if (lbo.cdpUrl) {
|
|
596
622
|
this.logger({
|
|
@@ -600,10 +626,9 @@ let V3 = (() => {
|
|
|
600
626
|
});
|
|
601
627
|
this.ctx = await context_js_1.V3Context.create(lbo.cdpUrl, {
|
|
602
628
|
env: "LOCAL",
|
|
629
|
+
cdpHeaders: lbo.cdpHeaders,
|
|
603
630
|
});
|
|
604
|
-
|
|
605
|
-
this.ctx.conn.cdpLogger = (info) => flowLogger_js_1.SessionFileLogger.logCdpCallEvent(info, logCtx);
|
|
606
|
-
this.ctx.conn.cdpEventLogger = (info) => flowLogger_js_1.SessionFileLogger.logCdpMessageEvent(info, logCtx);
|
|
631
|
+
this.ctx.conn.flowLoggerContext = this.flowLoggerContext;
|
|
607
632
|
this.ctx.conn.onTransportClosed(this._onCdpClosed);
|
|
608
633
|
this.state = {
|
|
609
634
|
kind: "LOCAL",
|
|
@@ -699,9 +724,7 @@ let V3 = (() => {
|
|
|
699
724
|
env: "LOCAL",
|
|
700
725
|
localBrowserLaunchOptions: lbo,
|
|
701
726
|
});
|
|
702
|
-
|
|
703
|
-
this.ctx.conn.cdpLogger = (info) => flowLogger_js_1.SessionFileLogger.logCdpCallEvent(info, logCtx);
|
|
704
|
-
this.ctx.conn.cdpEventLogger = (info) => flowLogger_js_1.SessionFileLogger.logCdpMessageEvent(info, logCtx);
|
|
727
|
+
this.ctx.conn.flowLoggerContext = this.flowLoggerContext;
|
|
705
728
|
this.ctx.conn.onTransportClosed(this._onCdpClosed);
|
|
706
729
|
this.state = {
|
|
707
730
|
kind: "LOCAL",
|
|
@@ -728,9 +751,6 @@ let V3 = (() => {
|
|
|
728
751
|
}
|
|
729
752
|
if (this.opts.env === "BROWSERBASE") {
|
|
730
753
|
const { apiKey, projectId } = this.requireBrowserbaseCreds();
|
|
731
|
-
if (!apiKey || !projectId) {
|
|
732
|
-
throw new index_js_1.MissingEnvironmentVariableError("BROWSERBASE_API_KEY and BROWSERBASE_PROJECT_ID", "Browserbase environment");
|
|
733
|
-
}
|
|
734
754
|
this.logger({
|
|
735
755
|
category: "init",
|
|
736
756
|
message: "Starting browserbase session",
|
|
@@ -749,18 +769,20 @@ let V3 = (() => {
|
|
|
749
769
|
logger: this.logger,
|
|
750
770
|
serverCache: this.opts.serverCache,
|
|
751
771
|
});
|
|
772
|
+
const { projectId: overrideProjectId, browserSettings, userMetadata, ...restSessionParams } = effectiveSessionParams;
|
|
773
|
+
const resolvedProjectId = overrideProjectId ?? projectId;
|
|
752
774
|
const createSessionPayload = {
|
|
753
|
-
projectId:
|
|
754
|
-
...
|
|
775
|
+
...(resolvedProjectId ? { projectId: resolvedProjectId } : {}),
|
|
776
|
+
...restSessionParams,
|
|
755
777
|
browserSettings: {
|
|
756
|
-
...(
|
|
757
|
-
viewport:
|
|
778
|
+
...(browserSettings ?? {}),
|
|
779
|
+
viewport: browserSettings?.viewport ?? {
|
|
758
780
|
width: 1288,
|
|
759
781
|
height: 711,
|
|
760
782
|
},
|
|
761
783
|
},
|
|
762
784
|
userMetadata: {
|
|
763
|
-
...(
|
|
785
|
+
...(userMetadata ?? {}),
|
|
764
786
|
stagehand: "true",
|
|
765
787
|
},
|
|
766
788
|
};
|
|
@@ -784,9 +806,7 @@ let V3 = (() => {
|
|
|
784
806
|
env: "BROWSERBASE",
|
|
785
807
|
apiClient: this.apiClient,
|
|
786
808
|
});
|
|
787
|
-
|
|
788
|
-
this.ctx.conn.cdpLogger = (info) => flowLogger_js_1.SessionFileLogger.logCdpCallEvent(info, logCtx);
|
|
789
|
-
this.ctx.conn.cdpEventLogger = (info) => flowLogger_js_1.SessionFileLogger.logCdpMessageEvent(info, logCtx);
|
|
809
|
+
this.ctx.conn.flowLoggerContext = this.flowLoggerContext;
|
|
790
810
|
this.ctx.conn.onTransportClosed(this._onCdpClosed);
|
|
791
811
|
this.state = { kind: "BROWSERBASE", sessionId, ws, bb };
|
|
792
812
|
this.browserbaseSessionId = sessionId;
|
|
@@ -848,6 +868,13 @@ let V3 = (() => {
|
|
|
848
868
|
// ignore cleanup errors
|
|
849
869
|
}
|
|
850
870
|
}
|
|
871
|
+
try {
|
|
872
|
+
this.detachEventStoreListener?.();
|
|
873
|
+
this.detachEventStoreListener = null;
|
|
874
|
+
}
|
|
875
|
+
catch {
|
|
876
|
+
// ignore cleanup errors
|
|
877
|
+
}
|
|
851
878
|
throw error;
|
|
852
879
|
}
|
|
853
880
|
}
|
|
@@ -891,7 +918,7 @@ let V3 = (() => {
|
|
|
891
918
|
this.browserbaseDebugUrl = undefined;
|
|
892
919
|
}
|
|
893
920
|
async act(input, options) {
|
|
894
|
-
return await
|
|
921
|
+
return await this.withLoggingContext(async () => {
|
|
895
922
|
if (!this.actHandler)
|
|
896
923
|
throw new index_js_1.StagehandNotInitializedError("act()");
|
|
897
924
|
let actResult;
|
|
@@ -908,10 +935,7 @@ let V3 = (() => {
|
|
|
908
935
|
});
|
|
909
936
|
}
|
|
910
937
|
else {
|
|
911
|
-
const
|
|
912
|
-
? options.timeout
|
|
913
|
-
: undefined;
|
|
914
|
-
const ensureTimeRemaining = (0, timeoutGuard_js_1.createTimeoutGuard)(effectiveTimeoutMs, (ms) => new sdkErrors_js_1.ActTimeoutError(ms));
|
|
938
|
+
const ensureTimeRemaining = (0, timeoutGuard_js_1.createTimeoutGuard)(options?.timeout, (ms) => new sdkErrors_js_1.ActTimeoutError(ms));
|
|
915
939
|
actResult = await this.actHandler.takeDeterministicAction({ ...input, selector }, v3Page, this.domSettleTimeoutMs, this.resolveLlmClient(options?.model), ensureTimeRemaining, options?.variables);
|
|
916
940
|
}
|
|
917
941
|
// history: record ObserveResult-based act call
|
|
@@ -978,7 +1002,7 @@ let V3 = (() => {
|
|
|
978
1002
|
});
|
|
979
1003
|
}
|
|
980
1004
|
async extract(a, b, c) {
|
|
981
|
-
return await
|
|
1005
|
+
return await this.withLoggingContext(async () => {
|
|
982
1006
|
if (!this.extractHandler) {
|
|
983
1007
|
throw new index_js_1.StagehandNotInitializedError("extract()");
|
|
984
1008
|
}
|
|
@@ -1046,7 +1070,7 @@ let V3 = (() => {
|
|
|
1046
1070
|
});
|
|
1047
1071
|
}
|
|
1048
1072
|
async observe(a, b) {
|
|
1049
|
-
return await
|
|
1073
|
+
return await this.withLoggingContext(async () => {
|
|
1050
1074
|
if (!this.observeHandler) {
|
|
1051
1075
|
throw new index_js_1.StagehandNotInitializedError("observe()");
|
|
1052
1076
|
}
|
|
@@ -1132,7 +1156,7 @@ let V3 = (() => {
|
|
|
1132
1156
|
try {
|
|
1133
1157
|
// Close session file logger
|
|
1134
1158
|
try {
|
|
1135
|
-
await flowLogger_js_1.
|
|
1159
|
+
await flowLogger_js_1.FlowLogger.close(this.flowLoggerContext);
|
|
1136
1160
|
}
|
|
1137
1161
|
catch {
|
|
1138
1162
|
// ignore
|
|
@@ -1168,6 +1192,13 @@ let V3 = (() => {
|
|
|
1168
1192
|
catch {
|
|
1169
1193
|
// ignore
|
|
1170
1194
|
}
|
|
1195
|
+
try {
|
|
1196
|
+
this.detachEventStoreListener?.();
|
|
1197
|
+
this.detachEventStoreListener = null;
|
|
1198
|
+
}
|
|
1199
|
+
catch {
|
|
1200
|
+
// ignore
|
|
1201
|
+
}
|
|
1171
1202
|
try {
|
|
1172
1203
|
this.bus.removeAllListeners();
|
|
1173
1204
|
}
|
|
@@ -1181,6 +1212,13 @@ let V3 = (() => {
|
|
|
1181
1212
|
V3._instances.delete(this);
|
|
1182
1213
|
}
|
|
1183
1214
|
}
|
|
1215
|
+
/**
|
|
1216
|
+
* Resolves the Browserbase API key from options or environment variables.
|
|
1217
|
+
* Returns undefined if no key is found (does not throw).
|
|
1218
|
+
*/
|
|
1219
|
+
get browserbaseApiKey() {
|
|
1220
|
+
return this.opts.apiKey || process_1.default.env.BROWSERBASE_API_KEY;
|
|
1221
|
+
}
|
|
1184
1222
|
/** Guard: ensure Browserbase credentials exist in options. */
|
|
1185
1223
|
requireBrowserbaseCreds() {
|
|
1186
1224
|
let { apiKey, projectId } = this.opts;
|
|
@@ -1190,17 +1228,13 @@ let V3 = (() => {
|
|
|
1190
1228
|
if (!projectId)
|
|
1191
1229
|
projectId =
|
|
1192
1230
|
process_1.default.env.BROWSERBASE_PROJECT_ID ?? process_1.default.env.BB_PROJECT_ID;
|
|
1193
|
-
if (!apiKey
|
|
1194
|
-
|
|
1195
|
-
if (!apiKey)
|
|
1196
|
-
missing.push("BROWSERBASE_API_KEY");
|
|
1197
|
-
if (!projectId)
|
|
1198
|
-
missing.push("BROWSERBASE_PROJECT_ID");
|
|
1199
|
-
throw new index_js_1.MissingEnvironmentVariableError(missing.join(", "), "Browserbase");
|
|
1231
|
+
if (!apiKey) {
|
|
1232
|
+
throw new index_js_1.MissingEnvironmentVariableError("BROWSERBASE_API_KEY", "Browserbase");
|
|
1200
1233
|
}
|
|
1201
1234
|
// Cache resolved values back into opts for consistency
|
|
1202
1235
|
this.opts.apiKey = apiKey;
|
|
1203
|
-
|
|
1236
|
+
if (projectId)
|
|
1237
|
+
this.opts.projectId = projectId;
|
|
1204
1238
|
// Informational log
|
|
1205
1239
|
this.logger({
|
|
1206
1240
|
category: "init",
|
|
@@ -1344,8 +1378,14 @@ let V3 = (() => {
|
|
|
1344
1378
|
const resolvedExecutionModel = options?.executionModel ?? options?.model;
|
|
1345
1379
|
const handler = new v3AgentHandler_js_1.V3AgentHandler(this, this.logger, agentLlmClient, resolvedExecutionModel, options?.systemPrompt, tools, options?.mode);
|
|
1346
1380
|
const resolvedOptions = typeof instructionOrOptions === "string"
|
|
1347
|
-
? {
|
|
1348
|
-
|
|
1381
|
+
? {
|
|
1382
|
+
instruction: instructionOrOptions,
|
|
1383
|
+
toolTimeout: DEFAULT_AGENT_TOOL_TIMEOUT_MS,
|
|
1384
|
+
}
|
|
1385
|
+
: {
|
|
1386
|
+
...instructionOrOptions,
|
|
1387
|
+
toolTimeout: instructionOrOptions.toolTimeout ?? DEFAULT_AGENT_TOOL_TIMEOUT_MS,
|
|
1388
|
+
};
|
|
1349
1389
|
const callbacksWithSafety = resolvedOptions.callbacks;
|
|
1350
1390
|
if (callbacksWithSafety?.onSafetyConfirmation) {
|
|
1351
1391
|
throw new index_js_1.StagehandInvalidArgumentError('onSafetyConfirmation callback is only supported when using mode: "cua" agents.');
|
|
@@ -1425,145 +1465,59 @@ let V3 = (() => {
|
|
|
1425
1465
|
throw new index_js_1.CuaModelRequiredError(index_js_1.AVAILABLE_CUA_MODELS);
|
|
1426
1466
|
}
|
|
1427
1467
|
const agentConfigSignature = this.agentCache.buildConfigSignature(options);
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
agentConfig: options,
|
|
1433
|
-
executeOptions: typeof instructionOrOptions === "object"
|
|
1434
|
-
? instructionOrOptions
|
|
1435
|
-
: null,
|
|
1436
|
-
});
|
|
1437
|
-
flowLogger_js_1.SessionFileLogger.logAgentTaskStarted({
|
|
1438
|
-
invocation: "Agent.execute",
|
|
1439
|
-
args: [instructionOrOptions],
|
|
1440
|
-
});
|
|
1441
|
-
const tools = options?.integrations
|
|
1442
|
-
? await (0, utils_js_2.resolveTools)(options.integrations, options.tools)
|
|
1443
|
-
: (options?.tools ?? {});
|
|
1444
|
-
const handler = new v3CuaAgentHandler_js_1.V3CuaAgentHandler(this, this.logger, {
|
|
1445
|
-
modelName,
|
|
1446
|
-
clientOptions,
|
|
1447
|
-
userProvidedInstructions: options.systemPrompt ??
|
|
1448
|
-
`You are a helpful assistant that can use a web browser.\nDo not ask follow up questions, the user will trust your judgement.`,
|
|
1449
|
-
}, tools);
|
|
1450
|
-
const resolvedOptions = typeof instructionOrOptions === "string"
|
|
1451
|
-
? { instruction: instructionOrOptions }
|
|
1452
|
-
: instructionOrOptions;
|
|
1453
|
-
if (resolvedOptions.page) {
|
|
1454
|
-
const normalizedPage = await this.normalizeToV3Page(resolvedOptions.page);
|
|
1455
|
-
this.ctx.setActivePage(normalizedPage);
|
|
1456
|
-
}
|
|
1457
|
-
const instruction = resolvedOptions.instruction.trim();
|
|
1458
|
-
const sanitizedOptions = this.agentCache.sanitizeExecuteOptions(resolvedOptions);
|
|
1459
|
-
const cacheVariables = (0, variables_js_1.flattenVariables)(resolvedOptions.variables);
|
|
1460
|
-
let cacheContext = null;
|
|
1461
|
-
if (this.agentCache.shouldAttemptCache(instruction)) {
|
|
1462
|
-
const startPage = await this.ctx.awaitActivePage();
|
|
1463
|
-
cacheContext = await this.agentCache.prepareContext({
|
|
1464
|
-
instruction,
|
|
1465
|
-
options: sanitizedOptions,
|
|
1466
|
-
configSignature: agentConfigSignature,
|
|
1467
|
-
page: startPage,
|
|
1468
|
-
variables: cacheVariables,
|
|
1469
|
-
});
|
|
1470
|
-
if (cacheContext) {
|
|
1471
|
-
const replayed = await this.agentCache.tryReplay(cacheContext);
|
|
1472
|
-
if (replayed) {
|
|
1473
|
-
flowLogger_js_1.SessionFileLogger.logAgentTaskCompleted({ cacheHit: true });
|
|
1474
|
-
return replayed;
|
|
1475
|
-
}
|
|
1476
|
-
}
|
|
1477
|
-
}
|
|
1478
|
-
let agentSteps = [];
|
|
1479
|
-
const shouldRecordLocally = !!cacheContext && (!this.apiClient || this.experimental);
|
|
1480
|
-
if (shouldRecordLocally) {
|
|
1481
|
-
this.beginAgentReplayRecording();
|
|
1482
|
-
}
|
|
1483
|
-
let result;
|
|
1484
|
-
try {
|
|
1485
|
-
if (this.apiClient && !this.experimental) {
|
|
1486
|
-
const page = await this.ctx.awaitActivePage();
|
|
1487
|
-
result = await this.apiClient.agentExecute(options, resolvedOptions, page.mainFrameId(), !!cacheContext);
|
|
1488
|
-
if (cacheContext) {
|
|
1489
|
-
const transferredEntry = this.apiClient.consumeLatestAgentCacheEntry();
|
|
1490
|
-
await this.agentCache.storeTransferredEntry(transferredEntry);
|
|
1491
|
-
}
|
|
1492
|
-
}
|
|
1493
|
-
else {
|
|
1494
|
-
result = await handler.execute(instructionOrOptions);
|
|
1495
|
-
}
|
|
1496
|
-
if (shouldRecordLocally) {
|
|
1497
|
-
agentSteps = this.endAgentReplayRecording();
|
|
1498
|
-
}
|
|
1499
|
-
if (shouldRecordLocally &&
|
|
1500
|
-
cacheContext &&
|
|
1501
|
-
result.success &&
|
|
1502
|
-
agentSteps.length > 0) {
|
|
1503
|
-
await this.agentCache.store(cacheContext, agentSteps, result);
|
|
1504
|
-
}
|
|
1505
|
-
return result;
|
|
1506
|
-
}
|
|
1507
|
-
catch (err) {
|
|
1508
|
-
if (shouldRecordLocally)
|
|
1509
|
-
this.discardAgentReplayRecording();
|
|
1510
|
-
throw err;
|
|
1511
|
-
}
|
|
1512
|
-
finally {
|
|
1513
|
-
if (shouldRecordLocally) {
|
|
1514
|
-
this.discardAgentReplayRecording();
|
|
1515
|
-
}
|
|
1516
|
-
flowLogger_js_1.SessionFileLogger.logAgentTaskCompleted();
|
|
1517
|
-
}
|
|
1518
|
-
}),
|
|
1519
|
-
};
|
|
1520
|
-
}
|
|
1521
|
-
// Default: AISDK tools-based agent
|
|
1522
|
-
const agentConfigSignature = this.agentCache.buildConfigSignature(options);
|
|
1523
|
-
const isStreaming = options?.stream ?? false;
|
|
1524
|
-
return {
|
|
1525
|
-
execute: async (instructionOrOptions) => (0, logger_js_2.withInstanceLogContext)(this.instanceId, async () => {
|
|
1468
|
+
const execute = flowLogger_js_1.FlowLogger.wrapWithLogging({
|
|
1469
|
+
eventType: "AgentExecute",
|
|
1470
|
+
eventIdSuffix: "3",
|
|
1471
|
+
})(async (instructionOrOptions) => this.withLoggingContext(async () => {
|
|
1526
1472
|
(0, validateExperimentalFeatures_js_1.validateExperimentalFeatures)({
|
|
1527
1473
|
isExperimental: this.experimental,
|
|
1528
1474
|
agentConfig: options,
|
|
1529
1475
|
executeOptions: typeof instructionOrOptions === "object"
|
|
1530
1476
|
? instructionOrOptions
|
|
1531
1477
|
: null,
|
|
1532
|
-
isStreaming,
|
|
1533
1478
|
});
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1479
|
+
const tools = options?.integrations
|
|
1480
|
+
? await (0, utils_js_2.resolveTools)(options.integrations, options.tools)
|
|
1481
|
+
: (options?.tools ?? {});
|
|
1482
|
+
const handler = new v3CuaAgentHandler_js_1.V3CuaAgentHandler(this, this.logger, {
|
|
1483
|
+
modelName,
|
|
1484
|
+
clientOptions,
|
|
1485
|
+
userProvidedInstructions: options.systemPrompt ??
|
|
1486
|
+
`You are a helpful assistant that can use a web browser.\nDo not ask follow up questions, the user will trust your judgement.`,
|
|
1487
|
+
}, tools);
|
|
1488
|
+
const resolvedOptions = typeof instructionOrOptions === "string"
|
|
1489
|
+
? {
|
|
1490
|
+
instruction: instructionOrOptions,
|
|
1491
|
+
toolTimeout: DEFAULT_AGENT_TOOL_TIMEOUT_MS,
|
|
1492
|
+
}
|
|
1493
|
+
: {
|
|
1494
|
+
...instructionOrOptions,
|
|
1495
|
+
toolTimeout: instructionOrOptions.toolTimeout ??
|
|
1496
|
+
DEFAULT_AGENT_TOOL_TIMEOUT_MS,
|
|
1497
|
+
};
|
|
1498
|
+
if (resolvedOptions.page) {
|
|
1499
|
+
const normalizedPage = await this.normalizeToV3Page(resolvedOptions.page);
|
|
1500
|
+
this.ctx.setActivePage(normalizedPage);
|
|
1501
|
+
}
|
|
1502
|
+
const instruction = resolvedOptions.instruction.trim();
|
|
1503
|
+
const sanitizedOptions = this.agentCache.sanitizeExecuteOptions(resolvedOptions);
|
|
1504
|
+
const cacheVariables = (0, variables_js_1.flattenVariables)(resolvedOptions.variables);
|
|
1505
|
+
let cacheContext = null;
|
|
1506
|
+
if (this.agentCache.shouldAttemptCache(instruction)) {
|
|
1507
|
+
const startPage = await this.ctx.awaitActivePage();
|
|
1508
|
+
cacheContext = await this.agentCache.prepareContext({
|
|
1509
|
+
instruction,
|
|
1510
|
+
options: sanitizedOptions,
|
|
1511
|
+
configSignature: agentConfigSignature,
|
|
1512
|
+
page: startPage,
|
|
1513
|
+
variables: cacheVariables,
|
|
1514
|
+
});
|
|
1541
1515
|
if (cacheContext) {
|
|
1542
|
-
const replayed = await this.agentCache.
|
|
1516
|
+
const replayed = await this.agentCache.tryReplay(cacheContext);
|
|
1543
1517
|
if (replayed) {
|
|
1544
|
-
flowLogger_js_1.SessionFileLogger.logAgentTaskCompleted({ cacheHit: true });
|
|
1545
1518
|
return replayed;
|
|
1546
1519
|
}
|
|
1547
1520
|
}
|
|
1548
|
-
const streamResult = await handler.stream(resolvedOptions);
|
|
1549
|
-
if (cacheContext) {
|
|
1550
|
-
const wrappedStream = this.agentCache.wrapStreamForCaching(cacheContext, streamResult, () => this.beginAgentReplayRecording(), () => this.endAgentReplayRecording(), () => this.discardAgentReplayRecording());
|
|
1551
|
-
// Log completion when stream is returned (stream completes asynchronously)
|
|
1552
|
-
flowLogger_js_1.SessionFileLogger.logAgentTaskCompleted();
|
|
1553
|
-
return wrappedStream;
|
|
1554
|
-
}
|
|
1555
|
-
// Log completion when stream is returned (stream completes asynchronously)
|
|
1556
|
-
flowLogger_js_1.SessionFileLogger.logAgentTaskCompleted();
|
|
1557
|
-
return streamResult;
|
|
1558
|
-
}
|
|
1559
|
-
// Non-streaming mode (default)
|
|
1560
|
-
const { handler, resolvedOptions, cacheContext, llmClient } = await this.prepareAgentExecution(options, instructionOrOptions, agentConfigSignature);
|
|
1561
|
-
if (cacheContext) {
|
|
1562
|
-
const replayed = await this.agentCache.tryReplay(cacheContext, llmClient);
|
|
1563
|
-
if (replayed) {
|
|
1564
|
-
flowLogger_js_1.SessionFileLogger.logAgentTaskCompleted({ cacheHit: true });
|
|
1565
|
-
return replayed;
|
|
1566
|
-
}
|
|
1567
1521
|
}
|
|
1568
1522
|
let agentSteps = [];
|
|
1569
1523
|
const shouldRecordLocally = !!cacheContext && (!this.apiClient || this.experimental);
|
|
@@ -1574,14 +1528,14 @@ let V3 = (() => {
|
|
|
1574
1528
|
try {
|
|
1575
1529
|
if (this.apiClient && !this.experimental) {
|
|
1576
1530
|
const page = await this.ctx.awaitActivePage();
|
|
1577
|
-
result = await this.apiClient.agentExecute(options
|
|
1531
|
+
result = await this.apiClient.agentExecute(options, resolvedOptions, page.mainFrameId(), !!cacheContext);
|
|
1578
1532
|
if (cacheContext) {
|
|
1579
1533
|
const transferredEntry = this.apiClient.consumeLatestAgentCacheEntry();
|
|
1580
1534
|
await this.agentCache.storeTransferredEntry(transferredEntry);
|
|
1581
1535
|
}
|
|
1582
1536
|
}
|
|
1583
1537
|
else {
|
|
1584
|
-
result = await handler.execute(
|
|
1538
|
+
result = await handler.execute(instructionOrOptions);
|
|
1585
1539
|
}
|
|
1586
1540
|
if (shouldRecordLocally) {
|
|
1587
1541
|
agentSteps = this.endAgentReplayRecording();
|
|
@@ -1603,9 +1557,93 @@ let V3 = (() => {
|
|
|
1603
1557
|
if (shouldRecordLocally) {
|
|
1604
1558
|
this.discardAgentReplayRecording();
|
|
1605
1559
|
}
|
|
1606
|
-
flowLogger_js_1.SessionFileLogger.logAgentTaskCompleted();
|
|
1607
1560
|
}
|
|
1608
|
-
})
|
|
1561
|
+
}));
|
|
1562
|
+
return {
|
|
1563
|
+
execute,
|
|
1564
|
+
};
|
|
1565
|
+
}
|
|
1566
|
+
// Default: AISDK tools-based agent
|
|
1567
|
+
const agentConfigSignature = this.agentCache.buildConfigSignature(options);
|
|
1568
|
+
const isStreaming = options?.stream ?? false;
|
|
1569
|
+
const execute = flowLogger_js_1.FlowLogger.wrapWithLogging({
|
|
1570
|
+
eventType: "AgentExecute",
|
|
1571
|
+
eventIdSuffix: "3",
|
|
1572
|
+
})(async (instructionOrOptions) => this.withLoggingContext(async () => {
|
|
1573
|
+
(0, validateExperimentalFeatures_js_1.validateExperimentalFeatures)({
|
|
1574
|
+
isExperimental: this.experimental,
|
|
1575
|
+
agentConfig: options,
|
|
1576
|
+
executeOptions: typeof instructionOrOptions === "object"
|
|
1577
|
+
? instructionOrOptions
|
|
1578
|
+
: null,
|
|
1579
|
+
isStreaming,
|
|
1580
|
+
});
|
|
1581
|
+
// Streaming mode
|
|
1582
|
+
if (isStreaming) {
|
|
1583
|
+
const { handler, resolvedOptions, cacheContext, llmClient } = await this.prepareAgentExecution(options, instructionOrOptions, agentConfigSignature);
|
|
1584
|
+
if (cacheContext) {
|
|
1585
|
+
const replayed = await this.agentCache.tryReplayAsStream(cacheContext, llmClient);
|
|
1586
|
+
if (replayed) {
|
|
1587
|
+
return replayed;
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
const streamResult = await handler.stream(resolvedOptions);
|
|
1591
|
+
if (cacheContext) {
|
|
1592
|
+
const wrappedStream = this.agentCache.wrapStreamForCaching(cacheContext, streamResult, () => this.beginAgentReplayRecording(), () => this.endAgentReplayRecording(), () => this.discardAgentReplayRecording());
|
|
1593
|
+
return wrappedStream;
|
|
1594
|
+
}
|
|
1595
|
+
return streamResult;
|
|
1596
|
+
}
|
|
1597
|
+
// Non-streaming mode (default)
|
|
1598
|
+
const { handler, resolvedOptions, cacheContext, llmClient } = await this.prepareAgentExecution(options, instructionOrOptions, agentConfigSignature);
|
|
1599
|
+
if (cacheContext) {
|
|
1600
|
+
const replayed = await this.agentCache.tryReplay(cacheContext, llmClient);
|
|
1601
|
+
if (replayed) {
|
|
1602
|
+
return replayed;
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
let agentSteps = [];
|
|
1606
|
+
const shouldRecordLocally = !!cacheContext && (!this.apiClient || this.experimental);
|
|
1607
|
+
if (shouldRecordLocally) {
|
|
1608
|
+
this.beginAgentReplayRecording();
|
|
1609
|
+
}
|
|
1610
|
+
let result;
|
|
1611
|
+
try {
|
|
1612
|
+
if (this.apiClient && !this.experimental) {
|
|
1613
|
+
const page = await this.ctx.awaitActivePage();
|
|
1614
|
+
result = await this.apiClient.agentExecute(options ?? {}, resolvedOptions, page.mainFrameId(), !!cacheContext);
|
|
1615
|
+
if (cacheContext) {
|
|
1616
|
+
const transferredEntry = this.apiClient.consumeLatestAgentCacheEntry();
|
|
1617
|
+
await this.agentCache.storeTransferredEntry(transferredEntry);
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
else {
|
|
1621
|
+
result = await handler.execute(resolvedOptions);
|
|
1622
|
+
}
|
|
1623
|
+
if (shouldRecordLocally) {
|
|
1624
|
+
agentSteps = this.endAgentReplayRecording();
|
|
1625
|
+
}
|
|
1626
|
+
if (shouldRecordLocally &&
|
|
1627
|
+
cacheContext &&
|
|
1628
|
+
result.success &&
|
|
1629
|
+
agentSteps.length > 0) {
|
|
1630
|
+
await this.agentCache.store(cacheContext, agentSteps, result);
|
|
1631
|
+
}
|
|
1632
|
+
return result;
|
|
1633
|
+
}
|
|
1634
|
+
catch (err) {
|
|
1635
|
+
if (shouldRecordLocally)
|
|
1636
|
+
this.discardAgentReplayRecording();
|
|
1637
|
+
throw err;
|
|
1638
|
+
}
|
|
1639
|
+
finally {
|
|
1640
|
+
if (shouldRecordLocally) {
|
|
1641
|
+
this.discardAgentReplayRecording();
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
}));
|
|
1645
|
+
return {
|
|
1646
|
+
execute,
|
|
1609
1647
|
};
|
|
1610
1648
|
}
|
|
1611
1649
|
};
|