@mastra/stagehand 0.3.1 → 0.3.2-alpha.0

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.cts CHANGED
@@ -1,53 +1,46 @@
1
- import { Stagehand, ModelConfiguration as ModelConfiguration$1 } from '@browserbasehq/stagehand';
2
- import { ThreadManager, ThreadSession, ThreadManagerConfig, BrowserConfig, BrowserRecordingOptions, MastraBrowser, BrowserToolError, BrowserState, BrowserTabState, ScreencastOptions, ScreencastStream, MouseEventParams, KeyboardEventParams } from '@mastra/core/browser';
3
- import { Tool } from '@mastra/core/tools';
4
- import { z } from 'zod';
5
-
6
- /**
7
- * Stagehand Tool Schemas
8
- *
9
- * AI-powered browser tools using natural language instructions.
10
- * These are fundamentally different from the deterministic AgentBrowser tools.
11
- */
12
-
1
+ import { ModelConfiguration as ModelConfiguration$1, Stagehand } from "@browserbasehq/stagehand";
2
+ import { BrowserConfig, BrowserRecordingOptions, BrowserState, BrowserTabState, BrowserToolError, KeyboardEventParams, MastraBrowser, MouseEventParams, ScreencastOptions, ScreencastStream, ThreadManager, ThreadManagerConfig, ThreadSession } from "@mastra/core/browser";
3
+ import { Tool } from "@mastra/core/tools";
4
+ import { z } from "zod";
5
+ //#region src/schemas.d.ts
13
6
  /**
14
7
  * stagehand_act - Perform an action using natural language
15
8
  */
16
9
  declare const actInputSchema: z.ZodObject<{
17
- instruction: z.ZodString;
18
- variables: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
19
- useVision: z.ZodOptional<z.ZodBoolean>;
20
- timeout: z.ZodOptional<z.ZodNumber>;
10
+ instruction: z.ZodString;
11
+ variables: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
12
+ useVision: z.ZodOptional<z.ZodBoolean>;
13
+ timeout: z.ZodOptional<z.ZodNumber>;
21
14
  }, z.core.$strip>;
22
15
  type ActInput = z.output<typeof actInputSchema>;
23
16
  /**
24
17
  * stagehand_extract - Extract structured data from a page
25
18
  */
26
19
  declare const extractInputSchema: z.ZodObject<{
27
- instruction: z.ZodString;
28
- schema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
29
- timeout: z.ZodOptional<z.ZodNumber>;
20
+ instruction: z.ZodString;
21
+ schema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
22
+ timeout: z.ZodOptional<z.ZodNumber>;
30
23
  }, z.core.$strip>;
31
24
  type ExtractInput = z.output<typeof extractInputSchema>;
32
25
  /**
33
26
  * stagehand_observe - Discover actionable elements on a page
34
27
  */
35
28
  declare const observeInputSchema: z.ZodObject<{
36
- instruction: z.ZodOptional<z.ZodString>;
37
- onlyVisible: z.ZodOptional<z.ZodBoolean>;
38
- timeout: z.ZodOptional<z.ZodNumber>;
29
+ instruction: z.ZodOptional<z.ZodString>;
30
+ onlyVisible: z.ZodOptional<z.ZodBoolean>;
31
+ timeout: z.ZodOptional<z.ZodNumber>;
39
32
  }, z.core.$strip>;
40
33
  type ObserveInput = z.output<typeof observeInputSchema>;
41
34
  /**
42
35
  * stagehand_navigate - Navigate to a URL
43
36
  */
44
37
  declare const navigateInputSchema: z.ZodObject<{
45
- url: z.ZodString;
46
- waitUntil: z.ZodOptional<z.ZodEnum<{
47
- load: "load";
48
- domcontentloaded: "domcontentloaded";
49
- networkidle: "networkidle";
50
- }>>;
38
+ url: z.ZodString;
39
+ waitUntil: z.ZodOptional<z.ZodEnum<{
40
+ load: "load";
41
+ domcontentloaded: "domcontentloaded";
42
+ networkidle: "networkidle";
43
+ }>>;
51
44
  }, z.core.$strip>;
52
45
  type NavigateInput = z.output<typeof navigateInputSchema>;
53
46
  /**
@@ -59,91 +52,82 @@ type CloseInput = z.output<typeof closeInputSchema>;
59
52
  * stagehand_tabs - Manage browser tabs
60
53
  */
61
54
  declare const tabsInputSchema: z.ZodObject<{
62
- action: z.ZodEnum<{
63
- list: "list";
64
- new: "new";
65
- switch: "switch";
66
- close: "close";
67
- }>;
68
- index: z.ZodOptional<z.ZodNumber>;
69
- url: z.ZodOptional<z.ZodString>;
55
+ action: z.ZodEnum<{
56
+ list: "list";
57
+ new: "new";
58
+ switch: "switch";
59
+ close: "close";
60
+ }>;
61
+ index: z.ZodOptional<z.ZodNumber>;
62
+ url: z.ZodOptional<z.ZodString>;
70
63
  }, z.core.$strip>;
71
64
  type TabsInput = z.output<typeof tabsInputSchema>;
72
65
  /**
73
66
  * stagehand_screenshot - Capture a screenshot of the current page
74
67
  */
75
68
  declare const screenshotInputSchema: z.ZodObject<{
76
- fullPage: z.ZodOptional<z.ZodBoolean>;
69
+ fullPage: z.ZodOptional<z.ZodBoolean>;
77
70
  }, z.core.$strip>;
78
71
  type ScreenshotInput = z.output<typeof screenshotInputSchema>;
