@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/monid.js
CHANGED
|
@@ -1,28 +1,33 @@
|
|
|
1
|
-
// monid (monid.ai): one key, and a
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
1
|
+
// monid (monid.ai): one key, and a listing of paid data endpoints from many providers. An agent is granted endpoints by
|
|
2
|
+
// name, `monid:<provider>/<endpoint>` or a provider's `monid:<provider>/*` (tool-names.ts), and each granted endpoint is
|
|
3
|
+
// one tool of its own, on every harness: its description, input and price as monid listed them when the agent was saved.
|
|
4
|
+
//
|
|
5
|
+
// At the save (server.ts saveable, the one check of a create, an edit and an inline run): each grant is read against
|
|
6
|
+
// monid's listing (a provider's wildcard: every endpoint it lists, GET /v1/endpoints; one endpoint: POST /v1/inspect),
|
|
7
|
+
// and the pin (MonidPin) is stamped on the revision. A grant monid does not list is refused in words, so is one that
|
|
8
|
+
// cannot be read now (no key, monid unreachable). A run reads its revision's pin and never monid's listing.
|
|
9
|
+
//
|
|
10
|
+
// Only an endpoint with a fixed price is pinned. One priced by usage (per result, per unit, metered) costs what it
|
|
11
|
+
// used, known only once it has run, and monid bounds no such call's charge: maxCost checks monid's estimate, which such a
|
|
12
|
+
// call can pass (monid's API reference, POST /v1/run). No hold could keep a run's cap, so it is refused as a named grant
|
|
13
|
+
// and left out of a provider's wildcard, each in words (unboundedWords).
|
|
14
|
+
//
|
|
15
|
+
// At a run (runner/monid-run.ts): each pinned endpoint is one host tool, by its catalog name (its wire name on the
|
|
16
|
+
// harness, catalog.ts wireName). The gate asks about it by that name, its card shows its pinned price, and a call is a
|
|
17
|
+
// paid step on the run's one ledger (paid-calls.ts paidStep) named by it: held at the pinned price before it is sent,
|
|
18
|
+
// refused unsent unless that fits the cap with what the run has spent and holds, then settled once at what monid says it
|
|
19
|
+
// charged, else at its hold unless monid says it charged nothing. It is sent with its hold as maxCost: monid refuses it
|
|
20
|
+
// unrun when it now prices it above the pin, so a fixed-price call is never charged past what it was held at.
|
|
6
21
|
//
|
|
7
22
|
// A run is sent once and never again: it spends money, and a request that failed after it left may have run. An async
|
|
8
23
|
// provider answers 202 with a run id, read again every POLL_MS until it ends, for at most WAIT_MS in all; a run the
|
|
9
24
|
// caller stops, or one that outlasts the wait, is asked to stop. Every answer reaches the model as JSON, cut at CLIP
|
|
10
25
|
// characters, the whole of it then filed under the run's work/evidence/monid/.
|
|
11
|
-
//
|
|
12
|
-
// What a run charged is the run's spend (cap.ts): marked before it is sent at the price an inspect quoted (else an
|
|
13
|
-
// allowance), then booked once in the run's records as a TOOL_COST (`monid.run`, charged by monid), its cost if monid
|
|
14
|
-
// reports one, else unknown unless monid says it charged nothing, which the cap counts at what the run was held at; and
|
|
15
|
-
// under a cap a run is refused before it is sent unless the run's spend plus what it is held at fits. discover and
|
|
16
|
-
// inspect cost nothing, and are never refused.
|
|
17
26
|
import { randomUUID } from "node:crypto";
|
|
18
|
-
import {
|
|
19
|
-
import { defineExtension, defineTool, ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
20
|
-
import { registerLabel, TOOL_COST } from "./timeline/index.js";
|
|
21
|
-
import { paidCall } from "./cap.js";
|
|
27
|
+
import { workspaceErrorWords } from "./workspace/index.js";
|
|
22
28
|
import { wireName } from "./catalog.js";
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import { forModel } from "./result.js";
|
|
29
|
+
import { formatToolName, parseToolName } from "./tool-names.js";
|
|
30
|
+
import { redacted } from "./key-refusal.js";
|
|
26
31
|
import { isObject } from "./validate.js";
|
|
27
32
|
export const MONID_KEY_ENV = "MONID_API_KEY";
|
|
28
33
|
/** Under `faux` only (startServe's `fauxMonid`): a module whose default export is the fetch monid's calls go through, in
|
|
@@ -31,13 +36,21 @@ export const FAUX_MONID_ENV = "AGENTRUN_SERVE_FAUX_MONID";
|
|
|
31
36
|
export const MONID_API = "https://api.monid.ai";
|
|
32
37
|
/** The most characters of one answer the model reads. */
|
|
33
38
|
export const CLIP = 60_000;
|
|
39
|
+
/** The most endpoints one provider's wildcard pins: a provider that lists more is granted endpoint by endpoint. */
|
|
40
|
+
export const MONID_WILDCARD_MAX = 50;
|
|
34
41
|
const TERMINAL = ["COMPLETED", "FAILED", "BLOCKED", "STOPPED", "TIMED_OUT"];
|
|
35
42
|
/** The shortest limit a read of a run gets near the deadline: it outlives the deadline by this much at most. */
|
|
36
43
|
const MIN_READ_MS = 100;
|
|
44
|
+
/** How many inspects a save has out at once. */
|
|
45
|
+
const INSPECTS_AT_ONCE = 8;
|
|
46
|
+
/** A save's read of the listing or an inspect, refused for the rate (429) or failed by monid (5xx), is read again after
|
|
47
|
+
* what monid says to wait (Retry-After, 2 s when it says nothing, at most READ_WAIT_MS), READ_TRIES times in all. */
|
|
48
|
+
const READ_TRIES = 4;
|
|
49
|
+
const READ_WAIT_MS = 10_000;
|
|
37
50
|
/** On an answer monid charged nothing for: the run never ran (refused as sent), was blocked or stopped, or the provider
|
|
38
51
|
* failed. A symbol, so the model never reads it. */
|
|
39
52
|
const UNCHARGED = Symbol("monid.uncharged");
|
|
40
|
-
const uncharged = (answer) => Object.assign(answer, { [UNCHARGED]: true });
|
|
53
|
+
export const uncharged = (answer) => Object.assign(answer, { [UNCHARGED]: true });
|
|
41
54
|
const pause = (ms, signal) => new Promise((resolve) => {
|
|
42
55
|
const timer = setTimeout(resolve, ms);
|
|
43
56
|
signal?.addEventListener("abort", () => (clearTimeout(timer), resolve()), { once: true });
|
|
@@ -83,14 +96,14 @@ function outcome(status, record) {
|
|
|
83
96
|
/** What a run's answer says monid charged, in USD: its cost; else undefined when monid charged nothing (UNCHARGED), and
|
|
84
97
|
* null for every other answer, which may have been charged (one with no cost, FAILED, TIMED_OUT, a run stopped by its
|
|
85
98
|
* caller or the wait, a run whose sending failed): never $0 for a charge no one knows, and counted by the cap at what
|
|
86
|
-
* the run was held at (
|
|
99
|
+
* the run was held at (paidStep). A cost in another currency is unknown too. */
|
|
87
100
|
export function chargeOf(answer) {
|
|
88
101
|
const cost = money(answer.cost);
|
|
89
102
|
if (cost)
|
|
90
103
|
return cost.currency === "USD" ? cost.value : null;
|
|
91
104
|
return answer[UNCHARGED] ? undefined : null;
|
|
92
105
|
}
|
|
93
|
-
/** monid's
|
|
106
|
+
/** monid's calls on `key`, each answering what its caller reads, never throwing. */
|
|
94
107
|
export function monidClient(options) {
|
|
95
108
|
const { key, requestMs = 30_000, pollMs = 2_000, waitMs = 150_000, sleep = pause } = options;
|
|
96
109
|
const send = options.fetch ?? fetch;
|
|
@@ -105,26 +118,38 @@ export function monidClient(options) {
|
|
|
105
118
|
catch {
|
|
106
119
|
return undefined;
|
|
107
120
|
} })();
|
|
108
|
-
|
|
121
|
+
const retryAfter = Number(res.headers?.get?.("retry-after") ?? NaN);
|
|
122
|
+
return { status: res.status, body: isObject(json) ? json : { message: text.slice(0, 500) }, ...(retryAfter >= 0 ? { retryAfter } : {}) };
|
|
109
123
|
}
|
|
110
124
|
catch (error) {
|
|
111
125
|
return { status: 0, body: { message: signal?.aborted ? "stopped by the caller" : limit.aborted ? `no answer in ${ms / 1000} s` : String(error?.message ?? error) } };
|
|
112
126
|
}
|
|
113
127
|
};
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
128
|
+
const answer = (res) => (res.status >= 200 && res.status < 300 ? res.body : failure(res.status, res.body));
|
|
129
|
+
/** A save's read, safe to repeat (READ_TRIES). */
|
|
130
|
+
const read = async (method, path, body, signal) => {
|
|
131
|
+
for (let tries = 1;; tries++) {
|
|
132
|
+
const res = await call(method, path, body, signal);
|
|
133
|
+
if ((res.status !== 429 && res.status < 500) || tries >= READ_TRIES || signal?.aborted)
|
|
134
|
+
return res;
|
|
135
|
+
await sleep(Math.min(READ_WAIT_MS, (res.retryAfter ?? 2) * 1000), signal);
|
|
136
|
+
}
|
|
117
137
|
};
|
|
118
138
|
const stop = async (runId, why) => {
|
|
119
139
|
const res = await call("POST", `/v1/runs/${encodeURIComponent(runId)}/stop`, undefined, undefined, 10_000);
|
|
120
140
|
return { error: `the run ${why}; ${res.status === 202 ? "monid was asked to stop it" : `monid refused to stop it (${res.status || "no answer"})`}, and a metered endpoint bills what it used before the stop`, runId };
|
|
121
141
|
};
|
|
122
142
|
return {
|
|
123
|
-
|
|
124
|
-
|
|
143
|
+
/** One page of monid's listing (GET /v1/endpoints): `items`, and `cursor` for the next page when there is one. */
|
|
144
|
+
endpoints: async (cursor, signal) => answer(await read("GET", `/v1/endpoints?limit=100${cursor ? `&cursor=${encodeURIComponent(cursor)}` : ""}`, undefined, signal)),
|
|
145
|
+
inspect: async (args, signal) => answer(await read("POST", "/v1/inspect", args, signal)),
|
|
146
|
+
/** One run, `maxCost` its most in USD when given: monid refuses a run whose estimate is above it, unrun and
|
|
147
|
+
* uncharged (400 MAX_COST_EXCEEDED). It is sent in whole micro-dollars (monid takes at most 6 decimals), rounded
|
|
148
|
+
* down, so it never allows more than given. */
|
|
125
149
|
async run(args, signal) {
|
|
126
150
|
const deadline = Date.now() + waitMs;
|
|
127
|
-
const
|
|
151
|
+
const maxCost = args.maxCost === undefined ? {} : { maxCost: Math.floor(args.maxCost * 1e6 + 1e-6) / 1e6 };
|
|
152
|
+
const first = await call("POST", "/v1/run", { provider: args.provider, endpoint: args.endpoint, input: args.input ?? {}, ...maxCost }, signal, waitMs);
|
|
128
153
|
if (first.status === 0)
|
|
129
154
|
return { error: `${first.body.message}: the run may have gone ahead at monid, and is not sent again` };
|
|
130
155
|
if (first.status !== 202 || typeof first.body.runId !== "string")
|
|
@@ -171,118 +196,179 @@ export async function monidText(answer, work, label) {
|
|
|
171
196
|
}
|
|
172
197
|
return `${cut}the whole answer is in the run's files at evidence/monid/${name}]`;
|
|
173
198
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
199
|
+
/** The fixed USD price of one call priced `price` (monid's listing): a per-call amount; the dearest variant of a matrix
|
|
200
|
+
* of fixed prices; a tiered price's default and every tier added up (tiers add, so all of them is the most one call
|
|
201
|
+
* can be charged). Undefined for a price by usage, or one in another currency. */
|
|
202
|
+
function fixedUsd(price) {
|
|
203
|
+
if (!isObject(price))
|
|
204
|
+
return undefined;
|
|
205
|
+
const of = (parts) => (parts.every((part) => fixedUsd(part) !== undefined) ? parts.map((part) => fixedUsd(part)) : undefined);
|
|
206
|
+
if (price.type === "PER_CALL") {
|
|
207
|
+
const amount = money(price.amount);
|
|
208
|
+
return amount?.currency === "USD" && amount.value >= 0 ? amount.value : undefined;
|
|
209
|
+
}
|
|
210
|
+
const variants = Array.isArray(price.variants) ? of(price.variants.map((variant) => (isObject(variant) ? variant.price : undefined))) : undefined;
|
|
211
|
+
if (price.type === "PER_UNIT_MATRIX")
|
|
212
|
+
return variants?.length ? Math.max(...variants) : undefined;
|
|
213
|
+
if (price.type === "TIERED" && Array.isArray(price.tiers)) {
|
|
214
|
+
const parts = of([...(price.default === undefined ? [] : [price.default]), ...price.tiers.map((tier) => (isObject(tier) ? tier.price : undefined))]);
|
|
215
|
+
return parts?.reduce((sum, usd) => sum + usd, 0);
|
|
216
|
+
}
|
|
217
|
+
return undefined;
|
|
218
|
+
}
|
|
219
|
+
/** What one call of an endpoint priced `price` is held at: its fixed price (fixedUsd); undefined when it has none, an
|
|
220
|
+
* endpoint no hold can keep a cap for (unboundedWords). */
|
|
221
|
+
export const heldOf = (price) => fixedUsd(price);
|
|
222
|
+
/** How monid prices `price`, in words: "per result (PER_RESULT)", "per 1 credit (PER_UNIT)". monid states every price
|
|
223
|
+
* in USD (its API reference). */
|
|
224
|
+
export function priceWords(price) {
|
|
225
|
+
if (!isObject(price))
|
|
226
|
+
return "with no stated price";
|
|
227
|
+
const type = typeof price.type === "string" ? price.type : "of no type";
|
|
228
|
+
if (type === "PER_RESULT")
|
|
229
|
+
return `per result (${type})`;
|
|
230
|
+
if (type === "PER_UNIT" && typeof price.unit === "string")
|
|
231
|
+
return `per ${typeof price.per === "number" ? price.per : 1} ${price.unit} (${type})`;
|
|
232
|
+
if (type === "METERED")
|
|
233
|
+
return `by metered use (${type})`;
|
|
234
|
+
if (type === "TIERED" || type === "PER_UNIT_MATRIX")
|
|
235
|
+
return `partly by usage (${type})`;
|
|
236
|
+
return `by usage (${type})`;
|
|
237
|
+
}
|
|
238
|
+
/** Why the endpoint `tool`, priced `price` (no fixed USD price: heldOf is undefined), cannot be granted. */
|
|
239
|
+
export const unboundedWords = (tool, price) => `${tool} cannot be granted: monid prices it ${priceWords(price)}, so what one call costs is known only after it has run, and monid does not bound it (a run's maxCost checks only monid's estimate, which a call priced by usage can pass). A run's cap could not be kept: grant endpoints monid prices per call.`;
|
|
240
|
+
/** `schema` moved from a document's root to the JSON pointer `at`: each local reference to a place in it (`#`, `#/…`)
|
|
241
|
+
* rebased onto `at`, so `#/$defs/Person` reads `#/properties/body/$defs/Person`. A schema with its own `$id` is a
|
|
242
|
+
* resource of its own, whose local references resolve inside it: it and all under it are left as they are. A keyword
|
|
243
|
+
* whose value is data (VALUE_KEYWORDS: `const`, `enum`, ...) is left as it is, a `$ref` in it being part of a value the
|
|
244
|
+
* endpoint takes; under a keyword that maps names to schemas (NAMED_SCHEMAS: `properties`, `$defs`, ...), each name is
|
|
245
|
+
* a name, never a keyword, and each schema under it is walked. */
|
|
246
|
+
const rebased = (schema, at) => {
|
|
247
|
+
if (Array.isArray(schema))
|
|
248
|
+
return schema.map((item) => rebased(item, at));
|
|
249
|
+
if (!isObject(schema) || typeof schema.$id === "string")
|
|
250
|
+
return schema;
|
|
251
|
+
return Object.fromEntries(Object.entries(schema).map(([key, value]) => {
|
|
252
|
+
if (key === "$ref" && typeof value === "string" && (value === "#" || value.startsWith("#/")))
|
|
253
|
+
return [key, `#${at}${value.slice(1)}`];
|
|
254
|
+
if (VALUE_KEYWORDS.has(key))
|
|
255
|
+
return [key, value];
|
|
256
|
+
if (NAMED_SCHEMAS.has(key) && isObject(value))
|
|
257
|
+
return [key, Object.fromEntries(Object.entries(value).map(([name, sub]) => [name, rebased(sub, at)]))];
|
|
258
|
+
return [key, rebased(value, at)];
|
|
259
|
+
}));
|
|
214
260
|
};
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
*
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
}
|
|
245
|
-
const answer = await call();
|
|
246
|
-
// Settled at what it charged: $0 only when monid charged nothing, null (unknown) when it may have and did not say.
|
|
247
|
-
// Paid for, it answers even when this cannot be written, never a failure the model would retry.
|
|
248
|
-
const usd = chargeOf(answer);
|
|
249
|
-
const settle = { ...label, usd: usd === undefined ? 0 : usd };
|
|
250
|
-
await record(api, TOOL_COST, settle, context).catch(() => undefined);
|
|
251
|
-
return answer;
|
|
252
|
-
};
|
|
253
|
-
// On the runner's one ledger (paid-calls.ts Ledger.paid): held there at the same figure and settled at the same charge
|
|
254
|
-
// ($0 when monid charged nothing, at its hold when it may have and did not say), in place of this process's spend.
|
|
255
|
-
const onLedger = kind === "run" ? paidLedger() : undefined;
|
|
256
|
-
const paid = onLedger
|
|
257
|
-
? await paidStep(onLedger, api.callId, { name: RUN, holdUsd: held, basis, by: label.charged_by }, call, (outcome) => {
|
|
258
|
-
if (!("result" in outcome))
|
|
259
|
-
return null;
|
|
260
|
-
const usd = chargeOf(outcome.result);
|
|
261
|
-
return usd === undefined ? 0 : usd;
|
|
262
|
-
})
|
|
263
|
-
: kind === "run" ? await paidCall(RUN, send, chargeOf, { usd: held, basis }) : { result: await call() };
|
|
264
|
-
if ("refused" in paid)
|
|
265
|
-
return forModel(JSON.stringify({ error: paid.refused }), { isError: true });
|
|
266
|
-
const answer = paid.result;
|
|
267
|
-
const price = kind === "inspect" && isObject(answer.price) && answer.price.type === "PER_CALL" ? money(answer.price.amount) : undefined;
|
|
268
|
-
if (price?.currency === "USD")
|
|
269
|
-
quotesOf(env).set(quoteKey(args), price.value);
|
|
270
|
-
const cost = money(answer.cost);
|
|
271
|
-
return forModel(await monidText(answer, work(), kind), { isError: answer.error !== undefined, ...(cost ? { details: { cost } } : {}) });
|
|
272
|
-
},
|
|
261
|
+
/** JSON Schema keywords whose value is data, not a schema. */
|
|
262
|
+
const VALUE_KEYWORDS = new Set(["const", "enum", "default", "examples", "example"]);
|
|
263
|
+
/** JSON Schema keywords whose value maps names to schemas. */
|
|
264
|
+
const NAMED_SCHEMAS = new Set(["properties", "patternProperties", "$defs", "definitions", "dependentSchemas"]);
|
|
265
|
+
/** An endpoint's input schema as one tool's (inspect's `input`: `pathParams`, `queryParams`, `body`, each a JSON
|
|
266
|
+
* Schema): an object of those parts, each required that requires a field, its local references rebased. */
|
|
267
|
+
function inputSchema(input) {
|
|
268
|
+
const parts = isObject(input) ? input : {};
|
|
269
|
+
const properties = {};
|
|
270
|
+
const required = [];
|
|
271
|
+
for (const part of ["pathParams", "queryParams", "body"]) {
|
|
272
|
+
if (!isObject(parts[part]))
|
|
273
|
+
continue;
|
|
274
|
+
const { $schema: _schema, ...schema } = rebased(parts[part], `/properties/${part}`);
|
|
275
|
+
properties[part] = schema;
|
|
276
|
+
if (Array.isArray(schema.required) && schema.required.length)
|
|
277
|
+
required.push(part);
|
|
278
|
+
}
|
|
279
|
+
return { type: "object", additionalProperties: false, properties, ...(required.length ? { required } : {}) };
|
|
280
|
+
}
|
|
281
|
+
/** The monid grants among `grants` pinned against monid's listing on `key` (pinned at a save, never at a run): each
|
|
282
|
+
* provider's wildcard read as the endpoints monid lists for it now (at most MONID_WILDCARD_MAX), each endpoint inspected
|
|
283
|
+
* for its description, input and price. A grant monid lists nothing for is refused, as is every grant when there is no
|
|
284
|
+
* key or monid cannot be read. An endpoint with no fixed price (heldOf) is refused as a named grant, and left out of a
|
|
285
|
+
* wildcard, which is refused when it leaves none. Undefined when no grant is monid's. */
|
|
286
|
+
export async function pinMonid(grants, options) {
|
|
287
|
+
const named = grants.flatMap((tool) => {
|
|
288
|
+
const parsed = parseToolName(tool);
|
|
289
|
+
return parsed?.kind === "monid" || parsed?.kind === "monid-provider" ? [{ tool, parsed }] : [];
|
|
273
290
|
});
|
|
291
|
+
if (!named.length)
|
|
292
|
+
return undefined;
|
|
293
|
+
if (!options.key)
|
|
294
|
+
return { refused: named.map(({ tool }) => ({ tool, message: `${tool} is pinned to what monid lists when the agent is saved, and there is no monid key here to read it with: save the monid key in Settings → Tool keys first.` })) };
|
|
295
|
+
const client = monidClient({ key: options.key, ...(options.fetch ? { fetch: options.fetch } : {}), ...(options.sleep ? { sleep: options.sleep } : {}) });
|
|
296
|
+
// monid's own words, which a save's refusal returns to its caller: the key they were read with cut from them, in
|
|
297
|
+
// every form a run's error is redacted of (key-refusal.ts redacted).
|
|
298
|
+
const key = options.key;
|
|
299
|
+
const said = (error) => redacted(String(error), [key]);
|
|
300
|
+
const refused = [];
|
|
301
|
+
// Each endpoint to pin, by catalog name: the grants' own, then each wildcard's provider's as monid lists them, with
|
|
302
|
+
// the wildcard (`from`) when no grant names it.
|
|
303
|
+
const wanted = new Map();
|
|
304
|
+
const providers = new Set(named.flatMap(({ parsed }) => (parsed.kind === "monid-provider" ? [parsed.provider] : [])));
|
|
305
|
+
if (providers.size) {
|
|
306
|
+
const listed = new Map();
|
|
307
|
+
// Every page, a bounded number of them: monid's listing is not filtered by provider.
|
|
308
|
+
for (let cursor, page = 0; (page === 0 || cursor) && page < 500; page++) {
|
|
309
|
+
const res = await client.endpoints(cursor, options.signal);
|
|
310
|
+
if (res.error !== undefined)
|
|
311
|
+
return { refused: named.map(({ tool }) => ({ tool, message: `${tool} could not be pinned: monid's listing could not be read (${said(res.error)}).` })) };
|
|
312
|
+
for (const item of Array.isArray(res.items) ? res.items : []) {
|
|
313
|
+
if (isObject(item) && typeof item.provider === "string" && typeof item.endpoint === "string" && providers.has(item.provider))
|
|
314
|
+
listed.set(item.provider, [...(listed.get(item.provider) ?? []), item.endpoint]);
|
|
315
|
+
}
|
|
316
|
+
cursor = typeof res.cursor === "string" && res.cursor ? res.cursor : undefined;
|
|
317
|
+
}
|
|
318
|
+
for (const { tool, parsed } of named) {
|
|
319
|
+
if (parsed.kind !== "monid-provider")
|
|
320
|
+
continue;
|
|
321
|
+
const endpoints = listed.get(parsed.provider) ?? [];
|
|
322
|
+
if (!endpoints.length)
|
|
323
|
+
refused.push({ tool, message: `monid lists no endpoint of a provider ${parsed.provider}.` });
|
|
324
|
+
else if (endpoints.length > MONID_WILDCARD_MAX)
|
|
325
|
+
refused.push({ tool, message: `monid lists ${endpoints.length} endpoints of ${parsed.provider}, more than the ${MONID_WILDCARD_MAX} one grant may pin: grant its endpoints by name, monid:${parsed.provider}/<endpoint>.` });
|
|
326
|
+
else
|
|
327
|
+
for (const path of endpoints)
|
|
328
|
+
wanted.set(formatToolName({ kind: "monid", provider: parsed.provider, endpoint: path.replace(/^\//, "") }), { provider: parsed.provider, endpoint: path, from: tool });
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
for (const { tool, parsed } of named)
|
|
332
|
+
if (parsed.kind === "monid")
|
|
333
|
+
wanted.set(tool, { provider: parsed.provider, endpoint: `/${parsed.endpoint}` });
|
|
334
|
+
// Each endpoint inspected, INSPECTS_AT_ONCE at a time.
|
|
335
|
+
const pin = {};
|
|
336
|
+
const leftOut = [];
|
|
337
|
+
const queue = [...wanted];
|
|
338
|
+
const inspectOne = async () => {
|
|
339
|
+
for (let next = queue.shift(); next; next = queue.shift()) {
|
|
340
|
+
const [tool, at] = next;
|
|
341
|
+
const res = await client.inspect(at, options.signal);
|
|
342
|
+
const usd = heldOf(res.price);
|
|
343
|
+
if (res.status === 404)
|
|
344
|
+
refused.push({ tool, message: `monid lists no endpoint ${at.endpoint} of a provider ${at.provider}.` });
|
|
345
|
+
else if (res.error !== undefined)
|
|
346
|
+
refused.push({ tool, message: `${tool} could not be pinned: monid's listing of it could not be read (${said(res.error)}).` });
|
|
347
|
+
else if (usd === undefined && at.from)
|
|
348
|
+
leftOut.push({ tool: at.from, endpoint: tool, message: `${tool} is left out of ${at.from}: ${unboundedWords(tool, res.price)}` });
|
|
349
|
+
else if (usd === undefined)
|
|
350
|
+
refused.push({ tool, message: unboundedWords(tool, res.price) });
|
|
351
|
+
else
|
|
352
|
+
pin[tool] = { description: [res.description, res.summary].find((said) => typeof said === "string" && said.trim() !== "")?.trim() ?? `${at.provider} ${at.endpoint}, an endpoint of monid's.`, input: inputSchema(res.input), usd };
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
await Promise.all(Array.from({ length: Math.min(INSPECTS_AT_ONCE, queue.length) }, inspectOne));
|
|
356
|
+
leftOut.sort((a, b) => (a.endpoint < b.endpoint ? -1 : a.endpoint > b.endpoint ? 1 : 0));
|
|
357
|
+
// A wildcard whose every endpoint was left out pins nothing: refused, with why for each.
|
|
358
|
+
for (const { tool, parsed } of named) {
|
|
359
|
+
if (parsed.kind !== "monid-provider" || refused.some((one) => one.tool === tool))
|
|
360
|
+
continue;
|
|
361
|
+
const left = leftOut.filter((one) => one.tool === tool);
|
|
362
|
+
if (left.length && !Object.keys(pin).some((endpoint) => wanted.get(endpoint)?.provider === parsed.provider))
|
|
363
|
+
refused.push({ tool, message: `${tool} pins nothing: every endpoint monid lists of ${parsed.provider} is priced by usage. ${left.map((one) => one.message).join(" ")}` });
|
|
364
|
+
}
|
|
365
|
+
// Two endpoints the harnesses would call by one name (wireName folds `.` and `/`): neither could be told apart.
|
|
366
|
+
const wires = new Map();
|
|
367
|
+
for (const tool of Object.keys(pin).sort()) {
|
|
368
|
+
const other = wires.get(wireName(tool));
|
|
369
|
+
if (other)
|
|
370
|
+
refused.push({ tool, message: `${tool} and ${other} are called by one name on every harness (${wireName(tool)}): grant one of them by name.` });
|
|
371
|
+
wires.set(wireName(tool), tool);
|
|
372
|
+
}
|
|
373
|
+
return refused.length ? { refused } : { pin: Object.fromEntries(Object.keys(pin).sort().map((tool) => [tool, pin[tool]])), leftOut: leftOut.map(({ tool, message }) => ({ tool, message })) };
|
|
274
374
|
}
|
|
275
|
-
/** The table's entry for `monid.<kind>`: it needs MONID_API_KEY, and no workflow node names it yet. */
|
|
276
|
-
export const monidTool = (kind) => ({
|
|
277
|
-
summary: SPECS[kind].summary,
|
|
278
|
-
needs: [MONID_KEY_ENV],
|
|
279
|
-
nodes: false,
|
|
280
|
-
bind: async (host) => {
|
|
281
|
-
// An answer too long for the model is filed in the run's own Workspace (in Mode 2, on the run's disk, where its read
|
|
282
|
-
// looks), else in the local folder the run works in.
|
|
283
|
-
const tool = monidRegistration(kind, host.env, () => host.workspace ?? localWorkspace(host.where.work));
|
|
284
|
-
const extension = defineExtension({ name: `monid-${kind}`, tools: [tool] });
|
|
285
|
-
host.install(extension);
|
|
286
|
-
return { tools: [tool], extensions: [extension] };
|
|
287
|
-
},
|
|
288
|
-
});
|