@mastra/agent-browser 0.3.0-alpha.0 → 0.3.0-alpha.1
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 +19 -0
- package/dist/index.cjs +23 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +36 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +23 -10
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -54,6 +54,12 @@ declare const clickInputSchema: z.ZodObject<{
|
|
|
54
54
|
Meta: "Meta";
|
|
55
55
|
Shift: "Shift";
|
|
56
56
|
}>>>;
|
|
57
|
+
waitUntil: z.ZodOptional<z.ZodEnum<{
|
|
58
|
+
load: "load";
|
|
59
|
+
domcontentloaded: "domcontentloaded";
|
|
60
|
+
networkidle: "networkidle";
|
|
61
|
+
}>>;
|
|
62
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
57
63
|
}, z.core.$strip>;
|
|
58
64
|
type ClickInput = z.output<typeof clickInputSchema>;
|
|
59
65
|
/**
|
|
@@ -77,6 +83,12 @@ declare const pressInputSchema: z.ZodObject<{
|
|
|
77
83
|
Meta: "Meta";
|
|
78
84
|
Shift: "Shift";
|
|
79
85
|
}>>>;
|
|
86
|
+
waitUntil: z.ZodOptional<z.ZodEnum<{
|
|
87
|
+
load: "load";
|
|
88
|
+
domcontentloaded: "domcontentloaded";
|
|
89
|
+
networkidle: "networkidle";
|
|
90
|
+
}>>;
|
|
91
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
80
92
|
}, z.core.$strip>;
|
|
81
93
|
type PressInput = z.output<typeof pressInputSchema>;
|
|
82
94
|
/**
|
|
@@ -87,6 +99,12 @@ declare const selectInputSchema: z.ZodObject<{
|
|
|
87
99
|
value: z.ZodOptional<z.ZodString>;
|
|
88
100
|
label: z.ZodOptional<z.ZodString>;
|
|
89
101
|
index: z.ZodOptional<z.ZodNumber>;
|
|
102
|
+
waitUntil: z.ZodOptional<z.ZodEnum<{
|
|
103
|
+
load: "load";
|
|
104
|
+
domcontentloaded: "domcontentloaded";
|
|
105
|
+
networkidle: "networkidle";
|
|
106
|
+
}>>;
|
|
107
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
90
108
|
}, z.core.$strip>;
|
|
91
109
|
type SelectInput = z.output<typeof selectInputSchema>;
|
|
92
110
|
/**
|
|
@@ -213,6 +231,12 @@ declare const browserSchemas: {
|
|
|
213
231
|
Meta: "Meta";
|
|
214
232
|
Shift: "Shift";
|
|
215
233
|
}>>>;
|
|
234
|
+
waitUntil: z.ZodOptional<z.ZodEnum<{
|
|
235
|
+
load: "load";
|
|
236
|
+
domcontentloaded: "domcontentloaded";
|
|
237
|
+
networkidle: "networkidle";
|
|
238
|
+
}>>;
|
|
239
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
216
240
|
}, z.core.$strip>;
|
|
217
241
|
readonly type: z.ZodObject<{
|
|
218
242
|
ref: z.ZodString;
|
|
@@ -228,12 +252,24 @@ declare const browserSchemas: {
|
|
|
228
252
|
Meta: "Meta";
|
|
229
253
|
Shift: "Shift";
|
|
230
254
|
}>>>;
|
|
255
|
+
waitUntil: z.ZodOptional<z.ZodEnum<{
|
|
256
|
+
load: "load";
|
|
257
|
+
domcontentloaded: "domcontentloaded";
|
|
258
|
+
networkidle: "networkidle";
|
|
259
|
+
}>>;
|
|
260
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
231
261
|
}, z.core.$strip>;
|
|
232
262
|
readonly select: z.ZodObject<{
|
|
233
263
|
ref: z.ZodString;
|
|
234
264
|
value: z.ZodOptional<z.ZodString>;
|
|
235
265
|
label: z.ZodOptional<z.ZodString>;
|
|
236
266
|
index: z.ZodOptional<z.ZodNumber>;
|
|
267
|
+
waitUntil: z.ZodOptional<z.ZodEnum<{
|
|
268
|
+
load: "load";
|
|
269
|
+
domcontentloaded: "domcontentloaded";
|
|
270
|
+
networkidle: "networkidle";
|
|
271
|
+
}>>;
|
|
272
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
237
273
|
}, z.core.$strip>;
|
|
238
274
|
readonly scroll: z.ZodObject<{
|
|
239
275
|
direction: z.ZodEnum<{
|
package/dist/index.d.ts
CHANGED
|
@@ -54,6 +54,12 @@ declare const clickInputSchema: z.ZodObject<{
|
|
|
54
54
|
Meta: "Meta";
|
|
55
55
|
Shift: "Shift";
|
|
56
56
|
}>>>;
|
|
57
|
+
waitUntil: z.ZodOptional<z.ZodEnum<{
|
|
58
|
+
load: "load";
|
|
59
|
+
domcontentloaded: "domcontentloaded";
|
|
60
|
+
networkidle: "networkidle";
|
|
61
|
+
}>>;
|
|
62
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
57
63
|
}, z.core.$strip>;
|
|
58
64
|
type ClickInput = z.output<typeof clickInputSchema>;
|
|
59
65
|
/**
|
|
@@ -77,6 +83,12 @@ declare const pressInputSchema: z.ZodObject<{
|
|
|
77
83
|
Meta: "Meta";
|
|
78
84
|
Shift: "Shift";
|
|
79
85
|
}>>>;
|
|
86
|
+
waitUntil: z.ZodOptional<z.ZodEnum<{
|
|
87
|
+
load: "load";
|
|
88
|
+
domcontentloaded: "domcontentloaded";
|
|
89
|
+
networkidle: "networkidle";
|
|
90
|
+
}>>;
|
|
91
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
80
92
|
}, z.core.$strip>;
|
|
81
93
|
type PressInput = z.output<typeof pressInputSchema>;
|
|
82
94
|
/**
|
|
@@ -87,6 +99,12 @@ declare const selectInputSchema: z.ZodObject<{
|
|
|
87
99
|
value: z.ZodOptional<z.ZodString>;
|
|
88
100
|
label: z.ZodOptional<z.ZodString>;
|
|
89
101
|
index: z.ZodOptional<z.ZodNumber>;
|
|
102
|
+
waitUntil: z.ZodOptional<z.ZodEnum<{
|
|
103
|
+
load: "load";
|
|
104
|
+
domcontentloaded: "domcontentloaded";
|
|
105
|
+
networkidle: "networkidle";
|
|
106
|
+
}>>;
|
|
107
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
90
108
|
}, z.core.$strip>;
|
|
91
109
|
type SelectInput = z.output<typeof selectInputSchema>;
|
|
92
110
|
/**
|
|
@@ -213,6 +231,12 @@ declare const browserSchemas: {
|
|
|
213
231
|
Meta: "Meta";
|
|
214
232
|
Shift: "Shift";
|
|
215
233
|
}>>>;
|
|
234
|
+
waitUntil: z.ZodOptional<z.ZodEnum<{
|
|
235
|
+
load: "load";
|
|
236
|
+
domcontentloaded: "domcontentloaded";
|
|
237
|
+
networkidle: "networkidle";
|
|
238
|
+
}>>;
|
|
239
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
216
240
|
}, z.core.$strip>;
|
|
217
241
|
readonly type: z.ZodObject<{
|
|
218
242
|
ref: z.ZodString;
|
|
@@ -228,12 +252,24 @@ declare const browserSchemas: {
|
|
|
228
252
|
Meta: "Meta";
|
|
229
253
|
Shift: "Shift";
|
|
230
254
|
}>>>;
|
|
255
|
+
waitUntil: z.ZodOptional<z.ZodEnum<{
|
|
256
|
+
load: "load";
|
|
257
|
+
domcontentloaded: "domcontentloaded";
|
|
258
|
+
networkidle: "networkidle";
|
|
259
|
+
}>>;
|
|
260
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
231
261
|
}, z.core.$strip>;
|
|
232
262
|
readonly select: z.ZodObject<{
|
|
233
263
|
ref: z.ZodString;
|
|
234
264
|
value: z.ZodOptional<z.ZodString>;
|
|
235
265
|
label: z.ZodOptional<z.ZodString>;
|
|
236
266
|
index: z.ZodOptional<z.ZodNumber>;
|
|
267
|
+
waitUntil: z.ZodOptional<z.ZodEnum<{
|
|
268
|
+
load: "load";
|
|
269
|
+
domcontentloaded: "domcontentloaded";
|
|
270
|
+
networkidle: "networkidle";
|
|
271
|
+
}>>;
|
|
272
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
237
273
|
}, z.core.$strip>;
|
|
238
274
|
readonly scroll: z.ZodObject<{
|
|
239
275
|
direction: z.ZodEnum<{
|
package/dist/index.js
CHANGED
|
@@ -139,7 +139,9 @@ var clickInputSchema = z.object({
|
|
|
139
139
|
ref: z.string().describe("Element ref from snapshot (e.g., @e5)"),
|
|
140
140
|
button: z.enum(["left", "right", "middle"]).optional().describe("Mouse button (default: left)"),
|
|
141
141
|
clickCount: z.number().optional().describe("Number of clicks (default: 1, use 2 for double-click)"),
|
|
142
|
-
modifiers: z.array(z.enum(["Alt", "Control", "Meta", "Shift"])).optional().describe("Modifier keys to hold")
|
|
142
|
+
modifiers: z.array(z.enum(["Alt", "Control", "Meta", "Shift"])).optional().describe("Modifier keys to hold"),
|
|
143
|
+
waitUntil: z.enum(["load", "domcontentloaded", "networkidle"]).optional().describe("If the click triggers a navigation, wait for this page load state before returning"),
|
|
144
|
+
timeout: z.number().nonnegative().optional().describe("Timeout in milliseconds for the click and optional waitUntil")
|
|
143
145
|
});
|
|
144
146
|
var typeInputSchema = z.object({
|
|
145
147
|
ref: z.string().describe("Element ref from snapshot"),
|
|
@@ -149,13 +151,17 @@ var typeInputSchema = z.object({
|
|
|
149
151
|
});
|
|
150
152
|
var pressInputSchema = z.object({
|
|
151
153
|
key: z.string().describe("Key to press (e.g., Enter, Tab, Escape, Control+a)"),
|
|
152
|
-
modifiers: z.array(z.enum(["Alt", "Control", "Meta", "Shift"])).optional().describe("Modifier keys to hold")
|
|
154
|
+
modifiers: z.array(z.enum(["Alt", "Control", "Meta", "Shift"])).optional().describe("Modifier keys to hold"),
|
|
155
|
+
waitUntil: z.enum(["load", "domcontentloaded", "networkidle"]).optional().describe("If the key press triggers a navigation, wait for this page load state before returning"),
|
|
156
|
+
timeout: z.number().nonnegative().optional().describe("Timeout in milliseconds for the optional waitUntil")
|
|
153
157
|
});
|
|
154
158
|
var selectInputSchema = z.object({
|
|
155
159
|
ref: z.string().describe("Select element ref from snapshot"),
|
|
156
160
|
value: z.string().optional().describe("Option value to select"),
|
|
157
161
|
label: z.string().optional().describe("Option label to select"),
|
|
158
|
-
index: z.number().int().min(0).optional().describe("Option index to select (0-based)")
|
|
162
|
+
index: z.number().int().min(0).optional().describe("Option index to select (0-based)"),
|
|
163
|
+
waitUntil: z.enum(["load", "domcontentloaded", "networkidle"]).optional().describe("If the selection triggers a navigation, wait for this page load state before returning"),
|
|
164
|
+
timeout: z.number().nonnegative().optional().describe("Timeout in milliseconds for the selection and optional waitUntil")
|
|
159
165
|
}).superRefine((data, ctx) => {
|
|
160
166
|
if (data.value === void 0 && data.label === void 0 && data.index === void 0) {
|
|
161
167
|
ctx.addIssue({
|
|
@@ -291,7 +297,7 @@ function createBackTool(browser) {
|
|
|
291
297
|
function createClickTool(browser) {
|
|
292
298
|
return createTool({
|
|
293
299
|
id: BROWSER_TOOLS.CLICK,
|
|
294
|
-
description: "Click an element using its ref from a snapshot. Use clickCount: 2 for double-click.",
|
|
300
|
+
description: "Click an element using its ref from a snapshot. Use clickCount: 2 for double-click. Pass waitUntil when the click triggers navigation so the page settles before the next snapshot.",
|
|
295
301
|
inputSchema: clickInputSchema,
|
|
296
302
|
execute: async (input, { agent }) => {
|
|
297
303
|
const threadId = agent?.threadId;
|
|
@@ -388,7 +394,7 @@ function createHoverTool(browser) {
|
|
|
388
394
|
function createPressTool(browser) {
|
|
389
395
|
return createTool({
|
|
390
396
|
id: BROWSER_TOOLS.PRESS,
|
|
391
|
-
description: "Press a keyboard key (e.g., Enter, Tab, Escape, Control+a).",
|
|
397
|
+
description: "Press a keyboard key (e.g., Enter, Tab, Escape, Control+a). Pass waitUntil when the keypress triggers navigation (e.g., Enter to submit a form) so the page settles before the next snapshot.",
|
|
392
398
|
inputSchema: pressInputSchema,
|
|
393
399
|
execute: async (input, { agent }) => {
|
|
394
400
|
const threadId = agent?.threadId;
|
|
@@ -446,7 +452,7 @@ function createScrollTool(browser) {
|
|
|
446
452
|
function createSelectTool(browser) {
|
|
447
453
|
return createTool({
|
|
448
454
|
id: BROWSER_TOOLS.SELECT,
|
|
449
|
-
description: "Select an option from a dropdown by value, label, or index.",
|
|
455
|
+
description: "Select an option from a dropdown by value, label, or index. Pass waitUntil when the selection triggers navigation so the page settles before the next snapshot.",
|
|
450
456
|
inputSchema: selectInputSchema,
|
|
451
457
|
execute: async (input, { agent }) => {
|
|
452
458
|
const threadId = agent?.threadId;
|
|
@@ -1089,12 +1095,15 @@ var AgentBrowser = class extends MastraBrowser {
|
|
|
1089
1095
|
"Take a new snapshot to see the current page state and get fresh refs."
|
|
1090
1096
|
);
|
|
1091
1097
|
}
|
|
1098
|
+
const timeout = input.timeout ?? this.defaultTimeout;
|
|
1099
|
+
const navigation = input.waitUntil ? page.waitForNavigation({ waitUntil: input.waitUntil, timeout }) : void 0;
|
|
1092
1100
|
await locator.click({
|
|
1093
1101
|
button: input.button ?? "left",
|
|
1094
1102
|
clickCount: input.clickCount ?? 1,
|
|
1095
1103
|
modifiers: input.modifiers,
|
|
1096
|
-
timeout
|
|
1104
|
+
timeout
|
|
1097
1105
|
});
|
|
1106
|
+
await navigation;
|
|
1098
1107
|
return {
|
|
1099
1108
|
success: true,
|
|
1100
1109
|
url: page.url(),
|
|
@@ -1163,7 +1172,10 @@ var AgentBrowser = class extends MastraBrowser {
|
|
|
1163
1172
|
async press(input, threadId) {
|
|
1164
1173
|
try {
|
|
1165
1174
|
const page = await this.getPage(threadId);
|
|
1175
|
+
const timeout = input.timeout ?? this.defaultTimeout;
|
|
1176
|
+
const navigation = input.waitUntil ? page.waitForNavigation({ waitUntil: input.waitUntil, timeout }) : void 0;
|
|
1166
1177
|
await page.keyboard.press(input.key);
|
|
1178
|
+
await navigation;
|
|
1167
1179
|
return {
|
|
1168
1180
|
success: true,
|
|
1169
1181
|
url: page.url(),
|
|
@@ -1191,9 +1203,10 @@ var AgentBrowser = class extends MastraBrowser {
|
|
|
1191
1203
|
if (input.value) selectValue.value = input.value;
|
|
1192
1204
|
if (input.label) selectValue.label = input.label;
|
|
1193
1205
|
if (input.index !== void 0) selectValue.index = input.index;
|
|
1194
|
-
const
|
|
1195
|
-
|
|
1196
|
-
});
|
|
1206
|
+
const timeout = input.timeout ?? this.defaultTimeout;
|
|
1207
|
+
const navigation = input.waitUntil ? page.waitForNavigation({ waitUntil: input.waitUntil, timeout }) : void 0;
|
|
1208
|
+
const selected = await locator.selectOption(selectValue, { timeout });
|
|
1209
|
+
await navigation;
|
|
1197
1210
|
return {
|
|
1198
1211
|
success: true,
|
|
1199
1212
|
selected,
|