@browserbasehq/orca 3.4.0-preview.0 → 3.5.0-preview.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 (919) hide show
  1. package/dist/cjs/lib/inference.d.ts +2 -1
  2. package/dist/cjs/lib/inference.js +10 -3
  3. package/dist/cjs/lib/inference.js.map +1 -1
  4. package/dist/cjs/lib/prompt.d.ts +2 -2
  5. package/dist/cjs/lib/prompt.js +19 -4
  6. package/dist/cjs/lib/prompt.js.map +1 -1
  7. package/dist/cjs/lib/v3/agent/AgentProvider.d.ts +1 -1
  8. package/dist/cjs/lib/v3/agent/AgentProvider.js.map +1 -1
  9. package/dist/cjs/lib/v3/agent/AnthropicCUAClient.js +10 -0
  10. package/dist/cjs/lib/v3/agent/AnthropicCUAClient.js.map +1 -1
  11. package/dist/cjs/lib/v3/agent/utils/captureAriaTreeProbe.d.ts +35 -0
  12. package/dist/cjs/lib/v3/agent/utils/captureAriaTreeProbe.js +38 -0
  13. package/dist/cjs/lib/v3/agent/utils/captureAriaTreeProbe.js.map +1 -0
  14. package/dist/cjs/lib/v3/agent/utils/postStepProbeEvidence.d.ts +19 -0
  15. package/dist/cjs/lib/v3/agent/utils/postStepProbeEvidence.js +54 -0
  16. package/dist/cjs/lib/v3/agent/utils/postStepProbeEvidence.js.map +1 -0
  17. package/dist/cjs/lib/v3/agent/utils/toolOutputEvidence.d.ts +2 -0
  18. package/dist/cjs/lib/v3/agent/utils/toolOutputEvidence.js +62 -0
  19. package/dist/cjs/lib/v3/agent/utils/toolOutputEvidence.js.map +1 -0
  20. package/dist/cjs/lib/v3/agent/utils/wrapEvidenceCallback.d.ts +3 -0
  21. package/dist/cjs/lib/v3/agent/utils/wrapEvidenceCallback.js +25 -0
  22. package/dist/cjs/lib/v3/agent/utils/wrapEvidenceCallback.js.map +1 -0
  23. package/dist/cjs/lib/v3/api.d.ts +7 -1
  24. package/dist/cjs/lib/v3/api.js +100 -29
  25. package/dist/cjs/lib/v3/api.js.map +1 -1
  26. package/dist/cjs/lib/v3/dom/build/selectorRuntime.generated.d.ts +24 -0
  27. package/dist/cjs/lib/v3/dom/build/selectorRuntime.generated.js +31 -0
  28. package/dist/cjs/lib/v3/dom/build/selectorRuntime.generated.js.map +1 -0
  29. package/dist/cjs/lib/v3/handlers/extractHandler.js +19 -2
  30. package/dist/cjs/lib/v3/handlers/extractHandler.js.map +1 -1
  31. package/dist/cjs/lib/v3/handlers/observeHandler.js +2 -1
  32. package/dist/cjs/lib/v3/handlers/observeHandler.js.map +1 -1
  33. package/dist/cjs/lib/v3/handlers/v3AgentHandler.d.ts +1 -0
  34. package/dist/cjs/lib/v3/handlers/v3AgentHandler.js +83 -7
  35. package/dist/cjs/lib/v3/handlers/v3AgentHandler.js.map +1 -1
  36. package/dist/cjs/lib/v3/handlers/v3CuaAgentHandler.d.ts +11 -0
  37. package/dist/cjs/lib/v3/handlers/v3CuaAgentHandler.js +120 -5
  38. package/dist/cjs/lib/v3/handlers/v3CuaAgentHandler.js.map +1 -1
  39. package/dist/cjs/lib/v3/index.d.ts +12 -0
  40. package/dist/cjs/lib/v3/index.js +19 -1
  41. package/dist/cjs/lib/v3/index.js.map +1 -1
  42. package/dist/cjs/lib/v3/launch/local.d.ts +2 -7
  43. package/dist/cjs/lib/v3/launch/local.js +47 -7
  44. package/dist/cjs/lib/v3/launch/local.js.map +1 -1
  45. package/dist/cjs/lib/v3/llm/LLMProvider.d.ts +3 -0
  46. package/dist/cjs/lib/v3/llm/LLMProvider.js +28 -8
  47. package/dist/cjs/lib/v3/llm/LLMProvider.js.map +1 -1
  48. package/dist/cjs/lib/v3/llm/aisdk.js +5 -0
  49. package/dist/cjs/lib/v3/llm/aisdk.js.map +1 -1
  50. package/dist/cjs/lib/v3/types/private/handlers.d.ts +2 -0
  51. package/dist/cjs/lib/v3/types/private/handlers.js.map +1 -1
  52. package/dist/cjs/lib/v3/types/private/snapshot.d.ts +2 -0
  53. package/dist/cjs/lib/v3/types/private/snapshot.js.map +1 -1
  54. package/dist/cjs/lib/v3/types/public/agent.d.ts +7 -1
  55. package/dist/cjs/lib/v3/types/public/agent.js.map +1 -1
  56. package/dist/cjs/lib/v3/types/public/agentEvidenceEvents.d.ts +85 -0
  57. package/dist/cjs/lib/v3/types/public/agentEvidenceEvents.js +15 -0
  58. package/dist/cjs/lib/v3/types/public/agentEvidenceEvents.js.map +1 -0
  59. package/dist/cjs/lib/v3/types/public/api.d.ts +584 -65
  60. package/dist/cjs/lib/v3/types/public/api.js +107 -7
  61. package/dist/cjs/lib/v3/types/public/api.js.map +1 -1
  62. package/dist/cjs/lib/v3/types/public/index.d.ts +1 -0
  63. package/dist/cjs/lib/v3/types/public/index.js +1 -0
  64. package/dist/cjs/lib/v3/types/public/index.js.map +1 -1
  65. package/dist/cjs/lib/v3/types/public/methods.d.ts +2 -0
  66. package/dist/cjs/lib/v3/types/public/methods.js.map +1 -1
  67. package/dist/cjs/lib/v3/types/public/model.d.ts +23 -10
  68. package/dist/cjs/lib/v3/types/public/model.js.map +1 -1
  69. package/dist/cjs/lib/v3/understudy/a11y/snapshot/a11yTree.js +25 -0
  70. package/dist/cjs/lib/v3/understudy/a11y/snapshot/a11yTree.js.map +1 -1
  71. package/dist/cjs/lib/v3/understudy/a11y/snapshot/treeFormatUtils.js +10 -1
  72. package/dist/cjs/lib/v3/understudy/a11y/snapshot/treeFormatUtils.js.map +1 -1
  73. package/dist/cjs/lib/v3/v3.d.ts +1 -0
  74. package/dist/cjs/lib/v3/v3.js +21 -47
  75. package/dist/cjs/lib/v3/v3.js.map +1 -1
  76. package/dist/cjs/lib/v3/verifier/evidenceNormalization.d.ts +7 -0
  77. package/dist/cjs/lib/v3/verifier/evidenceNormalization.js +100 -0
  78. package/dist/cjs/lib/v3/verifier/evidenceNormalization.js.map +1 -0
  79. package/dist/cjs/lib/v3/verifier/index.d.ts +6 -0
  80. package/dist/cjs/lib/v3/verifier/index.js +16 -0
  81. package/dist/cjs/lib/v3/verifier/index.js.map +1 -0
  82. package/dist/cjs/lib/v3/verifier/trajectory.d.ts +50 -0
  83. package/dist/cjs/lib/v3/verifier/trajectory.js +316 -0
  84. package/dist/cjs/lib/v3/verifier/trajectory.js.map +1 -0
  85. package/dist/cjs/lib/v3/verifier/types.d.ts +281 -0
  86. package/dist/cjs/lib/v3/verifier/types.js +10 -0
  87. package/dist/cjs/lib/v3/verifier/types.js.map +1 -0
  88. package/dist/cjs/lib/v3Evaluator.d.ts +29 -16
  89. package/dist/cjs/lib/v3Evaluator.js +184 -194
  90. package/dist/cjs/lib/v3Evaluator.js.map +1 -1
  91. package/dist/cjs/lib/v3LegacyEvaluator.d.ts +20 -0
  92. package/dist/cjs/lib/v3LegacyEvaluator.js +219 -0
  93. package/dist/cjs/lib/v3LegacyEvaluator.js.map +1 -0
  94. package/dist/cjs/lib/version.d.ts +1 -1
  95. package/dist/cjs/lib/version.js +1 -1
  96. package/dist/cjs/lib/version.js.map +1 -1
  97. package/dist/esm/lib/inference.d.ts +2 -1
  98. package/dist/esm/lib/inference.js +10 -3
  99. package/dist/esm/lib/inference.js.map +1 -1
  100. package/dist/esm/lib/prompt.d.ts +2 -2
  101. package/dist/esm/lib/prompt.js +19 -4
  102. package/dist/esm/lib/prompt.js.map +1 -1
  103. package/dist/esm/lib/v3/agent/AgentProvider.d.ts +1 -1
  104. package/dist/esm/lib/v3/agent/AgentProvider.js.map +1 -1
  105. package/dist/esm/lib/v3/agent/AnthropicCUAClient.js +10 -0
  106. package/dist/esm/lib/v3/agent/AnthropicCUAClient.js.map +1 -1
  107. package/dist/esm/lib/v3/agent/utils/captureAriaTreeProbe.d.ts +35 -0
  108. package/dist/esm/lib/v3/agent/utils/captureAriaTreeProbe.js +35 -0
  109. package/dist/esm/lib/v3/agent/utils/captureAriaTreeProbe.js.map +1 -0
  110. package/dist/esm/lib/v3/agent/utils/postStepProbeEvidence.d.ts +19 -0
  111. package/dist/esm/lib/v3/agent/utils/postStepProbeEvidence.js +50 -0
  112. package/dist/esm/lib/v3/agent/utils/postStepProbeEvidence.js.map +1 -0
  113. package/dist/esm/lib/v3/agent/utils/toolOutputEvidence.d.ts +2 -0
  114. package/dist/esm/lib/v3/agent/utils/toolOutputEvidence.js +59 -0
  115. package/dist/esm/lib/v3/agent/utils/toolOutputEvidence.js.map +1 -0
  116. package/dist/esm/lib/v3/agent/utils/wrapEvidenceCallback.d.ts +3 -0
  117. package/dist/esm/lib/v3/agent/utils/wrapEvidenceCallback.js +22 -0
  118. package/dist/esm/lib/v3/agent/utils/wrapEvidenceCallback.js.map +1 -0
  119. package/dist/esm/lib/v3/api.d.ts +7 -1
  120. package/dist/esm/lib/v3/api.js +100 -29
  121. package/dist/esm/lib/v3/api.js.map +1 -1
  122. package/dist/esm/lib/v3/dom/build/selectorRuntime.generated.d.ts +24 -0
  123. package/dist/esm/lib/v3/dom/build/selectorRuntime.generated.js +28 -0
  124. package/dist/esm/lib/v3/dom/build/selectorRuntime.generated.js.map +1 -0
  125. package/dist/esm/lib/v3/handlers/extractHandler.js +19 -2
  126. package/dist/esm/lib/v3/handlers/extractHandler.js.map +1 -1
  127. package/dist/esm/lib/v3/handlers/observeHandler.js +2 -1
  128. package/dist/esm/lib/v3/handlers/observeHandler.js.map +1 -1
  129. package/dist/esm/lib/v3/handlers/v3AgentHandler.d.ts +1 -0
  130. package/dist/esm/lib/v3/handlers/v3AgentHandler.js +83 -7
  131. package/dist/esm/lib/v3/handlers/v3AgentHandler.js.map +1 -1
  132. package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.d.ts +11 -0
  133. package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.js +120 -5
  134. package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.js.map +1 -1
  135. package/dist/esm/lib/v3/index.d.ts +12 -0
  136. package/dist/esm/lib/v3/index.js +10 -0
  137. package/dist/esm/lib/v3/index.js.map +1 -1
  138. package/dist/esm/lib/v3/launch/local.d.ts +2 -7
  139. package/dist/esm/lib/v3/launch/local.js +48 -8
  140. package/dist/esm/lib/v3/launch/local.js.map +1 -1
  141. package/dist/esm/lib/v3/llm/LLMProvider.d.ts +3 -0
  142. package/dist/esm/lib/v3/llm/LLMProvider.js +28 -9
  143. package/dist/esm/lib/v3/llm/LLMProvider.js.map +1 -1
  144. package/dist/esm/lib/v3/llm/aisdk.js +5 -0
  145. package/dist/esm/lib/v3/llm/aisdk.js.map +1 -1
  146. package/dist/esm/lib/v3/types/private/handlers.d.ts +2 -0
  147. package/dist/esm/lib/v3/types/private/handlers.js.map +1 -1
  148. package/dist/esm/lib/v3/types/private/snapshot.d.ts +2 -0
  149. package/dist/esm/lib/v3/types/private/snapshot.js.map +1 -1
  150. package/dist/esm/lib/v3/types/public/agent.d.ts +7 -1
  151. package/dist/esm/lib/v3/types/public/agent.js.map +1 -1
  152. package/dist/esm/lib/v3/types/public/agentEvidenceEvents.d.ts +85 -0
  153. package/dist/esm/lib/v3/types/public/agentEvidenceEvents.js +14 -0
  154. package/dist/esm/lib/v3/types/public/agentEvidenceEvents.js.map +1 -0
  155. package/dist/esm/lib/v3/types/public/api.d.ts +584 -65
  156. package/dist/esm/lib/v3/types/public/api.js +105 -5
  157. package/dist/esm/lib/v3/types/public/api.js.map +1 -1
  158. package/dist/esm/lib/v3/types/public/index.d.ts +1 -0
  159. package/dist/esm/lib/v3/types/public/index.js +1 -0
  160. package/dist/esm/lib/v3/types/public/index.js.map +1 -1
  161. package/dist/esm/lib/v3/types/public/methods.d.ts +2 -0
  162. package/dist/esm/lib/v3/types/public/methods.js.map +1 -1
  163. package/dist/esm/lib/v3/types/public/model.d.ts +23 -10
  164. package/dist/esm/lib/v3/types/public/model.js.map +1 -1
  165. package/dist/esm/lib/v3/understudy/a11y/snapshot/a11yTree.js +25 -0
  166. package/dist/esm/lib/v3/understudy/a11y/snapshot/a11yTree.js.map +1 -1
  167. package/dist/esm/lib/v3/understudy/a11y/snapshot/treeFormatUtils.js +10 -1
  168. package/dist/esm/lib/v3/understudy/a11y/snapshot/treeFormatUtils.js.map +1 -1
  169. package/dist/esm/lib/v3/v3.d.ts +1 -0
  170. package/dist/esm/lib/v3/v3.js +21 -47
  171. package/dist/esm/lib/v3/v3.js.map +1 -1
  172. package/dist/esm/lib/v3/verifier/evidenceNormalization.d.ts +7 -0
  173. package/dist/esm/lib/v3/verifier/evidenceNormalization.js +93 -0
  174. package/dist/esm/lib/v3/verifier/evidenceNormalization.js.map +1 -0
  175. package/dist/esm/lib/v3/verifier/index.d.ts +6 -0
  176. package/dist/esm/lib/v3/verifier/index.js +3 -0
  177. package/dist/esm/lib/v3/verifier/index.js.map +1 -0
  178. package/dist/esm/lib/v3/verifier/trajectory.d.ts +50 -0
  179. package/dist/esm/lib/v3/verifier/trajectory.js +273 -0
  180. package/dist/esm/lib/v3/verifier/trajectory.js.map +1 -0
  181. package/dist/esm/lib/v3/verifier/types.d.ts +281 -0
  182. package/dist/esm/lib/v3/verifier/types.js +9 -0
  183. package/dist/esm/lib/v3/verifier/types.js.map +1 -0
  184. package/dist/esm/lib/v3Evaluator.d.ts +29 -16
  185. package/dist/esm/lib/v3Evaluator.js +183 -193
  186. package/dist/esm/lib/v3Evaluator.js.map +1 -1
  187. package/dist/esm/lib/v3LegacyEvaluator.d.ts +20 -0
  188. package/dist/esm/lib/v3LegacyEvaluator.js +215 -0
  189. package/dist/esm/lib/v3LegacyEvaluator.js.map +1 -0
  190. package/dist/esm/lib/version.d.ts +1 -1
  191. package/dist/esm/lib/version.js +1 -1
  192. package/dist/esm/lib/version.js.map +1 -1
  193. package/package.json +33 -21
  194. package/dist/cjs/tests/cache-variables.test.d.ts +0 -1
  195. package/dist/cjs/tests/cache-variables.test.js +0 -221
  196. package/dist/cjs/tests/cache-variables.test.js.map +0 -1
  197. package/dist/cjs/tests/integration/agent-abort-signal.spec.d.ts +0 -1
  198. package/dist/cjs/tests/integration/agent-abort-signal.spec.js +0 -123
  199. package/dist/cjs/tests/integration/agent-abort-signal.spec.js.map +0 -1
  200. package/dist/cjs/tests/integration/agent-cache-self-heal.spec.d.ts +0 -1
  201. package/dist/cjs/tests/integration/agent-cache-self-heal.spec.js +0 -83
  202. package/dist/cjs/tests/integration/agent-cache-self-heal.spec.js.map +0 -1
  203. package/dist/cjs/tests/integration/agent-callbacks.spec.d.ts +0 -1
  204. package/dist/cjs/tests/integration/agent-callbacks.spec.js +0 -385
  205. package/dist/cjs/tests/integration/agent-callbacks.spec.js.map +0 -1
  206. package/dist/cjs/tests/integration/agent-experimental-validation.spec.d.ts +0 -1
  207. package/dist/cjs/tests/integration/agent-experimental-validation.spec.js +0 -362
  208. package/dist/cjs/tests/integration/agent-experimental-validation.spec.js.map +0 -1
  209. package/dist/cjs/tests/integration/agent-hybrid-mode.spec.d.ts +0 -1
  210. package/dist/cjs/tests/integration/agent-hybrid-mode.spec.js +0 -262
  211. package/dist/cjs/tests/integration/agent-hybrid-mode.spec.js.map +0 -1
  212. package/dist/cjs/tests/integration/agent-message-continuation.spec.d.ts +0 -1
  213. package/dist/cjs/tests/integration/agent-message-continuation.spec.js +0 -112
  214. package/dist/cjs/tests/integration/agent-message-continuation.spec.js.map +0 -1
  215. package/dist/cjs/tests/integration/agent-streaming.spec.d.ts +0 -1
  216. package/dist/cjs/tests/integration/agent-streaming.spec.js +0 -140
  217. package/dist/cjs/tests/integration/agent-streaming.spec.js.map +0 -1
  218. package/dist/cjs/tests/integration/cdp-close-api-region.spec.d.ts +0 -1
  219. package/dist/cjs/tests/integration/cdp-close-api-region.spec.js +0 -41
  220. package/dist/cjs/tests/integration/cdp-close-api-region.spec.js.map +0 -1
  221. package/dist/cjs/tests/integration/cdp-connection-close.spec.d.ts +0 -1
  222. package/dist/cjs/tests/integration/cdp-connection-close.spec.js +0 -76
  223. package/dist/cjs/tests/integration/cdp-connection-close.spec.js.map +0 -1
  224. package/dist/cjs/tests/integration/cdp-session-detached.spec.d.ts +0 -1
  225. package/dist/cjs/tests/integration/cdp-session-detached.spec.js +0 -45
  226. package/dist/cjs/tests/integration/cdp-session-detached.spec.js.map +0 -1
  227. package/dist/cjs/tests/integration/chrome-newtab-page-tracking.spec.d.ts +0 -1
  228. package/dist/cjs/tests/integration/chrome-newtab-page-tracking.spec.js +0 -56
  229. package/dist/cjs/tests/integration/chrome-newtab-page-tracking.spec.js.map +0 -1
  230. package/dist/cjs/tests/integration/click-count.spec.d.ts +0 -1
  231. package/dist/cjs/tests/integration/click-count.spec.js +0 -163
  232. package/dist/cjs/tests/integration/click-count.spec.js.map +0 -1
  233. package/dist/cjs/tests/integration/connect-to-existing-browser.spec.d.ts +0 -1
  234. package/dist/cjs/tests/integration/connect-to-existing-browser.spec.js +0 -99
  235. package/dist/cjs/tests/integration/connect-to-existing-browser.spec.js.map +0 -1
  236. package/dist/cjs/tests/integration/context-addInitScript.spec.d.ts +0 -1
  237. package/dist/cjs/tests/integration/context-addInitScript.spec.js +0 -285
  238. package/dist/cjs/tests/integration/context-addInitScript.spec.js.map +0 -1
  239. package/dist/cjs/tests/integration/context-extra-http-headers.spec.d.ts +0 -1
  240. package/dist/cjs/tests/integration/context-extra-http-headers.spec.js +0 -49
  241. package/dist/cjs/tests/integration/context-extra-http-headers.spec.js.map +0 -1
  242. package/dist/cjs/tests/integration/cookies.spec.d.ts +0 -1
  243. package/dist/cjs/tests/integration/cookies.spec.js +0 -187
  244. package/dist/cjs/tests/integration/cookies.spec.js.map +0 -1
  245. package/dist/cjs/tests/integration/default-page-tracking.spec.d.ts +0 -1
  246. package/dist/cjs/tests/integration/default-page-tracking.spec.js +0 -52
  247. package/dist/cjs/tests/integration/default-page-tracking.spec.js.map +0 -1
  248. package/dist/cjs/tests/integration/downloads.spec.d.ts +0 -1
  249. package/dist/cjs/tests/integration/downloads.spec.js +0 -52
  250. package/dist/cjs/tests/integration/downloads.spec.js.map +0 -1
  251. package/dist/cjs/tests/integration/flowLogger.spec.d.ts +0 -1
  252. package/dist/cjs/tests/integration/flowLogger.spec.js +0 -718
  253. package/dist/cjs/tests/integration/flowLogger.spec.js.map +0 -1
  254. package/dist/cjs/tests/integration/frame-get-location-and-click.spec.d.ts +0 -1
  255. package/dist/cjs/tests/integration/frame-get-location-and-click.spec.js +0 -57
  256. package/dist/cjs/tests/integration/frame-get-location-and-click.spec.js.map +0 -1
  257. package/dist/cjs/tests/integration/iframe-ctx-addInitScript-race.spec.d.ts +0 -1
  258. package/dist/cjs/tests/integration/iframe-ctx-addInitScript-race.spec.js +0 -219
  259. package/dist/cjs/tests/integration/iframe-ctx-addInitScript-race.spec.js.map +0 -1
  260. package/dist/cjs/tests/integration/iframe-ctx-addInitScript.spec.d.ts +0 -1
  261. package/dist/cjs/tests/integration/iframe-ctx-addInitScript.spec.js +0 -474
  262. package/dist/cjs/tests/integration/iframe-ctx-addInitScript.spec.js.map +0 -1
  263. package/dist/cjs/tests/integration/keep-alive.child.d.ts +0 -1
  264. package/dist/cjs/tests/integration/keep-alive.child.js +0 -85
  265. package/dist/cjs/tests/integration/keep-alive.child.js.map +0 -1
  266. package/dist/cjs/tests/integration/keep-alive.spec.d.ts +0 -22
  267. package/dist/cjs/tests/integration/keep-alive.spec.js +0 -490
  268. package/dist/cjs/tests/integration/keep-alive.spec.js.map +0 -1
  269. package/dist/cjs/tests/integration/keyboard.spec.d.ts +0 -1
  270. package/dist/cjs/tests/integration/keyboard.spec.js +0 -259
  271. package/dist/cjs/tests/integration/keyboard.spec.js.map +0 -1
  272. package/dist/cjs/tests/integration/locator-backend-node-id.spec.d.ts +0 -1
  273. package/dist/cjs/tests/integration/locator-backend-node-id.spec.js +0 -150
  274. package/dist/cjs/tests/integration/locator-backend-node-id.spec.js.map +0 -1
  275. package/dist/cjs/tests/integration/locator-content-methods.spec.d.ts +0 -1
  276. package/dist/cjs/tests/integration/locator-content-methods.spec.js +0 -180
  277. package/dist/cjs/tests/integration/locator-content-methods.spec.js.map +0 -1
  278. package/dist/cjs/tests/integration/locator-count-iframe.spec.d.ts +0 -1
  279. package/dist/cjs/tests/integration/locator-count-iframe.spec.js +0 -129
  280. package/dist/cjs/tests/integration/locator-count-iframe.spec.js.map +0 -1
  281. package/dist/cjs/tests/integration/locator-count.spec.d.ts +0 -1
  282. package/dist/cjs/tests/integration/locator-count.spec.js +0 -68
  283. package/dist/cjs/tests/integration/locator-count.spec.js.map +0 -1
  284. package/dist/cjs/tests/integration/locator-fill.spec.d.ts +0 -1
  285. package/dist/cjs/tests/integration/locator-fill.spec.js +0 -117
  286. package/dist/cjs/tests/integration/locator-fill.spec.js.map +0 -1
  287. package/dist/cjs/tests/integration/locator-input-methods.spec.d.ts +0 -1
  288. package/dist/cjs/tests/integration/locator-input-methods.spec.js +0 -127
  289. package/dist/cjs/tests/integration/locator-input-methods.spec.js.map +0 -1
  290. package/dist/cjs/tests/integration/locator-nth.spec.d.ts +0 -1
  291. package/dist/cjs/tests/integration/locator-nth.spec.js +0 -175
  292. package/dist/cjs/tests/integration/locator-nth.spec.js.map +0 -1
  293. package/dist/cjs/tests/integration/locator-select-option.spec.d.ts +0 -1
  294. package/dist/cjs/tests/integration/locator-select-option.spec.js +0 -216
  295. package/dist/cjs/tests/integration/locator-select-option.spec.js.map +0 -1
  296. package/dist/cjs/tests/integration/logger-initialization.spec.d.ts +0 -1
  297. package/dist/cjs/tests/integration/logger-initialization.spec.js +0 -597
  298. package/dist/cjs/tests/integration/logger-initialization.spec.js.map +0 -1
  299. package/dist/cjs/tests/integration/multi-instance-logger.spec.d.ts +0 -1
  300. package/dist/cjs/tests/integration/multi-instance-logger.spec.js +0 -293
  301. package/dist/cjs/tests/integration/multi-instance-logger.spec.js.map +0 -1
  302. package/dist/cjs/tests/integration/nested-div.spec.d.ts +0 -1
  303. package/dist/cjs/tests/integration/nested-div.spec.js +0 -22
  304. package/dist/cjs/tests/integration/nested-div.spec.js.map +0 -1
  305. package/dist/cjs/tests/integration/observe-element-id-format.spec.d.ts +0 -1
  306. package/dist/cjs/tests/integration/observe-element-id-format.spec.js +0 -130
  307. package/dist/cjs/tests/integration/observe-element-id-format.spec.js.map +0 -1
  308. package/dist/cjs/tests/integration/page-addInitScript.spec.d.ts +0 -1
  309. package/dist/cjs/tests/integration/page-addInitScript.spec.js +0 -94
  310. package/dist/cjs/tests/integration/page-addInitScript.spec.js.map +0 -1
  311. package/dist/cjs/tests/integration/page-console.spec.d.ts +0 -1
  312. package/dist/cjs/tests/integration/page-console.spec.js +0 -47
  313. package/dist/cjs/tests/integration/page-console.spec.js.map +0 -1
  314. package/dist/cjs/tests/integration/page-drag-and-drop.spec.d.ts +0 -1
  315. package/dist/cjs/tests/integration/page-drag-and-drop.spec.js +0 -437
  316. package/dist/cjs/tests/integration/page-drag-and-drop.spec.js.map +0 -1
  317. package/dist/cjs/tests/integration/page-extra-http-headers.spec.d.ts +0 -1
  318. package/dist/cjs/tests/integration/page-extra-http-headers.spec.js +0 -85
  319. package/dist/cjs/tests/integration/page-extra-http-headers.spec.js.map +0 -1
  320. package/dist/cjs/tests/integration/page-goto-response.spec.d.ts +0 -1
  321. package/dist/cjs/tests/integration/page-goto-response.spec.js +0 -34
  322. package/dist/cjs/tests/integration/page-goto-response.spec.js.map +0 -1
  323. package/dist/cjs/tests/integration/page-hover.spec.d.ts +0 -1
  324. package/dist/cjs/tests/integration/page-hover.spec.js +0 -165
  325. package/dist/cjs/tests/integration/page-hover.spec.js.map +0 -1
  326. package/dist/cjs/tests/integration/page-screenshot.spec.d.ts +0 -1
  327. package/dist/cjs/tests/integration/page-screenshot.spec.js +0 -292
  328. package/dist/cjs/tests/integration/page-screenshot.spec.js.map +0 -1
  329. package/dist/cjs/tests/integration/page-scroll.spec.d.ts +0 -1
  330. package/dist/cjs/tests/integration/page-scroll.spec.js +0 -183
  331. package/dist/cjs/tests/integration/page-scroll.spec.js.map +0 -1
  332. package/dist/cjs/tests/integration/page-send-cdp.spec.d.ts +0 -1
  333. package/dist/cjs/tests/integration/page-send-cdp.spec.js +0 -47
  334. package/dist/cjs/tests/integration/page-send-cdp.spec.js.map +0 -1
  335. package/dist/cjs/tests/integration/perform-understudy-method.spec.d.ts +0 -1
  336. package/dist/cjs/tests/integration/perform-understudy-method.spec.js +0 -63
  337. package/dist/cjs/tests/integration/perform-understudy-method.spec.js.map +0 -1
  338. package/dist/cjs/tests/integration/setinputfiles.spec.d.ts +0 -1
  339. package/dist/cjs/tests/integration/setinputfiles.spec.js +0 -133
  340. package/dist/cjs/tests/integration/setinputfiles.spec.js.map +0 -1
  341. package/dist/cjs/tests/integration/shadow-iframe-oopif.spec.d.ts +0 -1
  342. package/dist/cjs/tests/integration/shadow-iframe-oopif.spec.js +0 -161
  343. package/dist/cjs/tests/integration/shadow-iframe-oopif.spec.js.map +0 -1
  344. package/dist/cjs/tests/integration/shadow-iframe-spif.spec.d.ts +0 -1
  345. package/dist/cjs/tests/integration/shadow-iframe-spif.spec.js +0 -160
  346. package/dist/cjs/tests/integration/shadow-iframe-spif.spec.js.map +0 -1
  347. package/dist/cjs/tests/integration/testUtils.d.ts +0 -40
  348. package/dist/cjs/tests/integration/testUtils.js +0 -188
  349. package/dist/cjs/tests/integration/testUtils.js.map +0 -1
  350. package/dist/cjs/tests/integration/text-selector-innermost.spec.d.ts +0 -1
  351. package/dist/cjs/tests/integration/text-selector-innermost.spec.js +0 -105
  352. package/dist/cjs/tests/integration/text-selector-innermost.spec.js.map +0 -1
  353. package/dist/cjs/tests/integration/timeouts.spec.d.ts +0 -1
  354. package/dist/cjs/tests/integration/timeouts.spec.js +0 -309
  355. package/dist/cjs/tests/integration/timeouts.spec.js.map +0 -1
  356. package/dist/cjs/tests/integration/user-data-dir.spec.d.ts +0 -1
  357. package/dist/cjs/tests/integration/user-data-dir.spec.js +0 -77
  358. package/dist/cjs/tests/integration/user-data-dir.spec.js.map +0 -1
  359. package/dist/cjs/tests/integration/v3.config.d.ts +0 -4
  360. package/dist/cjs/tests/integration/v3.config.js +0 -11
  361. package/dist/cjs/tests/integration/v3.config.js.map +0 -1
  362. package/dist/cjs/tests/integration/v3.dynamic.config.d.ts +0 -4
  363. package/dist/cjs/tests/integration/v3.dynamic.config.js +0 -48
  364. package/dist/cjs/tests/integration/v3.dynamic.config.js.map +0 -1
  365. package/dist/cjs/tests/integration/v3.playwright.config.d.ts +0 -2
  366. package/dist/cjs/tests/integration/v3.playwright.config.js +0 -48
  367. package/dist/cjs/tests/integration/v3.playwright.config.js.map +0 -1
  368. package/dist/cjs/tests/integration/wait-for-selector.spec.d.ts +0 -1
  369. package/dist/cjs/tests/integration/wait-for-selector.spec.js +0 -683
  370. package/dist/cjs/tests/integration/wait-for-selector.spec.js.map +0 -1
  371. package/dist/cjs/tests/integration/wait-for-timeout.spec.d.ts +0 -1
  372. package/dist/cjs/tests/integration/wait-for-timeout.spec.js +0 -118
  373. package/dist/cjs/tests/integration/wait-for-timeout.spec.js.map +0 -1
  374. package/dist/cjs/tests/integration/xpath-for-location-deep.spec.d.ts +0 -1
  375. package/dist/cjs/tests/integration/xpath-for-location-deep.spec.js +0 -87
  376. package/dist/cjs/tests/integration/xpath-for-location-deep.spec.js.map +0 -1
  377. package/dist/cjs/tests/unit/agent-captcha-hooks.test.d.ts +0 -1
  378. package/dist/cjs/tests/unit/agent-captcha-hooks.test.js +0 -341
  379. package/dist/cjs/tests/unit/agent-captcha-hooks.test.js.map +0 -1
  380. package/dist/cjs/tests/unit/agent-execution-model.test.d.ts +0 -1
  381. package/dist/cjs/tests/unit/agent-execution-model.test.js +0 -150
  382. package/dist/cjs/tests/unit/agent-execution-model.test.js.map +0 -1
  383. package/dist/cjs/tests/unit/agent-metrics.test.d.ts +0 -1
  384. package/dist/cjs/tests/unit/agent-metrics.test.js +0 -112
  385. package/dist/cjs/tests/unit/agent-metrics.test.js.map +0 -1
  386. package/dist/cjs/tests/unit/agent-mode-routing.test.d.ts +0 -1
  387. package/dist/cjs/tests/unit/agent-mode-routing.test.js +0 -88
  388. package/dist/cjs/tests/unit/agent-mode-routing.test.js.map +0 -1
  389. package/dist/cjs/tests/unit/agent-system-prompt-variables.test.d.ts +0 -1
  390. package/dist/cjs/tests/unit/agent-system-prompt-variables.test.js +0 -23
  391. package/dist/cjs/tests/unit/agent-system-prompt-variables.test.js.map +0 -1
  392. package/dist/cjs/tests/unit/agent-temperature.test.d.ts +0 -1
  393. package/dist/cjs/tests/unit/agent-temperature.test.js +0 -191
  394. package/dist/cjs/tests/unit/agent-temperature.test.js.map +0 -1
  395. package/dist/cjs/tests/unit/agent-variables-validation.test.d.ts +0 -1
  396. package/dist/cjs/tests/unit/agent-variables-validation.test.js +0 -43
  397. package/dist/cjs/tests/unit/agent-variables-validation.test.js.map +0 -1
  398. package/dist/cjs/tests/unit/aisdk-clients.test.d.ts +0 -1
  399. package/dist/cjs/tests/unit/aisdk-clients.test.js +0 -86
  400. package/dist/cjs/tests/unit/aisdk-clients.test.js.map +0 -1
  401. package/dist/cjs/tests/unit/anthropic-cua-adaptive-thinking.test.d.ts +0 -1
  402. package/dist/cjs/tests/unit/anthropic-cua-adaptive-thinking.test.js +0 -250
  403. package/dist/cjs/tests/unit/anthropic-cua-adaptive-thinking.test.js.map +0 -1
  404. package/dist/cjs/tests/unit/api-client-observe-variables.test.d.ts +0 -1
  405. package/dist/cjs/tests/unit/api-client-observe-variables.test.js +0 -133
  406. package/dist/cjs/tests/unit/api-client-observe-variables.test.js.map +0 -1
  407. package/dist/cjs/tests/unit/api-multiregion.test.d.ts +0 -1
  408. package/dist/cjs/tests/unit/api-multiregion.test.js +0 -58
  409. package/dist/cjs/tests/unit/api-multiregion.test.js.map +0 -1
  410. package/dist/cjs/tests/unit/api-optional-model-api-key.test.d.ts +0 -1
  411. package/dist/cjs/tests/unit/api-optional-model-api-key.test.js +0 -155
  412. package/dist/cjs/tests/unit/api-optional-model-api-key.test.js.map +0 -1
  413. package/dist/cjs/tests/unit/api-variables-schema.test.d.ts +0 -1
  414. package/dist/cjs/tests/unit/api-variables-schema.test.js +0 -62
  415. package/dist/cjs/tests/unit/api-variables-schema.test.js.map +0 -1
  416. package/dist/cjs/tests/unit/browserbase-session-accessors.test.d.ts +0 -1
  417. package/dist/cjs/tests/unit/browserbase-session-accessors.test.js +0 -142
  418. package/dist/cjs/tests/unit/browserbase-session-accessors.test.js.map +0 -1
  419. package/dist/cjs/tests/unit/cache-llm-resolution.test.d.ts +0 -1
  420. package/dist/cjs/tests/unit/cache-llm-resolution.test.js +0 -186
  421. package/dist/cjs/tests/unit/cache-llm-resolution.test.js.map +0 -1
  422. package/dist/cjs/tests/unit/captcha-solver.test.d.ts +0 -1
  423. package/dist/cjs/tests/unit/captcha-solver.test.js +0 -154
  424. package/dist/cjs/tests/unit/captcha-solver.test.js.map +0 -1
  425. package/dist/cjs/tests/unit/cdp-connection-close.test.d.ts +0 -1
  426. package/dist/cjs/tests/unit/cdp-connection-close.test.js +0 -74
  427. package/dist/cjs/tests/unit/cdp-connection-close.test.js.map +0 -1
  428. package/dist/cjs/tests/unit/context-extra-http-headers.test.d.ts +0 -1
  429. package/dist/cjs/tests/unit/context-extra-http-headers.test.js +0 -58
  430. package/dist/cjs/tests/unit/context-extra-http-headers.test.js.map +0 -1
  431. package/dist/cjs/tests/unit/cookies.test.d.ts +0 -1
  432. package/dist/cjs/tests/unit/cookies.test.js +0 -944
  433. package/dist/cjs/tests/unit/cookies.test.js.map +0 -1
  434. package/dist/cjs/tests/unit/flowlogger-capturing-cdp.test.d.ts +0 -1
  435. package/dist/cjs/tests/unit/flowlogger-capturing-cdp.test.js +0 -95
  436. package/dist/cjs/tests/unit/flowlogger-capturing-cdp.test.js.map +0 -1
  437. package/dist/cjs/tests/unit/flowlogger-capturing-llm.test.d.ts +0 -1
  438. package/dist/cjs/tests/unit/flowlogger-capturing-llm.test.js +0 -43
  439. package/dist/cjs/tests/unit/flowlogger-capturing-llm.test.js.map +0 -1
  440. package/dist/cjs/tests/unit/flowlogger-eventstore.test.d.ts +0 -1
  441. package/dist/cjs/tests/unit/flowlogger-eventstore.test.js +0 -250
  442. package/dist/cjs/tests/unit/flowlogger-eventstore.test.js.map +0 -1
  443. package/dist/cjs/tests/unit/frame-registry-oopif-adoption.test.d.ts +0 -1
  444. package/dist/cjs/tests/unit/frame-registry-oopif-adoption.test.js +0 -60
  445. package/dist/cjs/tests/unit/frame-registry-oopif-adoption.test.js.map +0 -1
  446. package/dist/cjs/tests/unit/helpers/mockCDPSession.d.ts +0 -19
  447. package/dist/cjs/tests/unit/helpers/mockCDPSession.js +0 -29
  448. package/dist/cjs/tests/unit/helpers/mockCDPSession.js.map +0 -1
  449. package/dist/cjs/tests/unit/inference-temperature.test.d.ts +0 -1
  450. package/dist/cjs/tests/unit/inference-temperature.test.js +0 -65
  451. package/dist/cjs/tests/unit/inference-temperature.test.js.map +0 -1
  452. package/dist/cjs/tests/unit/llm-middleware.test.d.ts +0 -1
  453. package/dist/cjs/tests/unit/llm-middleware.test.js +0 -495
  454. package/dist/cjs/tests/unit/llm-middleware.test.js.map +0 -1
  455. package/dist/cjs/tests/unit/llm-provider.test.d.ts +0 -1
  456. package/dist/cjs/tests/unit/llm-provider.test.js +0 -64
  457. package/dist/cjs/tests/unit/llm-provider.test.js.map +0 -1
  458. package/dist/cjs/tests/unit/microsoft-cua-client.test.d.ts +0 -1
  459. package/dist/cjs/tests/unit/microsoft-cua-client.test.js +0 -86
  460. package/dist/cjs/tests/unit/microsoft-cua-client.test.js.map +0 -1
  461. package/dist/cjs/tests/unit/model-deprecation.test.d.ts +0 -1
  462. package/dist/cjs/tests/unit/model-deprecation.test.js +0 -142
  463. package/dist/cjs/tests/unit/model-deprecation.test.js.map +0 -1
  464. package/dist/cjs/tests/unit/model-utils.test.d.ts +0 -1
  465. package/dist/cjs/tests/unit/model-utils.test.js +0 -42
  466. package/dist/cjs/tests/unit/model-utils.test.js.map +0 -1
  467. package/dist/cjs/tests/unit/openai-compatible-temperature.test.d.ts +0 -1
  468. package/dist/cjs/tests/unit/openai-compatible-temperature.test.js +0 -84
  469. package/dist/cjs/tests/unit/openai-compatible-temperature.test.js.map +0 -1
  470. package/dist/cjs/tests/unit/openai-cua-client.test.d.ts +0 -1
  471. package/dist/cjs/tests/unit/openai-cua-client.test.js +0 -71
  472. package/dist/cjs/tests/unit/openai-cua-client.test.js.map +0 -1
  473. package/dist/cjs/tests/unit/page-extra-http-headers.test.d.ts +0 -1
  474. package/dist/cjs/tests/unit/page-extra-http-headers.test.js +0 -92
  475. package/dist/cjs/tests/unit/page-extra-http-headers.test.js.map +0 -1
  476. package/dist/cjs/tests/unit/page-snapshot.test.d.ts +0 -1
  477. package/dist/cjs/tests/unit/page-snapshot.test.js +0 -75
  478. package/dist/cjs/tests/unit/page-snapshot.test.js.map +0 -1
  479. package/dist/cjs/tests/unit/prompt-observe-variables.test.d.ts +0 -1
  480. package/dist/cjs/tests/unit/prompt-observe-variables.test.js +0 -25
  481. package/dist/cjs/tests/unit/prompt-observe-variables.test.js.map +0 -1
  482. package/dist/cjs/tests/unit/public-api/export-surface.test.d.ts +0 -1
  483. package/dist/cjs/tests/unit/public-api/export-surface.test.js +0 -107
  484. package/dist/cjs/tests/unit/public-api/export-surface.test.js.map +0 -1
  485. package/dist/cjs/tests/unit/public-api/llm-and-agents.test.d.ts +0 -1
  486. package/dist/cjs/tests/unit/public-api/llm-and-agents.test.js +0 -179
  487. package/dist/cjs/tests/unit/public-api/llm-and-agents.test.js.map +0 -1
  488. package/dist/cjs/tests/unit/public-api/public-error-types.test.d.ts +0 -62
  489. package/dist/cjs/tests/unit/public-api/public-error-types.test.js +0 -110
  490. package/dist/cjs/tests/unit/public-api/public-error-types.test.js.map +0 -1
  491. package/dist/cjs/tests/unit/public-api/public-types.test.d.ts +0 -1
  492. package/dist/cjs/tests/unit/public-api/public-types.test.js +0 -99
  493. package/dist/cjs/tests/unit/public-api/public-types.test.js.map +0 -1
  494. package/dist/cjs/tests/unit/public-api/runtime-utils.test.d.ts +0 -1
  495. package/dist/cjs/tests/unit/public-api/runtime-utils.test.js +0 -60
  496. package/dist/cjs/tests/unit/public-api/runtime-utils.test.js.map +0 -1
  497. package/dist/cjs/tests/unit/public-api/schema-utils.test.d.ts +0 -1
  498. package/dist/cjs/tests/unit/public-api/schema-utils.test.js +0 -95
  499. package/dist/cjs/tests/unit/public-api/schema-utils.test.js.map +0 -1
  500. package/dist/cjs/tests/unit/public-api/timeout-error-types.test.d.ts +0 -1
  501. package/dist/cjs/tests/unit/public-api/timeout-error-types.test.js +0 -121
  502. package/dist/cjs/tests/unit/public-api/timeout-error-types.test.js.map +0 -1
  503. package/dist/cjs/tests/unit/public-api/tool-type-export.test.d.ts +0 -1
  504. package/dist/cjs/tests/unit/public-api/tool-type-export.test.js +0 -65
  505. package/dist/cjs/tests/unit/public-api/tool-type-export.test.js.map +0 -1
  506. package/dist/cjs/tests/unit/public-api/v3-core.test.d.ts +0 -1
  507. package/dist/cjs/tests/unit/public-api/v3-core.test.js +0 -108
  508. package/dist/cjs/tests/unit/public-api/v3-core.test.js.map +0 -1
  509. package/dist/cjs/tests/unit/safety-confirmation.test.d.ts +0 -1
  510. package/dist/cjs/tests/unit/safety-confirmation.test.js +0 -110
  511. package/dist/cjs/tests/unit/safety-confirmation.test.js.map +0 -1
  512. package/dist/cjs/tests/unit/snapshot-a11y-resolvers.test.d.ts +0 -1
  513. package/dist/cjs/tests/unit/snapshot-a11y-resolvers.test.js +0 -431
  514. package/dist/cjs/tests/unit/snapshot-a11y-resolvers.test.js.map +0 -1
  515. package/dist/cjs/tests/unit/snapshot-a11y-tree-utils.test.d.ts +0 -1
  516. package/dist/cjs/tests/unit/snapshot-a11y-tree-utils.test.js +0 -306
  517. package/dist/cjs/tests/unit/snapshot-a11y-tree-utils.test.js.map +0 -1
  518. package/dist/cjs/tests/unit/snapshot-capture-orchestration.test.d.ts +0 -1
  519. package/dist/cjs/tests/unit/snapshot-capture-orchestration.test.js +0 -504
  520. package/dist/cjs/tests/unit/snapshot-capture-orchestration.test.js.map +0 -1
  521. package/dist/cjs/tests/unit/snapshot-cbor.test.d.ts +0 -1
  522. package/dist/cjs/tests/unit/snapshot-cbor.test.js +0 -204
  523. package/dist/cjs/tests/unit/snapshot-cbor.test.js.map +0 -1
  524. package/dist/cjs/tests/unit/snapshot-dom-session-builders.test.d.ts +0 -1
  525. package/dist/cjs/tests/unit/snapshot-dom-session-builders.test.js +0 -220
  526. package/dist/cjs/tests/unit/snapshot-dom-session-builders.test.js.map +0 -1
  527. package/dist/cjs/tests/unit/snapshot-dom-tree-utils.test.d.ts +0 -1
  528. package/dist/cjs/tests/unit/snapshot-dom-tree-utils.test.js +0 -107
  529. package/dist/cjs/tests/unit/snapshot-dom-tree-utils.test.js.map +0 -1
  530. package/dist/cjs/tests/unit/snapshot-focus-selectors-utils.test.d.ts +0 -1
  531. package/dist/cjs/tests/unit/snapshot-focus-selectors-utils.test.js +0 -89
  532. package/dist/cjs/tests/unit/snapshot-focus-selectors-utils.test.js.map +0 -1
  533. package/dist/cjs/tests/unit/snapshot-frame-merge.test.d.ts +0 -1
  534. package/dist/cjs/tests/unit/snapshot-frame-merge.test.js +0 -335
  535. package/dist/cjs/tests/unit/snapshot-frame-merge.test.js.map +0 -1
  536. package/dist/cjs/tests/unit/snapshot-tree-format-utils.test.d.ts +0 -1
  537. package/dist/cjs/tests/unit/snapshot-tree-format-utils.test.js +0 -84
  538. package/dist/cjs/tests/unit/snapshot-tree-format-utils.test.js.map +0 -1
  539. package/dist/cjs/tests/unit/snapshot-xpath-utils.test.d.ts +0 -1
  540. package/dist/cjs/tests/unit/snapshot-xpath-utils.test.js +0 -74
  541. package/dist/cjs/tests/unit/snapshot-xpath-utils.test.js.map +0 -1
  542. package/dist/cjs/tests/unit/timeout-handlers.test.d.ts +0 -1
  543. package/dist/cjs/tests/unit/timeout-handlers.test.js +0 -897
  544. package/dist/cjs/tests/unit/timeout-handlers.test.js.map +0 -1
  545. package/dist/cjs/tests/unit/understudy-command-exception.test.d.ts +0 -1
  546. package/dist/cjs/tests/unit/understudy-command-exception.test.js +0 -57
  547. package/dist/cjs/tests/unit/understudy-command-exception.test.js.map +0 -1
  548. package/dist/cjs/tests/unit/xpath-parser.test.d.ts +0 -1
  549. package/dist/cjs/tests/unit/xpath-parser.test.js +0 -311
  550. package/dist/cjs/tests/unit/xpath-parser.test.js.map +0 -1
  551. package/dist/cjs/tests/unit/xpath-resolver.test.d.ts +0 -1
  552. package/dist/cjs/tests/unit/xpath-resolver.test.js +0 -80
  553. package/dist/cjs/tests/unit/xpath-resolver.test.js.map +0 -1
  554. package/dist/cjs/tests/unit/zod-enum-compatibility.test.d.ts +0 -1
  555. package/dist/cjs/tests/unit/zod-enum-compatibility.test.js +0 -149
  556. package/dist/cjs/tests/unit/zod-enum-compatibility.test.js.map +0 -1
  557. package/dist/esm/tests/cache-variables.test.d.ts +0 -1
  558. package/dist/esm/tests/cache-variables.test.js +0 -219
  559. package/dist/esm/tests/cache-variables.test.js.map +0 -1
  560. package/dist/esm/tests/integration/agent-abort-signal.spec.d.ts +0 -1
  561. package/dist/esm/tests/integration/agent-abort-signal.spec.js +0 -121
  562. package/dist/esm/tests/integration/agent-abort-signal.spec.js.map +0 -1
  563. package/dist/esm/tests/integration/agent-cache-self-heal.spec.d.ts +0 -1
  564. package/dist/esm/tests/integration/agent-cache-self-heal.spec.js +0 -78
  565. package/dist/esm/tests/integration/agent-cache-self-heal.spec.js.map +0 -1
  566. package/dist/esm/tests/integration/agent-callbacks.spec.d.ts +0 -1
  567. package/dist/esm/tests/integration/agent-callbacks.spec.js +0 -383
  568. package/dist/esm/tests/integration/agent-callbacks.spec.js.map +0 -1
  569. package/dist/esm/tests/integration/agent-experimental-validation.spec.d.ts +0 -1
  570. package/dist/esm/tests/integration/agent-experimental-validation.spec.js +0 -360
  571. package/dist/esm/tests/integration/agent-experimental-validation.spec.js.map +0 -1
  572. package/dist/esm/tests/integration/agent-hybrid-mode.spec.d.ts +0 -1
  573. package/dist/esm/tests/integration/agent-hybrid-mode.spec.js +0 -260
  574. package/dist/esm/tests/integration/agent-hybrid-mode.spec.js.map +0 -1
  575. package/dist/esm/tests/integration/agent-message-continuation.spec.d.ts +0 -1
  576. package/dist/esm/tests/integration/agent-message-continuation.spec.js +0 -110
  577. package/dist/esm/tests/integration/agent-message-continuation.spec.js.map +0 -1
  578. package/dist/esm/tests/integration/agent-streaming.spec.d.ts +0 -1
  579. package/dist/esm/tests/integration/agent-streaming.spec.js +0 -138
  580. package/dist/esm/tests/integration/agent-streaming.spec.js.map +0 -1
  581. package/dist/esm/tests/integration/cdp-close-api-region.spec.d.ts +0 -1
  582. package/dist/esm/tests/integration/cdp-close-api-region.spec.js +0 -39
  583. package/dist/esm/tests/integration/cdp-close-api-region.spec.js.map +0 -1
  584. package/dist/esm/tests/integration/cdp-connection-close.spec.d.ts +0 -1
  585. package/dist/esm/tests/integration/cdp-connection-close.spec.js +0 -74
  586. package/dist/esm/tests/integration/cdp-connection-close.spec.js.map +0 -1
  587. package/dist/esm/tests/integration/cdp-session-detached.spec.d.ts +0 -1
  588. package/dist/esm/tests/integration/cdp-session-detached.spec.js +0 -43
  589. package/dist/esm/tests/integration/cdp-session-detached.spec.js.map +0 -1
  590. package/dist/esm/tests/integration/chrome-newtab-page-tracking.spec.d.ts +0 -1
  591. package/dist/esm/tests/integration/chrome-newtab-page-tracking.spec.js +0 -54
  592. package/dist/esm/tests/integration/chrome-newtab-page-tracking.spec.js.map +0 -1
  593. package/dist/esm/tests/integration/click-count.spec.d.ts +0 -1
  594. package/dist/esm/tests/integration/click-count.spec.js +0 -161
  595. package/dist/esm/tests/integration/click-count.spec.js.map +0 -1
  596. package/dist/esm/tests/integration/connect-to-existing-browser.spec.d.ts +0 -1
  597. package/dist/esm/tests/integration/connect-to-existing-browser.spec.js +0 -97
  598. package/dist/esm/tests/integration/connect-to-existing-browser.spec.js.map +0 -1
  599. package/dist/esm/tests/integration/context-addInitScript.spec.d.ts +0 -1
  600. package/dist/esm/tests/integration/context-addInitScript.spec.js +0 -283
  601. package/dist/esm/tests/integration/context-addInitScript.spec.js.map +0 -1
  602. package/dist/esm/tests/integration/context-extra-http-headers.spec.d.ts +0 -1
  603. package/dist/esm/tests/integration/context-extra-http-headers.spec.js +0 -47
  604. package/dist/esm/tests/integration/context-extra-http-headers.spec.js.map +0 -1
  605. package/dist/esm/tests/integration/cookies.spec.d.ts +0 -1
  606. package/dist/esm/tests/integration/cookies.spec.js +0 -185
  607. package/dist/esm/tests/integration/cookies.spec.js.map +0 -1
  608. package/dist/esm/tests/integration/default-page-tracking.spec.d.ts +0 -1
  609. package/dist/esm/tests/integration/default-page-tracking.spec.js +0 -50
  610. package/dist/esm/tests/integration/default-page-tracking.spec.js.map +0 -1
  611. package/dist/esm/tests/integration/downloads.spec.d.ts +0 -1
  612. package/dist/esm/tests/integration/downloads.spec.js +0 -47
  613. package/dist/esm/tests/integration/downloads.spec.js.map +0 -1
  614. package/dist/esm/tests/integration/flowLogger.spec.d.ts +0 -1
  615. package/dist/esm/tests/integration/flowLogger.spec.js +0 -716
  616. package/dist/esm/tests/integration/flowLogger.spec.js.map +0 -1
  617. package/dist/esm/tests/integration/frame-get-location-and-click.spec.d.ts +0 -1
  618. package/dist/esm/tests/integration/frame-get-location-and-click.spec.js +0 -55
  619. package/dist/esm/tests/integration/frame-get-location-and-click.spec.js.map +0 -1
  620. package/dist/esm/tests/integration/iframe-ctx-addInitScript-race.spec.d.ts +0 -1
  621. package/dist/esm/tests/integration/iframe-ctx-addInitScript-race.spec.js +0 -217
  622. package/dist/esm/tests/integration/iframe-ctx-addInitScript-race.spec.js.map +0 -1
  623. package/dist/esm/tests/integration/iframe-ctx-addInitScript.spec.d.ts +0 -1
  624. package/dist/esm/tests/integration/iframe-ctx-addInitScript.spec.js +0 -472
  625. package/dist/esm/tests/integration/iframe-ctx-addInitScript.spec.js.map +0 -1
  626. package/dist/esm/tests/integration/keep-alive.child.d.ts +0 -1
  627. package/dist/esm/tests/integration/keep-alive.child.js +0 -83
  628. package/dist/esm/tests/integration/keep-alive.child.js.map +0 -1
  629. package/dist/esm/tests/integration/keep-alive.spec.d.ts +0 -22
  630. package/dist/esm/tests/integration/keep-alive.spec.js +0 -482
  631. package/dist/esm/tests/integration/keep-alive.spec.js.map +0 -1
  632. package/dist/esm/tests/integration/keyboard.spec.d.ts +0 -1
  633. package/dist/esm/tests/integration/keyboard.spec.js +0 -257
  634. package/dist/esm/tests/integration/keyboard.spec.js.map +0 -1
  635. package/dist/esm/tests/integration/locator-backend-node-id.spec.d.ts +0 -1
  636. package/dist/esm/tests/integration/locator-backend-node-id.spec.js +0 -148
  637. package/dist/esm/tests/integration/locator-backend-node-id.spec.js.map +0 -1
  638. package/dist/esm/tests/integration/locator-content-methods.spec.d.ts +0 -1
  639. package/dist/esm/tests/integration/locator-content-methods.spec.js +0 -178
  640. package/dist/esm/tests/integration/locator-content-methods.spec.js.map +0 -1
  641. package/dist/esm/tests/integration/locator-count-iframe.spec.d.ts +0 -1
  642. package/dist/esm/tests/integration/locator-count-iframe.spec.js +0 -127
  643. package/dist/esm/tests/integration/locator-count-iframe.spec.js.map +0 -1
  644. package/dist/esm/tests/integration/locator-count.spec.d.ts +0 -1
  645. package/dist/esm/tests/integration/locator-count.spec.js +0 -66
  646. package/dist/esm/tests/integration/locator-count.spec.js.map +0 -1
  647. package/dist/esm/tests/integration/locator-fill.spec.d.ts +0 -1
  648. package/dist/esm/tests/integration/locator-fill.spec.js +0 -115
  649. package/dist/esm/tests/integration/locator-fill.spec.js.map +0 -1
  650. package/dist/esm/tests/integration/locator-input-methods.spec.d.ts +0 -1
  651. package/dist/esm/tests/integration/locator-input-methods.spec.js +0 -125
  652. package/dist/esm/tests/integration/locator-input-methods.spec.js.map +0 -1
  653. package/dist/esm/tests/integration/locator-nth.spec.d.ts +0 -1
  654. package/dist/esm/tests/integration/locator-nth.spec.js +0 -173
  655. package/dist/esm/tests/integration/locator-nth.spec.js.map +0 -1
  656. package/dist/esm/tests/integration/locator-select-option.spec.d.ts +0 -1
  657. package/dist/esm/tests/integration/locator-select-option.spec.js +0 -214
  658. package/dist/esm/tests/integration/locator-select-option.spec.js.map +0 -1
  659. package/dist/esm/tests/integration/logger-initialization.spec.d.ts +0 -1
  660. package/dist/esm/tests/integration/logger-initialization.spec.js +0 -595
  661. package/dist/esm/tests/integration/logger-initialization.spec.js.map +0 -1
  662. package/dist/esm/tests/integration/multi-instance-logger.spec.d.ts +0 -1
  663. package/dist/esm/tests/integration/multi-instance-logger.spec.js +0 -291
  664. package/dist/esm/tests/integration/multi-instance-logger.spec.js.map +0 -1
  665. package/dist/esm/tests/integration/nested-div.spec.d.ts +0 -1
  666. package/dist/esm/tests/integration/nested-div.spec.js +0 -20
  667. package/dist/esm/tests/integration/nested-div.spec.js.map +0 -1
  668. package/dist/esm/tests/integration/observe-element-id-format.spec.d.ts +0 -1
  669. package/dist/esm/tests/integration/observe-element-id-format.spec.js +0 -128
  670. package/dist/esm/tests/integration/observe-element-id-format.spec.js.map +0 -1
  671. package/dist/esm/tests/integration/page-addInitScript.spec.d.ts +0 -1
  672. package/dist/esm/tests/integration/page-addInitScript.spec.js +0 -92
  673. package/dist/esm/tests/integration/page-addInitScript.spec.js.map +0 -1
  674. package/dist/esm/tests/integration/page-console.spec.d.ts +0 -1
  675. package/dist/esm/tests/integration/page-console.spec.js +0 -45
  676. package/dist/esm/tests/integration/page-console.spec.js.map +0 -1
  677. package/dist/esm/tests/integration/page-drag-and-drop.spec.d.ts +0 -1
  678. package/dist/esm/tests/integration/page-drag-and-drop.spec.js +0 -435
  679. package/dist/esm/tests/integration/page-drag-and-drop.spec.js.map +0 -1
  680. package/dist/esm/tests/integration/page-extra-http-headers.spec.d.ts +0 -1
  681. package/dist/esm/tests/integration/page-extra-http-headers.spec.js +0 -83
  682. package/dist/esm/tests/integration/page-extra-http-headers.spec.js.map +0 -1
  683. package/dist/esm/tests/integration/page-goto-response.spec.d.ts +0 -1
  684. package/dist/esm/tests/integration/page-goto-response.spec.js +0 -32
  685. package/dist/esm/tests/integration/page-goto-response.spec.js.map +0 -1
  686. package/dist/esm/tests/integration/page-hover.spec.d.ts +0 -1
  687. package/dist/esm/tests/integration/page-hover.spec.js +0 -163
  688. package/dist/esm/tests/integration/page-hover.spec.js.map +0 -1
  689. package/dist/esm/tests/integration/page-screenshot.spec.d.ts +0 -1
  690. package/dist/esm/tests/integration/page-screenshot.spec.js +0 -257
  691. package/dist/esm/tests/integration/page-screenshot.spec.js.map +0 -1
  692. package/dist/esm/tests/integration/page-scroll.spec.d.ts +0 -1
  693. package/dist/esm/tests/integration/page-scroll.spec.js +0 -181
  694. package/dist/esm/tests/integration/page-scroll.spec.js.map +0 -1
  695. package/dist/esm/tests/integration/page-send-cdp.spec.d.ts +0 -1
  696. package/dist/esm/tests/integration/page-send-cdp.spec.js +0 -45
  697. package/dist/esm/tests/integration/page-send-cdp.spec.js.map +0 -1
  698. package/dist/esm/tests/integration/perform-understudy-method.spec.d.ts +0 -1
  699. package/dist/esm/tests/integration/perform-understudy-method.spec.js +0 -61
  700. package/dist/esm/tests/integration/perform-understudy-method.spec.js.map +0 -1
  701. package/dist/esm/tests/integration/setinputfiles.spec.d.ts +0 -1
  702. package/dist/esm/tests/integration/setinputfiles.spec.js +0 -128
  703. package/dist/esm/tests/integration/setinputfiles.spec.js.map +0 -1
  704. package/dist/esm/tests/integration/shadow-iframe-oopif.spec.d.ts +0 -1
  705. package/dist/esm/tests/integration/shadow-iframe-oopif.spec.js +0 -156
  706. package/dist/esm/tests/integration/shadow-iframe-oopif.spec.js.map +0 -1
  707. package/dist/esm/tests/integration/shadow-iframe-spif.spec.d.ts +0 -1
  708. package/dist/esm/tests/integration/shadow-iframe-spif.spec.js +0 -155
  709. package/dist/esm/tests/integration/shadow-iframe-spif.spec.js.map +0 -1
  710. package/dist/esm/tests/integration/testUtils.d.ts +0 -40
  711. package/dist/esm/tests/integration/testUtils.js +0 -178
  712. package/dist/esm/tests/integration/testUtils.js.map +0 -1
  713. package/dist/esm/tests/integration/text-selector-innermost.spec.d.ts +0 -1
  714. package/dist/esm/tests/integration/text-selector-innermost.spec.js +0 -103
  715. package/dist/esm/tests/integration/text-selector-innermost.spec.js.map +0 -1
  716. package/dist/esm/tests/integration/timeouts.spec.d.ts +0 -1
  717. package/dist/esm/tests/integration/timeouts.spec.js +0 -307
  718. package/dist/esm/tests/integration/timeouts.spec.js.map +0 -1
  719. package/dist/esm/tests/integration/user-data-dir.spec.d.ts +0 -1
  720. package/dist/esm/tests/integration/user-data-dir.spec.js +0 -42
  721. package/dist/esm/tests/integration/user-data-dir.spec.js.map +0 -1
  722. package/dist/esm/tests/integration/v3.config.d.ts +0 -4
  723. package/dist/esm/tests/integration/v3.config.js +0 -7
  724. package/dist/esm/tests/integration/v3.config.js.map +0 -1
  725. package/dist/esm/tests/integration/v3.dynamic.config.d.ts +0 -4
  726. package/dist/esm/tests/integration/v3.dynamic.config.js +0 -44
  727. package/dist/esm/tests/integration/v3.dynamic.config.js.map +0 -1
  728. package/dist/esm/tests/integration/v3.playwright.config.d.ts +0 -2
  729. package/dist/esm/tests/integration/v3.playwright.config.js +0 -46
  730. package/dist/esm/tests/integration/v3.playwright.config.js.map +0 -1
  731. package/dist/esm/tests/integration/wait-for-selector.spec.d.ts +0 -1
  732. package/dist/esm/tests/integration/wait-for-selector.spec.js +0 -681
  733. package/dist/esm/tests/integration/wait-for-selector.spec.js.map +0 -1
  734. package/dist/esm/tests/integration/wait-for-timeout.spec.d.ts +0 -1
  735. package/dist/esm/tests/integration/wait-for-timeout.spec.js +0 -116
  736. package/dist/esm/tests/integration/wait-for-timeout.spec.js.map +0 -1
  737. package/dist/esm/tests/integration/xpath-for-location-deep.spec.d.ts +0 -1
  738. package/dist/esm/tests/integration/xpath-for-location-deep.spec.js +0 -85
  739. package/dist/esm/tests/integration/xpath-for-location-deep.spec.js.map +0 -1
  740. package/dist/esm/tests/unit/agent-captcha-hooks.test.d.ts +0 -1
  741. package/dist/esm/tests/unit/agent-captcha-hooks.test.js +0 -339
  742. package/dist/esm/tests/unit/agent-captcha-hooks.test.js.map +0 -1
  743. package/dist/esm/tests/unit/agent-execution-model.test.d.ts +0 -1
  744. package/dist/esm/tests/unit/agent-execution-model.test.js +0 -148
  745. package/dist/esm/tests/unit/agent-execution-model.test.js.map +0 -1
  746. package/dist/esm/tests/unit/agent-metrics.test.d.ts +0 -1
  747. package/dist/esm/tests/unit/agent-metrics.test.js +0 -110
  748. package/dist/esm/tests/unit/agent-metrics.test.js.map +0 -1
  749. package/dist/esm/tests/unit/agent-mode-routing.test.d.ts +0 -1
  750. package/dist/esm/tests/unit/agent-mode-routing.test.js +0 -86
  751. package/dist/esm/tests/unit/agent-mode-routing.test.js.map +0 -1
  752. package/dist/esm/tests/unit/agent-system-prompt-variables.test.d.ts +0 -1
  753. package/dist/esm/tests/unit/agent-system-prompt-variables.test.js +0 -21
  754. package/dist/esm/tests/unit/agent-system-prompt-variables.test.js.map +0 -1
  755. package/dist/esm/tests/unit/agent-temperature.test.d.ts +0 -1
  756. package/dist/esm/tests/unit/agent-temperature.test.js +0 -189
  757. package/dist/esm/tests/unit/agent-temperature.test.js.map +0 -1
  758. package/dist/esm/tests/unit/agent-variables-validation.test.d.ts +0 -1
  759. package/dist/esm/tests/unit/agent-variables-validation.test.js +0 -41
  760. package/dist/esm/tests/unit/agent-variables-validation.test.js.map +0 -1
  761. package/dist/esm/tests/unit/aisdk-clients.test.d.ts +0 -1
  762. package/dist/esm/tests/unit/aisdk-clients.test.js +0 -84
  763. package/dist/esm/tests/unit/aisdk-clients.test.js.map +0 -1
  764. package/dist/esm/tests/unit/anthropic-cua-adaptive-thinking.test.d.ts +0 -1
  765. package/dist/esm/tests/unit/anthropic-cua-adaptive-thinking.test.js +0 -245
  766. package/dist/esm/tests/unit/anthropic-cua-adaptive-thinking.test.js.map +0 -1
  767. package/dist/esm/tests/unit/api-client-observe-variables.test.d.ts +0 -1
  768. package/dist/esm/tests/unit/api-client-observe-variables.test.js +0 -131
  769. package/dist/esm/tests/unit/api-client-observe-variables.test.js.map +0 -1
  770. package/dist/esm/tests/unit/api-multiregion.test.d.ts +0 -1
  771. package/dist/esm/tests/unit/api-multiregion.test.js +0 -56
  772. package/dist/esm/tests/unit/api-multiregion.test.js.map +0 -1
  773. package/dist/esm/tests/unit/api-optional-model-api-key.test.d.ts +0 -1
  774. package/dist/esm/tests/unit/api-optional-model-api-key.test.js +0 -153
  775. package/dist/esm/tests/unit/api-optional-model-api-key.test.js.map +0 -1
  776. package/dist/esm/tests/unit/api-variables-schema.test.d.ts +0 -1
  777. package/dist/esm/tests/unit/api-variables-schema.test.js +0 -60
  778. package/dist/esm/tests/unit/api-variables-schema.test.js.map +0 -1
  779. package/dist/esm/tests/unit/browserbase-session-accessors.test.d.ts +0 -1
  780. package/dist/esm/tests/unit/browserbase-session-accessors.test.js +0 -140
  781. package/dist/esm/tests/unit/browserbase-session-accessors.test.js.map +0 -1
  782. package/dist/esm/tests/unit/cache-llm-resolution.test.d.ts +0 -1
  783. package/dist/esm/tests/unit/cache-llm-resolution.test.js +0 -184
  784. package/dist/esm/tests/unit/cache-llm-resolution.test.js.map +0 -1
  785. package/dist/esm/tests/unit/captcha-solver.test.d.ts +0 -1
  786. package/dist/esm/tests/unit/captcha-solver.test.js +0 -152
  787. package/dist/esm/tests/unit/captcha-solver.test.js.map +0 -1
  788. package/dist/esm/tests/unit/cdp-connection-close.test.d.ts +0 -1
  789. package/dist/esm/tests/unit/cdp-connection-close.test.js +0 -72
  790. package/dist/esm/tests/unit/cdp-connection-close.test.js.map +0 -1
  791. package/dist/esm/tests/unit/context-extra-http-headers.test.d.ts +0 -1
  792. package/dist/esm/tests/unit/context-extra-http-headers.test.js +0 -56
  793. package/dist/esm/tests/unit/context-extra-http-headers.test.js.map +0 -1
  794. package/dist/esm/tests/unit/cookies.test.d.ts +0 -1
  795. package/dist/esm/tests/unit/cookies.test.js +0 -909
  796. package/dist/esm/tests/unit/cookies.test.js.map +0 -1
  797. package/dist/esm/tests/unit/flowlogger-capturing-cdp.test.d.ts +0 -1
  798. package/dist/esm/tests/unit/flowlogger-capturing-cdp.test.js +0 -93
  799. package/dist/esm/tests/unit/flowlogger-capturing-cdp.test.js.map +0 -1
  800. package/dist/esm/tests/unit/flowlogger-capturing-llm.test.d.ts +0 -1
  801. package/dist/esm/tests/unit/flowlogger-capturing-llm.test.js +0 -41
  802. package/dist/esm/tests/unit/flowlogger-capturing-llm.test.js.map +0 -1
  803. package/dist/esm/tests/unit/flowlogger-eventstore.test.d.ts +0 -1
  804. package/dist/esm/tests/unit/flowlogger-eventstore.test.js +0 -248
  805. package/dist/esm/tests/unit/flowlogger-eventstore.test.js.map +0 -1
  806. package/dist/esm/tests/unit/frame-registry-oopif-adoption.test.d.ts +0 -1
  807. package/dist/esm/tests/unit/frame-registry-oopif-adoption.test.js +0 -58
  808. package/dist/esm/tests/unit/frame-registry-oopif-adoption.test.js.map +0 -1
  809. package/dist/esm/tests/unit/helpers/mockCDPSession.d.ts +0 -19
  810. package/dist/esm/tests/unit/helpers/mockCDPSession.js +0 -25
  811. package/dist/esm/tests/unit/helpers/mockCDPSession.js.map +0 -1
  812. package/dist/esm/tests/unit/inference-temperature.test.d.ts +0 -1
  813. package/dist/esm/tests/unit/inference-temperature.test.js +0 -63
  814. package/dist/esm/tests/unit/inference-temperature.test.js.map +0 -1
  815. package/dist/esm/tests/unit/llm-middleware.test.d.ts +0 -1
  816. package/dist/esm/tests/unit/llm-middleware.test.js +0 -460
  817. package/dist/esm/tests/unit/llm-middleware.test.js.map +0 -1
  818. package/dist/esm/tests/unit/llm-provider.test.d.ts +0 -1
  819. package/dist/esm/tests/unit/llm-provider.test.js +0 -62
  820. package/dist/esm/tests/unit/llm-provider.test.js.map +0 -1
  821. package/dist/esm/tests/unit/microsoft-cua-client.test.d.ts +0 -1
  822. package/dist/esm/tests/unit/microsoft-cua-client.test.js +0 -84
  823. package/dist/esm/tests/unit/microsoft-cua-client.test.js.map +0 -1
  824. package/dist/esm/tests/unit/model-deprecation.test.d.ts +0 -1
  825. package/dist/esm/tests/unit/model-deprecation.test.js +0 -140
  826. package/dist/esm/tests/unit/model-deprecation.test.js.map +0 -1
  827. package/dist/esm/tests/unit/model-utils.test.d.ts +0 -1
  828. package/dist/esm/tests/unit/model-utils.test.js +0 -40
  829. package/dist/esm/tests/unit/model-utils.test.js.map +0 -1
  830. package/dist/esm/tests/unit/openai-compatible-temperature.test.d.ts +0 -1
  831. package/dist/esm/tests/unit/openai-compatible-temperature.test.js +0 -82
  832. package/dist/esm/tests/unit/openai-compatible-temperature.test.js.map +0 -1
  833. package/dist/esm/tests/unit/openai-cua-client.test.d.ts +0 -1
  834. package/dist/esm/tests/unit/openai-cua-client.test.js +0 -69
  835. package/dist/esm/tests/unit/openai-cua-client.test.js.map +0 -1
  836. package/dist/esm/tests/unit/page-extra-http-headers.test.d.ts +0 -1
  837. package/dist/esm/tests/unit/page-extra-http-headers.test.js +0 -90
  838. package/dist/esm/tests/unit/page-extra-http-headers.test.js.map +0 -1
  839. package/dist/esm/tests/unit/page-snapshot.test.d.ts +0 -1
  840. package/dist/esm/tests/unit/page-snapshot.test.js +0 -40
  841. package/dist/esm/tests/unit/page-snapshot.test.js.map +0 -1
  842. package/dist/esm/tests/unit/prompt-observe-variables.test.d.ts +0 -1
  843. package/dist/esm/tests/unit/prompt-observe-variables.test.js +0 -23
  844. package/dist/esm/tests/unit/prompt-observe-variables.test.js.map +0 -1
  845. package/dist/esm/tests/unit/public-api/export-surface.test.d.ts +0 -1
  846. package/dist/esm/tests/unit/public-api/export-surface.test.js +0 -72
  847. package/dist/esm/tests/unit/public-api/export-surface.test.js.map +0 -1
  848. package/dist/esm/tests/unit/public-api/llm-and-agents.test.d.ts +0 -1
  849. package/dist/esm/tests/unit/public-api/llm-and-agents.test.js +0 -144
  850. package/dist/esm/tests/unit/public-api/llm-and-agents.test.js.map +0 -1
  851. package/dist/esm/tests/unit/public-api/public-error-types.test.d.ts +0 -62
  852. package/dist/esm/tests/unit/public-api/public-error-types.test.js +0 -74
  853. package/dist/esm/tests/unit/public-api/public-error-types.test.js.map +0 -1
  854. package/dist/esm/tests/unit/public-api/public-types.test.d.ts +0 -1
  855. package/dist/esm/tests/unit/public-api/public-types.test.js +0 -97
  856. package/dist/esm/tests/unit/public-api/public-types.test.js.map +0 -1
  857. package/dist/esm/tests/unit/public-api/runtime-utils.test.d.ts +0 -1
  858. package/dist/esm/tests/unit/public-api/runtime-utils.test.js +0 -25
  859. package/dist/esm/tests/unit/public-api/runtime-utils.test.js.map +0 -1
  860. package/dist/esm/tests/unit/public-api/schema-utils.test.d.ts +0 -1
  861. package/dist/esm/tests/unit/public-api/schema-utils.test.js +0 -60
  862. package/dist/esm/tests/unit/public-api/schema-utils.test.js.map +0 -1
  863. package/dist/esm/tests/unit/public-api/timeout-error-types.test.d.ts +0 -1
  864. package/dist/esm/tests/unit/public-api/timeout-error-types.test.js +0 -86
  865. package/dist/esm/tests/unit/public-api/timeout-error-types.test.js.map +0 -1
  866. package/dist/esm/tests/unit/public-api/tool-type-export.test.d.ts +0 -1
  867. package/dist/esm/tests/unit/public-api/tool-type-export.test.js +0 -30
  868. package/dist/esm/tests/unit/public-api/tool-type-export.test.js.map +0 -1
  869. package/dist/esm/tests/unit/public-api/v3-core.test.d.ts +0 -1
  870. package/dist/esm/tests/unit/public-api/v3-core.test.js +0 -73
  871. package/dist/esm/tests/unit/public-api/v3-core.test.js.map +0 -1
  872. package/dist/esm/tests/unit/safety-confirmation.test.d.ts +0 -1
  873. package/dist/esm/tests/unit/safety-confirmation.test.js +0 -108
  874. package/dist/esm/tests/unit/safety-confirmation.test.js.map +0 -1
  875. package/dist/esm/tests/unit/snapshot-a11y-resolvers.test.d.ts +0 -1
  876. package/dist/esm/tests/unit/snapshot-a11y-resolvers.test.js +0 -396
  877. package/dist/esm/tests/unit/snapshot-a11y-resolvers.test.js.map +0 -1
  878. package/dist/esm/tests/unit/snapshot-a11y-tree-utils.test.d.ts +0 -1
  879. package/dist/esm/tests/unit/snapshot-a11y-tree-utils.test.js +0 -304
  880. package/dist/esm/tests/unit/snapshot-a11y-tree-utils.test.js.map +0 -1
  881. package/dist/esm/tests/unit/snapshot-capture-orchestration.test.d.ts +0 -1
  882. package/dist/esm/tests/unit/snapshot-capture-orchestration.test.js +0 -469
  883. package/dist/esm/tests/unit/snapshot-capture-orchestration.test.js.map +0 -1
  884. package/dist/esm/tests/unit/snapshot-cbor.test.d.ts +0 -1
  885. package/dist/esm/tests/unit/snapshot-cbor.test.js +0 -202
  886. package/dist/esm/tests/unit/snapshot-cbor.test.js.map +0 -1
  887. package/dist/esm/tests/unit/snapshot-dom-session-builders.test.d.ts +0 -1
  888. package/dist/esm/tests/unit/snapshot-dom-session-builders.test.js +0 -218
  889. package/dist/esm/tests/unit/snapshot-dom-session-builders.test.js.map +0 -1
  890. package/dist/esm/tests/unit/snapshot-dom-tree-utils.test.d.ts +0 -1
  891. package/dist/esm/tests/unit/snapshot-dom-tree-utils.test.js +0 -105
  892. package/dist/esm/tests/unit/snapshot-dom-tree-utils.test.js.map +0 -1
  893. package/dist/esm/tests/unit/snapshot-focus-selectors-utils.test.d.ts +0 -1
  894. package/dist/esm/tests/unit/snapshot-focus-selectors-utils.test.js +0 -87
  895. package/dist/esm/tests/unit/snapshot-focus-selectors-utils.test.js.map +0 -1
  896. package/dist/esm/tests/unit/snapshot-frame-merge.test.d.ts +0 -1
  897. package/dist/esm/tests/unit/snapshot-frame-merge.test.js +0 -333
  898. package/dist/esm/tests/unit/snapshot-frame-merge.test.js.map +0 -1
  899. package/dist/esm/tests/unit/snapshot-tree-format-utils.test.d.ts +0 -1
  900. package/dist/esm/tests/unit/snapshot-tree-format-utils.test.js +0 -82
  901. package/dist/esm/tests/unit/snapshot-tree-format-utils.test.js.map +0 -1
  902. package/dist/esm/tests/unit/snapshot-xpath-utils.test.d.ts +0 -1
  903. package/dist/esm/tests/unit/snapshot-xpath-utils.test.js +0 -72
  904. package/dist/esm/tests/unit/snapshot-xpath-utils.test.js.map +0 -1
  905. package/dist/esm/tests/unit/timeout-handlers.test.d.ts +0 -1
  906. package/dist/esm/tests/unit/timeout-handlers.test.js +0 -862
  907. package/dist/esm/tests/unit/timeout-handlers.test.js.map +0 -1
  908. package/dist/esm/tests/unit/understudy-command-exception.test.d.ts +0 -1
  909. package/dist/esm/tests/unit/understudy-command-exception.test.js +0 -55
  910. package/dist/esm/tests/unit/understudy-command-exception.test.js.map +0 -1
  911. package/dist/esm/tests/unit/xpath-parser.test.d.ts +0 -1
  912. package/dist/esm/tests/unit/xpath-parser.test.js +0 -309
  913. package/dist/esm/tests/unit/xpath-parser.test.js.map +0 -1
  914. package/dist/esm/tests/unit/xpath-resolver.test.d.ts +0 -1
  915. package/dist/esm/tests/unit/xpath-resolver.test.js +0 -78
  916. package/dist/esm/tests/unit/xpath-resolver.test.js.map +0 -1
  917. package/dist/esm/tests/unit/zod-enum-compatibility.test.d.ts +0 -1
  918. package/dist/esm/tests/unit/zod-enum-compatibility.test.js +0 -114
  919. package/dist/esm/tests/unit/zod-enum-compatibility.test.js.map +0 -1
