@sandboxrouter/sdk 0.11.0 → 0.13.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.
@@ -1,9 +1,17 @@
1
1
  import { readdirSync, readFileSync } from "node:fs";
2
2
  import { join } from "node:path";
3
- import { benchmarksPublishable, billingRules, CATALOG, cpuHourlyAtFull, fittingSpec, hourlyCost } from "./catalog.js";
3
+ import { benchmarksPublishable, billingRules, CATALOG, cpuHourlyAtFull, hourlyCost } from "./catalog.js";
4
4
  import { BILLED_VS_LIST } from "./billing.js";
5
- import { TASK_VERSION, taskByVersion, taskUsd } from "./task.js";
5
+ import { AGENT_TASK_VERSION } from "./agent-bench.js";
6
+ import { isCurrentTask, TASK_VERSION, taskByVersion, taskUsd } from "./task.js";
6
7
  import { median } from "./bench-store.js";
8
+ import { sizeOf } from "./router.js";
9
+ const sameSize = (a, b) => a.vcpu === b.vcpu && a.memoryGb === b.memoryGb;
10
+ const DEFAULT_SIZE = { vcpu: 2, memoryGb: 4 };
11
+ const requestedSize = (spec) => ({
12
+ vcpu: spec.vcpu ?? DEFAULT_SIZE.vcpu,
13
+ memoryGb: spec.memoryGb ?? DEFAULT_SIZE.memoryGb,
14
+ });
7
15
  export function makeReport(rows, opts) {
8
16
  return {
9
17
  tool: "sandboxrouter",
@@ -49,17 +57,18 @@ const KNOWN = new Set(CATALOG.map((c) => c.id));
49
57
  * the one with the most runs wins (a 100-run start-time benchmark over a 3-run job that also timed starts);
50
58
  * ties go to the newest.
51
59
  */
52
- export function aggregate(reports) {
60
+ export function aggregate(reports, cohort = DEFAULT_SIZE) {
61
+ const comparable = reports.filter((r) => sameSize(requestedSize(r.spec ?? {}), cohort));
53
62
  const latest = new Map();
54
63
  const newest = new Map();
55
- for (const rep of reports)
64
+ for (const rep of comparable)
56
65
  for (const r of rep.rows) {
57
66
  const key = `${r.provider}\u0000${rep.label ?? ""}`;
58
67
  if ((newest.get(key) ?? "") < rep.date)
59
68
  newest.set(key, rep.date);
60
69
  }
61
70
  const MONTH = 30 * 86_400_000;
62
- for (const rep of reports) {
71
+ for (const rep of comparable) {
63
72
  for (const r of rep.rows) {
64
73
  if (!KNOWN.has(r.provider))
65
74
  continue;
@@ -75,7 +84,10 @@ export function aggregate(reports) {
75
84
  for (const x of latest.values())
76
85
  by.set(x.row.provider, [...(by.get(x.row.provider) ?? []), x]);
77
86
  const rows = [...by.entries()].map(([id, xs]) => {
78
- const rs = xs.map((x) => x.row);
87
+ const latestRow = xs.reduce((a, b) => a.date >= b.date ? a : b).row;
88
+ const size = latestRow.size ?? sizeOf(id, cohort);
89
+ const matching = xs.filter(({ row }) => sameSize(row.size ?? sizeOf(id, cohort), size));
90
+ const rs = matching.map((x) => x.row);
79
91
  const runs = rs.reduce((n, r) => n + r.runs, 0);
80
92
  const ok = rs.reduce((n, r) => n + (r.runs - r.failures), 0);
81
93
  // Refusals for a limit on the benchmarking account aren't the provider failing: leave them out of the rate.
@@ -86,11 +98,12 @@ export function aggregate(reports) {
86
98
  submissions: rs.length,
87
99
  medianCreateMs: median(rs.map((r) => r.medianCreateMs).filter((n) => typeof n === "number")),
88
100
  medianExecMs: median(rs.map((r) => r.medianExecMs).filter((n) => typeof n === "number")),
101
+ medianReadyMs: rs.every((r) => r.medianReadyMs !== undefined) ? median(rs.map((r) => r.medianReadyMs)) : undefined,
89
102
  successRate: attempted ? ok / attempted : 0,
90
103
  runs: attempted,
91
- hourlyUsd: hourlyCost(id, fittingSpec(id)),
92
- size: fittingSpec(id),
93
- measuredAt: xs.map((x) => x.date).sort().at(-1),
104
+ hourlyUsd: hourlyCost(id, size),
105
+ size,
106
+ measuredAt: matching.map((x) => x.date).sort().at(-1),
94
107
  };
95
108
  });
96
109
  return rows.sort((a, b) => (a.medianCreateMs ?? Infinity) - (b.medianCreateMs ?? Infinity));
@@ -100,16 +113,15 @@ export function aggregate(reports) {
100
113
  * `version` (the short task's by default; TASKS.long.version for `--long`): each provider's latest run
101
114
  * from each location, then the median across locations (as `aggregate` does). Cheapest task first.
102
115
  */
103
- export function taskTable(reports, version = TASK_VERSION) {
104
- const def = taskByVersion(version);
105
- if (!def)
106
- return [];
116
+ function currentTaskRows(reports, version, cohort) {
107
117
  const latest = new Map();
118
+ if (!isCurrentTask(version))
119
+ return new Map();
108
120
  for (const rep of reports) {
109
- if (rep.task !== version)
121
+ if (rep.task !== version || !sameSize(requestedSize(rep.spec ?? {}), cohort))
110
122
  continue;
111
123
  for (const r of rep.rows) {
112
- if (!KNOWN.has(r.provider) || !r.taskPhasesMs || r.medianTaskMs === undefined || r.medianCreateMs === undefined)
124
+ if (!KNOWN.has(r.provider) || r.size === undefined || r.taskOk === undefined)
113
125
  continue;
114
126
  const key = `${r.provider}\u0000${rep.label ?? ""}`;
115
127
  const seen = latest.get(key);
@@ -120,45 +132,71 @@ export function taskTable(reports, version = TASK_VERSION) {
120
132
  const by = new Map();
121
133
  for (const x of latest.values())
122
134
  by.set(x.row.provider, [...(by.get(x.row.provider) ?? []), x]);
123
- const rows = [...by.entries()].map(([id, xs]) => {
135
+ // Keep a provider's region samples comparable when its default shape changes between reports.
136
+ for (const [id, xs] of by) {
137
+ const newest = xs.reduce((a, b) => a.date >= b.date ? a : b);
138
+ by.set(id, xs.filter((x) => sameSize(x.row.size, newest.row.size)));
139
+ }
140
+ return by;
141
+ }
142
+ export function taskOutcomes(reports, version, cohort = DEFAULT_SIZE) {
143
+ return [...currentTaskRows(reports, version, cohort)].map(([provider, xs]) => ({
144
+ provider,
145
+ name: CATALOG.find((c) => c.id === provider).name,
146
+ requested: xs.reduce((n, x) => n + x.row.runs, 0),
147
+ completed: xs.reduce((n, x) => n + x.row.taskOk, 0),
148
+ limited: xs.reduce((n, x) => n + (x.row.limited ?? 0), 0),
149
+ failures: xs.reduce((n, x) => n + x.row.failures - (x.row.limited ?? 0), 0),
150
+ taskFailures: xs.reduce((n, x) => n + x.row.runs - x.row.failures - x.row.taskOk, 0),
151
+ }));
152
+ }
153
+ export function taskTable(reports, version = TASK_VERSION, cohort = DEFAULT_SIZE) {
154
+ const def = taskByVersion(version);
155
+ if (!def || !isCurrentTask(version))
156
+ return [];
157
+ const rows = [...currentTaskRows(reports, version, cohort)].flatMap(([id, xs]) => {
124
158
  const rs = xs.map((x) => x.row);
125
- const createMs = median(rs.map((r) => r.medianCreateMs));
126
- const taskMillis = median(rs.map((r) => r.medianTaskMs));
127
- const phasesMs = Object.fromEntries(def.phases.map((p) => [p.id, median(rs.map((r) => r.taskPhasesMs[p.id]))]));
159
+ const successful = rs.filter((r) => r.taskOk > 0 && r.taskPhasesMs && r.medianTaskMs !== undefined && r.medianTaskReadyMs !== undefined);
160
+ if (!successful.length)
161
+ return [];
162
+ const createMs = median(successful.map((r) => r.medianTaskReadyMs));
163
+ const taskMillis = median(successful.map((r) => r.medianTaskMs));
164
+ const phasesMs = Object.fromEntries(def.phases.map((p) => [p.id, median(successful.map((r) => r.taskPhasesMs[p.id]))]));
128
165
  // The job's own CPU hint (the agent loop's 10%) prices it the way its sandboxes were started.
129
- const size = { ...fittingSpec(id), ...(def.cpuUtilization ? { cpuUtilization: def.cpuUtilization } : {}) };
166
+ const size = { ...rs[0].size, ...(def.cpuUtilization ? { cpuUtilization: def.cpuUtilization } : {}) };
130
167
  const ratio = BILLED_VS_LIST[id]?.ratio ?? 1;
131
- const hourlyUsd = hourlyCost(id, fittingSpec(id)) * ratio;
168
+ const hourlyUsd = hourlyCost(id, size) * ratio;
132
169
  const rules = billingRules(id);
133
- const cpus = rs.map((r) => r.medianTaskCpuMs).filter((n) => typeof n === "number");
170
+ const cpus = successful.map((r) => r.medianTaskCpuMs).filter((n) => typeof n === "number");
134
171
  // A container can show the whole host's /proc/stat (Daytona does): a reading beyond what the sandbox's
135
172
  // own vCPUs could do in that time isn't the sandbox's, so it's dropped and the task is priced at full CPU.
136
- const read = cpus.length === rs.length ? median(cpus) : undefined;
173
+ const read = cpus.length === successful.length ? median(cpus) : undefined;
137
174
  const cpuMs = read !== undefined && read <= size.vcpu * taskMillis * 1.1 ? read : undefined;
138
- const cores = rs.map((r) => r.medianTaskMaxCoreMs).filter((n) => typeof n === "number");
139
- const coreRead = cores.length === rs.length ? median(cores) : undefined;
175
+ const cores = successful.map((r) => r.medianTaskMaxCoreMs).filter((n) => typeof n === "number");
176
+ const coreRead = cores.length === successful.length ? median(cores) : undefined;
140
177
  const maxCoreMs = cpuMs !== undefined && coreRead !== undefined && coreRead <= taskMillis * 1.1 ? coreRead : undefined;
141
- return {
142
- provider: id,
143
- name: CATALOG.find((c) => c.id === id).name,
144
- size,
145
- createMs,
146
- taskMs: taskMillis,
147
- phasesMs,
148
- hourlyUsd,
149
- taskUsd: taskUsd(id, size, createMs, taskMillis, cpuMs, ratio, false, maxCoreMs),
150
- reusedUsd: taskUsd(id, size, createMs, taskMillis, cpuMs, ratio, true, maxCoreMs),
151
- runs: rs.reduce((n, r) => n + r.runs - (r.limited ?? 0), 0),
152
- successRate: (() => {
153
- const tried = rs.reduce((n, r) => n + r.runs - (r.limited ?? 0), 0);
154
- return tried ? rs.reduce((n, r) => n + r.runs - r.failures, 0) / tried : 0;
155
- })(),
156
- ...(cpuMs !== undefined ? { cpuMs } : {}),
157
- activeCpu: cpuHourlyAtFull(id, size) > 0,
158
- minimumSeconds: rules.minSeconds,
159
- perSandboxUsd: rules.perSandboxUsd,
160
- measuredAt: xs.map((x) => x.date).sort().at(-1),
161
- };
178
+ const runs = rs.reduce((n, r) => n + r.runs, 0);
179
+ const ok = rs.reduce((n, r) => n + r.taskOk, 0);
180
+ return [{
181
+ provider: id,
182
+ name: CATALOG.find((c) => c.id === id).name,
183
+ size,
184
+ createMs,
185
+ taskMs: taskMillis,
186
+ phasesMs,
187
+ hourlyUsd,
188
+ taskUsd: taskUsd(id, size, createMs, taskMillis, cpuMs, ratio, false, maxCoreMs),
189
+ reusedUsd: taskUsd(id, size, createMs, taskMillis, cpuMs, ratio, true, maxCoreMs),
190
+ runs,
191
+ ok,
192
+ limited: rs.reduce((n, r) => n + (r.limited ?? 0), 0),
193
+ successRate: runs ? ok / runs : 0,
194
+ ...(cpuMs !== undefined ? { cpuMs } : {}),
195
+ activeCpu: cpuHourlyAtFull(id, size) > 0,
196
+ minimumSeconds: rules.minSeconds,
197
+ perSandboxUsd: rules.perSandboxUsd,
198
+ measuredAt: xs.map((x) => x.date).sort().at(-1),
199
+ }];
162
200
  });
163
201
  return rows.sort((a, b) => a.taskUsd - b.taskUsd || a.provider.localeCompare(b.provider));
164
202
  }
@@ -318,9 +356,6 @@ export function burstTable(reports, task, n) {
318
356
  if (n !== undefined && rep.n !== n)
319
357
  continue;
320
358
  for (const r of rep.rows) {
321
- // Nothing started (an account blocked outright): nothing measured.
322
- if (r.ok === 0)
323
- continue;
324
359
  if (!KNOWN.has(r.provider) || !benchmarksPublishable(r.provider))
325
360
  continue;
326
361
  const seen = latest.get(r.provider);
@@ -356,7 +391,11 @@ export function loadAgentReports(dir) {
356
391
  /** Each provider's latest real-agent result: done right first, then cheapest sandbox per session. */
357
392
  export function agentTable(reports) {
358
393
  const latest = new Map();
394
+ const current = reports.filter((r) => r.task === AGENT_TASK_VERSION);
395
+ const cohort = current.reduce((a, b) => !a || b.date > a.date ? b : a, undefined);
359
396
  for (const rep of reports) {
397
+ if (rep.task !== AGENT_TASK_VERSION || rep.model !== cohort?.model)
398
+ continue;
360
399
  for (const r of rep.rows) {
361
400
  if (!KNOWN.has(r.provider) || !benchmarksPublishable(r.provider))
362
401
  continue;
@@ -367,5 +406,5 @@ export function agentTable(reports) {
367
406
  }
368
407
  return [...latest.values()]
369
408
  .map(({ row, date, model }) => ({ ...row, name: CATALOG.find((c) => c.id === row.provider).name, measuredAt: date, model }))
370
- .sort((a, b) => b.ok / b.runs - a.ok / a.runs || (a.medianUsd ?? Infinity) - (b.medianUsd ?? Infinity));
409
+ .sort((a, b) => b.ok / Math.max(1, b.requested ?? b.runs) - a.ok / Math.max(1, a.requested ?? a.runs) || (a.medianUsd ?? Infinity) - (b.medianUsd ?? Infinity));
371
410
  }
@@ -1,9 +1,9 @@
1
1
  import type { ProviderId } from "./types.js";
2
2
  /**
3
3
  * The price index: what a few standard pieces of sandbox work cost today across the providers that passed
4
- * the real-account check. Each line is the median of what the router would charge on each of them (list
5
- * price, corrected by measured bills, with minimum charges and per-sandbox fees over the run), plus the
6
- * cheapest. It moves only when a provider's price in the catalog changes.
4
+ * the real-account check. Each line shows the median and lowest estimated direct-provider cost (list
5
+ * price, corrected by measured bills, with minimum charges and modeled per-sandbox fees over the run).
6
+ * Account-specific fees, such as Boat's allowance overages, are excluded.
7
7
  */
8
8
  export declare const INDEX_LINES: readonly [{
9
9
  readonly id: "2x4-hour";
@@ -4,9 +4,9 @@ import { Router, rankUsd, runHours } from "./router.js";
4
4
  import { VERIFIED } from "./verified.js";
5
5
  /**
6
6
  * The price index: what a few standard pieces of sandbox work cost today across the providers that passed
7
- * the real-account check. Each line is the median of what the router would charge on each of them (list
8
- * price, corrected by measured bills, with minimum charges and per-sandbox fees over the run), plus the
9
- * cheapest. It moves only when a provider's price in the catalog changes.
7
+ * the real-account check. Each line shows the median and lowest estimated direct-provider cost (list
8
+ * price, corrected by measured bills, with minimum charges and modeled per-sandbox fees over the run).
9
+ * Account-specific fees, such as Boat's allowance overages, are excluded.
10
10
  */
11
11
  export const INDEX_LINES = [
12
12
  { id: "2x4-hour", label: "2 vCPU / 4 GB, one hour", unit: "per hour", spec: { vcpu: 2, memoryGb: 4, timeoutMinutes: 60 }, scale: 1 },
@@ -53,8 +53,11 @@ export class DockerProvider {
53
53
  }
54
54
  async connect(nativeId) {
55
55
  const r = await run(this.bin, ["inspect", "-f", "{{.State.Status}}", nativeId]);
56
- if (r.code !== 0)
57
- throw new ProviderError("docker", `no container ${nativeId}`, 404);
56
+ if (r.code !== 0) {
57
+ if (containerAbsent(r.stderr))
58
+ throw new ProviderError("docker", `no container ${nativeId}`, 404);
59
+ throw new ProviderError("docker", `inspect failed: ${r.stderr.trim().slice(0, 300)}`);
60
+ }
58
61
  if (r.stdout.trim() === "paused")
59
62
  await run(this.bin, ["unpause", nativeId]);
60
63
  return new DockerBox(this.bin, nativeId);
@@ -103,9 +106,16 @@ class DockerBox {
103
106
  throw new ProviderError("docker", `pause failed: ${r.stderr.trim()}`);
104
107
  }
105
108
  async kill() {
106
- await run(this.bin, ["rm", "-f", this.nativeId]);
109
+ const r = await run(this.bin, ["rm", "-f", this.nativeId]);
110
+ if (r.code !== 0 && !containerAbsent(r.stderr)) {
111
+ throw new ProviderError("docker", `docker rm failed: ${r.stderr.trim().slice(0, 300)}`);
112
+ }
107
113
  }
108
114
  }
115
+ /** Only an explicit daemon response confirms that the container is gone. */
116
+ function containerAbsent(stderr) {
117
+ return /^(?:Error(?: response from daemon)?: )?No such (?:container|object): /im.test(stderr);
118
+ }
109
119
  function run(bin, args, opts = {}) {
110
120
  const t0 = Date.now();
111
121
  return new Promise((resolve, reject) => {
@@ -57,21 +57,14 @@ export declare class LimrunProvider implements ComputerProvider {
57
57
  baseURL?: string;
58
58
  });
59
59
  configured(): boolean;
60
- /** @internal */
61
- client(): Promise<{
62
- mod: LimrunModule;
63
- lim: LimrunClient;
64
- }>;
60
+ private client;
65
61
  createComputer(spec: ComputerSpec): Promise<ProviderComputer>;
66
62
  /** Limrun ids don't say which platform they belong to, so try Android, then iOS. */
67
63
  connectComputer(nativeId: string): Promise<ProviderComputer>;
68
64
  }
69
- type LimrunModule = typeof import("@limrun/api");
70
- type LimrunClient = InstanceType<LimrunModule["Limrun"]>;
71
65
  /** @internal "ctrl+Return" on android -> { key: "ENTER", modifiers: ["ctrl"] }. Throws if unavailable. */
72
66
  export declare function limrunKey(chord: string, os: "android" | "ios"): {
73
67
  key: string;
74
68
  modifiers: string[];
75
69
  button?: string;
76
70
  };
77
- export {};
@@ -60,7 +60,6 @@ export class LimrunProvider {
60
60
  configured() {
61
61
  return !!this.apiKey;
62
62
  }
63
- /** @internal */
64
63
  client() {
65
64
  if (!this.apiKey)
66
65
  return Promise.reject(err("LIM_API_KEY is not set"));
@@ -1,6 +1,4 @@
1
1
  import type { ComputerOs, ComputerProvider, ComputerSpec, ProviderComputer } from "../computers.js";
2
- type MobilerunModule = typeof import("@mobilerun/sdk");
3
- type MobilerunClient = InstanceType<MobilerunModule["Mobilerun"]>;
4
2
  /**
5
3
  * Mobilerun (droidrun) cloud Android phones via `@mobilerun/sdk`. Desktop-only: no sandboxes.
6
4
  *
@@ -25,8 +23,7 @@ export declare class MobilerunProvider implements ComputerProvider {
25
23
  /** The SDK reads MOBILERUN_CLOUD_API_KEY itself; we read it too so configured() is honest. */
26
24
  constructor(apiKey?: string | undefined, baseURL?: string | undefined);
27
25
  configured(): boolean;
28
- /** @internal */
29
- sdk(): Promise<MobilerunClient>;
26
+ private sdk;
30
27
  createComputer(spec: ComputerSpec): Promise<ProviderComputer>;
31
28
  /** Re-attach by device id. A parked (stopped) phone is resumed and waited on. */
32
29
  connectComputer(nativeId: string): Promise<ProviderComputer>;
@@ -41,4 +38,3 @@ export declare class MobilerunProvider implements ComputerProvider {
41
38
  export declare const MOBILERUN_KEYS: Record<string, number>;
42
39
  /** One xdotool key name (no modifiers) to an Android key code. */
43
40
  export declare function mobilerunKey(name: string): number;
44
- export {};
@@ -35,7 +35,6 @@ export class MobilerunProvider {
35
35
  configured() {
36
36
  return !!this.apiKey;
37
37
  }
38
- /** @internal */
39
38
  async sdk() {
40
39
  if (!this.apiKey)
41
40
  throw new ProviderError(ID, "MOBILERUN_CLOUD_API_KEY is not set");
@@ -58,12 +57,12 @@ export class MobilerunProvider {
58
57
  if (mine) {
59
58
  if (mine.state === "stopped")
60
59
  await guard(client.devices.resume(mine.id));
61
- return new MobilerunComputer(this, await waitReady(client, mine.id));
60
+ return new MobilerunComputer(client, await waitReady(client, mine.id));
62
61
  }
63
62
  }
64
63
  const created = await guard(client.devices.create({ deviceType: "android_cloud_phone", billing: "auto", ...(name ? { name } : {}) }));
65
64
  const ready = created.state === "ready" ? created : await waitReady(client, created.id);
66
- return new MobilerunComputer(this, ready);
65
+ return new MobilerunComputer(client, ready);
67
66
  }
68
67
  /** Re-attach by device id. A parked (stopped) phone is resumed and waited on. */
69
68
  async connectComputer(nativeId) {
@@ -73,7 +72,7 @@ export class MobilerunProvider {
73
72
  throw new ProviderError(ID, `device ${nativeId} is terminated`, 404);
74
73
  if (d.state === "stopped")
75
74
  await guard(client.devices.resume(nativeId));
76
- return new MobilerunComputer(this, d.state === "ready" ? d : await waitReady(client, nativeId));
75
+ return new MobilerunComputer(client, d.state === "ready" ? d : await waitReady(client, nativeId));
77
76
  }
78
77
  }
79
78
  /**
@@ -203,19 +202,16 @@ async function bytesOf(p) {
203
202
  }
204
203
  /** Gestures take the canonical frame (the last screenshot), which is the phone's native pixels. */
205
204
  class MobilerunComputer {
206
- p;
205
+ client;
207
206
  nativeId;
208
207
  frame = 0;
209
208
  size;
210
- constructor(p, device) {
211
- this.p = p;
209
+ constructor(client, device) {
210
+ this.client = client;
212
211
  this.nativeId = device.id;
213
212
  }
214
- sdk() {
215
- return this.p.sdk();
216
- }
217
213
  async info() {
218
- const d = await guard((await this.sdk()).devices.retrieve(this.nativeId));
214
+ const d = await guard(this.client.devices.retrieve(this.nativeId));
219
215
  const status = d.state === "ready" ? "ready" : d.state === "stopped" ? "sleeping" : d.state === "terminated" ? "deleted" : d.state;
220
216
  const info = {
221
217
  id: d.id,
@@ -250,8 +246,7 @@ class MobilerunComputer {
250
246
  return out;
251
247
  }
252
248
  async capture() {
253
- const client = await this.sdk();
254
- const png = await bytesOf(client.devices.screenshots.capture(this.nativeId, {}, { headers: { "Accept-Encoding": "identity" } }));
249
+ const png = await bytesOf(this.client.devices.screenshots.capture(this.nativeId, {}, { headers: { "Accept-Encoding": "identity" } }));
255
250
  if (!png.length)
256
251
  throw new Error("screenshot came back empty");
257
252
  const s = pngSize(png);
@@ -271,7 +266,6 @@ class MobilerunComputer {
271
266
  return this.size;
272
267
  }
273
268
  async perform(a) {
274
- const client = await this.sdk();
275
269
  const id = this.nativeId;
276
270
  switch (a.action) {
277
271
  case "screenshot":
@@ -282,7 +276,7 @@ class MobilerunComputer {
282
276
  if (a.modifier)
283
277
  throw new Error("mobilerun taps can't hold modifier keys");
284
278
  const [x, y] = a.coordinate;
285
- await client.devices.actions.tap(id, { x: Math.round(x), y: Math.round(y) });
279
+ await this.client.devices.actions.tap(id, { x: Math.round(x), y: Math.round(y) });
286
280
  return {};
287
281
  }
288
282
  case "left_click_drag": {
@@ -290,7 +284,7 @@ class MobilerunComputer {
290
284
  throw new Error("left_click_drag needs startCoordinate and coordinate (a phone has no cursor)");
291
285
  const [sx, sy] = a.startCoordinate;
292
286
  const [ex, ey] = a.coordinate;
293
- await client.devices.actions.swipe(id, { startX: Math.round(sx), startY: Math.round(sy), endX: Math.round(ex), endY: Math.round(ey), duration: 600 });
287
+ await this.client.devices.actions.swipe(id, { startX: Math.round(sx), startY: Math.round(sy), endX: Math.round(ex), endY: Math.round(ey), duration: 600 });
294
288
  return {};
295
289
  }
296
290
  case "scroll": {
@@ -308,13 +302,13 @@ class MobilerunComputer {
308
302
  const [sx, sy, ex, ey] = vertical
309
303
  ? [cx, cy + (sign * span) / 2, cx, cy - (sign * span) / 2]
310
304
  : [cx + (sign * span) / 2, cy, cx - (sign * span) / 2, cy];
311
- await client.devices.actions.swipe(id, { startX: clampX(sx), startY: clampY(sy), endX: clampX(ex), endY: clampY(ey), duration: 400 });
305
+ await this.client.devices.actions.swipe(id, { startX: clampX(sx), startY: clampY(sy), endX: clampX(ex), endY: clampY(ey), duration: 400 });
312
306
  return {};
313
307
  }
314
308
  case "type":
315
309
  if (!a.text)
316
310
  throw new Error("type needs text");
317
- await client.devices.keyboard.write(id, { text: a.text });
311
+ await this.client.devices.keyboard.write(id, { text: a.text });
318
312
  return {};
319
313
  case "key": {
320
314
  if (!a.text)
@@ -323,7 +317,7 @@ class MobilerunComputer {
323
317
  const codes = a.text.trim().split(/\s+/).map(mobilerunKey);
324
318
  for (let n = 0; n < Math.max(1, a.repeat ?? 1); n++) {
325
319
  for (const key of codes)
326
- await client.devices.keyboard.key(id, { key });
320
+ await this.client.devices.keyboard.key(id, { key });
327
321
  }
328
322
  return {};
329
323
  }
@@ -362,9 +356,8 @@ class MobilerunComputer {
362
356
  }
363
357
  /** Pulls a file from a device path, e.g. /sdcard/Download/report.pdf. */
364
358
  async readFile(path) {
365
- const client = await this.sdk();
366
359
  try {
367
- return await bytesOf(client.devices.files.download(this.nativeId, { path }, { headers: { "Accept-Encoding": "identity" } }));
360
+ return await bytesOf(this.client.devices.files.download(this.nativeId, { path }, { headers: { "Accept-Encoding": "identity" } }));
368
361
  }
369
362
  catch (err) {
370
363
  throw toProviderError(err);
@@ -375,10 +368,9 @@ class MobilerunComputer {
375
368
  const name = path.slice(path.lastIndexOf("/") + 1);
376
369
  if (!name)
377
370
  throw new ProviderError(ID, `writeFile needs a file path, got directory "${path}"`);
378
- const client = await this.sdk();
379
371
  const { toFile } = await optionalImport("@mobilerun/sdk", "mobilerun");
380
372
  const file = await toFile(Buffer.from(toBytes(content)), name);
381
- await guard(client.devices.files.upload(this.nativeId, { path: dirname(path), file }));
373
+ await guard(this.client.devices.files.upload(this.nativeId, { path: dirname(path), file }));
382
374
  }
383
375
  /**
384
376
  * The device's WebRTC stream: `url` is the device's streamUrl and `token` its device-scoped
@@ -387,7 +379,7 @@ class MobilerunComputer {
387
379
  * (DeviceStream hasControl={false}). Mobilerun does not publish an expiry, so expiresAt is null.
388
380
  */
389
381
  async viewer(mode = "watch", _opts = {}) {
390
- const d = await guard((await this.sdk()).devices.retrieve(this.nativeId));
382
+ const d = await guard(this.client.devices.retrieve(this.nativeId));
391
383
  if (!d.streamUrl || !d.streamToken)
392
384
  throw new ProviderError(ID, `no live stream for device ${this.nativeId} (state: ${d.state})`);
393
385
  return {
@@ -400,11 +392,11 @@ class MobilerunComputer {
400
392
  }
401
393
  /** Park: apps, data and identity kept, no minutes billed. connectComputer resumes it. 404 where capabilities.stop is false. */
402
394
  async sleep() {
403
- await guard((await this.sdk()).devices.stop(this.nativeId));
395
+ await guard(this.client.devices.stop(this.nativeId));
404
396
  }
405
397
  /** Terminate and release. Subscription-billed (dedicated) phones refuse this with 401. */
406
398
  async delete() {
407
- await guard((await this.sdk()).devices.terminate(this.nativeId));
399
+ await guard(this.client.devices.terminate(this.nativeId));
408
400
  }
409
401
  }
410
402
  function seconds(n) {
@@ -1,4 +1,4 @@
1
- import { DEFAULT_MEMORY_GB, DEFAULT_VCPU } from "../catalog.js";
1
+ import { vercelSandboxSize } from "../catalog.js";
2
2
  import { ProviderError } from "../types.js";
3
3
  import { DEFAULT_EXEC_TIMEOUT_S, killedByTimeout, optionalImport, timeoutError, toBytes, wrapCommand } from "../util.js";
4
4
  /**
@@ -19,7 +19,7 @@ export class VercelProvider {
19
19
  }
20
20
  async create(spec) {
21
21
  const { Sandbox } = await optionalImport("@vercel/sandbox", "vercel");
22
- const vcpus = Math.min(8, Math.max(spec.vcpu ?? DEFAULT_VCPU, Math.ceil((spec.memoryGb ?? DEFAULT_MEMORY_GB) / 2)));
22
+ const { vcpu: vcpus } = vercelSandboxSize(spec);
23
23
  const sbx = await Sandbox.create({
24
24
  ...this.creds(),
25
25
  runtime: spec.image?.vercel ?? "node22",