@mastra/agent-browser 0.0.0 → 0.1.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 +67 -0
- package/LICENSE.md +30 -0
- package/dist/index.cjs +58 -217
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +18 -84
- package/dist/index.d.ts +18 -84
- package/dist/index.js +58 -217
- package/dist/index.js.map +1 -1
- package/package.json +16 -16
package/dist/index.d.cts
CHANGED
|
@@ -290,7 +290,7 @@ declare const browserSchemas: {
|
|
|
290
290
|
type BrowserConfig = BrowserConfig$1;
|
|
291
291
|
|
|
292
292
|
/**
|
|
293
|
-
* AgentBrowserThreadManager - Thread
|
|
293
|
+
* AgentBrowserThreadManager - Thread scope management for AgentBrowser
|
|
294
294
|
*
|
|
295
295
|
* Manages thread-scoped browser sessions using agent-browser's
|
|
296
296
|
* BrowserManager capabilities (newWindow, switchTo, closeTab).
|
|
@@ -322,25 +322,14 @@ interface AgentBrowserThreadManagerConfig extends ThreadManagerConfig {
|
|
|
322
322
|
* - 'thread': Each thread gets a dedicated browser manager instance
|
|
323
323
|
*/
|
|
324
324
|
declare class AgentBrowserThreadManager extends ThreadManager<BrowserManager> {
|
|
325
|
-
private sharedManager;
|
|
326
325
|
private readonly browserConfig;
|
|
327
326
|
private readonly resolveCdpUrl?;
|
|
328
327
|
private readonly onBrowserCreated?;
|
|
329
|
-
/** Map of thread ID to dedicated browser manager (for 'thread' scope) */
|
|
330
|
-
private readonly threadBrowsers;
|
|
331
328
|
constructor(config: AgentBrowserThreadManagerConfig);
|
|
332
329
|
/**
|
|
333
|
-
*
|
|
330
|
+
* Get the page for a specific thread, creating session if needed.
|
|
334
331
|
*/
|
|
335
|
-
|
|
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;
|
|
332
|
+
getPageForThread(threadId?: string): Promise<Page>;
|
|
344
333
|
/**
|
|
345
334
|
* Create a new session for a thread.
|
|
346
335
|
*/
|
|
@@ -349,12 +338,6 @@ declare class AgentBrowserThreadManager extends ThreadManager<BrowserManager> {
|
|
|
349
338
|
* Restore browser state (multiple tabs) to a browser manager.
|
|
350
339
|
*/
|
|
351
340
|
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
341
|
/**
|
|
359
342
|
* Get the browser manager for a specific session.
|
|
360
343
|
*/
|
|
@@ -365,29 +348,9 @@ declare class AgentBrowserThreadManager extends ThreadManager<BrowserManager> {
|
|
|
365
348
|
protected doDestroySession(session: AgentBrowserSession): Promise<void>;
|
|
366
349
|
/**
|
|
367
350
|
* Destroy all sessions (called during browser close).
|
|
351
|
+
* doDestroySession handles closing individual browser managers.
|
|
368
352
|
*/
|
|
369
353
|
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
354
|
}
|
|
392
355
|
|
|
393
356
|
/**
|
|
@@ -399,13 +362,9 @@ declare class AgentBrowser extends MastraBrowser {
|
|
|
399
362
|
readonly id: string;
|
|
400
363
|
readonly name = "AgentBrowser";
|
|
401
364
|
readonly provider = "vercel-labs/agent-browser";
|
|
402
|
-
/**
|
|
403
|
-
|
|
365
|
+
/** Shared browser manager instance (for 'shared' scope) - narrowed type from base class */
|
|
366
|
+
protected sharedManager: BrowserManager | null;
|
|
404
367
|
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
368
|
/** Thread manager - narrowed type from base class */
|
|
410
369
|
protected threadManager: AgentBrowserThreadManager;
|
|
411
370
|
constructor(config?: BrowserConfig);
|
|
@@ -413,32 +372,22 @@ declare class AgentBrowser extends MastraBrowser {
|
|
|
413
372
|
* Ensure browser is ready and thread session exists.
|
|
414
373
|
* Creates a new page/context for the current thread if needed.
|
|
415
374
|
*
|
|
416
|
-
* For '
|
|
375
|
+
* For 'thread' scope, we need to create the thread session BEFORE
|
|
417
376
|
* calling super.ensureReady() because the base class's ensureReady() will
|
|
418
377
|
* call checkBrowserAlive(), which needs at least one thread browser to exist.
|
|
419
378
|
*/
|
|
420
379
|
ensureReady(): Promise<void>;
|
|
421
380
|
/**
|
|
422
381
|
* Get the browser manager for the current thread.
|
|
423
|
-
* Delegates to ThreadManager for
|
|
382
|
+
* Delegates to ThreadManager for scope handling.
|
|
424
383
|
*/
|
|
425
384
|
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
385
|
protected doLaunch(): Promise<void>;
|
|
437
386
|
/**
|
|
438
|
-
* Set up close event listeners for '
|
|
387
|
+
* Set up close event listeners for 'shared' scope browser.
|
|
439
388
|
* This handles the case where the shared browser is closed externally.
|
|
440
389
|
*/
|
|
441
|
-
private
|
|
390
|
+
private setupCloseListenerForSharedScope;
|
|
442
391
|
protected doClose(): Promise<void>;
|
|
443
392
|
/**
|
|
444
393
|
* Check if the browser is still alive by verifying the page is connected.
|
|
@@ -458,21 +407,15 @@ declare class AgentBrowser extends MastraBrowser {
|
|
|
458
407
|
*/
|
|
459
408
|
private getPage;
|
|
460
409
|
/**
|
|
461
|
-
*
|
|
462
|
-
*
|
|
463
|
-
* For 'shared' scope, notifies all callbacks.
|
|
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.
|
|
464
412
|
*/
|
|
465
|
-
|
|
413
|
+
protected getActivePage(threadId?: string): Promise<Page | null>;
|
|
466
414
|
/**
|
|
467
415
|
* Set up close event listener for a thread's browser manager.
|
|
468
416
|
* This handles the case where a thread's browser is closed externally.
|
|
469
417
|
*/
|
|
470
418
|
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
419
|
/**
|
|
477
420
|
* Create an error response from an exception.
|
|
478
421
|
* Extends base class to add agent-browser specific error handling.
|
|
@@ -494,6 +437,11 @@ declare class AgentBrowser extends MastraBrowser {
|
|
|
494
437
|
* Get the current browser state (all tabs and active tab index).
|
|
495
438
|
*/
|
|
496
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;
|
|
497
445
|
/**
|
|
498
446
|
* Get browser state from a specific manager instance.
|
|
499
447
|
*/
|
|
@@ -506,11 +454,6 @@ declare class AgentBrowser extends MastraBrowser {
|
|
|
506
454
|
* Get the active tab index.
|
|
507
455
|
*/
|
|
508
456
|
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
457
|
goto(input: GotoInput, threadId?: string): Promise<{
|
|
515
458
|
success: true;
|
|
516
459
|
url: string;
|
|
@@ -602,15 +545,6 @@ declare class AgentBrowser extends MastraBrowser {
|
|
|
602
545
|
success: true;
|
|
603
546
|
hint: string;
|
|
604
547
|
} | 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
548
|
startScreencast(_options?: ScreencastOptions): Promise<ScreencastStream>;
|
|
615
549
|
injectMouseEvent(event: MouseEventParams, threadId?: string): Promise<void>;
|
|
616
550
|
injectKeyboardEvent(event: KeyboardEventParams, threadId?: string): Promise<void>;
|
package/dist/index.d.ts
CHANGED
|
@@ -290,7 +290,7 @@ declare const browserSchemas: {
|
|
|
290
290
|
type BrowserConfig = BrowserConfig$1;
|
|
291
291
|
|
|
292
292
|
/**
|
|
293
|
-
* AgentBrowserThreadManager - Thread
|
|
293
|
+
* AgentBrowserThreadManager - Thread scope management for AgentBrowser
|
|
294
294
|
*
|
|
295
295
|
* Manages thread-scoped browser sessions using agent-browser's
|
|
296
296
|
* BrowserManager capabilities (newWindow, switchTo, closeTab).
|
|
@@ -322,25 +322,14 @@ interface AgentBrowserThreadManagerConfig extends ThreadManagerConfig {
|
|
|
322
322
|
* - 'thread': Each thread gets a dedicated browser manager instance
|
|
323
323
|
*/
|
|
324
324
|
declare class AgentBrowserThreadManager extends ThreadManager<BrowserManager> {
|
|
325
|
-
private sharedManager;
|
|
326
325
|
private readonly browserConfig;
|
|
327
326
|
private readonly resolveCdpUrl?;
|
|
328
327
|
private readonly onBrowserCreated?;
|
|
329
|
-
/** Map of thread ID to dedicated browser manager (for 'thread' scope) */
|
|
330
|
-
private readonly threadBrowsers;
|
|
331
328
|
constructor(config: AgentBrowserThreadManagerConfig);
|
|
332
329
|
/**
|
|
333
|
-
*
|
|
330
|
+
* Get the page for a specific thread, creating session if needed.
|
|
334
331
|
*/
|
|
335
|
-
|
|
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;
|
|
332
|
+
getPageForThread(threadId?: string): Promise<Page>;
|
|
344
333
|
/**
|
|
345
334
|
* Create a new session for a thread.
|
|
346
335
|
*/
|
|
@@ -349,12 +338,6 @@ declare class AgentBrowserThreadManager extends ThreadManager<BrowserManager> {
|
|
|
349
338
|
* Restore browser state (multiple tabs) to a browser manager.
|
|
350
339
|
*/
|
|
351
340
|
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
341
|
/**
|
|
359
342
|
* Get the browser manager for a specific session.
|
|
360
343
|
*/
|
|
@@ -365,29 +348,9 @@ declare class AgentBrowserThreadManager extends ThreadManager<BrowserManager> {
|
|
|
365
348
|
protected doDestroySession(session: AgentBrowserSession): Promise<void>;
|
|
366
349
|
/**
|
|
367
350
|
* Destroy all sessions (called during browser close).
|
|
351
|
+
* doDestroySession handles closing individual browser managers.
|
|
368
352
|
*/
|
|
369
353
|
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
354
|
}
|
|
392
355
|
|
|
393
356
|
/**
|
|
@@ -399,13 +362,9 @@ declare class AgentBrowser extends MastraBrowser {
|
|
|
399
362
|
readonly id: string;
|
|
400
363
|
readonly name = "AgentBrowser";
|
|
401
364
|
readonly provider = "vercel-labs/agent-browser";
|
|
402
|
-
/**
|
|
403
|
-
|
|
365
|
+
/** Shared browser manager instance (for 'shared' scope) - narrowed type from base class */
|
|
366
|
+
protected sharedManager: BrowserManager | null;
|
|
404
367
|
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
368
|
/** Thread manager - narrowed type from base class */
|
|
410
369
|
protected threadManager: AgentBrowserThreadManager;
|
|
411
370
|
constructor(config?: BrowserConfig);
|
|
@@ -413,32 +372,22 @@ declare class AgentBrowser extends MastraBrowser {
|
|
|
413
372
|
* Ensure browser is ready and thread session exists.
|
|
414
373
|
* Creates a new page/context for the current thread if needed.
|
|
415
374
|
*
|
|
416
|
-
* For '
|
|
375
|
+
* For 'thread' scope, we need to create the thread session BEFORE
|
|
417
376
|
* calling super.ensureReady() because the base class's ensureReady() will
|
|
418
377
|
* call checkBrowserAlive(), which needs at least one thread browser to exist.
|
|
419
378
|
*/
|
|
420
379
|
ensureReady(): Promise<void>;
|
|
421
380
|
/**
|
|
422
381
|
* Get the browser manager for the current thread.
|
|
423
|
-
* Delegates to ThreadManager for
|
|
382
|
+
* Delegates to ThreadManager for scope handling.
|
|
424
383
|
*/
|
|
425
384
|
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
385
|
protected doLaunch(): Promise<void>;
|
|
437
386
|
/**
|
|
438
|
-
* Set up close event listeners for '
|
|
387
|
+
* Set up close event listeners for 'shared' scope browser.
|
|
439
388
|
* This handles the case where the shared browser is closed externally.
|
|
440
389
|
*/
|
|
441
|
-
private
|
|
390
|
+
private setupCloseListenerForSharedScope;
|
|
442
391
|
protected doClose(): Promise<void>;
|
|
443
392
|
/**
|
|
444
393
|
* Check if the browser is still alive by verifying the page is connected.
|
|
@@ -458,21 +407,15 @@ declare class AgentBrowser extends MastraBrowser {
|
|
|
458
407
|
*/
|
|
459
408
|
private getPage;
|
|
460
409
|
/**
|
|
461
|
-
*
|
|
462
|
-
*
|
|
463
|
-
* For 'shared' scope, notifies all callbacks.
|
|
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.
|
|
464
412
|
*/
|
|
465
|
-
|
|
413
|
+
protected getActivePage(threadId?: string): Promise<Page | null>;
|
|
466
414
|
/**
|
|
467
415
|
* Set up close event listener for a thread's browser manager.
|
|
468
416
|
* This handles the case where a thread's browser is closed externally.
|
|
469
417
|
*/
|
|
470
418
|
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
419
|
/**
|
|
477
420
|
* Create an error response from an exception.
|
|
478
421
|
* Extends base class to add agent-browser specific error handling.
|
|
@@ -494,6 +437,11 @@ declare class AgentBrowser extends MastraBrowser {
|
|
|
494
437
|
* Get the current browser state (all tabs and active tab index).
|
|
495
438
|
*/
|
|
496
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;
|
|
497
445
|
/**
|
|
498
446
|
* Get browser state from a specific manager instance.
|
|
499
447
|
*/
|
|
@@ -506,11 +454,6 @@ declare class AgentBrowser extends MastraBrowser {
|
|
|
506
454
|
* Get the active tab index.
|
|
507
455
|
*/
|
|
508
456
|
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
457
|
goto(input: GotoInput, threadId?: string): Promise<{
|
|
515
458
|
success: true;
|
|
516
459
|
url: string;
|
|
@@ -602,15 +545,6 @@ declare class AgentBrowser extends MastraBrowser {
|
|
|
602
545
|
success: true;
|
|
603
546
|
hint: string;
|
|
604
547
|
} | 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
548
|
startScreencast(_options?: ScreencastOptions): Promise<ScreencastStream>;
|
|
615
549
|
injectMouseEvent(event: MouseEventParams, threadId?: string): Promise<void>;
|
|
616
550
|
injectKeyboardEvent(event: KeyboardEventParams, threadId?: string): Promise<void>;
|