@parcha/agentrun-serve 0.1.0-beta.55 → 0.1.0-beta.57
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 +261 -0
- package/README.md +228 -45
- package/dist/acp-package.d.ts +2 -0
- package/dist/adapters.d.ts +18 -5
- package/dist/adapters.js +23 -9
- package/dist/agent-package.d.ts +3 -3
- package/dist/agent-package.js +17 -8
- package/dist/answer-json.d.ts +6 -2
- package/dist/answer-json.js +22 -4
- package/dist/api-keys.d.ts +76 -0
- package/dist/api-keys.js +217 -0
- package/dist/api-only.d.ts +17 -5
- package/dist/api-only.js +36 -8
- package/dist/browser-hold.d.ts +23 -0
- package/dist/browser-hold.js +48 -0
- package/dist/browser-person.d.ts +3 -0
- package/dist/browser-person.js +4 -1
- package/dist/calendar/tools.js +3 -2
- package/dist/chatgpt-plan.d.ts +28 -3
- package/dist/chatgpt-plan.js +182 -21
- package/dist/claude-login.d.ts +101 -14
- package/dist/claude-login.js +232 -49
- package/dist/claude-sign-in.d.ts +46 -0
- package/dist/claude-sign-in.js +93 -0
- package/dist/cli.js +63 -6
- package/dist/composio-made.d.ts +4 -0
- package/dist/composio-made.js +4 -0
- package/dist/composio-preset.d.ts +43 -2
- package/dist/composio-preset.js +92 -4
- package/dist/computer-held-routes.d.ts +5 -4
- package/dist/computer-held-routes.js +29 -8
- package/dist/computer-held.d.ts +6 -1
- package/dist/computer-held.js +14 -0
- package/dist/computer-record.js +4 -2
- package/dist/computer-viewer.js +4 -1
- package/dist/console/assets/{backend-D5EmB4N3.js → backend-DVhHzJX2.js} +19 -19
- package/dist/console/assets/index-Bwn1oTem.css +1 -0
- package/dist/console/assets/index-okP-y8PK.js +747 -0
- package/dist/console/index.html +2 -2
- package/dist/decisions.d.ts +1 -1
- package/dist/decisions.js +1 -1
- package/dist/docker-host-addresses.d.ts +22 -11
- package/dist/docker-host-addresses.js +38 -26
- package/dist/env-switch.d.ts +10 -0
- package/dist/env-switch.js +33 -2
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +2 -0
- package/dist/fal-price.d.ts +58 -20
- package/dist/fal-price.js +341 -82
- package/dist/handed-values.d.ts +43 -1
- package/dist/handed-values.js +119 -2
- package/dist/harness-archive.d.ts +13 -10
- package/dist/harness-archive.js +60 -34
- package/dist/harness-check.d.ts +3 -1
- package/dist/harness-check.js +25 -46
- package/dist/harness-keys.d.ts +73 -27
- package/dist/harness-keys.js +194 -61
- package/dist/harness-recipe-entry.d.ts +8 -7
- package/dist/harness-recipe-entry.js +21 -32
- package/dist/harness-recipe.d.ts +38 -25
- package/dist/harness-recipe.js +49 -36
- package/dist/harness-sign-in.js +12 -23
- package/dist/harness-table.d.ts +10 -3
- package/dist/harness-table.js +26 -21
- package/dist/harness.d.ts +1 -0
- package/dist/harness.js +17 -5
- package/dist/host-check.d.ts +4 -0
- package/dist/host-check.js +4 -0
- package/dist/hosted-search.d.ts +1 -1
- package/dist/hosted-search.js +1 -2
- package/dist/import-worker.d.ts +4 -2
- package/dist/import-worker.js +9 -2
- package/dist/in-flight.d.ts +26 -0
- package/dist/in-flight.js +52 -0
- package/dist/key-refusal.d.ts +26 -5
- package/dist/key-refusal.js +313 -37
- package/dist/learn/secrets.d.ts +31 -11
- package/dist/learn/secrets.js +152 -191
- package/dist/learning-cost.d.ts +6 -3
- package/dist/learning-cost.js +4 -2
- package/dist/link-check.js +1 -1
- package/dist/llms.txt +2 -2
- package/dist/marketplace.d.ts +77 -0
- package/dist/marketplace.js +224 -0
- package/dist/mcp-api-only-origins.d.ts +30 -0
- package/dist/mcp-api-only-origins.js +57 -0
- package/dist/mcp-gateway.d.ts +7 -5
- package/dist/mcp-gateway.js +9 -12
- package/dist/mcp-secret-writes.js +5 -3
- package/dist/mcp-servers-store.d.ts +28 -6
- package/dist/mcp-servers-store.js +53 -4
- package/dist/media-duration.d.ts +3 -0
- package/dist/media-duration.js +90 -9
- package/dist/model-form.d.ts +5 -4
- package/dist/model-form.js +11 -7
- package/dist/model.d.ts +5 -2
- package/dist/model.js +9 -5
- package/dist/ollama-provider.d.ts +7 -1
- package/dist/ollama-provider.js +14 -2
- package/dist/openapi.d.ts +3 -3
- package/dist/openapi.js +245 -42
- package/dist/otel/genai.d.ts +65 -0
- package/dist/otel/genai.js +116 -0
- package/dist/otel/tracer.d.ts +55 -0
- package/dist/otel/tracer.js +308 -0
- package/dist/page.d.ts +2 -0
- package/dist/page.js +3 -1
- package/dist/paid-calls.d.ts +1 -32
- package/dist/paid-calls.js +4 -39
- package/dist/place-offers.d.ts +14 -6
- package/dist/place-offers.js +26 -13
- package/dist/provider.d.ts +9 -0
- package/dist/provider.js +50 -3
- package/dist/redact/match.d.ts +101 -0
- package/dist/redact/match.js +1152 -0
- package/dist/refusal-words.d.ts +11 -0
- package/dist/refusal-words.js +11 -0
- package/dist/run-census.d.ts +67 -0
- package/dist/run-census.js +240 -0
- package/dist/run-computer.d.ts +6 -3
- package/dist/run-computer.js +4 -1
- package/dist/run-cut.d.ts +15 -6
- package/dist/run-cut.js +30 -9
- package/dist/run-files.d.ts +3 -0
- package/dist/run-files.js +3 -0
- package/dist/run-launch.d.ts +12 -1
- package/dist/run-launch.js +9 -10
- package/dist/run-learning-served.d.ts +2 -0
- package/dist/run-model-key.d.ts +8 -0
- package/dist/run-model-key.js +31 -1
- package/dist/run-reads-over-store.d.ts +24 -6
- package/dist/run-reads-over-store.js +67 -23
- package/dist/run-recordings.d.ts +5 -1
- package/dist/run-recordings.js +39 -14
- package/dist/run-timeline-served.d.ts +3 -1
- package/dist/run-timeline-served.js +4 -4
- package/dist/run-usage.d.ts +1 -0
- package/dist/runnable.d.ts +10 -1
- package/dist/runnable.js +20 -8
- package/dist/runner/adapter-loop.d.ts +14 -0
- package/dist/runner/adapter-loop.js +56 -11
- package/dist/runner/adapter-run-spec.d.ts +45 -8
- package/dist/runner/adapter-run-spec.js +154 -29
- package/dist/runner/adapters/pi.js +25 -3
- package/dist/runner/beside.js +11 -6
- package/dist/runner/big-writes.js +1 -10
- package/dist/runner/claim-secrets.d.ts +18 -3
- package/dist/runner/claim-secrets.js +35 -6
- package/dist/runner/cli-run-spec.d.ts +6 -0
- package/dist/runner/cli-run-spec.js +85 -36
- package/dist/runner/computer-journal.d.ts +9 -1
- package/dist/runner/computer-journal.js +26 -0
- package/dist/runner/conformance/harness.js +1 -1
- package/dist/runner/feedback-round.js +3 -0
- package/dist/runner/harness-loops.d.ts +6 -5
- package/dist/runner/harness-loops.js +7 -7
- package/dist/runner/held.d.ts +11 -5
- package/dist/runner/journal-kinds.d.ts +5 -0
- package/dist/runner/journal-kinds.js +5 -0
- package/dist/runner/loop-contract.d.ts +4 -0
- package/dist/runner/main.js +15 -6
- package/dist/runner/mcp-claim.js +30 -3
- package/dist/runner/mcp-run.d.ts +12 -0
- package/dist/runner/mcp-run.js +12 -5
- package/dist/runner/model-route.d.ts +17 -0
- package/dist/runner/model-route.js +120 -2
- package/dist/runner/presence.d.ts +4 -3
- package/dist/runner/presence.js +4 -2
- package/dist/runner/run-child-host.d.ts +5 -0
- package/dist/runner/run-child-host.js +71 -30
- package/dist/runner/run-child.js +5 -2
- package/dist/runner/runner.d.ts +18 -3
- package/dist/runner/runner.js +162 -36
- package/dist/runner/store-port.d.ts +1 -1
- package/dist/runner/store-secrets.d.ts +6 -0
- package/dist/runner/store-secrets.js +49 -7
- package/dist/runner/subagent.js +4 -40
- package/dist/runner/workflow-first.d.ts +11 -4
- package/dist/runner/workflow-first.js +14 -8
- package/dist/runner/workflow-spec.js +3 -2
- package/dist/runs-over-store.d.ts +15 -6
- package/dist/runs-over-store.js +33 -21
- package/dist/scrub-command.d.ts +73 -0
- package/dist/scrub-command.js +307 -0
- package/dist/secret-cut.d.ts +73 -0
- package/dist/secret-cut.js +291 -4
- package/dist/secret-rules.d.ts +143 -0
- package/dist/secret-rules.js +2564 -0
- package/dist/secrets.d.ts +7 -0
- package/dist/secrets.js +20 -0
- package/dist/server-keys.d.ts +20 -0
- package/dist/server-keys.js +25 -6
- package/dist/server.d.ts +57 -13
- package/dist/server.js +371 -113
- package/dist/skills/agentrun-serve/SKILL.md +4 -0
- package/dist/store/dialect.d.ts +3 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +1 -1
- package/dist/store/index.js +1 -1
- package/dist/store/journal/storage.js +1 -1
- package/dist/store/postgres/dialect.js +3 -0
- package/dist/store/postgres/migrations/0027_run_launch_census.sql +31 -0
- package/dist/store/schema.d.ts +6 -0
- package/dist/store/schema.js +11 -1
- package/dist/store/seal.d.ts +6 -1
- package/dist/store/seal.js +5 -3
- package/dist/store/sqlite/run-launch.d.ts +9 -1
- package/dist/store/sqlite/run-launch.js +24 -13
- package/dist/store/sqlite/run-patch.d.ts +1 -1
- package/dist/store/sqlite/run-patch.js +13 -4
- package/dist/store/sqlite/store.js +76 -16
- package/dist/store/store.d.ts +53 -3
- package/dist/store/store.js +27 -0
- package/dist/store-reads/learning.d.ts +6 -3
- package/dist/store-reads/learning.js +22 -7
- package/dist/store-view.d.ts +3 -0
- package/dist/store-view.js +4 -4
- package/dist/suggestions.js +3 -2
- package/dist/template-eval.d.ts +22 -11
- package/dist/template-eval.js +124 -41
- package/dist/template-import.d.ts +10 -0
- package/dist/template-import.js +16 -7
- package/dist/templates.d.ts +10 -2
- package/dist/templates.js +28 -8
- package/dist/timeline/index.d.ts +1 -1
- package/dist/timeline/index.js +1 -1
- package/dist/timeline/labels.d.ts +6 -4
- package/dist/timeline/labels.js +18 -6
- package/dist/timeline/timeline.d.ts +17 -7
- package/dist/timeline/timeline.js +28 -14
- package/dist/timeline/util.js +1 -1
- package/dist/timeline/web-calls.d.ts +26 -9
- package/dist/timeline/web-calls.js +124 -37
- package/dist/tool-gate.d.ts +42 -3
- package/dist/tool-gate.js +69 -6
- package/dist/tool-keys-store.d.ts +2 -4
- package/dist/tool-keys-store.js +5 -21
- package/dist/tool-keys.d.ts +2 -2
- package/dist/tool-keys.js +2 -2
- package/dist/tool-list.js +1 -1
- package/dist/tool-plane.d.ts +2 -2
- package/dist/tool-plane.js +35 -33
- package/dist/tools.js +13 -7
- package/dist/trigger-targets.d.ts +4 -0
- package/dist/trigger-targets.js +9 -2
- package/dist/triggers.d.ts +67 -4
- package/dist/triggers.js +171 -22
- package/dist/until.d.ts +3 -0
- package/dist/until.js +11 -0
- package/dist/validate.js +1 -1
- package/dist/web-fake.d.ts +1 -3
- package/dist/web-fake.js +7 -18
- package/dist/web-fetch.d.ts +6 -72
- package/dist/web-fetch.js +11 -265
- package/dist/web-run.d.ts +31 -0
- package/dist/web-run.js +90 -0
- package/dist/web-save.d.ts +6 -4
- package/dist/web-save.js +9 -12
- package/dist/web-search.d.ts +9 -127
- package/dist/web-search.js +23 -259
- package/dist/wires.d.ts +13 -0
- package/dist/wires.js +11 -0
- package/dist/workflow-run.d.ts +5 -4
- package/dist/workflow-run.js +5 -4
- package/dist/workspace/computer-deps.d.ts +3 -1
- package/dist/workspace/computer-deps.js +12 -4
- package/dist/workspace/computer-for-claim.d.ts +19 -2
- package/dist/workspace/computer-for-claim.js +101 -13
- package/dist/workspace/computer-janitor.d.ts +15 -7
- package/dist/workspace/computer-janitor.js +33 -8
- package/dist/workspace/computer-kept.d.ts +55 -4
- package/dist/workspace/computer-kept.js +129 -8
- package/dist/workspace/index.d.ts +1 -1
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/kind-skills.d.ts +4 -0
- package/dist/workspace/kind-skills.js +9 -0
- package/dist/workspace/run-end-computers.d.ts +5 -1
- package/dist/workspace/run-end-computers.js +27 -1
- package/dist/workspace/synced-folder.js +3 -4
- package/dist/wrapped.d.ts +65 -0
- package/dist/wrapped.js +77 -0
- package/package.json +17 -11
- package/skills/agentrun-serve/SKILL.md +4 -0
- package/templates/README.md +38 -15
- package/dist/console/assets/index-DUYLaqiR.js +0 -746
- package/dist/console/assets/index-DYhU4adm.css +0 -1
- package/dist/exa-keyless.d.ts +0 -34
- package/dist/exa-keyless.js +0 -118
- package/dist/firecrawl-keyless.d.ts +0 -41
- package/dist/firecrawl-keyless.js +0 -152
- package/dist/keyless-mcp.d.ts +0 -36
- package/dist/keyless-mcp.js +0 -127
- package/dist/text-urls.d.ts +0 -38
- package/dist/text-urls.js +0 -170
- package/dist/web-fetch-direct.d.ts +0 -119
- package/dist/web-fetch-direct.js +0 -190
|
@@ -1,4 +1,46 @@
|
|
|
1
|
-
|
|
1
|
+
// A desktop, a phone or a sandbox kept through its run's park. A run's own computer goes with its claim, and a park
|
|
2
|
+
// releases the claim; so a run that parked for a person (a tool's approval, a cap raise, a question) would resume on a new
|
|
3
|
+
// machine, with nothing the agent set up on the old one. Instead, the claim that parks keeps a desktop, a phone or a
|
|
4
|
+
// sandbox it made (or took back) for KEEP_MS: an answer within that time resumes the run on the same machine, its screen,
|
|
5
|
+
// files and programs as they were (computer-for-claim.ts: the claim's park, and the resumed claim's re-attach). After it,
|
|
6
|
+
// the kept computer is ended, and a later resume makes a new one, said as any replaced computer is, and why.
|
|
7
|
+
//
|
|
8
|
+
// One server setting per run holds it (`computer_kept:<run id>`): its provider, its kind, its ref, the claim epoch its
|
|
9
|
+
// labels carry, and the time it is kept until. The claim that parks writes it; the claim that resumes in time takes it
|
|
10
|
+
// off and attaches the computer. At its time it is ended by the parking runner's own timer and, whatever became of
|
|
11
|
+
// that process (a server's restart), by the janitor (computer-janitor.ts), which reads every row at each sweep and wakes
|
|
12
|
+
// at the earliest time still ahead. Ending one marks its row ending (no claim takes it after), deletes the computer, then
|
|
13
|
+
// marks the row ended, so the resume says why its computer is new; a row left ending (its process died, or its delete
|
|
14
|
+
// failed or hung mid-way) is deleted again at the janitor's next pass. A row whose run is final is removed, its computer
|
|
15
|
+
// deleted first.
|
|
16
|
+
//
|
|
17
|
+
// A sandbox's run folder is the run's either way (bound from this machine, or on Archil, as before); what the keep adds is
|
|
18
|
+
// the rest of the machine (its other files, its processes). A synced folder's delta lands on the disk at the park; what
|
|
19
|
+
// its programs write after it is read back whole by the claim that takes it back. One whose keep lapses is deleted, by
|
|
20
|
+
// the parking runner's own timer or the janitor, with no read-back: those writes are lost, as a runner lost loses an
|
|
21
|
+
// unanswered call's. A claim takes one back only to hold the run's folder the same way (its row's `folder`). An agent's
|
|
22
|
+
// own computer and a paired one outlive every claim already, and are never kept here; a runner lost, a crash or a
|
|
23
|
+
// server's stop still gives a new one.
|
|
24
|
+
//
|
|
25
|
+
// While the run is parked, its owner's live view says what it waits for and that the computer is kept, until when, then
|
|
26
|
+
// that it wasn't kept once its time passed (parkedWords, lapsedWords): the viewer's page, as the claim's park closes it
|
|
27
|
+
// (computer-live.ts), and the console's Screen tab, until when from the park's row on the run's timeline
|
|
28
|
+
// (computerKeptWords) and its lapse from GET /v2/runs/{id}/computer (computer-view.ts lapsedOf).
|
|
29
|
+
//
|
|
30
|
+
// A machine only the runner that kept it can reach again is pinned to that runner (pinnedOf): a container on its Docker
|
|
31
|
+
// engine (a local provider), or a machine that dials this server, whose socket is in that runner's attach hub. Its row
|
|
32
|
+
// names the runner and its process (`runner`, `incarnation`: the presence incarnation, runner/presence.ts), and while
|
|
33
|
+
// that runner is there under that incarnation and the keep lasts, the claim rule gives the run to that runner alone
|
|
34
|
+
// (store KEPT_PREFIX: no other runner's poll picks it, nothing is claimed and given back). A stop or cancel is exempt:
|
|
35
|
+
// any runner claims the run at once and ends it with no loop, never taking the row (runner.ts claimMore), and the
|
|
36
|
+
// row's runner ends the machine at its time, or at its janitor's pass once the run is over. Once it is gone (its row stale
|
|
37
|
+
// for PRESENCE_STALE_MS, a new incarnation, a refusal) any runner claims the run; a claim that then finds the machine gone
|
|
38
|
+
// says so (computerLostWords), and its janitor never ends a row pinned to another runner still there (sweepKept): that
|
|
39
|
+
// runner's own timer or janitor does. A machine any runner reaches by its id (an exec vendor's sandbox, a phone) is not
|
|
40
|
+
// pinned, and moves.
|
|
41
|
+
import { connectOf } from "@parcha/agentrun-computer";
|
|
42
|
+
import { PRESENCE_STALE_MS } from "../runner/presence.js";
|
|
43
|
+
import { FINAL_STATES, KEPT_PREFIX as KEPT_ROWS } from "../store/index.js";
|
|
2
44
|
/** How long a park keeps the run's computer for its resume: 10 minutes. */
|
|
3
45
|
export const KEEP_MS = 10 * 60_000;
|
|
4
46
|
/** KEEP_MS in words. */
|
|
@@ -16,12 +58,64 @@ const WAITING = {
|
|
|
16
58
|
export const parkedWords = (kind, cause) => `${WAITING[cause]} The ${kind} is kept for ${KEEP_WORDS}.`;
|
|
17
59
|
/** Why the run's computer at its resume is a new one: the one kept at its park was ended at its time. */
|
|
18
60
|
export const computerLapsedWords = (kind) => `The ${kind} wasn't kept: ${KEEP_WORDS} passed.`;
|
|
61
|
+
/** Why the run's computer at its resume is a new one: the one kept at its park was pinned to the runner that kept it
|
|
62
|
+
* (pinnedOf), that runner was gone by the resume, and the claiming runner could not reach it. Never names the runner:
|
|
63
|
+
* a runner's name carries its host's. */
|
|
64
|
+
export const computerLostWords = (kind) => `The ${kind} wasn't kept: the runner that kept it is gone.`;
|
|
19
65
|
/** The live view's words once the kept computer's time passed, the run still parked. */
|
|
20
66
|
export const lapsedWords = (kind) => `${computerLapsedWords(kind)} A new one starts when the run goes on.`;
|
|
21
|
-
/** The settings key prefix of the kept computers, one row per run. */
|
|
22
|
-
export const KEPT_PREFIX =
|
|
67
|
+
/** The settings key prefix of the kept computers, one row per run (the store's, which its claim rule reads). */
|
|
68
|
+
export const KEPT_PREFIX = KEPT_ROWS;
|
|
23
69
|
/** The settings key of `runId`'s kept computer. */
|
|
24
70
|
export const keptKeyOf = (runId) => `${KEPT_PREFIX}${runId}`;
|
|
71
|
+
/** Whether a computer of `entry`, made with `options` (its settings' options under the configuration's, as the claim makes
|
|
72
|
+
* its provider), can be reached again only by the runner that kept it: a local provider's (a container on that
|
|
73
|
+
* runner's Docker engine), or one whose machines dial this server (the computer package's connectOf "dial": its socket
|
|
74
|
+
* is in that runner's attach hub, its token names that runner). A connect the computer package refuses reads as exec,
|
|
75
|
+
* as resolve-computer.ts reads it. */
|
|
76
|
+
export function pinnedOf(entry, options = {}) {
|
|
77
|
+
if (entry.local === true)
|
|
78
|
+
return true;
|
|
79
|
+
try {
|
|
80
|
+
return connectOf(entry, options) === "dial";
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/** Whether `kept` names `holder` as the runner that keeps it (the same name and the same process). */
|
|
87
|
+
export const keptBy = (kept, holder) => holder !== undefined && kept.runner === holder.runner && kept.incarnation === holder.incarnation;
|
|
88
|
+
/** The one rule both janitor sweeps leave a kept machine by (sweepKept, and the provider sweep through sparedKept): its
|
|
89
|
+
* row is pinned to a runner other than `self` that is still there under the row's incarnation (seen within
|
|
90
|
+
* PRESENCE_STALE_MS). Only that runner's engine or hub has the machine, so a delete from here either finds nothing (and
|
|
91
|
+
* marks the row ended, leaking it) or, where both runners list it (a dial vendor's account, a shared Docker engine),
|
|
92
|
+
* ends a machine its runner still keeps. The runners are read once per maker's call. A read that fails counts every
|
|
93
|
+
* pinned row as held elsewhere: ending another runner's machine blind would leak it or take it. */
|
|
94
|
+
export function heldElsewhere(holders) {
|
|
95
|
+
let there;
|
|
96
|
+
return async (kept) => {
|
|
97
|
+
const { runners } = holders;
|
|
98
|
+
if (kept.runner === undefined || keptBy(kept, holders.self) || !runners)
|
|
99
|
+
return false;
|
|
100
|
+
there ??= runners.live(PRESENCE_STALE_MS).then((live) => new Set(live.map((one) => `${one.runner}\n${one.incarnation}`)), () => "unknown");
|
|
101
|
+
const live = await there;
|
|
102
|
+
return live === "unknown" || live.has(`${kept.runner}\n${kept.incarnation}`);
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/** The kept machines a provider sweep leaves this pass, by provider id and computer id: each row not yet ended whose
|
|
106
|
+
* machine is held elsewhere (heldElsewhere, the kept pass's own rule). Throws when the rows can't be read: the sweep
|
|
107
|
+
* then can't tell which machines are kept, and must not guess. */
|
|
108
|
+
export async function sparedKept(deps) {
|
|
109
|
+
const rows = await deps.settings.all({ prefix: KEPT_PREFIX });
|
|
110
|
+
const elsewhere = heldElsewhere(deps);
|
|
111
|
+
const spared = new Set();
|
|
112
|
+
for (const row of rows) {
|
|
113
|
+
const kept = keptOf(row.value);
|
|
114
|
+
if (kept && !kept.ended && (await elsewhere(kept)))
|
|
115
|
+
spared.add(`${kept.provider}\n${kept.id}`);
|
|
116
|
+
}
|
|
117
|
+
return (provider, id) => spared.has(`${provider}\n${id}`);
|
|
118
|
+
}
|
|
25
119
|
/** How long one delete of a kept computer may take at the janitor's pass: past it the pass goes on, the row is left
|
|
26
120
|
* ending, and the next pass deletes it again (a Docker command has no timeout of its own). */
|
|
27
121
|
export const KEPT_DELETE_MS = 60_000;
|
|
@@ -29,14 +123,19 @@ export const KEPT_DELETE_MS = 60_000;
|
|
|
29
123
|
export function keptOf(value) {
|
|
30
124
|
if (!value || typeof value !== "object")
|
|
31
125
|
return undefined;
|
|
32
|
-
const { provider, kind, id, name, epoch, until, folder, ending, ended } = value;
|
|
126
|
+
const { provider, kind, id, name, epoch, until, folder, runner, incarnation, ending, ended } = value;
|
|
33
127
|
if (typeof provider !== "string" || (kind !== "desktop" && kind !== "phone" && kind !== "sandbox") || typeof id !== "string" || typeof name !== "string")
|
|
34
128
|
return undefined;
|
|
35
129
|
if (typeof epoch !== "number" || !Number.isSafeInteger(epoch) || typeof until !== "number" || !Number.isFinite(until))
|
|
36
130
|
return undefined;
|
|
37
131
|
if (folder !== undefined && folder !== "bind" && folder !== "archil" && folder !== "sync")
|
|
38
132
|
return undefined;
|
|
39
|
-
|
|
133
|
+
// Its runner and incarnation together, or neither.
|
|
134
|
+
if ((runner === undefined) !== (incarnation === undefined))
|
|
135
|
+
return undefined;
|
|
136
|
+
if (runner !== undefined && (typeof runner !== "string" || typeof incarnation !== "string"))
|
|
137
|
+
return undefined;
|
|
138
|
+
const held = { ...(folder === undefined ? {} : { folder: folder }), ...(typeof runner === "string" && typeof incarnation === "string" ? { runner, incarnation } : {}) };
|
|
40
139
|
if (ended === true)
|
|
41
140
|
return { provider, kind, id, name, epoch, until, ...held, ended: true };
|
|
42
141
|
return { provider, kind, id, name, epoch, until, ...held, ...(ending === true ? { ending: true } : {}) };
|
|
@@ -45,6 +144,7 @@ export function keptOf(value) {
|
|
|
45
144
|
const rowOf = (kept, state) => ({
|
|
46
145
|
provider: kept.provider, kind: kept.kind, id: kept.id, name: kept.name, epoch: kept.epoch, until: kept.until,
|
|
47
146
|
...(kept.folder === undefined ? {} : { folder: kept.folder }),
|
|
147
|
+
...(kept.runner === undefined || kept.incarnation === undefined ? {} : { runner: kept.runner, incarnation: kept.incarnation }),
|
|
48
148
|
...(state === "ending" ? { ending: true } : state === "ended" ? { ended: true } : {}),
|
|
49
149
|
});
|
|
50
150
|
/** `runId`'s kept computer, as its row reads now; undefined when there is none. */
|
|
@@ -79,7 +179,10 @@ export async function endKept(settings, runId, kept, end) {
|
|
|
79
179
|
* deleted (unless its time already ended it) and the row removed; one past its time, or left ending, is ended (endKept),
|
|
80
180
|
* each delete bounded by `deleteMs` (KEPT_DELETE_MS). The rest are left, the earliest of their times answered as `next`.
|
|
81
181
|
* `providerOf`: the provider a row names, made with this server's keys, or undefined when this server can't make it (its
|
|
82
|
-
* keys gone): that row is left and said.
|
|
182
|
+
* keys gone): that row is left and said. A row pinned to a runner other than this one (`self`) that is still there under
|
|
183
|
+
* the row's incarnation (`runners`, seen within PRESENCE_STALE_MS) is left whatever its time or its run: only that
|
|
184
|
+
* runner's engine or hub has its machine, so a delete from here would find nothing, mark it ended and leak the machine.
|
|
185
|
+
* That runner's own timer, or its janitor, ends it; once it is gone the row is ended here as any other. Never throws.
|
|
83
186
|
*/
|
|
84
187
|
export async function sweepKept(deps) {
|
|
85
188
|
const ended = [];
|
|
@@ -92,6 +195,9 @@ export async function sweepKept(deps) {
|
|
|
92
195
|
catch (error) {
|
|
93
196
|
return { ended, failed: [`the kept computers could not be read: ${words(error)}`] };
|
|
94
197
|
}
|
|
198
|
+
// The runners there now, read once for the pass, only where a row is pinned to another runner (heldElsewhere: the
|
|
199
|
+
// provider sweep leaves the same machines by the same rule, computer-janitor.ts).
|
|
200
|
+
const othersThere = heldElsewhere(deps);
|
|
95
201
|
for (const row of rows) {
|
|
96
202
|
const runId = row.key.slice(KEPT_PREFIX.length);
|
|
97
203
|
const kept = keptOf(row.value);
|
|
@@ -107,6 +213,12 @@ export async function sweepKept(deps) {
|
|
|
107
213
|
await deps.settings.removeIf(row.key, kept);
|
|
108
214
|
continue;
|
|
109
215
|
}
|
|
216
|
+
if (await othersThere(kept)) {
|
|
217
|
+
// Its runner's own: woken again at its time while that is ahead, by then that runner may be gone.
|
|
218
|
+
if (!kept.ending && deps.now < kept.until)
|
|
219
|
+
next = Math.min(next ?? kept.until, kept.until);
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
110
222
|
if (!over && !kept.ending && deps.now < kept.until) {
|
|
111
223
|
next = Math.min(next ?? kept.until, kept.until);
|
|
112
224
|
continue;
|
|
@@ -142,17 +254,26 @@ export async function deleteKept(provider, kept) {
|
|
|
142
254
|
throw new Error(released.error.message);
|
|
143
255
|
return released.ok;
|
|
144
256
|
}
|
|
145
|
-
/** `work`, or its timeout in words after `ms
|
|
146
|
-
|
|
257
|
+
/** `work`, or its timeout in words after `ms`, or `signal`'s abort, whichever is first: a delete that hangs is left to
|
|
258
|
+
* finish on its own. */
|
|
259
|
+
export async function bounded(ms, work, signal) {
|
|
147
260
|
let timer;
|
|
261
|
+
let stopped;
|
|
148
262
|
const late = new Promise((_, reject) => {
|
|
149
263
|
timer = setTimeout(() => reject(new Error(`its delete did not answer within ${ms / 1000} s; the next pass tries again`)), ms);
|
|
264
|
+
stopped = () => reject(new Error("its delete was left at the run's stop; the next pass tries again"));
|
|
265
|
+
if (signal?.aborted)
|
|
266
|
+
stopped();
|
|
267
|
+
else
|
|
268
|
+
signal?.addEventListener("abort", stopped, { once: true });
|
|
150
269
|
});
|
|
151
270
|
try {
|
|
152
271
|
await Promise.race([work, late]);
|
|
153
272
|
}
|
|
154
273
|
finally {
|
|
155
274
|
clearTimeout(timer);
|
|
275
|
+
if (stopped)
|
|
276
|
+
signal?.removeEventListener("abort", stopped);
|
|
156
277
|
}
|
|
157
278
|
}
|
|
158
279
|
const words = (error) => (error instanceof Error ? error.message : String(error));
|
|
@@ -24,4 +24,4 @@ export { type ClaimComputer, type ClaimLaunch, computerForClaim, type ComputerFo
|
|
|
24
24
|
export { JANITOR_EVERY_MS, type JanitorDeps, type ProviderSweep, startJanitor, sweepServerComputers } from "./computer-janitor.js";
|
|
25
25
|
export { agentComputerOf, agentComputerView, ownerGoneOf, reconcileAgentComputer, serverIdOf } from "./agent-computer.js";
|
|
26
26
|
export { layOwnSkills, RUN_SKILLS_DIR } from "./revision-skills.js";
|
|
27
|
-
export { KIND_SKILLS, type KindSkill, kindSkillOf, type SkillKind } from "./kind-skills.js";
|
|
27
|
+
export { KIND_SKILLS, type KindSkill, kindSkillOf, type SkillKind, withoutKindSkill } from "./kind-skills.js";
|
package/dist/workspace/index.js
CHANGED
|
@@ -26,4 +26,4 @@ export { computerForClaim } from "./computer-for-claim.js";
|
|
|
26
26
|
export { JANITOR_EVERY_MS, startJanitor, sweepServerComputers } from "./computer-janitor.js";
|
|
27
27
|
export { agentComputerOf, agentComputerView, ownerGoneOf, reconcileAgentComputer, serverIdOf } from "./agent-computer.js";
|
|
28
28
|
export { layOwnSkills, RUN_SKILLS_DIR } from "./revision-skills.js";
|
|
29
|
-
export { KIND_SKILLS, kindSkillOf } from "./kind-skills.js";
|
|
29
|
+
export { KIND_SKILLS, kindSkillOf, withoutKindSkill } from "./kind-skills.js";
|
|
@@ -9,3 +9,7 @@ export type SkillKind = "desktop" | "phone";
|
|
|
9
9
|
export declare const KIND_SKILLS: Readonly<Record<SkillKind, KindSkill>>;
|
|
10
10
|
/** The skill a run's computer kind brings, if it brings one. */
|
|
11
11
|
export declare const kindSkillOf: (kind: string | undefined) => KindSkill | undefined;
|
|
12
|
+
/** A run's skill files without the one its computer kind brings: for a computer the claim did not start (every tool of
|
|
13
|
+
* it set to deny: ClaimComputer.off), whose skill is named to no one. An authored skill of that name is the agent's own,
|
|
14
|
+
* and stays. */
|
|
15
|
+
export declare function withoutKindSkill(files: readonly string[], authored: Readonly<Record<string, unknown>>, kind: string | undefined): readonly string[];
|
|
@@ -14,3 +14,12 @@ const read = (kind) => {
|
|
|
14
14
|
export const KIND_SKILLS = Object.freeze({ desktop: read("desktop"), phone: read("phone") });
|
|
15
15
|
/** The skill a run's computer kind brings, if it brings one. */
|
|
16
16
|
export const kindSkillOf = (kind) => (kind === "desktop" || kind === "phone" ? KIND_SKILLS[kind] : undefined);
|
|
17
|
+
/** A run's skill files without the one its computer kind brings: for a computer the claim did not start (every tool of
|
|
18
|
+
* it set to deny: ClaimComputer.off), whose skill is named to no one. An authored skill of that name is the agent's own,
|
|
19
|
+
* and stays. */
|
|
20
|
+
export function withoutKindSkill(files, authored, kind) {
|
|
21
|
+
const skill = kindSkillOf(kind);
|
|
22
|
+
if (!skill || Object.keys(authored).some((path) => path.split("/")[0] === skill.name))
|
|
23
|
+
return files;
|
|
24
|
+
return files.filter((file) => file !== `${skill.name}/SKILL.md`);
|
|
25
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Store } from "../store/index.js";
|
|
2
2
|
import type { ComputerDeps } from "./computer-deps.js";
|
|
3
|
+
import { type KeptHolder } from "./computer-kept.js";
|
|
3
4
|
/** The longest a run's end may spend on its computers, every try with its pauses: past it the provider's calls are cut
|
|
4
5
|
* (one that takes no signal, a release, left to finish on its own) and the run's end goes on, said in the log. */
|
|
5
6
|
export declare const RUN_END_COMPUTERS_MS = 120000;
|
|
@@ -8,7 +9,7 @@ export declare const RUN_END_RETRY_MS = 5000;
|
|
|
8
9
|
export interface RunEndComputersDeps {
|
|
9
10
|
/** The run's row and launch (its revision and place) and the agent's revision, where its computer setting is; the
|
|
10
11
|
* computer ledger, for a provider that keeps one. */
|
|
11
|
-
readonly store: Pick<Store, "agents" | "computerLedger"> & {
|
|
12
|
+
readonly store: Pick<Store, "agents" | "computerLedger" | "settings"> & {
|
|
12
13
|
readonly runs: Pick<Store["runs"], "get" | "launch">;
|
|
13
14
|
readonly computerIntervals?: Store["computerIntervals"];
|
|
14
15
|
};
|
|
@@ -17,6 +18,9 @@ export interface RunEndComputersDeps {
|
|
|
17
18
|
readonly computers: Pick<ComputerDeps, "kinds" | "providers" | "keyOf" | "keyTable" | "settings" | "launch" | "launches">;
|
|
18
19
|
/** Where what was let go, and a provider that failed, are said. */
|
|
19
20
|
readonly log: (line: string) => void;
|
|
21
|
+
/** The runner this end runs in (its name and presence incarnation), read at each end: a computer kept pinned to it is
|
|
22
|
+
* its own to let go here. Absent: every kept row that names a runner is another's. */
|
|
23
|
+
readonly self?: () => KeptHolder | undefined;
|
|
20
24
|
/** The bound on every try. Default RUN_END_COMPUTERS_MS. */
|
|
21
25
|
readonly timeoutMs?: number;
|
|
22
26
|
/** The pause between tries. Default RUN_END_RETRY_MS. */
|
|
@@ -15,10 +15,16 @@
|
|
|
15
15
|
// at all (its key is not in this runner's environment or the store) is not. Either is said in the runner's log, and the
|
|
16
16
|
// run's end stands. The janitor (computer-janitor.ts) ends a computer of a run that is over on its next sweep too, for a
|
|
17
17
|
// server that stopped before this ran, or a vendor that stayed down past the bound.
|
|
18
|
+
//
|
|
19
|
+
// Nor a computer the run's park kept pinned to a runner other than this one while that keep lasts (computer-kept.ts: its
|
|
20
|
+
// row names that runner, and is neither ending nor ended): a stop or cancel ends the run on whichever runner claims it,
|
|
21
|
+
// and the machine is the keeping runner's to end, at its time or its janitor's pass. A vendor's list (a dial machine's)
|
|
22
|
+
// shows it here too; it is left out of the list, so nothing under its id is deleted from here.
|
|
18
23
|
import { releaseOlder } from "@parcha/agentrun-computer";
|
|
19
24
|
import { KEY_TABLE, providerOptions } from "../computer-keys.js";
|
|
20
25
|
import { readLaunchBody } from "../run-launch.js";
|
|
21
26
|
import { settingOf } from "./computer-for-claim.js";
|
|
27
|
+
import { keptBy, readKept } from "./computer-kept.js";
|
|
22
28
|
import { storeLedger } from "./computer-ledger.js";
|
|
23
29
|
import { providerKeys } from "./resolve-computer.js";
|
|
24
30
|
import { endingDeletes, intervalWrites } from "./computer-intervals.js";
|
|
@@ -46,6 +52,19 @@ const pause = (ms, signal) => new Promise((resolve) => {
|
|
|
46
52
|
}, ms);
|
|
47
53
|
signal.addEventListener("abort", done, { once: true });
|
|
48
54
|
});
|
|
55
|
+
/** `provider` with the computer `id` left out of its lists: releaseOlder never sees it, so never deletes it. */
|
|
56
|
+
const sparing = (provider, id) => new Proxy(provider, {
|
|
57
|
+
get(target, key) {
|
|
58
|
+
if (key !== "list") {
|
|
59
|
+
const value = Reflect.get(target, key, target);
|
|
60
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
61
|
+
}
|
|
62
|
+
return async (...args) => {
|
|
63
|
+
const listed = await target.list(...args);
|
|
64
|
+
return listed.ok ? { ...listed, value: listed.value.filter((info) => info.ref.id !== id) } : listed;
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
});
|
|
49
68
|
/** The run's end for its computers (RunEndComputersDeps): given the claim that ended the run, every computer of the run
|
|
50
69
|
* at or below its epoch deleted, a provider that did not answer asked again until the bound. Never throws: a failure
|
|
51
70
|
* is said in the log. */
|
|
@@ -79,6 +98,12 @@ export function runEndComputers(deps) {
|
|
|
79
98
|
// A throw from here on is the vendor's or the daemon's (Docker's architecture asked): asked again.
|
|
80
99
|
return endingDeletes(await make(options.options, { ledger: storeLedger(store.computerLedger, entry.id) }), entry.id, writes);
|
|
81
100
|
};
|
|
101
|
+
/** The id of the run's computer its park kept pinned to a runner other than this one, while the keep lasts; a read
|
|
102
|
+
* that fails throws, and is asked again (a delete from here must not guess). */
|
|
103
|
+
const keptElsewhere = async (runId) => {
|
|
104
|
+
const kept = await readKept(store.settings, runId);
|
|
105
|
+
return kept && kept.runner !== undefined && !kept.ending && !kept.ended && !keptBy(kept, deps.self?.()) ? kept.id : undefined;
|
|
106
|
+
};
|
|
82
107
|
return async ({ runId, epoch }) => {
|
|
83
108
|
if (epoch <= 1)
|
|
84
109
|
return;
|
|
@@ -99,8 +124,9 @@ export function runEndComputers(deps) {
|
|
|
99
124
|
const provider = await providerOf(runId, epoch);
|
|
100
125
|
if (!provider)
|
|
101
126
|
return;
|
|
127
|
+
const spared = await keptElsewhere(runId);
|
|
102
128
|
// Every claim's at or below this one's: a computer of a later epoch fences the call (a later claim holds the run).
|
|
103
|
-
const released = await releaseOlder(provider, runId, epoch + 1, { signal });
|
|
129
|
+
const released = await releaseOlder(spared === undefined ? provider : sparing(provider, spared), runId, epoch + 1, { signal });
|
|
104
130
|
if (released.ok) {
|
|
105
131
|
const names = released.value.released.map((ref) => ref.name);
|
|
106
132
|
if (names.length > 0)
|
|
@@ -101,11 +101,10 @@ async function* tarEntries(store, { entries, meta }) {
|
|
|
101
101
|
export async function holdSynced(store, client, stored, signal) {
|
|
102
102
|
const folder = new FolderSync(client, store);
|
|
103
103
|
const options = signal ? { signal } : {};
|
|
104
|
-
// An empty folder
|
|
105
|
-
const
|
|
106
|
-
const held = empty ? await folder.baseline(options) : await folder.push(tarEntries(store, stored), options);
|
|
104
|
+
// An empty folder is an empty tar, as conformance pushes it.
|
|
105
|
+
const held = await folder.push(tarEntries(store, stored), options);
|
|
107
106
|
if (!held.ok)
|
|
108
|
-
throw new Error(
|
|
107
|
+
throw new Error(`the run's folder ${held.error.message}`);
|
|
109
108
|
for (const path of stored.linkObjects) {
|
|
110
109
|
const removed = await store.remove(path, "file");
|
|
111
110
|
if (!removed.ok)
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { Wrapped } from "@parcha/agentrun-import";
|
|
2
|
+
/** `wrapped` (the import package's) as GET /v2/wrapped serves it, and the runs imported from each source (`imported`). */
|
|
3
|
+
export declare function wrappedView(wrapped: Wrapped, imported: readonly {
|
|
4
|
+
source: string;
|
|
5
|
+
runs: number;
|
|
6
|
+
}[], unreadFiles?: number): {
|
|
7
|
+
year: number;
|
|
8
|
+
sessions: number;
|
|
9
|
+
turns: number;
|
|
10
|
+
requests: number;
|
|
11
|
+
tokens: {
|
|
12
|
+
input: number;
|
|
13
|
+
output: number;
|
|
14
|
+
cache_read: number;
|
|
15
|
+
cache_write: number;
|
|
16
|
+
};
|
|
17
|
+
cost_usd: number;
|
|
18
|
+
unpriced_requests: number;
|
|
19
|
+
days: {
|
|
20
|
+
day: string;
|
|
21
|
+
requests: number;
|
|
22
|
+
tokens: number;
|
|
23
|
+
}[];
|
|
24
|
+
hours: number[];
|
|
25
|
+
weekdays: number[];
|
|
26
|
+
active_ms: number;
|
|
27
|
+
harnesses: {
|
|
28
|
+
harness: string;
|
|
29
|
+
sessions: number;
|
|
30
|
+
requests: number;
|
|
31
|
+
tokens: number;
|
|
32
|
+
}[];
|
|
33
|
+
models: {
|
|
34
|
+
model: string;
|
|
35
|
+
requests: number;
|
|
36
|
+
tokens: number;
|
|
37
|
+
cost_usd: number;
|
|
38
|
+
}[];
|
|
39
|
+
sources: {
|
|
40
|
+
source: string;
|
|
41
|
+
sessions: number;
|
|
42
|
+
requests: number;
|
|
43
|
+
}[];
|
|
44
|
+
imported: {
|
|
45
|
+
source: string;
|
|
46
|
+
runs: number;
|
|
47
|
+
}[];
|
|
48
|
+
unread_files: number;
|
|
49
|
+
};
|
|
50
|
+
/** How long GET /v2/wrapped waits for a read before it answers 503 with a retry (the read goes on). */
|
|
51
|
+
export declare const WRAPPED_WAIT_MS = 15000;
|
|
52
|
+
/** A year's wrappedHome over this machine's home, and how many session files it could not read (one gone since it was
|
|
53
|
+
* listed, or one this user cannot open): the numbers are short by those, and say so. */
|
|
54
|
+
export type WrappedRead = {
|
|
55
|
+
wrapped: Wrapped;
|
|
56
|
+
unread: number;
|
|
57
|
+
};
|
|
58
|
+
/** `read` (one year's read, on the server's import worker), each year's shared: a read still going, or waiting its turn,
|
|
59
|
+
* is shared however long it takes; once it ends, a year already over when its read began is kept until the server stops
|
|
60
|
+
* (its requests were all in), and any other (this year's, or one that ended while it was read) for a minute. One read at
|
|
61
|
+
* a time: each is a worker holding a year's sessions, so a year asked while another is read waits for it to end. A read
|
|
62
|
+
* that fails is dropped, so the next ask reads again, and frees the turn. One per server. */
|
|
63
|
+
export declare function keptReads(read: (year: number) => Promise<WrappedRead>): (year: number) => Promise<WrappedRead>;
|
|
64
|
+
/** `read`'s answer if it comes within `ms`, else undefined (the read goes on). */
|
|
65
|
+
export declare function within<T>(read: Promise<T>, ms: number): Promise<T | undefined>;
|
package/dist/wrapped.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
const total = ({ input, output, cacheRead, cacheWrite }) => input + output + cacheRead + cacheWrite;
|
|
2
|
+
/** `wrapped` (the import package's) as GET /v2/wrapped serves it, and the runs imported from each source (`imported`). */
|
|
3
|
+
export function wrappedView(wrapped, imported, unreadFiles = 0) {
|
|
4
|
+
const { input, output, cacheRead, cacheWrite } = wrapped.tokens;
|
|
5
|
+
return {
|
|
6
|
+
year: wrapped.year,
|
|
7
|
+
sessions: wrapped.sessions,
|
|
8
|
+
turns: wrapped.turns,
|
|
9
|
+
requests: wrapped.requests,
|
|
10
|
+
tokens: { input, output, cache_read: cacheRead, cache_write: cacheWrite },
|
|
11
|
+
cost_usd: wrapped.cost,
|
|
12
|
+
unpriced_requests: wrapped.unpricedRequests,
|
|
13
|
+
days: wrapped.days,
|
|
14
|
+
hours: wrapped.hours,
|
|
15
|
+
weekdays: wrapped.weekdays,
|
|
16
|
+
active_ms: wrapped.activeMs,
|
|
17
|
+
harnesses: wrapped.harnesses,
|
|
18
|
+
models: wrapped.models.map(({ model, requests, tokens, cost }) => ({ model, requests, tokens: total(tokens), cost_usd: cost })),
|
|
19
|
+
sources: wrapped.sources,
|
|
20
|
+
imported: imported.map(({ source, runs }) => ({ source, runs })),
|
|
21
|
+
unread_files: unreadFiles,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/** A read of the current year is kept for a minute after it ends: a whole home is a long read. */
|
|
25
|
+
const KEEP_MS = 60_000;
|
|
26
|
+
/** How long GET /v2/wrapped waits for a read before it answers 503 with a retry (the read goes on). */
|
|
27
|
+
export const WRAPPED_WAIT_MS = 15_000;
|
|
28
|
+
/** `read` (one year's read, on the server's import worker), each year's shared: a read still going, or waiting its turn,
|
|
29
|
+
* is shared however long it takes; once it ends, a year already over when its read began is kept until the server stops
|
|
30
|
+
* (its requests were all in), and any other (this year's, or one that ended while it was read) for a minute. One read at
|
|
31
|
+
* a time: each is a worker holding a year's sessions, so a year asked while another is read waits for it to end. A read
|
|
32
|
+
* that fails is dropped, so the next ask reads again, and frees the turn. One per server. */
|
|
33
|
+
export function keptReads(read) {
|
|
34
|
+
const kept = new Map();
|
|
35
|
+
// The read whose turn it is or the last one given a turn, until it ends: the next starts after it.
|
|
36
|
+
let turn;
|
|
37
|
+
const inTurn = (start) => {
|
|
38
|
+
const started = turn ? turn.then(start) : start();
|
|
39
|
+
const mine = started.then(() => undefined, () => undefined);
|
|
40
|
+
turn = mine;
|
|
41
|
+
void mine.then(() => {
|
|
42
|
+
if (turn === mine)
|
|
43
|
+
turn = undefined;
|
|
44
|
+
});
|
|
45
|
+
return started;
|
|
46
|
+
};
|
|
47
|
+
return (year) => {
|
|
48
|
+
const held = kept.get(year);
|
|
49
|
+
const now = Date.now();
|
|
50
|
+
if (held && (held.at === undefined || year < held.began || now - held.at < KEEP_MS))
|
|
51
|
+
return held.read;
|
|
52
|
+
const entry = {};
|
|
53
|
+
entry.read = inTurn(() => {
|
|
54
|
+
entry.began = new Date(Date.now()).getFullYear();
|
|
55
|
+
return read(year);
|
|
56
|
+
});
|
|
57
|
+
kept.set(year, entry);
|
|
58
|
+
entry.read.then(() => {
|
|
59
|
+
entry.at = Date.now();
|
|
60
|
+
}, () => {
|
|
61
|
+
if (kept.get(year) === entry)
|
|
62
|
+
kept.delete(year);
|
|
63
|
+
});
|
|
64
|
+
return entry.read;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/** `read`'s answer if it comes within `ms`, else undefined (the read goes on). */
|
|
68
|
+
export async function within(read, ms) {
|
|
69
|
+
let timer;
|
|
70
|
+
const late = new Promise((resolve) => void (timer = setTimeout(resolve, ms, undefined)));
|
|
71
|
+
try {
|
|
72
|
+
return await Promise.race([read, late]);
|
|
73
|
+
}
|
|
74
|
+
finally {
|
|
75
|
+
clearTimeout(timer);
|
|
76
|
+
}
|
|
77
|
+
}
|
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.57",
|
|
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",
|
|
@@ -66,16 +66,22 @@
|
|
|
66
66
|
"@earendil-works/pi-coding-agent": "1.5.2",
|
|
67
67
|
"@modelcontextprotocol/client": "2.4.0",
|
|
68
68
|
"@modelcontextprotocol/server": "2.4.0",
|
|
69
|
-
"@
|
|
70
|
-
"@
|
|
71
|
-
"@
|
|
72
|
-
"@
|
|
73
|
-
"@
|
|
74
|
-
"@parcha/agentrun-
|
|
75
|
-
"@parcha/agentrun-
|
|
76
|
-
"@parcha/agentrun-
|
|
77
|
-
"@parcha/agentrun-
|
|
78
|
-
"@parcha/
|
|
69
|
+
"@opentelemetry/api": "1.10.0",
|
|
70
|
+
"@opentelemetry/exporter-trace-otlp-http": "0.301.2",
|
|
71
|
+
"@opentelemetry/resources": "3.1.1",
|
|
72
|
+
"@opentelemetry/sdk-trace": "3.1.1",
|
|
73
|
+
"@opentelemetry/semantic-conventions": "1.43.0",
|
|
74
|
+
"@parcha/agentrun-computer": "0.1.0-beta.57",
|
|
75
|
+
"@parcha/agentrun-decisions": "0.1.0-beta.57",
|
|
76
|
+
"@parcha/agentrun-dsl": "0.1.0-beta.57",
|
|
77
|
+
"@parcha/agentrun-harness-acp": "0.1.0-beta.57",
|
|
78
|
+
"@parcha/agentrun-harness-claude": "0.1.0-beta.57",
|
|
79
|
+
"@parcha/agentrun-harness-codex": "0.1.0-beta.57",
|
|
80
|
+
"@parcha/agentrun-import": "0.1.0-beta.57",
|
|
81
|
+
"@parcha/agentrun-jev": "0.1.0-beta.57",
|
|
82
|
+
"@parcha/agentrun-kernel": "0.1.0-beta.57",
|
|
83
|
+
"@parcha/agentrun-web": "0.1.0-beta.57",
|
|
84
|
+
"@parcha/pi-browser": "0.1.0-beta.57",
|
|
79
85
|
"@secretlint/core": "14.1.0",
|
|
80
86
|
"@secretlint/profiler": "14.1.0",
|
|
81
87
|
"croner": "11.0.0",
|
|
@@ -20,6 +20,10 @@ forbidden` with `error.details.console_url`, the console's form with the rest fi
|
|
|
20
20
|
Open that link in the person's browser for them and tell them to paste the secret there and save. Never ask for a
|
|
21
21
|
secret in the chat.
|
|
22
22
|
|
|
23
|
+
An API key for an app (`AGENTRUN_API_KEY`) is made the same way: the owner makes it in the console at
|
|
24
|
+
`<console>/#/settings/api-keys`, where it is shown once. `POST /v2/settings/api-keys` with the token is `403
|
|
25
|
+
forbidden`. A key the owner hands you is sent as the token is, as `Authorization: Bearer <key>`.
|
|
26
|
+
|
|
23
27
|
## Choose the onboarding path
|
|
24
28
|
|
|
25
29
|
For general setup, establish whether the user wants to **start a new agent** or **bring an existing agent**.
|