79
72
  declare const stagehandSchemas: {
80
- readonly act: z.ZodObject<{
81
- instruction: z.ZodString;
82
- variables: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
83
- useVision: z.ZodOptional<z.ZodBoolean>;
84
- timeout: z.ZodOptional<z.ZodNumber>;
85
- }, z.core.$strip>;
86
- readonly extract: z.ZodObject<{
87
- instruction: z.ZodString;
88
- schema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
89
- timeout: z.ZodOptional<z.ZodNumber>;
90
- }, z.core.$strip>;
91
- readonly observe: z.ZodObject<{
92
- instruction: z.ZodOptional<z.ZodString>;
93
- onlyVisible: z.ZodOptional<z.ZodBoolean>;
94
- timeout: z.ZodOptional<z.ZodNumber>;
95
- }, z.core.$strip>;
96
- readonly navigate: z.ZodObject<{
97
- url: z.ZodString;
98
- waitUntil: z.ZodOptional<z.ZodEnum<{
99
- load: "load";
100
- domcontentloaded: "domcontentloaded";
101
- networkidle: "networkidle";
102
- }>>;
103
- }, z.core.$strip>;
104
- readonly tabs: z.ZodObject<{
105
- action: z.ZodEnum<{
106
- list: "list";
107
- new: "new";
108
- switch: "switch";
109
- close: "close";
110
- }>;
111
- index: z.ZodOptional<z.ZodNumber>;
112
- url: z.ZodOptional<z.ZodString>;
113
- }, z.core.$strip>;
114
- readonly close: z.ZodObject<{}, z.core.$strip>;
115
- readonly screenshot: z.ZodObject<{
116
- fullPage: z.ZodOptional<z.ZodBoolean>;
117
- }, z.core.$strip>;
73
+ readonly act: z.ZodObject<{
74
+ instruction: z.ZodString;
75
+ variables: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
76
+ useVision: z.ZodOptional<z.ZodBoolean>;
77
+ timeout: z.ZodOptional<z.ZodNumber>;
78
+ }, z.core.$strip>;
79
+ readonly extract: z.ZodObject<{
80
+ instruction: z.ZodString;
81
+ schema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
82
+ timeout: z.ZodOptional<z.ZodNumber>;
83
+ }, z.core.$strip>;
84
+ readonly observe: z.ZodObject<{
85
+ instruction: z.ZodOptional<z.ZodString>;
86
+ onlyVisible: z.ZodOptional<z.ZodBoolean>;
87
+ timeout: z.ZodOptional<z.ZodNumber>;
88
+ }, z.core.$strip>;
89
+ readonly navigate: z.ZodObject<{
90
+ url: z.ZodString;
91
+ waitUntil: z.ZodOptional<z.ZodEnum<{
92
+ load: "load";
93
+ domcontentloaded: "domcontentloaded";
94
+ networkidle: "networkidle";
95
+ }>>;
96
+ }, z.core.$strip>;
97
+ readonly tabs: z.ZodObject<{
98
+ action: z.ZodEnum<{
99
+ list: "list";
100
+ new: "new";
101
+ switch: "switch";
102
+ close: "close";
103
+ }>;
104
+ index: z.ZodOptional<z.ZodNumber>;
105
+ url: z.ZodOptional<z.ZodString>;
106
+ }, z.core.$strip>;
107
+ readonly close: z.ZodObject<{}, z.core.$strip>;
108
+ readonly screenshot: z.ZodObject<{
109
+ fullPage: z.ZodOptional<z.ZodBoolean>;
110
+ }, z.core.$strip>;
118
111
  };
119
-
120
- /**
121
- * StagehandThreadManager - Thread scope management for StagehandBrowser
122
- *
123
- * Supports two scope modes:
124
- * - 'shared': All threads share the same Stagehand instance and page
125
- * - 'thread': Each thread gets its own Stagehand instance (separate browser)
126
- *
127
- * @see AgentBrowserThreadManager for the equivalent implementation.
128
- */
129
-
112
+ //#endregion
113
+ //#region src/thread-manager.d.ts
130
114
  type V3 = Stagehand;
131
115
  type V3Page$1 = NonNullable<ReturnType<NonNullable<Stagehand['context']>['activePage']>>;
132
116
  /**
133
117
  * Extended session info for Stagehand threads.
134
118
  */
135
119
  interface StagehandThreadSession extends ThreadSession {
136
- /** For 'thread' mode: dedicated Stagehand instance */
137
- stagehand?: V3;
120
+ /** For 'thread' mode: dedicated Stagehand instance */
121
+ stagehand?: V3;
138
122
  }
139
123
  /**
140
124
  * Configuration for StagehandThreadManager.
141
125
  */
142
126
  interface StagehandThreadManagerConfig extends ThreadManagerConfig {
143
- /** Function to create a new Stagehand instance (for 'thread' mode) */
144
- createStagehand?: () => Promise<V3>;
145
- /** Callback when a new browser/Stagehand instance is created for a thread */
146
- onBrowserCreated?: (stagehand: V3, threadId: string) => void;
127
+ /** Function to create a new Stagehand instance (for 'thread' mode) */
128
+ createStagehand?: () => Promise<V3>;
129
+ /** Callback when a new browser/Stagehand instance is created for a thread */
130
+ onBrowserCreated?: (stagehand: V3, threadId: string) => void;
147
131
  }
148
132
  /**
149
133
  * Thread manager for StagehandBrowser.
@@ -153,169 +137,177 @@ interface StagehandThreadManagerConfig extends ThreadManagerConfig {
153
137
  * - 'thread': Each thread gets a dedicated Stagehand instance
154
138
  */
