@parcha/agentrun-serve 0.1.0-beta.44 → 0.1.0-beta.46
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 +148 -5
- package/README.md +385 -305
- package/dist/acp-package.d.ts +28 -0
- package/dist/acp-package.js +23 -0
- package/dist/adapter-facts.d.ts +8 -1
- package/dist/adapter-facts.js +9 -1
- package/dist/adapters.d.ts +5 -0
- package/dist/adapters.js +36 -3
- package/dist/agent-delete.d.ts +50 -0
- package/dist/agent-delete.js +125 -0
- package/dist/agents-store.d.ts +9 -3
- package/dist/agents-store.js +22 -8
- package/dist/agents.d.ts +5 -1
- package/dist/agents.js +8 -4
- package/dist/api-only.d.ts +8 -3
- package/dist/api-only.js +10 -4
- package/dist/archil-routes.d.ts +5 -1
- package/dist/archil-routes.js +57 -2
- package/dist/browser-wait-ended.d.ts +2 -0
- package/dist/browser-wait-ended.js +2 -0
- package/dist/calendar/ics-faux.d.ts +3 -1
- package/dist/calendar/ics-faux.js +12 -2
- package/dist/calendar/tools.js +5 -2
- package/dist/chatgpt-plan.js +3 -1
- package/dist/claude-login.d.ts +135 -0
- package/dist/claude-login.js +244 -0
- package/dist/cli.js +62 -19
- package/dist/composio-preset.js +69 -7
- package/dist/composio-triggers.d.ts +14 -0
- package/dist/composio-triggers.js +79 -15
- package/dist/computer-attach.d.ts +40 -5
- package/dist/computer-attach.js +130 -15
- package/dist/computer-keys.d.ts +3 -0
- package/dist/computer-keys.js +7 -1
- package/dist/computer-live.js +3 -2
- package/dist/computers.d.ts +21 -10
- package/dist/computers.js +39 -28
- package/dist/console/assets/index-C2MYaUBa.css +1 -0
- package/dist/console/assets/index-CZZeCReB.js +701 -0
- package/dist/console/index.html +2 -2
- package/dist/decisions.d.ts +1 -1
- package/dist/dial-relay.d.ts +29 -0
- package/dist/dial-relay.js +94 -0
- package/dist/email/tools.js +10 -5
- package/dist/env-proxy.d.ts +2 -0
- package/dist/env-proxy.js +35 -0
- package/dist/errors.d.ts +3 -1
- package/dist/errors.js +7 -4
- package/dist/faux-computers.d.ts +8 -2
- package/dist/faux-computers.js +83 -6
- package/dist/harness-archive.d.ts +67 -0
- package/dist/harness-archive.js +177 -0
- package/dist/harness-goose.d.ts +34 -0
- package/dist/harness-goose.js +87 -0
- package/dist/harness-install.d.ts +21 -0
- package/dist/harness-install.js +24 -11
- package/dist/harness-opencode/adapter.js +1 -1
- package/dist/harness-table.d.ts +9 -1
- package/dist/harness-table.js +20 -3
- package/dist/harness.d.ts +1 -2
- package/dist/harness.js +3 -4
- package/dist/host.js +2 -1
- package/dist/import.d.ts +10 -0
- package/dist/import.js +28 -8
- package/dist/key-check.js +3 -0
- package/dist/learn/audit.d.ts +6 -6
- package/dist/learn/audit.js +3 -7
- package/dist/learn/check.d.ts +23 -89
- package/dist/learn/check.js +57 -335
- package/dist/learn/commit.d.ts +63 -90
- package/dist/learn/commit.js +124 -316
- package/dist/learn/compile.d.ts +53 -50
- package/dist/learn/compile.js +89 -104
- package/dist/learn/corrections.d.ts +13 -0
- package/dist/learn/corrections.js +23 -0
- package/dist/learn/delete.d.ts +5 -5
- package/dist/learn/delete.js +8 -10
- package/dist/learn/folder.d.ts +35 -47
- package/dist/learn/folder.js +118 -134
- package/dist/learn/index.d.ts +3 -5
- package/dist/learn/index.js +6 -9
- package/dist/learn/learning.sh +45 -15
- package/dist/learn/promote.d.ts +23 -5
- package/dist/learn/promote.js +40 -2
- package/dist/learn/{skills.d.ts → workflow-draft.d.ts} +30 -38
- package/dist/learn/{skills.js → workflow-draft.js} +48 -58
- package/dist/learn/workflow-nodes.js +1 -1
- package/dist/learned-workflow.js +2 -2
- package/dist/learning-cost.d.ts +38 -24
- package/dist/learning-cost.js +41 -24
- package/dist/learning-routes.d.ts +91 -170
- package/dist/learning-routes.js +183 -421
- package/dist/learning-run.d.ts +19 -40
- package/dist/learning-run.js +23 -93
- package/dist/learning-setting.d.ts +21 -10
- package/dist/learning-setting.js +47 -11
- package/dist/learning-words.d.ts +28 -74
- package/dist/learning-words.js +64 -162
- package/dist/learning.d.ts +61 -392
- package/dist/learning.js +101 -651
- package/dist/live-reach.d.ts +25 -2
- package/dist/live-reach.js +46 -4
- package/dist/llms.txt +1 -1
- package/dist/local-models.d.ts +3 -11
- package/dist/local-models.js +5 -6
- package/dist/mcp-servers-store.d.ts +4 -4
- package/dist/model-form.js +6 -5
- package/dist/model.d.ts +4 -0
- package/dist/model.js +26 -9
- package/dist/native/binding.js +1 -1
- package/dist/native/connection.js +1 -1
- package/dist/native/discovery.js +1 -1
- package/dist/native/instructions.d.ts +3 -0
- package/dist/native/instructions.js +5 -3
- package/dist/native/remote-worker-bridge.js +9 -43
- package/dist/native/remote.d.ts +8 -15
- package/dist/native/remote.js +3 -3
- package/dist/native/schema.js +1 -1
- package/dist/native/types.d.ts +2 -2
- package/dist/openapi.js +273 -319
- package/dist/paid-calls.d.ts +8 -0
- package/dist/paid-calls.js +20 -0
- package/dist/particle-provider.d.ts +11 -0
- package/dist/particle-provider.js +135 -0
- package/dist/port-models.d.ts +12 -4
- package/dist/port-models.js +28 -11
- package/dist/print.d.ts +27 -0
- package/dist/print.js +21 -0
- package/dist/provider.d.ts +7 -0
- package/dist/provider.js +15 -1
- package/dist/reflect-range.js +2 -3
- package/dist/run-launch.d.ts +14 -28
- package/dist/run-launch.js +9 -12
- package/dist/run-learning-served.d.ts +15 -89
- package/dist/run-listing.d.ts +34 -0
- package/dist/run-listing.js +128 -0
- package/dist/run-model-key.js +1 -1
- package/dist/run-timeline-served.js +5 -3
- package/dist/run-trace.d.ts +97 -0
- package/dist/run-trace.js +253 -0
- package/dist/run-view.d.ts +15 -0
- package/dist/run-view.js +9 -0
- package/dist/runnable.js +2 -1
- package/dist/runner/adapter-loop.d.ts +8 -6
- package/dist/runner/adapter-loop.js +16 -12
- package/dist/runner/adapter-run-spec.d.ts +16 -4
- package/dist/runner/adapter-run-spec.js +64 -58
- package/dist/runner/adapters/index.js +22 -0
- package/dist/runner/adapters/pi.d.ts +4 -12
- package/dist/runner/adapters/pi.js +2 -2
- package/dist/runner/audit.d.ts +1 -1
- package/dist/runner/audit.js +30 -13
- package/dist/runner/beside.d.ts +6 -2
- package/dist/runner/beside.js +38 -9
- package/dist/runner/claim-secrets.d.ts +18 -2
- package/dist/runner/claim-secrets.js +42 -18
- package/dist/runner/cli-run-spec.js +55 -51
- package/dist/runner/conformance/harness.d.ts +6 -0
- package/dist/runner/conformance/harness.js +35 -13
- package/dist/runner/conformance/subject.d.ts +6 -0
- package/dist/runner/dispatch.d.ts +2 -2
- package/dist/runner/end-of-run.d.ts +6 -14
- package/dist/runner/end-of-run.js +8 -33
- package/dist/runner/feedback-round.d.ts +2 -2
- package/dist/runner/feedback-round.js +7 -7
- package/dist/runner/github-app.js +3 -1
- package/dist/runner/harness-loops.d.ts +0 -8
- package/dist/runner/harness-loops.js +11 -59
- package/dist/runner/held.d.ts +170 -0
- package/dist/runner/held.js +57 -0
- package/dist/runner/journal-kinds.d.ts +2 -3
- package/dist/runner/journal-kinds.js +2 -3
- package/dist/runner/learned-first.d.ts +40 -0
- package/dist/runner/learned-first.js +32 -0
- package/dist/runner/learning-end.d.ts +77 -69
- package/dist/runner/learning-end.js +250 -303
- package/dist/runner/learning-seed.d.ts +15 -33
- package/dist/runner/learning-seed.js +24 -45
- package/dist/runner/loop-contract.d.ts +2 -3
- package/dist/runner/main.d.ts +17 -9
- package/dist/runner/main.js +82 -20
- package/dist/runner/mcp-run.d.ts +11 -0
- package/dist/runner/mcp-run.js +67 -0
- package/dist/runner/memory-claim.d.ts +10 -5
- package/dist/runner/memory-claim.js +12 -6
- package/dist/runner/model-route.d.ts +7 -4
- package/dist/runner/model-route.js +22 -10
- package/dist/runner/native-loop.d.ts +0 -7
- package/dist/runner/native-loop.js +9 -101
- package/dist/runner/promotion.d.ts +12 -8
- package/dist/runner/promotion.js +37 -28
- package/dist/runner/reflect-hook.d.ts +64 -95
- package/dist/runner/reflect-hook.js +112 -225
- package/dist/runner/run-channel.d.ts +43 -0
- package/dist/runner/run-channel.js +467 -0
- package/dist/runner/run-child-host.d.ts +169 -0
- package/dist/runner/run-child-host.js +1230 -0
- package/dist/runner/run-child.d.ts +1 -0
- package/dist/runner/run-child.js +254 -0
- package/dist/runner/run-errors.d.ts +2 -0
- package/dist/runner/run-errors.js +20 -0
- package/dist/runner/runner.js +1 -5
- package/dist/runner/sdk-ask.d.ts +78 -0
- package/dist/runner/sdk-ask.js +158 -0
- package/dist/runner/sdk-loop.d.ts +2 -4
- package/dist/runner/sdk-loop.js +29 -49
- package/dist/runner/store-secrets.d.ts +5 -3
- package/dist/runner/store-secrets.js +5 -1
- package/dist/runner/workflow-first.d.ts +5 -0
- package/dist/runner/workflow-first.js +4 -0
- package/dist/runner/workflow-spec.js +7 -2
- package/dist/runs-over-store.d.ts +16 -28
- package/dist/runs-over-store.js +31 -38
- package/dist/sdk/runs.d.ts +6 -11
- package/dist/sdk/runs.js +20 -41
- package/dist/sdk/schema.js +3 -4
- package/dist/seal-key.d.ts +5 -0
- package/dist/seal-key.js +7 -0
- package/dist/secrets.d.ts +3 -0
- package/dist/secrets.js +16 -3
- package/dist/server.d.ts +55 -33
- package/dist/server.js +689 -322
- package/dist/sign-ins-store.d.ts +8 -0
- package/dist/sign-ins-store.js +36 -1
- package/dist/skills.js +1 -1
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/journal/storage.js +3 -0
- package/dist/store/postgres/migrations/0017_run_listing.sql +83 -0
- package/dist/store/postgres/migrations/0018_trigger_template.sql +6 -0
- package/dist/store/postgres/migrations/0019_runner_relays.sql +28 -0
- package/dist/store/schema.d.ts +53 -4
- package/dist/store/schema.js +137 -6
- package/dist/store/sqlite/connection.d.ts +2 -0
- package/dist/store/sqlite/connection.js +3 -1
- package/dist/store/sqlite/run-patch.d.ts +0 -17
- package/dist/store/sqlite/run-patch.js +4 -33
- package/dist/store/sqlite/store.js +246 -63
- package/dist/store/sqlite/worker.js +25 -0
- package/dist/store/store.d.ts +193 -36
- package/dist/store/store.js +25 -3
- package/dist/store-reads/learning.d.ts +102 -204
- package/dist/store-reads/learning.js +159 -321
- package/dist/store-reads/loop.d.ts +0 -1
- package/dist/store-reads/loop.js +1 -1
- package/dist/store-view.d.ts +29 -1
- package/dist/store-view.js +97 -31
- package/dist/template-eval.d.ts +3 -6
- package/dist/template-eval.js +22 -36
- package/dist/templates.d.ts +8 -4
- package/dist/templates.js +44 -6
- package/dist/timeline/index.d.ts +1 -1
- package/dist/timeline/index.js +1 -1
- package/dist/timeline/timeline.d.ts +5 -1
- package/dist/timeline/timeline.js +16 -0
- package/dist/tool-gate.d.ts +0 -7
- package/dist/tool-gate.js +1 -15
- package/dist/tool-keys-store.d.ts +1 -1
- package/dist/tool-keys.d.ts +6 -4
- package/dist/tool-keys.js +12 -6
- package/dist/tools.d.ts +2 -2
- package/dist/tools.js +11 -4
- package/dist/triggers.d.ts +65 -6
- package/dist/triggers.js +125 -19
- package/dist/validate.js +1 -1
- package/dist/webhooks.d.ts +7 -2
- package/dist/webhooks.js +12 -5
- package/dist/workspace/agent-computer.d.ts +2 -0
- package/dist/workspace/agent-computer.js +2 -0
- package/dist/workspace/archil-claim.d.ts +7 -0
- package/dist/workspace/archil-claim.js +29 -0
- package/dist/workspace/archil.d.ts +9 -1
- package/dist/workspace/archil.js +165 -3
- package/dist/workspace/attach.d.ts +3 -1
- package/dist/workspace/attach.js +2 -0
- package/dist/workspace/attached-computers.d.ts +16 -5
- package/dist/workspace/attached-computers.js +25 -9
- package/dist/workspace/computer-deps.js +1 -1
- package/dist/workspace/computer-for-claim.d.ts +7 -3
- package/dist/workspace/computer-for-claim.js +119 -22
- package/dist/workspace/computer-hold.js +2 -1
- package/dist/workspace/computer-kept.d.ts +11 -1
- package/dist/workspace/computer-kept.js +24 -3
- package/dist/workspace/resolve-computer.d.ts +33 -19
- package/dist/workspace/resolve-computer.js +172 -64
- package/dist/workspace/revision-skills.d.ts +1 -2
- package/dist/workspace/revision-skills.js +3 -4
- package/dist/workspace/run-workspace.d.ts +1 -1
- package/dist/workspace/run-workspace.js +5 -0
- package/dist/workspace/synced-folder.d.ts +85 -0
- package/dist/workspace/synced-folder.js +230 -0
- package/dist/workspace/workspace.d.ts +4 -0
- package/launcher/agentrun-serve +1 -1
- package/package.json +10 -10
- package/templates/README.md +8 -8
- package/templates/inbound-lead/agent.md +5 -4
- package/templates/inbound-lead/evals/learned-correction/case.yaml +3 -3
- package/templates/inbound-lead/evals/learned-correction/fixtures/corrections.md +1 -0
- package/templates/inbound-lead/evals/learned-correction/graders/applies-correction.md +22 -0
- package/templates/inbound-lead/evals/learned-correction/graders/learned-origin.md +1 -1
- package/templates/inbound-lead/evals/learned-correction/prompt.md +1 -1
- package/templates/inbound-lead/lead.schema.json +6 -5
- package/templates/inbound-lead/rules/RUBRIC.md +4 -4
- package/templates/inbound-lead/skills/lead/SKILL.md +4 -4
- package/templates/kyb/agent.md +2 -1
- package/templates/market-monitor/evals/learned-preference/case.yaml +4 -4
- package/templates/market-monitor/evals/learned-preference/fixtures/corrections.md +1 -0
- package/templates/market-monitor/evals/learned-preference/graders/omits-junior-post.md +3 -3
- package/templates/market-monitor/evals/learned-preference/prompt.md +1 -1
- package/templates/release-notes/evals/learned-style/case.yaml +4 -4
- package/templates/release-notes/evals/learned-style/fixtures/corrections.md +1 -0
- package/templates/release-notes/evals/learned-style/graders/same-changes.md +2 -2
- package/templates/release-notes/evals/learned-style/prompt.md +1 -1
- package/dist/console/assets/index-BUktRvS-.css +0 -1
- package/dist/console/assets/index-nB9kTfIN.js +0 -711
- package/dist/learn/grade.d.ts +0 -138
- package/dist/learn/grade.js +0 -682
- package/dist/learn/notes.d.ts +0 -81
- package/dist/learn/notes.js +0 -178
- package/dist/learn/reflect.d.ts +0 -77
- package/dist/learn/reflect.js +0 -228
- package/dist/learn/relevance.d.ts +0 -24
- package/dist/learn/relevance.js +0 -91
- package/dist/learn/seed-check.d.ts +0 -74
- package/dist/learn/seed-check.js +0 -103
- package/dist/learning-batch.d.ts +0 -291
- package/dist/learning-batch.js +0 -600
- package/dist/learning-evals.d.ts +0 -35
- package/dist/learning-evals.js +0 -99
- package/dist/native/context.d.ts +0 -6
- package/dist/native/context.js +0 -22
- package/dist/propose.d.ts +0 -52
- package/dist/propose.js +0 -224
- package/dist/runner/learning-ask.d.ts +0 -47
- package/dist/runner/learning-ask.js +0 -128
- package/dist/runner/learning-dispatch.d.ts +0 -45
- package/dist/runner/learning-dispatch.js +0 -99
- package/dist/runner/learning-factory.d.ts +0 -16
- package/dist/runner/learning-factory.js +0 -50
- package/dist/runner/learning-loop.d.ts +0 -273
- package/dist/runner/learning-loop.js +0 -521
- package/dist/usage.d.ts +0 -11
- package/dist/usage.js +0 -11
- package/templates/inbound-lead/evals/learned-correction/fixtures/learning/MEMORY.md +0 -1
- package/templates/inbound-lead/evals/learned-correction/fixtures/learning/no-agencies.md +0 -14
- package/templates/inbound-lead/evals/learned-correction/graders/applies-note.md +0 -21
- package/templates/market-monitor/evals/learned-preference/fixtures/learning/MEMORY.md +0 -1
- package/templates/market-monitor/evals/learned-preference/fixtures/learning/skip-junior-job-posts.md +0 -8
- package/templates/release-notes/evals/learned-style/fixtures/learning/MEMORY.md +0 -1
- package/templates/release-notes/evals/learned-style/fixtures/learning/say-agent-not-bot.md +0 -13
package/dist/triggers.js
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
// now. A failed firing queues a trigger.failed webhook message.
|
|
24
24
|
import { createHash, randomBytes } from "node:crypto";
|
|
25
25
|
import { TRIGGER_LABELS } from "./timeline/index.js";
|
|
26
|
+
import { agentDeleting } from "./agents.js";
|
|
26
27
|
import { ApiError, invalid } from "./errors.js";
|
|
27
28
|
import { EFFORTS } from "./model.js";
|
|
28
29
|
import { AgentArchived, StoreConstraint, TriggerFull } from "./store/index.js";
|
|
@@ -217,6 +218,11 @@ export class Triggers {
|
|
|
217
218
|
/** Each trigger's firings, driven one after another in the order asked: a firing's overlap check reads what the one
|
|
218
219
|
* before it settled to. */
|
|
219
220
|
turns = new Map();
|
|
221
|
+
/** Each trigger's removals and the edits that name a target (the one way it moves to another agent), one after another
|
|
222
|
+
* on this server: a move never lands between a template update's delete of its Composio instance and its conditional
|
|
223
|
+
* delete of the row (remove), so a moved trigger never stands on an instance that delete took. Across servers the
|
|
224
|
+
* store's conditional write holds the row. Removed from the map once idle. */
|
|
225
|
+
edits = new Map();
|
|
220
226
|
/** Whether a firing waits for its trigger's room (max_active_runs): the timer then reads the store every WAIT_POLL_MS. */
|
|
221
227
|
waiting = false;
|
|
222
228
|
/** The triggers whose day-kept keys are at their cap, said once until they are under it again. */
|
|
@@ -270,7 +276,7 @@ export class Triggers {
|
|
|
270
276
|
await this.need(id);
|
|
271
277
|
return { firings: (await this.store.triggers.firings(id)).map(firingView) };
|
|
272
278
|
}
|
|
273
|
-
async create(body) {
|
|
279
|
+
async create(body, own = {}) {
|
|
274
280
|
const now = this.clock.now();
|
|
275
281
|
const { issues, source, target, settings } = readBody(this.adapters, body, now);
|
|
276
282
|
// Checked as its runs are given it: the input, then the line saying what fired it (a name the trigger may yet take).
|
|
@@ -281,6 +287,9 @@ export class Triggers {
|
|
|
281
287
|
const agentId = await this.agentOf(target);
|
|
282
288
|
const id = `trg_${randomBytes(12).toString("hex")}`;
|
|
283
289
|
const enabled = body.enabled !== false;
|
|
290
|
+
// None for an agent being deleted, off too, told before anything is minted or registered upstream (the store's own
|
|
291
|
+
// refusal is the backstop): the delete has listed its triggers already.
|
|
292
|
+
await this.needNotDeleting(agentId);
|
|
284
293
|
if (enabled)
|
|
285
294
|
await this.needAvailable(source.kind);
|
|
286
295
|
// Never made on for an archived agent: told before anything is minted (the store's own refusal is the backstop).
|
|
@@ -294,7 +303,7 @@ export class Triggers {
|
|
|
294
303
|
try {
|
|
295
304
|
// Its secrets are kept before the trigger is: one whose secret cannot be kept makes none.
|
|
296
305
|
const minted = await this.mint(kept, id);
|
|
297
|
-
const row = await this.store.triggers.create({ id, agentId, name, enabled, source: kept, target, nextAt: enabled ? nextAfter(this.adapter(kept), kept, now) : null, catchupWindowS: settings.catchup_window_s ?? CATCHUP_WINDOW_S, ...(typeof settings.max_active_runs === "number" ? { maxActiveRuns: settings.max_active_runs } : {}) }, this.scopesOf(kept));
|
|
306
|
+
const row = await this.store.triggers.create({ id, agentId, name, enabled, source: kept, target, nextAt: enabled ? nextAfter(this.adapter(kept), kept, now) : null, catchupWindowS: settings.catchup_window_s ?? CATCHUP_WINDOW_S, ...(typeof settings.max_active_runs === "number" ? { maxActiveRuns: settings.max_active_runs } : {}), ...(own.templateId !== undefined ? { templateId: own.templateId } : {}) }, this.scopesOf(kept));
|
|
298
307
|
return { row, minted };
|
|
299
308
|
}
|
|
300
309
|
catch (error) {
|
|
@@ -391,6 +400,13 @@ export class Triggers {
|
|
|
391
400
|
if (agent?.archivedAt != null)
|
|
392
401
|
throw new ApiError("agent_archived", archivedDetail(agent.name));
|
|
393
402
|
}
|
|
403
|
+
/** Refused (409 agent_not_runnable, agents.ts agentDeleting) when agent `agentId` is being deleted: another system's
|
|
404
|
+
* agent with an archive time, which only its delete writes (agent-delete.ts). */
|
|
405
|
+
async needNotDeleting(agentId) {
|
|
406
|
+
const agent = await this.store.agents.get(agentId);
|
|
407
|
+
if (agent?.archivedAt != null && agent.externalRef != null)
|
|
408
|
+
throw agentDeleting(agentId);
|
|
409
|
+
}
|
|
394
410
|
/** The store's refusal of a trigger left on for an archived agent (an archive that committed past needAgentOn) as the
|
|
395
411
|
* same 409; undefined for any other error. */
|
|
396
412
|
async archivedRefusal(error) {
|
|
@@ -441,20 +457,23 @@ export class Triggers {
|
|
|
441
457
|
/** PATCH: any of name, enabled, source, target, catchup_window_s and max_active_runs. Enabled again, or its source changed, a trigger goes on from now: a
|
|
442
458
|
* paused range is skipped, never caught up. Only the fields named change, applied to the trigger as it stands once
|
|
443
459
|
* the target's check is done: an edit made meanwhile keeps its own. */
|
|
444
|
-
async update(id, body) {
|
|
460
|
+
async update(id, body, own = {}) {
|
|
461
|
+
return isObject(body) && body.target !== undefined ? this.one(id, () => this.updating(id, body, own)) : this.updating(id, body, own);
|
|
462
|
+
}
|
|
463
|
+
async updating(id, body, own) {
|
|
445
464
|
// A source is written only on the row it was checked against (its updatedAt): another write meanwhile (the
|
|
446
465
|
// after-start seal's, a poll's next time) checks it again on the row as it is then, so a source read before a seal
|
|
447
466
|
// never writes the clear value back over it.
|
|
448
467
|
for (let tries = 1;; tries++) {
|
|
449
|
-
const done = await this.updateOnce(id, body, tries < SOURCE_EDIT_TRIES);
|
|
468
|
+
const done = await this.updateOnce(id, body, tries < SOURCE_EDIT_TRIES, own);
|
|
450
469
|
if (done)
|
|
451
470
|
return done;
|
|
452
471
|
}
|
|
453
472
|
}
|
|
454
473
|
/** One try of `update`: undefined when its source write was refused because the trigger changed since it was read and
|
|
455
474
|
* `retry` (try again); refused on the last try, precondition_failed. */
|
|
456
|
-
async updateOnce(id, body, retry) {
|
|
457
|
-
const was = await this.need(id);
|
|
475
|
+
async updateOnce(id, body, retry, own) {
|
|
476
|
+
const was = await this.need(id, own.onAgent);
|
|
458
477
|
const issues = unknownFields(body, WRITABLE);
|
|
459
478
|
let source = body.source === undefined ? undefined : sourceOf(this.adapters, body.source, this.clock.now(), issues);
|
|
460
479
|
const target = body.target === undefined ? undefined : targetOf(body.target, issues);
|
|
@@ -472,7 +491,7 @@ export class Triggers {
|
|
|
472
491
|
issues.push(...(await this.deps.targetIssues(this.given(typeof body.name === "string" ? body.name.trim() : was.name, source ?? was.source, target, this.clock.now()))));
|
|
473
492
|
if (issues.length || (body.source !== undefined && !source) || (body.target !== undefined && !target))
|
|
474
493
|
throw invalid(issues);
|
|
475
|
-
const trigger = await this.need(id);
|
|
494
|
+
const trigger = await this.need(id, own.onAgent);
|
|
476
495
|
if (source && source.kind !== trigger.source.kind)
|
|
477
496
|
throw invalid([{ field: "source.kind", reason: "not_allowed", message: "A trigger's source kind is fixed: make a new trigger for another." }]);
|
|
478
497
|
// What its sender keeps of it stays as it was made (Composio's instance): only what reads it here changes.
|
|
@@ -498,6 +517,9 @@ export class Triggers {
|
|
|
498
517
|
// A trigger belongs to its target's agent: aimed at another agent (or another agent's run), it moves to that agent,
|
|
499
518
|
// whose one name per trigger and list of triggers it joins.
|
|
500
519
|
const agentId = target ? await this.agentOf(target) : trigger.agentId;
|
|
520
|
+
// Moved to an agent being deleted, off too, or turned on for one: never (the store's own refusal is the backstop).
|
|
521
|
+
if (agentId !== trigger.agentId || (enabled && !trigger.enabled))
|
|
522
|
+
await this.needNotDeleting(agentId);
|
|
501
523
|
// Turned on, or aimed elsewhere while on: never for an archived agent (the store's own refusal is the backstop).
|
|
502
524
|
if (enabled && (!trigger.enabled || target))
|
|
503
525
|
await this.needAgentOn(agentId);
|
|
@@ -505,16 +527,20 @@ export class Triggers {
|
|
|
505
527
|
const polls = enabled && adapter.poll !== undefined && (!trigger.enabled || source !== undefined);
|
|
506
528
|
if (polls && !trigger.enabled)
|
|
507
529
|
this.restarts.set(id, (this.restarts.get(id) ?? 0) + 1);
|
|
530
|
+
// Moved to another agent, it is no package's (its mark cleared in the same write): a template update of the agent it
|
|
531
|
+
// left, or of the one it was moved back to, never takes it for one of its own. Kept in place by an apply, it is marked.
|
|
508
532
|
const patch = {
|
|
509
|
-
...(agentId !== trigger.agentId ? { agentId } : {}),
|
|
533
|
+
...(agentId !== trigger.agentId ? { agentId, templateId: null } : own.templateId !== undefined ? { templateId: own.templateId } : {}),
|
|
510
534
|
...(typeof body.name === "string" ? { name: body.name.trim() } : {}), ...(source ? { source } : {}), ...(target ? { target } : {}),
|
|
511
535
|
...(settings.catchup_window_s !== undefined ? { catchupWindowS: settings.catchup_window_s } : {}),
|
|
512
536
|
...(settings.max_active_runs !== undefined ? { maxActiveRuns: settings.max_active_runs } : {}), ...again, enabled, nextAt: next,
|
|
513
537
|
};
|
|
514
|
-
const
|
|
538
|
+
const conditions = { ...(source ? { ifUpdatedAt: trigger.updatedAt, ifSource: trigger.source } : {}), ...(own.onAgent !== undefined ? { ifAgent: own.onAgent } : {}) };
|
|
539
|
+
const row = await this.store.triggers.update(id, patch, enabled ? this.scopesOf(scopeSource) : [], Object.keys(conditions).length ? conditions : undefined).catch(async (error) => {
|
|
515
540
|
throw (await this.scopeTaken(error, scopeSource, trigger.id)) ?? (await this.archivedRefusal(error)) ?? nameTaken(error, patch.name ?? trigger.name);
|
|
516
541
|
});
|
|
517
|
-
|
|
542
|
+
const still = !row && source ? await this.store.triggers.get(id) : undefined;
|
|
543
|
+
if (still && (own.onAgent === undefined || still.agentId === own.onAgent)) {
|
|
518
544
|
if (retry)
|
|
519
545
|
return undefined;
|
|
520
546
|
throw new ApiError("precondition_failed", "the trigger kept changing while this edit was checked: read it again, then send the edit again");
|
|
@@ -535,14 +561,78 @@ export class Triggers {
|
|
|
535
561
|
const said = upstream && enabled !== trigger.enabled ? await upstream.turned(row.source, id, enabled) : undefined;
|
|
536
562
|
return { ...(await this.view(asTrigger(row))), ...said };
|
|
537
563
|
}
|
|
538
|
-
/** The trigger deleted, and what its sender keeps of it removed after (said, when it could not be: the delete holds).
|
|
539
|
-
|
|
564
|
+
/** The trigger deleted, and what its sender keeps of it removed after (said, when it could not be: the delete holds).
|
|
565
|
+
* On its agent's condition (`onAgent`: a template update's removal), what its sender keeps goes first: one its sender
|
|
566
|
+
* did not remove is said, and the trigger is kept here as it was (its row, its package mark, its sealed config and
|
|
567
|
+
* whether it is on), for the next update to remove; once it is gone there, the trigger goes here while it is still that
|
|
568
|
+
* agent's, then what its sender kept here for it. */
|
|
569
|
+
async remove(id, own = {}) {
|
|
570
|
+
return this.one(id, () => this.removing(id, own));
|
|
571
|
+
}
|
|
572
|
+
async removing(id, own) {
|
|
573
|
+
const trigger = await this.need(id, own.onAgent);
|
|
574
|
+
const upstream = this.deps.upstream?.(trigger.source.kind);
|
|
575
|
+
if (own.onAgent === undefined) {
|
|
576
|
+
await this.dropHere(trigger);
|
|
577
|
+
return upstream?.removed(trigger.source, id);
|
|
578
|
+
}
|
|
579
|
+
const here = () => this.dropHere(trigger, own.onAgent);
|
|
580
|
+
if (!upstream)
|
|
581
|
+
return void (await here());
|
|
582
|
+
const said = await upstream.removedThere(trigger.source, id, here);
|
|
583
|
+
if (said !== undefined)
|
|
584
|
+
return said;
|
|
585
|
+
await upstream.forgotten(trigger.source, id);
|
|
586
|
+
return undefined;
|
|
587
|
+
}
|
|
588
|
+
/** `value` as a create keeps a source (its adapter's defaults filled in: a feed's every_s), or undefined when a create
|
|
589
|
+
* would refuse it. */
|
|
590
|
+
sourceAsKept(value) {
|
|
591
|
+
const issues = [];
|
|
592
|
+
const source = sourceOf(this.adapters, value, this.clock.now(), issues);
|
|
593
|
+
return issues.length ? undefined : source;
|
|
594
|
+
}
|
|
595
|
+
/** A deleted agent's trigger (agent-delete.ts), its first half: what its sender keeps of it removed there, the trigger
|
|
596
|
+
* kept here, so a failure, or a stop before the second half (removeHere), leaves the row that names what is left to
|
|
597
|
+
* remove for the next delete to find. Throws `unavailable` with what could not be done there. */
|
|
598
|
+
async removeThere(id) {
|
|
540
599
|
const trigger = await this.need(id);
|
|
541
|
-
await this.
|
|
600
|
+
const said = await this.deps.upstream?.(trigger.source.kind)?.removed(trigger.source, id);
|
|
601
|
+
if (said === undefined)
|
|
602
|
+
return;
|
|
603
|
+
const notes = isObject(said) ? Object.values(said).flatMap((one) => (isObject(one) && typeof one.note === "string" ? [one.note] : [])) : [];
|
|
604
|
+
throw new ApiError("unavailable", `What ${trigger.source.kind} keeps of the trigger ${id} is not removed there yet${notes.length ? ` (${notes.join(" ")})` : ""}.`, { retry_after_ms: 5_000 });
|
|
605
|
+
}
|
|
606
|
+
/** The second half's first part, once removeThere is done: the trigger's adapter settings removed, its row kept. */
|
|
607
|
+
async removeSettings(id) {
|
|
608
|
+
await this.dropSettings(await this.need(id));
|
|
609
|
+
}
|
|
610
|
+
/** The second half, once removeThere is done: the trigger deleted here, its adapter settings and then its row. */
|
|
611
|
+
async removeHere(id) {
|
|
612
|
+
await this.dropHere(await this.need(id));
|
|
613
|
+
}
|
|
614
|
+
/** A trigger's adapter settings (a webhook's secret, a poll's cursor) removed; nothing else of it. */
|
|
615
|
+
async dropSettings(trigger) {
|
|
542
616
|
if (this.adapter(trigger.source)?.settings?.scope === "trigger")
|
|
543
|
-
await this.deps.settings(trigger.source.kind)?.remove(id);
|
|
617
|
+
await this.deps.settings(trigger.source.kind)?.remove(trigger.id);
|
|
618
|
+
}
|
|
619
|
+
/** The trigger's settings and row removed. Without `onAgent`, its settings first, then its row: the settings have no
|
|
620
|
+
* link to the row, so a failure or a stop between the two leaves the row, which the next remove finds, never settings
|
|
621
|
+
* with no trigger left to name them. With `onAgent` (a template update's removal), the row first, on its agent's
|
|
622
|
+
* condition compared in the delete, then its settings: a trigger moved to another agent meanwhile keeps both. A stop
|
|
623
|
+
* between the two there leaves settings no row names (keyed by an id never used again), never a moved trigger
|
|
624
|
+
* without its own. */
|
|
625
|
+
async dropHere(trigger, onAgent) {
|
|
626
|
+
if (onAgent === undefined) {
|
|
627
|
+
await this.dropSettings(trigger);
|
|
628
|
+
await this.store.triggers.remove(trigger.id);
|
|
629
|
+
}
|
|
630
|
+
else {
|
|
631
|
+
if (!(await this.store.triggers.remove(trigger.id, { ifAgent: onAgent })))
|
|
632
|
+
throw new ApiError("not_found", `no trigger ${trigger.id} on the agent ${onAgent}`);
|
|
633
|
+
await this.dropSettings(trigger);
|
|
634
|
+
}
|
|
544
635
|
await this.arm();
|
|
545
|
-
return this.deps.upstream?.(trigger.source.kind)?.removed(trigger.source, id);
|
|
546
636
|
}
|
|
547
637
|
/** Run now: one firing per Idempotency-Key, driven before the answer. `created` false: the key's firing, as it stands. */
|
|
548
638
|
async fire(id, idempotencyKey) {
|
|
@@ -593,6 +683,21 @@ export class Triggers {
|
|
|
593
683
|
}
|
|
594
684
|
await this.arm();
|
|
595
685
|
}
|
|
686
|
+
/** `work` on trigger `id` once every edit or removal of it asked before has settled (edits). Neither update nor remove
|
|
687
|
+
* calls the other, so a turn never waits on itself. Only a target edit takes a turn: any other edit runs beside one, as
|
|
688
|
+
* concurrent edits each keep their change (trigger-engine.test.mjs, two edits at once, one a target whose check is
|
|
689
|
+
* slow: the source edit lands while the target's check waits). One racing a removal writes its row while the row is
|
|
690
|
+
* there, or finds it gone (not_found): the store's update changes no row a delete took. */
|
|
691
|
+
one(id, work) {
|
|
692
|
+
const done = (this.edits.get(id) ?? Promise.resolve()).then(work);
|
|
693
|
+
const turn = done.then(() => undefined, () => undefined);
|
|
694
|
+
this.edits.set(id, turn);
|
|
695
|
+
void turn.then(() => {
|
|
696
|
+
if (this.edits.get(id) === turn)
|
|
697
|
+
this.edits.delete(id);
|
|
698
|
+
});
|
|
699
|
+
return done;
|
|
700
|
+
}
|
|
596
701
|
/** `key`'s firing driven after every firing of its trigger asked before it. */
|
|
597
702
|
inTurn(triggerId, key) {
|
|
598
703
|
const known = this.driving.get(key);
|
|
@@ -1040,7 +1145,8 @@ export class Triggers {
|
|
|
1040
1145
|
const trigger = await this.find(triggerId);
|
|
1041
1146
|
if (!firing || !trigger || firing.status !== "failed" || firing.notified)
|
|
1042
1147
|
return;
|
|
1043
|
-
const
|
|
1148
|
+
const agentName = (await this.store.agents.get(trigger.agentId))?.name || trigger.agentId;
|
|
1149
|
+
const told = await this.deps.notify({ trigger_id: trigger.id, name: trigger.name, agent_id: trigger.agentId, agent_name: agentName, firing_key: key, nominal_at: second(firing.nominalAt), error: firing.error ?? { code: "internal", message: "" }, auto_paused: firing.paused }, key);
|
|
1044
1150
|
// A mark that does not land (the outbox's write failed) is tried again at the next tick, under the same key, which
|
|
1045
1151
|
// the outbox holds once: a restart then finds it marked.
|
|
1046
1152
|
if (told === "queued" || told === "off")
|
|
@@ -1112,10 +1218,10 @@ export class Triggers {
|
|
|
1112
1218
|
async all() {
|
|
1113
1219
|
return (await this.store.triggers.all()).map(asTrigger);
|
|
1114
1220
|
}
|
|
1115
|
-
async need(id) {
|
|
1221
|
+
async need(id, onAgent) {
|
|
1116
1222
|
const row = await this.store.triggers.get(id);
|
|
1117
|
-
if (!row)
|
|
1118
|
-
throw new ApiError("not_found", `no trigger ${id}`);
|
|
1223
|
+
if (!row || (onAgent !== undefined && row.agentId !== onAgent))
|
|
1224
|
+
throw new ApiError("not_found", onAgent !== undefined && row ? `no trigger ${id} on the agent ${onAgent}` : `no trigger ${id}`);
|
|
1119
1225
|
return asTrigger(row);
|
|
1120
1226
|
}
|
|
1121
1227
|
/** The agent a trigger belongs to: its start_run target's, or the run its message_run target names. */
|
package/dist/validate.js
CHANGED
|
@@ -122,7 +122,7 @@ export function definitionIssues(definition, { at = "definition", creating = tru
|
|
|
122
122
|
if (d.workflow !== undefined)
|
|
123
123
|
out.push(issue(`${at}.learning`, "not_allowed", "A workflow revision does not learn: only an agentic run reflects on its work.", `Remove ${at}.learning.`));
|
|
124
124
|
else {
|
|
125
|
-
// true learns
|
|
125
|
+
// true learns (corrections and workflows); an object is on, with the loop's numbers.
|
|
126
126
|
const wrong = learningSettingIssue(d.learning, `${at}.learning`);
|
|
127
127
|
if (wrong)
|
|
128
128
|
out.push(issue(`${at}.learning`, "wrong_type", wrong));
|
package/dist/webhooks.d.ts
CHANGED
|
@@ -33,21 +33,25 @@ export declare function shownUrl(url: string): string;
|
|
|
33
33
|
/** What the webhook takes beside its store: `retryMs`, the waits between tries; `privateTargets`, whether it may send to a
|
|
34
34
|
* private network or this machine (the operator's AGENTRUN_WEBHOOK_PRIVATE_TARGETS, never the API's); `lookup`, every
|
|
35
35
|
* address a name resolves to (the system resolver by default); `storeRetryMs`, the wait before a try the store failed is
|
|
36
|
-
* tried again (STORE_RETRY_MS by default)
|
|
36
|
+
* tried again (STORE_RETRY_MS by default); `timeoutMs`, the bound on one try (TIMEOUT_MS by default), under the claim a
|
|
37
|
+
* try holds its message by (CLAIM_MS), so no try outlives its claim. */
|
|
37
38
|
export type WebhooksOptions = {
|
|
38
39
|
retryMs?: readonly number[];
|
|
39
40
|
privateTargets?: boolean;
|
|
40
41
|
lookup?: (host: string) => Promise<string[]>;
|
|
41
42
|
storeRetryMs?: number;
|
|
43
|
+
timeoutMs?: number;
|
|
42
44
|
};
|
|
43
45
|
/** What `emit` did with a notice: `queued`, in the store (or already there, or counted as sent); `unsaved`, the store
|
|
44
46
|
* refused the write, so the caller tells it again; `off`, no webhook set, or one a 410 turned off, so nothing is to be
|
|
45
47
|
* sent; `closed`, the server is stopping. */
|
|
46
48
|
export type Emitted = "queued" | "unsaved" | "off" | "closed";
|
|
47
|
-
/** What a notice says of its run: never its tools' arguments, its output or its input, which a receiver reads through the API.
|
|
49
|
+
/** What a notice says of its run: never its tools' arguments, its output or its input, which a receiver reads through the API.
|
|
50
|
+
* `agent_name`: its agent's name as the notice is built (server.ts agentNameOf), its id when the agent has no name. */
|
|
48
51
|
export type RunNotice = {
|
|
49
52
|
run_id: string;
|
|
50
53
|
agent_id: string;
|
|
54
|
+
agent_name: string;
|
|
51
55
|
status: string;
|
|
52
56
|
title: string;
|
|
53
57
|
pending?: {
|
|
@@ -123,6 +127,7 @@ export declare class Webhooks {
|
|
|
123
127
|
private readonly privateTargets;
|
|
124
128
|
private readonly lookup;
|
|
125
129
|
private readonly storeRetryMs;
|
|
130
|
+
private readonly timeoutMs;
|
|
126
131
|
/** `key` is the server's seal key; `say` takes a log line's fields. */
|
|
127
132
|
constructor(store: WebhooksStore, key: Buffer, say: (fields: Record<string, string | number>) => void, options?: WebhooksOptions);
|
|
128
133
|
/** Reads the webhook, its secret and its ledger once, and goes on with the messages an earlier server left queued, each
|
package/dist/webhooks.js
CHANGED
|
@@ -36,6 +36,7 @@ export const WEBHOOK_CHANNEL = "webhook-out";
|
|
|
36
36
|
export const WEBHOOK_SETTING = "webhook-out";
|
|
37
37
|
/** The waits before each try again, after the first at once: the Standard Webhooks schedule, cut at about a day. */
|
|
38
38
|
export const RETRY_MS = [5_000, 300_000, 1_800_000, 7_200_000, 18_000_000, 36_000_000];
|
|
39
|
+
/** The bound on one try, its name's lookup included (WebhooksOptions.timeoutMs changes it). */
|
|
39
40
|
const TIMEOUT_MS = 15_000;
|
|
40
41
|
/** How far back an end's run.ended is still queued: past the retries (RETRY_MS, about a day), a notice would not be sent
|
|
41
42
|
* any more. */
|
|
@@ -47,7 +48,8 @@ const MAX_URL = 2048;
|
|
|
47
48
|
const SECRET_FIELD = "secret";
|
|
48
49
|
/** Where its secret is kept in trigger_settings (adapter WEBHOOK_CHANNEL): the server's one scope, one minted field. */
|
|
49
50
|
export const WEBHOOK_SECRET_SPEC = { scope: "server", fields: { [SECRET_FIELD]: { mint: true } } };
|
|
50
|
-
/** How long a try's claim on its message holds (Store.channels.claim): past the try's own TIMEOUT_MS
|
|
51
|
+
/** How long a try's claim on its message holds (Store.channels.claim): past the try's own bound (TIMEOUT_MS, or the
|
|
52
|
+
* option's, which the constructor holds under this). */
|
|
51
53
|
const CLAIM_MS = 60_000;
|
|
52
54
|
/** Names that are this machine or its own network, whatever they resolve to. */
|
|
53
55
|
const LOCAL_NAME = /^(localhost|.*\.localhost|.*\.local|.*\.internal)$/i;
|
|
@@ -148,10 +150,15 @@ export class Webhooks {
|
|
|
148
150
|
privateTargets;
|
|
149
151
|
lookup;
|
|
150
152
|
storeRetryMs;
|
|
153
|
+
timeoutMs;
|
|
151
154
|
/** `key` is the server's seal key; `say` takes a log line's fields. */
|
|
152
155
|
constructor(store, key, say, options = {}) {
|
|
153
156
|
this.store = store;
|
|
154
157
|
this.say = say;
|
|
158
|
+
this.timeoutMs = options.timeoutMs ?? TIMEOUT_MS;
|
|
159
|
+
// Whole milliseconds: AbortSignal.timeout takes no other, and would throw at every send, after its claim.
|
|
160
|
+
if (!(Number.isInteger(this.timeoutMs) && this.timeoutMs > 0 && this.timeoutMs < CLAIM_MS))
|
|
161
|
+
throw new RangeError(`a webhook try's bound is whole milliseconds between 0 and ${CLAIM_MS} (its claim), not ${this.timeoutMs}`);
|
|
155
162
|
this.secrets = sealedSettingsOverStore(store, WEBHOOK_CHANNEL, WEBHOOK_SECRET_SPEC, key, say);
|
|
156
163
|
this.retryMs = options.retryMs ?? RETRY_MS;
|
|
157
164
|
this.storeRetryMs = options.storeRetryMs ?? STORE_RETRY_MS;
|
|
@@ -311,7 +318,7 @@ export class Webhooks {
|
|
|
311
318
|
if (ends && !this.due(marker, config))
|
|
312
319
|
return "queued";
|
|
313
320
|
const id = `msg_${createHash("sha256").update(`${run.run_id}\n${type}\n${marker}`).digest("hex").slice(0, 32)}`;
|
|
314
|
-
const data = { run_id: run.run_id, agent_id: run.agent_id, status: run.status, title: run.title, url: `${this.base}/#/runs/${encodeURIComponent(run.run_id)}`, ...(run.pending ? { pending: run.pending } : {}) };
|
|
321
|
+
const data = { run_id: run.run_id, agent_id: run.agent_id, agent_name: run.agent_name, status: run.status, title: run.title, url: `${this.base}/#/runs/${encodeURIComponent(run.run_id)}`, ...(run.pending ? { pending: run.pending } : {}) };
|
|
315
322
|
// A new wait goes beside the run's earlier waits and replaces its end (one after an end is a continued run's, past that
|
|
316
323
|
// end); an end replaces the run's last end and keeps its waits.
|
|
317
324
|
const told = ends ? { runId: run.run_id, marker: `${ENDED}${marker}`, replacing: ENDED } : { runId: run.run_id, marker: `${WAIT}${marker}`, replacing: ENDED };
|
|
@@ -480,7 +487,7 @@ export class Webhooks {
|
|
|
480
487
|
catch (error) {
|
|
481
488
|
// The try's own bound, cut or the server stopping: the lookup is given up on, never waited out.
|
|
482
489
|
if (signal.aborted)
|
|
483
|
-
return { refused: signal.reason?.name === "TimeoutError" ? `no answer in ${
|
|
490
|
+
return { refused: signal.reason?.name === "TimeoutError" ? `no answer in ${this.timeoutMs / 1000} s` : "not reached: the server is stopping" };
|
|
484
491
|
return { refused: `not reached: ${error.code ?? "its name does not resolve"}` };
|
|
485
492
|
}
|
|
486
493
|
if (!addresses.length || addresses.some(isPrivateAddress))
|
|
@@ -604,7 +611,7 @@ export class Webhooks {
|
|
|
604
611
|
const started = performance.now();
|
|
605
612
|
const target = new URL(config.url);
|
|
606
613
|
// One bound for the whole try, its name's lookup included, and the server's stop cuts it all (close()).
|
|
607
|
-
const signal = AbortSignal.any([AbortSignal.timeout(
|
|
614
|
+
const signal = AbortSignal.any([AbortSignal.timeout(this.timeoutMs), this.stop.signal]);
|
|
608
615
|
const dial = await this.dialled(target, signal);
|
|
609
616
|
if ("refused" in dial)
|
|
610
617
|
failure = dial.refused;
|
|
@@ -622,7 +629,7 @@ export class Webhooks {
|
|
|
622
629
|
failure = res.status >= 300 && res.status < 400 ? `answered ${res.status}: a redirect is not followed` : `answered ${res.status}`;
|
|
623
630
|
}
|
|
624
631
|
catch (error) {
|
|
625
|
-
failure = error.name === "TimeoutError" ? `no answer in ${
|
|
632
|
+
failure = error.name === "TimeoutError" ? `no answer in ${this.timeoutMs / 1000} s` : `not reached: ${error.cause?.code ?? error.message}`;
|
|
626
633
|
}
|
|
627
634
|
finally {
|
|
628
635
|
await dial.dispatcher?.close().catch(() => undefined);
|
|
@@ -51,6 +51,8 @@ export declare function forgetAgentComputer(store: {
|
|
|
51
51
|
type Holding = {
|
|
52
52
|
settings: Pick<Store["settings"], "get" | "putIfAbsent" | "replaceIf" | "removeIf">;
|
|
53
53
|
};
|
|
54
|
+
/** The settings key of the hold on an agent's own computer (gone with the agent's delete: agent-delete.ts). */
|
|
55
|
+
export declare const agentComputerHoldKey: (agentId: string) => string;
|
|
54
56
|
/** How long a hold that is letting go (its run detaching the computer at its end, or this server deleting it) keeps every
|
|
55
57
|
* other run off: the most a provider's detach or delete is waited on. A holder that died while letting go is taken over
|
|
56
58
|
* after it. */
|
|
@@ -55,6 +55,8 @@ export async function forgetAgentComputer(store, agentId, id) {
|
|
|
55
55
|
await store.settings.removeIf(recordKey(agentId), record);
|
|
56
56
|
}
|
|
57
57
|
const holdKey = (agentId) => `agent_computer_hold:${agentId}`;
|
|
58
|
+
/** The settings key of the hold on an agent's own computer (gone with the agent's delete: agent-delete.ts). */
|
|
59
|
+
export const agentComputerHoldKey = holdKey;
|
|
58
60
|
/** How long a hold that is letting go (its run detaching the computer at its end, or this server deleting it) keeps every
|
|
59
61
|
* other run off: the most a provider's detach or delete is waited on. A holder that died while letting go is taken over
|
|
60
62
|
* after it. */
|
|
@@ -3,6 +3,7 @@ import type { KeyEnv } from "../key-meta.js";
|
|
|
3
3
|
import type { SealedKeys } from "../store/store.js";
|
|
4
4
|
import { type ArchilDisk, type ArchilDiskOptions, type ArchilImage } from "./archil-disk.js";
|
|
5
5
|
import type { LaunchDisk } from "../run-launch.js";
|
|
6
|
+
import type { Workspace } from "./workspace.js";
|
|
6
7
|
import { type RunDisk, type RunDiskOptions } from "./run-disk.js";
|
|
7
8
|
export { ARCHIL_API_KEY_ROW, type ArchilSettings };
|
|
8
9
|
/** A claim this step refused, in words a person reads: no Archil call was made. */
|
|
@@ -68,4 +69,10 @@ export interface ArchilClaim {
|
|
|
68
69
|
release(): void;
|
|
69
70
|
}
|
|
70
71
|
/** The Archil step of a claim: its disk made, its API key opened; the run's mount credential minted when a mount asks. */
|
|
72
|
+
/** The run's folder on its disk where its runner opened it (held.ts archil), by the claim that stands for it in a run's own
|
|
73
|
+
* process: openRunWorkspace opens this Workspace for it. */
|
|
74
|
+
export declare const HELD_ARCHIL: WeakMap<object, Workspace>;
|
|
75
|
+
/** archilClaim where the run is: with the runner's seal key, its own; in a run's own process, its runner's (held.ts), as
|
|
76
|
+
* a claim that holds no key, whose revoke, inherit and release its runner makes. */
|
|
77
|
+
export declare function archilWhereHeld(options: ArchilClaimOptions): Promise<ArchilClaim>;
|
|
71
78
|
export declare function archilClaim(options: ArchilClaimOptions): Promise<ArchilClaim>;
|
|
@@ -21,6 +21,7 @@ import { archilApiKey } from "./archil-key.js";
|
|
|
21
21
|
import { archilDisk, pinnedImage } from "./archil-disk.js";
|
|
22
22
|
import { mintMountToken, nicknameOf, removeMountToken, removeOlderMountTokens, removeRunMountTokens } from "./archil-mount-credential.js";
|
|
23
23
|
import { COMPUTER_LIFETIME_MS } from "./computer-deps.js";
|
|
24
|
+
import { heldOrThrow } from "../runner/held.js";
|
|
24
25
|
import { runDiskOf } from "./run-disk.js";
|
|
25
26
|
export { ARCHIL_API_KEY_ROW };
|
|
26
27
|
/** A claim this step refused, in words a person reads: no Archil call was made. */
|
|
@@ -35,6 +36,34 @@ const RELEASED = "the run's Archil keys were released (its loop ended or its cla
|
|
|
35
36
|
/** How long a revoke waits to read the users list again for a mint it never heard of: past Archil's list lag (mint-4). */
|
|
36
37
|
const LOST_MINT_REREAD_MS = 2_000;
|
|
37
38
|
/** The Archil step of a claim: its disk made, its API key opened; the run's mount credential minted when a mount asks. */
|
|
39
|
+
/** The run's folder on its disk where its runner opened it (held.ts archil), by the claim that stands for it in a run's own
|
|
40
|
+
* process: openRunWorkspace opens this Workspace for it. */
|
|
41
|
+
export const HELD_ARCHIL = new WeakMap();
|
|
42
|
+
/** archilClaim where the run is: with the runner's seal key, its own; in a run's own process, its runner's (held.ts), as
|
|
43
|
+
* a claim that holds no key, whose revoke, inherit and release its runner makes. */
|
|
44
|
+
export async function archilWhereHeld(options) {
|
|
45
|
+
if (options.sealKey)
|
|
46
|
+
return archilClaim(options);
|
|
47
|
+
const given = await heldOrThrow("a Mode 2 run's disk").archil();
|
|
48
|
+
if (!given)
|
|
49
|
+
throw new Error("the runner opened no Archil disk for this Mode 2 run");
|
|
50
|
+
const none = (what) => {
|
|
51
|
+
throw new Error(`a Mode 2 run's ${what} is its runner's, not its own process's`);
|
|
52
|
+
};
|
|
53
|
+
const claim = {
|
|
54
|
+
get disk() { return none("disk"); },
|
|
55
|
+
get diskKind() { return none("disk"); },
|
|
56
|
+
get region() { return none("region"); },
|
|
57
|
+
get image() { return none("image"); },
|
|
58
|
+
token: async () => none("mount credential"),
|
|
59
|
+
revoke: () => given.revoke(),
|
|
60
|
+
inherit: () => void given.inherit().catch(() => undefined),
|
|
61
|
+
secrets: new Set(),
|
|
62
|
+
release: () => void given.release().catch(() => undefined),
|
|
63
|
+
};
|
|
64
|
+
HELD_ARCHIL.set(claim, given.workspace);
|
|
65
|
+
return claim;
|
|
66
|
+
}
|
|
38
67
|
export async function archilClaim(options) {
|
|
39
68
|
const { settings, sealKey } = options;
|
|
40
69
|
if (settings === undefined) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type MountSpec } from "@parcha/agentrun-computer";
|
|
2
2
|
import { type ArchilDisk, type ArchilImage } from "./archil-disk.js";
|
|
3
3
|
import { type AttachableComputer, type MountCheck } from "./attach.js";
|
|
4
|
+
import type { FolderStore } from "./synced-folder.js";
|
|
4
5
|
import { type Entry, type ExecOptions, type ExecResult, type GrepOptions, type GrepResult, type Stat, type Workspace } from "./workspace.js";
|
|
5
6
|
/** The most bytes one append call takes. */
|
|
6
7
|
export declare const APPEND_MAX: number;
|
|
@@ -53,7 +54,14 @@ declare class ArchilWorkspace implements Workspace {
|
|
|
53
54
|
/** The Archil mount a computer makes of this folder: the disk, its region, the root as the folder, and the token. */
|
|
54
55
|
mountSpec(): Promise<MountSpec>;
|
|
55
56
|
attach(computer: AttachableComputer, check: MountCheck): Promise<Workspace>;
|
|
57
|
+
/** The folder as a synced folder's runner keeps it (synced-folder.ts): its files and directories through the file
|
|
58
|
+
* API, each write after this workspace's execs; its modes and links, which the file API keeps no record of, in
|
|
59
|
+
* sync.json beside it (syncMetaOf). A failed write answers in words, kind limit where the disk took too much. */
|
|
60
|
+
syncStore(): FolderStore;
|
|
56
61
|
}
|
|
62
|
+
/** Where a synced folder's modes and links are kept: beside its root, never inside it, as its spill folder is. A run's
|
|
63
|
+
* ".../runs/<run>/work" keeps them in ".../runs/<run>/sync.json"; any other root in "<root>.sync.json". */
|
|
64
|
+
export declare const syncMetaOf: (root: string) => string;
|
|
57
65
|
/** A Workspace on folder `root` of Archil disk `disk` (a relative key, e.g. agents/<agent>/runs/<run>/work). */
|
|
58
66
|
export declare const archilWorkspace: (disk: ArchilDisk, root: string, options?: ArchilWorkspaceOptions) => ArchilWorkspace;
|
|
59
67
|
export type { ArchilWorkspace };
|