@browserbasehq/orca 3.1.0-patch.4 → 3.2.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 (225) hide show
  1. package/dist/cjs/lib/inference.js +1 -4
  2. package/dist/cjs/lib/inference.js.map +1 -1
  3. package/dist/cjs/lib/v3/agent/AgentProvider.js +0 -1
  4. package/dist/cjs/lib/v3/agent/AgentProvider.js.map +1 -1
  5. package/dist/cjs/lib/v3/agent/tools/act.d.ts +1 -1
  6. package/dist/cjs/lib/v3/agent/tools/act.js +20 -4
  7. package/dist/cjs/lib/v3/agent/tools/act.js.map +1 -1
  8. package/dist/cjs/lib/v3/agent/tools/ariaTree.d.ts +8 -1
  9. package/dist/cjs/lib/v3/agent/tools/ariaTree.js +60 -22
  10. package/dist/cjs/lib/v3/agent/tools/ariaTree.js.map +1 -1
  11. package/dist/cjs/lib/v3/agent/tools/click.js +23 -31
  12. package/dist/cjs/lib/v3/agent/tools/click.js.map +1 -1
  13. package/dist/cjs/lib/v3/agent/tools/dragAndDrop.js +22 -30
  14. package/dist/cjs/lib/v3/agent/tools/dragAndDrop.js.map +1 -1
  15. package/dist/cjs/lib/v3/agent/tools/extract.d.ts +2 -2
  16. package/dist/cjs/lib/v3/agent/tools/extract.js +16 -3
  17. package/dist/cjs/lib/v3/agent/tools/extract.js.map +1 -1
  18. package/dist/cjs/lib/v3/agent/tools/fillFormVision.js +30 -30
  19. package/dist/cjs/lib/v3/agent/tools/fillFormVision.js.map +1 -1
  20. package/dist/cjs/lib/v3/agent/tools/fillform.d.ts +7 -1
  21. package/dist/cjs/lib/v3/agent/tools/fillform.js +60 -37
  22. package/dist/cjs/lib/v3/agent/tools/fillform.js.map +1 -1
  23. package/dist/cjs/lib/v3/agent/tools/index.d.ts +5 -0
  24. package/dist/cjs/lib/v3/agent/tools/index.js +5 -5
  25. package/dist/cjs/lib/v3/agent/tools/index.js.map +1 -1
  26. package/dist/cjs/lib/v3/agent/tools/screenshot.d.ts +8 -0
  27. package/dist/cjs/lib/v3/agent/tools/screenshot.js +32 -15
  28. package/dist/cjs/lib/v3/agent/tools/screenshot.js.map +1 -1
  29. package/dist/cjs/lib/v3/agent/tools/scroll.js +12 -0
  30. package/dist/cjs/lib/v3/agent/tools/scroll.js.map +1 -1
  31. package/dist/cjs/lib/v3/agent/tools/type.js +23 -31
  32. package/dist/cjs/lib/v3/agent/tools/type.js.map +1 -1
  33. package/dist/cjs/lib/v3/agent/tools/wait.js +6 -0
  34. package/dist/cjs/lib/v3/agent/tools/wait.js.map +1 -1
  35. package/dist/cjs/lib/v3/agent/utils/handleDoneToolCall.js +4 -0
  36. package/dist/cjs/lib/v3/agent/utils/handleDoneToolCall.js.map +1 -1
  37. package/dist/cjs/lib/v3/api.d.ts +2 -2
  38. package/dist/cjs/lib/v3/api.js +1 -1
  39. package/dist/cjs/lib/v3/api.js.map +1 -1
  40. package/dist/cjs/lib/v3/cache/ActCache.d.ts +0 -1
  41. package/dist/cjs/lib/v3/cache/ActCache.js +2 -18
  42. package/dist/cjs/lib/v3/cache/ActCache.js.map +1 -1
  43. package/dist/cjs/lib/v3/handlers/actHandler.js +1 -2
  44. package/dist/cjs/lib/v3/handlers/actHandler.js.map +1 -1
  45. package/dist/cjs/lib/v3/handlers/extractHandler.js +2 -2
  46. package/dist/cjs/lib/v3/handlers/extractHandler.js.map +1 -1
  47. package/dist/cjs/lib/v3/handlers/observeHandler.js +1 -2
  48. package/dist/cjs/lib/v3/handlers/observeHandler.js.map +1 -1
  49. package/dist/cjs/lib/v3/handlers/v3AgentHandler.js +11 -16
  50. package/dist/cjs/lib/v3/handlers/v3AgentHandler.js.map +1 -1
  51. package/dist/cjs/lib/v3/index.d.ts +2 -1
  52. package/dist/cjs/lib/v3/launch/browserbase.d.ts +1 -1
  53. package/dist/cjs/lib/v3/launch/browserbase.js +4 -9
  54. package/dist/cjs/lib/v3/launch/browserbase.js.map +1 -1
  55. package/dist/cjs/lib/v3/llm/LLMProvider.js +0 -5
  56. package/dist/cjs/lib/v3/llm/LLMProvider.js.map +1 -1
  57. package/dist/cjs/lib/v3/runtimePaths.js +2 -1
  58. package/dist/cjs/lib/v3/runtimePaths.js.map +1 -1
  59. package/dist/cjs/lib/v3/shutdown/supervisor.js +2 -2
  60. package/dist/cjs/lib/v3/shutdown/supervisor.js.map +1 -1
  61. package/dist/cjs/lib/v3/timeoutConfig.d.ts +1 -1
  62. package/dist/cjs/lib/v3/timeoutConfig.js +5 -0
  63. package/dist/cjs/lib/v3/timeoutConfig.js.map +1 -1
  64. package/dist/cjs/lib/v3/types/private/shutdown.d.ts +1 -1
  65. package/dist/cjs/lib/v3/types/private/shutdown.js.map +1 -1
  66. package/dist/cjs/lib/v3/types/public/agent.d.ts +12 -1
  67. package/dist/cjs/lib/v3/types/public/agent.js +0 -1
  68. package/dist/cjs/lib/v3/types/public/agent.js.map +1 -1
  69. package/dist/cjs/lib/v3/types/public/api.d.ts +3 -0
  70. package/dist/cjs/lib/v3/types/public/api.js +1 -0
  71. package/dist/cjs/lib/v3/types/public/api.js.map +1 -1
  72. package/dist/cjs/lib/v3/types/public/model.d.ts +4 -2
  73. package/dist/cjs/lib/v3/types/public/model.js.map +1 -1
  74. package/dist/cjs/lib/v3/types/public/options.d.ts +1 -0
  75. package/dist/cjs/lib/v3/understudy/cdp.d.ts +5 -1
  76. package/dist/cjs/lib/v3/understudy/cdp.js +54 -7
  77. package/dist/cjs/lib/v3/understudy/cdp.js.map +1 -1
  78. package/dist/cjs/lib/v3/understudy/context.d.ts +1 -0
  79. package/dist/cjs/lib/v3/understudy/context.js +142 -60
  80. package/dist/cjs/lib/v3/understudy/context.js.map +1 -1
  81. package/dist/cjs/lib/v3/understudy/frame.js +23 -6
  82. package/dist/cjs/lib/v3/understudy/frame.js.map +1 -1
  83. package/dist/cjs/lib/v3/understudy/page.d.ts +13 -0
  84. package/dist/cjs/lib/v3/understudy/page.js +56 -3
  85. package/dist/cjs/lib/v3/understudy/page.js.map +1 -1
  86. package/dist/cjs/lib/v3/understudy/screenshotUtils.d.ts +0 -1
  87. package/dist/cjs/lib/v3/understudy/screenshotUtils.js +0 -18
  88. package/dist/cjs/lib/v3/understudy/screenshotUtils.js.map +1 -1
  89. package/dist/cjs/lib/v3/v3.js +38 -24
  90. package/dist/cjs/lib/v3/v3.js.map +1 -1
  91. package/dist/cjs/tests/integration/cdp-session-detached.spec.js +1 -1
  92. package/dist/cjs/tests/integration/cdp-session-detached.spec.js.map +1 -1
  93. package/dist/cjs/tests/integration/context-addInitScript.spec.js +104 -11
  94. package/dist/cjs/tests/integration/context-addInitScript.spec.js.map +1 -1
  95. package/dist/cjs/tests/integration/iframe-ctx-addInitScript-race.spec.d.ts +1 -0
  96. package/dist/cjs/tests/integration/iframe-ctx-addInitScript-race.spec.js +219 -0
  97. package/dist/cjs/tests/integration/iframe-ctx-addInitScript-race.spec.js.map +1 -0
  98. package/dist/cjs/tests/integration/page-extra-http-headers.spec.d.ts +1 -0
  99. package/dist/cjs/tests/integration/page-extra-http-headers.spec.js +85 -0
  100. package/dist/cjs/tests/integration/page-extra-http-headers.spec.js.map +1 -0
  101. package/dist/cjs/tests/integration/page-screenshot.spec.js +1 -1
  102. package/dist/cjs/tests/integration/page-screenshot.spec.js.map +1 -1
  103. package/dist/cjs/tests/integration/timeouts.spec.js +168 -0
  104. package/dist/cjs/tests/integration/timeouts.spec.js.map +1 -1
  105. package/dist/cjs/tests/unit/model-deprecation.test.js +5 -8
  106. package/dist/cjs/tests/unit/model-deprecation.test.js.map +1 -1
  107. package/dist/cjs/tests/unit/page-extra-http-headers.test.d.ts +1 -0
  108. package/dist/cjs/tests/unit/page-extra-http-headers.test.js +92 -0
  109. package/dist/cjs/tests/unit/page-extra-http-headers.test.js.map +1 -0
  110. package/dist/cjs/tests/unit/public-api/llm-and-agents.test.js +13 -1
  111. package/dist/cjs/tests/unit/public-api/llm-and-agents.test.js.map +1 -1
  112. package/dist/cjs/tests/unit/public-api/public-types.test.js.map +1 -1
  113. package/dist/esm/lib/inference.js +1 -4
  114. package/dist/esm/lib/inference.js.map +1 -1
  115. package/dist/esm/lib/v3/agent/AgentProvider.js +0 -1
  116. package/dist/esm/lib/v3/agent/AgentProvider.js.map +1 -1
  117. package/dist/esm/lib/v3/agent/tools/act.d.ts +1 -1
  118. package/dist/esm/lib/v3/agent/tools/act.js +20 -4
  119. package/dist/esm/lib/v3/agent/tools/act.js.map +1 -1
  120. package/dist/esm/lib/v3/agent/tools/ariaTree.d.ts +8 -1
  121. package/dist/esm/lib/v3/agent/tools/ariaTree.js +60 -22
  122. package/dist/esm/lib/v3/agent/tools/ariaTree.js.map +1 -1
  123. package/dist/esm/lib/v3/agent/tools/click.js +23 -31
  124. package/dist/esm/lib/v3/agent/tools/click.js.map +1 -1
  125. package/dist/esm/lib/v3/agent/tools/dragAndDrop.js +22 -30
  126. package/dist/esm/lib/v3/agent/tools/dragAndDrop.js.map +1 -1
  127. package/dist/esm/lib/v3/agent/tools/extract.d.ts +2 -2
  128. package/dist/esm/lib/v3/agent/tools/extract.js +16 -3
  129. package/dist/esm/lib/v3/agent/tools/extract.js.map +1 -1
  130. package/dist/esm/lib/v3/agent/tools/fillFormVision.js +30 -30
  131. package/dist/esm/lib/v3/agent/tools/fillFormVision.js.map +1 -1
  132. package/dist/esm/lib/v3/agent/tools/fillform.d.ts +7 -1
  133. package/dist/esm/lib/v3/agent/tools/fillform.js +60 -37
  134. package/dist/esm/lib/v3/agent/tools/fillform.js.map +1 -1
  135. package/dist/esm/lib/v3/agent/tools/index.d.ts +5 -0
  136. package/dist/esm/lib/v3/agent/tools/index.js +5 -5
  137. package/dist/esm/lib/v3/agent/tools/index.js.map +1 -1
  138. package/dist/esm/lib/v3/agent/tools/screenshot.d.ts +8 -0
  139. package/dist/esm/lib/v3/agent/tools/screenshot.js +32 -15
  140. package/dist/esm/lib/v3/agent/tools/screenshot.js.map +1 -1
  141. package/dist/esm/lib/v3/agent/tools/scroll.js +12 -0
  142. package/dist/esm/lib/v3/agent/tools/scroll.js.map +1 -1
  143. package/dist/esm/lib/v3/agent/tools/type.js +23 -31
  144. package/dist/esm/lib/v3/agent/tools/type.js.map +1 -1
  145. package/dist/esm/lib/v3/agent/tools/wait.js +6 -0
  146. package/dist/esm/lib/v3/agent/tools/wait.js.map +1 -1
  147. package/dist/esm/lib/v3/agent/utils/handleDoneToolCall.js +4 -0
  148. package/dist/esm/lib/v3/agent/utils/handleDoneToolCall.js.map +1 -1
  149. package/dist/esm/lib/v3/api.d.ts +2 -2
  150. package/dist/esm/lib/v3/api.js +1 -1
  151. package/dist/esm/lib/v3/api.js.map +1 -1
  152. package/dist/esm/lib/v3/cache/ActCache.d.ts +0 -1
  153. package/dist/esm/lib/v3/cache/ActCache.js +2 -18
  154. package/dist/esm/lib/v3/cache/ActCache.js.map +1 -1
  155. package/dist/esm/lib/v3/handlers/actHandler.js +1 -2
  156. package/dist/esm/lib/v3/handlers/actHandler.js.map +1 -1
  157. package/dist/esm/lib/v3/handlers/extractHandler.js +2 -2
  158. package/dist/esm/lib/v3/handlers/extractHandler.js.map +1 -1
  159. package/dist/esm/lib/v3/handlers/observeHandler.js +1 -2
  160. package/dist/esm/lib/v3/handlers/observeHandler.js.map +1 -1
  161. package/dist/esm/lib/v3/handlers/v3AgentHandler.js +11 -16
  162. package/dist/esm/lib/v3/handlers/v3AgentHandler.js.map +1 -1
  163. package/dist/esm/lib/v3/index.d.ts +2 -1
  164. package/dist/esm/lib/v3/launch/browserbase.d.ts +1 -1
  165. package/dist/esm/lib/v3/launch/browserbase.js +4 -9
  166. package/dist/esm/lib/v3/launch/browserbase.js.map +1 -1
  167. package/dist/esm/lib/v3/llm/LLMProvider.js +0 -5
  168. package/dist/esm/lib/v3/llm/LLMProvider.js.map +1 -1
  169. package/dist/esm/lib/v3/runtimePaths.js +2 -1
  170. package/dist/esm/lib/v3/runtimePaths.js.map +1 -1
  171. package/dist/esm/lib/v3/shutdown/supervisor.js +2 -2
  172. package/dist/esm/lib/v3/shutdown/supervisor.js.map +1 -1
  173. package/dist/esm/lib/v3/timeoutConfig.d.ts +1 -1
  174. package/dist/esm/lib/v3/timeoutConfig.js +5 -0
  175. package/dist/esm/lib/v3/timeoutConfig.js.map +1 -1
  176. package/dist/esm/lib/v3/types/private/shutdown.d.ts +1 -1
  177. package/dist/esm/lib/v3/types/private/shutdown.js.map +1 -1
  178. package/dist/esm/lib/v3/types/public/agent.d.ts +12 -1
  179. package/dist/esm/lib/v3/types/public/agent.js +0 -1
  180. package/dist/esm/lib/v3/types/public/agent.js.map +1 -1
  181. package/dist/esm/lib/v3/types/public/api.d.ts +3 -0
  182. package/dist/esm/lib/v3/types/public/api.js +1 -0
  183. package/dist/esm/lib/v3/types/public/api.js.map +1 -1
  184. package/dist/esm/lib/v3/types/public/model.d.ts +4 -2
  185. package/dist/esm/lib/v3/types/public/model.js.map +1 -1
  186. package/dist/esm/lib/v3/types/public/options.d.ts +1 -0
  187. package/dist/esm/lib/v3/understudy/cdp.d.ts +5 -1
  188. package/dist/esm/lib/v3/understudy/cdp.js +55 -8
  189. package/dist/esm/lib/v3/understudy/cdp.js.map +1 -1
  190. package/dist/esm/lib/v3/understudy/context.d.ts +1 -0
  191. package/dist/esm/lib/v3/understudy/context.js +142 -60
  192. package/dist/esm/lib/v3/understudy/context.js.map +1 -1
  193. package/dist/esm/lib/v3/understudy/frame.js +23 -6
  194. package/dist/esm/lib/v3/understudy/frame.js.map +1 -1
  195. package/dist/esm/lib/v3/understudy/page.d.ts +13 -0
  196. package/dist/esm/lib/v3/understudy/page.js +58 -5
  197. package/dist/esm/lib/v3/understudy/page.js.map +1 -1
  198. package/dist/esm/lib/v3/understudy/screenshotUtils.d.ts +0 -1
  199. package/dist/esm/lib/v3/understudy/screenshotUtils.js +0 -17
  200. package/dist/esm/lib/v3/understudy/screenshotUtils.js.map +1 -1
  201. package/dist/esm/lib/v3/v3.js +38 -24
  202. package/dist/esm/lib/v3/v3.js.map +1 -1
  203. package/dist/esm/tests/integration/cdp-session-detached.spec.js +1 -1
  204. package/dist/esm/tests/integration/cdp-session-detached.spec.js.map +1 -1
  205. package/dist/esm/tests/integration/context-addInitScript.spec.js +104 -11
  206. package/dist/esm/tests/integration/context-addInitScript.spec.js.map +1 -1
  207. package/dist/esm/tests/integration/iframe-ctx-addInitScript-race.spec.d.ts +1 -0
  208. package/dist/esm/tests/integration/iframe-ctx-addInitScript-race.spec.js +217 -0
  209. package/dist/esm/tests/integration/iframe-ctx-addInitScript-race.spec.js.map +1 -0
  210. package/dist/esm/tests/integration/page-extra-http-headers.spec.d.ts +1 -0
  211. package/dist/esm/tests/integration/page-extra-http-headers.spec.js +83 -0
  212. package/dist/esm/tests/integration/page-extra-http-headers.spec.js.map +1 -0
  213. package/dist/esm/tests/integration/page-screenshot.spec.js +1 -1
  214. package/dist/esm/tests/integration/page-screenshot.spec.js.map +1 -1
  215. package/dist/esm/tests/integration/timeouts.spec.js +168 -0
  216. package/dist/esm/tests/integration/timeouts.spec.js.map +1 -1
  217. package/dist/esm/tests/unit/model-deprecation.test.js +5 -8
  218. package/dist/esm/tests/unit/model-deprecation.test.js.map +1 -1
  219. package/dist/esm/tests/unit/page-extra-http-headers.test.d.ts +1 -0
  220. package/dist/esm/tests/unit/page-extra-http-headers.test.js +90 -0
  221. package/dist/esm/tests/unit/page-extra-http-headers.test.js.map +1 -0
  222. package/dist/esm/tests/unit/public-api/llm-and-agents.test.js +13 -1
  223. package/dist/esm/tests/unit/public-api/llm-and-agents.test.js.map +1 -1
  224. package/dist/esm/tests/unit/public-api/public-types.test.js.map +1 -1
  225. package/package.json +4 -2
