@parcha/agentrun-serve 0.1.0-beta.37 → 0.1.0-beta.38
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 +282 -0
- package/README.md +155 -92
- package/dist/agent-rows.d.ts +1 -1
- package/dist/agents-store.d.ts +35 -3
- package/dist/agents-store.js +39 -14
- package/dist/answer-json.d.ts +34 -1
- package/dist/answer-json.js +91 -9
- package/dist/api-only.d.ts +1 -1
- package/dist/api-only.js +2 -2
- package/dist/browser-cost.js +52 -93
- package/dist/cap.d.ts +0 -390
- package/dist/cap.js +4 -937
- package/dist/catalog.js +1 -1
- package/dist/composio-preset.d.ts +17 -0
- package/dist/composio-preset.js +43 -1
- package/dist/computer-calls.d.ts +36 -24
- package/dist/computer-calls.js +110 -27
- package/dist/computer-live.d.ts +5 -0
- package/dist/computer-live.js +12 -0
- package/dist/computer-setting.d.ts +15 -2
- package/dist/computer-setting.js +20 -4
- package/dist/computer-view.d.ts +3 -2
- package/dist/computer-view.js +5 -4
- package/dist/computer-viewer.js +26 -12
- package/dist/computers.d.ts +4 -1
- package/dist/computers.js +12 -6
- package/dist/console/assets/index-CjqQirbo.css +1 -0
- package/dist/console/assets/index-b6-XY5A9.js +576 -0
- package/dist/console/index.html +2 -2
- package/dist/console-links.d.ts +2 -0
- package/dist/console-links.js +3 -0
- package/dist/decisions.js +4 -0
- package/dist/faux-computers.js +4 -2
- package/dist/harness-opencode/adapter.js +7 -3
- package/dist/harness-opencode/facts.js +0 -2
- package/dist/harness-opencode/host/policy.d.ts +2 -5
- package/dist/harness-opencode/host/policy.js +8 -32
- package/dist/harness-table.d.ts +0 -2
- package/dist/harness-table.js +0 -2
- package/dist/host-tools.d.ts +1 -5
- package/dist/host-tools.js +7 -10
- package/dist/hosted-search.d.ts +0 -2
- package/dist/hosted-search.js +0 -21
- package/dist/key-words.d.ts +3 -2
- package/dist/key-words.js +4 -2
- package/dist/learn/check.d.ts +6 -1
- package/dist/learn/check.js +12 -4
- package/dist/learn/commit.d.ts +10 -0
- package/dist/learn/commit.js +18 -4
- package/dist/learn/compile.d.ts +243 -0
- package/dist/learn/compile.js +471 -0
- package/dist/learn/general.d.ts +3 -0
- package/dist/learn/general.js +4 -2
- package/dist/learn/grade.d.ts +1 -1
- package/dist/learn/grade.js +7 -6
- package/dist/learn/notes.d.ts +8 -0
- package/dist/learn/notes.js +18 -0
- package/dist/learn/promote.d.ts +253 -0
- package/dist/learn/promote.js +428 -0
- package/dist/learn/refit.d.ts +39 -0
- package/dist/learn/refit.js +236 -0
- package/dist/learn/reflect.d.ts +5 -25
- package/dist/learn/reflect.js +14 -131
- package/dist/learn/replay-calls.d.ts +63 -0
- package/dist/learn/replay-calls.js +158 -0
- package/dist/learn/skills.d.ts +17 -9
- package/dist/learn/skills.js +132 -42
- package/dist/learn/workflow-nodes.d.ts +15 -0
- package/dist/learn/workflow-nodes.js +44 -0
- package/dist/learned-nodes.d.ts +50 -2
- package/dist/learned-nodes.js +41 -2
- package/dist/learned-workflow.d.ts +19 -3
- package/dist/learned-workflow.js +105 -26
- package/dist/learning-batch.d.ts +2 -2
- package/dist/learning-batch.js +1 -1
- package/dist/learning-cost.d.ts +18 -6
- package/dist/learning-cost.js +15 -7
- package/dist/learning-routes.d.ts +14 -2
- package/dist/learning-routes.js +14 -3
- package/dist/learning-words.d.ts +7 -0
- package/dist/learning-words.js +7 -0
- package/dist/learning.d.ts +31 -6
- package/dist/learning.js +7 -4
- package/dist/llm.js +0 -3
- package/dist/mcp-gateway.d.ts +12 -20
- package/dist/mcp-gateway.js +16 -44
- package/dist/mcp-oauth.d.ts +5 -0
- package/dist/mcp-oauth.js +1 -1
- package/dist/mcp-pin-first.d.ts +37 -0
- package/dist/mcp-pin-first.js +107 -0
- package/dist/mcp-probe.d.ts +8 -9
- package/dist/mcp-probe.js +16 -33
- package/dist/mcp-servers-store.d.ts +89 -22
- package/dist/mcp-servers-store.js +131 -25
- package/dist/mcp-sources.d.ts +39 -0
- package/dist/mcp-sources.js +74 -0
- package/dist/mcp-store.d.ts +11 -0
- package/dist/mcp-store.js +16 -2
- package/dist/mcp-wire.d.ts +22 -0
- package/dist/mcp-wire.js +36 -0
- package/dist/mcp.js +3 -3
- package/dist/meta-tool-names.d.ts +1 -0
- package/dist/meta-tool-names.js +3 -0
- package/dist/model.d.ts +13 -0
- package/dist/model.js +46 -15
- package/dist/monid.d.ts +51 -25
- package/dist/monid.js +226 -140
- package/dist/openapi.js +336 -66
- package/dist/paid-calls.d.ts +26 -29
- package/dist/paid-calls.js +46 -102
- package/dist/propose.d.ts +7 -1
- package/dist/propose.js +18 -6
- package/dist/provider.js +9 -2
- package/dist/reflect-range.js +2 -1
- package/dist/rows.d.ts +5 -3
- package/dist/rows.js +15 -4
- package/dist/run-launch.d.ts +13 -0
- package/dist/run-launch.js +6 -0
- package/dist/run-learning-served.d.ts +13 -2
- package/dist/run-manifest.d.ts +5 -0
- package/dist/run-manifest.js +20 -0
- package/dist/run-secrets.js +2 -3
- package/dist/run-timeline-served.js +5 -2
- package/dist/run-view.d.ts +17 -6
- package/dist/run-view.js +51 -22
- package/dist/runnable.d.ts +0 -3
- package/dist/runnable.js +37 -29
- package/dist/runner/adapter-loop.d.ts +24 -10
- package/dist/runner/adapter-loop.js +852 -314
- package/dist/runner/adapter-run-spec.d.ts +12 -6
- package/dist/runner/adapter-run-spec.js +97 -46
- package/dist/runner/adapters/pi-computer.d.ts +3 -1
- package/dist/runner/adapters/pi-computer.js +13 -5
- package/dist/runner/adapters/pi.d.ts +16 -7
- package/dist/runner/adapters/pi.js +94 -33
- package/dist/runner/cli-run-spec.js +67 -27
- package/dist/runner/computer-channel.js +2 -1
- package/dist/runner/conformance/harness.d.ts +3 -0
- package/dist/runner/conformance/harness.js +145 -4
- package/dist/runner/conformance/subject.d.ts +11 -4
- package/dist/runner/end-of-run.d.ts +6 -5
- package/dist/runner/end-of-run.js +9 -6
- package/dist/runner/feedback-round.d.ts +52 -0
- package/dist/runner/feedback-round.js +79 -0
- package/dist/runner/journal-kinds.d.ts +24 -6
- package/dist/runner/journal-kinds.js +15 -0
- package/dist/runner/learning-end.d.ts +54 -19
- package/dist/runner/learning-end.js +272 -99
- package/dist/runner/learning-loop.d.ts +19 -1
- package/dist/runner/learning-loop.js +5 -2
- package/dist/runner/learning-seed.d.ts +4 -0
- package/dist/runner/learning-seed.js +14 -0
- package/dist/runner/loop-contract.d.ts +19 -3
- package/dist/runner/loop.d.ts +16 -1
- package/dist/runner/loop.js +21 -1
- package/dist/runner/mcp-claim.d.ts +5 -1
- package/dist/runner/mcp-claim.js +66 -50
- package/dist/runner/mcp-run.d.ts +16 -52
- package/dist/runner/mcp-run.js +12 -84
- package/dist/runner/meta-tools.d.ts +37 -0
- package/dist/runner/meta-tools.js +268 -0
- package/dist/runner/metrics.js +14 -3
- package/dist/runner/model-route.js +12 -3
- package/dist/runner/monid-run.d.ts +16 -0
- package/dist/runner/monid-run.js +96 -0
- package/dist/runner/promotion.d.ts +80 -0
- package/dist/runner/promotion.js +562 -0
- package/dist/runner/reflect-hook.d.ts +36 -21
- package/dist/runner/reflect-hook.js +138 -49
- package/dist/runner/runner.js +26 -4
- package/dist/runner/sessions.d.ts +8 -3
- package/dist/runner/sessions.js +5 -1
- package/dist/runner/step-guard.d.ts +62 -0
- package/dist/runner/step-guard.js +93 -0
- package/dist/runner/subagent.d.ts +0 -3
- package/dist/runner/subagent.js +7 -12
- package/dist/runner/workflow-first.d.ts +216 -0
- package/dist/runner/workflow-first.js +303 -0
- package/dist/runner/workflow-loop.js +17 -10
- package/dist/runner/workflow-spec.d.ts +1 -0
- package/dist/runner/workflow-spec.js +7 -3
- package/dist/runs-over-store.d.ts +11 -2
- package/dist/runs-over-store.js +21 -11
- package/dist/server.d.ts +88 -16
- package/dist/server.js +380 -87
- package/dist/settings-wake.d.ts +8 -6
- package/dist/settings-wake.js +13 -7
- package/dist/store/agent-body.d.ts +14 -3
- package/dist/store/agent-body.js +14 -10
- package/dist/store/command-wake.d.ts +3 -2
- package/dist/store/command-wake.js +4 -4
- package/dist/store/postgres/connection.js +3 -1
- package/dist/store/postgres/migrations/0010_imported_templates.sql +18 -0
- package/dist/store/postgres/migrations/0011_revision_mcp_pin.sql +13 -0
- package/dist/store/schema.d.ts +9 -0
- package/dist/store/schema.js +28 -8
- package/dist/store/sqlite/connection.d.ts +2 -2
- package/dist/store/sqlite/connection.js +2 -2
- package/dist/store/sqlite/run-patch.js +19 -7
- package/dist/store/sqlite/store.js +59 -18
- package/dist/store/store.d.ts +46 -14
- package/dist/store-reads/journal.d.ts +25 -1
- package/dist/store-reads/journal.js +63 -49
- package/dist/store-reads/learning.d.ts +101 -15
- package/dist/store-reads/learning.js +195 -61
- package/dist/store-reads/loop.d.ts +61 -0
- package/dist/store-reads/loop.js +111 -0
- package/dist/store-view.d.ts +3 -2
- package/dist/store-view.js +35 -17
- package/dist/template-eval.d.ts +18 -9
- package/dist/template-eval.js +91 -66
- package/dist/template-github-permissions.d.ts +2 -2
- package/dist/template-github-permissions.js +2 -1
- package/dist/template-import.d.ts +31 -0
- package/dist/template-import.js +121 -0
- package/dist/template-source.d.ts +51 -0
- package/dist/template-source.js +371 -0
- package/dist/templates.d.ts +218 -46
- package/dist/templates.js +493 -181
- package/dist/timeline/computer.d.ts +48 -0
- package/dist/timeline/computer.js +169 -0
- package/dist/timeline/index.d.ts +4 -3
- package/dist/timeline/index.js +4 -3
- package/dist/timeline/labels.d.ts +6 -2
- package/dist/timeline/labels.js +93 -2
- package/dist/timeline/origin.d.ts +19 -5
- package/dist/timeline/origin.js +11 -4
- package/dist/timeline/timeline.d.ts +11 -17
- package/dist/timeline/timeline.js +24 -9
- package/dist/tool-gate.d.ts +73 -46
- package/dist/tool-gate.js +133 -66
- package/dist/tool-keys.d.ts +4 -1
- package/dist/tool-keys.js +8 -3
- package/dist/tool-list.d.ts +26 -0
- package/dist/tool-list.js +43 -0
- package/dist/tool-names.d.ts +71 -0
- package/dist/tool-names.js +99 -0
- package/dist/tool-plane.d.ts +29 -27
- package/dist/tool-plane.js +65 -37
- package/dist/tools.d.ts +22 -6
- package/dist/tools.js +24 -20
- package/dist/validate.d.ts +15 -7
- package/dist/validate.js +91 -44
- package/dist/web-fetch.d.ts +1 -7
- package/dist/web-fetch.js +2 -22
- package/dist/workspace/computer-deps.d.ts +3 -0
- package/dist/workspace/computer-deps.js +5 -2
- package/dist/workspace/computer-for-claim.d.ts +6 -0
- package/dist/workspace/computer-for-claim.js +32 -14
- package/dist/workspace/computer-hold.js +7 -1
- package/dist/workspace/computer-script.d.ts +23 -7
- package/dist/workspace/computer-script.js +48 -14
- package/dist/workspace/index.d.ts +2 -2
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/kind-skills/desktop/SKILL.md +13 -0
- package/dist/workspace/kind-skills/phone/SKILL.md +4 -0
- package/dist/workspace/local.js +2 -2
- package/dist/workspace/resolve-computer.d.ts +21 -1
- package/dist/workspace/resolve-computer.js +32 -14
- package/dist/workspace/run-tools.d.ts +28 -10
- package/dist/workspace/run-tools.js +39 -11
- package/dist/{tool-budget.d.ts → wrap-up.d.ts} +1 -18
- package/dist/wrap-up.js +21 -0
- package/launcher/agentrun-serve +4 -2
- package/package.json +9 -9
- package/templates/README.md +111 -45
- package/templates/code-review/agent.md +30 -14
- package/templates/code-review/evals/clean-refactor/case.yaml +2 -1
- package/templates/code-review/evals/clean-refactor/graders/head-sha.md +6 -0
- package/templates/code-review/evals/injection/case.yaml +2 -1
- package/templates/code-review/evals/injection/graders/head-sha.md +6 -0
- package/templates/code-review/evals/mentions-defused/case.yaml +2 -2
- package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +0 -23
- package/templates/code-review/evals/mentions-defused/graders/head-sha.md +6 -0
- package/templates/code-review/evals/never-flag/case.yaml +2 -1
- package/templates/code-review/evals/never-flag/graders/head-sha.md +6 -0
- package/templates/code-review/evals/null-name/case.yaml +2 -1
- package/templates/code-review/evals/null-name/graders/head-sha.md +6 -0
- package/templates/code-review/evals/off-by-one/case.yaml +2 -1
- package/templates/code-review/evals/off-by-one/graders/head-sha.md +6 -0
- package/templates/code-review/evals/other-repo/case.yaml +16 -0
- package/templates/code-review/evals/other-repo/fixtures/github-mcp.json +130 -0
- package/templates/code-review/evals/other-repo/graders/head-sha.md +6 -0
- package/templates/code-review/evals/other-repo/graders/no-canary.md +6 -0
- package/templates/code-review/evals/other-repo/graders/no-other-repo.md +8 -0
- package/templates/code-review/evals/other-repo/graders/refused-not-quoted.md +18 -0
- package/templates/code-review/evals/other-repo/prompt.md +10 -0
- package/templates/code-review/evals/re-review/case.yaml +2 -1
- package/templates/code-review/evals/re-review/graders/head-sha.md +6 -0
- package/templates/code-review/evals/re-review-open/case.yaml +2 -1
- package/templates/code-review/evals/re-review-open/graders/head-sha.md +6 -0
- package/templates/code-review/evals/repo-rule/case.yaml +2 -1
- package/templates/code-review/evals/repo-rule/graders/head-sha.md +6 -0
- package/templates/code-review/evals/two-defects/case.yaml +2 -1
- package/templates/code-review/evals/two-defects/graders/head-sha.md +6 -0
- package/templates/code-review/rules/CODEREVIEW.md +1 -1
- package/templates/code-review/skills/review/DEEP.md +3 -2
- package/templates/code-review/skills/review/REVIEWER.md +3 -2
- package/templates/code-review/skills/review/SKILL.md +4 -3
- package/templates/code-review/{findings.schema.json → skills/review/findings.schema.json} +1 -0
- package/templates/inbound-lead/agent.md +26 -16
- package/templates/inbound-lead/evals/injection-in-form/graders/no-exfil.md +16 -0
- package/templates/inbound-lead/evals/injection-in-form/prompt.md +2 -2
- package/templates/inbound-lead/evals/write-back/case.yaml +2 -6
- package/templates/inbound-lead/evals/write-back/fixtures/fake-hubspot.json +34 -225
- package/templates/inbound-lead/evals/write-back/graders/note-and-score.md +10 -14
- package/templates/inbound-lead/evals/write-back/graders/writes-once.md +7 -0
- package/templates/inbound-lead/evals/write-back/prompt.md +1 -1
- package/templates/inbound-lead/evals/write-back-wrong-record/case.yaml +3 -7
- package/templates/inbound-lead/evals/write-back-wrong-record/fixtures/fake-hubspot.json +34 -225
- package/templates/inbound-lead/evals/write-back-wrong-record/graders/form-id.md +17 -0
- package/templates/inbound-lead/evals/write-back-wrong-record/graders/no-write.md +3 -3
- package/templates/inbound-lead/evals/write-back-wrong-record/prompt.md +2 -2
- package/templates/inbound-lead/skills/lead/SKILL.md +23 -27
- package/templates/kyb/agent.md +15 -5
- package/templates/kyb/evals/adverse-media/prompt.md +2 -7
- package/templates/kyb/evals/canada-active-filed/prompt.md +2 -6
- package/templates/kyb/evals/clean-public-company/prompt.md +2 -6
- package/templates/kyb/evals/injection-in-page/prompt.md +3 -7
- package/templates/kyb/evals/name-collision/prompt.md +2 -6
- package/templates/kyb/evals/no-invention/prompt.md +2 -6
- package/templates/kyb/evals/opensanctions-on/prompt.md +2 -6
- package/templates/kyb/evals/sanctioned-entity/prompt.md +2 -6
- package/templates/kyb/kyb.schema.json +8 -7
- package/templates/kyb/skills/kyb/SKILL.md +9 -6
- package/templates/market-monitor/agent.md +19 -12
- package/templates/market-monitor/evals/post-happens/case.yaml +4 -4
- package/templates/market-monitor/evals/post-happens/fixtures/slack-mcp.json +13 -9
- package/templates/market-monitor/evals/post-happens/graders/post-is-digest.md +1 -1
- package/templates/market-monitor/evals/post-happens/graders/posted-once.md +3 -3
- package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
- package/templates/release-notes/agent.md +32 -10
- package/templates/release-notes/evals/draft-not-publish/case.yaml +4 -3
- package/templates/release-notes/evals/draft-not-publish/fixtures/github-mcp.json +29 -51
- package/templates/release-notes/evals/every-pr-accounted/case.yaml +2 -1
- package/templates/release-notes/evals/issue-write-refused/case.yaml +4 -3
- package/templates/release-notes/evals/issue-write-refused/fixtures/github-mcp.json +29 -51
- package/templates/release-notes/evals/late-arrival/case.yaml +6 -5
- package/templates/release-notes/evals/late-arrival/fixtures/github-mcp.json +29 -51
- package/templates/release-notes/evals/learned-style/case.yaml +2 -1
- package/templates/release-notes/evals/no-pr-numbers-on-top/case.yaml +2 -1
- package/templates/release-notes/evals/other-repo/case.yaml +24 -0
- package/templates/release-notes/evals/other-repo/fixtures/github-mcp.json +907 -0
- package/templates/release-notes/evals/other-repo/graders/no-canary.md +7 -0
- package/templates/release-notes/evals/other-repo/graders/no-other-repo.md +8 -0
- package/templates/release-notes/evals/other-repo/graders/refused-not-quoted.md +18 -0
- package/templates/release-notes/evals/other-repo/prompt.md +32 -0
- package/templates/release-notes/evals/upgrade-line/case.yaml +2 -1
- package/templates/release-notes/evals/user-facing-only/case.yaml +2 -1
- package/templates/release-notes/notes.schema.json +1 -1
- package/templates/release-notes/skills/release-notes/SKILL.md +26 -17
- package/dist/console/assets/index-Cn6JX1uH.js +0 -563
- package/dist/console/assets/index-DRN62V5v.css +0 -1
- package/dist/tool-blurbs.d.ts +0 -4
- package/dist/tool-blurbs.js +0 -28
- package/dist/tool-budget.js +0 -62
- package/templates/code-review/evals/clean-refactor/graders/schema.md +0 -5
- package/templates/code-review/evals/injection/graders/schema.md +0 -5
- package/templates/code-review/evals/mentions-defused/graders/schema.md +0 -5
- package/templates/code-review/evals/never-flag/graders/schema.md +0 -5
- package/templates/code-review/evals/null-name/graders/schema.md +0 -5
- package/templates/code-review/evals/off-by-one/graders/schema.md +0 -5
- package/templates/code-review/evals/re-review/graders/schema.md +0 -5
- package/templates/code-review/evals/re-review-open/graders/schema.md +0 -5
- package/templates/code-review/evals/repo-rule/graders/schema.md +0 -5
- package/templates/code-review/evals/two-defects/graders/schema.md +0 -5
- package/templates/inbound-lead/evals/clear-disqualifier/graders/schema.md +0 -5
- package/templates/inbound-lead/evals/injection-in-form/graders/schema.md +0 -5
- package/templates/inbound-lead/evals/learned-correction/graders/schema.md +0 -5
- package/templates/inbound-lead/evals/strong-fit/graders/schema.md +0 -5
- package/templates/inbound-lead/evals/thin-data/graders/schema.md +0 -5
- package/templates/inbound-lead/evals/write-back/graders/schema.md +0 -5
- package/templates/inbound-lead/evals/write-back/graders/writes-twice.md +0 -7
- package/templates/inbound-lead/evals/write-back-wrong-record/graders/proves-record.md +0 -18
- package/templates/inbound-lead/evals/write-back-wrong-record/graders/schema.md +0 -5
- package/templates/kyb/evals/adverse-media/graders/schema.md +0 -5
- package/templates/kyb/evals/canada-active-filed/graders/schema.md +0 -5
- package/templates/kyb/evals/clean-public-company/graders/schema.md +0 -5
- package/templates/kyb/evals/injection-in-page/graders/schema.md +0 -5
- package/templates/kyb/evals/name-collision/graders/schema.md +0 -5
- package/templates/kyb/evals/no-invention/graders/schema.md +0 -5
- package/templates/kyb/evals/opensanctions-on/graders/schema.md +0 -5
- package/templates/kyb/evals/sanctioned-entity/graders/schema.md +0 -5
- package/templates/market-monitor/evals/blocked-source/graders/schema.md +0 -5
- package/templates/market-monitor/evals/every-competitor-named/graders/schema.md +0 -5
- package/templates/market-monitor/evals/learned-preference/graders/schema.md +0 -5
- package/templates/market-monitor/evals/no-repeats/graders/schema.md +0 -5
- package/templates/market-monitor/evals/nothing-changed/graders/schema.md +0 -5
- package/templates/market-monitor/evals/post-happens/graders/schema.md +0 -5
- package/templates/market-monitor/evals/pricing-change/graders/schema.md +0 -5
- package/templates/market-monitor/evals/pricing-moved/graders/schema.md +0 -5
- package/templates/release-notes/evals/draft-not-publish/graders/schema.md +0 -5
- package/templates/release-notes/evals/every-pr-accounted/graders/schema.md +0 -5
- package/templates/release-notes/evals/issue-write-refused/graders/schema.md +0 -5
- package/templates/release-notes/evals/late-arrival/graders/schema.md +0 -5
- package/templates/release-notes/evals/learned-style/graders/schema.md +0 -5
- package/templates/release-notes/evals/no-pr-numbers-on-top/graders/schema.md +0 -5
- package/templates/release-notes/evals/upgrade-line/graders/schema.md +0 -5
- package/templates/release-notes/evals/user-facing-only/graders/schema.md +0 -5
package/dist/server.js
CHANGED
|
@@ -12,14 +12,15 @@ import { once } from "node:events";
|
|
|
12
12
|
import { existsSync } from "node:fs";
|
|
13
13
|
import { rm } from "node:fs/promises";
|
|
14
14
|
import { homedir } from "node:os";
|
|
15
|
-
import {
|
|
15
|
+
import { pinFirst as pinFirstOf } from "./mcp-pin-first.js";
|
|
16
|
+
import { agentRevision, agentRevisions, agentView, commitAgent, createAgent, etagOf, externalKey, getAgent, listAgents, makeRevision, refuseExternal, revisionView, setAgentArchived, setCurrentRevision } from "./agents-store.js";
|
|
16
17
|
import { WORKFLOW_ADAPTERS } from "./runner/workflow-adapters.js";
|
|
17
18
|
import { DECISION_ADAPTER, decisionsOf, FAUX_JEV_ENV, FAUX_OPENROUTER_ENV, FAUX_PARALLEL_ENV, fauxFetch } from "./decisions.js";
|
|
18
19
|
import { FAUX_WEB_ENV } from "./web-fetch-direct.js";
|
|
19
|
-
import { FAUX_MONID_ENV } from "./monid.js";
|
|
20
|
+
import { FAUX_MONID_ENV, MONID_KEY_ENV, pinMonid } from "./monid.js";
|
|
20
21
|
import { FAUX_EXA_ENV } from "./exa-keyless.js";
|
|
21
22
|
import { FAUX_BROWSER_ENV, NODE_TOOLS, shellTools, toolingOf, toolOf, toolsView } from "./tools.js";
|
|
22
|
-
import { ApiError, invalid, unsupported } from "./errors.js";
|
|
23
|
+
import { ApiError, invalid, sentence, unsupported } from "./errors.js";
|
|
23
24
|
import { deref, explain } from "./explain.js";
|
|
24
25
|
import { HOME_HOST_OWNED } from "./files.js";
|
|
25
26
|
import { DATA_ENV, readJson, syncDir, TOKEN_FILE, writeDurable } from "./server-fs.js";
|
|
@@ -66,7 +67,9 @@ import { analytics as analyticsOverStore } from "./store-reads/analytics.js";
|
|
|
66
67
|
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
67
68
|
import { openStore, sealRunMcpAuth, StoreOwned, storeTarget } from "./store/index.js";
|
|
68
69
|
import { answerOf, logged } from "./agents.js";
|
|
70
|
+
import { LABEL_MAX, openFeedbackRound } from "./runner/feedback-round.js";
|
|
69
71
|
import { FINAL_STATES, RUN_CHANGES_PAGE } from "./store/store.js";
|
|
72
|
+
import { GRADE_SOURCES, gradeView, promotionsOf, promotionsShown, putGrade } from "./learn/promote.js";
|
|
70
73
|
import { runModelRef } from "./model.js";
|
|
71
74
|
// The v2 run statuses, as the run view names them (run-view.ts Status), for the list filter's validation. */
|
|
72
75
|
const STATUSES = ["queued", "working", "paused", "input_required", "completed", "failed", "cancelled"];
|
|
@@ -77,26 +80,30 @@ import { dockerDaemonCheck } from "./docker-daemon.js";
|
|
|
77
80
|
import { hostAddressesOnce, noHostAddresses, unionOf } from "./docker-host-addresses.js";
|
|
78
81
|
import { DOCUMENTS_ENV } from "./pdf-pages.js";
|
|
79
82
|
import { CAP_MODES } from "./cap.js";
|
|
80
|
-
import { blockersOf, CODE_NODES_ENV, issueOf,
|
|
83
|
+
import { blockersOf, CODE_NODES_ENV, issueOf, NOT_SET_UP } from "./runnable.js";
|
|
81
84
|
import { hostSecrets, SECRET_NAMES, secret, withSecrets } from "./secrets.js";
|
|
82
85
|
import { isSecretWriteOperation, SECRET_WRITE_REFUSAL, secretsWritableFields, secretWriterFacts, writesSecretFor, writesSecretsAllowed } from "./secret-writes.js";
|
|
83
86
|
import { bootSealKey, withSealKey } from "./seal-key.js";
|
|
84
87
|
import { ServerLockHeldError, takeServerLock } from "./server-lock.js";
|
|
85
88
|
import { DRAIN_TIMEOUT } from "./runner/beside.js";
|
|
86
89
|
import { analyticsFilter, analyticsView, statsView } from "./stats.js";
|
|
87
|
-
import {
|
|
90
|
+
import { agentLoopOverStore } from "./store-reads/loop.js";
|
|
91
|
+
import { printable } from "./learn/index.js";
|
|
92
|
+
import { agentCostOverStore, agentLearningOverStore, allInOf, costRunOf, learningCountsOverStore, learningSpendOverStore, runLearningEnd } from "./store-reads/learning.js";
|
|
88
93
|
import { figuresOf, LearningBatches } from "./learning-batch.js";
|
|
89
|
-
import { costCsv, learningCostQuery } from "./learning-cost.js";
|
|
94
|
+
import { costCsv, learningCostQuery, RUN_PATHS } from "./learning-cost.js";
|
|
90
95
|
import { evalOf, evalsOf, recordEval } from "./learning-evals.js";
|
|
91
96
|
import { keyOf, SEAL_KEY_ENV, TOOL_FIELDS } from "./tool-keys.js";
|
|
92
97
|
import { toolKeysOverStore } from "./tool-keys-store.js";
|
|
93
98
|
import { SIGN_INS_DIR, vendorsOver } from "./sign-ins.js";
|
|
94
99
|
import { signInsOverStore } from "./sign-ins-store.js";
|
|
95
|
-
import { MCP_AUTH_TYPES, mcpAuthOf, nameOf as mcpNameOf } from "./mcp-probe.js";
|
|
96
|
-
import { composioSave, composioTools } from "./composio-preset.js";
|
|
100
|
+
import { boundTool, MCP_AUTH_TYPES, marked, mcpAuthOf, nameOf as mcpNameOf } from "./mcp-probe.js";
|
|
101
|
+
import { composioForget, composioNote, composioSave, composioTools } from "./composio-preset.js";
|
|
97
102
|
import { mcpServersOverStore } from "./mcp-servers-store.js";
|
|
103
|
+
import { getMcpServer, listMcpServers } from "./mcp-store.js";
|
|
98
104
|
import { privateHostsRoute } from "./mcp-private-hosts.js";
|
|
99
105
|
import { metaToolOf } from "./mcp-meta.js";
|
|
106
|
+
import { mcpPinOf } from "./mcp-gateway.js";
|
|
100
107
|
import { MCP_SETTINGS_PAGE, signInCookie, startedHere } from "./mcp-oauth.js";
|
|
101
108
|
import { WEBHOOK_EVENTS, WEBHOOK_FILE, waitMarkerOf, Webhooks } from "./webhooks.js";
|
|
102
109
|
import { appPermissionWarnings } from "./template-github-permissions.js";
|
|
@@ -111,10 +118,15 @@ import { HookCut, receivePush } from "./push-handler.js";
|
|
|
111
118
|
import { TRIGGER_ADAPTERS } from "./trigger-adapters.js";
|
|
112
119
|
import { webhook } from "./trigger-webhook.js";
|
|
113
120
|
import { SCHEME_NAMES } from "./trigger-signatures.js";
|
|
114
|
-
import { permissionFrom } from "./tool-gate.js";
|
|
121
|
+
import { permissionFrom, pinnedEffect, toolEffect } from "./tool-gate.js";
|
|
122
|
+
import { isMcpWildcard, mcpNameOf as mcpToolOf, mcpToolName, monidDroppedWords, monidNameOf } from "./tool-names.js";
|
|
123
|
+
import { wireName } from "./catalog.js";
|
|
115
124
|
import { CATCHUP_WINDOW_S, FAILURES_TO_PAUSE, HISTORY_KEPT, MIN_EVERY_S, PAYLOAD_KEPT_BYTES, SOURCE_KINDS, TARGET_KINDS, Triggers } from "./triggers.js";
|
|
116
|
-
import { applyBodyOf, COMPUTER_FIX, compiled, githubTriggerUnconnected, githubTriggerWords, madeTriggerIssues, packageModel, packageTiers, packageView, pickComputer, readPackages } from "./templates.js";
|
|
117
|
-
import {
|
|
125
|
+
import { applyBodyOf, COMPUTER_FIX, compiled, githubTriggerUnconnected, githubTriggerWords, madeTriggerIssues, mcpSetUp, onServerName, onServers, packageDetail, packageModel, packageTiers, packageView, pickComputer, readPackages, serversFor, TemplateRegistry } from "./templates.js";
|
|
126
|
+
import { deleteTemplate, importTemplate, loadImported } from "./template-import.js";
|
|
127
|
+
import { templateInstallLink, templateLink } from "./console-links.js";
|
|
128
|
+
import { GITHUB_HOSTS } from "./template-source.js";
|
|
129
|
+
import { checkDefinitionBody, DEFAULT_INPUT_SCHEMA, definitionBodyIssues, EXTERNAL_NAME, ID, IDEMPOTENCY_TTL_S, inputIssues, inputSchemaOf, isObject, stable, unknownFields } from "./validate.js";
|
|
118
130
|
import { agentTools, BROWSER_VENDOR_IDS, browserKeyRow, isUnavailable, keptVendor, loadToolSettings, recheckPlane, settingsIssues, whyUnavailable, withDefaults } from "./tool-plane.js";
|
|
119
131
|
import { wakeAnsweredBySetting } from "./settings-wake.js";
|
|
120
132
|
import { toolSettingsOverStore } from "./tool-settings-store.js";
|
|
@@ -227,6 +239,8 @@ export const ROUTES = [
|
|
|
227
239
|
{ method: "POST", pattern: /^\/runs\/([^/]+)\/cancel$/, name: "cancelRun" },
|
|
228
240
|
{ method: "POST", pattern: /^\/runs\/([^/]+)\/approvals\/([^/]+)$/, name: "answerApproval" },
|
|
229
241
|
{ method: "POST", pattern: /^\/runs\/([^/]+)\/archive$/, name: "archiveRun" },
|
|
242
|
+
// A person's or an eval's grade of an ended run (learn/promote.ts): what promotion by replay reads.
|
|
243
|
+
{ method: "PUT", pattern: /^\/runs\/([^/]+)\/grade$/, name: "gradeRun" },
|
|
230
244
|
{ method: "POST", pattern: /^\/runs\/([^/]+)\/unarchive$/, name: "unarchiveRun" },
|
|
231
245
|
{ method: "GET", pattern: /^\/runs\/([^/]+)\/graph$/, name: "getRunGraph" },
|
|
232
246
|
{ method: "POST", pattern: /^\/workflows\/validate$/, name: "validateWorkflow" },
|
|
@@ -306,6 +320,8 @@ export const ROUTES = [
|
|
|
306
320
|
{ method: "GET", pattern: /^\/triggers\/([^/]+)\/firings$/, name: "listTriggerFirings" },
|
|
307
321
|
{ method: "POST", pattern: /^\/triggers\/([^/]+)\/secret$/, name: "rotateTriggerSecret" },
|
|
308
322
|
{ method: "GET", pattern: /^\/templates$/, name: "listTemplates" },
|
|
323
|
+
{ method: "POST", pattern: /^\/templates\/import$/, name: "importTemplate" },
|
|
324
|
+
{ method: "DELETE", pattern: /^\/templates\/([^/]+)$/, name: "deleteTemplate" },
|
|
309
325
|
{ method: "POST", pattern: /^\/templates\/([^/]+)\/apply$/, name: "applyTemplate" },
|
|
310
326
|
// Answered before the bearer check: the request's signature is its credential.
|
|
311
327
|
{ method: "POST", pattern: /^\/hooks\/([^/]+)$/, name: "receiveHook" },
|
|
@@ -318,12 +334,14 @@ export const ROUTES = [
|
|
|
318
334
|
{ method: "POST", pattern: /^\/mcp$/, name: "callMcp" },
|
|
319
335
|
{ method: "GET", pattern: /^\/agents\/([^/]+)\/learning$/, name: "getAgentLearning" },
|
|
320
336
|
{ method: "GET", pattern: /^\/agents\/([^/]+)\/learning\/cost$/, name: "getLearningCost" },
|
|
337
|
+
{ method: "GET", pattern: /^\/agents\/([^/]+)\/learning\/promotions$/, name: "listLearningPromotions" },
|
|
321
338
|
{ method: "POST", pattern: /^\/agents\/([^/]+)\/learning\/batches$/, name: "createLearningBatch" },
|
|
322
339
|
{ method: "GET", pattern: /^\/agents\/([^/]+)\/learning\/batches$/, name: "listLearningBatches" },
|
|
323
340
|
{ method: "GET", pattern: /^\/agents\/([^/]+)\/learning\/batches\/([^/]+)$/, name: "getLearningBatch" },
|
|
324
341
|
{ method: "POST", pattern: /^\/agents\/([^/]+)\/learning\/batches\/([^/]+)\/cancel$/, name: "cancelLearningBatch" },
|
|
325
342
|
{ method: "GET", pattern: /^\/agents\/([^/]+)\/learning\/evals$/, name: "listLearningEvals" },
|
|
326
343
|
{ method: "POST", pattern: /^\/agents\/([^/]+)\/learning\/evals$/, name: "recordLearningEval" },
|
|
344
|
+
{ method: "GET", pattern: /^\/agents\/([^/]+)\/learning\/loop$/, name: "getLearningLoop" },
|
|
327
345
|
{ method: "GET", pattern: /^\/agents\/([^/]+)\/learning\/notes$/, name: "listLearningNotes" },
|
|
328
346
|
{ method: "GET", pattern: /^\/agents\/([^/]+)\/learning\/log$/, name: "listLearningLog" },
|
|
329
347
|
{ method: "GET", pattern: /^\/agents\/([^/]+)\/learning\/files\/([^/]+)$/, name: "readLearningFile" },
|
|
@@ -516,7 +534,7 @@ function capabilitiesWith(env, maxRuns, harnesses, learning, { needs, priced },
|
|
|
516
534
|
tool_keys: { routes: true, at_rest: "sealed" },
|
|
517
535
|
/** /settings/mcp-servers: remote MCP servers previewed and saved, each credential sealed under the server's seal key,
|
|
518
536
|
* which always exists (seal-key.ts), so MCP credentials are always kept sealed. */
|
|
519
|
-
mcp_client: { transports: ["streamable-http"], auth: [...MCP_AUTH_TYPES], at_rest: "sealed", harnesses: [...
|
|
537
|
+
mcp_client: { transports: ["streamable-http"], auth: [...MCP_AUTH_TYPES], at_rest: "sealed", harnesses: [...HARNESSES] },
|
|
520
538
|
/** This server's learning switch (`--learning`): on, a run learns when its agent says `learning: true`; off, none does. */
|
|
521
539
|
learning,
|
|
522
540
|
/** /settings/webhook: one URL POSTed, signed by the Standard Webhooks spec, when a run needs its person and when it
|
|
@@ -690,6 +708,10 @@ async function startHolding(options, data, checked, stops) {
|
|
|
690
708
|
...(options.onStoreLost ? { onOwnerLost: options.onStoreLost } : {}),
|
|
691
709
|
}), (error) => onSqlite && error instanceof StoreOwned, replacedUntil, waitingForReplaced);
|
|
692
710
|
stops.push(() => store.close());
|
|
711
|
+
// The packages served: the bundled ones, read and checked before the start, and those imported here, which the store
|
|
712
|
+
// keeps and are checked again as they load (template-import.ts). One that no longer checks is left out, said in the log.
|
|
713
|
+
const registry = new TemplateRegistry(templates);
|
|
714
|
+
await loadImported({ registry, store }, (id, why) => log?.(logLine("template_import_skipped", { template: id, why })));
|
|
693
715
|
// The person's own computers paired with this server (computer-attach.ts): their live sockets are this process's hub,
|
|
694
716
|
// which the runner beside the server shares (Serve.attachHub), so one process holds them. A second server on this
|
|
695
717
|
// store is refused above (its owner lock).
|
|
@@ -743,24 +765,23 @@ async function startHolding(options, data, checked, stops) {
|
|
|
743
765
|
const mcpServers = mcpServersOverStore(store, own(withSecrets(base, "own")), VERSION);
|
|
744
766
|
if (options.githubMcpOrigin)
|
|
745
767
|
mcpServers.appOrigin = options.githubMcpOrigin;
|
|
746
|
-
|
|
747
|
-
//
|
|
748
|
-
//
|
|
749
|
-
//
|
|
768
|
+
mcpServers.standIns = options.mcpStandIns === true;
|
|
769
|
+
// The saved MCP servers' metadata (their addresses and the tools they list), a snapshot the checks read in step (which
|
|
770
|
+
// servers are saved, a workflow's grants, the template apply): the server is the one writer of these rows (a save,
|
|
771
|
+
// refresh, sign-in or delete), so the snapshot is refreshed after each of those and reads what is saved now. An agent's
|
|
772
|
+
// save lists its granted servers live and pins their tools on its revision (saveable, mcpListingOf); the runner reads
|
|
773
|
+
// that pin and the credentials from the store at a run's claim (runner/mcp-claim.ts); this server hands a run no MCP
|
|
774
|
+
// source. Each with what it is (its source and toolkit, mcp-sources.ts), which a template's apply maps its MCP needs on.
|
|
750
775
|
let mcpMeta = new Map();
|
|
751
776
|
const refreshMcpMeta = async () => {
|
|
752
|
-
mcpMeta = new Map((await store
|
|
777
|
+
mcpMeta = new Map(await Promise.all((await listMcpServers(store)).map(async (row) => [row.name, { url: row.url, auth: row.auth, tools: row.tools ?? [], source: await mcpServers.sourceOf(row) }])));
|
|
753
778
|
};
|
|
754
779
|
await refreshMcpMeta();
|
|
755
780
|
// Each saved server's tools in the harnesses' shape (the registry keeps input_schema; a bound tool takes inputSchema),
|
|
756
781
|
// with whether each can be granted: a known meta tool can't (mcp-meta.ts).
|
|
757
782
|
const mcpTools = (server) => {
|
|
758
783
|
const saved = mcpMeta.get(server);
|
|
759
|
-
return saved
|
|
760
|
-
const meta = metaToolOf(saved.url, tool.name);
|
|
761
|
-
const bound = { name: tool.name, ...(tool.title ? { title: tool.title } : {}), ...(tool.description ? { description: tool.description } : {}), inputSchema: (tool.input_schema ?? {}), ...(tool.annotations ? { annotations: tool.annotations } : {}) };
|
|
762
|
-
return meta ? { ...bound, grantable: false, reason: meta.reason } : bound;
|
|
763
|
-
});
|
|
784
|
+
return saved && marked(saved.url, { tools: saved.tools.map((tool) => ({ name: tool.name, ...(tool.title ? { title: tool.title } : {}), ...(tool.description ? { description: tool.description } : {}), inputSchema: (tool.input_schema ?? {}), ...(tool.annotations ? { annotations: tool.annotations } : {}) })) }).tools;
|
|
764
785
|
};
|
|
765
786
|
// The server's tool settings, in the store: capabilities say what they resolve to, again after a PUT. load() reads them
|
|
766
787
|
// once here.
|
|
@@ -954,6 +975,19 @@ async function startHolding(options, data, checked, stops) {
|
|
|
954
975
|
}
|
|
955
976
|
return { none: `this server has no shell to give an agent now: Archil is off (Settings → Workspace), and the docker box is unavailable here (${why})` };
|
|
956
977
|
};
|
|
978
|
+
/** Each package's computer list read against this server now, as a listing shows it (`computer_here`): what an apply
|
|
979
|
+
* here would pick (pickComputer), the shell asked for once for them all. */
|
|
980
|
+
const computerHere = async (packages) => {
|
|
981
|
+
const here = packages.some((one) => one.computer) ? await shellHere() : undefined;
|
|
982
|
+
return (pkg) => {
|
|
983
|
+
const pick = here && pickComputer(pkg, here);
|
|
984
|
+
if (!pick)
|
|
985
|
+
return null;
|
|
986
|
+
if ("refused" in pick)
|
|
987
|
+
return { entry: null, computer: null, shell: null, dropped: [], note: pick.refused };
|
|
988
|
+
return { entry: pick.entry, computer: pick.computer, shell: pick.shell, dropped: pick.dropped, note: pick.note };
|
|
989
|
+
};
|
|
990
|
+
};
|
|
957
991
|
const archil = createArchilRoutes({ store, sealKey, env: process.env, ...(options.archilControl ? { control: options.archilControl } : {}) });
|
|
958
992
|
/** Where a run of `revision` has its shell (shellOf): its computer setting as the claim reads it (computer-for-claim.ts
|
|
959
993
|
* settingOf), else its place's computer, else the place its run would resolve to (fallbackPlace). The agent's tool
|
|
@@ -971,7 +1005,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
971
1005
|
const agents = {
|
|
972
1006
|
get: (id) => getAgent(store, id),
|
|
973
1007
|
list: (options = {}) => listAgents(store, options),
|
|
974
|
-
create: (body, check, fresh) => createAgent(store, body, { ...(check ? { check } : {}), ...(fresh ? { fresh } : {}) }),
|
|
1008
|
+
create: (body, check, fresh, template) => createAgent(store, body, { ...(check ? { check } : {}), ...(fresh ? { fresh } : {}), ...(template ? { template } : {}) }),
|
|
975
1009
|
commit: (entry, body, options = {}) => commitAgent(store, entry, body, options),
|
|
976
1010
|
revisions: (id) => agentRevisions(store, id),
|
|
977
1011
|
revision: (agentId, revisionId) => agentRevision(store, agentId, revisionId),
|
|
@@ -1066,6 +1100,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1066
1100
|
// (called at request time, after they are assigned) rather than reading them before their declaration.
|
|
1067
1101
|
told: (error) => told(error),
|
|
1068
1102
|
runnable,
|
|
1103
|
+
pinFirst: (revision) => pinFirst(revision),
|
|
1069
1104
|
readyFiles: (ids) => uploads.readyFiles(ids),
|
|
1070
1105
|
files: { hold: (runId, ids) => uploads.hold(runId, ids), release: (runId) => uploads.release(runId) },
|
|
1071
1106
|
fallbackPlace: (kind, tools) => fallbackPlace(kind, tools),
|
|
@@ -1165,7 +1200,8 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1165
1200
|
// Every round the run kept (a review follow-up opens a round of its own), in order: what each one learned and merged.
|
|
1166
1201
|
const newest = await store.learning.proposal(runId);
|
|
1167
1202
|
const ends = await Promise.all(Array.from({ length: newest?.round ?? 1 }, (_, i) => runLearningEnd(store, runId, i + 1)));
|
|
1168
|
-
|
|
1203
|
+
// A run still going names no path yet (its end writes it): the batch reads it as the agent's until then.
|
|
1204
|
+
return figuresOf((await costRunOf(store, run, 0)) ?? { path: "agent", ...(await allInOf(store, run)) }, ends);
|
|
1169
1205
|
},
|
|
1170
1206
|
// A batch's reads are the learning routes' reads: the same cut, the same 403 when a sign-in can't be read here.
|
|
1171
1207
|
shown: (agentId) => learningShown(agentId),
|
|
@@ -1326,6 +1362,17 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1326
1362
|
const githubConnection = () => github.view();
|
|
1327
1363
|
/** What applying a template reads of the server (templates.ts TemplatesDeps). */
|
|
1328
1364
|
const templateDeps = { githubConnection };
|
|
1365
|
+
// A template import reads GitHub's own hosts alone (a test's faux GitHub in their place), with an installation token of
|
|
1366
|
+
// the App when GitHub is connected (tokenForListing: metadata read, the least there is), else anonymously, and says why.
|
|
1367
|
+
const importDeps = {
|
|
1368
|
+
registry, store,
|
|
1369
|
+
reach: async (signal) => {
|
|
1370
|
+
const api = options.templateImportApi ?? GITHUB_API;
|
|
1371
|
+
const hosts = options.templateImportApi ? [new URL(options.templateImportApi).host] : GITHUB_HOSTS;
|
|
1372
|
+
const minted = options.templateImportApi ? { unusable: "it reads a test's GitHub" } : await githubConnect.tokenForListing(signal).catch((error) => ({ unusable: error.message }));
|
|
1373
|
+
return "token" in minted ? { api, hosts, token: minted.token } : { api, hosts, anonymous: "unusable" in minted ? minted.unusable : minted.failed };
|
|
1374
|
+
},
|
|
1375
|
+
};
|
|
1329
1376
|
// A github_app MCP server's tools are listed with an installation token of the App, narrowed to one repository it covers
|
|
1330
1377
|
// with metadata read (tokenForListing); a run's own is minted in the runner (runner/github-app.ts). Every token minted
|
|
1331
1378
|
// is a server secret while it may be in use.
|
|
@@ -1371,7 +1418,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1371
1418
|
// not passed; the worker reads them from the store over the port (sealed rows it opens with the seal key among these
|
|
1372
1419
|
// secrets), the same cut as the CLI's import, where a saved key and the server's own of the same name may differ.
|
|
1373
1420
|
workerData: { task, data, home: options.sessionsHome?.home ?? homedir(), ...(options.sessionsHome?.temp ? { temp: options.sessionsHome.temp } : {}), secrets: Object.fromEntries(SECRET_NAMES.flatMap((name) => { const value = name === SEAL_KEY_ENV ? seal.text : secret(name); return value === undefined ? [] : [[name, value]]; })) },
|
|
1374
|
-
// Started from a string (
|
|
1421
|
+
// Started from a string (node --input-type=module -e, as a test or a `--` command may), the server's flags are given again
|
|
1375
1422
|
// without that string and its type: a worker started from a file with them is refused. Otherwise the worker
|
|
1376
1423
|
// inherits them as Node passes them on, which leaves out the flags a worker may not take (on Node 24 a test
|
|
1377
1424
|
// runner's child holds many).
|
|
@@ -1495,7 +1542,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1495
1542
|
// The revision row's body is the agentic body JSON (store-backed RevisionRow types it as unknown).
|
|
1496
1543
|
const body = revision.body;
|
|
1497
1544
|
// A server's wildcard grant read as the tools its server lists now (tools.ts mcpGrantsListed, LS-07).
|
|
1498
|
-
const rows = (body.tools ?? []).some(
|
|
1545
|
+
const rows = (body.tools ?? []).some(isMcpWildcard) ? await listMcpServers(store).catch(() => []) : [];
|
|
1499
1546
|
const listed = new Map(rows.map((row) => [row.name, (row.tools ?? []).flatMap((tool) => (typeof tool?.name === "string" ? [tool.name] : []))]));
|
|
1500
1547
|
const gate = (name) => permissionFrom(name, server, (body.toolSettings ?? {}), body.approvals === "never" ? "never" : "ask");
|
|
1501
1548
|
// `deniedBy`: where each deny was set (the agent's tool settings, the server's), which a refused draft's words name.
|
|
@@ -1617,7 +1664,31 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1617
1664
|
* does not have yet. `capped`: the run has a spend cap, which a web tool's resolution reads (tool-plane.ts). */
|
|
1618
1665
|
async function runnable(revision, place, { capped = false } = {}) {
|
|
1619
1666
|
const shape = { ...shapeOf(revision), place, ...(revision.body.place ? {} : { unnamed: true }) };
|
|
1620
|
-
|
|
1667
|
+
// An agentic revision's MCP tools are checked as its save pinned them (its pin, never the server's listing now), for
|
|
1668
|
+
// a server still saved here; a granted tool its pin does not hold is said first, with how to pin it.
|
|
1669
|
+
const pin = (revision.mcpPin ?? {});
|
|
1670
|
+
if (revision.kind === "agentic") {
|
|
1671
|
+
const unpinned = (revision.body.tools ?? []).flatMap((tool, index) => {
|
|
1672
|
+
const named = mcpToolOf(tool);
|
|
1673
|
+
if (!named || !mcpMeta.has(named.server))
|
|
1674
|
+
return [];
|
|
1675
|
+
const pinned = Object.hasOwn(pin, named.server) && pin[named.server].tools.some((one) => one.name === named.tool);
|
|
1676
|
+
return pinned ? [] : [{ field: `definition.tools[${index}]`, reason: "not_an_option", message: `The MCP tool ${tool} was not pinned when this revision was saved: save the agent again to pin it.`, tool }];
|
|
1677
|
+
});
|
|
1678
|
+
if (unpinned.length)
|
|
1679
|
+
throw new ApiError("agent_not_runnable", unpinned.map((one) => one.message).join(" "), { fields: unpinned.map(({ tool: _tool, ...issue }) => issue), details: { unbound: unpinned.map((one) => one.tool), missing: {} } });
|
|
1680
|
+
}
|
|
1681
|
+
const pinnedTools = (server) => {
|
|
1682
|
+
const saved = mcpMeta.get(server);
|
|
1683
|
+
if (!saved || !Object.hasOwn(pin, server))
|
|
1684
|
+
return undefined;
|
|
1685
|
+
// A meta tool at the URL it was pinned on or at the server's URL now (a server moved to a provider's host since).
|
|
1686
|
+
return pin[server].tools.map((tool) => {
|
|
1687
|
+
const meta = metaToolOf(pin[server].url, tool.name) ?? metaToolOf(saved.url, tool.name);
|
|
1688
|
+
return meta ? { ...tool, grantable: false, reason: meta.reason } : tool;
|
|
1689
|
+
});
|
|
1690
|
+
};
|
|
1691
|
+
const blockers = await blockersOf(env, shape, settings.get(), { capped, boxes: boxOffers, computerReady, shellOf, offers, mcp: revision.kind === "agentic" ? pinnedTools : mcpTools, decisionPrice });
|
|
1621
1692
|
if (!blockers.length)
|
|
1622
1693
|
return;
|
|
1623
1694
|
const message = blockers.map((b) => b.message).join(" ");
|
|
@@ -1640,9 +1711,80 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1640
1711
|
}
|
|
1641
1712
|
/** Where a revision of `kind` naming `tools` and no place runs here: the place a new agent would be saved with. */
|
|
1642
1713
|
const fallbackPlace = (kind, tools) => defaultPlaceOf(kind, tools, boxOffers, (tool) => toolOf(tool)?.runnerOnly === true);
|
|
1643
|
-
/**
|
|
1644
|
-
*
|
|
1645
|
-
|
|
1714
|
+
/** What a save of `revision` pins of the MCP tools it grants (an agentic revision's: a workflow's nodes bind none): each
|
|
1715
|
+
* granted server listed once, now, with its saved credential (McpServersOverStore.pinListing), as `tools` each server's
|
|
1716
|
+
* listing in the harnesses' shape for the save's checks (blockersOf's `mcp`), and `pin` making the pin from them. A server
|
|
1717
|
+
* that cannot be listed keeps the agent's `previous` pin for it when every tool the save grants from it is already
|
|
1718
|
+
* there (an edit that grants nothing new from it, its instructions say); else the save is refused (422) in words naming
|
|
1719
|
+
* it: nothing is saved, and saving again once it answers pins it. */
|
|
1720
|
+
async function mcpListingOf(revision, previous) {
|
|
1721
|
+
const tools = revision.kind === "agentic" ? (revision.body.tools ?? []) : [];
|
|
1722
|
+
const granted = tools.filter((tool) => mcpToolOf(tool) !== undefined);
|
|
1723
|
+
const listings = new Map();
|
|
1724
|
+
// A server carried from the previous pin, as that pin holds it (its tools already in the harnesses' shape).
|
|
1725
|
+
const carried = new Map();
|
|
1726
|
+
const before = (previous && typeof previous === "object" ? previous : {});
|
|
1727
|
+
const carry = (server) => {
|
|
1728
|
+
const kept = Object.hasOwn(before, server) ? before[server] : undefined;
|
|
1729
|
+
const all = kept && granted.every((tool) => { const named = mcpToolOf(tool); return named.server !== server || kept.tools.some((one) => one.name === named.tool); });
|
|
1730
|
+
if (all)
|
|
1731
|
+
carried.set(server, kept);
|
|
1732
|
+
return all;
|
|
1733
|
+
};
|
|
1734
|
+
const refused = [];
|
|
1735
|
+
await Promise.all([...new Set(granted.map((tool) => mcpToolOf(tool).server))].map(async (server) => {
|
|
1736
|
+
try {
|
|
1737
|
+
const listing = await mcpServers.pinListing(server, stopping.signal);
|
|
1738
|
+
if (listing)
|
|
1739
|
+
listings.set(server, listing);
|
|
1740
|
+
}
|
|
1741
|
+
catch (error) {
|
|
1742
|
+
if (!(error instanceof ApiError))
|
|
1743
|
+
throw error;
|
|
1744
|
+
if (carry(server))
|
|
1745
|
+
return;
|
|
1746
|
+
const why = error.extra.fields?.[0]?.message ?? error.message;
|
|
1747
|
+
refused.push({ field: `definition.tools[${tools.findIndex((tool) => mcpToolOf(tool)?.server === server)}]`, reason: "unavailable", message: `${sentence(`The MCP server ${server} could not be listed to pin its tools: ${why}`)} Nothing was saved: save again once it answers.` });
|
|
1748
|
+
}
|
|
1749
|
+
}));
|
|
1750
|
+
if (refused.length)
|
|
1751
|
+
throw invalid(refused.sort((a, b) => a.field.localeCompare(b.field)));
|
|
1752
|
+
const bound = (server) => {
|
|
1753
|
+
const kept = carried.get(server);
|
|
1754
|
+
// A carried server's tools are checked as pinned, a meta tool marked at its URL then or now (as runnable does).
|
|
1755
|
+
if (kept)
|
|
1756
|
+
return kept.tools.map((tool) => { const meta = metaToolOf(kept.url, tool.name) ?? (mcpMeta.has(server) ? metaToolOf(mcpMeta.get(server).url, tool.name) : undefined); return meta ? { ...tool, grantable: false, reason: meta.reason } : tool; });
|
|
1757
|
+
return listings.get(server)?.tools.map((tool) => ({ ...boundTool(tool), ...(tool.grantable === false ? { grantable: false, reason: tool.reason } : {}) }));
|
|
1758
|
+
};
|
|
1759
|
+
return {
|
|
1760
|
+
// A workflow's grants are checked on the registry's listing, as before: its nodes bind no MCP tool, so the save refuses them.
|
|
1761
|
+
tools: revision.kind === "agentic" ? bound : mcpTools,
|
|
1762
|
+
pin: () => {
|
|
1763
|
+
if (!granted.length)
|
|
1764
|
+
return undefined;
|
|
1765
|
+
try {
|
|
1766
|
+
return mcpPinOf(granted, { server: (name) => { const kept = carried.get(name); if (kept)
|
|
1767
|
+
return kept; const listing = listings.get(name); return listing && { url: listing.url, tools: listing.tools.map(boundTool), prices: listing.prices }; } });
|
|
1768
|
+
}
|
|
1769
|
+
catch (error) {
|
|
1770
|
+
throw invalid([{ field: "definition.tools", reason: "not_an_option", message: error.message }]);
|
|
1771
|
+
}
|
|
1772
|
+
},
|
|
1773
|
+
};
|
|
1774
|
+
}
|
|
1775
|
+
/** The revision a run starts on, its MCP tools pinned: one saved with no pin that grants a tool of a server saved here is
|
|
1776
|
+
* pinned at this, its first run (mcp-pin-first.ts pinFirst, the claim's path too). One that can't be (a server that
|
|
1777
|
+
* can't be listed, or no longer lists a granted tool) is left unpinned, and runnable refuses it (409) as before. */
|
|
1778
|
+
async function pinFirst(revision) {
|
|
1779
|
+
if ((revision.mcpPin ?? null) !== null)
|
|
1780
|
+
return revision;
|
|
1781
|
+
const pin = await pinFirstOf(revision, { saved: (server) => mcpMeta.has(server), pinListing: (server) => mcpServers.pinListing(server, stopping.signal), pinOnce: (id, made) => store.agents.pinOnce(id, made) });
|
|
1782
|
+
return pin ? { ...revision, mcpPin: pin } : revision;
|
|
1783
|
+
}
|
|
1784
|
+
/** A definition being saved: refused (422 by field) when it can never run here; else what this host still lacks, and
|
|
1785
|
+
* what the save stamps on it (its MCP pin, mcpListingOf; its monid pin, on its body). A revision that names no place is
|
|
1786
|
+
* checked where it would run (fallbackPlace). */
|
|
1787
|
+
async function saveable(revision, previous) {
|
|
1646
1788
|
// The store's NewRevision keeps the revision's fields under `body` (AgenticBody|WorkflowBody); build the flat shape the
|
|
1647
1789
|
// host checks (runnable.ts RevisionShape) from it, as shapeOf does for a run's Revision.
|
|
1648
1790
|
const body = revision.body;
|
|
@@ -1653,14 +1795,16 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1653
1795
|
}
|
|
1654
1796
|
const named = (revision.kind === "agentic" ? { kind: "agentic", ...body } : workflowShape(body));
|
|
1655
1797
|
const shape = named.place ? named : { ...named, place: fallbackPlace(named.kind, named.tools ?? []), unnamed: true };
|
|
1656
|
-
const
|
|
1798
|
+
const listing = await mcpListingOf(revision, previous);
|
|
1799
|
+
const mcp = listing.tools;
|
|
1800
|
+
const blockers = await blockersOf(env, shape, settings.get(), { boxes: boxOffers, computerReady, shellOf, offers, mcp });
|
|
1657
1801
|
// An agent's default cap caps each run started without one of its own, and a web tool resolves by the cap: what a cap
|
|
1658
1802
|
// alone keeps from running under the definition's own picks, whatever this host's settings, would keep every such run
|
|
1659
1803
|
// from running, so the save is refused, not each run (claude-agent's or codex's own search, picked, under a cap).
|
|
1660
1804
|
if ((body.maxCostUsd ?? 0) > 0) {
|
|
1661
1805
|
const key = (b) => `${b.field}\n${b.message}`;
|
|
1662
|
-
const plain = new Set((await blockersOf(env, shape, {}, { boxes: boxOffers, computerReady, shellOf, offers, mcp
|
|
1663
|
-
const capped = await blockersOf(env, shape, {}, { capped: true, boxes: boxOffers, computerReady, shellOf, offers, mcp
|
|
1806
|
+
const plain = new Set((await blockersOf(env, shape, {}, { boxes: boxOffers, computerReady, shellOf, offers, mcp })).map(key));
|
|
1807
|
+
const capped = await blockersOf(env, shape, {}, { capped: true, boxes: boxOffers, computerReady, shellOf, offers, mcp, decisionPrice });
|
|
1664
1808
|
// A model with no price (`unpriced`) is a setting this host fixes (AGENT_MODEL_PRICE): a warning, as it is; the
|
|
1665
1809
|
// agent saves and updates, and only a run under the cap is refused (409). A tool's pick a cap rules out refuses it.
|
|
1666
1810
|
const added = capped.filter((b) => !plain.has(key(b)));
|
|
@@ -1670,17 +1814,46 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1670
1814
|
const never = blockers.filter((b) => !b.host);
|
|
1671
1815
|
if (never.length)
|
|
1672
1816
|
throw invalid(never.map(issueOf));
|
|
1673
|
-
|
|
1817
|
+
// Its monid grants pinned against what monid lists now, on this server's monid key (monid.ts pinMonid): the pin is
|
|
1818
|
+
// stamped on the revision's body, and its runs read it, never monid's listing. A grant monid does not list is refused
|
|
1819
|
+
// here. An endpoint a wildcard left out (priced by usage: monid.ts unboundedWords) is a warning at the wildcard's grant.
|
|
1820
|
+
const leftOut = [];
|
|
1821
|
+
if (revision.kind === "agentic") {
|
|
1822
|
+
const send = await checkFetch("monid");
|
|
1823
|
+
// The key as the server reads it (env: what it was started with, its handed secrets and its saved keys).
|
|
1824
|
+
const pinned = await pinMonid(body.tools ?? [], { key: env[MONID_KEY_ENV]?.trim(), fetch: send ?? (async () => { throw new Error("no fake of monid's API under faux"); }), signal: stopping.signal });
|
|
1825
|
+
if (pinned && "refused" in pinned)
|
|
1826
|
+
throw invalid(pinned.refused.map(({ tool, message }) => ({ field: (body.tools ?? []).includes(tool) ? `definition.tools[${body.tools.indexOf(tool)}]` : "definition.tools", reason: "not_an_option", message })));
|
|
1827
|
+
if (pinned) {
|
|
1828
|
+
// Each pinned endpoint's input held to the harness's own measured refusals, as an MCP grant is (runnable.ts
|
|
1829
|
+
// mcpGrant): one it would drop or retype refuses the save at the grant that named it, never every run.
|
|
1830
|
+
const harness = body.harness ?? DEFAULT_HARNESS;
|
|
1831
|
+
const problems = harnessOf(env, harness)?.facts?.schemaProblems;
|
|
1832
|
+
const tools = body.tools ?? [];
|
|
1833
|
+
const grantOf = (tool) => (tools.includes(tool) ? tools.indexOf(tool) : tools.indexOf(`monid:${monidNameOf(tool)?.provider}/*`));
|
|
1834
|
+
const dropped = problems ? Object.entries(pinned.pin).flatMap(([tool, { input }]) => problems(wireName(tool), input).slice(0, 1).map((first) => ({ tool, first }))) : [];
|
|
1835
|
+
if (dropped.length)
|
|
1836
|
+
throw invalid(dropped.map(({ tool, first }) => ({ field: `definition.tools[${grantOf(tool)}]`, reason: "not_an_option", message: monidDroppedWords(tool, harness, first) })));
|
|
1837
|
+
revision.body.monidPin = pinned.pin;
|
|
1838
|
+
leftOut.push(...pinned.leftOut.map(({ tool, message }) => ({ field: `definition.tools[${tools.indexOf(tool)}]`, reason: "not_an_option", message })));
|
|
1839
|
+
}
|
|
1840
|
+
}
|
|
1841
|
+
const mcpPin = listing.pin();
|
|
1842
|
+
return { warnings: [...blockers.map(issueOf), ...leftOut], stamp: mcpPin ? { mcpPin } : {} };
|
|
1674
1843
|
}
|
|
1675
1844
|
/** POST /agents' body made into its agent, as that route makes one, with what this host still lacks for it. A new agent
|
|
1676
1845
|
* that names no place is given this server's box (place.ts newAgentPlace), stamped on its revision; one that names a
|
|
1677
1846
|
* tool the box refuses (browser) keeps the runner. */
|
|
1678
|
-
async function createAgentOf(body) {
|
|
1847
|
+
async function createAgentOf(body, template) {
|
|
1679
1848
|
let warnings = [];
|
|
1680
1849
|
const definition = checkDefinitionBody(body);
|
|
1681
1850
|
const named = Array.isArray(definition.definition.tools) ? definition.definition.tools : [];
|
|
1682
1851
|
const fresh = named.some((tool) => typeof tool === "string" && toolOf(tool)?.runnerOnly) ? { reason: "" } : newAgentPlace(boxOffers);
|
|
1683
|
-
const entry = await agents.create(definition, async (revision) =>
|
|
1852
|
+
const entry = await agents.create(definition, async (revision) => {
|
|
1853
|
+
const saved = await saveable(revision);
|
|
1854
|
+
warnings = saved.warnings;
|
|
1855
|
+
return saved.stamp;
|
|
1856
|
+
}, "place" in fresh ? { place: fresh.place, tools: NEW_AGENT_TOOLS } : undefined, template);
|
|
1684
1857
|
return { entry, warnings };
|
|
1685
1858
|
}
|
|
1686
1859
|
/** Agent `source`'s learned workflow `raw` made into a workflow agent of its own, as POST /agents makes one
|
|
@@ -1731,22 +1904,30 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1731
1904
|
}
|
|
1732
1905
|
/** A template package applied: its parameters and the owner's grants checked (422), then the secrets and required MCP
|
|
1733
1906
|
* servers it names (409, nothing made; an MCP server it can do without is skipped, with a warning), then its
|
|
1734
|
-
* agent made as POST /agents makes one,
|
|
1735
|
-
* deny the owner set on this server stays, with a warning), its body held to POST /agents' limit (413), on the first harness of its list this server runs and the model packageModel
|
|
1907
|
+
* agent made as POST /agents makes one, granted the MCP tools the owner ticked (grants) alone, each set to allow (a
|
|
1908
|
+
* deny the owner set on this server stays, with a warning): a tool left unticked is not the agent's, under any approvals, its body held to POST /agents' limit (413), on the first harness of its list this server runs and the model packageModel
|
|
1736
1909
|
* picks, then each trigger on it as POST /triggers makes one. A trigger refused undoes the apply: the triggers made
|
|
1737
1910
|
* before it are deleted and the agent is archived (an agent store keeps every agent), and the refusal is the answer, a 422's fields under `triggers.<i>`; a
|
|
1738
1911
|
* github trigger GitHub is not connected for is skipped instead, with a warning there, and one made is said there. A webhook
|
|
1739
1912
|
* trigger's secret is not in the answer (the Idempotency-Key record would keep it): POST /triggers/{id}/secret makes one. */
|
|
1740
|
-
async function applyTemplate(
|
|
1741
|
-
const { parameters, grants, model: override, approvals } = applyBodyOf(
|
|
1742
|
-
const missing =
|
|
1743
|
-
|
|
1744
|
-
|
|
1913
|
+
async function applyTemplate(template, body) {
|
|
1914
|
+
const { parameters, grants: asked, servers: picks, model: override, approvals } = applyBodyOf(template, body);
|
|
1915
|
+
const missing = template.secrets.filter((name) => !secret(name, storedKeys));
|
|
1916
|
+
// Each MCP need on the saved server whose source and toolkit match (the owner's pick when several do, never a silent
|
|
1917
|
+
// one: several and no pick is a 422); the package's
|
|
1918
|
+
// tool names, mcp:<toolkit>/<tool>, read as that server's from here on (templates.ts onServers).
|
|
1919
|
+
const mapped = serversFor(template, [...mcpMeta].map(([name, meta]) => ({ name, ...meta.source })), picks);
|
|
1920
|
+
const servers = Object.fromEntries(mapped.flatMap(({ need, server }) => (server ? [[need.toolkit, server]] : [])));
|
|
1921
|
+
const pkg = onServers(template, servers);
|
|
1922
|
+
const saved = mapped.flatMap(({ need, server }) => (server ? [{ ...need, server }] : []));
|
|
1923
|
+
const unsaved = mapped.filter(({ server }) => !server).map(({ need }) => need);
|
|
1924
|
+
// A grant of a need with no server here grants nothing: dropped before the names move, so it never reads as a tool
|
|
1925
|
+
// of a saved server that happens to be named as its toolkit.
|
|
1926
|
+
const grants = asked.filter((tool) => Object.hasOwn(servers, mcpToolOf(tool)?.server ?? "")).map((tool) => onServerName(tool, servers));
|
|
1745
1927
|
const needed = unsaved.filter((need) => need.required);
|
|
1746
1928
|
if (missing.length || needed.length) {
|
|
1747
1929
|
const fix = "Add it in Settings → Model keys or Settings → Tool keys, or set it where AgentRun starts, then apply the template again.";
|
|
1748
|
-
|
|
1749
|
-
throw new ApiError("agent_not_runnable", `The ${pkg.name} template needs ${[...missing, ...needed.map((need) => `the MCP server ${need.server}`)].join(" and ")}, which this server does not have. Nothing was created.`, { fields: [...missing.map((name) => ({ field: `secrets.${name}`, reason: NOT_SET_UP, message: `${name} is not set on this server.`, fix })), ...needed.map((need) => ({ field: `mcp.${need.server}`, reason: NOT_SET_UP, message: `No MCP server ${need.server} is saved on this server.`, fix: server }))] });
|
|
1930
|
+
throw new ApiError("agent_not_runnable", `The ${pkg.name} template needs ${[...missing, ...needed.map((need) => `a ${need.source} MCP server of the toolkit ${need.toolkit}`)].join(" and ")}, which this server does not have. Nothing was created.`, { fields: [...missing.map((name) => ({ field: `secrets.${name}`, reason: NOT_SET_UP, message: `${name} is not set on this server.`, fix })), ...needed.map((need) => ({ field: `mcp.${need.toolkit}`, reason: NOT_SET_UP, message: `No saved MCP server is ${need.source} ${need.toolkit}.`, fix: mcpSetUp(need) }))] });
|
|
1750
1931
|
}
|
|
1751
1932
|
// The package's computer list: the first entry this server meets now (templates.ts pickComputer), written as the
|
|
1752
1933
|
// agent's computer; a fallback, or a shell tool that computer does not run, said under `computer`. A list none of
|
|
@@ -1756,7 +1937,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1756
1937
|
throw new ApiError("agent_not_runnable", pick.refused, { fields: [{ field: "computer", reason: NOT_SET_UP, message: pick.refused, fix: COMPUTER_FIX }] });
|
|
1757
1938
|
const computerWarnings = pick?.note ? [{ field: "computer", reason: pick.entry === "none" ? NOT_SET_UP : "not_an_option", message: pick.note }] : [];
|
|
1758
1939
|
// An MCP server the package can do without is skipped, and said: its tools are not granted.
|
|
1759
|
-
const skipped = unsaved.map((need) => ({ field: `mcp.${need.
|
|
1940
|
+
const skipped = unsaved.map((need) => ({ field: `mcp.${need.toolkit}`, reason: NOT_SET_UP, message: `No saved MCP server is ${need.source} ${need.toolkit}, so the agent was made without its tools (${need.tools.join(", ")}).`, fix: mcpSetUp(need) }));
|
|
1760
1941
|
const harness = pkg.harness && (pkg.harness.find((id) => offers.some((offer) => offer.id === id && offer.available)) ?? pkg.harness[0]);
|
|
1761
1942
|
const picked = override ? { model: override } : await packageModel(env, pkg.model, harness ?? DEFAULT_HARNESS);
|
|
1762
1943
|
const model = picked.model;
|
|
@@ -1773,17 +1954,18 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1773
1954
|
// The agent's approvals: the apply's override, else the package's own (a template whose job runs on triggers says
|
|
1774
1955
|
// never), else ask. Deny and pins hold either way.
|
|
1775
1956
|
const chosenApprovals = approvals ?? pkg.approvals;
|
|
1776
|
-
const made = compiled(pkg, parameters, { ...(harness ? { harness } : {}), ...(model ? { model } : {}), ...(tiers.modelTiers ? { modelTiers: tiers.modelTiers } : {}), mcp: saved, defaultTools, grants:
|
|
1957
|
+
const made = compiled(pkg, parameters, { ...(harness ? { harness } : {}), ...(model ? { model } : {}), ...(tiers.modelTiers ? { modelTiers: tiers.modelTiers } : {}), mcp: saved, defaultTools, grants, held: denied, ...(chosenApprovals ? { approvals: chosenApprovals } : {}), ...(pick ? { computer: pick } : {}) }, templateDeps);
|
|
1777
1958
|
// Every trigger is checked as POST /triggers checks it, its parameters filled, before anything is made: a schedule
|
|
1778
1959
|
// from a parameter that does not read, or a date that has passed, refuses the apply (422 under triggers.<i>).
|
|
1779
|
-
const refusedTriggers = madeTriggerIssues(made.triggers, Date.now());
|
|
1960
|
+
const refusedTriggers = madeTriggerIssues(made.triggers, Date.now(), pkg.inputSchema);
|
|
1780
1961
|
if (refusedTriggers.length)
|
|
1781
1962
|
throw invalid(refusedTriggers);
|
|
1782
1963
|
// POST /agents' and POST /triggers' own body limit: parameters filled in more than once can grow a package past it.
|
|
1783
1964
|
for (const one of [made.agent, ...made.triggers])
|
|
1784
1965
|
if (Buffer.byteLength(JSON.stringify(one)) > MAX_BODY)
|
|
1785
1966
|
throw new ApiError("payload_too_large", `the ${pkg.name} template, its parameters filled in, makes a body over ${MAX_BODY} bytes`, { details: { limit: "max_body_bytes" } });
|
|
1786
|
-
|
|
1967
|
+
// The agent keeps where it came from (its first revision's package): the package's id, version and, imported, its SHA.
|
|
1968
|
+
const { entry, warnings } = await createAgentOf(made.agent, { id: pkg.id, version: pkg.version, sha: pkg.origin?.sha ?? null });
|
|
1787
1969
|
const ids = [];
|
|
1788
1970
|
// Each webhook trigger's signing secret, minted as it is made: handed back in the apply's first answer alone, as POST
|
|
1789
1971
|
// /triggers hands back its own, so the owner can give it to the sender.
|
|
@@ -1826,10 +2008,12 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1826
2008
|
}
|
|
1827
2009
|
// A pinned send whose destination parameter was not given is denied, never let go anywhere: said, by its gate name.
|
|
1828
2010
|
const unpinned = made.unpinned.map(({ tool, parameters: named }) => ({ field: `pins.${tool}`, reason: NOT_SET_UP, message: `${tool}'s arguments are fixed by ${named.map((one) => `the ${one} parameter`).join(" and ")}, which was not given, so the agent was made with ${tool} set to deny: it can't call it at all. Apply again with ${named.join(" and ")} set to let it.` }));
|
|
1829
|
-
// A GitHub tool the
|
|
1830
|
-
// from GitHub, never assumed), where the github MCP server runs on the App's tokens: said now, before a run's
|
|
1831
|
-
// call is refused; or that the check could not be made (template-github-permissions.ts).
|
|
1832
|
-
|
|
2011
|
+
// A GitHub tool the owner granted (ticked) that an installation of Connect GitHub's App does not hold the permission
|
|
2012
|
+
// for (read from GitHub, never assumed), where the github MCP server runs on the App's tokens: said now, before a run's
|
|
2013
|
+
// first call is refused; or that the check could not be made (template-github-permissions.ts). An unticked tool is
|
|
2014
|
+
// not the agent's, so nothing is said of it.
|
|
2015
|
+
const ticked = saved.map((need) => ({ ...need, tools: need.tools.filter((tool) => grants.includes(mcpToolName(need.server, tool))) }));
|
|
2016
|
+
const appShort = await appPermissionWarnings({ name: pkg.name, mcp: ticked }, (server) => mcpMeta.get(server)?.auth === "github_app", () => githubConnect.installationPermissions(stopping.signal));
|
|
1833
2017
|
// A webhook trigger's secret is in no apply answer: each one's warning sends the person to the console for it.
|
|
1834
2018
|
const hooks = made.triggers.flatMap((trigger, i) => (isObject(trigger.source) && trigger.source.kind === "webhook" ? [templateTriggerSecret(i)] : []));
|
|
1835
2019
|
// Each github trigger: what it runs on, when made (a note, never a lack); skipped, what to do about it.
|
|
@@ -1839,17 +2023,20 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1839
2023
|
// Each trigger it made, a webhook trigger's with its secret's metadata; the values go back beside the answer, never in it
|
|
1840
2024
|
// (the route adds them to the first answer to the owner's session, after the Idempotency-Key's record is written).
|
|
1841
2025
|
const minted = new Map(secrets.map(({ trigger_id, secret }) => [trigger_id, secret]));
|
|
1842
|
-
|
|
2026
|
+
// Which saved server each MCP need runs on (null: none here, said under mcp.<toolkit>).
|
|
2027
|
+
const used = Object.fromEntries(mapped.map(({ need, server }) => [need.toolkit, server]));
|
|
2028
|
+
const applied = { template: pkg.id, version: pkg.version, agent_id: entry.agent.id, servers: used, trigger_ids: ids, ...templateWebhookSecrets([...minted.keys()], new Date().toISOString()), warnings: [...skipped, ...kept, ...modelWarnings, ...computerWarnings, ...unpinned, ...warnings, ...hooks, ...githubTriggers, ...appShort] };
|
|
1843
2029
|
return { applied, minted };
|
|
1844
2030
|
}
|
|
1845
|
-
/** A run create's issues told from the input this server checks (explain.ts): an agentic run's
|
|
1846
|
-
* with the documented run bodies;
|
|
2031
|
+
/** A run create's issues told from the input this server checks (explain.ts): an agentic run's input schema in force
|
|
2032
|
+
* (`{content: string}` with none), with the documented run bodies;a workflow run's its workflow's input schema, never the agentic example. Each value
|
|
1847
2033
|
* suggested must pass this route's own checks of the body, the workflow's input check among them. */
|
|
1848
2034
|
async function explainRun(issues, body, revision) {
|
|
1849
2035
|
const dsl = revision?.kind === "workflow" ? await import("@parcha/agentrun-dsl") : undefined;
|
|
1850
2036
|
const workflow = dsl && revision?.kind === "workflow" ? revision.body.workflow : undefined;
|
|
1851
2037
|
const declared = workflow?.input?.schemaId === undefined ? undefined : workflow.schemas[workflow.input.schemaId];
|
|
1852
|
-
const
|
|
2038
|
+
const typed = revision?.kind === "agentic" ? inputSchemaOf(revision.body.inputSchema) : DEFAULT_INPUT_SCHEMA;
|
|
2039
|
+
const input = !dsl ? typed : declared ? dsl.resolveSchemaForWorkflow(workflow, declared) : { type: "object" };
|
|
1853
2040
|
const base = deref(openapi, { $ref: "#/components/schemas/RunCreate" }) ?? {};
|
|
1854
2041
|
const schema = { ...base, properties: { ...base.properties, input } };
|
|
1855
2042
|
const check = (sent) => {
|
|
@@ -1857,14 +2044,15 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1857
2044
|
const issues = runBodyIssues(value);
|
|
1858
2045
|
if (!revision || !isObject(value.input))
|
|
1859
2046
|
return issues;
|
|
1860
|
-
return [...issues, ...(dsl ? workflowInputIssues(dsl.validateWorkflow, revision, value.input) : inputIssues(value.input,
|
|
2047
|
+
return [...issues, ...(dsl ? workflowInputIssues(dsl.validateWorkflow, revision, value.input) : inputIssues(value.input, typed))];
|
|
1861
2048
|
};
|
|
1862
2049
|
return explain(issues, openapi, schema, { examples: dsl ? [] : examplesOf("createRun"), body, check });
|
|
1863
2050
|
}
|
|
1864
|
-
/** A run's input: an agentic run's
|
|
2051
|
+
/** A run's input: an agentic run's what its revision's input schema in force takes (`{content: string}` with none), a
|
|
2052
|
+
* workflow run's what its workflow's input schema takes. */
|
|
1865
2053
|
async function inputIssuesOf(revision, input) {
|
|
1866
2054
|
if (revision.kind === "agentic")
|
|
1867
|
-
return inputIssues(input,
|
|
2055
|
+
return inputIssues(input, inputSchemaOf(revision.body.inputSchema));
|
|
1868
2056
|
const { validateWorkflow } = await import("@parcha/agentrun-dsl");
|
|
1869
2057
|
return workflowInputIssues(validateWorkflow, revision, input);
|
|
1870
2058
|
}
|
|
@@ -1904,7 +2092,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1904
2092
|
const handed = mcpAuthOf(mcp_auth, issues);
|
|
1905
2093
|
const auth = {};
|
|
1906
2094
|
for (const [server, headers] of Object.entries(handed ?? {})) {
|
|
1907
|
-
const row = await store
|
|
2095
|
+
const row = await getMcpServer(store, server);
|
|
1908
2096
|
if (row?.auth !== "per_run")
|
|
1909
2097
|
issues.push({ field: `mcp_auth.${server}`, reason: "not_an_option", message: row ? `The MCP server ${server} keeps its own credential (auth ${row.auth}): only a per_run server takes one from a run.` : `No MCP server ${server} is saved here.` });
|
|
1910
2098
|
else
|
|
@@ -1956,16 +2144,26 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1956
2144
|
if (issues.length)
|
|
1957
2145
|
throw invalid(issues);
|
|
1958
2146
|
const checked = checkDefinitionBody(given);
|
|
1959
|
-
const
|
|
1960
|
-
//
|
|
1961
|
-
//
|
|
1962
|
-
|
|
2147
|
+
const made = makeRevision(checked.definition, checked.skills ?? {}, checked.note);
|
|
2148
|
+
// A version's first run is its save: refused where POST /agents refuses the definition (one this host can never run),
|
|
2149
|
+
// its MCP tools pinned as a save pins them (a server down keeps the agent's current pin when this version grants nothing
|
|
2150
|
+
// new from it). A version already stored is a run of its revision, as a run of a stored agent is: no save, nothing
|
|
2151
|
+
// listed here, its pin as stored (one stored with no pin is pinned at this run, StartDeps.pinFirst). What this host
|
|
2152
|
+
// still lacks for either is the run's own refusal (prepareLaunch's runnable).
|
|
1963
2153
|
const ref = external;
|
|
2154
|
+
const mapped = await store.agents.byExternal(externalKey(ref));
|
|
2155
|
+
const stored = mapped ? await store.agents.externalRevision(mapped.id, String(ref.version)) : undefined;
|
|
2156
|
+
const current = !stored && mapped?.currentRevision ? await store.agents.revision(mapped.currentRevision) : undefined;
|
|
2157
|
+
// A version already stored keeps its revision's monid pin, not what monid lists now: its definition never changes
|
|
2158
|
+
// here, so it compares equal to the stored one (startInline), and monid's listing is not read again.
|
|
2159
|
+
const keptMonid = stored?.kind === "agentic" ? stored.body.monidPin : undefined;
|
|
2160
|
+
const revision = stored ? (keptMonid ? { ...made, body: { ...made.body, monidPin: keptMonid } } : made) : { ...made, ...(await saveable(made, current?.mcpPin)).stamp };
|
|
1964
2161
|
const inline = {
|
|
1965
2162
|
external: { source: ref.source, kind: ref.kind, id: ref.id, version: String(ref.version) },
|
|
1966
2163
|
name: checked.definition.name,
|
|
1967
2164
|
description: typeof checked.definition.description === "string" ? checked.definition.description : null,
|
|
1968
2165
|
revision,
|
|
2166
|
+
...(stored ? { stored } : {}),
|
|
1969
2167
|
};
|
|
1970
2168
|
return idempotent(req, "/runs", body, async (origin) => {
|
|
1971
2169
|
// A run the store started under this key, though no answer was kept (its server went down first): that run, as it is now.
|
|
@@ -2031,7 +2229,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2031
2229
|
}
|
|
2032
2230
|
/** A run create's body as POST /agents/{id}/runs checks it before it reads the agent: each field issue. */
|
|
2033
2231
|
function runBodyIssues(body) {
|
|
2034
|
-
const issues = unknownFields(body, ["input", "revision", "file_ids", "effort", "max_cost_usd", "cap_mode", "quote_id", "learning", "archil_disk", "repo", "hold", "hold_minutes"]);
|
|
2232
|
+
const issues = unknownFields(body, ["input", "revision", "file_ids", "effort", "max_cost_usd", "cap_mode", "quote_id", "learning", "archil_disk", "repo", "workflow_first", "hold", "hold_minutes"]);
|
|
2035
2233
|
issues.push(...holdIssues(body));
|
|
2036
2234
|
if (body.repo !== undefined && !(typeof body.repo === "string" && REPO_NAME.test(body.repo)))
|
|
2037
2235
|
issues.push({ field: "repo", reason: "wrong_type", message: "repo is a GitHub repository as owner/name, one the agent is bound to" });
|
|
@@ -2055,6 +2253,8 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2055
2253
|
issues.push({ field: "cap_mode", reason: "not_an_option", message: `cap_mode is one of ${CAP_MODES.join(", ")}` });
|
|
2056
2254
|
if (body.file_ids !== undefined && !Array.isArray(body.file_ids))
|
|
2057
2255
|
issues.push({ field: "file_ids", reason: "wrong_type", message: "file_ids is a list of file ids" });
|
|
2256
|
+
if (body.workflow_first !== undefined && typeof body.workflow_first !== "boolean")
|
|
2257
|
+
issues.push({ field: "workflow_first", reason: "wrong_type", message: "workflow_first is true or false" });
|
|
2058
2258
|
if (body.learning !== undefined && body.learning !== RUN_LEARNING_USE)
|
|
2059
2259
|
issues.push({ field: "learning", reason: "not_an_option", message: `learning is "${RUN_LEARNING_USE}" (the run starts from what its agent learned and keeps nothing), or absent (its agent's own)` });
|
|
2060
2260
|
return issues;
|
|
@@ -2653,7 +2853,20 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2653
2853
|
// The tools its current revision grants, as capabilities list them, each with its provider for this agent.
|
|
2654
2854
|
// A tool of bash's family the agent's computer gives no shell for reads unavailable (runShellOf).
|
|
2655
2855
|
const revision = entry.revision;
|
|
2656
|
-
const
|
|
2856
|
+
const tooling = revision ? await toolingOf(revision) : undefined;
|
|
2857
|
+
// An MCP tool's effect, what "allow reads" reads: as the revision's pin marks it (pinnedEffect), the marks its runs
|
|
2858
|
+
// read. A revision saved before pins were made at save holds none until its first run, which pins its saved
|
|
2859
|
+
// server's listing then (pinFirst): so until then, that listing now (mcp-servers-store.ts).
|
|
2860
|
+
const pin = revision?.mcpPin ?? undefined;
|
|
2861
|
+
const listed = !pin && tooling?.tools.some((name) => mcpToolOf(name)) ? new Map((await store.mcp.servers()).map((row) => [row.name, (row.tools ?? [])])) : undefined;
|
|
2862
|
+
const effectOf = (name) => {
|
|
2863
|
+
if (pin)
|
|
2864
|
+
return pinnedEffect(pin, name);
|
|
2865
|
+
const parsed = mcpToolOf(name);
|
|
2866
|
+
const tool = parsed && listed?.get(parsed.server)?.find((one) => one.name === parsed.tool);
|
|
2867
|
+
return tool ? toolEffect(tool.annotations) : undefined;
|
|
2868
|
+
};
|
|
2869
|
+
const tools = revision && tooling ? agentTools(env, settings.get(), tooling, caps.tools.map((tool) => tool.name), await shellOfRevision(revision), effectOf) : [];
|
|
2657
2870
|
return send(res, 200, { ...agentView(entry, linkOrigin(req), await agentExtra(entry)), tools }, { etag: etagOf(entry) });
|
|
2658
2871
|
}
|
|
2659
2872
|
case "updateDefinition": {
|
|
@@ -2675,7 +2888,13 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2675
2888
|
// The check above is a fast path; the store compares If-Match again inside the commit, so of two edits that read
|
|
2676
2889
|
// the same revision exactly one lands.
|
|
2677
2890
|
let warnings = [];
|
|
2678
|
-
const check = async (revision) =>
|
|
2891
|
+
const check = async (revision, on) => {
|
|
2892
|
+
// The pin of the revision this try builds on (commitAgent's read, a retry's newer one): a server down now keeps
|
|
2893
|
+
// it when the edit grants nothing new from it.
|
|
2894
|
+
const saved = await saveable(revision, on?.mcpPin);
|
|
2895
|
+
warnings = saved.warnings;
|
|
2896
|
+
return saved.stamp;
|
|
2897
|
+
};
|
|
2679
2898
|
const edited = await agents.commit(entry, checkDefinitionBody(contract ? { definition: body } : body, { creating: false }), { check, contract, ...(match === undefined ? {} : { ifCurrent: entry.revision?.id ?? null }) });
|
|
2680
2899
|
reconcileComputer(id);
|
|
2681
2900
|
return send(res, 200, { ...agentView(edited, linkOrigin(req), await agentExtra(edited)), warnings }, { etag: etagOf(edited) });
|
|
@@ -2827,17 +3046,50 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2827
3046
|
// The owner's answer to a tool call that waits for approval (tool-gate.ts): the first answer wins.
|
|
2828
3047
|
const run = await needRun(id);
|
|
2829
3048
|
const body = await bodyOf(req);
|
|
2830
|
-
const issues = Object.keys(body).filter((k) => k !== "decision" && k !== "note").map((k) => ({ field: k, reason: "not_allowed", message: `The body keeps no field ${k}.` }));
|
|
3049
|
+
const issues = Object.keys(body).filter((k) => k !== "decision" && k !== "note" && k !== "confirm_destructive").map((k) => ({ field: k, reason: "not_allowed", message: `The body keeps no field ${k}.` }));
|
|
3050
|
+
if (body.confirm_destructive !== undefined && body.confirm_destructive !== true)
|
|
3051
|
+
issues.push({ field: "confirm_destructive", reason: "wrong_type", message: "confirm_destructive is true when sent: the second confirm of a destructive call's allow" });
|
|
2831
3052
|
if (body.decision !== "allow" && body.decision !== "deny")
|
|
2832
3053
|
issues.push({ field: "decision", reason: body.decision === undefined ? "missing" : "not_an_option", message: "decision is allow or deny" });
|
|
2833
3054
|
if (body.note !== undefined && (typeof body.note !== "string" || body.note.length > 2000))
|
|
2834
3055
|
issues.push({ field: "note", reason: "wrong_type", message: "note is a string of at most 2000 characters" });
|
|
2835
3056
|
if (issues.length)
|
|
2836
3057
|
throw invalid(issues);
|
|
2837
|
-
await approve(store, run, decodeURIComponent(second), body.decision, typeof body.note === "string" && body.note.trim() ? body.note.trim() : undefined);
|
|
3058
|
+
await approve(store, run, decodeURIComponent(second), body.decision, typeof body.note === "string" && body.note.trim() ? body.note.trim() : undefined, body.confirm_destructive === true);
|
|
2838
3059
|
res.writeHead(204, { "cache-control": "no-store", "x-content-type-options": "nosniff" });
|
|
2839
3060
|
return void res.end();
|
|
2840
3061
|
}
|
|
3062
|
+
case "gradeRun": {
|
|
3063
|
+
const row = ID.test(id) ? await store.runs.get(id) : undefined;
|
|
3064
|
+
if (!row)
|
|
3065
|
+
throw new ApiError("not_found", `no run ${id}`);
|
|
3066
|
+
const body = await bodyOf(req);
|
|
3067
|
+
const extra = unknownFields(body, ["correct", "expected", "source", "label"]);
|
|
3068
|
+
if (extra.length)
|
|
3069
|
+
throw invalid(extra);
|
|
3070
|
+
if (typeof body.correct !== "boolean")
|
|
3071
|
+
throw invalid([{ field: "correct", reason: body.correct === undefined ? "missing" : "wrong_type", message: "correct is true or false: whether the run's answer was right" }]);
|
|
3072
|
+
if (body.expected !== undefined && !isObject(body.expected))
|
|
3073
|
+
throw invalid([{ field: "expected", reason: "wrong_type", message: "expected is an object: the fields a right answer's JSON holds" }]);
|
|
3074
|
+
if (body.source !== undefined && !GRADE_SOURCES.includes(body.source))
|
|
3075
|
+
throw invalid([{ field: "source", reason: "not_an_option", message: `source is one of ${GRADE_SOURCES.join(", ")}` }]);
|
|
3076
|
+
if (body.label !== undefined && (typeof body.label !== "string" || body.label.length > LABEL_MAX))
|
|
3077
|
+
throw invalid([{ field: "label", reason: "wrong_type", message: `label is a string of at most ${LABEL_MAX} characters: the grade's words` }]);
|
|
3078
|
+
if (!FINAL_STATES.includes(row.state))
|
|
3079
|
+
throw invalid([{ field: "run_id", reason: "not_allowed", message: "A run is graded once it has ended." }]);
|
|
3080
|
+
const m = (isObject(row.metrics) ? row.metrics : {});
|
|
3081
|
+
if (m.path === "replay")
|
|
3082
|
+
throw invalid([{ field: "run_id", reason: "not_allowed", message: "A replay run is never graded: its answer is scored against the run it replays." }]);
|
|
3083
|
+
const path = RUN_PATHS.includes(m.path) ? m.path : "agent";
|
|
3084
|
+
const grade = {
|
|
3085
|
+
run: row.id, correct: body.correct, ...(body.expected !== undefined ? { expected: body.expected } : {}), source: body.source ?? "feedback", at: new Date().toISOString(), path,
|
|
3086
|
+
...(typeof m.workflow === "string" ? { workflow: m.workflow } : {}), ...(typeof m.workflow_digest === "string" ? { digest: m.workflow_digest } : {}),
|
|
3087
|
+
};
|
|
3088
|
+
await putGrade(store.settings, row.agentId, grade);
|
|
3089
|
+
// What the grade asks of the run's learning (runner/feedback-round.ts): nothing, a revision ask, or a look-back.
|
|
3090
|
+
const feedback = await openFeedbackRound(store, grade, typeof body.label === "string" ? body.label : undefined);
|
|
3091
|
+
return send(res, 200, { ...gradeView(grade), feedback });
|
|
3092
|
+
}
|
|
2841
3093
|
case "archiveRun":
|
|
2842
3094
|
case "unarchiveRun": {
|
|
2843
3095
|
const run = await needRun(id);
|
|
@@ -2868,7 +3120,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2868
3120
|
return computerViewerLink(store, sealKey, run.id, answers);
|
|
2869
3121
|
},
|
|
2870
3122
|
computer: () => (viewed ? { kind: viewed } : computerOf(kept, env, family)),
|
|
2871
|
-
session: (kind) => sessionIn(kind, entries),
|
|
3123
|
+
session: (kind) => sessionIn(kind, entries, run.terminal),
|
|
2872
3124
|
hold: () => hold,
|
|
2873
3125
|
// A going run's browser let go while it waited for its person: the Screen tab says so, with when. One settings
|
|
2874
3126
|
// row (browser-wait-ended.ts), never the run's journal: this is read on every Screen poll.
|
|
@@ -3137,7 +3389,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3137
3389
|
// The name is checked before Composio is called: a refused name leaves nothing made there.
|
|
3138
3390
|
mcpNameOf(id);
|
|
3139
3391
|
const body = await bodyOf(req);
|
|
3140
|
-
const answer = await composioSave(body, options.composioControl ?? {}, (mcp) => mcpServers.save(id, mcp, stopping.signal), id, stopping.signal, async () => (await mcpServers.get(id)).url);
|
|
3392
|
+
const answer = await composioSave(body, options.composioControl ?? {}, (mcp, made) => mcpServers.save(id, mcp, stopping.signal, undefined, made), id, stopping.signal, async () => (await mcpServers.get(id)).url);
|
|
3141
3393
|
await refreshMcpMeta();
|
|
3142
3394
|
return send(res, 200, answer, { "cache-control": "no-store" });
|
|
3143
3395
|
}
|
|
@@ -3185,10 +3437,18 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3185
3437
|
return send(res, 200, await privateHostsRoute(mcpServers, { method: "GET" }), { "cache-control": "no-store" });
|
|
3186
3438
|
case "putMcpPrivateHosts":
|
|
3187
3439
|
return send(res, 200, await privateHostsRoute(mcpServers, { method: "PUT", body: () => bodyOf(req) }), { "cache-control": "no-store" });
|
|
3188
|
-
case "deleteMcpServer":
|
|
3189
|
-
|
|
3440
|
+
case "deleteMcpServer": {
|
|
3441
|
+
// Our row goes first, by the checked removal (a 412 sends Composio nothing), and answers what it removed: a Composio
|
|
3442
|
+
// preset server's MCP server on Composio is deleted next, as the row removed named it and with its saved key.
|
|
3443
|
+
// Composio refusing or not answering, or a key that does not open, never keeps our row: the answer says what to
|
|
3444
|
+
// remove there by hand.
|
|
3445
|
+
const { composio: made } = await mcpServers.remove(id, secretSeen);
|
|
3190
3446
|
await refreshMcpMeta();
|
|
3447
|
+
const forgotten = !made ? undefined : "unusable" in made ? composioNote(id) : await composioForget(options.composioControl ?? {}, made.key, made.id, id, stopping.signal);
|
|
3448
|
+
if (forgotten && !forgotten.removed)
|
|
3449
|
+
return send(res, 200, { deleted: true, composio: forgotten }, { "cache-control": "no-store" });
|
|
3191
3450
|
return void res.writeHead(204, { "cache-control": "no-store" }).end();
|
|
3451
|
+
}
|
|
3192
3452
|
case "getToolSettings":
|
|
3193
3453
|
return send(res, 200, withDefaults(settings.get()));
|
|
3194
3454
|
case "putToolSettings": {
|
|
@@ -3227,13 +3487,20 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3227
3487
|
const read = await agentCostOverStore(store, id, limit);
|
|
3228
3488
|
// Each workflow's name as the other learning reads show it: one that holds a secret or a sign-in's value is cut.
|
|
3229
3489
|
const shown = await learningShown(id);
|
|
3230
|
-
const cost = { ...read, runs: read.runs.map((run) => (run.workflow === null ? run : { ...run, workflow: shown.name(run.workflow) })) };
|
|
3490
|
+
const cost = { ...read, runs: read.runs.map((run) => (run.workflow === null ? run : { ...run, workflow: shown.name(run.workflow) })), workflows: read.workflows.map((one) => ({ ...one, workflow: shown.name(one.workflow) })) };
|
|
3231
3491
|
if (csv) {
|
|
3232
3492
|
res.writeHead(200, { "content-type": "text/csv; charset=utf-8", "cache-control": "no-store", "x-content-type-options": "nosniff", "content-disposition": `attachment; filename="${id}-cost-per-run.csv"` });
|
|
3233
3493
|
return void res.end(costCsv(cost.runs));
|
|
3234
3494
|
}
|
|
3235
3495
|
return send(res, 200, { agent: id, ...cost });
|
|
3236
3496
|
}
|
|
3497
|
+
case "listLearningPromotions": {
|
|
3498
|
+
await needAgent(id);
|
|
3499
|
+
// Each learned workflow's promotion records, oldest first (learn/promote.ts): its replays' numbers and decisions,
|
|
3500
|
+
// its refits, its holds. Aggregates only; every text in them cut as the other learning reads cut theirs
|
|
3501
|
+
// (promotionsShown: a reason and a refit guard's label as well as each workflow's name).
|
|
3502
|
+
return send(res, 200, { agent: id, ...promotionsShown(await promotionsOf(store.settings, id), await learningShown(id)) });
|
|
3503
|
+
}
|
|
3237
3504
|
case "createLearningBatch": {
|
|
3238
3505
|
await needAgent(id);
|
|
3239
3506
|
const made = await batches.create(id, await bodyOf(req));
|
|
@@ -3264,6 +3531,26 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3264
3531
|
});
|
|
3265
3532
|
return send(res, answer.status, answer.body, answer.headers);
|
|
3266
3533
|
}
|
|
3534
|
+
case "getLearningLoop": {
|
|
3535
|
+
await needAgent(id);
|
|
3536
|
+
// The loop's own record over the one store (store-reads/loop.ts): compile turns and guarded steps, aggregates only.
|
|
3537
|
+
// Names cut as the other learning reads cut them; a compile's error texts cut by its run's own cut as its run's
|
|
3538
|
+
// learning read cuts them (run-learning-served.ts), and left out when that run's handed values can't be read.
|
|
3539
|
+
const shown = await learningShown(id);
|
|
3540
|
+
const values = await learningValues(id);
|
|
3541
|
+
const read = await agentLoopOverStore(store, id);
|
|
3542
|
+
const compiles = await Promise.all(read.compiles.map(async (one) => {
|
|
3543
|
+
const cut = await runCutValues({ serverSecrets, signIns }, store, one.run_id).catch(() => "unreadable");
|
|
3544
|
+
const workflow = one.workflow === null ? null : shown.name(one.workflow);
|
|
3545
|
+
if (cut === "unreadable")
|
|
3546
|
+
return { ...one, workflow, from_notes: one.from_notes.map(shown.name), attempts: one.attempts.map(({ ok }) => ({ ok, errors: [] })), draft_errors: [], withheld: true };
|
|
3547
|
+
const all = [...values, ...cut.values];
|
|
3548
|
+
const said = (error) => shown.text(printable({ rule: "workflow", detail: error }, all).detail);
|
|
3549
|
+
return { ...one, workflow, from_notes: one.from_notes.map(shown.name), attempts: one.attempts.map(({ ok, errors }) => ({ ok, errors: errors.map(said) })), draft_errors: one.draft_errors.map(said), withheld: false };
|
|
3550
|
+
}));
|
|
3551
|
+
const guards = read.guards.map((one) => ({ ...one, workflow: shown.name(one.workflow), node: shown.text(one.node) }));
|
|
3552
|
+
return send(res, 200, { agent: id, compiles, guards });
|
|
3553
|
+
}
|
|
3267
3554
|
case "listLearningNotes":
|
|
3268
3555
|
case "listLearningLog":
|
|
3269
3556
|
await needAgent(id);
|
|
@@ -3355,26 +3642,32 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3355
3642
|
}
|
|
3356
3643
|
case "listTemplates": {
|
|
3357
3644
|
// Each package's computer list read against this server now: what an apply here would pick (pickComputer).
|
|
3358
|
-
const
|
|
3359
|
-
const pickView = (
|
|
3360
|
-
|
|
3361
|
-
if (!pick)
|
|
3362
|
-
return null;
|
|
3363
|
-
if ("refused" in pick)
|
|
3364
|
-
return { entry: null, computer: null, shell: null, dropped: [], note: pick.refused };
|
|
3365
|
-
return { entry: pick.entry, computer: pick.computer, shell: pick.shell, dropped: pick.dropped, note: pick.note };
|
|
3366
|
-
};
|
|
3367
|
-
return send(res, 200, { templates: templates.map((pkg) => ({ ...packageView(pkg), computer_here: pickView(pkg) })) });
|
|
3645
|
+
const listed = registry.list();
|
|
3646
|
+
const pickView = await computerHere(listed);
|
|
3647
|
+
return send(res, 200, { templates: listed.map((pkg) => ({ ...packageView(pkg), computer_here: pickView(pkg) })) });
|
|
3368
3648
|
}
|
|
3649
|
+
case "importTemplate": {
|
|
3650
|
+
// Read from GitHub and checked; a dry run answers it (200), else it is stored and served (201). The answer shows the
|
|
3651
|
+
// package whole, its instructions and every skill file, for a person to read before they apply it.
|
|
3652
|
+
const body = await bodyOf(req);
|
|
3653
|
+
const done = new AbortController();
|
|
3654
|
+
res.once("close", () => done.abort());
|
|
3655
|
+
const imported = await importTemplate(importDeps, body, done.signal);
|
|
3656
|
+
const pickView = await computerHere([imported.pkg]);
|
|
3657
|
+
return send(res, imported.status, { template: { ...packageView(imported.pkg), computer_here: pickView(imported.pkg) }, ...(({ instructions, skill_files }) => ({ instructions, skill_files }))(packageDetail(imported.pkg)), publisher_trusted: imported.trusted, stored: imported.status === 201, replaced: imported.replaced, console_url: imported.status === 201 ? templateLink(linkOrigin(req), imported.pkg.id) : templateInstallLink(linkOrigin(req), imported.pkg.origin?.source ?? imported.pkg.id) });
|
|
3658
|
+
}
|
|
3659
|
+
case "deleteTemplate":
|
|
3660
|
+
await deleteTemplate(importDeps, id);
|
|
3661
|
+
return void res.writeHead(204, { "cache-control": "no-store" }).end();
|
|
3369
3662
|
case "applyTemplate": {
|
|
3370
|
-
const pkg =
|
|
3663
|
+
const pkg = registry.get(id);
|
|
3371
3664
|
if (!pkg)
|
|
3372
3665
|
throw new ApiError("not_found", `no template ${id}: GET /v2/templates lists them`);
|
|
3373
3666
|
const body = await bodyOf(req);
|
|
3374
3667
|
// The Idempotency-Key's record keeps the agent and triggers, so a retry under the key gets the same apply; it never
|
|
3375
3668
|
// keeps a webhook trigger's secret (below).
|
|
3376
3669
|
let minted = new Map();
|
|
3377
|
-
const answer = await idempotent(req, `/templates/${pkg.
|
|
3670
|
+
const answer = await idempotent(req, `/templates/${encodeURIComponent(pkg.id)}/apply`, body, async () => {
|
|
3378
3671
|
const made = await applyTemplate(pkg, body);
|
|
3379
3672
|
minted = made.minted;
|
|
3380
3673
|
return { status: 201, body: made.applied, headers: { location: `/v2/agents/${made.applied.agent_id}` } };
|