155
139
  declare class StagehandThreadManager extends ThreadManager<V3> {
156
- protected sessions: Map<string, StagehandThreadSession>;
157
- private createStagehand?;
158
- private onBrowserCreated?;
159
- constructor(config: StagehandThreadManagerConfig);
160
- /**
161
- * Set the factory function for creating new Stagehand instances.
162
- * Required for 'thread' scope mode.
163
- */
164
- setCreateStagehand(factory: () => Promise<V3>): void;
165
- /**
166
- * Get the page for a specific thread, creating session if needed.
167
- */
168
- getPageForThread(threadId?: string): Promise<V3Page$1 | null>;
169
- /**
170
- * Create a new session for a thread.
171
- */
172
- protected createSession(threadId: string): Promise<StagehandThreadSession>;
173
- /**
174
- * Restore browser state (multiple tabs) to a Stagehand instance.
175
- */
176
- private restoreBrowserState;
177
- /**
178
- * Get the manager (Stagehand instance) for a specific session.
179
- */
180
- protected getManagerForSession(session: StagehandThreadSession): V3;
181
- /**
182
- * Destroy a session and clean up resources.
183
- */
184
- protected doDestroySession(session: StagehandThreadSession): Promise<void>;
185
- /**
186
- * Destroy all sessions (called during browser close).
187
- * doDestroySession handles closing individual Stagehand instances.
188
- */
189
- destroyAllSessions(): Promise<void>;
140
+ protected sessions: Map<string, StagehandThreadSession>;
141
+ private createStagehand?;
142
+ private onBrowserCreated?;
143
+ constructor(config: StagehandThreadManagerConfig);
144
+ /**
145
+ * Set the factory function for creating new Stagehand instances.
146
+ * Required for 'thread' scope mode.
147
+ */
148
+ setCreateStagehand(factory: () => Promise<V3>): void;
149
+ /**
150
+ * Get the page for a specific thread, creating session if needed.
151
+ */
152
+ getPageForThread(threadId?: string): Promise<V3Page$1 | null>;
153
+ /**
154
+ * Create a new session for a thread.
155
+ */
156
+ protected createSession(threadId: string): Promise<StagehandThreadSession>;
157
+ /**
158
+ * Restore browser state (multiple tabs) to a Stagehand instance.
159
+ */
160
+ private restoreBrowserState;
161
+ /**
162
+ * Get the manager (Stagehand instance) for a specific session.
163
+ */
164
+ protected getManagerForSession(session: StagehandThreadSession): V3;
165
+ /**
166
+ * Destroy a session and clean up resources.
167
+ */
168
+ protected doDestroySession(session: StagehandThreadSession): Promise<void>;
169
+ /**
170
+ * Destroy all sessions (called during browser close).
171
+ * doDestroySession handles closing individual Stagehand instances.
172
+ */
173
+ destroyAllSessions(): Promise<void>;
190
174
  }
191
-
175
+ //#endregion
176
+ //#region src/tools/constants.d.ts
192
177
  /**
193
178
  * Stagehand Tool Constants
194
179
  */
195
180
  declare const STAGEHAND_TOOLS: {
196
- readonly ACT: "stagehand_act";
197
- readonly EXTRACT: "stagehand_extract";
198
- readonly OBSERVE: "stagehand_observe";
199
- readonly NAVIGATE: "stagehand_navigate";
200
- readonly TABS: "stagehand_tabs";
201
- readonly CLOSE: "stagehand_close";
202
- readonly SCREENSHOT: "stagehand_screenshot";
181
+ readonly ACT: "stagehand_act";
182
+ readonly EXTRACT: "stagehand_extract";
183
+ readonly OBSERVE: "stagehand_observe";
184
+ readonly NAVIGATE: "stagehand_navigate";
185
+ readonly TABS: "stagehand_tabs";
186
+ readonly CLOSE: "stagehand_close";
187
+ readonly SCREENSHOT: "stagehand_screenshot";
203
188
  };
204
189
  type StagehandToolName = (typeof STAGEHAND_TOOLS)[keyof typeof STAGEHAND_TOOLS];
205
-
206
- /**
207
- * Stagehand Browser Types
208
- */
209
-
190
+ //#endregion
191
+ //#region src/types.d.ts
210
192
  /**
211
193
  * Model configuration for Stagehand AI operations.
212
194
  */
213
195
  type ModelConfiguration = ModelConfiguration$1;
196
+ /**
197
+ * Providers Stagehand can resolve from a `provider/model` string.
198
+ *
199
+ * Stagehand splits the model id on its first slash and looks the prefix up in
200
+ * its internal AI SDK provider registry; an unknown prefix throws during
201
+ * browser startup rather than at configuration time. Mirrored here so callers
202
+ * can reject a bad provider up front. Keep in sync with `AISDKProviders` in
203
+ * `@browserbasehq/stagehand`.
204
+ */
205
+ declare const STAGEHAND_MODEL_PROVIDERS: readonly ["anthropic", "azure", "bedrock", "cerebras", "deepseek", "gateway", "google", "groq", "mistral", "ollama", "openai", "perplexity", "togetherai", "vertex", "xai"];
214
206
  /**
215
207
  * Stagehand-specific configuration fields.
216
208
  */
