@browserbasehq/orca 3.1.0-patch.0 → 3.1.0-patch.1

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.
Files changed (387) hide show
  1. package/dist/cjs/cli.js +183 -0
  2. package/dist/cjs/cli.js.map +7 -0
  3. package/dist/cjs/index.d.ts +1 -0
  4. package/dist/cjs/index.js +24956 -0
  5. package/dist/cjs/index.js.map +7 -0
  6. package/dist/cjs/lib/inference.d.ts +65 -0
  7. package/dist/cjs/lib/inferenceLogUtils.d.ts +12 -0
  8. package/dist/cjs/lib/logger.d.ts +69 -0
  9. package/dist/cjs/lib/modelUtils.d.ts +11 -0
  10. package/dist/cjs/lib/prompt.d.ts +14 -0
  11. package/dist/cjs/lib/utils.d.ts +68 -0
  12. package/dist/cjs/lib/v3/agent/AgentClient.d.ts +19 -0
  13. package/dist/cjs/lib/v3/agent/AgentProvider.d.ts +20 -0
  14. package/dist/cjs/lib/v3/agent/AnthropicCUAClient.d.ts +57 -0
  15. package/dist/cjs/lib/v3/agent/GoogleCUAClient.d.ts +74 -0
  16. package/dist/cjs/lib/v3/agent/MicrosoftCUAClient.d.ts +71 -0
  17. package/dist/cjs/lib/v3/agent/OpenAICUAClient.d.ts +69 -0
  18. package/dist/cjs/lib/v3/agent/prompts/agentSystemPrompt.d.ts +12 -0
  19. package/dist/cjs/lib/v3/agent/tools/act.d.ts +12 -0
  20. package/dist/cjs/lib/v3/agent/tools/ariaTree.d.ts +5 -0
  21. package/dist/cjs/lib/v3/agent/tools/click.d.ts +6 -0
  22. package/dist/cjs/lib/v3/agent/tools/clickAndHold.d.ts +14 -0
  23. package/dist/cjs/lib/v3/agent/tools/dragAndDrop.d.ts +7 -0
  24. package/dist/cjs/lib/v3/agent/tools/extract.d.ts +20 -0
  25. package/dist/cjs/lib/v3/agent/tools/fillFormVision.d.ts +12 -0
  26. package/dist/cjs/lib/v3/agent/tools/fillform.d.ts +12 -0
  27. package/dist/cjs/lib/v3/agent/tools/goto.d.ts +12 -0
  28. package/dist/cjs/lib/v3/agent/tools/index.d.ts +92 -0
  29. package/dist/cjs/lib/v3/agent/tools/keys.d.ts +24 -0
  30. package/dist/cjs/lib/v3/agent/tools/navback.d.ts +6 -0
  31. package/dist/cjs/lib/v3/agent/tools/screenshot.d.ts +6 -0
  32. package/dist/cjs/lib/v3/agent/tools/scroll.d.ts +19 -0
  33. package/dist/cjs/lib/v3/agent/tools/search.d.ts +15 -0
  34. package/dist/cjs/lib/v3/agent/tools/think.d.ts +6 -0
  35. package/dist/cjs/lib/v3/agent/tools/type.d.ts +7 -0
  36. package/dist/cjs/lib/v3/agent/tools/wait.d.ts +5 -0
  37. package/dist/cjs/lib/v3/agent/utils/actionMapping.d.ts +3 -0
  38. package/dist/cjs/lib/v3/agent/utils/coordinateNormalization.d.ts +13 -0
  39. package/dist/cjs/lib/v3/agent/utils/cuaKeyMapping.d.ts +10 -0
  40. package/dist/cjs/lib/v3/agent/utils/googleCustomToolHandler.d.ts +25 -0
  41. package/dist/cjs/lib/v3/agent/utils/handleDoneToolCall.d.ts +22 -0
  42. package/dist/cjs/lib/v3/agent/utils/imageCompression.d.ts +53 -0
  43. package/dist/cjs/lib/v3/agent/utils/messageProcessing.d.ts +12 -0
  44. package/dist/cjs/lib/v3/agent/utils/screenshotHandler.d.ts +10 -0
  45. package/dist/cjs/lib/v3/agent/utils/validateExperimentalFeatures.d.ts +26 -0
  46. package/dist/cjs/lib/v3/agent/utils/xpath.d.ts +11 -0
  47. package/dist/cjs/lib/v3/api.d.ts +86 -0
  48. package/dist/cjs/lib/v3/cache/ActCache.d.ts +23 -0
  49. package/dist/cjs/lib/v3/cache/AgentCache.d.ts +109 -0
  50. package/dist/cjs/lib/v3/cache/CacheStorage.d.ts +17 -0
  51. package/dist/cjs/lib/v3/cache/serverAgentCache.d.ts +7 -0
  52. package/dist/cjs/lib/v3/cache/utils.d.ts +15 -0
  53. package/dist/cjs/lib/v3/cli.d.ts +2 -0
  54. package/dist/cjs/lib/v3/dom/a11yScripts/index.d.ts +11 -0
  55. package/dist/cjs/lib/v3/dom/build/a11yScripts.generated.d.ts +16 -0
  56. package/dist/cjs/lib/v3/dom/build/locatorScripts.generated.d.ts +52 -0
  57. package/dist/cjs/lib/v3/dom/build/reRenderScriptContent.d.ts +1 -0
  58. package/dist/cjs/lib/v3/dom/build/rerender-index.d.ts +0 -0
  59. package/dist/cjs/lib/v3/dom/build/rerender-index.js +1 -0
  60. package/dist/cjs/lib/v3/dom/build/screenshotScripts.generated.d.ts +4 -0
  61. package/dist/cjs/lib/v3/dom/build/scriptV3Content.d.ts +1 -0
  62. package/dist/cjs/lib/v3/dom/build/v3-index.d.ts +0 -0
  63. package/dist/cjs/lib/v3/dom/build/v3-index.js +1 -0
  64. package/dist/cjs/lib/v3/dom/genA11yScripts.d.ts +1 -0
  65. package/dist/cjs/lib/v3/dom/genDomScripts.d.ts +1 -0
  66. package/dist/cjs/lib/v3/dom/genLocatorScripts.d.ts +1 -0
  67. package/dist/cjs/lib/v3/dom/genScreenshotScripts.d.ts +1 -0
  68. package/dist/cjs/lib/v3/dom/index.d.ts +1 -0
  69. package/dist/cjs/lib/v3/dom/locatorScripts/counts.d.ts +15 -0
  70. package/dist/cjs/lib/v3/dom/locatorScripts/index.d.ts +4 -0
  71. package/dist/cjs/lib/v3/dom/locatorScripts/scripts.d.ts +37 -0
  72. package/dist/cjs/lib/v3/dom/locatorScripts/selectors.d.ts +4 -0
  73. package/dist/cjs/lib/v3/dom/locatorScripts/waitForSelector.d.ts +19 -0
  74. package/dist/cjs/lib/v3/dom/locatorScripts/xpathParser.d.ts +76 -0
  75. package/dist/cjs/lib/v3/dom/locatorScripts/xpathResolver.d.ts +9 -0
  76. package/dist/cjs/lib/v3/dom/piercer.entry.d.ts +1 -0
  77. package/dist/cjs/lib/v3/dom/piercer.runtime.d.ts +23 -0
  78. package/dist/cjs/lib/v3/dom/rerenderMissingShadows.entry.d.ts +1 -0
  79. package/dist/cjs/lib/v3/dom/rerenderMissingShadows.runtime.d.ts +1 -0
  80. package/dist/cjs/lib/v3/dom/screenshotScripts/index.d.ts +1 -0
  81. package/dist/cjs/lib/v3/dom/screenshotScripts/resolveMaskRect.d.ts +8 -0
  82. package/dist/cjs/lib/v3/external_clients/aisdk.d.ts +11 -0
  83. package/dist/cjs/lib/v3/external_clients/customOpenAI.d.ts +18 -0
  84. package/dist/cjs/lib/v3/flowLogger.d.ts +139 -0
  85. package/dist/cjs/lib/v3/handlers/actHandler.d.ts +21 -0
  86. package/dist/cjs/lib/v3/handlers/extractHandler.d.ts +31 -0
  87. package/dist/cjs/lib/v3/handlers/handlerUtils/actHandlerUtils.d.ts +24 -0
  88. package/dist/cjs/lib/v3/handlers/handlerUtils/timeoutGuard.d.ts +2 -0
  89. package/dist/cjs/lib/v3/handlers/observeHandler.d.ts +17 -0
  90. package/dist/cjs/lib/v3/handlers/v3AgentHandler.d.ts +32 -0
  91. package/dist/cjs/lib/v3/handlers/v3CuaAgentHandler.d.ts +33 -0
  92. package/dist/cjs/lib/v3/index.d.ts +18 -0
  93. package/dist/cjs/lib/v3/launch/browserbase.d.ts +7 -0
  94. package/dist/cjs/lib/v3/launch/local.d.ts +15 -0
  95. package/dist/cjs/lib/v3/llm/AnthropicClient.d.ts +16 -0
  96. package/dist/cjs/lib/v3/llm/CerebrasClient.d.ts +17 -0
  97. package/dist/cjs/lib/v3/llm/GoogleClient.d.ts +19 -0
  98. package/dist/cjs/lib/v3/llm/GroqClient.d.ts +17 -0
  99. package/dist/cjs/lib/v3/llm/LLMClient.d.ts +121 -0
  100. package/dist/cjs/lib/v3/llm/LLMProvider.d.ts +13 -0
  101. package/dist/cjs/lib/v3/llm/OpenAIClient.d.ts +15 -0
  102. package/dist/cjs/lib/v3/llm/aisdk.d.ts +15 -0
  103. package/dist/cjs/lib/v3/logger.d.ts +9 -0
  104. package/dist/cjs/lib/v3/mcp/connection.d.ts +11 -0
  105. package/dist/cjs/lib/v3/mcp/utils.d.ts +3 -0
  106. package/dist/cjs/lib/v3/shutdown/cleanupLocal.d.ts +14 -0
  107. package/dist/cjs/lib/v3/shutdown/supervisor.d.ts +11 -0
  108. package/dist/cjs/lib/v3/shutdown/supervisorClient.d.ts +15 -0
  109. package/dist/cjs/lib/v3/tests/agent-abort-signal.spec.js +113 -0
  110. package/dist/cjs/lib/v3/tests/agent-abort-signal.spec.js.map +7 -0
  111. package/dist/cjs/lib/v3/tests/agent-cache-self-heal.spec.js +102 -0
  112. package/dist/cjs/lib/v3/tests/agent-cache-self-heal.spec.js.map +7 -0
  113. package/dist/cjs/lib/v3/tests/agent-callbacks.spec.js +374 -0
  114. package/dist/cjs/lib/v3/tests/agent-callbacks.spec.js.map +7 -0
  115. package/dist/cjs/lib/v3/tests/agent-experimental-validation.spec.js +354 -0
  116. package/dist/cjs/lib/v3/tests/agent-experimental-validation.spec.js.map +7 -0
  117. package/dist/cjs/lib/v3/tests/agent-hybrid-mode.spec.js +247 -0
  118. package/dist/cjs/lib/v3/tests/agent-hybrid-mode.spec.js.map +7 -0
  119. package/dist/cjs/lib/v3/tests/agent-message-continuation.spec.js +105 -0
  120. package/dist/cjs/lib/v3/tests/agent-message-continuation.spec.js.map +7 -0
  121. package/dist/cjs/lib/v3/tests/agent-streaming.spec.js +126 -0
  122. package/dist/cjs/lib/v3/tests/agent-streaming.spec.js.map +7 -0
  123. package/dist/cjs/lib/v3/tests/cdp-session-detached.spec.js +44 -0
  124. package/dist/cjs/lib/v3/tests/cdp-session-detached.spec.js.map +7 -0
  125. package/dist/cjs/lib/v3/tests/click-count.spec.js +147 -0
  126. package/dist/cjs/lib/v3/tests/click-count.spec.js.map +7 -0
  127. package/dist/cjs/lib/v3/tests/connect-to-existing-browser.spec.js +54 -0
  128. package/dist/cjs/lib/v3/tests/connect-to-existing-browser.spec.js.map +7 -0
  129. package/dist/cjs/lib/v3/tests/context-addInitScript.spec.js +176 -0
  130. package/dist/cjs/lib/v3/tests/context-addInitScript.spec.js.map +7 -0
  131. package/dist/cjs/lib/v3/tests/default-page-tracking.spec.js +53 -0
  132. package/dist/cjs/lib/v3/tests/default-page-tracking.spec.js.map +7 -0
  133. package/dist/cjs/lib/v3/tests/downloads.spec.js +80 -0
  134. package/dist/cjs/lib/v3/tests/downloads.spec.js.map +7 -0
  135. package/dist/cjs/lib/v3/tests/frame-get-location-and-click.spec.js +53 -0
  136. package/dist/cjs/lib/v3/tests/frame-get-location-and-click.spec.js.map +7 -0
  137. package/dist/cjs/lib/v3/tests/iframe-ctx-addInitScript.spec.js +493 -0
  138. package/dist/cjs/lib/v3/tests/iframe-ctx-addInitScript.spec.js.map +7 -0
  139. package/dist/cjs/lib/v3/tests/keep-alive.child.js +92 -0
  140. package/dist/cjs/lib/v3/tests/keep-alive.child.js.map +7 -0
  141. package/dist/cjs/lib/v3/tests/keep-alive.helpers.js +568 -0
  142. package/dist/cjs/lib/v3/tests/keep-alive.helpers.js.map +7 -0
  143. package/dist/cjs/lib/v3/tests/keep-alive.spec.js +15 -0
  144. package/dist/cjs/lib/v3/tests/keep-alive.spec.js.map +7 -0
  145. package/dist/cjs/lib/v3/tests/keyboard.spec.js +296 -0
  146. package/dist/cjs/lib/v3/tests/keyboard.spec.js.map +7 -0
  147. package/dist/cjs/lib/v3/tests/locator-backend-node-id.spec.js +159 -0
  148. package/dist/cjs/lib/v3/tests/locator-backend-node-id.spec.js.map +7 -0
  149. package/dist/cjs/lib/v3/tests/locator-content-methods.spec.js +191 -0
  150. package/dist/cjs/lib/v3/tests/locator-content-methods.spec.js.map +7 -0
  151. package/dist/cjs/lib/v3/tests/locator-count-iframe.spec.js +108 -0
  152. package/dist/cjs/lib/v3/tests/locator-count-iframe.spec.js.map +7 -0
  153. package/dist/cjs/lib/v3/tests/locator-count.spec.js +71 -0
  154. package/dist/cjs/lib/v3/tests/locator-count.spec.js.map +7 -0
  155. package/dist/cjs/lib/v3/tests/locator-fill.spec.js +118 -0
  156. package/dist/cjs/lib/v3/tests/locator-fill.spec.js.map +7 -0
  157. package/dist/cjs/lib/v3/tests/locator-input-methods.spec.js +136 -0
  158. package/dist/cjs/lib/v3/tests/locator-input-methods.spec.js.map +7 -0
  159. package/dist/cjs/lib/v3/tests/locator-nth.spec.js +157 -0
  160. package/dist/cjs/lib/v3/tests/locator-nth.spec.js.map +7 -0
  161. package/dist/cjs/lib/v3/tests/locator-select-option.spec.js +242 -0
  162. package/dist/cjs/lib/v3/tests/locator-select-option.spec.js.map +7 -0
  163. package/dist/cjs/lib/v3/tests/logger-initialization.spec.js +547 -0
  164. package/dist/cjs/lib/v3/tests/logger-initialization.spec.js.map +7 -0
  165. package/dist/cjs/lib/v3/tests/multi-instance-logger.spec.js +269 -0
  166. package/dist/cjs/lib/v3/tests/multi-instance-logger.spec.js.map +7 -0
  167. package/dist/cjs/lib/v3/tests/nested-div.spec.js +23 -0
  168. package/dist/cjs/lib/v3/tests/nested-div.spec.js.map +7 -0
  169. package/dist/cjs/lib/v3/tests/page-addInitScript.spec.js +90 -0
  170. package/dist/cjs/lib/v3/tests/page-addInitScript.spec.js.map +7 -0
  171. package/dist/cjs/lib/v3/tests/page-console.spec.js +56 -0
  172. package/dist/cjs/lib/v3/tests/page-console.spec.js.map +7 -0
  173. package/dist/cjs/lib/v3/tests/page-drag-and-drop.spec.js +418 -0
  174. package/dist/cjs/lib/v3/tests/page-drag-and-drop.spec.js.map +7 -0
  175. package/dist/cjs/lib/v3/tests/page-goto-response.spec.js +35 -0
  176. package/dist/cjs/lib/v3/tests/page-goto-response.spec.js.map +7 -0
  177. package/dist/cjs/lib/v3/tests/page-hover.spec.js +167 -0
  178. package/dist/cjs/lib/v3/tests/page-hover.spec.js.map +7 -0
  179. package/dist/cjs/lib/v3/tests/page-screenshot.spec.js +295 -0
  180. package/dist/cjs/lib/v3/tests/page-screenshot.spec.js.map +7 -0
  181. package/dist/cjs/lib/v3/tests/page-scroll.spec.js +182 -0
  182. package/dist/cjs/lib/v3/tests/page-scroll.spec.js.map +7 -0
  183. package/dist/cjs/lib/v3/tests/page-send-cdp.spec.js +46 -0
  184. package/dist/cjs/lib/v3/tests/page-send-cdp.spec.js.map +7 -0
  185. package/dist/cjs/lib/v3/tests/perform-understudy-method.spec.js +98 -0
  186. package/dist/cjs/lib/v3/tests/perform-understudy-method.spec.js.map +7 -0
  187. package/dist/cjs/lib/v3/tests/setinputfiles.spec.js +148 -0
  188. package/dist/cjs/lib/v3/tests/setinputfiles.spec.js.map +7 -0
  189. package/dist/cjs/lib/v3/tests/shadow-iframe-oopif.spec.js +156 -0
  190. package/dist/cjs/lib/v3/tests/shadow-iframe-oopif.spec.js.map +7 -0
  191. package/dist/cjs/lib/v3/tests/shadow-iframe-spif.spec.js +156 -0
  192. package/dist/cjs/lib/v3/tests/shadow-iframe-spif.spec.js.map +7 -0
  193. package/dist/cjs/lib/v3/tests/testUtils.js +54 -0
  194. package/dist/cjs/lib/v3/tests/testUtils.js.map +7 -0
  195. package/dist/cjs/lib/v3/tests/text-selector-innermost.spec.js +100 -0
  196. package/dist/cjs/lib/v3/tests/text-selector-innermost.spec.js.map +7 -0
  197. package/dist/cjs/lib/v3/tests/timeouts.spec.js +32 -0
  198. package/dist/cjs/lib/v3/tests/timeouts.spec.js.map +7 -0
  199. package/dist/cjs/lib/v3/tests/user-data-dir.spec.js +65 -0
  200. package/dist/cjs/lib/v3/tests/user-data-dir.spec.js.map +7 -0
  201. package/dist/cjs/lib/v3/tests/v3.config.js +36 -0
  202. package/dist/cjs/lib/v3/tests/v3.config.js.map +7 -0
  203. package/dist/cjs/lib/v3/tests/v3.dynamic.config.js +67 -0
  204. package/dist/cjs/lib/v3/tests/v3.dynamic.config.js.map +7 -0
  205. package/dist/cjs/lib/v3/tests/v3.playwright.config.js +61 -0
  206. package/dist/cjs/lib/v3/tests/v3.playwright.config.js.map +7 -0
  207. package/dist/cjs/lib/v3/tests/wait-for-selector.spec.js +593 -0
  208. package/dist/cjs/lib/v3/tests/wait-for-selector.spec.js.map +7 -0
  209. package/dist/cjs/lib/v3/tests/wait-for-timeout.spec.js +97 -0
  210. package/dist/cjs/lib/v3/tests/wait-for-timeout.spec.js.map +7 -0
  211. package/dist/cjs/lib/v3/tests/xpath-for-location-deep.spec.js +77 -0
  212. package/dist/cjs/lib/v3/tests/xpath-for-location-deep.spec.js.map +7 -0
  213. package/dist/cjs/lib/v3/timeoutConfig.d.ts +2 -0
  214. package/dist/cjs/lib/v3/types/private/agent.d.ts +6 -0
  215. package/dist/cjs/lib/v3/types/private/api.d.ts +11 -0
  216. package/dist/cjs/lib/v3/types/private/cache.d.ts +128 -0
  217. package/dist/cjs/lib/v3/types/private/evaluator.d.ts +40 -0
  218. package/dist/cjs/lib/v3/types/private/handlers.d.ts +38 -0
  219. package/dist/cjs/lib/v3/types/private/index.d.ts +7 -0
  220. package/dist/cjs/lib/v3/types/private/internal.d.ts +39 -0
  221. package/dist/cjs/lib/v3/types/private/locator.d.ts +9 -0
  222. package/dist/cjs/lib/v3/types/private/network.d.ts +34 -0
  223. package/dist/cjs/lib/v3/types/private/shutdown.d.ts +19 -0
  224. package/dist/cjs/lib/v3/types/private/shutdownErrors.d.ts +12 -0
  225. package/dist/cjs/lib/v3/types/private/snapshot.d.ts +117 -0
  226. package/dist/cjs/lib/v3/types/public/agent.d.ts +595 -0
  227. package/dist/cjs/lib/v3/types/public/api.d.ts +1211 -0
  228. package/dist/cjs/lib/v3/types/public/apiErrors.d.ts +18 -0
  229. package/dist/cjs/lib/v3/types/public/index.d.ts +12 -0
  230. package/dist/cjs/lib/v3/types/public/locator.d.ts +9 -0
  231. package/dist/cjs/lib/v3/types/public/logs.d.ts +23 -0
  232. package/dist/cjs/lib/v3/types/public/methods.d.ts +56 -0
  233. package/dist/cjs/lib/v3/types/public/metrics.d.ts +27 -0
  234. package/dist/cjs/lib/v3/types/public/model.d.ts +65 -0
  235. package/dist/cjs/lib/v3/types/public/options.d.ts +70 -0
  236. package/dist/cjs/lib/v3/types/public/page.d.ts +18 -0
  237. package/dist/cjs/lib/v3/types/public/screenshotTypes.d.ts +25 -0
  238. package/dist/cjs/lib/v3/types/public/sdkErrors.d.ts +152 -0
  239. package/dist/cjs/lib/v3/understudy/a11y/snapshot/a11yTree.d.ts +15 -0
  240. package/dist/cjs/lib/v3/understudy/a11y/snapshot/activeElement.d.ts +8 -0
  241. package/dist/cjs/lib/v3/understudy/a11y/snapshot/capture.d.ts +77 -0
  242. package/dist/cjs/lib/v3/understudy/a11y/snapshot/coordinateResolver.d.ts +7 -0
  243. package/dist/cjs/lib/v3/understudy/a11y/snapshot/domTree.d.ts +46 -0
  244. package/dist/cjs/lib/v3/understudy/a11y/snapshot/focusSelectors.d.ts +24 -0
  245. package/dist/cjs/lib/v3/understudy/a11y/snapshot/index.d.ts +4 -0
  246. package/dist/cjs/lib/v3/understudy/a11y/snapshot/sessions.d.ts +16 -0
  247. package/dist/cjs/lib/v3/understudy/a11y/snapshot/treeFormatUtils.d.ts +28 -0
  248. package/dist/cjs/lib/v3/understudy/a11y/snapshot/xpathUtils.d.ts +26 -0
  249. package/dist/cjs/lib/v3/understudy/a11yInvocation.d.ts +8 -0
  250. package/dist/cjs/lib/v3/understudy/cdp.d.ts +69 -0
  251. package/dist/cjs/lib/v3/understudy/consoleMessage.d.ts +22 -0
  252. package/dist/cjs/lib/v3/understudy/context.d.ts +132 -0
  253. package/dist/cjs/lib/v3/understudy/deepLocator.d.ts +87 -0
  254. package/dist/cjs/lib/v3/understudy/executionContextRegistry.d.ts +15 -0
  255. package/dist/cjs/lib/v3/understudy/fileUploadUtils.d.ts +13 -0
  256. package/dist/cjs/lib/v3/understudy/frame.d.ts +69 -0
  257. package/dist/cjs/lib/v3/understudy/frameLocator.d.ts +50 -0
  258. package/dist/cjs/lib/v3/understudy/frameRegistry.d.ts +101 -0
  259. package/dist/cjs/lib/v3/understudy/initScripts.d.ts +2 -0
  260. package/dist/cjs/lib/v3/understudy/lifecycleWatcher.d.ts +64 -0
  261. package/dist/cjs/lib/v3/understudy/locator.d.ts +194 -0
  262. package/dist/cjs/lib/v3/understudy/locatorInvocation.d.ts +8 -0
  263. package/dist/cjs/lib/v3/understudy/navigationResponseTracker.d.ts +84 -0
  264. package/dist/cjs/lib/v3/understudy/networkManager.d.ts +53 -0
  265. package/dist/cjs/lib/v3/understudy/page.d.ts +354 -0
  266. package/dist/cjs/lib/v3/understudy/piercer.d.ts +4 -0
  267. package/dist/cjs/lib/v3/understudy/response.d.ts +137 -0
  268. package/dist/cjs/lib/v3/understudy/screenshotUtils.d.ts +16 -0
  269. package/dist/cjs/lib/v3/understudy/selectorResolver.d.ts +38 -0
  270. package/dist/cjs/lib/v3/v3.d.ts +191 -0
  271. package/dist/cjs/lib/v3/zodCompat.d.ts +12 -0
  272. package/dist/cjs/lib/v3Evaluator.d.ts +19 -0
  273. package/dist/cjs/lib/version.d.ts +5 -0
  274. package/dist/cjs/package.json +3 -0
  275. package/dist/cjs/tests/browserbase-session-accessors.test.js +101 -0
  276. package/dist/cjs/tests/browserbase-session-accessors.test.js.map +7 -0
  277. package/dist/cjs/tests/cache-llm-resolution.test.js +187 -0
  278. package/dist/cjs/tests/cache-llm-resolution.test.js.map +7 -0
  279. package/dist/cjs/tests/helpers/mockCDPSession.js +50 -0
  280. package/dist/cjs/tests/helpers/mockCDPSession.js.map +7 -0
  281. package/dist/cjs/tests/llm-provider.test.js +57 -0
  282. package/dist/cjs/tests/llm-provider.test.js.map +7 -0
  283. package/dist/cjs/tests/model-deprecation.test.js +132 -0
  284. package/dist/cjs/tests/model-deprecation.test.js.map +7 -0
  285. package/dist/cjs/tests/page-snapshot.test.js +58 -0
  286. package/dist/cjs/tests/page-snapshot.test.js.map +7 -0
  287. package/dist/cjs/tests/public-api/export-surface.test.js +76 -0
  288. package/dist/cjs/tests/public-api/export-surface.test.js.map +7 -0
  289. package/dist/cjs/tests/public-api/llm-and-agents.test.js +150 -0
  290. package/dist/cjs/tests/public-api/llm-and-agents.test.js.map +7 -0
  291. package/dist/cjs/tests/public-api/public-error-types.test.js +104 -0
  292. package/dist/cjs/tests/public-api/public-error-types.test.js.map +7 -0
  293. package/dist/cjs/tests/public-api/public-types.test.js +74 -0
  294. package/dist/cjs/tests/public-api/public-types.test.js.map +7 -0
  295. package/dist/cjs/tests/public-api/runtime-utils.test.js +53 -0
  296. package/dist/cjs/tests/public-api/runtime-utils.test.js.map +7 -0
  297. package/dist/cjs/tests/public-api/schema-utils.test.js +100 -0
  298. package/dist/cjs/tests/public-api/schema-utils.test.js.map +7 -0
  299. package/dist/cjs/tests/public-api/timeout-error-types.test.js +103 -0
  300. package/dist/cjs/tests/public-api/timeout-error-types.test.js.map +7 -0
  301. package/dist/cjs/tests/public-api/tool-type-export.test.js +47 -0
  302. package/dist/cjs/tests/public-api/tool-type-export.test.js.map +7 -0
  303. package/dist/cjs/tests/public-api/v3-core.test.js +104 -0
  304. package/dist/cjs/tests/public-api/v3-core.test.js.map +7 -0
  305. package/dist/cjs/tests/safety-confirmation.test.js +134 -0
  306. package/dist/cjs/tests/safety-confirmation.test.js.map +7 -0
  307. package/dist/cjs/tests/snapshot-a11y-resolvers.test.js +370 -0
  308. package/dist/cjs/tests/snapshot-a11y-resolvers.test.js.map +7 -0
  309. package/dist/cjs/tests/snapshot-a11y-tree-utils.test.js +294 -0
  310. package/dist/cjs/tests/snapshot-a11y-tree-utils.test.js.map +7 -0
  311. package/dist/cjs/tests/snapshot-capture-orchestration.test.js +403 -0
  312. package/dist/cjs/tests/snapshot-capture-orchestration.test.js.map +7 -0
  313. package/dist/cjs/tests/snapshot-cbor.test.js +197 -0
  314. package/dist/cjs/tests/snapshot-cbor.test.js.map +7 -0
  315. package/dist/cjs/tests/snapshot-dom-session-builders.test.js +246 -0
  316. package/dist/cjs/tests/snapshot-dom-session-builders.test.js.map +7 -0
  317. package/dist/cjs/tests/snapshot-dom-tree-utils.test.js +104 -0
  318. package/dist/cjs/tests/snapshot-dom-tree-utils.test.js.map +7 -0
  319. package/dist/cjs/tests/snapshot-focus-selectors-utils.test.js +45 -0
  320. package/dist/cjs/tests/snapshot-focus-selectors-utils.test.js.map +7 -0
  321. package/dist/cjs/tests/snapshot-frame-merge.test.js +388 -0
  322. package/dist/cjs/tests/snapshot-frame-merge.test.js.map +7 -0
  323. package/dist/cjs/tests/snapshot-tree-format-utils.test.js +106 -0
  324. package/dist/cjs/tests/snapshot-tree-format-utils.test.js.map +7 -0
  325. package/dist/cjs/tests/snapshot-xpath-utils.test.js +74 -0
  326. package/dist/cjs/tests/snapshot-xpath-utils.test.js.map +7 -0
  327. package/dist/cjs/tests/timeout-handlers.test.js +864 -0
  328. package/dist/cjs/tests/timeout-handlers.test.js.map +7 -0
  329. package/dist/cjs/tests/xpath-parser.test.js +314 -0
  330. package/dist/cjs/tests/xpath-parser.test.js.map +7 -0
  331. package/dist/cjs/tests/xpath-resolver.test.js +70 -0
  332. package/dist/cjs/tests/xpath-resolver.test.js.map +7 -0
  333. package/dist/cjs/tests/zod-enum-compatibility.test.js +119 -0
  334. package/dist/cjs/tests/zod-enum-compatibility.test.js.map +7 -0
  335. package/dist/esm/lib/modelUtils.d.ts +0 -3
  336. package/dist/esm/lib/modelUtils.js +2 -7
  337. package/dist/esm/lib/modelUtils.js.map +1 -1
  338. package/dist/esm/lib/v3/agent/tools/act.d.ts +1 -2
  339. package/dist/esm/lib/v3/agent/tools/act.js.map +1 -1
  340. package/dist/esm/lib/v3/agent/tools/extract.d.ts +1 -2
  341. package/dist/esm/lib/v3/agent/tools/extract.js.map +1 -1
  342. package/dist/esm/lib/v3/agent/tools/fillform.d.ts +1 -2
  343. package/dist/esm/lib/v3/agent/tools/fillform.js.map +1 -1
  344. package/dist/esm/lib/v3/agent/tools/index.d.ts +2 -2
  345. package/dist/esm/lib/v3/agent/tools/index.js.map +1 -1
  346. package/dist/esm/lib/v3/cli.d.ts +2 -0
  347. package/dist/esm/lib/v3/cli.js +10 -0
  348. package/dist/esm/lib/v3/cli.js.map +1 -0
  349. package/dist/esm/lib/v3/dom/build/rerender-index.d.ts +0 -0
  350. package/dist/esm/lib/v3/dom/build/rerender-index.js.map +1 -0
  351. package/dist/esm/lib/v3/dom/build/v3-index.d.ts +0 -0
  352. package/dist/esm/lib/v3/dom/build/v3-index.js.map +1 -0
  353. package/dist/esm/lib/v3/handlers/v3AgentHandler.d.ts +2 -2
  354. package/dist/esm/lib/v3/handlers/v3AgentHandler.js.map +1 -1
  355. package/dist/esm/lib/v3/index.d.ts +1 -0
  356. package/dist/esm/lib/v3/index.js +1 -0
  357. package/dist/esm/lib/v3/index.js.map +1 -1
  358. package/dist/esm/lib/v3/shutdown/supervisor.d.ts +7 -5
  359. package/dist/esm/lib/v3/shutdown/supervisor.js +62 -52
  360. package/dist/esm/lib/v3/shutdown/supervisor.js.map +1 -1
  361. package/dist/esm/lib/v3/shutdown/supervisorClient.js +48 -52
  362. package/dist/esm/lib/v3/shutdown/supervisorClient.js.map +1 -1
  363. package/dist/esm/lib/v3/tests/click-count.spec.js +47 -12
  364. package/dist/esm/lib/v3/tests/click-count.spec.js.map +2 -2
  365. package/dist/esm/lib/v3/tests/iframe-ctx-addInitScript.spec.js +67 -21
  366. package/dist/esm/lib/v3/tests/iframe-ctx-addInitScript.spec.js.map +2 -2
  367. package/dist/esm/lib/v3/tests/v3.playwright.config.js +3 -60
  368. package/dist/esm/lib/v3/tests/v3.playwright.config.js.map +2 -2
  369. package/dist/esm/lib/v3/types/private/shutdown.d.ts +1 -13
  370. package/dist/esm/lib/v3/types/private/shutdown.js.map +1 -1
  371. package/dist/esm/lib/v3/understudy/context.js +10 -1
  372. package/dist/esm/lib/v3/understudy/context.js.map +1 -1
  373. package/dist/esm/lib/v3/understudy/locator.js +2 -2
  374. package/dist/esm/lib/v3/understudy/locator.js.map +1 -1
  375. package/dist/esm/lib/v3/understudy/page.js +2 -1
  376. package/dist/esm/lib/v3/understudy/page.js.map +1 -1
  377. package/dist/esm/lib/v3/v3.js +10 -13
  378. package/dist/esm/lib/v3/v3.js.map +1 -1
  379. package/dist/esm/tests/public-api/export-surface.test.js +1 -0
  380. package/dist/esm/tests/public-api/export-surface.test.js.map +2 -2
  381. package/package.json +13 -9
  382. package/dist/esm/lib/v3/tests/envReporter.js +0 -57
  383. package/dist/esm/lib/v3/tests/envReporter.js.map +0 -7
  384. package/dist/esm/tests/agent-execution-model.test.js +0 -139
  385. package/dist/esm/tests/agent-execution-model.test.js.map +0 -7
  386. package/dist/esm/tests/model-utils.test.js +0 -43
  387. package/dist/esm/tests/model-utils.test.js.map +0 -7
