@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/index.js
CHANGED
|
@@ -7,20 +7,24 @@ export { checkActions, isKey } from "./actions.js";
|
|
|
7
7
|
export { pullTar, pullTarStream, pushTar, readFile, writeFile } from "./files.js";
|
|
8
8
|
export { listProcesses, readAll } from "./processes.js";
|
|
9
9
|
export { createActionMapper, daemonWatch, redactWords, ScreenWatchError, toAction, watchEndCode, watchScreen, } from "./screen-watch.js";
|
|
10
|
-
|
|
10
|
+
// The provider classes and their option types are not here: each provider loads by its id through the registry
|
|
11
|
+
// (providerFor), or from its own subpath (@parcha/agentrun-computer/docker, /daytona, /modal, /e2b, /orgo,
|
|
12
|
+
// /phone-harness, /browserbase, /kernel, /local: each the provider file's name).
|
|
11
13
|
export { VOLUME_SUBPATH_ENGINE } from "./docker/volume.js";
|
|
12
14
|
export { DEFAULT_DOCKER_IMAGE, DOCKER_BASE, DOCKER_RECIPE, DOCKER_RECIPE_HAS, ensureImage, IMAGE_REPOSITORY, IMAGE_TIMEOUT_MS, imageSourceProblem, RECIPE_LABEL, recipeHash, recipeTag, } from "./docker/image.js";
|
|
13
15
|
export { EGRESS_IMAGE, EGRESS_LABEL, EGRESS_MOUNT, EGRESS_SOCKET } from "./docker/egress.js";
|
|
14
|
-
export { DAYTONA_DEFAULT_SNAPSHOT, DaytonaProvider } from "./daytona.js";
|
|
15
|
-
export { ModalProvider, } from "./modal.js";
|
|
16
16
|
export { ARCHIL_HELPER, ARCHIL_MOUNT_LABEL, ARCHIL_SYNC_SOCKET, ARCHIL_TOOL_UID, ARCHIL_TOOL_USER, ARCHIL_VERSION, archilLabels, archilMount, archilReadBack, archilRefusals, archilRelease, claimEpoch, helperSha256, mountDrift, mountWords, readArchilMount, recordedArchil, recordedMount, syncingClient, } from "./mount-archil.js";
|
|
17
|
-
export {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export {
|
|
17
|
+
export { BrowserVendorError, CREATE_LABEL, causeOf, memoryUrls, RECOVER_MS, } from "./browser.js";
|
|
18
|
+
// Local Chrome's provider class is on its provider id's subpath (@parcha/agentrun-computer/local-chrome), as every
|
|
19
|
+
// provider's is; the Chrome helpers it runs on are not a provider and stay here.
|
|
20
|
+
export { CHROME_ENV, CHROME_FLAGS, checkChrome, chromeFence, findChrome, killTree, NO_CHROME } from "./chrome.js";
|
|
21
|
+
export { DAEMON_IN_COMPUTER, helloDrift } from "./drift.js";
|
|
22
|
+
export { drift, hostOf, inspectDrift, mountOf, networkOf } from "./docker/inspect.js";
|
|
21
23
|
export { releaseOlder, sweep } from "./janitor.js";
|
|
22
|
-
export { EPOCH_LABEL, epochOf, epochProblem, RUN_LABEL, runLabels, runProblem } from "./labels.js";
|
|
24
|
+
export { EPOCH_LABEL, epochOf, epochProblem, IDLE_TTL_LABEL, OWNER_LABEL, ownerLabels, ownerOf, RUN_HASH_LABEL, RUN_LABEL, runHash, runLabels, runProblem } from "./labels.js";
|
|
23
25
|
export { waitUntil } from "./wait.js";
|
|
24
|
-
export { isProviderId, providerFor, providerIds, providerModule, providers, } from "./providers.js";
|
|
25
|
-
export {
|
|
26
|
+
export { descriptorOf, isProviderId, providerFor, providerIds, providerModule, providers, } from "./providers.js";
|
|
27
|
+
export { defineProvider, descriptorProblems } from "./descriptor.js";
|
|
28
|
+
export { BROWSER_IMAGE, BROWSERBASE, DAYTONA, DAYTONA_DEFAULT_SNAPSHOT, DAYTONA_GPU_SNAPSHOT, DESCRIPTORS, DOCKER, E2B, E2B_BASE_TEMPLATE, E2B_DESKTOP_TEMPLATE, KERNEL, LOCAL, MODAL, MODAL_DEFAULT_IMAGE, ORGO, ORGO_BASE_IMAGE, PHONE_GROUPS, PHONE_HARNESS, PHONE_IMAGE, } from "./descriptors/index.js";
|
|
29
|
+
export { configurationOf, entryOf, imagesOf, kindOf, PROVIDERS, SETTING_KIND_NAMES, SETTING_KINDS, serves, servingRefusals, } from "./kinds.js";
|
|
26
30
|
export * from "./conformance/index.js";
|
package/dist/isolation.d.ts
CHANGED
|
@@ -4,8 +4,6 @@ import { type Result } from "./result.js";
|
|
|
4
4
|
export declare const TOOL_USER = "2510:2510";
|
|
5
5
|
/** Why a remote provider refuses network open or an allowlist, in words. */
|
|
6
6
|
export declare const OWN_NETWORK_ONLY = "a remote computer takes network \"none\" only: its programs run in a network of their own, their loopback alone, so the vendor's agent in it (which runs commands as root) is out of their reach; open and allowlists wait for a proxy out of that network";
|
|
7
|
-
/** The interfaces /proc/<pid>/net/dev lists, in its order; undefined when the text is not that file. */
|
|
8
|
-
export declare function netDevInterfaces(text: string): string[] | undefined;
|
|
9
7
|
/**
|
|
10
8
|
* The drift of a computer's programs' network from their own loopback alone, in words: none when the live interfaces
|
|
11
9
|
* (up or addressed) of the daemon's network namespace are `lo` alone, else what they are (or that they could not be read).
|
package/dist/isolation.js
CHANGED
|
@@ -7,27 +7,11 @@
|
|
|
7
7
|
// raise them, holding no CAP_NET_ADMIN, and the read-back here proves it through computerd's probe. Network "none" is
|
|
8
8
|
// all such a computer takes until a proxy carries open and allowlists out of that namespace.
|
|
9
9
|
import { DAEMON_IN_COMPUTER } from "./drift.js";
|
|
10
|
-
import { fail, ok } from "./result.js";
|
|
10
|
+
import { fail, failAs, ok } from "./result.js";
|
|
11
11
|
/** The uid:gid the programs of a remote computer run as by default: the box image's agentrun-tool, no sudo. */
|
|
12
12
|
export const TOOL_USER = "2510:2510";
|
|
13
13
|
/** Why a remote provider refuses network open or an allowlist, in words. */
|
|
14
14
|
export const OWN_NETWORK_ONLY = 'a remote computer takes network "none" only: its programs run in a network of their own, their loopback alone, so the vendor\'s agent in it (which runs commands as root) is out of their reach; open and allowlists wait for a proxy out of that network';
|
|
15
|
-
/** The interfaces /proc/<pid>/net/dev lists, in its order; undefined when the text is not that file. */
|
|
16
|
-
export function netDevInterfaces(text) {
|
|
17
|
-
const lines = text.split("\n");
|
|
18
|
-
if (!lines[0]?.startsWith("Inter-|") || !lines[1]?.includes("face |"))
|
|
19
|
-
return undefined;
|
|
20
|
-
const names = [];
|
|
21
|
-
for (const line of lines.slice(2)) {
|
|
22
|
-
if (line.trim() === "")
|
|
23
|
-
continue;
|
|
24
|
-
const at = line.indexOf(":");
|
|
25
|
-
if (at < 0)
|
|
26
|
-
return undefined;
|
|
27
|
-
names.push(line.slice(0, at).trim());
|
|
28
|
-
}
|
|
29
|
-
return names;
|
|
30
|
-
}
|
|
31
15
|
/**
|
|
32
16
|
* The drift of a computer's programs' network from their own loopback alone, in words: none when the live interfaces
|
|
33
17
|
* (up or addressed) of the daemon's network namespace are `lo` alone, else what they are (or that they could not be read).
|
|
@@ -58,7 +42,7 @@ export function probeOwnNetworkDrift(report) {
|
|
|
58
42
|
export async function readOwnNetwork(client, timeoutMs, signal) {
|
|
59
43
|
const ran = await client.call("exec.run", { argv: [DAEMON_IN_COMPUTER, "probe"], timeoutMs }, signal ? { signal } : undefined);
|
|
60
44
|
if (!ran.ok)
|
|
61
|
-
return
|
|
45
|
+
return failAs(ran.error, `reading the computer's own network back (computerd probe): ${ran.error.message}`);
|
|
62
46
|
const out = Buffer.from(ran.value.stdout, "base64").toString("utf8");
|
|
63
47
|
if (ran.value.exitCode !== 0)
|
|
64
48
|
return fail("refused", `computerd probe, reading the computer's own network back, exited ${ran.value.exitCode}: ${Buffer.from(ran.value.stderr, "base64").toString("utf8").trim().slice(0, 300)}`);
|
package/dist/janitor.d.ts
CHANGED
|
@@ -5,6 +5,11 @@ export interface SweepOptions {
|
|
|
5
5
|
labels?: Record<string, string>;
|
|
6
6
|
/** The time to compare deadlines with; default now. */
|
|
7
7
|
now?: Date;
|
|
8
|
+
/**
|
|
9
|
+
* Whether an agent is gone, by its id: the caller's answer (serve's agents). An agent's computer whose owner is gone
|
|
10
|
+
* is deleted; without this, no agent counts as gone.
|
|
11
|
+
*/
|
|
12
|
+
ownerGone?: (agent: string) => boolean | Promise<boolean>;
|
|
8
13
|
signal?: AbortSignal;
|
|
9
14
|
}
|
|
10
15
|
export interface Swept {
|
|
@@ -22,11 +27,20 @@ export interface Swept {
|
|
|
22
27
|
* "janitor"; a caller runs it on a schedule. A computer that cannot be deleted does not stop the sweep: the result is
|
|
23
28
|
* then an error naming it and what was deleted. A provider with sweepLeftovers then removes, with the same labels and
|
|
24
29
|
* time, what its computers left behind (Docker: egress proxies and volumes whose computer is gone).
|
|
30
|
+
*
|
|
31
|
+
* An agent's computer (an owner label, or an info the provider marks owned, of a provider that declares persistence: of
|
|
32
|
+
* one that does not, an owner label is a caller's and keeps nothing) is never deleted by a deadline: only when
|
|
33
|
+
* its owner is gone (ownerGone), or once it has been detached for longer than its owner's idle TTL. One whose owner
|
|
34
|
+
* the janitor cannot read is kept. A
|
|
35
|
+
* provider that declares persistence is swept for its agents' computers alone under lifetime "vendor", since no vendor
|
|
36
|
+
* ends them.
|
|
25
37
|
*/
|
|
26
|
-
export declare function sweep(provider: ComputerProvider, { labels, now, signal }?: SweepOptions): Promise<Result<Swept>>;
|
|
38
|
+
export declare function sweep(provider: ComputerProvider, { labels, now, ownerGone, signal }?: SweepOptions): Promise<Result<Swept>>;
|
|
27
39
|
export interface ReleasedOlder {
|
|
28
40
|
/** The run's computers deleted: each with a lower epoch, and each that carries no epoch it can read. */
|
|
29
41
|
released: ComputerRef[];
|
|
42
|
+
/** The agents' computers among them, detached instead of deleted: their state kept for the claim to attach. */
|
|
43
|
+
detached: ComputerRef[];
|
|
30
44
|
/** The run's computers of this very epoch, left as they are. */
|
|
31
45
|
kept: ComputerRef[];
|
|
32
46
|
/** Of those released, each whose epoch label was missing or not an epoch, with what was wrong: it could not prove it is current. */
|
|
@@ -46,5 +60,8 @@ export interface ReleasedOlder {
|
|
|
46
60
|
* released: a partial cleanup is never a success, so a caller revokes nothing and mounts nothing after it. An aborted
|
|
47
61
|
* call starts no further release and says which ran. It revokes no mount: that is the root helper's, inside the
|
|
48
62
|
* computer, and a deleted computer holds none.
|
|
63
|
+
*
|
|
64
|
+
* An agent's computer (an owner label, readable or not, or an info marked owned, of a provider that declares
|
|
65
|
+
* persistence) of a lower epoch is detached, never deleted: its state is the agent's, and the new claim attaches it.
|
|
49
66
|
*/
|
|
50
67
|
export declare function releaseOlder(provider: ComputerProvider, run: string, epoch: number, { signal }?: CallContext): Promise<Result<ReleasedOlder>>;
|
package/dist/janitor.js
CHANGED
|
@@ -1,9 +1,39 @@
|
|
|
1
1
|
// The janitor: ends computers whose deadline has passed, for a provider whose vendor does not end them itself; and, on a
|
|
2
2
|
// takeover, the run's computers of an older claim.
|
|
3
|
-
import { epochOf, epochProblem, RUN_LABEL, runProblem } from "./labels.js";
|
|
4
|
-
import { fail, ok } from "./result.js";
|
|
3
|
+
import { epochOf, epochProblem, ownerOf, RUN_LABEL, runProblem } from "./labels.js";
|
|
4
|
+
import { fail, failAs, ok } from "./result.js";
|
|
5
5
|
/** Clock skew a deadline may carry past now + maxLifetimeMs before it counts as unreadable. */
|
|
6
6
|
const SKEW_MS = 60_000;
|
|
7
|
+
/** Whether a run's computer's deadline is ahead of at, and readable: no later than at + cap. */
|
|
8
|
+
const alive = (deadline, at, cap) => {
|
|
9
|
+
const time = deadline instanceof Date ? deadline.getTime() : Number.NaN;
|
|
10
|
+
return !Number.isNaN(time) && time > at && time <= at + cap;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Whose a listed computer is. A provider that declares no persistence keeps no agent's computer, so all of its are runs',
|
|
14
|
+
* whatever their labels say: an owner label a caller put on a run's spec never keeps it from the janitor. Of a provider
|
|
15
|
+
* that declares persistence, an agent's: its owner label says so (an owner label that cannot be read too, with no owner
|
|
16
|
+
* known), or the provider marks it owned (its info's owned, with owner when the listing knows it). A run's otherwise.
|
|
17
|
+
*/
|
|
18
|
+
function tenureOf(info, persistence) {
|
|
19
|
+
if (persistence === undefined)
|
|
20
|
+
return { agent: false };
|
|
21
|
+
const label = ownerOf(info.labels);
|
|
22
|
+
if (!label.ok)
|
|
23
|
+
return { agent: true };
|
|
24
|
+
if (label.value !== undefined)
|
|
25
|
+
return { agent: true, owner: label.value };
|
|
26
|
+
if (info.owned === true)
|
|
27
|
+
return { agent: true, ...(info.owner === undefined ? {} : { owner: info.owner }) };
|
|
28
|
+
return { agent: false };
|
|
29
|
+
}
|
|
30
|
+
/** Whether an agent's computer ends: its owner is gone, or it has been detached for longer than its idle TTL. */
|
|
31
|
+
async function ownerEnds(info, owner, at, ownerGone) {
|
|
32
|
+
if (ownerGone !== undefined && (await ownerGone(owner.agent)) === true)
|
|
33
|
+
return true;
|
|
34
|
+
const since = info.detachedAt instanceof Date ? info.detachedAt.getTime() : Number.NaN;
|
|
35
|
+
return owner.idleTtlMs !== undefined && !Number.isNaN(since) && at - since >= owner.idleTtlMs;
|
|
36
|
+
}
|
|
7
37
|
/**
|
|
8
38
|
* Deletes every computer the provider lists whose deadline has passed, or whose deadline is missing or unreadable
|
|
9
39
|
* (fail closed); leaves the rest. A deadline more than the provider's maxLifetimeMs past now (with a minute for clock
|
|
@@ -11,10 +41,17 @@ const SKEW_MS = 60_000;
|
|
|
11
41
|
* "janitor"; a caller runs it on a schedule. A computer that cannot be deleted does not stop the sweep: the result is
|
|
12
42
|
* then an error naming it and what was deleted. A provider with sweepLeftovers then removes, with the same labels and
|
|
13
43
|
* time, what its computers left behind (Docker: egress proxies and volumes whose computer is gone).
|
|
44
|
+
*
|
|
45
|
+
* An agent's computer (an owner label, or an info the provider marks owned, of a provider that declares persistence: of
|
|
46
|
+
* one that does not, an owner label is a caller's and keeps nothing) is never deleted by a deadline: only when
|
|
47
|
+
* its owner is gone (ownerGone), or once it has been detached for longer than its owner's idle TTL. One whose owner
|
|
48
|
+
* the janitor cannot read is kept. A
|
|
49
|
+
* provider that declares persistence is swept for its agents' computers alone under lifetime "vendor", since no vendor
|
|
50
|
+
* ends them.
|
|
14
51
|
*/
|
|
15
|
-
export async function sweep(provider, { labels = {}, now, signal } = {}) {
|
|
16
|
-
const { lifetime, maxLifetimeMs } = provider.capabilities();
|
|
17
|
-
if (lifetime !== "janitor") {
|
|
52
|
+
export async function sweep(provider, { labels = {}, now, ownerGone, signal } = {}) {
|
|
53
|
+
const { lifetime, maxLifetimeMs, persistence } = provider.capabilities();
|
|
54
|
+
if (lifetime !== "janitor" && persistence === undefined) {
|
|
18
55
|
return fail("refused", `the ${provider.id} provider declares lifetime "${lifetime}": its vendor ends its computers itself, so the janitor does not sweep them`);
|
|
19
56
|
}
|
|
20
57
|
if (now !== undefined && !(now instanceof Date && !Number.isNaN(now.getTime())))
|
|
@@ -31,9 +68,13 @@ export async function sweep(provider, { labels = {}, now, signal } = {}) {
|
|
|
31
68
|
const failed = [];
|
|
32
69
|
let firstError;
|
|
33
70
|
let kept = 0;
|
|
34
|
-
for (const
|
|
35
|
-
const
|
|
36
|
-
|
|
71
|
+
for (const info of listed.value) {
|
|
72
|
+
const { ref, deadline } = info;
|
|
73
|
+
const tenure = tenureOf(info, persistence);
|
|
74
|
+
// An agent's computer goes by its owner's rules, never a deadline: one whose owner the janitor cannot read is kept.
|
|
75
|
+
// A run's goes by its deadline, and under lifetime "vendor" its vendor ends it.
|
|
76
|
+
const ends = tenure.agent ? tenure.owner !== undefined && (await ownerEnds(info, tenure.owner, at, ownerGone)) : lifetime === "janitor" && !alive(deadline, at, cap);
|
|
77
|
+
if (!ends) {
|
|
37
78
|
kept++;
|
|
38
79
|
continue;
|
|
39
80
|
}
|
|
@@ -64,7 +105,7 @@ export async function sweep(provider, { labels = {}, now, signal } = {}) {
|
|
|
64
105
|
}
|
|
65
106
|
if (firstError) {
|
|
66
107
|
const words = [...(failed.length > 0 ? [`could not delete ${failed.join("; ")}`] : []), ...(leftBehind === undefined ? [] : [`could not remove what its computers left behind: ${leftBehind}`])];
|
|
67
|
-
return
|
|
108
|
+
return failAs(firstError, `the sweep deleted ${deleted.join(", ") || "none"} but ${words.join(", and ")}`);
|
|
68
109
|
}
|
|
69
110
|
return ok({ deleted, kept, ...(leftovers === undefined ? {} : { leftovers }) });
|
|
70
111
|
}
|
|
@@ -79,6 +120,9 @@ export async function sweep(provider, { labels = {}, now, signal } = {}) {
|
|
|
79
120
|
* released: a partial cleanup is never a success, so a caller revokes nothing and mounts nothing after it. An aborted
|
|
80
121
|
* call starts no further release and says which ran. It revokes no mount: that is the root helper's, inside the
|
|
81
122
|
* computer, and a deleted computer holds none.
|
|
123
|
+
*
|
|
124
|
+
* An agent's computer (an owner label, readable or not, or an info marked owned, of a provider that declares
|
|
125
|
+
* persistence) of a lower epoch is detached, never deleted: its state is the agent's, and the new claim attaches it.
|
|
82
126
|
*/
|
|
83
127
|
export async function releaseOlder(provider, run, epoch, { signal } = {}) {
|
|
84
128
|
const problem = runProblem(run) ?? epochProblem(epoch);
|
|
@@ -89,21 +133,24 @@ export async function releaseOlder(provider, run, epoch, { signal } = {}) {
|
|
|
89
133
|
return fail("aborted", `${what} was aborted before it began`);
|
|
90
134
|
const listed = await provider.list({ [RUN_LABEL]: run }, { signal });
|
|
91
135
|
if (!listed.ok)
|
|
92
|
-
return
|
|
136
|
+
return failAs(listed.error, `could not list run ${JSON.stringify(run)}'s computers: ${listed.error.message}`);
|
|
137
|
+
const { persistence } = provider.capabilities();
|
|
93
138
|
const older = [];
|
|
94
139
|
const kept = [];
|
|
95
140
|
const unproven = [];
|
|
96
141
|
const newer = [];
|
|
97
|
-
for (const
|
|
142
|
+
for (const info of listed.value) {
|
|
143
|
+
const { ref, labels } = info;
|
|
98
144
|
if (labels?.[RUN_LABEL] !== run)
|
|
99
145
|
continue;
|
|
100
146
|
const read = epochOf(labels);
|
|
147
|
+
const owned = tenureOf(info, persistence).agent;
|
|
101
148
|
if (!read.ok) {
|
|
102
|
-
older.push({ ref });
|
|
149
|
+
older.push({ ref, owned });
|
|
103
150
|
unproven.push({ ref, problem: read.error.message });
|
|
104
151
|
}
|
|
105
152
|
else if (read.value < epoch)
|
|
106
|
-
older.push({ ref, epoch: read.value });
|
|
153
|
+
older.push({ ref, epoch: read.value, owned });
|
|
107
154
|
else if (read.value === epoch)
|
|
108
155
|
kept.push(ref);
|
|
109
156
|
else
|
|
@@ -113,23 +160,24 @@ export async function releaseOlder(provider, run, epoch, { signal } = {}) {
|
|
|
113
160
|
return fail("refused", `fenced: run ${JSON.stringify(run)} has ${newer.join(", ")}, above this claim's epoch ${epoch}; a later claim holds the run, so nothing was released`);
|
|
114
161
|
}
|
|
115
162
|
const released = [];
|
|
163
|
+
const detached = [];
|
|
116
164
|
const failed = [];
|
|
117
165
|
let firstError;
|
|
118
|
-
const done = () => `it released ${released.map((ref) => ref.name).join(", ") || "none"}${failed.length > 0 ? `, and could not release ${failed.join("; ")}` : ""}`;
|
|
119
|
-
for (const [at, { ref, epoch: was }] of older.entries()) {
|
|
166
|
+
const done = () => `it released ${released.map((ref) => ref.name).join(", ") || "none"}${detached.length > 0 ? `, detached the agents' ${detached.map((ref) => ref.name).join(", ")}` : ""}${failed.length > 0 ? `, and could not release ${failed.join("; ")}` : ""}`;
|
|
167
|
+
for (const [at, { ref, epoch: was, owned }] of older.entries()) {
|
|
120
168
|
if (signal?.aborted) {
|
|
121
169
|
const left = older.slice(at).map((one) => one.ref.name);
|
|
122
170
|
return fail("aborted", `${what} was aborted: ${done()}; it did not start ${left.join(", ")}`);
|
|
123
171
|
}
|
|
124
|
-
const result = await provider.release(ref, "delete");
|
|
172
|
+
const result = await provider.release(ref, owned ? "detach" : "delete");
|
|
125
173
|
if (result.ok)
|
|
126
|
-
released.push(ref);
|
|
174
|
+
(owned ? detached : released).push(ref);
|
|
127
175
|
else {
|
|
128
176
|
firstError ??= result.error;
|
|
129
177
|
failed.push(`${ref.name} (${was === undefined ? "no epoch" : `epoch ${was}`}): ${result.error.message}`);
|
|
130
178
|
}
|
|
131
179
|
}
|
|
132
180
|
if (firstError)
|
|
133
|
-
return
|
|
134
|
-
return ok({ released, kept, unproven });
|
|
181
|
+
return failAs(firstError, `${what} is incomplete: ${done()}`);
|
|
182
|
+
return ok({ released, detached, kept, unproven });
|
|
135
183
|
}
|
package/dist/kernel.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type BrowserStream, type ReleaseConfirm, type RestReply, type UrlStore } from "./browser.js";
|
|
2
2
|
import type { KindCapabilities } from "./kinds.js";
|
|
3
3
|
import type { MountKind } from "./mount.js";
|
|
4
|
-
import type
|
|
4
|
+
import { type AttachedComputer, type CallContext, type ComputerCapabilities, type ComputerConnection, type ComputerInfo, type ComputerProvider, type ComputerRef, type ComputerSpec, type CreatedComputer, type NetworkPolicy, type NetworkSpec, type Refusal, type ReleaseHow } from "./provider.js";
|
|
5
5
|
import { type Result } from "./result.js";
|
|
6
6
|
export declare const KERNEL_API_URL = "https://api.onkernel.com";
|
|
7
7
|
/** The domain a Kernel CDP URL is on (wss://<host>.kernel.sh:8443, read live 11-08; its API is onkernel.com): cdpUrlProblem holds it there. */
|
|
@@ -11,7 +11,7 @@ export declare const KERNEL_MIN_LIFETIME_MS = 10000;
|
|
|
11
11
|
export declare const KERNEL_MAX_LIFETIME_MS = 259200000;
|
|
12
12
|
/** A browser takes no mount. */
|
|
13
13
|
export declare const MOUNT: readonly MountKind[];
|
|
14
|
-
/** The one configuration it offers,
|
|
14
|
+
/** The one configuration it offers, its descriptor's: a browser with a CDP target and a live view. */
|
|
15
15
|
export declare const CAPABILITIES: readonly KindCapabilities[];
|
|
16
16
|
/** A browser as Kernel answers it; only what the provider reads. */
|
|
17
17
|
export interface KernelBrowser {
|
|
@@ -98,7 +98,7 @@ export declare class KernelProvider implements ComputerProvider {
|
|
|
98
98
|
*/
|
|
99
99
|
connect(ref: ComputerRef): Promise<Result<ComputerConnection>>;
|
|
100
100
|
/** Deletes the browser and waits until Kernel reads it as gone; one already deleted or unknown is released. */
|
|
101
|
-
release(ref: ComputerRef, how:
|
|
101
|
+
release(ref: ComputerRef, how: ReleaseHow, { signal }?: CallContext): Promise<Result<void>>;
|
|
102
102
|
/** The browser's live view, which takes input: a view-only one is refused, never handed over as one. */
|
|
103
103
|
stream(ref: ComputerRef, options?: {
|
|
104
104
|
viewOnly?: boolean;
|
package/dist/kernel.js
CHANGED
|
@@ -12,9 +12,14 @@
|
|
|
12
12
|
// connection closes, and sets no wall clock. So lifetimeMs is the longest a browser lives unwatched, at most Kernel's
|
|
13
13
|
// largest idle timeout (72 h), and list reads no deadline.
|
|
14
14
|
import { readFileSync } from "node:fs";
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
15
|
+
import { KERNEL } from "./descriptors/kernel.js";
|
|
16
|
+
import { BROWSER_IMAGE } from "./descriptors/shared.js";
|
|
17
|
+
import { cdpUrlProblem, browserClient, browserHello, BrowserVendorError, CREATE_LABEL, carries, causeOf, checkBrowser, createLabelValue, createUncertain, DEFAULT_CONFIRM, defaultSleep, httpsBase, idProblem, labelsOf, labelsProblem, memoryUrls, queryable, recoverCreate, releaseConfirmed, restCall, causedFail, vendorFailure, withoutCreateLabel, } from "./browser.js";
|
|
18
|
+
import { runLifetimeMs, } from "./provider.js";
|
|
19
|
+
import { failFor, ok, vendorFail } from "./result.js";
|
|
17
20
|
import { connectionError } from "./test-connection.js";
|
|
21
|
+
/** This module's failures: one with code vendor names Kernel. */
|
|
22
|
+
const fail = failFor("kernel");
|
|
18
23
|
const VERSION = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
|
|
19
24
|
const NAME = "Kernel";
|
|
20
25
|
export const KERNEL_API_URL = "https://api.onkernel.com";
|
|
@@ -27,9 +32,9 @@ export const KERNEL_MAX_LIFETIME_MS = 259_200_000;
|
|
|
27
32
|
/** The most pages a list reads before it fails rather than run on. */
|
|
28
33
|
const MAX_PAGES = 100;
|
|
29
34
|
/** A browser takes no mount. */
|
|
30
|
-
export const MOUNT =
|
|
31
|
-
/** The one configuration it offers,
|
|
32
|
-
export const CAPABILITIES =
|
|
35
|
+
export const MOUNT = KERNEL.mounts;
|
|
36
|
+
/** The one configuration it offers, its descriptor's: a browser with a CDP target and a live view. */
|
|
37
|
+
export const CAPABILITIES = KERNEL.capabilities;
|
|
33
38
|
/** Kernel's REST API over fetch: the default request. */
|
|
34
39
|
export function kernelRest({ apiKey, apiUrl = KERNEL_API_URL, fetch: fetcher = fetch }) {
|
|
35
40
|
const o = { vendor: NAME, fetch: fetcher, base: httpsBase(apiUrl, "the Kernel API URL"), headers: { Authorization: `Bearer ${apiKey}` } };
|
|
@@ -66,7 +71,7 @@ export class KernelProvider {
|
|
|
66
71
|
return {
|
|
67
72
|
kind: "browser",
|
|
68
73
|
lifetime: "vendor",
|
|
69
|
-
network: [
|
|
74
|
+
network: [...KERNEL.network],
|
|
70
75
|
isolation: "vm",
|
|
71
76
|
os: "linux",
|
|
72
77
|
daemon: "none",
|
|
@@ -89,7 +94,7 @@ export class KernelProvider {
|
|
|
89
94
|
if (signal?.aborted)
|
|
90
95
|
return fail("aborted", "create was aborted before Kernel was called");
|
|
91
96
|
const written = { [CREATE_LABEL]: createLabelValue(), ...spec.labels };
|
|
92
|
-
const body = { ...settings, timeout_seconds: Math.ceil(spec
|
|
97
|
+
const body = { ...settings, timeout_seconds: Math.ceil(runLifetimeMs(spec) / 1000), tags: written };
|
|
93
98
|
let made;
|
|
94
99
|
try {
|
|
95
100
|
made = await this.#request("POST", "/browsers", { body, ...(signal ? { signal } : {}) });
|
|
@@ -99,7 +104,7 @@ export class KernelProvider {
|
|
|
99
104
|
if (failed.ok || !createUncertain(error))
|
|
100
105
|
return failed;
|
|
101
106
|
// The browser may have been made though its answer never came: found by its create label, never made again.
|
|
102
|
-
return
|
|
107
|
+
return causedFail(failed.error.code, `${failed.error.message}; ${await this.#recover(written)}`, causeOf(failed), "kernel");
|
|
103
108
|
}
|
|
104
109
|
const browser = (made.json ?? {});
|
|
105
110
|
const id = text(browser.session_id);
|
|
@@ -114,7 +119,7 @@ export class KernelProvider {
|
|
|
114
119
|
if (unusable !== undefined) {
|
|
115
120
|
// The browser is made and billed until its idle timeout: deleted here, not left to a later sweep.
|
|
116
121
|
const released = await this.release(refOf(id), "delete");
|
|
117
|
-
return
|
|
122
|
+
return vendorFail("kernel", `Kernel POST /browsers made a browser with no CDP URL to hand over: ${unusable}; ${released.ok ? "the browser was released" : `the browser was not released (${released.error.code}), and its tags let a sweep find it`}`);
|
|
118
123
|
}
|
|
119
124
|
this.#urls.set(id, url);
|
|
120
125
|
const live = text(browser.browser_live_view_url);
|
|
@@ -153,9 +158,9 @@ export class KernelProvider {
|
|
|
153
158
|
return fail(reached ? connectionError(failed.error).code : "unreachable", failed.error.message);
|
|
154
159
|
}
|
|
155
160
|
if (page.status === 404)
|
|
156
|
-
return
|
|
161
|
+
return vendorFail("kernel", `Kernel ${call} answered 404: the API URL is not Kernel's`);
|
|
157
162
|
if (!Array.isArray(page.json))
|
|
158
|
-
return
|
|
163
|
+
return vendorFail("kernel", `Kernel ${call} answered ${page.status} (not_a_list)`);
|
|
159
164
|
const n = page.json.length;
|
|
160
165
|
const more = page.headers.get("x-has-more") === "true" ? " or more" : "";
|
|
161
166
|
return ok({ detail: `Kernel answered: ${n}${more} active ${n === 1 && more === "" ? "browser" : "browsers"} in the organization` });
|
|
@@ -250,10 +255,10 @@ export class KernelProvider {
|
|
|
250
255
|
return ok(found);
|
|
251
256
|
const next = Number(page.headers.get("x-next-offset"));
|
|
252
257
|
if (!Number.isInteger(next) || next <= offset)
|
|
253
|
-
return
|
|
258
|
+
return vendorFail("kernel", "Kernel reported more browsers without the next page's offset");
|
|
254
259
|
offset = next;
|
|
255
260
|
}
|
|
256
|
-
return
|
|
261
|
+
return vendorFail("kernel", `Kernel kept answering more pages of browsers past ${MAX_PAGES}`);
|
|
257
262
|
}
|
|
258
263
|
async list(labels, { signal } = {}) {
|
|
259
264
|
const found = await this.#browsers(labels, signal);
|
|
@@ -298,7 +303,7 @@ export class KernelProvider {
|
|
|
298
303
|
// Whatever held it (create, a read, a host's url store), a URL a driver would dial is wss: on Kernel's own domain.
|
|
299
304
|
const unusable = cdpUrlProblem(url, NAME, CDP_DOMAIN);
|
|
300
305
|
if (unusable !== undefined)
|
|
301
|
-
return
|
|
306
|
+
return vendorFail("kernel", `the Kernel browser ${id} is not handed over: ${unusable}`);
|
|
302
307
|
this.#urls.set(id, url);
|
|
303
308
|
const hello = browserHello(VERSION, this.capabilities().groups);
|
|
304
309
|
const client = browserClient(hello, (signal) => this.#alive(id, signal));
|
package/dist/kinds.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { DescriptorKey, DescriptorSetting, ParkedConfiguration, ProviderDescriptor } from "./descriptor.js";
|
|
1
2
|
import type { MountKind } from "./mount.js";
|
|
2
3
|
import type { ComputerKind, Group } from "./protocol.js";
|
|
3
|
-
import type { ComputerCapabilities } from "./provider.js";
|
|
4
|
+
import type { ComputerCapabilities, NetworkForm } from "./provider.js";
|
|
4
5
|
import type { Result } from "./result.js";
|
|
5
6
|
/**
|
|
6
7
|
* What an agent is given. none: the run's folder only, no computer. sandbox: a Linux shell with files and processes.
|
|
@@ -20,48 +21,73 @@ export interface SettingKindSpec {
|
|
|
20
21
|
export declare const SETTING_KINDS: Readonly<Record<ComputerSettingKind, SettingKindSpec>>;
|
|
21
22
|
/** Every setting kind, in the table's order. */
|
|
22
23
|
export declare const SETTING_KIND_NAMES: ComputerSettingKind[];
|
|
23
|
-
/**
|
|
24
|
-
|
|
24
|
+
/**
|
|
25
|
+
* The capabilities serves() and kindOf() read: one configuration a provider offers, with the GPUs it offers (Settings'
|
|
26
|
+
* GPU choice). In a descriptor, `image` is the name an agent's setting selects it by (Orgo's `windows`), the image its
|
|
27
|
+
* computer starts from, and `options` are what create() takes to build it ({ os: "windows" }), beside the keys. A
|
|
28
|
+
* configuration with no image is the one a setting that names none gets, as is the one whose image is the kind's
|
|
29
|
+
* defaultImage.
|
|
30
|
+
*/
|
|
31
|
+
export type KindCapabilities = Pick<ComputerCapabilities, "kind" | "groups" | "gpu"> & {
|
|
32
|
+
readonly image?: string;
|
|
33
|
+
readonly options?: Readonly<Record<string, unknown>>;
|
|
34
|
+
};
|
|
25
35
|
/** Why capabilities do not serve a setting kind, in words; none when they do. */
|
|
26
36
|
export declare function servingRefusals(capabilities: KindCapabilities, kind: ComputerSettingKind): string[];
|
|
27
37
|
/** Whether a provider with these capabilities serves the kind: its machine kind is one of the kind's, and it declares every required group. */
|
|
28
38
|
export declare function serves(capabilities: KindCapabilities, kind: ComputerSettingKind): boolean;
|
|
29
39
|
/** The setting kind these capabilities serve, or undefined when they serve none. Machine kinds are apart, so at most one. */
|
|
30
40
|
export declare function kindOf(capabilities: KindCapabilities): ComputerSettingKind | undefined;
|
|
31
|
-
/**
|
|
32
|
-
export
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
41
|
+
/** The images a kind's configurations offer by name (`serving`: those that serve it), the kind's default first when it is one. */
|
|
42
|
+
export declare function imagesOf(serving: readonly Pick<KindCapabilities, "image">[], defaultImage: string | undefined): string[];
|
|
43
|
+
/**
|
|
44
|
+
* The configuration a setting selects among a kind's (`serving`): the one its image names; with none named, the one
|
|
45
|
+
* whose image is the kind's default, else one with no image, else the first. Undefined when the image names none.
|
|
46
|
+
*/
|
|
47
|
+
export declare function configurationOf<Configuration extends Pick<KindCapabilities, "image">>(serving: readonly Configuration[], image: string | undefined, defaultImage: string | undefined): Configuration | undefined;
|
|
48
|
+
/** A provider as Settings shows it: its descriptor's data, and the setting kinds it serves. */
|
|
37
49
|
export interface ProviderEntry {
|
|
38
|
-
/** Its id: a line of the provider registry (providers.ts)
|
|
39
|
-
id: string;
|
|
40
|
-
label: string;
|
|
50
|
+
/** Its id: a line of the provider registry (providers.ts). */
|
|
51
|
+
readonly id: string;
|
|
52
|
+
readonly label: string;
|
|
41
53
|
/** Derived: the setting kinds its capabilities serve (serves), never written by hand. */
|
|
42
|
-
kinds: readonly ComputerSettingKind[];
|
|
43
|
-
/** The serve-side key names
|
|
44
|
-
keys: readonly
|
|
45
|
-
/**
|
|
46
|
-
|
|
47
|
-
/** The
|
|
48
|
-
|
|
54
|
+
readonly kinds: readonly ComputerSettingKind[];
|
|
55
|
+
/** The serve-side key names and the options they fill; never a value. */
|
|
56
|
+
readonly keys: readonly DescriptorKey[];
|
|
57
|
+
/** Settings that are no key but go to its options. */
|
|
58
|
+
readonly settings?: readonly DescriptorSetting[];
|
|
59
|
+
/** The mount kinds its computers take; [] cannot mount the run's folder. */
|
|
60
|
+
readonly mounts: readonly MountKind[];
|
|
49
61
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
62
|
+
* The network forms its computers make, its descriptor's: ["none"], a remote computer whose programs run in a network
|
|
63
|
+
* of their own; ["open"], the vendor's own network, which no allowlist of this server reaches; Docker's all three.
|
|
52
64
|
*/
|
|
53
|
-
|
|
65
|
+
readonly network: readonly NetworkForm[];
|
|
66
|
+
/** The vendor bills by time; prices are the vendor's page, not ours. */
|
|
67
|
+
readonly metered: boolean;
|
|
68
|
+
/** Its static capabilities: the machine kind and groups of each configuration it offers. */
|
|
69
|
+
readonly capabilities: readonly KindCapabilities[];
|
|
54
70
|
/**
|
|
55
|
-
* The image a computer of each setting kind starts from when its setting names none
|
|
56
|
-
*
|
|
57
|
-
* none: serve builds its image itself (DOCKER_RECIPE).
|
|
71
|
+
* The image a computer of each setting kind starts from when its setting names none. A kind with no entry has no
|
|
72
|
+
* default, and the caller refuses the setting in words. Docker's sandbox has none: its image is made (prepareImage).
|
|
58
73
|
*/
|
|
59
|
-
defaultImage?: Partial<Record<ComputerSettingKind, string>>;
|
|
74
|
+
readonly defaultImage?: Partial<Record<ComputerSettingKind, string>>;
|
|
75
|
+
/** Its built providers make or pull their image before the first create (prepareImage()). */
|
|
76
|
+
readonly prepareImage?: boolean;
|
|
77
|
+
/** Its computers run on this machine's container engine. */
|
|
78
|
+
readonly local?: boolean;
|
|
79
|
+
/** create() takes a ledger the server keeps for it, as this option. */
|
|
80
|
+
readonly ledger?: {
|
|
81
|
+
readonly option: string;
|
|
82
|
+
};
|
|
83
|
+
/** The server's environment variables its provider reads on this machine, passed as options.env (descriptor.ts). */
|
|
84
|
+
readonly hostEnv?: readonly string[];
|
|
85
|
+
/** Configurations it builds but does not offer yet, each with why: a setting naming one's image is refused as parked. */
|
|
86
|
+
readonly parked?: readonly ParkedConfiguration[];
|
|
60
87
|
}
|
|
61
|
-
/**
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
*/
|
|
88
|
+
/** A descriptor as Settings shows it: its data, and the setting kinds its capabilities serve, derived by serves(). */
|
|
89
|
+
export declare function entryOf(descriptor: ProviderDescriptor): ProviderEntry;
|
|
90
|
+
/** Every provider Settings offers: each built-in descriptor (descriptors/index.ts), as entryOf gives it. */
|
|
65
91
|
export declare const PROVIDERS: readonly ProviderEntry[];
|
|
66
92
|
/** What testConnection is given: the provider's keys by their serve-side names, and the caller's signal. */
|
|
67
93
|
export interface TestConnectionOptions {
|