@browserbasehq/orca 3.2.0-preview.4 → 3.2.1-preview.0

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 (308) hide show
  1. package/README.md +2 -2
  2. package/dist/cjs/lib/inference.d.ts +3 -1
  3. package/dist/cjs/lib/inference.js +3 -3
  4. package/dist/cjs/lib/inference.js.map +1 -1
  5. package/dist/cjs/lib/prompt.d.ts +1 -1
  6. package/dist/cjs/lib/prompt.js +24 -18
  7. package/dist/cjs/lib/prompt.js.map +1 -1
  8. package/dist/cjs/lib/v3/agent/AgentClient.d.ts +8 -0
  9. package/dist/cjs/lib/v3/agent/AgentClient.js +13 -0
  10. package/dist/cjs/lib/v3/agent/AgentClient.js.map +1 -1
  11. package/dist/cjs/lib/v3/agent/AgentProvider.js +1 -0
  12. package/dist/cjs/lib/v3/agent/AgentProvider.js.map +1 -1
  13. package/dist/cjs/lib/v3/agent/AnthropicCUAClient.d.ts +3 -1
  14. package/dist/cjs/lib/v3/agent/AnthropicCUAClient.js +61 -9
  15. package/dist/cjs/lib/v3/agent/AnthropicCUAClient.js.map +1 -1
  16. package/dist/cjs/lib/v3/agent/GoogleCUAClient.js +1 -0
  17. package/dist/cjs/lib/v3/agent/GoogleCUAClient.js.map +1 -1
  18. package/dist/cjs/lib/v3/agent/MicrosoftCUAClient.js +16 -0
  19. package/dist/cjs/lib/v3/agent/MicrosoftCUAClient.js.map +1 -1
  20. package/dist/cjs/lib/v3/agent/OpenAICUAClient.d.ts +12 -6
  21. package/dist/cjs/lib/v3/agent/OpenAICUAClient.js +164 -49
  22. package/dist/cjs/lib/v3/agent/OpenAICUAClient.js.map +1 -1
  23. package/dist/cjs/lib/v3/agent/prompts/agentSystemPrompt.d.ts +2 -2
  24. package/dist/cjs/lib/v3/agent/prompts/agentSystemPrompt.js +10 -11
  25. package/dist/cjs/lib/v3/agent/prompts/agentSystemPrompt.js.map +1 -1
  26. package/dist/cjs/lib/v3/agent/tools/fillform.d.ts +0 -1
  27. package/dist/cjs/lib/v3/agent/tools/fillform.js +7 -10
  28. package/dist/cjs/lib/v3/agent/tools/fillform.js.map +1 -1
  29. package/dist/cjs/lib/v3/agent/tools/index.js +1 -1
  30. package/dist/cjs/lib/v3/agent/tools/index.js.map +1 -1
  31. package/dist/cjs/lib/v3/agent/tools/keys.d.ts +2 -1
  32. package/dist/cjs/lib/v3/agent/tools/keys.js +57 -49
  33. package/dist/cjs/lib/v3/agent/tools/keys.js.map +1 -1
  34. package/dist/cjs/lib/v3/agent/utils/captchaSolver.d.ts +76 -0
  35. package/dist/cjs/lib/v3/agent/utils/captchaSolver.js +175 -0
  36. package/dist/cjs/lib/v3/agent/utils/captchaSolver.js.map +1 -0
  37. package/dist/cjs/lib/v3/agent/utils/coordinateNormalization.js +3 -5
  38. package/dist/cjs/lib/v3/agent/utils/coordinateNormalization.js.map +1 -1
  39. package/dist/cjs/lib/v3/agent/utils/variables.d.ts +5 -0
  40. package/dist/cjs/lib/v3/agent/utils/variables.js +9 -0
  41. package/dist/cjs/lib/v3/agent/utils/variables.js.map +1 -1
  42. package/dist/cjs/lib/v3/api.d.ts +5 -3
  43. package/dist/cjs/lib/v3/api.js +5 -15
  44. package/dist/cjs/lib/v3/api.js.map +1 -1
  45. package/dist/cjs/lib/v3/cache/AgentCache.js +5 -3
  46. package/dist/cjs/lib/v3/cache/AgentCache.js.map +1 -1
  47. package/dist/cjs/lib/v3/flowlogger/EventStore.js +1 -1
  48. package/dist/cjs/lib/v3/flowlogger/EventStore.js.map +1 -1
  49. package/dist/cjs/lib/v3/handlers/observeHandler.js +2 -1
  50. package/dist/cjs/lib/v3/handlers/observeHandler.js.map +1 -1
  51. package/dist/cjs/lib/v3/handlers/v3AgentHandler.d.ts +2 -1
  52. package/dist/cjs/lib/v3/handlers/v3AgentHandler.js +110 -46
  53. package/dist/cjs/lib/v3/handlers/v3AgentHandler.js.map +1 -1
  54. package/dist/cjs/lib/v3/handlers/v3CuaAgentHandler.d.ts +5 -0
  55. package/dist/cjs/lib/v3/handlers/v3CuaAgentHandler.js +131 -16
  56. package/dist/cjs/lib/v3/handlers/v3CuaAgentHandler.js.map +1 -1
  57. package/dist/cjs/lib/v3/index.d.ts +1 -1
  58. package/dist/cjs/lib/v3/llm/LLMProvider.d.ts +5 -2
  59. package/dist/cjs/lib/v3/llm/LLMProvider.js +14 -6
  60. package/dist/cjs/lib/v3/llm/LLMProvider.js.map +1 -1
  61. package/dist/cjs/lib/v3/llm/OpenAIClient.js +1 -0
  62. package/dist/cjs/lib/v3/llm/OpenAIClient.js.map +1 -1
  63. package/dist/cjs/lib/v3/llm/aisdk.d.ts +3 -1
  64. package/dist/cjs/lib/v3/llm/aisdk.js +67 -17
  65. package/dist/cjs/lib/v3/llm/aisdk.js.map +1 -1
  66. package/dist/cjs/lib/v3/types/private/cache.d.ts +0 -1
  67. package/dist/cjs/lib/v3/types/private/cache.js.map +1 -1
  68. package/dist/cjs/lib/v3/types/private/handlers.d.ts +1 -0
  69. package/dist/cjs/lib/v3/types/private/handlers.js.map +1 -1
  70. package/dist/cjs/lib/v3/types/public/agent.d.ts +8 -3
  71. package/dist/cjs/lib/v3/types/public/agent.js +1 -0
  72. package/dist/cjs/lib/v3/types/public/agent.js.map +1 -1
  73. package/dist/cjs/lib/v3/types/public/api.d.ts +54 -7
  74. package/dist/cjs/lib/v3/types/public/api.js +47 -16
  75. package/dist/cjs/lib/v3/types/public/api.js.map +1 -1
  76. package/dist/cjs/lib/v3/types/public/methods.d.ts +1 -0
  77. package/dist/cjs/lib/v3/types/public/methods.js.map +1 -1
  78. package/dist/cjs/lib/v3/types/public/model.d.ts +32 -2
  79. package/dist/cjs/lib/v3/types/public/model.js.map +1 -1
  80. package/dist/cjs/lib/v3/types/public/variables.d.ts +7 -0
  81. package/dist/cjs/lib/v3/types/public/variables.js +22 -0
  82. package/dist/cjs/lib/v3/types/public/variables.js.map +1 -0
  83. package/dist/cjs/lib/v3/understudy/context.js +11 -3
  84. package/dist/cjs/lib/v3/understudy/context.js.map +1 -1
  85. package/dist/cjs/lib/v3/understudy/page.js +1 -1
  86. package/dist/cjs/lib/v3/understudy/page.js.map +1 -1
  87. package/dist/cjs/lib/v3/v3.d.ts +23 -2
  88. package/dist/cjs/lib/v3/v3.js +111 -13
  89. package/dist/cjs/lib/v3/v3.js.map +1 -1
  90. package/dist/cjs/lib/version.d.ts +1 -1
  91. package/dist/cjs/lib/version.js +1 -1
  92. package/dist/cjs/lib/version.js.map +1 -1
  93. package/dist/cjs/tests/integration/agent-captcha-autosolve.spec.d.ts +1 -0
  94. package/dist/cjs/tests/integration/agent-captcha-autosolve.spec.js +56 -0
  95. package/dist/cjs/tests/integration/agent-captcha-autosolve.spec.js.map +1 -0
  96. package/dist/cjs/tests/integration/agent-hybrid-mode.spec.js +6 -6
  97. package/dist/cjs/tests/integration/agent-hybrid-mode.spec.js.map +1 -1
  98. package/dist/cjs/tests/integration/chrome-newtab-page-tracking.spec.d.ts +1 -0
  99. package/dist/cjs/tests/integration/chrome-newtab-page-tracking.spec.js +56 -0
  100. package/dist/cjs/tests/integration/chrome-newtab-page-tracking.spec.js.map +1 -0
  101. package/dist/cjs/tests/integration/timeouts.spec.js +1 -1
  102. package/dist/cjs/tests/integration/timeouts.spec.js.map +1 -1
  103. package/dist/cjs/tests/unit/agent-captcha-hooks.test.d.ts +1 -0
  104. package/dist/cjs/tests/unit/agent-captcha-hooks.test.js +341 -0
  105. package/dist/cjs/tests/unit/agent-captcha-hooks.test.js.map +1 -0
  106. package/dist/cjs/tests/unit/agent-execution-model.test.js +25 -3
  107. package/dist/cjs/tests/unit/agent-execution-model.test.js.map +1 -1
  108. package/dist/cjs/tests/unit/agent-metrics.test.d.ts +1 -0
  109. package/dist/cjs/tests/unit/agent-metrics.test.js +112 -0
  110. package/dist/cjs/tests/unit/agent-metrics.test.js.map +1 -0
  111. package/dist/cjs/tests/unit/agent-system-prompt-variables.test.d.ts +1 -0
  112. package/dist/cjs/tests/unit/agent-system-prompt-variables.test.js +23 -0
  113. package/dist/cjs/tests/unit/agent-system-prompt-variables.test.js.map +1 -0
  114. package/dist/cjs/tests/unit/aisdk-clients.test.d.ts +1 -0
  115. package/dist/cjs/tests/unit/aisdk-clients.test.js +90 -0
  116. package/dist/cjs/tests/unit/aisdk-clients.test.js.map +1 -0
  117. package/dist/cjs/tests/unit/anthropic-cua-adaptive-thinking.test.d.ts +1 -0
  118. package/dist/cjs/tests/unit/anthropic-cua-adaptive-thinking.test.js +250 -0
  119. package/dist/cjs/tests/unit/anthropic-cua-adaptive-thinking.test.js.map +1 -0
  120. package/dist/cjs/tests/unit/api-client-observe-variables.test.d.ts +1 -0
  121. package/dist/cjs/tests/unit/api-client-observe-variables.test.js +86 -0
  122. package/dist/cjs/tests/unit/api-client-observe-variables.test.js.map +1 -0
  123. package/dist/cjs/tests/unit/api-optional-model-api-key.test.d.ts +1 -0
  124. package/dist/cjs/tests/unit/api-optional-model-api-key.test.js +95 -0
  125. package/dist/cjs/tests/unit/api-optional-model-api-key.test.js.map +1 -0
  126. package/dist/cjs/tests/unit/api-variables-schema.test.d.ts +1 -0
  127. package/dist/cjs/tests/unit/api-variables-schema.test.js +37 -0
  128. package/dist/cjs/tests/unit/api-variables-schema.test.js.map +1 -0
  129. package/dist/cjs/tests/unit/browserbase-session-accessors.test.js +40 -0
  130. package/dist/cjs/tests/unit/browserbase-session-accessors.test.js.map +1 -1
  131. package/dist/cjs/tests/unit/captcha-solver.test.d.ts +1 -0
  132. package/dist/cjs/tests/unit/captcha-solver.test.js +154 -0
  133. package/dist/cjs/tests/unit/captcha-solver.test.js.map +1 -0
  134. package/dist/cjs/tests/unit/flowlogger-eventstore.test.js +1 -1
  135. package/dist/cjs/tests/unit/flowlogger-eventstore.test.js.map +1 -1
  136. package/dist/cjs/tests/unit/llm-middleware.test.d.ts +1 -0
  137. package/dist/cjs/tests/unit/llm-middleware.test.js +495 -0
  138. package/dist/cjs/tests/unit/llm-middleware.test.js.map +1 -0
  139. package/dist/cjs/tests/unit/microsoft-cua-client.test.d.ts +1 -0
  140. package/dist/cjs/tests/unit/microsoft-cua-client.test.js +86 -0
  141. package/dist/cjs/tests/unit/microsoft-cua-client.test.js.map +1 -0
  142. package/dist/cjs/tests/unit/openai-cua-client.test.d.ts +1 -0
  143. package/dist/cjs/tests/unit/openai-cua-client.test.js +71 -0
  144. package/dist/cjs/tests/unit/openai-cua-client.test.js.map +1 -0
  145. package/dist/cjs/tests/unit/prompt-observe-variables.test.d.ts +1 -0
  146. package/dist/cjs/tests/unit/prompt-observe-variables.test.js +19 -0
  147. package/dist/cjs/tests/unit/prompt-observe-variables.test.js.map +1 -0
  148. package/dist/cjs/tests/unit/public-api/llm-and-agents.test.js +1 -0
  149. package/dist/cjs/tests/unit/public-api/llm-and-agents.test.js.map +1 -1
  150. package/dist/cjs/tests/unit/public-api/public-types.test.js.map +1 -1
  151. package/dist/cjs/tests/unit/timeout-handlers.test.js +50 -0
  152. package/dist/cjs/tests/unit/timeout-handlers.test.js.map +1 -1
  153. package/dist/esm/lib/inference.d.ts +3 -1
  154. package/dist/esm/lib/inference.js +3 -3
  155. package/dist/esm/lib/inference.js.map +1 -1
  156. package/dist/esm/lib/prompt.d.ts +1 -1
  157. package/dist/esm/lib/prompt.js +24 -18
  158. package/dist/esm/lib/prompt.js.map +1 -1
  159. package/dist/esm/lib/v3/agent/AgentClient.d.ts +8 -0
  160. package/dist/esm/lib/v3/agent/AgentClient.js +13 -0
  161. package/dist/esm/lib/v3/agent/AgentClient.js.map +1 -1
  162. package/dist/esm/lib/v3/agent/AgentProvider.js +1 -0
  163. package/dist/esm/lib/v3/agent/AgentProvider.js.map +1 -1
  164. package/dist/esm/lib/v3/agent/AnthropicCUAClient.d.ts +3 -1
  165. package/dist/esm/lib/v3/agent/AnthropicCUAClient.js +61 -9
  166. package/dist/esm/lib/v3/agent/AnthropicCUAClient.js.map +1 -1
  167. package/dist/esm/lib/v3/agent/GoogleCUAClient.js +1 -0
  168. package/dist/esm/lib/v3/agent/GoogleCUAClient.js.map +1 -1
  169. package/dist/esm/lib/v3/agent/MicrosoftCUAClient.js +16 -0
  170. package/dist/esm/lib/v3/agent/MicrosoftCUAClient.js.map +1 -1
  171. package/dist/esm/lib/v3/agent/OpenAICUAClient.d.ts +12 -6
  172. package/dist/esm/lib/v3/agent/OpenAICUAClient.js +164 -49
  173. package/dist/esm/lib/v3/agent/OpenAICUAClient.js.map +1 -1
  174. package/dist/esm/lib/v3/agent/prompts/agentSystemPrompt.d.ts +2 -2
  175. package/dist/esm/lib/v3/agent/prompts/agentSystemPrompt.js +10 -11
  176. package/dist/esm/lib/v3/agent/prompts/agentSystemPrompt.js.map +1 -1
  177. package/dist/esm/lib/v3/agent/tools/fillform.d.ts +0 -1
  178. package/dist/esm/lib/v3/agent/tools/fillform.js +7 -10
  179. package/dist/esm/lib/v3/agent/tools/fillform.js.map +1 -1
  180. package/dist/esm/lib/v3/agent/tools/index.js +1 -1
  181. package/dist/esm/lib/v3/agent/tools/index.js.map +1 -1
  182. package/dist/esm/lib/v3/agent/tools/keys.d.ts +2 -1
  183. package/dist/esm/lib/v3/agent/tools/keys.js +57 -49
  184. package/dist/esm/lib/v3/agent/tools/keys.js.map +1 -1
  185. package/dist/esm/lib/v3/agent/utils/captchaSolver.d.ts +76 -0
  186. package/dist/esm/lib/v3/agent/utils/captchaSolver.js +171 -0
  187. package/dist/esm/lib/v3/agent/utils/captchaSolver.js.map +1 -0
  188. package/dist/esm/lib/v3/agent/utils/coordinateNormalization.js +3 -5
  189. package/dist/esm/lib/v3/agent/utils/coordinateNormalization.js.map +1 -1
  190. package/dist/esm/lib/v3/agent/utils/variables.d.ts +5 -0
  191. package/dist/esm/lib/v3/agent/utils/variables.js +8 -0
  192. package/dist/esm/lib/v3/agent/utils/variables.js.map +1 -1
  193. package/dist/esm/lib/v3/api.d.ts +5 -3
  194. package/dist/esm/lib/v3/api.js +5 -15
  195. package/dist/esm/lib/v3/api.js.map +1 -1
  196. package/dist/esm/lib/v3/cache/AgentCache.js +5 -3
  197. package/dist/esm/lib/v3/cache/AgentCache.js.map +1 -1
  198. package/dist/esm/lib/v3/flowlogger/EventStore.js +1 -1
  199. package/dist/esm/lib/v3/flowlogger/EventStore.js.map +1 -1
  200. package/dist/esm/lib/v3/handlers/observeHandler.js +2 -1
  201. package/dist/esm/lib/v3/handlers/observeHandler.js.map +1 -1
  202. package/dist/esm/lib/v3/handlers/v3AgentHandler.d.ts +2 -1
  203. package/dist/esm/lib/v3/handlers/v3AgentHandler.js +110 -46
  204. package/dist/esm/lib/v3/handlers/v3AgentHandler.js.map +1 -1
  205. package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.d.ts +5 -0
  206. package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.js +131 -16
  207. package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.js.map +1 -1
  208. package/dist/esm/lib/v3/index.d.ts +1 -1
  209. package/dist/esm/lib/v3/llm/LLMProvider.d.ts +5 -2
  210. package/dist/esm/lib/v3/llm/LLMProvider.js +15 -7
  211. package/dist/esm/lib/v3/llm/LLMProvider.js.map +1 -1
  212. package/dist/esm/lib/v3/llm/OpenAIClient.js +1 -0
  213. package/dist/esm/lib/v3/llm/OpenAIClient.js.map +1 -1
  214. package/dist/esm/lib/v3/llm/aisdk.d.ts +3 -1
  215. package/dist/esm/lib/v3/llm/aisdk.js +67 -17
  216. package/dist/esm/lib/v3/llm/aisdk.js.map +1 -1
  217. package/dist/esm/lib/v3/types/private/cache.d.ts +0 -1
  218. package/dist/esm/lib/v3/types/private/cache.js.map +1 -1
  219. package/dist/esm/lib/v3/types/private/handlers.d.ts +1 -0
  220. package/dist/esm/lib/v3/types/private/handlers.js.map +1 -1
  221. package/dist/esm/lib/v3/types/public/agent.d.ts +8 -3
  222. package/dist/esm/lib/v3/types/public/agent.js +1 -0
  223. package/dist/esm/lib/v3/types/public/agent.js.map +1 -1
  224. package/dist/esm/lib/v3/types/public/api.d.ts +54 -7
  225. package/dist/esm/lib/v3/types/public/api.js +42 -14
  226. package/dist/esm/lib/v3/types/public/api.js.map +1 -1
  227. package/dist/esm/lib/v3/types/public/methods.d.ts +1 -0
  228. package/dist/esm/lib/v3/types/public/methods.js.map +1 -1
  229. package/dist/esm/lib/v3/types/public/model.d.ts +32 -2
  230. package/dist/esm/lib/v3/types/public/model.js.map +1 -1
  231. package/dist/esm/lib/v3/types/public/variables.d.ts +7 -0
  232. package/dist/esm/lib/v3/types/public/variables.js +19 -0
  233. package/dist/esm/lib/v3/types/public/variables.js.map +1 -0
  234. package/dist/esm/lib/v3/understudy/context.js +11 -3
  235. package/dist/esm/lib/v3/understudy/context.js.map +1 -1
  236. package/dist/esm/lib/v3/understudy/page.js +1 -1
  237. package/dist/esm/lib/v3/understudy/page.js.map +1 -1
  238. package/dist/esm/lib/v3/v3.d.ts +23 -2
  239. package/dist/esm/lib/v3/v3.js +111 -14
  240. package/dist/esm/lib/v3/v3.js.map +1 -1
  241. package/dist/esm/lib/version.d.ts +1 -1
  242. package/dist/esm/lib/version.js +1 -1
  243. package/dist/esm/lib/version.js.map +1 -1
  244. package/dist/esm/tests/integration/agent-captcha-autosolve.spec.d.ts +1 -0
  245. package/dist/esm/tests/integration/agent-captcha-autosolve.spec.js +54 -0
  246. package/dist/esm/tests/integration/agent-captcha-autosolve.spec.js.map +1 -0
  247. package/dist/esm/tests/integration/agent-hybrid-mode.spec.js +6 -6
  248. package/dist/esm/tests/integration/agent-hybrid-mode.spec.js.map +1 -1
  249. package/dist/esm/tests/integration/chrome-newtab-page-tracking.spec.d.ts +1 -0
  250. package/dist/esm/tests/integration/chrome-newtab-page-tracking.spec.js +54 -0
  251. package/dist/esm/tests/integration/chrome-newtab-page-tracking.spec.js.map +1 -0
  252. package/dist/esm/tests/integration/timeouts.spec.js +1 -1
  253. package/dist/esm/tests/integration/timeouts.spec.js.map +1 -1
  254. package/dist/esm/tests/unit/agent-captcha-hooks.test.d.ts +1 -0
  255. package/dist/esm/tests/unit/agent-captcha-hooks.test.js +339 -0
  256. package/dist/esm/tests/unit/agent-captcha-hooks.test.js.map +1 -0
  257. package/dist/esm/tests/unit/agent-execution-model.test.js +25 -3
  258. package/dist/esm/tests/unit/agent-execution-model.test.js.map +1 -1
  259. package/dist/esm/tests/unit/agent-metrics.test.d.ts +1 -0
  260. package/dist/esm/tests/unit/agent-metrics.test.js +110 -0
  261. package/dist/esm/tests/unit/agent-metrics.test.js.map +1 -0
  262. package/dist/esm/tests/unit/agent-system-prompt-variables.test.d.ts +1 -0
  263. package/dist/esm/tests/unit/agent-system-prompt-variables.test.js +21 -0
  264. package/dist/esm/tests/unit/agent-system-prompt-variables.test.js.map +1 -0
  265. package/dist/esm/tests/unit/aisdk-clients.test.d.ts +1 -0
  266. package/dist/esm/tests/unit/aisdk-clients.test.js +88 -0
  267. package/dist/esm/tests/unit/aisdk-clients.test.js.map +1 -0
  268. package/dist/esm/tests/unit/anthropic-cua-adaptive-thinking.test.d.ts +1 -0
  269. package/dist/esm/tests/unit/anthropic-cua-adaptive-thinking.test.js +245 -0
  270. package/dist/esm/tests/unit/anthropic-cua-adaptive-thinking.test.js.map +1 -0
  271. package/dist/esm/tests/unit/api-client-observe-variables.test.d.ts +1 -0
  272. package/dist/esm/tests/unit/api-client-observe-variables.test.js +84 -0
  273. package/dist/esm/tests/unit/api-client-observe-variables.test.js.map +1 -0
  274. package/dist/esm/tests/unit/api-optional-model-api-key.test.d.ts +1 -0
  275. package/dist/esm/tests/unit/api-optional-model-api-key.test.js +93 -0
  276. package/dist/esm/tests/unit/api-optional-model-api-key.test.js.map +1 -0
  277. package/dist/esm/tests/unit/api-variables-schema.test.d.ts +1 -0
  278. package/dist/esm/tests/unit/api-variables-schema.test.js +35 -0
  279. package/dist/esm/tests/unit/api-variables-schema.test.js.map +1 -0
  280. package/dist/esm/tests/unit/browserbase-session-accessors.test.js +40 -0
  281. package/dist/esm/tests/unit/browserbase-session-accessors.test.js.map +1 -1
  282. package/dist/esm/tests/unit/captcha-solver.test.d.ts +1 -0
  283. package/dist/esm/tests/unit/captcha-solver.test.js +152 -0
  284. package/dist/esm/tests/unit/captcha-solver.test.js.map +1 -0
  285. package/dist/esm/tests/unit/flowlogger-eventstore.test.js +1 -1
  286. package/dist/esm/tests/unit/flowlogger-eventstore.test.js.map +1 -1
  287. package/dist/esm/tests/unit/llm-middleware.test.d.ts +1 -0
  288. package/dist/esm/tests/unit/llm-middleware.test.js +460 -0
  289. package/dist/esm/tests/unit/llm-middleware.test.js.map +1 -0
  290. package/dist/esm/tests/unit/microsoft-cua-client.test.d.ts +1 -0
  291. package/dist/esm/tests/unit/microsoft-cua-client.test.js +84 -0
  292. package/dist/esm/tests/unit/microsoft-cua-client.test.js.map +1 -0
  293. package/dist/esm/tests/unit/openai-cua-client.test.d.ts +1 -0
  294. package/dist/esm/tests/unit/openai-cua-client.test.js +69 -0
  295. package/dist/esm/tests/unit/openai-cua-client.test.js.map +1 -0
  296. package/dist/esm/tests/unit/prompt-observe-variables.test.d.ts +1 -0
  297. package/dist/esm/tests/unit/prompt-observe-variables.test.js +17 -0
  298. package/dist/esm/tests/unit/prompt-observe-variables.test.js.map +1 -0
  299. package/dist/esm/tests/unit/public-api/llm-and-agents.test.js +1 -0
  300. package/dist/esm/tests/unit/public-api/llm-and-agents.test.js.map +1 -1
  301. package/dist/esm/tests/unit/public-api/public-types.test.js.map +1 -1
  302. package/dist/esm/tests/unit/timeout-handlers.test.js +50 -0
  303. package/dist/esm/tests/unit/timeout-handlers.test.js.map +1 -1
  304. package/package.json +5 -9
  305. package/dist/cjs/lib/v3/dom/build/rerender-index.js +0 -1
  306. package/dist/cjs/lib/v3/dom/build/v3-index.js +0 -1
  307. package/dist/esm/lib/v3/dom/build/rerender-index.js +0 -1
  308. package/dist/esm/lib/v3/dom/build/v3-index.js +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../../lib/prompt.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,2BAA2B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zC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,GAAG,GAAG,CAAC;aACxB,IAAI,CAAC,IAAI,CAAC,CAAC;QACd,MAAM,eAAe,GAAG,+DAA+D,aAAa,uDAAuD,CAAC;QAC5J,WAAW,IAAI,IAAI,eAAe,EAAE,CAAC;IACvC,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,IAAY;IACpD,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE;;;;;EAKX,IAAI;;;;;;;;;;;;;;;;;;;;;;;mFAuB6E;KAChF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,2BAA2B;IACzC,OAAO,gJAAgJ,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;AACnM,CAAC;AAED,MAAM,UAAU,0BAA0B;IACxC,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE;kBACK,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;;;CAGvD;KACE,CAAC;AACJ,CAAC","sourcesContent":["import { ChatMessage } from \"./v3/llm/LLMClient.js\";\nimport type { Variables } from \"./v3/types/public/agent.js\";\n\nexport function buildUserInstructionsString(\n userProvidedInstructions?: string,\n): string {\n if (!userProvidedInstructions) {\n return \"\";\n }\n\n return `\\n\\n# Custom Instructions Provided by the User\n \nPlease keep the user's instructions in mind when performing actions. If the user's instructions are not relevant to the current task, ignore them.\n\nUser Instructions:\n${userProvidedInstructions}`;\n}\n\n// extract\nexport function buildExtractSystemPrompt(\n isUsingPrintExtractedDataTool: boolean = false,\n userProvidedInstructions?: string,\n): ChatMessage {\n const baseContent = `You are extracting content on behalf of a user.\n If a user asks you to extract a 'list' of information, or 'all' information, \n YOU MUST EXTRACT ALL OF THE INFORMATION THAT THE USER REQUESTS.\n \n You will be given:\n1. An instruction\n2. `;\n\n const contentDetail = `A list of DOM elements to extract from.`;\n\n const instructions = `\nPrint the exact text from the DOM elements with all symbols, characters, and endlines as is.\nPrint null or an empty string if no new information is found.\n `.trim();\n\n const toolInstructions = isUsingPrintExtractedDataTool\n ? `\nONLY print the content using the print_extracted_data tool provided.\nONLY print the content using the print_extracted_data tool provided.\n `.trim()\n : \"\";\n\n const additionalInstructions =\n \"If a user is attempting to extract links or URLs, you MUST respond with ONLY the IDs of the link elements. \\n\" +\n \"Do not attempt to extract links directly from the text unless absolutely necessary. \";\n\n const userInstructions = buildUserInstructionsString(\n userProvidedInstructions,\n );\n\n const content =\n `${baseContent}${contentDetail}\\n\\n${instructions}\\n${toolInstructions}${\n additionalInstructions ? `\\n\\n${additionalInstructions}` : \"\"\n }${userInstructions ? `\\n\\n${userInstructions}` : \"\"}`.replace(/\\s+/g, \" \");\n\n return {\n role: \"system\",\n content,\n };\n}\n\nexport function buildExtractUserPrompt(\n instruction: string,\n domElements: string,\n isUsingPrintExtractedDataTool: boolean = false,\n): ChatMessage {\n let content = `Instruction: ${instruction}\nDOM: ${domElements}`;\n\n if (isUsingPrintExtractedDataTool) {\n content += `\nONLY print the content using the print_extracted_data tool provided.\nONLY print the content using the print_extracted_data tool provided.`;\n }\n\n return {\n role: \"user\",\n content,\n };\n}\n\nconst metadataSystemPrompt = `You are an AI assistant tasked with evaluating the progress and completion status of an extraction task.\nAnalyze the extraction response and determine if the task is completed or if more information is needed.\nStrictly abide by the following criteria:\n1. Once the instruction has been satisfied by the current extraction response, ALWAYS set completion status to true and stop processing, regardless of remaining chunks.\n2. Only set completion status to false if BOTH of these conditions are true:\n - The instruction has not been satisfied yet\n - There are still chunks left to process (chunksTotal > chunksSeen)`;\n\nexport function buildMetadataSystemPrompt(): ChatMessage {\n return {\n role: \"system\",\n content: metadataSystemPrompt,\n };\n}\n\nexport function buildMetadataPrompt(\n instruction: string,\n extractionResponse: object,\n): ChatMessage {\n return {\n role: \"user\",\n content: `Instruction: ${instruction}\nExtracted content: ${JSON.stringify(extractionResponse, null, 2)}`,\n };\n}\n\n// observe\nexport function buildObserveSystemPrompt(\n userProvidedInstructions?: string,\n supportedActions?: string[],\n): ChatMessage {\n const actionsString = supportedActions?.length\n ? `\\n\\nSupported actions: ${supportedActions.join(\", \")}`\n : \"\";\n\n const observeSystemPrompt = `\nYou are helping the user automate the browser by finding elements based on what the user wants to observe in the page.\n\nYou will be given:\n1. a instruction of elements to observe\n2. a hierarchical accessibility tree showing the semantic structure of the page. The tree is a hybrid of the DOM and the accessibility tree.\n\nReturn an array of elements that match the instruction if they exist, otherwise return an empty array.\nWhen returning elements, include the appropriate method from the supported actions list.${actionsString}. When choosing non-left click actions, provide right or middle as the argument.`;\n const content = observeSystemPrompt.replace(/\\s+/g, \" \");\n\n return {\n role: \"system\",\n content: [content, buildUserInstructionsString(userProvidedInstructions)]\n .filter(Boolean)\n .join(\"\\n\\n\"),\n };\n}\n\nexport function buildObserveUserMessage(\n instruction: string,\n domElements: string,\n): ChatMessage {\n return {\n role: \"user\",\n content: `instruction: ${instruction}\nAccessibility Tree: \\n${domElements}\\n`,\n };\n}\n\nexport function buildActSystemPrompt(\n userProvidedInstructions?: string,\n): ChatMessage {\n const actSystemPrompt = `\nYou are helping the user automate the browser by finding elements based on what action the user wants to take on the page\n\nYou will be given:\n1. a user defined instruction about what action to take\n2. a hierarchical accessibility tree showing the semantic structure of the page. The tree is a hybrid of the DOM and the accessibility tree.\n\nReturn the element that matches the instruction if it exists. Otherwise, return an empty object.`;\n const content = actSystemPrompt.replace(/\\s+/g, \" \");\n\n return {\n role: \"system\",\n content: [content, buildUserInstructionsString(userProvidedInstructions)]\n .filter(Boolean)\n .join(\"\\n\\n\"),\n };\n}\n\nexport function buildActPrompt(\n action: string,\n supportedActions: string[],\n variables?: Variables,\n): string {\n // Base instruction\n let instruction = `Find the most relevant element to perform an action on given the following action: ${action}. \n IF AND ONLY IF the action EXPLICITLY includes the word 'dropdown' and implies choosing/selecting an option from a dropdown, ignore the 'General Instructions' section, and follow the 'Dropdown Specific Instructions' section carefully.\n \n General Instructions: \n Provide an action for this element such as ${supportedActions.join(\", \")}. Remember that to users, buttons and links look the same in most cases.\n When choosing non-left click actions, provide right or middle as the argument\n If the action is completely unrelated to a potential action to be taken on the page, return an empty object. \n ONLY return one action. If multiple actions are relevant, return the most relevant one. \n If the user is asking to scroll to a position on the page, e.g., 'halfway' or 0.75, etc, you must return the argument formatted as the correct percentage, e.g., '50%' or '75%', etc.\n If the user is asking to scroll to the next chunk/previous chunk, choose the nextChunk/prevChunk method. No arguments are required here.\n If the action implies a key press, e.g., 'press enter', 'press a', 'press space', etc., always choose the press method with the appropriate key as argument — e.g. 'a', 'Enter', 'Space'. Do not choose a click action on an on-screen keyboard. Capitalize the first character like 'Enter', 'Tab', 'Escape' only for special keys. \n \n Dropdown Specific Instructions:\n For interacting with dropdowns, there are two specific cases that you need to handle. \n \n CASE 1: the element is a 'select' element. \n - choose the selectOptionFromDropdown method,\n - set the argument to the exact text of the option that should be selected,\n - set twoStep to false.\n CASE 2: the element is NOT a 'select' element:\n - do not attempt to directly choose the element from the dropdown. You will need to click to expand the dropdown first. You will achieve this by following these instructions:\n - choose the node that most closely corresponds to the given instruction EVEN if it is a 'StaticText' element, or otherwise does not appear to be interactable. \n - choose the 'click' method\n - set twoStep to true.\n `;\n\n // Add variable names (not values) to the instruction if any\n if (variables && Object.keys(variables).length > 0) {\n const variableNames = Object.keys(variables)\n .map((key) => `%${key}%`)\n .join(\", \");\n const variablesPrompt = `The following variables are available to use in the action: ${variableNames}. Fill the argument variables with the variable name.`;\n instruction += ` ${variablesPrompt}`;\n }\n\n return instruction;\n}\n\nexport function buildStepTwoPrompt(\n originalUserAction: string,\n previousAction: string,\n supportedActions: string[],\n variables?: Variables,\n): string {\n // Base instruction\n let instruction = `\n The original user action was: ${originalUserAction}.\n You have just taken the following action which completed step 1 of 2: ${previousAction}.\n \n Now, you must find the most relevant element to perform an action on in order to complete step 2 of 2. \n \n General Instructions: \n Provide an action for this element such as ${supportedActions.join(\", \")}. Remember that to users, buttons and links look the same in most cases.\n If the action is completely unrelated to a potential action to be taken on the page, return an empty object. \n ONLY return one action. If multiple actions are relevant, return the most relevant one. \n If the user is asking to scroll to a position on the page, e.g., 'halfway' or 0.75, etc, you must return the argument formatted as the correct percentage, e.g., '50%' or '75%', etc.\n If the user is asking to scroll to the next chunk/previous chunk, choose the nextChunk/prevChunk method. No arguments are required here.\n If the action implies a key press, e.g., 'press enter', 'press a', 'press space', etc., always choose the press method with the appropriate key as argument — e.g. 'a', 'Enter', 'Space'. Do not choose a click action on an on-screen keyboard. Capitalize the first character like 'Enter', 'Tab', 'Escape' only for special keys. \n `;\n\n // Add variable names (not values) to the instruction if any\n if (variables && Object.keys(variables).length > 0) {\n const variableNames = Object.keys(variables)\n .map((key) => `%${key}%`)\n .join(\", \");\n const variablesPrompt = `The following variables are available to use in the action: ${variableNames}. Fill the argument variables with the variable name.`;\n instruction += ` ${variablesPrompt}`;\n }\n\n return instruction;\n}\n\nexport function buildOperatorSystemPrompt(goal: string): ChatMessage {\n return {\n role: \"system\",\n content: `You are a general-purpose agent whose job is to accomplish the user's goal across multiple model calls by running actions on the page.\n\nYou will be given a goal and a list of steps that have been taken so far. Your job is to determine if either the user's goal has been completed or if there are still steps that need to be taken.\n\n# Your current goal\n${goal}\n\n# CRITICAL: You MUST use the provided tools to take actions. Do not just describe what you want to do - actually call the appropriate tools.\n\n# Available tools and when to use them:\n- \\`act\\`: Use this to interact with the page (click, type, navigate, etc.)\n- \\`extract\\`: Use this to get information from the page\n- \\`goto\\`: Use this to navigate to a specific URL\n- \\`wait\\`: Use this to wait for a period of time\n- \\`navback\\`: Use this to go back to the previous page\n- \\`refresh\\`: Use this to refresh the current page\n- \\`close\\`: Use this ONLY when the task is complete or cannot be achieved\n- External tools: Use any additional tools (like search tools) as needed for your goal\n\n# Important guidelines\n1. ALWAYS use tools - never just provide text responses about what you plan to do\n2. Break down complex actions into individual atomic steps\n3. For \\`act\\` commands, use only one action at a time, such as:\n - Single click on a specific element\n - Type into a single input field\n - Select a single option\n4. Avoid combining multiple actions in one instruction\n5. If multiple actions are needed, they should be separate steps\n6. Only use \\`close\\` when the task is genuinely complete or impossible to achieve`,\n };\n}\n\nexport function buildCuaDefaultSystemPrompt(): string {\n return `You are a helpful assistant that can use a web browser.\\nDo not ask follow up questions, the user will trust your judgement. Today's date is ${new Date().toISOString().split(\"T\")[0]}.`;\n}\n\nexport function buildGoogleCUASystemPrompt(): ChatMessage {\n return {\n role: \"system\",\n content: `You are a general-purpose browser agent whose job is to accomplish the user's goal.\nToday's date is ${new Date().toISOString().split(\"T\")[0]}.\nYou have access to a search tool; however, in most cases you should operate within the page/url the user has provided. ONLY use the search tool if you're stuck or the task is impossible to complete within the current page.\nYou will be given a goal and a list of steps that have been taken so far. Avoid requesting the user for input as much as possible. Good luck!\n`,\n };\n}\n"]}