217
209
  interface StagehandLogLine {
218
- category?: string;
219
- message: string;
220
- level?: 0 | 1 | 2;
221
- timestamp?: string;
222
- auxiliary?: Record<string, {
223
- value: string;
224
- type: string;
225
- }>;
210
+ category?: string;
211
+ message: string;
212
+ level?: 0 | 1 | 2;
213
+ timestamp?: string;
214
+ auxiliary?: Record<string, {
215
+ value: string;
216
+ type: string;
217
+ }>;
226
218
  }
227
219
  interface StagehandConfigExtensions {
228
- /**
229
- * Environment to run the browser in
230
- * - 'LOCAL': Run browser locally
231
- * - 'BROWSERBASE': Use Browserbase cloud
232
- * @default 'LOCAL'
233
- */
234
- env?: 'LOCAL' | 'BROWSERBASE';
235
- /**
236
- * Browserbase API key (required when env = 'BROWSERBASE')
237
- */
238
- apiKey?: string;
239
- /**
240
- * Browserbase project ID (required when env = 'BROWSERBASE')
241
- */
242
- projectId?: string;
243
- /**
244
- * Model configuration for AI operations
245
- * @default 'openai/gpt-4o'
246
- */
247
- model?: ModelConfiguration;
248
- /**
249
- * Enable Stagehand experimental features.
250
- */
251
- experimental?: boolean;
252
- /**
253
- * Disable the Stagehand API so model execution runs locally.
254
- */
255
- disableAPI?: boolean;
256
- /**
257
- * Enable self-healing selectors.
258
- * When enabled, Stagehand uses AI to find elements even when selectors fail.
259
- * @default true
260
- */
261
- selfHeal?: boolean;
262
- /**
263
- * Timeout for DOM to settle after actions (ms)
264
- * @default 5000
265
- */
266
- domSettleTimeout?: number;
267
- /**
268
- * Logging verbosity level.
269
- * - 0: Suppress INFO/DEBUG logs
270
- * - 1: Include INFO logs
271
- * - 2: Include DEBUG logs
272
- *
273
- * @default 0
274
- */
275
- verbose?: 0 | 1 | 2;
276
- /**
277
- * Optional Stagehand logger hook. When provided, Stagehand log lines are
278
- * routed here instead of being written directly to the process console.
279
- */
280
- logger?: (line: StagehandLogLine) => void;
281
- /**
282
- * Disable Stagehand's Pino console logging backend.
283
- *
284
- * @default true
285
- */
286
- disablePino?: boolean;
287
- /**
288
- * Custom system prompt for AI operations (act, extract, observe)
289
- */
290
- systemPrompt?: string;
291
- /**
292
- * Whether to preserve the user data directory after the browser closes.
293
- * By default, Stagehand may clean up temporary user data directories.
294
- * Set to `true` to keep the profile data for future sessions.
295
- *
296
- * Only applicable when `profile` is provided.
297
- *
298
- * @default false
299
- */
300
- preserveUserDataDir?: boolean;
301
- /**
302
- * Alpha: opt into browser recording tools.
303
- *
304
- * Recording tools are disabled by default. Provide an output directory to add
305
- * `browser_record` and `browser_record_caption` to this browser's toolset.
306
- */
307
- recording?: BrowserRecordingOptions;
308
- /**
309
- * Tool names to exclude from the browser toolset.
310
- * Use this to disable specific tools, e.g. `['stagehand_screenshot']`
311
- * to skip the screenshot tool for models that don't support vision.
312
- *
313
- * @example
314
- * ```ts
315
- * new StagehandBrowser({ excludeTools: ['stagehand_screenshot'] })
316
- * ```
317
- */
318
- excludeTools?: StagehandToolName[];
220
+ /**
221
+ * Environment to run the browser in
222
+ * - 'LOCAL': Run browser locally
223
+ * - 'BROWSERBASE': Use Browserbase cloud
224
+ * @default 'LOCAL'
225
+ */
226
+ env?: 'LOCAL' | 'BROWSERBASE';
227
+ /**
228
+ * Browserbase API key (required when env = 'BROWSERBASE')
229
+ */
230
+ apiKey?: string;
231
+ /**
232
+ * Browserbase project ID (required when env = 'BROWSERBASE')
233
+ */
234
+ projectId?: string;
235
+ /**
236
+ * Model configuration for AI operations
237
+ * @default 'openai/gpt-4o'
238
+ */
239
+ model?: ModelConfiguration;
240
+ /**
241
+ * Enable Stagehand experimental features.
242
+ */
243
+ experimental?: boolean;
244
+ /**
245
+ * Disable the Stagehand API so model execution runs locally.
246
+ */
247
+ disableAPI?: boolean;
248
+ /**
249
+ * Enable self-healing selectors.
250
+ * When enabled, Stagehand uses AI to find elements even when selectors fail.
251
+ * @default true
252
+ */
253
+ selfHeal?: boolean;
254
+ /**
255
+ * Timeout for DOM to settle after actions (ms)
256
+ * @default 5000
257
+ */
258
+ domSettleTimeout?: number;
259
+ /**
260
+ * Logging verbosity level.
261
+ * - 0: Suppress INFO/DEBUG logs
262
+ * - 1: Include INFO logs
263
+ * - 2: Include DEBUG logs
264
+ *
265
+ * @default 0
266
+ */
267
+ verbose?: 0 | 1 | 2;
268
+ /**
269
+ * Optional Stagehand logger hook. When provided, Stagehand log lines are
270
+ * routed here instead of being written directly to the process console.
271
+ */
272
+ logger?: (line: StagehandLogLine) => void;
273
+ /**
274
+ * Disable Stagehand's Pino console logging backend.
275
+ *
276
+ * @default true
277
+ */
278
+ disablePino?: boolean;
279
+ /**
280
+ * Custom system prompt for AI operations (act, extract, observe)
281
+ */
282
+ systemPrompt?: string;
283
+ /**
284
+ * Whether to preserve the user data directory after the browser closes.
285
+ * By default, Stagehand may clean up temporary user data directories.
286
+ * Set to `true` to keep the profile data for future sessions.
287
+ *
288
+ * Only applicable when `profile` is provided.
289
+ *
290
+ * @default false
291
+ */
292
+ preserveUserDataDir?: boolean;
293
+ /**
294
+ * Alpha: opt into browser recording tools.
295
+ *
296
+ * Recording tools are disabled by default. Provide an output directory to add
297
+ * `browser_record` and `browser_record_caption` to this browser's toolset.
298
+ */
299
+ recording?: BrowserRecordingOptions;
300
+ /**
301
+ * Tool names to exclude from the browser toolset.
302
+ * Use this to disable specific tools, e.g. `['stagehand_screenshot']`
303
+ * to skip the screenshot tool for models that don't support vision.
304
+ *
305
+ * @example
306
+ * ```ts
307
+ * new StagehandBrowser({ excludeTools: ['stagehand_screenshot'] })
308
+ * ```
309
+ */
310
+ excludeTools?: StagehandToolName[];
319
311
  }
