@parcha/agentrun-computer 0.1.0-beta.41 → 0.1.0-beta.43
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/NOTICE +2 -0
- package/README.md +254 -14
- package/box/README.md +2 -2
- package/box/build-e2b.mjs +1 -1
- package/dist/box-image.d.ts +1 -3
- package/dist/box-image.js +1 -11
- package/dist/boxd.d.ts +126 -0
- package/dist/boxd.js +418 -0
- package/dist/cloudflare.d.ts +32 -0
- package/dist/cloudflare.js +181 -0
- package/dist/computerd-linux-amd64 +0 -0
- package/dist/computerd-linux-arm64 +0 -0
- package/dist/computerd.json +2 -2
- package/dist/conformance/boxd.d.ts +77 -0
- package/dist/conformance/boxd.js +113 -0
- package/dist/conformance/cases/isolation.js +1 -17
- package/dist/conformance/cloudflare.d.ts +42 -0
- package/dist/conformance/cloudflare.js +54 -0
- package/dist/conformance/dial-only.d.ts +6 -0
- package/dist/conformance/dial-only.js +9 -0
- package/dist/conformance/e2b.d.ts +12 -3
- package/dist/conformance/e2b.js +21 -4
- package/dist/conformance/fly.d.ts +52 -0
- package/dist/conformance/fly.js +52 -0
- package/dist/conformance/modal.d.ts +15 -2
- package/dist/conformance/modal.js +36 -3
- package/dist/conformance/morph.d.ts +59 -0
- package/dist/conformance/morph.js +95 -0
- package/dist/conformance/phone-harness.js +2 -2
- package/dist/conformance/runner.js +3 -3
- package/dist/conformance/sweep.d.ts +1 -6
- package/dist/conformance/sweep.js +8 -18
- package/dist/descriptors/boxd.d.ts +52 -0
- package/dist/descriptors/boxd.js +29 -0
- package/dist/descriptors/cloudflare.d.ts +21 -0
- package/dist/descriptors/cloudflare.js +29 -0
- package/dist/descriptors/e2b.d.ts +4 -0
- package/dist/descriptors/e2b.js +3 -0
- package/dist/descriptors/fly.d.ts +19 -0
- package/dist/descriptors/fly.js +28 -0
- package/dist/descriptors/index.d.ts +113 -1
- package/dist/descriptors/index.js +7 -2
- package/dist/descriptors/modal.d.ts +3 -0
- package/dist/descriptors/modal.js +7 -2
- package/dist/descriptors/morph.d.ts +15 -0
- package/dist/descriptors/morph.js +21 -0
- package/dist/descriptors/phone-harness.d.ts +1 -0
- package/dist/descriptors/phone-harness.js +2 -0
- package/dist/e2b.d.ts +7 -1
- package/dist/e2b.js +87 -44
- package/dist/fly.d.ts +43 -0
- package/dist/fly.js +245 -0
- package/dist/host.d.ts +8 -28
- package/dist/hosted/process.d.ts +19 -0
- package/dist/hosted/process.js +28 -0
- package/dist/hosted/provider.d.ts +11 -22
- package/dist/hosted/provider.js +30 -201
- package/dist/hosted/scripts.d.ts +2 -8
- package/dist/hosted/scripts.js +2 -22
- package/dist/hosted/ssh-exec.d.ts +2 -1
- package/dist/hosted/ssh-exec.js +58 -2
- package/dist/hosted/values.d.ts +5 -0
- package/dist/hosted/values.js +9 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/modal.d.ts +6 -0
- package/dist/modal.js +20 -10
- package/dist/morph.d.ts +65 -0
- package/dist/morph.js +495 -0
- package/dist/phone-harness.d.ts +15 -5
- package/dist/phone-harness.js +50 -15
- package/dist/screen-watch.js +2 -2
- package/package.json +20 -2
package/dist/phone-harness.js
CHANGED
|
@@ -13,7 +13,7 @@ import { createHash, randomBytes } from "node:crypto";
|
|
|
13
13
|
import { readFileSync } from "node:fs";
|
|
14
14
|
import { readFile } from "node:fs/promises";
|
|
15
15
|
import { createConnection } from "node:net";
|
|
16
|
-
import { basename } from "node:path";
|
|
16
|
+
import { basename, isAbsolute } from "node:path";
|
|
17
17
|
import { fileURLToPath } from "node:url";
|
|
18
18
|
import { DaemonClient } from "./client.js";
|
|
19
19
|
import { CreateRequests, endedWords, labelsDiffer, otherSpecWords } from "./create-requests.js";
|
|
@@ -31,6 +31,12 @@ export const PHONE_HARNESS_URL = "https://api.phone-harness.com";
|
|
|
31
31
|
export const DEFAULT_MAX_LIFETIME_MS = 30 * 60_000;
|
|
32
32
|
/** How long create waits for a phone to be ready by default: the service's own CLI waits 240 s. */
|
|
33
33
|
export const DEFAULT_READY_MS = 240_000;
|
|
34
|
+
/**
|
|
35
|
+
* The live view's frame width when its caller asks none: phoned's own default (1280) is wider than a phone, so each
|
|
36
|
+
* frame went at the screen's full size, about 2.2 times the pixels of a 1080-wide phone's at this width, over a link
|
|
37
|
+
* to a cloud phone. The viewer fits the whole phone in its Screen tab, so 720 × 1600 still fills it.
|
|
38
|
+
*/
|
|
39
|
+
const PHONE_FRAME_WIDTH = 720;
|
|
34
40
|
/** How long one API request may take by default: a stalled request is cut off, and create's own calls stay bounded. */
|
|
35
41
|
const DEFAULT_REQUEST_MS = 30_000;
|
|
36
42
|
/** How long one adb call may take. */
|
|
@@ -293,6 +299,18 @@ export function adbAnswer(raw, what) {
|
|
|
293
299
|
return vendorFail("phone-harness", `the adb server refused ${what}: ${redactWords(message.trim())}`);
|
|
294
300
|
return vendorFail("phone-harness", `the adb server answered ${what} with ${JSON.stringify(raw.subarray(0, 40).toString("latin1"))}, not OKAY or FAIL`);
|
|
295
301
|
}
|
|
302
|
+
const SHA256 = /^[0-9a-f]{64}$/;
|
|
303
|
+
const pinned = (apk) => typeof apk === "object" && apk !== null && typeof apk.path === "string" && isAbsolute(apk.path) && typeof apk.sha256 === "string" && SHA256.test(apk.sha256);
|
|
304
|
+
/** PHONE_HARNESS_APKS as the apks option: a comma list of <absolute path>@sha256:<hex>; unset or blank, none. */
|
|
305
|
+
function apksOf(value) {
|
|
306
|
+
return (value ?? "").split(",").map((one) => one.trim()).filter((one) => one !== "").map((one) => {
|
|
307
|
+
const at = one.lastIndexOf("@sha256:");
|
|
308
|
+
const apk = { path: one.slice(0, Math.max(at, 0)), sha256: one.slice(at + "@sha256:".length) };
|
|
309
|
+
if (at < 0 || !pinned(apk))
|
|
310
|
+
throw new Error(`PHONE_HARNESS_APKS is a comma list of <absolute path>@sha256:<64 hex digits>, the APKs every phone installs: ${show(one)} is not one`);
|
|
311
|
+
return apk;
|
|
312
|
+
});
|
|
313
|
+
}
|
|
296
314
|
/** The phone-harness provider from its options alone; throws in words when one is missing or wrong. */
|
|
297
315
|
export async function create(options) {
|
|
298
316
|
return new PhoneHarnessProvider(options);
|
|
@@ -365,10 +383,10 @@ export class PhoneHarnessProvider {
|
|
|
365
383
|
throw new Error("options.adb is the adb CLI's path, or a transport with run(), server() and open()");
|
|
366
384
|
}
|
|
367
385
|
this.#phonedPath = options.phoned ?? DEFAULT_PHONED_PATH;
|
|
368
|
-
const apks = options.apks ??
|
|
369
|
-
if (!Array.isArray(apks) || !apks.every(
|
|
370
|
-
throw new Error(`options.apks ${show(options.apks)} is not a list of APK
|
|
371
|
-
this.#apks =
|
|
386
|
+
const apks = options.apks ?? apksOf(options.env?.PHONE_HARNESS_APKS);
|
|
387
|
+
if (!Array.isArray(apks) || !apks.every(pinned))
|
|
388
|
+
throw new Error(`options.apks ${show(options.apks)} is not a list of { path, sha256 }: an APK file's absolute path and its sha256, 64 lowercase hex digits`);
|
|
389
|
+
this.#apks = apks.map(({ path, sha256 }) => ({ path, sha256 }));
|
|
372
390
|
this.#adb = adb === undefined || typeof adb === "string" ? adbCli(adb ?? "adb") : adb;
|
|
373
391
|
this.#ledger = guardedLedger(options.ledger ?? memoryLedger());
|
|
374
392
|
this.#maxLifetimeMs = options.maxLifetimeMs ?? DEFAULT_MAX_LIFETIME_MS;
|
|
@@ -622,16 +640,23 @@ export class PhoneHarnessProvider {
|
|
|
622
640
|
return ledgerSafe(() => this.#connect(ref));
|
|
623
641
|
}
|
|
624
642
|
/**
|
|
625
|
-
* The live view:
|
|
626
|
-
*
|
|
627
|
-
*
|
|
643
|
+
* The live view: phoned's screen.watch on a connection of the watch's own (daemonWatch), JPEG frames at most
|
|
644
|
+
* PHONE_FRAME_WIDTH wide unless the caller asks a width, from the phone's screenshot. Upright with no rotation of
|
|
645
|
+
* ours: the screenshot gives the display in its current orientation, and input taps and swipes take that same space,
|
|
646
|
+
* so each frame's width and height come from its own screenshot, never from wm size.
|
|
628
647
|
*/
|
|
629
648
|
watch(ref, handlers, options) {
|
|
630
|
-
return daemonWatch(this, ref, handlers, options);
|
|
649
|
+
return daemonWatch(this, ref, handlers, { ...options, maxWidth: options?.maxWidth ?? PHONE_FRAME_WIDTH });
|
|
631
650
|
}
|
|
632
651
|
async #create(spec, name, requestKey, signal) {
|
|
633
652
|
if (signal?.aborted)
|
|
634
653
|
return fail("aborted", "create was aborted before the phone harness was asked");
|
|
654
|
+
// An APK not there, or not its pin, would fail the connect of a phone billed by the minute: none is rented for it.
|
|
655
|
+
for (const pin of this.#apks) {
|
|
656
|
+
const apk = await this.#apk(pin);
|
|
657
|
+
if (!apk.ok)
|
|
658
|
+
return fail(apk.error.code, `${apk.error.message}: no phone was rented`);
|
|
659
|
+
}
|
|
635
660
|
const looked = this.#now();
|
|
636
661
|
const body = { platform: "android", kind: "emulator", timeout_seconds: Math.ceil(runLifetimeMs(spec) / 1000) };
|
|
637
662
|
// The key goes into the ledger before the POST: whatever answers are lost, list() can find the phone by it. It is
|
|
@@ -1088,15 +1113,25 @@ export class PhoneHarnessProvider {
|
|
|
1088
1113
|
return vendorFail("phone-harness", `${what} could not be put in place on the phone: ${redactWords(moved.value.trim().split("\n")[0] ?? "")}`);
|
|
1089
1114
|
return ok(undefined);
|
|
1090
1115
|
}
|
|
1116
|
+
/** An APK of the apks option, read once it matches, held to its pin: not_found when it is not there, refused when its
|
|
1117
|
+
* bytes' sha256 is not the pinned one, and then read again next time, so the right file put there since is taken. */
|
|
1118
|
+
async #apk({ path, sha256 }) {
|
|
1119
|
+
const what = `the APK ${basename(path)}`;
|
|
1120
|
+
const file = await this.#fileAt(path, (why) => `${what} is not at ${path} (${why})`);
|
|
1121
|
+
if (!file.ok || file.value.sha256 === sha256)
|
|
1122
|
+
return file;
|
|
1123
|
+
this.#files.delete(path);
|
|
1124
|
+
return fail("refused", `${what} at ${path} is not the one pinned: its sha256 is ${file.value.sha256}, not ${sha256}`);
|
|
1125
|
+
}
|
|
1091
1126
|
/**
|
|
1092
|
-
* The apks option's APKs, each put on the phone like phoned's jar and installed there with
|
|
1093
|
-
* phone: a marker beside it on the phone (<apk>.installed) says that phone installed those
|
|
1094
|
-
* which starts phoned afresh, installs nothing again.
|
|
1127
|
+
* The apks option's APKs, each held to its pin, put on the phone like phoned's jar and installed there with
|
|
1128
|
+
* `pm install -r`, once per phone: a marker beside it on the phone (<apk>.installed) says that phone installed those
|
|
1129
|
+
* bytes, so a later connect, which starts phoned afresh, installs nothing again.
|
|
1095
1130
|
*/
|
|
1096
1131
|
async #install(transport, adb, onPhone) {
|
|
1097
|
-
for (const
|
|
1098
|
-
const what = `the APK ${basename(path)}`;
|
|
1099
|
-
const apk = await this.#
|
|
1132
|
+
for (const pin of this.#apks) {
|
|
1133
|
+
const what = `the APK ${basename(pin.path)}`;
|
|
1134
|
+
const apk = await this.#apk(pin);
|
|
1100
1135
|
if (!apk.ok)
|
|
1101
1136
|
return apk;
|
|
1102
1137
|
const remote = `${PHONE_TMP}/apk-${apk.value.sha256.slice(0, 16)}.apk`;
|
package/dist/screen-watch.js
CHANGED
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
// once, by daemonWatch, as an adapter over watchScreen: each frame goes to handlers.frame(frame, ack), and the next is
|
|
14
14
|
// given only once ack() is called; a computer that goes ends it once with handlers.ended(error), its code gone,
|
|
15
15
|
// unreachable, refused or unsupported; close() and the signal end it with no ended(). Every computerd provider and the
|
|
16
|
-
// phone answer watch() through daemonWatch, on a connection of the watch's own: computerd
|
|
17
|
-
//
|
|
16
|
+
// phone answer watch() through daemonWatch, on a connection of the watch's own: computerd and phoned both give JPEG
|
|
17
|
+
// frames. No error in either layer holds a URL or a secret.
|
|
18
18
|
// The most characters one typed text holds, on every kind: computerd's MaxTypeRunes, which checkActions enforces too.
|
|
19
19
|
import { MAX_TYPE_CHARACTERS } from "./actions.js";
|
|
20
20
|
import { fail, ok } from "./result.js";
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcha/agentrun-computer",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.43",
|
|
4
4
|
"description": "The open platform's computer protocol: a daemon in every computer, and one provisioner per vendor, starting with Docker.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agentrun",
|
|
7
7
|
"computer",
|
|
8
8
|
"sandbox",
|
|
9
9
|
"docker",
|
|
10
|
-
"daytona"
|
|
10
|
+
"daytona",
|
|
11
|
+
"boxd"
|
|
11
12
|
],
|
|
12
13
|
"type": "module",
|
|
13
14
|
"license": "Apache-2.0",
|
|
@@ -50,6 +51,22 @@
|
|
|
50
51
|
"types": "./dist/agent37.d.ts",
|
|
51
52
|
"default": "./dist/agent37.js"
|
|
52
53
|
},
|
|
54
|
+
"./fly": {
|
|
55
|
+
"types": "./dist/fly.d.ts",
|
|
56
|
+
"default": "./dist/fly.js"
|
|
57
|
+
},
|
|
58
|
+
"./cloudflare": {
|
|
59
|
+
"types": "./dist/cloudflare.d.ts",
|
|
60
|
+
"default": "./dist/cloudflare.js"
|
|
61
|
+
},
|
|
62
|
+
"./morph": {
|
|
63
|
+
"types": "./dist/morph.d.ts",
|
|
64
|
+
"default": "./dist/morph.js"
|
|
65
|
+
},
|
|
66
|
+
"./boxd": {
|
|
67
|
+
"types": "./dist/boxd.d.ts",
|
|
68
|
+
"default": "./dist/boxd.js"
|
|
69
|
+
},
|
|
53
70
|
"./orgo": {
|
|
54
71
|
"types": "./dist/orgo.d.ts",
|
|
55
72
|
"default": "./dist/orgo.js"
|
|
@@ -101,6 +118,7 @@
|
|
|
101
118
|
"test:daytona": "node --test --test-timeout=1800000 test/daytona/*.test.mjs",
|
|
102
119
|
"test:modal": "node --test --test-timeout=1800000 test/modal/*.test.mjs",
|
|
103
120
|
"test:e2b": "node --test --test-timeout=1800000 test/e2b/*.test.mjs",
|
|
121
|
+
"test:boxd": "node --test --test-timeout=1800000 test/boxd/*.test.mjs",
|
|
104
122
|
"conformance": "node dist/conformance/cli.js"
|
|
105
123
|
},
|
|
106
124
|
"repository": {
|