@mearl/native-host 2.3.0 → 2.5.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/agentbay-browser.d.ts +91 -0
- package/dist/browser-inventory.d.ts +2 -1
- package/dist/cdp-backend/cdp-session.d.ts +10 -4
- package/dist/cdp-backend/client.d.ts +8 -21
- package/dist/cdp-backend/cookie-transfer.d.ts +5 -0
- package/dist/host-updater.d.ts +39 -0
- package/dist/index.js +1265 -414
- package/dist/managed-browser.d.ts +6 -0
- package/package.json +9 -4
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/** AgentBay browser lifecycle and CDP endpoint resolution. */
|
|
2
|
+
import { type DaemonRecord } from '@mearl/daemon-core';
|
|
3
|
+
import type { BrowserLaunchParams } from '@mearl/browser-core';
|
|
4
|
+
import { type TransferableCookie } from './cdp-backend/cookie-transfer.js';
|
|
5
|
+
export declare const DEFAULT_AGENTBAY_IMAGE_ID = "imgc-0aae4rgl8kvagdv1j";
|
|
6
|
+
export interface AgentBayBrowserRecord extends DaemonRecord {
|
|
7
|
+
pid: number;
|
|
8
|
+
browserId: string;
|
|
9
|
+
name: string;
|
|
10
|
+
sessionId: string;
|
|
11
|
+
imageId?: string;
|
|
12
|
+
accessUrl?: string;
|
|
13
|
+
createdAt: string;
|
|
14
|
+
copiedCookies?: {
|
|
15
|
+
domains: string[];
|
|
16
|
+
count: number;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export interface AgentBaySessionLike {
|
|
20
|
+
sessionId: string;
|
|
21
|
+
resourceUrl?: string;
|
|
22
|
+
browser: {
|
|
23
|
+
initializeAsync(options: Record<string, unknown>): Promise<boolean>;
|
|
24
|
+
getEndpointUrl(): Promise<string>;
|
|
25
|
+
};
|
|
26
|
+
delete(syncContext?: boolean): Promise<{
|
|
27
|
+
success: boolean;
|
|
28
|
+
errorMessage?: string;
|
|
29
|
+
}>;
|
|
30
|
+
keepAlive(): Promise<{
|
|
31
|
+
success?: boolean;
|
|
32
|
+
errorMessage?: string;
|
|
33
|
+
}>;
|
|
34
|
+
}
|
|
35
|
+
export interface AgentBayClientLike {
|
|
36
|
+
create(params: Record<string, unknown>): Promise<{
|
|
37
|
+
success: boolean;
|
|
38
|
+
session?: AgentBaySessionLike;
|
|
39
|
+
errorMessage?: string;
|
|
40
|
+
}>;
|
|
41
|
+
get(sessionId: string): Promise<{
|
|
42
|
+
success: boolean;
|
|
43
|
+
session?: AgentBaySessionLike;
|
|
44
|
+
errorMessage?: string;
|
|
45
|
+
}>;
|
|
46
|
+
}
|
|
47
|
+
export interface AgentBayBrowserSummary {
|
|
48
|
+
browserId: string;
|
|
49
|
+
name: string;
|
|
50
|
+
provider: 'agentbay';
|
|
51
|
+
headless: false;
|
|
52
|
+
persistent: false;
|
|
53
|
+
agentbaySessionId: string;
|
|
54
|
+
agentbayImageId?: string;
|
|
55
|
+
agentbayAccessUrl?: string;
|
|
56
|
+
createdAt: string;
|
|
57
|
+
copiedCookies?: AgentBayBrowserRecord['copiedCookies'];
|
|
58
|
+
running: boolean;
|
|
59
|
+
}
|
|
60
|
+
export interface AgentBayBrowserManagerDeps {
|
|
61
|
+
nativeHostScript: string;
|
|
62
|
+
exportCookies: (domains: string[]) => Promise<TransferableCookie[]>;
|
|
63
|
+
getBrowserUserAgent: () => Promise<string>;
|
|
64
|
+
log: (...args: any[]) => void;
|
|
65
|
+
createAgentBayClient?: (apiKey: string) => Promise<AgentBayClientLike>;
|
|
66
|
+
persistBrowserRecord?: (record: AgentBayBrowserRecord) => void;
|
|
67
|
+
resolveApiKey?: () => string;
|
|
68
|
+
}
|
|
69
|
+
interface AgentBayCdpClient {
|
|
70
|
+
sendCommand(method: string, params?: Record<string, any>, timeoutMs?: number): Promise<any>;
|
|
71
|
+
close(): void;
|
|
72
|
+
}
|
|
73
|
+
type ConnectAgentBayCdp = (endpoint: string) => Promise<AgentBayCdpClient>;
|
|
74
|
+
interface AgentBayBrowserSessionInitOptions {
|
|
75
|
+
userAgent?: string;
|
|
76
|
+
connectCdp?: ConnectAgentBayCdp;
|
|
77
|
+
}
|
|
78
|
+
/** Stable managed-browser identity while keeping the cloud provider explicit. */
|
|
79
|
+
export declare function agentBayBrowserId(name: string): string;
|
|
80
|
+
export declare function resolveAgentBayApiKey(): string;
|
|
81
|
+
export declare function resolveAgentBayImageId(value: unknown): string;
|
|
82
|
+
export declare function normalizeDesktopUserAgent(value: unknown): string;
|
|
83
|
+
export declare function normalizeAgentBayAccessUrl(value: unknown): string | undefined;
|
|
84
|
+
export declare function hasAgentBayBrowser(selector: string): boolean;
|
|
85
|
+
export declare function listAgentBayBrowsers(): AgentBayBrowserSummary[];
|
|
86
|
+
export declare function resolveAgentBayEndpoint(sessionId: string): Promise<string>;
|
|
87
|
+
export declare function keepAgentBaySessionAlive(sessionId: string): Promise<void>;
|
|
88
|
+
export declare function initializeAgentBayBrowserSession(session: Pick<AgentBaySessionLike, 'browser'>, input: Pick<BrowserLaunchParams, 'url'>, cookies: TransferableCookie[], options?: AgentBayBrowserSessionInitOptions): Promise<number>;
|
|
89
|
+
export declare function launchAgentBayBrowser(input: BrowserLaunchParams, deps: AgentBayBrowserManagerDeps): Promise<AgentBayBrowserSummary>;
|
|
90
|
+
export declare function closeAgentBayBrowser(selector: string): Promise<Record<string, any>>;
|
|
91
|
+
export {};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { BrowserListResult } from '@mearl/browser-core';
|
|
2
2
|
import { type BrowserRecord } from './browser-registry.js';
|
|
3
3
|
import { type ManagedBrowserSummary } from './managed-browser.js';
|
|
4
|
+
import { type AgentBayBrowserSummary } from './agentbay-browser.js';
|
|
4
5
|
type BrowserInventoryResult = Omit<BrowserListResult, 'defaultBrowserId'>;
|
|
5
|
-
export declare function mergeBrowserInventory(connected: BrowserRecord[], managed: ManagedBrowserSummary
|
|
6
|
+
export declare function mergeBrowserInventory(connected: BrowserRecord[], managed: Array<ManagedBrowserSummary | AgentBayBrowserSummary>): BrowserInventoryResult;
|
|
6
7
|
export declare function listBrowserInventory(): BrowserInventoryResult;
|
|
7
8
|
export {};
|
|
@@ -19,18 +19,23 @@ export interface PageSession {
|
|
|
19
19
|
touch: boolean;
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
+
export interface CdpSessionOptions {
|
|
23
|
+
port?: number;
|
|
24
|
+
userDataDir?: string;
|
|
25
|
+
endpointUrl?: string;
|
|
26
|
+
endpointResolver?: () => Promise<string>;
|
|
27
|
+
}
|
|
22
28
|
export declare class CdpSession {
|
|
23
29
|
readonly port: number;
|
|
24
30
|
readonly userDataDir?: string;
|
|
31
|
+
private readonly endpointUrl?;
|
|
32
|
+
private readonly endpointResolver?;
|
|
25
33
|
private browserClient;
|
|
26
34
|
private pageSessions;
|
|
27
35
|
/** Virtual tabId counter → CDP targetId */
|
|
28
36
|
private tabIdMap;
|
|
29
37
|
private nextTabId;
|
|
30
|
-
constructor(options?: number |
|
|
31
|
-
port?: number;
|
|
32
|
-
userDataDir?: string;
|
|
33
|
-
});
|
|
38
|
+
constructor(options?: number | CdpSessionOptions);
|
|
34
39
|
getBrowserClient(): Promise<CdpClient>;
|
|
35
40
|
/**
|
|
36
41
|
* Get (or create) a page session.
|
|
@@ -58,6 +63,7 @@ export declare class CdpSession {
|
|
|
58
63
|
* Used when HTTP /json is unavailable.
|
|
59
64
|
*/
|
|
60
65
|
private pageWsUrl;
|
|
66
|
+
private isRemote;
|
|
61
67
|
private findTargetByIdViaCdp;
|
|
62
68
|
private findDefaultPageTargetViaCdp;
|
|
63
69
|
private fetchVersionInfo;
|
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Minimal WebSocket-based CDP client for native-host (no external deps).
|
|
3
|
-
* Uses node:http upgrade event + raw frame handling via node:net Socket.
|
|
4
|
-
*/
|
|
1
|
+
/** WebSocket CDP client shared by local and remote browser sessions. */
|
|
5
2
|
type EventCallback = (params: any) => void;
|
|
6
|
-
/**
|
|
7
|
-
* A virtual client that routes CDP messages through a specific sessionId
|
|
8
|
-
* on a shared browser-level WebSocket connection.
|
|
9
|
-
*
|
|
10
|
-
* This is used for page-level commands when Chrome does not allow direct
|
|
11
|
-
* connections to /devtools/page/... (e.g., when enabled via chrome://inspect).
|
|
12
|
-
*/
|
|
13
3
|
export declare class CdpChildSession {
|
|
14
4
|
private readonly parent;
|
|
15
5
|
readonly sessionId: string;
|
|
@@ -20,28 +10,25 @@ export declare class CdpChildSession {
|
|
|
20
10
|
close(): void;
|
|
21
11
|
}
|
|
22
12
|
export declare class CdpClient {
|
|
23
|
-
private socket;
|
|
24
|
-
private buffer;
|
|
13
|
+
private readonly socket;
|
|
25
14
|
private nextId;
|
|
26
15
|
private pending;
|
|
27
16
|
private eventHandlers;
|
|
28
|
-
/** sessionId → method → callbacks (for multiplexed page sessions) */
|
|
29
17
|
private sessionEventHandlers;
|
|
30
18
|
private _closed;
|
|
31
19
|
private constructor();
|
|
32
|
-
|
|
20
|
+
static connect(wsUrl: string): Promise<CdpClient>;
|
|
33
21
|
createChildSession(sessionId: string): CdpChildSession;
|
|
34
|
-
/** Send a command within a specific CDP session (multiplexed on this connection). */
|
|
35
22
|
sendCommandInSession(sessionId: string, method: string, params?: Record<string, any>, timeoutMs?: number): Promise<any>;
|
|
36
|
-
/** Subscribe to events from a specific CDP session. */
|
|
37
23
|
onSession(sessionId: string, method: string, callback: EventCallback): () => void;
|
|
38
|
-
static connect(wsUrl: string): Promise<CdpClient>;
|
|
39
|
-
private consumeFrames;
|
|
40
|
-
private handleMessage;
|
|
41
24
|
sendCommand(method: string, params?: Record<string, any>, timeoutMs?: number): Promise<any>;
|
|
42
25
|
on(method: string, callback: EventCallback): () => void;
|
|
43
|
-
private sendText;
|
|
44
26
|
close(): void;
|
|
45
27
|
get closed(): boolean;
|
|
28
|
+
private sendRequest;
|
|
29
|
+
private consumeMessage;
|
|
30
|
+
private handleMessage;
|
|
31
|
+
private handleClosed;
|
|
32
|
+
private rejectPending;
|
|
46
33
|
}
|
|
47
34
|
export {};
|
|
@@ -18,8 +18,13 @@ export interface TransferableCookie {
|
|
|
18
18
|
hasCrossSiteAncestor?: boolean;
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
|
+
interface CookieCommandClient {
|
|
22
|
+
sendCommand(method: string, params?: Record<string, any>, timeoutMs?: number): Promise<any>;
|
|
23
|
+
}
|
|
21
24
|
export declare function normalizeCookieDomain(input: string): string;
|
|
22
25
|
export declare function normalizeCookieDomains(inputs: unknown): string[];
|
|
23
26
|
export declare function cookieMatchesDomain(cookieDomain: string, requestedDomain: string): boolean;
|
|
24
27
|
export declare function cdpExportCookies(session: CdpSession, domains: string[]): Promise<TransferableCookie[]>;
|
|
25
28
|
export declare function cdpImportCookies(session: CdpSession, cookies: TransferableCookie[]): Promise<number>;
|
|
29
|
+
export declare function cdpImportCookiesWithClient(browser: CookieCommandClient, cookies: TransferableCookie[]): Promise<number>;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type CommandRunner } from '@mearl/setup/process';
|
|
2
|
+
export declare const NATIVE_HOST_UPDATE_TIMEOUT_MS: number;
|
|
3
|
+
export type NativeHostUpdateError = 'lock-timeout' | 'network' | 'package-unavailable' | 'setup-failed' | 'timeout' | 'verification-failed' | 'unknown';
|
|
4
|
+
export interface NativeHostUpdateCommand {
|
|
5
|
+
args: string[];
|
|
6
|
+
}
|
|
7
|
+
type UpdateLockRunner = <T>(targetVersion: string, operation: () => Promise<T>) => Promise<T>;
|
|
8
|
+
export interface RunNativeHostUpdateOptions {
|
|
9
|
+
areTargetsInstalled?: (targetReleaseLine: string, environment: NodeJS.ProcessEnv) => Promise<boolean>;
|
|
10
|
+
environment?: NodeJS.ProcessEnv;
|
|
11
|
+
nodePath?: string;
|
|
12
|
+
packageBinDirectory?: string | null;
|
|
13
|
+
packageManagerCommand?: string | null;
|
|
14
|
+
packageRunner?: string;
|
|
15
|
+
platform?: NodeJS.Platform;
|
|
16
|
+
runner?: CommandRunner;
|
|
17
|
+
timeoutMs?: number;
|
|
18
|
+
updateLockPath?: string;
|
|
19
|
+
withUpdateLock?: UpdateLockRunner;
|
|
20
|
+
}
|
|
21
|
+
export interface NativeHostUpdateCoordinatorOptions {
|
|
22
|
+
hostVersion: string;
|
|
23
|
+
log: (...args: unknown[]) => void;
|
|
24
|
+
requestRestart: () => void | Promise<void>;
|
|
25
|
+
runUpdate: (targetVersion: string) => Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
export declare class NativeHostUpdateFailure extends Error {
|
|
28
|
+
readonly updateError: NativeHostUpdateError;
|
|
29
|
+
constructor(updateError: NativeHostUpdateError, message: string);
|
|
30
|
+
}
|
|
31
|
+
export declare function nativeHostUpdateCommand(targetVersion: string): NativeHostUpdateCommand;
|
|
32
|
+
export declare function runNativeHostUpdate(targetVersion: string, options?: RunNativeHostUpdateOptions): Promise<void>;
|
|
33
|
+
export declare class NativeHostUpdateCoordinator {
|
|
34
|
+
#private;
|
|
35
|
+
private readonly options;
|
|
36
|
+
constructor(options: NativeHostUpdateCoordinatorOptions);
|
|
37
|
+
evaluate(extensionVersion: unknown, checkForUpdates: unknown): void;
|
|
38
|
+
}
|
|
39
|
+
export {};
|