@sandboxrouter/sdk 0.18.0 → 0.20.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/assistant.d.ts +172 -0
- package/dist/assistant.js +307 -0
- package/dist/bench.d.ts +10 -0
- package/dist/bench.js +17 -7
- package/dist/browser.d.ts +164 -0
- package/dist/browser.js +350 -0
- package/dist/catalog.js +11 -2
- package/dist/cli.js +2 -2
- package/dist/client.d.ts +106 -0
- package/dist/client.js +78 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/leaderboard.d.ts +5 -1
- package/dist/leaderboard.js +7 -0
- package/dist/move.d.ts +5 -0
- package/dist/move.js +4 -3
- package/dist/price-index.d.ts +51 -0
- package/dist/price-index.js +70 -0
- package/dist/providers/runcloud.js +11 -3
- package/dist/providers/vercel.d.ts +6 -0
- package/dist/providers/vercel.js +18 -2
- package/dist/published.js +588 -115
- package/dist/recommend.d.ts +3 -1
- package/dist/recommend.js +4 -0
- package/dist/results.js +136 -1
- package/dist/router.d.ts +22 -0
- package/dist/router.js +28 -0
- package/dist/save.d.ts +120 -0
- package/dist/save.js +276 -0
- package/dist/steady.d.ts +92 -0
- package/dist/steady.js +164 -0
- package/dist/task.d.ts +2 -0
- package/dist/task.js +2 -2
- package/dist/types.d.ts +2 -0
- package/package.json +4 -4
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { type Router } from "./router.js";
|
|
2
|
+
import type { ProviderId } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Browser benchmark: what an agent that browses asks of a sandbox. One session, in one fresh sandbox of the
|
|
5
|
+
* provider's stock image:
|
|
6
|
+
*
|
|
7
|
+
* 1. a working browser: start the sandbox, then install Node, Playwright and headless Chromium in it;
|
|
8
|
+
* 2. launch the browser;
|
|
9
|
+
* 3. open three real pages over the network, each until the network is quiet;
|
|
10
|
+
* 4. work in a page: build a 4,000-row table, type a filter, sort it, and read the answer back;
|
|
11
|
+
* 5. take a full-page screenshot;
|
|
12
|
+
* 6. reload a real page five times, as an agent moving around a site does.
|
|
13
|
+
*
|
|
14
|
+
* The page work is checked against values computed here, the screenshot must be a real PNG and every page must
|
|
15
|
+
* answer 200 with its title, so a session only counts when the browser really did the work. The real pages are
|
|
16
|
+
* this project's own site, so the benchmark loads nobody else's servers.
|
|
17
|
+
*/
|
|
18
|
+
export declare const BROWSER_VERSION = "browser-v1";
|
|
19
|
+
export declare const BROWSER_PAGES: readonly ["https://www.sandboxrouter.ai/", "https://www.sandboxrouter.ai/providers", "https://www.sandboxrouter.ai/docs"];
|
|
20
|
+
export declare const BROWSER_RELOADS = 5;
|
|
21
|
+
/** The table the page builds, and what filtering it by "ab" and sorting by value must give. The same arithmetic runs in the page. */
|
|
22
|
+
export declare function browserFixture(rows?: number): {
|
|
23
|
+
rows: number;
|
|
24
|
+
matches: number;
|
|
25
|
+
topId: number;
|
|
26
|
+
topValue: number;
|
|
27
|
+
};
|
|
28
|
+
/** Runs in the sandbox, under Node with Playwright. Prints one line: SRBROWSER {json}. */
|
|
29
|
+
export declare const BROWSER_TASK: string;
|
|
30
|
+
/**
|
|
31
|
+
* Makes a working browser in a stock image: Node (fetched when the image has none recent enough), Playwright,
|
|
32
|
+
* and headless Chromium with the system libraries it needs (installed with apt or dnf where the sandbox allows
|
|
33
|
+
* it). It ends by starting the browser and drawing a page: a stock image where that fails has no working browser.
|
|
34
|
+
*/
|
|
35
|
+
export declare const BROWSER_SETUP: string;
|
|
36
|
+
/** One session's times, in ms. Create and setup are seen from the test machine; the browser's own steps are timed in the sandbox. */
|
|
37
|
+
export interface BrowserSession {
|
|
38
|
+
createMs: number;
|
|
39
|
+
/** Installing Node, Playwright and Chromium in the stock image. */
|
|
40
|
+
setupMs: number;
|
|
41
|
+
launchMs: number;
|
|
42
|
+
/** First load of each real page, in order. */
|
|
43
|
+
pageMs: number[];
|
|
44
|
+
/** Each reload of a real page already visited. */
|
|
45
|
+
reloadMs: number[];
|
|
46
|
+
/** Building, filtering and sorting the table, and reading the answer back. */
|
|
47
|
+
workMs: number;
|
|
48
|
+
screenshotMs: number;
|
|
49
|
+
screenshotBytes: number;
|
|
50
|
+
/** The whole browser task as the test machine saw it: launch to close, with the round trip. */
|
|
51
|
+
taskMs: number;
|
|
52
|
+
cpuMs?: number;
|
|
53
|
+
maxCoreMs?: number;
|
|
54
|
+
}
|
|
55
|
+
export interface BrowserSummary {
|
|
56
|
+
/** Start plus setup: how long until a stock sandbox has a browser that works. Median. */
|
|
57
|
+
readyMs?: number;
|
|
58
|
+
launchMs?: number;
|
|
59
|
+
/** Median first load across the real pages of every session. */
|
|
60
|
+
pageMs?: number;
|
|
61
|
+
reloadMs?: number;
|
|
62
|
+
workMs?: number;
|
|
63
|
+
screenshotMs?: number;
|
|
64
|
+
/** The browser task alone. Median. */
|
|
65
|
+
taskMs?: number;
|
|
66
|
+
}
|
|
67
|
+
/** Where a session stopped. Kept as counts, not messages: a result file holds no error text. */
|
|
68
|
+
export type BrowserFailure = "create" | "setup" | "browse";
|
|
69
|
+
export interface BrowserRow extends BrowserSummary {
|
|
70
|
+
provider: string;
|
|
71
|
+
size: {
|
|
72
|
+
vcpu: number;
|
|
73
|
+
memoryGb: number;
|
|
74
|
+
};
|
|
75
|
+
sessions: BrowserSession[];
|
|
76
|
+
failures: number;
|
|
77
|
+
/** How many sessions stopped at each step. */
|
|
78
|
+
failedAt?: Partial<Record<BrowserFailure, number>>;
|
|
79
|
+
/** Published prices applied to one whole session (start, setup and task), median. */
|
|
80
|
+
sessionUsd?: number;
|
|
81
|
+
/** The browser task alone, in a sandbox that is already up with its browser installed. */
|
|
82
|
+
taskUsd?: number;
|
|
83
|
+
hourlyUsd?: number;
|
|
84
|
+
}
|
|
85
|
+
export interface BrowserReport {
|
|
86
|
+
tool: "sandboxrouter-browser";
|
|
87
|
+
version: string;
|
|
88
|
+
task: string;
|
|
89
|
+
date: string;
|
|
90
|
+
label?: string;
|
|
91
|
+
by?: string;
|
|
92
|
+
spec: {
|
|
93
|
+
vcpu: number;
|
|
94
|
+
memoryGb: number;
|
|
95
|
+
};
|
|
96
|
+
runs: number;
|
|
97
|
+
pages: number;
|
|
98
|
+
reloads: number;
|
|
99
|
+
node: string;
|
|
100
|
+
platform: string;
|
|
101
|
+
rows: BrowserRow[];
|
|
102
|
+
}
|
|
103
|
+
export declare function browserSummary(sessions: BrowserSession[]): BrowserSummary;
|
|
104
|
+
export interface BrowserOptions {
|
|
105
|
+
router: Router;
|
|
106
|
+
providers: ProviderId[];
|
|
107
|
+
runs?: number;
|
|
108
|
+
spec?: {
|
|
109
|
+
vcpu: number;
|
|
110
|
+
memoryGb: number;
|
|
111
|
+
};
|
|
112
|
+
onProgress?: (message: string) => void;
|
|
113
|
+
}
|
|
114
|
+
/** Providers side by side, each running its sessions one after another. */
|
|
115
|
+
export declare function browser(opts: BrowserOptions): Promise<BrowserRow[]>;
|
|
116
|
+
export declare function loadBrowserReports(dir: string): BrowserReport[];
|
|
117
|
+
/**
|
|
118
|
+
* For the website: each provider's newest report of the current task. A provider is listed when every session
|
|
119
|
+
* finished and checked out, fastest browser task first. `noBrowser` names the providers whose stock image
|
|
120
|
+
* could not be given a browser at all (every session stopped at setup): a fact about the image, not a failure.
|
|
121
|
+
*/
|
|
122
|
+
export declare function browserTable(reports: BrowserReport[]): {
|
|
123
|
+
rows: {
|
|
124
|
+
provider: string;
|
|
125
|
+
name: string;
|
|
126
|
+
size: {
|
|
127
|
+
vcpu: number;
|
|
128
|
+
memoryGb: number;
|
|
129
|
+
};
|
|
130
|
+
readyMs: number;
|
|
131
|
+
launchMs: number;
|
|
132
|
+
pageMs: number;
|
|
133
|
+
reloadMs: number;
|
|
134
|
+
workMs: number;
|
|
135
|
+
screenshotMs: number;
|
|
136
|
+
taskMs: number;
|
|
137
|
+
sessionUsd?: number | undefined;
|
|
138
|
+
taskUsd?: number | undefined;
|
|
139
|
+
sessions: number;
|
|
140
|
+
measuredAt: string;
|
|
141
|
+
}[];
|
|
142
|
+
noBrowser: {
|
|
143
|
+
provider: string;
|
|
144
|
+
name: string;
|
|
145
|
+
}[];
|
|
146
|
+
};
|
|
147
|
+
/** For recommend(): the browser task as a job. Time is start, setup and task; cost is the whole session. */
|
|
148
|
+
export declare function browserJobs(reports: BrowserReport[]): Record<string, {
|
|
149
|
+
name: string;
|
|
150
|
+
size: {
|
|
151
|
+
vcpu: number;
|
|
152
|
+
memoryGb: number;
|
|
153
|
+
};
|
|
154
|
+
createMs: number;
|
|
155
|
+
taskMs: number;
|
|
156
|
+
taskUsd: number;
|
|
157
|
+
reusedUsd: number;
|
|
158
|
+
successRate: number;
|
|
159
|
+
runs: number;
|
|
160
|
+
ok: number;
|
|
161
|
+
minimumSeconds?: number;
|
|
162
|
+
perSandboxUsd?: number;
|
|
163
|
+
measuredAt: string;
|
|
164
|
+
}>;
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import { readdirSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { BILLED_VS_LIST } from "./billing.js";
|
|
4
|
+
import { benchmarksPublishable, billingRules, CATALOG, DEFAULT_MEMORY_GB, DEFAULT_VCPU, fixedSize, hourlyCost } from "./catalog.js";
|
|
5
|
+
import { median } from "./bench-store.js";
|
|
6
|
+
import { sizeOf } from "./router.js";
|
|
7
|
+
import { busyMs, maxCoreMs, taskUsd } from "./task.js";
|
|
8
|
+
/**
|
|
9
|
+
* Browser benchmark: what an agent that browses asks of a sandbox. One session, in one fresh sandbox of the
|
|
10
|
+
* provider's stock image:
|
|
11
|
+
*
|
|
12
|
+
* 1. a working browser: start the sandbox, then install Node, Playwright and headless Chromium in it;
|
|
13
|
+
* 2. launch the browser;
|
|
14
|
+
* 3. open three real pages over the network, each until the network is quiet;
|
|
15
|
+
* 4. work in a page: build a 4,000-row table, type a filter, sort it, and read the answer back;
|
|
16
|
+
* 5. take a full-page screenshot;
|
|
17
|
+
* 6. reload a real page five times, as an agent moving around a site does.
|
|
18
|
+
*
|
|
19
|
+
* The page work is checked against values computed here, the screenshot must be a real PNG and every page must
|
|
20
|
+
* answer 200 with its title, so a session only counts when the browser really did the work. The real pages are
|
|
21
|
+
* this project's own site, so the benchmark loads nobody else's servers.
|
|
22
|
+
*/
|
|
23
|
+
export const BROWSER_VERSION = "browser-v1";
|
|
24
|
+
export const BROWSER_PAGES = ["https://www.sandboxrouter.ai/", "https://www.sandboxrouter.ai/providers", "https://www.sandboxrouter.ai/docs"];
|
|
25
|
+
export const BROWSER_RELOADS = 5;
|
|
26
|
+
const PLAYWRIGHT = "1.65.1";
|
|
27
|
+
const DIR = "/tmp/sr-browser";
|
|
28
|
+
const ROWS = 4000;
|
|
29
|
+
const NODE_BASE = "https://nodejs.org/dist/v22.11.0/node-v22.11.0-linux";
|
|
30
|
+
/** The table the page builds, and what filtering it by "ab" and sorting by value must give. The same arithmetic runs in the page. */
|
|
31
|
+
export function browserFixture(rows = ROWS) {
|
|
32
|
+
let s = 20261201;
|
|
33
|
+
const next = () => ((s = (Math.imul(s, 1664525) + 1013904223) >>> 0) >>> 8);
|
|
34
|
+
const all = [];
|
|
35
|
+
for (let id = 1; id <= rows; id++) {
|
|
36
|
+
let name = "";
|
|
37
|
+
for (let i = 0; i < 6; i++)
|
|
38
|
+
name += "abcdefgh"[next() % 8];
|
|
39
|
+
all.push({ id, name, value: next() % 100_000 });
|
|
40
|
+
}
|
|
41
|
+
const hits = all.filter((r) => r.name.includes("ab")).sort((a, b) => b.value - a.value || a.id - b.id);
|
|
42
|
+
return { rows, matches: hits.length, topId: hits[0].id, topValue: hits[0].value };
|
|
43
|
+
}
|
|
44
|
+
/** The page the browser works in: it builds the table itself, and filters and sorts when asked. No network. */
|
|
45
|
+
const PAGE = `<!doctype html><meta charset="utf-8"><title>sr-browser</title>
|
|
46
|
+
<style>body{font:14px system-ui,sans-serif}td,th{padding:4px 10px;border-bottom:1px solid #ddd}</style>
|
|
47
|
+
<input id="q" placeholder="filter"><button id="sort">Sort by value</button><p id="count"></p>
|
|
48
|
+
<table><thead><tr><th>id</th><th>name</th><th>value</th></tr></thead><tbody id="rows"></tbody></table>
|
|
49
|
+
<script>
|
|
50
|
+
let s = 20261201; const next = () => ((s = (Math.imul(s, 1664525) + 1013904223) >>> 0) >>> 8);
|
|
51
|
+
const all = []; for (let id = 1; id <= ${ROWS}; id++) { let name = ""; for (let i = 0; i < 6; i++) name += "abcdefgh"[next() % 8]; all.push({ id, name, value: next() % 100000 }); }
|
|
52
|
+
let shown = all;
|
|
53
|
+
const draw = () => { document.getElementById("rows").innerHTML = shown.map((r) => "<tr><td>" + r.id + "</td><td>" + r.name + "</td><td>" + r.value + "</td></tr>").join(""); document.getElementById("count").textContent = shown.length + " rows"; };
|
|
54
|
+
document.getElementById("q").addEventListener("input", (e) => { shown = all.filter((r) => r.name.includes(e.target.value)); draw(); });
|
|
55
|
+
document.getElementById("sort").addEventListener("click", () => { shown = [...shown].sort((a, b) => b.value - a.value || a.id - b.id); draw(); });
|
|
56
|
+
draw();
|
|
57
|
+
</script>`;
|
|
58
|
+
/** Runs in the sandbox, under Node with Playwright. Prints one line: SRBROWSER {json}. */
|
|
59
|
+
export const BROWSER_TASK = `import { chromium } from "playwright";
|
|
60
|
+
const ms = async (work) => { const t = performance.now(); const v = await work(); return [Math.max(1, Math.round(performance.now() - t)), v]; };
|
|
61
|
+
const PAGES = ${JSON.stringify(BROWSER_PAGES)};
|
|
62
|
+
const out = {};
|
|
63
|
+
const [launchMs, browser] = await ms(() => chromium.launch({ args: ["--no-sandbox", "--disable-dev-shm-usage", "--disable-gpu"] }));
|
|
64
|
+
out.launchMs = launchMs;
|
|
65
|
+
try {
|
|
66
|
+
const context = await browser.newContext({ viewport: { width: 1280, height: 800 } });
|
|
67
|
+
const page = await context.newPage();
|
|
68
|
+
out.pageMs = [];
|
|
69
|
+
for (const url of PAGES) {
|
|
70
|
+
const [t, res] = await ms(() => page.goto(url, { waitUntil: "networkidle", timeout: 60000 }));
|
|
71
|
+
if (!res || res.status() !== 200) throw new Error("page " + url + " answered " + (res ? res.status() : "nothing"));
|
|
72
|
+
if (!/sandboxRouter/i.test(await page.title())) throw new Error("page " + url + " has the wrong title");
|
|
73
|
+
out.pageMs.push(t);
|
|
74
|
+
}
|
|
75
|
+
out.reloadMs = [];
|
|
76
|
+
for (let i = 0; i < ${BROWSER_RELOADS}; i++) {
|
|
77
|
+
const [t, res] = await ms(() => page.goto(PAGES[1], { waitUntil: "networkidle", timeout: 60000 }));
|
|
78
|
+
if (!res || res.status() !== 200) throw new Error("reload answered " + (res ? res.status() : "nothing"));
|
|
79
|
+
out.reloadMs.push(t);
|
|
80
|
+
}
|
|
81
|
+
const work = await context.newPage();
|
|
82
|
+
const [workMs, answer] = await ms(async () => {
|
|
83
|
+
await work.setContent(${JSON.stringify(PAGE)}, { waitUntil: "load" });
|
|
84
|
+
await work.fill("#q", "ab");
|
|
85
|
+
await work.click("#sort");
|
|
86
|
+
return work.evaluate(() => ({ count: document.getElementById("count").textContent, top: [...document.querySelectorAll("#rows tr:first-child td")].map((td) => td.textContent) }));
|
|
87
|
+
});
|
|
88
|
+
out.workMs = workMs;
|
|
89
|
+
out.answer = answer;
|
|
90
|
+
const [shotMs, png] = await ms(() => work.screenshot({ fullPage: true, type: "png" }));
|
|
91
|
+
out.screenshotMs = shotMs;
|
|
92
|
+
out.screenshotBytes = png.length;
|
|
93
|
+
out.png = png.subarray(0, 8).toString("hex") === "89504e470d0a1a0a";
|
|
94
|
+
} finally {
|
|
95
|
+
await browser.close();
|
|
96
|
+
}
|
|
97
|
+
console.log("SRBROWSER " + JSON.stringify(out));
|
|
98
|
+
`;
|
|
99
|
+
const DNF_LIBS = "nss nspr atk at-spi2-atk at-spi2-core cups-libs libdrm libxkbcommon libXcomposite libXdamage libXfixes libXrandr libX11 libXext libxcb mesa-libgbm pango cairo alsa-lib dbus-libs expat";
|
|
100
|
+
const SMOKE = `import("playwright").then(async ({ chromium }) => { const b = await chromium.launch({ args: ["--no-sandbox", "--disable-dev-shm-usage", "--disable-gpu"] }); const p = await b.newPage(); await p.setContent("<p>ok</p>"); await p.screenshot(); await b.close(); }).catch((e) => { console.error(String(e).slice(0, 2000)); process.exit(1); })`;
|
|
101
|
+
/**
|
|
102
|
+
* Makes a working browser in a stock image: Node (fetched when the image has none recent enough), Playwright,
|
|
103
|
+
* and headless Chromium with the system libraries it needs (installed with apt or dnf where the sandbox allows
|
|
104
|
+
* it). It ends by starting the browser and drawing a page: a stock image where that fails has no working browser.
|
|
105
|
+
*/
|
|
106
|
+
export const BROWSER_SETUP = [
|
|
107
|
+
"set -e",
|
|
108
|
+
`mkdir -p ${DIR} && cd ${DIR}`,
|
|
109
|
+
`export PLAYWRIGHT_BROWSERS_PATH=${DIR}/browsers npm_config_update_notifier=false DEBIAN_FRONTEND=noninteractive`,
|
|
110
|
+
'case "$(uname -m)" in aarch64|arm64) A=arm64 ;; *) A=x64 ;; esac',
|
|
111
|
+
`get() { if command -v curl > /dev/null; then curl -sSfL -o "$2" "$1"; elif command -v wget > /dev/null; then wget -q -O "$2" "$1"; else python3 -c "import shutil, sys, urllib.request; shutil.copyfileobj(urllib.request.urlopen(sys.argv[1]), open(sys.argv[2], 'wb'))" "$1" "$2"; fi; }`,
|
|
112
|
+
// The same Node everywhere, so the installer and the task do not depend on what the image ships.
|
|
113
|
+
`mkdir -p ${DIR}/node && get "${NODE_BASE}-$A.tar.gz" ${DIR}/node.tgz && tar xzf ${DIR}/node.tgz -C ${DIR}/node --strip-components=1 && rm ${DIR}/node.tgz`,
|
|
114
|
+
`export PATH=${DIR}/node/bin:$PATH`,
|
|
115
|
+
`echo '{"name":"sr-browser","private":true,"type":"module"}' > package.json`,
|
|
116
|
+
`npm install --no-audit --no-fund --loglevel=error playwright@${PLAYWRIGHT} > /dev/null`,
|
|
117
|
+
// With the system libraries where the sandbox lets us install them; without, where the image already has them.
|
|
118
|
+
"npx playwright install --with-deps chromium-headless-shell > install.log 2>&1 || npx playwright install chromium-headless-shell >> install.log 2>&1",
|
|
119
|
+
// Playwright installs libraries with apt only. On an image with dnf (Amazon Linux, Fedora) they come from there.
|
|
120
|
+
`if command -v dnf > /dev/null && ! command -v apt-get > /dev/null; then S=""; [ "$(id -u)" = 0 ] || S="sudo -n"; $S dnf install -y -q ${DNF_LIBS} >> install.log 2>&1 || true; fi`,
|
|
121
|
+
// The browser has to really start and draw a page here, or this image has no working browser.
|
|
122
|
+
`node -e ${JSON.stringify(SMOKE)} >> install.log 2>&1`,
|
|
123
|
+
"echo ready",
|
|
124
|
+
].join("\n");
|
|
125
|
+
const RUN = `cd ${DIR} && PATH=${DIR}/node/bin:$PATH PLAYWRIGHT_BROWSERS_PATH=${DIR}/browsers node task.mjs`;
|
|
126
|
+
const STAT = `grep '^cpu' /proc/stat 2> /dev/null | tr '\\n' ';'`;
|
|
127
|
+
export function browserSummary(sessions) {
|
|
128
|
+
if (!sessions.length)
|
|
129
|
+
return {};
|
|
130
|
+
return {
|
|
131
|
+
readyMs: median(sessions.map((s) => s.createMs + s.setupMs)),
|
|
132
|
+
launchMs: median(sessions.map((s) => s.launchMs)),
|
|
133
|
+
pageMs: median(sessions.flatMap((s) => s.pageMs)),
|
|
134
|
+
reloadMs: median(sessions.flatMap((s) => s.reloadMs)),
|
|
135
|
+
workMs: median(sessions.map((s) => s.workMs)),
|
|
136
|
+
screenshotMs: median(sessions.map((s) => s.screenshotMs)),
|
|
137
|
+
taskMs: median(sessions.map((s) => s.taskMs)),
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
class StepError extends Error {
|
|
141
|
+
step;
|
|
142
|
+
constructor(step, message) {
|
|
143
|
+
super(message);
|
|
144
|
+
this.step = step;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/** Providers side by side, each running its sessions one after another. */
|
|
148
|
+
export async function browser(opts) {
|
|
149
|
+
const runs = opts.runs ?? 3;
|
|
150
|
+
const asked = opts.spec ?? { vcpu: DEFAULT_VCPU, memoryGb: DEFAULT_MEMORY_GB };
|
|
151
|
+
const fixture = browserFixture();
|
|
152
|
+
const round = (t) => Math.max(1, Math.round(performance.now() - t));
|
|
153
|
+
const session = async (provider, spec) => {
|
|
154
|
+
let box;
|
|
155
|
+
try {
|
|
156
|
+
const t0 = performance.now();
|
|
157
|
+
try {
|
|
158
|
+
box = await opts.router.create(spec, { provider, fallback: false, deadlineSeconds: 180 });
|
|
159
|
+
}
|
|
160
|
+
catch (e) {
|
|
161
|
+
throw new StepError("create", e.message);
|
|
162
|
+
}
|
|
163
|
+
const live = box;
|
|
164
|
+
const createMs = round(t0);
|
|
165
|
+
const before = (await live.exec(STAT).catch(() => ({ stdout: "" }))).stdout;
|
|
166
|
+
const t1 = performance.now();
|
|
167
|
+
const setup = await live.exec(BROWSER_SETUP, { timeoutSeconds: 600 }).catch((e) => {
|
|
168
|
+
throw new StepError("setup", e.message);
|
|
169
|
+
});
|
|
170
|
+
if (setup.exitCode !== 0 || !setup.stdout.includes("ready"))
|
|
171
|
+
throw new StepError("setup", `setup exited ${setup.exitCode}: ${(setup.stderr || setup.stdout).slice(-200)}`);
|
|
172
|
+
const setupMs = round(t1);
|
|
173
|
+
try {
|
|
174
|
+
await live.writeFile(`${DIR}/task.mjs`, BROWSER_TASK);
|
|
175
|
+
const t2 = performance.now();
|
|
176
|
+
const r = await live.exec(RUN, { timeoutSeconds: 300 });
|
|
177
|
+
const taskMs = round(t2);
|
|
178
|
+
const line = r.stdout.split("\n").find((l) => l.startsWith("SRBROWSER "));
|
|
179
|
+
if (r.exitCode !== 0 || !line)
|
|
180
|
+
throw new Error(`the browser task exited ${r.exitCode}: ${(r.stderr || r.stdout).slice(-300)}`);
|
|
181
|
+
const o = JSON.parse(line.slice(10));
|
|
182
|
+
if (o.answer.count !== `${fixture.matches} rows` || Number(o.answer.top[0]) !== fixture.topId || Number(o.answer.top[2]) !== fixture.topValue)
|
|
183
|
+
throw new Error("the page returned the wrong answer");
|
|
184
|
+
if (!o.png || !(o.screenshotBytes > 20_000))
|
|
185
|
+
throw new Error("the screenshot is not a real PNG");
|
|
186
|
+
if (o.pageMs.length !== BROWSER_PAGES.length || o.reloadMs.length !== BROWSER_RELOADS)
|
|
187
|
+
throw new Error("not every page was loaded");
|
|
188
|
+
const after = (await live.exec(STAT).catch(() => ({ stdout: "" }))).stdout;
|
|
189
|
+
const total = setupMs + taskMs;
|
|
190
|
+
const cpu = busyMs(before, after);
|
|
191
|
+
const plausible = cpu !== undefined && cpu <= (spec.vcpu ?? DEFAULT_VCPU) * total * 1.1;
|
|
192
|
+
const core = plausible ? maxCoreMs(before, after) : undefined;
|
|
193
|
+
return {
|
|
194
|
+
createMs, setupMs, launchMs: o.launchMs, pageMs: o.pageMs, reloadMs: o.reloadMs, workMs: o.workMs, screenshotMs: o.screenshotMs, screenshotBytes: o.screenshotBytes, taskMs,
|
|
195
|
+
...(plausible ? { cpuMs: cpu } : {}),
|
|
196
|
+
...(core !== undefined ? { maxCoreMs: core } : {}),
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
catch (e) {
|
|
200
|
+
throw e instanceof StepError ? e : new StepError("browse", e.message);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
finally {
|
|
204
|
+
await box?.kill().catch(() => { });
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
return Promise.all(opts.providers.map(async (provider) => {
|
|
208
|
+
// A browser keeps cores busy: priced and reserved as full use.
|
|
209
|
+
const spec = { ...asked, ...fixedSize(provider, asked), timeoutMinutes: 20 };
|
|
210
|
+
const size = sizeOf(provider, spec);
|
|
211
|
+
const done = [];
|
|
212
|
+
const failedAt = {};
|
|
213
|
+
for (let i = 0; i < runs; i++) {
|
|
214
|
+
try {
|
|
215
|
+
const s = await session(provider, spec);
|
|
216
|
+
done.push(s);
|
|
217
|
+
opts.onProgress?.(`${provider} session ${i + 1}/${runs}: browser ready in ${s.createMs + s.setupMs} ms, launch ${s.launchMs} ms, pages ${s.pageMs.join("/")} ms, work ${s.workMs} ms, screenshot ${s.screenshotMs} ms`);
|
|
218
|
+
}
|
|
219
|
+
catch (e) {
|
|
220
|
+
const step = e instanceof StepError ? e.step : "browse";
|
|
221
|
+
failedAt[step] = (failedAt[step] ?? 0) + 1;
|
|
222
|
+
opts.onProgress?.(`${provider} session ${i + 1}/${runs} failed at ${step}: ${e.message.replace(/\s+/g, " ").slice(0, 300)}`);
|
|
223
|
+
// A stock image that cannot get a browser will not get one on the next try either.
|
|
224
|
+
if (step === "setup" && !done.length) {
|
|
225
|
+
failedAt.setup = runs - i;
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
const failures = Object.values(failedAt).reduce((a, b) => a + (b ?? 0), 0);
|
|
231
|
+
let hourlyUsd;
|
|
232
|
+
let sessionUsd;
|
|
233
|
+
let workUsd;
|
|
234
|
+
try {
|
|
235
|
+
hourlyUsd = hourlyCost(provider, { ...spec, cpuUtilization: 1 });
|
|
236
|
+
const ratio = BILLED_VS_LIST[provider]?.ratio ?? 1;
|
|
237
|
+
const whole = done.map((s) => Math.round(taskUsd(provider, size, s.createMs, s.setupMs + s.taskMs, s.cpuMs, ratio, false, s.maxCoreMs) * 1e9));
|
|
238
|
+
// The task alone has no CPU reading of its own: priced with every core busy.
|
|
239
|
+
const alone = done.map((s) => Math.round(taskUsd(provider, size, 0, s.taskMs, undefined, ratio, true) * 1e9));
|
|
240
|
+
if (whole.length)
|
|
241
|
+
sessionUsd = median(whole) / 1e9;
|
|
242
|
+
if (alone.length)
|
|
243
|
+
workUsd = median(alone) / 1e9;
|
|
244
|
+
}
|
|
245
|
+
catch {
|
|
246
|
+
/* no price: the row still stands */
|
|
247
|
+
}
|
|
248
|
+
return {
|
|
249
|
+
provider, size, sessions: done, ...browserSummary(done), failures,
|
|
250
|
+
...(failures ? { failedAt } : {}),
|
|
251
|
+
...(sessionUsd !== undefined ? { sessionUsd } : {}),
|
|
252
|
+
...(workUsd !== undefined ? { taskUsd: workUsd } : {}),
|
|
253
|
+
...(hourlyUsd !== undefined ? { hourlyUsd } : {}),
|
|
254
|
+
};
|
|
255
|
+
}));
|
|
256
|
+
}
|
|
257
|
+
export function loadBrowserReports(dir) {
|
|
258
|
+
let files;
|
|
259
|
+
try {
|
|
260
|
+
files = readdirSync(dir).filter((f) => f.endsWith(".json"));
|
|
261
|
+
}
|
|
262
|
+
catch {
|
|
263
|
+
return [];
|
|
264
|
+
}
|
|
265
|
+
const out = [];
|
|
266
|
+
for (const f of files.sort()) {
|
|
267
|
+
try {
|
|
268
|
+
const r = JSON.parse(readFileSync(join(dir, f), "utf8"));
|
|
269
|
+
if (r?.tool === "sandboxrouter-browser" && Array.isArray(r.rows))
|
|
270
|
+
out.push(r);
|
|
271
|
+
}
|
|
272
|
+
catch {
|
|
273
|
+
/* skip unreadable files */
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return out;
|
|
277
|
+
}
|
|
278
|
+
const KNOWN = new Set(CATALOG.map((c) => c.id));
|
|
279
|
+
function latestRows(reports) {
|
|
280
|
+
const latest = new Map();
|
|
281
|
+
for (const rep of reports) {
|
|
282
|
+
if (rep.task !== BROWSER_VERSION)
|
|
283
|
+
continue;
|
|
284
|
+
for (const row of rep.rows) {
|
|
285
|
+
if (!KNOWN.has(row.provider) || !benchmarksPublishable(row.provider))
|
|
286
|
+
continue;
|
|
287
|
+
const seen = latest.get(row.provider);
|
|
288
|
+
if (!seen || rep.date > seen.rep.date)
|
|
289
|
+
latest.set(row.provider, { row, rep });
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return [...latest.values()];
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* For the website: each provider's newest report of the current task. A provider is listed when every session
|
|
296
|
+
* finished and checked out, fastest browser task first. `noBrowser` names the providers whose stock image
|
|
297
|
+
* could not be given a browser at all (every session stopped at setup): a fact about the image, not a failure.
|
|
298
|
+
*/
|
|
299
|
+
export function browserTable(reports) {
|
|
300
|
+
const latest = latestRows(reports);
|
|
301
|
+
const name = (id) => CATALOG.find((c) => c.id === id).name;
|
|
302
|
+
const rows = latest
|
|
303
|
+
.filter(({ row, rep }) => row.failures === 0 && row.sessions.length === rep.runs && row.taskMs !== undefined)
|
|
304
|
+
.map(({ row, rep }) => ({
|
|
305
|
+
provider: row.provider,
|
|
306
|
+
name: name(row.provider),
|
|
307
|
+
size: row.size,
|
|
308
|
+
readyMs: row.readyMs,
|
|
309
|
+
launchMs: row.launchMs,
|
|
310
|
+
pageMs: row.pageMs,
|
|
311
|
+
reloadMs: row.reloadMs,
|
|
312
|
+
workMs: row.workMs,
|
|
313
|
+
screenshotMs: row.screenshotMs,
|
|
314
|
+
taskMs: row.taskMs,
|
|
315
|
+
...(row.sessionUsd !== undefined ? { sessionUsd: row.sessionUsd } : {}),
|
|
316
|
+
...(row.taskUsd !== undefined ? { taskUsd: row.taskUsd } : {}),
|
|
317
|
+
sessions: row.sessions.length,
|
|
318
|
+
measuredAt: rep.date.slice(0, 10),
|
|
319
|
+
}))
|
|
320
|
+
.sort((a, b) => a.taskMs - b.taskMs || a.provider.localeCompare(b.provider));
|
|
321
|
+
const noBrowser = latest
|
|
322
|
+
.filter(({ row, rep }) => !row.sessions.length && (row.failedAt?.setup ?? 0) === rep.runs)
|
|
323
|
+
.map(({ row }) => ({ provider: row.provider, name: name(row.provider) }))
|
|
324
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
|
325
|
+
return { rows, noBrowser };
|
|
326
|
+
}
|
|
327
|
+
/** For recommend(): the browser task as a job. Time is start, setup and task; cost is the whole session. */
|
|
328
|
+
export function browserJobs(reports) {
|
|
329
|
+
const out = {};
|
|
330
|
+
for (const { row, rep } of latestRows(reports).sort((a, b) => a.row.provider.localeCompare(b.row.provider))) {
|
|
331
|
+
if (!row.sessions.length || row.sessionUsd === undefined || row.taskUsd === undefined)
|
|
332
|
+
continue;
|
|
333
|
+
const rules = billingRules(row.provider);
|
|
334
|
+
out[row.provider] = {
|
|
335
|
+
name: CATALOG.find((c) => c.id === row.provider).name,
|
|
336
|
+
size: row.size,
|
|
337
|
+
createMs: median(row.sessions.map((s) => s.createMs)),
|
|
338
|
+
taskMs: median(row.sessions.map((s) => s.setupMs + s.taskMs)),
|
|
339
|
+
taskUsd: row.sessionUsd,
|
|
340
|
+
reusedUsd: row.taskUsd,
|
|
341
|
+
successRate: row.sessions.length / rep.runs,
|
|
342
|
+
runs: rep.runs,
|
|
343
|
+
ok: row.sessions.length,
|
|
344
|
+
...(rules.minSeconds > 1 ? { minimumSeconds: rules.minSeconds } : {}),
|
|
345
|
+
...(rules.perSandboxUsd ? { perSandboxUsd: rules.perSandboxUsd } : {}),
|
|
346
|
+
measuredAt: rep.date,
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
return out;
|
|
350
|
+
}
|
package/dist/catalog.js
CHANGED
|
@@ -519,8 +519,10 @@ ENTRIES.push({
|
|
|
519
519
|
name: "Run Cloud",
|
|
520
520
|
pricing: {
|
|
521
521
|
vcpuHour: 0.008856,
|
|
522
|
+
reservesCpu: true,
|
|
523
|
+
cpuFloor: 0.125,
|
|
522
524
|
gbHour: 0.0029943,
|
|
523
|
-
note: "per second ($0.00000492 per physical core = 2 vCPUs, $0.00000083175 per GiB); the reservation is the floor, CPU and memory used above it bill at the same rates; $5 to start without a card, then the first $15 a month free with one",
|
|
525
|
+
note: "per second ($0.00000492 per physical core = 2 vCPUs, $0.00000083175 per GiB); the reservation is the floor, CPU and memory used above it bill at the same rates (the adapter reserves cpuUtilization of the size and bursts to the full size); $5 to start without a card, then the first $15 a month free with one",
|
|
524
526
|
source: "https://run.cloud/pricing",
|
|
525
527
|
checked: "2026-11-27",
|
|
526
528
|
},
|
|
@@ -799,7 +801,9 @@ export function fixedSize(id, spec = {}) {
|
|
|
799
801
|
* compare them at the asked size. Starting one for real needs your own image or template built at that size.
|
|
800
802
|
*/
|
|
801
803
|
export function withOwnImages(spec) {
|
|
802
|
-
|
|
804
|
+
// Every provider gets one, not only those with a fixed default size: naming an image for some
|
|
805
|
+
// providers leaves the rest out of routing (see `unfit`), and this is a comparison across all of them.
|
|
806
|
+
const image = Object.fromEntries(CATALOG.map((c) => [c.id, "your-image"]));
|
|
803
807
|
return { ...spec, image: { ...image, ...spec.image } };
|
|
804
808
|
}
|
|
805
809
|
/** A spec this provider can take as-is: its default size if it has one, else the router default. */
|
|
@@ -926,6 +930,11 @@ export function unfit(id, spec, require = []) {
|
|
|
926
930
|
for (const c of needs)
|
|
927
931
|
if (!p.capabilities.includes(c))
|
|
928
932
|
return `no ${c} support`;
|
|
933
|
+
// An image is named per provider. A provider given none would start its own default image, which is
|
|
934
|
+
// not what was asked for, so once any image is named only the providers named can take the sandbox.
|
|
935
|
+
const imaged = Object.entries(spec.image ?? {}).filter(([, v]) => v).map(([k]) => k);
|
|
936
|
+
if (imaged.length > 0 && !imaged.includes(id))
|
|
937
|
+
return `no image given for ${id} (image names ${imaged.join(", ")})`;
|
|
929
938
|
if (spec.ports?.length && p.limits.maxPorts !== undefined && spec.ports.length > p.limits.maxPorts)
|
|
930
939
|
return `max ${p.limits.maxPorts} preview ports`;
|
|
931
940
|
const reserved = spec.ports?.find((port) => p.limits.reservedPorts?.includes(port));
|
package/dist/cli.js
CHANGED
|
@@ -26,7 +26,7 @@ Usage:
|
|
|
26
26
|
sandboxrouter providers [--vcpu N] [--memory GB] price table + which keys are set
|
|
27
27
|
sandboxrouter route [spec flags] [route flags] dry run: the order providers would be tried
|
|
28
28
|
sandboxrouter quote [spec/route flags] [--json] where a create would land and what the run would cost
|
|
29
|
-
sandboxrouter recommend [--job short|long|python|download|agent|repo|start] [--count N] [--priority value|cost|speed]
|
|
29
|
+
sandboxrouter recommend [--job short|long|python|download|agent|repo|assistant|browser|start] [--count N] [--priority value|cost|speed]
|
|
30
30
|
[--reuse] [--provider a,b] [--json]
|
|
31
31
|
which provider for a job, from the published benchmarks: per successful run, with start
|
|
32
32
|
times under load for --count 10 and up; --provider limits it to the ones you name
|
|
@@ -236,7 +236,7 @@ async function main() {
|
|
|
236
236
|
return;
|
|
237
237
|
}
|
|
238
238
|
if (cmd === "recommend") {
|
|
239
|
-
const jobs = ["start", "short", "long", "python", "download", "agent", "repo"];
|
|
239
|
+
const jobs = ["start", "short", "long", "python", "download", "agent", "repo", "assistant", "browser"];
|
|
240
240
|
const priorities = ["value", "cost", "speed"];
|
|
241
241
|
const job = (values.job ?? "short");
|
|
242
242
|
const priority = (values.priority ?? "value");
|