1
+ {"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../../lib/prompt.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzE,MAAM,UAAU,2BAA2B,CACzC,wBAAiC;IAEjC,IAAI,CAAC,wBAAwB,EAAE,CAAC;QAC9B,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,OAAO;;;;;EAKP,wBAAwB,EAAE,CAAC;AAC7B,CAAC;AAED,UAAU;AACV,MAAM,UAAU,wBAAwB,CACtC,gCAAyC,KAAK,EAC9C,wBAAiC;IAEjC,MAAM,WAAW,GAAG;;;;;;IAMlB,CAAC;IAEH,MAAM,aAAa,GAAG,yCAAyC,CAAC;IAEhE,MAAM,YAAY,GAAG;;;GAGpB,CAAC,IAAI,EAAE,CAAC;IAET,MAAM,gBAAgB,GAAG,6BAA6B;QACpD,CAAC,CAAC;;;GAGH,CAAC,IAAI,EAAE;QACN,CAAC,CAAC,EAAE,CAAC;IAEP,MAAM,sB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EAKX,IAAI;;;;;;;;;;;;;;;;;;;;;;;mFAuB6E;KAChF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,2BAA2B;IACzC,OAAO,gJAAgJ,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;AACnM,CAAC;AAED,MAAM,UAAU,0BAA0B;IACxC,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE;kBACK,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;;;CAGvD;KACE,CAAC;AACJ,CAAC","sourcesContent":["import { ChatMessage } from \"./v3/llm/LLMClient.js\";\nimport type { Variables } from \"./v3/types/public/agent.js\";\nimport { getVariablePromptEntries } from \"./v3/agent/utils/variables.js\";\n\nexport function buildUserInstructionsString(\n userProvidedInstructions?: string,\n): string {\n if (!userProvidedInstructions) {\n return \"\";\n }\n\n return `\\n\\n# Custom Instructions Provided by the User\n \nPlease keep the user's instructions in mind when performing actions. If the user's instructions are not relevant to the current task, ignore them.\n\nUser Instructions:\n${userProvidedInstructions}`;\n}\n\n// extract\nexport function buildExtractSystemPrompt(\n isUsingPrintExtractedDataTool: boolean = false,\n userProvidedInstructions?: string,\n): ChatMessage {\n const baseContent = `You are extracting content on behalf of a user.\n If a user asks you to extract a 'list' of information, or 'all' information, \n YOU MUST EXTRACT ALL OF THE INFORMATION THAT THE USER REQUESTS.\n \n You will be given:\n1. An instruction\n2. `;\n\n const contentDetail = `A list of DOM elements to extract from.`;\n\n const instructions = `\nPrint the exact text from the DOM elements with all symbols, characters, and endlines as is.\nPrint null or an empty string if no new information is found.\n `.trim();\n\n const toolInstructions = isUsingPrintExtractedDataTool\n ? `\nONLY print the content using the print_extracted_data tool provided.\nONLY print the content using the print_extracted_data tool provided.\n `.trim()\n : \"\";\n\n const additionalInstructions =\n \"If a user is attempting to extract links or URLs, you MUST respond with ONLY the IDs of the link elements. \\n\" +\n \"Do not attempt to extract links directly from the text unless absolutely necessary. \";\n\n const userInstructions = buildUserInstructionsString(\n userProvidedInstructions,\n );\n\n const content =\n `${baseContent}${contentDetail}\\n\\n${instructions}\\n${toolInstructions}${\n additionalInstructions ? `\\n\\n${additionalInstructions}` : \"\"\n }${userInstructions ? `\\n\\n${userInstructions}` : \"\"}`.replace(/\\s+/g, \" \");\n\n return {\n role: \"system\",\n content,\n };\n}\n\nexport function buildExtractUserPrompt(\n instruction: string,\n domElements: string,\n isUsingPrintExtractedDataTool: boolean = false,\n): ChatMessage {\n let content = `Instruction: ${instruction}\nDOM: ${domElements}`;\n\n if (isUsingPrintExtractedDataTool) {\n content += `\nONLY print the content using the print_extracted_data tool provided.\nONLY print the content using the print_extracted_data tool provided.`;\n }\n\n return {\n role: \"user\",\n content,\n };\n}\n\nconst metadataSystemPrompt = `You are an AI assistant tasked with evaluating the progress and completion status of an extraction task.\nAnalyze the extraction response and determine if the task is completed or if more information is needed.\nStrictly abide by the following criteria:\n1. Once the instruction has been satisfied by the current extraction response, ALWAYS set completion status to true and stop processing, regardless of remaining chunks.\n2. Only set completion status to false if BOTH of these conditions are true:\n - The instruction has not been satisfied yet\n - There are still chunks left to process (chunksTotal > chunksSeen)`;\n\nexport function buildMetadataSystemPrompt(): ChatMessage {\n return {\n role: \"system\",\n content: metadataSystemPrompt,\n };\n}\n\nexport function buildMetadataPrompt(\n instruction: string,\n extractionResponse: object,\n): ChatMessage {\n return {\n role: \"user\",\n content: `Instruction: ${instruction}\nExtracted content: ${JSON.stringify(extractionResponse, null, 2)}`,\n };\n}\n\n// observe\nexport function buildObserveSystemPrompt(\n userProvidedInstructions?: string,\n supportedActions?: string[],\n variables?: Variables,\n): ChatMessage {\n const actionsString = supportedActions?.length\n ? `\\n\\nSupported actions: ${supportedActions.join(\", \")}`\n : \"\";\n const variableEntries = getVariablePromptEntries(variables);\n const variablesString = variableEntries.length\n ? `\\n\\nAvailable variables: ${variableEntries\n .map(({ name, description }) => {\n return description ? `%${name}% (${description})` : `%${name}%`;\n })\n .join(\n \", \",\n )}. When an action needs a dynamic or sensitive value, return the matching %variableName% placeholder in the action arguments instead of a literal value`\n : \"\";\n\n const observeSystemPrompt = `\nYou are helping the user automate the browser by finding elements based on what the user wants to observe in the page.\n\nYou will be given:\n1. a instruction of elements to observe\n2. a hierarchical accessibility tree showing the semantic structure of the page. The tree is a hybrid of the DOM and the accessibility tree.\n\nReturn an array of elements that match the instruction if they exist, otherwise return an empty array.\nWhen returning elements, include the appropriate method from the supported actions list.${actionsString}${variablesString}. When choosing non-left click actions, provide right or middle as the argument.`;\n const content = observeSystemPrompt.replace(/\\s+/g, \" \");\n\n return {\n role: \"system\",\n content: [content, buildUserInstructionsString(userProvidedInstructions)]\n .filter(Boolean)\n .join(\"\\n\\n\"),\n };\n}\n\nexport function buildObserveUserMessage(\n instruction: string,\n domElements: string,\n): ChatMessage {\n return {\n role: \"user\",\n content: `instruction: ${instruction}\nAccessibility Tree: \\n${domElements}\\n`,\n };\n}\n\nexport function buildActSystemPrompt(\n userProvidedInstructions?: string,\n): ChatMessage {\n const actSystemPrompt = `\nYou are helping the user automate the browser by finding elements based on what action the user wants to take on the page\n\nYou will be given:\n1. a user defined instruction about what action to take\n2. a hierarchical accessibility tree showing the semantic structure of the page. The tree is a hybrid of the DOM and the accessibility tree.\n\nReturn the element that matches the instruction if it exists. Otherwise, return an empty object.`;\n const content = actSystemPrompt.replace(/\\s+/g, \" \");\n\n return {\n role: \"system\",\n content: [content, buildUserInstructionsString(userProvidedInstructions)]\n .filter(Boolean)\n .join(\"\\n\\n\"),\n };\n}\n\nfunction buildActVariablesPrompt(variables?: Variables): string {\n if (!variables || Object.keys(variables).length === 0) {\n return \"\";\n }\n\n const variableNames = Object.keys(variables)\n .map((key) => `%${key}%`)\n .join(\", \");\n\n return ` The user has provided the following variables to be used in the action: ${variableNames} \\n\n Note that these are the variable names/keys, and not the actual variable values. \\n\n To use the variables in the action, you must respond with the variable name inside the 'arguments' array. The variable name must be wrapped in percentage signs (eg, %variableNameHere%) so that it can be replaced with the actual variable value before the action is taken. \\n`;\n}\n\nexport function buildActPrompt(\n action: string,\n supportedActions: string[],\n variables?: Variables,\n): string {\n // Base instruction\n let instruction = `Find the most relevant element to perform an action on given the following action: ${action}. \n IF AND ONLY IF the action EXPLICITLY includes the word 'dropdown' and implies choosing/selecting an option from a dropdown, ignore the 'General Instructions' section, and follow the 'Dropdown Specific Instructions' section carefully.\n \n General Instructions: \n Provide an action for this element such as ${supportedActions.join(\", \")}. Remember that to users, buttons and links look the same in most cases.\n When choosing non-left click actions, provide right or middle as the argument\n If the action is completely unrelated to a potential action to be taken on the page, return an empty object. \n ONLY return one action. If multiple actions are relevant, return the most relevant one. \n If the user is asking to scroll to a position on the page, e.g., 'halfway' or 0.75, etc, you must return the argument formatted as the correct percentage, e.g., '50%' or '75%', etc.\n If the user is asking to scroll to the next chunk/previous chunk, choose the nextChunk/prevChunk method. No arguments are required here.\n If the action implies a key press, e.g., 'press enter', 'press a', 'press space', etc., always choose the press method with the appropriate key as argument — e.g. 'a', 'Enter', 'Space'. Do not choose a click action on an on-screen keyboard. Capitalize the first character like 'Enter', 'Tab', 'Escape' only for special keys. \n \n Dropdown Specific Instructions:\n For interacting with dropdowns, there are two specific cases that you need to handle. \n \n CASE 1: the element is a 'select' element. \n - choose the selectOptionFromDropdown method,\n - set the argument to the exact text of the option that should be selected,\n - set twoStep to false.\n CASE 2: the element is NOT a 'select' element:\n - do not attempt to directly choose the element from the dropdown. You will need to click to expand the dropdown first. You will achieve this by following these instructions:\n - choose the node that most closely corresponds to the given instruction EVEN if it is a 'StaticText' element, or otherwise does not appear to be interactable. \n - choose the 'click' method\n - set twoStep to true.\n `;\n\n instruction += buildActVariablesPrompt(variables);\n\n return instruction;\n}\n\nexport function buildStepTwoPrompt(\n originalUserAction: string,\n previousAction: string,\n supportedActions: string[],\n variables?: Variables,\n): string {\n // Base instruction\n let instruction = `\n The original user action was: ${originalUserAction}.\n You have just taken the following action which completed step 1 of 2: ${previousAction}.\n \n Now, you must find the most relevant element to perform an action on in order to complete step 2 of 2. \n \n General Instructions: \n Provide an action for this element such as ${supportedActions.join(\", \")}. Remember that to users, buttons and links look the same in most cases.\n If the action is completely unrelated to a potential action to be taken on the page, return an empty object. \n ONLY return one action. If multiple actions are relevant, return the most relevant one. \n If the user is asking to scroll to a position on the page, e.g., 'halfway' or 0.75, etc, you must return the argument formatted as the correct percentage, e.g., '50%' or '75%', etc.\n If the user is asking to scroll to the next chunk/previous chunk, choose the nextChunk/prevChunk method. No arguments are required here.\n If the action implies a key press, e.g., 'press enter', 'press a', 'press space', etc., always choose the press method with the appropriate key as argument — e.g. 'a', 'Enter', 'Space'. Do not choose a click action on an on-screen keyboard. Capitalize the first character like 'Enter', 'Tab', 'Escape' only for special keys. \n `;\n\n instruction += buildActVariablesPrompt(variables);\n\n return instruction;\n}\n\nexport function buildOperatorSystemPrompt(goal: string): ChatMessage {\n return {\n role: \"system\",\n content: `You are a general-purpose agent whose job is to accomplish the user's goal across multiple model calls by running actions on the page.\n\nYou will be given a goal and a list of steps that have been taken so far. Your job is to determine if either the user's goal has been completed or if there are still steps that need to be taken.\n\n# Your current goal\n${goal}\n\n# CRITICAL: You MUST use the provided tools to take actions. Do not just describe what you want to do - actually call the appropriate tools.\n\n# Available tools and when to use them:\n- \\`act\\`: Use this to interact with the page (click, type, navigate, etc.)\n- \\`extract\\`: Use this to get information from the page\n- \\`goto\\`: Use this to navigate to a specific URL\n- \\`wait\\`: Use this to wait for a period of time\n- \\`navback\\`: Use this to go back to the previous page\n- \\`refresh\\`: Use this to refresh the current page\n- \\`close\\`: Use this ONLY when the task is complete or cannot be achieved\n- External tools: Use any additional tools (like search tools) as needed for your goal\n\n# Important guidelines\n1. ALWAYS use tools - never just provide text responses about what you plan to do\n2. Break down complex actions into individual atomic steps\n3. For \\`act\\` commands, use only one action at a time, such as:\n - Single click on a specific element\n - Type into a single input field\n - Select a single option\n4. Avoid combining multiple actions in one instruction\n5. If multiple actions are needed, they should be separate steps\n6. Only use \\`close\\` when the task is genuinely complete or impossible to achieve`,\n };\n}\n\nexport function buildCuaDefaultSystemPrompt(): string {\n return `You are a helpful assistant that can use a web browser.\\nDo not ask follow up questions, the user will trust your judgement. Today's date is ${new Date().toISOString().split(\"T\")[0]}.`;\n}\n\nexport function buildGoogleCUASystemPrompt(): ChatMessage {\n return {\n role: \"system\",\n content: `You are a general-purpose browser agent whose job is to accomplish the user's goal.\nToday's date is ${new Date().toISOString().split(\"T\")[0]}.\nYou have access to a search tool; however, in most cases you should operate within the page/url the user has provided. ONLY use the search tool if you're stuck or the task is impossible to complete within the current page.\nYou will be given a goal and a list of steps that have been taken so far. Avoid requesting the user for input as much as possible. Good luck!\n`,\n };\n}\n"]}
@@ -16,4 +16,12 @@ export declare abstract class AgentClient {
16
16
  abstract setCurrentUrl(url: string): void;
17
17
  abstract setScreenshotProvider(provider: () => Promise<string>): void;
18
18
  abstract setActionHandler(handler: (action: AgentAction) => Promise<void>): void;
19
+ /** Optional hook called at the top of every step in the agent loop. */
20
+ protected preStepHook?: () => Promise<void>;
21
+ setPreStepHook(handler: () => Promise<void>): void;
22
+ /**
23
+ * Optional ephemeral context note that should be sent to the next model turn.
24
+ * Clients that do not support this can ignore it.
25
+ */
26
+ addContextNote(note: string): void;
19
27
  }
