@parcha/agentrun-serve 0.1.0-beta.56 → 0.1.0-beta.58
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 +281 -0
- package/README.md +246 -66
- package/dist/acp-package.d.ts +2 -0
- package/dist/adapters.d.ts +15 -3
- package/dist/adapters.js +17 -6
- package/dist/agent-package.d.ts +3 -3
- package/dist/agent-package.js +17 -8
- package/dist/api-keys.d.ts +76 -0
- package/dist/api-keys.js +217 -0
- package/dist/api-only.d.ts +15 -5
- package/dist/api-only.js +32 -8
- package/dist/box-paths.d.ts +4 -3
- package/dist/box-paths.js +7 -4
- package/dist/browser-hold.d.ts +23 -0
- package/dist/browser-hold.js +48 -0
- package/dist/browser-person.d.ts +3 -0
- package/dist/browser-person.js +4 -1
- package/dist/chatgpt-plan.d.ts +18 -8
- package/dist/chatgpt-plan.js +91 -34
- package/dist/claude-login-token.d.ts +117 -0
- package/dist/claude-login-token.js +737 -0
- package/dist/claude-login.d.ts +120 -22
- package/dist/claude-login.js +347 -63
- package/dist/claude-sign-in.d.ts +17 -6
- package/dist/claude-sign-in.js +42 -39
- package/dist/cli.js +33 -10
- package/dist/composio-made.d.ts +4 -0
- package/dist/composio-made.js +4 -0
- package/dist/composio-preset.d.ts +43 -2
- package/dist/composio-preset.js +92 -4
- package/dist/computer-attach.d.ts +35 -17
- package/dist/computer-attach.js +301 -49
- package/dist/computer-held-routes.d.ts +5 -4
- package/dist/computer-held-routes.js +29 -8
- package/dist/computer-held.d.ts +6 -1
- package/dist/computer-held.js +14 -0
- package/dist/computer-record.js +4 -2
- package/dist/computer-viewer.js +4 -1
- package/dist/computers.d.ts +10 -10
- package/dist/computers.js +5 -5
- package/dist/console/assets/{backend-Boh7tC4i.js → backend-CSAWUqtZ.js} +19 -19
- package/dist/console/assets/index-Bwn1oTem.css +1 -0
- package/dist/console/assets/index-DPh29cyz.js +747 -0
- package/dist/console/index.html +2 -2
- package/dist/decisions.d.ts +1 -1
- package/dist/decisions.js +1 -1
- package/dist/dial-relay.d.ts +25 -4
- package/dist/dial-relay.js +129 -1
- package/dist/docker-host-addresses.d.ts +22 -11
- package/dist/docker-host-addresses.js +38 -26
- package/dist/env-switch.d.ts +8 -0
- package/dist/env-switch.js +31 -2
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +2 -0
- package/dist/fal-price.d.ts +56 -20
- package/dist/fal-price.js +400 -90
- package/dist/handed-values.d.ts +43 -1
- package/dist/handed-values.js +119 -2
- package/dist/harness-archive.d.ts +13 -10
- package/dist/harness-archive.js +60 -34
- package/dist/harness-check.d.ts +3 -1
- package/dist/harness-check.js +25 -46
- package/dist/harness-keys.d.ts +73 -27
- package/dist/harness-keys.js +194 -61
- package/dist/harness-recipe-entry.d.ts +8 -7
- package/dist/harness-recipe-entry.js +21 -32
- package/dist/harness-recipe.d.ts +38 -25
- package/dist/harness-recipe.js +49 -36
- package/dist/harness-sign-in.js +12 -23
- package/dist/harness-table.d.ts +10 -3
- package/dist/harness-table.js +26 -21
- package/dist/harness.d.ts +1 -0
- package/dist/harness.js +17 -5
- package/dist/hosted-search.d.ts +1 -1
- package/dist/hosted-search.js +1 -2
- package/dist/import-worker.d.ts +4 -2
- package/dist/import-worker.js +9 -2
- package/dist/in-flight.d.ts +26 -0
- package/dist/in-flight.js +52 -0
- package/dist/key-refusal.d.ts +9 -4
- package/dist/key-refusal.js +107 -25
- package/dist/learn/ledger.d.ts +170 -0
- package/dist/learn/ledger.js +218 -0
- package/dist/learn/promote.d.ts +3 -3
- package/dist/learn/promote.js +1 -1
- package/dist/learn/secrets.d.ts +13 -3
- package/dist/learn/secrets.js +118 -17
- package/dist/learning-cost.d.ts +28 -23
- package/dist/learning-cost.js +19 -23
- package/dist/link-check.js +1 -1
- package/dist/live-reach.d.ts +2 -0
- package/dist/live-reach.js +2 -0
- package/dist/llms.txt +1 -1
- package/dist/marketplace.d.ts +77 -0
- package/dist/marketplace.js +224 -0
- package/dist/mcp-api-only-origins.d.ts +35 -0
- package/dist/mcp-api-only-origins.js +57 -0
- package/dist/mcp-gateway.d.ts +7 -5
- package/dist/mcp-gateway.js +9 -12
- package/dist/mcp-secret-writes.js +5 -3
- package/dist/mcp-servers-store.d.ts +28 -6
- package/dist/mcp-servers-store.js +53 -4
- package/dist/media-duration.d.ts +3 -0
- package/dist/media-duration.js +90 -9
- package/dist/micro.d.ts +2 -0
- package/dist/micro.js +2 -0
- package/dist/model-form.d.ts +5 -4
- package/dist/model-form.js +11 -7
- package/dist/model.d.ts +10 -6
- package/dist/model.js +16 -11
- package/dist/monid.d.ts +14 -1
- package/dist/monid.js +103 -26
- package/dist/ollama-provider.d.ts +7 -1
- package/dist/ollama-provider.js +14 -2
- package/dist/openapi.js +210 -37
- package/dist/otel/genai.d.ts +65 -0
- package/dist/otel/genai.js +116 -0
- package/dist/otel/tracer.d.ts +55 -0
- package/dist/otel/tracer.js +308 -0
- package/dist/page.d.ts +2 -0
- package/dist/page.js +3 -1
- package/dist/paid-calls.d.ts +1 -32
- package/dist/paid-calls.js +4 -39
- package/dist/place-offers.d.ts +4 -0
- package/dist/place-offers.js +7 -4
- package/dist/provider.d.ts +11 -2
- package/dist/provider.js +59 -8
- package/dist/redact/match.d.ts +30 -3
- package/dist/redact/match.js +422 -41
- package/dist/refusal-words.d.ts +11 -0
- package/dist/refusal-words.js +11 -0
- package/dist/run-census.d.ts +67 -0
- package/dist/run-census.js +240 -0
- package/dist/run-computer.d.ts +6 -3
- package/dist/run-computer.js +4 -1
- package/dist/run-cut.d.ts +15 -6
- package/dist/run-cut.js +30 -9
- package/dist/run-files.d.ts +3 -0
- package/dist/run-files.js +3 -0
- package/dist/run-launch.d.ts +12 -1
- package/dist/run-launch.js +9 -10
- package/dist/run-learning-served.d.ts +4 -2
- package/dist/run-model-key.d.ts +8 -0
- package/dist/run-model-key.js +31 -1
- package/dist/run-reads-over-store.d.ts +24 -6
- package/dist/run-reads-over-store.js +67 -23
- package/dist/run-recordings.d.ts +5 -1
- package/dist/run-recordings.js +39 -14
- package/dist/run-timeline-served.d.ts +2 -0
- package/dist/run-timeline-served.js +2 -2
- package/dist/run-usage.d.ts +1 -0
- package/dist/run-view.d.ts +1 -2
- package/dist/run-view.js +2 -1
- package/dist/runnable.d.ts +10 -1
- package/dist/runnable.js +20 -8
- package/dist/runner/adapter-loop.d.ts +11 -0
- package/dist/runner/adapter-loop.js +58 -26
- package/dist/runner/adapter-run-spec.d.ts +55 -11
- package/dist/runner/adapter-run-spec.js +183 -52
- package/dist/runner/adapters/pi.js +25 -3
- package/dist/runner/beside.d.ts +9 -2
- package/dist/runner/beside.js +27 -9
- package/dist/runner/big-writes.js +1 -10
- package/dist/runner/claim-secrets.d.ts +27 -10
- package/dist/runner/claim-secrets.js +49 -22
- package/dist/runner/cli-run-spec.d.ts +6 -0
- package/dist/runner/cli-run-spec.js +97 -38
- package/dist/runner/computer-journal.d.ts +9 -1
- package/dist/runner/computer-journal.js +26 -0
- package/dist/runner/conformance/harness.js +1 -1
- package/dist/runner/feedback-round.js +3 -0
- package/dist/runner/harness-loops.d.ts +6 -5
- package/dist/runner/harness-loops.js +7 -7
- package/dist/runner/held.d.ts +24 -6
- package/dist/runner/journal-kinds.d.ts +5 -0
- package/dist/runner/journal-kinds.js +5 -0
- package/dist/runner/main.d.ts +11 -6
- package/dist/runner/main.js +19 -9
- package/dist/runner/mcp-claim.js +31 -3
- package/dist/runner/mcp-run.d.ts +9 -0
- package/dist/runner/mcp-run.js +11 -5
- package/dist/runner/model-route.d.ts +17 -0
- package/dist/runner/model-route.js +120 -2
- package/dist/runner/presence.d.ts +11 -1
- package/dist/runner/presence.js +7 -0
- package/dist/runner/reflect-hook.js +1 -1
- package/dist/runner/run-child-host.d.ts +22 -8
- package/dist/runner/run-child-host.js +128 -41
- package/dist/runner/run-child.js +5 -2
- package/dist/runner/runner.d.ts +17 -3
- package/dist/runner/runner.js +130 -34
- package/dist/runner/save-slots.js +2 -1
- package/dist/runner/store-port.d.ts +1 -1
- package/dist/runner/store-secrets.d.ts +6 -0
- package/dist/runner/store-secrets.js +49 -7
- package/dist/runner/subagent.d.ts +11 -0
- package/dist/runner/subagent.js +16 -38
- package/dist/runner/workflow-first.d.ts +35 -15
- package/dist/runner/workflow-first.js +38 -25
- package/dist/runner/workflow-spec.js +4 -3
- package/dist/runs-over-store.d.ts +15 -6
- package/dist/runs-over-store.js +33 -21
- package/dist/scrub-command.d.ts +73 -0
- package/dist/scrub-command.js +307 -0
- package/dist/secret-cut.d.ts +73 -0
- package/dist/secret-cut.js +291 -4
- package/dist/secret-rules.d.ts +143 -0
- package/dist/secret-rules.js +2564 -0
- package/dist/secrets.d.ts +7 -0
- package/dist/secrets.js +20 -0
- package/dist/server-keys.d.ts +20 -0
- package/dist/server-keys.js +25 -6
- package/dist/server.d.ts +65 -13
- package/dist/server.js +470 -157
- package/dist/skills/agentrun-serve/SKILL.md +4 -0
- package/dist/slots.d.ts +9 -0
- package/dist/slots.js +45 -0
- package/dist/store/index.d.ts +1 -1
- package/dist/store/index.js +1 -1
- package/dist/store/journal/storage.js +1 -1
- package/dist/store/postgres/migrations/0027_run_launch_census.sql +31 -0
- package/dist/store/postgres/migrations/0028_learning_ledger.sql +44 -0
- package/dist/store/schema.d.ts +23 -0
- package/dist/store/schema.js +58 -2
- package/dist/store/seal.d.ts +6 -1
- package/dist/store/seal.js +5 -3
- package/dist/store/sqlite/run-launch.d.ts +9 -1
- package/dist/store/sqlite/run-launch.js +24 -13
- package/dist/store/sqlite/run-patch.d.ts +12 -2
- package/dist/store/sqlite/run-patch.js +42 -5
- package/dist/store/sqlite/store.js +105 -12
- package/dist/store/store.d.ts +57 -2
- package/dist/store/store.js +20 -0
- package/dist/store-reads/learning.d.ts +84 -124
- package/dist/store-reads/learning.js +210 -274
- package/dist/store-view.d.ts +3 -0
- package/dist/store-view.js +3 -3
- package/dist/suggestions.js +3 -2
- package/dist/template-eval.d.ts +39 -9
- package/dist/template-eval.js +191 -60
- package/dist/template-import.js +6 -2
- package/dist/templates.d.ts +10 -2
- package/dist/templates.js +28 -8
- package/dist/timeline/labels.d.ts +6 -4
- package/dist/timeline/labels.js +18 -6
- package/dist/timeline/timeline.d.ts +5 -0
- package/dist/timeline/timeline.js +14 -8
- package/dist/timeline/util.js +1 -1
- package/dist/timeline/web-calls.d.ts +22 -7
- package/dist/timeline/web-calls.js +106 -35
- package/dist/tool-gate.d.ts +42 -3
- package/dist/tool-gate.js +66 -5
- package/dist/tool-keys-store.d.ts +2 -4
- package/dist/tool-keys-store.js +5 -21
- package/dist/tool-keys.d.ts +2 -2
- package/dist/tool-keys.js +2 -2
- package/dist/tool-list.js +1 -1
- package/dist/tool-plane.d.ts +2 -2
- package/dist/tool-plane.js +35 -33
- package/dist/tools.js +13 -7
- package/dist/trigger-targets.d.ts +4 -0
- package/dist/trigger-targets.js +9 -2
- package/dist/triggers.d.ts +67 -4
- package/dist/triggers.js +171 -22
- package/dist/until.d.ts +3 -0
- package/dist/until.js +11 -0
- package/dist/web-fake.d.ts +1 -3
- package/dist/web-fake.js +7 -18
- package/dist/web-fetch.d.ts +6 -72
- package/dist/web-fetch.js +11 -265
- package/dist/web-run.d.ts +31 -0
- package/dist/web-run.js +90 -0
- package/dist/web-save.d.ts +10 -13
- package/dist/web-save.js +13 -55
- package/dist/web-search.d.ts +9 -127
- package/dist/web-search.js +23 -259
- package/dist/wires.d.ts +13 -0
- package/dist/wires.js +11 -0
- package/dist/workflow-run.d.ts +5 -4
- package/dist/workflow-run.js +5 -4
- package/dist/workspace/attached-computers.d.ts +32 -9
- package/dist/workspace/attached-computers.js +77 -13
- package/dist/workspace/computer-deps.d.ts +8 -2
- package/dist/workspace/computer-deps.js +10 -3
- package/dist/workspace/computer-for-claim.d.ts +12 -1
- package/dist/workspace/computer-for-claim.js +83 -11
- package/dist/workspace/computer-kept.d.ts +3 -0
- package/dist/workspace/computer-kept.js +11 -2
- package/dist/workspace/index.d.ts +1 -1
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/kind-skills.d.ts +4 -0
- package/dist/workspace/kind-skills.js +9 -0
- package/dist/workspace/paired-route.d.ts +91 -0
- package/dist/workspace/paired-route.js +153 -0
- package/dist/workspace/synced-folder.js +3 -4
- package/dist/wrapped.d.ts +20 -6
- package/dist/wrapped.js +66 -25
- package/package.json +17 -11
- package/skills/agentrun-serve/SKILL.md +4 -0
- package/templates/README.md +32 -10
- package/dist/console/assets/index-CQ3cJRzI.js +0 -746
- package/dist/console/assets/index-DKkaS3a0.css +0 -1
- package/dist/exa-keyless.d.ts +0 -34
- package/dist/exa-keyless.js +0 -118
- package/dist/firecrawl-keyless.d.ts +0 -41
- package/dist/firecrawl-keyless.js +0 -152
- package/dist/keyless-mcp.d.ts +0 -36
- package/dist/keyless-mcp.js +0 -127
- package/dist/text-urls.d.ts +0 -38
- package/dist/text-urls.js +0 -170
- package/dist/web-fetch-direct.d.ts +0 -119
- package/dist/web-fetch-direct.js +0 -190
|
@@ -52,10 +52,9 @@ export interface Revise {
|
|
|
52
52
|
readonly by_hand_usd: number;
|
|
53
53
|
readonly runs: number;
|
|
54
54
|
}
|
|
55
|
-
/**
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
* cost and every learning round booked for it; null when any part is unknown), when it started. */
|
|
55
|
+
/** One of the agent's runs as the money rule reads it: its record's path fields, its all-in cost (the cost series'
|
|
56
|
+
* `total_usd`, learn/ledger.ts RunFigures: the job, its look-back and its audit's shadow; null when any part is
|
|
57
|
+
* unknown), when it started. */
|
|
59
58
|
export type PastRun = {
|
|
60
59
|
readonly metrics: unknown;
|
|
61
60
|
readonly allInUsd: number | null;
|
|
@@ -66,12 +65,26 @@ type Mean = {
|
|
|
66
65
|
readonly runs: number;
|
|
67
66
|
readonly mean_usd: number;
|
|
68
67
|
};
|
|
69
|
-
/**
|
|
70
|
-
* its
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
|
|
74
|
-
|
|
68
|
+
/** What the money rule reads of the agent (store-reads/learning.ts pastRunsOf): of its newest PAST_RUNS runs on no named
|
|
69
|
+
* disk, those since its learning's reset (`runs`, any order), and the by-hand cost over those same runs (`by_hand`: the
|
|
70
|
+
* mean job's own $ of the ones on the `agent` path, learning left out) with the by-hand runs it left out for an unknown
|
|
71
|
+
* cost (`by_hand_unknown`). */
|
|
72
|
+
export type PastRuns = {
|
|
73
|
+
readonly runs: readonly PastRun[];
|
|
74
|
+
readonly by_hand: Mean | null;
|
|
75
|
+
readonly by_hand_unknown: number;
|
|
76
|
+
};
|
|
77
|
+
/** No runs read: nothing to stop. */
|
|
78
|
+
export declare const NO_PAST_RUNS: PastRuns;
|
|
79
|
+
/** How many of the agent's newest runs on no named disk the money rule reads, both sides (store-reads/learning.ts
|
|
80
|
+
* pastRunsOf): a launch's read is bounded whatever the agent's history, and the cost page reads the same window. */
|
|
81
|
+
export declare const PAST_RUNS = 500;
|
|
82
|
+
/** The money rule's two sides for workflow `name` at `digest`, over the agent's runs (`past`): `served`, the mean all-in
|
|
83
|
+
* of its newest COST_WINDOW runs served first at that digest (path workflow or handed_back) whose all-in is known (the
|
|
84
|
+
* cost page's `after` side reads the same figure); `by_hand`, as given (PastRuns: the job's own $ over the same runs,
|
|
85
|
+
* never a second baseline here); `unknown_runs`, the runs either side would have read that it left out for an unknown cost (the cost
|
|
86
|
+
* page's rule: left out and counted). */
|
|
87
|
+
export declare function costLineOf(past: PastRuns, name: string, digest: string): {
|
|
75
88
|
served: Mean | {
|
|
76
89
|
runs: 0;
|
|
77
90
|
mean_usd: null;
|
|
@@ -85,11 +98,11 @@ export declare const overLine: (line: ReturnType<typeof costLineOf>) => boolean;
|
|
|
85
98
|
/** The money rule's decision over the agent's runs (`past`, store-reads/learning.ts pastRunsOverStore): whether it stops a
|
|
86
99
|
* workflow at a digest from running first (overLine), the one workflowFirstOf reads at a claim. Each workflow's state
|
|
87
100
|
* (learn/promote.ts servingStateOf) folds it in at its champion's digest. */
|
|
88
|
-
export declare const costStopOf: (past:
|
|
101
|
+
export declare const costStopOf: (past: PastRuns) => CostStop;
|
|
89
102
|
/** Each learned workflow that has served one of the agent's runs (`past`) first, at the digest its newest served run
|
|
90
103
|
* ran, with the money rule's two sides there, the runs they left out for an unknown all-in, and where it stands:
|
|
91
104
|
* `serving`, or `needs_revision` once over the line (overLine). What the agent's cost per run shows its owner. */
|
|
92
|
-
export declare function workflowCostsOf(past:
|
|
105
|
+
export declare function workflowCostsOf(past: PastRuns): {
|
|
93
106
|
workflow: string;
|
|
94
107
|
digest: string;
|
|
95
108
|
state: "serving" | "needs_revision";
|
|
@@ -155,10 +168,12 @@ export declare const workflowDigest: (workflow: Pick<LearnedWorkflow, "workflow"
|
|
|
155
168
|
* run (launch.replay) serves the workflow it replays, by name, alone: no promotion, no money rule; none when its claim
|
|
156
169
|
* laid no workflow by that name at that digest (runner/promotion.ts replayClaimed then refuses the claim: the run ends
|
|
157
170
|
* failed, never on the agent's path). */
|
|
158
|
-
export declare function workflowFirstOf(kind: string, workflows: readonly LearnedWorkflow[], launch: RunLaunch, log?: (line: string) => void, past?: () => Promise<
|
|
171
|
+
export declare function workflowFirstOf(kind: string, workflows: readonly LearnedWorkflow[], launch: RunLaunch, log?: (line: string) => void, past?: () => Promise<PastRuns>, promoted?: Promoted, outputSchema?: unknown): Promise<FirstChoice>;
|
|
159
172
|
/** What a run's workflow-first step did, from its root entries (the WORKFLOW_FIRST entry): the workflow, its digest, the
|
|
160
173
|
* promotion it served under (WorkflowFirst.promotion), and whether it answered or handed back; undefined when it served
|
|
161
|
-
* none.
|
|
174
|
+
* none. `cut` on a hand-back the workflow never made itself: its call's end (WORKFLOW_FIRST_CALL) is `interrupted`, a
|
|
175
|
+
* crash or a lost runner cut it and the next claim ended it, never running it again (adapter-loop.ts serveFirst). The
|
|
176
|
+
* run's path is the run-end classifier's (store-reads/learning.ts runPathOverStore), which reads this first. */
|
|
162
177
|
export declare function servedOf(entries: readonly {
|
|
163
178
|
readonly kind: string;
|
|
164
179
|
readonly data?: unknown;
|
|
@@ -167,11 +182,13 @@ export declare function servedOf(entries: readonly {
|
|
|
167
182
|
workflow: string;
|
|
168
183
|
digest?: string;
|
|
169
184
|
promotion?: number;
|
|
185
|
+
cut?: true;
|
|
170
186
|
} | undefined;
|
|
171
187
|
/** The run-record fields a learning run's metrics carry, from the run-end classifier's `classified` path
|
|
172
188
|
* (runPathOverStore): the path it took, the learned revision it ran on, the learned workflow it ran (served first, or
|
|
173
189
|
* called by its agent) and, for one served first, its digest and the promotion it served under (`workflow_promotion`,
|
|
174
|
-
* which its grade keeps),
|
|
190
|
+
* which its grade keeps), `workflow_cut` on a hand-back a restart cut (servedOf `cut`: the workflow handed nothing back
|
|
191
|
+
* itself), and `not_auditable` when a trigger started it (never audited); and from its root `entries`,
|
|
175
192
|
* each loop's exit (`loops`, loopsOf: a quote re-pick is a loop's second pass), when one ran. learning-cost reads path
|
|
176
193
|
* and workflow from here. None for a run that does not learn. */
|
|
177
194
|
export declare function pathMetrics(launch: RunLaunch, classified: {
|
|
@@ -179,6 +196,7 @@ export declare function pathMetrics(launch: RunLaunch, classified: {
|
|
|
179
196
|
workflow: string | null;
|
|
180
197
|
digest?: string;
|
|
181
198
|
promotion?: number;
|
|
199
|
+
cut?: true;
|
|
182
200
|
} | undefined, entries?: readonly {
|
|
183
201
|
readonly kind: string;
|
|
184
202
|
readonly data?: unknown;
|
|
@@ -188,7 +206,9 @@ export declare function pathMetrics(launch: RunLaunch, classified: {
|
|
|
188
206
|
workflow?: string;
|
|
189
207
|
workflow_digest?: string;
|
|
190
208
|
workflow_promotion?: number;
|
|
209
|
+
workflow_cut?: true;
|
|
191
210
|
not_auditable?: true;
|
|
211
|
+
not_served?: "cost_stop";
|
|
192
212
|
loops?: LoopRow[];
|
|
193
213
|
replay?: ReplayMetrics;
|
|
194
214
|
audit?: NonNullable<RunLaunch["audit"]> & {
|
|
@@ -12,10 +12,11 @@
|
|
|
12
12
|
// is one sample; a revision is asked only of a workflow its promotion holds), and never keeps the workflow from serving.
|
|
13
13
|
// One money rule does (costLineOf): a workflow
|
|
14
14
|
// serves while its all-in cost a run over its last COST_WINDOW served runs at its digest stays under the agent's by-hand
|
|
15
|
-
// cost
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
//
|
|
15
|
+
// cost. Both are the cost page's own (store-reads/learning.ts, over learn/ledger.ts summarize): the served side reads a
|
|
16
|
+
// run's all-in (its booked cost, the workflow and any handback's agent work together, and every learning round booked
|
|
17
|
+
// for it), and the by-hand cost is the job's own cost of the agent's runs on its own path among the same runs (its newest
|
|
18
|
+
// PAST_RUNS on no named disk since its learning's reset), so a compile turn is never by hand: it is its revision's spend. A run
|
|
19
|
+
// whose cost is unknown is left out of its side's mean and counted, never read as 0. Over that line it stops running
|
|
19
20
|
// first: the agent takes the run, the run's journal keeps why with the two numbers (WORKFLOW_FIRST, outcome
|
|
20
21
|
// needs_revision), and the agent's cost per run shows it stopped. The stop asks for no compile. A new revision of it (a
|
|
21
22
|
// new digest: one its hold asked, or its owner's) serves again from zero. Fewer than
|
|
@@ -38,19 +39,22 @@ import { comparedOf, sameAnswer } from "../learn/promote.js";
|
|
|
38
39
|
export const WORKFLOW_FIRST = "agentrun.workflow_first";
|
|
39
40
|
/** The one call id a run's workflow-first call goes under: replay never, a crash's call is ended interrupted. */
|
|
40
41
|
export const WORKFLOW_FIRST_CALL = "workflow-first";
|
|
41
|
-
/**
|
|
42
|
+
/** No runs read: nothing to stop. */
|
|
43
|
+
export const NO_PAST_RUNS = { runs: [], by_hand: null, by_hand_unknown: 0 };
|
|
44
|
+
/** How many of the agent's newest runs on no named disk the money rule reads, both sides (store-reads/learning.ts
|
|
45
|
+
* pastRunsOf): a launch's read is bounded whatever the agent's history, and the cost page reads the same window. */
|
|
42
46
|
export const PAST_RUNS = 500;
|
|
43
47
|
const SERVED = ["workflow", "handed_back"];
|
|
44
48
|
const usd = (value) => Math.round(value * 1e6) / 1e6;
|
|
45
49
|
const meanOf = (costs) => (costs.length ? { runs: costs.length, mean_usd: usd(costs.reduce((a, b) => a + b, 0) / costs.length) } : null);
|
|
46
50
|
const pathFields = (metrics) => (isObject(metrics) ? metrics : {});
|
|
47
|
-
/** The money rule's two sides for workflow `name` at `digest`, over the agent's runs (`past`,
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
51
|
+
/** The money rule's two sides for workflow `name` at `digest`, over the agent's runs (`past`): `served`, the mean all-in
|
|
52
|
+
* of its newest COST_WINDOW runs served first at that digest (path workflow or handed_back) whose all-in is known (the
|
|
53
|
+
* cost page's `after` side reads the same figure); `by_hand`, as given (PastRuns: the job's own $ over the same runs,
|
|
54
|
+
* never a second baseline here); `unknown_runs`, the runs either side would have read that it left out for an unknown cost (the cost
|
|
55
|
+
* page's rule: left out and counted). */
|
|
52
56
|
export function costLineOf(past, name, digest) {
|
|
53
|
-
const newest = [...past].sort((a, b) => b.startedAt - a.startedAt);
|
|
57
|
+
const newest = [...past.runs].sort((a, b) => b.startedAt - a.startedAt);
|
|
54
58
|
const known = (run) => typeof run.allInUsd === "number" && Number.isFinite(run.allInUsd);
|
|
55
59
|
const ran = (run) => { const m = pathFields(run.metrics); return m.workflow === name && SERVED.includes(m.path); };
|
|
56
60
|
// Newest first, until COST_WINDOW known: an unknown one met before the window filled is one it left out.
|
|
@@ -64,11 +68,7 @@ export function costLineOf(past, name, digest) {
|
|
|
64
68
|
else
|
|
65
69
|
servedUnknown += 1;
|
|
66
70
|
}
|
|
67
|
-
|
|
68
|
-
const first = Math.min(...newest.filter(ran).map((run) => run.startedAt));
|
|
69
|
-
const hand = agent.some(known) ? agent : newest.filter((run) => run.startedAt < first && !SERVED.includes(pathFields(run.metrics).path) && pathFields(run.metrics).path !== "replay" && pathFields(run.metrics).path !== "audit");
|
|
70
|
-
const byHand = hand.filter(known).map((run) => run.allInUsd);
|
|
71
|
-
return { served: meanOf(served) ?? { runs: 0, mean_usd: null }, by_hand: meanOf(byHand), unknown_runs: servedUnknown + hand.length - byHand.length };
|
|
71
|
+
return { served: meanOf(served) ?? { runs: 0, mean_usd: null }, by_hand: past.by_hand, unknown_runs: servedUnknown + past.by_hand_unknown };
|
|
72
72
|
}
|
|
73
73
|
/** Whether a cost line is over the money rule's line: COST_WINDOW served runs or more at the digest, a by-hand cost to
|
|
74
74
|
* hold them to, and their mean at or over it. */
|
|
@@ -82,7 +82,7 @@ export const costStopOf = (past) => (workflow, digest) => overLine(costLineOf(pa
|
|
|
82
82
|
* `serving`, or `needs_revision` once over the line (overLine). What the agent's cost per run shows its owner. */
|
|
83
83
|
export function workflowCostsOf(past) {
|
|
84
84
|
const newest = new Map();
|
|
85
|
-
for (const run of [...past].sort((a, b) => b.startedAt - a.startedAt)) {
|
|
85
|
+
for (const run of [...past.runs].sort((a, b) => b.startedAt - a.startedAt)) {
|
|
86
86
|
const m = pathFields(run.metrics);
|
|
87
87
|
if (SERVED.includes(m.path) && typeof m.workflow === "string" && typeof m.workflow_digest === "string" && !newest.has(m.workflow))
|
|
88
88
|
newest.set(m.workflow, m.workflow_digest);
|
|
@@ -214,33 +214,43 @@ export async function workflowFirstOf(kind, workflows, launch, log, past, promot
|
|
|
214
214
|
const serve = { ...champion, serve: { name: chosen.name, digest, ...(promotion !== undefined ? { promotion } : {}), input: launch.input, revision: launch.learning.seed, ...(outputSchema !== undefined ? { outputSchema } : {}) } };
|
|
215
215
|
if (!past)
|
|
216
216
|
return serve;
|
|
217
|
-
|
|
217
|
+
// Runs it can't read stop nothing: the run is served unchecked, and the log says so.
|
|
218
|
+
const read = await past().catch((error) => {
|
|
219
|
+
log?.(`workflow-first: the money rule could not read the agent's past runs (${error instanceof Error ? error.message : String(error)}); ${chosen.name} serves this run unchecked`);
|
|
220
|
+
return NO_PAST_RUNS;
|
|
221
|
+
});
|
|
222
|
+
const line = costLineOf(read, chosen.name, digest);
|
|
218
223
|
if (line.served.runs < COST_WINDOW)
|
|
219
224
|
return serve;
|
|
220
225
|
if (line.by_hand === null) {
|
|
221
|
-
log?.(`workflow-first: no by-hand cost to hold ${chosen.name} to (no run on the agent's path
|
|
226
|
+
log?.(`workflow-first: no by-hand cost to hold ${chosen.name} to (no run of known cost on the agent's path before a learned workflow first served); it runs first`);
|
|
222
227
|
return serve;
|
|
223
228
|
}
|
|
224
229
|
if (!overLine(line))
|
|
225
230
|
return serve;
|
|
226
231
|
const revise = { workflow: chosen.name, digest, served_usd: line.served.mean_usd, by_hand_usd: line.by_hand.mean_usd, runs: line.served.runs, revision: launch.learning.seed, ...(outputSchema !== undefined ? { outputSchema } : {}) };
|
|
227
232
|
const unknown = line.unknown_runs ? ` (${line.unknown_runs} run${line.unknown_runs === 1 ? "" : "s"} of unknown cost left out)` : "";
|
|
228
|
-
log?.(`workflow-first: ${chosen.name} cost $${revise.served_usd} a run over its last ${revise.runs} served runs, at or over $${revise.by_hand_usd} by hand
|
|
233
|
+
log?.(`workflow-first: ${chosen.name} cost $${revise.served_usd} a run over its last ${revise.runs} served runs, at or over $${revise.by_hand_usd} by hand (served all-in, by hand the job's own, over the same runs)${unknown}; it does not run first until a new revision of it; the agent takes this run`);
|
|
229
234
|
return { ...champion, revise };
|
|
230
235
|
}
|
|
231
236
|
/** What a run's workflow-first step did, from its root entries (the WORKFLOW_FIRST entry): the workflow, its digest, the
|
|
232
237
|
* promotion it served under (WorkflowFirst.promotion), and whether it answered or handed back; undefined when it served
|
|
233
|
-
* none.
|
|
238
|
+
* none. `cut` on a hand-back the workflow never made itself: its call's end (WORKFLOW_FIRST_CALL) is `interrupted`, a
|
|
239
|
+
* crash or a lost runner cut it and the next claim ended it, never running it again (adapter-loop.ts serveFirst). The
|
|
240
|
+
* run's path is the run-end classifier's (store-reads/learning.ts runPathOverStore), which reads this first. */
|
|
234
241
|
export function servedOf(entries) {
|
|
235
242
|
const served = entries.findLast((entry) => entry.kind === WORKFLOW_FIRST && (entry.data?.outcome === "answered" || entry.data?.outcome === "handed_back"))?.data;
|
|
236
243
|
if (!served || typeof served.workflow !== "string")
|
|
237
244
|
return undefined;
|
|
238
|
-
|
|
245
|
+
const end = entries.findLast((entry) => entry.kind === KINDS.callEnd && entry.data?.callId === WORKFLOW_FIRST_CALL)?.data;
|
|
246
|
+
const cut = served.outcome === "handed_back" && end?.status === "interrupted";
|
|
247
|
+
return { outcome: served.outcome, workflow: served.workflow, ...(typeof served.digest === "string" ? { digest: served.digest } : {}), ...(typeof served.promotion === "number" ? { promotion: served.promotion } : {}), ...(cut ? { cut: true } : {}) };
|
|
239
248
|
}
|
|
240
249
|
/** The run-record fields a learning run's metrics carry, from the run-end classifier's `classified` path
|
|
241
250
|
* (runPathOverStore): the path it took, the learned revision it ran on, the learned workflow it ran (served first, or
|
|
242
251
|
* called by its agent) and, for one served first, its digest and the promotion it served under (`workflow_promotion`,
|
|
243
|
-
* which its grade keeps),
|
|
252
|
+
* which its grade keeps), `workflow_cut` on a hand-back a restart cut (servedOf `cut`: the workflow handed nothing back
|
|
253
|
+
* itself), and `not_auditable` when a trigger started it (never audited); and from its root `entries`,
|
|
244
254
|
* each loop's exit (`loops`, loopsOf: a quote re-pick is a loop's second pass), when one ran. learning-cost reads path
|
|
245
255
|
* and workflow from here. None for a run that does not learn. */
|
|
246
256
|
export function pathMetrics(launch, classified, entries = []) {
|
|
@@ -252,7 +262,7 @@ export function pathMetrics(launch, classified, entries = []) {
|
|
|
252
262
|
return { path: "audit", audit: { of: launch.audit.of, workflow: launch.audit.workflow, digest: launch.audit.digest, ...verdict } };
|
|
253
263
|
if (!launch.learning)
|
|
254
264
|
return {};
|
|
255
|
-
const { path, workflow, digest, promotion } = classified ?? { path: "agent", workflow: null };
|
|
265
|
+
const { path, workflow, digest, promotion, cut } = classified ?? { path: "agent", workflow: null };
|
|
256
266
|
const loops = loopsOf(entries);
|
|
257
267
|
const rows = loops.length ? { loops } : {};
|
|
258
268
|
if (launch.replay) {
|
|
@@ -269,7 +279,10 @@ export function pathMetrics(launch, classified, entries = []) {
|
|
|
269
279
|
}
|
|
270
280
|
// A served run a trigger started (learn/audit.ts auditableLaunch) is never audited: counted on the promotions read.
|
|
271
281
|
const notAuditable = SERVED_PATHS.includes(path) && !auditableLaunch(launch);
|
|
272
|
-
|
|
282
|
+
// The money rule stopped its workflow from running first (its WORKFLOW_FIRST entry asks for a revision): why it was not
|
|
283
|
+
// served, the ledger's (learn/ledger.ts record).
|
|
284
|
+
const costStop = path === "agent" && entries.some((entry) => entry.kind === WORKFLOW_FIRST && entry.data?.outcome === "needs_revision");
|
|
285
|
+
return { path, ...(launch.learning.seed ? { learned_revision: launch.learning.seed } : {}), ...(workflow ? { workflow } : {}), ...(digest ? { workflow_digest: digest } : {}), ...(promotion !== undefined ? { workflow_promotion: promotion } : {}), ...(cut && path === "handed_back" ? { workflow_cut: true } : {}), ...(notAuditable ? { not_auditable: true } : {}), ...(costStop ? { not_served: "cost_stop" } : {}), ...rows };
|
|
273
286
|
}
|
|
274
287
|
/** What run `entries` (its root's) say its learned workflow answered alone: the workflow and its answer (the model's
|
|
275
288
|
* message written just before the WORKFLOW_FIRST entry, in its commit); undefined for a run it did not answer. A follow-up that opens such a
|
|
@@ -30,8 +30,9 @@ import { runGate } from "../tool-gate.js";
|
|
|
30
30
|
import { callNodeAskText, deniedText, modelNodeAskText } from "../refusal-words.js";
|
|
31
31
|
import { planeOf, TOOL_PLANE_ENV } from "../tool-plane.js";
|
|
32
32
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
33
|
-
import {
|
|
34
|
-
import {
|
|
33
|
+
import { parallelExtractFee, parallelSearchFee, searchArgs } from "@parcha/agentrun-web";
|
|
34
|
+
import { bookedIn } from "../paid-calls.js";
|
|
35
|
+
import { WEB_SEARCH_TOOL } from "../web-search.js";
|
|
35
36
|
import { money, pricingOf, requestPrice, TOOL_SESSION } from "@parcha/agentrun-kernel/kernel/cap";
|
|
36
37
|
import { claimModelEnv, claimModelKey, claimSecrets, holdRunKey, keyedAtClaim, withoutModelKeys } from "./claim-secrets.js";
|
|
37
38
|
import { routeOf } from "./model-route.js";
|
|
@@ -172,7 +173,7 @@ export function workflowSpecOf(deps) {
|
|
|
172
173
|
withoutModelKeys(claimedEnv);
|
|
173
174
|
if (runKey && run?.redact)
|
|
174
175
|
holdRunKey(run.redact, runKey);
|
|
175
|
-
const providerOf = deps.providerOf ?? routeProviderOf(claimModelEnv(deps.env ?? process.env, claimedEnv, runKey, claim));
|
|
176
|
+
const providerOf = deps.providerOf ?? routeProviderOf(claimModelEnv(deps.env ?? process.env, [claimedEnv], runKey, claim));
|
|
176
177
|
// Each tier's provider and cap model, resolved once; the proxies start here (before the Harness opens, since the models
|
|
177
178
|
// catalog the Harness takes points at them), their hooks deferred to the booking wired at harnessReady.
|
|
178
179
|
const providers = new Map();
|
|
@@ -6,7 +6,8 @@ import { ApiError, type InputIssue } from "./errors.js";
|
|
|
6
6
|
import { type LearningMode, type Seed, type Shown } from "./learning.js";
|
|
7
7
|
import { type Place } from "./place.js";
|
|
8
8
|
import { type RepoBinding } from "./run-repo.js";
|
|
9
|
-
import { type LaunchDisk, type RunLaunch } from "./run-launch.js";
|
|
9
|
+
import { type HeldRefusal, type LaunchDisk, type RunLaunch } from "./run-launch.js";
|
|
10
|
+
import { type ModelKeyTarget } from "./run-model-key.js";
|
|
10
11
|
import { type ApprovalDecision, type RunMoment } from "./run-view.js";
|
|
11
12
|
import { type LaunchSealed, type NewRevision, type RevisionRow, type RunOrigin, type RunRow, type Store } from "./store/index.js";
|
|
12
13
|
import { type ToolSettingsMap } from "./tool-plane.js";
|
|
@@ -124,11 +125,13 @@ export interface StartDeps {
|
|
|
124
125
|
/** Marks an input refusal as told from a revision (server.ts told). */
|
|
125
126
|
told(error: ApiError): ApiError;
|
|
126
127
|
/** Refuses a revision this host cannot run, by field (server.ts runnable), each tool key the run carries (`carried`, by
|
|
127
|
-
* name) read as one the host holds.
|
|
128
|
+
* name) read as one the host holds. `held`: the run holds its computer (hold: true), so a refusal for its model alone
|
|
129
|
+
* is returned for its launch instead of thrown (computer-held.ts). */
|
|
128
130
|
runnable(revision: Revision, place: Place, options: {
|
|
129
131
|
capped: boolean;
|
|
130
132
|
carried?: readonly string[];
|
|
131
|
-
|
|
133
|
+
held?: boolean;
|
|
134
|
+
}): Promise<HeldRefusal | undefined>;
|
|
132
135
|
/** The revision a run starts on, its MCP tools pinned: one that grants an MCP tool and was saved with no pin (before
|
|
133
136
|
* pins were made at save, or an inline agent's version stored then) is pinned once, at its first run (server.ts
|
|
134
137
|
* pinFirst); any other as it is. */
|
|
@@ -220,8 +223,9 @@ export interface StartDeps {
|
|
|
220
223
|
export interface StartOptions {
|
|
221
224
|
readonly trigger?: RunTrigger;
|
|
222
225
|
/** The run's launch secrets, sealed for its id once it has one (the create body's mcp_auth and model_key, server.ts),
|
|
223
|
-
* given the launch the start prepared
|
|
224
|
-
|
|
226
|
+
* given the launch the start prepared and where its model requests go (run-model-key.ts keyTargetOf), which the sealer
|
|
227
|
+
* may refuse (a model key where the run's model takes none). */
|
|
228
|
+
readonly sealed?: (runId: string, launch: RunLaunch, target: ModelKeyTarget) => Uint8Array | null;
|
|
225
229
|
/** The run's title when its starter names one (a trigger's: "<Source> <name>"), else it is made from its input. */
|
|
226
230
|
readonly title?: string;
|
|
227
231
|
readonly origin?: RunOrigin;
|
|
@@ -229,6 +233,11 @@ export interface StartOptions {
|
|
|
229
233
|
readonly from?: MessageOrigin;
|
|
230
234
|
/** The names of the tool keys the run carries (`keys`, run-keys.ts; their values go only into `sealed`). */
|
|
231
235
|
readonly keys?: readonly string[];
|
|
236
|
+
/** The firing the run starts, in the run's own write (store.runs.create `firing`): a launch hook's host's start. */
|
|
237
|
+
readonly firing?: {
|
|
238
|
+
triggerId: string;
|
|
239
|
+
key: string;
|
|
240
|
+
};
|
|
232
241
|
}
|
|
233
242
|
/** The run's learning start: undefined when the run does not learn (the server's learning off, a workflow revision, or
|
|
234
243
|
* its revision does not say learning), else the seed sha it starts from, its # Learned text (its owner's corrections,
|
|
@@ -250,7 +259,7 @@ export declare function learningStartFor(deps: StartDeps, entry: AgentEntry, rev
|
|
|
250
259
|
* (store.runs.create), which a runner reads at its claim. No process, no door, no setup file: where the run runs is the
|
|
251
260
|
* runner's. Under `origin`, a key that already started a run gets that run (the store's one-run-per-key), so a retry never
|
|
252
261
|
* starts a second. */
|
|
253
|
-
export declare function startRun(store: Store, deps: StartDeps, entry: AgentEntry, body: Json, { trigger, origin, capped, from, title, sealed, keys }?: StartOptions): Promise<RunRow>;
|
|
262
|
+
export declare function startRun(store: Store, deps: StartDeps, entry: AgentEntry, body: Json, { trigger, origin, capped, from, title, sealed, keys, firing }?: StartOptions): Promise<RunRow>;
|
|
254
263
|
/** Writes run `runId` of agent `agentId` with `write`, its files (launch.files) held for it first (StartDeps.files): a
|
|
255
264
|
* hold that fails part way, a write that fails, or one that answers another run (an origin key's run started before),
|
|
256
265
|
* lets go of the hold. In Mode 2 they are placed in the run's folder instead (StartDeps.files.place), and the run is
|
package/dist/runs-over-store.js
CHANGED
|
@@ -16,7 +16,7 @@ import { launchNative } from "./native/connection.js";
|
|
|
16
16
|
import { randomBytes } from "node:crypto";
|
|
17
17
|
import { externalKey, getAgent, ownedElsewhere } from "./agents-store.js";
|
|
18
18
|
import { CAP_TOLERANCE, money } from "./cap.js";
|
|
19
|
-
import { holdOf } from "./computer-held.js";
|
|
19
|
+
import { heldRefused, holdOf } from "./computer-held.js";
|
|
20
20
|
import { computerOfPlace, settingOfDefinition } from "./computer-setting.js";
|
|
21
21
|
import { ApiError, invalid, unsupported } from "./errors.js";
|
|
22
22
|
import { labelsOf } from "./run-labels.js";
|
|
@@ -28,19 +28,19 @@ import { thinkingLevel } from "./model.js";
|
|
|
28
28
|
import { resolvePlace } from "./place.js";
|
|
29
29
|
import { githubTargetOf } from "./github.js";
|
|
30
30
|
import { repoOf } from "./run-repo.js";
|
|
31
|
-
import { launchBody, sourceProjectOf } from "./run-launch.js";
|
|
31
|
+
import { launchBody, readLaunchBody, sourceProjectOf } from "./run-launch.js";
|
|
32
32
|
import { learningDiskOf } from "./learn/learning-of.js";
|
|
33
|
-
import { modelKeyRequired, serverKeyMissing } from "./run-model-key.js";
|
|
33
|
+
import { keyTargetOf, modelKeyRequired, serverKeyMissing } from "./run-model-key.js";
|
|
34
34
|
import { raiseFollowUpId } from "./run-view.js";
|
|
35
35
|
import { sendCommand } from "./runner/commands.js";
|
|
36
36
|
import { refuseWhileNoRunner } from "./runner/presence.js";
|
|
37
|
-
import { RevisionMoved, AgentDeleting, AgentPurged, AgentArchived, AnswerTaken, ExternalBodyConflict, RunFinal, StoreConstraint, StoreLaunchMissing } from "./store/index.js";
|
|
37
|
+
import { RevisionMoved, AgentDeleting, AgentPurged, AgentArchived, AnswerTaken, ExternalBodyConflict, FiringMoved, RunFinal, StoreConstraint, StoreLaunchMissing } from "./store/index.js";
|
|
38
38
|
import { canonical } from "./store/agent-body.js";
|
|
39
39
|
import { sourceSyncOf } from "./source-sync/types.js";
|
|
40
40
|
import { toolingOf } from "./tools.js";
|
|
41
41
|
import { planeFor } from "./tool-plane.js";
|
|
42
42
|
import { declaredKeys, undeclaredKeys, withCarried } from "./run-keys.js";
|
|
43
|
-
import { clip } from "
|
|
43
|
+
import { clip } from "@parcha/agentrun-web";
|
|
44
44
|
import { isObject } from "./validate.js";
|
|
45
45
|
/** Why a message that may not answer a person's question is not sent (runs.ts WAITS_ON_A_PERSON). */
|
|
46
46
|
export const WAITS_ON_A_PERSON = "The run is waiting on a person.";
|
|
@@ -178,6 +178,11 @@ export async function message(store, moment, content, { requestId, answers = tru
|
|
|
178
178
|
throw new ApiError("not_continuable", "Backend SDK runs are single-task sessions. Start a new SDK call for another task.");
|
|
179
179
|
if (nativeOf(launchBody))
|
|
180
180
|
throw new ApiError("input_invalid", "Native jobs do not support in-session steering or follow-up messages. Start a new native run.");
|
|
181
|
+
// A held run its model kept from running at its create never runs its agent: a message would be its first turn (taken at
|
|
182
|
+
// a start, or opening it again once it ended), so it is refused as its start is (computer-held.ts).
|
|
183
|
+
const heldModel = readLaunchBody(launchBody)?.hold?.refused;
|
|
184
|
+
if (heldModel)
|
|
185
|
+
throw heldRefused(heldModel);
|
|
181
186
|
// Archiving closes a run: it, or a run of its archived agent, takes no message, said as archived (never as finished). Another
|
|
182
187
|
// system's agent is archived only by its delete: said so, as every run of it is refused (AgentDeleting).
|
|
183
188
|
const archivedAgent = moment.archived === "agent" ? await store.agents.get(moment.agentId) : null;
|
|
@@ -444,7 +449,7 @@ export async function learningStartFor(deps, entry, revision, rbody, { use = fal
|
|
|
444
449
|
* (store.runs.create), which a runner reads at its claim. No process, no door, no setup file: where the run runs is the
|
|
445
450
|
* runner's. Under `origin`, a key that already started a run gets that run (the store's one-run-per-key), so a retry never
|
|
446
451
|
* starts a second. */
|
|
447
|
-
export async function startRun(store, deps, entry, body, { trigger, origin, capped = false, from, title, sealed, keys } = {}) {
|
|
452
|
+
export async function startRun(store, deps, entry, body, { trigger, origin, capped = false, from, title, sealed, keys, firing } = {}) {
|
|
448
453
|
if (sourceSyncOf(entry.revision?.body)) {
|
|
449
454
|
// Re-delivery of a firing that already admitted a run is not a new start and needs no new project preparation.
|
|
450
455
|
if (origin) {
|
|
@@ -466,11 +471,12 @@ export async function startRun(store, deps, entry, body, { trigger, origin, capp
|
|
|
466
471
|
if (entry.revision?.body?.sdk)
|
|
467
472
|
throw new ApiError("agent_not_runnable", "This agent runs in your backend SDK. Start it through its SDK learning wrapper; AgentRun does not launch its tools or credentials.");
|
|
468
473
|
const { launch, revision } = await prepareLaunch(deps, entry, body, { ...(trigger ? { trigger } : {}), capped, ...(from ? { from } : {}), ...(title !== undefined ? { title } : {}), ...(keys ? { keys } : {}) });
|
|
469
|
-
|
|
474
|
+
const target = keyTargetOf(deps.planeEnv(), launch, revision);
|
|
475
|
+
keyedOrRefused(deps, target, sealed);
|
|
470
476
|
const runId = (deps.newRunId ?? uuidv7)();
|
|
471
477
|
try {
|
|
472
478
|
const labels = labelsOf(body.labels);
|
|
473
|
-
return await withHeldFiles(store, deps, runId, entry.agent.id, revision, launch, (launch) => store.runs.create({ id: runId, agentId: entry.agent.id, revisionId: revision.id, expectedCurrent: entry.agent.currentRevision, ...(origin ? { origin } : {}), ...(labels ? { labels } : {}) }, { body: launchBody(launch), ...(sealed ? { sealed: sealed(runId, launch,
|
|
479
|
+
return await withHeldFiles(store, deps, runId, entry.agent.id, revision, launch, (launch) => store.runs.create({ id: runId, agentId: entry.agent.id, revisionId: revision.id, expectedCurrent: entry.agent.currentRevision, ...(origin ? { origin } : {}), ...(labels ? { labels } : {}), ...(firing ? { firing } : {}) }, { body: launchBody(launch), ...(sealed ? { sealed: sealed(runId, launch, target) } : {}) }));
|
|
474
480
|
}
|
|
475
481
|
catch (error) {
|
|
476
482
|
if (error instanceof RevisionMoved)
|
|
@@ -487,9 +493,10 @@ export async function startRun(store, deps, entry, body, { trigger, origin, capp
|
|
|
487
493
|
}
|
|
488
494
|
/** A start with no launch secrets (`sealed`: a trigger's firing, a learning batch's row) whose route goes to the model
|
|
489
495
|
* gateway, on a server that holds no key for it (run-model-key.ts serverKeyMissing): 422 model_key_required, nothing
|
|
490
|
-
* written, never a failure at its first model call. A start with them (the API's) is the sealer's to check.
|
|
491
|
-
|
|
492
|
-
|
|
496
|
+
* written, never a failure at its first model call. A start with them (the API's) is the sealer's to check. `target`:
|
|
497
|
+
* the run's (run-model-key.ts keyTargetOf), a held run's whose model was refused at its create among them. */
|
|
498
|
+
function keyedOrRefused(deps, target, sealed) {
|
|
499
|
+
if (!sealed && serverKeyMissing(deps.planeEnv(), target))
|
|
493
500
|
throw modelKeyRequired(false);
|
|
494
501
|
}
|
|
495
502
|
/** Writes run `runId` of agent `agentId` with `write`, its files (launch.files) held for it first (StartDeps.files): a
|
|
@@ -578,8 +585,10 @@ export async function withHeldFiles(store, deps, runId, agentId, revision, launc
|
|
|
578
585
|
knownAbsent = true;
|
|
579
586
|
}
|
|
580
587
|
catch { /* preserve preparation until the admission can be resolved */ }
|
|
588
|
+
// A refusal the store gave in the run's own transaction (a host start whose firing was released meanwhile: FiringMoved)
|
|
589
|
+
// wrote nothing, so the run never exists and its preparation goes.
|
|
581
590
|
if (knownAbsent && (error instanceof StoreConstraint || error instanceof RevisionMoved || error instanceof AgentDeleting
|
|
582
|
-
|| error instanceof AgentPurged || error instanceof AgentArchived || error instanceof ExternalBodyConflict || error instanceof ApiError))
|
|
591
|
+
|| error instanceof AgentPurged || error instanceof AgentArchived || error instanceof ExternalBodyConflict || error instanceof FiringMoved || error instanceof ApiError))
|
|
583
592
|
await undo(true);
|
|
584
593
|
throw error;
|
|
585
594
|
}
|
|
@@ -673,7 +682,8 @@ async function startInlineOnce(store, deps, inline, body, { origin, sealed, keys
|
|
|
673
682
|
// A store revision is the revision the run path reads as a pi Revision (its body is the revision body), as pinnedOf hands
|
|
674
683
|
// one across.
|
|
675
684
|
const { launch } = await prepareLaunch(deps, entry, body, { revision: (storedRevision ?? revision), ...(keys ? { keys } : {}) });
|
|
676
|
-
|
|
685
|
+
const target = keyTargetOf(deps.planeEnv(), launch, storedRevision ?? revision);
|
|
686
|
+
keyedOrRefused(deps, target, sealed);
|
|
677
687
|
const runId = (deps.newRunId ?? uuidv7)();
|
|
678
688
|
const labels = labelsOf(body.labels);
|
|
679
689
|
try {
|
|
@@ -681,7 +691,7 @@ async function startInlineOnce(store, deps, inline, body, { origin, sealed, keys
|
|
|
681
691
|
agent: { id: entry.agent.id, name: inline.name, description: inline.description, ref },
|
|
682
692
|
revision: { id: revision.id, version: external.version, kind: revision.kind, body: revision.body, skills: revision.skills, ...(revision.note !== undefined ? { note: revision.note } : {}), ...(revision.mcpPin !== undefined ? { mcpPin: revision.mcpPin } : {}), ...(revision.monidPin !== undefined ? { monidPin: revision.monidPin } : {}) },
|
|
683
693
|
run: { id: runId, ...(origin ? { origin } : {}), ...(labels ? { labels } : {}) },
|
|
684
|
-
launch: { body: launchBody(launch), ...(sealed ? { sealed: sealed(runId, launch,
|
|
694
|
+
launch: { body: launchBody(launch), ...(sealed ? { sealed: sealed(runId, launch, target) } : {}) },
|
|
685
695
|
}));
|
|
686
696
|
}
|
|
687
697
|
catch (error) {
|
|
@@ -747,17 +757,18 @@ export async function prepareLaunch(deps, entry, body, { trigger, capped = false
|
|
|
747
757
|
if (refused !== undefined)
|
|
748
758
|
throw new ApiError("runner_refused", refused);
|
|
749
759
|
const place = resolvePlace(rbody.place, deps.fallbackPlace(revision.kind, revision.kind === "agentic" ? (rbody.tools ?? []) : []));
|
|
750
|
-
// Checked as pinned: an earlier revision with no pin is pinned now, once (StartDeps.pinFirst); one that could not be, as
|
|
751
|
-
// its server could not be listed, is refused with the rest (runnable).
|
|
752
|
-
await deps.runnable(deps.pinFirst ? await deps.pinFirst(revision) : revision, place, { capped: cap !== undefined, carried });
|
|
753
760
|
// A held computer (computer-held.ts): only one that speaks the protocol, its kind as the claim reads it (the
|
|
754
|
-
// revision's computer, else its place's).
|
|
761
|
+
// revision's computer, else its place's). Read before the run's check, which defers a held run's model refusal.
|
|
755
762
|
const hold = holdOf(body, (settingOfDefinition(rbody)?.computer ?? computerOfPlace(place)).kind);
|
|
756
763
|
if (hold !== undefined && "field" in hold)
|
|
757
764
|
throw invalid([hold]);
|
|
758
765
|
// A workflow's loop opens no held computer and takes no start or release: its run holds nothing.
|
|
759
766
|
if (hold !== undefined && revision.kind === "workflow")
|
|
760
767
|
throw invalid([{ field: "hold", reason: "not_an_option", message: "hold is for an agent's run: a workflow run does not hold its computer for its owner." }]);
|
|
768
|
+
// Checked as pinned: an earlier revision with no pin is pinned now, once (StartDeps.pinFirst); one that could not be, as
|
|
769
|
+
// its server could not be listed, is refused with the rest (runnable). A held run kept from running by its model alone
|
|
770
|
+
// is not refused: those words ride its hold, for its start to answer (computer-held.ts).
|
|
771
|
+
const modelRefused = await deps.runnable(deps.pinFirst ? await deps.pinFirst(revision) : revision, place, { capped: cap !== undefined, carried, held: hold !== undefined });
|
|
761
772
|
// The title shows on the run's page, the runs list and Mission Control: built from its input as shown, each held value
|
|
762
773
|
// redacted before a long one is cut (a cut key could no longer be found).
|
|
763
774
|
const shown = redactedOutput(input, deps.serverSecrets());
|
|
@@ -768,8 +779,9 @@ export async function prepareLaunch(deps, entry, body, { trigger, capped = false
|
|
|
768
779
|
// the run carries resolves a tool as one the host holds would.
|
|
769
780
|
const tooling = await toolingOf(revision);
|
|
770
781
|
const plane = tooling ? planeFor(withCarried(deps.planeEnv(), carried), tooling, deps.toolSettings(), { capped: cap !== undefined, run: true }) : {};
|
|
771
|
-
// The run's model, resolved once, at start (the runner reads launch.model only).
|
|
772
|
-
|
|
782
|
+
// The run's model, resolved once, at start (the runner reads launch.model only). None for a held run whose model was
|
|
783
|
+
// refused: resolving it would throw those words, and its claim takes the stand-in on its revision's model (computer-held.ts).
|
|
784
|
+
const model = modelRefused ? undefined : await deps.modelOf(entry, revision);
|
|
773
785
|
// The run's Archil disk, chosen now and kept in its launch (run-launch.ts archilDisk): the one the body names (a disk per
|
|
774
786
|
// customer), else its agent's when it has one; with neither, its claim makes the agent's.
|
|
775
787
|
const named = isObject(body.archil_disk) && typeof body.archil_disk.disk_id === "string" ? body.archil_disk.disk_id : undefined;
|
|
@@ -815,7 +827,7 @@ export async function prepareLaunch(deps, entry, body, { trigger, capped = false
|
|
|
815
827
|
...(from ? { inputOrigin: from } : {}),
|
|
816
828
|
...(model ? { model } : {}),
|
|
817
829
|
...(archilDisk ? { archilDisk } : {}),
|
|
818
|
-
...(hold ? { hold } : {}),
|
|
830
|
+
...(hold ? { hold: modelRefused ? { ...hold, refused: modelRefused } : hold } : {}),
|
|
819
831
|
};
|
|
820
832
|
return { launch, revision };
|
|
821
833
|
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { SignInReader } from "./run-view.js";
|
|
2
|
+
import { type Store } from "./store/index.js";
|
|
3
|
+
/** The kinds of cut, in the order they are printed (secret-rules.ts CutKind). */
|
|
4
|
+
export declare const CUT_KINDS: readonly ["format", "held", "dump", "label", "personal", "jev"];
|
|
5
|
+
type Kind = (typeof CUT_KINDS)[number];
|
|
6
|
+
/** The run view's fields a share carries (share-design §1, the `run` allowlist, store-view.ts viewOfRun); every other
|
|
7
|
+
* field is dropped. `imported_from` carries its `source` alone. */
|
|
8
|
+
export declare const SHARE_RUN_FIELDS: readonly ["kind", "status", "state", "title", "created_at", "ended_at", "result", "error", "review", "cost", "stopped_for", "budget_refused_calls", "effort", "approvals"];
|
|
9
|
+
/** The reads a share's text is gathered by: the run's one cut (run-cut.ts runCutValues) and what serves under it. */
|
|
10
|
+
export interface ShareTextDeps {
|
|
11
|
+
readonly serverSecrets: () => string[];
|
|
12
|
+
readonly signIns?: SignInReader;
|
|
13
|
+
/** The store's seal key, undefined when it has none: the run's sealed launch values are read under it (run-cut.ts). */
|
|
14
|
+
readonly sealKey: Buffer | undefined;
|
|
15
|
+
readonly keyEnv: () => NodeJS.ProcessEnv;
|
|
16
|
+
}
|
|
17
|
+
/** Every string in a JSON value, its object keys included (a key can hold a value: a header's name a tool printed, a
|
|
18
|
+
* map keyed by a command line). */
|
|
19
|
+
export declare function stringsOf(value: unknown): string[];
|
|
20
|
+
/** A tool's output with its call's context (ruling LVI): the file the call read whole (`path`) or the shell command it
|
|
21
|
+
* ran (`command`), so the scrubber reads a credential file's or a dump command's output as the dump it is, though the
|
|
22
|
+
* output stands alone in its result's field. A share's export reads the same (secret-cut.ts ScrubOptions). */
|
|
23
|
+
export interface ShareText {
|
|
24
|
+
readonly text: string;
|
|
25
|
+
readonly path?: string;
|
|
26
|
+
readonly command?: string;
|
|
27
|
+
}
|
|
28
|
+
/** What a share of run `runId` would carry, as strings (object keys included: stringsOf), a tool's output with its
|
|
29
|
+
* call's context (ShareText), with the run's cut set read after them (the cut only grows, so the last read holds every
|
|
30
|
+
* value an earlier read cut); `unknown` for a run the store does not hold, `withheld` when its cut can't be read here. */
|
|
31
|
+
export declare function shareTexts(store: Store, runId: string, deps: ShareTextDeps): Promise<{
|
|
32
|
+
kind: string;
|
|
33
|
+
texts: (string | ShareText)[];
|
|
34
|
+
held: string[];
|
|
35
|
+
} | "unknown" | "withheld">;
|
|
36
|
+
/** One rule's line of the count. */
|
|
37
|
+
export interface RuleCount {
|
|
38
|
+
readonly rule: string;
|
|
39
|
+
readonly kind: string;
|
|
40
|
+
readonly restorable: boolean;
|
|
41
|
+
readonly count: number;
|
|
42
|
+
}
|
|
43
|
+
/** The count `scrub` prints: by rule, by kind, the cuts a share would make and how many of them could be restored, and
|
|
44
|
+
* how many `[redacted]` marks the served text holds already (known key formats and held values the server's own cut takes
|
|
45
|
+
* out where it serves the run, run-view.ts shownOf, or keys an import took out before). */
|
|
46
|
+
export interface ShareCount {
|
|
47
|
+
readonly run_id: string;
|
|
48
|
+
readonly kind: string;
|
|
49
|
+
readonly strings: number;
|
|
50
|
+
readonly rules: RuleCount[];
|
|
51
|
+
readonly by_kind: Record<Kind, number>;
|
|
52
|
+
readonly cuts: number;
|
|
53
|
+
readonly restorable: number;
|
|
54
|
+
readonly already_redacted: number;
|
|
55
|
+
/** Whether a share would be refused: cut mode fails closed on one of the strings (its final check finds a held value or
|
|
56
|
+
* a format left once cut), so no share of this run is made until a rule cuts it. */
|
|
57
|
+
readonly blocked: boolean;
|
|
58
|
+
}
|
|
59
|
+
/** The scrubber's count over `texts` with `held` as its held values, a ShareText with its call's context: each cut's
|
|
60
|
+
* rule, kind and whether it can be restored, never its value, shape or offsets. */
|
|
61
|
+
export declare function countCuts(runId: string, kind: string, texts: readonly (string | ShareText)[], held: readonly string[]): Promise<ShareCount>;
|
|
62
|
+
/** The count as a table: one line per rule, totals by kind, and the line that says what a share would cut. */
|
|
63
|
+
export declare function countTable(count: ShareCount): string;
|
|
64
|
+
/** The line that says a run could not be counted: the error's own words, cut by the scrubber first with `held` as its
|
|
65
|
+
* held values (a store's error could quote what it read, a held value among it), else withheld. */
|
|
66
|
+
export declare function couldNotCount(runId: string, error: unknown, held: readonly string[]): Promise<string>;
|
|
67
|
+
/** `agentrun-serve scrub RUN [--data DIR] [--json]`: the exit code (the file's head). Output goes to `out`, words about
|
|
68
|
+
* why nothing was counted to `err`. */
|
|
69
|
+
export declare function scrubMain(argv: readonly string[], usage: string, io?: {
|
|
70
|
+
out: (line: string) => void;
|
|
71
|
+
err: (line: string) => void;
|
|
72
|
+
}): Promise<number>;
|
|
73
|
+
export {};
|