@parcha/agentrun-serve 0.1.0-beta.32 → 0.1.0-beta.34
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 +270 -0
- package/README.md +343 -246
- package/dist/adapters.d.ts +0 -7
- package/dist/adapters.js +11 -22
- package/dist/agent-rows.d.ts +98 -0
- package/dist/agent-rows.js +1 -0
- package/dist/agents-store.d.ts +6 -2
- package/dist/agents-store.js +60 -25
- package/dist/agents.d.ts +9 -125
- package/dist/agents.js +15 -305
- package/dist/answer-json.d.ts +23 -0
- package/dist/answer-json.js +58 -0
- package/dist/api-only.d.ts +14 -0
- package/dist/api-only.js +33 -0
- package/dist/archil-routes.d.ts +1 -1
- package/dist/bash-read-only.d.ts +22 -0
- package/dist/bash-read-only.js +701 -0
- package/dist/box-egress-vm.d.ts +0 -8
- package/dist/box-egress-vm.js +0 -10
- package/dist/box-egress.d.ts +0 -4
- package/dist/box-egress.js +1 -16
- package/dist/box-paths.d.ts +25 -2
- package/dist/box-paths.js +79 -11
- package/dist/box-relay.d.ts +0 -11
- package/dist/box-relay.js +0 -20
- package/dist/box-settings.d.ts +26 -0
- package/dist/box-settings.js +63 -0
- package/dist/boxes.d.ts +21 -1
- package/dist/boxes.js +27 -20
- package/dist/browser-commands.d.ts +5 -2
- package/dist/browser-commands.js +4 -4
- package/dist/browser-computer.d.ts +5 -0
- package/dist/browser-computer.js +21 -0
- package/dist/browser-cost.d.ts +9 -6
- package/dist/browser-cost.js +94 -51
- package/dist/browser-live.d.ts +7 -20
- package/dist/browser-live.js +15 -93
- package/dist/browser-person.d.ts +18 -53
- package/dist/browser-person.js +94 -279
- package/dist/budget.d.ts +0 -4
- package/dist/budget.js +0 -7
- package/dist/cap.d.ts +8 -12
- package/dist/cap.js +12 -27
- package/dist/cli.js +61 -20
- package/dist/closed-pipes.d.ts +2 -0
- package/dist/closed-pipes.js +13 -0
- package/dist/computer-commands.d.ts +2 -0
- package/dist/computer-commands.js +2 -0
- package/dist/computer-keys.js +5 -2
- package/dist/computer-setting.d.ts +20 -4
- package/dist/computer-setting.js +25 -5
- package/dist/computers.d.ts +31 -3
- package/dist/computers.js +70 -11
- package/dist/confine.d.ts +120 -0
- package/dist/confine.js +436 -0
- package/dist/console/assets/index-RPHGlXmM.js +540 -0
- package/dist/console/assets/index-opTN5Naq.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/daytona-api.d.ts +0 -11
- package/dist/daytona-api.js +1 -82
- package/dist/decision-rows.d.ts +1 -1
- package/dist/decision-rows.js +1 -1
- package/dist/docker-daemon.d.ts +31 -0
- package/dist/docker-daemon.js +56 -0
- package/dist/docker-host-addresses.d.ts +37 -0
- package/dist/docker-host-addresses.js +110 -0
- package/dist/effort-guidance.js +4 -3
- package/dist/environment.d.ts +0 -3
- package/dist/environment.js +3 -5
- package/dist/errors.d.ts +0 -2
- package/dist/errors.js +6 -9
- package/dist/filed-answer.d.ts +32 -0
- package/dist/filed-answer.js +160 -0
- package/dist/files.d.ts +1 -11
- package/dist/files.js +2 -21
- package/dist/github-connection.d.ts +2 -2
- package/dist/github-connection.js +1 -1
- package/dist/graph-view.d.ts +3 -5
- package/dist/graph-view.js +4 -14
- package/dist/handed-values.d.ts +9 -0
- package/dist/handed-values.js +26 -0
- package/dist/harness-install.d.ts +22 -5
- package/dist/harness-install.js +98 -20
- package/dist/harness-opencode/adapter.d.ts +7 -0
- package/dist/harness-opencode/adapter.js +23 -6
- package/dist/harness-opencode/index.d.ts +1 -1
- package/dist/harness-opencode/index.js +1 -1
- package/dist/harness-opencode/verify.d.ts +17 -0
- package/dist/harness-opencode/verify.js +30 -10
- package/dist/harness-table.js +6 -1
- package/dist/harness.d.ts +4 -3
- package/dist/harness.js +16 -1
- package/dist/heard.js +1 -1
- package/dist/held-fd.d.ts +5 -0
- package/dist/held-fd.js +14 -0
- package/dist/host-calls.d.ts +20 -0
- package/dist/host-calls.js +12 -0
- package/dist/host-tools.d.ts +4 -21
- package/dist/host-tools.js +4 -61
- package/dist/host.d.ts +2 -4
- package/dist/host.js +2 -7
- package/dist/import-summary.d.ts +1 -5
- package/dist/import-summary.js +0 -21
- package/dist/import.d.ts +6 -6
- package/dist/import.js +62 -24
- package/dist/key-refusal.d.ts +5 -1
- package/dist/key-refusal.js +19 -4
- package/dist/learn/check.d.ts +6 -2
- package/dist/learn/check.js +83 -29
- package/dist/learn/folder.d.ts +5 -1
- package/dist/learn/folder.js +10 -3
- package/dist/learn/grade.d.ts +14 -0
- package/dist/learn/grade.js +68 -12
- package/dist/learn/index.d.ts +4 -4
- package/dist/learn/index.js +4 -4
- package/dist/learn/reflect.d.ts +31 -2
- package/dist/learn/reflect.js +79 -4
- package/dist/learn/relevance.d.ts +24 -0
- package/dist/learn/relevance.js +91 -0
- package/dist/learn/secrets.d.ts +8 -1
- package/dist/learn/secrets.js +95 -15
- package/dist/learn/skills.d.ts +112 -14
- package/dist/learn/skills.js +556 -52
- package/dist/learned-workflow.d.ts +37 -5
- package/dist/learned-workflow.js +106 -12
- package/dist/learning-routes.d.ts +16 -49
- package/dist/learning-routes.js +46 -36
- package/dist/learning-run.d.ts +6 -250
- package/dist/learning-run.js +11 -665
- package/dist/learning-words.d.ts +12 -5
- package/dist/learning-words.js +18 -9
- package/dist/learning.d.ts +93 -77
- package/dist/learning.js +176 -304
- package/dist/live/stream.js +1 -1
- package/dist/live/translate.js +13 -3
- package/dist/local-models.d.ts +11 -5
- package/dist/local-models.js +13 -8
- package/dist/mcp-gateway.d.ts +11 -52
- package/dist/mcp-gateway.js +44 -148
- package/dist/mcp-oauth.d.ts +10 -14
- package/dist/mcp-oauth.js +14 -32
- package/dist/mcp-probe.d.ts +0 -7
- package/dist/mcp-probe.js +4 -10
- package/dist/mcp-servers-store.d.ts +6 -6
- package/dist/mcp-servers-store.js +13 -15
- package/dist/mcp-store.js +3 -4
- package/dist/mcp.js +4 -3
- package/dist/model.d.ts +6 -7
- package/dist/model.js +43 -27
- package/dist/monid.d.ts +0 -2
- package/dist/monid.js +3 -6
- package/dist/openapi.d.ts +8 -1
- package/dist/openapi.js +124 -50
- package/dist/page.d.ts +1 -3
- package/dist/page.js +9 -19
- package/dist/paid-calls.d.ts +21 -27
- package/dist/paid-calls.js +28 -62
- package/dist/pause.d.ts +0 -2
- package/dist/pause.js +1 -8
- package/dist/place.d.ts +0 -5
- package/dist/place.js +0 -10
- package/dist/print.d.ts +2 -1
- package/dist/print.js +4 -2
- package/dist/propose.js +83 -39
- package/dist/push-handler.d.ts +1 -1
- package/dist/reflect-range.d.ts +25 -0
- package/dist/reflect-range.js +30 -0
- package/dist/refusal-words.d.ts +5 -1
- package/dist/refusal-words.js +5 -1
- package/dist/rows.d.ts +1 -1
- package/dist/run-cut.d.ts +0 -6
- package/dist/run-cut.js +0 -6
- package/dist/run-db.d.ts +2 -13
- package/dist/run-db.js +2 -41
- package/dist/run-launch.d.ts +19 -2
- package/dist/run-launch.js +13 -5
- package/dist/run-learning-served.d.ts +46 -2
- package/dist/run-learning-served.js +26 -7
- package/dist/run-reads-over-store.d.ts +1 -1
- package/dist/run-reads-over-store.js +15 -6
- package/dist/run-secrets.d.ts +33 -0
- package/dist/run-secrets.js +53 -0
- package/dist/run-timeline-served.d.ts +5 -1
- package/dist/run-timeline-served.js +19 -5
- package/dist/run-view.d.ts +12 -17
- package/dist/run-view.js +29 -28
- package/dist/runnable.d.ts +18 -10
- package/dist/runnable.js +21 -10
- package/dist/runner/adapter-loop.d.ts +14 -3
- package/dist/runner/adapter-loop.js +464 -62
- package/dist/runner/adapter-run-spec.d.ts +29 -8
- package/dist/runner/adapter-run-spec.js +96 -37
- package/dist/runner/adapters/index.js +11 -1
- package/dist/runner/adapters/pi.d.ts +15 -1
- package/dist/runner/adapters/pi.js +19 -5
- package/dist/runner/beside.d.ts +30 -3
- package/dist/runner/beside.js +54 -12
- package/dist/runner/claim-secrets.d.ts +10 -1
- package/dist/runner/claim-secrets.js +49 -15
- package/dist/runner/cli-run-spec.d.ts +2 -0
- package/dist/runner/cli-run-spec.js +60 -17
- package/dist/runner/commands.js +1 -1
- package/dist/runner/computer-journal.d.ts +15 -2
- package/dist/runner/computer-journal.js +41 -5
- package/dist/runner/conformance/harness.js +118 -8
- package/dist/runner/conformance/subject.d.ts +4 -1
- package/dist/runner/dispatch.d.ts +8 -1
- package/dist/runner/dispatch.js +81 -7
- package/dist/runner/end-of-run.d.ts +8 -2
- package/dist/runner/end-of-run.js +10 -4
- package/dist/runner/github-app.js +1 -1
- package/dist/runner/harness-loops.d.ts +9 -1
- package/dist/runner/harness-loops.js +15 -2
- package/dist/runner/journal-kinds.d.ts +30 -6
- package/dist/runner/journal-kinds.js +20 -5
- package/dist/runner/journal-reader.d.ts +1 -1
- package/dist/runner/journal-reader.js +2 -2
- package/dist/runner/learning-ask.d.ts +4 -0
- package/dist/runner/learning-ask.js +15 -1
- package/dist/runner/learning-end.d.ts +18 -3
- package/dist/runner/learning-end.js +113 -11
- package/dist/runner/learning-loop.d.ts +5 -0
- package/dist/runner/learning-loop.js +26 -6
- package/dist/runner/live-ticker.d.ts +1 -1
- package/dist/runner/live-ticker.js +28 -4
- package/dist/runner/loop-contract.d.ts +3 -2
- package/dist/runner/main.d.ts +64 -10
- package/dist/runner/main.js +165 -27
- package/dist/runner/mcp-claim.d.ts +1 -1
- package/dist/runner/mcp-claim.js +2 -3
- package/dist/runner/mcp-run.d.ts +2 -0
- package/dist/runner/mcp-run.js +15 -5
- package/dist/runner/memory-claim.d.ts +9 -0
- package/dist/runner/memory-claim.js +25 -0
- package/dist/runner/metrics.d.ts +33 -1
- package/dist/runner/metrics.js +85 -1
- package/dist/runner/model-route.d.ts +13 -0
- package/dist/runner/model-route.js +154 -11
- package/dist/runner/redact.d.ts +8 -2
- package/dist/runner/redact.js +11 -2
- package/dist/runner/reflect-hook.d.ts +12 -1
- package/dist/runner/reflect-hook.js +33 -3
- package/dist/runner/runner.d.ts +20 -0
- package/dist/runner/runner.js +56 -10
- package/dist/runner/store-port.d.ts +1 -1
- package/dist/runner/store-secrets.d.ts +3 -3
- package/dist/runner/store-secrets.js +8 -12
- package/dist/runner/text-tools.d.ts +44 -0
- package/dist/runner/text-tools.js +237 -0
- package/dist/runner/workflow-loop.d.ts +6 -0
- package/dist/runner/workflow-loop.js +6 -4
- package/dist/runner/workflow-spec.d.ts +18 -0
- package/dist/runner/workflow-spec.js +68 -26
- package/dist/runs-over-store.d.ts +8 -3
- package/dist/runs-over-store.js +76 -19
- package/dist/seal-key.d.ts +54 -15
- package/dist/seal-key.js +232 -82
- package/dist/sealed-settings-store.d.ts +19 -4
- package/dist/sealed-settings-store.js +9 -9
- package/dist/sealing.d.ts +4 -0
- package/dist/sealing.js +20 -0
- package/dist/secret-cut.d.ts +1 -1
- package/dist/secret-cut.js +1 -1
- package/dist/secret-name.d.ts +9 -0
- package/dist/secret-name.js +15 -0
- package/dist/secret-writes.d.ts +0 -1
- package/dist/secret-writes.js +0 -1
- package/dist/secrets.d.ts +2 -10
- package/dist/secrets.js +21 -17
- package/dist/server-fs.d.ts +4 -0
- package/dist/server-fs.js +8 -2
- package/dist/server-lock.d.ts +0 -24
- package/dist/server-lock.js +1 -80
- package/dist/server-secrets-store.d.ts +4 -4
- package/dist/server-secrets-store.js +10 -32
- package/dist/server-secrets.d.ts +4 -9
- package/dist/server-secrets.js +12 -33
- package/dist/server.d.ts +26 -44
- package/dist/server.js +229 -142
- package/dist/sign-ins-store.d.ts +34 -36
- package/dist/sign-ins-store.js +27 -38
- package/dist/sign-ins.d.ts +2 -119
- package/dist/sign-ins.js +5 -311
- package/dist/standard-webhooks.d.ts +1 -1
- package/dist/standard-webhooks.js +1 -1
- package/dist/stats.d.ts +3 -2
- package/dist/stats.js +1 -1
- package/dist/store/agent-body.d.ts +8 -2
- package/dist/store/agent-body.js +16 -4
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +3 -3
- package/dist/store/open.d.ts +18 -5
- package/dist/store/open.js +23 -3
- package/dist/store/postgres/connection.d.ts +18 -2
- package/dist/store/postgres/connection.js +156 -32
- package/dist/store/postgres/migrate.d.ts +4 -0
- package/dist/store/postgres/migrate.js +27 -3
- package/dist/store/postgres/migrations/0003_commands_one_answer.check.sql +19 -0
- package/dist/store/postgres/migrations/0003_commands_one_answer.sql +13 -0
- package/dist/store/postgres/store.d.ts +9 -2
- package/dist/store/postgres/store.js +9 -0
- package/dist/store/schema.js +1 -1
- package/dist/store/seal.js +2 -2
- package/dist/store/sqlite/connection.js +49 -5
- package/dist/store/sqlite/run-patch.d.ts +3 -0
- package/dist/store/sqlite/run-patch.js +3 -0
- package/dist/store/sqlite/store.js +64 -20
- package/dist/store/store.d.ts +38 -6
- package/dist/store/store.js +12 -2
- package/dist/store-reads/cap.d.ts +1 -1
- package/dist/store-reads/cap.js +22 -4
- package/dist/store-reads/journal.d.ts +25 -6
- package/dist/store-reads/journal.js +173 -21
- package/dist/store-reads/learning.d.ts +26 -8
- package/dist/store-reads/learning.js +12 -4
- package/dist/store-reads/workflow.d.ts +1 -1
- package/dist/store-reads/workflow.js +1 -1
- package/dist/store-view.d.ts +5 -1
- package/dist/store-view.js +91 -23
- package/dist/template-eval.d.ts +60 -4
- package/dist/template-eval.js +120 -54
- package/dist/templates.d.ts +24 -10
- package/dist/templates.js +69 -38
- package/dist/timeline/group.d.ts +33 -0
- package/dist/timeline/group.js +77 -0
- package/dist/timeline/index.d.ts +7 -0
- package/dist/timeline/index.js +7 -0
- package/dist/timeline/labels.d.ts +79 -0
- package/dist/timeline/labels.js +150 -0
- package/dist/timeline/origin.d.ts +56 -0
- package/dist/timeline/origin.js +92 -0
- package/dist/timeline/render-text.d.ts +11 -0
- package/dist/timeline/render-text.js +62 -0
- package/dist/timeline/timeline.d.ts +274 -0
- package/dist/timeline/timeline.js +1308 -0
- package/dist/timeline/util.d.ts +17 -0
- package/dist/timeline/util.js +49 -0
- package/dist/tool-gate.d.ts +41 -216
- package/dist/tool-gate.js +79 -540
- package/dist/tool-keys-store.d.ts +11 -12
- package/dist/tool-keys-store.js +24 -31
- package/dist/tool-keys.d.ts +9 -104
- package/dist/tool-keys.js +15 -271
- package/dist/tool-plane.d.ts +14 -42
- package/dist/tool-plane.js +23 -81
- package/dist/tool-settings-store.d.ts +1 -2
- package/dist/tool-settings-store.js +5 -8
- package/dist/tools.d.ts +31 -19
- package/dist/tools.js +101 -108
- package/dist/trigger-adapter.d.ts +2 -2
- package/dist/trigger-schedule.js +2 -1
- package/dist/trigger-secrets-shown.js +5 -1
- package/dist/trigger-targets.d.ts +13 -1
- package/dist/trigger-targets.js +31 -1
- package/dist/triggers.d.ts +2 -2
- package/dist/triggers.js +3 -3
- package/dist/turn-end.d.ts +1 -1
- package/dist/turn-end.js +1 -1
- package/dist/turns.d.ts +0 -6
- package/dist/turns.js +0 -19
- package/dist/uploads.js +1 -1
- package/dist/usage.d.ts +0 -2
- package/dist/usage.js +0 -2
- package/dist/validate.d.ts +2 -0
- package/dist/validate.js +23 -14
- package/dist/webhooks.d.ts +102 -76
- package/dist/webhooks.js +266 -233
- package/dist/workflow-run.d.ts +114 -0
- package/dist/workflow-run.js +144 -0
- package/dist/workspace/beneath.d.ts +19 -0
- package/dist/workspace/beneath.js +106 -0
- package/dist/workspace/computer-deps.d.ts +52 -5
- package/dist/workspace/computer-deps.js +154 -19
- package/dist/workspace/computer-for-claim.d.ts +19 -14
- package/dist/workspace/computer-for-claim.js +77 -16
- package/dist/workspace/computer-hold.d.ts +6 -1
- package/dist/workspace/computer-hold.js +6 -1
- package/dist/workspace/computer-janitor.d.ts +47 -0
- package/dist/workspace/computer-janitor.js +182 -0
- package/dist/workspace/computer-providers.d.ts +6 -2
- package/dist/workspace/computer-providers.js +1 -1
- package/dist/workspace/grep-worker.d.ts +5 -0
- package/dist/workspace/grep-worker.js +9 -6
- package/dist/workspace/index.d.ts +4 -3
- package/dist/workspace/index.js +4 -4
- package/dist/workspace/local.d.ts +11 -2
- package/dist/workspace/local.js +161 -43
- package/dist/workspace/resolve-computer.d.ts +50 -10
- package/dist/workspace/resolve-computer.js +46 -11
- package/dist/workspace/run-tools.d.ts +13 -31
- package/dist/workspace/run-tools.js +10 -27
- package/dist/workspace-paths.d.ts +0 -17
- package/dist/workspace-paths.js +1 -41
- package/dist/workspace.d.ts +0 -17
- package/dist/workspace.js +3 -99
- package/launcher/agentrun-serve +6 -33
- package/package.json +14 -14
- package/templates/README.md +9 -3
- package/templates/inbound-lead/agent.md +1 -1
- package/templates/kyb/agent.md +1 -1
- package/templates/market-monitor/agent.md +2 -2
- package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
- package/dist/app.d.ts +0 -5
- package/dist/app.js +0 -514
- package/dist/bound-files.d.ts +0 -4
- package/dist/bound-files.js +0 -164
- package/dist/bounds.d.ts +0 -26
- package/dist/bounds.js +0 -137
- package/dist/coding-tools.d.ts +0 -47
- package/dist/coding-tools.js +0 -189
- package/dist/computer-adb.d.ts +0 -12
- package/dist/computer-adb.js +0 -14
- package/dist/console/assets/index-35-7aeIZ.js +0 -519
- package/dist/console/assets/index-Cejbov-Y.css +0 -1
- package/dist/content-filter.d.ts +0 -7
- package/dist/content-filter.js +0 -23
- package/dist/disk.d.ts +0 -33
- package/dist/disk.js +0 -85
- package/dist/door-line.d.ts +0 -23
- package/dist/door-line.js +0 -83
- package/dist/grade.d.ts +0 -63
- package/dist/grade.js +0 -150
- package/dist/harness-app.d.ts +0 -69
- package/dist/harness-app.js +0 -1162
- package/dist/mcp-servers.d.ts +0 -269
- package/dist/mcp-servers.js +0 -456
- package/dist/packs.d.ts +0 -71
- package/dist/packs.js +0 -180
- package/dist/request-start.d.ts +0 -27
- package/dist/request-start.js +0 -381
- package/dist/run-box.d.ts +0 -205
- package/dist/run-box.js +0 -661
- package/dist/run-holder.d.ts +0 -52
- package/dist/run-holder.js +0 -139
- package/dist/runs.d.ts +0 -1200
- package/dist/runs.js +0 -4103
- package/dist/sealed-settings.d.ts +0 -60
- package/dist/sealed-settings.js +0 -178
- package/dist/served-only.d.ts +0 -5
- package/dist/served-only.js +0 -12
- package/dist/sessions.d.ts +0 -6
- package/dist/sessions.js +0 -109
- package/dist/workspace/computer-serves.d.ts +0 -12
- package/dist/workspace/computer-serves.js +0 -15
|
@@ -10,9 +10,9 @@ import { DatabaseSync } from "node:sqlite";
|
|
|
10
10
|
import { claimFence, storeNow } from "../fence.js";
|
|
11
11
|
import { RunStorage } from "../journal/storage.js";
|
|
12
12
|
import { COMMANDS_ONE_ANSWER, DDL, SCHEMA_VERSION } from "../schema.js";
|
|
13
|
-
import { AgentArchived, CommandTaken, ExternalBodyConflict, Fenced, RunFinal, SchemaVersionUnknown, STORE_WRITE_DEADLINE_MS, StoreConstraint, StoreFromEarlierVersion, TriggerFull, FINAL_STATES, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, SignInHandedTo, SignInMissing,
|
|
13
|
+
import { AgentArchived, CommandTaken, ExternalBodyConflict, Fenced, RunFinal, SchemaVersionUnknown, STORE_WRITE_DEADLINE_MS, StoreConstraint, StoreFromEarlierVersion, TriggerFull, FINAL_STATES, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, SignInHandedTo, SignInMissing, } from "../store.js";
|
|
14
14
|
import { Connection } from "./connection.js";
|
|
15
|
-
import { applyRunPatch, refuseLeftovers, RUN_COLUMNS, runOf, SIGN_IN_HANDED_LOCK } from "./run-patch.js";
|
|
15
|
+
import { applyRunPatch, NOT_A_LEARNING_RUN, refuseLeftovers, RUN_COLUMNS, runOf, SIGN_IN_HANDED_LOCK } from "./run-patch.js";
|
|
16
16
|
import { readLaunch, writeLaunch } from "./run-launch.js";
|
|
17
17
|
import { canonical } from "../agent-body.js";
|
|
18
18
|
import { aadOf, sealedAt } from "../seal.js";
|
|
@@ -127,8 +127,10 @@ async function versionOf(db) {
|
|
|
127
127
|
* triggers, tool keys and trigger secrets (all in the store now), and the per-run door's token (the per-run door is
|
|
128
128
|
* gone). This version's own top-level files are not among them, so a directory holding them opens: .token and
|
|
129
129
|
* .server.json beside the store and its lock, a leftover box-image.json, and the files this version still keeps beside
|
|
130
|
-
* the store in the same format an earlier version did (the
|
|
131
|
-
*
|
|
130
|
+
* the store in the same format an earlier version did (the kept idempotency answers and the learning usage ledger),
|
|
131
|
+
* which an earlier version's copy of reads the same. A webhook config and outbox an earlier build kept beside the store
|
|
132
|
+
* (webhook.json, webhook-outbox.json) do not refuse the directory either: nothing reads them, and the webhook, now in
|
|
133
|
+
* the store, is set again. */
|
|
132
134
|
const EARLIER_ROOT_FILES = ["mcp-servers.json", "triggers.json", "tool-keys.json", "trigger-secrets.json", ".door-token"];
|
|
133
135
|
/** The files an earlier version kept in a data directory, relative to it: its store (a STORE_FILE with tables and no
|
|
134
136
|
* store_meta row), agent homes (<agent>/agent.sqlite, agents/<agent>/agent.sqlite), run databases (runs/<run>/run.sqlite,
|
|
@@ -303,14 +305,17 @@ class SqliteStore {
|
|
|
303
305
|
const clock = () => storeNow(d, now);
|
|
304
306
|
this.#clock = clock;
|
|
305
307
|
const insertAgent = (tx, agent, at) => tx.run("INSERT INTO agents (id, name, description, created_at) VALUES (?, ?, ?, ?)", agent.id, agent.name, agent.description ?? null, at);
|
|
306
|
-
const insertRevision = async (tx, agentId, revision, at) => {
|
|
308
|
+
const insertRevision = async (tx, agentId, revision, at, ifCurrent) => {
|
|
307
309
|
// The parent is the agent's current revision now (null for its first): the agent must exist, which its first revision
|
|
308
|
-
// (create) and a later one (addRevision, upgrade) both guarantee before this. Held
|
|
309
|
-
// never both name the same parent
|
|
310
|
+
// (create) and a later one (addRevision, upgrade) both guarantee before this. Held (a writer's row lock), so two
|
|
311
|
+
// revisions added at once, by this server or another on the same store, never both name the same parent, and
|
|
312
|
+
// `ifCurrent` is compared with what no other writer can move until this commits.
|
|
310
313
|
await d.lockRow(tx, "agents", "id", agentId);
|
|
311
314
|
const agent = await tx.get("SELECT current_revision FROM agents WHERE id = ?", agentId);
|
|
312
315
|
if (!agent)
|
|
313
316
|
throw new StoreConstraint(`no agent ${agentId}`);
|
|
317
|
+
if (ifCurrent !== undefined && agent.current_revision !== ifCurrent)
|
|
318
|
+
throw new RevisionMoved(agentId, agent.current_revision);
|
|
314
319
|
await tx.run("INSERT INTO revisions (id, agent_id, parent_id, kind, body, skills, note, package, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", revision.id, agentId, agent.current_revision, revision.kind, json(revision.body), revision.skills === undefined || revision.skills === null ? null : json(revision.skills), revision.note ?? null, revision.package === undefined ? null : json(revision.package), at);
|
|
315
320
|
await tx.run("UPDATE agents SET current_revision = ? WHERE id = ?", revision.id, agentId);
|
|
316
321
|
};
|
|
@@ -381,8 +386,8 @@ class SqliteStore {
|
|
|
381
386
|
await writeScopes(tx, t.id, []);
|
|
382
387
|
return off.map(({ id: triggerId, name }) => ({ id: triggerId, name })).sort((a, b) => a.name.localeCompare(b.name));
|
|
383
388
|
}),
|
|
384
|
-
addRevision: async ({ agentId, ...revision }) => {
|
|
385
|
-
await db.transaction((tx) => insertRevision(tx, agentId, revision, now()));
|
|
389
|
+
addRevision: async ({ agentId, ifCurrent, ...revision }) => {
|
|
390
|
+
await db.transaction((tx) => insertRevision(tx, agentId, revision, now(), ifCurrent));
|
|
386
391
|
},
|
|
387
392
|
setCurrent: async (agentId, revisionId) => {
|
|
388
393
|
const changed = await db.transaction((tx) => tx.runCounted("UPDATE agents SET current_revision = ? WHERE id = ? AND EXISTS (SELECT 1 FROM revisions WHERE id = ? AND agent_id = ?)", revisionId, agentId, revisionId, agentId));
|
|
@@ -706,7 +711,9 @@ class SqliteStore {
|
|
|
706
711
|
},
|
|
707
712
|
launch: (runId) => readLaunch(db, runId),
|
|
708
713
|
list: async ({ agentId, revisionId, state, archived, limit }) => {
|
|
709
|
-
|
|
714
|
+
// A built-in learning run (a run's grade and merge, queued with its kept learning) is no run of a person's: no list,
|
|
715
|
+
// count, stat or notice names it.
|
|
716
|
+
const where = [NOT_A_LEARNING_RUN];
|
|
710
717
|
const params = [];
|
|
711
718
|
if (agentId !== undefined)
|
|
712
719
|
(where.push("agent_id = ?"), params.push(agentId));
|
|
@@ -743,6 +750,11 @@ class SqliteStore {
|
|
|
743
750
|
const rows = await db.all(`SELECT id FROM runs WHERE ${claimable.sql} ORDER BY started_at, id${bounded ? " LIMIT ?" : ""}`, ...claimable.params, ...(bounded ? [limit] : []));
|
|
744
751
|
return rows.map((row) => row.id);
|
|
745
752
|
},
|
|
753
|
+
heldAt: async (runId) => {
|
|
754
|
+
const n = clock();
|
|
755
|
+
const row = await db.get(`SELECT epoch FROM runs WHERE id = ? AND runner IS NOT NULL AND claimed_until >= ${n.sql}`, runId, ...n.params);
|
|
756
|
+
return row === undefined ? undefined : Number(row.epoch);
|
|
757
|
+
},
|
|
746
758
|
claimMany: (runner, k, { leaseMs = DEFAULT_LEASE_MS } = {}) => this.#claimRuns(runner, leaseMs, { k }),
|
|
747
759
|
update: async (claim, patch, rows = {}) => {
|
|
748
760
|
if (Array.isArray(rows) || typeof rows !== "object" || rows === null)
|
|
@@ -965,6 +977,23 @@ class SqliteStore {
|
|
|
965
977
|
return row ? proposalOf(row) : undefined;
|
|
966
978
|
},
|
|
967
979
|
proposals: async (agentId, { limit = 100 } = {}) => (await db.all("SELECT run_id, agent_id, turn, proposal, learning_run_id, created_at FROM learning_proposals WHERE agent_id = ? ORDER BY created_at DESC, run_id DESC LIMIT ?", agentId, limit)).map(proposalOf),
|
|
980
|
+
spend: async ({ from, to }) => {
|
|
981
|
+
const rows = await db.all(`SELECT lp.agent_id, lp.proposal, lp.created_at, lp.learning_run_id, lr.state AS run_state, lr.ended_at AS run_ended_at, lr.cost_usd AS run_cost_usd
|
|
982
|
+
FROM learning_proposals lp
|
|
983
|
+
JOIN runs src ON src.id = lp.run_id
|
|
984
|
+
LEFT JOIN runs lr ON lr.id = lp.learning_run_id
|
|
985
|
+
WHERE src.imported_from IS NULL AND COALESCE(lr.ended_at, lp.created_at) >= ? AND COALESCE(lr.ended_at, lp.created_at) < ?
|
|
986
|
+
ORDER BY COALESCE(lr.ended_at, lp.created_at), lp.run_id`, from, to);
|
|
987
|
+
return rows.flatMap((row) => {
|
|
988
|
+
// A proposal: once its learning run ended, failed or was stopped, its row's cost is the grade's spend (a stop
|
|
989
|
+
// seen after a paid grade keeps it, learning-loop.ts).
|
|
990
|
+
if (row.learning_run_id !== null)
|
|
991
|
+
return row.run_state === "ended" || row.run_state === "failed" || row.run_state === "stopped" ? [{ agentId: row.agent_id, at: row.run_ended_at ?? row.created_at, costUsd: row.run_cost_usd }] : [];
|
|
992
|
+
// Kept with no learning run: dropped before it was proposed (nothing graded), unless it is still a proposal.
|
|
993
|
+
const kept = JSON.parse(row.proposal);
|
|
994
|
+
return kept?.state === "proposed" ? [] : [{ agentId: row.agent_id, at: row.created_at, costUsd: 0 }];
|
|
995
|
+
});
|
|
996
|
+
},
|
|
968
997
|
};
|
|
969
998
|
this.settings = {
|
|
970
999
|
get: async (key) => {
|
|
@@ -974,6 +1003,11 @@ class SqliteStore {
|
|
|
974
1003
|
put: async (key, value) => {
|
|
975
1004
|
await db.write([{ sql: "INSERT INTO settings (key, value, updated_at) VALUES (?, ?, ?) ON CONFLICT (key) DO UPDATE SET value = excluded.value, updated_at = excluded.updated_at", params: [key, json(value), now()] }]);
|
|
976
1005
|
},
|
|
1006
|
+
putIfAbsent: async (key, value) => {
|
|
1007
|
+
await db.write([{ sql: "INSERT INTO settings (key, value, updated_at) VALUES (?, ?, ?) ON CONFLICT (key) DO NOTHING", params: [key, json(value), now()] }]);
|
|
1008
|
+
const row = await db.get("SELECT value FROM settings WHERE key = ?", key);
|
|
1009
|
+
return row === undefined ? undefined : JSON.parse(row.value);
|
|
1010
|
+
},
|
|
977
1011
|
remove: async (key) => {
|
|
978
1012
|
await db.write([{ sql: "DELETE FROM settings WHERE key = ?", params: [key] }]);
|
|
979
1013
|
},
|
|
@@ -1040,31 +1074,41 @@ class SqliteStore {
|
|
|
1040
1074
|
all: async () => {
|
|
1041
1075
|
const out = [];
|
|
1042
1076
|
const bytes = (value) => Uint8Array.from(value);
|
|
1077
|
+
// A row whose AAD cannot be built (a key holding the separator) was never sealed by this store's writers, which
|
|
1078
|
+
// build the same AAD: it is left out, never a failed read of every other.
|
|
1079
|
+
const add = (row) => {
|
|
1080
|
+
try {
|
|
1081
|
+
out.push(row());
|
|
1082
|
+
}
|
|
1083
|
+
catch {
|
|
1084
|
+
// Left out: see above.
|
|
1085
|
+
}
|
|
1086
|
+
};
|
|
1043
1087
|
for (const row of await db.all("SELECT name, sealed FROM sealed_keys ORDER BY name")) {
|
|
1044
|
-
|
|
1088
|
+
add(() => ({ plane: "sealed_keys", where: { name: row.name }, aad: aadOf(sealedAt.sealedKey(row.name)), sealed: bytes(row.sealed) }));
|
|
1045
1089
|
}
|
|
1046
1090
|
for (const row of await db.all("SELECT name, sealed FROM mcp_servers WHERE sealed IS NOT NULL ORDER BY name")) {
|
|
1047
|
-
|
|
1091
|
+
add(() => ({ plane: "mcp_servers", where: { name: row.name }, aad: aadOf(sealedAt.mcpServer(row.name)), sealed: bytes(row.sealed) }));
|
|
1048
1092
|
}
|
|
1049
1093
|
for (const row of await db.all("SELECT state, sealed FROM mcp_oauth_pending ORDER BY state")) {
|
|
1050
|
-
|
|
1094
|
+
add(() => ({ plane: "mcp_oauth_pending", where: { state: row.state }, aad: aadOf(sealedAt.oauthPending(row.state)), sealed: bytes(row.sealed) }));
|
|
1051
1095
|
}
|
|
1052
1096
|
for (const row of await db.all("SELECT adapter, scope, field, sealed FROM trigger_settings ORDER BY adapter, scope, field")) {
|
|
1053
1097
|
// Base64 text in this column (sealed-settings-store.ts), under the table's documented composite-key AAD.
|
|
1054
|
-
|
|
1098
|
+
add(() => ({ plane: "trigger_settings", where: { adapter: row.adapter, scope: row.scope, field: row.field }, aad: `trigger_settings|${row.adapter}|${row.scope}|${row.field}`, sealed: Uint8Array.from(Buffer.from(row.sealed, "base64")) }));
|
|
1055
1099
|
}
|
|
1056
1100
|
for (const row of await db.all("SELECT agent_id, provider, pointer_sealed FROM sign_ins ORDER BY agent_id, provider")) {
|
|
1057
|
-
|
|
1101
|
+
add(() => ({ plane: "sign_ins", where: { agentId: row.agent_id, provider: row.provider }, aad: aadOf(sealedAt.signIn(row.agent_id, row.provider)), sealed: bytes(row.pointer_sealed) }));
|
|
1058
1102
|
}
|
|
1059
1103
|
// A tombstone keeps the pointer's sealed bytes under the live row's binding (store/seal.ts signIn).
|
|
1060
1104
|
for (const row of await db.all("SELECT id, agent_id, provider, pointer_sealed FROM sign_in_tombstones ORDER BY id")) {
|
|
1061
|
-
|
|
1105
|
+
add(() => ({ plane: "sign_in_tombstones", where: { id: String(row.id), agentId: row.agent_id, provider: row.provider }, aad: aadOf(sealedAt.signIn(row.agent_id, row.provider)), sealed: bytes(row.pointer_sealed) }));
|
|
1062
1106
|
}
|
|
1063
1107
|
for (const row of await db.all("SELECT run_id, kind, tag, sealed FROM computer_viewers ORDER BY run_id, kind, tag")) {
|
|
1064
|
-
|
|
1108
|
+
add(() => ({ plane: "computer_viewers", where: { runId: row.run_id, kind: row.kind, tag: row.tag }, aad: aadOf(sealedAt.liveViewer(row.run_id, row.kind, row.tag)), sealed: bytes(row.sealed) }));
|
|
1065
1109
|
}
|
|
1066
1110
|
for (const row of await db.all("SELECT run_id, sealed FROM run_launch WHERE sealed IS NOT NULL ORDER BY run_id")) {
|
|
1067
|
-
|
|
1111
|
+
add(() => ({ plane: "run_launch", where: { runId: row.run_id }, aad: aadOf({ table: "run_launch", row: row.run_id, column: "sealed" }), sealed: bytes(row.sealed) }));
|
|
1068
1112
|
}
|
|
1069
1113
|
return out;
|
|
1070
1114
|
},
|
|
@@ -1120,8 +1164,8 @@ class SqliteStore {
|
|
|
1120
1164
|
const at = now();
|
|
1121
1165
|
const tomb = await tx.get("INSERT INTO sign_in_tombstones (agent_id, provider, pointer_sealed, forgotten_at) VALUES (?, ?, ?, ?) RETURNING agent_id, provider, pointer_sealed, forgotten_at", agentId, provider, live.pointer_sealed, at);
|
|
1122
1166
|
await tx.run("DELETE FROM sign_ins WHERE agent_id = ? AND provider = ?", agentId, provider);
|
|
1123
|
-
//
|
|
1124
|
-
|
|
1167
|
+
// Every tombstone is kept: what the agent learned is cut of each pointer it ever held (handed-values.ts
|
|
1168
|
+
// agentPointers), and a dropped one would be shown again.
|
|
1125
1169
|
return signInTombstoneOf(tomb);
|
|
1126
1170
|
}),
|
|
1127
1171
|
handedHolder: async (hash, options) => (await handedHolderIn(db, hash, { settleMs: options?.settleMs ?? 0, now: options?.at !== undefined ? { sql: d.bigintParam, params: [options.at] } : clock() }))?.id,
|
package/dist/store/store.d.ts
CHANGED
|
@@ -241,6 +241,20 @@ export interface Learning {
|
|
|
241
241
|
proposals(agentId: string, options?: {
|
|
242
242
|
limit?: number;
|
|
243
243
|
}): Promise<LearningProposal[]>;
|
|
244
|
+
/** What learning spent outside any run, in one read: each run (not imported) whose learning ended in [from, to) (ms),
|
|
245
|
+
* its agent, when its learning ended and what its grade cost (null: unknown; 0: nothing graded). A learning dropped
|
|
246
|
+
* before it was proposed ended when it was kept; a proposal ended when its learning run ended (ended or failed), whose
|
|
247
|
+
* row keeps the grade's spend as its cost. One still waiting for its grade is none of them. */
|
|
248
|
+
spend(window: {
|
|
249
|
+
from: number;
|
|
250
|
+
to: number;
|
|
251
|
+
}): Promise<LearningSpend[]>;
|
|
252
|
+
}
|
|
253
|
+
/** One run's learning end as GET /usage's learning meter counts it (Learning.spend). */
|
|
254
|
+
export interface LearningSpend {
|
|
255
|
+
readonly agentId: string;
|
|
256
|
+
readonly at: number;
|
|
257
|
+
readonly costUsd: number | null;
|
|
244
258
|
}
|
|
245
259
|
/** A command a journal commit takes, with the id of the record that is its effect, an id the effect's batch newly
|
|
246
260
|
* allocates (an entry, a created document, a new task): written only by the commit that newly writes that record, in its
|
|
@@ -452,9 +466,13 @@ export interface Agents {
|
|
|
452
466
|
id: string;
|
|
453
467
|
name: string;
|
|
454
468
|
}[]>;
|
|
455
|
-
/** Adds a revision and makes it the agent's current one, in one commit.
|
|
469
|
+
/** Adds a revision and makes it the agent's current one, in one commit. With `ifCurrent` (a revision id, or null for
|
|
470
|
+
* none), only while that is still the agent's current revision, compared in the same transaction under the agent row's
|
|
471
|
+
* lock: RevisionMoved, and nothing written, when another writer (this server's, or another server's on the same store)
|
|
472
|
+
* moved it first. */
|
|
456
473
|
addRevision(revision: NewRevision & {
|
|
457
474
|
agentId: string;
|
|
475
|
+
ifCurrent?: string | null;
|
|
458
476
|
}): Promise<void>;
|
|
459
477
|
/** Makes `revisionId`, one of the agent's own, its current one. StoreConstraint when it is not a revision of `agentId`. */
|
|
460
478
|
setCurrent(agentId: string, revisionId: string): Promise<void>;
|
|
@@ -615,7 +633,7 @@ export interface Runs {
|
|
|
615
633
|
* none (it was not started with one), never a default. */
|
|
616
634
|
launch(runId: string): Promise<RunLaunchRow>;
|
|
617
635
|
/** Newest first, at most `limit` (no limit: all). `archived` filters on the run's own archive time (true: archived,
|
|
618
|
-
* false: not); its agent's archive is read apart. */
|
|
636
|
+
* false: not); its agent's archive is read apart. A built-in learning run (one a kept learning names) is never listed. */
|
|
619
637
|
list(filter: {
|
|
620
638
|
agentId?: string;
|
|
621
639
|
revisionId?: string;
|
|
@@ -641,6 +659,10 @@ export interface Runs {
|
|
|
641
659
|
claimable(options?: {
|
|
642
660
|
limit?: number;
|
|
643
661
|
}): Promise<string[]>;
|
|
662
|
+
/** The epoch a runner's claim holds run `runId` at now, judged by the store's own clock (the one claims are stamped
|
|
663
|
+
* and fenced by), never a reader's; undefined when no claim holds it (none, released, or run out) or there is no
|
|
664
|
+
* such run. */
|
|
665
|
+
heldAt(runId: string): Promise<number | undefined>;
|
|
644
666
|
/** Claims up to `k` claimable runs for `runner`, oldest first, in one transaction: each at its own epoch + 1, with its
|
|
645
667
|
* `from`. A runner fills its free loops with one call. */
|
|
646
668
|
claimMany(runner: string, k: number, options?: {
|
|
@@ -818,6 +840,9 @@ export interface Settings {
|
|
|
818
840
|
get(key: string): Promise<unknown | undefined>;
|
|
819
841
|
/** Saves `value` (JSON) under `key`, inserted or replaced in place. */
|
|
820
842
|
put(key: string, value: unknown): Promise<void>;
|
|
843
|
+
/** Saves `value` under `key` only when the key has no row yet, in one statement, so of two processes that race the first
|
|
844
|
+
* wins; the value saved under it after (this one, or the one there before). */
|
|
845
|
+
putIfAbsent(key: string, value: unknown): Promise<unknown>;
|
|
821
846
|
/** The key's row goes; a key with no row is left as it is. */
|
|
822
847
|
remove(key: string): Promise<void>;
|
|
823
848
|
/** Every setting, by key. */
|
|
@@ -943,15 +968,15 @@ export interface SignInRow {
|
|
|
943
968
|
readonly verifiedAt: number | null;
|
|
944
969
|
}
|
|
945
970
|
/** A forgotten sign-in's pointer, kept sealed byte for byte as its live row held it (so it still opens under the same
|
|
946
|
-
* binding), only so a server started later can cut it from what a run it was handed shows
|
|
971
|
+
* binding), only so a server started later can cut it from what a run it was handed shows and from what its agent
|
|
972
|
+
* learned. Every one is kept, never only the newest: a note may quote the agent's first pointer, and a shorter list
|
|
973
|
+
* would show it. */
|
|
947
974
|
export interface SignInTombstoneRow {
|
|
948
975
|
readonly agentId: string;
|
|
949
976
|
readonly provider: string;
|
|
950
977
|
readonly pointerSealed: Uint8Array;
|
|
951
978
|
readonly forgottenAt: number;
|
|
952
979
|
}
|
|
953
|
-
/** How many forgotten pointers an agent keeps per store, the oldest dropped first. */
|
|
954
|
-
export declare const SIGN_IN_TOMBSTONES_KEPT = 32;
|
|
955
980
|
export interface SignIns {
|
|
956
981
|
/** Saves the one live sign-in for the agent and provider, its pointer already sealed by the caller: inserted, or replaced
|
|
957
982
|
* in place when one is saved already (one per agent and provider). */
|
|
@@ -990,7 +1015,7 @@ export interface SignIns {
|
|
|
990
1015
|
/** Forgets the agent's live sign-in for the provider, in the one transaction a launch shares as its lock: when a running
|
|
991
1016
|
* run holds `hash` in its sign_in_handed (or, with `heldUnreadable`, when any running run was handed a sign-in at all),
|
|
992
1017
|
* the forget is refused (SignInHandedTo, naming the run) and nothing is written; otherwise the live row's sealed pointer
|
|
993
|
-
* moves to a tombstone (
|
|
1018
|
+
* moves to a tombstone (every one kept) and the live row goes. SignInMissing when the agent has
|
|
994
1019
|
* no live sign-in for the provider. */
|
|
995
1020
|
forget(agentId: string, provider: string, held: {
|
|
996
1021
|
hash?: string;
|
|
@@ -1242,6 +1267,13 @@ export declare class StoreConstraint extends Error {
|
|
|
1242
1267
|
};
|
|
1243
1268
|
});
|
|
1244
1269
|
}
|
|
1270
|
+
/** An agent's current revision is not the one a conditional write expected (addRevision's `ifCurrent`): another write
|
|
1271
|
+
* moved it first. `current` is the agent's current revision now. Nothing was written. */
|
|
1272
|
+
export declare class RevisionMoved extends Error {
|
|
1273
|
+
readonly agentId: string;
|
|
1274
|
+
readonly current: string | null;
|
|
1275
|
+
constructor(agentId: string, current: string | null);
|
|
1276
|
+
}
|
|
1245
1277
|
/** Forgetting a sign-in a running run was handed: refused, nothing written. `runId` is the run that holds it. */
|
|
1246
1278
|
export declare class SignInHandedTo extends Error {
|
|
1247
1279
|
readonly runId: string;
|
package/dist/store/store.js
CHANGED
|
@@ -48,8 +48,6 @@ export const STORE_WRITE_DEADLINE_MS = 10_000;
|
|
|
48
48
|
* slow commit is still landing a set whose token the provider already spent, and a waiter then takes over and refreshes
|
|
49
49
|
* with the spent one. Made from the two bounds so it cannot drift. */
|
|
50
50
|
export const MCP_REFRESH_LEASE_MS = MCP_REFRESH_CALL_MS + STORE_WRITE_DEADLINE_MS + 2_000;
|
|
51
|
-
/** How many forgotten pointers an agent keeps per store, the oldest dropped first. */
|
|
52
|
-
export const SIGN_IN_TOMBSTONES_KEPT = 32;
|
|
53
51
|
/** A write under a claim whose epoch is no longer the run's: refused, and nothing written. */
|
|
54
52
|
export class Fenced extends Error {
|
|
55
53
|
runId;
|
|
@@ -172,6 +170,18 @@ export class StoreConstraint extends Error {
|
|
|
172
170
|
this.unique = details.unique;
|
|
173
171
|
}
|
|
174
172
|
}
|
|
173
|
+
/** An agent's current revision is not the one a conditional write expected (addRevision's `ifCurrent`): another write
|
|
174
|
+
* moved it first. `current` is the agent's current revision now. Nothing was written. */
|
|
175
|
+
export class RevisionMoved extends Error {
|
|
176
|
+
agentId;
|
|
177
|
+
current;
|
|
178
|
+
constructor(agentId, current) {
|
|
179
|
+
super(`the current revision of agent ${agentId} moved (now ${current ?? "none"})`);
|
|
180
|
+
this.agentId = agentId;
|
|
181
|
+
this.current = current;
|
|
182
|
+
this.name = "RevisionMoved";
|
|
183
|
+
}
|
|
184
|
+
}
|
|
175
185
|
/** Forgetting a sign-in a running run was handed: refused, nothing written. `runId` is the run that holds it. */
|
|
176
186
|
export class SignInHandedTo extends Error {
|
|
177
187
|
runId;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Context } from "@earendil-works/chord";
|
|
2
2
|
import { type Meters } from "../cap.js";
|
|
3
3
|
import type { Store } from "../store/store.js";
|
|
4
|
-
/** What a run
|
|
4
|
+
/** What a run has spent, as the cap reads it, from the one store's journal: its model requests and its paid tool calls. */
|
|
5
5
|
export declare function spentOverStore(store: Store, runId: string, context: Context): Promise<number | null>;
|
|
6
6
|
/** /usage's meters for a run that ended, over the one store's journal (design 2.1): cap.ts meterFiguresFrom over A's
|
|
7
7
|
* entries, with the run's paid tool charges folded back from its paid-tools session (journal.ts withPaidCosts) as the
|
package/dist/store-reads/cap.js
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import { meterFiguresFrom, spentFrom } from "../cap.js";
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { bookedCapSpend, bookedSpend, costIsBooked } from "../runner/metrics.js";
|
|
3
|
+
import { isCliRecord, runEntries, withPaidCosts } from "./journal.js";
|
|
4
|
+
/** What a run has spent, as the cap reads it, from the one store's journal: its model requests and its paid tool calls. */
|
|
4
5
|
export async function spentOverStore(store, runId, context) {
|
|
5
|
-
|
|
6
|
+
const entries = await runEntries(store, runId, context);
|
|
7
|
+
// A run whose record carries no cost of its own (a CLI harness's, a workflow's) reads what its sessions booked, the
|
|
8
|
+
// figure its cap holds it to (metrics.ts bookedCapSpend), its record's answers reading $0: 0 before any request, an
|
|
9
|
+
// unknown booked spend unknown (null).
|
|
10
|
+
if (costIsBooked(entries, isCliRecord(entries)))
|
|
11
|
+
return bookedCapSpend(entries);
|
|
12
|
+
// A pi run's paid tool calls (a browser's time, a search, a monid call) are booked on the run's one ledger, not its root:
|
|
13
|
+
// folded back as the charges the file-backed root held (withPaidCosts), as metersOverStore reads them, so a live run's
|
|
14
|
+
// listed spend counts them.
|
|
15
|
+
return spentFrom(withPaidCosts(entries));
|
|
6
16
|
}
|
|
7
17
|
/** /usage's meters for a run that ended, over the one store's journal (design 2.1): cap.ts meterFiguresFrom over A's
|
|
8
18
|
* entries, with the run's paid tool charges folded back from its paid-tools session (journal.ts withPaidCosts) as the
|
|
@@ -13,5 +23,13 @@ export async function metersOverStore(store, runId, context) {
|
|
|
13
23
|
const raw = await runEntries(store, runId, context);
|
|
14
24
|
if (!raw.length)
|
|
15
25
|
return { tools: 0, tokens: null, browser: { usd: 0, seconds: 0 }, others: 0, known: { tokens: 0, browser: 0, others: 0 } };
|
|
16
|
-
|
|
26
|
+
const figures = meterFiguresFrom(withPaidCosts(raw).map((entry) => ({ conversation: Number(entry.conversationId ?? 0), entry })));
|
|
27
|
+
// A run whose record carries no cost of its own (a CLI harness's, a workflow's): its tokens meter is its model requests
|
|
28
|
+
// at what they were booked at (metrics.ts bookedSpend, the one reader), never the $0 its record reads.
|
|
29
|
+
if (!costIsBooked(raw, isCliRecord(raw)))
|
|
30
|
+
return figures;
|
|
31
|
+
const model = bookedSpend(raw, "model");
|
|
32
|
+
if (!model.requests)
|
|
33
|
+
return figures;
|
|
34
|
+
return { ...figures, tokens: model.usd, known: { ...figures.known, tokens: model.known } };
|
|
17
35
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Context } from "@earendil-works/chord";
|
|
2
|
-
import type { EntryLike, TimelineEvent, TimelineOptions } from "
|
|
2
|
+
import type { EntryLike, TimelineEvent, TimelineOptions } from "../timeline/index.js";
|
|
3
3
|
import { Hearing } from "../heard.js";
|
|
4
|
-
import { type Reflect } from "../
|
|
4
|
+
import { type Reflect } from "../reflect-range.js";
|
|
5
5
|
import type { Store } from "../store/store.js";
|
|
6
6
|
/** A run's entries from the one store, in log order (by id across every conversation), as the old "SELECT record FROM
|
|
7
7
|
* entries ORDER BY id" read them for a settled run. A run with no journal reads as none. */
|
|
@@ -18,13 +18,32 @@ export declare function runReflect(store: Store, runId: string, context: Context
|
|
|
18
18
|
* given back unused shows nothing. Each charge is placed right after its call's result, joined by `call`, as the ledger
|
|
19
19
|
* wrote it there. A run with no paid-tools session reads unchanged. */
|
|
20
20
|
export declare function withPaidCosts(entries: readonly EntryLike[]): EntryLike[];
|
|
21
|
+
/** Whether `entries` are a CLI harness's record (its loop's calls and messages). */
|
|
22
|
+
export declare const isCliRecord: (entries: readonly EntryLike[]) => boolean;
|
|
21
23
|
/** A run's timeline rows, the renderer (timelineOf) unchanged, over the one store's entries, with a CLI harness's record
|
|
22
24
|
* rendered as its pi-shaped entries (piShaped) and its paid tool charges read back from the paid-tools session
|
|
23
|
-
* (withPaidCosts).
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* (
|
|
25
|
+
* (withPaidCosts). A run whose record carries no per-request cost (a CLI harness's, a workflow's: metrics.ts
|
|
26
|
+
* costIsBooked) has the usage row the renderer folds from its model turns put in its booking's words (bookedUsage): its
|
|
27
|
+
* model requests at what the run's model proxy booked them at, and its paid tool calls at what they charged, as a pi
|
|
28
|
+
* run's usage row counts them; its decisions' rows and cost come from their receipts (decision-rows.ts withDecisions),
|
|
29
|
+
* once. The end-of-run turn's rows are labelled as the server labels them (reflect-range.ts labelled). */
|
|
27
30
|
export declare function runTimeline(store: Store, runId: string, context: Context, options?: TimelineOptions): Promise<TimelineEvent[]>;
|
|
31
|
+
/** How a reader serves an answer whole: its redactor over the whole text (key-refusal.ts redactedAnswer with the run's
|
|
32
|
+
* values), and a key for those values (their digest), so an answer is read once per held value set. */
|
|
33
|
+
export type WholeAnswer = {
|
|
34
|
+
readonly serve: (text: string) => string;
|
|
35
|
+
readonly key: string;
|
|
36
|
+
};
|
|
37
|
+
/** The WholeAnswer of a run whose served words are cut of `values` (run-cut.ts runCutValues). */
|
|
38
|
+
export declare const wholeAnswerFor: (values: readonly string[]) => WholeAnswer;
|
|
39
|
+
/** `rows` (runTimeline's, rendered with `options`) with each final answer whole, as main served a run's answer: the renderer
|
|
40
|
+
* cuts a row's text at CAPS.text, and its redactor (`options.redact`, key-refusal.ts redacted) reads only the head a row
|
|
41
|
+
* shows and cuts the rest, ending what it cut in "..." (short of the cap when it replaced a held value there), or giving
|
|
42
|
+
* "[redacted]" alone when all it read was redacted. A final answer row at the cap, ending so or reading so is read again
|
|
43
|
+
* from the journal, settled as the rows were, with no text cap and none
|
|
44
|
+
* of the rows' redactor, the same row by its id (its entry's), and given through `whole.serve`, which reads every byte
|
|
45
|
+
* of it and never cuts. Every other row is as it was. */
|
|
46
|
+
export declare function wholeAnswers(store: Store, runId: string, context: Context, rows: TimelineEvent[], options: TimelineOptions, whole: WholeAnswer): Promise<TimelineEvent[]>;
|
|
28
47
|
/** What was said to a run (its hearing), from the one store's entries, as runs.ts noteTurns fed it from the stream: each
|
|
29
48
|
* user entry noted in log order, its origin read by the same matcher. */
|
|
30
49
|
export declare function runHearing(store: Store, runId: string, context: Context): Promise<Hearing>;
|