@@ -13,5 +13,18 @@ export class AgentClient {
13
13
  this.userProvidedInstructions = userProvidedInstructions;
14
14
  this.clientOptions = {};
15
15
  }
16
+ /** Optional hook called at the top of every step in the agent loop. */
17
+ preStepHook;
18
+ setPreStepHook(handler) {
19
+ this.preStepHook = handler;
20
+ }
21
+ /**
22
+ * Optional ephemeral context note that should be sent to the next model turn.
23
+ * Clients that do not support this can ignore it.
24
+ */
25
+ addContextNote(note) {
26
+ void note;
27
+ // no-op by default
28
+ }
16
29
  }
17
30
  //# sourceMappingURL=AgentClient.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AgentClient.js","sourceRoot":"","sources":["../../../../../lib/v3/agent/AgentClient.ts"],"names":[],"mappings":"AAQA;;;GAGG;AACH,MAAM,OAAgB,WAAW;IACxB,IAAI,CAAY;IAChB,SAAS,CAAS;IAClB,aAAa,CAAgB;IAC7B,wBAAwB,CAAU;IAEzC,YACE,IAAe,EACf,SAAiB,EACjB,wBAAiC;QAEjC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,wBAAwB,GAAG,wBAAwB,CAAC;QACzD,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;IAC1B,CAAC;CAiBF","sourcesContent":["import {\n AgentAction,\n AgentResult,\n AgentType,\n AgentExecutionOptions,\n} from \"../types/public/agent.js\";\nimport { ClientOptions } from \"../types/public/model.js\";\n\n/**\n * Abstract base class for agent clients\n * This provides a common interface for all agent implementations\n */\nexport abstract class AgentClient {\n public type: AgentType;\n public modelName: string;\n public clientOptions: ClientOptions;\n public userProvidedInstructions?: string;\n\n constructor(\n type: AgentType,\n modelName: string,\n userProvidedInstructions?: string,\n ) {\n this.type = type;\n this.modelName = modelName;\n this.userProvidedInstructions = userProvidedInstructions;\n this.clientOptions = {};\n }\n\n abstract execute(options: AgentExecutionOptions): Promise<AgentResult>;\n\n abstract captureScreenshot(\n options?: Record<string, unknown>,\n ): Promise<unknown>;\n\n abstract setViewport(width: number, height: number): void;\n\n abstract setCurrentUrl(url: string): void;\n\n abstract setScreenshotProvider(provider: () => Promise<string>): void;\n\n abstract setActionHandler(\n handler: (action: AgentAction) => Promise<void>,\n ): void;\n}\n"]}