@@ -1,6 +1,6 @@
1
1
  import type { V3 } from "../../v3.js";
2
2
  import type { AgentModelConfig } from "../../types/public/agent.js";
3
- export declare const extractTool: (v3: V3, executionModel?: string | AgentModelConfig) => import("ai").Tool<{
3
+ export declare const extractTool: (v3: V3, executionModel?: string | AgentModelConfig, toolTimeout?: number) => import("ai").Tool<{
4
4
  instruction: string;
5
5
  schema?: {
6
6
  [x: string]: unknown;
@@ -16,6 +16,6 @@ export declare const extractTool: (v3: V3, executionModel?: string | AgentModelC
16
16
  error?: undefined;
17
17
  } | {
18
18
  success: boolean;
19
- error: string;
19
+ error: any;
20
20
  result?: undefined;
21
21
  }>;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.extractTool = void 0;
4
4
  const ai_1 = require("ai");
5
5
  const zod_1 = require("zod");
6
+ const sdkErrors_js_1 = require("../../types/public/sdkErrors.js");
6
7
  function jsonSchemaToZod(schema) {
7
8
  switch (schema.type) {
8
9
  case "object": {
@@ -39,7 +40,7 @@ function jsonSchemaToZod(schema) {
39
40
  return zod_1.z.any();
40
41
  }
41
42
  }
42
- const extractTool = (v3, executionModel) => (0, ai_1.tool)({
43
+ const extractTool = (v3, executionModel, toolTimeout) => (0, ai_1.tool)({
43
44
  description: `Extract structured data from the current page based on a provided schema.
44
45
 
45
46
  USAGE GUIDELINES:
@@ -84,12 +85,24 @@ const extractTool = (v3, executionModel) => (0, ai_1.tool)({
84
85
  : undefined;
85
86
  const result = await v3.extract(instruction, parsedSchema, {
86
87
  ...(executionModel ? { model: executionModel } : {}),
88
+ timeout: toolTimeout,
87
89
  });
88
90
  return { success: true, result };
89
91
  }
90
92
  catch (error) {
91
- const err = error;
92
- return { success: false, error: err?.message ?? String(error) };
93
+ if (error instanceof sdkErrors_js_1.TimeoutError) {
94
+ const timeoutMessage = `TimeoutError: extract() timed out try using a smaller or simpler schema`;
95
+ v3.logger({
96
+ category: "agent",
97
+ message: timeoutMessage,
98
+ level: 0,
99
+ });
100
+ return {
101
+ success: false,
102
+ error: timeoutMessage,
103
+ };
104
+ }
105
+ return { success: false, error: error?.message ?? String(error) };
93
106
  }
94
107
  },
95
108
  });
@@ -1 +1 @@
1
- {"version":3,"file":"extract.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/tools/extract.ts"],"names":[],"mappings":";;;AAAA,2BAA0B;AAC1B,6BAAoC;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M,MAAM,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,WAAW,EAAE,YAAY,EAAE;gBACzD,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACrD,CAAC,CAAC;YACH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QACnC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,GAAG,GAAG,KAAc,CAAC;YAC3B,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAClE,CAAC;IACH,CAAC;CACF,CAAC,CAAC;AAxDQ,QAAA,WAAW,eAwDnB","sourcesContent":["import { tool } from \"ai\";\nimport { z, ZodTypeAny } from \"zod\";\nimport type { V3 } from \"../../v3.js\";\nimport type { AgentModelConfig } from \"../../types/public/agent.js\";\n\ninterface JsonSchema {\n type?: string;\n properties?: Record<string, JsonSchema>;\n items?: JsonSchema;\n enum?: string[];\n format?: \"url\" | \"email\" | \"uuid\";\n}\n\nfunction jsonSchemaToZod(schema: JsonSchema): ZodTypeAny {\n switch (schema.type) {\n case \"object\": {\n const shape: Record<string, ZodTypeAny> = {};\n if (schema.properties) {\n for (const [key, value] of Object.entries(schema.properties)) {\n shape[key] = jsonSchemaToZod(value);\n }\n }\n return z.object(shape);\n }\n case \"array\":\n return z.array(schema.items ? jsonSchemaToZod(schema.items) : z.any());\n case \"string\": {\n let s = z.string();\n if (schema.format === \"url\") s = s.url();\n if (schema.format === \"email\") s = s.email();\n if (schema.format === \"uuid\") s = s.uuid();\n if (schema.enum && schema.enum.length > 0)\n return z.enum(schema.enum as [string, ...string[]]);\n return s;\n }\n case \"number\":\n case \"integer\":\n return z.number();\n case \"boolean\":\n return z.boolean();\n case \"null\":\n return z.null();\n default:\n return z.any();\n }\n}\n\nexport const extractTool = (\n v3: V3,\n executionModel?: string | AgentModelConfig,\n) =>\n tool({\n description: `Extract structured data from the current page based on a provided schema.\n \n USAGE GUIDELINES:\n - Keep schemas MINIMAL - only include fields essential for the task\n - IMPORTANT: only use this if explicitly asked for structured output. In most scenarios, you should use the aria tree tool over this.\n - For URL fields, use format: \"url\"\n \n EXAMPLES:\n 1. Extract a single value:\n instruction: \"extract the product price\"\n schema: { type: \"object\", properties: { price: { type: \"number\" } } }\n \n 2. Extract multiple fields:\n instruction: \"extract product name and price\"\n schema: { type: \"object\", properties: { name: { type: \"string\" }, price: { type: \"number\" } } }\n \n 3. Extract arrays:\n instruction: \"extract all product names and prices\"\n schema: { type: \"object\", properties: { products: { type: \"array\", items: { type: \"object\", properties: { name: { type: \"string\" }, price: { type: \"number\" } } } } } }\n \n 4. Extract a URL:\n instruction: \"extract the link\"\n schema: { type: \"object\", properties: { url: { type: \"string\", format: \"url\" } } }`,\n inputSchema: z.object({\n instruction: z.string(),\n schema: z\n .object({\n type: z.string().optional(),\n properties: z.record(z.string(), z.unknown()).optional(),\n items: z.unknown().optional(),\n enum: z.array(z.string()).optional(),\n format: z.enum([\"url\", \"email\", \"uuid\"]).optional(),\n })\n .passthrough()\n .optional()\n .describe(\"JSON Schema object describing the structure to extract\"),\n }),\n execute: async ({ instruction, schema }) => {\n try {\n const parsedSchema = schema\n ? jsonSchemaToZod(schema as JsonSchema)\n : undefined;\n const result = await v3.extract(instruction, parsedSchema, {\n ...(executionModel ? { model: executionModel } : {}),\n });\n return { success: true, result };\n } catch (error) {\n const err = error as Error;\n return { success: false, error: err?.message ?? String(error) };\n }\n },\n });\n"]}
1
+ {"version":3,"file":"extract.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/tools/extract.ts"],"names":[],"mappings":";;;AAAA,2BAA0B;AAC1B,6BAAoC;AAGpC,kEAA+D;AAU/D,SAAS,eAAe,CAAC,MAAkB;IACzC,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,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,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACpD,OAAO,EAAE,WAAW;aACrB,CAAC,CAAC;YACH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QACnC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,2BAAY,EAAE,CAAC;gBAClC,MAAM,cAAc,GAAG,2EAA2E,CAAC;gBACnG,EAAE,CAAC,MAAM,CAAC;oBACR,QAAQ,EAAE,OAAO;oBACjB,OAAO,EAAE,cAAc;oBACvB,KAAK,EAAE,CAAC;iBACT,CAAC,CAAC;gBACH,OAAO;oBACL,OAAO,EAAE,KAAK;oBACd,KAAK,EAAE,cAAc;iBACtB,CAAC;YACJ,CAAC;YACD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QACpE,CAAC;IACH,CAAC;CACF,CAAC,CAAC;AArEQ,QAAA,WAAW,eAqEnB","sourcesContent":["import { tool } from \"ai\";\nimport { z, ZodTypeAny } from \"zod\";\nimport type { V3 } from \"../../v3.js\";\nimport type { AgentModelConfig } from \"../../types/public/agent.js\";\nimport { TimeoutError } from \"../../types/public/sdkErrors.js\";\n\ninterface JsonSchema {\n type?: string;\n properties?: Record<string, JsonSchema>;\n items?: JsonSchema;\n enum?: string[];\n format?: \"url\" | \"email\" | \"uuid\";\n}\n\nfunction jsonSchemaToZod(schema: JsonSchema): ZodTypeAny {\n switch (schema.type) {\n case \"object\": {\n const shape: Record<string, ZodTypeAny> = {};\n if (schema.properties) {\n for (const [key, value] of Object.entries(schema.properties)) {\n shape[key] = jsonSchemaToZod(value);\n }\n }\n return z.object(shape);\n }\n case \"array\":\n return z.array(schema.items ? jsonSchemaToZod(schema.items) : z.any());\n case \"string\": {\n let s = z.string();\n if (schema.format === \"url\") s = s.url();\n if (schema.format === \"email\") s = s.email();\n if (schema.format === \"uuid\") s = s.uuid();\n if (schema.enum && schema.enum.length > 0)\n return z.enum(schema.enum as [string, ...string[]]);\n return s;\n }\n case \"number\":\n case \"integer\":\n return z.number();\n case \"boolean\":\n return z.boolean();\n case \"null\":\n return z.null();\n default:\n return z.any();\n }\n}\n\nexport const extractTool = (\n v3: V3,\n executionModel?: string | AgentModelConfig,\n toolTimeout?: number,\n) =>\n tool({\n description: `Extract structured data from the current page based on a provided schema.\n \n USAGE GUIDELINES:\n - Keep schemas MINIMAL - only include fields essential for the task\n - IMPORTANT: only use this if explicitly asked for structured output. In most scenarios, you should use the aria tree tool over this.\n - For URL fields, use format: \"url\"\n \n EXAMPLES:\n 1. Extract a single value:\n instruction: \"extract the product price\"\n schema: { type: \"object\", properties: { price: { type: \"number\" } } }\n \n 2. Extract multiple fields:\n instruction: \"extract product name and price\"\n schema: { type: \"object\", properties: { name: { type: \"string\" }, price: { type: \"number\" } } }\n \n 3. Extract arrays:\n instruction: \"extract all product names and prices\"\n schema: { type: \"object\", properties: { products: { type: \"array\", items: { type: \"object\", properties: { name: { type: \"string\" }, price: { type: \"number\" } } } } } }\n \n 4. Extract a URL:\n instruction: \"extract the link\"\n schema: { type: \"object\", properties: { url: { type: \"string\", format: \"url\" } } }`,\n inputSchema: z.object({\n instruction: z.string(),\n schema: z\n .object({\n type: z.string().optional(),\n properties: z.record(z.string(), z.unknown()).optional(),\n items: z.unknown().optional(),\n enum: z.array(z.string()).optional(),\n format: z.enum([\"url\", \"email\", \"uuid\"]).optional(),\n })\n .passthrough()\n .optional()\n .describe(\"JSON Schema object describing the structure to extract\"),\n }),\n execute: async ({ instruction, schema }) => {\n try {\n const parsedSchema = schema\n ? jsonSchemaToZod(schema as JsonSchema)\n : undefined;\n const result = await v3.extract(instruction, parsedSchema, {\n ...(executionModel ? { model: executionModel } : {}),\n timeout: toolTimeout,\n });\n return { success: true, result };\n } catch (error) {\n if (error instanceof TimeoutError) {\n const timeoutMessage = `TimeoutError: extract() timed out — try using a smaller or simpler schema`;\n v3.logger({\n category: \"agent\",\n message: timeoutMessage,\n level: 0,\n });\n return {\n success: false,\n error: timeoutMessage,\n };\n }\n return { success: false, error: error?.message ?? String(error) };\n }\n },\n });\n"]}
@@ -120,37 +120,37 @@ MANDATORY USE CASES (always use fillFormVision for these):
120
120
  }
121
121
  },
122
122
  toModelOutput: (result) => {
123
- if (result.success) {
124
- const content = [
125
- {
126
- type: "text",
127
- text: JSON.stringify({
128
- success: result.success,
129
- fieldsCount: result.playwrightArguments?.length ?? 0,
130
- }),
131
- },
132
- ];
133
- if (result.screenshotBase64) {
134
- content.push({
135
- type: "media",
136
- mediaType: "image/png",
137
- data: result.screenshotBase64,
138
- });
139
- }
140
- return { type: "content", value: content };
123
+ if (result.success === false || result.error !== undefined) {
124
+ return {
125
+ type: "content",
126
+ value: [
127
+ {
128
+ type: "text",
129
+ text: JSON.stringify({
130
+ success: result.success,
131
+ error: result.error,
132
+ }),
133
+ },
134
+ ],
135
+ };
141
136
  }
142
- return {
143
- type: "content",
144
- value: [
145
- {
146
- type: "text",
147
- text: JSON.stringify({
148
- success: result.success,
149
- error: result.error,
150
- }),
151
- },
152
- ],
153
- };
137
+ const content = [
138
+ {
139
+ type: "text",
140
+ text: JSON.stringify({
141
+ success: result.success,
142
+ fieldsCount: result.playwrightArguments?.length ?? 0,
143
+ }),
144
+ },
145
+ ];
146
+ if (result.screenshotBase64) {
147
+ content.push({
148
+ type: "media",
149
+ mediaType: "image/png",
150
+ data: result.screenshotBase64,
151
+ });
152
+ }
153
+ return { type: "content", value: content };
154
154
  },
155
155
  });
156
156
  };
@@ -1 +1 @@
1
- {"version":3,"file":"fillFormVision.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/tools/fillFormVision.ts"],"names":[],"mappings":";;;AAAA,2BAA0B;AAC1B,6BAAwB;AAQxB,oFAAyE;AACzE,gDAAgD;AAChD,wEAAyE;AACzE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,OAAO;4BACvB,WAAW,EAAE,MAAM,CAAC,mBAAmB,EAAE,MAAM,IAAI,CAAC;yBACrD,CAAC;qBACH;iBACF,CAAC;gBACF,IAAI,MAAM,CAAC,gBAAgB,EAAE,CAAC;oBAC5B,OAAO,CAAC,IAAI,CAAC;wBACX,IAAI,EAAE,OAAO;wBACb,SAAS,EAAE,WAAW;wBACtB,IAAI,EAAE,MAAM,CAAC,gBAAgB;qBAC9B,CAAC,CAAC;gBACL,CAAC;gBACD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;YAC7C,CAAC;YACD,OAAO;gBACL,IAAI,EAAE,SAAS;gBACf,KAAK,EAAE;oBACL;wBACE,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;4BACnB,OAAO,EAAE,MAAM,CAAC,OAAO;4BACvB,KAAK,EAAE,MAAM,CAAC,KAAK;yBACpB,CAAC;qBACH;iBACF;aACF,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC;AA5KW,QAAA,kBAAkB,sBA4K7B","sourcesContent":["import { tool } from \"ai\";\nimport { z } from \"zod\";\nimport type { V3 } from \"../../v3.js\";\nimport type { Action } from \"../../types/public/methods.js\";\nimport type {\n FillFormVisionToolResult,\n ModelOutputContentItem,\n Variables,\n} from \"../../types/public/agent.js\";\nimport { processCoordinates } from \"../utils/coordinateNormalization.js\";\nimport { ensureXPath } from \"../utils/xpath.js\";\nimport { waitAndCaptureScreenshot } from \"../utils/screenshotHandler.js\";\nimport { substituteVariables } from \"../utils/variables.js\";\n\nexport const fillFormVisionTool = (\n v3: V3,\n provider?: string,\n variables?: Variables,\n) => {\n const hasVariables = variables && Object.keys(variables).length > 0;\n const valueDescription = hasVariables\n ? `Text to type into the target field. Use %variableName% to substitute a variable value. Available: ${Object.keys(variables).join(\", \")}`\n : \"Text to type into the target field\";\n\n return tool({\n description: `FORM FILL - SPECIALIZED MULTI-FIELD INPUT TOOL\n\nCRITICAL: Use this for ANY form with 2+ input fields (text inputs, textareas, etc.)\nIMPORTANT: Ensure the fields are visible within the current viewport\n\nWHY THIS TOOL EXISTS:\n- Forms are the #1 use case for multi-field input\n- Optimized specifically for input/textarea elements\n- 4-6x faster than individual typing actions\n\nUse fillFormVision: Pure form filling (inputs, textareas only)\nMANDATORY USE CASES (always use fillFormVision for these):\n- Registration forms: name, email, password fields\n- Contact forms: name, email, message fields\n- Checkout forms: address, payment info fields\n- Profile updates: multiple user data fields\n- Search filters: multiple criteria inputs`,\n inputSchema: z.object({\n fields: z\n .array(\n z.object({\n action: z\n .string()\n .describe(\n \"Description of the typing action, e.g. 'type foo into the bar field'\",\n ),\n value: z.string().describe(valueDescription),\n coordinates: z\n .object({\n x: z.number(),\n y: z.number(),\n })\n .describe(\"Coordinates of the target field\"),\n }),\n )\n .min(2, \"Provide at least two fields to fill\"),\n }),\n execute: async ({ fields }): Promise<FillFormVisionToolResult> => {\n try {\n const page = await v3.context.awaitActivePage();\n\n // Process coordinates and substitute variables for each field\n // Keep original values (with %tokens%) for logging/caching, substituted values for typing\n const processedFields = fields.map((field) => {\n const processed = processCoordinates(\n field.coordinates.x,\n field.coordinates.y,\n provider,\n v3,\n );\n return {\n ...field,\n originalValue: field.value, // Keep original with %tokens% for cache\n value: substituteVariables(field.value, variables),\n coordinates: { x: processed.x, y: processed.y },\n };\n });\n\n v3.logger({\n category: \"agent\",\n message: `Agent calling tool: fillFormVision`,\n level: 1,\n auxiliary: {\n arguments: {\n value: JSON.stringify({ fields }), // Don't log substituted values\n type: \"object\",\n },\n },\n });\n\n // Only request XPath when caching is enabled to avoid unnecessary computation\n const shouldCollectXpath = v3.isAgentReplayActive();\n const actions: Action[] = [];\n\n for (const field of processedFields) {\n // Click the field, only requesting XPath when caching is enabled\n const xpath = await page.click(\n field.coordinates.x,\n field.coordinates.y,\n {\n returnXpath: shouldCollectXpath,\n },\n );\n await page.type(field.value);\n\n // Build Action with XPath for deterministic replay (only when caching)\n // Use originalValue (with %tokens%) so cache stores references, not sensitive values\n if (shouldCollectXpath) {\n const normalizedXpath = ensureXPath(xpath);\n if (normalizedXpath) {\n actions.push({\n selector: normalizedXpath,\n description: field.action,\n method: \"type\",\n arguments: [field.originalValue],\n });\n }\n }\n\n // Small delay between fields\n await new Promise((resolve) => setTimeout(resolve, 100));\n }\n\n const screenshotBase64 = await waitAndCaptureScreenshot(page, 100);\n\n // Record as \"act\" step with proper Actions for deterministic replay (only when caching)\n if (shouldCollectXpath && actions.length > 0) {\n v3.recordAgentReplayStep({\n type: \"act\",\n instruction: `Fill ${fields.length} form fields`,\n actions,\n actionDescription: `Fill ${fields.length} form fields`,\n });\n }\n\n return {\n success: true,\n playwrightArguments: processedFields,\n screenshotBase64,\n };\n } catch (error) {\n return {\n success: false,\n error: `Error filling form: ${(error as Error).message}`,\n };\n }\n },\n toModelOutput: (result) => {\n if (result.success) {\n const content: ModelOutputContentItem[] = [\n {\n type: \"text\",\n text: JSON.stringify({\n success: result.success,\n fieldsCount: result.playwrightArguments?.length ?? 0,\n }),\n },\n ];\n if (result.screenshotBase64) {\n content.push({\n type: \"media\",\n mediaType: \"image/png\",\n data: result.screenshotBase64,\n });\n }\n return { type: \"content\", value: content };\n }\n return {\n type: \"content\",\n value: [\n {\n type: \"text\",\n text: JSON.stringify({\n success: result.success,\n error: result.error,\n }),\n },\n ],\n };\n },\n });\n};\n"]}
1
+ {"version":3,"file":"fillFormVision.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/tools/fillFormVision.ts"],"names":[],"mappings":";;;AAAA,2BAA0B;AAC1B,6BAAwB;AAQxB,oFAAyE;AACzE,gDAAgD;AAChD,wEAAyE;AACzE,wDAA4D;AAErD,MAAM,kBAAkB,GAAG,CAChC,EAAM,EACN,QAAiB,EACjB,SAAqB,EACrB,EAAE;IACF,MAAM,YAAY,GAAG,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM,GAA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AED,MAAM,OAAO,GAA6B;gBACxC;oBACE,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;wBACnB,OAAO,EAAE,MAAM,CAAC,OAAO;wBACvB,WAAW,EAAE,MAAM,CAAC,mBAAmB,EAAE,MAAM,IAAI,CAAC;qBACrD,CAAC;iBACH;aACF,CAAC;YACF,IAAI,MAAM,CAAC,gBAAgB,EAAE,CAAC;gBAC5B,OAAO,CAAC,IAAI,CAAC;oBACX,IAAI,EAAE,OAAO;oBACb,SAAS,EAAE,WAAW;oBACtB,IAAI,EAAE,MAAM,CAAC,gBAAgB;iBAC9B,CAAC,CAAC;YACL,CAAC;YACD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;QAC7C,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC;AA7KW,QAAA,kBAAkB,sBA6K7B","sourcesContent":["import { tool } from \"ai\";\nimport { z } from \"zod\";\nimport type { V3 } from \"../../v3.js\";\nimport type { Action } from \"../../types/public/methods.js\";\nimport type {\n FillFormVisionToolResult,\n ModelOutputContentItem,\n Variables,\n} from \"../../types/public/agent.js\";\nimport { processCoordinates } from \"../utils/coordinateNormalization.js\";\nimport { ensureXPath } from \"../utils/xpath.js\";\nimport { waitAndCaptureScreenshot } from \"../utils/screenshotHandler.js\";\nimport { substituteVariables } from \"../utils/variables.js\";\n\nexport const fillFormVisionTool = (\n v3: V3,\n provider?: string,\n variables?: Variables,\n) => {\n const hasVariables = variables && Object.keys(variables).length > 0;\n const valueDescription = hasVariables\n ? `Text to type into the target field. Use %variableName% to substitute a variable value. Available: ${Object.keys(variables).join(\", \")}`\n : \"Text to type into the target field\";\n\n return tool({\n description: `FORM FILL - SPECIALIZED MULTI-FIELD INPUT TOOL\n\nCRITICAL: Use this for ANY form with 2+ input fields (text inputs, textareas, etc.)\nIMPORTANT: Ensure the fields are visible within the current viewport\n\nWHY THIS TOOL EXISTS:\n- Forms are the #1 use case for multi-field input\n- Optimized specifically for input/textarea elements\n- 4-6x faster than individual typing actions\n\nUse fillFormVision: Pure form filling (inputs, textareas only)\nMANDATORY USE CASES (always use fillFormVision for these):\n- Registration forms: name, email, password fields\n- Contact forms: name, email, message fields\n- Checkout forms: address, payment info fields\n- Profile updates: multiple user data fields\n- Search filters: multiple criteria inputs`,\n inputSchema: z.object({\n fields: z\n .array(\n z.object({\n action: z\n .string()\n .describe(\n \"Description of the typing action, e.g. 'type foo into the bar field'\",\n ),\n value: z.string().describe(valueDescription),\n coordinates: z\n .object({\n x: z.number(),\n y: z.number(),\n })\n .describe(\"Coordinates of the target field\"),\n }),\n )\n .min(2, \"Provide at least two fields to fill\"),\n }),\n execute: async ({ fields }): Promise<FillFormVisionToolResult> => {\n try {\n const page = await v3.context.awaitActivePage();\n\n // Process coordinates and substitute variables for each field\n // Keep original values (with %tokens%) for logging/caching, substituted values for typing\n const processedFields = fields.map((field) => {\n const processed = processCoordinates(\n field.coordinates.x,\n field.coordinates.y,\n provider,\n v3,\n );\n return {\n ...field,\n originalValue: field.value, // Keep original with %tokens% for cache\n value: substituteVariables(field.value, variables),\n coordinates: { x: processed.x, y: processed.y },\n };\n });\n\n v3.logger({\n category: \"agent\",\n message: `Agent calling tool: fillFormVision`,\n level: 1,\n auxiliary: {\n arguments: {\n value: JSON.stringify({ fields }), // Don't log substituted values\n type: \"object\",\n },\n },\n });\n\n // Only request XPath when caching is enabled to avoid unnecessary computation\n const shouldCollectXpath = v3.isAgentReplayActive();\n const actions: Action[] = [];\n\n for (const field of processedFields) {\n // Click the field, only requesting XPath when caching is enabled\n const xpath = await page.click(\n field.coordinates.x,\n field.coordinates.y,\n {\n returnXpath: shouldCollectXpath,\n },\n );\n await page.type(field.value);\n\n // Build Action with XPath for deterministic replay (only when caching)\n // Use originalValue (with %tokens%) so cache stores references, not sensitive values\n if (shouldCollectXpath) {\n const normalizedXpath = ensureXPath(xpath);\n if (normalizedXpath) {\n actions.push({\n selector: normalizedXpath,\n description: field.action,\n method: \"type\",\n arguments: [field.originalValue],\n });\n }\n }\n\n // Small delay between fields\n await new Promise((resolve) => setTimeout(resolve, 100));\n }\n\n const screenshotBase64 = await waitAndCaptureScreenshot(page, 100);\n\n // Record as \"act\" step with proper Actions for deterministic replay (only when caching)\n if (shouldCollectXpath && actions.length > 0) {\n v3.recordAgentReplayStep({\n type: \"act\",\n instruction: `Fill ${fields.length} form fields`,\n actions,\n actionDescription: `Fill ${fields.length} form fields`,\n });\n }\n\n return {\n success: true,\n playwrightArguments: processedFields,\n screenshotBase64,\n };\n } catch (error) {\n return {\n success: false,\n error: `Error filling form: ${(error as Error).message}`,\n };\n }\n },\n toModelOutput: (result) => {\n if (result.success === false || result.error !== undefined) {\n return {\n type: \"content\",\n value: [\n {\n type: \"text\",\n text: JSON.stringify({\n success: result.success,\n error: result.error,\n }),\n },\n ],\n };\n }\n\n const content: ModelOutputContentItem[] = [\n {\n type: \"text\",\n text: JSON.stringify({\n success: result.success,\n fieldsCount: result.playwrightArguments?.length ?? 0,\n }),\n },\n ];\n if (result.screenshotBase64) {\n content.push({\n type: \"media\",\n mediaType: \"image/png\",\n data: result.screenshotBase64,\n });\n }\n return { type: \"content\", value: content };\n },\n });\n};\n"]}
@@ -1,7 +1,7 @@
1
1
  import type { V3 } from "../../v3.js";
