@alfe.ai/browser 0.0.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.cjs +600 -0
- package/dist/index.d.cts +232 -0
- package/dist/index.d.ts +232 -0
- package/dist/index.js +574 -0
- package/package.json +30 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { Page } from "puppeteer-core";
|
|
2
|
+
|
|
3
|
+
//#region ../remote/dist/index.d.ts
|
|
4
|
+
|
|
5
|
+
declare const RemoteFrameType: {
|
|
6
|
+
/** viewer→plugin: a viewer attached. Payload: SessionOpenPayload. */
|
|
7
|
+
readonly SESSION_OPEN: 1;
|
|
8
|
+
/** either direction: a viewer detached / session torn down. */
|
|
9
|
+
readonly SESSION_CLOSE: 2;
|
|
10
|
+
/** plugin→viewer: current surface state. Payload: SessionStatePayload. */
|
|
11
|
+
readonly SESSION_STATE: 3;
|
|
12
|
+
/** plugin→viewer (browser): the page navigated. Payload: { url }. */
|
|
13
|
+
readonly NAVIGATION: 4;
|
|
14
|
+
/** plugin→viewer: [metaLen:u16BE][meta JSON][raw JPEG]. */
|
|
15
|
+
readonly SCREENCAST_FRAME: 16;
|
|
16
|
+
/** viewer→plugin: { frameSeq } — drives ack-gated backpressure. */
|
|
17
|
+
readonly SCREENCAST_ACK: 17;
|
|
18
|
+
readonly INPUT_MOUSE: 32;
|
|
19
|
+
readonly INPUT_WHEEL: 33;
|
|
20
|
+
readonly INPUT_KEY: 34;
|
|
21
|
+
/** viewer→plugin: { width, height, dpr }. */
|
|
22
|
+
readonly RESIZE: 35;
|
|
23
|
+
readonly TAKEOVER_REQUEST: 48;
|
|
24
|
+
readonly TAKEOVER_GRANTED: 49;
|
|
25
|
+
readonly TAKEOVER_DENIED: 50;
|
|
26
|
+
readonly RELEASE_CONTROL: 51;
|
|
27
|
+
readonly CONTROL_REVOKED: 52;
|
|
28
|
+
/** plugin→viewer: raw PTY output bytes. */
|
|
29
|
+
readonly TERMINAL_DATA: 64;
|
|
30
|
+
/** viewer→plugin: raw keystroke bytes. */
|
|
31
|
+
readonly TERMINAL_INPUT: 65;
|
|
32
|
+
/** viewer→plugin: { cols, rows }. */
|
|
33
|
+
readonly TERMINAL_RESIZE: 66;
|
|
34
|
+
};
|
|
35
|
+
type RemoteFrameType = (typeof RemoteFrameType)[keyof typeof RemoteFrameType];
|
|
36
|
+
type RemoteSurface = "browser" | "terminal";
|
|
37
|
+
interface RemoteFrame {
|
|
38
|
+
type: RemoteFrameType;
|
|
39
|
+
sessionId: number;
|
|
40
|
+
payload: Buffer;
|
|
41
|
+
}
|
|
42
|
+
interface SessionOpenPayload {
|
|
43
|
+
surface: RemoteSurface;
|
|
44
|
+
/** Browser: initial viewport in device pixels. */
|
|
45
|
+
width?: number;
|
|
46
|
+
height?: number;
|
|
47
|
+
dpr?: number;
|
|
48
|
+
/** Terminal: initial PTY dimensions. */
|
|
49
|
+
cols?: number;
|
|
50
|
+
rows?: number;
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/surface.d.ts
|
|
54
|
+
interface SurfaceHandler {
|
|
55
|
+
/** Which surface this handler serves. */
|
|
56
|
+
readonly surface: RemoteSurface;
|
|
57
|
+
/** A viewer attached — open the surface for this session. */
|
|
58
|
+
openSession(sessionId: number, open: SessionOpenPayload): void | Promise<void>;
|
|
59
|
+
/** A subsequent frame for one of this handler's sessions (not SESSION_OPEN). */
|
|
60
|
+
handleFrame(frame: RemoteFrame): void;
|
|
61
|
+
/** The viewer detached — tear down this session's resources. */
|
|
62
|
+
closeSession(sessionId: number): void;
|
|
63
|
+
}
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region src/types.d.ts
|
|
66
|
+
interface Logger {
|
|
67
|
+
info(msg: string, ...args: unknown[]): void;
|
|
68
|
+
warn(msg: string, ...args: unknown[]): void;
|
|
69
|
+
error(msg: string, ...args: unknown[]): void;
|
|
70
|
+
debug(msg: string, ...args: unknown[]): void;
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/turn-controller.d.ts
|
|
74
|
+
/**
|
|
75
|
+
* TurnController — the write-mutex between agent automation and a human during
|
|
76
|
+
* a browser co-browse handoff. The plugin owns the single CDP session, so this
|
|
77
|
+
* lives plugin-side; the relay only forwards the control frames.
|
|
78
|
+
*
|
|
79
|
+
* Only *writes* are gated — screencast reads always flow so the human sees the
|
|
80
|
+
* live page regardless of who holds the token. Agent automation ops call
|
|
81
|
+
* `acquireAgent()` and park while the human is in control; the human's input is
|
|
82
|
+
* injected only while `owner === 'human'`.
|
|
83
|
+
*/
|
|
84
|
+
type TurnOwner = "agent" | "human";
|
|
85
|
+
interface TurnControllerOptions {
|
|
86
|
+
/** Fired whenever ownership changes, so the plugin can emit SESSION_STATE. */
|
|
87
|
+
onOwnerChange?: (owner: TurnOwner) => void;
|
|
88
|
+
}
|
|
89
|
+
declare class TurnController {
|
|
90
|
+
private owner;
|
|
91
|
+
private waiters;
|
|
92
|
+
private readonly onOwnerChange?;
|
|
93
|
+
constructor(options?: TurnControllerOptions);
|
|
94
|
+
get currentOwner(): TurnOwner;
|
|
95
|
+
get humanInControl(): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Resolve once the agent is (again) allowed to drive. Resolves immediately if
|
|
98
|
+
* the agent already holds the token; otherwise parks until `releaseHuman()`.
|
|
99
|
+
* Every automation op awaits this before touching the page.
|
|
100
|
+
*/
|
|
101
|
+
acquireAgent(): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Grant control to a human. Succeeds unless a human already holds it (single
|
|
104
|
+
* controller). "Human request always wins over the agent" — the agent parks
|
|
105
|
+
* at its next `acquireAgent()`.
|
|
106
|
+
*/
|
|
107
|
+
grantHuman(): boolean;
|
|
108
|
+
/** Return control to the agent and drain any parked automation ops. */
|
|
109
|
+
releaseHuman(): void;
|
|
110
|
+
private setOwner;
|
|
111
|
+
}
|
|
112
|
+
//#endregion
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/types.d.ts
|
|
115
|
+
interface BrowserSessionOptions {
|
|
116
|
+
/** Path to the Chrome/Chromium binary (from the headless-browser integration). */
|
|
117
|
+
executablePath: string;
|
|
118
|
+
/** Persistent profile dir so cookies/login survive process restarts. */
|
|
119
|
+
userDataDir: string;
|
|
120
|
+
/** Headless mode (default true). */
|
|
121
|
+
headless?: boolean;
|
|
122
|
+
/** Pass --no-sandbox (needed on most managed Linux VMs). */
|
|
123
|
+
noSandbox?: boolean;
|
|
124
|
+
/** Shut Chrome down after this many ms with no holds/activity (default 5 min). */
|
|
125
|
+
idleShutdownMs?: number;
|
|
126
|
+
/** Extra Chrome args. */
|
|
127
|
+
extraArgs?: string[];
|
|
128
|
+
logger?: Logger;
|
|
129
|
+
}
|
|
130
|
+
interface BrowserSurfaceOptions extends BrowserSessionOptions {
|
|
131
|
+
/**
|
|
132
|
+
* Guard consulted before agent-driven or human navigation. Return false to
|
|
133
|
+
* block (SSRF policy). Defaults to allow-all; Phase 11 wires the integration
|
|
134
|
+
* SSRF allowlist here.
|
|
135
|
+
*/
|
|
136
|
+
isNavigationAllowed?: (url: string) => boolean;
|
|
137
|
+
}
|
|
138
|
+
//#endregion
|
|
139
|
+
//#region src/browser-session.d.ts
|
|
140
|
+
declare class BrowserSession {
|
|
141
|
+
private readonly options;
|
|
142
|
+
private browser;
|
|
143
|
+
private activePage;
|
|
144
|
+
private launching;
|
|
145
|
+
private holds;
|
|
146
|
+
private idleTimer;
|
|
147
|
+
private readonly log;
|
|
148
|
+
private readonly idleMs;
|
|
149
|
+
constructor(options: BrowserSessionOptions);
|
|
150
|
+
/** Launch Chrome if not already running (idempotent, concurrent-safe). */
|
|
151
|
+
ensureLaunched(): Promise<void>;
|
|
152
|
+
private doLaunch;
|
|
153
|
+
/** The current active page, launching Chrome first if needed. */
|
|
154
|
+
getActivePage(): Promise<Page>;
|
|
155
|
+
/** Prevent idle shutdown while a viewer or op is active. */
|
|
156
|
+
addHold(): void;
|
|
157
|
+
/** Release a hold; arm idle shutdown when the last one is released. */
|
|
158
|
+
removeHold(): void;
|
|
159
|
+
/** Reset the idle timer on any activity (only relevant when unheld). */
|
|
160
|
+
touch(): void;
|
|
161
|
+
private armIdleTimer;
|
|
162
|
+
private clearIdleTimer;
|
|
163
|
+
shutdown(): Promise<void>;
|
|
164
|
+
}
|
|
165
|
+
//#endregion
|
|
166
|
+
//#region src/automation.d.ts
|
|
167
|
+
interface NavigateResult {
|
|
168
|
+
url: string;
|
|
169
|
+
title: string;
|
|
170
|
+
}
|
|
171
|
+
declare class BrowserAutomation {
|
|
172
|
+
private readonly session;
|
|
173
|
+
private readonly turn;
|
|
174
|
+
private readonly isNavigationAllowed;
|
|
175
|
+
constructor(session: BrowserSession, turn: TurnController, isNavigationAllowed: (url: string) => boolean);
|
|
176
|
+
navigate(url: string): Promise<NavigateResult>;
|
|
177
|
+
click(selector: string): Promise<void>;
|
|
178
|
+
type(selector: string, text: string): Promise<void>;
|
|
179
|
+
waitFor(opts: {
|
|
180
|
+
selector?: string;
|
|
181
|
+
ms?: number;
|
|
182
|
+
urlPattern?: string;
|
|
183
|
+
}): Promise<void>;
|
|
184
|
+
/** One-shot JPEG screenshot (base64) for the agent's own reasoning — distinct
|
|
185
|
+
* from the continuous screencast stream to viewers. */
|
|
186
|
+
screenshot(): Promise<string>;
|
|
187
|
+
/** Evaluate an expression in the page context via CDP (no eval on our side). */
|
|
188
|
+
evaluate(expression: string): Promise<unknown>;
|
|
189
|
+
}
|
|
190
|
+
//#endregion
|
|
191
|
+
//#region src/browser-surface.d.ts
|
|
192
|
+
interface HandoffResult {
|
|
193
|
+
released: boolean;
|
|
194
|
+
timedOut: boolean;
|
|
195
|
+
url: string;
|
|
196
|
+
title: string;
|
|
197
|
+
}
|
|
198
|
+
declare class BrowserSurface implements SurfaceHandler {
|
|
199
|
+
private readonly options;
|
|
200
|
+
private readonly sendFrame;
|
|
201
|
+
readonly surface: "browser";
|
|
202
|
+
private readonly session;
|
|
203
|
+
private readonly turn;
|
|
204
|
+
private readonly pump;
|
|
205
|
+
private readonly injector;
|
|
206
|
+
readonly automation: BrowserAutomation;
|
|
207
|
+
private readonly viewers;
|
|
208
|
+
private viewport;
|
|
209
|
+
private handoff;
|
|
210
|
+
private readonly log;
|
|
211
|
+
constructor(options: BrowserSurfaceOptions, sendFrame: (buf: Buffer) => void);
|
|
212
|
+
openSession(sessionId: number, open: SessionOpenPayload): Promise<void>;
|
|
213
|
+
handleFrame(frame: RemoteFrame): void;
|
|
214
|
+
closeSession(sessionId: number): void;
|
|
215
|
+
/**
|
|
216
|
+
* Agent tool entry point: hand control to the human and block until they
|
|
217
|
+
* release it (RELEASE_CONTROL) or `timeoutMs` elapses. Resolves with the
|
|
218
|
+
* final page URL/title so the agent resumes on the same live page.
|
|
219
|
+
*/
|
|
220
|
+
requestHandoff(timeoutMs: number): Promise<HandoffResult>;
|
|
221
|
+
shutdown(): Promise<void>;
|
|
222
|
+
private releaseToAgent;
|
|
223
|
+
private ensureStreaming;
|
|
224
|
+
private applyResize;
|
|
225
|
+
private broadcastFrame;
|
|
226
|
+
private broadcast;
|
|
227
|
+
private broadcastState;
|
|
228
|
+
private sendState;
|
|
229
|
+
private currentPageInfo;
|
|
230
|
+
}
|
|
231
|
+
//#endregion
|
|
232
|
+
export { BrowserAutomation, BrowserSession, type BrowserSessionOptions, BrowserSurface, type BrowserSurfaceOptions, type HandoffResult, type Logger, type NavigateResult };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { Page } from "puppeteer-core";
|
|
2
|
+
|
|
3
|
+
//#region ../remote/dist/index.d.ts
|
|
4
|
+
|
|
5
|
+
declare const RemoteFrameType: {
|
|
6
|
+
/** viewer→plugin: a viewer attached. Payload: SessionOpenPayload. */
|
|
7
|
+
readonly SESSION_OPEN: 1;
|
|
8
|
+
/** either direction: a viewer detached / session torn down. */
|
|
9
|
+
readonly SESSION_CLOSE: 2;
|
|
10
|
+
/** plugin→viewer: current surface state. Payload: SessionStatePayload. */
|
|
11
|
+
readonly SESSION_STATE: 3;
|
|
12
|
+
/** plugin→viewer (browser): the page navigated. Payload: { url }. */
|
|
13
|
+
readonly NAVIGATION: 4;
|
|
14
|
+
/** plugin→viewer: [metaLen:u16BE][meta JSON][raw JPEG]. */
|
|
15
|
+
readonly SCREENCAST_FRAME: 16;
|
|
16
|
+
/** viewer→plugin: { frameSeq } — drives ack-gated backpressure. */
|
|
17
|
+
readonly SCREENCAST_ACK: 17;
|
|
18
|
+
readonly INPUT_MOUSE: 32;
|
|
19
|
+
readonly INPUT_WHEEL: 33;
|
|
20
|
+
readonly INPUT_KEY: 34;
|
|
21
|
+
/** viewer→plugin: { width, height, dpr }. */
|
|
22
|
+
readonly RESIZE: 35;
|
|
23
|
+
readonly TAKEOVER_REQUEST: 48;
|
|
24
|
+
readonly TAKEOVER_GRANTED: 49;
|
|
25
|
+
readonly TAKEOVER_DENIED: 50;
|
|
26
|
+
readonly RELEASE_CONTROL: 51;
|
|
27
|
+
readonly CONTROL_REVOKED: 52;
|
|
28
|
+
/** plugin→viewer: raw PTY output bytes. */
|
|
29
|
+
readonly TERMINAL_DATA: 64;
|
|
30
|
+
/** viewer→plugin: raw keystroke bytes. */
|
|
31
|
+
readonly TERMINAL_INPUT: 65;
|
|
32
|
+
/** viewer→plugin: { cols, rows }. */
|
|
33
|
+
readonly TERMINAL_RESIZE: 66;
|
|
34
|
+
};
|
|
35
|
+
type RemoteFrameType = (typeof RemoteFrameType)[keyof typeof RemoteFrameType];
|
|
36
|
+
type RemoteSurface = "browser" | "terminal";
|
|
37
|
+
interface RemoteFrame {
|
|
38
|
+
type: RemoteFrameType;
|
|
39
|
+
sessionId: number;
|
|
40
|
+
payload: Buffer;
|
|
41
|
+
}
|
|
42
|
+
interface SessionOpenPayload {
|
|
43
|
+
surface: RemoteSurface;
|
|
44
|
+
/** Browser: initial viewport in device pixels. */
|
|
45
|
+
width?: number;
|
|
46
|
+
height?: number;
|
|
47
|
+
dpr?: number;
|
|
48
|
+
/** Terminal: initial PTY dimensions. */
|
|
49
|
+
cols?: number;
|
|
50
|
+
rows?: number;
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/surface.d.ts
|
|
54
|
+
interface SurfaceHandler {
|
|
55
|
+
/** Which surface this handler serves. */
|
|
56
|
+
readonly surface: RemoteSurface;
|
|
57
|
+
/** A viewer attached — open the surface for this session. */
|
|
58
|
+
openSession(sessionId: number, open: SessionOpenPayload): void | Promise<void>;
|
|
59
|
+
/** A subsequent frame for one of this handler's sessions (not SESSION_OPEN). */
|
|
60
|
+
handleFrame(frame: RemoteFrame): void;
|
|
61
|
+
/** The viewer detached — tear down this session's resources. */
|
|
62
|
+
closeSession(sessionId: number): void;
|
|
63
|
+
}
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region src/types.d.ts
|
|
66
|
+
interface Logger {
|
|
67
|
+
info(msg: string, ...args: unknown[]): void;
|
|
68
|
+
warn(msg: string, ...args: unknown[]): void;
|
|
69
|
+
error(msg: string, ...args: unknown[]): void;
|
|
70
|
+
debug(msg: string, ...args: unknown[]): void;
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/turn-controller.d.ts
|
|
74
|
+
/**
|
|
75
|
+
* TurnController — the write-mutex between agent automation and a human during
|
|
76
|
+
* a browser co-browse handoff. The plugin owns the single CDP session, so this
|
|
77
|
+
* lives plugin-side; the relay only forwards the control frames.
|
|
78
|
+
*
|
|
79
|
+
* Only *writes* are gated — screencast reads always flow so the human sees the
|
|
80
|
+
* live page regardless of who holds the token. Agent automation ops call
|
|
81
|
+
* `acquireAgent()` and park while the human is in control; the human's input is
|
|
82
|
+
* injected only while `owner === 'human'`.
|
|
83
|
+
*/
|
|
84
|
+
type TurnOwner = "agent" | "human";
|
|
85
|
+
interface TurnControllerOptions {
|
|
86
|
+
/** Fired whenever ownership changes, so the plugin can emit SESSION_STATE. */
|
|
87
|
+
onOwnerChange?: (owner: TurnOwner) => void;
|
|
88
|
+
}
|
|
89
|
+
declare class TurnController {
|
|
90
|
+
private owner;
|
|
91
|
+
private waiters;
|
|
92
|
+
private readonly onOwnerChange?;
|
|
93
|
+
constructor(options?: TurnControllerOptions);
|
|
94
|
+
get currentOwner(): TurnOwner;
|
|
95
|
+
get humanInControl(): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Resolve once the agent is (again) allowed to drive. Resolves immediately if
|
|
98
|
+
* the agent already holds the token; otherwise parks until `releaseHuman()`.
|
|
99
|
+
* Every automation op awaits this before touching the page.
|
|
100
|
+
*/
|
|
101
|
+
acquireAgent(): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Grant control to a human. Succeeds unless a human already holds it (single
|
|
104
|
+
* controller). "Human request always wins over the agent" — the agent parks
|
|
105
|
+
* at its next `acquireAgent()`.
|
|
106
|
+
*/
|
|
107
|
+
grantHuman(): boolean;
|
|
108
|
+
/** Return control to the agent and drain any parked automation ops. */
|
|
109
|
+
releaseHuman(): void;
|
|
110
|
+
private setOwner;
|
|
111
|
+
}
|
|
112
|
+
//#endregion
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/types.d.ts
|
|
115
|
+
interface BrowserSessionOptions {
|
|
116
|
+
/** Path to the Chrome/Chromium binary (from the headless-browser integration). */
|
|
117
|
+
executablePath: string;
|
|
118
|
+
/** Persistent profile dir so cookies/login survive process restarts. */
|
|
119
|
+
userDataDir: string;
|
|
120
|
+
/** Headless mode (default true). */
|
|
121
|
+
headless?: boolean;
|
|
122
|
+
/** Pass --no-sandbox (needed on most managed Linux VMs). */
|
|
123
|
+
noSandbox?: boolean;
|
|
124
|
+
/** Shut Chrome down after this many ms with no holds/activity (default 5 min). */
|
|
125
|
+
idleShutdownMs?: number;
|
|
126
|
+
/** Extra Chrome args. */
|
|
127
|
+
extraArgs?: string[];
|
|
128
|
+
logger?: Logger;
|
|
129
|
+
}
|
|
130
|
+
interface BrowserSurfaceOptions extends BrowserSessionOptions {
|
|
131
|
+
/**
|
|
132
|
+
* Guard consulted before agent-driven or human navigation. Return false to
|
|
133
|
+
* block (SSRF policy). Defaults to allow-all; Phase 11 wires the integration
|
|
134
|
+
* SSRF allowlist here.
|
|
135
|
+
*/
|
|
136
|
+
isNavigationAllowed?: (url: string) => boolean;
|
|
137
|
+
}
|
|
138
|
+
//#endregion
|
|
139
|
+
//#region src/browser-session.d.ts
|
|
140
|
+
declare class BrowserSession {
|
|
141
|
+
private readonly options;
|
|
142
|
+
private browser;
|
|
143
|
+
private activePage;
|
|
144
|
+
private launching;
|
|
145
|
+
private holds;
|
|
146
|
+
private idleTimer;
|
|
147
|
+
private readonly log;
|
|
148
|
+
private readonly idleMs;
|
|
149
|
+
constructor(options: BrowserSessionOptions);
|
|
150
|
+
/** Launch Chrome if not already running (idempotent, concurrent-safe). */
|
|
151
|
+
ensureLaunched(): Promise<void>;
|
|
152
|
+
private doLaunch;
|
|
153
|
+
/** The current active page, launching Chrome first if needed. */
|
|
154
|
+
getActivePage(): Promise<Page>;
|
|
155
|
+
/** Prevent idle shutdown while a viewer or op is active. */
|
|
156
|
+
addHold(): void;
|
|
157
|
+
/** Release a hold; arm idle shutdown when the last one is released. */
|
|
158
|
+
removeHold(): void;
|
|
159
|
+
/** Reset the idle timer on any activity (only relevant when unheld). */
|
|
160
|
+
touch(): void;
|
|
161
|
+
private armIdleTimer;
|
|
162
|
+
private clearIdleTimer;
|
|
163
|
+
shutdown(): Promise<void>;
|
|
164
|
+
}
|
|
165
|
+
//#endregion
|
|
166
|
+
//#region src/automation.d.ts
|
|
167
|
+
interface NavigateResult {
|
|
168
|
+
url: string;
|
|
169
|
+
title: string;
|
|
170
|
+
}
|
|
171
|
+
declare class BrowserAutomation {
|
|
172
|
+
private readonly session;
|
|
173
|
+
private readonly turn;
|
|
174
|
+
private readonly isNavigationAllowed;
|
|
175
|
+
constructor(session: BrowserSession, turn: TurnController, isNavigationAllowed: (url: string) => boolean);
|
|
176
|
+
navigate(url: string): Promise<NavigateResult>;
|
|
177
|
+
click(selector: string): Promise<void>;
|
|
178
|
+
type(selector: string, text: string): Promise<void>;
|
|
179
|
+
waitFor(opts: {
|
|
180
|
+
selector?: string;
|
|
181
|
+
ms?: number;
|
|
182
|
+
urlPattern?: string;
|
|
183
|
+
}): Promise<void>;
|
|
184
|
+
/** One-shot JPEG screenshot (base64) for the agent's own reasoning — distinct
|
|
185
|
+
* from the continuous screencast stream to viewers. */
|
|
186
|
+
screenshot(): Promise<string>;
|
|
187
|
+
/** Evaluate an expression in the page context via CDP (no eval on our side). */
|
|
188
|
+
evaluate(expression: string): Promise<unknown>;
|
|
189
|
+
}
|
|
190
|
+
//#endregion
|
|
191
|
+
//#region src/browser-surface.d.ts
|
|
192
|
+
interface HandoffResult {
|
|
193
|
+
released: boolean;
|
|
194
|
+
timedOut: boolean;
|
|
195
|
+
url: string;
|
|
196
|
+
title: string;
|
|
197
|
+
}
|
|
198
|
+
declare class BrowserSurface implements SurfaceHandler {
|
|
199
|
+
private readonly options;
|
|
200
|
+
private readonly sendFrame;
|
|
201
|
+
readonly surface: "browser";
|
|
202
|
+
private readonly session;
|
|
203
|
+
private readonly turn;
|
|
204
|
+
private readonly pump;
|
|
205
|
+
private readonly injector;
|
|
206
|
+
readonly automation: BrowserAutomation;
|
|
207
|
+
private readonly viewers;
|
|
208
|
+
private viewport;
|
|
209
|
+
private handoff;
|
|
210
|
+
private readonly log;
|
|
211
|
+
constructor(options: BrowserSurfaceOptions, sendFrame: (buf: Buffer) => void);
|
|
212
|
+
openSession(sessionId: number, open: SessionOpenPayload): Promise<void>;
|
|
213
|
+
handleFrame(frame: RemoteFrame): void;
|
|
214
|
+
closeSession(sessionId: number): void;
|
|
215
|
+
/**
|
|
216
|
+
* Agent tool entry point: hand control to the human and block until they
|
|
217
|
+
* release it (RELEASE_CONTROL) or `timeoutMs` elapses. Resolves with the
|
|
218
|
+
* final page URL/title so the agent resumes on the same live page.
|
|
219
|
+
*/
|
|
220
|
+
requestHandoff(timeoutMs: number): Promise<HandoffResult>;
|
|
221
|
+
shutdown(): Promise<void>;
|
|
222
|
+
private releaseToAgent;
|
|
223
|
+
private ensureStreaming;
|
|
224
|
+
private applyResize;
|
|
225
|
+
private broadcastFrame;
|
|
226
|
+
private broadcast;
|
|
227
|
+
private broadcastState;
|
|
228
|
+
private sendState;
|
|
229
|
+
private currentPageInfo;
|
|
230
|
+
}
|
|
231
|
+
//#endregion
|
|
232
|
+
export { BrowserAutomation, BrowserSession, type BrowserSessionOptions, BrowserSurface, type BrowserSurfaceOptions, type HandoffResult, type Logger, type NavigateResult };
|