@parcha/agentrun-serve 0.1.0-beta.35 → 0.1.0-beta.36
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 +128 -0
- package/README.md +260 -168
- package/dist/adapters.d.ts +12 -2
- package/dist/adapters.js +27 -2
- package/dist/agent-rows.d.ts +2 -1
- package/dist/agents-store.d.ts +2 -0
- package/dist/agents-store.js +9 -4
- package/dist/api-only.d.ts +2 -1
- package/dist/api-only.js +3 -1
- package/dist/archil-routes.d.ts +40 -7
- package/dist/archil-routes.js +167 -54
- package/dist/archil-settings.d.ts +79 -7
- package/dist/archil-settings.js +140 -14
- package/dist/attach-images.d.ts +15 -0
- package/dist/attach-images.js +59 -0
- package/dist/background.d.ts +0 -6
- package/dist/background.js +0 -28
- package/dist/box-image.d.ts +1 -97
- package/dist/box-image.js +4 -284
- package/dist/box-paths.d.ts +2 -7
- package/dist/box-paths.js +7 -13
- package/dist/box-settings.d.ts +0 -11
- package/dist/box-settings.js +4 -29
- package/dist/browser-commands.js +1 -1
- package/dist/browser-computer.d.ts +47 -3
- package/dist/browser-computer.js +286 -18
- package/dist/browser-person.d.ts +19 -2
- package/dist/browser-person.js +55 -6
- package/dist/browser-wait-ended.d.ts +23 -0
- package/dist/browser-wait-ended.js +42 -0
- package/dist/cap.d.ts +13 -41
- package/dist/cap.js +24 -73
- package/dist/cli.js +4 -22
- package/dist/computer-routes.d.ts +1 -4
- package/dist/computer-routes.js +3 -5
- package/dist/computer-setting.d.ts +2 -0
- package/dist/computer-setting.js +38 -1
- package/dist/computer-view.d.ts +11 -2
- package/dist/computer-view.js +2 -1
- package/dist/computers.d.ts +48 -7
- package/dist/computers.js +100 -23
- package/dist/console/assets/index-BI4Byidu.js +550 -0
- package/dist/console/assets/index-C19gUF2n.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/docker-daemon.d.ts +2 -2
- package/dist/docker-daemon.js +2 -2
- package/dist/errors.js +5 -5
- package/dist/faux-computers.js +4 -0
- package/dist/files.d.ts +1 -9
- package/dist/files.js +1 -9
- package/dist/github.d.ts +22 -2
- package/dist/github.js +42 -8
- package/dist/gpu-words.d.ts +14 -0
- package/dist/gpu-words.js +21 -0
- package/dist/graph-view.d.ts +2 -0
- package/dist/graph-view.js +25 -1
- package/dist/handed-values.d.ts +1 -1
- package/dist/handed-values.js +1 -1
- package/dist/harness-install.d.ts +60 -3
- package/dist/harness-install.js +322 -34
- package/dist/harness.js +1 -1
- package/dist/host-tools.d.ts +8 -9
- package/dist/host-tools.js +7 -7
- package/dist/index.d.ts +1 -3
- package/dist/index.js +1 -2
- package/dist/key-refusal.d.ts +1 -1
- package/dist/key-refusal.js +2 -2
- package/dist/learn/check.d.ts +7 -1
- package/dist/learn/check.js +123 -5
- package/dist/learn/commit.d.ts +40 -6
- package/dist/learn/commit.js +164 -20
- package/dist/learn/folder.d.ts +5 -0
- package/dist/learn/folder.js +33 -0
- package/dist/learn/grade.d.ts +18 -1
- package/dist/learn/grade.js +86 -16
- package/dist/learn/index.d.ts +1 -1
- package/dist/learn/index.js +1 -1
- package/dist/learn/learning.sh +12 -1
- package/dist/learn/notes.d.ts +3 -0
- package/dist/learn/notes.js +3 -0
- package/dist/learn/reflect.d.ts +5 -2
- package/dist/learn/reflect.js +43 -29
- package/dist/learn/skills.d.ts +4 -0
- package/dist/learn/skills.js +7 -0
- package/dist/learned-nodes.d.ts +6 -2
- package/dist/learned-workflow.d.ts +19 -9
- package/dist/learned-workflow.js +62 -34
- package/dist/learning-cost.d.ts +79 -0
- package/dist/learning-cost.js +69 -0
- package/dist/learning-routes.d.ts +8 -3
- package/dist/learning-routes.js +9 -6
- package/dist/learning-words.d.ts +3 -0
- package/dist/learning-words.js +6 -2
- package/dist/learning.d.ts +13 -6
- package/dist/learning.js +4 -2
- package/dist/mcp-probe.d.ts +8 -1
- package/dist/mcp-probe.js +62 -20
- package/dist/mcp-secret-writes.js +4 -0
- package/dist/mcp-servers-store.js +8 -3
- package/dist/model.d.ts +5 -5
- package/dist/model.js +6 -6
- package/dist/openapi.d.ts +2 -0
- package/dist/openapi.js +204 -47
- package/dist/owner.d.ts +0 -1
- package/dist/owner.js +0 -2
- package/dist/paid-calls.js +1 -1
- package/dist/place-offers.d.ts +97 -0
- package/dist/place-offers.js +206 -0
- package/dist/place.d.ts +9 -13
- package/dist/place.js +22 -32
- package/dist/port-models.d.ts +2 -1
- package/dist/port-models.js +5 -3
- package/dist/print.d.ts +1 -8
- package/dist/print.js +1 -14
- package/dist/propose.d.ts +1 -0
- package/dist/propose.js +25 -10
- package/dist/run-cut.d.ts +5 -0
- package/dist/run-cut.js +19 -0
- package/dist/run-db.js +3 -3
- package/dist/run-launch.d.ts +14 -1
- package/dist/run-launch.js +7 -2
- package/dist/run-learning-served.d.ts +1 -1
- package/dist/run-manifest.d.ts +2 -2
- package/dist/run-manifest.js +2 -2
- package/dist/run-secrets.js +3 -3
- package/dist/run-timeline-served.js +56 -44
- package/dist/run-view.d.ts +5 -2
- package/dist/run-view.js +4 -3
- package/dist/runnable.d.ts +2 -2
- package/dist/runnable.js +6 -2
- package/dist/runner/adapter-loop.d.ts +16 -1
- package/dist/runner/adapter-loop.js +131 -30
- package/dist/runner/adapter-run-spec.d.ts +25 -4
- package/dist/runner/adapter-run-spec.js +103 -24
- package/dist/runner/adapters/pi.d.ts +11 -3
- package/dist/runner/adapters/pi.js +35 -12
- package/dist/runner/beside.js +6 -2
- package/dist/runner/cli-run-spec.d.ts +7 -0
- package/dist/runner/cli-run-spec.js +92 -38
- package/dist/runner/commands.d.ts +5 -1
- package/dist/runner/commands.js +3 -3
- package/dist/runner/conformance/harness.d.ts +0 -1
- package/dist/runner/conformance/harness.js +8 -5
- package/dist/runner/github-app.js +2 -2
- package/dist/runner/harness-loops.js +1 -1
- package/dist/runner/journal-kinds.d.ts +15 -5
- package/dist/runner/journal-kinds.js +6 -1
- package/dist/runner/learning-end.d.ts +15 -0
- package/dist/runner/learning-end.js +26 -5
- package/dist/runner/learning-factory.js +6 -2
- package/dist/runner/learning-loop.d.ts +73 -1
- package/dist/runner/learning-loop.js +203 -18
- package/dist/runner/learning-seed.d.ts +2 -0
- package/dist/runner/learning-seed.js +1 -1
- package/dist/runner/loop-contract.d.ts +8 -0
- package/dist/runner/loop-contract.js +6 -0
- package/dist/runner/loop.d.ts +5 -1
- package/dist/runner/loop.js +20 -0
- package/dist/runner/main.js +12 -2
- package/dist/runner/mcp-claim.d.ts +4 -0
- package/dist/runner/mcp-claim.js +29 -1
- package/dist/runner/mcp-github.d.ts +4 -2
- package/dist/runner/mcp-github.js +0 -7
- package/dist/runner/mcp-run.d.ts +2 -0
- package/dist/runner/mcp-run.js +1 -0
- package/dist/runner/metrics.d.ts +4 -0
- package/dist/runner/metrics.js +9 -0
- package/dist/runner/model-route.d.ts +3 -0
- package/dist/runner/model-route.js +5 -2
- package/dist/runner/pr-checkout.d.ts +59 -0
- package/dist/runner/pr-checkout.js +176 -0
- package/dist/runner/reflect-hook.d.ts +1 -0
- package/dist/runner/reflect-hook.js +3 -3
- package/dist/runner/runner.js +47 -12
- package/dist/runner/spec-holds.d.ts +8 -3
- package/dist/runner/spec-holds.js +12 -10
- package/dist/runner/store-port.d.ts +4 -1
- package/dist/runner/store-secrets.js +17 -1
- package/dist/runner/subagent.d.ts +44 -0
- package/dist/runner/subagent.js +188 -0
- package/dist/runner/workflow-host.d.ts +18 -2
- package/dist/runner/workflow-host.js +23 -3
- package/dist/runner/workflow-loop.d.ts +5 -2
- package/dist/runner/workflow-loop.js +9 -8
- package/dist/runner/workflow-spec.d.ts +26 -14
- package/dist/runner/workflow-spec.js +97 -30
- package/dist/runs-over-store.d.ts +11 -6
- package/dist/runs-over-store.js +111 -24
- package/dist/sealing.js +1 -2
- package/dist/secret-cut.d.ts +1 -1
- package/dist/secret-cut.js +1 -1
- package/dist/server.d.ts +32 -49
- package/dist/server.js +249 -199
- package/dist/store/agent-body.d.ts +9 -2
- package/dist/store/agent-body.js +16 -8
- package/dist/store/deadline.js +9 -5
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +2 -2
- package/dist/store/journal/storage.js +2 -1
- package/dist/store/postgres/connection.js +9 -4
- package/dist/store/postgres/migrations/0004_runs_outcome_stop_or_cancel.sql +11 -0
- package/dist/store/schema.d.ts +2 -1
- package/dist/store/schema.js +11 -8
- package/dist/store/seal.d.ts +13 -0
- package/dist/store/seal.js +19 -0
- package/dist/store/sqlite/connection.d.ts +5 -0
- package/dist/store/sqlite/connection.js +88 -47
- package/dist/store/sqlite/run-patch.d.ts +18 -2
- package/dist/store/sqlite/run-patch.js +31 -2
- package/dist/store/sqlite/store.js +65 -11
- package/dist/store/store.d.ts +62 -12
- package/dist/store/store.js +22 -1
- package/dist/store-reads/analytics.js +3 -2
- package/dist/store-reads/cap.d.ts +1 -3
- package/dist/store-reads/cap.js +8 -6
- package/dist/store-reads/decisions.d.ts +2 -2
- package/dist/store-reads/decisions.js +3 -6
- package/dist/store-reads/journal.js +45 -12
- package/dist/store-reads/learning.d.ts +15 -1
- package/dist/store-reads/learning.js +68 -10
- package/dist/store-reads/runs.d.ts +6 -4
- package/dist/store-reads/runs.js +17 -10
- package/dist/store-reads/stats.js +5 -1
- package/dist/store-view.js +45 -19
- package/dist/template-eval.js +2 -1
- package/dist/templates.d.ts +64 -0
- package/dist/templates.js +101 -16
- package/dist/timeline/timeline.d.ts +3 -1
- package/dist/timeline/timeline.js +19 -4
- package/dist/tool-blurbs.js +1 -0
- package/dist/tool-budget.d.ts +8 -0
- package/dist/tool-budget.js +7 -1
- package/dist/tool-gate.d.ts +7 -1
- package/dist/tool-gate.js +7 -2
- package/dist/tool-plane.d.ts +33 -19
- package/dist/tool-plane.js +64 -27
- package/dist/tools.d.ts +18 -34
- package/dist/tools.js +104 -70
- package/dist/trigger-signatures.d.ts +1 -0
- package/dist/trigger-signatures.js +3 -1
- package/dist/triggers.d.ts +3 -3
- package/dist/triggers.js +2 -2
- package/dist/turn-end.d.ts +0 -3
- package/dist/turn-end.js +0 -3
- package/dist/usage-lines.d.ts +1 -1
- package/dist/validate.d.ts +6 -0
- package/dist/validate.js +30 -3
- package/dist/webhooks.d.ts +2 -1
- package/dist/webhooks.js +5 -2
- package/dist/workflow/decision-recovery.d.ts +23 -0
- package/dist/workflow/decision-recovery.js +80 -0
- package/dist/workflow/decisions.d.ts +134 -0
- package/dist/workflow/decisions.js +46 -0
- package/dist/workflow/host-session.d.ts +5 -0
- package/dist/workflow/host-session.js +85 -0
- package/dist/workflow/host-tools.d.ts +3 -0
- package/dist/workflow/host-tools.js +3 -0
- package/dist/workflow/node-runner.d.ts +112 -0
- package/dist/workflow/node-runner.js +270 -0
- package/dist/workflow/node.d.ts +88 -0
- package/dist/workflow/node.js +99 -0
- package/dist/workflow/operator-error.d.ts +4 -0
- package/dist/workflow/operator-error.js +4 -0
- package/dist/workflow/pi-versions.d.ts +9 -0
- package/dist/workflow/pi-versions.js +8 -0
- package/dist/workflow/readers.d.ts +36 -0
- package/dist/workflow/readers.js +145 -0
- package/dist/workflow/record-file.d.ts +10 -0
- package/dist/workflow/record-file.js +56 -0
- package/dist/workflow/record-tool.d.ts +76 -0
- package/dist/workflow/record-tool.js +126 -0
- package/dist/workflow/record.d.ts +151 -0
- package/dist/workflow/record.js +401 -0
- package/dist/workflow/run-error.d.ts +16 -0
- package/dist/workflow/run-error.js +26 -0
- package/dist/workflow/runner.d.ts +6 -0
- package/dist/workflow/runner.js +240 -0
- package/dist/workflow/store.d.ts +23 -0
- package/dist/workflow/store.js +242 -0
- package/dist/workflow/task.d.ts +133 -0
- package/dist/workflow/task.js +411 -0
- package/dist/workflow/thinking.d.ts +3 -0
- package/dist/workflow/thinking.js +7 -0
- package/dist/workflow/tool-context.d.ts +21 -0
- package/dist/workflow/tool-context.js +13 -0
- package/dist/workflow/types.d.ts +126 -0
- package/dist/workflow/types.js +1 -0
- package/dist/workflow/wal.d.ts +11 -0
- package/dist/workflow/wal.js +106 -0
- package/dist/workflow-run.d.ts +1 -1
- package/dist/workspace/agent-computer.d.ts +137 -0
- package/dist/workspace/agent-computer.js +292 -0
- package/dist/workspace/archil-claim.d.ts +11 -0
- package/dist/workspace/archil-claim.js +18 -10
- package/dist/workspace/archil-disks.d.ts +49 -0
- package/dist/workspace/archil-disks.js +185 -0
- package/dist/workspace/archil-exec.js +2 -3
- package/dist/workspace/archil-mount-credential.d.ts +20 -4
- package/dist/workspace/archil-mount-credential.js +13 -4
- package/dist/workspace/computer-deps.d.ts +16 -8
- package/dist/workspace/computer-deps.js +18 -7
- package/dist/workspace/computer-for-claim.d.ts +42 -6
- package/dist/workspace/computer-for-claim.js +209 -9
- package/dist/workspace/computer-janitor.d.ts +3 -2
- package/dist/workspace/computer-janitor.js +43 -9
- package/dist/workspace/computer-ledger.d.ts +3 -1
- package/dist/workspace/computer-ledger.js +7 -0
- package/dist/workspace/index.d.ts +3 -2
- package/dist/workspace/index.js +1 -0
- package/dist/workspace/resolve-computer.d.ts +42 -11
- package/dist/workspace/resolve-computer.js +65 -13
- package/dist/workspace/run-disk.d.ts +34 -0
- package/dist/workspace/run-disk.js +91 -0
- package/dist/workspace/run-tools.d.ts +4 -4
- package/dist/workspace/run-tools.js +8 -6
- package/dist/workspace/server-run-workspace.d.ts +3 -2
- package/dist/workspace/server-run-workspace.js +17 -4
- package/dist/workspace.js +1 -1
- package/package.json +10 -15
- package/templates/README.md +9 -6
- package/templates/code-review/agent.md +27 -11
- package/templates/code-review/evals/clean-refactor/graders/coverage.md +4 -0
- package/templates/code-review/evals/clean-refactor/graders/risk.md +5 -0
- package/templates/code-review/evals/injection/graders/ignores.md +1 -1
- package/templates/code-review/evals/never-flag/case.yaml +3 -0
- package/templates/code-review/evals/never-flag/graders/only-p0.md +4 -0
- package/templates/code-review/evals/never-flag/graders/schema.md +5 -0
- package/templates/code-review/evals/never-flag/prompt.md +30 -0
- package/templates/code-review/evals/null-name/graders/finds.md +1 -1
- package/templates/code-review/evals/off-by-one/graders/finds.md +1 -1
- package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +6 -5
- package/templates/code-review/evals/re-review/graders/resolves.md +1 -1
- package/templates/code-review/evals/re-review/prompt.md +1 -1
- package/templates/code-review/evals/re-review-open/case.yaml +3 -0
- package/templates/code-review/evals/re-review-open/graders/schema.md +5 -0
- package/templates/code-review/evals/re-review-open/graders/stays-open.md +4 -0
- package/templates/code-review/evals/re-review-open/prompt.md +27 -0
- package/templates/code-review/evals/repo-rule/graders/cites.md +1 -1
- package/templates/code-review/evals/two-defects/case.yaml +3 -0
- package/templates/code-review/evals/two-defects/graders/both.md +4 -0
- package/templates/code-review/evals/two-defects/graders/schema.md +5 -0
- package/templates/code-review/evals/two-defects/prompt.md +25 -0
- package/templates/code-review/findings.schema.json +131 -27
- package/templates/code-review/rules/CODEREVIEW.md +76 -0
- package/templates/code-review/skills/review/DEEP.md +130 -0
- package/templates/code-review/skills/review/REVIEWER.md +116 -0
- package/templates/code-review/skills/review/SKILL.md +104 -154
- package/dist/box/record.d.ts +0 -6
- package/dist/box/record.js +0 -41
- package/dist/box/sweep.d.ts +0 -53
- package/dist/box/sweep.js +0 -193
- package/dist/box-egress-vm.d.ts +0 -118
- package/dist/box-egress-vm.js +0 -354
- package/dist/box-egress.d.ts +0 -105
- package/dist/box-egress.js +0 -256
- package/dist/box-relay-vm.d.ts +0 -84
- package/dist/box-relay-vm.js +0 -437
- package/dist/box-relay.d.ts +0 -36
- package/dist/box-relay.js +0 -207
- package/dist/boxes.d.ts +0 -109
- package/dist/boxes.js +0 -249
- package/dist/budget.d.ts +0 -71
- package/dist/budget.js +0 -199
- package/dist/console/assets/index-B7NKTU8E.css +0 -1
- package/dist/console/assets/index-CXZMgJE7.js +0 -550
- package/dist/daytona-api.d.ts +0 -10
- package/dist/daytona-api.js +0 -20
- package/dist/egress-proxy.d.ts +0 -45
- package/dist/egress-proxy.js +0 -416
- package/dist/egress-table.d.ts +0 -24
- package/dist/egress-table.js +0 -165
- package/templates/code-review/rules/REVIEW.md +0 -41
package/dist/cap.d.ts
CHANGED
|
@@ -84,7 +84,7 @@ export declare function wrapUpDue(cap: number, spent: number, held: number, typi
|
|
|
84
84
|
/** The wrap-up's words, what is left to the cent. `nonePriced`: the run's own model has no priced request yet, so its
|
|
85
85
|
* typical cost is the next request's expected cost and the note can come before the run has done anything (step 0):
|
|
86
86
|
* the words say the budget and ask for a short answer, not a finish. Read from the same priced costs live and in a
|
|
87
|
-
* process opened again (
|
|
87
|
+
* process opened again (ownCosts), so a restart picks the same words. */
|
|
88
88
|
export declare const wrapUpWords: (leftUsd: number, nonePriced?: boolean) => string;
|
|
89
89
|
/** A request priced at `price` under `mode`, its input `bound` tokens after `previous` at `now`, plus `feeUsd`: `cost`, what
|
|
90
90
|
* it is held at given its output tokens (its expected input, never more than uncached), and `worst`, its input uncached.
|
|
@@ -167,7 +167,7 @@ export declare const attemptLost: (a: Attempt, last: boolean) => boolean;
|
|
|
167
167
|
export declare const anyAttemptLost: (attempts: readonly Attempt[] | undefined) => boolean;
|
|
168
168
|
export declare function piEnded(message: Pick<AssistantMessage, "stopReason" | "usage" | "api">, began: boolean, attempts: readonly Attempt[] | undefined): Ended;
|
|
169
169
|
/** How pi's error for a request whose start mark could not be written begins (request-start.ts builds it from this): the
|
|
170
|
-
* request never left, so the entry answers none, and
|
|
170
|
+
* request never left, so the entry answers none, and spentFrom leaves it out by this. */
|
|
171
171
|
export declare const MARK_NOT_WRITTEN = "the model request was not sent: its mark could not be written";
|
|
172
172
|
/** pi's error for a request that left and whose end mark the store refused (request-start.ts): its cost is not recorded
|
|
173
173
|
* as booked, so it stays open, read at its start mark's hold, never closed by this entry at its own usage. */
|
|
@@ -194,19 +194,8 @@ export declare const CAP_REFUSAL_PREFIX: RegExp;
|
|
|
194
194
|
* before its end), and the usd of a cost written apart from an answer, a paid tool's charge among them; 0 for anything
|
|
195
195
|
* else, or for a cost that is not a number (which makes the whole spend unknown, by the timeline's verdict). */
|
|
196
196
|
export declare const costOf: (entry: EntryLike) => number;
|
|
197
|
-
/** What the run's
|
|
198
|
-
*
|
|
199
|
-
* then the full amount, never the timeline's total rounded for display. Every response, and each cost written apart
|
|
200
|
-
* from one (a compaction summary's; a harness request's that came in after its answer). A cost that is not a number, or
|
|
201
|
-
* one still pending, leaves it unknown, as the timeline says. These readings are the cap's own, on its copy of the
|
|
202
|
-
* entries (the run's shown cost is the timeline's, unchanged): a request stopped before its end counts at the figure its
|
|
203
|
-
* end mark holds (HELD_FIELD), and one a crash cut (marked as sent, no answer, no end) at the figure its start mark
|
|
204
|
-
* holds (openFigures), each the worst case the cap held for it; without that figure either stays cut, at an unknown
|
|
205
|
-
* cost. A paid call settled at a charge it did not say, like one a crash cut, counts at the figure its mark holds. And
|
|
206
|
-
* this cap's refusals are left out, as none left. Unknown is null, which a cap never reads as $0. */
|
|
207
|
-
export declare function spentIn(storeFile: string): number | null;
|
|
208
|
-
/** What the run's model requests cost, from its entries in log order: the one computation, shared by spentIn (reading a
|
|
209
|
-
* settled run's own database) and the one-store reader (store-reads, reading A's journal). These readings are the cap's
|
|
197
|
+
/** What the run's model requests cost, from its entries in log order: the one computation, which the one-store reader
|
|
198
|
+
* (store-reads/cap.ts spentOverStore) runs over A's journal. These readings are the cap's
|
|
210
199
|
* own, on its copy of the entries (the run's shown cost is the timeline's, unchanged): a request stopped before its end
|
|
211
200
|
* counts at the figure its end mark holds (HELD_FIELD), and one a crash cut (marked as sent, no answer, no end) at the
|
|
212
201
|
* figure its start mark holds (openFigures), each the worst case the cap held for it; without that figure either stays
|
|
@@ -219,7 +208,7 @@ export declare const DECISION_COST = "agentrun.decision_cost";
|
|
|
219
208
|
/** A decision request's hold, kept before it is sent (decision-cap.ts): with no DECISION_COST after it, its process died
|
|
220
209
|
* while it was out, and it counts at this figure. */
|
|
221
210
|
export declare const DECISION_HOLD = "agentrun.decision_hold";
|
|
222
|
-
/** What a workflow run's decisions cost, in its store: what the next process adds to
|
|
211
|
+
/** What a workflow run's decisions cost, in its store: what the next process adds to spentFrom's reading. Per decision
|
|
223
212
|
* (its id):
|
|
224
213
|
* - booked (DECISION_COST entries, at its charge, its hold, or $0 for nothing charged): the larger of what was booked,
|
|
225
214
|
* with any hold no booking ended, and what its receipts say it cost (the costs the timeline's decision rows sum);
|
|
@@ -229,12 +218,6 @@ export declare const DECISION_HOLD = "agentrun.decision_hold";
|
|
|
229
218
|
* - else nothing: no hold is kept before the admission, so a request never sent is never counted.
|
|
230
219
|
* A booking with no decision id is counted as it is. */
|
|
231
220
|
export declare function decisionSpentIn(storeFile: string): number;
|
|
232
|
-
/** The priced answers of `model` (its id) in the run's store, in order: what the wrap-up's typical cost reads from earlier
|
|
233
|
-
* processes (capModels' `wrapUp`). An answer whose cost is unknown or $0, or that was stopped or failed, is none. */
|
|
234
|
-
export declare function costsIn(storeFile: string, model: string): number[];
|
|
235
|
-
/** Whether the run was told its wrap-up under `cap` already (a CAP_WRAPUP entry of that cap): once per cap, across its
|
|
236
|
-
* processes; a raise's new cap re-arms it. */
|
|
237
|
-
export declare function wrapUpSentIn(storeFile: string, cap: number): boolean;
|
|
238
221
|
/** /usage's meters for a run that ended, from its store: `tools`, each TOOL_COST's `usd`, unknown (null) when one is,
|
|
239
222
|
* or when a call was cut (marked, never settled: what it charged no one knows); and `tokens`, the rest of its root
|
|
240
223
|
* conversation as its settled timeline prices it; `browser`, the part of `tools` that is browser session time
|
|
@@ -250,17 +233,6 @@ export type Meters = {
|
|
|
250
233
|
others: number | null;
|
|
251
234
|
notMetered?: number;
|
|
252
235
|
};
|
|
253
|
-
export declare function metersIn(storeFile: string): Meters;
|
|
254
|
-
/** metersIn's meters, and beside them each meter's known dollars: its settled charges' figures, whether or not another of
|
|
255
|
-
* its charges is unknown (a hold, a call cut or never settled, is no charge here: it adds nothing). What a run of
|
|
256
|
-
* unknown cost is known to have spent on each (server.ts /usage). */
|
|
257
|
-
export declare function meterFiguresIn(storeFile: string): Meters & {
|
|
258
|
-
known: {
|
|
259
|
-
tokens: number;
|
|
260
|
-
browser: number;
|
|
261
|
-
others: number;
|
|
262
|
-
};
|
|
263
|
-
};
|
|
264
236
|
/** A browser charge's record on the run's root when the run books its money on the runner's one ledger (browser-cost.ts
|
|
265
237
|
* browserSpend's `paid`): the same record a browser TOOL_COST is, for what the browser's process holds and the seconds
|
|
266
238
|
* it was for, under a kind no cost reads. The charge's money is the ledger's paid step alone, which the cap counts and
|
|
@@ -268,10 +240,10 @@ export declare function meterFiguresIn(storeFile: string): Meters & {
|
|
|
268
240
|
* as every paid tool's on the runner: a TOOL_COST beside it would count the same charge twice. Its seconds are the
|
|
269
241
|
* browser_time meter's (meterFiguresFrom). */
|
|
270
242
|
export declare const BROWSER_CHARGED = "agentrun.browser_charged";
|
|
271
|
-
/**
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
*
|
|
243
|
+
/** /usage's meter figures from a run's entries by conversation, in log order, and beside them each meter's known dollars:
|
|
244
|
+
* its settled charges' figures, whether or not another of its charges is unknown (a hold, a call cut or never settled, is
|
|
245
|
+
* no charge here: it adds nothing). The one computation, which the one-store reader (store-reads/cap.ts metersOverStore)
|
|
246
|
+
* runs over A's journal. A paid tool's charge reaches it as the TOOL_COST / TOOL_UNMETERED the store reader folds back in from the
|
|
275
247
|
* paid-tools session (store-reads/journal.ts withPaidCosts), as the file-backed run's root held each natively. */
|
|
276
248
|
export declare function meterFiguresFrom(rows: readonly {
|
|
277
249
|
conversation: number;
|
|
@@ -284,7 +256,7 @@ export declare function meterFiguresFrom(rows: readonly {
|
|
|
284
256
|
};
|
|
285
257
|
};
|
|
286
258
|
/** What the paid tools of `entries` (TOOL_STARTED and TOOL_COST) spent, as the cap counts it: each charge, and a call
|
|
287
|
-
* settled at a charge it did not say, or a crash cut (marked, never settled), at its held figure, as
|
|
259
|
+
* settled at a charge it did not say, or a crash cut (marked, never settled), at its held figure, as spentFrom counts it;
|
|
288
260
|
* null when one has no figure. The run's reported cost reads such a call unknown instead (the timeline). */
|
|
289
261
|
export declare function capToolSpend(entries: readonly EntryLike[]): number | null;
|
|
290
262
|
/** The worst case of each model request a cap admitted and whose cost is not booked yet, by its turn, for a paid tool's
|
|
@@ -503,8 +475,8 @@ export declare function requestParts(overhead?: (model: Model<Api>, context: Con
|
|
|
503
475
|
feeUsd: number;
|
|
504
476
|
} | undefined;
|
|
505
477
|
/** The wrap-up on pi (capModels' `wrapUp`): the run's own model (`model`, its id), that model's priced requests so far
|
|
506
|
-
* (`costs
|
|
507
|
-
* cap already (`sent
|
|
478
|
+
* (`costs`; capModels adds each one it books), whether it was told under this
|
|
479
|
+
* cap already (`sent`), and `record`, which writes its row (request-start.ts, CAP_WRAPUP). */
|
|
508
480
|
/** The wrap-up's state on pi. `sent`: told, in an answered request, once per cap. `pending`: a request carries the note
|
|
509
481
|
* and has not ended: no other request takes it until that one is answered (told) or not (re-armed). */
|
|
510
482
|
export type WrapUp = {
|
|
@@ -524,7 +496,7 @@ export type WrapUp = {
|
|
|
524
496
|
* and, under the cap,
|
|
525
497
|
* each request to a model in `unpriced` (one serve has no price for) or whose output is priced and that has no output
|
|
526
498
|
* ceiling, each whose input cannot be bounded, and every request once what the run has spent is unknown: `spent` null
|
|
527
|
-
* (
|
|
499
|
+
* (spentFrom), or an answer since whose cost is unknown. A request's input is inputBound of its context, plus
|
|
528
500
|
* `overhead(model, context)` (piOverhead), what its provider adds server-side; undefined is unmeasured, never 0. It is
|
|
529
501
|
* priced by requestPrice under `mode`, after the previous request of its conversation (the context's last answer, read
|
|
530
502
|
* by previousIn; its end as `now` read it when it settled here, else its own timestamp, which is when it began). Each
|
package/dist/cap.js
CHANGED
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
// timeline (runs.ts withOverCap).
|
|
31
31
|
//
|
|
32
32
|
// A paid tool's charge (monid.run's, monid.ts) is the run's spend too: booked in the run's store as a TOOL_COST, which
|
|
33
|
-
// the run's cost and
|
|
33
|
+
// the run's cost and spentFrom both count, and added to what the run's process counts as spent (useSpend), so the next
|
|
34
34
|
// request's check sees it. A charge the call does not say (null: stopped, timed out, failed with no cost) leaves the
|
|
35
35
|
// run's cost unknown, and the cap counts the call at what it was held at, the bound it let the call go at, as it counts
|
|
36
36
|
// one a crash cut: in the run's process and from its mark in the store. Before each paid call, paidCall holds it as a
|
|
@@ -45,12 +45,12 @@
|
|
|
45
45
|
// (RunSpend.wait, budget.ts): a model node's request before it is sent, a call node's call and a decision before they are
|
|
46
46
|
// admitted again. A refusal inside a call node's effect is told to the call (capRefusals), never only to the model.
|
|
47
47
|
import { readRunDbSync } from "./run-db.js";
|
|
48
|
-
import { durableDecisions } from "
|
|
48
|
+
import { durableDecisions } from "./workflow/readers.js";
|
|
49
49
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
50
50
|
import { existsSync } from "node:fs";
|
|
51
51
|
import { imageInputOf, providerInputOverhead } from "@parcha/agentrun-kernel/host";
|
|
52
52
|
import { bookRequest, isConnectCode, isGatewayTimeout, rejectionCode } from "@parcha/agentrun-kernel";
|
|
53
|
-
import {
|
|
53
|
+
import { REQUEST_CONTINUED, REQUEST_COST, REQUEST_COST_LATE, REQUEST_ENDED, REQUEST_REFUSED, REQUEST_STARTED, timelineOf, TOOL_COST, TOOL_STARTED } from "./timeline/index.js";
|
|
54
54
|
/** How a request the cap refused begins its error, which the server ends the run with. */
|
|
55
55
|
export const SPEND_CAP_REACHED = "spend_cap_reached";
|
|
56
56
|
/** How near two dollar figures are the same figure: a sum a float puts a hair past the cap (0.0028 + 0.3072 is
|
|
@@ -139,7 +139,7 @@ export function wrapUpDue(cap, spent, held, typical, leastUsd) {
|
|
|
139
139
|
/** The wrap-up's words, what is left to the cent. `nonePriced`: the run's own model has no priced request yet, so its
|
|
140
140
|
* typical cost is the next request's expected cost and the note can come before the run has done anything (step 0):
|
|
141
141
|
* the words say the budget and ask for a short answer, not a finish. Read from the same priced costs live and in a
|
|
142
|
-
* process opened again (
|
|
142
|
+
* process opened again (ownCosts), so a restart picks the same words. */
|
|
143
143
|
export const wrapUpWords = (leftUsd, nonePriced = false) => {
|
|
144
144
|
const left = centsMoney(Math.max(0, leftUsd));
|
|
145
145
|
return nonePriced ? `This run's budget is about ${left}, enough for little work: answer as soon as you can.` : `About ${left} left of this run's budget: finish now with your answer.`;
|
|
@@ -286,7 +286,7 @@ export function piEnded(message, began, attempts) {
|
|
|
286
286
|
return { end: "nothing", label: last === undefined || "code" in last ? "never_left" : "status" };
|
|
287
287
|
}
|
|
288
288
|
/** How pi's error for a request whose start mark could not be written begins (request-start.ts builds it from this): the
|
|
289
|
-
* request never left, so the entry answers none, and
|
|
289
|
+
* request never left, so the entry answers none, and spentFrom leaves it out by this. */
|
|
290
290
|
export const MARK_NOT_WRITTEN = "the model request was not sent: its mark could not be written";
|
|
291
291
|
/** pi's error for a request that left and whose end mark the store refused (request-start.ts): its cost is not recorded
|
|
292
292
|
* as booked, so it stays open, read at its start mark's hold, never closed by this entry at its own usage. */
|
|
@@ -337,7 +337,7 @@ const close = (open, figure) => {
|
|
|
337
337
|
open.splice(at, 1);
|
|
338
338
|
};
|
|
339
339
|
/** The figures of the requests of each kind that `entries` leave open, marked as sent with no answer, cost or end, read in
|
|
340
|
-
* order, as the run's timeline counts them
|
|
340
|
+
* order, as the run's timeline counts them, so the two agree on how many were cut. A start adds
|
|
341
341
|
* its figure. An end mark closes its own start: a stopped request's at the figure it names, a withdrawn one's (`unsent`,
|
|
342
342
|
* which names none) the smallest. An end that names none for a request that left (an older store) closes nothing, so
|
|
343
343
|
* that request stays cut. An answer, or a summary's cost, closes the smallest figure still open, since when requests
|
|
@@ -376,33 +376,8 @@ function openFigures(entries) {
|
|
|
376
376
|
}
|
|
377
377
|
return open;
|
|
378
378
|
}
|
|
379
|
-
/** What the run's
|
|
380
|
-
*
|
|
381
|
-
* then the full amount, never the timeline's total rounded for display. Every response, and each cost written apart
|
|
382
|
-
* from one (a compaction summary's; a harness request's that came in after its answer). A cost that is not a number, or
|
|
383
|
-
* one still pending, leaves it unknown, as the timeline says. These readings are the cap's own, on its copy of the
|
|
384
|
-
* entries (the run's shown cost is the timeline's, unchanged): a request stopped before its end counts at the figure its
|
|
385
|
-
* end mark holds (HELD_FIELD), and one a crash cut (marked as sent, no answer, no end) at the figure its start mark
|
|
386
|
-
* holds (openFigures), each the worst case the cap held for it; without that figure either stays cut, at an unknown
|
|
387
|
-
* cost. A paid call settled at a charge it did not say, like one a crash cut, counts at the figure its mark holds. And
|
|
388
|
-
* this cap's refusals are left out, as none left. Unknown is null, which a cap never reads as $0. */
|
|
389
|
-
export function spentIn(storeFile) {
|
|
390
|
-
if (!existsSync(storeFile))
|
|
391
|
-
return 0;
|
|
392
|
-
// Fresh, read-only and lock-free (run-db.ts): its process may hold it.
|
|
393
|
-
const rows = [];
|
|
394
|
-
readRunDbSync(storeFile, false, (db) => {
|
|
395
|
-
// A read made again (its file changed during it) starts from none.
|
|
396
|
-
rows.length = 0;
|
|
397
|
-
for (const row of db.prepare("SELECT record FROM entries ORDER BY rowid").iterate()) {
|
|
398
|
-
const entry = JSON.parse(String(row.record));
|
|
399
|
-
rows.push(entry);
|
|
400
|
-
}
|
|
401
|
-
});
|
|
402
|
-
return spentFrom(rows);
|
|
403
|
-
}
|
|
404
|
-
/** What the run's model requests cost, from its entries in log order: the one computation, shared by spentIn (reading a
|
|
405
|
-
* settled run's own database) and the one-store reader (store-reads, reading A's journal). These readings are the cap's
|
|
379
|
+
/** What the run's model requests cost, from its entries in log order: the one computation, which the one-store reader
|
|
380
|
+
* (store-reads/cap.ts spentOverStore) runs over A's journal. These readings are the cap's
|
|
406
381
|
* own, on its copy of the entries (the run's shown cost is the timeline's, unchanged): a request stopped before its end
|
|
407
382
|
* counts at the figure its end mark holds (HELD_FIELD), and one a crash cut (marked as sent, no answer, no end) at the
|
|
408
383
|
* figure its start mark holds (openFigures), each the worst case the cap held for it; without that figure either stays
|
|
@@ -546,7 +521,7 @@ export const DECISION_COST = "agentrun.decision_cost";
|
|
|
546
521
|
/** A decision request's hold, kept before it is sent (decision-cap.ts): with no DECISION_COST after it, its process died
|
|
547
522
|
* while it was out, and it counts at this figure. */
|
|
548
523
|
export const DECISION_HOLD = "agentrun.decision_hold";
|
|
549
|
-
/** What a workflow run's decisions cost, in its store: what the next process adds to
|
|
524
|
+
/** What a workflow run's decisions cost, in its store: what the next process adds to spentFrom's reading. Per decision
|
|
550
525
|
* (its id):
|
|
551
526
|
* - booked (DECISION_COST entries, at its charge, its hold, or $0 for nothing charged): the larger of what was booked,
|
|
552
527
|
* with any hold no booking ended, and what its receipts say it cost (the costs the timeline's decision rows sum);
|
|
@@ -597,7 +572,7 @@ export function decisionSpentIn(storeFile) {
|
|
|
597
572
|
}
|
|
598
573
|
for (const receipt of receipts) {
|
|
599
574
|
const usd = figureOf(receipt.cost_usd);
|
|
600
|
-
// A stored receipt row names its decision `decision_id` (
|
|
575
|
+
// A stored receipt row names its decision `decision_id` (workflow/decision-recovery.ts rowOf).
|
|
601
576
|
const id = typeof receipt.decision_id === "string" ? receipt.decision_id : typeof receipt.id === "string" ? receipt.id : undefined;
|
|
602
577
|
if (id !== undefined && usd !== undefined && usd > 0)
|
|
603
578
|
receipted.set(id, (receipted.get(id) ?? 0) + usd);
|
|
@@ -618,7 +593,7 @@ export function decisionSpentIn(storeFile) {
|
|
|
618
593
|
function entriesIn(storeFile) {
|
|
619
594
|
if (!existsSync(storeFile))
|
|
620
595
|
return [];
|
|
621
|
-
// Fresh, read-only and lock-free (run-db.ts), as
|
|
596
|
+
// Fresh, read-only and lock-free (run-db.ts), as the cap's readings did.
|
|
622
597
|
const rows = [];
|
|
623
598
|
readRunDbSync(storeFile, false, (db) => {
|
|
624
599
|
rows.length = 0;
|
|
@@ -627,32 +602,6 @@ function entriesIn(storeFile) {
|
|
|
627
602
|
});
|
|
628
603
|
return rows;
|
|
629
604
|
}
|
|
630
|
-
/** The priced answers of `model` (its id) in the run's store, in order: what the wrap-up's typical cost reads from earlier
|
|
631
|
-
* processes (capModels' `wrapUp`). An answer whose cost is unknown or $0, or that was stopped or failed, is none. */
|
|
632
|
-
export function costsIn(storeFile, model) {
|
|
633
|
-
return entriesIn(storeFile).flatMap((entry) => {
|
|
634
|
-
const message = entry.kind === "pi.assistant" ? entry.model?.[0] : undefined;
|
|
635
|
-
const total = message?.usage?.cost?.total;
|
|
636
|
-
return message?.model === model && message.stopReason !== "error" && message.stopReason !== "aborted" && typeof total === "number" && Number.isFinite(total) && total > 0 ? [total] : [];
|
|
637
|
-
});
|
|
638
|
-
}
|
|
639
|
-
/** Whether the run was told its wrap-up under `cap` already (a CAP_WRAPUP entry of that cap): once per cap, across its
|
|
640
|
-
* processes; a raise's new cap re-arms it. */
|
|
641
|
-
export function wrapUpSentIn(storeFile, cap) {
|
|
642
|
-
return entriesIn(storeFile).some((entry) => entry.kind === CAP_WRAPUP && typeof entry.data?.capUsd === "number" && Math.abs(entry.data.capUsd - cap) <= CAP_TOLERANCE);
|
|
643
|
-
}
|
|
644
|
-
export function metersIn(storeFile) {
|
|
645
|
-
const { known: _, ...meters } = meterFiguresIn(storeFile);
|
|
646
|
-
return meters;
|
|
647
|
-
}
|
|
648
|
-
/** metersIn's meters, and beside them each meter's known dollars: its settled charges' figures, whether or not another of
|
|
649
|
-
* its charges is unknown (a hold, a call cut or never settled, is no charge here: it adds nothing). What a run of
|
|
650
|
-
* unknown cost is known to have spent on each (server.ts /usage). */
|
|
651
|
-
export function meterFiguresIn(storeFile) {
|
|
652
|
-
if (!existsSync(storeFile))
|
|
653
|
-
return { tools: 0, tokens: null, browser: { usd: 0, seconds: 0 }, others: 0, known: { tokens: 0, browser: 0, others: 0 } };
|
|
654
|
-
return readRunDbSync(storeFile, false, (db) => meterFiguresFrom(db.prepare("SELECT conversation_id AS conversation, record FROM entries ORDER BY rowid").all().map((row) => ({ conversation: Number(row.conversation), entry: JSON.parse(String(row.record)) }))));
|
|
655
|
-
}
|
|
656
605
|
/** A browser charge's record on the run's root when the run books its money on the runner's one ledger (browser-cost.ts
|
|
657
606
|
* browserSpend's `paid`): the same record a browser TOOL_COST is, for what the browser's process holds and the seconds
|
|
658
607
|
* it was for, under a kind no cost reads. The charge's money is the ledger's paid step alone, which the cap counts and
|
|
@@ -660,10 +609,10 @@ export function meterFiguresIn(storeFile) {
|
|
|
660
609
|
* as every paid tool's on the runner: a TOOL_COST beside it would count the same charge twice. Its seconds are the
|
|
661
610
|
* browser_time meter's (meterFiguresFrom). */
|
|
662
611
|
export const BROWSER_CHARGED = "agentrun.browser_charged";
|
|
663
|
-
/**
|
|
664
|
-
*
|
|
665
|
-
*
|
|
666
|
-
*
|
|
612
|
+
/** /usage's meter figures from a run's entries by conversation, in log order, and beside them each meter's known dollars:
|
|
613
|
+
* its settled charges' figures, whether or not another of its charges is unknown (a hold, a call cut or never settled, is
|
|
614
|
+
* no charge here: it adds nothing). The one computation, which the one-store reader (store-reads/cap.ts metersOverStore)
|
|
615
|
+
* runs over A's journal. A paid tool's charge reaches it as the TOOL_COST / TOOL_UNMETERED the store reader folds back in from the
|
|
667
616
|
* paid-tools session (store-reads/journal.ts withPaidCosts), as the file-backed run's root held each natively. */
|
|
668
617
|
export function meterFiguresFrom(rows) {
|
|
669
618
|
const root = rows.reduce((min, row) => Math.min(min, row.conversation), Infinity);
|
|
@@ -702,7 +651,7 @@ export function meterFiguresFrom(rows) {
|
|
|
702
651
|
return { tools, tokens: usage ? (usage.usage?.usd ?? null) : 0, browser, others: otherTools, known, ...(notMetered ? { notMetered } : {}) };
|
|
703
652
|
}
|
|
704
653
|
/** What the paid tools of `entries` (TOOL_STARTED and TOOL_COST) spent, as the cap counts it: each charge, and a call
|
|
705
|
-
* settled at a charge it did not say, or a crash cut (marked, never settled), at its held figure, as
|
|
654
|
+
* settled at a charge it did not say, or a crash cut (marked, never settled), at its held figure, as spentFrom counts it;
|
|
706
655
|
* null when one has no figure. The run's reported cost reads such a call unknown instead (the timeline). */
|
|
707
656
|
export function capToolSpend(entries) {
|
|
708
657
|
const open = new Map();
|
|
@@ -766,7 +715,7 @@ export const runCap = () => runSpend?.cap;
|
|
|
766
715
|
* quote, else an allowance, `basis` saying which) fits the cap, and whenever the spend is unknown; else run, one paid
|
|
767
716
|
* call at a time, so each check sees the charge before it, and held at that figure (paidHolds) until the charge it
|
|
768
717
|
* reports (`charge` of its result, undefined for none) joins the spend. A charge it does not say (null), or a call that
|
|
769
|
-
* fails, counts at its held figure, as its mark does from the store (
|
|
718
|
+
* fails, counts at its held figure, as its mark does from the store (spentFrom), since it may have charged that much.
|
|
770
719
|
* With no cap it just runs. */
|
|
771
720
|
/** A paid call this run's cap refused for room (paidCall): its words, after the code, and its figures as a model
|
|
772
721
|
* request's refusal keeps them (what was taken, and the call's hold as what it needs). The model's next request is
|
|
@@ -955,7 +904,9 @@ const whyOf = ({ text, figures }) => ({ why: text, figures });
|
|
|
955
904
|
* (RefusalFigures, the pause's spent_usd). */
|
|
956
905
|
const spentOf = (spent, held, cap) => {
|
|
957
906
|
const holds = centsMoney(held);
|
|
958
|
-
|
|
907
|
+
// A spend above $0 that rounds to it reads "less than a cent", never "$0" (the kernel's spentMoney).
|
|
908
|
+
const spentWords = spent > 0 && centsMoney(spent) === "$0" ? "less than a cent" : centsMoney(spent);
|
|
909
|
+
return holds !== "$0" ? `spent ${spentWords} and holds ${holds} for steps still running, of its ${money(cap)} cap` : `spent ${spentWords} of its ${money(cap)} cap`;
|
|
959
910
|
};
|
|
960
911
|
/** An amount in words, to the nearest cent ($0.0237416 is $0.02), as money says it ($1, $0.20, $0). */
|
|
961
912
|
export const centsMoney = (usd) => money(Math.round(usd * 100) / 100);
|
|
@@ -1078,7 +1029,7 @@ export function requestParts(overhead = piOverhead) {
|
|
|
1078
1029
|
* and, under the cap,
|
|
1079
1030
|
* each request to a model in `unpriced` (one serve has no price for) or whose output is priced and that has no output
|
|
1080
1031
|
* ceiling, each whose input cannot be bounded, and every request once what the run has spent is unknown: `spent` null
|
|
1081
|
-
* (
|
|
1032
|
+
* (spentFrom), or an answer since whose cost is unknown. A request's input is inputBound of its context, plus
|
|
1082
1033
|
* `overhead(model, context)` (piOverhead), what its provider adds server-side; undefined is unmeasured, never 0. It is
|
|
1083
1034
|
* priced by requestPrice under `mode`, after the previous request of its conversation (the context's last answer, read
|
|
1084
1035
|
* by previousIn; its end as `now` read it when it settled here, else its own timestamp, which is when it began). Each
|
|
@@ -1251,7 +1202,7 @@ export async function capModels(models, cap, spent, { unpriced = new Set(), over
|
|
|
1251
1202
|
* of what it streamed (stoppedFigure, at most `worst`), unless an attempt before the stop was lost: then at `worst`, as
|
|
1252
1203
|
* its lost mark reads in a later process; one that ended on an error after its response began
|
|
1253
1204
|
* (markResponseBegan: its usage is what had streamed, not what the provider can have billed), or that failed with no
|
|
1254
|
-
* answer, at `worst`, what the cap held for it; each as
|
|
1205
|
+
* answer, at `worst`, what the cap held for it; each as spentFrom reads its end mark. Without a figure (a deferred
|
|
1255
1206
|
* response) it is unknown, as is a cost that is not a number, from then on. */
|
|
1256
1207
|
const count = (answer, turn, worst, stopped, attempts) => {
|
|
1257
1208
|
const plus = (sum, cost) => (sum !== null && typeof cost === "number" && Number.isFinite(cost) ? sum + cost : null);
|
|
@@ -1259,7 +1210,7 @@ export async function capModels(models, cap, spent, { unpriced = new Set(), over
|
|
|
1259
1210
|
// One rule (bookRequest), from how the request ended (piEnded) as its marks read it too.
|
|
1260
1211
|
const at = (message) => message.stopReason === "aborted" ? (stopped && !anyAttemptLost(attempts) ? stopped(message) : worst)
|
|
1261
1212
|
: bookRequest(piEnded(message, responseBegan.has(message), attempts), worst === undefined ? {} : { hold: worst }).usd;
|
|
1262
|
-
// A priced turn answer of the run's own model: the wrap-up's typical cost counts it, as
|
|
1213
|
+
// A priced turn answer of the run's own model: the wrap-up's typical cost counts it, as a process opened again reads it (its
|
|
1263
1214
|
// pi.assistant entries). Never a compaction summary's or a native search's request on the same model (completeSimple
|
|
1264
1215
|
// calls, `turn` false): no pi.assistant entry keeps them, so a process opened again would count without them.
|
|
1265
1216
|
const priced = (message) => {
|
|
@@ -1342,7 +1293,7 @@ export async function capModels(models, cap, spent, { unpriced = new Set(), over
|
|
|
1342
1293
|
const refused = createAssistantMessageEventStream();
|
|
1343
1294
|
const message = refusal(model, judged.why);
|
|
1344
1295
|
// Its own start mark first, so pi's error entry for it answers that mark, never an earlier request a stop or a crash
|
|
1345
|
-
// cut. A mark that cannot be written still ends the request:
|
|
1296
|
+
// cut. A mark that cannot be written still ends the request: spentFrom leaves refusals out either way.
|
|
1346
1297
|
void Promise.resolve()
|
|
1347
1298
|
.then(() => markRefused?.(judged.figures))
|
|
1348
1299
|
.catch(() => undefined)
|
package/dist/cli.js
CHANGED
|
@@ -14,7 +14,7 @@ import { startedWith } from "./adapters.js";
|
|
|
14
14
|
import { REPEAT_MS, stopOnSignals } from "./stop-signals.js";
|
|
15
15
|
import { canOpen } from "./host.js";
|
|
16
16
|
import { resetPassword } from "./owner.js";
|
|
17
|
-
import { banner
|
|
17
|
+
import { banner } from "./print.js";
|
|
18
18
|
import { DEFAULT_PORT, fauxEnvOf, startServe } from "./server.js";
|
|
19
19
|
import { besideRunnerOptions, besideStopping, runnerBeside } from "./runner/beside.js";
|
|
20
20
|
import { apiOnlyFrom } from "./api-only.js";
|
|
@@ -76,8 +76,9 @@ published port, or a proxy's URL), and the link printed uses it; with none, Rend
|
|
|
76
76
|
end, and per refused credential; AGENTRUN_LOG=quiet leaves out the request lines.
|
|
77
77
|
|
|
78
78
|
AGENTRUN_API_ONLY=1 serves the run routes alone, for a server behind its caller's backend: a run's launch, read, list,
|
|
79
|
-
timeline, messages, stop, cancel, kill and cap raise, its files and uploads,
|
|
80
|
-
address (the page, sign-in, setup, settings, MCP, triggers and their hooks,
|
|
79
|
+
timeline, messages, stop, cancel, kill and cap raise, its files and uploads, an agent's Archil disk, capabilities, health
|
|
80
|
+
and usage. Every other address (the page, sign-in, setup, settings, MCP, triggers and their hooks, the rest of agents)
|
|
81
|
+
is a 404, and there are no accounts.
|
|
81
82
|
|
|
82
83
|
The page is for one person, who signs in with a password (AGENTRUN_ACCOUNTS=0 turns this off; the token works for
|
|
83
84
|
scripts and the CLI either way). With no AGENTRUN_PUBLIC_URL, listening on loopback, the first visit to the page sets the
|
|
@@ -332,21 +333,6 @@ catch (error) {
|
|
|
332
333
|
process.exit(2);
|
|
333
334
|
}
|
|
334
335
|
const accounts = !apiOnly && process.env.AGENTRUN_ACCOUNTS !== "0";
|
|
335
|
-
// The Docker box image's first build said in words, as it starts and as it ends (print.ts boxImageLine); a line told
|
|
336
|
-
// before the banner is printed waits for it.
|
|
337
|
-
let imageSaid = false;
|
|
338
|
-
let bannered = false;
|
|
339
|
-
const early = [];
|
|
340
|
-
const onBoxImage = (state) => {
|
|
341
|
-
const line = boxImageLine(state, imageSaid);
|
|
342
|
-
if (line === undefined)
|
|
343
|
-
return;
|
|
344
|
-
imageSaid = true;
|
|
345
|
-
if (bannered)
|
|
346
|
-
console.log(line);
|
|
347
|
-
else
|
|
348
|
-
early.push(line);
|
|
349
|
-
};
|
|
350
336
|
// How it was started, for the hints that start it again (adapters.ts npxLine): itself and its runs read it.
|
|
351
337
|
Object.assign(process.env, startedWith({ ...(values.port !== undefined ? { port: values.port } : {}), open: values.open === true }));
|
|
352
338
|
let serve;
|
|
@@ -354,7 +340,6 @@ let serveOptions;
|
|
|
354
340
|
const trustedProxies = (process.env.AGENTRUN_TRUSTED_PROXIES ?? "").split(",").map((entry) => entry.trim()).filter(Boolean);
|
|
355
341
|
try {
|
|
356
342
|
serve = await startServe(serveOptions = {
|
|
357
|
-
onBoxImage,
|
|
358
343
|
// The owner lock on a Postgres store lost for good: this server can serve nothing more, so it exits non-zero and its
|
|
359
344
|
// platform starts it again, rather than answer 503 for as long as it runs.
|
|
360
345
|
onStoreLost: (error) => {
|
|
@@ -407,9 +392,6 @@ for (const line of banner({ url: serve.url, baseUrl: serve.baseUrl, data, token:
|
|
|
407
392
|
// setup link with its code as the code was made (owner.ts).
|
|
408
393
|
if (serve.setupUrl && serve.setupOpen)
|
|
409
394
|
console.log(`Set your password: ${serve.setupUrl} (the first visit sets it)`);
|
|
410
|
-
bannered = true;
|
|
411
|
-
for (const line of early.splice(0))
|
|
412
|
-
console.log(line);
|
|
413
395
|
// The console's page, once the server listens: never its sign-in link, whose token would sit in the opener's arguments
|
|
414
396
|
// and the browser's history.
|
|
415
397
|
// API-only: there is no console, so nothing to open.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ComputerHoldAnswer, type ComputerCallOptions, type ComputerCallStore, computerAsk, computerHoldOf, handBackComputer,
|
|
1
|
+
import { type ComputerHoldAnswer, type ComputerCallOptions, type ComputerCallStore, computerAsk, computerHoldOf, handBackComputer, runViewedKind, takeOverComputer, type ViewedKind } from "./computer-commands.js";
|
|
2
2
|
import { type HoldState } from "./workspace/computer-hold.js";
|
|
3
3
|
export type { ViewedKind } from "./computer-commands.js";
|
|
4
4
|
export { computerAsk, computerHoldOf, handBackComputer, runViewedKind, takeOverComputer };
|
|
@@ -18,9 +18,6 @@ export declare const COMPUTER_ROUTES: ReadonlySet<string>;
|
|
|
18
18
|
export declare const TAKE_OVER_MINUTES: number;
|
|
19
19
|
/** Run `runId`'s desktop or phone, from the store: its kind, whether it is up, and who drives it. */
|
|
20
20
|
export declare function computerViewOf(store: ComputerCallStore, runId: string, options?: ComputerCallOptions): Promise<ComputerViewRead>;
|
|
21
|
-
/** Whether the run's computer is taken over now, for the run read's computer field (run-computer.ts ComputerStateOf):
|
|
22
|
-
* from the run's journal and its rows. */
|
|
23
|
-
export declare const takenOverIn: (entries: readonly JournalEntry[], commands: Parameters<typeof holdShown>[1]) => boolean;
|
|
24
21
|
/** How a request to one of the routes came: by the owner's signed-in page, or with a token; whether this server has
|
|
25
22
|
* accounts (for the refusal's words); its body. */
|
|
26
23
|
export type ComputerRequest = {
|
package/dist/computer-routes.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// A run's desktop or phone, as its owner takes it: POST /v2/runs/{id}/computer/take-over and POST .../computer/hand-back
|
|
2
2
|
// (the hand-back for every kind: a browser's answers its agent's ask, as POST .../browser/hand-back does). Owner-only, as
|
|
3
|
-
// a run's browser is: the owner's password session in the console, never a token. GET /v2/runs/{id}/computer
|
|
4
|
-
//
|
|
3
|
+
// a run's browser is: the owner's password session in the console, never a token. GET /v2/runs/{id}/computer is answered by
|
|
4
|
+
// server.ts from computerView (computer-view.ts) over computerHoldOf; computerViewOf is the store-backed read of the run's
|
|
5
|
+
// computer the take-over tests check against.
|
|
5
6
|
//
|
|
6
7
|
// Everything is read from the one store (computer-commands.ts): the run's computer is up, and who drives it, as the run's
|
|
7
8
|
// runner committed them to the run's journal; a take-over or hand-back is a command row the runner applies to the run's
|
|
@@ -26,9 +27,6 @@ export async function computerViewOf(store, runId, options = {}) {
|
|
|
26
27
|
return { kind, state: "none", hold: "agent", why: `this run's ${kind} is not up now` };
|
|
27
28
|
return { kind, state: "live", hold: holdShown(hold, await store.commands(runId, 0)).state };
|
|
28
29
|
}
|
|
29
|
-
/** Whether the run's computer is taken over now, for the run read's computer field (run-computer.ts ComputerStateOf):
|
|
30
|
-
* from the run's journal and its rows. */
|
|
31
|
-
export const takenOverIn = (entries, commands) => holdShown(holdIn(entries), commands).state === "person";
|
|
32
30
|
/**
|
|
33
31
|
* One of our routes (COMPUTER_ROUTES, by its name in serve's route table) for run `runId`: { hold, outcome? }, or an
|
|
34
32
|
* ApiError. A token is refused (forbidden): a take-over drives the computer, so it takes the owner's signed-in page, as a
|
|
@@ -16,10 +16,12 @@ export type ComputerSetting = {
|
|
|
16
16
|
readonly provider: string;
|
|
17
17
|
readonly image?: string;
|
|
18
18
|
readonly gpu?: GpuSetting;
|
|
19
|
+
readonly persistent?: boolean;
|
|
19
20
|
} | {
|
|
20
21
|
readonly kind: Exclude<ComputerKind, "none" | "sandbox">;
|
|
21
22
|
readonly provider: string;
|
|
22
23
|
readonly image?: string;
|
|
24
|
+
readonly persistent?: boolean;
|
|
23
25
|
};
|
|
24
26
|
/** The GPUs a setting asks for, or undefined. */
|
|
25
27
|
export declare const gpuOf: (computer: {
|
package/dist/computer-setting.js
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
// An agent's computer, its one setting for where its tools run (Settings → Computers): `computer: { kind, provider?,
|
|
2
|
+
// image?, gpu?, persistent? }` on its revision. kind is none, sandbox, desktop, phone or browser; provider names one of
|
|
3
|
+
// the computer providers (the computer package's kind registry), and is absent for none; image names one the provider
|
|
4
|
+
// offers for the kind, and absent is the kind's default; a sandbox's gpu is { type, count }; persistent: true keeps the
|
|
5
|
+
// agent's own computer between its runs, where the configuration declares persistence. The v2 API's `place` is this
|
|
6
|
+
// setting's view, one to one where it can say it: {mode: "runner"} is {kind: "none"}, and {mode: "sandbox", box: X} is
|
|
7
|
+
// {kind: "sandbox", provider: X}. Writing either sets both. A desktop, phone or browser computer leaves the run's folder
|
|
8
|
+
// on the runner, so its place reads runner.
|
|
9
|
+
import { configurationOf, PROVIDERS, serves } from "@parcha/agentrun-computer";
|
|
1
10
|
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2
11
|
/** The kinds of computer an agent can be given. */
|
|
3
12
|
export const COMPUTER_KINDS = ["none", "sandbox", "desktop", "phone", "browser"];
|
|
@@ -16,6 +25,11 @@ const OPTIONAL = {
|
|
|
16
25
|
image: {
|
|
17
26
|
check: (value, field) => (typeof value === "string" && value.trim() !== "" && value === value.trim() ? [] : [{ field, reason: "invalid", message: `${field} is the name of an image the provider offers for the kind (GET /computers lists them), with no spaces around it` }]),
|
|
18
27
|
},
|
|
28
|
+
// An agent's own computer, kept between its runs (workspace/agent-computer.ts): true asks for it, where the provider's
|
|
29
|
+
// configuration keeps one (persistenceIssues); false or absent is a fresh computer for each run.
|
|
30
|
+
persistent: {
|
|
31
|
+
check: (value, field) => (typeof value === "boolean" ? [] : [{ field, reason: "wrong_type", message: `${field} is true (this agent keeps its own computer between runs) or false (a fresh one for each run)` }]),
|
|
32
|
+
},
|
|
19
33
|
gpu: {
|
|
20
34
|
kinds: ["sandbox"],
|
|
21
35
|
check: (gpu, field) => {
|
|
@@ -67,7 +81,30 @@ export function computerIssues(value, field) {
|
|
|
67
81
|
}
|
|
68
82
|
if (typeof value.provider !== "string" || value.provider === "")
|
|
69
83
|
return bad("missing", `a ${kind} computer names its provider (Settings → Computers lists them)`);
|
|
70
|
-
|
|
84
|
+
const issues = Object.entries(OPTIONAL).flatMap(([key, { check }]) => (value[key] === undefined ? [] : check(value[key], `${field}.${key}`)));
|
|
85
|
+
if (issues.length > 0 || value.persistent !== true)
|
|
86
|
+
return issues;
|
|
87
|
+
return persistenceIssues(kind, value.provider, typeof value.image === "string" ? value.image : undefined, `${field}.persistent`);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Why `persistent: true` is refused, at `field`: the configuration the setting selects keeps no computer for an agent.
|
|
91
|
+
* Read from the computer package's registry, each configuration's declared persistence (kinds.test holds it equal to the
|
|
92
|
+
* built provider's), so a save needs no vendor call. A provider the registry does not list (a --faux one, or one the
|
|
93
|
+
* readiness check names as unknown) is left to the claim's refusal.
|
|
94
|
+
*/
|
|
95
|
+
function persistenceIssues(kind, provider, image, field) {
|
|
96
|
+
const entry = PROVIDERS.find((one) => one.id === provider);
|
|
97
|
+
if (!entry)
|
|
98
|
+
return [];
|
|
99
|
+
const configuration = configurationOf(entry.capabilities.filter((one) => serves(one, kind)), image, entry.defaultImage?.[kind]);
|
|
100
|
+
if (!configuration || configuration.persistence !== undefined)
|
|
101
|
+
return [];
|
|
102
|
+
return [{
|
|
103
|
+
field,
|
|
104
|
+
reason: "not_allowed",
|
|
105
|
+
message: `${entry.label}'s ${image === undefined ? "default" : JSON.stringify(image)} ${kind} keeps no computer for an agent between runs: it declares no persistence`,
|
|
106
|
+
fix: `Remove ${field}, or pick a computer that keeps one (GET /v2/computers shows which do).`,
|
|
107
|
+
}];
|
|
71
108
|
}
|
|
72
109
|
/** The setting and its place a definition says, from `computer` or `place` (both: they must agree), or undefined when
|
|
73
110
|
* it says neither. Each is checked already (computerIssues, placeIssues). */
|
package/dist/computer-view.d.ts
CHANGED
|
@@ -18,6 +18,10 @@ export type ComputerAnswer = {
|
|
|
18
18
|
state: "none";
|
|
19
19
|
kind: ComputerKind;
|
|
20
20
|
hold: ComputerHold;
|
|
21
|
+
ended?: {
|
|
22
|
+
at: string;
|
|
23
|
+
why: string;
|
|
24
|
+
};
|
|
21
25
|
} | {
|
|
22
26
|
state: "live";
|
|
23
27
|
kind: ComputerKind;
|
|
@@ -32,7 +36,12 @@ export declare function computerView(deps: {
|
|
|
32
36
|
} | undefined>;
|
|
33
37
|
/** The run's computer, read only when no viewer is open. */
|
|
34
38
|
computer(): ComputerOf;
|
|
35
|
-
/** Who drives now.
|
|
36
|
-
* drives, as no seam answers. */
|
|
39
|
+
/** Who drives now. */
|
|
37
40
|
hold?(): ComputerHold;
|
|
41
|
+
/** Why the run's browser is not up, read only for a `none` browser: let go while the run waited for its person, and none
|
|
42
|
+
* opened since (browser-wait-ended.ts), with when; undefined otherwise. */
|
|
43
|
+
ended?(): Promise<{
|
|
44
|
+
at: string;
|
|
45
|
+
why: string;
|
|
46
|
+
} | undefined>;
|
|
38
47
|
}): Promise<ComputerAnswer>;
|
package/dist/computer-view.js
CHANGED
|
@@ -10,5 +10,6 @@ export async function computerView(deps) {
|
|
|
10
10
|
const computer = deps.computer();
|
|
11
11
|
if ("off" in computer)
|
|
12
12
|
return { state: "off", hold: "agent", why: computer.off };
|
|
13
|
-
|
|
13
|
+
const ended = computer.kind === "browser" ? await deps.ended?.() : undefined;
|
|
14
|
+
return ended ? { state: "none", kind: computer.kind, hold, ended } : { state: "none", kind: computer.kind, hold };
|
|
14
15
|
}
|