@parcha/agentrun-computer 0.1.0-beta.34 → 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.
Files changed (99) hide show
  1. package/README.md +144 -26
  2. package/dist/browser.d.ts +12 -13
  3. package/dist/browser.js +16 -14
  4. package/dist/browserbase.d.ts +3 -5
  5. package/dist/browserbase.js +16 -13
  6. package/dist/chrome.js +1 -1
  7. package/dist/computerd-linux-amd64 +0 -0
  8. package/dist/computerd-linux-arm64 +0 -0
  9. package/dist/conformance/browserbase.js +1 -1
  10. package/dist/conformance/cases/provider.js +78 -3
  11. package/dist/conformance/daytona.js +2 -1
  12. package/dist/conformance/e2b.js +2 -1
  13. package/dist/conformance/fixture.js +24 -2
  14. package/dist/conformance/kernel.js +1 -1
  15. package/dist/conformance/kind.js +2 -1
  16. package/dist/conformance/{local.d.ts → local-chrome.d.ts} +7 -7
  17. package/dist/conformance/{local.js → local-chrome.js} +11 -11
  18. package/dist/conformance/orgo.d.ts +11 -5
  19. package/dist/conformance/orgo.js +37 -8
  20. package/dist/conformance/phone-harness.js +2 -1
  21. package/dist/conformance/report.js +3 -2
  22. package/dist/conformance/runner.js +25 -7
  23. package/dist/conformance/types.d.ts +21 -8
  24. package/dist/conformance/types.js +10 -0
  25. package/dist/conformance/windows-fixture.d.ts +1 -0
  26. package/dist/conformance/windows-fixture.js +37 -0
  27. package/dist/daytona.d.ts +3 -34
  28. package/dist/daytona.js +34 -61
  29. package/dist/descriptor.d.ts +94 -0
  30. package/dist/descriptor.js +81 -0
  31. package/dist/descriptors/browserbase.d.ts +24 -0
  32. package/dist/descriptors/browserbase.js +18 -0
  33. package/dist/descriptors/daytona.d.ts +62 -0
  34. package/dist/descriptors/daytona.js +49 -0
  35. package/dist/descriptors/docker.d.ts +12 -0
  36. package/dist/descriptors/docker.js +17 -0
  37. package/dist/descriptors/e2b.d.ts +22 -0
  38. package/dist/descriptors/e2b.js +19 -0
  39. package/dist/descriptors/index.d.ts +229 -0
  40. package/dist/descriptors/index.js +19 -0
  41. package/dist/descriptors/kernel.d.ts +20 -0
  42. package/dist/descriptors/kernel.js +15 -0
  43. package/dist/descriptors/local-chrome.d.ts +17 -0
  44. package/dist/descriptors/local-chrome.js +21 -0
  45. package/dist/descriptors/modal.d.ts +50 -0
  46. package/dist/descriptors/modal.js +38 -0
  47. package/dist/descriptors/orgo.d.ts +88 -0
  48. package/dist/descriptors/orgo.js +44 -0
  49. package/dist/descriptors/phone-harness.d.ts +28 -0
  50. package/dist/descriptors/phone-harness.js +20 -0
  51. package/dist/descriptors/shared.d.ts +7 -0
  52. package/dist/descriptors/shared.js +6 -0
  53. package/dist/desktop.d.ts +4 -4
  54. package/dist/desktop.js +4 -4
  55. package/dist/docker/egress.d.ts +1 -1
  56. package/dist/docker/image.js +17 -15
  57. package/dist/docker/inspect.d.ts +147 -0
  58. package/dist/docker/inspect.js +335 -0
  59. package/dist/docker.d.ts +6 -6
  60. package/dist/docker.js +46 -42
  61. package/dist/drift.d.ts +3 -145
  62. package/dist/drift.js +5 -334
  63. package/dist/e2b.d.ts +2 -8
  64. package/dist/e2b.js +16 -22
  65. package/dist/index.d.ts +8 -11
  66. package/dist/index.js +13 -11
  67. package/dist/isolation.js +2 -2
  68. package/dist/janitor.d.ts +18 -1
  69. package/dist/janitor.js +67 -19
  70. package/dist/kernel.d.ts +3 -5
  71. package/dist/kernel.js +19 -16
  72. package/dist/kinds.d.ts +54 -34
  73. package/dist/kinds.js +19 -117
  74. package/dist/labels.d.ts +12 -0
  75. package/dist/labels.js +39 -1
  76. package/dist/{local.d.ts → local-chrome.d.ts} +5 -8
  77. package/dist/{local.js → local-chrome.js} +19 -16
  78. package/dist/local-supervisor.d.ts +3 -3
  79. package/dist/local-supervisor.js +3 -3
  80. package/dist/modal.d.ts +3 -22
  81. package/dist/modal.js +15 -31
  82. package/dist/mount-archil.js +4 -4
  83. package/dist/orgo-channel.js +16 -13
  84. package/dist/orgo-desktop.d.ts +153 -0
  85. package/dist/orgo-desktop.js +1614 -0
  86. package/dist/orgo-names.d.ts +52 -0
  87. package/dist/orgo-names.js +84 -0
  88. package/dist/orgo.d.ts +18 -15
  89. package/dist/orgo.js +46 -107
  90. package/dist/phone-harness.d.ts +4 -10
  91. package/dist/phone-harness.js +45 -46
  92. package/dist/provider.d.ts +91 -10
  93. package/dist/provider.js +42 -0
  94. package/dist/providers.d.ts +23 -24
  95. package/dist/providers.js +14 -17
  96. package/dist/result.d.ts +11 -1
  97. package/dist/result.js +11 -0
  98. package/dist/test-connection.js +2 -2
  99. package/package.json +42 -2
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 { ref, deadline } of listed.value) {
35
- const time = deadline instanceof Date ? deadline.getTime() : Number.NaN;
36
- if (!Number.isNaN(time) && time > at && time <= at + cap) {
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 fail(firstError.code, `the sweep deleted ${deleted.join(", ") || "none"} but ${words.join(", and ")}`);
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 fail(listed.error.code, `could not list run ${JSON.stringify(run)}'s computers: ${listed.error.message}`);
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 { ref, labels } of listed.value) {
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 fail(firstError.code, `${what} is incomplete: ${done()}`);
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 { AttachedComputer, CallContext, ComputerCapabilities, ComputerConnection, ComputerInfo, ComputerProvider, ComputerRef, ComputerSpec, CreatedComputer, NetworkForm, NetworkPolicy, NetworkSpec, Refusal } from "./provider.js";
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,9 +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 network a Kernel browser runs on: Kernel's own, open; it cannot be closed or narrowed. */
15
- export declare const NETWORK: readonly NetworkForm[];
16
- /** The one configuration it offers, the kind registry's entry (kinds.ts): a browser with a CDP target and a live view. */
14
+ /** The one configuration it offers, its descriptor's: a browser with a CDP target and a live view. */
17
15
  export declare const CAPABILITIES: readonly KindCapabilities[];
18
16
  /** A browser as Kernel answers it; only what the provider reads. */
19
17
  export interface KernelBrowser {
@@ -100,7 +98,7 @@ export declare class KernelProvider implements ComputerProvider {
100
98
  */
101
99
  connect(ref: ComputerRef): Promise<Result<ComputerConnection>>;
102
100
  /** Deletes the browser and waits until Kernel reads it as gone; one already deleted or unknown is released. */
103
- release(ref: ComputerRef, how: "stop" | "delete", { signal }?: CallContext): Promise<Result<void>>;
101
+ release(ref: ComputerRef, how: ReleaseHow, { signal }?: CallContext): Promise<Result<void>>;
104
102
  /** The browser's live view, which takes input: a view-only one is refused, never handed over as one. */
105
103
  stream(ref: ComputerRef, options?: {
106
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 { cdpUrlProblem, BROWSER_IMAGE, browserClient, browserHello, BrowserVendorError, CREATE_LABEL, carries, causeOf, checkBrowser, createLabelValue, createUncertain, DEFAULT_CONFIRM, defaultSleep, httpsBase, idProblem, labelsOf, labelsProblem, memoryUrls, queryable, recoverCreate, releaseConfirmed, restCall, vendorFail, vendorFailure, withoutCreateLabel, } from "./browser.js";
16
- import { fail, ok } from "./result.js";
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,11 +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 network a Kernel browser runs on: Kernel's own, open; it cannot be closed or narrowed. */
32
- export const NETWORK = ["open"];
33
- /** The one configuration it offers, the kind registry's entry (kinds.ts): a browser with a CDP target and a live view. */
34
- export const CAPABILITIES = [{ kind: "browser", groups: ["cdp", "stream"] }];
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;
35
38
  /** Kernel's REST API over fetch: the default request. */
36
39
  export function kernelRest({ apiKey, apiUrl = KERNEL_API_URL, fetch: fetcher = fetch }) {
37
40
  const o = { vendor: NAME, fetch: fetcher, base: httpsBase(apiUrl, "the Kernel API URL"), headers: { Authorization: `Bearer ${apiKey}` } };
@@ -68,7 +71,7 @@ export class KernelProvider {
68
71
  return {
69
72
  kind: "browser",
70
73
  lifetime: "vendor",
71
- network: [...NETWORK],
74
+ network: [...KERNEL.network],
72
75
  isolation: "vm",
73
76
  os: "linux",
74
77
  daemon: "none",
@@ -91,7 +94,7 @@ export class KernelProvider {
91
94
  if (signal?.aborted)
92
95
  return fail("aborted", "create was aborted before Kernel was called");
93
96
  const written = { [CREATE_LABEL]: createLabelValue(), ...spec.labels };
94
- const body = { ...settings, timeout_seconds: Math.ceil(spec.lifetimeMs / 1000), tags: written };
97
+ const body = { ...settings, timeout_seconds: Math.ceil(runLifetimeMs(spec) / 1000), tags: written };
95
98
  let made;
96
99
  try {
97
100
  made = await this.#request("POST", "/browsers", { body, ...(signal ? { signal } : {}) });
@@ -101,7 +104,7 @@ export class KernelProvider {
101
104
  if (failed.ok || !createUncertain(error))
102
105
  return failed;
103
106
  // The browser may have been made though its answer never came: found by its create label, never made again.
104
- return vendorFail(failed.error.code, `${failed.error.message}; ${await this.#recover(written)}`, causeOf(failed));
107
+ return causedFail(failed.error.code, `${failed.error.message}; ${await this.#recover(written)}`, causeOf(failed), "kernel");
105
108
  }
106
109
  const browser = (made.json ?? {});
107
110
  const id = text(browser.session_id);
@@ -116,7 +119,7 @@ export class KernelProvider {
116
119
  if (unusable !== undefined) {
117
120
  // The browser is made and billed until its idle timeout: deleted here, not left to a later sweep.
118
121
  const released = await this.release(refOf(id), "delete");
119
- return fail("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`}`);
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`}`);
120
123
  }
121
124
  this.#urls.set(id, url);
122
125
  const live = text(browser.browser_live_view_url);
@@ -155,9 +158,9 @@ export class KernelProvider {
155
158
  return fail(reached ? connectionError(failed.error).code : "unreachable", failed.error.message);
156
159
  }
157
160
  if (page.status === 404)
158
- return fail("kernel", `Kernel ${call} answered 404: the API URL is not Kernel's`);
161
+ return vendorFail("kernel", `Kernel ${call} answered 404: the API URL is not Kernel's`);
159
162
  if (!Array.isArray(page.json))
160
- return fail("kernel", `Kernel ${call} answered ${page.status} (not_a_list)`);
163
+ return vendorFail("kernel", `Kernel ${call} answered ${page.status} (not_a_list)`);
161
164
  const n = page.json.length;
162
165
  const more = page.headers.get("x-has-more") === "true" ? " or more" : "";
163
166
  return ok({ detail: `Kernel answered: ${n}${more} active ${n === 1 && more === "" ? "browser" : "browsers"} in the organization` });
@@ -252,10 +255,10 @@ export class KernelProvider {
252
255
  return ok(found);
253
256
  const next = Number(page.headers.get("x-next-offset"));
254
257
  if (!Number.isInteger(next) || next <= offset)
255
- return fail("kernel", "Kernel reported more browsers without the next page's offset");
258
+ return vendorFail("kernel", "Kernel reported more browsers without the next page's offset");
256
259
  offset = next;
257
260
  }
258
- return fail("kernel", `Kernel kept answering more pages of browsers past ${MAX_PAGES}`);
261
+ return vendorFail("kernel", `Kernel kept answering more pages of browsers past ${MAX_PAGES}`);
259
262
  }
260
263
  async list(labels, { signal } = {}) {
261
264
  const found = await this.#browsers(labels, signal);
@@ -300,7 +303,7 @@ export class KernelProvider {
300
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.
301
304
  const unusable = cdpUrlProblem(url, NAME, CDP_DOMAIN);
302
305
  if (unusable !== undefined)
303
- return fail("kernel", `the Kernel browser ${id} is not handed over: ${unusable}`);
306
+ return vendorFail("kernel", `the Kernel browser ${id} is not handed over: ${unusable}`);
304
307
  this.#urls.set(id, url);
305
308
  const hello = browserHello(VERSION, this.capabilities().groups);
306
309
  const client = browserClient(hello, (signal) => this.#alive(id, signal));
package/dist/kinds.d.ts CHANGED
@@ -1,3 +1,4 @@
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
4
  import type { ComputerCapabilities, NetworkForm } from "./provider.js";
@@ -20,54 +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
- /** The capabilities serves() and kindOf() read, and the GPUs a configuration offers (Settings' GPU choice). */
24
- export type KindCapabilities = Pick<ComputerCapabilities, "kind" | "groups" | "gpu">;
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
- /** One key a provider takes in Settings: its serve-side name (Settings accepts only these), and whether it is needed. */
32
- export interface ProviderKey {
33
- name: string;
34
- required: boolean;
35
- }
36
- /** A provider as Settings shows it. */
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) once its file lands. */
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 only; never a value. */
44
- keys: readonly ProviderKey[];
45
- /** The mount kinds its computers take; [] cannot mount the run's folder. Its module's MOUNT, once its file lands. */
46
- mounts: readonly MountKind[];
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[];
47
61
  /**
48
- * The network forms its computers make: its module's NETWORK, which its capabilities().network returns. ["none"]: a
49
- * remote computer whose programs run in a network of their own; ["open"]: the vendor's own network, which no
50
- * allowlist of this server reaches; Docker's makes all three.
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.
51
64
  */
52
- network: readonly NetworkForm[];
65
+ readonly network: readonly NetworkForm[];
53
66
  /** The vendor bills by time; prices are the vendor's page, not ours. */
54
- metered: boolean;
67
+ readonly metered: boolean;
68
+ /** Its static capabilities: the machine kind and groups of each configuration it offers. */
69
+ readonly capabilities: readonly KindCapabilities[];
55
70
  /**
56
- * Its static capabilities: the machine kind and groups of each configuration it offers. Its module's CAPABILITIES,
57
- * once its file lands, and each built configuration's capabilities().
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
- capabilities: readonly KindCapabilities[];
60
- /**
61
- * The image a computer of each setting kind starts from when its setting names none, each the constant its provider
62
- * module owns. A kind with no entry has no default, and the caller refuses the setting in words. Docker's sandbox has
63
- * none: serve builds its image itself (DOCKER_RECIPE).
64
- */
65
- 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[];
66
87
  }
67
- /**
68
- * Every provider Settings offers, each with its provider file in the registry;
69
- * a unit test then holds each to its module (CAPABILITIES, MOUNT, NETWORK). daytona, modal and e2b take archil mounts.
70
- */
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. */
71
91
  export declare const PROVIDERS: readonly ProviderEntry[];
72
92
  /** What testConnection is given: the provider's keys by their serve-side names, and the caller's signal. */
73
93
  export interface TestConnectionOptions {
package/dist/kinds.js CHANGED
@@ -1,17 +1,4 @@
1
- // The kind registry: the computer an agent is given, its setting kind, and the providers Settings offers for it. Two
2
- // axes: the machine kind is the protocol's (capabilities().kind, KIND_SHAPES); the setting kind is what an agent is
3
- // given in Settings, `computer: { kind, provider? }`, as machine kinds and capability groups. Whether a provider serves
4
- // a setting kind is computed from its capabilities alone (serves), never kept beside them: a provider that drops a
5
- // group stops serving the kind. The model's tools are not here: they live in the kernel's tool registry, keyed by
6
- // these groups.
7
- // The default images are values: each from the provider module that owns it. Those modules import this one for types
8
- // alone, so this is no import cycle.
9
- import { BROWSER_IMAGE } from "./browser.js";
10
- import { DAYTONA_DEFAULT_SNAPSHOT, DAYTONA_GPU } from "./daytona.js";
11
- import { E2B_BASE_TEMPLATE, E2B_DESKTOP_TEMPLATE } from "./e2b.js";
12
- import { MODAL_DEFAULT_IMAGE, MODAL_GPU } from "./modal.js";
13
- import { ORGO_BASE_IMAGE } from "./orgo.js";
14
- import { PHONE_IMAGE } from "./phone-harness.js";
1
+ import { DESCRIPTORS } from "./descriptors/index.js";
15
2
  export const SETTING_KINDS = {
16
3
  none: { machineKinds: [], required: [], optional: [] },
17
4
  sandbox: { machineKinds: ["linux"], required: ["exec", "files", "processes"], optional: [] },
@@ -45,109 +32,24 @@ export function serves(capabilities, kind) {
45
32
  export function kindOf(capabilities) {
46
33
  return SETTING_KIND_NAMES.find((kind) => serves(capabilities, kind));
47
34
  }
48
- const SANDBOX = { kind: "linux", groups: ["exec", "files", "processes"] };
49
- const LINUX_DESKTOP = { kind: "desktop", groups: ["exec", "files", "processes", "screen", "input.pointer", "input.keys"] };
50
- /** A provider's GPU capability as its configuration carries it: a deep copy of the module's own. */
51
- const gpuOf = (gpu) => structuredClone(gpu);
52
- /** An entry with its kinds derived from its capabilities. */
53
- function entry(fields) {
54
- return { ...fields, kinds: SETTING_KIND_NAMES.filter((kind) => fields.capabilities.some((one) => serves(one, kind))) };
35
+ /** The images a kind's configurations offer by name (`serving`: those that serve it), the kind's default first when it is one. */
36
+ export function imagesOf(serving, defaultImage) {
37
+ const names = [...new Set(serving.flatMap((one) => (one.image === undefined ? [] : [one.image])))];
38
+ return defaultImage !== undefined && names.includes(defaultImage) ? [defaultImage, ...names.filter((name) => name !== defaultImage)] : names;
55
39
  }
56
40
  /**
57
- * Every provider Settings offers, each with its provider file in the registry;
58
- * a unit test then holds each to its module (CAPABILITIES, MOUNT, NETWORK). daytona, modal and e2b take archil mounts.
41
+ * The configuration a setting selects among a kind's (`serving`): the one its image names; with none named, the one
42
+ * whose image is the kind's default, else one with no image, else the first. Undefined when the image names none.
59
43
  */
60
- export const PROVIDERS = [
61
- entry({ id: "docker", label: "Docker", keys: [], mounts: ["bind"], network: ["none", "open", "allow"], metered: false, capabilities: [SANDBOX, LINUX_DESKTOP] }),
62
- entry({
63
- id: "daytona",
64
- label: "Daytona",
65
- keys: [
66
- { name: "DAYTONA_API_KEY", required: true },
67
- { name: "DAYTONA_API_URL", required: false },
68
- { name: "DAYTONA_TARGET", required: false },
69
- ],
70
- mounts: ["archil"],
71
- network: ["none"],
72
- metered: true,
73
- capabilities: [{ ...SANDBOX, gpu: gpuOf(DAYTONA_GPU) }],
74
- defaultImage: { sandbox: DAYTONA_DEFAULT_SNAPSHOT },
75
- }),
76
- entry({
77
- id: "modal",
78
- label: "Modal",
79
- keys: [
80
- { name: "MODAL_TOKEN_ID", required: true },
81
- { name: "MODAL_TOKEN_SECRET", required: true },
82
- ],
83
- mounts: ["archil"],
84
- network: ["none"],
85
- metered: true,
86
- capabilities: [{ ...SANDBOX, gpu: gpuOf(MODAL_GPU) }],
87
- defaultImage: { sandbox: MODAL_DEFAULT_IMAGE },
88
- }),
89
- entry({
90
- id: "e2b",
91
- label: "E2B",
92
- keys: [{ name: "E2B_API_KEY", required: true }],
93
- mounts: ["archil"],
94
- network: ["none"],
95
- metered: true,
96
- capabilities: [SANDBOX, LINUX_DESKTOP],
97
- defaultImage: { sandbox: E2B_BASE_TEMPLATE, desktop: E2B_DESKTOP_TEMPLATE },
98
- }),
99
- entry({
100
- id: "orgo",
101
- label: "Orgo",
102
- keys: [{ name: "ORGO_API_KEY", required: true }],
103
- mounts: [],
104
- network: ["none"],
105
- metered: true,
106
- capabilities: [LINUX_DESKTOP],
107
- defaultImage: { desktop: ORGO_BASE_IMAGE },
108
- }),
109
- entry({
110
- id: "phone-harness",
111
- label: "Phone harness",
112
- keys: [{ name: "PHONE_HARNESS_API_KEY", required: true }],
113
- mounts: [],
114
- network: ["open"],
115
- metered: true,
116
- capabilities: [{ kind: "android", groups: ["screen", "input.touch", "input.keys", "apps", "apps.ui_tree"] }],
117
- defaultImage: { phone: PHONE_IMAGE },
118
- }),
119
- entry({
120
- id: "browserbase",
121
- label: "Browserbase",
122
- keys: [
123
- { name: "BROWSERBASE_API_KEY", required: true },
124
- { name: "BROWSERBASE_PROJECT_ID", required: true },
125
- ],
126
- mounts: [],
127
- network: ["open"],
128
- metered: true,
129
- capabilities: [{ kind: "browser", groups: ["cdp", "stream"] }],
130
- defaultImage: { browser: BROWSER_IMAGE },
131
- }),
132
- entry({
133
- id: "kernel",
134
- label: "Kernel",
135
- keys: [{ name: "KERNEL_API_KEY", required: true }],
136
- mounts: [],
137
- network: ["open"],
138
- metered: true,
139
- capabilities: [{ kind: "browser", groups: ["cdp", "stream"] }],
140
- defaultImage: { browser: BROWSER_IMAGE },
141
- }),
142
- // This machine's Chrome: no key, nothing billed, no live view (a person watching runs it headed).
143
- entry({
144
- id: "local",
145
- label: "Local Chrome",
146
- keys: [],
147
- mounts: [],
148
- network: ["open", "allow"],
149
- metered: false,
150
- capabilities: [{ kind: "browser", groups: ["cdp"] }],
151
- defaultImage: { browser: BROWSER_IMAGE },
152
- }),
153
- ];
44
+ export function configurationOf(serving, image, defaultImage) {
45
+ if (image !== undefined)
46
+ return serving.find((one) => one.image === image);
47
+ return serving.find((one) => defaultImage !== undefined && one.image === defaultImage) ?? serving.find((one) => one.image === undefined) ?? serving[0];
48
+ }
49
+ /** A descriptor as Settings shows it: its data, and the setting kinds its capabilities serve, derived by serves(). */
50
+ export function entryOf(descriptor) {
51
+ const { load: _load, ...data } = descriptor;
52
+ return { ...data, kinds: SETTING_KIND_NAMES.filter((kind) => descriptor.capabilities.some((one) => serves(one, kind))) };
53
+ }
54
+ /** Every provider Settings offers: each built-in descriptor (descriptors/index.ts), as entryOf gives it. */
55
+ export const PROVIDERS = DESCRIPTORS.map(entryOf);
package/dist/labels.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { epochProblem } from "./mount.js";
2
+ import { type ComputerOwner } from "./provider.js";
2
3
  import { type Result } from "./result.js";
3
4
  export { epochProblem };
4
5
  /** The run a computer works for. */
@@ -11,6 +12,17 @@ export declare const RUN_HASH_LABEL = "agentrun.run.hash";
11
12
  /** The run label's hash, as a provider keeps it where the run itself doesn't fit (a computer's name): base32 of its
12
13
  * sha256, lower case, 16 letters. */
13
14
  export declare function runHash(run: string): string;
15
+ /** The agent a persistent computer belongs to, as agent:<id>. */
16
+ export declare const OWNER_LABEL = "agentrun.owner";
17
+ /** The owner's idle TTL of a persistent computer, in milliseconds, in decimal: how long it may stay detached. */
18
+ export declare const IDLE_TTL_LABEL = "agentrun.idle-ttl-ms";
19
+ /** The labels of an agent's computer: its owner, and its idle TTL when the owner set one. Throws, in words, on an owner that is not one. */
20
+ export declare function ownerLabels(owner: ComputerOwner): Record<string, string>;
21
+ /**
22
+ * A computer's owner, read from its labels: undefined for a run's computer (no owner label). An owner label that is not
23
+ * agent:<id>, or an idle TTL that is not a decimal whole number above 0, is invalid, in words naming what it reads.
24
+ */
25
+ export declare function ownerOf(labels: Record<string, string> | undefined): Result<ComputerOwner | undefined>;
14
26
  /**
15
27
  * Why run is not a run id, in words, or undefined when it is one: a non-empty string with no NUL byte. That is the
16
28
  * strictest rule the providers share for a label's value (Docker, Daytona and Modal each refuse only a NUL), so every