@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/CHANGELOG.md +13 -0
- package/dist/index.cjs +1192 -1280
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +455 -474
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +455 -474
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1188 -1276
- package/dist/index.js.map +1 -1
- package/package.json +10 -9
package/dist/index.d.cts
CHANGED
|
@@ -1,53 +1,46 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Tool } from
|
|
4
|
-
import { z } from
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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
|
-
|
|
137
|
-
|
|
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
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
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
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
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
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
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
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
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
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
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
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
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
|