@browserbasehq/orca 3.1.0-patch.4 → 3.2.0-preview.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (297) hide show
  1. package/dist/cjs/lib/inference.js +1 -4
  2. package/dist/cjs/lib/inference.js.map +1 -1
  3. package/dist/cjs/lib/utils.d.ts +1 -0
  4. package/dist/cjs/lib/utils.js +4 -0
  5. package/dist/cjs/lib/utils.js.map +1 -1
  6. package/dist/cjs/lib/v3/agent/AgentProvider.js +0 -1
  7. package/dist/cjs/lib/v3/agent/AgentProvider.js.map +1 -1
  8. package/dist/cjs/lib/v3/agent/AnthropicCUAClient.js +4 -6
  9. package/dist/cjs/lib/v3/agent/AnthropicCUAClient.js.map +1 -1
  10. package/dist/cjs/lib/v3/agent/GoogleCUAClient.js +4 -6
  11. package/dist/cjs/lib/v3/agent/GoogleCUAClient.js.map +1 -1
  12. package/dist/cjs/lib/v3/agent/OpenAICUAClient.js +4 -6
  13. package/dist/cjs/lib/v3/agent/OpenAICUAClient.js.map +1 -1
  14. package/dist/cjs/lib/v3/agent/prompts/agentSystemPrompt.d.ts +2 -0
  15. package/dist/cjs/lib/v3/agent/prompts/agentSystemPrompt.js +2 -2
  16. package/dist/cjs/lib/v3/agent/prompts/agentSystemPrompt.js.map +1 -1
  17. package/dist/cjs/lib/v3/agent/tools/act.d.ts +1 -1
  18. package/dist/cjs/lib/v3/agent/tools/act.js +20 -4
  19. package/dist/cjs/lib/v3/agent/tools/act.js.map +1 -1
  20. package/dist/cjs/lib/v3/agent/tools/ariaTree.d.ts +8 -1
  21. package/dist/cjs/lib/v3/agent/tools/ariaTree.js +60 -22
  22. package/dist/cjs/lib/v3/agent/tools/ariaTree.js.map +1 -1
  23. package/dist/cjs/lib/v3/agent/tools/{search.js → braveSearch.js} +1 -1
  24. package/dist/cjs/lib/v3/agent/tools/braveSearch.js.map +1 -0
  25. package/dist/cjs/lib/v3/agent/tools/browserbaseSearch.d.ts +13 -0
  26. package/dist/cjs/lib/v3/agent/tools/browserbaseSearch.js +70 -0
  27. package/dist/cjs/lib/v3/agent/tools/browserbaseSearch.js.map +1 -0
  28. package/dist/cjs/lib/v3/agent/tools/click.js +23 -31
  29. package/dist/cjs/lib/v3/agent/tools/click.js.map +1 -1
  30. package/dist/cjs/lib/v3/agent/tools/dragAndDrop.js +22 -30
  31. package/dist/cjs/lib/v3/agent/tools/dragAndDrop.js.map +1 -1
  32. package/dist/cjs/lib/v3/agent/tools/extract.d.ts +2 -2
  33. package/dist/cjs/lib/v3/agent/tools/extract.js +16 -3
  34. package/dist/cjs/lib/v3/agent/tools/extract.js.map +1 -1
  35. package/dist/cjs/lib/v3/agent/tools/fillFormVision.js +30 -30
  36. package/dist/cjs/lib/v3/agent/tools/fillFormVision.js.map +1 -1
  37. package/dist/cjs/lib/v3/agent/tools/fillform.d.ts +7 -1
  38. package/dist/cjs/lib/v3/agent/tools/fillform.js +60 -37
  39. package/dist/cjs/lib/v3/agent/tools/fillform.js.map +1 -1
  40. package/dist/cjs/lib/v3/agent/tools/index.d.ts +19 -3
  41. package/dist/cjs/lib/v3/agent/tools/index.js +12 -8
  42. package/dist/cjs/lib/v3/agent/tools/index.js.map +1 -1
  43. package/dist/cjs/lib/v3/agent/tools/screenshot.d.ts +8 -0
  44. package/dist/cjs/lib/v3/agent/tools/screenshot.js +32 -15
  45. package/dist/cjs/lib/v3/agent/tools/screenshot.js.map +1 -1
  46. package/dist/cjs/lib/v3/agent/tools/scroll.js +12 -0
  47. package/dist/cjs/lib/v3/agent/tools/scroll.js.map +1 -1
  48. package/dist/cjs/lib/v3/agent/tools/type.js +23 -31
  49. package/dist/cjs/lib/v3/agent/tools/type.js.map +1 -1
  50. package/dist/cjs/lib/v3/agent/tools/wait.js +6 -0
  51. package/dist/cjs/lib/v3/agent/tools/wait.js.map +1 -1
  52. package/dist/cjs/lib/v3/agent/utils/handleDoneToolCall.js +4 -0
  53. package/dist/cjs/lib/v3/agent/utils/handleDoneToolCall.js.map +1 -1
  54. package/dist/cjs/lib/v3/api.d.ts +2 -2
  55. package/dist/cjs/lib/v3/api.js +1 -1
  56. package/dist/cjs/lib/v3/api.js.map +1 -1
  57. package/dist/cjs/lib/v3/cache/ActCache.d.ts +0 -1
  58. package/dist/cjs/lib/v3/cache/ActCache.js +2 -18
  59. package/dist/cjs/lib/v3/cache/ActCache.js.map +1 -1
  60. package/dist/cjs/lib/v3/eventStore.d.ts +41 -0
  61. package/dist/cjs/lib/v3/eventStore.js +375 -0
  62. package/dist/cjs/lib/v3/eventStore.js.map +1 -0
  63. package/dist/cjs/lib/v3/flowLogger.d.ts +62 -103
  64. package/dist/cjs/lib/v3/flowLogger.js +362 -773
  65. package/dist/cjs/lib/v3/flowLogger.js.map +1 -1
  66. package/dist/cjs/lib/v3/handlers/actHandler.js +1 -2
  67. package/dist/cjs/lib/v3/handlers/actHandler.js.map +1 -1
  68. package/dist/cjs/lib/v3/handlers/extractHandler.js +2 -2
  69. package/dist/cjs/lib/v3/handlers/extractHandler.js.map +1 -1
  70. package/dist/cjs/lib/v3/handlers/handlerUtils/actHandlerUtils.js +21 -33
  71. package/dist/cjs/lib/v3/handlers/handlerUtils/actHandlerUtils.js.map +1 -1
  72. package/dist/cjs/lib/v3/handlers/observeHandler.js +1 -2
  73. package/dist/cjs/lib/v3/handlers/observeHandler.js.map +1 -1
  74. package/dist/cjs/lib/v3/handlers/v3AgentHandler.d.ts +0 -4
  75. package/dist/cjs/lib/v3/handlers/v3AgentHandler.js +23 -48
  76. package/dist/cjs/lib/v3/handlers/v3AgentHandler.js.map +1 -1
  77. package/dist/cjs/lib/v3/handlers/v3CuaAgentHandler.js +10 -12
  78. package/dist/cjs/lib/v3/handlers/v3CuaAgentHandler.js.map +1 -1
  79. package/dist/cjs/lib/v3/index.d.ts +2 -1
  80. package/dist/cjs/lib/v3/launch/browserbase.d.ts +1 -1
  81. package/dist/cjs/lib/v3/launch/browserbase.js +4 -9
  82. package/dist/cjs/lib/v3/launch/browserbase.js.map +1 -1
  83. package/dist/cjs/lib/v3/llm/LLMProvider.js +0 -5
  84. package/dist/cjs/lib/v3/llm/LLMProvider.js.map +1 -1
  85. package/dist/cjs/lib/v3/llm/aisdk.js +10 -16
  86. package/dist/cjs/lib/v3/llm/aisdk.js.map +1 -1
  87. package/dist/cjs/lib/v3/runtimePaths.js +2 -1
  88. package/dist/cjs/lib/v3/runtimePaths.js.map +1 -1
  89. package/dist/cjs/lib/v3/shutdown/supervisor.js +2 -2
  90. package/dist/cjs/lib/v3/shutdown/supervisor.js.map +1 -1
  91. package/dist/cjs/lib/v3/timeoutConfig.d.ts +1 -1
  92. package/dist/cjs/lib/v3/timeoutConfig.js +5 -0
  93. package/dist/cjs/lib/v3/timeoutConfig.js.map +1 -1
  94. package/dist/cjs/lib/v3/types/private/shutdown.d.ts +1 -1
  95. package/dist/cjs/lib/v3/types/private/shutdown.js.map +1 -1
  96. package/dist/cjs/lib/v3/types/public/agent.d.ts +28 -3
  97. package/dist/cjs/lib/v3/types/public/agent.js +0 -1
  98. package/dist/cjs/lib/v3/types/public/agent.js.map +1 -1
  99. package/dist/cjs/lib/v3/types/public/api.d.ts +3 -0
  100. package/dist/cjs/lib/v3/types/public/api.js +1 -0
  101. package/dist/cjs/lib/v3/types/public/api.js.map +1 -1
  102. package/dist/cjs/lib/v3/types/public/model.d.ts +4 -2
  103. package/dist/cjs/lib/v3/types/public/model.js.map +1 -1
  104. package/dist/cjs/lib/v3/types/public/options.d.ts +6 -0
  105. package/dist/cjs/lib/v3/types/public/options.js.map +1 -1
  106. package/dist/cjs/lib/v3/understudy/cdp.d.ts +8 -13
  107. package/dist/cjs/lib/v3/understudy/cdp.js +137 -17
  108. package/dist/cjs/lib/v3/understudy/cdp.js.map +1 -1
  109. package/dist/cjs/lib/v3/understudy/context.d.ts +1 -0
  110. package/dist/cjs/lib/v3/understudy/context.js +142 -60
  111. package/dist/cjs/lib/v3/understudy/context.js.map +1 -1
  112. package/dist/cjs/lib/v3/understudy/frame.js +23 -6
  113. package/dist/cjs/lib/v3/understudy/frame.js.map +1 -1
  114. package/dist/cjs/lib/v3/understudy/page.d.ts +13 -0
  115. package/dist/cjs/lib/v3/understudy/page.js +88 -20
  116. package/dist/cjs/lib/v3/understudy/page.js.map +1 -1
  117. package/dist/cjs/lib/v3/understudy/screenshotUtils.d.ts +0 -1
  118. package/dist/cjs/lib/v3/understudy/screenshotUtils.js +0 -18
  119. package/dist/cjs/lib/v3/understudy/screenshotUtils.js.map +1 -1
  120. package/dist/cjs/lib/v3/v3.d.ts +10 -0
  121. package/dist/cjs/lib/v3/v3.js +210 -172
  122. package/dist/cjs/lib/v3/v3.js.map +1 -1
  123. package/dist/cjs/tests/integration/cdp-session-detached.spec.js +1 -1
  124. package/dist/cjs/tests/integration/cdp-session-detached.spec.js.map +1 -1
  125. package/dist/cjs/tests/integration/context-addInitScript.spec.js +104 -11
  126. package/dist/cjs/tests/integration/context-addInitScript.spec.js.map +1 -1
  127. package/dist/cjs/tests/integration/iframe-ctx-addInitScript-race.spec.js +219 -0
  128. package/dist/cjs/tests/integration/iframe-ctx-addInitScript-race.spec.js.map +1 -0
  129. package/dist/cjs/tests/integration/page-extra-http-headers.spec.js +85 -0
  130. package/dist/cjs/tests/integration/page-extra-http-headers.spec.js.map +1 -0
  131. package/dist/cjs/tests/integration/page-screenshot.spec.js +1 -1
  132. package/dist/cjs/tests/integration/page-screenshot.spec.js.map +1 -1
  133. package/dist/cjs/tests/integration/timeouts.spec.js +168 -0
  134. package/dist/cjs/tests/integration/timeouts.spec.js.map +1 -1
  135. package/dist/cjs/tests/unit/model-deprecation.test.js +5 -8
  136. package/dist/cjs/tests/unit/model-deprecation.test.js.map +1 -1
  137. package/dist/cjs/tests/unit/page-extra-http-headers.test.d.ts +1 -0
  138. package/dist/cjs/tests/unit/page-extra-http-headers.test.js +92 -0
  139. package/dist/cjs/tests/unit/page-extra-http-headers.test.js.map +1 -0
  140. package/dist/cjs/tests/unit/public-api/llm-and-agents.test.js +13 -1
  141. package/dist/cjs/tests/unit/public-api/llm-and-agents.test.js.map +1 -1
  142. package/dist/cjs/tests/unit/public-api/public-types.test.js.map +1 -1
  143. package/dist/esm/lib/inference.js +1 -4
  144. package/dist/esm/lib/inference.js.map +1 -1
  145. package/dist/esm/lib/utils.d.ts +1 -0
  146. package/dist/esm/lib/utils.js +3 -0
  147. package/dist/esm/lib/utils.js.map +1 -1
  148. package/dist/esm/lib/v3/agent/AgentProvider.js +0 -1
  149. package/dist/esm/lib/v3/agent/AgentProvider.js.map +1 -1
  150. package/dist/esm/lib/v3/agent/AnthropicCUAClient.js +5 -7
  151. package/dist/esm/lib/v3/agent/AnthropicCUAClient.js.map +1 -1
  152. package/dist/esm/lib/v3/agent/GoogleCUAClient.js +5 -7
  153. package/dist/esm/lib/v3/agent/GoogleCUAClient.js.map +1 -1
  154. package/dist/esm/lib/v3/agent/OpenAICUAClient.js +5 -7
  155. package/dist/esm/lib/v3/agent/OpenAICUAClient.js.map +1 -1
  156. package/dist/esm/lib/v3/agent/prompts/agentSystemPrompt.d.ts +2 -0
  157. package/dist/esm/lib/v3/agent/prompts/agentSystemPrompt.js +2 -2
  158. package/dist/esm/lib/v3/agent/prompts/agentSystemPrompt.js.map +1 -1
  159. package/dist/esm/lib/v3/agent/tools/act.d.ts +1 -1
  160. package/dist/esm/lib/v3/agent/tools/act.js +20 -4
  161. package/dist/esm/lib/v3/agent/tools/act.js.map +1 -1
  162. package/dist/esm/lib/v3/agent/tools/ariaTree.d.ts +8 -1
  163. package/dist/esm/lib/v3/agent/tools/ariaTree.js +60 -22
  164. package/dist/esm/lib/v3/agent/tools/ariaTree.js.map +1 -1
  165. package/dist/esm/lib/v3/agent/tools/{search.js → braveSearch.js} +1 -1
  166. package/dist/esm/lib/v3/agent/tools/braveSearch.js.map +1 -0
  167. package/dist/esm/lib/v3/agent/tools/browserbaseSearch.d.ts +13 -0
  168. package/dist/esm/lib/v3/agent/tools/browserbaseSearch.js +66 -0
  169. package/dist/esm/lib/v3/agent/tools/browserbaseSearch.js.map +1 -0
  170. package/dist/esm/lib/v3/agent/tools/click.js +23 -31
  171. package/dist/esm/lib/v3/agent/tools/click.js.map +1 -1
  172. package/dist/esm/lib/v3/agent/tools/dragAndDrop.js +22 -30
  173. package/dist/esm/lib/v3/agent/tools/dragAndDrop.js.map +1 -1
  174. package/dist/esm/lib/v3/agent/tools/extract.d.ts +2 -2
  175. package/dist/esm/lib/v3/agent/tools/extract.js +16 -3
  176. package/dist/esm/lib/v3/agent/tools/extract.js.map +1 -1
  177. package/dist/esm/lib/v3/agent/tools/fillFormVision.js +30 -30
  178. package/dist/esm/lib/v3/agent/tools/fillFormVision.js.map +1 -1
  179. package/dist/esm/lib/v3/agent/tools/fillform.d.ts +7 -1
  180. package/dist/esm/lib/v3/agent/tools/fillform.js +60 -37
  181. package/dist/esm/lib/v3/agent/tools/fillform.js.map +1 -1
  182. package/dist/esm/lib/v3/agent/tools/index.d.ts +19 -3
  183. package/dist/esm/lib/v3/agent/tools/index.js +12 -8
  184. package/dist/esm/lib/v3/agent/tools/index.js.map +1 -1
  185. package/dist/esm/lib/v3/agent/tools/screenshot.d.ts +8 -0
  186. package/dist/esm/lib/v3/agent/tools/screenshot.js +32 -15
  187. package/dist/esm/lib/v3/agent/tools/screenshot.js.map +1 -1
  188. package/dist/esm/lib/v3/agent/tools/scroll.js +12 -0
  189. package/dist/esm/lib/v3/agent/tools/scroll.js.map +1 -1
  190. package/dist/esm/lib/v3/agent/tools/type.js +23 -31
  191. package/dist/esm/lib/v3/agent/tools/type.js.map +1 -1
  192. package/dist/esm/lib/v3/agent/tools/wait.js +6 -0
  193. package/dist/esm/lib/v3/agent/tools/wait.js.map +1 -1
  194. package/dist/esm/lib/v3/agent/utils/handleDoneToolCall.js +4 -0
  195. package/dist/esm/lib/v3/agent/utils/handleDoneToolCall.js.map +1 -1
  196. package/dist/esm/lib/v3/api.d.ts +2 -2
  197. package/dist/esm/lib/v3/api.js +1 -1
  198. package/dist/esm/lib/v3/api.js.map +1 -1
  199. package/dist/esm/lib/v3/cache/ActCache.d.ts +0 -1
  200. package/dist/esm/lib/v3/cache/ActCache.js +2 -18
  201. package/dist/esm/lib/v3/cache/ActCache.js.map +1 -1
  202. package/dist/esm/lib/v3/eventStore.d.ts +41 -0
  203. package/dist/esm/lib/v3/eventStore.js +363 -0
  204. package/dist/esm/lib/v3/eventStore.js.map +1 -0
  205. package/dist/esm/lib/v3/flowLogger.d.ts +62 -103
  206. package/dist/esm/lib/v3/flowLogger.js +356 -762
  207. package/dist/esm/lib/v3/flowLogger.js.map +1 -1
  208. package/dist/esm/lib/v3/handlers/actHandler.js +1 -2
  209. package/dist/esm/lib/v3/handlers/actHandler.js.map +1 -1
  210. package/dist/esm/lib/v3/handlers/extractHandler.js +2 -2
  211. package/dist/esm/lib/v3/handlers/extractHandler.js.map +1 -1
  212. package/dist/esm/lib/v3/handlers/handlerUtils/actHandlerUtils.js +22 -34
  213. package/dist/esm/lib/v3/handlers/handlerUtils/actHandlerUtils.js.map +1 -1
  214. package/dist/esm/lib/v3/handlers/observeHandler.js +1 -2
  215. package/dist/esm/lib/v3/handlers/observeHandler.js.map +1 -1
  216. package/dist/esm/lib/v3/handlers/v3AgentHandler.d.ts +0 -4
  217. package/dist/esm/lib/v3/handlers/v3AgentHandler.js +25 -50
  218. package/dist/esm/lib/v3/handlers/v3AgentHandler.js.map +1 -1
  219. package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.js +11 -13
  220. package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.js.map +1 -1
  221. package/dist/esm/lib/v3/index.d.ts +2 -1
  222. package/dist/esm/lib/v3/launch/browserbase.d.ts +1 -1
  223. package/dist/esm/lib/v3/launch/browserbase.js +4 -9
  224. package/dist/esm/lib/v3/launch/browserbase.js.map +1 -1
  225. package/dist/esm/lib/v3/llm/LLMProvider.js +0 -5
  226. package/dist/esm/lib/v3/llm/LLMProvider.js.map +1 -1
  227. package/dist/esm/lib/v3/llm/aisdk.js +11 -17
  228. package/dist/esm/lib/v3/llm/aisdk.js.map +1 -1
  229. package/dist/esm/lib/v3/runtimePaths.js +2 -1
  230. package/dist/esm/lib/v3/runtimePaths.js.map +1 -1
  231. package/dist/esm/lib/v3/shutdown/supervisor.js +2 -2
  232. package/dist/esm/lib/v3/shutdown/supervisor.js.map +1 -1
  233. package/dist/esm/lib/v3/timeoutConfig.d.ts +1 -1
  234. package/dist/esm/lib/v3/timeoutConfig.js +5 -0
  235. package/dist/esm/lib/v3/timeoutConfig.js.map +1 -1
  236. package/dist/esm/lib/v3/types/private/shutdown.d.ts +1 -1
  237. package/dist/esm/lib/v3/types/private/shutdown.js.map +1 -1
  238. package/dist/esm/lib/v3/types/public/agent.d.ts +28 -3
  239. package/dist/esm/lib/v3/types/public/agent.js +0 -1
  240. package/dist/esm/lib/v3/types/public/agent.js.map +1 -1
  241. package/dist/esm/lib/v3/types/public/api.d.ts +3 -0
  242. package/dist/esm/lib/v3/types/public/api.js +1 -0
  243. package/dist/esm/lib/v3/types/public/api.js.map +1 -1
  244. package/dist/esm/lib/v3/types/public/model.d.ts +4 -2
  245. package/dist/esm/lib/v3/types/public/model.js.map +1 -1
  246. package/dist/esm/lib/v3/types/public/options.d.ts +6 -0
  247. package/dist/esm/lib/v3/types/public/options.js.map +1 -1
  248. package/dist/esm/lib/v3/understudy/cdp.d.ts +8 -13
  249. package/dist/esm/lib/v3/understudy/cdp.js +138 -18
  250. package/dist/esm/lib/v3/understudy/cdp.js.map +1 -1
  251. package/dist/esm/lib/v3/understudy/context.d.ts +1 -0
  252. package/dist/esm/lib/v3/understudy/context.js +142 -60
  253. package/dist/esm/lib/v3/understudy/context.js.map +1 -1
  254. package/dist/esm/lib/v3/understudy/frame.js +23 -6
  255. package/dist/esm/lib/v3/understudy/frame.js.map +1 -1
  256. package/dist/esm/lib/v3/understudy/page.d.ts +13 -0
  257. package/dist/esm/lib/v3/understudy/page.js +91 -23
  258. package/dist/esm/lib/v3/understudy/page.js.map +1 -1
  259. package/dist/esm/lib/v3/understudy/screenshotUtils.d.ts +0 -1
  260. package/dist/esm/lib/v3/understudy/screenshotUtils.js +0 -17
  261. package/dist/esm/lib/v3/understudy/screenshotUtils.js.map +1 -1
  262. package/dist/esm/lib/v3/v3.d.ts +10 -0
  263. package/dist/esm/lib/v3/v3.js +211 -173
  264. package/dist/esm/lib/v3/v3.js.map +1 -1
  265. package/dist/esm/tests/integration/cdp-session-detached.spec.js +1 -1
  266. package/dist/esm/tests/integration/cdp-session-detached.spec.js.map +1 -1
  267. package/dist/esm/tests/integration/context-addInitScript.spec.js +104 -11
  268. package/dist/esm/tests/integration/context-addInitScript.spec.js.map +1 -1
  269. package/dist/esm/tests/integration/iframe-ctx-addInitScript-race.spec.d.ts +1 -0
  270. package/dist/esm/tests/integration/iframe-ctx-addInitScript-race.spec.js +217 -0
  271. package/dist/esm/tests/integration/iframe-ctx-addInitScript-race.spec.js.map +1 -0
  272. package/dist/esm/tests/integration/page-extra-http-headers.spec.d.ts +1 -0
  273. package/dist/esm/tests/integration/page-extra-http-headers.spec.js +83 -0
  274. package/dist/esm/tests/integration/page-extra-http-headers.spec.js.map +1 -0
  275. package/dist/esm/tests/integration/page-screenshot.spec.js +1 -1
  276. package/dist/esm/tests/integration/page-screenshot.spec.js.map +1 -1
  277. package/dist/esm/tests/integration/timeouts.spec.js +168 -0
  278. package/dist/esm/tests/integration/timeouts.spec.js.map +1 -1
  279. package/dist/esm/tests/unit/model-deprecation.test.js +5 -8
  280. package/dist/esm/tests/unit/model-deprecation.test.js.map +1 -1
  281. package/dist/esm/tests/unit/page-extra-http-headers.test.d.ts +1 -0
  282. package/dist/esm/tests/unit/page-extra-http-headers.test.js +90 -0
  283. package/dist/esm/tests/unit/page-extra-http-headers.test.js.map +1 -0
  284. package/dist/esm/tests/unit/public-api/llm-and-agents.test.js +13 -1
  285. package/dist/esm/tests/unit/public-api/llm-and-agents.test.js.map +1 -1
  286. package/dist/esm/tests/unit/public-api/public-types.test.js.map +1 -1
  287. package/package.json +2 -2
  288. package/dist/cjs/lib/v3/agent/tools/search.js.map +0 -1
  289. package/dist/cjs/tests/unit/rerender-missing-shadows.test.js +0 -209
  290. package/dist/cjs/tests/unit/rerender-missing-shadows.test.js.map +0 -1
  291. package/dist/esm/lib/v3/agent/tools/search.js.map +0 -1
  292. package/dist/esm/tests/unit/rerender-missing-shadows.test.js +0 -207
  293. package/dist/esm/tests/unit/rerender-missing-shadows.test.js.map +0 -1
  294. /package/dist/cjs/lib/v3/agent/tools/{search.d.ts → braveSearch.d.ts} +0 -0
  295. /package/dist/cjs/tests/{unit/rerender-missing-shadows.test.d.ts → integration/iframe-ctx-addInitScript-race.spec.d.ts} +0 -0
  296. /package/dist/{esm/tests/unit/rerender-missing-shadows.test.d.ts → cjs/tests/integration/page-extra-http-headers.spec.d.ts} +0 -0
  297. /package/dist/esm/lib/v3/agent/tools/{search.d.ts → braveSearch.d.ts} +0 -0
