@howaboua/pi-durable-browser 0.0.0-stage → 0.9.1
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/LICENSE +21 -0
- package/NOTICE +52 -0
- package/README.md +86 -2
- package/dist/browser/artifact-store.d.ts +16 -0
- package/dist/browser/artifacts.d.ts +20 -0
- package/dist/browser/bounds.d.ts +4 -0
- package/dist/browser/config-store.d.ts +11 -0
- package/dist/browser/config.d.ts +7 -0
- package/dist/browser/help.d.ts +1 -0
- package/dist/browser/launcher.d.ts +1 -0
- package/dist/browser/operation-executor.d.ts +12 -0
- package/dist/browser/operation-input.d.ts +10 -0
- package/dist/browser/operation.d.ts +115 -0
- package/dist/browser/parse-operation.d.ts +6 -0
- package/dist/browser/parse-tab-operation.d.ts +3 -0
- package/dist/browser/remote-helper.d.ts +3 -0
- package/dist/browser/remote-process.d.ts +6 -0
- package/dist/browser/remote.d.ts +4 -0
- package/dist/browser/request.d.ts +8 -0
- package/dist/browser/routes.d.ts +15 -0
- package/dist/browser/runtime.d.ts +35 -0
- package/dist/browser/voice-start.d.ts +17 -0
- package/dist/browser/worker-client.d.ts +1 -0
- package/dist/browser/worker-server.d.ts +1 -0
- package/dist/browser/worker-socket.d.ts +11 -0
- package/dist/cdp/accessibility-snapshot.d.ts +11 -0
- package/dist/cdp/actions/click.d.ts +6 -0
- package/dist/cdp/actions/element.d.ts +22 -0
- package/dist/cdp/actions/fill.d.ts +8 -0
- package/dist/cdp/actions/key.d.ts +20 -0
- package/dist/cdp/actions/page.d.ts +7 -0
- package/dist/cdp/actions/screenshot.d.ts +14 -0
- package/dist/cdp/actions/selector.d.ts +2 -0
- package/dist/cdp/actions/type.d.ts +3 -0
- package/dist/cdp/actions/wait.d.ts +9 -0
- package/dist/cdp/client.d.ts +20 -0
- package/dist/cdp/discovery.d.ts +7 -0
- package/dist/cdp/evaluate.d.ts +3 -0
- package/dist/cdp/pages.d.ts +4 -0
- package/dist/cdp/serial.d.ts +1 -0
- package/dist/cdp/session.d.ts +27 -0
- package/dist/cdp/snapshot-contract.d.ts +38 -0
- package/dist/cdp/snapshot.d.ts +3 -0
- package/dist/cdp/tab-bridge.d.ts +26 -0
- package/dist/cdp/tabs.d.ts +32 -0
- package/dist/cdp/types.d.ts +22 -0
- package/dist/cdp/url.d.ts +1 -0
- package/dist/index.d.ts +119 -0
- package/dist/index.js +3951 -0
- package/dist/presentation.d.ts +43 -0
- package/dist/presentation.js +82 -0
- package/dist/remote-worker.d.ts +2 -0
- package/dist/remote-worker.js +3850 -0
- package/package.json +43 -5
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { CdpConnection, CdpEventWait, CdpParams } from "./types.ts";
|
|
2
|
+
type EventHandler = (params: unknown) => void;
|
|
3
|
+
export declare class CdpClient implements CdpConnection {
|
|
4
|
+
private socket;
|
|
5
|
+
private nextId;
|
|
6
|
+
private readonly pending;
|
|
7
|
+
private readonly eventHandlers;
|
|
8
|
+
private readonly closeHandlers;
|
|
9
|
+
connect(url: string, signal?: AbortSignal): Promise<void>;
|
|
10
|
+
send(method: string, params?: CdpParams, sessionId?: string, signal?: AbortSignal): Promise<unknown>;
|
|
11
|
+
onEvent(method: string, handler: EventHandler): () => void;
|
|
12
|
+
waitForEvent(method: string, timeout?: number, signal?: AbortSignal): CdpEventWait;
|
|
13
|
+
onClose(handler: () => void): () => void;
|
|
14
|
+
close(): void;
|
|
15
|
+
private sendOnce;
|
|
16
|
+
private handleMessage;
|
|
17
|
+
private finishPending;
|
|
18
|
+
private handleClose;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const CDP_TIMEOUT_MS = 15000;
|
|
2
|
+
export declare const NAVIGATION_TIMEOUT_MS = 30000;
|
|
3
|
+
export declare function probeDebugPort(port: string, host?: string, signal?: AbortSignal): Promise<string>;
|
|
4
|
+
export declare function getWebSocketUrl(signal?: AbortSignal, recovery?: string): Promise<string>;
|
|
5
|
+
export declare function sleep(ms: number, signal?: AbortSignal): Promise<void>;
|
|
6
|
+
export declare function resolvePrefix(prefix: string, candidates: string[], noun?: string, missingHint?: string): string;
|
|
7
|
+
export declare function getDisplayPrefixLength(targetIds: string[]): number;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { CdpConnection } from "./types.ts";
|
|
2
|
+
export declare function evaluate(cdp: CdpConnection, sessionId: string, expression: string, signal?: AbortSignal): Promise<unknown>;
|
|
3
|
+
export declare function evaluateText(cdp: CdpConnection, sessionId: string, expression: string, signal?: AbortSignal): Promise<string>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CdpConnection, PageInfo } from "./types.ts";
|
|
2
|
+
export declare function getPageTargets(cdp: CdpConnection, signal?: AbortSignal): Promise<PageInfo[]>;
|
|
3
|
+
export declare function getDisplayedPages(targets: PageInfo[]): PageInfo[];
|
|
4
|
+
export declare function waitForOpenedTarget(cdp: CdpConnection, targetId: string, requestedUrl: string, timeout?: number, signal?: AbortSignal): Promise<PageInfo>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function waitForTurn<T>(promise: Promise<T>, signal?: AbortSignal): Promise<T>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { getWebSocketUrl } from "./discovery.ts";
|
|
2
|
+
import { type ActiveTab } from "./tab-bridge.ts";
|
|
3
|
+
import type { PageInfo } from "./types.ts";
|
|
4
|
+
export declare class BrowserCdpSession {
|
|
5
|
+
private closing;
|
|
6
|
+
private root;
|
|
7
|
+
private rootPending;
|
|
8
|
+
private readonly ownerId;
|
|
9
|
+
private readonly ownershipDirectory;
|
|
10
|
+
private readonly tabs;
|
|
11
|
+
private readonly tabPromises;
|
|
12
|
+
private readonly discover;
|
|
13
|
+
constructor(ownerId: string, ownershipDirectory: string, discover?: typeof getWebSocketUrl);
|
|
14
|
+
pages(signal?: AbortSignal): Promise<PageInfo[]>;
|
|
15
|
+
open(url: string, signal?: AbortSignal): Promise<{
|
|
16
|
+
refId: string;
|
|
17
|
+
}>;
|
|
18
|
+
show(refId: string, signal?: AbortSignal): Promise<string>;
|
|
19
|
+
closeTab(refId: string, signal?: AbortSignal): Promise<string>;
|
|
20
|
+
withTab<T>(refId: string, signal: AbortSignal | undefined, action: (tab: ActiveTab) => Promise<T>, rendering?: "background" | "foreground"): Promise<T>;
|
|
21
|
+
stop(refId?: string): Promise<void>;
|
|
22
|
+
close(): Promise<void>;
|
|
23
|
+
private rootConnection;
|
|
24
|
+
private connectTab;
|
|
25
|
+
private stopPendingTab;
|
|
26
|
+
private connectRoot;
|
|
27
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export type SnapshotResponseLength = "short" | "medium" | "long";
|
|
2
|
+
export declare const SNAPSHOT_LIMITS: Record<SnapshotResponseLength, number>;
|
|
3
|
+
export interface SnapshotLine {
|
|
4
|
+
line: number;
|
|
5
|
+
text: string;
|
|
6
|
+
element_id?: number | undefined;
|
|
7
|
+
}
|
|
8
|
+
export interface SnapshotElement {
|
|
9
|
+
id: number;
|
|
10
|
+
role: string;
|
|
11
|
+
name?: string | undefined;
|
|
12
|
+
href?: string | undefined;
|
|
13
|
+
href_omitted?: true | undefined;
|
|
14
|
+
value?: unknown;
|
|
15
|
+
checked?: boolean | "mixed" | undefined;
|
|
16
|
+
selected?: boolean | undefined;
|
|
17
|
+
expanded?: boolean | undefined;
|
|
18
|
+
disabled?: boolean | undefined;
|
|
19
|
+
}
|
|
20
|
+
export interface SnapshotResult {
|
|
21
|
+
ref_id?: string | undefined;
|
|
22
|
+
title: string;
|
|
23
|
+
url: string;
|
|
24
|
+
lineno: number;
|
|
25
|
+
content: SnapshotLine[];
|
|
26
|
+
elements: SnapshotElement[];
|
|
27
|
+
pattern?: string | undefined;
|
|
28
|
+
next_lineno?: number | undefined;
|
|
29
|
+
}
|
|
30
|
+
export interface SnapshotOptions {
|
|
31
|
+
refId?: string | undefined;
|
|
32
|
+
pattern?: string | undefined;
|
|
33
|
+
lineno?: number | string | undefined;
|
|
34
|
+
responseLength?: SnapshotResponseLength | string | undefined;
|
|
35
|
+
signal?: AbortSignal | undefined;
|
|
36
|
+
}
|
|
37
|
+
export declare function positiveInteger(value: number | string, label: string): number;
|
|
38
|
+
export declare function snapshotResponseLength(value: string | undefined): SnapshotResponseLength;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type SnapshotOptions, type SnapshotResult } from "./snapshot-contract.ts";
|
|
2
|
+
import type { CdpConnection, ElementRefs } from "./types.ts";
|
|
3
|
+
export declare function snapshotData(cdp: CdpConnection, sessionId: string, elementRefs: ElementRefs, options?: SnapshotOptions): Promise<SnapshotResult>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { CdpClient } from "./client.ts";
|
|
2
|
+
import type { ElementRefs } from "./types.ts";
|
|
3
|
+
export interface ActiveTab {
|
|
4
|
+
cdp: CdpClient;
|
|
5
|
+
sessionId: string;
|
|
6
|
+
elementRefs: ElementRefs;
|
|
7
|
+
refId: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class TabBridge {
|
|
10
|
+
readonly elementRefs: ElementRefs;
|
|
11
|
+
readonly targetId: string;
|
|
12
|
+
readonly cdp: CdpClient;
|
|
13
|
+
readonly sessionId: string;
|
|
14
|
+
private tail;
|
|
15
|
+
private idleTimer;
|
|
16
|
+
private closed;
|
|
17
|
+
private closing;
|
|
18
|
+
private backgroundRendering;
|
|
19
|
+
private readonly onClose;
|
|
20
|
+
private constructor();
|
|
21
|
+
static connect(targetId: string, onClose: () => void, signal: AbortSignal | undefined, discover: (signal?: AbortSignal) => Promise<string>): Promise<TabBridge>;
|
|
22
|
+
run<T>(refId: string, signal: AbortSignal | undefined, action: (tab: ActiveTab) => Promise<T>): Promise<T>;
|
|
23
|
+
setBackgroundRendering(enabled: boolean, signal?: AbortSignal): Promise<void>;
|
|
24
|
+
close(detach?: boolean): Promise<void>;
|
|
25
|
+
private resetIdle;
|
|
26
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { CdpConnection, PageInfo } from "./types.ts";
|
|
2
|
+
export declare class BrowserTabs {
|
|
3
|
+
private readonly cdp;
|
|
4
|
+
private readonly directory;
|
|
5
|
+
private readonly ownershipDirectory;
|
|
6
|
+
private readonly scope;
|
|
7
|
+
private tail;
|
|
8
|
+
private closed;
|
|
9
|
+
private prepared;
|
|
10
|
+
constructor(cdp: CdpConnection, ownerId: string, directory: string, browserUrl: string);
|
|
11
|
+
list(signal?: AbortSignal): Promise<PageInfo[]>;
|
|
12
|
+
shutdown(): Promise<void>;
|
|
13
|
+
private enqueue;
|
|
14
|
+
private listNow;
|
|
15
|
+
resolve(refId: string, signal?: AbortSignal): Promise<{
|
|
16
|
+
page: PageInfo;
|
|
17
|
+
refId: string;
|
|
18
|
+
}>;
|
|
19
|
+
open(url: string, signal?: AbortSignal): Promise<{
|
|
20
|
+
refId: string;
|
|
21
|
+
}>;
|
|
22
|
+
show(refId: string, signal?: AbortSignal): Promise<string>;
|
|
23
|
+
close(refId: string, signal?: AbortSignal): Promise<{
|
|
24
|
+
targetId: string;
|
|
25
|
+
refId: string;
|
|
26
|
+
}>;
|
|
27
|
+
private targetPath;
|
|
28
|
+
private readOwned;
|
|
29
|
+
private touchDirectory;
|
|
30
|
+
private remember;
|
|
31
|
+
private forget;
|
|
32
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type CdpParams = Record<string, unknown>;
|
|
2
|
+
export interface CdpEventWait {
|
|
3
|
+
promise: Promise<unknown>;
|
|
4
|
+
cancel(): void;
|
|
5
|
+
}
|
|
6
|
+
export interface CdpConnection {
|
|
7
|
+
send(method: string, params?: CdpParams, sessionId?: string, signal?: AbortSignal): Promise<unknown>;
|
|
8
|
+
onEvent(method: string, handler: (params: unknown) => void): () => void;
|
|
9
|
+
waitForEvent(method: string, timeout?: number, signal?: AbortSignal): CdpEventWait;
|
|
10
|
+
}
|
|
11
|
+
export interface PageInfo {
|
|
12
|
+
targetId: string;
|
|
13
|
+
title: string;
|
|
14
|
+
url: string;
|
|
15
|
+
type?: string;
|
|
16
|
+
openerId?: string;
|
|
17
|
+
owned?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export type ElementRefs = Map<number, number>;
|
|
20
|
+
export declare function asRecord(value: unknown, label?: string): Record<string, unknown>;
|
|
21
|
+
export declare function asString(value: unknown, label: string): string;
|
|
22
|
+
export declare function errorMessage(error: unknown): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function assertHttpUrl(value: string): void;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { JsonValue } from "@earendil-works/chord";
|
|
2
|
+
import { Type } from "@earendil-works/pi-ai";
|
|
3
|
+
import { BrowserRuntime, type BrowserRuntimeConfig } from "./browser/runtime.ts";
|
|
4
|
+
export { type BrowserArtifactStore, environmentArtifactStore, nodeArtifactStore, } from "./browser/artifact-store.ts";
|
|
5
|
+
export { type BrowserRouteConfig, normalizeBrowserRouteConfig, } from "./browser/config.ts";
|
|
6
|
+
export { type BrowserRouteConfigStore, createBrowserRouteConfigFileStore, readBrowserRouteConfig, writeBrowserRouteConfig, } from "./browser/config-store.ts";
|
|
7
|
+
export type { BrowserOperation } from "./browser/operation.ts";
|
|
8
|
+
export { type BrowserRequest, parseBrowserRequest } from "./browser/request.ts";
|
|
9
|
+
export { BrowserRoutes, parseBrowserRoutes } from "./browser/routes.ts";
|
|
10
|
+
export { type BrowserExecutionOptions, BrowserRuntime, type BrowserRuntimeConfig, } from "./browser/runtime.ts";
|
|
11
|
+
export { type BrowserVoiceStartOptions, type BrowserVoiceStartResult, startBrowserVoice, } from "./browser/voice-start.ts";
|
|
12
|
+
export declare function prepareBrowserInput(input: unknown): {
|
|
13
|
+
command: string;
|
|
14
|
+
};
|
|
15
|
+
export interface BrowserToolOptions {
|
|
16
|
+
/** Keep native voice automation available without exposing the agent tool. */
|
|
17
|
+
voiceOnly?: boolean;
|
|
18
|
+
/** Artifact directory inside api.env, relative to that environment's cwd. */
|
|
19
|
+
environmentArtifactDirectory?: string;
|
|
20
|
+
}
|
|
21
|
+
export declare function createBrowserTool(runtime: BrowserRuntime, options?: BrowserToolOptions): {
|
|
22
|
+
name: string;
|
|
23
|
+
description: string;
|
|
24
|
+
parameters: Type.TObject<{
|
|
25
|
+
command: Type.TOptional<Type.TString>;
|
|
26
|
+
}>;
|
|
27
|
+
constrainedSampling?: false | import("@earendil-works/pi-ai").ConstrainedSamplingConfig;
|
|
28
|
+
replay?: "safe" | "unsafe";
|
|
29
|
+
executionMode?: import("@earendil-works/pi-durable").ToolExecutionMode;
|
|
30
|
+
prepareArguments?(args: unknown): {
|
|
31
|
+
command?: string;
|
|
32
|
+
};
|
|
33
|
+
structuredOutputSchema?: Type.TSchema;
|
|
34
|
+
callers?: readonly ("model" | "tools")[];
|
|
35
|
+
deferred?: true;
|
|
36
|
+
outputLimits?: {
|
|
37
|
+
readonly maxBytes?: number;
|
|
38
|
+
readonly maxLines?: number;
|
|
39
|
+
readonly retain?: "head" | "tail";
|
|
40
|
+
};
|
|
41
|
+
execute(args: {
|
|
42
|
+
command?: string;
|
|
43
|
+
}, api: import("@earendil-works/pi-durable").ToolExecutionApi<JsonValue>, context: import("@earendil-works/chord").Context): Promise<import("@earendil-works/pi-durable").ToolExecutionResult<JsonValue>>;
|
|
44
|
+
executionHints: {
|
|
45
|
+
discovery: "help";
|
|
46
|
+
inputSchema: {
|
|
47
|
+
type: string;
|
|
48
|
+
additionalProperties: boolean;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
/** The host explicitly authorizes native CDP, launch, SSH and private state IO.
|
|
53
|
+
* The host must await close() before discarding this process-local runtime. */
|
|
54
|
+
export declare function createBrowserExtension(config: BrowserRuntimeConfig & BrowserToolOptions): {
|
|
55
|
+
runtime: BrowserRuntime;
|
|
56
|
+
tool: {
|
|
57
|
+
name: string;
|
|
58
|
+
description: string;
|
|
59
|
+
parameters: Type.TObject<{
|
|
60
|
+
command: Type.TOptional<Type.TString>;
|
|
61
|
+
}>;
|
|
62
|
+
constrainedSampling?: false | import("@earendil-works/pi-ai").ConstrainedSamplingConfig;
|
|
63
|
+
replay?: "safe" | "unsafe";
|
|
64
|
+
executionMode?: import("@earendil-works/pi-durable").ToolExecutionMode;
|
|
65
|
+
prepareArguments?(args: unknown): {
|
|
66
|
+
command?: string;
|
|
67
|
+
};
|
|
68
|
+
structuredOutputSchema?: Type.TSchema;
|
|
69
|
+
callers?: readonly ("model" | "tools")[];
|
|
70
|
+
deferred?: true;
|
|
71
|
+
outputLimits?: {
|
|
72
|
+
readonly maxBytes?: number;
|
|
73
|
+
readonly maxLines?: number;
|
|
74
|
+
readonly retain?: "head" | "tail";
|
|
75
|
+
};
|
|
76
|
+
execute(args: {
|
|
77
|
+
command?: string;
|
|
78
|
+
}, api: import("@earendil-works/pi-durable").ToolExecutionApi<JsonValue>, context: import("@earendil-works/chord").Context): Promise<import("@earendil-works/pi-durable").ToolExecutionResult<JsonValue>>;
|
|
79
|
+
executionHints: {
|
|
80
|
+
discovery: "help";
|
|
81
|
+
inputSchema: {
|
|
82
|
+
type: string;
|
|
83
|
+
additionalProperties: boolean;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
extension: import("@earendil-works/pi-durable").Extension<{
|
|
88
|
+
name: string;
|
|
89
|
+
description: string;
|
|
90
|
+
parameters: Type.TObject<{
|
|
91
|
+
command: Type.TOptional<Type.TString>;
|
|
92
|
+
}>;
|
|
93
|
+
constrainedSampling?: false | import("@earendil-works/pi-ai").ConstrainedSamplingConfig;
|
|
94
|
+
replay?: "safe" | "unsafe";
|
|
95
|
+
executionMode?: import("@earendil-works/pi-durable").ToolExecutionMode;
|
|
96
|
+
prepareArguments?(args: unknown): {
|
|
97
|
+
command?: string;
|
|
98
|
+
};
|
|
99
|
+
structuredOutputSchema?: Type.TSchema;
|
|
100
|
+
callers?: readonly ("model" | "tools")[];
|
|
101
|
+
deferred?: true;
|
|
102
|
+
outputLimits?: {
|
|
103
|
+
readonly maxBytes?: number;
|
|
104
|
+
readonly maxLines?: number;
|
|
105
|
+
readonly retain?: "head" | "tail";
|
|
106
|
+
};
|
|
107
|
+
execute(args: {
|
|
108
|
+
command?: string;
|
|
109
|
+
}, api: import("@earendil-works/pi-durable").ToolExecutionApi<JsonValue>, context: import("@earendil-works/chord").Context): Promise<import("@earendil-works/pi-durable").ToolExecutionResult<JsonValue>>;
|
|
110
|
+
executionHints: {
|
|
111
|
+
discovery: "help";
|
|
112
|
+
inputSchema: {
|
|
113
|
+
type: string;
|
|
114
|
+
additionalProperties: boolean;
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
}>;
|
|
118
|
+
close: () => Promise<void>;
|
|
119
|
+
};
|