@browserbasehq/orca 3.2.0-preview.3 → 3.2.0-preview.5
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 +2 -2
- package/dist/cjs/lib/inference.js.map +1 -1
- package/dist/cjs/lib/prompt.d.ts +1 -1
- package/dist/cjs/lib/prompt.js +11 -2
- 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/AnthropicCUAClient.js +6 -7
- package/dist/cjs/lib/v3/agent/AnthropicCUAClient.js.map +1 -1
- package/dist/cjs/lib/v3/agent/GoogleCUAClient.js +6 -7
- package/dist/cjs/lib/v3/agent/GoogleCUAClient.js.map +1 -1
- package/dist/cjs/lib/v3/agent/MicrosoftCUAClient.js +1 -0
- package/dist/cjs/lib/v3/agent/MicrosoftCUAClient.js.map +1 -1
- package/dist/cjs/lib/v3/agent/OpenAICUAClient.d.ts +4 -4
- package/dist/cjs/lib/v3/agent/OpenAICUAClient.js +67 -8
- package/dist/cjs/lib/v3/agent/OpenAICUAClient.js.map +1 -1
- package/dist/cjs/lib/v3/agent/prompts/agentSystemPrompt.d.ts +2 -2
- package/dist/cjs/lib/v3/agent/prompts/agentSystemPrompt.js +10 -11
- package/dist/cjs/lib/v3/agent/prompts/agentSystemPrompt.js.map +1 -1
- package/dist/cjs/lib/v3/agent/tools/act.js +1 -10
- package/dist/cjs/lib/v3/agent/tools/act.js.map +1 -1
- package/dist/cjs/lib/v3/agent/tools/ariaTree.js +1 -12
- package/dist/cjs/lib/v3/agent/tools/ariaTree.js.map +1 -1
- package/dist/cjs/lib/v3/agent/tools/braveSearch.js.map +1 -1
- package/dist/cjs/lib/v3/agent/tools/browserbaseSearch.js.map +1 -1
- 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.map +1 -1
- package/dist/cjs/lib/v3/agent/tools/extract.js +1 -10
- package/dist/cjs/lib/v3/agent/tools/extract.js.map +1 -1
- package/dist/cjs/lib/v3/agent/tools/fillFormVision.js.map +1 -1
- package/dist/cjs/lib/v3/agent/tools/fillform.d.ts +0 -1
- package/dist/cjs/lib/v3/agent/tools/fillform.js +8 -20
- package/dist/cjs/lib/v3/agent/tools/fillform.js.map +1 -1
- package/dist/cjs/lib/v3/agent/tools/index.d.ts +2 -2
- package/dist/cjs/lib/v3/agent/tools/index.js +53 -5
- 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/type.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/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/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/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 +2 -1
- 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 +112 -78
- 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/llm/aisdk.js +11 -17
- package/dist/cjs/lib/v3/llm/aisdk.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/public/api.d.ts +24 -7
- package/dist/cjs/lib/v3/types/public/api.js +41 -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/options.d.ts +7 -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 +3 -12
- package/dist/cjs/lib/v3/understudy/cdp.js +134 -21
- package/dist/cjs/lib/v3/understudy/cdp.js.map +1 -1
- package/dist/cjs/lib/v3/understudy/page.js +28 -18
- package/dist/cjs/lib/v3/understudy/page.js.map +1 -1
- package/dist/cjs/lib/v3/v3.d.ts +12 -2
- package/dist/cjs/lib/v3/v3.js +194 -160
- package/dist/cjs/lib/v3/v3.js.map +1 -1
- package/dist/cjs/lib/version.d.ts +1 -1
- package/dist/cjs/lib/version.js +1 -1
- package/dist/cjs/lib/version.js.map +1 -1
- package/dist/cjs/tests/integration/agent-captcha-autosolve.spec.d.ts +1 -0
- 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/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/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 +113 -3
- 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/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/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/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/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 +2 -2
- package/dist/esm/lib/inference.js.map +1 -1
- package/dist/esm/lib/prompt.d.ts +1 -1
- package/dist/esm/lib/prompt.js +11 -2
- 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/AnthropicCUAClient.js +6 -7
- package/dist/esm/lib/v3/agent/AnthropicCUAClient.js.map +1 -1
- package/dist/esm/lib/v3/agent/GoogleCUAClient.js +6 -7
- package/dist/esm/lib/v3/agent/GoogleCUAClient.js.map +1 -1
- package/dist/esm/lib/v3/agent/MicrosoftCUAClient.js +1 -0
- package/dist/esm/lib/v3/agent/MicrosoftCUAClient.js.map +1 -1
- package/dist/esm/lib/v3/agent/OpenAICUAClient.d.ts +4 -4
- package/dist/esm/lib/v3/agent/OpenAICUAClient.js +67 -8
- package/dist/esm/lib/v3/agent/OpenAICUAClient.js.map +1 -1
- package/dist/esm/lib/v3/agent/prompts/agentSystemPrompt.d.ts +2 -2
- package/dist/esm/lib/v3/agent/prompts/agentSystemPrompt.js +10 -11
- package/dist/esm/lib/v3/agent/prompts/agentSystemPrompt.js.map +1 -1
- package/dist/esm/lib/v3/agent/tools/act.js +1 -10
- package/dist/esm/lib/v3/agent/tools/act.js.map +1 -1
- package/dist/esm/lib/v3/agent/tools/ariaTree.js +1 -12
- package/dist/esm/lib/v3/agent/tools/ariaTree.js.map +1 -1
- package/dist/esm/lib/v3/agent/tools/braveSearch.js.map +1 -1
- package/dist/esm/lib/v3/agent/tools/browserbaseSearch.js.map +1 -1
- 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.map +1 -1
- package/dist/esm/lib/v3/agent/tools/extract.js +1 -10
- package/dist/esm/lib/v3/agent/tools/extract.js.map +1 -1
- package/dist/esm/lib/v3/agent/tools/fillFormVision.js.map +1 -1
- package/dist/esm/lib/v3/agent/tools/fillform.d.ts +0 -1
- package/dist/esm/lib/v3/agent/tools/fillform.js +8 -20
- package/dist/esm/lib/v3/agent/tools/fillform.js.map +1 -1
- package/dist/esm/lib/v3/agent/tools/index.d.ts +2 -2
- package/dist/esm/lib/v3/agent/tools/index.js +53 -5
- 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/type.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/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/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/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 +2 -1
- 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 +112 -78
- 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/llm/aisdk.js +11 -17
- package/dist/esm/lib/v3/llm/aisdk.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/public/api.d.ts +24 -7
- package/dist/esm/lib/v3/types/public/api.js +36 -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/options.d.ts +7 -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 +3 -12
- package/dist/esm/lib/v3/understudy/cdp.js +134 -21
- package/dist/esm/lib/v3/understudy/cdp.js.map +1 -1
- package/dist/esm/lib/v3/understudy/page.js +28 -18
- package/dist/esm/lib/v3/understudy/page.js.map +1 -1
- package/dist/esm/lib/v3/v3.d.ts +12 -2
- package/dist/esm/lib/v3/v3.js +194 -160
- package/dist/esm/lib/v3/v3.js.map +1 -1
- package/dist/esm/lib/version.d.ts +1 -1
- package/dist/esm/lib/version.js +1 -1
- package/dist/esm/lib/version.js.map +1 -1
- package/dist/esm/tests/integration/agent-captcha-autosolve.spec.d.ts +1 -0
- package/dist/esm/tests/integration/agent-captcha-autosolve.spec.js +54 -0
- package/dist/esm/tests/integration/agent-captcha-autosolve.spec.js.map +1 -0
- package/dist/esm/tests/integration/agent-hybrid-mode.spec.js +6 -6
- package/dist/esm/tests/integration/agent-hybrid-mode.spec.js.map +1 -1
- package/dist/esm/tests/integration/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/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 +113 -3
- 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/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/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/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/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 +4 -2
- 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/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/lib/v3/v3.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { EventEmitter } from "events";
|
|
2
1
|
import { z } from "zod";
|
|
3
2
|
import { InferStagehandSchema, StagehandZodSchema } from "./zodCompat.js";
|
|
4
3
|
import { LLMClient } from "./llm/LLMClient.js";
|
|
5
4
|
import { AgentReplayStep } from "./types/private/index.js";
|
|
6
5
|
import { AgentConfig, AgentExecuteOptions, AgentStreamExecuteOptions, AgentResult, LogLine, StagehandMetrics, Action, ActOptions, ActResult, defaultExtractSchema, ExtractOptions, HistoryEntry, ObserveOptions, pageTextSchema, V3FunctionName, V3Options, AgentStreamResult } from "./types/public/index.js";
|
|
7
6
|
import { V3Context } from "./understudy/context.js";
|
|
7
|
+
import { type FlowLoggerContext } from "./flowlogger/FlowLogger.js";
|
|
8
|
+
import { EventEmitterWithWildcardSupport } from "./flowlogger/EventEmitter.js";
|
|
9
|
+
import { EventStore } from "./flowlogger/EventStore.js";
|
|
8
10
|
/**
|
|
9
11
|
* V3
|
|
10
12
|
*
|
|
@@ -32,7 +34,7 @@ export declare class V3 {
|
|
|
32
34
|
* Event bus for internal communication.
|
|
33
35
|
* Emits events like 'screenshot' when screenshots are captured during agent execution.
|
|
34
36
|
*/
|
|
35
|
-
readonly bus:
|
|
37
|
+
readonly bus: EventEmitterWithWildcardSupport;
|
|
36
38
|
private modelName;
|
|
37
39
|
private modelClientOptions;
|
|
38
40
|
private llmProvider;
|
|
@@ -49,6 +51,11 @@ export declare class V3 {
|
|
|
49
51
|
* Returns true if the browser is running on Browserbase.
|
|
50
52
|
*/
|
|
51
53
|
get isBrowserbase(): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Returns true if captcha auto-solving is enabled on Browserbase.
|
|
56
|
+
* Defaults to true when not explicitly set to false.
|
|
57
|
+
*/
|
|
58
|
+
get isCaptchaAutoSolveEnabled(): boolean;
|
|
52
59
|
/**
|
|
53
60
|
* Returns true if advancedStealth is enabled in Browserbase settings.
|
|
54
61
|
*/
|
|
@@ -70,6 +77,9 @@ export declare class V3 {
|
|
|
70
77
|
private stagehandLogger;
|
|
71
78
|
private _history;
|
|
72
79
|
private readonly instanceId;
|
|
80
|
+
private readonly sessionId;
|
|
81
|
+
readonly eventStore: EventStore;
|
|
82
|
+
readonly flowLoggerContext: FlowLoggerContext;
|
|
73
83
|
private static _processGuardsInstalled;
|
|
74
84
|
private static _instances;
|
|
75
85
|
private cacheStorage;
|
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,7 +63,9 @@ 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";
|
|
@@ -111,9 +113,15 @@ let V3 = (() => {
|
|
|
111
113
|
return class V3 {
|
|
112
114
|
static {
|
|
113
115
|
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
114
|
-
_act_decorators = [
|
|
115
|
-
|
|
116
|
-
|
|
116
|
+
_act_decorators = [FlowLogger.wrapWithLogging({
|
|
117
|
+
eventType: "StagehandAct",
|
|
118
|
+
})];
|
|
119
|
+
_extract_decorators = [FlowLogger.wrapWithLogging({
|
|
120
|
+
eventType: "StagehandExtract",
|
|
121
|
+
})];
|
|
122
|
+
_observe_decorators = [FlowLogger.wrapWithLogging({
|
|
123
|
+
eventType: "StagehandObserve",
|
|
124
|
+
})];
|
|
117
125
|
__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);
|
|
118
126
|
__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);
|
|
119
127
|
__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);
|
|
@@ -130,7 +138,7 @@ let V3 = (() => {
|
|
|
130
138
|
* Event bus for internal communication.
|
|
131
139
|
* Emits events like 'screenshot' when screenshots are captured during agent execution.
|
|
132
140
|
*/
|
|
133
|
-
bus = new
|
|
141
|
+
bus = new EventEmitterWithWildcardSupport();
|
|
134
142
|
modelName;
|
|
135
143
|
modelClientOptions;
|
|
136
144
|
llmProvider;
|
|
@@ -155,6 +163,15 @@ let V3 = (() => {
|
|
|
155
163
|
get isBrowserbase() {
|
|
156
164
|
return this.state.kind === "BROWSERBASE";
|
|
157
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Returns true if captcha auto-solving is enabled on Browserbase.
|
|
168
|
+
* Defaults to true when not explicitly set to false.
|
|
169
|
+
*/
|
|
170
|
+
get isCaptchaAutoSolveEnabled() {
|
|
171
|
+
return (this.isBrowserbase &&
|
|
172
|
+
this.opts.browserbaseSessionCreateParams?.browserSettings
|
|
173
|
+
?.solveCaptchas !== false);
|
|
174
|
+
}
|
|
158
175
|
/**
|
|
159
176
|
* Returns true if advancedStealth is enabled in Browserbase settings.
|
|
160
177
|
*/
|
|
@@ -198,6 +215,9 @@ let V3 = (() => {
|
|
|
198
215
|
stagehandLogger;
|
|
199
216
|
_history = [];
|
|
200
217
|
instanceId;
|
|
218
|
+
sessionId;
|
|
219
|
+
eventStore;
|
|
220
|
+
flowLoggerContext;
|
|
201
221
|
static _processGuardsInstalled = false;
|
|
202
222
|
static _instances = new Set();
|
|
203
223
|
cacheStorage;
|
|
@@ -237,6 +257,7 @@ let V3 = (() => {
|
|
|
237
257
|
this.externalLogger = opts.logger;
|
|
238
258
|
this.verbose = opts.verbose ?? 1;
|
|
239
259
|
this.instanceId = uuidv7();
|
|
260
|
+
this.sessionId = opts.sessionId ?? this.instanceId;
|
|
240
261
|
this.keepAlive =
|
|
241
262
|
opts.keepAlive ?? opts.browserbaseSessionCreateParams?.keepAlive;
|
|
242
263
|
// Create per-instance StagehandLogger (handles usePino, verbose, externalLogger)
|
|
@@ -329,8 +350,21 @@ let V3 = (() => {
|
|
|
329
350
|
act: this.act.bind(this),
|
|
330
351
|
});
|
|
331
352
|
this.opts = opts;
|
|
332
|
-
//
|
|
333
|
-
|
|
353
|
+
// FlowLogger always gets a per-instance session context and shared event
|
|
354
|
+
// bus. The attached EventStore decides which sinks are active:
|
|
355
|
+
// `BROWSERBASE_FLOW_LOGS=1` enables pretty stderr output,
|
|
356
|
+
// and `BROWSERBASE_CONFIG_DIR` enables the pretty/jsonl file sinks for this session.
|
|
357
|
+
this.eventStore = new EventStore(this.sessionId, opts);
|
|
358
|
+
this.flowLoggerContext = FlowLogger.init(this.sessionId, this.bus);
|
|
359
|
+
// Flow event pipeline:
|
|
360
|
+
// FlowLogger -> this.bus -> this.eventStore -> configured sinks/query history.
|
|
361
|
+
// V3 owns the bus for this session. EventStore is not another bus; it just
|
|
362
|
+
// receives already-emitted FlowEvents here, then fans them out to sinks and
|
|
363
|
+
// keeps the queryable per-session history used by /v4/log, parent/ancestor lookups, and tests.
|
|
364
|
+
// `on()` stores a strong reference to the handler, so the EventStore
|
|
365
|
+
// stays alive until this bus is garbage-collected with the rest of the V3
|
|
366
|
+
// object graph.
|
|
367
|
+
this.bus.on("*", this.eventStore.emit);
|
|
334
368
|
// Track instance for global process guard handling
|
|
335
369
|
V3._instances.add(this);
|
|
336
370
|
}
|
|
@@ -571,9 +605,7 @@ let V3 = (() => {
|
|
|
571
605
|
env: "LOCAL",
|
|
572
606
|
cdpHeaders: lbo.cdpHeaders,
|
|
573
607
|
});
|
|
574
|
-
|
|
575
|
-
this.ctx.conn.cdpLogger = (info) => SessionFileLogger.logCdpCallEvent(info, logCtx);
|
|
576
|
-
this.ctx.conn.cdpEventLogger = (info) => SessionFileLogger.logCdpMessageEvent(info, logCtx);
|
|
608
|
+
this.ctx.conn.flowLoggerContext = this.flowLoggerContext;
|
|
577
609
|
this.ctx.conn.onTransportClosed(this._onCdpClosed);
|
|
578
610
|
this.state = {
|
|
579
611
|
kind: "LOCAL",
|
|
@@ -669,9 +701,7 @@ let V3 = (() => {
|
|
|
669
701
|
env: "LOCAL",
|
|
670
702
|
localBrowserLaunchOptions: lbo,
|
|
671
703
|
});
|
|
672
|
-
|
|
673
|
-
this.ctx.conn.cdpLogger = (info) => SessionFileLogger.logCdpCallEvent(info, logCtx);
|
|
674
|
-
this.ctx.conn.cdpEventLogger = (info) => SessionFileLogger.logCdpMessageEvent(info, logCtx);
|
|
704
|
+
this.ctx.conn.flowLoggerContext = this.flowLoggerContext;
|
|
675
705
|
this.ctx.conn.onTransportClosed(this._onCdpClosed);
|
|
676
706
|
this.state = {
|
|
677
707
|
kind: "LOCAL",
|
|
@@ -706,9 +736,13 @@ let V3 = (() => {
|
|
|
706
736
|
const baseSessionParams = this.opts.browserbaseSessionCreateParams ?? {};
|
|
707
737
|
const resolvedKeepAlive = this.keepAlive;
|
|
708
738
|
const keepAlive = this.keepAlive === true;
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
739
|
+
let effectiveSessionParams = baseSessionParams;
|
|
740
|
+
if (resolvedKeepAlive !== undefined) {
|
|
741
|
+
effectiveSessionParams = {
|
|
742
|
+
...baseSessionParams,
|
|
743
|
+
keepAlive: resolvedKeepAlive,
|
|
744
|
+
};
|
|
745
|
+
}
|
|
712
746
|
if (!this.disableAPI && !this.experimental) {
|
|
713
747
|
this.apiClient = new StagehandAPIClient({
|
|
714
748
|
apiKey,
|
|
@@ -753,9 +787,7 @@ let V3 = (() => {
|
|
|
753
787
|
env: "BROWSERBASE",
|
|
754
788
|
apiClient: this.apiClient,
|
|
755
789
|
});
|
|
756
|
-
|
|
757
|
-
this.ctx.conn.cdpLogger = (info) => SessionFileLogger.logCdpCallEvent(info, logCtx);
|
|
758
|
-
this.ctx.conn.cdpEventLogger = (info) => SessionFileLogger.logCdpMessageEvent(info, logCtx);
|
|
790
|
+
this.ctx.conn.flowLoggerContext = this.flowLoggerContext;
|
|
759
791
|
this.ctx.conn.onTransportClosed(this._onCdpClosed);
|
|
760
792
|
this.state = { kind: "BROWSERBASE", sessionId, ws, bb };
|
|
761
793
|
this.browserbaseSessionId = sessionId;
|
|
@@ -1031,6 +1063,7 @@ let V3 = (() => {
|
|
|
1031
1063
|
const handlerParams = {
|
|
1032
1064
|
instruction,
|
|
1033
1065
|
model: options?.model,
|
|
1066
|
+
variables: options?.variables,
|
|
1034
1067
|
timeout: options?.timeout,
|
|
1035
1068
|
selector: options?.selector,
|
|
1036
1069
|
page: page,
|
|
@@ -1050,6 +1083,7 @@ let V3 = (() => {
|
|
|
1050
1083
|
// history: record observe call (omit page object)
|
|
1051
1084
|
this.addToHistory("observe", {
|
|
1052
1085
|
instruction,
|
|
1086
|
+
variables: options?.variables,
|
|
1053
1087
|
timeout: options?.timeout,
|
|
1054
1088
|
}, results);
|
|
1055
1089
|
return results;
|
|
@@ -1098,7 +1132,7 @@ let V3 = (() => {
|
|
|
1098
1132
|
try {
|
|
1099
1133
|
// Close session file logger
|
|
1100
1134
|
try {
|
|
1101
|
-
await
|
|
1135
|
+
await FlowLogger.close(this.flowLoggerContext);
|
|
1102
1136
|
}
|
|
1103
1137
|
catch {
|
|
1104
1138
|
// ignore
|
|
@@ -1134,6 +1168,12 @@ let V3 = (() => {
|
|
|
1134
1168
|
catch {
|
|
1135
1169
|
// ignore
|
|
1136
1170
|
}
|
|
1171
|
+
try {
|
|
1172
|
+
await this.eventStore.destroy();
|
|
1173
|
+
}
|
|
1174
|
+
catch {
|
|
1175
|
+
// ignore
|
|
1176
|
+
}
|
|
1137
1177
|
try {
|
|
1138
1178
|
this.bus.removeAllListeners();
|
|
1139
1179
|
}
|
|
@@ -1311,7 +1351,7 @@ let V3 = (() => {
|
|
|
1311
1351
|
? this.resolveLlmClient(options.model)
|
|
1312
1352
|
: this.llmClient;
|
|
1313
1353
|
const resolvedExecutionModel = options?.executionModel ?? options?.model;
|
|
1314
|
-
const handler = new V3AgentHandler(this, this.logger, agentLlmClient, resolvedExecutionModel, options?.systemPrompt, tools, options?.mode);
|
|
1354
|
+
const handler = new V3AgentHandler(this, this.logger, agentLlmClient, resolvedExecutionModel, options?.systemPrompt, tools, options?.mode, this.isCaptchaAutoSolveEnabled);
|
|
1315
1355
|
const resolvedOptions = typeof instructionOrOptions === "string"
|
|
1316
1356
|
? {
|
|
1317
1357
|
instruction: instructionOrOptions,
|
|
@@ -1400,152 +1440,59 @@ let V3 = (() => {
|
|
|
1400
1440
|
throw new CuaModelRequiredError(AVAILABLE_CUA_MODELS);
|
|
1401
1441
|
}
|
|
1402
1442
|
const agentConfigSignature = this.agentCache.buildConfigSignature(options);
|
|
1403
|
-
|
|
1404
|
-
execute: async (instructionOrOptions) => withInstanceLogContext(this.instanceId, async () => {
|
|
1405
|
-
validateExperimentalFeatures({
|
|
1406
|
-
isExperimental: this.experimental,
|
|
1407
|
-
agentConfig: options,
|
|
1408
|
-
executeOptions: typeof instructionOrOptions === "object"
|
|
1409
|
-
? instructionOrOptions
|
|
1410
|
-
: null,
|
|
1411
|
-
});
|
|
1412
|
-
SessionFileLogger.logAgentTaskStarted({
|
|
1413
|
-
invocation: "Agent.execute",
|
|
1414
|
-
args: [instructionOrOptions],
|
|
1415
|
-
});
|
|
1416
|
-
const tools = options?.integrations
|
|
1417
|
-
? await resolveTools(options.integrations, options.tools)
|
|
1418
|
-
: (options?.tools ?? {});
|
|
1419
|
-
const handler = new V3CuaAgentHandler(this, this.logger, {
|
|
1420
|
-
modelName,
|
|
1421
|
-
clientOptions,
|
|
1422
|
-
userProvidedInstructions: options.systemPrompt ??
|
|
1423
|
-
`You are a helpful assistant that can use a web browser.\nDo not ask follow up questions, the user will trust your judgement.`,
|
|
1424
|
-
}, tools);
|
|
1425
|
-
const resolvedOptions = typeof instructionOrOptions === "string"
|
|
1426
|
-
? {
|
|
1427
|
-
instruction: instructionOrOptions,
|
|
1428
|
-
toolTimeout: DEFAULT_AGENT_TOOL_TIMEOUT_MS,
|
|
1429
|
-
}
|
|
1430
|
-
: {
|
|
1431
|
-
...instructionOrOptions,
|
|
1432
|
-
toolTimeout: instructionOrOptions.toolTimeout ??
|
|
1433
|
-
DEFAULT_AGENT_TOOL_TIMEOUT_MS,
|
|
1434
|
-
};
|
|
1435
|
-
if (resolvedOptions.page) {
|
|
1436
|
-
const normalizedPage = await this.normalizeToV3Page(resolvedOptions.page);
|
|
1437
|
-
this.ctx.setActivePage(normalizedPage);
|
|
1438
|
-
}
|
|
1439
|
-
const instruction = resolvedOptions.instruction.trim();
|
|
1440
|
-
const sanitizedOptions = this.agentCache.sanitizeExecuteOptions(resolvedOptions);
|
|
1441
|
-
const cacheVariables = flattenVariables(resolvedOptions.variables);
|
|
1442
|
-
let cacheContext = null;
|
|
1443
|
-
if (this.agentCache.shouldAttemptCache(instruction)) {
|
|
1444
|
-
const startPage = await this.ctx.awaitActivePage();
|
|
1445
|
-
cacheContext = await this.agentCache.prepareContext({
|
|
1446
|
-
instruction,
|
|
1447
|
-
options: sanitizedOptions,
|
|
1448
|
-
configSignature: agentConfigSignature,
|
|
1449
|
-
page: startPage,
|
|
1450
|
-
variables: cacheVariables,
|
|
1451
|
-
});
|
|
1452
|
-
if (cacheContext) {
|
|
1453
|
-
const replayed = await this.agentCache.tryReplay(cacheContext);
|
|
1454
|
-
if (replayed) {
|
|
1455
|
-
SessionFileLogger.logAgentTaskCompleted({ cacheHit: true });
|
|
1456
|
-
return replayed;
|
|
1457
|
-
}
|
|
1458
|
-
}
|
|
1459
|
-
}
|
|
1460
|
-
let agentSteps = [];
|
|
1461
|
-
const shouldRecordLocally = !!cacheContext && (!this.apiClient || this.experimental);
|
|
1462
|
-
if (shouldRecordLocally) {
|
|
1463
|
-
this.beginAgentReplayRecording();
|
|
1464
|
-
}
|
|
1465
|
-
let result;
|
|
1466
|
-
try {
|
|
1467
|
-
if (this.apiClient && !this.experimental) {
|
|
1468
|
-
const page = await this.ctx.awaitActivePage();
|
|
1469
|
-
result = await this.apiClient.agentExecute(options, resolvedOptions, page.mainFrameId(), !!cacheContext);
|
|
1470
|
-
if (cacheContext) {
|
|
1471
|
-
const transferredEntry = this.apiClient.consumeLatestAgentCacheEntry();
|
|
1472
|
-
await this.agentCache.storeTransferredEntry(transferredEntry);
|
|
1473
|
-
}
|
|
1474
|
-
}
|
|
1475
|
-
else {
|
|
1476
|
-
result = await handler.execute(instructionOrOptions);
|
|
1477
|
-
}
|
|
1478
|
-
if (shouldRecordLocally) {
|
|
1479
|
-
agentSteps = this.endAgentReplayRecording();
|
|
1480
|
-
}
|
|
1481
|
-
if (shouldRecordLocally &&
|
|
1482
|
-
cacheContext &&
|
|
1483
|
-
result.success &&
|
|
1484
|
-
agentSteps.length > 0) {
|
|
1485
|
-
await this.agentCache.store(cacheContext, agentSteps, result);
|
|
1486
|
-
}
|
|
1487
|
-
return result;
|
|
1488
|
-
}
|
|
1489
|
-
catch (err) {
|
|
1490
|
-
if (shouldRecordLocally)
|
|
1491
|
-
this.discardAgentReplayRecording();
|
|
1492
|
-
throw err;
|
|
1493
|
-
}
|
|
1494
|
-
finally {
|
|
1495
|
-
if (shouldRecordLocally) {
|
|
1496
|
-
this.discardAgentReplayRecording();
|
|
1497
|
-
}
|
|
1498
|
-
SessionFileLogger.logAgentTaskCompleted();
|
|
1499
|
-
}
|
|
1500
|
-
}),
|
|
1501
|
-
};
|
|
1502
|
-
}
|
|
1503
|
-
// Default: AISDK tools-based agent
|
|
1504
|
-
const agentConfigSignature = this.agentCache.buildConfigSignature(options);
|
|
1505
|
-
const isStreaming = options?.stream ?? false;
|
|
1506
|
-
return {
|
|
1507
|
-
execute: async (instructionOrOptions) => withInstanceLogContext(this.instanceId, async () => {
|
|
1443
|
+
const execute = async (instructionOrOptions) => withInstanceLogContext(this.instanceId, async () => {
|
|
1508
1444
|
validateExperimentalFeatures({
|
|
1509
1445
|
isExperimental: this.experimental,
|
|
1510
1446
|
agentConfig: options,
|
|
1511
1447
|
executeOptions: typeof instructionOrOptions === "object"
|
|
1512
1448
|
? instructionOrOptions
|
|
1513
1449
|
: null,
|
|
1514
|
-
isStreaming,
|
|
1515
|
-
});
|
|
1516
|
-
SessionFileLogger.logAgentTaskStarted({
|
|
1517
|
-
invocation: "Agent.execute",
|
|
1518
|
-
args: [instructionOrOptions],
|
|
1519
1450
|
});
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1451
|
+
const tools = options?.integrations
|
|
1452
|
+
? await resolveTools(options.integrations, options.tools)
|
|
1453
|
+
: (options?.tools ?? {});
|
|
1454
|
+
const handler = new V3CuaAgentHandler(this, this.logger, {
|
|
1455
|
+
modelName,
|
|
1456
|
+
clientOptions,
|
|
1457
|
+
userProvidedInstructions: (options.systemPrompt ??
|
|
1458
|
+
`You are a helpful assistant that can use a web browser.\nDo not ask follow up questions, the user will trust your judgement.`) +
|
|
1459
|
+
(this.isCaptchaAutoSolveEnabled
|
|
1460
|
+
? CAPTCHA_CUA_SYSTEM_PROMPT_NOTE
|
|
1461
|
+
: ""),
|
|
1462
|
+
}, tools);
|
|
1463
|
+
const resolvedOptions = typeof instructionOrOptions === "string"
|
|
1464
|
+
? {
|
|
1465
|
+
instruction: instructionOrOptions,
|
|
1466
|
+
toolTimeout: DEFAULT_AGENT_TOOL_TIMEOUT_MS,
|
|
1467
|
+
}
|
|
1468
|
+
: {
|
|
1469
|
+
...instructionOrOptions,
|
|
1470
|
+
toolTimeout: instructionOrOptions.toolTimeout ??
|
|
1471
|
+
DEFAULT_AGENT_TOOL_TIMEOUT_MS,
|
|
1472
|
+
};
|
|
1473
|
+
if (resolvedOptions.page) {
|
|
1474
|
+
const normalizedPage = await this.normalizeToV3Page(resolvedOptions.page);
|
|
1475
|
+
this.ctx.setActivePage(normalizedPage);
|
|
1476
|
+
}
|
|
1477
|
+
const instruction = resolvedOptions.instruction.trim();
|
|
1478
|
+
const sanitizedOptions = this.agentCache.sanitizeExecuteOptions(resolvedOptions);
|
|
1479
|
+
const cacheVariables = flattenVariables(resolvedOptions.variables);
|
|
1480
|
+
let cacheContext = null;
|
|
1481
|
+
if (this.agentCache.shouldAttemptCache(instruction)) {
|
|
1482
|
+
const startPage = await this.ctx.awaitActivePage();
|
|
1483
|
+
cacheContext = await this.agentCache.prepareContext({
|
|
1484
|
+
instruction,
|
|
1485
|
+
options: sanitizedOptions,
|
|
1486
|
+
configSignature: agentConfigSignature,
|
|
1487
|
+
page: startPage,
|
|
1488
|
+
variables: cacheVariables,
|
|
1489
|
+
});
|
|
1523
1490
|
if (cacheContext) {
|
|
1524
|
-
const replayed = await this.agentCache.
|
|
1491
|
+
const replayed = await this.agentCache.tryReplay(cacheContext);
|
|
1525
1492
|
if (replayed) {
|
|
1526
|
-
SessionFileLogger.logAgentTaskCompleted({ cacheHit: true });
|
|
1527
1493
|
return replayed;
|
|
1528
1494
|
}
|
|
1529
1495
|
}
|
|
1530
|
-
const streamResult = await handler.stream(resolvedOptions);
|
|
1531
|
-
if (cacheContext) {
|
|
1532
|
-
const wrappedStream = this.agentCache.wrapStreamForCaching(cacheContext, streamResult, () => this.beginAgentReplayRecording(), () => this.endAgentReplayRecording(), () => this.discardAgentReplayRecording());
|
|
1533
|
-
// Log completion when stream is returned (stream completes asynchronously)
|
|
1534
|
-
SessionFileLogger.logAgentTaskCompleted();
|
|
1535
|
-
return wrappedStream;
|
|
1536
|
-
}
|
|
1537
|
-
// Log completion when stream is returned (stream completes asynchronously)
|
|
1538
|
-
SessionFileLogger.logAgentTaskCompleted();
|
|
1539
|
-
return streamResult;
|
|
1540
|
-
}
|
|
1541
|
-
// Non-streaming mode (default)
|
|
1542
|
-
const { handler, resolvedOptions, cacheContext, llmClient } = await this.prepareAgentExecution(options, instructionOrOptions, agentConfigSignature);
|
|
1543
|
-
if (cacheContext) {
|
|
1544
|
-
const replayed = await this.agentCache.tryReplay(cacheContext, llmClient);
|
|
1545
|
-
if (replayed) {
|
|
1546
|
-
SessionFileLogger.logAgentTaskCompleted({ cacheHit: true });
|
|
1547
|
-
return replayed;
|
|
1548
|
-
}
|
|
1549
1496
|
}
|
|
1550
1497
|
let agentSteps = [];
|
|
1551
1498
|
const shouldRecordLocally = !!cacheContext && (!this.apiClient || this.experimental);
|
|
@@ -1556,14 +1503,14 @@ let V3 = (() => {
|
|
|
1556
1503
|
try {
|
|
1557
1504
|
if (this.apiClient && !this.experimental) {
|
|
1558
1505
|
const page = await this.ctx.awaitActivePage();
|
|
1559
|
-
result = await this.apiClient.agentExecute(options
|
|
1506
|
+
result = await this.apiClient.agentExecute(options, resolvedOptions, page.mainFrameId(), !!cacheContext);
|
|
1560
1507
|
if (cacheContext) {
|
|
1561
1508
|
const transferredEntry = this.apiClient.consumeLatestAgentCacheEntry();
|
|
1562
1509
|
await this.agentCache.storeTransferredEntry(transferredEntry);
|
|
1563
1510
|
}
|
|
1564
1511
|
}
|
|
1565
1512
|
else {
|
|
1566
|
-
result = await handler.execute(
|
|
1513
|
+
result = await handler.execute(instructionOrOptions);
|
|
1567
1514
|
}
|
|
1568
1515
|
if (shouldRecordLocally) {
|
|
1569
1516
|
agentSteps = this.endAgentReplayRecording();
|
|
@@ -1585,9 +1532,96 @@ let V3 = (() => {
|
|
|
1585
1532
|
if (shouldRecordLocally) {
|
|
1586
1533
|
this.discardAgentReplayRecording();
|
|
1587
1534
|
}
|
|
1588
|
-
SessionFileLogger.logAgentTaskCompleted();
|
|
1589
1535
|
}
|
|
1590
|
-
})
|
|
1536
|
+
});
|
|
1537
|
+
return {
|
|
1538
|
+
execute: FlowLogger.wrapWithLogging({
|
|
1539
|
+
eventType: "AgentExecute",
|
|
1540
|
+
context: this.flowLoggerContext,
|
|
1541
|
+
})(execute),
|
|
1542
|
+
};
|
|
1543
|
+
}
|
|
1544
|
+
// Default: AISDK tools-based agent
|
|
1545
|
+
const agentConfigSignature = this.agentCache.buildConfigSignature(options);
|
|
1546
|
+
const isStreaming = options?.stream ?? false;
|
|
1547
|
+
const execute = async (instructionOrOptions) => withInstanceLogContext(this.instanceId, async () => {
|
|
1548
|
+
validateExperimentalFeatures({
|
|
1549
|
+
isExperimental: this.experimental,
|
|
1550
|
+
agentConfig: options,
|
|
1551
|
+
executeOptions: typeof instructionOrOptions === "object"
|
|
1552
|
+
? instructionOrOptions
|
|
1553
|
+
: null,
|
|
1554
|
+
isStreaming,
|
|
1555
|
+
});
|
|
1556
|
+
// Streaming mode
|
|
1557
|
+
if (isStreaming) {
|
|
1558
|
+
const { handler, resolvedOptions, cacheContext, llmClient } = await this.prepareAgentExecution(options, instructionOrOptions, agentConfigSignature);
|
|
1559
|
+
if (cacheContext) {
|
|
1560
|
+
const replayed = await this.agentCache.tryReplayAsStream(cacheContext, llmClient);
|
|
1561
|
+
if (replayed) {
|
|
1562
|
+
return replayed;
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
const streamResult = await handler.stream(resolvedOptions);
|
|
1566
|
+
if (cacheContext) {
|
|
1567
|
+
const wrappedStream = this.agentCache.wrapStreamForCaching(cacheContext, streamResult, () => this.beginAgentReplayRecording(), () => this.endAgentReplayRecording(), () => this.discardAgentReplayRecording());
|
|
1568
|
+
return wrappedStream;
|
|
1569
|
+
}
|
|
1570
|
+
return streamResult;
|
|
1571
|
+
}
|
|
1572
|
+
// Non-streaming mode (default)
|
|
1573
|
+
const { handler, resolvedOptions, cacheContext, llmClient } = await this.prepareAgentExecution(options, instructionOrOptions, agentConfigSignature);
|
|
1574
|
+
if (cacheContext) {
|
|
1575
|
+
const replayed = await this.agentCache.tryReplay(cacheContext, llmClient);
|
|
1576
|
+
if (replayed) {
|
|
1577
|
+
return replayed;
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
let agentSteps = [];
|
|
1581
|
+
const shouldRecordLocally = !!cacheContext && (!this.apiClient || this.experimental);
|
|
1582
|
+
if (shouldRecordLocally) {
|
|
1583
|
+
this.beginAgentReplayRecording();
|
|
1584
|
+
}
|
|
1585
|
+
let result;
|
|
1586
|
+
try {
|
|
1587
|
+
if (this.apiClient && !this.experimental) {
|
|
1588
|
+
const page = await this.ctx.awaitActivePage();
|
|
1589
|
+
result = await this.apiClient.agentExecute(options ?? {}, resolvedOptions, page.mainFrameId(), !!cacheContext);
|
|
1590
|
+
if (cacheContext) {
|
|
1591
|
+
const transferredEntry = this.apiClient.consumeLatestAgentCacheEntry();
|
|
1592
|
+
await this.agentCache.storeTransferredEntry(transferredEntry);
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
else {
|
|
1596
|
+
result = await handler.execute(resolvedOptions);
|
|
1597
|
+
}
|
|
1598
|
+
if (shouldRecordLocally) {
|
|
1599
|
+
agentSteps = this.endAgentReplayRecording();
|
|
1600
|
+
}
|
|
1601
|
+
if (shouldRecordLocally &&
|
|
1602
|
+
cacheContext &&
|
|
1603
|
+
result.success &&
|
|
1604
|
+
agentSteps.length > 0) {
|
|
1605
|
+
await this.agentCache.store(cacheContext, agentSteps, result);
|
|
1606
|
+
}
|
|
1607
|
+
return result;
|
|
1608
|
+
}
|
|
1609
|
+
catch (err) {
|
|
1610
|
+
if (shouldRecordLocally)
|
|
1611
|
+
this.discardAgentReplayRecording();
|
|
1612
|
+
throw err;
|
|
1613
|
+
}
|
|
1614
|
+
finally {
|
|
1615
|
+
if (shouldRecordLocally) {
|
|
1616
|
+
this.discardAgentReplayRecording();
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
});
|
|
1620
|
+
return {
|
|
1621
|
+
execute: FlowLogger.wrapWithLogging({
|
|
1622
|
+
eventType: "AgentExecute",
|
|
1623
|
+
context: this.flowLoggerContext,
|
|
1624
|
+
})(execute),
|
|
1591
1625
|
};
|
|
1592
1626
|
}
|
|
1593
1627
|
};
|