@browserbasehq/orca 3.1.0-patch.4 → 3.2.0-middleware.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.d.ts +3 -1
- package/dist/cjs/lib/inference.js +4 -7
- package/dist/cjs/lib/inference.js.map +1 -1
- package/dist/cjs/lib/prompt.d.ts +1 -1
- package/dist/cjs/lib/prompt.js +24 -18
- package/dist/cjs/lib/prompt.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 +10 -6
- package/dist/cjs/lib/v3/agent/OpenAICUAClient.js +107 -18
- 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 +11 -12
- 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/agent/utils/variables.d.ts +5 -0
- package/dist/cjs/lib/v3/agent/utils/variables.js +9 -0
- package/dist/cjs/lib/v3/agent/utils/variables.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 +3 -3
- 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 +14 -11
- package/dist/cjs/lib/v3/llm/LLMProvider.js.map +1 -1
- package/dist/cjs/lib/v3/llm/aisdk.d.ts +3 -1
- package/dist/cjs/lib/v3/llm/aisdk.js +24 -28
- 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/handlers.d.ts +1 -0
- package/dist/cjs/lib/v3/types/private/handlers.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 +27 -7
- package/dist/cjs/lib/v3/types/public/api.js +42 -14
- package/dist/cjs/lib/v3/types/public/api.js.map +1 -1
- package/dist/cjs/lib/v3/types/public/methods.d.ts +1 -0
- package/dist/cjs/lib/v3/types/public/methods.js.map +1 -1
- package/dist/cjs/lib/v3/types/public/model.d.ts +14 -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/types/public/variables.d.ts +7 -0
- package/dist/cjs/lib/v3/types/public/variables.js +22 -0
- package/dist/cjs/lib/v3/types/public/variables.js.map +1 -0
- 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 +148 -62
- 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 +85 -22
- 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 +250 -180
- package/dist/cjs/lib/v3/v3.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/chrome-newtab-page-tracking.spec.js +56 -0
- package/dist/cjs/tests/integration/chrome-newtab-page-tracking.spec.js.map +1 -0
- 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.d.ts +1 -0
- 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 +25 -3
- package/dist/cjs/tests/unit/agent-execution-model.test.js.map +1 -1
- package/dist/cjs/tests/unit/agent-system-prompt-variables.test.d.ts +1 -0
- package/dist/cjs/tests/unit/agent-system-prompt-variables.test.js +23 -0
- package/dist/cjs/tests/unit/agent-system-prompt-variables.test.js.map +1 -0
- package/dist/cjs/tests/unit/aisdk-reasoning-effort.test.d.ts +1 -0
- package/dist/cjs/tests/unit/aisdk-reasoning-effort.test.js +153 -0
- package/dist/cjs/tests/unit/aisdk-reasoning-effort.test.js.map +1 -0
- package/dist/cjs/tests/unit/api-client-observe-variables.test.d.ts +1 -0
- package/dist/cjs/tests/unit/api-client-observe-variables.test.js +86 -0
- package/dist/cjs/tests/unit/api-client-observe-variables.test.js.map +1 -0
- package/dist/cjs/tests/unit/api-variables-schema.test.d.ts +1 -0
- package/dist/cjs/tests/unit/api-variables-schema.test.js +37 -0
- package/dist/cjs/tests/unit/api-variables-schema.test.js.map +1 -0
- 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/prompt-observe-variables.test.d.ts +1 -0
- package/dist/cjs/tests/unit/prompt-observe-variables.test.js +19 -0
- package/dist/cjs/tests/unit/prompt-observe-variables.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/cjs/tests/unit/timeout-handlers.test.js +50 -0
- package/dist/cjs/tests/unit/timeout-handlers.test.js.map +1 -1
- package/dist/esm/lib/inference.d.ts +3 -1
- package/dist/esm/lib/inference.js +4 -7
- package/dist/esm/lib/inference.js.map +1 -1
- package/dist/esm/lib/prompt.d.ts +1 -1
- package/dist/esm/lib/prompt.js +24 -18
- package/dist/esm/lib/prompt.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 +10 -6
- package/dist/esm/lib/v3/agent/OpenAICUAClient.js +107 -18
- 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 +11 -12
- 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/agent/utils/variables.d.ts +5 -0
- package/dist/esm/lib/v3/agent/utils/variables.js +8 -0
- package/dist/esm/lib/v3/agent/utils/variables.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 +3 -3
- 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 +15 -12
- package/dist/esm/lib/v3/llm/LLMProvider.js.map +1 -1
- package/dist/esm/lib/v3/llm/aisdk.d.ts +3 -1
- package/dist/esm/lib/v3/llm/aisdk.js +24 -28
- 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/handlers.d.ts +1 -0
- package/dist/esm/lib/v3/types/private/handlers.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 +27 -7
- package/dist/esm/lib/v3/types/public/api.js +37 -12
- package/dist/esm/lib/v3/types/public/api.js.map +1 -1
- package/dist/esm/lib/v3/types/public/methods.d.ts +1 -0
- package/dist/esm/lib/v3/types/public/methods.js.map +1 -1
- package/dist/esm/lib/v3/types/public/model.d.ts +14 -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/types/public/variables.d.ts +7 -0
- package/dist/esm/lib/v3/types/public/variables.js +19 -0
- package/dist/esm/lib/v3/types/public/variables.js.map +1 -0
- 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 +148 -62
- 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 +87 -24
- 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 +250 -181
- package/dist/esm/lib/v3/v3.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/chrome-newtab-page-tracking.spec.d.ts +1 -0
- package/dist/esm/tests/integration/chrome-newtab-page-tracking.spec.js +54 -0
- package/dist/esm/tests/integration/chrome-newtab-page-tracking.spec.js.map +1 -0
- 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 +25 -3
- package/dist/esm/tests/unit/agent-execution-model.test.js.map +1 -1
- package/dist/esm/tests/unit/agent-system-prompt-variables.test.d.ts +1 -0
- package/dist/esm/tests/unit/agent-system-prompt-variables.test.js +21 -0
- package/dist/esm/tests/unit/agent-system-prompt-variables.test.js.map +1 -0
- package/dist/esm/tests/unit/aisdk-reasoning-effort.test.d.ts +1 -0
- package/dist/esm/tests/unit/aisdk-reasoning-effort.test.js +118 -0
- package/dist/esm/tests/unit/aisdk-reasoning-effort.test.js.map +1 -0
- package/dist/esm/tests/unit/api-client-observe-variables.test.d.ts +1 -0
- package/dist/esm/tests/unit/api-client-observe-variables.test.js +84 -0
- package/dist/esm/tests/unit/api-client-observe-variables.test.js.map +1 -0
- package/dist/esm/tests/unit/api-variables-schema.test.d.ts +1 -0
- package/dist/esm/tests/unit/api-variables-schema.test.js +35 -0
- package/dist/esm/tests/unit/api-variables-schema.test.js.map +1 -0
- 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/prompt-observe-variables.test.d.ts +1 -0
- package/dist/esm/tests/unit/prompt-observe-variables.test.js +17 -0
- package/dist/esm/tests/unit/prompt-observe-variables.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/dist/esm/tests/unit/timeout-handlers.test.js +50 -0
- package/dist/esm/tests/unit/timeout-handlers.test.js.map +1 -1
- package/package.json +6 -4
- 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/chrome-newtab-page-tracking.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
|
}
|
|
@@ -384,6 +423,13 @@ let V3 = (() => {
|
|
|
384
423
|
mergedOptions.apiKey = apiKey;
|
|
385
424
|
}
|
|
386
425
|
}
|
|
426
|
+
if (perCallMiddleware) {
|
|
427
|
+
return this.llmProvider.getClient(modelName, mergedOptions, {
|
|
428
|
+
experimental: this.experimental,
|
|
429
|
+
disableAPI: this.disableAPI,
|
|
430
|
+
middleware: perCallMiddleware,
|
|
431
|
+
});
|
|
432
|
+
}
|
|
387
433
|
const cacheKey = JSON.stringify({
|
|
388
434
|
modelName,
|
|
389
435
|
clientOptions: mergedOptions,
|
|
@@ -392,7 +438,10 @@ let V3 = (() => {
|
|
|
392
438
|
if (cached) {
|
|
393
439
|
return cached;
|
|
394
440
|
}
|
|
395
|
-
const client = this.llmProvider.getClient(modelName, mergedOptions, {
|
|
441
|
+
const client = this.llmProvider.getClient(modelName, mergedOptions, {
|
|
442
|
+
experimental: this.experimental,
|
|
443
|
+
disableAPI: this.disableAPI,
|
|
444
|
+
});
|
|
396
445
|
this.overrideLlmClients.set(cacheKey, client);
|
|
397
446
|
return client;
|
|
398
447
|
}
|
|
@@ -552,6 +601,13 @@ let V3 = (() => {
|
|
|
552
601
|
}
|
|
553
602
|
}
|
|
554
603
|
const lbo = this.opts.localBrowserLaunchOptions ?? {};
|
|
604
|
+
if (lbo.cdpHeaders && !lbo.cdpUrl) {
|
|
605
|
+
this.logger({
|
|
606
|
+
category: "init",
|
|
607
|
+
message: "`cdpHeaders` was provided but `cdpUrl` is not set — cdpHeaders will be ignored. Set `cdpUrl` to connect to an existing browser via CDP.",
|
|
608
|
+
level: 2,
|
|
609
|
+
});
|
|
610
|
+
}
|
|
555
611
|
// If a CDP URL is provided, attach instead of launching.
|
|
556
612
|
if (lbo.cdpUrl) {
|
|
557
613
|
this.logger({
|
|
@@ -561,10 +617,9 @@ let V3 = (() => {
|
|
|
561
617
|
});
|
|
562
618
|
this.ctx = await V3Context.create(lbo.cdpUrl, {
|
|
563
619
|
env: "LOCAL",
|
|
620
|
+
cdpHeaders: lbo.cdpHeaders,
|
|
564
621
|
});
|
|
565
|
-
|
|
566
|
-
this.ctx.conn.cdpLogger = (info) => SessionFileLogger.logCdpCallEvent(info, logCtx);
|
|
567
|
-
this.ctx.conn.cdpEventLogger = (info) => SessionFileLogger.logCdpMessageEvent(info, logCtx);
|
|
622
|
+
this.ctx.conn.flowLoggerContext = this.flowLoggerContext;
|
|
568
623
|
this.ctx.conn.onTransportClosed(this._onCdpClosed);
|
|
569
624
|
this.state = {
|
|
570
625
|
kind: "LOCAL",
|
|
@@ -660,9 +715,7 @@ let V3 = (() => {
|
|
|
660
715
|
env: "LOCAL",
|
|
661
716
|
localBrowserLaunchOptions: lbo,
|
|
662
717
|
});
|
|
663
|
-
|
|
664
|
-
this.ctx.conn.cdpLogger = (info) => SessionFileLogger.logCdpCallEvent(info, logCtx);
|
|
665
|
-
this.ctx.conn.cdpEventLogger = (info) => SessionFileLogger.logCdpMessageEvent(info, logCtx);
|
|
718
|
+
this.ctx.conn.flowLoggerContext = this.flowLoggerContext;
|
|
666
719
|
this.ctx.conn.onTransportClosed(this._onCdpClosed);
|
|
667
720
|
this.state = {
|
|
668
721
|
kind: "LOCAL",
|
|
@@ -689,9 +742,6 @@ let V3 = (() => {
|
|
|
689
742
|
}
|
|
690
743
|
if (this.opts.env === "BROWSERBASE") {
|
|
691
744
|
const { apiKey, projectId } = this.requireBrowserbaseCreds();
|
|
692
|
-
if (!apiKey || !projectId) {
|
|
693
|
-
throw new MissingEnvironmentVariableError("BROWSERBASE_API_KEY and BROWSERBASE_PROJECT_ID", "Browserbase environment");
|
|
694
|
-
}
|
|
695
745
|
this.logger({
|
|
696
746
|
category: "init",
|
|
697
747
|
message: "Starting browserbase session",
|
|
@@ -700,9 +750,13 @@ let V3 = (() => {
|
|
|
700
750
|
const baseSessionParams = this.opts.browserbaseSessionCreateParams ?? {};
|
|
701
751
|
const resolvedKeepAlive = this.keepAlive;
|
|
702
752
|
const keepAlive = this.keepAlive === true;
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
753
|
+
let effectiveSessionParams = baseSessionParams;
|
|
754
|
+
if (resolvedKeepAlive !== undefined) {
|
|
755
|
+
effectiveSessionParams = {
|
|
756
|
+
...baseSessionParams,
|
|
757
|
+
keepAlive: resolvedKeepAlive,
|
|
758
|
+
};
|
|
759
|
+
}
|
|
706
760
|
if (!this.disableAPI && !this.experimental) {
|
|
707
761
|
this.apiClient = new StagehandAPIClient({
|
|
708
762
|
apiKey,
|
|
@@ -710,18 +764,20 @@ let V3 = (() => {
|
|
|
710
764
|
logger: this.logger,
|
|
711
765
|
serverCache: this.opts.serverCache,
|
|
712
766
|
});
|
|
767
|
+
const { projectId: overrideProjectId, browserSettings, userMetadata, ...restSessionParams } = effectiveSessionParams;
|
|
768
|
+
const resolvedProjectId = overrideProjectId ?? projectId;
|
|
713
769
|
const createSessionPayload = {
|
|
714
|
-
projectId:
|
|
715
|
-
...
|
|
770
|
+
...(resolvedProjectId ? { projectId: resolvedProjectId } : {}),
|
|
771
|
+
...restSessionParams,
|
|
716
772
|
browserSettings: {
|
|
717
|
-
...(
|
|
718
|
-
viewport:
|
|
773
|
+
...(browserSettings ?? {}),
|
|
774
|
+
viewport: browserSettings?.viewport ?? {
|
|
719
775
|
width: 1288,
|
|
720
776
|
height: 711,
|
|
721
777
|
},
|
|
722
778
|
},
|
|
723
779
|
userMetadata: {
|
|
724
|
-
...(
|
|
780
|
+
...(userMetadata ?? {}),
|
|
725
781
|
stagehand: "true",
|
|
726
782
|
},
|
|
727
783
|
};
|
|
@@ -745,9 +801,7 @@ let V3 = (() => {
|
|
|
745
801
|
env: "BROWSERBASE",
|
|
746
802
|
apiClient: this.apiClient,
|
|
747
803
|
});
|
|
748
|
-
|
|
749
|
-
this.ctx.conn.cdpLogger = (info) => SessionFileLogger.logCdpCallEvent(info, logCtx);
|
|
750
|
-
this.ctx.conn.cdpEventLogger = (info) => SessionFileLogger.logCdpMessageEvent(info, logCtx);
|
|
804
|
+
this.ctx.conn.flowLoggerContext = this.flowLoggerContext;
|
|
751
805
|
this.ctx.conn.onTransportClosed(this._onCdpClosed);
|
|
752
806
|
this.state = { kind: "BROWSERBASE", sessionId, ws, bb };
|
|
753
807
|
this.browserbaseSessionId = sessionId;
|
|
@@ -869,10 +923,7 @@ let V3 = (() => {
|
|
|
869
923
|
});
|
|
870
924
|
}
|
|
871
925
|
else {
|
|
872
|
-
const
|
|
873
|
-
? options.timeout
|
|
874
|
-
: undefined;
|
|
875
|
-
const ensureTimeRemaining = createTimeoutGuard(effectiveTimeoutMs, (ms) => new ActTimeoutError(ms));
|
|
926
|
+
const ensureTimeRemaining = createTimeoutGuard(options?.timeout, (ms) => new ActTimeoutError(ms));
|
|
876
927
|
actResult = await this.actHandler.takeDeterministicAction({ ...input, selector }, v3Page, this.domSettleTimeoutMs, this.resolveLlmClient(options?.model), ensureTimeRemaining, options?.variables);
|
|
877
928
|
}
|
|
878
929
|
// history: record ObserveResult-based act call
|
|
@@ -1026,6 +1077,7 @@ let V3 = (() => {
|
|
|
1026
1077
|
const handlerParams = {
|
|
1027
1078
|
instruction,
|
|
1028
1079
|
model: options?.model,
|
|
1080
|
+
variables: options?.variables,
|
|
1029
1081
|
timeout: options?.timeout,
|
|
1030
1082
|
selector: options?.selector,
|
|
1031
1083
|
page: page,
|
|
@@ -1045,6 +1097,7 @@ let V3 = (() => {
|
|
|
1045
1097
|
// history: record observe call (omit page object)
|
|
1046
1098
|
this.addToHistory("observe", {
|
|
1047
1099
|
instruction,
|
|
1100
|
+
variables: options?.variables,
|
|
1048
1101
|
timeout: options?.timeout,
|
|
1049
1102
|
}, results);
|
|
1050
1103
|
return results;
|
|
@@ -1093,7 +1146,7 @@ let V3 = (() => {
|
|
|
1093
1146
|
try {
|
|
1094
1147
|
// Close session file logger
|
|
1095
1148
|
try {
|
|
1096
|
-
await
|
|
1149
|
+
await FlowLogger.close(this.flowLoggerContext);
|
|
1097
1150
|
}
|
|
1098
1151
|
catch {
|
|
1099
1152
|
// ignore
|
|
@@ -1129,6 +1182,12 @@ let V3 = (() => {
|
|
|
1129
1182
|
catch {
|
|
1130
1183
|
// ignore
|
|
1131
1184
|
}
|
|
1185
|
+
try {
|
|
1186
|
+
await this.eventStore.destroy();
|
|
1187
|
+
}
|
|
1188
|
+
catch {
|
|
1189
|
+
// ignore
|
|
1190
|
+
}
|
|
1132
1191
|
try {
|
|
1133
1192
|
this.bus.removeAllListeners();
|
|
1134
1193
|
}
|
|
@@ -1142,6 +1201,13 @@ let V3 = (() => {
|
|
|
1142
1201
|
V3._instances.delete(this);
|
|
1143
1202
|
}
|
|
1144
1203
|
}
|
|
1204
|
+
/**
|
|
1205
|
+
* Resolves the Browserbase API key from options or environment variables.
|
|
1206
|
+
* Returns undefined if no key is found (does not throw).
|
|
1207
|
+
*/
|
|
1208
|
+
get browserbaseApiKey() {
|
|
1209
|
+
return this.opts.apiKey || process.env.BROWSERBASE_API_KEY;
|
|
1210
|
+
}
|
|
1145
1211
|
/** Guard: ensure Browserbase credentials exist in options. */
|
|
1146
1212
|
requireBrowserbaseCreds() {
|
|
1147
1213
|
let { apiKey, projectId } = this.opts;
|
|
@@ -1151,17 +1217,13 @@ let V3 = (() => {
|
|
|
1151
1217
|
if (!projectId)
|
|
1152
1218
|
projectId =
|
|
1153
1219
|
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");
|
|
1220
|
+
if (!apiKey) {
|
|
1221
|
+
throw new MissingEnvironmentVariableError("BROWSERBASE_API_KEY", "Browserbase");
|
|
1161
1222
|
}
|
|
1162
1223
|
// Cache resolved values back into opts for consistency
|
|
1163
1224
|
this.opts.apiKey = apiKey;
|
|
1164
|
-
|
|
1225
|
+
if (projectId)
|
|
1226
|
+
this.opts.projectId = projectId;
|
|
1165
1227
|
// Informational log
|
|
1166
1228
|
this.logger({
|
|
1167
1229
|
category: "init",
|
|
@@ -1303,10 +1365,16 @@ let V3 = (() => {
|
|
|
1303
1365
|
? this.resolveLlmClient(options.model)
|
|
1304
1366
|
: this.llmClient;
|
|
1305
1367
|
const resolvedExecutionModel = options?.executionModel ?? options?.model;
|
|
1306
|
-
const handler = new V3AgentHandler(this, this.logger, agentLlmClient, resolvedExecutionModel, options?.systemPrompt, tools, options?.mode);
|
|
1368
|
+
const handler = new V3AgentHandler(this, this.logger, agentLlmClient, resolvedExecutionModel, options?.systemPrompt, tools, options?.mode, this.isCaptchaAutoSolveEnabled);
|
|
1307
1369
|
const resolvedOptions = typeof instructionOrOptions === "string"
|
|
1308
|
-
? {
|
|
1309
|
-
|
|
1370
|
+
? {
|
|
1371
|
+
instruction: instructionOrOptions,
|
|
1372
|
+
toolTimeout: DEFAULT_AGENT_TOOL_TIMEOUT_MS,
|
|
1373
|
+
}
|
|
1374
|
+
: {
|
|
1375
|
+
...instructionOrOptions,
|
|
1376
|
+
toolTimeout: instructionOrOptions.toolTimeout ?? DEFAULT_AGENT_TOOL_TIMEOUT_MS,
|
|
1377
|
+
};
|
|
1310
1378
|
const callbacksWithSafety = resolvedOptions.callbacks;
|
|
1311
1379
|
if (callbacksWithSafety?.onSafetyConfirmation) {
|
|
1312
1380
|
throw new StagehandInvalidArgumentError('onSafetyConfirmation callback is only supported when using mode: "cua" agents.');
|
|
@@ -1386,145 +1454,59 @@ let V3 = (() => {
|
|
|
1386
1454
|
throw new CuaModelRequiredError(AVAILABLE_CUA_MODELS);
|
|
1387
1455
|
}
|
|
1388
1456
|
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 () => {
|
|
1457
|
+
const execute = async (instructionOrOptions) => withInstanceLogContext(this.instanceId, async () => {
|
|
1487
1458
|
validateExperimentalFeatures({
|
|
1488
1459
|
isExperimental: this.experimental,
|
|
1489
1460
|
agentConfig: options,
|
|
1490
1461
|
executeOptions: typeof instructionOrOptions === "object"
|
|
1491
1462
|
? instructionOrOptions
|
|
1492
1463
|
: null,
|
|
1493
|
-
isStreaming,
|
|
1494
|
-
});
|
|
1495
|
-
SessionFileLogger.logAgentTaskStarted({
|
|
1496
|
-
invocation: "Agent.execute",
|
|
1497
|
-
args: [instructionOrOptions],
|
|
1498
1464
|
});
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1465
|
+
const tools = options?.integrations
|
|
1466
|
+
? await resolveTools(options.integrations, options.tools)
|
|
1467
|
+
: (options?.tools ?? {});
|
|
1468
|
+
const handler = new V3CuaAgentHandler(this, this.logger, {
|
|
1469
|
+
modelName,
|
|
1470
|
+
clientOptions,
|
|
1471
|
+
userProvidedInstructions: (options.systemPrompt ??
|
|
1472
|
+
`You are a helpful assistant that can use a web browser.\nDo not ask follow up questions, the user will trust your judgement.`) +
|
|
1473
|
+
(this.isCaptchaAutoSolveEnabled
|
|
1474
|
+
? CAPTCHA_CUA_SYSTEM_PROMPT_NOTE
|
|
1475
|
+
: ""),
|
|
1476
|
+
}, tools);
|
|
1477
|
+
const resolvedOptions = typeof instructionOrOptions === "string"
|
|
1478
|
+
? {
|
|
1479
|
+
instruction: instructionOrOptions,
|
|
1480
|
+
toolTimeout: DEFAULT_AGENT_TOOL_TIMEOUT_MS,
|
|
1481
|
+
}
|
|
1482
|
+
: {
|
|
1483
|
+
...instructionOrOptions,
|
|
1484
|
+
toolTimeout: instructionOrOptions.toolTimeout ??
|
|
1485
|
+
DEFAULT_AGENT_TOOL_TIMEOUT_MS,
|
|
1486
|
+
};
|
|
1487
|
+
if (resolvedOptions.page) {
|
|
1488
|
+
const normalizedPage = await this.normalizeToV3Page(resolvedOptions.page);
|
|
1489
|
+
this.ctx.setActivePage(normalizedPage);
|
|
1490
|
+
}
|
|
1491
|
+
const instruction = resolvedOptions.instruction.trim();
|
|
1492
|
+
const sanitizedOptions = this.agentCache.sanitizeExecuteOptions(resolvedOptions);
|
|
1493
|
+
const cacheVariables = flattenVariables(resolvedOptions.variables);
|
|
1494
|
+
let cacheContext = null;
|
|
1495
|
+
if (this.agentCache.shouldAttemptCache(instruction)) {
|
|
1496
|
+
const startPage = await this.ctx.awaitActivePage();
|
|
1497
|
+
cacheContext = await this.agentCache.prepareContext({
|
|
1498
|
+
instruction,
|
|
1499
|
+
options: sanitizedOptions,
|
|
1500
|
+
configSignature: agentConfigSignature,
|
|
1501
|
+
page: startPage,
|
|
1502
|
+
variables: cacheVariables,
|
|
1503
|
+
});
|
|
1502
1504
|
if (cacheContext) {
|
|
1503
|
-
const replayed = await this.agentCache.
|
|
1505
|
+
const replayed = await this.agentCache.tryReplay(cacheContext);
|
|
1504
1506
|
if (replayed) {
|
|
1505
|
-
SessionFileLogger.logAgentTaskCompleted({ cacheHit: true });
|
|
1506
1507
|
return replayed;
|
|
1507
1508
|
}
|
|
1508
1509
|
}
|
|
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
1510
|
}
|
|
1529
1511
|
let agentSteps = [];
|
|
1530
1512
|
const shouldRecordLocally = !!cacheContext && (!this.apiClient || this.experimental);
|
|
@@ -1535,14 +1517,14 @@ let V3 = (() => {
|
|
|
1535
1517
|
try {
|
|
1536
1518
|
if (this.apiClient && !this.experimental) {
|
|
1537
1519
|
const page = await this.ctx.awaitActivePage();
|
|
1538
|
-
result = await this.apiClient.agentExecute(options
|
|
1520
|
+
result = await this.apiClient.agentExecute(options, resolvedOptions, page.mainFrameId(), !!cacheContext);
|
|
1539
1521
|
if (cacheContext) {
|
|
1540
1522
|
const transferredEntry = this.apiClient.consumeLatestAgentCacheEntry();
|
|
1541
1523
|
await this.agentCache.storeTransferredEntry(transferredEntry);
|
|
1542
1524
|
}
|
|
1543
1525
|
}
|
|
1544
1526
|
else {
|
|
1545
|
-
result = await handler.execute(
|
|
1527
|
+
result = await handler.execute(instructionOrOptions);
|
|
1546
1528
|
}
|
|
1547
1529
|
if (shouldRecordLocally) {
|
|
1548
1530
|
agentSteps = this.endAgentReplayRecording();
|
|
@@ -1564,9 +1546,96 @@ let V3 = (() => {
|
|
|
1564
1546
|
if (shouldRecordLocally) {
|
|
1565
1547
|
this.discardAgentReplayRecording();
|
|
1566
1548
|
}
|
|
1567
|
-
SessionFileLogger.logAgentTaskCompleted();
|
|
1568
1549
|
}
|
|
1569
|
-
})
|
|
1550
|
+
});
|
|
1551
|
+
return {
|
|
1552
|
+
execute: FlowLogger.wrapWithLogging({
|
|
1553
|
+
eventType: "AgentExecute",
|
|
1554
|
+
context: this.flowLoggerContext,
|
|
1555
|
+
})(execute),
|
|
1556
|
+
};
|
|
1557
|
+
}
|
|
1558
|
+
// Default: AISDK tools-based agent
|
|
1559
|
+
const agentConfigSignature = this.agentCache.buildConfigSignature(options);
|
|
1560
|
+
const isStreaming = options?.stream ?? false;
|
|
1561
|
+
const execute = async (instructionOrOptions) => withInstanceLogContext(this.instanceId, async () => {
|
|
1562
|
+
validateExperimentalFeatures({
|
|
1563
|
+
isExperimental: this.experimental,
|
|
1564
|
+
agentConfig: options,
|
|
1565
|
+
executeOptions: typeof instructionOrOptions === "object"
|
|
1566
|
+
? instructionOrOptions
|
|
1567
|
+
: null,
|
|
1568
|
+
isStreaming,
|
|
1569
|
+
});
|
|
1570
|
+
// Streaming mode
|
|
1571
|
+
if (isStreaming) {
|
|
1572
|
+
const { handler, resolvedOptions, cacheContext, llmClient } = await this.prepareAgentExecution(options, instructionOrOptions, agentConfigSignature);
|
|
1573
|
+
if (cacheContext) {
|
|
1574
|
+
const replayed = await this.agentCache.tryReplayAsStream(cacheContext, llmClient);
|
|
1575
|
+
if (replayed) {
|
|
1576
|
+
return replayed;
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
const streamResult = await handler.stream(resolvedOptions);
|
|
1580
|
+
if (cacheContext) {
|
|
1581
|
+
const wrappedStream = this.agentCache.wrapStreamForCaching(cacheContext, streamResult, () => this.beginAgentReplayRecording(), () => this.endAgentReplayRecording(), () => this.discardAgentReplayRecording());
|
|
1582
|
+
return wrappedStream;
|
|
1583
|
+
}
|
|
1584
|
+
return streamResult;
|
|
1585
|
+
}
|
|
1586
|
+
// Non-streaming mode (default)
|
|
1587
|
+
const { handler, resolvedOptions, cacheContext, llmClient } = await this.prepareAgentExecution(options, instructionOrOptions, agentConfigSignature);
|
|
1588
|
+
if (cacheContext) {
|
|
1589
|
+
const replayed = await this.agentCache.tryReplay(cacheContext, llmClient);
|
|
1590
|
+
if (replayed) {
|
|
1591
|
+
return replayed;
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
let agentSteps = [];
|
|
1595
|
+
const shouldRecordLocally = !!cacheContext && (!this.apiClient || this.experimental);
|
|
1596
|
+
if (shouldRecordLocally) {
|
|
1597
|
+
this.beginAgentReplayRecording();
|
|
1598
|
+
}
|
|
1599
|
+
let result;
|
|
1600
|
+
try {
|
|
1601
|
+
if (this.apiClient && !this.experimental) {
|
|
1602
|
+
const page = await this.ctx.awaitActivePage();
|
|
1603
|
+
result = await this.apiClient.agentExecute(options ?? {}, resolvedOptions, page.mainFrameId(), !!cacheContext);
|
|
1604
|
+
if (cacheContext) {
|
|
1605
|
+
const transferredEntry = this.apiClient.consumeLatestAgentCacheEntry();
|
|
1606
|
+
await this.agentCache.storeTransferredEntry(transferredEntry);
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
else {
|
|
1610
|
+
result = await handler.execute(resolvedOptions);
|
|
1611
|
+
}
|
|
1612
|
+
if (shouldRecordLocally) {
|
|
1613
|
+
agentSteps = this.endAgentReplayRecording();
|
|
1614
|
+
}
|
|
1615
|
+
if (shouldRecordLocally &&
|
|
1616
|
+
cacheContext &&
|
|
1617
|
+
result.success &&
|
|
1618
|
+
agentSteps.length > 0) {
|
|
1619
|
+
await this.agentCache.store(cacheContext, agentSteps, result);
|
|
1620
|
+
}
|
|
1621
|
+
return result;
|
|
1622
|
+
}
|
|
1623
|
+
catch (err) {
|
|
1624
|
+
if (shouldRecordLocally)
|
|
1625
|
+
this.discardAgentReplayRecording();
|
|
1626
|
+
throw err;
|
|
1627
|
+
}
|
|
1628
|
+
finally {
|
|
1629
|
+
if (shouldRecordLocally) {
|
|
1630
|
+
this.discardAgentReplayRecording();
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
});
|
|
1634
|
+
return {
|
|
1635
|
+
execute: FlowLogger.wrapWithLogging({
|
|
1636
|
+
eventType: "AgentExecute",
|
|
1637
|
+
context: this.flowLoggerContext,
|
|
1638
|
+
})(execute),
|
|
1570
1639
|
};
|
|
1571
1640
|
}
|
|
1572
1641
|
};
|