@browserbasehq/orca 3.2.0-preview.3 → 3.2.0-preview.5

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 (313) hide show
  1. package/dist/cjs/lib/inference.d.ts +3 -1
  2. package/dist/cjs/lib/inference.js +2 -2
  3. package/dist/cjs/lib/inference.js.map +1 -1
  4. package/dist/cjs/lib/prompt.d.ts +1 -1
  5. package/dist/cjs/lib/prompt.js +11 -2
  6. package/dist/cjs/lib/prompt.js.map +1 -1
  7. package/dist/cjs/lib/utils.d.ts +1 -0
  8. package/dist/cjs/lib/utils.js +4 -0
  9. package/dist/cjs/lib/utils.js.map +1 -1
  10. package/dist/cjs/lib/v3/agent/AgentClient.d.ts +8 -0
  11. package/dist/cjs/lib/v3/agent/AgentClient.js +13 -0
  12. package/dist/cjs/lib/v3/agent/AgentClient.js.map +1 -1
  13. package/dist/cjs/lib/v3/agent/AnthropicCUAClient.js +6 -7
  14. package/dist/cjs/lib/v3/agent/AnthropicCUAClient.js.map +1 -1
  15. package/dist/cjs/lib/v3/agent/GoogleCUAClient.js +6 -7
  16. package/dist/cjs/lib/v3/agent/GoogleCUAClient.js.map +1 -1
  17. package/dist/cjs/lib/v3/agent/MicrosoftCUAClient.js +1 -0
  18. package/dist/cjs/lib/v3/agent/MicrosoftCUAClient.js.map +1 -1
  19. package/dist/cjs/lib/v3/agent/OpenAICUAClient.d.ts +4 -4
  20. package/dist/cjs/lib/v3/agent/OpenAICUAClient.js +67 -8
  21. package/dist/cjs/lib/v3/agent/OpenAICUAClient.js.map +1 -1
  22. package/dist/cjs/lib/v3/agent/prompts/agentSystemPrompt.d.ts +2 -2
  23. package/dist/cjs/lib/v3/agent/prompts/agentSystemPrompt.js +10 -11
  24. package/dist/cjs/lib/v3/agent/prompts/agentSystemPrompt.js.map +1 -1
  25. package/dist/cjs/lib/v3/agent/tools/act.js +1 -10
  26. package/dist/cjs/lib/v3/agent/tools/act.js.map +1 -1
  27. package/dist/cjs/lib/v3/agent/tools/ariaTree.js +1 -12
  28. package/dist/cjs/lib/v3/agent/tools/ariaTree.js.map +1 -1
  29. package/dist/cjs/lib/v3/agent/tools/braveSearch.js.map +1 -1
  30. package/dist/cjs/lib/v3/agent/tools/browserbaseSearch.js.map +1 -1
  31. package/dist/cjs/lib/v3/agent/tools/click.js.map +1 -1
  32. package/dist/cjs/lib/v3/agent/tools/clickAndHold.js.map +1 -1
  33. package/dist/cjs/lib/v3/agent/tools/dragAndDrop.js.map +1 -1
  34. package/dist/cjs/lib/v3/agent/tools/extract.js +1 -10
  35. package/dist/cjs/lib/v3/agent/tools/extract.js.map +1 -1
  36. package/dist/cjs/lib/v3/agent/tools/fillFormVision.js.map +1 -1
  37. package/dist/cjs/lib/v3/agent/tools/fillform.d.ts +0 -1
  38. package/dist/cjs/lib/v3/agent/tools/fillform.js +8 -20
  39. package/dist/cjs/lib/v3/agent/tools/fillform.js.map +1 -1
  40. package/dist/cjs/lib/v3/agent/tools/index.d.ts +2 -2
  41. package/dist/cjs/lib/v3/agent/tools/index.js +53 -5
  42. package/dist/cjs/lib/v3/agent/tools/index.js.map +1 -1
  43. package/dist/cjs/lib/v3/agent/tools/keys.d.ts +1 -1
  44. package/dist/cjs/lib/v3/agent/tools/keys.js.map +1 -1
  45. package/dist/cjs/lib/v3/agent/tools/type.js.map +1 -1
  46. package/dist/cjs/lib/v3/agent/utils/captchaSolver.d.ts +76 -0
  47. package/dist/cjs/lib/v3/agent/utils/captchaSolver.js +175 -0
  48. package/dist/cjs/lib/v3/agent/utils/captchaSolver.js.map +1 -0
  49. package/dist/cjs/lib/v3/agent/utils/variables.d.ts +5 -0
  50. package/dist/cjs/lib/v3/agent/utils/variables.js +9 -0
  51. package/dist/cjs/lib/v3/agent/utils/variables.js.map +1 -1
  52. package/dist/cjs/lib/v3/flowlogger/EventEmitter.d.ts +7 -0
  53. package/dist/cjs/lib/v3/flowlogger/EventEmitter.js +30 -0
  54. package/dist/cjs/lib/v3/flowlogger/EventEmitter.js.map +1 -0
  55. package/dist/cjs/lib/v3/flowlogger/EventSink.d.ts +44 -0
  56. package/dist/cjs/lib/v3/flowlogger/EventSink.js +217 -0
  57. package/dist/cjs/lib/v3/flowlogger/EventSink.js.map +1 -0
  58. package/dist/cjs/lib/v3/flowlogger/EventStore.d.ts +26 -0
  59. package/dist/cjs/lib/v3/flowlogger/EventStore.js +135 -0
  60. package/dist/cjs/lib/v3/flowlogger/EventStore.js.map +1 -0
  61. package/dist/cjs/lib/v3/flowlogger/FlowLogger.d.ts +99 -0
  62. package/dist/cjs/lib/v3/flowlogger/FlowLogger.js +591 -0
  63. package/dist/cjs/lib/v3/flowlogger/FlowLogger.js.map +1 -0
  64. package/dist/cjs/lib/v3/flowlogger/prettify.d.ts +6 -0
  65. package/dist/cjs/lib/v3/flowlogger/prettify.js +395 -0
  66. package/dist/cjs/lib/v3/flowlogger/prettify.js.map +1 -0
  67. package/dist/cjs/lib/v3/handlers/handlerUtils/actHandlerUtils.js +43 -57
  68. package/dist/cjs/lib/v3/handlers/handlerUtils/actHandlerUtils.js.map +1 -1
  69. package/dist/cjs/lib/v3/handlers/observeHandler.js +2 -1
  70. package/dist/cjs/lib/v3/handlers/observeHandler.js.map +1 -1
  71. package/dist/cjs/lib/v3/handlers/v3AgentHandler.d.ts +2 -5
  72. package/dist/cjs/lib/v3/handlers/v3AgentHandler.js +112 -78
  73. package/dist/cjs/lib/v3/handlers/v3AgentHandler.js.map +1 -1
  74. package/dist/cjs/lib/v3/handlers/v3CuaAgentHandler.d.ts +5 -0
  75. package/dist/cjs/lib/v3/handlers/v3CuaAgentHandler.js +134 -14
  76. package/dist/cjs/lib/v3/handlers/v3CuaAgentHandler.js.map +1 -1
  77. package/dist/cjs/lib/v3/llm/aisdk.js +11 -17
  78. package/dist/cjs/lib/v3/llm/aisdk.js.map +1 -1
  79. package/dist/cjs/lib/v3/types/private/cache.d.ts +0 -1
  80. package/dist/cjs/lib/v3/types/private/cache.js.map +1 -1
  81. package/dist/cjs/lib/v3/types/private/handlers.d.ts +1 -0
  82. package/dist/cjs/lib/v3/types/private/handlers.js.map +1 -1
  83. package/dist/cjs/lib/v3/types/public/api.d.ts +24 -7
  84. package/dist/cjs/lib/v3/types/public/api.js +41 -14
  85. package/dist/cjs/lib/v3/types/public/api.js.map +1 -1
  86. package/dist/cjs/lib/v3/types/public/methods.d.ts +1 -0
  87. package/dist/cjs/lib/v3/types/public/methods.js.map +1 -1
  88. package/dist/cjs/lib/v3/types/public/options.d.ts +7 -0
  89. package/dist/cjs/lib/v3/types/public/options.js.map +1 -1
  90. package/dist/cjs/lib/v3/types/public/variables.d.ts +7 -0
  91. package/dist/cjs/lib/v3/types/public/variables.js +22 -0
  92. package/dist/cjs/lib/v3/types/public/variables.js.map +1 -0
  93. package/dist/cjs/lib/v3/understudy/cdp.d.ts +3 -12
  94. package/dist/cjs/lib/v3/understudy/cdp.js +134 -21
  95. package/dist/cjs/lib/v3/understudy/cdp.js.map +1 -1
  96. package/dist/cjs/lib/v3/understudy/page.js +28 -18
  97. package/dist/cjs/lib/v3/understudy/page.js.map +1 -1
  98. package/dist/cjs/lib/v3/v3.d.ts +12 -2
  99. package/dist/cjs/lib/v3/v3.js +194 -160
  100. package/dist/cjs/lib/v3/v3.js.map +1 -1
  101. package/dist/cjs/lib/version.d.ts +1 -1
  102. package/dist/cjs/lib/version.js +1 -1
  103. package/dist/cjs/lib/version.js.map +1 -1
  104. package/dist/cjs/tests/integration/agent-captcha-autosolve.spec.d.ts +1 -0
  105. package/dist/cjs/tests/integration/agent-captcha-autosolve.spec.js +56 -0
  106. package/dist/cjs/tests/integration/agent-captcha-autosolve.spec.js.map +1 -0
  107. package/dist/cjs/tests/integration/agent-hybrid-mode.spec.js +6 -6
  108. package/dist/cjs/tests/integration/agent-hybrid-mode.spec.js.map +1 -1
  109. package/dist/cjs/tests/integration/flowLogger.spec.d.ts +1 -0
  110. package/dist/cjs/tests/integration/flowLogger.spec.js +714 -0
  111. package/dist/cjs/tests/integration/flowLogger.spec.js.map +1 -0
  112. package/dist/cjs/tests/integration/testUtils.d.ts +33 -0
  113. package/dist/cjs/tests/integration/testUtils.js +144 -0
  114. package/dist/cjs/tests/integration/testUtils.js.map +1 -1
  115. package/dist/cjs/tests/integration/timeouts.spec.js +113 -3
  116. package/dist/cjs/tests/integration/timeouts.spec.js.map +1 -1
  117. package/dist/cjs/tests/unit/agent-captcha-hooks.test.d.ts +1 -0
  118. package/dist/cjs/tests/unit/agent-captcha-hooks.test.js +285 -0
  119. package/dist/cjs/tests/unit/agent-captcha-hooks.test.js.map +1 -0
  120. package/dist/cjs/tests/unit/agent-execution-model.test.js +25 -3
  121. package/dist/cjs/tests/unit/agent-execution-model.test.js.map +1 -1
  122. package/dist/cjs/tests/unit/agent-system-prompt-variables.test.d.ts +1 -0
  123. package/dist/cjs/tests/unit/agent-system-prompt-variables.test.js +23 -0
  124. package/dist/cjs/tests/unit/agent-system-prompt-variables.test.js.map +1 -0
  125. package/dist/cjs/tests/unit/api-client-observe-variables.test.d.ts +1 -0
  126. package/dist/cjs/tests/unit/api-client-observe-variables.test.js +86 -0
  127. package/dist/cjs/tests/unit/api-client-observe-variables.test.js.map +1 -0
  128. package/dist/cjs/tests/unit/api-variables-schema.test.d.ts +1 -0
  129. package/dist/cjs/tests/unit/api-variables-schema.test.js +37 -0
  130. package/dist/cjs/tests/unit/api-variables-schema.test.js.map +1 -0
  131. package/dist/cjs/tests/unit/browserbase-session-accessors.test.js +20 -0
  132. package/dist/cjs/tests/unit/browserbase-session-accessors.test.js.map +1 -1
  133. package/dist/cjs/tests/unit/captcha-solver.test.d.ts +1 -0
  134. package/dist/cjs/tests/unit/captcha-solver.test.js +154 -0
  135. package/dist/cjs/tests/unit/captcha-solver.test.js.map +1 -0
  136. package/dist/cjs/tests/unit/flowlogger-capturing-cdp.test.d.ts +1 -0
  137. package/dist/cjs/tests/unit/flowlogger-capturing-cdp.test.js +95 -0
  138. package/dist/cjs/tests/unit/flowlogger-capturing-cdp.test.js.map +1 -0
  139. package/dist/cjs/tests/unit/flowlogger-capturing-llm.test.d.ts +1 -0
  140. package/dist/cjs/tests/unit/flowlogger-capturing-llm.test.js +43 -0
  141. package/dist/cjs/tests/unit/flowlogger-capturing-llm.test.js.map +1 -0
  142. package/dist/cjs/tests/unit/flowlogger-eventstore.test.d.ts +1 -0
  143. package/dist/cjs/tests/unit/flowlogger-eventstore.test.js +250 -0
  144. package/dist/cjs/tests/unit/flowlogger-eventstore.test.js.map +1 -0
  145. package/dist/cjs/tests/unit/openai-cua-client.test.d.ts +1 -0
  146. package/dist/cjs/tests/unit/openai-cua-client.test.js +71 -0
  147. package/dist/cjs/tests/unit/openai-cua-client.test.js.map +1 -0
  148. package/dist/cjs/tests/unit/prompt-observe-variables.test.d.ts +1 -0
  149. package/dist/cjs/tests/unit/prompt-observe-variables.test.js +19 -0
  150. package/dist/cjs/tests/unit/prompt-observe-variables.test.js.map +1 -0
  151. package/dist/cjs/tests/unit/public-api/public-types.test.js.map +1 -1
  152. package/dist/cjs/tests/unit/timeout-handlers.test.js +50 -0
  153. package/dist/cjs/tests/unit/timeout-handlers.test.js.map +1 -1
  154. package/dist/esm/lib/inference.d.ts +3 -1
  155. package/dist/esm/lib/inference.js +2 -2
  156. package/dist/esm/lib/inference.js.map +1 -1
  157. package/dist/esm/lib/prompt.d.ts +1 -1
  158. package/dist/esm/lib/prompt.js +11 -2
  159. package/dist/esm/lib/prompt.js.map +1 -1
  160. package/dist/esm/lib/utils.d.ts +1 -0
  161. package/dist/esm/lib/utils.js +3 -0
  162. package/dist/esm/lib/utils.js.map +1 -1
  163. package/dist/esm/lib/v3/agent/AgentClient.d.ts +8 -0
  164. package/dist/esm/lib/v3/agent/AgentClient.js +13 -0
  165. package/dist/esm/lib/v3/agent/AgentClient.js.map +1 -1
  166. package/dist/esm/lib/v3/agent/AnthropicCUAClient.js +6 -7
  167. package/dist/esm/lib/v3/agent/AnthropicCUAClient.js.map +1 -1
  168. package/dist/esm/lib/v3/agent/GoogleCUAClient.js +6 -7
  169. package/dist/esm/lib/v3/agent/GoogleCUAClient.js.map +1 -1
  170. package/dist/esm/lib/v3/agent/MicrosoftCUAClient.js +1 -0
  171. package/dist/esm/lib/v3/agent/MicrosoftCUAClient.js.map +1 -1
  172. package/dist/esm/lib/v3/agent/OpenAICUAClient.d.ts +4 -4
  173. package/dist/esm/lib/v3/agent/OpenAICUAClient.js +67 -8
  174. package/dist/esm/lib/v3/agent/OpenAICUAClient.js.map +1 -1
  175. package/dist/esm/lib/v3/agent/prompts/agentSystemPrompt.d.ts +2 -2
  176. package/dist/esm/lib/v3/agent/prompts/agentSystemPrompt.js +10 -11
  177. package/dist/esm/lib/v3/agent/prompts/agentSystemPrompt.js.map +1 -1
  178. package/dist/esm/lib/v3/agent/tools/act.js +1 -10
  179. package/dist/esm/lib/v3/agent/tools/act.js.map +1 -1
  180. package/dist/esm/lib/v3/agent/tools/ariaTree.js +1 -12
  181. package/dist/esm/lib/v3/agent/tools/ariaTree.js.map +1 -1
  182. package/dist/esm/lib/v3/agent/tools/braveSearch.js.map +1 -1
  183. package/dist/esm/lib/v3/agent/tools/browserbaseSearch.js.map +1 -1
  184. package/dist/esm/lib/v3/agent/tools/click.js.map +1 -1
  185. package/dist/esm/lib/v3/agent/tools/clickAndHold.js.map +1 -1
  186. package/dist/esm/lib/v3/agent/tools/dragAndDrop.js.map +1 -1
  187. package/dist/esm/lib/v3/agent/tools/extract.js +1 -10
  188. package/dist/esm/lib/v3/agent/tools/extract.js.map +1 -1
  189. package/dist/esm/lib/v3/agent/tools/fillFormVision.js.map +1 -1
  190. package/dist/esm/lib/v3/agent/tools/fillform.d.ts +0 -1
  191. package/dist/esm/lib/v3/agent/tools/fillform.js +8 -20
  192. package/dist/esm/lib/v3/agent/tools/fillform.js.map +1 -1
  193. package/dist/esm/lib/v3/agent/tools/index.d.ts +2 -2
  194. package/dist/esm/lib/v3/agent/tools/index.js +53 -5
  195. package/dist/esm/lib/v3/agent/tools/index.js.map +1 -1
  196. package/dist/esm/lib/v3/agent/tools/keys.d.ts +1 -1
  197. package/dist/esm/lib/v3/agent/tools/keys.js.map +1 -1
  198. package/dist/esm/lib/v3/agent/tools/type.js.map +1 -1
  199. package/dist/esm/lib/v3/agent/utils/captchaSolver.d.ts +76 -0
  200. package/dist/esm/lib/v3/agent/utils/captchaSolver.js +171 -0
  201. package/dist/esm/lib/v3/agent/utils/captchaSolver.js.map +1 -0
  202. package/dist/esm/lib/v3/agent/utils/variables.d.ts +5 -0
  203. package/dist/esm/lib/v3/agent/utils/variables.js +8 -0
  204. package/dist/esm/lib/v3/agent/utils/variables.js.map +1 -1
  205. package/dist/esm/lib/v3/flowlogger/EventEmitter.d.ts +7 -0
  206. package/dist/esm/lib/v3/flowlogger/EventEmitter.js +26 -0
  207. package/dist/esm/lib/v3/flowlogger/EventEmitter.js.map +1 -0
  208. package/dist/esm/lib/v3/flowlogger/EventSink.d.ts +44 -0
  209. package/dist/esm/lib/v3/flowlogger/EventSink.js +206 -0
  210. package/dist/esm/lib/v3/flowlogger/EventSink.js.map +1 -0
  211. package/dist/esm/lib/v3/flowlogger/EventStore.d.ts +26 -0
  212. package/dist/esm/lib/v3/flowlogger/EventStore.js +127 -0
  213. package/dist/esm/lib/v3/flowlogger/EventStore.js.map +1 -0
  214. package/dist/esm/lib/v3/flowlogger/FlowLogger.d.ts +99 -0
  215. package/dist/esm/lib/v3/flowlogger/FlowLogger.js +583 -0
  216. package/dist/esm/lib/v3/flowlogger/FlowLogger.js.map +1 -0
  217. package/dist/esm/lib/v3/flowlogger/prettify.d.ts +6 -0
  218. package/dist/esm/lib/v3/flowlogger/prettify.js +389 -0
  219. package/dist/esm/lib/v3/flowlogger/prettify.js.map +1 -0
  220. package/dist/esm/lib/v3/handlers/handlerUtils/actHandlerUtils.js +43 -57
  221. package/dist/esm/lib/v3/handlers/handlerUtils/actHandlerUtils.js.map +1 -1
  222. package/dist/esm/lib/v3/handlers/observeHandler.js +2 -1
  223. package/dist/esm/lib/v3/handlers/observeHandler.js.map +1 -1
  224. package/dist/esm/lib/v3/handlers/v3AgentHandler.d.ts +2 -5
  225. package/dist/esm/lib/v3/handlers/v3AgentHandler.js +112 -78
  226. package/dist/esm/lib/v3/handlers/v3AgentHandler.js.map +1 -1
  227. package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.d.ts +5 -0
  228. package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.js +134 -14
  229. package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.js.map +1 -1
  230. package/dist/esm/lib/v3/llm/aisdk.js +11 -17
  231. package/dist/esm/lib/v3/llm/aisdk.js.map +1 -1
  232. package/dist/esm/lib/v3/types/private/cache.d.ts +0 -1
  233. package/dist/esm/lib/v3/types/private/cache.js.map +1 -1
  234. package/dist/esm/lib/v3/types/private/handlers.d.ts +1 -0
  235. package/dist/esm/lib/v3/types/private/handlers.js.map +1 -1
  236. package/dist/esm/lib/v3/types/public/api.d.ts +24 -7
  237. package/dist/esm/lib/v3/types/public/api.js +36 -12
  238. package/dist/esm/lib/v3/types/public/api.js.map +1 -1
  239. package/dist/esm/lib/v3/types/public/methods.d.ts +1 -0
  240. package/dist/esm/lib/v3/types/public/methods.js.map +1 -1
  241. package/dist/esm/lib/v3/types/public/options.d.ts +7 -0
  242. package/dist/esm/lib/v3/types/public/options.js.map +1 -1
  243. package/dist/esm/lib/v3/types/public/variables.d.ts +7 -0
  244. package/dist/esm/lib/v3/types/public/variables.js +19 -0
  245. package/dist/esm/lib/v3/types/public/variables.js.map +1 -0
  246. package/dist/esm/lib/v3/understudy/cdp.d.ts +3 -12
  247. package/dist/esm/lib/v3/understudy/cdp.js +134 -21
  248. package/dist/esm/lib/v3/understudy/cdp.js.map +1 -1
  249. package/dist/esm/lib/v3/understudy/page.js +28 -18
  250. package/dist/esm/lib/v3/understudy/page.js.map +1 -1
  251. package/dist/esm/lib/v3/v3.d.ts +12 -2
  252. package/dist/esm/lib/v3/v3.js +194 -160
  253. package/dist/esm/lib/v3/v3.js.map +1 -1
  254. package/dist/esm/lib/version.d.ts +1 -1
  255. package/dist/esm/lib/version.js +1 -1
  256. package/dist/esm/lib/version.js.map +1 -1
  257. package/dist/esm/tests/integration/agent-captcha-autosolve.spec.d.ts +1 -0
  258. package/dist/esm/tests/integration/agent-captcha-autosolve.spec.js +54 -0
  259. package/dist/esm/tests/integration/agent-captcha-autosolve.spec.js.map +1 -0
  260. package/dist/esm/tests/integration/agent-hybrid-mode.spec.js +6 -6
  261. package/dist/esm/tests/integration/agent-hybrid-mode.spec.js.map +1 -1
  262. package/dist/esm/tests/integration/flowLogger.spec.d.ts +1 -0
  263. package/dist/esm/tests/integration/flowLogger.spec.js +712 -0
  264. package/dist/esm/tests/integration/flowLogger.spec.js.map +1 -0
  265. package/dist/esm/tests/integration/testUtils.d.ts +33 -0
  266. package/dist/esm/tests/integration/testUtils.js +138 -0
  267. package/dist/esm/tests/integration/testUtils.js.map +1 -1
  268. package/dist/esm/tests/integration/timeouts.spec.js +113 -3
  269. package/dist/esm/tests/integration/timeouts.spec.js.map +1 -1
  270. package/dist/esm/tests/unit/agent-captcha-hooks.test.d.ts +1 -0
  271. package/dist/esm/tests/unit/agent-captcha-hooks.test.js +283 -0
  272. package/dist/esm/tests/unit/agent-captcha-hooks.test.js.map +1 -0
  273. package/dist/esm/tests/unit/agent-execution-model.test.js +25 -3
  274. package/dist/esm/tests/unit/agent-execution-model.test.js.map +1 -1
  275. package/dist/esm/tests/unit/agent-system-prompt-variables.test.d.ts +1 -0
  276. package/dist/esm/tests/unit/agent-system-prompt-variables.test.js +21 -0
  277. package/dist/esm/tests/unit/agent-system-prompt-variables.test.js.map +1 -0
  278. package/dist/esm/tests/unit/api-client-observe-variables.test.d.ts +1 -0
  279. package/dist/esm/tests/unit/api-client-observe-variables.test.js +84 -0
  280. package/dist/esm/tests/unit/api-client-observe-variables.test.js.map +1 -0
  281. package/dist/esm/tests/unit/api-variables-schema.test.d.ts +1 -0
  282. package/dist/esm/tests/unit/api-variables-schema.test.js +35 -0
  283. package/dist/esm/tests/unit/api-variables-schema.test.js.map +1 -0
  284. package/dist/esm/tests/unit/browserbase-session-accessors.test.js +20 -0
  285. package/dist/esm/tests/unit/browserbase-session-accessors.test.js.map +1 -1
  286. package/dist/esm/tests/unit/captcha-solver.test.d.ts +1 -0
  287. package/dist/esm/tests/unit/captcha-solver.test.js +152 -0
  288. package/dist/esm/tests/unit/captcha-solver.test.js.map +1 -0
  289. package/dist/esm/tests/unit/flowlogger-capturing-cdp.test.d.ts +1 -0
  290. package/dist/esm/tests/unit/flowlogger-capturing-cdp.test.js +93 -0
  291. package/dist/esm/tests/unit/flowlogger-capturing-cdp.test.js.map +1 -0
  292. package/dist/esm/tests/unit/flowlogger-capturing-llm.test.d.ts +1 -0
  293. package/dist/esm/tests/unit/flowlogger-capturing-llm.test.js +41 -0
  294. package/dist/esm/tests/unit/flowlogger-capturing-llm.test.js.map +1 -0
  295. package/dist/esm/tests/unit/flowlogger-eventstore.test.d.ts +1 -0
  296. package/dist/esm/tests/unit/flowlogger-eventstore.test.js +248 -0
  297. package/dist/esm/tests/unit/flowlogger-eventstore.test.js.map +1 -0
  298. package/dist/esm/tests/unit/openai-cua-client.test.d.ts +1 -0
  299. package/dist/esm/tests/unit/openai-cua-client.test.js +69 -0
  300. package/dist/esm/tests/unit/openai-cua-client.test.js.map +1 -0
  301. package/dist/esm/tests/unit/prompt-observe-variables.test.d.ts +1 -0
  302. package/dist/esm/tests/unit/prompt-observe-variables.test.js +17 -0
  303. package/dist/esm/tests/unit/prompt-observe-variables.test.js.map +1 -0
  304. package/dist/esm/tests/unit/public-api/public-types.test.js.map +1 -1
  305. package/dist/esm/tests/unit/timeout-handlers.test.js +50 -0
  306. package/dist/esm/tests/unit/timeout-handlers.test.js.map +1 -1
  307. package/package.json +4 -2
  308. package/dist/cjs/lib/v3/flowLogger.d.ts +0 -139
  309. package/dist/cjs/lib/v3/flowLogger.js +0 -881
  310. package/dist/cjs/lib/v3/flowLogger.js.map +0 -1
  311. package/dist/esm/lib/v3/flowLogger.d.ts +0 -139
  312. package/dist/esm/lib/v3/flowLogger.js +0 -868
  313. package/dist/esm/lib/v3/flowLogger.js.map +0 -1
