@mastra/agent-browser 0.0.0-async-hooks-fix-20260405144639
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 +74 -0
- package/LICENSE.md +30 -0
- package/dist/index.cjs +1577 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +588 -0
- package/dist/index.d.ts +588 -0
- package/dist/index.js +1557 -0
- package/dist/index.js.map +1 -0
- package/package.json +66 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,588 @@
|
|
|
1
|
+
import { BrowserConfig as BrowserConfig$1, ThreadManager, ThreadManagerConfig, ThreadSession, MastraBrowser, BrowserToolError, BrowserState, BrowserTabState, ScreencastOptions, ScreencastStream, MouseEventParams, KeyboardEventParams } from '@mastra/core/browser';
|
|
2
|
+
import { Tool } from '@mastra/core/tools';
|
|
3
|
+
import { BrowserManager } from 'agent-browser';
|
|
4
|
+
import { Page } from 'playwright-core';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* AgentBrowser Tool Schemas
|
|
9
|
+
*
|
|
10
|
+
* Flat schemas for browser tools. Each tool has a single-purpose schema
|
|
11
|
+
* without discriminated unions, making them easier for LLMs to understand.
|
|
12
|
+
*
|
|
13
|
+
* Tools:
|
|
14
|
+
* - Core: goto, snapshot, click, type, press, select, scroll, close
|
|
15
|
+
* - Extended: hover, back, dialog, wait, tabs, drag
|
|
16
|
+
* - Escape Hatch: evaluate
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* browser_goto - Navigate to a URL
|
|
21
|
+
*/
|
|
22
|
+
declare const gotoInputSchema: z.ZodObject<{
|
|
23
|
+
url: z.ZodString;
|
|
24
|
+
waitUntil: z.ZodOptional<z.ZodEnum<{
|
|
25
|
+
load: "load";
|
|
26
|
+
domcontentloaded: "domcontentloaded";
|
|
27
|
+
networkidle: "networkidle";
|
|
28
|
+
}>>;
|
|
29
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
30
|
+
}, z.core.$strip>;
|
|
31
|
+
type GotoInput = z.output<typeof gotoInputSchema>;
|
|
32
|
+
/**
|
|
33
|
+
* browser_snapshot - Get accessibility tree snapshot
|
|
34
|
+
*/
|
|
35
|
+
declare const snapshotInputSchema: z.ZodObject<{
|
|
36
|
+
interactiveOnly: z.ZodOptional<z.ZodBoolean>;
|
|
37
|
+
maxDepth: z.ZodOptional<z.ZodNumber>;
|
|
38
|
+
}, z.core.$strip>;
|
|
39
|
+
type SnapshotInput = z.output<typeof snapshotInputSchema>;
|
|
40
|
+
/**
|
|
41
|
+
* browser_click - Click an element
|
|
42
|
+
*/
|
|
43
|
+
declare const clickInputSchema: z.ZodObject<{
|
|
44
|
+
ref: z.ZodString;
|
|
45
|
+
button: z.ZodOptional<z.ZodEnum<{
|
|
46
|
+
left: "left";
|
|
47
|
+
right: "right";
|
|
48
|
+
middle: "middle";
|
|
49
|
+
}>>;
|
|
50
|
+
clickCount: z.ZodOptional<z.ZodNumber>;
|
|
51
|
+
modifiers: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
52
|
+
Alt: "Alt";
|
|
53
|
+
Control: "Control";
|
|
54
|
+
Meta: "Meta";
|
|
55
|
+
Shift: "Shift";
|
|
56
|
+
}>>>;
|
|
57
|
+
}, z.core.$strip>;
|
|
58
|
+
type ClickInput = z.output<typeof clickInputSchema>;
|
|
59
|
+
/**
|
|
60
|
+
* browser_type - Type text into an element
|
|
61
|
+
*/
|
|
62
|
+
declare const typeInputSchema: z.ZodObject<{
|
|
63
|
+
ref: z.ZodString;
|
|
64
|
+
text: z.ZodString;
|
|
65
|
+
clear: z.ZodOptional<z.ZodBoolean>;
|
|
66
|
+
delay: z.ZodOptional<z.ZodNumber>;
|
|
67
|
+
}, z.core.$strip>;
|
|
68
|
+
type TypeInput = z.output<typeof typeInputSchema>;
|
|
69
|
+
/**
|
|
70
|
+
* browser_press - Press a keyboard key
|
|
71
|
+
*/
|
|
72
|
+
declare const pressInputSchema: z.ZodObject<{
|
|
73
|
+
key: z.ZodString;
|
|
74
|
+
modifiers: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
75
|
+
Alt: "Alt";
|
|
76
|
+
Control: "Control";
|
|
77
|
+
Meta: "Meta";
|
|
78
|
+
Shift: "Shift";
|
|
79
|
+
}>>>;
|
|
80
|
+
}, z.core.$strip>;
|
|
81
|
+
type PressInput = z.output<typeof pressInputSchema>;
|
|
82
|
+
/**
|
|
83
|
+
* browser_select - Select option from dropdown
|
|
84
|
+
*/
|
|
85
|
+
declare const selectInputSchema: z.ZodObject<{
|
|
86
|
+
ref: z.ZodString;
|
|
87
|
+
value: z.ZodOptional<z.ZodString>;
|
|
88
|
+
label: z.ZodOptional<z.ZodString>;
|
|
89
|
+
index: z.ZodOptional<z.ZodNumber>;
|
|
90
|
+
}, z.core.$strip>;
|
|
91
|
+
type SelectInput = z.output<typeof selectInputSchema>;
|
|
92
|
+
/**
|
|
93
|
+
* browser_scroll - Scroll the page or element
|
|
94
|
+
*/
|
|
95
|
+
declare const scrollInputSchema: z.ZodObject<{
|
|
96
|
+
direction: z.ZodEnum<{
|
|
97
|
+
left: "left";
|
|
98
|
+
right: "right";
|
|
99
|
+
up: "up";
|
|
100
|
+
down: "down";
|
|
101
|
+
}>;
|
|
102
|
+
amount: z.ZodOptional<z.ZodNumber>;
|
|
103
|
+
ref: z.ZodOptional<z.ZodString>;
|
|
104
|
+
}, z.core.$strip>;
|
|
105
|
+
type ScrollInput = z.output<typeof scrollInputSchema>;
|
|
106
|
+
/**
|
|
107
|
+
* browser_close - Close the browser
|
|
108
|
+
*/
|
|
109
|
+
declare const closeInputSchema: z.ZodObject<{}, z.core.$strip>;
|
|
110
|
+
type CloseInput = z.output<typeof closeInputSchema>;
|
|
111
|
+
/**
|
|
112
|
+
* browser_hover - Hover over an element
|
|
113
|
+
*/
|
|
114
|
+
declare const hoverInputSchema: z.ZodObject<{
|
|
115
|
+
ref: z.ZodString;
|
|
116
|
+
}, z.core.$strip>;
|
|
117
|
+
type HoverInput = z.output<typeof hoverInputSchema>;
|
|
118
|
+
/**
|
|
119
|
+
* browser_back - Go back in browser history
|
|
120
|
+
*/
|
|
121
|
+
declare const backInputSchema: z.ZodObject<{}, z.core.$strip>;
|
|
122
|
+
type BackInput = z.output<typeof backInputSchema>;
|
|
123
|
+
/**
|
|
124
|
+
* browser_dialog - Click an element that triggers a dialog and handle it
|
|
125
|
+
*/
|
|
126
|
+
declare const dialogInputSchema: z.ZodObject<{
|
|
127
|
+
triggerRef: z.ZodString;
|
|
128
|
+
action: z.ZodEnum<{
|
|
129
|
+
accept: "accept";
|
|
130
|
+
dismiss: "dismiss";
|
|
131
|
+
}>;
|
|
132
|
+
text: z.ZodOptional<z.ZodString>;
|
|
133
|
+
}, z.core.$strip>;
|
|
134
|
+
type DialogInput = z.output<typeof dialogInputSchema>;
|
|
135
|
+
/**
|
|
136
|
+
* browser_wait - Wait for an element or condition
|
|
137
|
+
*/
|
|
138
|
+
declare const waitInputSchema: z.ZodObject<{
|
|
139
|
+
ref: z.ZodOptional<z.ZodString>;
|
|
140
|
+
state: z.ZodOptional<z.ZodEnum<{
|
|
141
|
+
visible: "visible";
|
|
142
|
+
hidden: "hidden";
|
|
143
|
+
attached: "attached";
|
|
144
|
+
detached: "detached";
|
|
145
|
+
}>>;
|
|
146
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
147
|
+
}, z.core.$strip>;
|
|
148
|
+
type WaitInput = z.output<typeof waitInputSchema>;
|
|
149
|
+
/**
|
|
150
|
+
* browser_tabs - Manage browser tabs
|
|
151
|
+
*/
|
|
152
|
+
declare const tabsInputSchema: z.ZodObject<{
|
|
153
|
+
action: z.ZodEnum<{
|
|
154
|
+
list: "list";
|
|
155
|
+
new: "new";
|
|
156
|
+
switch: "switch";
|
|
157
|
+
close: "close";
|
|
158
|
+
}>;
|
|
159
|
+
index: z.ZodOptional<z.ZodNumber>;
|
|
160
|
+
url: z.ZodOptional<z.ZodString>;
|
|
161
|
+
}, z.core.$strip>;
|
|
162
|
+
type TabsInput = z.output<typeof tabsInputSchema>;
|
|
163
|
+
/**
|
|
164
|
+
* browser_drag - Drag an element to another element
|
|
165
|
+
*/
|
|
166
|
+
declare const dragInputSchema: z.ZodObject<{
|
|
167
|
+
sourceRef: z.ZodOptional<z.ZodString>;
|
|
168
|
+
targetRef: z.ZodOptional<z.ZodString>;
|
|
169
|
+
sourceSelector: z.ZodOptional<z.ZodString>;
|
|
170
|
+
targetSelector: z.ZodOptional<z.ZodString>;
|
|
171
|
+
}, z.core.$strip>;
|
|
172
|
+
type DragInput = z.output<typeof dragInputSchema>;
|
|
173
|
+
/**
|
|
174
|
+
* browser_evaluate - Execute JavaScript in the browser
|
|
175
|
+
*/
|
|
176
|
+
declare const evaluateInputSchema: z.ZodObject<{
|
|
177
|
+
script: z.ZodString;
|
|
178
|
+
arg: z.ZodOptional<z.ZodUnknown>;
|
|
179
|
+
}, z.core.$strip>;
|
|
180
|
+
type EvaluateInput = z.output<typeof evaluateInputSchema>;
|
|
181
|
+
declare const browserSchemas: {
|
|
182
|
+
readonly goto: z.ZodObject<{
|
|
183
|
+
url: z.ZodString;
|
|
184
|
+
waitUntil: z.ZodOptional<z.ZodEnum<{
|
|
185
|
+
load: "load";
|
|
186
|
+
domcontentloaded: "domcontentloaded";
|
|
187
|
+
networkidle: "networkidle";
|
|
188
|
+
}>>;
|
|
189
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
190
|
+
}, z.core.$strip>;
|
|
191
|
+
readonly snapshot: z.ZodObject<{
|
|
192
|
+
interactiveOnly: z.ZodOptional<z.ZodBoolean>;
|
|
193
|
+
maxDepth: z.ZodOptional<z.ZodNumber>;
|
|
194
|
+
}, z.core.$strip>;
|
|
195
|
+
readonly click: z.ZodObject<{
|
|
196
|
+
ref: z.ZodString;
|
|
197
|
+
button: z.ZodOptional<z.ZodEnum<{
|
|
198
|
+
left: "left";
|
|
199
|
+
right: "right";
|
|
200
|
+
middle: "middle";
|
|
201
|
+
}>>;
|
|
202
|
+
clickCount: z.ZodOptional<z.ZodNumber>;
|
|
203
|
+
modifiers: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
204
|
+
Alt: "Alt";
|
|
205
|
+
Control: "Control";
|
|
206
|
+
Meta: "Meta";
|
|
207
|
+
Shift: "Shift";
|
|
208
|
+
}>>>;
|
|
209
|
+
}, z.core.$strip>;
|
|
210
|
+
readonly type: z.ZodObject<{
|
|
211
|
+
ref: z.ZodString;
|
|
212
|
+
text: z.ZodString;
|
|
213
|
+
clear: z.ZodOptional<z.ZodBoolean>;
|
|
214
|
+
delay: z.ZodOptional<z.ZodNumber>;
|
|
215
|
+
}, z.core.$strip>;
|
|
216
|
+
readonly press: z.ZodObject<{
|
|
217
|
+
key: z.ZodString;
|
|
218
|
+
modifiers: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
219
|
+
Alt: "Alt";
|
|
220
|
+
Control: "Control";
|
|
221
|
+
Meta: "Meta";
|
|
222
|
+
Shift: "Shift";
|
|
223
|
+
}>>>;
|
|
224
|
+
}, z.core.$strip>;
|
|
225
|
+
readonly select: z.ZodObject<{
|
|
226
|
+
ref: z.ZodString;
|
|
227
|
+
value: z.ZodOptional<z.ZodString>;
|
|
228
|
+
label: z.ZodOptional<z.ZodString>;
|
|
229
|
+
index: z.ZodOptional<z.ZodNumber>;
|
|
230
|
+
}, z.core.$strip>;
|
|
231
|
+
readonly scroll: z.ZodObject<{
|
|
232
|
+
direction: z.ZodEnum<{
|
|
233
|
+
left: "left";
|
|
234
|
+
right: "right";
|
|
235
|
+
up: "up";
|
|
236
|
+
down: "down";
|
|
237
|
+
}>;
|
|
238
|
+
amount: z.ZodOptional<z.ZodNumber>;
|
|
239
|
+
ref: z.ZodOptional<z.ZodString>;
|
|
240
|
+
}, z.core.$strip>;
|
|
241
|
+
readonly close: z.ZodObject<{}, z.core.$strip>;
|
|
242
|
+
readonly hover: z.ZodObject<{
|
|
243
|
+
ref: z.ZodString;
|
|
244
|
+
}, z.core.$strip>;
|
|
245
|
+
readonly back: z.ZodObject<{}, z.core.$strip>;
|
|
246
|
+
readonly dialog: z.ZodObject<{
|
|
247
|
+
triggerRef: z.ZodString;
|
|
248
|
+
action: z.ZodEnum<{
|
|
249
|
+
accept: "accept";
|
|
250
|
+
dismiss: "dismiss";
|
|
251
|
+
}>;
|
|
252
|
+
text: z.ZodOptional<z.ZodString>;
|
|
253
|
+
}, z.core.$strip>;
|
|
254
|
+
readonly wait: z.ZodObject<{
|
|
255
|
+
ref: z.ZodOptional<z.ZodString>;
|
|
256
|
+
state: z.ZodOptional<z.ZodEnum<{
|
|
257
|
+
visible: "visible";
|
|
258
|
+
hidden: "hidden";
|
|
259
|
+
attached: "attached";
|
|
260
|
+
detached: "detached";
|
|
261
|
+
}>>;
|
|
262
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
263
|
+
}, z.core.$strip>;
|
|
264
|
+
readonly tabs: z.ZodObject<{
|
|
265
|
+
action: z.ZodEnum<{
|
|
266
|
+
list: "list";
|
|
267
|
+
new: "new";
|
|
268
|
+
switch: "switch";
|
|
269
|
+
close: "close";
|
|
270
|
+
}>;
|
|
271
|
+
index: z.ZodOptional<z.ZodNumber>;
|
|
272
|
+
url: z.ZodOptional<z.ZodString>;
|
|
273
|
+
}, z.core.$strip>;
|
|
274
|
+
readonly drag: z.ZodObject<{
|
|
275
|
+
sourceRef: z.ZodOptional<z.ZodString>;
|
|
276
|
+
targetRef: z.ZodOptional<z.ZodString>;
|
|
277
|
+
sourceSelector: z.ZodOptional<z.ZodString>;
|
|
278
|
+
targetSelector: z.ZodOptional<z.ZodString>;
|
|
279
|
+
}, z.core.$strip>;
|
|
280
|
+
readonly evaluate: z.ZodObject<{
|
|
281
|
+
script: z.ZodString;
|
|
282
|
+
arg: z.ZodOptional<z.ZodUnknown>;
|
|
283
|
+
}, z.core.$strip>;
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Configuration options for AgentBrowser.
|
|
288
|
+
* Type alias for BaseBrowserConfig.
|
|
289
|
+
*/
|
|
290
|
+
type BrowserConfig = BrowserConfig$1;
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* AgentBrowserThreadManager - Thread scope management for AgentBrowser
|
|
294
|
+
*
|
|
295
|
+
* Manages thread-scoped browser sessions using agent-browser's
|
|
296
|
+
* BrowserManager capabilities (newWindow, switchTo, closeTab).
|
|
297
|
+
*/
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Extended session info for AgentBrowser.
|
|
301
|
+
*/
|
|
302
|
+
interface AgentBrowserSession extends ThreadSession {
|
|
303
|
+
/** For 'thread' scope: dedicated browser manager instance */
|
|
304
|
+
manager?: BrowserManager;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Configuration for AgentBrowserThreadManager.
|
|
308
|
+
*/
|
|
309
|
+
interface AgentBrowserThreadManagerConfig extends ThreadManagerConfig {
|
|
310
|
+
/** Browser configuration for launching new instances */
|
|
311
|
+
browserConfig: BrowserConfig;
|
|
312
|
+
/** Function to resolve CDP URL (may be async) */
|
|
313
|
+
resolveCdpUrl?: (cdpUrl: string | (() => string | Promise<string>)) => Promise<string>;
|
|
314
|
+
/** Callback when a new browser manager is created for a thread */
|
|
315
|
+
onBrowserCreated?: (manager: BrowserManager, threadId: string) => void;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Thread manager implementation for AgentBrowser.
|
|
319
|
+
*
|
|
320
|
+
* Supports two scope modes:
|
|
321
|
+
* - 'shared': All threads share the shared browser manager
|
|
322
|
+
* - 'thread': Each thread gets a dedicated browser manager instance
|
|
323
|
+
*/
|
|
324
|
+
declare class AgentBrowserThreadManager extends ThreadManager<BrowserManager> {
|
|
325
|
+
private readonly browserConfig;
|
|
326
|
+
private readonly resolveCdpUrl?;
|
|
327
|
+
private readonly onBrowserCreated?;
|
|
328
|
+
constructor(config: AgentBrowserThreadManagerConfig);
|
|
329
|
+
/**
|
|
330
|
+
* Get the page for a specific thread, creating session if needed.
|
|
331
|
+
*/
|
|
332
|
+
getPageForThread(threadId?: string): Promise<Page>;
|
|
333
|
+
/**
|
|
334
|
+
* Create a new session for a thread.
|
|
335
|
+
*/
|
|
336
|
+
protected createSession(threadId: string): Promise<AgentBrowserSession>;
|
|
337
|
+
/**
|
|
338
|
+
* Restore browser state (multiple tabs) to a browser manager.
|
|
339
|
+
*/
|
|
340
|
+
private restoreBrowserState;
|
|
341
|
+
/**
|
|
342
|
+
* Get the browser manager for a specific session.
|
|
343
|
+
*/
|
|
344
|
+
protected getManagerForSession(session: AgentBrowserSession): BrowserManager;
|
|
345
|
+
/**
|
|
346
|
+
* Destroy a session and clean up resources.
|
|
347
|
+
*/
|
|
348
|
+
protected doDestroySession(session: AgentBrowserSession): Promise<void>;
|
|
349
|
+
/**
|
|
350
|
+
* Destroy all sessions (called during browser close).
|
|
351
|
+
* doDestroySession handles closing individual browser managers.
|
|
352
|
+
*/
|
|
353
|
+
destroyAllSessions(): Promise<void>;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* AgentBrowser - Browser automation using agent-browser (vercel-labs/agent-browser)
|
|
358
|
+
*
|
|
359
|
+
* Uses snapshot + refs pattern for LLM-friendly element targeting.
|
|
360
|
+
*/
|
|
361
|
+
declare class AgentBrowser extends MastraBrowser {
|
|
362
|
+
readonly id: string;
|
|
363
|
+
readonly name = "AgentBrowser";
|
|
364
|
+
readonly provider = "vercel-labs/agent-browser";
|
|
365
|
+
/** Shared browser manager instance (for 'shared' scope) - narrowed type from base class */
|
|
366
|
+
protected sharedManager: BrowserManager | null;
|
|
367
|
+
private defaultTimeout;
|
|
368
|
+
/** Thread manager - narrowed type from base class */
|
|
369
|
+
protected threadManager: AgentBrowserThreadManager;
|
|
370
|
+
constructor(config?: BrowserConfig);
|
|
371
|
+
/**
|
|
372
|
+
* Ensure browser is ready and thread session exists.
|
|
373
|
+
* Creates a new page/context for the current thread if needed.
|
|
374
|
+
*
|
|
375
|
+
* For 'thread' scope, we need to create the thread session BEFORE
|
|
376
|
+
* calling super.ensureReady() because the base class's ensureReady() will
|
|
377
|
+
* call checkBrowserAlive(), which needs at least one thread browser to exist.
|
|
378
|
+
*/
|
|
379
|
+
ensureReady(): Promise<void>;
|
|
380
|
+
/**
|
|
381
|
+
* Get the browser manager for the current thread.
|
|
382
|
+
* Delegates to ThreadManager for scope handling.
|
|
383
|
+
*/
|
|
384
|
+
getManagerForThread(threadId?: string): Promise<BrowserManager>;
|
|
385
|
+
protected doLaunch(): Promise<void>;
|
|
386
|
+
/**
|
|
387
|
+
* Set up close event listeners for 'shared' scope browser.
|
|
388
|
+
* This handles the case where the shared browser is closed externally.
|
|
389
|
+
*/
|
|
390
|
+
private setupCloseListenerForSharedScope;
|
|
391
|
+
protected doClose(): Promise<void>;
|
|
392
|
+
/**
|
|
393
|
+
* Check if the browser is still alive by verifying the page is connected.
|
|
394
|
+
* Called by base class ensureReady() to detect externally closed browsers.
|
|
395
|
+
*/
|
|
396
|
+
protected checkBrowserAlive(): Promise<boolean>;
|
|
397
|
+
/**
|
|
398
|
+
* Get the browser tools for this provider.
|
|
399
|
+
* Returns 17 flat tools for browser automation.
|
|
400
|
+
*/
|
|
401
|
+
getTools(): Record<string, Tool<any, any>>;
|
|
402
|
+
/**
|
|
403
|
+
* Get the page for the current thread.
|
|
404
|
+
* Uses thread scope if enabled, otherwise returns the shared page.
|
|
405
|
+
* @param explicitThreadId - Optional thread ID to use instead of getCurrentThread()
|
|
406
|
+
* Use this to avoid race conditions in concurrent tool calls.
|
|
407
|
+
*/
|
|
408
|
+
private getPage;
|
|
409
|
+
/**
|
|
410
|
+
* Get the active page for a thread (implements abstract method from base class).
|
|
411
|
+
* Returns null if no page is available, unlike getPage which throws.
|
|
412
|
+
*/
|
|
413
|
+
protected getActivePage(threadId?: string): Promise<Page | null>;
|
|
414
|
+
/**
|
|
415
|
+
* Set up close event listener for a thread's browser manager.
|
|
416
|
+
* This handles the case where a thread's browser is closed externally.
|
|
417
|
+
*/
|
|
418
|
+
private setupCloseListenerForThread;
|
|
419
|
+
/**
|
|
420
|
+
* Create an error response from an exception.
|
|
421
|
+
* Extends base class to add agent-browser specific error handling.
|
|
422
|
+
*/
|
|
423
|
+
protected createErrorFromException(error: unknown, context: string): BrowserToolError;
|
|
424
|
+
private requireLocator;
|
|
425
|
+
private getScrollInfo;
|
|
426
|
+
/**
|
|
427
|
+
* Get the current page URL without launching the browser.
|
|
428
|
+
* @param threadId - Optional thread ID for thread-isolated browsers
|
|
429
|
+
* @returns The current URL string, or null if browser is not running
|
|
430
|
+
*/
|
|
431
|
+
getCurrentUrl(threadId?: string): Promise<string | null>;
|
|
432
|
+
/**
|
|
433
|
+
* Navigate to a URL (simple form). Used internally for restoring state on relaunch.
|
|
434
|
+
*/
|
|
435
|
+
navigateTo(url: string): Promise<void>;
|
|
436
|
+
/**
|
|
437
|
+
* Get the current browser state (all tabs and active tab index).
|
|
438
|
+
*/
|
|
439
|
+
getBrowserState(threadId?: string): Promise<BrowserState | null>;
|
|
440
|
+
/**
|
|
441
|
+
* Get browser state for a thread (implements abstract method from base class).
|
|
442
|
+
* Sync version that uses existing manager lookup without creating sessions.
|
|
443
|
+
*/
|
|
444
|
+
protected getBrowserStateForThread(threadId?: string): BrowserState | null;
|
|
445
|
+
/**
|
|
446
|
+
* Get browser state from a specific manager instance.
|
|
447
|
+
*/
|
|
448
|
+
private getBrowserStateForManager;
|
|
449
|
+
/**
|
|
450
|
+
* Get all open tabs with their URLs and titles.
|
|
451
|
+
*/
|
|
452
|
+
getTabState(threadId?: string): Promise<BrowserTabState[]>;
|
|
453
|
+
/**
|
|
454
|
+
* Get the active tab index.
|
|
455
|
+
*/
|
|
456
|
+
getActiveTabIndex(threadId?: string): Promise<number>;
|
|
457
|
+
goto(input: GotoInput, threadId?: string): Promise<{
|
|
458
|
+
success: true;
|
|
459
|
+
url: string;
|
|
460
|
+
title: string;
|
|
461
|
+
hint: string;
|
|
462
|
+
} | BrowserToolError>;
|
|
463
|
+
snapshot(input: SnapshotInput, threadId?: string): Promise<{
|
|
464
|
+
success: true;
|
|
465
|
+
snapshot: string;
|
|
466
|
+
url: string;
|
|
467
|
+
title: string;
|
|
468
|
+
elementCount: number;
|
|
469
|
+
scroll: string;
|
|
470
|
+
hint?: string;
|
|
471
|
+
} | BrowserToolError>;
|
|
472
|
+
click(input: ClickInput, threadId?: string): Promise<{
|
|
473
|
+
success: true;
|
|
474
|
+
url: string;
|
|
475
|
+
hint: string;
|
|
476
|
+
} | BrowserToolError>;
|
|
477
|
+
type(input: TypeInput, threadId?: string): Promise<{
|
|
478
|
+
success: true;
|
|
479
|
+
value: string;
|
|
480
|
+
url: string;
|
|
481
|
+
hint: string;
|
|
482
|
+
} | BrowserToolError>;
|
|
483
|
+
press(input: PressInput, threadId?: string): Promise<{
|
|
484
|
+
success: true;
|
|
485
|
+
url: string;
|
|
486
|
+
hint: string;
|
|
487
|
+
} | BrowserToolError>;
|
|
488
|
+
select(input: SelectInput, threadId?: string): Promise<{
|
|
489
|
+
success: true;
|
|
490
|
+
selected: string[];
|
|
491
|
+
url: string;
|
|
492
|
+
hint: string;
|
|
493
|
+
} | BrowserToolError>;
|
|
494
|
+
scroll(input: ScrollInput, threadId?: string): Promise<{
|
|
495
|
+
success: true;
|
|
496
|
+
position: {
|
|
497
|
+
x: number;
|
|
498
|
+
y: number;
|
|
499
|
+
};
|
|
500
|
+
scroll: string;
|
|
501
|
+
hint: string;
|
|
502
|
+
} | BrowserToolError>;
|
|
503
|
+
hover(input: HoverInput, threadId?: string): Promise<{
|
|
504
|
+
success: true;
|
|
505
|
+
url: string;
|
|
506
|
+
hint: string;
|
|
507
|
+
} | BrowserToolError>;
|
|
508
|
+
back(threadId?: string): Promise<{
|
|
509
|
+
success: true;
|
|
510
|
+
url: string;
|
|
511
|
+
title: string;
|
|
512
|
+
hint: string;
|
|
513
|
+
} | BrowserToolError>;
|
|
514
|
+
dialog(input: DialogInput, threadId?: string): Promise<{
|
|
515
|
+
success: true;
|
|
516
|
+
action: 'accept' | 'dismiss';
|
|
517
|
+
dialogType: string;
|
|
518
|
+
message: string;
|
|
519
|
+
hint: string;
|
|
520
|
+
} | BrowserToolError>;
|
|
521
|
+
wait(input: WaitInput, threadId?: string): Promise<{
|
|
522
|
+
success: true;
|
|
523
|
+
hint: string;
|
|
524
|
+
} | BrowserToolError>;
|
|
525
|
+
tabs(input: TabsInput, threadId?: string): Promise<{
|
|
526
|
+
success: true;
|
|
527
|
+
tabs?: unknown[];
|
|
528
|
+
index?: number;
|
|
529
|
+
url?: string;
|
|
530
|
+
title?: string;
|
|
531
|
+
remaining?: number;
|
|
532
|
+
hint: string;
|
|
533
|
+
} | BrowserToolError>;
|
|
534
|
+
drag(input: DragInput, threadId?: string): Promise<{
|
|
535
|
+
success: true;
|
|
536
|
+
url: string;
|
|
537
|
+
hint: string;
|
|
538
|
+
} | BrowserToolError>;
|
|
539
|
+
evaluate(input: EvaluateInput, threadId?: string): Promise<{
|
|
540
|
+
success: true;
|
|
541
|
+
result: unknown;
|
|
542
|
+
hint: string;
|
|
543
|
+
} | BrowserToolError>;
|
|
544
|
+
closeBrowser(): Promise<{
|
|
545
|
+
success: true;
|
|
546
|
+
hint: string;
|
|
547
|
+
} | BrowserToolError>;
|
|
548
|
+
startScreencast(_options?: ScreencastOptions): Promise<ScreencastStream>;
|
|
549
|
+
injectMouseEvent(event: MouseEventParams, threadId?: string): Promise<void>;
|
|
550
|
+
injectKeyboardEvent(event: KeyboardEventParams, threadId?: string): Promise<void>;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
/**
|
|
554
|
+
* Browser Tool Constants
|
|
555
|
+
*/
|
|
556
|
+
declare const BROWSER_TOOLS: {
|
|
557
|
+
readonly GOTO: "browser_goto";
|
|
558
|
+
readonly SNAPSHOT: "browser_snapshot";
|
|
559
|
+
readonly CLICK: "browser_click";
|
|
560
|
+
readonly TYPE: "browser_type";
|
|
561
|
+
readonly PRESS: "browser_press";
|
|
562
|
+
readonly SELECT: "browser_select";
|
|
563
|
+
readonly SCROLL: "browser_scroll";
|
|
564
|
+
readonly CLOSE: "browser_close";
|
|
565
|
+
readonly HOVER: "browser_hover";
|
|
566
|
+
readonly BACK: "browser_back";
|
|
567
|
+
readonly DIALOG: "browser_dialog";
|
|
568
|
+
readonly WAIT: "browser_wait";
|
|
569
|
+
readonly TABS: "browser_tabs";
|
|
570
|
+
readonly DRAG: "browser_drag";
|
|
571
|
+
readonly EVALUATE: "browser_evaluate";
|
|
572
|
+
};
|
|
573
|
+
type BrowserToolName = (typeof BROWSER_TOOLS)[keyof typeof BROWSER_TOOLS];
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* AgentBrowser Tools
|
|
577
|
+
*
|
|
578
|
+
* Creates browser tools bound to an AgentBrowser instance.
|
|
579
|
+
* Each tool is defined in its own file for maintainability.
|
|
580
|
+
*/
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* Creates all browser tools bound to an AgentBrowser instance.
|
|
584
|
+
* The browser is lazily initialized on first tool use.
|
|
585
|
+
*/
|
|
586
|
+
declare function createAgentBrowserTools(browser: AgentBrowser): Record<string, Tool<any, any>>;
|
|
587
|
+
|
|
588
|
+
export { AgentBrowser, BROWSER_TOOLS, type BackInput, type BrowserConfig, type BrowserToolName, type ClickInput, type CloseInput, type DialogInput, type DragInput, type EvaluateInput, type GotoInput, type HoverInput, type PressInput, type ScrollInput, type SelectInput, type SnapshotInput, type TabsInput, type TypeInput, type WaitInput, backInputSchema, browserSchemas, clickInputSchema, closeInputSchema, createAgentBrowserTools, dialogInputSchema, dragInputSchema, evaluateInputSchema, gotoInputSchema, hoverInputSchema, pressInputSchema, scrollInputSchema, selectInputSchema, snapshotInputSchema, tabsInputSchema, typeInputSchema, waitInputSchema };
|