@@ -63,11 +63,13 @@ import { resolveModel } from "../modelUtils.js";
63
63
  import { StagehandAPIClient } from "./api.js";
64
64
  import { validateExperimentalFeatures } from "./agent/utils/validateExperimentalFeatures.js";
65
65
  import { flattenVariables } from "./agent/utils/variables.js";
66
- import { SessionFileLogger, logStagehandStep } from "./flowLogger.js";
66
+ import { FlowLogger } from "./flowLogger.js";
67
+ import { getEventStore } from "./eventStore.js";
67
68
  import { createTimeoutGuard } from "./handlers/handlerUtils/timeoutGuard.js";
68
69
  import { ActTimeoutError } from "./types/public/sdkErrors.js";
69
70
  const DEFAULT_MODEL_NAME = "openai/gpt-4.1-mini";
70
71
  const DEFAULT_VIEWPORT = { width: 1288, height: 711 };
72
+ const DEFAULT_AGENT_TOOL_TIMEOUT_MS = 45000;
71
73
  function resolveModelConfiguration(model) {
72
74
  if (!model) {
73
75
  return { modelName: DEFAULT_MODEL_NAME };
@@ -110,9 +112,18 @@ let V3 = (() => {
110
112
  return class V3 {
111
113
  static {
112
114
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
113
- _act_decorators = [logStagehandStep("Stagehand.act", "ACT")];
114
- _extract_decorators = [logStagehandStep("Stagehand.extract", "EXTRACT")];
115
- _observe_decorators = [logStagehandStep("Stagehand.observe", "OBSERVE")];
115
+ _act_decorators = [FlowLogger.wrapWithLogging({
116
+ eventType: "StagehandAct",
117
+ eventIdSuffix: "4",
118
+ })];
119
+ _extract_decorators = [FlowLogger.wrapWithLogging({
120
+ eventType: "StagehandExtract",
121
+ eventIdSuffix: "4",
122
+ })];
123
+ _observe_decorators = [FlowLogger.wrapWithLogging({
124
+ eventType: "StagehandObserve",
125
+ eventIdSuffix: "4",
126
+ })];
116
127
  __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);
117
128
  __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);
118
129
  __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);
@@ -197,6 +208,8 @@ let V3 = (() => {
197
208
  stagehandLogger;
198
209
  _history = [];
199
210
  instanceId;
211
+ sessionId;
212
+ flowLoggerContext;
200
213
  static _processGuardsInstalled = false;
201
214
  static _instances = new Set();
202
215
  cacheStorage;
@@ -205,6 +218,10 @@ let V3 = (() => {
205
218
  apiClient = null;
206
219
  keepAlive;
207
220
  shutdownSupervisor = null;
221
+ detachEventStoreListener = null;
222
+ withLoggingContext(fn) {
223
+ return withInstanceLogContext(this.instanceId, fn);
224
+ }
208
225
  stagehandMetrics = {
209
226
  actPromptTokens: 0,
210
227
  actCompletionTokens: 0,
@@ -236,6 +253,7 @@ let V3 = (() => {
236
253
  this.externalLogger = opts.logger;
237
254
  this.verbose = opts.verbose ?? 1;
238
255
  this.instanceId = uuidv7();
256
+ this.sessionId = opts.sessionId ?? this.instanceId;
239
257
  this.keepAlive =
240
258
  opts.keepAlive ?? opts.browserbaseSessionCreateParams?.keepAlive;
241
259
  // Create per-instance StagehandLogger (handles usePino, verbose, externalLogger)
@@ -328,8 +346,9 @@ let V3 = (() => {
328
346
  act: this.act.bind(this),
329
347
  });
330
348
  this.opts = opts;
331
- // Initialize session file logger
332
- SessionFileLogger.init(this.instanceId, opts);
349
+ void getEventStore().initializeSession(this.sessionId, opts);
350
+ this.flowLoggerContext = FlowLogger.init(this.sessionId, this.bus);
351
+ this.detachEventStoreListener = getEventStore().attachBus(this.sessionId, this.bus);
333
352
  // Track instance for global process guard handling
334
353
  V3._instances.add(this);
335
354
  }
@@ -536,7 +555,7 @@ let V3 = (() => {
536
555
  */
537
556
  async init() {
538
557
  try {
539
- return await withInstanceLogContext(this.instanceId, async () => {
558
+ return await this.withLoggingContext(async () => {
540
559
  this.actHandler = new ActHandler(this.llmClient, this.modelName, this.modelClientOptions, (model) => this.resolveLlmClient(model), this.opts.systemPrompt ?? "", this.logInferenceToFile, this.opts.selfHeal ?? true, (functionName, promptTokens, completionTokens, reasoningTokens, cachedInputTokens, inferenceTimeMs) => this.updateMetrics(functionName, promptTokens, completionTokens, reasoningTokens, cachedInputTokens, inferenceTimeMs), this.domSettleTimeoutMs);
541
560
  this.extractHandler = new ExtractHandler(this.llmClient, this.modelName, this.modelClientOptions, (model) => this.resolveLlmClient(model), this.opts.systemPrompt ?? "", this.logInferenceToFile, this.experimental, (functionName, promptTokens, completionTokens, reasoningTokens, cachedInputTokens, inferenceTimeMs) => this.updateMetrics(functionName, promptTokens, completionTokens, reasoningTokens, cachedInputTokens, inferenceTimeMs));
542
561
  this.observeHandler = new ObserveHandler(this.llmClient, this.modelName, this.modelClientOptions, (model) => this.resolveLlmClient(model), this.opts.systemPrompt ?? "", this.logInferenceToFile, this.experimental, (functionName, promptTokens, completionTokens, reasoningTokens, cachedInputTokens, inferenceTimeMs) => this.updateMetrics(functionName, promptTokens, completionTokens, reasoningTokens, cachedInputTokens, inferenceTimeMs));
@@ -552,6 +571,13 @@ let V3 = (() => {
552
571
  }
553
572
  }
554
573
  const lbo = this.opts.localBrowserLaunchOptions ?? {};
574
+ if (lbo.cdpHeaders && !lbo.cdpUrl) {
575
+ this.logger({
576
+ category: "init",
577
+ message: "`cdpHeaders` was provided but `cdpUrl` is not set — cdpHeaders will be ignored. Set `cdpUrl` to connect to an existing browser via CDP.",
578
+ level: 2,
579
+ });
580
+ }
555
581
  // If a CDP URL is provided, attach instead of launching.
556
582
  if (lbo.cdpUrl) {
557
583
  this.logger({
@@ -561,10 +587,9 @@ let V3 = (() => {
561
587
  });
562
588
  this.ctx = await V3Context.create(lbo.cdpUrl, {
563
589
  env: "LOCAL",
590
+ cdpHeaders: lbo.cdpHeaders,
564
591
  });
565
- const logCtx = SessionFileLogger.getContext();
566
- this.ctx.conn.cdpLogger = (info) => SessionFileLogger.logCdpCallEvent(info, logCtx);
567
- this.ctx.conn.cdpEventLogger = (info) => SessionFileLogger.logCdpMessageEvent(info, logCtx);
592
+ this.ctx.conn.flowLoggerContext = this.flowLoggerContext;
568
593
  this.ctx.conn.onTransportClosed(this._onCdpClosed);
569
594
  this.state = {
570
595
  kind: "LOCAL",
@@ -660,9 +685,7 @@ let V3 = (() => {
660
685
  env: "LOCAL",
661
686
  localBrowserLaunchOptions: lbo,
662
687
  });
663
- const logCtx = SessionFileLogger.getContext();
664
- this.ctx.conn.cdpLogger = (info) => SessionFileLogger.logCdpCallEvent(info, logCtx);
665
- this.ctx.conn.cdpEventLogger = (info) => SessionFileLogger.logCdpMessageEvent(info, logCtx);
688
+ this.ctx.conn.flowLoggerContext = this.flowLoggerContext;
666
689
  this.ctx.conn.onTransportClosed(this._onCdpClosed);
667
690
  this.state = {
668
691
  kind: "LOCAL",
@@ -689,9 +712,6 @@ let V3 = (() => {
689
712
  }
690
713
  if (this.opts.env === "BROWSERBASE") {
691
714
  const { apiKey, projectId } = this.requireBrowserbaseCreds();
692
- if (!apiKey || !projectId) {
693
- throw new MissingEnvironmentVariableError("BROWSERBASE_API_KEY and BROWSERBASE_PROJECT_ID", "Browserbase environment");
694
- }
695
715
  this.logger({
696
716
  category: "init",
697
717
  message: "Starting browserbase session",
@@ -710,18 +730,20 @@ let V3 = (() => {
710
730
  logger: this.logger,
711
731
  serverCache: this.opts.serverCache,
712
732
  });
733
+ const { projectId: overrideProjectId, browserSettings, userMetadata, ...restSessionParams } = effectiveSessionParams;
734
+ const resolvedProjectId = overrideProjectId ?? projectId;
713
735
  const createSessionPayload = {
714
- projectId: effectiveSessionParams.projectId ?? projectId,
715
- ...effectiveSessionParams,
736
+ ...(resolvedProjectId ? { projectId: resolvedProjectId } : {}),
737
+ ...restSessionParams,
716
738
  browserSettings: {
717
- ...(effectiveSessionParams.browserSettings ?? {}),
718
- viewport: effectiveSessionParams.browserSettings?.viewport ?? {
739
+ ...(browserSettings ?? {}),
740
+ viewport: browserSettings?.viewport ?? {
719
741
  width: 1288,
720
742
  height: 711,
721
743
  },
722
744
  },
723
745
  userMetadata: {
724
- ...(effectiveSessionParams.userMetadata ?? {}),
746
+ ...(userMetadata ?? {}),
725
747
  stagehand: "true",
726
748
  },
727
749
  };
@@ -745,9 +767,7 @@ let V3 = (() => {
745
767
  env: "BROWSERBASE",
746
768
  apiClient: this.apiClient,
747
769
  });
748
- const logCtx = SessionFileLogger.getContext();
749
- this.ctx.conn.cdpLogger = (info) => SessionFileLogger.logCdpCallEvent(info, logCtx);
750
- this.ctx.conn.cdpEventLogger = (info) => SessionFileLogger.logCdpMessageEvent(info, logCtx);
770
+ this.ctx.conn.flowLoggerContext = this.flowLoggerContext;
751
771
  this.ctx.conn.onTransportClosed(this._onCdpClosed);
752
772
  this.state = { kind: "BROWSERBASE", sessionId, ws, bb };
753
773
  this.browserbaseSessionId = sessionId;
@@ -809,6 +829,13 @@ let V3 = (() => {
809
829
  // ignore cleanup errors
810
830
  }
811
831
  }
832
+ try {
833
+ this.detachEventStoreListener?.();
834
+ this.detachEventStoreListener = null;
835
+ }
836
+ catch {
837
+ // ignore cleanup errors
838
+ }
812
839
  throw error;
813
840
  }
814
841
  }
@@ -852,7 +879,7 @@ let V3 = (() => {
852
879
  this.browserbaseDebugUrl = undefined;
853
880
  }
854
881
  async act(input, options) {
855
- return await withInstanceLogContext(this.instanceId, async () => {
882
+ return await this.withLoggingContext(async () => {
856
883
  if (!this.actHandler)
857
884
  throw new StagehandNotInitializedError("act()");
858
885
  let actResult;
@@ -869,10 +896,7 @@ let V3 = (() => {
869
896
  });
870
897
  }
871
898
  else {
872
- const effectiveTimeoutMs = typeof options?.timeout === "number" && options.timeout > 0
873
- ? options.timeout
874
- : undefined;
875
- const ensureTimeRemaining = createTimeoutGuard(effectiveTimeoutMs, (ms) => new ActTimeoutError(ms));
899
+ const ensureTimeRemaining = createTimeoutGuard(options?.timeout, (ms) => new ActTimeoutError(ms));
876
900
  actResult = await this.actHandler.takeDeterministicAction({ ...input, selector }, v3Page, this.domSettleTimeoutMs, this.resolveLlmClient(options?.model), ensureTimeRemaining, options?.variables);
877
901
  }
878
902
  // history: record ObserveResult-based act call
@@ -939,7 +963,7 @@ let V3 = (() => {
939
963
  });
940
964
  }
941
965
  async extract(a, b, c) {
942
- return await withInstanceLogContext(this.instanceId, async () => {
966
+ return await this.withLoggingContext(async () => {
943
967
  if (!this.extractHandler) {
944
968
  throw new StagehandNotInitializedError("extract()");
945
969
  }
@@ -1007,7 +1031,7 @@ let V3 = (() => {
1007
1031
  });
1008
1032
  }
1009
1033
  async observe(a, b) {
1010
- return await withInstanceLogContext(this.instanceId, async () => {
1034
+ return await this.withLoggingContext(async () => {
1011
1035
  if (!this.observeHandler) {
1012
1036
  throw new StagehandNotInitializedError("observe()");
1013
1037
  }
@@ -1093,7 +1117,7 @@ let V3 = (() => {
1093
1117
  try {
1094
1118
  // Close session file logger
1095
1119
  try {
1096
- await SessionFileLogger.close();
1120
+ await FlowLogger.close(this.flowLoggerContext);
1097
1121
  }
1098
1122
  catch {
1099
1123
  // ignore
@@ -1129,6 +1153,13 @@ let V3 = (() => {
1129
1153
  catch {
1130
1154
  // ignore
1131
1155
  }
1156
+ try {
1157
+ this.detachEventStoreListener?.();
1158
+ this.detachEventStoreListener = null;
1159
+ }
1160
+ catch {
1161
+ // ignore
1162
+ }
1132
1163
  try {
1133
1164
  this.bus.removeAllListeners();
1134
1165
  }
@@ -1142,6 +1173,13 @@ let V3 = (() => {
1142
1173
  V3._instances.delete(this);
1143
1174
  }
1144
1175
  }
1176
+ /**
1177
+ * Resolves the Browserbase API key from options or environment variables.
1178
+ * Returns undefined if no key is found (does not throw).
1179
+ */
1180
+ get browserbaseApiKey() {
1181
+ return this.opts.apiKey || process.env.BROWSERBASE_API_KEY;
1182
+ }
1145
1183
  /** Guard: ensure Browserbase credentials exist in options. */
1146
1184
  requireBrowserbaseCreds() {
1147
1185
  let { apiKey, projectId } = this.opts;
@@ -1151,17 +1189,13 @@ let V3 = (() => {
1151
1189
  if (!projectId)
1152
1190
  projectId =
1153
1191
  process.env.BROWSERBASE_PROJECT_ID ?? process.env.BB_PROJECT_ID;
1154
- if (!apiKey || !projectId) {
1155
- const missing = [];
1156
- if (!apiKey)
1157
- missing.push("BROWSERBASE_API_KEY");
1158
- if (!projectId)
1159
- missing.push("BROWSERBASE_PROJECT_ID");
1160
- throw new MissingEnvironmentVariableError(missing.join(", "), "Browserbase");
1192
+ if (!apiKey) {
1193
+ throw new MissingEnvironmentVariableError("BROWSERBASE_API_KEY", "Browserbase");
1161
1194
  }
1162
1195
  // Cache resolved values back into opts for consistency
1163
1196
  this.opts.apiKey = apiKey;
1164
- this.opts.projectId = projectId;
1197
+ if (projectId)
1198
+ this.opts.projectId = projectId;
1165
1199
  // Informational log
1166
1200
  this.logger({
1167
1201
  category: "init",
@@ -1305,8 +1339,14 @@ let V3 = (() => {
1305
1339
  const resolvedExecutionModel = options?.executionModel ?? options?.model;
1306
1340
  const handler = new V3AgentHandler(this, this.logger, agentLlmClient, resolvedExecutionModel, options?.systemPrompt, tools, options?.mode);
1307
1341
  const resolvedOptions = typeof instructionOrOptions === "string"
1308
- ? { instruction: instructionOrOptions }
1309
- : instructionOrOptions;
1342
+ ? {
1343
+ instruction: instructionOrOptions,
1344
+ toolTimeout: DEFAULT_AGENT_TOOL_TIMEOUT_MS,
1345
+ }
1346
+ : {
1347
+ ...instructionOrOptions,
1348
+ toolTimeout: instructionOrOptions.toolTimeout ?? DEFAULT_AGENT_TOOL_TIMEOUT_MS,
1349
+ };
1310
1350
  const callbacksWithSafety = resolvedOptions.callbacks;
1311
1351
  if (callbacksWithSafety?.onSafetyConfirmation) {
1312
1352
  throw new StagehandInvalidArgumentError('onSafetyConfirmation callback is only supported when using mode: "cua" agents.');
@@ -1386,145 +1426,59 @@ let V3 = (() => {
1386
1426
  throw new CuaModelRequiredError(AVAILABLE_CUA_MODELS);
1387
1427
  }
1388
1428
  const agentConfigSignature = this.agentCache.buildConfigSignature(options);
1389
- return {
1390
- execute: async (instructionOrOptions) => withInstanceLogContext(this.instanceId, async () => {
1391
- validateExperimentalFeatures({
1392
- isExperimental: this.experimental,
1393
- agentConfig: options,
1394
- executeOptions: typeof instructionOrOptions === "object"
1395
- ? instructionOrOptions
1396
- : null,
1397
- });
1398
- SessionFileLogger.logAgentTaskStarted({
1399
- invocation: "Agent.execute",
1400
- args: [instructionOrOptions],
1401
- });
1402
- const tools = options?.integrations
1403
- ? await resolveTools(options.integrations, options.tools)
1404
- : (options?.tools ?? {});
1405
- const handler = new V3CuaAgentHandler(this, this.logger, {
1406
- modelName,
1407
- clientOptions,
1408
- userProvidedInstructions: options.systemPrompt ??
1409
- `You are a helpful assistant that can use a web browser.\nDo not ask follow up questions, the user will trust your judgement.`,
1410
- }, tools);
1411
- const resolvedOptions = typeof instructionOrOptions === "string"
1412
- ? { instruction: instructionOrOptions }
1413
- : instructionOrOptions;
1414
- if (resolvedOptions.page) {
1415
- const normalizedPage = await this.normalizeToV3Page(resolvedOptions.page);
1416
- this.ctx.setActivePage(normalizedPage);
1417
- }
1418
- const instruction = resolvedOptions.instruction.trim();
1419
- const sanitizedOptions = this.agentCache.sanitizeExecuteOptions(resolvedOptions);
1420
- const cacheVariables = flattenVariables(resolvedOptions.variables);
1421
- let cacheContext = null;
1422
- if (this.agentCache.shouldAttemptCache(instruction)) {
1423
- const startPage = await this.ctx.awaitActivePage();
1424
- cacheContext = await this.agentCache.prepareContext({
1425
- instruction,
1426
- options: sanitizedOptions,
1427
- configSignature: agentConfigSignature,
1428
- page: startPage,
1429
- variables: cacheVariables,
1430
- });
1431
- if (cacheContext) {
1432
- const replayed = await this.agentCache.tryReplay(cacheContext);
1433
- if (replayed) {
1434
- SessionFileLogger.logAgentTaskCompleted({ cacheHit: true });
1435
- return replayed;
1436
- }
1437
- }
1438
- }
1439
- let agentSteps = [];
1440
- const shouldRecordLocally = !!cacheContext && (!this.apiClient || this.experimental);
1441
- if (shouldRecordLocally) {
1442
- this.beginAgentReplayRecording();
1443
- }
1444
- let result;
1445
- try {
1446
- if (this.apiClient && !this.experimental) {
1447
- const page = await this.ctx.awaitActivePage();
1448
- result = await this.apiClient.agentExecute(options, resolvedOptions, page.mainFrameId(), !!cacheContext);
1449
- if (cacheContext) {
1450
- const transferredEntry = this.apiClient.consumeLatestAgentCacheEntry();
1451
- await this.agentCache.storeTransferredEntry(transferredEntry);
1452
- }
1453
- }
1454
- else {
1455
- result = await handler.execute(instructionOrOptions);
1456
- }
1457
- if (shouldRecordLocally) {
1458
- agentSteps = this.endAgentReplayRecording();
1459
- }
1460
- if (shouldRecordLocally &&
1461
- cacheContext &&
1462
- result.success &&
1463
- agentSteps.length > 0) {
1464
- await this.agentCache.store(cacheContext, agentSteps, result);
1465
- }
1466
- return result;
1467
- }
1468
- catch (err) {
1469
- if (shouldRecordLocally)
1470
- this.discardAgentReplayRecording();
1471
- throw err;
1472
- }
1473
- finally {
1474
- if (shouldRecordLocally) {
1475
- this.discardAgentReplayRecording();
1476
- }
1477
- SessionFileLogger.logAgentTaskCompleted();
1478
- }
1479
- }),
1480
- };
1481
- }
1482
- // Default: AISDK tools-based agent
1483
- const agentConfigSignature = this.agentCache.buildConfigSignature(options);
1484
- const isStreaming = options?.stream ?? false;
1485
- return {
1486
- execute: async (instructionOrOptions) => withInstanceLogContext(this.instanceId, async () => {
1429
+ const execute = FlowLogger.wrapWithLogging({
1430
+ eventType: "AgentExecute",
1431
+ eventIdSuffix: "3",
1432
+ })(async (instructionOrOptions) => this.withLoggingContext(async () => {
1487
1433
  validateExperimentalFeatures({
1488
1434
  isExperimental: this.experimental,
1489
1435
  agentConfig: options,
1490
1436
  executeOptions: typeof instructionOrOptions === "object"
1491
1437
  ? instructionOrOptions
1492
1438
  : null,
1493
- isStreaming,
1494
1439
  });
1495
- SessionFileLogger.logAgentTaskStarted({
1496
- invocation: "Agent.execute",
1497
- args: [instructionOrOptions],
1498
- });
1499
- // Streaming mode
1500
- if (isStreaming) {
1501
- const { handler, resolvedOptions, cacheContext, llmClient } = await this.prepareAgentExecution(options, instructionOrOptions, agentConfigSignature);
1440
+ const tools = options?.integrations
1441
+ ? await resolveTools(options.integrations, options.tools)
1442
+ : (options?.tools ?? {});
1443
+ const handler = new V3CuaAgentHandler(this, this.logger, {
1444
+ modelName,
1445
+ clientOptions,
1446
+ userProvidedInstructions: options.systemPrompt ??
1447
+ `You are a helpful assistant that can use a web browser.\nDo not ask follow up questions, the user will trust your judgement.`,
1448
+ }, tools);
1449
+ const resolvedOptions = typeof instructionOrOptions === "string"
1450
+ ? {
1451
+ instruction: instructionOrOptions,
1452
+ toolTimeout: DEFAULT_AGENT_TOOL_TIMEOUT_MS,
1453
+ }
1454
+ : {
1455
+ ...instructionOrOptions,
1456
+ toolTimeout: instructionOrOptions.toolTimeout ??
1457
+ DEFAULT_AGENT_TOOL_TIMEOUT_MS,
1458
+ };
1459
+ if (resolvedOptions.page) {
1460
+ const normalizedPage = await this.normalizeToV3Page(resolvedOptions.page);
1461
+ this.ctx.setActivePage(normalizedPage);
1462
+ }
1463
+ const instruction = resolvedOptions.instruction.trim();
1464
+ const sanitizedOptions = this.agentCache.sanitizeExecuteOptions(resolvedOptions);
1465
+ const cacheVariables = flattenVariables(resolvedOptions.variables);
1466
+ let cacheContext = null;
1467
+ if (this.agentCache.shouldAttemptCache(instruction)) {
1468
+ const startPage = await this.ctx.awaitActivePage();
1469
+ cacheContext = await this.agentCache.prepareContext({
1470
+ instruction,
1471
+ options: sanitizedOptions,
1472
+ configSignature: agentConfigSignature,
1473
+ page: startPage,
1474
+ variables: cacheVariables,
1475
+ });
1502
1476
  if (cacheContext) {
1503
- const replayed = await this.agentCache.tryReplayAsStream(cacheContext, llmClient);
1477
+ const replayed = await this.agentCache.tryReplay(cacheContext);
1504
1478
  if (replayed) {
1505
- SessionFileLogger.logAgentTaskCompleted({ cacheHit: true });
1506
1479
  return replayed;
1507
1480
  }
1508
1481
  }
1509
- const streamResult = await handler.stream(resolvedOptions);
1510
- if (cacheContext) {
1511
- const wrappedStream = this.agentCache.wrapStreamForCaching(cacheContext, streamResult, () => this.beginAgentReplayRecording(), () => this.endAgentReplayRecording(), () => this.discardAgentReplayRecording());
1512
- // Log completion when stream is returned (stream completes asynchronously)
1513
- SessionFileLogger.logAgentTaskCompleted();
1514
- return wrappedStream;
1515
- }
1516
- // Log completion when stream is returned (stream completes asynchronously)
1517
- SessionFileLogger.logAgentTaskCompleted();
1518
- return streamResult;
1519
- }
1520
- // Non-streaming mode (default)
1521
- const { handler, resolvedOptions, cacheContext, llmClient } = await this.prepareAgentExecution(options, instructionOrOptions, agentConfigSignature);
1522
- if (cacheContext) {
1523
- const replayed = await this.agentCache.tryReplay(cacheContext, llmClient);
1524
- if (replayed) {
1525
- SessionFileLogger.logAgentTaskCompleted({ cacheHit: true });
1526
- return replayed;
1527
- }
1528
1482
  }
1529
1483
  let agentSteps = [];
1530
1484
  const shouldRecordLocally = !!cacheContext && (!this.apiClient || this.experimental);
@@ -1535,14 +1489,14 @@ let V3 = (() => {
1535
1489
  try {
1536
1490
  if (this.apiClient && !this.experimental) {
1537
1491
  const page = await this.ctx.awaitActivePage();
1538
- result = await this.apiClient.agentExecute(options ?? {}, resolvedOptions, page.mainFrameId(), !!cacheContext);
1492
+ result = await this.apiClient.agentExecute(options, resolvedOptions, page.mainFrameId(), !!cacheContext);
1539
1493
  if (cacheContext) {
1540
1494
  const transferredEntry = this.apiClient.consumeLatestAgentCacheEntry();
1541
1495
  await this.agentCache.storeTransferredEntry(transferredEntry);
1542
1496
  }
1543
1497
  }
1544
1498
  else {
1545
- result = await handler.execute(resolvedOptions);
1499
+ result = await handler.execute(instructionOrOptions);
1546
1500
  }
1547
1501
  if (shouldRecordLocally) {
1548
1502
  agentSteps = this.endAgentReplayRecording();
@@ -1564,9 +1518,93 @@ let V3 = (() => {
1564
1518
  if (shouldRecordLocally) {
1565
1519
  this.discardAgentReplayRecording();
1566
1520
  }
1567
- SessionFileLogger.logAgentTaskCompleted();
1568
1521
  }
1569
- }),
1522
+ }));
1523
+ return {
1524
+ execute,
1525
+ };
1526
+ }
1527
+ // Default: AISDK tools-based agent
1528
+ const agentConfigSignature = this.agentCache.buildConfigSignature(options);
1529
+ const isStreaming = options?.stream ?? false;
1530
+ const execute = FlowLogger.wrapWithLogging({
1531
+ eventType: "AgentExecute",
1532
+ eventIdSuffix: "3",
1533
+ })(async (instructionOrOptions) => this.withLoggingContext(async () => {
1534
+ validateExperimentalFeatures({
1535
+ isExperimental: this.experimental,
1536
+ agentConfig: options,
1537
+ executeOptions: typeof instructionOrOptions === "object"
1538
+ ? instructionOrOptions
1539
+ : null,
1540
+ isStreaming,
1541
+ });
1542
+ // Streaming mode
1543
+ if (isStreaming) {
1544
+ const { handler, resolvedOptions, cacheContext, llmClient } = await this.prepareAgentExecution(options, instructionOrOptions, agentConfigSignature);
1545
+ if (cacheContext) {
1546
+ const replayed = await this.agentCache.tryReplayAsStream(cacheContext, llmClient);
1547
+ if (replayed) {
1548
+ return replayed;
1549
+ }
1550
+ }
1551
+ const streamResult = await handler.stream(resolvedOptions);
1552
+ if (cacheContext) {
1553
+ const wrappedStream = this.agentCache.wrapStreamForCaching(cacheContext, streamResult, () => this.beginAgentReplayRecording(), () => this.endAgentReplayRecording(), () => this.discardAgentReplayRecording());
1554
+ return wrappedStream;
1555
+ }
1556
+ return streamResult;
1557
+ }
1558
+ // Non-streaming mode (default)
1559
+ const { handler, resolvedOptions, cacheContext, llmClient } = await this.prepareAgentExecution(options, instructionOrOptions, agentConfigSignature);
1560
+ if (cacheContext) {
1561
+ const replayed = await this.agentCache.tryReplay(cacheContext, llmClient);
1562
+ if (replayed) {
1563
+ return replayed;
1564
+ }
1565
+ }
1566
+ let agentSteps = [];
1567
+ const shouldRecordLocally = !!cacheContext && (!this.apiClient || this.experimental);
1568
+ if (shouldRecordLocally) {
1569
+ this.beginAgentReplayRecording();
1570
+ }
1571
+ let result;
1572
+ try {
1573
+ if (this.apiClient && !this.experimental) {
1574
+ const page = await this.ctx.awaitActivePage();
1575
+ result = await this.apiClient.agentExecute(options ?? {}, resolvedOptions, page.mainFrameId(), !!cacheContext);
1576
+ if (cacheContext) {
1577
+ const transferredEntry = this.apiClient.consumeLatestAgentCacheEntry();
1578
+ await this.agentCache.storeTransferredEntry(transferredEntry);
1579
+ }
1580
+ }
1581
+ else {
1582
+ result = await handler.execute(resolvedOptions);
1583
+ }
1584
+ if (shouldRecordLocally) {
1585
+ agentSteps = this.endAgentReplayRecording();
1586
+ }
1587
+ if (shouldRecordLocally &&
1588
+ cacheContext &&
1589
+ result.success &&
1590
+ agentSteps.length > 0) {
1591
+ await this.agentCache.store(cacheContext, agentSteps, result);
1592
+ }
1593
+ return result;
1594
+ }
1595
+ catch (err) {
1596
+ if (shouldRecordLocally)
1597
+ this.discardAgentReplayRecording();
1598
+ throw err;
1599
+ }
1600
+ finally {
1601
+ if (shouldRecordLocally) {
1602
+ this.discardAgentReplayRecording();
1603
+ }
1604
+ }
1605
+ }));
1606
+ return {
1607
+ execute,
1570
1608
  };
1571
1609
  }
1572
1610
  };