@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/templates.js
CHANGED
|
@@ -9,37 +9,54 @@ import { basename, join } from "node:path";
|
|
|
9
9
|
import { fileURLToPath } from "node:url";
|
|
10
10
|
import { parseDocument } from "yaml";
|
|
11
11
|
import { invalid } from "./errors.js";
|
|
12
|
+
// Where a package's MCP tools come from (a Composio toolkit, GitHub's MCP server, or any other server by its address): a
|
|
13
|
+
// saved MCP server records one too, and apply maps each need to a server whose record matches.
|
|
14
|
+
import { MCP_SOURCES } from "./mcp-sources.js";
|
|
12
15
|
import { HARNESSES } from "./harness.js";
|
|
13
16
|
import { TOOL_KEY_ROWS } from "./key-words.js";
|
|
14
|
-
import { MCP_SERVER_NAME } from "./mcp-probe.js";
|
|
15
17
|
import { chooseModel, harnessRuns, hostModel, MODEL_KEYS, THINKING_LEVELS } from "./model.js";
|
|
16
|
-
import {
|
|
18
|
+
import { isPinKeys } from "./tool-gate.js";
|
|
19
|
+
import { formatToolName, isMcpName, isMonidName, MCP_SERVER_NAME, MCP_TOOL_NAME, mcpToolName, MONID_NAME_WORDS, parseToolName } from "./tool-names.js";
|
|
17
20
|
import { pinIssues, sortedPin } from "./tool-plane.js";
|
|
18
21
|
import { BASH_POLICIES } from "./bash-read-only.js";
|
|
19
22
|
import { BOUND_TOOLS, toolOf } from "./tools.js";
|
|
20
23
|
import { TRIGGER_ADAPTERS } from "./trigger-adapters.js";
|
|
21
24
|
import { triggerBodyIssues } from "./triggers.js";
|
|
22
|
-
import {
|
|
25
|
+
import { definitionBodyIssues, inputIssues, inputSchemaOf, isObject, MODEL_REF, MODEL_TIER_NAMES, unknownFields } from "./validate.js";
|
|
26
|
+
import { schemaCheck } from "./answer-json.js";
|
|
23
27
|
import { APPROVALS } from "./approvals.js";
|
|
24
28
|
export const TEMPLATES_DIR = fileURLToPath(new URL("../templates/", import.meta.url));
|
|
25
29
|
export const MANIFEST = "agent.md";
|
|
26
30
|
/** A package's model tier, mapped to the server's own (model.ts Tier: AGENT_MODEL_FAST, AGENT_MODEL, AGENT_MODEL_STRONG). */
|
|
27
31
|
export const MODEL_TIERS = { fast: "fast", balanced: "default", strong: "strong" };
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
*
|
|
31
|
-
export const
|
|
32
|
-
export const GRADER_TYPES = ["llm", "regex", "tool_used", "file_exists", "schema"];
|
|
32
|
+
const SCALAR_TYPES = ["string", "number", "integer", "boolean"];
|
|
33
|
+
/** A case's grader types. The answer's output schema is no grader's: every graded run of a package with `output` is held
|
|
34
|
+
* to it by the server's own verdict (template-eval.ts outputVerdict). */
|
|
35
|
+
export const GRADER_TYPES = ["llm", "regex", "tool_used", "file_exists"];
|
|
33
36
|
/** The entries of a package's `computer` preference list: `shell`, a computer that gives the agent a shell here (bash);
|
|
34
37
|
* `none`, no shell, the file tools alone. Apply takes the first this server meets now (pickComputer). */
|
|
35
38
|
export const COMPUTER_ENTRIES = ["shell", "none"];
|
|
36
|
-
const FIELDS = ["name", "display_name", "version", "description", "license", "author", "repository", "harness", "model", "effort", "tools", "mcp", "tool_policy", "computer", "checkout", "parameters", "secrets", "budget", "learning", "approvals", "triggers", "output"
|
|
39
|
+
const FIELDS = ["name", "display_name", "version", "description", "license", "author", "repository", "category", "tags", "harness", "model", "effort", "tools", "mcp", "tool_policy", "computer", "checkout", "parameters", "inputs", "secrets", "budget", "learning", "approvals", "triggers", "output"];
|
|
40
|
+
/** What a package is for, shown on a marketplace page and the console's list: display only, never applied. */
|
|
41
|
+
export const CATEGORIES = ["engineering", "security", "sales", "marketing", "research", "finance", "operations", "compliance", "personal"];
|
|
42
|
+
const TAG = /^[a-z0-9-]{1,32}$/;
|
|
43
|
+
const MAX_TAGS = 8;
|
|
44
|
+
/** An MCP need's reason: one line, shown on the apply screen beside its tools. */
|
|
45
|
+
const MAX_REASON = 280;
|
|
46
|
+
/** An input's or a parameter's types: a scalar, or a list of one. */
|
|
47
|
+
export const INPUT_TYPES = [...SCALAR_TYPES, "array"];
|
|
48
|
+
/** What a string input's or parameter's value is: a form asks for it as such, and the server checks the JSON Schema
|
|
49
|
+
* formats it knows. cron and timezone are for the form alone (a schedule picker, a zone choice); where a parameter fills
|
|
50
|
+
* a schedule, the schedule's own check reads the value at apply. */
|
|
51
|
+
export const INPUT_FORMATS = ["uri", "email", "hostname", "date", "date-time", "uuid", "cron", "timezone"];
|
|
52
|
+
/** An input's or a parameter's keys: what a form and a JSON Schema say of one field. */
|
|
53
|
+
const INPUT_KEYS = ["type", "required", "pattern", "enum", "format", "default", "description", "title", "examples", "minimum", "maximum", "minLength", "maxLength", "items"];
|
|
54
|
+
/** A list input's `items`: a scalar's keys alone. */
|
|
55
|
+
const ITEM_KEYS = ["type", "pattern", "enum", "format", "minimum", "maximum", "minLength", "maxLength"];
|
|
37
56
|
const NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
38
57
|
const PARAMETER = /^[a-z][a-z0-9_]{0,63}$/;
|
|
39
58
|
/** The keys a package may need: those Settings saves (a tool's or a model provider's), each one a run is handed. */
|
|
40
59
|
export const PACKAGE_SECRETS = [...new Set([...TOOL_KEY_ROWS.flatMap((row) => row.fields), ...MODEL_KEYS.map((row) => row.field)])];
|
|
41
|
-
/** An MCP tool's name: one tool, never the server's wildcard `*`. */
|
|
42
|
-
const MCP_TOOL = /^[A-Za-z0-9_.-]{1,128}$/;
|
|
43
60
|
/** A package's bounds: each file, all its files together (POST /agents' own body limit), and how many it holds. */
|
|
44
61
|
export const MAX_FILE_BYTES = 256 << 10;
|
|
45
62
|
export const MAX_PACKAGE_BYTES = 1 << 20;
|
|
@@ -49,23 +66,22 @@ export const MAX_PACKAGE_FILES = 256;
|
|
|
49
66
|
export const MAX_EVAL_FILE_BYTES = 32 << 20;
|
|
50
67
|
/** A parameter's sample, of its type, for the check that compiles a package before any apply. */
|
|
51
68
|
const SAMPLES = { string: "x", number: 1, integer: 1, boolean: true };
|
|
69
|
+
/** A string of each format a parameter (or a list parameter's items) may say, for that check. */
|
|
70
|
+
const FORMAT_SAMPLES = { uri: "https://example.com", email: "someone@example.com", hostname: "example.com", date: "2026-01-01", "date-time": "2026-01-01T00:00:00Z", uuid: "00000000-0000-4000-8000-000000000000", cron: "0 9 * * *", timezone: "UTC" };
|
|
71
|
+
/** A scalar's sample: its first choice, else one of its format, else one of its type. */
|
|
72
|
+
const sampleOf = (spec) => (Array.isArray(spec.enum) ? spec.enum[0] : FORMAT_SAMPLES[spec.format] ?? SAMPLES[spec.type]);
|
|
52
73
|
/** An agent id in the shape an apply gives a trigger's target, for that check. */
|
|
53
74
|
const SAMPLE_AGENT = `agt_${"0".repeat(24)}`;
|
|
54
75
|
// semver.org's own expression, SemVer 2.0.0.
|
|
55
76
|
const SEMVER = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
|
|
56
77
|
const PLACEHOLDER = /\$\{parameters\.([^}]*)\}/g;
|
|
78
|
+
/** Text that is one placeholder alone: it takes the parameter's value with its type (a pin's, a trigger's input's). */
|
|
79
|
+
const WHOLE = /^\$\{parameters\.([^}]*)\}$/;
|
|
57
80
|
const FRONT = /^---\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/;
|
|
58
|
-
/** Whether `value` is of the
|
|
81
|
+
/** Whether `value` is of the scalar type `type`. */
|
|
59
82
|
const ofType = (type, value) => (type === "integer" ? Number.isSafeInteger(value) : type === "number" ? typeof value === "number" && Number.isFinite(value) : typeof value === type);
|
|
60
|
-
/**
|
|
61
|
-
const
|
|
62
|
-
try {
|
|
63
|
-
return new RegExp(pattern, "u").test(text);
|
|
64
|
-
}
|
|
65
|
-
catch {
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
};
|
|
83
|
+
/** A compiled field schema's (fieldsSchema's) properties, by name. */
|
|
84
|
+
export const fieldsOf = (schema) => schema.properties;
|
|
69
85
|
/** A schedule's fields a parameter may fill: its time, read by the server as the schedule, and checked at apply. */
|
|
70
86
|
const SCHEDULE_FIELDS = ["cron", "timezone"];
|
|
71
87
|
/** A package that does not check: every problem, each naming its file. */
|
|
@@ -78,7 +94,10 @@ export class PackageError extends Error {
|
|
|
78
94
|
this.problems = problems;
|
|
79
95
|
}
|
|
80
96
|
}
|
|
81
|
-
/**
|
|
97
|
+
/** The source kinds whose accept rules a parameter may fill: a github trigger's, and a webhook trigger's (a provider that
|
|
98
|
+
* sends every trigger of a project to one URL, as Composio does, is filtered to the owner's own repository by them). */
|
|
99
|
+
const FILTERED_KINDS = ["github", "webhook"];
|
|
100
|
+
/** A github or webhook source split at its where conditions' `in` values, the one place a parameter may fill it: `ins`, each
|
|
82
101
|
* condition's list, and `rest`, the source without them. */
|
|
83
102
|
function whereIns(source) {
|
|
84
103
|
const ins = [];
|
|
@@ -107,19 +126,49 @@ const GITHUB_EVENT_WORDS = { pull_request: "pull request", pull_request_review:
|
|
|
107
126
|
export const githubTriggerUnconnected = (packageName, source) => `Connect GitHub in Settings, then apply again so it runs by itself: ${githubTriggerWords(packageName, source)}`;
|
|
108
127
|
/** Every string in `value`, deep. */
|
|
109
128
|
const strings = (value) => (typeof value === "string" ? [value] : Array.isArray(value) ? value.flatMap(strings) : isObject(value) ? Object.values(value).flatMap(strings) : []);
|
|
110
|
-
/**
|
|
111
|
-
|
|
112
|
-
|
|
129
|
+
/** The value given for the parameter `name` (its own: never an inherited name such as constructor), else undefined. */
|
|
130
|
+
const givenOf = (given, name) => (Object.hasOwn(given, name) ? given[name] ?? undefined : undefined);
|
|
131
|
+
/** Whether a pin's parameter was given no value it can pin: none, "", or an empty list. */
|
|
132
|
+
const unset = (value) => value === undefined || value === "" || (Array.isArray(value) && !value.length);
|
|
133
|
+
/** A parameter's value as text: a list's items joined by ", " (an empty one, ""), nothing as "". */
|
|
134
|
+
const asText = (value) => (value === undefined ? "" : Array.isArray(value) ? value.map(asText).join(", ") : String(value));
|
|
135
|
+
/** `value` with each `${parameters.x}` in its strings replaced by the value given for x as text (asText). */
|
|
136
|
+
const filled = (value, given) => typeof value === "string" ? value.replace(PLACEHOLDER, (_, name) => asText(givenOf(given, name)))
|
|
113
137
|
: Array.isArray(value) ? value.map((item) => filled(item, given))
|
|
114
138
|
: isObject(value) ? Object.fromEntries(Object.entries(value).map(([key, item]) => [key, filled(item, given)]))
|
|
115
139
|
: value;
|
|
140
|
+
/** Text filled from `given`, the one rule a trigger's input and a pin share: text that is one placeholder alone takes the
|
|
141
|
+
* parameter's value with its type (a list stays a list, an integer an integer), undefined when it was given none; other
|
|
142
|
+
* text is filled as text. Each caller keeps its own rule for a value given none. */
|
|
143
|
+
const typedFilled = (text, given) => {
|
|
144
|
+
const whole = WHOLE.exec(text);
|
|
145
|
+
return whole ? givenOf(given, whole[1]) : filled(text, given);
|
|
146
|
+
};
|
|
147
|
+
/** A trigger's target.input filled (typedFilled): a whole placeholder given no value is dropped, so the input schema
|
|
148
|
+
* sees the field absent. */
|
|
149
|
+
const inputFilled = (value, given) => {
|
|
150
|
+
if (typeof value === "string")
|
|
151
|
+
return typedFilled(value, given);
|
|
152
|
+
if (Array.isArray(value))
|
|
153
|
+
return value.map((item) => inputFilled(item, given)).filter((item) => item !== undefined);
|
|
154
|
+
if (isObject(value))
|
|
155
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, inputFilled(item, given)]).filter(([, item]) => item !== undefined));
|
|
156
|
+
return value;
|
|
157
|
+
};
|
|
158
|
+
/** A trigger filled from the apply's parameters: its target.input typed (inputFilled), the rest as text. */
|
|
159
|
+
const triggerFilled = (trigger, given) => {
|
|
160
|
+
const out = filled(trigger, given);
|
|
161
|
+
if (isObject(trigger.target) && trigger.target.input !== undefined)
|
|
162
|
+
out.target = { ...out.target, input: inputFilled(trigger.target.input, given) };
|
|
163
|
+
return out;
|
|
164
|
+
};
|
|
116
165
|
/** An mcp entry's `pin` read: by tool, each one of the entry's `tools`, its arguments checked by the one rule every pin
|
|
117
166
|
* is (tool-plane.ts pinIssues, on the tool's gate name), text in it may hold `${parameters.<name>}` (checked with the
|
|
118
167
|
* other placeholders). Each problem is told through `bad`; a tool whose pin reads is kept. */
|
|
119
168
|
function pinOf(pin, server, tools, at, bad) {
|
|
120
169
|
const out = {};
|
|
121
170
|
if (!isObject(pin))
|
|
122
|
-
return bad(`${at} is {<tool>: {<argument>: <value or \${parameters.<name>},
|
|
171
|
+
return bad(`${at} is {<tool>: {<argument>: <value or \${parameters.<name>}, a list of them, or {keys: [<key or \${parameters.<name>}>]}>}}, by the entry's tools`), out;
|
|
123
172
|
for (const [tool, args] of Object.entries(pin)) {
|
|
124
173
|
if (!tools.includes(tool)) {
|
|
125
174
|
bad(`${at}.${tool}: ${tool} is not one of this entry's tools (${tools.join(", ")}): a pin fixes the arguments of a tool the package lists`);
|
|
@@ -133,36 +182,213 @@ function pinOf(pin, server, tools, at, bad) {
|
|
|
133
182
|
}
|
|
134
183
|
return out;
|
|
135
184
|
}
|
|
136
|
-
/** A pin's scalar filled from the apply's `given` parameters:
|
|
137
|
-
*
|
|
138
|
-
*
|
|
185
|
+
/** A pin's scalar filled from the apply's `given` parameters (typedFilled: an integer pins an integer), a list's items
|
|
186
|
+
* as text. `empty`: the parameters its placeholders name that were given no value (absent, or ""), so the pin cannot
|
|
187
|
+
* hold what the owner meant. */
|
|
139
188
|
function scalarFilled(value, given) {
|
|
140
189
|
if (typeof value !== "string")
|
|
141
190
|
return { value, empty: [] };
|
|
142
|
-
const
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
if (whole && !empty.length) {
|
|
146
|
-
const one = given[whole[1]];
|
|
147
|
-
if (typeof one === "string" || typeof one === "number" || typeof one === "boolean")
|
|
148
|
-
return { value: one, empty };
|
|
149
|
-
}
|
|
150
|
-
return { value: filled(value, given), empty };
|
|
191
|
+
const empty = [...value.matchAll(PLACEHOLDER)].map((match) => match[1]).filter((name) => unset(givenOf(given, name)));
|
|
192
|
+
const one = typedFilled(value, given);
|
|
193
|
+
return { value: !empty.length && (typeof one === "string" || typeof one === "number" || typeof one === "boolean") ? one : filled(value, given), empty };
|
|
151
194
|
}
|
|
152
|
-
/** A pin's
|
|
195
|
+
/** A keys pin's keys filled as text (scalarFilled), in their order; a key that is one placeholder alone of a list
|
|
196
|
+
* parameter adds each of its items: any of the fields the owner named. */
|
|
197
|
+
function keysFilled(keys, given) {
|
|
198
|
+
const each = keys.map((key) => {
|
|
199
|
+
const whole = WHOLE.exec(key);
|
|
200
|
+
const list = whole ? givenOf(given, whole[1]) : undefined;
|
|
201
|
+
if (Array.isArray(list) && list.length)
|
|
202
|
+
return { value: list.map(asText), empty: [] };
|
|
203
|
+
const one = scalarFilled(key, given);
|
|
204
|
+
return { value: [asText(one.value)], empty: one.empty };
|
|
205
|
+
});
|
|
206
|
+
return { value: { keys: each.flatMap((one) => one.value) }, empty: each.flatMap((one) => one.empty) };
|
|
207
|
+
}
|
|
208
|
+
/** A pin's value filled (scalarFilled), each of a one-of list's in its order, a keys pin's keys (keysFilled). One
|
|
209
|
+
* placeholder alone of a list parameter pins the list as a one-of: any of the values the owner gave. */
|
|
153
210
|
function pinFilled(value, given) {
|
|
211
|
+
if (isPinKeys(value))
|
|
212
|
+
return keysFilled(value.keys, given);
|
|
213
|
+
const list = typeof value === "string" ? typedFilled(value, given) : undefined;
|
|
214
|
+
if (Array.isArray(list) && list.length)
|
|
215
|
+
return { value: list, empty: [] };
|
|
154
216
|
if (!Array.isArray(value))
|
|
155
217
|
return scalarFilled(value, given);
|
|
156
218
|
const each = value.map((one) => scalarFilled(one, given));
|
|
157
219
|
return { value: each.map((one) => one.value), empty: each.flatMap((one) => one.empty) };
|
|
158
220
|
}
|
|
159
|
-
/**
|
|
160
|
-
export function
|
|
221
|
+
/** A package's folder on disk: each entry as lstat sees it, so a link is an entry of its own kind, never followed. */
|
|
222
|
+
export function folderFiles(dir) {
|
|
223
|
+
return {
|
|
224
|
+
name: basename(dir),
|
|
225
|
+
where: dir,
|
|
226
|
+
entries: (sub) => readdirSync(join(dir, sub), { withFileTypes: true }),
|
|
227
|
+
kind: (path) => {
|
|
228
|
+
const stat = lstatSync(join(dir, path), { throwIfNoEntry: false });
|
|
229
|
+
return stat?.isDirectory() ? "dir" : stat?.isFile() ? "file" : stat ? "other" : undefined;
|
|
230
|
+
},
|
|
231
|
+
size: (path) => lstatSync(join(dir, path)).size,
|
|
232
|
+
text: (path) => readFileSync(join(dir, path), "utf8"),
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
/** A package held in memory, by path (template-source.ts keeps regular files alone): its folders are those its files'
|
|
236
|
+
* paths name. */
|
|
237
|
+
export function memoryFiles(name, where, files) {
|
|
238
|
+
const kind = (path) => (files.has(path) ? "file" : path === "" || [...files.keys()].some((one) => one.startsWith(`${path}/`)) ? "dir" : undefined);
|
|
239
|
+
return {
|
|
240
|
+
name,
|
|
241
|
+
where,
|
|
242
|
+
entries: (sub) => {
|
|
243
|
+
const prefix = sub ? `${sub}/` : "";
|
|
244
|
+
const names = new Set([...files.keys()].filter((path) => path.startsWith(prefix)).map((path) => path.slice(prefix.length).split("/")[0]));
|
|
245
|
+
return [...names].map((one) => {
|
|
246
|
+
const at = `${prefix}${one}`;
|
|
247
|
+
return { name: one, isDirectory: () => kind(at) === "dir", isFile: () => kind(at) === "file" };
|
|
248
|
+
});
|
|
249
|
+
},
|
|
250
|
+
kind,
|
|
251
|
+
size: (path) => files.get(path)?.length ?? 0,
|
|
252
|
+
text: (path) => files.get(path)?.toString("utf8") ?? "",
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
/** A scalar input's (or a list's item's) JSON Schema from its manifest keys, each checked by `bad` (said at `at`):
|
|
256
|
+
* pattern, format and lengths for a string, bounds for a number, an enum of distinct values of its type. */
|
|
257
|
+
function scalarSchema(type, f, at, bad) {
|
|
258
|
+
const out = { type };
|
|
259
|
+
const text = type === "string";
|
|
260
|
+
const numeric = type === "number" || type === "integer";
|
|
261
|
+
if (f.pattern !== undefined) {
|
|
262
|
+
if (!text || typeof f.pattern !== "string")
|
|
263
|
+
bad(`${at}.pattern is a regular expression, on a string`);
|
|
264
|
+
else {
|
|
265
|
+
try {
|
|
266
|
+
new RegExp(f.pattern, "u");
|
|
267
|
+
out.pattern = f.pattern;
|
|
268
|
+
}
|
|
269
|
+
catch {
|
|
270
|
+
bad(`${at}.pattern is not a regular expression`);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
if (f.format !== undefined) {
|
|
275
|
+
if (!text || !INPUT_FORMATS.includes(f.format))
|
|
276
|
+
bad(`${at}.format is one of ${INPUT_FORMATS.join(", ")}, on a string`);
|
|
277
|
+
else
|
|
278
|
+
out.format = f.format;
|
|
279
|
+
}
|
|
280
|
+
for (const key of ["minLength", "maxLength"]) {
|
|
281
|
+
if (f[key] === undefined)
|
|
282
|
+
continue;
|
|
283
|
+
if (!text || !(Number.isSafeInteger(f[key]) && f[key] >= 0))
|
|
284
|
+
bad(`${at}.${key} is a whole number of 0 or more, on a string`);
|
|
285
|
+
else
|
|
286
|
+
out[key] = f[key];
|
|
287
|
+
}
|
|
288
|
+
for (const key of ["minimum", "maximum"]) {
|
|
289
|
+
if (f[key] === undefined)
|
|
290
|
+
continue;
|
|
291
|
+
if (!numeric || !(typeof f[key] === "number" && Number.isFinite(f[key])))
|
|
292
|
+
bad(`${at}.${key} is a number, on a number or an integer`);
|
|
293
|
+
else
|
|
294
|
+
out[key] = f[key];
|
|
295
|
+
}
|
|
296
|
+
if (f.enum !== undefined) {
|
|
297
|
+
if (Array.isArray(f.enum) && f.enum.length > 0 && f.enum.every((one) => ofType(type, one)) && new Set(f.enum).size === f.enum.length)
|
|
298
|
+
out.enum = f.enum;
|
|
299
|
+
else
|
|
300
|
+
bad(`${at}.enum is a list of one or more distinct ${type} values`);
|
|
301
|
+
}
|
|
302
|
+
return out;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* A package's `inputs` (each run's typed input, the agent's input_schema) or `parameters` (the setup an apply takes),
|
|
306
|
+
* compiled: a closed object schema of each field by its machine name, required unless it says `required: false`. The
|
|
307
|
+
* vocabulary: type, required, title, description, examples, default, enum, pattern, format, minimum/maximum,
|
|
308
|
+
* minLength/maxLength, and `type: array` of a scalar (`items`); nothing else. A default (on a field that is not
|
|
309
|
+
* required) and each example meet their own field. An input named `content` is the run's message: a string. Undefined
|
|
310
|
+
* when the package names none.
|
|
311
|
+
*/
|
|
312
|
+
function fieldsSchema(value, of, bad) {
|
|
313
|
+
if (value === undefined)
|
|
314
|
+
return undefined;
|
|
315
|
+
if (!isObject(value) || !Object.keys(value).length)
|
|
316
|
+
return bad(`${of} is a mapping of each field, by its name`), undefined;
|
|
317
|
+
const properties = {};
|
|
318
|
+
const required = [];
|
|
319
|
+
for (const [key, f] of Object.entries(value)) {
|
|
320
|
+
const at = `${of}.${key}`;
|
|
321
|
+
if (!PARAMETER.test(key)) {
|
|
322
|
+
bad(`${at}: a name is lowercase letters, digits and _, starting with a letter, at most 64`);
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
if (!isObject(f) || !INPUT_TYPES.includes(f.type)) {
|
|
326
|
+
bad(`${at} is {type: ${INPUT_TYPES.join(" | ")}, required?, title?, description?, examples?, default?, enum?, pattern?, format?, minimum?, maximum?, minLength?, maxLength?, items? (an array's scalar)}`);
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
329
|
+
for (const issue of unknownFields(f, INPUT_KEYS))
|
|
330
|
+
bad(`${at} has no field ${issue.field}: the fields are ${INPUT_KEYS.join(", ")}`);
|
|
331
|
+
if (of === "inputs" && key === "content" && f.type !== "string")
|
|
332
|
+
bad(`${at} is a string: content is the run's message`);
|
|
333
|
+
if (f.required !== undefined && typeof f.required !== "boolean")
|
|
334
|
+
bad(`${at}.required is true or false`);
|
|
335
|
+
for (const word of ["title", "description"])
|
|
336
|
+
if (f[word] !== undefined && !(typeof f[word] === "string" && f[word].trim()))
|
|
337
|
+
bad(`${at}.${word} is text`);
|
|
338
|
+
let schema;
|
|
339
|
+
if (f.type === "array") {
|
|
340
|
+
const items = f.items;
|
|
341
|
+
for (const word of ["pattern", "format", "enum", "minimum", "maximum", "minLength", "maxLength"])
|
|
342
|
+
if (f[word] !== undefined)
|
|
343
|
+
bad(`${at}.${word} goes on its items: a list's keys are type, items and the words`);
|
|
344
|
+
if (!isObject(items) || !SCALAR_TYPES.includes(items.type) || unknownFields(items, ITEM_KEYS).length) {
|
|
345
|
+
bad(`${at}.items is {type: ${SCALAR_TYPES.join(" | ")}} and that scalar's keys: a list is a list of a scalar`);
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
schema = { type: "array", items: scalarSchema(items.type, items, `${at}.items`, bad) };
|
|
349
|
+
}
|
|
350
|
+
else {
|
|
351
|
+
if (f.items !== undefined)
|
|
352
|
+
bad(`${at}.items is for type: array`);
|
|
353
|
+
schema = scalarSchema(f.type, f, at, bad);
|
|
354
|
+
}
|
|
355
|
+
if (typeof f.title === "string")
|
|
356
|
+
schema.title = f.title;
|
|
357
|
+
if (typeof f.description === "string")
|
|
358
|
+
schema.description = f.description;
|
|
359
|
+
// A default and each example meet the field they are of, as the server checks a value given for it.
|
|
360
|
+
const compiled = schemaCheck(schema);
|
|
361
|
+
const meets = (one) => !("why" in compiled) && !compiled.check(one).length;
|
|
362
|
+
if (f.examples !== undefined) {
|
|
363
|
+
if (Array.isArray(f.examples) && f.examples.length && f.examples.every(meets))
|
|
364
|
+
schema.examples = f.examples;
|
|
365
|
+
else
|
|
366
|
+
bad(`${at}.examples is a list of one or more values it takes`);
|
|
367
|
+
}
|
|
368
|
+
if (f.default !== undefined) {
|
|
369
|
+
if (f.required !== false)
|
|
370
|
+
bad(`${at} is required and has a default: a default is for one that may be left out (required: false)`);
|
|
371
|
+
else if (!meets(f.default))
|
|
372
|
+
bad(`${at}.default is not a value it takes`);
|
|
373
|
+
else
|
|
374
|
+
schema.default = f.default;
|
|
375
|
+
}
|
|
376
|
+
properties[key] = schema;
|
|
377
|
+
if (f.required !== false)
|
|
378
|
+
required.push(key);
|
|
379
|
+
}
|
|
380
|
+
return { type: "object", additionalProperties: false, ...(required.length ? { required } : {}), properties };
|
|
381
|
+
}
|
|
382
|
+
/** Reads the package at `from` (its folder, or its files: PackageFiles) checked whole: a valid package, or PackageError
|
|
383
|
+
* with every problem found. */
|
|
384
|
+
export function readPackage(from) {
|
|
385
|
+
const src = typeof from === "string" ? folderFiles(from) : from;
|
|
386
|
+
const dir = src.where;
|
|
161
387
|
const problems = [];
|
|
162
388
|
const bad = (where, message) => void problems.push(`${where}: ${message}`);
|
|
163
389
|
/** The regular files under `sub`, by path from it with forward slashes; a link or any other kind of entry is a
|
|
164
390
|
* problem (a package is read from disk, and a link would carry a file from outside it into an agent). */
|
|
165
|
-
const files = (sub) =>
|
|
391
|
+
const files = (sub) => src.entries(sub).sort((a, b) => (a.name < b.name ? -1 : 1)).flatMap((entry) => {
|
|
166
392
|
const path = sub ? `${sub}/${entry.name}` : entry.name;
|
|
167
393
|
if (entry.isDirectory())
|
|
168
394
|
return files(path);
|
|
@@ -170,11 +396,8 @@ export function readPackage(dir) {
|
|
|
170
396
|
return bad(path, "is not a regular file or a folder (links are refused)"), [];
|
|
171
397
|
return [path];
|
|
172
398
|
});
|
|
173
|
-
const kind = (path) =>
|
|
174
|
-
|
|
175
|
-
return stat?.isDirectory() ? "dir" : stat?.isFile() ? "file" : stat ? "other" : undefined;
|
|
176
|
-
};
|
|
177
|
-
const text = (path) => readFileSync(join(dir, path), "utf8");
|
|
399
|
+
const kind = (path) => src.kind(path);
|
|
400
|
+
const text = (path) => src.text(path);
|
|
178
401
|
/** A file's YAML front matter and body. */
|
|
179
402
|
const front = (path, required = true) => {
|
|
180
403
|
const content = text(path);
|
|
@@ -209,26 +432,26 @@ export function readPackage(dir) {
|
|
|
209
432
|
};
|
|
210
433
|
/** `path` is a regular file inside the package. */
|
|
211
434
|
const inside = (path) => typeof path === "string" && !path.startsWith("/") && !path.split("/").some((part) => part === ".." || part === "." || part === "") && kind(path) === "file";
|
|
212
|
-
const name =
|
|
213
|
-
if (
|
|
435
|
+
const name = src.name;
|
|
436
|
+
if (src.kind("") !== "dir")
|
|
214
437
|
throw new PackageError(dir, ["it is not a folder: a package is one"]);
|
|
215
438
|
if (kind(MANIFEST) !== "file")
|
|
216
439
|
throw new PackageError(dir, [`${MANIFEST}: missing: a package is a folder with agent.md (its manifest in the front matter, the agent's instructions in the body)`]);
|
|
217
|
-
for (const entry of
|
|
440
|
+
for (const entry of src.entries("")) {
|
|
218
441
|
if (entry.isDirectory() && !["skills", "rules", "evals"].includes(entry.name))
|
|
219
442
|
bad(`${entry.name}/`, "a package's folders are skills/, rules/ and evals/");
|
|
220
443
|
}
|
|
221
444
|
// Bounded before anything is read: a file, the files together, and how many there are.
|
|
222
445
|
// The agent's files' bytes (evals/ is the package's own test data, never part of an agent) under POST /v2/agents'
|
|
223
446
|
// limits, an eval's file under MAX_EVAL_FILE_BYTES alone; every file, evals/ too, counts toward MAX_PACKAGE_FILES. A
|
|
224
|
-
// file under evals/ an agent is given all the same (the answer's schema, which
|
|
225
|
-
// agent's limits: checked once the manifest names it, before it is read.
|
|
447
|
+
// file under evals/ an agent is given all the same (the answer's schema, which becomes its output_schema and is in its
|
|
448
|
+
// instructions) keeps the agent's limits: checked once the manifest names it, before it is read.
|
|
226
449
|
const listed = files("");
|
|
227
450
|
const all = listed.filter((path) => !path.startsWith("evals/"));
|
|
228
|
-
const sizes = all.map((path) => [path,
|
|
451
|
+
const sizes = all.map((path) => [path, src.size(path)]);
|
|
229
452
|
const agentBytes = sizes.reduce((sum, [, size]) => sum + size, 0);
|
|
230
453
|
const limits = [
|
|
231
|
-
...listed.filter((path) => path.startsWith("evals/") &&
|
|
454
|
+
...listed.filter((path) => path.startsWith("evals/") && src.size(path) > MAX_EVAL_FILE_BYTES).map((path) => `${path}: is over ${MAX_EVAL_FILE_BYTES} bytes, an eval file's limit`),
|
|
232
455
|
...sizes.filter(([, size]) => size > MAX_FILE_BYTES).map(([path]) => `${path}: is over ${MAX_FILE_BYTES} bytes, a package file's limit`),
|
|
233
456
|
...(agentBytes > MAX_PACKAGE_BYTES ? [`the package's files are over ${MAX_PACKAGE_BYTES} bytes together, POST /v2/agents' own limit`] : []),
|
|
234
457
|
...(listed.length > MAX_PACKAGE_FILES ? [`the package holds over ${MAX_PACKAGE_FILES} files`] : []),
|
|
@@ -255,6 +478,10 @@ export function readPackage(dir) {
|
|
|
255
478
|
bad(MANIFEST, "author is {name, email?, url?}");
|
|
256
479
|
if (f.repository !== undefined && !(typeof f.repository === "string" && URL.canParse(f.repository) && /^https?:$/.test(new URL(f.repository).protocol)))
|
|
257
480
|
bad(MANIFEST, "repository is an http(s) URL");
|
|
481
|
+
// Display only: what a marketplace page and the console's list file it under, and its tags.
|
|
482
|
+
if (f.category !== undefined && !CATEGORIES.includes(f.category))
|
|
483
|
+
bad(MANIFEST, `category is one of ${CATEGORIES.join(", ")}`);
|
|
484
|
+
const tags = f.tags === undefined ? [] : Array.isArray(f.tags) && f.tags.length <= MAX_TAGS && f.tags.every((tag) => typeof tag === "string" && TAG.test(tag)) && new Set(f.tags).size === f.tags.length ? f.tags : (bad(MANIFEST, `tags is a list of at most ${MAX_TAGS} tags, each once, each lowercase letters, digits and dashes (${TAG.source})`), []);
|
|
258
485
|
const harness = f.harness === undefined ? undefined : list(f.harness, "harness", (id) => HARNESSES.includes(id));
|
|
259
486
|
if (harness && !harness.length)
|
|
260
487
|
bad(MANIFEST, `harness is a non-empty preference list of ${HARNESSES.join(", ")}; leave it out for any`);
|
|
@@ -264,24 +491,36 @@ export function readPackage(dir) {
|
|
|
264
491
|
if (f.effort !== undefined && !THINKING_LEVELS.includes(f.effort))
|
|
265
492
|
bad(MANIFEST, `effort is one of ${THINKING_LEVELS.join(", ")}`);
|
|
266
493
|
const tools = f.tools === undefined ? undefined : list(f.tools, "tools");
|
|
267
|
-
if (tools?.some(
|
|
494
|
+
if (tools?.some(isMcpName))
|
|
268
495
|
bad(MANIFEST, "tools grants no MCP tool: mcp lists them, by server");
|
|
269
|
-
|
|
270
|
-
|
|
496
|
+
// A monid endpoint (monid:<provider>/<endpoint> or monid:<provider>/*) is granted as written and pinned at the apply's save.
|
|
497
|
+
for (const tool of tools?.filter((tool) => !isMcpName(tool) && !(isMonidName(tool) && parseToolName(tool)) && !BOUND_TOOLS.includes(tool)) ?? [])
|
|
498
|
+
bad(MANIFEST, isMonidName(tool) ? `tools: ${MONID_NAME_WORDS(tool)}` : `tools: ${tool} is not a tool this server binds (${BOUND_TOOLS.join(", ")})`);
|
|
271
499
|
const mcp = [];
|
|
272
|
-
|
|
500
|
+
// Each need by where its tools come from (source, toolkit), never by a saved server's name: the package names its tools
|
|
501
|
+
// mcp:<toolkit>/<tool>, and apply maps the toolkit to the server the owner saved for it.
|
|
502
|
+
for (const [i, need] of (f.mcp === undefined ? [] : Array.isArray(f.mcp) ? f.mcp : (bad(MANIFEST, "mcp is a list of {source, toolkit, tools, required?, reason?, allow?, pin?}"), [])).entries()) {
|
|
273
503
|
const names = isObject(need) && Array.isArray(need.tools) ? need.tools : [];
|
|
274
504
|
const allow = isObject(need) && need.allow !== undefined ? need.allow : [];
|
|
275
505
|
const pin = isObject(need) && need.pin !== undefined ? need.pin : {};
|
|
276
|
-
const
|
|
506
|
+
const reason = isObject(need) ? need.reason : undefined;
|
|
507
|
+
const ok = isObject(need) && !unknownFields(need, ["source", "toolkit", "tools", "required", "reason", "allow", "pin"]).length && MCP_SOURCES.includes(need.source) && typeof need.toolkit === "string" && MCP_SERVER_NAME.test(need.toolkit)
|
|
508
|
+
&& names.length > 0 && names.every((tool) => typeof tool === "string" && MCP_TOOL_NAME.test(tool)) && new Set(names).size === names.length && (need.required === undefined || typeof need.required === "boolean")
|
|
509
|
+
&& (reason === undefined || (typeof reason === "string" && reason.trim() !== "" && reason.length <= MAX_REASON && !/[\r\n]/.test(reason)))
|
|
277
510
|
&& Array.isArray(allow) && allow.every((tool) => names.includes(tool)) && new Set(allow).size === allow.length;
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
bad(MANIFEST, `mcp[${i}]
|
|
511
|
+
// A toolkit is held to the MCP server name rule (tool-names.ts), so mcp:<toolkit>/<tool> inside the package is a catalog
|
|
512
|
+
// name every place that checks one (an agent's grant, a tool setting, a learned workflow) takes.
|
|
513
|
+
if (isObject(need) && need.toolkit !== undefined && (typeof need.toolkit !== "string" || !MCP_SERVER_NAME.test(need.toolkit)))
|
|
514
|
+
bad(MANIFEST, `mcp[${i}].toolkit ${JSON.stringify(need.toolkit)} is not a toolkit name: ${MCP_SERVER_NAME.source}, the MCP server name rule, since the package names its tools mcp:<toolkit>/<tool>`);
|
|
515
|
+
else if (!ok)
|
|
516
|
+
bad(MANIFEST, `mcp[${i}] is {source: ${MCP_SOURCES.join(" | ")}, toolkit: the toolkit its tools come from, the name the package calls them by (mcp:<toolkit>/<tool>, ${MCP_SERVER_NAME.source}), tools: its tool names (${MCP_TOOL_NAME.source}), none twice, required?: true or false, reason?: one line of at most ${MAX_REASON} characters on why the agent needs them, allow?: the tools of its tools it asks the owner to allow, pin?: {<tool>: {<argument>: <value>}}}`);
|
|
517
|
+
else if (need.source === "github" && need.toolkit !== "github")
|
|
518
|
+
bad(MANIFEST, `mcp[${i}]: a github source's toolkit is github (GitHub's MCP server), not ${need.toolkit}`);
|
|
519
|
+
else if (mcp.some((m) => m.toolkit === need.toolkit))
|
|
520
|
+
bad(MANIFEST, `mcp[${i}]: the toolkit ${need.toolkit} is listed twice: its tools are all mcp:${need.toolkit}/<tool>, so they are one entry`);
|
|
282
521
|
else {
|
|
283
|
-
const pinned = pinOf(pin, need.
|
|
284
|
-
mcp.push({
|
|
522
|
+
const pinned = pinOf(pin, need.toolkit, names, `mcp[${i}].pin`, (message) => bad(MANIFEST, message));
|
|
523
|
+
mcp.push({ source: need.source, toolkit: need.toolkit, tools: names, required: need.required === true, ...(typeof reason === "string" ? { reason } : {}), allow: allow, pin: pinned });
|
|
285
524
|
}
|
|
286
525
|
}
|
|
287
526
|
// A policy by tool: bash's alone (bash-read-only.ts), on a package that grants bash or names no tools (a new agent's
|
|
@@ -316,47 +555,17 @@ export function readPackage(dir) {
|
|
|
316
555
|
// The server's checkout before each run's first turn: the pull request the run's GitHub event names, at its head.
|
|
317
556
|
if (f.checkout !== undefined && f.checkout !== "pull_request")
|
|
318
557
|
bad(MANIFEST, "checkout is pull_request: the server checks out the pull request the run's GitHub event names, at its head, in repo/ before the first turn");
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
bad(MANIFEST, `parameters.${key} is {type: ${PARAMETER_TYPES.join(" | ")}, required?, pattern? (strings), enum?, format? (strings), default?, description}, its name lowercase`);
|
|
324
|
-
continue;
|
|
325
|
-
}
|
|
326
|
-
try {
|
|
327
|
-
if (typeof p.pattern === "string")
|
|
328
|
-
new RegExp(p.pattern, "u");
|
|
329
|
-
}
|
|
330
|
-
catch {
|
|
331
|
-
bad(MANIFEST, `parameters.${key}.pattern is not a regular expression`);
|
|
332
|
-
}
|
|
333
|
-
// What a string's value is (a cron line, a time zone), for a form to ask for it as such.
|
|
334
|
-
const format = p.format === undefined ? undefined : p.type === "string" && PARAMETER_FORMATS.includes(p.format) ? p.format : (bad(MANIFEST, `parameters.${key}.format is one of ${PARAMETER_FORMATS.join(", ")}, on a string parameter`), undefined);
|
|
335
|
-
// A closed set of values (a form shows a choice, never a pattern): one or more, each of the parameter's type, once.
|
|
336
|
-
const choices = p.enum === undefined ? undefined : Array.isArray(p.enum) && p.enum.length > 0 && p.enum.every((one) => ofType(p.type, one)) && new Set(p.enum).size === p.enum.length ? p.enum : (bad(MANIFEST, `parameters.${key}.enum is a list of one or more distinct ${p.type} values`), undefined);
|
|
337
|
-
if (choices && typeof p.pattern === "string")
|
|
338
|
-
bad(MANIFEST, `parameters.${key} has an enum and a pattern: the enum says the values, so leave the pattern out`);
|
|
339
|
-
if (choices && p.default !== undefined && !choices.includes(p.default))
|
|
340
|
-
bad(MANIFEST, `parameters.${key}.default is not one of its enum`);
|
|
341
|
-
if (p.default !== undefined) {
|
|
342
|
-
if (!ofType(p.type, p.default))
|
|
343
|
-
bad(MANIFEST, `parameters.${key}.default is a ${p.type}, as the parameter is`);
|
|
344
|
-
else if (typeof p.pattern === "string" && typeof p.default === "string" && !safeTest(p.pattern, p.default))
|
|
345
|
-
bad(MANIFEST, `parameters.${key}.default does not match its pattern`);
|
|
346
|
-
if (p.required === true)
|
|
347
|
-
bad(MANIFEST, `parameters.${key} is required and has a default: a default is for a parameter apply may leave out`);
|
|
348
|
-
}
|
|
349
|
-
parameters[key] = { type: p.type, required: p.required === true, description: p.description, ...(typeof p.pattern === "string" ? { pattern: p.pattern } : {}), ...(choices ? { enum: choices } : {}), ...(format ? { format } : {}), ...(p.default !== undefined && ofType(p.type, p.default) ? { default: p.default } : {}) };
|
|
350
|
-
}
|
|
558
|
+
// The setup an apply takes, in the inputs' grammar, by the same compiler; none, a schema of no fields.
|
|
559
|
+
const parameters = fieldsSchema(f.parameters, "parameters", (message) => bad(MANIFEST, message)) ?? { type: "object", additionalProperties: false, properties: {} };
|
|
560
|
+
const fields = fieldsOf(parameters);
|
|
561
|
+
const inputSchema = fieldsSchema(f.inputs, "inputs", (message) => bad(MANIFEST, message));
|
|
351
562
|
const secrets = list(f.secrets, "secrets", (secret) => /^[A-Z][A-Z0-9_]{0,127}$/.test(secret));
|
|
352
563
|
for (const secret of secrets.filter((name) => !PACKAGE_SECRETS.includes(name)))
|
|
353
564
|
bad(MANIFEST, `secrets names ${secret}, a key this server cannot hold: a package needs the keys Settings saves and a run is handed (${PACKAGE_SECRETS.join(", ")})`);
|
|
354
|
-
// Each run's
|
|
355
|
-
// agent's max_tool_calls: each conversation's calls), one of them at least.
|
|
565
|
+
// Each run's limit: its spend cap (per_run_usd, the agent's max_cost_usd), required once a budget is given.
|
|
356
566
|
const perRun = (value) => typeof value === "number" && Number.isFinite(value) && value > 0;
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
bad(MANIFEST, `budget is {per_run_usd?: a number above 0, tool_calls?: a whole number from 1 to ${MAX_TOOL_CALLS}}, one of them at least`);
|
|
567
|
+
if (f.budget !== undefined && !(isObject(f.budget) && !unknownFields(f.budget, ["per_run_usd"]).length && perRun(f.budget.per_run_usd)))
|
|
568
|
+
bad(MANIFEST, "budget is {per_run_usd: a number above 0}");
|
|
360
569
|
if (f.learning !== undefined && typeof f.learning !== "boolean")
|
|
361
570
|
bad(MANIFEST, "learning is true or false");
|
|
362
571
|
if (f.approvals !== undefined && f.approvals !== "ask" && f.approvals !== "never")
|
|
@@ -379,15 +588,13 @@ export function readPackage(dir) {
|
|
|
379
588
|
if (triggers.length && !(isObject(f.budget) && f.budget.per_run_usd !== undefined))
|
|
380
589
|
bad(MANIFEST, "budget is required when the package has triggers: {per_run_usd}, each run's cap");
|
|
381
590
|
let outputSchema;
|
|
382
|
-
let schemaBounded = true;
|
|
383
591
|
if (f.output !== undefined) {
|
|
384
592
|
const at = isObject(f.output) ? f.output.schema : undefined;
|
|
385
|
-
const evalSize = typeof at === "string" && at.startsWith("evals/") && inside(at) ?
|
|
593
|
+
const evalSize = typeof at === "string" && at.startsWith("evals/") && inside(at) ? src.size(at) : 0;
|
|
386
594
|
if (!isObject(f.output) || unknownFields(f.output, ["schema"]).length || !inside(at))
|
|
387
595
|
bad(MANIFEST, "output is {schema: a JSON Schema file in the package}");
|
|
388
596
|
else if (evalSize > MAX_FILE_BYTES || agentBytes + evalSize > MAX_PACKAGE_BYTES) {
|
|
389
|
-
|
|
390
|
-
bad(at, evalSize > MAX_FILE_BYTES ? `is over ${MAX_FILE_BYTES} bytes, a package file's limit: the answer's schema ships beside each SKILL.md, so it keeps an agent file's limits, under evals/ too` : `takes the agent's files over ${MAX_PACKAGE_BYTES} bytes together, POST /v2/agents' own limit: the answer's schema ships beside each SKILL.md, so it counts as an agent file, under evals/ too`);
|
|
597
|
+
bad(at, evalSize > MAX_FILE_BYTES ? `is over ${MAX_FILE_BYTES} bytes, a package file's limit: the answer's schema is given to the agent, so it keeps an agent file's limits, under evals/ too` : `takes the agent's files over ${MAX_PACKAGE_BYTES} bytes together, POST /v2/agents' own limit: the answer's schema is given to the agent, so it counts as an agent file, under evals/ too`);
|
|
391
598
|
}
|
|
392
599
|
else {
|
|
393
600
|
try {
|
|
@@ -400,49 +607,49 @@ export function readPackage(dir) {
|
|
|
400
607
|
}
|
|
401
608
|
}
|
|
402
609
|
}
|
|
403
|
-
const checks = list(f.checks, "checks", (check) => NAME.test(check));
|
|
404
610
|
const instructions = manifest?.body.trim() ?? "";
|
|
405
611
|
if (manifest && !instructions)
|
|
406
612
|
bad(MANIFEST, "its body is empty: the body is the agent's instructions");
|
|
407
613
|
for (const value of strings([instructions, triggers, f.display_name, mcp.map((need) => need.pin)])) {
|
|
408
614
|
for (const [, used] of value.matchAll(PLACEHOLDER))
|
|
409
|
-
if (!Object.hasOwn(
|
|
615
|
+
if (!Object.hasOwn(fields, used))
|
|
410
616
|
bad(MANIFEST, `\${parameters.${used}} names no parameter`);
|
|
411
617
|
}
|
|
412
618
|
// A placeholder fills text a run reads, a schedule's time (its cron and timezone, read as the schedule at apply), and a
|
|
413
|
-
// github trigger's where `in` values (the repository it takes, say); a trigger's other settings are the
|
|
414
|
-
// checked here. A parameter that sets a time has a default, so the schedule the package ships is checked
|
|
415
|
-
// a github trigger takes is required or has a default, so the trigger never fills
|
|
619
|
+
// github or webhook trigger's where `in` values (the repository it takes, say); a trigger's other settings are the
|
|
620
|
+
// package's own, checked here. A parameter that sets a time has a default, so the schedule the package ships is checked
|
|
621
|
+
// here too; one a github or webhook trigger's where takes is required or has a default, so the trigger never fills
|
|
622
|
+
// empty and takes no event.
|
|
416
623
|
triggers.forEach((trigger, i) => {
|
|
417
624
|
if (!isObject(trigger))
|
|
418
625
|
return;
|
|
419
626
|
const timed = isObject(trigger.source) && trigger.source.kind === "schedule";
|
|
420
|
-
const
|
|
627
|
+
const filtered = isObject(trigger.source) && FILTERED_KINDS.includes(trigger.source.kind);
|
|
421
628
|
const fixed = Object.entries(trigger).flatMap(([key, value]) => key === "target" && isObject(value) ? Object.entries(value).filter(([k]) => k !== "input").map(([k, v]) => [`target.${k}`, v])
|
|
422
629
|
: key === "source" && timed && isObject(value) ? Object.entries(value).filter(([k]) => !SCHEDULE_FIELDS.includes(k)).map(([k, v]) => [`source.${k}`, v])
|
|
423
|
-
: key === "source" &&
|
|
630
|
+
: key === "source" && filtered && isObject(value) ? [[key, whereIns(value).rest]]
|
|
424
631
|
: [[key, value]]);
|
|
425
632
|
for (const [at, value] of fixed)
|
|
426
633
|
for (const [used] of strings(value).flatMap((text) => [...text.matchAll(PLACEHOLDER)]))
|
|
427
|
-
bad(MANIFEST, `triggers[${i}].${at} holds ${used}: a placeholder goes in display_name, the instructions, a trigger's target.input, a schedule's cron and timezone, a github trigger's where in values, or an mcp pin's values`);
|
|
428
|
-
if (
|
|
634
|
+
bad(MANIFEST, `triggers[${i}].${at} holds ${used}: a placeholder goes in display_name, the instructions, a trigger's target.input, a schedule's cron and timezone, a github or webhook trigger's where in values, or an mcp pin's values`);
|
|
635
|
+
if (filtered) {
|
|
429
636
|
for (const used of new Set(strings(whereIns(trigger.source).ins).flatMap((text) => [...text.matchAll(PLACEHOLDER)].map((m) => m[1])))) {
|
|
430
|
-
if (Object.hasOwn(
|
|
431
|
-
bad(MANIFEST, `parameters.${used} is used in triggers[${i}].source.accept, so it is required or has a default: a
|
|
637
|
+
if (Object.hasOwn(fields, used) && !parameters.required?.includes(used) && fields[used].default === undefined)
|
|
638
|
+
bad(MANIFEST, `parameters.${used} is used in triggers[${i}].source.accept, so it is required or has a default: a ${trigger.source.kind} trigger filled empty takes no event`);
|
|
432
639
|
}
|
|
433
640
|
}
|
|
434
641
|
if (!timed)
|
|
435
642
|
return;
|
|
436
643
|
for (const field of SCHEDULE_FIELDS) {
|
|
437
644
|
for (const [, used] of strings(trigger.source[field]).flatMap((text) => [...text.matchAll(PLACEHOLDER)])) {
|
|
438
|
-
if (Object.hasOwn(
|
|
645
|
+
if (Object.hasOwn(fields, used) && fields[used].default === undefined)
|
|
439
646
|
bad(MANIFEST, `parameters.${used} is used in triggers[${i}].source.${field}, so it needs a default: the schedule the package ships is checked with it`);
|
|
440
647
|
}
|
|
441
648
|
}
|
|
442
649
|
});
|
|
443
650
|
// skills/<name>/SKILL.md, each named as its folder and described, as Agent Skills are; rules/*.md beside each.
|
|
444
651
|
const skills = {};
|
|
445
|
-
const skillDirs = kind("skills") === "dir" ?
|
|
652
|
+
const skillDirs = kind("skills") === "dir" ? src.entries("skills") : [];
|
|
446
653
|
for (const entry of skillDirs) {
|
|
447
654
|
if (!entry.isDirectory() || !NAME.test(entry.name)) {
|
|
448
655
|
bad(`skills/${entry.name}`, "skills/ holds only skill folders, each named in lowercase letters, digits and dashes");
|
|
@@ -459,7 +666,7 @@ export function readPackage(dir) {
|
|
|
459
666
|
for (const path of own)
|
|
460
667
|
skills[`${entry.name}/${path}`] = text(`skills/${entry.name}/${path}`);
|
|
461
668
|
}
|
|
462
|
-
const rules = kind("rules") === "dir" ?
|
|
669
|
+
const rules = kind("rules") === "dir" ? src.entries("rules") : [];
|
|
463
670
|
if (rules.length && !skillDirs.length)
|
|
464
671
|
bad("rules/", "rules ship beside each skill's SKILL.md, and the package has no skill");
|
|
465
672
|
for (const entry of rules) {
|
|
@@ -475,19 +682,13 @@ export function readPackage(dir) {
|
|
|
475
682
|
skills[path] = text(`rules/${entry.name}`);
|
|
476
683
|
}
|
|
477
684
|
}
|
|
478
|
-
// The answer's schema
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
const path = `${skill.name}/${basename(schemaFile)}`;
|
|
482
|
-
if (Object.hasOwn(skills, path))
|
|
483
|
-
bad(schemaFile, `skills/${path} has the same name, and the answer's schema ships beside each SKILL.md`);
|
|
484
|
-
else
|
|
485
|
-
skills[path] = text(schemaFile);
|
|
486
|
-
}
|
|
685
|
+
// The answer's schema is not copied beside each SKILL.md: it becomes the agent's output_schema, which the runner puts in
|
|
686
|
+
// the instructions on every harness (answer-json.ts outputContract). A skill that reads the file itself (a reviewer
|
|
687
|
+
// subagent's guide) keeps it in its own folder.
|
|
487
688
|
// evals/<case>/: prompt.md (the run's input), graders/*.md (each its type in its front matter), case.yaml and
|
|
488
689
|
// fixtures/ if it has them. The layout only: no eval runs here.
|
|
489
690
|
const evals = [];
|
|
490
|
-
for (const entry of kind("evals") === "dir" ?
|
|
691
|
+
for (const entry of kind("evals") === "dir" ? src.entries("evals") : []) {
|
|
491
692
|
const at = `evals/${entry.name}`;
|
|
492
693
|
if (!entry.isDirectory() || !NAME.test(entry.name)) {
|
|
493
694
|
bad(at, "evals/ holds only case folders, each named in lowercase letters, digits and dashes");
|
|
@@ -512,44 +713,59 @@ export function readPackage(dir) {
|
|
|
512
713
|
continue;
|
|
513
714
|
if (!GRADER_TYPES.includes(grader.data.type))
|
|
514
715
|
bad(`${at}/${path}`, `type is one of ${GRADER_TYPES.join(", ")}`);
|
|
515
|
-
else if (grader.data.type === "schema" && !inside(grader.data.schema))
|
|
516
|
-
bad(`${at}/${path}`, "a schema grader names its schema: a JSON Schema file in the package");
|
|
517
716
|
}
|
|
518
717
|
}
|
|
519
718
|
if (problems.length)
|
|
520
719
|
throw new PackageError(dir, [...new Set(problems)]);
|
|
521
720
|
const p = {
|
|
522
|
-
name, ...(typeof f.display_name === "string" ? { displayName: f.display_name } : {}), version: f.version, description: f.description,
|
|
721
|
+
id: name, origin: null, name, ...(typeof f.display_name === "string" ? { displayName: f.display_name } : {}), version: f.version, description: f.description,
|
|
523
722
|
...(typeof f.license === "string" ? { license: f.license } : {}), ...(isObject(f.author) ? { author: f.author } : {}), ...(typeof f.repository === "string" ? { repository: f.repository } : {}),
|
|
723
|
+
...(typeof f.category === "string" ? { category: f.category } : {}), tags,
|
|
524
724
|
...(harness ? { harness } : {}), ...(isObject(f.model) ? { model: f.model } : {}), ...(typeof f.effort === "string" ? { effort: f.effort } : {}),
|
|
525
|
-
...(tools ? { tools } : {}), mcp, ...(computer ? { computer } : {}), ...(toolPolicy ? { toolPolicy } : {}), ...(f.checkout === "pull_request" ? { checkout: "pull_request" } : {}), parameters,
|
|
526
|
-
triggers: triggers, ...(isObject(f.output) ? { output: { schema: f.output.schema } } : {}), ...(isObject(outputSchema) ? { outputSchema } : {}),
|
|
725
|
+
...(tools ? { tools } : {}), mcp, ...(computer ? { computer } : {}), ...(toolPolicy ? { toolPolicy } : {}), ...(f.checkout === "pull_request" ? { checkout: "pull_request" } : {}), parameters, ...(inputSchema ? { inputSchema } : {}), secrets, ...(isObject(f.budget) ? { budget: { per_run_usd: f.budget.per_run_usd } } : {}), ...(typeof f.learning === "boolean" ? { learning: f.learning } : {}), ...(f.approvals === "ask" || f.approvals === "never" ? { approvals: f.approvals } : {}),
|
|
726
|
+
triggers: triggers, ...(isObject(f.output) ? { output: { schema: f.output.schema } } : {}), ...(isObject(outputSchema) ? { outputSchema } : {}), instructions, skills, evals,
|
|
527
727
|
};
|
|
528
728
|
// What an apply makes, made here with each parameter's default, else a sample of its type, and checked as POST
|
|
529
729
|
// /v2/agents and POST /v2/triggers check their bodies (all but the agent the trigger names, which an apply makes). A
|
|
530
730
|
// trigger's times are read as of the epoch, so its form is checked here and a date that has passed is the apply's
|
|
531
731
|
// refusal, never a server's start.
|
|
532
|
-
const samples = Object.fromEntries(Object.entries(
|
|
732
|
+
const samples = Object.fromEntries(Object.entries(fields).map(([key, spec]) => [key, spec.default ?? (spec.type === "array" ? [sampleOf(spec.items)] : sampleOf(spec))]));
|
|
533
733
|
const declared = Object.fromEntries(MODEL_TIER_NAMES.flatMap((tier) => (p.model?.[tier] ? [[tier, p.model[tier]]] : [])));
|
|
534
|
-
|
|
734
|
+
// Every MCP tool ticked, each served under its toolkit's name: the widest agent an apply can make, so each tool the
|
|
735
|
+
// package lists is checked as a grant.
|
|
736
|
+
const every = mcp.flatMap(({ toolkit, tools: listed }) => listed.map((tool) => mcpToolName(toolkit, tool)));
|
|
737
|
+
const made = compiled(p, samples, { ...(harness ? { harness: harness[0] } : {}), ...(p.model?.prefer ? { model: p.model.prefer } : {}), ...(Object.keys(declared).length ? { modelTiers: declared } : {}), mcp: mcp.map((need) => ({ ...need, server: need.toolkit })), defaultTools: [], grants: every });
|
|
535
738
|
for (const issue of definitionBodyIssues(made.agent))
|
|
536
739
|
bad(issue.field.startsWith("skills.") ? `skills/${issue.field.slice("skills.".length)}` : MANIFEST, `${issue.field.startsWith("skills.") ? "" : `the agent it makes: ${issue.field}: `}${issue.message}`);
|
|
537
|
-
for
|
|
538
|
-
|
|
740
|
+
// A sample stands in for a value apply is given: at a target.input field a parameter with no default fills whole, what
|
|
741
|
+
// hangs on the value (a pattern, a bound, a choice) is the apply's, on the value given. Its type, and whether the
|
|
742
|
+
// inputs name the field at all, are checked here.
|
|
743
|
+
const sampled = (field) => {
|
|
744
|
+
const at = /^triggers\.(\d+)\.target\.input\.([^.]+)/.exec(field);
|
|
745
|
+
const target = at ? p.triggers[Number(at[1])]?.target : undefined;
|
|
746
|
+
const value = at && isObject(target) && isObject(target.input) ? target.input[at[2]] : undefined;
|
|
747
|
+
const whole = typeof value === "string" ? WHOLE.exec(value) : null;
|
|
748
|
+
return !!whole && Object.hasOwn(fields, whole[1]) && fields[whole[1]].default === undefined;
|
|
749
|
+
};
|
|
750
|
+
for (const issue of madeTriggerIssues(made.triggers, 0, p.inputSchema))
|
|
751
|
+
if (["wrong_type", "not_allowed", "missing"].includes(issue.reason) || !sampled(issue.field))
|
|
752
|
+
bad(MANIFEST, `${issue.field.replace(/^triggers\.(\d+)\./, "triggers[$1].")}: ${issue.message}`);
|
|
539
753
|
if (problems.length)
|
|
540
754
|
throw new PackageError(dir, [...new Set(problems)]);
|
|
541
755
|
return p;
|
|
542
756
|
}
|
|
543
757
|
/** What is wrong with the trigger bodies an apply makes (compiled's `triggers`), as POST /v2/triggers checks a body, all
|
|
544
758
|
* but the agent each names (the one the apply makes), as of `now`, each field under `triggers.<i>`. A trigger's input is
|
|
545
|
-
* its runs' input, and a package's agent is agentic, so each input is checked against
|
|
546
|
-
* validator runs it as of the epoch (a time's form
|
|
547
|
-
|
|
759
|
+
* its runs' input, and a package's agent is agentic, so each input is checked against the package's input schema in
|
|
760
|
+
* force too (`inputSchema`, its `inputs` compiled: inputSchemaOf). The validator runs it as of the epoch (a time's form
|
|
761
|
+
* only); an apply runs it before it makes anything. */
|
|
762
|
+
export function madeTriggerIssues(made, now, inputSchema) {
|
|
763
|
+
const schema = inputSchemaOf(inputSchema);
|
|
548
764
|
return made.flatMap((trigger, i) => {
|
|
549
765
|
const issues = triggerBodyIssues(TRIGGER_ADAPTERS, { ...trigger, target: { ...trigger.target, agent_id: SAMPLE_AGENT } }, now);
|
|
550
766
|
const input = isObject(trigger.target) ? trigger.target.input : undefined;
|
|
551
767
|
if (isObject(input))
|
|
552
|
-
issues.push(...inputIssues(input,
|
|
768
|
+
issues.push(...inputIssues(input, schema, "target.input"));
|
|
553
769
|
return issues.map((issue) => ({ ...issue, field: `triggers.${i}.${issue.field}` }));
|
|
554
770
|
});
|
|
555
771
|
}
|
|
@@ -560,22 +776,69 @@ export function readPackages(dir = TEMPLATES_DIR) {
|
|
|
560
776
|
/** A package as GET /v2/templates lists it: what an apply asks for and makes. */
|
|
561
777
|
export function packageView(p) {
|
|
562
778
|
return {
|
|
779
|
+
id: p.id, bundled: p.origin === null, source: p.origin?.source ?? null, sha: p.origin?.sha ?? null, publisher: p.origin?.publisher ?? null,
|
|
563
780
|
name: p.name, display_name: p.displayName ?? null, version: p.version, description: p.description, license: p.license ?? null, author: p.author ?? null, repository: p.repository ?? null,
|
|
781
|
+
category: p.category ?? null, tags: p.tags,
|
|
564
782
|
output: p.output ? { schema: p.output.schema, json_schema: p.outputSchema ?? null } : null,
|
|
565
783
|
harness: p.harness ?? null, model: p.model ?? null, effort: p.effort ?? null, tools: p.tools ?? null, tool_policy: p.toolPolicy ?? null, computer: p.computer ?? null, checkout: p.checkout ?? null,
|
|
566
|
-
mcp: p.mcp.map(({
|
|
784
|
+
mcp: p.mcp.map(({ source, toolkit, tools, required, reason, allow, pin }) => ({ source, toolkit, required, reason: reason ?? null, tools: tools.map((name) => ({ name, tool: mcpToolName(toolkit, name), asks: allow.includes(name) ? "allow" : "ask", ...(Object.hasOwn(pin, name) ? { pin: pin[name] } : {}) })) })), parameters: p.parameters, input_schema: p.inputSchema ?? null, secrets: p.secrets,
|
|
567
785
|
budget: p.budget ?? null, learning: p.learning ?? false, approvals_default: p.approvals ?? "ask", triggers: p.triggers, skills: Object.keys(p.skills).filter((path) => /^[^/]+\/SKILL\.md$/.test(path)).map((path) => path.slice(0, -"/SKILL.md".length)), evals: p.evals,
|
|
568
786
|
};
|
|
569
787
|
}
|
|
788
|
+
/** A package as an import answers it: its listing, and every text its agent would be given, the instructions and each
|
|
789
|
+
* skill file by path (a rule and the answer's schema beside each SKILL.md among them), so a person reads what a third
|
|
790
|
+
* party's package would tell their agent before it is installed. */
|
|
791
|
+
export function packageDetail(p) {
|
|
792
|
+
return { ...packageView(p), instructions: p.instructions, skill_files: { ...p.skills } };
|
|
793
|
+
}
|
|
794
|
+
/** The packages this server serves: the ones it ships, read at its start, and the ones imported here (the store keeps
|
|
795
|
+
* them; the server loads them beside the bundled ones at its start). An id is one package; a bundled one is never
|
|
796
|
+
* replaced or removed, and an imported id (`github:…`) is never a bundled one's name. */
|
|
797
|
+
export class TemplateRegistry {
|
|
798
|
+
bundled;
|
|
799
|
+
imported = new Map();
|
|
800
|
+
constructor(bundled) {
|
|
801
|
+
this.bundled = bundled;
|
|
802
|
+
}
|
|
803
|
+
/** The bundled packages by name, then the imported ones by id. */
|
|
804
|
+
list() {
|
|
805
|
+
return [...this.bundled, ...[...this.imported.values()].sort((a, b) => a.id.localeCompare(b.id))];
|
|
806
|
+
}
|
|
807
|
+
get(id) {
|
|
808
|
+
return this.bundled.find((p) => p.id === id) ?? this.imported.get(id);
|
|
809
|
+
}
|
|
810
|
+
/** An imported package, in place of the one under its id. */
|
|
811
|
+
put(p) {
|
|
812
|
+
if (p.origin === null || this.bundled.some((one) => one.id === p.id))
|
|
813
|
+
throw new TypeError(`${p.id} is a bundled package's id`);
|
|
814
|
+
this.imported.set(p.id, p);
|
|
815
|
+
}
|
|
816
|
+
/** Whether an imported package of that id was there to remove. */
|
|
817
|
+
remove(id) {
|
|
818
|
+
return this.imported.delete(id);
|
|
819
|
+
}
|
|
820
|
+
}
|
|
570
821
|
/** POST /v2/templates/{name}/apply's body (`{parameters, grants?, overrides?: {model}}`), checked against the package:
|
|
571
|
-
* the parameters as given, the MCP tools the owner allows (each one the package lists, by its gate name), and the model
|
|
822
|
+
* the parameters as given (a blank one at its default), the MCP tools the owner allows (each one the package lists, by its gate name), and the model
|
|
572
823
|
* asked for in place of the package's. 422 naming every field that is wrong. */
|
|
573
824
|
export function applyBodyOf(p, body) {
|
|
574
|
-
const issues = unknownFields(body, ["parameters", "grants", "overrides"]);
|
|
575
|
-
const listed = p.mcp.flatMap(({
|
|
825
|
+
const issues = unknownFields(body, ["parameters", "grants", "servers", "overrides"]);
|
|
826
|
+
const listed = p.mcp.flatMap(({ toolkit, tools }) => tools.map((tool) => mcpToolName(toolkit, tool)));
|
|
576
827
|
const grants = [];
|
|
577
828
|
if (body.grants !== undefined && !Array.isArray(body.grants))
|
|
578
|
-
issues.push({ field: "grants", reason: "wrong_type", message: "grants is a list of the package's MCP tools, by
|
|
829
|
+
issues.push({ field: "grants", reason: "wrong_type", message: "grants is a list of the package's MCP tools, by the package's own names (mcp:<toolkit>/<tool>), the owner allows" });
|
|
830
|
+
// The owner's pick of a saved server for a toolkit (when several match): checked against what is saved at apply.
|
|
831
|
+
const servers = {};
|
|
832
|
+
if (body.servers !== undefined && !isObject(body.servers))
|
|
833
|
+
issues.push({ field: "servers", reason: "wrong_type", message: "servers is an object: {<toolkit>: <the saved MCP server's name>}, for a need several saved servers match" });
|
|
834
|
+
for (const [toolkit, name] of Object.entries(isObject(body.servers) ? body.servers : {})) {
|
|
835
|
+
if (!p.mcp.some((need) => need.toolkit === toolkit))
|
|
836
|
+
issues.push({ field: `servers.${toolkit}`, reason: "not_allowed", message: `The package ${p.name} uses no toolkit ${toolkit}: its MCP needs are ${p.mcp.map((need) => need.toolkit).join(", ") || "none"}.` });
|
|
837
|
+
else if (typeof name !== "string" || !MCP_SERVER_NAME.test(name))
|
|
838
|
+
issues.push({ field: `servers.${toolkit}`, reason: "wrong_type", message: `servers.${toolkit} is the name of a saved MCP server` });
|
|
839
|
+
else
|
|
840
|
+
servers[toolkit] = name;
|
|
841
|
+
}
|
|
579
842
|
for (const [i, grant] of (Array.isArray(body.grants) ? body.grants : []).entries()) {
|
|
580
843
|
if (typeof grant !== "string" || !listed.includes(grant))
|
|
581
844
|
issues.push({ field: `grants.${i}`, reason: "not_allowed", message: `grants.${i} is not a tool of the package ${p.name}: it grants ${listed.join(", ") || "no MCP tool"}.` });
|
|
@@ -585,28 +848,17 @@ export function applyBodyOf(p, body) {
|
|
|
585
848
|
const given = body.parameters ?? {};
|
|
586
849
|
if (!isObject(given))
|
|
587
850
|
issues.push({ field: "parameters", reason: "wrong_type", message: "parameters is an object of the package's parameters, by name" });
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
issues.push({ field: `parameters.${key}`, reason: "bad_format", message: `parameters.${key} is ${spec.description}` });
|
|
600
|
-
else
|
|
601
|
-
parameters[key] = value;
|
|
602
|
-
}
|
|
603
|
-
for (const [key, spec] of Object.entries(p.parameters)) {
|
|
604
|
-
const absent = isObject(given) && (!Object.hasOwn(given, key) || given[key] === undefined || given[key] === "");
|
|
605
|
-
if (spec.required && absent)
|
|
606
|
-
issues.push({ field: `parameters.${key}`, reason: "missing", message: `parameters.${key} is required: ${spec.description}` });
|
|
607
|
-
else if (absent && spec.default !== undefined)
|
|
608
|
-
parameters[key] = spec.default;
|
|
609
|
-
}
|
|
851
|
+
// A parameter left blank (left out, or "") takes its default; then they are checked as a run's input is (the same
|
|
852
|
+
// compiler, the same words), so a blank required one is missing.
|
|
853
|
+
// A declared parameter given blank is left out (its default filled); an undeclared one stays, for the check to refuse.
|
|
854
|
+
const fields = fieldsOf(p.parameters);
|
|
855
|
+
const blank = (key) => !isObject(given) || givenOf(given, key) === undefined || given[key] === "";
|
|
856
|
+
const parameters = Object.fromEntries([
|
|
857
|
+
...Object.entries(isObject(given) ? given : {}).filter(([key]) => !blank(key) || !Object.hasOwn(fields, key)),
|
|
858
|
+
...Object.entries(fields).filter(([key, spec]) => blank(key) && spec.default !== undefined).map(([key, spec]) => [key, spec.default]),
|
|
859
|
+
]);
|
|
860
|
+
if (isObject(given))
|
|
861
|
+
issues.push(...inputIssues(parameters, p.parameters, "parameters"));
|
|
610
862
|
const overrides = body.overrides ?? {};
|
|
611
863
|
if (!isObject(overrides))
|
|
612
864
|
issues.push({ field: "overrides", reason: "wrong_type", message: "overrides is an object: {model?, approvals?}" });
|
|
@@ -619,7 +871,7 @@ export function applyBodyOf(p, body) {
|
|
|
619
871
|
}
|
|
620
872
|
if (issues.length)
|
|
621
873
|
throw invalid(issues);
|
|
622
|
-
return { parameters, grants, ...(isObject(overrides) && typeof overrides.model === "string" ? { model: overrides.model } : {}), ...(isObject(overrides) && (overrides.approvals === "ask" || overrides.approvals === "never") ? { approvals: overrides.approvals } : {}) };
|
|
874
|
+
return { parameters, grants, servers, ...(isObject(overrides) && typeof overrides.model === "string" ? { model: overrides.model } : {}), ...(isObject(overrides) && (overrides.approvals === "ask" || overrides.approvals === "never") ? { approvals: overrides.approvals } : {}) };
|
|
623
875
|
}
|
|
624
876
|
/** The model a package's agent gets here, as `{model?, warning?}`: its `prefer` when this server runs it on `harness`
|
|
625
877
|
* with a key for its provider, but never through a gateway (AGENT_MODEL_BASE_URL), which never said it serves it: then
|
|
@@ -704,16 +956,20 @@ export async function packageTiers(env, model, harness, own) {
|
|
|
704
956
|
return { ...(Object.keys(tiers).length ? { modelTiers: tiers } : {}), ...(skipped.length ? { warning: skipped.join(" ") } : {}) };
|
|
705
957
|
}
|
|
706
958
|
/** The bodies an apply makes: POST /v2/agents' (its definition and skill files) and each trigger's, with no agent_id,
|
|
707
|
-
* every `${parameters.x}` filled. `
|
|
708
|
-
* the package's tools
|
|
709
|
-
*
|
|
710
|
-
*
|
|
711
|
-
*
|
|
712
|
-
*
|
|
959
|
+
* every `${parameters.x}` filled. `grants`, the owner's answer at apply (the tools ticked, by the saved servers' names):
|
|
960
|
+
* of the package's tools on `mcp`, its needs each served by a saved server, those alone are granted, beside the package's tools (or, when it names
|
|
961
|
+
* none, `defaultTools`, those this server gives a new agent), each set to allow but those `held` (a deny the owner set on
|
|
962
|
+
* this server holds them: granted, never allowed). A tool left unticked is not the agent's at all, so no harness offers
|
|
963
|
+
* it and approvals never, which lifts an ask of a tool the agent has, has nothing to lift: the owner grants it later in
|
|
964
|
+
* the agent's tools. A tool the package pins gets its pin, filled, in the agent's tool settings, whatever its permission
|
|
965
|
+
* and ticked or not (it holds once the tool is granted later); one whose pin fills empty (its parameter not given) is set
|
|
966
|
+
* to deny instead, and named in `unpinned` (by gate name, with the parameters not given): a send with no destination set
|
|
967
|
+
* never runs. */
|
|
713
968
|
export function compiled(p, parameters, chosen, _deps) {
|
|
714
969
|
const skills = Object.keys(p.skills).filter((path) => /^[^/]+\/SKILL\.md$/.test(path)).map((path) => path.slice(0, -"/SKILL.md".length));
|
|
715
|
-
|
|
716
|
-
const
|
|
970
|
+
// The ticks, in the package's order: never a tool of a server not saved here, nor one the owner did not tick.
|
|
971
|
+
const granted = chosen.mcp.flatMap(({ server, tools }) => tools.map((tool) => mcpToolName(server, tool))).filter((tool) => chosen.grants.includes(tool));
|
|
972
|
+
const allowed = granted.filter((tool) => !chosen.held?.includes(tool));
|
|
717
973
|
// The computer its list picked (pickComputer): its tools less the shell tools that computer does not run; a package
|
|
718
974
|
// that names none is given that computer's shell tools, as a new agent in a box is given the box's.
|
|
719
975
|
const pick = chosen.computer;
|
|
@@ -738,15 +994,17 @@ export function compiled(p, parameters, chosen, _deps) {
|
|
|
738
994
|
name: p.displayName ? filled(p.displayName, parameters) : p.name, description: p.description, instructions: filled(p.instructions, parameters),
|
|
739
995
|
...(chosen.harness ? { harness: chosen.harness } : {}), ...(chosen.model ? { model: chosen.model } : {}), ...(chosen.modelTiers && Object.keys(chosen.modelTiers).length ? { model_tiers: chosen.modelTiers } : {}), ...(p.effort ? { thinking: p.effort } : {}),
|
|
740
996
|
...(pick ? { computer: pick.computer } : {}), ...(tools ? { tools } : {}), ...(Object.keys(settings).length ? { tool_settings: settings } : {}),
|
|
741
|
-
...(p.learning !== undefined ? { learning: p.learning } : {}), ...(p.budget?.per_run_usd ? { max_cost_usd: p.budget.per_run_usd } : {}),
|
|
997
|
+
...(p.learning !== undefined ? { learning: p.learning } : {}), ...(p.budget?.per_run_usd ? { max_cost_usd: p.budget.per_run_usd } : {}), skills,
|
|
742
998
|
// The apply's choice: unattended only when it says never (none given: the agent asks).
|
|
743
999
|
...(chosen.approvals === "never" ? { approvals: "never" } : {}),
|
|
1000
|
+
// The package's typed input (manifest `inputs`): what each run's input is checked against, and how the model reads it.
|
|
1001
|
+
...(isObject(p.inputSchema) ? { input_schema: p.inputSchema } : {}),
|
|
744
1002
|
// The package's answer schema (manifest `output`): each completed run's structured answer, checked, is its result.output.
|
|
745
1003
|
...(isObject(p.outputSchema) ? { output_schema: p.outputSchema } : {}),
|
|
746
1004
|
// The package's checkout (manifest `checkout`): the server fetches it before each run's first turn.
|
|
747
1005
|
...(p.checkout ? { checkout: p.checkout } : {}),
|
|
748
1006
|
};
|
|
749
|
-
return { agent: { definition, skills: { ...p.skills } }, triggers: p.triggers.map((trigger) =>
|
|
1007
|
+
return { agent: { definition, skills: { ...p.skills } }, triggers: p.triggers.map((trigger) => triggerFilled(trigger, parameters)), unpinned };
|
|
750
1008
|
}
|
|
751
1009
|
/** Each pin the package's MCP servers (`mcp`) set, by the tool's gate name, its values filled from `parameters`, and the
|
|
752
1010
|
* parameters it names that were not given (`empty`, none when it fills whole). */
|
|
@@ -756,3 +1014,57 @@ export function filledPins(mcp, parameters) {
|
|
|
756
1014
|
return { tool: mcpToolName(server, tool), pin: Object.fromEntries(each.map(([arg, one]) => [arg, one.value])), empty: [...new Set(each.flatMap(([, one]) => one.empty))] };
|
|
757
1015
|
}));
|
|
758
1016
|
}
|
|
1017
|
+
/** How the owner sets up a need no saved server matches, in words: the Composio preset with its toolkit and actions,
|
|
1018
|
+
* GitHub's MCP on the App, or any server marked with the toolkit in Settings. */
|
|
1019
|
+
export function mcpSetUp(need) {
|
|
1020
|
+
const tools = need.tools.join(", ");
|
|
1021
|
+
return need.source === "composio" ? `Add it in Settings → MCP servers → Add from Composio, toolkit ${need.toolkit}, actions ${tools}, then apply the template again.`
|
|
1022
|
+
: need.source === "github" ? "Connect GitHub in Settings, then add GitHub's MCP server in Settings → MCP servers with GitHub App access, and apply the template again."
|
|
1023
|
+
: `Add the MCP server that serves ${tools} in Settings → MCP servers and set its toolkit to ${need.toolkit}, then apply the template again.`;
|
|
1024
|
+
}
|
|
1025
|
+
/** Each MCP need of `p` mapped to a saved server here: `candidates`, those whose record is the need's {source, toolkit},
|
|
1026
|
+
* by name; `server`, the owner's pick among them (`picks`, by toolkit), else the one candidate, else none. Never picked
|
|
1027
|
+
* silently: several candidates and no pick is refused (422 under servers.<toolkit>, naming them), and so is a pick that
|
|
1028
|
+
* is not a candidate (an owner never maps a need to a server that says it is something else). */
|
|
1029
|
+
export function serversFor(p, saved, picks) {
|
|
1030
|
+
const issues = [];
|
|
1031
|
+
const mapped = p.mcp.map((need) => {
|
|
1032
|
+
const candidates = saved.filter((one) => one.source === need.source && one.toolkit === need.toolkit).map((one) => one.name).sort();
|
|
1033
|
+
const pick = Object.hasOwn(picks, need.toolkit) ? picks[need.toolkit] : undefined;
|
|
1034
|
+
if (pick !== undefined && !candidates.includes(pick))
|
|
1035
|
+
issues.push({ field: `servers.${need.toolkit}`, reason: "not_an_option", message: `${pick} is not a saved MCP server that is ${need.source} ${need.toolkit}: ${candidates.length ? `${candidates.join(", ")} ${candidates.length === 1 ? "is" : "are"}` : "none is saved here"}.` });
|
|
1036
|
+
else if (pick === undefined && candidates.length > 1)
|
|
1037
|
+
issues.push({ field: `servers.${need.toolkit}`, reason: "missing", message: `Saved MCP servers ${new Intl.ListFormat("en", { type: "conjunction" }).format(candidates)} are each ${need.source} ${need.toolkit}: servers.${need.toolkit} says which one the agent uses.` });
|
|
1038
|
+
const server = pick ?? (candidates.length === 1 ? candidates[0] : null);
|
|
1039
|
+
return { need, server, candidates };
|
|
1040
|
+
});
|
|
1041
|
+
if (issues.length)
|
|
1042
|
+
throw invalid(issues);
|
|
1043
|
+
return mapped;
|
|
1044
|
+
}
|
|
1045
|
+
const SERVER_PART = MCP_SERVER_NAME.source.slice(1, -1);
|
|
1046
|
+
const TOOL_PART = MCP_TOOL_NAME.source.slice(1, -1);
|
|
1047
|
+
/** A catalog MCP name in prose (`mcp:<server>/<tool>` or `mcp:<server>/*`), whole: not the tail of a longer word
|
|
1048
|
+
* (`xmcp:gmail/x`), nor cut short of a longer tool name. */
|
|
1049
|
+
const MCP_NAME_IN_TEXT = new RegExp(`(?<![A-Za-z0-9_.:/-])mcp:${SERVER_PART}/(?:\\*|${TOOL_PART}(?![A-Za-z0-9_-]))`, "g");
|
|
1050
|
+
/** Catalog name `name` on the saved servers of `servers` ({toolkit: saved name}): read (parseToolName), its server swapped
|
|
1051
|
+
* when it is one of the package's toolkits, and written again (formatToolName); a wildcard `mcp:<toolkit>/*` the same
|
|
1052
|
+
* way. Any other name, or one outside the grammar, as it is. */
|
|
1053
|
+
export function onServerName(name, servers) {
|
|
1054
|
+
const parsed = parseToolName(name);
|
|
1055
|
+
if (!parsed || (parsed.kind !== "mcp" && parsed.kind !== "mcp-server") || !Object.hasOwn(servers, parsed.server))
|
|
1056
|
+
return name;
|
|
1057
|
+
return formatToolName({ ...parsed, server: servers[parsed.server] });
|
|
1058
|
+
}
|
|
1059
|
+
/** `text` with each whole catalog MCP name in it on the saved servers' (onServerName), in one pass, so a server named as
|
|
1060
|
+
* another of the package's toolkits is never rewritten twice. */
|
|
1061
|
+
export function onServerNames(text, servers) {
|
|
1062
|
+
if (!Object.keys(servers).some((toolkit) => servers[toolkit] !== toolkit))
|
|
1063
|
+
return text;
|
|
1064
|
+
return text.replace(MCP_NAME_IN_TEXT, (name) => onServerName(name, servers));
|
|
1065
|
+
}
|
|
1066
|
+
/** `p` as the agent an apply makes on `servers` sees it: its instructions and each skill file with the package's tool
|
|
1067
|
+
* names on the saved servers' (onServerNames). Nothing else of it names a server: its pins and allow are by tool. */
|
|
1068
|
+
export function onServers(p, servers) {
|
|
1069
|
+
return { ...p, instructions: onServerNames(p.instructions, servers), skills: Object.fromEntries(Object.entries(p.skills).map(([path, text]) => [path, onServerNames(text, servers)])) };
|
|
1070
|
+
}
|