@parcha/agentrun-computer 0.1.0-beta.58 → 0.1.0-beta.60

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 (143) hide show
  1. package/README.md +285 -81
  2. package/box/Dockerfile +4 -3
  3. package/box/install.sh +57 -11
  4. package/dist/agent37.d.ts +11 -4
  5. package/dist/agent37.js +217 -19
  6. package/dist/attach.d.ts +24 -4
  7. package/dist/attach.js +50 -19
  8. package/dist/boxd.js +22 -9
  9. package/dist/browser.d.ts +56 -11
  10. package/dist/browser.js +76 -17
  11. package/dist/browserbase.d.ts +20 -5
  12. package/dist/browserbase.js +186 -21
  13. package/dist/child-env.d.ts +11 -0
  14. package/dist/child-env.js +22 -0
  15. package/dist/chrome.d.ts +5 -2
  16. package/dist/chrome.js +5 -2
  17. package/dist/cloudflare.d.ts +2 -0
  18. package/dist/cloudflare.js +5 -3
  19. package/dist/computerd-linux-amd64 +0 -0
  20. package/dist/computerd-linux-arm64 +0 -0
  21. package/dist/computerd.json +1 -1
  22. package/dist/conformance/agent37.d.ts +20 -40
  23. package/dist/conformance/agent37.js +31 -118
  24. package/dist/conformance/archil.d.ts +13 -3
  25. package/dist/conformance/archil.js +22 -17
  26. package/dist/conformance/boxd.d.ts +8 -31
  27. package/dist/conformance/boxd.js +19 -74
  28. package/dist/conformance/browserbase.d.ts +3 -6
  29. package/dist/conformance/browserbase.js +6 -17
  30. package/dist/conformance/cases/health.js +6 -3
  31. package/dist/conformance/cases/provider.js +4 -1
  32. package/dist/conformance/cli.d.ts +3 -1
  33. package/dist/conformance/cli.js +69 -9
  34. package/dist/conformance/cloudflare.d.ts +3 -6
  35. package/dist/conformance/cloudflare.js +7 -15
  36. package/dist/conformance/daytona.d.ts +6 -20
  37. package/dist/conformance/daytona.js +22 -57
  38. package/dist/conformance/dial-only.d.ts +4 -3
  39. package/dist/conformance/dial-only.js +3 -3
  40. package/dist/conformance/docker.d.ts +4 -5
  41. package/dist/conformance/docker.js +8 -14
  42. package/dist/conformance/e2b.d.ts +10 -36
  43. package/dist/conformance/e2b.js +27 -84
  44. package/dist/conformance/fly.d.ts +3 -6
  45. package/dist/conformance/fly.js +2 -6
  46. package/dist/conformance/groundbox.d.ts +7 -23
  47. package/dist/conformance/groundbox.js +16 -56
  48. package/dist/conformance/index.d.ts +1 -0
  49. package/dist/conformance/index.js +1 -0
  50. package/dist/conformance/kernel.d.ts +3 -6
  51. package/dist/conformance/kernel.js +5 -15
  52. package/dist/conformance/kind.d.ts +0 -6
  53. package/dist/conformance/kind.js +0 -4
  54. package/dist/conformance/local-chrome.d.ts +5 -7
  55. package/dist/conformance/local-chrome.js +7 -11
  56. package/dist/conformance/modal.d.ts +10 -38
  57. package/dist/conformance/modal.js +27 -74
  58. package/dist/conformance/module-kit.d.ts +87 -0
  59. package/dist/conformance/module-kit.js +88 -0
  60. package/dist/conformance/morph.d.ts +7 -23
  61. package/dist/conformance/morph.js +20 -66
  62. package/dist/conformance/orgo.d.ts +5 -10
  63. package/dist/conformance/orgo.js +15 -27
  64. package/dist/conformance/phone-harness.d.ts +3 -5
  65. package/dist/conformance/phone-harness.js +3 -11
  66. package/dist/conformance/runner.d.ts +13 -3
  67. package/dist/conformance/runner.js +32 -11
  68. package/dist/conformance/smolcloud.d.ts +7 -23
  69. package/dist/conformance/smolcloud.js +16 -49
  70. package/dist/conformance/sweep.d.ts +10 -5
  71. package/dist/conformance/sweep.js +91 -38
  72. package/dist/conformance/tti.d.ts +69 -0
  73. package/dist/conformance/tti.js +205 -0
  74. package/dist/conformance/types.d.ts +9 -2
  75. package/dist/daytona.js +60 -20
  76. package/dist/descriptor.d.ts +37 -0
  77. package/dist/descriptor.js +9 -0
  78. package/dist/descriptors/agent37.d.ts +4 -1
  79. package/dist/descriptors/agent37.js +5 -2
  80. package/dist/descriptors/browserbase.d.ts +3 -0
  81. package/dist/descriptors/browserbase.js +4 -0
  82. package/dist/descriptors/docker.d.ts +2 -0
  83. package/dist/descriptors/docker.js +5 -0
  84. package/dist/descriptors/env-names.d.ts +32 -0
  85. package/dist/descriptors/env-names.js +60 -0
  86. package/dist/descriptors/index.d.ts +14 -3
  87. package/dist/descriptors/kernel.d.ts +3 -0
  88. package/dist/descriptors/kernel.js +2 -0
  89. package/dist/descriptors/local-chrome.d.ts +1 -1
  90. package/dist/descriptors/local-chrome.js +5 -3
  91. package/dist/descriptors/phone-harness.d.ts +1 -1
  92. package/dist/descriptors/phone-harness.js +4 -2
  93. package/dist/docker/egress.d.ts +7 -0
  94. package/dist/docker/egress.js +8 -0
  95. package/dist/docker/image.d.ts +5 -1
  96. package/dist/docker/image.js +12 -8
  97. package/dist/docker.d.ts +52 -13
  98. package/dist/docker.js +166 -92
  99. package/dist/drift.js +6 -6
  100. package/dist/e2b.d.ts +2 -2
  101. package/dist/e2b.js +2 -3
  102. package/dist/groundbox.js +6 -6
  103. package/dist/host.d.ts +23 -0
  104. package/dist/hosted/download.d.ts +23 -0
  105. package/dist/hosted/download.js +144 -0
  106. package/dist/hosted/process.d.ts +5 -0
  107. package/dist/hosted/process.js +20 -0
  108. package/dist/hosted/provider.js +120 -48
  109. package/dist/hosted/rest.d.ts +19 -8
  110. package/dist/hosted/rest.js +47 -14
  111. package/dist/hosted/scripts.d.ts +10 -0
  112. package/dist/hosted/scripts.js +23 -2
  113. package/dist/hosted/ssh-exec.d.ts +7 -1
  114. package/dist/hosted/ssh-exec.js +19 -14
  115. package/dist/hosted/ssh-key.d.ts +18 -0
  116. package/dist/hosted/ssh-key.js +36 -0
  117. package/dist/index.d.ts +5 -3
  118. package/dist/index.js +4 -2
  119. package/dist/janitor.d.ts +7 -1
  120. package/dist/janitor.js +2 -2
  121. package/dist/kernel.d.ts +14 -4
  122. package/dist/kernel.js +141 -18
  123. package/dist/local-chrome.d.ts +12 -3
  124. package/dist/local-chrome.js +108 -10
  125. package/dist/local-supervisor.js +1 -0
  126. package/dist/modal.d.ts +6 -5
  127. package/dist/modal.js +7 -7
  128. package/dist/morph.js +5 -8
  129. package/dist/orgo-channel.d.ts +3 -2
  130. package/dist/orgo-channel.js +3 -3
  131. package/dist/orgo-desktop.js +2 -4
  132. package/dist/orgo.d.ts +6 -0
  133. package/dist/orgo.js +158 -15
  134. package/dist/phone-harness.d.ts +7 -5
  135. package/dist/phone-harness.js +60 -61
  136. package/dist/protocol.d.ts +10 -0
  137. package/dist/protocol.js +17 -0
  138. package/dist/provider.d.ts +6 -2
  139. package/dist/screen-watch.d.ts +6 -1
  140. package/dist/screen-watch.js +166 -12
  141. package/dist/vendor-sdk.d.ts +9 -0
  142. package/dist/vendor-sdk.js +26 -0
  143. package/package.json +8 -1
