@parcha/agentrun-computer 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/README.md +308 -36
- package/dist/browser.d.ts +13 -14
- package/dist/browser.js +22 -17
- package/dist/browserbase.d.ts +3 -3
- package/dist/browserbase.js +16 -11
- package/dist/child.d.ts +2 -0
- package/dist/child.js +13 -2
- package/dist/chrome.d.ts +73 -0
- package/dist/chrome.js +224 -0
- package/dist/computerd-linux-amd64 +0 -0
- package/dist/computerd-linux-arm64 +0 -0
- package/dist/conformance/browserbase.js +1 -1
- package/dist/conformance/cases/gpu.d.ts +2 -0
- package/dist/conformance/cases/gpu.js +108 -0
- package/dist/conformance/cases/health.js +83 -3
- package/dist/conformance/cases/index.js +2 -0
- package/dist/conformance/cases/mount.d.ts +8 -1
- package/dist/conformance/cases/mount.js +4 -3
- package/dist/conformance/cases/provider.js +92 -3
- package/dist/conformance/cli.js +46 -7
- package/dist/conformance/daytona.js +2 -1
- package/dist/conformance/e2b.js +2 -1
- package/dist/conformance/fixture.js +24 -2
- package/dist/conformance/kernel.js +1 -1
- package/dist/conformance/kind.js +2 -1
- package/dist/conformance/local-chrome.d.ts +30 -0
- package/dist/conformance/local-chrome.js +36 -0
- package/dist/conformance/orgo.d.ts +11 -5
- package/dist/conformance/orgo.js +37 -8
- package/dist/conformance/phone-harness.js +2 -1
- package/dist/conformance/report.js +13 -7
- package/dist/conformance/runner.js +68 -18
- package/dist/conformance/types.d.ts +78 -18
- package/dist/conformance/types.js +10 -0
- package/dist/conformance/windows-fixture.d.ts +1 -0
- package/dist/conformance/windows-fixture.js +37 -0
- package/dist/daytona.d.ts +4 -6
- package/dist/daytona.js +97 -52
- package/dist/descriptor.d.ts +94 -0
- package/dist/descriptor.js +81 -0
- package/dist/descriptors/browserbase.d.ts +24 -0
- package/dist/descriptors/browserbase.js +18 -0
- package/dist/descriptors/daytona.d.ts +62 -0
- package/dist/descriptors/daytona.js +49 -0
- package/dist/descriptors/docker.d.ts +12 -0
- package/dist/descriptors/docker.js +17 -0
- package/dist/descriptors/e2b.d.ts +22 -0
- package/dist/descriptors/e2b.js +19 -0
- package/dist/descriptors/index.d.ts +229 -0
- package/dist/descriptors/index.js +19 -0
- package/dist/descriptors/kernel.d.ts +20 -0
- package/dist/descriptors/kernel.js +15 -0
- package/dist/descriptors/local-chrome.d.ts +17 -0
- package/dist/descriptors/local-chrome.js +21 -0
- package/dist/descriptors/modal.d.ts +50 -0
- package/dist/descriptors/modal.js +38 -0
- package/dist/descriptors/orgo.d.ts +88 -0
- package/dist/descriptors/orgo.js +44 -0
- package/dist/descriptors/phone-harness.d.ts +28 -0
- package/dist/descriptors/phone-harness.js +20 -0
- package/dist/descriptors/shared.d.ts +7 -0
- package/dist/descriptors/shared.js +6 -0
- package/dist/desktop.d.ts +4 -4
- package/dist/desktop.js +4 -4
- package/dist/docker/egress.d.ts +1 -1
- package/dist/docker/image.js +17 -15
- package/dist/docker/inspect.d.ts +147 -0
- package/dist/docker/inspect.js +335 -0
- package/dist/docker.d.ts +6 -4
- package/dist/docker.js +53 -41
- package/dist/drift.d.ts +6 -146
- package/dist/drift.js +14 -334
- package/dist/e2b.d.ts +2 -6
- package/dist/e2b.js +19 -22
- package/dist/index.d.ts +9 -10
- package/dist/index.js +14 -10
- package/dist/isolation.d.ts +0 -2
- package/dist/isolation.js +2 -18
- package/dist/janitor.d.ts +18 -1
- package/dist/janitor.js +67 -19
- package/dist/kernel.d.ts +3 -3
- package/dist/kernel.js +19 -14
- package/dist/kinds.d.ts +56 -30
- package/dist/kinds.js +19 -97
- package/dist/labels.d.ts +18 -0
- package/dist/labels.js +65 -2
- package/dist/local-chrome.d.ts +86 -0
- package/dist/local-chrome.js +475 -0
- package/dist/local-supervisor.d.ts +51 -0
- package/dist/local-supervisor.js +221 -0
- package/dist/modal.d.ts +15 -7
- package/dist/modal.js +83 -39
- package/dist/mount-archil.js +4 -4
- package/dist/orgo-channel.js +16 -13
- package/dist/orgo-desktop.d.ts +153 -0
- package/dist/orgo-desktop.js +1614 -0
- package/dist/orgo-names.d.ts +52 -0
- package/dist/orgo-names.js +84 -0
- package/dist/orgo.d.ts +18 -13
- package/dist/orgo.js +54 -128
- package/dist/phone-harness.d.ts +4 -8
- package/dist/phone-harness.js +48 -46
- package/dist/protocol.d.ts +20 -0
- package/dist/protocol.js +9 -0
- package/dist/provider.d.ts +151 -10
- package/dist/provider.js +70 -0
- package/dist/providers.d.ts +22 -17
- package/dist/providers.js +14 -16
- package/dist/result.d.ts +11 -1
- package/dist/result.js +11 -0
- package/dist/test-connection.js +2 -2
- package/package.json +42 -2
package/dist/phone-harness.js
CHANGED
|
@@ -14,21 +14,20 @@ import { readFileSync } from "node:fs";
|
|
|
14
14
|
import { createConnection } from "node:net";
|
|
15
15
|
import { crc32, deflateSync } from "node:zlib";
|
|
16
16
|
import { checkActions } from "./actions.js";
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
17
|
+
import { PHONE_GROUPS, PHONE_HARNESS } from "./descriptors/phone-harness.js";
|
|
18
|
+
import { MAX_CHUNK_BYTES, MAX_UI_NODES, PROTOCOL_VERSION, } from "./protocol.js";
|
|
19
|
+
import { checkGpu, checkTenure, runLifetimeMs, } from "./provider.js";
|
|
20
|
+
import { failFor, ok, vendorFail } from "./result.js";
|
|
20
21
|
import { daemonWatch, redactWords } from "./screen-watch.js";
|
|
21
22
|
import { listTested } from "./test-connection.js";
|
|
23
|
+
/** This module's failures: one with code vendor names the phone harness. */
|
|
24
|
+
const fail = failFor("phone-harness");
|
|
22
25
|
/** The phone harness's API. */
|
|
23
26
|
export const PHONE_HARNESS_URL = "https://api.phone-harness.com";
|
|
24
|
-
/** What a cloud Android offers through this provider, as its capabilities and hello declare them. */
|
|
25
|
-
export const PHONE_GROUPS = ["screen", "input.touch", "input.keys", "apps", "apps.ui_tree"];
|
|
26
27
|
/** A phone mounts no folder. */
|
|
27
|
-
export const MOUNT =
|
|
28
|
-
/** The one configuration it offers, as its capabilities() declare it:
|
|
29
|
-
export const CAPABILITIES =
|
|
30
|
-
/** The image a phone is read back by: a cloud Android has none to choose, so a setting that names none takes this. */
|
|
31
|
-
export const PHONE_IMAGE = "android";
|
|
28
|
+
export const MOUNT = PHONE_HARNESS.mounts;
|
|
29
|
+
/** The one configuration it offers, as its capabilities() declare it: its descriptor's. */
|
|
30
|
+
export const CAPABILITIES = PHONE_HARNESS.capabilities;
|
|
32
31
|
/** The longest lifetime by default: a rented phone bills by the minute. */
|
|
33
32
|
export const DEFAULT_MAX_LIFETIME_MS = 30 * 60_000;
|
|
34
33
|
/** How long create waits for a phone to be ready by default: the service's own CLI waits 240 s. */
|
|
@@ -79,7 +78,7 @@ async function ledgerSafe(fn) {
|
|
|
79
78
|
}
|
|
80
79
|
catch (error) {
|
|
81
80
|
if (error instanceof LedgerFailure)
|
|
82
|
-
return
|
|
81
|
+
return vendorFail("phone-harness", error.message);
|
|
83
82
|
throw error;
|
|
84
83
|
}
|
|
85
84
|
}
|
|
@@ -111,7 +110,7 @@ export function adbCli(path = "adb", { port = ADB_SERVER_PORT, env } = {}) {
|
|
|
111
110
|
if (error && signal?.aborted)
|
|
112
111
|
return resolve(fail("aborted", "adb was aborted"));
|
|
113
112
|
if (error && typeof error.code !== "number")
|
|
114
|
-
return resolve(
|
|
113
|
+
return resolve(vendorFail("phone-harness", `adb could not run: ${error.message.split("\n")[0]}`));
|
|
115
114
|
resolve(ok({ exitCode: typeof code === "number" ? code : error ? 1 : 0, stdout: Buffer.from(stdout), stderr: Buffer.from(stderr).toString("utf8") }));
|
|
116
115
|
});
|
|
117
116
|
// stdin always ends, so no adb waits on it; it carries the input when there is one.
|
|
@@ -125,7 +124,7 @@ export function adbCli(path = "adb", { port = ADB_SERVER_PORT, env } = {}) {
|
|
|
125
124
|
const start = await started;
|
|
126
125
|
if (!start.ok || start.value.exitCode !== 0) {
|
|
127
126
|
started = undefined;
|
|
128
|
-
return start.ok ?
|
|
127
|
+
return start.ok ? vendorFail("phone-harness", `adb start-server failed: ${start.value.stderr.trim().split("\n")[0] || `exit code ${start.value.exitCode}`}`) : start;
|
|
129
128
|
}
|
|
130
129
|
const frame = (request) => `${Buffer.byteLength(request).toString(16).padStart(4, "0")}${request}`;
|
|
131
130
|
return new Promise((resolve) => {
|
|
@@ -155,10 +154,10 @@ export function adbCli(path = "adb", { port = ADB_SERVER_PORT, env } = {}) {
|
|
|
155
154
|
bound = true;
|
|
156
155
|
socket.write(frame(service));
|
|
157
156
|
});
|
|
158
|
-
socket.on("error", (error) => done(
|
|
157
|
+
socket.on("error", (error) => done(vendorFail("phone-harness", `the adb server on 127.0.0.1:${port} could not be reached for ${what}: ${error.message}`)));
|
|
159
158
|
socket.on("close", () => {
|
|
160
159
|
if (!bound)
|
|
161
|
-
return done(
|
|
160
|
+
return done(vendorFail("phone-harness", `the adb server closed host:transport-id:${transport} before it answered`));
|
|
162
161
|
// A phone's service answers OKAY and then its output, with no length: the output is what follows.
|
|
163
162
|
if (transport !== undefined && buffer.subarray(0, 4).toString("latin1") === "OKAY")
|
|
164
163
|
return done(ok(buffer.subarray(4).toString("utf8")));
|
|
@@ -185,8 +184,8 @@ export function adbAnswer(raw, what) {
|
|
|
185
184
|
if (status === "OKAY")
|
|
186
185
|
return ok(message);
|
|
187
186
|
if (status === "FAIL")
|
|
188
|
-
return
|
|
189
|
-
return
|
|
187
|
+
return vendorFail("phone-harness", `the adb server refused ${what}: ${redactWords(message.trim())}`);
|
|
188
|
+
return vendorFail("phone-harness", `the adb server answered ${what} with ${JSON.stringify(raw.subarray(0, 40).toString("latin1"))}, not OKAY or FAIL`);
|
|
190
189
|
}
|
|
191
190
|
/** The phone-harness provider from its options alone; throws in words when one is missing or wrong. */
|
|
192
191
|
export async function create(options) {
|
|
@@ -259,7 +258,7 @@ export class PhoneHarnessProvider {
|
|
|
259
258
|
os: "android",
|
|
260
259
|
daemon: "none",
|
|
261
260
|
lifetime: "vendor",
|
|
262
|
-
network: [
|
|
261
|
+
network: [...PHONE_HARNESS.network],
|
|
263
262
|
isolation: "vm",
|
|
264
263
|
groups: [...PHONE_GROUPS],
|
|
265
264
|
maxLifetimeMs: this.#maxLifetimeMs,
|
|
@@ -267,7 +266,7 @@ export class PhoneHarnessProvider {
|
|
|
267
266
|
};
|
|
268
267
|
}
|
|
269
268
|
check(spec) {
|
|
270
|
-
const refusals =
|
|
269
|
+
const refusals = checkTenure({ lifetimeMs: spec?.lifetimeMs, owner: spec?.owner }, this.capabilities(), "phone harness");
|
|
271
270
|
if (typeof spec?.image !== "string" || spec.image === "")
|
|
272
271
|
refusals.push({ field: "image", message: "image is required: a name the phone is read back by (a cloud Android has no image to choose)" });
|
|
273
272
|
if (spec?.network !== "open")
|
|
@@ -280,6 +279,7 @@ export class PhoneHarnessProvider {
|
|
|
280
279
|
}
|
|
281
280
|
if (spec?.mount !== undefined)
|
|
282
281
|
refusals.push({ field: "mount", message: "mount: a cloud phone mounts no folder" });
|
|
282
|
+
refusals.push(...checkGpu(spec?.gpu, this.capabilities()));
|
|
283
283
|
return refusals;
|
|
284
284
|
}
|
|
285
285
|
// --- the API ---------------------------------------------------------------------------------------------------
|
|
@@ -348,7 +348,7 @@ export class PhoneHarnessProvider {
|
|
|
348
348
|
return fail("limit", `${where}: ${said} (session_limit)`);
|
|
349
349
|
if (response.status === 404)
|
|
350
350
|
return fail("not_found", `${where}: ${said} (404)`);
|
|
351
|
-
const failed =
|
|
351
|
+
const failed = vendorFail("phone-harness", `${where}: ${said} (${response.status}${answer.code ? `, ${answer.code}` : ""})`);
|
|
352
352
|
// A 5xx is no refusal: a gateway may answer it for a request the service went on to act on.
|
|
353
353
|
return response.status >= 500 ? { ...failed, uncertain: true } : failed;
|
|
354
354
|
}
|
|
@@ -415,10 +415,10 @@ export class PhoneHarnessProvider {
|
|
|
415
415
|
return fail("aborted", "create was aborted before the phone harness was asked");
|
|
416
416
|
const from = this.#now();
|
|
417
417
|
const requestKey = randomBytes(16).toString("hex");
|
|
418
|
-
const body = { platform: "android", kind: "emulator", timeout_seconds: Math.ceil(spec
|
|
418
|
+
const body = { platform: "android", kind: "emulator", timeout_seconds: Math.ceil(runLifetimeMs(spec) / 1000) };
|
|
419
419
|
// The key goes into the ledger before the POST: whatever answers are lost, list() can find the phone by it.
|
|
420
420
|
const pending = pendingId(requestKey);
|
|
421
|
-
await this.#ledger.put({ id: pending, labels: { ...(spec.labels ?? {}) }, image: spec.image, deadline: new Date(from + spec
|
|
421
|
+
await this.#ledger.put({ id: pending, labels: { ...(spec.labels ?? {}) }, image: spec.image, deadline: new Date(from + runLifetimeMs(spec)).toISOString(), request: requestKey });
|
|
422
422
|
const posted = await this.#api("POST", "/sessions", { body, headers: { "Idempotency-Key": requestKey }, ...(signal ? { signal } : {}) });
|
|
423
423
|
const cancelled = !posted.ok && posted.error.code === "aborted";
|
|
424
424
|
let first = posted.ok ? sessionOf(posted.value.json, "POST /sessions") : undefined;
|
|
@@ -432,10 +432,10 @@ export class PhoneHarnessProvider {
|
|
|
432
432
|
const kept = "the ledger keeps the request's key, so list() finds the phone if it was made";
|
|
433
433
|
const recovered = await this.#api("GET", `/sessions/requests/${requestKey}`);
|
|
434
434
|
if (!recovered.ok)
|
|
435
|
-
return fail(cancelled ? "aborted" : "
|
|
435
|
+
return fail(cancelled ? "aborted" : "vendor", `${why}; and the service has no session for the request: ${recovered.error.message}; ${kept}`);
|
|
436
436
|
first = sessionOf(recovered.value.json, `GET /sessions/requests/${requestKey}`);
|
|
437
437
|
if (!first.ok)
|
|
438
|
-
return fail(cancelled ? "aborted" : "
|
|
438
|
+
return fail(cancelled ? "aborted" : "vendor", `${why}; and its recovery answered no session: ${first.error.message}; ${kept}`);
|
|
439
439
|
}
|
|
440
440
|
else if (!posted.ok) {
|
|
441
441
|
// The phone harness refused the request: nothing was made, and the key is forgotten.
|
|
@@ -443,7 +443,7 @@ export class PhoneHarnessProvider {
|
|
|
443
443
|
return posted;
|
|
444
444
|
}
|
|
445
445
|
if (first === undefined || !first.ok)
|
|
446
|
-
return
|
|
446
|
+
return vendorFail("phone-harness", "POST /sessions answered no session");
|
|
447
447
|
const id = first.value.id;
|
|
448
448
|
/** A ledger write about the phone, or the phone ended in words: a phone its ledger cannot record would bill unseen. */
|
|
449
449
|
const record = async (write) => {
|
|
@@ -455,11 +455,11 @@ export class PhoneHarnessProvider {
|
|
|
455
455
|
// Ended at once, by the API alone: the ledger has just failed.
|
|
456
456
|
const ended = await this.#api("DELETE", `/sessions/${encodeURIComponent(id)}`);
|
|
457
457
|
const after = ended.ok || ended.error.code === "not_found" ? "the phone was ended" : `the phone ${id} could not be ended (${ended.error.message})`;
|
|
458
|
-
return
|
|
458
|
+
return vendorFail("phone-harness", `${error instanceof Error ? error.message : String(error)}; ${after}`);
|
|
459
459
|
}
|
|
460
460
|
};
|
|
461
461
|
const named = await record(async () => {
|
|
462
|
-
await this.#ledger.put({ id, labels: { ...(spec.labels ?? {}) }, image: spec.image, deadline: this.#deadlineOf(first.value, from + spec
|
|
462
|
+
await this.#ledger.put({ id, labels: { ...(spec.labels ?? {}) }, image: spec.image, deadline: this.#deadlineOf(first.value, from + runLifetimeMs(spec)) });
|
|
463
463
|
await this.#ledger.remove(pending);
|
|
464
464
|
});
|
|
465
465
|
if (!named.ok)
|
|
@@ -488,23 +488,23 @@ export class PhoneHarnessProvider {
|
|
|
488
488
|
return ended("timeout", `the phone ${id} was not ready within ${this.#readyMs / 1000} s: ${read.error.message}`);
|
|
489
489
|
}
|
|
490
490
|
if (!read.ok)
|
|
491
|
-
return ended(read.error.code === "gone" ? "
|
|
491
|
+
return ended(read.error.code === "gone" ? "vendor" : read.error.code, `the phone ${id} did not start: ${read.error.message}`);
|
|
492
492
|
session = read.value;
|
|
493
493
|
if (session.state === "ready")
|
|
494
494
|
break;
|
|
495
495
|
if (session.state !== "provisioning")
|
|
496
|
-
return ended("
|
|
496
|
+
return ended("vendor", `the phone ${id} did not start: ${this.#clean(session.error ?? session.state)}`);
|
|
497
497
|
if (this.#now() - from >= this.#readyMs)
|
|
498
498
|
return ended("timeout", `the phone ${id} was not ready within ${this.#readyMs / 1000} s`);
|
|
499
499
|
await this.#sleep(this.#pollMs);
|
|
500
500
|
}
|
|
501
|
-
const deadline = this.#deadlineOf(session, from + spec
|
|
501
|
+
const deadline = this.#deadlineOf(session, from + runLifetimeMs(spec));
|
|
502
502
|
const kept = await record(() => this.#ledger.put({ id, labels: { ...(spec.labels ?? {}) }, image: spec.image, deadline }));
|
|
503
503
|
if (!kept.ok)
|
|
504
504
|
return kept;
|
|
505
505
|
const took = this.#now() - from;
|
|
506
506
|
if (this.#now() >= Date.parse(deadline)) {
|
|
507
|
-
return ended("timeout", `the phone ${id}'s lifetime of ${spec
|
|
507
|
+
return ended("timeout", `the phone ${id}'s lifetime of ${runLifetimeMs(spec) / 1000} s ended before it was ready (it took ${Math.round(took / 100) / 10} s)`);
|
|
508
508
|
}
|
|
509
509
|
return ok({ id, name: id });
|
|
510
510
|
}
|
|
@@ -554,7 +554,7 @@ export class PhoneHarnessProvider {
|
|
|
554
554
|
if (!got.ok)
|
|
555
555
|
return got;
|
|
556
556
|
if (!Array.isArray(got.value.json))
|
|
557
|
-
return
|
|
557
|
+
return vendorFail("phone-harness", `GET /sessions answered ${show(got.value.json).slice(0, 200)}, not a list`);
|
|
558
558
|
const live = new Map();
|
|
559
559
|
for (const one of got.value.json) {
|
|
560
560
|
const session = sessionOf(one, "GET /sessions");
|
|
@@ -632,6 +632,8 @@ export class PhoneHarnessProvider {
|
|
|
632
632
|
async #release(ref, how) {
|
|
633
633
|
if (how === "stop")
|
|
634
634
|
return fail("unsupported", "a cloud phone has no stop: release it with delete, which ends the session");
|
|
635
|
+
if (how !== "delete")
|
|
636
|
+
return fail("unsupported", `a cloud phone is kept for no agent (the phone harness declares no persistence), so release ${JSON.stringify(how)} is refused and the phone is left as it is: release it with delete`);
|
|
635
637
|
const entry = await this.#ledger.get(ref.id);
|
|
636
638
|
if (entry?.released !== undefined) {
|
|
637
639
|
// Released already, and the service may still be ending it: ok. Its own GET says whether it is gone, and then it is
|
|
@@ -674,7 +676,7 @@ export class PhoneHarnessProvider {
|
|
|
674
676
|
return ok(id);
|
|
675
677
|
last = state ?? "not listed";
|
|
676
678
|
}
|
|
677
|
-
return
|
|
679
|
+
return vendorFail("phone-harness", `adb connected to the phone, and the adb server still lists it as ${last}, not a device`);
|
|
678
680
|
}
|
|
679
681
|
async #connect(ref) {
|
|
680
682
|
const entry = await this.#ledger.get(ref.id);
|
|
@@ -698,7 +700,7 @@ export class PhoneHarnessProvider {
|
|
|
698
700
|
// The vendor's shapes (OpenAPI SessionAdb): a DNS name, a port, and a code ph_ and base32 letters. Anything outside
|
|
699
701
|
// these characters is refused rather than passed to adb.
|
|
700
702
|
if (typeof host !== "string" || !/^[A-Za-z0-9.:-]+$/.test(host) || !Number.isSafeInteger(port) || typeof code !== "string" || !/^[A-Za-z0-9_-]{1,128}$/.test(code)) {
|
|
701
|
-
return
|
|
703
|
+
return vendorFail("phone-harness", `the phone harness gave ${ref.id} no adb link this provider can use (a host, a port and an unlock code)`);
|
|
702
704
|
}
|
|
703
705
|
// The endpoint and the code never reach an argv: the endpoint goes to the adb server over its socket, the unlock as
|
|
704
706
|
// a shell service on a socket the server bound to the phone, and every spawned adb names the phone by its transport id.
|
|
@@ -743,7 +745,7 @@ export class PhoneHarnessProvider {
|
|
|
743
745
|
const said = connected.value.trim();
|
|
744
746
|
// adb's answer names the endpoint, so none of it is passed on: the error is the provider's own words.
|
|
745
747
|
if (!said.includes("connected") || /cannot|failed|unable/i.test(said)) {
|
|
746
|
-
return letGo(
|
|
748
|
+
return letGo(vendorFail("phone-harness", `adb could not reach the phone of ${ref.id}: the adb server could not connect to its adb endpoint`));
|
|
747
749
|
}
|
|
748
750
|
const transport = await this.#transportOf(endpoint);
|
|
749
751
|
if (!transport.ok)
|
|
@@ -757,7 +759,7 @@ export class PhoneHarnessProvider {
|
|
|
757
759
|
return letGo(asked);
|
|
758
760
|
if (!asked.value.includes("ph-ok")) {
|
|
759
761
|
if (!/^locked\b/.test(asked.value.trim()))
|
|
760
|
-
return letGo(
|
|
762
|
+
return letGo(vendorFail("phone-harness", `the phone of ${ref.id} answered neither ph-ok nor locked`));
|
|
761
763
|
// The vendor's unlock is the shell command `unlock <code>`, once per connection (docs, guides/connect-adb): the
|
|
762
764
|
// shell service's own string, sent over the adb server's socket bound to the phone, so no argv holds the code.
|
|
763
765
|
// Probe 1 (2026-11-08) showed it live: "unlocked", and getprop answered after it.
|
|
@@ -771,7 +773,7 @@ export class PhoneHarnessProvider {
|
|
|
771
773
|
if (!probe.value.stdout.toString("utf8").includes("ph-ok")) {
|
|
772
774
|
// The vendor's answer ("wrong code") may echo the code, more than once, or an endpoint: all are taken out.
|
|
773
775
|
const words = redactWords(unlocked.value.trim().split("\n")[0].replaceAll(code, "[code]"));
|
|
774
|
-
return letGo(
|
|
776
|
+
return letGo(vendorFail("phone-harness", /\bunlocked\b/.test(unlocked.value) ? `the phone of ${ref.id} stayed locked after its unlock code` : `the phone of ${ref.id} refused its unlock code: ${words}`));
|
|
775
777
|
}
|
|
776
778
|
}
|
|
777
779
|
const client = new AdbClient(id, adb, release, this.#sleep, this.#now);
|
|
@@ -793,7 +795,7 @@ const carries = (labels, wanted) => Object.entries(wanted ?? {}).every(([key, va
|
|
|
793
795
|
function sessionOf(json, where) {
|
|
794
796
|
const s = json;
|
|
795
797
|
if (typeof s !== "object" || s === null || typeof s.id !== "string" || typeof s.state !== "string")
|
|
796
|
-
return
|
|
798
|
+
return vendorFail("phone-harness", `${where} answered ${show(json).slice(0, 200)}, not a session`);
|
|
797
799
|
return ok(s);
|
|
798
800
|
}
|
|
799
801
|
// --- the client: the protocol over adb ---------------------------------------------------------------------------
|
|
@@ -880,12 +882,12 @@ class AdbClient {
|
|
|
880
882
|
const sizes = [...size.value.matchAll(/(\d+)x(\d+)/g)];
|
|
881
883
|
const last = sizes.at(-1);
|
|
882
884
|
if (!last)
|
|
883
|
-
return
|
|
885
|
+
return vendorFail("phone-harness", `the phone (adb transport ${this.transport}) did not say its screen's size: ${size.value.trim().slice(0, 100)}`);
|
|
884
886
|
this.#size = [Number(last[1]), Number(last[2])];
|
|
885
887
|
const dpi = [...density.value.matchAll(/(\d+)/g)].at(-1);
|
|
886
888
|
this.#scale = dpi ? Number(dpi[1]) / 160 : 1;
|
|
887
889
|
const reported = abi.value.trim();
|
|
888
|
-
this.#hello = { version, os: "android", kind: "android", arch: ARCH[reported] ?? reported, groups: [...PHONE_GROUPS] };
|
|
890
|
+
this.#hello = { protocol: PROTOCOL_VERSION, version, os: "android", kind: "android", arch: ARCH[reported] ?? reported, groups: [...PHONE_GROUPS] };
|
|
889
891
|
return ok(this.#hello);
|
|
890
892
|
}
|
|
891
893
|
close() {
|
|
@@ -913,7 +915,7 @@ class AdbClient {
|
|
|
913
915
|
return ran;
|
|
914
916
|
if (ran.value.exitCode !== 0) {
|
|
915
917
|
const why = (ran.value.stderr.trim() || ran.value.stdout.toString("utf8").trim()).split("\n")[0] || `exit code ${ran.value.exitCode}`;
|
|
916
|
-
return
|
|
918
|
+
return vendorFail("phone-harness", `${command.split(" ").slice(0, 2).join(" ")} on the phone failed: ${redactWords(why)}`);
|
|
917
919
|
}
|
|
918
920
|
return ok(ran.value.stdout.toString("utf8"));
|
|
919
921
|
}
|
|
@@ -922,7 +924,7 @@ class AdbClient {
|
|
|
922
924
|
if (!ran.ok)
|
|
923
925
|
return ran;
|
|
924
926
|
if (ran.value.exitCode !== 0)
|
|
925
|
-
return
|
|
927
|
+
return vendorFail("phone-harness", `${command.split(" ")[0]} on the phone failed: ${redactWords(ran.value.stderr.trim().split("\n")[0] || `exit code ${ran.value.exitCode}`)}`);
|
|
926
928
|
return ok(ran.value.stdout);
|
|
927
929
|
}
|
|
928
930
|
async call(method, params, options = {}) {
|
|
@@ -1277,7 +1279,7 @@ class AdbClient {
|
|
|
1277
1279
|
if (!started.ok)
|
|
1278
1280
|
return started;
|
|
1279
1281
|
if (/Error:|Exception/.test(started.value))
|
|
1280
|
-
return
|
|
1282
|
+
return vendorFail("phone-harness", `am start of ${component}: ${redactWords(started.value.trim().split("\n").at(-1) ?? "")}`);
|
|
1281
1283
|
return ok({});
|
|
1282
1284
|
}
|
|
1283
1285
|
async #terminate(id) {
|
|
@@ -1308,14 +1310,14 @@ function pointsOf(action) {
|
|
|
1308
1310
|
/** The frame `adb exec-out screencap` gives: a header (width, height, format, and a color space on newer Androids), then the pixels. */
|
|
1309
1311
|
export function decodeScreencap(raw) {
|
|
1310
1312
|
if (raw.length < 12)
|
|
1311
|
-
return
|
|
1313
|
+
return vendorFail("phone-harness", `screencap gave ${raw.length} bytes, not a frame`);
|
|
1312
1314
|
const width = raw.readUInt32LE(0);
|
|
1313
1315
|
const height = raw.readUInt32LE(4);
|
|
1314
1316
|
const format = raw.readUInt32LE(8);
|
|
1315
1317
|
const pixels = width * height * 4;
|
|
1316
1318
|
const header = raw.length - pixels;
|
|
1317
1319
|
if (!(width > 0 && height > 0 && (header === 12 || header === 16)))
|
|
1318
|
-
return
|
|
1320
|
+
return vendorFail("phone-harness", `screencap gave ${raw.length} bytes for a ${width}x${height} frame`);
|
|
1319
1321
|
const rgba = Buffer.from(raw.subarray(header));
|
|
1320
1322
|
// 1 is RGBA_8888, 2 RGBX_8888 (alpha unset), 5 BGRA_8888.
|
|
1321
1323
|
if (format === 2)
|
|
@@ -1413,7 +1415,7 @@ export function parseUiTree(xml, [width, height]) {
|
|
|
1413
1415
|
stack.push(node);
|
|
1414
1416
|
}
|
|
1415
1417
|
if (top.length === 0)
|
|
1416
|
-
return
|
|
1418
|
+
return vendorFail("phone-harness", "uiautomator's dump held no node");
|
|
1417
1419
|
if (top.length === 1)
|
|
1418
1420
|
return ok({ root: top[0], nodes, truncated });
|
|
1419
1421
|
return ok({ root: { role: "hierarchy", bounds: [0, 0, width, height], enabled: true, children: top }, nodes: nodes + 1, truncated });
|
package/dist/protocol.d.ts
CHANGED
|
@@ -38,11 +38,21 @@ export type Group = "exec" | "files" | "processes" | "screen" | "input.pointer"
|
|
|
38
38
|
export declare const GROUPS: readonly Group[];
|
|
39
39
|
/** The groups a provider answers itself, which a computerd hello never lists. */
|
|
40
40
|
export declare const PROVIDER_GROUPS: readonly Group[];
|
|
41
|
+
/**
|
|
42
|
+
* The version of this protocol: its methods, their params and results, the limits and the error kinds, as spec/computer
|
|
43
|
+
* publishes them. hello carries it, apart from the daemon's own version. It changes when the wire changes, not with
|
|
44
|
+
* each release: a minor step adds (a method, an optional field, a group), a major one changes or removes. computerd's
|
|
45
|
+
* Go constant (methods.ProtocolVersion) holds the same value, and a test keeps them equal.
|
|
46
|
+
*/
|
|
47
|
+
export declare const PROTOCOL_VERSION = "0.1";
|
|
41
48
|
export interface HelloParams {
|
|
42
49
|
/** Who is asking, for the daemon's log: a name and version. */
|
|
43
50
|
client: string;
|
|
44
51
|
}
|
|
45
52
|
export interface HelloResult {
|
|
53
|
+
/** The protocol version this computer speaks: PROTOCOL_VERSION. */
|
|
54
|
+
protocol: string;
|
|
55
|
+
/** The daemon's own version (with daemon none, the provider's). */
|
|
46
56
|
version: string;
|
|
47
57
|
os: ComputerOs;
|
|
48
58
|
kind: ComputerKind;
|
|
@@ -51,7 +61,17 @@ export interface HelloResult {
|
|
|
51
61
|
groups: Group[];
|
|
52
62
|
/** The DISPLAY a desktop's screen and input methods drive, such as ":99"; absent on any other computer. */
|
|
53
63
|
display?: string;
|
|
64
|
+
/** How init holds its programs off the computer's network, when it gave them one of their own (init --own-network). */
|
|
65
|
+
fence?: NetworkFence;
|
|
54
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* How init holds its programs off the computer's network: "netns", a network namespace init made itself as root;
|
|
69
|
+
* "userns-netns", one it made inside a user namespace of its own, where root may not make one (gVisor, whose root holds
|
|
70
|
+
* no CAP_SYS_ADMIN). Either way the programs reach their own loopback alone.
|
|
71
|
+
*/
|
|
72
|
+
export type NetworkFence = "netns" | "userns-netns";
|
|
73
|
+
/** Every NetworkFence, as hello may report it. */
|
|
74
|
+
export declare const NETWORK_FENCES: readonly NetworkFence[];
|
|
55
75
|
export type PingParams = Record<string, never>;
|
|
56
76
|
export type PingResult = Record<string, never>;
|
|
57
77
|
export interface ExecRunParams {
|
package/dist/protocol.js
CHANGED
|
@@ -26,6 +26,15 @@ export const MAX_READ_WAIT_MS = 30_000;
|
|
|
26
26
|
export const GROUPS = ["exec", "files", "processes", "screen", "input.pointer", "input.keys", "input.touch", "apps", "apps.install", "apps.ui_tree", "cdp", "stream", "downloads"];
|
|
27
27
|
/** The groups a provider answers itself, which a computerd hello never lists. */
|
|
28
28
|
export const PROVIDER_GROUPS = ["cdp", "stream", "downloads"];
|
|
29
|
+
/**
|
|
30
|
+
* The version of this protocol: its methods, their params and results, the limits and the error kinds, as spec/computer
|
|
31
|
+
* publishes them. hello carries it, apart from the daemon's own version. It changes when the wire changes, not with
|
|
32
|
+
* each release: a minor step adds (a method, an optional field, a group), a major one changes or removes. computerd's
|
|
33
|
+
* Go constant (methods.ProtocolVersion) holds the same value, and a test keeps them equal.
|
|
34
|
+
*/
|
|
35
|
+
export const PROTOCOL_VERSION = "0.1";
|
|
36
|
+
/** Every NetworkFence, as hello may report it. */
|
|
37
|
+
export const NETWORK_FENCES = ["netns", "userns-netns"];
|
|
29
38
|
/** The most actions one input.actions batch holds. */
|
|
30
39
|
export const MAX_ACTIONS = 100;
|
|
31
40
|
/**
|
package/dist/provider.d.ts
CHANGED
|
@@ -1,14 +1,37 @@
|
|
|
1
1
|
import type { MountKind, MountReadBack, MountSpec } from "./mount.js";
|
|
2
|
-
import type { ComputerClient, ComputerKind, ComputerOs, Group, HelloResult } from "./protocol.js";
|
|
2
|
+
import type { ComputerClient, ComputerKind, ComputerOs, Group, HelloResult, NetworkFence } from "./protocol.js";
|
|
3
3
|
import type { Result } from "./result.js";
|
|
4
4
|
import type { ScreenWatch, ScreenWatchHandlers, WatchOptions } from "./screen-watch.js";
|
|
5
5
|
export type NetworkSpec = "none" | "open" | {
|
|
6
6
|
allow: string[];
|
|
7
7
|
};
|
|
8
|
+
/** A network's form, as a provider declares the ones it makes (capabilities().network, its descriptor's network): "allow"
|
|
9
|
+
* is NetworkSpec's allowlist. */
|
|
10
|
+
export type NetworkForm = "none" | "open" | "allow";
|
|
11
|
+
/** The agent a persistent computer belongs to (spec.owner): it outlives the agent's runs, which take it one at a time. */
|
|
12
|
+
export interface ComputerOwner {
|
|
13
|
+
/** The agent's id: a non-empty string with no NUL byte (ownerProblem). */
|
|
14
|
+
agent: string;
|
|
15
|
+
/** How long the computer may stay detached before the janitor deletes it. Absent: it stays until it is deleted. */
|
|
16
|
+
idleTtlMs?: number;
|
|
17
|
+
}
|
|
18
|
+
/** The claim a run holds a computer under: the run, and the claim's epoch (labels.ts). */
|
|
19
|
+
export interface ComputerClaim {
|
|
20
|
+
run: string;
|
|
21
|
+
epoch: number;
|
|
22
|
+
}
|
|
8
23
|
export interface ComputerSpec {
|
|
9
24
|
image: string;
|
|
10
|
-
/**
|
|
11
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Required for a run's computer: one with no deadline is refused. An agent's computer (owner) has no run deadline and
|
|
27
|
+
* leaves it out (checkTenure).
|
|
28
|
+
*/
|
|
29
|
+
lifetimeMs?: number;
|
|
30
|
+
/**
|
|
31
|
+
* Makes the computer the agent's, persistent across its runs, on a provider that declares persistence; refused in
|
|
32
|
+
* words by any other. It carries the owner's labels (ownerLabels).
|
|
33
|
+
*/
|
|
34
|
+
owner?: ComputerOwner;
|
|
12
35
|
network: NetworkSpec;
|
|
13
36
|
cpus?: number;
|
|
14
37
|
memoryMb?: number;
|
|
@@ -22,6 +45,47 @@ export interface ComputerSpec {
|
|
|
22
45
|
* refuses any other kind before a vendor call. An Archil token is never in a label, a read-back or an error.
|
|
23
46
|
*/
|
|
24
47
|
mount?: MountSpec;
|
|
48
|
+
/**
|
|
49
|
+
* GPUs for the computer: a type the provider declares (capabilities().gpu.types, the vendor's own name, such as Modal's
|
|
50
|
+
* "A100-80GB" or Daytona's "H100") and how many, 1 up to capabilities().gpu.max. check() refuses one the provider does
|
|
51
|
+
* not declare in words before a vendor call; a provider that declares no gpu refuses any.
|
|
52
|
+
*/
|
|
53
|
+
gpu?: GpuSpec;
|
|
54
|
+
}
|
|
55
|
+
/** A computer's GPUs: one type, and how many of it. */
|
|
56
|
+
export interface GpuSpec {
|
|
57
|
+
type: string;
|
|
58
|
+
count: number;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The GPUs a provider offers: the types it takes, by the vendor's own names, and the most one computer may have; and
|
|
62
|
+
* how a GPU computer differs from the provider's others, each stated where the vendor makes it so.
|
|
63
|
+
*/
|
|
64
|
+
export interface GpuCapability {
|
|
65
|
+
types: string[];
|
|
66
|
+
max: number;
|
|
67
|
+
/** A GPU computer's isolation, where it is not capabilities().isolation (Modal's GPUs run on gVisor only). */
|
|
68
|
+
isolation?: ComputerCapabilities["isolation"];
|
|
69
|
+
/** The vendor may end a GPU computer to free capacity, at any time. */
|
|
70
|
+
preemptible?: boolean;
|
|
71
|
+
/** A GPU computer's stop deletes it: nothing of it is kept (Daytona: no pause, no snapshot). */
|
|
72
|
+
stopDeletes?: boolean;
|
|
73
|
+
/** The one region a GPU computer runs in, whatever the provider's own (Daytona's "earth"). */
|
|
74
|
+
region?: string;
|
|
75
|
+
/** The size a GPU computer gets for each GPU (the vendor's defaults). */
|
|
76
|
+
perGpu?: {
|
|
77
|
+
cpus: number;
|
|
78
|
+
memoryMb: number;
|
|
79
|
+
diskMb: number;
|
|
80
|
+
};
|
|
81
|
+
/** The mount kinds a GPU computer takes, where fewer than capabilities().mount: none yet proven on its GPU computers. */
|
|
82
|
+
mounts?: MountKind[];
|
|
83
|
+
/**
|
|
84
|
+
* How init holds a GPU computer's programs off its network, where it is not the plain network namespace: on Modal's
|
|
85
|
+
* gVisor, "userns-netns", one made inside a user namespace, as root there may not make one (measured). The fence holds
|
|
86
|
+
* either way; each computer's hello reads back the one it got.
|
|
87
|
+
*/
|
|
88
|
+
fence?: NetworkFence;
|
|
25
89
|
}
|
|
26
90
|
/** One kind of allowlist entry a provider takes: how many a list may hold, and the ports an entry opens. */
|
|
27
91
|
export interface AllowRule {
|
|
@@ -47,7 +111,8 @@ export interface ComputerCapabilities {
|
|
|
47
111
|
kind: ComputerKind;
|
|
48
112
|
/** Who ends a computer at its deadline: the vendor, or our janitor by label. */
|
|
49
113
|
lifetime: "vendor" | "janitor";
|
|
50
|
-
network:
|
|
114
|
+
/** The network forms it makes: of its descriptor's network (the forms all its configurations make), its own. */
|
|
115
|
+
network: NetworkForm[];
|
|
51
116
|
/** With network "allow": what an allowlist may hold and which ports it opens. */
|
|
52
117
|
allow?: AllowCapability;
|
|
53
118
|
/**
|
|
@@ -56,7 +121,11 @@ export interface ComputerCapabilities {
|
|
|
56
121
|
* once the live bypass cases pass (ruling 9).
|
|
57
122
|
*/
|
|
58
123
|
networkReadBack?: boolean;
|
|
59
|
-
|
|
124
|
+
/**
|
|
125
|
+
* What keeps the computer's programs apart from everything else. host: they are processes of the machine the
|
|
126
|
+
* provider runs on, as its user (the local browser's Chrome, held only by Chrome's own sandbox and its egress proxy).
|
|
127
|
+
*/
|
|
128
|
+
isolation: "container" | "gvisor" | "microvm" | "vm" | "machine" | "host";
|
|
60
129
|
os: ComputerOs;
|
|
61
130
|
/**
|
|
62
131
|
* With release "stop": true when a stop ends in deletion (Daytona with autoDeleteMinutes 0), so release(ref, "stop")
|
|
@@ -77,6 +146,16 @@ export interface ComputerCapabilities {
|
|
|
77
146
|
release: Array<"stop" | "delete">;
|
|
78
147
|
/** The kinds of spec.mount this provider takes: bind (a host folder), archil (a folder of an Archil disk). Absent: none. */
|
|
79
148
|
mount?: MountKind[];
|
|
149
|
+
/**
|
|
150
|
+
* Present when the provider keeps computers for agents (spec.owner): release(ref, "detach") stops one with its state
|
|
151
|
+
* kept, and attach with a claim brings it back. keepsState: its files survive a detach. resume: true when it comes
|
|
152
|
+
* back as it was, its processes running; false when it boots again from its kept disk. Absent: spec.owner and detach
|
|
153
|
+
* are refused in words.
|
|
154
|
+
*/
|
|
155
|
+
persistence?: {
|
|
156
|
+
keepsState: true;
|
|
157
|
+
resume: boolean;
|
|
158
|
+
};
|
|
80
159
|
/**
|
|
81
160
|
* The TCP ports the vendor's own agent listens on inside the computer (Daytona's toolbox 2280, E2B's envd 49983), each
|
|
82
161
|
* the provider's own fact: an agent that runs commands as root or with sudo for whoever reaches it. The computer's
|
|
@@ -85,6 +164,8 @@ export interface ComputerCapabilities {
|
|
|
85
164
|
* Absent: no vendor's agent runs beside the programs (Docker). A child daemon must declare it.
|
|
86
165
|
*/
|
|
87
166
|
vendorAgentPorts?: number[];
|
|
167
|
+
/** The GPUs spec.gpu may ask for. Absent: none, and check() refuses any spec.gpu. */
|
|
168
|
+
gpu?: GpuCapability;
|
|
88
169
|
}
|
|
89
170
|
/** The os and daemon modes each kind may have; no other pair is valid. */
|
|
90
171
|
export declare const KIND_SHAPES: Readonly<Record<ComputerKind, {
|
|
@@ -98,6 +179,29 @@ export declare function kindRefusals({ kind, os, daemon }: Pick<ComputerCapabili
|
|
|
98
179
|
* milliseconds above 0, and at most capabilities().maxLifetimeMs.
|
|
99
180
|
*/
|
|
100
181
|
export declare function checkLifetime(lifetimeMs: unknown, { lifetime, maxLifetimeMs }: Pick<ComputerCapabilities, "lifetime" | "maxLifetimeMs">): Refusal[];
|
|
182
|
+
/**
|
|
183
|
+
* A run's computer's lifetime, in a provider's create once check() passed the spec: its lifetimeMs, which
|
|
184
|
+
* checkLifetime requires of every spec with no owner. A spec without one is a caller's mistake past check(): a throw.
|
|
185
|
+
*/
|
|
186
|
+
export declare function runLifetimeMs(spec: Pick<ComputerSpec, "lifetimeMs">): number;
|
|
187
|
+
/** Why owner is not an agent's ownership, in words, or undefined when it is one. */
|
|
188
|
+
export declare function ownerProblem(owner: unknown): string | undefined;
|
|
189
|
+
/**
|
|
190
|
+
* The lifetime rule every provider's check() shares, with no vendor call. A run's computer (no owner) takes
|
|
191
|
+
* checkLifetime. An agent's computer (owner) needs a provider that declares persistence, an owner that is one
|
|
192
|
+
* (ownerProblem), and no lifetimeMs: it has no run deadline.
|
|
193
|
+
*/
|
|
194
|
+
export declare function checkTenure({ lifetimeMs, owner }: {
|
|
195
|
+
lifetimeMs?: unknown;
|
|
196
|
+
owner?: unknown;
|
|
197
|
+
}, capabilities: Pick<ComputerCapabilities, "lifetime" | "maxLifetimeMs" | "persistence">, provider?: string): Refusal[];
|
|
198
|
+
/**
|
|
199
|
+
* The one GPU rule every provider's check() shares, with no vendor call: no spec.gpu is no refusal; one given is an
|
|
200
|
+
* object of a declared type (capabilities().gpu.types) and a whole count from 1 to capabilities().gpu.max; a provider
|
|
201
|
+
* that declares no gpu refuses any. With `mount`, the spec's as given, a GPU computer takes only the kinds gpu.mounts
|
|
202
|
+
* names, where it names them. Serve's claim and readiness read the same rule, so a refusal reads alike wherever it is met.
|
|
203
|
+
*/
|
|
204
|
+
export declare function checkGpu(gpu: unknown, { gpu: offered }: Pick<ComputerCapabilities, "gpu">, mount?: unknown): Refusal[];
|
|
101
205
|
/** Why a spec is refused, in words, before any vendor call. */
|
|
102
206
|
export interface Refusal {
|
|
103
207
|
field: string;
|
|
@@ -130,6 +234,10 @@ export interface ReadBackSpec {
|
|
|
130
234
|
kind?: ComputerKind;
|
|
131
235
|
/** What is mounted at /workspace, never a token; absent when nothing is. */
|
|
132
236
|
mount?: MountReadBack;
|
|
237
|
+
/** An agent's computer: its owner, read back; absent for a run's computer. */
|
|
238
|
+
owner?: ComputerOwner;
|
|
239
|
+
/** The GPUs the computer was given, as the vendor reports them (Daytona) or as create recorded them (Modal); absent: none. */
|
|
240
|
+
gpu?: GpuSpec;
|
|
133
241
|
}
|
|
134
242
|
/**
|
|
135
243
|
* What a read-back recorded that does not refuse the computer, in words, one line each: under network none, the probe
|
|
@@ -151,16 +259,34 @@ export interface AttachedComputer extends ComputerRef {
|
|
|
151
259
|
export interface ComputerInfo {
|
|
152
260
|
ref: ComputerRef;
|
|
153
261
|
labels: Record<string, string>;
|
|
154
|
-
/** undefined when the deadline label is missing or unreadable: the janitor deletes such a computer. */
|
|
262
|
+
/** undefined when the deadline label is missing or unreadable: the janitor deletes such a run's computer. An agent's has none. */
|
|
155
263
|
deadline: Date | undefined;
|
|
156
264
|
state: "running" | "stopped";
|
|
157
265
|
network: NetworkPolicy;
|
|
158
266
|
/** What is mounted at /workspace, read back, never a token; absent when nothing is. */
|
|
159
267
|
mount?: MountReadBack;
|
|
268
|
+
/**
|
|
269
|
+
* An agent's computer (spec.owner), as the provider knows it, owner label or not: true. The janitor never deletes one
|
|
270
|
+
* by a deadline. A provider whose listing carries the owner label need not set it.
|
|
271
|
+
*/
|
|
272
|
+
owned?: boolean;
|
|
273
|
+
/** An owned computer's owner, when the listing knows it (its labels, or the provider's own record). */
|
|
274
|
+
owner?: ComputerOwner;
|
|
275
|
+
/** An agent's computer that is detached now: when it was detached, the janitor's idle clock. Absent otherwise. */
|
|
276
|
+
detachedAt?: Date;
|
|
160
277
|
}
|
|
161
278
|
export interface CallContext {
|
|
162
279
|
signal?: AbortSignal;
|
|
163
280
|
}
|
|
281
|
+
/** attach's context: with a claim, an agent's computer is brought back and taken by that run, under that epoch. */
|
|
282
|
+
export interface AttachContext extends CallContext {
|
|
283
|
+
claim?: ComputerClaim;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* How release ends or lets go of a computer. stop: stopped and kept, until deleted. delete: gone. detach: an agent's
|
|
287
|
+
* computer stops with its state kept, still the agent's (a provider that declares persistence; refused otherwise).
|
|
288
|
+
*/
|
|
289
|
+
export type ReleaseHow = "stop" | "delete" | "detach";
|
|
164
290
|
/** A live connection to a computer's daemon. */
|
|
165
291
|
export interface ComputerConnection {
|
|
166
292
|
client: ComputerClient;
|
|
@@ -184,21 +310,27 @@ export interface ComputerProvider {
|
|
|
184
310
|
}): Promise<Result<CreatedComputer>>;
|
|
185
311
|
/**
|
|
186
312
|
* Finds one computer this provider made, by its id or by labels, with the spec read back from it; none or several is
|
|
187
|
-
* an error in words.
|
|
313
|
+
* an error in words. With context.claim (a provider that declares persistence): the agent's computer is brought back
|
|
314
|
+
* (started, when detached) and taken under the claim, so it carries the claim's run and epoch labels. A claim of the
|
|
315
|
+
* same run below the epoch the computer carries is refused as fenced, and a claim on a run's computer (no owner) is
|
|
316
|
+
* refused; neither changes anything.
|
|
188
317
|
*/
|
|
189
318
|
attach(ref: {
|
|
190
319
|
id: string;
|
|
191
320
|
} | {
|
|
192
321
|
labels: Record<string, string>;
|
|
193
|
-
}, context?:
|
|
322
|
+
}, context?: AttachContext): Promise<Result<AttachedComputer>>;
|
|
194
323
|
/** Every computer this provider made that carries all of these labels: the janitor's view. */
|
|
195
324
|
list(labels: Record<string, string>, context?: CallContext): Promise<Result<ComputerInfo[]>>;
|
|
196
325
|
/** Reads the network back; with a policy, sets it, or refuses in words when it cannot. Never wider than asked. */
|
|
197
326
|
network(ref: ComputerRef, policy?: NetworkSpec, context?: CallContext): Promise<Result<NetworkPolicy>>;
|
|
198
327
|
/** Checks hello against this provider's version, kind and groups, and refuses on a mismatch. */
|
|
199
328
|
connect(ref: ComputerRef): Promise<Result<ComputerConnection>>;
|
|
200
|
-
/**
|
|
201
|
-
|
|
329
|
+
/**
|
|
330
|
+
* Idempotent: a computer already gone is ok. A "stop" capabilities().release does not declare is refused in words. A
|
|
331
|
+
* "detach" is refused in words, the computer as it was, on a provider with no persistence and on a run's computer.
|
|
332
|
+
*/
|
|
333
|
+
release(ref: ComputerRef, how: ReleaseHow): Promise<Result<void>>;
|
|
202
334
|
/**
|
|
203
335
|
* Sets the deadline to now + ttlMs: never earlier than the current deadline, never past created + maxLifetimeMs. A
|
|
204
336
|
* ttlMs that would move it earlier, or past that cap, is refused in words with the deadline unchanged: an extend
|
|
@@ -242,4 +374,13 @@ export interface ComputerProvider {
|
|
|
242
374
|
testConnection?(context?: CallContext): Promise<Result<{
|
|
243
375
|
detail: string;
|
|
244
376
|
}>>;
|
|
377
|
+
/**
|
|
378
|
+
* The image its computers start from, made ready on its engine before the first create: built from its recipe, or
|
|
379
|
+
* pulled by name, when the engine lacks it; ok with the tag to put in spec.image. `onWait` is told once, before a build
|
|
380
|
+
* or a pull it waits on, never when the image is there. A provider whose descriptor declares prepareImage has it;
|
|
381
|
+
* optional for every other.
|
|
382
|
+
*/
|
|
383
|
+
prepareImage?(context?: CallContext & {
|
|
384
|
+
onWait?: (making: "build" | "pull", tag: string) => void;
|
|
385
|
+
}): Promise<Result<string>>;
|
|
245
386
|
}
|