@mastra/stagehand 0.2.1-alpha.0 → 0.2.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 +26 -0
- package/dist/index.cjs +78 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +45 -13
- package/dist/index.d.ts +45 -13
- package/dist/index.js +78 -4
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.d.cts
CHANGED
|
@@ -69,6 +69,13 @@ declare const tabsInputSchema: z.ZodObject<{
|
|
|
69
69
|
url: z.ZodOptional<z.ZodString>;
|
|
70
70
|
}, z.core.$strip>;
|
|
71
71
|
type TabsInput = z.output<typeof tabsInputSchema>;
|
|
72
|
+
/**
|
|
73
|
+
* stagehand_screenshot - Capture a screenshot of the current page
|
|
74
|
+
*/
|
|
75
|
+
declare const screenshotInputSchema: z.ZodObject<{
|
|
76
|
+
fullPage: z.ZodOptional<z.ZodBoolean>;
|
|
77
|
+
}, z.core.$strip>;
|
|
78
|
+
type ScreenshotInput = z.output<typeof screenshotInputSchema>;
|
|
72
79
|
declare const stagehandSchemas: {
|
|
73
80
|
readonly act: z.ZodObject<{
|
|
74
81
|
instruction: z.ZodString;
|
|
@@ -105,6 +112,9 @@ declare const stagehandSchemas: {
|
|
|
105
112
|
url: z.ZodOptional<z.ZodString>;
|
|
106
113
|
}, z.core.$strip>;
|
|
107
114
|
readonly close: z.ZodObject<{}, z.core.$strip>;
|
|
115
|
+
readonly screenshot: z.ZodObject<{
|
|
116
|
+
fullPage: z.ZodOptional<z.ZodBoolean>;
|
|
117
|
+
}, z.core.$strip>;
|
|
108
118
|
};
|
|
109
119
|
|
|
110
120
|
/**
|
|
@@ -179,6 +189,20 @@ declare class StagehandThreadManager extends ThreadManager<V3> {
|
|
|
179
189
|
destroyAllSessions(): Promise<void>;
|
|
180
190
|
}
|
|
181
191
|
|
|
192
|
+
/**
|
|
193
|
+
* Stagehand Tool Constants
|
|
194
|
+
*/
|
|
195
|
+
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";
|
|
203
|
+
};
|
|
204
|
+
type StagehandToolName = (typeof STAGEHAND_TOOLS)[keyof typeof STAGEHAND_TOOLS];
|
|
205
|
+
|
|
182
206
|
/**
|
|
183
207
|
* Stagehand Browser Types
|
|
184
208
|
*/
|
|
@@ -248,6 +272,17 @@ interface StagehandConfigExtensions {
|
|
|
248
272
|
* @default false
|
|
249
273
|
*/
|
|
250
274
|
preserveUserDataDir?: boolean;
|
|
275
|
+
/**
|
|
276
|
+
* Tool names to exclude from the browser toolset.
|
|
277
|
+
* Use this to disable specific tools, e.g. `['stagehand_screenshot']`
|
|
278
|
+
* to skip the screenshot tool for models that don't support vision.
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* ```ts
|
|
282
|
+
* new StagehandBrowser({ excludeTools: ['stagehand_screenshot'] })
|
|
283
|
+
* ```
|
|
284
|
+
*/
|
|
285
|
+
excludeTools?: StagehandToolName[];
|
|
251
286
|
}
|
|
252
287
|
/**
|
|
253
288
|
* Configuration for StagehandBrowser.
|
|
@@ -446,6 +481,16 @@ declare class StagehandBrowser extends MastraBrowser {
|
|
|
446
481
|
title: string;
|
|
447
482
|
hint: string;
|
|
448
483
|
} | BrowserToolError>;
|
|
484
|
+
/**
|
|
485
|
+
* Capture a screenshot of the current page
|
|
486
|
+
* @param input - Screenshot input
|
|
487
|
+
* @param threadId - Optional thread ID for thread-safe operation
|
|
488
|
+
*/
|
|
489
|
+
screenshot(input: ScreenshotInput, threadId?: string): Promise<{
|
|
490
|
+
base64: string;
|
|
491
|
+
url: string;
|
|
492
|
+
title: string;
|
|
493
|
+
} | BrowserToolError>;
|
|
449
494
|
/**
|
|
450
495
|
* Manage browser tabs - list, create, switch, close
|
|
451
496
|
* @param input - Tabs input
|
|
@@ -515,19 +560,6 @@ declare class StagehandBrowser extends MastraBrowser {
|
|
|
515
560
|
*/
|
|
516
561
|
declare function getStagehandChromePid(stagehand: Stagehand): number | undefined;
|
|
517
562
|
|
|
518
|
-
/**
|
|
519
|
-
* Stagehand Tool Constants
|
|
520
|
-
*/
|
|
521
|
-
declare const STAGEHAND_TOOLS: {
|
|
522
|
-
readonly ACT: "stagehand_act";
|
|
523
|
-
readonly EXTRACT: "stagehand_extract";
|
|
524
|
-
readonly OBSERVE: "stagehand_observe";
|
|
525
|
-
readonly NAVIGATE: "stagehand_navigate";
|
|
526
|
-
readonly TABS: "stagehand_tabs";
|
|
527
|
-
readonly CLOSE: "stagehand_close";
|
|
528
|
-
};
|
|
529
|
-
type StagehandToolName = (typeof STAGEHAND_TOOLS)[keyof typeof STAGEHAND_TOOLS];
|
|
530
|
-
|
|
531
563
|
/**
|
|
532
564
|
* Stagehand Tools
|
|
533
565
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -69,6 +69,13 @@ declare const tabsInputSchema: z.ZodObject<{
|
|
|
69
69
|
url: z.ZodOptional<z.ZodString>;
|
|
70
70
|
}, z.core.$strip>;
|
|
71
71
|
type TabsInput = z.output<typeof tabsInputSchema>;
|
|
72
|
+
/**
|
|
73
|
+
* stagehand_screenshot - Capture a screenshot of the current page
|
|
74
|
+
*/
|
|
75
|
+
declare const screenshotInputSchema: z.ZodObject<{
|
|
76
|
+
fullPage: z.ZodOptional<z.ZodBoolean>;
|
|
77
|
+
}, z.core.$strip>;
|
|
78
|
+
type ScreenshotInput = z.output<typeof screenshotInputSchema>;
|
|
72
79
|
declare const stagehandSchemas: {
|
|
73
80
|
readonly act: z.ZodObject<{
|
|
74
81
|
instruction: z.ZodString;
|
|
@@ -105,6 +112,9 @@ declare const stagehandSchemas: {
|
|
|
105
112
|
url: z.ZodOptional<z.ZodString>;
|
|
106
113
|
}, z.core.$strip>;
|
|
107
114
|
readonly close: z.ZodObject<{}, z.core.$strip>;
|
|
115
|
+
readonly screenshot: z.ZodObject<{
|
|
116
|
+
fullPage: z.ZodOptional<z.ZodBoolean>;
|
|
117
|
+
}, z.core.$strip>;
|
|
108
118
|
};
|
|
109
119
|
|
|
110
120
|
/**
|
|
@@ -179,6 +189,20 @@ declare class StagehandThreadManager extends ThreadManager<V3> {
|
|
|
179
189
|
destroyAllSessions(): Promise<void>;
|
|
180
190
|
}
|
|
181
191
|
|
|
192
|
+
/**
|
|
193
|
+
* Stagehand Tool Constants
|
|
194
|
+
*/
|
|
195
|
+
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";
|
|
203
|
+
};
|
|
204
|
+
type StagehandToolName = (typeof STAGEHAND_TOOLS)[keyof typeof STAGEHAND_TOOLS];
|
|
205
|
+
|
|
182
206
|
/**
|
|
183
207
|
* Stagehand Browser Types
|
|
184
208
|
*/
|
|
@@ -248,6 +272,17 @@ interface StagehandConfigExtensions {
|
|
|
248
272
|
* @default false
|
|
249
273
|
*/
|
|
250
274
|
preserveUserDataDir?: boolean;
|
|
275
|
+
/**
|
|
276
|
+
* Tool names to exclude from the browser toolset.
|
|
277
|
+
* Use this to disable specific tools, e.g. `['stagehand_screenshot']`
|
|
278
|
+
* to skip the screenshot tool for models that don't support vision.
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* ```ts
|
|
282
|
+
* new StagehandBrowser({ excludeTools: ['stagehand_screenshot'] })
|
|
283
|
+
* ```
|
|
284
|
+
*/
|
|
285
|
+
excludeTools?: StagehandToolName[];
|
|
251
286
|
}
|
|
252
287
|
/**
|
|
253
288
|
* Configuration for StagehandBrowser.
|
|
@@ -446,6 +481,16 @@ declare class StagehandBrowser extends MastraBrowser {
|
|
|
446
481
|
title: string;
|
|
447
482
|
hint: string;
|
|
448
483
|
} | BrowserToolError>;
|
|
484
|
+
/**
|
|
485
|
+
* Capture a screenshot of the current page
|
|
486
|
+
* @param input - Screenshot input
|
|
487
|
+
* @param threadId - Optional thread ID for thread-safe operation
|
|
488
|
+
*/
|
|
489
|
+
screenshot(input: ScreenshotInput, threadId?: string): Promise<{
|
|
490
|
+
base64: string;
|
|
491
|
+
url: string;
|
|
492
|
+
title: string;
|
|
493
|
+
} | BrowserToolError>;
|
|
449
494
|
/**
|
|
450
495
|
* Manage browser tabs - list, create, switch, close
|
|
451
496
|
* @param input - Tabs input
|
|
@@ -515,19 +560,6 @@ declare class StagehandBrowser extends MastraBrowser {
|
|
|
515
560
|
*/
|
|
516
561
|
declare function getStagehandChromePid(stagehand: Stagehand): number | undefined;
|
|
517
562
|
|
|
518
|
-
/**
|
|
519
|
-
* Stagehand Tool Constants
|
|
520
|
-
*/
|
|
521
|
-
declare const STAGEHAND_TOOLS: {
|
|
522
|
-
readonly ACT: "stagehand_act";
|
|
523
|
-
readonly EXTRACT: "stagehand_extract";
|
|
524
|
-
readonly OBSERVE: "stagehand_observe";
|
|
525
|
-
readonly NAVIGATE: "stagehand_navigate";
|
|
526
|
-
readonly TABS: "stagehand_tabs";
|
|
527
|
-
readonly CLOSE: "stagehand_close";
|
|
528
|
-
};
|
|
529
|
-
type StagehandToolName = (typeof STAGEHAND_TOOLS)[keyof typeof STAGEHAND_TOOLS];
|
|
530
|
-
|
|
531
563
|
/**
|
|
532
564
|
* Stagehand Tools
|
|
533
565
|
*
|
package/dist/index.js
CHANGED
|
@@ -152,6 +152,9 @@ var tabsInputSchema = z.object({
|
|
|
152
152
|
});
|
|
153
153
|
}
|
|
154
154
|
});
|
|
155
|
+
var screenshotInputSchema = z.object({
|
|
156
|
+
fullPage: z.boolean().optional().describe("Capture the full scrollable page instead of just the viewport (default: false)")
|
|
157
|
+
});
|
|
155
158
|
var stagehandSchemas = {
|
|
156
159
|
// Core AI
|
|
157
160
|
act: actInputSchema,
|
|
@@ -160,7 +163,9 @@ var stagehandSchemas = {
|
|
|
160
163
|
// Navigation & State
|
|
161
164
|
navigate: navigateInputSchema,
|
|
162
165
|
tabs: tabsInputSchema,
|
|
163
|
-
close: closeInputSchema
|
|
166
|
+
close: closeInputSchema,
|
|
167
|
+
// Utility
|
|
168
|
+
screenshot: screenshotInputSchema
|
|
164
169
|
};
|
|
165
170
|
|
|
166
171
|
// src/tools/constants.ts
|
|
@@ -172,7 +177,9 @@ var STAGEHAND_TOOLS = {
|
|
|
172
177
|
// Navigation & State
|
|
173
178
|
NAVIGATE: "stagehand_navigate",
|
|
174
179
|
TABS: "stagehand_tabs",
|
|
175
|
-
CLOSE: "stagehand_close"
|
|
180
|
+
CLOSE: "stagehand_close",
|
|
181
|
+
// Utility
|
|
182
|
+
SCREENSHOT: "stagehand_screenshot"
|
|
176
183
|
};
|
|
177
184
|
|
|
178
185
|
// src/tools/act.ts
|
|
@@ -253,6 +260,38 @@ function createObserveTool(browser) {
|
|
|
253
260
|
}
|
|
254
261
|
});
|
|
255
262
|
}
|
|
263
|
+
function createScreenshotTool(browser) {
|
|
264
|
+
return createTool({
|
|
265
|
+
id: STAGEHAND_TOOLS.SCREENSHOT,
|
|
266
|
+
description: "Capture a screenshot of the current viewport as a visible PNG (set fullPage: true for full-page capture). Use observe or extract when you only need text or interactive elements \u2014 screenshots are expensive. Use this when you need to visually inspect the page, e.g. evaluating images, product photos, layout, design, or colors.",
|
|
267
|
+
inputSchema: screenshotInputSchema,
|
|
268
|
+
execute: async (input, { agent }) => {
|
|
269
|
+
const threadId = agent?.threadId;
|
|
270
|
+
browser.setCurrentThread(threadId);
|
|
271
|
+
await browser.ensureReady();
|
|
272
|
+
return await browser.screenshot(input, threadId);
|
|
273
|
+
},
|
|
274
|
+
toModelOutput(output) {
|
|
275
|
+
const result = output;
|
|
276
|
+
if (typeof result.base64 !== "string") {
|
|
277
|
+
return {
|
|
278
|
+
type: "content",
|
|
279
|
+
value: [{ type: "text", text: result.message ?? "Failed to capture screenshot." }]
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
return {
|
|
283
|
+
type: "content",
|
|
284
|
+
value: [
|
|
285
|
+
{
|
|
286
|
+
type: "media",
|
|
287
|
+
mediaType: "image/png",
|
|
288
|
+
data: result.base64
|
|
289
|
+
}
|
|
290
|
+
]
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
}
|
|
256
295
|
function createTabsTool(browser) {
|
|
257
296
|
return createTool({
|
|
258
297
|
id: STAGEHAND_TOOLS.TABS,
|
|
@@ -277,7 +316,9 @@ function createStagehandTools(browser) {
|
|
|
277
316
|
// Navigation & State
|
|
278
317
|
[STAGEHAND_TOOLS.NAVIGATE]: createNavigateTool(browser),
|
|
279
318
|
[STAGEHAND_TOOLS.TABS]: createTabsTool(browser),
|
|
280
|
-
[STAGEHAND_TOOLS.CLOSE]: createCloseTool(browser)
|
|
319
|
+
[STAGEHAND_TOOLS.CLOSE]: createCloseTool(browser),
|
|
320
|
+
// Utility
|
|
321
|
+
[STAGEHAND_TOOLS.SCREENSHOT]: createScreenshotTool(browser)
|
|
281
322
|
};
|
|
282
323
|
}
|
|
283
324
|
function patchProfileExitType(profilePath, logger) {
|
|
@@ -636,7 +677,14 @@ var StagehandBrowser = class extends MastraBrowser {
|
|
|
636
677
|
// Tools - Implements MastraBrowser.getTools()
|
|
637
678
|
// ---------------------------------------------------------------------------
|
|
638
679
|
getTools() {
|
|
639
|
-
|
|
680
|
+
const tools = createStagehandTools(this);
|
|
681
|
+
const exclude = this.stagehandConfig.excludeTools;
|
|
682
|
+
if (exclude?.length) {
|
|
683
|
+
for (const name of exclude) {
|
|
684
|
+
delete tools[name];
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
return tools;
|
|
640
688
|
}
|
|
641
689
|
// ---------------------------------------------------------------------------
|
|
642
690
|
// Core AI Methods
|
|
@@ -746,6 +794,32 @@ var StagehandBrowser = class extends MastraBrowser {
|
|
|
746
794
|
}
|
|
747
795
|
}
|
|
748
796
|
// ---------------------------------------------------------------------------
|
|
797
|
+
// Screenshot
|
|
798
|
+
// ---------------------------------------------------------------------------
|
|
799
|
+
/**
|
|
800
|
+
* Capture a screenshot of the current page
|
|
801
|
+
* @param input - Screenshot input
|
|
802
|
+
* @param threadId - Optional thread ID for thread-safe operation
|
|
803
|
+
*/
|
|
804
|
+
async screenshot(input, threadId) {
|
|
805
|
+
const page = this.getPage(threadId);
|
|
806
|
+
if (!page) {
|
|
807
|
+
return this.createError("browser_error", "Browser page not available.", "Ensure the browser is launched.");
|
|
808
|
+
}
|
|
809
|
+
try {
|
|
810
|
+
const buffer = await page.screenshot({
|
|
811
|
+
fullPage: input.fullPage ?? false,
|
|
812
|
+
type: "png"
|
|
813
|
+
});
|
|
814
|
+
const base64 = Buffer.from(buffer).toString("base64");
|
|
815
|
+
const url = page.url();
|
|
816
|
+
const title = await page.title();
|
|
817
|
+
return { base64, url, title };
|
|
818
|
+
} catch (error) {
|
|
819
|
+
return this.createErrorFromException(error, "Screenshot");
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
// ---------------------------------------------------------------------------
|
|
749
823
|
// Tab Management
|
|
750
824
|
// ---------------------------------------------------------------------------
|
|
751
825
|
/**
|