@browserbasehq/stagehand 2.5.5 → 2.5.7

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.
package/dist/index.d.ts CHANGED
@@ -314,6 +314,9 @@ interface ObserveOptions {
314
314
  * @deprecated The `onlyVisible` parameter has no effect in this version of Stagehand and will be removed in later versions.
315
315
  */
316
316
  onlyVisible?: boolean;
317
+ /**
318
+ * @deprecated The `drawOverlay` parameter has no effect in this version of Stagehand and will be removed in later versions.
319
+ */
317
320
  drawOverlay?: boolean;
318
321
  iframes?: boolean;
319
322
  frameId?: string;
package/dist/index.js CHANGED
@@ -494,7 +494,7 @@ var StagehandFunctionName = /* @__PURE__ */ ((StagehandFunctionName2) => {
494
494
  })(StagehandFunctionName || {});
495
495
 
496
496
  // lib/version.ts
497
- var STAGEHAND_VERSION = "2.5.5";
497
+ var STAGEHAND_VERSION = "2.5.7";
498
498
 
499
499
  // types/stagehandErrors.ts
500
500
  var StagehandError = class extends Error {
@@ -2161,57 +2161,6 @@ function validateZodSchema(schema, data) {
2161
2161
  }
2162
2162
  throw new ZodSchemaValidationError(data, result.error.format());
2163
2163
  }
2164
- function drawObserveOverlay(page, results) {
2165
- return __async(this, null, function* () {
2166
- const xpathList = results.map((result) => result.selector);
2167
- const validXpaths = xpathList.filter((xpath) => xpath !== "xpath=");
2168
- yield page.evaluate((selectors2) => {
2169
- selectors2.forEach((selector) => {
2170
- let element;
2171
- if (selector.startsWith("xpath=")) {
2172
- const xpath = selector.substring(6);
2173
- element = document.evaluate(
2174
- xpath,
2175
- document,
2176
- null,
2177
- XPathResult.FIRST_ORDERED_NODE_TYPE,
2178
- null
2179
- ).singleNodeValue;
2180
- } else {
2181
- element = document.querySelector(selector);
2182
- }
2183
- if (element instanceof HTMLElement) {
2184
- const overlay = document.createElement("div");
2185
- overlay.setAttribute("stagehandObserve", "true");
2186
- const rect = element.getBoundingClientRect();
2187
- overlay.style.position = "absolute";
2188
- overlay.style.left = rect.left + "px";
2189
- overlay.style.top = rect.top + "px";
2190
- overlay.style.width = rect.width + "px";
2191
- overlay.style.height = rect.height + "px";
2192
- overlay.style.backgroundColor = "rgba(255, 255, 0, 0.3)";
2193
- overlay.style.pointerEvents = "none";
2194
- overlay.style.zIndex = "10000";
2195
- document.body.appendChild(overlay);
2196
- }
2197
- });
2198
- }, validXpaths);
2199
- });
2200
- }
2201
- function clearOverlays(page) {
2202
- return __async(this, null, function* () {
2203
- yield page.evaluate(() => {
2204
- const elements = document.querySelectorAll('[stagehandObserve="true"]');
2205
- elements.forEach((el) => {
2206
- const parent = el.parentNode;
2207
- while (el.firstChild) {
2208
- parent == null ? void 0 : parent.insertBefore(el.firstChild, el);
2209
- }
2210
- parent == null ? void 0 : parent.removeChild(el);
2211
- });
2212
- });
2213
- });
2214
- }
2215
2164
  function isRunningInBun() {
2216
2165
  return typeof process !== "undefined" && typeof process.versions !== "undefined" && "bun" in process.versions;
2217
2166
  }
@@ -3709,6 +3658,13 @@ var StagehandObserveHandler = class {
3709
3658
  level: 1
3710
3659
  });
3711
3660
  }
3661
+ if (drawOverlay !== void 0) {
3662
+ this.logger({
3663
+ category: "observation",
3664
+ message: "Warning: the drawOverlay parameter has been deprecated and this parameter is now a no-op.",
3665
+ level: 1
3666
+ });
3667
+ }
3712
3668
  yield this.stagehandPage._waitForSettledDom();
3713
3669
  this.logger({
3714
3670
  category: "observation",
@@ -3836,9 +3792,6 @@ var StagehandObserveHandler = class {
3836
3792
  }
3837
3793
  }
3838
3794
  });
