@mastra/stagehand 0.2.1 → 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 +17 -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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @mastra/stagehand
|
|
2
2
|
|
|
3
|
+
## 0.2.2-alpha.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Added `screenshot` tool to `@mastra/stagehand` (`stagehand_screenshot`) and `@mastra/agent-browser` (`browser_screenshot`). Captures a PNG screenshot and returns image content for vision-capable models. ([#16074](https://github.com/mastra-ai/mastra/pull/16074))
|
|
8
|
+
|
|
9
|
+
Added `excludeTools` config option to opt out of specific tools:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
const browser = new StagehandBrowser({
|
|
13
|
+
excludeTools: ['stagehand_screenshot'],
|
|
14
|
+
});
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [[`b59316f`](https://github.com/mastra-ai/mastra/commit/b59316ffa0f7688165b0f9c81ccdf85da461e5b2), [`55f1e2d`](https://github.com/mastra-ai/mastra/commit/55f1e2d65425b95a49ae788053b266f256e38c96), [`d48a705`](https://github.com/mastra-ai/mastra/commit/d48a705ff3dfbdc7a996e07ecd8293b5effd9a2a)]:
|
|
18
|
+
- @mastra/core@1.33.0-alpha.12
|
|
19
|
+
|
|
3
20
|
## 0.2.1
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -154,6 +154,9 @@ var tabsInputSchema = zod.z.object({
|
|
|
154
154
|
});
|
|
155
155
|
}
|
|
156
156
|
});
|
|
157
|
+
var screenshotInputSchema = zod.z.object({
|
|
158
|
+
fullPage: zod.z.boolean().optional().describe("Capture the full scrollable page instead of just the viewport (default: false)")
|
|
159
|
+
});
|
|
157
160
|
var stagehandSchemas = {
|
|
158
161
|
// Core AI
|
|
159
162
|
act: actInputSchema,
|
|
@@ -162,7 +165,9 @@ var stagehandSchemas = {
|
|
|
162
165
|
// Navigation & State
|
|
163
166
|
navigate: navigateInputSchema,
|
|
164
167
|
tabs: tabsInputSchema,
|
|
165
|
-
close: closeInputSchema
|
|
168
|
+
close: closeInputSchema,
|
|
169
|
+
// Utility
|
|
170
|
+
screenshot: screenshotInputSchema
|
|
166
171
|
};
|
|
167
172
|
|
|
168
173
|
// src/tools/constants.ts
|
|
@@ -174,7 +179,9 @@ var STAGEHAND_TOOLS = {
|
|
|
174
179
|
// Navigation & State
|
|
175
180
|
NAVIGATE: "stagehand_navigate",
|
|
176
181
|
TABS: "stagehand_tabs",
|
|
177
|
-
CLOSE: "stagehand_close"
|
|
182
|
+
CLOSE: "stagehand_close",
|
|
183
|
+
// Utility
|
|
184
|
+
SCREENSHOT: "stagehand_screenshot"
|
|
178
185
|
};
|
|
179
186
|
|
|
180
187
|
// src/tools/act.ts
|
|
@@ -255,6 +262,38 @@ function createObserveTool(browser) {
|
|
|
255
262
|
}
|
|
256
263
|
});
|
|
257
264
|
}
|
|
265
|
+
function createScreenshotTool(browser) {
|
|
266
|
+
return tools.createTool({
|
|
267
|
+
id: STAGEHAND_TOOLS.SCREENSHOT,
|
|
268
|
+
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.",
|
|
269
|
+
inputSchema: screenshotInputSchema,
|
|
270
|
+
execute: async (input, { agent }) => {
|
|
271
|
+
const threadId = agent?.threadId;
|
|
272
|
+
browser.setCurrentThread(threadId);
|
|
273
|
+
await browser.ensureReady();
|
|
274
|
+
return await browser.screenshot(input, threadId);
|
|
275
|
+
},
|
|
276
|
+
toModelOutput(output) {
|
|
277
|
+
const result = output;
|
|
278
|
+
if (typeof result.base64 !== "string") {
|
|
279
|
+
return {
|
|
280
|
+
type: "content",
|
|
281
|
+
value: [{ type: "text", text: result.message ?? "Failed to capture screenshot." }]
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
return {
|
|
285
|
+
type: "content",
|
|
286
|
+
value: [
|
|
287
|
+
{
|
|
288
|
+
type: "media",
|
|
289
|
+
mediaType: "image/png",
|
|
290
|
+
data: result.base64
|
|
291
|
+
}
|
|
292
|
+
]
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
}
|
|
258
297
|
function createTabsTool(browser) {
|
|
259
298
|
return tools.createTool({
|
|
260
299
|
id: STAGEHAND_TOOLS.TABS,
|
|
@@ -279,7 +318,9 @@ function createStagehandTools(browser) {
|
|
|
279
318
|
// Navigation & State
|
|
280
319
|
[STAGEHAND_TOOLS.NAVIGATE]: createNavigateTool(browser),
|
|
281
320
|
[STAGEHAND_TOOLS.TABS]: createTabsTool(browser),
|
|
282
|
-
[STAGEHAND_TOOLS.CLOSE]: createCloseTool(browser)
|
|
321
|
+
[STAGEHAND_TOOLS.CLOSE]: createCloseTool(browser),
|
|
322
|
+
// Utility
|
|
323
|
+
[STAGEHAND_TOOLS.SCREENSHOT]: createScreenshotTool(browser)
|
|
283
324
|
};
|
|
284
325
|
}
|
|
285
326
|
function patchProfileExitType(profilePath, logger) {
|
|
@@ -638,7 +679,14 @@ var StagehandBrowser = class extends browser.MastraBrowser {
|
|
|
638
679
|
// Tools - Implements MastraBrowser.getTools()
|
|
639
680
|
// ---------------------------------------------------------------------------
|
|
640
681
|
getTools() {
|
|
641
|
-
|
|
682
|
+
const tools = createStagehandTools(this);
|
|
683
|
+
const exclude = this.stagehandConfig.excludeTools;
|
|
684
|
+
if (exclude?.length) {
|
|
685
|
+
for (const name of exclude) {
|
|
686
|
+
delete tools[name];
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
return tools;
|
|
642
690
|
}
|
|
643
691
|
// ---------------------------------------------------------------------------
|
|
644
692
|
// Core AI Methods
|
|
@@ -748,6 +796,32 @@ var StagehandBrowser = class extends browser.MastraBrowser {
|
|
|
748
796
|
}
|
|
749
797
|
}
|
|
750
798
|
// ---------------------------------------------------------------------------
|
|
799
|
+
// Screenshot
|
|
800
|
+
// ---------------------------------------------------------------------------
|
|
801
|
+
/**
|
|
802
|
+
* Capture a screenshot of the current page
|
|
803
|
+
* @param input - Screenshot input
|
|
804
|
+
* @param threadId - Optional thread ID for thread-safe operation
|
|
805
|
+
*/
|
|
806
|
+
async screenshot(input, threadId) {
|
|
807
|
+
const page = this.getPage(threadId);
|
|
808
|
+
if (!page) {
|
|
809
|
+
return this.createError("browser_error", "Browser page not available.", "Ensure the browser is launched.");
|
|
810
|
+
}
|
|
811
|
+
try {
|
|
812
|
+
const buffer = await page.screenshot({
|
|
813
|
+
fullPage: input.fullPage ?? false,
|
|
814
|
+
type: "png"
|
|
815
|
+
});
|
|
816
|
+
const base64 = Buffer.from(buffer).toString("base64");
|
|
817
|
+
const url = page.url();
|
|
818
|
+
const title = await page.title();
|
|
819
|
+
return { base64, url, title };
|
|
820
|
+
} catch (error) {
|
|
821
|
+
return this.createErrorFromException(error, "Screenshot");
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
// ---------------------------------------------------------------------------
|
|
751
825
|
// Tab Management
|
|
752
826
|
// ---------------------------------------------------------------------------
|
|
753
827
|
/**
|