320
312
  /**
321
313
  * Configuration for StagehandBrowser.
@@ -326,54 +318,46 @@ type StagehandBrowserConfig = BrowserConfig & StagehandConfigExtensions;
326
318
  * Action returned from observe()
327
319
  */
328
320
  interface StagehandAction {
329
- /** XPath selector to locate element */
330
- selector: string;
331
- /** Human-readable description */
332
- description: string;
333
- /** Suggested action method */
334
- method?: string;
335
- /** Additional action parameters */
336
- arguments?: string[];
321
+ /** XPath selector to locate element */
322
+ selector: string;
323
+ /** Human-readable description */
324
+ description: string;
325
+ /** Suggested action method */
326
+ method?: string;
327
+ /** Additional action parameters */
328
+ arguments?: string[];
337
329
  }
338
330
  /**
339
331
  * Result from act()
340
332
  */
341
333
  interface ActResult {
342
- success: boolean;
343
- message?: string;
344
- action?: string;
345
- url?: string;
346
- hint?: string;
334
+ success: boolean;
335
+ message?: string;
336
+ action?: string;
337
+ url?: string;
338
+ hint?: string;
347
339
  }
348
340
  /**
349
341
  * Result from extract()
350
342
  */
351
343
  interface ExtractResult<T = unknown> {
352
- success: boolean;
353
- data?: T;
354
- error?: string;
355
- url?: string;
356
- hint?: string;
344
+ success: boolean;
345
+ data?: T;
346
+ error?: string;
347
+ url?: string;
348
+ hint?: string;
357
349
  }
358
350
  /**
359
351
  * Result from observe()
360
352
  */
361
353
  interface ObserveResult {
362
- success: boolean;
363
- actions: StagehandAction[];
364
- url?: string;
365
- hint?: string;
354
+ success: boolean;
355
+ actions: StagehandAction[];
356
+ url?: string;
357
+ hint?: string;
366
358
  }
367
-
368
- /**
369
- * StagehandBrowser - AI-powered browser automation using Stagehand v3
370
- *
371
- * Uses natural language instructions for browser interactions.
372
- * Fundamentally different from AgentBrowser's deterministic refs approach.
373
- *
374
- * Stagehand v3 is CDP-native and provides direct CDP access for screencast/input injection.
375
- */
376
-
359
+ //#endregion
360
+ //#region src/stagehand-browser.d.ts
377
361
  type V3Page = NonNullable<ReturnType<NonNullable<Stagehand['context']>['activePage']>>;
378
362
  /**
379
363
  * StagehandBrowser - AI-powered browser using Stagehand v3
@@ -386,202 +370,203 @@ type V3Page = NonNullable<ReturnType<NonNullable<Stagehand['context']>['activePa
386
370
  * - 'thread': Each thread gets its own Stagehand instance (separate browser)
387
371
  */
