@parcha/agentrun-serve 0.1.0-beta.52 → 0.1.0-beta.54
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 +149 -1
- package/README.md +295 -37
- package/dist/agent-delete.d.ts +5 -6
- package/dist/agent-delete.js +30 -67
- package/dist/agent-package.d.ts +71 -0
- package/dist/agent-package.js +345 -0
- package/dist/agent-rows.d.ts +1 -1
- package/dist/agents-store.d.ts +26 -20
- package/dist/agents-store.js +42 -34
- package/dist/api-only.d.ts +25 -6
- package/dist/api-only.js +34 -13
- package/dist/claude-login.d.ts +1 -0
- package/dist/claude-login.js +1 -1
- package/dist/cli-learning/cli.d.ts +3 -0
- package/dist/cli-learning/cli.js +17 -3
- package/dist/cli-learning/connections.js +3 -2
- package/dist/cli-learning/schema.js +2 -1
- package/dist/cli.js +76 -8
- package/dist/composio-preset.d.ts +3 -1
- package/dist/composio-preset.js +5 -3
- package/dist/composio-triggers.d.ts +4 -0
- package/dist/composio-triggers.js +4 -1
- package/dist/computer-needs.d.ts +32 -0
- package/dist/computer-needs.js +80 -0
- package/dist/computer-setting.d.ts +5 -2
- package/dist/computer-setting.js +8 -1
- package/dist/computers.d.ts +0 -2
- package/dist/computers.js +1 -1
- package/dist/console/assets/index-B_85An2t.js +745 -0
- package/dist/console/assets/index-n1YsbnYh.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/console-links.d.ts +1 -0
- package/dist/console-links.js +2 -0
- package/dist/env-switch.d.ts +14 -0
- package/dist/env-switch.js +23 -0
- package/dist/errors.d.ts +5 -0
- package/dist/errors.js +10 -0
- package/dist/eval-previous.js +4 -3
- package/dist/fal-price.js +10 -13
- package/dist/github-connection.d.ts +50 -1
- package/dist/github-connection.js +96 -3
- package/dist/github-faux.d.ts +11 -2
- package/dist/github-faux.js +138 -7
- package/dist/github-pull-request.d.ts +37 -0
- package/dist/github-pull-request.js +110 -0
- package/dist/handed-secret.d.ts +4 -0
- package/dist/handed-secret.js +10 -0
- package/dist/harness-archive.d.ts +15 -5
- package/dist/harness-archive.js +71 -34
- package/dist/harness-check.d.ts +2 -1
- package/dist/harness-check.js +36 -95
- package/dist/harness-egress.d.ts +23 -0
- package/dist/harness-egress.js +69 -0
- package/dist/harness-recipe-entry.d.ts +71 -0
- package/dist/harness-recipe-entry.js +184 -0
- package/dist/harness-recipe.d.ts +73 -6
- package/dist/harness-recipe.js +185 -31
- package/dist/harness-sign-in.d.ts +29 -0
- package/dist/harness-sign-in.js +122 -0
- package/dist/harness-table.d.ts +21 -0
- package/dist/harness-table.js +58 -3
- package/dist/harness-zip.d.ts +6 -0
- package/dist/harness-zip.js +203 -0
- package/dist/ids.d.ts +11 -0
- package/dist/ids.js +36 -0
- package/dist/learn/commit.d.ts +14 -1
- package/dist/learn/commit.js +156 -1
- package/dist/learn/compile.js +22 -8
- package/dist/learn/folder.d.ts +5 -0
- package/dist/learn/folder.js +10 -1
- package/dist/learn/learning.sh +15 -3
- package/dist/learn/promote.d.ts +2 -2
- package/dist/learn/secrets.js +30 -7
- package/dist/learning-routes.d.ts +23 -11
- package/dist/learning-routes.js +110 -20
- package/dist/learning.d.ts +9 -6
- package/dist/learning.js +9 -4
- package/dist/live-reach.d.ts +34 -7
- package/dist/live-reach.js +76 -11
- package/dist/mcp-gateway.js +15 -2
- package/dist/mcp-probe.d.ts +3 -0
- package/dist/mcp-probe.js +8 -3
- package/dist/mcp-resources.d.ts +44 -0
- package/dist/mcp-resources.js +100 -0
- package/dist/mcp-servers-store.d.ts +16 -12
- package/dist/model.d.ts +4 -4
- package/dist/model.js +6 -6
- package/dist/native/cli.js +9 -2
- package/dist/native/connection.d.ts +2 -2
- package/dist/native/connection.js +5 -2
- package/dist/native/discovery.d.ts +2 -0
- package/dist/native/discovery.js +10 -6
- package/dist/native/remote-worker-bridge.js +36 -4
- package/dist/native/remote.d.ts +18 -1
- package/dist/native/remote.js +126 -37
- package/dist/native/schema.d.ts +6 -0
- package/dist/native/schema.js +31 -6
- package/dist/native/source-account.d.ts +13 -0
- package/dist/native/source-account.js +114 -0
- package/dist/native/source-capture-hooks.d.ts +5 -0
- package/dist/native/source-capture-hooks.js +102 -0
- package/dist/native/source-mcp-selection.d.ts +13 -0
- package/dist/native/source-mcp-selection.js +72 -0
- package/dist/native/source-runtime-tools.d.ts +19 -0
- package/dist/native/source-runtime-tools.js +103 -0
- package/dist/native/source-snapshot-types.d.ts +138 -0
- package/dist/native/source-snapshot-types.js +12 -0
- package/dist/native/source-snapshot.d.ts +8 -0
- package/dist/native/source-snapshot.js +1201 -0
- package/dist/observation/learning.js +3 -2
- package/dist/openapi.js +275 -40
- package/dist/print.js +1 -1
- package/dist/purged-workflow.d.ts +12 -0
- package/dist/purged-workflow.js +43 -0
- package/dist/run-keys.d.ts +46 -0
- package/dist/run-keys.js +109 -0
- package/dist/run-launch.d.ts +16 -1
- package/dist/run-launch.js +30 -1
- package/dist/run-learning-served.d.ts +2 -2
- package/dist/run-model-key.d.ts +2 -2
- package/dist/run-model-key.js +5 -5
- package/dist/run-secrets.d.ts +2 -0
- package/dist/run-secrets.js +7 -4
- package/dist/run-view.d.ts +17 -0
- package/dist/run-view.js +25 -1
- package/dist/runner/adapter-loop.d.ts +11 -3
- package/dist/runner/adapter-loop.js +138 -22
- package/dist/runner/adapter-run-spec.js +26 -13
- package/dist/runner/audit.d.ts +2 -0
- package/dist/runner/audit.js +9 -1
- package/dist/runner/beside.js +2 -1
- package/dist/runner/claim-secrets.d.ts +29 -3
- package/dist/runner/claim-secrets.js +38 -4
- package/dist/runner/cli-run-spec.js +24 -13
- package/dist/runner/harness-loops.d.ts +6 -0
- package/dist/runner/harness-loops.js +11 -1
- package/dist/runner/held.d.ts +4 -0
- package/dist/runner/journal-kinds.d.ts +2 -0
- package/dist/runner/learned-first.d.ts +2 -0
- package/dist/runner/learned-first.js +1 -1
- package/dist/runner/learning-end.d.ts +7 -2
- package/dist/runner/learning-end.js +22 -10
- package/dist/runner/learning-seed.d.ts +9 -3
- package/dist/runner/learning-seed.js +2 -2
- package/dist/runner/main.d.ts +1 -0
- package/dist/runner/main.js +20 -13
- package/dist/runner/mcp-claim.js +6 -1
- package/dist/runner/mcp-run.d.ts +10 -7
- package/dist/runner/mcp-run.js +3 -5
- package/dist/runner/metrics.d.ts +4 -2
- package/dist/runner/metrics.js +15 -3
- package/dist/runner/monid-run.js +9 -11
- package/dist/runner/pr-checkout.d.ts +21 -4
- package/dist/runner/pr-checkout.js +103 -4
- package/dist/runner/project-checkpoint.d.ts +35 -0
- package/dist/runner/project-checkpoint.js +116 -0
- package/dist/runner/project-drain.d.ts +8 -0
- package/dist/runner/project-drain.js +25 -0
- package/dist/runner/project-host.d.ts +10 -0
- package/dist/runner/project-host.js +52 -0
- package/dist/runner/promotion.d.ts +14 -6
- package/dist/runner/promotion.js +98 -41
- package/dist/runner/redact.d.ts +13 -0
- package/dist/runner/redact.js +67 -1
- package/dist/runner/run-channel.d.ts +9 -0
- package/dist/runner/run-channel.js +15 -2
- package/dist/runner/run-child-host.d.ts +8 -4
- package/dist/runner/run-child-host.js +178 -45
- package/dist/runner/run-errors.js +2 -2
- package/dist/runner/runner-check.d.ts +3 -0
- package/dist/runner/runner-check.js +28 -2
- package/dist/runner/runner.js +26 -9
- package/dist/runner/store-secrets.js +7 -3
- package/dist/runner/workflow-first.d.ts +4 -0
- package/dist/runner/workflow-first.js +13 -0
- package/dist/runner/workflow-loop.d.ts +2 -1
- package/dist/runner/workflow-loop.js +2 -1
- package/dist/runner/workflow-spec.js +1 -1
- package/dist/runs-over-store.d.ts +34 -6
- package/dist/runs-over-store.js +133 -25
- package/dist/sdk/runs.d.ts +11 -1
- package/dist/sdk/runs.js +117 -26
- package/dist/sdk/schema.js +12 -2
- package/dist/sdk/workflows.d.ts +1 -1
- package/dist/server.d.ts +79 -32
- package/dist/server.js +673 -113
- package/dist/skills/agentrun-serve/SKILL.md +2 -1
- package/dist/source-sync/adoption.d.ts +15 -0
- package/dist/source-sync/adoption.js +36 -0
- package/dist/source-sync/auxiliary.d.ts +23 -0
- package/dist/source-sync/auxiliary.js +64 -0
- package/dist/source-sync/capture-git.d.ts +5 -0
- package/dist/source-sync/capture-git.js +272 -0
- package/dist/source-sync/capture-project.d.ts +53 -0
- package/dist/source-sync/capture-project.js +206 -0
- package/dist/source-sync/capture-refusal.d.ts +7 -0
- package/dist/source-sync/capture-refusal.js +16 -0
- package/dist/source-sync/capture.d.ts +11 -0
- package/dist/source-sync/capture.js +22 -0
- package/dist/source-sync/checkpoint-gate.d.ts +21 -0
- package/dist/source-sync/checkpoint-gate.js +52 -0
- package/dist/source-sync/checkpoints.d.ts +66 -0
- package/dist/source-sync/checkpoints.js +168 -0
- package/dist/source-sync/claim.d.ts +11 -0
- package/dist/source-sync/claim.js +48 -0
- package/dist/source-sync/destination.d.ts +47 -0
- package/dist/source-sync/destination.js +239 -0
- package/dist/source-sync/io.d.ts +15 -0
- package/dist/source-sync/io.js +52 -0
- package/dist/source-sync/local.d.ts +43 -0
- package/dist/source-sync/local.js +229 -0
- package/dist/source-sync/prepare.d.ts +59 -0
- package/dist/source-sync/prepare.js +93 -0
- package/dist/source-sync/projects.d.ts +61 -0
- package/dist/source-sync/projects.js +130 -0
- package/dist/source-sync/registry.d.ts +95 -0
- package/dist/source-sync/registry.js +226 -0
- package/dist/source-sync/service.d.ts +33 -0
- package/dist/source-sync/service.js +118 -0
- package/dist/source-sync/skill-edits.d.ts +12 -0
- package/dist/source-sync/skill-edits.js +122 -0
- package/dist/source-sync/snapshots.d.ts +48 -0
- package/dist/source-sync/snapshots.js +448 -0
- package/dist/source-sync/types.d.ts +9 -0
- package/dist/source-sync/types.js +14 -0
- package/dist/source-sync/workspace.d.ts +66 -0
- package/dist/source-sync/workspace.js +273 -0
- package/dist/store/agent-body.d.ts +6 -2
- package/dist/store/agent-body.js +18 -7
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/schema.d.ts +2 -1
- package/dist/store/schema.js +2 -1
- package/dist/store/seal.d.ts +5 -1
- package/dist/store/seal.js +12 -3
- package/dist/store/sqlite/project-checkpoints.d.ts +11 -0
- package/dist/store/sqlite/project-checkpoints.js +70 -0
- package/dist/store/sqlite/run-launch.d.ts +4 -12
- package/dist/store/sqlite/run-launch.js +5 -19
- package/dist/store/sqlite/store.js +224 -170
- package/dist/store/store.d.ts +116 -39
- package/dist/store/store.js +14 -1
- package/dist/store-reads/learning.d.ts +2 -2
- package/dist/store-view.d.ts +3 -1
- package/dist/store-view.js +17 -5
- package/dist/suggestions.d.ts +282 -0
- package/dist/suggestions.js +919 -0
- package/dist/telemetry.d.ts +8 -1
- package/dist/telemetry.js +12 -4
- package/dist/template-import.d.ts +27 -2
- package/dist/template-import.js +148 -13
- package/dist/templates.d.ts +103 -77
- package/dist/templates.js +71 -17
- package/dist/timeline/index.d.ts +1 -1
- package/dist/timeline/index.js +1 -1
- package/dist/timeline/timeline.d.ts +5 -0
- package/dist/timeline/timeline.js +8 -0
- package/dist/tool-plane.d.ts +12 -12
- package/dist/tools.d.ts +8 -8
- package/dist/trigger-launch-hook.d.ts +49 -0
- package/dist/trigger-launch-hook.js +91 -0
- package/dist/trigger-targets.d.ts +14 -1
- package/dist/trigger-targets.js +20 -0
- package/dist/triggers.d.ts +54 -5
- package/dist/triggers.js +143 -8
- package/dist/uploads-archil.js +1 -1
- package/dist/uploads.js +1 -1
- package/dist/validate.d.ts +1 -1
- package/dist/validate.js +3 -4
- package/dist/workspace/computer-for-claim.d.ts +2 -0
- package/dist/workspace/computer-for-claim.js +43 -0
- package/dist/workspace/paths.d.ts +6 -0
- package/dist/workspace/paths.js +6 -0
- package/dist/workspace/resolve-computer.d.ts +1 -0
- package/dist/workspace/run-tools.d.ts +2 -0
- package/dist/workspace/run-tools.js +8 -0
- package/dist/workspace/synced-folder.d.ts +1 -1
- package/dist/workspace/synced-folder.js +11 -14
- package/launcher/agentrun-serve +1 -1
- package/package.json +10 -10
- package/skills/agentrun-serve/SKILL.md +2 -1
- package/templates/README.md +8 -4
- package/templates/agent-scout/agent.md +46 -0
- package/templates/agent-scout/skills/scout/SKILL.md +88 -0
- package/templates/agent-scout/skills/scout/suggestions.schema.json +112 -0
- package/dist/console/assets/index-B-D0EM3j.js +0 -733
- package/dist/console/assets/index-DlQepP2J.css +0 -1
package/dist/triggers.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { type MessageOrigin } from "./timeline/index.js";
|
|
|
2
2
|
import { ApiError, type InputIssue } from "./errors.js";
|
|
3
3
|
import { type FiringRow, type Store } from "./store/index.js";
|
|
4
4
|
import { type Source, type TriggerAdapter } from "./trigger-adapter.js";
|
|
5
|
+
import { type LaunchHook } from "./trigger-launch-hook.js";
|
|
5
6
|
import { type Json } from "./validate.js";
|
|
6
7
|
export { MAX_EVERY_S, MIN_EVERY_S } from "./trigger-schedule.js";
|
|
7
8
|
/** The firings each trigger keeps in its history, newest first; a firing still due is never dropped, nor a failure whose
|
|
@@ -14,6 +15,8 @@ export declare const DUE_KEPT = 20;
|
|
|
14
15
|
export declare const SOURCE_KINDS: readonly string[];
|
|
15
16
|
export declare const TARGET_KINDS: readonly ["start_run", "message_run"];
|
|
16
17
|
export declare const FIRING_STATUSES: readonly ["due", "started", "sent", "skipped", "failed", "missed"];
|
|
18
|
+
/** A firing the launch hook's host took (a 2xx) without starting its run here under the firing (RunCreate trigger_firing). */
|
|
19
|
+
export declare const HANDED_NO_RUN = "Handed to the host by the launch hook, which started no run here for it.";
|
|
17
20
|
/** The most of a webhook's payload a firing passes on: the rest is cut, at a character's start (trigger-adapter.ts). */
|
|
18
21
|
/** How late a missed time may be and still fire once, by default: an hour. */
|
|
19
22
|
export declare const CATCHUP_WINDOW_S = 3600;
|
|
@@ -119,6 +122,9 @@ export type TriggerDeps = {
|
|
|
119
122
|
credentials?(kind: string): Promise<unknown>;
|
|
120
123
|
/** What keeps a target from starting runs here, by field (its agent, its kind, its input). */
|
|
121
124
|
targetIssues(target: Target): Promise<InputIssue[]>;
|
|
125
|
+
/** The refusal of a trigger aimed at `target` whose firings could never start or message a run that has what it needs
|
|
126
|
+
* (run-keys.ts firingsOwe), once its fields read; undefined, or no such dep, when there is none. */
|
|
127
|
+
targetRefusal?(target: Target): Promise<ApiError | undefined>;
|
|
122
128
|
/** Starts the target's run with `input`, as POST /agents/{id}/runs would, under `origin`, titled `title` (its
|
|
123
129
|
* trigger's, never its input's); its first message is the trigger's (`from`, never the person's); ApiError when
|
|
124
130
|
* refused. */
|
|
@@ -168,6 +174,9 @@ export type TriggerDeps = {
|
|
|
168
174
|
publicUrl?: string;
|
|
169
175
|
/** What source `kind`'s sender keeps of its triggers, when it is set up from here (TriggerUpstream); none for the rest. */
|
|
170
176
|
upstream?(kind: string): TriggerUpstream | undefined;
|
|
177
|
+
/** The launch hook (AGENTRUN_LAUNCH_HOOK_URL): set, a firing that would start a run here is handed to the host
|
|
178
|
+
* instead (trigger-launch-hook.ts); a message_run firing starts no run and is sent here as ever. */
|
|
179
|
+
launchHook?: LaunchHook;
|
|
171
180
|
};
|
|
172
181
|
export declare const firingKey: (by: string, triggerId: string, what: string) => string;
|
|
173
182
|
/** What is wrong with a POST /triggers body by itself, as create refuses it with the sources of `adapters`, all but the
|
|
@@ -208,10 +217,13 @@ export declare class Triggers {
|
|
|
208
217
|
/** Each polled trigger's count of turn-ons: a poll that sees it changed keeps nothing, its cursor read before. */
|
|
209
218
|
private readonly restarts;
|
|
210
219
|
private closed;
|
|
220
|
+
/** Aborted by close: a firing being handed to the host is cut short and left due. */
|
|
221
|
+
private readonly stopping;
|
|
211
222
|
constructor(deps: TriggerDeps);
|
|
212
223
|
/** At the server's start: every enabled trigger whose source no longer reads turned off, each failure's trigger.failed
|
|
213
|
-
* queued that is not yet,
|
|
214
|
-
*
|
|
224
|
+
* queued that is not yet, each sent firing whose host's run is in the store started with it (relink), every firing an
|
|
225
|
+
* earlier server left due driven again (its origin key makes a run it already started the same run), the times missed
|
|
226
|
+
* while it was down recorded, and the timer armed. */
|
|
215
227
|
start(): Promise<void>;
|
|
216
228
|
close(): void;
|
|
217
229
|
list(): Promise<{
|
|
@@ -230,6 +242,7 @@ export declare class Triggers {
|
|
|
230
242
|
created_at: string;
|
|
231
243
|
updated_at: string;
|
|
232
244
|
last_firing: {
|
|
245
|
+
start_by?: string | undefined;
|
|
233
246
|
attempts?: number | undefined;
|
|
234
247
|
retry_at?: string | undefined;
|
|
235
248
|
catch_up?: boolean | undefined;
|
|
@@ -269,6 +282,7 @@ export declare class Triggers {
|
|
|
269
282
|
created_at: string;
|
|
270
283
|
updated_at: string;
|
|
271
284
|
last_firing: {
|
|
285
|
+
start_by?: string | undefined;
|
|
272
286
|
attempts?: number | undefined;
|
|
273
287
|
retry_at?: string | undefined;
|
|
274
288
|
catch_up?: boolean | undefined;
|
|
@@ -294,6 +308,7 @@ export declare class Triggers {
|
|
|
294
308
|
}>;
|
|
295
309
|
firings(id: string): Promise<{
|
|
296
310
|
firings: {
|
|
311
|
+
start_by?: string | undefined;
|
|
297
312
|
attempts?: number | undefined;
|
|
298
313
|
retry_at?: string | undefined;
|
|
299
314
|
catch_up?: boolean | undefined;
|
|
@@ -327,6 +342,7 @@ export declare class Triggers {
|
|
|
327
342
|
created_at: string;
|
|
328
343
|
updated_at: string;
|
|
329
344
|
last_firing: {
|
|
345
|
+
start_by?: string | undefined;
|
|
330
346
|
attempts?: number | undefined;
|
|
331
347
|
retry_at?: string | undefined;
|
|
332
348
|
catch_up?: boolean | undefined;
|
|
@@ -386,9 +402,13 @@ export declare class Triggers {
|
|
|
386
402
|
id: string;
|
|
387
403
|
name: string;
|
|
388
404
|
}[]>;
|
|
389
|
-
/** Agent `agentId` unarchived: none of its triggers turns on again
|
|
390
|
-
*
|
|
391
|
-
|
|
405
|
+
/** Agent `agentId` unarchived: none of its triggers turns on again, but those its archive turned off whose source
|
|
406
|
+
* `turnOn` takes, each turned on as a PATCH with enabled true does (an API-only server's with the launch hook, which
|
|
407
|
+
* serves no trigger route: api-only.ts). The triggers its archive turned off that are off still, by name: each is
|
|
408
|
+
* turned on by a PATCH. One `turnOn` takes that can't be on (a schedule with no time left), or that its first check
|
|
409
|
+
* turns off again, is named: what is off is read from the store after the turn-ons, never taken from whether one
|
|
410
|
+
* resolved. */
|
|
411
|
+
agentUnarchived(agentId: string, turnOn?: (source: Source) => boolean): Promise<{
|
|
392
412
|
id: string;
|
|
393
413
|
name: string;
|
|
394
414
|
}[]>;
|
|
@@ -437,6 +457,7 @@ export declare class Triggers {
|
|
|
437
457
|
created_at: string;
|
|
438
458
|
updated_at: string;
|
|
439
459
|
last_firing: {
|
|
460
|
+
start_by?: string | undefined;
|
|
440
461
|
attempts?: number | undefined;
|
|
441
462
|
retry_at?: string | undefined;
|
|
442
463
|
catch_up?: boolean | undefined;
|
|
@@ -561,6 +582,33 @@ export declare class Triggers {
|
|
|
561
582
|
/** A target refused the firing: a busy server's answer is a failed try under the table; any other (a refusal, a thrown
|
|
562
583
|
* error) fails the firing at once. Both count toward the streak. */
|
|
563
584
|
private answered;
|
|
585
|
+
/** A start_run firing handed to the host by the launch hook, never started here. The run the host started for it
|
|
586
|
+
* (handedStart: under the firing's key) makes it started, as a run started here would, whatever the hook answered;
|
|
587
|
+
* else a 2xx makes it sent, with no run (its attrs kept for a run the host starts late: handedRan) and its startBy
|
|
588
|
+
* LAUNCH_HOOK_LATE_START_MS after that answer, and any other answer or none skipped with why. The server's stop leaves
|
|
589
|
+
* it due, so the next start hands it again under the same webhook-id (or finds the run the host started). */
|
|
590
|
+
private handed;
|
|
591
|
+
/** The run the host starts through the API for a firing the launch hook handed it (RunCreate `trigger_firing`): the
|
|
592
|
+
* firing's key (the run's origin key, so the firing finds it), and the trigger, input origin and title its own start
|
|
593
|
+
* would give the run; or the run already started under that key. Refused, in words, unless this server has the hook and
|
|
594
|
+
* the firing, of a start_run trigger on `agentId`, is due (being handed over) or one its host took with no run, up to
|
|
595
|
+
* its startBy (the host may answer first and start the run after). */
|
|
596
|
+
handedStart(given: unknown, agentId: string): Promise<{
|
|
597
|
+
run_id: string;
|
|
598
|
+
} | {
|
|
599
|
+
key: string;
|
|
600
|
+
trigger: RunTrigger;
|
|
601
|
+
from: MessageOrigin;
|
|
602
|
+
title: string;
|
|
603
|
+
}>;
|
|
604
|
+
/** Run `runId`, which the host started for firing `key` (handedStart), started: one whose host answered first (sent,
|
|
605
|
+
* with no run) is made started here, as handed() makes it when the run came first, so the overlap check and
|
|
606
|
+
* max_active_runs count it. A firing still being handed is left to handed(), which reads its run after the answer. */
|
|
607
|
+
handedRan(triggerId: string, key: string, runId: string): Promise<void>;
|
|
608
|
+
/** Each sent firing whose host's run is in the store under its key, though the server stopped before the firing was
|
|
609
|
+
* started with it (a late start writes the run, then handedRan): started with that run, so the overlap check and
|
|
610
|
+
* max_active_runs count it. */
|
|
611
|
+
private relink;
|
|
564
612
|
private started;
|
|
565
613
|
/** A failed firing: one more in its trigger's streak, the trigger turned off at FAILURES_TO_PAUSE, and trigger.failed
|
|
566
614
|
* queued (after the firing is written: a start finds one not yet queued and queues it, under the same webhook-id). */
|
|
@@ -632,6 +680,7 @@ export interface TriggerOwn {
|
|
|
632
680
|
readonly onAgent?: string;
|
|
633
681
|
}
|
|
634
682
|
declare function firingView(firing: FiringRow): {
|
|
683
|
+
start_by?: string | undefined;
|
|
635
684
|
attempts?: number | undefined;
|
|
636
685
|
retry_at?: string | undefined;
|
|
637
686
|
catch_up?: boolean | undefined;
|
package/dist/triggers.js
CHANGED
|
@@ -21,14 +21,18 @@
|
|
|
21
21
|
// late timer does not drift. Of the times that came while the server was down, or its timer late past LATE_MS, the
|
|
22
22
|
// latest fires if it is within the trigger's catch-up window and the rest are one `missed` row; the schedule goes on from
|
|
23
23
|
// now. A failed firing queues a trigger.failed webhook message.
|
|
24
|
+
// With the launch hook set (trigger-launch-hook.ts), a firing that would start a run goes the same way up to the start,
|
|
25
|
+
// then is handed to the host instead: sent when the host takes it, skipped with why when it does not.
|
|
24
26
|
import { createHash, randomBytes } from "node:crypto";
|
|
25
27
|
import { TRIGGER_LABELS } from "./timeline/index.js";
|
|
26
28
|
import { agentDeleting, purgedAgent } from "./agents.js";
|
|
29
|
+
import { ownedElsewhere } from "./agents-store.js";
|
|
27
30
|
import { ApiError, invalid } from "./errors.js";
|
|
28
31
|
import { EFFORTS } from "./model.js";
|
|
29
32
|
import { AgentArchived, StoreConstraint, TriggerFull } from "./store/index.js";
|
|
30
33
|
import { carriesPrevious, PAYLOAD_KEPT_BYTES, second, validZone } from "./trigger-adapter.js";
|
|
31
34
|
import { TRIGGER_ADAPTERS } from "./trigger-adapters.js";
|
|
35
|
+
import { handToHost, LAUNCH_HOOK_LATE_START_MS } from "./trigger-launch-hook.js";
|
|
32
36
|
import { MAX_EVERY_S } from "./trigger-schedule.js";
|
|
33
37
|
import { ID, IDEMPOTENCY_TTL_S, isObject, unknownFields } from "./validate.js";
|
|
34
38
|
export { MAX_EVERY_S, MIN_EVERY_S } from "./trigger-schedule.js";
|
|
@@ -44,6 +48,8 @@ const FULL_RETRY_S = 30;
|
|
|
44
48
|
export const SOURCE_KINDS = TRIGGER_ADAPTERS.map((a) => a.id);
|
|
45
49
|
export const TARGET_KINDS = ["start_run", "message_run"];
|
|
46
50
|
export const FIRING_STATUSES = ["due", "started", "sent", "skipped", "failed", "missed"];
|
|
51
|
+
/** A firing the launch hook's host took (a 2xx) without starting its run here under the firing (RunCreate trigger_firing). */
|
|
52
|
+
export const HANDED_NO_RUN = "Handed to the host by the launch hook, which started no run here for it.";
|
|
47
53
|
/** The most of a webhook's payload a firing passes on: the rest is cut, at a character's start (trigger-adapter.ts). */
|
|
48
54
|
/** How late a missed time may be and still fire once, by default: an hour. */
|
|
49
55
|
export const CATCHUP_WINDOW_S = 3600;
|
|
@@ -239,6 +245,8 @@ export class Triggers {
|
|
|
239
245
|
/** Each polled trigger's count of turn-ons: a poll that sees it changed keeps nothing, its cursor read before. */
|
|
240
246
|
restarts = new Map();
|
|
241
247
|
closed = false;
|
|
248
|
+
/** Aborted by close: a firing being handed to the host is cut short and left due. */
|
|
249
|
+
stopping = new AbortController();
|
|
242
250
|
constructor(deps) {
|
|
243
251
|
this.deps = deps;
|
|
244
252
|
this.store = deps.store;
|
|
@@ -254,15 +262,18 @@ export class Triggers {
|
|
|
254
262
|
throw new Error(`two trigger sources claim the id ${twice.id}${twice.push ? `, and its hook /v2/hooks/${twice.id}` : ""}: one source each`);
|
|
255
263
|
}
|
|
256
264
|
/** At the server's start: every enabled trigger whose source no longer reads turned off, each failure's trigger.failed
|
|
257
|
-
* queued that is not yet,
|
|
258
|
-
*
|
|
265
|
+
* queued that is not yet, each sent firing whose host's run is in the store started with it (relink), every firing an
|
|
266
|
+
* earlier server left due driven again (its origin key makes a run it already started the same run), the times missed
|
|
267
|
+
* while it was down recorded, and the timer armed. */
|
|
259
268
|
async start() {
|
|
260
269
|
const now = this.clock.now();
|
|
261
270
|
await this.offUnreadable((await this.all()).filter((t) => t.enabled && this.problem(t.source)), now);
|
|
271
|
+
await this.relink();
|
|
262
272
|
await this.tick();
|
|
263
273
|
}
|
|
264
274
|
close() {
|
|
265
275
|
this.closed = true;
|
|
276
|
+
this.stopping.abort();
|
|
266
277
|
this.timer?.clear();
|
|
267
278
|
this.timer = undefined;
|
|
268
279
|
}
|
|
@@ -284,6 +295,9 @@ export class Triggers {
|
|
|
284
295
|
issues.push(...(await this.deps.targetIssues(this.given(typeof body.name === "string" ? body.name.trim() : `trg_${"0".repeat(24)}`, source, target, now))));
|
|
285
296
|
if (issues.length || !source || !target)
|
|
286
297
|
throw invalid(issues);
|
|
298
|
+
const refused = await this.deps.targetRefusal?.(target);
|
|
299
|
+
if (refused)
|
|
300
|
+
throw refused;
|
|
287
301
|
const agentId = await this.agentOf(target);
|
|
288
302
|
const id = `trg_${randomBytes(12).toString("hex")}`;
|
|
289
303
|
const enabled = body.enabled !== false;
|
|
@@ -388,11 +402,20 @@ export class Triggers {
|
|
|
388
402
|
await this.offThere((await Promise.all(off.map((t) => this.find(t.id)))).filter((t) => t !== undefined));
|
|
389
403
|
return off;
|
|
390
404
|
}
|
|
391
|
-
/** Agent `agentId` unarchived: none of its triggers turns on again
|
|
392
|
-
*
|
|
393
|
-
|
|
405
|
+
/** Agent `agentId` unarchived: none of its triggers turns on again, but those its archive turned off whose source
|
|
406
|
+
* `turnOn` takes, each turned on as a PATCH with enabled true does (an API-only server's with the launch hook, which
|
|
407
|
+
* serves no trigger route: api-only.ts). The triggers its archive turned off that are off still, by name: each is
|
|
408
|
+
* turned on by a PATCH. One `turnOn` takes that can't be on (a schedule with no time left), or that its first check
|
|
409
|
+
* turns off again, is named: what is off is read from the store after the turn-ons, never taken from whether one
|
|
410
|
+
* resolved. */
|
|
411
|
+
async agentUnarchived(agentId, turnOn = () => false) {
|
|
394
412
|
await this.store.agents.archive(agentId, false);
|
|
395
|
-
|
|
413
|
+
const off = (await this.store.triggers.list(agentId)).map(asTrigger).filter((t) => !t.enabled && reasonOf(t.disabled) === "agent_archived");
|
|
414
|
+
for (const t of off)
|
|
415
|
+
if (turnOn(t.source))
|
|
416
|
+
await this.update(t.id, { enabled: true }, { onAgent: agentId }).catch(() => undefined);
|
|
417
|
+
const ids = new Set(off.map((t) => t.id));
|
|
418
|
+
return (await this.store.triggers.list(agentId)).filter((t) => ids.has(t.id) && !t.enabled).map((t) => ({ id: t.id, name: t.name }));
|
|
396
419
|
}
|
|
397
420
|
/** Refused (409 agent_archived) when agent `agentId` is archived: a trigger made on, turned on or aimed at it. */
|
|
398
421
|
async needAgentOn(agentId) {
|
|
@@ -407,7 +430,7 @@ export class Triggers {
|
|
|
407
430
|
const agent = await this.store.agents.get(agentId);
|
|
408
431
|
if (agent?.purgedAt != null)
|
|
409
432
|
throw purgedAgent(agent);
|
|
410
|
-
if (agent?.archivedAt != null && agent
|
|
433
|
+
if (agent?.archivedAt != null && ownedElsewhere(agent))
|
|
411
434
|
throw agentDeleting(agentId);
|
|
412
435
|
}
|
|
413
436
|
/** The store's refusal of a trigger left on for an archived agent (an archive that committed past needAgentOn) as the
|
|
@@ -494,6 +517,9 @@ export class Triggers {
|
|
|
494
517
|
issues.push(...(await this.deps.targetIssues(this.given(typeof body.name === "string" ? body.name.trim() : was.name, source ?? was.source, target, this.clock.now()))));
|
|
495
518
|
if (issues.length || (body.source !== undefined && !source) || (body.target !== undefined && !target))
|
|
496
519
|
throw invalid(issues);
|
|
520
|
+
const refused = target ? await this.deps.targetRefusal?.(target) : undefined;
|
|
521
|
+
if (refused)
|
|
522
|
+
throw refused;
|
|
497
523
|
const trigger = await this.need(id, own.onAgent);
|
|
498
524
|
if (source && source.kind !== trigger.source.kind)
|
|
499
525
|
throw invalid([{ field: "source.kind", reason: "not_allowed", message: "A trigger's source kind is fixed: make a new trigger for another." }]);
|
|
@@ -977,6 +1003,8 @@ export class Triggers {
|
|
|
977
1003
|
return;
|
|
978
1004
|
if (now.target.kind === "message_run")
|
|
979
1005
|
return void (await this.send(now, firing));
|
|
1006
|
+
if (this.deps.launchHook)
|
|
1007
|
+
return void (await this.handed(now, firing, this.deps.launchHook));
|
|
980
1008
|
let started;
|
|
981
1009
|
try {
|
|
982
1010
|
const attrs = firing.attrs;
|
|
@@ -1104,6 +1132,112 @@ export class Triggers {
|
|
|
1104
1132
|
return this.failedTry(triggerId, key, error);
|
|
1105
1133
|
await this.failed(triggerId, key, errorOf(error), runId);
|
|
1106
1134
|
}
|
|
1135
|
+
/** A start_run firing handed to the host by the launch hook, never started here. The run the host started for it
|
|
1136
|
+
* (handedStart: under the firing's key) makes it started, as a run started here would, whatever the hook answered;
|
|
1137
|
+
* else a 2xx makes it sent, with no run (its attrs kept for a run the host starts late: handedRan) and its startBy
|
|
1138
|
+
* LAUNCH_HOOK_LATE_START_MS after that answer, and any other answer or none skipped with why. The server's stop leaves
|
|
1139
|
+
* it due, so the next start hands it again under the same webhook-id (or finds the run the host started). */
|
|
1140
|
+
async handed(trigger, firing, hook) {
|
|
1141
|
+
if (trigger.target.kind !== "start_run")
|
|
1142
|
+
return;
|
|
1143
|
+
const agentId = trigger.target.agent_id;
|
|
1144
|
+
const sent = {
|
|
1145
|
+
firing_id: firing.key, trigger_id: trigger.id, agent_id: agentId, revision_id: (await this.store.agents.get(agentId))?.currentRevision ?? null,
|
|
1146
|
+
input: this.inputOf(trigger, firing), fired_at: second(firing.nominalAt),
|
|
1147
|
+
};
|
|
1148
|
+
const handed = await handToHost(hook, sent, this.stopping.signal, () => this.clock.now());
|
|
1149
|
+
if (this.closed || "stopped" in handed)
|
|
1150
|
+
return;
|
|
1151
|
+
const linked = await this.deps.runOf(firing.key);
|
|
1152
|
+
if (this.closed)
|
|
1153
|
+
return;
|
|
1154
|
+
if (linked)
|
|
1155
|
+
return void (await this.started(trigger.id, firing.key, linked.run_id));
|
|
1156
|
+
if ("skipped" in handed) {
|
|
1157
|
+
await this.store.triggers.settle(trigger.id, firing.key, { status: "skipped", reason: handed.skipped });
|
|
1158
|
+
this.deps.say({ condition: "trigger_hook_skipped", trigger: trigger.id, firing: firing.key });
|
|
1159
|
+
return;
|
|
1160
|
+
}
|
|
1161
|
+
await this.store.triggers.settle(trigger.id, firing.key, { status: "sent", reason: HANDED_NO_RUN, keepAttrs: true, startBy: this.clock.now() + LAUNCH_HOOK_LATE_START_MS }, { reset: true });
|
|
1162
|
+
// The host may start the run right after its answer: one it started between the read above and this write found the
|
|
1163
|
+
// firing still due (handedRan left it), so it is read again here.
|
|
1164
|
+
const after = await this.deps.runOf(firing.key);
|
|
1165
|
+
if (this.closed)
|
|
1166
|
+
return;
|
|
1167
|
+
if (after)
|
|
1168
|
+
return void (await this.started(trigger.id, firing.key, after.run_id));
|
|
1169
|
+
this.deps.say({ condition: "trigger_handed", trigger: trigger.id, firing: firing.key });
|
|
1170
|
+
}
|
|
1171
|
+
/** The run the host starts through the API for a firing the launch hook handed it (RunCreate `trigger_firing`): the
|
|
1172
|
+
* firing's key (the run's origin key, so the firing finds it), and the trigger, input origin and title its own start
|
|
1173
|
+
* would give the run; or the run already started under that key. Refused, in words, unless this server has the hook and
|
|
1174
|
+
* the firing, of a start_run trigger on `agentId`, is due (being handed over) or one its host took with no run, up to
|
|
1175
|
+
* its startBy (the host may answer first and start the run after). */
|
|
1176
|
+
async handedStart(given, agentId) {
|
|
1177
|
+
const refused = (reason, message, field = "trigger_firing") => invalid([{ field, reason, message }]);
|
|
1178
|
+
if (!this.deps.launchHook)
|
|
1179
|
+
throw refused("not_allowed", "This server has no launch hook: a run starts as a trigger firing's only when the hook handed that firing to its host.");
|
|
1180
|
+
if (!isObject(given))
|
|
1181
|
+
throw refused("wrong_type", "trigger_firing is { trigger_id, firing_id }, as the launch hook sent them.");
|
|
1182
|
+
const extra = unknownFields(given, ["trigger_id", "firing_id"]);
|
|
1183
|
+
if (extra.length)
|
|
1184
|
+
throw invalid(extra.map((issue) => ({ ...issue, field: `trigger_firing.${issue.field}` })));
|
|
1185
|
+
const { trigger_id: triggerId, firing_id: key } = given;
|
|
1186
|
+
if (typeof triggerId !== "string" || !ID.test(triggerId))
|
|
1187
|
+
throw refused("wrong_type", "trigger_id is the trigger's id, as the launch hook sent it.", "trigger_firing.trigger_id");
|
|
1188
|
+
if (typeof key !== "string" || !/^fir_[0-9a-f]{32}$/.test(key))
|
|
1189
|
+
throw refused("wrong_type", "firing_id is the firing's id, as the launch hook sent it.", "trigger_firing.firing_id");
|
|
1190
|
+
const trigger = await this.find(triggerId);
|
|
1191
|
+
if (!trigger || trigger.target.kind !== "start_run" || trigger.target.agent_id !== agentId)
|
|
1192
|
+
throw refused("not_found", `This agent has no trigger ${triggerId} that starts its runs.`, "trigger_firing.trigger_id");
|
|
1193
|
+
const firing = await this.store.triggers.firing(triggerId, key);
|
|
1194
|
+
if (!firing)
|
|
1195
|
+
throw refused("not_found", `Trigger ${triggerId} has no firing ${key}.`, "trigger_firing.firing_id");
|
|
1196
|
+
// The run already under its key is its run. A stop between that run's write and handedRan left the firing sent with
|
|
1197
|
+
// no run, so a repeated start starts the firing with it.
|
|
1198
|
+
const prior = await this.deps.runOf(key);
|
|
1199
|
+
if (prior) {
|
|
1200
|
+
await this.handedRan(triggerId, key, prior.run_id);
|
|
1201
|
+
return prior;
|
|
1202
|
+
}
|
|
1203
|
+
const minutes = LAUNCH_HOOK_LATE_START_MS / 60_000;
|
|
1204
|
+
const taken = firing.status === "sent" && firing.runId === null && firing.reason === HANDED_NO_RUN;
|
|
1205
|
+
if (taken && (firing.startBy === null || this.clock.now() > firing.startBy)) {
|
|
1206
|
+
const until = firing.startBy === null ? "" : ` (start_by ${iso(firing.startBy)})`;
|
|
1207
|
+
throw refused("not_due", `Firing ${key}'s host answered without starting its run, and the ${minutes} minutes after its host answered in which it may still start it have passed${until}.`, "trigger_firing.firing_id");
|
|
1208
|
+
}
|
|
1209
|
+
if (firing.status !== "due" && !taken) {
|
|
1210
|
+
throw refused("not_due", `Firing ${key} is ${firing.status}${firing.reason ? ` (${firing.reason})` : ""}: a run starts only for a firing the launch hook is handing over, or one its host took within ${minutes} minutes of its answer.`, "trigger_firing.firing_id");
|
|
1211
|
+
}
|
|
1212
|
+
const attrs = firing.attrs;
|
|
1213
|
+
return { key, trigger: { id: triggerId, firing_key: key, name: trigger.name, ...(attrs && Object.keys(attrs).length ? { attrs } : {}) }, from: this.originOf(trigger), title: this.titleOf(trigger, firing) };
|
|
1214
|
+
}
|
|
1215
|
+
/** Run `runId`, which the host started for firing `key` (handedStart), started: one whose host answered first (sent,
|
|
1216
|
+
* with no run) is made started here, as handed() makes it when the run came first, so the overlap check and
|
|
1217
|
+
* max_active_runs count it. A firing still being handed is left to handed(), which reads its run after the answer. */
|
|
1218
|
+
async handedRan(triggerId, key, runId) {
|
|
1219
|
+
const firing = await this.store.triggers.firing(triggerId, key);
|
|
1220
|
+
if (firing?.status === "sent" && firing.runId === null && firing.reason === HANDED_NO_RUN)
|
|
1221
|
+
await this.started(triggerId, key, runId);
|
|
1222
|
+
}
|
|
1223
|
+
/** Each sent firing whose host's run is in the store under its key, though the server stopped before the firing was
|
|
1224
|
+
* started with it (a late start writes the run, then handedRan): started with that run, so the overlap check and
|
|
1225
|
+
* max_active_runs count it. */
|
|
1226
|
+
async relink() {
|
|
1227
|
+
for (const trigger of await this.all()) {
|
|
1228
|
+
if (trigger.target.kind !== "start_run")
|
|
1229
|
+
continue;
|
|
1230
|
+
for (const firing of await this.store.triggers.firings(trigger.id)) {
|
|
1231
|
+
if (firing.status !== "sent" || firing.runId !== null)
|
|
1232
|
+
continue;
|
|
1233
|
+
const run = await this.deps.runOf(firing.key);
|
|
1234
|
+
if (this.closed)
|
|
1235
|
+
return;
|
|
1236
|
+
if (run)
|
|
1237
|
+
await this.handedRan(trigger.id, firing.key, run.run_id);
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1107
1241
|
async started(triggerId, key, runId) {
|
|
1108
1242
|
await this.store.triggers.settle(triggerId, key, { status: "started", runId }, { reset: true });
|
|
1109
1243
|
this.deps.say({ condition: "trigger_fired", trigger: triggerId, firing: key, run: runId });
|
|
@@ -1183,7 +1317,7 @@ export class Triggers {
|
|
|
1183
1317
|
* most SEEN_KEPT of them; past it the oldest go, said once each time the cap is reached. */
|
|
1184
1318
|
async prune(trigger) {
|
|
1185
1319
|
const cap = this.deps.seenKept ?? SEEN_KEPT;
|
|
1186
|
-
const over = await this.store.triggers.prune(trigger.id, { history: HISTORY_KEPT, dayMs: DAY_MS, keepByKey: (by) => by === "manual" || eventful(adapterIn(this.adapters, by)), kept: cap });
|
|
1320
|
+
const over = await this.store.triggers.prune(trigger.id, { history: HISTORY_KEPT, dayMs: DAY_MS, keepByKey: (by) => by === "manual" || eventful(adapterIn(this.adapters, by)), kept: cap, now: this.clock.now() });
|
|
1187
1321
|
if (over > 0) {
|
|
1188
1322
|
if (!this.seenFull.has(trigger.id))
|
|
1189
1323
|
this.deps.say({ condition: "trigger_seen_full", trigger: trigger.id, kept: cap });
|
|
@@ -1352,6 +1486,7 @@ function firingView(firing) {
|
|
|
1352
1486
|
return {
|
|
1353
1487
|
key: firing.key, by: firing.by, nominal_at: second(firing.nominalAt), status: firing.status, at: iso(firing.at), run_id: firing.runId, reason: firing.reason, error: firing.error,
|
|
1354
1488
|
...(firing.count !== null ? { count: firing.count } : {}), ...(firing.catchUp ? { catch_up: true } : {}), ...(firing.retryAt !== null ? { attempts: firing.attempts, retry_at: iso(firing.retryAt) } : {}),
|
|
1489
|
+
...(firing.startBy !== null ? { start_by: iso(firing.startBy) } : {}),
|
|
1355
1490
|
};
|
|
1356
1491
|
}
|
|
1357
1492
|
/** A payload tag's attributes from its source's `attrs`, each ` name="value"`: a name of lowercase letters, digits, `_` and
|
package/dist/uploads-archil.js
CHANGED
|
@@ -33,7 +33,7 @@ import { agentDirName, runKey } from "./workspace/paths.js";
|
|
|
33
33
|
import { runDiskOf } from "./workspace/run-disk.js";
|
|
34
34
|
import { isWorkspaceError, WorkspaceError } from "./workspace/index.js";
|
|
35
35
|
import { answerOf, copyFilesInto, INPUTS_DIR, isUploadedFile, MAX_FILES_PER_RUN, MAX_UPLOAD_BYTES, mismatchOf, pathProblem, readyFilesOf, reservation, sentInOneCall, slots, } from "./uploads.js";
|
|
36
|
-
import { uuidv7 } from "./
|
|
36
|
+
import { uuidv7 } from "./ids.js";
|
|
37
37
|
/** The folder of the uploads disk the files are kept under. */
|
|
38
38
|
export const UPLOADS_KEY = "files";
|
|
39
39
|
const RECORD = "file.json";
|
package/dist/uploads.js
CHANGED
|
@@ -7,7 +7,7 @@ import { createHash } from "node:crypto";
|
|
|
7
7
|
import { copyFile, link, lstat, mkdir, open, readdir, readFile, rename, rm, unlink } from "node:fs/promises";
|
|
8
8
|
import { DISK_DIR } from "./server-fs.js";
|
|
9
9
|
import { dirname, join } from "node:path";
|
|
10
|
-
import { uuidv7 } from "./
|
|
10
|
+
import { uuidv7 } from "./ids.js";
|
|
11
11
|
import { ApiError, invalid } from "./errors.js";
|
|
12
12
|
import { typeOf } from "./file-types.js";
|
|
13
13
|
import { readJson, serialBy, tempOf, writeDurable } from "./files.js";
|
package/dist/validate.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export declare const DEFINITION_FIELDS: string[];
|
|
|
12
12
|
/** What an agentic definition may ask the server to check out in each run's folder before its first turn
|
|
13
13
|
* (runner/pr-checkout.ts): `pull_request`, the pull request the run's GitHub event names, at its head, read-only, in
|
|
14
14
|
* `repo/`; `none` clears it on an edit. */
|
|
15
|
-
export declare const CHECKOUTS: readonly ["pull_request", "none"];
|
|
15
|
+
export declare const CHECKOUTS: readonly ["pull_request", "repository", "none"];
|
|
16
16
|
/** The most bytes an agent's output_schema takes, as JSON. */
|
|
17
17
|
export declare const MAX_OUTPUT_SCHEMA_BYTES: number;
|
|
18
18
|
/** The most bytes an agent's input_schema takes, as JSON. */
|
package/dist/validate.js
CHANGED
|
@@ -22,7 +22,7 @@ export const DEFINITION_FIELDS = ["id", "version", "name", "description", "instr
|
|
|
22
22
|
/** What an agentic definition may ask the server to check out in each run's folder before its first turn
|
|
23
23
|
* (runner/pr-checkout.ts): `pull_request`, the pull request the run's GitHub event names, at its head, read-only, in
|
|
24
24
|
* `repo/`; `none` clears it on an edit. */
|
|
25
|
-
export const CHECKOUTS = ["pull_request", "none"];
|
|
25
|
+
export const CHECKOUTS = ["pull_request", "repository", "none"];
|
|
26
26
|
/** The most bytes an agent's output_schema takes, as JSON. */
|
|
27
27
|
export const MAX_OUTPUT_SCHEMA_BYTES = 64 * 1024;
|
|
28
28
|
/** The most bytes an agent's input_schema takes, as JSON. */
|
|
@@ -175,8 +175,7 @@ export function definitionIssues(definition, { at = "definition", creating = tru
|
|
|
175
175
|
if (!(typeof d.max_cost_usd === "number" && Number.isFinite(d.max_cost_usd) && d.max_cost_usd >= 0))
|
|
176
176
|
out.push(issue(`${at}.max_cost_usd`, "wrong_type", `${at}.max_cost_usd is a number of at least 0, in US dollars: above 0 sets the agent's default cap, 0 clears it`));
|
|
177
177
|
}
|
|
178
|
-
// The agent's
|
|
179
|
-
// wins when lower): above 0 sets it, 0 clears it, and an edit that leaves it out keeps the agent's (agents-store.ts).
|
|
178
|
+
// The agent's limit on each run's free-model requests: see DefinitionInput.max_requests (openapi.ts).
|
|
180
179
|
if (d.max_requests !== undefined && !(typeof d.max_requests === "number" && Number.isSafeInteger(d.max_requests) && d.max_requests >= 0))
|
|
181
180
|
out.push(issue(`${at}.max_requests`, "wrong_type", `${at}.max_requests is a whole number of at least 0: above 0 sets the most requests on free models each run makes (the server's own limit holds when it is lower), 0 clears it`));
|
|
182
181
|
// The server's checkout before each run's first turn: kept by an edit that leaves it out, cleared by `none`.
|
|
@@ -184,7 +183,7 @@ export function definitionIssues(definition, { at = "definition", creating = tru
|
|
|
184
183
|
if (d.workflow !== undefined)
|
|
185
184
|
out.push(issue(`${at}.checkout`, "not_allowed", "A workflow revision keeps no checkout: only an agentic run starts in a checkout.", `Remove ${at}.checkout.`));
|
|
186
185
|
else if (!CHECKOUTS.includes(d.checkout))
|
|
187
|
-
out.push(issue(`${at}.checkout`, "not_an_option", `${at}.checkout is one of ${CHECKOUTS.join(", ")}: pull_request checks out the pull request the run's GitHub event names, at its head, in repo/ before the first turn; none clears it`));
|
|
186
|
+
out.push(issue(`${at}.checkout`, "not_an_option", `${at}.checkout is one of ${CHECKOUTS.join(", ")}: pull_request checks out the pull request the run's GitHub event names, at its head, in repo/ before the first turn; repository checks out the head of the default branch of the repository the run names (https://github.com/<owner>/<repo> in its first message, or its start's repo); none clears it`));
|
|
188
187
|
}
|
|
189
188
|
return out;
|
|
190
189
|
}
|
|
@@ -208,6 +208,8 @@ export interface ClaimComputer {
|
|
|
208
208
|
* stopped (compute-cost.ts): run before the run's end or park is written (the spec's beforeRelease), so the end's
|
|
209
209
|
* cost holds it. Absent where nothing is metered. */
|
|
210
210
|
settle?(): Promise<void>;
|
|
211
|
+
/** Strict durable folder sync for project checkpoints; distinct from metering settlement. */
|
|
212
|
+
syncProject?(signal?: AbortSignal): Promise<void>;
|
|
211
213
|
release(why?: ViewEnd): Promise<void>;
|
|
212
214
|
/** The claim's release at the run's park, for `cause`: a computer it `keeps` is kept for KEEP_MS (computer-kept.ts),
|
|
213
215
|
* its live view closed with the park's cause and the keep's time (ParkedEnd) and its hold ended, but the machine left
|
|
@@ -43,6 +43,7 @@ import { startRecording } from "../computer-record.js";
|
|
|
43
43
|
import { computerOfPlace } from "../computer-setting.js";
|
|
44
44
|
import { KEY_TABLE, providerOptions, settingOptions } from "../computer-keys.js";
|
|
45
45
|
import { LOST_RECREATES, lostEnd, lostInCallWords, lostRecreatedWords } from "../computer-lost.js";
|
|
46
|
+
import { missingNeeds, needsNoSandboxWords, needsWords } from "../computer-needs.js";
|
|
46
47
|
import { inToolCall, stopRun } from "../paid-calls.js";
|
|
47
48
|
import { getSealedKey } from "../server-keys.js";
|
|
48
49
|
import { agentComputerOf, forgetAgentComputer, holdAgentComputer, keepAgentComputer, liveHolderOf, reconcileAgentComputer, serverIdOf } from "./agent-computer.js";
|
|
@@ -872,6 +873,13 @@ store, deps) {
|
|
|
872
873
|
},
|
|
873
874
|
};
|
|
874
875
|
const setting = await settingOf(launch, store);
|
|
876
|
+
// Programs it needs (computer.needs) are checked in a sandbox's box alone: a setting that needs them and is any other
|
|
877
|
+
// kind is refused before anything is rented, never run without them.
|
|
878
|
+
const needs = setting?.needs;
|
|
879
|
+
if (needs?.length && setting?.kind !== "sandbox") {
|
|
880
|
+
const label = setting?.provider ? kinds.PROVIDERS.find((one) => one.id === setting.provider)?.label ?? setting.provider : undefined;
|
|
881
|
+
throw unavailable(needsNoSandboxWords(needs, setting?.kind === "none" || !setting ? "none" : `a ${setting.kind}${label ? ` on ${label}` : ""}`));
|
|
882
|
+
}
|
|
875
883
|
const resolved = await resolveComputer(setting, deps.mode, kinds, side);
|
|
876
884
|
if ("refused" in resolved)
|
|
877
885
|
throw unavailable(resolved.refused);
|
|
@@ -900,6 +908,19 @@ store, deps) {
|
|
|
900
908
|
throw error;
|
|
901
909
|
}
|
|
902
910
|
const computer = started.computer;
|
|
911
|
+
// What the agent needs its sandbox to have (computer.needs): asked of the box it started, before anything of the run
|
|
912
|
+
// reaches a model. A box that lacks one, or that could not be asked, is let go and the run ends in words: never a run on
|
|
913
|
+
// a box without what its work needs.
|
|
914
|
+
if (needs?.length) {
|
|
915
|
+
// A sandbox setting whose start gave no sandbox is no box to check: refused as one that could not be asked.
|
|
916
|
+
const answer = computer?.kind === "sandbox" ? await missingNeeds(computer.computer.client, needs, deps.signal) : { unchecked: "its start gave no sandbox" };
|
|
917
|
+
if ("unchecked" in answer || answer.missing.length > 0) {
|
|
918
|
+
await started.release().catch(() => undefined);
|
|
919
|
+
await meter?.stopAll().catch(() => undefined);
|
|
920
|
+
await revoke().catch(() => undefined);
|
|
921
|
+
throw unavailable(needsWords(answer, needs, kinds.PROVIDERS.find((one) => one.id === resolved.provider)));
|
|
922
|
+
}
|
|
923
|
+
}
|
|
903
924
|
// A desktop's or a phone's: its hold, parking the run's ports while a person holds it, and its live view, proxy-only (no
|
|
904
925
|
// vendor's URL reaches a person), opened under this claim. A fenced open is a lost claim. The release ends the hold.
|
|
905
926
|
let endHold = () => { };
|
|
@@ -968,6 +989,28 @@ store, deps) {
|
|
|
968
989
|
...(keeps ? { keeps: keeps.kind } : {}),
|
|
969
990
|
...(meter ? { settle: () => meter.stopAll() } : {}),
|
|
970
991
|
release,
|
|
992
|
+
async syncProject(signal) {
|
|
993
|
+
const cancellation = signal && deps.signal ? AbortSignal.any([signal, deps.signal]) : signal ?? deps.signal;
|
|
994
|
+
cancellation?.throwIfAborted();
|
|
995
|
+
if (started.sync) {
|
|
996
|
+
if (!(await started.sync()).ok)
|
|
997
|
+
throw new Error("The project folder could not be durably synchronized.");
|
|
998
|
+
}
|
|
999
|
+
else if (resolved.folder === "bind") {
|
|
1000
|
+
// A bind is already this Workspace's filesystem, so there is no remote folder delta to pull. File tools
|
|
1001
|
+
// fsync their own writes, but arbitrary shell edits need this final syncfs after dispatch has settled.
|
|
1002
|
+
// Use the supplied host Workspace, never the lost-aware computer client (which could recreate a machine).
|
|
1003
|
+
const flushed = await deps.workspace.exec(["/usr/bin/sync", "-f", "."], {
|
|
1004
|
+
env: { PATH: "/usr/bin:/bin", LANG: "C", LC_ALL: "C" }, timeoutMs: 30_000, maxOutput: 1024,
|
|
1005
|
+
...(cancellation ? { signal: cancellation } : {}),
|
|
1006
|
+
});
|
|
1007
|
+
if (flushed.code !== 0 || flushed.signal || flushed.timedOut || flushed.truncated)
|
|
1008
|
+
throw new Error("The bound project folder could not be durably synchronized.");
|
|
1009
|
+
}
|
|
1010
|
+
else if (runComputer && "check" in runComputer && runComputer.check)
|
|
1011
|
+
throw new Error("This mounted project has no verified synchronization capability.");
|
|
1012
|
+
cancellation?.throwIfAborted();
|
|
1013
|
+
},
|
|
971
1014
|
async park(cause) {
|
|
972
1015
|
if (!keeps || !settings || released) {
|
|
973
1016
|
await release();
|
|
@@ -20,6 +20,12 @@ export declare const agentLearningFolder: (dataDir: string, agentId: string) =>
|
|
|
20
20
|
export declare const homeKey: (agentId: string) => string;
|
|
21
21
|
/** Agent `agentId`'s home, the root of its home Workspace: `<data>/disk/agents/<agent>/home`. */
|
|
22
22
|
export declare const agentHomeFolder: (dataDir: string, agentId: string) => string;
|
|
23
|
+
/** Immutable source bundles, private to the server and outside every run's tool root. */
|
|
24
|
+
export declare const sourceSnapshotsKey: (agentId: string) => string;
|
|
25
|
+
export declare const sourceSnapshotsFolder: (dataDir: string, agentId: string) => string;
|
|
26
|
+
/** A run's source placement receipt, beside work/ so its tools cannot rewrite the admission proof. */
|
|
27
|
+
export declare const sourceRunControlKey: (agentId: string, runId: string) => string;
|
|
28
|
+
export declare const sourceRunControlFolder: (dataDir: string, agentId: string, runId: string) => string;
|
|
23
29
|
/** Run `runId`'s scratch folder on this machine: `<data>/scratch/<agent>/<run>`. Outside the disk, so no Workspace
|
|
24
30
|
* holds it, in either mode. */
|
|
25
31
|
export declare const scratchFolder: (dataDir: string, agentId: string, runId: string) => string;
|
package/dist/workspace/paths.js
CHANGED
|
@@ -55,6 +55,12 @@ export const agentLearningFolder = (dataDir, agentId) => join(dataDir, DISK_DIR,
|
|
|
55
55
|
export const homeKey = (agentId) => `agents/${agentDirName(agentId)}/home`;
|
|
56
56
|
/** Agent `agentId`'s home, the root of its home Workspace: `<data>/disk/agents/<agent>/home`. */
|
|
57
57
|
export const agentHomeFolder = (dataDir, agentId) => join(dataDir, DISK_DIR, homeKey(agentId));
|
|
58
|
+
/** Immutable source bundles, private to the server and outside every run's tool root. */
|
|
59
|
+
export const sourceSnapshotsKey = (agentId) => `agents/${agentDirName(agentId)}/source-snapshots`;
|
|
60
|
+
export const sourceSnapshotsFolder = (dataDir, agentId) => join(dataDir, DISK_DIR, sourceSnapshotsKey(agentId));
|
|
61
|
+
/** A run's source placement receipt, beside work/ so its tools cannot rewrite the admission proof. */
|
|
62
|
+
export const sourceRunControlKey = (agentId, runId) => `agents/${agentDirName(agentId)}/runs/${checkId(runId, "run")}/source-control`;
|
|
63
|
+
export const sourceRunControlFolder = (dataDir, agentId, runId) => join(dataDir, DISK_DIR, sourceRunControlKey(agentId, runId));
|
|
58
64
|
/** Run `runId`'s scratch folder on this machine: `<data>/scratch/<agent>/<run>`. Outside the disk, so no Workspace
|
|
59
65
|
* holds it, in either mode. */
|
|
60
66
|
export const scratchFolder = (dataDir, agentId, runId) => join(dataDir, "scratch", agentDirName(agentId), checkId(runId, "run"));
|
|
@@ -23,6 +23,7 @@ export type ComputerSetting = {
|
|
|
23
23
|
readonly surface?: "code" | "tools";
|
|
24
24
|
readonly exec?: boolean;
|
|
25
25
|
readonly record?: boolean;
|
|
26
|
+
readonly needs?: readonly string[];
|
|
26
27
|
};
|
|
27
28
|
/** Whether a computer (or its setting) takes its agent's programs away: `exec: false`. Only a desktop or a phone takes
|
|
28
29
|
* `exec` (computer-setting.ts refuses it on any other kind at save), so a computer without programs is one of those. */
|
|
@@ -167,6 +167,8 @@ export type RunTools = {
|
|
|
167
167
|
/** The run's end, before the computer is let go: its background processes ended (TERM, then KILL 3 s later; none with
|
|
168
168
|
* no computer), then bash's full outputs and TMPDIR swept. */
|
|
169
169
|
end(): Promise<void>;
|
|
170
|
+
/** Strict checkpoint stop: cleanup errors or any still-running tracked process refuse publication. */
|
|
171
|
+
settleProject(): Promise<readonly string[]>;
|
|
170
172
|
};
|
|
171
173
|
/**
|
|
172
174
|
* A run's tools on `workspace`, attached to `computer` when its kind has files and exec and its provider mounts the
|
|
@@ -180,6 +180,14 @@ export async function runTools(workspace, computer, options) {
|
|
|
180
180
|
kindTools,
|
|
181
181
|
...(run.computer ? { computer: run.computer } : {}),
|
|
182
182
|
hostTools: (names, results) => bindTools(run, registry, names, results ? { results } : {}),
|
|
183
|
+
async settleProject() {
|
|
184
|
+
const before = await run.hands.processes?.list() ?? [];
|
|
185
|
+
await endBackground(run.hands);
|
|
186
|
+
if ((await run.hands.processes?.list() ?? []).some(process => process.running))
|
|
187
|
+
throw new Error("Project processes have not settled.");
|
|
188
|
+
await run.sweep();
|
|
189
|
+
return before.filter(process => process.argv[3] === "agentrun-background" && /^[1-9][0-9]*$/.test(process.argv[4] ?? "")).map(process => `background/${process.argv[4]}/output.log`);
|
|
190
|
+
},
|
|
183
191
|
async end() {
|
|
184
192
|
await endBackground(run.hands);
|
|
185
193
|
await run.sweep();
|
|
@@ -38,7 +38,7 @@ export type HeldFolder = {
|
|
|
38
38
|
};
|
|
39
39
|
/**
|
|
40
40
|
* The stored folder pushed into the computer's empty /workspace through `client` (the computer's own, under no sync),
|
|
41
|
-
* one streaming tar
|
|
41
|
+
* one streaming tar (FolderSync.push), then the computer's listing read as the manifest: the sync the claim
|
|
42
42
|
* holds from then on (the caller sets HeldFolder.folder to it), at the claim's start and for a new sandbox in place of a
|
|
43
43
|
* lost one, whose files the old manifest does not describe. The links an exec made on the disk (linkObjects), now links
|
|
44
44
|
* in the computer, are then removed from the disk. Throws in words where the push, the listing or a remove fails.
|