@mastra/agent-browser 0.2.2 → 0.3.0-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/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { BrowserConfig as BrowserConfig$1, ThreadManager, ThreadManagerConfig, ThreadSession, MastraBrowser, BrowserToolError, BrowserState, BrowserTabState, ScreencastOptions, ScreencastStream, MouseEventParams, KeyboardEventParams } from '@mastra/core/browser';
1
+ import { BrowserConfig as BrowserConfig$1, ThreadManager, ThreadManagerConfig, ThreadSession, BrowserState, MastraBrowser, BrowserToolError, BrowserTabState, ScreencastOptions, ScreencastStream, MouseEventParams, KeyboardEventParams } from '@mastra/core/browser';
2
2
  import { Tool } from '@mastra/core/tools';
3
3
  import { BrowserManager } from 'agent-browser';
4
4
  import { Page } from 'playwright-core';
@@ -376,6 +376,11 @@ interface AgentBrowserThreadManagerConfig extends ThreadManagerConfig {
376
376
  /** Callback when a new browser manager is created for a thread */
377
377
  onBrowserCreated?: (manager: BrowserManager, threadId: string) => void;
378
378
  }
379
+ /**
380
+ * Factory for custom thread managers (e.g. Firecrawl-hosted CDP per session).
381
+ * Defaults to {@link AgentBrowserThreadManager} when omitted.
382
+ */
383
+ type CreateAgentBrowserThreadManager = (config: AgentBrowserThreadManagerConfig) => AgentBrowserThreadManager;
379
384
  /**
380
385
  * Thread manager implementation for AgentBrowser.
381
386
  *
@@ -384,9 +389,9 @@ interface AgentBrowserThreadManagerConfig extends ThreadManagerConfig {
384
389
  * - 'thread': Each thread gets a dedicated browser manager instance
385
390
  */