@@ -0,0 +1,219 @@
1
+ "use strict";
2
+ /**
3
+ * Legacy V3 evaluator implementation.
4
+ *
5
+ * This is the behavior-preserving implementation that backs V3Evaluator when
6
+ * STAGEHAND_EVALUATOR_BACKEND=legacy.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.LegacyV3Evaluator = void 0;
10
+ const zod_1 = require("zod");
11
+ const LLMProvider_js_1 = require("./v3/llm/LLMProvider.js");
12
+ const sdkErrors_js_1 = require("./v3/types/public/sdkErrors.js");
13
+ const EvaluationSchema = zod_1.z.object({
14
+ evaluation: zod_1.z.enum(["YES", "NO"]),
15
+ reasoning: zod_1.z.string(),
16
+ });
17
+ const BatchEvaluationSchema = zod_1.z.array(EvaluationSchema);
18
+ class LegacyV3Evaluator {
19
+ v3;
20
+ modelName;
21
+ modelClientOptions;
22
+ silentLogger = () => { };
23
+ constructor(v3, modelName, modelClientOptions) {
24
+ this.v3 = v3;
25
+ this.modelName = modelName || "google/gemini-2.5-flash";
26
+ this.modelClientOptions = modelClientOptions || {
27
+ apiKey: process.env.GEMINI_API_KEY ||
28
+ process.env.GOOGLE_GENERATIVE_AI_API_KEY ||
29
+ "",
30
+ };
31
+ }
32
+ getClient() {
33
+ // Prefer a dedicated provider so we can override model per-evaluation
34
+ const provider = new LLMProvider_js_1.LLMProvider(this.v3.logger);
35
+ return provider.getClient(this.modelName, this.modelClientOptions);
36
+ }
37
+ async ask(options) {
38
+ const { question, answer, screenshot = true, systemPrompt, screenshotDelayMs = 250, agentReasoning, } = options;
39
+ if (!question)
40
+ throw new sdkErrors_js_1.StagehandInvalidArgumentError("Question cannot be an empty string");
41
+ if (!answer && !screenshot)
42
+ throw new sdkErrors_js_1.StagehandInvalidArgumentError("Either answer (text) or screenshot must be provided");
43
+ if (Array.isArray(screenshot)) {
44
+ return this._evaluateWithMultipleScreenshots({
45
+ question,
46
+ answer,
47
+ screenshots: screenshot,
48
+ systemPrompt,
49
+ agentReasoning,
50
+ });
51
+ }
52
+ const defaultSystemPrompt = `You are an expert evaluator that confidently returns YES or NO based on if the original goal was achieved. You have access to ${screenshot ? "a screenshot" : "the agents reasoning and actions throughout the task"} that you can use to evaluate the tasks completion. Provide detailed reasoning for your answer.\n Today's date is ${new Date().toLocaleDateString()}`;
53
+ await new Promise((r) => setTimeout(r, screenshotDelayMs));
54
+ let imageBuffer;
55
+ if (screenshot) {
56
+ const page = await this.v3.context.awaitActivePage();
57
+ imageBuffer = await page.screenshot({ fullPage: false });
58
+ }
59
+ const llmClient = this.getClient();
60
+ const response = await llmClient.createChatCompletion({
61
+ logger: this.silentLogger,
62
+ options: {
63
+ messages: [
64
+ { role: "system", content: systemPrompt || defaultSystemPrompt },
65
+ {
66
+ role: "user",
67
+ content: [
68
+ {
69
+ type: "text",
70
+ text: agentReasoning
71
+ ? `Question: ${question}\n\nAgent's reasoning and actions taken:\n${agentReasoning}`
72
+ : question,
73
+ },
74
+ ...(screenshot && imageBuffer
75
+ ? [
76
+ {
77
+ type: "image_url",
78
+ image_url: {
79
+ url: `data:image/jpeg;base64,${imageBuffer.toString("base64")}`,
80
+ },
81
+ },
82
+ ]
83
+ : []),
84
+ ...(answer
85
+ ? [{ type: "text", text: `the answer is ${answer}` }]
86
+ : []),
87
+ ],
88
+ },
89
+ ],
90
+ response_model: { name: "EvaluationResult", schema: EvaluationSchema },
91
+ },
92
+ });
93
+ try {
94
+ const result = response.data;
95
+ return { evaluation: result.evaluation, reasoning: result.reasoning };
96
+ }
97
+ catch (error) {
98
+ const errorMessage = error instanceof Error ? error.message : String(error);
99
+ return {
100
+ evaluation: "INVALID",
101
+ reasoning: `Failed to get structured response: ${errorMessage}`,
102
+ };
103
+ }
104
+ }
105
+ async batchAsk(options) {
106
+ const { questions, screenshot = true, systemPrompt = "You are an expert evaluator that returns YES or NO with a concise reasoning.", screenshotDelayMs = 250, } = options;
107
+ if (!questions?.length)
108
+ throw new sdkErrors_js_1.StagehandInvalidArgumentError("Questions array cannot be empty");
109
+ await new Promise((r) => setTimeout(r, screenshotDelayMs));
110
+ let imageBuffer;
111
+ if (screenshot) {
112
+ const page = await this.v3.context.awaitActivePage();
113
+ imageBuffer = await page.screenshot({ fullPage: false });
114
+ }
115
+ const llmClient = this.getClient();
116
+ const formatted = questions
117
+ .map((item, i) => `${i + 1}. ${item.question}${item.answer ? `\n Answer: ${item.answer}` : ""}`)
118
+ .join("\n\n");
119
+ const response = await llmClient.createChatCompletion({
120
+ logger: this.silentLogger,
121
+ options: {
122
+ messages: [
123
+ {
124
+ role: "system",
125
+ content: `${systemPrompt}\n\nYou will be given multiple questions${screenshot ? " with a screenshot" : ""}. ${questions.some((q) => q.answer) ? "Some questions include answers to evaluate." : ""} Answer each question by returning an object in the specified JSON format. Return a single JSON array containing one object for each question in the order they were asked.`,
126
+ },
127
+ {
128
+ role: "user",
129
+ content: [
130
+ { type: "text", text: formatted },
131
+ ...(screenshot && imageBuffer
132
+ ? [
133
+ {
134
+ type: "image_url",
135
+ image_url: {
136
+ url: `data:image/jpeg;base64,${imageBuffer.toString("base64")}`,
137
+ },
138
+ },
139
+ ]
140
+ : []),
141
+ ],
142
+ },
143
+ ],
144
+ response_model: {
145
+ name: "BatchEvaluationResult",
146
+ schema: BatchEvaluationSchema,
147
+ },
148
+ },
149
+ });
150
+ try {
151
+ const results = response.data;
152
+ return results.map((r) => ({
153
+ evaluation: r.evaluation,
154
+ reasoning: r.reasoning,
155
+ }));
156
+ }
157
+ catch (error) {
158
+ const errorMessage = error instanceof Error ? error.message : String(error);
159
+ return questions.map(() => ({
160
+ evaluation: "INVALID",
161
+ reasoning: `Failed to get structured response: ${errorMessage}`,
162
+ }));
163
+ }
164
+ }
165
+ async _evaluateWithMultipleScreenshots(options) {
166
+ const { question, answer, screenshots, agentReasoning, systemPrompt = `You are an expert evaluator that confidently returns YES or NO given a question and multiple screenshots showing the progression of a task.
167
+ ${agentReasoning ? "You also have access to the agent's detailed reasoning and thought process throughout the task." : ""}
168
+ Analyze ALL screenshots to understand the complete journey. Look for evidence of task completion across all screenshots, not just the last one.
169
+ Success criteria may appear at different points in the sequence (confirmation messages, intermediate states, etc).
170
+ ${agentReasoning ? "The agent's reasoning provides crucial context about what actions were attempted, what was observed, and the decision-making process. Use this alongside the visual evidence to make a comprehensive evaluation." : ""}
171
+ Today's date is ${new Date().toLocaleDateString()}`, } = options;
172
+ if (!question)
173
+ throw new sdkErrors_js_1.StagehandInvalidArgumentError("Question cannot be an empty string");
174
+ if (!screenshots || screenshots.length === 0)
175
+ throw new sdkErrors_js_1.StagehandInvalidArgumentError("At least one screenshot must be provided");
176
+ const llmClient = this.getClient();
177
+ const imageContents = screenshots.map((s) => ({
178
+ type: "image_url",
179
+ image_url: { url: `data:image/jpeg;base64,${s.toString("base64")}` },
180
+ }));
181
+ const response = await llmClient.createChatCompletion({
182
+ logger: this.silentLogger,
183
+ options: {
184
+ messages: [
185
+ { role: "system", content: systemPrompt },
186
+ {
187
+ role: "user",
188
+ content: [
189
+ {
190
+ type: "text",
191
+ text: agentReasoning
192
+ ? `Question: ${question}\n\nAgent's reasoning and actions throughout the task:\n${agentReasoning}\n\nI'm providing ${screenshots.length} screenshots showing the progression of the task. Please analyze both the agent's reasoning and all screenshots to determine if the task was completed successfully.`
193
+ : `${question}\n\nI'm providing ${screenshots.length} screenshots showing the progression of the task. Please analyze all of them to determine if the task was completed successfully.`,
194
+ },
195
+ ...(answer
196
+ ? [{ type: "text", text: `the answer is ${answer}` }]
197
+ : []),
198
+ ...imageContents,
199
+ ],
200
+ },
201
+ ],
202
+ response_model: { name: "EvaluationResult", schema: EvaluationSchema },
203
+ },
204
+ });
205
+ try {
206
+ const result = response.data;
207
+ return { evaluation: result.evaluation, reasoning: result.reasoning };
208
+ }
209
+ catch (error) {
210
+ const errorMessage = error instanceof Error ? error.message : String(error);
211
+ return {
212
+ evaluation: "INVALID",
213
+ reasoning: `Failed to get structured response: ${errorMessage}`,
214
+ };
215
+ }
216
+ }
217
+ }
218
+ exports.LegacyV3Evaluator = LegacyV3Evaluator;
219
+ //# sourceMappingURL=v3LegacyEvaluator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"v3LegacyEvaluator.js","sourceRoot":"","sources":["../../../lib/v3LegacyEvaluator.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,6BAAwB;AAWxB,4DAAsD;AACtD,iEAA+E;AAE/E,MAAM,gBAAgB,GAAG,OAAC,CAAC,MAAM,CAAC;IAChC,UAAU,EAAE,OAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACjC,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE;CACtB,CAAC,CAAC;AAEH,MAAM,qBAAqB,GAAG,OAAC,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;AAExD,MAAa,iBAAiB;IACpB,EAAE,CAAK;IACP,SAAS,CAAiB;IAC1B,kBAAkB,CAAqC;IACvD,YAAY,GAA+B,GAAG,EAAE,GAAE,CAAC,CAAC;IAE5D,YACE,EAAM,EACN,SAA0B,EAC1B,kBAAkC;QAElC,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,SAA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B,OAAO,EAAE;gBACP,QAAQ,EAAE;oBACR,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE;oBACzC;wBACE,IAAI,EAAE,MAAM;wBACZ,OAAO,EAAE;4BACP;gCACE,IAAI,EAAE,MAAM;gCACZ,IAAI,EAAE,cAAc;oCAClB,CAAC,CAAC,aAAa,QAAQ,2DAA2D,cAAc,qBAAqB,WAAW,CAAC,MAAM,sKAAsK;oCAC7S,CAAC,CAAC,GAAG,QAAQ,qBAAqB,WAAW,CAAC,MAAM,mIAAmI;6BAC1L;4BACD,GAAG,CAAC,MAAM;gCACR,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,iBAAiB,MAAM,EAAE,EAAE,CAAC;gCAC9D,CAAC,CAAC,EAAE,CAAC;4BACP,GAAG,aAAa;yBACjB;qBACF;iBACF;gBACD,cAAc,EAAE,EAAE,IAAI,EAAE,kBAAkB,EAAE,MAAM,EAAE,gBAAgB,EAAE;aACvE;SACF,CAAC,CAAC;QAEH,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,QAAQ,CAAC,IAEvB,CAAC;YACF,OAAO,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC;QACxE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,YAAY,GAChB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACzD,OAAO;gBACL,UAAU,EAAE,SAAS;gBACrB,SAAS,EAAE,sCAAsC,YAAY,EAAE;aACvD,CAAC;QACb,CAAC;IACH,CAAC;CACF;AAlRD,8CAkRC","sourcesContent":["/**\n * Legacy V3 evaluator implementation.\n *\n * This is the behavior-preserving implementation that backs V3Evaluator when\n * STAGEHAND_EVALUATOR_BACKEND=legacy.\n */\n\nimport { z } from \"zod\";\nimport type { AvailableModel, ClientOptions } from \"./v3/types/public/model.js\";\nimport type {\n EvaluateOptions,\n BatchAskOptions,\n EvaluationResult,\n} from \"./v3/types/private/evaluator.js\";\nimport { LLMParsedResponse } from \"./inference.js\";\nimport { LLMResponse, LLMClient } from \"./v3/llm/LLMClient.js\";\nimport { LogLine } from \"./v3/types/public/logs.js\";\nimport { V3 } from \"./v3/v3.js\";\nimport { LLMProvider } from \"./v3/llm/LLMProvider.js\";\nimport { StagehandInvalidArgumentError } from \"./v3/types/public/sdkErrors.js\";\n\nconst EvaluationSchema = z.object({\n evaluation: z.enum([\"YES\", \"NO\"]),\n reasoning: z.string(),\n});\n\nconst BatchEvaluationSchema = z.array(EvaluationSchema);\n\nexport class LegacyV3Evaluator {\n private v3: V3;\n private modelName: AvailableModel;\n private modelClientOptions: ClientOptions | { apiKey: string };\n private silentLogger: (message: LogLine) => void = () => {};\n\n constructor(\n v3: V3,\n modelName?: AvailableModel,\n modelClientOptions?: ClientOptions,\n ) {\n this.v3 = v3;\n this.modelName = modelName || (\"google/gemini-2.5-flash\" as AvailableModel);\n this.modelClientOptions = modelClientOptions || {\n apiKey:\n process.env.GEMINI_API_KEY ||\n process.env.GOOGLE_GENERATIVE_AI_API_KEY ||\n \"\",\n };\n }\n\n private getClient(): LLMClient {\n // Prefer a dedicated provider so we can override model per-evaluation\n const provider = new LLMProvider(this.v3.logger);\n return provider.getClient(this.modelName, this.modelClientOptions);\n }\n\n async ask(options: EvaluateOptions): Promise<EvaluationResult> {\n const {\n question,\n answer,\n screenshot = true,\n systemPrompt,\n screenshotDelayMs = 250,\n agentReasoning,\n } = options;\n if (!question)\n throw new StagehandInvalidArgumentError(\n \"Question cannot be an empty string\",\n );\n if (!answer && !screenshot)\n throw new StagehandInvalidArgumentError(\n \"Either answer (text) or screenshot must be provided\",\n );\n\n if (Array.isArray(screenshot)) {\n return this._evaluateWithMultipleScreenshots({\n question,\n answer,\n screenshots: screenshot,\n systemPrompt,\n agentReasoning,\n });\n }\n\n const defaultSystemPrompt = `You are an expert evaluator that confidently returns YES or NO based on if the original goal was achieved. You have access to ${screenshot ? \"a screenshot\" : \"the agents reasoning and actions throughout the task\"} that you can use to evaluate the tasks completion. Provide detailed reasoning for your answer.\\n Today's date is ${new Date().toLocaleDateString()}`;\n\n await new Promise((r) => setTimeout(r, screenshotDelayMs));\n let imageBuffer: Buffer | undefined;\n if (screenshot) {\n const page = await this.v3.context.awaitActivePage();\n imageBuffer = await page.screenshot({ fullPage: false });\n }\n\n const llmClient = this.getClient();\n\n const response = await llmClient.createChatCompletion<\n LLMParsedResponse<LLMResponse>\n >({\n logger: this.silentLogger,\n options: {\n messages: [\n { role: \"system\", content: systemPrompt || defaultSystemPrompt },\n {\n role: \"user\",\n content: [\n {\n type: \"text\",\n text: agentReasoning\n ? `Question: ${question}\\n\\nAgent's reasoning and actions taken:\\n${agentReasoning}`\n : question,\n },\n ...(screenshot && imageBuffer\n ? [\n {\n type: \"image_url\" as const,\n image_url: {\n url: `data:image/jpeg;base64,${imageBuffer.toString(\"base64\")}`,\n },\n },\n ]\n : []),\n ...(answer\n ? [{ type: \"text\" as const, text: `the answer is ${answer}` }]\n : []),\n ],\n },\n ],\n response_model: { name: \"EvaluationResult\", schema: EvaluationSchema },\n },\n });\n\n try {\n const result = response.data as unknown as z.infer<\n typeof EvaluationSchema\n >;\n return { evaluation: result.evaluation, reasoning: result.reasoning };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n return {\n evaluation: \"INVALID\",\n reasoning: `Failed to get structured response: ${errorMessage}`,\n } as const;\n }\n }\n\n async batchAsk(options: BatchAskOptions): Promise<EvaluationResult[]> {\n const {\n questions,\n screenshot = true,\n systemPrompt = \"You are an expert evaluator that returns YES or NO with a concise reasoning.\",\n screenshotDelayMs = 250,\n } = options;\n if (!questions?.length)\n throw new StagehandInvalidArgumentError(\n \"Questions array cannot be empty\",\n );\n\n await new Promise((r) => setTimeout(r, screenshotDelayMs));\n let imageBuffer: Buffer | undefined;\n if (screenshot) {\n const page = await this.v3.context.awaitActivePage();\n imageBuffer = await page.screenshot({ fullPage: false });\n }\n\n const llmClient = this.getClient();\n\n const formatted = questions\n .map(\n (item, i) =>\n `${i + 1}. ${item.question}${item.answer ? `\\n Answer: ${item.answer}` : \"\"}`,\n )\n .join(\"\\n\\n\");\n\n const response = await llmClient.createChatCompletion<\n LLMParsedResponse<LLMResponse>\n >({\n logger: this.silentLogger,\n options: {\n messages: [\n {\n role: \"system\",\n content: `${systemPrompt}\\n\\nYou will be given multiple questions${screenshot ? \" with a screenshot\" : \"\"}. ${questions.some((q) => q.answer) ? \"Some questions include answers to evaluate.\" : \"\"} Answer each question by returning an object in the specified JSON format. Return a single JSON array containing one object for each question in the order they were asked.`,\n },\n {\n role: \"user\",\n content: [\n { type: \"text\", text: formatted },\n ...(screenshot && imageBuffer\n ? [\n {\n type: \"image_url\" as const,\n image_url: {\n url: `data:image/jpeg;base64,${imageBuffer.toString(\"base64\")}`,\n },\n },\n ]\n : []),\n ],\n },\n ],\n response_model: {\n name: \"BatchEvaluationResult\",\n schema: BatchEvaluationSchema,\n },\n },\n });\n\n try {\n const results = response.data as unknown as z.infer<\n typeof BatchEvaluationSchema\n >;\n return results.map((r) => ({\n evaluation: r.evaluation,\n reasoning: r.reasoning,\n }));\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n return questions.map(() => ({\n evaluation: \"INVALID\" as const,\n reasoning: `Failed to get structured response: ${errorMessage}`,\n }));\n }\n }\n\n private async _evaluateWithMultipleScreenshots(options: {\n question: string;\n answer?: string;\n screenshots: Buffer[];\n systemPrompt?: string;\n agentReasoning?: string;\n }): Promise<EvaluationResult> {\n const {\n question,\n answer,\n screenshots,\n agentReasoning,\n systemPrompt = `You are an expert evaluator that confidently returns YES or NO given a question and multiple screenshots showing the progression of a task.\n ${agentReasoning ? \"You also have access to the agent's detailed reasoning and thought process throughout the task.\" : \"\"}\n Analyze ALL screenshots to understand the complete journey. Look for evidence of task completion across all screenshots, not just the last one.\n Success criteria may appear at different points in the sequence (confirmation messages, intermediate states, etc).\n ${agentReasoning ? \"The agent's reasoning provides crucial context about what actions were attempted, what was observed, and the decision-making process. Use this alongside the visual evidence to make a comprehensive evaluation.\" : \"\"}\n Today's date is ${new Date().toLocaleDateString()}`,\n } = options;\n\n if (!question)\n throw new StagehandInvalidArgumentError(\n \"Question cannot be an empty string\",\n );\n if (!screenshots || screenshots.length === 0)\n throw new StagehandInvalidArgumentError(\n \"At least one screenshot must be provided\",\n );\n\n const llmClient = this.getClient();\n\n const imageContents = screenshots.map((s) => ({\n type: \"image_url\" as const,\n image_url: { url: `data:image/jpeg;base64,${s.toString(\"base64\")}` },\n }));\n\n const response = await llmClient.createChatCompletion<\n LLMParsedResponse<LLMResponse>\n >({\n logger: this.silentLogger,\n options: {\n messages: [\n { role: \"system\", content: systemPrompt },\n {\n role: \"user\",\n content: [\n {\n type: \"text\",\n text: agentReasoning\n ? `Question: ${question}\\n\\nAgent's reasoning and actions throughout the task:\\n${agentReasoning}\\n\\nI'm providing ${screenshots.length} screenshots showing the progression of the task. Please analyze both the agent's reasoning and all screenshots to determine if the task was completed successfully.`\n : `${question}\\n\\nI'm providing ${screenshots.length} screenshots showing the progression of the task. Please analyze all of them to determine if the task was completed successfully.`,\n },\n ...(answer\n ? [{ type: \"text\" as const, text: `the answer is ${answer}` }]\n : []),\n ...imageContents,\n ],\n },\n ],\n response_model: { name: \"EvaluationResult\", schema: EvaluationSchema },\n },\n });\n\n try {\n const result = response.data as unknown as z.infer<\n typeof EvaluationSchema\n >;\n return { evaluation: result.evaluation, reasoning: result.reasoning };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n return {\n evaluation: \"INVALID\",\n reasoning: `Failed to get structured response: ${errorMessage}`,\n } as const;\n }\n }\n}\n"]}
@@ -2,4 +2,4 @@
2
2
  * AUTO-GENERATED — DO NOT EDIT BY HAND