@@ -0,0 +1,119 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __copyProps = (to, from, except, desc) => {
8
+ if (from && typeof from === "object" || typeof from === "function") {
9
+ for (let key of __getOwnPropNames(from))
10
+ if (!__hasOwnProp.call(to, key) && key !== except)
11
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
+ }
13
+ return to;
14
+ };
15
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
16
+ // If the importer is in node compatibility mode or this is not an ESM
17
+ // file that has been converted to a CommonJS file using a Babel-
18
+ // compatible transform (i.e. "__esModule" has not been set), then set
19
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
23
+ var import_vitest = require("vitest");
24
+ var z3 = __toESM(require("zod/v3"), 1);
25
+ var import_zod = require("zod");
26
+ var import_handlers = require("../lib/v3/types/private/handlers.js");
27
+ (0, import_vitest.describe)("SupportedUnderstudyAction enum Zod compatibility", () => {
28
+ const testInput = {
29
+ elementId: "1-2",
30
+ method: "click",
31
+ arguments: []
32
+ };
33
+ const invalidInput = {
34
+ elementId: "1-2",
35
+ method: "invalidMethod",
36
+ arguments: []
37
+ };
38
+ (0, import_vitest.it)("Object.values(SupportedUnderstudyAction) produces correct array for z.enum()", () => {
39
+ const enumValues = Object.values(
40
+ import_handlers.SupportedUnderstudyAction
41
+ );
42
+ (0, import_vitest.expect)(enumValues).toContain("click");
43
+ (0, import_vitest.expect)(enumValues).toContain("fill");
44
+ (0, import_vitest.expect)(enumValues).toContain("type");
45
+ (0, import_vitest.expect)(enumValues).toContain("press");
46
+ (0, import_vitest.expect)(enumValues).toContain("scrollTo");
47
+ (0, import_vitest.expect)(enumValues).toContain("nextChunk");
48
+ (0, import_vitest.expect)(enumValues).toContain("prevChunk");
49
+ (0, import_vitest.expect)(enumValues).toContain("selectOptionFromDropdown");
50
+ (0, import_vitest.expect)(enumValues).toContain("hover");
51
+ (0, import_vitest.expect)(enumValues).toContain("doubleClick");
52
+ (0, import_vitest.expect)(enumValues).toContain("dragAndDrop");
53
+ (0, import_vitest.expect)(enumValues.length).toBe(11);
54
+ });
55
+ (0, import_vitest.it)("Zod v3 z.enum() with Object.values(SupportedUnderstudyAction) works correctly", () => {
56
+ const enumValues = Object.values(
57
+ import_handlers.SupportedUnderstudyAction
58
+ );
59
+ const schema = z3.z.object({
60
+ elementId: z3.z.string(),
61
+ method: z3.z.enum(enumValues),
62
+ arguments: z3.z.array(z3.z.string())
63
+ });
64
+ const validResult = schema.safeParse(testInput);
65
+ (0, import_vitest.expect)(validResult.success).toBe(true);
66
+ if (validResult.success) {
67
+ (0, import_vitest.expect)(validResult.data.method).toBe("click");
68
+ }
69
+ const invalidResult = schema.safeParse(invalidInput);
70
+ (0, import_vitest.expect)(invalidResult.success).toBe(false);
71
+ });
72
+ (0, import_vitest.it)("Zod v4 z.enum() with Object.values(SupportedUnderstudyAction) works correctly", () => {
73
+ const enumValues = Object.values(
74
+ import_handlers.SupportedUnderstudyAction
75
+ );
76
+ const schema = import_zod.z.object({
77
+ elementId: import_zod.z.string(),
78
+ method: import_zod.z.enum(enumValues),
79
+ arguments: import_zod.z.array(import_zod.z.string())
80
+ });
81
+ const validResult = schema.safeParse(testInput);
82
+ (0, import_vitest.expect)(validResult.success).toBe(true);
83
+ if (validResult.success) {
84
+ (0, import_vitest.expect)(validResult.data.method).toBe("click");
85
+ }
86
+ const invalidResult = schema.safeParse(invalidInput);
87
+ (0, import_vitest.expect)(invalidResult.success).toBe(false);
88
+ });
89
+ (0, import_vitest.it)("Zod v3 z.enum() with raw TypeScript enum throws error on parse", () => {
90
+ const schema = z3.z.object({
91
+ elementId: z3.z.string(),
92
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
93
+ method: z3.z.enum(import_handlers.SupportedUnderstudyAction),
94
+ arguments: z3.z.array(z3.z.string())
95
+ });
96
+ (0, import_vitest.expect)(() => schema.safeParse(testInput)).toThrow("object is not iterable");
97
+ });
98
+ (0, import_vitest.it)("Zod v4 z.enum() with raw TypeScript enum works (but not v3 compatible)", () => {
99
+ const schema = import_zod.z.object({
100
+ elementId: import_zod.z.string(),
101
+ method: import_zod.z.enum(import_handlers.SupportedUnderstudyAction),
102
+ arguments: import_zod.z.array(import_zod.z.string())
103
+ });
104
+ const validResult = schema.safeParse(testInput);
105
+ (0, import_vitest.expect)(validResult.success).toBe(true);
106
+ });
107
+ (0, import_vitest.it)("All SupportedUnderstudyAction values are valid enum options", () => {
108
+ const enumValues = Object.values(
109
+ import_handlers.SupportedUnderstudyAction
110
+ );
111
+ const v3Schema = z3.z.enum(enumValues);
112
+ const v4Schema = import_zod.z.enum(enumValues);
113
+ for (const action of enumValues) {
114
+ (0, import_vitest.expect)(v3Schema.safeParse(action).success).toBe(true);
115
+ (0, import_vitest.expect)(v4Schema.safeParse(action).success).toBe(true);
116
+ }
117
+ });
118
+ });
119
+ //# sourceMappingURL=zod-enum-compatibility.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../tests/zod-enum-compatibility.test.ts"],
4
+ "sourcesContent": ["import { describe, expect, it } from \"vitest\";\nimport * as z3 from \"zod/v3\";\nimport { z as z4 } from \"zod\";\nimport { SupportedUnderstudyAction } from \"../lib/v3/types/private/handlers.js\";\n\n/**\n * Tests for Zod v3/v4 compatibility with the SupportedUnderstudyAction enum.\n *\n * This test ensures that z.enum() works correctly with both Zod v3 and v4.\n * The key issue is that z.enum() in Zod v3 does NOT accept TypeScript enums directly -\n * it only accepts string literal tuples. For TypeScript enums, you need to use\n * Object.values() to convert the enum to an array first.\n *\n * In Zod v4, z.enum() was updated to accept TypeScript enums directly, but for\n * backwards compatibility, we should use Object.values() which works with both.\n *\n * See PR #1613: https://github.com/browserbase/stagehand/pull/1613\n */\ndescribe(\"SupportedUnderstudyAction enum Zod compatibility\", () => {\n const testInput = {\n elementId: \"1-2\",\n method: \"click\",\n arguments: [] as string[],\n };\n\n const invalidInput = {\n elementId: \"1-2\",\n method: \"invalidMethod\",\n arguments: [] as string[],\n };\n\n it(\"Object.values(SupportedUnderstudyAction) produces correct array for z.enum()\", () => {\n const enumValues = Object.values(\n SupportedUnderstudyAction,\n ) as unknown as readonly [string, ...string[]];\n\n expect(enumValues).toContain(\"click\");\n expect(enumValues).toContain(\"fill\");\n expect(enumValues).toContain(\"type\");\n expect(enumValues).toContain(\"press\");\n expect(enumValues).toContain(\"scrollTo\");\n expect(enumValues).toContain(\"nextChunk\");\n expect(enumValues).toContain(\"prevChunk\");\n expect(enumValues).toContain(\"selectOptionFromDropdown\");\n expect(enumValues).toContain(\"hover\");\n expect(enumValues).toContain(\"doubleClick\");\n expect(enumValues).toContain(\"dragAndDrop\");\n expect(enumValues.length).toBe(11);\n });\n\n it(\"Zod v3 z.enum() with Object.values(SupportedUnderstudyAction) works correctly\", () => {\n const enumValues = Object.values(\n SupportedUnderstudyAction,\n ) as unknown as readonly [string, ...string[]];\n\n const schema = z3.z.object({\n elementId: z3.z.string(),\n method: z3.z.enum(enumValues),\n arguments: z3.z.array(z3.z.string()),\n });\n\n // Valid input should pass\n const validResult = schema.safeParse(testInput);\n expect(validResult.success).toBe(true);\n if (validResult.success) {\n expect(validResult.data.method).toBe(\"click\");\n }\n\n // Invalid input should fail\n const invalidResult = schema.safeParse(invalidInput);\n expect(invalidResult.success).toBe(false);\n });\n\n it(\"Zod v4 z.enum() with Object.values(SupportedUnderstudyAction) works correctly\", () => {\n const enumValues = Object.values(\n SupportedUnderstudyAction,\n ) as unknown as readonly [string, ...string[]];\n\n const schema = z4.object({\n elementId: z4.string(),\n method: z4.enum(enumValues),\n arguments: z4.array(z4.string()),\n });\n\n // Valid input should pass\n const validResult = schema.safeParse(testInput);\n expect(validResult.success).toBe(true);\n if (validResult.success) {\n expect(validResult.data.method).toBe(\"click\");\n }\n\n // Invalid input should fail\n const invalidResult = schema.safeParse(invalidInput);\n expect(invalidResult.success).toBe(false);\n });\n\n it(\"Zod v3 z.enum() with raw TypeScript enum throws error on parse\", () => {\n // This demonstrates the bug that PR #1613 would introduce\n // In Zod v3, z.enum() does NOT accept TypeScript enums directly\n // The schema creation might succeed, but parsing will fail\n\n const schema = z3.z.object({\n elementId: z3.z.string(),\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n method: z3.z.enum(SupportedUnderstudyAction as any),\n arguments: z3.z.array(z3.z.string()),\n });\n\n // This should throw an error because the enum is not iterable\n expect(() => schema.safeParse(testInput)).toThrow(\"object is not iterable\");\n });\n\n it(\"Zod v4 z.enum() with raw TypeScript enum works (but not v3 compatible)\", () => {\n // Zod v4 allows passing TypeScript enums directly to z.enum()\n // But this approach is NOT backwards compatible with v3\n\n const schema = z4.object({\n elementId: z4.string(),\n method: z4.enum(SupportedUnderstudyAction),\n arguments: z4.array(z4.string()),\n });\n\n // In v4, this works fine\n const validResult = schema.safeParse(testInput);\n expect(validResult.success).toBe(true);\n });\n\n it(\"All SupportedUnderstudyAction values are valid enum options\", () => {\n const enumValues = Object.values(\n SupportedUnderstudyAction,\n ) as unknown as readonly [string, ...string[]];\n\n // Test with both v3 and v4 schemas\n const v3Schema = z3.z.enum(enumValues);\n const v4Schema = z4.enum(enumValues);\n\n for (const action of enumValues) {\n expect(v3Schema.safeParse(action).success).toBe(true);\n expect(v4Schema.safeParse(action).success).toBe(true);\n }\n });\n});\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA,oBAAqC;AACrC,SAAoB;AACpB,iBAAwB;AACxB,sBAA0C;AAAA,IAe1C,wBAAS,oDAAoD,MAAM;AACjE,QAAM,YAAY;AAAA,IAChB,WAAW;AAAA,IACX,QAAQ;AAAA,IACR,WAAW,CAAC;AAAA,EACd;AAEA,QAAM,eAAe;AAAA,IACnB,WAAW;AAAA,IACX,QAAQ;AAAA,IACR,WAAW,CAAC;AAAA,EACd;AAEA,wBAAG,gFAAgF,MAAM;AACvF,UAAM,aAAa,OAAO;AAAA,MACxB;AAAA,IACF;AAEA,8BAAO,UAAU,EAAE,UAAU,OAAO;AACpC,8BAAO,UAAU,EAAE,UAAU,MAAM;AACnC,8BAAO,UAAU,EAAE,UAAU,MAAM;AACnC,8BAAO,UAAU,EAAE,UAAU,OAAO;AACpC,8BAAO,UAAU,EAAE,UAAU,UAAU;AACvC,8BAAO,UAAU,EAAE,UAAU,WAAW;AACxC,8BAAO,UAAU,EAAE,UAAU,WAAW;AACxC,8BAAO,UAAU,EAAE,UAAU,0BAA0B;AACvD,8BAAO,UAAU,EAAE,UAAU,OAAO;AACpC,8BAAO,UAAU,EAAE,UAAU,aAAa;AAC1C,8BAAO,UAAU,EAAE,UAAU,aAAa;AAC1C,8BAAO,WAAW,MAAM,EAAE,KAAK,EAAE;AAAA,EACnC,CAAC;AAED,wBAAG,iFAAiF,MAAM;AACxF,UAAM,aAAa,OAAO;AAAA,MACxB;AAAA,IACF;AAEA,UAAM,SAAS,GAAG,EAAE,OAAO;AAAA,MACzB,WAAW,GAAG,EAAE,OAAO;AAAA,MACvB,QAAQ,GAAG,EAAE,KAAK,UAAU;AAAA,MAC5B,WAAW,GAAG,EAAE,MAAM,GAAG,EAAE,OA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AAW,WAAAA,EAAG,OAAO;AAAA,MACrB,QAAQ,WAAAA,EAAG,KAAK,yCAAyB;AAAA,MACzC,WAAW,WAAAA,EAAG,MAAM,WAAAA,EAAG,OAAO,CAAC;AAAA,IACjC,CAAC;AAGD,UAAM,cAAc,OAAO,UAAU,SAAS;AAC9C,8BAAO,YAAY,OAAO,EAAE,KAAK,IAAI;AAAA,EACvC,CAAC;AAED,wBAAG,+DAA+D,MAAM;AACtE,UAAM,aAAa,OAAO;AAAA,MACxB;AAAA,IACF;AAGA,UAAM,WAAW,GAAG,EAAE,KAAK,UAAU;AACrC,UAAM,WAAW,WAAAA,EAAG,KAAK,UAAU;AAEnC,eAAW,UAAU,YAAY;AAC/B,gCAAO,SAAS,UAAU,MAAM,EAAE,OAAO,EAAE,KAAK,IAAI;AACpD,gCAAO,SAAS,UAAU,MAAM,EAAE,OAAO,EAAE,KAAK,IAAI;AAAA,IACtD;AAAA,EACF,CAAC;AACH,CAAC;",
6
+ "names": ["z4"]
7
+ }
@@ -1,7 +1,4 @@
1
1
  import { ClientOptions, ModelConfiguration } from "./v3/types/public/model.js";