1
+ {"version":3,"file":"AgentClient.js","sourceRoot":"","sources":["../../../../../lib/v3/agent/AgentClient.ts"],"names":[],"mappings":"AAQA;;;GAGG;AACH,MAAM,OAAgB,WAAW;IACxB,IAAI,CAAY;IAChB,SAAS,CAAS;IAClB,aAAa,CAAgB;IAC7B,wBAAwB,CAAU;IAEzC,YACE,IAAe,EACf,SAAiB,EACjB,wBAAiC;QAEjC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,wBAAwB,GAAG,wBAAwB,CAAC;QACzD,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;IAC1B,CAAC;IAkBD,uEAAuE;IAC7D,WAAW,CAAuB;IAE5C,cAAc,CAAC,OAA4B;QACzC,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC;IAC7B,CAAC;IAED;;;OAGG;IACH,cAAc,CAAC,IAAY;QACzB,KAAK,IAAI,CAAC;QACV,mBAAmB;IACrB,CAAC;CACF","sourcesContent":["import {\n AgentAction,\n AgentResult,\n AgentType,\n AgentExecutionOptions,\n} from \"../types/public/agent.js\";\nimport { ClientOptions } from \"../types/public/model.js\";\n\n/**\n * Abstract base class for agent clients\n * This provides a common interface for all agent implementations\n */\nexport abstract class AgentClient {\n public type: AgentType;\n public modelName: string;\n public clientOptions: ClientOptions;\n public userProvidedInstructions?: string;\n\n constructor(\n type: AgentType,\n modelName: string,\n userProvidedInstructions?: string,\n ) {\n this.type = type;\n this.modelName = modelName;\n this.userProvidedInstructions = userProvidedInstructions;\n this.clientOptions = {};\n }\n\n abstract execute(options: AgentExecutionOptions): Promise<AgentResult>;\n\n abstract captureScreenshot(\n options?: Record<string, unknown>,\n ): Promise<unknown>;\n\n abstract setViewport(width: number, height: number): void;\n\n abstract setCurrentUrl(url: string): void;\n\n abstract setScreenshotProvider(provider: () => Promise<string>): void;\n\n abstract setActionHandler(\n handler: (action: AgentAction) => Promise<void>,\n ): void;\n\n /** Optional hook called at the top of every step in the agent loop. */\n protected preStepHook?: () => Promise<void>;\n\n setPreStepHook(handler: () => Promise<void>): void {\n this.preStepHook = handler;\n }\n\n /**\n * Optional ephemeral context note that should be sent to the next model turn.\n * Clients that do not support this can ignore it.\n */\n addContextNote(note: string): void {\n void note;\n // no-op by default\n }\n}\n"]}
@@ -5,6 +5,7 @@ import { GoogleCUAClient } from "./GoogleCUAClient.js";
5
5
  import { MicrosoftCUAClient } from "./MicrosoftCUAClient.js";
6
6
  // Map model names to their provider types
