@parcha/agentrun-serve 0.1.0-beta.43 → 0.1.0-beta.44

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 (141) hide show
  1. package/CHANGELOG.md +105 -0
  2. package/README.md +213 -24
  3. package/dist/cli.js +42 -8
  4. package/dist/composio-preset.d.ts +4 -3
  5. package/dist/composio-preset.js +12 -4
  6. package/dist/composio-triggers.d.ts +20 -2
  7. package/dist/composio-triggers.js +183 -17
  8. package/dist/computer-lost.d.ts +11 -0
  9. package/dist/computer-lost.js +19 -0
  10. package/dist/computer-record.d.ts +10 -2
  11. package/dist/computer-record.js +50 -18
  12. package/dist/computer-setting.d.ts +1 -0
  13. package/dist/computer-setting.js +2 -2
  14. package/dist/console/assets/index-BUktRvS-.css +1 -0
  15. package/dist/console/assets/index-nB9kTfIN.js +711 -0
  16. package/dist/console/index.html +2 -2
  17. package/dist/errors.d.ts +1 -0
  18. package/dist/errors.js +3 -0
  19. package/dist/harness-table.d.ts +51 -3
  20. package/dist/harness-table.js +101 -13
  21. package/dist/harness.d.ts +18 -1
  22. package/dist/harness.js +21 -9
  23. package/dist/host.d.ts +12 -10
  24. package/dist/host.js +18 -16
  25. package/dist/import-worker.d.ts +3 -0
  26. package/dist/import-worker.js +7 -5
  27. package/dist/import.d.ts +22 -1
  28. package/dist/import.js +141 -28
  29. package/dist/learn/check.d.ts +3 -0
  30. package/dist/learn/check.js +1 -1
  31. package/dist/learn/compile.js +1 -1
  32. package/dist/learn/delete.d.ts +17 -0
  33. package/dist/learn/delete.js +44 -0
  34. package/dist/learn/promote.d.ts +7 -1
  35. package/dist/learn/promote.js +8 -4
  36. package/dist/learn/skills.d.ts +4 -0
  37. package/dist/learn/skills.js +17 -1
  38. package/dist/learn/workflow-nodes.d.ts +22 -1
  39. package/dist/learn/workflow-nodes.js +28 -9
  40. package/dist/learning-cost.d.ts +100 -0
  41. package/dist/learning-cost.js +116 -1
  42. package/dist/learning-evals.d.ts +2 -0
  43. package/dist/learning-evals.js +4 -3
  44. package/dist/learning-routes.d.ts +8 -0
  45. package/dist/learning-routes.js +17 -0
  46. package/dist/learning.d.ts +1 -1
  47. package/dist/listen-first.d.ts +30 -0
  48. package/dist/listen-first.js +115 -0
  49. package/dist/llms.txt +2 -1
  50. package/dist/mcp-servers-store.d.ts +12 -12
  51. package/dist/model.d.ts +8 -4
  52. package/dist/model.js +16 -8
  53. package/dist/openapi.js +115 -39
  54. package/dist/owner.d.ts +8 -0
  55. package/dist/owner.js +11 -0
  56. package/dist/paid-calls.d.ts +6 -0
  57. package/dist/paid-calls.js +11 -1
  58. package/dist/place.d.ts +8 -3
  59. package/dist/place.js +13 -9
  60. package/dist/provider.js +15 -1
  61. package/dist/run-learning-served.d.ts +1 -1
  62. package/dist/run-model-key.d.ts +64 -0
  63. package/dist/run-model-key.js +147 -0
  64. package/dist/runner/adapter-loop.d.ts +6 -0
  65. package/dist/runner/adapter-loop.js +9 -2
  66. package/dist/runner/adapter-run-spec.d.ts +6 -3
  67. package/dist/runner/adapter-run-spec.js +70 -23
  68. package/dist/runner/adapters/index.d.ts +4 -2
  69. package/dist/runner/adapters/index.js +13 -4
  70. package/dist/runner/audit.d.ts +4 -0
  71. package/dist/runner/audit.js +15 -4
  72. package/dist/runner/beside.d.ts +2 -1
  73. package/dist/runner/beside.js +5 -2
  74. package/dist/runner/claim-secrets.d.ts +49 -0
  75. package/dist/runner/claim-secrets.js +110 -1
  76. package/dist/runner/cli-run-spec.d.ts +2 -1
  77. package/dist/runner/cli-run-spec.js +32 -13
  78. package/dist/runner/commands.d.ts +3 -6
  79. package/dist/runner/feedback-round.d.ts +3 -2
  80. package/dist/runner/feedback-round.js +7 -3
  81. package/dist/runner/harness-loops.js +30 -8
  82. package/dist/runner/journal-kinds.d.ts +5 -0
  83. package/dist/runner/learning-end.d.ts +3 -0
  84. package/dist/runner/learning-end.js +4 -0
  85. package/dist/runner/loop-contract.d.ts +6 -0
  86. package/dist/runner/loop-contract.js +4 -0
  87. package/dist/runner/loop.js +6 -2
  88. package/dist/runner/main.d.ts +1 -0
  89. package/dist/runner/main.js +24 -7
  90. package/dist/runner/memory-claim.d.ts +9 -6
  91. package/dist/runner/memory-claim.js +12 -9
  92. package/dist/runner/promotion.d.ts +5 -0
  93. package/dist/runner/promotion.js +46 -7
  94. package/dist/runner/reflect-hook.d.ts +4 -0
  95. package/dist/runner/reflect-hook.js +22 -3
  96. package/dist/runner/runner.js +57 -4
  97. package/dist/runner/store-secrets.js +9 -5
  98. package/dist/runner/workflow-spec.js +10 -2
  99. package/dist/runs-over-store.d.ts +5 -4
  100. package/dist/runs-over-store.js +13 -3
  101. package/dist/sdk/workflows.d.ts +1 -1
  102. package/dist/server.d.ts +64 -50
  103. package/dist/server.js +457 -120
  104. package/dist/store/index.d.ts +2 -2
  105. package/dist/store/index.js +1 -1
  106. package/dist/store/seal.d.ts +20 -2
  107. package/dist/store/seal.js +24 -8
  108. package/dist/store/sqlite/run-launch.d.ts +4 -1
  109. package/dist/store/sqlite/run-launch.js +12 -0
  110. package/dist/store/sqlite/store.d.ts +3 -2
  111. package/dist/store/sqlite/store.js +118 -16
  112. package/dist/store/store.d.ts +38 -3
  113. package/dist/store-reads/analytics.js +11 -1
  114. package/dist/store-reads/learning.d.ts +41 -2
  115. package/dist/store-reads/learning.js +158 -5
  116. package/dist/store-reads/stats.js +13 -3
  117. package/dist/store-view.d.ts +5 -1
  118. package/dist/store-view.js +12 -11
  119. package/dist/telemetry.d.ts +59 -0
  120. package/dist/telemetry.js +153 -0
  121. package/dist/tool-keys-store.d.ts +1 -1
  122. package/dist/tool-keys.d.ts +2 -2
  123. package/dist/tool-plane.d.ts +12 -12
  124. package/dist/tools.d.ts +11 -11
  125. package/dist/tools.js +18 -5
  126. package/dist/trigger-adapter.d.ts +3 -0
  127. package/dist/trigger-adapters.d.ts +4 -0
  128. package/dist/trigger-adapters.js +13 -0
  129. package/dist/trigger-composio.d.ts +58 -1
  130. package/dist/trigger-composio.js +160 -6
  131. package/dist/triggers.d.ts +4 -0
  132. package/dist/triggers.js +22 -3
  133. package/dist/validate.d.ts +11 -7
  134. package/dist/validate.js +8 -7
  135. package/dist/workspace/computer-for-claim.d.ts +15 -5
  136. package/dist/workspace/computer-for-claim.js +228 -32
  137. package/dist/workspace/resolve-computer.d.ts +8 -2
  138. package/dist/workspace/resolve-computer.js +1 -1
  139. package/package.json +10 -9
  140. package/dist/console/assets/index-BrcDSBD8.css +0 -1
  141. package/dist/console/assets/index-Bz6IWncl.js +0 -711
