@browserbasehq/orca 3.5.1-preview.0 → 3.7.0-preview.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (242) hide show
  1. package/README.md +0 -12
  2. package/dist/cjs/lib/utils.d.ts +6 -0
  3. package/dist/cjs/lib/utils.js +11 -0
  4. package/dist/cjs/lib/utils.js.map +1 -1
  5. package/dist/cjs/lib/v3/agent/AgentClient.d.ts +2 -2
  6. package/dist/cjs/lib/v3/agent/AgentClient.js.map +1 -1
  7. package/dist/cjs/lib/v3/agent/AgentProvider.js +4 -3
  8. package/dist/cjs/lib/v3/agent/AgentProvider.js.map +1 -1
  9. package/dist/cjs/lib/v3/agent/AnthropicCUAClient.d.ts +4 -3
  10. package/dist/cjs/lib/v3/agent/AnthropicCUAClient.js +21 -18
  11. package/dist/cjs/lib/v3/agent/AnthropicCUAClient.js.map +1 -1
  12. package/dist/cjs/lib/v3/agent/GoogleCUAClient.d.ts +12 -3
  13. package/dist/cjs/lib/v3/agent/GoogleCUAClient.js +217 -36
  14. package/dist/cjs/lib/v3/agent/GoogleCUAClient.js.map +1 -1
  15. package/dist/cjs/lib/v3/agent/MicrosoftCUAClient.d.ts +2 -2
  16. package/dist/cjs/lib/v3/agent/MicrosoftCUAClient.js +2 -2
  17. package/dist/cjs/lib/v3/agent/MicrosoftCUAClient.js.map +1 -1
  18. package/dist/cjs/lib/v3/agent/OpenAICUAClient.d.ts +6 -3
  19. package/dist/cjs/lib/v3/agent/OpenAICUAClient.js +13 -7
  20. package/dist/cjs/lib/v3/agent/OpenAICUAClient.js.map +1 -1
  21. package/dist/cjs/lib/v3/agent/utils/handleDoneToolCall.d.ts +1 -0
  22. package/dist/cjs/lib/v3/agent/utils/handleDoneToolCall.js +50 -3
  23. package/dist/cjs/lib/v3/agent/utils/handleDoneToolCall.js.map +1 -1
  24. package/dist/cjs/lib/v3/cache/ActCache.js +1 -1
  25. package/dist/cjs/lib/v3/cache/ActCache.js.map +1 -1
  26. package/dist/cjs/lib/v3/cache/utils.d.ts +7 -0
  27. package/dist/cjs/lib/v3/cache/utils.js +19 -0
  28. package/dist/cjs/lib/v3/cache/utils.js.map +1 -1
  29. package/dist/cjs/lib/v3/handlers/v3AgentHandler.d.ts +2 -1
  30. package/dist/cjs/lib/v3/handlers/v3AgentHandler.js +55 -16
  31. package/dist/cjs/lib/v3/handlers/v3AgentHandler.js.map +1 -1
  32. package/dist/cjs/lib/v3/handlers/v3CuaAgentHandler.js +32 -18
  33. package/dist/cjs/lib/v3/handlers/v3CuaAgentHandler.js.map +1 -1
  34. package/dist/cjs/lib/v3/index.d.ts +3 -2
  35. package/dist/cjs/lib/v3/index.js.map +1 -1
  36. package/dist/cjs/lib/v3/launch/local.js +1 -0
  37. package/dist/cjs/lib/v3/launch/local.js.map +1 -1
  38. package/dist/cjs/lib/v3/llm/LLMProvider.d.ts +2 -2
  39. package/dist/cjs/lib/v3/llm/LLMProvider.js +1 -0
  40. package/dist/cjs/lib/v3/llm/LLMProvider.js.map +1 -1
  41. package/dist/cjs/lib/v3/llm/aisdk.js +4 -0
  42. package/dist/cjs/lib/v3/llm/aisdk.js.map +1 -1
  43. package/dist/cjs/lib/v3/llm/anthropicOptions.d.ts +57 -0
  44. package/dist/cjs/lib/v3/llm/anthropicOptions.js +115 -0
  45. package/dist/cjs/lib/v3/llm/anthropicOptions.js.map +1 -0
  46. package/dist/cjs/lib/v3/types/public/agent.d.ts +10 -1
  47. package/dist/cjs/lib/v3/types/public/agent.js +2 -0
  48. package/dist/cjs/lib/v3/types/public/agent.js.map +1 -1
  49. package/dist/cjs/lib/v3/types/public/context.d.ts +7 -0
  50. package/dist/cjs/lib/v3/types/public/context.js.map +1 -1
  51. package/dist/cjs/lib/v3/types/public/model.d.ts +3 -2
  52. package/dist/cjs/lib/v3/types/public/model.js.map +1 -1
  53. package/dist/cjs/lib/v3/types/public/sdkErrors.d.ts +4 -0
  54. package/dist/cjs/lib/v3/types/public/sdkErrors.js +9 -1
  55. package/dist/cjs/lib/v3/types/public/sdkErrors.js.map +1 -1
  56. package/dist/cjs/lib/v3/understudy/cdp.d.ts +2 -0
  57. package/dist/cjs/lib/v3/understudy/cdp.js +26 -12
  58. package/dist/cjs/lib/v3/understudy/cdp.js.map +1 -1
  59. package/dist/cjs/lib/v3/understudy/context.d.ts +13 -1
  60. package/dist/cjs/lib/v3/understudy/context.js +284 -1
  61. package/dist/cjs/lib/v3/understudy/context.js.map +1 -1
  62. package/dist/cjs/lib/v3/understudy/domainPolicy.d.ts +25 -0
  63. package/dist/cjs/lib/v3/understudy/domainPolicy.js +162 -0
  64. package/dist/cjs/lib/v3/understudy/domainPolicy.js.map +1 -0
  65. package/dist/cjs/lib/v3/understudy/page.js +1 -1
  66. package/dist/cjs/lib/v3/understudy/page.js.map +1 -1
  67. package/dist/cjs/lib/v3/v3.js +8 -2
  68. package/dist/cjs/lib/v3/v3.js.map +1 -1
  69. package/dist/cjs/lib/v3/verifier/errorTaxonomy.d.ts +35 -0
  70. package/dist/cjs/lib/v3/verifier/errorTaxonomy.js +291 -0
  71. package/dist/cjs/lib/v3/verifier/errorTaxonomy.js.map +1 -0
  72. package/dist/cjs/lib/v3/verifier/evidence.d.ts +44 -0
  73. package/dist/cjs/lib/v3/verifier/evidence.js +432 -0
  74. package/dist/cjs/lib/v3/verifier/evidence.js.map +1 -0
  75. package/dist/cjs/lib/v3/verifier/index.d.ts +1 -1
  76. package/dist/cjs/lib/v3/verifier/index.js.map +1 -1
  77. package/dist/cjs/lib/v3/verifier/prompts/batchedRelevance.d.ts +21 -0
  78. package/dist/cjs/lib/v3/verifier/prompts/batchedRelevance.js +71 -0
  79. package/dist/cjs/lib/v3/verifier/prompts/batchedRelevance.js.map +1 -0
  80. package/dist/cjs/lib/v3/verifier/prompts/firstPointOfFailure.d.ts +3 -0
  81. package/dist/cjs/lib/v3/verifier/prompts/firstPointOfFailure.js +166 -0
  82. package/dist/cjs/lib/v3/verifier/prompts/firstPointOfFailure.js.map +1 -0
  83. package/dist/cjs/lib/v3/verifier/prompts/fusedJudgment.d.ts +35 -0
  84. package/dist/cjs/lib/v3/verifier/prompts/fusedJudgment.js +158 -0
  85. package/dist/cjs/lib/v3/verifier/prompts/fusedJudgment.js.map +1 -0
  86. package/dist/cjs/lib/v3/verifier/prompts/fusedOutcome.d.ts +26 -0
  87. package/dist/cjs/lib/v3/verifier/prompts/fusedOutcome.js +137 -0
  88. package/dist/cjs/lib/v3/verifier/prompts/fusedOutcome.js.map +1 -0
  89. package/dist/cjs/lib/v3/verifier/prompts/index.d.ts +8 -0
  90. package/dist/cjs/lib/v3/verifier/prompts/index.js +22 -0
  91. package/dist/cjs/lib/v3/verifier/prompts/index.js.map +1 -0
  92. package/dist/cjs/lib/v3/verifier/prompts/perCriterionScore.d.ts +23 -0
  93. package/dist/cjs/lib/v3/verifier/prompts/perCriterionScore.js +77 -0
  94. package/dist/cjs/lib/v3/verifier/prompts/perCriterionScore.js.map +1 -0
  95. package/dist/cjs/lib/v3/verifier/prompts/render.d.ts +23 -0
  96. package/dist/cjs/lib/v3/verifier/prompts/render.js +45 -0
  97. package/dist/cjs/lib/v3/verifier/prompts/render.js.map +1 -0
  98. package/dist/cjs/lib/v3/verifier/prompts/rubricGeneration.d.ts +16 -0
  99. package/dist/cjs/lib/v3/verifier/prompts/rubricGeneration.js +321 -0
  100. package/dist/cjs/lib/v3/verifier/prompts/rubricGeneration.js.map +1 -0
  101. package/dist/cjs/lib/v3/verifier/prompts/taskValidity.d.ts +1 -0
  102. package/dist/cjs/lib/v3/verifier/prompts/taskValidity.js +116 -0
  103. package/dist/cjs/lib/v3/verifier/prompts/taskValidity.js.map +1 -0
  104. package/dist/cjs/lib/v3/verifier/rubricVerifier.d.ts +91 -0
  105. package/dist/cjs/lib/v3/verifier/rubricVerifier.js +1645 -0
  106. package/dist/cjs/lib/v3/verifier/rubricVerifier.js.map +1 -0
  107. package/dist/cjs/lib/v3/verifier/trajectory.d.ts +3 -3
  108. package/dist/cjs/lib/v3/verifier/trajectory.js +26 -26
  109. package/dist/cjs/lib/v3/verifier/trajectory.js.map +1 -1
  110. package/dist/cjs/lib/v3/verifier/types.d.ts +163 -15
  111. package/dist/cjs/lib/v3/verifier/types.js +0 -7
  112. package/dist/cjs/lib/v3/verifier/types.js.map +1 -1
  113. package/dist/cjs/lib/v3Evaluator.d.ts +5 -0
  114. package/dist/cjs/lib/v3Evaluator.js +47 -7
  115. package/dist/cjs/lib/v3Evaluator.js.map +1 -1
  116. package/dist/cjs/lib/version.d.ts +1 -1
  117. package/dist/cjs/lib/version.js +1 -1
  118. package/dist/cjs/lib/version.js.map +1 -1
  119. package/dist/esm/lib/utils.d.ts +6 -0
  120. package/dist/esm/lib/utils.js +10 -0
  121. package/dist/esm/lib/utils.js.map +1 -1
  122. package/dist/esm/lib/v3/agent/AgentClient.d.ts +2 -2
  123. package/dist/esm/lib/v3/agent/AgentClient.js.map +1 -1
  124. package/dist/esm/lib/v3/agent/AgentProvider.js +4 -3
  125. package/dist/esm/lib/v3/agent/AgentProvider.js.map +1 -1
  126. package/dist/esm/lib/v3/agent/AnthropicCUAClient.d.ts +4 -3
  127. package/dist/esm/lib/v3/agent/AnthropicCUAClient.js +21 -18
  128. package/dist/esm/lib/v3/agent/AnthropicCUAClient.js.map +1 -1
  129. package/dist/esm/lib/v3/agent/GoogleCUAClient.d.ts +12 -3
  130. package/dist/esm/lib/v3/agent/GoogleCUAClient.js +217 -36
  131. package/dist/esm/lib/v3/agent/GoogleCUAClient.js.map +1 -1
  132. package/dist/esm/lib/v3/agent/MicrosoftCUAClient.d.ts +2 -2
  133. package/dist/esm/lib/v3/agent/MicrosoftCUAClient.js +2 -2
  134. package/dist/esm/lib/v3/agent/MicrosoftCUAClient.js.map +1 -1
  135. package/dist/esm/lib/v3/agent/OpenAICUAClient.d.ts +6 -3
  136. package/dist/esm/lib/v3/agent/OpenAICUAClient.js +13 -7
  137. package/dist/esm/lib/v3/agent/OpenAICUAClient.js.map +1 -1
  138. package/dist/esm/lib/v3/agent/utils/handleDoneToolCall.d.ts +1 -0
  139. package/dist/esm/lib/v3/agent/utils/handleDoneToolCall.js +49 -3
  140. package/dist/esm/lib/v3/agent/utils/handleDoneToolCall.js.map +1 -1
  141. package/dist/esm/lib/v3/cache/ActCache.js +2 -2
  142. package/dist/esm/lib/v3/cache/ActCache.js.map +1 -1
  143. package/dist/esm/lib/v3/cache/utils.d.ts +7 -0
  144. package/dist/esm/lib/v3/cache/utils.js +18 -0
  145. package/dist/esm/lib/v3/cache/utils.js.map +1 -1
  146. package/dist/esm/lib/v3/handlers/v3AgentHandler.d.ts +2 -1
  147. package/dist/esm/lib/v3/handlers/v3AgentHandler.js +55 -16
  148. package/dist/esm/lib/v3/handlers/v3AgentHandler.js.map +1 -1
  149. package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.js +32 -18
  150. package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.js.map +1 -1
  151. package/dist/esm/lib/v3/index.d.ts +3 -2
  152. package/dist/esm/lib/v3/index.js.map +1 -1
  153. package/dist/esm/lib/v3/launch/local.js +1 -0
  154. package/dist/esm/lib/v3/launch/local.js.map +1 -1
  155. package/dist/esm/lib/v3/llm/LLMProvider.d.ts +2 -2
  156. package/dist/esm/lib/v3/llm/LLMProvider.js +1 -0
  157. package/dist/esm/lib/v3/llm/LLMProvider.js.map +1 -1
  158. package/dist/esm/lib/v3/llm/aisdk.js +4 -0
  159. package/dist/esm/lib/v3/llm/aisdk.js.map +1 -1
  160. package/dist/esm/lib/v3/llm/anthropicOptions.d.ts +57 -0
  161. package/dist/esm/lib/v3/llm/anthropicOptions.js +106 -0
  162. package/dist/esm/lib/v3/llm/anthropicOptions.js.map +1 -0
  163. package/dist/esm/lib/v3/types/public/agent.d.ts +10 -1
  164. package/dist/esm/lib/v3/types/public/agent.js +2 -0
  165. package/dist/esm/lib/v3/types/public/agent.js.map +1 -1
  166. package/dist/esm/lib/v3/types/public/context.d.ts +7 -0
  167. package/dist/esm/lib/v3/types/public/context.js.map +1 -1
  168. package/dist/esm/lib/v3/types/public/model.d.ts +3 -2
  169. package/dist/esm/lib/v3/types/public/model.js.map +1 -1
  170. package/dist/esm/lib/v3/types/public/sdkErrors.d.ts +4 -0
  171. package/dist/esm/lib/v3/types/public/sdkErrors.js +7 -0
  172. package/dist/esm/lib/v3/types/public/sdkErrors.js.map +1 -1
  173. package/dist/esm/lib/v3/understudy/cdp.d.ts +2 -0
  174. package/dist/esm/lib/v3/understudy/cdp.js +26 -12
  175. package/dist/esm/lib/v3/understudy/cdp.js.map +1 -1
  176. package/dist/esm/lib/v3/understudy/context.d.ts +13 -1
  177. package/dist/esm/lib/v3/understudy/context.js +285 -2
  178. package/dist/esm/lib/v3/understudy/context.js.map +1 -1
  179. package/dist/esm/lib/v3/understudy/domainPolicy.d.ts +25 -0
  180. package/dist/esm/lib/v3/understudy/domainPolicy.js +158 -0
  181. package/dist/esm/lib/v3/understudy/domainPolicy.js.map +1 -0
  182. package/dist/esm/lib/v3/understudy/page.js +1 -1
  183. package/dist/esm/lib/v3/understudy/page.js.map +1 -1
  184. package/dist/esm/lib/v3/v3.js +8 -2
  185. package/dist/esm/lib/v3/v3.js.map +1 -1
  186. package/dist/esm/lib/v3/verifier/errorTaxonomy.d.ts +35 -0
  187. package/dist/esm/lib/v3/verifier/errorTaxonomy.js +285 -0
  188. package/dist/esm/lib/v3/verifier/errorTaxonomy.js.map +1 -0
  189. package/dist/esm/lib/v3/verifier/evidence.d.ts +44 -0
  190. package/dist/esm/lib/v3/verifier/evidence.js +393 -0
  191. package/dist/esm/lib/v3/verifier/evidence.js.map +1 -0
  192. package/dist/esm/lib/v3/verifier/index.d.ts +1 -1
  193. package/dist/esm/lib/v3/verifier/index.js.map +1 -1
  194. package/dist/esm/lib/v3/verifier/prompts/batchedRelevance.d.ts +21 -0
  195. package/dist/esm/lib/v3/verifier/prompts/batchedRelevance.js +68 -0
  196. package/dist/esm/lib/v3/verifier/prompts/batchedRelevance.js.map +1 -0
  197. package/dist/esm/lib/v3/verifier/prompts/firstPointOfFailure.d.ts +3 -0
  198. package/dist/esm/lib/v3/verifier/prompts/firstPointOfFailure.js +162 -0
  199. package/dist/esm/lib/v3/verifier/prompts/firstPointOfFailure.js.map +1 -0
  200. package/dist/esm/lib/v3/verifier/prompts/fusedJudgment.d.ts +35 -0
  201. package/dist/esm/lib/v3/verifier/prompts/fusedJudgment.js +155 -0
  202. package/dist/esm/lib/v3/verifier/prompts/fusedJudgment.js.map +1 -0
  203. package/dist/esm/lib/v3/verifier/prompts/fusedOutcome.d.ts +26 -0
  204. package/dist/esm/lib/v3/verifier/prompts/fusedOutcome.js +134 -0
  205. package/dist/esm/lib/v3/verifier/prompts/fusedOutcome.js.map +1 -0
  206. package/dist/esm/lib/v3/verifier/prompts/index.d.ts +8 -0
  207. package/dist/esm/lib/v3/verifier/prompts/index.js +9 -0
  208. package/dist/esm/lib/v3/verifier/prompts/index.js.map +1 -0
  209. package/dist/esm/lib/v3/verifier/prompts/perCriterionScore.d.ts +23 -0
  210. package/dist/esm/lib/v3/verifier/prompts/perCriterionScore.js +74 -0
  211. package/dist/esm/lib/v3/verifier/prompts/perCriterionScore.js.map +1 -0
  212. package/dist/esm/lib/v3/verifier/prompts/render.d.ts +23 -0
  213. package/dist/esm/lib/v3/verifier/prompts/render.js +41 -0
  214. package/dist/esm/lib/v3/verifier/prompts/render.js.map +1 -0
  215. package/dist/esm/lib/v3/verifier/prompts/rubricGeneration.d.ts +16 -0
  216. package/dist/esm/lib/v3/verifier/prompts/rubricGeneration.js +318 -0
  217. package/dist/esm/lib/v3/verifier/prompts/rubricGeneration.js.map +1 -0
  218. package/dist/esm/lib/v3/verifier/prompts/taskValidity.d.ts +1 -0
  219. package/dist/esm/lib/v3/verifier/prompts/taskValidity.js +113 -0
  220. package/dist/esm/lib/v3/verifier/prompts/taskValidity.js.map +1 -0
  221. package/dist/esm/lib/v3/verifier/rubricVerifier.d.ts +91 -0
  222. package/dist/esm/lib/v3/verifier/rubricVerifier.js +1640 -0
  223. package/dist/esm/lib/v3/verifier/rubricVerifier.js.map +1 -0
  224. package/dist/esm/lib/v3/verifier/trajectory.d.ts +3 -3
  225. package/dist/esm/lib/v3/verifier/trajectory.js +26 -26
  226. package/dist/esm/lib/v3/verifier/trajectory.js.map +1 -1
  227. package/dist/esm/lib/v3/verifier/types.d.ts +163 -15
  228. package/dist/esm/lib/v3/verifier/types.js +0 -7
  229. package/dist/esm/lib/v3/verifier/types.js.map +1 -1
  230. package/dist/esm/lib/v3Evaluator.d.ts +5 -0
  231. package/dist/esm/lib/v3Evaluator.js +47 -7
  232. package/dist/esm/lib/v3Evaluator.js.map +1 -1
  233. package/dist/esm/lib/version.d.ts +1 -1
  234. package/dist/esm/lib/version.js +1 -1
  235. package/dist/esm/lib/version.js.map +1 -1
  236. package/package.json +10 -10
  237. package/dist/cjs/lib/v3/dom/build/selectorRuntime.generated.d.ts +0 -24
  238. package/dist/cjs/lib/v3/dom/build/selectorRuntime.generated.js +0 -31
  239. package/dist/cjs/lib/v3/dom/build/selectorRuntime.generated.js.map +0 -1
  240. package/dist/esm/lib/v3/dom/build/selectorRuntime.generated.d.ts +0 -24
  241. package/dist/esm/lib/v3/dom/build/selectorRuntime.generated.js +0 -28
  242. package/dist/esm/lib/v3/dom/build/selectorRuntime.generated.js.map +0 -1