7
7
  export const modelToAgentProviderMap = {
8
+ "gpt-5.4": "openai",
8
9
  "computer-use-preview": "openai",
9
10
  "computer-use-preview-2025-03-11": "openai",
10
11
  "claude-sonnet-4-20250514": "anthropic",
@@ -1 +1 @@
1
- {"version":3,"file":"AgentProvider.js","sourceRoot":"","sources":["../../../../../lib/v3/agent/AgentProvider.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,qBAAqB,EACrB,6BAA6B,GAC9B,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,0CAA0C;AAC1C,MAAM,CAAC,MAAM,uBAAuB,GAAsC;IACxE,sBAAsB,EAAE,QAAQ;IAChC,iCAAiC,EAAE,QAAQ;IAC3C,0BAA0B,EAAE,WAAW;IACvC,4BAA4B,EAAE,WAAW;IACzC,0BAA0B,EAAE,WAAW;IACvC,iBAAiB,EAAE,WAAW;IAC9B,mBAAmB,EAAE,WAAW;IAChC,2BAA2B,EAAE,WAAW;IACxC,yCAAyC,EAAE,QAAQ;IACnD,wBAAwB,EAAE,QAAQ;IAClC,sBAAsB,EAAE,QAAQ;IAChC,SAAS,EAAE,WAAW;CACvB,CAAC;AAEF;;;;GAIG;AACH,MAAM,OAAO,aAAa;IAChB,MAAM,CAA6B;IAE3C;;OAEG;IACH,YAAY,MAAkC;QAC5C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,SAAS,CACP,SAAiB,EACjB,aAA6B,EAC7B,wBAAiC,EACjC,K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AAO,EAAE,gCAAgC,YAAY,EAAE;gBACvD,KAAK,EAAE,CAAC;aACT,CAAC,CAAC;YACH,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED,MAAM,CAAC,gBAAgB,CAAC,SAAiB;QACvC,MAAM,UAAU,GAAG,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC;YACxC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YACzB,CAAC,CAAC,SAAS,CAAC;QAEd,IAAI,UAAU,IAAI,uBAAuB,EAAE,CAAC;YAC1C,OAAO,uBAAuB,CAAC,UAAU,CAAC,CAAC;QAC7C,CAAC;QAED,MAAM,IAAI,qBAAqB,CAC7B,MAAM,CAAC,IAAI,CAAC,uBAAuB,CAAC,EACpC,oBAAoB,CACrB,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { ToolSet } from \"ai/dist\";\nimport { AgentProviderType } from \"../types/public/agent.js\";\nimport { LogLine } from \"../types/public/logs.js\";\nimport { ClientOptions } from \"../types/public/model.js\";\nimport {\n UnsupportedModelError,\n UnsupportedModelProviderError,\n} from \"../types/public/sdkErrors.js\";\nimport { AgentClient } from \"./AgentClient.js\";\nimport { AnthropicCUAClient } from \"./AnthropicCUAClient.js\";\nimport { OpenAICUAClient } from \"./OpenAICUAClient.js\";\nimport { GoogleCUAClient } from \"./GoogleCUAClient.js\";\nimport { MicrosoftCUAClient } from \"./MicrosoftCUAClient.js\";\n\n// Map model names to their provider types\nexport const modelToAgentProviderMap: Record<string, AgentProviderType> = {\n \"computer-use-preview\": \"openai\",\n \"computer-use-preview-2025-03-11\": \"openai\",\n \"claude-sonnet-4-20250514\": \"anthropic\",\n \"claude-sonnet-4-5-20250929\": \"anthropic\",\n \"claude-opus-4-5-20251101\": \"anthropic\",\n \"claude-opus-4-6\": \"anthropic\",\n \"claude-sonnet-4-6\": \"anthropic\",\n \"claude-haiku-4-5-20251001\": \"anthropic\",\n \"gemini-2.5-computer-use-preview-10-2025\": \"google\",\n \"gemini-3-flash-preview\": \"google\",\n \"gemini-3-pro-preview\": \"google\",\n \"fara-7b\": \"microsoft\",\n};\n\n/**\n * Provider for agent clients\n * This class is responsible for creating the appropriate agent client\n * based on the provider type\n */\nexport class AgentProvider {\n private logger: (message: LogLine) => void;\n\n /**\n * Create a new agent provider\n */\n constructor(logger: (message: LogLine) => void) {\n this.logger = logger;\n }\n\n getClient(\n modelName: string,\n clientOptions?: ClientOptions,\n userProvidedInstructions?: string,\n tools?: ToolSet,\n ): AgentClient {\n // Check if provider is explicitly set in clientOptions\n const explicitProvider = clientOptions?.provider as\n | AgentProviderType\n | undefined;\n const type = explicitProvider || AgentProvider.getAgentProvider(modelName);\n\n this.logger({\n category: \"agent\",\n message: `Getting agent client for type: ${type}, model: ${modelName}${explicitProvider ? \" (explicit provider)\" : \"\"}`,\n level: 2,\n });\n\n try {\n switch (type) {\n case \"openai\":\n return new OpenAICUAClient(\n type,\n modelName,\n userProvidedInstructions,\n clientOptions,\n tools,\n );\n case \"anthropic\":\n return new AnthropicCUAClient(\n type,\n modelName,\n userProvidedInstructions,\n clientOptions,\n tools,\n );\n case \"google\":\n return new GoogleCUAClient(\n type,\n modelName,\n userProvidedInstructions,\n clientOptions,\n tools,\n );\n case \"microsoft\":\n return new MicrosoftCUAClient(\n type,\n modelName,\n userProvidedInstructions,\n clientOptions,\n );\n default:\n throw new UnsupportedModelProviderError(\n [\"openai\", \"anthropic\", \"google\", \"microsoft\"],\n \"Computer Use Agent\",\n );\n }\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n this.logger({\n category: \"agent\",\n message: `Error creating agent client: ${errorMessage}`,\n level: 0,\n });\n throw error;\n }\n }\n\n static getAgentProvider(modelName: string): AgentProviderType {\n const normalized = modelName.includes(\"/\")\n ? modelName.split(\"/\")[1]\n : modelName;\n\n if (normalized in modelToAgentProviderMap) {\n return modelToAgentProviderMap[normalized];\n }\n\n throw new UnsupportedModelError(\n Object.keys(modelToAgentProviderMap),\n \"Computer Use Agent\",\n );\n }\n}\n"]}
1
+ {"version":3,"file":"AgentProvider.js","sourceRoot":"","sources":["../../../../../lib/v3/agent/AgentProvider.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,qBAAqB,EACrB,6BAA6B,GAC9B,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,0CAA0C;AAC1C,MAAM,CAAC,MAAM,uBAAuB,GAAsC;IACxE,SAAS,EAAE,QAAQ;IACnB,sBAAsB,EAAE,QAAQ;IAChC,iCAAiC,EAAE,QAAQ;IAC3C,0BAA0B,EAAE,WAAW;IACvC,4BAA4B,EAAE,WAAW;IACzC,0BAA0B,EAAE,WAAW;IACvC,iBAAiB,EAAE,WAAW;IAC9B,mBAAmB,EAAE,WAAW;IAChC,2BAA2B,EAAE,WAAW;IACxC,yCAAyC,EAAE,QAAQ;IACnD,wBAAwB,EAAE,QAAQ;IAClC,sBAAsB,EAAE,QAAQ;IAChC,SAAS,EAAE,WAAW;CACvB,CAAC;AAEF;;;;GAIG;AACH,MAAM,OAAO,aAAa;IAChB,MAAM,CAA6B;IAE3C;;OAEG;IACH,YAAY,MAAkC;QAC5C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,SAAS,CACP,SAAiB,EACjB,aAA6B,EAC7B,wBAAiC,EACjC,KAAe;QAEf,uDAAuD;QACvD,MAAM,gBAAgB,GAAG,aAAa,EAAE,QAE3B,CAAC;QACd,MAAM,IAAI,GAAG,gBAAgB,IAAI,aAAa,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;QAE3E,IAAI,CAAC,MAAM,CAAC;YACV,QAA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QAAQ,CAAC,GAAG,CAAC;YACxC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YACzB,CAAC,CAAC,SAAS,CAAC;QAEd,IAAI,UAAU,IAAI,uBAAuB,EAAE,CAAC;YAC1C,OAAO,uBAAuB,CAAC,UAAU,CAAC,CAAC;QAC7C,CAAC;QAED,MAAM,IAAI,qBAAqB,CAC7B,MAAM,CAAC,IAAI,CAAC,uBAAuB,CAAC,EACpC,oBAAoB,CACrB,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { ToolSet } from \"ai/dist\";\nimport { AgentProviderType } from \"../types/public/agent.js\";\nimport { LogLine } from \"../types/public/logs.js\";\nimport { ClientOptions } from \"../types/public/model.js\";\nimport {\n UnsupportedModelError,\n UnsupportedModelProviderError,\n} from \"../types/public/sdkErrors.js\";\nimport { AgentClient } from \"./AgentClient.js\";\nimport { AnthropicCUAClient } from \"./AnthropicCUAClient.js\";\nimport { OpenAICUAClient } from \"./OpenAICUAClient.js\";\nimport { GoogleCUAClient } from \"./GoogleCUAClient.js\";\nimport { MicrosoftCUAClient } from \"./MicrosoftCUAClient.js\";\n\n// Map model names to their provider types\nexport const modelToAgentProviderMap: Record<string, AgentProviderType> = {\n \"gpt-5.4\": \"openai\",\n \"computer-use-preview\": \"openai\",\n \"computer-use-preview-2025-03-11\": \"openai\",\n \"claude-sonnet-4-20250514\": \"anthropic\",\n \"claude-sonnet-4-5-20250929\": \"anthropic\",\n \"claude-opus-4-5-20251101\": \"anthropic\",\n \"claude-opus-4-6\": \"anthropic\",\n \"claude-sonnet-4-6\": \"anthropic\",\n \"claude-haiku-4-5-20251001\": \"anthropic\",\n \"gemini-2.5-computer-use-preview-10-2025\": \"google\",\n \"gemini-3-flash-preview\": \"google\",\n \"gemini-3-pro-preview\": \"google\",\n \"fara-7b\": \"microsoft\",\n};\n\n/**\n * Provider for agent clients\n * This class is responsible for creating the appropriate agent client\n * based on the provider type\n */\nexport class AgentProvider {\n private logger: (message: LogLine) => void;\n\n /**\n * Create a new agent provider\n */\n constructor(logger: (message: LogLine) => void) {\n this.logger = logger;\n }\n\n getClient(\n modelName: string,\n clientOptions?: ClientOptions,\n userProvidedInstructions?: string,\n tools?: ToolSet,\n ): AgentClient {\n // Check if provider is explicitly set in clientOptions\n const explicitProvider = clientOptions?.provider as\n | AgentProviderType\n | undefined;\n const type = explicitProvider || AgentProvider.getAgentProvider(modelName);\n\n this.logger({\n category: \"agent\",\n message: `Getting agent client for type: ${type}, model: ${modelName}${explicitProvider ? \" (explicit provider)\" : \"\"}`,\n level: 2,\n });\n\n try {\n switch (type) {\n case \"openai\":\n return new OpenAICUAClient(\n type,\n modelName,\n userProvidedInstructions,\n clientOptions,\n tools,\n );\n case \"anthropic\":\n return new AnthropicCUAClient(\n type,\n modelName,\n userProvidedInstructions,\n clientOptions,\n tools,\n );\n case \"google\":\n return new GoogleCUAClient(\n type,\n modelName,\n userProvidedInstructions,\n clientOptions,\n tools,\n );\n case \"microsoft\":\n return new MicrosoftCUAClient(\n type,\n modelName,\n userProvidedInstructions,\n clientOptions,\n );\n default:\n throw new UnsupportedModelProviderError(\n [\"openai\", \"anthropic\", \"google\", \"microsoft\"],\n \"Computer Use Agent\",\n );\n }\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n this.logger({\n category: \"agent\",\n message: `Error creating agent client: ${errorMessage}`,\n level: 0,\n });\n throw error;\n }\n }\n\n static getAgentProvider(modelName: string): AgentProviderType {\n const normalized = modelName.includes(\"/\")\n ? modelName.split(\"/\")[1]\n : modelName;\n\n if (normalized in modelToAgentProviderMap) {\n return modelToAgentProviderMap[normalized];\n }\n\n throw new UnsupportedModelError(\n Object.keys(modelToAgentProviderMap),\n \"Computer Use Agent\",\n );\n }\n}\n"]}
@@ -18,6 +18,8 @@ export declare class AnthropicCUAClient extends AgentClient {
18
18
  private screenshotProvider?;
19
19
  private actionHandler?;
20
20
  private thinkingBudget;
21
+ private thinkingEffort;
22
+ private userTemperature;
21
23
  private tools?;
22
24
  constructor(type: AgentType, modelName: string, userProvidedInstructions?: string, clientOptions?: ClientOptions, tools?: ToolSet);
23
25
  setViewport(width: number, height: number): void;
@@ -43,7 +45,7 @@ export declare class AnthropicCUAClient extends AgentClient {
43
45
  };
44
46
  }>;
45
47
  private createInitialInputItems;
46
- getAction(inputItems: ResponseInputItem[]): Promise<{
48
+ getAction(inputItems: ResponseInputItem[], logger?: (message: LogLine) => void): Promise<{
47
49
  content: AnthropicContentBlock[];
48
50
  id: string;
49
51
  usage: Record<string, number>;
@@ -19,6 +19,8 @@ export class AnthropicCUAClient extends AgentClient {
19
19
  screenshotProvider;
20
20
  actionHandler;
21
21
  thinkingBudget = null;
22
+ thinkingEffort = null;
23
+ userTemperature;
22
24
  tools;
23
25
  constructor(type, modelName, userProvidedInstructions, clientOptions, tools) {
24
26
  super(type, modelName, userProvidedInstructions);
@@ -26,11 +28,17 @@ export class AnthropicCUAClient extends AgentClient {
26
28
  this.apiKey =
27
29
  clientOptions?.apiKey || process.env.ANTHROPIC_API_KEY || "";
28
30
  this.baseURL = clientOptions?.baseURL || undefined;
29
- // Get thinking budget if specified
31
+ // Get thinking budget if specified (deprecated for 4.6 models)
30
32
  if (clientOptions?.thinkingBudget &&
31
33
  typeof clientOptions.thinkingBudget === "number") {
32
34
  this.thinkingBudget = clientOptions.thinkingBudget;
33
35
  }
36
+ // Get thinking effort for adaptive thinking (Claude 4.6+ models)
37
+ if (clientOptions?.thinkingEffort) {
38
+ this.thinkingEffort = clientOptions.thinkingEffort;
39
+ }
40
+ // Track user-specified temperature so we can warn if adaptive thinking overrides it
41
+ this.userTemperature = clientOptions?.temperature;
34
42
  // Store client options for reference
35
43
  this.clientOptions = {
36
44
  apiKey: this.apiKey,
@@ -84,6 +92,7 @@ export class AnthropicCUAClient extends AgentClient {
84
92
  try {
85
93
  // Execute steps until completion or max steps reached
86
94
  while (!completed && currentStep < maxSteps) {
95
+ await this.preStepHook?.();
87
96
  logger({
88
97
  category: "agent",
89
98
  message: `Executing step ${currentStep + 1}/${maxSteps}`,
@@ -157,7 +166,7 @@ export class AnthropicCUAClient extends AgentClient {
157
166
  async executeStep(inputItems, logger) {
158
167
  try {
159
168
  // Get response from the model
160
- const result = await this.getAction(inputItems);
169
+ const result = await this.getAction(inputItems, logger);
161
170
  const content = result.content;
162
171
  const usage = {
163
172
  input_tokens: result.usage.input_tokens,
@@ -316,7 +325,7 @@ export class AnthropicCUAClient extends AgentClient {
316
325
  },
317
326
  ];
318
327
  }
319
- async getAction(inputItems) {
328
+ async getAction(inputItems, logger) {
320
329
  try {
321
330
  // For the API request, we use the inputItems directly
322
331
  // These should already be properly formatted as a sequence of user/assistant messages
@@ -331,19 +340,46 @@ export class AnthropicCUAClient extends AgentClient {
331
340
  // Note: We don't need special handling for tool_result items here anymore
332
341
  // as they should already be properly wrapped in user messages
333
342
  }
334
- // Configure thinking capability if available
335
- const thinking = this.thinkingBudget
336
- ? { type: "enabled", budget_tokens: this.thinkingBudget }
337
- : undefined;
338
343
  // Claude 4.6+ models require the newer computer_20251124 tool version
344
+ // and support adaptive thinking instead of budget_tokens
339
345
  const modelBase = this.modelName.includes("/")
340
346
  ? this.modelName.split("/")[1]
341
347
  : this.modelName;
342
- const shouldUseNewToolVersion = [
348
+ // Check if this is a Claude 4.6+ model that supports adaptive thinking
349
+ const isAdaptiveThinkingModel = [
343
350
  "claude-opus-4-6",
344
351
  "claude-sonnet-4-6",
345
- "claude-opus-4-5-20251101",
346
352
  ].includes(modelBase);
353
+ // claude-opus-4-5-20251101 uses the newer computer tool version but does
354
+ // NOT support adaptive thinking — it still requires budget_tokens.
355
+ const shouldUseNewToolVersion = isAdaptiveThinkingModel || modelBase === "claude-opus-4-5-20251101";
356
+ // Configure thinking capability based on model version
357
+ // - For 4.6 models: Use adaptive thinking with effort (recommended, defaults to "medium")
358
+ // - For older models: Use enabled thinking with budget_tokens (deprecated)
359
+ let thinking;
360
+ let outputConfig;
361
+ let useAdaptiveThinking = false;
362
+ if (isAdaptiveThinkingModel) {
363
+ if (this.thinkingBudget) {
364
+ logger?.({
365
+ category: "agent",
366
+ message: `thinkingBudget is ignored for ${this.modelName}; use thinkingEffort instead`,
367
+ level: 2,
368
+ });
369
+ }
370
+ if (this.thinkingEffort !== "none") {
371
+ // Claude 4.6+ models use adaptive thinking with output_config.effort
372
+ // Default to "medium" effort if not explicitly specified
373
+ // See: https://platform.claude.com/docs/en/build-with-claude/adaptive-thinking
374
+ thinking = { type: "adaptive" };
375
+ outputConfig = { effort: this.thinkingEffort || "medium" };
376
+ useAdaptiveThinking = true;
377
+ }
378
+ }
379
+ else if (this.thinkingBudget) {
380
+ // Older models use enabled thinking with budget_tokens (deprecated for 4.6)
381
+ thinking = { type: "enabled", budget_tokens: this.thinkingBudget };
382
+ }
347
383
  const computerToolType = shouldUseNewToolVersion
348
384
  ? "computer_20251124"
349
385
  : "computer_20250124";
@@ -396,6 +432,22 @@ export class AnthropicCUAClient extends AgentClient {
396
432
  if (thinking) {
397
433
  requestParams.thinking = thinking;
398
434
  }
435
+ // Add output_config for adaptive thinking (Claude 4.6+ models)
436
+ if (outputConfig) {
437
+ requestParams.output_config = outputConfig;
438
+ }
439
+ // Adaptive thinking requires temperature to be set to 1
440
+ // See: https://platform.claude.com/docs/en/build-with-claude/adaptive-thinking
441
+ if (useAdaptiveThinking) {
442
+ if (this.userTemperature !== undefined && this.userTemperature !== 1) {
443
+ logger?.({
444
+ category: "agent",
445
+ message: `Adaptive thinking requires temperature=1; overriding user-specified temperature=${this.userTemperature}`,
446
+ level: 2,
447
+ });
448
+ }
449
+ requestParams.temperature = 1;
450
+ }
399
451
  // Log LLM request
400
452
  const llmRequestId = uuidv7();
401
453
  FlowLogger.logLlmRequest({
@@ -1 +1 @@
1
- {"version":3,"file":"AnthropicCUAClient.js","sourceRoot":"","sources":["../../../../../lib/v3/agent/AnthropicCUAClient.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,4BAA4B,EAC5B,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AC;QACd,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,sCAAsC,EAAE,KAAK,CAAC,CAAC;YAC7D,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAC,OAGvB;QACC,oCAAoC;QACpC,IAAI,OAAO,EAAE,WAAW,EAAE,CAAC;YACzB,OAAO,yBAAyB,OAAO,CAAC,WAAW,EAAE,CAAC;QACxD,CAAC;QAED,2CAA2C;QAC3C,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC5B,IAAI,CAAC;gBACH,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,kBAAkB,EAAE,CAAC;gBACpD,OAAO,yBAAyB,WAAW,EAAE,CAAC;YAChD,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAC;gBACpD,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;QAED,MAAM,IAAI,4BAA4B,CACpC,yCAAyC;YACvC,iGAAiG,CACpG,CAAC;IACJ,CAAC;CACF","sourcesContent":["import {\n AgentAction,\n AgentResult,\n AgentType,\n AnthropicContentBlock,\n AnthropicMessage,\n AnthropicTextBlock,\n AnthropicToolResult,\n AgentExecutionOptions,\n ToolUseItem,\n} from \"../types/public/agent.js\";\nimport { LogLine } from \"../types/public/logs.js\";\nimport { ClientOptions } from \"../types/public/model.js\";\nimport {\n AgentScreenshotProviderError,\n StagehandClosedError,\n} from \"../types/public/sdkErrors.js\";\nimport Anthropic from \"@anthropic-ai/sdk\";\nimport { ToolSet } from \"ai\";\nimport { AgentClient } from \"./AgentClient.js\";\nimport { compressConversationImages } from \"./utils/imageCompression.js\";\nimport { toJsonSchema } from \"../zodCompat.js\";\nimport type { StagehandZodSchema } from \"../zodCompat.js\";\nimport {\n FlowLogger,\n extractLlmCuaPromptSummary,\n extractLlmCuaResponseSummary,\n} from \"../flowlogger/FlowLogger.js\";\nimport { v7 as uuidv7 } from \"uuid\";\n\nexport type ResponseInputItem = AnthropicMessage | AnthropicToolResult;\n\n/**\n * Client for Anthropic's Computer Use API\n * This implementation uses the official Anthropic Messages API for Computer Use\n */\nexport class AnthropicCUAClient extends AgentClient {\n private apiKey: string;\n private baseURL?: string;\n private client: Anthropic;\n public lastMessageId?: string;\n private currentViewport = { width: 1288, height: 711 };\n private currentUrl?: string;\n private screenshotProvider?: () => Promise<string>;\n private actionHandler?: (action: AgentAction) => Promise<void>;\n private thinkingBudget: number | null = null;\n private tools?: ToolSet;\n\n constructor(\n type: AgentType,\n modelName: string,\n userProvidedInstructions?: string,\n clientOptions?: ClientOptions,\n tools?: ToolSet,\n ) {\n super(type, modelName, userProvidedInstructions);\n\n // Process client options\n this.apiKey =\n (clientOptions?.apiKey as string) || process.env.ANTHROPIC_API_KEY || \"\";\n this.baseURL = (clientOptions?.baseURL as string) || undefined;\n\n // Get thinking budget if specified\n if (\n clientOptions?.thinkingBudget &&\n typeof clientOptions.thinkingBudget === \"number\"\n ) {\n this.thinkingBudget = clientOptions.thinkingBudget;\n }\n\n // Store client options for reference\n this.clientOptions = {\n apiKey: this.apiKey,\n };\n\n if (this.baseURL) {\n this.clientOptions.baseURL = this.baseURL;\n }\n\n // Initialize the Anthropic client\n this.client = new Anthropic(this.clientOptions);\n\n this.tools = tools;\n }\n\n setViewport(width: number, height: number): void {\n this.currentViewport = { width, height };\n }\n\n setCurrentUrl(url: string): void {\n this.currentUrl = url;\n }\n\n setScreenshotProvider(provider: () => Promise<string>): void {\n this.screenshotProvider = provider;\n }\n\n setActionHandler(handler: (action: AgentAction) => Promise<void>): void {\n this.actionHandler = handler;\n }\n\n setTools(tools: ToolSet): void {\n this.tools = tools;\n }\n\n /**\n * Execute a task with the Anthropic CUA\n * This is the main entry point for the agent\n * @implements AgentClient.execute\n */\n async execute(executionOptions: AgentExecutionOptions): Promise<AgentResult> {\n const { options, logger } = executionOptions;\n const { instruction } = options;\n const maxSteps = options.maxSteps || 10;\n\n let currentStep = 0;\n let completed = false;\n const actions: AgentAction[] = [];\n const messageList: string[] = [];\n let finalMessage = \"\";\n\n // Start with the initial instruction\n let inputItems: ResponseInputItem[] =\n this.createInitialInputItems(instruction);\n\n logger({\n category: \"agent\",\n message: `Starting Anthropic agent execution with instruction: ${instruction}`,\n level: 1,\n });\n\n let totalInputTokens = 0;\n let totalOutputTokens = 0;\n let totalInferenceTime = 0;\n\n try {\n // Execute steps until completion or max steps reached\n while (!completed && currentStep < maxSteps) {\n logger({\n category: \"agent\",\n message: `Executing step ${currentStep + 1}/${maxSteps}`,\n level: 1,\n });\n\n const result = await this.executeStep(inputItems, logger);\n totalInputTokens += result.usage.input_tokens;\n totalOutputTokens += result.usage.output_tokens;\n totalInferenceTime += result.usage.inference_time_ms;\n\n // Add actions to the list\n if (result.actions.length > 0) {\n logger({\n category: \"agent\",\n message: `Step ${currentStep + 1} performed ${result.actions.length} actions`,\n level: 2,\n });\n actions.push(...result.actions);\n }\n\n // Update completion status\n completed = result.completed;\n\n // Update the input items for the next step if we're continuing\n if (!completed) {\n inputItems = result.nextInputItems;\n }\n\n // Record any message for this step\n if (result.message) {\n messageList.push(result.message);\n finalMessage = result.message;\n }\n\n // Increment step counter\n currentStep++;\n }\n\n logger({\n category: \"agent\",\n message: `Anthropic agent execution completed: ${completed}, with ${actions.length} total actions performed`,\n level: 1,\n });\n\n // Return the final result\n return {\n success: completed,\n actions,\n message: finalMessage,\n completed,\n usage: {\n input_tokens: totalInputTokens,\n output_tokens: totalOutputTokens,\n inference_time_ms: totalInferenceTime,\n },\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n logger({\n category: \"agent\",\n message: `Error executing agent task: ${errorMessage}`,\n level: 0,\n });\n\n return {\n success: false,\n actions,\n message: `Failed to execute task: ${errorMessage}`,\n completed: false,\n usage: {\n input_tokens: totalInputTokens,\n output_tokens: totalOutputTokens,\n inference_time_ms: totalInferenceTime,\n },\n };\n }\n }\n\n async executeStep(\n inputItems: ResponseInputItem[],\n logger: (message: LogLine) => void,\n ): Promise<{\n actions: AgentAction[];\n message: string;\n completed: boolean;\n nextInputItems: ResponseInputItem[];\n usage: {\n input_tokens: number;\n output_tokens: number;\n inference_time_ms: number;\n };\n }> {\n try {\n // Get response from the model\n const result = await this.getAction(inputItems);\n const content = result.content;\n const usage = {\n input_tokens: result.usage.input_tokens,\n output_tokens: result.usage.output_tokens,\n inference_time_ms: result.usage.inference_time_ms,\n };\n\n logger({\n category: \"agent\",\n message: `Received response with ${content.length} content blocks`,\n level: 2,\n });\n\n // Extract actions from the content\n const stepActions: AgentAction[] = [];\n const toolUseItems: ToolUseItem[] = [];\n let message = \"\";\n\n // Process content blocks to find tool use items and text content\n for (const block of content) {\n logger({\n category: \"agent\",\n message: `Processing block type: ${block.type}, id: ${block.id || \"unknown\"}`,\n level: 2,\n });\n\n if (block.type === \"tool_use\") {\n // Direct handling of tool_use type\n logger({\n category: \"agent\",\n message: `Found tool_use block: ${JSON.stringify(block)}`,\n level: 2,\n });\n\n // Cast to ToolUseItem and add to list\n const toolUseItem = block as ToolUseItem;\n toolUseItems.push(toolUseItem);\n\n logger({\n category: \"agent\",\n message: `Added tool_use item: ${toolUseItem.name}, action: ${JSON.stringify(toolUseItem.input)}`,\n level: 2,\n });\n\n // Convert tool use to action and add to actions list\n const action = this.convertToolUseToAction(toolUseItem);\n if (action) {\n logger({\n category: \"agent\",\n message: `Created action from tool_use: ${toolUseItem.name}, action: ${action.type}`,\n level: 2,\n });\n stepActions.push(action);\n } else if (this.tools && toolUseItem.name in this.tools) {\n stepActions.push({\n type: \"custom_tool\",\n tool: toolUseItem.name,\n input: toolUseItem.input,\n } as AgentAction);\n }\n } else if (block.type === \"text\") {\n // Safe to cast here since we've verified it's a text block\n const textBlock = block as unknown as AnthropicTextBlock;\n message += textBlock.text + \"\\n\";\n\n logger({\n category: \"agent\",\n message: `Found text block: ${textBlock.text}`,\n level: 2,\n });\n } else {\n logger({\n category: \"agent\",\n message: `Found unknown block type: ${block.type}`,\n level: 2,\n });\n }\n }\n\n // Execute actions if an action handler is provided\n if (this.actionHandler && stepActions.length > 0) {\n for (const action of stepActions) {\n try {\n logger({\n category: \"agent\",\n message: `Executing action: ${action.type}`,\n level: 1,\n });\n await this.actionHandler(action);\n } catch (error) {\n if (error instanceof StagehandClosedError) {\n throw error;\n }\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n logger({\n category: \"agent\",\n message: `Error executing action ${action.type}: ${errorMessage}`,\n level: 0,\n });\n }\n }\n }\n\n // Create the assistant response message with all content blocks\n const assistantMessage: AnthropicMessage = {\n role: \"assistant\",\n content: content as unknown as AnthropicContentBlock[],\n };\n\n // Keep track of the conversation history by preserving all previous messages\n // and adding new messages at the end\n const nextInputItems: ResponseInputItem[] = [...inputItems];\n\n // Add the assistant message with tool_use blocks to the history\n compressConversationImages(nextInputItems);\n\n nextInputItems.push(assistantMessage);\n\n // Generate tool results and add them as a user message\n if (toolUseItems.length > 0) {\n const toolResults = await this.takeAction(toolUseItems, logger);\n\n if (toolResults.length > 0) {\n // Tool results are AnthropicToolResult[] which are compatible with AnthropicContentBlock[]\n const userToolResultsMessage: AnthropicMessage = {\n role: \"user\",\n content: toolResults as unknown as AnthropicContentBlock[],\n };\n nextInputItems.push(userToolResultsMessage);\n }\n }\n\n // The step is completed only if there were no tool_use items\n const completed = toolUseItems.length === 0;\n\n logger({\n category: \"agent\",\n message: `Step processed ${toolUseItems.length} tool use items, completed: ${completed}`,\n level: 2,\n });\n\n return {\n actions: stepActions,\n message: message.trim(),\n completed,\n nextInputItems,\n usage: usage,\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n logger({\n category: \"agent\",\n message: `Error executing step: ${errorMessage}`,\n level: 0,\n });\n\n throw error;\n }\n }\n\n private createInitialInputItems(instruction: string): AnthropicMessage[] {\n // For the initial request, we use a simple array with the user's instruction\n return [\n {\n role: \"system\",\n content: this.userProvidedInstructions,\n },\n {\n role: \"user\",\n content: instruction,\n },\n ];\n }\n\n async getAction(inputItems: ResponseInputItem[]): Promise<{\n content: AnthropicContentBlock[];\n id: string;\n usage: Record<string, number>;\n }> {\n try {\n // For the API request, we use the inputItems directly\n // These should already be properly formatted as a sequence of user/assistant messages\n const messages: AnthropicMessage[] = [];\n\n for (const item of inputItems) {\n if (\"role\" in item) {\n // Skip system messages as Anthropic requires system as a top-level parameter\n if (item.role !== \"system\") {\n messages.push(item);\n }\n }\n // Note: We don't need special handling for tool_result items here anymore\n // as they should already be properly wrapped in user messages\n }\n\n // Configure thinking capability if available\n const thinking = this.thinkingBudget\n ? { type: \"enabled\" as const, budget_tokens: this.thinkingBudget }\n : undefined;\n\n // Claude 4.6+ models require the newer computer_20251124 tool version\n const modelBase = this.modelName.includes(\"/\")\n ? this.modelName.split(\"/\")[1]\n : this.modelName;\n const shouldUseNewToolVersion = [\n \"claude-opus-4-6\",\n \"claude-sonnet-4-6\",\n \"claude-opus-4-5-20251101\",\n ].includes(modelBase);\n\n const computerToolType = shouldUseNewToolVersion\n ? \"computer_20251124\"\n : \"computer_20250124\";\n const betaFlag = shouldUseNewToolVersion\n ? \"computer-use-2025-11-24\"\n : \"computer-use-2025-01-24\";\n\n // Create the request parameters\n const requestParams: Record<string, unknown> = {\n model: this.modelName,\n max_tokens: 4096,\n messages: messages,\n tools: [\n {\n type: computerToolType,\n name: \"computer\",\n display_width_px: this.currentViewport.width,\n display_height_px: this.currentViewport.height,\n display_number: 1,\n },\n ],\n betas: [betaFlag],\n };\n\n // Add custom tools if available\n if (this.tools && Object.keys(this.tools).length > 0) {\n const customTools = Object.entries(this.tools).map(([name, tool]) => {\n const schema = tool.inputSchema as StagehandZodSchema;\n\n // Convert Zod schema to proper JSON schema format for Anthropic\n const jsonSchema = toJsonSchema(schema) as {\n properties?: Record<string, unknown>;\n required?: string[];\n };\n\n const inputSchema = {\n type: \"object\",\n properties: jsonSchema.properties || {},\n required: jsonSchema.required || [],\n };\n\n return {\n name,\n description: tool.description,\n input_schema: inputSchema,\n };\n });\n\n requestParams.tools = [\n ...(requestParams.tools as Record<string, unknown>[]),\n ...customTools,\n ];\n }\n\n // Add system parameter if provided\n if (this.userProvidedInstructions) {\n requestParams.system = this.userProvidedInstructions;\n }\n\n // Add thinking parameter if available\n if (thinking) {\n requestParams.thinking = thinking;\n }\n\n // Log LLM request\n const llmRequestId = uuidv7();\n FlowLogger.logLlmRequest({\n requestId: llmRequestId,\n model: this.modelName,\n prompt: extractLlmCuaPromptSummary(messages),\n });\n\n const startTime = Date.now();\n // Create the message using the Anthropic Messages API\n // @ts-expect-error - The Anthropic SDK types are stricter than what we need\n const response = await this.client.beta.messages.create(requestParams);\n const endTime = Date.now();\n const elapsedMs = endTime - startTime;\n const usage = {\n input_tokens: response.usage.input_tokens,\n output_tokens: response.usage.output_tokens,\n inference_time_ms: elapsedMs,\n };\n\n // Log LLM response\n FlowLogger.logLlmResponse({\n requestId: llmRequestId,\n model: this.modelName,\n output: extractLlmCuaResponseSummary(response.content),\n inputTokens: response.usage.input_tokens,\n outputTokens: response.usage.output_tokens,\n });\n\n // Store the message ID for future use\n this.lastMessageId = response.id;\n\n // Return the content and message ID\n return {\n // Cast the response content to our internal type\n content: response.content as unknown as AnthropicContentBlock[],\n id: response.id,\n usage,\n };\n } catch (error) {\n console.error(\"Error getting action from Anthropic:\", error);\n throw error;\n }\n }\n\n async takeAction(\n toolUseItems: ToolUseItem[],\n logger: (message: LogLine) => void,\n ): Promise<AnthropicToolResult[]> {\n const toolResults: AnthropicToolResult[] = [];\n\n logger({\n category: \"agent\",\n message: `Taking action on ${toolUseItems.length} tool use items`,\n level: 2,\n });\n\n // Process each tool use item\n for (const item of toolUseItems) {\n try {\n logger({\n category: \"agent\",\n message: `Processing tool use: ${item.name}, id: ${item.id}, action: ${JSON.stringify(item.input)}`,\n level: 2,\n });\n\n // TODO: Normalize and migrate to agentHandler\n\n // For computer tool, capture screenshot and return image\n if (item.name === \"computer\") {\n // Get action type\n const action = item.input.action as string;\n logger({\n category: \"agent\",\n message: `Computer action type: ${action}`,\n level: 2,\n });\n\n // Capture a screenshot for the response\n const screenshot = await this.captureScreenshot();\n logger({\n category: \"agent\",\n message: `Screenshot captured, length: ${screenshot.length}`,\n level: 2,\n });\n\n // Create proper image content block for Anthropic\n const imageContent = [\n {\n type: \"image\",\n source: {\n type: \"base64\",\n media_type: \"image/png\",\n data: screenshot.replace(/^data:image\\/png;base64,/, \"\"),\n },\n },\n ];\n\n // Add current URL if available\n if (this.currentUrl) {\n toolResults.push({\n type: \"tool_result\",\n tool_use_id: item.id,\n content: [\n ...imageContent,\n {\n type: \"text\",\n text: `Current URL: ${this.currentUrl}`,\n },\n ],\n });\n } else {\n toolResults.push({\n type: \"tool_result\",\n tool_use_id: item.id,\n content: imageContent,\n });\n }\n\n logger({\n category: \"agent\",\n message: `Added computer tool result for tool_use_id: ${item.id}`,\n level: 2,\n });\n } else {\n // Handle custom tools\n let toolResult = \"Tool executed successfully\";\n if (this.tools && item.name in this.tools) {\n try {\n const tool = this.tools[item.name];\n\n logger({\n category: \"agent\",\n message: `Executing tool call: ${item.name} with args: ${JSON.stringify(item.input)}`,\n level: 1,\n });\n\n const result = await tool.execute(item.input, {\n toolCallId: item.id,\n messages: [],\n });\n toolResult = JSON.stringify(result);\n\n logger({\n category: \"agent\",\n message: `Tool ${item.name} completed successfully. Result: ${toolResult}`,\n level: 1,\n });\n } catch (toolError) {\n const errorMessage =\n toolError instanceof Error\n ? toolError.message\n : String(toolError);\n toolResult = `Error executing tool: ${errorMessage}`;\n\n logger({\n category: \"agent\",\n message: `Error executing tool ${item.name}: ${errorMessage}`,\n level: 0,\n });\n }\n }\n\n toolResults.push({\n type: \"tool_result\",\n tool_use_id: item.id,\n content: [\n {\n type: \"text\",\n text: toolResult,\n },\n ],\n });\n\n logger({\n category: \"agent\",\n message: `Added custom tool result for tool ${item.name}, tool_use_id: ${item.id}`,\n level: 2,\n });\n }\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n\n logger({\n category: \"agent\",\n message: `Error executing tool use: ${errorMessage}`,\n level: 0,\n });\n\n try {\n // For computer tool, try to capture a screenshot even on error\n if (item.name === \"computer\") {\n const screenshot = await this.captureScreenshot();\n\n toolResults.push({\n type: \"tool_result\",\n tool_use_id: item.id,\n content: [\n {\n type: \"image\",\n source: {\n type: \"base64\",\n media_type: \"image/png\",\n data: screenshot.replace(/^data:image\\/png;base64,/, \"\"),\n },\n },\n {\n type: \"text\",\n text: `Error: ${errorMessage}`,\n },\n ],\n });\n\n logger({\n category: \"agent\",\n message: `Added error tool result with screenshot for tool_use_id: ${item.id}`,\n level: 1,\n });\n } else {\n // For other tools, return an error message as a text content block\n toolResults.push({\n type: \"tool_result\",\n tool_use_id: item.id,\n content: [\n {\n type: \"text\",\n text: `Error: ${errorMessage}`,\n },\n ],\n });\n\n logger({\n category: \"agent\",\n message: `Added error tool result for tool_use_id: ${item.id}`,\n level: 1,\n });\n }\n } catch (screenshotError) {\n // If we can't capture a screenshot, just send the error\n logger({\n category: \"agent\",\n message: `Error capturing screenshot: ${String(screenshotError)}`,\n level: 0,\n });\n\n toolResults.push({\n type: \"tool_result\",\n tool_use_id: item.id,\n content: [\n {\n type: \"text\",\n text: `Error: ${errorMessage}`,\n },\n ],\n });\n\n logger({\n category: \"agent\",\n message: `Added text error tool result for tool_use_id: ${item.id}`,\n level: 1,\n });\n }\n }\n }\n\n logger({\n category: \"agent\",\n message: `Prepared ${toolResults.length} tool results for next request`,\n level: 2,\n });\n\n return toolResults;\n }\n\n private convertToolUseToAction(item: ToolUseItem): AgentAction | null {\n try {\n const { name, input } = item;\n\n if (name === \"computer\") {\n // For computer actions, format according to the action type\n const action = input.action as string;\n\n if (!action) {\n console.warn(\"Missing action in tool use item:\", item);\n return null;\n }\n\n // Handle different action types specifically\n if (action === \"screenshot\") {\n return {\n type: \"screenshot\",\n ...input,\n };\n } else if (action === \"click\") {\n return {\n type: \"click\",\n x: input.x as number,\n y: input.y as number,\n button: (input.button as string) || \"left\",\n ...input,\n };\n } else if (action === \"type\") {\n return {\n type: \"type\",\n text: input.text as string,\n ...input,\n };\n } else if (action === \"keypress\" || action === \"key\") {\n return {\n type: \"keypress\",\n keys: [input.text as string],\n ...input,\n };\n } else if (action === \"double_click\" || action === \"doubleClick\") {\n return {\n type: \"doubleClick\",\n x:\n (input.x as number) ||\n (input.coordinate ? (input.coordinate as number[])[0] : 0),\n y:\n (input.y as number) ||\n (input.coordinate ? (input.coordinate as number[])[1] : 0),\n ...input,\n };\n } else if (action === \"scroll\") {\n // Convert Anthropic's coordinate, scroll_amount and scroll_direction into scroll_x and scroll_y\n const x =\n (input.x as number) ||\n (input.coordinate ? (input.coordinate as number[])[0] : 0);\n const y =\n (input.y as number) ||\n (input.coordinate ? (input.coordinate as number[])[1] : 0);\n\n // Calculate scroll_x and scroll_y based on scroll_amount and scroll_direction\n let scroll_x = 0;\n let scroll_y = 0;\n\n const scrollAmount = (input.scroll_amount as number) || 5;\n const scrollMultiplier = 100; // Pixels per unit of scroll_amount\n\n if (input.scroll_direction) {\n const direction = input.scroll_direction as string;\n if (direction === \"down\") {\n scroll_y = scrollAmount * scrollMultiplier;\n } else if (direction === \"up\") {\n scroll_y = -scrollAmount * scrollMultiplier;\n } else if (direction === \"right\") {\n scroll_x = scrollAmount * scrollMultiplier;\n } else if (direction === \"left\") {\n scroll_x = -scrollAmount * scrollMultiplier;\n }\n } else {\n // Use direct scroll_x and scroll_y if provided\n scroll_x = (input.scroll_x as number) || 0;\n scroll_y = (input.scroll_y as number) || 0;\n }\n\n return {\n type: \"scroll\",\n x: x,\n y: y,\n scroll_x: scroll_x,\n scroll_y: scroll_y,\n ...input,\n };\n } else if (action === \"move\") {\n // Handle Anthropic's coordinate format\n const coordinates = input.coordinate as number[] | undefined;\n const x = coordinates ? coordinates[0] : (input.x as number) || 0;\n const y = coordinates ? coordinates[1] : (input.y as number) || 0;\n\n return {\n type: \"move\",\n x: x,\n y: y,\n ...input,\n };\n } else if (action === \"drag\" || action === \"left_click_drag\") {\n // Make sure path is properly formatted\n const path =\n (input.path as { x: number; y: number }[]) ||\n (input.coordinate\n ? [\n {\n x: (input.start_coordinate as number[])[0],\n y: (input.start_coordinate as number[])[1],\n },\n {\n x: (input.coordinate as number[])[0],\n y: (input.coordinate as number[])[1],\n },\n ]\n : []);\n\n return {\n type: \"drag\",\n path: path,\n ...input,\n };\n } else if (action === \"wait\") {\n return {\n type: \"wait\",\n ...input,\n };\n } else if (action === \"left_click\") {\n // Convert left_click to regular click\n const coordinates = input.coordinate as number[] | undefined;\n const x = coordinates ? coordinates[0] : (input.x as number) || 0;\n const y = coordinates ? coordinates[1] : (input.y as number) || 0;\n\n return {\n type: \"click\",\n x: x,\n y: y,\n button: \"left\",\n ...input,\n };\n } else {\n // For other computer actions, use the action type directly\n return {\n type: action,\n ...input,\n };\n }\n } else if (name === \"str_replace_editor\" || name === \"bash\") {\n // For editor or bash tools\n return {\n type: name,\n params: input,\n };\n } else if (this.tools && name in this.tools) {\n return null;\n }\n\n console.warn(`Unknown tool name: ${name}`);\n return null;\n } catch (error) {\n console.error(\"Error converting tool use to action:\", error);\n return null;\n }\n }\n\n async captureScreenshot(options?: {\n base64Image?: string;\n currentUrl?: string;\n }): Promise<string> {\n // Use provided options if available\n if (options?.base64Image) {\n return `data:image/png;base64,${options.base64Image}`;\n }\n\n // Use the screenshot provider if available\n if (this.screenshotProvider) {\n try {\n const base64Image = await this.screenshotProvider();\n return `data:image/png;base64,${base64Image}`;\n } catch (error) {\n console.error(\"Error capturing screenshot:\", error);\n throw error;\n }\n }\n\n throw new AgentScreenshotProviderError(\n \"`screenshotProvider` has not been set. \" +\n \"Please call `setScreenshotProvider()` with a valid function that returns a base64-encoded image\",\n );\n }\n}\n"]}
1
+ {"version":3,"file":"AnthropicCUAClient.js","sourceRoot":"","sources":["../../../../../lib/v3/agent/AnthropicCUAClient.ts"],"names":[],"mappings":"AAaA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AK,oBAAoB,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;gBAC5D,2BAA2B;gBAC3B,OAAO;oBACL,IAAI,EAAE,IAAI;oBACV,MAAM,EAAE,KAAK;iBACd,CAAC;YACJ,CAAC;iBAAM,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;gBAC5C,OAAO,IAAI,CAAC;YACd,CAAC;YAED,OAAO,CAAC,IAAI,CAAC,sBAAsB,IAAI,EAAE,CAAC,CAAC;YAC3C,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,sCAAsC,EAAE,KAAK,CAAC,CAAC;YAC7D,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAC,OAGvB;QACC,oCAAoC;QACpC,IAAI,OAAO,EAAE,WAAW,EAAE,CAAC;YACzB,OAAO,yBAAyB,OAAO,CAAC,WAAW,EAAE,CAAC;QACxD,CAAC;QAED,2CAA2C;QAC3C,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC5B,IAAI,CAAC;gBACH,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,kBAAkB,EAAE,CAAC;gBACpD,OAAO,yBAAyB,WAAW,EAAE,CAAC;YAChD,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAC;gBACpD,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;QAED,MAAM,IAAI,4BAA4B,CACpC,yCAAyC;YACvC,iGAAiG,CACpG,CAAC;IACJ,CAAC;CACF","sourcesContent":["import {\n AgentAction,\n AgentResult,\n AgentType,\n AnthropicContentBlock,\n AnthropicMessage,\n AnthropicTextBlock,\n AnthropicToolResult,\n AgentExecutionOptions,\n ToolUseItem,\n} from \"../types/public/agent.js\";\nimport { LogLine } from \"../types/public/logs.js\";\nimport { ClientOptions, ThinkingEffort } from \"../types/public/model.js\";\nimport {\n AgentScreenshotProviderError,\n StagehandClosedError,\n} from \"../types/public/sdkErrors.js\";\nimport Anthropic from \"@anthropic-ai/sdk\";\nimport { ToolSet } from \"ai\";\nimport { AgentClient } from \"./AgentClient.js\";\nimport { compressConversationImages } from \"./utils/imageCompression.js\";\nimport { toJsonSchema } from \"../zodCompat.js\";\nimport type { StagehandZodSchema } from \"../zodCompat.js\";\nimport {\n FlowLogger,\n extractLlmCuaPromptSummary,\n extractLlmCuaResponseSummary,\n} from \"../flowlogger/FlowLogger.js\";\nimport { v7 as uuidv7 } from \"uuid\";\n\nexport type ResponseInputItem = AnthropicMessage | AnthropicToolResult;\n\n/**\n * Client for Anthropic's Computer Use API\n * This implementation uses the official Anthropic Messages API for Computer Use\n */\nexport class AnthropicCUAClient extends AgentClient {\n private apiKey: string;\n private baseURL?: string;\n private client: Anthropic;\n public lastMessageId?: string;\n private currentViewport = { width: 1288, height: 711 };\n private currentUrl?: string;\n private screenshotProvider?: () => Promise<string>;\n private actionHandler?: (action: AgentAction) => Promise<void>;\n private thinkingBudget: number | null = null;\n private thinkingEffort: ThinkingEffort | null = null;\n private userTemperature: number | undefined;\n private tools?: ToolSet;\n\n constructor(\n type: AgentType,\n modelName: string,\n userProvidedInstructions?: string,\n clientOptions?: ClientOptions,\n tools?: ToolSet,\n ) {\n super(type, modelName, userProvidedInstructions);\n\n // Process client options\n this.apiKey =\n (clientOptions?.apiKey as string) || process.env.ANTHROPIC_API_KEY || \"\";\n this.baseURL = (clientOptions?.baseURL as string) || undefined;\n\n // Get thinking budget if specified (deprecated for 4.6 models)\n if (\n clientOptions?.thinkingBudget &&\n typeof clientOptions.thinkingBudget === \"number\"\n ) {\n this.thinkingBudget = clientOptions.thinkingBudget;\n }\n\n // Get thinking effort for adaptive thinking (Claude 4.6+ models)\n if (clientOptions?.thinkingEffort) {\n this.thinkingEffort = clientOptions.thinkingEffort;\n }\n\n // Track user-specified temperature so we can warn if adaptive thinking overrides it\n this.userTemperature = clientOptions?.temperature;\n\n // Store client options for reference\n this.clientOptions = {\n apiKey: this.apiKey,\n };\n\n if (this.baseURL) {\n this.clientOptions.baseURL = this.baseURL;\n }\n\n // Initialize the Anthropic client\n this.client = new Anthropic(this.clientOptions);\n\n this.tools = tools;\n }\n\n setViewport(width: number, height: number): void {\n this.currentViewport = { width, height };\n }\n\n setCurrentUrl(url: string): void {\n this.currentUrl = url;\n }\n\n setScreenshotProvider(provider: () => Promise<string>): void {\n this.screenshotProvider = provider;\n }\n\n setActionHandler(handler: (action: AgentAction) => Promise<void>): void {\n this.actionHandler = handler;\n }\n\n setTools(tools: ToolSet): void {\n this.tools = tools;\n }\n\n /**\n * Execute a task with the Anthropic CUA\n * This is the main entry point for the agent\n * @implements AgentClient.execute\n */\n async execute(executionOptions: AgentExecutionOptions): Promise<AgentResult> {\n const { options, logger } = executionOptions;\n const { instruction } = options;\n const maxSteps = options.maxSteps || 10;\n\n let currentStep = 0;\n let completed = false;\n const actions: AgentAction[] = [];\n const messageList: string[] = [];\n let finalMessage = \"\";\n\n // Start with the initial instruction\n let inputItems: ResponseInputItem[] =\n this.createInitialInputItems(instruction);\n\n logger({\n category: \"agent\",\n message: `Starting Anthropic agent execution with instruction: ${instruction}`,\n level: 1,\n });\n\n let totalInputTokens = 0;\n let totalOutputTokens = 0;\n let totalInferenceTime = 0;\n\n try {\n // Execute steps until completion or max steps reached\n while (!completed && currentStep < maxSteps) {\n await this.preStepHook?.();\n\n logger({\n category: \"agent\",\n message: `Executing step ${currentStep + 1}/${maxSteps}`,\n level: 1,\n });\n\n const result = await this.executeStep(inputItems, logger);\n totalInputTokens += result.usage.input_tokens;\n totalOutputTokens += result.usage.output_tokens;\n totalInferenceTime += result.usage.inference_time_ms;\n\n // Add actions to the list\n if (result.actions.length > 0) {\n logger({\n category: \"agent\",\n message: `Step ${currentStep + 1} performed ${result.actions.length} actions`,\n level: 2,\n });\n actions.push(...result.actions);\n }\n\n // Update completion status\n completed = result.completed;\n\n // Update the input items for the next step if we're continuing\n if (!completed) {\n inputItems = result.nextInputItems;\n }\n\n // Record any message for this step\n if (result.message) {\n messageList.push(result.message);\n finalMessage = result.message;\n }\n\n // Increment step counter\n currentStep++;\n }\n\n logger({\n category: \"agent\",\n message: `Anthropic agent execution completed: ${completed}, with ${actions.length} total actions performed`,\n level: 1,\n });\n\n // Return the final result\n return {\n success: completed,\n actions,\n message: finalMessage,\n completed,\n usage: {\n input_tokens: totalInputTokens,\n output_tokens: totalOutputTokens,\n inference_time_ms: totalInferenceTime,\n },\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n logger({\n category: \"agent\",\n message: `Error executing agent task: ${errorMessage}`,\n level: 0,\n });\n\n return {\n success: false,\n actions,\n message: `Failed to execute task: ${errorMessage}`,\n completed: false,\n usage: {\n input_tokens: totalInputTokens,\n output_tokens: totalOutputTokens,\n inference_time_ms: totalInferenceTime,\n },\n };\n }\n }\n\n async executeStep(\n inputItems: ResponseInputItem[],\n logger: (message: LogLine) => void,\n ): Promise<{\n actions: AgentAction[];\n message: string;\n completed: boolean;\n nextInputItems: ResponseInputItem[];\n usage: {\n input_tokens: number;\n output_tokens: number;\n inference_time_ms: number;\n };\n }> {\n try {\n // Get response from the model\n const result = await this.getAction(inputItems, logger);\n const content = result.content;\n const usage = {\n input_tokens: result.usage.input_tokens,\n output_tokens: result.usage.output_tokens,\n inference_time_ms: result.usage.inference_time_ms,\n };\n\n logger({\n category: \"agent\",\n message: `Received response with ${content.length} content blocks`,\n level: 2,\n });\n\n // Extract actions from the content\n const stepActions: AgentAction[] = [];\n const toolUseItems: ToolUseItem[] = [];\n let message = \"\";\n\n // Process content blocks to find tool use items and text content\n for (const block of content) {\n logger({\n category: \"agent\",\n message: `Processing block type: ${block.type}, id: ${block.id || \"unknown\"}`,\n level: 2,\n });\n\n if (block.type === \"tool_use\") {\n // Direct handling of tool_use type\n logger({\n category: \"agent\",\n message: `Found tool_use block: ${JSON.stringify(block)}`,\n level: 2,\n });\n\n // Cast to ToolUseItem and add to list\n const toolUseItem = block as ToolUseItem;\n toolUseItems.push(toolUseItem);\n\n logger({\n category: \"agent\",\n message: `Added tool_use item: ${toolUseItem.name}, action: ${JSON.stringify(toolUseItem.input)}`,\n level: 2,\n });\n\n // Convert tool use to action and add to actions list\n const action = this.convertToolUseToAction(toolUseItem);\n if (action) {\n logger({\n category: \"agent\",\n message: `Created action from tool_use: ${toolUseItem.name}, action: ${action.type}`,\n level: 2,\n });\n stepActions.push(action);\n } else if (this.tools && toolUseItem.name in this.tools) {\n stepActions.push({\n type: \"custom_tool\",\n tool: toolUseItem.name,\n input: toolUseItem.input,\n } as AgentAction);\n }\n } else if (block.type === \"text\") {\n // Safe to cast here since we've verified it's a text block\n const textBlock = block as unknown as AnthropicTextBlock;\n message += textBlock.text + \"\\n\";\n\n logger({\n category: \"agent\",\n message: `Found text block: ${textBlock.text}`,\n level: 2,\n });\n } else {\n logger({\n category: \"agent\",\n message: `Found unknown block type: ${block.type}`,\n level: 2,\n });\n }\n }\n\n // Execute actions if an action handler is provided\n if (this.actionHandler && stepActions.length > 0) {\n for (const action of stepActions) {\n try {\n logger({\n category: \"agent\",\n message: `Executing action: ${action.type}`,\n level: 1,\n });\n await this.actionHandler(action);\n } catch (error) {\n if (error instanceof StagehandClosedError) {\n throw error;\n }\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n logger({\n category: \"agent\",\n message: `Error executing action ${action.type}: ${errorMessage}`,\n level: 0,\n });\n }\n }\n }\n\n // Create the assistant response message with all content blocks\n const assistantMessage: AnthropicMessage = {\n role: \"assistant\",\n content: content as unknown as AnthropicContentBlock[],\n };\n\n // Keep track of the conversation history by preserving all previous messages\n // and adding new messages at the end\n const nextInputItems: ResponseInputItem[] = [...inputItems];\n\n // Add the assistant message with tool_use blocks to the history\n compressConversationImages(nextInputItems);\n\n nextInputItems.push(assistantMessage);\n\n // Generate tool results and add them as a user message\n if (toolUseItems.length > 0) {\n const toolResults = await this.takeAction(toolUseItems, logger);\n\n if (toolResults.length > 0) {\n // Tool results are AnthropicToolResult[] which are compatible with AnthropicContentBlock[]\n const userToolResultsMessage: AnthropicMessage = {\n role: \"user\",\n content: toolResults as unknown as AnthropicContentBlock[],\n };\n nextInputItems.push(userToolResultsMessage);\n }\n }\n\n // The step is completed only if there were no tool_use items\n const completed = toolUseItems.length === 0;\n\n logger({\n category: \"agent\",\n message: `Step processed ${toolUseItems.length} tool use items, completed: ${completed}`,\n level: 2,\n });\n\n return {\n actions: stepActions,\n message: message.trim(),\n completed,\n nextInputItems,\n usage: usage,\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n logger({\n category: \"agent\",\n message: `Error executing step: ${errorMessage}`,\n level: 0,\n });\n\n throw error;\n }\n }\n\n private createInitialInputItems(instruction: string): AnthropicMessage[] {\n // For the initial request, we use a simple array with the user's instruction\n return [\n {\n role: \"system\",\n content: this.userProvidedInstructions,\n },\n {\n role: \"user\",\n content: instruction,\n },\n ];\n }\n\n async getAction(\n inputItems: ResponseInputItem[],\n logger?: (message: LogLine) => void,\n ): Promise<{\n content: AnthropicContentBlock[];\n id: string;\n usage: Record<string, number>;\n }> {\n try {\n // For the API request, we use the inputItems directly\n // These should already be properly formatted as a sequence of user/assistant messages\n const messages: AnthropicMessage[] = [];\n\n for (const item of inputItems) {\n if (\"role\" in item) {\n // Skip system messages as Anthropic requires system as a top-level parameter\n if (item.role !== \"system\") {\n messages.push(item);\n }\n }\n // Note: We don't need special handling for tool_result items here anymore\n // as they should already be properly wrapped in user messages\n }\n\n // Claude 4.6+ models require the newer computer_20251124 tool version\n // and support adaptive thinking instead of budget_tokens\n const modelBase = this.modelName.includes(\"/\")\n ? this.modelName.split(\"/\")[1]\n : this.modelName;\n\n // Check if this is a Claude 4.6+ model that supports adaptive thinking\n const isAdaptiveThinkingModel = [\n \"claude-opus-4-6\",\n \"claude-sonnet-4-6\",\n ].includes(modelBase);\n\n // claude-opus-4-5-20251101 uses the newer computer tool version but does\n // NOT support adaptive thinking — it still requires budget_tokens.\n const shouldUseNewToolVersion =\n isAdaptiveThinkingModel || modelBase === \"claude-opus-4-5-20251101\";\n\n // Configure thinking capability based on model version\n // - For 4.6 models: Use adaptive thinking with effort (recommended, defaults to \"medium\")\n // - For older models: Use enabled thinking with budget_tokens (deprecated)\n let thinking:\n | { type: \"adaptive\" }\n | { type: \"enabled\"; budget_tokens: number }\n | undefined;\n let outputConfig: { effort: Exclude<ThinkingEffort, \"none\"> } | undefined;\n let useAdaptiveThinking = false;\n\n if (isAdaptiveThinkingModel) {\n if (this.thinkingBudget) {\n logger?.({\n category: \"agent\",\n message: `thinkingBudget is ignored for ${this.modelName}; use thinkingEffort instead`,\n level: 2,\n });\n }\n\n if (this.thinkingEffort !== \"none\") {\n // Claude 4.6+ models use adaptive thinking with output_config.effort\n // Default to \"medium\" effort if not explicitly specified\n // See: https://platform.claude.com/docs/en/build-with-claude/adaptive-thinking\n thinking = { type: \"adaptive\" };\n outputConfig = { effort: this.thinkingEffort || \"medium\" };\n useAdaptiveThinking = true;\n }\n } else if (this.thinkingBudget) {\n // Older models use enabled thinking with budget_tokens (deprecated for 4.6)\n thinking = { type: \"enabled\", budget_tokens: this.thinkingBudget };\n }\n\n const computerToolType = shouldUseNewToolVersion\n ? \"computer_20251124\"\n : \"computer_20250124\";\n const betaFlag = shouldUseNewToolVersion\n ? \"computer-use-2025-11-24\"\n : \"computer-use-2025-01-24\";\n\n // Create the request parameters\n const requestParams: Record<string, unknown> = {\n model: this.modelName,\n max_tokens: 4096,\n messages: messages,\n tools: [\n {\n type: computerToolType,\n name: \"computer\",\n display_width_px: this.currentViewport.width,\n display_height_px: this.currentViewport.height,\n display_number: 1,\n },\n ],\n betas: [betaFlag],\n };\n\n // Add custom tools if available\n if (this.tools && Object.keys(this.tools).length > 0) {\n const customTools = Object.entries(this.tools).map(([name, tool]) => {\n const schema = tool.inputSchema as StagehandZodSchema;\n\n // Convert Zod schema to proper JSON schema format for Anthropic\n const jsonSchema = toJsonSchema(schema) as {\n properties?: Record<string, unknown>;\n required?: string[];\n };\n\n const inputSchema = {\n type: \"object\",\n properties: jsonSchema.properties || {},\n required: jsonSchema.required || [],\n };\n\n return {\n name,\n description: tool.description,\n input_schema: inputSchema,\n };\n });\n\n requestParams.tools = [\n ...(requestParams.tools as Record<string, unknown>[]),\n ...customTools,\n ];\n }\n\n // Add system parameter if provided\n if (this.userProvidedInstructions) {\n requestParams.system = this.userProvidedInstructions;\n }\n\n // Add thinking parameter if available\n if (thinking) {\n requestParams.thinking = thinking;\n }\n\n // Add output_config for adaptive thinking (Claude 4.6+ models)\n if (outputConfig) {\n requestParams.output_config = outputConfig;\n }\n\n // Adaptive thinking requires temperature to be set to 1\n // See: https://platform.claude.com/docs/en/build-with-claude/adaptive-thinking\n if (useAdaptiveThinking) {\n if (this.userTemperature !== undefined && this.userTemperature !== 1) {\n logger?.({\n category: \"agent\",\n message: `Adaptive thinking requires temperature=1; overriding user-specified temperature=${this.userTemperature}`,\n level: 2,\n });\n }\n requestParams.temperature = 1;\n }\n\n // Log LLM request\n const llmRequestId = uuidv7();\n FlowLogger.logLlmRequest({\n requestId: llmRequestId,\n model: this.modelName,\n prompt: extractLlmCuaPromptSummary(messages),\n });\n\n const startTime = Date.now();\n // Create the message using the Anthropic Messages API\n // @ts-expect-error - The Anthropic SDK types are stricter than what we need\n const response = await this.client.beta.messages.create(requestParams);\n const endTime = Date.now();\n const elapsedMs = endTime - startTime;\n const usage = {\n input_tokens: response.usage.input_tokens,\n output_tokens: response.usage.output_tokens,\n inference_time_ms: elapsedMs,\n };\n\n // Log LLM response\n FlowLogger.logLlmResponse({\n requestId: llmRequestId,\n model: this.modelName,\n output: extractLlmCuaResponseSummary(response.content),\n inputTokens: response.usage.input_tokens,\n outputTokens: response.usage.output_tokens,\n });\n\n // Store the message ID for future use\n this.lastMessageId = response.id;\n\n // Return the content and message ID\n return {\n // Cast the response content to our internal type\n content: response.content as unknown as AnthropicContentBlock[],\n id: response.id,\n usage,\n };\n } catch (error) {\n console.error(\"Error getting action from Anthropic:\", error);\n throw error;\n }\n }\n\n async takeAction(\n toolUseItems: ToolUseItem[],\n logger: (message: LogLine) => void,\n ): Promise<AnthropicToolResult[]> {\n const toolResults: AnthropicToolResult[] = [];\n\n logger({\n category: \"agent\",\n message: `Taking action on ${toolUseItems.length} tool use items`,\n level: 2,\n });\n\n // Process each tool use item\n for (const item of toolUseItems) {\n try {\n logger({\n category: \"agent\",\n message: `Processing tool use: ${item.name}, id: ${item.id}, action: ${JSON.stringify(item.input)}`,\n level: 2,\n });\n\n // TODO: Normalize and migrate to agentHandler\n\n // For computer tool, capture screenshot and return image\n if (item.name === \"computer\") {\n // Get action type\n const action = item.input.action as string;\n logger({\n category: \"agent\",\n message: `Computer action type: ${action}`,\n level: 2,\n });\n\n // Capture a screenshot for the response\n const screenshot = await this.captureScreenshot();\n logger({\n category: \"agent\",\n message: `Screenshot captured, length: ${screenshot.length}`,\n level: 2,\n });\n\n // Create proper image content block for Anthropic\n const imageContent = [\n {\n type: \"image\",\n source: {\n type: \"base64\",\n media_type: \"image/png\",\n data: screenshot.replace(/^data:image\\/png;base64,/, \"\"),\n },\n },\n ];\n\n // Add current URL if available\n if (this.currentUrl) {\n toolResults.push({\n type: \"tool_result\",\n tool_use_id: item.id,\n content: [\n ...imageContent,\n {\n type: \"text\",\n text: `Current URL: ${this.currentUrl}`,\n },\n ],\n });\n } else {\n toolResults.push({\n type: \"tool_result\",\n tool_use_id: item.id,\n content: imageContent,\n });\n }\n\n logger({\n category: \"agent\",\n message: `Added computer tool result for tool_use_id: ${item.id}`,\n level: 2,\n });\n } else {\n // Handle custom tools\n let toolResult = \"Tool executed successfully\";\n if (this.tools && item.name in this.tools) {\n try {\n const tool = this.tools[item.name];\n\n logger({\n category: \"agent\",\n message: `Executing tool call: ${item.name} with args: ${JSON.stringify(item.input)}`,\n level: 1,\n });\n\n const result = await tool.execute(item.input, {\n toolCallId: item.id,\n messages: [],\n });\n toolResult = JSON.stringify(result);\n\n logger({\n category: \"agent\",\n message: `Tool ${item.name} completed successfully. Result: ${toolResult}`,\n level: 1,\n });\n } catch (toolError) {\n const errorMessage =\n toolError instanceof Error\n ? toolError.message\n : String(toolError);\n toolResult = `Error executing tool: ${errorMessage}`;\n\n logger({\n category: \"agent\",\n message: `Error executing tool ${item.name}: ${errorMessage}`,\n level: 0,\n });\n }\n }\n\n toolResults.push({\n type: \"tool_result\",\n tool_use_id: item.id,\n content: [\n {\n type: \"text\",\n text: toolResult,\n },\n ],\n });\n\n logger({\n category: \"agent\",\n message: `Added custom tool result for tool ${item.name}, tool_use_id: ${item.id}`,\n level: 2,\n });\n }\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n\n logger({\n category: \"agent\",\n message: `Error executing tool use: ${errorMessage}`,\n level: 0,\n });\n\n try {\n // For computer tool, try to capture a screenshot even on error\n if (item.name === \"computer\") {\n const screenshot = await this.captureScreenshot();\n\n toolResults.push({\n type: \"tool_result\",\n tool_use_id: item.id,\n content: [\n {\n type: \"image\",\n source: {\n type: \"base64\",\n media_type: \"image/png\",\n data: screenshot.replace(/^data:image\\/png;base64,/, \"\"),\n },\n },\n {\n type: \"text\",\n text: `Error: ${errorMessage}`,\n },\n ],\n });\n\n logger({\n category: \"agent\",\n message: `Added error tool result with screenshot for tool_use_id: ${item.id}`,\n level: 1,\n });\n } else {\n // For other tools, return an error message as a text content block\n toolResults.push({\n type: \"tool_result\",\n tool_use_id: item.id,\n content: [\n {\n type: \"text\",\n text: `Error: ${errorMessage}`,\n },\n ],\n });\n\n logger({\n category: \"agent\",\n message: `Added error tool result for tool_use_id: ${item.id}`,\n level: 1,\n });\n }\n } catch (screenshotError) {\n // If we can't capture a screenshot, just send the error\n logger({\n category: \"agent\",\n message: `Error capturing screenshot: ${String(screenshotError)}`,\n level: 0,\n });\n\n toolResults.push({\n type: \"tool_result\",\n tool_use_id: item.id,\n content: [\n {\n type: \"text\",\n text: `Error: ${errorMessage}`,\n },\n ],\n });\n\n logger({\n category: \"agent\",\n message: `Added text error tool result for tool_use_id: ${item.id}`,\n level: 1,\n });\n }\n }\n }\n\n logger({\n category: \"agent\",\n message: `Prepared ${toolResults.length} tool results for next request`,\n level: 2,\n });\n\n return toolResults;\n }\n\n private convertToolUseToAction(item: ToolUseItem): AgentAction | null {\n try {\n const { name, input } = item;\n\n if (name === \"computer\") {\n // For computer actions, format according to the action type\n const action = input.action as string;\n\n if (!action) {\n console.warn(\"Missing action in tool use item:\", item);\n return null;\n }\n\n // Handle different action types specifically\n if (action === \"screenshot\") {\n return {\n type: \"screenshot\",\n ...input,\n };\n } else if (action === \"click\") {\n return {\n type: \"click\",\n x: input.x as number,\n y: input.y as number,\n button: (input.button as string) || \"left\",\n ...input,\n };\n } else if (action === \"type\") {\n return {\n type: \"type\",\n text: input.text as string,\n ...input,\n };\n } else if (action === \"keypress\" || action === \"key\") {\n return {\n type: \"keypress\",\n keys: [input.text as string],\n ...input,\n };\n } else if (action === \"double_click\" || action === \"doubleClick\") {\n return {\n type: \"doubleClick\",\n x:\n (input.x as number) ||\n (input.coordinate ? (input.coordinate as number[])[0] : 0),\n y:\n (input.y as number) ||\n (input.coordinate ? (input.coordinate as number[])[1] : 0),\n ...input,\n };\n } else if (action === \"scroll\") {\n // Convert Anthropic's coordinate, scroll_amount and scroll_direction into scroll_x and scroll_y\n const x =\n (input.x as number) ||\n (input.coordinate ? (input.coordinate as number[])[0] : 0);\n const y =\n (input.y as number) ||\n (input.coordinate ? (input.coordinate as number[])[1] : 0);\n\n // Calculate scroll_x and scroll_y based on scroll_amount and scroll_direction\n let scroll_x = 0;\n let scroll_y = 0;\n\n const scrollAmount = (input.scroll_amount as number) || 5;\n const scrollMultiplier = 100; // Pixels per unit of scroll_amount\n\n if (input.scroll_direction) {\n const direction = input.scroll_direction as string;\n if (direction === \"down\") {\n scroll_y = scrollAmount * scrollMultiplier;\n } else if (direction === \"up\") {\n scroll_y = -scrollAmount * scrollMultiplier;\n } else if (direction === \"right\") {\n scroll_x = scrollAmount * scrollMultiplier;\n } else if (direction === \"left\") {\n scroll_x = -scrollAmount * scrollMultiplier;\n }\n } else {\n // Use direct scroll_x and scroll_y if provided\n scroll_x = (input.scroll_x as number) || 0;\n scroll_y = (input.scroll_y as number) || 0;\n }\n\n return {\n type: \"scroll\",\n x: x,\n y: y,\n scroll_x: scroll_x,\n scroll_y: scroll_y,\n ...input,\n };\n } else if (action === \"move\") {\n // Handle Anthropic's coordinate format\n const coordinates = input.coordinate as number[] | undefined;\n const x = coordinates ? coordinates[0] : (input.x as number) || 0;\n const y = coordinates ? coordinates[1] : (input.y as number) || 0;\n\n return {\n type: \"move\",\n x: x,\n y: y,\n ...input,\n };\n } else if (action === \"drag\" || action === \"left_click_drag\") {\n // Make sure path is properly formatted\n const path =\n (input.path as { x: number; y: number }[]) ||\n (input.coordinate\n ? [\n {\n x: (input.start_coordinate as number[])[0],\n y: (input.start_coordinate as number[])[1],\n },\n {\n x: (input.coordinate as number[])[0],\n y: (input.coordinate as number[])[1],\n },\n ]\n : []);\n\n return {\n type: \"drag\",\n path: path,\n ...input,\n };\n } else if (action === \"wait\") {\n return {\n type: \"wait\",\n ...input,\n };\n } else if (action === \"left_click\") {\n // Convert left_click to regular click\n const coordinates = input.coordinate as number[] | undefined;\n const x = coordinates ? coordinates[0] : (input.x as number) || 0;\n const y = coordinates ? coordinates[1] : (input.y as number) || 0;\n\n return {\n type: \"click\",\n x: x,\n y: y,\n button: \"left\",\n ...input,\n };\n } else {\n // For other computer actions, use the action type directly\n return {\n type: action,\n ...input,\n };\n }\n } else if (name === \"str_replace_editor\" || name === \"bash\") {\n // For editor or bash tools\n return {\n type: name,\n params: input,\n };\n } else if (this.tools && name in this.tools) {\n return null;\n }\n\n console.warn(`Unknown tool name: ${name}`);\n return null;\n } catch (error) {\n console.error(\"Error converting tool use to action:\", error);\n return null;\n }\n }\n\n async captureScreenshot(options?: {\n base64Image?: string;\n currentUrl?: string;\n }): Promise<string> {\n // Use provided options if available\n if (options?.base64Image) {\n return `data:image/png;base64,${options.base64Image}`;\n }\n\n // Use the screenshot provider if available\n if (this.screenshotProvider) {\n try {\n const base64Image = await this.screenshotProvider();\n return `data:image/png;base64,${base64Image}`;\n } catch (error) {\n console.error(\"Error capturing screenshot:\", error);\n throw error;\n }\n }\n\n throw new AgentScreenshotProviderError(\n \"`screenshotProvider` has not been set. \" +\n \"Please call `setScreenshotProvider()` with a valid function that returns a base64-encoded image\",\n );\n }\n}\n"]}
@@ -175,6 +175,7 @@ export class GoogleCUAClient extends AgentClient {
175
175
  try {
176
176
  // Execute steps until completion or max steps reached
177
177
  while (!completed && currentStep < maxSteps) {
178
+ await this.preStepHook?.();
178
179
  logger({
179
180
  category: "agent",
180
181
  message: `Executing step ${currentStep + 1}/${maxSteps}`,