386
391
  declare class AgentBrowserThreadManager extends ThreadManager<BrowserManager> {
387
- private readonly browserConfig;
392
+ protected readonly browserConfig: BrowserConfig;
388
393
  private readonly resolveCdpUrl?;
389
- private readonly onBrowserCreated?;
394
+ protected readonly onBrowserCreated?: (manager: BrowserManager, threadId: string) => void;
390
395
  constructor(config: AgentBrowserThreadManagerConfig);
391
396
  /**
392
397
  * Get the page for a specific thread, creating session if needed.
@@ -399,7 +404,7 @@ declare class AgentBrowserThreadManager extends ThreadManager<BrowserManager> {
399
404
  /**
400
405
  * Restore browser state (multiple tabs) to a browser manager.
401
406
  */
402
- private restoreBrowserState;
407
+ protected restoreBrowserState(manager: BrowserManager, state: BrowserState): Promise<void>;
403
408
  /**
404
409
  * Get the browser manager for a specific session.
405
410
  */
@@ -415,6 +420,10 @@ declare class AgentBrowserThreadManager extends ThreadManager<BrowserManager> {
415
420
  destroyAllSessions(): Promise<void>;
416
421
  }
417
422
 
423
+ /** AgentBrowser accepts an optional thread-manager factory (see {@link CreateAgentBrowserThreadManager}). */
424
+ type AgentBrowserConfig = BrowserConfig & {
425
+ createThreadManager?: CreateAgentBrowserThreadManager;
426
+ };
418
427
  /**
419
428
  * AgentBrowser - Browser automation using agent-browser (vercel-labs/agent-browser)
420
429
  *
@@ -422,8 +431,8 @@ declare class AgentBrowserThreadManager extends ThreadManager<BrowserManager> {
422
431
  */
423
432
  declare class AgentBrowser extends MastraBrowser {
424
433
  readonly id: string;
425
- readonly name = "AgentBrowser";
426
- readonly provider = "vercel-labs/agent-browser";
434
+ readonly name: string;
435
+ readonly provider: string;
427
436
  /** Shared browser manager instance (for 'shared' scope) - narrowed type from base class */
428
437
  protected sharedManager: BrowserManager | null;
429
438
  private defaultTimeout;
@@ -432,7 +441,7 @@ declare class AgentBrowser extends MastraBrowser {
432
441
  /** Thread manager - narrowed type from base class */
433
442
  protected threadManager: AgentBrowserThreadManager;
434
443
  private browserConfig;
435
- constructor(config?: BrowserConfig);
444
+ constructor(config?: AgentBrowserConfig);
436
445
  /**
437
446
  * Ensure browser is ready and thread session exists.
438
447
  * Creates a new page/context for the current thread if needed.
@@ -452,7 +461,7 @@ declare class AgentBrowser extends MastraBrowser {
452
461
  * Set up close event listeners for 'shared' scope browser.
453
462
  * This handles the case where the shared browser is closed externally.
454
463
  */
455
- private setupCloseListenerForSharedScope;
464
+ protected setupCloseListenerForSharedScope(manager: BrowserManager): void;
456
465
  protected doClose(): Promise<void>;
457
466
  /**
458
467
  * Check if the browser is still alive by verifying the page is connected.
@@ -652,4 +661,4 @@ declare function getBrowserPid(manager: BrowserManager): Promise<number | undefi
652
661
  */
653
662
  declare function createAgentBrowserTools(browser: AgentBrowser): Record<string, Tool<any, any>>;
654
663
 
655
- 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, getBrowserPid, gotoInputSchema, hoverInputSchema, pressInputSchema, scrollInputSchema, selectInputSchema, snapshotInputSchema, tabsInputSchema, typeInputSchema, waitInputSchema };
664
+ export { AgentBrowser, type AgentBrowserConfig, type AgentBrowserSession, AgentBrowserThreadManager, type AgentBrowserThreadManagerConfig, BROWSER_TOOLS, type BackInput, type BrowserConfig, type BrowserToolName, type ClickInput, type CloseInput, type CreateAgentBrowserThreadManager, 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, getBrowserPid, gotoInputSchema, hoverInputSchema, pressInputSchema, scrollInputSchema, selectInputSchema, snapshotInputSchema, tabsInputSchema, typeInputSchema, waitInputSchema };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { BrowserConfig as BrowserConfig$1, ThreadManager, ThreadManagerConfig, ThreadSession, MastraBrowser, BrowserToolError, BrowserState, BrowserTabState, ScreencastOptions, ScreencastStream, MouseEventParams, KeyboardEventParams } from '@mastra/core/browser';
1
+ import { BrowserConfig as BrowserConfig$1, ThreadManager, ThreadManagerConfig, ThreadSession, BrowserState, MastraBrowser, BrowserToolError, BrowserTabState, ScreencastOptions, ScreencastStream, MouseEventParams, KeyboardEventParams } from '@mastra/core/browser';
2
2
  import { Tool } from '@mastra/core/tools';
3
3
  import { BrowserManager } from 'agent-browser';
4
4
  import { Page } from 'playwright-core';
@@ -376,6 +376,11 @@ interface AgentBrowserThreadManagerConfig extends ThreadManagerConfig {
376
376
  /** Callback when a new browser manager is created for a thread */
377
377
  onBrowserCreated?: (manager: BrowserManager, threadId: string) => void;
378
378
  }
379
+ /**
380
+ * Factory for custom thread managers (e.g. Firecrawl-hosted CDP per session).
381
+ * Defaults to {@link AgentBrowserThreadManager} when omitted.
382
+ */
383
+ type CreateAgentBrowserThreadManager = (config: AgentBrowserThreadManagerConfig) => AgentBrowserThreadManager;
379
384
  /**
380
385
  * Thread manager implementation for AgentBrowser.
381
386
  *
@@ -384,9 +389,9 @@ interface AgentBrowserThreadManagerConfig extends ThreadManagerConfig {
384
389
  * - 'thread': Each thread gets a dedicated browser manager instance
385
390
  */
386
391
  declare class AgentBrowserThreadManager extends ThreadManager<BrowserManager> {
387
- private readonly browserConfig;
392
+ protected readonly browserConfig: BrowserConfig;
388
393
  private readonly resolveCdpUrl?;
389
- private readonly onBrowserCreated?;
394
+ protected readonly onBrowserCreated?: (manager: BrowserManager, threadId: string) => void;
390
395
  constructor(config: AgentBrowserThreadManagerConfig);
391
396
  /**
392
397
  * Get the page for a specific thread, creating session if needed.
@@ -399,7 +404,7 @@ declare class AgentBrowserThreadManager extends ThreadManager<BrowserManager> {
399
404
  /**
400
405
  * Restore browser state (multiple tabs) to a browser manager.
401
406
  */
402
- private restoreBrowserState;
407
+ protected restoreBrowserState(manager: BrowserManager, state: BrowserState): Promise<void>;
403
408
  /**
404
409
  * Get the browser manager for a specific session.
405
410
  */
@@ -415,6 +420,10 @@ declare class AgentBrowserThreadManager extends ThreadManager<BrowserManager> {
415
420
  destroyAllSessions(): Promise<void>;
416
421
  }
417
422
 
423
+ /** AgentBrowser accepts an optional thread-manager factory (see {@link CreateAgentBrowserThreadManager}). */
424
+ type AgentBrowserConfig = BrowserConfig & {
425
+ createThreadManager?: CreateAgentBrowserThreadManager;
426
+ };
418
427
  /**
419
428
  * AgentBrowser - Browser automation using agent-browser (vercel-labs/agent-browser)
420
429
  *
@@ -422,8 +431,8 @@ declare class AgentBrowserThreadManager extends ThreadManager<BrowserManager> {
422
431
  */
423
432
  declare class AgentBrowser extends MastraBrowser {
424
433
  readonly id: string;
425
- readonly name = "AgentBrowser";
426
- readonly provider = "vercel-labs/agent-browser";
434
+ readonly name: string;
435
+ readonly provider: string;
427
436
  /** Shared browser manager instance (for 'shared' scope) - narrowed type from base class */
428
437
  protected sharedManager: BrowserManager | null;
429
438
  private defaultTimeout;
@@ -432,7 +441,7 @@ declare class AgentBrowser extends MastraBrowser {
432
441
  /** Thread manager - narrowed type from base class */
433
442
  protected threadManager: AgentBrowserThreadManager;
434
443
  private browserConfig;
435
- constructor(config?: BrowserConfig);
444
+ constructor(config?: AgentBrowserConfig);
436
445
  /**
437
446
  * Ensure browser is ready and thread session exists.
438
447
  * Creates a new page/context for the current thread if needed.
@@ -452,7 +461,7 @@ declare class AgentBrowser extends MastraBrowser {
452
461
  * Set up close event listeners for 'shared' scope browser.
453
462
  * This handles the case where the shared browser is closed externally.
454
463
  */
455
- private setupCloseListenerForSharedScope;
464
+ protected setupCloseListenerForSharedScope(manager: BrowserManager): void;
456
465
  protected doClose(): Promise<void>;
457
466
  /**
458
467
  * Check if the browser is still alive by verifying the page is connected.
@@ -652,4 +661,4 @@ declare function getBrowserPid(manager: BrowserManager): Promise<number | undefi
652
661
  */
653
662
  declare function createAgentBrowserTools(browser: AgentBrowser): Record<string, Tool<any, any>>;
654
663
 
655
- 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, getBrowserPid, gotoInputSchema, hoverInputSchema, pressInputSchema, scrollInputSchema, selectInputSchema, snapshotInputSchema, tabsInputSchema, typeInputSchema, waitInputSchema };
664
+ export { AgentBrowser, type AgentBrowserConfig, type AgentBrowserSession, AgentBrowserThreadManager, type AgentBrowserThreadManagerConfig, BROWSER_TOOLS, type BackInput, type BrowserConfig, type BrowserToolName, type ClickInput, type CloseInput, type CreateAgentBrowserThreadManager, 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, getBrowserPid, gotoInputSchema, hoverInputSchema, pressInputSchema, scrollInputSchema, selectInputSchema, snapshotInputSchema, tabsInputSchema, typeInputSchema, waitInputSchema };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { MastraBrowser, DEFAULT_THREAD_ID, ScreencastStreamImpl, ThreadManager } from '@mastra/core/browser';
1
+ import { ThreadManager, MastraBrowser, DEFAULT_THREAD_ID, ScreencastStreamImpl } from '@mastra/core/browser';
2
2
  import { BrowserManager } from 'agent-browser';
3
3
  import { createTool } from '@mastra/core/tools';
4
4
  import { z } from 'zod';
@@ -574,7 +574,7 @@ var AgentBrowser = class extends MastraBrowser {
574
574
  this.defaultTimeout = config.timeout;
575
575
  }
576
576
  const effectiveScope = config.cdpUrl ? config.scope ?? "shared" : config.scope ?? "thread";
577
- this.threadManager = new AgentBrowserThreadManager({
577
+ const threadManagerConfig = {
578
578
  scope: effectiveScope,
579
579
  browserConfig: { ...config, headless: this.headless },
580
580
  resolveCdpUrl: this.resolveCdpUrl.bind(this),
@@ -587,7 +587,9 @@ var AgentBrowser = class extends MastraBrowser {
587
587
  onBrowserCreated: (manager, threadId) => {
588
588
  this.setupCloseListenerForThread(manager, threadId);
589
589
  }
590
- });
590
+ };
591
+ const createTm = config.createThreadManager ?? ((opts) => new AgentBrowserThreadManager(opts));
592
+ this.threadManager = createTm(threadManagerConfig);
591
593
  }
592
594
  // ---------------------------------------------------------------------------
593
595
  // Thread Scope (delegated to ThreadManager)
@@ -1684,6 +1686,6 @@ var AgentBrowser = class extends MastraBrowser {
1684
1686
  }
1685
1687
  };
1686
1688
 
1687
- export { AgentBrowser, BROWSER_TOOLS, backInputSchema, browserSchemas, clickInputSchema, closeInputSchema, createAgentBrowserTools, dialogInputSchema, dragInputSchema, evaluateInputSchema, getBrowserPid, gotoInputSchema, hoverInputSchema, pressInputSchema, scrollInputSchema, selectInputSchema, snapshotInputSchema, tabsInputSchema, typeInputSchema, waitInputSchema };
1689
+ export { AgentBrowser, AgentBrowserThreadManager, BROWSER_TOOLS, backInputSchema, browserSchemas, clickInputSchema, closeInputSchema, createAgentBrowserTools, dialogInputSchema, dragInputSchema, evaluateInputSchema, getBrowserPid, gotoInputSchema, hoverInputSchema, pressInputSchema, scrollInputSchema, selectInputSchema, snapshotInputSchema, tabsInputSchema, typeInputSchema, waitInputSchema };
1688
1690
  //# sourceMappingURL=index.js.map
1689
1691
  //# sourceMappingURL=index.js.map