@parcha/pi-browser 0.0.0-stage → 0.1.0-beta.14
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 +23 -0
- package/LICENSE +202 -0
- package/NOTICE +33 -0
- package/README.md +348 -2
- package/dist/coding-agent-local.d.ts +16 -0
- package/dist/coding-agent-local.js +138 -0
- package/dist/coding-agent.d.ts +79 -0
- package/dist/coding-agent.js +448 -0
- package/dist/core/contract.d.ts +26 -0
- package/dist/core/contract.js +154 -0
- package/dist/core/custody.d.ts +117 -0
- package/dist/core/custody.js +126 -0
- package/dist/core/decisions.d.ts +43 -0
- package/dist/core/decisions.js +4 -0
- package/dist/core/downloads.d.ts +35 -0
- package/dist/core/downloads.js +131 -0
- package/dist/core/effects.d.ts +63 -0
- package/dist/core/effects.js +256 -0
- package/dist/core/evidence.d.ts +43 -0
- package/dist/core/evidence.js +6 -0
- package/dist/core/failures.d.ts +36 -0
- package/dist/core/failures.js +68 -0
- package/dist/core/find.d.ts +32 -0
- package/dist/core/find.js +179 -0
- package/dist/core/guard.d.ts +6 -0
- package/dist/core/guard.js +25 -0
- package/dist/core/host.d.ts +328 -0
- package/dist/core/host.js +2 -0
- package/dist/core/images.d.ts +37 -0
- package/dist/core/images.js +60 -0
- package/dist/core/lease.d.ts +16 -0
- package/dist/core/lease.js +30 -0
- package/dist/core/receipts.d.ts +19 -0
- package/dist/core/receipts.js +22 -0
- package/dist/core/redact.d.ts +13 -0
- package/dist/core/redact.js +83 -0
- package/dist/core/session-control.d.ts +25 -0
- package/dist/core/session-control.js +75 -0
- package/dist/core/sites.d.ts +33 -0
- package/dist/core/sites.js +102 -0
- package/dist/core/tools.d.ts +72 -0
- package/dist/core/tools.js +200 -0
- package/dist/core/uri.d.ts +11 -0
- package/dist/core/uri.js +37 -0
- package/dist/core/usage.d.ts +19 -0
- package/dist/core/usage.js +44 -0
- package/dist/core/web.d.ts +98 -0
- package/dist/core/web.js +327 -0
- package/dist/driver/extension-worker.d.ts +6 -0
- package/dist/driver/extension-worker.js +121 -0
- package/dist/driver/stagehand.d.ts +25 -0
- package/dist/driver/stagehand.js +91 -0
- package/dist/durable-result.d.ts +6 -0
- package/dist/durable-result.js +2 -0
- package/dist/durable.d.ts +79 -0
- package/dist/durable.js +582 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +20 -0
- package/dist/providers/browserbase-net.d.ts +13 -0
- package/dist/providers/browserbase-net.js +96 -0
- package/dist/providers/browserbase.d.ts +152 -0
- package/dist/providers/browserbase.js +262 -0
- package/dist/providers/cdp-call.d.ts +6 -0
- package/dist/providers/cdp-call.js +25 -0
- package/dist/providers/cdp.d.ts +55 -0
- package/dist/providers/cdp.js +423 -0
- package/dist/providers/http.d.ts +2 -0
- package/dist/providers/http.js +21 -0
- package/dist/providers/kernel.d.ts +49 -0
- package/dist/providers/kernel.js +246 -0
- package/dist/providers/shared.d.ts +47 -0
- package/dist/providers/shared.js +82 -0
- package/dist/recorder/credential.d.ts +9 -0
- package/dist/recorder/credential.js +49 -0
- package/dist/recorder/follow.d.ts +26 -0
- package/dist/recorder/follow.js +138 -0
- package/dist/recorder/frames.d.ts +80 -0
- package/dist/recorder/frames.js +309 -0
- package/dist/recorder/index.d.ts +4 -0
- package/dist/recorder/index.js +7 -0
- package/dist/recorder/jpeg.d.ts +8 -0
- package/dist/recorder/jpeg.js +70 -0
- package/dist/recorder/track.d.ts +107 -0
- package/dist/recorder/track.js +259 -0
- package/dist/store.d.ts +56 -0
- package/dist/store.js +196 -0
- package/dist/testing/backend.d.ts +231 -0
- package/dist/testing/backend.js +414 -0
- package/dist/testing/driver.d.ts +28 -0
- package/dist/testing/driver.js +32 -0
- package/dist/testing/index.d.ts +4 -0
- package/dist/testing/index.js +4 -0
- package/dist/testing/pages.d.ts +3 -0
- package/dist/testing/pages.js +10 -0
- package/dist/testing/sentinels.d.ts +29 -0
- package/dist/testing/sentinels.js +38 -0
- package/dist/vendor/stagehand-facade/contract.d.ts +348 -0
- package/dist/vendor/stagehand-facade/contract.js +155 -0
- package/dist/vendor/stagehand-facade/runtime.d.ts +90 -0
- package/dist/vendor/stagehand-facade/runtime.js +1640 -0
- package/dist/vendor/stagehand-facade/screenshot-transport.d.ts +15 -0
- package/dist/vendor/stagehand-facade/screenshot-transport.js +51 -0
- package/dist/vendor/stagehand-facade/tools.d.ts +31 -0
- package/dist/vendor/stagehand-facade/tools.js +139 -0
- package/dist/web.d.ts +41 -0
- package/dist/web.js +38 -0
- package/package.json +123 -4
- package/src/vendor/stagehand-facade/UPSTREAM.json +24 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { StagehandFacadeScreenshot } from "./tools.js";
|
|
2
|
+
export type ScreenshotOptions = {
|
|
3
|
+
fullPage?: boolean;
|
|
4
|
+
type?: "png" | "jpeg";
|
|
5
|
+
quality?: number;
|
|
6
|
+
};
|
|
7
|
+
type CaptureScreenshot = (options: ScreenshotOptions) => Promise<StagehandFacadeScreenshot>;
|
|
8
|
+
export type TransportSafeScreenshot = {
|
|
9
|
+
image: StagehandFacadeScreenshot;
|
|
10
|
+
options: ScreenshotOptions;
|
|
11
|
+
adjusted: boolean;
|
|
12
|
+
};
|
|
13
|
+
export declare function screenshotBase64BudgetFromArgs(args: string[]): number | undefined;
|
|
14
|
+
export declare function captureScreenshotWithinBase64Budget(capture: CaptureScreenshot, requested: ScreenshotOptions, maxBase64Bytes: number): Promise<TransportSafeScreenshot>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
const SCREENSHOT_BUDGET_FLAG = "--max-screenshot-base64-bytes=";
|
|
2
|
+
export function screenshotBase64BudgetFromArgs(args) {
|
|
3
|
+
const value = args.find((arg) => arg.startsWith(SCREENSHOT_BUDGET_FLAG));
|
|
4
|
+
if (value === undefined)
|
|
5
|
+
return undefined;
|
|
6
|
+
const budget = Number(value.slice(SCREENSHOT_BUDGET_FLAG.length));
|
|
7
|
+
if (!Number.isSafeInteger(budget) || budget < 1_024) {
|
|
8
|
+
throw new Error(`${SCREENSHOT_BUDGET_FLAG} must be an integer of at least 1024.`);
|
|
9
|
+
}
|
|
10
|
+
return budget;
|
|
11
|
+
}
|
|
12
|
+
export async function captureScreenshotWithinBase64Budget(capture, requested, maxBase64Bytes) {
|
|
13
|
+
const attempts = screenshotAttempts(requested);
|
|
14
|
+
for (const [index, options] of attempts.entries()) {
|
|
15
|
+
const image = await capture(options);
|
|
16
|
+
if (Buffer.byteLength(image.data, "utf8") <= maxBase64Bytes) {
|
|
17
|
+
return { image, options, adjusted: index > 0 || !sameOptions(options, requested) };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
throw new Error(`Screenshot exceeds the ${maxBase64Bytes}-byte MCP transport budget after compressed viewport retries.`);
|
|
21
|
+
}
|
|
22
|
+
function screenshotAttempts(requested) {
|
|
23
|
+
const initial = {
|
|
24
|
+
fullPage: requested.fullPage ?? false,
|
|
25
|
+
type: requested.type ?? "jpeg",
|
|
26
|
+
...(requested.type === "png" ? {} : { quality: requested.quality ?? 40 }),
|
|
27
|
+
};
|
|
28
|
+
const maxFallbackQuality = requested.type === "png" ? 40 : (requested.quality ?? 40);
|
|
29
|
+
const attempts = [
|
|
30
|
+
initial,
|
|
31
|
+
{
|
|
32
|
+
fullPage: false,
|
|
33
|
+
type: "jpeg",
|
|
34
|
+
quality: Math.min(maxFallbackQuality, 40),
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
fullPage: false,
|
|
38
|
+
type: "jpeg",
|
|
39
|
+
quality: Math.min(maxFallbackQuality, 25),
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
fullPage: false,
|
|
43
|
+
type: "jpeg",
|
|
44
|
+
quality: Math.min(maxFallbackQuality, 10),
|
|
45
|
+
},
|
|
46
|
+
];
|
|
47
|
+
return attempts.filter((candidate, index) => attempts.findIndex((other) => sameOptions(candidate, other)) === index);
|
|
48
|
+
}
|
|
49
|
+
function sameOptions(left, right) {
|
|
50
|
+
return (left.fullPage === right.fullPage && left.type === right.type && left.quality === right.quality);
|
|
51
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Stagehand } from "@browserbasehq/stagehand";
|
|
2
|
+
import { type RefAction } from "./contract.js";
|
|
3
|
+
export type StagehandFacadeScreenshot = {
|
|
4
|
+
data: string;
|
|
5
|
+
mimeType: "image/png" | "image/jpeg";
|
|
6
|
+
};
|
|
7
|
+
export declare class StagehandFacadeTools {
|
|
8
|
+
private readonly stagehand;
|
|
9
|
+
private readonly snapshotsByPage;
|
|
10
|
+
private queue;
|
|
11
|
+
constructor(stagehand: Stagehand);
|
|
12
|
+
snapshot(options?: {
|
|
13
|
+
includeIframes?: boolean;
|
|
14
|
+
}): Promise<string>;
|
|
15
|
+
screenshot(options?: {
|
|
16
|
+
fullPage?: boolean;
|
|
17
|
+
type?: "png" | "jpeg";
|
|
18
|
+
quality?: number;
|
|
19
|
+
}): Promise<StagehandFacadeScreenshot>;
|
|
20
|
+
runActions(actions: RefAction[]): Promise<{
|
|
21
|
+
completed: number;
|
|
22
|
+
url: string;
|
|
23
|
+
}>;
|
|
24
|
+
run(code: string): Promise<unknown>;
|
|
25
|
+
private snapshotNow;
|
|
26
|
+
private screenshotNow;
|
|
27
|
+
private runActionsNow;
|
|
28
|
+
private runNow;
|
|
29
|
+
private activePage;
|
|
30
|
+
private enqueue;
|
|
31
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { NAVIGATED_SNAPSHOT_ERROR, NO_HYDRATED_SNAPSHOT_ERROR, RefActionSchema, staleSnapshotIdError, } from "./contract.js";
|
|
2
|
+
import { createPlaywrightCompatRuntime } from "./runtime.js";
|
|
3
|
+
const AsyncFunction = Object.getPrototypeOf(async function () { }).constructor;
|
|
4
|
+
const ACTION_RUNNER_SOURCE = `"use strict";
|
|
5
|
+
let completed = 0;
|
|
6
|
+
for (const action of input.actions) {
|
|
7
|
+
const locator = stagehand.page.locator(action.selector);
|
|
8
|
+
switch (action.op) {
|
|
9
|
+
case "click": await locator.click(); break;
|
|
10
|
+
case "hover": await locator.hover(); break;
|
|
11
|
+
case "fill": await locator.fill(action.value); break;
|
|
12
|
+
case "type": await locator.type(action.text, action.delay === undefined ? undefined : { delay: action.delay }); break;
|
|
13
|
+
case "press": await locator.click(); await stagehand.page.keyPress(action.key); break;
|
|
14
|
+
case "select": await locator.selectOption(action.values); break;
|
|
15
|
+
default: throw new Error("Unsupported ref action: " + String(action.op));
|
|
16
|
+
}
|
|
17
|
+
completed += 1;
|
|
18
|
+
}
|
|
19
|
+
return { completed };`;
|
|
20
|
+
const actionRunner = new AsyncFunction("stagehand", "input", ACTION_RUNNER_SOURCE);
|
|
21
|
+
const FACADE_PRELUDE = `"use strict";
|
|
22
|
+
const __stagehandCompatIdentity = (target) => target;
|
|
23
|
+
for (let index = 0; index <= 32; index += 1) {
|
|
24
|
+
globalThis[index === 0 ? "__name" : "__name" + index] = __stagehandCompatIdentity;
|
|
25
|
+
}
|
|
26
|
+
const createRuntime = ${createPlaywrightCompatRuntime.toString()};
|
|
27
|
+
const runtime = await createRuntime(batchStagehand);
|
|
28
|
+
const page = runtime.page;
|
|
29
|
+
const context = runtime.context;
|
|
30
|
+
const browser = runtime.browser;
|
|
31
|
+
const console = globalThis.console;
|
|
32
|
+
let value;
|
|
33
|
+
let executionError;
|
|
34
|
+
try {
|
|
35
|
+
value = await (async () => { `;
|
|
36
|
+
const FACADE_EPILOGUE = `
|
|
37
|
+
})();
|
|
38
|
+
} catch (error) {
|
|
39
|
+
executionError = {
|
|
40
|
+
name: typeof error?.name === "string" ? error.name : "Error",
|
|
41
|
+
message: typeof error?.message === "string" ? error.message : String(error),
|
|
42
|
+
...(typeof error?.stack === "string" ? { stack: error.stack } : {}),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
__stagehandPlaywrightCompat: true,
|
|
47
|
+
value,
|
|
48
|
+
executionError,
|
|
49
|
+
};`;
|
|
50
|
+
export class StagehandFacadeTools {
|
|
51
|
+
stagehand;
|
|
52
|
+
snapshotsByPage = new Map();
|
|
53
|
+
queue = Promise.resolve();
|
|
54
|
+
constructor(stagehand) {
|
|
55
|
+
this.stagehand = stagehand;
|
|
56
|
+
}
|
|
57
|
+
snapshot(options = {}) {
|
|
58
|
+
return this.enqueue(() => this.snapshotNow(options));
|
|
59
|
+
}
|
|
60
|
+
screenshot(options = {}) {
|
|
61
|
+
return this.enqueue(() => this.screenshotNow(options));
|
|
62
|
+
}
|
|
63
|
+
runActions(actions) {
|
|
64
|
+
return this.enqueue(() => this.runActionsNow(actions));
|
|
65
|
+
}
|
|
66
|
+
run(code) {
|
|
67
|
+
return this.enqueue(() => this.runNow(code));
|
|
68
|
+
}
|
|
69
|
+
async snapshotNow(options) {
|
|
70
|
+
const page = await this.activePage();
|
|
71
|
+
const snapshot = await page.snapshot({ includeIframes: options.includeIframes ?? true });
|
|
72
|
+
this.snapshotsByPage.set(page.pageId, {
|
|
73
|
+
url: await page.url(),
|
|
74
|
+
xpathById: { ...snapshot.xpathMap },
|
|
75
|
+
});
|
|
76
|
+
return snapshot.formattedTree;
|
|
77
|
+
}
|
|
78
|
+
async screenshotNow(options) {
|
|
79
|
+
const page = await this.activePage();
|
|
80
|
+
const type = options.type ?? "png";
|
|
81
|
+
// CDP only accepts quality for jpeg, and only as an integer.
|
|
82
|
+
const quality = type === "jpeg" && options.quality !== undefined ? Math.round(options.quality) : undefined;
|
|
83
|
+
const bytes = await page.screenshot({
|
|
84
|
+
type,
|
|
85
|
+
...(options.fullPage === undefined ? {} : { fullPage: options.fullPage }),
|
|
86
|
+
...(quality === undefined ? {} : { quality }),
|
|
87
|
+
});
|
|
88
|
+
return {
|
|
89
|
+
data: Buffer.from(bytes).toString("base64"),
|
|
90
|
+
mimeType: type === "jpeg" ? "image/jpeg" : "image/png",
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
async runActionsNow(actions) {
|
|
94
|
+
const parsed = RefActionSchema.array().min(1).parse(actions);
|
|
95
|
+
const page = await this.activePage();
|
|
96
|
+
const snapshot = this.snapshotsByPage.get(page.pageId);
|
|
97
|
+
if (!snapshot)
|
|
98
|
+
throw new Error(NO_HYDRATED_SNAPSHOT_ERROR);
|
|
99
|
+
if ((await page.url()) !== snapshot.url) {
|
|
100
|
+
this.snapshotsByPage.delete(page.pageId);
|
|
101
|
+
throw new Error(NAVIGATED_SNAPSHOT_ERROR);
|
|
102
|
+
}
|
|
103
|
+
const hydrated = parsed.map((action) => {
|
|
104
|
+
const xpath = trimTrailingTextNode(snapshot.xpathById[action.id]);
|
|
105
|
+
if (!xpath)
|
|
106
|
+
throw new Error(staleSnapshotIdError(action.id));
|
|
107
|
+
return { ...action, selector: `xpath=${xpath}` };
|
|
108
|
+
});
|
|
109
|
+
const result = await this.stagehand.experimentalBatch(actionRunner, { actions: hydrated }, { page, timeout: 60_000 });
|
|
110
|
+
return { completed: result?.completed ?? hydrated.length, url: await page.url() };
|
|
111
|
+
}
|
|
112
|
+
async runNow(code) {
|
|
113
|
+
const page = await this.activePage();
|
|
114
|
+
const callback = new AsyncFunction("batchStagehand", "input", FACADE_PRELUDE + code + FACADE_EPILOGUE);
|
|
115
|
+
const envelope = await this.stagehand.experimentalBatch(callback, {}, { page, timeout: 60_000 });
|
|
116
|
+
if (envelope.executionError) {
|
|
117
|
+
const error = new Error(envelope.executionError.message);
|
|
118
|
+
error.name = envelope.executionError.name;
|
|
119
|
+
if (envelope.executionError.stack)
|
|
120
|
+
error.stack = envelope.executionError.stack;
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
return envelope.value;
|
|
124
|
+
}
|
|
125
|
+
async activePage() {
|
|
126
|
+
const page = await this.stagehand.browser.context.activePage();
|
|
127
|
+
if (!page)
|
|
128
|
+
throw new Error("Stagehand has no active page.");
|
|
129
|
+
return page;
|
|
130
|
+
}
|
|
131
|
+
enqueue(operation) {
|
|
132
|
+
const result = this.queue.then(operation, operation);
|
|
133
|
+
this.queue = result.then(() => undefined, () => undefined);
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function trimTrailingTextNode(path) {
|
|
138
|
+
return path?.replace(/\/text\(\)(\[\d+\])?$/iu, "");
|
|
139
|
+
}
|
package/dist/web.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { defineExtension, type ConversationId, type ToolRegistration } from "@earendil-works/pi-durable";
|
|
2
|
+
import type { Decisions } from "./core/decisions.js";
|
|
3
|
+
import type { EvidenceSink } from "./core/evidence.js";
|
|
4
|
+
import type { FetchRequest, FetchResult, PriceTable, SearchRequest, SearchResult } from "./core/host.js";
|
|
5
|
+
import { type RenderedPage, type WebBackup, type WebToolsOptions } from "./core/web.js";
|
|
6
|
+
export type WebExtensionOptions = {
|
|
7
|
+
providers: {
|
|
8
|
+
/** Names the source in `via` (`<name>_fetch`, `<name>_search`); default "provider". */
|
|
9
|
+
name?: string;
|
|
10
|
+
fetch?: (request: FetchRequest, signal?: AbortSignal) => Promise<FetchResult>;
|
|
11
|
+
search?: (request: SearchRequest, signal?: AbortSignal) => Promise<SearchResult>;
|
|
12
|
+
};
|
|
13
|
+
evidence: EvidenceSink;
|
|
14
|
+
/** Per use: evidence label and proxies. Default: label "web", proxies on. */
|
|
15
|
+
scope?: (conversationId: ConversationId) => {
|
|
16
|
+
label: string;
|
|
17
|
+
proxies: boolean;
|
|
18
|
+
} | Promise<{
|
|
19
|
+
label: string;
|
|
20
|
+
proxies: boolean;
|
|
21
|
+
}>;
|
|
22
|
+
prices?: Partial<PriceTable>;
|
|
23
|
+
redact?: {
|
|
24
|
+
values: () => readonly string[];
|
|
25
|
+
};
|
|
26
|
+
/** The host's fallback fetchers, tried in order when the provider cannot fetch a page. */
|
|
27
|
+
backups?: ReadonlyArray<WebBackup>;
|
|
28
|
+
decisions?: Pick<Decisions, "classifyPage">;
|
|
29
|
+
render?: {
|
|
30
|
+
enabled: boolean;
|
|
31
|
+
read(url: string, signal?: AbortSignal): Promise<RenderedPage>;
|
|
32
|
+
};
|
|
33
|
+
pdf?: WebToolsOptions["pdf"];
|
|
34
|
+
section?: {
|
|
35
|
+
addendum?: string;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
export declare function createWebExtension(options: WebExtensionOptions): {
|
|
39
|
+
extension: ReturnType<typeof defineExtension>;
|
|
40
|
+
tools: readonly ToolRegistration[];
|
|
41
|
+
};
|
package/dist/web.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { defineExtension, defineTool } from "@earendil-works/pi-durable";
|
|
2
|
+
import { WEB_TOOLS } from "./core/contract.js";
|
|
3
|
+
import { providerKeyValues } from "./core/session-control.js";
|
|
4
|
+
import { createWebTools } from "./core/web.js";
|
|
5
|
+
import { forModel } from "./durable-result.js";
|
|
6
|
+
const usage = (usd) => ({ input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0, cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: usd } });
|
|
7
|
+
export function createWebExtension(options) {
|
|
8
|
+
const tools = createWebTools({
|
|
9
|
+
name: options.providers.name ?? "provider",
|
|
10
|
+
fetch: options.providers.fetch,
|
|
11
|
+
search: options.providers.search,
|
|
12
|
+
evidence: options.evidence,
|
|
13
|
+
scope: options.scope ?? (() => ({ label: "web", proxies: true })),
|
|
14
|
+
prices: options.prices,
|
|
15
|
+
redact: { values: () => providerKeyValues(process.env, options.redact?.values) },
|
|
16
|
+
backups: options.backups,
|
|
17
|
+
classifyPage: options.decisions?.classifyPage,
|
|
18
|
+
render: options.render,
|
|
19
|
+
pdf: options.pdf,
|
|
20
|
+
});
|
|
21
|
+
const run = { web_fetch: tools.fetch, web_search: tools.search };
|
|
22
|
+
const result = ({ text, isError, details, usd }) => ({ ...forModel([{ type: "text", text }]), isError, details: details, usage: usage(usd) });
|
|
23
|
+
const registrations = WEB_TOOLS
|
|
24
|
+
.filter((tool) => (tool.listedWhen === "fetch" ? options.providers.fetch || options.render?.enabled || options.backups?.length : options.providers.search))
|
|
25
|
+
.map((tool) => defineTool({
|
|
26
|
+
name: tool.name,
|
|
27
|
+
description: tool.description,
|
|
28
|
+
parameters: tool.parameters,
|
|
29
|
+
replay: tool.replay,
|
|
30
|
+
executionMode: tool.executionMode,
|
|
31
|
+
execute: async (args, api, context) => result(await run[tool.name](api.conversationId, args, context.abortSignal)),
|
|
32
|
+
}));
|
|
33
|
+
// Matched by name: another extension's tool registered under the same name would carry the text too.
|
|
34
|
+
const names = new Set(registrations.map((tool) => tool.name));
|
|
35
|
+
const addendum = options.section?.addendum;
|
|
36
|
+
const sections = addendum ? [{ key: "web", render: async (input) => (input.agent.tools.some((tool) => names.has(tool.name)) ? addendum : undefined) }] : [];
|
|
37
|
+
return { extension: defineExtension({ name: "web", tools: registrations, sections }), tools: registrations };
|
|
38
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,125 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcha/pi-browser",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0-beta.14",
|
|
4
|
+
"description": "A durable browser for pi agents: session custody that survives crashes, effect and replay classes per tool, evidence with SHA-256, typed failures, and no credential in any model-visible string.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pi-package",
|
|
7
|
+
"pi-durable",
|
|
8
|
+
"browser",
|
|
9
|
+
"stagehand",
|
|
10
|
+
"browserbase"
|
|
11
|
+
],
|
|
12
|
+
"type": "module",
|
|
13
|
+
"license": "Apache-2.0",
|
|
14
|
+
"author": "Parcha Labs, Inc.",
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=22.19.0"
|
|
17
|
+
},
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./durable": {
|
|
24
|
+
"types": "./dist/durable.d.ts",
|
|
25
|
+
"import": "./dist/durable.js"
|
|
26
|
+
},
|
|
27
|
+
"./recorder": {
|
|
28
|
+
"types": "./dist/recorder/index.d.ts",
|
|
29
|
+
"import": "./dist/recorder/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./providers/browserbase": {
|
|
32
|
+
"types": "./dist/providers/browserbase.d.ts",
|
|
33
|
+
"import": "./dist/providers/browserbase.js"
|
|
34
|
+
},
|
|
35
|
+
"./providers/cdp": {
|
|
36
|
+
"types": "./dist/providers/cdp.d.ts",
|
|
37
|
+
"import": "./dist/providers/cdp.js"
|
|
38
|
+
},
|
|
39
|
+
"./providers/kernel": {
|
|
40
|
+
"types": "./dist/providers/kernel.d.ts",
|
|
41
|
+
"import": "./dist/providers/kernel.js"
|
|
42
|
+
},
|
|
43
|
+
"./driver/stagehand": {
|
|
44
|
+
"types": "./dist/driver/stagehand.d.ts",
|
|
45
|
+
"import": "./dist/driver/stagehand.js"
|
|
46
|
+
},
|
|
47
|
+
"./testing": {
|
|
48
|
+
"types": "./dist/testing/index.d.ts",
|
|
49
|
+
"import": "./dist/testing/index.js"
|
|
50
|
+
},
|
|
51
|
+
"./coding-agent": {
|
|
52
|
+
"types": "./dist/coding-agent.d.ts",
|
|
53
|
+
"import": "./dist/coding-agent.js"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"files": [
|
|
57
|
+
"dist",
|
|
58
|
+
"!dist/**/*.map",
|
|
59
|
+
"src/vendor/stagehand-facade/UPSTREAM.json",
|
|
60
|
+
"CHANGELOG.md",
|
|
61
|
+
"LICENSE",
|
|
62
|
+
"NOTICE",
|
|
63
|
+
"README.md"
|
|
64
|
+
],
|
|
65
|
+
"pi": {
|
|
66
|
+
"extensions": [
|
|
67
|
+
"./dist/coding-agent.js"
|
|
68
|
+
]
|
|
69
|
+
},
|
|
70
|
+
"sideEffects": false,
|
|
71
|
+
"scripts": {
|
|
72
|
+
"build": "rm -rf dist && tsc -p tsconfig.json",
|
|
73
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
74
|
+
"test": "node scripts/run-tests.mjs",
|
|
75
|
+
"test:chrome": "node scripts/run-tests.mjs --chrome",
|
|
76
|
+
"verify:tarball": "node scripts/verify-tarball.mjs"
|
|
77
|
+
},
|
|
78
|
+
"dependencies": {
|
|
79
|
+
"@browserbasehq/stagehand": "~4.1.0",
|
|
80
|
+
"node-html-markdown": "^2.0.0",
|
|
81
|
+
"node-html-parser": "^6.1.13",
|
|
82
|
+
"undici": "^6.28.0",
|
|
83
|
+
"zod": "~4.4.3"
|
|
84
|
+
},
|
|
85
|
+
"peerDependencies": {
|
|
86
|
+
"@browserbasehq/sdk": ">=2.20.0 <3",
|
|
87
|
+
"@earendil-works/chord": ">=1.1.0 <1.4.0",
|
|
88
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
89
|
+
"@earendil-works/pi-durable": ">=1.1.0 <1.4.0"
|
|
90
|
+
},
|
|
91
|
+
"peerDependenciesMeta": {
|
|
92
|
+
"@browserbasehq/sdk": {
|
|
93
|
+
"optional": true
|
|
94
|
+
},
|
|
95
|
+
"@earendil-works/chord": {
|
|
96
|
+
"optional": true
|
|
97
|
+
},
|
|
98
|
+
"@earendil-works/pi-coding-agent": {
|
|
99
|
+
"optional": true
|
|
100
|
+
},
|
|
101
|
+
"@earendil-works/pi-durable": {
|
|
102
|
+
"optional": true
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
"devDependencies": {
|
|
106
|
+
"@earendil-works/chord": "1.1.0",
|
|
107
|
+
"@earendil-works/pi-ai": "1.1.0",
|
|
108
|
+
"@earendil-works/pi-coding-agent": "1.1.0",
|
|
109
|
+
"@earendil-works/pi-durable": "1.1.0",
|
|
110
|
+
"typebox": "1.3.7"
|
|
111
|
+
},
|
|
112
|
+
"repository": {
|
|
113
|
+
"type": "git",
|
|
114
|
+
"url": "git+https://github.com/Parcha-ai/agentrun.git",
|
|
115
|
+
"directory": "packages/pi-browser"
|
|
116
|
+
},
|
|
117
|
+
"bugs": {
|
|
118
|
+
"url": "https://github.com/Parcha-ai/agentrun/issues"
|
|
119
|
+
},
|
|
120
|
+
"homepage": "https://agentrun.ai",
|
|
121
|
+
"publishConfig": {
|
|
122
|
+
"access": "public",
|
|
123
|
+
"tag": "beta"
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"repo": "github.com/browserbase/stagehand",
|
|
3
|
+
"path": "packages/integrations/core/src/facade",
|
|
4
|
+
"commit": "cd7b230778cf92269e4cb90e80d97f5113781c51",
|
|
5
|
+
"release": "@browserbasehq/stagehand@4.1.0",
|
|
6
|
+
"files": {
|
|
7
|
+
"contract.ts": {
|
|
8
|
+
"blob": "97abd1a13fd2b55a005445e14522495890b6adb7",
|
|
9
|
+
"sha256": "7979b5de068244c350648dab627e9cdec07337a2eeab42509710c088328c7ac1"
|
|
10
|
+
},
|
|
11
|
+
"tools.ts": {
|
|
12
|
+
"blob": "e291407d3f493b6aaa1b740d3527c836c1a55bc9",
|
|
13
|
+
"sha256": "6bcbaf0f31ba8b8f94604858d8aacf0bdc58b5b62649d5afd996c49550b3082b"
|
|
14
|
+
},
|
|
15
|
+
"runtime.ts": {
|
|
16
|
+
"blob": "03242d1cabe18b0c13de8fc72766094bbb0560c9",
|
|
17
|
+
"sha256": "67e19f29a79d24d1cfeb73700d54beac9b07d43d6150e8f1b86e78ef010c8b82"
|
|
18
|
+
},
|
|
19
|
+
"screenshot-transport.ts": {
|
|
20
|
+
"blob": "065bff1dbc47ad50946f0bb98b5ceb5560a9626d",
|
|
21
|
+
"sha256": "a4c6b68225ae2fd61eb00e692b602a1d44f782eb676d86284d3ac5eb94b05406"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|