@@ -174,6 +174,8 @@ class GoogleCUAClient extends AgentClient_js_1.AgentClient {
174
174
  await this.initializeHistory(instruction);
175
175
  let totalInputTokens = 0;
176
176
  let totalOutputTokens = 0;
177
+ let totalReasoningTokens = 0;
178
+ let totalCachedInputTokens = 0;
177
179
  let totalInferenceTime = 0;
178
180
  try {
179
181
  // Execute steps until completion or max steps reached
@@ -187,6 +189,8 @@ class GoogleCUAClient extends AgentClient_js_1.AgentClient {
187
189
  const result = await this.executeStep(logger);
188
190
  totalInputTokens += result.usage.input_tokens;
189
191
  totalOutputTokens += result.usage.output_tokens;
192
+ totalReasoningTokens += result.usage.reasoning_tokens;
193
+ totalCachedInputTokens += result.usage.cached_input_tokens;
190
194
  totalInferenceTime += result.usage.inference_time_ms;
191
195
  // Add actions to the list
192
196
  actions.push(...result.actions);
@@ -209,6 +213,8 @@ class GoogleCUAClient extends AgentClient_js_1.AgentClient {
209
213
  usage: {
210
214
  input_tokens: totalInputTokens,
211
215
  output_tokens: totalOutputTokens,
216
+ reasoning_tokens: totalReasoningTokens,
217
+ cached_input_tokens: totalCachedInputTokens,
212
218
  inference_time_ms: totalInferenceTime,
213
219
  },
214
220
  };
@@ -228,6 +234,8 @@ class GoogleCUAClient extends AgentClient_js_1.AgentClient {
228
234
  usage: {
229
235
  input_tokens: totalInputTokens,
230
236
  output_tokens: totalOutputTokens,
237
+ reasoning_tokens: totalReasoningTokens,
238
+ cached_input_tokens: totalCachedInputTokens,
231
239
  inference_time_ms: totalInferenceTime,
232
240
  },
233
241
  };
@@ -365,9 +373,14 @@ class GoogleCUAClient extends AgentClient_js_1.AgentClient {
365
373
  }
366
374
  // Execute actions and collect function responses
367
375
  const functionResponses = [];
368
- if (result.actions.length > 0) {
376
+ // Always process the model's response, even when it produced no
377
+ // executable action (e.g. a standalone take_screenshot). The model
378
+ // expects exactly one function response — a fresh screenshot — per
379
+ // computer-use call; skipping it when there are 0 actions leaves the
380
+ // model blind and it gives up after one empty turn.
381
+ {
369
382
  let hasError = false;
370
- // Execute all actions
383
+ // Execute all actions (a no-op when there are none).
371
384
  for (let i = 0; i < result.actions.length; i++) {
372
385
  const action = result.actions[i];
373
386
  logger({
@@ -385,6 +398,15 @@ class GoogleCUAClient extends AgentClient_js_1.AgentClient {
385
398
  level: 2,
386
399
  });
387
400
  }
401
+ else if (action.type === "screenshot") {
402
+ // No interaction to perform — the screenshot captured below is
403
+ // returned to the model as this call's function response.
404
+ logger({
405
+ category: "agent",
406
+ message: "take_screenshot: capturing current page",
407
+ level: 2,
408
+ });
409
+ }
388
410
  else if (action.type === "custom_tool") {
389
411
  const toolName = action.name;
390
412
  const toolArgs = action.arguments;
@@ -438,7 +460,7 @@ class GoogleCUAClient extends AgentClient_js_1.AgentClient {
438
460
  level: 2,
439
461
  });
440
462
  const screenshot = await this.captureScreenshot();
441
- const base64Data = screenshot.replace(/^data:image\/png;base64,/, "");
463
+ const base64Data = screenshot.base64;
442
464
  // Create one function response for each computer use function call
443
465
  // Following Python SDK pattern: FunctionResponse with parts containing inline_data
444
466
  for (const functionCall of computerUseFunctionCalls) {
@@ -460,7 +482,7 @@ class GoogleCUAClient extends AgentClient_js_1.AgentClient {
460
482
  parts: [
461
483
  {
462
484
  inlineData: {
463
- mimeType: "image/png",
485
+ mimeType: screenshot.mediaType,
464
486
  data: base64Data,
465
487
  },
466
488
  },
@@ -497,8 +519,14 @@ class GoogleCUAClient extends AgentClient_js_1.AgentClient {
497
519
  message: result.message,
498
520
  completed: result.completed,
499
521
  usage: {
522
+ // promptTokenCount is the TOTAL input and already includes the
523
+ // cached portion; cachedContentTokenCount is the cache-hit subset
524
+ // (tracked separately for visibility, not additive). thoughtsTokenCount
525
+ // is Gemini's thinking/reasoning output.
500
526
  input_tokens: usageMetadata?.promptTokenCount || 0,
501
527
  output_tokens: usageMetadata?.candidatesTokenCount || 0,
528
+ reasoning_tokens: usageMetadata?.thoughtsTokenCount || 0,
529
+ cached_input_tokens: usageMetadata?.cachedContentTokenCount || 0,
502
530
  inference_time_ms: elapsedMs,
503
531
  },
504
532
  };
@@ -553,23 +581,26 @@ class GoogleCUAClient extends AgentClient_js_1.AgentClient {
553
581
  level: 2,
554
582
  });
555
583
  // Convert function call to action(s)
556
- const action = this.convertFunctionCallToAction(part.functionCall);
584
+ const action = this.convertFunctionCallToAction(part.functionCall, logger);
557
585
  if (action) {
558
- // Special handling for type_text_at - we need to click first
559
- if (part.functionCall.name === "type_text_at" &&
560
- action.type === "type") {
586
+ // Special handling for type actions. gemini-2.5 type_text_at carries
587
+ // coordinates (click the field first); gemini-3.x `type` has none and
588
+ // types into the element the model already focused.
589
+ if (action.type === "type") {
561
590
  logger({
562
591
  category: "agent",
563
592
  message: `Adding action: ${JSON.stringify(action)}`,
564
593
  level: 2,
565
594
  });
566
- // First add a click action at the same coordinates
567
- actions.push({
568
- type: "click",
569
- x: action.x,
570
- y: action.y,
571
- button: "left",
572
- });
595
+ // Click the target first only when coordinates are provided.
596
+ if (typeof action.x === "number" && typeof action.y === "number") {
597
+ actions.push({
598
+ type: "click",
599
+ x: action.x,
600
+ y: action.y,
601
+ button: "left",
602
+ });
603
+ }
573
604
  // If clear_before_typing is true (default), add a select all
574
605
  if (action.clearBeforeTyping) {
575
606
  // Select all text in the field
@@ -623,18 +654,80 @@ class GoogleCUAClient extends AgentClient_js_1.AgentClient {
623
654
  /**
624
655
  * Convert Google function call to Stagehand action
625
656
  */
626
- convertFunctionCallToAction(functionCall) {
627
- const { name, args } = functionCall;
628
- if (!name || !args) {
657
+ convertFunctionCallToAction(functionCall, logger) {
658
+ const { name: rawName } = functionCall;
659
+ // Default args to an empty object so no-argument predefined functions
660
+ // (e.g. take_screenshot, go_back) are not rejected by the guard below.
661
+ const args = functionCall.args ?? {};
662
+ if (!rawName) {
629
663
  return null;
630
664
  }
665
+ // The gemini-3.x computer-use tool renamed several of the predefined
666
+ // functions that gemini-2.5-computer-use-preview used, and adds a
667
+ // descriptive `intent` arg to every call. The argument fields are otherwise
668
+ // unchanged (confirmed for click/navigate). Normalize the 3.x names to the
669
+ // canonical 2.5 names so a single set of handlers serves both generations;
670
+ // `intent` is ignored since handlers only read the args they need.
671
+ // NOTE: click and take_screenshot are confirmed from live gemini-3.5-flash
672
+ // traffic; the rest are inferred from the same drop-the-qualifier pattern
673
+ // and are safe aliases (any unmapped name still hits the warning below).
674
+ // gemini-3.x renamed several predefined functions vs gemini-2.5. Alias the
675
+ // 3.x names whose behavior maps cleanly onto a 2.5 canonical handler. Click
676
+ // variants that carry distinct semantics (double/triple/right/middle click,
677
+ // move) are NOT aliased here — they have dedicated cases below so the click
678
+ // count and button are preserved. 2.5 never emits any of these names, so
679
+ // the 2.5 handlers are unaffected.
680
+ const NAME_ALIASES = {
681
+ click: "click_at",
682
+ left_click: "click_at",
683
+ type: "type_text_at",
684
+ type_text: "type_text_at",
685
+ hover: "hover_at",
686
+ scroll: "scroll_at",
687
+ drag: "drag_and_drop",
688
+ key: "key_combination",
689
+ keys: "key_combination",
690
+ key_press: "key_combination",
691
+ press_key: "key_combination",
692
+ press_keys: "key_combination",
693
+ hotkey: "key_combination",
694
+ screenshot: "take_screenshot",
695
+ wait: "wait_5_seconds",
696
+ };
697
+ const name = NAME_ALIASES[rawName] ?? rawName;
698
+ // Predefined computer-use tools take precedence over custom tools. If a
699
+ // custom tool was registered under a reserved (aliased) name, note that the
700
+ // predefined tool wins rather than silently dropping the custom one.
701
+ if (rawName in NAME_ALIASES && (0, googleCustomToolHandler_js_1.isCustomTool)(functionCall, this.tools)) {
702
+ logger?.({
703
+ category: "agent",
704
+ message: `Custom tool "${rawName}" collides with a predefined Google CUA function; using the predefined tool. Rename the custom tool to avoid the conflict.`,
705
+ level: 2,
706
+ });
707
+ }
631
708
  switch (name) {
632
709
  case "open_web_browser":
633
710
  return {
634
711
  type: "open_web_browser",
635
712
  timestamp: Date.now(),
636
713
  };
714
+ case "take_screenshot":
715
+ // No UI interaction. The step loop captures a fresh screenshot and
716
+ // returns it to the model as this call's function response; marked as a
717
+ // recognized action (not null) so it isn't dropped, and skipped in the
718
+ // executor like open_web_browser.
719
+ return {
720
+ type: "screenshot",
721
+ timestamp: Date.now(),
722
+ };
637
723
  case "click_at": {
724
+ // x/y are required; reject a malformed call rather than normalizing
725
+ // undefined/NaN/Infinity into bad coordinates. (gemini-3.x `click`
726
+ // aliases here.)
727
+ if (!GoogleCUAClient.isFiniteCoord(args.x) ||
728
+ !GoogleCUAClient.isFiniteCoord(args.y)) {
729
+ return null;
730
+ }
638
731
  const { x, y } = this.normalizeCoordinates(args.x, args.y);
639
732
  return {
640
733
  type: "click",
@@ -643,28 +736,74 @@ class GoogleCUAClient extends AgentClient_js_1.AgentClient {
643
736
  button: args.button || "left",
644
737
  };
645
738
  }
646
- case "type_text_at": {
739
+ // gemini-3.x click family. The executor natively supports double/triple
740
+ // click and right/middle button, so preserve those semantics rather than
741
+ // collapsing to a single left click. All require integer coordinates;
742
+ // drop the call (return null) on a malformed payload so the executor is
743
+ // never handed NaN.
744
+ case "double_click":
745
+ case "triple_click":
746
+ case "right_click":
747
+ case "middle_click":
748
+ case "move": {
749
+ if (!GoogleCUAClient.isFiniteCoord(args.x) ||
750
+ !GoogleCUAClient.isFiniteCoord(args.y)) {
751
+ return null;
752
+ }
647
753
  const { x, y } = this.normalizeCoordinates(args.x, args.y);
648
- // Google's type_text_at includes press_enter and clear_before_typing parameters
754
+ if (name === "move") {
755
+ return { type: "move", x, y };
756
+ }
757
+ if (name === "double_click" || name === "triple_click") {
758
+ return { type: name, x, y };
759
+ }
760
+ return {
761
+ type: "click",
762
+ x,
763
+ y,
764
+ button: name === "right_click" ? "right" : "middle",
765
+ };
766
+ }
767
+ case "type_text_at": {
768
+ // text is required; reject a malformed call rather than typing
769
+ // "undefined". An empty string is valid (e.g. clear the field).
770
+ if (typeof args.text !== "string") {
771
+ return null;
772
+ }
773
+ // press_enter and clear_before_typing are shared across generations.
649
774
  const pressEnter = args.press_enter ?? false;
650
775
  const clearBeforeTyping = args.clear_before_typing ?? true;
651
- // For type_text_at, we need to click first then type
652
- // This matches the behavior expected by Google's CUA
653
- // We'll handle this in the executeStep method by converting to two actions
654
- return {
776
+ const base = {
655
777
  type: "type",
656
778
  text: args.text,
657
- x,
658
- y,
659
779
  pressEnter,
660
780
  clearBeforeTyping,
661
781
  };
782
+ // gemini-2.5 type_text_at carries x/y (click the field, then type).
783
+ // gemini-3.x `type` has no coordinates and types into the element the
784
+ // model already focused with a preceding click. Only attach coords when
785
+ // present so the executor doesn't click at NaN.
786
+ if (typeof args.x === "number" && typeof args.y === "number") {
787
+ const { x, y } = this.normalizeCoordinates(args.x, args.y);
788
+ return { ...base, x, y };
789
+ }
790
+ return base;
662
791
  }
663
792
  case "key_combination": {
664
- const keys = args.keys
665
- .split("+")
666
- .map((key) => key.trim())
793
+ // gemini-2.5 key_combination sends `keys` as a "+"-joined string;
794
+ // gemini-3.x `hotkey` sends a `keys` array, and `press_key` sends a
795
+ // single `key`. Accept all three.
796
+ const raw = args.keys !== undefined ? args.keys : args.key;
797
+ const parts = Array.isArray(raw)
798
+ ? raw
799
+ : String(raw ?? "").split("+");
800
+ const keys = parts
801
+ .map((key) => String(key).trim())
802
+ .filter(Boolean)
667
803
  .map((key) => (0, cuaKeyMapping_js_1.mapKeyToPlaywright)(key));
804
+ if (keys.length === 0) {
805
+ return null;
806
+ }
668
807
  return {
669
808
  type: "keypress",
670
809
  keys,
@@ -678,9 +817,24 @@ class GoogleCUAClient extends AgentClient_js_1.AgentClient {
678
817
  };
679
818
  }
680
819
  case "scroll_at": {
820
+ // A coordinate-less (or malformed) `scroll` alias (gemini-3.x) scrolls
821
+ // the document via PageUp/PageDown.
822
+ if (!GoogleCUAClient.isFiniteCoord(args.x) ||
823
+ !GoogleCUAClient.isFiniteCoord(args.y)) {
824
+ const dir = (args.direction || "down").toLowerCase();
825
+ return {
826
+ type: "keypress",
827
+ keys: [dir === "up" ? "PageUp" : "PageDown"],
828
+ };
829
+ }
681
830
  const { x, y } = this.normalizeCoordinates(args.x, args.y);
682
831
  const direction = (args.direction || "down").toLowerCase();
683
- const magnitude = typeof args.magnitude === "number" ? args.magnitude : 800;
832
+ // 2.5 uses `magnitude`; gemini-3.x `scroll` uses `magnitude_in_pixels`.
833
+ const magnitude = GoogleCUAClient.isFiniteCoord(args.magnitude)
834
+ ? args.magnitude
835
+ : GoogleCUAClient.isFiniteCoord(args.magnitude_in_pixels)
836
+ ? args.magnitude_in_pixels
837
+ : 800;
684
838
  let scroll_x = 0;
685
839
  let scroll_y = 0;
686
840
  if (direction === "up") {
@@ -708,6 +862,11 @@ class GoogleCUAClient extends AgentClient_js_1.AgentClient {
708
862
  };
709
863
  }
710
864
  case "navigate":
865
+ // url is required; reject a malformed call rather than navigating to
866
+ // "undefined".
867
+ if (typeof args.url !== "string" || args.url.length === 0) {
868
+ return null;
869
+ }
711
870
  return {
712
871
  type: "goto",
713
872
  url: args.url,
@@ -739,8 +898,20 @@ class GoogleCUAClient extends AgentClient_js_1.AgentClient {
739
898
  url: "https://www.google.com",
740
899
  };
741
900
  case "drag_and_drop": {
742
- const startPoint = this.normalizeCoordinates(args.x, args.y);
743
- const endPoint = this.normalizeCoordinates(args.destination_x, args.destination_y);
901
+ // 2.5 uses x/y + destination_x/destination_y; gemini-3.x `drag_and_drop`
902
+ // uses start_x/start_y + end_x/end_y. Accept either.
903
+ const sx = args.x ?? args.start_x;
904
+ const sy = args.y ?? args.start_y;
905
+ const ex = args.destination_x ?? args.end_x;
906
+ const ey = args.destination_y ?? args.end_y;
907
+ if (!GoogleCUAClient.isFiniteCoord(sx) ||
908
+ !GoogleCUAClient.isFiniteCoord(sy) ||
909
+ !GoogleCUAClient.isFiniteCoord(ex) ||
910
+ !GoogleCUAClient.isFiniteCoord(ey)) {
911
+ return null;
912
+ }
913
+ const startPoint = this.normalizeCoordinates(sx, sy);
914
+ const endPoint = this.normalizeCoordinates(ex, ey);
744
915
  return {
745
916
  type: "drag",
746
917
  path: [
@@ -763,6 +934,14 @@ class GoogleCUAClient extends AgentClient_js_1.AgentClient {
763
934
  return null;
764
935
  }
765
936
  }
937
+ /**
938
+ * True only for a usable coordinate/number: rejects undefined, non-numbers,
939
+ * and the numeric edge cases NaN and Infinity (both `typeof "number"`), so
940
+ * malformed function calls are dropped instead of normalizing into NaN.
941
+ */
942
+ static isFiniteCoord(value) {
943
+ return typeof value === "number" && Number.isFinite(value);
944
+ }
766
945
  /**
767
946
  * Normalize coordinates from Google's 0-1000 range to viewport dimensions
768
947
  */
@@ -781,13 +960,15 @@ class GoogleCUAClient extends AgentClient_js_1.AgentClient {
781
960
  }
782
961
  // Use provided options if available
783
962
  if (options?.base64Image) {
784
- return `data:image/png;base64,${options.base64Image}`;
963
+ return {
964
+ base64: options.base64Image,
965
+ mediaType: options.mediaType ?? "image/png",
966
+ };
785
967
  }
786
968
  // Use the screenshot provider if available
787
969
  if (this.screenshotProvider) {
788
970
  try {
789
- const base64Image = await this.screenshotProvider();
790
- return `data:image/png;base64,${base64Image}`;
971
+ return await this.screenshotProvider();
791
972
  }
792
973
  catch (error) {
793
974
  console.error("Error capturing screenshot:", error);
@@ -795,7 +976,7 @@ class GoogleCUAClient extends AgentClient_js_1.AgentClient {
795
976
  }
796
977
  }
797
978
  throw new sdkErrors_js_1.AgentScreenshotProviderError("`screenshotProvider` has not been set. " +
798
- "Please call `setScreenshotProvider()` with a valid function that returns a base64-encoded image");
979
+ "Please call `setScreenshotProvider()` with a valid function that returns a base64-encoded image and media type");
799
980
  }
800
981
  }
801
982
  exports.GoogleCUAClient = GoogleCUAClient;