388
372
  declare class StagehandBrowser extends MastraBrowser {
389
- readonly id: string;
390
- readonly name = "StagehandBrowser";
391
- readonly provider = "browserbase/stagehand";
392
- /** Shared Stagehand instance (for 'shared' scope) - narrowed type from base class */
393
- protected sharedManager: Stagehand | null;
394
- private stagehandConfig;
395
- /** Thread manager - narrowed type from base class */
396
- protected threadManager: StagehandThreadManager;
397
- /** Debounce timers per thread for tab change reconnection */
398
- private tabChangeDebounceTimers;
399
- constructor(config?: StagehandBrowserConfig);
400
- /**
401
- * Ensure browser is ready and thread session exists.
402
- * For 'thread' scope, this creates a dedicated Stagehand instance for the thread.
403
- */
404
- ensureReady(): Promise<void>;
405
- /**
406
- * Build Stagehand options from config.
407
- * Returns the configuration object expected by Stagehand constructor.
408
- */
409
- private buildStagehandOptions;
410
- /**
411
- * Create a new Stagehand instance with the current config.
412
- * Used by thread manager for 'thread' scope.
413
- */
414
- private createStagehandInstance;
415
- protected doLaunch(): Promise<void>;
416
- /**
417
- * Set up close event listener for a shared Stagehand instance.
418
- * Listens to both context and page close events for robust detection.
419
- */
420
- /**
421
- * Set up a CDP-based close listener for a Stagehand instance.
422
- *
423
- * Tracks page targets via CDP `Target.targetCreated` / `Target.targetDestroyed`.
424
- * When all page targets are gone the `onDisconnect` callback fires. This is more
425
- * reliable than Playwright's `context.close` / `page.close` events which don't
426
- * fire when Chrome is killed externally (SIGTERM/SIGKILL).
427
- */
428
- private setupCloseListener;
429
- protected doClose(): Promise<void>;
430
- handleBrowserDisconnected(): void;
431
- protected handleThreadBrowserDisconnected(threadId: string): void;
432
- closeThreadSession(threadId: string): Promise<void>;
433
- private patchExitType;
434
- /**
435
- * Check if the browser is still alive by verifying the context and pages exist.
436
- * Called by base class ensureReady() to detect externally closed browsers.
437
- */
438
- protected checkBrowserAlive(): Promise<boolean>;
439
- /**
440
- * Create an error response from an exception.
441
- * Extends base class to add Stagehand-specific error handling.
442
- */
443
- protected createErrorFromException(error: unknown, context: string): BrowserToolError;
444
- /**
445
- * Get the Stagehand instance for a thread, creating it if needed.
446
- * For 'thread' scope, this creates a dedicated Stagehand instance.
447
- * For 'shared' scope, returns the shared instance.
448
- */
449
- getManagerForThread(threadId?: string): Promise<Stagehand | null>;
450
- /**
451
- * Require a Stagehand instance for the given or current thread.
452
- * Throws if no instance is available.
453
- * @param explicitThreadId - Optional thread ID to use instead of getCurrentThread()
454
- * Use this to avoid race conditions in concurrent tool calls.
455
- */
456
- private requireStagehand;
457
- /**
458
- * Get the current page from Stagehand v3, respecting thread scope.
459
- * @param explicitThreadId - Optional thread ID to use instead of getCurrentThread()
460
- * Use this to avoid race conditions in concurrent tool calls.
461
- */
462
- private getPage;
463
- /**
464
- * Get the active page for a thread (implements abstract method from base class).
465
- */
466
- protected getActivePage(threadId?: string): Promise<V3Page | null>;
467
- /**
468
- * Get a CDP session for a specific page.
469
- */
470
- private getCdpSessionForPage;
471
- getTools(): Record<string, Tool<any, any>>;
472
- /**
473
- * Perform an action using natural language instruction
474
- * @param input - Action input
475
- * @param threadId - Optional thread ID for thread-safe operation
476
- */
477
- act(input: ActInput, threadId?: string): Promise<{
478
- success: true;
479
- message?: string;
480
- action?: string;
481
- url: string;
482
- hint: string;
483
- } | BrowserToolError>;
484
- /**
485
- * Extract structured data from a page using natural language
486
- * @param input - Extract input
487
- * @param threadId - Optional thread ID for thread-safe operation
488
- */
489
- extract(input: ExtractInput, threadId?: string): Promise<{
490
- success: true;
491
- data: unknown;
492
- url: string;
493
- hint: string;
494
- } | BrowserToolError>;
495
- /**
496
- * Discover actionable elements on a page
497
- * @param input - Observe input
498
- * @param threadId - Optional thread ID for thread-safe operation
499
- */
500
- observe(input: ObserveInput, threadId?: string): Promise<{
501
- success: true;
502
- actions: StagehandAction[];
503
- url: string;
504
- hint: string;
505
- } | BrowserToolError>;
506
- /**
507
- * Navigate to a URL
508
- * @param input - Navigate input
509
- * @param threadId - Optional thread ID for thread-safe operation
510
- */
511
- navigate(input: NavigateInput, threadId?: string): Promise<{
512
- success: true;
513
- url: string;
514
- title: string;
515
- hint: string;
516
- } | BrowserToolError>;
517
- /**
518
- * Capture a screenshot of the current page
519
- * @param input - Screenshot input
520
- * @param threadId - Optional thread ID for thread-safe operation
521
- */
522
- screenshot(input: ScreenshotInput, threadId?: string): Promise<{
523
- base64: string;
524
- url: string;
525
- title: string;
526
- } | BrowserToolError>;
527
- /**
528
- * Manage browser tabs - list, create, switch, close
529
- * @param input - Tabs input
530
- * @param threadId - Optional thread ID for thread-safe operation
531
- */
532
- tabs(input: TabsInput, threadId?: string): Promise<{
533
- success: true;
534
- tabs?: Array<{
535
- index: number;
536
- url: string;
537
- title: string;
538
- active: boolean;
539
- }>;
540
- hint: string;
541
- } | {
542
- success: true;
543
- index?: number;
544
- url?: string;
545
- title?: string;
546
- remaining?: number;
547
- hint: string;
548
- } | BrowserToolError>;
549
- getCurrentUrl(threadId?: string): Promise<string | null>;
550
- /**
551
- * Navigate to a URL (simple version). Used internally for restoring state on relaunch.
552
- */
553
- navigateTo(url: string): Promise<void>;
554
- /**
555
- * Get the current browser state (all tabs and active tab index).
556
- */
557
- getBrowserState(threadId?: string): Promise<BrowserState | null>;
558
- /**
559
- * Get browser state for a thread (implements abstract method from base class).
560
- * Sync version that uses existing manager lookup without creating sessions.
561
- */
562
- protected getBrowserStateForThread(threadId?: string): BrowserState | null;
563
- /**
564
- * Get browser state from a specific Stagehand instance.
565
- */
566
- private getBrowserStateFromStagehand;
567
- /**
568
- * Get all open tabs with their URLs and titles.
569
- */
570
- getTabState(threadId?: string): Promise<BrowserTabState[]>;
571
- /**
572
- * Get the active tab index.
573
- */
574
- getActiveTabIndex(threadId?: string): Promise<number>;
575
- startScreencast(options?: ScreencastOptions): Promise<ScreencastStream>;
576
- /**
577
- * Set up listeners to detect tab changes and reconnect the screencast.
578
- * Uses CDP Target events since Stagehand doesn't expose page lifecycle events.
579
- */
580
- private setupTabChangeDetection;
581
- injectMouseEvent(event: MouseEventParams, threadId?: string): Promise<void>;
582
- injectKeyboardEvent(event: KeyboardEventParams, threadId?: string): Promise<void>;
373
+ readonly id: string;
374
+ readonly name = "StagehandBrowser";
375
+ readonly provider = "browserbase/stagehand";
376
+ /** Shared Stagehand instance (for 'shared' scope) - narrowed type from base class */
377
+ protected sharedManager: Stagehand | null;
378
+ private stagehandConfig;
379
+ /** Thread manager - narrowed type from base class */
380
+ protected threadManager: StagehandThreadManager;
381
+ /** Debounce timers per thread for tab change reconnection */
382
+ private tabChangeDebounceTimers;
383
+ constructor(config?: StagehandBrowserConfig);
384
+ /**
385
+ * Ensure browser is ready and thread session exists.
386
+ * For 'thread' scope, this creates a dedicated Stagehand instance for the thread.
387
+ */
388
+ ensureReady(): Promise<void>;
389
+ /**
390
+ * Build Stagehand options from config.
391
+ * Returns the configuration object expected by Stagehand constructor.
392
+ */
393
+ private buildStagehandOptions;
394
+ /**
395
+ * Create a new Stagehand instance with the current config.
396
+ * Used by thread manager for 'thread' scope.
397
+ */
398
+ private createStagehandInstance;
399
+ protected doLaunch(): Promise<void>;
400
+ /**
401
+ * Set up close event listener for a shared Stagehand instance.
402
+ * Listens to both context and page close events for robust detection.
403
+ */
404
+ /**
405
+ * Set up a CDP-based close listener for a Stagehand instance.
406
+ *
407
+ * Tracks page targets via CDP `Target.targetCreated` / `Target.targetDestroyed`.
408
+ * When all page targets are gone the `onDisconnect` callback fires. This is more
409
+ * reliable than Playwright's `context.close` / `page.close` events which don't
410
+ * fire when Chrome is killed externally (SIGTERM/SIGKILL).
411
+ */
412
+ private setupCloseListener;
413
+ protected doClose(): Promise<void>;
414
+ handleBrowserDisconnected(): void;
415
+ protected handleThreadBrowserDisconnected(threadId: string): void;
416
+ closeThreadSession(threadId: string): Promise<void>;
417
+ private patchExitType;
418
+ /**
419
+ * Check if the browser is still alive by verifying the context and pages exist.
420
+ * Called by base class ensureReady() to detect externally closed browsers.
421
+ */
422
+ protected checkBrowserAlive(): Promise<boolean>;
423
+ /**
424
+ * Create an error response from an exception.
425
+ * Extends base class to add Stagehand-specific error handling.
426
+ */
427
+ protected createErrorFromException(error: unknown, context: string): BrowserToolError;
428
+ /**
429
+ * Get the Stagehand instance for a thread, creating it if needed.
430
+ * For 'thread' scope, this creates a dedicated Stagehand instance.
431
+ * For 'shared' scope, returns the shared instance.
432
+ */
433
+ getManagerForThread(threadId?: string): Promise<Stagehand | null>;
434
+ /**
435
+ * Require a Stagehand instance for the given or current thread.
436
+ * Throws if no instance is available.
437
+ * @param explicitThreadId - Optional thread ID to use instead of getCurrentThread()
438
+ * Use this to avoid race conditions in concurrent tool calls.
439
+ */
440
+ private requireStagehand;
441
+ /**
442
+ * Get the current page from Stagehand v3, respecting thread scope.
443
+ * @param explicitThreadId - Optional thread ID to use instead of getCurrentThread()
444
+ * Use this to avoid race conditions in concurrent tool calls.
445
+ */
446
+ private getPage;
447
+ /**
448
+ * Get the active page for a thread (implements abstract method from base class).
449
+ */
450
+ protected getActivePage(threadId?: string): Promise<V3Page | null>;
451
+ /**
452
+ * Get a CDP session for a specific page.
453
+ */
454
+ private getCdpSessionForPage;
455
+ getTools(): Record<string, Tool<any, any>>;
456
+ /**
457
+ * Perform an action using natural language instruction
458
+ * @param input - Action input
459
+ * @param threadId - Optional thread ID for thread-safe operation
460
+ */
461
+ act(input: ActInput, threadId?: string): Promise<{
462
+ success: true;
463
+ message?: string;
464
+ action?: string;
465
+ url: string;
466
+ hint: string;
467
+ } | BrowserToolError>;
468
+ /**
469
+ * Extract structured data from a page using natural language
470
+ * @param input - Extract input
471
+ * @param threadId - Optional thread ID for thread-safe operation
472
+ */
473
+ extract(input: ExtractInput, threadId?: string): Promise<{
474
+ success: true;
475
+ data: unknown;
476
+ url: string;
477
+ hint: string;
478
+ } | BrowserToolError>;
479
+ /**
480
+ * Discover actionable elements on a page
481
+ * @param input - Observe input
482
+ * @param threadId - Optional thread ID for thread-safe operation
483
+ */
484
+ observe(input: ObserveInput, threadId?: string): Promise<{
485
+ success: true;
486
+ actions: StagehandAction[];
487
+ url: string;
488
+ hint: string;
489
+ } | BrowserToolError>;
490
+ /**
491
+ * Navigate to a URL
492
+ * @param input - Navigate input
493
+ * @param threadId - Optional thread ID for thread-safe operation
494
+ */
495
+ navigate(input: NavigateInput, threadId?: string): Promise<{
496
+ success: true;
497
+ url: string;
498
+ title: string;
499
+ hint: string;
500
+ } | BrowserToolError>;
501
+ /**
502
+ * Capture a screenshot of the current page
503
+ * @param input - Screenshot input
504
+ * @param threadId - Optional thread ID for thread-safe operation
505
+ */
506
+ screenshot(input: ScreenshotInput, threadId?: string): Promise<{
507
+ base64: string;
508
+ url: string;
509
+ title: string;
510
+ } | BrowserToolError>;
511
+ /**
512
+ * Manage browser tabs - list, create, switch, close
513
+ * @param input - Tabs input
514
+ * @param threadId - Optional thread ID for thread-safe operation
515
+ */
516
+ tabs(input: TabsInput, threadId?: string): Promise<{
517
+ success: true;
518
+ tabs?: Array<{
519
+ index: number;
520
+ url: string;
521
+ title: string;
522
+ active: boolean;
523
+ }>;
524
+ hint: string;
525
+ } | {
526
+ success: true;
527
+ index?: number;
528
+ url?: string;
529
+ title?: string;
530
+ remaining?: number;
531
+ hint: string;
532
+ } | BrowserToolError>;
533
+ getCurrentUrl(threadId?: string): Promise<string | null>;
534
+ /**
535
+ * Navigate to a URL (simple version). Used internally for restoring state on relaunch.
536
+ */
537
+ navigateTo(url: string): Promise<void>;
538
+ /**
539
+ * Get the current browser state (all tabs and active tab index).
540
+ */
541
+ getBrowserState(threadId?: string): Promise<BrowserState | null>;
542
+ /**
543
+ * Get browser state for a thread (implements abstract method from base class).
544
+ * Sync version that uses existing manager lookup without creating sessions.
545
+ */
546
+ protected getBrowserStateForThread(threadId?: string): BrowserState | null;
547
+ /**
548
+ * Get browser state from a specific Stagehand instance.
549
+ */
550
+ private getBrowserStateFromStagehand;
551
+ /**
552
+ * Get all open tabs with their URLs and titles.
553
+ */
554
+ getTabState(threadId?: string): Promise<BrowserTabState[]>;
555
+ /**
556
+ * Get the active tab index.
557
+ */
558
+ getActiveTabIndex(threadId?: string): Promise<number>;
559
+ startScreencast(options?: ScreencastOptions): Promise<ScreencastStream>;
560
+ /**
561
+ * Set up listeners to detect tab changes and reconnect the screencast.
562
+ * Uses CDP Target events since Stagehand doesn't expose page lifecycle events.
563
+ */
564
+ private setupTabChangeDetection;
565
+ injectMouseEvent(event: MouseEventParams, threadId?: string): Promise<void>;
566
+ injectKeyboardEvent(event: KeyboardEventParams, threadId?: string): Promise<void>;
583
567
  }
