@parcha/agentrun-serve 0.1.0-beta.42 → 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.
- package/CHANGELOG.md +126 -0
- package/README.md +221 -31
- package/dist/cli.js +42 -8
- package/dist/composio-preset.d.ts +4 -3
- package/dist/composio-preset.js +12 -4
- package/dist/composio-triggers.d.ts +20 -2
- package/dist/composio-triggers.js +183 -17
- package/dist/computer-lost.d.ts +11 -0
- package/dist/computer-lost.js +19 -0
- package/dist/computer-record.d.ts +10 -2
- package/dist/computer-record.js +50 -18
- package/dist/computer-setting.d.ts +1 -0
- package/dist/computer-setting.js +2 -2
- package/dist/console/assets/index-BUktRvS-.css +1 -0
- package/dist/console/assets/index-nB9kTfIN.js +711 -0
- package/dist/console/index.html +2 -2
- package/dist/decisions.js +0 -4
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +3 -0
- package/dist/harness-table.d.ts +51 -3
- package/dist/harness-table.js +101 -13
- package/dist/harness.d.ts +18 -1
- package/dist/harness.js +21 -9
- package/dist/host.d.ts +12 -10
- package/dist/host.js +18 -16
- package/dist/import-sources.js +25 -5
- package/dist/import-worker.d.ts +3 -0
- package/dist/import-worker.js +7 -5
- package/dist/import.d.ts +22 -1
- package/dist/import.js +141 -28
- package/dist/learn/audit.d.ts +123 -0
- package/dist/learn/audit.js +159 -0
- package/dist/learn/check.d.ts +3 -0
- package/dist/learn/check.js +1 -1
- package/dist/learn/compile.d.ts +50 -74
- package/dist/learn/compile.js +90 -124
- package/dist/learn/delete.d.ts +17 -0
- package/dist/learn/delete.js +44 -0
- package/dist/learn/folder.d.ts +9 -0
- package/dist/learn/folder.js +13 -2
- package/dist/learn/promote.d.ts +92 -200
- package/dist/learn/promote.js +65 -187
- package/dist/learn/replay-calls.d.ts +5 -0
- package/dist/learn/replay-calls.js +12 -1
- package/dist/learn/secrets.d.ts +8 -0
- package/dist/learn/secrets.js +12 -0
- package/dist/learn/skills.d.ts +4 -0
- package/dist/learn/skills.js +19 -5
- package/dist/learn/workflow-nodes.d.ts +23 -3
- package/dist/learn/workflow-nodes.js +30 -12
- package/dist/learned-nodes.d.ts +9 -34
- package/dist/learned-nodes.js +11 -23
- package/dist/learned-workflow.d.ts +6 -8
- package/dist/learned-workflow.js +18 -57
- package/dist/learning-batch.d.ts +13 -5
- package/dist/learning-batch.js +34 -8
- package/dist/learning-cost.d.ts +111 -4
- package/dist/learning-cost.js +120 -3
- package/dist/learning-evals.d.ts +2 -0
- package/dist/learning-evals.js +4 -3
- package/dist/learning-routes.d.ts +8 -0
- package/dist/learning-routes.js +18 -1
- package/dist/learning-setting.d.ts +16 -1
- package/dist/learning-setting.js +34 -2
- package/dist/learning.d.ts +1 -1
- package/dist/listen-first.d.ts +30 -0
- package/dist/listen-first.js +115 -0
- package/dist/llms.txt +2 -1
- package/dist/mcp-servers-store.d.ts +12 -12
- package/dist/model.d.ts +8 -4
- package/dist/model.js +16 -8
- package/dist/openapi.js +203 -87
- package/dist/owner.d.ts +8 -0
- package/dist/owner.js +11 -0
- package/dist/paid-calls.d.ts +6 -0
- package/dist/paid-calls.js +11 -1
- package/dist/place.d.ts +8 -3
- package/dist/place.js +13 -9
- package/dist/provider.js +15 -1
- package/dist/run-launch.d.ts +6 -3
- package/dist/run-launch.js +2 -0
- package/dist/run-learning-served.d.ts +1 -1
- package/dist/run-model-key.d.ts +64 -0
- package/dist/run-model-key.js +147 -0
- package/dist/runner/adapter-loop.d.ts +10 -0
- package/dist/runner/adapter-loop.js +26 -4
- package/dist/runner/adapter-run-spec.d.ts +6 -3
- package/dist/runner/adapter-run-spec.js +83 -25
- package/dist/runner/adapters/index.d.ts +4 -2
- package/dist/runner/adapters/index.js +13 -4
- package/dist/runner/audit.d.ts +68 -0
- package/dist/runner/audit.js +349 -0
- package/dist/runner/beside.d.ts +2 -1
- package/dist/runner/beside.js +6 -3
- package/dist/runner/claim-secrets.d.ts +49 -0
- package/dist/runner/claim-secrets.js +110 -1
- package/dist/runner/cli-run-spec.d.ts +2 -1
- package/dist/runner/cli-run-spec.js +44 -15
- package/dist/runner/commands.d.ts +3 -6
- package/dist/runner/feedback-round.d.ts +3 -2
- package/dist/runner/feedback-round.js +8 -7
- package/dist/runner/harness-loops.js +31 -23
- package/dist/runner/journal-kinds.d.ts +5 -7
- package/dist/runner/journal-kinds.js +0 -7
- package/dist/runner/learning-dispatch.d.ts +0 -16
- package/dist/runner/learning-dispatch.js +4 -47
- package/dist/runner/learning-end.d.ts +55 -13
- package/dist/runner/learning-end.js +128 -44
- package/dist/runner/learning-factory.d.ts +1 -1
- package/dist/runner/learning-factory.js +1 -4
- package/dist/runner/learning-loop.d.ts +2 -38
- package/dist/runner/learning-loop.js +8 -116
- package/dist/runner/loop-contract.d.ts +6 -0
- package/dist/runner/loop-contract.js +4 -0
- package/dist/runner/loop.js +6 -2
- package/dist/runner/main.d.ts +1 -0
- package/dist/runner/main.js +25 -8
- package/dist/runner/memory-claim.d.ts +9 -6
- package/dist/runner/memory-claim.js +12 -9
- package/dist/runner/promotion.d.ts +55 -54
- package/dist/runner/promotion.js +232 -585
- package/dist/runner/reflect-hook.d.ts +14 -0
- package/dist/runner/reflect-hook.js +28 -3
- package/dist/runner/runner.js +57 -4
- package/dist/runner/store-secrets.js +9 -5
- package/dist/runner/workflow-first.d.ts +6 -5
- package/dist/runner/workflow-first.js +17 -12
- package/dist/runner/workflow-spec.js +10 -2
- package/dist/runs-over-store.d.ts +5 -4
- package/dist/runs-over-store.js +13 -3
- package/dist/sdk/workflows.d.ts +1 -1
- package/dist/server.d.ts +64 -50
- package/dist/server.js +516 -134
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/seal.d.ts +20 -2
- package/dist/store/seal.js +24 -8
- package/dist/store/sqlite/run-launch.d.ts +4 -1
- package/dist/store/sqlite/run-launch.js +12 -0
- package/dist/store/sqlite/store.d.ts +3 -2
- package/dist/store/sqlite/store.js +119 -16
- package/dist/store/store.d.ts +41 -3
- package/dist/store-reads/analytics.js +11 -1
- package/dist/store-reads/learning.d.ts +57 -7
- package/dist/store-reads/learning.js +194 -28
- package/dist/store-reads/loop.d.ts +4 -39
- package/dist/store-reads/loop.js +10 -79
- package/dist/store-reads/stats.js +13 -3
- package/dist/store-view.d.ts +5 -1
- package/dist/store-view.js +12 -1
- package/dist/telemetry.d.ts +59 -0
- package/dist/telemetry.js +153 -0
- package/dist/tool-keys-store.d.ts +1 -1
- package/dist/tool-keys.d.ts +2 -2
- package/dist/tool-plane.d.ts +12 -12
- package/dist/tools.d.ts +11 -11
- package/dist/tools.js +18 -5
- package/dist/trigger-adapter.d.ts +3 -0
- package/dist/trigger-adapters.d.ts +4 -0
- package/dist/trigger-adapters.js +13 -0
- package/dist/trigger-composio.d.ts +58 -1
- package/dist/trigger-composio.js +160 -6
- package/dist/triggers.d.ts +4 -0
- package/dist/triggers.js +22 -3
- package/dist/validate.d.ts +11 -7
- package/dist/validate.js +8 -7
- package/dist/workspace/computer-for-claim.d.ts +15 -5
- package/dist/workspace/computer-for-claim.js +228 -32
- package/dist/workspace/resolve-computer.d.ts +8 -2
- package/dist/workspace/resolve-computer.js +1 -1
- package/dist/workspace/run-tools.d.ts +1 -1
- package/dist/workspace/run-tools.js +14 -3
- package/package.json +10 -9
- package/dist/console/assets/index-C3gNPz58.css +0 -1
- package/dist/console/assets/index-DYJ_wj27.js +0 -711
- package/dist/learn/general.d.ts +0 -69
- package/dist/learn/general.js +0 -75
- package/dist/learn/refit.d.ts +0 -48
- package/dist/learn/refit.js +0 -264
- package/dist/runner/step-guard.d.ts +0 -62
- package/dist/runner/step-guard.js +0 -93
|
@@ -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
|
|
463
|
-
if (!
|
|
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
|
-
|
|
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
|
-
|
|
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:
|
|
553
|
-
if (!pairedRow && (
|
|
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
|
-
|
|
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
|
-
|
|
612
|
-
|
|
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
|
|
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
|
-
...(
|
|
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
|
|
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
|
|
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 {
|
|
@@ -92,7 +92,7 @@ export type RunHands = {
|
|
|
92
92
|
/** A desktop's or a phone's computer as a codemode script gets it bound; none for any other computer. */
|
|
93
93
|
readonly computer?: ScriptComputer;
|
|
94
94
|
/** The run's end, after its background processes are ended and before the computer is let go: bash's full outputs
|
|
95
|
-
* and its TMPDIR swept. */
|
|
95
|
+
* and its TMPDIR swept, through the computer when it mounts the folder. */
|
|
96
96
|
sweep(): Promise<void>;
|
|
97
97
|
};
|
|
98
98
|
/** The run's hands and host executors on `workspace`, attached to `computer` when its kind and provider mount the folder,
|
|
@@ -94,9 +94,20 @@ export async function runHands(workspace, claimed, options) {
|
|
|
94
94
|
...((computer?.kind === "desktop" || computer?.kind === "phone") && computer.surface ? { surface: computer.surface } : {}),
|
|
95
95
|
...(script ? { computer: script } : {}),
|
|
96
96
|
async sweep() {
|
|
97
|
-
// Through the run
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
// Through the Workspace the run wrote them through: the computer's when it mounts the folder, since on Archil the
|
|
98
|
+
// run's own Workspace is the disk's file API, which the mount's write delegation refuses until the computer's
|
|
99
|
+
// release. A computer that no longer answers leaves a Mode 1 folder to the run's own Workspace (a folder of this
|
|
100
|
+
// machine, which no delegation holds); a Mode 2 one keeps its scratch, said by the release's log.
|
|
101
|
+
for (const dir of [OUTPUT_DIR, TMP_DIR]) {
|
|
102
|
+
try {
|
|
103
|
+
await attached.remove(dir, { recursive: true, force: true });
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
if (mounted === undefined || options.mode === 2)
|
|
107
|
+
throw error;
|
|
108
|
+
await workspace.remove(dir, { recursive: true, force: true });
|
|
109
|
+
}
|
|
110
|
+
}
|
|
100
111
|
},
|
|
101
112
|
};
|
|
102
113
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcha/agentrun-serve",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
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.
|
|
58
|
-
"@parcha/agentrun-decisions": "0.1.0-beta.
|
|
59
|
-
"@parcha/agentrun-dsl": "0.1.0-beta.
|
|
60
|
-
"@parcha/agentrun-harness-claude": "0.1.0-beta.
|
|
61
|
-
"@parcha/agentrun-harness-codex": "0.1.0-beta.
|
|
62
|
-
"@parcha/agentrun-jev": "0.1.0-beta.
|
|
63
|
-
"@parcha/agentrun-kernel": "0.1.0-beta.
|
|
64
|
-
"@parcha/pi-browser": "0.1.0-beta.
|
|
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",
|