@alfe.ai/browser 0.2.0 → 0.3.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/README.md +29 -0
- package/dist/index.cjs +729 -153
- package/dist/index.d.cts +58 -14
- package/dist/index.d.ts +58 -14
- package/dist/index.js +730 -154
- package/package.json +3 -2
package/dist/index.d.cts
CHANGED
|
@@ -96,9 +96,10 @@ declare class TurnController {
|
|
|
96
96
|
/**
|
|
97
97
|
* Resolve once the agent is (again) allowed to drive. Resolves immediately if
|
|
98
98
|
* the agent already holds the token; otherwise parks until `releaseHuman()`.
|
|
99
|
-
* Every automation op awaits this before touching the page.
|
|
99
|
+
* Every automation op awaits this before touching the page. Cancellation
|
|
100
|
+
* removes only this waiter and never changes the current human owner.
|
|
100
101
|
*/
|
|
101
|
-
acquireAgent(): Promise<void>;
|
|
102
|
+
acquireAgent(signal?: AbortSignal): Promise<void>;
|
|
102
103
|
/**
|
|
103
104
|
* Grant control to a human. Succeeds unless a human already holds it (single
|
|
104
105
|
* controller). "Human request always wins over the agent" — the agent parks
|
|
@@ -112,6 +113,18 @@ declare class TurnController {
|
|
|
112
113
|
//#endregion
|
|
113
114
|
//#endregion
|
|
114
115
|
//#region src/types.d.ts
|
|
116
|
+
/** Private local capability for a trusted adapter, never a tool result. */
|
|
117
|
+
interface BrowserOperationContext {
|
|
118
|
+
/** Loopback Chrome endpoint. Do not log, persist, or expose to a viewer/model. */
|
|
119
|
+
browserWSEndpoint: string;
|
|
120
|
+
/** The exact active page's CDP target; never choose the first context/page. */
|
|
121
|
+
targetId: string;
|
|
122
|
+
/** On abort, stop and await all external work before returning. */
|
|
123
|
+
signal: AbortSignal;
|
|
124
|
+
}
|
|
125
|
+
interface BrowserOperationOptions {
|
|
126
|
+
signal?: AbortSignal;
|
|
127
|
+
}
|
|
115
128
|
interface BrowserSessionOptions {
|
|
116
129
|
/** Path to the Chrome/Chromium binary (from the headless-browser integration). */
|
|
117
130
|
executablePath: string;
|
|
@@ -125,16 +138,11 @@ interface BrowserSessionOptions {
|
|
|
125
138
|
idleShutdownMs?: number;
|
|
126
139
|
/** Extra Chrome args. */
|
|
127
140
|
extraArgs?: string[];
|
|
128
|
-
|
|
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
|
-
*/
|
|
141
|
+
/** Guard applied to every intercepted HTTP(S) page request. */
|
|
136
142
|
isNavigationAllowed?: (url: string) => boolean;
|
|
143
|
+
logger?: Logger;
|
|
137
144
|
}
|
|
145
|
+
type BrowserSurfaceOptions = BrowserSessionOptions;
|
|
138
146
|
//#endregion
|
|
139
147
|
//#region src/browser-session.d.ts
|
|
140
148
|
declare class BrowserSession {
|
|
@@ -144,6 +152,9 @@ declare class BrowserSession {
|
|
|
144
152
|
private launching;
|
|
145
153
|
private holds;
|
|
146
154
|
private idleTimer;
|
|
155
|
+
private generation;
|
|
156
|
+
private readonly preparedPages;
|
|
157
|
+
private readonly activePageListeners;
|
|
147
158
|
private readonly log;
|
|
148
159
|
private readonly idleMs;
|
|
149
160
|
constructor(options: BrowserSessionOptions);
|
|
@@ -156,8 +167,16 @@ declare class BrowserSession {
|
|
|
156
167
|
* screencast to a transient `about:blank` throwaway target.
|
|
157
168
|
*/
|
|
158
169
|
private adoptIfNavigable;
|
|
170
|
+
/** A login popup can close while the agent is parked for human control.
|
|
171
|
+
* Recover here, without waiting for another automation call to discover
|
|
172
|
+
* that the active page is closed, and rebind the viewer to its opener. */
|
|
173
|
+
private restoreAfterClose;
|
|
159
174
|
/** The current active page, launching Chrome first if needed. */
|
|
160
175
|
getActivePage(): Promise<Page>;
|
|
176
|
+
onActivePageChange(listener: (page: Page) => void | Promise<void>): () => void;
|
|
177
|
+
/** Internal to the serialized automation turn. The caller holds Chrome until
|
|
178
|
+
* the adapter has disconnected its client/awaited its child process exit. */
|
|
179
|
+
withCdpTarget<T>(operation: (context: BrowserOperationContext) => Promise<T>, signal: AbortSignal): Promise<T>;
|
|
161
180
|
/** Prevent idle shutdown while a viewer or op is active. */
|
|
162
181
|
addHold(): void;
|
|
163
182
|
/** Release a hold; arm idle shutdown when the last one is released. */
|
|
@@ -167,6 +186,9 @@ declare class BrowserSession {
|
|
|
167
186
|
private armIdleTimer;
|
|
168
187
|
private clearIdleTimer;
|
|
169
188
|
shutdown(): Promise<void>;
|
|
189
|
+
private setActivePage;
|
|
190
|
+
private preparePage;
|
|
191
|
+
private isLaunchCurrent;
|
|
170
192
|
}
|
|
171
193
|
//#endregion
|
|
172
194
|
//#region src/automation.d.ts
|
|
@@ -178,6 +200,8 @@ declare class BrowserAutomation {
|
|
|
178
200
|
private readonly session;
|
|
179
201
|
private readonly turn;
|
|
180
202
|
private readonly isNavigationAllowed;
|
|
203
|
+
private operationTail;
|
|
204
|
+
private readonly stopping;
|
|
181
205
|
constructor(session: BrowserSession, turn: TurnController, isNavigationAllowed: (url: string) => boolean);
|
|
182
206
|
navigate(url: string): Promise<NavigateResult>;
|
|
183
207
|
click(selector: string): Promise<void>;
|
|
@@ -192,6 +216,17 @@ declare class BrowserAutomation {
|
|
|
192
216
|
screenshot(): Promise<string>;
|
|
193
217
|
/** Evaluate an expression in the page context via CDP (no eval on our side). */
|
|
194
218
|
evaluate(expression: string): Promise<unknown>;
|
|
219
|
+
/** Wait until all agent operations that were already queued have settled. */
|
|
220
|
+
waitUntilIdle(): Promise<void>;
|
|
221
|
+
/** Trusted local adapters share the built-in automation queue and exact page.
|
|
222
|
+
* The callback must disconnect/await children in finally, including on abort.
|
|
223
|
+
* Do not invoke another automation operation or handoff from the callback. */
|
|
224
|
+
withCdpOperation<T>(operation: (context: BrowserOperationContext) => Promise<T>, options?: BrowserOperationOptions): Promise<T>;
|
|
225
|
+
/** Insert the claim at a precise queue position; later automation parks. */
|
|
226
|
+
yieldToHuman(grant: () => void): Promise<void>;
|
|
227
|
+
/** Abort first, then await callback cleanup before the owner closes Chrome. */
|
|
228
|
+
shutdown(): Promise<void>;
|
|
229
|
+
private run;
|
|
195
230
|
}
|
|
196
231
|
//#endregion
|
|
197
232
|
//#region src/browser-surface.d.ts
|
|
@@ -202,7 +237,6 @@ interface HandoffResult {
|
|
|
202
237
|
title: string;
|
|
203
238
|
}
|
|
204
239
|
declare class BrowserSurface implements SurfaceHandler {
|
|
205
|
-
private readonly options;
|
|
206
240
|
private readonly sendFrame;
|
|
207
241
|
readonly surface: "browser";
|
|
208
242
|
private readonly session;
|
|
@@ -213,6 +247,13 @@ declare class BrowserSurface implements SurfaceHandler {
|
|
|
213
247
|
private readonly viewers;
|
|
214
248
|
private viewport;
|
|
215
249
|
private handoff;
|
|
250
|
+
private controllerSessionId;
|
|
251
|
+
private pendingControllerSessionId;
|
|
252
|
+
private claimGeneration;
|
|
253
|
+
private streamGeneration;
|
|
254
|
+
private streamQueue;
|
|
255
|
+
private closed;
|
|
256
|
+
private readonly removePageListener;
|
|
216
257
|
private readonly log;
|
|
217
258
|
constructor(options: BrowserSurfaceOptions, sendFrame: (buf: Buffer) => void);
|
|
218
259
|
openSession(sessionId: number, open: SessionOpenPayload): Promise<void>;
|
|
@@ -233,7 +274,7 @@ declare class BrowserSurface implements SurfaceHandler {
|
|
|
233
274
|
* under the user (mislabeled 409 on the real claim; agent only resuming when
|
|
234
275
|
* the tab closed).
|
|
235
276
|
*/
|
|
236
|
-
requestHandoff(timeoutMs: number): Promise<HandoffResult>;
|
|
277
|
+
requestHandoff(timeoutMs: number, signal?: AbortSignal): Promise<HandoffResult>;
|
|
237
278
|
/**
|
|
238
279
|
* Keep the shared Chrome alive across an awaiting-human window. Delegates to
|
|
239
280
|
* the session's hold counter (which also backs per-viewer holds). Idempotent
|
|
@@ -244,13 +285,16 @@ declare class BrowserSurface implements SurfaceHandler {
|
|
|
244
285
|
removeHold(): void;
|
|
245
286
|
shutdown(): Promise<void>;
|
|
246
287
|
private releaseToAgent;
|
|
247
|
-
private
|
|
288
|
+
private restartStreaming;
|
|
289
|
+
private enqueueStreamCleanup;
|
|
290
|
+
private shouldStream;
|
|
248
291
|
private applyResize;
|
|
249
292
|
private broadcastFrame;
|
|
250
293
|
private broadcast;
|
|
251
294
|
private broadcastState;
|
|
252
295
|
private sendState;
|
|
253
296
|
private currentPageInfo;
|
|
297
|
+
private sendFrameSafe;
|
|
254
298
|
}
|
|
255
299
|
//#endregion
|
|
256
|
-
export { BrowserAutomation, BrowserSession, type BrowserSessionOptions, BrowserSurface, type BrowserSurfaceOptions, type HandoffResult, type Logger, type NavigateResult };
|
|
300
|
+
export { BrowserAutomation, type BrowserOperationContext, type BrowserOperationOptions, BrowserSession, type BrowserSessionOptions, BrowserSurface, type BrowserSurfaceOptions, type HandoffResult, type Logger, type NavigateResult };
|
package/dist/index.d.ts
CHANGED
|
@@ -96,9 +96,10 @@ declare class TurnController {
|
|
|
96
96
|
/**
|
|
97
97
|
* Resolve once the agent is (again) allowed to drive. Resolves immediately if
|
|
98
98
|
* the agent already holds the token; otherwise parks until `releaseHuman()`.
|
|
99
|
-
* Every automation op awaits this before touching the page.
|
|
99
|
+
* Every automation op awaits this before touching the page. Cancellation
|
|
100
|
+
* removes only this waiter and never changes the current human owner.
|
|
100
101
|
*/
|
|
101
|
-
acquireAgent(): Promise<void>;
|
|
102
|
+
acquireAgent(signal?: AbortSignal): Promise<void>;
|
|
102
103
|
/**
|
|
103
104
|
* Grant control to a human. Succeeds unless a human already holds it (single
|
|
104
105
|
* controller). "Human request always wins over the agent" — the agent parks
|
|
@@ -112,6 +113,18 @@ declare class TurnController {
|
|
|
112
113
|
//#endregion
|
|
113
114
|
//#endregion
|
|
114
115
|
//#region src/types.d.ts
|
|
116
|
+
/** Private local capability for a trusted adapter, never a tool result. */
|
|
117
|
+
interface BrowserOperationContext {
|
|
118
|
+
/** Loopback Chrome endpoint. Do not log, persist, or expose to a viewer/model. */
|
|
119
|
+
browserWSEndpoint: string;
|
|
120
|
+
/** The exact active page's CDP target; never choose the first context/page. */
|
|
121
|
+
targetId: string;
|
|
122
|
+
/** On abort, stop and await all external work before returning. */
|
|
123
|
+
signal: AbortSignal;
|
|
124
|
+
}
|
|
125
|
+
interface BrowserOperationOptions {
|
|
126
|
+
signal?: AbortSignal;
|
|
127
|
+
}
|
|
115
128
|
interface BrowserSessionOptions {
|
|
116
129
|
/** Path to the Chrome/Chromium binary (from the headless-browser integration). */
|
|
117
130
|
executablePath: string;
|
|
@@ -125,16 +138,11 @@ interface BrowserSessionOptions {
|
|
|
125
138
|
idleShutdownMs?: number;
|
|
126
139
|
/** Extra Chrome args. */
|
|
127
140
|
extraArgs?: string[];
|
|
128
|
-
|
|
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
|
-
*/
|
|
141
|
+
/** Guard applied to every intercepted HTTP(S) page request. */
|
|
136
142
|
isNavigationAllowed?: (url: string) => boolean;
|
|
143
|
+
logger?: Logger;
|
|
137
144
|
}
|
|
145
|
+
type BrowserSurfaceOptions = BrowserSessionOptions;
|
|
138
146
|
//#endregion
|
|
139
147
|
//#region src/browser-session.d.ts
|
|
140
148
|
declare class BrowserSession {
|
|
@@ -144,6 +152,9 @@ declare class BrowserSession {
|
|
|
144
152
|
private launching;
|
|
145
153
|
private holds;
|
|
146
154
|
private idleTimer;
|
|
155
|
+
private generation;
|
|
156
|
+
private readonly preparedPages;
|
|
157
|
+
private readonly activePageListeners;
|
|
147
158
|
private readonly log;
|
|
148
159
|
private readonly idleMs;
|
|
149
160
|
constructor(options: BrowserSessionOptions);
|
|
@@ -156,8 +167,16 @@ declare class BrowserSession {
|
|
|
156
167
|
* screencast to a transient `about:blank` throwaway target.
|
|
157
168
|
*/
|
|
158
169
|
private adoptIfNavigable;
|
|
170
|
+
/** A login popup can close while the agent is parked for human control.
|
|
171
|
+
* Recover here, without waiting for another automation call to discover
|
|
172
|
+
* that the active page is closed, and rebind the viewer to its opener. */
|
|
173
|
+
private restoreAfterClose;
|
|
159
174
|
/** The current active page, launching Chrome first if needed. */
|
|
160
175
|
getActivePage(): Promise<Page>;
|
|
176
|
+
onActivePageChange(listener: (page: Page) => void | Promise<void>): () => void;
|
|
177
|
+
/** Internal to the serialized automation turn. The caller holds Chrome until
|
|
178
|
+
* the adapter has disconnected its client/awaited its child process exit. */
|
|
179
|
+
withCdpTarget<T>(operation: (context: BrowserOperationContext) => Promise<T>, signal: AbortSignal): Promise<T>;
|
|
161
180
|
/** Prevent idle shutdown while a viewer or op is active. */
|
|
162
181
|
addHold(): void;
|
|
163
182
|
/** Release a hold; arm idle shutdown when the last one is released. */
|
|
@@ -167,6 +186,9 @@ declare class BrowserSession {
|
|
|
167
186
|
private armIdleTimer;
|
|
168
187
|
private clearIdleTimer;
|
|
169
188
|
shutdown(): Promise<void>;
|
|
189
|
+
private setActivePage;
|
|
190
|
+
private preparePage;
|
|
191
|
+
private isLaunchCurrent;
|
|
170
192
|
}
|
|
171
193
|
//#endregion
|
|
172
194
|
//#region src/automation.d.ts
|
|
@@ -178,6 +200,8 @@ declare class BrowserAutomation {
|
|
|
178
200
|
private readonly session;
|
|
179
201
|
private readonly turn;
|
|
180
202
|
private readonly isNavigationAllowed;
|
|
203
|
+
private operationTail;
|
|
204
|
+
private readonly stopping;
|
|
181
205
|
constructor(session: BrowserSession, turn: TurnController, isNavigationAllowed: (url: string) => boolean);
|
|
182
206
|
navigate(url: string): Promise<NavigateResult>;
|
|
183
207
|
click(selector: string): Promise<void>;
|
|
@@ -192,6 +216,17 @@ declare class BrowserAutomation {
|
|
|
192
216
|
screenshot(): Promise<string>;
|
|
193
217
|
/** Evaluate an expression in the page context via CDP (no eval on our side). */
|
|
194
218
|
evaluate(expression: string): Promise<unknown>;
|
|
219
|
+
/** Wait until all agent operations that were already queued have settled. */
|
|
220
|
+
waitUntilIdle(): Promise<void>;
|
|
221
|
+
/** Trusted local adapters share the built-in automation queue and exact page.
|
|
222
|
+
* The callback must disconnect/await children in finally, including on abort.
|
|
223
|
+
* Do not invoke another automation operation or handoff from the callback. */
|
|
224
|
+
withCdpOperation<T>(operation: (context: BrowserOperationContext) => Promise<T>, options?: BrowserOperationOptions): Promise<T>;
|
|
225
|
+
/** Insert the claim at a precise queue position; later automation parks. */
|
|
226
|
+
yieldToHuman(grant: () => void): Promise<void>;
|
|
227
|
+
/** Abort first, then await callback cleanup before the owner closes Chrome. */
|
|
228
|
+
shutdown(): Promise<void>;
|
|
229
|
+
private run;
|
|
195
230
|
}
|
|
196
231
|
//#endregion
|
|
197
232
|
//#region src/browser-surface.d.ts
|
|
@@ -202,7 +237,6 @@ interface HandoffResult {
|
|
|
202
237
|
title: string;
|
|
203
238
|
}
|
|
204
239
|
declare class BrowserSurface implements SurfaceHandler {
|
|
205
|
-
private readonly options;
|
|
206
240
|
private readonly sendFrame;
|
|
207
241
|
readonly surface: "browser";
|
|
208
242
|
private readonly session;
|
|
@@ -213,6 +247,13 @@ declare class BrowserSurface implements SurfaceHandler {
|
|
|
213
247
|
private readonly viewers;
|
|
214
248
|
private viewport;
|
|
215
249
|
private handoff;
|
|
250
|
+
private controllerSessionId;
|
|
251
|
+
private pendingControllerSessionId;
|
|
252
|
+
private claimGeneration;
|
|
253
|
+
private streamGeneration;
|
|
254
|
+
private streamQueue;
|
|
255
|
+
private closed;
|
|
256
|
+
private readonly removePageListener;
|
|
216
257
|
private readonly log;
|
|
217
258
|
constructor(options: BrowserSurfaceOptions, sendFrame: (buf: Buffer) => void);
|
|
218
259
|
openSession(sessionId: number, open: SessionOpenPayload): Promise<void>;
|
|
@@ -233,7 +274,7 @@ declare class BrowserSurface implements SurfaceHandler {
|
|
|
233
274
|
* under the user (mislabeled 409 on the real claim; agent only resuming when
|
|
234
275
|
* the tab closed).
|
|
235
276
|
*/
|
|
236
|
-
requestHandoff(timeoutMs: number): Promise<HandoffResult>;
|
|
277
|
+
requestHandoff(timeoutMs: number, signal?: AbortSignal): Promise<HandoffResult>;
|
|
237
278
|
/**
|
|
238
279
|
* Keep the shared Chrome alive across an awaiting-human window. Delegates to
|
|
239
280
|
* the session's hold counter (which also backs per-viewer holds). Idempotent
|
|
@@ -244,13 +285,16 @@ declare class BrowserSurface implements SurfaceHandler {
|
|
|
244
285
|
removeHold(): void;
|
|
245
286
|
shutdown(): Promise<void>;
|
|
246
287
|
private releaseToAgent;
|
|
247
|
-
private
|
|
288
|
+
private restartStreaming;
|
|
289
|
+
private enqueueStreamCleanup;
|
|
290
|
+
private shouldStream;
|
|
248
291
|
private applyResize;
|
|
249
292
|
private broadcastFrame;
|
|
250
293
|
private broadcast;
|
|
251
294
|
private broadcastState;
|
|
252
295
|
private sendState;
|
|
253
296
|
private currentPageInfo;
|
|
297
|
+
private sendFrameSafe;
|
|
254
298
|
}
|
|
255
299
|
//#endregion
|
|
256
|
-
export { BrowserAutomation, BrowserSession, type BrowserSessionOptions, BrowserSurface, type BrowserSurfaceOptions, type HandoffResult, type Logger, type NavigateResult };
|
|
300
|
+
export { BrowserAutomation, type BrowserOperationContext, type BrowserOperationOptions, BrowserSession, type BrowserSessionOptions, BrowserSurface, type BrowserSurfaceOptions, type HandoffResult, type Logger, type NavigateResult };
|