@mastra/agent-browser 0.0.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/dist/index.cjs +1736 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +654 -0
- package/dist/index.d.ts +654 -0
- package/dist/index.js +1716 -0
- package/dist/index.js.map +1 -0
- package/package.json +66 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,654 @@
|
|
|
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 isolation 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 sharedManager;
|
|
326
|
+
private readonly browserConfig;
|
|
327
|
+
private readonly resolveCdpUrl?;
|
|
328
|
+
private readonly onBrowserCreated?;
|
|
329
|
+
/** Map of thread ID to dedicated browser manager (for 'thread' scope) */
|
|
330
|
+
private readonly threadBrowsers;
|
|
331
|
+
constructor(config: AgentBrowserThreadManagerConfig);
|
|
332
|
+
/**
|
|
333
|
+
* Set the shared browser manager (called after browser launch).
|
|
334
|
+
*/
|
|
335
|
+
setSharedManager(manager: BrowserManager): void;
|
|
336
|
+
/**
|
|
337
|
+
* Clear the shared browser manager (called when browser disconnects).
|
|
338
|
+
*/
|
|
339
|
+
clearSharedManager(): void;
|
|
340
|
+
/**
|
|
341
|
+
* Get the shared browser manager.
|
|
342
|
+
*/
|
|
343
|
+
protected getSharedManager(): BrowserManager;
|
|
344
|
+
/**
|
|
345
|
+
* Create a new session for a thread.
|
|
346
|
+
*/
|
|
347
|
+
protected createSession(threadId: string): Promise<AgentBrowserSession>;
|
|
348
|
+
/**
|
|
349
|
+
* Restore browser state (multiple tabs) to a browser manager.
|
|
350
|
+
*/
|
|
351
|
+
private restoreBrowserState;
|
|
352
|
+
/**
|
|
353
|
+
* Switch to an existing session.
|
|
354
|
+
* For 'thread' scope, no switching needed - each thread has its own manager.
|
|
355
|
+
* For 'shared' scope, nothing to switch.
|
|
356
|
+
*/
|
|
357
|
+
protected switchToSession(_session: AgentBrowserSession): Promise<void>;
|
|
358
|
+
/**
|
|
359
|
+
* Get the browser manager for a specific session.
|
|
360
|
+
*/
|
|
361
|
+
protected getManagerForSession(session: AgentBrowserSession): BrowserManager;
|
|
362
|
+
/**
|
|
363
|
+
* Destroy a session and clean up resources.
|
|
364
|
+
*/
|
|
365
|
+
protected doDestroySession(session: AgentBrowserSession): Promise<void>;
|
|
366
|
+
/**
|
|
367
|
+
* Destroy all sessions (called during browser close).
|
|
368
|
+
*/
|
|
369
|
+
destroyAllSessions(): Promise<void>;
|
|
370
|
+
/**
|
|
371
|
+
* Check if any thread browsers are still running.
|
|
372
|
+
*/
|
|
373
|
+
hasActiveThreadBrowsers(): boolean;
|
|
374
|
+
/**
|
|
375
|
+
* Get the browser manager for an existing thread session without creating a new one.
|
|
376
|
+
* Returns null if no session exists for the thread.
|
|
377
|
+
*/
|
|
378
|
+
getExistingManagerForThread(threadId: string): BrowserManager | null;
|
|
379
|
+
/**
|
|
380
|
+
* Clear all session tracking without closing browsers.
|
|
381
|
+
* Used when browsers have been externally closed and we just need to reset state.
|
|
382
|
+
*/
|
|
383
|
+
clearAllSessions(): void;
|
|
384
|
+
/**
|
|
385
|
+
* Clear a specific thread's session without closing the browser.
|
|
386
|
+
* Used when a thread's browser has been externally closed.
|
|
387
|
+
* Preserves the browser state for potential restoration.
|
|
388
|
+
* @param threadId - The thread ID to clear
|
|
389
|
+
*/
|
|
390
|
+
clearSession(threadId: string): void;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* AgentBrowser - Browser automation using agent-browser (vercel-labs/agent-browser)
|
|
395
|
+
*
|
|
396
|
+
* Uses snapshot + refs pattern for LLM-friendly element targeting.
|
|
397
|
+
*/
|
|
398
|
+
declare class AgentBrowser extends MastraBrowser {
|
|
399
|
+
readonly id: string;
|
|
400
|
+
readonly name = "AgentBrowser";
|
|
401
|
+
readonly provider = "vercel-labs/agent-browser";
|
|
402
|
+
/** Primary browser manager (for 'none' mode, also used as fallback) */
|
|
403
|
+
private browserManager;
|
|
404
|
+
private defaultTimeout;
|
|
405
|
+
/** Active screencast streams per thread (for triggering reconnects on tab changes) */
|
|
406
|
+
private activeScreencastStreams;
|
|
407
|
+
/** Default key for shared scope */
|
|
408
|
+
private static readonly SHARED_STREAM_KEY;
|
|
409
|
+
/** Thread manager - narrowed type from base class */
|
|
410
|
+
protected threadManager: AgentBrowserThreadManager;
|
|
411
|
+
constructor(config?: BrowserConfig);
|
|
412
|
+
/**
|
|
413
|
+
* Ensure browser is ready and thread session exists.
|
|
414
|
+
* Creates a new page/context for the current thread if needed.
|
|
415
|
+
*
|
|
416
|
+
* For 'browser' isolation, we need to create the thread session BEFORE
|
|
417
|
+
* calling super.ensureReady() because the base class's ensureReady() will
|
|
418
|
+
* call checkBrowserAlive(), which needs at least one thread browser to exist.
|
|
419
|
+
*/
|
|
420
|
+
ensureReady(): Promise<void>;
|
|
421
|
+
/**
|
|
422
|
+
* Get the browser manager for the current thread.
|
|
423
|
+
* Delegates to ThreadManager for isolation handling.
|
|
424
|
+
*/
|
|
425
|
+
getManagerForThread(threadId?: string): Promise<BrowserManager>;
|
|
426
|
+
/**
|
|
427
|
+
* Get the page for a specific thread.
|
|
428
|
+
* For thread-isolated modes, ensures we're on the correct context/page.
|
|
429
|
+
*/
|
|
430
|
+
getPageForThread(threadId?: string): Promise<Page>;
|
|
431
|
+
/**
|
|
432
|
+
* Close a specific thread's browser session.
|
|
433
|
+
* Delegates to ThreadManager and notifies registered callbacks.
|
|
434
|
+
*/
|
|
435
|
+
closeThreadSession(threadId: string): Promise<void>;
|
|
436
|
+
protected doLaunch(): Promise<void>;
|
|
437
|
+
/**
|
|
438
|
+
* Set up close event listeners for 'none' isolation shared browser.
|
|
439
|
+
* This handles the case where the shared browser is closed externally.
|
|
440
|
+
*/
|
|
441
|
+
private setupCloseListenerForNoneIsolation;
|
|
442
|
+
protected doClose(): Promise<void>;
|
|
443
|
+
/**
|
|
444
|
+
* Check if the browser is still alive by verifying the page is connected.
|
|
445
|
+
* Called by base class ensureReady() to detect externally closed browsers.
|
|
446
|
+
*/
|
|
447
|
+
protected checkBrowserAlive(): Promise<boolean>;
|
|
448
|
+
/**
|
|
449
|
+
* Get the browser tools for this provider.
|
|
450
|
+
* Returns 17 flat tools for browser automation.
|
|
451
|
+
*/
|
|
452
|
+
getTools(): Record<string, Tool<any, any>>;
|
|
453
|
+
/**
|
|
454
|
+
* Get the page for the current thread.
|
|
455
|
+
* Uses thread scope if enabled, otherwise returns the shared page.
|
|
456
|
+
* @param explicitThreadId - Optional thread ID to use instead of getCurrentThread()
|
|
457
|
+
* Use this to avoid race conditions in concurrent tool calls.
|
|
458
|
+
*/
|
|
459
|
+
private getPage;
|
|
460
|
+
/**
|
|
461
|
+
* Handle browser disconnection by clearing internal state.
|
|
462
|
+
* For 'thread' scope, only notifies the specific thread's callbacks.
|
|
463
|
+
* For 'shared' scope, notifies all callbacks.
|
|
464
|
+
*/
|
|
465
|
+
handleBrowserDisconnected(): void;
|
|
466
|
+
/**
|
|
467
|
+
* Set up close event listener for a thread's browser manager.
|
|
468
|
+
* This handles the case where a thread's browser is closed externally.
|
|
469
|
+
*/
|
|
470
|
+
private setupCloseListenerForThread;
|
|
471
|
+
/**
|
|
472
|
+
* Handle browser disconnection for a specific thread.
|
|
473
|
+
* Called when a thread's browser is closed externally.
|
|
474
|
+
*/
|
|
475
|
+
private handleThreadBrowserDisconnected;
|
|
476
|
+
/**
|
|
477
|
+
* Create an error response from an exception.
|
|
478
|
+
* Extends base class to add agent-browser specific error handling.
|
|
479
|
+
*/
|
|
480
|
+
protected createErrorFromException(error: unknown, context: string): BrowserToolError;
|
|
481
|
+
private requireLocator;
|
|
482
|
+
private getScrollInfo;
|
|
483
|
+
/**
|
|
484
|
+
* Get the current page URL without launching the browser.
|
|
485
|
+
* @param threadId - Optional thread ID for thread-isolated browsers
|
|
486
|
+
* @returns The current URL string, or null if browser is not running
|
|
487
|
+
*/
|
|
488
|
+
getCurrentUrl(threadId?: string): Promise<string | null>;
|
|
489
|
+
/**
|
|
490
|
+
* Navigate to a URL (simple form). Used internally for restoring state on relaunch.
|
|
491
|
+
*/
|
|
492
|
+
navigateTo(url: string): Promise<void>;
|
|
493
|
+
/**
|
|
494
|
+
* Get the current browser state (all tabs and active tab index).
|
|
495
|
+
*/
|
|
496
|
+
getBrowserState(threadId?: string): Promise<BrowserState | null>;
|
|
497
|
+
/**
|
|
498
|
+
* Get browser state from a specific manager instance.
|
|
499
|
+
*/
|
|
500
|
+
private getBrowserStateForManager;
|
|
501
|
+
/**
|
|
502
|
+
* Get all open tabs with their URLs and titles.
|
|
503
|
+
*/
|
|
504
|
+
getTabState(threadId?: string): Promise<BrowserTabState[]>;
|
|
505
|
+
/**
|
|
506
|
+
* Get the active tab index.
|
|
507
|
+
*/
|
|
508
|
+
getActiveTabIndex(threadId?: string): Promise<number>;
|
|
509
|
+
/**
|
|
510
|
+
* Update the browser state in the thread session.
|
|
511
|
+
* Called on navigation, tab open/close to keep state fresh.
|
|
512
|
+
*/
|
|
513
|
+
private updateSessionBrowserState;
|
|
514
|
+
goto(input: GotoInput, threadId?: string): Promise<{
|
|
515
|
+
success: true;
|
|
516
|
+
url: string;
|
|
517
|
+
title: string;
|
|
518
|
+
hint: string;
|
|
519
|
+
} | BrowserToolError>;
|
|
520
|
+
snapshot(input: SnapshotInput, threadId?: string): Promise<{
|
|
521
|
+
success: true;
|
|
522
|
+
snapshot: string;
|
|
523
|
+
url: string;
|
|
524
|
+
title: string;
|
|
525
|
+
elementCount: number;
|
|
526
|
+
scroll: string;
|
|
527
|
+
hint?: string;
|
|
528
|
+
} | BrowserToolError>;
|
|
529
|
+
click(input: ClickInput, threadId?: string): Promise<{
|
|
530
|
+
success: true;
|
|
531
|
+
url: string;
|
|
532
|
+
hint: string;
|
|
533
|
+
} | BrowserToolError>;
|
|
534
|
+
type(input: TypeInput, threadId?: string): Promise<{
|
|
535
|
+
success: true;
|
|
536
|
+
value: string;
|
|
537
|
+
url: string;
|
|
538
|
+
hint: string;
|
|
539
|
+
} | BrowserToolError>;
|
|
540
|
+
press(input: PressInput, threadId?: string): Promise<{
|
|
541
|
+
success: true;
|
|
542
|
+
url: string;
|
|
543
|
+
hint: string;
|
|
544
|
+
} | BrowserToolError>;
|
|
545
|
+
select(input: SelectInput, threadId?: string): Promise<{
|
|
546
|
+
success: true;
|
|
547
|
+
selected: string[];
|
|
548
|
+
url: string;
|
|
549
|
+
hint: string;
|
|
550
|
+
} | BrowserToolError>;
|
|
551
|
+
scroll(input: ScrollInput, threadId?: string): Promise<{
|
|
552
|
+
success: true;
|
|
553
|
+
position: {
|
|
554
|
+
x: number;
|
|
555
|
+
y: number;
|
|
556
|
+
};
|
|
557
|
+
scroll: string;
|
|
558
|
+
hint: string;
|
|
559
|
+
} | BrowserToolError>;
|
|
560
|
+
hover(input: HoverInput, threadId?: string): Promise<{
|
|
561
|
+
success: true;
|
|
562
|
+
url: string;
|
|
563
|
+
hint: string;
|
|
564
|
+
} | BrowserToolError>;
|
|
565
|
+
back(threadId?: string): Promise<{
|
|
566
|
+
success: true;
|
|
567
|
+
url: string;
|
|
568
|
+
title: string;
|
|
569
|
+
hint: string;
|
|
570
|
+
} | BrowserToolError>;
|
|
571
|
+
dialog(input: DialogInput, threadId?: string): Promise<{
|
|
572
|
+
success: true;
|
|
573
|
+
action: 'accept' | 'dismiss';
|
|
574
|
+
dialogType: string;
|
|
575
|
+
message: string;
|
|
576
|
+
hint: string;
|
|
577
|
+
} | BrowserToolError>;
|
|
578
|
+
wait(input: WaitInput, threadId?: string): Promise<{
|
|
579
|
+
success: true;
|
|
580
|
+
hint: string;
|
|
581
|
+
} | BrowserToolError>;
|
|
582
|
+
tabs(input: TabsInput, threadId?: string): Promise<{
|
|
583
|
+
success: true;
|
|
584
|
+
tabs?: unknown[];
|
|
585
|
+
index?: number;
|
|
586
|
+
url?: string;
|
|
587
|
+
title?: string;
|
|
588
|
+
remaining?: number;
|
|
589
|
+
hint: string;
|
|
590
|
+
} | BrowserToolError>;
|
|
591
|
+
drag(input: DragInput, threadId?: string): Promise<{
|
|
592
|
+
success: true;
|
|
593
|
+
url: string;
|
|
594
|
+
hint: string;
|
|
595
|
+
} | BrowserToolError>;
|
|
596
|
+
evaluate(input: EvaluateInput, threadId?: string): Promise<{
|
|
597
|
+
success: true;
|
|
598
|
+
result: unknown;
|
|
599
|
+
hint: string;
|
|
600
|
+
} | BrowserToolError>;
|
|
601
|
+
closeBrowser(): Promise<{
|
|
602
|
+
success: true;
|
|
603
|
+
hint: string;
|
|
604
|
+
} | BrowserToolError>;
|
|
605
|
+
/**
|
|
606
|
+
* Get the stream key for a thread (or shared key for shared scope).
|
|
607
|
+
*/
|
|
608
|
+
private getStreamKey;
|
|
609
|
+
/**
|
|
610
|
+
* Trigger a screencast reconnect after tab changes.
|
|
611
|
+
* Called internally when tabs are switched or closed.
|
|
612
|
+
*/
|
|
613
|
+
private reconnectScreencast;
|
|
614
|
+
startScreencast(_options?: ScreencastOptions): Promise<ScreencastStream>;
|
|
615
|
+
injectMouseEvent(event: MouseEventParams, threadId?: string): Promise<void>;
|
|
616
|
+
injectKeyboardEvent(event: KeyboardEventParams, threadId?: string): Promise<void>;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
/**
|
|
620
|
+
* Browser Tool Constants
|
|
621
|
+
*/
|
|
622
|
+
declare const BROWSER_TOOLS: {
|
|
623
|
+
readonly GOTO: "browser_goto";
|
|
624
|
+
readonly SNAPSHOT: "browser_snapshot";
|
|
625
|
+
readonly CLICK: "browser_click";
|
|
626
|
+
readonly TYPE: "browser_type";
|
|
627
|
+
readonly PRESS: "browser_press";
|
|
628
|
+
readonly SELECT: "browser_select";
|
|
629
|
+
readonly SCROLL: "browser_scroll";
|
|
630
|
+
readonly CLOSE: "browser_close";
|
|
631
|
+
readonly HOVER: "browser_hover";
|
|
632
|
+
readonly BACK: "browser_back";
|
|
633
|
+
readonly DIALOG: "browser_dialog";
|
|
634
|
+
readonly WAIT: "browser_wait";
|
|
635
|
+
readonly TABS: "browser_tabs";
|
|
636
|
+
readonly DRAG: "browser_drag";
|
|
637
|
+
readonly EVALUATE: "browser_evaluate";
|
|
638
|
+
};
|
|
639
|
+
type BrowserToolName = (typeof BROWSER_TOOLS)[keyof typeof BROWSER_TOOLS];
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* AgentBrowser Tools
|
|
643
|
+
*
|
|
644
|
+
* Creates browser tools bound to an AgentBrowser instance.
|
|
645
|
+
* Each tool is defined in its own file for maintainability.
|
|
646
|
+
*/
|
|
647
|
+
|
|
648
|
+
/**
|
|
649
|
+
* Creates all browser tools bound to an AgentBrowser instance.
|
|
650
|
+
* The browser is lazily initialized on first tool use.
|
|
651
|
+
*/
|
|
652
|
+
declare function createAgentBrowserTools(browser: AgentBrowser): Record<string, Tool<any, any>>;
|
|
653
|
+
|
|
654
|
+
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 };
|