@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/daytona.js
CHANGED
|
@@ -7,27 +7,37 @@ import { readFileSync } from "node:fs";
|
|
|
7
7
|
import { resolve } from "node:path";
|
|
8
8
|
import { PassThrough, Writable } from "node:stream";
|
|
9
9
|
import { fileURLToPath } from "node:url";
|
|
10
|
-
import { childCommands, daemonDrift, shellCommand } from "./child.js";
|
|
10
|
+
import { childCommands, daemonDrift, installerOf, shellCommand } from "./child.js";
|
|
11
11
|
import { OWN_NETWORK_ONLY, readOwnNetwork, TOOL_USER } from "./isolation.js";
|
|
12
12
|
import { DaemonClient } from "./client.js";
|
|
13
|
+
import { DAYTONA, DAYTONA_DEFAULT_SNAPSHOT, DAYTONA_GPU, DAYTONA_GPU_REGION, DAYTONA_GPU_SNAPSHOT, DAYTONA_GPU_SNAPSHOT_GPU } from "./descriptors/daytona.js";
|
|
13
14
|
import { COMPUTER_LABEL, DEADLINE_LABEL, helloDrift, WORK } from "./drift.js";
|
|
14
15
|
import { releaseOlder } from "./janitor.js";
|
|
15
16
|
import { epochOf, RUN_LABEL } from "./labels.js";
|
|
16
17
|
import { checkMount, readBackOf } from "./mount.js";
|
|
17
18
|
import { ARCHIL_MOUNT_LABEL, ARCHIL_TOOL_UID, archilLabels, archilMount, archilRefusals, archilRelease, mountDrift, readArchilMount, recordedMount, syncingClient, } from "./mount-archil.js";
|
|
18
19
|
import { MAX_LINE_BYTES } from "./protocol.js";
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
20
|
+
import { checkGpu, checkTenure, runLifetimeMs, } from "./provider.js";
|
|
21
|
+
import { errorOf, failFor, ok, vendorFail } from "./result.js";
|
|
21
22
|
import { daemonWatch } from "./screen-watch.js";
|
|
22
23
|
import { countTested } from "./test-connection.js";
|
|
23
24
|
import { waitUntil } from "./wait.js";
|
|
25
|
+
/** This module's failures: one with code vendor names Daytona. */
|
|
26
|
+
const fail = failFor("daytona");
|
|
24
27
|
/**
|
|
25
28
|
* The mount kinds a Daytona computer takes: an Archil mount of the run's folder (mount-archil.ts), made as root through
|
|
26
29
|
* the toolbox, from a snapshot of box/Dockerfile, with the daemon user agentrun-tool (daemonUser "2510:2510").
|
|
27
30
|
*/
|
|
28
|
-
export const MOUNT =
|
|
29
|
-
/**
|
|
30
|
-
|
|
31
|
+
export const MOUNT = DAYTONA.mounts;
|
|
32
|
+
/** A copy of its descriptor's DAYTONA_GPU, so no caller can change the provider's own. */
|
|
33
|
+
const daytonaGpuCapability = () => ({
|
|
34
|
+
...DAYTONA_GPU,
|
|
35
|
+
types: [...DAYTONA_GPU.types],
|
|
36
|
+
perGpu: { ...DAYTONA_GPU.perGpu },
|
|
37
|
+
mounts: [],
|
|
38
|
+
});
|
|
39
|
+
/** The machine kind, groups and GPUs of its one configuration (its descriptor's): a linux computer, with GPUs when asked. */
|
|
40
|
+
export const CAPABILITIES = DAYTONA.capabilities;
|
|
31
41
|
/**
|
|
32
42
|
* A DaytonaProvider from its options alone; it reads no environment, so the key, the API URL (default Daytona's own) and
|
|
33
43
|
* the target are the caller's: serve passes its DAYTONA_API_KEY, DAYTONA_API_URL and DAYTONA_TARGET, the conformance
|
|
@@ -47,8 +57,6 @@ export function create(options) {
|
|
|
47
57
|
export const conformance = () => import("./conformance/daytona.js");
|
|
48
58
|
const VERSION = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
|
|
49
59
|
const DEFAULT_API_URL = "https://app.daytona.io/api";
|
|
50
|
-
/** The image that asks for Daytona's default snapshot: the create sends no snapshot field. */
|
|
51
|
-
export const DAYTONA_DEFAULT_SNAPSHOT = "default";
|
|
52
60
|
/** The label, in the provider's own namespace beside the deadline's, that holds the image create was asked for: Daytona
|
|
53
61
|
* reports only the snapshot it resolved that image to, a name of its own for "default". */
|
|
54
62
|
const IMAGE_LABEL = `${COMPUTER_LABEL}.image`;
|
|
@@ -88,7 +96,7 @@ const MAX_CIDRS = 10;
|
|
|
88
96
|
const TOOLBOX_PORT = 2280;
|
|
89
97
|
const INIT_SESSION = "agentrun-computerd";
|
|
90
98
|
const STAGING = "/tmp/agentrun-computerd-";
|
|
91
|
-
const SPEC_FIELDS = new Set(["image", "lifetimeMs", "network", "labels", "mount"]);
|
|
99
|
+
const SPEC_FIELDS = new Set(["image", "lifetimeMs", "network", "labels", "mount", "gpu"]);
|
|
92
100
|
/** The provider's root channel: argv run as root in a session of its own; the image's user is root, never sudo. */
|
|
93
101
|
const ROOT_RUN = [
|
|
94
102
|
"# agentrun-computer: root",
|
|
@@ -289,7 +297,7 @@ function codeOf(status, text) {
|
|
|
289
297
|
return "limit";
|
|
290
298
|
if (status === 400 || status === 409 || status === 422)
|
|
291
299
|
return "invalid";
|
|
292
|
-
return "
|
|
300
|
+
return "vendor";
|
|
293
301
|
}
|
|
294
302
|
/** Whether fetch failed on a redirect it was told not to follow. */
|
|
295
303
|
function redirected(cause) {
|
|
@@ -352,7 +360,7 @@ class Rest {
|
|
|
352
360
|
return ok({ status: response.status, bytes });
|
|
353
361
|
const text = decoder.decode(bytes).replace(/\s+/g, " ").slice(0, 300);
|
|
354
362
|
retryable = response.status === 429 || response.status >= 500;
|
|
355
|
-
failure =
|
|
363
|
+
failure = errorOf(codeOf(response.status, text), `${what}: ${response.status} ${text}`, "daytona");
|
|
356
364
|
}
|
|
357
365
|
catch (cause) {
|
|
358
366
|
if (signal?.aborted)
|
|
@@ -360,9 +368,9 @@ class Rest {
|
|
|
360
368
|
if (timeout.aborted)
|
|
361
369
|
failure = { code: "timeout", message: `${what} did not answer within ${timeoutMs / 1000} s` };
|
|
362
370
|
else if (redirected(cause))
|
|
363
|
-
return
|
|
371
|
+
return vendorFail("daytona", `${what}: Daytona answered with a redirect, which is never followed: it would carry the key`);
|
|
364
372
|
else
|
|
365
|
-
failure = { code: "daytona", message: `${what}: ${cause.message}` };
|
|
373
|
+
failure = { code: "vendor", vendor: "daytona", message: `${what}: ${cause.message}` };
|
|
366
374
|
}
|
|
367
375
|
if (!retryable || attempt >= attempts)
|
|
368
376
|
return { ok: false, error: failure };
|
|
@@ -379,15 +387,20 @@ class Rest {
|
|
|
379
387
|
if (!found.ok)
|
|
380
388
|
return found.error.code === "not_found" ? ok(undefined) : found;
|
|
381
389
|
const sb = found.value;
|
|
382
|
-
return typeof sb?.id === "string" ? ok(sb) :
|
|
390
|
+
return typeof sb?.id === "string" ? ok(sb) : vendorFail("daytona", `GET /sandbox/${idOrName}: no sandbox in the answer`);
|
|
383
391
|
}
|
|
384
392
|
}
|
|
385
393
|
/** Every way a sandbox, as Daytona reads it back, differs from what create asked for. Pure: no call. */
|
|
386
394
|
function sandboxDrift(spec, sb, expected) {
|
|
387
395
|
const found = [];
|
|
388
396
|
const mismatch = (field, declared, actual) => found.push(`${field}: declared ${show(declared)}, read back ${show(actual)}`);
|
|
389
|
-
//
|
|
390
|
-
|
|
397
|
+
// A GPU computer is made from daytona-gpu, whatever image named it. Daytona's default snapshot is whichever it names: a
|
|
398
|
+
// computer made from it is not held to a name.
|
|
399
|
+
if (spec.gpu !== undefined) {
|
|
400
|
+
if (sb.snapshot !== DAYTONA_GPU_SNAPSHOT)
|
|
401
|
+
mismatch("snapshot", DAYTONA_GPU_SNAPSHOT, sb.snapshot);
|
|
402
|
+
}
|
|
403
|
+
else if (spec.image !== DAYTONA_DEFAULT_SNAPSHOT && sb.snapshot !== spec.image)
|
|
391
404
|
mismatch("snapshot", spec.image, sb.snapshot);
|
|
392
405
|
const network = networkOf(sb);
|
|
393
406
|
if (!samePolicy(network, spec.network))
|
|
@@ -417,8 +430,12 @@ function sandboxDrift(spec, sb, expected) {
|
|
|
417
430
|
mismatch("public", false, sb.public);
|
|
418
431
|
if (sb.kvm === true)
|
|
419
432
|
mismatch("kvm", false, sb.kvm);
|
|
420
|
-
|
|
421
|
-
|
|
433
|
+
// The GPUs read back, held to the snapshot's own (a create sends none): daytona-gpu's for a GPU computer, none else.
|
|
434
|
+
const gpus = spec.gpu === undefined ? 0 : DAYTONA_GPU_SNAPSHOT_GPU.count;
|
|
435
|
+
if ((sb.gpu ?? 0) !== gpus)
|
|
436
|
+
mismatch("gpu", gpus, sb.gpu);
|
|
437
|
+
if (spec.gpu !== undefined && sb.gpuType !== DAYTONA_GPU_SNAPSHOT_GPU.type)
|
|
438
|
+
mismatch("gpuType", DAYTONA_GPU_SNAPSHOT_GPU.type, sb.gpuType);
|
|
422
439
|
if (Array.isArray(sb.volumes) ? sb.volumes.length > 0 : sb.volumes !== undefined && sb.volumes !== null)
|
|
423
440
|
mismatch("volumes", [], sb.volumes);
|
|
424
441
|
if (typeof sb.linkedSandboxId === "string" && sb.linkedSandboxId !== "")
|
|
@@ -471,12 +488,12 @@ function sessionStream(socket, send) {
|
|
|
471
488
|
lines(Buffer.from(data), false);
|
|
472
489
|
});
|
|
473
490
|
socket.addEventListener("error", (event) => {
|
|
474
|
-
opened(
|
|
491
|
+
opened(vendorFail("daytona", `the log stream failed: ${event.message ?? "no reason given"}`));
|
|
475
492
|
if (!readable.destroyed)
|
|
476
493
|
readable.destroy(new Error(`the log stream failed${event.message ? `: ${event.message}` : ""}`));
|
|
477
494
|
});
|
|
478
495
|
socket.addEventListener("close", ({ code }) => {
|
|
479
|
-
opened(
|
|
496
|
+
opened(vendorFail("daytona", `the log stream closed before it opened (code ${code ?? "none"})`));
|
|
480
497
|
if (readable.destroyed)
|
|
481
498
|
return;
|
|
482
499
|
lines(Buffer.alloc(0), true);
|
|
@@ -571,7 +588,7 @@ export class DaytonaProvider {
|
|
|
571
588
|
return {
|
|
572
589
|
kind: "linux",
|
|
573
590
|
lifetime: "vendor",
|
|
574
|
-
network: [
|
|
591
|
+
network: [...DAYTONA.network],
|
|
575
592
|
isolation: this.#class === "linux-vm" ? "vm" : "container",
|
|
576
593
|
os: "linux",
|
|
577
594
|
daemon: "child",
|
|
@@ -582,6 +599,8 @@ export class DaytonaProvider {
|
|
|
582
599
|
stopDeletes: this.#autoDelete === 0,
|
|
583
600
|
mount: [...MOUNT],
|
|
584
601
|
vendorAgentPorts: [TOOLBOX_PORT],
|
|
602
|
+
// A GPU sandbox's limits are stated in gpu: its stop deletes it, it runs in region earth, its size is per GPU.
|
|
603
|
+
gpu: daytonaGpuCapability(),
|
|
585
604
|
};
|
|
586
605
|
}
|
|
587
606
|
check(spec) {
|
|
@@ -593,7 +612,7 @@ export class DaytonaProvider {
|
|
|
593
612
|
refuse("image", `an image is required: the id or name of a Daytona snapshot, or "${DAYTONA_DEFAULT_SNAPSHOT}" for Daytona's default snapshot`);
|
|
594
613
|
else if (/[\0-\x1f]/.test(image))
|
|
595
614
|
refuse("image", "a snapshot name has no control characters");
|
|
596
|
-
refusals.push(...
|
|
615
|
+
refusals.push(...checkTenure(given, this.capabilities(), "Daytona"));
|
|
597
616
|
if (network === "open" || (typeof network === "object" && network !== null && "allow" in network))
|
|
598
617
|
refuse("network", OWN_NETWORK_ONLY);
|
|
599
618
|
else if (network !== "none")
|
|
@@ -613,6 +632,13 @@ export class DaytonaProvider {
|
|
|
613
632
|
refuse("mount", `an Archil mount's tools run as agentrun-tool, ${tool}:${tool}, and this provider's daemon user is ${this.#uid}:${this.#gid}: give it daemonUser "${tool}:${tool}"`);
|
|
614
633
|
}
|
|
615
634
|
}
|
|
635
|
+
// The GPU is the snapshot's (a create sends none): daytona-gpu's type and count alone, and no mount (DAYTONA_GPU).
|
|
636
|
+
const gpuRefused = checkGpu(given.gpu, this.capabilities(), given.mount);
|
|
637
|
+
refusals.push(...gpuRefused);
|
|
638
|
+
// A GPU computer is made from daytona-gpu: a spec names it, or Daytona's default, never another snapshot.
|
|
639
|
+
if (given.gpu !== undefined && gpuRefused.length === 0 && typeof image === "string" && image !== DAYTONA_DEFAULT_SNAPSHOT && image !== DAYTONA_GPU_SNAPSHOT) {
|
|
640
|
+
refuse("image", `a Daytona GPU computer is made from Daytona's GPU snapshot ${DAYTONA_GPU_SNAPSHOT} alone, not ${JSON.stringify(image)}: give "${DAYTONA_GPU_SNAPSHOT}" or "${DAYTONA_DEFAULT_SNAPSHOT}"; no other snapshot is proven to give a GPU computer`);
|
|
641
|
+
}
|
|
616
642
|
for (const [field, value] of Object.entries(given)) {
|
|
617
643
|
if (SPEC_FIELDS.has(field) || value === undefined)
|
|
618
644
|
continue;
|
|
@@ -642,23 +668,30 @@ export class DaytonaProvider {
|
|
|
642
668
|
if (signal?.aborted)
|
|
643
669
|
return fail("aborted", "create was aborted before Daytona was called");
|
|
644
670
|
const name = `computer-${randomBytes(6).toString("hex")}`;
|
|
645
|
-
const deadline = new Date(Date.now() + spec
|
|
671
|
+
const deadline = new Date(Date.now() + runLifetimeMs(spec)).toISOString();
|
|
646
672
|
const archil = archilOf(spec);
|
|
647
673
|
const body = {
|
|
648
674
|
name,
|
|
649
|
-
//
|
|
650
|
-
|
|
675
|
+
// A GPU sandbox is made from daytona-gpu (check() took "default" or that name). Otherwise "default" sends no
|
|
676
|
+
// snapshot, and Daytona makes the sandbox from its default snapshot.
|
|
677
|
+
...(spec.gpu !== undefined ? { snapshot: DAYTONA_GPU_SNAPSHOT } : spec.image === DAYTONA_DEFAULT_SNAPSHOT ? {} : { snapshot: spec.image }),
|
|
651
678
|
// An Archil computer carries its mount as a label: kind and source, never the token.
|
|
652
679
|
labels: { ...spec.labels, ...(archil ? archilLabels(archil) : {}), [COMPUTER_LABEL]: "1", [DEADLINE_LABEL]: deadline, [IMAGE_LABEL]: spec.image },
|
|
653
680
|
env: {},
|
|
654
681
|
public: false,
|
|
655
|
-
|
|
656
|
-
|
|
682
|
+
// A GPU sandbox runs in region earth alone, whatever the provider's target.
|
|
683
|
+
...(spec.gpu !== undefined ? { target: DAYTONA_GPU_REGION } : this.#target === undefined ? {} : { target: this.#target }),
|
|
684
|
+
ttlMinutes: Math.max(1, Math.ceil(runLifetimeMs(spec) / 60_000)),
|
|
657
685
|
autoStopInterval: this.#autoStop,
|
|
658
|
-
|
|
686
|
+
// A GPU sandbox's stop deletes it (no pause, no snapshot), so it is asked for and read back as deleted at stop:
|
|
687
|
+
// autoDeleteInterval 0 is Daytona's ephemeral (its SDK's ephemeral sets it; CreateSandbox has no ephemeral field).
|
|
688
|
+
autoDeleteInterval: this.#autoDeleteFor(spec.gpu !== undefined),
|
|
659
689
|
// An Archil computer's root reaches Archil: Daytona's network is open, and init's own namespace (loopback alone)
|
|
660
690
|
// holds the tools to none.
|
|
661
691
|
...(networkBody(archil ? "open" : spec.network) ?? { networkBlockAll: true }),
|
|
692
|
+
// No resource field (cpu, gpu, gpuType, memory, disk): a snapshot carries its own, and Daytona refuses a create that
|
|
693
|
+
// names a snapshot and sends any (400 "Cannot specify Sandbox resources when using a snapshot"). A GPU computer's
|
|
694
|
+
// GPU is daytona-gpu's, held in the read-back.
|
|
662
695
|
};
|
|
663
696
|
const posted = await this.#rest.json("POST", this.#rest.sandbox(), { json: body, timeoutMs: this.#timeouts.createMs }, signal);
|
|
664
697
|
const made = posted.ok ? posted.value : undefined;
|
|
@@ -670,7 +703,7 @@ export class DaytonaProvider {
|
|
|
670
703
|
const left = removed.ok ? "" : `; a sandbox named ${name} may be left (${removed.error.message}), which Daytona ends by ${deadline}`;
|
|
671
704
|
if (!posted.ok)
|
|
672
705
|
return fail(posted.error.code, `${posted.error.code === "aborted" ? "create was aborted" : "Daytona did not create the sandbox"}: ${posted.error.message}${left}`);
|
|
673
|
-
return
|
|
706
|
+
return vendorFail("daytona", `POST /sandbox: no sandbox id in the answer${left}`);
|
|
674
707
|
}
|
|
675
708
|
const ref = { id: made.id, name };
|
|
676
709
|
// From here the sandbox exists: every step takes the caller's signal, and a failure or an abort deletes it.
|
|
@@ -678,7 +711,7 @@ export class DaytonaProvider {
|
|
|
678
711
|
if (signal?.aborted)
|
|
679
712
|
return this.#abandon(ref, { code: "aborted", message: "create was aborted" }, signal);
|
|
680
713
|
if (prepared.ok)
|
|
681
|
-
return ok(ref);
|
|
714
|
+
return ok(prepared.value.length > 0 ? { ...ref, notes: prepared.value } : ref);
|
|
682
715
|
return this.#abandon(ref, prepared.error, signal);
|
|
683
716
|
}
|
|
684
717
|
async #abandon(ref, error, signal) {
|
|
@@ -701,7 +734,7 @@ export class DaytonaProvider {
|
|
|
701
734
|
const sb = started.value;
|
|
702
735
|
const archil = archilOf(spec);
|
|
703
736
|
// An Archil computer's network at Daytona is open for root; init's own namespace holds the tools to the spec's none.
|
|
704
|
-
const vendor = sandboxDrift(archil ? { ...spec, network: "open" } : spec, sb, this.#sandboxExpected(deadline));
|
|
737
|
+
const vendor = sandboxDrift(archil ? { ...spec, network: "open" } : spec, sb, this.#sandboxExpected(deadline, spec.gpu !== undefined));
|
|
705
738
|
if (vendor.length > 0)
|
|
706
739
|
return fail("refused", `it did not match its spec: ${vendor.join("; ")}`);
|
|
707
740
|
const toolbox = await this.#toolbox(sb, signal);
|
|
@@ -725,6 +758,8 @@ export class DaytonaProvider {
|
|
|
725
758
|
const read = /^sha256 ([0-9a-f]{64})$/m.exec(install.value.result)?.[1];
|
|
726
759
|
if (read !== sha256)
|
|
727
760
|
return fail("refused", `it did not match its spec: daemon: uploaded sha256 ${sha256}, the installed binary reads back ${show(read)}`);
|
|
761
|
+
// Who installed it, for the create's notes: root, or the snapshot's user through passwordless sudo (daytona-gpu's).
|
|
762
|
+
const installer = installerOf(install.value.result);
|
|
728
763
|
// The run's folder, mounted before init starts, so no tool program runs before it is there.
|
|
729
764
|
let epoch;
|
|
730
765
|
if (archil) {
|
|
@@ -772,7 +807,8 @@ export class DaytonaProvider {
|
|
|
772
807
|
return fail("refused", `it did not match its spec: mount: declared ${show(want)}, read back ${show(mountRead.value ?? "nothing")}`);
|
|
773
808
|
}
|
|
774
809
|
}
|
|
775
|
-
|
|
810
|
+
const listed = await this.#waitListed(ref.id, signal);
|
|
811
|
+
return listed.ok ? ok(installer === undefined ? [] : [installer]) : listed;
|
|
776
812
|
}
|
|
777
813
|
/**
|
|
778
814
|
* What an Archil computer mounts at /workspace, read back through its computerd: the mount table, and whether the
|
|
@@ -800,7 +836,7 @@ export class DaytonaProvider {
|
|
|
800
836
|
return ran;
|
|
801
837
|
const commandId = ran.value?.cmdId;
|
|
802
838
|
if (typeof commandId !== "string")
|
|
803
|
-
return
|
|
839
|
+
return vendorFail("daytona", "POST exec: no command id in the answer");
|
|
804
840
|
const command = `${session}/command/${encodeURIComponent(commandId)}`;
|
|
805
841
|
if (stdin !== undefined) {
|
|
806
842
|
// Its words never carry stdin: it is the disk's token.
|
|
@@ -833,8 +869,12 @@ export class DaytonaProvider {
|
|
|
833
869
|
},
|
|
834
870
|
};
|
|
835
871
|
}
|
|
836
|
-
#sandboxExpected(deadline) {
|
|
837
|
-
return { deadline, sandboxClass: this.#class, autoStopInterval: this.#autoStop, autoDeleteInterval: this.#
|
|
872
|
+
#sandboxExpected(deadline, gpu = false) {
|
|
873
|
+
return { deadline, sandboxClass: this.#class, autoStopInterval: this.#autoStop, autoDeleteInterval: this.#autoDeleteFor(gpu) };
|
|
874
|
+
}
|
|
875
|
+
/** The autoDeleteInterval a sandbox is made and read back with: 0 for a GPU sandbox, which a stop deletes; else the option's. */
|
|
876
|
+
#autoDeleteFor(gpu) {
|
|
877
|
+
return gpu ? 0 : this.#autoDelete;
|
|
838
878
|
}
|
|
839
879
|
#daemonExpected() {
|
|
840
880
|
const { kind, groups } = this.capabilities();
|
|
@@ -849,7 +889,7 @@ export class DaytonaProvider {
|
|
|
849
889
|
return ok(current);
|
|
850
890
|
if (current === undefined || GONE.has(current.state ?? "") || current.state === "error" || current.state === "build_failed") {
|
|
851
891
|
const reason = current?.errorReason ? `: ${current.errorReason}` : "";
|
|
852
|
-
return
|
|
892
|
+
return vendorFail("daytona", `the sandbox went to ${current?.state ?? "deleted"} while starting${reason}`);
|
|
853
893
|
}
|
|
854
894
|
if (!first && Date.now() >= end)
|
|
855
895
|
return fail("timeout", `the sandbox did not start within ${this.#timeouts.startMs / 1000} s (state ${current.state})`);
|
|
@@ -904,10 +944,10 @@ export class DaytonaProvider {
|
|
|
904
944
|
url = new URL(proxy ?? "");
|
|
905
945
|
}
|
|
906
946
|
catch {
|
|
907
|
-
return
|
|
947
|
+
return vendorFail("daytona", `Daytona gave no toolbox URL for ${sb.id}`);
|
|
908
948
|
}
|
|
909
949
|
if (url.protocol !== "https:")
|
|
910
|
-
return
|
|
950
|
+
return vendorFail("daytona", `the toolbox URL Daytona gave is not https (${url.protocol}), so the key is not sent to it`);
|
|
911
951
|
return ok(`${url.href.replace(/\/+$/, "")}/${encodeURIComponent(sb.id)}`);
|
|
912
952
|
}
|
|
913
953
|
async #execute(toolbox, command, signal) {
|
|
@@ -950,7 +990,7 @@ export class DaytonaProvider {
|
|
|
950
990
|
const commandId = ran.ok ? ran.value?.cmdId : undefined;
|
|
951
991
|
if (!ran.ok || typeof commandId !== "string") {
|
|
952
992
|
await removeSession();
|
|
953
|
-
return ran.ok ?
|
|
993
|
+
return ran.ok ? vendorFail("daytona", "POST exec: no command id in the answer") : ran;
|
|
954
994
|
}
|
|
955
995
|
const command = `${session}/command/${encodeURIComponent(commandId)}`;
|
|
956
996
|
const logs = `${command.replace(/^https:/, "wss:")}/logs?follow=true`;
|
|
@@ -960,7 +1000,7 @@ export class DaytonaProvider {
|
|
|
960
1000
|
}
|
|
961
1001
|
catch (error) {
|
|
962
1002
|
await removeSession();
|
|
963
|
-
return
|
|
1003
|
+
return vendorFail("daytona", `opening the log stream: ${error.message}`);
|
|
964
1004
|
}
|
|
965
1005
|
const stream = sessionStream(socket, async (data) => {
|
|
966
1006
|
const sent = await this.#rest.call("POST", `${command}/input`, { json: { data } });
|
|
@@ -1003,7 +1043,7 @@ export class DaytonaProvider {
|
|
|
1003
1043
|
return timedOut();
|
|
1004
1044
|
if (hello.error.code !== "gone")
|
|
1005
1045
|
return hello;
|
|
1006
|
-
return
|
|
1046
|
+
return vendorFail("daytona", `cannot reach the daemon in ${sb.name ?? sb.id}: ${stream.stderr() || hello.error.message}`);
|
|
1007
1047
|
}
|
|
1008
1048
|
return ok({ client, hello: hello.value, close });
|
|
1009
1049
|
}
|
|
@@ -1036,7 +1076,7 @@ export class DaytonaProvider {
|
|
|
1036
1076
|
if (!opened.ok)
|
|
1037
1077
|
return opened;
|
|
1038
1078
|
const { kind, groups } = this.capabilities();
|
|
1039
|
-
const drifted = helloDrift(opened.value.hello, { version: VERSION, kind, groups, arch: this.#arch });
|
|
1079
|
+
const drifted = helloDrift(opened.value.hello, { version: VERSION, kind, groups, arch: this.#arch, fence: true });
|
|
1040
1080
|
// An Archil computer's client syncs the run's folder after every call that may change it, before it answers.
|
|
1041
1081
|
if (drifted.length === 0)
|
|
1042
1082
|
return recordedMount(found.value.labels) ? ok({ ...opened.value, client: syncingClient(opened.value.client) }) : opened;
|
|
@@ -1103,9 +1143,11 @@ export class DaytonaProvider {
|
|
|
1103
1143
|
// The image create was asked for, from its label; a computer made before the label was written reports its snapshot.
|
|
1104
1144
|
const asked = sb.labels?.[IMAGE_LABEL];
|
|
1105
1145
|
const specNetwork = archilComputer || (typeof network === "object" && "other" in network) ? "none" : network;
|
|
1106
|
-
|
|
1146
|
+
// The GPUs Daytona reports, held to what check() allows: a type this provider declares, a count up to its max.
|
|
1147
|
+
const gpu = isWhole(sb.gpu) && sb.gpu > 0 ? { type: String(sb.gpuType), count: sb.gpu } : undefined;
|
|
1148
|
+
const spec = { image: asked ?? sb.snapshot, lifetimeMs: 1, network: specNetwork, labels, ...(gpu === undefined ? {} : { gpu }) };
|
|
1107
1149
|
found.push(...this.check(spec).map(({ field, message }) => `${field}: ${message}, read back from the computer`));
|
|
1108
|
-
const vendor = sandboxDrift(spec, sb, this.#sandboxExpected(sb.labels?.[DEADLINE_LABEL] ?? ""));
|
|
1150
|
+
const vendor = sandboxDrift(spec, sb, this.#sandboxExpected(sb.labels?.[DEADLINE_LABEL] ?? "", gpu !== undefined));
|
|
1109
1151
|
found.push(...vendor.filter((line) => !line.startsWith("network:") &&
|
|
1110
1152
|
!line.startsWith(`label ${DEADLINE_LABEL}`) &&
|
|
1111
1153
|
!(asked === undefined && line.startsWith(`label ${IMAGE_LABEL}`)) &&
|
|
@@ -1158,6 +1200,7 @@ export class DaytonaProvider {
|
|
|
1158
1200
|
...(workdir === undefined ? {} : { workdir }),
|
|
1159
1201
|
...(deadline === undefined ? {} : { deadline }),
|
|
1160
1202
|
...(kind === undefined ? {} : { kind }),
|
|
1203
|
+
...(gpu === undefined ? {} : { gpu }),
|
|
1161
1204
|
},
|
|
1162
1205
|
});
|
|
1163
1206
|
}
|
|
@@ -1176,17 +1219,17 @@ export class DaytonaProvider {
|
|
|
1176
1219
|
const value = answer.value;
|
|
1177
1220
|
const items = Array.isArray(value) ? value : Array.isArray(value?.items) ? value.items : undefined;
|
|
1178
1221
|
if (items === undefined)
|
|
1179
|
-
return
|
|
1222
|
+
return vendorFail("daytona", "GET /sandbox: the listing is not a page of sandboxes");
|
|
1180
1223
|
found.push(...items);
|
|
1181
1224
|
const next = Array.isArray(value) ? undefined : value?.nextCursor;
|
|
1182
1225
|
if (typeof next !== "string" || next === "")
|
|
1183
1226
|
return ok(found);
|
|
1184
1227
|
if (seen.has(next))
|
|
1185
|
-
return
|
|
1228
|
+
return vendorFail("daytona", `GET /sandbox: the listing's cursor ${next} came back twice`);
|
|
1186
1229
|
seen.add(next);
|
|
1187
1230
|
cursor = next;
|
|
1188
1231
|
}
|
|
1189
|
-
return
|
|
1232
|
+
return vendorFail("daytona", `GET /sandbox: the listing ran past ${MAX_PAGES} pages`);
|
|
1190
1233
|
}
|
|
1191
1234
|
/**
|
|
1192
1235
|
* For the sweep after a live run: every sandbox Daytona lists with agentrun.computer=1, whatever its name or state, as
|
|
@@ -1224,7 +1267,7 @@ export class DaytonaProvider {
|
|
|
1224
1267
|
const value = answer.value;
|
|
1225
1268
|
const items = Array.isArray(value) ? value : Array.isArray(value?.items) ? value.items : undefined;
|
|
1226
1269
|
if (items === undefined)
|
|
1227
|
-
return countTested("Daytona",
|
|
1270
|
+
return countTested("Daytona", vendorFail("daytona", "GET /sandbox: the listing is not a page of sandboxes"));
|
|
1228
1271
|
const next = Array.isArray(value) ? undefined : value?.nextCursor;
|
|
1229
1272
|
return countTested("Daytona", ok({ count: items.filter((item) => ours(item) && !going(item)).length, more: typeof next === "string" && next !== "" }));
|
|
1230
1273
|
}
|
|
@@ -1410,8 +1453,10 @@ export class DaytonaProvider {
|
|
|
1410
1453
|
if (!stopped.ok && stopped.error.code !== "invalid" && stopped.error.code !== "not_found")
|
|
1411
1454
|
return stopped;
|
|
1412
1455
|
}
|
|
1413
|
-
// With autoDeleteInterval 0, Daytona deletes a sandbox as it stops: such a stop is done once the computer is gone.
|
|
1414
|
-
|
|
1456
|
+
// With autoDeleteInterval 0, Daytona deletes a sandbox as it stops: such a stop is done once the computer is gone. A
|
|
1457
|
+
// GPU sandbox is one of those whatever the option (its stop deletes it).
|
|
1458
|
+
const deletes = this.#autoDeleteFor(isWhole(sb.gpu) && sb.gpu > 0) === 0;
|
|
1459
|
+
return this.#settle(ref, deletes ? "gone" : "stopped", "stop", signal);
|
|
1415
1460
|
}
|
|
1416
1461
|
/**
|
|
1417
1462
|
* Waits, through waitUntil, until Daytona reads the sandbox as wanted, twice running, by its own read and by the
|
|
@@ -1433,7 +1478,7 @@ export class DaytonaProvider {
|
|
|
1433
1478
|
const sb = got.value;
|
|
1434
1479
|
last = stateWords(sb);
|
|
1435
1480
|
if (sb !== undefined && (sb.state === "error" || sb.state === "build_failed") && sb.desiredState !== "destroyed") {
|
|
1436
|
-
return { failed:
|
|
1481
|
+
return { failed: vendorFail("daytona", `release ${how} of ${ref.name}: it went to ${sb.state}${sb.errorReason ? `: ${sb.errorReason}` : ""}`) };
|
|
1437
1482
|
}
|
|
1438
1483
|
const gone = sb === undefined || sb.state === "destroyed";
|
|
1439
1484
|
const reached = gone ? "gone" : want === "stopped" && STOPPED.has(sb.state ?? "") ? "stopped" : undefined;
|
|
@@ -1493,6 +1538,6 @@ export class DaytonaProvider {
|
|
|
1493
1538
|
if (attempt < DELETE_ATTEMPTS)
|
|
1494
1539
|
await sleep(this.#timeouts.retryMs);
|
|
1495
1540
|
}
|
|
1496
|
-
return { ok: false, error: failure ?? { code: "daytona", message: `could not delete ${idOrName}` } };
|
|
1541
|
+
return { ok: false, error: failure ?? { code: "vendor", vendor: "daytona", message: `could not delete ${idOrName}` } };
|
|
1497
1542
|
}
|
|
1498
1543
|
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { ComputerSettingKind, KindCapabilities } from "./kinds.js";
|
|
2
|
+
import type { MountKind } from "./mount.js";
|
|
3
|
+
import type { NetworkForm } from "./provider.js";
|
|
4
|
+
import type { ProviderModule } from "./providers.js";
|
|
5
|
+
/** One key a provider takes in Settings: its serve-side name, the create() option it fills, and whether it is needed. */
|
|
6
|
+
export interface DescriptorKey {
|
|
7
|
+
/** The name Settings stores it under and shows (DAYTONA_API_KEY); never a value. */
|
|
8
|
+
readonly name: string;
|
|
9
|
+
/** The create() option it fills (apiKey). */
|
|
10
|
+
readonly option: string;
|
|
11
|
+
readonly required: boolean;
|
|
12
|
+
}
|
|
13
|
+
/** A setting that is no key but fills a create() option, with the value used when the server names none. */
|
|
14
|
+
export interface DescriptorSetting {
|
|
15
|
+
/** Its name in the server's settings (modalApp). */
|
|
16
|
+
readonly name: string;
|
|
17
|
+
/** The create() option it fills (app). */
|
|
18
|
+
readonly option: string;
|
|
19
|
+
/** The value when the server's settings name none. */
|
|
20
|
+
readonly default?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A configuration its module builds but the provider does not offer yet: its kind, groups, image and create() options,
|
|
24
|
+
* as an offered one's, and why it is parked, in words. The conformance suite holds a built one to it as to an offered one.
|
|
25
|
+
*/
|
|
26
|
+
export type ParkedConfiguration = KindCapabilities & {
|
|
27
|
+
readonly image: string;
|
|
28
|
+
readonly why: string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* A provider, declared once. Every field is data but load(), which imports the provider module only when called:
|
|
32
|
+
* reading a descriptor loads no provider and no vendor SDK.
|
|
33
|
+
*/
|
|
34
|
+
export interface ProviderDescriptor<Module extends ProviderModule = ProviderModule> {
|
|
35
|
+
/** Its id, in the provider registry and in Settings: lowercase letters, digits and hyphens. */
|
|
36
|
+
readonly id: string;
|
|
37
|
+
/** Its name in words, as Settings shows it. */
|
|
38
|
+
readonly label: string;
|
|
39
|
+
/** The keys Settings takes for it, by name, and the option each fills; [] for none (Docker's host is local). */
|
|
40
|
+
readonly keys: readonly DescriptorKey[];
|
|
41
|
+
/** Settings that are no key but go to its options (Modal's app). */
|
|
42
|
+
readonly settings?: readonly DescriptorSetting[];
|
|
43
|
+
/** The vendor bills by time; prices are the vendor's page, not ours. */
|
|
44
|
+
readonly metered: boolean;
|
|
45
|
+
/** The mount kinds its computers take, as its providers' capabilities().mount declare them; [] for none. */
|
|
46
|
+
readonly mounts: readonly MountKind[];
|
|
47
|
+
/**
|
|
48
|
+
* The network forms its computers make, as its providers' capabilities().network declare them: ["none"], a remote
|
|
49
|
+
* computer whose programs run in a network of their own; ["open"], the vendor's own network, which no allowlist of
|
|
50
|
+
* this server reaches; Docker's makes all three. A provider of several configurations declares every form they make.
|
|
51
|
+
*/
|
|
52
|
+
readonly network: readonly NetworkForm[];
|
|
53
|
+
/**
|
|
54
|
+
* The machine kind and groups of each configuration it offers, as each built provider's capabilities() declare them;
|
|
55
|
+
* where it offers more than one image of a kind, each one's image (the name a setting selects it by) and the create()
|
|
56
|
+
* options that build it (KindCapabilities).
|
|
57
|
+
*/
|
|
58
|
+
readonly capabilities: readonly KindCapabilities[];
|
|
59
|
+
/**
|
|
60
|
+
* The image a computer of each setting kind starts from when its setting names none. A kind with no entry has no
|
|
61
|
+
* default, and the caller refuses the setting in words (Docker's sandbox: the server builds its image, prepareImage).
|
|
62
|
+
*/
|
|
63
|
+
readonly defaultImage?: Partial<Record<ComputerSettingKind, string>>;
|
|
64
|
+
/** Its built providers have prepareImage(): the image a computer starts from is made or pulled before the first create. */
|
|
65
|
+
readonly prepareImage?: boolean;
|
|
66
|
+
/** Its computers run on this machine's container engine: a server passes it its local host options (volume, host addresses). */
|
|
67
|
+
readonly local?: boolean;
|
|
68
|
+
/** create() takes a ledger the server keeps for it, as `options[ledger.option]` (the phone harness's sessions). */
|
|
69
|
+
readonly ledger?: {
|
|
70
|
+
readonly option: string;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* The server's own environment variables its provider reads on this machine, by name (Local Chrome's, where it finds
|
|
74
|
+
* Chrome): a server passes their values, and no other variable of its own, as `options.env`. The provider itself reads
|
|
75
|
+
* no environment.
|
|
76
|
+
*/
|
|
77
|
+
readonly hostEnv?: readonly string[];
|
|
78
|
+
/**
|
|
79
|
+
* Configurations its module builds but does not offer yet (Orgo's Windows and macOS desktops), each by the image a
|
|
80
|
+
* setting would name and why: a setting naming one is refused in its words, saying it is parked, never as an unknown
|
|
81
|
+
* image. No setting kind lists one, and Settings never offers one.
|
|
82
|
+
*/
|
|
83
|
+
readonly parked?: readonly ParkedConfiguration[];
|
|
84
|
+
/** The provider module, loaded on demand: its create(), its conformance module. */
|
|
85
|
+
load(): Promise<Module>;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* A descriptor, checked: its id's shape, its keys' and settings' names and options unique and non-empty, and one
|
|
89
|
+
* configuration at least. Throws in words naming what is wrong, so a bad descriptor never reaches a registry. The const
|
|
90
|
+
* type parameter keeps its literal id and its module's type, so ProviderOptions can read a create()'s options from it.
|
|
91
|
+
*/
|
|
92
|
+
export declare function defineProvider<const Descriptor extends ProviderDescriptor>(descriptor: Descriptor): Descriptor;
|
|
93
|
+
/** What is wrong with a value offered as a descriptor, in words; none when it is one. */
|
|
94
|
+
export declare function descriptorProblems(value: unknown): string[];
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
const ID = /^[a-z0-9][a-z0-9-]*$/;
|
|
2
|
+
/**
|
|
3
|
+
* A descriptor, checked: its id's shape, its keys' and settings' names and options unique and non-empty, and one
|
|
4
|
+
* configuration at least. Throws in words naming what is wrong, so a bad descriptor never reaches a registry. The const
|
|
5
|
+
* type parameter keeps its literal id and its module's type, so ProviderOptions can read a create()'s options from it.
|
|
6
|
+
*/
|
|
7
|
+
export function defineProvider(descriptor) {
|
|
8
|
+
const problems = descriptorProblems(descriptor);
|
|
9
|
+
if (problems.length > 0)
|
|
10
|
+
throw new Error(`the provider descriptor ${JSON.stringify(descriptor?.id)}: ${problems.join("; ")}`);
|
|
11
|
+
return descriptor;
|
|
12
|
+
}
|
|
13
|
+
/** What is wrong with a value offered as a descriptor, in words; none when it is one. */
|
|
14
|
+
export function descriptorProblems(value) {
|
|
15
|
+
if (typeof value !== "object" || value === null)
|
|
16
|
+
return ["it is not an object"];
|
|
17
|
+
const d = value;
|
|
18
|
+
const problems = [];
|
|
19
|
+
if (typeof d.id !== "string" || !ID.test(d.id))
|
|
20
|
+
problems.push(`id ${JSON.stringify(d.id)} is not lowercase letters, digits and hyphens`);
|
|
21
|
+
if (typeof d.label !== "string" || d.label.trim() === "")
|
|
22
|
+
problems.push("label is not a name in words");
|
|
23
|
+
if (typeof d.metered !== "boolean")
|
|
24
|
+
problems.push("metered is not true or false");
|
|
25
|
+
if (typeof d.load !== "function")
|
|
26
|
+
problems.push("load is not a function that imports the provider module");
|
|
27
|
+
if (!Array.isArray(d.mounts) || d.mounts.some((kind) => kind !== "bind" && kind !== "archil"))
|
|
28
|
+
problems.push("mounts is not a list of mount kinds (bind, archil)");
|
|
29
|
+
if (!Array.isArray(d.network) || d.network.length === 0 || d.network.some((form) => form !== "none" && form !== "open" && form !== "allow"))
|
|
30
|
+
problems.push("network is not a list of the network forms its computers make (none, open, allow)");
|
|
31
|
+
if (!Array.isArray(d.capabilities) || d.capabilities.length === 0)
|
|
32
|
+
problems.push("capabilities is not a list of one configuration or more");
|
|
33
|
+
else if (d.capabilities.some((one) => typeof one?.kind !== "string" || !Array.isArray(one.groups)))
|
|
34
|
+
problems.push("each configuration is a machine kind and its groups");
|
|
35
|
+
else {
|
|
36
|
+
const images = new Set();
|
|
37
|
+
for (const one of d.capabilities) {
|
|
38
|
+
if (one.image !== undefined && (typeof one.image !== "string" || one.image.trim() === "" || one.image !== one.image.trim()))
|
|
39
|
+
problems.push(`a configuration's image ${JSON.stringify(one.image)} is not a name`);
|
|
40
|
+
else if (one.image !== undefined && images.has(`${one.kind} ${one.image}`))
|
|
41
|
+
problems.push(`two ${one.kind} configurations have the image ${one.image}`);
|
|
42
|
+
else if (one.image !== undefined)
|
|
43
|
+
images.add(`${one.kind} ${one.image}`);
|
|
44
|
+
if (one.options !== undefined && (typeof one.options !== "object" || one.options === null || Array.isArray(one.options)))
|
|
45
|
+
problems.push("a configuration's options are an object, as create() takes them");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const named = (list, what) => {
|
|
49
|
+
if (list === undefined)
|
|
50
|
+
return;
|
|
51
|
+
if (!Array.isArray(list))
|
|
52
|
+
return void problems.push(`${what} is not a list`);
|
|
53
|
+
const names = new Set();
|
|
54
|
+
const options = new Set();
|
|
55
|
+
for (const one of list) {
|
|
56
|
+
if (typeof one?.name !== "string" || one.name === "" || typeof one.option !== "string" || one.option === "")
|
|
57
|
+
problems.push(`each of ${what} has a name and the option it fills`);
|
|
58
|
+
else if (names.has(one.name) || options.has(one.option))
|
|
59
|
+
problems.push(`${what} names ${one.name} or fills ${one.option} twice`);
|
|
60
|
+
else
|
|
61
|
+
names.add(one.name), options.add(one.option);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
if (d.keys === undefined)
|
|
65
|
+
problems.push("keys is not a list");
|
|
66
|
+
named(d.keys, "keys");
|
|
67
|
+
named(d.settings, "settings");
|
|
68
|
+
if (Array.isArray(d.keys) && d.keys.some((key) => typeof key?.required !== "boolean"))
|
|
69
|
+
problems.push("each key says whether it is required");
|
|
70
|
+
if (d.ledger !== undefined && (typeof d.ledger?.option !== "string" || d.ledger.option === ""))
|
|
71
|
+
problems.push("ledger names the option it fills");
|
|
72
|
+
if (d.hostEnv !== undefined && (!Array.isArray(d.hostEnv) || d.hostEnv.some((name) => typeof name !== "string" || name === "")))
|
|
73
|
+
problems.push("hostEnv is a list of environment variable names");
|
|
74
|
+
if (d.parked !== undefined) {
|
|
75
|
+
if (!Array.isArray(d.parked) || d.parked.some((one) => typeof one?.image !== "string" || one.image === "" || typeof one.why !== "string" || one.why === "" || typeof one.kind !== "string" || !Array.isArray(one.groups)))
|
|
76
|
+
problems.push("parked is a list of configurations, each with its image and why it is parked");
|
|
77
|
+
else if (Array.isArray(d.capabilities) && d.parked.some((one) => d.capabilities.some((offered) => offered?.image === one.image)))
|
|
78
|
+
problems.push("a parked image is also offered");
|
|
79
|
+
}
|
|
80
|
+
return problems;
|
|
81
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const BROWSERBASE: {
|
|
2
|
+
readonly id: "browserbase";
|
|
3
|
+
readonly label: "Browserbase";
|
|
4
|
+
readonly keys: readonly [{
|
|
5
|
+
readonly name: "BROWSERBASE_API_KEY";
|
|
6
|
+
readonly option: "apiKey";
|
|
7
|
+
readonly required: true;
|
|
8
|
+
}, {
|
|
9
|
+
readonly name: "BROWSERBASE_PROJECT_ID";
|
|
10
|
+
readonly option: "projectId";
|
|
11
|
+
readonly required: true;
|
|
12
|
+
}];
|
|
13
|
+
readonly metered: true;
|
|
14
|
+
readonly mounts: readonly [];
|
|
15
|
+
readonly network: readonly ["open"];
|
|
16
|
+
readonly capabilities: readonly [{
|
|
17
|
+
readonly kind: "browser";
|
|
18
|
+
readonly groups: ["cdp", "stream"];
|
|
19
|
+
}];
|
|
20
|
+
readonly defaultImage: {
|
|
21
|
+
readonly browser: "chromium";
|
|
22
|
+
};
|
|
23
|
+
readonly load: () => Promise<typeof import("../browserbase.js")>;
|
|
24
|
+
};
|