2
- export declare function extractModelName(model?: string | {
3
- modelName: string;
4
- }): string | undefined;
5
2
  export declare function splitModelName(model: string): {
6
3
  provider: string;
7
4
  modelName: string;
@@ -1,10 +1,4 @@
1
1
  import { AVAILABLE_CUA_MODELS, } from "./v3/types/public/agent.js";
2
- //useful when resolving a model from string or object formats we accept
3
- export function extractModelName(model) {
4
- if (!model)
5
- return undefined;
6
- return typeof model === "string" ? model : model.modelName;
7
- }
8
2
  export function splitModelName(model) {
9
3
  const firstSlashIndex = model.indexOf("/");
10
4
  const provider = model.substring(0, firstSlashIndex);
@@ -12,7 +6,8 @@ export function splitModelName(model) {
12
6
  return { provider, modelName };
13
7
  }
14
8
  export function resolveModel(model) {
15
- const modelString = extractModelName(model);
9
+ // Extract the model string and client options
10
+ const modelString = typeof model === "string" ? model : model.modelName;
16
11
  const clientOptions = typeof model === "string"
17
12
  ? {}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B,QAAQ,GAAG,aAAa,CAAC,QAAkB,CAAC;QAC5C,eAAe,GAAG,WAAW,CAAC,CAAC,2BAA2B;IAC5D,CAAC;SAAM,CAAC;QACN,kCAAkC;QAClC,MAAM,KAAK,GAAG,cAAc,CAAC,WAAW,CAAC,CAAC;QAC1C,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAC1B,eAAe,GAAG,KAAK,CAAC,SAAS,CAAC;IACpC,CAAC;IAED,4BAA4B;IAC5B,MAAM,KAAK,GACT,mBAAmB;QACnB,oBAAoB,CAAC,QAAQ,CAAC,WAAgC,CAAC,CAAC;IAElE,OAAO;QACL,QAAQ;QACR,SAAS,EAAE,eAAe;QAC1B,aAAa;QACb,KAAK;KACN,CAAC;AACJ,CAAC","sourcesContent":["import { ClientOptions, ModelConfiguration } from \"./v3/types/public/model.js\";\nimport {\n AVAILABLE_CUA_MODELS,\n AvailableCuaModel,\n} from \"./v3/types/public/agent.js\";\n\n//useful when resolving a model from string or object formats we accept\nexport function extractModelName(\n model?: string | { modelName: string },\n): string | undefined {\n if (!model) return undefined;\n return typeof model === \"string\" ? model : model.modelName;\n}\n\nexport function splitModelName(model: string): {\n provider: string;\n modelName: string;\n} {\n const firstSlashIndex = model.indexOf(\"/\");\n const provider = model.substring(0, firstSlashIndex);\n const modelName = model.substring(firstSlashIndex + 1);\n return { provider, modelName };\n}\n\nexport function resolveModel(model: string | ModelConfiguration): {\n provider: string;\n modelName: string;\n clientOptions: ClientOptions;\n isCua: boolean;\n} {\n const modelString = extractModelName(model)!;\n const clientOptions =\n typeof model === \"string\"\n ? {}\n : (() => {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { modelName: _, ...rest } = model;\n return rest;\n })();\n\n // Check if provider is explicitly set in clientOptions\n const hasExplicitProvider = clientOptions.provider !== undefined;\n\n // If provider is explicitly set, don't split the model name - pass it through as-is\n let provider: string;\n let parsedModelName: string;\n\n if (hasExplicitProvider) {\n provider = clientOptions.provider as string;\n parsedModelName = modelString; // Keep the full model name\n } else {\n // Parse the model string normally\n const split = splitModelName(modelString);\n provider = split.provider;\n parsedModelName = split.modelName;\n }\n\n // Check if it's a CUA model\n const isCua =\n hasExplicitProvider ||\n AVAILABLE_CUA_MODELS.includes(modelString as AvailableCuaModel);\n\n return {\n provider,\n modelName: parsedModelName,\n clientOptions,\n isCua,\n };\n}\n"]}
1
+ {"version":3,"file":"modelUtils.js","sourceRoot":"","sources":["../../../lib/modelUtils.ts"],"names":[],"mappings":"AACA,OAAO,EACL,oBAAoB,GAErB,MAAM,4BAA4B,CAAC;AAEpC,MAAM,UAAU,cAAc,CAAC,KAAa;IAI1C,MAAM,eAAe,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC3C,MAAM,QAAQ,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC;IACrD,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC,eAAe,GAAG,CAAC,CAAC,CAAC;IACvD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAkC;IAM7D,8CAA8C;IAC9C,MAAM,WAAW,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC;IACxE,MAAM,aAAa,GACjB,OAAO,KAAK,KAAK,QAAQ;QACvB,CAAC,CAAC,EAAE;QACJ,CAAC,CAAC,CAAC,GAAG,EAAE;YACJ,6DAA6D;YAC7D,MAAM,EAAE,SAAS,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;YACxC,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,EAAE,CAAC;IAEX,uDAAuD;IACvD,MAAM,mBAAmB,GAAG,aAAa,CAAC,QAAQ,KAAK,SAAS,CAAC;IAEjE,oFAAoF;IACpF,IAAI,QAAgB,CAAC;IACrB,IAAI,eAAuB,CAAC;IAE5B,IAAI,mBAAmB,EAAE,CAAC;QACxB,QAAQ,GAAG,aAAa,CAAC,QAAkB,CAAC;QAC5C,eAAe,GAAG,WAAW,CAAC,CAAC,2BAA2B;IAC5D,CAAC;SAAM,CAAC;QACN,kCAAkC;QAClC,MAAM,KAAK,GAAG,cAAc,CAAC,WAAW,CAAC,CAAC;QAC1C,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAC1B,eAAe,GAAG,KAAK,CAAC,SAAS,CAAC;IACpC,CAAC;IAED,4BAA4B;IAC5B,MAAM,KAAK,GACT,mBAAmB;QACnB,oBAAoB,CAAC,QAAQ,CAAC,WAAgC,CAAC,CAAC;IAElE,OAAO;QACL,QAAQ;QACR,SAAS,EAAE,eAAe;QAC1B,aAAa;QACb,KAAK;KACN,CAAC;AACJ,CAAC","sourcesContent":["import { ClientOptions, ModelConfiguration } from \"./v3/types/public/model.js\";\nimport {\n AVAILABLE_CUA_MODELS,\n AvailableCuaModel,\n} from \"./v3/types/public/agent.js\";\n\nexport function splitModelName(model: string): {\n provider: string;\n modelName: string;\n} {\n const firstSlashIndex = model.indexOf(\"/\");\n const provider = model.substring(0, firstSlashIndex);\n const modelName = model.substring(firstSlashIndex + 1);\n return { provider, modelName };\n}\n\nexport function resolveModel(model: string | ModelConfiguration): {\n provider: string;\n modelName: string;\n clientOptions: ClientOptions;\n isCua: boolean;\n} {\n // Extract the model string and client options\n const modelString = typeof model === \"string\" ? model : model.modelName;\n const clientOptions =\n typeof model === \"string\"\n ? {}\n : (() => {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { modelName: _, ...rest } = model;\n return rest;\n })();\n\n // Check if provider is explicitly set in clientOptions\n const hasExplicitProvider = clientOptions.provider !== undefined;\n\n // If provider is explicitly set, don't split the model name - pass it through as-is\n let provider: string;\n let parsedModelName: string;\n\n if (hasExplicitProvider) {\n provider = clientOptions.provider as string;\n parsedModelName = modelString; // Keep the full model name\n } else {\n // Parse the model string normally\n const split = splitModelName(modelString);\n provider = split.provider;\n parsedModelName = split.modelName;\n }\n\n // Check if it's a CUA model\n const isCua =\n hasExplicitProvider ||\n AVAILABLE_CUA_MODELS.includes(modelString as AvailableCuaModel);\n\n return {\n provider,\n modelName: parsedModelName,\n clientOptions,\n isCua,\n };\n}\n"]}
@@ -1,7 +1,6 @@
1
1
  import type { V3 } from "../../v3.js";
2
2
  import type { Action } from "../../types/public/methods.js";
3
- import type { AgentModelConfig } from "../../types/public/agent.js";
4
- export declare const actTool: (v3: V3, executionModel?: string | AgentModelConfig) => import("ai").Tool<{
3
+ export declare const actTool: (v3: V3, executionModel?: string) => import("ai").Tool<{
5
4
  action: string;
6
5
  }, {
7
6
  success: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"act.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/tools/act.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,EAAM,EAAE,cAA0C,EAAE,EAAE,CAC5E,IAAI,CAAC;IACH,WAAW,EACT,+GAA+G;IACjH,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;QACpB,MAAM,EAAE,CAAC;aACN,MAAM,EAAE;aACR,QAAQ,CACP,0GAA0G,CAC3G;KACJ,CAAC;IACF,OAAO,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;QAC5B,IAAI,CAAC;YACH,EAAE,CAAC,MAAM,CAAC;gBACR,QAAQ,EAAE,OAAO;gBACjB,OAAO,EAAE,yBAAyB;gBAClC,KAAK,EAAE,CAAC;gBACR,SAAS,EAAE;oBACT,SAAS,EAAE;wBACT,KAAK,EAAE,MAAM;wBACb,IAAI,EAAE,QAAQ;qBACf;iBACF;aACF,CAAC,CAAC;YACH,MAAM,OAAO,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;YACvE,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YAC7C,MAAM,OAAO,GAAI,MAAM,CAAC,OAAgC,IAAI,EAAE,CAAC;YAC/D,EAAE,CAAC,qBAAqB,CAAC;gBACvB,IAAI,EAAE,KAAK;gBACX,WAAW,EAAE,MAAM;gBACnB,OAAO;gBACP,iBAAiB,EAAE,MAAM,CAAC,iBAAiB;gBAC3C,OAAO,EAAE,MAAM,CAAC,OAAO;aACxB,CAAC,CAAC;YACH,sDAAsD;YACtD,6DAA6D;YAC7D,MAAM,QAAQ,GAIV;gBACF,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,IAAI;gBAC/B,MAAM,EAAE,MAAM,EAAE,iBAAiB,IAAI,MAAM;aAC5C,CAAC;YACF,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACvB,QAAQ,CAAC,mBAAmB,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;YAC5C,CAAC;YACD,OAAO,QAAQ,CAAC;QAClB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QACpE,CAAC;IACH,CAAC;CACF,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 } from \"../../types/public/agent.js\";\n\nexport const actTool = (v3: V3, executionModel?: string | AgentModelConfig) =>\n tool({\n description:\n \"Perform an action on the page (click, type). Provide a short, specific phrase that mentions the element type.\",\n inputSchema: z.object({\n action: z\n .string()\n .describe(\n 'Describe what to click or type, e.g. \"click the Login button\" or \"type \"John\" into the first name input\"',\n ),\n }),\n execute: async ({ action }) => {\n try {\n v3.logger({\n category: \"agent\",\n message: `Agent calling tool: act`,\n level: 1,\n auxiliary: {\n arguments: {\n value: action,\n type: \"string\",\n },\n },\n });\n const options = executionModel ? { model: executionModel } : undefined;\n const result = await v3.act(action, options);\n const actions = (result.actions as Action[] | undefined) ?? [];\n v3.recordAgentReplayStep({\n type: \"act\",\n instruction: action,\n actions,\n actionDescription: result.actionDescription,\n message: result.message,\n });\n // Only include playwrightArguments when actions exist\n // (undefined is not valid JSON and breaks AI SDK validation)\n const response: {\n success: boolean;\n action: string;\n playwrightArguments?: Action;\n } = {\n success: result.success ?? true,\n action: result?.actionDescription ?? action,\n };\n if (actions.length > 0) {\n response.playwrightArguments = actions[0];\n }\n return response;\n } catch (error) {\n return { success: false, error: error?.message ?? String(error) };\n }\n },\n });\n"]}
1
+ {"version":3,"file":"act.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/tools/act.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,EAAM,EAAE,cAAuB,EAAE,EAAE,CACzD,IAAI,CAAC;IACH,WAAW,EACT,+GAA+G;IACjH,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;QACpB,MAAM,EAAE,CAAC;aACN,MAAM,EAAE;aACR,QAAQ,CACP,0GAA0G,CAC3G;KACJ,CAAC;IACF,OAAO,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;QAC5B,IAAI,CAAC;YACH,EAAE,CAAC,MAAM,CAAC;gBACR,QAAQ,EAAE,OAAO;gBACjB,OAAO,EAAE,yBAAyB;gBAClC,KAAK,EAAE,CAAC;gBACR,SAAS,EAAE;oBACT,SAAS,EAAE;wBACT,KAAK,EAAE,MAAM;wBACb,IAAI,EAAE,QAAQ;qBACf;iBACF;aACF,CAAC,CAAC;YACH,MAAM,OAAO,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;YACvE,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YAC7C,MAAM,OAAO,GAAI,MAAM,CAAC,OAAgC,IAAI,EAAE,CAAC;YAC/D,EAAE,CAAC,qBAAqB,CAAC;gBACvB,IAAI,EAAE,KAAK;gBACX,WAAW,EAAE,MAAM;gBACnB,OAAO;gBACP,iBAAiB,EAAE,MAAM,CAAC,iBAAiB;gBAC3C,OAAO,EAAE,MAAM,CAAC,OAAO;aACxB,CAAC,CAAC;YACH,sDAAsD;YACtD,6DAA6D;YAC7D,MAAM,QAAQ,GAIV;gBACF,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,IAAI;gBAC/B,MAAM,EAAE,MAAM,EAAE,iBAAiB,IAAI,MAAM;aAC5C,CAAC;YACF,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACvB,QAAQ,CAAC,mBAAmB,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;YAC5C,CAAC;YACD,OAAO,QAAQ,CAAC;QAClB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QACpE,CAAC;IACH,CAAC;CACF,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\";\n\nexport const actTool = (v3: V3, executionModel?: string) =>\n tool({\n description:\n \"Perform an action on the page (click, type). Provide a short, specific phrase that mentions the element type.\",\n inputSchema: z.object({\n action: z\n .string()\n .describe(\n 'Describe what to click or type, e.g. \"click the Login button\" or \"type \"John\" into the first name input\"',\n ),\n }),\n execute: async ({ action }) => {\n try {\n v3.logger({\n category: \"agent\",\n message: `Agent calling tool: act`,\n level: 1,\n auxiliary: {\n arguments: {\n value: action,\n type: \"string\",\n },\n },\n });\n const options = executionModel ? { model: executionModel } : undefined;\n const result = await v3.act(action, options);\n const actions = (result.actions as Action[] | undefined) ?? [];\n v3.recordAgentReplayStep({\n type: \"act\",\n instruction: action,\n actions,\n actionDescription: result.actionDescription,\n message: result.message,\n });\n // Only include playwrightArguments when actions exist\n // (undefined is not valid JSON and breaks AI SDK validation)\n const response: {\n success: boolean;\n action: string;\n playwrightArguments?: Action;\n } = {\n success: result.success ?? true,\n action: result?.actionDescription ?? action,\n };\n if (actions.length > 0) {\n response.playwrightArguments = actions[0];\n }\n return response;\n } catch (error) {\n return { success: false, error: error?.message ?? String(error) };\n }\n },\n });\n"]}
@@ -1,6 +1,5 @@
1
1
  import type { V3 } from "../../v3.js";
