@browserbasehq/orca 3.1.0-patch.4 → 3.2.0-preview.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/lib/inference.js +1 -4
- package/dist/cjs/lib/inference.js.map +1 -1
- package/dist/cjs/lib/utils.d.ts +1 -0
- package/dist/cjs/lib/utils.js +4 -0
- package/dist/cjs/lib/utils.js.map +1 -1
- package/dist/cjs/lib/v3/agent/AgentProvider.js +0 -1
- package/dist/cjs/lib/v3/agent/AgentProvider.js.map +1 -1
- package/dist/cjs/lib/v3/agent/AnthropicCUAClient.js +4 -6
- package/dist/cjs/lib/v3/agent/AnthropicCUAClient.js.map +1 -1
- package/dist/cjs/lib/v3/agent/GoogleCUAClient.js +4 -6
- package/dist/cjs/lib/v3/agent/GoogleCUAClient.js.map +1 -1
- package/dist/cjs/lib/v3/agent/OpenAICUAClient.js +4 -6
- package/dist/cjs/lib/v3/agent/OpenAICUAClient.js.map +1 -1
- package/dist/cjs/lib/v3/agent/prompts/agentSystemPrompt.d.ts +2 -0
- package/dist/cjs/lib/v3/agent/prompts/agentSystemPrompt.js +2 -2
- package/dist/cjs/lib/v3/agent/prompts/agentSystemPrompt.js.map +1 -1
- package/dist/cjs/lib/v3/agent/tools/act.d.ts +1 -1
- package/dist/cjs/lib/v3/agent/tools/act.js +20 -4
- package/dist/cjs/lib/v3/agent/tools/act.js.map +1 -1
- package/dist/cjs/lib/v3/agent/tools/ariaTree.d.ts +8 -1
- package/dist/cjs/lib/v3/agent/tools/ariaTree.js +60 -22
- package/dist/cjs/lib/v3/agent/tools/ariaTree.js.map +1 -1
- package/dist/cjs/lib/v3/agent/tools/{search.js → braveSearch.js} +1 -1
- package/dist/cjs/lib/v3/agent/tools/braveSearch.js.map +1 -0
- package/dist/cjs/lib/v3/agent/tools/browserbaseSearch.d.ts +13 -0
- package/dist/cjs/lib/v3/agent/tools/browserbaseSearch.js +70 -0
- package/dist/cjs/lib/v3/agent/tools/browserbaseSearch.js.map +1 -0
- package/dist/cjs/lib/v3/agent/tools/click.js +23 -31
- package/dist/cjs/lib/v3/agent/tools/click.js.map +1 -1
- package/dist/cjs/lib/v3/agent/tools/dragAndDrop.js +22 -30
- package/dist/cjs/lib/v3/agent/tools/dragAndDrop.js.map +1 -1
- package/dist/cjs/lib/v3/agent/tools/extract.d.ts +2 -2
- package/dist/cjs/lib/v3/agent/tools/extract.js +16 -3
- package/dist/cjs/lib/v3/agent/tools/extract.js.map +1 -1
- package/dist/cjs/lib/v3/agent/tools/fillFormVision.js +30 -30
- package/dist/cjs/lib/v3/agent/tools/fillFormVision.js.map +1 -1
- package/dist/cjs/lib/v3/agent/tools/fillform.d.ts +7 -1
- package/dist/cjs/lib/v3/agent/tools/fillform.js +60 -37
- package/dist/cjs/lib/v3/agent/tools/fillform.js.map +1 -1
- package/dist/cjs/lib/v3/agent/tools/index.d.ts +19 -3
- package/dist/cjs/lib/v3/agent/tools/index.js +12 -8
- package/dist/cjs/lib/v3/agent/tools/index.js.map +1 -1
- package/dist/cjs/lib/v3/agent/tools/screenshot.d.ts +8 -0
- package/dist/cjs/lib/v3/agent/tools/screenshot.js +32 -15
- package/dist/cjs/lib/v3/agent/tools/screenshot.js.map +1 -1
- package/dist/cjs/lib/v3/agent/tools/scroll.js +12 -0
- package/dist/cjs/lib/v3/agent/tools/scroll.js.map +1 -1
- package/dist/cjs/lib/v3/agent/tools/type.js +23 -31
- package/dist/cjs/lib/v3/agent/tools/type.js.map +1 -1
- package/dist/cjs/lib/v3/agent/tools/wait.js +6 -0
- package/dist/cjs/lib/v3/agent/tools/wait.js.map +1 -1
- package/dist/cjs/lib/v3/agent/utils/handleDoneToolCall.js +4 -0
- package/dist/cjs/lib/v3/agent/utils/handleDoneToolCall.js.map +1 -1
- package/dist/cjs/lib/v3/api.d.ts +2 -2
- package/dist/cjs/lib/v3/api.js +1 -1
- package/dist/cjs/lib/v3/api.js.map +1 -1
- package/dist/cjs/lib/v3/cache/ActCache.d.ts +0 -1
- package/dist/cjs/lib/v3/cache/ActCache.js +2 -18
- package/dist/cjs/lib/v3/cache/ActCache.js.map +1 -1
- package/dist/cjs/lib/v3/eventStore.d.ts +41 -0
- package/dist/cjs/lib/v3/eventStore.js +375 -0
- package/dist/cjs/lib/v3/eventStore.js.map +1 -0
- package/dist/cjs/lib/v3/flowLogger.d.ts +62 -103
- package/dist/cjs/lib/v3/flowLogger.js +362 -773
- package/dist/cjs/lib/v3/flowLogger.js.map +1 -1
- package/dist/cjs/lib/v3/handlers/actHandler.js +1 -2
- package/dist/cjs/lib/v3/handlers/actHandler.js.map +1 -1
- package/dist/cjs/lib/v3/handlers/extractHandler.js +2 -2
- package/dist/cjs/lib/v3/handlers/extractHandler.js.map +1 -1
- package/dist/cjs/lib/v3/handlers/handlerUtils/actHandlerUtils.js +21 -33
- package/dist/cjs/lib/v3/handlers/handlerUtils/actHandlerUtils.js.map +1 -1
- package/dist/cjs/lib/v3/handlers/observeHandler.js +1 -2
- package/dist/cjs/lib/v3/handlers/observeHandler.js.map +1 -1
- package/dist/cjs/lib/v3/handlers/v3AgentHandler.d.ts +0 -4
- package/dist/cjs/lib/v3/handlers/v3AgentHandler.js +23 -48
- package/dist/cjs/lib/v3/handlers/v3AgentHandler.js.map +1 -1
- package/dist/cjs/lib/v3/handlers/v3CuaAgentHandler.js +10 -12
- package/dist/cjs/lib/v3/handlers/v3CuaAgentHandler.js.map +1 -1
- package/dist/cjs/lib/v3/index.d.ts +2 -1
- package/dist/cjs/lib/v3/launch/browserbase.d.ts +1 -1
- package/dist/cjs/lib/v3/launch/browserbase.js +4 -9
- package/dist/cjs/lib/v3/launch/browserbase.js.map +1 -1
- package/dist/cjs/lib/v3/llm/LLMProvider.js +0 -5
- package/dist/cjs/lib/v3/llm/LLMProvider.js.map +1 -1
- package/dist/cjs/lib/v3/llm/aisdk.js +10 -16
- package/dist/cjs/lib/v3/llm/aisdk.js.map +1 -1
- package/dist/cjs/lib/v3/runtimePaths.js +2 -1
- package/dist/cjs/lib/v3/runtimePaths.js.map +1 -1
- package/dist/cjs/lib/v3/shutdown/supervisor.js +2 -2
- package/dist/cjs/lib/v3/shutdown/supervisor.js.map +1 -1
- package/dist/cjs/lib/v3/timeoutConfig.d.ts +1 -1
- package/dist/cjs/lib/v3/timeoutConfig.js +5 -0
- package/dist/cjs/lib/v3/timeoutConfig.js.map +1 -1
- package/dist/cjs/lib/v3/types/private/shutdown.d.ts +1 -1
- package/dist/cjs/lib/v3/types/private/shutdown.js.map +1 -1
- package/dist/cjs/lib/v3/types/public/agent.d.ts +28 -3
- package/dist/cjs/lib/v3/types/public/agent.js +0 -1
- package/dist/cjs/lib/v3/types/public/agent.js.map +1 -1
- package/dist/cjs/lib/v3/types/public/api.d.ts +3 -0
- package/dist/cjs/lib/v3/types/public/api.js +1 -0
- package/dist/cjs/lib/v3/types/public/api.js.map +1 -1
- package/dist/cjs/lib/v3/types/public/model.d.ts +4 -2
- package/dist/cjs/lib/v3/types/public/model.js.map +1 -1
- package/dist/cjs/lib/v3/types/public/options.d.ts +6 -0
- package/dist/cjs/lib/v3/types/public/options.js.map +1 -1
- package/dist/cjs/lib/v3/understudy/cdp.d.ts +8 -13
- package/dist/cjs/lib/v3/understudy/cdp.js +137 -17
- package/dist/cjs/lib/v3/understudy/cdp.js.map +1 -1
- package/dist/cjs/lib/v3/understudy/context.d.ts +1 -0
- package/dist/cjs/lib/v3/understudy/context.js +142 -60
- package/dist/cjs/lib/v3/understudy/context.js.map +1 -1
- package/dist/cjs/lib/v3/understudy/frame.js +23 -6
- package/dist/cjs/lib/v3/understudy/frame.js.map +1 -1
- package/dist/cjs/lib/v3/understudy/page.d.ts +13 -0
- package/dist/cjs/lib/v3/understudy/page.js +88 -20
- package/dist/cjs/lib/v3/understudy/page.js.map +1 -1
- package/dist/cjs/lib/v3/understudy/screenshotUtils.d.ts +0 -1
- package/dist/cjs/lib/v3/understudy/screenshotUtils.js +0 -18
- package/dist/cjs/lib/v3/understudy/screenshotUtils.js.map +1 -1
- package/dist/cjs/lib/v3/v3.d.ts +10 -0
- package/dist/cjs/lib/v3/v3.js +210 -172
- package/dist/cjs/lib/v3/v3.js.map +1 -1
- package/dist/cjs/tests/integration/cdp-session-detached.spec.js +1 -1
- package/dist/cjs/tests/integration/cdp-session-detached.spec.js.map +1 -1
- package/dist/cjs/tests/integration/context-addInitScript.spec.js +104 -11
- package/dist/cjs/tests/integration/context-addInitScript.spec.js.map +1 -1
- package/dist/cjs/tests/integration/iframe-ctx-addInitScript-race.spec.js +219 -0
- package/dist/cjs/tests/integration/iframe-ctx-addInitScript-race.spec.js.map +1 -0
- package/dist/cjs/tests/integration/page-extra-http-headers.spec.js +85 -0
- package/dist/cjs/tests/integration/page-extra-http-headers.spec.js.map +1 -0
- package/dist/cjs/tests/integration/page-screenshot.spec.js +1 -1
- package/dist/cjs/tests/integration/page-screenshot.spec.js.map +1 -1
- package/dist/cjs/tests/integration/timeouts.spec.js +168 -0
- package/dist/cjs/tests/integration/timeouts.spec.js.map +1 -1
- package/dist/cjs/tests/unit/model-deprecation.test.js +5 -8
- package/dist/cjs/tests/unit/model-deprecation.test.js.map +1 -1
- package/dist/cjs/tests/unit/page-extra-http-headers.test.d.ts +1 -0
- package/dist/cjs/tests/unit/page-extra-http-headers.test.js +92 -0
- package/dist/cjs/tests/unit/page-extra-http-headers.test.js.map +1 -0
- package/dist/cjs/tests/unit/public-api/llm-and-agents.test.js +13 -1
- package/dist/cjs/tests/unit/public-api/llm-and-agents.test.js.map +1 -1
- package/dist/cjs/tests/unit/public-api/public-types.test.js.map +1 -1
- package/dist/esm/lib/inference.js +1 -4
- package/dist/esm/lib/inference.js.map +1 -1
- package/dist/esm/lib/utils.d.ts +1 -0
- package/dist/esm/lib/utils.js +3 -0
- package/dist/esm/lib/utils.js.map +1 -1
- package/dist/esm/lib/v3/agent/AgentProvider.js +0 -1
- package/dist/esm/lib/v3/agent/AgentProvider.js.map +1 -1
- package/dist/esm/lib/v3/agent/AnthropicCUAClient.js +5 -7
- package/dist/esm/lib/v3/agent/AnthropicCUAClient.js.map +1 -1
- package/dist/esm/lib/v3/agent/GoogleCUAClient.js +5 -7
- package/dist/esm/lib/v3/agent/GoogleCUAClient.js.map +1 -1
- package/dist/esm/lib/v3/agent/OpenAICUAClient.js +5 -7
- package/dist/esm/lib/v3/agent/OpenAICUAClient.js.map +1 -1
- package/dist/esm/lib/v3/agent/prompts/agentSystemPrompt.d.ts +2 -0
- package/dist/esm/lib/v3/agent/prompts/agentSystemPrompt.js +2 -2
- package/dist/esm/lib/v3/agent/prompts/agentSystemPrompt.js.map +1 -1
- package/dist/esm/lib/v3/agent/tools/act.d.ts +1 -1
- package/dist/esm/lib/v3/agent/tools/act.js +20 -4
- package/dist/esm/lib/v3/agent/tools/act.js.map +1 -1
- package/dist/esm/lib/v3/agent/tools/ariaTree.d.ts +8 -1
- package/dist/esm/lib/v3/agent/tools/ariaTree.js +60 -22
- package/dist/esm/lib/v3/agent/tools/ariaTree.js.map +1 -1
- package/dist/esm/lib/v3/agent/tools/{search.js → braveSearch.js} +1 -1
- package/dist/esm/lib/v3/agent/tools/braveSearch.js.map +1 -0
- package/dist/esm/lib/v3/agent/tools/browserbaseSearch.d.ts +13 -0
- package/dist/esm/lib/v3/agent/tools/browserbaseSearch.js +66 -0
- package/dist/esm/lib/v3/agent/tools/browserbaseSearch.js.map +1 -0
- package/dist/esm/lib/v3/agent/tools/click.js +23 -31
- package/dist/esm/lib/v3/agent/tools/click.js.map +1 -1
- package/dist/esm/lib/v3/agent/tools/dragAndDrop.js +22 -30
- package/dist/esm/lib/v3/agent/tools/dragAndDrop.js.map +1 -1
- package/dist/esm/lib/v3/agent/tools/extract.d.ts +2 -2
- package/dist/esm/lib/v3/agent/tools/extract.js +16 -3
- package/dist/esm/lib/v3/agent/tools/extract.js.map +1 -1
- package/dist/esm/lib/v3/agent/tools/fillFormVision.js +30 -30
- package/dist/esm/lib/v3/agent/tools/fillFormVision.js.map +1 -1
- package/dist/esm/lib/v3/agent/tools/fillform.d.ts +7 -1
- package/dist/esm/lib/v3/agent/tools/fillform.js +60 -37
- package/dist/esm/lib/v3/agent/tools/fillform.js.map +1 -1
- package/dist/esm/lib/v3/agent/tools/index.d.ts +19 -3
- package/dist/esm/lib/v3/agent/tools/index.js +12 -8
- package/dist/esm/lib/v3/agent/tools/index.js.map +1 -1
- package/dist/esm/lib/v3/agent/tools/screenshot.d.ts +8 -0
- package/dist/esm/lib/v3/agent/tools/screenshot.js +32 -15
- package/dist/esm/lib/v3/agent/tools/screenshot.js.map +1 -1
- package/dist/esm/lib/v3/agent/tools/scroll.js +12 -0
- package/dist/esm/lib/v3/agent/tools/scroll.js.map +1 -1
- package/dist/esm/lib/v3/agent/tools/type.js +23 -31
- package/dist/esm/lib/v3/agent/tools/type.js.map +1 -1
- package/dist/esm/lib/v3/agent/tools/wait.js +6 -0
- package/dist/esm/lib/v3/agent/tools/wait.js.map +1 -1
- package/dist/esm/lib/v3/agent/utils/handleDoneToolCall.js +4 -0
- package/dist/esm/lib/v3/agent/utils/handleDoneToolCall.js.map +1 -1
- package/dist/esm/lib/v3/api.d.ts +2 -2
- package/dist/esm/lib/v3/api.js +1 -1
- package/dist/esm/lib/v3/api.js.map +1 -1
- package/dist/esm/lib/v3/cache/ActCache.d.ts +0 -1
- package/dist/esm/lib/v3/cache/ActCache.js +2 -18
- package/dist/esm/lib/v3/cache/ActCache.js.map +1 -1
- package/dist/esm/lib/v3/eventStore.d.ts +41 -0
- package/dist/esm/lib/v3/eventStore.js +363 -0
- package/dist/esm/lib/v3/eventStore.js.map +1 -0
- package/dist/esm/lib/v3/flowLogger.d.ts +62 -103
- package/dist/esm/lib/v3/flowLogger.js +356 -762
- package/dist/esm/lib/v3/flowLogger.js.map +1 -1
- package/dist/esm/lib/v3/handlers/actHandler.js +1 -2
- package/dist/esm/lib/v3/handlers/actHandler.js.map +1 -1
- package/dist/esm/lib/v3/handlers/extractHandler.js +2 -2
- package/dist/esm/lib/v3/handlers/extractHandler.js.map +1 -1
- package/dist/esm/lib/v3/handlers/handlerUtils/actHandlerUtils.js +22 -34
- package/dist/esm/lib/v3/handlers/handlerUtils/actHandlerUtils.js.map +1 -1
- package/dist/esm/lib/v3/handlers/observeHandler.js +1 -2
- package/dist/esm/lib/v3/handlers/observeHandler.js.map +1 -1
- package/dist/esm/lib/v3/handlers/v3AgentHandler.d.ts +0 -4
- package/dist/esm/lib/v3/handlers/v3AgentHandler.js +25 -50
- package/dist/esm/lib/v3/handlers/v3AgentHandler.js.map +1 -1
- package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.js +11 -13
- package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.js.map +1 -1
- package/dist/esm/lib/v3/index.d.ts +2 -1
- package/dist/esm/lib/v3/launch/browserbase.d.ts +1 -1
- package/dist/esm/lib/v3/launch/browserbase.js +4 -9
- package/dist/esm/lib/v3/launch/browserbase.js.map +1 -1
- package/dist/esm/lib/v3/llm/LLMProvider.js +0 -5
- package/dist/esm/lib/v3/llm/LLMProvider.js.map +1 -1
- package/dist/esm/lib/v3/llm/aisdk.js +11 -17
- package/dist/esm/lib/v3/llm/aisdk.js.map +1 -1
- package/dist/esm/lib/v3/runtimePaths.js +2 -1
- package/dist/esm/lib/v3/runtimePaths.js.map +1 -1
- package/dist/esm/lib/v3/shutdown/supervisor.js +2 -2
- package/dist/esm/lib/v3/shutdown/supervisor.js.map +1 -1
- package/dist/esm/lib/v3/timeoutConfig.d.ts +1 -1
- package/dist/esm/lib/v3/timeoutConfig.js +5 -0
- package/dist/esm/lib/v3/timeoutConfig.js.map +1 -1
- package/dist/esm/lib/v3/types/private/shutdown.d.ts +1 -1
- package/dist/esm/lib/v3/types/private/shutdown.js.map +1 -1
- package/dist/esm/lib/v3/types/public/agent.d.ts +28 -3
- package/dist/esm/lib/v3/types/public/agent.js +0 -1
- package/dist/esm/lib/v3/types/public/agent.js.map +1 -1
- package/dist/esm/lib/v3/types/public/api.d.ts +3 -0
- package/dist/esm/lib/v3/types/public/api.js +1 -0
- package/dist/esm/lib/v3/types/public/api.js.map +1 -1
- package/dist/esm/lib/v3/types/public/model.d.ts +4 -2
- package/dist/esm/lib/v3/types/public/model.js.map +1 -1
- package/dist/esm/lib/v3/types/public/options.d.ts +6 -0
- package/dist/esm/lib/v3/types/public/options.js.map +1 -1
- package/dist/esm/lib/v3/understudy/cdp.d.ts +8 -13
- package/dist/esm/lib/v3/understudy/cdp.js +138 -18
- package/dist/esm/lib/v3/understudy/cdp.js.map +1 -1
- package/dist/esm/lib/v3/understudy/context.d.ts +1 -0
- package/dist/esm/lib/v3/understudy/context.js +142 -60
- package/dist/esm/lib/v3/understudy/context.js.map +1 -1
- package/dist/esm/lib/v3/understudy/frame.js +23 -6
- package/dist/esm/lib/v3/understudy/frame.js.map +1 -1
- package/dist/esm/lib/v3/understudy/page.d.ts +13 -0
- package/dist/esm/lib/v3/understudy/page.js +91 -23
- package/dist/esm/lib/v3/understudy/page.js.map +1 -1
- package/dist/esm/lib/v3/understudy/screenshotUtils.d.ts +0 -1
- package/dist/esm/lib/v3/understudy/screenshotUtils.js +0 -17
- package/dist/esm/lib/v3/understudy/screenshotUtils.js.map +1 -1
- package/dist/esm/lib/v3/v3.d.ts +10 -0
- package/dist/esm/lib/v3/v3.js +211 -173
- package/dist/esm/lib/v3/v3.js.map +1 -1
- package/dist/esm/tests/integration/cdp-session-detached.spec.js +1 -1
- package/dist/esm/tests/integration/cdp-session-detached.spec.js.map +1 -1
- package/dist/esm/tests/integration/context-addInitScript.spec.js +104 -11
- package/dist/esm/tests/integration/context-addInitScript.spec.js.map +1 -1
- package/dist/esm/tests/integration/iframe-ctx-addInitScript-race.spec.d.ts +1 -0
- package/dist/esm/tests/integration/iframe-ctx-addInitScript-race.spec.js +217 -0
- package/dist/esm/tests/integration/iframe-ctx-addInitScript-race.spec.js.map +1 -0
- package/dist/esm/tests/integration/page-extra-http-headers.spec.d.ts +1 -0
- package/dist/esm/tests/integration/page-extra-http-headers.spec.js +83 -0
- package/dist/esm/tests/integration/page-extra-http-headers.spec.js.map +1 -0
- package/dist/esm/tests/integration/page-screenshot.spec.js +1 -1
- package/dist/esm/tests/integration/page-screenshot.spec.js.map +1 -1
- package/dist/esm/tests/integration/timeouts.spec.js +168 -0
- package/dist/esm/tests/integration/timeouts.spec.js.map +1 -1
- package/dist/esm/tests/unit/model-deprecation.test.js +5 -8
- package/dist/esm/tests/unit/model-deprecation.test.js.map +1 -1
- package/dist/esm/tests/unit/page-extra-http-headers.test.d.ts +1 -0
- package/dist/esm/tests/unit/page-extra-http-headers.test.js +90 -0
- package/dist/esm/tests/unit/page-extra-http-headers.test.js.map +1 -0
- package/dist/esm/tests/unit/public-api/llm-and-agents.test.js +13 -1
- package/dist/esm/tests/unit/public-api/llm-and-agents.test.js.map +1 -1
- package/dist/esm/tests/unit/public-api/public-types.test.js.map +1 -1
- package/package.json +2 -2
- package/dist/cjs/lib/v3/agent/tools/search.js.map +0 -1
- package/dist/cjs/tests/unit/rerender-missing-shadows.test.js +0 -209
- package/dist/cjs/tests/unit/rerender-missing-shadows.test.js.map +0 -1
- package/dist/esm/lib/v3/agent/tools/search.js.map +0 -1
- package/dist/esm/tests/unit/rerender-missing-shadows.test.js +0 -207
- package/dist/esm/tests/unit/rerender-missing-shadows.test.js.map +0 -1
- /package/dist/cjs/lib/v3/agent/tools/{search.d.ts → braveSearch.d.ts} +0 -0
- /package/dist/cjs/tests/{unit/rerender-missing-shadows.test.d.ts → integration/iframe-ctx-addInitScript-race.spec.d.ts} +0 -0
- /package/dist/{esm/tests/unit/rerender-missing-shadows.test.d.ts → cjs/tests/integration/page-extra-http-headers.spec.d.ts} +0 -0
- /package/dist/esm/lib/v3/agent/tools/{search.d.ts → braveSearch.d.ts} +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { tool } from "ai";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
|
|
3
|
+
import { TimeoutError } from "../../types/public/sdkErrors.js";
|
|
4
|
+
export const fillFormTool = (v3, executionModel, variables, toolTimeout) => {
|
|
4
5
|
const hasVariables = variables && Object.keys(variables).length > 0;
|
|
5
6
|
const valueDescription = hasVariables
|
|
6
7
|
? `Text to type into the target. Use %variableName% to substitute a variable value. Available: ${Object.keys(variables).join(", ")}`
|
|
@@ -18,45 +19,67 @@ export const fillFormTool = (v3, executionModel, variables) => {
|
|
|
18
19
|
.min(1, "Provide at least one field to fill"),
|
|
19
20
|
}),
|
|
20
21
|
execute: async ({ fields }) => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
try {
|
|
23
|
+
v3.logger({
|
|
24
|
+
category: "agent",
|
|
25
|
+
message: `Agent calling tool: fillForm`,
|
|
26
|
+
level: 1,
|
|
27
|
+
auxiliary: {
|
|
28
|
+
arguments: {
|
|
29
|
+
value: JSON.stringify(fields),
|
|
30
|
+
type: "object",
|
|
31
|
+
},
|
|
29
32
|
},
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
33
|
+
});
|
|
34
|
+
const instruction = `Return observation results for the following actions: ${fields
|
|
35
|
+
.map((f) => f.action)
|
|
36
|
+
.join(", ")}`;
|
|
37
|
+
const observeOptions = executionModel
|
|
38
|
+
? { model: executionModel, timeout: toolTimeout }
|
|
39
|
+
: { timeout: toolTimeout };
|
|
40
|
+
const observeResults = await v3.observe(instruction, observeOptions);
|
|
41
|
+
const completed = [];
|
|
42
|
+
const replayableActions = [];
|
|
43
|
+
for (const res of observeResults) {
|
|
44
|
+
const actOptions = variables
|
|
45
|
+
? { variables, timeout: toolTimeout }
|
|
46
|
+
: { timeout: toolTimeout };
|
|
47
|
+
const actResult = await v3.act(res, actOptions);
|
|
48
|
+
completed.push(actResult);
|
|
49
|
+
if (Array.isArray(actResult.actions)) {
|
|
50
|
+
replayableActions.push(...actResult.actions);
|
|
51
|
+
}
|
|
47
52
|
}
|
|
53
|
+
v3.recordAgentReplayStep({
|
|
54
|
+
type: "fillForm",
|
|
55
|
+
fields,
|
|
56
|
+
observeResults,
|
|
57
|
+
actions: replayableActions,
|
|
58
|
+
});
|
|
59
|
+
return {
|
|
60
|
+
success: true,
|
|
61
|
+
actions: completed,
|
|
62
|
+
playwrightArguments: replayableActions,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
if (error instanceof TimeoutError) {
|
|
67
|
+
const timeoutMessage = `TimeoutError while waiting for fillForm() to complete (it may continue executing in the background)`;
|
|
68
|
+
v3.logger({
|
|
69
|
+
category: "agent",
|
|
70
|
+
message: timeoutMessage,
|
|
71
|
+
level: 0,
|
|
72
|
+
});
|
|
73
|
+
return {
|
|
74
|
+
success: false,
|
|
75
|
+
error: `${timeoutMessage} — try filling fewer fields at once or use a different tool`,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
success: false,
|
|
80
|
+
error: error?.message ?? String(error),
|
|
81
|
+
};
|
|
48
82
|
}
|
|
49
|
-
v3.recordAgentReplayStep({
|
|
50
|
-
type: "fillForm",
|
|
51
|
-
fields,
|
|
52
|
-
observeResults,
|
|
53
|
-
actions: replayableActions,
|
|
54
|
-
});
|
|
55
|
-
return {
|
|
56
|
-
success: true,
|
|
57
|
-
actions: completed,
|
|
58
|
-
playwrightArguments: replayableActions,
|
|
59
|
-
};
|
|
60
83
|
},
|
|
61
84
|
});
|
|
62
85
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fillform.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/tools/fillform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,E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cAAc;oBACd,OAAO,EAAE,iBAAiB;iBAC3B,CAAC,CAAC;gBACH,OAAO;oBACL,OAAO,EAAE,IAAI;oBACb,OAAO,EAAE,SAAS;oBAClB,mBAAmB,EAAE,iBAAiB;iBACvC,CAAC;YACJ,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,KAAK,YAAY,YAAY,EAAE,CAAC;oBAClC,MAAM,cAAc,GAAG,qGAAqG,CAAC;oBAC7H,EAAE,CAAC,MAAM,CAAC;wBACR,QAAQ,EAAE,OAAO;wBACjB,OAAO,EAAE,cAAc;wBACvB,KAAK,EAAE,CAAC;qBACT,CAAC,CAAC;oBACH,OAAO;wBACL,OAAO,EAAE,KAAK;wBACd,KAAK,EAAE,GAAG,cAAc,6DAA6D;qBACtF,CAAC;gBACJ,CAAC;gBACD,OAAO;oBACL,OAAO,EAAE,KAAK;oBACd,KAAK,EAAE,KAAK,EAAE,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC;iBACvC,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["import { tool } from \"ai\";\nimport { z } from \"zod\";\nimport type { V3 } from \"../../v3.js\";\nimport type { Action } from \"../../types/public/methods.js\";\nimport type { AgentModelConfig, Variables } from \"../../types/public/agent.js\";\nimport { TimeoutError } from \"../../types/public/sdkErrors.js\";\n\nexport const fillFormTool = (\n v3: V3,\n executionModel?: string | AgentModelConfig,\n variables?: Variables,\n toolTimeout?: number,\n) => {\n const hasVariables = variables && Object.keys(variables).length > 0;\n const valueDescription = hasVariables\n ? `Text to type into the target. Use %variableName% to substitute a variable value. Available: ${Object.keys(variables).join(\", \")}`\n : \"Text to type into the target\";\n\n return tool({\n description: `📝 FORM FILL - MULTI-FIELD INPUT TOOL\\nFor any form with 2+ inputs/textareas. Faster than individual typing.`,\n inputSchema: z.object({\n fields: z\n .array(\n z.object({\n action: z\n .string()\n .describe(\n 'Description of typing action, e.g. \"type foo into the email field\"',\n ),\n value: z.string().describe(valueDescription),\n }),\n )\n .min(1, \"Provide at least one field to fill\"),\n }),\n execute: async ({ fields }) => {\n try {\n v3.logger({\n category: \"agent\",\n message: `Agent calling tool: fillForm`,\n level: 1,\n auxiliary: {\n arguments: {\n value: JSON.stringify(fields),\n type: \"object\",\n },\n },\n });\n const instruction = `Return observation results for the following actions: ${fields\n .map((f) => f.action)\n .join(\", \")}`;\n\n const observeOptions = executionModel\n ? { model: executionModel, timeout: toolTimeout }\n : { timeout: toolTimeout };\n const observeResults = await v3.observe(instruction, observeOptions);\n\n const completed = [] as unknown[];\n const replayableActions: Action[] = [];\n for (const res of observeResults) {\n const actOptions = variables\n ? { variables, timeout: toolTimeout }\n : { timeout: toolTimeout };\n const actResult = await v3.act(res, actOptions);\n completed.push(actResult);\n if (Array.isArray(actResult.actions)) {\n replayableActions.push(...(actResult.actions as Action[]));\n }\n }\n v3.recordAgentReplayStep({\n type: \"fillForm\",\n fields,\n observeResults,\n actions: replayableActions,\n });\n return {\n success: true,\n actions: completed,\n playwrightArguments: replayableActions,\n };\n } catch (error) {\n if (error instanceof TimeoutError) {\n const timeoutMessage = `TimeoutError while waiting for fillForm() to complete (it may continue executing in the background)`;\n v3.logger({\n category: \"agent\",\n message: timeoutMessage,\n level: 0,\n });\n return {\n success: false,\n error: `${timeoutMessage} — try filling fewer fields at once or use a different tool`,\n };\n }\n return {\n success: false,\n error: error?.message ?? String(error),\n };\n }\n },\n });\n};\n"]}
|
|
@@ -14,7 +14,8 @@ import { clickAndHoldTool } from "./clickAndHold.js";
|
|
|
14
14
|
import { keysTool } from "./keys.js";
|
|
15
15
|
import { fillFormVisionTool } from "./fillFormVision.js";
|
|
16
16
|
import { thinkTool } from "./think.js";
|
|
17
|
-
import { searchTool } from "./
|
|
17
|
+
import { searchTool as browserbaseSearchTool } from "./browserbaseSearch.js";
|
|
18
|
+
import { searchTool as braveSearchTool } from "./braveSearch.js";
|
|
18
19
|
import type { ToolSet, InferUITools } from "ai";
|
|
19
20
|
import type { V3 } from "../../v3.js";
|
|
20
21
|
import type { LogLine } from "../../types/public/logs.js";
|
|
@@ -42,12 +43,27 @@ export interface V3AgentToolOptions {
|
|
|
42
43
|
* When provided, these tools will have an optional useVariable field.
|
|
43
44
|
*/
|
|
44
45
|
variables?: Variables;
|
|
46
|
+
/**
|
|
47
|
+
* Timeout in milliseconds for tool calls that invoke v3 methods (act, extract, fillForm, ariaTree).
|
|
48
|
+
* Forwarded to the underlying v3 call's `timeout` option.
|
|
49
|
+
*/
|
|
50
|
+
toolTimeout?: number;
|
|
51
|
+
/**
|
|
52
|
+
* Whether to enable the Browserbase-powered web search tool.
|
|
53
|
+
* Requires a valid Browserbase API key.
|
|
54
|
+
*/
|
|
55
|
+
useSearch?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* The Browserbase API key used for the search tool.
|
|
58
|
+
* Resolved from BROWSERBASE_API_KEY env var or the Stagehand constructor.
|
|
59
|
+
*/
|
|
60
|
+
browserbaseApiKey?: string;
|
|
45
61
|
}
|
|
46
62
|
export declare function createAgentTools(v3: V3, options?: V3AgentToolOptions): ToolSet;
|
|
47
63
|
export type AgentTools = ReturnType<typeof createAgentTools>;
|
|
48
64
|
/**
|
|
49
65
|
* Type map of all agent tools for strong typing of tool calls and results.
|
|
50
|
-
* Note: `search` is optional
|
|
66
|
+
* Note: `search` is optional — enabled via useSearch: true (Browserbase) or BRAVE_API_KEY env var (legacy).
|
|
51
67
|
*/
|
|
52
68
|
export type AgentToolTypesMap = {
|
|
53
69
|
act: ReturnType<typeof actTool>;
|
|
@@ -63,7 +79,7 @@ export type AgentToolTypesMap = {
|
|
|
63
79
|
navback: ReturnType<typeof navBackTool>;
|
|
64
80
|
screenshot: ReturnType<typeof screenshotTool>;
|
|
65
81
|
scroll: ReturnType<typeof scrollTool> | ReturnType<typeof scrollVisionTool>;
|
|
66
|
-
search?: ReturnType<typeof
|
|
82
|
+
search?: ReturnType<typeof browserbaseSearchTool> | ReturnType<typeof braveSearchTool>;
|
|
67
83
|
think: ReturnType<typeof thinkTool>;
|
|
68
84
|
type: ReturnType<typeof typeTool>;
|
|
69
85
|
wait: ReturnType<typeof waitTool>;
|
|
@@ -14,7 +14,8 @@ import { clickAndHoldTool } from "./clickAndHold.js";
|
|
|
14
14
|
import { keysTool } from "./keys.js";
|
|
15
15
|
import { fillFormVisionTool } from "./fillFormVision.js";
|
|
16
16
|
import { thinkTool } from "./think.js";
|
|
17
|
-
import { searchTool } from "./
|
|
17
|
+
import { searchTool as browserbaseSearchTool } from "./browserbaseSearch.js";
|
|
18
|
+
import { searchTool as braveSearchTool } from "./braveSearch.js";
|
|
18
19
|
/**
|
|
19
20
|
* Filters tools based on mode and explicit exclusions.
|
|
20
21
|
* - 'dom' mode: Removes coordinate-based tools (click, type, dragAndDrop, clickAndHold, fillFormVision)
|
|
@@ -48,14 +49,15 @@ export function createAgentTools(v3, options) {
|
|
|
48
49
|
const provider = options?.provider;
|
|
49
50
|
const excludeTools = options?.excludeTools;
|
|
50
51
|
const variables = options?.variables;
|
|
52
|
+
const toolTimeout = options?.toolTimeout;
|
|
51
53
|
const allTools = {
|
|
52
|
-
act: actTool(v3, executionModel, variables),
|
|
53
|
-
ariaTree: ariaTreeTool(v3),
|
|
54
|
+
act: actTool(v3, executionModel, variables, toolTimeout),
|
|
55
|
+
ariaTree: ariaTreeTool(v3, toolTimeout),
|
|
54
56
|
click: clickTool(v3, provider),
|
|
55
57
|
clickAndHold: clickAndHoldTool(v3, provider),
|
|
56
58
|
dragAndDrop: dragAndDropTool(v3, provider),
|
|
57
|
-
extract: extractTool(v3, executionModel),
|
|
58
|
-
fillForm: fillFormTool(v3, executionModel, variables),
|
|
59
|
+
extract: extractTool(v3, executionModel, toolTimeout),
|
|
60
|
+
fillForm: fillFormTool(v3, executionModel, variables, toolTimeout),
|
|
59
61
|
fillFormVision: fillFormVisionTool(v3, provider, variables),
|
|
60
62
|
goto: gotoTool(v3),
|
|
61
63
|
keys: keysTool(v3),
|
|
@@ -66,9 +68,11 @@ export function createAgentTools(v3, options) {
|
|
|
66
68
|
type: typeTool(v3, provider, variables),
|
|
67
69
|
wait: waitTool(v3, mode),
|
|
68
70
|
};
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
if (options?.useSearch && options.browserbaseApiKey) {
|
|
72
|
+
allTools.search = browserbaseSearchTool(v3, options.browserbaseApiKey);
|
|
73
|
+
}
|
|
74
|
+
else if (process.env.BRAVE_API_KEY) {
|
|
75
|
+
allTools.search = braveSearchTool(v3);
|
|
72
76
|
}
|
|
73
77
|
return filterTools(allTools, mode, excludeTools);
|
|
74
78
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAA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,EAAE,QAAQ,CAAC;QAC1C,OAAO,EAAE,WAAW,CAAC,EAAE,EAAE,cAAc,EAAE,WAAW,CAAC;QACrD,QAAQ,EAAE,YAAY,CAAC,EAAE,EAAE,cAAc,EAAE,SAAS,EAAE,WAAW,CAAC;QAClE,cAAc,EAAE,kBAAkB,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,CAAC;QAC3D,IAAI,EAAE,QAAQ,CAAC,EAAE,CAAC;QAClB,IAAI,EAAE,QAAQ,CAAC,EAAE,CAAC;QAClB,OAAO,EAAE,WAAW,CAAC,EAAE,CAAC;QACxB,UAAU,EAAE,cAAc,CAAC,EAAE,CAAC;QAC9B,MAAM,EAAE,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,gBAAgB,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,EAAE,CAAC;QAC3E,KAAK,EAAE,SAAS,EAAE;QAClB,IAAI,EAAE,QAAQ,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,CAAC;QACvC,IAAI,EAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;KACzB,CAAC;IAEF,IAAI,OAAO,EAAE,SAAS,IAAI,OAAO,CAAC,iBAAiB,EAAE,CAAC;QACpD,QAAQ,CAAC,MAAM,GAAG,qBAAqB,CAAC,EAAE,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACzE,CAAC;SAAM,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC;QACrC,QAAQ,CAAC,MAAM,GAAG,eAAe,CAAC,EAAE,CAAC,CAAC;IACxC,CAAC;IAED,OAAO,WAAW,CAAC,QAAQ,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;AACnD,CAAC","sourcesContent":["import { gotoTool } from \"./goto.js\";\nimport { actTool } from \"./act.js\";\nimport { screenshotTool } from \"./screenshot.js\";\nimport { waitTool } from \"./wait.js\";\nimport { navBackTool } from \"./navback.js\";\nimport { ariaTreeTool } from \"./ariaTree.js\";\nimport { fillFormTool } from \"./fillform.js\";\nimport { scrollTool, scrollVisionTool } from \"./scroll.js\";\nimport { extractTool } from \"./extract.js\";\nimport { clickTool } from \"./click.js\";\nimport { typeTool } from \"./type.js\";\nimport { dragAndDropTool } from \"./dragAndDrop.js\";\nimport { clickAndHoldTool } from \"./clickAndHold.js\";\nimport { keysTool } from \"./keys.js\";\nimport { fillFormVisionTool } from \"./fillFormVision.js\";\nimport { thinkTool } from \"./think.js\";\nimport { searchTool as browserbaseSearchTool } from \"./browserbaseSearch.js\";\nimport { searchTool as braveSearchTool } from \"./braveSearch.js\";\n\nimport type { ToolSet, InferUITools } from \"ai\";\nimport type { V3 } from \"../../v3.js\";\nimport type { LogLine } from \"../../types/public/logs.js\";\nimport type {\n AgentToolMode,\n AgentModelConfig,\n Variables,\n} from \"../../types/public/agent.js\";\n\nexport interface V3AgentToolOptions {\n executionModel?: string | AgentModelConfig;\n logger?: (message: LogLine) => void;\n /**\n * Tool mode determines which set of tools are available.\n * - 'dom' (default): Uses DOM-based tools (act, fillForm) - removes coordinate-based tools\n * - 'hybrid': Uses coordinate-based tools (click, type, dragAndDrop, etc.) - removes fillForm\n */\n mode?: AgentToolMode;\n /**\n * The model provider. Used for model-specific coordinate handling\n */\n provider?: string;\n /**\n * Tools to exclude from the available toolset.\n * These tools will be filtered out after mode-based filtering.\n */\n excludeTools?: string[];\n /**\n * Variables available to the agent for use in act/type tools.\n * When provided, these tools will have an optional useVariable field.\n */\n variables?: Variables;\n /**\n * Timeout in milliseconds for tool calls that invoke v3 methods (act, extract, fillForm, ariaTree).\n * Forwarded to the underlying v3 call's `timeout` option.\n */\n toolTimeout?: number;\n /**\n * Whether to enable the Browserbase-powered web search tool.\n * Requires a valid Browserbase API key.\n */\n useSearch?: boolean;\n /**\n * The Browserbase API key used for the search tool.\n * Resolved from BROWSERBASE_API_KEY env var or the Stagehand constructor.\n */\n browserbaseApiKey?: string;\n}\n\n/**\n * Filters tools based on mode and explicit exclusions.\n * - 'dom' mode: Removes coordinate-based tools (click, type, dragAndDrop, clickAndHold, fillFormVision)\n * - 'hybrid' mode: Removes DOM-based form tool (fillForm) in favor of coordinate-based fillFormVision\n * - excludeTools: Additional tools to remove from the toolset\n */\nfunction filterTools(\n tools: ToolSet,\n mode: AgentToolMode,\n excludeTools?: string[],\n): ToolSet {\n const filtered: ToolSet = { ...tools };\n\n // Mode-based filtering\n if (mode === \"hybrid\") {\n delete filtered.fillForm;\n } else {\n // DOM mode (default)\n delete filtered.click;\n delete filtered.type;\n delete filtered.dragAndDrop;\n delete filtered.clickAndHold;\n delete filtered.fillFormVision;\n }\n\n if (excludeTools) {\n for (const toolName of excludeTools) {\n delete filtered[toolName];\n }\n }\n\n return filtered;\n}\n\nexport function createAgentTools(v3: V3, options?: V3AgentToolOptions) {\n const executionModel = options?.executionModel;\n const mode = options?.mode ?? \"dom\";\n const provider = options?.provider;\n const excludeTools = options?.excludeTools;\n const variables = options?.variables;\n const toolTimeout = options?.toolTimeout;\n\n const allTools: ToolSet = {\n act: actTool(v3, executionModel, variables, toolTimeout),\n ariaTree: ariaTreeTool(v3, toolTimeout),\n click: clickTool(v3, provider),\n clickAndHold: clickAndHoldTool(v3, provider),\n dragAndDrop: dragAndDropTool(v3, provider),\n extract: extractTool(v3, executionModel, toolTimeout),\n fillForm: fillFormTool(v3, executionModel, variables, toolTimeout),\n fillFormVision: fillFormVisionTool(v3, provider, variables),\n goto: gotoTool(v3),\n keys: keysTool(v3),\n navback: navBackTool(v3),\n screenshot: screenshotTool(v3),\n scroll: mode === \"hybrid\" ? scrollVisionTool(v3, provider) : scrollTool(v3),\n think: thinkTool(),\n type: typeTool(v3, provider, variables),\n wait: waitTool(v3, mode),\n };\n\n if (options?.useSearch && options.browserbaseApiKey) {\n allTools.search = browserbaseSearchTool(v3, options.browserbaseApiKey);\n } else if (process.env.BRAVE_API_KEY) {\n allTools.search = braveSearchTool(v3);\n }\n\n return filterTools(allTools, mode, excludeTools);\n}\n\nexport type AgentTools = ReturnType<typeof createAgentTools>;\n\n/**\n * Type map of all agent tools for strong typing of tool calls and results.\n * Note: `search` is optional — enabled via useSearch: true (Browserbase) or BRAVE_API_KEY env var (legacy).\n */\nexport type AgentToolTypesMap = {\n act: ReturnType<typeof actTool>;\n ariaTree: ReturnType<typeof ariaTreeTool>;\n click: ReturnType<typeof clickTool>;\n clickAndHold: ReturnType<typeof clickAndHoldTool>;\n dragAndDrop: ReturnType<typeof dragAndDropTool>;\n extract: ReturnType<typeof extractTool>;\n fillForm: ReturnType<typeof fillFormTool>;\n fillFormVision: ReturnType<typeof fillFormVisionTool>;\n goto: ReturnType<typeof gotoTool>;\n keys: ReturnType<typeof keysTool>;\n navback: ReturnType<typeof navBackTool>;\n screenshot: ReturnType<typeof screenshotTool>;\n scroll: ReturnType<typeof scrollTool> | ReturnType<typeof scrollVisionTool>;\n search?:\n | ReturnType<typeof browserbaseSearchTool>\n | ReturnType<typeof braveSearchTool>;\n think: ReturnType<typeof thinkTool>;\n type: ReturnType<typeof typeTool>;\n wait: ReturnType<typeof waitTool>;\n};\n\n/**\n * Inferred UI tools type for type-safe tool inputs and outputs.\n * Use with UIMessage for full type safety in UI contexts.\n */\nexport type AgentUITools = InferUITools<AgentToolTypesMap>;\n\n/**\n * Union type for all possible agent tool calls.\n * Provides type-safe access to tool call arguments.\n */\nexport type AgentToolCall = {\n [K in keyof AgentToolTypesMap]: {\n toolName: K;\n toolCallId: string;\n args: AgentUITools[K][\"input\"];\n };\n}[keyof AgentToolTypesMap];\n\n/**\n * Union type for all possible agent tool results.\n * Provides type-safe access to tool result values.\n */\nexport type AgentToolResult = {\n [K in keyof AgentToolTypesMap]: {\n toolName: K;\n toolCallId: string;\n result: AgentUITools[K][\"output\"];\n };\n}[keyof AgentToolTypesMap];\n"]}
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import type { V3 } from "../../v3.js";
|
|
2
2
|
export declare const screenshotTool: (v3: V3) => import("ai").Tool<Record<string, never>, {
|
|
3
|
+
success: boolean;
|
|
3
4
|
base64: string;
|
|
4
5
|
timestamp: number;
|
|
5
6
|
pageUrl: string;
|
|
7
|
+
error?: undefined;
|
|
8
|
+
} | {
|
|
9
|
+
success: boolean;
|
|
10
|
+
error: string;
|
|
11
|
+
base64?: undefined;
|
|
12
|
+
timestamp?: undefined;
|
|
13
|
+
pageUrl?: undefined;
|
|
6
14
|
}>;
|
|
@@ -4,23 +4,40 @@ export const screenshotTool = (v3) => tool({
|
|
|
4
4
|
description: "Takes a screenshot (PNG) of the current page. Use this to quickly verify page state.",
|
|
5
5
|
inputSchema: z.object({}),
|
|
6
6
|
execute: async () => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
try {
|
|
8
|
+
v3.logger({
|
|
9
|
+
category: "agent",
|
|
10
|
+
message: `Agent calling tool: screenshot`,
|
|
11
|
+
level: 1,
|
|
12
|
+
});
|
|
13
|
+
const page = await v3.context.awaitActivePage();
|
|
14
|
+
const buffer = await page.screenshot({ fullPage: false });
|
|
15
|
+
const pageUrl = page.url();
|
|
16
|
+
return {
|
|
17
|
+
success: true,
|
|
18
|
+
base64: buffer.toString("base64"),
|
|
19
|
+
timestamp: Date.now(),
|
|
20
|
+
pageUrl,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
return {
|
|
25
|
+
success: false,
|
|
26
|
+
error: `Error taking screenshot: ${error.message}`,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
toModelOutput: (result) => {
|
|
31
|
+
if (result.success === false || result.error !== undefined) {
|
|
32
|
+
return {
|
|
33
|
+
type: "content",
|
|
34
|
+
value: [{ type: "text", text: JSON.stringify(result) }],
|
|
35
|
+
};
|
|
36
|
+
}
|
|
15
37
|
return {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
pageUrl,
|
|
38
|
+
type: "content",
|
|
39
|
+
value: [{ type: "media", mediaType: "image/png", data: result.base64 }],
|
|
19
40
|
};
|
|
20
41
|
},
|
|
21
|
-
toModelOutput: (result) => ({
|
|
22
|
-
type: "content",
|
|
23
|
-
value: [{ type: "media", mediaType: "image/png", data: result.base64 }],
|
|
24
|
-
}),
|
|
25
42
|
});
|
|
26
43
|
//# sourceMappingURL=screenshot.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"screenshot.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/tools/screenshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,EAAM,EAAE,EAAE,CACvC,IAAI,CAAC;IACH,WAAW,EACT,sFAAsF;IACxF,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC;IACzB,OAAO,EAAE,KAAK,IAAI,EAAE;QAClB,EAAE,CAAC,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"screenshot.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/tools/screenshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,EAAM,EAAE,EAAE,CACvC,IAAI,CAAC;IACH,WAAW,EACT,sFAAsF;IACxF,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC;IACzB,OAAO,EAAE,KAAK,IAAI,EAAE;QAClB,IAAI,CAAC;YACH,EAAE,CAAC,MAAM,CAAC;gBACR,QAAQ,EAAE,OAAO;gBACjB,OAAO,EAAE,gCAAgC;gBACzC,KAAK,EAAE,CAAC;aACT,CAAC,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,eAAe,EAAE,CAAC;YAChD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;YAC1D,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YAC3B,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC;gBACjC,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;gBACrB,OAAO;aACR,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,4BAA6B,KAAe,CAAC,OAAO,EAAE;aAC9D,CAAC;QACJ,CAAC;IACH,CAAC;IACD,aAAa,EAAE,CAAC,MAAM,EAAE,EAAE;QACxB,IAAI,MAAM,CAAC,OAAO,KAAK,KAAK,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YAC3D,OAAO;gBACL,IAAI,EAAE,SAAS;gBACf,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;aACxD,CAAC;QACJ,CAAC;QAED,OAAO;YACL,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC;SACxE,CAAC;IACJ,CAAC;CACF,CAAC,CAAC","sourcesContent":["import { tool } from \"ai\";\nimport { z } from \"zod\";\nimport type { V3 } from \"../../v3.js\";\n\nexport const screenshotTool = (v3: V3) =>\n tool({\n description:\n \"Takes a screenshot (PNG) of the current page. Use this to quickly verify page state.\",\n inputSchema: z.object({}),\n execute: async () => {\n try {\n v3.logger({\n category: \"agent\",\n message: `Agent calling tool: screenshot`,\n level: 1,\n });\n const page = await v3.context.awaitActivePage();\n const buffer = await page.screenshot({ fullPage: false });\n const pageUrl = page.url();\n return {\n success: true,\n base64: buffer.toString(\"base64\"),\n timestamp: Date.now(),\n pageUrl,\n };\n } catch (error) {\n return {\n success: false,\n error: `Error taking screenshot: ${(error as Error).message}`,\n };\n }\n },\n toModelOutput: (result) => {\n if (result.success === false || result.error !== undefined) {\n return {\n type: \"content\",\n value: [{ type: \"text\", text: JSON.stringify(result) }],\n };\n }\n\n return {\n type: \"content\",\n value: [{ type: \"media\", mediaType: \"image/png\", data: result.base64 }],\n };\n },\n });\n"]}
|
|
@@ -44,6 +44,12 @@ export const scrollTool = (v3) => tool({
|
|
|
44
44
|
};
|
|
45
45
|
},
|
|
46
46
|
toModelOutput: (result) => {
|
|
47
|
+
if (result.success === false || result.error !== undefined) {
|
|
48
|
+
return {
|
|
49
|
+
type: "content",
|
|
50
|
+
value: [{ type: "text", text: JSON.stringify(result) }],
|
|
51
|
+
};
|
|
52
|
+
}
|
|
47
53
|
return {
|
|
48
54
|
type: "json",
|
|
49
55
|
value: {
|
|
@@ -119,6 +125,12 @@ export const scrollVisionTool = (v3, provider) => tool({
|
|
|
119
125
|
};
|
|
120
126
|
},
|
|
121
127
|
toModelOutput: (result) => {
|
|
128
|
+
if (result.success === false || result.error !== undefined) {
|
|
129
|
+
return {
|
|
130
|
+
type: "content",
|
|
131
|
+
value: [{ type: "text", text: JSON.stringify(result) }],
|
|
132
|
+
};
|
|
133
|
+
}
|
|
122
134
|
const content = [
|
|
123
135
|
{
|
|
124
136
|
type: "text",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scroll.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/tools/scroll.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA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CAAC;QACD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;IAC7C,CAAC;CACF,CAAC,CAAC","sourcesContent":["import { tool } from \"ai\";\nimport { z } from \"zod\";\nimport type { V3 } from \"../../v3.js\";\nimport type {\n ScrollToolResult,\n ScrollVisionToolResult,\n ModelOutputContentItem,\n} from \"../../types/public/agent.js\";\nimport { processCoordinates } from \"../utils/coordinateNormalization.js\";\nimport { waitAndCaptureScreenshot } from \"../utils/screenshotHandler.js\";\n\n/**\n * Simple scroll tool for DOM mode (non-grounding models).\n * No coordinates - scrolls from viewport center.\n */\nexport const scrollTool = (v3: V3) =>\n tool({\n description:\n \"Scroll the page up or down by a percentage of the viewport height. Default is 80%, and what should be typically used for general page scrolling\",\n inputSchema: z.object({\n direction: z.enum([\"up\", \"down\"]),\n percentage: z.number().min(1).max(200).optional(),\n }),\n execute: async ({\n direction,\n percentage = 80,\n }): Promise<ScrollToolResult> => {\n v3.logger({\n category: \"agent\",\n message: `Agent calling tool: scroll`,\n level: 1,\n auxiliary: {\n arguments: {\n value: JSON.stringify({ direction, percentage }),\n type: \"object\",\n },\n },\n });\n\n const page = await v3.context.awaitActivePage();\n\n const { w, h } = await page.mainFrame().evaluate<{\n w: number;\n h: number;\n }>(\"({ w: window.innerWidth, h: window.innerHeight })\");\n\n const scrollDistance = Math.round((h * percentage) / 100);\n const cx = Math.floor(w / 2);\n const cy = Math.floor(h / 2);\n const deltaY = direction === \"up\" ? -scrollDistance : scrollDistance;\n\n await page.scroll(cx, cy, 0, deltaY);\n\n v3.recordAgentReplayStep({\n type: \"scroll\",\n deltaX: 0,\n deltaY,\n anchor: { x: cx, y: cy },\n });\n\n return {\n success: true,\n message: `Scrolled ${percentage}% ${direction} (${scrollDistance}px)`,\n scrolledPixels: scrollDistance,\n };\n },\n toModelOutput: (result) => {\n return {\n type: \"json\",\n value: {\n success: result.success,\n message: result.message,\n scrolledPixels: result.scrolledPixels,\n },\n };\n },\n });\n\n/**\n * Scroll tool for hybrid mode (grounding models).\n * Supports optional coordinates for scrolling within nested scrollable elements.\n */\nexport const scrollVisionTool = (v3: V3, provider?: string) =>\n tool({\n description: `Scroll the page up or down. For general page scrolling, no coordinates needed. Only provide coordinates when scrolling inside a nested scrollable element (e.g., a dropdown menu, modal with overflow, or scrollable sidebar). Default is 80%, and what should be typically used for general page scrolling`,\n inputSchema: z.object({\n direction: z.enum([\"up\", \"down\"]),\n coordinates: z\n .array(z.number())\n .optional()\n .describe(\n \"Only use coordinates for scrolling inside a nested scrollable element - provide (x, y) within that element\",\n ),\n percentage: z.number().min(1).max(200).optional(),\n }),\n execute: async ({\n direction,\n coordinates,\n percentage = 80,\n }): Promise<ScrollVisionToolResult> => {\n const page = await v3.context.awaitActivePage();\n\n const { w, h } = await page.mainFrame().evaluate<{\n w: number;\n h: number;\n }>(\"({ w: window.innerWidth, h: window.innerHeight })\");\n\n // Process coordinates if provided, otherwise use viewport center\n let cx: number;\n let cy: number;\n if (coordinates) {\n const processed = processCoordinates(\n coordinates[0],\n coordinates[1],\n provider,\n v3,\n );\n cx = processed.x;\n cy = processed.y;\n } else {\n cx = Math.floor(w / 2);\n cy = Math.floor(h / 2);\n }\n\n v3.logger({\n category: \"agent\",\n message: `Agent calling tool: scroll`,\n level: 1,\n auxiliary: {\n arguments: {\n value: JSON.stringify({\n direction,\n coordinates,\n percentage,\n processed: { cx, cy },\n }),\n type: \"object\",\n },\n },\n });\n\n const scrollDistance = Math.round((h * percentage) / 100);\n const deltaY = direction === \"up\" ? -scrollDistance : scrollDistance;\n\n await page.scroll(cx, cy, 0, deltaY);\n\n const screenshotBase64 = await waitAndCaptureScreenshot(page, 100);\n\n v3.recordAgentReplayStep({\n type: \"scroll\",\n deltaX: 0,\n deltaY,\n anchor: { x: cx, y: cy },\n });\n\n return {\n success: true,\n message: coordinates\n ? `Scrolled ${percentage}% ${direction} at (${cx}, ${cy})`\n : `Scrolled ${percentage}% ${direction}`,\n scrolledPixels: scrollDistance,\n screenshotBase64,\n };\n },\n toModelOutput: (result) => {\n const content: ModelOutputContentItem[] = [\n {\n type: \"text\",\n text: JSON.stringify({\n success: result.success,\n message: result.message,\n scrolledPixels: result.scrolledPixels,\n }),\n },\n ];\n if (result.screenshotBase64) {\n content.push({\n type: \"media\",\n mediaType: \"image/png\",\n data: result.screenshotBase64,\n });\n }\n return { type: \"content\", value: content };\n },\n });\n"]}
|
|
1
|
+
{"version":3,"file":"scroll.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/tools/scroll.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACzE,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzE;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,EAAM,EAAE,EAAE,CACnC,IAAI,CAAC;IACH,WAAW,EACT,iJAAiJ;IACnJ,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;QACpB,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACjC,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE;KAClD,CAAC;IACF,OAAO,EAAE,KAAK,EAAE,EACd,SAAS,EACT,UAAU,GAAG,EAAE,GAChB,EAA6B,EAAE;QAC9B,EAAE,CAAC,MAAM,CAAC;YACR,QAAQ,EAAE,OAAO;YACjB,OAAO,EAAE,4BAA4B;YACrC,KAAK,EAAE,CAAC;YACR,SAAS,EAAE;gBACT,SAAS,EAAE;oBACT,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,CAA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CAAC;QAEH,OAAO;YACL,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,WAAW;gBAClB,CAAC,CAAC,YAAY,UAAU,KAAK,SAAS,QAAQ,EAAE,KAAK,EAAE,GAAG;gBAC1D,CAAC,CAAC,YAAY,UAAU,KAAK,SAAS,EAAE;YAC1C,cAAc,EAAE,cAAc;YAC9B,gBAAgB;SACjB,CAAC;IACJ,CAAC;IACD,aAAa,EAAE,CAAC,MAAM,EAAE,EAAE;QACxB,IAAI,MAAM,CAAC,OAAO,KAAK,KAAK,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YAC3D,OAAO;gBACL,IAAI,EAAE,SAAS;gBACf,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;aACxD,CAAC;QACJ,CAAC;QAED,MAAM,OAAO,GAA6B;YACxC;gBACE,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;oBACnB,OAAO,EAAE,MAAM,CAAC,OAAO;oBACvB,OAAO,EAAE,MAAM,CAAC,OAAO;oBACvB,cAAc,EAAE,MAAM,CAAC,cAAc;iBACtC,CAAC;aACH;SACF,CAAC;QACF,IAAI,MAAM,CAAC,gBAAgB,EAAE,CAAC;YAC5B,OAAO,CAAC,IAAI,CAAC;gBACX,IAAI,EAAE,OAAO;gBACb,SAAS,EAAE,WAAW;gBACtB,IAAI,EAAE,MAAM,CAAC,gBAAgB;aAC9B,CAAC,CAAC;QACL,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;IAC7C,CAAC;CACF,CAAC,CAAC","sourcesContent":["import { tool } from \"ai\";\nimport { z } from \"zod\";\nimport type { V3 } from \"../../v3.js\";\nimport type {\n ScrollToolResult,\n ScrollVisionToolResult,\n ModelOutputContentItem,\n} from \"../../types/public/agent.js\";\nimport { processCoordinates } from \"../utils/coordinateNormalization.js\";\nimport { waitAndCaptureScreenshot } from \"../utils/screenshotHandler.js\";\n\n/**\n * Simple scroll tool for DOM mode (non-grounding models).\n * No coordinates - scrolls from viewport center.\n */\nexport const scrollTool = (v3: V3) =>\n tool({\n description:\n \"Scroll the page up or down by a percentage of the viewport height. Default is 80%, and what should be typically used for general page scrolling\",\n inputSchema: z.object({\n direction: z.enum([\"up\", \"down\"]),\n percentage: z.number().min(1).max(200).optional(),\n }),\n execute: async ({\n direction,\n percentage = 80,\n }): Promise<ScrollToolResult> => {\n v3.logger({\n category: \"agent\",\n message: `Agent calling tool: scroll`,\n level: 1,\n auxiliary: {\n arguments: {\n value: JSON.stringify({ direction, percentage }),\n type: \"object\",\n },\n },\n });\n\n const page = await v3.context.awaitActivePage();\n\n const { w, h } = await page.mainFrame().evaluate<{\n w: number;\n h: number;\n }>(\"({ w: window.innerWidth, h: window.innerHeight })\");\n\n const scrollDistance = Math.round((h * percentage) / 100);\n const cx = Math.floor(w / 2);\n const cy = Math.floor(h / 2);\n const deltaY = direction === \"up\" ? -scrollDistance : scrollDistance;\n\n await page.scroll(cx, cy, 0, deltaY);\n\n v3.recordAgentReplayStep({\n type: \"scroll\",\n deltaX: 0,\n deltaY,\n anchor: { x: cx, y: cy },\n });\n\n return {\n success: true,\n message: `Scrolled ${percentage}% ${direction} (${scrollDistance}px)`,\n scrolledPixels: scrollDistance,\n };\n },\n toModelOutput: (result) => {\n if (result.success === false || result.error !== undefined) {\n return {\n type: \"content\",\n value: [{ type: \"text\", text: JSON.stringify(result) }],\n };\n }\n\n return {\n type: \"json\",\n value: {\n success: result.success,\n message: result.message,\n scrolledPixels: result.scrolledPixels,\n },\n };\n },\n });\n\n/**\n * Scroll tool for hybrid mode (grounding models).\n * Supports optional coordinates for scrolling within nested scrollable elements.\n */\nexport const scrollVisionTool = (v3: V3, provider?: string) =>\n tool({\n description: `Scroll the page up or down. For general page scrolling, no coordinates needed. Only provide coordinates when scrolling inside a nested scrollable element (e.g., a dropdown menu, modal with overflow, or scrollable sidebar). Default is 80%, and what should be typically used for general page scrolling`,\n inputSchema: z.object({\n direction: z.enum([\"up\", \"down\"]),\n coordinates: z\n .array(z.number())\n .optional()\n .describe(\n \"Only use coordinates for scrolling inside a nested scrollable element - provide (x, y) within that element\",\n ),\n percentage: z.number().min(1).max(200).optional(),\n }),\n execute: async ({\n direction,\n coordinates,\n percentage = 80,\n }): Promise<ScrollVisionToolResult> => {\n const page = await v3.context.awaitActivePage();\n\n const { w, h } = await page.mainFrame().evaluate<{\n w: number;\n h: number;\n }>(\"({ w: window.innerWidth, h: window.innerHeight })\");\n\n // Process coordinates if provided, otherwise use viewport center\n let cx: number;\n let cy: number;\n if (coordinates) {\n const processed = processCoordinates(\n coordinates[0],\n coordinates[1],\n provider,\n v3,\n );\n cx = processed.x;\n cy = processed.y;\n } else {\n cx = Math.floor(w / 2);\n cy = Math.floor(h / 2);\n }\n\n v3.logger({\n category: \"agent\",\n message: `Agent calling tool: scroll`,\n level: 1,\n auxiliary: {\n arguments: {\n value: JSON.stringify({\n direction,\n coordinates,\n percentage,\n processed: { cx, cy },\n }),\n type: \"object\",\n },\n },\n });\n\n const scrollDistance = Math.round((h * percentage) / 100);\n const deltaY = direction === \"up\" ? -scrollDistance : scrollDistance;\n\n await page.scroll(cx, cy, 0, deltaY);\n\n const screenshotBase64 = await waitAndCaptureScreenshot(page, 100);\n\n v3.recordAgentReplayStep({\n type: \"scroll\",\n deltaX: 0,\n deltaY,\n anchor: { x: cx, y: cy },\n });\n\n return {\n success: true,\n message: coordinates\n ? `Scrolled ${percentage}% ${direction} at (${cx}, ${cy})`\n : `Scrolled ${percentage}% ${direction}`,\n scrolledPixels: scrollDistance,\n screenshotBase64,\n };\n },\n toModelOutput: (result) => {\n if (result.success === false || result.error !== undefined) {\n return {\n type: \"content\",\n value: [{ type: \"text\", text: JSON.stringify(result) }],\n };\n }\n\n const content: ModelOutputContentItem[] = [\n {\n type: \"text\",\n text: JSON.stringify({\n success: result.success,\n message: result.message,\n scrolledPixels: result.scrolledPixels,\n }),\n },\n ];\n if (result.screenshotBase64) {\n content.push({\n type: \"media\",\n mediaType: \"image/png\",\n data: result.screenshotBase64,\n });\n }\n return { type: \"content\", value: content };\n },\n });\n"]}
|
|
@@ -77,38 +77,30 @@ export const typeTool = (v3, provider, variables) => {
|
|
|
77
77
|
}
|
|
78
78
|
},
|
|
79
79
|
toModelOutput: (result) => {
|
|
80
|
-
if (result.success) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
success: result.success,
|
|
86
|
-
describe: result.describe,
|
|
87
|
-
text: result.text,
|
|
88
|
-
}),
|
|
89
|
-
},
|
|
90
|
-
];
|
|
91
|
-
if (result.screenshotBase64) {
|
|
92
|
-
content.push({
|
|
93
|
-
type: "media",
|
|
94
|
-
mediaType: "image/png",
|
|
95
|
-
data: result.screenshotBase64,
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
return { type: "content", value: content };
|
|
80
|
+
if (result.success === false || result.error !== undefined) {
|
|
81
|
+
return {
|
|
82
|
+
type: "content",
|
|
83
|
+
value: [{ type: "text", text: JSON.stringify(result) }],
|
|
84
|
+
};
|
|
99
85
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
{
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
86
|
+
const content = [
|
|
87
|
+
{
|
|
88
|
+
type: "text",
|
|
89
|
+
text: JSON.stringify({
|
|
90
|
+
success: result.success,
|
|
91
|
+
describe: result.describe,
|
|
92
|
+
text: result.text,
|
|
93
|
+
}),
|
|
94
|
+
},
|
|
95
|
+
];
|
|
96
|
+
if (result.screenshotBase64) {
|
|
97
|
+
content.push({
|
|
98
|
+
type: "media",
|
|
99
|
+
mediaType: "image/png",
|
|
100
|
+
data: result.screenshotBase64,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
return { type: "content", value: content };
|
|
112
104
|
},
|
|
113
105
|
});
|
|
114
106
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/tools/type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAQxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,EAAM,EAAE,QAAiB,EAAE,SAAqB,EAAE,EAAE;IAC3E,MAAM,YAAY,GAAG,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IACpE,MAAM,eAAe,GAAG,YAAY;QAClC,CAAC,CAAC,oGAAoG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QACzI,CAAC,CAAC,mCAAmC,CAAC;IAExC,OAAO,IAAI,CAAC;QACV,WAAW,EACT,2QAA2Q;QAC7Q,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;YACpB,QAAQ,EAAE,CAAC;iBACR,MAAM,EAAE;iBACR,QAAQ,CACP,4HAA4H,CAC7H;YACH,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,eAAe,CAAC;YAC1C,WAAW,EAAE,CAAC;iBACX,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;iBACjB,QAAQ,CAAC,iDAAiD,CAAC;SAC/D,C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AE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;iBACxD,CAAC;YACJ,CAAC;YAED,MAAM,OAAO,GAA6B;gBACxC;oBACE,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;wBACnB,OAAO,EAAE,MAAM,CAAC,OAAO;wBACvB,QAAQ,EAAE,MAAM,CAAC,QAAQ;wBACzB,IAAI,EAAE,MAAM,CAAC,IAAI;qBAClB,CAAC;iBACH;aACF,CAAC;YACF,IAAI,MAAM,CAAC,gBAAgB,EAAE,CAAC;gBAC5B,OAAO,CAAC,IAAI,CAAC;oBACX,IAAI,EAAE,OAAO;oBACb,SAAS,EAAE,WAAW;oBACtB,IAAI,EAAE,MAAM,CAAC,gBAAgB;iBAC9B,CAAC,CAAC;YACL,CAAC;YACD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;QAC7C,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["import { tool } from \"ai\";\nimport { z } from \"zod\";\nimport type { V3 } from \"../../v3.js\";\nimport type { Action } from \"../../types/public/methods.js\";\nimport type {\n TypeToolResult,\n ModelOutputContentItem,\n Variables,\n} from \"../../types/public/agent.js\";\nimport { processCoordinates } from \"../utils/coordinateNormalization.js\";\nimport { ensureXPath } from \"../utils/xpath.js\";\nimport { waitAndCaptureScreenshot } from \"../utils/screenshotHandler.js\";\nimport { substituteVariables } from \"../utils/variables.js\";\n\nexport const typeTool = (v3: V3, provider?: string, variables?: Variables) => {\n const hasVariables = variables && Object.keys(variables).length > 0;\n const textDescription = hasVariables\n ? `The text to type into the element. Use %variableName% to substitute a variable value. Available: ${Object.keys(variables).join(\", \")}`\n : \"The text to type into the element\";\n\n return tool({\n description:\n \"Type text into an element using its coordinates. This will click the element and then type the text into it (this is the most reliable way to type into an element, always use this over act, unless the element is not visible in the screenshot, but shown in ariaTree)\",\n inputSchema: z.object({\n describe: z\n .string()\n .describe(\n \"Describe the element to type into in a short, specific phrase that mentions the element type and a good visual description\",\n ),\n text: z.string().describe(textDescription),\n coordinates: z\n .array(z.number())\n .describe(\"The (x, y) coordinates to type into the element\"),\n }),\n execute: async ({\n describe,\n coordinates,\n text,\n }): Promise<TypeToolResult> => {\n try {\n const page = await v3.context.awaitActivePage();\n const processed = processCoordinates(\n coordinates[0],\n coordinates[1],\n provider,\n v3,\n );\n\n // Substitute any %variableName% tokens in the text\n const actualText = substituteVariables(text, variables);\n\n v3.logger({\n category: \"agent\",\n message: `Agent calling tool: type`,\n level: 1,\n auxiliary: {\n arguments: {\n value: JSON.stringify({ describe, text }),\n type: \"object\",\n },\n },\n });\n\n // Only request XPath when caching is enabled to avoid unnecessary computation\n const shouldCollectXpath = v3.isAgentReplayActive();\n const xpath = await page.click(processed.x, processed.y, {\n returnXpath: shouldCollectXpath,\n });\n\n await page.type(actualText);\n\n const screenshotBase64 = await waitAndCaptureScreenshot(page);\n\n // Record as an \"act\" step with proper Action for deterministic replay (only when caching)\n if (shouldCollectXpath) {\n const normalizedXpath = ensureXPath(xpath);\n if (normalizedXpath) {\n const action: Action = {\n selector: normalizedXpath,\n description: describe,\n method: \"type\",\n arguments: [text],\n };\n v3.recordAgentReplayStep({\n type: \"act\",\n instruction: describe,\n actions: [action],\n actionDescription: describe,\n });\n }\n }\n\n return {\n success: true,\n describe,\n text, // Return original text (with %variableName% tokens) to avoid exposing sensitive values to LLM\n screenshotBase64,\n };\n } catch (error) {\n return {\n success: false,\n error: `Error typing: ${(error as Error).message}`,\n };\n }\n },\n toModelOutput: (result) => {\n if (result.success === false || result.error !== undefined) {\n return {\n type: \"content\",\n value: [{ type: \"text\", text: JSON.stringify(result) }],\n };\n }\n\n const content: ModelOutputContentItem[] = [\n {\n type: \"text\",\n text: JSON.stringify({\n success: result.success,\n describe: result.describe,\n text: result.text,\n }),\n },\n ];\n if (result.screenshotBase64) {\n content.push({\n type: \"media\",\n mediaType: \"image/png\",\n data: result.screenshotBase64,\n });\n }\n return { type: \"content\", value: content };\n },\n });\n};\n"]}
|
|
@@ -31,6 +31,12 @@ export const waitTool = (v3, mode) => tool({
|
|
|
31
31
|
return { success: true, waited: timeMs };
|
|
32
32
|
},
|
|
33
33
|
toModelOutput: (result) => {
|
|
34
|
+
if (result.success === false || result.error !== undefined) {
|
|
35
|
+
return {
|
|
36
|
+
type: "content",
|
|
37
|
+
value: [{ type: "text", text: JSON.stringify(result) }],
|
|
38
|
+
};
|
|
39
|
+
}
|
|
34
40
|
const content = [
|
|
35
41
|
{
|
|
36
42
|
type: "text",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wait.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/tools/wait.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzE,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,EAAM,EAAE,IAAoB,EAAE,EAAE,CACvD,IAAI,CAAC;IACH,WAAW,EAAE,2BAA2B;IACxC,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;QACpB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,sBAAsB,CAAC;KACpD,CAAC;IACF,OAAO,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAA2B,EAAE;QACrD,EAAE,CAAC,MAAM,CAAC;YACR,QAAQ,EAAE,OAAO;YACjB,OAAO,EAAE,0BAA0B;YACnC,KAAK,EAAE,CAAC;YACR,SAAS,EAAE;gBACT,SAAS,EAAE;oBACT,KAAK,EAAE,eAAe,MAAM,eAAe;oBAC3C,IAAI,EAAE,QAAQ;iBACf;aACF;SACF,CAAC,CAAC;QACH,MAAM,IA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type {\n AgentToolMode,\n WaitToolResult,\n ModelOutputContentItem,\n} from \"../../types/public/agent.js\";\nimport { waitAndCaptureScreenshot } from \"../utils/screenshotHandler.js\";\n\nexport const waitTool = (v3: V3, mode?: AgentToolMode) =>\n tool({\n description: \"Wait for a specified time\",\n inputSchema: z.object({\n timeMs: z.number().describe(\"Time in milliseconds\"),\n }),\n execute: async ({ timeMs }): Promise<WaitToolResult> => {\n v3.logger({\n category: \"agent\",\n message: `Agent calling tool: wait`,\n level: 1,\n auxiliary: {\n arguments: {\n value: `Waiting for ${timeMs} milliseconds`,\n type: \"string\",\n },\n },\n });\n await new Promise((resolve) => setTimeout(resolve, timeMs));\n if (timeMs > 0) {\n v3.recordAgentReplayStep({ type: \"wait\", timeMs });\n }\n\n // Take screenshot after wait in hybrid mode for visual feedback\n if (mode === \"hybrid\") {\n const page = await v3.context.awaitActivePage();\n const screenshotBase64 = await waitAndCaptureScreenshot(page, 0);\n return { success: true, waited: timeMs, screenshotBase64 };\n }\n\n return { success: true, waited: timeMs };\n },\n toModelOutput: (result) => {\n const content: ModelOutputContentItem[] = [\n {\n type: \"text\",\n text: JSON.stringify({\n success: result.success,\n waited: result.waited,\n }),\n },\n ];\n if (result.screenshotBase64) {\n content.push({\n type: \"media\",\n mediaType: \"image/png\",\n data: result.screenshotBase64,\n });\n }\n return { type: \"content\", value: content };\n },\n });\n"]}
|
|
1
|
+
{"version":3,"file":"wait.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/tools/wait.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzE,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,EAAM,EAAE,IAAoB,EAAE,EAAE,CACvD,IAAI,CAAC;IACH,WAAW,EAAE,2BAA2B;IACxC,WAAW,EAAE,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,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;aACxD,CAAC;QACJ,CAAC;QAED,MAAM,OAAO,GAA6B;YACxC;gBACE,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;oBACnB,OAAO,EAAE,MAAM,CAAC,OAAO;oBACvB,MAAM,EAAE,MAAM,CAAC,MAAM;iBACtB,CAAC;aACH;SACF,CAAC;QACF,IAAI,MAAM,CAAC,gBAAgB,EAAE,CAAC;YAC5B,OAAO,CAAC,IAAI,CAAC;gBACX,IAAI,EAAE,OAAO;gBACb,SAAS,EAAE,WAAW;gBACtB,IAAI,EAAE,MAAM,CAAC,gBAAgB;aAC9B,CAAC,CAAC;QACL,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;IAC7C,CAAC;CACF,CAAC,CAAC","sourcesContent":["import { tool } from \"ai\";\nimport { z } from \"zod\";\nimport type { V3 } from \"../../v3.js\";\nimport type {\n AgentToolMode,\n WaitToolResult,\n ModelOutputContentItem,\n} from \"../../types/public/agent.js\";\nimport { waitAndCaptureScreenshot } from \"../utils/screenshotHandler.js\";\n\nexport const waitTool = (v3: V3, mode?: AgentToolMode) =>\n tool({\n description: \"Wait for a specified time\",\n inputSchema: z.object({\n timeMs: z.number().describe(\"Time in milliseconds\"),\n }),\n execute: async ({ timeMs }): Promise<WaitToolResult> => {\n v3.logger({\n category: \"agent\",\n message: `Agent calling tool: wait`,\n level: 1,\n auxiliary: {\n arguments: {\n value: `Waiting for ${timeMs} milliseconds`,\n type: \"string\",\n },\n },\n });\n await new Promise((resolve) => setTimeout(resolve, timeMs));\n if (timeMs > 0) {\n v3.recordAgentReplayStep({ type: \"wait\", timeMs });\n }\n\n // Take screenshot after wait in hybrid mode for visual feedback\n if (mode === \"hybrid\") {\n const page = await v3.context.awaitActivePage();\n const screenshotBase64 = await waitAndCaptureScreenshot(page, 0);\n return { success: true, waited: timeMs, screenshotBase64 };\n }\n\n return { success: true, waited: timeMs };\n },\n toModelOutput: (result) => {\n if (result.success === false || result.error !== undefined) {\n return {\n type: \"content\",\n value: [{ type: \"text\", text: JSON.stringify(result) }],\n };\n }\n\n const content: ModelOutputContentItem[] = [\n {\n type: \"text\",\n text: JSON.stringify({\n success: result.success,\n waited: result.waited,\n }),\n },\n ];\n if (result.screenshotBase64) {\n content.push({\n type: \"media\",\n mediaType: \"image/png\",\n data: result.screenshotBase64,\n });\n }\n return { type: \"content\", value: content };\n },\n });\n"]}
|
|
@@ -72,6 +72,10 @@ Call the "done" tool with:
|
|
|
72
72
|
messages: [...inputMessages, userPrompt],
|
|
73
73
|
tools: { done: doneTool },
|
|
74
74
|
toolChoice: { type: "tool", toolName: "done" },
|
|
75
|
+
providerOptions: {
|
|
76
|
+
google: { mediaResolution: "MEDIA_RESOLUTION_HIGH" },
|
|
77
|
+
openai: { store: false },
|
|
78
|
+
},
|
|
75
79
|
});
|
|
76
80
|
const doneToolCall = result.toolCalls.find((tc) => tc.toolName === "done");
|
|
77
81
|
const outputMessages = [
|