@browserbasehq/stagehand 3.0.7-alpha-5e337135056e0c4be59099b1919c2df741b27fea → 3.0.7-alpha-4d71162beb119635b69b17637564a2bbd0e373e7

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 (3) hide show
  1. package/dist/index.d.ts +329 -3
  2. package/dist/index.js +1131 -321
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -179,7 +179,7 @@ var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")])
179
179
  var STAGEHAND_VERSION;
180
180
  var init_version = __esm({
181
181
  "lib/version.ts"() {
182
- STAGEHAND_VERSION = "3.0.7-alpha-5e337135056e0c4be59099b1919c2df741b27fea";
182
+ STAGEHAND_VERSION = "3.0.7-alpha-4d71162beb119635b69b17637564a2bbd0e373e7";
183
183
  }
184
184
  });
185
185
 
@@ -14790,11 +14790,11 @@ var require_bignumber = __commonJS({
14790
14790
  return n > 0 || n === i2 ? i2 : i2 - 1;
14791
14791
  }
14792
14792
  function coeffToString(a) {
14793
- var s2, z69, i2 = 1, j = a.length, r2 = a[0] + "";
14793
+ var s2, z71, i2 = 1, j = a.length, r2 = a[0] + "";
14794
14794
  for (; i2 < j; ) {
14795
14795
  s2 = a[i2++] + "";
14796
- z69 = LOG_BASE - s2.length;
14797
- for (; z69--; s2 = "0" + s2) ;
14796
+ z71 = LOG_BASE - s2.length;
14797
+ for (; z71--; s2 = "0" + s2) ;
14798
14798
  r2 += s2;
14799
14799
  }
14800
14800
  for (j = r2.length; r2.charCodeAt(--j) === 48; ) ;
@@ -14827,15 +14827,15 @@ var require_bignumber = __commonJS({
14827
14827
  function toExponential(str, e2) {
14828
14828
  return (str.length > 1 ? str.charAt(0) + "." + str.slice(1) : str) + (e2 < 0 ? "e" : "e+") + e2;
14829
14829
  }
14830
- function toFixedPoint(str, e2, z69) {
14830
+ function toFixedPoint(str, e2, z71) {
14831
14831
  var len, zs;
14832
14832
  if (e2 < 0) {
14833
- for (zs = z69 + "."; ++e2; zs += z69) ;
14833
+ for (zs = z71 + "."; ++e2; zs += z71) ;
14834
14834
  str = zs + str;
14835
14835
  } else {
14836
14836
  len = str.length;
14837
14837
  if (++e2 > len) {
14838
- for (zs = z69, e2 -= len; --e2; zs += z69) ;
14838
+ for (zs = z71, e2 -= len; --e2; zs += z71) ;
14839
14839
  str += zs;
14840
14840
  } else if (e2 < len) {
14841
14841
  str = str.slice(0, e2) + "." + str.slice(e2);
@@ -26435,14 +26435,38 @@ var init_page = __esm({
26435
26435
  }));
26436
26436
  return;
26437
26437
  }
26438
+ const isLetter = /^[a-zA-Z]$/.test(ch);
26439
+ const isDigit = /^[0-9]$/.test(ch);
26440
+ let key = ch;
26441
+ let code = "";
26442
+ let windowsVirtualKeyCode;
26443
+ if (isLetter) {
26444
+ key = ch;
26445
+ code = `Key${ch.toUpperCase()}`;
26446
+ windowsVirtualKeyCode = ch.toUpperCase().charCodeAt(0);
26447
+ } else if (isDigit) {
26448
+ key = ch;
26449
+ code = `Digit${ch}`;
26450
+ windowsVirtualKeyCode = ch.charCodeAt(0);
26451
+ } else if (ch === " ") {
26452
+ key = " ";
26453
+ code = "Space";
26454
+ windowsVirtualKeyCode = 32;
26455
+ }
26438
26456
  const down = {
26439
26457
  type: "keyDown",
26458
+ key,
26459
+ code: code || void 0,
26440
26460
  text: ch,
26441
- unmodifiedText: ch
26461
+ unmodifiedText: ch,
26462
+ windowsVirtualKeyCode
26442
26463
  };
26443
26464
  yield this.mainSession.send("Input.dispatchKeyEvent", down);
26444
26465
  yield this.mainSession.send("Input.dispatchKeyEvent", {
26445
- type: "keyUp"
26466
+ type: "keyUp",
26467
+ key,
26468
+ code: code || void 0,
26469
+ windowsVirtualKeyCode
26446
26470
  });
26447
26471
  });
26448
26472
  const pressBackspace = () => __async(this, null, function* () {
@@ -26634,10 +26658,11 @@ var init_page = __esm({
26634
26658
  });
26635
26659
  });
26636
26660
  }
26637
- /** Normalize modifier key names to match CDP expectations */
26661
+ /** Normalize key names to match CDP expectations */
26638
26662
  normalizeModifierKey(key) {
26639
- const normalized = key.toLowerCase();
26640
- switch (normalized) {
26663
+ const lower2 = key.toLowerCase();
26664
+ switch (lower2) {
26665
+ // Modifier keys
26641
26666
  case "cmd":
26642
26667
  case "command":
26643
26668
  return this.isMacOS() ? "Meta" : "Control";
@@ -26645,11 +26670,56 @@ var init_page = __esm({
26645
26670
  case "windows":
26646
26671
  return "Meta";
26647
26672
  case "ctrl":
26673
+ case "control":
26648
26674
  return "Control";
26649
26675
  case "option":
26676
+ case "alt":
26650
26677
  return "Alt";
26651
26678
  case "shift":
26652
26679
  return "Shift";
26680
+ case "meta":
26681
+ return "Meta";
26682
+ // Action keys
26683
+ case "enter":
26684
+ case "return":
26685
+ return "Enter";
26686
+ case "esc":
26687
+ case "escape":
26688
+ return "Escape";
26689
+ case "backspace":
26690
+ return "Backspace";
26691
+ case "tab":
26692
+ return "Tab";
26693
+ case "space":
26694
+ case "spacebar":
26695
+ return " ";
26696
+ case "delete":
26697
+ case "del":
26698
+ return "Delete";
26699
+ // Arrow keys
26700
+ case "left":
26701
+ case "arrowleft":
26702
+ return "ArrowLeft";
26703
+ case "right":
26704
+ case "arrowright":
26705
+ return "ArrowRight";
26706
+ case "up":
26707
+ case "arrowup":
26708
+ return "ArrowUp";
26709
+ case "down":
26710
+ case "arrowdown":
26711
+ return "ArrowDown";
26712
+ // Navigation keys
26713
+ case "home":
26714
+ return "Home";
26715
+ case "end":
26716
+ return "End";
26717
+ case "pageup":
26718
+ case "pgup":
26719
+ return "PageUp";
26720
+ case "pagedown":
26721
+ case "pgdn":
26722
+ return "PageDown";
26653
26723
  default:
26654
26724
  return key;
26655
26725
  }
@@ -30682,10 +30752,10 @@ var ObserveHandler = class {
30682
30752
  }
30683
30753
  };
30684
30754
 
30685
- // lib/v3/agent/tools/v3-goto.ts
30755
+ // lib/v3/agent/tools/goto.ts
30686
30756
  var import_ai = require("ai");
30687
30757
  var import_zod5 = require("zod");
30688
- var createGotoTool = (v3) => (0, import_ai.tool)({
30758
+ var gotoTool = (v3) => (0, import_ai.tool)({
30689
30759
  description: "Navigate to a specific URL",
30690
30760
  inputSchema: import_zod5.z.object({
30691
30761
  url: import_zod5.z.string().describe("The URL to navigate to")
@@ -30714,10 +30784,10 @@ var createGotoTool = (v3) => (0, import_ai.tool)({
30714
30784
  })
30715
30785
  });
30716
30786
 
30717
- // lib/v3/agent/tools/v3-act.ts
30787
+ // lib/v3/agent/tools/act.ts
30718
30788
  var import_ai2 = require("ai");
30719
30789
  var import_zod6 = require("zod");
30720
- var createActTool = (v3, executionModel) => (0, import_ai2.tool)({
30790
+ var actTool = (v3, executionModel) => (0, import_ai2.tool)({
30721
30791
  description: "Perform an action on the page (click, type). Provide a short, specific phrase that mentions the element type.",
30722
30792
  inputSchema: import_zod6.z.object({
30723
30793
  action: import_zod6.z.string().describe(
@@ -30759,10 +30829,10 @@ var createActTool = (v3, executionModel) => (0, import_ai2.tool)({
30759
30829
  })
30760
30830
  });
30761
30831
 
30762
- // lib/v3/agent/tools/v3-screenshot.ts
30832
+ // lib/v3/agent/tools/screenshot.ts
30763
30833
  var import_ai3 = require("ai");
30764
30834
  var import_zod7 = require("zod");
30765
- var createScreenshotTool = (v3) => (0, import_ai3.tool)({
30835
+ var screenshotTool = (v3) => (0, import_ai3.tool)({
30766
30836
  description: "Takes a screenshot (PNG) of the current page. Use this to quickly verify page state.",
30767
30837
  inputSchema: import_zod7.z.object({}),
30768
30838
  execute: () => __async(null, null, function* () {
@@ -30786,10 +30856,10 @@ var createScreenshotTool = (v3) => (0, import_ai3.tool)({
30786
30856
  })
30787
30857
  });
30788
30858
 
30789
- // lib/v3/agent/tools/v3-wait.ts
30859
+ // lib/v3/agent/tools/wait.ts
30790
30860
  var import_ai4 = require("ai");
30791
30861
  var import_zod8 = require("zod");
30792
- var createWaitTool = (v3) => (0, import_ai4.tool)({
30862
+ var waitTool = (v3) => (0, import_ai4.tool)({
30793
30863
  description: "Wait for a specified time",
30794
30864
  inputSchema: import_zod8.z.object({
30795
30865
  timeMs: import_zod8.z.number().describe("Time in milliseconds")
@@ -30814,10 +30884,10 @@ var createWaitTool = (v3) => (0, import_ai4.tool)({
30814
30884
  })
30815
30885
  });
30816
30886
 
30817
- // lib/v3/agent/tools/v3-navback.ts
30887
+ // lib/v3/agent/tools/navback.ts
30818
30888
  var import_ai5 = require("ai");
30819
30889
  var import_zod9 = require("zod");
30820
- var createNavBackTool = (v3) => (0, import_ai5.tool)({
30890
+ var navBackTool = (v3) => (0, import_ai5.tool)({
30821
30891
  description: "Navigate back to the previous page",
30822
30892
  inputSchema: import_zod9.z.object({
30823
30893
  reasoningText: import_zod9.z.string().describe("Why you're going back")
@@ -30838,10 +30908,10 @@ var createNavBackTool = (v3) => (0, import_ai5.tool)({
30838
30908
  })
30839
30909
  });
30840
30910
 
30841
- // lib/v3/agent/tools/v3-close.ts
30911
+ // lib/v3/agent/tools/close.ts
30842
30912
  var import_ai6 = require("ai");
30843
30913
  var import_zod10 = require("zod");
30844
- var createCloseTool = () => (0, import_ai6.tool)({
30914
+ var closeTool = () => (0, import_ai6.tool)({
30845
30915
  description: "Complete the task and close",
30846
30916
  inputSchema: import_zod10.z.object({
30847
30917
  reasoning: import_zod10.z.string().describe("Summary of what was accomplished"),
@@ -30852,10 +30922,10 @@ var createCloseTool = () => (0, import_ai6.tool)({
30852
30922
  })
30853
30923
  });
30854
30924
 
30855
- // lib/v3/agent/tools/v3-ariaTree.ts
30925
+ // lib/v3/agent/tools/ariaTree.ts
30856
30926
  var import_ai7 = require("ai");
30857
30927
  var import_zod11 = require("zod");
30858
- var createAriaTreeTool = (v3) => (0, import_ai7.tool)({
30928
+ var ariaTreeTool = (v3) => (0, import_ai7.tool)({
30859
30929
  description: "gets the accessibility (ARIA) hybrid tree text for the current page. use this to understand structure and content.",
30860
30930
  inputSchema: import_zod11.z.object({}),
30861
30931
  execute: () => __async(null, null, function* () {
@@ -30883,10 +30953,10 @@ ${result.content}` }]
30883
30953
  })
30884
30954
  });
30885
30955
 
30886
- // lib/v3/agent/tools/v3-fillform.ts
30956
+ // lib/v3/agent/tools/fillform.ts
30887
30957
  var import_ai8 = require("ai");
30888
30958
  var import_zod12 = require("zod");
30889
- var createFillFormTool = (v3, executionModel) => (0, import_ai8.tool)({
30959
+ var fillFormTool = (v3, executionModel) => (0, import_ai8.tool)({
30890
30960
  description: `\u{1F4DD} FORM FILL - MULTI-FIELD INPUT TOOL
30891
30961
  For any form with 2+ inputs/textareas. Faster than individual typing.`,
30892
30962
  inputSchema: import_zod12.z.object({
@@ -30937,32 +31007,114 @@ For any form with 2+ inputs/textareas. Faster than individual typing.`,
30937
31007
  })
30938
31008
  });
30939
31009
 
30940
- // lib/v3/agent/tools/v3-scroll.ts
31010
+ // lib/v3/agent/tools/scroll.ts
30941
31011
  var import_ai9 = require("ai");
30942
31012
  var import_zod13 = require("zod");
30943
- var createScrollTool = (v3) => (0, import_ai9.tool)({
30944
- description: "Scroll the page",
31013
+
31014
+ // lib/v3/agent/utils/coordinateNormalization.ts
31015
+ var DEFAULT_VIEWPORT = { width: 1288, height: 711 };
31016
+ function isGoogleProvider(provider) {
31017
+ if (!provider) return false;
31018
+ return provider.toLowerCase().includes("google");
31019
+ }
31020
+ function normalizeGoogleCoordinates(x2, y) {
31021
+ const clampedX = Math.min(999, Math.max(0, x2));
31022
+ const clampedY = Math.min(999, Math.max(0, y));
31023
+ return {
31024
+ x: Math.floor(clampedX / 1e3 * DEFAULT_VIEWPORT.width),
31025
+ y: Math.floor(clampedY / 1e3 * DEFAULT_VIEWPORT.height)
31026
+ };
31027
+ }
31028
+ function processCoordinates(x2, y, provider) {
31029
+ if (isGoogleProvider(provider)) {
31030
+ return normalizeGoogleCoordinates(x2, y);
31031
+ }
31032
+ return { x: x2, y };
31033
+ }
31034
+
31035
+ // lib/v3/agent/tools/scroll.ts
31036
+ var scrollTool = (v3) => (0, import_ai9.tool)({
31037
+ description: "Scroll the page up or down by a percentage of the viewport height. Default is 80%, and what should be typically used for general page scrolling",
30945
31038
  inputSchema: import_zod13.z.object({
30946
- pixels: import_zod13.z.number().describe("Number of pixels to scroll up or down"),
30947
- direction: import_zod13.z.enum(["up", "down"]).describe("Direction to scroll")
31039
+ direction: import_zod13.z.enum(["up", "down"]),
31040
+ percentage: import_zod13.z.number().min(1).max(200).optional()
30948
31041
  }),
30949
- execute: (_0) => __async(null, [_0], function* ({ pixels, direction }) {
31042
+ execute: (_0) => __async(null, [_0], function* ({ direction, percentage = 80 }) {
30950
31043
  v3.logger({
30951
31044
  category: "agent",
30952
31045
  message: `Agent calling tool: scroll`,
30953
31046
  level: 1,
30954
31047
  auxiliary: {
30955
31048
  arguments: {
30956
- value: JSON.stringify({ pixels, direction }),
31049
+ value: JSON.stringify({ direction, percentage }),
30957
31050
  type: "object"
30958
31051
  }
30959
31052
  }
30960
31053
  });
30961
31054
  const page = yield v3.context.awaitActivePage();
30962
31055
  const { w, h: h2 } = yield page.mainFrame().evaluate("({ w: window.innerWidth, h: window.innerHeight })");
30963
- const cx = Math.max(0, Math.floor(w / 2));
30964
- const cy = Math.max(0, Math.floor(h2 / 2));
30965
- const deltaY = direction === "up" ? -Math.abs(pixels) : Math.abs(pixels);
31056
+ const scrollDistance = Math.round(h2 * percentage / 100);
31057
+ const cx = Math.floor(w / 2);
31058
+ const cy = Math.floor(h2 / 2);
31059
+ const deltaY = direction === "up" ? -scrollDistance : scrollDistance;
31060
+ yield page.scroll(cx, cy, 0, deltaY);
31061
+ v3.recordAgentReplayStep({
31062
+ type: "scroll",
31063
+ deltaX: 0,
31064
+ deltaY,
31065
+ anchor: { x: cx, y: cy }
31066
+ });
31067
+ return {
31068
+ success: true,
31069
+ message: `Scrolled ${percentage}% ${direction} (${scrollDistance}px)`,
31070
+ scrolledPixels: scrollDistance
31071
+ };
31072
+ })
31073
+ });
31074
+ var scrollVisionTool = (v3, provider) => (0, import_ai9.tool)({
31075
+ description: `Scroll the page up or down. For general page scrolling, no coordinates needed. Only provide coordinates when scrolling inside a nested scrollable element (e.g., a dropdown menu, modal with overflow, or scrollable sidebar). Default is 80%, and what should be typically used for general page scrolling`,
31076
+ inputSchema: import_zod13.z.object({
31077
+ direction: import_zod13.z.enum(["up", "down"]),
31078
+ coordinates: import_zod13.z.array(import_zod13.z.number()).optional().describe(
31079
+ "Only use coordinates for scrolling inside a nested scrollable element - provide (x, y) within that element"
31080
+ ),
31081
+ percentage: import_zod13.z.number().min(1).max(200).optional()
31082
+ }),
31083
+ execute: (_0) => __async(null, [_0], function* ({ direction, coordinates, percentage = 80 }) {
31084
+ const page = yield v3.context.awaitActivePage();
31085
+ const { w, h: h2 } = yield page.mainFrame().evaluate("({ w: window.innerWidth, h: window.innerHeight })");
31086
+ let cx;
31087
+ let cy;
31088
+ if (coordinates) {
31089
+ const processed = processCoordinates(
31090
+ coordinates[0],
31091
+ coordinates[1],
31092
+ provider
31093
+ );
31094
+ cx = processed.x;
31095
+ cy = processed.y;
31096
+ } else {
31097
+ cx = Math.floor(w / 2);
31098
+ cy = Math.floor(h2 / 2);
31099
+ }
31100
+ v3.logger({
31101
+ category: "agent",
31102
+ message: `Agent calling tool: scroll`,
31103
+ level: 1,
31104
+ auxiliary: {
31105
+ arguments: {
31106
+ value: JSON.stringify({
31107
+ direction,
31108
+ coordinates,
31109
+ percentage,
31110
+ processed: { cx, cy }
31111
+ }),
31112
+ type: "object"
31113
+ }
31114
+ }
31115
+ });
31116
+ const scrollDistance = Math.round(h2 * percentage / 100);
31117
+ const deltaY = direction === "up" ? -scrollDistance : scrollDistance;
30966
31118
  yield page.scroll(cx, cy, 0, deltaY);
30967
31119
  v3.recordAgentReplayStep({
30968
31120
  type: "scroll",
@@ -30970,11 +31122,15 @@ var createScrollTool = (v3) => (0, import_ai9.tool)({
30970
31122
  deltaY,
30971
31123
  anchor: { x: cx, y: cy }
30972
31124
  });
30973
- return { success: true, pixels };
31125
+ return {
31126
+ success: true,
31127
+ message: coordinates ? `Scrolled ${percentage}% ${direction} at (${cx}, ${cy})` : `Scrolled ${percentage}% ${direction}`,
31128
+ scrolledPixels: scrollDistance
31129
+ };
30974
31130
  })
30975
31131
  });
30976
31132
 
30977
- // lib/v3/agent/tools/v3-extract.ts
31133
+ // lib/v3/agent/tools/extract.ts
30978
31134
  var import_ai10 = require("ai");
30979
31135
  var import_zod14 = require("zod");
30980
31136
  function evaluateZodSchema(schemaStr, logger) {
@@ -30991,7 +31147,7 @@ function evaluateZodSchema(schemaStr, logger) {
30991
31147
  return import_zod14.z.any();
30992
31148
  }
30993
31149
  }
30994
- var createExtractTool = (v3, executionModel, logger) => (0, import_ai10.tool)({
31150
+ var extractTool = (v3, executionModel, logger) => (0, import_ai10.tool)({
30995
31151
  description: `Extract structured data from the current page based on a provided schema.
30996
31152
 
30997
31153
  USAGE GUIDELINES:
@@ -31026,25 +31182,677 @@ var createExtractTool = (v3, executionModel, logger) => (0, import_ai10.tool)({
31026
31182
  })
31027
31183
  });
31028
31184
 
31185
+ // lib/v3/agent/tools/click.ts
31186
+ var import_ai11 = require("ai");
31187
+ var import_zod15 = require("zod");
31188
+ function waitForTimeout(ms) {
31189
+ return new Promise((resolve3) => setTimeout(resolve3, ms));
31190
+ }
31191
+ var clickTool = (v3, provider) => (0, import_ai11.tool)({
31192
+ description: "Click on an element using its coordinates (this is the most reliable way to click on an element, always use this over act, unless the element is not visible in the screenshot, but shown in ariaTree)",
31193
+ inputSchema: import_zod15.z.object({
31194
+ describe: import_zod15.z.string().describe(
31195
+ "Describe the element to click on in a short, specific phrase that mentions the element type and a good visual description"
31196
+ ),
31197
+ coordinates: import_zod15.z.array(import_zod15.z.number()).describe("The (x, y) coordinates to click on")
31198
+ }),
31199
+ execute: (_0) => __async(null, [_0], function* ({ describe, coordinates }) {
31200
+ try {
31201
+ const page = yield v3.context.awaitActivePage();
31202
+ const processed = processCoordinates(
31203
+ coordinates[0],
31204
+ coordinates[1],
31205
+ provider
31206
+ );
31207
+ v3.logger({
31208
+ category: "agent",
31209
+ message: `Agent calling tool: click`,
31210
+ level: 1,
31211
+ auxiliary: {
31212
+ arguments: {
31213
+ value: JSON.stringify({ describe, coordinates, processed }),
31214
+ type: "string"
31215
+ }
31216
+ }
31217
+ });
31218
+ yield page.click(processed.x, processed.y);
31219
+ if (isGoogleProvider(provider)) {
31220
+ yield waitForTimeout(1e3);
31221
+ }
31222
+ v3.recordAgentReplayStep({
31223
+ type: "click",
31224
+ instruction: describe,
31225
+ playwrightArguments: { coordinates: [processed.x, processed.y] }
31226
+ });
31227
+ return {
31228
+ success: true,
31229
+ describe,
31230
+ coordinates: [processed.x, processed.y]
31231
+ };
31232
+ } catch (error) {
31233
+ return {
31234
+ success: false,
31235
+ error: `Error clicking: ${error.message}`
31236
+ };
31237
+ }
31238
+ })
31239
+ });
31240
+
31241
+ // lib/v3/agent/tools/type.ts
31242
+ var import_ai12 = require("ai");
31243
+ var import_zod16 = require("zod");
31244
+ function waitForTimeout2(ms) {
31245
+ return new Promise((resolve3) => setTimeout(resolve3, ms));
31246
+ }
31247
+ var typeTool = (v3, provider) => (0, import_ai12.tool)({
31248
+ description: "Type text into an element using its coordinates. This will click the element and then type the text into it (this is the most reliable way to type into an element, always use this over act, unless the element is not visible in the screenshot, but shown in ariaTree)",
31249
+ inputSchema: import_zod16.z.object({
31250
+ describe: import_zod16.z.string().describe(
31251
+ "Describe the element to type into in a short, specific phrase that mentions the element type and a good visual description"
31252
+ ),
31253
+ text: import_zod16.z.string().describe("The text to type into the element"),
31254
+ coordinates: import_zod16.z.array(import_zod16.z.number()).describe("The (x, y) coordinates to type into the element")
31255
+ }),
31256
+ execute: (_0) => __async(null, [_0], function* ({ describe, coordinates, text }) {
31257
+ try {
31258
+ const page = yield v3.context.awaitActivePage();
31259
+ const processed = processCoordinates(
31260
+ coordinates[0],
31261
+ coordinates[1],
31262
+ provider
31263
+ );
31264
+ v3.logger({
31265
+ category: "agent",
31266
+ message: `Agent calling tool: type`,
31267
+ level: 1,
31268
+ auxiliary: {
31269
+ arguments: {
31270
+ value: JSON.stringify({ describe, coordinates, processed, text }),
31271
+ type: "string"
31272
+ }
31273
+ }
31274
+ });
31275
+ yield page.click(processed.x, processed.y);
31276
+ if (isGoogleProvider(provider)) {
31277
+ yield waitForTimeout2(1e3);
31278
+ }
31279
+ yield page.type(text);
31280
+ v3.recordAgentReplayStep({
31281
+ type: "type",
31282
+ instruction: describe,
31283
+ playwrightArguments: {
31284
+ coordinates: [processed.x, processed.y],
31285
+ text
31286
+ }
31287
+ });
31288
+ return { success: true, describe, text };
31289
+ } catch (error) {
31290
+ return {
31291
+ success: false,
31292
+ error: `Error typing: ${error.message}`
31293
+ };
31294
+ }
31295
+ })
31296
+ });
31297
+
31298
+ // lib/v3/agent/tools/dragAndDrop.ts
31299
+ var import_ai13 = require("ai");
31300
+ var import_zod17 = require("zod");
31301
+ var dragAndDropTool = (v3, provider) => (0, import_ai13.tool)({
31302
+ description: "Drag and drop an element using its coordinates (this is the most reliable way to drag and drop an element, always use this over act, unless the element is not visible in the screenshot, but shown in ariaTree)",
31303
+ inputSchema: import_zod17.z.object({
31304
+ describe: import_zod17.z.string().describe("Describe the element to drag and drop"),
31305
+ startCoordinates: import_zod17.z.array(import_zod17.z.number()).describe("The (x, y) coordinates to start the drag and drop from"),
31306
+ endCoordinates: import_zod17.z.array(import_zod17.z.number()).describe("The (x, y) coordinates to end the drag and drop at")
31307
+ }),
31308
+ execute: (_0) => __async(null, [_0], function* ({ describe, startCoordinates, endCoordinates }) {
31309
+ try {
31310
+ const page = yield v3.context.awaitActivePage();
31311
+ const processedStart = processCoordinates(
31312
+ startCoordinates[0],
31313
+ startCoordinates[1],
31314
+ provider
31315
+ );
31316
+ const processedEnd = processCoordinates(
31317
+ endCoordinates[0],
31318
+ endCoordinates[1],
31319
+ provider
31320
+ );
31321
+ v3.logger({
31322
+ category: "agent",
31323
+ message: `Agent calling tool: dragAndDrop`,
31324
+ level: 1,
31325
+ auxiliary: {
31326
+ arguments: {
31327
+ value: JSON.stringify({
31328
+ describe,
31329
+ startCoordinates,
31330
+ endCoordinates,
31331
+ processedStart,
31332
+ processedEnd
31333
+ }),
31334
+ type: "string"
31335
+ }
31336
+ }
31337
+ });
31338
+ yield page.dragAndDrop(
31339
+ processedStart.x,
31340
+ processedStart.y,
31341
+ processedEnd.x,
31342
+ processedEnd.y
31343
+ );
31344
+ v3.recordAgentReplayStep({
31345
+ type: "dragAndDrop",
31346
+ instruction: describe,
31347
+ playwrightArguments: {
31348
+ startCoordinates: [processedStart.x, processedStart.y],
31349
+ endCoordinates: [processedEnd.x, processedEnd.y]
31350
+ }
31351
+ });
31352
+ return { success: true, describe };
31353
+ } catch (error) {
31354
+ return {
31355
+ success: false,
31356
+ error: `Error dragging: ${error.message}`
31357
+ };
31358
+ }
31359
+ })
31360
+ });
31361
+
31362
+ // lib/v3/agent/tools/clickAndHold.ts
31363
+ var import_ai14 = require("ai");
31364
+ var import_zod18 = require("zod");
31365
+ var clickAndHoldTool = (v3, provider) => (0, import_ai14.tool)({
31366
+ description: "Click and hold on an element using its coordinates",
31367
+ inputSchema: import_zod18.z.object({
31368
+ describe: import_zod18.z.string().describe(
31369
+ "Describe the element to click on in a short, specific phrase that mentions the element type and a good visual description"
31370
+ ),
31371
+ duration: import_zod18.z.number().describe("The duration to hold the element in milliseconds"),
31372
+ coordinates: import_zod18.z.array(import_zod18.z.number()).describe("The (x, y) coordinates to click on")
31373
+ }),
31374
+ execute: (_0) => __async(null, [_0], function* ({ describe, coordinates, duration }) {
31375
+ try {
31376
+ const page = yield v3.context.awaitActivePage();
31377
+ const processed = processCoordinates(
31378
+ coordinates[0],
31379
+ coordinates[1],
31380
+ provider
31381
+ );
31382
+ v3.logger({
31383
+ category: "agent",
31384
+ message: `Agent calling tool: clickAndHold`,
31385
+ level: 1,
31386
+ auxiliary: {
31387
+ arguments: {
31388
+ value: JSON.stringify({
31389
+ describe,
31390
+ coordinates,
31391
+ processed,
31392
+ duration
31393
+ }),
31394
+ type: "string"
31395
+ }
31396
+ }
31397
+ });
31398
+ yield page.dragAndDrop(
31399
+ processed.x,
31400
+ processed.y,
31401
+ processed.x,
31402
+ processed.y,
31403
+ { delay: duration }
31404
+ );
31405
+ v3.recordAgentReplayStep({
31406
+ type: "clickAndHold",
31407
+ instruction: describe,
31408
+ playwrightArguments: {
31409
+ coordinates: [processed.x, processed.y],
31410
+ duration
31411
+ }
31412
+ });
31413
+ return { success: true, describe };
31414
+ } catch (error) {
31415
+ return {
31416
+ success: false,
31417
+ error: `Error clicking and holding: ${error.message}`
31418
+ };
31419
+ }
31420
+ })
31421
+ });
31422
+
31423
+ // lib/v3/agent/tools/keys.ts
31424
+ var import_ai15 = require("ai");
31425
+ var import_zod19 = require("zod");
31426
+ var keysTool = (v3) => (0, import_ai15.tool)({
31427
+ description: `Send keyboard input to the page without targeting a specific element. Unlike the type tool which clicks then types into coordinates, this sends keystrokes directly to wherever focus currently is.
31428
+
31429
+ Use method="type" to enter text into the currently focused element. Preferred when: input is already focused, text needs to flow across multiple fields (e.g., verification codes)
31430
+
31431
+ Use method="press" for navigation keys (Enter, Tab, Escape, Backspace, arrows) and keyboard shortcuts (Cmd+A, Ctrl+C, Shift+Tab).`,
31432
+ inputSchema: import_zod19.z.object({
31433
+ method: import_zod19.z.enum(["press", "type"]),
31434
+ value: import_zod19.z.string().describe(
31435
+ "The text to type, or the key/combo to press (Enter, Tab, Cmd+A)"
31436
+ ),
31437
+ repeat: import_zod19.z.number().optional()
31438
+ }),
31439
+ execute: (_0) => __async(null, [_0], function* ({ method, value, repeat }) {
31440
+ try {
31441
+ const page = yield v3.context.awaitActivePage();
31442
+ v3.logger({
31443
+ category: "agent",
31444
+ message: `Agent calling tool: keys`,
31445
+ level: 1,
31446
+ auxiliary: {
31447
+ arguments: {
31448
+ value: JSON.stringify({ method, value, repeat }),
31449
+ type: "string"
31450
+ }
31451
+ }
31452
+ });
31453
+ const times = Math.max(1, repeat != null ? repeat : 1);
31454
+ if (method === "type") {
31455
+ for (let i2 = 0; i2 < times; i2++) {
31456
+ yield page.type(value, { delay: 100 });
31457
+ }
31458
+ v3.recordAgentReplayStep({
31459
+ type: "keys",
31460
+ instruction: `type "${value}"`,
31461
+ playwrightArguments: { method, text: value, times }
31462
+ });
31463
+ return { success: true, method, value, times };
31464
+ }
31465
+ if (method === "press") {
31466
+ for (let i2 = 0; i2 < times; i2++) {
31467
+ yield page.keyPress(value, { delay: 100 });
31468
+ }
31469
+ v3.recordAgentReplayStep({
31470
+ type: "keys",
31471
+ instruction: `press ${value}`,
31472
+ playwrightArguments: { method, keys: value, times }
31473
+ });
31474
+ return { success: true, method, value, times };
31475
+ }
31476
+ return { success: false, error: `Unsupported method: ${method}` };
31477
+ } catch (error) {
31478
+ return { success: false, error: error.message };
31479
+ }
31480
+ })
31481
+ });
31482
+
31483
+ // lib/v3/agent/tools/fillFormVision.ts
31484
+ var import_ai16 = require("ai");
31485
+ var import_zod20 = require("zod");
31486
+ var fillFormVisionTool = (v3, provider) => (0, import_ai16.tool)({
31487
+ description: `FORM FILL - SPECIALIZED MULTI-FIELD INPUT TOOL
31488
+
31489
+ CRITICAL: Use this for ANY form with 2+ input fields (text inputs, textareas, etc.)
31490
+ IMPORTANT: Ensure the fields are visible within the current viewport
31491
+
31492
+ WHY THIS TOOL EXISTS:
31493
+ - Forms are the #1 use case for multi-field input
31494
+ - Optimized specifically for input/textarea elements
31495
+ - 4-6x faster than individual typing actions
31496
+
31497
+ Use fillFormVision: Pure form filling (inputs, textareas only)
31498
+ MANDATORY USE CASES (always use fillFormVision for these):
31499
+ - Registration forms: name, email, password fields
31500
+ - Contact forms: name, email, message fields
31501
+ - Checkout forms: address, payment info fields
31502
+ - Profile updates: multiple user data fields
31503
+ - Search filters: multiple criteria inputs`,
31504
+ inputSchema: import_zod20.z.object({
31505
+ fields: import_zod20.z.array(
31506
+ import_zod20.z.object({
31507
+ action: import_zod20.z.string().describe(
31508
+ "Description of the typing action, e.g. 'type foo into the bar field'"
31509
+ ),
31510
+ value: import_zod20.z.string().describe("Text to type into the target field"),
31511
+ coordinates: import_zod20.z.object({
31512
+ x: import_zod20.z.number(),
31513
+ y: import_zod20.z.number()
31514
+ }).describe("Coordinates of the target field")
31515
+ })
31516
+ ).min(2, "Provide at least two fields to fill")
31517
+ }),
31518
+ execute: (_0) => __async(null, [_0], function* ({ fields }) {
31519
+ try {
31520
+ const page = yield v3.context.awaitActivePage();
31521
+ const processedFields = fields.map((field) => {
31522
+ const processed = processCoordinates(
31523
+ field.coordinates.x,
31524
+ field.coordinates.y,
31525
+ provider
31526
+ );
31527
+ return __spreadProps(__spreadValues({}, field), {
31528
+ coordinates: { x: processed.x, y: processed.y }
31529
+ });
31530
+ });
31531
+ v3.logger({
31532
+ category: "agent",
31533
+ message: `Agent calling tool: fillFormVision`,
31534
+ level: 1,
31535
+ auxiliary: {
31536
+ arguments: {
31537
+ value: JSON.stringify({ fields, processedFields }),
31538
+ type: "string"
31539
+ }
31540
+ }
31541
+ });
31542
+ for (const field of processedFields) {
31543
+ yield page.click(field.coordinates.x, field.coordinates.y);
31544
+ yield page.type(field.value);
31545
+ yield new Promise((resolve3) => setTimeout(resolve3, 100));
31546
+ }
31547
+ v3.recordAgentReplayStep({
31548
+ type: "fillFormVision",
31549
+ instruction: `Fill ${fields.length} form fields`,
31550
+ playwrightArguments: processedFields
31551
+ });
31552
+ return {
31553
+ success: true,
31554
+ playwrightArguments: processedFields
31555
+ };
31556
+ } catch (error) {
31557
+ return {
31558
+ success: false,
31559
+ error: `Error filling form: ${error.message}`
31560
+ };
31561
+ }
31562
+ })
31563
+ });
31564
+
31565
+ // lib/v3/agent/tools/think.ts
31566
+ var import_ai17 = require("ai");
31567
+ var import_zod21 = require("zod");
31568
+ var thinkTool = () => (0, import_ai17.tool)({
31569
+ description: `Use this tool to think through complex problems or plan a sequence of steps. This is for internal reasoning only and doesn't perform any actions. Use this to:
31570
+
31571
+ 1. Plan a multi-step approach before taking action
31572
+ 2. Break down complex tasks
31573
+ 3. Reason through edge cases
31574
+ 4. Evaluate options when you're unsure what to do next
31575
+
31576
+ The output is only visible to you; use it to track your own reasoning process.`,
31577
+ inputSchema: import_zod21.z.object({
31578
+ reasoning: import_zod21.z.string().describe(
31579
+ "Your step-by-step reasoning or planning process. Be as detailed as needed."
31580
+ )
31581
+ }),
31582
+ execute: (_0) => __async(null, [_0], function* ({ reasoning }) {
31583
+ return {
31584
+ acknowledged: true,
31585
+ message: reasoning
31586
+ };
31587
+ })
31588
+ });
31589
+
31590
+ // lib/v3/agent/tools/search.ts
31591
+ var import_ai18 = require("ai");
31592
+ var import_zod22 = require("zod");
31593
+ function performBraveSearch(query) {
31594
+ return __async(this, null, function* () {
31595
+ var _a4;
31596
+ try {
31597
+ const encodedQuery = encodeURIComponent(query);
31598
+ const response = yield fetch(
31599
+ `https://api.search.brave.com/res/v1/web/search?q=${encodedQuery}`,
31600
+ {
31601
+ method: "GET",
31602
+ headers: {
31603
+ Accept: "application/json",
31604
+ "Accept-Encoding": "gzip",
31605
+ "X-Subscription-Token": process.env.BRAVE_API_KEY
31606
+ }
31607
+ }
31608
+ );
31609
+ if (!response.ok) {
31610
+ return {
31611
+ error: `Brave API error: ${response.status} ${response.statusText}`,
31612
+ data: { results: [] }
31613
+ };
31614
+ }
31615
+ const data = yield response.json();
31616
+ const results = [];
31617
+ if (((_a4 = data == null ? void 0 : data.web) == null ? void 0 : _a4.results) && Array.isArray(data.web.results)) {
31618
+ for (const item of data.web.results.slice(0, 5)) {
31619
+ if (item.title && item.url) {
31620
+ results.push({
31621
+ title: item.title,
31622
+ url: item.url,
31623
+ description: item.description
31624
+ });
31625
+ }
31626
+ }
31627
+ }
31628
+ return { data: { results } };
31629
+ } catch (error) {
31630
+ console.error("Search error", error);
31631
+ return {
31632
+ error: `Error performing search: ${error.message}`,
31633
+ data: { results: [] }
31634
+ };
31635
+ }
31636
+ });
31637
+ }
31638
+ var searchTool = (v3) => (0, import_ai18.tool)({
31639
+ description: "Perform a web search and returns results. Use this tool when you need information from the web or when you are unsure of the exact URL you want to navigate to. This can be used to find the ideal entry point, resulting in a task that is easier to complete due to starting further in the process.",
31640
+ inputSchema: import_zod22.z.object({
31641
+ query: import_zod22.z.string().describe("The search query to look for on the web")
31642
+ }),
31643
+ execute: (_0) => __async(null, [_0], function* ({ query }) {
31644
+ var _a4, _b, _c;
31645
+ v3.logger({
31646
+ category: "agent",
31647
+ message: `Agent calling tool: search`,
31648
+ level: 1,
31649
+ auxiliary: {
31650
+ arguments: {
31651
+ value: JSON.stringify({ query }),
31652
+ type: "string"
31653
+ }
31654
+ }
31655
+ });
31656
+ const result = yield performBraveSearch(query);
31657
+ v3.recordAgentReplayStep({
31658
+ type: "search",
31659
+ instruction: query,
31660
+ playwrightArguments: { query },
31661
+ message: (_c = result.error) != null ? _c : `Found ${(_b = (_a4 = result.data) == null ? void 0 : _a4.results.length) != null ? _b : 0} results`
31662
+ });
31663
+ return __spreadProps(__spreadValues({}, result), {
31664
+ timestamp: Date.now()
31665
+ });
31666
+ })
31667
+ });
31668
+
31029
31669
  // lib/v3/agent/tools/index.ts
31670
+ function filterToolsByMode(tools, mode) {
31671
+ const filtered = __spreadValues({}, tools);
31672
+ if (mode === "hybrid") {
31673
+ delete filtered.fillForm;
31674
+ return filtered;
31675
+ }
31676
+ delete filtered.click;
31677
+ delete filtered.type;
31678
+ delete filtered.dragAndDrop;
31679
+ delete filtered.clickAndHold;
31680
+ delete filtered.fillFormVision;
31681
+ return filtered;
31682
+ }
31030
31683
  function createAgentTools(v3, options) {
31684
+ var _a4;
31031
31685
  const executionModel = options == null ? void 0 : options.executionModel;
31032
- return {
31033
- act: createActTool(v3, executionModel),
31034
- ariaTree: createAriaTreeTool(v3),
31035
- close: createCloseTool(),
31036
- extract: createExtractTool(v3, executionModel, options == null ? void 0 : options.logger),
31037
- fillForm: createFillFormTool(v3, executionModel),
31038
- goto: createGotoTool(v3),
31039
- navback: createNavBackTool(v3),
31040
- screenshot: createScreenshotTool(v3),
31041
- scroll: createScrollTool(v3),
31042
- wait: createWaitTool(v3)
31686
+ const mode = (_a4 = options == null ? void 0 : options.mode) != null ? _a4 : "dom";
31687
+ const provider = options == null ? void 0 : options.provider;
31688
+ const allTools = {
31689
+ act: actTool(v3, executionModel),
31690
+ ariaTree: ariaTreeTool(v3),
31691
+ click: clickTool(v3, provider),
31692
+ clickAndHold: clickAndHoldTool(v3, provider),
31693
+ close: closeTool(),
31694
+ dragAndDrop: dragAndDropTool(v3, provider),
31695
+ extract: extractTool(v3, executionModel, options == null ? void 0 : options.logger),
31696
+ fillForm: fillFormTool(v3, executionModel),
31697
+ fillFormVision: fillFormVisionTool(v3, provider),
31698
+ goto: gotoTool(v3),
31699
+ keys: keysTool(v3),
31700
+ navback: navBackTool(v3),
31701
+ screenshot: screenshotTool(v3),
31702
+ scroll: mode === "hybrid" ? scrollVisionTool(v3, provider) : scrollTool(v3),
31703
+ think: thinkTool(),
31704
+ type: typeTool(v3, provider),
31705
+ wait: waitTool(v3)
31043
31706
  };
31707
+ if (process.env.BRAVE_API_KEY) {
31708
+ allTools.search = searchTool(v3);
31709
+ }
31710
+ return filterToolsByMode(allTools, mode);
31711
+ }
31712
+
31713
+ // lib/v3/agent/prompts/agentSystemPrompt.ts
31714
+ function buildAgentSystemPrompt(options) {
31715
+ const {
31716
+ url,
31717
+ executionInstruction,
31718
+ mode,
31719
+ systemInstructions,
31720
+ isBrowserbase = false
31721
+ } = options;
31722
+ const localeDate = (/* @__PURE__ */ new Date()).toLocaleDateString();
31723
+ const isoDate = (/* @__PURE__ */ new Date()).toISOString();
31724
+ const cdata = (text) => `<![CDATA[${text}]]>`;
31725
+ const isHybridMode = mode === "hybrid";
31726
+ const hasSearch = Boolean(process.env.BRAVE_API_KEY);
31727
+ const searchToolLine = hasSearch ? `
31728
+ <tool name="search">Perform a web search and return results. Prefer this over navigating to Google and searching within the page for reliability and efficiency.</tool>` : "";
31729
+ const toolsSection = isHybridMode ? `<tools>
31730
+ <tool name="screenshot">Take a compressed JPEG screenshot for quick visual context</tool>
31731
+ <tool name="ariaTree">Get an accessibility (ARIA) hybrid tree for full page context</tool>
31732
+ <tool name="click">Click on an element (PREFERRED - more reliable when element is visible in viewport)</tool>
31733
+ <tool name="type">Type text into an element (PREFERRED - more reliable when element is visible in viewport)</tool>
31734
+ <tool name="act">Perform a specific atomic action (click, type, etc.) - ONLY use when element is in ariaTree but NOT visible in screenshot. Less reliable but can interact with out-of-viewport elements.</tool>
31735
+ <tool name="dragAndDrop">Drag and drop an element</tool>
31736
+ <tool name="clickAndHold">Click and hold on an element</tool>
31737
+ <tool name="keys">Press a keyboard key</tool>
31738
+ <tool name="fillFormVision">Fill out a form using coordinates</tool>
31739
+ <tool name="think">Think about the task</tool>
31740
+ <tool name="extract">Extract structured data</tool>
31741
+ <tool name="goto">Navigate to a URL</tool>
31742
+ <tool name="wait|navback">Control timing and navigation</tool>
31743
+ <tool name="scroll">Scroll the page x pixels up or down</tool>
31744
+ ${searchToolLine}
31745
+ </tools>` : `<tools>
31746
+ <tool name="screenshot">Take a compressed JPEG screenshot for quick visual context</tool>
31747
+ <tool name="ariaTree">Get an accessibility (ARIA) hybrid tree for full page context</tool>
31748
+ <tool name="act">Perform a specific atomic action (click, type)</tool>
31749
+ <tool name="keys">Press a keyboard key</tool>
31750
+ <tool name="fillForm">Fill out a form</tool>
31751
+ <tool name="think">Think about the task</tool>
31752
+ <tool name="extract">Extract structured data</tool>
31753
+ <tool name="goto">Navigate to a URL</tool>
31754
+ <tool name="wait|navback">Control timing and navigation</tool>
31755
+ <tool name="scroll">Scroll the page x pixels up or down</tool>
31756
+ ${searchToolLine}
31757
+ </tools>`;
31758
+ const strategyItems = isHybridMode ? [
31759
+ `<item>Tool selection priority: Use specific tools (click, type) when elements are visible in viewport for maximum reliability.</item>`,
31760
+ `<item>Always use screenshot to get proper grounding of the coordinates you want to type/click into.</item>`,
31761
+ `<item>When interacting with an input, always use the type tool to type into the input, over clicking and then typing into it.</item>`,
31762
+ `<item>Use ariaTree as a secondary tool when elements aren't visible in screenshot or to get full page context.</item>`,
31763
+ `<item>Only use act when element is in ariaTree but NOT visible in screenshot.</item>`
31764
+ ] : [
31765
+ `<item>Tool selection priority: Use act tool for all clicking and typing on a page.</item>`,
31766
+ `<item>Always check ariaTree first to understand full page content without scrolling - it shows all elements including those below the fold.</item>`,
31767
+ `<item>When interacting with an input, always use the act tool to type into the input, over clicking and then typing.</item>`,
31768
+ `<item>If an element is present in the ariaTree, use act to interact with it directly - this eliminates the need to scroll.</item>`,
31769
+ `<item>Use screenshot for visual confirmation when needed, but rely primarily on ariaTree for element detection.</item>`
31770
+ ];
31771
+ const strategySection = strategyItems.join("\n ");
31772
+ const commonStrategyItems = `
31773
+ <item>CRITICAL: Use extract ONLY when the task explicitly requires structured data output (e.g., "get job listings", "extract product details"). For reading page content or understanding elements, always use ${isHybridMode ? "screenshot or ariaTree" : "ariaTree"} instead - it's faster and more reliable.</item>
31774
+ <item>Keep actions atomic and verify outcomes before proceeding.</item>
31775
+ <item>For each action, provide clear reasoning about why you're taking that step.</item>
31776
+ <item>When you need to input text that could be entered character-by-character or through multiple separate inputs, prefer using the keys tool to type the entire sequence at once. This is more efficient for scenarios like verification codes split across multiple fields, or when virtual keyboards are present but direct typing would be faster.</item>
31777
+ `;
31778
+ const pageUnderstandingProtocol = isHybridMode ? `<page_understanding_protocol>
31779
+ <step_1>
31780
+ <title>UNDERSTAND THE PAGE</title>
31781
+ <primary_tool>
31782
+ <name>screenshot</name>
31783
+ <usage>Visual confirmation when needed. Ideally after navigating to a new page.</usage>
31784
+ </primary_tool>
31785
+ <secondary_tool>
31786
+ <name>ariaTree</name>
31787
+ <usage>Get complete page context before taking actions</usage>
31788
+ <benefit>Eliminates the need to scroll and provides full accessible content</benefit>
31789
+ </secondary_tool>
31790
+ </step_1>
31791
+ </page_understanding_protocol>` : `<page_understanding_protocol>
31792
+ <step_1>
31793
+ <title>UNDERSTAND THE PAGE</title>
31794
+ <primary_tool>
31795
+ <name>ariaTree</name>
31796
+ <usage>Get complete page context before taking actions</usage>
31797
+ <benefit>Eliminates the need to scroll and provides full accessible content</benefit>
31798
+ </primary_tool>
31799
+ <secondary_tool>
31800
+ <name>screenshot</name>
31801
+ <usage>Visual confirmation when needed. Ideally after navigating to a new page.</usage>
31802
+ </secondary_tool>
31803
+ </step_1>
31804
+ </page_understanding_protocol>`;
31805
+ const roadblocksSection = isBrowserbase ? `<roadblocks>
31806
+ <note>captchas, popups, etc.</note>
31807
+ <captcha>If you see a captcha, use the wait tool. It will automatically be solved by our internal solver.</captcha>
31808
+ </roadblocks>` : "";
31809
+ const customInstructionsBlock = systemInstructions ? `<customInstructions>${cdata(systemInstructions)}</customInstructions>
31810
+ ` : "";
31811
+ return `<system>
31812
+ <identity>You are a web automation assistant using browser automation tools to accomplish the user's goal.</identity>
31813
+ ${customInstructionsBlock}<task>
31814
+ <goal>${cdata(executionInstruction)}</goal>
31815
+ <date display="local" iso="${isoDate}">${localeDate}</date>
31816
+ <note>You may think the date is different due to knowledge cutoff, but this is the actual date.</note>
31817
+ </task>
31818
+ <page>
31819
+ <startingUrl>you are starting your task on this url: ${url}</startingUrl>
31820
+ </page>
31821
+ <mindset>
31822
+ <note>Be very intentional about your action. The initial instruction is very important, and slight variations of the actual goal can lead to failures.</note>
31823
+ <importantNote>If something fails to meet a single condition of the task, move on from it rather than seeing if it meets other criteria. We only care that it meets all of it</importantNote>
31824
+ <note>When the task is complete, do not seek more information; you have completed the task.</note>
31825
+ </mindset>
31826
+ <guidelines>
31827
+ <item>Always start by understanding the current page state</item>
31828
+ <item>Use the screenshot tool to verify page state when needed</item>
31829
+ <item>Use appropriate tools for each action</item>
31830
+ <item>When the task is complete, use the "close" tool with taskComplete: true</item>
31831
+ <item>If the task cannot be completed, use "close" with taskComplete: false</item>
31832
+ </guidelines>
31833
+ ${pageUnderstandingProtocol}
31834
+ <navigation>
31835
+ <rule>If you are confident in the URL, navigate directly to it.</rule>
31836
+ ${hasSearch ? `<rule>If you are not confident in the URL, use the search tool to find it.</rule>` : ``}
31837
+ </navigation>
31838
+ ${toolsSection}
31839
+ <strategy>
31840
+ ${strategySection}
31841
+ ${commonStrategyItems}
31842
+ </strategy>
31843
+ ${roadblocksSection}
31844
+ <completion>
31845
+ <note>When you complete the task, explain any information that was found that was relevant to the original task.</note>
31846
+ <examples>
31847
+ <example>If you were asked for specific flights, list the flights you found.</example>
31848
+ <example>If you were asked for information about a product, list the product information you were asked for.</example>
31849
+ </examples>
31850
+ </completion>
31851
+ </system>`;
31044
31852
  }
31045
31853
 
31046
31854
  // lib/v3/handlers/v3AgentHandler.ts
31047
- var import_ai11 = require("ai");
31855
+ var import_ai19 = require("ai");
31048
31856
 
31049
31857
  // lib/v3/agent/utils/messageProcessing.ts
31050
31858
  function isToolMessage(message) {
@@ -31243,13 +32051,14 @@ function getErrorMessage(error) {
31243
32051
  return error instanceof Error ? error.message : String(error);
31244
32052
  }
31245
32053
  var V3AgentHandler = class {
31246
- constructor(v3, logger, llmClient, executionModel, systemInstructions, mcpTools) {
32054
+ constructor(v3, logger, llmClient, executionModel, systemInstructions, mcpTools, mode) {
31247
32055
  this.v3 = v3;
31248
32056
  this.logger = logger;
31249
32057
  this.llmClient = llmClient;
31250
32058
  this.executionModel = executionModel;
31251
32059
  this.systemInstructions = systemInstructions;
31252
32060
  this.mcpTools = mcpTools;
32061
+ this.mode = mode != null ? mode : "dom";
31253
32062
  }
31254
32063
  prepareAgent(instructionOrOptions) {
31255
32064
  return __async(this, null, function* () {
@@ -31257,10 +32066,14 @@ var V3AgentHandler = class {
31257
32066
  try {
31258
32067
  const options = typeof instructionOrOptions === "string" ? { instruction: instructionOrOptions } : instructionOrOptions;
31259
32068
  const maxSteps = options.maxSteps || 20;
31260
- const systemPrompt = this.buildSystemPrompt(
31261
- options.instruction,
31262
- this.systemInstructions
31263
- );
32069
+ const initialPageUrl = (yield this.v3.context.awaitActivePage()).url();
32070
+ const systemPrompt = buildAgentSystemPrompt({
32071
+ url: initialPageUrl,
32072
+ executionInstruction: options.instruction,
32073
+ mode: this.mode,
32074
+ systemInstructions: this.systemInstructions,
32075
+ isBrowserbase: this.v3.isBrowserbase
32076
+ });
31264
32077
  const tools = this.createTools();
31265
32078
  const allTools = __spreadValues(__spreadValues({}, tools), this.mcpTools);
31266
32079
  const messages = ((_a4 = options.messages) == null ? void 0 : _a4.length) ? [...options.messages, { role: "user", content: options.instruction }] : [{ role: "user", content: options.instruction }];
@@ -31268,7 +32081,7 @@ var V3AgentHandler = class {
31268
32081
  throw new MissingLLMConfigurationError();
31269
32082
  }
31270
32083
  const baseModel = this.llmClient.getLanguageModel();
31271
- const wrappedModel = (0, import_ai11.wrapLanguageModel)({
32084
+ const wrappedModel = (0, import_ai19.wrapLanguageModel)({
31272
32085
  model: baseModel,
31273
32086
  middleware: __spreadValues({
31274
32087
  transformParams: (_0) => __async(this, [_0], function* ({ params }) {
@@ -31277,7 +32090,6 @@ var V3AgentHandler = class {
31277
32090
  })
31278
32091
  }, SessionFileLogger.createLlmLoggingMiddleware(baseModel.modelId))
31279
32092
  });
31280
- const initialPageUrl = (yield this.v3.context.awaitActivePage()).url();
31281
32093
  return {
31282
32094
  options,
31283
32095
  maxSteps,
@@ -31339,14 +32151,16 @@ var V3AgentHandler = class {
31339
32151
  }
31340
32152
  }
31341
32153
  state.currentPageUrl = (yield this.v3.context.awaitActivePage()).url();
31342
- try {
31343
- yield this.captureAndEmitScreenshot();
31344
- } catch (e2) {
31345
- this.logger({
31346
- category: "agent",
31347
- message: `Warning: Failed to capture screenshot: ${getErrorMessage(e2)}`,
31348
- level: 1
31349
- });
32154
+ if (process.env.EVALS === "true") {
32155
+ try {
32156
+ yield this.captureAndEmitScreenshot();
32157
+ } catch (e2) {
32158
+ this.logger({
32159
+ category: "agent",
32160
+ message: `Warning: Failed to capture screenshot: ${getErrorMessage(e2)}`,
32161
+ level: 1
32162
+ });
32163
+ }
31350
32164
  }
31351
32165
  }
31352
32166
  if (userCallback) {
@@ -31356,8 +32170,11 @@ var V3AgentHandler = class {
31356
32170
  }
31357
32171
  execute(instructionOrOptions) {
31358
32172
  return __async(this, null, function* () {
32173
+ var _a4;
31359
32174
  const startTime = Date.now();
31360
- const signal = typeof instructionOrOptions === "object" ? instructionOrOptions.signal : void 0;
32175
+ const options = typeof instructionOrOptions === "object" ? instructionOrOptions : null;
32176
+ const signal = options == null ? void 0 : options.signal;
32177
+ const shouldHighlightCursor = (_a4 = options == null ? void 0 : options.highlightCursor) != null ? _a4 : this.mode === "hybrid";
31361
32178
  const state = {
31362
32179
  collectedReasoning: [],
31363
32180
  actions: [],
@@ -31368,7 +32185,7 @@ var V3AgentHandler = class {
31368
32185
  let messages = [];
31369
32186
  try {
31370
32187
  const {
31371
- options,
32188
+ options: preparedOptions,
31372
32189
  maxSteps,
31373
32190
  systemPrompt,
31374
32191
  allTools,
@@ -31376,6 +32193,11 @@ var V3AgentHandler = class {
31376
32193
  wrappedModel,
31377
32194
  initialPageUrl
31378
32195
  } = yield this.prepareAgent(instructionOrOptions);
32196
+ if (shouldHighlightCursor && this.mode === "hybrid") {
32197
+ const page = yield this.v3.context.awaitActivePage();
32198
+ yield page.enableCursorOverlay().catch(() => {
32199
+ });
32200
+ }
31379
32201
  messages = preparedMessages;
31380
32202
  state.currentPageUrl = initialPageUrl;
31381
32203
  const callbacks = instructionOrOptions.callbacks;
@@ -31403,7 +32225,7 @@ var V3AgentHandler = class {
31403
32225
  toolChoice: "auto",
31404
32226
  prepareStep: callbacks == null ? void 0 : callbacks.prepareStep,
31405
32227
  onStepFinish: this.createStepHandler(state, callbacks == null ? void 0 : callbacks.onStepFinish),
31406
- abortSignal: options.signal
32228
+ abortSignal: preparedOptions.signal
31407
32229
  });
31408
32230
  return this.consolidateMetricsAndResult(
31409
32231
  startTime,
@@ -31437,6 +32259,9 @@ var V3AgentHandler = class {
31437
32259
  }
31438
32260
  stream(instructionOrOptions) {
31439
32261
  return __async(this, null, function* () {
32262
+ var _a4;
32263
+ const streamOptions = typeof instructionOrOptions === "object" ? instructionOrOptions : null;
32264
+ const shouldHighlightCursor = (_a4 = streamOptions == null ? void 0 : streamOptions.highlightCursor) != null ? _a4 : this.mode === "hybrid";
31440
32265
  const {
31441
32266
  options,
31442
32267
  maxSteps,
@@ -31446,6 +32271,11 @@ var V3AgentHandler = class {
31446
32271
  wrappedModel,
31447
32272
  initialPageUrl
31448
32273
  } = yield this.prepareAgent(instructionOrOptions);
32274
+ if (shouldHighlightCursor && this.mode === "hybrid") {
32275
+ const page = yield this.v3.context.awaitActivePage();
32276
+ yield page.enableCursorOverlay().catch(() => {
32277
+ });
32278
+ }
31449
32279
  const callbacks = instructionOrOptions.callbacks;
31450
32280
  const state = {
31451
32281
  collectedReasoning: [],
@@ -31500,11 +32330,11 @@ var V3AgentHandler = class {
31500
32330
  resolveResult(result);
31501
32331
  },
31502
32332
  onAbort: (event) => {
31503
- var _a4;
32333
+ var _a5;
31504
32334
  if (callbacks == null ? void 0 : callbacks.onAbort) {
31505
32335
  callbacks.onAbort(event);
31506
32336
  }
31507
- const reason = ((_a4 = options.signal) == null ? void 0 : _a4.reason) ? String(options.signal.reason) : "Stream was aborted";
32337
+ const reason = ((_a5 = options.signal) == null ? void 0 : _a5.reason) ? String(options.signal.reason) : "Stream was aborted";
31508
32338
  rejectResult(new AgentAbortError(reason));
31509
32339
  },
31510
32340
  abortSignal: options.signal
@@ -31552,41 +32382,14 @@ var V3AgentHandler = class {
31552
32382
  messages: fullMessages
31553
32383
  };
31554
32384
  }
31555
- buildSystemPrompt(executionInstruction, systemInstructions) {
31556
- if (systemInstructions) {
31557
- return `${systemInstructions}
31558
- Your current goal: ${executionInstruction} when the task is complete, use the "close" tool with taskComplete: true`;
31559
- }
31560
- return `You are a web automation assistant using browser automation tools to accomplish the user's goal.
31561
-
31562
- Your task: ${executionInstruction}
31563
-
31564
- You have access to various browser automation tools. Use them step by step to complete the task.
31565
-
31566
- IMPORTANT GUIDELINES:
31567
- 1. Always start by understanding the current page state
31568
- 2. Use the screenshot tool to verify page state when needed
31569
- 3. Use appropriate tools for each action
31570
- 4. When the task is complete, use the "close" tool with taskComplete: true
31571
- 5. If the task cannot be completed, use "close" with taskComplete: false
31572
-
31573
- TOOLS OVERVIEW:
31574
- - screenshot: Take a PNG screenshot for quick visual context (use sparingly)
31575
- - ariaTree: Get an accessibility (ARIA) hybrid tree for full page context
31576
- - act: Perform a specific atomic action (click, type, etc.)
31577
- - extract: Extract structured data
31578
- - goto: Navigate to a URL
31579
- - wait/navback/refresh: Control timing and navigation
31580
- - scroll: Scroll the page x pixels up or down
31581
-
31582
- STRATEGY:
31583
- - Prefer ariaTree to understand the page before acting; use screenshot for confirmation.
31584
- - Keep actions atomic and verify outcomes before proceeding.`;
31585
- }
31586
32385
  createTools() {
32386
+ var _a4, _b, _c;
32387
+ const provider = (_c = (_b = (_a4 = this.llmClient) == null ? void 0 : _a4.getLanguageModel) == null ? void 0 : _b.call(_a4)) == null ? void 0 : _c.provider;
31587
32388
  return createAgentTools(this.v3, {
31588
32389
  executionModel: this.executionModel,
31589
- logger: this.logger
32390
+ logger: this.logger,
32391
+ mode: this.mode,
32392
+ provider
31590
32393
  });
31591
32394
  }
31592
32395
  handleStop(result, maxSteps) {
@@ -31595,7 +32398,7 @@ STRATEGY:
31595
32398
  if ((_a4 = lastStep == null ? void 0 : lastStep.toolCalls) == null ? void 0 : _a4.some((tc) => tc.toolName === "close")) {
31596
32399
  return true;
31597
32400
  }
31598
- return (0, import_ai11.stepCountIs)(maxSteps)(result);
32401
+ return (0, import_ai19.stepCountIs)(maxSteps)(result);
31599
32402
  }
31600
32403
  /**
31601
32404
  * Capture a screenshot and emit it via the event bus
@@ -32077,8 +32880,8 @@ var AnthropicCUAClient = class extends AgentClient {
32077
32880
  betas: ["computer-use-2025-01-24"]
32078
32881
  };
32079
32882
  if (this.tools && Object.keys(this.tools).length > 0) {
32080
- const customTools = Object.entries(this.tools).map(([name, tool13]) => {
32081
- const schema = tool13.inputSchema;
32883
+ const customTools = Object.entries(this.tools).map(([name, tool21]) => {
32884
+ const schema = tool21.inputSchema;
32082
32885
  const jsonSchema3 = toJsonSchema(schema);
32083
32886
  const inputSchema = {
32084
32887
  type: "object",
@@ -32087,7 +32890,7 @@ var AnthropicCUAClient = class extends AgentClient {
32087
32890
  };
32088
32891
  return {
32089
32892
  name,
32090
- description: tool13.description,
32893
+ description: tool21.description,
32091
32894
  input_schema: inputSchema
32092
32895
  };
32093
32896
  });
@@ -32205,13 +33008,13 @@ var AnthropicCUAClient = class extends AgentClient {
32205
33008
  let toolResult = "Tool executed successfully";
32206
33009
  if (this.tools && item.name in this.tools) {
32207
33010
  try {
32208
- const tool13 = this.tools[item.name];
33011
+ const tool21 = this.tools[item.name];
32209
33012
  logger({
32210
33013
  category: "agent",
32211
33014
  message: `Executing tool call: ${item.name} with args: ${JSON.stringify(item.input)}`,
32212
33015
  level: 1
32213
33016
  });
32214
- const result = yield tool13.execute(item.input, {
33017
+ const result = yield tool21.execute(item.input, {
32215
33018
  toolCallId: item.id,
32216
33019
  messages: []
32217
33020
  });
@@ -32733,13 +33536,13 @@ var OpenAICUAClient = class extends AgentClient {
32733
33536
  truncation: "auto"
32734
33537
  };
32735
33538
  if (this.tools && Object.keys(this.tools).length > 0) {
32736
- const customTools = Object.entries(this.tools).map(([name, tool13]) => ({
33539
+ const customTools = Object.entries(this.tools).map(([name, tool21]) => ({
32737
33540
  type: "function",
32738
33541
  name,
32739
33542
  function: {
32740
33543
  name,
32741
- description: tool13.description,
32742
- parameters: tool13.inputSchema
33544
+ description: tool21.description,
33545
+ parameters: tool21.inputSchema
32743
33546
  }
32744
33547
  }));
32745
33548
  requestParams.tools = [
@@ -32879,14 +33682,14 @@ var OpenAICUAClient = class extends AgentClient {
32879
33682
  let toolResult = "Tool executed successfully";
32880
33683
  if (this.tools && item.name in this.tools) {
32881
33684
  try {
32882
- const tool13 = this.tools[item.name];
33685
+ const tool21 = this.tools[item.name];
32883
33686
  const args = JSON.parse(item.arguments);
32884
33687
  logger({
32885
33688
  category: "agent",
32886
33689
  message: `Executing tool call: ${item.name} with args: ${item.arguments}`,
32887
33690
  level: 1
32888
33691
  });
32889
- const result = yield tool13.execute(args, {
33692
+ const result = yield tool21.execute(args, {
32890
33693
  toolCallId: item.call_id,
32891
33694
  messages: []
32892
33695
  });
@@ -33042,8 +33845,8 @@ function executeGoogleCustomTool(toolName, toolArgs, tools, functionCall, logger
33042
33845
  message: `Executing custom tool: ${toolName} with args: ${JSON.stringify(toolArgs)}`,
33043
33846
  level: 1
33044
33847
  });
33045
- const tool13 = tools[toolName];
33046
- const toolResult = yield tool13.execute(toolArgs, {
33848
+ const tool21 = tools[toolName];
33849
+ const toolResult = yield tool21.execute(toolArgs, {
33047
33850
  toolCallId: `tool_${Date.now()}`,
33048
33851
  messages: []
33049
33852
  });
@@ -33091,22 +33894,22 @@ function isCustomTool(functionCall, tools) {
33091
33894
  }
33092
33895
  function convertToolSetToFunctionDeclarations(tools) {
33093
33896
  const functionDeclarations = [];
33094
- for (const [name, tool13] of Object.entries(tools)) {
33095
- const functionDeclaration = convertToolToFunctionDeclaration(name, tool13);
33897
+ for (const [name, tool21] of Object.entries(tools)) {
33898
+ const functionDeclaration = convertToolToFunctionDeclaration(name, tool21);
33096
33899
  if (functionDeclaration) {
33097
33900
  functionDeclarations.push(functionDeclaration);
33098
33901
  }
33099
33902
  }
33100
33903
  return functionDeclarations;
33101
33904
  }
33102
- function convertToolToFunctionDeclaration(name, tool13) {
33905
+ function convertToolToFunctionDeclaration(name, tool21) {
33103
33906
  try {
33104
- const schema = tool13.inputSchema;
33907
+ const schema = tool21.inputSchema;
33105
33908
  const jsonSchema3 = toJsonSchema(schema);
33106
33909
  const parameters = convertJsonSchemaToGoogleParameters(jsonSchema3);
33107
33910
  return {
33108
33911
  name,
33109
- description: tool13.description || `Execute ${name}`,
33912
+ description: tool21.description || `Execute ${name}`,
33110
33913
  parameters
33111
33914
  };
33112
33915
  } catch (error) {
@@ -36234,23 +37037,23 @@ function waitForWebSocketDebuggerUrl(port, timeoutMs) {
36234
37037
  init_sdkErrors();
36235
37038
 
36236
37039
  // lib/v3/llm/aisdk.ts
36237
- var import_ai13 = require("ai");
37040
+ var import_ai21 = require("ai");
36238
37041
  var import_uuid5 = require("uuid");
36239
37042
 
36240
37043
  // lib/v3/llm/LLMClient.ts
36241
- var import_ai12 = require("ai");
37044
+ var import_ai20 = require("ai");
36242
37045
  var AnnotatedScreenshotText = "This is a screenshot of the current page state with the elements annotated on it. Each element id is annotated with a number to the top left of it. Duplicate annotations at the same location are under each other vertically.";
36243
37046
  var LLMClient = class {
36244
37047
  constructor(modelName, userProvidedInstructions) {
36245
- this.generateObject = import_ai12.generateObject;
36246
- this.generateText = import_ai12.generateText;
36247
- this.streamText = import_ai12.streamText;
36248
- this.streamObject = import_ai12.streamObject;
36249
- this.generateImage = import_ai12.experimental_generateImage;
36250
- this.embed = import_ai12.embed;
36251
- this.embedMany = import_ai12.embedMany;
36252
- this.transcribe = import_ai12.experimental_transcribe;
36253
- this.generateSpeech = import_ai12.experimental_generateSpeech;
37048
+ this.generateObject = import_ai20.generateObject;
37049
+ this.generateText = import_ai20.generateText;
37050
+ this.streamText = import_ai20.streamText;
37051
+ this.streamObject = import_ai20.streamObject;
37052
+ this.generateImage = import_ai20.experimental_generateImage;
37053
+ this.embed = import_ai20.embed;
37054
+ this.embedMany = import_ai20.embedMany;
37055
+ this.transcribe = import_ai20.experimental_transcribe;
37056
+ this.generateSpeech = import_ai20.experimental_generateSpeech;
36254
37057
  this.modelName = modelName;
36255
37058
  this.userProvidedInstructions = userProvidedInstructions;
36256
37059
  }
@@ -36362,7 +37165,7 @@ var AISdkClient = class extends LLMClient {
36362
37165
  prompt: promptPreview2
36363
37166
  });
36364
37167
  try {
36365
- objectResponse = yield (0, import_ai13.generateObject)({
37168
+ objectResponse = yield (0, import_ai21.generateObject)({
36366
37169
  model: this.model,
36367
37170
  messages: formattedMessages,
36368
37171
  schema: options.response_model.schema,
@@ -36382,7 +37185,7 @@ var AISdkClient = class extends LLMClient {
36382
37185
  operation: "generateObject",
36383
37186
  output: `[error: ${err instanceof Error ? err.message : "unknown"}]`
36384
37187
  });
36385
- if (import_ai13.NoObjectGeneratedError.isInstance(err)) {
37188
+ if (import_ai21.NoObjectGeneratedError.isInstance(err)) {
36386
37189
  (_g = this.logger) == null ? void 0 : _g.call(this, {
36387
37190
  category: "AISDK error",
36388
37191
  message: err.message,
@@ -36460,10 +37263,10 @@ var AISdkClient = class extends LLMClient {
36460
37263
  }
36461
37264
  const tools = {};
36462
37265
  if (options.tools && options.tools.length > 0) {
36463
- for (const tool13 of options.tools) {
36464
- tools[tool13.name] = {
36465
- description: tool13.description,
36466
- inputSchema: tool13.parameters
37266
+ for (const tool21 of options.tools) {
37267
+ tools[tool21.name] = {
37268
+ description: tool21.description,
37269
+ inputSchema: tool21.parameters
36467
37270
  };
36468
37271
  }
36469
37272
  }
@@ -36480,7 +37283,7 @@ var AISdkClient = class extends LLMClient {
36480
37283
  });
36481
37284
  let textResponse;
36482
37285
  try {
36483
- textResponse = yield (0, import_ai13.generateText)({
37286
+ textResponse = yield (0, import_ai21.generateText)({
36484
37287
  model: this.model,
36485
37288
  messages: formattedMessages,
36486
37289
  tools: Object.keys(tools).length > 0 ? tools : void 0,
@@ -36662,14 +37465,14 @@ var AnthropicClient = class extends LLMClient {
36662
37465
  }
36663
37466
  formattedMessages.push(screenshotMessage);
36664
37467
  }
36665
- let anthropicTools2 = (_a4 = options.tools) == null ? void 0 : _a4.map((tool13) => {
37468
+ let anthropicTools2 = (_a4 = options.tools) == null ? void 0 : _a4.map((tool21) => {
36666
37469
  return {
36667
- name: tool13.name,
36668
- description: tool13.description,
37470
+ name: tool21.name,
37471
+ description: tool21.description,
36669
37472
  input_schema: {
36670
37473
  type: "object",
36671
- properties: tool13.parameters.properties,
36672
- required: tool13.parameters.required
37474
+ properties: tool21.parameters.properties,
37475
+ required: tool21.parameters.required
36673
37476
  }
36674
37477
  };
36675
37478
  });
@@ -36856,15 +37659,15 @@ var CerebrasClient = class extends LLMClient {
36856
37659
  return __spreadProps(__spreadValues({}, baseMessage), { role: "user" });
36857
37660
  }
36858
37661
  });
36859
- let tools = (_a4 = options.tools) == null ? void 0 : _a4.map((tool13) => ({
37662
+ let tools = (_a4 = options.tools) == null ? void 0 : _a4.map((tool21) => ({
36860
37663
  type: "function",
36861
37664
  function: {
36862
- name: tool13.name,
36863
- description: tool13.description,
37665
+ name: tool21.name,
37666
+ description: tool21.description,
36864
37667
  parameters: {
36865
37668
  type: "object",
36866
- properties: tool13.parameters.properties,
36867
- required: tool13.parameters.required
37669
+ properties: tool21.parameters.properties,
37670
+ required: tool21.parameters.required
36868
37671
  }
36869
37672
  }
36870
37673
  }));
@@ -37157,18 +37960,18 @@ ${firstPartText.text}`;
37157
37960
  }
37158
37961
  return [
37159
37962
  {
37160
- functionDeclarations: tools.map((tool13) => {
37963
+ functionDeclarations: tools.map((tool21) => {
37161
37964
  let parameters = void 0;
37162
- if (tool13.parameters) {
37965
+ if (tool21.parameters) {
37163
37966
  parameters = {
37164
37967
  type: import_genai4.Type.OBJECT,
37165
- properties: tool13.parameters.properties,
37166
- required: tool13.parameters.required
37968
+ properties: tool21.parameters.properties,
37969
+ required: tool21.parameters.required
37167
37970
  };
37168
37971
  }
37169
37972
  return {
37170
- name: tool13.name,
37171
- description: tool13.description,
37973
+ name: tool21.name,
37974
+ description: tool21.description,
37172
37975
  parameters
37173
37976
  };
37174
37977
  })
@@ -37444,15 +38247,15 @@ var GroqClient = class extends LLMClient {
37444
38247
  return __spreadProps(__spreadValues({}, baseMessage), { role: "user" });
37445
38248
  }
37446
38249
  });
37447
- let tools = (_a4 = options.tools) == null ? void 0 : _a4.map((tool13) => ({
38250
+ let tools = (_a4 = options.tools) == null ? void 0 : _a4.map((tool21) => ({
37448
38251
  type: "function",
37449
38252
  function: {
37450
- name: tool13.name,
37451
- description: tool13.description,
38253
+ name: tool21.name,
38254
+ description: tool21.description,
37452
38255
  parameters: {
37453
38256
  type: "object",
37454
- properties: tool13.parameters.properties,
37455
- required: tool13.parameters.required
38257
+ properties: tool21.parameters.properties,
38258
+ required: tool21.parameters.required
37456
38259
  }
37457
38260
  }
37458
38261
  }));
@@ -37829,11 +38632,11 @@ ${parsedSchema}
37829
38632
  messages: formattedMessages,
37830
38633
  response_format: responseFormat,
37831
38634
  stream: false,
37832
- tools: (_e = options.tools) == null ? void 0 : _e.map((tool13) => ({
38635
+ tools: (_e = options.tools) == null ? void 0 : _e.map((tool21) => ({
37833
38636
  function: {
37834
- name: tool13.name,
37835
- description: tool13.description,
37836
- parameters: tool13.parameters
38637
+ name: tool21.name,
38638
+ description: tool21.description,
38639
+ parameters: tool21.parameters
37837
38640
  },
37838
38641
  type: "function"
37839
38642
  }))
@@ -38626,7 +39429,7 @@ var postToApi = (_0) => __async(null, [_0], function* ({
38626
39429
  throw handleFetchError({ error, url, requestBodyValues: body.values });
38627
39430
  }
38628
39431
  });
38629
- function tool11(tool22) {
39432
+ function tool19(tool22) {
38630
39433
  return tool22;
38631
39434
  }
38632
39435
  function createProviderDefinedToolFactory({
@@ -38650,7 +39453,7 @@ function createProviderDefinedToolFactory({
38650
39453
  "onInputDelta",
38651
39454
  "onInputAvailable"
38652
39455
  ]);
38653
- return tool11({
39456
+ return tool19({
38654
39457
  type: "provider-defined",
38655
39458
  id,
38656
39459
  name,
@@ -38685,7 +39488,7 @@ function createProviderDefinedToolFactoryWithOutputSchema({
38685
39488
  "onInputDelta",
38686
39489
  "onInputAvailable"
38687
39490
  ]);
38688
- return tool11({
39491
+ return tool19({
38689
39492
  type: "provider-defined",
38690
39493
  id,
38691
39494
  name,
@@ -40499,21 +41302,21 @@ function prepareChatTools({
40499
41302
  return { tools: void 0, toolChoice: void 0, toolWarnings };
40500
41303
  }
40501
41304
  const openaiTools2 = [];
40502
- for (const tool13 of tools) {
40503
- switch (tool13.type) {
41305
+ for (const tool21 of tools) {
41306
+ switch (tool21.type) {
40504
41307
  case "function":
40505
41308
  openaiTools2.push({
40506
41309
  type: "function",
40507
41310
  function: {
40508
- name: tool13.name,
40509
- description: tool13.description,
40510
- parameters: tool13.inputSchema,
41311
+ name: tool21.name,
41312
+ description: tool21.description,
41313
+ parameters: tool21.inputSchema,
40511
41314
  strict: structuredOutputs ? strictJsonSchema : void 0
40512
41315
  }
40513
41316
  });
40514
41317
  break;
40515
41318
  default:
40516
- toolWarnings.push({ type: "unsupported-tool", tool: tool13 });
41319
+ toolWarnings.push({ type: "unsupported-tool", tool: tool21 });
40517
41320
  break;
40518
41321
  }
40519
41322
  }
@@ -42829,22 +43632,22 @@ function prepareResponsesTools(_0) {
42829
43632
  return { tools: void 0, toolChoice: void 0, toolWarnings };
42830
43633
  }
42831
43634
  const openaiTools2 = [];
42832
- for (const tool13 of tools) {
42833
- switch (tool13.type) {
43635
+ for (const tool21 of tools) {
43636
+ switch (tool21.type) {
42834
43637
  case "function":
42835
43638
  openaiTools2.push({
42836
43639
  type: "function",
42837
- name: tool13.name,
42838
- description: tool13.description,
42839
- parameters: tool13.inputSchema,
43640
+ name: tool21.name,
43641
+ description: tool21.description,
43642
+ parameters: tool21.inputSchema,
42840
43643
  strict: strictJsonSchema
42841
43644
  });
42842
43645
  break;
42843
43646
  case "provider-defined": {
42844
- switch (tool13.id) {
43647
+ switch (tool21.id) {
42845
43648
  case "openai.file_search": {
42846
43649
  const args = yield validateTypes({
42847
- value: tool13.args,
43650
+ value: tool21.args,
42848
43651
  schema: fileSearchArgsSchema
42849
43652
  });
42850
43653
  openaiTools2.push({
@@ -42867,7 +43670,7 @@ function prepareResponsesTools(_0) {
42867
43670
  }
42868
43671
  case "openai.web_search_preview": {
42869
43672
  const args = yield validateTypes({
42870
- value: tool13.args,
43673
+ value: tool21.args,
42871
43674
  schema: webSearchPreviewArgsSchema
42872
43675
  });
42873
43676
  openaiTools2.push({
@@ -42879,7 +43682,7 @@ function prepareResponsesTools(_0) {
42879
43682
  }
42880
43683
  case "openai.web_search": {
42881
43684
  const args = yield validateTypes({
42882
- value: tool13.args,
43685
+ value: tool21.args,
42883
43686
  schema: webSearchArgsSchema
42884
43687
  });
42885
43688
  openaiTools2.push({
@@ -42892,7 +43695,7 @@ function prepareResponsesTools(_0) {
42892
43695
  }
42893
43696
  case "openai.code_interpreter": {
42894
43697
  const args = yield validateTypes({
42895
- value: tool13.args,
43698
+ value: tool21.args,
42896
43699
  schema: codeInterpreterArgsSchema
42897
43700
  });
42898
43701
  openaiTools2.push({
@@ -42903,7 +43706,7 @@ function prepareResponsesTools(_0) {
42903
43706
  }
42904
43707
  case "openai.image_generation": {
42905
43708
  const args = yield validateTypes({
42906
- value: tool13.args,
43709
+ value: tool21.args,
42907
43710
  schema: imageGenerationArgsSchema
42908
43711
  });
42909
43712
  openaiTools2.push({
@@ -42927,7 +43730,7 @@ function prepareResponsesTools(_0) {
42927
43730
  break;
42928
43731
  }
42929
43732
  default:
42930
- toolWarnings.push({ type: "unsupported-tool", tool: tool13 });
43733
+ toolWarnings.push({ type: "unsupported-tool", tool: tool21 });
42931
43734
  break;
42932
43735
  }
42933
43736
  }
@@ -43032,7 +43835,7 @@ var OpenAIResponsesLanguageModel = class {
43032
43835
  }
43033
43836
  function hasOpenAITool(id) {
43034
43837
  return (tools == null ? void 0 : tools.find(
43035
- (tool13) => tool13.type === "provider-defined" && tool13.id === id
43838
+ (tool21) => tool21.type === "provider-defined" && tool21.id === id
43036
43839
  )) != null;
43037
43840
  }
43038
43841
  const topLogprobs = typeof (openaiOptions == null ? void 0 : openaiOptions.logprobs) === "number" ? openaiOptions == null ? void 0 : openaiOptions.logprobs : (openaiOptions == null ? void 0 : openaiOptions.logprobs) === true ? TOP_LOGPROBS_MAX : void 0;
@@ -43040,7 +43843,7 @@ var OpenAIResponsesLanguageModel = class {
43040
43843
  addInclude("message.output_text.logprobs");
43041
43844
  }
43042
43845
  const webSearchToolName = (_c = tools == null ? void 0 : tools.find(
43043
- (tool13) => tool13.type === "provider-defined" && (tool13.id === "openai.web_search" || tool13.id === "openai.web_search_preview")
43846
+ (tool21) => tool21.type === "provider-defined" && (tool21.id === "openai.web_search" || tool21.id === "openai.web_search_preview")
43044
43847
  )) == null ? void 0 : _c.name;
43045
43848
  if (webSearchToolName) {
43046
43849
  addInclude("web_search_call.action.sources");
@@ -44894,7 +45697,7 @@ var postToApi2 = (_0) => __async(null, [_0], function* ({
44894
45697
  throw handleFetchError2({ error, url, requestBodyValues: body.values });
44895
45698
  }
44896
45699
  });
44897
- function tool12(tool22) {
45700
+ function tool20(tool22) {
44898
45701
  return tool22;
44899
45702
  }
44900
45703
  function createProviderDefinedToolFactory2({
@@ -44918,7 +45721,7 @@ function createProviderDefinedToolFactory2({
44918
45721
  "onInputDelta",
44919
45722
  "onInputAvailable"
44920
45723
  ]);
44921
- return tool12({
45724
+ return tool20({
44922
45725
  type: "provider-defined",
44923
45726
  id,
44924
45727
  name,
@@ -44953,7 +45756,7 @@ function createProviderDefinedToolFactoryWithOutputSchema2({
44953
45756
  "onInputDelta",
44954
45757
  "onInputAvailable"
44955
45758
  ]);
44956
- return tool12({
45759
+ return tool20({
44957
45760
  type: "provider-defined",
44958
45761
  id,
44959
45762
  name,
@@ -46634,25 +47437,25 @@ function prepareTools({
46634
47437
  if (tools == null) {
46635
47438
  return { tools: void 0, toolConfig: void 0, toolWarnings };
46636
47439
  }
46637
- const hasFunctionTools = tools.some((tool13) => tool13.type === "function");
47440
+ const hasFunctionTools = tools.some((tool21) => tool21.type === "function");
46638
47441
  const hasProviderDefinedTools = tools.some(
46639
- (tool13) => tool13.type === "provider-defined"
47442
+ (tool21) => tool21.type === "provider-defined"
46640
47443
  );
46641
47444
  if (hasFunctionTools && hasProviderDefinedTools) {
46642
- const functionTools = tools.filter((tool13) => tool13.type === "function");
47445
+ const functionTools = tools.filter((tool21) => tool21.type === "function");
46643
47446
  toolWarnings.push({
46644
47447
  type: "unsupported-tool",
46645
- tool: tools.find((tool13) => tool13.type === "function"),
47448
+ tool: tools.find((tool21) => tool21.type === "function"),
46646
47449
  details: `Cannot mix function tools with provider-defined tools in the same request. Falling back to provider-defined tools only. The following function tools will be ignored: ${functionTools.map((t2) => t2.name).join(", ")}. Please use either function tools or provider-defined tools, but not both.`
46647
47450
  });
46648
47451
  }
46649
47452
  if (hasProviderDefinedTools) {
46650
47453
  const googleTools22 = [];
46651
47454
  const providerDefinedTools = tools.filter(
46652
- (tool13) => tool13.type === "provider-defined"
47455
+ (tool21) => tool21.type === "provider-defined"
46653
47456
  );
46654
- providerDefinedTools.forEach((tool13) => {
46655
- switch (tool13.id) {
47457
+ providerDefinedTools.forEach((tool21) => {
47458
+ switch (tool21.id) {
46656
47459
  case "google.google_search":
46657
47460
  if (isGemini2orNewer) {
46658
47461
  googleTools22.push({ googleSearch: {} });
@@ -46660,8 +47463,8 @@ function prepareTools({
46660
47463
  googleTools22.push({
46661
47464
  googleSearchRetrieval: {
46662
47465
  dynamicRetrievalConfig: {
46663
- mode: tool13.args.mode,
46664
- dynamicThreshold: tool13.args.dynamicThreshold
47466
+ mode: tool21.args.mode,
47467
+ dynamicThreshold: tool21.args.dynamicThreshold
46665
47468
  }
46666
47469
  }
46667
47470
  });
@@ -46675,7 +47478,7 @@ function prepareTools({
46675
47478
  } else {
46676
47479
  toolWarnings.push({
46677
47480
  type: "unsupported-tool",
46678
- tool: tool13,
47481
+ tool: tool21,
46679
47482
  details: "The URL context tool is not supported with other Gemini models than Gemini 2."
46680
47483
  });
46681
47484
  }
@@ -46686,18 +47489,18 @@ function prepareTools({
46686
47489
  } else {
46687
47490
  toolWarnings.push({
46688
47491
  type: "unsupported-tool",
46689
- tool: tool13,
47492
+ tool: tool21,
46690
47493
  details: "The code execution tools is not supported with other Gemini models than Gemini 2."
46691
47494
  });
46692
47495
  }
46693
47496
  break;
46694
47497
  case "google.file_search":
46695
47498
  if (supportsFileSearch) {
46696
- googleTools22.push({ fileSearch: __spreadValues({}, tool13.args) });
47499
+ googleTools22.push({ fileSearch: __spreadValues({}, tool21.args) });
46697
47500
  } else {
46698
47501
  toolWarnings.push({
46699
47502
  type: "unsupported-tool",
46700
- tool: tool13,
47503
+ tool: tool21,
46701
47504
  details: "The file search tool is only supported with Gemini 2.5 models."
46702
47505
  });
46703
47506
  }
@@ -46708,22 +47511,22 @@ function prepareTools({
46708
47511
  retrieval: {
46709
47512
  vertex_rag_store: {
46710
47513
  rag_resources: {
46711
- rag_corpus: tool13.args.ragCorpus
47514
+ rag_corpus: tool21.args.ragCorpus
46712
47515
  },
46713
- similarity_top_k: tool13.args.topK
47516
+ similarity_top_k: tool21.args.topK
46714
47517
  }
46715
47518
  }
46716
47519
  });
46717
47520
  } else {
46718
47521
  toolWarnings.push({
46719
47522
  type: "unsupported-tool",
46720
- tool: tool13,
47523
+ tool: tool21,
46721
47524
  details: "The RAG store tool is not supported with other Gemini models than Gemini 2."
46722
47525
  });
46723
47526
  }
46724
47527
  break;
46725
47528
  default:
46726
- toolWarnings.push({ type: "unsupported-tool", tool: tool13 });
47529
+ toolWarnings.push({ type: "unsupported-tool", tool: tool21 });
46727
47530
  break;
46728
47531
  }
46729
47532
  });
@@ -46734,17 +47537,17 @@ function prepareTools({
46734
47537
  };
46735
47538
  }
46736
47539
  const functionDeclarations = [];
46737
- for (const tool13 of tools) {
46738
- switch (tool13.type) {
47540
+ for (const tool21 of tools) {
47541
+ switch (tool21.type) {
46739
47542
  case "function":
46740
47543
  functionDeclarations.push({
46741
- name: tool13.name,
46742
- description: (_a4 = tool13.description) != null ? _a4 : "",
46743
- parameters: convertJSONSchemaToOpenAPISchema(tool13.inputSchema)
47544
+ name: tool21.name,
47545
+ description: (_a4 = tool21.description) != null ? _a4 : "",
47546
+ parameters: convertJSONSchemaToOpenAPISchema(tool21.inputSchema)
46744
47547
  });
46745
47548
  break;
46746
47549
  default:
46747
- toolWarnings.push({ type: "unsupported-tool", tool: tool13 });
47550
+ toolWarnings.push({ type: "unsupported-tool", tool: tool21 });
46748
47551
  break;
46749
47552
  }
46750
47553
  }
@@ -46858,7 +47661,7 @@ var GoogleGenerativeAILanguageModel = class {
46858
47661
  schema: googleGenerativeAIProviderOptions
46859
47662
  });
46860
47663
  if ((tools == null ? void 0 : tools.some(
46861
- (tool13) => tool13.type === "provider-defined" && tool13.id === "google.vertex_rag_store"
47664
+ (tool21) => tool21.type === "provider-defined" && tool21.id === "google.vertex_rag_store"
46862
47665
  )) && !this.config.provider.startsWith("google.vertex.")) {
46863
47666
  warnings.push({
46864
47667
  type: "other",
@@ -48720,23 +49523,23 @@ function prepareTools2(_0) {
48720
49523
  return { tools: void 0, toolChoice: void 0, toolWarnings, betas };
48721
49524
  }
48722
49525
  const anthropicTools2 = [];
48723
- for (const tool13 of tools) {
48724
- switch (tool13.type) {
49526
+ for (const tool21 of tools) {
49527
+ switch (tool21.type) {
48725
49528
  case "function": {
48726
- const cacheControl = validator3.getCacheControl(tool13.providerOptions, {
49529
+ const cacheControl = validator3.getCacheControl(tool21.providerOptions, {
48727
49530
  type: "tool definition",
48728
49531
  canCache: true
48729
49532
  });
48730
49533
  anthropicTools2.push({
48731
- name: tool13.name,
48732
- description: tool13.description,
48733
- input_schema: tool13.inputSchema,
49534
+ name: tool21.name,
49535
+ description: tool21.description,
49536
+ input_schema: tool21.inputSchema,
48734
49537
  cache_control: cacheControl
48735
49538
  });
48736
49539
  break;
48737
49540
  }
48738
49541
  case "provider-defined": {
48739
- switch (tool13.id) {
49542
+ switch (tool21.id) {
48740
49543
  case "anthropic.code_execution_20250522": {
48741
49544
  betas.add("code-execution-2025-05-22");
48742
49545
  anthropicTools2.push({
@@ -48759,9 +49562,9 @@ function prepareTools2(_0) {
48759
49562
  anthropicTools2.push({
48760
49563
  name: "computer",
48761
49564
  type: "computer_20250124",
48762
- display_width_px: tool13.args.displayWidthPx,
48763
- display_height_px: tool13.args.displayHeightPx,
48764
- display_number: tool13.args.displayNumber,
49565
+ display_width_px: tool21.args.displayWidthPx,
49566
+ display_height_px: tool21.args.displayHeightPx,
49567
+ display_number: tool21.args.displayNumber,
48765
49568
  cache_control: void 0
48766
49569
  });
48767
49570
  break;
@@ -48771,9 +49574,9 @@ function prepareTools2(_0) {
48771
49574
  anthropicTools2.push({
48772
49575
  name: "computer",
48773
49576
  type: "computer_20241022",
48774
- display_width_px: tool13.args.displayWidthPx,
48775
- display_height_px: tool13.args.displayHeightPx,
48776
- display_number: tool13.args.displayNumber,
49577
+ display_width_px: tool21.args.displayWidthPx,
49578
+ display_height_px: tool21.args.displayHeightPx,
49579
+ display_number: tool21.args.displayNumber,
48777
49580
  cache_control: void 0
48778
49581
  });
48779
49582
  break;
@@ -48807,7 +49610,7 @@ function prepareTools2(_0) {
48807
49610
  }
48808
49611
  case "anthropic.text_editor_20250728": {
48809
49612
  const args = yield validateTypes2({
48810
- value: tool13.args,
49613
+ value: tool21.args,
48811
49614
  schema: textEditor_20250728ArgsSchema
48812
49615
  });
48813
49616
  anthropicTools2.push({
@@ -48847,7 +49650,7 @@ function prepareTools2(_0) {
48847
49650
  case "anthropic.web_fetch_20250910": {
48848
49651
  betas.add("web-fetch-2025-09-10");
48849
49652
  const args = yield validateTypes2({
48850
- value: tool13.args,
49653
+ value: tool21.args,
48851
49654
  schema: webFetch_20250910ArgsSchema
48852
49655
  });
48853
49656
  anthropicTools2.push({
@@ -48864,7 +49667,7 @@ function prepareTools2(_0) {
48864
49667
  }
48865
49668
  case "anthropic.web_search_20250305": {
48866
49669
  const args = yield validateTypes2({
48867
- value: tool13.args,
49670
+ value: tool21.args,
48868
49671
  schema: webSearch_20250305ArgsSchema
48869
49672
  });
48870
49673
  anthropicTools2.push({
@@ -48879,14 +49682,14 @@ function prepareTools2(_0) {
48879
49682
  break;
48880
49683
  }
48881
49684
  default: {
48882
- toolWarnings.push({ type: "unsupported-tool", tool: tool13 });
49685
+ toolWarnings.push({ type: "unsupported-tool", tool: tool21 });
48883
49686
  break;
48884
49687
  }
48885
49688
  }
48886
49689
  break;
48887
49690
  }
48888
49691
  default: {
48889
- toolWarnings.push({ type: "unsupported-tool", tool: tool13 });
49692
+ toolWarnings.push({ type: "unsupported-tool", tool: tool21 });
48890
49693
  break;
48891
49694
  }
48892
49695
  }
@@ -49845,7 +50648,7 @@ var AnthropicMessagesLanguageModel = class {
49845
50648
  betas.add("skills-2025-10-02");
49846
50649
  betas.add("files-api-2025-04-14");
49847
50650
  if (!(tools == null ? void 0 : tools.some(
49848
- (tool13) => tool13.type === "provider-defined" && tool13.id === "anthropic.code_execution_20250825"
50651
+ (tool21) => tool21.type === "provider-defined" && tool21.id === "anthropic.code_execution_20250825"
49849
50652
  ))) {
49850
50653
  warnings.push({
49851
50654
  type: "other",
@@ -51683,24 +52486,24 @@ function prepareTools3({
51683
52486
  if (tools == null) {
51684
52487
  return { tools: void 0, toolConfig: void 0, toolWarnings };
51685
52488
  }
51686
- const hasFunctionTools = tools.some((tool13) => tool13.type === "function");
52489
+ const hasFunctionTools = tools.some((tool21) => tool21.type === "function");
51687
52490
  const hasProviderDefinedTools = tools.some(
51688
- (tool13) => tool13.type === "provider-defined"
52491
+ (tool21) => tool21.type === "provider-defined"
51689
52492
  );
51690
52493
  if (hasFunctionTools && hasProviderDefinedTools) {
51691
52494
  toolWarnings.push({
51692
52495
  type: "unsupported-tool",
51693
- tool: tools.find((tool13) => tool13.type === "function"),
52496
+ tool: tools.find((tool21) => tool21.type === "function"),
51694
52497
  details: "Cannot mix function tools with provider-defined tools in the same request. Please use either function tools or provider-defined tools, but not both."
51695
52498
  });
51696
52499
  }
51697
52500
  if (hasProviderDefinedTools) {
51698
52501
  const googleTools22 = [];
51699
52502
  const providerDefinedTools = tools.filter(
51700
- (tool13) => tool13.type === "provider-defined"
52503
+ (tool21) => tool21.type === "provider-defined"
51701
52504
  );
51702
- providerDefinedTools.forEach((tool13) => {
51703
- switch (tool13.id) {
52505
+ providerDefinedTools.forEach((tool21) => {
52506
+ switch (tool21.id) {
51704
52507
  case "google.google_search":
51705
52508
  if (isGemini2) {
51706
52509
  googleTools22.push({ googleSearch: {} });
@@ -51708,8 +52511,8 @@ function prepareTools3({
51708
52511
  googleTools22.push({
51709
52512
  googleSearchRetrieval: {
51710
52513
  dynamicRetrievalConfig: {
51711
- mode: tool13.args.mode,
51712
- dynamicThreshold: tool13.args.dynamicThreshold
52514
+ mode: tool21.args.mode,
52515
+ dynamicThreshold: tool21.args.dynamicThreshold
51713
52516
  }
51714
52517
  }
51715
52518
  });
@@ -51723,7 +52526,7 @@ function prepareTools3({
51723
52526
  } else {
51724
52527
  toolWarnings.push({
51725
52528
  type: "unsupported-tool",
51726
- tool: tool13,
52529
+ tool: tool21,
51727
52530
  details: "The URL context tool is not supported with other Gemini models than Gemini 2."
51728
52531
  });
51729
52532
  }
@@ -51734,13 +52537,13 @@ function prepareTools3({
51734
52537
  } else {
51735
52538
  toolWarnings.push({
51736
52539
  type: "unsupported-tool",
51737
- tool: tool13,
52540
+ tool: tool21,
51738
52541
  details: "The code execution tools is not supported with other Gemini models than Gemini 2."
51739
52542
  });
51740
52543
  }
51741
52544
  break;
51742
52545
  default:
51743
- toolWarnings.push({ type: "unsupported-tool", tool: tool13 });
52546
+ toolWarnings.push({ type: "unsupported-tool", tool: tool21 });
51744
52547
  break;
51745
52548
  }
51746
52549
  });
@@ -51751,17 +52554,17 @@ function prepareTools3({
51751
52554
  };
51752
52555
  }
51753
52556
  const functionDeclarations = [];
51754
- for (const tool13 of tools) {
51755
- switch (tool13.type) {
52557
+ for (const tool21 of tools) {
52558
+ switch (tool21.type) {
51756
52559
  case "function":
51757
52560
  functionDeclarations.push({
51758
- name: tool13.name,
51759
- description: (_a4 = tool13.description) != null ? _a4 : "",
51760
- parameters: convertJSONSchemaToOpenAPISchema2(tool13.inputSchema)
52561
+ name: tool21.name,
52562
+ description: (_a4 = tool21.description) != null ? _a4 : "",
52563
+ parameters: convertJSONSchemaToOpenAPISchema2(tool21.inputSchema)
51761
52564
  });
51762
52565
  break;
51763
52566
  default:
51764
- toolWarnings.push({ type: "unsupported-tool", tool: tool13 });
52567
+ toolWarnings.push({ type: "unsupported-tool", tool: tool21 });
51765
52568
  break;
51766
52569
  }
51767
52570
  }
@@ -52884,16 +53687,16 @@ function prepareTools4({
52884
53687
  return { tools: void 0, toolChoice: void 0, toolWarnings };
52885
53688
  }
52886
53689
  const openaiCompatTools = [];
52887
- for (const tool13 of tools) {
52888
- if (tool13.type === "provider-defined") {
52889
- toolWarnings.push({ type: "unsupported-tool", tool: tool13 });
53690
+ for (const tool21 of tools) {
53691
+ if (tool21.type === "provider-defined") {
53692
+ toolWarnings.push({ type: "unsupported-tool", tool: tool21 });
52890
53693
  } else {
52891
53694
  openaiCompatTools.push({
52892
53695
  type: "function",
52893
53696
  function: {
52894
- name: tool13.name,
52895
- description: tool13.description,
52896
- parameters: tool13.inputSchema
53697
+ name: tool21.name,
53698
+ description: tool21.description,
53699
+ parameters: tool21.inputSchema
52897
53700
  }
52898
53701
  });
52899
53702
  }
@@ -54238,16 +55041,16 @@ function prepareTools5({
54238
55041
  return { tools: void 0, toolChoice: void 0, toolWarnings };
54239
55042
  }
54240
55043
  const xaiTools = [];
54241
- for (const tool13 of tools) {
54242
- if (tool13.type === "provider-defined") {
54243
- toolWarnings.push({ type: "unsupported-tool", tool: tool13 });
55044
+ for (const tool21 of tools) {
55045
+ if (tool21.type === "provider-defined") {
55046
+ toolWarnings.push({ type: "unsupported-tool", tool: tool21 });
54244
55047
  } else {
54245
55048
  xaiTools.push({
54246
55049
  type: "function",
54247
55050
  function: {
54248
- name: tool13.name,
54249
- description: tool13.description,
54250
- parameters: tool13.inputSchema
55051
+ name: tool21.name,
55052
+ description: tool21.description,
55053
+ parameters: tool21.inputSchema
54251
55054
  }
54252
55055
  });
54253
55056
  }
@@ -55247,21 +56050,21 @@ function prepareChatTools2({
55247
56050
  return { tools: void 0, toolChoice: void 0, toolWarnings };
55248
56051
  }
55249
56052
  const openaiTools2 = [];
55250
- for (const tool13 of tools) {
55251
- switch (tool13.type) {
56053
+ for (const tool21 of tools) {
56054
+ switch (tool21.type) {
55252
56055
  case "function":
55253
56056
  openaiTools2.push({
55254
56057
  type: "function",
55255
56058
  function: {
55256
- name: tool13.name,
55257
- description: tool13.description,
55258
- parameters: tool13.inputSchema,
56059
+ name: tool21.name,
56060
+ description: tool21.description,
56061
+ parameters: tool21.inputSchema,
55259
56062
  strict: structuredOutputs ? strictJsonSchema : void 0
55260
56063
  }
55261
56064
  });
55262
56065
  break;
55263
56066
  default:
55264
- toolWarnings.push({ type: "unsupported-tool", tool: tool13 });
56067
+ toolWarnings.push({ type: "unsupported-tool", tool: tool21 });
55265
56068
  break;
55266
56069
  }
55267
56070
  }
@@ -57843,22 +58646,22 @@ function prepareResponsesTools2(_0) {
57843
58646
  return { tools: void 0, toolChoice: void 0, toolWarnings };
57844
58647
  }
57845
58648
  const openaiTools2 = [];
57846
- for (const tool13 of tools) {
57847
- switch (tool13.type) {
58649
+ for (const tool21 of tools) {
58650
+ switch (tool21.type) {
57848
58651
  case "function":
57849
58652
  openaiTools2.push({
57850
58653
  type: "function",
57851
- name: tool13.name,
57852
- description: tool13.description,
57853
- parameters: tool13.inputSchema,
58654
+ name: tool21.name,
58655
+ description: tool21.description,
58656
+ parameters: tool21.inputSchema,
57854
58657
  strict: strictJsonSchema
57855
58658
  });
57856
58659
  break;
57857
58660
  case "provider-defined": {
57858
- switch (tool13.id) {
58661
+ switch (tool21.id) {
57859
58662
  case "openai.file_search": {
57860
58663
  const args = yield validateTypes({
57861
- value: tool13.args,
58664
+ value: tool21.args,
57862
58665
  schema: fileSearchArgsSchema3
57863
58666
  });
57864
58667
  openaiTools2.push({
@@ -57881,7 +58684,7 @@ function prepareResponsesTools2(_0) {
57881
58684
  }
57882
58685
  case "openai.web_search_preview": {
57883
58686
  const args = yield validateTypes({
57884
- value: tool13.args,
58687
+ value: tool21.args,
57885
58688
  schema: webSearchPreviewArgsSchema2
57886
58689
  });
57887
58690
  openaiTools2.push({
@@ -57893,7 +58696,7 @@ function prepareResponsesTools2(_0) {
57893
58696
  }
57894
58697
  case "openai.web_search": {
57895
58698
  const args = yield validateTypes({
57896
- value: tool13.args,
58699
+ value: tool21.args,
57897
58700
  schema: webSearchArgsSchema2
57898
58701
  });
57899
58702
  openaiTools2.push({
@@ -57906,7 +58709,7 @@ function prepareResponsesTools2(_0) {
57906
58709
  }
57907
58710
  case "openai.code_interpreter": {
57908
58711
  const args = yield validateTypes({
57909
- value: tool13.args,
58712
+ value: tool21.args,
57910
58713
  schema: codeInterpreterArgsSchema2
57911
58714
  });
57912
58715
  openaiTools2.push({
@@ -57917,7 +58720,7 @@ function prepareResponsesTools2(_0) {
57917
58720
  }
57918
58721
  case "openai.image_generation": {
57919
58722
  const args = yield validateTypes({
57920
- value: tool13.args,
58723
+ value: tool21.args,
57921
58724
  schema: imageGenerationArgsSchema2
57922
58725
  });
57923
58726
  openaiTools2.push({
@@ -57941,7 +58744,7 @@ function prepareResponsesTools2(_0) {
57941
58744
  break;
57942
58745
  }
57943
58746
  default:
57944
- toolWarnings.push({ type: "unsupported-tool", tool: tool13 });
58747
+ toolWarnings.push({ type: "unsupported-tool", tool: tool21 });
57945
58748
  break;
57946
58749
  }
57947
58750
  }
@@ -58046,7 +58849,7 @@ var OpenAIResponsesLanguageModel2 = class {
58046
58849
  }
58047
58850
  function hasOpenAITool(id) {
58048
58851
  return (tools == null ? void 0 : tools.find(
58049
- (tool13) => tool13.type === "provider-defined" && tool13.id === id
58852
+ (tool21) => tool21.type === "provider-defined" && tool21.id === id
58050
58853
  )) != null;
58051
58854
  }
58052
58855
  const topLogprobs = typeof (openaiOptions == null ? void 0 : openaiOptions.logprobs) === "number" ? openaiOptions == null ? void 0 : openaiOptions.logprobs : (openaiOptions == null ? void 0 : openaiOptions.logprobs) === true ? TOP_LOGPROBS_MAX2 : void 0;
@@ -58054,7 +58857,7 @@ var OpenAIResponsesLanguageModel2 = class {
58054
58857
  addInclude("message.output_text.logprobs");
58055
58858
  }
58056
58859
  const webSearchToolName = (_c = tools == null ? void 0 : tools.find(
58057
- (tool13) => tool13.type === "provider-defined" && (tool13.id === "openai.web_search" || tool13.id === "openai.web_search_preview")
58860
+ (tool21) => tool21.type === "provider-defined" && (tool21.id === "openai.web_search" || tool21.id === "openai.web_search_preview")
58058
58861
  )) == null ? void 0 : _c.name;
58059
58862
  if (webSearchToolName) {
58060
58863
  addInclude("web_search_call.action.sources");
@@ -59277,13 +60080,13 @@ function prepareTools6({
59277
60080
  return { tools: void 0, toolChoice: void 0, toolWarnings };
59278
60081
  }
59279
60082
  const groqTools2 = [];
59280
- for (const tool13 of tools) {
59281
- if (tool13.type === "provider-defined") {
59282
- if (tool13.id === "groq.browser_search") {
60083
+ for (const tool21 of tools) {
60084
+ if (tool21.type === "provider-defined") {
60085
+ if (tool21.id === "groq.browser_search") {
59283
60086
  if (!isBrowserSearchSupportedModel(modelId)) {
59284
60087
  toolWarnings.push({
59285
60088
  type: "unsupported-tool",
59286
- tool: tool13,
60089
+ tool: tool21,
59287
60090
  details: `Browser search is only supported on the following models: ${getSupportedModelsString()}. Current model: ${modelId}`
59288
60091
  });
59289
60092
  } else {
@@ -59292,15 +60095,15 @@ function prepareTools6({
59292
60095
  });
59293
60096
  }
59294
60097
  } else {
59295
- toolWarnings.push({ type: "unsupported-tool", tool: tool13 });
60098
+ toolWarnings.push({ type: "unsupported-tool", tool: tool21 });
59296
60099
  }
59297
60100
  } else {
59298
60101
  groqTools2.push({
59299
60102
  type: "function",
59300
60103
  function: {
59301
- name: tool13.name,
59302
- description: tool13.description,
59303
- parameters: tool13.inputSchema
60104
+ name: tool21.name,
60105
+ description: tool21.description,
60106
+ parameters: tool21.inputSchema
59304
60107
  }
59305
60108
  });
59306
60109
  }
@@ -60352,16 +61155,16 @@ function prepareTools7({
60352
61155
  return { tools: void 0, toolChoice: void 0, toolWarnings };
60353
61156
  }
60354
61157
  const mistralTools = [];
60355
- for (const tool13 of tools) {
60356
- if (tool13.type === "provider-defined") {
60357
- toolWarnings.push({ type: "unsupported-tool", tool: tool13 });
61158
+ for (const tool21 of tools) {
61159
+ if (tool21.type === "provider-defined") {
61160
+ toolWarnings.push({ type: "unsupported-tool", tool: tool21 });
60358
61161
  } else {
60359
61162
  mistralTools.push({
60360
61163
  type: "function",
60361
61164
  function: {
60362
- name: tool13.name,
60363
- description: tool13.description,
60364
- parameters: tool13.inputSchema
61165
+ name: tool21.name,
61166
+ description: tool21.description,
61167
+ parameters: tool21.inputSchema
60365
61168
  }
60366
61169
  });
60367
61170
  }
@@ -60381,7 +61184,7 @@ function prepareTools7({
60381
61184
  case "tool":
60382
61185
  return {
60383
61186
  tools: mistralTools.filter(
60384
- (tool13) => tool13.function.name === toolChoice.toolName
61187
+ (tool21) => tool21.function.name === toolChoice.toolName
60385
61188
  ),
60386
61189
  toolChoice: "any",
60387
61190
  toolWarnings
@@ -62164,10 +62967,10 @@ function prepareResponsesTools3({
62164
62967
  return { tools: void 0, toolChoice: void 0, toolWarnings };
62165
62968
  }
62166
62969
  const ollamaTools = [];
62167
- for (const tool13 of tools) {
62168
- switch (tool13.type) {
62970
+ for (const tool21 of tools) {
62971
+ switch (tool21.type) {
62169
62972
  case "function": {
62170
- let parameters = tool13.inputSchema;
62973
+ let parameters = tool21.inputSchema;
62171
62974
  if (!parameters) {
62172
62975
  parameters = {
62173
62976
  type: "object",
@@ -62183,15 +62986,15 @@ function prepareResponsesTools3({
62183
62986
  ollamaTools.push({
62184
62987
  type: "function",
62185
62988
  function: {
62186
- name: tool13.name,
62187
- description: tool13.description,
62989
+ name: tool21.name,
62990
+ description: tool21.description,
62188
62991
  parameters
62189
62992
  }
62190
62993
  });
62191
62994
  break;
62192
62995
  }
62193
62996
  default:
62194
- toolWarnings.push({ type: "unsupported-tool", tool: tool13 });
62997
+ toolWarnings.push({ type: "unsupported-tool", tool: tool21 });
62195
62998
  break;
62196
62999
  }
62197
63000
  }
@@ -62989,13 +63792,13 @@ var resolveTools = (clients, userTools) => __async(null, null, function* () {
62989
63792
  const clientTools = yield clientInstance.listTools({
62990
63793
  cursor: nextCursor
62991
63794
  });
62992
- for (const tool13 of clientTools.tools) {
62993
- tools[tool13.name] = {
62994
- description: tool13.description,
62995
- inputSchema: jsonSchemaToZod(tool13.inputSchema),
63795
+ for (const tool21 of clientTools.tools) {
63796
+ tools[tool21.name] = {
63797
+ description: tool21.description,
63798
+ inputSchema: jsonSchemaToZod(tool21.inputSchema),
62996
63799
  execute: (input) => __async(null, null, function* () {
62997
63800
  const result = yield clientInstance.callTool({
62998
- name: tool13.name,
63801
+ name: tool21.name,
62999
63802
  arguments: input
63000
63803
  });
63001
63804
  return result;
@@ -63069,7 +63872,7 @@ init_response2();
63069
63872
  init_sdkErrors();
63070
63873
 
63071
63874
  // examples/external_clients/aisdk.ts
63072
- var import_ai14 = require("ai");
63875
+ var import_ai22 = require("ai");
63073
63876
  var AISdkClient2 = class extends LLMClient {
63074
63877
  constructor({ model }) {
63075
63878
  super(model.modelId);
@@ -63131,7 +63934,7 @@ var AISdkClient2 = class extends LLMClient {
63131
63934
  }
63132
63935
  );
63133
63936
  if (options.response_model) {
63134
- const response2 = yield (0, import_ai14.generateObject)({
63937
+ const response2 = yield (0, import_ai22.generateObject)({
63135
63938
  model: this.model,
63136
63939
  messages: formattedMessages,
63137
63940
  schema: options.response_model.schema
@@ -63154,7 +63957,7 @@ var AISdkClient2 = class extends LLMClient {
63154
63957
  inputSchema: rawTool.parameters
63155
63958
  };
63156
63959
  }
63157
- const response = yield (0, import_ai14.generateText)({
63960
+ const response = yield (0, import_ai22.generateText)({
63158
63961
  model: this.model,
63159
63962
  messages: formattedMessages,
63160
63963
  tools
@@ -64488,7 +65291,7 @@ function validateExperimentalFeatures(options) {
64488
65291
  init_flowLogger();
64489
65292
  init_sdkErrors();
64490
65293
  var DEFAULT_MODEL_NAME = "openai/gpt-4.1-mini";
64491
- var DEFAULT_VIEWPORT = { width: 1288, height: 711 };
65294
+ var DEFAULT_VIEWPORT2 = { width: 1288, height: 711 };
64492
65295
  function resolveModelConfiguration(model) {
64493
65296
  if (!model) {
64494
65297
  return { modelName: DEFAULT_MODEL_NAME };
@@ -64681,6 +65484,12 @@ var _V3 = class _V3 {
64681
65484
  get browserbaseDebugURL() {
64682
65485
  return this.browserbaseDebugUrl;
64683
65486
  }
65487
+ /**
65488
+ * Returns true if the browser is running on Browserbase.
65489
+ */
65490
+ get isBrowserbase() {
65491
+ return this.state.kind === "BROWSERBASE";
65492
+ }
64684
65493
  /**
64685
65494
  * Async property for metrics so callers can `await v3.metrics`.
64686
65495
  * When using API mode, fetches metrics from the API. Otherwise returns local metrics.
@@ -65022,7 +65831,7 @@ var _V3 = class _V3 {
65022
65831
  if (lbo.devtools) chromeFlags.push("--auto-open-devtools-for-tabs");
65023
65832
  if (lbo.locale) chromeFlags.push(`--lang=${lbo.locale}`);
65024
65833
  if (!lbo.viewport) {
65025
- lbo.viewport = DEFAULT_VIEWPORT;
65834
+ lbo.viewport = DEFAULT_VIEWPORT2;
65026
65835
  }
65027
65836
  if (((_f = lbo.viewport) == null ? void 0 : _f.width) && ((_g = lbo.viewport) == null ? void 0 : _g.height)) {
65028
65837
  chromeFlags.push(
@@ -65647,7 +66456,8 @@ var _V3 = class _V3 {
65647
66456
  agentLlmClient,
65648
66457
  typeof (options == null ? void 0 : options.executionModel) === "string" ? options.executionModel : (_b = options == null ? void 0 : options.executionModel) == null ? void 0 : _b.modelName,
65649
66458
  options == null ? void 0 : options.systemPrompt,
65650
- tools
66459
+ tools,
66460
+ options == null ? void 0 : options.mode
65651
66461
  );
65652
66462
  const resolvedOptions = typeof instructionOrOptions === "string" ? { instruction: instructionOrOptions } : instructionOrOptions;
65653
66463
  if (resolvedOptions.page) {
@@ -65895,14 +66705,14 @@ function isObserveResult(v) {
65895
66705
 
65896
66706
  // lib/v3Evaluator.ts
65897
66707
  var import_dotenv2 = __toESM(require("dotenv"));
65898
- var import_zod15 = require("zod");
66708
+ var import_zod23 = require("zod");
65899
66709
  init_sdkErrors();
65900
66710
  import_dotenv2.default.config();
65901
- var EvaluationSchema = import_zod15.z.object({
65902
- evaluation: import_zod15.z.enum(["YES", "NO"]),
65903
- reasoning: import_zod15.z.string()
66711
+ var EvaluationSchema = import_zod23.z.object({
66712
+ evaluation: import_zod23.z.enum(["YES", "NO"]),
66713
+ reasoning: import_zod23.z.string()
65904
66714
  });
65905
- var BatchEvaluationSchema = import_zod15.z.array(EvaluationSchema);
66715
+ var BatchEvaluationSchema = import_zod23.z.array(EvaluationSchema);
65906
66716
  var V3Evaluator = class {
65907
66717
  constructor(v3, modelName, modelClientOptions) {
65908
66718
  this.silentLogger = () => {