@browserbasehq/stagehand 2.5.6 → 2.5.8

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
@@ -978,6 +978,10 @@ declare class InvalidAISDKModelFormatError extends StagehandError {
978
978
  declare class StagehandNotInitializedError extends StagehandError {
979
979
  constructor(prop: string);
980
980
  }
981
+ declare class StagehandTargetClosedError extends StagehandError {
982
+ causedBy?: Error | StagehandError;
983
+ constructor(error?: unknown);
984
+ }
981
985
  declare class BrowserbaseSessionNotFoundError extends StagehandError {
982
986
  constructor();
983
987
  }
@@ -1244,4 +1248,4 @@ declare class Stagehand {
1244
1248
  };
1245
1249
  }
1246
1250
 
1247
- export { AISdkClient, type ActOptions, type ActResult, type ActToolResult, type ActionExecutionResult, type AgentAction$1 as AgentAction, type AgentClientOptions, type AgentConfig, type AgentExecuteOptions$1 as AgentExecuteOptions, type AgentExecuteParams, type AgentExecutionOptions, type AgentHandlerOptions, type AgentInstance, type AgentOptions$1 as AgentOptions, type AgentProviderType, type AgentResult$1 as AgentResult, AgentScreenshotProviderError, type AgentType, AnnotatedScreenshotText, type AnthropicContentBlock, type AnthropicJsonSchemaObject, type AnthropicMessage, type AnthropicTextBlock, type AnthropicToolResult, type AvailableModel, AvailableModelSchema, type Browser, type BrowserContext, type BrowserResult, BrowserbaseSessionNotFoundError, CaptchaTimeoutError, type ChatCompletionOptions, type ChatMessage, type ChatMessageContent, type ChatMessageImageContent, type ChatMessageTextContent, type ClientOptions, type ComputerCallItem, type ConstructorParams, ContentFrameNotFoundError, type CreateChatCompletionOptions, CreateChatCompletionResponseError, ExperimentalApiConflictError, ExperimentalNotConfiguredError, type ExtractOptions, type ExtractResult, type FunctionCallItem, type GotoOptions, HandlerNotInitializedError, type HistoryEntry, type InitResult, InvalidAISDKModelFormatError, LLMClient, type LLMResponse, LLMResponseError, LOG_LEVEL_NAMES, type LocalBrowserLaunchOptions, type LogLevel, type LogLine, type Logger, MCPConnectionError, MissingEnvironmentVariableError, MissingLLMConfigurationError, type ModelProvider, type ObserveOptions, type ObserveResult$1 as ObserveResult, type Page, PlaywrightCommandException, PlaywrightCommandMethodNotSupportedException, type ResponseInputItem, type ResponseItem, Stagehand, StagehandAPIError, StagehandAPIUnauthorizedError, StagehandClickError, StagehandDefaultError, StagehandDomProcessError, StagehandElementNotFoundError, StagehandEnvironmentError, StagehandError, StagehandEvalError, StagehandFunctionName, StagehandHttpError, StagehandIframeError, StagehandInitError, StagehandInvalidArgumentError, type StagehandMetrics, StagehandMissingArgumentError, StagehandNotInitializedError, StagehandResponseBodyError, StagehandResponseParseError, type StagehandScreenshotOptions, StagehandServerError, StagehandShadowRootMissingError, StagehandShadowSegmentEmptyError, StagehandShadowSegmentNotFoundError, type ToolUseItem, type TreeResult, UnsupportedAISDKModelProviderError, UnsupportedModelError, UnsupportedModelProviderError, XPathResolutionError, type ZodPathSegments, ZodSchemaValidationError, connectToMCPServer, defaultExtractSchema, getAccessibilityTree, pageTextSchema };
1251
+ export { AISdkClient, type ActOptions, type ActResult, type ActToolResult, type ActionExecutionResult, type AgentAction$1 as AgentAction, type AgentClientOptions, type AgentConfig, type AgentExecuteOptions$1 as AgentExecuteOptions, type AgentExecuteParams, type AgentExecutionOptions, type AgentHandlerOptions, type AgentInstance, type AgentOptions$1 as AgentOptions, type AgentProviderType, type AgentResult$1 as AgentResult, AgentScreenshotProviderError, type AgentType, AnnotatedScreenshotText, type AnthropicContentBlock, type AnthropicJsonSchemaObject, type AnthropicMessage, type AnthropicTextBlock, type AnthropicToolResult, type AvailableModel, AvailableModelSchema, type Browser, type BrowserContext, type BrowserResult, BrowserbaseSessionNotFoundError, CaptchaTimeoutError, type ChatCompletionOptions, type ChatMessage, type ChatMessageContent, type ChatMessageImageContent, type ChatMessageTextContent, type ClientOptions, type ComputerCallItem, type ConstructorParams, ContentFrameNotFoundError, type CreateChatCompletionOptions, CreateChatCompletionResponseError, ExperimentalApiConflictError, ExperimentalNotConfiguredError, type ExtractOptions, type ExtractResult, type FunctionCallItem, type GotoOptions, HandlerNotInitializedError, type HistoryEntry, type InitResult, InvalidAISDKModelFormatError, LLMClient, type LLMResponse, LLMResponseError, LOG_LEVEL_NAMES, type LocalBrowserLaunchOptions, type LogLevel, type LogLine, type Logger, MCPConnectionError, MissingEnvironmentVariableError, MissingLLMConfigurationError, type ModelProvider, type ObserveOptions, type ObserveResult$1 as ObserveResult, type Page, PlaywrightCommandException, PlaywrightCommandMethodNotSupportedException, type ResponseInputItem, type ResponseItem, Stagehand, StagehandAPIError, StagehandAPIUnauthorizedError, StagehandClickError, StagehandDefaultError, StagehandDomProcessError, StagehandElementNotFoundError, StagehandEnvironmentError, StagehandError, StagehandEvalError, StagehandFunctionName, StagehandHttpError, StagehandIframeError, StagehandInitError, StagehandInvalidArgumentError, type StagehandMetrics, StagehandMissingArgumentError, StagehandNotInitializedError, StagehandResponseBodyError, StagehandResponseParseError, type StagehandScreenshotOptions, StagehandServerError, StagehandShadowRootMissingError, StagehandShadowSegmentEmptyError, StagehandShadowSegmentNotFoundError, StagehandTargetClosedError, type ToolUseItem, type TreeResult, UnsupportedAISDKModelProviderError, UnsupportedModelError, UnsupportedModelProviderError, XPathResolutionError, type ZodPathSegments, ZodSchemaValidationError, connectToMCPServer, defaultExtractSchema, getAccessibilityTree, pageTextSchema };
package/dist/index.js CHANGED
@@ -466,6 +466,7 @@ __export(index_exports, {
466
466
  StagehandShadowRootMissingError: () => StagehandShadowRootMissingError,
467
467
  StagehandShadowSegmentEmptyError: () => StagehandShadowSegmentEmptyError,
468
468
  StagehandShadowSegmentNotFoundError: () => StagehandShadowSegmentNotFoundError,
469
+ StagehandTargetClosedError: () => StagehandTargetClosedError,
469
470
  UnsupportedAISDKModelProviderError: () => UnsupportedAISDKModelProviderError,
470
471
  UnsupportedModelError: () => UnsupportedModelError,
471
472
  UnsupportedModelProviderError: () => UnsupportedModelProviderError,
@@ -494,7 +495,7 @@ var StagehandFunctionName = /* @__PURE__ */ ((StagehandFunctionName2) => {
494
495
  })(StagehandFunctionName || {});
495
496
 
496
497
  // lib/version.ts
497
- var STAGEHAND_VERSION = "2.5.6";
498
+ var STAGEHAND_VERSION = "2.5.8";
498
499
 
499
500
  // types/stagehandErrors.ts
500
501
  var StagehandError = class extends Error {
@@ -568,6 +569,15 @@ var StagehandNotInitializedError = class extends StagehandError {
568
569
  );
569
570
  }
570
571
  };
572
+ var StagehandTargetClosedError = class extends StagehandError {
573
+ constructor(error) {
574
+ const message = error instanceof Error || error instanceof StagehandError ? `Target closed before CDP session could attach: ${error.message}` : "Target closed before CDP session could attach";
575
+ super(message);
576
+ if (error instanceof Error || error instanceof StagehandError) {
577
+ this.causedBy = error;
578
+ }
579
+ }
580
+ };
571
581
  var BrowserbaseSessionNotFoundError = class extends StagehandError {
572
582
  constructor() {
573
583
  super("No Browserbase session ID found");
@@ -2154,6 +2164,18 @@ var ID_PATTERN = /^\d+-\d+$/;
2154
2164
  // lib/utils.ts
2155
2165
  var import_genai = require("@google/genai");
2156
2166
  var import_v33 = require("zod/v3");
2167
+ var TARGET_GONE_ERROR_SNIPPETS = [
2168
+ "No target with given id found",
2169
+ "Target closed"
2170
+ ];
2171
+ function isTargetGoneError(err) {
2172
+ const msg = err instanceof Error ? err.message : String(err);
2173
+ return TARGET_GONE_ERROR_SNIPPETS.some((snippet) => msg.includes(snippet));
2174
+ }
2175
+ function isTargetGone(target) {
2176
+ if (typeof target.isClosed === "function" && target.isClosed()) return true;
2177
+ return typeof target.isDetached === "function" && target.isDetached();
2178
+ }
2157
2179
  function validateZodSchema(schema, data) {
2158
2180
  const result = schema.safeParse(data);
2159
2181
  if (result.success) {
@@ -4624,12 +4646,24 @@ var StagehandPage = class _StagehandPage {
4624
4646
  return __async(this, arguments, function* (target = this.page) {
4625
4647
  var _a15;
4626
4648
  const cached = this.cdpClients.get(target);
4627
- if (cached) return cached;
4649
+ if (cached) {
4650
+ if (isTargetGone(target)) {
4651
+ this.cdpClients.delete(target);
4652
+ throw new StagehandTargetClosedError();
4653
+ }
4654
+ return cached;
4655
+ }
4656
+ if (isTargetGone(target)) {
4657
+ throw new StagehandTargetClosedError();
4658
+ }
4628
4659
  try {
4629
4660
  const session = yield this.context.newCDPSession(target);
4630
4661
  this.cdpClients.set(target, session);
4631
4662
  return session;
4632
4663
  } catch (err) {
4664
+ if (isTargetGone(target) || isTargetGoneError(err)) {
4665
+ throw new StagehandTargetClosedError(err);
4666
+ }
4633
4667
  const msg = (_a15 = err.message) != null ? _a15 : "";
4634
4668
  if (msg.includes("does not have a separate CDP session")) {
4635
4669
  const rootSession = yield this.getCDPClient(this.page);
@@ -4726,6 +4760,9 @@ var _StagehandContext = class _StagehandContext {
4726
4760
  }
4727
4761
  createStagehandPage(page) {
4728
4762
  return __async(this, null, function* () {
4763
+ if (page.isClosed()) {
4764
+ throw new StagehandTargetClosedError();
4765
+ }
4729
4766
  const stagehandPage = yield new StagehandPage(
4730
4767
  page,
4731
4768
  this.stagehand,
@@ -4766,9 +4803,18 @@ var _StagehandContext = class _StagehandContext {
4766
4803
  }));
4767
4804
  const existingPages = context.pages();
4768
4805
  for (const page of existingPages) {
4769
- const stagehandPage = yield instance.createStagehandPage(page);
4806
+ if (page.isClosed()) continue;
4807
+ let stagehandPage;
4808
+ try {
4809
+ stagehandPage = yield instance.createStagehandPage(page);
4810
+ } catch (err) {
4811
+ if (err instanceof StagehandTargetClosedError || isTargetGoneError(err) || page.isClosed()) {
4812
+ continue;
4813
+ }
4814
+ throw err;
4815
+ }
4770
4816
  yield instance.attachFrameNavigatedListener(page);
4771
- if (!instance.activeStagehandPage) {
4817
+ if (!instance.activeStagehandPage && stagehandPage) {
4772
4818
  instance.setActivePage(stagehandPage);
4773
4819
  }
4774
4820
  }
@@ -4817,9 +4863,17 @@ var _StagehandContext = class _StagehandContext {
4817
4863
  }
4818
4864
  handleNewPlaywrightPage(pwPage) {
4819
4865
  return __async(this, null, function* () {
4866
+ if (pwPage.isClosed()) return;
4820
4867
  let stagehandPage = this.pageMap.get(pwPage);
4821
4868
  if (!stagehandPage) {
4822
- stagehandPage = yield this.createStagehandPage(pwPage);
4869
+ try {
4870
+ stagehandPage = yield this.createStagehandPage(pwPage);
4871
+ } catch (err) {
4872
+ if (err instanceof StagehandTargetClosedError || isTargetGoneError(err) || pwPage.isClosed()) {
4873
+ return;
4874
+ }
4875
+ throw err;
4876
+ }
4823
4877
  }
4824
4878
  this.setActivePage(stagehandPage);
4825
4879
  });
@@ -4828,7 +4882,14 @@ var _StagehandContext = class _StagehandContext {
4828
4882
  return __async(this, null, function* () {
4829
4883
  const shPage = this.pageMap.get(pwPage);
4830
4884
  if (!shPage) return;
4831
- const session = yield this.intContext.newCDPSession(pwPage);
4885
+ if (pwPage.isClosed()) return;
4886
+ let session;
4887
+ try {
4888
+ session = yield this.intContext.newCDPSession(pwPage);
4889
+ } catch (err) {
4890
+ if (pwPage.isClosed() || isTargetGoneError(err)) return;
4891
+ throw err;
4892
+ }
4832
4893
  yield session.send("Page.enable");
4833
4894
  pwPage.once("close", () => {
4834
4895
  if (shPage.frameId) this.unregisterFrameId(shPage.frameId);
@@ -23452,51 +23513,74 @@ var createScrollTool = (stagehand) => (0, import_ai11.tool)({
23452
23513
  // lib/agent/tools/extract.ts
23453
23514
  var import_ai12 = require("ai");
23454
23515
  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"
23516
+ function jsonSchemaToZod2(schema) {
23517
+ switch (schema.type) {
23518
+ case "object": {
23519
+ const shape = {};
23520
+ if (schema.properties) {
23521
+ for (const [key, value] of Object.entries(schema.properties)) {
23522
+ shape[key] = jsonSchemaToZod2(value);
23468
23523
  }
23469
23524
  }
23470
- });
23471
- return import_v314.z.any();
23525
+ return import_v314.z.object(shape);
23526
+ }
23527
+ case "array":
23528
+ return import_v314.z.array(schema.items ? jsonSchemaToZod2(schema.items) : import_v314.z.any());
23529
+ case "string": {
23530
+ let s = import_v314.z.string();
23531
+ if (schema.format === "url") s = s.url();
23532
+ if (schema.format === "email") s = s.email();
23533
+ if (schema.format === "uuid") s = s.uuid();
23534
+ if (schema.enum && schema.enum.length > 0)
23535
+ return import_v314.z.enum(schema.enum);
23536
+ return s;
23537
+ }
23538
+ case "number":
23539
+ case "integer":
23540
+ return import_v314.z.number();
23541
+ case "boolean":
23542
+ return import_v314.z.boolean();
23543
+ case "null":
23544
+ return import_v314.z.null();
23545
+ default:
23546
+ return import_v314.z.any();
23472
23547
  }
23473
23548
  }
23474
- var createExtractTool = (stagehand, executionModel, logger) => (0, import_ai12.tool)({
23549
+ var createExtractTool = (stagehand, executionModel) => (0, import_ai12.tool)({
23475
23550
  description: `Extract structured data from the current page based on a provided schema.
23476
23551
 
23477
23552
  USAGE GUIDELINES:
23478
23553
  - 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()
23554
+ - IMPORTANT: only use this if explicitly asked for structured output. In most scenarios, you should use the aria tree tool over this.
23555
+ - For URL fields, use format: "url"
23556
+
23481
23557
  EXAMPLES:
23482
23558
  1. Extract a single value:
23483
23559
  instruction: "extract the product price"
23484
- schema: "z.object({ price: z.number()})"
23560
+ schema: { type: "object", properties: { price: { type: "number" } } }
23485
23561
 
23486
23562
  2. Extract multiple fields:
23487
23563
  instruction: "extract product name and price"
23488
- schema: "z.object({ name: z.string(), price: z.number() })"
23564
+ schema: { type: "object", properties: { name: { type: "string" }, price: { type: "number" } } }
23489
23565
 
23490
23566
  3. Extract arrays:
23491
23567
  instruction: "extract all product names and prices"
23492
- schema: "z.object({ products: z.array(z.object({ name: z.string(), price: z.number() })) })"`,
23568
+ schema: { type: "object", properties: { products: { type: "array", items: { type: "object", properties: { name: { type: "string" }, price: { type: "number" } } } } } }
23569
+
23570
+ 4. Extract a URL:
23571
+ instruction: "extract the link"
23572
+ schema: { type: "object", properties: { url: { type: "string", format: "url" } } }`,
23493
23573
  parameters: import_v314.z.object({
23494
23574
  instruction: import_v314.z.string().describe(
23495
23575
  "Clear instruction describing what data to extract from the page"
23496
23576
  ),
23497
- schema: import_v314.z.string().describe(
23498
- 'Zod schema as a string (e.g., "z.object({ price: z.number() })")'
23499
- )
23577
+ schema: import_v314.z.object({
23578
+ type: import_v314.z.string().optional(),
23579
+ properties: import_v314.z.record(import_v314.z.string(), import_v314.z.unknown()).optional(),
23580
+ items: import_v314.z.unknown().optional(),
23581
+ enum: import_v314.z.array(import_v314.z.string()).optional(),
23582
+ format: import_v314.z.enum(["url", "email", "uuid"]).optional()
23583
+ }).passthrough().describe("JSON Schema object describing the structure to extract")
23500
23584
  }),
23501
23585
  execute: (_0) => __async(null, [_0], function* ({ instruction, schema }) {
23502
23586
  try {
@@ -23509,14 +23593,13 @@ var createExtractTool = (stagehand, executionModel, logger) => (0, import_ai12.t
23509
23593
  value: instruction,
23510
23594
  type: "string"
23511
23595
  },
23512
- // TODO: check if we want to log this
23513
23596
  schema: {
23514
- value: schema,
23597
+ value: JSON.stringify(schema),
23515
23598
  type: "object"
23516
23599
  }
23517
23600
  }
23518
23601
  });
23519
- const zodSchema = evaluateZodSchema(schema, logger);
23602
+ const zodSchema = jsonSchemaToZod2(schema);
23520
23603
  const schemaObject = zodSchema instanceof import_v314.z.ZodObject ? zodSchema : import_v314.z.object({ result: zodSchema });
23521
23604
  const result = yield stagehand.page.extract(__spreadValues({
23522
23605
  instruction,
@@ -23545,7 +23628,7 @@ function createAgentTools(stagehand, options) {
23545
23628
  act: createActTool(stagehand, executionModel),
23546
23629
  ariaTree: createAriaTreeTool(stagehand),
23547
23630
  close: createCloseTool(),
23548
- extract: createExtractTool(stagehand, executionModel, options == null ? void 0 : options.logger),
23631
+ extract: createExtractTool(stagehand, executionModel),
23549
23632
  fillForm: createFillFormTool(stagehand, executionModel),
23550
23633
  goto: createGotoTool(stagehand),
23551
23634
  navback: createNavBackTool(stagehand),
@@ -24945,6 +25028,7 @@ var Stagehand3 = class {
24945
25028
  StagehandShadowRootMissingError,
24946
25029
  StagehandShadowSegmentEmptyError,
24947
25030
  StagehandShadowSegmentNotFoundError,
25031
+ StagehandTargetClosedError,
24948
25032
  UnsupportedAISDKModelProviderError,
24949
25033
  UnsupportedModelError,
24950
25034
  UnsupportedModelProviderError,
@@ -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;
@@ -3,6 +3,12 @@ import { z, ZodTypeAny } from "zod/v3";
3
3
  import { LogLine } from "../types/log";
4
4
  import { ModelProvider } from "../types/model";
5
5
  import { ZodPathSegments } from "../types/stagehand";
6
+ export declare const TARGET_GONE_ERROR_SNIPPETS: string[];
7
+ export declare function isTargetGoneError(err: unknown): boolean;
8
+ export declare function isTargetGone(target: {
9
+ isClosed?: () => boolean;
10
+ isDetached?: () => boolean;
11
+ }): boolean;
6
12
  export declare function validateZodSchema(schema: z.ZodTypeAny, data: unknown): boolean;
7
13
  /**
8
14
  * Detects if the code is running in the Bun runtime environment.
@@ -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.8";
@@ -27,6 +27,10 @@ export declare class InvalidAISDKModelFormatError extends StagehandError {
27
27
  export declare class StagehandNotInitializedError extends StagehandError {
28
28
  constructor(prop: string);
29
29
  }
30
+ export declare class StagehandTargetClosedError extends StagehandError {
31
+ causedBy?: Error | StagehandError;
32
+ constructor(error?: unknown);
33
+ }
30
34
  export declare class BrowserbaseSessionNotFoundError extends StagehandError {
31
35
  constructor();
32
36
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@browserbasehq/stagehand",
3
- "version": "2.5.6",
3
+ "version": "2.5.8",
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",