@@ -1,10 +1,12 @@
1
- import { EventEmitter } from "events";
2
1
  import { z } from "zod";
3
2
  import { InferStagehandSchema, StagehandZodSchema } from "./zodCompat.js";
4
3
  import { LLMClient } from "./llm/LLMClient.js";
5
4
  import { AgentReplayStep } from "./types/private/index.js";
6
5
  import { AgentConfig, AgentExecuteOptions, AgentStreamExecuteOptions, AgentResult, LogLine, StagehandMetrics, Action, ActOptions, ActResult, defaultExtractSchema, ExtractOptions, HistoryEntry, ObserveOptions, pageTextSchema, V3FunctionName, V3Options, AgentStreamResult } from "./types/public/index.js";
7
6
  import { V3Context } from "./understudy/context.js";
7
+ import { type FlowLoggerContext } from "./flowlogger/FlowLogger.js";
8
+ import { EventEmitterWithWildcardSupport } from "./flowlogger/EventEmitter.js";
9
+ import { EventStore } from "./flowlogger/EventStore.js";
8
10
  /**
9
11
  * V3
10
12
  *
@@ -32,7 +34,7 @@ export declare class V3 {
32
34
  * Event bus for internal communication.
33
35
  * Emits events like 'screenshot' when screenshots are captured during agent execution.
34
36
  */