package/dist/kernel.js CHANGED
@@ -20,7 +20,8 @@ import { randomBytes } from "node:crypto";
20
20
  import { readFileSync } from "node:fs";
21
21
  import { KERNEL } from "./descriptors/kernel.js";
22
22
  import { BROWSER_IMAGE } from "./descriptors/shared.js";
23
- import { cdpUrlProblem, browserClient, browserHello, BrowserVendorError, CREATE_LABEL, carries, causeOf, checkBrowser, createLabelValue, createUncertain, DEFAULT_CONFIRM, defaultSleep, idProblem, labelsOf, labelsProblem, memoryUrls, pointerOk, queryable, recoverCreate, releaseConfirmed, restCall, causedFail, vendorFailure, withoutCreateLabel, } from "./browser.js";
23
+ import { cdpUrlProblem, browserClient, browserHello, BrowserVendorError, CREATE_LABEL, carries, causeOf, checkBrowser, createUncertain, DEFAULT_CONFIRM, ATTEMPT_LABEL, convergedBrowser, heldBrowser, newAttempt, defaultSleep, idProblem, labelsOf, labelsProblem, memoryUrls, pointerOk, queryable, RECOVER_MS, recoverCreate, releaseConfirmed, boundedRelease, restCall, causedFail, vendorFailure, withoutCreateLabel, } from "./browser.js";
24
+ import { CreateRequests, endedWords, labelsDiffer, otherSpecWords } from "./create-requests.js";
24
25
  import { httpsBase } from "./hosted/rest.js";
25
26
  import { runLifetimeMs, } from "./provider.js";
26
27
  import { failFor, ok, vendorFail } from "./result.js";
@@ -38,6 +39,8 @@ export const KERNEL_MIN_LIFETIME_MS = 10_000;
38
39
  export const KERNEL_MAX_LIFETIME_MS = 259_200_000;
39
40
  /** The most pages a list reads before it fails rather than run on. */
40
41
  const MAX_PAGES = 100;
42
+ /** A browser as its create label finds it. */
43
+ const heldOf = ({ id, tags, createdAt }) => ({ id, labels: tags, ...(createdAt === undefined ? {} : { createdAt }) });
41
44
  /** Kernel's REST API over fetch: the default request. */
