@mearl/native-host
Advanced tools
| /** AgentBay browser lifecycle and CDP endpoint resolution. */ | ||
| import { type DaemonRecord } from '@mearl/daemon-core'; | ||
| import type { BrowserLaunchParams } from '@mearl/browser-core'; | ||
| import { type TransferableCookie } from './cdp-backend/cookie-transfer.js'; | ||
| export declare const DEFAULT_AGENTBAY_IMAGE_ID = "imgc-0aae4rgl8kvagdv1j"; | ||
| export interface AgentBayBrowserRecord extends DaemonRecord { | ||
| pid: number; | ||
| browserId: string; | ||
| name: string; | ||
| sessionId: string; | ||
| imageId?: string; | ||
| accessUrl?: string; | ||
| createdAt: string; | ||
| copiedCookies?: { | ||
| domains: string[]; | ||
| count: number; | ||
| }; | ||
| } | ||
| export interface AgentBaySessionLike { | ||
| sessionId: string; | ||
| resourceUrl?: string; | ||
| browser: { | ||
| initializeAsync(options: Record<string, unknown>): Promise<boolean>; | ||
| getEndpointUrl(): Promise<string>; | ||
| }; | ||
| delete(syncContext?: boolean): Promise<{ | ||
| success: boolean; | ||
| errorMessage?: string; | ||
| }>; | ||
| keepAlive(): Promise<{ | ||
| success?: boolean; | ||
| errorMessage?: string; | ||
| }>; | ||
| } | ||
| export interface AgentBayClientLike { | ||
| create(params: Record<string, unknown>): Promise<{ | ||
| success: boolean; | ||
| session?: AgentBaySessionLike; | ||
| errorMessage?: string; | ||
| }>; | ||
| get(sessionId: string): Promise<{ | ||
| success: boolean; | ||
| session?: AgentBaySessionLike; | ||
| errorMessage?: string; | ||
| }>; | ||
| } | ||
| export interface AgentBayBrowserSummary { | ||
| browserId: string; | ||
| name: string; | ||
| provider: 'agentbay'; | ||
| headless: false; | ||
| persistent: false; | ||
| agentbaySessionId: string; | ||
| agentbayImageId?: string; | ||
| agentbayAccessUrl?: string; | ||
| createdAt: string; | ||
| copiedCookies?: AgentBayBrowserRecord['copiedCookies']; | ||
| running: boolean; | ||
| } | ||
| export interface AgentBayBrowserManagerDeps { | ||
| nativeHostScript: string; | ||
| exportCookies: (domains: string[]) => Promise<TransferableCookie[]>; | ||
| getBrowserUserAgent: () => Promise<string>; | ||
| log: (...args: any[]) => void; | ||
| createAgentBayClient?: (apiKey: string) => Promise<AgentBayClientLike>; | ||
| persistBrowserRecord?: (record: AgentBayBrowserRecord) => void; | ||
| resolveApiKey?: () => string; | ||
| } | ||
| interface AgentBayCdpClient { | ||
| sendCommand(method: string, params?: Record<string, any>, timeoutMs?: number): Promise<any>; | ||
| close(): void; | ||
| } | ||
| type ConnectAgentBayCdp = (endpoint: string) => Promise<AgentBayCdpClient>; | ||
| interface AgentBayBrowserSessionInitOptions { | ||
| userAgent?: string; | ||
| connectCdp?: ConnectAgentBayCdp; | ||
| } | ||
| /** Stable managed-browser identity while keeping the cloud provider explicit. */ | ||
| export declare function agentBayBrowserId(name: string): string; | ||
| export declare function resolveAgentBayApiKey(): string; | ||
| export declare function resolveAgentBayImageId(value: unknown): string; | ||
| export declare function normalizeDesktopUserAgent(value: unknown): string; | ||
| export declare function normalizeAgentBayAccessUrl(value: unknown): string | undefined; | ||
| export declare function hasAgentBayBrowser(selector: string): boolean; | ||
| export declare function listAgentBayBrowsers(): AgentBayBrowserSummary[]; | ||
| export declare function resolveAgentBayEndpoint(sessionId: string): Promise<string>; | ||
| export declare function keepAgentBaySessionAlive(sessionId: string): Promise<void>; | ||
| export declare function initializeAgentBayBrowserSession(session: Pick<AgentBaySessionLike, 'browser'>, input: Pick<BrowserLaunchParams, 'url'>, cookies: TransferableCookie[], options?: AgentBayBrowserSessionInitOptions): Promise<number>; | ||
| export declare function launchAgentBayBrowser(input: BrowserLaunchParams, deps: AgentBayBrowserManagerDeps): Promise<AgentBayBrowserSummary>; | ||
| export declare function closeAgentBayBrowser(selector: string): Promise<Record<string, any>>; | ||
| export {}; |
| import type { BrowserListResult } from '@mearl/browser-core'; | ||
| import { type BrowserRecord } from './browser-registry.js'; | ||
| import { type ManagedBrowserSummary } from './managed-browser.js'; | ||
| import { type AgentBayBrowserSummary } from './agentbay-browser.js'; | ||
| type BrowserInventoryResult = Omit<BrowserListResult, 'defaultBrowserId'>; | ||
| export declare function mergeBrowserInventory(connected: BrowserRecord[], managed: ManagedBrowserSummary[]): BrowserInventoryResult; | ||
| export declare function mergeBrowserInventory(connected: BrowserRecord[], managed: Array<ManagedBrowserSummary | AgentBayBrowserSummary>): BrowserInventoryResult; | ||
| export declare function listBrowserInventory(): BrowserInventoryResult; | ||
| export {}; |
@@ -22,5 +22,13 @@ /** | ||
| } | ||
| export interface CdpSessionOptions { | ||
| port?: number; | ||
| userDataDir?: string; | ||
| endpointUrl?: string; | ||
| endpointResolver?: () => Promise<string>; | ||
| } | ||
| export declare class CdpSession { | ||
| readonly port: number; | ||
| readonly userDataDir?: string; | ||
| private readonly endpointUrl?; | ||
| private readonly endpointResolver?; | ||
| private browserClient; | ||
@@ -31,6 +39,3 @@ private pageSessions; | ||
| private nextTabId; | ||
| constructor(options?: number | { | ||
| port?: number; | ||
| userDataDir?: string; | ||
| }); | ||
| constructor(options?: number | CdpSessionOptions); | ||
| getBrowserClient(): Promise<CdpClient>; | ||
@@ -63,2 +68,3 @@ /** | ||
| private pageWsUrl; | ||
| private isRemote; | ||
| private findTargetByIdViaCdp; | ||
@@ -65,0 +71,0 @@ private findDefaultPageTargetViaCdp; |
@@ -1,13 +0,3 @@ | ||
| /** | ||
| * Minimal WebSocket-based CDP client for native-host (no external deps). | ||
| * Uses node:http upgrade event + raw frame handling via node:net Socket. | ||
| */ | ||
| /** WebSocket CDP client shared by local and remote browser sessions. */ | ||
| type EventCallback = (params: any) => void; | ||
| /** | ||
| * A virtual client that routes CDP messages through a specific sessionId | ||
| * on a shared browser-level WebSocket connection. | ||
| * | ||
| * This is used for page-level commands when Chrome does not allow direct | ||
| * connections to /devtools/page/... (e.g., when enabled via chrome://inspect). | ||
| */ | ||
| export declare class CdpChildSession { | ||
@@ -23,26 +13,23 @@ private readonly parent; | ||
| export declare class CdpClient { | ||
| private socket; | ||
| private buffer; | ||
| private readonly socket; | ||
| private nextId; | ||
| private pending; | ||
| private eventHandlers; | ||
| /** sessionId → method → callbacks (for multiplexed page sessions) */ | ||
| private sessionEventHandlers; | ||
| private _closed; | ||
| private constructor(); | ||
| /** Create a child session client that routes through this connection via sessionId. */ | ||
| static connect(wsUrl: string): Promise<CdpClient>; | ||
| createChildSession(sessionId: string): CdpChildSession; | ||
| /** Send a command within a specific CDP session (multiplexed on this connection). */ | ||
| sendCommandInSession(sessionId: string, method: string, params?: Record<string, any>, timeoutMs?: number): Promise<any>; | ||
| /** Subscribe to events from a specific CDP session. */ | ||
| onSession(sessionId: string, method: string, callback: EventCallback): () => void; | ||
| static connect(wsUrl: string): Promise<CdpClient>; | ||
| private consumeFrames; | ||
| private handleMessage; | ||
| sendCommand(method: string, params?: Record<string, any>, timeoutMs?: number): Promise<any>; | ||
| on(method: string, callback: EventCallback): () => void; | ||
| private sendText; | ||
| close(): void; | ||
| get closed(): boolean; | ||
| private sendRequest; | ||
| private consumeMessage; | ||
| private handleMessage; | ||
| private handleClosed; | ||
| private rejectPending; | ||
| } | ||
| export {}; |
@@ -21,2 +21,5 @@ /** Cookie export/import helpers for copying selected domains between CDP browsers. */ | ||
| } | ||
| interface CookieCommandClient { | ||
| sendCommand(method: string, params?: Record<string, any>, timeoutMs?: number): Promise<any>; | ||
| } | ||
| export declare function normalizeCookieDomain(input: string): string; | ||
@@ -27,1 +30,3 @@ export declare function normalizeCookieDomains(inputs: unknown): string[]; | ||
| export declare function cdpImportCookies(session: CdpSession, cookies: TransferableCookie[]): Promise<number>; | ||
| export declare function cdpImportCookiesWithClient(browser: CookieCommandClient, cookies: TransferableCookie[]): Promise<number>; | ||
| export {}; |
@@ -39,2 +39,3 @@ /** Managed Chrome lifecycle for isolated, optionally headless browser instances. */ | ||
| name: string; | ||
| provider: 'local'; | ||
| headless: boolean; | ||
@@ -54,2 +55,3 @@ persistent: boolean; | ||
| } | ||
| export declare function validateName(value: unknown): string; | ||
| /** Use one case-insensitive identity for registry, locking, and persistent profile paths. */ | ||
@@ -70,2 +72,6 @@ export declare function managedBrowserId(name: string): string; | ||
| export declare function listManagedBrowsers(): ManagedBrowserSummary[]; | ||
| export declare function hasManagedBrowser(selector: string): boolean; | ||
| export declare function waitForBrowserRegistration(browserId: string, expectedPid: number): Promise<void>; | ||
| export declare function stopProcess(pid: number, commandMarker: string): Promise<void>; | ||
| export declare function acquireLaunchLock(browserId: string): () => void; | ||
| export declare function launchManagedBrowser(input: BrowserLaunchParams, deps: ManagedBrowserManagerDeps): Promise<Record<string, any>>; | ||
@@ -72,0 +78,0 @@ export declare function closeManagedBrowser(selector: string, options?: { |
+9
-4
| { | ||
| "name": "@mearl/native-host", | ||
| "version": "2.4.0", | ||
| "version": "2.5.0", | ||
| "description": "Native Messaging Host for Mearl — bridges Chrome Extension and local socket server", | ||
@@ -30,10 +30,15 @@ "type": "module", | ||
| }, | ||
| "dependencies": { | ||
| "ws": "^8.18.3", | ||
| "wuying-agentbay-sdk": "^0.22.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@agentclientprotocol/sdk": "^1.2.1", | ||
| "@types/node": "^24.9.1", | ||
| "@types/ws": "^8.18.1", | ||
| "esbuild": "^0.25.2", | ||
| "typescript": "^5.8.3", | ||
| "@mearl/browser-core": "2.4.0", | ||
| "@mearl/daemon-core": "2.4.0", | ||
| "@mearl/setup": "2.4.0" | ||
| "@mearl/browser-core": "2.5.0", | ||
| "@mearl/daemon-core": "2.5.0", | ||
| "@mearl/setup": "2.5.0" | ||
| }, | ||
@@ -40,0 +45,0 @@ "scripts": { |
Sorry, the diff of this file is too big to display
1175974
1.82%53
1.92%32830
1.47%2
Infinity%8
14.29%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added