@browserbasehq/orca 3.1.0-patch.4 → 3.2.0-middleware.1
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/AgentClient.d.ts +8 -0
- package/dist/cjs/lib/v3/agent/AgentClient.js +13 -0
- package/dist/cjs/lib/v3/agent/AgentClient.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 +6 -7
- package/dist/cjs/lib/v3/agent/AnthropicCUAClient.js.map +1 -1
- package/dist/cjs/lib/v3/agent/GoogleCUAClient.js +6 -7
- package/dist/cjs/lib/v3/agent/GoogleCUAClient.js.map +1 -1
- package/dist/cjs/lib/v3/agent/MicrosoftCUAClient.js +1 -0
- package/dist/cjs/lib/v3/agent/MicrosoftCUAClient.js.map +1 -1
- package/dist/cjs/lib/v3/agent/OpenAICUAClient.d.ts +4 -4
- package/dist/cjs/lib/v3/agent/OpenAICUAClient.js +67 -8
- package/dist/cjs/lib/v3/agent/OpenAICUAClient.js.map +1 -1
- package/dist/cjs/lib/v3/agent/prompts/agentSystemPrompt.d.ts +4 -2
- package/dist/cjs/lib/v3/agent/prompts/agentSystemPrompt.js +7 -7
- 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 +11 -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 +49 -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/clickAndHold.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 +7 -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 -2
- package/dist/cjs/lib/v3/agent/tools/fillform.js +56 -45
- 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 +63 -11
- package/dist/cjs/lib/v3/agent/tools/index.js.map +1 -1
- package/dist/cjs/lib/v3/agent/tools/keys.d.ts +1 -1
- package/dist/cjs/lib/v3/agent/tools/keys.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/captchaSolver.d.ts +76 -0
- package/dist/cjs/lib/v3/agent/utils/captchaSolver.js +175 -0
- package/dist/cjs/lib/v3/agent/utils/captchaSolver.js.map +1 -0
- 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/flowlogger/EventEmitter.d.ts +7 -0
- package/dist/cjs/lib/v3/flowlogger/EventEmitter.js +30 -0
- package/dist/cjs/lib/v3/flowlogger/EventEmitter.js.map +1 -0
- package/dist/cjs/lib/v3/flowlogger/EventSink.d.ts +44 -0
- package/dist/cjs/lib/v3/flowlogger/EventSink.js +217 -0
- package/dist/cjs/lib/v3/flowlogger/EventSink.js.map +1 -0
- package/dist/cjs/lib/v3/flowlogger/EventStore.d.ts +26 -0
- package/dist/cjs/lib/v3/flowlogger/EventStore.js +135 -0
- package/dist/cjs/lib/v3/flowlogger/EventStore.js.map +1 -0
- package/dist/cjs/lib/v3/flowlogger/FlowLogger.d.ts +99 -0
- package/dist/cjs/lib/v3/flowlogger/FlowLogger.js +591 -0
- package/dist/cjs/lib/v3/flowlogger/FlowLogger.js.map +1 -0
- package/dist/cjs/lib/v3/flowlogger/prettify.d.ts +6 -0
- package/dist/cjs/lib/v3/flowlogger/prettify.js +395 -0
- package/dist/cjs/lib/v3/flowlogger/prettify.js.map +1 -0
- 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 +43 -57
- 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 +2 -5
- package/dist/cjs/lib/v3/handlers/v3AgentHandler.js +130 -91
- package/dist/cjs/lib/v3/handlers/v3AgentHandler.js.map +1 -1
- package/dist/cjs/lib/v3/handlers/v3CuaAgentHandler.d.ts +5 -0
- package/dist/cjs/lib/v3/handlers/v3CuaAgentHandler.js +134 -14
- 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.d.ts +5 -2
- package/dist/cjs/lib/v3/llm/LLMProvider.js +13 -11
- package/dist/cjs/lib/v3/llm/LLMProvider.js.map +1 -1
- package/dist/cjs/lib/v3/llm/aisdk.js +11 -17
- 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/cache.d.ts +0 -1
- package/dist/cjs/lib/v3/types/private/cache.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 +7 -0
- package/dist/cjs/lib/v3/types/public/api.js +9 -0
- package/dist/cjs/lib/v3/types/public/api.js.map +1 -1
- package/dist/cjs/lib/v3/types/public/model.d.ts +12 -3
- package/dist/cjs/lib/v3/types/public/model.js.map +1 -1
- package/dist/cjs/lib/v3/types/public/options.d.ts +8 -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 +180 -20
- 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 +84 -21
- 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 +26 -3
- package/dist/cjs/lib/v3/v3.js +242 -180
- package/dist/cjs/lib/v3/v3.js.map +1 -1
- package/dist/cjs/lib/version.d.ts +1 -1
- package/dist/cjs/lib/version.js +1 -1
- package/dist/cjs/lib/version.js.map +1 -1
- package/dist/cjs/tests/integration/agent-captcha-autosolve.spec.js +56 -0
- package/dist/cjs/tests/integration/agent-captcha-autosolve.spec.js.map +1 -0
- package/dist/cjs/tests/integration/agent-hybrid-mode.spec.js +6 -6
- package/dist/cjs/tests/integration/agent-hybrid-mode.spec.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/flowLogger.spec.js +714 -0
- package/dist/cjs/tests/integration/flowLogger.spec.js.map +1 -0
- package/dist/cjs/tests/integration/iframe-ctx-addInitScript-race.spec.d.ts +1 -0
- 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.d.ts +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/testUtils.d.ts +33 -0
- package/dist/cjs/tests/integration/testUtils.js +144 -0
- package/dist/cjs/tests/integration/testUtils.js.map +1 -1
- package/dist/cjs/tests/integration/timeouts.spec.js +278 -0
- package/dist/cjs/tests/integration/timeouts.spec.js.map +1 -1
- package/dist/cjs/tests/unit/agent-captcha-hooks.test.d.ts +1 -0
- package/dist/cjs/tests/unit/agent-captcha-hooks.test.js +285 -0
- package/dist/cjs/tests/unit/agent-captcha-hooks.test.js.map +1 -0
- package/dist/cjs/tests/unit/agent-execution-model.test.js +1 -1
- package/dist/cjs/tests/unit/agent-execution-model.test.js.map +1 -1
- package/dist/cjs/tests/unit/browserbase-session-accessors.test.js +20 -0
- package/dist/cjs/tests/unit/browserbase-session-accessors.test.js.map +1 -1
- package/dist/cjs/tests/unit/captcha-solver.test.d.ts +1 -0
- package/dist/cjs/tests/unit/captcha-solver.test.js +154 -0
- package/dist/cjs/tests/unit/captcha-solver.test.js.map +1 -0
- package/dist/cjs/tests/unit/flowlogger-capturing-cdp.test.d.ts +1 -0
- package/dist/cjs/tests/unit/flowlogger-capturing-cdp.test.js +95 -0
- package/dist/cjs/tests/unit/flowlogger-capturing-cdp.test.js.map +1 -0
- package/dist/cjs/tests/unit/flowlogger-capturing-llm.test.d.ts +1 -0
- package/dist/cjs/tests/unit/flowlogger-capturing-llm.test.js +43 -0
- package/dist/cjs/tests/unit/flowlogger-capturing-llm.test.js.map +1 -0
- package/dist/cjs/tests/unit/flowlogger-eventstore.test.d.ts +1 -0
- package/dist/cjs/tests/unit/flowlogger-eventstore.test.js +250 -0
- package/dist/cjs/tests/unit/flowlogger-eventstore.test.js.map +1 -0
- package/dist/cjs/tests/unit/llm-middleware.test.d.ts +1 -0
- package/dist/cjs/tests/unit/llm-middleware.test.js +495 -0
- package/dist/cjs/tests/unit/llm-middleware.test.js.map +1 -0
- package/dist/cjs/tests/unit/model-deprecation.test.js +5 -8
- package/dist/cjs/tests/unit/model-deprecation.test.js.map +1 -1
- package/dist/cjs/tests/unit/openai-cua-client.test.d.ts +1 -0
- package/dist/cjs/tests/unit/openai-cua-client.test.js +71 -0
- package/dist/cjs/tests/unit/openai-cua-client.test.js.map +1 -0
- 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/AgentClient.d.ts +8 -0
- package/dist/esm/lib/v3/agent/AgentClient.js +13 -0
- package/dist/esm/lib/v3/agent/AgentClient.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 +6 -7
- package/dist/esm/lib/v3/agent/AnthropicCUAClient.js.map +1 -1
- package/dist/esm/lib/v3/agent/GoogleCUAClient.js +6 -7
- package/dist/esm/lib/v3/agent/GoogleCUAClient.js.map +1 -1
- package/dist/esm/lib/v3/agent/MicrosoftCUAClient.js +1 -0
- package/dist/esm/lib/v3/agent/MicrosoftCUAClient.js.map +1 -1
- package/dist/esm/lib/v3/agent/OpenAICUAClient.d.ts +4 -4
- package/dist/esm/lib/v3/agent/OpenAICUAClient.js +67 -8
- package/dist/esm/lib/v3/agent/OpenAICUAClient.js.map +1 -1
- package/dist/esm/lib/v3/agent/prompts/agentSystemPrompt.d.ts +4 -2
- package/dist/esm/lib/v3/agent/prompts/agentSystemPrompt.js +7 -7
- 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 +11 -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 +49 -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/clickAndHold.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 +7 -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 -2
- package/dist/esm/lib/v3/agent/tools/fillform.js +56 -45
- 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 +63 -11
- package/dist/esm/lib/v3/agent/tools/index.js.map +1 -1
- package/dist/esm/lib/v3/agent/tools/keys.d.ts +1 -1
- package/dist/esm/lib/v3/agent/tools/keys.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/captchaSolver.d.ts +76 -0
- package/dist/esm/lib/v3/agent/utils/captchaSolver.js +171 -0
- package/dist/esm/lib/v3/agent/utils/captchaSolver.js.map +1 -0
- 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/flowlogger/EventEmitter.d.ts +7 -0
- package/dist/esm/lib/v3/flowlogger/EventEmitter.js +26 -0
- package/dist/esm/lib/v3/flowlogger/EventEmitter.js.map +1 -0
- package/dist/esm/lib/v3/flowlogger/EventSink.d.ts +44 -0
- package/dist/esm/lib/v3/flowlogger/EventSink.js +206 -0
- package/dist/esm/lib/v3/flowlogger/EventSink.js.map +1 -0
- package/dist/esm/lib/v3/flowlogger/EventStore.d.ts +26 -0
- package/dist/esm/lib/v3/flowlogger/EventStore.js +127 -0
- package/dist/esm/lib/v3/flowlogger/EventStore.js.map +1 -0
- package/dist/esm/lib/v3/flowlogger/FlowLogger.d.ts +99 -0
- package/dist/esm/lib/v3/flowlogger/FlowLogger.js +583 -0
- package/dist/esm/lib/v3/flowlogger/FlowLogger.js.map +1 -0
- package/dist/esm/lib/v3/flowlogger/prettify.d.ts +6 -0
- package/dist/esm/lib/v3/flowlogger/prettify.js +389 -0
- package/dist/esm/lib/v3/flowlogger/prettify.js.map +1 -0
- 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 +43 -57
- 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 +2 -5
- package/dist/esm/lib/v3/handlers/v3AgentHandler.js +131 -92
- package/dist/esm/lib/v3/handlers/v3AgentHandler.js.map +1 -1
- package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.d.ts +5 -0
- package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.js +134 -14
- 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.d.ts +5 -2
- package/dist/esm/lib/v3/llm/LLMProvider.js +14 -12
- 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/cache.d.ts +0 -1
- package/dist/esm/lib/v3/types/private/cache.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 +7 -0
- package/dist/esm/lib/v3/types/public/api.js +9 -0
- package/dist/esm/lib/v3/types/public/api.js.map +1 -1
- package/dist/esm/lib/v3/types/public/model.d.ts +12 -3
- package/dist/esm/lib/v3/types/public/model.js.map +1 -1
- package/dist/esm/lib/v3/types/public/options.d.ts +8 -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 +181 -21
- 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 +86 -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 +26 -3
- package/dist/esm/lib/v3/v3.js +242 -181
- package/dist/esm/lib/v3/v3.js.map +1 -1
- package/dist/esm/lib/version.d.ts +1 -1
- package/dist/esm/lib/version.js +1 -1
- package/dist/esm/lib/version.js.map +1 -1
- package/dist/esm/tests/integration/agent-captcha-autosolve.spec.d.ts +1 -0
- package/dist/esm/tests/integration/agent-captcha-autosolve.spec.js +54 -0
- package/dist/esm/tests/integration/agent-captcha-autosolve.spec.js.map +1 -0
- package/dist/esm/tests/integration/agent-hybrid-mode.spec.js +6 -6
- package/dist/esm/tests/integration/agent-hybrid-mode.spec.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/flowLogger.spec.d.ts +1 -0
- package/dist/esm/tests/integration/flowLogger.spec.js +712 -0
- package/dist/esm/tests/integration/flowLogger.spec.js.map +1 -0
- 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/testUtils.d.ts +33 -0
- package/dist/esm/tests/integration/testUtils.js +138 -0
- package/dist/esm/tests/integration/testUtils.js.map +1 -1
- package/dist/esm/tests/integration/timeouts.spec.js +278 -0
- package/dist/esm/tests/integration/timeouts.spec.js.map +1 -1
- package/dist/esm/tests/unit/agent-captcha-hooks.test.d.ts +1 -0
- package/dist/esm/tests/unit/agent-captcha-hooks.test.js +283 -0
- package/dist/esm/tests/unit/agent-captcha-hooks.test.js.map +1 -0
- package/dist/esm/tests/unit/agent-execution-model.test.js +1 -1
- package/dist/esm/tests/unit/agent-execution-model.test.js.map +1 -1
- package/dist/esm/tests/unit/browserbase-session-accessors.test.js +20 -0
- package/dist/esm/tests/unit/browserbase-session-accessors.test.js.map +1 -1
- package/dist/esm/tests/unit/captcha-solver.test.d.ts +1 -0
- package/dist/esm/tests/unit/captcha-solver.test.js +152 -0
- package/dist/esm/tests/unit/captcha-solver.test.js.map +1 -0
- package/dist/esm/tests/unit/flowlogger-capturing-cdp.test.d.ts +1 -0
- package/dist/esm/tests/unit/flowlogger-capturing-cdp.test.js +93 -0
- package/dist/esm/tests/unit/flowlogger-capturing-cdp.test.js.map +1 -0
- package/dist/esm/tests/unit/flowlogger-capturing-llm.test.d.ts +1 -0
- package/dist/esm/tests/unit/flowlogger-capturing-llm.test.js +41 -0
- package/dist/esm/tests/unit/flowlogger-capturing-llm.test.js.map +1 -0
- package/dist/esm/tests/unit/flowlogger-eventstore.test.d.ts +1 -0
- package/dist/esm/tests/unit/flowlogger-eventstore.test.js +248 -0
- package/dist/esm/tests/unit/flowlogger-eventstore.test.js.map +1 -0
- package/dist/esm/tests/unit/llm-middleware.test.d.ts +1 -0
- package/dist/esm/tests/unit/llm-middleware.test.js +460 -0
- package/dist/esm/tests/unit/llm-middleware.test.js.map +1 -0
- package/dist/esm/tests/unit/model-deprecation.test.js +5 -8
- package/dist/esm/tests/unit/model-deprecation.test.js.map +1 -1
- package/dist/esm/tests/unit/openai-cua-client.test.d.ts +1 -0
- package/dist/esm/tests/unit/openai-cua-client.test.js +69 -0
- package/dist/esm/tests/unit/openai-cua-client.test.js.map +1 -0
- 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 +5 -3
- package/dist/cjs/lib/v3/agent/tools/search.js.map +0 -1
- package/dist/cjs/lib/v3/flowLogger.d.ts +0 -139
- package/dist/cjs/lib/v3/flowLogger.js +0 -881
- package/dist/cjs/lib/v3/flowLogger.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/lib/v3/flowLogger.d.ts +0 -139
- package/dist/esm/lib/v3/flowLogger.js +0 -868
- package/dist/esm/lib/v3/flowLogger.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/agent-captcha-autosolve.spec.d.ts} +0 -0
- /package/dist/{esm/tests/unit/rerender-missing-shadows.test.d.ts → cjs/tests/integration/flowLogger.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
|
@@ -32,7 +32,6 @@ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn,
|
|
|
32
32
|
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
33
33
|
done = true;
|
|
34
34
|
};
|
|
35
|
-
import { EventEmitter } from "events";
|
|
36
35
|
import fs from "fs";
|
|
37
36
|
import os from "os";
|
|
38
37
|
import path from "path";
|
|
@@ -50,6 +49,7 @@ import { ExtractHandler } from "./handlers/extractHandler.js";
|
|
|
50
49
|
import { ObserveHandler } from "./handlers/observeHandler.js";
|
|
51
50
|
import { V3AgentHandler } from "./handlers/v3AgentHandler.js";
|
|
52
51
|
import { V3CuaAgentHandler } from "./handlers/v3CuaAgentHandler.js";
|
|
52
|
+
import { CAPTCHA_CUA_SYSTEM_PROMPT_NOTE } from "./agent/utils/captchaSolver.js";
|
|
53
53
|
import { createBrowserbaseSession } from "./launch/browserbase.js";
|
|
54
54
|
import { launchLocalChrome } from "./launch/local.js";
|
|
55
55
|
import { LLMProvider } from "./llm/LLMProvider.js";
|
|
@@ -63,12 +63,15 @@ 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/FlowLogger.js";
|
|
67
|
+
import { EventEmitterWithWildcardSupport } from "./flowlogger/EventEmitter.js";
|
|
68
|
+
import { EventStore } from "./flowlogger/EventStore.js";
|
|
67
69
|
import { createTimeoutGuard } from "./handlers/handlerUtils/timeoutGuard.js";
|
|
68
70
|
import { ActTimeoutError } from "./types/public/sdkErrors.js";
|
|
69
71
|
const DEFAULT_MODEL_NAME = "openai/gpt-4.1-mini";
|
|
70
72
|
const DEFAULT_VIEWPORT = { width: 1288, height: 711 };
|
|
71
|
-
|
|
73
|
+
const DEFAULT_AGENT_TOOL_TIMEOUT_MS = 45000;
|
|
74
|
+
export function resolveModelConfiguration(model) {
|
|
72
75
|
if (!model) {
|
|
73
76
|
return { modelName: DEFAULT_MODEL_NAME };
|
|
74
77
|
}
|
|
@@ -76,13 +79,14 @@ function resolveModelConfiguration(model) {
|
|
|
76
79
|
return { modelName: model };
|
|
77
80
|
}
|
|
78
81
|
if (model && typeof model === "object") {
|
|
79
|
-
const { modelName, ...clientOptions } = model;
|
|
82
|
+
const { modelName, middleware, ...clientOptions } = model;
|
|
80
83
|
if (!modelName) {
|
|
81
84
|
throw new StagehandInvalidArgumentError("model.modelName is required when providing client options.");
|
|
82
85
|
}
|
|
83
86
|
return {
|
|
84
87
|
modelName,
|
|
85
88
|
clientOptions: clientOptions,
|
|
89
|
+
middleware,
|
|
86
90
|
};
|
|
87
91
|
}
|
|
88
92
|
return { modelName: DEFAULT_MODEL_NAME };
|
|
@@ -110,9 +114,15 @@ let V3 = (() => {
|
|
|
110
114
|
return class V3 {
|
|
111
115
|
static {
|
|
112
116
|
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
113
|
-
_act_decorators = [
|
|
114
|
-
|
|
115
|
-
|
|
117
|
+
_act_decorators = [FlowLogger.wrapWithLogging({
|
|
118
|
+
eventType: "StagehandAct",
|
|
119
|
+
})];
|
|
120
|
+
_extract_decorators = [FlowLogger.wrapWithLogging({
|
|
121
|
+
eventType: "StagehandExtract",
|
|
122
|
+
})];
|
|
123
|
+
_observe_decorators = [FlowLogger.wrapWithLogging({
|
|
124
|
+
eventType: "StagehandObserve",
|
|
125
|
+
})];
|
|
116
126
|
__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
127
|
__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
128
|
__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);
|
|
@@ -129,7 +139,7 @@ let V3 = (() => {
|
|
|
129
139
|
* Event bus for internal communication.
|
|
130
140
|
* Emits events like 'screenshot' when screenshots are captured during agent execution.
|
|
131
141
|
*/
|
|
132
|
-
bus = new
|
|
142
|
+
bus = new EventEmitterWithWildcardSupport();
|
|
133
143
|
modelName;
|
|
134
144
|
modelClientOptions;
|
|
135
145
|
llmProvider;
|
|
@@ -154,6 +164,15 @@ let V3 = (() => {
|
|
|
154
164
|
get isBrowserbase() {
|
|
155
165
|
return this.state.kind === "BROWSERBASE";
|
|
156
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* Returns true if captcha auto-solving is enabled on Browserbase.
|
|
169
|
+
* Defaults to true when not explicitly set to false.
|
|
170
|
+
*/
|
|
171
|
+
get isCaptchaAutoSolveEnabled() {
|
|
172
|
+
return (this.isBrowserbase &&
|
|
173
|
+
this.opts.browserbaseSessionCreateParams?.browserSettings
|
|
174
|
+
?.solveCaptchas !== false);
|
|
175
|
+
}
|
|
157
176
|
/**
|
|
158
177
|
* Returns true if advancedStealth is enabled in Browserbase settings.
|
|
159
178
|
*/
|
|
@@ -197,6 +216,9 @@ let V3 = (() => {
|
|
|
197
216
|
stagehandLogger;
|
|
198
217
|
_history = [];
|
|
199
218
|
instanceId;
|
|
219
|
+
sessionId;
|
|
220
|
+
eventStore;
|
|
221
|
+
flowLoggerContext;
|
|
200
222
|
static _processGuardsInstalled = false;
|
|
201
223
|
static _instances = new Set();
|
|
202
224
|
cacheStorage;
|
|
@@ -236,6 +258,7 @@ let V3 = (() => {
|
|
|
236
258
|
this.externalLogger = opts.logger;
|
|
237
259
|
this.verbose = opts.verbose ?? 1;
|
|
238
260
|
this.instanceId = uuidv7();
|
|
261
|
+
this.sessionId = opts.sessionId ?? this.instanceId;
|
|
239
262
|
this.keepAlive =
|
|
240
263
|
opts.keepAlive ?? opts.browserbaseSessionCreateParams?.keepAlive;
|
|
241
264
|
// Create per-instance StagehandLogger (handles usePino, verbose, externalLogger)
|
|
@@ -267,11 +290,11 @@ let V3 = (() => {
|
|
|
267
290
|
catch {
|
|
268
291
|
// ignore
|
|
269
292
|
}
|
|
270
|
-
const { modelName, clientOptions } = resolveModelConfiguration(opts.model);
|
|
293
|
+
const { modelName, clientOptions, middleware } = resolveModelConfiguration(opts.model);
|
|
271
294
|
this.modelName = modelName;
|
|
272
295
|
this.experimental = opts.experimental ?? false;
|
|
273
296
|
this.logInferenceToFile = opts.logInferenceToFile ?? false;
|
|
274
|
-
this.llmProvider = new LLMProvider(this.logger);
|
|
297
|
+
this.llmProvider = new LLMProvider(this.logger, middleware);
|
|
275
298
|
this.domSettleTimeoutMs = opts.domSettleTimeout;
|
|
276
299
|
this.disableAPI = opts.disableAPI ?? false;
|
|
277
300
|
const baseClientOptions = clientOptions
|
|
@@ -328,8 +351,21 @@ let V3 = (() => {
|
|
|
328
351
|
act: this.act.bind(this),
|
|
329
352
|
});
|
|
330
353
|
this.opts = opts;
|
|
331
|
-
//
|
|
332
|
-
|
|
354
|
+
// FlowLogger always gets a per-instance session context and shared event
|
|
355
|
+
// bus. The attached EventStore decides which sinks are active:
|
|
356
|
+
// `BROWSERBASE_FLOW_LOGS=1` enables pretty stderr output,
|
|
357
|
+
// and `BROWSERBASE_CONFIG_DIR` enables the pretty/jsonl file sinks for this session.
|
|
358
|
+
this.eventStore = new EventStore(this.sessionId, opts);
|
|
359
|
+
this.flowLoggerContext = FlowLogger.init(this.sessionId, this.bus);
|
|
360
|
+
// Flow event pipeline:
|
|
361
|
+
// FlowLogger -> this.bus -> this.eventStore -> configured sinks/query history.
|
|
362
|
+
// V3 owns the bus for this session. EventStore is not another bus; it just
|
|
363
|
+
// receives already-emitted FlowEvents here, then fans them out to sinks and
|
|
364
|
+
// keeps the queryable per-session history used by /v4/log, parent/ancestor lookups, and tests.
|
|
365
|
+
// `on()` stores a strong reference to the handler, so the EventStore
|
|
366
|
+
// stays alive until this bus is garbage-collected with the rest of the V3
|
|
367
|
+
// object graph.
|
|
368
|
+
this.bus.on("*", this.eventStore.emit);
|
|
333
369
|
// Track instance for global process guard handling
|
|
334
370
|
V3._instances.add(this);
|
|
335
371
|
}
|
|
@@ -359,15 +395,18 @@ let V3 = (() => {
|
|
|
359
395
|
}
|
|
360
396
|
let modelName;
|
|
361
397
|
let clientOptions;
|
|
398
|
+
let perCallMiddleware;
|
|
362
399
|
if (typeof model === "string") {
|
|
363
400
|
modelName = model;
|
|
364
401
|
}
|
|
365
402
|
else {
|
|
366
|
-
const { modelName: overrideModelName, ...rest } = model;
|
|
403
|
+
const { modelName: overrideModelName, middleware, ...rest } = model;
|
|
367
404
|
modelName = overrideModelName;
|
|
368
405
|
clientOptions = rest;
|
|
406
|
+
perCallMiddleware = middleware;
|
|
369
407
|
}
|
|
370
408
|
if (modelName === this.modelName &&
|
|
409
|
+
!perCallMiddleware &&
|
|
371
410
|
(!clientOptions || Object.keys(clientOptions).length === 0)) {
|
|
372
411
|
return this.llmClient;
|
|
373
412
|
}
|
|
@@ -392,7 +431,11 @@ let V3 = (() => {
|
|
|
392
431
|
if (cached) {
|
|
393
432
|
return cached;
|
|
394
433
|
}
|
|
395
|
-
const client = this.llmProvider.getClient(modelName, mergedOptions, {
|
|
434
|
+
const client = this.llmProvider.getClient(modelName, mergedOptions, {
|
|
435
|
+
experimental: this.experimental,
|
|
436
|
+
disableAPI: this.disableAPI,
|
|
437
|
+
middleware: perCallMiddleware,
|
|
438
|
+
});
|
|
396
439
|
this.overrideLlmClients.set(cacheKey, client);
|
|
397
440
|
return client;
|
|
398
441
|
}
|
|
@@ -552,6 +595,13 @@ let V3 = (() => {
|
|
|
552
595
|
}
|
|
553
596
|
}
|
|
554
597
|
const lbo = this.opts.localBrowserLaunchOptions ?? {};
|
|
598
|
+
if (lbo.cdpHeaders && !lbo.cdpUrl) {
|
|
599
|
+
this.logger({
|
|
600
|
+
category: "init",
|
|
601
|
+
message: "`cdpHeaders` was provided but `cdpUrl` is not set — cdpHeaders will be ignored. Set `cdpUrl` to connect to an existing browser via CDP.",
|
|
602
|
+
level: 2,
|
|
603
|
+
});
|
|
604
|
+
}
|
|
555
605
|
// If a CDP URL is provided, attach instead of launching.
|
|
556
606
|
if (lbo.cdpUrl) {
|
|
557
607
|
this.logger({
|
|
@@ -561,10 +611,9 @@ let V3 = (() => {
|
|
|
561
611
|
});
|
|
562
612
|
this.ctx = await V3Context.create(lbo.cdpUrl, {
|
|
563
613
|
env: "LOCAL",
|
|
614
|
+
cdpHeaders: lbo.cdpHeaders,
|
|
564
615
|
});
|
|
565
|
-
|
|
566
|
-
this.ctx.conn.cdpLogger = (info) => SessionFileLogger.logCdpCallEvent(info, logCtx);
|
|
567
|
-
this.ctx.conn.cdpEventLogger = (info) => SessionFileLogger.logCdpMessageEvent(info, logCtx);
|
|
616
|
+
this.ctx.conn.flowLoggerContext = this.flowLoggerContext;
|
|
568
617
|
this.ctx.conn.onTransportClosed(this._onCdpClosed);
|
|
569
618
|
this.state = {
|
|
570
619
|
kind: "LOCAL",
|
|
@@ -660,9 +709,7 @@ let V3 = (() => {
|
|
|
660
709
|
env: "LOCAL",
|
|
661
710
|
localBrowserLaunchOptions: lbo,
|
|
662
711
|
});
|
|
663
|
-
|
|
664
|
-
this.ctx.conn.cdpLogger = (info) => SessionFileLogger.logCdpCallEvent(info, logCtx);
|
|
665
|
-
this.ctx.conn.cdpEventLogger = (info) => SessionFileLogger.logCdpMessageEvent(info, logCtx);
|
|
712
|
+
this.ctx.conn.flowLoggerContext = this.flowLoggerContext;
|
|
666
713
|
this.ctx.conn.onTransportClosed(this._onCdpClosed);
|
|
667
714
|
this.state = {
|
|
668
715
|
kind: "LOCAL",
|
|
@@ -689,9 +736,6 @@ let V3 = (() => {
|
|
|
689
736
|
}
|
|
690
737
|
if (this.opts.env === "BROWSERBASE") {
|
|
691
738
|
const { apiKey, projectId } = this.requireBrowserbaseCreds();
|
|
692
|
-
if (!apiKey || !projectId) {
|
|
693
|
-
throw new MissingEnvironmentVariableError("BROWSERBASE_API_KEY and BROWSERBASE_PROJECT_ID", "Browserbase environment");
|
|
694
|
-
}
|
|
695
739
|
this.logger({
|
|
696
740
|
category: "init",
|
|
697
741
|
message: "Starting browserbase session",
|
|
@@ -700,9 +744,13 @@ let V3 = (() => {
|
|
|
700
744
|
const baseSessionParams = this.opts.browserbaseSessionCreateParams ?? {};
|
|
701
745
|
const resolvedKeepAlive = this.keepAlive;
|
|
702
746
|
const keepAlive = this.keepAlive === true;
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
747
|
+
let effectiveSessionParams = baseSessionParams;
|
|
748
|
+
if (resolvedKeepAlive !== undefined) {
|
|
749
|
+
effectiveSessionParams = {
|
|
750
|
+
...baseSessionParams,
|
|
751
|
+
keepAlive: resolvedKeepAlive,
|
|
752
|
+
};
|
|
753
|
+
}
|
|
706
754
|
if (!this.disableAPI && !this.experimental) {
|
|
707
755
|
this.apiClient = new StagehandAPIClient({
|
|
708
756
|
apiKey,
|
|
@@ -710,18 +758,20 @@ let V3 = (() => {
|
|
|
710
758
|
logger: this.logger,
|
|
711
759
|
serverCache: this.opts.serverCache,
|
|
712
760
|
});
|
|
761
|
+
const { projectId: overrideProjectId, browserSettings, userMetadata, ...restSessionParams } = effectiveSessionParams;
|
|
762
|
+
const resolvedProjectId = overrideProjectId ?? projectId;
|
|
713
763
|
const createSessionPayload = {
|
|
714
|
-
projectId:
|
|
715
|
-
...
|
|
764
|
+
...(resolvedProjectId ? { projectId: resolvedProjectId } : {}),
|
|
765
|
+
...restSessionParams,
|
|
716
766
|
browserSettings: {
|
|
717
|
-
...(
|
|
718
|
-
viewport:
|
|
767
|
+
...(browserSettings ?? {}),
|
|
768
|
+
viewport: browserSettings?.viewport ?? {
|
|
719
769
|
width: 1288,
|
|
720
770
|
height: 711,
|
|
721
771
|
},
|
|
722
772
|
},
|
|
723
773
|
userMetadata: {
|
|
724
|
-
...(
|
|
774
|
+
...(userMetadata ?? {}),
|
|
725
775
|
stagehand: "true",
|
|
726
776
|
},
|
|
727
777
|
};
|
|
@@ -745,9 +795,7 @@ let V3 = (() => {
|
|
|
745
795
|
env: "BROWSERBASE",
|
|
746
796
|
apiClient: this.apiClient,
|
|
747
797
|
});
|
|
748
|
-
|
|
749
|
-
this.ctx.conn.cdpLogger = (info) => SessionFileLogger.logCdpCallEvent(info, logCtx);
|
|
750
|
-
this.ctx.conn.cdpEventLogger = (info) => SessionFileLogger.logCdpMessageEvent(info, logCtx);
|
|
798
|
+
this.ctx.conn.flowLoggerContext = this.flowLoggerContext;
|
|
751
799
|
this.ctx.conn.onTransportClosed(this._onCdpClosed);
|
|
752
800
|
this.state = { kind: "BROWSERBASE", sessionId, ws, bb };
|
|
753
801
|
this.browserbaseSessionId = sessionId;
|
|
@@ -869,10 +917,7 @@ let V3 = (() => {
|
|
|
869
917
|
});
|
|
870
918
|
}
|
|
871
919
|
else {
|
|
872
|
-
const
|
|
873
|
-
? options.timeout
|
|
874
|
-
: undefined;
|
|
875
|
-
const ensureTimeRemaining = createTimeoutGuard(effectiveTimeoutMs, (ms) => new ActTimeoutError(ms));
|
|
920
|
+
const ensureTimeRemaining = createTimeoutGuard(options?.timeout, (ms) => new ActTimeoutError(ms));
|
|
876
921
|
actResult = await this.actHandler.takeDeterministicAction({ ...input, selector }, v3Page, this.domSettleTimeoutMs, this.resolveLlmClient(options?.model), ensureTimeRemaining, options?.variables);
|
|
877
922
|
}
|
|
878
923
|
// history: record ObserveResult-based act call
|
|
@@ -1093,7 +1138,7 @@ let V3 = (() => {
|
|
|
1093
1138
|
try {
|
|
1094
1139
|
// Close session file logger
|
|
1095
1140
|
try {
|
|
1096
|
-
await
|
|
1141
|
+
await FlowLogger.close(this.flowLoggerContext);
|
|
1097
1142
|
}
|
|
1098
1143
|
catch {
|
|
1099
1144
|
// ignore
|
|
@@ -1129,6 +1174,12 @@ let V3 = (() => {
|
|
|
1129
1174
|
catch {
|
|
1130
1175
|
// ignore
|
|
1131
1176
|
}
|
|
1177
|
+
try {
|
|
1178
|
+
await this.eventStore.destroy();
|
|
1179
|
+
}
|
|
1180
|
+
catch {
|
|
1181
|
+
// ignore
|
|
1182
|
+
}
|
|
1132
1183
|
try {
|
|
1133
1184
|
this.bus.removeAllListeners();
|
|
1134
1185
|
}
|
|
@@ -1142,6 +1193,13 @@ let V3 = (() => {
|
|
|
1142
1193
|
V3._instances.delete(this);
|
|
1143
1194
|
}
|
|
1144
1195
|
}
|
|
1196
|
+
/**
|
|
1197
|
+
* Resolves the Browserbase API key from options or environment variables.
|
|
1198
|
+
* Returns undefined if no key is found (does not throw).
|
|
1199
|
+
*/
|
|
1200
|
+
get browserbaseApiKey() {
|
|
1201
|
+
return this.opts.apiKey || process.env.BROWSERBASE_API_KEY;
|
|
1202
|
+
}
|
|
1145
1203
|
/** Guard: ensure Browserbase credentials exist in options. */
|
|
1146
1204
|
requireBrowserbaseCreds() {
|
|
1147
1205
|
let { apiKey, projectId } = this.opts;
|
|
@@ -1151,17 +1209,13 @@ let V3 = (() => {
|
|
|
1151
1209
|
if (!projectId)
|
|
1152
1210
|
projectId =
|
|
1153
1211
|
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");
|
|
1212
|
+
if (!apiKey) {
|
|
1213
|
+
throw new MissingEnvironmentVariableError("BROWSERBASE_API_KEY", "Browserbase");
|
|
1161
1214
|
}
|
|
1162
1215
|
// Cache resolved values back into opts for consistency
|
|
1163
1216
|
this.opts.apiKey = apiKey;
|
|
1164
|
-
|
|
1217
|
+
if (projectId)
|
|
1218
|
+
this.opts.projectId = projectId;
|
|
1165
1219
|
// Informational log
|
|
1166
1220
|
this.logger({
|
|
1167
1221
|
category: "init",
|
|
@@ -1303,10 +1357,16 @@ let V3 = (() => {
|
|
|
1303
1357
|
? this.resolveLlmClient(options.model)
|
|
1304
1358
|
: this.llmClient;
|
|
1305
1359
|
const resolvedExecutionModel = options?.executionModel ?? options?.model;
|
|
1306
|
-
const handler = new V3AgentHandler(this, this.logger, agentLlmClient, resolvedExecutionModel, options?.systemPrompt, tools, options?.mode);
|
|
1360
|
+
const handler = new V3AgentHandler(this, this.logger, agentLlmClient, resolvedExecutionModel, options?.systemPrompt, tools, options?.mode, this.isCaptchaAutoSolveEnabled);
|
|
1307
1361
|
const resolvedOptions = typeof instructionOrOptions === "string"
|
|
1308
|
-
? {
|
|
1309
|
-
|
|
1362
|
+
? {
|
|
1363
|
+
instruction: instructionOrOptions,
|
|
1364
|
+
toolTimeout: DEFAULT_AGENT_TOOL_TIMEOUT_MS,
|
|
1365
|
+
}
|
|
1366
|
+
: {
|
|
1367
|
+
...instructionOrOptions,
|
|
1368
|
+
toolTimeout: instructionOrOptions.toolTimeout ?? DEFAULT_AGENT_TOOL_TIMEOUT_MS,
|
|
1369
|
+
};
|
|
1310
1370
|
const callbacksWithSafety = resolvedOptions.callbacks;
|
|
1311
1371
|
if (callbacksWithSafety?.onSafetyConfirmation) {
|
|
1312
1372
|
throw new StagehandInvalidArgumentError('onSafetyConfirmation callback is only supported when using mode: "cua" agents.');
|
|
@@ -1386,145 +1446,59 @@ let V3 = (() => {
|
|
|
1386
1446
|
throw new CuaModelRequiredError(AVAILABLE_CUA_MODELS);
|
|
1387
1447
|
}
|
|
1388
1448
|
const agentConfigSignature = this.agentCache.buildConfigSignature(options);
|
|
1389
|
-
|
|
1390
|
-
execute: async (instructionOrOptions) => withInstanceLogContext(this.instanceId, async () => {
|
|
1391
|
-
validateExperimentalFeatures({
|
|
1392
|
-
isExperimental: this.experimental,
|
|
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 () => {
|
|
1449
|
+
const execute = async (instructionOrOptions) => withInstanceLogContext(this.instanceId, async () => {
|
|
1487
1450
|
validateExperimentalFeatures({
|
|
1488
1451
|
isExperimental: this.experimental,
|
|
1489
1452
|
agentConfig: options,
|
|
1490
1453
|
executeOptions: typeof instructionOrOptions === "object"
|
|
1491
1454
|
? instructionOrOptions
|
|
1492
1455
|
: null,
|
|
1493
|
-
isStreaming,
|
|
1494
1456
|
});
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1457
|
+
const tools = options?.integrations
|
|
1458
|
+
? await resolveTools(options.integrations, options.tools)
|
|
1459
|
+
: (options?.tools ?? {});
|
|
1460
|
+
const handler = new V3CuaAgentHandler(this, this.logger, {
|
|
1461
|
+
modelName,
|
|
1462
|
+
clientOptions,
|
|
1463
|
+
userProvidedInstructions: (options.systemPrompt ??
|
|
1464
|
+
`You are a helpful assistant that can use a web browser.\nDo not ask follow up questions, the user will trust your judgement.`) +
|
|
1465
|
+
(this.isCaptchaAutoSolveEnabled
|
|
1466
|
+
? CAPTCHA_CUA_SYSTEM_PROMPT_NOTE
|
|
1467
|
+
: ""),
|
|
1468
|
+
}, tools);
|
|
1469
|
+
const resolvedOptions = typeof instructionOrOptions === "string"
|
|
1470
|
+
? {
|
|
1471
|
+
instruction: instructionOrOptions,
|
|
1472
|
+
toolTimeout: DEFAULT_AGENT_TOOL_TIMEOUT_MS,
|
|
1473
|
+
}
|
|
1474
|
+
: {
|
|
1475
|
+
...instructionOrOptions,
|
|
1476
|
+
toolTimeout: instructionOrOptions.toolTimeout ??
|
|
1477
|
+
DEFAULT_AGENT_TOOL_TIMEOUT_MS,
|
|
1478
|
+
};
|
|
1479
|
+
if (resolvedOptions.page) {
|
|
1480
|
+
const normalizedPage = await this.normalizeToV3Page(resolvedOptions.page);
|
|
1481
|
+
this.ctx.setActivePage(normalizedPage);
|
|
1482
|
+
}
|
|
1483
|
+
const instruction = resolvedOptions.instruction.trim();
|
|
1484
|
+
const sanitizedOptions = this.agentCache.sanitizeExecuteOptions(resolvedOptions);
|
|
1485
|
+
const cacheVariables = flattenVariables(resolvedOptions.variables);
|
|
1486
|
+
let cacheContext = null;
|
|
1487
|
+
if (this.agentCache.shouldAttemptCache(instruction)) {
|
|
1488
|
+
const startPage = await this.ctx.awaitActivePage();
|
|
1489
|
+
cacheContext = await this.agentCache.prepareContext({
|
|
1490
|
+
instruction,
|
|
1491
|
+
options: sanitizedOptions,
|
|
1492
|
+
configSignature: agentConfigSignature,
|
|
1493
|
+
page: startPage,
|
|
1494
|
+
variables: cacheVariables,
|
|
1495
|
+
});
|
|
1502
1496
|
if (cacheContext) {
|
|
1503
|
-
const replayed = await this.agentCache.
|
|
1497
|
+
const replayed = await this.agentCache.tryReplay(cacheContext);
|
|
1504
1498
|
if (replayed) {
|
|
1505
|
-
SessionFileLogger.logAgentTaskCompleted({ cacheHit: true });
|
|
1506
1499
|
return replayed;
|
|
1507
1500
|
}
|
|
1508
1501
|
}
|
|
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
1502
|
}
|
|
1529
1503
|
let agentSteps = [];
|
|
1530
1504
|
const shouldRecordLocally = !!cacheContext && (!this.apiClient || this.experimental);
|
|
@@ -1535,14 +1509,14 @@ let V3 = (() => {
|
|
|
1535
1509
|
try {
|
|
1536
1510
|
if (this.apiClient && !this.experimental) {
|
|
1537
1511
|
const page = await this.ctx.awaitActivePage();
|
|
1538
|
-
result = await this.apiClient.agentExecute(options
|
|
1512
|
+
result = await this.apiClient.agentExecute(options, resolvedOptions, page.mainFrameId(), !!cacheContext);
|
|
1539
1513
|
if (cacheContext) {
|
|
1540
1514
|
const transferredEntry = this.apiClient.consumeLatestAgentCacheEntry();
|
|
1541
1515
|
await this.agentCache.storeTransferredEntry(transferredEntry);
|
|
1542
1516
|
}
|
|
1543
1517
|
}
|
|
1544
1518
|
else {
|
|
1545
|
-
result = await handler.execute(
|
|
1519
|
+
result = await handler.execute(instructionOrOptions);
|
|
1546
1520
|
}
|
|
1547
1521
|
if (shouldRecordLocally) {
|
|
1548
1522
|
agentSteps = this.endAgentReplayRecording();
|
|
@@ -1564,9 +1538,96 @@ let V3 = (() => {
|
|
|
1564
1538
|
if (shouldRecordLocally) {
|
|
1565
1539
|
this.discardAgentReplayRecording();
|
|
1566
1540
|
}
|
|
1567
|
-
SessionFileLogger.logAgentTaskCompleted();
|
|
1568
1541
|
}
|
|
1569
|
-
})
|
|
1542
|
+
});
|
|
1543
|
+
return {
|
|
1544
|
+
execute: FlowLogger.wrapWithLogging({
|
|
1545
|
+
eventType: "AgentExecute",
|
|
1546
|
+
context: this.flowLoggerContext,
|
|
1547
|
+
})(execute),
|
|
1548
|
+
};
|
|
1549
|
+
}
|
|
1550
|
+
// Default: AISDK tools-based agent
|
|
1551
|
+
const agentConfigSignature = this.agentCache.buildConfigSignature(options);
|
|
1552
|
+
const isStreaming = options?.stream ?? false;
|
|
1553
|
+
const execute = async (instructionOrOptions) => withInstanceLogContext(this.instanceId, async () => {
|
|
1554
|
+
validateExperimentalFeatures({
|
|
1555
|
+
isExperimental: this.experimental,
|
|
1556
|
+
agentConfig: options,
|
|
1557
|
+
executeOptions: typeof instructionOrOptions === "object"
|
|
1558
|
+
? instructionOrOptions
|
|
1559
|
+
: null,
|
|
1560
|
+
isStreaming,
|
|
1561
|
+
});
|
|
1562
|
+
// Streaming mode
|
|
1563
|
+
if (isStreaming) {
|
|
1564
|
+
const { handler, resolvedOptions, cacheContext, llmClient } = await this.prepareAgentExecution(options, instructionOrOptions, agentConfigSignature);
|
|
1565
|
+
if (cacheContext) {
|
|
1566
|
+
const replayed = await this.agentCache.tryReplayAsStream(cacheContext, llmClient);
|
|
1567
|
+
if (replayed) {
|
|
1568
|
+
return replayed;
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
const streamResult = await handler.stream(resolvedOptions);
|
|
1572
|
+
if (cacheContext) {
|
|
1573
|
+
const wrappedStream = this.agentCache.wrapStreamForCaching(cacheContext, streamResult, () => this.beginAgentReplayRecording(), () => this.endAgentReplayRecording(), () => this.discardAgentReplayRecording());
|
|
1574
|
+
return wrappedStream;
|
|
1575
|
+
}
|
|
1576
|
+
return streamResult;
|
|
1577
|
+
}
|
|
1578
|
+
// Non-streaming mode (default)
|
|
1579
|
+
const { handler, resolvedOptions, cacheContext, llmClient } = await this.prepareAgentExecution(options, instructionOrOptions, agentConfigSignature);
|
|
1580
|
+
if (cacheContext) {
|
|
1581
|
+
const replayed = await this.agentCache.tryReplay(cacheContext, llmClient);
|
|
1582
|
+
if (replayed) {
|
|
1583
|
+
return replayed;
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1586
|
+
let agentSteps = [];
|
|
1587
|
+
const shouldRecordLocally = !!cacheContext && (!this.apiClient || this.experimental);
|
|
1588
|
+
if (shouldRecordLocally) {
|
|
1589
|
+
this.beginAgentReplayRecording();
|
|
1590
|
+
}
|
|
1591
|
+
let result;
|
|
1592
|
+
try {
|
|
1593
|
+
if (this.apiClient && !this.experimental) {
|
|
1594
|
+
const page = await this.ctx.awaitActivePage();
|
|
1595
|
+
result = await this.apiClient.agentExecute(options ?? {}, resolvedOptions, page.mainFrameId(), !!cacheContext);
|
|
1596
|
+
if (cacheContext) {
|
|
1597
|
+
const transferredEntry = this.apiClient.consumeLatestAgentCacheEntry();
|
|
1598
|
+
await this.agentCache.storeTransferredEntry(transferredEntry);
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
else {
|
|
1602
|
+
result = await handler.execute(resolvedOptions);
|
|
1603
|
+
}
|
|
1604
|
+
if (shouldRecordLocally) {
|
|
1605
|
+
agentSteps = this.endAgentReplayRecording();
|
|
1606
|
+
}
|
|
1607
|
+
if (shouldRecordLocally &&
|
|
1608
|
+
cacheContext &&
|
|
1609
|
+
result.success &&
|
|
1610
|
+
agentSteps.length > 0) {
|
|
1611
|
+
await this.agentCache.store(cacheContext, agentSteps, result);
|
|
1612
|
+
}
|
|
1613
|
+
return result;
|
|
1614
|
+
}
|
|
1615
|
+
catch (err) {
|
|
1616
|
+
if (shouldRecordLocally)
|
|
1617
|
+
this.discardAgentReplayRecording();
|
|
1618
|
+
throw err;
|
|
1619
|
+
}
|
|
1620
|
+
finally {
|
|
1621
|
+
if (shouldRecordLocally) {
|
|
1622
|
+
this.discardAgentReplayRecording();
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1625
|
+
});
|
|
1626
|
+
return {
|
|
1627
|
+
execute: FlowLogger.wrapWithLogging({
|
|
1628
|
+
eventType: "AgentExecute",
|
|
1629
|
+
context: this.flowLoggerContext,
|
|
1630
|
+
})(execute),
|
|
1570
1631
|
};
|
|
1571
1632
|
}
|
|
1572
1633
|
};
|