@browserbasehq/orca 3.0.9-alpha-4 → 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 (990) 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/index.d.ts +3 -0
  336. package/dist/esm/index.js +3 -0
  337. package/dist/esm/lib/inference.d.ts +65 -0
  338. package/dist/esm/lib/inference.js +333 -0
  339. package/dist/esm/lib/inference.js.map +1 -0
  340. package/dist/esm/lib/inferenceLogUtils.d.ts +12 -0
  341. package/dist/esm/lib/inferenceLogUtils.js +92 -0
  342. package/dist/esm/lib/inferenceLogUtils.js.map +1 -0
  343. package/dist/esm/lib/logger.d.ts +69 -0
  344. package/dist/esm/lib/logger.js +323 -0
  345. package/dist/esm/lib/logger.js.map +1 -0
  346. package/dist/esm/lib/modelUtils.d.ts +11 -0
  347. package/dist/esm/lib/modelUtils.js +43 -0
  348. package/dist/esm/lib/modelUtils.js.map +1 -0
  349. package/dist/esm/lib/prompt.d.ts +14 -0
  350. package/dist/esm/lib/prompt.js +230 -0
  351. package/dist/esm/lib/prompt.js.map +1 -0
  352. package/dist/esm/lib/utils.d.ts +68 -0
  353. package/dist/esm/lib/utils.js +654 -0
  354. package/dist/esm/lib/utils.js.map +1 -0
  355. package/dist/esm/lib/v3/agent/AgentClient.d.ts +19 -0
  356. package/dist/esm/lib/v3/agent/AgentClient.js +17 -0
  357. package/dist/esm/lib/v3/agent/AgentClient.js.map +1 -0
  358. package/dist/esm/lib/v3/agent/AgentProvider.d.ts +20 -0
  359. package/dist/esm/lib/v3/agent/AgentProvider.js +77 -0
  360. package/dist/esm/lib/v3/agent/AgentProvider.js.map +1 -0
  361. package/dist/esm/lib/v3/agent/AnthropicCUAClient.d.ts +57 -0
  362. package/dist/esm/lib/v3/agent/AnthropicCUAClient.js +822 -0
  363. package/dist/esm/lib/v3/agent/AnthropicCUAClient.js.map +1 -0
  364. package/dist/esm/lib/v3/agent/GoogleCUAClient.d.ts +74 -0
  365. package/dist/esm/lib/v3/agent/GoogleCUAClient.js +799 -0
  366. package/dist/esm/lib/v3/agent/GoogleCUAClient.js.map +1 -0
  367. package/dist/esm/lib/v3/agent/MicrosoftCUAClient.d.ts +71 -0
  368. package/dist/esm/lib/v3/agent/MicrosoftCUAClient.js +770 -0
  369. package/dist/esm/lib/v3/agent/MicrosoftCUAClient.js.map +1 -0
  370. package/dist/esm/lib/v3/agent/OpenAICUAClient.d.ts +69 -0
  371. package/dist/esm/lib/v3/agent/OpenAICUAClient.js +615 -0
  372. package/dist/esm/lib/v3/agent/OpenAICUAClient.js.map +1 -0
  373. package/dist/esm/lib/v3/agent/prompts/agentSystemPrompt.d.ts +12 -0
  374. package/dist/esm/lib/v3/agent/prompts/agentSystemPrompt.js +186 -0
  375. package/dist/esm/lib/v3/agent/prompts/agentSystemPrompt.js.map +1 -0
  376. package/dist/esm/lib/v3/agent/tools/act.d.ts +12 -0
  377. package/dist/esm/lib/v3/agent/tools/act.js +49 -0
  378. package/dist/esm/lib/v3/agent/tools/act.js.map +1 -0
  379. package/dist/esm/lib/v3/agent/tools/ariaTree.d.ts +5 -0
  380. package/dist/esm/lib/v3/agent/tools/ariaTree.js +31 -0
  381. package/dist/esm/lib/v3/agent/tools/ariaTree.js.map +1 -0
  382. package/dist/esm/lib/v3/agent/tools/click.d.ts +6 -0
  383. package/dist/esm/lib/v3/agent/tools/click.js +104 -0
  384. package/dist/esm/lib/v3/agent/tools/click.js.map +1 -0
  385. package/dist/esm/lib/v3/agent/tools/clickAndHold.d.ts +14 -0
  386. package/dist/esm/lib/v3/agent/tools/clickAndHold.js +68 -0
  387. package/dist/esm/lib/v3/agent/tools/clickAndHold.js.map +1 -0
  388. package/dist/esm/lib/v3/agent/tools/dragAndDrop.d.ts +7 -0
  389. package/dist/esm/lib/v3/agent/tools/dragAndDrop.js +105 -0
  390. package/dist/esm/lib/v3/agent/tools/dragAndDrop.js.map +1 -0
  391. package/dist/esm/lib/v3/agent/tools/extract.d.ts +20 -0
  392. package/dist/esm/lib/v3/agent/tools/extract.js +93 -0
  393. package/dist/esm/lib/v3/agent/tools/extract.js.map +1 -0
  394. package/dist/esm/lib/v3/agent/tools/fillFormVision.d.ts +12 -0
  395. package/dist/esm/lib/v3/agent/tools/fillFormVision.js +143 -0
  396. package/dist/esm/lib/v3/agent/tools/fillFormVision.js.map +1 -0
  397. package/dist/esm/lib/v3/agent/tools/fillform.d.ts +12 -0
  398. package/dist/esm/lib/v3/agent/tools/fillform.js +56 -0
  399. package/dist/esm/lib/v3/agent/tools/fillform.js.map +1 -0
  400. package/dist/esm/lib/v3/agent/tools/goto.d.ts +12 -0
  401. package/dist/esm/lib/v3/agent/tools/goto.js +31 -0
  402. package/dist/esm/lib/v3/agent/tools/goto.js.map +1 -0
  403. package/dist/esm/lib/v3/agent/tools/index.d.ts +92 -0
  404. package/dist/esm/lib/v3/agent/tools/index.js +74 -0
  405. package/dist/esm/lib/v3/agent/tools/index.js.map +1 -0
  406. package/dist/esm/lib/v3/agent/tools/keys.d.ts +24 -0
  407. package/dist/esm/lib/v3/agent/tools/keys.js +60 -0
  408. package/dist/esm/lib/v3/agent/tools/keys.js.map +1 -0
  409. package/dist/esm/lib/v3/agent/tools/navback.d.ts +6 -0
  410. package/dist/esm/lib/v3/agent/tools/navback.js +23 -0
  411. package/dist/esm/lib/v3/agent/tools/navback.js.map +1 -0
  412. package/dist/esm/lib/v3/agent/tools/screenshot.d.ts +6 -0
  413. package/dist/esm/lib/v3/agent/tools/screenshot.js +26 -0
  414. package/dist/esm/lib/v3/agent/tools/screenshot.js.map +1 -0
  415. package/dist/esm/lib/v3/agent/tools/scroll.d.ts +19 -0
  416. package/dist/esm/lib/v3/agent/tools/scroll.js +142 -0
  417. package/dist/esm/lib/v3/agent/tools/scroll.js.map +1 -0
  418. package/dist/esm/lib/v3/agent/tools/search.d.ts +15 -0
  419. package/dist/esm/lib/v3/agent/tools/search.js +73 -0
  420. package/dist/esm/lib/v3/agent/tools/search.js.map +1 -0
  421. package/dist/esm/lib/v3/agent/tools/think.d.ts +6 -0
  422. package/dist/esm/lib/v3/agent/tools/think.js +24 -0
  423. package/dist/esm/lib/v3/agent/tools/think.js.map +1 -0
  424. package/dist/esm/lib/v3/agent/tools/type.d.ts +7 -0
  425. package/dist/esm/lib/v3/agent/tools/type.js +106 -0
  426. package/dist/esm/lib/v3/agent/tools/type.js.map +1 -0
  427. package/dist/esm/lib/v3/agent/tools/wait.d.ts +5 -0
  428. package/dist/esm/lib/v3/agent/tools/wait.js +53 -0
  429. package/dist/esm/lib/v3/agent/tools/wait.js.map +1 -0
  430. package/dist/esm/lib/v3/agent/utils/actionMapping.d.ts +3 -0
  431. package/dist/esm/lib/v3/agent/utils/actionMapping.js +100 -0
  432. package/dist/esm/lib/v3/agent/utils/actionMapping.js.map +1 -0
  433. package/dist/esm/lib/v3/agent/utils/coordinateNormalization.d.ts +13 -0
  434. package/dist/esm/lib/v3/agent/utils/coordinateNormalization.js +28 -0
  435. package/dist/esm/lib/v3/agent/utils/coordinateNormalization.js.map +1 -0
  436. package/dist/esm/lib/v3/agent/utils/cuaKeyMapping.d.ts +10 -0
  437. package/dist/esm/lib/v3/agent/utils/cuaKeyMapping.js +62 -0
  438. package/dist/esm/lib/v3/agent/utils/cuaKeyMapping.js.map +1 -0
  439. package/dist/esm/lib/v3/agent/utils/googleCustomToolHandler.d.ts +25 -0
  440. package/dist/esm/lib/v3/agent/utils/googleCustomToolHandler.js +145 -0
  441. package/dist/esm/lib/v3/agent/utils/googleCustomToolHandler.js.map +1 -0
  442. package/dist/esm/lib/v3/agent/utils/handleDoneToolCall.d.ts +22 -0
  443. package/dist/esm/lib/v3/agent/utils/handleDoneToolCall.js +101 -0
  444. package/dist/esm/lib/v3/agent/utils/handleDoneToolCall.js.map +1 -0
  445. package/dist/esm/lib/v3/agent/utils/imageCompression.d.ts +53 -0
  446. package/dist/esm/lib/v3/agent/utils/imageCompression.js +204 -0
  447. package/dist/esm/lib/v3/agent/utils/imageCompression.js.map +1 -0
  448. package/dist/esm/lib/v3/agent/utils/messageProcessing.d.ts +12 -0
  449. package/dist/esm/lib/v3/agent/utils/messageProcessing.js +164 -0
  450. package/dist/esm/lib/v3/agent/utils/messageProcessing.js.map +1 -0
  451. package/dist/esm/lib/v3/agent/utils/screenshotHandler.d.ts +10 -0
  452. package/dist/esm/lib/v3/agent/utils/screenshotHandler.js +26 -0
  453. package/dist/esm/lib/v3/agent/utils/screenshotHandler.js.map +1 -0
  454. package/dist/esm/lib/v3/agent/utils/validateExperimentalFeatures.d.ts +26 -0
  455. package/dist/esm/lib/v3/agent/utils/validateExperimentalFeatures.js +79 -0
  456. package/dist/esm/lib/v3/agent/utils/validateExperimentalFeatures.js.map +1 -0
  457. package/dist/esm/lib/v3/agent/utils/xpath.d.ts +11 -0
  458. package/dist/esm/lib/v3/agent/utils/xpath.js +19 -0
  459. package/dist/esm/lib/v3/agent/utils/xpath.js.map +1 -0
  460. package/dist/esm/lib/v3/api.d.ts +86 -0
  461. package/dist/esm/lib/v3/api.js +484 -0
  462. package/dist/esm/lib/v3/api.js.map +1 -0
  463. package/dist/esm/lib/v3/cache/ActCache.d.ts +23 -0
  464. package/dist/esm/lib/v3/cache/ActCache.js +292 -0
  465. package/dist/esm/lib/v3/cache/ActCache.js.map +1 -0
  466. package/dist/esm/lib/v3/cache/AgentCache.d.ts +109 -0
  467. package/dist/esm/lib/v3/cache/AgentCache.js +640 -0
  468. package/dist/esm/lib/v3/cache/AgentCache.js.map +1 -0
  469. package/dist/esm/lib/v3/cache/CacheStorage.d.ts +17 -0
  470. package/dist/esm/lib/v3/cache/CacheStorage.js +98 -0
  471. package/dist/esm/lib/v3/cache/CacheStorage.js.map +1 -0
  472. package/dist/esm/lib/v3/cache/serverAgentCache.d.ts +7 -0
  473. package/dist/esm/lib/v3/cache/serverAgentCache.js +49 -0
  474. package/dist/esm/lib/v3/cache/serverAgentCache.js.map +1 -0
  475. package/dist/esm/lib/v3/cache/utils.d.ts +15 -0
  476. package/dist/esm/lib/v3/cache/utils.js +39 -0
  477. package/dist/esm/lib/v3/cache/utils.js.map +1 -0
  478. package/dist/esm/lib/v3/cli.d.ts +2 -0
  479. package/dist/esm/lib/v3/cli.js +10 -0
  480. package/dist/esm/lib/v3/cli.js.map +1 -0
  481. package/dist/esm/lib/v3/dom/a11yScripts/index.d.ts +11 -0
  482. package/dist/esm/lib/v3/dom/a11yScripts/index.js +117 -0
  483. package/dist/esm/lib/v3/dom/a11yScripts/index.js.map +1 -0
  484. package/dist/esm/lib/v3/dom/build/a11yScripts.generated.d.ts +16 -0
  485. package/dist/esm/lib/v3/dom/build/a11yScripts.generated.js +20 -0
  486. package/dist/esm/lib/v3/dom/build/a11yScripts.generated.js.map +1 -0
  487. package/dist/esm/lib/v3/dom/build/locatorScripts.generated.d.ts +52 -0
  488. package/dist/esm/lib/v3/dom/build/locatorScripts.generated.js +56 -0
  489. package/dist/esm/lib/v3/dom/build/locatorScripts.generated.js.map +1 -0
  490. package/dist/esm/lib/v3/dom/build/reRenderScriptContent.d.ts +1 -0
  491. package/dist/esm/lib/v3/dom/build/reRenderScriptContent.js +2 -0
  492. package/dist/esm/lib/v3/dom/build/reRenderScriptContent.js.map +1 -0
  493. package/dist/esm/lib/v3/dom/build/rerender-index.d.ts +0 -0
  494. package/dist/esm/lib/v3/dom/build/rerender-index.js +1 -0
  495. package/dist/esm/lib/v3/dom/build/rerender-index.js.map +1 -0
  496. package/dist/esm/lib/v3/dom/build/screenshotScripts.generated.d.ts +4 -0
  497. package/dist/esm/lib/v3/dom/build/screenshotScripts.generated.js +8 -0
  498. package/dist/esm/lib/v3/dom/build/screenshotScripts.generated.js.map +1 -0
  499. package/dist/esm/lib/v3/dom/build/scriptV3Content.d.ts +1 -0
  500. package/dist/esm/lib/v3/dom/build/scriptV3Content.js +2 -0
  501. package/dist/esm/lib/v3/dom/build/scriptV3Content.js.map +1 -0
  502. package/dist/esm/lib/v3/dom/build/v3-index.d.ts +0 -0
  503. package/dist/esm/lib/v3/dom/build/v3-index.js +1 -0
  504. package/dist/esm/lib/v3/dom/build/v3-index.js.map +1 -0
  505. package/dist/esm/lib/v3/dom/genA11yScripts.d.ts +1 -0
  506. package/dist/esm/lib/v3/dom/genA11yScripts.js +54 -0
  507. package/dist/esm/lib/v3/dom/genA11yScripts.js.map +1 -0
  508. package/dist/esm/lib/v3/dom/genDomScripts.d.ts +1 -0
  509. package/dist/esm/lib/v3/dom/genDomScripts.js +38 -0
  510. package/dist/esm/lib/v3/dom/genDomScripts.js.map +1 -0
  511. package/dist/esm/lib/v3/dom/genLocatorScripts.d.ts +1 -0
  512. package/dist/esm/lib/v3/dom/genLocatorScripts.js +51 -0
  513. package/dist/esm/lib/v3/dom/genLocatorScripts.js.map +1 -0
  514. package/dist/esm/lib/v3/dom/genScreenshotScripts.d.ts +1 -0
  515. package/dist/esm/lib/v3/dom/genScreenshotScripts.js +37 -0
  516. package/dist/esm/lib/v3/dom/genScreenshotScripts.js.map +1 -0
  517. package/dist/esm/lib/v3/dom/index.d.ts +1 -0
  518. package/dist/esm/lib/v3/dom/index.js +2 -0
  519. package/dist/esm/lib/v3/dom/index.js.map +1 -0
  520. package/dist/esm/lib/v3/dom/locatorScripts/counts.d.ts +15 -0
  521. package/dist/esm/lib/v3/dom/locatorScripts/counts.js +272 -0
  522. package/dist/esm/lib/v3/dom/locatorScripts/counts.js.map +1 -0
  523. package/dist/esm/lib/v3/dom/locatorScripts/index.d.ts +4 -0
  524. package/dist/esm/lib/v3/dom/locatorScripts/index.js +5 -0
  525. package/dist/esm/lib/v3/dom/locatorScripts/index.js.map +1 -0
  526. package/dist/esm/lib/v3/dom/locatorScripts/scripts.d.ts +37 -0
  527. package/dist/esm/lib/v3/dom/locatorScripts/scripts.js +458 -0
  528. package/dist/esm/lib/v3/dom/locatorScripts/scripts.js.map +1 -0
  529. package/dist/esm/lib/v3/dom/locatorScripts/selectors.d.ts +4 -0
  530. package/dist/esm/lib/v3/dom/locatorScripts/selectors.js +283 -0
  531. package/dist/esm/lib/v3/dom/locatorScripts/selectors.js.map +1 -0
  532. package/dist/esm/lib/v3/dom/locatorScripts/waitForSelector.d.ts +19 -0
  533. package/dist/esm/lib/v3/dom/locatorScripts/waitForSelector.js +283 -0
  534. package/dist/esm/lib/v3/dom/locatorScripts/waitForSelector.js.map +1 -0
  535. package/dist/esm/lib/v3/dom/locatorScripts/xpathParser.d.ts +76 -0
  536. package/dist/esm/lib/v3/dom/locatorScripts/xpathParser.js +376 -0
  537. package/dist/esm/lib/v3/dom/locatorScripts/xpathParser.js.map +1 -0
  538. package/dist/esm/lib/v3/dom/locatorScripts/xpathResolver.d.ts +9 -0
  539. package/dist/esm/lib/v3/dom/locatorScripts/xpathResolver.js +196 -0
  540. package/dist/esm/lib/v3/dom/locatorScripts/xpathResolver.js.map +1 -0
  541. package/dist/esm/lib/v3/dom/piercer.entry.d.ts +1 -0
  542. package/dist/esm/lib/v3/dom/piercer.entry.js +3 -0
  543. package/dist/esm/lib/v3/dom/piercer.entry.js.map +1 -0
  544. package/dist/esm/lib/v3/dom/piercer.runtime.d.ts +23 -0
  545. package/dist/esm/lib/v3/dom/piercer.runtime.js +90 -0
  546. package/dist/esm/lib/v3/dom/piercer.runtime.js.map +1 -0
  547. package/dist/esm/lib/v3/dom/rerenderMissingShadows.entry.d.ts +1 -0
  548. package/dist/esm/lib/v3/dom/rerenderMissingShadows.entry.js +3 -0
  549. package/dist/esm/lib/v3/dom/rerenderMissingShadows.entry.js.map +1 -0
  550. package/dist/esm/lib/v3/dom/rerenderMissingShadows.runtime.d.ts +1 -0
  551. package/dist/esm/lib/v3/dom/rerenderMissingShadows.runtime.js +40 -0
  552. package/dist/esm/lib/v3/dom/rerenderMissingShadows.runtime.js.map +1 -0
  553. package/dist/esm/lib/v3/dom/screenshotScripts/index.d.ts +1 -0
  554. package/dist/esm/lib/v3/dom/screenshotScripts/index.js +2 -0
  555. package/dist/esm/lib/v3/dom/screenshotScripts/index.js.map +1 -0
  556. package/dist/esm/lib/v3/dom/screenshotScripts/resolveMaskRect.d.ts +8 -0
  557. package/dist/esm/lib/v3/dom/screenshotScripts/resolveMaskRect.js +82 -0
  558. package/dist/esm/lib/v3/dom/screenshotScripts/resolveMaskRect.js.map +1 -0
  559. package/dist/esm/lib/v3/external_clients/aisdk.d.ts +11 -0
  560. package/dist/esm/lib/v3/external_clients/aisdk.js +103 -0
  561. package/dist/esm/lib/v3/external_clients/aisdk.js.map +1 -0
  562. package/dist/esm/lib/v3/external_clients/customOpenAI.d.ts +18 -0
  563. package/dist/esm/lib/v3/external_clients/customOpenAI.js +220 -0
  564. package/dist/esm/lib/v3/external_clients/customOpenAI.js.map +1 -0
  565. package/dist/esm/lib/v3/flowLogger.d.ts +139 -0
  566. package/dist/esm/lib/v3/flowLogger.js +868 -0
  567. package/dist/esm/lib/v3/flowLogger.js.map +1 -0
  568. package/dist/esm/lib/v3/handlers/actHandler.d.ts +21 -0
  569. package/dist/esm/lib/v3/handlers/actHandler.js +340 -0
  570. package/dist/esm/lib/v3/handlers/actHandler.js.map +1 -0
  571. package/dist/esm/lib/v3/handlers/extractHandler.d.ts +31 -0
  572. package/dist/esm/lib/v3/handlers/extractHandler.js +139 -0
  573. package/dist/esm/lib/v3/handlers/extractHandler.js.map +1 -0
  574. package/dist/esm/lib/v3/handlers/handlerUtils/actHandlerUtils.d.ts +24 -0
  575. package/dist/esm/lib/v3/handlers/handlerUtils/actHandlerUtils.js +623 -0
  576. package/dist/esm/lib/v3/handlers/handlerUtils/actHandlerUtils.js.map +1 -0
  577. package/dist/esm/lib/v3/handlers/handlerUtils/timeoutGuard.d.ts +2 -0
  578. package/dist/esm/lib/v3/handlers/handlerUtils/timeoutGuard.js +14 -0
  579. package/dist/esm/lib/v3/handlers/handlerUtils/timeoutGuard.js.map +1 -0
  580. package/dist/esm/lib/v3/handlers/observeHandler.d.ts +17 -0
  581. package/dist/esm/lib/v3/handlers/observeHandler.js +156 -0
  582. package/dist/esm/lib/v3/handlers/observeHandler.js.map +1 -0
  583. package/dist/esm/lib/v3/handlers/v3AgentHandler.d.ts +32 -0
  584. package/dist/esm/lib/v3/handlers/v3AgentHandler.js +461 -0
  585. package/dist/esm/lib/v3/handlers/v3AgentHandler.js.map +1 -0
  586. package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.d.ts +33 -0
  587. package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.js +528 -0
  588. package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.js.map +1 -0
  589. package/dist/esm/lib/v3/index.d.ts +18 -0
  590. package/dist/esm/lib/v3/index.js +14 -0
  591. package/dist/esm/lib/v3/index.js.map +1 -0
  592. package/dist/esm/lib/v3/launch/browserbase.d.ts +7 -0
  593. package/dist/esm/lib/v3/launch/browserbase.js +46 -0
  594. package/dist/esm/lib/v3/launch/browserbase.js.map +1 -0
  595. package/dist/esm/lib/v3/launch/local.d.ts +15 -0
  596. package/dist/esm/lib/v3/launch/local.js +98 -0
  597. package/dist/esm/lib/v3/launch/local.js.map +1 -0
  598. package/dist/esm/lib/v3/llm/AnthropicClient.d.ts +16 -0
  599. package/dist/esm/lib/v3/llm/AnthropicClient.js +239 -0
  600. package/dist/esm/lib/v3/llm/AnthropicClient.js.map +1 -0
  601. package/dist/esm/lib/v3/llm/CerebrasClient.d.ts +17 -0
  602. package/dist/esm/lib/v3/llm/CerebrasClient.js +235 -0
  603. package/dist/esm/lib/v3/llm/CerebrasClient.js.map +1 -0
  604. package/dist/esm/lib/v3/llm/GoogleClient.d.ts +19 -0
  605. package/dist/esm/lib/v3/llm/GoogleClient.js +369 -0
  606. package/dist/esm/lib/v3/llm/GoogleClient.js.map +1 -0
  607. package/dist/esm/lib/v3/llm/GroqClient.d.ts +17 -0
  608. package/dist/esm/lib/v3/llm/GroqClient.js +236 -0
  609. package/dist/esm/lib/v3/llm/GroqClient.js.map +1 -0
  610. package/dist/esm/lib/v3/llm/LLMClient.d.ts +121 -0
  611. package/dist/esm/lib/v3/llm/LLMClient.js +23 -0
  612. package/dist/esm/lib/v3/llm/LLMClient.js.map +1 -0
  613. package/dist/esm/lib/v3/llm/LLMProvider.d.ts +13 -0
  614. package/dist/esm/lib/v3/llm/LLMProvider.js +194 -0
  615. package/dist/esm/lib/v3/llm/LLMProvider.js.map +1 -0
  616. package/dist/esm/lib/v3/llm/OpenAIClient.d.ts +15 -0
  617. package/dist/esm/lib/v3/llm/OpenAIClient.js +329 -0
  618. package/dist/esm/lib/v3/llm/OpenAIClient.js.map +1 -0
  619. package/dist/esm/lib/v3/llm/aisdk.d.ts +15 -0
  620. package/dist/esm/lib/v3/llm/aisdk.js +348 -0
  621. package/dist/esm/lib/v3/llm/aisdk.js.map +1 -0
  622. package/dist/esm/lib/v3/logger.d.ts +9 -0
  623. package/dist/esm/lib/v3/logger.js +96 -0
  624. package/dist/esm/lib/v3/logger.js.map +1 -0
  625. package/dist/esm/lib/v3/mcp/connection.d.ts +11 -0
  626. package/dist/esm/lib/v3/mcp/connection.js +49 -0
  627. package/dist/esm/lib/v3/mcp/connection.js.map +1 -0
  628. package/dist/esm/lib/v3/mcp/utils.d.ts +3 -0
  629. package/dist/esm/lib/v3/mcp/utils.js +36 -0
  630. package/dist/esm/lib/v3/mcp/utils.js.map +1 -0
  631. package/dist/esm/lib/v3/shutdown/cleanupLocal.d.ts +14 -0
  632. package/dist/esm/lib/v3/shutdown/cleanupLocal.js +30 -0
  633. package/dist/esm/lib/v3/shutdown/cleanupLocal.js.map +1 -0
  634. package/dist/esm/lib/v3/shutdown/supervisor.d.ts +11 -0
  635. package/dist/esm/lib/v3/shutdown/supervisor.js +166 -0
  636. package/dist/esm/lib/v3/shutdown/supervisor.js.map +1 -0
  637. package/dist/esm/lib/v3/shutdown/supervisorClient.d.ts +15 -0
  638. package/dist/esm/lib/v3/shutdown/supervisorClient.js +93 -0
  639. package/dist/esm/lib/v3/shutdown/supervisorClient.js.map +1 -0
  640. package/dist/esm/lib/v3/tests/agent-abort-signal.spec.js +113 -0
  641. package/dist/esm/lib/v3/tests/agent-abort-signal.spec.js.map +7 -0
  642. package/dist/esm/lib/v3/tests/agent-cache-self-heal.spec.js +80 -0
  643. package/dist/esm/lib/v3/tests/agent-cache-self-heal.spec.js.map +7 -0
  644. package/dist/esm/lib/v3/tests/agent-callbacks.spec.js +374 -0
  645. package/dist/esm/lib/v3/tests/agent-callbacks.spec.js.map +7 -0
  646. package/dist/esm/lib/v3/tests/agent-experimental-validation.spec.js +357 -0
  647. package/dist/esm/lib/v3/tests/agent-experimental-validation.spec.js.map +7 -0
  648. package/dist/esm/lib/v3/tests/agent-hybrid-mode.spec.js +247 -0
  649. package/dist/esm/lib/v3/tests/agent-hybrid-mode.spec.js.map +7 -0
  650. package/dist/esm/lib/v3/tests/agent-message-continuation.spec.js +105 -0
  651. package/dist/esm/lib/v3/tests/agent-message-continuation.spec.js.map +7 -0
  652. package/dist/esm/lib/v3/tests/agent-streaming.spec.js +126 -0
  653. package/dist/esm/lib/v3/tests/agent-streaming.spec.js.map +7 -0
  654. package/dist/esm/lib/v3/tests/cdp-session-detached.spec.js +44 -0
  655. package/dist/esm/lib/v3/tests/cdp-session-detached.spec.js.map +7 -0
  656. package/dist/esm/lib/v3/tests/click-count.spec.js +147 -0
  657. package/dist/esm/lib/v3/tests/click-count.spec.js.map +7 -0
  658. package/dist/esm/lib/v3/tests/connect-to-existing-browser.spec.js +54 -0
  659. package/dist/esm/lib/v3/tests/connect-to-existing-browser.spec.js.map +7 -0
  660. package/dist/esm/lib/v3/tests/context-addInitScript.spec.js +176 -0
  661. package/dist/esm/lib/v3/tests/context-addInitScript.spec.js.map +7 -0
  662. package/dist/esm/lib/v3/tests/default-page-tracking.spec.js +53 -0
  663. package/dist/esm/lib/v3/tests/default-page-tracking.spec.js.map +7 -0
  664. package/dist/esm/lib/v3/tests/downloads.spec.js +58 -0
  665. package/dist/esm/lib/v3/tests/downloads.spec.js.map +7 -0
  666. package/dist/esm/lib/v3/tests/frame-get-location-and-click.spec.js +53 -0
  667. package/dist/esm/lib/v3/tests/frame-get-location-and-click.spec.js.map +7 -0
  668. package/dist/esm/lib/v3/tests/iframe-ctx-addInitScript.spec.js +493 -0
  669. package/dist/esm/lib/v3/tests/iframe-ctx-addInitScript.spec.js.map +7 -0
  670. package/dist/esm/lib/v3/tests/keep-alive.child.js +92 -0
  671. package/dist/esm/lib/v3/tests/keep-alive.child.js.map +7 -0
  672. package/dist/esm/lib/v3/tests/keep-alive.helpers.js +532 -0
  673. package/dist/esm/lib/v3/tests/keep-alive.helpers.js.map +7 -0
  674. package/dist/esm/lib/v3/tests/keep-alive.spec.js +19 -0
  675. package/dist/esm/lib/v3/tests/keep-alive.spec.js.map +7 -0
  676. package/dist/esm/lib/v3/tests/keyboard.spec.js +296 -0
  677. package/dist/esm/lib/v3/tests/keyboard.spec.js.map +7 -0
  678. package/dist/esm/lib/v3/tests/locator-backend-node-id.spec.js +159 -0
  679. package/dist/esm/lib/v3/tests/locator-backend-node-id.spec.js.map +7 -0
  680. package/dist/esm/lib/v3/tests/locator-content-methods.spec.js +191 -0
  681. package/dist/esm/lib/v3/tests/locator-content-methods.spec.js.map +7 -0
  682. package/dist/esm/lib/v3/tests/locator-count-iframe.spec.js +108 -0
  683. package/dist/esm/lib/v3/tests/locator-count-iframe.spec.js.map +7 -0
  684. package/dist/esm/lib/v3/tests/locator-count.spec.js +71 -0
  685. package/dist/esm/lib/v3/tests/locator-count.spec.js.map +7 -0
  686. package/dist/esm/lib/v3/tests/locator-fill.spec.js +118 -0
  687. package/dist/esm/lib/v3/tests/locator-fill.spec.js.map +7 -0
  688. package/dist/esm/lib/v3/tests/locator-input-methods.spec.js +136 -0
  689. package/dist/esm/lib/v3/tests/locator-input-methods.spec.js.map +7 -0
  690. package/dist/esm/lib/v3/tests/locator-nth.spec.js +157 -0
  691. package/dist/esm/lib/v3/tests/locator-nth.spec.js.map +7 -0
  692. package/dist/esm/lib/v3/tests/locator-select-option.spec.js +242 -0
  693. package/dist/esm/lib/v3/tests/locator-select-option.spec.js.map +7 -0
  694. package/dist/esm/lib/v3/tests/logger-initialization.spec.js +552 -0
  695. package/dist/esm/lib/v3/tests/logger-initialization.spec.js.map +7 -0
  696. package/dist/esm/lib/v3/tests/multi-instance-logger.spec.js +269 -0
  697. package/dist/esm/lib/v3/tests/multi-instance-logger.spec.js.map +7 -0
  698. package/dist/esm/lib/v3/tests/nested-div.spec.js +23 -0
  699. package/dist/esm/lib/v3/tests/nested-div.spec.js.map +7 -0
  700. package/dist/esm/lib/v3/tests/page-addInitScript.spec.js +90 -0
  701. package/dist/esm/lib/v3/tests/page-addInitScript.spec.js.map +7 -0
  702. package/dist/esm/lib/v3/tests/page-console.spec.js +56 -0
  703. package/dist/esm/lib/v3/tests/page-console.spec.js.map +7 -0
  704. package/dist/esm/lib/v3/tests/page-drag-and-drop.spec.js +418 -0
  705. package/dist/esm/lib/v3/tests/page-drag-and-drop.spec.js.map +7 -0
  706. package/dist/esm/lib/v3/tests/page-goto-response.spec.js +35 -0
  707. package/dist/esm/lib/v3/tests/page-goto-response.spec.js.map +7 -0
  708. package/dist/esm/lib/v3/tests/page-hover.spec.js +167 -0
  709. package/dist/esm/lib/v3/tests/page-hover.spec.js.map +7 -0
  710. package/dist/esm/lib/v3/tests/page-screenshot.spec.js +273 -0
  711. package/dist/esm/lib/v3/tests/page-screenshot.spec.js.map +7 -0
  712. package/dist/esm/lib/v3/tests/page-scroll.spec.js +182 -0
  713. package/dist/esm/lib/v3/tests/page-scroll.spec.js.map +7 -0
  714. package/dist/esm/lib/v3/tests/page-send-cdp.spec.js +46 -0
  715. package/dist/esm/lib/v3/tests/page-send-cdp.spec.js.map +7 -0
  716. package/dist/esm/lib/v3/tests/perform-understudy-method.spec.js +98 -0
  717. package/dist/esm/lib/v3/tests/perform-understudy-method.spec.js.map +7 -0
  718. package/dist/esm/lib/v3/tests/setinputfiles.spec.js +126 -0
  719. package/dist/esm/lib/v3/tests/setinputfiles.spec.js.map +7 -0
  720. package/dist/esm/lib/v3/tests/shadow-iframe-oopif.spec.js +134 -0
  721. package/dist/esm/lib/v3/tests/shadow-iframe-oopif.spec.js.map +7 -0
  722. package/dist/esm/lib/v3/tests/shadow-iframe-spif.spec.js +134 -0
  723. package/dist/esm/lib/v3/tests/shadow-iframe-spif.spec.js.map +7 -0
  724. package/dist/esm/lib/v3/tests/testUtils.js +31 -0
  725. package/dist/esm/lib/v3/tests/testUtils.js.map +7 -0
  726. package/dist/esm/lib/v3/tests/text-selector-innermost.spec.js +100 -0
  727. package/dist/esm/lib/v3/tests/text-selector-innermost.spec.js.map +7 -0
  728. package/dist/esm/lib/v3/tests/timeouts.spec.js +32 -0
  729. package/dist/esm/lib/v3/tests/timeouts.spec.js.map +7 -0
  730. package/dist/esm/lib/v3/tests/user-data-dir.spec.js +43 -0
  731. package/dist/esm/lib/v3/tests/user-data-dir.spec.js.map +7 -0
  732. package/dist/esm/lib/v3/tests/v3.config.js +15 -0
  733. package/dist/esm/lib/v3/tests/v3.config.js.map +7 -0
  734. package/dist/esm/lib/v3/tests/v3.dynamic.config.js +43 -0
  735. package/dist/esm/lib/v3/tests/v3.dynamic.config.js.map +7 -0
  736. package/dist/esm/lib/v3/tests/v3.playwright.config.js +41 -0
  737. package/dist/esm/lib/v3/tests/v3.playwright.config.js.map +7 -0
  738. package/dist/esm/lib/v3/tests/wait-for-selector.spec.js +593 -0
  739. package/dist/esm/lib/v3/tests/wait-for-selector.spec.js.map +7 -0
  740. package/dist/esm/lib/v3/tests/wait-for-timeout.spec.js +97 -0
  741. package/dist/esm/lib/v3/tests/wait-for-timeout.spec.js.map +7 -0
  742. package/dist/esm/lib/v3/tests/xpath-for-location-deep.spec.js +77 -0
  743. package/dist/esm/lib/v3/tests/xpath-for-location-deep.spec.js.map +7 -0
  744. package/dist/esm/lib/v3/timeoutConfig.d.ts +2 -0
  745. package/dist/esm/lib/v3/timeoutConfig.js +27 -0
  746. package/dist/esm/lib/v3/timeoutConfig.js.map +1 -0
  747. package/dist/esm/lib/v3/types/private/agent.d.ts +6 -0
  748. package/dist/esm/lib/v3/types/private/agent.js +2 -0
  749. package/dist/esm/lib/v3/types/private/agent.js.map +1 -0
  750. package/dist/esm/lib/v3/types/private/api.d.ts +11 -0
  751. package/dist/esm/lib/v3/types/private/api.js +2 -0
  752. package/dist/esm/lib/v3/types/private/api.js.map +1 -0
  753. package/dist/esm/lib/v3/types/private/cache.d.ts +128 -0
  754. package/dist/esm/lib/v3/types/private/cache.js +2 -0
  755. package/dist/esm/lib/v3/types/private/cache.js.map +1 -0
  756. package/dist/esm/lib/v3/types/private/evaluator.d.ts +40 -0
  757. package/dist/esm/lib/v3/types/private/evaluator.js +2 -0
  758. package/dist/esm/lib/v3/types/private/evaluator.js.map +1 -0
  759. package/dist/esm/lib/v3/types/private/handlers.d.ts +38 -0
  760. package/dist/esm/lib/v3/types/private/handlers.js +16 -0
  761. package/dist/esm/lib/v3/types/private/handlers.js.map +1 -0
  762. package/dist/esm/lib/v3/types/private/index.d.ts +7 -0
  763. package/dist/esm/lib/v3/types/private/index.js +8 -0
  764. package/dist/esm/lib/v3/types/private/index.js.map +1 -0
  765. package/dist/esm/lib/v3/types/private/internal.d.ts +39 -0
  766. package/dist/esm/lib/v3/types/private/internal.js +2 -0
  767. package/dist/esm/lib/v3/types/private/internal.js.map +1 -0
  768. package/dist/esm/lib/v3/types/private/locator.d.ts +9 -0
  769. package/dist/esm/lib/v3/types/private/locator.js +2 -0
  770. package/dist/esm/lib/v3/types/private/locator.js.map +1 -0
  771. package/dist/esm/lib/v3/types/private/network.d.ts +34 -0
  772. package/dist/esm/lib/v3/types/private/network.js +3 -0
  773. package/dist/esm/lib/v3/types/private/network.js.map +1 -0
  774. package/dist/esm/lib/v3/types/private/shutdown.d.ts +19 -0
  775. package/dist/esm/lib/v3/types/private/shutdown.js +5 -0
  776. package/dist/esm/lib/v3/types/private/shutdown.js.map +1 -0
  777. package/dist/esm/lib/v3/types/private/shutdownErrors.d.ts +12 -0
  778. package/dist/esm/lib/v3/types/private/shutdownErrors.js +22 -0
  779. package/dist/esm/lib/v3/types/private/shutdownErrors.js.map +1 -0
  780. package/dist/esm/lib/v3/types/private/snapshot.d.ts +117 -0
  781. package/dist/esm/lib/v3/types/private/snapshot.js +2 -0
  782. package/dist/esm/lib/v3/types/private/snapshot.js.map +1 -0
  783. package/dist/esm/lib/v3/types/public/agent.d.ts +595 -0
  784. package/dist/esm/lib/v3/types/public/agent.js +15 -0
  785. package/dist/esm/lib/v3/types/public/agent.js.map +1 -0
  786. package/dist/esm/lib/v3/types/public/api.d.ts +1211 -0
  787. package/dist/esm/lib/v3/types/public/api.js +915 -0
  788. package/dist/esm/lib/v3/types/public/api.js.map +1 -0
  789. package/dist/esm/lib/v3/types/public/apiErrors.d.ts +18 -0
  790. package/dist/esm/lib/v3/types/public/apiErrors.js +32 -0
  791. package/dist/esm/lib/v3/types/public/apiErrors.js.map +1 -0
  792. package/dist/esm/lib/v3/types/public/index.d.ts +12 -0
  793. package/dist/esm/lib/v3/types/public/index.js +14 -0
  794. package/dist/esm/lib/v3/types/public/index.js.map +1 -0
  795. package/dist/esm/lib/v3/types/public/locator.d.ts +9 -0
  796. package/dist/esm/lib/v3/types/public/locator.js +2 -0
  797. package/dist/esm/lib/v3/types/public/locator.js.map +1 -0
  798. package/dist/esm/lib/v3/types/public/logs.d.ts +23 -0
  799. package/dist/esm/lib/v3/types/public/logs.js +13 -0
  800. package/dist/esm/lib/v3/types/public/logs.js.map +1 -0
  801. package/dist/esm/lib/v3/types/public/methods.d.ts +56 -0
  802. package/dist/esm/lib/v3/types/public/methods.js +15 -0
  803. package/dist/esm/lib/v3/types/public/methods.js.map +1 -0
  804. package/dist/esm/lib/v3/types/public/metrics.d.ts +27 -0
  805. package/dist/esm/lib/v3/types/public/metrics.js +2 -0
  806. package/dist/esm/lib/v3/types/public/metrics.js.map +1 -0
  807. package/dist/esm/lib/v3/types/public/model.d.ts +65 -0
  808. package/dist/esm/lib/v3/types/public/model.js +2 -0
  809. package/dist/esm/lib/v3/types/public/model.js.map +1 -0
  810. package/dist/esm/lib/v3/types/public/options.d.ts +70 -0
  811. package/dist/esm/lib/v3/types/public/options.js +4 -0
  812. package/dist/esm/lib/v3/types/public/options.js.map +1 -0
  813. package/dist/esm/lib/v3/types/public/page.d.ts +18 -0
  814. package/dist/esm/lib/v3/types/public/page.js +3 -0
  815. package/dist/esm/lib/v3/types/public/page.js.map +1 -0
  816. package/dist/esm/lib/v3/types/public/screenshotTypes.d.ts +25 -0
  817. package/dist/esm/lib/v3/types/public/screenshotTypes.js +2 -0
  818. package/dist/esm/lib/v3/types/public/screenshotTypes.js.map +1 -0
  819. package/dist/esm/lib/v3/types/public/sdkErrors.d.ts +152 -0
  820. package/dist/esm/lib/v3/types/public/sdkErrors.js +305 -0
  821. package/dist/esm/lib/v3/types/public/sdkErrors.js.map +1 -0
  822. package/dist/esm/lib/v3/understudy/a11y/snapshot/a11yTree.d.ts +15 -0
  823. package/dist/esm/lib/v3/understudy/a11y/snapshot/a11yTree.js +196 -0
  824. package/dist/esm/lib/v3/understudy/a11y/snapshot/a11yTree.js.map +1 -0
  825. package/dist/esm/lib/v3/understudy/a11y/snapshot/activeElement.d.ts +8 -0
  826. package/dist/esm/lib/v3/understudy/a11y/snapshot/activeElement.js +121 -0
  827. package/dist/esm/lib/v3/understudy/a11y/snapshot/activeElement.js.map +1 -0
  828. package/dist/esm/lib/v3/understudy/a11y/snapshot/capture.d.ts +77 -0
  829. package/dist/esm/lib/v3/understudy/a11y/snapshot/capture.js +336 -0
  830. package/dist/esm/lib/v3/understudy/a11y/snapshot/capture.js.map +1 -0
  831. package/dist/esm/lib/v3/understudy/a11y/snapshot/coordinateResolver.d.ts +7 -0
  832. package/dist/esm/lib/v3/understudy/a11y/snapshot/coordinateResolver.js +129 -0
  833. package/dist/esm/lib/v3/understudy/a11y/snapshot/coordinateResolver.js.map +1 -0
  834. package/dist/esm/lib/v3/understudy/a11y/snapshot/domTree.d.ts +46 -0
  835. package/dist/esm/lib/v3/understudy/a11y/snapshot/domTree.js +274 -0
  836. package/dist/esm/lib/v3/understudy/a11y/snapshot/domTree.js.map +1 -0
  837. package/dist/esm/lib/v3/understudy/a11y/snapshot/focusSelectors.d.ts +24 -0
  838. package/dist/esm/lib/v3/understudy/a11y/snapshot/focusSelectors.js +216 -0
  839. package/dist/esm/lib/v3/understudy/a11y/snapshot/focusSelectors.js.map +1 -0
  840. package/dist/esm/lib/v3/understudy/a11y/snapshot/index.d.ts +4 -0
  841. package/dist/esm/lib/v3/understudy/a11y/snapshot/index.js +5 -0
  842. package/dist/esm/lib/v3/understudy/a11y/snapshot/index.js.map +1 -0
  843. package/dist/esm/lib/v3/understudy/a11y/snapshot/sessions.d.ts +16 -0
  844. package/dist/esm/lib/v3/understudy/a11y/snapshot/sessions.js +22 -0
  845. package/dist/esm/lib/v3/understudy/a11y/snapshot/sessions.js.map +1 -0
  846. package/dist/esm/lib/v3/understudy/a11y/snapshot/treeFormatUtils.d.ts +28 -0
  847. package/dist/esm/lib/v3/understudy/a11y/snapshot/treeFormatUtils.js +135 -0
  848. package/dist/esm/lib/v3/understudy/a11y/snapshot/treeFormatUtils.js.map +1 -0
  849. package/dist/esm/lib/v3/understudy/a11y/snapshot/xpathUtils.d.ts +26 -0
  850. package/dist/esm/lib/v3/understudy/a11y/snapshot/xpathUtils.js +102 -0
  851. package/dist/esm/lib/v3/understudy/a11y/snapshot/xpathUtils.js.map +1 -0
  852. package/dist/esm/lib/v3/understudy/a11yInvocation.d.ts +8 -0
  853. package/dist/esm/lib/v3/understudy/a11yInvocation.js +12 -0
  854. package/dist/esm/lib/v3/understudy/a11yInvocation.js.map +1 -0
  855. package/dist/esm/lib/v3/understudy/cdp.d.ts +69 -0
  856. package/dist/esm/lib/v3/understudy/cdp.js +251 -0
  857. package/dist/esm/lib/v3/understudy/cdp.js.map +1 -0
  858. package/dist/esm/lib/v3/understudy/consoleMessage.d.ts +22 -0
  859. package/dist/esm/lib/v3/understudy/consoleMessage.js +66 -0
  860. package/dist/esm/lib/v3/understudy/consoleMessage.js.map +1 -0
  861. package/dist/esm/lib/v3/understudy/context.d.ts +132 -0
  862. package/dist/esm/lib/v3/understudy/context.js +696 -0
  863. package/dist/esm/lib/v3/understudy/context.js.map +1 -0
  864. package/dist/esm/lib/v3/understudy/deepLocator.d.ts +87 -0
  865. package/dist/esm/lib/v3/understudy/deepLocator.js +218 -0
  866. package/dist/esm/lib/v3/understudy/deepLocator.js.map +1 -0
  867. package/dist/esm/lib/v3/understudy/executionContextRegistry.d.ts +15 -0
  868. package/dist/esm/lib/v3/understudy/executionContextRegistry.js +83 -0
  869. package/dist/esm/lib/v3/understudy/executionContextRegistry.js.map +1 -0
  870. package/dist/esm/lib/v3/understudy/fileUploadUtils.d.ts +13 -0
  871. package/dist/esm/lib/v3/understudy/fileUploadUtils.js +81 -0
  872. package/dist/esm/lib/v3/understudy/fileUploadUtils.js.map +1 -0
  873. package/dist/esm/lib/v3/understudy/frame.d.ts +69 -0
  874. package/dist/esm/lib/v3/understudy/frame.js +211 -0
  875. package/dist/esm/lib/v3/understudy/frame.js.map +1 -0
  876. package/dist/esm/lib/v3/understudy/frameLocator.d.ts +50 -0
  877. package/dist/esm/lib/v3/understudy/frameLocator.js +255 -0
  878. package/dist/esm/lib/v3/understudy/frameLocator.js.map +1 -0
  879. package/dist/esm/lib/v3/understudy/frameRegistry.d.ts +101 -0
  880. package/dist/esm/lib/v3/understudy/frameRegistry.js +298 -0
  881. package/dist/esm/lib/v3/understudy/frameRegistry.js.map +1 -0
  882. package/dist/esm/lib/v3/understudy/initScripts.d.ts +2 -0
  883. package/dist/esm/lib/v3/understudy/initScripts.js +33 -0
  884. package/dist/esm/lib/v3/understudy/initScripts.js.map +1 -0
  885. package/dist/esm/lib/v3/understudy/lifecycleWatcher.d.ts +64 -0
  886. package/dist/esm/lib/v3/understudy/lifecycleWatcher.js +245 -0
  887. package/dist/esm/lib/v3/understudy/lifecycleWatcher.js.map +1 -0
  888. package/dist/esm/lib/v3/understudy/locator.d.ts +194 -0
  889. package/dist/esm/lib/v3/understudy/locator.js +753 -0
  890. package/dist/esm/lib/v3/understudy/locator.js.map +1 -0
  891. package/dist/esm/lib/v3/understudy/locatorInvocation.d.ts +8 -0
  892. package/dist/esm/lib/v3/understudy/locatorInvocation.js +12 -0
  893. package/dist/esm/lib/v3/understudy/locatorInvocation.js.map +1 -0
  894. package/dist/esm/lib/v3/understudy/navigationResponseTracker.d.ts +84 -0
  895. package/dist/esm/lib/v3/understudy/navigationResponseTracker.js +224 -0
  896. package/dist/esm/lib/v3/understudy/navigationResponseTracker.js.map +1 -0
  897. package/dist/esm/lib/v3/understudy/networkManager.d.ts +53 -0
  898. package/dist/esm/lib/v3/understudy/networkManager.js +306 -0
  899. package/dist/esm/lib/v3/understudy/networkManager.js.map +1 -0
  900. package/dist/esm/lib/v3/understudy/page.d.ts +354 -0
  901. package/dist/esm/lib/v3/understudy/page.js +1942 -0
  902. package/dist/esm/lib/v3/understudy/page.js.map +1 -0
  903. package/dist/esm/lib/v3/understudy/piercer.d.ts +4 -0
  904. package/dist/esm/lib/v3/understudy/piercer.js +61 -0
  905. package/dist/esm/lib/v3/understudy/piercer.js.map +1 -0
  906. package/dist/esm/lib/v3/understudy/response.d.ts +137 -0
  907. package/dist/esm/lib/v3/understudy/response.js +330 -0
  908. package/dist/esm/lib/v3/understudy/response.js.map +1 -0
  909. package/dist/esm/lib/v3/understudy/screenshotUtils.d.ts +16 -0
  910. package/dist/esm/lib/v3/understudy/screenshotUtils.js +352 -0
  911. package/dist/esm/lib/v3/understudy/screenshotUtils.js.map +1 -0
  912. package/dist/esm/lib/v3/understudy/selectorResolver.d.ts +38 -0
  913. package/dist/esm/lib/v3/understudy/selectorResolver.js +296 -0
  914. package/dist/esm/lib/v3/understudy/selectorResolver.js.map +1 -0
  915. package/dist/esm/lib/v3/v3.d.ts +191 -0
  916. package/dist/esm/lib/v3/v3.js +1569 -0
  917. package/dist/esm/lib/v3/v3.js.map +1 -0
  918. package/dist/esm/lib/v3/zodCompat.d.ts +12 -0
  919. package/dist/esm/lib/v3/zodCompat.js +17 -0
  920. package/dist/esm/lib/v3/zodCompat.js.map +1 -0
  921. package/dist/esm/lib/v3Evaluator.d.ts +19 -0
  922. package/dist/esm/lib/v3Evaluator.js +210 -0
  923. package/dist/esm/lib/v3Evaluator.js.map +1 -0
  924. package/dist/esm/lib/version.d.ts +5 -0
  925. package/dist/esm/lib/version.js +6 -0
  926. package/dist/esm/lib/version.js.map +1 -0
  927. package/dist/esm/package.json +3 -0
  928. package/dist/esm/tests/browserbase-session-accessors.test.js +101 -0
  929. package/dist/esm/tests/browserbase-session-accessors.test.js.map +7 -0
  930. package/dist/esm/tests/cache-llm-resolution.test.js +187 -0
  931. package/dist/esm/tests/cache-llm-resolution.test.js.map +7 -0
  932. package/dist/esm/tests/helpers/mockCDPSession.js +27 -0
  933. package/dist/esm/tests/helpers/mockCDPSession.js.map +7 -0
  934. package/dist/esm/tests/llm-provider.test.js +57 -0
  935. package/dist/esm/tests/llm-provider.test.js.map +7 -0
  936. package/dist/esm/tests/model-deprecation.test.js +135 -0
  937. package/dist/esm/tests/model-deprecation.test.js.map +7 -0
  938. package/dist/esm/tests/page-snapshot.test.js +36 -0
  939. package/dist/esm/tests/page-snapshot.test.js.map +7 -0
  940. package/dist/esm/tests/public-api/export-surface.test.js +54 -0
  941. package/dist/esm/tests/public-api/export-surface.test.js.map +7 -0
  942. package/dist/esm/tests/public-api/llm-and-agents.test.js +128 -0
  943. package/dist/esm/tests/public-api/llm-and-agents.test.js.map +7 -0
  944. package/dist/esm/tests/public-api/public-error-types.test.js +71 -0
  945. package/dist/esm/tests/public-api/public-error-types.test.js.map +7 -0
  946. package/dist/esm/tests/public-api/public-types.test.js +74 -0
  947. package/dist/esm/tests/public-api/public-types.test.js.map +7 -0
  948. package/dist/esm/tests/public-api/runtime-utils.test.js +31 -0
  949. package/dist/esm/tests/public-api/runtime-utils.test.js.map +7 -0
  950. package/dist/esm/tests/public-api/schema-utils.test.js +78 -0
  951. package/dist/esm/tests/public-api/schema-utils.test.js.map +7 -0
  952. package/dist/esm/tests/public-api/timeout-error-types.test.js +81 -0
  953. package/dist/esm/tests/public-api/timeout-error-types.test.js.map +7 -0
  954. package/dist/esm/tests/public-api/tool-type-export.test.js +25 -0
  955. package/dist/esm/tests/public-api/tool-type-export.test.js.map +7 -0
  956. package/dist/esm/tests/public-api/v3-core.test.js +82 -0
  957. package/dist/esm/tests/public-api/v3-core.test.js.map +7 -0
  958. package/dist/esm/tests/safety-confirmation.test.js +134 -0
  959. package/dist/esm/tests/safety-confirmation.test.js.map +7 -0
  960. package/dist/esm/tests/snapshot-a11y-resolvers.test.js +348 -0
  961. package/dist/esm/tests/snapshot-a11y-resolvers.test.js.map +7 -0
  962. package/dist/esm/tests/snapshot-a11y-tree-utils.test.js +300 -0
  963. package/dist/esm/tests/snapshot-a11y-tree-utils.test.js.map +7 -0
  964. package/dist/esm/tests/snapshot-capture-orchestration.test.js +381 -0
  965. package/dist/esm/tests/snapshot-capture-orchestration.test.js.map +7 -0
  966. package/dist/esm/tests/snapshot-cbor.test.js +197 -0
  967. package/dist/esm/tests/snapshot-cbor.test.js.map +7 -0
  968. package/dist/esm/tests/snapshot-dom-session-builders.test.js +251 -0
  969. package/dist/esm/tests/snapshot-dom-session-builders.test.js.map +7 -0
  970. package/dist/esm/tests/snapshot-dom-tree-utils.test.js +109 -0
  971. package/dist/esm/tests/snapshot-dom-tree-utils.test.js.map +7 -0
  972. package/dist/esm/tests/snapshot-focus-selectors-utils.test.js +49 -0
  973. package/dist/esm/tests/snapshot-focus-selectors-utils.test.js.map +7 -0
  974. package/dist/esm/tests/snapshot-frame-merge.test.js +391 -0
  975. package/dist/esm/tests/snapshot-frame-merge.test.js.map +7 -0
  976. package/dist/esm/tests/snapshot-tree-format-utils.test.js +113 -0
  977. package/dist/esm/tests/snapshot-tree-format-utils.test.js.map +7 -0
  978. package/dist/esm/tests/snapshot-xpath-utils.test.js +79 -0
  979. package/dist/esm/tests/snapshot-xpath-utils.test.js.map +7 -0
  980. package/dist/esm/tests/timeout-handlers.test.js +850 -0
  981. package/dist/esm/tests/timeout-handlers.test.js.map +7 -0
  982. package/dist/esm/tests/xpath-parser.test.js +317 -0
  983. package/dist/esm/tests/xpath-parser.test.js.map +7 -0
  984. package/dist/esm/tests/xpath-resolver.test.js +73 -0
  985. package/dist/esm/tests/xpath-resolver.test.js.map +7 -0
  986. package/dist/esm/tests/zod-enum-compatibility.test.js +97 -0
  987. package/dist/esm/tests/zod-enum-compatibility.test.js.map +7 -0
  988. package/package.json +41 -24
  989. package/dist/index.d.ts +0 -4363
  990. package/dist/index.js +0 -76530