35
- readonly bus: EventEmitter;
37
+ readonly bus: EventEmitterWithWildcardSupport;
36
38
  private modelName;
37
39
  private modelClientOptions;
38
40
  private llmProvider;
@@ -49,6 +51,11 @@ export declare class V3 {
49
51
  * Returns true if the browser is running on Browserbase.
50
52
  */
51
53
  get isBrowserbase(): boolean;
54
+ /**
55
+ * Returns true if captcha auto-solving is enabled on Browserbase.
56
+ * Defaults to true when not explicitly set to false.
57
+ */
58
+ get isCaptchaAutoSolveEnabled(): boolean;
52
59
  /**
53
60
  * Returns true if advancedStealth is enabled in Browserbase settings.
54
61
  */
@@ -70,6 +77,9 @@ export declare class V3 {
70
77
  private stagehandLogger;
71
78
  private _history;
72
79
  private readonly instanceId;
80
+ private readonly sessionId;
81
+ readonly eventStore: EventStore;
82
+ readonly flowLoggerContext: FlowLoggerContext;
73
83
  private static _processGuardsInstalled;
74
84
  private static _instances;
75
85
  private cacheStorage;
@@ -71,7 +71,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
71
71
  };
72
72
  Object.defineProperty(exports, "__esModule", { value: true });
73
73
  exports.V3 = void 0;
74
- const events_1 = require("events");
75
74
  const fs_1 = __importDefault(require("fs"));
76
75
  const os_1 = __importDefault(require("os"));
77
76
  const path_1 = __importDefault(require("path"));
@@ -89,6 +88,7 @@ const extractHandler_js_1 = require("./handlers/extractHandler.js");
89
88
  const observeHandler_js_1 = require("./handlers/observeHandler.js");
90
89
  const v3AgentHandler_js_1 = require("./handlers/v3AgentHandler.js");
91
90
  const v3CuaAgentHandler_js_1 = require("./handlers/v3CuaAgentHandler.js");
91
+ const captchaSolver_js_1 = require("./agent/utils/captchaSolver.js");
92
92
  const browserbase_js_1 = require("./launch/browserbase.js");
93
93
  const local_js_1 = require("./launch/local.js");
94
94
  const LLMProvider_js_1 = require("./llm/LLMProvider.js");
@@ -102,7 +102,9 @@ const modelUtils_js_2 = require("../modelUtils.js");
102
102
  const api_js_1 = require("./api.js");
103
103
  const validateExperimentalFeatures_js_1 = require("./agent/utils/validateExperimentalFeatures.js");
104
104
  const variables_js_1 = require("./agent/utils/variables.js");
105
- const flowLogger_js_1 = require("./flowLogger.js");
105
+ const FlowLogger_js_1 = require("./flowlogger/FlowLogger.js");
106
+ const EventEmitter_js_1 = require("./flowlogger/EventEmitter.js");
107
+ const EventStore_js_1 = require("./flowlogger/EventStore.js");
106
108
  const timeoutGuard_js_1 = require("./handlers/handlerUtils/timeoutGuard.js");
107
109
  const sdkErrors_js_1 = require("./types/public/sdkErrors.js");
108
110
  const DEFAULT_MODEL_NAME = "openai/gpt-4.1-mini";
@@ -150,9 +152,15 @@ let V3 = (() => {
150
152
  return class V3 {
151
153
  static {
152
154
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
153
- _act_decorators = [(0, flowLogger_js_1.logStagehandStep)("Stagehand.act", "ACT")];
154
- _extract_decorators = [(0, flowLogger_js_1.logStagehandStep)("Stagehand.extract", "EXTRACT")];
155
- _observe_decorators = [(0, flowLogger_js_1.logStagehandStep)("Stagehand.observe", "OBSERVE")];
155
+ _act_decorators = [FlowLogger_js_1.FlowLogger.wrapWithLogging({
156
+ eventType: "StagehandAct",
157
+ })];
158
+ _extract_decorators = [FlowLogger_js_1.FlowLogger.wrapWithLogging({
159
+ eventType: "StagehandExtract",
160
+ })];
161
+ _observe_decorators = [FlowLogger_js_1.FlowLogger.wrapWithLogging({
162
+ eventType: "StagehandObserve",
163
+ })];
156
164
  __esDecorate(this, null, _act_decorators, { kind: "method", name: "act", static: false, private: false, access: { has: obj => "act" in obj, get: obj => obj.act }, metadata: _metadata }, null, _instanceExtraInitializers);
157
165
  __esDecorate(this, null, _extract_decorators, { kind: "method", name: "extract", static: false, private: false, access: { has: obj => "extract" in obj, get: obj => obj.extract }, metadata: _metadata }, null, _instanceExtraInitializers);
158
166
  __esDecorate(this, null, _observe_decorators, { kind: "method", name: "observe", static: false, private: false, access: { has: obj => "observe" in obj, get: obj => obj.observe }, metadata: _metadata }, null, _instanceExtraInitializers);
@@ -169,7 +177,7 @@ let V3 = (() => {
169
177
  * Event bus for internal communication.
170
178
  * Emits events like 'screenshot' when screenshots are captured during agent execution.
171
179
  */
172
- bus = new events_1.EventEmitter();
180
+ bus = new EventEmitter_js_1.EventEmitterWithWildcardSupport();
173
181
  modelName;
174
182
  modelClientOptions;
175
183
  llmProvider;
@@ -194,6 +202,15 @@ let V3 = (() => {
194
202
  get isBrowserbase() {
195
203
  return this.state.kind === "BROWSERBASE";
196
204
  }
205
+ /**
206
+ * Returns true if captcha auto-solving is enabled on Browserbase.
207
+ * Defaults to true when not explicitly set to false.
208
+ */
209
+ get isCaptchaAutoSolveEnabled() {
210
+ return (this.isBrowserbase &&
211
+ this.opts.browserbaseSessionCreateParams?.browserSettings
212
+ ?.solveCaptchas !== false);
213
+ }
197
214
  /**
198
215
  * Returns true if advancedStealth is enabled in Browserbase settings.
199
216
  */
@@ -237,6 +254,9 @@ let V3 = (() => {
237
254
  stagehandLogger;
238
255
  _history = [];
239
256
  instanceId;
257
+ sessionId;
258
+ eventStore;
259
+ flowLoggerContext;
240
260
  static _processGuardsInstalled = false;
241
261
  static _instances = new Set();
242
262
  cacheStorage;
@@ -276,6 +296,7 @@ let V3 = (() => {
276
296
  this.externalLogger = opts.logger;
277
297
  this.verbose = opts.verbose ?? 1;
278
298
  this.instanceId = (0, uuid_1.v7)();
299
+ this.sessionId = opts.sessionId ?? this.instanceId;
279
300
  this.keepAlive =
280
301
  opts.keepAlive ?? opts.browserbaseSessionCreateParams?.keepAlive;
281
302
  // Create per-instance StagehandLogger (handles usePino, verbose, externalLogger)
@@ -368,8 +389,21 @@ let V3 = (() => {
368
389
  act: this.act.bind(this),
369
390
  });
370
391
  this.opts = opts;
371
- // Initialize session file logger
372
- flowLogger_js_1.SessionFileLogger.init(this.instanceId, opts);
392
+ // FlowLogger always gets a per-instance session context and shared event
393
+ // bus. The attached EventStore decides which sinks are active:
394
+ // `BROWSERBASE_FLOW_LOGS=1` enables pretty stderr output,
395
+ // and `BROWSERBASE_CONFIG_DIR` enables the pretty/jsonl file sinks for this session.
396
+ this.eventStore = new EventStore_js_1.EventStore(this.sessionId, opts);
397
+ this.flowLoggerContext = FlowLogger_js_1.FlowLogger.init(this.sessionId, this.bus);
398
+ // Flow event pipeline:
399
+ // FlowLogger -> this.bus -> this.eventStore -> configured sinks/query history.
400
+ // V3 owns the bus for this session. EventStore is not another bus; it just
401
+ // receives already-emitted FlowEvents here, then fans them out to sinks and
402
+ // keeps the queryable per-session history used by /v4/log, parent/ancestor lookups, and tests.
403
+ // `on()` stores a strong reference to the handler, so the EventStore
404
+ // stays alive until this bus is garbage-collected with the rest of the V3
405
+ // object graph.
406
+ this.bus.on("*", this.eventStore.emit);
373
407
  // Track instance for global process guard handling
374
408
  V3._instances.add(this);
375
409
  }
@@ -610,9 +644,7 @@ let V3 = (() => {
610
644
  env: "LOCAL",
611
645
  cdpHeaders: lbo.cdpHeaders,
612
646
  });
613
- const logCtx = flowLogger_js_1.SessionFileLogger.getContext();
614
- this.ctx.conn.cdpLogger = (info) => flowLogger_js_1.SessionFileLogger.logCdpCallEvent(info, logCtx);
615
- this.ctx.conn.cdpEventLogger = (info) => flowLogger_js_1.SessionFileLogger.logCdpMessageEvent(info, logCtx);
647
+ this.ctx.conn.flowLoggerContext = this.flowLoggerContext;
616
648
  this.ctx.conn.onTransportClosed(this._onCdpClosed);
617
649
  this.state = {
618
650
  kind: "LOCAL",
@@ -708,9 +740,7 @@ let V3 = (() => {
708
740
  env: "LOCAL",
709
741
  localBrowserLaunchOptions: lbo,
710
742
  });
711
- const logCtx = flowLogger_js_1.SessionFileLogger.getContext();
712
- this.ctx.conn.cdpLogger = (info) => flowLogger_js_1.SessionFileLogger.logCdpCallEvent(info, logCtx);
713
- this.ctx.conn.cdpEventLogger = (info) => flowLogger_js_1.SessionFileLogger.logCdpMessageEvent(info, logCtx);
743
+ this.ctx.conn.flowLoggerContext = this.flowLoggerContext;
714
744
  this.ctx.conn.onTransportClosed(this._onCdpClosed);
715
745
  this.state = {
716
746
  kind: "LOCAL",
@@ -745,9 +775,13 @@ let V3 = (() => {
745
775
  const baseSessionParams = this.opts.browserbaseSessionCreateParams ?? {};
746
776
  const resolvedKeepAlive = this.keepAlive;
747
777
  const keepAlive = this.keepAlive === true;
748
- const effectiveSessionParams = resolvedKeepAlive !== undefined
749
- ? { ...baseSessionParams, keepAlive: resolvedKeepAlive }
750
- : baseSessionParams;
778
+ let effectiveSessionParams = baseSessionParams;
779
+ if (resolvedKeepAlive !== undefined) {
780
+ effectiveSessionParams = {
781
+ ...baseSessionParams,
782
+ keepAlive: resolvedKeepAlive,
783
+ };
784
+ }
751
785
  if (!this.disableAPI && !this.experimental) {
752
786
  this.apiClient = new api_js_1.StagehandAPIClient({
753
787
  apiKey,
@@ -792,9 +826,7 @@ let V3 = (() => {
792
826
  env: "BROWSERBASE",
793
827
  apiClient: this.apiClient,
794
828
  });
795
- const logCtx = flowLogger_js_1.SessionFileLogger.getContext();
796
- this.ctx.conn.cdpLogger = (info) => flowLogger_js_1.SessionFileLogger.logCdpCallEvent(info, logCtx);
797
- this.ctx.conn.cdpEventLogger = (info) => flowLogger_js_1.SessionFileLogger.logCdpMessageEvent(info, logCtx);
829
+ this.ctx.conn.flowLoggerContext = this.flowLoggerContext;
798
830
  this.ctx.conn.onTransportClosed(this._onCdpClosed);
799
831
  this.state = { kind: "BROWSERBASE", sessionId, ws, bb };
800
832
  this.browserbaseSessionId = sessionId;
@@ -1070,6 +1102,7 @@ let V3 = (() => {
1070
1102
  const handlerParams = {
1071
1103
  instruction,
1072
1104
  model: options?.model,
1105
+ variables: options?.variables,
1073
1106
  timeout: options?.timeout,
1074
1107
  selector: options?.selector,
1075
1108
  page: page,
@@ -1089,6 +1122,7 @@ let V3 = (() => {
1089
1122
  // history: record observe call (omit page object)
1090
1123
  this.addToHistory("observe", {
1091
1124
  instruction,
1125
+ variables: options?.variables,
1092
1126
  timeout: options?.timeout,
1093
1127
  }, results);
1094
1128
  return results;
@@ -1137,7 +1171,7 @@ let V3 = (() => {
1137
1171
  try {
1138
1172
  // Close session file logger
1139
1173
  try {
1140
- await flowLogger_js_1.SessionFileLogger.close();
1174
+ await FlowLogger_js_1.FlowLogger.close(this.flowLoggerContext);
1141
1175
  }
1142
1176
  catch {
1143
1177
  // ignore
@@ -1173,6 +1207,12 @@ let V3 = (() => {
1173
1207
  catch {
1174
1208
  // ignore
1175
1209
  }
1210
+ try {
1211
+ await this.eventStore.destroy();
1212
+ }
1213
+ catch {
1214
+ // ignore
1215
+ }
1176
1216
  try {
1177
1217
  this.bus.removeAllListeners();
1178
1218
  }
@@ -1350,7 +1390,7 @@ let V3 = (() => {
1350
1390
  ? this.resolveLlmClient(options.model)
1351
1391
  : this.llmClient;
1352
1392
  const resolvedExecutionModel = options?.executionModel ?? options?.model;
1353
- const handler = new v3AgentHandler_js_1.V3AgentHandler(this, this.logger, agentLlmClient, resolvedExecutionModel, options?.systemPrompt, tools, options?.mode);
1393
+ const handler = new v3AgentHandler_js_1.V3AgentHandler(this, this.logger, agentLlmClient, resolvedExecutionModel, options?.systemPrompt, tools, options?.mode, this.isCaptchaAutoSolveEnabled);
1354
1394
  const resolvedOptions = typeof instructionOrOptions === "string"
1355
1395
  ? {
1356
1396
  instruction: instructionOrOptions,
@@ -1439,152 +1479,59 @@ let V3 = (() => {
1439
1479
  throw new index_js_1.CuaModelRequiredError(index_js_1.AVAILABLE_CUA_MODELS);
1440
1480
  }
1441
1481
  const agentConfigSignature = this.agentCache.buildConfigSignature(options);
1442
- return {
1443
- execute: async (instructionOrOptions) => (0, logger_js_2.withInstanceLogContext)(this.instanceId, async () => {
1444
- (0, validateExperimentalFeatures_js_1.validateExperimentalFeatures)({
1445
- isExperimental: this.experimental,
1446
- agentConfig: options,
1447
- executeOptions: typeof instructionOrOptions === "object"
1448
- ? instructionOrOptions
1449
- : null,
1450
- });
1451
- flowLogger_js_1.SessionFileLogger.logAgentTaskStarted({
1452
- invocation: "Agent.execute",
1453
- args: [instructionOrOptions],
1454
- });
1455
- const tools = options?.integrations
1456
- ? await (0, utils_js_2.resolveTools)(options.integrations, options.tools)
1457
- : (options?.tools ?? {});
1458
- const handler = new v3CuaAgentHandler_js_1.V3CuaAgentHandler(this, this.logger, {
1459
- modelName,
1460
- clientOptions,
1461
- userProvidedInstructions: options.systemPrompt ??
1462
- `You are a helpful assistant that can use a web browser.\nDo not ask follow up questions, the user will trust your judgement.`,
1463
- }, tools);
1464
- const resolvedOptions = typeof instructionOrOptions === "string"
1465
- ? {
1466
- instruction: instructionOrOptions,
1467
- toolTimeout: DEFAULT_AGENT_TOOL_TIMEOUT_MS,
1468
- }
1469
- : {
1470
- ...instructionOrOptions,
1471
- toolTimeout: instructionOrOptions.toolTimeout ??
1472
- DEFAULT_AGENT_TOOL_TIMEOUT_MS,
1473
- };
1474
- if (resolvedOptions.page) {
1475
- const normalizedPage = await this.normalizeToV3Page(resolvedOptions.page);
1476
- this.ctx.setActivePage(normalizedPage);
1477
- }
1478
- const instruction = resolvedOptions.instruction.trim();
1479
- const sanitizedOptions = this.agentCache.sanitizeExecuteOptions(resolvedOptions);
1480
- const cacheVariables = (0, variables_js_1.flattenVariables)(resolvedOptions.variables);
1481
- let cacheContext = null;
1482
- if (this.agentCache.shouldAttemptCache(instruction)) {
1483
- const startPage = await this.ctx.awaitActivePage();
1484
- cacheContext = await this.agentCache.prepareContext({
1485
- instruction,
1486
- options: sanitizedOptions,
1487
- configSignature: agentConfigSignature,
1488
- page: startPage,
1489
- variables: cacheVariables,
1490
- });
1491
- if (cacheContext) {
1492
- const replayed = await this.agentCache.tryReplay(cacheContext);
1493
- if (replayed) {
1494
- flowLogger_js_1.SessionFileLogger.logAgentTaskCompleted({ cacheHit: true });
1495
- return replayed;
1496
- }
1497
- }
1498
- }
1499
- let agentSteps = [];
1500
- const shouldRecordLocally = !!cacheContext && (!this.apiClient || this.experimental);
1501
- if (shouldRecordLocally) {
1502
- this.beginAgentReplayRecording();
1503
- }
1504
- let result;
1505
- try {
1506
- if (this.apiClient && !this.experimental) {
1507
- const page = await this.ctx.awaitActivePage();
1508
- result = await this.apiClient.agentExecute(options, resolvedOptions, page.mainFrameId(), !!cacheContext);
1509
- if (cacheContext) {
1510
- const transferredEntry = this.apiClient.consumeLatestAgentCacheEntry();
1511
- await this.agentCache.storeTransferredEntry(transferredEntry);
1512
- }
1513
- }
1514
- else {
1515
- result = await handler.execute(instructionOrOptions);
1516
- }
1517
- if (shouldRecordLocally) {
1518
- agentSteps = this.endAgentReplayRecording();
1519
- }
1520
- if (shouldRecordLocally &&
1521
- cacheContext &&
1522
- result.success &&
1523
- agentSteps.length > 0) {
1524
- await this.agentCache.store(cacheContext, agentSteps, result);
1525
- }
1526
- return result;
1527
- }
1528
- catch (err) {
1529
- if (shouldRecordLocally)
1530
- this.discardAgentReplayRecording();
1531
- throw err;
1532
- }
1533
- finally {
1534
- if (shouldRecordLocally) {
1535
- this.discardAgentReplayRecording();
1536
- }
1537
- flowLogger_js_1.SessionFileLogger.logAgentTaskCompleted();
1538
- }
1539
- }),
1540
- };
1541
- }
1542
- // Default: AISDK tools-based agent
1543
- const agentConfigSignature = this.agentCache.buildConfigSignature(options);
1544
- const isStreaming = options?.stream ?? false;
1545
- return {
1546
- execute: async (instructionOrOptions) => (0, logger_js_2.withInstanceLogContext)(this.instanceId, async () => {
1482
+ const execute = async (instructionOrOptions) => (0, logger_js_2.withInstanceLogContext)(this.instanceId, async () => {
1547
1483
  (0, validateExperimentalFeatures_js_1.validateExperimentalFeatures)({
1548
1484
  isExperimental: this.experimental,
1549
1485
  agentConfig: options,
1550
1486
  executeOptions: typeof instructionOrOptions === "object"
1551
1487
  ? instructionOrOptions
1552
1488
  : null,
1553
- isStreaming,
1554
- });
1555
- flowLogger_js_1.SessionFileLogger.logAgentTaskStarted({
1556
- invocation: "Agent.execute",
1557
- args: [instructionOrOptions],
1558
1489
  });
1559
- // Streaming mode
1560
- if (isStreaming) {
1561
- const { handler, resolvedOptions, cacheContext, llmClient } = await this.prepareAgentExecution(options, instructionOrOptions, agentConfigSignature);
1490
+ const tools = options?.integrations
1491
+ ? await (0, utils_js_2.resolveTools)(options.integrations, options.tools)
1492
+ : (options?.tools ?? {});
1493
+ const handler = new v3CuaAgentHandler_js_1.V3CuaAgentHandler(this, this.logger, {
1494
+ modelName,
1495
+ clientOptions,
1496
+ userProvidedInstructions: (options.systemPrompt ??
1497
+ `You are a helpful assistant that can use a web browser.\nDo not ask follow up questions, the user will trust your judgement.`) +
1498
+ (this.isCaptchaAutoSolveEnabled
1499
+ ? captchaSolver_js_1.CAPTCHA_CUA_SYSTEM_PROMPT_NOTE
1500
+ : ""),
1501
+ }, tools);
1502
+ const resolvedOptions = typeof instructionOrOptions === "string"
1503
+ ? {
1504
+ instruction: instructionOrOptions,
1505
+ toolTimeout: DEFAULT_AGENT_TOOL_TIMEOUT_MS,
1506
+ }
1507
+ : {
1508
+ ...instructionOrOptions,
1509
+ toolTimeout: instructionOrOptions.toolTimeout ??
1510
+ DEFAULT_AGENT_TOOL_TIMEOUT_MS,
1511
+ };
1512
+ if (resolvedOptions.page) {
1513
+ const normalizedPage = await this.normalizeToV3Page(resolvedOptions.page);
1514
+ this.ctx.setActivePage(normalizedPage);
1515
+ }
1516
+ const instruction = resolvedOptions.instruction.trim();
1517
+ const sanitizedOptions = this.agentCache.sanitizeExecuteOptions(resolvedOptions);
1518
+ const cacheVariables = (0, variables_js_1.flattenVariables)(resolvedOptions.variables);
1519
+ let cacheContext = null;
1520
+ if (this.agentCache.shouldAttemptCache(instruction)) {
1521
+ const startPage = await this.ctx.awaitActivePage();
1522
+ cacheContext = await this.agentCache.prepareContext({
1523
+ instruction,
1524
+ options: sanitizedOptions,
1525
+ configSignature: agentConfigSignature,
1526
+ page: startPage,
1527
+ variables: cacheVariables,
1528
+ });
1562
1529
  if (cacheContext) {
1563
- const replayed = await this.agentCache.tryReplayAsStream(cacheContext, llmClient);
1530
+ const replayed = await this.agentCache.tryReplay(cacheContext);
1564
1531
  if (replayed) {
1565
- flowLogger_js_1.SessionFileLogger.logAgentTaskCompleted({ cacheHit: true });
1566
1532
  return replayed;
1567
1533
  }
1568
1534
  }
1569
- const streamResult = await handler.stream(resolvedOptions);
1570
- if (cacheContext) {
1571
- const wrappedStream = this.agentCache.wrapStreamForCaching(cacheContext, streamResult, () => this.beginAgentReplayRecording(), () => this.endAgentReplayRecording(), () => this.discardAgentReplayRecording());
1572
- // Log completion when stream is returned (stream completes asynchronously)
1573
- flowLogger_js_1.SessionFileLogger.logAgentTaskCompleted();
1574
- return wrappedStream;
1575
- }
1576
- // Log completion when stream is returned (stream completes asynchronously)
1577
- flowLogger_js_1.SessionFileLogger.logAgentTaskCompleted();
1578
- return streamResult;
1579
- }
1580
- // Non-streaming mode (default)
1581
- const { handler, resolvedOptions, cacheContext, llmClient } = await this.prepareAgentExecution(options, instructionOrOptions, agentConfigSignature);
1582
- if (cacheContext) {
1583
- const replayed = await this.agentCache.tryReplay(cacheContext, llmClient);
1584
- if (replayed) {
1585
- flowLogger_js_1.SessionFileLogger.logAgentTaskCompleted({ cacheHit: true });
1586
- return replayed;
1587
- }
1588
1535
  }
1589
1536
  let agentSteps = [];
1590
1537
  const shouldRecordLocally = !!cacheContext && (!this.apiClient || this.experimental);
@@ -1595,14 +1542,14 @@ let V3 = (() => {
1595
1542
  try {
1596
1543
  if (this.apiClient && !this.experimental) {
1597
1544
  const page = await this.ctx.awaitActivePage();
1598
- result = await this.apiClient.agentExecute(options ?? {}, resolvedOptions, page.mainFrameId(), !!cacheContext);
1545
+ result = await this.apiClient.agentExecute(options, resolvedOptions, page.mainFrameId(), !!cacheContext);
1599
1546
  if (cacheContext) {
1600
1547
  const transferredEntry = this.apiClient.consumeLatestAgentCacheEntry();
1601
1548
  await this.agentCache.storeTransferredEntry(transferredEntry);
1602
1549
  }
1603
1550
  }
1604
1551
  else {
1605
- result = await handler.execute(resolvedOptions);
1552
+ result = await handler.execute(instructionOrOptions);
1606
1553
  }
1607
1554
  if (shouldRecordLocally) {
1608
1555
  agentSteps = this.endAgentReplayRecording();
@@ -1624,9 +1571,96 @@ let V3 = (() => {
1624
1571
  if (shouldRecordLocally) {
1625
1572
  this.discardAgentReplayRecording();
1626
1573
  }
1627
- flowLogger_js_1.SessionFileLogger.logAgentTaskCompleted();
1628
1574
  }
1629
- }),
1575
+ });
1576
+ return {
1577
+ execute: FlowLogger_js_1.FlowLogger.wrapWithLogging({
1578
+ eventType: "AgentExecute",
1579
+ context: this.flowLoggerContext,
1580
+ })(execute),
1581
+ };
1582
+ }
1583
+ // Default: AISDK tools-based agent
1584
+ const agentConfigSignature = this.agentCache.buildConfigSignature(options);
1585
+ const isStreaming = options?.stream ?? false;
1586
+ const execute = async (instructionOrOptions) => (0, logger_js_2.withInstanceLogContext)(this.instanceId, async () => {
1587
+ (0, validateExperimentalFeatures_js_1.validateExperimentalFeatures)({
1588
+ isExperimental: this.experimental,
1589
+ agentConfig: options,
1590
+ executeOptions: typeof instructionOrOptions === "object"
1591
+ ? instructionOrOptions
1592
+ : null,
1593
+ isStreaming,
1594
+ });
1595
+ // Streaming mode
1596
+ if (isStreaming) {
1597
+ const { handler, resolvedOptions, cacheContext, llmClient } = await this.prepareAgentExecution(options, instructionOrOptions, agentConfigSignature);
1598
+ if (cacheContext) {
1599
+ const replayed = await this.agentCache.tryReplayAsStream(cacheContext, llmClient);
1600
+ if (replayed) {
1601
+ return replayed;
1602
+ }
1603
+ }
1604
+ const streamResult = await handler.stream(resolvedOptions);
1605
+ if (cacheContext) {
1606
+ const wrappedStream = this.agentCache.wrapStreamForCaching(cacheContext, streamResult, () => this.beginAgentReplayRecording(), () => this.endAgentReplayRecording(), () => this.discardAgentReplayRecording());
1607
+ return wrappedStream;
1608
+ }
1609
+ return streamResult;
1610
+ }
1611
+ // Non-streaming mode (default)
1612
+ const { handler, resolvedOptions, cacheContext, llmClient } = await this.prepareAgentExecution(options, instructionOrOptions, agentConfigSignature);
1613
+ if (cacheContext) {
1614
+ const replayed = await this.agentCache.tryReplay(cacheContext, llmClient);
1615
+ if (replayed) {
1616
+ return replayed;
1617
+ }
1618
+ }
1619
+ let agentSteps = [];
1620
+ const shouldRecordLocally = !!cacheContext && (!this.apiClient || this.experimental);
1621
+ if (shouldRecordLocally) {
1622
+ this.beginAgentReplayRecording();
1623
+ }
1624
+ let result;
1625
+ try {
1626
+ if (this.apiClient && !this.experimental) {
1627
+ const page = await this.ctx.awaitActivePage();
1628
+ result = await this.apiClient.agentExecute(options ?? {}, resolvedOptions, page.mainFrameId(), !!cacheContext);
1629
+ if (cacheContext) {
1630
+ const transferredEntry = this.apiClient.consumeLatestAgentCacheEntry();
1631
+ await this.agentCache.storeTransferredEntry(transferredEntry);
1632
+ }
1633
+ }
1634
+ else {
1635
+ result = await handler.execute(resolvedOptions);
1636
+ }
1637
+ if (shouldRecordLocally) {
1638
+ agentSteps = this.endAgentReplayRecording();
1639
+ }
1640
+ if (shouldRecordLocally &&
1641
+ cacheContext &&
1642
+ result.success &&
1643
+ agentSteps.length > 0) {
1644
+ await this.agentCache.store(cacheContext, agentSteps, result);
1645
+ }
1646
+ return result;
1647
+ }
1648
+ catch (err) {
1649
+ if (shouldRecordLocally)
1650
+ this.discardAgentReplayRecording();
1651
+ throw err;
1652
+ }
1653
+ finally {
1654
+ if (shouldRecordLocally) {
1655
+ this.discardAgentReplayRecording();
1656
+ }
1657
+ }
1658
+ });
1659
+ return {
1660
+ execute: FlowLogger_js_1.FlowLogger.wrapWithLogging({
1661
+ eventType: "AgentExecute",
1662
+ context: this.flowLoggerContext,
1663
+ })(execute),
1630
1664
  };
1631
1665
  }
1632
1666
  };