@browserbasehq/stagehand 2.5.6 → 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.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.6";
497
+ var STAGEHAND_VERSION = "2.5.7";
498
498
 
499
499
  // types/stagehandErrors.ts
500
500
  var StagehandError = class extends Error {
@@ -23452,51 +23452,74 @@ var createScrollTool = (stagehand) => (0, import_ai11.tool)({
23452
23452
  // lib/agent/tools/extract.ts
23453
23453
  var import_ai12 = require("ai");
23454
23454
  var import_v314 = require("zod/v3");
23455
- function evaluateZodSchema(schemaStr, logger) {
23456
- try {
23457
- const schemaFunction = new Function("z", `return ${schemaStr}`);
23458
- return schemaFunction(import_v314.z);
23459
- } catch (error) {
23460
- logger == null ? void 0 : logger({
23461
- category: "extract",
23462
- message: `Failed to evaluate schema string, using z.any(): ${error}`,
23463
- level: 1,
23464
- auxiliary: {
23465
- error: {
23466
- value: error,
23467
- 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);
23468
23462
  }
23469
23463
  }
23470
- });
23471
- 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();
23472
23486
  }
23473
23487
  }
23474
- var createExtractTool = (stagehand, executionModel, logger) => (0, import_ai12.tool)({
23488
+ var createExtractTool = (stagehand, executionModel) => (0, import_ai12.tool)({
23475
23489
  description: `Extract structured data from the current page based on a provided schema.
23476
23490
 
23477
23491
  USAGE GUIDELINES:
23478
23492
  - Keep schemas MINIMAL - only include fields essential for the task
23479
- - IMPORANT: only use this if explicitly asked for structured output. In most scenarios, you should use the aria tree tool over this.
23480
- - 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
+
23481
23496
  EXAMPLES:
23482
23497
  1. Extract a single value:
23483
23498
  instruction: "extract the product price"
23484
- schema: "z.object({ price: z.number()})"
23499
+ schema: { type: "object", properties: { price: { type: "number" } } }
23485
23500
 
23486
23501
  2. Extract multiple fields:
23487
23502
  instruction: "extract product name and price"
23488
- schema: "z.object({ name: z.string(), price: z.number() })"
23503
+ schema: { type: "object", properties: { name: { type: "string" }, price: { type: "number" } } }
23489
23504
 
23490
23505
  3. Extract arrays:
23491
23506
  instruction: "extract all product names and prices"
23492
- 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" } } }`,
23493
23512
  parameters: import_v314.z.object({
23494
23513
  instruction: import_v314.z.string().describe(
23495
23514
  "Clear instruction describing what data to extract from the page"
23496
23515
  ),
23497
- schema: import_v314.z.string().describe(
23498
- 'Zod schema as a string (e.g., "z.object({ price: z.number() })")'
23499
- )
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")
23500
23523
  }),
23501
23524
  execute: (_0) => __async(null, [_0], function* ({ instruction, schema }) {
23502
23525
  try {
@@ -23509,14 +23532,13 @@ var createExtractTool = (stagehand, executionModel, logger) => (0, import_ai12.t
23509
23532
  value: instruction,
23510
23533
  type: "string"
23511
23534
  },
23512
- // TODO: check if we want to log this
23513
23535
  schema: {
23514
- value: schema,
23536
+ value: JSON.stringify(schema),
23515
23537
  type: "object"
23516
23538
  }
23517
23539
  }
23518
23540
  });
23519
- const zodSchema = evaluateZodSchema(schema, logger);
23541
+ const zodSchema = jsonSchemaToZod2(schema);
23520
23542
  const schemaObject = zodSchema instanceof import_v314.z.ZodObject ? zodSchema : import_v314.z.object({ result: zodSchema });
23521
23543
  const result = yield stagehand.page.extract(__spreadValues({
23522
23544
  instruction,
@@ -23545,7 +23567,7 @@ function createAgentTools(stagehand, options) {
23545
23567
  act: createActTool(stagehand, executionModel),
23546
23568
  ariaTree: createAriaTreeTool(stagehand),
23547
23569
  close: createCloseTool(),
23548
- extract: createExtractTool(stagehand, executionModel, options == null ? void 0 : options.logger),
23570
+ extract: createExtractTool(stagehand, executionModel),
23549
23571
  fillForm: createFillFormTool(stagehand, executionModel),
23550
23572
  goto: createGotoTool(stagehand),
23551
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;
@@ -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.6";
5
+ export declare const STAGEHAND_VERSION: "2.5.7";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@browserbasehq/stagehand",
3
- "version": "2.5.6",
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",