@@ -0,0 +1,1569 @@
1
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
2
+ var useValue = arguments.length > 2;
3
+ for (var i = 0; i < initializers.length; i++) {
4
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
5
+ }
6
+ return useValue ? value : void 0;
7
+ };
8
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
9
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
10
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
11
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
12
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
13
+ var _, done = false;
14
+ for (var i = decorators.length - 1; i >= 0; i--) {
15
+ var context = {};
16
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
17
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
18
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
19
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
20
+ if (kind === "accessor") {
21
+ if (result === void 0) continue;
22
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
23
+ if (_ = accept(result.get)) descriptor.get = _;
24
+ if (_ = accept(result.set)) descriptor.set = _;
25
+ if (_ = accept(result.init)) initializers.unshift(_);
26
+ }
27
+ else if (_ = accept(result)) {
28
+ if (kind === "field") initializers.unshift(_);
29
+ else descriptor[key] = _;
30
+ }
31
+ }
32
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
33
+ done = true;
34
+ };
35
+ import { EventEmitter } from "events";
36
+ import fs from "fs";
37
+ import os from "os";
38
+ import path from "path";
39
+ import process from "process";
40
+ import { v7 as uuidv7 } from "uuid";
41
+ import { toJsonSchema, } from "./zodCompat.js";
42
+ import { loadApiKeyFromEnv } from "../utils.js";
43
+ import { StagehandLogger } from "../logger.js";
44
+ import { ActCache } from "./cache/ActCache.js";
45
+ import { AgentCache } from "./cache/AgentCache.js";
46
+ import { CacheStorage } from "./cache/CacheStorage.js";
47
+ import { ActHandler } from "./handlers/actHandler.js";
48
+ import { ExtractHandler } from "./handlers/extractHandler.js";
49
+ import { ObserveHandler } from "./handlers/observeHandler.js";
50
+ import { V3AgentHandler } from "./handlers/v3AgentHandler.js";
51
+ import { V3CuaAgentHandler } from "./handlers/v3CuaAgentHandler.js";
52
+ import { createBrowserbaseSession } from "./launch/browserbase.js";
53
+ import { launchLocalChrome } from "./launch/local.js";
54
+ import { LLMProvider } from "./llm/LLMProvider.js";
55
+ import { bindInstanceLogger, unbindInstanceLogger, withInstanceLogContext, } from "./logger.js";
56
+ import { cleanupLocalBrowser } from "./shutdown/cleanupLocal.js";
57
+ import { startShutdownSupervisor } from "./shutdown/supervisorClient.js";
58
+ import { resolveTools } from "./mcp/utils.js";
59
+ import { AVAILABLE_CUA_MODELS, defaultExtractSchema, V3FunctionName, CuaModelRequiredError, StagehandInvalidArgumentError, StagehandNotInitializedError, MissingEnvironmentVariableError, StagehandInitError, } from "./types/public/index.js";
60
+ import { V3Context } from "./understudy/context.js";
61
+ import { resolveModel } from "../modelUtils.js";
62
+ import { StagehandAPIClient } from "./api.js";
63
+ import { validateExperimentalFeatures } from "./agent/utils/validateExperimentalFeatures.js";
64
+ import { SessionFileLogger, logStagehandStep } from "./flowLogger.js";
65
+ import { createTimeoutGuard } from "./handlers/handlerUtils/timeoutGuard.js";
66
+ import { ActTimeoutError } from "./types/public/sdkErrors.js";
67
+ const DEFAULT_MODEL_NAME = "openai/gpt-4.1-mini";
68
+ const DEFAULT_VIEWPORT = { width: 1288, height: 711 };
69
+ function resolveModelConfiguration(model) {
70
+ if (!model) {
71
+ return { modelName: DEFAULT_MODEL_NAME };
72
+ }
73
+ if (typeof model === "string") {
74
+ return { modelName: model };
75
+ }
76
+ if (model && typeof model === "object") {
77
+ const { modelName, ...clientOptions } = model;
78
+ if (!modelName) {
79
+ throw new StagehandInvalidArgumentError("model.modelName is required when providing client options.");
80
+ }
81
+ return {
82
+ modelName,
83
+ clientOptions: clientOptions,
84
+ };
85
+ }
86
+ return { modelName: DEFAULT_MODEL_NAME };
87
+ }
88
+ /**
89
+ * V3
90
+ *
91
+ * Purpose:
92
+ * A high-level orchestrator for Stagehand V3. Abstracts away whether the browser
93
+ * runs **locally via Chrome** or remotely on **Browserbase**, and exposes simple
94
+ * entrypoints (`act`, `extract`, `observe`) that delegate to the corresponding
95
+ * handler classes.
96
+ *
97
+ * Responsibilities:
98
+ * - Bootstraps Chrome or Browserbase, ensures a working CDP WebSocket, and builds a `V3Context`.
99
+ * - Manages lifecycle: init, context access, cleanup.
100
+ * - Bridges external page objects (Playwright/Puppeteer) into internal frameIds for handlers.
101
+ * - Provides a stable API surface for downstream code regardless of runtime environment.
102
+ */
103
+ let V3 = (() => {
104
+ let _instanceExtraInitializers = [];
105
+ let _act_decorators;
106
+ let _extract_decorators;
107
+ let _observe_decorators;
108
+ return class V3 {
109
+ static {
110
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
111
+ _act_decorators = [logStagehandStep("Stagehand.act", "ACT")];
112
+ _extract_decorators = [logStagehandStep("Stagehand.extract", "EXTRACT")];
113
+ _observe_decorators = [logStagehandStep("Stagehand.observe", "OBSERVE")];
114
+ __esDecorate(this, null, _act_decorators, { kind: "method", name: "act", static: false, private: false, access: { has: obj => "act" in obj, get: obj => obj.act }, metadata: _metadata }, null, _instanceExtraInitializers);
115
+ __esDecorate(this, null, _extract_decorators, { kind: "method", name: "extract", static: false, private: false, access: { has: obj => "extract" in obj, get: obj => obj.extract }, metadata: _metadata }, null, _instanceExtraInitializers);
116
+ __esDecorate(this, null, _observe_decorators, { kind: "method", name: "observe", static: false, private: false, access: { has: obj => "observe" in obj, get: obj => obj.observe }, metadata: _metadata }, null, _instanceExtraInitializers);
117
+ if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
118
+ }
119
+ opts = __runInitializers(this, _instanceExtraInitializers);
120
+ state = { kind: "UNINITIALIZED" };
121
+ actHandler = null;
122
+ extractHandler = null;
123
+ observeHandler = null;
124
+ ctx = null;
125
+ llmClient;
126
+ /**
127
+ * Event bus for internal communication.
128
+ * Emits events like 'screenshot' when screenshots are captured during agent execution.
129
+ */
130
+ bus = new EventEmitter();
131
+ modelName;
132
+ modelClientOptions;
133
+ llmProvider;
134
+ overrideLlmClients = new Map();
135
+ domSettleTimeoutMs;
136
+ _isClosing = false;
137
+ browserbaseSessionId;
138
+ browserbaseSessionUrl;
139
+ browserbaseDebugUrl;
140
+ get browserbaseSessionID() {
141
+ return this.browserbaseSessionId;
142
+ }
143
+ get browserbaseSessionURL() {
144
+ return this.browserbaseSessionUrl;
145
+ }
146
+ get browserbaseDebugURL() {
147
+ return this.browserbaseDebugUrl;
148
+ }
149
+ /**
150
+ * Returns true if the browser is running on Browserbase.
151
+ */
152
+ get isBrowserbase() {
153
+ return this.state.kind === "BROWSERBASE";
154
+ }
155
+ /**
156
+ * Returns true if advancedStealth is enabled in Browserbase settings.
157
+ */
158
+ get isAdvancedStealth() {
159
+ return (this.opts.browserbaseSessionCreateParams?.browserSettings
160
+ ?.advancedStealth === true);
161
+ }
162
+ /**
163
+ * Returns the configured viewport dimensions from launch options.
164
+ * Falls back to default 1288x711 if not configured.
165
+ */
166
+ get configuredViewport() {
167
+ const defaultWidth = 1288;
168
+ const defaultHeight = 711;
169
+ if (this.opts.env === "BROWSERBASE") {
170
+ const vp = this.opts.browserbaseSessionCreateParams?.browserSettings?.viewport;
171
+ return {
172
+ width: vp?.width ?? defaultWidth,
173
+ height: vp?.height ?? defaultHeight,
174
+ };
175
+ }
176
+ // LOCAL env
177
+ const vp = this.opts.localBrowserLaunchOptions?.viewport;
178
+ return {
179
+ width: vp?.width ?? defaultWidth,
180
+ height: vp?.height ?? defaultHeight,
181
+ };
182
+ }
183
+ _onCdpClosed = (why) => {
184
+ if (this.state.kind === "BROWSERBASE") {
185
+ void this._logBrowserbaseSessionStatus();
186
+ }
187
+ // Single place to react to the transport closing
188
+ this._immediateShutdown(`CDP transport closed: ${why}`).catch(() => { });
189
+ };
190
+ experimental = false;
191
+ logInferenceToFile = false;
192
+ disableAPI = false;
193
+ externalLogger;
194
+ verbose = 1;
195
+ stagehandLogger;
196
+ _history = [];
197
+ instanceId;
198
+ static _processGuardsInstalled = false;
199
+ static _instances = new Set();
200
+ cacheStorage;
201
+ actCache;
202
+ agentCache;
203
+ apiClient = null;
204
+ keepAlive;
205
+ shutdownSupervisor = null;
206
+ stagehandMetrics = {
207
+ actPromptTokens: 0,
208
+ actCompletionTokens: 0,
209
+ actReasoningTokens: 0,
210
+ actCachedInputTokens: 0,
211
+ actInferenceTimeMs: 0,
212
+ extractPromptTokens: 0,
213
+ extractCompletionTokens: 0,
214
+ extractReasoningTokens: 0,
215
+ extractCachedInputTokens: 0,
216
+ extractInferenceTimeMs: 0,
217
+ observePromptTokens: 0,
218
+ observeCompletionTokens: 0,
219
+ observeReasoningTokens: 0,
220
+ observeCachedInputTokens: 0,
221
+ observeInferenceTimeMs: 0,
222
+ agentPromptTokens: 0,
223
+ agentCompletionTokens: 0,
224
+ agentReasoningTokens: 0,
225
+ agentCachedInputTokens: 0,
226
+ agentInferenceTimeMs: 0,
227
+ totalPromptTokens: 0,
228
+ totalCompletionTokens: 0,
229
+ totalReasoningTokens: 0,
230
+ totalCachedInputTokens: 0,
231
+ totalInferenceTimeMs: 0,
232
+ };
233
+ constructor(opts) {
234
+ this.externalLogger = opts.logger;
235
+ this.verbose = opts.verbose ?? 1;
236
+ this.instanceId = uuidv7();
237
+ this.keepAlive =
238
+ opts.keepAlive ?? opts.browserbaseSessionCreateParams?.keepAlive;
239
+ // Create per-instance StagehandLogger (handles usePino, verbose, externalLogger)
240
+ // This gives each V3 instance independent logger configuration
241
+ // while still sharing the underlying Pino worker thread via StagehandLogger.sharedPinoLogger
242
+ const loggerOptions = {
243
+ pretty: true,
244
+ level: "info", // Most permissive - filtering happens at instance level
245
+ };
246
+ if (opts.disablePino !== undefined) {
247
+ loggerOptions.usePino = !opts.disablePino;
248
+ }
249
+ this.stagehandLogger = new StagehandLogger(loggerOptions, opts.logger);
250
+ this.stagehandLogger.setVerbosity(this.verbose);
251
+ // Also bind to AsyncLocalStorage for v3Logger() calls from handlers
252
+ // This maintains backward compatibility with code that uses v3Logger() directly
253
+ try {
254
+ if (this.externalLogger) {
255
+ // Use external logger directly when provided
256
+ bindInstanceLogger(this.instanceId, this.externalLogger);
257
+ }
258
+ else {
259
+ // Fall back to stagehandLogger when no external logger
260
+ bindInstanceLogger(this.instanceId, (line) => {
261
+ this.stagehandLogger.log(line);
262
+ });
263
+ }
264
+ }
265
+ catch {
266
+ // ignore
267
+ }
268
+ const { modelName, clientOptions } = resolveModelConfiguration(opts.model);
269
+ this.modelName = modelName;
270
+ this.experimental = opts.experimental ?? false;
271
+ this.logInferenceToFile = opts.logInferenceToFile ?? false;
272
+ this.llmProvider = new LLMProvider(this.logger);
273
+ this.domSettleTimeoutMs = opts.domSettleTimeout;
274
+ this.disableAPI = opts.disableAPI ?? false;
275
+ const baseClientOptions = clientOptions
276
+ ? { ...clientOptions }
277
+ : {};
278
+ if (opts.llmClient) {
279
+ this.llmClient = opts.llmClient;
280
+ this.modelClientOptions = baseClientOptions;
281
+ this.disableAPI = true;
282
+ }
283
+ else {
284
+ // Ensure API key is set
285
+ let apiKey = baseClientOptions.apiKey;
286
+ if (!apiKey) {
287
+ try {
288
+ apiKey = loadApiKeyFromEnv(this.modelName.split("/")[0], // "openai", "anthropic", etc
289
+ this.logger);
290
+ }
291
+ catch (error) {
292
+ this.logger({
293
+ category: "init",
294
+ message: `Error loading API key for model ${this.modelName}: ${error}. Continuing without LLM client.`,
295
+ level: 0,
296
+ });
297
+ throw error;
298
+ }
299
+ }
300
+ this.modelClientOptions = {
301
+ ...baseClientOptions,
302
+ apiKey,
303
+ };
304
+ // Get the default client for this model
305
+ this.llmClient = this.llmProvider.getClient(this.modelName, this.modelClientOptions, { experimental: this.experimental, disableAPI: this.disableAPI });
306
+ }
307
+ this.cacheStorage = CacheStorage.create(opts.cacheDir, this.logger, {
308
+ label: "cache directory",
309
+ });
310
+ this.actCache = new ActCache({
311
+ storage: this.cacheStorage,
312
+ logger: this.logger,
313
+ getActHandler: () => this.actHandler,
314
+ getDefaultLlmClient: () => this.resolveLlmClient(),
315
+ domSettleTimeoutMs: this.domSettleTimeoutMs,
316
+ });
317
+ this.agentCache = new AgentCache({
318
+ storage: this.cacheStorage,
319
+ logger: this.logger,
320
+ getActHandler: () => this.actHandler,
321
+ getContext: () => this.ctx,
322
+ getDefaultLlmClient: () => this.resolveLlmClient(),
323
+ getBaseModelName: () => this.modelName,
324
+ getSystemPrompt: () => opts.systemPrompt,
325
+ domSettleTimeoutMs: this.domSettleTimeoutMs,
326
+ act: this.act.bind(this),
327
+ });
328
+ this.opts = opts;
329
+ // Initialize session file logger
330
+ SessionFileLogger.init(this.instanceId, opts);
331
+ // Track instance for global process guard handling
332
+ V3._instances.add(this);
333
+ }
334
+ /**
335
+ * Async property for metrics so callers can `await v3.metrics`.
336
+ * When using API mode, fetches metrics from the API. Otherwise returns local metrics.
337
+ */
338
+ get metrics() {
339
+ if (this.apiClient) {
340
+ // Fetch metrics from the API
341
+ return this.apiClient.getReplayMetrics().catch((error) => {
342
+ this.logger({
343
+ category: "metrics",
344
+ message: `Failed to fetch metrics from API: ${error}`,
345
+ level: 0,
346
+ });
347
+ // Fall back to local metrics on error
348
+ return this.stagehandMetrics;
349
+ });
350
+ }
351
+ // Return local metrics wrapped in a Promise for consistency
352
+ return Promise.resolve(this.stagehandMetrics);
353
+ }
354
+ resolveLlmClient(model) {
355
+ if (!model) {
356
+ return this.llmClient;
357
+ }
358
+ let modelName;
359
+ let clientOptions;
360
+ if (typeof model === "string") {
361
+ modelName = model;
362
+ }
363
+ else {
364
+ const { modelName: overrideModelName, ...rest } = model;
365
+ modelName = overrideModelName;
366
+ clientOptions = rest;
367
+ }
368
+ if (modelName === this.modelName &&
369
+ (!clientOptions || Object.keys(clientOptions).length === 0)) {
370
+ return this.llmClient;
371
+ }
372
+ const overrideProvider = String(modelName).split("/")[0];
373
+ const baseProvider = String(this.modelName).split("/")[0];
374
+ const mergedOptions = {
375
+ ...(overrideProvider === baseProvider ? this.modelClientOptions : {}),
376
+ ...(clientOptions ?? {}),
377
+ };
378
+ const providerKey = overrideProvider;
379
+ if (!mergedOptions.apiKey) {
380
+ const apiKey = loadApiKeyFromEnv(providerKey, this.logger);
381
+ if (apiKey) {
382
+ mergedOptions.apiKey = apiKey;
383
+ }
384
+ }
385
+ const cacheKey = JSON.stringify({
386
+ modelName,
387
+ clientOptions: mergedOptions,
388
+ });
389
+ const cached = this.overrideLlmClients.get(cacheKey);
390
+ if (cached) {
391
+ return cached;
392
+ }
393
+ const client = this.llmProvider.getClient(modelName, mergedOptions, { experimental: this.experimental, disableAPI: this.disableAPI });
394
+ this.overrideLlmClients.set(cacheKey, client);
395
+ return client;
396
+ }
397
+ beginAgentReplayRecording() {
398
+ this.agentCache.beginRecording();
399
+ }
400
+ endAgentReplayRecording() {
401
+ return this.agentCache.endRecording();
402
+ }
403
+ discardAgentReplayRecording() {
404
+ this.agentCache.discardRecording();
405
+ }
406
+ isAgentReplayRecording() {
407
+ return this.agentCache.isRecording();
408
+ }
409
+ isAgentReplayActive() {
410
+ return this.agentCache.isReplayActive();
411
+ }
412
+ recordAgentReplayStep(step) {
413
+ this.agentCache.recordStep(step);
414
+ }
415
+ /**
416
+ * Async property for history so callers can `await v3.history`.
417
+ * Returns a frozen copy to avoid external mutation.
418
+ */
419
+ get history() {
420
+ return Promise.resolve(Object.freeze([...this._history]));
421
+ }
422
+ addToHistory(method, parameters, result) {
423
+ this._history.push({
424
+ method,
425
+ parameters,
426
+ result: result ?? null,
427
+ timestamp: new Date().toISOString(),
428
+ });
429
+ }
430
+ updateMetrics(functionName, promptTokens, completionTokens, reasoningTokens, cachedInputTokens, inferenceTimeMs) {
431
+ switch (functionName) {
432
+ case V3FunctionName.ACT:
433
+ this.stagehandMetrics.actPromptTokens += promptTokens;
434
+ this.stagehandMetrics.actCompletionTokens += completionTokens;
435
+ this.stagehandMetrics.actReasoningTokens += reasoningTokens;
436
+ this.stagehandMetrics.actCachedInputTokens += cachedInputTokens;
437
+ this.stagehandMetrics.actInferenceTimeMs += inferenceTimeMs;
438
+ break;
439
+ case V3FunctionName.EXTRACT:
440
+ this.stagehandMetrics.extractPromptTokens += promptTokens;
441
+ this.stagehandMetrics.extractCompletionTokens += completionTokens;
442
+ this.stagehandMetrics.extractReasoningTokens += reasoningTokens;
443
+ this.stagehandMetrics.extractCachedInputTokens += cachedInputTokens;
444
+ this.stagehandMetrics.extractInferenceTimeMs += inferenceTimeMs;
445
+ break;
446
+ case V3FunctionName.OBSERVE:
447
+ this.stagehandMetrics.observePromptTokens += promptTokens;
448
+ this.stagehandMetrics.observeCompletionTokens += completionTokens;
449
+ this.stagehandMetrics.observeReasoningTokens += reasoningTokens;
450
+ this.stagehandMetrics.observeCachedInputTokens += cachedInputTokens;
451
+ this.stagehandMetrics.observeInferenceTimeMs += inferenceTimeMs;
452
+ break;
453
+ case V3FunctionName.AGENT:
454
+ this.stagehandMetrics.agentPromptTokens += promptTokens;
455
+ this.stagehandMetrics.agentCompletionTokens += completionTokens;
456
+ this.stagehandMetrics.agentReasoningTokens += reasoningTokens;
457
+ this.stagehandMetrics.agentCachedInputTokens += cachedInputTokens;
458
+ this.stagehandMetrics.agentInferenceTimeMs += inferenceTimeMs;
459
+ break;
460
+ }
461
+ this.updateTotalMetrics(promptTokens, completionTokens, reasoningTokens, cachedInputTokens, inferenceTimeMs);
462
+ }
463
+ updateTotalMetrics(promptTokens, completionTokens, reasoningTokens, cachedInputTokens, inferenceTimeMs) {
464
+ this.stagehandMetrics.totalPromptTokens += promptTokens;
465
+ this.stagehandMetrics.totalCompletionTokens += completionTokens;
466
+ this.stagehandMetrics.totalReasoningTokens += reasoningTokens;
467
+ this.stagehandMetrics.totalCachedInputTokens += cachedInputTokens;
468
+ this.stagehandMetrics.totalInferenceTimeMs += inferenceTimeMs;
469
+ }
470
+ async _immediateShutdown(reason) {
471
+ try {
472
+ this.logger({
473
+ category: "v3",
474
+ message: `initiating shutdown → ${reason}`,
475
+ level: 0,
476
+ });
477
+ }
478
+ catch {
479
+ //
480
+ }
481
+ try {
482
+ this.logger({
483
+ category: "v3",
484
+ message: `closing resources → ${reason}`,
485
+ level: 0,
486
+ });
487
+ await this.close({ force: true });
488
+ }
489
+ catch {
490
+ // swallow — already shutting down
491
+ }
492
+ }
493
+ /** Spawn a crash-only supervisor that cleans up when this process dies. */
494
+ startShutdownSupervisor(config) {
495
+ if (this.shutdownSupervisor)
496
+ return this.shutdownSupervisor;
497
+ this.shutdownSupervisor = startShutdownSupervisor(config, {
498
+ onError: (error, context) => {
499
+ try {
500
+ this.logger({
501
+ category: "v3",
502
+ message: "Shutdown supervisor unavailable; crash cleanup disabled. " +
503
+ "If this process exits unexpectedly, local Chrome or Browserbase " +
504
+ "sessions may remain running even with keepAlive=false.",
505
+ level: 0,
506
+ auxiliary: {
507
+ context: { value: context, type: "string" },
508
+ error: { value: error.message, type: "string" },
509
+ },
510
+ });
511
+ }
512
+ catch {
513
+ // ignore logging failures
514
+ }
515
+ },
516
+ });
517
+ return this.shutdownSupervisor;
518
+ }
519
+ /** Stop the supervisor during a normal shutdown. */
520
+ stopShutdownSupervisor() {
521
+ if (!this.shutdownSupervisor)
522
+ return;
523
+ try {
524
+ this.shutdownSupervisor.stop();
525
+ }
526
+ catch {
527
+ // best-effort
528
+ }
529
+ this.shutdownSupervisor = null;
530
+ }
531
+ /**
532
+ * Entrypoint: initializes handlers, launches Chrome or Browserbase,
533
+ * and sets up a CDP context.
534
+ */
535
+ async init() {
536
+ try {
537
+ return await withInstanceLogContext(this.instanceId, async () => {
538
+ this.actHandler = new ActHandler(this.llmClient, this.modelName, this.modelClientOptions, (model) => this.resolveLlmClient(model), this.opts.systemPrompt ?? "", this.logInferenceToFile, this.opts.selfHeal ?? true, (functionName, promptTokens, completionTokens, reasoningTokens, cachedInputTokens, inferenceTimeMs) => this.updateMetrics(functionName, promptTokens, completionTokens, reasoningTokens, cachedInputTokens, inferenceTimeMs), this.domSettleTimeoutMs);
539
+ this.extractHandler = new ExtractHandler(this.llmClient, this.modelName, this.modelClientOptions, (model) => this.resolveLlmClient(model), this.opts.systemPrompt ?? "", this.logInferenceToFile, this.experimental, (functionName, promptTokens, completionTokens, reasoningTokens, cachedInputTokens, inferenceTimeMs) => this.updateMetrics(functionName, promptTokens, completionTokens, reasoningTokens, cachedInputTokens, inferenceTimeMs));
540
+ this.observeHandler = new ObserveHandler(this.llmClient, this.modelName, this.modelClientOptions, (model) => this.resolveLlmClient(model), this.opts.systemPrompt ?? "", this.logInferenceToFile, this.experimental, (functionName, promptTokens, completionTokens, reasoningTokens, cachedInputTokens, inferenceTimeMs) => this.updateMetrics(functionName, promptTokens, completionTokens, reasoningTokens, cachedInputTokens, inferenceTimeMs));
541
+ if (this.opts.env === "LOCAL") {
542
+ // chrome-launcher conditionally adds --headless when the environment variable
543
+ // HEADLESS is set, without parsing its value.
544
+ // if it is not equal to true, then we delete it from the process
545
+ const envHeadless = process.env.HEADLESS;
546
+ if (envHeadless !== undefined) {
547
+ const normalized = envHeadless.trim().toLowerCase();
548
+ if (normalized !== "true") {
549
+ delete process.env.HEADLESS;
550
+ }
551
+ }
552
+ const lbo = this.opts.localBrowserLaunchOptions ?? {};
553
+ // If a CDP URL is provided, attach instead of launching.
554
+ if (lbo.cdpUrl) {
555
+ this.logger({
556
+ category: "init",
557
+ message: "Connecting to local browser",
558
+ level: 1,
559
+ });
560
+ this.ctx = await V3Context.create(lbo.cdpUrl, {
561
+ env: "LOCAL",
562
+ });
563
+ const logCtx = SessionFileLogger.getContext();
564
+ this.ctx.conn.cdpLogger = (info) => SessionFileLogger.logCdpCallEvent(info, logCtx);
565
+ this.ctx.conn.cdpEventLogger = (info) => SessionFileLogger.logCdpMessageEvent(info, logCtx);
566
+ this.ctx.conn.onTransportClosed(this._onCdpClosed);
567
+ this.state = {
568
+ kind: "LOCAL",
569
+ // no LaunchedChrome when attaching externally; create a stub kill
570
+ chrome: {
571
+ kill: async () => { },
572
+ },
573
+ ws: lbo.cdpUrl,
574
+ };
575
+ this.resetBrowserbaseSessionMetadata();
576
+ // Post-connect settings (downloads and viewport) if provided
577
+ await this._applyPostConnectLocalOptions(lbo);
578
+ return;
579
+ }
580
+ this.logger({
581
+ category: "init",
582
+ message: "Launching local browser",
583
+ level: 1,
584
+ });
585
+ // Determine or create user data dir
586
+ let userDataDir = lbo.userDataDir;
587
+ let createdTemp = false;
588
+ if (!userDataDir) {
589
+ const base = path.join(os.tmpdir(), "stagehand-v3");
590
+ fs.mkdirSync(base, { recursive: true });
591
+ userDataDir = fs.mkdtempSync(path.join(base, "profile-"));
592
+ createdTemp = true;
593
+ }
594
+ // Build chrome flags
595
+ const defaults = [
596
+ "--remote-allow-origins=*",
597
+ "--no-first-run",
598
+ "--no-default-browser-check",
599
+ "--disable-dev-shm-usage",
600
+ "--site-per-process",
601
+ ];
602
+ let chromeFlags = [];
603
+ const ignore = lbo.ignoreDefaultArgs;
604
+ if (ignore === true) {
605
+ // drop defaults
606
+ chromeFlags = [];
607
+ }
608
+ else if (Array.isArray(ignore)) {
609
+ chromeFlags = defaults.filter((f) => !ignore.some((ex) => f.includes(ex)));
610
+ }
611
+ else {
612
+ chromeFlags = [...defaults];
613
+ }
614
+ // headless handled by launchLocalChrome
615
+ if (lbo.devtools)
616
+ chromeFlags.push("--auto-open-devtools-for-tabs");
617
+ if (lbo.locale)
618
+ chromeFlags.push(`--lang=${lbo.locale}`);
619
+ if (!lbo.viewport) {
620
+ lbo.viewport = DEFAULT_VIEWPORT;
621
+ }
622
+ if (lbo.viewport?.width && lbo.viewport?.height) {
623
+ chromeFlags.push(`--window-size=${lbo.viewport.width},${lbo.viewport.height + 87}`);
624
+ }
625
+ if (typeof lbo.deviceScaleFactor === "number") {
626
+ chromeFlags.push(`--force-device-scale-factor=${Math.max(0.1, lbo.deviceScaleFactor)}`);
627
+ }
628
+ if (lbo.hasTouch)
629
+ chromeFlags.push("--touch-events=enabled");
630
+ if (lbo.ignoreHTTPSErrors)
631
+ chromeFlags.push("--ignore-certificate-errors");
632
+ if (lbo.proxy?.server)
633
+ chromeFlags.push(`--proxy-server=${lbo.proxy.server}`);
634
+ if (lbo.proxy?.bypass)
635
+ chromeFlags.push(`--proxy-bypass-list=${lbo.proxy.bypass}`);
636
+ // add user-supplied args last
637
+ if (Array.isArray(lbo.args))
638
+ chromeFlags.push(...lbo.args);
639
+ const keepAlive = this.keepAlive === true;
640
+ const { ws, chrome } = await launchLocalChrome({
641
+ chromePath: lbo.executablePath,
642
+ chromeFlags,
643
+ port: lbo.port,
644
+ headless: lbo.headless,
645
+ userDataDir,
646
+ connectTimeoutMs: lbo.connectTimeoutMs,
647
+ handleSIGINT: !keepAlive,
648
+ });
649
+ if (keepAlive) {
650
+ try {
651
+ chrome.process?.unref?.();
652
+ }
653
+ catch {
654
+ // best-effort: avoid keeping the event loop alive
655
+ }
656
+ }
657
+ this.ctx = await V3Context.create(ws, {
658
+ env: "LOCAL",
659
+ localBrowserLaunchOptions: lbo,
660
+ });
661
+ const logCtx = SessionFileLogger.getContext();
662
+ this.ctx.conn.cdpLogger = (info) => SessionFileLogger.logCdpCallEvent(info, logCtx);
663
+ this.ctx.conn.cdpEventLogger = (info) => SessionFileLogger.logCdpMessageEvent(info, logCtx);
664
+ this.ctx.conn.onTransportClosed(this._onCdpClosed);
665
+ this.state = {
666
+ kind: "LOCAL",
667
+ chrome,
668
+ ws,
669
+ userDataDir,
670
+ createdTempProfile: createdTemp,
671
+ preserveUserDataDir: !!lbo.preserveUserDataDir,
672
+ };
673
+ this.resetBrowserbaseSessionMetadata();
674
+ const chromePid = chrome.process?.pid ?? chrome.pid;
675
+ if (!keepAlive && chromePid) {
676
+ this.startShutdownSupervisor({
677
+ kind: "LOCAL",
678
+ pid: chromePid,
679
+ userDataDir,
680
+ createdTempProfile: createdTemp,
681
+ preserveUserDataDir: !!lbo.preserveUserDataDir,
682
+ });
683
+ }
684
+ // Post-connect settings (downloads and viewport) if provided
685
+ await this._applyPostConnectLocalOptions(lbo);
686
+ return;
687
+ }
688
+ if (this.opts.env === "BROWSERBASE") {
689
+ const { apiKey, projectId } = this.requireBrowserbaseCreds();
690
+ if (!apiKey || !projectId) {
691
+ throw new MissingEnvironmentVariableError("BROWSERBASE_API_KEY and BROWSERBASE_PROJECT_ID", "Browserbase environment");
692
+ }
693
+ this.logger({
694
+ category: "init",
695
+ message: "Starting browserbase session",
696
+ level: 1,
697
+ });
698
+ const baseSessionParams = this.opts.browserbaseSessionCreateParams ?? {};
699
+ const resolvedKeepAlive = this.keepAlive;
700
+ const keepAlive = this.keepAlive === true;
701
+ const effectiveSessionParams = resolvedKeepAlive !== undefined
702
+ ? { ...baseSessionParams, keepAlive: resolvedKeepAlive }
703
+ : baseSessionParams;
704
+ if (!this.disableAPI && !this.experimental) {
705
+ this.apiClient = new StagehandAPIClient({
706
+ apiKey,
707
+ projectId,
708
+ logger: this.logger,
709
+ });
710
+ const createSessionPayload = {
711
+ projectId: effectiveSessionParams.projectId ?? projectId,
712
+ ...effectiveSessionParams,
713
+ browserSettings: {
714
+ ...(effectiveSessionParams.browserSettings ?? {}),
715
+ viewport: effectiveSessionParams.browserSettings?.viewport ?? {
716
+ width: 1288,
717
+ height: 711,
718
+ },
719
+ },
720
+ userMetadata: {
721
+ ...(effectiveSessionParams.userMetadata ?? {}),
722
+ stagehand: "true",
723
+ },
724
+ };
725
+ const { sessionId, available } = await this.apiClient.init({
726
+ modelName: this.modelName,
727
+ modelApiKey: this.modelClientOptions.apiKey,
728
+ domSettleTimeoutMs: this.domSettleTimeoutMs,
729
+ verbose: this.verbose,
730
+ systemPrompt: this.opts.systemPrompt,
731
+ selfHeal: this.opts.selfHeal,
732
+ browserbaseSessionCreateParams: createSessionPayload,
733
+ browserbaseSessionID: this.opts.browserbaseSessionID,
734
+ });
735
+ if (!available) {
736
+ this.apiClient = null;
737
+ }
738
+ this.opts.browserbaseSessionID = sessionId;
739
+ }
740
+ const { ws, sessionId, bb } = await createBrowserbaseSession(apiKey, projectId, effectiveSessionParams, this.opts.browserbaseSessionID);
741
+ this.ctx = await V3Context.create(ws, {
742
+ env: "BROWSERBASE",
743
+ apiClient: this.apiClient,
744
+ });
745
+ const logCtx = SessionFileLogger.getContext();
746
+ this.ctx.conn.cdpLogger = (info) => SessionFileLogger.logCdpCallEvent(info, logCtx);
747
+ this.ctx.conn.cdpEventLogger = (info) => SessionFileLogger.logCdpMessageEvent(info, logCtx);
748
+ this.ctx.conn.onTransportClosed(this._onCdpClosed);
749
+ this.state = { kind: "BROWSERBASE", sessionId, ws, bb };
750
+ this.browserbaseSessionId = sessionId;
751
+ if (!keepAlive && !this.disableAPI) {
752
+ this.startShutdownSupervisor({
753
+ kind: "STAGEHAND_API",
754
+ sessionId,
755
+ apiKey,
756
+ projectId,
757
+ });
758
+ }
759
+ await this._ensureBrowserbaseDownloadsEnabled();
760
+ const resumed = !!this.opts.browserbaseSessionID;
761
+ let debugUrl;
762
+ try {
763
+ const dbg = (await bb.sessions.debug(sessionId));
764
+ debugUrl = dbg?.debuggerUrl;
765
+ }
766
+ catch {
767
+ // Ignore debug fetch failures; continue with sessionUrl only
768
+ }
769
+ const sessionUrl = `https://www.browserbase.com/sessions/${sessionId}`;
770
+ this.browserbaseSessionUrl = sessionUrl;
771
+ this.browserbaseDebugUrl = debugUrl;
772
+ try {
773
+ this.logger({
774
+ category: "init",
775
+ message: resumed
776
+ ? this.apiClient
777
+ ? "Browserbase session started"
778
+ : "Browserbase session resumed"
779
+ : "Browserbase session started",
780
+ level: 1,
781
+ auxiliary: {
782
+ sessionUrl: { value: sessionUrl, type: "string" },
783
+ ...(debugUrl && {
784
+ debugUrl: { value: debugUrl, type: "string" },
785
+ }),
786
+ sessionId: { value: sessionId, type: "string" },
787
+ },
788
+ });
789
+ }
790
+ catch {
791
+ // best-effort logging — ignore failures
792
+ }
793
+ return;
794
+ }
795
+ const neverEnv = this.opts.env;
796
+ throw new StagehandInitError(`Unsupported env: ${neverEnv}`);
797
+ });
798
+ }
799
+ catch (error) {
800
+ // Cleanup instanceLoggers map on init failure to prevent memory leak
801
+ if (this.externalLogger) {
802
+ try {
803
+ unbindInstanceLogger(this.instanceId);
804
+ }
805
+ catch {
806
+ // ignore cleanup errors
807
+ }
808
+ }
809
+ throw error;
810
+ }
811
+ }
812
+ /** Apply post-connect local browser options that require CDP. */
813
+ async _applyPostConnectLocalOptions(lbo) {
814
+ try {
815
+ // Downloads behavior
816
+ if (lbo.downloadsPath || lbo.acceptDownloads !== undefined) {
817
+ const behavior = lbo.acceptDownloads === false ? "deny" : "allow";
818
+ await this.ctx?.conn
819
+ .send("Browser.setDownloadBehavior", {
820
+ behavior,
821
+ downloadPath: lbo.downloadsPath,
822
+ eventsEnabled: true,
823
+ })
824
+ .catch(() => { });
825
+ }
826
+ }
827
+ catch {
828
+ // best-effort only
829
+ }
830
+ }
831
+ async _ensureBrowserbaseDownloadsEnabled() {
832
+ const conn = this.ctx?.conn;
833
+ if (!conn)
834
+ return;
835
+ try {
836
+ await conn.send("Browser.setDownloadBehavior", {
837
+ behavior: "allow",
838
+ downloadPath: "downloads",
839
+ eventsEnabled: true,
840
+ });
841
+ }
842
+ catch {
843
+ // best-effort only
844
+ }
845
+ }
846
+ resetBrowserbaseSessionMetadata() {
847
+ this.browserbaseSessionId = undefined;
848
+ this.browserbaseSessionUrl = undefined;
849
+ this.browserbaseDebugUrl = undefined;
850
+ }
851
+ async act(input, options) {
852
+ return await withInstanceLogContext(this.instanceId, async () => {
853
+ if (!this.actHandler)
854
+ throw new StagehandNotInitializedError("act()");
855
+ let actResult;
856
+ if (isObserveResult(input)) {
857
+ // Resolve page: use provided page if any, otherwise default active page
858
+ const v3Page = await this.resolvePage(options?.page);
859
+ // Use selector as provided to support XPath, CSS, and other engines
860
+ const selector = input.selector;
861
+ if (this.apiClient) {
862
+ actResult = await this.apiClient.act({
863
+ input,
864
+ options,
865
+ frameId: v3Page.mainFrameId(),
866
+ });
867
+ }
868
+ else {
869
+ const effectiveTimeoutMs = typeof options?.timeout === "number" && options.timeout > 0
870
+ ? options.timeout
871
+ : undefined;
872
+ const ensureTimeRemaining = createTimeoutGuard(effectiveTimeoutMs, (ms) => new ActTimeoutError(ms));
873
+ actResult = await this.actHandler.takeDeterministicAction({ ...input, selector }, v3Page, this.domSettleTimeoutMs, this.resolveLlmClient(options?.model), ensureTimeRemaining, options?.variables);
874
+ }
875
+ // history: record ObserveResult-based act call
876
+ this.addToHistory("act", {
877
+ observeResult: input,
878
+ }, actResult);
879
+ return actResult;
880
+ }
881
+ // instruction path
882
+ if (typeof input !== "string" || !input.trim()) {
883
+ throw new StagehandInvalidArgumentError("act(): instruction string is required unless passing an Action");
884
+ }
885
+ // Resolve page from options or default
886
+ const page = await this.resolvePage(options?.page);
887
+ const actCacheLlmClient = options?.model
888
+ ? this.resolveLlmClient(options.model)
889
+ : undefined;
890
+ let actCacheContext = null;
891
+ const canUseCache = typeof input === "string" &&
892
+ !this.isAgentReplayRecording() &&
893
+ this.actCache.enabled;
894
+ if (canUseCache) {
895
+ actCacheContext = await this.actCache.prepareContext(input, page, options?.variables);
896
+ if (actCacheContext) {
897
+ const cachedResult = await this.actCache.tryReplay(actCacheContext, page, options?.timeout, actCacheLlmClient);
898
+ if (cachedResult) {
899
+ this.addToHistory("act", {
900
+ instruction: input,
901
+ variables: options?.variables,
902
+ timeout: options?.timeout,
903
+ cacheHit: true,
904
+ }, cachedResult);
905
+ return cachedResult;
906
+ }
907
+ }
908
+ }
909
+ const handlerParams = {
910
+ instruction: input,
911
+ page,
912
+ variables: options?.variables,
913
+ timeout: options?.timeout,
914
+ model: options?.model,
915
+ };
916
+ if (this.apiClient) {
917
+ const frameId = page.mainFrameId();
918
+ actResult = await this.apiClient.act({ input, options, frameId });
919
+ }
920
+ else {
921
+ actResult = await this.actHandler.act(handlerParams);
922
+ }
923
+ // history: record instruction-based act call (omit page object)
924
+ this.addToHistory("act", {
925
+ instruction: input,
926
+ variables: options?.variables,
927
+ timeout: options?.timeout,
928
+ }, actResult);
929
+ if (actCacheContext &&
930
+ actResult.success &&
931
+ Array.isArray(actResult.actions) &&
932
+ actResult.actions.length > 0) {
933
+ await this.actCache.store(actCacheContext, actResult);
934
+ }
935
+ return actResult;
936
+ });
937
+ }
938
+ async extract(a, b, c) {
939
+ return await withInstanceLogContext(this.instanceId, async () => {
940
+ if (!this.extractHandler) {
941
+ throw new StagehandNotInitializedError("extract()");
942
+ }
943
+ // Normalize args
944
+ let instruction;
945
+ let schema;
946
+ let options;
947
+ if (typeof a === "string") {
948
+ instruction = a;
949
+ const isZodSchema = (val) => !!val &&
950
+ typeof val === "object" &&
951
+ "parse" in val &&
952
+ "safeParse" in val;
953
+ if (isZodSchema(b)) {
954
+ schema = b;
955
+ options = c;
956
+ }
957
+ else {
958
+ options = b;
959
+ }
960
+ }
961
+ else {
962
+ // a is options or undefined
963
+ options = a || undefined;
964
+ }
965
+ if (!instruction && schema) {
966
+ throw new StagehandInvalidArgumentError("extract(): schema provided without instruction");
967
+ }
968
+ // If instruction without schema → defaultExtractSchema
969
+ const effectiveSchema = instruction && !schema ? defaultExtractSchema : schema;
970
+ // Resolve page from options or use active page
971
+ const page = await this.resolvePage(options?.page);
972
+ const handlerParams = {
973
+ instruction,
974
+ schema: effectiveSchema,
975
+ model: options?.model,
976
+ timeout: options?.timeout,
977
+ selector: options?.selector,
978
+ page,
979
+ };
980
+ let result;
981
+ if (this.apiClient) {
982
+ const frameId = page.mainFrameId();
983
+ result = await this.apiClient.extract({
984
+ instruction: handlerParams.instruction,
985
+ schema: handlerParams.schema,
986
+ options,
987
+ frameId,
988
+ });
989
+ }
990
+ else {
991
+ result =
992
+ await this.extractHandler.extract(handlerParams);
993
+ }
994
+ const historySchemaDescriptor = effectiveSchema
995
+ ? toJsonSchema(effectiveSchema)
996
+ : undefined;
997
+ this.addToHistory("extract", {
998
+ instruction,
999
+ selector: options?.selector,
1000
+ timeout: options?.timeout,
1001
+ schema: historySchemaDescriptor,
1002
+ }, result);
1003
+ return result;
1004
+ });
1005
+ }
1006
+ async observe(a, b) {
1007
+ return await withInstanceLogContext(this.instanceId, async () => {
1008
+ if (!this.observeHandler) {
1009
+ throw new StagehandNotInitializedError("observe()");
1010
+ }
1011
+ // Normalize args
1012
+ let instruction;
1013
+ let options;
1014
+ if (typeof a === "string") {
1015
+ instruction = a;
1016
+ options = b;
1017
+ }
1018
+ else {
1019
+ options = a;
1020
+ }
1021
+ // Resolve to our internal Page type
1022
+ const page = await this.resolvePage(options?.page);
1023
+ const handlerParams = {
1024
+ instruction,
1025
+ model: options?.model,
1026
+ timeout: options?.timeout,
1027
+ selector: options?.selector,
1028
+ page: page,
1029
+ };
1030
+ let results;
1031
+ if (this.apiClient) {
1032
+ const frameId = page.mainFrameId();
1033
+ results = await this.apiClient.observe({
1034
+ instruction,
1035
+ options,
1036
+ frameId,
1037
+ });
1038
+ }
1039
+ else {
1040
+ results = await this.observeHandler.observe(handlerParams);
1041
+ }
1042
+ // history: record observe call (omit page object)
1043
+ this.addToHistory("observe", {
1044
+ instruction,
1045
+ timeout: options?.timeout,
1046
+ }, results);
1047
+ return results;
1048
+ });
1049
+ }
1050
+ /** Return the browser-level CDP WebSocket endpoint. */
1051
+ connectURL() {
1052
+ if (this.state.kind === "UNINITIALIZED") {
1053
+ throw new StagehandNotInitializedError("connectURL()");
1054
+ }
1055
+ return this.state.ws;
1056
+ }
1057
+ /** Expose the current CDP-backed context. */
1058
+ get context() {
1059
+ return this.ctx;
1060
+ }
1061
+ /** Best-effort cleanup of context and launched resources. */
1062
+ async close(opts) {
1063
+ // If we're already closing and this isn't a forced close, no-op.
1064
+ if (this._isClosing && !opts?.force)
1065
+ return;
1066
+ this._isClosing = true;
1067
+ const keepAlive = this.keepAlive === true;
1068
+ // End Browserbase session via API when keepAlive is not enabled
1069
+ if (!keepAlive && this.apiClient) {
1070
+ try {
1071
+ await this.apiClient.end();
1072
+ }
1073
+ catch {
1074
+ // best-effort cleanup
1075
+ }
1076
+ }
1077
+ try {
1078
+ // Close session file logger
1079
+ try {
1080
+ await SessionFileLogger.close();
1081
+ }
1082
+ catch {
1083
+ // ignore
1084
+ }
1085
+ // Unhook CDP transport close handler
1086
+ try {
1087
+ if (this.ctx?.conn && this._onCdpClosed) {
1088
+ this.ctx.conn.offTransportClosed?.(this._onCdpClosed);
1089
+ }
1090
+ }
1091
+ catch {
1092
+ // ignore
1093
+ }
1094
+ // Close CDP context
1095
+ try {
1096
+ await this.ctx?.close();
1097
+ }
1098
+ catch {
1099
+ // ignore
1100
+ }
1101
+ // Kill local Chrome and clean up temp profile when keepAlive is not enabled
1102
+ if (!keepAlive && this.state.kind === "LOCAL") {
1103
+ const localState = this.state;
1104
+ await cleanupLocalBrowser({
1105
+ killChrome: () => localState.chrome.kill(),
1106
+ userDataDir: localState.userDataDir,
1107
+ createdTempProfile: localState.createdTempProfile,
1108
+ preserveUserDataDir: localState.preserveUserDataDir,
1109
+ });
1110
+ }
1111
+ }
1112
+ finally {
1113
+ this.stopShutdownSupervisor();
1114
+ // Reset internal state
1115
+ this.state = { kind: "UNINITIALIZED" };
1116
+ this.ctx = null;
1117
+ this._isClosing = false;
1118
+ this.resetBrowserbaseSessionMetadata();
1119
+ try {
1120
+ unbindInstanceLogger(this.instanceId);
1121
+ }
1122
+ catch {
1123
+ // ignore
1124
+ }
1125
+ try {
1126
+ this.bus.removeAllListeners();
1127
+ }
1128
+ catch {
1129
+ // ignore
1130
+ }
1131
+ this._history = [];
1132
+ this.actHandler = null;
1133
+ this.extractHandler = null;
1134
+ this.observeHandler = null;
1135
+ V3._instances.delete(this);
1136
+ }
1137
+ }
1138
+ /** Guard: ensure Browserbase credentials exist in options. */
1139
+ requireBrowserbaseCreds() {
1140
+ let { apiKey, projectId } = this.opts;
1141
+ // Fall back to environment variables if not explicitly provided
1142
+ if (!apiKey)
1143
+ apiKey = process.env.BROWSERBASE_API_KEY ?? process.env.BB_API_KEY;
1144
+ if (!projectId)
1145
+ projectId =
1146
+ process.env.BROWSERBASE_PROJECT_ID ?? process.env.BB_PROJECT_ID;
1147
+ if (!apiKey || !projectId) {
1148
+ const missing = [];
1149
+ if (!apiKey)
1150
+ missing.push("BROWSERBASE_API_KEY");
1151
+ if (!projectId)
1152
+ missing.push("BROWSERBASE_PROJECT_ID");
1153
+ throw new MissingEnvironmentVariableError(missing.join(", "), "Browserbase");
1154
+ }
1155
+ // Cache resolved values back into opts for consistency
1156
+ this.opts.apiKey = apiKey;
1157
+ this.opts.projectId = projectId;
1158
+ // Informational log
1159
+ this.logger({
1160
+ category: "init",
1161
+ message: "Using Browserbase credentials",
1162
+ level: 1,
1163
+ });
1164
+ return { apiKey, projectId };
1165
+ }
1166
+ get logger() {
1167
+ // Delegate to per-instance StagehandLogger
1168
+ // StagehandLogger handles: verbosity filtering, usePino selection, external logger routing
1169
+ // This provides per-instance configuration while maintaining shared Pino optimization
1170
+ return (logLine) => {
1171
+ const line = { ...logLine, level: logLine.level ?? 1 };
1172
+ this.stagehandLogger.log(line);
1173
+ };
1174
+ }
1175
+ /**
1176
+ * Normalize a Playwright/Puppeteer page object into its top frame id,
1177
+ * so handlers can resolve it to a `Page` within our V3Context.
1178
+ */
1179
+ async resolveTopFrameId(page) {
1180
+ if (this.isPlaywrightPage(page)) {
1181
+ const cdp = await page.context().newCDPSession(page);
1182
+ const { frameTree } = await cdp.send("Page.getFrameTree");
1183
+ return frameTree.frame.id;
1184
+ }
1185
+ if (this.isPatchrightPage(page)) {
1186
+ const cdp = await page.context().newCDPSession(page);
1187
+ const { frameTree } = await cdp.send("Page.getFrameTree");
1188
+ return frameTree.frame.id;
1189
+ }
1190
+ if (this.isPuppeteerPage(page)) {
1191
+ const cdp = await page.createCDPSession();
1192
+ const { frameTree } = await cdp.send("Page.getFrameTree");
1193
+ this.logger({
1194
+ category: "v3",
1195
+ message: "Puppeteer frame id",
1196
+ level: 2,
1197
+ auxiliary: { frameId: { value: frameTree.frame.id, type: "string" } },
1198
+ });
1199
+ return frameTree.frame.id;
1200
+ }
1201
+ throw new StagehandInvalidArgumentError("Unsupported page object passed to V3.act()");
1202
+ }
1203
+ isPlaywrightPage(p) {
1204
+ return (typeof p === "object" &&
1205
+ p !== null &&
1206
+ typeof p.context === "function");
1207
+ }
1208
+ isPatchrightPage(p) {
1209
+ return (typeof p === "object" &&
1210
+ p !== null &&
1211
+ typeof p.context === "function");
1212
+ }
1213
+ isPuppeteerPage(p) {
1214
+ return (typeof p === "object" &&
1215
+ p !== null &&
1216
+ typeof p.target === "function");
1217
+ }
1218
+ /** Resolve an external page reference or fall back to the active V3 page. */
1219
+ async resolvePage(page) {
1220
+ if (page) {
1221
+ return await this.normalizeToV3Page(page);
1222
+ }
1223
+ const ctx = this.ctx;
1224
+ if (!ctx) {
1225
+ throw new StagehandNotInitializedError("resolvePage()");
1226
+ }
1227
+ return await ctx.awaitActivePage();
1228
+ }
1229
+ async normalizeToV3Page(input) {
1230
+ if (input instanceof (await import("./understudy/page.js")).Page) {
1231
+ return input;
1232
+ }
1233
+ if (this.isPlaywrightPage(input)) {
1234
+ const frameId = await this.resolveTopFrameId(input);
1235
+ const page = this.ctx.resolvePageByMainFrameId(frameId);
1236
+ if (!page)
1237
+ throw new StagehandInitError("Failed to resolve V3 Page from Playwright page.");
1238
+ return page;
1239
+ }
1240
+ if (this.isPatchrightPage(input)) {
1241
+ const frameId = await this.resolveTopFrameId(input);
1242
+ const page = this.ctx.resolvePageByMainFrameId(frameId);
1243
+ if (!page)
1244
+ throw new StagehandInitError("Failed to resolve V3 Page from Patchright page.");
1245
+ return page;
1246
+ }
1247
+ if (this.isPuppeteerPage(input)) {
1248
+ const frameId = await this.resolveTopFrameId(input);
1249
+ const page = this.ctx.resolvePageByMainFrameId(frameId);
1250
+ if (!page)
1251
+ throw new StagehandInitError("Failed to resolve V3 Page from Puppeteer page.");
1252
+ return page;
1253
+ }
1254
+ throw new StagehandInvalidArgumentError("Unsupported page object.");
1255
+ }
1256
+ async _logBrowserbaseSessionStatus() {
1257
+ if (this.state.kind !== "BROWSERBASE") {
1258
+ return;
1259
+ }
1260
+ try {
1261
+ const snapshot = (await this.state.bb.sessions.retrieve(this.state.sessionId));
1262
+ if (!snapshot?.status)
1263
+ return;
1264
+ const sessionId = snapshot.id ?? this.state.sessionId;
1265
+ const message = snapshot.status === "TIMED_OUT"
1266
+ ? `Browserbase session timed out (sessionId: ${sessionId})`
1267
+ : `Browserbase session status: ${snapshot.status}`;
1268
+ this.logger({
1269
+ category: "v3",
1270
+ message,
1271
+ level: 0,
1272
+ });
1273
+ }
1274
+ catch {
1275
+ // Ignore failures; nothing to log
1276
+ }
1277
+ }
1278
+ /**
1279
+ * Prepares shared context for agent execution (both execute and stream).
1280
+ * Extracts duplicated setup logic into a single helper.
1281
+ */
1282
+ async prepareAgentExecution(options, instructionOrOptions, agentConfigSignature) {
1283
+ // Note: experimental validation is done at the call site before this method
1284
+ // Warn if mode is not explicitly set (defaults to "dom")
1285
+ if (options?.mode === undefined) {
1286
+ this.logger({
1287
+ category: "agent",
1288
+ message: "Using agent in default DOM mode (legacy). Agent will default to 'hybrid' on an upcoming release for improved performance.\n → https://docs.stagehand.dev/v3/basics/agent\n",
1289
+ level: 0,
1290
+ });
1291
+ }
1292
+ const tools = options?.integrations
1293
+ ? await resolveTools(options.integrations, options.tools)
1294
+ : (options?.tools ?? {});
1295
+ const agentLlmClient = options?.model
1296
+ ? this.resolveLlmClient(options.model)
1297
+ : this.llmClient;
1298
+ const handler = new V3AgentHandler(this, this.logger, agentLlmClient, typeof options?.executionModel === "string"
1299
+ ? options.executionModel
1300
+ : options?.executionModel?.modelName, options?.systemPrompt, tools, options?.mode);
1301
+ const resolvedOptions = typeof instructionOrOptions === "string"
1302
+ ? { instruction: instructionOrOptions }
1303
+ : instructionOrOptions;
1304
+ const callbacksWithSafety = resolvedOptions.callbacks;
1305
+ if (callbacksWithSafety?.onSafetyConfirmation) {
1306
+ throw new StagehandInvalidArgumentError('onSafetyConfirmation callback is only supported when using mode: "cua" agents.');
1307
+ }
1308
+ if (resolvedOptions.page) {
1309
+ const normalizedPage = await this.normalizeToV3Page(resolvedOptions.page);
1310
+ this.ctx.setActivePage(normalizedPage);
1311
+ }
1312
+ const instruction = resolvedOptions.instruction.trim();
1313
+ const sanitizedOptions = this.agentCache.sanitizeExecuteOptions(resolvedOptions);
1314
+ const cacheContext = this.agentCache.shouldAttemptCache(instruction)
1315
+ ? await this.agentCache.prepareContext({
1316
+ instruction,
1317
+ options: sanitizedOptions,
1318
+ configSignature: agentConfigSignature,
1319
+ page: await this.ctx.awaitActivePage(),
1320
+ })
1321
+ : null;
1322
+ return {
1323
+ handler,
1324
+ resolvedOptions,
1325
+ instruction,
1326
+ cacheContext,
1327
+ llmClient: agentLlmClient,
1328
+ };
1329
+ }
1330
+ agent(options) {
1331
+ // Determine if CUA mode is enabled (via mode: "cua" or deprecated cua: true)
1332
+ const isCuaMode = options?.mode !== undefined
1333
+ ? options.mode === "cua"
1334
+ : options?.cua === true;
1335
+ // Emit deprecation warning for cua: true
1336
+ if (options?.cua === true) {
1337
+ this.logger({
1338
+ category: "agent",
1339
+ message: '[DEPRECATED] The "cua: true" option is deprecated. Use "mode: \'cua\'" instead. This option will be removed in a future version.',
1340
+ level: 0,
1341
+ });
1342
+ console.warn('[Stagehand] DEPRECATED: The "cua: true" option is deprecated. Use "mode: \'cua\'" instead.');
1343
+ }
1344
+ this.logger({
1345
+ category: "agent",
1346
+ message: "Creating v3 agent instance",
1347
+ level: 1,
1348
+ auxiliary: {
1349
+ cua: { value: isCuaMode ? "true" : "false", type: "boolean" },
1350
+ mode: { value: options?.mode ?? "dom", type: "string" },
1351
+ model: options?.model
1352
+ ? typeof options?.model === "string"
1353
+ ? { value: options.model, type: "string" }
1354
+ : { value: options.model.modelName, type: "string" }
1355
+ : { value: this.llmClient.modelName, type: "string" },
1356
+ systemPrompt: { value: options?.systemPrompt ?? "", type: "string" },
1357
+ tools: { value: JSON.stringify(options?.tools ?? {}), type: "object" },
1358
+ ...(options?.integrations && {
1359
+ integrations: {
1360
+ value: JSON.stringify(options.integrations),
1361
+ type: "object",
1362
+ },
1363
+ }),
1364
+ },
1365
+ });
1366
+ // If CUA mode is enabled (via mode: "cua" or deprecated cua: true), use the computer-use agent path
1367
+ if (isCuaMode) {
1368
+ // Validate agent config at creation time (includes CUA+streaming conflict check)
1369
+ validateExperimentalFeatures({
1370
+ isExperimental: this.experimental,
1371
+ agentConfig: options,
1372
+ });
1373
+ const modelToUse = options?.model || {
1374
+ modelName: this.modelName,
1375
+ ...this.modelClientOptions,
1376
+ };
1377
+ const { modelName, isCua, clientOptions } = resolveModel(modelToUse);
1378
+ if (!isCua) {
1379
+ throw new CuaModelRequiredError(AVAILABLE_CUA_MODELS);
1380
+ }
1381
+ const agentConfigSignature = this.agentCache.buildConfigSignature(options);
1382
+ return {
1383
+ execute: async (instructionOrOptions) => withInstanceLogContext(this.instanceId, async () => {
1384
+ validateExperimentalFeatures({
1385
+ isExperimental: this.experimental,
1386
+ agentConfig: options,
1387
+ executeOptions: typeof instructionOrOptions === "object"
1388
+ ? instructionOrOptions
1389
+ : null,
1390
+ });
1391
+ SessionFileLogger.logAgentTaskStarted({
1392
+ invocation: "Agent.execute",
1393
+ args: [instructionOrOptions],
1394
+ });
1395
+ const tools = options?.integrations
1396
+ ? await resolveTools(options.integrations, options.tools)
1397
+ : (options?.tools ?? {});
1398
+ const handler = new V3CuaAgentHandler(this, this.logger, {
1399
+ modelName,
1400
+ clientOptions,
1401
+ userProvidedInstructions: options.systemPrompt ??
1402
+ `You are a helpful assistant that can use a web browser.\nDo not ask follow up questions, the user will trust your judgement.`,
1403
+ }, tools);
1404
+ const resolvedOptions = typeof instructionOrOptions === "string"
1405
+ ? { instruction: instructionOrOptions }
1406
+ : instructionOrOptions;
1407
+ if (resolvedOptions.page) {
1408
+ const normalizedPage = await this.normalizeToV3Page(resolvedOptions.page);
1409
+ this.ctx.setActivePage(normalizedPage);
1410
+ }
1411
+ const instruction = resolvedOptions.instruction.trim();
1412
+ const sanitizedOptions = this.agentCache.sanitizeExecuteOptions(resolvedOptions);
1413
+ let cacheContext = null;
1414
+ if (this.agentCache.shouldAttemptCache(instruction)) {
1415
+ const startPage = await this.ctx.awaitActivePage();
1416
+ cacheContext = await this.agentCache.prepareContext({
1417
+ instruction,
1418
+ options: sanitizedOptions,
1419
+ configSignature: agentConfigSignature,
1420
+ page: startPage,
1421
+ });
1422
+ if (cacheContext) {
1423
+ const replayed = await this.agentCache.tryReplay(cacheContext);
1424
+ if (replayed) {
1425
+ SessionFileLogger.logAgentTaskCompleted({ cacheHit: true });
1426
+ return replayed;
1427
+ }
1428
+ }
1429
+ }
1430
+ let agentSteps = [];
1431
+ const shouldRecordLocally = !!cacheContext && (!this.apiClient || this.experimental);
1432
+ if (shouldRecordLocally) {
1433
+ this.beginAgentReplayRecording();
1434
+ }
1435
+ let result;
1436
+ try {
1437
+ if (this.apiClient && !this.experimental) {
1438
+ const page = await this.ctx.awaitActivePage();
1439
+ result = await this.apiClient.agentExecute(options, resolvedOptions, page.mainFrameId(), !!cacheContext);
1440
+ if (cacheContext) {
1441
+ const transferredEntry = this.apiClient.consumeLatestAgentCacheEntry();
1442
+ await this.agentCache.storeTransferredEntry(transferredEntry);
1443
+ }
1444
+ }
1445
+ else {
1446
+ result = await handler.execute(instructionOrOptions);
1447
+ }
1448
+ if (shouldRecordLocally) {
1449
+ agentSteps = this.endAgentReplayRecording();
1450
+ }
1451
+ if (shouldRecordLocally &&
1452
+ cacheContext &&
1453
+ result.success &&
1454
+ agentSteps.length > 0) {
1455
+ await this.agentCache.store(cacheContext, agentSteps, result);
1456
+ }
1457
+ return result;
1458
+ }
1459
+ catch (err) {
1460
+ if (shouldRecordLocally)
1461
+ this.discardAgentReplayRecording();
1462
+ throw err;
1463
+ }
1464
+ finally {
1465
+ if (shouldRecordLocally) {
1466
+ this.discardAgentReplayRecording();
1467
+ }
1468
+ SessionFileLogger.logAgentTaskCompleted();
1469
+ }
1470
+ }),
1471
+ };
1472
+ }
1473
+ // Default: AISDK tools-based agent
1474
+ const agentConfigSignature = this.agentCache.buildConfigSignature(options);
1475
+ const isStreaming = options?.stream ?? false;
1476
+ return {
1477
+ execute: async (instructionOrOptions) => withInstanceLogContext(this.instanceId, async () => {
1478
+ validateExperimentalFeatures({
1479
+ isExperimental: this.experimental,
1480
+ agentConfig: options,
1481
+ executeOptions: typeof instructionOrOptions === "object"
1482
+ ? instructionOrOptions
1483
+ : null,
1484
+ isStreaming,
1485
+ });
1486
+ SessionFileLogger.logAgentTaskStarted({
1487
+ invocation: "Agent.execute",
1488
+ args: [instructionOrOptions],
1489
+ });
1490
+ // Streaming mode
1491
+ if (isStreaming) {
1492
+ const { handler, resolvedOptions, cacheContext, llmClient } = await this.prepareAgentExecution(options, instructionOrOptions, agentConfigSignature);
1493
+ if (cacheContext) {
1494
+ const replayed = await this.agentCache.tryReplayAsStream(cacheContext, llmClient);
1495
+ if (replayed) {
1496
+ SessionFileLogger.logAgentTaskCompleted({ cacheHit: true });
1497
+ return replayed;
1498
+ }
1499
+ }
1500
+ const streamResult = await handler.stream(resolvedOptions);
1501
+ if (cacheContext) {
1502
+ const wrappedStream = this.agentCache.wrapStreamForCaching(cacheContext, streamResult, () => this.beginAgentReplayRecording(), () => this.endAgentReplayRecording(), () => this.discardAgentReplayRecording());
1503
+ // Log completion when stream is returned (stream completes asynchronously)
1504
+ SessionFileLogger.logAgentTaskCompleted();
1505
+ return wrappedStream;
1506
+ }
1507
+ // Log completion when stream is returned (stream completes asynchronously)
1508
+ SessionFileLogger.logAgentTaskCompleted();
1509
+ return streamResult;
1510
+ }
1511
+ // Non-streaming mode (default)
1512
+ const { handler, resolvedOptions, cacheContext, llmClient } = await this.prepareAgentExecution(options, instructionOrOptions, agentConfigSignature);
1513
+ if (cacheContext) {
1514
+ const replayed = await this.agentCache.tryReplay(cacheContext, llmClient);
1515
+ if (replayed) {
1516
+ SessionFileLogger.logAgentTaskCompleted({ cacheHit: true });
1517
+ return replayed;
1518
+ }
1519
+ }
1520
+ let agentSteps = [];
1521
+ const shouldRecordLocally = !!cacheContext && (!this.apiClient || this.experimental);
1522
+ if (shouldRecordLocally) {
1523
+ this.beginAgentReplayRecording();
1524
+ }
1525
+ let result;
1526
+ try {
1527
+ if (this.apiClient && !this.experimental) {
1528
+ const page = await this.ctx.awaitActivePage();
1529
+ result = await this.apiClient.agentExecute(options ?? {}, resolvedOptions, page.mainFrameId(), !!cacheContext);
1530
+ if (cacheContext) {
1531
+ const transferredEntry = this.apiClient.consumeLatestAgentCacheEntry();
1532
+ await this.agentCache.storeTransferredEntry(transferredEntry);
1533
+ }
1534
+ }
1535
+ else {
1536
+ result = await handler.execute(resolvedOptions);
1537
+ }
1538
+ if (shouldRecordLocally) {
1539
+ agentSteps = this.endAgentReplayRecording();
1540
+ }
1541
+ if (shouldRecordLocally &&
1542
+ cacheContext &&
1543
+ result.success &&
1544
+ agentSteps.length > 0) {
1545
+ await this.agentCache.store(cacheContext, agentSteps, result);
1546
+ }
1547
+ return result;
1548
+ }
1549
+ catch (err) {
1550
+ if (shouldRecordLocally)
1551
+ this.discardAgentReplayRecording();
1552
+ throw err;
1553
+ }
1554
+ finally {
1555
+ if (shouldRecordLocally) {
1556
+ this.discardAgentReplayRecording();
1557
+ }
1558
+ SessionFileLogger.logAgentTaskCompleted();
1559
+ }
1560
+ }),
1561
+ };
1562
+ }
1563
+ };
1564
+ })();
1565
+ export { V3 };
1566
+ function isObserveResult(v) {
1567
+ return (!!v && typeof v === "object" && "selector" in v);
1568
+ }
1569
+ //# sourceMappingURL=v3.js.map