@parcha/agentrun-serve 0.1.0-beta.33 → 0.1.0-beta.35
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 +368 -0
- package/README.md +341 -208
- package/dist/adapters.d.ts +3 -4
- package/dist/adapters.js +18 -15
- package/dist/agent-rows.d.ts +99 -0
- package/dist/agent-rows.js +1 -0
- package/dist/agents-store.d.ts +6 -2
- package/dist/agents-store.js +75 -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 +1 -1
- package/dist/api-only.js +2 -2
- package/dist/archil-settings.d.ts +11 -1
- package/dist/archil-settings.js +10 -0
- package/dist/bash-read-only.d.ts +35 -0
- package/dist/bash-read-only.js +778 -0
- package/dist/box-settings.d.ts +3 -23
- package/dist/box-settings.js +7 -51
- package/dist/boxes.d.ts +17 -0
- 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 +95 -51
- package/dist/browser-live.d.ts +7 -20
- package/dist/browser-live.js +15 -93
- package/dist/browser-person.d.ts +18 -51
- package/dist/browser-person.js +94 -277
- package/dist/budget.d.ts +0 -5
- package/dist/budget.js +0 -5
- package/dist/cap.d.ts +14 -8
- package/dist/cap.js +19 -9
- package/dist/cli.js +71 -18
- 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.d.ts +20 -10
- package/dist/computer-keys.js +36 -54
- package/dist/computer-setting.d.ts +20 -3
- package/dist/computer-setting.js +58 -10
- package/dist/computers.d.ts +35 -2
- package/dist/computers.js +72 -11
- package/dist/confine.d.ts +120 -0
- package/dist/confine.js +436 -0
- package/dist/console/assets/index-B7NKTU8E.css +1 -0
- package/dist/console/assets/index-CXZMgJE7.js +550 -0
- package/dist/console/index.html +2 -2
- package/dist/content-filter.d.ts +7 -0
- package/dist/content-filter.js +23 -0
- package/dist/decision-cap.d.ts +7 -29
- package/dist/decision-cap.js +3 -94
- 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/effort-guidance.js +4 -3
- package/dist/environment.d.ts +0 -3
- package/dist/environment.js +3 -5
- package/dist/errors.d.ts +1 -2
- package/dist/errors.js +9 -9
- package/dist/explain.js +3 -1
- package/dist/filed-answer.d.ts +32 -0
- package/dist/filed-answer.js +160 -0
- package/dist/files.d.ts +1 -3
- package/dist/files.js +2 -4
- package/dist/github-connection.d.ts +1 -1
- package/dist/github-connection.js +25 -7
- package/dist/github-faux.d.ts +26 -0
- package/dist/github-faux.js +76 -0
- package/dist/github.d.ts +6 -2
- package/dist/github.js +5 -3
- package/dist/graph-served.d.ts +5 -3
- package/dist/graph-served.js +14 -6
- package/dist/graph-view.d.ts +3 -5
- package/dist/graph-view.js +9 -16
- package/dist/handed-values.d.ts +9 -0
- package/dist/handed-values.js +26 -0
- package/dist/harness-install.d.ts +1 -7
- package/dist/harness-install.js +1 -18
- package/dist/harness-opencode/adapter.d.ts +7 -0
- package/dist/harness-opencode/adapter.js +23 -6
- package/dist/harness-opencode/harness.js +0 -1
- package/dist/harness-opencode/host/policy.js +2 -2
- 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/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 +14 -15
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/key-refusal.d.ts +5 -1
- package/dist/key-refusal.js +19 -4
- package/dist/learn/check.d.ts +8 -2
- package/dist/learn/check.js +85 -31
- package/dist/learn/folder.d.ts +11 -4
- package/dist/learn/folder.js +17 -19
- package/dist/learn/grade.d.ts +18 -1
- package/dist/learn/grade.js +108 -14
- package/dist/learn/index.d.ts +5 -5
- package/dist/learn/index.js +5 -5
- package/dist/learn/learning.sh +1 -14
- package/dist/learn/notes.d.ts +14 -3
- package/dist/learn/notes.js +16 -6
- package/dist/learn/reflect.d.ts +31 -2
- package/dist/learn/reflect.js +83 -6
- package/dist/learn/relevance.d.ts +24 -0
- package/dist/learn/relevance.js +91 -0
- package/dist/learn/secrets.d.ts +7 -1
- package/dist/learn/secrets.js +86 -19
- package/dist/learn/skills.d.ts +159 -18
- package/dist/learn/skills.js +644 -64
- package/dist/learned-nodes.d.ts +14 -0
- package/dist/learned-nodes.js +8 -0
- package/dist/learned-workflow.d.ts +41 -6
- package/dist/learned-workflow.js +153 -18
- package/dist/learning-routes.d.ts +49 -4
- package/dist/learning-routes.js +113 -31
- package/dist/learning-run.d.ts +16 -31
- package/dist/learning-run.js +31 -38
- package/dist/learning-words.d.ts +12 -5
- package/dist/learning-words.js +18 -9
- package/dist/learning.d.ts +91 -97
- package/dist/learning.js +176 -320
- package/dist/live/stream.js +1 -1
- package/dist/live/translate.js +12 -2
- package/dist/llm.d.ts +4 -1
- package/dist/llm.js +4 -2
- package/dist/local-models.d.ts +11 -5
- package/dist/local-models.js +13 -8
- package/dist/mcp-gateway.d.ts +17 -49
- package/dist/mcp-gateway.js +55 -136
- 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 +18 -18
- package/dist/mcp-servers-store.js +12 -14
- package/dist/mcp-store.js +3 -4
- package/dist/mcp.js +4 -3
- package/dist/model.d.ts +9 -7
- package/dist/model.js +51 -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 +156 -58
- package/dist/page.d.ts +1 -3
- package/dist/page.js +6 -18
- package/dist/paid-calls.d.ts +21 -27
- package/dist/paid-calls.js +26 -61
- package/dist/pause.d.ts +2 -19
- package/dist/pause.js +5 -74
- package/dist/port-models.d.ts +10 -3
- package/dist/port-models.js +26 -6
- package/dist/propose.d.ts +2 -0
- package/dist/propose.js +80 -45
- 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 -11
- package/dist/run-db.js +2 -37
- package/dist/run-launch.d.ts +21 -2
- package/dist/run-launch.js +14 -5
- package/dist/run-learning-served.d.ts +21 -4
- package/dist/run-learning-served.js +23 -13
- package/dist/run-reads-over-store.d.ts +5 -3
- package/dist/run-reads-over-store.js +25 -14
- package/dist/run-secrets.d.ts +1 -1
- package/dist/run-timeline-served.d.ts +5 -1
- package/dist/run-timeline-served.js +27 -6
- package/dist/run-view.d.ts +37 -22
- package/dist/run-view.js +85 -38
- package/dist/runnable.d.ts +21 -10
- package/dist/runnable.js +35 -12
- package/dist/runner/adapter-loop.d.ts +36 -5
- package/dist/runner/adapter-loop.js +663 -69
- package/dist/runner/adapter-run-spec.d.ts +42 -8
- package/dist/runner/adapter-run-spec.js +186 -52
- package/dist/runner/adapters/index.js +11 -1
- package/dist/runner/adapters/pi.d.ts +40 -2
- package/dist/runner/adapters/pi.js +110 -27
- package/dist/runner/beside.d.ts +38 -3
- package/dist/runner/beside.js +54 -5
- package/dist/runner/claim-secrets.d.ts +16 -1
- package/dist/runner/claim-secrets.js +62 -14
- package/dist/runner/cli-run-spec.d.ts +5 -0
- package/dist/runner/cli-run-spec.js +159 -41
- 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.d.ts +1 -0
- package/dist/runner/conformance/harness.js +123 -13
- 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.d.ts +7 -2
- package/dist/runner/github-app.js +47 -16
- package/dist/runner/harness-loops.d.ts +15 -2
- package/dist/runner/harness-loops.js +38 -2
- package/dist/runner/journal-kinds.d.ts +60 -6
- package/dist/runner/journal-kinds.js +43 -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 +194 -20
- package/dist/runner/learning-loop.d.ts +7 -0
- package/dist/runner/learning-loop.js +36 -8
- package/dist/runner/learning-seed.d.ts +6 -0
- package/dist/runner/learning-seed.js +6 -0
- package/dist/runner/loop-contract.d.ts +4 -0
- package/dist/runner/main.d.ts +61 -9
- package/dist/runner/main.js +144 -20
- package/dist/runner/mcp-claim.d.ts +3 -0
- package/dist/runner/mcp-claim.js +7 -3
- package/dist/runner/mcp-github.d.ts +11 -2
- package/dist/runner/mcp-github.js +55 -4
- package/dist/runner/mcp-run.d.ts +2 -0
- package/dist/runner/mcp-run.js +16 -5
- package/dist/runner/memory-claim.d.ts +9 -0
- package/dist/runner/memory-claim.js +25 -0
- package/dist/runner/metrics.d.ts +46 -1
- package/dist/runner/metrics.js +156 -1
- package/dist/runner/model-route.d.ts +16 -0
- package/dist/runner/model-route.js +134 -10
- 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 +146 -18
- package/dist/runner/spec-holds.d.ts +7 -2
- package/dist/runner/spec-holds.js +4 -3
- 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-host.d.ts +7 -2
- package/dist/runner/workflow-host.js +3 -1
- package/dist/runner/workflow-loop.d.ts +10 -1
- package/dist/runner/workflow-loop.js +14 -6
- package/dist/runner/workflow-spec.d.ts +21 -0
- package/dist/runner/workflow-spec.js +217 -93
- package/dist/runs-over-store.d.ts +14 -3
- package/dist/runs-over-store.js +100 -23
- package/dist/seal-key.d.ts +0 -2
- package/dist/seal-key.js +5 -45
- 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/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 +5 -85
- package/dist/server-secrets-store.d.ts +4 -4
- package/dist/server-secrets-store.js +9 -31
- package/dist/server-secrets.d.ts +4 -9
- package/dist/server-secrets.js +12 -36
- package/dist/server.d.ts +37 -56
- package/dist/server.js +322 -134
- 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/stop-signals.d.ts +4 -2
- package/dist/stop-signals.js +5 -3
- package/dist/store/agent-body.d.ts +12 -2
- package/dist/store/agent-body.js +22 -4
- package/dist/store/deadline.d.ts +18 -0
- package/dist/store/deadline.js +45 -0
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +2 -2
- package/dist/store/open.d.ts +6 -3
- package/dist/store/open.js +2 -2
- package/dist/store/postgres/connection.d.ts +22 -2
- package/dist/store/postgres/connection.js +211 -41
- package/dist/store/postgres/migrate.d.ts +4 -0
- package/dist/store/postgres/migrate.js +9 -2
- 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 +14 -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 +41 -12
- package/dist/store/store.d.ts +35 -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 +9 -6
- package/dist/store-reads/journal.js +129 -18
- package/dist/store-reads/learning.d.ts +82 -8
- package/dist/store-reads/learning.js +184 -11
- package/dist/store-reads/workflow.d.ts +1 -1
- package/dist/store-reads/workflow.js +1 -1
- package/dist/store-view.d.ts +19 -1
- package/dist/store-view.js +95 -27
- package/dist/template-eval.d.ts +60 -4
- package/dist/template-eval.js +120 -54
- package/dist/templates.d.ts +33 -14
- package/dist/templates.js +82 -46
- 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 +282 -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-budget.d.ts +18 -0
- package/dist/tool-budget.js +50 -0
- package/dist/tool-gate.d.ts +47 -218
- package/dist/tool-gate.js +87 -545
- package/dist/tool-keys-store.d.ts +11 -12
- package/dist/tool-keys-store.js +24 -31
- package/dist/tool-keys.d.ts +5 -101
- package/dist/tool-keys.js +8 -267
- package/dist/tool-plane.d.ts +23 -52
- 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 +67 -25
- package/dist/tools.js +170 -119
- package/dist/trigger-adapter.d.ts +2 -2
- 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.d.ts +28 -5
- package/dist/uploads.js +83 -10
- package/dist/usage.d.ts +1 -49
- package/dist/usage.js +3 -84
- package/dist/validate.d.ts +4 -0
- package/dist/validate.js +33 -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/archil-claim.d.ts +2 -2
- package/dist/workspace/archil-claim.js +4 -3
- package/dist/workspace/archil-disk.d.ts +10 -1
- package/dist/workspace/archil-disk.js +4 -0
- package/dist/workspace/archil-exec.d.ts +12 -2
- package/dist/workspace/archil-exec.js +16 -0
- package/dist/workspace/archil.d.ts +2 -2
- package/dist/workspace/archil.js +25 -5
- package/dist/workspace/attach.js +2 -0
- package/dist/workspace/beneath.d.ts +19 -0
- package/dist/workspace/beneath.js +106 -0
- package/dist/workspace/computer-deps.d.ts +26 -9
- package/dist/workspace/computer-deps.js +144 -43
- package/dist/workspace/computer-for-claim.d.ts +17 -14
- package/dist/workspace/computer-for-claim.js +99 -26
- 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-ledger.d.ts +1 -8
- package/dist/workspace/computer-ledger.js +0 -3
- package/dist/workspace/computer-providers.d.ts +5 -3
- package/dist/workspace/computer-providers.js +11 -9
- package/dist/workspace/grep-worker.d.ts +5 -0
- package/dist/workspace/grep-worker.js +9 -6
- package/dist/workspace/hands.d.ts +5 -2
- package/dist/workspace/hands.js +4 -3
- package/dist/workspace/index.d.ts +6 -5
- package/dist/workspace/index.js +4 -4
- package/dist/workspace/local.d.ts +14 -2
- package/dist/workspace/local.js +170 -43
- package/dist/workspace/paths.js +3 -2
- package/dist/workspace/pi-env.d.ts +4 -0
- package/dist/workspace/pi-env.js +3 -2
- package/dist/workspace/resolve-computer.d.ts +55 -10
- package/dist/workspace/resolve-computer.js +66 -14
- package/dist/workspace/run-tools.d.ts +15 -31
- package/dist/workspace/run-tools.js +19 -30
- package/dist/workspace/workspace.d.ts +5 -0
- 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 +4 -110
- package/package.json +14 -14
- package/skills/agentrun-serve/SKILL.md +1 -1
- package/templates/README.md +11 -5
- package/templates/code-review/evals/mentions-defused/case.yaml +15 -0
- package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +254 -0
- package/templates/code-review/evals/mentions-defused/graders/no-pings.md +16 -0
- package/templates/code-review/evals/mentions-defused/graders/posted-a-review.md +5 -0
- package/templates/code-review/evals/mentions-defused/graders/schema.md +5 -0
- package/templates/code-review/evals/mentions-defused/prompt.md +10 -0
- package/templates/kyb/evals/clean-public-company/graders/no-opensanctions.md +5 -0
- package/templates/kyb/evals/opensanctions-on/case.yaml +5 -0
- package/templates/kyb/evals/opensanctions-on/graders/licence-and-evidence.md +18 -0
- package/templates/kyb/evals/opensanctions-on/graders/schema.md +5 -0
- package/templates/kyb/evals/opensanctions-on/prompt.md +11 -0
- package/templates/market-monitor/agent.md +2 -2
- package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
- package/templates/release-notes/agent.md +11 -0
- package/dist/bound-files.d.ts +0 -4
- package/dist/bound-files.js +0 -164
- 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-Dn0ngwG9.js +0 -535
- package/dist/console/assets/index-DvW6Aled.css +0 -1
- package/dist/grade.d.ts +0 -63
- package/dist/grade.js +0 -150
- 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/sealed-settings.d.ts +0 -60
- package/dist/sealed-settings.js +0 -171
- 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
package/dist/triggers.js
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
// latest fires if it is within the trigger's catch-up window and the rest are one `missed` row; the schedule goes on from
|
|
23
23
|
// now. A failed firing queues a trigger.failed webhook message.
|
|
24
24
|
import { createHash, randomBytes } from "node:crypto";
|
|
25
|
-
import { TRIGGER_LABELS } from "
|
|
25
|
+
import { TRIGGER_LABELS } from "./timeline/index.js";
|
|
26
26
|
import { ApiError, invalid } from "./errors.js";
|
|
27
27
|
import { EFFORTS } from "./model.js";
|
|
28
28
|
import { AgentArchived, StoreConstraint, TriggerFull } from "./store/index.js";
|
|
@@ -256,7 +256,7 @@ export class Triggers {
|
|
|
256
256
|
// A scope belongs to one trigger: told before anything is minted or written (the store's scope rows are the backstop).
|
|
257
257
|
if (enabled)
|
|
258
258
|
await this.scopeFree(source, id);
|
|
259
|
-
// Its secrets are kept before the trigger is: one
|
|
259
|
+
// Its secrets are kept before the trigger is: one whose secret cannot be kept makes none.
|
|
260
260
|
const minted = await this.mint(source, id);
|
|
261
261
|
const name = typeof body.name === "string" ? body.name.trim() : id;
|
|
262
262
|
let row;
|
|
@@ -755,7 +755,7 @@ export class Triggers {
|
|
|
755
755
|
const trigger = await this.find(triggerId);
|
|
756
756
|
if (!firing || !trigger || firing.status !== "failed" || firing.notified)
|
|
757
757
|
return;
|
|
758
|
-
const told = this.deps.notify({ trigger_id: trigger.id, name: trigger.name, firing_key: key, nominal_at: second(firing.nominalAt), error: firing.error ?? { code: "internal", message: "" }, auto_paused: firing.paused }, key);
|
|
758
|
+
const told = await this.deps.notify({ trigger_id: trigger.id, name: trigger.name, firing_key: key, nominal_at: second(firing.nominalAt), error: firing.error ?? { code: "internal", message: "" }, auto_paused: firing.paused }, key);
|
|
759
759
|
// A mark that does not land (the outbox's write failed) is tried again at the next tick, under the same key, which
|
|
760
760
|
// the outbox holds once: a restart then finds it marked.
|
|
761
761
|
if (told === "queued" || told === "off")
|
package/dist/turn-end.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** `{ kind: TURN_END, data: TurnEndData }`: a turn of the session `key` is over. Written in the same commit as the turn's
|
|
2
2
|
* last entries. #1424's first form held only `key` and `status`, and closes the message sent last before it. The
|
|
3
3
|
* timeline reads it too (the next message is not a steer), so the kind is the timeline's. */
|
|
4
|
-
export { TURN_END } from "
|
|
4
|
+
export { TURN_END } from "./timeline/index.js";
|
|
5
5
|
/** The root's record of a message the door accepted (`{ key, id, content }`), and of its end (`{ key, id, sent }`):
|
|
6
6
|
* `sent` to the session, or dropped by a stop. The bridge writes a TURN_END naming the message once its turn is over;
|
|
7
7
|
* for a message an older bridge sent and wrote no end for, the run's next process writes it as it opens. */
|
package/dist/turn-end.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
/** `{ kind: TURN_END, data: TurnEndData }`: a turn of the session `key` is over. Written in the same commit as the turn's
|
|
5
5
|
* last entries. #1424's first form held only `key` and `status`, and closes the message sent last before it. The
|
|
6
6
|
* timeline reads it too (the next message is not a steer), so the kind is the timeline's. */
|
|
7
|
-
export { TURN_END } from "
|
|
7
|
+
export { TURN_END } from "./timeline/index.js";
|
|
8
8
|
/** The root's record of a message the door accepted (`{ key, id, content }`), and of its end (`{ key, id, sent }`):
|
|
9
9
|
* `sent` to the session, or dropped by a stop. The bridge writes a TURN_END naming the message once its turn is over;
|
|
10
10
|
* for a message an older bridge sent and wrote no end for, the run's next process writes it as it opens. */
|
package/dist/turns.d.ts
CHANGED
|
@@ -13,12 +13,6 @@ export declare class Turns {
|
|
|
13
13
|
* the door's snapshot carries them with `answer_text`), at `now`. `skip`: entries of no turn of the run's own (its
|
|
14
14
|
* end-of-run turn's). Reading the same records again changes nothing: a turn's first end stands. */
|
|
15
15
|
note(entries: readonly unknown[], submissions?: readonly unknown[], skip?: (id: number) => boolean, now?: number): void;
|
|
16
|
-
/** A reconnect's snapshot (the door's `inputs`): the run's inputs from the newest settled one on, and every earlier one
|
|
17
|
-
* not settled yet. It is the whole state, where an event batch carries only changes: a message this ledger holds
|
|
18
|
-
* open that is missing from it, from before its newest settled input, settled while the stream was down. That one
|
|
19
|
-
* is closed, its own end unread and never the run's (the settled one after it is newer). One still queued, a
|
|
20
|
-
* follow-up a steer settled ahead of, is in the snapshot and stays open. */
|
|
21
|
-
snapshot(inputs: readonly unknown[], skip?: (id: number) => boolean, now?: number): void;
|
|
22
16
|
/** How many messages the run took whose turns have not ended. */
|
|
23
17
|
get open(): number;
|
|
24
18
|
/** The newest message's turn's end, once no message is open. */
|
package/dist/turns.js
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
// codex as it is sent (or dropped by a stop), and TURN_END, in the commit of the turn's last entries.
|
|
7
7
|
// A message is open from the moment the run took it until its turn's end closes it, so a follow-up queued behind a turn
|
|
8
8
|
// keeps the run open whatever the door says meanwhile.
|
|
9
|
-
import { newestSettledInput } from "@parcha/pi-durable-disk/internals";
|
|
10
9
|
import { ADAPTER_API, MESSAGE, MESSAGE_END, TURN_END } from "./turn-end.js";
|
|
11
10
|
/** The request id prefix of a run's end-of-run turn (learning-run.ts): the server's message, never the person's. */
|
|
12
11
|
export const REFLECT_REQUEST = "learn-reflect-";
|
|
@@ -102,24 +101,6 @@ export class Turns {
|
|
|
102
101
|
for (const value of submissions)
|
|
103
102
|
this.#settle(value, skip, now);
|
|
104
103
|
}
|
|
105
|
-
/** A reconnect's snapshot (the door's `inputs`): the run's inputs from the newest settled one on, and every earlier one
|
|
106
|
-
* not settled yet. It is the whole state, where an event batch carries only changes: a message this ledger holds
|
|
107
|
-
* open that is missing from it, from before its newest settled input, settled while the stream was down. That one
|
|
108
|
-
* is closed, its own end unread and never the run's (the settled one after it is newer). One still queued, a
|
|
109
|
-
* follow-up a steer settled ahead of, is in the snapshot and stays open. */
|
|
110
|
-
snapshot(inputs, skip, now = Date.now()) {
|
|
111
|
-
this.note([], inputs, skip, now);
|
|
112
|
-
const records = inputs.filter((value) => isObject(value) && value.type === "input" && typeof value.id === "number" && typeof value.status === "string");
|
|
113
|
-
const held = new Set(records.map((value) => `s:${value.id}`));
|
|
114
|
-
// The newest settled input as the door's snapshot chose it, by the same rule: the run's own, never the end-of-run turn's.
|
|
115
|
-
const newest = newestSettledInput(records, REFLECT_REQUEST);
|
|
116
|
-
if (newest < 0)
|
|
117
|
-
return;
|
|
118
|
-
const through = records[newest].id;
|
|
119
|
-
for (const message of this.#messages.values())
|
|
120
|
-
if (message.key.startsWith("s:") && !message.end && message.order < through && !held.has(message.key))
|
|
121
|
-
message.end = { status: "answered", answer: null };
|
|
122
|
-
}
|
|
123
104
|
/** One input submission: a message taken while queued or placed, closed once it is settled. */
|
|
124
105
|
#settle(value, skip, now) {
|
|
125
106
|
if (!isObject(value) || value.type !== "input" || typeof value.id !== "number")
|
package/dist/uploads.d.ts
CHANGED
|
@@ -98,9 +98,32 @@ export declare class Uploads {
|
|
|
98
98
|
/** A run's `file_ids`: each a file that is ready, none twice, at most MAX_FILES_PER_RUN, or 422 at `file_ids`. */
|
|
99
99
|
readyFiles(ids: readonly unknown[]): Promise<UploadedFile[]>;
|
|
100
100
|
/** Copies `files` into the run's `inputs/` through its Workspace, each at its `path` with its folders, in order, before
|
|
101
|
-
* the run's
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
|
|
101
|
+
* the run's first turn: a name taken already (the same path twice, a file where another's folder goes, or what the
|
|
102
|
+
* folder held before) gets the next free suffix (`notes-2.txt`, `docs-2/`), the same for the same files in the same
|
|
103
|
+
* order. Each copy is a new file written whole by the Workspace, never a link to the upload; a link on the way fails
|
|
104
|
+
* the copy (ESCAPE), and nothing is written through it. `bytesOf`: where each file's bytes are read (its upload's own,
|
|
105
|
+
* or the run's hold of them, `held`). */
|
|
106
|
+
copyInto(work: Workspace | string, files: readonly UploadedFile[], bytesOf?: (file: UploadedFile) => string): Promise<void>;
|
|
107
|
+
/** At a run's start, before its row is written: each of its files (`ids`, ready) held for it under
|
|
108
|
+
* `<root>/.held/<run id>/`, its record and its bytes (a hard link to the upload's, which never change once ready; a
|
|
109
|
+
* copy where the disk links none). The run's claim copies from the hold (heldFiles), so a file deleted after the start
|
|
110
|
+
* and before the claim is still the run's: a started run keeps the files it was started with. In turn with each file's
|
|
111
|
+
* delete, so a hold either has the bytes or the start fails at that file (422, as readyFiles words it). */
|
|
112
|
+
hold(runId: string, ids: readonly string[]): Promise<void>;
|
|
113
|
+
/** The files run `runId` holds (hold), in `ids`' order: a file with no hold (a run started before holds, or one whose
|
|
114
|
+
* hold went) read as it is now (readyFiles). With where each one's bytes are. */
|
|
115
|
+
heldFiles(runId: string, ids: readonly string[]): Promise<{
|
|
116
|
+
files: UploadedFile[];
|
|
117
|
+
bytesOf: (file: UploadedFile) => string;
|
|
118
|
+
}>;
|
|
119
|
+
/** Lets go of run `runId`'s hold: once its files are in its workspace, or when it ends without them (released). */
|
|
120
|
+
release(runId: string): Promise<void>;
|
|
121
|
+
/** The run ids that hold files here (hold), for a start's sweep of the holds of runs that ended. */
|
|
122
|
+
holders(): Promise<string[]>;
|
|
106
123
|
}
|
|
124
|
+
/** The words a run fails in when its files cannot be copied into its workspace at its claim. */
|
|
125
|
+
export declare const notCopied: (why: string) => string;
|
|
126
|
+
/** At a run's claim: its uploaded files (`ids`, the launch's file_ids) copied into its work/inputs/ once, from its hold
|
|
127
|
+
* (Uploads.hold), and the hold let go. A resumed claim finds inputs/ there and copies nothing, so the copy's suffixes
|
|
128
|
+
* never duplicate a file across claims. A copy that fails throws in notCopied's words: the run ends failed, saying why. */
|
|
129
|
+
export declare function copyRunFiles(data: string, runId: string, workspace: Workspace, ids: readonly string[]): Promise<void>;
|
package/dist/uploads.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// Uploads: a file reserved (POST /v2/files) and its bytes sent (PUT /v2/files/{file_id}), or sent in one call (POST
|
|
2
|
-
// /v2/files?path=..., the bytes the body); listed, read and deleted; and the ready files a run names (`file_ids`)
|
|
3
|
-
// into its workspace
|
|
2
|
+
// /v2/files?path=..., the bytes the body); listed, read and deleted; and the ready files a run names (`file_ids`) held
|
|
3
|
+
// for it at its start and copied into its workspace at its claim. Each file is `<data>/files/<file_id>/`: its bytes
|
|
4
4
|
// (`bytes`) and its record (`file.json`, the contract's File), both 0600, the record written whole. A ready file's bytes
|
|
5
5
|
// never change, and a run gets a copy of them through its Workspace, never a link: nothing a run does reaches the upload.
|
|
6
6
|
import { createHash, randomBytes } from "node:crypto";
|
|
7
|
-
import { lstat, mkdir, open, readdir, readFile, rename, rm, unlink } from "node:fs/promises";
|
|
8
|
-
import { DISK_DIR } from "
|
|
7
|
+
import { copyFile, link, lstat, mkdir, open, readdir, readFile, rename, rm, unlink } from "node:fs/promises";
|
|
8
|
+
import { DISK_DIR } from "./server-fs.js";
|
|
9
9
|
import { dirname, join } from "node:path";
|
|
10
10
|
import { ApiError, invalid } from "./errors.js";
|
|
11
11
|
import { typeOf } from "./file-types.js";
|
|
@@ -22,6 +22,9 @@ export const INPUTS_DIR = "inputs";
|
|
|
22
22
|
export const UPLOADS_DIR = "files";
|
|
23
23
|
const RECORD = "file.json";
|
|
24
24
|
const BYTES = "bytes";
|
|
25
|
+
/** Under the root: each started run's hold of its files until its claim copies them (Uploads.hold). A dot-name, never a
|
|
26
|
+
* file id (ID starts with a letter or digit), so the files' list and the sweep pass it by. */
|
|
27
|
+
const HELD_DIR = ".held";
|
|
25
28
|
/** The `upload.expires_at` the answer to a reservation gives, which the contract requires: advisory, not enforced in this
|
|
26
29
|
* release. A later PUT is still taken, and nothing deletes an upload. */
|
|
27
30
|
const UPLOAD_WINDOW_MS = 86_400_000;
|
|
@@ -423,11 +426,12 @@ export class Uploads {
|
|
|
423
426
|
return files;
|
|
424
427
|
}
|
|
425
428
|
/** Copies `files` into the run's `inputs/` through its Workspace, each at its `path` with its folders, in order, before
|
|
426
|
-
* the run's
|
|
427
|
-
*
|
|
428
|
-
*
|
|
429
|
-
*
|
|
430
|
-
|
|
429
|
+
* the run's first turn: a name taken already (the same path twice, a file where another's folder goes, or what the
|
|
430
|
+
* folder held before) gets the next free suffix (`notes-2.txt`, `docs-2/`), the same for the same files in the same
|
|
431
|
+
* order. Each copy is a new file written whole by the Workspace, never a link to the upload; a link on the way fails
|
|
432
|
+
* the copy (ESCAPE), and nothing is written through it. `bytesOf`: where each file's bytes are read (its upload's own,
|
|
433
|
+
* or the run's hold of them, `held`). */
|
|
434
|
+
async copyInto(work, files, bytesOf = (file) => join(this.root, file.file_id, BYTES)) {
|
|
431
435
|
const workspace = workspaceAt(work);
|
|
432
436
|
await uploadTestHooks.beforeCopy?.(workspace);
|
|
433
437
|
const names = takenNames(workspace);
|
|
@@ -437,9 +441,78 @@ export class Uploads {
|
|
|
437
441
|
for (const segment of segments.slice(0, -1))
|
|
438
442
|
dir = `${dir}/${free(await names(dir), segment, "dir")}`;
|
|
439
443
|
const name = free(await names(dir), segments.at(-1), "file");
|
|
440
|
-
await workspace.write(`${dir}/${name}`, await readFile(
|
|
444
|
+
await workspace.write(`${dir}/${name}`, await readFile(bytesOf(file)));
|
|
441
445
|
}
|
|
442
446
|
}
|
|
447
|
+
/** At a run's start, before its row is written: each of its files (`ids`, ready) held for it under
|
|
448
|
+
* `<root>/.held/<run id>/`, its record and its bytes (a hard link to the upload's, which never change once ready; a
|
|
449
|
+
* copy where the disk links none). The run's claim copies from the hold (heldFiles), so a file deleted after the start
|
|
450
|
+
* and before the claim is still the run's: a started run keeps the files it was started with. In turn with each file's
|
|
451
|
+
* delete, so a hold either has the bytes or the start fails at that file (422, as readyFiles words it). */
|
|
452
|
+
async hold(runId, ids) {
|
|
453
|
+
const dir = join(this.root, HELD_DIR, runId);
|
|
454
|
+
await mkdir(dir, { recursive: true, mode: 0o700 });
|
|
455
|
+
for (const [i, id] of ids.entries()) {
|
|
456
|
+
await this.exclusive(id, async () => {
|
|
457
|
+
const file = await this.get(id);
|
|
458
|
+
if (file?.status !== "ready")
|
|
459
|
+
throw invalid([{ field: `file_ids[${i}]`, reason: "not_an_option", message: `There is no file ${id}: reserve it with POST /v2/files.` }]);
|
|
460
|
+
const bytes = join(dir, `${id}.${BYTES}`);
|
|
461
|
+
await link(join(this.root, id, BYTES), bytes).catch(async (error) => {
|
|
462
|
+
if (error.code !== "EEXIST")
|
|
463
|
+
await copyFile(join(this.root, id, BYTES), bytes);
|
|
464
|
+
});
|
|
465
|
+
await writeDurable(join(dir, `${id}.json`), `${JSON.stringify(file)}\n`);
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
/** The files run `runId` holds (hold), in `ids`' order: a file with no hold (a run started before holds, or one whose
|
|
470
|
+
* hold went) read as it is now (readyFiles). With where each one's bytes are. */
|
|
471
|
+
async heldFiles(runId, ids) {
|
|
472
|
+
const dir = join(this.root, HELD_DIR, runId);
|
|
473
|
+
const held = new Map();
|
|
474
|
+
for (const id of ids) {
|
|
475
|
+
const record = ID.test(id) ? await readJson(join(dir, `${id}.json`)) : null;
|
|
476
|
+
if (isFile(record) && record.file_id === id && (await lstat(join(dir, `${id}.${BYTES}`)).catch(() => null))?.isFile())
|
|
477
|
+
held.set(id, record);
|
|
478
|
+
}
|
|
479
|
+
const live = await this.readyFiles(ids.filter((id) => !held.has(id)));
|
|
480
|
+
const now = new Map(live.map((file) => [file.file_id, file]));
|
|
481
|
+
return {
|
|
482
|
+
files: ids.map((id) => held.get(id) ?? now.get(id)),
|
|
483
|
+
bytesOf: (file) => (held.has(file.file_id) ? join(dir, `${file.file_id}.${BYTES}`) : join(this.root, file.file_id, BYTES)),
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
/** Lets go of run `runId`'s hold: once its files are in its workspace, or when it ends without them (released). */
|
|
487
|
+
async release(runId) {
|
|
488
|
+
await rm(join(this.root, HELD_DIR, runId), { recursive: true, force: true });
|
|
489
|
+
}
|
|
490
|
+
/** The run ids that hold files here (hold), for a start's sweep of the holds of runs that ended. */
|
|
491
|
+
async holders() {
|
|
492
|
+
return (await readdir(join(this.root, HELD_DIR)).catch(() => [])).filter((name) => ID.test(name));
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
/** The words a run fails in when its files cannot be copied into its workspace at its claim. */
|
|
496
|
+
export const notCopied = (why) => `The run's files could not be copied into its workspace: ${why}`;
|
|
497
|
+
/** At a run's claim: its uploaded files (`ids`, the launch's file_ids) copied into its work/inputs/ once, from its hold
|
|
498
|
+
* (Uploads.hold), and the hold let go. A resumed claim finds inputs/ there and copies nothing, so the copy's suffixes
|
|
499
|
+
* never duplicate a file across claims. A copy that fails throws in notCopied's words: the run ends failed, saying why. */
|
|
500
|
+
export async function copyRunFiles(data, runId, workspace, ids) {
|
|
501
|
+
const uploads = new Uploads(join(data, UPLOADS_DIR));
|
|
502
|
+
const copied = await workspace.list(INPUTS_DIR).then(() => true, () => false);
|
|
503
|
+
if (!copied) {
|
|
504
|
+
try {
|
|
505
|
+
const { files, bytesOf } = await uploads.heldFiles(runId, ids);
|
|
506
|
+
await uploads.copyInto(workspace, files, bytesOf);
|
|
507
|
+
}
|
|
508
|
+
catch (error) {
|
|
509
|
+
// The run ends failed on this: its hold goes with it.
|
|
510
|
+
await uploads.release(runId).catch(() => undefined);
|
|
511
|
+
const why = error instanceof ApiError ? error.extra.fields?.map((issue) => issue.message).join("; ") || error.message : error.message;
|
|
512
|
+
throw new Error(notCopied(why), { cause: error });
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
await uploads.release(runId);
|
|
443
516
|
}
|
|
444
517
|
/** The names in each folder of `workspace`, by its path, each read once from its listing (none for a folder not there
|
|
445
518
|
* yet) and kept up to date with what the copy takes. */
|
package/dist/usage.d.ts
CHANGED
|
@@ -1,59 +1,11 @@
|
|
|
1
|
-
import { type Learning, type LearningReason, type Tokens } from "./learning.js";
|
|
2
|
-
/** On a line written since they were kept (learning.ts Learning): `seed_notes`, how many notes the run started from;
|
|
3
|
-
* `answered_at` and `job_cost_usd`, when its job's answer was final and what it had cost then, once it looked back;
|
|
4
|
-
* `look_back_usd`, what looking back cost (0 when it did not; null when unknown). */
|
|
5
|
-
export type Outcome = {
|
|
6
|
-
run: string;
|
|
7
|
-
agent: string;
|
|
8
|
-
state: "merged" | "dropped";
|
|
9
|
-
reason: LearningReason | null;
|
|
10
|
-
at: string;
|
|
11
|
-
cost: number | null;
|
|
12
|
-
tokens: Tokens | null;
|
|
13
|
-
seed_notes?: number;
|
|
14
|
-
given?: string[];
|
|
15
|
-
read?: string[];
|
|
16
|
-
answered_at?: string;
|
|
17
|
-
job_cost_usd?: number | null;
|
|
18
|
-
look_back_usd?: number | null;
|
|
19
|
-
};
|
|
20
|
-
/** A run's files as they are now, once its line is written: the latest one per run is what its line says. */
|
|
21
|
-
export type NotesLine = {
|
|
22
|
-
run: string;
|
|
23
|
-
agent: string;
|
|
24
|
-
notes: true;
|
|
25
|
-
given?: string[];
|
|
26
|
-
read?: string[];
|
|
27
|
-
};
|
|
28
|
-
type Ended = Learning & {
|
|
29
|
-
state: "merged" | "dropped";
|
|
30
|
-
};
|
|
31
|
-
/** Whether a run's learning has ended: merged or dropped, which never moves again. */
|
|
32
|
-
export declare const ended: (learning: Learning | undefined | null) => learning is Ended;
|
|
33
1
|
/** The files of the notes a run was given and read; a list left with none is absent. */
|
|
34
2
|
export type NoteFiles = {
|
|
35
3
|
given?: string[];
|
|
36
4
|
read?: string[];
|
|
37
5
|
};
|
|
38
6
|
/** A learning's notes ({file, name}) as files: an entry without a string `file` is skipped, so a learning saved out of
|
|
39
|
-
* shape never stops a reader
|
|
7
|
+
* shape never stops a reader. */
|
|
40
8
|
export declare const notesOf: (learning: {
|
|
41
9
|
given?: unknown;
|
|
42
10
|
read?: unknown;
|
|
43
11
|
}) => NoteFiles;
|
|
44
|
-
/** A ledger line's notes (files): an entry that is not a string is skipped. */
|
|
45
|
-
export declare const lineNotesOf: (line: {
|
|
46
|
-
given?: unknown;
|
|
47
|
-
read?: unknown;
|
|
48
|
-
}) => NoteFiles;
|
|
49
|
-
/** The `notes` line of run `run` of agent `agent`: its files as `learning` says them now. */
|
|
50
|
-
export declare const notesLineOf: (run: string, agent: string, learning: Learning) => NotesLine;
|
|
51
|
-
/** The line of run `run` of agent `agent`, whose learning ended as `learning` says. */
|
|
52
|
-
export declare const outcomeOf: (run: string, agent: string, learning: Ended) => Outcome;
|
|
53
|
-
/** Every run's line, by run (its first), its files as its latest `notes` line says them: a line cut short by a crash,
|
|
54
|
-
* or out of shape, is skipped. */
|
|
55
|
-
export declare function outcomes(data: string): Promise<Map<string, Outcome>>;
|
|
56
|
-
/** Writes one run's line, or its `notes` line. A line starts on a line of its own, so one a crash cut short spoils
|
|
57
|
-
* nothing after it. */
|
|
58
|
-
export declare const record: (data: string, line: Outcome | NotesLine) => Promise<void>;
|
|
59
|
-
export {};
|
package/dist/usage.js
CHANGED
|
@@ -1,92 +1,11 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
// /usage's `learning` meter reads from it what learning spent outside any run, so neither opens a run's files. A line
|
|
4
|
-
// holds the run, its agent, how its learning ended and when, how many notes it started from, when its answer was final
|
|
5
|
-
// and what its job and its look-back cost (GET /v2/agents/{id}/learning's `impact` reads these), and what its grade
|
|
6
|
-
// spent on the host after the run (the
|
|
7
|
-
// grader on the agent's model, and the injection screen when Jev is its judge), which is in no run's journal and no
|
|
8
|
-
// run's total: `cost` in dollars and `tokens`, each null when unknown, never 0, and 0 when nothing was graded. A run's
|
|
9
|
-
// learning ends once and never moves again, so a line is read once per run: one written again (a restart that found
|
|
10
|
-
// its run's end saved and its line maybe missing) is not counted twice. The notes a run was given and read are the one
|
|
11
|
-
// part that moves after (a follow-up reads another note): a `notes` line, the run's and its files only, says them anew,
|
|
12
|
-
// and the latest one wins; it never counts the run or its costs.
|
|
13
|
-
import { appendFile, readFile } from "node:fs/promises";
|
|
14
|
-
import { join } from "node:path";
|
|
15
|
-
import { LEARNING_REASONS, NO_TOKENS } from "./learning.js";
|
|
1
|
+
// A learning's notes as files: the notes a run was given and read (learning.ts Learning), each by its file, as the store's
|
|
2
|
+
// learning reads (store-reads/learning.ts) and a learning run (learning-run.ts) count them.
|
|
16
3
|
import { isObject } from "./validate.js";
|
|
17
|
-
const ledger = (data) => join(data, "learning-usage.jsonl");
|
|
18
|
-
/** Whether a run's learning has ended: merged or dropped, which never moves again. */
|
|
19
|
-
export const ended = (learning) => learning?.state === "merged" || learning?.state === "dropped";
|
|
20
4
|
const filesOf = (source, fileOf) => {
|
|
21
5
|
const files = (list) => (Array.isArray(list) ? list.flatMap((entry) => { const file = fileOf(entry); return typeof file === "string" ? [file] : []; }) : []);
|
|
22
6
|
const [given, read] = [files(source.given), files(source.read)];
|
|
23
7
|
return { ...(given.length ? { given } : {}), ...(read.length ? { read } : {}) };
|
|
24
8
|
};
|
|
25
9
|
/** A learning's notes ({file, name}) as files: an entry without a string `file` is skipped, so a learning saved out of
|
|
26
|
-
* shape never stops a reader
|
|
10
|
+
* shape never stops a reader. */
|
|
27
11
|
export const notesOf = (learning) => filesOf(learning, (entry) => (isObject(entry) ? entry.file : undefined));
|
|
28
|
-
/** A ledger line's notes (files): an entry that is not a string is skipped. */
|
|
29
|
-
export const lineNotesOf = (line) => filesOf(line, (entry) => entry);
|
|
30
|
-
/** The `notes` line of run `run` of agent `agent`: its files as `learning` says them now. */
|
|
31
|
-
export const notesLineOf = (run, agent, learning) => ({ run, agent, notes: true, ...notesOf(learning) });
|
|
32
|
-
/** The line of run `run` of agent `agent`, whose learning ended as `learning` says. */
|
|
33
|
-
export const outcomeOf = (run, agent, learning) => ({
|
|
34
|
-
run, agent, state: learning.state, reason: learning.reason, at: learning.at,
|
|
35
|
-
...(learning.cost_usd ? { cost: learning.cost_usd.grade, tokens: learning.tokens?.grade ?? null } : { cost: 0, tokens: { ...NO_TOKENS } }),
|
|
36
|
-
...(isCount(learning.seed_notes) ? { seed_notes: learning.seed_notes } : {}),
|
|
37
|
-
// The files of the notes it was given and read (learning.ts Learning), so an agent's notes count their runs after it ends.
|
|
38
|
-
...notesOf(learning),
|
|
39
|
-
...(learning.answered_at === undefined ? { look_back_usd: 0 } : { answered_at: learning.answered_at, job_cost_usd: learning.job_cost_usd ?? null, look_back_usd: learning.look_back_usd ?? null }),
|
|
40
|
-
});
|
|
41
|
-
const isUsd = (value) => value === null || (typeof value === "number" && Number.isFinite(value) && value >= 0);
|
|
42
|
-
const isCount = (value) => Number.isSafeInteger(value) && value >= 0;
|
|
43
|
-
/** Every run's line, by run (its first), its files as its latest `notes` line says them: a line cut short by a crash,
|
|
44
|
-
* or out of shape, is skipped. */
|
|
45
|
-
export async function outcomes(data) {
|
|
46
|
-
const text = await readFile(ledger(data), "utf8").catch((error) => (error.code === "ENOENT" ? "" : Promise.reject(error)));
|
|
47
|
-
const out = new Map();
|
|
48
|
-
const latest = new Map();
|
|
49
|
-
for (const line of text.split("\n")) {
|
|
50
|
-
let entry;
|
|
51
|
-
try {
|
|
52
|
-
entry = JSON.parse(line);
|
|
53
|
-
}
|
|
54
|
-
catch {
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
if (isObject(entry) && entry.notes === true && typeof entry.run === "string") {
|
|
58
|
-
latest.set(entry.run, lineNotesOf(entry));
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
if (!isObject(entry) || typeof entry.run !== "string" || typeof entry.agent !== "string" || typeof entry.at !== "string")
|
|
62
|
-
continue;
|
|
63
|
-
if ((entry.state !== "merged" && entry.state !== "dropped") || !(entry.reason === null || LEARNING_REASONS.includes(entry.reason)))
|
|
64
|
-
continue;
|
|
65
|
-
if (!(entry.cost === null || typeof entry.cost === "number"))
|
|
66
|
-
continue;
|
|
67
|
-
if (entry.seed_notes !== undefined && !isCount(entry.seed_notes))
|
|
68
|
-
delete entry.seed_notes;
|
|
69
|
-
for (const key of ["given", "read"])
|
|
70
|
-
if (entry[key] !== undefined && !(Array.isArray(entry[key]) && entry[key].every((file) => typeof file === "string")))
|
|
71
|
-
delete entry[key];
|
|
72
|
-
if (entry.answered_at !== undefined && (typeof entry.answered_at !== "string" || !Date.parse(entry.answered_at)))
|
|
73
|
-
delete entry.answered_at;
|
|
74
|
-
for (const key of ["job_cost_usd", "look_back_usd"])
|
|
75
|
-
if (entry[key] !== undefined && !isUsd(entry[key]))
|
|
76
|
-
delete entry[key];
|
|
77
|
-
if (!out.has(entry.run))
|
|
78
|
-
out.set(entry.run, entry);
|
|
79
|
-
}
|
|
80
|
-
for (const [run, files] of latest) {
|
|
81
|
-
const outcome = out.get(run);
|
|
82
|
-
if (!outcome)
|
|
83
|
-
continue;
|
|
84
|
-
delete outcome.given;
|
|
85
|
-
delete outcome.read;
|
|
86
|
-
Object.assign(outcome, files);
|
|
87
|
-
}
|
|
88
|
-
return out;
|
|
89
|
-
}
|
|
90
|
-
/** Writes one run's line, or its `notes` line. A line starts on a line of its own, so one a crash cut short spoils
|
|
91
|
-
* nothing after it. */
|
|
92
|
-
export const record = (data, line) => appendFile(ledger(data), `\n${JSON.stringify(line)}\n`, { mode: 0o600 });
|
package/dist/validate.d.ts
CHANGED
|
@@ -11,6 +11,10 @@ export declare const stable: (value: unknown) => string;
|
|
|
11
11
|
export declare const DEFINITION_FIELDS: string[];
|
|
12
12
|
/** Why a field a definition may have elsewhere has no place in an agent store's revision. */
|
|
13
13
|
export declare const NOT_KEPT: Record<string, string>;
|
|
14
|
+
/** The most tool calls an agent's budget (max_tool_calls, tool-budget.ts) may name. */
|
|
15
|
+
export declare const MAX_TOOL_CALLS = 1000;
|
|
16
|
+
/** The most bytes an agent's output_schema takes, as JSON. */
|
|
17
|
+
export declare const MAX_OUTPUT_SCHEMA_BYTES: number;
|
|
14
18
|
/** `provider/model-id`. */
|
|
15
19
|
export declare const MODEL_REF: RegExp;
|
|
16
20
|
/** A body's fields that `allowed` does not name, each as the 422's not_allowed issue. */
|
package/dist/validate.js
CHANGED
|
@@ -4,9 +4,10 @@ import { HARNESSES } from "./harness.js";
|
|
|
4
4
|
import { THINKING_LEVELS } from "./model.js";
|
|
5
5
|
import { placeIssues } from "./place.js";
|
|
6
6
|
import { computerIssues, settingConflict } from "./computer-setting.js";
|
|
7
|
-
import {
|
|
7
|
+
import { settingsIssues } from "./tool-plane.js";
|
|
8
8
|
import { CAP_MODES } from "./cap.js";
|
|
9
9
|
import { APPROVALS } from "./approvals.js";
|
|
10
|
+
import { schemaCheck } from "./answer-json.js";
|
|
10
11
|
export const ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
11
12
|
/** An inline agent's source or kind in its external reference (POST /runs): no colon, which the reference's key splits on. */
|
|
12
13
|
export const EXTERNAL_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
|
|
@@ -16,12 +17,15 @@ export const isObject = (value) => typeof value === "object" && value !== null &
|
|
|
16
17
|
/** How long an Idempotency-Key answers with its first answer (capabilities' limits.idempotency_ttl_s). */
|
|
17
18
|
export const IDEMPOTENCY_TTL_S = 86_400;
|
|
18
19
|
export const stable = (value) => Array.isArray(value) ? `[${value.map(stable).join(",")}]` : isObject(value) ? `{${Object.keys(value).sort().map((k) => `${JSON.stringify(k)}:${stable(value[k])}`).join(",")}}` : JSON.stringify(value);
|
|
19
|
-
export const DEFINITION_FIELDS = ["id", "version", "name", "description", "instructions", "workflow", "model", "thinking", "harness", "place", "computer", "learning", "skills", "tools", "tool_settings", "approvals", "max_cost_usd", "cap_mode"];
|
|
20
|
+
export const DEFINITION_FIELDS = ["id", "version", "name", "description", "instructions", "workflow", "model", "thinking", "harness", "place", "computer", "learning", "skills", "tools", "tool_settings", "approvals", "max_cost_usd", "cap_mode", "output_schema", "max_tool_calls"];
|
|
20
21
|
/** Why a field a definition may have elsewhere has no place in an agent store's revision. */
|
|
21
22
|
export const NOT_KEPT = {
|
|
22
23
|
input_schema: "The agent store keeps no input_schema: an agentic run takes {content}, and a workflow checks its input against its own schema.",
|
|
23
|
-
output_schema: "The agent store keeps no output_schema: a workflow run's output is its workflow's.",
|
|
24
24
|
};
|
|
25
|
+
/** The most tool calls an agent's budget (max_tool_calls, tool-budget.ts) may name. */
|
|
26
|
+
export const MAX_TOOL_CALLS = 1_000;
|
|
27
|
+
/** The most bytes an agent's output_schema takes, as JSON. */
|
|
28
|
+
export const MAX_OUTPUT_SCHEMA_BYTES = 64 * 1024;
|
|
25
29
|
/** `provider/model-id`. */
|
|
26
30
|
export const MODEL_REF = /^[^/\s]+\/\S+$/;
|
|
27
31
|
const SKILL_FILE = "/SKILL.md";
|
|
@@ -93,22 +97,29 @@ export function definitionIssues(definition, { at = "definition", creating = tru
|
|
|
93
97
|
else if (typeof d.learning !== "boolean")
|
|
94
98
|
out.push(issue(`${at}.learning`, "wrong_type", `${at}.learning is true or false`));
|
|
95
99
|
}
|
|
100
|
+
// An agentic revision's structured answer: the JSON Schema its final answer's last fenced json block meets, read into a
|
|
101
|
+
// completed run's result.output (answer-json.ts structuredAnswer). A workflow's output is its workflow's own.
|
|
102
|
+
if (d.output_schema !== undefined) {
|
|
103
|
+
if (d.workflow !== undefined)
|
|
104
|
+
out.push(issue(`${at}.output_schema`, "not_allowed", "A workflow revision keeps no output_schema: its run's output is its workflow's.", `Remove ${at}.output_schema.`));
|
|
105
|
+
else if (!isObject(d.output_schema))
|
|
106
|
+
out.push(issue(`${at}.output_schema`, "wrong_type", `${at}.output_schema is a JSON Schema object`));
|
|
107
|
+
else if (Buffer.byteLength(JSON.stringify(d.output_schema)) > MAX_OUTPUT_SCHEMA_BYTES)
|
|
108
|
+
out.push(issue(`${at}.output_schema`, "too_long", `${at}.output_schema is over ${MAX_OUTPUT_SCHEMA_BYTES} bytes as JSON`));
|
|
109
|
+
else {
|
|
110
|
+
const compiled = schemaCheck(d.output_schema);
|
|
111
|
+
if ("why" in compiled)
|
|
112
|
+
out.push(issue(`${at}.output_schema`, "bad_format", `${at}.output_schema ${compiled.why}`));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
96
115
|
if (d.skills !== undefined)
|
|
97
116
|
names(d.skills, `${at}.skills`, out);
|
|
98
117
|
if (d.tools !== undefined)
|
|
99
118
|
names(d.tools, `${at}.tools`, out);
|
|
100
119
|
// The agent's own tool settings, over the server's (tool-plane.ts); an edit that leaves them out keeps none.
|
|
101
120
|
if (d.tool_settings !== undefined) {
|
|
102
|
-
|
|
103
|
-
out.push(...
|
|
104
|
-
// An agent's own pin, once its store keeps one (AGENT_LAYER_PINS); until then a pin that is one is the server's to set.
|
|
105
|
-
if (!AGENT_LAYER_PINS && isObject(d.tool_settings)) {
|
|
106
|
-
for (const [name, setting] of Object.entries(d.tool_settings)) {
|
|
107
|
-
const field = `${at}.tool_settings.${name}.pin`;
|
|
108
|
-
if (isObject(setting) && setting.pin !== undefined && !settings.some((one) => one.field === field || one.field.startsWith(`${field}.`)))
|
|
109
|
-
out.push(issue(field, "not_set_up_here", AGENT_PIN_LATER));
|
|
110
|
-
}
|
|
111
|
-
}
|
|
121
|
+
// An agent's own pin among them, kept as given (the gate holds its runs to it).
|
|
122
|
+
out.push(...settingsIssues(d.tool_settings, `${at}.tool_settings`, "agent"));
|
|
112
123
|
}
|
|
113
124
|
// Whether the agent's runs ask a person (the gate as its settings say) or run unattended, an ask allowed: never over a
|
|
114
125
|
// deny. An edit that leaves it out asks, as one that leaves out tool_settings keeps none: no edit makes an agent
|
|
@@ -116,11 +127,19 @@ export function definitionIssues(definition, { at = "definition", creating = tru
|
|
|
116
127
|
if (d.approvals !== undefined && !APPROVALS.includes(d.approvals))
|
|
117
128
|
out.push(issue(`${at}.approvals`, "not_an_option", `${at}.approvals is one of ${APPROVALS.join(", ")}: ask, the default, waits for a person where a tool is set to ask; never runs the agent unattended, each such tool allowed, while a deny still refuses`));
|
|
118
129
|
// The agent's default cap of each run started without one of its own: above 0 sets it, 0 clears it (no default), and
|
|
119
|
-
// an edit that leaves it out keeps the agent's (agents.ts), so leaving a field out never removes a spend limit.
|
|
130
|
+
// an edit that leaves it out keeps the agent's (agents-store.ts), so leaving a field out never removes a spend limit.
|
|
120
131
|
if (d.max_cost_usd !== undefined) {
|
|
121
132
|
if (!(typeof d.max_cost_usd === "number" && Number.isFinite(d.max_cost_usd) && d.max_cost_usd >= 0))
|
|
122
133
|
out.push(issue(`${at}.max_cost_usd`, "wrong_type", `${at}.max_cost_usd is a number of at least 0, in US dollars: above 0 sets the agent's default cap, 0 clears it`));
|
|
123
134
|
}
|
|
135
|
+
// The tool calls each conversation of an agentic run may make (tool-budget.ts): above 0 sets the budget, 0 clears it, and
|
|
136
|
+
// an edit that leaves it out keeps the agent's, as the default cap is kept.
|
|
137
|
+
if (d.max_tool_calls !== undefined) {
|
|
138
|
+
if (d.workflow !== undefined)
|
|
139
|
+
out.push(issue(`${at}.max_tool_calls`, "not_allowed", "A workflow revision keeps no tool-call budget: its nodes are its steps.", `Remove ${at}.max_tool_calls.`));
|
|
140
|
+
else if (!(Number.isSafeInteger(d.max_tool_calls) && d.max_tool_calls >= 0 && d.max_tool_calls <= MAX_TOOL_CALLS))
|
|
141
|
+
out.push(issue(`${at}.max_tool_calls`, "wrong_type", `${at}.max_tool_calls is a whole number from 0 to ${MAX_TOOL_CALLS}: above 0, the tool calls each conversation of a run may make before every further call is refused with words that say to answer now; 0 clears it`));
|
|
142
|
+
}
|
|
124
143
|
// How a run's cap prices its requests (cap.ts CapMode): kept, as the default cap is, by an edit that leaves it out.
|
|
125
144
|
if (d.cap_mode !== undefined) {
|
|
126
145
|
if (!CAP_MODES.includes(d.cap_mode))
|