42
45
  export function kernelRest({ apiKey, apiUrl = KERNEL_API_URL, fetch: fetcher = fetch }) {
43
46
  const o = { vendor: NAME, fetch: fetcher, base: httpsBase(apiUrl, "the Kernel API URL"), headers: { Authorization: `Bearer ${apiKey}` } };
@@ -49,7 +52,7 @@ const text = (value) => (typeof value === "string" ? value.trim() : "");
49
52
  const refOf = (id) => ({ id, name: id });
50
53
  const statusOf = (error) => error?.status;
51
54
  /** What a Kernel browser offers beyond the protocol, a fresh copy each time. */
52
- const KERNEL_BROWSER = () => ({ timeout: "inactivity", minLifetimeMs: KERNEL_MIN_LIFETIME_MS, profiles: { settleMs: 0 }, headless: true });
55
+ const KERNEL_BROWSER = () => ({ timeout: "inactivity", minLifetimeMs: KERNEL_MIN_LIFETIME_MS, profiles: { settleMs: KERNEL.profiles.settleMs }, headless: true });
53
56
  /** Computers that are Kernel browsers. */
54
57
  export class KernelProvider {
55
58
  id = "kernel";
@@ -60,7 +63,18 @@ export class KernelProvider {
60
63
  #live;
61
64
  #confirm;
62
65
  #sleep;
63
- constructor({ apiKey, apiUrl, env = {}, fetch: fetcher, confirm = DEFAULT_CONFIRM, sleep = defaultSleep }) {
66
+ /** The bound of each cleanup a create runs for itself (cleanupMs). */
67
+ #cleanupMs;
68
+ /** Idempotent create's in-process half: one browser per request id (provider.md). */
69
+ #requests = new CreateRequests();
70
+ /** The request's name of each browser this provider made or found for a create, by id: its release ends the request. */
71
+ #requestOf = new Map();
72
+ /**
73
+ * The browser each request's create answered, by the request's name, kept past its release: a request whose browser
74
+ * ended on its own (its timeout, the vendor) is refused exists, as one released here is, never made again.
75
+ */
76
+ #madeFor = new Map();
77
+ constructor({ apiKey, apiUrl, env = {}, fetch: fetcher, confirm = DEFAULT_CONFIRM, sleep = defaultSleep, cleanupMs = RECOVER_MS }) {
64
78
  if (typeof apiKey !== "string" || apiKey === "")
65
79
  throw new Error("set options.apiKey to a Kernel API key: the provider reads no environment");
66
80
  const api = apiUrl || env.KERNEL_BASE_URL?.trim() || undefined;
@@ -69,6 +83,7 @@ export class KernelProvider {
69
83
  this.#live = memoryUrls();
70
84
  this.#confirm = confirm;
71
85
  this.#sleep = sleep;
86
+ this.#cleanupMs = cleanupMs;
72
87
  }
73
88
  /**
74
89
  * A browser: Kernel ends a browser after its idle timeout (lifetime vendor), at most 72 h; it reaches the open web;
@@ -94,24 +109,51 @@ export class KernelProvider {
94
109
  return checkBrowser(spec, this.capabilities(), NAME, KERNEL_MIN_LIFETIME_MS);
95
110
  }
96
111
  /**
97
- * Makes a browser at most once, with the lifetime as its idle timeout in whole seconds and the labels as its tags.
98
- * spec.browser is the session's own options, each refused by check() unless declared; a profile is made first if
99
- * Kernel does not know it.
112
+ * Makes a browser once per request (provider.md, Idempotent create), with the lifetime as its idle timeout in whole
113
+ * seconds and the labels as its tags, with the request's name (computerNameFor) as its create label. A request whose
114
+ * browser Kernel still holds undeleted answers that one, found by its create label; one whose browser was deleted here
115
+ * is refused exists; a create of a request in flight here waits for the first (CreateRequests). spec.browser is the
116
+ * session's own options, each refused by check() unless declared; a profile is made first if Kernel does not know it.
100
117
  */
101
118
  async create(spec, context) {
102
- const signal = context?.signal;
103
119
  const refusals = this.check(spec);
104
- if (refusals.length > 0)
105
- return fail("refused", refusals.map(({ field, message }) => `${field}: ${message}`).join("; "));
120
+ return this.#requests.create(spec, context, {
121
+ refuse: fail,
122
+ ...(refusals.length > 0 ? { refused: refusals.map(({ field, message }) => `${field}: ${message}`).join("; ") } : {}),
123
+ make: async (request) => {
124
+ const made = await this.#createNamed(spec, request, context.signal);
125
+ if (made.ok)
126
+ this.#madeFor.set(request, made.value.id);
127
+ return made;
128
+ },
129
+ });
130
+ }
131
+ /** Everything create does under the request's name: the browser Kernel holds under it, or a new one. */
132
+ async #createNamed(spec, request, signal) {
106
133
  if (signal?.aborted)
107
134
  return fail("aborted", "create was aborted before Kernel was called");
135
+ const held = await this.#browsers({ [CREATE_LABEL]: request }, signal);
136
+ if (!held.ok)
137
+ return held;
138
+ const found = heldBrowser(spec.labels ?? {}, held.value.map(heldOf));
139
+ if (found !== undefined) {
140
+ if (found.differ.length > 0)
141
+ return fail("exists", otherSpecWords(`${request} (browser ${found.id})`, "was made", found.differ));
142
+ this.#requestOf.set(found.id, request);
143
+ return ok(refOf(found.id));
144
+ }
145
+ const ended = await this.#ended(spec, request, signal);
146
+ if (ended !== undefined)
147
+ return ended;
108
148
  const options = spec.browser;
109
149
  if (options?.profile !== undefined) {
110
150
  const ensured = await this.#ensureProfile(options.profile.pointer, signal);
111
151
  if (!ensured.ok)
112
152
  return causedFail(ensured.error.code, `the profile could not be made ready: ${ensured.error.message}; no browser was made`, causeOf(ensured), "kernel");
113
153
  }
114
- const written = { [CREATE_LABEL]: createLabelValue(), ...spec.labels };
154
+ // The request's label, which a retry and a converge find it by, and this POST's own, which its recovery finds it by.
155
+ const attempt = { [ATTEMPT_LABEL]: newAttempt() };
156
+ const written = { [CREATE_LABEL]: request, ...attempt, ...spec.labels };
115
157
  const body = {
116
158
  ...(options !== undefined ? { stealth: false } : {}),
117
159
  ...(options?.viewport ? { viewport: { width: options.viewport.width, height: options.viewport.height } } : {}),
@@ -128,8 +170,10 @@ export class KernelProvider {
128
170
  const failed = vendorFailure("kernel", NAME, "POST /browsers", error);
129
171
  if (failed.ok || !createUncertain(error))
130
172
  return failed;
131
- // The browser may have been made though its answer never came: found by its create label, never made again.
132
- return causedFail(failed.error.code, `${failed.error.message}; ${await this.#recover(written)}`, causeOf(failed), "kernel");
173
+ // The browser may have been made though its answer never came: found by this POST's attempt label and deleted,
174
+ // and the request is ended, so it is never made again.
175
+ this.#requests.end(request);
176
+ return causedFail(failed.error.code, `${failed.error.message}; ${await this.#recover(attempt)}`, causeOf(failed), "kernel");
133
177
  }
134
178
  const browser = (made.json ?? {});
135
179
  const id = text(browser.session_id);
@@ -138,8 +182,17 @@ export class KernelProvider {
138
182
  return vendorFailure("kernel", NAME, "POST /browsers", new BrowserVendorError(NAME, "POST /browsers", made.status, "no_session"));
139
183
  if (idProblem(id, NAME) !== undefined) {
140
184
  const failed = vendorFailure("kernel", NAME, "POST /browsers", new BrowserVendorError(NAME, "POST /browsers", made.status, "no_session"));
141
- return failed.ok ? failed : fail(failed.error.code, `${failed.error.message}; ${await this.#recover(written)}`);
185
+ if (failed.ok)
186
+ return failed;
187
+ this.#requests.end(request);
188
+ return fail(failed.error.code, `${failed.error.message}; ${await this.#recover(attempt)}`);
142
189
  }
190
+ this.#requests.made(request);
191
+ // Another process's create of this request may have made one too (#converge): the older is answered.
192
+ const converged = await this.#converge(spec, request, { id, tags: {}, ...(text(browser.created_at) === "" ? {} : { createdAt: text(browser.created_at) }) }, signal);
193
+ if (converged !== undefined)
194
+ return converged;
195
+ this.#requestOf.set(id, request);
143
196
  const unusable = cdpUrlProblem(url, NAME, CDP_DOMAIN);
144
197
  if (unusable !== undefined) {
145
198
  // The browser is made and billed until its idle timeout: deleted here, not left to a later sweep.
@@ -152,6 +205,64 @@ export class KernelProvider {
152
205
  this.#live.set(id, live);
153
206
  return ok(refOf(id));
154
207
  }
208
+ /**
209
+ * The one browser a request keeps (convergedBrowser): the request's create label listed again once Kernel made mine.
210
+ * Undefined when mine is the oldest (or the listing fails: the create goes on with its own); an abort deletes mine,
211
+ * never under the caller's signal, and the create is aborted. Else mine is deleted,
212
+ * never under the caller's signal, and the older answered: refused exists when it is gone by then, or when its labels
213
+ * are another spec's.
214
+ */
215
+ async #converge(spec, request, mine, signal) {
216
+ const listed = await this.#browsers({ [CREATE_LABEL]: request }, signal);
217
+ if (!listed.ok) {
218
+ if (listed.error.code !== "aborted" && !signal?.aborted)
219
+ return undefined;
220
+ // The caller is gone: the browser this POST made is deleted, never under the caller's signal.
221
+ this.#requests.end(request);
222
+ const released = await boundedRelease("browser", mine.id, this.#cleanupMs, (bound) => this.#releaseBrowser(mine.id, bound));
223
+ return fail("aborted", `create was aborted once Kernel had made the browser ${mine.id}; ${released.ok ? "the browser was released" : `the browser could not be released (${released.error.message}), and its tags let a sweep find it`}`);
224
+ }
225
+ const kept = convergedBrowser(listed.value.map(heldOf), heldOf(mine));
226
+ if (kept === "mine")
227
+ return undefined;
228
+ const released = await boundedRelease("browser", mine.id, this.#cleanupMs, (bound) => this.#releaseBrowser(mine.id, bound));
229
+ if (!released.ok)
230
+ return fail(released.error.code, `${request} keeps the browser ${kept.id}, the older of its two, and the browser ${mine.id} made for it could not be deleted (${released.error.message})`);
231
+ const alive = await this.#alive(kept.id, signal);
232
+ if (!alive.ok)
233
+ return alive;
234
+ if (!alive.value) {
235
+ this.#requests.end(request);
236
+ return fail("exists", endedWords(request));
237
+ }
238
+ const differ = labelsDiffer(spec.labels ?? {}, kept.labels, "read back");
239
+ if (differ.length > 0)
240
+ return fail("exists", otherSpecWords(`${request} (browser ${kept.id})`, "was made", differ));
241
+ this.#requestOf.set(kept.id, request);
242
+ return ok(refOf(kept.id));
243
+ }
244
+ /**
245
+ * A request this provider answered a browser for before, which its create label no longer finds: refused exists, the
246
+ * request ended, once Kernel reads that browser as gone too; one it still holds (a listing that left it out) is
247
+ * answered when its labels are this spec's. Undefined for a request with no browser here yet.
248
+ */
249
+ async #ended(spec, request, signal) {
250
+ const before = this.#madeFor.get(request);
251
+ if (before === undefined)
252
+ return undefined;
253
+ const read = await this.#running(before, signal);
254
+ if (!read.ok && read.error.code !== "not_found" && read.error.code !== "gone")
255
+ return read;
256
+ if (!read.ok) {
257
+ this.#requests.end(request);
258
+ return fail("exists", endedWords(request));
259
+ }
260
+ const differ = labelsDiffer(spec.labels ?? {}, withoutCreateLabel(labelsOf(read.value.tags)), "read back");
261
+ if (differ.length > 0)
262
+ return fail("exists", otherSpecWords(`${request} (browser ${before})`, "was made", differ));
263
+ this.#requestOf.set(before, request);
264
+ return ok(refOf(before));
265
+ }
155
266
  /** A browser names only a profile Kernel knows: made if it is not (GET, then POST); a 409 is another process making it. */
156
267
  async #ensureProfile(name, signal) {
157
268
  try {
@@ -203,16 +314,16 @@ export class KernelProvider {
203
314
  }
204
315
  /**
205
316
  * The browsers a lost create made, released: what recoverCreate says of them. They are found as list finds any, by the
206
- * tags the create wrote (its create label first, so the query names it, then the run's), through #browsers: another
207
- * browser of the same run carries a create label of its own and is left alone. #browsers reads every state not
208
- * deleted, so a browser still starting is found and released too.
317
+ * attempt label its POST wrote (ATTEMPT_LABEL), through #browsers: another create's browser, of this request or
318
+ * another, carries an attempt label of its own and is left alone, even one another instance has answered. #browsers
319
+ * reads every state not deleted, so a browser still starting is found and released too.
209
320
  */
210
321
  #recover(labels) {
211
322
  const find = async (signal) => {
212
323
  const found = await this.#browsers(labels, signal);
213
324
  return found.ok ? ok(found.value.map((b) => b.id)) : found;
214
325
  };
215
- return recoverCreate("browser", find, (id) => this.release(refOf(id), "delete"), this.#sleep);
326
+ return recoverCreate("browser", find, (id, signal) => this.release(refOf(id), "delete", { signal }), this.#sleep, this.#cleanupMs);
216
327
  }
217
328
  /**
218
329
  * Settings' test: one page of the organization's active browsers (GET /browsers?status=active), which makes nothing.
@@ -322,7 +433,8 @@ export class KernelProvider {
322
433
  const id = text(row?.session_id);
323
434
  if (id !== "" && !row.deleted_at && carries(row.tags, labels) && !seen.has(id)) {
324
435
  seen.add(id);
325
- found.push({ id, tags: withoutCreateLabel(labelsOf(row.tags)) });
436
+ const createdAt = text(row.created_at);
437
+ found.push({ id, tags: withoutCreateLabel(labelsOf(row.tags)), ...(createdAt === "" ? {} : { createdAt }) });
326
438
  }
327
439
  }
328
440
  if (page.headers.get("x-has-more") !== "true")
@@ -391,6 +503,17 @@ export class KernelProvider {
391
503
  const problem = idProblem(id, NAME);
392
504
  if (problem)
393
505
  return fail("invalid", problem);
506
+ // The request's browser is ended here: a later create of it is refused exists, never made again.
507
+ const request = this.#requestOf.get(id);
508
+ if (request !== undefined)
509
+ this.#requests.end(request);
510
+ const released = await this.#releaseBrowser(id, signal);
511
+ if (released.ok)
512
+ this.#requestOf.delete(id);
513
+ return released;
514
+ }
515
+ /** Deletes the browser and waits until Kernel reads it as gone; the request it was made for is not ended. */
516
+ async #releaseBrowser(id, signal) {
394
517
  const released = await releaseConfirmed({
395
518
  request: async () => {
396
519
  try {
@@ -12,8 +12,11 @@ export interface LocalBrowserOptions {
12
12
  /** The Chrome or Chromium to run; default the one findChrome finds in `env`, then in the usual places. */
13
13
  executablePath?: string;
14
14
  /**
15
- * Where CHROME_PATH, PI_BROWSER_CHROME and PATH are read when no executablePath is given: the host's environment, which
16
- * it passes (serve passes its own). The library reads none.
15
+ * The host's environment, which it passes (serve passes its own values of the descriptor's hostEnv): where
16
+ * CHROME_PATH, PI_BROWSER_CHROME and PATH are read when no executablePath is given, and what the supervisor and the
17
+ * Chrome it starts, and the sandbox check's Chrome, hold of it: the names Chrome reads (CHROME_ENV_NAMES: PATH, HOME,
18
+ * the display, locale, fonts and temp directory) and nothing else, so no key the host holds reaches Chrome. The
19
+ * library reads none: without env, Chrome starts with none.
17
20
  */
18
21
  env?: Readonly<Record<string, string | undefined>>;
19
22
  /** Shows the window, for a person watching on this machine; default headless. */
@@ -42,7 +45,13 @@ export declare class LocalBrowserProvider implements ComputerProvider {
42
45
  /** The Chrome this provider runs: the option's, else one found; null when there is none. */
43
46
  executable(): string | null;
44
47
  check(spec: ComputerSpec): Refusal[];
45
- /** Starts Chrome under a supervisor of its own, waits until its DevTools socket answers, and hands back its ref. */
48
+ /**
49
+ * Starts Chrome under a supervisor of its own, waits until its DevTools socket answers, and hands back its ref: once
50
+ * per request (provider.md, Idempotent create). The request's name (computerNameFor) is the browser's id and its
51
+ * directory's name, which mkdir claims for one create alone. A request whose directory is already under the root
52
+ * answers that browser, from this process or another (#taken); one whose browser was released here is refused
53
+ * exists; a create of a request in flight here waits for the first (CreateRequests).
54
+ */
46
55
  create(spec: ComputerSpec, context: CreateContext): Promise<Result<CreatedComputer>>;
47
56
  /**
48
57
  * Settings' test: finds the Chrome and starts it once, headless, on a blank page, with its sandbox on (chrome.ts
@@ -18,18 +18,20 @@
18
18
  // alone. It is for local and development use.
19
19
  //
20
20
  // Files: one directory per browser under the root (default <tmpdir>/agentrun-local-browser-<uid>, 0700), named by the
21
- // browser's id: browser.json (its labels and deadline, which list and attach read), supervisor.pid, state.json (Chrome's
21
+ // browser's id: claim.json (the pid and time of the create that made the directory), browser.json (its labels and
22
+ // deadline, which list and attach read), supervisor.pid, state.json (Chrome's
22
23
  // pid and port, once it answers), the profile, the proxy's socket and two logs. A release removes all of it.
23
24
  import { spawn } from "node:child_process";
24
- import { randomBytes } from "node:crypto";
25
25
  import { existsSync, readFileSync } from "node:fs";
26
26
  import { lstat, mkdir, readdir, readFile, rm, writeFile } from "node:fs/promises";
27
27
  import { tmpdir } from "node:os";
28
28
  import { join, resolve } from "node:path";
29
29
  import { fileURLToPath } from "node:url";
30
30
  import { browserClient, browserHello, browserSpecRefusals, carries, labelsProblem } from "./browser.js";
31
+ import { CreateRequests, endedWords, labelsDiffer, otherSpecWords } from "./create-requests.js";
31
32
  import { alive, answeringPath, CHROME_FLAGS, checkChrome, findChrome, killTree, NO_CHROME, AS_ROOT, runsWith, singletonDir } from "./chrome.js";
32
33
  import { LOCAL } from "./descriptors/local-chrome.js";
34
+ import { chromeEnv } from "./child-env.js";
33
35
  import { BROWSER_IMAGE } from "./descriptors/shared.js";
34
36
  import { parseAllow } from "./docker/egress-proxy.js";
35
37
  import { BROWSER_FILE, CHROME_PID_FILE, EGRESS_SOCKET_FILE, PROFILE_DIR, READY_MS, STATE_FILE, SUPERVISOR_FILE } from "./local-supervisor.js";
@@ -43,6 +45,8 @@ export const LOCAL_MAX_LIFETIME_MS = 24 * 60 * 60_000;
43
45
  const WINDOW = "--window-size=1280,800";
44
46
  /** A Unix socket's path holds 107 bytes; a root whose browsers' sockets would not fit is refused. */
45
47
  const SOCKET_PATH_MAX = 107;
48
+ /** The record a create writes in the directory it claimed: its process's pid and the time, before browser.json. */
49
+ const CLAIM_FILE = "claim.json";
46
50
  /** How long a release waits for the supervisor, then for Chrome, to end. */
47
51
  const END_MS = 10_000;
48
52
  /** The networks a local browser runs on, its descriptor's: through its egress proxy, public addresses ("open"), or only
@@ -73,7 +77,8 @@ const networkRecord = (network) => {
73
77
  };
74
78
  /** A browser's network as list, attach and network() read it back from browser.json. */
75
79
  const networkRead = (record) => (record.allow ? { allow: [...record.allow] } : "open");
76
- const ID = /^lb-[0-9a-f]{16}$/;
80
+ /** A browser's id, its directory's name: its request's name (computerNameFor), or lb-<16 hex> for one made before ids were. */
81
+ const ID = /^(?:computer-[0-9a-f]{12}|lb-[0-9a-f]{16})$/;
77
82
  const idProblem = (id) => (typeof id === "string" && ID.test(id) ? undefined : `${typeof id === "string" ? JSON.stringify(id) : String(id)} is not a local browser's id`);
78
83
  const refOf = (id) => ({ id, name: id });
79
84
  const SPEC_FIELDS = new Set(["image", "lifetimeMs", "network", "labels", "browser"]);
@@ -94,6 +99,13 @@ export class LocalBrowserProvider {
94
99
  #env;
95
100
  #headed;
96
101
  #uid;
102
+ /** Idempotent create's in-process half: one browser per request id (provider.md). */
103
+ #requests = new CreateRequests();
104
+ /**
105
+ * The ids of the browsers this provider's creates answered, kept past their end: a request whose browser ended on its
106
+ * own (its deadline, its supervisor) is refused exists, as one released here is, never made again.
107
+ */
108
+ #made = new Set();
97
109
  root;
98
110
  constructor({ executablePath, env = {}, headed = false, root, uid = process.getuid?.() } = {}) {
99
111
  this.#executablePath = executablePath === "" ? undefined : executablePath;
@@ -183,21 +195,104 @@ export class LocalBrowserProvider {
183
195
  return fail("invalid", `the local browser's root ${this.root} could not be made (${error.code ?? error.message})`);
184
196
  }
185
197
  }
186
- /** Starts Chrome under a supervisor of its own, waits until its DevTools socket answers, and hands back its ref. */
198
+ /**
199
+ * Starts Chrome under a supervisor of its own, waits until its DevTools socket answers, and hands back its ref: once
200
+ * per request (provider.md, Idempotent create). The request's name (computerNameFor) is the browser's id and its
201
+ * directory's name, which mkdir claims for one create alone. A request whose directory is already under the root
202
+ * answers that browser, from this process or another (#taken); one whose browser was released here is refused
203
+ * exists; a create of a request in flight here waits for the first (CreateRequests).
204
+ */
187
205
  async create(spec, context) {
188
- const signal = context?.signal;
189
206
  const refusals = this.check(spec);
190
- if (refusals.length > 0)
191
- return fail(refusals.some((r) => r.field === "image" && r.message.endsWith(NO_CHROME)) ? "not_found" : "refused", refusals.map(({ field, message }) => `${field}: ${message}`).join("; "));
207
+ return this.#requests.create(spec, context, {
208
+ refuse: (code, message) => fail(code === "refused" && refusals.some((r) => r.field === "image" && r.message.endsWith(NO_CHROME)) ? "not_found" : code, message),
209
+ ...(refusals.length > 0 ? { refused: refusals.map(({ field, message }) => `${field}: ${message}`).join("; ") } : {}),
210
+ make: async (id) => {
211
+ const made = await this.#createNamed(spec, id, context.signal);
212
+ if (made.ok)
213
+ this.#made.add(id);
214
+ return made;
215
+ },
216
+ });
217
+ }
218
+ /**
219
+ * The browser of a request whose directory another create claimed: answered once its Chrome answers on its DevTools
220
+ * socket, when it is this spec's (its labels and network, as browser.json holds them), and refused exists when it is
221
+ * another's, when its deadline has passed, or when its supervisor has ended with no Chrome left. Waited for within the
222
+ * time a create of its own takes.
223
+ */
224
+ async #taken(spec, id, signal) {
225
+ const dir = this.#dir(id);
226
+ const wait = READY_MS + 10_000;
227
+ const until = Date.now() + wait;
228
+ for (;;) {
229
+ const made = await lstat(dir).then((stat) => stat, () => undefined);
230
+ if (made === undefined)
231
+ return fail("exists", endedWords(id));
232
+ const record = await this.#record(id);
233
+ if (record === undefined) {
234
+ // No browser.json yet: the create that claimed the directory is still making it, or it crashed. Its claim says
235
+ // who and when (the directory's own time where it wrote none); one whose process is gone, or older than a
236
+ // create takes, never finishes.
237
+ const claim = await readJson(join(dir, CLAIM_FILE));
238
+ const pid = claim?.pid;
239
+ const at = typeof claim?.at === "string" ? Date.parse(claim.at) : Number.NaN;
240
+ const since = Number.isNaN(at) ? made.mtimeMs : at;
241
+ if ((typeof pid === "number" && Number.isInteger(pid) && pid > 0 && !alive(pid)) || Date.now() - since > wait) {
242
+ return fail("exists", `${id}: an earlier create of this request did not finish: create with a new request id`);
243
+ }
244
+ }
245
+ else {
246
+ const allow = (network) => JSON.stringify(network.allow ? [...network.allow].sort() : null);
247
+ const differ = labelsDiffer(spec.labels ?? {}, record.labels, "read back");
248
+ const asked = networkRecord(spec.network);
249
+ if (allow(asked) !== allow(record))
250
+ differ.push(`network: asked ${JSON.stringify(spec.network)}, read back ${JSON.stringify(networkRead(record))}`);
251
+ if (differ.length > 0)
252
+ return fail("exists", otherSpecWords(id, "was made", differ));
253
+ if (Date.parse(record.deadline) <= Date.now())
254
+ return fail("exists", endedWords(id));
255
+ const state = await this.#live(id);
256
+ if (state !== undefined && (await answeringPath(state.port)) === state.path)
257
+ return ok(refOf(id));
258
+ const supervisor = Number((await readFile(join(dir, SUPERVISOR_FILE), "utf8").catch(() => "")).trim());
259
+ if (state === undefined && Number.isInteger(supervisor) && supervisor > 0 && !runsWith(supervisor, dir))
260
+ return fail("exists", `${id} was made for this request and no longer runs: create with a new request id`);
261
+ }
262
+ if (Date.now() + 100 >= until)
263
+ return fail("timeout", `${id}, made for this request, did not answer within ${wait / 1000} s`);
264
+ await sleep(100);
265
+ if (signal?.aborted)
266
+ return fail("aborted", `create was aborted while ${id}, made for this request, came up`);
267
+ }
268
+ }
269
+ /** Everything create does under the request's name: the browser its directory already holds, or a new one. */
270
+ async #createNamed(spec, id, signal) {
192
271
  if (signal?.aborted)
193
272
  return fail("aborted", "create was aborted before Chrome was started");
194
273
  const rooted = await this.#ensureRoot();
195
274
  if (!rooted.ok)
196
275
  return rooted;
197
- const id = `lb-${randomBytes(8).toString("hex")}`;
198
276
  const dir = join(this.root, id);
199
277
  if (Buffer.byteLength(join(dir, EGRESS_SOCKET_FILE)) > SOCKET_PATH_MAX)
200
278
  return fail("invalid", `the local browser's root ${this.root} is too long for a Unix socket under it: set the root option to a shorter directory`);
279
+ // The directory is the request's claim: made by one create alone, and one already there is the request's browser.
280
+ try {
281
+ await mkdir(dir, { mode: 0o700 });
282
+ }
283
+ catch (error) {
284
+ if (error.code === "EEXIST")
285
+ return this.#taken(spec, id, signal);
286
+ return fail("invalid", `the local browser's directory could not be made under ${this.root} (${error.code ?? error.message})`);
287
+ }
288
+ // The claim's record, so a create that finds the directory and no browser.json knows whether its maker still runs.
289
+ await writeFile(join(dir, CLAIM_FILE), JSON.stringify({ pid: process.pid, at: new Date().toISOString() }), { mode: 0o600, flag: "wx" }).catch(() => undefined);
290
+ // A request whose browser this provider answered before, and whose directory is gone: it ended on its own.
291
+ if (this.#made.has(id)) {
292
+ await rm(dir, { recursive: true, force: true }).catch(() => undefined);
293
+ this.#requests.end(id);
294
+ return fail("exists", endedWords(id));
295
+ }
201
296
  const now = Date.now();
202
297
  const record = {
203
298
  provider: LOCAL.id,
@@ -224,7 +319,8 @@ export class LocalBrowserProvider {
224
319
  }
225
320
  let child;
226
321
  try {
227
- child = spawn(process.execPath, [SUPERVISOR, dir], { detached: true, stdio: ["ignore", "pipe", "ignore"] });
322
+ // Its environment is Chrome's (chromeEnv), which the Chrome it starts inherits: no key the host holds.
323
+ child = spawn(process.execPath, [SUPERVISOR, dir], { detached: true, env: chromeEnv(this.#env), stdio: ["ignore", "pipe", "ignore"] });
228
324
  }
229
325
  catch (error) {
230
326
  await rm(dir, { recursive: true, force: true }).catch(() => undefined);
@@ -290,7 +386,7 @@ export class LocalBrowserProvider {
290
386
  if (refused.length > 0)
291
387
  return fail(refused[0]?.field === "host" ? "refused" : "not_found", refused[0].message);
292
388
  // A Chrome found or named is started once with its sandbox on: what a create would do, with nothing kept.
293
- const checked = await checkChrome(this.executable(), this.#uid === undefined ? {} : { uid: this.#uid });
389
+ const checked = await checkChrome(this.executable(), { env: this.#env, ...(this.#uid === undefined ? {} : { uid: this.#uid }) });
294
390
  if (!checked.ok)
295
391
  return checked;
296
392
  return ok({ detail: `${checked.value} starts here with its sandbox on: no key is needed` });
@@ -425,6 +521,8 @@ export class LocalBrowserProvider {
425
521
  const problem = idProblem(id);
426
522
  if (problem)
427
523
  return fail("invalid", problem);
524
+ // The request's browser is ended here: a later create of it is refused exists, never made again.
525
+ this.#requests.end(id);
428
526
  const dir = this.#dir(id);
429
527
  if (!(await lstat(dir).then(() => true, () => false)))
430
528
  return ok(undefined);
@@ -141,6 +141,7 @@ export async function supervise(dir, out) {
141
141
  const stderr = openSync(join(dir, CHROME_LOG), "a", 0o600);
142
142
  try {
143
143
  const args = [...record.args, ...chromeFence(`http://${RELAY_HOST}:${relayPort}`), `--user-data-dir=${profile}`, "--remote-debugging-port=0", "--remote-debugging-address=127.0.0.1", "about:blank"]; // key-gate: loopback-rule the local Chrome's DevTools socket listens on loopback alone
144
+ // Chrome inherits this process's environment, which the provider cut to what Chrome reads (local-chrome.ts chromeEnv).
144
145
  child = spawn(record.executablePath, args, {
145
146
  stdio: ["ignore", "ignore", stderr],
146
147
  detached: true,
package/dist/modal.d.ts CHANGED
@@ -24,8 +24,9 @@ export interface ModalProviderOptions extends Omit<HostedOptions, "desktop" | "m
24
24
  */
25
25
  connect?: "exec" | "dial";
26
26
  }
27
- /** The SDK's default server (modal-client@64880502:js/src/config.ts:143). */
28
- export declare const MODAL_DEFAULT_SERVER_URL = "https://api.modal.com:443";
27
+ /** The SDK's default server (modal-client@64880502:js/src/config.ts:143, which writes https's own port, :443), as
28
+ * httpsBase hands it to the client. */
29
+ export declare const MODAL_DEFAULT_SERVER_URL = "https://api.modal.com";
29
30
  /** What modalClient gives the SDK's ModalClient: the token, explicitly, so the SDK fills none of it in. */
30
31
  export interface ModalClientParams {
31
32
  tokenId: string;
@@ -38,7 +39,7 @@ export interface ModalClientOptions {
38
39
  /** The Modal token's id and secret. Serve passes its MODAL_TOKEN_ID and MODAL_TOKEN_SECRET; the conformance module the token it reads. */
39
40
  tokenId: string;
40
41
  tokenSecret: string;
41
- /** The server the token goes to, https alone; default the SDK's, https://api.modal.com:443. */
42
+ /** The server the token goes to, https alone; default the SDK's, https://api.modal.com. */
42
43
  serverUrl?: string;
43
44
  /** The SDK's ModalClient; imported from the host's modal package by default. */
44
45
  ModalClient?: ModalClientConstructor;
@@ -58,8 +59,8 @@ export interface ModalCreateOptions extends Omit<ModalProviderOptions, "sdk">, M
58
59
  * So this is the library's one touch of the environment, a guard and not a setting (README, Settings): an ambient
59
60
  * MODAL_SERVER_URL is refused, and MODAL_SERVER_URL is set to the chosen server only while the client is constructed,
60
61
  * and put back after, so no profile can redirect the key. process.env is the whole process's: constructions run one at a
61
- * time, each waiting for the last, so none sees another's server. The modal package is the host's: it is imported only
62
- * here.
62
+ * time, each waiting for the last, so none sees another's server. The modal package, an optional dependency, is loaded
63
+ * only here.
63
64
  */
64
65
  export declare function modalClient({ tokenId, tokenSecret, serverUrl, ModalClient }: ModalClientOptions): Promise<ModalSdk>;
65
66
  /**
package/dist/modal.js CHANGED
@@ -8,12 +8,12 @@ import { AGENTRUN_DIAL, PID_WRAPPER, pidKill, pidStderr } from "./hosted/scripts
8
8
  import { connectOf, kindRefusal } from "./descriptor.js";
9
9
  import { isWhole } from "./hosted/values.js";
10
10
  import { ok } from "./result.js";
11
+ import { vendorSdk } from "./vendor-sdk.js";
11
12
  /** A GPU as the SDK takes it: the type, then :count past one ("T4", "H100:8"). */
12
13
  const modalGpu = ({ type, count }) => (count === 1 ? type : `${type}:${count}`);
13
- /** The SDK's default server (modal-client@64880502:js/src/config.ts:143). */
14
- export const MODAL_DEFAULT_SERVER_URL = "https://api.modal.com:443";
15
- /** Not a literal, so no type checker or bundler resolves the SDK from this package. */
16
- const MODAL_PACKAGE = "modal";
14
+ /** The SDK's default server (modal-client@64880502:js/src/config.ts:143, which writes https's own port, :443), as
15
+ * httpsBase hands it to the client. */
16
+ export const MODAL_DEFAULT_SERVER_URL = "https://api.modal.com";
17
17
  /** The construction now running, or the last one: the next waits for it, so two never overlap. */
18
18
  let constructing = Promise.resolve();
19
19
  /**
@@ -28,8 +28,8 @@ let constructing = Promise.resolve();
28
28
  * So this is the library's one touch of the environment, a guard and not a setting (README, Settings): an ambient
29
29
  * MODAL_SERVER_URL is refused, and MODAL_SERVER_URL is set to the chosen server only while the client is constructed,
30
30
  * and put back after, so no profile can redirect the key. process.env is the whole process's: constructions run one at a
31
- * time, each waiting for the last, so none sees another's server. The modal package is the host's: it is imported only
32
- * here.
31
+ * time, each waiting for the last, so none sees another's server. The modal package, an optional dependency, is loaded
32
+ * only here.
33
33
  */
34
34
  export async function modalClient({ tokenId, tokenSecret, serverUrl = MODAL_DEFAULT_SERVER_URL, ModalClient }) {
35
35
  if (typeof tokenId !== "string" || tokenId === "" || typeof tokenSecret !== "string" || tokenSecret === "") {
@@ -39,7 +39,7 @@ export async function modalClient({ tokenId, tokenSecret, serverUrl = MODAL_DEFA
39
39
  const ambient = `the Modal provider refuses to start while MODAL_SERVER_URL is set: the SDK would send the key there. Unset it, and pass the server as options.serverUrl if it is not ${MODAL_DEFAULT_SERVER_URL}`;
40
40
  if (process.env.MODAL_SERVER_URL)
41
41
  throw new Error(ambient);
42
- const Client = ModalClient ?? (await import(MODAL_PACKAGE)).ModalClient;
42
+ const Client = ModalClient ?? (await vendorSdk(MODAL.label, "modal")).ModalClient;
43
43
  // getProfile reads MODAL_SERVER_URL from process.env when the client is constructed (client.ts:123), and the
44
44
  // control-plane client is made then (client.ts:175); afterwards process.env is as it was. One construction at a time.
45
45
  const turn = constructing.then(() => {
package/dist/morph.js CHANGED
@@ -26,8 +26,7 @@ import { httpsBase, jsonOf, rest } from "./hosted/rest.js";
26
26
  import { pemOf, SshExec, SshTunnelError } from "./hosted/ssh-exec.js";
27
27
  import { DOMAIN, dateOf, sizeRefusals } from "./hosted/values.js";
28
28
  import { failFor, ok } from "./result.js";
29
- /** Not a literal, so no type checker or bundler resolves ssh2 from this package. */
30
- const SSH2_PACKAGE = "ssh2";
29
+ import { vendorSdk } from "./vendor-sdk.js";
31
30
  /** The SDKs' base (api.ts:11 MORPH_BASE_URL) and SSH gateway (api.ts:12-13). */
32
31
  const DEFAULT_API_URL = "https://cloud.morph.so/api";
33
32
  const DEFAULT_SSH_HOST = "ssh.cloud.morph.so";
@@ -447,7 +446,7 @@ class MorphHost {
447
446
  export async function create(options) {
448
447
  const { ssh2: given, ...rest } = options ?? {};
449
448
  // ssh2 is CommonJS: its Client is a named export of the module, and of its default.
450
- const loaded = given ?? (await import(SSH2_PACKAGE));
449
+ const loaded = given ?? (await vendorSdk(MORPH.label, "ssh2"));
451
450
  const ssh2 = typeof loaded.Client === "function" ? loaded : loaded.default;
452
451
  return new MorphProvider({ ...rest, ssh2: ssh2 });
453
452
  }
@@ -481,17 +480,15 @@ export class MorphProvider extends HostedProvider {
481
480
  throw new Error("options.ssh2 must be the ssh2 package (its Client class): the host installs it, as it does for Agent37");
482
481
  if (typeof fetcher !== "function")
483
482
  throw new Error("options.fetch must be a function, as the global fetch is");
484
- const api = new URL(httpsBase(apiUrl, "the Morph API URL"));
485
- if (api.search !== "" || api.hash !== "")
486
- throw new Error(`the Morph API URL takes no query or fragment, as ${DEFAULT_API_URL} has none: ${JSON.stringify(apiUrl)}`);
483
+ const api = httpsBase(apiUrl, "the Morph API URL");
487
484
  if (typeof sshHost !== "string" || !(DOMAIN.test(sshHost) || isIP(sshHost) !== 0))
488
485
  throw new Error(`sshHost must be a host name such as ${DEFAULT_SSH_HOST}, not ${JSON.stringify(sshHost)}`);
489
486
  if (!Number.isSafeInteger(sshPort) || sshPort < 1 || sshPort > 65_535)
490
487
  throw new Error(`sshPort must be a TCP port, not ${JSON.stringify(sshPort)}`);
491
- super(new MorphHost({ apiKey, ssh2, fetch: fetcher, apiUrl: api.href.replace(/\/+$/, ""), sshHost, sshPort }), { ...rest, timeouts });
488
+ super(new MorphHost({ apiKey, ssh2, fetch: fetcher, apiUrl: api, sshHost, sshPort }), { ...rest, timeouts });
492
489
  }
493
490
  }
494
491
  /** The account a key reaches, in words, for the sweep's scope: the key's sha256 prefix, never the key. */
495
492
  export function accountOf(apiKey, apiUrl = DEFAULT_API_URL) {
496
- return `the Morph account of the key sha256:${createHash("sha256").update(apiKey, "utf8").digest("hex").slice(0, 12)} at ${apiUrl.replace(/\/+$/, "")}`;
493
+ return `the Morph account of the key sha256:${createHash("sha256").update(apiKey, "utf8").digest("hex").slice(0, 12)} at ${httpsBase(apiUrl, "the Morph API URL")}`;
497
494
  }
@@ -26,8 +26,9 @@ export interface OrgoRest {
26
26
  signal?: AbortSignal;
27
27
  }): Promise<Result<T> | OrgoFailure>;
28
28
  }
29
- /** Orgo's REST API with a key: every call bounded, every failure a code and words that never hold the key. */
30
- export declare function orgoRest({ apiKey, apiUrl, fetch: fetcher }: {
29
+ /** Orgo's REST API with a key: every call bounded, every failure a code and words that never hold the key. `apiUrl` is
30
+ * httpsBase's answer, as the providers pass it. */
31
+ export declare function orgoRest({ apiKey, apiUrl: base, fetch: fetcher }: {
31
32
  apiKey: string;
32
33
  apiUrl?: string;
33
34
  fetch?: typeof fetch;