3839
- if (drawOverlay) {
3840
- yield drawObserveOverlay(this.stagehandPage.page, elementsWithSelectors);
3841
- }
3842
3795
  return elementsWithSelectors;
3843
3796
  });
3844
3797
  }
@@ -4389,7 +4342,6 @@ var StagehandPage = class _StagehandPage {
4389
4342
  if (!this.actHandler) {
4390
4343
  throw new HandlerNotInitializedError("Act");
4391
4344
  }
4392
- yield clearOverlays(this.page);
4393
4345
  if (typeof actionOrOptions === "object" && actionOrOptions !== null) {
4394
4346
  if ("selector" in actionOrOptions && "method" in actionOrOptions) {
4395
4347
  const observeResult = actionOrOptions;
@@ -4468,7 +4420,6 @@ var StagehandPage = class _StagehandPage {
4468
4420
  if (!this.extractHandler) {
4469
4421
  throw new HandlerNotInitializedError("Extract");
4470
4422
  }
4471
- yield clearOverlays(this.page);
4472
4423
  if (!instructionOrOptions) {
4473
4424
  let result2;
4474
4425
  if (this.api) {
@@ -4571,7 +4522,6 @@ var StagehandPage = class _StagehandPage {
4571
4522
  if (!this.observeHandler) {
4572
4523
  throw new HandlerNotInitializedError("Observe");
4573
4524
  }
4574
- yield clearOverlays(this.page);
4575
4525
  const options = typeof instructionOrOptions === "string" ? { instruction: instructionOrOptions } : instructionOrOptions || {};
4576
4526
  const {
4577
4527
  instruction,
@@ -23502,51 +23452,74 @@ var createScrollTool = (stagehand) => (0, import_ai11.tool)({
23502
23452
  // lib/agent/tools/extract.ts
23503
23453
  var import_ai12 = require("ai");
23504
23454
  var import_v314 = require("zod/v3");
23505
- function evaluateZodSchema(schemaStr, logger) {
23506
- try {
23507
- const schemaFunction = new Function("z", `return ${schemaStr}`);
23508
- return schemaFunction(import_v314.z);
23509
- } catch (error) {
23510
- logger == null ? void 0 : logger({
23511
- category: "extract",
23512
- message: `Failed to evaluate schema string, using z.any(): ${error}`,
23513
- level: 1,
23514
- auxiliary: {
23515
- error: {
23516
- value: error,
23517
- type: "string"
23455
+ function jsonSchemaToZod2(schema) {
23456
+ switch (schema.type) {
23457
+ case "object": {
23458
+ const shape = {};
23459
+ if (schema.properties) {
23460
+ for (const [key, value] of Object.entries(schema.properties)) {
23461
+ shape[key] = jsonSchemaToZod2(value);
23518
23462
  }
23519
23463
  }
23520
- });
23521
- return import_v314.z.any();
23464
+ return import_v314.z.object(shape);
23465
+ }
23466
+ case "array":
23467
+ return import_v314.z.array(schema.items ? jsonSchemaToZod2(schema.items) : import_v314.z.any());
23468
+ case "string": {
23469
+ let s = import_v314.z.string();
23470
+ if (schema.format === "url") s = s.url();
23471
+ if (schema.format === "email") s = s.email();
23472
+ if (schema.format === "uuid") s = s.uuid();
23473
+ if (schema.enum && schema.enum.length > 0)
23474
+ return import_v314.z.enum(schema.enum);
23475
+ return s;
23476
+ }
23477
+ case "number":
23478
+ case "integer":
23479
+ return import_v314.z.number();
23480
+ case "boolean":
23481
+ return import_v314.z.boolean();
23482
+ case "null":
23483
+ return import_v314.z.null();
23484
+ default:
23485
+ return import_v314.z.any();
23522
23486
  }
23523
23487
  }
23524
- var createExtractTool = (stagehand, executionModel, logger) => (0, import_ai12.tool)({
23488
+ var createExtractTool = (stagehand, executionModel) => (0, import_ai12.tool)({
23525
23489
  description: `Extract structured data from the current page based on a provided schema.
23526
23490
 
23527
23491
  USAGE GUIDELINES:
23528
23492
  - Keep schemas MINIMAL - only include fields essential for the task
23529
- - IMPORANT: only use this if explicitly asked for structured output. In most scenarios, you should use the aria tree tool over this.
23530
- - If you need to extract a link, make sure the type defintion follows the format of z.string().url()
23493
+ - IMPORTANT: only use this if explicitly asked for structured output. In most scenarios, you should use the aria tree tool over this.
23494
+ - For URL fields, use format: "url"
23495
+
23531
23496
  EXAMPLES:
23532
23497
  1. Extract a single value:
23533
23498
  instruction: "extract the product price"
23534
- schema: "z.object({ price: z.number()})"
23499
+ schema: { type: "object", properties: { price: { type: "number" } } }
23535
23500
 
23536
23501
  2. Extract multiple fields:
23537
23502
  instruction: "extract product name and price"
23538
- schema: "z.object({ name: z.string(), price: z.number() })"
23503
+ schema: { type: "object", properties: { name: { type: "string" }, price: { type: "number" } } }
23539
23504
 
23540
23505
  3. Extract arrays:
23541
23506
  instruction: "extract all product names and prices"
23542
- schema: "z.object({ products: z.array(z.object({ name: z.string(), price: z.number() })) })"`,
23507
+ schema: { type: "object", properties: { products: { type: "array", items: { type: "object", properties: { name: { type: "string" }, price: { type: "number" } } } } } }
23508
+
23509
+ 4. Extract a URL:
23510
+ instruction: "extract the link"
23511
+ schema: { type: "object", properties: { url: { type: "string", format: "url" } } }`,
23543
23512
  parameters: import_v314.z.object({
23544
23513
  instruction: import_v314.z.string().describe(
23545
23514
  "Clear instruction describing what data to extract from the page"
23546
23515
  ),
23547
- schema: import_v314.z.string().describe(
23548
- 'Zod schema as a string (e.g., "z.object({ price: z.number() })")'
23549
- )
23516
+ schema: import_v314.z.object({
23517
+ type: import_v314.z.string().optional(),
23518
+ properties: import_v314.z.record(import_v314.z.string(), import_v314.z.unknown()).optional(),
23519
+ items: import_v314.z.unknown().optional(),
23520
+ enum: import_v314.z.array(import_v314.z.string()).optional(),
23521
+ format: import_v314.z.enum(["url", "email", "uuid"]).optional()
23522
+ }).passthrough().describe("JSON Schema object describing the structure to extract")
23550
23523
  }),
23551
23524
  execute: (_0) => __async(null, [_0], function* ({ instruction, schema }) {
23552
23525
  try {
@@ -23559,14 +23532,13 @@ var createExtractTool = (stagehand, executionModel, logger) => (0, import_ai12.t
23559
23532
  value: instruction,
23560
23533
  type: "string"
23561
23534
  },
23562
- // TODO: check if we want to log this
23563
23535
  schema: {
23564
- value: schema,
23536
+ value: JSON.stringify(schema),
23565
23537
  type: "object"
23566
23538
  }
23567
23539
  }
23568
23540
  });
23569
- const zodSchema = evaluateZodSchema(schema, logger);
23541
+ const zodSchema = jsonSchemaToZod2(schema);
23570
23542
  const schemaObject = zodSchema instanceof import_v314.z.ZodObject ? zodSchema : import_v314.z.object({ result: zodSchema });
23571
23543
  const result = yield stagehand.page.extract(__spreadValues({
23572
23544
  instruction,
@@ -23595,7 +23567,7 @@ function createAgentTools(stagehand, options) {
23595
23567
  act: createActTool(stagehand, executionModel),
23596
23568
  ariaTree: createAriaTreeTool(stagehand),
23597
23569
  close: createCloseTool(),
23598
- extract: createExtractTool(stagehand, executionModel, options == null ? void 0 : options.logger),
23570
+ extract: createExtractTool(stagehand, executionModel),
23599
23571
  fillForm: createFillFormTool(stagehand, executionModel),
23600
23572
  goto: createGotoTool(stagehand),
23601
23573
  navback: createNavBackTool(stagehand),
@@ -1,14 +1,47 @@
1
1
  import { z } from "zod/v3";
2
2
  import { Stagehand } from "../../index";
3
- import { LogLine } from "@/types/log";
4
- export declare const createExtractTool: (stagehand: Stagehand, executionModel?: string, logger?: (message: LogLine) => void) => import("ai/dist").Tool<z.ZodObject<{
3
+ export declare const createExtractTool: (stagehand: Stagehand, executionModel?: string) => import("ai/dist").Tool<z.ZodObject<{
5
4
  instruction: z.ZodString;
6
- schema: z.ZodString;
5
+ schema: z.ZodObject<{
6
+ type: z.ZodOptional<z.ZodString>;
7
+ properties: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
8
+ items: z.ZodOptional<z.ZodUnknown>;
9
+ enum: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
10
+ format: z.ZodOptional<z.ZodEnum<["url", "email", "uuid"]>>;
11
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
12
+ type: z.ZodOptional<z.ZodString>;
13
+ properties: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
14
+ items: z.ZodOptional<z.ZodUnknown>;
15
+ enum: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
16
+ format: z.ZodOptional<z.ZodEnum<["url", "email", "uuid"]>>;
17
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
18
+ type: z.ZodOptional<z.ZodString>;
19
+ properties: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
20
+ items: z.ZodOptional<z.ZodUnknown>;
21
+ enum: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
22
+ format: z.ZodOptional<z.ZodEnum<["url", "email", "uuid"]>>;
23
+ }, z.ZodTypeAny, "passthrough">>;
7
24
  }, "strip", z.ZodTypeAny, {
8
- schema?: string;
25
+ schema?: {
26
+ type?: string;
27
+ format?: "url" | "email" | "uuid";
28
+ properties?: Record<string, unknown>;
29
+ items?: unknown;
30
+ enum?: string[];
31
+ } & {
32
+ [k: string]: unknown;
33
+ };
9
34
  instruction?: string;
10
35
  }, {
11
- schema?: string;
36
+ schema?: {
37
+ type?: string;
38
+ format?: "url" | "email" | "uuid";
39
+ properties?: Record<string, unknown>;
40
+ items?: unknown;
41
+ enum?: string[];
42
+ } & {
43
+ [k: string]: unknown;
44
+ };
12
45
  instruction?: string;
13
46
  }>, {
14
47
  success: boolean;
@@ -22,7 +55,15 @@ export declare const createExtractTool: (stagehand: Stagehand, executionModel?:
22
55
  data?: undefined;
23
56
  }> & {
24
57
  execute: (args: {
25
- schema?: string;
58
+ schema?: {
59
+ type?: string;
60
+ format?: "url" | "email" | "uuid";
61
+ properties?: Record<string, unknown>;
62
+ items?: unknown;
63
+ enum?: string[];
64
+ } & {
65
+ [k: string]: unknown;
66
+ };
26
67
  instruction?: string;
27
68
  }, options: import("ai/dist").ToolExecutionOptions) => PromiseLike<{
28
69
  success: boolean;
@@ -94,12 +94,46 @@ export declare function createAgentTools(stagehand: Stagehand, options?: AgentTo
94
94
  };
95
95
  extract: import("ai/dist").Tool<import("zod/v3").ZodObject<{
96
96
  instruction: import("zod/v3").ZodString;
97
- schema: import("zod/v3").ZodString;
97
+ schema: import("zod/v3").ZodObject<{
98
+ type: import("zod/v3").ZodOptional<import("zod/v3").ZodString>;
99
+ properties: import("zod/v3").ZodOptional<import("zod/v3").ZodRecord<import("zod/v3").ZodString, import("zod/v3").ZodUnknown>>;
100
+ items: import("zod/v3").ZodOptional<import("zod/v3").ZodUnknown>;
101
+ enum: import("zod/v3").ZodOptional<import("zod/v3").ZodArray<import("zod/v3").ZodString, "many">>;
102
+ format: import("zod/v3").ZodOptional<import("zod/v3").ZodEnum<["url", "email", "uuid"]>>;
103
+ }, "passthrough", import("zod/v3").ZodTypeAny, import("zod/v3").objectOutputType<{
104
+ type: import("zod/v3").ZodOptional<import("zod/v3").ZodString>;
105
+ properties: import("zod/v3").ZodOptional<import("zod/v3").ZodRecord<import("zod/v3").ZodString, import("zod/v3").ZodUnknown>>;
106
+ items: import("zod/v3").ZodOptional<import("zod/v3").ZodUnknown>;
107
+ enum: import("zod/v3").ZodOptional<import("zod/v3").ZodArray<import("zod/v3").ZodString, "many">>;
108
+ format: import("zod/v3").ZodOptional<import("zod/v3").ZodEnum<["url", "email", "uuid"]>>;
109
+ }, import("zod/v3").ZodTypeAny, "passthrough">, import("zod/v3").objectInputType<{
110
+ type: import("zod/v3").ZodOptional<import("zod/v3").ZodString>;
111
+ properties: import("zod/v3").ZodOptional<import("zod/v3").ZodRecord<import("zod/v3").ZodString, import("zod/v3").ZodUnknown>>;
112
+ items: import("zod/v3").ZodOptional<import("zod/v3").ZodUnknown>;
113
+ enum: import("zod/v3").ZodOptional<import("zod/v3").ZodArray<import("zod/v3").ZodString, "many">>;
114
+ format: import("zod/v3").ZodOptional<import("zod/v3").ZodEnum<["url", "email", "uuid"]>>;
115
+ }, import("zod/v3").ZodTypeAny, "passthrough">>;
98
116
  }, "strip", import("zod/v3").ZodTypeAny, {
99
- schema?: string;
117
+ schema?: {
118
+ type?: string;
119
+ format?: "url" | "email" | "uuid";
120
+ properties?: Record<string, unknown>;
121
+ items?: unknown;
122
+ enum?: string[];
123
+ } & {
124
+ [k: string]: unknown;
125
+ };
100
126
  instruction?: string;
101
127
  }, {
102
- schema?: string;
128
+ schema?: {
129
+ type?: string;
130
+ format?: "url" | "email" | "uuid";
131
+ properties?: Record<string, unknown>;
132
+ items?: unknown;
133
+ enum?: string[];
134
+ } & {
135
+ [k: string]: unknown;
136
+ };
103
137
  instruction?: string;
104
138
  }>, {
105
139
  success: boolean;
@@ -113,7 +147,15 @@ export declare function createAgentTools(stagehand: Stagehand, options?: AgentTo
113
147
  data?: undefined;
114
148
  }> & {
115
149
  execute: (args: {
116
- schema?: string;
150
+ schema?: {
151
+ type?: string;
152
+ format?: "url" | "email" | "uuid";
153
+ properties?: Record<string, unknown>;
154
+ items?: unknown;
155
+ enum?: string[];
156
+ } & {
157
+ [k: string]: unknown;
158
+ };
117
159
  instruction?: string;
118
160
  }, options: import("ai/dist").ToolExecutionOptions) => PromiseLike<{
119
161
  success: boolean;
@@ -25,6 +25,9 @@ export declare class StagehandObserveHandler {
25
25
  * @deprecated The `onlyVisible` parameter has no effect in this version of Stagehand and will be removed in later versions.
26
26
  */
27
27
  onlyVisible?: boolean;
28
+ /**
29
+ * @deprecated The `drawOverlay` parameter has no effect in this version of Stagehand and will be removed in later versions.
30
+ */
28
31
  drawOverlay?: boolean;
29
32
  fromAct?: boolean;
30
33
  iframes?: boolean;
@@ -1,12 +1,9 @@
1
1
  import { Schema } from "@google/genai";
2
2
  import { z, ZodTypeAny } from "zod/v3";
3
- import { ObserveResult, Page } from ".";
4
3
  import { LogLine } from "../types/log";
5
4
  import { ModelProvider } from "../types/model";
6
5
  import { ZodPathSegments } from "../types/stagehand";
7
6
  export declare function validateZodSchema(schema: z.ZodTypeAny, data: unknown): boolean;
8
- export declare function drawObserveOverlay(page: Page, results: ObserveResult[]): Promise<void>;
9
- export declare function clearOverlays(page: Page): Promise<void>;
10
7
  /**
11
8
  * Detects if the code is running in the Bun runtime environment.
12
9
  * @returns {boolean} True if running in Bun, false otherwise.
@@ -2,4 +2,4 @@
2
2
  * AUTO-GENERATED — DO NOT EDIT BY HAND
3
3
  * Run `pnpm run gen-version` to refresh.
4
4
  */
5
- export declare const STAGEHAND_VERSION: "2.5.5";
5
+ export declare const STAGEHAND_VERSION: "2.5.7";
@@ -150,6 +150,9 @@ export interface ObserveOptions {
150
150
  * @deprecated The `onlyVisible` parameter has no effect in this version of Stagehand and will be removed in later versions.
151
151
  */
152
152
  onlyVisible?: boolean;
153
+ /**
154
+ * @deprecated The `drawOverlay` parameter has no effect in this version of Stagehand and will be removed in later versions.
155
+ */
153
156
  drawOverlay?: boolean;
154
157
  iframes?: boolean;
155
158
  frameId?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@browserbasehq/stagehand",
3
- "version": "2.5.5",
3
+ "version": "2.5.7",
4
4
  "description": "An AI web browsing framework focused on simplicity and extensibility.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",