package/dist/validate.js CHANGED
@@ -57,8 +57,9 @@ export const skillNames = (files) => [...files].filter((path) => path.endsWith(S
57
57
  /**
58
58
  * A definition as `POST /agents` and `PUT .../definition` take it: what one revision of an agent keeps. `instructions`
59
59
  * makes an agentic revision, `workflow` (an agentrun-dsl workflow) a workflow revision. `creating` asks for a name.
60
+ * `harnesses`: the ids `harness` may name, the server's table's (harness-table.ts harnessIds); the built-in ones by default.
60
61
  */
61
- export function definitionIssues(definition, { at = "definition", creating = true } = {}) {
62
+ export function definitionIssues(definition, { at = "definition", creating = true, harnesses = HARNESSES } = {}) {
62
63
  if (!isObject(definition))
63
64
  return [issue(at, definition === undefined ? "missing" : "wrong_type", `${at} is not an object`)];
64
65
  const out = [];
@@ -105,8 +106,8 @@ export function definitionIssues(definition, { at = "definition", creating = tru
105
106
  }
106
107
  }
107
108
  }
108
- if (d.harness !== undefined && !HARNESSES.includes(d.harness))
109
- out.push(issue(`${at}.harness`, "not_an_option", `${at}.harness is one of ${HARNESSES.join(", ")}`));
109
+ if (d.harness !== undefined && !harnesses.includes(d.harness))
110
+ out.push(issue(`${at}.harness`, "not_an_option", `${at}.harness is one of ${harnesses.join(", ")}`));
110
111
  if (d.place !== undefined)
111
112
  out.push(...placeIssues(d.place, `${at}.place`));
112
113
  if (d.computer !== undefined)
@@ -202,12 +203,12 @@ export function skillIssues(named, files) {
202
203
  ];
203
204
  }
204
205
  /** What is wrong with `{definition, skills?, note?}`, as checkDefinitionBody refuses it: every field issue. */
205
- export function definitionBodyIssues(body, { creating = true } = {}) {
206
+ export function definitionBodyIssues(body, { creating = true, harnesses } = {}) {
206
207
  const out = [];
207
208
  for (const key of Object.keys(body))
208
209
  if (!["definition", "skills", "note"].includes(key))
209
210
  out.push(issue(key, "not_allowed", `The body keeps no field ${key}.`, `Remove ${key}.`));
210
- out.push(...definitionIssues(body.definition, { creating }));
211
+ out.push(...definitionIssues(body.definition, { creating, ...(harnesses ? { harnesses } : {}) }));
211
212
  if (body.skills !== undefined || creating)
212
213
  skillFileIssues(body.skills ?? {}, out);
213
214
  if (body.note !== undefined && !(typeof body.note === "string" && body.note.length <= 2_000))
@@ -219,8 +220,8 @@ export function definitionBodyIssues(body, { creating = true } = {}) {
219
220
  * files (absent on an edit: the current revision's); `note` says what the revision changes. Throws `422 input_invalid`
220
221
  * naming every field that is wrong.
221
222
  */
222
- export function checkDefinitionBody(body, { creating = true } = {}) {
223
- const out = definitionBodyIssues(body, { creating });
223
+ export function checkDefinitionBody(body, { creating = true, harnesses } = {}) {
224
+ const out = definitionBodyIssues(body, { creating, ...(harnesses ? { harnesses } : {}) });
224
225
  if (out.length)
225
226
  throw invalid(out);
226
227
  return { definition: body.definition, ...(body.skills !== undefined || creating ? { skills: (body.skills ?? {}) } : {}), ...(typeof body.note === "string" ? { note: body.note } : {}) };
@@ -115,11 +115,12 @@ export interface ComputerForClaimDeps {
115
115
  readonly revokeMount?: () => Promise<void>;
116
116
  /** The live view's registration for a desktop or a phone (proxy-only). Absent: no view is opened. */
117
117
  readonly openComputerView?: OpenComputerView;
118
- /** Where the agent's setting asks for a video of its desktop's or phone's screen (computer.record): the run's
118
+ /** Where the agent's setting asks for a video of its computer's screen (computer.record): the run's
119
119
  * recordings folder on this machine (paths.ts recordingsFolder) and where its lines on the run's timeline go
120
- * (computer-record.ts startRecording; for tests, the program in ffmpeg's place and the bounds). The computer this claim
121
- * attaches is recorded through a watch of its own, with or without a viewer, until its release, the run's end or its
122
- * park. Absent: nothing is recorded. */
120
+ * (computer-record.ts startRecording; for tests, the program in ffmpeg's place and the bounds). The desktop or phone
121
+ * this claim attaches is recorded through a watch of its own, with or without a viewer, until its release, the run's
122
+ * end or its park; a browser's sessions each by the run's browser tool, through its ClaimBrowser's `record`. Absent:
123
+ * nothing is recorded. */
123
124
  readonly recordings?: Pick<RecordInput, "folder" | "say" | "ffmpeg" | "limits">;
124
125
  /** Told once, before the claim waits on its computer's image (a provider that makes its own: Docker's recipe built on
125
126
  * a host that lacks it, or a named image pulled); never when the host has it. The run's caller says it on the run's
@@ -144,8 +145,17 @@ export interface ComputerForClaimDeps {
144
145
  * it refuses is refused with code computer_unavailable before anything is made. Absent: every kind. */
145
146
  readonly refuseKind?: (kind: Exclude<ComputerSettingKind, "none">) => string | undefined;
146
147
  /** Told what became of the agent's own computer at the claim (a persistent setting): made, attached from an earlier
147
- * run, or made again because the one this server kept is gone. The run's caller says it on the run's timeline. */
148
+ * run, or made again because the one this server kept is gone; and when a sandbox the claim made was lost mid-run and
149
+ * a new one started in its place (computer-lost.ts lostRecreatedWords). The run's caller says it on the run's
150
+ * timeline. */
148
151
  readonly onComputerNote?: (words: string) => void;
152
+ /** The most new sandboxes the claim starts in place of ones its provider lost mid-run (lostAware); the next loss past
153
+ * them ends the run, code computer_unavailable. Default LOST_RECREATES (2). */
154
+ readonly recreates?: number;
155
+ /** Stops the run for good in `words`, from any caller (paid-calls.ts stopRunWith over the run's ledger's pause): how a
156
+ * loss past `recreates` ends the run, whoever's call found it (the owner's computer channel too). Absent: the ledger
157
+ * of the tool call that found it (stopRun), and a loss found outside one stops nothing. */
158
+ readonly stopRun?: (words: string) => Promise<void>;
149
159
  /** Whether the run's journal says an earlier claim made the run a computer of its own (ClaimComputer.made, recorded by
150
160
  * the adapter loop: computer-journal.ts hadComputer): asked at a later claim that makes a fresh one, before anything
151
161
  * is rented, so a claim that finds no older computer of the run to let go (the earlier claim let its own go at its
@@ -17,6 +17,12 @@
17
17
  // journal says an earlier claim made, hadComputer), the ready line says so (and that the kept one's time had passed,
18
18
  // `lapsed`), and the run's tools and model are told (run-tools.ts, the adapter loop's computer note).
19
19
  //
20
+ // A sandbox the claim made can be lost mid-run (its vendor deleted it, or no longer has it): the call that finds it lost
21
+ // fails, and the next call of the run's tools starts a new one in its place under this claim (lostAware), its folder
22
+ // mounted again (Mode 2: a new mount credential, the lost one's removed), said on the run's timeline, up to `recreates`
23
+ // times a claim; the loss after that ends the run, code computer_unavailable. A provider error that is not a loss (a 5xx,
24
+ // a timeout) starts nothing. A desktop, a phone, a paired computer and the agent's own are never started again so.
25
+ //
20
26
  // A provider is made with its keys (the server's environment's, else the store's sealed keys, through the composer's
21
27
  // keyOf: computer-deps.ts), by the names the registry declares, through serve's own
22
28
  // map of key names to options (computer-keys.ts providerOptions); a provider that keeps sessions with no labels of their
@@ -35,6 +41,8 @@ import { isBrowserProvider, ownerFilter, releaseOlder, RUN_LABEL, runLabels } fr
35
41
  import { startRecording } from "../computer-record.js";
36
42
  import { computerOfPlace } from "../computer-setting.js";
37
43
  import { KEY_TABLE, providerOptions } from "../computer-keys.js";
44
+ import { LOST_RECREATES, lostEnd, lostRecreatedWords } from "../computer-lost.js";
45
+ import { inToolCall, stopRun } from "../paid-calls.js";
38
46
  import { getSealedKey } from "../server-keys.js";
39
47
  import { agentComputerOf, forgetAgentComputer, holdAgentComputer, keepAgentComputer, liveHolderOf, reconcileAgentComputer, serverIdOf } from "./agent-computer.js";
40
48
  import { pairedProvider, withPaired } from "./attached-computers.js";
@@ -245,6 +253,125 @@ async function providerLaunch(provider, claim, spec, signal) {
245
253
  }
246
254
  return { ...providerComputer(provider, ref, connected.value), releasedOlder };
247
255
  }
256
+ /** The words a hosted provider's connection answers every call in once its vendor deleted the machine (the computer
257
+ * package's hosted deletedSaid: "the computer <name> (<id>) was deleted: <vendor> no longer has it"). */
258
+ const DELETED_SAID = /^the computer \S+ \(\S+\) was deleted: /;
259
+ /**
260
+ * `first`, a sandbox the claim made through its provider (or took back from the run's park), held so its loss is not the
261
+ * run's: a call it answers deleted (the hosted connection's own words, DELETED_SAID), or gone with its provider
262
+ * confirming it no longer has it (attach answers not_found or gone), marks it lost, and that call answers as it did. The
263
+ * next call made inside one of the run's tool calls starts a new one in its place (`renewal.remake`, one at a time
264
+ * however many calls ask) and goes to it: the lost one let go, the run's Timeline told (`started`). Each new one is the
265
+ * claim's, under its epoch: a later claim lets it go as it lets any of the run's older computers go. A start that fails
266
+ * answers its words and counts for nothing: the next call tries again under the same request, so a retry finds what an
267
+ * earlier try made. Gone with the provider still reporting the machine, or its read failing (a 5xx, a timeout), is not
268
+ * lost: the call's own answer stands, and so does a read that comes back after another call already replaced the one it
269
+ * asked about. A loss once `renewal.max` new ones were started ends the run at once (`renewal.stop`, computer-lost.ts
270
+ * lostEnd's words, code computer_unavailable), the call that found it answering those words, as every later call does.
271
+ * A call outside a tool call (the run's end sweeping its scratch, the owner's computer channel) gets the loss's own
272
+ * answer and starts nothing.
273
+ */
274
+ function lostAware(first, renewal) {
275
+ let current = first;
276
+ /** Why the current one is lost, until a new one replaces it. */
277
+ let lost;
278
+ /** How many new ones this claim started. */
279
+ let made = 0;
280
+ /** The current one was let go since it was lost (a failed start's retry does not let it go again). */
281
+ let letGo = false;
282
+ /** The bound was passed: every call answers this. */
283
+ let spent;
284
+ let renewing;
285
+ let released = false;
286
+ /** Whether `error`, answered by `held`, says its provider no longer has it. */
287
+ const goneFrom = async (held, error) => {
288
+ if (error.code === "not_found")
289
+ return DELETED_SAID.test(error.message);
290
+ if (error.code !== "gone")
291
+ return false;
292
+ const found = await renewal.provider.attach({ id: held.ref.id }).catch(() => undefined);
293
+ return found !== undefined && !found.ok && (found.error.code === "not_found" || found.error.code === "gone");
294
+ };
295
+ /** `why`, the current one's loss: past the bound, the run's end, at once. */
296
+ const lose = async (why) => {
297
+ if (made < renewal.max) {
298
+ lost = why;
299
+ letGo = false;
300
+ return why;
301
+ }
302
+ spent = { code: "not_found", message: lostEnd(renewal.max, why.message) };
303
+ await renewal.stop(spent.message);
304
+ return spent;
305
+ };
306
+ /** A new one in place of the lost one, or why the run has none now. */
307
+ const renew = async (why) => {
308
+ // The lost one's resources go first: a vendor's delete of one it no longer has is done already.
309
+ if (!letGo) {
310
+ await current.release().catch(() => undefined);
311
+ letGo = true;
312
+ }
313
+ let fresh;
314
+ try {
315
+ fresh = await renewal.remake(made + 1);
316
+ }
317
+ catch (error) {
318
+ return { code: "gone", message: `${why.message}; a new sandbox could not be started: ${error instanceof Error ? error.message : String(error)}` };
319
+ }
320
+ if (released) {
321
+ await fresh.release().catch(() => undefined);
322
+ return why;
323
+ }
324
+ made += 1;
325
+ current = fresh;
326
+ lost = undefined;
327
+ renewal.started(fresh.ref.name);
328
+ return undefined;
329
+ };
330
+ const client = {
331
+ async call(method, params, options) {
332
+ if (spent)
333
+ return { ok: false, error: spent };
334
+ if (lost) {
335
+ if (!renewal.may())
336
+ return { ok: false, error: lost };
337
+ const why = lost;
338
+ const failed = await (renewing ??= renew(why).finally(() => (renewing = undefined)));
339
+ if (failed)
340
+ return { ok: false, error: failed };
341
+ }
342
+ const held = current;
343
+ const answered = await held.client.call(method, params, options);
344
+ if (answered.ok || held !== current || lost || spent)
345
+ return answered;
346
+ const gone = await goneFrom(held, answered.error);
347
+ // Read back after another call replaced it, or found it lost, or the run ended: this answer alone stands.
348
+ if (!gone || held !== current || lost || spent)
349
+ return answered;
350
+ return { ok: false, error: await lose(answered.error) };
351
+ },
352
+ close() {
353
+ current.client.close();
354
+ },
355
+ };
356
+ return {
357
+ get id() {
358
+ return current.id;
359
+ },
360
+ get ref() {
361
+ return current.ref;
362
+ },
363
+ groups: first.groups,
364
+ machine: first.machine,
365
+ hello: first.hello,
366
+ client,
367
+ readBack: () => current.readBack(),
368
+ close: () => current.close(),
369
+ async release() {
370
+ released = true;
371
+ await current.release();
372
+ },
373
+ };
374
+ }
248
375
  /** The computer an earlier claim of the run kept at its park (`kept`), attached again through `provider` and connected,
249
376
  * or undefined when its provider no longer has it or it does not connect (one that does not is deleted). */
250
377
  async function keptLaunch(provider, kept, signal) {
@@ -435,6 +562,77 @@ store, deps) {
435
562
  throw new Error(options.error.message);
436
563
  return make({ ...options.options, ...configuration.options }, { ledger: storeLedger(store.computerLedger, entry.id), ...(launch.boxAllow === undefined ? {} : { boxAllow: launch.boxAllow }) });
437
564
  };
565
+ /** What a computer of `kind` from `entry` is made with under this claim, but its mount: the deps' spec, within what
566
+ * `provider` declares it makes, from the image it prepares (readyImage) or the spec's, under the claim's labels. */
567
+ const specOf = async (entry, provider, kind, configuration, signal, gpu) => {
568
+ // What this provider makes, as it declares it: the spec asks for one of its networks, within its lifetime
569
+ // (computer-deps.ts computerSpecOf).
570
+ const { network: networks, maxLifetimeMs } = provider.capabilities();
571
+ const run = {
572
+ ...(launch.boxAllow === undefined ? {} : { boxAllow: launch.boxAllow }),
573
+ ...(launch.boxAllowSet ? { boxAllowSet: true } : {}),
574
+ ...(networks ? { networks } : {}),
575
+ ...(typeof maxLifetimeMs === "number" ? { maxLifetimeMs } : {}),
576
+ };
577
+ // A provider that declares it prepares its own image (its prepareImage(): its recipe built when the engine lacks it,
578
+ // an image by name pulled) does so first, and the computer starts from the tag it answers: the recipe's tag is in no
579
+ // registry, so a run of it unbuilt would be refused. The spec comes first, so a setting it refuses builds nothing. A
580
+ // configuration that names its image starts from it, else the kind's default.
581
+ const asked = deps.spec(entry, kind, run, configuration.image);
582
+ const ready = await readyImage(entry, provider, signal, deps.onImageWait);
583
+ const image = ready ?? asked.image;
584
+ if (image === undefined)
585
+ throw new Error(`${entry.label} names no image for its ${kind} computer and prepares none`);
586
+ return { ...asked, image, labels: runLabels(launch.runId, launch.epoch), ...(gpu ? { gpu } : {}) };
587
+ };
588
+ /** How a sandbox of `provider` this claim holds is started again once its provider lost it (lostAware): made from
589
+ * `specNow` (the lost one's spec, or for one taken back from the park this claim's own, read when it is needed), under
590
+ * this claim's labels and its own request (the claim's, then which new one), so a retry of it under this epoch finds
591
+ * the one it made. Where it mounts the run's folder (`mounts`), the lost one's mount credential is removed (Mode 2) and
592
+ * a new mount asked for, which is read back before the new one serves a call. */
593
+ const renewalOf = (provider, entry, specNow, mounts) => ({
594
+ provider,
595
+ max: deps.recreates ?? LOST_RECREATES,
596
+ async remake(times) {
597
+ deps.onStarting?.({ provider: entry.label, kind: "sandbox" });
598
+ const spec = await specNow();
599
+ let mount;
600
+ if (mounts) {
601
+ await deps.revokeMount?.();
602
+ mount = await deps.workspace.mountSpec();
603
+ }
604
+ const call = deps.signal ? { signal: deps.signal } : {};
605
+ const created = await provider.create({ ...spec, ...(mount ? { mount } : {}) }, { requestId: `${claimRequestId(launch)}#lost-${times}`, ...call });
606
+ if (!created.ok)
607
+ throw new Error(created.error.message);
608
+ const ref = { id: created.value.id, name: created.value.name };
609
+ const connected = await provider.connect(ref);
610
+ if (!connected.ok) {
611
+ await provider.release(ref, "delete").catch(() => undefined);
612
+ throw new Error(connected.error.message);
613
+ }
614
+ const again = providerComputer(provider, ref, connected.value);
615
+ if (mount) {
616
+ try {
617
+ await deps.workspace.attach({ id: ref.id, client: again.client, readBack: () => again.readBack() }, { ...deps.check, epoch: deps.check.epoch ?? launch.epoch });
618
+ }
619
+ catch (error) {
620
+ await again.release().catch(() => undefined);
621
+ throw error;
622
+ }
623
+ }
624
+ return again;
625
+ },
626
+ started: (name) => {
627
+ // A park after this keeps the new one, whose labels and mount are this claim's epoch's (a kept one taken back
628
+ // carried its park's).
629
+ if (keepable)
630
+ keepable.epoch = launch.epoch;
631
+ deps.onComputerNote?.(lostRecreatedWords(name));
632
+ },
633
+ stop: (words) => (deps.stopRun ?? stopRun)(words),
634
+ may: () => inToolCall() && deps.signal?.aborted !== true,
635
+ });
438
636
  const side = {
439
637
  keysOf: providerKeys(kinds, deps.keyOf ?? (async (name) => (deps.sealKey ? await getSealedKey(store, deps.sealKey, name) : undefined))),
440
638
  answers: deps.answers ?? (async () => false),
@@ -443,7 +641,7 @@ store, deps) {
443
641
  // time is not over: taken off its row first (computer-kept.ts takeKept), so its end and this claim never both have it,
444
642
  // then attached and connected again. Its mount, where it has one, stays the one it was made with: its credential is
445
643
  // this claim's from here (inheritMount). Never the agent's own computer, a paired one or --faux's.
446
- async reattach(entry, { kind, keys, configuration, persistent, signal }) {
644
+ async reattach(entry, { kind, keys, configuration, gpu, persistent, signal }) {
447
645
  const record = kept;
448
646
  kept = undefined;
449
647
  if (!record || !store.settings || persistent || paired.some((row) => row.id === entry.id))
@@ -459,10 +657,13 @@ store, deps) {
459
657
  return undefined;
460
658
  }
461
659
  const provider = await vendorProvider(entry, keys, configuration);
462
- const again = await keptLaunch(provider, record, signal);
463
- if (!again)
660
+ const taken = await keptLaunch(provider, record, signal);
661
+ if (!taken)
464
662
  return undefined;
465
663
  deps.inheritMount?.();
664
+ // A sandbox taken back is started again when it is lost as one this claim made (lostAware): the new one is this
665
+ // claim's, made from this claim's spec, its folder mounted.
666
+ const again = record.kind === "sandbox" ? lostAware(taken, renewalOf(provider, entry, () => specOf(entry, provider, kind, configuration, deps.signal, gpu), true)) : taken;
466
667
  keepable = { provider, entry: entry.id, kind: record.kind, computer: again, epoch: record.epoch };
467
668
  ownKind = record.kind;
468
669
  const screen = record.kind === "sandbox" ? undefined : record.kind;
@@ -492,25 +693,7 @@ store, deps) {
492
693
  return own;
493
694
  }
494
695
  const provider = pairedRow ? pairedProvider(pairedRow, deps.attached?.hub) : await vendorProvider(entry, keys, configuration);
495
- // What this provider makes, as it declares it: the spec asks for one of its networks, within its lifetime
496
- // (computer-deps.ts computerSpecOf).
497
- const { network: networks, maxLifetimeMs } = provider.capabilities();
498
- const run = {
499
- ...(launch.boxAllow === undefined ? {} : { boxAllow: launch.boxAllow }),
500
- ...(launch.boxAllowSet ? { boxAllowSet: true } : {}),
501
- ...(networks ? { networks } : {}),
502
- ...(typeof maxLifetimeMs === "number" ? { maxLifetimeMs } : {}),
503
- };
504
- // A provider that declares it prepares its own image (its prepareImage(): its recipe built when the engine lacks it,
505
- // an image by name pulled) does so first, and the computer starts from the tag it answers: the recipe's tag is in no
506
- // registry, so a run of it unbuilt would be refused. The spec comes first, so a setting it refuses builds nothing. A
507
- // configuration that names its image starts from it, else the kind's default.
508
- const asked = deps.spec(entry, kind, run, configuration.image);
509
- const ready = await readyImage(entry, provider, signal, deps.onImageWait);
510
- const image = ready ?? asked.image;
511
- if (image === undefined)
512
- throw new Error(`${entry.label} names no image for its ${kind} computer and prepares none`);
513
- const spec = { ...asked, image, labels: runLabels(launch.runId, launch.epoch), ...(mount ? { mount } : {}), ...(gpu ? { gpu } : {}) };
696
+ const spec = { ...(await specOf(entry, provider, kind, configuration, signal, gpu)), ...(mount ? { mount } : {}) };
514
697
  // A browser makes nothing here: the run's browser tool opens each session through it, so a session lives (and is
515
698
  // booked) only while the tool holds it.
516
699
  if (kind === "browser") {
@@ -545,12 +728,16 @@ store, deps) {
545
728
  // go. A paired computer is the same one at every claim, and is no computer of the run's own.
546
729
  const journalSays = !pairedRow && launch.epoch > 1 && (await deps.hadComputer?.()) === true;
547
730
  const fresh = await providerLaunch(provider, launch, spec, signal);
548
- launched = fresh;
731
+ // A sandbox the claim made is started again when its provider loses it mid-run (lostAware): never a paired
732
+ // computer, nor a desktop or a phone (a person may hold or watch it), nor the agent's own (persistent, above).
733
+ const { releasedOlder } = fresh;
734
+ const held = kind === "sandbox" && !pairedRow ? lostAware(fresh, renewalOf(provider, entry, async () => spec, mount !== undefined)) : fresh;
735
+ launched = held;
549
736
  if (!pairedRow)
550
737
  ownKind = kind;
551
738
  if (!pairedRow && (kind === "desktop" || kind === "phone" || kind === "sandbox"))
552
- keepable = { provider, entry: entry.id, kind, computer: fresh, epoch: launch.epoch };
553
- if (!pairedRow && (fresh.releasedOlder || journalSays))
739
+ keepable = { provider, entry: entry.id, kind, computer: held, epoch: launch.epoch };
740
+ if (!pairedRow && (releasedOlder || journalSays))
554
741
  replaced = { kind: kind, folderKept: deps.mode === 2 && mount !== undefined, ...(lapsed ? { lapsed: true } : {}) };
555
742
  }
556
743
  made = { id: launched.id, machine: launched.machine, ...(launched.watch ? { watch: launched.watch, ...(kind === "desktop" || kind === "phone" ? { gone: goneOf(provider, launched.id, listedUnder, kind) } : {}) } : {}) };
@@ -592,7 +779,17 @@ store, deps) {
592
779
  let hold;
593
780
  let held;
594
781
  let view;
595
- let recording;
782
+ // The agent asks for a video of the screen (computer.record): the desktop's or phone's, through a watch of the
783
+ // recorder's own while this claim holds it; each browser session's, through its live view's (the run's browser tool).
784
+ const recordings = [];
785
+ const record = deps.recordings && setting?.record === true
786
+ ? (watch, tag, kind) => {
787
+ const one = startRecording({ ...deps.recordings, watch, tag, kind });
788
+ recordings.push(one);
789
+ return one;
790
+ }
791
+ : undefined;
792
+ const runComputer = computer?.kind === "browser" && record ? { ...computer, browser: { ...computer.browser, record: (id, watch) => record(watch, id, "browser") } } : computer;
596
793
  if (computer && (computer.kind === "desktop" || computer.kind === "phone")) {
597
794
  const theHold = computerHold();
598
795
  if (deps.openComputerView && made?.watch) {
@@ -608,9 +805,8 @@ store, deps) {
608
805
  }
609
806
  view = opened.view;
610
807
  }
611
- // The agent asks for a video of the screen (computer.record): a watch of the recorder's own, while this claim holds it.
612
- if (deps.recordings && made?.watch && setting?.record === true)
613
- recording = startRecording({ ...deps.recordings, watch: made.watch, tag: made.id, kind: computer.kind });
808
+ if (record && made?.watch)
809
+ record(made.watch, made.id, computer.kind);
614
810
  // The run's end closes the hold (workspace/computer-hold.ts close()): a take in force ends `released` (the computer
615
811
  // goes; the composer's `ended` ViewEnd maps onto it), the agent's open ask is let go at once, and nothing is taken after.
616
812
  endHold = () => theHold.close();
@@ -619,7 +815,7 @@ store, deps) {
619
815
  }
620
816
  let released;
621
817
  const release = (why = "released") => (released ??= (async () => {
622
- await recording?.stop(typeof why === "object" ? "parked" : why);
818
+ await Promise.all(recordings.map((one) => one.stop(typeof why === "object" ? "parked" : why)));
623
819
  await Promise.resolve(view?.close(why)).catch(() => undefined);
624
820
  endHold();
625
821
  try {
@@ -634,7 +830,7 @@ store, deps) {
634
830
  const keeps = computer && keepable && store.settings ? keepable : undefined;
635
831
  const settings = store.settings;
636
832
  return {
637
- ...(computer ? { computer } : {}),
833
+ ...(runComputer ? { computer: runComputer } : {}),
638
834
  ...(hold ? { hold } : {}),
639
835
  ...(held ? { held } : {}),
640
836
  ...(replaced ? { replaced } : {}),
@@ -660,7 +856,7 @@ store, deps) {
660
856
  // kept, never that it ended; the hold with it; the machine and its mount stay.
661
857
  released = (async () => {
662
858
  // The recording pauses: the claim that resumes the run goes on in a new file.
663
- await recording?.stop("parked");
859
+ await Promise.all(recordings.map((one) => one.stop("parked")));
664
860
  await Promise.resolve(view?.close({ parked: cause, until: row.until })).catch(() => undefined);
665
861
  endHold();
666
862
  await keeps.computer.close();
@@ -1,6 +1,7 @@
1
1
  import { type ShellPlace } from "@parcha/agentrun-kernel/kernel";
2
2
  import { type BrowserFeatures, type BrowserFile, type BrowserSpec, type ComputerClient, type ComputerSettingKind, type GpuSpec, type Group, type HelloResult, type KindCapabilities, type MountReadBack, type MountSpec, type ProviderEntry, type Result } from "@parcha/agentrun-computer";
3
3
  import { type DockerDaemon } from "../docker-daemon.js";
4
+ import type { Recording, RecordWatch } from "../computer-record.js";
4
5
  import type { MountCheck } from "./attach.js";
5
6
  import type { RunComputer } from "./run-tools.js";
6
7
  import type { Workspace } from "./workspace.js";
@@ -10,8 +11,8 @@ export type { ComputerSettingKind, KindCapabilities, ProviderEntry, ShellPlace }
10
11
  /** An agent's computer setting. `image`: the one of the provider's configurations it selects; absent, the default. A
11
12
  * sandbox's may ask for GPUs. `persistent`: the agent keeps its own computer between runs (agent-computer.ts). A
12
13
  * desktop's or a phone's `surface` and `exec` go to the run's tools on the RunComputer (run-tools.ts); `exec: false`
13
- * also mounts no folder in it and gives the run no shell. A desktop's or a phone's `record`: the claim records its
14
- * screen (computer-for-claim.ts, computer-record.ts). */
14
+ * also mounts no folder in it and gives the run no shell. A desktop's, a phone's or a browser's `record`: the claim
15
+ * records its screen (computer-for-claim.ts, computer-record.ts). */
15
16
  export type ComputerSetting = {
16
17
  readonly kind: string;
17
18
  readonly provider?: string | null;
@@ -76,6 +77,10 @@ export type ClaimBrowser = {
76
77
  url(id: string): Promise<string>;
77
78
  /** Ends the session; one already gone is ended. */
78
79
  close(id: string): Promise<void>;
80
+ /** Where the agent's setting asks for it (computer.record), records session `id`'s screen through `watch` (its live
81
+ * view's, computer-record.ts browserWatch) until the caller stops it at the session's release, or the claim's release
82
+ * stops it. Absent: nothing is recorded. */
83
+ readonly record?: (id: string, watch: RecordWatch) => Recording;
79
84
  /** The files a session downloaded, kept by the provider: where its features declare downloads. */
80
85
  readonly downloads?: {
81
86
  list(id: string): Promise<BrowserFile[]>;
@@ -111,6 +116,7 @@ export type ClaimSide = {
111
116
  readonly kind: ComputerSettingKind;
112
117
  readonly keys: Readonly<Record<string, string>>;
113
118
  readonly configuration: KindCapabilities;
119
+ readonly gpu?: GpuSpec;
114
120
  readonly persistent?: true;
115
121
  readonly signal?: AbortSignal;
116
122
  }): Promise<(LaunchedComputer & {
@@ -311,7 +311,7 @@ export async function resolveComputer(given, mode, registry, side) {
311
311
  ports,
312
312
  async start({ workspace, check, signal }) {
313
313
  // A computer kept at the run's park, attached again: it mounts what it mounted, read back under its own epoch.
314
- const again = await side.reattach?.(entry, { kind, keys, configuration, ...(persistent ? { persistent: true } : {}), ...(signal ? { signal } : {}) });
314
+ const again = await side.reattach?.(entry, { kind, keys, configuration, ...(gpu ? { gpu: { type: gpu.type, count: gpu.count } } : {}), ...(persistent ? { persistent: true } : {}), ...(signal ? { signal } : {}) });
315
315
  const mount = mounts && !again ? await workspace.mountSpec() : undefined;
316
316
  let launched;
317
317
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcha/agentrun-serve",
3
- "version": "0.1.0-beta.43",
3
+ "version": "0.1.0-beta.44",
4
4
  "description": "The AgentRun server: the /v2 API and console over one store, with runners that run your agents; the deployable process of the AgentRun platform.",
5
5
  "keywords": [
6
6
  "agentrun",
@@ -54,14 +54,14 @@
54
54
  "@earendil-works/pi-coding-agent": "1.5.2",
55
55
  "@modelcontextprotocol/client": "2.4.0",
56
56
  "@modelcontextprotocol/server": "2.4.0",
57
- "@parcha/agentrun-computer": "0.1.0-beta.43",
58
- "@parcha/agentrun-decisions": "0.1.0-beta.43",
59
- "@parcha/agentrun-dsl": "0.1.0-beta.43",
60
- "@parcha/agentrun-harness-claude": "0.1.0-beta.43",
61
- "@parcha/agentrun-harness-codex": "0.1.0-beta.43",
62
- "@parcha/agentrun-jev": "0.1.0-beta.43",
63
- "@parcha/agentrun-kernel": "0.1.0-beta.43",
64
- "@parcha/pi-browser": "0.1.0-beta.43",
57
+ "@parcha/agentrun-computer": "0.1.0-beta.44",
58
+ "@parcha/agentrun-decisions": "0.1.0-beta.44",
59
+ "@parcha/agentrun-dsl": "0.1.0-beta.44",
60
+ "@parcha/agentrun-harness-claude": "0.1.0-beta.44",
61
+ "@parcha/agentrun-harness-codex": "0.1.0-beta.44",
62
+ "@parcha/agentrun-jev": "0.1.0-beta.44",
63
+ "@parcha/agentrun-kernel": "0.1.0-beta.44",
64
+ "@parcha/pi-browser": "0.1.0-beta.44",
65
65
  "@secretlint/core": "13.1.0",
66
66
  "@secretlint/profiler": "13.1.0",
67
67
  "@secretlint/secretlint-rule-preset-recommend": "13.1.0",
@@ -96,6 +96,7 @@
96
96
  "@earendil-works/chord": "1.5.2",
97
97
  "@earendil-works/pi-ai": "1.5.2",
98
98
  "@earendil-works/pi-durable": "1.5.2",
99
+ "@parcha/agentrun-harness-acp": "0.1.0-beta.44",
99
100
  "@types/pg": "8.23.1",
100
101
  "@types/proxy-addr": "2.0.3",
101
102
  "@types/ws": "8.18.2",