2
- import type { AgentModelConfig } from "../../types/public/agent.js";
3
- export declare const extractTool: (v3: V3, executionModel?: string | AgentModelConfig) => import("ai").Tool<{
2
+ export declare const extractTool: (v3: V3, executionModel?: string) => import("ai").Tool<{
4
3
  instruction: string;
5
4
  schema?: {
6
5
  [x: string]: unknown;
@@ -1 +1 @@
1
- {"version":3,"file":"extract.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/tools/extract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAc,MAAM,KAAK,CAAC;AAYpC,SAAS,eAAe,CAAC,MAAkB;IACzC,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,MAAM,KAAK,GAA+B,EAAE,CAAC;YAC7C,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;gBACtB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,C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ACnC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,GAAG,GAAG,KAAc,CAAC;YAC3B,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAClE,CAAC;IACH,CAAC;CACF,CAAC,CAAC","sourcesContent":["import { tool } from \"ai\";\nimport { z, ZodTypeAny } from \"zod\";\nimport type { V3 } from \"../../v3.js\";\nimport type { AgentModelConfig } from \"../../types/public/agent.js\";\n\ninterface JsonSchema {\n type?: string;\n properties?: Record<string, JsonSchema>;\n items?: JsonSchema;\n enum?: string[];\n format?: \"url\" | \"email\" | \"uuid\";\n}\n\nfunction jsonSchemaToZod(schema: JsonSchema): ZodTypeAny {\n switch (schema.type) {\n case \"object\": {\n const shape: Record<string, ZodTypeAny> = {};\n if (schema.properties) {\n for (const [key, value] of Object.entries(schema.properties)) {\n shape[key] = jsonSchemaToZod(value);\n }\n }\n return z.object(shape);\n }\n case \"array\":\n return z.array(schema.items ? jsonSchemaToZod(schema.items) : z.any());\n case \"string\": {\n let s = z.string();\n if (schema.format === \"url\") s = s.url();\n if (schema.format === \"email\") s = s.email();\n if (schema.format === \"uuid\") s = s.uuid();\n if (schema.enum && schema.enum.length > 0)\n return z.enum(schema.enum as [string, ...string[]]);\n return s;\n }\n case \"number\":\n case \"integer\":\n return z.number();\n case \"boolean\":\n return z.boolean();\n case \"null\":\n return z.null();\n default:\n return z.any();\n }\n}\n\nexport const extractTool = (\n v3: V3,\n executionModel?: string | AgentModelConfig,\n) =>\n tool({\n description: `Extract structured data from the current page based on a provided schema.\n \n USAGE GUIDELINES:\n - Keep schemas MINIMAL - only include fields essential for the task\n - IMPORTANT: only use this if explicitly asked for structured output. In most scenarios, you should use the aria tree tool over this.\n - For URL fields, use format: \"url\"\n \n EXAMPLES:\n 1. Extract a single value:\n instruction: \"extract the product price\"\n schema: { type: \"object\", properties: { price: { type: \"number\" } } }\n \n 2. Extract multiple fields:\n instruction: \"extract product name and price\"\n schema: { type: \"object\", properties: { name: { type: \"string\" }, price: { type: \"number\" } } }\n \n 3. Extract arrays:\n instruction: \"extract all product names and prices\"\n schema: { type: \"object\", properties: { products: { type: \"array\", items: { type: \"object\", properties: { name: { type: \"string\" }, price: { type: \"number\" } } } } } }\n \n 4. Extract a URL:\n instruction: \"extract the link\"\n schema: { type: \"object\", properties: { url: { type: \"string\", format: \"url\" } } }`,\n inputSchema: z.object({\n instruction: z.string(),\n schema: z\n .object({\n type: z.string().optional(),\n properties: z.record(z.string(), z.unknown()).optional(),\n items: z.unknown().optional(),\n enum: z.array(z.string()).optional(),\n format: z.enum([\"url\", \"email\", \"uuid\"]).optional(),\n })\n .passthrough()\n .optional()\n .describe(\"JSON Schema object describing the structure to extract\"),\n }),\n execute: async ({ instruction, schema }) => {\n try {\n const parsedSchema = schema\n ? jsonSchemaToZod(schema as JsonSchema)\n : undefined;\n const result = await v3.extract(instruction, parsedSchema, {\n ...(executionModel ? { model: executionModel } : {}),\n });\n return { success: true, result };\n } catch (error) {\n const err = error as Error;\n return { success: false, error: err?.message ?? String(error) };\n }\n },\n });\n"]}
1
+ {"version":3,"file":"extract.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/tools/extract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAc,MAAM,KAAK,CAAC;AAWpC,SAAS,eAAe,CAAC,MAAkB;IACzC,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,MAAM,KAAK,GAA+B,EAAE,CAAC;YAC7C,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;gBACtB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;oBAC7D,K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AG,KAAc,CAAC;YAC3B,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAClE,CAAC;IACH,CAAC;CACF,CAAC,CAAC","sourcesContent":["import { tool } from \"ai\";\nimport { z, ZodTypeAny } from \"zod\";\nimport type { V3 } from \"../../v3.js\";\n\ninterface JsonSchema {\n type?: string;\n properties?: Record<string, JsonSchema>;\n items?: JsonSchema;\n enum?: string[];\n format?: \"url\" | \"email\" | \"uuid\";\n}\n\nfunction jsonSchemaToZod(schema: JsonSchema): ZodTypeAny {\n switch (schema.type) {\n case \"object\": {\n const shape: Record<string, ZodTypeAny> = {};\n if (schema.properties) {\n for (const [key, value] of Object.entries(schema.properties)) {\n shape[key] = jsonSchemaToZod(value);\n }\n }\n return z.object(shape);\n }\n case \"array\":\n return z.array(schema.items ? jsonSchemaToZod(schema.items) : z.any());\n case \"string\": {\n let s = z.string();\n if (schema.format === \"url\") s = s.url();\n if (schema.format === \"email\") s = s.email();\n if (schema.format === \"uuid\") s = s.uuid();\n if (schema.enum && schema.enum.length > 0)\n return z.enum(schema.enum as [string, ...string[]]);\n return s;\n }\n case \"number\":\n case \"integer\":\n return z.number();\n case \"boolean\":\n return z.boolean();\n case \"null\":\n return z.null();\n default:\n return z.any();\n }\n}\n\nexport const extractTool = (v3: V3, executionModel?: string) =>\n tool({\n description: `Extract structured data from the current page based on a provided schema.\n \n USAGE GUIDELINES:\n - Keep schemas MINIMAL - only include fields essential for the task\n - IMPORTANT: only use this if explicitly asked for structured output. In most scenarios, you should use the aria tree tool over this.\n - For URL fields, use format: \"url\"\n \n EXAMPLES:\n 1. Extract a single value:\n instruction: \"extract the product price\"\n schema: { type: \"object\", properties: { price: { type: \"number\" } } }\n \n 2. Extract multiple fields:\n instruction: \"extract product name and price\"\n schema: { type: \"object\", properties: { name: { type: \"string\" }, price: { type: \"number\" } } }\n \n 3. Extract arrays:\n instruction: \"extract all product names and prices\"\n schema: { type: \"object\", properties: { products: { type: \"array\", items: { type: \"object\", properties: { name: { type: \"string\" }, price: { type: \"number\" } } } } } }\n \n 4. Extract a URL:\n instruction: \"extract the link\"\n schema: { type: \"object\", properties: { url: { type: \"string\", format: \"url\" } } }`,\n inputSchema: z.object({\n instruction: z.string(),\n schema: z\n .object({\n type: z.string().optional(),\n properties: z.record(z.string(), z.unknown()).optional(),\n items: z.unknown().optional(),\n enum: z.array(z.string()).optional(),\n format: z.enum([\"url\", \"email\", \"uuid\"]).optional(),\n })\n .passthrough()\n .optional()\n .describe(\"JSON Schema object describing the structure to extract\"),\n }),\n execute: async ({ instruction, schema }) => {\n try {\n const parsedSchema = schema\n ? jsonSchemaToZod(schema as JsonSchema)\n : undefined;\n const result = await v3.extract(instruction, parsedSchema, {\n ...(executionModel ? { model: executionModel } : {}),\n });\n return { success: true, result };\n } catch (error) {\n const err = error as Error;\n return { success: false, error: err?.message ?? String(error) };\n }\n },\n });\n"]}
@@ -1,7 +1,6 @@
1
1
  import type { V3 } from "../../v3.js";
2
2
  import type { Action } from "../../types/public/methods.js";
3
- import type { AgentModelConfig } from "../../types/public/agent.js";
4
- export declare const fillFormTool: (v3: V3, executionModel?: string | AgentModelConfig) => import("ai").Tool<{
3
+ export declare const fillFormTool: (v3: V3, executionModel?: string) => import("ai").Tool<{
5
4
  fields: {
6
5
  action: string;
7
6
  value: string;
@@ -1 +1 @@
1
- {"version":3,"file":"fillform.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/tools/fillform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,EAAM,EACN,cAA0C,EAC1C,EAAE,CACF,IAAI,CAAC;IACH,WAAW,EAAE,8GAA8G;IAC3H,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC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C,OAAO,CAAC,EAAE,CAAC;gBACrC,iBAAiB,CAAC,IAAI,CAAC,GAAI,SAAS,CAAC,OAAoB,CAAC,CAAC;YAC7D,CAAC;QACH,CAAC;QACD,EAAE,CAAC,qBAAqB,CAAC;YACvB,IAAI,EAAE,UAAU;YAChB,MAAM;YACN,cAAc;YACd,OAAO,EAAE,iBAAiB;SAC3B,CAAC,CAAC;QACH,OAAO;YACL,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,SAAS;YAClB,mBAAmB,EAAE,iBAAiB;SACvC,CAAC;IACJ,CAAC;CACF,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 } from \"../../types/public/agent.js\";\n\nexport const fillFormTool = (\n v3: V3,\n executionModel?: string | AgentModelConfig,\n) =>\n 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(\"Text to type into the target\"),\n }),\n )\n .min(1, \"Provide at least one field to fill\"),\n }),\n execute: async ({ fields }) => {\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 }\n : undefined;\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 actResult = await v3.act(res);\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 },\n });\n"]}
1
+ {"version":3,"file":"fillform.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/tools/fillform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,EAAM,EAAE,cAAuB,EAAE,EAAE,CAC9D,IAAI,CAAC;IACH,WAAW,EAAE,8GAA8G;IAC3H,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;QACpB,MAAM,EAAE,CAAC;aACN,KAAK,CACJ,CAAC,CAAC,MAAM,CAAC;YACP,MAAM,EAAE,CAAC;iBACN,MAAM,EAAE;iBACR,QAAQ,CACP,oEAAoE,CACrE;YACH,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,8BAA8B,CAAC;SAC3D,CAAC,CACH;aACA,GAAG,CAAC,CAAC,EAAE,oCAAoC,CAAC;KAChD,CAAC;IACF,OAAO,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;QAC5B,EAAE,CAAC,MAAM,CAAC;YACR,QAAQ,EAAE,OAAO;YACjB,OAAO,EAAE,8BAA8B;YACvC,KAAK,EAAE,CAAC;YACR,SAAS,EAAE;gBACT,SAAS,EAAE;oBACT,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;oBAC7B,IAAI,EAAE,QAAQ;iBACf;aACF;SACF,CAAC,CAAC;QACH,MAAM,WAAW,GAAG,yDAAyD,MAAM;aAChF,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;aACpB,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAEhB,MAAM,cAAc,GAAG,cAAc;YACnC,CAAC,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE;YAC3B,CAAC,CAAC,SAAS,CAAC;QACd,MAAM,cAAc,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;QAErE,MAAM,SAAS,GAAG,EAAe,CAAC;QAClC,MAAM,iBAAiB,GAAa,EAAE,CAAC;QACvC,KAAK,MAAM,GAAG,IAAI,cAAc,EAAE,CAAC;YACjC,MAAM,SAAS,GAAG,MAAM,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACpC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAC1B,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;gBACrC,iBAAiB,CAAC,IAAI,CAAC,GAAI,SAAS,CAAC,OAAoB,CAAC,CAAC;YAC7D,CAAC;QACH,CAAC;QACD,EAAE,CAAC,qBAAqB,CAAC;YACvB,IAAI,EAAE,UAAU;YAChB,MAAM;YACN,cAAc;YACd,OAAO,EAAE,iBAAiB;SAC3B,CAAC,CAAC;QACH,OAAO;YACL,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,SAAS;YAClB,mBAAmB,EAAE,iBAAiB;SACvC,CAAC;IACJ,CAAC;CACF,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\";\n\nexport const fillFormTool = (v3: V3, executionModel?: string) =>\n 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(\"Text to type into the target\"),\n }),\n )\n .min(1, \"Provide at least one field to fill\"),\n }),\n execute: async ({ fields }) => {\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 }\n : undefined;\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 actResult = await v3.act(res);\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 },\n });\n"]}
@@ -18,9 +18,9 @@ import { searchTool } from "./search.js";
18
18
  import type { ToolSet, InferUITools } from "ai";
19
19
  import type { V3 } from "../../v3.js";
20
20
  import type { LogLine } from "../../types/public/logs.js";
21
- import type { AgentToolMode, AgentModelConfig } from "../../types/public/agent.js";
21
+ import type { AgentToolMode } from "../../types/public/agent.js";
22
22
  export interface V3AgentToolOptions {
23
- executionModel?: string | AgentModelConfig;
23
+ executionModel?: string;
24
24
  logger?: (message: LogLine) => void;
25
25
  /**
26
26
  * Tool mode determines which set of tools are available.
@@ -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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AAG,UAAU,CAAC,EAAE,CAAC,CAAC;IACnC,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 } from \"./search.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} 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\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\n const allTools: ToolSet = {\n act: actTool(v3, executionModel),\n ariaTree: ariaTreeTool(v3),\n click: clickTool(v3, provider),\n clickAndHold: clickAndHoldTool(v3, provider),\n dragAndDrop: dragAndDropTool(v3, provider),\n extract: extractTool(v3, executionModel),\n fillForm: fillFormTool(v3, executionModel),\n fillFormVision: fillFormVisionTool(v3, provider),\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),\n wait: waitTool(v3, mode),\n };\n\n // Only include search tool if BRAVE_API_KEY is configured\n if (process.env.BRAVE_API_KEY) {\n allTools.search = searchTool(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 as it's only available when BRAVE_API_KEY is configured.\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?: ReturnType<typeof searchTool>;\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
+ {"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,OA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CAAC,CAAC;IACnC,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 } from \"./search.js\";\n\nimport type { ToolSet, InferUITools } from \"ai\";\nimport type { V3 } from \"../../v3.js\";\nimport type { LogLine } from \"../../types/public/logs.js\";\nimport type { AgentToolMode } from \"../../types/public/agent.js\";\n\nexport interface V3AgentToolOptions {\n executionModel?: string;\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\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\n const allTools: ToolSet = {\n act: actTool(v3, executionModel),\n ariaTree: ariaTreeTool(v3),\n click: clickTool(v3, provider),\n clickAndHold: clickAndHoldTool(v3, provider),\n dragAndDrop: dragAndDropTool(v3, provider),\n extract: extractTool(v3, executionModel),\n fillForm: fillFormTool(v3, executionModel),\n fillFormVision: fillFormVisionTool(v3, provider),\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),\n wait: waitTool(v3, mode),\n };\n\n // Only include search tool if BRAVE_API_KEY is configured\n if (process.env.BRAVE_API_KEY) {\n allTools.search = searchTool(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 as it's only available when BRAVE_API_KEY is configured.\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?: ReturnType<typeof searchTool>;\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"]}
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ import process from "node:process";
3
+ import { maybeRunShutdownSupervisorFromArgv } from "./shutdown/supervisor.js";
4
+ // currently the CLI is only used to spawn the shutdown supervisor
5
+ // in the future, we may want to add more CLI commands here
6
+ if (!maybeRunShutdownSupervisorFromArgv(process.argv.slice(2))) {
7
+ console.error("Unsupported stagehand CLI invocation. Expected --supervisor with valid args.");
8
+ process.exit(1);
9
+ }
10
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../../lib/v3/cli.js"],"names":[],"mappings":";AAEA,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,kCAAkC,EAAE,MAAM,0BAA0B,CAAC;AAE9E,kEAAkE;AAClE,2DAA2D;AAC3D,IAAI,CAAC,kCAAkC,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC/D,OAAO,CAAC,KAAK,CACX,8EAA8E,CAC/E,CAAC;IACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC","sourcesContent":["#!/usr/bin/env node\n\nimport process from \"node:process\";\nimport { maybeRunShutdownSupervisorFromArgv } from \"./shutdown/supervisor.js\";\n\n// currently the CLI is only used to spawn the shutdown supervisor\n// in the future, we may want to add more CLI commands here\nif (!maybeRunShutdownSupervisorFromArgv(process.argv.slice(2))) {\n console.error(\n \"Unsupported stagehand CLI invocation. Expected --supervisor with valid args.\",\n );\n process.exit(1);\n}\n"]}
File without changes
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rerender-index.js","sourceRoot":"","sources":["../../../../../../lib/v3/dom/build/rerender-index.js"],"names":[],"mappings":"AAAA,CAAC,GAAE,EAAE,GAAC,SAAS,CAAC,KAAG,IAAG,CAAC;IAAA,IAAI,CAAC,GAAC,MAAM,CAAC,eAAe,CAAC;IAAA,IAAG,CAAC,CAAC,IAAE,OAAO,CAAC,CAAC,aAAa,IAAE,UAAU;QAAC,OAAO;IAAA,IAAI,CAAC,GAAC,EAAE,EAAC,CAAC,GAAC,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,EAAC,UAAU,CAAC,YAAY,CAAC,CAAC;IAAA,OAAK,CAAC,CAAC,QAAQ,EAAE,GAAE,CAAC;QAAA,IAAI,CAAC,GAAC,CAAC,CAAC,WAAW,EAAC,CAAC,GAAC,CAAC,CAAC,OAAO,EAAE,WAAW,EAAE,IAAE,EAAE,CAAC;QAAA,IAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAE,OAAO,cAAc,EAAE,GAAG,IAAE,UAAU,IAAE,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC;YAAC,SAAS;QAAA,IAAI,CAAC,GAAC,CAAC,CAAC,CAAC,CAAC,UAAU,EAAC,CAAC,GAAC,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;QAAA,CAAC,IAAE,CAAC,IAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IAAA,CAAC;IAAA,KAAI,IAAI,CAAC,IAAI,CAAC;QAAC,IAAG,CAAC;YAAA,IAAI,CAAC,GAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;YAAA,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAA;QAAA,CAAC;QAAA,MAAK,CAAC,CAAA,CAAC;IAAA,CAAC,CAAC,KAAK,IAAE,CAAC,CAAC,MAAM,IAAE,OAAO,CAAC,IAAI,CAAC,uBAAuB,EAAC,EAAC,KAAK,EAAC,CAAC,CAAC,MAAM,EAAC,CAAC,CAAA;AAAA,CAAC;AAAA,OAAM,CAAC,EAAC,CAAC;IAAA,OAAO,CAAC,IAAI,CAAC,6BAA6B,EAAC,EAAC,OAAO,EAAC,MAAM,CAAC,CAAC,IAAE,EAAE,CAAC,EAAC,CAAC,CAAA;AAAA,CAAC,CAAA,CAAC,CAAA,CAAC,EAAE,CAAC,CAAA,CAAC,CAAC,EAAE,CAAC","sourcesContent":["(()=>{function s(){try{let o=window.__stagehandV3__;if(!o||typeof o.getClosedRoot!=\"function\")return;let t=[],r=document.createTreeWalker(document,NodeFilter.SHOW_ELEMENT);for(;r.nextNode();){let e=r.currentNode,n=e.tagName?.toLowerCase()??\"\";if(!n.includes(\"-\")||typeof customElements?.get!=\"function\"||!customElements.get(n))continue;let c=!!e.shadowRoot,i=!!o.getClosedRoot(e);c||i||t.push(e)}for(let e of t)try{let n=e.cloneNode(!0);e.replaceWith(n)}catch{}o.stats&&t.length&&console.info(\"[v3-piercer] rerender\",{count:t.length})}catch(o){console.info(\"[v3-piercer] rerender error\",{message:String(o??\"\")})}}s();})();\n"]}
File without changes
@@ -0,0 +1 @@
1
+ {"version":3,"file":"v3-index.js","sourceRoot":"","sources":["../../../../../../lib/v3/dom/build/v3-index.js"],"names":[],"mappings":"AAAA,CAAC,GAAE,EAAE,GAAC,SAAS,CAAC,CAAC,CAAC,GAAC,EAAE,IAAE,IAAI,CAAC,GAAC,CAAC,CAAA,EAAE,GAAC,IAAG,EAAC,UAAU,EAAC,CAAC,EAAC,GAAC,CAAC,CAAC,CAAA,MAAM,CAAC,eAAe,GAAC,EAAC,aAAa,EAAC,CAAC,CAAA,EAAE,CAAA,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAC,KAAK,EAAC,GAAE,EAAE,CAAA,CAAC,EAAC,SAAS,EAAC,CAAC,CAAC,EAAC,GAAG,EAAC,QAAQ,CAAC,IAAI,EAAC,KAAK,EAAC,MAAM,CAAC,GAAG,KAAG,MAAM,EAAC,IAAI,EAAC,CAAC,CAAC,SAAS,EAAC,MAAM,EAAC,CAAC,CAAC,WAAW,EAAC,CAAC,EAAC,CAAA,CAAA,CAAC,EAAC,CAAC,GAAC,OAAO,CAAC,SAAS,CAAC,YAAY,CAAC,CAAA,IAAG,CAAC,CAAC,WAAW,IAAE,CAAC,CAAC,SAAS,EAAC,CAAC;IAAA,CAAC,CAAC,SAAS,CAAC,KAAK,GAAC,CAAC,CAAC,EAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IAAA,OAAM;AAAA,CAAC,CAAA,IAAI,CAAC,GAAC,EAAC,UAAU,EAAC,IAAI,OAAO,EAAC,SAAS,EAAC,CAAC,EAAC,WAAW,EAAC,CAAC,EAAC,KAAK,EAAC,CAAC,CAAC,EAAC,EAAC,CAAC,GAAC,CAAC,EAAC,CAAC,GAAC,UAAS,CAAC,IAAE,IAAI,CAAC,GAAC,CAAC,EAAE,IAAI,IAAE,MAAM,EAAC,CAAC,GAAC,CAAC,CAAC,IAA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AC,qBAAqB,GAAC,CAAC,CAAC,EAAC,CAAC,CAAC,CAAC,CAAC,EAAC,CAAC,CAAC,KAAK,IAAE,OAAO,CAAC,IAAI,CAAC,wBAAwB,EAAC,EAAC,GAAG,EAAC,QAAQ,CAAC,IAAI,EAAC,KAAK,EAAC,MAAM,CAAC,GAAG,KAAG,MAAM,EAAC,UAAU,EAAC,QAAQ,CAAC,UAAU,EAAC,CAAC,CAAA,CAAA,CAAC,CAAA,CAAC,CAAC,EAAC,KAAK,EAAC,CAAC,CAAC,EAAC,WAAW,EAAC,CAAC,CAAC,EAAC,CAAC,CAAC,CAAA,CAAC,CAAC,EAAE,CAAC","sourcesContent":["(()=>{function s(c={}){let r=e=>{let{hostToRoot:o}=e;window.__stagehandV3__={getClosedRoot:a=>o.get(a),stats:()=>({installed:!0,url:location.href,isTop:window.top===window,open:e.openCount,closed:e.closedCount})}},n=Element.prototype.attachShadow;if(n.__v3Patched&&n.__v3State){n.__v3State.debug=!0,r(n.__v3State);return}let t={hostToRoot:new WeakMap,openCount:0,closedCount:0,debug:!0},l=n,d=function(e){let o=e?.mode??\"open\",a=l.call(this,e);try{t.hostToRoot.set(this,a),o===\"closed\"?t.closedCount++:t.openCount++,t.debug&&console.info(\"[v3-piercer] attachShadow\",{tag:this.tagName?.toLowerCase()??\"\",mode:o,url:location.href})}catch{}return a};if(d.__v3Patched=!0,d.__v3State=t,Object.defineProperty(Element.prototype,\"attachShadow\",{configurable:!0,writable:!0,value:d}),c.tagExisting)try{let e=document.createTreeWalker(document,NodeFilter.SHOW_ELEMENT);for(;e.nextNode();){let o=e.currentNode;o.shadowRoot&&(t.hostToRoot.set(o,o.shadowRoot),t.openCount++)}}catch{}window.__stagehandV3Injected=!0,r(t),t.debug&&console.info(\"[v3-piercer] installed\",{url:location.href,isTop:window.top===window,readyState:document.readyState})}s({debug:!0,tagExisting:!1});})();\n"]}
@@ -2,7 +2,7 @@ import { LogLine } from "../types/public/logs.js";
2
2
  import { V3 } from "../v3.js";
3
3
  import { ToolSet } from "ai";
4
4
  import { LLMClient } from "../llm/LLMClient.js";
5
- import { AgentExecuteOptions, AgentStreamExecuteOptions, AgentResult, AgentStreamResult, AgentToolMode, AgentModelConfig } from "../types/public/agent.js";
5
+ import { AgentExecuteOptions, AgentStreamExecuteOptions, AgentResult, AgentStreamResult, AgentToolMode } from "../types/public/agent.js";
6
6
  export declare class V3AgentHandler {
7
7
  private v3;
8
8
  private logger;
@@ -11,7 +11,7 @@ export declare class V3AgentHandler {
11
11
  private systemInstructions?;
12
12
  private mcpTools?;
13
13
  private mode;
14
- constructor(v3: V3, logger: (message: LogLine) => void, llmClient: LLMClient, executionModel?: string | AgentModelConfig, systemInstructions?: string, mcpTools?: ToolSet, mode?: AgentToolMode);
14
+ constructor(v3: V3, logger: (message: LogLine) => void, llmClient: LLMClient, executionModel?: string, systemInstructions?: string, mcpTools?: ToolSet, mode?: AgentToolMode);
15
15
  private prepareAgent;
16
16
  private createPrepareStep;
17
17
  private createStepHandler;
@@ -1 +1 @@
1
- {"version":3,"file":"v3AgentHandler.js","sourceRoot":"","sources":["../../../../../lib/v3/handlers/v3AgentHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAG/E,OAAO,EAGL,iBAAiB,EACjB,WAAW,GAOZ,MAAM,IAAI,CAAC;AAEZ,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAEtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAarD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EACL,4BAA4B,EAC5B,yCAAyC,EACzC,eAAe,GAChB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAA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ent/prompts/agentSystemPrompt.js\";\nimport { LogLine } from \"../types/public/logs.js\";\nimport { V3 } from \"../v3.js\";\nimport {\n ModelMessage,\n ToolSet,\n wrapLanguageModel,\n stepCountIs,\n LanguageModel,\n type LanguageModelUsage,\n type StepResult,\n type GenerateTextOnStepFinishCallback,\n type StreamTextOnStepFinishCallback,\n type PrepareStepFunction,\n} from \"ai\";\nimport { StagehandZodObject } from \"../zodCompat.js\";\nimport { processMessages } from \"../agent/utils/messageProcessing.js\";\nimport { LLMClient } from \"../llm/LLMClient.js\";\nimport { SessionFileLogger } from \"../flowLogger.js\";\nimport {\n AgentExecuteOptions,\n AgentStreamExecuteOptions,\n AgentExecuteOptionsBase,\n AgentResult,\n AgentContext,\n AgentState,\n AgentStreamResult,\n AgentStreamCallbacks,\n AgentToolMode,\n AgentModelConfig,\n} from \"../types/public/agent.js\";\nimport { V3FunctionName } from \"../types/public/methods.js\";\nimport { mapToolResultToActions } from \"../agent/utils/actionMapping.js\";\nimport {\n MissingLLMConfigurationError,\n StreamingCallbacksInNonStreamingModeError,\n AgentAbortError,\n} from \"../types/public/sdkErrors.js\";\nimport { handleDoneToolCall } from \"../agent/utils/handleDoneToolCall.js\";\n\nfunction getErrorMessage(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n\n/**\n * Prepends a system message with cache control to the messages array.\n * The cache control providerOptions are used by Anthropic and ignored by other providers.\n */\nfunction prependSystemMessage(\n systemPrompt: string,\n messages: ModelMessage[],\n): ModelMessage[] {\n return [\n {\n role: \"system\",\n content: systemPrompt,\n providerOptions: {\n anthropic: {\n cacheControl: { type: \"ephemeral\" },\n },\n },\n },\n ...messages,\n ];\n}\n\nexport class V3AgentHandler {\n private v3: V3;\n private logger: (message: LogLine) => void;\n private llmClient: LLMClient;\n private executionModel?: string | AgentModelConfig;\n private systemInstructions?: string;\n private mcpTools?: ToolSet;\n private mode: AgentToolMode;\n\n constructor(\n v3: V3,\n logger: (message: LogLine) => void,\n llmClient: LLMClient,\n executionModel?: string | AgentModelConfig,\n systemInstructions?: string,\n mcpTools?: ToolSet,\n mode?: AgentToolMode,\n ) {\n this.v3 = v3;\n this.logger = logger;\n this.llmClient = llmClient;\n this.executionModel = executionModel;\n this.systemInstructions = systemInstructions;\n this.mcpTools = mcpTools;\n this.mode = mode ?? \"dom\";\n }\n\n private async prepareAgent(\n instructionOrOptions: string | AgentExecuteOptionsBase,\n ): Promise<AgentContext> {\n try {\n const options =\n typeof instructionOrOptions === \"string\"\n ? { instruction: instructionOrOptions }\n : instructionOrOptions;\n\n const maxSteps = options.maxSteps || 20;\n\n // Get the initial page URL first (needed for the system prompt)\n const initialPageUrl = (await this.v3.context.awaitActivePage()).url();\n\n // Build the system prompt with mode-aware tool guidance\n const systemPrompt = buildAgentSystemPrompt({\n url: initialPageUrl,\n executionInstruction: options.instruction,\n mode: this.mode,\n systemInstructions: this.systemInstructions,\n isBrowserbase: this.v3.isBrowserbase,\n excludeTools: options.excludeTools,\n });\n\n const tools = this.createTools(options.excludeTools);\n const allTools: ToolSet = { ...tools, ...this.mcpTools };\n\n // Use provided messages for continuation, or start fresh with the instruction\n const messages: ModelMessage[] = options.messages?.length\n ? [...options.messages, { role: \"user\", content: options.instruction }]\n : [{ role: \"user\", content: options.instruction }];\n\n if (!this.llmClient?.getLanguageModel) {\n throw new MissingLLMConfigurationError();\n }\n const baseModel = this.llmClient.getLanguageModel();\n //to do - we likely do not need middleware anymore\n const wrappedModel = wrapLanguageModel({\n model: baseModel,\n middleware: {\n ...SessionFileLogger.createLlmLoggingMiddleware(baseModel.modelId),\n },\n });\n\n if (\n this.mode === \"hybrid\" &&\n !baseModel.modelId.includes(\"gemini-3-flash\") &&\n !baseModel.modelId.includes(\"claude\")\n ) {\n this.logger({\n category: \"agent\",\n message: `Warning: \"${baseModel.modelId}\" may not perform well in hybrid mode. See recommended models: https://docs.stagehand.dev/v3/basics/agent#hybrid-mode`,\n level: 0,\n });\n }\n\n return {\n options,\n maxSteps,\n systemPrompt,\n allTools,\n messages,\n wrappedModel,\n initialPageUrl,\n };\n } catch (error) {\n this.logger({\n category: \"agent\",\n message: `failed to prepare agent: ${error}`,\n level: 0,\n });\n throw error;\n }\n }\n private createPrepareStep(\n userCallback?: PrepareStepFunction<ToolSet>,\n ): PrepareStepFunction<ToolSet> {\n return async (options) => {\n processMessages(options.messages);\n if (userCallback) {\n return userCallback(options);\n }\n return options;\n };\n }\n\n private createStepHandler(\n state: AgentState,\n userCallback?:\n | GenerateTextOnStepFinishCallback<ToolSet>\n | StreamTextOnStepFinishCallback<ToolSet>,\n ) {\n return async (event: StepResult<ToolSet>) => {\n this.logger({\n category: \"agent\",\n message: `Step finished: ${event.finishReason}`,\n level: 2,\n });\n\n if (event.toolCalls && event.toolCalls.length > 0) {\n for (let i = 0; i < event.toolCalls.length; i++) {\n const toolCall = event.toolCalls[i];\n const args = toolCall.input;\n const toolResult = event.toolResults?.[i];\n\n if (event.text && event.text.length > 0) {\n state.collectedReasoning.push(event.text);\n this.logger({\n category: \"agent\",\n message: `reasoning: ${event.text}`,\n level: 1,\n });\n }\n\n if (toolCall.toolName === \"done\") {\n state.completed = true;\n if (args?.taskComplete) {\n const doneReasoning = args.reasoning;\n const allReasoning = state.collectedReasoning.join(\" \");\n state.finalMessage = doneReasoning\n ? `${allReasoning} ${doneReasoning}`.trim()\n : allReasoning || \"Task completed successfully\";\n }\n }\n const mappedActions = mapToolResultToActions({\n toolCallName: toolCall.toolName,\n toolResult,\n args,\n reasoning: event.text || undefined,\n });\n\n for (const action of mappedActions) {\n action.pageUrl = state.currentPageUrl;\n action.timestamp = Date.now();\n state.actions.push(action);\n }\n }\n state.currentPageUrl = (await this.v3.context.awaitActivePage()).url();\n\n // Capture screenshot after tool execution (only for evals)\n if (process.env.EVALS === \"true\") {\n try {\n await this.captureAndEmitScreenshot();\n } catch (e) {\n this.logger({\n category: \"agent\",\n message: `Warning: Failed to capture screenshot: ${getErrorMessage(e)}`,\n level: 1,\n });\n }\n }\n }\n\n if (userCallback) {\n await userCallback(event);\n }\n };\n }\n\n public async execute(\n instructionOrOptions: string | AgentExecuteOptions,\n ): Promise<AgentResult> {\n const startTime = Date.now();\n const options =\n typeof instructionOrOptions === \"object\" ? instructionOrOptions : null;\n const signal = options?.signal;\n\n // Highlight cursor defaults to true for hybrid mode, can be overridden\n const shouldHighlightCursor =\n options?.highlightCursor ?? this.mode === \"hybrid\";\n\n const state: AgentState = {\n collectedReasoning: [],\n actions: [],\n finalMessage: \"\",\n completed: false,\n currentPageUrl: \"\",\n };\n\n let messages: ModelMessage[] = [];\n\n try {\n const {\n options: preparedOptions,\n maxSteps,\n systemPrompt,\n allTools,\n messages: preparedMessages,\n wrappedModel,\n initialPageUrl,\n } = await this.prepareAgent(instructionOrOptions);\n\n // Enable cursor overlay for hybrid mode (coordinate-based interactions)\n if (shouldHighlightCursor && this.mode === \"hybrid\") {\n const page = await this.v3.context.awaitActivePage();\n await page.enableCursorOverlay().catch(() => {});\n }\n\n messages = preparedMessages;\n state.currentPageUrl = initialPageUrl;\n\n const callbacks = (instructionOrOptions as AgentExecuteOptions).callbacks;\n\n if (callbacks) {\n const streamingOnlyCallbacks = [\n \"onChunk\",\n \"onFinish\",\n \"onError\",\n \"onAbort\",\n ];\n const invalidCallbacks = streamingOnlyCallbacks.filter(\n (name) => callbacks[name as keyof typeof callbacks] != null,\n );\n if (invalidCallbacks.length > 0) {\n throw new StreamingCallbacksInNonStreamingModeError(invalidCallbacks);\n }\n }\n\n const result = await this.llmClient.generateText({\n model: wrappedModel,\n messages: prependSystemMessage(systemPrompt, messages),\n tools: allTools,\n stopWhen: (result) => this.handleStop(result, maxSteps),\n temperature: 1,\n toolChoice: \"auto\",\n\n prepareStep: this.createPrepareStep(callbacks?.prepareStep),\n onStepFinish: this.createStepHandler(state, callbacks?.onStepFinish),\n abortSignal: preparedOptions.signal,\n providerOptions: wrappedModel.modelId.includes(\"gemini-3\")\n ? {\n google: {\n mediaResolution: \"MEDIA_RESOLUTION_HIGH\",\n },\n }\n : undefined,\n });\n\n const allMessages = [...messages, ...(result.response?.messages || [])];\n const doneResult = await this.ensureDone(\n state,\n wrappedModel,\n allMessages,\n preparedOptions.instruction,\n preparedOptions.output,\n this.logger,\n );\n\n return this.consolidateMetricsAndResult(\n startTime,\n state,\n doneResult.messages,\n result,\n maxSteps,\n doneResult.output,\n );\n } catch (error) {\n // Re-throw validation errors that should propagate to the caller\n if (error instanceof StreamingCallbacksInNonStreamingModeError) {\n throw error;\n }\n\n // Re-throw abort errors wrapped in AgentAbortError for consistent error typing\n if (signal?.aborted) {\n const reason = signal.reason ? String(signal.reason) : \"aborted\";\n throw new AgentAbortError(reason);\n }\n\n const errorMessage = getErrorMessage(error);\n this.logger({\n category: \"agent\",\n message: `Error executing agent task: ${errorMessage}`,\n level: 0,\n });\n\n // For non-abort errors, return a failure result instead of throwing\n return {\n success: false,\n actions: state.actions,\n message: `Failed to execute task: ${errorMessage}`,\n completed: false,\n messages,\n };\n }\n }\n\n public async stream(\n instructionOrOptions: string | AgentStreamExecuteOptions,\n ): Promise<AgentStreamResult> {\n const streamOptions =\n typeof instructionOrOptions === \"object\" ? instructionOrOptions : null;\n\n // Highlight cursor defaults to true for hybrid mode, can be overridden\n const shouldHighlightCursor =\n streamOptions?.highlightCursor ?? this.mode === \"hybrid\";\n\n const {\n options,\n maxSteps,\n systemPrompt,\n allTools,\n messages,\n wrappedModel,\n initialPageUrl,\n } = await this.prepareAgent(instructionOrOptions);\n\n // Enable cursor overlay for hybrid mode (coordinate-based interactions)\n if (shouldHighlightCursor && this.mode === \"hybrid\") {\n const page = await this.v3.context.awaitActivePage();\n await page.enableCursorOverlay().catch(() => {});\n }\n\n const callbacks = (instructionOrOptions as AgentStreamExecuteOptions)\n .callbacks as AgentStreamCallbacks | undefined;\n\n const state: AgentState = {\n collectedReasoning: [],\n actions: [],\n finalMessage: \"\",\n completed: false,\n currentPageUrl: initialPageUrl,\n };\n const startTime = Date.now();\n\n let resolveResult: (value: AgentResult | PromiseLike<AgentResult>) => void;\n let rejectResult: (reason: unknown) => void;\n const resultPromise = new Promise<AgentResult>((resolve, reject) => {\n resolveResult = resolve;\n rejectResult = reject;\n });\n\n const handleError = (error: unknown) => {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n this.logger({\n category: \"agent\",\n message: `Error during streaming: ${errorMessage}`,\n level: 0,\n });\n rejectResult(error);\n };\n\n const streamResult = this.llmClient.streamText({\n model: wrappedModel,\n messages: prependSystemMessage(systemPrompt, messages),\n tools: allTools,\n stopWhen: (result) => this.handleStop(result, maxSteps),\n temperature: 1,\n toolChoice: \"auto\",\n prepareStep: this.createPrepareStep(callbacks?.prepareStep),\n onStepFinish: this.createStepHandler(state, callbacks?.onStepFinish),\n onError: (event) => {\n if (callbacks?.onError) {\n callbacks.onError(event);\n }\n handleError(event.error);\n },\n onChunk: callbacks?.onChunk,\n onFinish: (event) => {\n if (callbacks?.onFinish) {\n callbacks.onFinish(event);\n }\n\n const allMessages = [...messages, ...(event.response?.messages || [])];\n this.ensureDone(\n state,\n wrappedModel,\n allMessages,\n options.instruction,\n options.output,\n this.logger,\n ).then((doneResult) => {\n const result = this.consolidateMetricsAndResult(\n startTime,\n state,\n doneResult.messages,\n event,\n maxSteps,\n doneResult.output,\n );\n resolveResult(result);\n });\n },\n onAbort: (event) => {\n if (callbacks?.onAbort) {\n callbacks.onAbort(event);\n }\n // Reject the result promise with AgentAbortError when stream is aborted\n const reason = options.signal?.reason\n ? String(options.signal.reason)\n : \"Stream was aborted\";\n rejectResult(new AgentAbortError(reason));\n },\n abortSignal: options.signal,\n providerOptions: wrappedModel.modelId.includes(\"gemini-3\")\n ? {\n google: {\n mediaResolution: \"MEDIA_RESOLUTION_HIGH\",\n },\n }\n : undefined,\n });\n\n const agentStreamResult = streamResult as AgentStreamResult;\n agentStreamResult.result = resultPromise;\n return agentStreamResult;\n }\n\n private consolidateMetricsAndResult(\n startTime: number,\n state: AgentState,\n inputMessages: ModelMessage[],\n result: {\n text?: string;\n totalUsage?: LanguageModelUsage;\n response?: { messages?: ModelMessage[] };\n steps?: StepResult<ToolSet>[];\n },\n maxSteps?: number,\n output?: Record<string, unknown>,\n ): AgentResult {\n if (!state.finalMessage) {\n const allReasoning = state.collectedReasoning.join(\" \").trim();\n\n if (!state.completed && maxSteps && result.steps?.length >= maxSteps) {\n this.logger({\n category: \"agent\",\n message: `Agent stopped: reached maximum steps (${maxSteps})`,\n level: 1,\n });\n state.finalMessage = `Agent stopped: reached maximum steps (${maxSteps})`;\n } else {\n state.finalMessage = allReasoning || result.text || \"\";\n }\n }\n\n const endTime = Date.now();\n const inferenceTimeMs = endTime - startTime;\n if (result.totalUsage) {\n this.v3.updateMetrics(\n V3FunctionName.AGENT,\n result.totalUsage.inputTokens || 0,\n result.totalUsage.outputTokens || 0,\n result.totalUsage.reasoningTokens || 0,\n result.totalUsage.cachedInputTokens || 0,\n inferenceTimeMs,\n );\n }\n\n return {\n success: state.completed,\n message: state.finalMessage || \"Task execution completed\",\n actions: state.actions,\n completed: state.completed,\n output,\n usage: result.totalUsage\n ? {\n input_tokens: result.totalUsage.inputTokens || 0,\n output_tokens: result.totalUsage.outputTokens || 0,\n reasoning_tokens: result.totalUsage.reasoningTokens || 0,\n cached_input_tokens: result.totalUsage.cachedInputTokens || 0,\n inference_time_ms: inferenceTimeMs,\n }\n : undefined,\n messages: inputMessages,\n };\n }\n\n private createTools(excludeTools?: string[]) {\n const provider = this.llmClient?.getLanguageModel?.()?.provider;\n return createAgentTools(this.v3, {\n executionModel: this.executionModel,\n logger: this.logger,\n mode: this.mode,\n provider,\n excludeTools,\n });\n }\n\n private handleStop(\n result: Parameters<ReturnType<typeof stepCountIs>>[0],\n maxSteps: number,\n ): boolean | PromiseLike<boolean> {\n const lastStep = result.steps[result.steps.length - 1];\n if (lastStep?.toolCalls?.some((tc) => tc.toolName === \"done\")) {\n return true;\n }\n return stepCountIs(maxSteps)(result);\n }\n\n /**\n * Ensures the done tool is called at the end of agent execution.\n * Returns the messages and any extracted output from the done call.\n */\n private async ensureDone(\n state: AgentState,\n model: LanguageModel,\n messages: ModelMessage[],\n instruction: string,\n outputSchema?: StagehandZodObject,\n logger?: (message: LogLine) => void,\n ): Promise<{ messages: ModelMessage[]; output?: Record<string, unknown> }> {\n if (state.completed) return { messages };\n\n const doneResult = await handleDoneToolCall({\n model,\n inputMessages: messages,\n instruction,\n outputSchema,\n logger,\n });\n\n state.completed = doneResult.taskComplete;\n state.finalMessage = doneResult.reasoning;\n\n const doneAction = mapToolResultToActions({\n toolCallName: \"done\",\n toolResult: {\n success: true,\n reasoning: doneResult.reasoning,\n taskComplete: doneResult.taskComplete,\n },\n args: {\n reasoning: doneResult.reasoning,\n taskComplete: doneResult.taskComplete,\n },\n reasoning: doneResult.reasoning,\n });\n\n for (const action of doneAction) {\n action.pageUrl = state.currentPageUrl;\n action.timestamp = Date.now();\n state.actions.push(action);\n }\n\n return {\n messages: [...messages, ...doneResult.messages],\n output: doneResult.output,\n };\n }\n\n /**\n * Capture a screenshot and emit it via the event bus\n */\n private async captureAndEmitScreenshot(): Promise<void> {\n try {\n const page = await this.v3.context.awaitActivePage();\n const screenshot = await page.screenshot({ fullPage: false });\n this.v3.bus.emit(\"agent_screenshot_taken_event\", screenshot);\n } catch (error) {\n this.logger({\n category: \"agent\",\n message: `Error capturing screenshot: ${getErrorMessage(error)}`,\n level: 0,\n });\n }\n }\n}\n"]}
1
+ {"version":3,"file":"v3AgentHandler.js","sourceRoot":"","sources":["../../../../../lib/v3/handlers/v3AgentHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAG/E,OAAO,EAGL,iBAAiB,EACjB,WAAW,GAOZ,MAAM,IAAI,CAAC;AAEZ,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAEtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CA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AAM,CAAC;gBACV,QAAQ,EAAE,OAAO;gBACjB,OAAO,EAAE,+BAA+B,eAAe,CAAC,KAAK,CAAC,EAAE;gBAChE,KAAK,EAAE,CAAC;aACT,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF","sourcesContent":["import { createAgentTools } from \"../agent/tools/index.js\";\nimport { buildAgentSystemPrompt } from \"../agent/prompts/agentSystemPrompt.js\";\nimport { LogLine } from \"../types/public/logs.js\";\nimport { V3 } from \"../v3.js\";\nimport {\n ModelMessage,\n ToolSet,\n wrapLanguageModel,\n stepCountIs,\n LanguageModel,\n type LanguageModelUsage,\n type StepResult,\n type GenerateTextOnStepFinishCallback,\n type StreamTextOnStepFinishCallback,\n type PrepareStepFunction,\n} from \"ai\";\nimport { StagehandZodObject } from \"../zodCompat.js\";\nimport { processMessages } from \"../agent/utils/messageProcessing.js\";\nimport { LLMClient } from \"../llm/LLMClient.js\";\nimport { SessionFileLogger } from \"../flowLogger.js\";\nimport {\n AgentExecuteOptions,\n AgentStreamExecuteOptions,\n AgentExecuteOptionsBase,\n AgentResult,\n AgentContext,\n AgentState,\n AgentStreamResult,\n AgentStreamCallbacks,\n AgentToolMode,\n} from \"../types/public/agent.js\";\nimport { V3FunctionName } from \"../types/public/methods.js\";\nimport { mapToolResultToActions } from \"../agent/utils/actionMapping.js\";\nimport {\n MissingLLMConfigurationError,\n StreamingCallbacksInNonStreamingModeError,\n AgentAbortError,\n} from \"../types/public/sdkErrors.js\";\nimport { handleDoneToolCall } from \"../agent/utils/handleDoneToolCall.js\";\n\nfunction getErrorMessage(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n\n/**\n * Prepends a system message with cache control to the messages array.\n * The cache control providerOptions are used by Anthropic and ignored by other providers.\n */\nfunction prependSystemMessage(\n systemPrompt: string,\n messages: ModelMessage[],\n): ModelMessage[] {\n return [\n {\n role: \"system\",\n content: systemPrompt,\n providerOptions: {\n anthropic: {\n cacheControl: { type: \"ephemeral\" },\n },\n },\n },\n ...messages,\n ];\n}\n\nexport class V3AgentHandler {\n private v3: V3;\n private logger: (message: LogLine) => void;\n private llmClient: LLMClient;\n private executionModel?: string;\n private systemInstructions?: string;\n private mcpTools?: ToolSet;\n private mode: AgentToolMode;\n\n constructor(\n v3: V3,\n logger: (message: LogLine) => void,\n llmClient: LLMClient,\n executionModel?: string,\n systemInstructions?: string,\n mcpTools?: ToolSet,\n mode?: AgentToolMode,\n ) {\n this.v3 = v3;\n this.logger = logger;\n this.llmClient = llmClient;\n this.executionModel = executionModel;\n this.systemInstructions = systemInstructions;\n this.mcpTools = mcpTools;\n this.mode = mode ?? \"dom\";\n }\n\n private async prepareAgent(\n instructionOrOptions: string | AgentExecuteOptionsBase,\n ): Promise<AgentContext> {\n try {\n const options =\n typeof instructionOrOptions === \"string\"\n ? { instruction: instructionOrOptions }\n : instructionOrOptions;\n\n const maxSteps = options.maxSteps || 20;\n\n // Get the initial page URL first (needed for the system prompt)\n const initialPageUrl = (await this.v3.context.awaitActivePage()).url();\n\n // Build the system prompt with mode-aware tool guidance\n const systemPrompt = buildAgentSystemPrompt({\n url: initialPageUrl,\n executionInstruction: options.instruction,\n mode: this.mode,\n systemInstructions: this.systemInstructions,\n isBrowserbase: this.v3.isBrowserbase,\n excludeTools: options.excludeTools,\n });\n\n const tools = this.createTools(options.excludeTools);\n const allTools: ToolSet = { ...tools, ...this.mcpTools };\n\n // Use provided messages for continuation, or start fresh with the instruction\n const messages: ModelMessage[] = options.messages?.length\n ? [...options.messages, { role: \"user\", content: options.instruction }]\n : [{ role: \"user\", content: options.instruction }];\n\n if (!this.llmClient?.getLanguageModel) {\n throw new MissingLLMConfigurationError();\n }\n const baseModel = this.llmClient.getLanguageModel();\n //to do - we likely do not need middleware anymore\n const wrappedModel = wrapLanguageModel({\n model: baseModel,\n middleware: {\n ...SessionFileLogger.createLlmLoggingMiddleware(baseModel.modelId),\n },\n });\n\n if (\n this.mode === \"hybrid\" &&\n !baseModel.modelId.includes(\"gemini-3-flash\") &&\n !baseModel.modelId.includes(\"claude\")\n ) {\n this.logger({\n category: \"agent\",\n message: `Warning: \"${baseModel.modelId}\" may not perform well in hybrid mode. See recommended models: https://docs.stagehand.dev/v3/basics/agent#hybrid-mode`,\n level: 0,\n });\n }\n\n return {\n options,\n maxSteps,\n systemPrompt,\n allTools,\n messages,\n wrappedModel,\n initialPageUrl,\n };\n } catch (error) {\n this.logger({\n category: \"agent\",\n message: `failed to prepare agent: ${error}`,\n level: 0,\n });\n throw error;\n }\n }\n private createPrepareStep(\n userCallback?: PrepareStepFunction<ToolSet>,\n ): PrepareStepFunction<ToolSet> {\n return async (options) => {\n processMessages(options.messages);\n if (userCallback) {\n return userCallback(options);\n }\n return options;\n };\n }\n\n private createStepHandler(\n state: AgentState,\n userCallback?:\n | GenerateTextOnStepFinishCallback<ToolSet>\n | StreamTextOnStepFinishCallback<ToolSet>,\n ) {\n return async (event: StepResult<ToolSet>) => {\n this.logger({\n category: \"agent\",\n message: `Step finished: ${event.finishReason}`,\n level: 2,\n });\n\n if (event.toolCalls && event.toolCalls.length > 0) {\n for (let i = 0; i < event.toolCalls.length; i++) {\n const toolCall = event.toolCalls[i];\n const args = toolCall.input;\n const toolResult = event.toolResults?.[i];\n\n if (event.text && event.text.length > 0) {\n state.collectedReasoning.push(event.text);\n this.logger({\n category: \"agent\",\n message: `reasoning: ${event.text}`,\n level: 1,\n });\n }\n\n if (toolCall.toolName === \"done\") {\n state.completed = true;\n if (args?.taskComplete) {\n const doneReasoning = args.reasoning;\n const allReasoning = state.collectedReasoning.join(\" \");\n state.finalMessage = doneReasoning\n ? `${allReasoning} ${doneReasoning}`.trim()\n : allReasoning || \"Task completed successfully\";\n }\n }\n const mappedActions = mapToolResultToActions({\n toolCallName: toolCall.toolName,\n toolResult,\n args,\n reasoning: event.text || undefined,\n });\n\n for (const action of mappedActions) {\n action.pageUrl = state.currentPageUrl;\n action.timestamp = Date.now();\n state.actions.push(action);\n }\n }\n state.currentPageUrl = (await this.v3.context.awaitActivePage()).url();\n\n // Capture screenshot after tool execution (only for evals)\n if (process.env.EVALS === \"true\") {\n try {\n await this.captureAndEmitScreenshot();\n } catch (e) {\n this.logger({\n category: \"agent\",\n message: `Warning: Failed to capture screenshot: ${getErrorMessage(e)}`,\n level: 1,\n });\n }\n }\n }\n\n if (userCallback) {\n await userCallback(event);\n }\n };\n }\n\n public async execute(\n instructionOrOptions: string | AgentExecuteOptions,\n ): Promise<AgentResult> {\n const startTime = Date.now();\n const options =\n typeof instructionOrOptions === \"object\" ? instructionOrOptions : null;\n const signal = options?.signal;\n\n // Highlight cursor defaults to true for hybrid mode, can be overridden\n const shouldHighlightCursor =\n options?.highlightCursor ?? this.mode === \"hybrid\";\n\n const state: AgentState = {\n collectedReasoning: [],\n actions: [],\n finalMessage: \"\",\n completed: false,\n currentPageUrl: \"\",\n };\n\n let messages: ModelMessage[] = [];\n\n try {\n const {\n options: preparedOptions,\n maxSteps,\n systemPrompt,\n allTools,\n messages: preparedMessages,\n wrappedModel,\n initialPageUrl,\n } = await this.prepareAgent(instructionOrOptions);\n\n // Enable cursor overlay for hybrid mode (coordinate-based interactions)\n if (shouldHighlightCursor && this.mode === \"hybrid\") {\n const page = await this.v3.context.awaitActivePage();\n await page.enableCursorOverlay().catch(() => {});\n }\n\n messages = preparedMessages;\n state.currentPageUrl = initialPageUrl;\n\n const callbacks = (instructionOrOptions as AgentExecuteOptions).callbacks;\n\n if (callbacks) {\n const streamingOnlyCallbacks = [\n \"onChunk\",\n \"onFinish\",\n \"onError\",\n \"onAbort\",\n ];\n const invalidCallbacks = streamingOnlyCallbacks.filter(\n (name) => callbacks[name as keyof typeof callbacks] != null,\n );\n if (invalidCallbacks.length > 0) {\n throw new StreamingCallbacksInNonStreamingModeError(invalidCallbacks);\n }\n }\n\n const result = await this.llmClient.generateText({\n model: wrappedModel,\n messages: prependSystemMessage(systemPrompt, messages),\n tools: allTools,\n stopWhen: (result) => this.handleStop(result, maxSteps),\n temperature: 1,\n toolChoice: \"auto\",\n\n prepareStep: this.createPrepareStep(callbacks?.prepareStep),\n onStepFinish: this.createStepHandler(state, callbacks?.onStepFinish),\n abortSignal: preparedOptions.signal,\n providerOptions: wrappedModel.modelId.includes(\"gemini-3\")\n ? {\n google: {\n mediaResolution: \"MEDIA_RESOLUTION_HIGH\",\n },\n }\n : undefined,\n });\n\n const allMessages = [...messages, ...(result.response?.messages || [])];\n const doneResult = await this.ensureDone(\n state,\n wrappedModel,\n allMessages,\n preparedOptions.instruction,\n preparedOptions.output,\n this.logger,\n );\n\n return this.consolidateMetricsAndResult(\n startTime,\n state,\n doneResult.messages,\n result,\n maxSteps,\n doneResult.output,\n );\n } catch (error) {\n // Re-throw validation errors that should propagate to the caller\n if (error instanceof StreamingCallbacksInNonStreamingModeError) {\n throw error;\n }\n\n // Re-throw abort errors wrapped in AgentAbortError for consistent error typing\n if (signal?.aborted) {\n const reason = signal.reason ? String(signal.reason) : \"aborted\";\n throw new AgentAbortError(reason);\n }\n\n const errorMessage = getErrorMessage(error);\n this.logger({\n category: \"agent\",\n message: `Error executing agent task: ${errorMessage}`,\n level: 0,\n });\n\n // For non-abort errors, return a failure result instead of throwing\n return {\n success: false,\n actions: state.actions,\n message: `Failed to execute task: ${errorMessage}`,\n completed: false,\n messages,\n };\n }\n }\n\n public async stream(\n instructionOrOptions: string | AgentStreamExecuteOptions,\n ): Promise<AgentStreamResult> {\n const streamOptions =\n typeof instructionOrOptions === \"object\" ? instructionOrOptions : null;\n\n // Highlight cursor defaults to true for hybrid mode, can be overridden\n const shouldHighlightCursor =\n streamOptions?.highlightCursor ?? this.mode === \"hybrid\";\n\n const {\n options,\n maxSteps,\n systemPrompt,\n allTools,\n messages,\n wrappedModel,\n initialPageUrl,\n } = await this.prepareAgent(instructionOrOptions);\n\n // Enable cursor overlay for hybrid mode (coordinate-based interactions)\n if (shouldHighlightCursor && this.mode === \"hybrid\") {\n const page = await this.v3.context.awaitActivePage();\n await page.enableCursorOverlay().catch(() => {});\n }\n\n const callbacks = (instructionOrOptions as AgentStreamExecuteOptions)\n .callbacks as AgentStreamCallbacks | undefined;\n\n const state: AgentState = {\n collectedReasoning: [],\n actions: [],\n finalMessage: \"\",\n completed: false,\n currentPageUrl: initialPageUrl,\n };\n const startTime = Date.now();\n\n let resolveResult: (value: AgentResult | PromiseLike<AgentResult>) => void;\n let rejectResult: (reason: unknown) => void;\n const resultPromise = new Promise<AgentResult>((resolve, reject) => {\n resolveResult = resolve;\n rejectResult = reject;\n });\n\n const handleError = (error: unknown) => {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n this.logger({\n category: \"agent\",\n message: `Error during streaming: ${errorMessage}`,\n level: 0,\n });\n rejectResult(error);\n };\n\n const streamResult = this.llmClient.streamText({\n model: wrappedModel,\n messages: prependSystemMessage(systemPrompt, messages),\n tools: allTools,\n stopWhen: (result) => this.handleStop(result, maxSteps),\n temperature: 1,\n toolChoice: \"auto\",\n prepareStep: this.createPrepareStep(callbacks?.prepareStep),\n onStepFinish: this.createStepHandler(state, callbacks?.onStepFinish),\n onError: (event) => {\n if (callbacks?.onError) {\n callbacks.onError(event);\n }\n handleError(event.error);\n },\n onChunk: callbacks?.onChunk,\n onFinish: (event) => {\n if (callbacks?.onFinish) {\n callbacks.onFinish(event);\n }\n\n const allMessages = [...messages, ...(event.response?.messages || [])];\n this.ensureDone(\n state,\n wrappedModel,\n allMessages,\n options.instruction,\n options.output,\n this.logger,\n ).then((doneResult) => {\n const result = this.consolidateMetricsAndResult(\n startTime,\n state,\n doneResult.messages,\n event,\n maxSteps,\n doneResult.output,\n );\n resolveResult(result);\n });\n },\n onAbort: (event) => {\n if (callbacks?.onAbort) {\n callbacks.onAbort(event);\n }\n // Reject the result promise with AgentAbortError when stream is aborted\n const reason = options.signal?.reason\n ? String(options.signal.reason)\n : \"Stream was aborted\";\n rejectResult(new AgentAbortError(reason));\n },\n abortSignal: options.signal,\n providerOptions: wrappedModel.modelId.includes(\"gemini-3\")\n ? {\n google: {\n mediaResolution: \"MEDIA_RESOLUTION_HIGH\",\n },\n }\n : undefined,\n });\n\n const agentStreamResult = streamResult as AgentStreamResult;\n agentStreamResult.result = resultPromise;\n return agentStreamResult;\n }\n\n private consolidateMetricsAndResult(\n startTime: number,\n state: AgentState,\n inputMessages: ModelMessage[],\n result: {\n text?: string;\n totalUsage?: LanguageModelUsage;\n response?: { messages?: ModelMessage[] };\n steps?: StepResult<ToolSet>[];\n },\n maxSteps?: number,\n output?: Record<string, unknown>,\n ): AgentResult {\n if (!state.finalMessage) {\n const allReasoning = state.collectedReasoning.join(\" \").trim();\n\n if (!state.completed && maxSteps && result.steps?.length >= maxSteps) {\n this.logger({\n category: \"agent\",\n message: `Agent stopped: reached maximum steps (${maxSteps})`,\n level: 1,\n });\n state.finalMessage = `Agent stopped: reached maximum steps (${maxSteps})`;\n } else {\n state.finalMessage = allReasoning || result.text || \"\";\n }\n }\n\n const endTime = Date.now();\n const inferenceTimeMs = endTime - startTime;\n if (result.totalUsage) {\n this.v3.updateMetrics(\n V3FunctionName.AGENT,\n result.totalUsage.inputTokens || 0,\n result.totalUsage.outputTokens || 0,\n result.totalUsage.reasoningTokens || 0,\n result.totalUsage.cachedInputTokens || 0,\n inferenceTimeMs,\n );\n }\n\n return {\n success: state.completed,\n message: state.finalMessage || \"Task execution completed\",\n actions: state.actions,\n completed: state.completed,\n output,\n usage: result.totalUsage\n ? {\n input_tokens: result.totalUsage.inputTokens || 0,\n output_tokens: result.totalUsage.outputTokens || 0,\n reasoning_tokens: result.totalUsage.reasoningTokens || 0,\n cached_input_tokens: result.totalUsage.cachedInputTokens || 0,\n inference_time_ms: inferenceTimeMs,\n }\n : undefined,\n messages: inputMessages,\n };\n }\n\n private createTools(excludeTools?: string[]) {\n const provider = this.llmClient?.getLanguageModel?.()?.provider;\n return createAgentTools(this.v3, {\n executionModel: this.executionModel,\n logger: this.logger,\n mode: this.mode,\n provider,\n excludeTools,\n });\n }\n\n private handleStop(\n result: Parameters<ReturnType<typeof stepCountIs>>[0],\n maxSteps: number,\n ): boolean | PromiseLike<boolean> {\n const lastStep = result.steps[result.steps.length - 1];\n if (lastStep?.toolCalls?.some((tc) => tc.toolName === \"done\")) {\n return true;\n }\n return stepCountIs(maxSteps)(result);\n }\n\n /**\n * Ensures the done tool is called at the end of agent execution.\n * Returns the messages and any extracted output from the done call.\n */\n private async ensureDone(\n state: AgentState,\n model: LanguageModel,\n messages: ModelMessage[],\n instruction: string,\n outputSchema?: StagehandZodObject,\n logger?: (message: LogLine) => void,\n ): Promise<{ messages: ModelMessage[]; output?: Record<string, unknown> }> {\n if (state.completed) return { messages };\n\n const doneResult = await handleDoneToolCall({\n model,\n inputMessages: messages,\n instruction,\n outputSchema,\n logger,\n });\n\n state.completed = doneResult.taskComplete;\n state.finalMessage = doneResult.reasoning;\n\n const doneAction = mapToolResultToActions({\n toolCallName: \"done\",\n toolResult: {\n success: true,\n reasoning: doneResult.reasoning,\n taskComplete: doneResult.taskComplete,\n },\n args: {\n reasoning: doneResult.reasoning,\n taskComplete: doneResult.taskComplete,\n },\n reasoning: doneResult.reasoning,\n });\n\n for (const action of doneAction) {\n action.pageUrl = state.currentPageUrl;\n action.timestamp = Date.now();\n state.actions.push(action);\n }\n\n return {\n messages: [...messages, ...doneResult.messages],\n output: doneResult.output,\n };\n }\n\n /**\n * Capture a screenshot and emit it via the event bus\n */\n private async captureAndEmitScreenshot(): Promise<void> {\n try {\n const page = await this.v3.context.awaitActivePage();\n const screenshot = await page.screenshot({ fullPage: false });\n this.v3.bus.emit(\"agent_screenshot_taken_event\", screenshot);\n } catch (error) {\n this.logger({\n category: \"agent\",\n message: `Error capturing screenshot: ${getErrorMessage(error)}`,\n level: 0,\n });\n }\n }\n}\n"]}