3
3
  * Run `pnpm run gen-version` to refresh.
4
4
  */
5
- export declare const STAGEHAND_VERSION: "3.3.0";
5
+ export declare const STAGEHAND_VERSION: "3.4.0";
@@ -5,5 +5,5 @@ exports.STAGEHAND_VERSION = void 0;
5
5
  * AUTO-GENERATED — DO NOT EDIT BY HAND
6
6
  * Run `pnpm run gen-version` to refresh.
7
7
  */
8
- exports.STAGEHAND_VERSION = "3.3.0";
8
+ exports.STAGEHAND_VERSION = "3.4.0";
9
9
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../../lib/version.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACU,QAAA,iBAAiB,GAAG,OAAgB,CAAC","sourcesContent":["/**\n * AUTO-GENERATED — DO NOT EDIT BY HAND\n * Run `pnpm run gen-version` to refresh.\n */\nexport const STAGEHAND_VERSION = \"3.3.0\" as const;\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../../lib/version.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACU,QAAA,iBAAiB,GAAG,OAAgB,CAAC","sourcesContent":["/**\n * AUTO-GENERATED — DO NOT EDIT BY HAND\n * Run `pnpm run gen-version` to refresh.\n */\nexport const STAGEHAND_VERSION = \"3.4.0\" as const;\n"]}
@@ -3,7 +3,7 @@ import { LLMClient } from "./v3/llm/LLMClient.js";
3
3
  import type { InferStagehandSchema, StagehandZodObject } from "./v3/zodCompat.js";