2
2
  import type { Action } from "../../types/public/methods.js";
3
3
  import type { AgentModelConfig, Variables } from "../../types/public/agent.js";
4
- export declare const fillFormTool: (v3: V3, executionModel?: string | AgentModelConfig, variables?: Variables) => import("ai").Tool<{
4
+ export declare const fillFormTool: (v3: V3, executionModel?: string | AgentModelConfig, variables?: Variables, toolTimeout?: number) => import("ai").Tool<{
5
5
  fields: {
6
6
  action: string;
7
7
  value: string;
@@ -10,4 +10,10 @@ export declare const fillFormTool: (v3: V3, executionModel?: string | AgentModel
10
10
  success: boolean;
11
11
  actions: unknown[];
12
12
  playwrightArguments: Action[];
13
+ error?: undefined;
14
+ } | {
15
+ success: boolean;
16
+ error: any;
17
+ actions?: undefined;
18
+ playwrightArguments?: undefined;
13
19
  }>;
@@ -3,7 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fillFormTool = void 0;
4
4
  const ai_1 = require("ai");
5
5
  const zod_1 = require("zod");
6
- const fillFormTool = (v3, executionModel, variables) => {
6
+ const sdkErrors_js_1 = require("../../types/public/sdkErrors.js");
7
+ const fillFormTool = (v3, executionModel, variables, toolTimeout) => {
7
8
  const hasVariables = variables && Object.keys(variables).length > 0;
8
9
  const valueDescription = hasVariables
9
10
  ? `Text to type into the target. Use %variableName% to substitute a variable value. Available: ${Object.keys(variables).join(", ")}`
@@ -21,45 +22,67 @@ const fillFormTool = (v3, executionModel, variables) => {
21
22
  .min(1, "Provide at least one field to fill"),
22
23
  }),
23
24
  execute: async ({ fields }) => {
24
- v3.logger({
25
- category: "agent",
26
- message: `Agent calling tool: fillForm`,
27
- level: 1,
28
- auxiliary: {
29
- arguments: {
30
- value: JSON.stringify(fields),
31
- type: "object",
25
+ try {
26
+ v3.logger({
27
+ category: "agent",
28
+ message: `Agent calling tool: fillForm`,
29
+ level: 1,
30
+ auxiliary: {
31
+ arguments: {
32
+ value: JSON.stringify(fields),
33
+ type: "object",
34
+ },
32
35
  },
33
- },
34
- });
35
- const instruction = `Return observation results for the following actions: ${fields
36
- .map((f) => f.action)
37
- .join(", ")}`;
38
- const observeOptions = executionModel
39
- ? { model: executionModel }
40
- : undefined;
41
- const observeResults = await v3.observe(instruction, observeOptions);
42
- const completed = [];
43
- const replayableActions = [];
44
- for (const res of observeResults) {
45
- const actOptions = variables ? { variables } : undefined;
46
- const actResult = await v3.act(res, actOptions);
47
- completed.push(actResult);
48
- if (Array.isArray(actResult.actions)) {
49
- replayableActions.push(...actResult.actions);
36
+ });
37
+ const instruction = `Return observation results for the following actions: ${fields
38
+ .map((f) => f.action)
39
+ .join(", ")}`;
40
+ const observeOptions = executionModel
41
+ ? { model: executionModel, timeout: toolTimeout }
42
+ : { timeout: toolTimeout };
43
+ const observeResults = await v3.observe(instruction, observeOptions);
44
+ const completed = [];
45
+ const replayableActions = [];
46
+ for (const res of observeResults) {
47
+ const actOptions = variables
48
+ ? { variables, timeout: toolTimeout }
49
+ : { timeout: toolTimeout };
50
+ const actResult = await v3.act(res, actOptions);
51
+ completed.push(actResult);
52
+ if (Array.isArray(actResult.actions)) {
53
+ replayableActions.push(...actResult.actions);
54
+ }
50
55
  }
56
+ v3.recordAgentReplayStep({
57
+ type: "fillForm",
58
+ fields,
59
+ observeResults,
60
+ actions: replayableActions,
61
+ });
62
+ return {
63
+ success: true,
64
+ actions: completed,
65
+ playwrightArguments: replayableActions,
66
+ };
67
+ }
68
+ catch (error) {
69
+ if (error instanceof sdkErrors_js_1.TimeoutError) {
70
+ const timeoutMessage = `TimeoutError while waiting for fillForm() to complete (it may continue executing in the background)`;
71
+ v3.logger({
72
+ category: "agent",
73
+ message: timeoutMessage,
74
+ level: 0,
75
+ });
76
+ return {
77
+ success: false,
78
+ error: `${timeoutMessage} — try filling fewer fields at once or use a different tool`,
79
+ };
80
+ }
81
+ return {
82
+ success: false,
83
+ error: error?.message ?? String(error),
84
+ };
51
85
  }
52
- v3.recordAgentReplayStep({
53
- type: "fillForm",
54
- fields,
55
- observeResults,
56
- actions: replayableActions,
57
- });
58
- return {
59
- success: true,
60
- actions: completed,
61
- playwrightArguments: replayableActions,
62
- };
63
86
  },
64
87
  });
65
88
  };
@@ -1 +1 @@
1
- {"version":3,"file":"fillform.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/tools/fillform.ts"],"names":[],"mappings":";;;AAAA,2BAA0B;AAC1B,6BAAwB;AAKjB,MAAM,YAAY,GAAG,CAC1B,EAAM,EACN,cAA0C,EAC1C,SAAqB,EACrB,EAAE;IACF,MAAM,YAAY,GAAG,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IACpE,MAAM,gBAAgB,GAAG,YAAY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AAM,iBAAiB,GAAa,EAAE,CAAC;YACvC,KAAK,MAAM,GAAG,IAAI,cAAc,EAAE,CAAC;gBACjC,MAAM,UAAU,GAAG,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;gBACzD,MAAM,SAAS,GAAG,MAAM,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;gBAChD,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;gBAC1B,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;oBACrC,iBAAiB,CAAC,IAAI,CAAC,GAAI,SAAS,CAAC,OAAoB,CAAC,CAAC;gBAC7D,CAAC;YACH,CAAC;YACD,EAAE,CAAC,qBAAqB,CAAC;gBACvB,IAAI,EAAE,UAAU;gBAChB,MAAM;gBACN,cAAc;gBACd,OAAO,EAAE,iBAAiB;aAC3B,CAAC,CAAC;YACH,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,OAAO,EAAE,SAAS;gBAClB,mBAAmB,EAAE,iBAAiB;aACvC,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC;AAtEW,QAAA,YAAY,gBAsEvB","sourcesContent":["import { tool } from \"ai\";\nimport { z } from \"zod\";\nimport type { V3 } from \"../../v3.js\";\nimport type { Action } from \"../../types/public/methods.js\";\nimport type { AgentModelConfig, Variables } from \"../../types/public/agent.js\";\n\nexport const fillFormTool = (\n v3: V3,\n executionModel?: string | AgentModelConfig,\n variables?: Variables,\n) => {\n const hasVariables = variables && Object.keys(variables).length > 0;\n const valueDescription = hasVariables\n ? `Text to type into the target. Use %variableName% to substitute a variable value. Available: ${Object.keys(variables).join(\", \")}`\n : \"Text to type into the target\";\n\n return tool({\n description: `📝 FORM FILL - MULTI-FIELD INPUT TOOL\\nFor any form with 2+ inputs/textareas. Faster than individual typing.`,\n inputSchema: z.object({\n fields: z\n .array(\n z.object({\n action: z\n .string()\n .describe(\n 'Description of typing action, e.g. \"type foo into the email field\"',\n ),\n value: z.string().describe(valueDescription),\n }),\n )\n .min(1, \"Provide at least one field to fill\"),\n }),\n execute: async ({ fields }) => {\n v3.logger({\n category: \"agent\",\n message: `Agent calling tool: fillForm`,\n level: 1,\n auxiliary: {\n arguments: {\n value: JSON.stringify(fields),\n type: \"object\",\n },\n },\n });\n const instruction = `Return observation results for the following actions: ${fields\n .map((f) => f.action)\n .join(\", \")}`;\n\n const observeOptions = executionModel\n ? { model: executionModel }\n : undefined;\n const observeResults = await v3.observe(instruction, observeOptions);\n\n const completed = [] as unknown[];\n const replayableActions: Action[] = [];\n for (const res of observeResults) {\n const actOptions = variables ? { variables } : undefined;\n const actResult = await v3.act(res, actOptions);\n completed.push(actResult);\n if (Array.isArray(actResult.actions)) {\n replayableActions.push(...(actResult.actions as Action[]));\n }\n }\n v3.recordAgentReplayStep({\n type: \"fillForm\",\n fields,\n observeResults,\n actions: replayableActions,\n });\n return {\n success: true,\n actions: completed,\n playwrightArguments: replayableActions,\n };\n },\n });\n};\n"]}
1
+ {"version":3,"file":"fillform.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/tools/fillform.ts"],"names":[],"mappings":";;;AAAA,2BAA0B;AAC1B,6BAAwB;AAIxB,kEAA+D;AAExD,MAAM,YAAY,GAAG,CAC1B,EAAM,EACN,cAA0C,EAC1C,SAAqB,EACrB,WAAoB,EACpB,EAAE;IACF,MAAM,YAAY,GAAG,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IACpE,MAAM,gBAAgB,GAAG,YAAY;QACnC,CAAC,CAAC,+FAA+F,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QACpI,CAAC,CAAC,8BAA8B,CAAC;IAEnC,OAAO,IAAA,SAAI,EAAC;QACV,WAAW,EAAE,8GAA8G;QAC3H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port { z } from \"zod\";\nimport type { V3 } from \"../../v3.js\";\nimport type { Action } from \"../../types/public/methods.js\";\nimport type { AgentModelConfig, Variables } from \"../../types/public/agent.js\";\nimport { TimeoutError } from \"../../types/public/sdkErrors.js\";\n\nexport const fillFormTool = (\n v3: V3,\n executionModel?: string | AgentModelConfig,\n variables?: Variables,\n toolTimeout?: number,\n) => {\n const hasVariables = variables && Object.keys(variables).length > 0;\n const valueDescription = hasVariables\n ? `Text to type into the target. Use %variableName% to substitute a variable value. Available: ${Object.keys(variables).join(\", \")}`\n : \"Text to type into the target\";\n\n return tool({\n description: `📝 FORM FILL - MULTI-FIELD INPUT TOOL\\nFor any form with 2+ inputs/textareas. Faster than individual typing.`,\n inputSchema: z.object({\n fields: z\n .array(\n z.object({\n action: z\n .string()\n .describe(\n 'Description of typing action, e.g. \"type foo into the email field\"',\n ),\n value: z.string().describe(valueDescription),\n }),\n )\n .min(1, \"Provide at least one field to fill\"),\n }),\n execute: async ({ fields }) => {\n try {\n v3.logger({\n category: \"agent\",\n message: `Agent calling tool: fillForm`,\n level: 1,\n auxiliary: {\n arguments: {\n value: JSON.stringify(fields),\n type: \"object\",\n },\n },\n });\n const instruction = `Return observation results for the following actions: ${fields\n .map((f) => f.action)\n .join(\", \")}`;\n\n const observeOptions = executionModel\n ? { model: executionModel, timeout: toolTimeout }\n : { timeout: toolTimeout };\n const observeResults = await v3.observe(instruction, observeOptions);\n\n const completed = [] as unknown[];\n const replayableActions: Action[] = [];\n for (const res of observeResults) {\n const actOptions = variables\n ? { variables, timeout: toolTimeout }\n : { timeout: toolTimeout };\n const actResult = await v3.act(res, actOptions);\n completed.push(actResult);\n if (Array.isArray(actResult.actions)) {\n replayableActions.push(...(actResult.actions as Action[]));\n }\n }\n v3.recordAgentReplayStep({\n type: \"fillForm\",\n fields,\n observeResults,\n actions: replayableActions,\n });\n return {\n success: true,\n actions: completed,\n playwrightArguments: replayableActions,\n };\n } catch (error) {\n if (error instanceof TimeoutError) {\n const timeoutMessage = `TimeoutError while waiting for fillForm() to complete (it may continue executing in the background)`;\n v3.logger({\n category: \"agent\",\n message: timeoutMessage,\n level: 0,\n });\n return {\n success: false,\n error: `${timeoutMessage} — try filling fewer fields at once or use a different tool`,\n };\n }\n return {\n success: false,\n error: error?.message ?? String(error),\n };\n }\n },\n });\n};\n"]}
@@ -42,6 +42,11 @@ export interface V3AgentToolOptions {
42
42
  * When provided, these tools will have an optional useVariable field.
43
43
  */
44
44
  variables?: Variables;
45
+ /**
46
+ * Timeout in milliseconds for tool calls that invoke v3 methods (act, extract, fillForm, ariaTree).
47
+ * Forwarded to the underlying v3 call's `timeout` option.
48
+ */
49
+ toolTimeout?: number;
45
50
  }
46
51
  export declare function createAgentTools(v3: V3, options?: V3AgentToolOptions): ToolSet;
47
52
  export type AgentTools = ReturnType<typeof createAgentTools>;
@@ -51,14 +51,15 @@ function createAgentTools(v3, options) {
51
51
  const provider = options?.provider;
52
52
  const excludeTools = options?.excludeTools;
53
53
  const variables = options?.variables;
54
+ const toolTimeout = options?.toolTimeout;
54
55
  const allTools = {
55
- act: (0, act_js_1.actTool)(v3, executionModel, variables),
56
- ariaTree: (0, ariaTree_js_1.ariaTreeTool)(v3),
56
+ act: (0, act_js_1.actTool)(v3, executionModel, variables, toolTimeout),
57
+ ariaTree: (0, ariaTree_js_1.ariaTreeTool)(v3, toolTimeout),
57
58
  click: (0, click_js_1.clickTool)(v3, provider),
58
59
  clickAndHold: (0, clickAndHold_js_1.clickAndHoldTool)(v3, provider),
59
60
  dragAndDrop: (0, dragAndDrop_js_1.dragAndDropTool)(v3, provider),
60
- extract: (0, extract_js_1.extractTool)(v3, executionModel),
61
- fillForm: (0, fillform_js_1.fillFormTool)(v3, executionModel, variables),
61
+ extract: (0, extract_js_1.extractTool)(v3, executionModel, toolTimeout),
62
+ fillForm: (0, fillform_js_1.fillFormTool)(v3, executionModel, variables, toolTimeout),
62
63
  fillFormVision: (0, fillFormVision_js_1.fillFormVisionTool)(v3, provider, variables),
63
64
  goto: (0, goto_js_1.gotoTool)(v3),
64
65
  keys: (0, keys_js_1.keysTool)(v3),
@@ -69,7 +70,6 @@ function createAgentTools(v3, options) {
69
70
  type: (0, type_js_1.typeTool)(v3, provider, variables),
70
71
  wait: (0, wait_js_1.waitTool)(v3, mode),
71
72
  };
72
- // Only include search tool if BRAVE_API_KEY is configured
73
73
  if (process.env.BRAVE_API_KEY) {
74
74
  allTools.search = (0, search_js_1.searchTool)(v3);
75
75
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/tools/index.ts"],"names":[],"mappings":";;AAsFA,4CAgCC;AAtHD,uCAAqC;AACrC,qCAAmC;AACnC,mDAAiD;AACjD,uCAAqC;AACrC,6CAA2C;AAC3C,+CAA6C;AAC7C,+CAA6C;AAC7C,2CAA2D;AAC3D,6CAA2C;AAC3C,yCAAuC;AACvC,uCAAqC;AACrC,qDAAmD;AACnD,uDAAqD;AACrD,uCAAqC;AACrC,2DAAyD;AACzD,yCAAuC;AACvC,2CAAyC;AAoCzC;;;;;GAKG;AACH,SAAS,WAAW,CAClB,KAAc,EACd,IAAmB,EACnB,YAAuB;IAEvB,MAAM,QAAQ,GAAY,EAAE,GAAG,KAAK,EAAE,CAAC;IAEvC,uBAAuB;IACvB,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;QACtB,OAAO,QAAQ,CAAC,QAAQ,CAAC;IAC3B,CAAC;SAAM,CAAC;QACN,qBAAqB;QACrB,OAAO,QAAQ,CAAC,KAAK,CAAC;QACtB,OAAO,QAAQ,CAAC,IAAI,CAAC;QACrB,OAAO,QAAQ,CAAC,WAAW,CAAC;QAC5B,OAAO,QAAQ,CAAC,YAAY,CAAC;QAC7B,OAAO,QAAQ,CAAC,cAAc,CAAC;IACjC,CAAC;IAED,IAAI,YAAY,EAAE,CAAC;QACjB,KAAK,MAAM,QAAQ,IAAI,YAAY,EAAE,CAAC;YACpC,OAAO,QAAQ,CAAC,QAAQ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AAC,CAAC,CAAC,CAAC,IAAA,sBAAU,EAAC,EAAE,CAAC;QAC3E,KAAK,EAAE,IAAA,oBAAS,GAAE;QAClB,IAAI,EAAE,IAAA,kBAAQ,EAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,CAAC;QACvC,IAAI,EAAE,IAAA,kBAAQ,EAAC,EAAE,EAAE,IAAI,CAAC;KACzB,CAAC;IAEF,0DAA0D;IAC1D,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC;QAC9B,QAAQ,CAAC,MAAM,GAAG,IAAA,sBAAU,EAAC,EAAE,CAAC,CAAC;IACnC,CAAC;IAED,OAAO,WAAW,CAAC,QAAQ,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;AACnD,CAAC","sourcesContent":["import { gotoTool } from \"./goto.js\";\nimport { actTool } from \"./act.js\";\nimport { screenshotTool } from \"./screenshot.js\";\nimport { waitTool } from \"./wait.js\";\nimport { navBackTool } from \"./navback.js\";\nimport { ariaTreeTool } from \"./ariaTree.js\";\nimport { fillFormTool } from \"./fillform.js\";\nimport { scrollTool, scrollVisionTool } from \"./scroll.js\";\nimport { extractTool } from \"./extract.js\";\nimport { clickTool } from \"./click.js\";\nimport { typeTool } from \"./type.js\";\nimport { dragAndDropTool } from \"./dragAndDrop.js\";\nimport { clickAndHoldTool } from \"./clickAndHold.js\";\nimport { keysTool } from \"./keys.js\";\nimport { fillFormVisionTool } from \"./fillFormVision.js\";\nimport { thinkTool } from \"./think.js\";\nimport { searchTool } from \"./search.js\";\n\nimport type { ToolSet, InferUITools } from \"ai\";\nimport type { V3 } from \"../../v3.js\";\nimport type { LogLine } from \"../../types/public/logs.js\";\nimport type {\n AgentToolMode,\n AgentModelConfig,\n Variables,\n} from \"../../types/public/agent.js\";\n\nexport interface V3AgentToolOptions {\n executionModel?: string | AgentModelConfig;\n logger?: (message: LogLine) => void;\n /**\n * Tool mode determines which set of tools are available.\n * - 'dom' (default): Uses DOM-based tools (act, fillForm) - removes coordinate-based tools\n * - 'hybrid': Uses coordinate-based tools (click, type, dragAndDrop, etc.) - removes fillForm\n */\n mode?: AgentToolMode;\n /**\n * The model provider. Used for model-specific coordinate handling\n */\n provider?: string;\n /**\n * Tools to exclude from the available toolset.\n * These tools will be filtered out after mode-based filtering.\n */\n excludeTools?: string[];\n /**\n * Variables available to the agent for use in act/type tools.\n * When provided, these tools will have an optional useVariable field.\n */\n variables?: Variables;\n}\n\n/**\n * Filters tools based on mode and explicit exclusions.\n * - 'dom' mode: Removes coordinate-based tools (click, type, dragAndDrop, clickAndHold, fillFormVision)\n * - 'hybrid' mode: Removes DOM-based form tool (fillForm) in favor of coordinate-based fillFormVision\n * - excludeTools: Additional tools to remove from the toolset\n */\nfunction filterTools(\n tools: ToolSet,\n mode: AgentToolMode,\n excludeTools?: string[],\n): ToolSet {\n const filtered: ToolSet = { ...tools };\n\n // Mode-based filtering\n if (mode === \"hybrid\") {\n delete filtered.fillForm;\n } else {\n // DOM mode (default)\n delete filtered.click;\n delete filtered.type;\n delete filtered.dragAndDrop;\n delete filtered.clickAndHold;\n delete filtered.fillFormVision;\n }\n\n if (excludeTools) {\n for (const toolName of excludeTools) {\n delete filtered[toolName];\n }\n }\n\n return filtered;\n}\n\nexport function createAgentTools(v3: V3, options?: V3AgentToolOptions) {\n const executionModel = options?.executionModel;\n const mode = options?.mode ?? \"dom\";\n const provider = options?.provider;\n const excludeTools = options?.excludeTools;\n const variables = options?.variables;\n\n const allTools: ToolSet = {\n act: actTool(v3, executionModel, variables),\n ariaTree: ariaTreeTool(v3),\n click: clickTool(v3, provider),\n clickAndHold: clickAndHoldTool(v3, provider),\n dragAndDrop: dragAndDropTool(v3, provider),\n extract: extractTool(v3, executionModel),\n fillForm: fillFormTool(v3, executionModel, variables),\n fillFormVision: fillFormVisionTool(v3, provider, variables),\n goto: gotoTool(v3),\n keys: keysTool(v3),\n navback: navBackTool(v3),\n screenshot: screenshotTool(v3),\n scroll: mode === \"hybrid\" ? scrollVisionTool(v3, provider) : scrollTool(v3),\n think: thinkTool(),\n type: typeTool(v3, provider, variables),\n wait: waitTool(v3, mode),\n };\n\n // Only include search tool if BRAVE_API_KEY is configured\n if (process.env.BRAVE_API_KEY) {\n allTools.search = searchTool(v3);\n }\n\n return filterTools(allTools, mode, excludeTools);\n}\n\nexport type AgentTools = ReturnType<typeof createAgentTools>;\n\n/**\n * Type map of all agent tools for strong typing of tool calls and results.\n * Note: `search` is optional as it's only available when BRAVE_API_KEY is configured.\n */\nexport type AgentToolTypesMap = {\n act: ReturnType<typeof actTool>;\n ariaTree: ReturnType<typeof ariaTreeTool>;\n click: ReturnType<typeof clickTool>;\n clickAndHold: ReturnType<typeof clickAndHoldTool>;\n dragAndDrop: ReturnType<typeof dragAndDropTool>;\n extract: ReturnType<typeof extractTool>;\n fillForm: ReturnType<typeof fillFormTool>;\n fillFormVision: ReturnType<typeof fillFormVisionTool>;\n goto: ReturnType<typeof gotoTool>;\n keys: ReturnType<typeof keysTool>;\n navback: ReturnType<typeof navBackTool>;\n screenshot: ReturnType<typeof screenshotTool>;\n scroll: ReturnType<typeof scrollTool> | ReturnType<typeof scrollVisionTool>;\n search?: ReturnType<typeof searchTool>;\n think: ReturnType<typeof thinkTool>;\n type: ReturnType<typeof typeTool>;\n wait: ReturnType<typeof waitTool>;\n};\n\n/**\n * Inferred UI tools type for type-safe tool inputs and outputs.\n * Use with UIMessage for full type safety in UI contexts.\n */\nexport type AgentUITools = InferUITools<AgentToolTypesMap>;\n\n/**\n * Union type for all possible agent tool calls.\n * Provides type-safe access to tool call arguments.\n */\nexport type AgentToolCall = {\n [K in keyof AgentToolTypesMap]: {\n toolName: K;\n toolCallId: string;\n args: AgentUITools[K][\"input\"];\n };\n}[keyof AgentToolTypesMap];\n\n/**\n * Union type for all possible agent tool results.\n * Provides type-safe access to tool result values.\n */\nexport type AgentToolResult = {\n [K in keyof AgentToolTypesMap]: {\n toolName: K;\n toolCallId: string;\n result: AgentUITools[K][\"output\"];\n };\n}[keyof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kBAAQ,EAAC,EAAE,EAAE,IAAI,CAAC;KACzB,CAAC;IAEF,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC;QAC9B,QAAQ,CAAC,MAAM,GAAG,IAAA,sBAAU,EAAC,EAAE,CAAC,CAAC;IACnC,CAAC;IAED,OAAO,WAAW,CAAC,QAAQ,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;AACnD,CAAC","sourcesContent":["import { gotoTool } from \"./goto.js\";\nimport { actTool } from \"./act.js\";\nimport { screenshotTool } from \"./screenshot.js\";\nimport { waitTool } from \"./wait.js\";\nimport { navBackTool } from \"./navback.js\";\nimport { ariaTreeTool } from \"./ariaTree.js\";\nimport { fillFormTool } from \"./fillform.js\";\nimport { scrollTool, scrollVisionTool } from \"./scroll.js\";\nimport { extractTool } from \"./extract.js\";\nimport { clickTool } from \"./click.js\";\nimport { typeTool } from \"./type.js\";\nimport { dragAndDropTool } from \"./dragAndDrop.js\";\nimport { clickAndHoldTool } from \"./clickAndHold.js\";\nimport { keysTool } from \"./keys.js\";\nimport { fillFormVisionTool } from \"./fillFormVision.js\";\nimport { thinkTool } from \"./think.js\";\nimport { searchTool } from \"./search.js\";\n\nimport type { ToolSet, InferUITools } from \"ai\";\nimport type { V3 } from \"../../v3.js\";\nimport type { LogLine } from \"../../types/public/logs.js\";\nimport type {\n AgentToolMode,\n AgentModelConfig,\n Variables,\n} from \"../../types/public/agent.js\";\n\nexport interface V3AgentToolOptions {\n executionModel?: string | AgentModelConfig;\n logger?: (message: LogLine) => void;\n /**\n * Tool mode determines which set of tools are available.\n * - 'dom' (default): Uses DOM-based tools (act, fillForm) - removes coordinate-based tools\n * - 'hybrid': Uses coordinate-based tools (click, type, dragAndDrop, etc.) - removes fillForm\n */\n mode?: AgentToolMode;\n /**\n * The model provider. Used for model-specific coordinate handling\n */\n provider?: string;\n /**\n * Tools to exclude from the available toolset.\n * These tools will be filtered out after mode-based filtering.\n */\n excludeTools?: string[];\n /**\n * Variables available to the agent for use in act/type tools.\n * When provided, these tools will have an optional useVariable field.\n */\n variables?: Variables;\n /**\n * Timeout in milliseconds for tool calls that invoke v3 methods (act, extract, fillForm, ariaTree).\n * Forwarded to the underlying v3 call's `timeout` option.\n */\n toolTimeout?: number;\n}\n\n/**\n * Filters tools based on mode and explicit exclusions.\n * - 'dom' mode: Removes coordinate-based tools (click, type, dragAndDrop, clickAndHold, fillFormVision)\n * - 'hybrid' mode: Removes DOM-based form tool (fillForm) in favor of coordinate-based fillFormVision\n * - excludeTools: Additional tools to remove from the toolset\n */\nfunction filterTools(\n tools: ToolSet,\n mode: AgentToolMode,\n excludeTools?: string[],\n): ToolSet {\n const filtered: ToolSet = { ...tools };\n\n // Mode-based filtering\n if (mode === \"hybrid\") {\n delete filtered.fillForm;\n } else {\n // DOM mode (default)\n delete filtered.click;\n delete filtered.type;\n delete filtered.dragAndDrop;\n delete filtered.clickAndHold;\n delete filtered.fillFormVision;\n }\n\n if (excludeTools) {\n for (const toolName of excludeTools) {\n delete filtered[toolName];\n }\n }\n\n return filtered;\n}\n\nexport function createAgentTools(v3: V3, options?: V3AgentToolOptions) {\n const executionModel = options?.executionModel;\n const mode = options?.mode ?? \"dom\";\n const provider = options?.provider;\n const excludeTools = options?.excludeTools;\n const variables = options?.variables;\n const toolTimeout = options?.toolTimeout;\n\n const allTools: ToolSet = {\n act: actTool(v3, executionModel, variables, toolTimeout),\n ariaTree: ariaTreeTool(v3, toolTimeout),\n click: clickTool(v3, provider),\n clickAndHold: clickAndHoldTool(v3, provider),\n dragAndDrop: dragAndDropTool(v3, provider),\n extract: extractTool(v3, executionModel, toolTimeout),\n fillForm: fillFormTool(v3, executionModel, variables, toolTimeout),\n fillFormVision: fillFormVisionTool(v3, provider, variables),\n goto: gotoTool(v3),\n keys: keysTool(v3),\n navback: navBackTool(v3),\n screenshot: screenshotTool(v3),\n scroll: mode === \"hybrid\" ? scrollVisionTool(v3, provider) : scrollTool(v3),\n think: thinkTool(),\n type: typeTool(v3, provider, variables),\n wait: waitTool(v3, mode),\n };\n\n if (process.env.BRAVE_API_KEY) {\n allTools.search = searchTool(v3);\n }\n\n return filterTools(allTools, mode, excludeTools);\n}\n\nexport type AgentTools = ReturnType<typeof createAgentTools>;\n\n/**\n * Type map of all agent tools for strong typing of tool calls and results.\n * Note: `search` is optional as it's only available when BRAVE_API_KEY is configured.\n */\nexport type AgentToolTypesMap = {\n act: ReturnType<typeof actTool>;\n ariaTree: ReturnType<typeof ariaTreeTool>;\n click: ReturnType<typeof clickTool>;\n clickAndHold: ReturnType<typeof clickAndHoldTool>;\n dragAndDrop: ReturnType<typeof dragAndDropTool>;\n extract: ReturnType<typeof extractTool>;\n fillForm: ReturnType<typeof fillFormTool>;\n fillFormVision: ReturnType<typeof fillFormVisionTool>;\n goto: ReturnType<typeof gotoTool>;\n keys: ReturnType<typeof keysTool>;\n navback: ReturnType<typeof navBackTool>;\n screenshot: ReturnType<typeof screenshotTool>;\n scroll: ReturnType<typeof scrollTool> | ReturnType<typeof scrollVisionTool>;\n search?: ReturnType<typeof searchTool>;\n think: ReturnType<typeof thinkTool>;\n type: ReturnType<typeof typeTool>;\n wait: ReturnType<typeof waitTool>;\n};\n\n/**\n * Inferred UI tools type for type-safe tool inputs and outputs.\n * Use with UIMessage for full type safety in UI contexts.\n */\nexport type AgentUITools = InferUITools<AgentToolTypesMap>;\n\n/**\n * Union type for all possible agent tool calls.\n * Provides type-safe access to tool call arguments.\n */\nexport type AgentToolCall = {\n [K in keyof AgentToolTypesMap]: {\n toolName: K;\n toolCallId: string;\n args: AgentUITools[K][\"input\"];\n };\n}[keyof AgentToolTypesMap];\n\n/**\n * Union type for all possible agent tool results.\n * Provides type-safe access to tool result values.\n */\nexport type AgentToolResult = {\n [K in keyof AgentToolTypesMap]: {\n toolName: K;\n toolCallId: string;\n result: AgentUITools[K][\"output\"];\n };\n}[keyof AgentToolTypesMap];\n"]}
@@ -1,6 +1,14 @@
1
1
  import type { V3 } from "../../v3.js";
2
2
  export declare const screenshotTool: (v3: V3) => import("ai").Tool<Record<string, never>, {
3
+ success: boolean;
3
4
  base64: string;
4
5
  timestamp: number;
5
6
  pageUrl: string;
7
+ error?: undefined;
8
+ } | {
9
+ success: boolean;
10
+ error: string;
11
+ base64?: undefined;
12
+ timestamp?: undefined;
13
+ pageUrl?: undefined;
6
14
  }>;
@@ -7,24 +7,41 @@ const screenshotTool = (v3) => (0, ai_1.tool)({
7
7
  description: "Takes a screenshot (PNG) of the current page. Use this to quickly verify page state.",
8
8
  inputSchema: zod_1.z.object({}),
9
9
  execute: async () => {
10
- v3.logger({
11
- category: "agent",
12
- message: `Agent calling tool: screenshot`,
13
- level: 1,
14
- });
15
- const page = await v3.context.awaitActivePage();
16
- const buffer = await page.screenshot({ fullPage: false });
17
- const pageUrl = page.url();
10
+ try {
11
+ v3.logger({
12
+ category: "agent",
13
+ message: `Agent calling tool: screenshot`,
14
+ level: 1,
15
+ });
16
+ const page = await v3.context.awaitActivePage();
17
+ const buffer = await page.screenshot({ fullPage: false });
18
+ const pageUrl = page.url();
19
+ return {
20
+ success: true,
21
+ base64: buffer.toString("base64"),
22
+ timestamp: Date.now(),
23
+ pageUrl,
24
+ };
25
+ }
26
+ catch (error) {
27
+ return {
28
+ success: false,
29
+ error: `Error taking screenshot: ${error.message}`,
30
+ };
31
+ }
32
+ },
33
+ toModelOutput: (result) => {
34
+ if (result.success === false || result.error !== undefined) {
35
+ return {
36
+ type: "content",
37
+ value: [{ type: "text", text: JSON.stringify(result) }],
38
+ };
39
+ }
18
40
  return {
19
- base64: buffer.toString("base64"),
20
- timestamp: Date.now(),
21
- pageUrl,
41
+ type: "content",
42
+ value: [{ type: "media", mediaType: "image/png", data: result.base64 }],
22
43
  };
23
44
  },
24
- toModelOutput: (result) => ({
25
- type: "content",
26
- value: [{ type: "media", mediaType: "image/png", data: result.base64 }],
27
- }),
28
45
  });
29
46
  exports.screenshotTool = screenshotTool;
30
47
  //# sourceMappingURL=screenshot.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"screenshot.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/tools/screenshot.ts"],"names":[],"mappings":";;;AAAA,2BAA0B;AAC1B,6BAAwB;AAGjB,MAAM,cAAc,GAAG,CAAC,EAAM,EAAE,EAAE,CACvC,IAAA,SAAI,EAAC;IACH,WAAW,EACT,sFAAsF;IACxF,WAAW,EAAE,OAAC,CAAC,MAAM,CAAC,EAAE,CAAC;IACzB,OAAO,EAAE,KAAK,IAAI,EAAE;QAClB,EAAE,CAAC,MAAM,CAAC;YACR,QAAQ,EAAE,OAAO;YACjB,OAAO,EAAE,gCAAgC;YACzC,KAAK,EAAE,CAAC;SACT,CAAC,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,eAAe,EAAE,CAAC;QAChD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;QAC1D,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC3B,OAAO;YACL,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC;YACjC,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;YACrB,OAAO;SACR,CAAC;IACJ,CAAC;IACD,aAAa,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAC1B,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC;KACxE,CAAC;CACH,CAAC,CAAC;AAxBQ,QAAA,cAAc,kBAwBtB","sourcesContent":["import { tool } from \"ai\";\nimport { z } from \"zod\";\nimport type { V3 } from \"../../v3.js\";\n\nexport const screenshotTool = (v3: V3) =>\n tool({\n description:\n \"Takes a screenshot (PNG) of the current page. Use this to quickly verify page state.\",\n inputSchema: z.object({}),\n execute: async () => {\n v3.logger({\n category: \"agent\",\n message: `Agent calling tool: screenshot`,\n level: 1,\n });\n const page = await v3.context.awaitActivePage();\n const buffer = await page.screenshot({ fullPage: false });\n const pageUrl = page.url();\n return {\n base64: buffer.toString(\"base64\"),\n timestamp: Date.now(),\n pageUrl,\n };\n },\n toModelOutput: (result) => ({\n type: \"content\",\n value: [{ type: \"media\", mediaType: \"image/png\", data: result.base64 }],\n }),\n });\n"]}
1
+ {"version":3,"file":"screenshot.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/tools/screenshot.ts"],"names":[],"mappings":";;;AAAA,2BAA0B;AAC1B,6BAAwB;AAGjB,MAAM,cAAc,GAAG,CAAC,EAAM,EAAE,EAAE,CACvC,IAAA,SAAI,EAAC;IACH,WAAW,EACT,sFAAsF;IACxF,WAAW,EAAE,OAAC,CAAC,MAAM,CAAC,EAAE,CAAC;IACzB,OAAO,EAAE,KAAK,IAAI,EAAE;QAClB,IAAI,CAAC;YACH,EAAE,CAAC,MAAM,CAAC;gBACR,QAAQ,EAAE,OAAO;gBACjB,OAAO,EAAE,gCAAgC;gBACzC,KAAK,EAAE,CAAC;aACT,CAAC,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,eAAe,EAAE,CAAC;YAChD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;YAC1D,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YAC3B,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC;gBACjC,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;gBACrB,OAAO;aACR,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,4BAA6B,KAAe,CAAC,OAAO,EAAE;aAC9D,CAAC;QACJ,CAAC;IACH,CAAC;IACD,aAAa,EAAE,CAAC,MAAM,EAAE,EAAE;QACxB,IAAI,MAAM,CAAC,OAAO,KAAK,KAAK,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YAC3D,OAAO;gBACL,IAAI,EAAE,SAAS;gBACf,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;aACxD,CAAC;QACJ,CAAC;QAED,OAAO;YACL,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC;SACxE,CAAC;IACJ,CAAC;CACF,CAAC,CAAC;AAzCQ,QAAA,cAAc,kBAyCtB","sourcesContent":["import { tool } from \"ai\";\nimport { z } from \"zod\";\nimport type { V3 } from \"../../v3.js\";\n\nexport const screenshotTool = (v3: V3) =>\n tool({\n description:\n \"Takes a screenshot (PNG) of the current page. Use this to quickly verify page state.\",\n inputSchema: z.object({}),\n execute: async () => {\n try {\n v3.logger({\n category: \"agent\",\n message: `Agent calling tool: screenshot`,\n level: 1,\n });\n const page = await v3.context.awaitActivePage();\n const buffer = await page.screenshot({ fullPage: false });\n const pageUrl = page.url();\n return {\n success: true,\n base64: buffer.toString(\"base64\"),\n timestamp: Date.now(),\n pageUrl,\n };\n } catch (error) {\n return {\n success: false,\n error: `Error taking screenshot: ${(error as Error).message}`,\n };\n }\n },\n toModelOutput: (result) => {\n if (result.success === false || result.error !== undefined) {\n return {\n type: \"content\",\n value: [{ type: \"text\", text: JSON.stringify(result) }],\n };\n }\n\n return {\n type: \"content\",\n value: [{ type: \"media\", mediaType: \"image/png\", data: result.base64 }],\n };\n },\n });\n"]}
@@ -47,6 +47,12 @@ const scrollTool = (v3) => (0, ai_1.tool)({
47
47
  };
48
48
  },
49
49
  toModelOutput: (result) => {
50
+ if (result.success === false || result.error !== undefined) {
51
+ return {
52
+ type: "content",
53
+ value: [{ type: "text", text: JSON.stringify(result) }],
54
+ };
55
+ }
50
56
  return {
51
57
  type: "json",
52
58
  value: {
@@ -123,6 +129,12 @@ const scrollVisionTool = (v3, provider) => (0, ai_1.tool)({
123
129
  };
124
130
  },
125
131
  toModelOutput: (result) => {
132
+ if (result.success === false || result.error !== undefined) {
133
+ return {
134
+ type: "content",
135
+ value: [{ type: "text", text: JSON.stringify(result) }],
136
+ };
137
+ }
126
138
  const content = [
127
139
  {
128
140
  type: "text",