@browserbasehq/orca 3.2.0-preview.4 → 3.2.1-preview.0
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/README.md +2 -2
- package/dist/cjs/lib/inference.d.ts +3 -1
- package/dist/cjs/lib/inference.js +3 -3
- 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/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 +1 -0
- package/dist/cjs/lib/v3/agent/AgentProvider.js.map +1 -1
- package/dist/cjs/lib/v3/agent/AnthropicCUAClient.d.ts +3 -1
- package/dist/cjs/lib/v3/agent/AnthropicCUAClient.js +61 -9
- package/dist/cjs/lib/v3/agent/AnthropicCUAClient.js.map +1 -1
- package/dist/cjs/lib/v3/agent/GoogleCUAClient.js +1 -0
- package/dist/cjs/lib/v3/agent/GoogleCUAClient.js.map +1 -1
- package/dist/cjs/lib/v3/agent/MicrosoftCUAClient.js +16 -0
- package/dist/cjs/lib/v3/agent/MicrosoftCUAClient.js.map +1 -1
- package/dist/cjs/lib/v3/agent/OpenAICUAClient.d.ts +12 -6
- package/dist/cjs/lib/v3/agent/OpenAICUAClient.js +164 -49
- 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/fillform.d.ts +0 -1
- package/dist/cjs/lib/v3/agent/tools/fillform.js +7 -10
- package/dist/cjs/lib/v3/agent/tools/fillform.js.map +1 -1
- package/dist/cjs/lib/v3/agent/tools/index.js +1 -1
- package/dist/cjs/lib/v3/agent/tools/index.js.map +1 -1
- package/dist/cjs/lib/v3/agent/tools/keys.d.ts +2 -1
- package/dist/cjs/lib/v3/agent/tools/keys.js +57 -49
- package/dist/cjs/lib/v3/agent/tools/keys.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/coordinateNormalization.js +3 -5
- package/dist/cjs/lib/v3/agent/utils/coordinateNormalization.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 +5 -3
- package/dist/cjs/lib/v3/api.js +5 -15
- package/dist/cjs/lib/v3/api.js.map +1 -1
- package/dist/cjs/lib/v3/cache/AgentCache.js +5 -3
- package/dist/cjs/lib/v3/cache/AgentCache.js.map +1 -1
- package/dist/cjs/lib/v3/flowlogger/EventStore.js +1 -1
- package/dist/cjs/lib/v3/flowlogger/EventStore.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 -1
- package/dist/cjs/lib/v3/handlers/v3AgentHandler.js +110 -46
- 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 +131 -16
- package/dist/cjs/lib/v3/handlers/v3CuaAgentHandler.js.map +1 -1
- package/dist/cjs/lib/v3/index.d.ts +1 -1
- package/dist/cjs/lib/v3/llm/LLMProvider.d.ts +5 -2
- package/dist/cjs/lib/v3/llm/LLMProvider.js +14 -6
- package/dist/cjs/lib/v3/llm/LLMProvider.js.map +1 -1
- package/dist/cjs/lib/v3/llm/OpenAIClient.js +1 -0
- package/dist/cjs/lib/v3/llm/OpenAIClient.js.map +1 -1
- package/dist/cjs/lib/v3/llm/aisdk.d.ts +3 -1
- package/dist/cjs/lib/v3/llm/aisdk.js +67 -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/agent.d.ts +8 -3
- package/dist/cjs/lib/v3/types/public/agent.js +1 -0
- package/dist/cjs/lib/v3/types/public/agent.js.map +1 -1
- package/dist/cjs/lib/v3/types/public/api.d.ts +54 -7
- package/dist/cjs/lib/v3/types/public/api.js +47 -16
- 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 +32 -2
- package/dist/cjs/lib/v3/types/public/model.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/context.js +11 -3
- package/dist/cjs/lib/v3/understudy/context.js.map +1 -1
- package/dist/cjs/lib/v3/understudy/page.js +1 -1
- package/dist/cjs/lib/v3/understudy/page.js.map +1 -1
- package/dist/cjs/lib/v3/v3.d.ts +23 -2
- package/dist/cjs/lib/v3/v3.js +111 -13
- 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/chrome-newtab-page-tracking.spec.d.ts +1 -0
- 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/timeouts.spec.js +1 -1
- 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 +341 -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-metrics.test.d.ts +1 -0
- package/dist/cjs/tests/unit/agent-metrics.test.js +112 -0
- package/dist/cjs/tests/unit/agent-metrics.test.js.map +1 -0
- 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-clients.test.d.ts +1 -0
- package/dist/cjs/tests/unit/aisdk-clients.test.js +90 -0
- package/dist/cjs/tests/unit/aisdk-clients.test.js.map +1 -0
- package/dist/cjs/tests/unit/anthropic-cua-adaptive-thinking.test.d.ts +1 -0
- package/dist/cjs/tests/unit/anthropic-cua-adaptive-thinking.test.js +250 -0
- package/dist/cjs/tests/unit/anthropic-cua-adaptive-thinking.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-optional-model-api-key.test.d.ts +1 -0
- package/dist/cjs/tests/unit/api-optional-model-api-key.test.js +95 -0
- package/dist/cjs/tests/unit/api-optional-model-api-key.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 +40 -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-eventstore.test.js +1 -1
- package/dist/cjs/tests/unit/flowlogger-eventstore.test.js.map +1 -1
- 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/microsoft-cua-client.test.d.ts +1 -0
- package/dist/cjs/tests/unit/microsoft-cua-client.test.js +86 -0
- package/dist/cjs/tests/unit/microsoft-cua-client.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/llm-and-agents.test.js +1 -0
- 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 +3 -3
- 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/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 +1 -0
- package/dist/esm/lib/v3/agent/AgentProvider.js.map +1 -1
- package/dist/esm/lib/v3/agent/AnthropicCUAClient.d.ts +3 -1
- package/dist/esm/lib/v3/agent/AnthropicCUAClient.js +61 -9
- package/dist/esm/lib/v3/agent/AnthropicCUAClient.js.map +1 -1
- package/dist/esm/lib/v3/agent/GoogleCUAClient.js +1 -0
- package/dist/esm/lib/v3/agent/GoogleCUAClient.js.map +1 -1
- package/dist/esm/lib/v3/agent/MicrosoftCUAClient.js +16 -0
- package/dist/esm/lib/v3/agent/MicrosoftCUAClient.js.map +1 -1
- package/dist/esm/lib/v3/agent/OpenAICUAClient.d.ts +12 -6
- package/dist/esm/lib/v3/agent/OpenAICUAClient.js +164 -49
- 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/fillform.d.ts +0 -1
- package/dist/esm/lib/v3/agent/tools/fillform.js +7 -10
- package/dist/esm/lib/v3/agent/tools/fillform.js.map +1 -1
- package/dist/esm/lib/v3/agent/tools/index.js +1 -1
- package/dist/esm/lib/v3/agent/tools/index.js.map +1 -1
- package/dist/esm/lib/v3/agent/tools/keys.d.ts +2 -1
- package/dist/esm/lib/v3/agent/tools/keys.js +57 -49
- package/dist/esm/lib/v3/agent/tools/keys.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/coordinateNormalization.js +3 -5
- package/dist/esm/lib/v3/agent/utils/coordinateNormalization.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 +5 -3
- package/dist/esm/lib/v3/api.js +5 -15
- package/dist/esm/lib/v3/api.js.map +1 -1
- package/dist/esm/lib/v3/cache/AgentCache.js +5 -3
- package/dist/esm/lib/v3/cache/AgentCache.js.map +1 -1
- package/dist/esm/lib/v3/flowlogger/EventStore.js +1 -1
- package/dist/esm/lib/v3/flowlogger/EventStore.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 -1
- package/dist/esm/lib/v3/handlers/v3AgentHandler.js +110 -46
- 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 +131 -16
- package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.js.map +1 -1
- package/dist/esm/lib/v3/index.d.ts +1 -1
- package/dist/esm/lib/v3/llm/LLMProvider.d.ts +5 -2
- package/dist/esm/lib/v3/llm/LLMProvider.js +15 -7
- package/dist/esm/lib/v3/llm/LLMProvider.js.map +1 -1
- package/dist/esm/lib/v3/llm/OpenAIClient.js +1 -0
- package/dist/esm/lib/v3/llm/OpenAIClient.js.map +1 -1
- package/dist/esm/lib/v3/llm/aisdk.d.ts +3 -1
- package/dist/esm/lib/v3/llm/aisdk.js +67 -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/agent.d.ts +8 -3
- package/dist/esm/lib/v3/types/public/agent.js +1 -0
- package/dist/esm/lib/v3/types/public/agent.js.map +1 -1
- package/dist/esm/lib/v3/types/public/api.d.ts +54 -7
- package/dist/esm/lib/v3/types/public/api.js +42 -14
- 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 +32 -2
- package/dist/esm/lib/v3/types/public/model.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/context.js +11 -3
- package/dist/esm/lib/v3/understudy/context.js.map +1 -1
- package/dist/esm/lib/v3/understudy/page.js +1 -1
- package/dist/esm/lib/v3/understudy/page.js.map +1 -1
- package/dist/esm/lib/v3/v3.d.ts +23 -2
- package/dist/esm/lib/v3/v3.js +111 -14
- 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/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/timeouts.spec.js +1 -1
- 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 +339 -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-metrics.test.d.ts +1 -0
- package/dist/esm/tests/unit/agent-metrics.test.js +110 -0
- package/dist/esm/tests/unit/agent-metrics.test.js.map +1 -0
- 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-clients.test.d.ts +1 -0
- package/dist/esm/tests/unit/aisdk-clients.test.js +88 -0
- package/dist/esm/tests/unit/aisdk-clients.test.js.map +1 -0
- package/dist/esm/tests/unit/anthropic-cua-adaptive-thinking.test.d.ts +1 -0
- package/dist/esm/tests/unit/anthropic-cua-adaptive-thinking.test.js +245 -0
- package/dist/esm/tests/unit/anthropic-cua-adaptive-thinking.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-optional-model-api-key.test.d.ts +1 -0
- package/dist/esm/tests/unit/api-optional-model-api-key.test.js +93 -0
- package/dist/esm/tests/unit/api-optional-model-api-key.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 +40 -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-eventstore.test.js +1 -1
- package/dist/esm/tests/unit/flowlogger-eventstore.test.js.map +1 -1
- 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/microsoft-cua-client.test.d.ts +1 -0
- package/dist/esm/tests/unit/microsoft-cua-client.test.js +84 -0
- package/dist/esm/tests/unit/microsoft-cua-client.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/llm-and-agents.test.js +1 -0
- 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 +5 -9
- package/dist/cjs/lib/v3/dom/build/rerender-index.js +0 -1
- package/dist/cjs/lib/v3/dom/build/v3-index.js +0 -1
- package/dist/esm/lib/v3/dom/build/rerender-index.js +0 -1
- package/dist/esm/lib/v3/dom/build/v3-index.js +0 -1
|
@@ -3,62 +3,70 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.keysTool = void 0;
|
|
4
4
|
const ai_1 = require("ai");
|
|
5
5
|
const zod_1 = require("zod");
|
|
6
|
-
const
|
|
7
|
-
|
|
6
|
+
const variables_js_1 = require("../utils/variables.js");
|
|
7
|
+
const keysTool = (v3, variables) => {
|
|
8
|
+
const hasVariables = variables && Object.keys(variables).length > 0;
|
|
9
|
+
const valueDescription = hasVariables
|
|
10
|
+
? `The text to type, or the key/combo to press (Enter, Tab, Cmd+A). Use %variableName% to substitute a variable value. Available: ${Object.keys(variables).join(", ")}`
|
|
11
|
+
: "The text to type, or the key/combo to press (Enter, Tab, Cmd+A)";
|
|
12
|
+
return (0, ai_1.tool)({
|
|
13
|
+
description: `Send keyboard input to the page without targeting a specific element. Unlike the type tool which clicks then types into coordinates, this sends keystrokes directly to wherever focus currently is.
|
|
8
14
|
|
|
9
15
|
Use method="type" to enter text into the currently focused element. Preferred when: input is already focused, text needs to flow across multiple fields (e.g., verification codes)
|
|
10
16
|
|
|
11
17
|
Use method="press" for navigation keys (Enter, Tab, Escape, Backspace, arrows) and keyboard shortcuts (Cmd+A, Ctrl+C, Shift+Tab).`,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
type: "object",
|
|
18
|
+
inputSchema: zod_1.z.object({
|
|
19
|
+
method: zod_1.z.enum(["press", "type"]),
|
|
20
|
+
value: zod_1.z.string().describe(valueDescription),
|
|
21
|
+
repeat: zod_1.z.number().optional(),
|
|
22
|
+
}),
|
|
23
|
+
execute: async ({ method, value, repeat }) => {
|
|
24
|
+
try {
|
|
25
|
+
const page = await v3.context.awaitActivePage();
|
|
26
|
+
v3.logger({
|
|
27
|
+
category: "agent",
|
|
28
|
+
message: `Agent calling tool: keys`,
|
|
29
|
+
level: 1,
|
|
30
|
+
auxiliary: {
|
|
31
|
+
arguments: {
|
|
32
|
+
value: JSON.stringify({ method, value, repeat }),
|
|
33
|
+
type: "object",
|
|
34
|
+
},
|
|
30
35
|
},
|
|
31
|
-
},
|
|
32
|
-
});
|
|
33
|
-
const times = Math.max(1, repeat ?? 1);
|
|
34
|
-
if (method === "type") {
|
|
35
|
-
for (let i = 0; i < times; i++) {
|
|
36
|
-
await page.type(value, { delay: 100 });
|
|
37
|
-
}
|
|
38
|
-
v3.recordAgentReplayStep({
|
|
39
|
-
type: "keys",
|
|
40
|
-
instruction: `type "${value}"`,
|
|
41
|
-
playwrightArguments: { method, text: value, times },
|
|
42
36
|
});
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
37
|
+
const times = Math.max(1, repeat ?? 1);
|
|
38
|
+
if (method === "type") {
|
|
39
|
+
// Substitute any %variableName% tokens in the value
|
|
40
|
+
const actualValue = (0, variables_js_1.substituteVariables)(value, variables);
|
|
41
|
+
for (let i = 0; i < times; i++) {
|
|
42
|
+
await page.type(actualValue, { delay: 100 });
|
|
43
|
+
}
|
|
44
|
+
v3.recordAgentReplayStep({
|
|
45
|
+
type: "keys",
|
|
46
|
+
instruction: `type "${value}"`,
|
|
47
|
+
playwrightArguments: { method, text: value, times },
|
|
48
|
+
});
|
|
49
|
+
// Return original value (with %variableName% tokens) to avoid exposing sensitive values to LLM
|
|
50
|
+
return { success: true, method, value, times };
|
|
48
51
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
if (method === "press") {
|
|
53
|
+
for (let i = 0; i < times; i++) {
|
|
54
|
+
await page.keyPress(value, { delay: 100 });
|
|
55
|
+
}
|
|
56
|
+
v3.recordAgentReplayStep({
|
|
57
|
+
type: "keys",
|
|
58
|
+
instruction: `press ${value}`,
|
|
59
|
+
playwrightArguments: { method, keys: value, times },
|
|
60
|
+
});
|
|
61
|
+
return { success: true, method, value, times };
|
|
62
|
+
}
|
|
63
|
+
return { success: false, error: `Unsupported method: ${method}` };
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
return { success: false, error: error.message };
|
|
55
67
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return { success: false, error: error.message };
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
});
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
};
|
|
63
71
|
exports.keysTool = keysTool;
|
|
64
72
|
//# sourceMappingURL=keys.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/tools/keys.ts"],"names":[],"mappings":";;;AAAA,2BAA0B;AAC1B,6BAAwB;
|
|
1
|
+
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/tools/keys.ts"],"names":[],"mappings":";;;AAAA,2BAA0B;AAC1B,6BAAwB;AAGxB,wDAA4D;AAErD,MAAM,QAAQ,GAAG,CAAC,EAAM,EAAE,SAAqB,EAAE,EAAE;IACxD,MAAM,YAAY,GAAG,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,SAA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O,EAAE,CAAC;YAClD,CAAC;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC;AAnEW,QAAA,QAAQ,YAmEnB","sourcesContent":["import { tool } from \"ai\";\nimport { z } from \"zod\";\nimport type { V3 } from \"../../v3.js\";\nimport type { Variables } from \"../../types/public/agent.js\";\nimport { substituteVariables } from \"../utils/variables.js\";\n\nexport const keysTool = (v3: V3, variables?: Variables) => {\n const hasVariables = variables && Object.keys(variables).length > 0;\n const valueDescription = hasVariables\n ? `The text to type, or the key/combo to press (Enter, Tab, Cmd+A). Use %variableName% to substitute a variable value. Available: ${Object.keys(variables).join(\", \")}`\n : \"The text to type, or the key/combo to press (Enter, Tab, Cmd+A)\";\n\n return tool({\n description: `Send keyboard input to the page without targeting a specific element. Unlike the type tool which clicks then types into coordinates, this sends keystrokes directly to wherever focus currently is.\n\nUse method=\"type\" to enter text into the currently focused element. Preferred when: input is already focused, text needs to flow across multiple fields (e.g., verification codes)\n\nUse method=\"press\" for navigation keys (Enter, Tab, Escape, Backspace, arrows) and keyboard shortcuts (Cmd+A, Ctrl+C, Shift+Tab).`,\n inputSchema: z.object({\n method: z.enum([\"press\", \"type\"]),\n value: z.string().describe(valueDescription),\n repeat: z.number().optional(),\n }),\n execute: async ({ method, value, repeat }) => {\n try {\n const page = await v3.context.awaitActivePage();\n v3.logger({\n category: \"agent\",\n message: `Agent calling tool: keys`,\n level: 1,\n auxiliary: {\n arguments: {\n value: JSON.stringify({ method, value, repeat }),\n type: \"object\",\n },\n },\n });\n\n const times = Math.max(1, repeat ?? 1);\n\n if (method === \"type\") {\n // Substitute any %variableName% tokens in the value\n const actualValue = substituteVariables(value, variables);\n for (let i = 0; i < times; i++) {\n await page.type(actualValue, { delay: 100 });\n }\n v3.recordAgentReplayStep({\n type: \"keys\",\n instruction: `type \"${value}\"`,\n playwrightArguments: { method, text: value, times },\n });\n // Return original value (with %variableName% tokens) to avoid exposing sensitive values to LLM\n return { success: true, method, value, times };\n }\n\n if (method === \"press\") {\n for (let i = 0; i < times; i++) {\n await page.keyPress(value, { delay: 100 });\n }\n v3.recordAgentReplayStep({\n type: \"keys\",\n instruction: `press ${value}`,\n playwrightArguments: { method, keys: value, times },\n });\n return { success: true, method, value, times };\n }\n\n return { success: false, error: `Unsupported method: ${method}` };\n } catch (error) {\n return { success: false, error: error.message };\n }\n },\n });\n};\n"]}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { Page } from "../../understudy/page.js";
|
|
2
|
+
/** Injected into the agent message stream after a successful captcha solve. */
|
|
3
|
+
export declare const CAPTCHA_SOLVED_MSG = "A captcha was automatically detected and solved \u2014 no further interaction with the captcha is needed, even if it does not visually appear solved. Do not click the captcha checkbox, widget, or challenge again. Continue with your task.";
|
|
4
|
+
/** Injected into the agent message stream when the captcha solver fails. */
|
|
5
|
+
export declare const CAPTCHA_ERRORED_MSG = "A captcha was detected but the automatic captcha solver failed to solve it. You may need to try a different approach or navigate around the captcha.";
|
|
6
|
+
/** Appended to the system prompt (DOM/hybrid agents) when captchas auto-solve. */
|
|
7
|
+
export declare const CAPTCHA_SYSTEM_PROMPT_NOTE = "Captchas on this page are automatically detected and solved by the browser environment. Do not interact with or attempt to solve any captchas yourself \u2014 they will be handled for you. Do not click the captcha checkbox, widget, or challenge again after it has been solved, even if it still looks unresolved. Continue with your task as if the captcha does not exist.";
|
|
8
|
+
/** Appended to the CUA system prompt when captchas auto-solve. */
|
|
9
|
+
export declare const CAPTCHA_CUA_SYSTEM_PROMPT_NOTE = "\n\nCaptchas on this page are automatically detected and solved by the browser environment. Do not interact with or attempt to solve any captchas yourself \u2014 they will be handled for you. Continue with your task as if the captcha does not exist.";
|
|
10
|
+
/**
|
|
11
|
+
* Tracks Browserbase captcha solver state via console messages and provides
|
|
12
|
+
* a blocking `waitIfSolving()` that agents call before each step/action.
|
|
13
|
+
*
|
|
14
|
+
* Accepts a page-provider callback so the listener is automatically
|
|
15
|
+
* re-attached when the active page changes (e.g. popup / new tab).
|
|
16
|
+
*
|
|
17
|
+
* All concurrent callers of `waitIfSolving()` share the same underlying
|
|
18
|
+
* promise, so multiple waiters are safely resolved together.
|
|
19
|
+
*/
|
|
20
|
+
export declare class CaptchaSolver {
|
|
21
|
+
private solving;
|
|
22
|
+
private _solvedSinceLastConsume;
|
|
23
|
+
private _erroredSinceLastConsume;
|
|
24
|
+
private listener;
|
|
25
|
+
private attachedPage;
|
|
26
|
+
private pageProvider;
|
|
27
|
+
/** Shared promise that all concurrent waitIfSolving() callers await. */
|
|
28
|
+
private waitPromise;
|
|
29
|
+
/** Resolves the shared waitPromise. */
|
|
30
|
+
private resolveWait;
|
|
31
|
+
/** Timeout handle for the 90s deadline. */
|
|
32
|
+
private waitTimer;
|
|
33
|
+
/**
|
|
34
|
+
* Initialise with a callback that returns the current active page.
|
|
35
|
+
* The listener is lazily (re-)attached whenever the active page changes.
|
|
36
|
+
*/
|
|
37
|
+
init(pageProvider: () => Promise<Page>): void;
|
|
38
|
+
/** Whether a captcha solve is currently in progress. */
|
|
39
|
+
isSolving(): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Ensure the console listener is attached to the current active page.
|
|
42
|
+
* If the active page has changed since the last call, the old listener
|
|
43
|
+
* is removed and a new one is installed.
|
|
44
|
+
*/
|
|
45
|
+
ensureAttached(): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Returns a promise that resolves immediately if no captcha is being
|
|
48
|
+
* solved, or blocks until the solver finishes, errors, or the 90s
|
|
49
|
+
* timeout is reached.
|
|
50
|
+
*
|
|
51
|
+
* Also re-attaches the listener to the current active page if it has
|
|
52
|
+
* changed since the last call.
|
|
53
|
+
*
|
|
54
|
+
* All concurrent callers share the same promise, so no waiter is
|
|
55
|
+
* orphaned.
|
|
56
|
+
*/
|
|
57
|
+
waitIfSolving(): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Returns and resets the solve event flags.
|
|
60
|
+
* Call after `waitIfSolving()` to check whether a captcha was solved
|
|
61
|
+
* (or errored) since the last consume. This captures events even if
|
|
62
|
+
* the solve completed between two `waitIfSolving()` calls.
|
|
63
|
+
*/
|
|
64
|
+
consumeSolveResult(): {
|
|
65
|
+
solved: boolean;
|
|
66
|
+
errored: boolean;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Remove the console listener and reset all state.
|
|
70
|
+
*/
|
|
71
|
+
dispose(): void;
|
|
72
|
+
/** Remove the console listener from the currently attached page. */
|
|
73
|
+
private detachListener;
|
|
74
|
+
/** Resolve the shared wait promise and clear the timeout. */
|
|
75
|
+
private settle;
|
|
76
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CaptchaSolver = exports.CAPTCHA_CUA_SYSTEM_PROMPT_NOTE = exports.CAPTCHA_SYSTEM_PROMPT_NOTE = exports.CAPTCHA_ERRORED_MSG = exports.CAPTCHA_SOLVED_MSG = void 0;
|
|
4
|
+
const SOLVING_STARTED = "browserbase-solving-started";
|
|
5
|
+
const SOLVING_FINISHED = "browserbase-solving-finished";
|
|
6
|
+
const SOLVING_ERRORED = "browserbase-solving-errored";
|
|
7
|
+
/** Maximum time (ms) to wait for the captcha solver before giving up. */
|
|
8
|
+
const SOLVE_TIMEOUT_MS = 90_000;
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
// Shared captcha notification strings
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
/** Injected into the agent message stream after a successful captcha solve. */
|
|
13
|
+
exports.CAPTCHA_SOLVED_MSG = "A captcha was automatically detected and solved — no further interaction with the captcha is needed, even if it does not visually appear solved. Do not click the captcha checkbox, widget, or challenge again. Continue with your task.";
|
|
14
|
+
/** Injected into the agent message stream when the captcha solver fails. */
|
|
15
|
+
exports.CAPTCHA_ERRORED_MSG = "A captcha was detected but the automatic captcha solver failed to solve it. You may need to try a different approach or navigate around the captcha.";
|
|
16
|
+
/** Appended to the system prompt (DOM/hybrid agents) when captchas auto-solve. */
|
|
17
|
+
exports.CAPTCHA_SYSTEM_PROMPT_NOTE = "Captchas on this page are automatically detected and solved by the browser environment. Do not interact with or attempt to solve any captchas yourself — they will be handled for you. Do not click the captcha checkbox, widget, or challenge again after it has been solved, even if it still looks unresolved. Continue with your task as if the captcha does not exist.";
|
|
18
|
+
/** Appended to the CUA system prompt when captchas auto-solve. */
|
|
19
|
+
exports.CAPTCHA_CUA_SYSTEM_PROMPT_NOTE = "\n\nCaptchas on this page are automatically detected and solved by the browser environment. Do not interact with or attempt to solve any captchas yourself — they will be handled for you. Continue with your task as if the captcha does not exist.";
|
|
20
|
+
/**
|
|
21
|
+
* Tracks Browserbase captcha solver state via console messages and provides
|
|
22
|
+
* a blocking `waitIfSolving()` that agents call before each step/action.
|
|
23
|
+
*
|
|
24
|
+
* Accepts a page-provider callback so the listener is automatically
|
|
25
|
+
* re-attached when the active page changes (e.g. popup / new tab).
|
|
26
|
+
*
|
|
27
|
+
* All concurrent callers of `waitIfSolving()` share the same underlying
|
|
28
|
+
* promise, so multiple waiters are safely resolved together.
|
|
29
|
+
*/
|
|
30
|
+
class CaptchaSolver {
|
|
31
|
+
solving = false;
|
|
32
|
+
_solvedSinceLastConsume = false;
|
|
33
|
+
_erroredSinceLastConsume = false;
|
|
34
|
+
listener = null;
|
|
35
|
+
attachedPage = null;
|
|
36
|
+
pageProvider = null;
|
|
37
|
+
/** Shared promise that all concurrent waitIfSolving() callers await. */
|
|
38
|
+
waitPromise = null;
|
|
39
|
+
/** Resolves the shared waitPromise. */
|
|
40
|
+
resolveWait = null;
|
|
41
|
+
/** Timeout handle for the 90s deadline. */
|
|
42
|
+
waitTimer = null;
|
|
43
|
+
/**
|
|
44
|
+
* Initialise with a callback that returns the current active page.
|
|
45
|
+
* The listener is lazily (re-)attached whenever the active page changes.
|
|
46
|
+
*/
|
|
47
|
+
init(pageProvider) {
|
|
48
|
+
this.pageProvider = pageProvider;
|
|
49
|
+
}
|
|
50
|
+
/** Whether a captcha solve is currently in progress. */
|
|
51
|
+
isSolving() {
|
|
52
|
+
return this.solving;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Ensure the console listener is attached to the current active page.
|
|
56
|
+
* If the active page has changed since the last call, the old listener
|
|
57
|
+
* is removed and a new one is installed.
|
|
58
|
+
*/
|
|
59
|
+
async ensureAttached() {
|
|
60
|
+
if (!this.pageProvider)
|
|
61
|
+
return;
|
|
62
|
+
const page = await this.pageProvider();
|
|
63
|
+
if (page === this.attachedPage)
|
|
64
|
+
return;
|
|
65
|
+
// Detach from the old page
|
|
66
|
+
this.detachListener();
|
|
67
|
+
this.attachedPage = page;
|
|
68
|
+
this.listener = (msg) => {
|
|
69
|
+
const text = msg.text();
|
|
70
|
+
if (text === SOLVING_STARTED) {
|
|
71
|
+
this.solving = true;
|
|
72
|
+
}
|
|
73
|
+
else if (text === SOLVING_FINISHED) {
|
|
74
|
+
this.solving = false;
|
|
75
|
+
this._solvedSinceLastConsume = true;
|
|
76
|
+
this.settle();
|
|
77
|
+
}
|
|
78
|
+
else if (text === SOLVING_ERRORED) {
|
|
79
|
+
this.solving = false;
|
|
80
|
+
this._erroredSinceLastConsume = true;
|
|
81
|
+
this.settle();
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
page.on("console", this.listener);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Returns a promise that resolves immediately if no captcha is being
|
|
88
|
+
* solved, or blocks until the solver finishes, errors, or the 90s
|
|
89
|
+
* timeout is reached.
|
|
90
|
+
*
|
|
91
|
+
* Also re-attaches the listener to the current active page if it has
|
|
92
|
+
* changed since the last call.
|
|
93
|
+
*
|
|
94
|
+
* All concurrent callers share the same promise, so no waiter is
|
|
95
|
+
* orphaned.
|
|
96
|
+
*/
|
|
97
|
+
async waitIfSolving() {
|
|
98
|
+
await this.ensureAttached();
|
|
99
|
+
if (!this.solving)
|
|
100
|
+
return;
|
|
101
|
+
// Return the existing shared promise if one is already pending
|
|
102
|
+
if (this.waitPromise)
|
|
103
|
+
return this.waitPromise;
|
|
104
|
+
this.waitPromise = new Promise((resolve) => {
|
|
105
|
+
this.resolveWait = resolve;
|
|
106
|
+
this.waitTimer = setTimeout(() => {
|
|
107
|
+
this.solving = false;
|
|
108
|
+
this._erroredSinceLastConsume = true;
|
|
109
|
+
this.settle();
|
|
110
|
+
}, SOLVE_TIMEOUT_MS);
|
|
111
|
+
});
|
|
112
|
+
return this.waitPromise;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Returns and resets the solve event flags.
|
|
116
|
+
* Call after `waitIfSolving()` to check whether a captcha was solved
|
|
117
|
+
* (or errored) since the last consume. This captures events even if
|
|
118
|
+
* the solve completed between two `waitIfSolving()` calls.
|
|
119
|
+
*/
|
|
120
|
+
consumeSolveResult() {
|
|
121
|
+
const result = {
|
|
122
|
+
solved: this._solvedSinceLastConsume,
|
|
123
|
+
errored: this._erroredSinceLastConsume,
|
|
124
|
+
};
|
|
125
|
+
this._solvedSinceLastConsume = false;
|
|
126
|
+
this._erroredSinceLastConsume = false;
|
|
127
|
+
return result;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Remove the console listener and reset all state.
|
|
131
|
+
*/
|
|
132
|
+
dispose() {
|
|
133
|
+
this.detachListener();
|
|
134
|
+
this.attachedPage = null;
|
|
135
|
+
this.pageProvider = null;
|
|
136
|
+
this.solving = false;
|
|
137
|
+
this._solvedSinceLastConsume = false;
|
|
138
|
+
this._erroredSinceLastConsume = false;
|
|
139
|
+
this.settle();
|
|
140
|
+
}
|
|
141
|
+
// ------------------------------------------------------------------
|
|
142
|
+
// Internal helpers
|
|
143
|
+
// ------------------------------------------------------------------
|
|
144
|
+
/** Remove the console listener from the currently attached page. */
|
|
145
|
+
detachListener() {
|
|
146
|
+
if (this.attachedPage && this.listener) {
|
|
147
|
+
this.attachedPage.off("console", this.listener);
|
|
148
|
+
}
|
|
149
|
+
this.listener = null;
|
|
150
|
+
// If a solve was in progress, mark it as errored so consumers
|
|
151
|
+
// know it was interrupted (consistent with the timeout path).
|
|
152
|
+
if (this.solving) {
|
|
153
|
+
this._erroredSinceLastConsume = true;
|
|
154
|
+
}
|
|
155
|
+
// Reset solving state so waiters aren't stuck waiting for events
|
|
156
|
+
// that can never arrive from the detached page.
|
|
157
|
+
this.solving = false;
|
|
158
|
+
this.settle();
|
|
159
|
+
}
|
|
160
|
+
/** Resolve the shared wait promise and clear the timeout. */
|
|
161
|
+
settle() {
|
|
162
|
+
if (this.waitTimer) {
|
|
163
|
+
clearTimeout(this.waitTimer);
|
|
164
|
+
this.waitTimer = null;
|
|
165
|
+
}
|
|
166
|
+
if (this.resolveWait) {
|
|
167
|
+
const resolve = this.resolveWait;
|
|
168
|
+
this.resolveWait = null;
|
|
169
|
+
this.waitPromise = null;
|
|
170
|
+
resolve();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
exports.CaptchaSolver = CaptchaSolver;
|
|
175
|
+
//# sourceMappingURL=captchaSolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"captchaSolver.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/utils/captchaSolver.ts"],"names":[],"mappings":";;;AAGA,MAAM,eAAe,GAAG,6BAA6B,CAAC;AACtD,MAAM,gBAAgB,GAAG,8BAA8B,CAAC;AACxD,MAAM,eAAe,GAAG,6BAA6B,CAAC;AAEtD,yEAAyE;AACzE,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEhC,8EAA8E;AAC9E,sCAAsC;AACtC,8EAA8E;AAE9E,+EAA+E;AAClE,QAAA,kBAAkB,GAC7B,0OAA0O,CAAC;AAE7O,4EAA4E;AAC/D,QAAA,mBAAmB,GAC9B,sJAAsJ,CAAC;AAEzJ,kFAAkF;AACrE,QAAA,0BAA0B,GACrC,6WAA6W,CAAC;AAEhX,kEAAkE;AACrD,QAAA,8BAA8B,GACzC,sPAA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/page.js\";\nimport type { ConsoleMessage } from \"../../understudy/consoleMessage.js\";\n\nconst SOLVING_STARTED = \"browserbase-solving-started\";\nconst SOLVING_FINISHED = \"browserbase-solving-finished\";\nconst SOLVING_ERRORED = \"browserbase-solving-errored\";\n\n/** Maximum time (ms) to wait for the captcha solver before giving up. */\nconst SOLVE_TIMEOUT_MS = 90_000;\n\n// ---------------------------------------------------------------------------\n// Shared captcha notification strings\n// ---------------------------------------------------------------------------\n\n/** Injected into the agent message stream after a successful captcha solve. */\nexport const CAPTCHA_SOLVED_MSG =\n \"A captcha was automatically detected and solved — no further interaction with the captcha is needed, even if it does not visually appear solved. Do not click the captcha checkbox, widget, or challenge again. Continue with your task.\";\n\n/** Injected into the agent message stream when the captcha solver fails. */\nexport const CAPTCHA_ERRORED_MSG =\n \"A captcha was detected but the automatic captcha solver failed to solve it. You may need to try a different approach or navigate around the captcha.\";\n\n/** Appended to the system prompt (DOM/hybrid agents) when captchas auto-solve. */\nexport const CAPTCHA_SYSTEM_PROMPT_NOTE =\n \"Captchas on this page are automatically detected and solved by the browser environment. Do not interact with or attempt to solve any captchas yourself — they will be handled for you. Do not click the captcha checkbox, widget, or challenge again after it has been solved, even if it still looks unresolved. Continue with your task as if the captcha does not exist.\";\n\n/** Appended to the CUA system prompt when captchas auto-solve. */\nexport const CAPTCHA_CUA_SYSTEM_PROMPT_NOTE =\n \"\\n\\nCaptchas on this page are automatically detected and solved by the browser environment. Do not interact with or attempt to solve any captchas yourself — they will be handled for you. Continue with your task as if the captcha does not exist.\";\n\n/**\n * Tracks Browserbase captcha solver state via console messages and provides\n * a blocking `waitIfSolving()` that agents call before each step/action.\n *\n * Accepts a page-provider callback so the listener is automatically\n * re-attached when the active page changes (e.g. popup / new tab).\n *\n * All concurrent callers of `waitIfSolving()` share the same underlying\n * promise, so multiple waiters are safely resolved together.\n */\nexport class CaptchaSolver {\n private solving = false;\n private _solvedSinceLastConsume = false;\n private _erroredSinceLastConsume = false;\n private listener: ((msg: ConsoleMessage) => void) | null = null;\n private attachedPage: Page | null = null;\n private pageProvider: (() => Promise<Page>) | null = null;\n\n /** Shared promise that all concurrent waitIfSolving() callers await. */\n private waitPromise: Promise<void> | null = null;\n /** Resolves the shared waitPromise. */\n private resolveWait: (() => void) | null = null;\n /** Timeout handle for the 90s deadline. */\n private waitTimer: ReturnType<typeof setTimeout> | null = null;\n\n /**\n * Initialise with a callback that returns the current active page.\n * The listener is lazily (re-)attached whenever the active page changes.\n */\n init(pageProvider: () => Promise<Page>): void {\n this.pageProvider = pageProvider;\n }\n\n /** Whether a captcha solve is currently in progress. */\n isSolving(): boolean {\n return this.solving;\n }\n\n /**\n * Ensure the console listener is attached to the current active page.\n * If the active page has changed since the last call, the old listener\n * is removed and a new one is installed.\n */\n async ensureAttached(): Promise<void> {\n if (!this.pageProvider) return;\n const page = await this.pageProvider();\n if (page === this.attachedPage) return;\n\n // Detach from the old page\n this.detachListener();\n\n this.attachedPage = page;\n this.listener = (msg: ConsoleMessage) => {\n const text = msg.text();\n if (text === SOLVING_STARTED) {\n this.solving = true;\n } else if (text === SOLVING_FINISHED) {\n this.solving = false;\n this._solvedSinceLastConsume = true;\n this.settle();\n } else if (text === SOLVING_ERRORED) {\n this.solving = false;\n this._erroredSinceLastConsume = true;\n this.settle();\n }\n };\n page.on(\"console\", this.listener);\n }\n\n /**\n * Returns a promise that resolves immediately if no captcha is being\n * solved, or blocks until the solver finishes, errors, or the 90s\n * timeout is reached.\n *\n * Also re-attaches the listener to the current active page if it has\n * changed since the last call.\n *\n * All concurrent callers share the same promise, so no waiter is\n * orphaned.\n */\n async waitIfSolving(): Promise<void> {\n await this.ensureAttached();\n\n if (!this.solving) return;\n\n // Return the existing shared promise if one is already pending\n if (this.waitPromise) return this.waitPromise;\n\n this.waitPromise = new Promise<void>((resolve) => {\n this.resolveWait = resolve;\n this.waitTimer = setTimeout(() => {\n this.solving = false;\n this._erroredSinceLastConsume = true;\n this.settle();\n }, SOLVE_TIMEOUT_MS);\n });\n\n return this.waitPromise;\n }\n\n /**\n * Returns and resets the solve event flags.\n * Call after `waitIfSolving()` to check whether a captcha was solved\n * (or errored) since the last consume. This captures events even if\n * the solve completed between two `waitIfSolving()` calls.\n */\n consumeSolveResult(): { solved: boolean; errored: boolean } {\n const result = {\n solved: this._solvedSinceLastConsume,\n errored: this._erroredSinceLastConsume,\n };\n this._solvedSinceLastConsume = false;\n this._erroredSinceLastConsume = false;\n return result;\n }\n\n /**\n * Remove the console listener and reset all state.\n */\n dispose(): void {\n this.detachListener();\n this.attachedPage = null;\n this.pageProvider = null;\n this.solving = false;\n this._solvedSinceLastConsume = false;\n this._erroredSinceLastConsume = false;\n this.settle();\n }\n\n // ------------------------------------------------------------------\n // Internal helpers\n // ------------------------------------------------------------------\n\n /** Remove the console listener from the currently attached page. */\n private detachListener(): void {\n if (this.attachedPage && this.listener) {\n this.attachedPage.off(\"console\", this.listener);\n }\n this.listener = null;\n // If a solve was in progress, mark it as errored so consumers\n // know it was interrupted (consistent with the timeout path).\n if (this.solving) {\n this._erroredSinceLastConsume = true;\n }\n // Reset solving state so waiters aren't stuck waiting for events\n // that can never arrive from the detached page.\n this.solving = false;\n this.settle();\n }\n\n /** Resolve the shared wait promise and clear the timeout. */\n private settle(): void {\n if (this.waitTimer) {\n clearTimeout(this.waitTimer);\n this.waitTimer = null;\n }\n if (this.resolveWait) {\n const resolve = this.resolveWait;\n this.resolveWait = null;\n this.waitPromise = null;\n resolve();\n }\n }\n}\n"]}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.isGoogleProvider = isGoogleProvider;
|
|
4
4
|
exports.normalizeGoogleCoordinates = normalizeGoogleCoordinates;
|
|
5
5
|
exports.processCoordinates = processCoordinates;
|
|
6
|
-
// Default viewport for
|
|
6
|
+
// Default viewport for Browserbase managed fingerprinting mode
|
|
7
7
|
const STEALTH_VIEWPORT = { width: 1288, height: 711 };
|
|
8
8
|
function isGoogleProvider(provider) {
|
|
9
9
|
if (!provider)
|
|
@@ -22,10 +22,8 @@ function normalizeGoogleCoordinates(x, y, viewport) {
|
|
|
22
22
|
}
|
|
23
23
|
function processCoordinates(x, y, provider, v3) {
|
|
24
24
|
if (isGoogleProvider(provider) && v3) {
|
|
25
|
-
//
|
|
26
|
-
const viewport = v3.
|
|
27
|
-
? STEALTH_VIEWPORT
|
|
28
|
-
: v3.configuredViewport;
|
|
25
|
+
// Browserbase managed fingerprinting uses a fixed viewport fallback.
|
|
26
|
+
const viewport = v3.isVerified ? STEALTH_VIEWPORT : v3.configuredViewport;
|
|
29
27
|
return normalizeGoogleCoordinates(x, y, viewport);
|
|
30
28
|
}
|
|
31
29
|
return { x, y };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coordinateNormalization.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/utils/coordinateNormalization.ts"],"names":[],"mappings":";;AAKA,4CAGC;AAID,gEAWC;AAED,
|
|
1
|
+
{"version":3,"file":"coordinateNormalization.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/utils/coordinateNormalization.ts"],"names":[],"mappings":";;AAKA,4CAGC;AAID,gEAWC;AAED,gDAYC;AAnCD,+DAA+D;AAC/D,MAAM,gBAAgB,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;AAEtD,SAAgB,gBAAgB,CAAC,QAAiB;IAChD,IAAI,CAAC,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC5B,OAAO,QAAQ,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACnD,CAAC;AAED,qEAAqE;AACrE,kCAAkC;AAClC,SAAgB,0BAA0B,CACxC,CAAS,EACT,CAAS,EACT,QAA2C;IAE3C,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC/C,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC/C,OAAO;QACL,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC;QACjD,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC;KACnD,CAAC;AACJ,CAAC;AAED,SAAgB,kBAAkB,CAChC,CAAS,EACT,CAAS,EACT,QAAiB,EACjB,EAAO;IAEP,IAAI,gBAAgB,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC;QACrC,qEAAqE;QACrE,MAAM,QAAQ,GAAG,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC,kBAAkB,CAAC;QAC1E,OAAO,0BAA0B,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC;IACpD,CAAC;IACD,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AAClB,CAAC","sourcesContent":["import type { V3 } from \"../../v3.js\";\n\n// Default viewport for Browserbase managed fingerprinting mode\nconst STEALTH_VIEWPORT = { width: 1288, height: 711 };\n\nexport function isGoogleProvider(provider?: string): boolean {\n if (!provider) return false;\n return provider.toLowerCase().includes(\"google\");\n}\n\n// Google returns coordinates in a 0-1000 range, we need to normalize\n// them to the viewport dimensions\nexport function normalizeGoogleCoordinates(\n x: number,\n y: number,\n viewport: { width: number; height: number },\n): { x: number; y: number } {\n const clampedX = Math.min(999, Math.max(0, x));\n const clampedY = Math.min(999, Math.max(0, y));\n return {\n x: Math.floor((clampedX / 1000) * viewport.width),\n y: Math.floor((clampedY / 1000) * viewport.height),\n };\n}\n\nexport function processCoordinates(\n x: number,\n y: number,\n provider?: string,\n v3?: V3,\n): { x: number; y: number } {\n if (isGoogleProvider(provider) && v3) {\n // Browserbase managed fingerprinting uses a fixed viewport fallback.\n const viewport = v3.isVerified ? STEALTH_VIEWPORT : v3.configuredViewport;\n return normalizeGoogleCoordinates(x, y, viewport);\n }\n return { x, y };\n}\n"]}
|
|
@@ -9,6 +9,11 @@ export declare function resolveVariableValue(v: VariableValue): string;
|
|
|
9
9
|
* Returns undefined for simple primitive values.
|
|
10
10
|
*/
|
|
11
11
|
export declare function getVariableDescription(v: VariableValue): string | undefined;
|
|
12
|
+
export interface VariablePromptEntry {
|
|
13
|
+
name: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare function getVariablePromptEntries(variables?: Variables): VariablePromptEntry[];
|
|
12
17
|
/**
|
|
13
18
|
* Substitutes %variableName% tokens in text with resolved variable values.
|
|
14
19
|
* Works with both simple and rich variable formats.
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.resolveVariableValue = resolveVariableValue;
|
|
4
4
|
exports.getVariableDescription = getVariableDescription;
|
|
5
|
+
exports.getVariablePromptEntries = getVariablePromptEntries;
|
|
5
6
|
exports.substituteVariables = substituteVariables;
|
|
6
7
|
exports.flattenVariables = flattenVariables;
|
|
7
8
|
/**
|
|
@@ -24,6 +25,14 @@ function getVariableDescription(v) {
|
|
|
24
25
|
}
|
|
25
26
|
return undefined;
|
|
26
27
|
}
|
|
28
|
+
function getVariablePromptEntries(variables) {
|
|
29
|
+
if (!variables)
|
|
30
|
+
return [];
|
|
31
|
+
return Object.entries(variables).map(([name, value]) => ({
|
|
32
|
+
name,
|
|
33
|
+
description: getVariableDescription(value),
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
27
36
|
/**
|
|
28
37
|
* Substitutes %variableName% tokens in text with resolved variable values.
|
|
29
38
|
* Works with both simple and rich variable formats.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variables.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/utils/variables.ts"],"names":[],"mappings":";;AAMA,oDAKC;AAMD,wDAKC;AAMD,kDAWC;AAMD,4CASC;
|
|
1
|
+
{"version":3,"file":"variables.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/utils/variables.ts"],"names":[],"mappings":";;AAMA,oDAKC;AAMD,wDAKC;AAOD,4DAQC;AAMD,kDAWC;AAMD,4CASC;AAnED;;;GAGG;AACH,SAAgB,oBAAoB,CAAC,CAAgB;IACnD,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAI,OAAO,IAAI,CAAC,EAAE,CAAC;QACxD,OAAO,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC;IACD,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;AACnB,CAAC;AAED;;;GAGG;AACH,SAAgB,sBAAsB,CAAC,CAAgB;IACrD,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAI,OAAO,IAAI,CAAC,EAAE,CAAC;QACxD,OAAO,CAAC,CAAC,WAAW,CAAC;IACvB,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAOD,SAAgB,wBAAwB,CACtC,SAAqB;IAErB,IAAI,CAAC,SAAS;QAAE,OAAO,EAAE,CAAC;IAC1B,OAAO,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;QACvD,IAAI;QACJ,WAAW,EAAE,sBAAsB,CAAC,KAAK,CAAC;KAC3C,CAAC,CAAC,CAAC;AACN,CAAC;AAED;;;GAGG;AACH,SAAgB,mBAAmB,CACjC,IAAY,EACZ,SAAqB;IAErB,IAAI,CAAC,SAAS;QAAE,OAAO,IAAI,CAAC;IAC5B,IAAI,MAAM,GAAG,IAAI,CAAC;IAClB,KAAK,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QACjD,MAAM,KAAK,GAAG,IAAI,GAAG,GAAG,CAAC;QACzB,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;GAGG;AACH,SAAgB,gBAAgB,CAC9B,SAAqB;IAErB,IAAI,CAAC,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IACxE,MAAM,MAAM,GAA2B,EAAE,CAAC;IAC1C,KAAK,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QACjD,MAAM,CAAC,GAAG,CAAC,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC;IACxC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { Variables, VariableValue } from \"../../types/public/agent.js\";\n\n/**\n * Resolves a VariableValue to its primitive string value.\n * Handles both simple primitives (\"secret\") and rich objects ({ value: \"secret\", description: \"...\" }).\n */\nexport function resolveVariableValue(v: VariableValue): string {\n if (typeof v === \"object\" && v !== null && \"value\" in v) {\n return String(v.value);\n }\n return String(v);\n}\n\n/**\n * Extracts the optional description from a VariableValue.\n * Returns undefined for simple primitive values.\n */\nexport function getVariableDescription(v: VariableValue): string | undefined {\n if (typeof v === \"object\" && v !== null && \"value\" in v) {\n return v.description;\n }\n return undefined;\n}\n\nexport interface VariablePromptEntry {\n name: string;\n description?: string;\n}\n\nexport function getVariablePromptEntries(\n variables?: Variables,\n): VariablePromptEntry[] {\n if (!variables) return [];\n return Object.entries(variables).map(([name, value]) => ({\n name,\n description: getVariableDescription(value),\n }));\n}\n\n/**\n * Substitutes %variableName% tokens in text with resolved variable values.\n * Works with both simple and rich variable formats.\n */\nexport function substituteVariables(\n text: string,\n variables?: Variables,\n): string {\n if (!variables) return text;\n let result = text;\n for (const [key, v] of Object.entries(variables)) {\n const token = `%${key}%`;\n result = result.split(token).join(resolveVariableValue(v));\n }\n return result;\n}\n\n/**\n * Flattens Variables to Record<string, string> for internal consumers\n * that only need key→value mappings (e.g., actHandler, cache replay).\n */\nexport function flattenVariables(\n variables?: Variables,\n): Record<string, string> | undefined {\n if (!variables || Object.keys(variables).length === 0) return undefined;\n const result: Record<string, string> = {};\n for (const [key, v] of Object.entries(variables)) {\n result[key] = resolveVariableValue(v);\n }\n return result;\n}\n"]}
|
package/dist/cjs/lib/v3/api.d.ts
CHANGED
|
@@ -37,8 +37,10 @@ interface StagehandAPIConstructorParams {
|
|
|
37
37
|
* Wire format: Api.SessionStartRequest (modelApiKey sent via header, not body)
|
|
38
38
|
*/
|
|
39
39
|
interface ClientSessionStartParams extends Api.SessionStartRequest {
|
|
40
|
-
/** Model API key - sent via x-model-api-key header, not in request body
|
|
41
|
-
|
|
40
|
+
/** Model API key - sent via x-model-api-key header, not in request body.
|
|
41
|
+
* Optional: when omitted, requests are sent without the x-model-api-key header
|
|
42
|
+
* and the server is expected to handle model authentication on its own. */
|
|
43
|
+
modelApiKey?: string;
|
|
42
44
|
}
|
|
43
45
|
/**
|
|
44
46
|
* Client parameters for act() method.
|
|
@@ -75,7 +77,7 @@ export declare class StagehandAPIClient {
|
|
|
75
77
|
private apiKey;
|
|
76
78
|
private projectId?;
|
|
77
79
|
private sessionId?;
|
|
78
|
-
private modelApiKey
|
|
80
|
+
private modelApiKey?;
|
|
79
81
|
private modelProvider?;
|
|
80
82
|
private region?;
|
|
81
83
|
private logger;
|
package/dist/cjs/lib/v3/api.js
CHANGED
|
@@ -59,9 +59,6 @@ class StagehandAPIClient {
|
|
|
59
59
|
async init({ modelName, modelApiKey, domSettleTimeoutMs, verbose, systemPrompt, selfHeal, browserbaseSessionCreateParams, browserbaseSessionID,
|
|
60
60
|
// browser, TODO for local browsers
|
|
61
61
|
}) {
|
|
62
|
-
if (!modelApiKey) {
|
|
63
|
-
throw new index_js_1.StagehandAPIError("modelApiKey is required");
|
|
64
|
-
}
|
|
65
62
|
this.modelApiKey = modelApiKey;
|
|
66
63
|
// Extract provider from modelName (e.g., "openai/gpt-5-nano" -> "openai")
|
|
67
64
|
this.modelProvider = modelName?.includes("/")
|
|
@@ -89,7 +86,6 @@ class StagehandAPIClient {
|
|
|
89
86
|
method: "POST",
|
|
90
87
|
body: JSON.stringify(requestBody),
|
|
91
88
|
});
|
|
92
|
-
console.log(JSON.stringify(requestBody, null, 2));
|
|
93
89
|
if (sessionResponse.status === 401) {
|
|
94
90
|
throw new index_js_1.StagehandAPIUnauthorizedError("Unauthorized. Ensure you provided a valid API key.");
|
|
95
91
|
}
|
|
@@ -240,9 +236,6 @@ class StagehandAPIClient {
|
|
|
240
236
|
frameId,
|
|
241
237
|
shouldCache,
|
|
242
238
|
};
|
|
243
|
-
console.log(JSON.stringify(requestBody, null, 2));
|
|
244
|
-
console.log(JSON.stringify(requestBody, null, 2));
|
|
245
|
-
console.log(JSON.stringify(requestBody, null, 2));
|
|
246
239
|
const result = await this.execute({
|
|
247
240
|
method: "agentExecute",
|
|
248
241
|
args: requestBody,
|
|
@@ -393,7 +386,7 @@ class StagehandAPIClient {
|
|
|
393
386
|
: this.modelApiKey;
|
|
394
387
|
return {
|
|
395
388
|
modelName: model,
|
|
396
|
-
apiKey,
|
|
389
|
+
...(apiKey ? { apiKey } : {}),
|
|
397
390
|
};
|
|
398
391
|
}
|
|
399
392
|
if (!model.apiKey) {
|
|
@@ -405,7 +398,7 @@ class StagehandAPIClient {
|
|
|
405
398
|
: this.modelApiKey;
|
|
406
399
|
return {
|
|
407
400
|
...model,
|
|
408
|
-
apiKey,
|
|
401
|
+
...(apiKey ? { apiKey } : {}),
|
|
409
402
|
};
|
|
410
403
|
}
|
|
411
404
|
return model;
|
|
@@ -557,7 +550,7 @@ class StagehandAPIClient {
|
|
|
557
550
|
"x-bb-session-id": this.sessionId,
|
|
558
551
|
// we want real-time logs, so we stream the response
|
|
559
552
|
"x-stream-response": "true",
|
|
560
|
-
"x-model-api-key": this.modelApiKey,
|
|
553
|
+
...(this.modelApiKey ? { "x-model-api-key": this.modelApiKey } : {}),
|
|
561
554
|
"x-language": "typescript",
|
|
562
555
|
"x-sdk-version": version_js_1.STAGEHAND_VERSION,
|
|
563
556
|
};
|
|
@@ -579,16 +572,13 @@ class StagehandAPIClient {
|
|
|
579
572
|
else {
|
|
580
573
|
baseUrl = getApiUrlForRegion(this.region);
|
|
581
574
|
}
|
|
582
|
-
const
|
|
583
|
-
const fetchOptions = {
|
|
575
|
+
const response = await this.fetchWithCookies(`${baseUrl}${path}`, {
|
|
584
576
|
...options,
|
|
585
577
|
headers: {
|
|
586
578
|
...defaultHeaders,
|
|
587
579
|
...options.headers,
|
|
588
580
|
},
|
|
589
|
-
};
|
|
590
|
-
console.log("Fetch request:", JSON.stringify({ url: fetchUrl, ...fetchOptions }, null, 2));
|
|
591
|
-
const response = await this.fetchWithCookies(fetchUrl, fetchOptions);
|
|
581
|
+
});
|
|
592
582
|
return response;
|
|
593
583
|
}
|
|
594
584
|
}
|