@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/agents.js
CHANGED
|
@@ -1,20 +1,8 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { DatabaseSync } from "node:sqlite";
|
|
7
|
-
import { AgentHomeError, openStore, STORE_FILE } from "@parcha/pi-durable-agent";
|
|
8
|
-
import { agentLink } from "./console-links.js";
|
|
9
|
-
import { ApiError, invalid } from "./errors.js";
|
|
10
|
-
import { harnessOfBody } from "./harness.js";
|
|
11
|
-
import { storedHarness } from "./harness-table.js";
|
|
12
|
-
import { isObject, skillIssues, skillNames, stable } from "./validate.js";
|
|
13
|
-
import { computerOfPlace, settingOfDefinition } from "./computer-setting.js";
|
|
14
|
-
/** A revision's computer as the API shows it: its own, else the one its place says (a revision saved before the setting
|
|
15
|
-
* keeps its place alone); none when it names neither (the host's default applies). */
|
|
16
|
-
const computerView = (body) => body.computer ? { computer: body.computer } : body.place ? { computer: computerOfPlace(body.place) } : {};
|
|
17
|
-
import { approvalsOf } from "./approvals.js";
|
|
1
|
+
// How a request waits out a busy store: SQLite's busy or locked, or the agent home's own `busy`, retried step by step
|
|
2
|
+
// (whenFree), then answered home_busy. The agents themselves are over the one store (agents-store.ts).
|
|
3
|
+
import { ApiError } from "./errors.js";
|
|
4
|
+
import { isObject } from "./validate.js";
|
|
5
|
+
import { StoreBusy, StoreDeadline } from "./store/index.js";
|
|
18
6
|
/** SQLITE_BUSY or SQLITE_LOCKED: another connection holds the database. */
|
|
19
7
|
export const sqliteBusy = (error) => isObject(error) && error.code === "ERR_SQLITE_ERROR" && typeof error.errcode === "number" && [5, 6].includes(error.errcode & 0xff);
|
|
20
8
|
/** How long a request waits for a busy agent store, step by step: short first, so a reader's overlap costs
|
|
@@ -39,293 +27,15 @@ export async function whenFree(act, delaysMs, onBusy) {
|
|
|
39
27
|
}
|
|
40
28
|
}
|
|
41
29
|
}
|
|
42
|
-
/** A store another writer holds: SQLite's busy or locked,
|
|
43
|
-
* store
|
|
44
|
-
|
|
30
|
+
/** A store another writer holds: SQLite's busy or locked, the one store's lock held past its busy wait (StoreBusy), or a
|
|
31
|
+
* transaction of the one store rolled back at its deadline (StoreDeadline). Nothing of the request's write was kept, so
|
|
32
|
+
* it may be sent again: every answer of the server maps it the same way, home_busy (answerOf). */
|
|
33
|
+
export const storeBusy = (error) => sqliteBusy(error) || error instanceof StoreBusy || error instanceof StoreDeadline;
|
|
45
34
|
/** The answer to a request the agent store stayed busy for. */
|
|
46
35
|
export const homeBusy = () => new ApiError("home_busy", "the agent store is busy with another write; try again", { retry_after_ms: 500 });
|
|
47
|
-
/**
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const issues = error.issues;
|
|
54
|
-
if (issues?.length)
|
|
55
|
-
throw invalid(issues.map((issue) => ({ field: `${field}${issue.path}`, reason: "invalid", code: issue.code, message: issue.message })), error.message);
|
|
56
|
-
throw invalid([{ field, reason: "invalid", message: error.message }]);
|
|
57
|
-
}
|
|
58
|
-
if (error instanceof AgentHomeError && error.code === "missing")
|
|
59
|
-
throw new ApiError("not_found", error.message);
|
|
60
|
-
if (error instanceof AgentHomeError && error.code === "stale")
|
|
61
|
-
throw new ApiError("precondition_failed", "the agent's current revision moved since the If-Match it was read at: read the agent again");
|
|
62
|
-
throw error;
|
|
63
|
-
}
|
|
64
|
-
export class Agents {
|
|
65
|
-
dir;
|
|
66
|
-
/** Never waits for another connection synchronously: what touches it goes through `request` or `whenFree`. */
|
|
67
|
-
store;
|
|
68
|
-
/** Read-only, for the store's skill texts, which its reads do not return. */
|
|
69
|
-
skills;
|
|
70
|
-
constructor(dir) {
|
|
71
|
-
this.dir = dir;
|
|
72
|
-
this.store = openStore(dir, { busyTimeoutMs: 0 });
|
|
73
|
-
this.skills = new DatabaseSync(join(dir, STORE_FILE), { readOnly: true, timeout: 0 });
|
|
74
|
-
}
|
|
75
|
-
/** A read or write of the store for a request: a busy store is waited for about 2 s (REQUEST_BUSY_MS). */
|
|
76
|
-
request(act) {
|
|
77
|
-
return whenFree(act, REQUEST_BUSY_MS);
|
|
78
|
-
}
|
|
79
|
-
closed = false;
|
|
80
|
-
close() {
|
|
81
|
-
if (this.closed)
|
|
82
|
-
return;
|
|
83
|
-
this.closed = true;
|
|
84
|
-
this.skills.close();
|
|
85
|
-
this.store.close();
|
|
86
|
-
}
|
|
87
|
-
/** Skill texts by their SHA-256. */
|
|
88
|
-
texts(shas) {
|
|
89
|
-
const out = new Map();
|
|
90
|
-
const read = this.skills.prepare("SELECT content FROM skills WHERE sha256 = ?");
|
|
91
|
-
for (const sha of shas) {
|
|
92
|
-
const row = read.get(sha);
|
|
93
|
-
if (typeof row?.content === "string")
|
|
94
|
-
out.set(sha, row.content);
|
|
95
|
-
}
|
|
96
|
-
return out;
|
|
97
|
-
}
|
|
98
|
-
/** The revision a checked definition makes; `files` are its skill files by path. */
|
|
99
|
-
revisionOf(definition, files, note) {
|
|
100
|
-
const issues = skillIssues(definition.skills, Object.keys(files));
|
|
101
|
-
if (issues.length)
|
|
102
|
-
throw invalid(issues);
|
|
103
|
-
// The default harness is never stored: naming pi and naming none are one revision.
|
|
104
|
-
const stored = typeof definition.harness === "string" ? storedHarness(definition.harness) : undefined;
|
|
105
|
-
const harness = stored ? { harness: stored } : {};
|
|
106
|
-
// Unlike the harness, a place is kept when it is runner: the default is the host's, so naming runner says something. The
|
|
107
|
-
// computer and its place are one setting: naming either keeps both (computer-setting.ts).
|
|
108
|
-
const setting = settingOfDefinition(definition);
|
|
109
|
-
const place = setting ? { place: setting.place, computer: setting.computer } : {};
|
|
110
|
-
// A capability with nothing set is none: `{web_search: {}}` and no settings are one revision.
|
|
111
|
-
const kept = Object.entries(isObject(definition.tool_settings) ? definition.tool_settings : {}).filter(([, setting]) => isObject(setting) && Object.keys(setting).length);
|
|
112
|
-
const set = kept.length ? { toolSettings: Object.fromEntries(kept) } : {};
|
|
113
|
-
// Unattended is kept only when it is asked for: an agent that asks (the default) and one that says nothing are one
|
|
114
|
-
// revision, as they were before the field.
|
|
115
|
-
const unattended = definition.approvals === "never" ? { approvals: "never" } : {};
|
|
116
|
-
const common = { skills: files, tools: definition.tools ?? [], ...harness, ...place, ...set, ...unattended, ...(note !== undefined ? { note } : {}) };
|
|
117
|
-
// A default spend cap for each run, and how it prices a request: an agentic revision's or a workflow's.
|
|
118
|
-
const capped = { ...(typeof definition.max_cost_usd === "number" && definition.max_cost_usd > 0 ? { maxCostUsd: definition.max_cost_usd } : {}), ...(typeof definition.cap_mode === "string" ? { capMode: definition.cap_mode } : {}) };
|
|
119
|
-
if (isObject(definition.workflow))
|
|
120
|
-
return { kind: "workflow", workflow: definition.workflow, ...common, ...capped };
|
|
121
|
-
// The learning switch is kept whenever a definition sets it, false included; a definition that leaves it out keeps
|
|
122
|
-
// none, and its revision id is the one it had before the switch.
|
|
123
|
-
const learning = typeof definition.learning === "boolean" ? { learning: definition.learning } : {};
|
|
124
|
-
return { kind: "agentic", instructions: definition.instructions, ...(typeof definition.model === "string" ? { model: definition.model } : {}), ...(typeof definition.thinking === "string" ? { thinking: definition.thinking } : {}), ...common, ...learning, ...capped };
|
|
125
|
-
}
|
|
126
|
-
/** `definition.version`, when given, is the number of the revision the request leaves current. */
|
|
127
|
-
checkVersion(definition, version) {
|
|
128
|
-
if (definition.version !== undefined && definition.version !== version)
|
|
129
|
-
throw invalid([{ field: "definition.version", reason: "not_an_option", message: `definition.version is ${version} here: the number of the revision this definition leaves current` }]);
|
|
130
|
-
}
|
|
131
|
-
/** A workflow revision is checked before anything is written, so a refusal makes no agent. */
|
|
132
|
-
async checked(revision) {
|
|
133
|
-
if (revision.kind !== "workflow")
|
|
134
|
-
return;
|
|
135
|
-
const { checkWorkflowBody } = await import("@parcha/pi-durable-agent/workflow");
|
|
136
|
-
await checkWorkflowBody({ workflow: revision.workflow, tools: revision.tools ?? [] }).catch((error) => storeError(error, "definition.workflow"));
|
|
137
|
-
}
|
|
138
|
-
/** A new agent and its first revision, current. A definition id already here is `409 agent_exists`. `check` sees the
|
|
139
|
-
* revision before anything is written, and may refuse it. */
|
|
140
|
-
/** `fresh`: the place a new agent that names none is saved with, and the tools it gets when it names none (place.ts
|
|
141
|
-
* newAgentPlace); an agentic definition alone takes them, and only where it leaves them out. */
|
|
142
|
-
async create({ definition, skills = {}, note }, check, fresh) {
|
|
143
|
-
const given = typeof definition.id === "string" ? definition.id : undefined;
|
|
144
|
-
if (given !== undefined && (await this.request(() => this.store.readAgent(given))))
|
|
145
|
-
throw new ApiError("agent_exists", `an agent ${given} exists here`);
|
|
146
|
-
// Stamped on the revision now, never resolved at run time: an agent saved with no place keeps running on the runner.
|
|
147
|
-
const stamped = fresh && definition.place === undefined && definition.computer === undefined && !isObject(definition.workflow) ? { place: fresh.place, ...(definition.tools === undefined ? { tools: [...fresh.tools] } : {}) } : {};
|
|
148
|
-
const revision = this.revisionOf({ ...definition, ...stamped }, skills, note);
|
|
149
|
-
this.checkVersion(definition, 1);
|
|
150
|
-
await this.checked(revision);
|
|
151
|
-
await check?.(revision);
|
|
152
|
-
let agent;
|
|
153
|
-
try {
|
|
154
|
-
agent = await this.request(() => this.store.createAgent({ name: definition.name, ...(typeof definition.description === "string" ? { description: definition.description } : {}), ...(given !== undefined ? { id: given } : {}) }));
|
|
155
|
-
}
|
|
156
|
-
catch (error) {
|
|
157
|
-
if (error instanceof AgentHomeError && error.code === "exists")
|
|
158
|
-
throw new ApiError("agent_exists", `an agent ${given} exists here`);
|
|
159
|
-
storeError(error);
|
|
160
|
-
}
|
|
161
|
-
await this.request(() => this.store.commitRevision(agent.id, revision, { setCurrent: true })).catch((error) => storeError(error));
|
|
162
|
-
return (await this.get(agent.id));
|
|
163
|
-
}
|
|
164
|
-
/** An edit: a new revision of the agent, its parent the current one, made current. Without `skills` the current
|
|
165
|
-
* revision's skill files carry over. An edit that is the current revision writes nothing, so a PUT sent twice makes
|
|
166
|
-
* one revision. The store keeps an agent's id, name and description from its creation. `ifCurrent` (from If-Match)
|
|
167
|
-
* is the current revision the caller read, null for none: the store compares it in the commit's own transaction.
|
|
168
|
-
* `check` sees the revision, the current one's included, before anything is written, and may refuse it. */
|
|
169
|
-
/** `contract`: the contract's edit, whose version the caller has checked is past the current one. It always makes a new
|
|
170
|
-
* revision, the same definition included, numbered as this store numbers them (the next), whatever version it named. */
|
|
171
|
-
async commit(read, { definition, skills, note }, { ifCurrent, check, contract = false } = {}) {
|
|
172
|
-
const held = (now) => {
|
|
173
|
-
if (ifCurrent !== undefined && (now.revision?.id ?? null) !== ifCurrent)
|
|
174
|
-
storeError(new AgentHomeError("stale", "the agent's current revision is not the one the commit expects"));
|
|
175
|
-
return now;
|
|
176
|
-
};
|
|
177
|
-
let entry = held((await this.get(read.agent.id)) ?? read);
|
|
178
|
-
const { agent } = entry;
|
|
179
|
-
const kept = [
|
|
180
|
-
...(definition.id !== undefined && definition.id !== agent.id ? [{ field: "definition.id", reason: "not_an_option", message: `definition.id is ${agent.id}, the agent's id` }] : []),
|
|
181
|
-
...["name", "description"]
|
|
182
|
-
.filter((key) => definition[key] !== undefined && definition[key] !== agent[key])
|
|
183
|
-
.map((key) => ({ field: `definition.${key}`, reason: "not_allowed", message: `The agent store keeps an agent's ${key} from its creation; an edit does not change it.`, fix: `Remove definition.${key}.` })),
|
|
184
|
-
];
|
|
185
|
-
if (kept.length)
|
|
186
|
-
throw invalid(kept);
|
|
187
|
-
// Each try builds the revision on the current one, checks it and commits it on that one: a current revision another
|
|
188
|
-
// writer moved since the build is sent back as stale, and the next try builds and checks again on the new one, so
|
|
189
|
-
// what an edit leaves out (skill files, harness, place, learning) is never carried over from a revision it does not
|
|
190
|
-
// follow.
|
|
191
|
-
for (let tries = 1;; tries++) {
|
|
192
|
-
if (tries > 1)
|
|
193
|
-
entry = held((await this.get(agent.id)) ?? entry);
|
|
194
|
-
let files = skills;
|
|
195
|
-
if (files === undefined) {
|
|
196
|
-
const held = Object.entries(entry.revision?.body.skills ?? {});
|
|
197
|
-
const texts = await this.request(() => this.texts(held.map(([, sha]) => sha)));
|
|
198
|
-
files = Object.fromEntries(held.map(([path, sha]) => [path, texts.get(sha) ?? ""]));
|
|
199
|
-
}
|
|
200
|
-
// An edit that names no harness, place, learning switch or default cap keeps the agent's, as it keeps its skill
|
|
201
|
-
// files: absent here is unchanged, not the default.
|
|
202
|
-
const harness = entry.revision?.body.harness;
|
|
203
|
-
// The computer setting with it (a revision from before it keeps its place alone, which says its computer).
|
|
204
|
-
const kept = definition.place === undefined && definition.computer === undefined ? (entry.revision?.body.computer ? { computer: entry.revision.body.computer } : entry.revision?.body.place ? { place: entry.revision.body.place } : {}) : {};
|
|
205
|
-
const learning = entry.revision?.kind === "agentic" && !isObject(definition.workflow) ? entry.revision.body.learning : undefined;
|
|
206
|
-
// And its default cap, whichever kind it was or becomes: leaving it out never removes a spend limit; only 0 clears it.
|
|
207
|
-
const cap = entry.revision?.body.maxCostUsd;
|
|
208
|
-
// And how that cap prices a request, as the cap itself is kept.
|
|
209
|
-
const capMode = entry.revision?.body.capMode;
|
|
210
|
-
const revision = this.revisionOf({ ...definition, ...(definition.harness === undefined && harness ? { harness } : {}), ...kept, ...(definition.learning === undefined && learning !== undefined ? { learning } : {}), ...(definition.max_cost_usd === undefined && cap !== undefined ? { max_cost_usd: cap } : {}), ...(definition.cap_mode === undefined && capMode !== undefined ? { cap_mode: capMode } : {}) }, files, note);
|
|
211
|
-
await this.checked(revision);
|
|
212
|
-
await check?.(revision);
|
|
213
|
-
const base = entry.revision?.id ?? null;
|
|
214
|
-
const attempt = async () => {
|
|
215
|
-
const now = held(this.entry(agent.id) ?? entry);
|
|
216
|
-
if ((now.revision?.id ?? null) !== base)
|
|
217
|
-
throw new AgentHomeError("stale", "the agent's current revision moved while the edit was checked");
|
|
218
|
-
if (!contract && now.revision && sameRevision(now.revision, revision)) {
|
|
219
|
-
this.checkVersion(definition, now.version);
|
|
220
|
-
return now;
|
|
221
|
-
}
|
|
222
|
-
if (!contract)
|
|
223
|
-
this.checkVersion(definition, now.revisions + 1);
|
|
224
|
-
await this.store.commitRevision(agent.id, revision, { setCurrent: true, ifCurrent: base });
|
|
225
|
-
return undefined;
|
|
226
|
-
};
|
|
227
|
-
try {
|
|
228
|
-
return (await this.request(attempt)) ?? (await this.get(agent.id));
|
|
229
|
-
}
|
|
230
|
-
catch (error) {
|
|
231
|
-
// Without If-Match an edit goes on the revision current when it commits: one moved under it is read again.
|
|
232
|
-
if (ifCurrent === undefined && tries < 5 && error instanceof AgentHomeError && error.code === "stale")
|
|
233
|
-
continue;
|
|
234
|
-
storeError(error);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
/** Makes `revision`, one of the agent's own, its current one. */
|
|
239
|
-
async setCurrent(entry, revision) {
|
|
240
|
-
await this.request(() => this.store.setCurrent(entry.agent.id, revision)).catch((error) => storeError(error, "revision"));
|
|
241
|
-
return (await this.get(entry.agent.id));
|
|
242
|
-
}
|
|
243
|
-
/** Archives or unarchives an agent or a run. */
|
|
244
|
-
async setArchived(kind, id, archived) {
|
|
245
|
-
await this.request(() => this.store.setArchived(kind, id, archived)).catch((error) => storeError(error));
|
|
246
|
-
}
|
|
247
|
-
/** The agent's revisions, newest first, each with its number. */
|
|
248
|
-
revisions(id) {
|
|
249
|
-
return this.request(() => {
|
|
250
|
-
const rows = this.store.listRevisions(id);
|
|
251
|
-
return rows.map((row, index) => ({ ...row, version: rows.length - index }));
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
/** Revision `id` and its number, or null when it is not one of `agent`'s. */
|
|
255
|
-
async revision(agent, id) {
|
|
256
|
-
const row = (await this.revisions(agent)).find((r) => r.id === id);
|
|
257
|
-
return row ? { revision: await this.request(() => this.store.readRevision(id)), version: row.version } : null;
|
|
258
|
-
}
|
|
259
|
-
/** The agent `id`, or null. `runs` saves a read when the caller holds every run already. */
|
|
260
|
-
get(id) {
|
|
261
|
-
return this.request(() => this.entry(id));
|
|
262
|
-
}
|
|
263
|
-
entry(id, runs) {
|
|
264
|
-
const found = this.store.readAgent(id);
|
|
265
|
-
if (!found)
|
|
266
|
-
return null;
|
|
267
|
-
const at = found.revisions.findIndex((revision) => revision.current);
|
|
268
|
-
const revision = at < 0 ? null : (({ current: _, ...rest }) => rest)(found.revisions[at]);
|
|
269
|
-
const own = (runs ?? this.store.listRuns({ agent: id })).filter((run) => run.agent === id);
|
|
270
|
-
const sizes = new Map();
|
|
271
|
-
if (revision)
|
|
272
|
-
for (const [sha, text] of this.texts(Object.values(revision.body.skills)))
|
|
273
|
-
sizes.set(sha, Buffer.byteLength(text, "utf8"));
|
|
274
|
-
const live = own.filter((run) => run.state === "running").length;
|
|
275
|
-
return { agent: found.agent, revision, version: at < 0 ? 0 : found.revisions.length - at, revisions: found.revisions.length, runs: { count: own.length, live }, sizes };
|
|
276
|
-
}
|
|
277
|
-
/** Every agent here, newest first. */
|
|
278
|
-
list() {
|
|
279
|
-
return this.request(() => {
|
|
280
|
-
const runs = this.store.listRuns();
|
|
281
|
-
return this.store
|
|
282
|
-
.listAgents()
|
|
283
|
-
.map((row) => this.entry(row.id, runs))
|
|
284
|
-
.sort((a, b) => b.agent.createdAt.localeCompare(a.agent.createdAt) || a.agent.id.localeCompare(b.agent.id));
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
/** Whether `next` would be `current` again: the same kind and body, skills by their SHA-256. */
|
|
289
|
-
function sameRevision(current, next) {
|
|
290
|
-
const { kind, note: _, skills = {}, ...rest } = next;
|
|
291
|
-
const body = { ...rest, skills: Object.fromEntries(Object.entries(skills).map(([path, text]) => [path, createHash("sha256").update(text).digest("hex")])), tools: next.tools ?? [] };
|
|
292
|
-
return current.kind === kind && stable(current.body) === stable(body);
|
|
293
|
-
}
|
|
294
|
-
/** The agent's ETag: its current revision, which only an edit or `POST .../current` moves. */
|
|
295
|
-
export const etagOf = (entry) => `"${entry.revision?.id ?? "none"}"`;
|
|
296
|
-
/** A revision as a definition, as `POST /agents` takes one, numbered. */
|
|
297
|
-
export function definitionOf(agent, revision, version) {
|
|
298
|
-
const body = revision.kind === "agentic"
|
|
299
|
-
? { instructions: revision.body.instructions, ...(revision.body.model ? { model: revision.body.model } : {}), ...(revision.body.thinking ? { thinking: revision.body.thinking } : {}), ...(revision.body.learning !== undefined ? { learning: revision.body.learning } : {}), ...(revision.body.maxCostUsd !== undefined ? { max_cost_usd: revision.body.maxCostUsd } : {}), ...(revision.body.capMode !== undefined ? { cap_mode: revision.body.capMode } : {}) }
|
|
300
|
-
: { workflow: revision.body.workflow, ...(revision.body.maxCostUsd !== undefined ? { max_cost_usd: revision.body.maxCostUsd } : {}), ...(revision.body.capMode !== undefined ? { cap_mode: revision.body.capMode } : {}) };
|
|
301
|
-
return { id: agent.id, version, name: agent.name, ...(agent.description !== undefined ? { description: agent.description } : {}), ...body, harness: harnessOfBody(revision.body), ...(revision.body.place ? { place: revision.body.place } : {}), ...computerView(revision.body), skills: skillNames(Object.keys(revision.body.skills)), tools: revision.body.tools, ...(revision.body.toolSettings ? { tool_settings: revision.body.toolSettings } : {}), approvals: approvalsOf(revision.body.approvals) };
|
|
302
|
-
}
|
|
303
|
-
/** `Agent` as the contract shows it, with its current revision and its saved sign-ins (sign-ins.ts view: never a ref).
|
|
304
|
-
* `origin`: where its console page is (console-links.ts). */
|
|
305
|
-
export function agentView(entry, origin, signIns = [], learning) {
|
|
306
|
-
const { agent, revision } = entry;
|
|
307
|
-
return {
|
|
308
|
-
agent_id: agent.id,
|
|
309
|
-
definition: revision ? definitionOf(agent, revision, entry.version) : null,
|
|
310
|
-
kind: revision?.kind ?? null,
|
|
311
|
-
revision: revision?.id ?? null,
|
|
312
|
-
revisions: entry.revisions,
|
|
313
|
-
source: null,
|
|
314
|
-
skills: Object.entries(revision?.body.skills ?? {}).map(([path, sha]) => ({ path, sha256: sha, size_bytes: entry.sizes.get(sha) ?? null })),
|
|
315
|
-
sign_ins: signIns,
|
|
316
|
-
runs: entry.runs,
|
|
317
|
-
region: "local",
|
|
318
|
-
home_etag: etagOf(entry),
|
|
319
|
-
archived_at: agent.archivedAt ?? null,
|
|
320
|
-
console_url: agentLink(origin, agent.id),
|
|
321
|
-
// How many of its learned items wait for its owner's OK (learning-routes.ts pendingCount): only for an agent that
|
|
322
|
-
// learns on a server whose learning is on.
|
|
323
|
-
...(learning ? { learning } : {}),
|
|
324
|
-
created_at: agent.createdAt,
|
|
325
|
-
updated_at: revision && revision.createdAt > agent.createdAt ? revision.createdAt : agent.createdAt,
|
|
326
|
-
};
|
|
327
|
-
}
|
|
328
|
-
/** One revision as `GET .../revisions` lists it. */
|
|
329
|
-
export function revisionView(agent, row, revision) {
|
|
330
|
-
return { revision: row.id, version: row.version, parent: row.parent, kind: row.kind, current: row.current, note: row.note ?? null, created_at: row.createdAt, definition: definitionOf(agent, revision, row.version) };
|
|
331
|
-
}
|
|
36
|
+
/** What a request's error answers, over HTTP and through an MCP tool alike (server.ts, mcp.ts dispatch): an ApiError as
|
|
37
|
+
* it is; a busy store home_busy (409, retryable), never 500; anything else internal, its message kept. */
|
|
38
|
+
export const answerOf = (error) => error instanceof ApiError ? error : storeBusy(error) ? homeBusy() : new ApiError("internal", error?.message ?? String(error));
|
|
39
|
+
/** Whether a request's error goes to the server's log: every fault the server did not answer on purpose. A busy wait
|
|
40
|
+
* is not one; a transaction past its deadline is (something held the store that long). */
|
|
41
|
+
export const logged = (error) => !(error instanceof ApiError) && (!storeBusy(error) || error instanceof StoreDeadline);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** The text of the last fenced `json` block in `text` (```json or a longer fence, ~~~ too), or undefined. */
|
|
2
|
+
export declare function lastJsonBlock(text: string): string | undefined;
|
|
3
|
+
/** The answer's last fenced json block, parsed, or why there is none. */
|
|
4
|
+
export declare function answerJson(answer: string): {
|
|
5
|
+
value: unknown;
|
|
6
|
+
} | {
|
|
7
|
+
why: string;
|
|
8
|
+
};
|
|
9
|
+
/** A JSON Schema's checker: each problem of a value against it, by path, none for a value that meets it. */
|
|
10
|
+
export type SchemaCheck = (value: unknown) => string[];
|
|
11
|
+
/** `schema` compiled to its checker, or why it does not compile. */
|
|
12
|
+
export declare function schemaCheck(schema: unknown): {
|
|
13
|
+
check: SchemaCheck;
|
|
14
|
+
} | {
|
|
15
|
+
why: string;
|
|
16
|
+
};
|
|
17
|
+
/** A final answer's structured part against an agent's output schema: the value of its last fenced json block when it
|
|
18
|
+
* meets the schema, else why not (no block, not JSON, the first problems against the schema). */
|
|
19
|
+
export declare function structuredAnswer(answer: string, schema: unknown): {
|
|
20
|
+
value: unknown;
|
|
21
|
+
} | {
|
|
22
|
+
why: string;
|
|
23
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// An answer's structured part: the last fenced `json` block of a final answer, parsed, and checked against an agent's
|
|
2
|
+
// output schema (definition.output_schema). The one reader of it: a completed agentic run's result.output (store-view.ts)
|
|
3
|
+
// and a template eval's schema and target graders (template-eval.ts) read an answer's JSON alike.
|
|
4
|
+
import { Compile } from "typebox/schema";
|
|
5
|
+
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6
|
+
/** The text of the last fenced `json` block in `text` (```json or a longer fence, ~~~ too), or undefined. */
|
|
7
|
+
export function lastJsonBlock(text) {
|
|
8
|
+
const lines = text.split(/\r?\n/);
|
|
9
|
+
let found;
|
|
10
|
+
for (let i = 0; i < lines.length; i++) {
|
|
11
|
+
const open = /^ {0,3}(`{3,}|~{3,})\s*json\s*$/i.exec(lines[i]);
|
|
12
|
+
if (!open)
|
|
13
|
+
continue;
|
|
14
|
+
const fence = open[1];
|
|
15
|
+
const end = lines.findIndex((line, j) => j > i && new RegExp(`^ {0,3}${fence[0] === "`" ? "`" : "~"}{${fence.length},}\\s*$`).test(line));
|
|
16
|
+
if (end < 0)
|
|
17
|
+
break;
|
|
18
|
+
found = lines.slice(i + 1, end).join("\n");
|
|
19
|
+
i = end;
|
|
20
|
+
}
|
|
21
|
+
return found;
|
|
22
|
+
}
|
|
23
|
+
/** The answer's last fenced json block, parsed, or why there is none. */
|
|
24
|
+
export function answerJson(answer) {
|
|
25
|
+
const block = lastJsonBlock(answer);
|
|
26
|
+
if (block === undefined)
|
|
27
|
+
return { why: "the answer has no fenced json block" };
|
|
28
|
+
try {
|
|
29
|
+
return { value: JSON.parse(block) };
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
return { why: `the answer's last json block is not JSON: ${error.message}` };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** `schema` compiled to its checker, or why it does not compile. */
|
|
36
|
+
export function schemaCheck(schema) {
|
|
37
|
+
if (!isObject(schema))
|
|
38
|
+
return { why: "it is not a JSON object" };
|
|
39
|
+
try {
|
|
40
|
+
const validator = Compile(schema);
|
|
41
|
+
return { check: (value) => validator.Errors(value)[1].map((e) => `${e.instancePath || "/"} ${e.message}`) };
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
return { why: `it does not compile as a JSON Schema: ${error.message}` };
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** A final answer's structured part against an agent's output schema: the value of its last fenced json block when it
|
|
48
|
+
* meets the schema, else why not (no block, not JSON, the first problems against the schema). */
|
|
49
|
+
export function structuredAnswer(answer, schema) {
|
|
50
|
+
const compiled = schemaCheck(schema);
|
|
51
|
+
if ("why" in compiled)
|
|
52
|
+
return { why: `the output schema ${compiled.why}` };
|
|
53
|
+
const json = answerJson(answer);
|
|
54
|
+
if ("why" in json)
|
|
55
|
+
return json;
|
|
56
|
+
const problems = compiled.check(json.value);
|
|
57
|
+
return problems.length ? { why: `the answer's json does not meet the output schema: ${problems.slice(0, 3).join("; ")}` } : { value: json.value };
|
|
58
|
+
}
|
package/dist/api-only.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { Route } from "./server.js";
|
|
|
2
2
|
/** The variable that turns the profile on. */
|
|
3
3
|
export declare const API_ONLY_ENV = "AGENTRUN_API_ONLY";
|
|
4
4
|
/** The routes (server.ts ROUTES, by name) an API-only server serves: a run's launch, read, list, timeline, messages,
|
|
5
|
-
* stop, cancel
|
|
5
|
+
* stop, cancel and cap raise; its files and the uploads a launch names; capabilities, health and usage. */
|
|
6
6
|
export declare const API_ONLY_ROUTES: ReadonlySet<string>;
|
|
7
7
|
/** Whether `env` turns the profile on: `1` or `true` on; unset, empty, `0` or `false` off. Any other value is refused in
|
|
8
8
|
* words (a TypeError), so a typo never leaves the console open on a server meant to be API-only. */
|
package/dist/api-only.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/** The variable that turns the profile on. */
|
|
2
2
|
export const API_ONLY_ENV = "AGENTRUN_API_ONLY";
|
|
3
3
|
/** The routes (server.ts ROUTES, by name) an API-only server serves: a run's launch, read, list, timeline, messages,
|
|
4
|
-
* stop, cancel
|
|
4
|
+
* stop, cancel and cap raise; its files and the uploads a launch names; capabilities, health and usage. */
|
|
5
5
|
export const API_ONLY_ROUTES = new Set([
|
|
6
6
|
"createRun", "createInlineRun",
|
|
7
7
|
"getRun", "listRuns", "listAllRuns", "getTimeline",
|
|
8
|
-
"sendMessage", "stopRun", "cancelRun", "
|
|
8
|
+
"sendMessage", "stopRun", "cancelRun", "raiseRunCap",
|
|
9
9
|
"listRunFiles", "readRunFile",
|
|
10
10
|
"createFile", "listFiles", "getFile", "uploadFile", "deleteFile",
|
|
11
11
|
"getCapabilities", "getHealth", "getUsage",
|
|
@@ -4,11 +4,21 @@ export declare const ARCHIL_SETTINGS_KEY = "archil";
|
|
|
4
4
|
/** The sealed-key row of the Archil account key (the file API and exec), saved through server-keys.ts. Named *_ROW: a
|
|
5
5
|
* constant named like a key holding a string reads as a literal credential to the source export. */
|
|
6
6
|
export declare const ARCHIL_API_KEY_ROW = "archil.api_key";
|
|
7
|
+
/** The exec image a Mode 2 server runs commands in when the owner saved none: Docker's official
|
|
8
|
+
* `buildpack-deps:trixie-scm` (Debian 13 with git 2.47.3, GNU coreutils, perl-base, grep, sed, mawk, diffutils and
|
|
9
|
+
* findutils; no ripgrep), pinned to the multi-arch index digest Docker Hub served for that tag on 2026-11-11. Archil's
|
|
10
|
+
* own default exec image has git 2.34.1, and a shell under a bash policy runs git only at 2.43 or later (bash-read-only.ts
|
|
11
|
+
* POLICY_GIT_FLOOR), so a read-only agent there would get no git. Its git was read from the top layer's
|
|
12
|
+
* /var/lib/dpkg/status for amd64 and arm64 alike (`git 1:2.47.3-0+deb13u1`). To move it, read the tag's index digest
|
|
13
|
+
* again (an anonymous pull token from auth.docker.io for `repository:library/buildpack-deps:pull`, then a HEAD of
|
|
14
|
+
* registry-1.docker.io/v2/library/buildpack-deps/manifests/trixie-scm accepting an OCI index: its
|
|
15
|
+
* `docker-content-digest`), check the git its layers hold, and put it here. An image the owner saved replaces it. */
|
|
16
|
+
export declare const DEFAULT_ARCHIL_EXEC_IMAGE = "buildpack-deps@sha256:4f34e1d673fdb65371de9f88bdd32c4e30152fe692b35604aef5c0b3c0e6da10";
|
|
7
17
|
export interface ArchilSettings {
|
|
8
18
|
readonly diskId: string;
|
|
9
19
|
readonly region: string;
|
|
10
20
|
readonly s3Url: string;
|
|
11
|
-
/** A pinned image for the disk's exec, when the owner set one; absent,
|
|
21
|
+
/** A pinned image for the disk's exec, when the owner set one; absent, DEFAULT_ARCHIL_EXEC_IMAGE. */
|
|
12
22
|
readonly image?: string;
|
|
13
23
|
}
|
|
14
24
|
/** The Archil settings the owner saved, or undefined when none is (Mode 1). A row that is not the expected shape reads as
|
package/dist/archil-settings.js
CHANGED
|
@@ -3,6 +3,16 @@ export const ARCHIL_SETTINGS_KEY = "archil";
|
|
|
3
3
|
/** The sealed-key row of the Archil account key (the file API and exec), saved through server-keys.ts. Named *_ROW: a
|
|
4
4
|
* constant named like a key holding a string reads as a literal credential to the source export. */
|
|
5
5
|
export const ARCHIL_API_KEY_ROW = "archil.api_key";
|
|
6
|
+
/** The exec image a Mode 2 server runs commands in when the owner saved none: Docker's official
|
|
7
|
+
* `buildpack-deps:trixie-scm` (Debian 13 with git 2.47.3, GNU coreutils, perl-base, grep, sed, mawk, diffutils and
|
|
8
|
+
* findutils; no ripgrep), pinned to the multi-arch index digest Docker Hub served for that tag on 2026-11-11. Archil's
|
|
9
|
+
* own default exec image has git 2.34.1, and a shell under a bash policy runs git only at 2.43 or later (bash-read-only.ts
|
|
10
|
+
* POLICY_GIT_FLOOR), so a read-only agent there would get no git. Its git was read from the top layer's
|
|
11
|
+
* /var/lib/dpkg/status for amd64 and arm64 alike (`git 1:2.47.3-0+deb13u1`). To move it, read the tag's index digest
|
|
12
|
+
* again (an anonymous pull token from auth.docker.io for `repository:library/buildpack-deps:pull`, then a HEAD of
|
|
13
|
+
* registry-1.docker.io/v2/library/buildpack-deps/manifests/trixie-scm accepting an OCI index: its
|
|
14
|
+
* `docker-content-digest`), check the git its layers hold, and put it here. An image the owner saved replaces it. */
|
|
15
|
+
export const DEFAULT_ARCHIL_EXEC_IMAGE = "buildpack-deps@sha256:4f34e1d673fdb65371de9f88bdd32c4e30152fe692b35604aef5c0b3c0e6da10";
|
|
6
16
|
/** The Archil settings the owner saved, or undefined when none is (Mode 1). A row that is not the expected shape reads as
|
|
7
17
|
* undefined, never a half-configured Mode 2. */
|
|
8
18
|
export async function loadArchilSettings(store) {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** The policies an agent may set on bash (tool_settings.bash.policy). */
|
|
2
|
+
export declare const BASH_POLICIES: readonly ["read-only"];
|
|
3
|
+
export type BashPolicy = (typeof BASH_POLICIES)[number];
|
|
4
|
+
/** An agent's bash policy as its own tool settings write it (tool_settings.bash.policy), or undefined for none: any
|
|
5
|
+
* value, a policy this server does not know too (the gate refuses its every call; policyEnv holds its shell all the same). */
|
|
6
|
+
export declare function bashPolicyOf(toolSettings: unknown): string | undefined;
|
|
7
|
+
/** The command-line config a shell under a policy gives git (GIT_CONFIG_KEY_n / GIT_CONFIG_VALUE_n). */
|
|
8
|
+
export declare const POLICY_GIT_CONFIG: readonly (readonly [string, string])[];
|
|
9
|
+
/** What a shell under bash policy `policy` adds to the run's fixed environment (hands.ts shellEnv): git's config locked
|
|
10
|
+
* down (POLICY_GIT_CONFIG and the variables above); nothing without a policy. */
|
|
11
|
+
export declare function policyEnv(policy: string | undefined): Readonly<Record<string, string>>;
|
|
12
|
+
/** The oldest git that holds the whole lock-down (attr.tree). */
|
|
13
|
+
export declare const POLICY_GIT_FLOOR = "2.43";
|
|
14
|
+
/** What a shell under bash policy `policy` runs before the command, on a line of its own: `git` as a function that runs
|
|
15
|
+
* git only at POLICY_GIT_FLOOR or later. Empty without a policy. POSIX sh, for bash and the sh fallback alike. */
|
|
16
|
+
export declare function policyPrelude(policy: string | undefined): string;
|
|
17
|
+
/** The programs a read-only command may run. */
|
|
18
|
+
export declare const PROGRAMS: ReadonlySet<string>;
|
|
19
|
+
/** The programs a command may pipe into: filters of their input. */
|
|
20
|
+
export declare const PIPE_TARGETS: ReadonlySet<string>;
|
|
21
|
+
/** git's read subcommands. */
|
|
22
|
+
export declare const GIT_READS: ReadonlySet<string>;
|
|
23
|
+
/** What a refusal adds, so the model knows what it may run instead. */
|
|
24
|
+
export declare const READ_ONLY_HINT = "Use read commands only: git diff, show, log, grep, ls-files, merge-base or rev-parse; grep -n; sed -n 'N,Mp' FILE; cat, head, tail, wc, ls; find without -exec. Pipe only into head, tail, sed -n, grep, wc, sort, uniq, cut, tr or nl, with no redirection but 2>/dev/null or 2>&1, no $ or backticks, and quote glob patterns.";
|
|
25
|
+
/** The refusal of a call under the read-only policy, as the model reads it: the reason, that it did not run, and what may. */
|
|
26
|
+
export declare const readOnlyText: (tool: string, reason: string, notRun: string) => string;
|
|
27
|
+
/** The run's folder as the command knows it: its absolute names (the first is where a command starts, each names the
|
|
28
|
+
* same folder: the folder's path on this machine, the computer's name for it). */
|
|
29
|
+
export type Folder = readonly string[];
|
|
30
|
+
/** Throws, with the reason, unless `command` is a read-only command line run from `folder`'s first name (relative to the
|
|
31
|
+
* folder: `start`, "" for the folder itself). */
|
|
32
|
+
export declare function checkReadOnly(command: string, folder: Folder, start?: string): void;
|
|
33
|
+
/** Why the read-only policy refuses shell tool `tool`'s call with `args`, or undefined when it may go on to the gate's
|
|
34
|
+
* permission. `folder`: the run's folder by its names (the first is where a command starts). */
|
|
35
|
+
export declare function readOnlyReason(tool: string, args: unknown, folder: Folder): string | undefined;
|