584
-
568
+ //#endregion
569
+ //#region src/utils.d.ts
585
570
  /**
586
571
  * Extract the Chrome process PID from a Stagehand instance.
587
572
  *
@@ -592,17 +577,13 @@ declare class StagehandBrowser extends MastraBrowser {
592
577
  * Returns undefined if the PID can't be found (e.g. BROWSERBASE env, not yet init'd).
593
578
  */
594
579
  declare function getStagehandChromePid(stagehand: Stagehand): number | undefined;
595
-
596
- /**
597
- * Stagehand Tools
598
- *
599
- * Creates AI-powered browser tools bound to a StagehandBrowser instance.
600
- */
601
-
580
+ //#endregion
581
+ //#region src/tools/index.d.ts
602
582
  /**
603
583
  * Creates all Stagehand tools bound to a StagehandBrowser instance.
604
584
  * The browser is lazily initialized on first tool use.
605
585
  */
606
586
  declare function createStagehandTools(browser: StagehandBrowser): Record<string, Tool<any, any>>;
607
-
608
- export { type ActInput, type ActResult, type CloseInput, type ExtractInput, type ExtractResult, type ModelConfiguration, type NavigateInput, type ObserveInput, type ObserveResult, STAGEHAND_TOOLS, type StagehandAction, StagehandBrowser, type StagehandBrowserConfig, type StagehandToolName, type TabsInput, actInputSchema, closeInputSchema, createStagehandTools, extractInputSchema, getStagehandChromePid, navigateInputSchema, observeInputSchema, stagehandSchemas, tabsInputSchema };
587
+ //#endregion
588
+ export { type ActInput, type ActResult, type CloseInput, type ExtractInput, type ExtractResult, type ModelConfiguration, type NavigateInput, type ObserveInput, type ObserveResult, STAGEHAND_MODEL_PROVIDERS, STAGEHAND_TOOLS, type StagehandAction, StagehandBrowser, type StagehandBrowserConfig, type StagehandToolName, type TabsInput, actInputSchema, closeInputSchema, createStagehandTools, extractInputSchema, getStagehandChromePid, navigateInputSchema, observeInputSchema, stagehandSchemas, tabsInputSchema };
589
+ //# sourceMappingURL=index.d.cts.map