4
4
  import type { Variables } from "./v3/types/public/agent.js";
5
5
  export type { LLMParsedResponse, LLMUsage } from "./v3/llm/LLMClient.js";
6
- export declare function extract<T extends StagehandZodObject>({ instruction, domElements, schema, llmClient, logger, userProvidedInstructions, logInferenceToFile, }: {
6
+ export declare function extract<T extends StagehandZodObject>({ instruction, domElements, schema, llmClient, logger, userProvidedInstructions, logInferenceToFile, screenshot, }: {
7
7
  instruction: string;
8
8
  domElements: string;
9
9
  schema: T;
@@ -11,6 +11,7 @@ export declare function extract<T extends StagehandZodObject>({ instruction, dom
11
11
  userProvidedInstructions?: string;
12
12
  logger: (message: LogLine) => void;
13
13
  logInferenceToFile?: boolean;
14
+ screenshot?: Buffer;
14
15
  }): Promise<InferStagehandSchema<T> & {
15
16
  metadata: {
16
17
  completed: boolean;
@@ -3,10 +3,11 @@ import { getEnvTimeoutMs, withTimeout } from "./v3/timeoutConfig.js";
3
3
  import { buildActSystemPrompt, buildExtractSystemPrompt, buildExtractUserPrompt, buildMetadataPrompt, buildMetadataSystemPrompt, buildObserveSystemPrompt, buildObserveUserMessage, } from "./prompt.js";
4
4
  import { appendSummary, writeTimestampedTxtFile } from "./inferenceLogUtils.js";
5
5
  import { SupportedUnderstudyAction } from "./v3/types/private/handlers.js";
6
+ import { StagehandInvalidArgumentError } from "./v3/types/public/sdkErrors.js";
6
7
  function withLlmTimeout(promise, operation) {
7
8
  return withTimeout(promise, getEnvTimeoutMs("LLM_MAX_MS"), `LLM ${operation}`);
8
9
  }
9
- export async function extract({ instruction, domElements, schema, llmClient, logger, userProvidedInstructions, logInferenceToFile = false, }) {
10
+ export async function extract({ instruction, domElements, schema, llmClient, logger, userProvidedInstructions, logInferenceToFile = false, screenshot, }) {
10
11
  const metadataSchema = z.object({
11
12
  progress: z
12
13
  .string()
@@ -16,9 +17,15 @@ export async function extract({ instruction, domElements, schema, llmClient, log
16
17
  .describe("true if the goal is now accomplished. Use this conservatively, only when sure that the goal has been completed."),
17
18
  });
18
19
  const isUsingAnthropic = llmClient.type === "anthropic";
20
+ if (screenshot && llmClient.type !== "aisdk") {
21
+ throw new StagehandInvalidArgumentError("extract({ screenshot: true }) is only supported with AI SDK clients.");
22
+ }
23
+ const screenshotDataUrl = screenshot
24
+ ? `data:image/png;base64,${screenshot.toString("base64")}`
25
+ : undefined;
19
26
  const extractCallMessages = [
20
- buildExtractSystemPrompt(isUsingAnthropic, userProvidedInstructions),
21
- buildExtractUserPrompt(instruction, domElements, isUsingAnthropic),
27
+ buildExtractSystemPrompt(isUsingAnthropic, userProvidedInstructions, Boolean(screenshotDataUrl)),
28
+ buildExtractUserPrompt(instruction, domElements, isUsingAnthropic, screenshotDataUrl),
22
29
  ];
23
30
  let extractCallFile = "";
24
31
  let extractCallTimestamp = "";
@@ -1 +1 @@
1
- {"version":3,"file":"inference.js","sourceRoot":"","sources":["../../../lib/inference.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACxB,sBAAsB,EACtB,mBAAmB,EACnB,yBAAyB,EACzB,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAKhF,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAM3E,SAAS,cAAc,CAAI,OAAmB,EAAE,SAAiB;IAC/D,OAAO,WAAW,CAChB,OAAO,EACP,eAAe,CAAC,YAAY,CAAC,EAC7B,OAAO,SAAS,EAAE,CACnB,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,OAAO,CAA+B,EAC1D,WAAW,EACX,WAAW,EACX,MAAM,EACN,SAAS,EACT,MAAM,EACN,wBAAwB,EACxB,kBAAkB,GAAG,KAAK,GAS3B;IACC,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;QAC9B,QAAQ,EAAE,CAAC;aACR,MAAM,EAAE;aACR,QAAQ,CACP,oEAAoE,CACrE;QACH,SAAS,EAAE,CAAC;aACT,OAAO,EAAE;aACT,QAAQ,CACP,iHAAiH,CAClH;KACJ,CAAC,CAAC;IAKH,MAAM,gBAAgB,GAAG,SAAS,CAAC,IAAI,KAAK,WAAW,CAAC;IAExD,MAAM,mBAAmB,GAAkB;QACzC,wBAAwB,CAAC,gBAAgB,EAAE,wBAAwB,CAAC;QACpE,sBAAs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AO,CAAC,MAAM,CAAC,SAAS;YACnC,WAAW,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC;YAC/C,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC;YACrC,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,SAAS;SACpC;QACH,CAAC,CAAC,SAAS,CAAC;IAEd,OAAO;QACL,OAAO,EAAE,aAAa;QACtB,aAAa,EAAE,YAAY;QAC3B,iBAAiB,EAAE,gBAAgB;QACnC,gBAAgB,EAAE,eAAe;QACjC,mBAAmB,EAAE,iBAAiB;QACtC,iBAAiB,EAAE,WAAW;QAC9B,OAAO,EAAE,OAAO,CAAC,OAAO;KACzB,CAAC;AACJ,CAAC","sourcesContent":["import { z } from \"zod\";\nimport { LogLine } from \"./v3/types/public/logs.js\";\nimport { ChatMessage, LLMClient } from \"./v3/llm/LLMClient.js\";\nimport { getEnvTimeoutMs, withTimeout } from \"./v3/timeoutConfig.js\";\nimport {\n buildActSystemPrompt,\n buildExtractSystemPrompt,\n buildExtractUserPrompt,\n buildMetadataPrompt,\n buildMetadataSystemPrompt,\n buildObserveSystemPrompt,\n buildObserveUserMessage,\n} from \"./prompt.js\";\nimport { appendSummary, writeTimestampedTxtFile } from \"./inferenceLogUtils.js\";\nimport type {\n InferStagehandSchema,\n StagehandZodObject,\n} from \"./v3/zodCompat.js\";\nimport { SupportedUnderstudyAction } from \"./v3/types/private/handlers.js\";\nimport type { Variables } from \"./v3/types/public/agent.js\";\n\n// Re-export for backward compatibility\nexport type { LLMParsedResponse, LLMUsage } from \"./v3/llm/LLMClient.js\";\n\nfunction withLlmTimeout<T>(promise: Promise<T>, operation: string): Promise<T> {\n return withTimeout(\n promise,\n getEnvTimeoutMs(\"LLM_MAX_MS\"),\n `LLM ${operation}`,\n );\n}\n\nexport async function extract<T extends StagehandZodObject>({\n instruction,\n domElements,\n schema,\n llmClient,\n logger,\n userProvidedInstructions,\n logInferenceToFile = false,\n}: {\n instruction: string;\n domElements: string;\n schema: T;\n llmClient: LLMClient;\n userProvidedInstructions?: string;\n logger: (message: LogLine) => void;\n logInferenceToFile?: boolean;\n}) {\n const metadataSchema = z.object({\n progress: z\n .string()\n .describe(\n \"progress of what has been extracted so far, as concise as possible\",\n ),\n completed: z\n .boolean()\n .describe(\n \"true if the goal is now accomplished. Use this conservatively, only when sure that the goal has been completed.\",\n ),\n });\n\n type ExtractionResponse = InferStagehandSchema<T>;\n type MetadataResponse = z.infer<typeof metadataSchema>;\n\n const isUsingAnthropic = llmClient.type === \"anthropic\";\n\n const extractCallMessages: ChatMessage[] = [\n buildExtractSystemPrompt(isUsingAnthropic, userProvidedInstructions),\n buildExtractUserPrompt(instruction, domElements, isUsingAnthropic),\n ];\n\n let extractCallFile = \"\";\n let extractCallTimestamp = \"\";\n if (logInferenceToFile) {\n const { fileName, timestamp } = writeTimestampedTxtFile(\n \"extract_summary\",\n \"extract_call\",\n {\n modelCall: \"extract\",\n messages: extractCallMessages,\n },\n );\n extractCallFile = fileName;\n extractCallTimestamp = timestamp;\n }\n\n const extractStartTime = Date.now();\n const extractionResponse = await withLlmTimeout(\n llmClient.createChatCompletion<ExtractionResponse>({\n options: {\n messages: extractCallMessages,\n response_model: {\n schema,\n name: \"Extraction\",\n },\n top_p: 1,\n frequency_penalty: 0,\n presence_penalty: 0,\n },\n logger,\n }),\n \"extract\",\n );\n const extractEndTime = Date.now();\n\n const { data: extractedData, usage: extractUsage } = extractionResponse;\n\n let extractResponseFile: string;\n if (logInferenceToFile) {\n const { fileName } = writeTimestampedTxtFile(\n \"extract_summary\",\n \"extract_response\",\n {\n modelResponse: \"extract\",\n rawResponse: extractedData,\n },\n );\n extractResponseFile = fileName;\n\n appendSummary(\"extract\", {\n extract_inference_type: \"extract\",\n timestamp: extractCallTimestamp,\n LLM_input_file: extractCallFile,\n LLM_output_file: extractResponseFile,\n prompt_tokens: extractUsage?.prompt_tokens ?? 0,\n completion_tokens: extractUsage?.completion_tokens ?? 0,\n reasoning_tokens: extractUsage?.reasoning_tokens ?? 0,\n cached_input_tokens: extractUsage?.cached_input_tokens ?? 0,\n inference_time_ms: extractEndTime - extractStartTime,\n });\n }\n\n const metadataCallMessages: ChatMessage[] = [\n buildMetadataSystemPrompt(),\n buildMetadataPrompt(instruction, extractedData),\n ];\n\n let metadataCallFile = \"\";\n let metadataCallTimestamp = \"\";\n if (logInferenceToFile) {\n const { fileName, timestamp } = writeTimestampedTxtFile(\n \"extract_summary\",\n \"metadata_call\",\n {\n modelCall: \"metadata\",\n messages: metadataCallMessages,\n },\n );\n metadataCallFile = fileName;\n metadataCallTimestamp = timestamp;\n }\n\n const metadataStartTime = Date.now();\n const metadataResponse = await withLlmTimeout(\n llmClient.createChatCompletion<MetadataResponse>({\n options: {\n messages: metadataCallMessages,\n response_model: {\n name: \"Metadata\",\n schema: metadataSchema,\n },\n top_p: 1,\n frequency_penalty: 0,\n presence_penalty: 0,\n },\n logger,\n }),\n \"extract metadata\",\n );\n const metadataEndTime = Date.now();\n\n const {\n data: {\n completed: metadataResponseCompleted,\n progress: metadataResponseProgress,\n },\n usage: metadataResponseUsage,\n } = metadataResponse;\n\n let metadataResponseFile: string;\n if (logInferenceToFile) {\n const { fileName } = writeTimestampedTxtFile(\n \"extract_summary\",\n \"metadata_response\",\n {\n modelResponse: \"metadata\",\n completed: metadataResponseCompleted,\n progress: metadataResponseProgress,\n },\n );\n metadataResponseFile = fileName;\n\n appendSummary(\"extract\", {\n extract_inference_type: \"metadata\",\n timestamp: metadataCallTimestamp,\n LLM_input_file: metadataCallFile,\n LLM_output_file: metadataResponseFile,\n prompt_tokens: metadataResponseUsage?.prompt_tokens ?? 0,\n completion_tokens: metadataResponseUsage?.completion_tokens ?? 0,\n reasoning_tokens: metadataResponseUsage?.reasoning_tokens ?? 0,\n cached_input_tokens: metadataResponseUsage?.cached_input_tokens ?? 0,\n inference_time_ms: metadataEndTime - metadataStartTime,\n });\n }\n\n const totalPromptTokens =\n (extractUsage?.prompt_tokens ?? 0) +\n (metadataResponseUsage?.prompt_tokens ?? 0);\n\n const totalCompletionTokens =\n (extractUsage?.completion_tokens ?? 0) +\n (metadataResponseUsage?.completion_tokens ?? 0);\n\n const totalInferenceTimeMs =\n extractEndTime - extractStartTime + (metadataEndTime - metadataStartTime);\n const totalReasoningTokens =\n (extractUsage?.reasoning_tokens ?? 0) +\n (metadataResponseUsage?.reasoning_tokens ?? 0);\n const totalCachedInputTokens =\n (extractUsage?.cached_input_tokens ?? 0) +\n (metadataResponseUsage?.cached_input_tokens ?? 0);\n\n return {\n ...extractedData,\n metadata: {\n completed: metadataResponseCompleted,\n progress: metadataResponseProgress,\n },\n prompt_tokens: totalPromptTokens,\n completion_tokens: totalCompletionTokens,\n reasoning_tokens: totalReasoningTokens,\n cached_input_tokens: totalCachedInputTokens,\n inference_time_ms: totalInferenceTimeMs,\n };\n}\n\nexport async function observe({\n instruction,\n domElements,\n llmClient,\n userProvidedInstructions,\n logger,\n logInferenceToFile = false,\n supportedActions,\n variables,\n}: {\n instruction: string;\n domElements: string;\n llmClient: LLMClient;\n userProvidedInstructions?: string;\n logger: (message: LogLine) => void;\n logInferenceToFile?: boolean;\n supportedActions?: string[];\n variables?: Variables;\n}) {\n const observeSchema = z.object({\n elements: z\n .array(\n z.object({\n elementId: z\n .string()\n .regex(/^\\d+-\\d+$/)\n .describe(\n \"the exact ID string associated with the element. Never include surrounding square brackets. This field must follow the format of 'number-number'. For example, if the accessibility tree shows [0-18372], return '0-18372', not '18372'.\",\n ),\n description: z\n .string()\n .describe(\n \"a description of the accessible element and its purpose\",\n ),\n method: z\n .enum(\n // Use Object.values() for Zod v3 compatibility - z.enum() in v3 doesn't accept TypeScript enums directly\n Object.values(SupportedUnderstudyAction) as unknown as readonly [\n string,\n ...string[],\n ],\n )\n .describe(\n `the candidate method/action to interact with the element. Select one of the available Understudy interaction methods.`,\n ),\n arguments: z.array(\n z\n .string()\n .describe(\n \"the arguments to pass to the method. For example, for a click, the arguments are empty, but for a fill, the arguments are the value to fill in.\",\n ),\n ),\n }),\n )\n .describe(\"an array of accessible elements that match the instruction\"),\n });\n\n type ObserveResponse = z.infer<typeof observeSchema>;\n\n const messages: ChatMessage[] = [\n buildObserveSystemPrompt(\n userProvidedInstructions,\n supportedActions,\n variables,\n ),\n buildObserveUserMessage(instruction, domElements),\n ];\n\n let callTimestamp = \"\";\n let callFile = \"\";\n if (logInferenceToFile) {\n const { fileName, timestamp } = writeTimestampedTxtFile(\n `observe_summary`,\n `observe_call`,\n {\n modelCall: \"observe\",\n messages,\n },\n );\n callFile = fileName;\n callTimestamp = timestamp;\n }\n\n const start = Date.now();\n const rawResponse = await llmClient.createChatCompletion<ObserveResponse>({\n options: {\n messages,\n response_model: {\n schema: observeSchema,\n name: \"Observation\",\n },\n top_p: 1,\n frequency_penalty: 0,\n presence_penalty: 0,\n },\n logger,\n });\n const end = Date.now();\n const usageTimeMs = end - start;\n\n const { data: observeData, usage: observeUsage } = rawResponse;\n const promptTokens = observeUsage?.prompt_tokens ?? 0;\n const completionTokens = observeUsage?.completion_tokens ?? 0;\n const reasoningTokens = observeUsage?.reasoning_tokens ?? 0;\n const cachedInputTokens = observeUsage?.cached_input_tokens ?? 0;\n\n let responseFile: string;\n if (logInferenceToFile) {\n const { fileName: responseFileName } = writeTimestampedTxtFile(\n `observe_summary`,\n `observe_response`,\n {\n modelResponse: \"observe\",\n rawResponse: observeData,\n },\n );\n responseFile = responseFileName;\n\n appendSummary(\"observe\", {\n [`observe_inference_type`]: \"observe\",\n timestamp: callTimestamp,\n LLM_input_file: callFile,\n LLM_output_file: responseFile,\n prompt_tokens: promptTokens,\n completion_tokens: completionTokens,\n reasoning_tokens: reasoningTokens,\n cached_input_tokens: cachedInputTokens,\n inference_time_ms: usageTimeMs,\n });\n }\n\n const parsedElements =\n observeData.elements?.map((el) => {\n const base = {\n elementId: el.elementId,\n description: String(el.description),\n method: String(el.method),\n arguments: el.arguments,\n };\n return base;\n }) ?? [];\n\n return {\n elements: parsedElements,\n prompt_tokens: promptTokens,\n completion_tokens: completionTokens,\n reasoning_tokens: reasoningTokens,\n cached_input_tokens: cachedInputTokens,\n inference_time_ms: usageTimeMs,\n };\n}\n\nexport async function act({\n instruction,\n domElements,\n llmClient,\n userProvidedInstructions,\n logger,\n logInferenceToFile = false,\n}: {\n instruction: string;\n domElements: string;\n llmClient: LLMClient;\n userProvidedInstructions?: string;\n logger: (message: LogLine) => void;\n logInferenceToFile?: boolean;\n}) {\n const actSchema = z.object({\n action: z\n .object({\n elementId: z\n .string()\n .regex(/^\\d+-\\d+$/)\n .describe(\n \"the ID string associated with the element. Never include surrounding square brackets. This field must follow the format of 'number-number'. for example, '0-76' or '16-21'\",\n ),\n description: z\n .string()\n .describe(\"a description of the accessible element and its purpose\"),\n method: z\n .enum(\n // Use Object.values() for Zod v3 compatibility - z.enum() in v3 doesn't accept TypeScript enums directly\n Object.values(SupportedUnderstudyAction) as unknown as readonly [\n string,\n ...string[],\n ],\n )\n .describe(\n \"the candidate method/action to interact with the element. Select one of the available Understudy interaction methods.\",\n ),\n arguments: z.array(\n z\n .string()\n .describe(\n \"the arguments to pass to the method. For example, for a click, the arguments are empty, but for a fill, the arguments are the value to fill in.\",\n ),\n ),\n })\n .nullable()\n .describe(\n \"The element to act on. Return null if no element on the page matches the instruction — do NOT fabricate or guess an element, and never emit empty strings or placeholder values.\",\n ),\n twoStep: z.boolean(),\n });\n\n type ActResponse = z.infer<typeof actSchema>;\n\n const messages: ChatMessage[] = [\n buildActSystemPrompt(userProvidedInstructions),\n buildObserveUserMessage(instruction, domElements),\n ];\n\n let callTimestamp = \"\";\n let callFile = \"\";\n if (logInferenceToFile) {\n const { fileName, timestamp } = writeTimestampedTxtFile(\n `act_summary`,\n `act_call`,\n {\n modelCall: \"act\",\n messages,\n },\n );\n callFile = fileName;\n callTimestamp = timestamp;\n }\n\n const start = Date.now();\n const rawResponse = await llmClient.createChatCompletion<ActResponse>({\n options: {\n messages,\n response_model: {\n schema: actSchema,\n name: \"act\",\n },\n top_p: 1,\n frequency_penalty: 0,\n presence_penalty: 0,\n },\n logger,\n });\n const end = Date.now();\n const usageTimeMs = end - start;\n\n const { data: actData, usage: actUsage } = rawResponse;\n const promptTokens = actUsage?.prompt_tokens ?? 0;\n const completionTokens = actUsage?.completion_tokens ?? 0;\n const reasoningTokens = actUsage?.reasoning_tokens ?? 0;\n const cachedInputTokens = actUsage?.cached_input_tokens ?? 0;\n\n let responseFile: string;\n if (logInferenceToFile) {\n const { fileName: responseFileName } = writeTimestampedTxtFile(\n `act_summary`,\n `act_response`,\n {\n modelResponse: \"act\",\n rawResponse: actData,\n },\n );\n responseFile = responseFileName;\n\n appendSummary(\"act\", {\n [`act_inference_type`]: \"act\",\n timestamp: callTimestamp,\n LLM_input_file: callFile,\n LLM_output_file: responseFile,\n prompt_tokens: promptTokens,\n completion_tokens: completionTokens,\n reasoning_tokens: reasoningTokens,\n cached_input_tokens: cachedInputTokens,\n inference_time_ms: usageTimeMs,\n });\n }\n\n const parsedElement = actData.action\n ? {\n elementId: actData.action.elementId,\n description: String(actData.action.description),\n method: String(actData.action.method),\n arguments: actData.action.arguments,\n }\n : undefined;\n\n return {\n element: parsedElement,\n prompt_tokens: promptTokens,\n completion_tokens: completionTokens,\n reasoning_tokens: reasoningTokens,\n cached_input_tokens: cachedInputTokens,\n inference_time_ms: usageTimeMs,\n twoStep: actData.twoStep,\n };\n}\n"]}
1
+ {"version":3,"file":"inference.js","sourceRoot":"","sources":["../../../lib/inference.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACxB,sBAAsB,EACtB,mBAAmB,EACnB,yBAAyB,EACzB,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,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C,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC;YACrC,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,SAAS;SACpC;QACH,CAAC,CAAC,SAAS,CAAC;IAEd,OAAO;QACL,OAAO,EAAE,aAAa;QACtB,aAAa,EAAE,YAAY;QAC3B,iBAAiB,EAAE,gBAAgB;QACnC,gBAAgB,EAAE,eAAe;QACjC,mBAAmB,EAAE,iBAAiB;QACtC,iBAAiB,EAAE,WAAW;QAC9B,OAAO,EAAE,OAAO,CAAC,OAAO;KACzB,CAAC;AACJ,CAAC","sourcesContent":["import { z } from \"zod\";\nimport { LogLine } from \"./v3/types/public/logs.js\";\nimport { ChatMessage, LLMClient } from \"./v3/llm/LLMClient.js\";\nimport { getEnvTimeoutMs, withTimeout } from \"./v3/timeoutConfig.js\";\nimport {\n buildActSystemPrompt,\n buildExtractSystemPrompt,\n buildExtractUserPrompt,\n buildMetadataPrompt,\n buildMetadataSystemPrompt,\n buildObserveSystemPrompt,\n buildObserveUserMessage,\n} from \"./prompt.js\";\nimport { appendSummary, writeTimestampedTxtFile } from \"./inferenceLogUtils.js\";\nimport type {\n InferStagehandSchema,\n StagehandZodObject,\n} from \"./v3/zodCompat.js\";\nimport { SupportedUnderstudyAction } from \"./v3/types/private/handlers.js\";\nimport type { Variables } from \"./v3/types/public/agent.js\";\nimport { StagehandInvalidArgumentError } from \"./v3/types/public/sdkErrors.js\";\n\n// Re-export for backward compatibility\nexport type { LLMParsedResponse, LLMUsage } from \"./v3/llm/LLMClient.js\";\n\nfunction withLlmTimeout<T>(promise: Promise<T>, operation: string): Promise<T> {\n return withTimeout(\n promise,\n getEnvTimeoutMs(\"LLM_MAX_MS\"),\n `LLM ${operation}`,\n );\n}\n\nexport async function extract<T extends StagehandZodObject>({\n instruction,\n domElements,\n schema,\n llmClient,\n logger,\n userProvidedInstructions,\n logInferenceToFile = false,\n screenshot,\n}: {\n instruction: string;\n domElements: string;\n schema: T;\n llmClient: LLMClient;\n userProvidedInstructions?: string;\n logger: (message: LogLine) => void;\n logInferenceToFile?: boolean;\n screenshot?: Buffer;\n}) {\n const metadataSchema = z.object({\n progress: z\n .string()\n .describe(\n \"progress of what has been extracted so far, as concise as possible\",\n ),\n completed: z\n .boolean()\n .describe(\n \"true if the goal is now accomplished. Use this conservatively, only when sure that the goal has been completed.\",\n ),\n });\n\n type ExtractionResponse = InferStagehandSchema<T>;\n type MetadataResponse = z.infer<typeof metadataSchema>;\n\n const isUsingAnthropic = llmClient.type === \"anthropic\";\n if (screenshot && llmClient.type !== \"aisdk\") {\n throw new StagehandInvalidArgumentError(\n \"extract({ screenshot: true }) is only supported with AI SDK clients.\",\n );\n }\n const screenshotDataUrl = screenshot\n ? `data:image/png;base64,${screenshot.toString(\"base64\")}`\n : undefined;\n\n const extractCallMessages: ChatMessage[] = [\n buildExtractSystemPrompt(\n isUsingAnthropic,\n userProvidedInstructions,\n Boolean(screenshotDataUrl),\n ),\n buildExtractUserPrompt(\n instruction,\n domElements,\n isUsingAnthropic,\n screenshotDataUrl,\n ),\n ];\n\n let extractCallFile = \"\";\n let extractCallTimestamp = \"\";\n if (logInferenceToFile) {\n const { fileName, timestamp } = writeTimestampedTxtFile(\n \"extract_summary\",\n \"extract_call\",\n {\n modelCall: \"extract\",\n messages: extractCallMessages,\n },\n );\n extractCallFile = fileName;\n extractCallTimestamp = timestamp;\n }\n\n const extractStartTime = Date.now();\n const extractionResponse = await withLlmTimeout(\n llmClient.createChatCompletion<ExtractionResponse>({\n options: {\n messages: extractCallMessages,\n response_model: {\n schema,\n name: \"Extraction\",\n },\n top_p: 1,\n frequency_penalty: 0,\n presence_penalty: 0,\n },\n logger,\n }),\n \"extract\",\n );\n const extractEndTime = Date.now();\n\n const { data: extractedData, usage: extractUsage } = extractionResponse;\n\n let extractResponseFile: string;\n if (logInferenceToFile) {\n const { fileName } = writeTimestampedTxtFile(\n \"extract_summary\",\n \"extract_response\",\n {\n modelResponse: \"extract\",\n rawResponse: extractedData,\n },\n );\n extractResponseFile = fileName;\n\n appendSummary(\"extract\", {\n extract_inference_type: \"extract\",\n timestamp: extractCallTimestamp,\n LLM_input_file: extractCallFile,\n LLM_output_file: extractResponseFile,\n prompt_tokens: extractUsage?.prompt_tokens ?? 0,\n completion_tokens: extractUsage?.completion_tokens ?? 0,\n reasoning_tokens: extractUsage?.reasoning_tokens ?? 0,\n cached_input_tokens: extractUsage?.cached_input_tokens ?? 0,\n inference_time_ms: extractEndTime - extractStartTime,\n });\n }\n\n const metadataCallMessages: ChatMessage[] = [\n buildMetadataSystemPrompt(),\n buildMetadataPrompt(instruction, extractedData),\n ];\n\n let metadataCallFile = \"\";\n let metadataCallTimestamp = \"\";\n if (logInferenceToFile) {\n const { fileName, timestamp } = writeTimestampedTxtFile(\n \"extract_summary\",\n \"metadata_call\",\n {\n modelCall: \"metadata\",\n messages: metadataCallMessages,\n },\n );\n metadataCallFile = fileName;\n metadataCallTimestamp = timestamp;\n }\n\n const metadataStartTime = Date.now();\n const metadataResponse = await withLlmTimeout(\n llmClient.createChatCompletion<MetadataResponse>({\n options: {\n messages: metadataCallMessages,\n response_model: {\n name: \"Metadata\",\n schema: metadataSchema,\n },\n top_p: 1,\n frequency_penalty: 0,\n presence_penalty: 0,\n },\n logger,\n }),\n \"extract metadata\",\n );\n const metadataEndTime = Date.now();\n\n const {\n data: {\n completed: metadataResponseCompleted,\n progress: metadataResponseProgress,\n },\n usage: metadataResponseUsage,\n } = metadataResponse;\n\n let metadataResponseFile: string;\n if (logInferenceToFile) {\n const { fileName } = writeTimestampedTxtFile(\n \"extract_summary\",\n \"metadata_response\",\n {\n modelResponse: \"metadata\",\n completed: metadataResponseCompleted,\n progress: metadataResponseProgress,\n },\n );\n metadataResponseFile = fileName;\n\n appendSummary(\"extract\", {\n extract_inference_type: \"metadata\",\n timestamp: metadataCallTimestamp,\n LLM_input_file: metadataCallFile,\n LLM_output_file: metadataResponseFile,\n prompt_tokens: metadataResponseUsage?.prompt_tokens ?? 0,\n completion_tokens: metadataResponseUsage?.completion_tokens ?? 0,\n reasoning_tokens: metadataResponseUsage?.reasoning_tokens ?? 0,\n cached_input_tokens: metadataResponseUsage?.cached_input_tokens ?? 0,\n inference_time_ms: metadataEndTime - metadataStartTime,\n });\n }\n\n const totalPromptTokens =\n (extractUsage?.prompt_tokens ?? 0) +\n (metadataResponseUsage?.prompt_tokens ?? 0);\n\n const totalCompletionTokens =\n (extractUsage?.completion_tokens ?? 0) +\n (metadataResponseUsage?.completion_tokens ?? 0);\n\n const totalInferenceTimeMs =\n extractEndTime - extractStartTime + (metadataEndTime - metadataStartTime);\n const totalReasoningTokens =\n (extractUsage?.reasoning_tokens ?? 0) +\n (metadataResponseUsage?.reasoning_tokens ?? 0);\n const totalCachedInputTokens =\n (extractUsage?.cached_input_tokens ?? 0) +\n (metadataResponseUsage?.cached_input_tokens ?? 0);\n\n return {\n ...extractedData,\n metadata: {\n completed: metadataResponseCompleted,\n progress: metadataResponseProgress,\n },\n prompt_tokens: totalPromptTokens,\n completion_tokens: totalCompletionTokens,\n reasoning_tokens: totalReasoningTokens,\n cached_input_tokens: totalCachedInputTokens,\n inference_time_ms: totalInferenceTimeMs,\n };\n}\n\nexport async function observe({\n instruction,\n domElements,\n llmClient,\n userProvidedInstructions,\n logger,\n logInferenceToFile = false,\n supportedActions,\n variables,\n}: {\n instruction: string;\n domElements: string;\n llmClient: LLMClient;\n userProvidedInstructions?: string;\n logger: (message: LogLine) => void;\n logInferenceToFile?: boolean;\n supportedActions?: string[];\n variables?: Variables;\n}) {\n const observeSchema = z.object({\n elements: z\n .array(\n z.object({\n elementId: z\n .string()\n .regex(/^\\d+-\\d+$/)\n .describe(\n \"the exact ID string associated with the element. Never include surrounding square brackets. This field must follow the format of 'number-number'. For example, if the accessibility tree shows [0-18372], return '0-18372', not '18372'.\",\n ),\n description: z\n .string()\n .describe(\n \"a description of the accessible element and its purpose\",\n ),\n method: z\n .enum(\n // Use Object.values() for Zod v3 compatibility - z.enum() in v3 doesn't accept TypeScript enums directly\n Object.values(SupportedUnderstudyAction) as unknown as readonly [\n string,\n ...string[],\n ],\n )\n .describe(\n `the candidate method/action to interact with the element. Select one of the available Understudy interaction methods.`,\n ),\n arguments: z.array(\n z\n .string()\n .describe(\n \"the arguments to pass to the method. For example, for a click, the arguments are empty, but for a fill, the arguments are the value to fill in.\",\n ),\n ),\n }),\n )\n .describe(\"an array of accessible elements that match the instruction\"),\n });\n\n type ObserveResponse = z.infer<typeof observeSchema>;\n\n const messages: ChatMessage[] = [\n buildObserveSystemPrompt(\n userProvidedInstructions,\n supportedActions,\n variables,\n ),\n buildObserveUserMessage(instruction, domElements),\n ];\n\n let callTimestamp = \"\";\n let callFile = \"\";\n if (logInferenceToFile) {\n const { fileName, timestamp } = writeTimestampedTxtFile(\n `observe_summary`,\n `observe_call`,\n {\n modelCall: \"observe\",\n messages,\n },\n );\n callFile = fileName;\n callTimestamp = timestamp;\n }\n\n const start = Date.now();\n const rawResponse = await llmClient.createChatCompletion<ObserveResponse>({\n options: {\n messages,\n response_model: {\n schema: observeSchema,\n name: \"Observation\",\n },\n top_p: 1,\n frequency_penalty: 0,\n presence_penalty: 0,\n },\n logger,\n });\n const end = Date.now();\n const usageTimeMs = end - start;\n\n const { data: observeData, usage: observeUsage } = rawResponse;\n const promptTokens = observeUsage?.prompt_tokens ?? 0;\n const completionTokens = observeUsage?.completion_tokens ?? 0;\n const reasoningTokens = observeUsage?.reasoning_tokens ?? 0;\n const cachedInputTokens = observeUsage?.cached_input_tokens ?? 0;\n\n let responseFile: string;\n if (logInferenceToFile) {\n const { fileName: responseFileName } = writeTimestampedTxtFile(\n `observe_summary`,\n `observe_response`,\n {\n modelResponse: \"observe\",\n rawResponse: observeData,\n },\n );\n responseFile = responseFileName;\n\n appendSummary(\"observe\", {\n [`observe_inference_type`]: \"observe\",\n timestamp: callTimestamp,\n LLM_input_file: callFile,\n LLM_output_file: responseFile,\n prompt_tokens: promptTokens,\n completion_tokens: completionTokens,\n reasoning_tokens: reasoningTokens,\n cached_input_tokens: cachedInputTokens,\n inference_time_ms: usageTimeMs,\n });\n }\n\n const parsedElements =\n observeData.elements?.map((el) => {\n const base = {\n elementId: el.elementId,\n description: String(el.description),\n method: String(el.method),\n arguments: el.arguments,\n };\n return base;\n }) ?? [];\n\n return {\n elements: parsedElements,\n prompt_tokens: promptTokens,\n completion_tokens: completionTokens,\n reasoning_tokens: reasoningTokens,\n cached_input_tokens: cachedInputTokens,\n inference_time_ms: usageTimeMs,\n };\n}\n\nexport async function act({\n instruction,\n domElements,\n llmClient,\n userProvidedInstructions,\n logger,\n logInferenceToFile = false,\n}: {\n instruction: string;\n domElements: string;\n llmClient: LLMClient;\n userProvidedInstructions?: string;\n logger: (message: LogLine) => void;\n logInferenceToFile?: boolean;\n}) {\n const actSchema = z.object({\n action: z\n .object({\n elementId: z\n .string()\n .regex(/^\\d+-\\d+$/)\n .describe(\n \"the ID string associated with the element. Never include surrounding square brackets. This field must follow the format of 'number-number'. for example, '0-76' or '16-21'\",\n ),\n description: z\n .string()\n .describe(\"a description of the accessible element and its purpose\"),\n method: z\n .enum(\n // Use Object.values() for Zod v3 compatibility - z.enum() in v3 doesn't accept TypeScript enums directly\n Object.values(SupportedUnderstudyAction) as unknown as readonly [\n string,\n ...string[],\n ],\n )\n .describe(\n \"the candidate method/action to interact with the element. Select one of the available Understudy interaction methods.\",\n ),\n arguments: z.array(\n z\n .string()\n .describe(\n \"the arguments to pass to the method. For example, for a click, the arguments are empty, but for a fill, the arguments are the value to fill in.\",\n ),\n ),\n })\n .nullable()\n .describe(\n \"The element to act on. Return null if no element on the page matches the instruction — do NOT fabricate or guess an element, and never emit empty strings or placeholder values.\",\n ),\n twoStep: z.boolean(),\n });\n\n type ActResponse = z.infer<typeof actSchema>;\n\n const messages: ChatMessage[] = [\n buildActSystemPrompt(userProvidedInstructions),\n buildObserveUserMessage(instruction, domElements),\n ];\n\n let callTimestamp = \"\";\n let callFile = \"\";\n if (logInferenceToFile) {\n const { fileName, timestamp } = writeTimestampedTxtFile(\n `act_summary`,\n `act_call`,\n {\n modelCall: \"act\",\n messages,\n },\n );\n callFile = fileName;\n callTimestamp = timestamp;\n }\n\n const start = Date.now();\n const rawResponse = await llmClient.createChatCompletion<ActResponse>({\n options: {\n messages,\n response_model: {\n schema: actSchema,\n name: \"act\",\n },\n top_p: 1,\n frequency_penalty: 0,\n presence_penalty: 0,\n },\n logger,\n });\n const end = Date.now();\n const usageTimeMs = end - start;\n\n const { data: actData, usage: actUsage } = rawResponse;\n const promptTokens = actUsage?.prompt_tokens ?? 0;\n const completionTokens = actUsage?.completion_tokens ?? 0;\n const reasoningTokens = actUsage?.reasoning_tokens ?? 0;\n const cachedInputTokens = actUsage?.cached_input_tokens ?? 0;\n\n let responseFile: string;\n if (logInferenceToFile) {\n const { fileName: responseFileName } = writeTimestampedTxtFile(\n `act_summary`,\n `act_response`,\n {\n modelResponse: \"act\",\n rawResponse: actData,\n },\n );\n responseFile = responseFileName;\n\n appendSummary(\"act\", {\n [`act_inference_type`]: \"act\",\n timestamp: callTimestamp,\n LLM_input_file: callFile,\n LLM_output_file: responseFile,\n prompt_tokens: promptTokens,\n completion_tokens: completionTokens,\n reasoning_tokens: reasoningTokens,\n cached_input_tokens: cachedInputTokens,\n inference_time_ms: usageTimeMs,\n });\n }\n\n const parsedElement = actData.action\n ? {\n elementId: actData.action.elementId,\n description: String(actData.action.description),\n method: String(actData.action.method),\n arguments: actData.action.arguments,\n }\n : undefined;\n\n return {\n element: parsedElement,\n prompt_tokens: promptTokens,\n completion_tokens: completionTokens,\n reasoning_tokens: reasoningTokens,\n cached_input_tokens: cachedInputTokens,\n inference_time_ms: usageTimeMs,\n twoStep: actData.twoStep,\n };\n}\n"]}
@@ -1,8 +1,8 @@
1
1
  import { ChatMessage } from "./v3/llm/LLMClient.js";
2
2
  import type { Variables } from "./v3/types/public/agent.js";
3
3
  export declare function buildUserInstructionsString(userProvidedInstructions?: string): string;
4
- export declare function buildExtractSystemPrompt(isUsingPrintExtractedDataTool?: boolean, userProvidedInstructions?: string): ChatMessage;
5
- export declare function buildExtractUserPrompt(instruction: string, domElements: string, isUsingPrintExtractedDataTool?: boolean): ChatMessage;
4
+ export declare function buildExtractSystemPrompt(isUsingPrintExtractedDataTool?: boolean, userProvidedInstructions?: string, includeScreenshot?: boolean): ChatMessage;
5
+ export declare function buildExtractUserPrompt(instruction: string, domElements: string, isUsingPrintExtractedDataTool?: boolean, screenshotDataUrl?: string): ChatMessage;
6
6
  export declare function buildMetadataSystemPrompt(): ChatMessage;
7
7
  export declare function buildMetadataPrompt(instruction: string, extractionResponse: object): ChatMessage;
8
8
  export declare function buildObserveSystemPrompt(userProvidedInstructions?: string, supportedActions?: string[], variables?: Variables): ChatMessage;
@@ -11,7 +11,7 @@ User Instructions:
11
11
  ${userProvidedInstructions}`;
12
12
  }
13
13
  // extract
14
- export function buildExtractSystemPrompt(isUsingPrintExtractedDataTool = false, userProvidedInstructions) {
14
+ export function buildExtractSystemPrompt(isUsingPrintExtractedDataTool = false, userProvidedInstructions, includeScreenshot = false) {
15
15
  const baseContent = `You are extracting content on behalf of a user.
16
16
  If a user asks you to extract a 'list' of information, or 'all' information,
17
17
  YOU MUST EXTRACT ALL OF THE INFORMATION THAT THE USER REQUESTS.
@@ -19,7 +19,9 @@ export function buildExtractSystemPrompt(isUsingPrintExtractedDataTool = false,
19
19
  You will be given:
20
20
  1. An instruction
21
21
  2. `;
22
- const contentDetail = `A list of DOM elements to extract from.`;
22
+ const contentDetail = includeScreenshot
23
+ ? `A list of DOM elements to extract from and a screenshot of the current viewport to extract from. Use them together to extract content from the page.`
24
+ : `A list of DOM elements to extract from.`;
23
25
  const instructions = `
24
26
  Print the exact text from the DOM elements with all symbols, characters, and endlines as is.
25
27
  Print null or an empty string if no new information is found.
@@ -39,14 +41,27 @@ ONLY print the content using the print_extracted_data tool provided.
39
41
  content,
40
42
  };
41
43
  }
42
- export function buildExtractUserPrompt(instruction, domElements, isUsingPrintExtractedDataTool = false) {
43
- let content = `Instruction: ${instruction}
44
+ export function buildExtractUserPrompt(instruction, domElements, isUsingPrintExtractedDataTool = false, screenshotDataUrl) {
45
+ let content = screenshotDataUrl
46
+ ? `Instruction: ${instruction}
47
+ DOM: ${domElements}
48
+ Use the screenshot of the current viewport together with the accessibility tree to extract content from the page.`
49
+ : `Instruction: ${instruction}
44
50
  DOM: ${domElements}`;
45
51
  if (isUsingPrintExtractedDataTool) {
46
52
  content += `
47
53
  ONLY print the content using the print_extracted_data tool provided.
48
54
  ONLY print the content using the print_extracted_data tool provided.`;
49
55
  }
56
+ if (screenshotDataUrl) {
57
+ return {
58
+ role: "user",
59
+ content: [
60
+ { type: "text", text: content },
61
+ { type: "image_url", image_url: { url: screenshotDataUrl } },
62
+ ],
63
+ };
64
+ }
50
65
  return {
51
66
  role: "user",
52
67
  content,
@@ -1 +1 @@
1
- {"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../../lib/prompt.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzE,MAAM,UAAU,2BAA2B,CACzC,wBAAiC;IAEjC,IAAI,CAAC,wBAAwB,EAAE,CAAC;QAC9B,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,OAAO;;;;;EAKP,wBAAwB,EAAE,CAAC;AAC7B,CAAC;AAED,UAAU;AACV,MAAM,UAAU,wBAAwB,CACtC,gCAAyC,KAAK,EAC9C,wBAAiC;IAEjC,MAAM,WAAW,GAAG;;;;;;IAMlB,CAAC;IAEH,MAAM,aAAa,GAAG,yCAAyC,CAAC;IAEhE,MAAM,YAAY,GAAG;;;GAGpB,CAAC,IAAI,EAAE,CAAC;IAET,MAAM,gBAAgB,GAAG,6BAA6B;QACpD,CAAC,CAAC;;;GAGH,CAAC,IAAI,EAAE;QACN,CAAC,CAAC,EAAE,CAAC;IAEP,MAAM,sBAAsB,GAC1B,+GAA+G;QAC/G,sFAAsF,CAAC;IAE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E;KAChF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,2BAA2B;IACzC,OAAO,gJAAgJ,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;AACnM,CAAC;AAED,MAAM,UAAU,0BAA0B;IACxC,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE;kBACK,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;;;CAGvD;KACE,CAAC;AACJ,CAAC","sourcesContent":["import { ChatMessage } from \"./v3/llm/LLMClient.js\";\nimport type { Variables } from \"./v3/types/public/agent.js\";\nimport { getVariablePromptEntries } from \"./v3/agent/utils/variables.js\";\n\nexport function buildUserInstructionsString(\n userProvidedInstructions?: string,\n): string {\n if (!userProvidedInstructions) {\n return \"\";\n }\n\n return `\\n\\n# Custom Instructions Provided by the User\n \nPlease keep the user's instructions in mind when performing actions. If the user's instructions are not relevant to the current task, ignore them.\n\nUser Instructions:\n${userProvidedInstructions}`;\n}\n\n// extract\nexport function buildExtractSystemPrompt(\n isUsingPrintExtractedDataTool: boolean = false,\n userProvidedInstructions?: string,\n): ChatMessage {\n const baseContent = `You are extracting content on behalf of a user.\n If a user asks you to extract a 'list' of information, or 'all' information, \n YOU MUST EXTRACT ALL OF THE INFORMATION THAT THE USER REQUESTS.\n \n You will be given:\n1. An instruction\n2. `;\n\n const contentDetail = `A list of DOM elements to extract from.`;\n\n const instructions = `\nPrint the exact text from the DOM elements with all symbols, characters, and endlines as is.\nPrint null or an empty string if no new information is found.\n `.trim();\n\n const toolInstructions = isUsingPrintExtractedDataTool\n ? `\nONLY print the content using the print_extracted_data tool provided.\nONLY print the content using the print_extracted_data tool provided.\n `.trim()\n : \"\";\n\n const additionalInstructions =\n \"If a user is attempting to extract links or URLs, you MUST respond with ONLY the IDs of the link elements. \\n\" +\n \"Do not attempt to extract links directly from the text unless absolutely necessary. \";\n\n const userInstructions = buildUserInstructionsString(\n userProvidedInstructions,\n );\n\n const content =\n `${baseContent}${contentDetail}\\n\\n${instructions}\\n${toolInstructions}${\n additionalInstructions ? `\\n\\n${additionalInstructions}` : \"\"\n }${userInstructions ? `\\n\\n${userInstructions}` : \"\"}`.replace(/\\s+/g, \" \");\n\n return {\n role: \"system\",\n content,\n };\n}\n\nexport function buildExtractUserPrompt(\n instruction: string,\n domElements: string,\n isUsingPrintExtractedDataTool: boolean = false,\n): ChatMessage {\n let content = `Instruction: ${instruction}\nDOM: ${domElements}`;\n\n if (isUsingPrintExtractedDataTool) {\n content += `\nONLY print the content using the print_extracted_data tool provided.\nONLY print the content using the print_extracted_data tool provided.`;\n }\n\n return {\n role: \"user\",\n content,\n };\n}\n\nconst metadataSystemPrompt = `You are an AI assistant tasked with evaluating the progress and completion status of an extraction task.\nAnalyze the extraction response and determine if the task is completed or if more information is needed.\nStrictly abide by the following criteria:\n1. Once the instruction has been satisfied by the current extraction response, ALWAYS set completion status to true and stop processing, regardless of remaining chunks.\n2. Only set completion status to false if BOTH of these conditions are true:\n - The instruction has not been satisfied yet\n - There are still chunks left to process (chunksTotal > chunksSeen)`;\n\nexport function buildMetadataSystemPrompt(): ChatMessage {\n return {\n role: \"system\",\n content: metadataSystemPrompt,\n };\n}\n\nexport function buildMetadataPrompt(\n instruction: string,\n extractionResponse: object,\n): ChatMessage {\n return {\n role: \"user\",\n content: `Instruction: ${instruction}\nExtracted content: ${JSON.stringify(extractionResponse, null, 2)}`,\n };\n}\n\n// observe\nexport function buildObserveSystemPrompt(\n userProvidedInstructions?: string,\n supportedActions?: string[],\n variables?: Variables,\n): ChatMessage {\n const actionsString = supportedActions?.length\n ? `\\n\\nSupported actions: ${supportedActions.join(\", \")}`\n : \"\";\n const variableEntries = getVariablePromptEntries(variables);\n const variablesString = variableEntries.length\n ? `\\n\\nAvailable variables: ${variableEntries\n .map(({ name, description }) => {\n return description ? `%${name}% (${description})` : `%${name}%`;\n })\n .join(\n \", \",\n )}. When an action needs a dynamic or sensitive value, return the matching %variableName% placeholder in the action arguments instead of a literal value`\n : \"\";\n\n const observeSystemPrompt = `\nYou are helping the user automate the browser by finding elements based on what the user wants to observe in the page.\n\nYou will be given:\n1. a instruction of elements to observe\n2. a hierarchical accessibility tree showing the semantic structure of the page. The tree is a hybrid of the DOM and the accessibility tree.\n\nReturn an array of elements that match the instruction if they exist, otherwise return an empty array.\nWhen returning elements, include the appropriate method from the supported actions list.${actionsString}${variablesString}. When choosing non-left click actions, provide right or middle as the argument.\n\nEach element in the accessibility tree has an ID in square brackets, like [0-18372]. The ID has two parts: frame ordinal and backend node ID. Always copy the complete ID exactly as shown inside the brackets into elementId, including the frame ordinal and hyphen. For example, if the tree shows [0-18372], return elementId \"0-18372\"; never return only \"18372\".`;\n const content = observeSystemPrompt.replace(/\\s+/g, \" \");\n\n return {\n role: \"system\",\n content: [content, buildUserInstructionsString(userProvidedInstructions)]\n .filter(Boolean)\n .join(\"\\n\\n\"),\n };\n}\n\nexport function buildObserveUserMessage(\n instruction: string,\n domElements: string,\n): ChatMessage {\n return {\n role: \"user\",\n content: `instruction: ${instruction}\nAccessibility Tree: \\n${domElements}\\n`,\n };\n}\n\nexport function buildActSystemPrompt(\n userProvidedInstructions?: string,\n): ChatMessage {\n const actSystemPrompt = `\nYou are helping the user automate the browser by finding elements based on what action the user wants to take on the page\n\nYou will be given:\n1. a user defined instruction about what action to take\n2. a hierarchical accessibility tree showing the semantic structure of the page. The tree is a hybrid of the DOM and the accessibility tree.\n\nReturn the element that matches the instruction if it exists. If no element on the page matches the instruction, set \\`action\\` to null. Do not fabricate or guess an element — empty strings or placeholder values for elementId/description/method are not acceptable.`;\n const content = actSystemPrompt.replace(/\\s+/g, \" \");\n\n return {\n role: \"system\",\n content: [content, buildUserInstructionsString(userProvidedInstructions)]\n .filter(Boolean)\n .join(\"\\n\\n\"),\n };\n}\n\nfunction buildActVariablesPrompt(variables?: Variables): string {\n if (!variables || Object.keys(variables).length === 0) {\n return \"\";\n }\n\n const variableNames = Object.keys(variables)\n .map((key) => `%${key}%`)\n .join(\", \");\n\n return ` The user has provided the following variables to be used in the action: ${variableNames} \\n\n Note that these are the variable names/keys, and not the actual variable values. \\n\n To use the variables in the action, you must respond with the variable name inside the 'arguments' array. The variable name must be wrapped in percentage signs (eg, %variableNameHere%) so that it can be replaced with the actual variable value before the action is taken. \\n`;\n}\n\nexport function buildActPrompt(\n action: string,\n supportedActions: string[],\n variables?: Variables,\n): string {\n // Base instruction\n let instruction = `Find the most relevant element to perform an action on given the following action: ${action}. \n IF AND ONLY IF the action EXPLICITLY includes the word 'dropdown' and implies choosing/selecting an option from a dropdown, ignore the 'General Instructions' section, and follow the 'Dropdown Specific Instructions' section carefully.\n \n General Instructions: \n Provide an action for this element such as ${supportedActions.join(\", \")}. Remember that to users, buttons and links look the same in most cases.\n When choosing non-left click actions, provide right or middle as the argument\n If the action is completely unrelated to a potential action to be taken on the page, or no matching element exists, set \\`action\\` to null. Do not fabricate or guess an element.\n ONLY return one action. If multiple actions are relevant, return the most relevant one.\n If the user is asking to scroll to a position on the page, e.g., 'halfway' or 0.75, etc, you must return the argument formatted as the correct percentage, e.g., '50%' or '75%', etc.\n If the user is asking to scroll to the next chunk/previous chunk, choose the nextChunk/prevChunk method. No arguments are required here.\n If the action implies a key press, e.g., 'press enter', 'press a', 'press space', etc., always choose the press method with the appropriate key as argument — e.g. 'a', 'Enter', 'Space'. Do not choose a click action on an on-screen keyboard. Capitalize the first character like 'Enter', 'Tab', 'Escape' only for special keys. \n \n Dropdown Specific Instructions:\n For interacting with dropdowns, there are two specific cases that you need to handle. \n \n CASE 1: the element is a 'select' element. \n - choose the selectOptionFromDropdown method,\n - set the argument to the exact text of the option that should be selected,\n - set twoStep to false.\n CASE 2: the element is NOT a 'select' element:\n - do not attempt to directly choose the element from the dropdown. You will need to click to expand the dropdown first. You will achieve this by following these instructions:\n - choose the node that most closely corresponds to the given instruction EVEN if it is a 'StaticText' element, or otherwise does not appear to be interactable. \n - choose the 'click' method\n - set twoStep to true.\n `;\n\n instruction += buildActVariablesPrompt(variables);\n\n return instruction;\n}\n\nexport function buildStepTwoPrompt(\n originalUserAction: string,\n previousAction: string,\n supportedActions: string[],\n variables?: Variables,\n): string {\n // Base instruction\n let instruction = `\n The original user action was: ${originalUserAction}.\n You have just taken the following action which completed step 1 of 2: ${previousAction}.\n \n Now, you must find the most relevant element to perform an action on in order to complete step 2 of 2. \n \n General Instructions: \n Provide an action for this element such as ${supportedActions.join(\", \")}. Remember that to users, buttons and links look the same in most cases.\n If the action is completely unrelated to a potential action to be taken on the page, or no matching element exists, set \\`action\\` to null. Do not fabricate or guess an element.\n ONLY return one action. If multiple actions are relevant, return the most relevant one.\n If the user is asking to scroll to a position on the page, e.g., 'halfway' or 0.75, etc, you must return the argument formatted as the correct percentage, e.g., '50%' or '75%', etc.\n If the user is asking to scroll to the next chunk/previous chunk, choose the nextChunk/prevChunk method. No arguments are required here.\n If the action implies a key press, e.g., 'press enter', 'press a', 'press space', etc., always choose the press method with the appropriate key as argument — e.g. 'a', 'Enter', 'Space'. Do not choose a click action on an on-screen keyboard. Capitalize the first character like 'Enter', 'Tab', 'Escape' only for special keys. \n `;\n\n instruction += buildActVariablesPrompt(variables);\n\n return instruction;\n}\n\nexport function buildOperatorSystemPrompt(goal: string): ChatMessage {\n return {\n role: \"system\",\n content: `You are a general-purpose agent whose job is to accomplish the user's goal across multiple model calls by running actions on the page.\n\nYou will be given a goal and a list of steps that have been taken so far. Your job is to determine if either the user's goal has been completed or if there are still steps that need to be taken.\n\n# Your current goal\n${goal}\n\n# CRITICAL: You MUST use the provided tools to take actions. Do not just describe what you want to do - actually call the appropriate tools.\n\n# Available tools and when to use them:\n- \\`act\\`: Use this to interact with the page (click, type, navigate, etc.)\n- \\`extract\\`: Use this to get information from the page\n- \\`goto\\`: Use this to navigate to a specific URL\n- \\`wait\\`: Use this to wait for a period of time\n- \\`navback\\`: Use this to go back to the previous page\n- \\`refresh\\`: Use this to refresh the current page\n- \\`close\\`: Use this ONLY when the task is complete or cannot be achieved\n- External tools: Use any additional tools (like search tools) as needed for your goal\n\n# Important guidelines\n1. ALWAYS use tools - never just provide text responses about what you plan to do\n2. Break down complex actions into individual atomic steps\n3. For \\`act\\` commands, use only one action at a time, such as:\n - Single click on a specific element\n - Type into a single input field\n - Select a single option\n4. Avoid combining multiple actions in one instruction\n5. If multiple actions are needed, they should be separate steps\n6. Only use \\`close\\` when the task is genuinely complete or impossible to achieve`,\n };\n}\n\nexport function buildCuaDefaultSystemPrompt(): string {\n return `You are a helpful assistant that can use a web browser.\\nDo not ask follow up questions, the user will trust your judgement. Today's date is ${new Date().toISOString().split(\"T\")[0]}.`;\n}\n\nexport function buildGoogleCUASystemPrompt(): ChatMessage {\n return {\n role: \"system\",\n content: `You are a general-purpose browser agent whose job is to accomplish the user's goal.\nToday's date is ${new Date().toISOString().split(\"T\")[0]}.\nYou have access to a search tool; however, in most cases you should operate within the page/url the user has provided. ONLY use the search tool if you're stuck or the task is impossible to complete within the current page.\nYou will be given a goal and a list of steps that have been taken so far. Avoid requesting the user for input as much as possible. Good luck!\n`,\n };\n}\n"]}
1
+ {"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../../lib/prompt.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzE,MAAM,UAAU,2BAA2B,CACzC,wBAAiC;IAEjC,IAAI,CAAC,wBAAwB,EAAE,CAAC;QAC9B,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,OAAO;;;;;EAKP,wBAAwB,EAAE,CAAC;AAC7B,CAAC;AAED,UAAU;AACV,MAAM,UAAU,wBAAwB,CACtC,gCAAyC,KAAK,EAC9C,wBAAiC,EACjC,oBAA6B,KAAK;IAElC,MAAM,WAAW,GAAG;;;;;;IAMlB,CAAC;IAEH,MAAM,aAAa,GAAG,iBAAiB;QACrC,CAAC,CAAC,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AsF,MAAM;;;;iDAI/D,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC;;;;;;;;;;;;;;;;;;;;GAoBzE,CAAC;IAEF,WAAW,IAAI,uBAAuB,CAAC,SAAS,CAAC,CAAC;IAElD,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,kBAA0B,EAC1B,cAAsB,EACtB,gBAA0B,EAC1B,SAAqB;IAErB,mBAAmB;IACnB,IAAI,WAAW,GAAG;kCACc,kBAAkB;0EACsB,cAAc;;;;;+CAKzC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC;;;;;;GAMvE,CAAC;IAEF,WAAW,IAAI,uBAAuB,CAAC,SAAS,CAAC,CAAC;IAElD,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,IAAY;IACpD,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE;;;;;EAKX,IAAI;;;;;;;;;;;;;;;;;;;;;;;mFAuB6E;KAChF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,2BAA2B;IACzC,OAAO,gJAAgJ,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;AACnM,CAAC;AAED,MAAM,UAAU,0BAA0B;IACxC,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE;kBACK,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;;;CAGvD;KACE,CAAC;AACJ,CAAC","sourcesContent":["import { ChatMessage } from \"./v3/llm/LLMClient.js\";\nimport type { Variables } from \"./v3/types/public/agent.js\";\nimport { getVariablePromptEntries } from \"./v3/agent/utils/variables.js\";\n\nexport function buildUserInstructionsString(\n userProvidedInstructions?: string,\n): string {\n if (!userProvidedInstructions) {\n return \"\";\n }\n\n return `\\n\\n# Custom Instructions Provided by the User\n \nPlease keep the user's instructions in mind when performing actions. If the user's instructions are not relevant to the current task, ignore them.\n\nUser Instructions:\n${userProvidedInstructions}`;\n}\n\n// extract\nexport function buildExtractSystemPrompt(\n isUsingPrintExtractedDataTool: boolean = false,\n userProvidedInstructions?: string,\n includeScreenshot: boolean = false,\n): ChatMessage {\n const baseContent = `You are extracting content on behalf of a user.\n If a user asks you to extract a 'list' of information, or 'all' information, \n YOU MUST EXTRACT ALL OF THE INFORMATION THAT THE USER REQUESTS.\n \n You will be given:\n1. An instruction\n2. `;\n\n const contentDetail = includeScreenshot\n ? `A list of DOM elements to extract from and a screenshot of the current viewport to extract from. Use them together to extract content from the page.`\n : `A list of DOM elements to extract from.`;\n\n const instructions = `\nPrint the exact text from the DOM elements with all symbols, characters, and endlines as is.\nPrint null or an empty string if no new information is found.\n `.trim();\n\n const toolInstructions = isUsingPrintExtractedDataTool\n ? `\nONLY print the content using the print_extracted_data tool provided.\nONLY print the content using the print_extracted_data tool provided.\n `.trim()\n : \"\";\n\n const additionalInstructions =\n \"If a user is attempting to extract links or URLs, you MUST respond with ONLY the IDs of the link elements. \\n\" +\n \"Do not attempt to extract links directly from the text unless absolutely necessary. \";\n\n const userInstructions = buildUserInstructionsString(\n userProvidedInstructions,\n );\n\n const content =\n `${baseContent}${contentDetail}\\n\\n${instructions}\\n${toolInstructions}${\n additionalInstructions ? `\\n\\n${additionalInstructions}` : \"\"\n }${userInstructions ? `\\n\\n${userInstructions}` : \"\"}`.replace(/\\s+/g, \" \");\n\n return {\n role: \"system\",\n content,\n };\n}\n\nexport function buildExtractUserPrompt(\n instruction: string,\n domElements: string,\n isUsingPrintExtractedDataTool: boolean = false,\n screenshotDataUrl?: string,\n): ChatMessage {\n let content = screenshotDataUrl\n ? `Instruction: ${instruction}\nDOM: ${domElements}\nUse the screenshot of the current viewport together with the accessibility tree to extract content from the page.`\n : `Instruction: ${instruction}\nDOM: ${domElements}`;\n\n if (isUsingPrintExtractedDataTool) {\n content += `\nONLY print the content using the print_extracted_data tool provided.\nONLY print the content using the print_extracted_data tool provided.`;\n }\n\n if (screenshotDataUrl) {\n return {\n role: \"user\",\n content: [\n { type: \"text\", text: content },\n { type: \"image_url\", image_url: { url: screenshotDataUrl } },\n ],\n };\n }\n\n return {\n role: \"user\",\n content,\n };\n}\n\nconst metadataSystemPrompt = `You are an AI assistant tasked with evaluating the progress and completion status of an extraction task.\nAnalyze the extraction response and determine if the task is completed or if more information is needed.\nStrictly abide by the following criteria:\n1. Once the instruction has been satisfied by the current extraction response, ALWAYS set completion status to true and stop processing, regardless of remaining chunks.\n2. Only set completion status to false if BOTH of these conditions are true:\n - The instruction has not been satisfied yet\n - There are still chunks left to process (chunksTotal > chunksSeen)`;\n\nexport function buildMetadataSystemPrompt(): ChatMessage {\n return {\n role: \"system\",\n content: metadataSystemPrompt,\n };\n}\n\nexport function buildMetadataPrompt(\n instruction: string,\n extractionResponse: object,\n): ChatMessage {\n return {\n role: \"user\",\n content: `Instruction: ${instruction}\nExtracted content: ${JSON.stringify(extractionResponse, null, 2)}`,\n };\n}\n\n// observe\nexport function buildObserveSystemPrompt(\n userProvidedInstructions?: string,\n supportedActions?: string[],\n variables?: Variables,\n): ChatMessage {\n const actionsString = supportedActions?.length\n ? `\\n\\nSupported actions: ${supportedActions.join(\", \")}`\n : \"\";\n const variableEntries = getVariablePromptEntries(variables);\n const variablesString = variableEntries.length\n ? `\\n\\nAvailable variables: ${variableEntries\n .map(({ name, description }) => {\n return description ? `%${name}% (${description})` : `%${name}%`;\n })\n .join(\n \", \",\n )}. When an action needs a dynamic or sensitive value, return the matching %variableName% placeholder in the action arguments instead of a literal value`\n : \"\";\n\n const observeSystemPrompt = `\nYou are helping the user automate the browser by finding elements based on what the user wants to observe in the page.\n\nYou will be given:\n1. a instruction of elements to observe\n2. a hierarchical accessibility tree showing the semantic structure of the page. The tree is a hybrid of the DOM and the accessibility tree.\n\nReturn an array of elements that match the instruction if they exist, otherwise return an empty array.\nWhen returning elements, include the appropriate method from the supported actions list.${actionsString}${variablesString}. When choosing non-left click actions, provide right or middle as the argument.\n\nEach element in the accessibility tree has an ID in square brackets, like [0-18372]. The ID has two parts: frame ordinal and backend node ID. Always copy the complete ID exactly as shown inside the brackets into elementId, including the frame ordinal and hyphen. For example, if the tree shows [0-18372], return elementId \"0-18372\"; never return only \"18372\".`;\n const content = observeSystemPrompt.replace(/\\s+/g, \" \");\n\n return {\n role: \"system\",\n content: [content, buildUserInstructionsString(userProvidedInstructions)]\n .filter(Boolean)\n .join(\"\\n\\n\"),\n };\n}\n\nexport function buildObserveUserMessage(\n instruction: string,\n domElements: string,\n): ChatMessage {\n return {\n role: \"user\",\n content: `instruction: ${instruction}\nAccessibility Tree: \\n${domElements}\\n`,\n };\n}\n\nexport function buildActSystemPrompt(\n userProvidedInstructions?: string,\n): ChatMessage {\n const actSystemPrompt = `\nYou are helping the user automate the browser by finding elements based on what action the user wants to take on the page\n\nYou will be given:\n1. a user defined instruction about what action to take\n2. a hierarchical accessibility tree showing the semantic structure of the page. The tree is a hybrid of the DOM and the accessibility tree.\n\nReturn the element that matches the instruction if it exists. If no element on the page matches the instruction, set \\`action\\` to null. Do not fabricate or guess an element — empty strings or placeholder values for elementId/description/method are not acceptable.`;\n const content = actSystemPrompt.replace(/\\s+/g, \" \");\n\n return {\n role: \"system\",\n content: [content, buildUserInstructionsString(userProvidedInstructions)]\n .filter(Boolean)\n .join(\"\\n\\n\"),\n };\n}\n\nfunction buildActVariablesPrompt(variables?: Variables): string {\n if (!variables || Object.keys(variables).length === 0) {\n return \"\";\n }\n\n const variableNames = Object.keys(variables)\n .map((key) => `%${key}%`)\n .join(\", \");\n\n return ` The user has provided the following variables to be used in the action: ${variableNames} \\n\n Note that these are the variable names/keys, and not the actual variable values. \\n\n To use the variables in the action, you must respond with the variable name inside the 'arguments' array. The variable name must be wrapped in percentage signs (eg, %variableNameHere%) so that it can be replaced with the actual variable value before the action is taken. \\n`;\n}\n\nexport function buildActPrompt(\n action: string,\n supportedActions: string[],\n variables?: Variables,\n): string {\n // Base instruction\n let instruction = `Find the most relevant element to perform an action on given the following action: ${action}. \n IF AND ONLY IF the action EXPLICITLY includes the word 'dropdown' and implies choosing/selecting an option from a dropdown, ignore the 'General Instructions' section, and follow the 'Dropdown Specific Instructions' section carefully.\n \n General Instructions: \n Provide an action for this element such as ${supportedActions.join(\", \")}. Remember that to users, buttons and links look the same in most cases.\n When choosing non-left click actions, provide right or middle as the argument\n If the action is completely unrelated to a potential action to be taken on the page, or no matching element exists, set \\`action\\` to null. Do not fabricate or guess an element.\n ONLY return one action. If multiple actions are relevant, return the most relevant one.\n If the user is asking to scroll to a position on the page, e.g., 'halfway' or 0.75, etc, you must return the argument formatted as the correct percentage, e.g., '50%' or '75%', etc.\n If the user is asking to scroll to the next chunk/previous chunk, choose the nextChunk/prevChunk method. No arguments are required here.\n If the action implies a key press, e.g., 'press enter', 'press a', 'press space', etc., always choose the press method with the appropriate key as argument — e.g. 'a', 'Enter', 'Space'. Do not choose a click action on an on-screen keyboard. Capitalize the first character like 'Enter', 'Tab', 'Escape' only for special keys. \n \n Dropdown Specific Instructions:\n For interacting with dropdowns, there are two specific cases that you need to handle. \n \n CASE 1: the element is a 'select' element. \n - choose the selectOptionFromDropdown method,\n - set the argument to the exact text of the option that should be selected,\n - set twoStep to false.\n CASE 2: the element is NOT a 'select' element:\n - do not attempt to directly choose the element from the dropdown. You will need to click to expand the dropdown first. You will achieve this by following these instructions:\n - choose the node that most closely corresponds to the given instruction EVEN if it is a 'StaticText' element, or otherwise does not appear to be interactable. \n - choose the 'click' method\n - set twoStep to true.\n `;\n\n instruction += buildActVariablesPrompt(variables);\n\n return instruction;\n}\n\nexport function buildStepTwoPrompt(\n originalUserAction: string,\n previousAction: string,\n supportedActions: string[],\n variables?: Variables,\n): string {\n // Base instruction\n let instruction = `\n The original user action was: ${originalUserAction}.\n You have just taken the following action which completed step 1 of 2: ${previousAction}.\n \n Now, you must find the most relevant element to perform an action on in order to complete step 2 of 2. \n \n General Instructions: \n Provide an action for this element such as ${supportedActions.join(\", \")}. Remember that to users, buttons and links look the same in most cases.\n If the action is completely unrelated to a potential action to be taken on the page, or no matching element exists, set \\`action\\` to null. Do not fabricate or guess an element.\n ONLY return one action. If multiple actions are relevant, return the most relevant one.\n If the user is asking to scroll to a position on the page, e.g., 'halfway' or 0.75, etc, you must return the argument formatted as the correct percentage, e.g., '50%' or '75%', etc.\n If the user is asking to scroll to the next chunk/previous chunk, choose the nextChunk/prevChunk method. No arguments are required here.\n If the action implies a key press, e.g., 'press enter', 'press a', 'press space', etc., always choose the press method with the appropriate key as argument — e.g. 'a', 'Enter', 'Space'. Do not choose a click action on an on-screen keyboard. Capitalize the first character like 'Enter', 'Tab', 'Escape' only for special keys. \n `;\n\n instruction += buildActVariablesPrompt(variables);\n\n return instruction;\n}\n\nexport function buildOperatorSystemPrompt(goal: string): ChatMessage {\n return {\n role: \"system\",\n content: `You are a general-purpose agent whose job is to accomplish the user's goal across multiple model calls by running actions on the page.\n\nYou will be given a goal and a list of steps that have been taken so far. Your job is to determine if either the user's goal has been completed or if there are still steps that need to be taken.\n\n# Your current goal\n${goal}\n\n# CRITICAL: You MUST use the provided tools to take actions. Do not just describe what you want to do - actually call the appropriate tools.\n\n# Available tools and when to use them:\n- \\`act\\`: Use this to interact with the page (click, type, navigate, etc.)\n- \\`extract\\`: Use this to get information from the page\n- \\`goto\\`: Use this to navigate to a specific URL\n- \\`wait\\`: Use this to wait for a period of time\n- \\`navback\\`: Use this to go back to the previous page\n- \\`refresh\\`: Use this to refresh the current page\n- \\`close\\`: Use this ONLY when the task is complete or cannot be achieved\n- External tools: Use any additional tools (like search tools) as needed for your goal\n\n# Important guidelines\n1. ALWAYS use tools - never just provide text responses about what you plan to do\n2. Break down complex actions into individual atomic steps\n3. For \\`act\\` commands, use only one action at a time, such as:\n - Single click on a specific element\n - Type into a single input field\n - Select a single option\n4. Avoid combining multiple actions in one instruction\n5. If multiple actions are needed, they should be separate steps\n6. Only use \\`close\\` when the task is genuinely complete or impossible to achieve`,\n };\n}\n\nexport function buildCuaDefaultSystemPrompt(): string {\n return `You are a helpful assistant that can use a web browser.\\nDo not ask follow up questions, the user will trust your judgement. Today's date is ${new Date().toISOString().split(\"T\")[0]}.`;\n}\n\nexport function buildGoogleCUASystemPrompt(): ChatMessage {\n return {\n role: \"system\",\n content: `You are a general-purpose browser agent whose job is to accomplish the user's goal.\nToday's date is ${new Date().toISOString().split(\"T\")[0]}.\nYou have access to a search tool; however, in most cases you should operate within the page/url the user has provided. ONLY use the search tool if you're stuck or the task is impossible to complete within the current page.\nYou will be given a goal and a list of steps that have been taken so far. Avoid requesting the user for input as much as possible. Good luck!\n`,\n };\n}\n"]}