@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/cjs/lib/v3/v3.js
CHANGED
|
@@ -71,7 +71,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
71
71
|
};
|
|
72
72
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
73
73
|
exports.V3 = void 0;
|
|
74
|
-
|
|
74
|
+
exports.resolveModelConfiguration = resolveModelConfiguration;
|
|
75
75
|
const fs_1 = __importDefault(require("fs"));
|
|
76
76
|
const os_1 = __importDefault(require("os"));
|
|
77
77
|
const path_1 = __importDefault(require("path"));
|
|
@@ -89,6 +89,7 @@ const extractHandler_js_1 = require("./handlers/extractHandler.js");
|
|
|
89
89
|
const observeHandler_js_1 = require("./handlers/observeHandler.js");
|
|
90
90
|
const v3AgentHandler_js_1 = require("./handlers/v3AgentHandler.js");
|
|
91
91
|
const v3CuaAgentHandler_js_1 = require("./handlers/v3CuaAgentHandler.js");
|
|
92
|
+
const captchaSolver_js_1 = require("./agent/utils/captchaSolver.js");
|
|
92
93
|
const browserbase_js_1 = require("./launch/browserbase.js");
|
|
93
94
|
const local_js_1 = require("./launch/local.js");
|
|
94
95
|
const LLMProvider_js_1 = require("./llm/LLMProvider.js");
|
|
@@ -102,11 +103,14 @@ const modelUtils_js_2 = require("../modelUtils.js");
|
|
|
102
103
|
const api_js_1 = require("./api.js");
|
|
103
104
|
const validateExperimentalFeatures_js_1 = require("./agent/utils/validateExperimentalFeatures.js");
|
|
104
105
|
const variables_js_1 = require("./agent/utils/variables.js");
|
|
105
|
-
const
|
|
106
|
+
const FlowLogger_js_1 = require("./flowlogger/FlowLogger.js");
|
|
107
|
+
const EventEmitter_js_1 = require("./flowlogger/EventEmitter.js");
|
|
108
|
+
const EventStore_js_1 = require("./flowlogger/EventStore.js");
|
|
106
109
|
const timeoutGuard_js_1 = require("./handlers/handlerUtils/timeoutGuard.js");
|
|
107
110
|
const sdkErrors_js_1 = require("./types/public/sdkErrors.js");
|
|
108
111
|
const DEFAULT_MODEL_NAME = "openai/gpt-4.1-mini";
|
|
109
112
|
const DEFAULT_VIEWPORT = { width: 1288, height: 711 };
|
|
113
|
+
const DEFAULT_AGENT_TOOL_TIMEOUT_MS = 45000;
|
|
110
114
|
function resolveModelConfiguration(model) {
|
|
111
115
|
if (!model) {
|
|
112
116
|
return { modelName: DEFAULT_MODEL_NAME };
|
|
@@ -115,13 +119,14 @@ function resolveModelConfiguration(model) {
|
|
|
115
119
|
return { modelName: model };
|
|
116
120
|
}
|
|
117
121
|
if (model && typeof model === "object") {
|
|
118
|
-
const { modelName, ...clientOptions } = model;
|
|
122
|
+
const { modelName, middleware, ...clientOptions } = model;
|
|
119
123
|
if (!modelName) {
|
|
120
124
|
throw new index_js_1.StagehandInvalidArgumentError("model.modelName is required when providing client options.");
|
|
121
125
|
}
|
|
122
126
|
return {
|
|
123
127
|
modelName,
|
|
124
128
|
clientOptions: clientOptions,
|
|
129
|
+
middleware,
|
|
125
130
|
};
|
|
126
131
|
}
|
|
127
132
|
return { modelName: DEFAULT_MODEL_NAME };
|
|
@@ -149,9 +154,15 @@ let V3 = (() => {
|
|
|
149
154
|
return class V3 {
|
|
150
155
|
static {
|
|
151
156
|
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
152
|
-
_act_decorators = [
|
|
153
|
-
|
|
154
|
-
|
|
157
|
+
_act_decorators = [FlowLogger_js_1.FlowLogger.wrapWithLogging({
|
|
158
|
+
eventType: "StagehandAct",
|
|
159
|
+
})];
|
|
160
|
+
_extract_decorators = [FlowLogger_js_1.FlowLogger.wrapWithLogging({
|
|
161
|
+
eventType: "StagehandExtract",
|
|
162
|
+
})];
|
|
163
|
+
_observe_decorators = [FlowLogger_js_1.FlowLogger.wrapWithLogging({
|
|
164
|
+
eventType: "StagehandObserve",
|
|
165
|
+
})];
|
|
155
166
|
__esDecorate(this, null, _act_decorators, { kind: "method", name: "act", static: false, private: false, access: { has: obj => "act" in obj, get: obj => obj.act }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
156
167
|
__esDecorate(this, null, _extract_decorators, { kind: "method", name: "extract", static: false, private: false, access: { has: obj => "extract" in obj, get: obj => obj.extract }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
157
168
|
__esDecorate(this, null, _observe_decorators, { kind: "method", name: "observe", static: false, private: false, access: { has: obj => "observe" in obj, get: obj => obj.observe }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
@@ -168,7 +179,7 @@ let V3 = (() => {
|
|
|
168
179
|
* Event bus for internal communication.
|
|
169
180
|
* Emits events like 'screenshot' when screenshots are captured during agent execution.
|
|
170
181
|
*/
|
|
171
|
-
bus = new
|
|
182
|
+
bus = new EventEmitter_js_1.EventEmitterWithWildcardSupport();
|
|
172
183
|
modelName;
|
|
173
184
|
modelClientOptions;
|
|
174
185
|
llmProvider;
|
|
@@ -193,6 +204,15 @@ let V3 = (() => {
|
|
|
193
204
|
get isBrowserbase() {
|
|
194
205
|
return this.state.kind === "BROWSERBASE";
|
|
195
206
|
}
|
|
207
|
+
/**
|
|
208
|
+
* Returns true if captcha auto-solving is enabled on Browserbase.
|
|
209
|
+
* Defaults to true when not explicitly set to false.
|
|
210
|
+
*/
|
|
211
|
+
get isCaptchaAutoSolveEnabled() {
|
|
212
|
+
return (this.isBrowserbase &&
|
|
213
|
+
this.opts.browserbaseSessionCreateParams?.browserSettings
|
|
214
|
+
?.solveCaptchas !== false);
|
|
215
|
+
}
|
|
196
216
|
/**
|
|
197
217
|
* Returns true if advancedStealth is enabled in Browserbase settings.
|
|
198
218
|
*/
|
|
@@ -236,6 +256,9 @@ let V3 = (() => {
|
|
|
236
256
|
stagehandLogger;
|
|
237
257
|
_history = [];
|
|
238
258
|
instanceId;
|
|
259
|
+
sessionId;
|
|
260
|
+
eventStore;
|
|
261
|
+
flowLoggerContext;
|
|
239
262
|
static _processGuardsInstalled = false;
|
|
240
263
|
static _instances = new Set();
|
|
241
264
|
cacheStorage;
|
|
@@ -275,6 +298,7 @@ let V3 = (() => {
|
|
|
275
298
|
this.externalLogger = opts.logger;
|
|
276
299
|
this.verbose = opts.verbose ?? 1;
|
|
277
300
|
this.instanceId = (0, uuid_1.v7)();
|
|
301
|
+
this.sessionId = opts.sessionId ?? this.instanceId;
|
|
278
302
|
this.keepAlive =
|
|
279
303
|
opts.keepAlive ?? opts.browserbaseSessionCreateParams?.keepAlive;
|
|
280
304
|
// Create per-instance StagehandLogger (handles usePino, verbose, externalLogger)
|
|
@@ -306,11 +330,11 @@ let V3 = (() => {
|
|
|
306
330
|
catch {
|
|
307
331
|
// ignore
|
|
308
332
|
}
|
|
309
|
-
const { modelName, clientOptions } = resolveModelConfiguration(opts.model);
|
|
333
|
+
const { modelName, clientOptions, middleware } = resolveModelConfiguration(opts.model);
|
|
310
334
|
this.modelName = modelName;
|
|
311
335
|
this.experimental = opts.experimental ?? false;
|
|
312
336
|
this.logInferenceToFile = opts.logInferenceToFile ?? false;
|
|
313
|
-
this.llmProvider = new LLMProvider_js_1.LLMProvider(this.logger);
|
|
337
|
+
this.llmProvider = new LLMProvider_js_1.LLMProvider(this.logger, middleware);
|
|
314
338
|
this.domSettleTimeoutMs = opts.domSettleTimeout;
|
|
315
339
|
this.disableAPI = opts.disableAPI ?? false;
|
|
316
340
|
const baseClientOptions = clientOptions
|
|
@@ -367,8 +391,21 @@ let V3 = (() => {
|
|
|
367
391
|
act: this.act.bind(this),
|
|
368
392
|
});
|
|
369
393
|
this.opts = opts;
|
|
370
|
-
//
|
|
371
|
-
|
|
394
|
+
// FlowLogger always gets a per-instance session context and shared event
|
|
395
|
+
// bus. The attached EventStore decides which sinks are active:
|
|
396
|
+
// `BROWSERBASE_FLOW_LOGS=1` enables pretty stderr output,
|
|
397
|
+
// and `BROWSERBASE_CONFIG_DIR` enables the pretty/jsonl file sinks for this session.
|
|
398
|
+
this.eventStore = new EventStore_js_1.EventStore(this.sessionId, opts);
|
|
399
|
+
this.flowLoggerContext = FlowLogger_js_1.FlowLogger.init(this.sessionId, this.bus);
|
|
400
|
+
// Flow event pipeline:
|
|
401
|
+
// FlowLogger -> this.bus -> this.eventStore -> configured sinks/query history.
|
|
402
|
+
// V3 owns the bus for this session. EventStore is not another bus; it just
|
|
403
|
+
// receives already-emitted FlowEvents here, then fans them out to sinks and
|
|
404
|
+
// keeps the queryable per-session history used by /v4/log, parent/ancestor lookups, and tests.
|
|
405
|
+
// `on()` stores a strong reference to the handler, so the EventStore
|
|
406
|
+
// stays alive until this bus is garbage-collected with the rest of the V3
|
|
407
|
+
// object graph.
|
|
408
|
+
this.bus.on("*", this.eventStore.emit);
|
|
372
409
|
// Track instance for global process guard handling
|
|
373
410
|
V3._instances.add(this);
|
|
374
411
|
}
|
|
@@ -398,15 +435,18 @@ let V3 = (() => {
|
|
|
398
435
|
}
|
|
399
436
|
let modelName;
|
|
400
437
|
let clientOptions;
|
|
438
|
+
let perCallMiddleware;
|
|
401
439
|
if (typeof model === "string") {
|
|
402
440
|
modelName = model;
|
|
403
441
|
}
|
|
404
442
|
else {
|
|
405
|
-
const { modelName: overrideModelName, ...rest } = model;
|
|
443
|
+
const { modelName: overrideModelName, middleware, ...rest } = model;
|
|
406
444
|
modelName = overrideModelName;
|
|
407
445
|
clientOptions = rest;
|
|
446
|
+
perCallMiddleware = middleware;
|
|
408
447
|
}
|
|
409
448
|
if (modelName === this.modelName &&
|
|
449
|
+
!perCallMiddleware &&
|
|
410
450
|
(!clientOptions || Object.keys(clientOptions).length === 0)) {
|
|
411
451
|
return this.llmClient;
|
|
412
452
|
}
|
|
@@ -423,6 +463,13 @@ let V3 = (() => {
|
|
|
423
463
|
mergedOptions.apiKey = apiKey;
|
|
424
464
|
}
|
|
425
465
|
}
|
|
466
|
+
if (perCallMiddleware) {
|
|
467
|
+
return this.llmProvider.getClient(modelName, mergedOptions, {
|
|
468
|
+
experimental: this.experimental,
|
|
469
|
+
disableAPI: this.disableAPI,
|
|
470
|
+
middleware: perCallMiddleware,
|
|
471
|
+
});
|
|
472
|
+
}
|
|
426
473
|
const cacheKey = JSON.stringify({
|
|
427
474
|
modelName,
|
|
428
475
|
clientOptions: mergedOptions,
|
|
@@ -431,7 +478,10 @@ let V3 = (() => {
|
|
|
431
478
|
if (cached) {
|
|
432
479
|
return cached;
|
|
433
480
|
}
|
|
434
|
-
const client = this.llmProvider.getClient(modelName, mergedOptions, {
|
|
481
|
+
const client = this.llmProvider.getClient(modelName, mergedOptions, {
|
|
482
|
+
experimental: this.experimental,
|
|
483
|
+
disableAPI: this.disableAPI,
|
|
484
|
+
});
|
|
435
485
|
this.overrideLlmClients.set(cacheKey, client);
|
|
436
486
|
return client;
|
|
437
487
|
}
|
|
@@ -591,6 +641,13 @@ let V3 = (() => {
|
|
|
591
641
|
}
|
|
592
642
|
}
|
|
593
643
|
const lbo = this.opts.localBrowserLaunchOptions ?? {};
|
|
644
|
+
if (lbo.cdpHeaders && !lbo.cdpUrl) {
|
|
645
|
+
this.logger({
|
|
646
|
+
category: "init",
|
|
647
|
+
message: "`cdpHeaders` was provided but `cdpUrl` is not set — cdpHeaders will be ignored. Set `cdpUrl` to connect to an existing browser via CDP.",
|
|
648
|
+
level: 2,
|
|
649
|
+
});
|
|
650
|
+
}
|
|
594
651
|
// If a CDP URL is provided, attach instead of launching.
|
|
595
652
|
if (lbo.cdpUrl) {
|
|
596
653
|
this.logger({
|
|
@@ -600,10 +657,9 @@ let V3 = (() => {
|
|
|
600
657
|
});
|
|
601
658
|
this.ctx = await context_js_1.V3Context.create(lbo.cdpUrl, {
|
|
602
659
|
env: "LOCAL",
|
|
660
|
+
cdpHeaders: lbo.cdpHeaders,
|
|
603
661
|
});
|
|
604
|
-
|
|
605
|
-
this.ctx.conn.cdpLogger = (info) => flowLogger_js_1.SessionFileLogger.logCdpCallEvent(info, logCtx);
|
|
606
|
-
this.ctx.conn.cdpEventLogger = (info) => flowLogger_js_1.SessionFileLogger.logCdpMessageEvent(info, logCtx);
|
|
662
|
+
this.ctx.conn.flowLoggerContext = this.flowLoggerContext;
|
|
607
663
|
this.ctx.conn.onTransportClosed(this._onCdpClosed);
|
|
608
664
|
this.state = {
|
|
609
665
|
kind: "LOCAL",
|
|
@@ -699,9 +755,7 @@ let V3 = (() => {
|
|
|
699
755
|
env: "LOCAL",
|
|
700
756
|
localBrowserLaunchOptions: lbo,
|
|
701
757
|
});
|
|
702
|
-
|
|
703
|
-
this.ctx.conn.cdpLogger = (info) => flowLogger_js_1.SessionFileLogger.logCdpCallEvent(info, logCtx);
|
|
704
|
-
this.ctx.conn.cdpEventLogger = (info) => flowLogger_js_1.SessionFileLogger.logCdpMessageEvent(info, logCtx);
|
|
758
|
+
this.ctx.conn.flowLoggerContext = this.flowLoggerContext;
|
|
705
759
|
this.ctx.conn.onTransportClosed(this._onCdpClosed);
|
|
706
760
|
this.state = {
|
|
707
761
|
kind: "LOCAL",
|
|
@@ -728,9 +782,6 @@ let V3 = (() => {
|
|
|
728
782
|
}
|
|
729
783
|
if (this.opts.env === "BROWSERBASE") {
|
|
730
784
|
const { apiKey, projectId } = this.requireBrowserbaseCreds();
|
|
731
|
-
if (!apiKey || !projectId) {
|
|
732
|
-
throw new index_js_1.MissingEnvironmentVariableError("BROWSERBASE_API_KEY and BROWSERBASE_PROJECT_ID", "Browserbase environment");
|
|
733
|
-
}
|
|
734
785
|
this.logger({
|
|
735
786
|
category: "init",
|
|
736
787
|
message: "Starting browserbase session",
|
|
@@ -739,9 +790,13 @@ let V3 = (() => {
|
|
|
739
790
|
const baseSessionParams = this.opts.browserbaseSessionCreateParams ?? {};
|
|
740
791
|
const resolvedKeepAlive = this.keepAlive;
|
|
741
792
|
const keepAlive = this.keepAlive === true;
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
793
|
+
let effectiveSessionParams = baseSessionParams;
|
|
794
|
+
if (resolvedKeepAlive !== undefined) {
|
|
795
|
+
effectiveSessionParams = {
|
|
796
|
+
...baseSessionParams,
|
|
797
|
+
keepAlive: resolvedKeepAlive,
|
|
798
|
+
};
|
|
799
|
+
}
|
|
745
800
|
if (!this.disableAPI && !this.experimental) {
|
|
746
801
|
this.apiClient = new api_js_1.StagehandAPIClient({
|
|
747
802
|
apiKey,
|
|
@@ -749,18 +804,20 @@ let V3 = (() => {
|
|
|
749
804
|
logger: this.logger,
|
|
750
805
|
serverCache: this.opts.serverCache,
|
|
751
806
|
});
|
|
807
|
+
const { projectId: overrideProjectId, browserSettings, userMetadata, ...restSessionParams } = effectiveSessionParams;
|
|
808
|
+
const resolvedProjectId = overrideProjectId ?? projectId;
|
|
752
809
|
const createSessionPayload = {
|
|
753
|
-
projectId:
|
|
754
|
-
...
|
|
810
|
+
...(resolvedProjectId ? { projectId: resolvedProjectId } : {}),
|
|
811
|
+
...restSessionParams,
|
|
755
812
|
browserSettings: {
|
|
756
|
-
...(
|
|
757
|
-
viewport:
|
|
813
|
+
...(browserSettings ?? {}),
|
|
814
|
+
viewport: browserSettings?.viewport ?? {
|
|
758
815
|
width: 1288,
|
|
759
816
|
height: 711,
|
|
760
817
|
},
|
|
761
818
|
},
|
|
762
819
|
userMetadata: {
|
|
763
|
-
...(
|
|
820
|
+
...(userMetadata ?? {}),
|
|
764
821
|
stagehand: "true",
|
|
765
822
|
},
|
|
766
823
|
};
|
|
@@ -784,9 +841,7 @@ let V3 = (() => {
|
|
|
784
841
|
env: "BROWSERBASE",
|
|
785
842
|
apiClient: this.apiClient,
|
|
786
843
|
});
|
|
787
|
-
|
|
788
|
-
this.ctx.conn.cdpLogger = (info) => flowLogger_js_1.SessionFileLogger.logCdpCallEvent(info, logCtx);
|
|
789
|
-
this.ctx.conn.cdpEventLogger = (info) => flowLogger_js_1.SessionFileLogger.logCdpMessageEvent(info, logCtx);
|
|
844
|
+
this.ctx.conn.flowLoggerContext = this.flowLoggerContext;
|
|
790
845
|
this.ctx.conn.onTransportClosed(this._onCdpClosed);
|
|
791
846
|
this.state = { kind: "BROWSERBASE", sessionId, ws, bb };
|
|
792
847
|
this.browserbaseSessionId = sessionId;
|
|
@@ -908,10 +963,7 @@ let V3 = (() => {
|
|
|
908
963
|
});
|
|
909
964
|
}
|
|
910
965
|
else {
|
|
911
|
-
const
|
|
912
|
-
? options.timeout
|
|
913
|
-
: undefined;
|
|
914
|
-
const ensureTimeRemaining = (0, timeoutGuard_js_1.createTimeoutGuard)(effectiveTimeoutMs, (ms) => new sdkErrors_js_1.ActTimeoutError(ms));
|
|
966
|
+
const ensureTimeRemaining = (0, timeoutGuard_js_1.createTimeoutGuard)(options?.timeout, (ms) => new sdkErrors_js_1.ActTimeoutError(ms));
|
|
915
967
|
actResult = await this.actHandler.takeDeterministicAction({ ...input, selector }, v3Page, this.domSettleTimeoutMs, this.resolveLlmClient(options?.model), ensureTimeRemaining, options?.variables);
|
|
916
968
|
}
|
|
917
969
|
// history: record ObserveResult-based act call
|
|
@@ -1065,6 +1117,7 @@ let V3 = (() => {
|
|
|
1065
1117
|
const handlerParams = {
|
|
1066
1118
|
instruction,
|
|
1067
1119
|
model: options?.model,
|
|
1120
|
+
variables: options?.variables,
|
|
1068
1121
|
timeout: options?.timeout,
|
|
1069
1122
|
selector: options?.selector,
|
|
1070
1123
|
page: page,
|
|
@@ -1084,6 +1137,7 @@ let V3 = (() => {
|
|
|
1084
1137
|
// history: record observe call (omit page object)
|
|
1085
1138
|
this.addToHistory("observe", {
|
|
1086
1139
|
instruction,
|
|
1140
|
+
variables: options?.variables,
|
|
1087
1141
|
timeout: options?.timeout,
|
|
1088
1142
|
}, results);
|
|
1089
1143
|
return results;
|
|
@@ -1132,7 +1186,7 @@ let V3 = (() => {
|
|
|
1132
1186
|
try {
|
|
1133
1187
|
// Close session file logger
|
|
1134
1188
|
try {
|
|
1135
|
-
await
|
|
1189
|
+
await FlowLogger_js_1.FlowLogger.close(this.flowLoggerContext);
|
|
1136
1190
|
}
|
|
1137
1191
|
catch {
|
|
1138
1192
|
// ignore
|
|
@@ -1168,6 +1222,12 @@ let V3 = (() => {
|
|
|
1168
1222
|
catch {
|
|
1169
1223
|
// ignore
|
|
1170
1224
|
}
|
|
1225
|
+
try {
|
|
1226
|
+
await this.eventStore.destroy();
|
|
1227
|
+
}
|
|
1228
|
+
catch {
|
|
1229
|
+
// ignore
|
|
1230
|
+
}
|
|
1171
1231
|
try {
|
|
1172
1232
|
this.bus.removeAllListeners();
|
|
1173
1233
|
}
|
|
@@ -1181,6 +1241,13 @@ let V3 = (() => {
|
|
|
1181
1241
|
V3._instances.delete(this);
|
|
1182
1242
|
}
|
|
1183
1243
|
}
|
|
1244
|
+
/**
|
|
1245
|
+
* Resolves the Browserbase API key from options or environment variables.
|
|
1246
|
+
* Returns undefined if no key is found (does not throw).
|
|
1247
|
+
*/
|
|
1248
|
+
get browserbaseApiKey() {
|
|
1249
|
+
return this.opts.apiKey || process_1.default.env.BROWSERBASE_API_KEY;
|
|
1250
|
+
}
|
|
1184
1251
|
/** Guard: ensure Browserbase credentials exist in options. */
|
|
1185
1252
|
requireBrowserbaseCreds() {
|
|
1186
1253
|
let { apiKey, projectId } = this.opts;
|
|
@@ -1190,17 +1257,13 @@ let V3 = (() => {
|
|
|
1190
1257
|
if (!projectId)
|
|
1191
1258
|
projectId =
|
|
1192
1259
|
process_1.default.env.BROWSERBASE_PROJECT_ID ?? process_1.default.env.BB_PROJECT_ID;
|
|
1193
|
-
if (!apiKey
|
|
1194
|
-
|
|
1195
|
-
if (!apiKey)
|
|
1196
|
-
missing.push("BROWSERBASE_API_KEY");
|
|
1197
|
-
if (!projectId)
|
|
1198
|
-
missing.push("BROWSERBASE_PROJECT_ID");
|
|
1199
|
-
throw new index_js_1.MissingEnvironmentVariableError(missing.join(", "), "Browserbase");
|
|
1260
|
+
if (!apiKey) {
|
|
1261
|
+
throw new index_js_1.MissingEnvironmentVariableError("BROWSERBASE_API_KEY", "Browserbase");
|
|
1200
1262
|
}
|
|
1201
1263
|
// Cache resolved values back into opts for consistency
|
|
1202
1264
|
this.opts.apiKey = apiKey;
|
|
1203
|
-
|
|
1265
|
+
if (projectId)
|
|
1266
|
+
this.opts.projectId = projectId;
|
|
1204
1267
|
// Informational log
|
|
1205
1268
|
this.logger({
|
|
1206
1269
|
category: "init",
|
|
@@ -1342,10 +1405,16 @@ let V3 = (() => {
|
|
|
1342
1405
|
? this.resolveLlmClient(options.model)
|
|
1343
1406
|
: this.llmClient;
|
|
1344
1407
|
const resolvedExecutionModel = options?.executionModel ?? options?.model;
|
|
1345
|
-
const handler = new v3AgentHandler_js_1.V3AgentHandler(this, this.logger, agentLlmClient, resolvedExecutionModel, options?.systemPrompt, tools, options?.mode);
|
|
1408
|
+
const handler = new v3AgentHandler_js_1.V3AgentHandler(this, this.logger, agentLlmClient, resolvedExecutionModel, options?.systemPrompt, tools, options?.mode, this.isCaptchaAutoSolveEnabled);
|
|
1346
1409
|
const resolvedOptions = typeof instructionOrOptions === "string"
|
|
1347
|
-
? {
|
|
1348
|
-
|
|
1410
|
+
? {
|
|
1411
|
+
instruction: instructionOrOptions,
|
|
1412
|
+
toolTimeout: DEFAULT_AGENT_TOOL_TIMEOUT_MS,
|
|
1413
|
+
}
|
|
1414
|
+
: {
|
|
1415
|
+
...instructionOrOptions,
|
|
1416
|
+
toolTimeout: instructionOrOptions.toolTimeout ?? DEFAULT_AGENT_TOOL_TIMEOUT_MS,
|
|
1417
|
+
};
|
|
1349
1418
|
const callbacksWithSafety = resolvedOptions.callbacks;
|
|
1350
1419
|
if (callbacksWithSafety?.onSafetyConfirmation) {
|
|
1351
1420
|
throw new index_js_1.StagehandInvalidArgumentError('onSafetyConfirmation callback is only supported when using mode: "cua" agents.');
|
|
@@ -1425,145 +1494,59 @@ let V3 = (() => {
|
|
|
1425
1494
|
throw new index_js_1.CuaModelRequiredError(index_js_1.AVAILABLE_CUA_MODELS);
|
|
1426
1495
|
}
|
|
1427
1496
|
const agentConfigSignature = this.agentCache.buildConfigSignature(options);
|
|
1428
|
-
|
|
1429
|
-
execute: async (instructionOrOptions) => (0, logger_js_2.withInstanceLogContext)(this.instanceId, async () => {
|
|
1430
|
-
(0, validateExperimentalFeatures_js_1.validateExperimentalFeatures)({
|
|
1431
|
-
isExperimental: this.experimental,
|
|
1432
|
-
agentConfig: options,
|
|
1433
|
-
executeOptions: typeof instructionOrOptions === "object"
|
|
1434
|
-
? instructionOrOptions
|
|
1435
|
-
: null,
|
|
1436
|
-
});
|
|
1437
|
-
flowLogger_js_1.SessionFileLogger.logAgentTaskStarted({
|
|
1438
|
-
invocation: "Agent.execute",
|
|
1439
|
-
args: [instructionOrOptions],
|
|
1440
|
-
});
|
|
1441
|
-
const tools = options?.integrations
|
|
1442
|
-
? await (0, utils_js_2.resolveTools)(options.integrations, options.tools)
|
|
1443
|
-
: (options?.tools ?? {});
|
|
1444
|
-
const handler = new v3CuaAgentHandler_js_1.V3CuaAgentHandler(this, this.logger, {
|
|
1445
|
-
modelName,
|
|
1446
|
-
clientOptions,
|
|
1447
|
-
userProvidedInstructions: options.systemPrompt ??
|
|
1448
|
-
`You are a helpful assistant that can use a web browser.\nDo not ask follow up questions, the user will trust your judgement.`,
|
|
1449
|
-
}, tools);
|
|
1450
|
-
const resolvedOptions = typeof instructionOrOptions === "string"
|
|
1451
|
-
? { instruction: instructionOrOptions }
|
|
1452
|
-
: instructionOrOptions;
|
|
1453
|
-
if (resolvedOptions.page) {
|
|
1454
|
-
const normalizedPage = await this.normalizeToV3Page(resolvedOptions.page);
|
|
1455
|
-
this.ctx.setActivePage(normalizedPage);
|
|
1456
|
-
}
|
|
1457
|
-
const instruction = resolvedOptions.instruction.trim();
|
|
1458
|
-
const sanitizedOptions = this.agentCache.sanitizeExecuteOptions(resolvedOptions);
|
|
1459
|
-
const cacheVariables = (0, variables_js_1.flattenVariables)(resolvedOptions.variables);
|
|
1460
|
-
let cacheContext = null;
|
|
1461
|
-
if (this.agentCache.shouldAttemptCache(instruction)) {
|
|
1462
|
-
const startPage = await this.ctx.awaitActivePage();
|
|
1463
|
-
cacheContext = await this.agentCache.prepareContext({
|
|
1464
|
-
instruction,
|
|
1465
|
-
options: sanitizedOptions,
|
|
1466
|
-
configSignature: agentConfigSignature,
|
|
1467
|
-
page: startPage,
|
|
1468
|
-
variables: cacheVariables,
|
|
1469
|
-
});
|
|
1470
|
-
if (cacheContext) {
|
|
1471
|
-
const replayed = await this.agentCache.tryReplay(cacheContext);
|
|
1472
|
-
if (replayed) {
|
|
1473
|
-
flowLogger_js_1.SessionFileLogger.logAgentTaskCompleted({ cacheHit: true });
|
|
1474
|
-
return replayed;
|
|
1475
|
-
}
|
|
1476
|
-
}
|
|
1477
|
-
}
|
|
1478
|
-
let agentSteps = [];
|
|
1479
|
-
const shouldRecordLocally = !!cacheContext && (!this.apiClient || this.experimental);
|
|
1480
|
-
if (shouldRecordLocally) {
|
|
1481
|
-
this.beginAgentReplayRecording();
|
|
1482
|
-
}
|
|
1483
|
-
let result;
|
|
1484
|
-
try {
|
|
1485
|
-
if (this.apiClient && !this.experimental) {
|
|
1486
|
-
const page = await this.ctx.awaitActivePage();
|
|
1487
|
-
result = await this.apiClient.agentExecute(options, resolvedOptions, page.mainFrameId(), !!cacheContext);
|
|
1488
|
-
if (cacheContext) {
|
|
1489
|
-
const transferredEntry = this.apiClient.consumeLatestAgentCacheEntry();
|
|
1490
|
-
await this.agentCache.storeTransferredEntry(transferredEntry);
|
|
1491
|
-
}
|
|
1492
|
-
}
|
|
1493
|
-
else {
|
|
1494
|
-
result = await handler.execute(instructionOrOptions);
|
|
1495
|
-
}
|
|
1496
|
-
if (shouldRecordLocally) {
|
|
1497
|
-
agentSteps = this.endAgentReplayRecording();
|
|
1498
|
-
}
|
|
1499
|
-
if (shouldRecordLocally &&
|
|
1500
|
-
cacheContext &&
|
|
1501
|
-
result.success &&
|
|
1502
|
-
agentSteps.length > 0) {
|
|
1503
|
-
await this.agentCache.store(cacheContext, agentSteps, result);
|
|
1504
|
-
}
|
|
1505
|
-
return result;
|
|
1506
|
-
}
|
|
1507
|
-
catch (err) {
|
|
1508
|
-
if (shouldRecordLocally)
|
|
1509
|
-
this.discardAgentReplayRecording();
|
|
1510
|
-
throw err;
|
|
1511
|
-
}
|
|
1512
|
-
finally {
|
|
1513
|
-
if (shouldRecordLocally) {
|
|
1514
|
-
this.discardAgentReplayRecording();
|
|
1515
|
-
}
|
|
1516
|
-
flowLogger_js_1.SessionFileLogger.logAgentTaskCompleted();
|
|
1517
|
-
}
|
|
1518
|
-
}),
|
|
1519
|
-
};
|
|
1520
|
-
}
|
|
1521
|
-
// Default: AISDK tools-based agent
|
|
1522
|
-
const agentConfigSignature = this.agentCache.buildConfigSignature(options);
|
|
1523
|
-
const isStreaming = options?.stream ?? false;
|
|
1524
|
-
return {
|
|
1525
|
-
execute: async (instructionOrOptions) => (0, logger_js_2.withInstanceLogContext)(this.instanceId, async () => {
|
|
1497
|
+
const execute = async (instructionOrOptions) => (0, logger_js_2.withInstanceLogContext)(this.instanceId, async () => {
|
|
1526
1498
|
(0, validateExperimentalFeatures_js_1.validateExperimentalFeatures)({
|
|
1527
1499
|
isExperimental: this.experimental,
|
|
1528
1500
|
agentConfig: options,
|
|
1529
1501
|
executeOptions: typeof instructionOrOptions === "object"
|
|
1530
1502
|
? instructionOrOptions
|
|
1531
1503
|
: null,
|
|
1532
|
-
isStreaming,
|
|
1533
|
-
});
|
|
1534
|
-
flowLogger_js_1.SessionFileLogger.logAgentTaskStarted({
|
|
1535
|
-
invocation: "Agent.execute",
|
|
1536
|
-
args: [instructionOrOptions],
|
|
1537
1504
|
});
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1505
|
+
const tools = options?.integrations
|
|
1506
|
+
? await (0, utils_js_2.resolveTools)(options.integrations, options.tools)
|
|
1507
|
+
: (options?.tools ?? {});
|
|
1508
|
+
const handler = new v3CuaAgentHandler_js_1.V3CuaAgentHandler(this, this.logger, {
|
|
1509
|
+
modelName,
|
|
1510
|
+
clientOptions,
|
|
1511
|
+
userProvidedInstructions: (options.systemPrompt ??
|
|
1512
|
+
`You are a helpful assistant that can use a web browser.\nDo not ask follow up questions, the user will trust your judgement.`) +
|
|
1513
|
+
(this.isCaptchaAutoSolveEnabled
|
|
1514
|
+
? captchaSolver_js_1.CAPTCHA_CUA_SYSTEM_PROMPT_NOTE
|
|
1515
|
+
: ""),
|
|
1516
|
+
}, tools);
|
|
1517
|
+
const resolvedOptions = typeof instructionOrOptions === "string"
|
|
1518
|
+
? {
|
|
1519
|
+
instruction: instructionOrOptions,
|
|
1520
|
+
toolTimeout: DEFAULT_AGENT_TOOL_TIMEOUT_MS,
|
|
1521
|
+
}
|
|
1522
|
+
: {
|
|
1523
|
+
...instructionOrOptions,
|
|
1524
|
+
toolTimeout: instructionOrOptions.toolTimeout ??
|
|
1525
|
+
DEFAULT_AGENT_TOOL_TIMEOUT_MS,
|
|
1526
|
+
};
|
|
1527
|
+
if (resolvedOptions.page) {
|
|
1528
|
+
const normalizedPage = await this.normalizeToV3Page(resolvedOptions.page);
|
|
1529
|
+
this.ctx.setActivePage(normalizedPage);
|
|
1530
|
+
}
|
|
1531
|
+
const instruction = resolvedOptions.instruction.trim();
|
|
1532
|
+
const sanitizedOptions = this.agentCache.sanitizeExecuteOptions(resolvedOptions);
|
|
1533
|
+
const cacheVariables = (0, variables_js_1.flattenVariables)(resolvedOptions.variables);
|
|
1534
|
+
let cacheContext = null;
|
|
1535
|
+
if (this.agentCache.shouldAttemptCache(instruction)) {
|
|
1536
|
+
const startPage = await this.ctx.awaitActivePage();
|
|
1537
|
+
cacheContext = await this.agentCache.prepareContext({
|
|
1538
|
+
instruction,
|
|
1539
|
+
options: sanitizedOptions,
|
|
1540
|
+
configSignature: agentConfigSignature,
|
|
1541
|
+
page: startPage,
|
|
1542
|
+
variables: cacheVariables,
|
|
1543
|
+
});
|
|
1541
1544
|
if (cacheContext) {
|
|
1542
|
-
const replayed = await this.agentCache.
|
|
1545
|
+
const replayed = await this.agentCache.tryReplay(cacheContext);
|
|
1543
1546
|
if (replayed) {
|
|
1544
|
-
flowLogger_js_1.SessionFileLogger.logAgentTaskCompleted({ cacheHit: true });
|
|
1545
1547
|
return replayed;
|
|
1546
1548
|
}
|
|
1547
1549
|
}
|
|
1548
|
-
const streamResult = await handler.stream(resolvedOptions);
|
|
1549
|
-
if (cacheContext) {
|
|
1550
|
-
const wrappedStream = this.agentCache.wrapStreamForCaching(cacheContext, streamResult, () => this.beginAgentReplayRecording(), () => this.endAgentReplayRecording(), () => this.discardAgentReplayRecording());
|
|
1551
|
-
// Log completion when stream is returned (stream completes asynchronously)
|
|
1552
|
-
flowLogger_js_1.SessionFileLogger.logAgentTaskCompleted();
|
|
1553
|
-
return wrappedStream;
|
|
1554
|
-
}
|
|
1555
|
-
// Log completion when stream is returned (stream completes asynchronously)
|
|
1556
|
-
flowLogger_js_1.SessionFileLogger.logAgentTaskCompleted();
|
|
1557
|
-
return streamResult;
|
|
1558
|
-
}
|
|
1559
|
-
// Non-streaming mode (default)
|
|
1560
|
-
const { handler, resolvedOptions, cacheContext, llmClient } = await this.prepareAgentExecution(options, instructionOrOptions, agentConfigSignature);
|
|
1561
|
-
if (cacheContext) {
|
|
1562
|
-
const replayed = await this.agentCache.tryReplay(cacheContext, llmClient);
|
|
1563
|
-
if (replayed) {
|
|
1564
|
-
flowLogger_js_1.SessionFileLogger.logAgentTaskCompleted({ cacheHit: true });
|
|
1565
|
-
return replayed;
|
|
1566
|
-
}
|
|
1567
1550
|
}
|
|
1568
1551
|
let agentSteps = [];
|
|
1569
1552
|
const shouldRecordLocally = !!cacheContext && (!this.apiClient || this.experimental);
|
|
@@ -1574,14 +1557,14 @@ let V3 = (() => {
|
|
|
1574
1557
|
try {
|
|
1575
1558
|
if (this.apiClient && !this.experimental) {
|
|
1576
1559
|
const page = await this.ctx.awaitActivePage();
|
|
1577
|
-
result = await this.apiClient.agentExecute(options
|
|
1560
|
+
result = await this.apiClient.agentExecute(options, resolvedOptions, page.mainFrameId(), !!cacheContext);
|
|
1578
1561
|
if (cacheContext) {
|
|
1579
1562
|
const transferredEntry = this.apiClient.consumeLatestAgentCacheEntry();
|
|
1580
1563
|
await this.agentCache.storeTransferredEntry(transferredEntry);
|
|
1581
1564
|
}
|
|
1582
1565
|
}
|
|
1583
1566
|
else {
|
|
1584
|
-
result = await handler.execute(
|
|
1567
|
+
result = await handler.execute(instructionOrOptions);
|
|
1585
1568
|
}
|
|
1586
1569
|
if (shouldRecordLocally) {
|
|
1587
1570
|
agentSteps = this.endAgentReplayRecording();
|
|
@@ -1603,9 +1586,96 @@ let V3 = (() => {
|
|
|
1603
1586
|
if (shouldRecordLocally) {
|
|
1604
1587
|
this.discardAgentReplayRecording();
|
|
1605
1588
|
}
|
|
1606
|
-
flowLogger_js_1.SessionFileLogger.logAgentTaskCompleted();
|
|
1607
1589
|
}
|
|
1608
|
-
})
|
|
1590
|
+
});
|
|
1591
|
+
return {
|
|
1592
|
+
execute: FlowLogger_js_1.FlowLogger.wrapWithLogging({
|
|
1593
|
+
eventType: "AgentExecute",
|
|
1594
|
+
context: this.flowLoggerContext,
|
|
1595
|
+
})(execute),
|
|
1596
|
+
};
|
|
1597
|
+
}
|
|
1598
|
+
// Default: AISDK tools-based agent
|
|
1599
|
+
const agentConfigSignature = this.agentCache.buildConfigSignature(options);
|
|
1600
|
+
const isStreaming = options?.stream ?? false;
|
|
1601
|
+
const execute = async (instructionOrOptions) => (0, logger_js_2.withInstanceLogContext)(this.instanceId, async () => {
|
|
1602
|
+
(0, validateExperimentalFeatures_js_1.validateExperimentalFeatures)({
|
|
1603
|
+
isExperimental: this.experimental,
|
|
1604
|
+
agentConfig: options,
|
|
1605
|
+
executeOptions: typeof instructionOrOptions === "object"
|
|
1606
|
+
? instructionOrOptions
|
|
1607
|
+
: null,
|
|
1608
|
+
isStreaming,
|
|
1609
|
+
});
|
|
1610
|
+
// Streaming mode
|
|
1611
|
+
if (isStreaming) {
|
|
1612
|
+
const { handler, resolvedOptions, cacheContext, llmClient } = await this.prepareAgentExecution(options, instructionOrOptions, agentConfigSignature);
|
|
1613
|
+
if (cacheContext) {
|
|
1614
|
+
const replayed = await this.agentCache.tryReplayAsStream(cacheContext, llmClient);
|
|
1615
|
+
if (replayed) {
|
|
1616
|
+
return replayed;
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
const streamResult = await handler.stream(resolvedOptions);
|
|
1620
|
+
if (cacheContext) {
|
|
1621
|
+
const wrappedStream = this.agentCache.wrapStreamForCaching(cacheContext, streamResult, () => this.beginAgentReplayRecording(), () => this.endAgentReplayRecording(), () => this.discardAgentReplayRecording());
|
|
1622
|
+
return wrappedStream;
|
|
1623
|
+
}
|
|
1624
|
+
return streamResult;
|
|
1625
|
+
}
|
|
1626
|
+
// Non-streaming mode (default)
|
|
1627
|
+
const { handler, resolvedOptions, cacheContext, llmClient } = await this.prepareAgentExecution(options, instructionOrOptions, agentConfigSignature);
|
|
1628
|
+
if (cacheContext) {
|
|
1629
|
+
const replayed = await this.agentCache.tryReplay(cacheContext, llmClient);
|
|
1630
|
+
if (replayed) {
|
|
1631
|
+
return replayed;
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
let agentSteps = [];
|
|
1635
|
+
const shouldRecordLocally = !!cacheContext && (!this.apiClient || this.experimental);
|
|
1636
|
+
if (shouldRecordLocally) {
|
|
1637
|
+
this.beginAgentReplayRecording();
|
|
1638
|
+
}
|
|
1639
|
+
let result;
|
|
1640
|
+
try {
|
|
1641
|
+
if (this.apiClient && !this.experimental) {
|
|
1642
|
+
const page = await this.ctx.awaitActivePage();
|
|
1643
|
+
result = await this.apiClient.agentExecute(options ?? {}, resolvedOptions, page.mainFrameId(), !!cacheContext);
|
|
1644
|
+
if (cacheContext) {
|
|
1645
|
+
const transferredEntry = this.apiClient.consumeLatestAgentCacheEntry();
|
|
1646
|
+
await this.agentCache.storeTransferredEntry(transferredEntry);
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
else {
|
|
1650
|
+
result = await handler.execute(resolvedOptions);
|
|
1651
|
+
}
|
|
1652
|
+
if (shouldRecordLocally) {
|
|
1653
|
+
agentSteps = this.endAgentReplayRecording();
|
|
1654
|
+
}
|
|
1655
|
+
if (shouldRecordLocally &&
|
|
1656
|
+
cacheContext &&
|
|
1657
|
+
result.success &&
|
|
1658
|
+
agentSteps.length > 0) {
|
|
1659
|
+
await this.agentCache.store(cacheContext, agentSteps, result);
|
|
1660
|
+
}
|
|
1661
|
+
return result;
|
|
1662
|
+
}
|
|
1663
|
+
catch (err) {
|
|
1664
|
+
if (shouldRecordLocally)
|
|
1665
|
+
this.discardAgentReplayRecording();
|
|
1666
|
+
throw err;
|
|
1667
|
+
}
|
|
1668
|
+
finally {
|
|
1669
|
+
if (shouldRecordLocally) {
|
|
1670
|
+
this.discardAgentReplayRecording();
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
});
|
|
1674
|
+
return {
|
|
1675
|
+
execute: FlowLogger_js_1.FlowLogger.wrapWithLogging({
|
|
1676
|
+
eventType: "AgentExecute",
|
|
1677
|
+
context: this.flowLoggerContext,
|
|
1678
|
+
})(execute),
|
|
1609
1679
|
};
|
|
1610
1680
|
}
|
|
1611
1681
|
};
|