@mearl/native-host 3.0.0-beta.0 → 3.0.0-beta.10
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/README.md +119 -168
- package/README.zh-CN.md +319 -0
- package/dist/THIRD_PARTY_NOTICES.txt +22 -655
- package/dist/agent/chat-visualization.d.ts +3 -0
- package/dist/agent/managed-programs.d.ts +24 -0
- package/dist/agent/manager.d.ts +15 -2
- package/dist/agent/skill-manager.d.ts +8 -1
- package/dist/app-authorization.d.ts +8 -0
- package/dist/app-profile-catalog.d.ts +3 -1
- package/dist/browser-enhancement-gateway.d.ts +24 -0
- package/dist/browser-identity.d.ts +11 -0
- package/dist/browser-registry.d.ts +1 -0
- package/dist/browser-socket-request.d.ts +4 -0
- package/dist/capability-contracts.d.ts +15 -52
- package/dist/capability-hooks.d.ts +42 -0
- package/dist/cdp-backend/buffers.d.ts +11 -11
- package/dist/cdp-backend/capability-handlers.d.ts +1 -0
- package/dist/cdp-backend/cdp-session.d.ts +2 -0
- package/dist/cdp-backend/cdp-utils.d.ts +3 -8
- package/dist/cdp-backend/handlers.d.ts +2 -1
- package/dist/cdp-backend/http-handlers.d.ts +12 -9
- package/dist/cdp-backend/network-control.d.ts +5 -0
- package/dist/cdp-backend/page-dialogs.d.ts +14 -0
- package/dist/cdp-backend/request-cookies.d.ts +8 -0
- package/dist/cdp-backend/response-cookies.d.ts +8 -0
- package/dist/cdp-backend/send-request.d.ts +3 -2
- package/dist/control-session-manager.d.ts +1 -1
- package/dist/index.js +182 -217
- package/dist/install.js +1 -1
- package/dist/native-capability-services.d.ts +5 -2
- package/dist/node-capabilities.d.ts +1 -0
- package/dist/node-capabilities.js +2 -2
- package/dist/page-runtime-store.d.ts +2 -27
- package/dist/plugin-task-host.js +30 -45
- package/dist/plugin-worker.js +23 -38
- package/dist/pluginModelSessionWorker.js +1 -1
- package/dist/preset-auto-update.d.ts +18 -0
- package/dist/preset-components.d.ts +3 -1
- package/dist/provider-app-resources.d.ts +32 -0
- package/dist/provider-control.d.ts +1 -1
- package/dist/provider-enhancements.d.ts +21 -0
- package/package.json +17 -10
- package/dist/alipay-auth-code.d.ts +0 -13
- package/dist/cdp-backend/mtop-environment.d.ts +0 -7
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import type { AgentChatStatus } from '@mearl/browser-core';
|
|
3
|
+
import { type CommandRunner } from '@mearl/daemon-core';
|
|
4
|
+
import type { AgentCapabilityFactory } from '../capability-hooks.js';
|
|
5
|
+
import type { AgentProviderLoader } from './manager.js';
|
|
6
|
+
export declare class ManagedAgentPrograms {
|
|
7
|
+
private readonly directory;
|
|
8
|
+
private readonly run;
|
|
9
|
+
private readonly spawnLogin;
|
|
10
|
+
private readonly installing;
|
|
11
|
+
private qoderLogin?;
|
|
12
|
+
constructor(directory?: string, run?: CommandRunner, spawnLogin?: typeof spawn);
|
|
13
|
+
addToExecutableSearch(env?: NodeJS.ProcessEnv): void;
|
|
14
|
+
qoderLoader(context: Parameters<AgentCapabilityFactory>[0]): (AgentProviderLoader & {
|
|
15
|
+
revision: string;
|
|
16
|
+
}) | undefined;
|
|
17
|
+
describe(status: AgentChatStatus): AgentChatStatus;
|
|
18
|
+
install(id: unknown, status: () => Promise<AgentChatStatus>): Promise<AgentChatStatus>;
|
|
19
|
+
loginQoder(onSignedIn: () => void): Promise<string | null>;
|
|
20
|
+
private startQoderLogin;
|
|
21
|
+
private installMissing;
|
|
22
|
+
private executableFiles;
|
|
23
|
+
private installPackage;
|
|
24
|
+
}
|
package/dist/agent/manager.d.ts
CHANGED
|
@@ -2,9 +2,12 @@ import type { AgentChatEvent, AgentChatEventsOptions, AgentChatEventsResult, Age
|
|
|
2
2
|
import { type ToolboxAgentRuntime } from '../toolbox-service.js';
|
|
3
3
|
import type { AgentProvider, AgentProviderSessionOptions, AgentProviderTurnOptions } from '@mearl/agent-runtime';
|
|
4
4
|
export interface AgentChatManagerDependencies {
|
|
5
|
+
installedProviders?: () => Array<AgentProviderLoader & {
|
|
6
|
+
revision: unknown;
|
|
7
|
+
}>;
|
|
5
8
|
resolveToolboxAgent?: (toolId: string) => ToolboxAgentRuntime;
|
|
6
9
|
}
|
|
7
|
-
interface AgentProviderLoader {
|
|
10
|
+
export interface AgentProviderLoader {
|
|
8
11
|
id: string;
|
|
9
12
|
load(): Promise<AgentProvider>;
|
|
10
13
|
}
|
|
@@ -14,6 +17,9 @@ export declare class AgentChatManager {
|
|
|
14
17
|
private readonly providers;
|
|
15
18
|
private readonly providerLoaders;
|
|
16
19
|
private readonly providerLoads;
|
|
20
|
+
private readonly providerOperations;
|
|
21
|
+
private readonly installedSources;
|
|
22
|
+
private readonly unavailableProviders;
|
|
17
23
|
private disposed;
|
|
18
24
|
private readonly sessions;
|
|
19
25
|
private readonly sessionByProviderThread;
|
|
@@ -25,6 +31,8 @@ export declare class AgentChatManager {
|
|
|
25
31
|
private readonly truncatedEventSessions;
|
|
26
32
|
private readonly unsubscribe;
|
|
27
33
|
private readonly taskListeners;
|
|
34
|
+
private qoderNeedsReconnect;
|
|
35
|
+
private readonly qoderSessionsToResume;
|
|
28
36
|
constructor(providers: Array<AgentProvider | AgentProviderLoader>, emit: (event: AgentChatEvent) => void, dependencies?: AgentChatManagerDependencies);
|
|
29
37
|
getStatus(): Promise<AgentChatStatus>;
|
|
30
38
|
prepare(options: AgentChatPrepareOptions): Promise<void>;
|
|
@@ -49,11 +57,16 @@ export declare class AgentChatManager {
|
|
|
49
57
|
private recordEvent;
|
|
50
58
|
private trimReplayBuffer;
|
|
51
59
|
private getProvider;
|
|
60
|
+
qoderCredentialsChanged(): void;
|
|
61
|
+
private reconnectQoderIfIdle;
|
|
52
62
|
private registerProvider;
|
|
63
|
+
private withProvider;
|
|
64
|
+
private withAcceptedProvider;
|
|
65
|
+
private releaseProviderOperation;
|
|
66
|
+
private refreshInstalledProviders;
|
|
53
67
|
private loadProvider;
|
|
54
68
|
private getSession;
|
|
55
69
|
private providerThreadKey;
|
|
56
70
|
private providerRequestKey;
|
|
57
71
|
private sessionTurnKey;
|
|
58
72
|
}
|
|
59
|
-
export {};
|
|
@@ -14,6 +14,7 @@ export interface AgentSkillBackend {
|
|
|
14
14
|
install(data: AgentSkillInstallOptions): ReturnType<SkillCliRunner>;
|
|
15
15
|
installBatch?(data: SkillBackendBatchOptions): ReturnType<SkillCliRunner>;
|
|
16
16
|
normalizeSource?(source: string, sourceType?: string): string;
|
|
17
|
+
readSources?: typeof readTrackedSkillSources;
|
|
17
18
|
update(data: AgentSkillMutationOptions): ReturnType<SkillCliRunner>;
|
|
18
19
|
uninstall(data: AgentSkillMutationOptions): ReturnType<SkillCliRunner>;
|
|
19
20
|
checkUpdates(data: AgentSkillCheckUpdatesOptions): Promise<AgentSkillCheckUpdatesResult>;
|
|
@@ -35,14 +36,20 @@ export declare class AgentSkillManager {
|
|
|
35
36
|
private backend;
|
|
36
37
|
/** A preset batch keeps one accepted manager for all of its operations. */
|
|
37
38
|
capture(): AgentSkillManager;
|
|
38
|
-
inspectGlobal(source: string, name: string, version?: string): SkillInstallationStatus;
|
|
39
|
+
inspectGlobal(source: string, name: string, version?: string, migrateFrom?: readonly string[]): SkillInstallationStatus;
|
|
40
|
+
hasGlobalRegistrationConflict(name: string, aliases: readonly string[]): boolean;
|
|
39
41
|
repairGlobalRegistration(name: string, options?: {
|
|
40
42
|
registrationManagedBy?: string;
|
|
43
|
+
replaceExisting?: boolean;
|
|
44
|
+
expectedPluginNames?: readonly string[];
|
|
41
45
|
}): Promise<void>;
|
|
42
46
|
install(data: AgentSkillInstallOptions): Promise<AgentSkillMutationResult>;
|
|
43
47
|
installGlobal(source: string, name: string): Promise<AgentSkillMutationResult>;
|
|
44
48
|
installGlobals(source: string, names: string[], options?: {
|
|
45
49
|
registrationManagedBy?: string;
|
|
50
|
+
migrateFrom?: Readonly<Record<string, readonly string[]>>;
|
|
51
|
+
replaceSkills?: readonly string[];
|
|
52
|
+
expectedPluginNames?: Readonly<Record<string, readonly string[]>>;
|
|
46
53
|
}): Promise<AgentSkillMutationResult>;
|
|
47
54
|
private installAccepted;
|
|
48
55
|
checkUpdates(data: AgentSkillCheckUpdatesOptions): Promise<AgentSkillCheckUpdatesResult>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type AppAuthorizationProgress = 'installing' | 'connected' | 'authorizing';
|
|
2
|
+
export declare function startAppAuthorization(hook: string, value: unknown, progress?: (phase: AppAuthorizationProgress) => void): Promise<{
|
|
3
|
+
browserId: string;
|
|
4
|
+
qrSvg: string;
|
|
5
|
+
}>;
|
|
6
|
+
export declare function waitAppAuthorization(browserId: string, value: unknown, progress?: (phase: AppAuthorizationProgress) => void): Promise<Record<string, unknown>>;
|
|
7
|
+
export declare function closeAppAuthorization(browserId: string): Promise<void>;
|
|
8
|
+
export declare function closeAppAuthorizations(): Promise<void>;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { type ResolveAppProfileOptions } from '@mearl/app-profiles';
|
|
2
2
|
import { type AppProfileCatalogEntry } from '@mearl/browser-core';
|
|
3
3
|
export declare function findCapabilityAppProfile(id: string): AppProfileCatalogEntry | undefined;
|
|
4
|
-
export declare function listInstalledAppProfiles(
|
|
4
|
+
export declare function listInstalledAppProfiles(options?: {
|
|
5
|
+
refresh?: boolean;
|
|
6
|
+
}): Promise<{
|
|
5
7
|
profiles: AppProfileCatalogEntry[];
|
|
6
8
|
errors: Array<{
|
|
7
9
|
plugin: string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type BrowserEnhancementRequest, type BrowserEnhancementResponse, type ProviderEnhancementTarget } from '@mearl/browser-core';
|
|
2
|
+
import type { ProviderControlHostRecord } from '@mearl/provider/host';
|
|
3
|
+
import { type BrowserRecord } from './browser-registry.js';
|
|
4
|
+
interface Dependencies {
|
|
5
|
+
browsers(): BrowserRecord[];
|
|
6
|
+
controlHost(): ProviderControlHostRecord | null;
|
|
7
|
+
available(): boolean;
|
|
8
|
+
run<T>(action: string, data: {
|
|
9
|
+
tabId: number;
|
|
10
|
+
[key: string]: unknown;
|
|
11
|
+
}, work: () => Promise<T>): Promise<T>;
|
|
12
|
+
tabs(deadline?: number): Promise<number[]>;
|
|
13
|
+
verifySource(provider: BrowserRecord, tabId: number, deadline?: number): Promise<ProviderEnhancementTarget>;
|
|
14
|
+
invoke(request: BrowserEnhancementRequest, deadline?: number): Promise<BrowserEnhancementResponse>;
|
|
15
|
+
}
|
|
16
|
+
/** Accept only the live control host's scoped RPC, never caller-supplied trust/owner flags. */
|
|
17
|
+
export declare class BrowserEnhancementGateway {
|
|
18
|
+
private readonly dependencies;
|
|
19
|
+
private readonly bindings;
|
|
20
|
+
private pendingBindings;
|
|
21
|
+
constructor(dependencies: Dependencies);
|
|
22
|
+
invoke(source: unknown, proof: unknown, request: BrowserEnhancementRequest, deadline?: number, sourceIdentity?: unknown, sourceTabId?: unknown): Promise<BrowserEnhancementResponse>;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface BrowserIdentityProbe {
|
|
2
|
+
platform: NodeJS.Platform;
|
|
3
|
+
parentPid: number;
|
|
4
|
+
executable(pid: number): string;
|
|
5
|
+
bundleIdentifier(plist: string): string;
|
|
6
|
+
}
|
|
7
|
+
/** Inspect only the Native Messaging host's direct parent, never all running browsers. */
|
|
8
|
+
export declare function detectNativeBrowserName(probe?: BrowserIdentityProbe): string | undefined;
|
|
9
|
+
/** Cache the bounded probe across extension reconnects; keep the reported name as fallback. */
|
|
10
|
+
export declare function createExtensionBrowserNameResolver(detect?: typeof detectNativeBrowserName): (reportedName: string) => string;
|
|
11
|
+
export {};
|
|
@@ -51,6 +51,7 @@ export interface BrowserRecord extends DaemonRecord {
|
|
|
51
51
|
/** Epoch ms of the last record write; latest-wins tiebreak. */
|
|
52
52
|
updatedAt: number;
|
|
53
53
|
}
|
|
54
|
+
export declare function browserConnectionIdentity(browser: Pick<BrowserRecord, 'pid' | 'startedAt' | 'socketPath'>): string;
|
|
54
55
|
export declare function initBrowserRegistry(deps: {
|
|
55
56
|
log: (...args: any[]) => void;
|
|
56
57
|
}): void;
|
|
@@ -2,4 +2,8 @@ import { type ProviderHostContextData } from '@mearl/provider';
|
|
|
2
2
|
export declare function requestBrowserSocket(socketPath: string, action: string, data: Record<string, any>, version: string, timeoutMs?: number, browserId?: string, host?: ProviderHostContextData, routing?: {
|
|
3
3
|
providerTarget?: string;
|
|
4
4
|
controlSource?: string;
|
|
5
|
+
providerControlToken?: string;
|
|
6
|
+
providerSourceIdentity?: string;
|
|
7
|
+
providerPageId?: number;
|
|
8
|
+
deadline?: number;
|
|
5
9
|
}): Promise<any>;
|
|
@@ -1,66 +1,29 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { RequestCookie, RequestMetadata, ParsedSseEvent, RumEvent } from '@mearl/browser-core';
|
|
2
|
+
/** Protocol-specific fields remain opaque to the HTTP host. */
|
|
3
|
+
export interface ResolvedProtocolRequest {
|
|
4
4
|
requestData: unknown;
|
|
5
|
-
dataStr: string;
|
|
6
|
-
version: string;
|
|
7
5
|
normalizedMethod: 'GET' | 'POST';
|
|
8
|
-
|
|
6
|
+
timeout: number;
|
|
9
7
|
gatewayUrl: URL;
|
|
10
8
|
customHeaders: Record<string, string>;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
isMopen: boolean;
|
|
9
|
+
metadata?: RequestMetadata;
|
|
10
|
+
[key: string]: unknown;
|
|
14
11
|
}
|
|
15
|
-
export interface
|
|
12
|
+
export interface PreparedProtocolRequest extends ResolvedProtocolRequest {
|
|
16
13
|
targetUrl: URL;
|
|
17
14
|
requestHeaders: Record<string, string>;
|
|
18
15
|
cookieHeader: string;
|
|
19
16
|
body?: string;
|
|
20
17
|
}
|
|
21
|
-
export
|
|
22
|
-
|
|
23
|
-
startTimeMs: number;
|
|
24
|
-
lastMessageTimeMs?: number;
|
|
25
|
-
}
|
|
26
|
-
export interface MtopStreamCaptureStart {
|
|
27
|
-
id: number;
|
|
28
|
-
api: string;
|
|
18
|
+
export type { RequestStreamCapture as ProtocolStreamCapture, RequestStreamCaptureResponse as ProtocolStreamCaptureResponse } from '@mearl/browser-core';
|
|
19
|
+
export type ProtocolStreamCaptureStart = Omit<import('@mearl/browser-core').RequestStreamCaptureStart, 'url'> & {
|
|
29
20
|
url?: string;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}>;
|
|
35
|
-
requestData?: unknown;
|
|
36
|
-
timestampMs?: number;
|
|
37
|
-
tabId?: number;
|
|
38
|
-
captureSequence: number;
|
|
39
|
-
}
|
|
40
|
-
export interface MtopStreamCaptureResponse {
|
|
41
|
-
status: number;
|
|
42
|
-
statusText: string;
|
|
43
|
-
responseHeaders: Array<{
|
|
44
|
-
name: string;
|
|
45
|
-
value: string;
|
|
46
|
-
}>;
|
|
47
|
-
}
|
|
48
|
-
export interface MtopCapability {
|
|
49
|
-
resolveRequest(data: SendMtopRequestParams): ResolvedMtopRequest;
|
|
50
|
-
prepareRequest(resolved: ResolvedMtopRequest, cookies: Map<string, string>, stream?: boolean): PreparedSignedMtopRequest;
|
|
21
|
+
};
|
|
22
|
+
export interface RequestProtocolCapability {
|
|
23
|
+
resolveRequest(data: Record<string, unknown>): ResolvedProtocolRequest;
|
|
24
|
+
prepareRequest(resolved: ResolvedProtocolRequest, cookies: readonly RequestCookie[], stream?: boolean): PreparedProtocolRequest;
|
|
51
25
|
parseResponse(text: string): unknown;
|
|
52
26
|
consumeResponse(response: Response, onReceive: (event: ParsedSseEvent) => void | Promise<void>): Promise<unknown>;
|
|
53
|
-
createCapture(data: MtopStreamCaptureStart): MtopStreamCapture;
|
|
54
|
-
updateCapture(capture: MtopStreamCapture, response: MtopStreamCaptureResponse): void;
|
|
55
|
-
appendCapture(capture: MtopStreamCapture, data: unknown, timestampMs?: number): boolean;
|
|
56
|
-
finishCapture(capture: MtopStreamCapture, options?: {
|
|
57
|
-
timestampMs?: number;
|
|
58
|
-
error?: string;
|
|
59
|
-
}): void;
|
|
60
|
-
gateways: Array<{
|
|
61
|
-
prod: string;
|
|
62
|
-
pre: string;
|
|
63
|
-
}>;
|
|
64
27
|
}
|
|
65
28
|
export interface TrackingCapability {
|
|
66
29
|
matches(url: string): boolean;
|
|
@@ -69,5 +32,5 @@ export interface TrackingCapability {
|
|
|
69
32
|
now?: number;
|
|
70
33
|
}): RumEvent[];
|
|
71
34
|
}
|
|
72
|
-
export declare function
|
|
73
|
-
export declare function getTrackingCapability(): TrackingCapability
|
|
35
|
+
export declare function getRequestProtocolCapability(): RequestProtocolCapability;
|
|
36
|
+
export declare function getTrackingCapability(): TrackingCapability;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { RequestCookie, AppProfileDefinition } from '@mearl/browser-core';
|
|
2
|
+
import type { AgentProvider } from '@mearl/agent-runtime';
|
|
3
|
+
import type { BrowserSegmentedControl, PageRuntimeBinding } from '@mearl/preset/bundles';
|
|
4
|
+
import type { RequestProtocolCapability, TrackingCapability } from './capability-contracts.js';
|
|
5
|
+
import type { AgentSkillBackend } from './agent/skill-manager.js';
|
|
6
|
+
import type { SandboxBrowserAccessCapability, ResolvedSandboxBrowserAccess } from './sandbox-browser-access.js';
|
|
7
|
+
import type { CookieCopyPlan } from './cdp-backend/cookie-transfer.js';
|
|
8
|
+
import type { BuiltinBrowserLaunchOptions } from './builtin-provider-options.js';
|
|
9
|
+
export interface AppCapabilityCatalog {
|
|
10
|
+
namespace: string;
|
|
11
|
+
profiles: AppProfileDefinition[];
|
|
12
|
+
bindings: Record<string, string>;
|
|
13
|
+
order?: string[];
|
|
14
|
+
}
|
|
15
|
+
export type AgentCapabilityFactory = (options: {
|
|
16
|
+
log(message: string): void;
|
|
17
|
+
version: string;
|
|
18
|
+
}) => AgentProvider | Promise<AgentProvider>;
|
|
19
|
+
/** Host-owned contracts are defined once; providers implement these contracts. */
|
|
20
|
+
export interface NativeCapabilityHooks {
|
|
21
|
+
'request.protocol': () => RequestProtocolCapability;
|
|
22
|
+
'tracking.request': () => TrackingCapability;
|
|
23
|
+
'request.inspect': (input: {
|
|
24
|
+
url: string;
|
|
25
|
+
body?: string;
|
|
26
|
+
}) => unknown;
|
|
27
|
+
'app.profileCatalog': () => AppCapabilityCatalog;
|
|
28
|
+
'app.pageRuntime': (binding: PageRuntimeBinding) => string | undefined;
|
|
29
|
+
'app.defaultPageRuntime': () => PageRuntimeBinding;
|
|
30
|
+
'app.userInfo': (url: string, cookies: RequestCookie[]) => {
|
|
31
|
+
userId?: string;
|
|
32
|
+
userName?: string;
|
|
33
|
+
};
|
|
34
|
+
'browser.control': () => BrowserSegmentedControl;
|
|
35
|
+
'browser.access.capability': () => SandboxBrowserAccessCapability | null;
|
|
36
|
+
'browser.access.resolve': () => Promise<ResolvedSandboxBrowserAccess>;
|
|
37
|
+
'cookie.copyPlan': (input: BuiltinBrowserLaunchOptions['copyCookieDomains']) => CookieCopyPlan;
|
|
38
|
+
'plugins.catalog': () => unknown;
|
|
39
|
+
'skills.manager': () => AgentSkillBackend | undefined;
|
|
40
|
+
'analytics.endpoint': () => string;
|
|
41
|
+
[hook: `agent.provider.${string}`]: AgentCapabilityFactory;
|
|
42
|
+
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type ProtocolStreamCapture, type ProtocolStreamCaptureResponse, type ProtocolStreamCaptureStart } from '../capability-contracts.js';
|
|
2
2
|
/**
|
|
3
3
|
* In-memory circular buffers for CDP network requests, console logs, and
|
|
4
4
|
* RUM/tracking events. A single CdpSession subscribes to CDP events and
|
|
5
5
|
* fills these buffers; callers read from them without CDP interaction.
|
|
6
6
|
*/
|
|
7
7
|
import { TextDecoder } from 'node:util';
|
|
8
|
-
import type {
|
|
8
|
+
import type { CapturedRequest, RumEvent, ConsoleLog, RequestBufferAccounting } from '@mearl/browser-core';
|
|
9
9
|
import { type CaptureSequenceState, type SseEventParser } from '@mearl/browser-core';
|
|
10
10
|
import type { CdpClient, CdpChildSession } from './client.js';
|
|
11
|
-
interface PartialRequest extends
|
|
11
|
+
interface PartialRequest extends CapturedRequest {
|
|
12
12
|
id: number;
|
|
13
13
|
requestId: string;
|
|
14
14
|
timestamp: string;
|
|
@@ -43,11 +43,11 @@ interface CdpSseStream {
|
|
|
43
43
|
mode: 'eventsource' | 'resource' | 'fallback';
|
|
44
44
|
lastMessageTimeMs?: number;
|
|
45
45
|
}
|
|
46
|
-
export type
|
|
47
|
-
export type
|
|
48
|
-
export type
|
|
46
|
+
export type CdpProtocolStreamCapture = ProtocolStreamCapture;
|
|
47
|
+
export type CdpProtocolStreamStart = Omit<ProtocolStreamCaptureStart, 'id' | 'tabId' | 'captureSequence'>;
|
|
48
|
+
export type CdpProtocolStreamResponse = ProtocolStreamCaptureResponse;
|
|
49
49
|
export interface CdpBuffers {
|
|
50
|
-
requests:
|
|
50
|
+
requests: CapturedRequest[];
|
|
51
51
|
logs: ConsoleLog[];
|
|
52
52
|
events: RumEvent[];
|
|
53
53
|
pending: Map<string, PartialRequest>;
|
|
@@ -61,10 +61,10 @@ export interface CdpBuffers {
|
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
63
|
export declare function createBuffers(tabId?: number): CdpBuffers;
|
|
64
|
-
export declare function
|
|
65
|
-
export declare function
|
|
66
|
-
export declare function
|
|
67
|
-
export declare function
|
|
64
|
+
export declare function recordCdpProtocolStreamStart(buffers: CdpBuffers, data: CdpProtocolStreamStart): CdpProtocolStreamCapture;
|
|
65
|
+
export declare function recordCdpProtocolStreamResponse(buffers: CdpBuffers, capture: CdpProtocolStreamCapture, response: CdpProtocolStreamResponse): void;
|
|
66
|
+
export declare function recordCdpProtocolStreamChunk(buffers: CdpBuffers, capture: CdpProtocolStreamCapture, data: unknown, timestampMs?: number): void;
|
|
67
|
+
export declare function recordCdpProtocolStreamEnd(buffers: CdpBuffers, capture: CdpProtocolStreamCapture, options?: {
|
|
68
68
|
timestampMs?: number;
|
|
69
69
|
error?: string;
|
|
70
70
|
}): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -50,6 +50,7 @@ export declare class CdpSession {
|
|
|
50
50
|
private pageSessions;
|
|
51
51
|
private pageSessionPromises;
|
|
52
52
|
private pageSessionInitializers;
|
|
53
|
+
private pageInitialization;
|
|
53
54
|
/** Virtual tabId counter → CDP targetId */
|
|
54
55
|
private tabIdMap;
|
|
55
56
|
private nextTabId;
|
|
@@ -74,6 +75,7 @@ export declare class CdpSession {
|
|
|
74
75
|
attachOpenPageTargets(): Promise<void>;
|
|
75
76
|
private connectBrowserClient;
|
|
76
77
|
private createPageSession;
|
|
78
|
+
private preparePageSession;
|
|
77
79
|
private getOrCreatePageSession;
|
|
78
80
|
private findTargetById;
|
|
79
81
|
private findDefaultPageTarget;
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* Shared utilities for CDP backend handlers.
|
|
3
|
-
*
|
|
4
|
-
* Contains: HTTP helper (nodeFetch), cookie utilities, page-load waiters,
|
|
5
|
-
* viewport helpers, and serialized function sources for page injection.
|
|
6
|
-
*/
|
|
7
|
-
import { type PageClickPointerType, type PageDragPoint, type PageDragPointerType } from '@mearl/browser-core';
|
|
1
|
+
import { type CookieCandidate, type PageClickPointerType, type PageDragPoint, type PageDragPointerType } from '@mearl/browser-core';
|
|
8
2
|
import type { PageSession } from './cdp-session.js';
|
|
9
3
|
export declare const TYPE_INTO_ELEMENT_SRC: string;
|
|
10
4
|
export declare const CLICK_ELEMENT_VIA_JS_SRC: string;
|
|
@@ -21,8 +15,9 @@ export declare function nodeFetch(urlStr: string, options?: {
|
|
|
21
15
|
headers: Record<string, string>;
|
|
22
16
|
body: string;
|
|
23
17
|
bodyBuffer: Buffer;
|
|
18
|
+
setCookies: string[];
|
|
24
19
|
}>;
|
|
25
|
-
export declare function getCookiesForUrl(session: PageSession, targetUrl: string): Promise<
|
|
20
|
+
export declare function getCookiesForUrl(session: PageSession, targetUrl: string): Promise<CookieCandidate[]>;
|
|
26
21
|
export declare function buildMultipartFormBody(fields: Record<string, string>): {
|
|
27
22
|
contentType: string;
|
|
28
23
|
body: string;
|
|
@@ -8,6 +8,7 @@ import './request-handlers.js';
|
|
|
8
8
|
import './mock-handlers.js';
|
|
9
9
|
import './http-handlers.js';
|
|
10
10
|
import './browser-handlers.js';
|
|
11
|
+
import './capability-handlers.js';
|
|
11
12
|
import './rule-handlers.js';
|
|
12
13
|
import './tab-handlers.js';
|
|
13
14
|
import './interaction-handlers.js';
|
|
@@ -19,7 +20,7 @@ import './composite-handlers.js';
|
|
|
19
20
|
export { dispatchCdpAction, getRegisteredActionNames } from './action-registry.js';
|
|
20
21
|
export { cdpGetRequests, cdpGetLogs, cdpGetEvents } from './request-handlers.js';
|
|
21
22
|
export { cdpSetMock, cdpGetMocks } from './mock-handlers.js';
|
|
22
|
-
export { cdpSendRequest,
|
|
23
|
+
export { cdpSendRequest, cdpSendProtocolRequest } from './http-handlers.js';
|
|
23
24
|
export { cdpPageScreenshot } from './browser-handlers.js';
|
|
24
25
|
export { cdpTabOpen, cdpTabClose, cdpTabList } from './tab-handlers.js';
|
|
25
26
|
export { cdpPageClick, cdpPageType, cdpPageScroll, cdpPageInspect, cdpPageEval, cdpPagePress, cdpPageWait, cdpPageNavigate, cdpPageUpload, cdpSetDeviceEmulation, } from './interaction-handlers.js';
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
+
import { type ResponseCookieSync } from './response-cookies.js';
|
|
1
2
|
/**
|
|
2
|
-
* CDP HTTP proxy /
|
|
3
|
+
* CDP HTTP proxy / PROTOCOL request / API schema handlers.
|
|
3
4
|
*/
|
|
4
|
-
import type
|
|
5
|
+
import { type RequestMetadata, SendRequestParams } from '@mearl/browser-core';
|
|
5
6
|
import type { PageSession } from './cdp-session.js';
|
|
6
|
-
export interface
|
|
7
|
+
export interface CdpProtocolStreamRequestMetadata {
|
|
7
8
|
method: 'GET' | 'POST';
|
|
8
9
|
url: string;
|
|
9
10
|
requestHeaders: Array<{
|
|
10
11
|
name: string;
|
|
11
12
|
value: string;
|
|
12
13
|
}>;
|
|
14
|
+
metadata?: RequestMetadata;
|
|
13
15
|
}
|
|
14
|
-
export interface
|
|
16
|
+
export interface CdpProtocolStreamResponseMetadata {
|
|
15
17
|
status: number;
|
|
16
18
|
statusText: string;
|
|
17
19
|
responseHeaders: Array<{
|
|
@@ -19,15 +21,16 @@ export interface CdpMtopStreamResponseMetadata {
|
|
|
19
21
|
value: string;
|
|
20
22
|
}>;
|
|
21
23
|
}
|
|
22
|
-
export interface
|
|
23
|
-
onRequestPrepared?: (metadata:
|
|
24
|
-
onResponse?: (metadata:
|
|
24
|
+
export interface CdpProtocolStreamCallbacks {
|
|
25
|
+
onRequestPrepared?: (metadata: CdpProtocolStreamRequestMetadata) => void | Promise<void>;
|
|
26
|
+
onResponse?: (metadata: CdpProtocolStreamResponseMetadata) => void | Promise<void>;
|
|
25
27
|
onReceive: (data: unknown) => void | Promise<void>;
|
|
26
28
|
}
|
|
27
29
|
export declare function cdpSendRequest(session: PageSession, data: SendRequestParams): Promise<any>;
|
|
28
|
-
export declare function
|
|
29
|
-
export declare function
|
|
30
|
+
export declare function cdpSendProtocolRequest(session: PageSession, data: Record<string, unknown>): Promise<any>;
|
|
31
|
+
export declare function cdpSendProtocolStreamRequest(session: PageSession, data: Record<string, unknown>, callbacks: CdpProtocolStreamCallbacks): Promise<{
|
|
30
32
|
success: true;
|
|
31
33
|
response: unknown;
|
|
32
34
|
requestData: unknown;
|
|
35
|
+
cookieSync?: ResponseCookieSync;
|
|
33
36
|
}>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { NetworkControlSelection } from '@mearl/browser-core';
|
|
2
|
+
import type { PageSession } from './cdp-session.js';
|
|
3
|
+
export declare function setCdpNetworkControl(session: PageSession, selection: NetworkControlSelection | null): Promise<void>;
|
|
4
|
+
export declare function getCdpNetworkControl(session: PageSession): NetworkControlSelection | undefined;
|
|
5
|
+
export declare function clearCdpNetworkControlState(sessions?: Iterable<PageSession>): void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PageDialogState } from '@mearl/browser-core';
|
|
2
|
+
import type { PageSession } from './cdp-session.js';
|
|
3
|
+
import type { CdpClient, CdpChildSession } from './client.js';
|
|
4
|
+
type Client = CdpClient | CdpChildSession;
|
|
5
|
+
export declare function getCdpPageDialogs(session: PageSession): PageDialogState;
|
|
6
|
+
/** A temporary frame connection that owns a modal must survive until its handling ack. */
|
|
7
|
+
export declare function deferCdpDialogCleanup(session: PageSession, cleanup: () => void): void;
|
|
8
|
+
/** Subscribe before Page.enable, including on temporary frame sessions. */
|
|
9
|
+
export declare function monitorCdpPageDialogs(session: PageSession, client?: CdpChildSession | CdpClient): () => void;
|
|
10
|
+
/** Only page execution goes through this gate; lifecycle and Fetch cleanup remain independent. */
|
|
11
|
+
export declare function sendCdpPageCommand(session: PageSession, client: Pick<Client, 'sendCommand'>, method: string, params?: Record<string, any>, timeoutMs?: number, onDispatch?: () => void): Promise<any>;
|
|
12
|
+
export declare function snapshotCdpPageDialog(session: PageSession, data: any): any;
|
|
13
|
+
export declare function pressCdpPageDialog(session: PageSession, data: any): Promise<any>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type CookieCandidate } from '@mearl/browser-core';
|
|
2
|
+
/** Background proxy requests use the target URL's first-party, schemeful site. */
|
|
3
|
+
export declare function getRequestCookiePartition(url: string): {
|
|
4
|
+
topLevelSite: string;
|
|
5
|
+
hasCrossSiteAncestor: false;
|
|
6
|
+
};
|
|
7
|
+
/** Keep ordinary cookies and only the target site's first-party partition. */
|
|
8
|
+
export declare function selectRequestCookies<T extends CookieCandidate>(cookies: readonly T[], url: string): T[];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { PageSession } from './cdp-session.js';
|
|
2
|
+
export interface ResponseCookieSync {
|
|
3
|
+
updatedCount: number;
|
|
4
|
+
rejectedCount: number;
|
|
5
|
+
failedCount: number;
|
|
6
|
+
}
|
|
7
|
+
/** Apply response cookies to the same browser context that supplied the request's credentials. */
|
|
8
|
+
export declare function syncResponseCookies(session: PageSession, url: string, headers: readonly string[]): Promise<ResponseCookieSync | undefined>;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import { type SendRequestParams } from '@mearl/browser-core';
|
|
2
|
-
|
|
1
|
+
import { type RequestCookie, type SendRequestParams } from '@mearl/browser-core';
|
|
2
|
+
import type { ResponseCookieSync } from './response-cookies.js';
|
|
3
|
+
export declare function executeNodeSendRequest(data: SendRequestParams, cookies?: readonly RequestCookie[], onResponseCookies?: (url: string, headers: readonly string[]) => Promise<ResponseCookieSync | undefined>): Promise<any>;
|
|
@@ -6,7 +6,7 @@ interface Dependencies {
|
|
|
6
6
|
transport: () => ControlSessionInfo['transport'];
|
|
7
7
|
invoke: (action: string, data: any, transport: ControlSessionInfo['transport']) => Promise<any>;
|
|
8
8
|
deactivate?: (tabs: number[], transport: ControlSessionInfo['transport']) => Promise<void>;
|
|
9
|
-
cleanup: (tabs: number[], transport: ControlSessionInfo['transport'], preserveEnvironment: boolean) => Promise<void>;
|
|
9
|
+
cleanup: (tabs: number[], transport: ControlSessionInfo['transport'], preserveEnvironment: boolean, returningToAgent?: boolean) => Promise<void>;
|
|
10
10
|
download: (data: PageDownloadParams, transport: ControlSessionInfo['transport'], origin: string) => Promise<{
|
|
11
11
|
filename: string;
|
|
12
12
|
filePath: string;
|