@parcha/pi-browser 0.1.0-beta.33 → 0.1.0-beta.35
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/CHANGELOG.md +25 -0
- package/NOTICE +30 -0
- package/README.md +33 -199
- package/dist/core/contract.d.ts +9 -6
- package/dist/core/contract.js +22 -34
- package/dist/core/custody.d.ts +6 -0
- package/dist/core/custody.js +6 -0
- package/dist/core/driving-guard.js +17 -2
- package/dist/core/evidence.d.ts +1 -1
- package/dist/core/files.d.ts +3 -0
- package/dist/core/files.js +4 -1
- package/dist/core/host.d.ts +0 -63
- package/dist/core/redact.d.ts +0 -2
- package/dist/core/redact.js +0 -32
- package/dist/core/session-control.d.ts +0 -2
- package/dist/core/session-control.js +0 -5
- package/dist/core/tools.d.ts +9 -0
- package/dist/core/usage.d.ts +0 -2
- package/dist/core/usage.js +0 -2
- package/dist/core/web.d.ts +2 -111
- package/dist/core/web.js +0 -443
- package/dist/driver/cdp.d.ts +6 -0
- package/dist/driver/cdp.js +245 -0
- package/dist/driver/page-driver.js +29 -3
- package/dist/durable/store.js +13 -4
- package/dist/durable.d.ts +2 -12
- package/dist/durable.js +9 -80
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/live-view/provider.d.ts +2 -2
- package/dist/live-view/provider.js +2 -2
- package/dist/live-view/server.d.ts +1 -1
- package/dist/providers/browserbase.d.ts +0 -31
- package/dist/providers/browserbase.js +2 -27
- package/dist/providers/chrome-args.d.ts +3 -0
- package/dist/providers/chrome-args.js +13 -2
- package/dist/testing/backend.d.ts +2 -21
- package/dist/testing/backend.js +1 -25
- package/dist/vendor/browser-use-pi/ax.d.ts +106 -0
- package/dist/vendor/browser-use-pi/ax.js +642 -0
- package/dist/vendor/browser-use-pi/cdp.d.ts +19 -0
- package/dist/vendor/browser-use-pi/cdp.js +106 -0
- package/dist/vendor/browser-use-pi/page.d.ts +38 -0
- package/dist/vendor/browser-use-pi/page.js +112 -0
- package/package.json +7 -25
- package/src/vendor/browser-use-pi/UPSTREAM.json +25 -0
- package/src/vendor/stagehand-facade/UPSTREAM.json +0 -4
- package/dist/coding-agent-local.d.ts +0 -12
- package/dist/coding-agent-local.js +0 -72
- package/dist/coding-agent.d.ts +0 -135
- package/dist/coding-agent.js +0 -641
- package/dist/core/sites.d.ts +0 -33
- package/dist/core/sites.js +0 -104
- package/dist/durable/web.d.ts +0 -47
- package/dist/durable/web.js +0 -41
- package/dist/providers/assigned.d.ts +0 -18
- package/dist/providers/assigned.js +0 -75
- package/dist/recorder/credential.d.ts +0 -9
- package/dist/recorder/credential.js +0 -49
- package/dist/recorder/follow.d.ts +0 -36
- package/dist/recorder/follow.js +0 -163
- package/dist/recorder/frames.d.ts +0 -87
- package/dist/recorder/frames.js +0 -377
- package/dist/recorder/index.d.ts +0 -4
- package/dist/recorder/index.js +0 -7
- package/dist/recorder/jpeg.d.ts +0 -8
- package/dist/recorder/jpeg.js +0 -70
- package/dist/recorder/track.d.ts +0 -107
- package/dist/recorder/track.js +0 -280
- package/dist/vendor/stagehand-facade/screenshot-transport.d.ts +0 -15
- package/dist/vendor/stagehand-facade/screenshot-transport.js +0 -51
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** The connection to the browser closed, failed or never opened: a dropped connection, not the page's error. */
|
|
2
|
+
export declare class CDPConnectionClosedError extends Error {
|
|
3
|
+
name: string;
|
|
4
|
+
}
|
|
5
|
+
/** Explicit commands over one flattened CDP WebSocket. No proxies. */
|
|
6
|
+
export declare class CDP {
|
|
7
|
+
private socket;
|
|
8
|
+
readonly timeoutMs: number;
|
|
9
|
+
private nextId;
|
|
10
|
+
private pending;
|
|
11
|
+
/** Every event, with its session: the driver's dialogs and network tracking read them. Never receives responses. */
|
|
12
|
+
observeEvent: ((method: string, params: unknown, sessionId?: string) => void) | undefined;
|
|
13
|
+
private constructor();
|
|
14
|
+
/** The connection over `socket`, once it is open; a socket that does not open within the timeout (at least 15 s) is closed and refused. */
|
|
15
|
+
static open(socket: WebSocket, timeoutMs?: number): Promise<CDP>;
|
|
16
|
+
send<T = any>(method: string, params?: object, sessionId?: string): Promise<T>;
|
|
17
|
+
private fail;
|
|
18
|
+
close(): void;
|
|
19
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// Adapted from Browser Use Pi (https://github.com/browser-use/browser-use-pi) at commit
|
|
2
|
+
// e7007f219b10fa2c2baae1bf3e2f902a5a2706fd, src/cdp.ts. MIT License, Copyright (c) 2026 Browser Use contributors; the
|
|
3
|
+
// license's full text is in this package's NOTICE, and UPSTREAM.json beside this file records the source.
|
|
4
|
+
// Changes: one connection over a socket the caller opens (core/dial.ts openDial); no lazy connection, no macOS approval
|
|
5
|
+
// prompt and no target bookkeeping; untyped params and results in place of devtools-protocol's types, so the package
|
|
6
|
+
// takes no dependency for them; a connection that closes, fails or never opens fails with CDPConnectionClosedError, the
|
|
7
|
+
// name the package's failures read as a dropped connection (core/failures.ts), so a call reconnects.
|
|
8
|
+
/** The connection to the browser closed, failed or never opened: a dropped connection, not the page's error. */
|
|
9
|
+
export class CDPConnectionClosedError extends Error {
|
|
10
|
+
name = "CDPConnectionClosedError";
|
|
11
|
+
}
|
|
12
|
+
/** Explicit commands over one flattened CDP WebSocket. No proxies. */
|
|
13
|
+
export class CDP {
|
|
14
|
+
socket;
|
|
15
|
+
timeoutMs;
|
|
16
|
+
nextId = 0;
|
|
17
|
+
pending = new Map();
|
|
18
|
+
/** Every event, with its session: the driver's dialogs and network tracking read them. Never receives responses. */
|
|
19
|
+
observeEvent;
|
|
20
|
+
constructor(socket, timeoutMs) {
|
|
21
|
+
this.socket = socket;
|
|
22
|
+
this.timeoutMs = timeoutMs;
|
|
23
|
+
socket.addEventListener("message", ({ data }) => {
|
|
24
|
+
try {
|
|
25
|
+
const message = JSON.parse(String(data));
|
|
26
|
+
if (message.id !== undefined) {
|
|
27
|
+
const request = this.pending.get(message.id);
|
|
28
|
+
if (message.error)
|
|
29
|
+
request?.reject(new Error(`CDP ${message.error.code}: ${message.error.message}`));
|
|
30
|
+
else
|
|
31
|
+
request?.resolve(message.result);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
try {
|
|
35
|
+
this.observeEvent?.(message.method, message.params, message.sessionId);
|
|
36
|
+
}
|
|
37
|
+
catch { /* an observer cannot change delivery */ }
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
this.fail(new Error("Malformed CDP message."));
|
|
42
|
+
socket.close();
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
socket.addEventListener("close", () => this.fail(new CDPConnectionClosedError("CDP connection closed. Inspect state before retrying.")));
|
|
46
|
+
socket.addEventListener("error", () => this.fail(new CDPConnectionClosedError("CDP connection failed.")));
|
|
47
|
+
}
|
|
48
|
+
/** The connection over `socket`, once it is open; a socket that does not open within the timeout (at least 15 s) is closed and refused. */
|
|
49
|
+
static async open(socket, timeoutMs = 15_000) {
|
|
50
|
+
const connectMs = Math.max(timeoutMs, 15_000);
|
|
51
|
+
await new Promise((resolve, reject) => {
|
|
52
|
+
const finish = (error) => {
|
|
53
|
+
clearTimeout(timer);
|
|
54
|
+
socket.removeEventListener("open", open);
|
|
55
|
+
socket.removeEventListener("error", failed);
|
|
56
|
+
socket.removeEventListener("close", failed);
|
|
57
|
+
if (error) {
|
|
58
|
+
socket.close();
|
|
59
|
+
reject(error);
|
|
60
|
+
}
|
|
61
|
+
else
|
|
62
|
+
resolve();
|
|
63
|
+
};
|
|
64
|
+
const open = () => finish();
|
|
65
|
+
const failed = () => finish(new CDPConnectionClosedError("Could not connect to CDP endpoint."));
|
|
66
|
+
const timer = setTimeout(() => finish(new CDPConnectionClosedError("CDP connection timed out.")), connectMs);
|
|
67
|
+
socket.addEventListener("open", open, { once: true });
|
|
68
|
+
socket.addEventListener("error", failed, { once: true });
|
|
69
|
+
socket.addEventListener("close", failed, { once: true });
|
|
70
|
+
});
|
|
71
|
+
return new CDP(socket, timeoutMs);
|
|
72
|
+
}
|
|
73
|
+
send(method, params = {}, sessionId) {
|
|
74
|
+
if (this.socket.readyState !== WebSocket.OPEN)
|
|
75
|
+
return Promise.reject(new CDPConnectionClosedError("CDP connection is closed."));
|
|
76
|
+
if (this.pending.size >= 256)
|
|
77
|
+
return Promise.reject(new Error("Too many pending CDP commands (256)."));
|
|
78
|
+
const id = ++this.nextId;
|
|
79
|
+
return new Promise((resolve, reject) => {
|
|
80
|
+
const finish = (error, value) => {
|
|
81
|
+
clearTimeout(timer);
|
|
82
|
+
this.pending.delete(id);
|
|
83
|
+
if (error)
|
|
84
|
+
reject(error);
|
|
85
|
+
else
|
|
86
|
+
resolve(value);
|
|
87
|
+
};
|
|
88
|
+
const timer = setTimeout(() => finish(new Error(`CDP ${method} exceeded ${this.timeoutMs} ms; the action may have happened.`)), this.timeoutMs);
|
|
89
|
+
this.pending.set(id, { resolve: (value) => finish(undefined, value), reject: (error) => finish(error) });
|
|
90
|
+
try {
|
|
91
|
+
this.socket.send(JSON.stringify({ id, method, params, ...(sessionId ? { sessionId } : {}) }));
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
finish(error instanceof Error ? error : new Error(String(error)));
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
fail(error) {
|
|
99
|
+
for (const request of [...this.pending.values()])
|
|
100
|
+
request.reject(error);
|
|
101
|
+
}
|
|
102
|
+
close() {
|
|
103
|
+
this.fail(new CDPConnectionClosedError("CDP connection closed."));
|
|
104
|
+
this.socket.close();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { CDP } from "./cdp.js";
|
|
2
|
+
/** The schemes a page is sent to: the web and the blank page, never a file of this machine or the browser's own pages. */
|
|
3
|
+
export declare const NAVIGABLE: RegExp;
|
|
4
|
+
/** A tab with explicit CDP, page evaluation and observation. No selector/action layer. */
|
|
5
|
+
export declare class Page {
|
|
6
|
+
readonly connection: CDP;
|
|
7
|
+
targetId: string;
|
|
8
|
+
sessionId: string;
|
|
9
|
+
private constructor();
|
|
10
|
+
static attach(connection: CDP, targetId: string): Promise<Page>;
|
|
11
|
+
cdp<T = any>(method: string, params?: object): Promise<T>;
|
|
12
|
+
goto(url: string): Promise<{
|
|
13
|
+
url: string;
|
|
14
|
+
title: string;
|
|
15
|
+
}>;
|
|
16
|
+
info(): Promise<{
|
|
17
|
+
url: string;
|
|
18
|
+
title: string;
|
|
19
|
+
}>;
|
|
20
|
+
evaluate<T, A = undefined>(fn: ((argument: A) => T) | string, argument?: A): Promise<Awaited<T>>;
|
|
21
|
+
waitFor<A = undefined>(fn: (arg: A) => unknown, argument?: A, options?: {
|
|
22
|
+
timeoutMs?: number;
|
|
23
|
+
}): Promise<void>;
|
|
24
|
+
clickAt(x: number, y: number): Promise<void>;
|
|
25
|
+
moveTo(x: number, y: number): Promise<void>;
|
|
26
|
+
/** `clip` in CSS pixels from the viewport's corner, as the page tools give it; the browser's own is from the document's. */
|
|
27
|
+
screenshot(options?: {
|
|
28
|
+
type?: "png" | "jpeg";
|
|
29
|
+
quality?: number;
|
|
30
|
+
fullPage?: boolean;
|
|
31
|
+
clip?: {
|
|
32
|
+
x: number;
|
|
33
|
+
y: number;
|
|
34
|
+
width: number;
|
|
35
|
+
height: number;
|
|
36
|
+
};
|
|
37
|
+
}): Promise<string>;
|
|
38
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// Adapted from Browser Use Pi (https://github.com/browser-use/browser-use-pi) at commit
|
|
2
|
+
// e7007f219b10fa2c2baae1bf3e2f902a5a2706fd, src/page.ts. MIT License, Copyright (c) 2026 Browser Use contributors; the
|
|
3
|
+
// license's full text is in this package's NOTICE, and UPSTREAM.json beside this file records the source.
|
|
4
|
+
// Changes: the Page class only (no Tabs, no snapshot of its own: ax.ts's is the driver's); goto refuses a scheme other
|
|
5
|
+
// than http, https and about:blank; screenshot takes the driver's format, quality, clip and full-page options; untyped
|
|
6
|
+
// CDP params and results.
|
|
7
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
8
|
+
const contextLost = /Execution context was destroyed|Cannot find context|Cannot find default execution context/;
|
|
9
|
+
/** The schemes a page is sent to: the web and the blank page, never a file of this machine or the browser's own pages. */
|
|
10
|
+
export const NAVIGABLE = /^(https?:\/\/|about:blank$)/i;
|
|
11
|
+
/** A tab with explicit CDP, page evaluation and observation. No selector/action layer. */
|
|
12
|
+
export class Page {
|
|
13
|
+
connection;
|
|
14
|
+
targetId;
|
|
15
|
+
sessionId;
|
|
16
|
+
constructor(connection, targetId, sessionId) {
|
|
17
|
+
this.connection = connection;
|
|
18
|
+
this.targetId = targetId;
|
|
19
|
+
this.sessionId = sessionId;
|
|
20
|
+
}
|
|
21
|
+
static async attach(connection, targetId) {
|
|
22
|
+
const { sessionId } = await connection.send("Target.attachToTarget", { targetId, flatten: true });
|
|
23
|
+
const page = new Page(connection, targetId, sessionId);
|
|
24
|
+
try {
|
|
25
|
+
await page.cdp("Page.enable");
|
|
26
|
+
await page.cdp("Runtime.enable");
|
|
27
|
+
return page;
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
// The caller never receives this page, so it cannot release the failed attachment.
|
|
31
|
+
await connection.send("Target.detachFromTarget", { sessionId }).catch(() => { });
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
cdp(method, params) {
|
|
36
|
+
return this.connection.send(method, params, this.sessionId);
|
|
37
|
+
}
|
|
38
|
+
async goto(url) {
|
|
39
|
+
if (!NAVIGABLE.test(url))
|
|
40
|
+
throw new Error(`goto takes an http or https URL (or about:blank), not ${JSON.stringify(url.slice(0, 100))}`);
|
|
41
|
+
const result = await this.cdp("Page.navigate", { url });
|
|
42
|
+
if (result.errorText)
|
|
43
|
+
throw new Error(`Navigation failed: ${result.errorText}`);
|
|
44
|
+
await this.waitFor(() => document.readyState !== "loading");
|
|
45
|
+
return this.info();
|
|
46
|
+
}
|
|
47
|
+
async info() {
|
|
48
|
+
return this.evaluate(() => ({ url: location.href, title: document.title }));
|
|
49
|
+
}
|
|
50
|
+
async evaluate(fn, argument) {
|
|
51
|
+
const expression = typeof fn === "string" ? fn : `(${fn.toString()})(${JSON.stringify(argument) ?? "undefined"})`;
|
|
52
|
+
const response = await this.cdp("Runtime.evaluate", {
|
|
53
|
+
expression,
|
|
54
|
+
// Bound synchronous execution in Chrome too; rejecting a CDP promise does not stop it.
|
|
55
|
+
timeout: this.connection.timeoutMs,
|
|
56
|
+
awaitPromise: true,
|
|
57
|
+
returnByValue: true,
|
|
58
|
+
userGesture: true,
|
|
59
|
+
});
|
|
60
|
+
if (response.exceptionDetails)
|
|
61
|
+
throw new Error(response.exceptionDetails.exception?.description ?? response.exceptionDetails.text);
|
|
62
|
+
return response.result.value;
|
|
63
|
+
}
|
|
64
|
+
async waitFor(fn, argument, options = {}) {
|
|
65
|
+
const timeoutMs = options.timeoutMs ?? this.connection.timeoutMs;
|
|
66
|
+
const deadline = Date.now() + timeoutMs;
|
|
67
|
+
while (Date.now() < deadline) {
|
|
68
|
+
try {
|
|
69
|
+
if (await this.evaluate(fn, argument))
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
if (!(error instanceof Error) || !contextLost.test(error.message))
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
await delay(Math.min(100, Math.max(0, deadline - Date.now())));
|
|
77
|
+
}
|
|
78
|
+
throw new Error(`Page condition exceeded ${timeoutMs} ms.`);
|
|
79
|
+
}
|
|
80
|
+
async clickAt(x, y) {
|
|
81
|
+
if (![x, y].every(Number.isFinite))
|
|
82
|
+
throw new Error("Coordinates must be finite.");
|
|
83
|
+
await this.cdp("Input.dispatchMouseEvent", { type: "mouseMoved", x, y });
|
|
84
|
+
await this.cdp("Input.dispatchMouseEvent", { type: "mousePressed", x, y, button: "left", clickCount: 1 });
|
|
85
|
+
await this.cdp("Input.dispatchMouseEvent", { type: "mouseReleased", x, y, button: "left", clickCount: 1 });
|
|
86
|
+
}
|
|
87
|
+
async moveTo(x, y) {
|
|
88
|
+
if (![x, y].every(Number.isFinite))
|
|
89
|
+
throw new Error("Coordinates must be finite.");
|
|
90
|
+
await this.cdp("Input.dispatchMouseEvent", { type: "mouseMoved", x, y });
|
|
91
|
+
}
|
|
92
|
+
/** `clip` in CSS pixels from the viewport's corner, as the page tools give it; the browser's own is from the document's. */
|
|
93
|
+
async screenshot(options = {}) {
|
|
94
|
+
const type = options.type ?? "png";
|
|
95
|
+
let clip;
|
|
96
|
+
if (options.clip) {
|
|
97
|
+
const scroll = await this.evaluate(() => ({ x: scrollX, y: scrollY })).catch(() => ({ x: 0, y: 0 }));
|
|
98
|
+
clip = { ...options.clip, x: options.clip.x + scroll.x, y: options.clip.y + scroll.y, scale: 1 };
|
|
99
|
+
}
|
|
100
|
+
else if (options.fullPage) {
|
|
101
|
+
const { cssContentSize } = await this.cdp("Page.getLayoutMetrics");
|
|
102
|
+
clip = { x: 0, y: 0, width: Math.ceil(cssContentSize.width), height: Math.ceil(cssContentSize.height), scale: 1 };
|
|
103
|
+
}
|
|
104
|
+
const { data } = await this.cdp("Page.captureScreenshot", {
|
|
105
|
+
format: type,
|
|
106
|
+
...(type === "jpeg" && options.quality !== undefined ? { quality: Math.round(options.quality) } : {}),
|
|
107
|
+
...(options.fullPage && !options.clip ? { captureBeyondViewport: true } : {}),
|
|
108
|
+
...(clip ? { clip } : {}),
|
|
109
|
+
});
|
|
110
|
+
return data;
|
|
111
|
+
}
|
|
112
|
+
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcha/pi-browser",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.35",
|
|
4
4
|
"description": "Your agent gets its own browser, and you can take over and hand it back.",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"pi-package",
|
|
7
6
|
"pi-durable",
|
|
8
7
|
"browser",
|
|
9
8
|
"stagehand",
|
|
@@ -13,7 +12,7 @@
|
|
|
13
12
|
"license": "Apache-2.0",
|
|
14
13
|
"author": "Parcha Labs, Inc.",
|
|
15
14
|
"engines": {
|
|
16
|
-
"node": ">=24.
|
|
15
|
+
"node": ">=24.22.3"
|
|
17
16
|
},
|
|
18
17
|
"exports": {
|
|
19
18
|
".": {
|
|
@@ -24,10 +23,6 @@
|
|
|
24
23
|
"types": "./dist/durable.d.ts",
|
|
25
24
|
"import": "./dist/durable.js"
|
|
26
25
|
},
|
|
27
|
-
"./recorder": {
|
|
28
|
-
"types": "./dist/recorder/index.d.ts",
|
|
29
|
-
"import": "./dist/recorder/index.js"
|
|
30
|
-
},
|
|
31
26
|
"./live-view": {
|
|
32
27
|
"types": "./dist/live-view/index.d.ts",
|
|
33
28
|
"import": "./dist/live-view/index.js"
|
|
@@ -48,10 +43,6 @@
|
|
|
48
43
|
"types": "./dist/providers/chrome-args.d.ts",
|
|
49
44
|
"import": "./dist/providers/chrome-args.js"
|
|
50
45
|
},
|
|
51
|
-
"./providers/assigned": {
|
|
52
|
-
"types": "./dist/providers/assigned.d.ts",
|
|
53
|
-
"import": "./dist/providers/assigned.js"
|
|
54
|
-
},
|
|
55
46
|
"./providers/kernel": {
|
|
56
47
|
"types": "./dist/providers/kernel.d.ts",
|
|
57
48
|
"import": "./dist/providers/kernel.js"
|
|
@@ -60,29 +51,25 @@
|
|
|
60
51
|
"types": "./dist/driver/stagehand.d.ts",
|
|
61
52
|
"import": "./dist/driver/stagehand.js"
|
|
62
53
|
},
|
|
54
|
+
"./driver/cdp": {
|
|
55
|
+
"types": "./dist/driver/cdp.d.ts",
|
|
56
|
+
"import": "./dist/driver/cdp.js"
|
|
57
|
+
},
|
|
63
58
|
"./testing": {
|
|
64
59
|
"types": "./dist/testing/index.d.ts",
|
|
65
60
|
"import": "./dist/testing/index.js"
|
|
66
|
-
},
|
|
67
|
-
"./coding-agent": {
|
|
68
|
-
"types": "./dist/coding-agent.d.ts",
|
|
69
|
-
"import": "./dist/coding-agent.js"
|
|
70
61
|
}
|
|
71
62
|
},
|
|
72
63
|
"files": [
|
|
73
64
|
"dist",
|
|
74
65
|
"!dist/**/*.map",
|
|
75
66
|
"src/vendor/stagehand-facade/UPSTREAM.json",
|
|
67
|
+
"src/vendor/browser-use-pi/UPSTREAM.json",
|
|
76
68
|
"CHANGELOG.md",
|
|
77
69
|
"LICENSE",
|
|
78
70
|
"NOTICE",
|
|
79
71
|
"README.md"
|
|
80
72
|
],
|
|
81
|
-
"pi": {
|
|
82
|
-
"extensions": [
|
|
83
|
-
"./dist/coding-agent.js"
|
|
84
|
-
]
|
|
85
|
-
},
|
|
86
73
|
"sideEffects": false,
|
|
87
74
|
"scripts": {
|
|
88
75
|
"build": "rm -rf dist && tsc -p tsconfig.json",
|
|
@@ -102,7 +89,6 @@
|
|
|
102
89
|
"peerDependencies": {
|
|
103
90
|
"@browserbasehq/sdk": ">=2.20.0 <3",
|
|
104
91
|
"@earendil-works/chord": "1.5.0",
|
|
105
|
-
"@earendil-works/pi-coding-agent": "*",
|
|
106
92
|
"@earendil-works/pi-durable": "1.5.0"
|
|
107
93
|
},
|
|
108
94
|
"peerDependenciesMeta": {
|
|
@@ -112,9 +98,6 @@
|
|
|
112
98
|
"@earendil-works/chord": {
|
|
113
99
|
"optional": true
|
|
114
100
|
},
|
|
115
|
-
"@earendil-works/pi-coding-agent": {
|
|
116
|
-
"optional": true
|
|
117
|
-
},
|
|
118
101
|
"@earendil-works/pi-durable": {
|
|
119
102
|
"optional": true
|
|
120
103
|
}
|
|
@@ -122,7 +105,6 @@
|
|
|
122
105
|
"devDependencies": {
|
|
123
106
|
"@earendil-works/chord": "1.5.0",
|
|
124
107
|
"@earendil-works/pi-ai": "1.5.0",
|
|
125
|
-
"@earendil-works/pi-coding-agent": "1.5.0",
|
|
126
108
|
"@earendil-works/pi-durable": "1.5.0"
|
|
127
109
|
},
|
|
128
110
|
"repository": {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"repo": "github.com/browser-use/browser-use-pi",
|
|
3
|
+
"path": "src",
|
|
4
|
+
"commit": "e7007f219b10fa2c2baae1bf3e2f902a5a2706fd",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"copyright": "Copyright (c) 2026 Browser Use contributors",
|
|
7
|
+
"adapted": "Each file is adapted, not copied byte for byte: its header says what changed.",
|
|
8
|
+
"files": {
|
|
9
|
+
"ax.ts": {
|
|
10
|
+
"from": "src/ax.ts",
|
|
11
|
+
"blob": "ff6136126eb4b569c24e42827c680f87ec0a2034",
|
|
12
|
+
"sha256": "b7464264115728b279f5a194b306c7390f5cb6b35a2c038ac192b363f37d1017"
|
|
13
|
+
},
|
|
14
|
+
"cdp.ts": {
|
|
15
|
+
"from": "src/cdp.ts",
|
|
16
|
+
"blob": "b1cf591aa32a4cebd0e8c139b54061d1ebc73e30",
|
|
17
|
+
"sha256": "64f6211e67ced581ccf8642bd08797094f3ff712129e66582b144f7a10f4bb1b"
|
|
18
|
+
},
|
|
19
|
+
"page.ts": {
|
|
20
|
+
"from": "src/page.ts",
|
|
21
|
+
"blob": "44494a6d31659a11f47dc1731afd894dda384dde",
|
|
22
|
+
"sha256": "aa80d16e22ea2a3b5bbaeae132f0915f45a628b61a0d0ff33decbcb592b3e2c9"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -15,10 +15,6 @@
|
|
|
15
15
|
"runtime.ts": {
|
|
16
16
|
"blob": "03242d1cabe18b0c13de8fc72766094bbb0560c9",
|
|
17
17
|
"sha256": "67e19f29a79d24d1cfeb73700d54beac9b07d43d6150e8f1b86e78ef010c8b82"
|
|
18
|
-
},
|
|
19
|
-
"screenshot-transport.ts": {
|
|
20
|
-
"blob": "065bff1dbc47ad50946f0bb98b5ceb5560a9626d",
|
|
21
|
-
"sha256": "a4c6b68225ae2fd61eb00e692b602a1d44f782eb676d86284d3ac5eb94b05406"
|
|
22
18
|
}
|
|
23
19
|
}
|
|
24
20
|
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { EvidenceSink } from "./core/evidence.js";
|
|
2
|
-
import type { WebBackup } from "./core/web.js";
|
|
3
|
-
export declare function findChrome(env?: NodeJS.ProcessEnv, exists?: (file: string) => boolean): string | null;
|
|
4
|
-
export declare function fileEvidenceSink(root: string, relativeTo: string): EvidenceSink;
|
|
5
|
-
export { isPrivateAddress, pinnedLookup } from "./core/public-fetch.js";
|
|
6
|
-
/** Public hosts only, so a page-steered agent never reaches the owner's private network: each redirect hop is resolved
|
|
7
|
-
* once, checked and dialled at that address. No cookies or credentials; at most 5 MiB. An HTML page is read by
|
|
8
|
-
* readPage, off the event loop: a page cut before it was read says so on its last line. */
|
|
9
|
-
export declare function httpBackup(options?: {
|
|
10
|
-
lookup?: (host: string) => Promise<string[]>;
|
|
11
|
-
fetchImpl?: (url: URL, init: Record<string, unknown>) => Promise<Response>;
|
|
12
|
-
}): WebBackup;
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { existsSync } from "node:fs";
|
|
2
|
-
import { mkdir, writeFile } from "node:fs/promises";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { publicFetch } from "./core/public-fetch.js";
|
|
5
|
-
import { READ_MAX_CHARS, readPage, thousands } from "./core/read-page.js";
|
|
6
|
-
const LINUX_NAMES = ["google-chrome", "google-chrome-stable", "chromium", "chromium-browser"];
|
|
7
|
-
export function findChrome(env = process.env, exists = existsSync) {
|
|
8
|
-
for (const named of [env.PI_BROWSER_CHROME, env.CHROME_PATH])
|
|
9
|
-
if (named && exists(named))
|
|
10
|
-
return named;
|
|
11
|
-
const onPath = (env.PATH ?? "").split(path.delimiter).filter(Boolean).flatMap((dir) => LINUX_NAMES.map((name) => path.join(dir, name)));
|
|
12
|
-
const fixed = ["/opt/google/chrome/chrome", "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"];
|
|
13
|
-
return [...onPath, ...fixed].find((file) => exists(file)) ?? null;
|
|
14
|
-
}
|
|
15
|
-
/** One path segment of `[A-Za-z0-9._-]`; a label of only dots (`.`, `..`) is never a directory name. */
|
|
16
|
-
const safe = (part) => {
|
|
17
|
-
const cleaned = part.replace(/[^A-Za-z0-9._-]+/g, "_").slice(0, 60);
|
|
18
|
-
return !cleaned ? "browser" : /^\.+$/.test(cleaned) ? `_${cleaned}` : cleaned;
|
|
19
|
-
};
|
|
20
|
-
export function fileEvidenceSink(root, relativeTo) {
|
|
21
|
-
let seq = 0;
|
|
22
|
-
return {
|
|
23
|
-
async file(label, record) {
|
|
24
|
-
try {
|
|
25
|
-
const dir = path.join(root, safe(label));
|
|
26
|
-
await mkdir(dir, { recursive: true });
|
|
27
|
-
const text = typeof record.body === "string";
|
|
28
|
-
const header = ["tool: " + record.tool, "args: " + JSON.stringify(record.args), "status: " + record.status,
|
|
29
|
-
...Object.entries(record.facts).filter(([, value]) => value !== undefined).map(([key, value]) => `${key}: ${value}`), "---"];
|
|
30
|
-
// A name is reserved with an exclusive create, so a later session (or a fork) never overwrites an earlier
|
|
31
|
-
// receipt.
|
|
32
|
-
for (;;) {
|
|
33
|
-
const stem = `${String(++seq).padStart(4, "0")}-${record.tool}`;
|
|
34
|
-
const [receipt, capture] = [path.join(dir, `${stem}.md`), path.join(dir, `${stem}.${record.ext ?? "bin"}`)];
|
|
35
|
-
try {
|
|
36
|
-
await writeFile(text ? receipt : capture, text ? `${header.join("\n")}\n${record.body}` : record.body, { flag: "wx" });
|
|
37
|
-
}
|
|
38
|
-
catch (error) {
|
|
39
|
-
if (error.code === "EEXIST")
|
|
40
|
-
continue;
|
|
41
|
-
throw error;
|
|
42
|
-
}
|
|
43
|
-
if (!text)
|
|
44
|
-
await writeFile(receipt, `${header.join("\n")}\n(the capture is ${path.basename(capture)})\n`);
|
|
45
|
-
const rel = (file) => path.relative(relativeTo, file).split(path.sep).join("/");
|
|
46
|
-
return { path: rel(receipt), bodyLine: text ? header.length + 1 : undefined, ...(text ? {} : { bodyPath: rel(capture) }) };
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
catch {
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
export { isPrivateAddress, pinnedLookup } from "./core/public-fetch.js";
|
|
56
|
-
/** Public hosts only, so a page-steered agent never reaches the owner's private network: each redirect hop is resolved
|
|
57
|
-
* once, checked and dialled at that address. No cookies or credentials; at most 5 MiB. An HTML page is read by
|
|
58
|
-
* readPage, off the event loop: a page cut before it was read says so on its last line. */
|
|
59
|
-
export function httpBackup(options = {}) {
|
|
60
|
-
return {
|
|
61
|
-
name: "http",
|
|
62
|
-
async fetch(url, signal) {
|
|
63
|
-
const answer = await publicFetch(url, { ...options, ...(signal ? { signal } : {}) });
|
|
64
|
-
if (answer.status < 200 || answer.status >= 300)
|
|
65
|
-
throw Object.assign(new Error(`the page answered ${answer.status}`), { status: answer.status });
|
|
66
|
-
if (!/html/i.test(answer.contentType))
|
|
67
|
-
return answer.body;
|
|
68
|
-
const page = await readPage(answer.body, answer.url, signal ? { signal } : {});
|
|
69
|
-
return page.truncated ? `${page.text}\n\n(Cut: the page is ${thousands(page.html_chars)} characters of HTML, and only its first ${thousands(READ_MAX_CHARS)}, scripts and styles aside, were read.)` : page.text;
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
}
|
package/dist/coding-agent.d.ts
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { type AttachedSession, type CustodyPort, type DriverFactory, type Overrides } from "./core/custody.js";
|
|
3
|
-
import type { BrowserConfig, BrowserPolicy, BrowserProvider, HandoffOutcome, HandoffPort, ReleaseReason, SiteRunPort, WorkspaceFiles } from "./core/host.js";
|
|
4
|
-
import { type Redact } from "./core/redact.js";
|
|
5
|
-
import { type VaultOptions, type VaultRuntime } from "./vault-session.js";
|
|
6
|
-
import type { VaultTarget } from "./core/vault.js";
|
|
7
|
-
import type { DrivingGates } from "./live-view/protocol.js";
|
|
8
|
-
import { type PageDriver } from "./core/tools.js";
|
|
9
|
-
import { type WebBackup } from "./core/web.js";
|
|
10
|
-
export { findChrome } from "./coding-agent-local.js";
|
|
11
|
-
export declare const SESSION_ENTRY = "browser.session";
|
|
12
|
-
export type CodingAgentOptions = VaultOptions & {
|
|
13
|
-
/** The saved sign-in this extension's browser restores and captures, and the origins it may touch: the host's choice, never the model's. Needs `sessionVault`. */
|
|
14
|
-
vault?: VaultTarget;
|
|
15
|
-
/** Default: chosen by the `--browser-*` flags and `PI_BROWSER_*` when the session starts. */
|
|
16
|
-
provider?: BrowserProvider | (() => BrowserProvider | Promise<BrowserProvider>);
|
|
17
|
-
/** Default: the Stagehand driver. */
|
|
18
|
-
driver?: DriverFactory<PageDriver>;
|
|
19
|
-
policy?: Partial<BrowserPolicy>;
|
|
20
|
-
/** The person/model mutex shared with the live view (`createLiveView`'s `gates`); the default, the package's process-wide `drivingGates`, is the one the live view
|
|
21
|
-
* defaults to as well. Pass it here only together with the same registry there. */
|
|
22
|
-
gates?: DrivingGates;
|
|
23
|
-
/** Fetchers tried when the provider cannot fetch a page. Default: a plain HTTP read of public hosts. */
|
|
24
|
-
backups?: ReadonlyArray<WebBackup>;
|
|
25
|
-
env?: NodeJS.ProcessEnv;
|
|
26
|
-
/** `use_website`'s sites; absent, the tool is not listed. Each child is a pi session with this extension and no
|
|
27
|
-
* use_website, started through pi's SDK and disposed, so its browser released, when it reports. */
|
|
28
|
-
sites?: SiteRunPort;
|
|
29
|
-
/** Reaches a person for `browser_request_handoff`; absent, the tool is not listed. */
|
|
30
|
-
handoff?: HandoffPort;
|
|
31
|
-
/** Resolves `browser_upload` paths. Default: files under the session's working directory. */
|
|
32
|
-
files?: WorkspaceFiles;
|
|
33
|
-
/** Lists `browser_upload` and `browser_downloads`. Default true; a use_website child gets neither. */
|
|
34
|
-
fileTools?: boolean;
|
|
35
|
-
};
|
|
36
|
-
type Deps = {
|
|
37
|
-
config: BrowserConfig;
|
|
38
|
-
/** The live view's driving gates (default: the package's process-wide ones). */
|
|
39
|
-
gates?: DrivingGates;
|
|
40
|
-
provider: () => Promise<BrowserProvider>;
|
|
41
|
-
driver: DriverFactory<PageDriver>;
|
|
42
|
-
keep: (customType: string, data: unknown) => void;
|
|
43
|
-
redact: Redact;
|
|
44
|
-
signal: AbortSignal;
|
|
45
|
-
handoff?: HandoffPort;
|
|
46
|
-
/** The host's session vault and the sign-in it keeps for this session, when it gave them. */
|
|
47
|
-
vault?: VaultRuntime | null;
|
|
48
|
-
vaultTarget?: VaultTarget;
|
|
49
|
-
};
|
|
50
|
-
export declare class LocalCustody implements CustodyPort<PageDriver> {
|
|
51
|
-
private readonly d;
|
|
52
|
-
private live;
|
|
53
|
-
/** Browsers that are gone whose directories are not: each is released again as cleanup, never kept as the live session. */
|
|
54
|
-
private leftovers;
|
|
55
|
-
/** The last session this custody released, so a release asked after it can say how and when it ended. */
|
|
56
|
-
private lastReleased;
|
|
57
|
-
private seq;
|
|
58
|
-
private notice;
|
|
59
|
-
/** The session an idle release ended, told with its notice and named while its replacement has loaded no page; any
|
|
60
|
-
* other release ends it, and a failed launch never touches it. */
|
|
61
|
-
private replacedBy;
|
|
62
|
-
private readonly queue;
|
|
63
|
-
private readonly idle;
|
|
64
|
-
/** The poll of a session the idle timer kept for a person (#1098): stopped when the session is released or closed. */
|
|
65
|
-
private leaving;
|
|
66
|
-
constructor(d: Deps);
|
|
67
|
-
private serial;
|
|
68
|
-
private save;
|
|
69
|
-
private failure;
|
|
70
|
-
/** Release every session the branch's entries leave open (a browser a crashed process left running); never adopted. */
|
|
71
|
-
releaseOrphans(entries: ReadonlyArray<{
|
|
72
|
-
type: string;
|
|
73
|
-
customType?: string;
|
|
74
|
-
data?: any;
|
|
75
|
-
}>): Promise<void>;
|
|
76
|
-
private attached;
|
|
77
|
-
private launch;
|
|
78
|
-
/** A release the provider fails leaves the session held, so a later release, the shutdown or the next start can retry it. The exception is a
|
|
79
|
-
* release that says the browser is gone and only a directory is left (`profile_not_removed`): that session is over (it is never the live
|
|
80
|
-
* one again), its record stays open for the directory, which is released again by the next release, the shutdown or the next start; the
|
|
81
|
-
* caller is still told what is left. */
|
|
82
|
-
/** The vault capture of a session while its browser exists; skipped while a person is driving it. Never throws. */
|
|
83
|
-
private captured;
|
|
84
|
-
private finish;
|
|
85
|
-
private refuseHeld;
|
|
86
|
-
/** Releases again each browser that is gone and whose directory was left; one that still cannot be removed stays for the next time, and the
|
|
87
|
-
* last such failure is returned for a caller that was asked to release. */
|
|
88
|
-
private sweepLeftovers;
|
|
89
|
-
private retireEnded;
|
|
90
|
-
session(signal?: AbortSignal): Promise<AttachedSession<PageDriver>>;
|
|
91
|
-
current(): Promise<string | null>;
|
|
92
|
-
relaunch(overrides: Overrides): Promise<AttachedSession<PageDriver>>;
|
|
93
|
-
release(): Promise<{
|
|
94
|
-
released: boolean;
|
|
95
|
-
sessionId: string | null;
|
|
96
|
-
ended?: {
|
|
97
|
-
reason: ReleaseReason;
|
|
98
|
-
at: string | null;
|
|
99
|
-
};
|
|
100
|
-
}>;
|
|
101
|
-
/** Releases without failing the caller; idempotent. */
|
|
102
|
-
close(reason: ReleaseReason): Promise<void>;
|
|
103
|
-
hold(requestId: string): Promise<{
|
|
104
|
-
tag: string;
|
|
105
|
-
sessionId: string;
|
|
106
|
-
}>;
|
|
107
|
-
resume(notice: string | null): Promise<void>;
|
|
108
|
-
dispatching(): Promise<void>;
|
|
109
|
-
journal(): Promise<void>;
|
|
110
|
-
mark(): Promise<void>;
|
|
111
|
-
settle(): Promise<void>;
|
|
112
|
-
navigated(url: string): Promise<void>;
|
|
113
|
-
ended(): Promise<boolean>;
|
|
114
|
-
unreachable(): Promise<{
|
|
115
|
-
released: boolean;
|
|
116
|
-
lastUrl: string | null;
|
|
117
|
-
kept?: "held" | "viewing" | "person_driving";
|
|
118
|
-
}>;
|
|
119
|
-
/** Blocks on the port until the person answers or the call is aborted; the session comes back either way. */
|
|
120
|
-
handoff(ask: {
|
|
121
|
-
requestId: string;
|
|
122
|
-
instruction: string;
|
|
123
|
-
completionCondition: string;
|
|
124
|
-
}, signal?: AbortSignal): Promise<{
|
|
125
|
-
outcome: HandoffOutcome;
|
|
126
|
-
reason?: string;
|
|
127
|
-
} | {
|
|
128
|
-
refused: string;
|
|
129
|
-
}>;
|
|
130
|
-
dropped(): Promise<void>;
|
|
131
|
-
/** A session left idle is released after the policy's idle spell. */
|
|
132
|
-
activity(delta: 1 | -1): void;
|
|
133
|
-
}
|
|
134
|
-
export declare function createBrowserExtension(options?: CodingAgentOptions): (pi: ExtensionAPI) => void;
|
|
135
|
-
export default function piBrowser(pi: ExtensionAPI): void;
|