@parcha/agentrun-serve 0.1.0-beta.58 → 0.1.0-beta.60
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 +402 -1
- package/README.md +516 -190
- package/dist/acp-package.d.ts +5 -1
- package/dist/acp-package.js +19 -2
- package/dist/adapters.d.ts +23 -2
- package/dist/adapters.js +106 -33
- package/dist/agent-delete.d.ts +6 -9
- package/dist/agent-delete.js +5 -3
- package/dist/agent-package.js +11 -1
- package/dist/agents-store.js +1 -1
- package/dist/answer-text.d.ts +3 -0
- package/dist/answer-text.js +22 -0
- package/dist/api-only.d.ts +2 -2
- package/dist/api-only.js +3 -3
- package/dist/archil-routes.d.ts +4 -1
- package/dist/archil-routes.js +15 -12
- package/dist/archil-settings.d.ts +18 -8
- package/dist/archil-settings.js +35 -17
- package/dist/attach-conformance.js +5 -4
- package/dist/box-paths.d.ts +3 -2
- package/dist/box-paths.js +5 -4
- package/dist/browser-computer.d.ts +3 -8
- package/dist/browser-computer.js +12 -35
- package/dist/browser-cost.js +94 -20
- package/dist/capacity.d.ts +1 -1
- package/dist/capacity.js +3 -3
- package/dist/chatgpt-plan.d.ts +7 -0
- package/dist/chatgpt-plan.js +35 -11
- package/dist/claude-login-token.d.ts +20 -11
- package/dist/claude-login-token.js +175 -107
- package/dist/claude-login.d.ts +124 -33
- package/dist/claude-login.js +562 -85
- package/dist/claude-sign-in.d.ts +3 -0
- package/dist/claude-sign-in.js +10 -1
- package/dist/cli-learning/connections.js +1 -1
- package/dist/cli.js +323 -292
- package/dist/composio-made.d.ts +1 -6
- package/dist/composio-made.js +1 -6
- package/dist/composio-owners.d.ts +26 -0
- package/dist/composio-owners.js +36 -0
- package/dist/composio-preset.d.ts +56 -23
- package/dist/composio-preset.js +173 -77
- package/dist/composio-triggers.d.ts +4 -4
- package/dist/composio-triggers.js +6 -7
- package/dist/compute-cost.js +11 -2
- package/dist/computer-attach.d.ts +6 -3
- package/dist/computer-attach.js +41 -29
- package/dist/computer-held-routes.d.ts +1 -1
- package/dist/computer-held-routes.js +9 -4
- package/dist/computer-keys.d.ts +11 -1
- package/dist/computer-keys.js +26 -1
- package/dist/computer-record.js +3 -1
- package/dist/computer-view.d.ts +5 -3
- package/dist/computer-view.js +10 -6
- package/dist/computer-viewer.js +36 -7
- package/dist/computers.d.ts +2 -1
- package/dist/computers.js +6 -3
- package/dist/console/THIRD-PARTY-NOTICES.txt +50 -0
- package/dist/console/assets/backend-QnwGVBeU.js +166 -0
- package/dist/console/assets/index-DZi-muIj.js +629 -0
- package/dist/console/assets/share-pz61zIn9.js +6 -0
- package/dist/console/assets/styles-CcceGcu2.js +291 -0
- package/dist/console/assets/styles-fjQBFfMv.css +1 -0
- package/dist/console/index.html +4 -3
- package/dist/console/share.html +17 -0
- package/dist/decisions.d.ts +17 -7
- package/dist/decisions.js +41 -15
- package/dist/dial-relay.js +10 -4
- package/dist/docker-daemon.js +4 -5
- package/dist/docker-host-addresses.js +29 -11
- package/dist/email/account.d.ts +6 -0
- package/dist/email/account.js +6 -0
- package/dist/email/authentication.d.ts +21 -0
- package/dist/email/authentication.js +106 -0
- package/dist/email/email-faux.d.ts +11 -2
- package/dist/email/email-faux.js +21 -5
- package/dist/email/mail.d.ts +25 -0
- package/dist/email/mail.js +58 -2
- package/dist/email/names.js +2 -2
- package/dist/email/tools.d.ts +9 -4
- package/dist/email/tools.js +95 -13
- package/dist/env-switch.d.ts +12 -2
- package/dist/env-switch.js +23 -3
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +2 -0
- package/dist/factory-activity.d.ts +68 -0
- package/dist/factory-activity.js +153 -0
- package/dist/factory-runs.d.ts +11 -0
- package/dist/factory-runs.js +52 -0
- package/dist/fal-price.d.ts +11 -1
- package/dist/fal-price.js +33 -0
- package/dist/faux-computers.js +1 -1
- package/dist/filed-answer.d.ts +2 -2
- package/dist/filed-answer.js +2 -2
- package/dist/filed-tool.d.ts +32 -0
- package/dist/filed-tool.js +122 -0
- package/dist/graph-served.d.ts +10 -5
- package/dist/graph-served.js +40 -10
- package/dist/handed-values.js +1 -2
- package/dist/harness-check.d.ts +2 -1
- package/dist/harness-check.js +45 -12
- package/dist/harness-keys.d.ts +1 -2
- package/dist/harness-keys.js +10 -8
- package/dist/harness-opencode/facts.js +2 -0
- package/dist/harness-recipe-entry.d.ts +9 -3
- package/dist/harness-recipe-entry.js +18 -9
- package/dist/harness-recipe.d.ts +21 -0
- package/dist/harness-recipe.js +25 -3
- package/dist/harness-table.d.ts +12 -0
- package/dist/harness-table.js +21 -6
- package/dist/harness.js +6 -2
- package/dist/helper-env.d.ts +4 -1
- package/dist/helper-env.js +4 -1
- package/dist/host-check.d.ts +2 -3
- package/dist/host-check.js +13 -7
- package/dist/hosted-search.js +1 -1
- package/dist/import-worker.js +2 -2
- package/dist/import.d.ts +20 -8
- package/dist/import.js +448 -187
- package/dist/key-refusal.d.ts +14 -2
- package/dist/key-refusal.js +97 -33
- package/dist/learn/audit.d.ts +28 -27
- package/dist/learn/audit.js +87 -62
- package/dist/learn/check.js +1 -1
- package/dist/learn/commit.d.ts +35 -43
- package/dist/learn/commit.js +62 -270
- package/dist/learn/compile.d.ts +9 -6
- package/dist/learn/compile.js +51 -28
- package/dist/learn/corrections.js +1 -1
- package/dist/learn/delete.d.ts +5 -12
- package/dist/learn/delete.js +17 -30
- package/dist/learn/field-check.d.ts +111 -0
- package/dist/learn/field-check.js +174 -0
- package/dist/learn/forget-run.d.ts +16 -0
- package/dist/learn/forget-run.js +53 -0
- package/dist/learn/index.js +1 -1
- package/dist/learn/learning-of.d.ts +0 -4
- package/dist/learn/learning-of.js +0 -5
- package/dist/learn/ledger.d.ts +32 -29
- package/dist/learn/ledger.js +26 -19
- package/dist/learn/{folder.d.ts → legacy/folder.d.ts} +2 -1
- package/dist/learn/{folder.js → legacy/folder.js} +4 -7
- package/dist/learn/legacy/place.d.ts +16 -0
- package/dist/{workspace/learning-workspace.js → learn/legacy/place.js} +12 -42
- package/dist/learn/legacy/scrub.d.ts +28 -0
- package/dist/learn/legacy/scrub.js +258 -0
- package/dist/learn/promote.d.ts +119 -102
- package/dist/learn/promote.js +119 -262
- package/dist/learn/reset-ledger.d.ts +18 -0
- package/dist/learn/reset-ledger.js +14 -0
- package/dist/learn/rows.d.ts +186 -0
- package/dist/learn/rows.js +376 -0
- package/dist/learn/secrets.d.ts +4 -0
- package/dist/learn/secrets.js +12 -0
- package/dist/learn/workflow-draft.d.ts +4 -1
- package/dist/learn/workflow-draft.js +12 -2
- package/dist/learned-nodes.d.ts +8 -5
- package/dist/learned-nodes.js +8 -5
- package/dist/learned-workflow.d.ts +2 -1
- package/dist/learned-workflow.js +13 -10
- package/dist/learning-cost.d.ts +25 -8
- package/dist/learning-cost.js +23 -8
- package/dist/learning-reset.d.ts +1 -1
- package/dist/learning-reset.js +9 -11
- package/dist/learning-routes.d.ts +60 -81
- package/dist/learning-routes.js +187 -360
- package/dist/learning-setting.d.ts +6 -0
- package/dist/learning-setting.js +11 -1
- package/dist/learning-words.d.ts +2 -0
- package/dist/learning-words.js +2 -0
- package/dist/learning.d.ts +18 -24
- package/dist/learning.js +35 -66
- package/dist/listen-first.d.ts +5 -4
- package/dist/listen-first.js +4 -5
- package/dist/live-reach.d.ts +7 -0
- package/dist/live-reach.js +7 -0
- package/dist/mcp-api-only-origins.d.ts +15 -0
- package/dist/mcp-api-only-origins.js +40 -0
- package/dist/mcp-gateway.d.ts +22 -2
- package/dist/mcp-gateway.js +85 -11
- package/dist/mcp-oauth.d.ts +1 -1
- package/dist/mcp-oauth.js +3 -2
- package/dist/mcp-probe.d.ts +3 -0
- package/dist/mcp-probe.js +3 -0
- package/dist/mcp-resources.d.ts +1 -1
- package/dist/mcp-secret-writes.d.ts +24 -2
- package/dist/mcp-secret-writes.js +30 -2
- package/dist/mcp-servers-store.d.ts +52 -14
- package/dist/mcp-servers-store.js +165 -61
- package/dist/mcp-sources.d.ts +1 -2
- package/dist/mcp-sources.js +1 -2
- package/dist/mcp-store.d.ts +5 -5
- package/dist/mcp-store.js +3 -3
- package/dist/mcp.js +1 -1
- package/dist/model-gateway.d.ts +1 -1
- package/dist/model-gateway.js +20 -36
- package/dist/native/discovery.d.ts +6 -0
- package/dist/native/discovery.js +14 -1
- package/dist/native/remote.d.ts +5 -0
- package/dist/native/remote.js +16 -0
- package/dist/native/runtime.js +3 -2
- package/dist/observation/observer.d.ts +6 -6
- package/dist/ollama-provider.d.ts +23 -9
- package/dist/ollama-provider.js +49 -20
- package/dist/openapi.js +290 -79
- package/dist/otel/genai.d.ts +83 -7
- package/dist/otel/genai.js +69 -9
- package/dist/otel/tracer.d.ts +42 -13
- package/dist/otel/tracer.js +241 -56
- package/dist/page.d.ts +7 -1
- package/dist/page.js +76 -22
- package/dist/paid-calls.d.ts +6 -4
- package/dist/paid-calls.js +15 -7
- package/dist/place-offers.d.ts +58 -34
- package/dist/place-offers.js +96 -54
- package/dist/place.d.ts +41 -20
- package/dist/place.js +97 -47
- package/dist/print.js +1 -1
- package/dist/provider.d.ts +3 -2
- package/dist/provider.js +17 -8
- package/dist/purged-workflow.d.ts +0 -33
- package/dist/purged-workflow.js +3 -71
- package/dist/redact/match.d.ts +42 -9
- package/dist/redact/match.js +356 -54
- package/dist/run-census.d.ts +1 -1
- package/dist/run-census.js +4 -5
- package/dist/run-cut.js +4 -5
- package/dist/run-export-store.d.ts +15 -0
- package/dist/run-export-store.js +30 -0
- package/dist/run-export.d.ts +139 -0
- package/dist/run-export.js +379 -0
- package/dist/run-file-cut.d.ts +5 -0
- package/dist/run-file-cut.js +13 -0
- package/dist/run-launch.d.ts +3 -3
- package/dist/run-launch.js +16 -3
- package/dist/run-learning-served.d.ts +3 -3
- package/dist/run-learning-served.js +1 -1
- package/dist/run-listing.d.ts +1 -1
- package/dist/run-model-key.d.ts +15 -6
- package/dist/run-model-key.js +30 -31
- package/dist/run-reads-over-store.js +4 -4
- package/dist/run-secrets.js +3 -5
- package/dist/run-timeline-served.d.ts +1 -1
- package/dist/run-timeline-served.js +8 -5
- package/dist/runnable.js +26 -9
- package/dist/runner/adapter-loop.d.ts +35 -18
- package/dist/runner/adapter-loop.js +94 -47
- package/dist/runner/adapter-run-spec.d.ts +14 -1
- package/dist/runner/adapter-run-spec.js +73 -46
- package/dist/runner/adapters/pi.js +4 -2
- package/dist/runner/audit.d.ts +10 -9
- package/dist/runner/audit.js +64 -67
- package/dist/runner/beside.js +5 -6
- package/dist/runner/claim-secrets.d.ts +10 -3
- package/dist/runner/claim-secrets.js +29 -13
- package/dist/runner/cli-run-spec.d.ts +18 -0
- package/dist/runner/cli-run-spec.js +87 -58
- package/dist/runner/compare-end.d.ts +2 -3
- package/dist/runner/compare-end.js +30 -11
- package/dist/runner/conformance/harness.js +2 -3
- package/dist/runner/conformance/subject.d.ts +4 -1
- package/dist/runner/disk-free.d.ts +15 -4
- package/dist/runner/disk-free.js +25 -7
- package/dist/runner/feedback-round.d.ts +1 -1
- package/dist/runner/feedback-round.js +2 -2
- package/dist/runner/harness-loops.js +3 -4
- package/dist/runner/held.d.ts +5 -12
- package/dist/runner/held.js +0 -25
- package/dist/runner/journal-kinds.d.ts +8 -2
- package/dist/runner/journal-kinds.js +23 -5
- package/dist/runner/learned-first.d.ts +0 -2
- package/dist/runner/learned-first.js +23 -7
- package/dist/runner/learning-end.d.ts +14 -24
- package/dist/runner/learning-end.js +52 -94
- package/dist/runner/learning-seed.d.ts +13 -16
- package/dist/runner/learning-seed.js +13 -23
- package/dist/runner/live-ticker.js +7 -5
- package/dist/runner/loop-contract.d.ts +0 -2
- package/dist/runner/loop.d.ts +7 -0
- package/dist/runner/loop.js +1 -0
- package/dist/runner/main.js +13 -12
- package/dist/runner/mcp-claim.js +21 -5
- package/dist/runner/mcp-run.d.ts +4 -0
- package/dist/runner/mcp-run.js +2 -0
- package/dist/runner/meta-tools.js +3 -2
- package/dist/runner/metrics.d.ts +7 -0
- package/dist/runner/metrics.js +19 -0
- package/dist/runner/model-route.d.ts +10 -7
- package/dist/runner/model-route.js +79 -15
- package/dist/runner/native-loop.js +12 -11
- package/dist/runner/presence.d.ts +1 -4
- package/dist/runner/presence.js +6 -8
- package/dist/runner/promotion.d.ts +39 -36
- package/dist/runner/promotion.js +168 -112
- package/dist/runner/redact.d.ts +3 -1
- package/dist/runner/redact.js +5 -3
- package/dist/runner/reflect-hook.d.ts +2 -2
- package/dist/runner/reflect-hook.js +4 -1
- package/dist/runner/responses-fetch.d.ts +36 -0
- package/dist/runner/responses-fetch.js +511 -0
- package/dist/runner/run-child-host.d.ts +21 -14
- package/dist/runner/run-child-host.js +187 -141
- package/dist/runner/run-child.js +11 -4
- package/dist/runner/runner-check.js +5 -1
- package/dist/runner/runner.d.ts +3 -4
- package/dist/runner/runner.js +13 -9
- package/dist/runner/sdk-loop.js +10 -12
- package/dist/runner/spec-holds.d.ts +8 -1
- package/dist/runner/spec-holds.js +9 -4
- package/dist/runner/workflow-calls.d.ts +9 -0
- package/dist/runner/workflow-calls.js +150 -0
- package/dist/runner/workflow-first.d.ts +120 -32
- package/dist/runner/workflow-first.js +218 -94
- package/dist/runner/workflow-spec.js +1 -1
- package/dist/runs-over-store.js +8 -7
- package/dist/save-once.d.ts +14 -0
- package/dist/save-once.js +31 -0
- package/dist/scrub-command.d.ts +34 -31
- package/dist/scrub-command.js +116 -147
- package/dist/sdk/check.d.ts +1 -4
- package/dist/sdk/check.js +2 -3
- package/dist/sdk/runs.d.ts +26 -7
- package/dist/sdk/runs.js +194 -78
- package/dist/seal-key.js +4 -4
- package/dist/secret-cut.d.ts +3 -0
- package/dist/secret-cut.js +7 -1
- package/dist/secret-rules.d.ts +8 -1
- package/dist/secret-rules.js +482 -53
- package/dist/secrets.d.ts +55 -9
- package/dist/secrets.js +345 -21
- package/dist/server-fs.d.ts +1 -1
- package/dist/server-fs.js +1 -1
- package/dist/server-keys.d.ts +10 -3
- package/dist/server-keys.js +16 -3
- package/dist/server-secrets-store.js +2 -4
- package/dist/server.d.ts +30 -18
- package/dist/server.js +520 -238
- package/dist/share-context.d.ts +22 -0
- package/dist/share-context.js +76 -0
- package/dist/shell-lex.d.ts +105 -0
- package/dist/shell-lex.js +646 -0
- package/dist/sign-ins-store.d.ts +5 -7
- package/dist/sign-ins-store.js +12 -16
- package/dist/sign-ins.d.ts +7 -11
- package/dist/sign-ins.js +40 -41
- package/dist/skills/agentrun-serve/SKILL.md +5 -2
- package/dist/source-sync/auxiliary.js +2 -2
- package/dist/start-switches.d.ts +6 -5
- package/dist/start-switches.js +8 -4
- package/dist/stats.d.ts +5 -1
- package/dist/stats.js +1 -1
- package/dist/store/agent-body.js +2 -2
- package/dist/store/dialect.d.ts +4 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/mcp-record-keys.d.ts +10 -0
- package/dist/store/mcp-record-keys.js +13 -0
- package/dist/store/postgres/dialect.js +2 -0
- package/dist/store/postgres/migrations/0029_run_launch_census_settle.sql +28 -0
- package/dist/store/postgres/migrations/0030_learning_ledger_epoch.sql +40 -0
- package/dist/store/postgres/migrations/0031_learning_ledger_calls.sql +12 -0
- package/dist/store/postgres/migrations/0032_learning_rows.sql +65 -0
- package/dist/store/postgres/store.js +4 -0
- package/dist/store/schema.d.ts +60 -11
- package/dist/store/schema.js +147 -17
- package/dist/store/seal.d.ts +4 -1
- package/dist/store/sqlite/learning-rows.d.ts +23 -0
- package/dist/store/sqlite/learning-rows.js +559 -0
- package/dist/store/sqlite/run-launch.d.ts +3 -10
- package/dist/store/sqlite/run-launch.js +12 -23
- package/dist/store/sqlite/run-patch.d.ts +17 -10
- package/dist/store/sqlite/run-patch.js +50 -13
- package/dist/store/sqlite/store.d.ts +9 -0
- package/dist/store/sqlite/store.js +194 -46
- package/dist/store/store-schema.js +3 -4
- package/dist/store/store.d.ts +286 -38
- package/dist/store/store.js +27 -11
- package/dist/store-reads/analytics.d.ts +2 -1
- package/dist/store-reads/analytics.js +7 -5
- package/dist/store-reads/journal.d.ts +33 -3
- package/dist/store-reads/journal.js +99 -4
- package/dist/store-reads/learning.d.ts +50 -45
- package/dist/store-reads/learning.js +153 -116
- package/dist/store-reads/loop.js +1 -1
- package/dist/store-reads/stats.d.ts +2 -2
- package/dist/store-reads/stats.js +13 -7
- package/dist/store-view.d.ts +24 -2
- package/dist/store-view.js +49 -17
- package/dist/suggestions.d.ts +1 -1
- package/dist/suggestions.js +29 -13
- package/dist/template-eval.d.ts +72 -9
- package/dist/template-eval.js +358 -64
- package/dist/templates.d.ts +10 -2
- package/dist/templates.js +31 -4
- package/dist/timeline/labels.d.ts +1 -1
- package/dist/timeline/labels.js +4 -3
- package/dist/timeline/timeline.d.ts +23 -11
- package/dist/timeline/timeline.js +115 -31
- package/dist/timeline/web-calls.d.ts +8 -6
- package/dist/timeline/web-calls.js +10 -6
- package/dist/tool-gate.d.ts +13 -1
- package/dist/tool-gate.js +43 -3
- package/dist/tool-keys-store.js +2 -4
- package/dist/tool-keys.d.ts +11 -0
- package/dist/tool-keys.js +16 -0
- package/dist/tool-plane.d.ts +54 -13
- package/dist/tool-plane.js +103 -32
- package/dist/tools.d.ts +5 -1
- package/dist/tools.js +7 -7
- package/dist/trigger-email.js +12 -6
- package/dist/triggers.d.ts +15 -34
- package/dist/triggers.js +119 -126
- package/dist/validate.d.ts +8 -1
- package/dist/validate.js +163 -23
- package/dist/web-fake.d.ts +2 -1
- package/dist/web-fake.js +8 -6
- package/dist/web-fetch.d.ts +8 -6
- package/dist/web-fetch.js +13 -11
- package/dist/web-holds.d.ts +34 -0
- package/dist/web-holds.js +89 -0
- package/dist/web-run.d.ts +32 -5
- package/dist/web-run.js +76 -28
- package/dist/web-save.js +23 -12
- package/dist/web-search.js +14 -25
- package/dist/wires.d.ts +4 -3
- package/dist/wires.js +5 -4
- package/dist/workspace/archil-claim.d.ts +12 -5
- package/dist/workspace/archil-claim.js +45 -5
- package/dist/workspace/archil-exec.js +1 -1
- package/dist/workspace/archil.d.ts +1 -1
- package/dist/workspace/archil.js +1 -1
- package/dist/workspace/attach.js +52 -19
- package/dist/workspace/attached-computers.d.ts +6 -2
- package/dist/workspace/attached-computers.js +5 -4
- package/dist/workspace/computer-deps.d.ts +23 -6
- package/dist/workspace/computer-deps.js +38 -18
- package/dist/workspace/computer-for-claim.d.ts +21 -4
- package/dist/workspace/computer-for-claim.js +160 -54
- package/dist/workspace/computer-intervals.d.ts +2 -0
- package/dist/workspace/computer-intervals.js +1 -1
- package/dist/workspace/computer-janitor.d.ts +48 -14
- package/dist/workspace/computer-janitor.js +153 -44
- package/dist/workspace/computer-kept.d.ts +158 -32
- package/dist/workspace/computer-kept.js +288 -63
- package/dist/workspace/computer-providers.d.ts +19 -4
- package/dist/workspace/computer-providers.js +40 -6
- package/dist/workspace/index.d.ts +2 -3
- package/dist/workspace/index.js +2 -3
- package/dist/workspace/local.js +41 -1
- package/dist/workspace/mount-revoke-left.d.ts +31 -0
- package/dist/workspace/mount-revoke-left.js +72 -0
- package/dist/workspace/paired-route.js +4 -5
- package/dist/workspace/paths.d.ts +0 -4
- package/dist/workspace/paths.js +0 -6
- package/dist/workspace/resolve-computer.d.ts +5 -2
- package/dist/workspace/resolve-computer.js +9 -3
- package/dist/workspace/run-end-computers.d.ts +11 -5
- package/dist/workspace/run-end-computers.js +153 -28
- package/dist/workspace/run-tools.d.ts +22 -3
- package/dist/workspace/run-tools.js +17 -5
- package/dist/workspace/run-workspace.d.ts +14 -1
- package/dist/workspace/run-workspace.js +34 -1
- package/dist/workspace/workspace.d.ts +7 -1
- package/dist/workspace/workspace.js +1 -1
- package/package.json +13 -14
- package/skills/agentrun-serve/SKILL.md +5 -2
- package/templates/README.md +22 -6
- package/templates/TOOLS.md +46 -0
- package/dist/console/assets/backend-CSAWUqtZ.js +0 -166
- package/dist/console/assets/index-Bwn1oTem.css +0 -1
- package/dist/console/assets/index-DPh29cyz.js +0 -747
- package/dist/workspace/learning-workspace.d.ts +0 -24
- /package/dist/learn/{learning.sh → legacy/learning.sh} +0 -0
package/dist/composio-preset.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
// (`api_key_env`, COMPOSIO_API_KEY only, a secret the launcher hands the server and each runner over its pipe): the server
|
|
9
9
|
// then keeps the name, seals nothing, and reads the value at each use (composio-made.ts composioKeyFromEnv).
|
|
10
10
|
import { randomBytes } from "node:crypto";
|
|
11
|
+
import { textUpTo } from "./answer-text.js";
|
|
11
12
|
import { COMPOSIO_KEY_ENV, COMPOSIO_ORIGIN, composioKeyFromEnv } from "./composio-made.js";
|
|
12
13
|
import { ApiError, invalid } from "./errors.js";
|
|
13
14
|
import { priceValid } from "./mcp-probe.js";
|
|
@@ -18,6 +19,40 @@ const BASE = COMPOSIO_ORIGIN;
|
|
|
18
19
|
const SAVE_FIELDS = ["api_key", "api_key_env", "toolkit", "tools", "user_id", "auth_config_id", "price_usd"];
|
|
19
20
|
/** The one Composio user a server's actions run as, unless the owner names another. */
|
|
20
21
|
export const COMPOSIO_USER = "agentrun";
|
|
22
|
+
/** The namespace an API token's Composio users are kept in at Composio: its save names `ops`, Composio knows
|
|
23
|
+
* `agentrun.token.ops`, which, through this install, only the token's own connect link connects. A fixed prefix,
|
|
24
|
+
* never the token's id: tokens rotate, and every token is one identity in the records. No save names a user_id in
|
|
25
|
+
* it. */
|
|
26
|
+
export const COMPOSIO_TOKEN_USER_PREFIX = "agentrun.token.";
|
|
27
|
+
/** The Composio user an API token's save names `user` as (composioSave `userAs`). */
|
|
28
|
+
export const composioTokenUser = (user) => COMPOSIO_TOKEN_USER_PREFIX + user;
|
|
29
|
+
/** Whether `user` is in the API token's namespace: the prefix exactly as its saves write it, and a user after it. Every
|
|
30
|
+
* listed API token is one principal (api-token.ts), so the prefix is the namespace, not one per token. */
|
|
31
|
+
export const composioTokenNamespaced = (user) => user.startsWith(COMPOSIO_TOKEN_USER_PREFIX) && user.length > COMPOSIO_TOKEN_USER_PREFIX.length;
|
|
32
|
+
/** Why a run's Composio binding on an API-only server can't be used: its user is one the owner's servers call as here
|
|
33
|
+
* (composio-owners.ts ownersComposioUsers). Never names the user or the server. */
|
|
34
|
+
export const COMPOSIO_OWNERS_USER_WORDS = `it is a Composio user this server's owner calls as here (the preset's default user, its tool-listing user, or the user an MCP server the owner saved calls as), and a run's binding on this API-only server never calls as the owner: name a Composio user of the run's own person`;
|
|
35
|
+
/** Whether a connected account Composio answered is `user`'s: only one it names as that user's. One it answers under
|
|
36
|
+
* another user (a Composio answering every user's, whatever user_ids asks), or with no user_id, is never. */
|
|
37
|
+
const accountOf = (user) => (one) => isObject(one) && one.user_id === user;
|
|
38
|
+
/** Whether Composio lists the connected account `account` as an ACTIVE one under `user` for `toolkit`: `listed`,
|
|
39
|
+
* `unlisted` (none, or one started, expired or turned off: only an ACTIVE account calls as its user), or `unbounded`
|
|
40
|
+
* when it lists more ACTIVE ones than the lookup's bound (MAX_PAGES of ACCOUNT_PAGE, as the save's), so it can't be
|
|
41
|
+
* checked. Any failure to read throws (asking): the caller refuses, never assumes. */
|
|
42
|
+
export async function composioListsAccount(ask, user, toolkit, account) {
|
|
43
|
+
let cursor;
|
|
44
|
+
for (let page = 0; page < MAX_PAGES; page++) {
|
|
45
|
+
const listed = await ask("checking the run's connected account", "GET", `/api/v3/connected_accounts?user_ids=${encodeURIComponent(user)}&toolkit_slugs=${encodeURIComponent(toolkit)}&statuses=ACTIVE&limit=${ACCOUNT_PAGE}${cursor ? `&cursor=${encodeURIComponent(cursor)}` : ""}`);
|
|
46
|
+
if ((Array.isArray(listed.items) ? listed.items : []).filter(accountOf(user)).some((one) => one.id === account && one.status === "ACTIVE"))
|
|
47
|
+
return "listed";
|
|
48
|
+
cursor = text(listed.next_cursor) || undefined;
|
|
49
|
+
if (!cursor)
|
|
50
|
+
return "unlisted";
|
|
51
|
+
}
|
|
52
|
+
return "unbounded";
|
|
53
|
+
}
|
|
54
|
+
/** The bound composioListsAccount reads to, in words (a function: the bounds are declared below). */
|
|
55
|
+
export const composioAccountBoundWords = () => `more than ${MAX_PAGES} pages of connected accounts (${ACCOUNT_PAGE} a page)`;
|
|
21
56
|
/** A Composio toolkit's slug, as a save takes it once trimmed and lower-cased. */
|
|
22
57
|
export const COMPOSIO_TOOLKIT = /^[a-z0-9][a-z0-9_-]{0,63}$/;
|
|
23
58
|
const TOOLKIT = COMPOSIO_TOOLKIT;
|
|
@@ -27,7 +62,10 @@ export const COMPOSIO_USER_ID = /^[A-Za-z0-9._@:-]{1,128}$/;
|
|
|
27
62
|
export const COMPOSIO_USER_ID_WORDS = "letters, digits and . _ @ : - (1 to 128)";
|
|
28
63
|
const USER_ID = COMPOSIO_USER_ID;
|
|
29
64
|
/** The `user_id` a save names for a per-run server, reserved for that and never a Composio user: the server keeps no user
|
|
30
|
-
* and no connected account, and each run names its own (mcp_auth.<server> = {composio_user_id, connected_account_id?}).
|
|
65
|
+
* and no connected account, and each run names its own (mcp_auth.<server> = {composio_user_id, connected_account_id?}).
|
|
66
|
+
* The server lends its Composio key to each run's binding, so the API token never binds a user the owner connects here
|
|
67
|
+
* (composio-owners.ts): refused at the request (422) and, for a binding sealed before the owner connected it, at the
|
|
68
|
+
* claim. A user the owner connected directly at Composio, which no record here names, is not refused. */
|
|
31
69
|
export const COMPOSIO_PER_RUN = "per_run";
|
|
32
70
|
/** A Composio connected account's id, as a run's binding names one: Composio's are `ca_` and a short random id. At least
|
|
33
71
|
* 8 characters in all, so the run's redactors (which hold a value of 8 or more) hold every one. */
|
|
@@ -39,39 +77,24 @@ const ADDRESS_ACCOUNT = "connected_account_id";
|
|
|
39
77
|
export const COMPOSIO_AUTH_CONFIG_ID = /^ac_[A-Za-z0-9_-]{1,64}$/;
|
|
40
78
|
const PAGE = 200;
|
|
41
79
|
const MAX_PAGES = 10;
|
|
80
|
+
/** The connected accounts a lookup asks for a page. Composio documents `limit` on GET /api/v3/connected_accounts with no
|
|
81
|
+
* default or maximum; 50 is the page it documents for auth configs, the one such list it bounds. */
|
|
82
|
+
const ACCOUNT_PAGE = 50;
|
|
42
83
|
const MAX_TOOLS = 500;
|
|
43
84
|
/** The longest action slug a save takes: Composio's are far shorter. */
|
|
44
85
|
const MAX_SLUG = 128;
|
|
45
86
|
const WAIT_MS = 20_000;
|
|
87
|
+
/** The most bytes read of any one Composio answer: a page of 200 actions with their descriptions is well under it. */
|
|
88
|
+
const MAX_ANSWER = 4 * 1024 * 1024;
|
|
89
|
+
/** The toolkit listing's one deadline, every page in all. */
|
|
90
|
+
const LIST_MS = 30_000;
|
|
46
91
|
const text = (value) => (typeof value === "string" ? value : "");
|
|
47
|
-
const OVER = Symbol("over budget");
|
|
48
|
-
/** `res`'s body as text: with a budget, read only while it lasts, its bytes taken from it (OVER thrown once it runs out). */
|
|
49
|
-
async function answerOf(res, budget) {
|
|
50
|
-
if (!budget)
|
|
51
|
-
return res.text();
|
|
52
|
-
const reader = res.body?.getReader();
|
|
53
|
-
if (!reader)
|
|
54
|
-
return "";
|
|
55
|
-
const parts = [];
|
|
56
|
-
for (;;) {
|
|
57
|
-
const { done, value } = await reader.read();
|
|
58
|
-
if (done)
|
|
59
|
-
return Buffer.concat(parts).toString("utf8");
|
|
60
|
-
budget.left -= value.byteLength;
|
|
61
|
-
if (budget.left < 0) {
|
|
62
|
-
await reader.cancel().catch(() => undefined);
|
|
63
|
-
throw OVER;
|
|
64
|
-
}
|
|
65
|
-
parts.push(value);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
92
|
const issue = (field, reason, message) => ({ field, reason, message });
|
|
69
93
|
/** A Composio call as `key`: its JSON answer, or an error in words that name `step` and never the key nor a `sealed`
|
|
70
94
|
* value (a trigger's sealed config), and end with `outcome`, what the failure left (a save's: nothing was saved). A call
|
|
71
95
|
* with sealed values in play passes on none of Composio's words. Composio's 404 is `missing` when given: the words of a
|
|
72
|
-
* toolkit it has not, or the refusal on another field.
|
|
73
|
-
|
|
74
|
-
export function asking(control, key, signal, outcome = "nothing was saved", sealed = [], budget) {
|
|
96
|
+
* toolkit it has not, or the refusal on another field. An answer over MAX_ANSWER is refused in words, unread. */
|
|
97
|
+
export function asking(control, key, signal, outcome = "nothing was saved", sealed = []) {
|
|
75
98
|
const base = (control.baseUrl ?? BASE).replace(/\/+$/, "");
|
|
76
99
|
const send = control.fetch ?? fetch;
|
|
77
100
|
// Composio's words may quote what it was sent, as sent, JSON-escaped or percent-encoded. With a sealed value in play
|
|
@@ -90,13 +113,13 @@ export function asking(control, key, signal, outcome = "nothing was saved", seal
|
|
|
90
113
|
headers: { "x-api-key": key, accept: "application/json", ...(body === undefined ? {} : { "content-type": "application/json" }) },
|
|
91
114
|
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
92
115
|
});
|
|
93
|
-
raw = await
|
|
116
|
+
raw = await textUpTo(res, MAX_ANSWER);
|
|
94
117
|
}
|
|
95
|
-
catch
|
|
96
|
-
if (error === OVER && budget)
|
|
97
|
-
throw new ApiError("upstream_failed", `Composio's answers while ${step} were over ${budget.of / (1024 * 1024)} MiB: ${outcome}.`);
|
|
118
|
+
catch {
|
|
98
119
|
throw new ApiError("upstream_failed", `Composio did not answer while ${step}: ${outcome}.`);
|
|
99
120
|
}
|
|
121
|
+
if (raw === undefined)
|
|
122
|
+
throw new ApiError("upstream_failed", `Composio's answer while ${step} was over ${MAX_ANSWER / (1024 * 1024)} MiB: ${outcome}.`);
|
|
100
123
|
let json;
|
|
101
124
|
try {
|
|
102
125
|
json = JSON.parse(raw);
|
|
@@ -164,22 +187,38 @@ function needsNoAuth(kit) {
|
|
|
164
187
|
return modes.length > 0 && modes.every((mode) => mode === "NO_AUTH");
|
|
165
188
|
}
|
|
166
189
|
const notFound = (toolkit) => `Composio has no toolkit ${toolkit}: use its slug (github, slack, gmail...).`;
|
|
167
|
-
/**
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
|
|
171
|
-
|
|
190
|
+
/** Every page of the Composio listing at `path` (a query of its own, to which each page's cursor is added), at most `max`:
|
|
191
|
+
* what `keep` takes of each item (an item it answers undefined for is dropped), so no page is held past its own read,
|
|
192
|
+
* and whether the list ended within them (`complete`). A cursor Composio names a second time ends the list there, not
|
|
193
|
+
* complete. */
|
|
194
|
+
async function pages(ask, step, path, max, keep, missing) {
|
|
195
|
+
const items = [];
|
|
196
|
+
const seen = new Set();
|
|
172
197
|
let cursor;
|
|
173
|
-
for (let page = 0; page <
|
|
174
|
-
const listed = await ask(
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
198
|
+
for (let page = 0; page < max; page++) {
|
|
199
|
+
const listed = await ask(step, "GET", `${path}${cursor ? `&cursor=${encodeURIComponent(cursor)}` : ""}`, undefined, missing);
|
|
200
|
+
if (Array.isArray(listed.items))
|
|
201
|
+
for (const item of listed.items) {
|
|
202
|
+
const kept = keep(item);
|
|
203
|
+
if (kept !== undefined)
|
|
204
|
+
items.push(kept);
|
|
205
|
+
}
|
|
178
206
|
cursor = text(listed.next_cursor) || undefined;
|
|
179
207
|
if (!cursor)
|
|
180
|
-
return {
|
|
208
|
+
return { items, complete: true };
|
|
209
|
+
if (seen.has(cursor))
|
|
210
|
+
break;
|
|
211
|
+
seen.add(cursor);
|
|
181
212
|
}
|
|
182
|
-
return {
|
|
213
|
+
return { items, complete: false };
|
|
214
|
+
}
|
|
215
|
+
/** A toolkit's actions, every page (at most MAX_PAGES), at its latest version: without toolkit_versions Composio lists its
|
|
216
|
+
* base version (00000000_00), which leaves out the actions added since (linear 21 of 48, stripe 33 of 435, live 11-18),
|
|
217
|
+
* though its MCP servers serve them. `complete`: the list ended within MAX_PAGES. */
|
|
218
|
+
async function toolkitTools(ask, toolkit) {
|
|
219
|
+
const toolOf = (item) => (isObject(item) && text(item.slug) ? { slug: text(item.slug), name: text(item.name) || text(item.slug), description: text(item.description) } : undefined);
|
|
220
|
+
const { items: tools, complete } = await pages(ask, "listing the toolkit's actions", `/api/v3/tools?toolkit_slug=${encodeURIComponent(toolkit)}&toolkit_versions=latest&limit=${PAGE}`, MAX_PAGES, toolOf, notFound(toolkit));
|
|
221
|
+
return { tools, complete };
|
|
183
222
|
}
|
|
184
223
|
/** POST /settings/mcp-servers/composio/tools: a toolkit's actions, for the console's picker, and whether it needs no sign-in. */
|
|
185
224
|
export async function composioTools(body, control, signal) {
|
|
@@ -196,10 +235,9 @@ const likelySlug = (slug, slugs) => {
|
|
|
196
235
|
};
|
|
197
236
|
/** The most pages of the toolkit list read (PAGE each): Composio offers about a thousand. */
|
|
198
237
|
const MAX_TOOLKIT_PAGES = 20;
|
|
199
|
-
/**
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
* MAX_TOOLKIT_BYTES in all; a cursor it names a second time ends the list), by name: each one's slug, as a save takes it (a slug outside COMPOSIO_TOOLKIT is left out), and its name. Stores nothing. */
|
|
238
|
+
/** POST /settings/mcp-servers/composio/toolkits: the toolkits Composio offers, every page (at most MAX_TOOLKIT_PAGES, all
|
|
239
|
+
* within LIST_MS), by name: each one's slug, as a save takes it (a slug outside COMPOSIO_TOOLKIT is left out), and its
|
|
240
|
+
* name. Stores nothing. */
|
|
203
241
|
export async function composioToolkits(body, control, signal) {
|
|
204
242
|
if (!isObject(body))
|
|
205
243
|
throw invalid([issue("body", "invalid", "The body is {api_key}.")]);
|
|
@@ -209,44 +247,47 @@ export async function composioToolkits(body, control, signal) {
|
|
|
209
247
|
const key = typeof body.api_key === "string" ? body.api_key.trim() : "";
|
|
210
248
|
if (!key || key.length > 8192)
|
|
211
249
|
throw invalid([issue("api_key", "missing", "Send your Composio API key.")]);
|
|
212
|
-
const
|
|
250
|
+
const within = control.listDeadline?.() ?? AbortSignal.timeout(LIST_MS);
|
|
251
|
+
const ask = asking(control, key, signal ? AbortSignal.any([signal, within]) : within, "no toolkit was listed");
|
|
252
|
+
const toolkitOf = (item) => {
|
|
253
|
+
const slug = isObject(item) ? text(item.slug).trim().toLowerCase() : "";
|
|
254
|
+
return TOOLKIT.test(slug) ? { slug, name: text(item.name).trim() || slug } : undefined;
|
|
255
|
+
};
|
|
213
256
|
const found = new Map();
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
for (const item of Array.isArray(listed.items) ? listed.items : []) {
|
|
219
|
-
const slug = isObject(item) ? text(item.slug).trim().toLowerCase() : "";
|
|
220
|
-
if (TOOLKIT.test(slug) && !found.has(slug))
|
|
221
|
-
found.set(slug, { slug, name: text(item.name).trim() || slug });
|
|
222
|
-
}
|
|
223
|
-
cursor = text(listed.next_cursor) || undefined;
|
|
224
|
-
if (!cursor || seen.has(cursor))
|
|
225
|
-
break;
|
|
226
|
-
seen.add(cursor);
|
|
227
|
-
}
|
|
257
|
+
const { items } = await pages(ask, "listing the toolkits", `/api/v3/toolkits?sort_by=alphabetically&limit=${PAGE}`, MAX_TOOLKIT_PAGES, toolkitOf);
|
|
258
|
+
for (const kit of items)
|
|
259
|
+
if (!found.has(kit.slug))
|
|
260
|
+
found.set(kit.slug, kit);
|
|
228
261
|
return { toolkits: [...found.values()].sort((a, b) => a.name.localeCompare(b.name, "en", { sensitivity: "base" }) || a.slug.localeCompare(b.slug)) };
|
|
229
262
|
}
|
|
230
|
-
export const COMPOSIO_ACCOUNT_STATES = ["connected", "pending", "expired", "none", "unknown"];
|
|
231
263
|
/** The longest label kept, and the most labels. */
|
|
232
264
|
const MAX_LABEL = 120;
|
|
233
265
|
const MAX_LABELS = 10;
|
|
234
266
|
/** `value` as a label: one line of text, cut to MAX_LABEL; none when empty or shaped as an account's id. */
|
|
235
|
-
|
|
267
|
+
function accountLabel(value) {
|
|
236
268
|
const line = typeof value === "string" ? value.replace(/[\u0000-\u001f\u007f]+/g, " ").trim().slice(0, MAX_LABEL).trim() : "";
|
|
237
269
|
return line && !COMPOSIO_ACCOUNT_ID.test(line) ? line : undefined;
|
|
238
270
|
}
|
|
239
271
|
const labelOf = (account) => accountLabel(account.alias) ?? (isObject(account.state) && isObject(account.state.val) ? accountLabel(account.state.val.displayName) : undefined) ?? accountLabel(account.word_id);
|
|
240
|
-
/** The
|
|
241
|
-
* as Composio lists
|
|
242
|
-
* say it will stop answering
|
|
243
|
-
*
|
|
244
|
-
*
|
|
272
|
+
/** The connected accounts of `of.user` for `of.toolkit` under `of.auth_config` (under every config where none is named;
|
|
273
|
+
* ACTIVE ones alone with `active`), as Composio lists them now: only those Composio names as that user's. One with no
|
|
274
|
+
* user_id (a field Composio's docs say it will stop answering) is never kept, though Composio was asked for this user's
|
|
275
|
+
* alone: nothing says whose it is, so the user connects one again. None, unasked, for a user that is no Composio user id
|
|
276
|
+
* (COMPOSIO_USER_ID): a blank one Composio may read as every user. */
|
|
277
|
+
export async function accountsUnder(ask, of, active = false) {
|
|
278
|
+
if (!COMPOSIO_USER_ID.test(of.user))
|
|
279
|
+
return [];
|
|
280
|
+
const enc = encodeURIComponent;
|
|
281
|
+
const listed = await ask("checking the connected account", "GET", `/api/v3/connected_accounts?user_ids=${enc(of.user)}&toolkit_slugs=${enc(of.toolkit)}${of.auth_config ? `&auth_config_ids=${enc(of.auth_config)}` : ""}${active ? "&statuses=ACTIVE" : ""}`);
|
|
282
|
+
return (Array.isArray(listed.items) ? listed.items : []).filter((a) => isObject(a) && a.user_id === of.user && (!of.auth_config || (isObject(a.auth_config) && a.auth_config.id === of.auth_config)) && (!active || a.status === "ACTIVE"));
|
|
283
|
+
}
|
|
284
|
+
/** The account of a saved Composio server's user for its toolkit, under its auth config (accountsUnder), as Composio
|
|
285
|
+
* lists it now: one Composio names as that user's (accountsUnder), which gives its labels too. `unknown`, unasked, for a user that is no one Composio user (empty, which Composio
|
|
286
|
+
* reads as every user). */
|
|
245
287
|
export async function composioAccount(ask, of) {
|
|
246
288
|
if (!COMPOSIO_USER_ID.test(of.user))
|
|
247
289
|
return { state: "unknown" };
|
|
248
|
-
const
|
|
249
|
-
const mine = (Array.isArray(listed.items) ? listed.items : []).filter((a) => isObject(a) && (!a.user_id || a.user_id === of.user) && isObject(a.auth_config) && a.auth_config.id === of.auth_config);
|
|
290
|
+
const mine = await accountsUnder(ask, of);
|
|
250
291
|
const active = mine.filter((a) => a.status === "ACTIVE");
|
|
251
292
|
if (active.length) {
|
|
252
293
|
const labels = [...new Set(active.map(labelOf).filter((label) => !!label))].slice(0, MAX_LABELS);
|
|
@@ -299,8 +340,15 @@ export const composioRunQuery = (binding) => ({ [ADDRESS_USER]: binding.user_id,
|
|
|
299
340
|
* toolkit's Composio-managed one, found or made. `save` gets what the server stands on there too (`stands`,
|
|
300
341
|
* composio-made.ts): the auth config found or made and the account found or started, each marked whether this save made
|
|
301
342
|
* it, for its delete to remove what was made. The key is the body's `api_key`, or COMPOSIO_API_KEY's value when the body
|
|
302
|
-
* sends `api_key_env` (head): then `stands.key_env` names it, and the store seals no credential.
|
|
303
|
-
|
|
343
|
+
* sends `api_key_env` (head): then `stands.key_env` names it, and the store seals no credential. `standsOn`: the caller's
|
|
344
|
+
* check of the auth config named (before anything is sent) or found (before anything is made against it): an API token's
|
|
345
|
+
* save never stands on one a server the owner saved stands on. `accountOn`: the caller's check of an ACTIVE account the
|
|
346
|
+
* save found for its user, before anything is made (an API token's save: only one a server the token saved holds); with
|
|
347
|
+
* it, a user whose accounts run past the lookup's pages is 403, since they can't all be checked. Each
|
|
348
|
+
* refuses by throwing, and the save makes nothing. `userAs`: the Composio user the body's `user_id` (or the default) is
|
|
349
|
+
* sent as, in every call, the address and the record (an API token's save: composioTokenUser); per_run is never mapped.
|
|
350
|
+
* A user_id in the token's namespace (COMPOSIO_TOKEN_USER_PREFIX) is the server's to add, so no body names one: 422. */
|
|
351
|
+
export async function composioSave(body, control, save, name, signal, savedUrl, standsOn, accountOn, userAs) {
|
|
304
352
|
// No address and no headers of the caller's own: Composio makes the server and answers its address, and the key is the
|
|
305
353
|
// one header sent. Any field the save does not take is refused before anything is sent, never ignored.
|
|
306
354
|
if (isObject(body)) {
|
|
@@ -310,14 +358,19 @@ export async function composioSave(body, control, save, name, signal, savedUrl)
|
|
|
310
358
|
}
|
|
311
359
|
const { key, toolkit, rest, keyEnv } = head(body, { keyEnv: true });
|
|
312
360
|
const tools = Array.isArray(rest.tools) ? rest.tools : [];
|
|
313
|
-
const
|
|
361
|
+
const given = rest.user_id === undefined ? COMPOSIO_USER : typeof rest.user_id === "string" ? rest.user_id : "";
|
|
314
362
|
const price = rest.price_usd;
|
|
315
363
|
const ownConfig = rest.auth_config_id === undefined ? undefined : typeof rest.auth_config_id === "string" ? rest.auth_config_id : "";
|
|
316
364
|
const issues = [];
|
|
317
365
|
if (!tools.length || tools.length > MAX_TOOLS || !tools.every((t) => typeof t === "string" && t && t.length <= MAX_SLUG))
|
|
318
366
|
issues.push(issue("tools", "invalid", `Send the slugs of the actions to grant: 1 to ${MAX_TOOLS} of them, each at most ${MAX_SLUG} characters.`));
|
|
319
|
-
if (!USER_ID.test(
|
|
367
|
+
if (!USER_ID.test(given))
|
|
320
368
|
issues.push(issue("user_id", "invalid", `A user_id is ${COMPOSIO_USER_ID_WORDS}, or "${COMPOSIO_PER_RUN}" for a server each run names its own account for.`));
|
|
369
|
+
// In any letter case: Composio may fold a user id's, and then such a user would land in the token's namespace.
|
|
370
|
+
else if (given.toLowerCase().startsWith(COMPOSIO_TOKEN_USER_PREFIX))
|
|
371
|
+
issues.push(issue("user_id", "not_allowed", `A user_id starting "${COMPOSIO_TOKEN_USER_PREFIX}" (in any letter case) is the API token's: its saves are kept at Composio under that prefix, and no save names one. Name another user_id.`));
|
|
372
|
+
else if (userAs && given !== COMPOSIO_PER_RUN && !USER_ID.test(userAs(given)))
|
|
373
|
+
issues.push(issue("user_id", "invalid", `This save's user_id is at most ${128 - userAs("").length} characters (${COMPOSIO_USER_ID_WORDS} in all): Composio knows it as ${userAs("<user_id>")}.`));
|
|
321
374
|
if (price !== undefined && !priceValid(price))
|
|
322
375
|
issues.push(issue("price_usd", "invalid", "price_usd is what each call of the server's actions costs, in USD: a finite number, 0 or more."));
|
|
323
376
|
if (ownConfig !== undefined && !COMPOSIO_AUTH_CONFIG_ID.test(ownConfig))
|
|
@@ -325,7 +378,9 @@ export async function composioSave(body, control, save, name, signal, savedUrl)
|
|
|
325
378
|
if (issues.length)
|
|
326
379
|
throw invalid(issues);
|
|
327
380
|
// A per-run server: no user, no account, no connect link here; each run names its own (mcp_auth).
|
|
328
|
-
const perRun =
|
|
381
|
+
const perRun = given === COMPOSIO_PER_RUN;
|
|
382
|
+
// The user every Composio call, the address and the record name: the given one, or the caller's mapping of it.
|
|
383
|
+
const user = perRun || !userAs ? given : userAs(given);
|
|
329
384
|
// Every granted action at the one price, saved as the server's prices: each call is held and booked as any priced MCP
|
|
330
385
|
// call (mcp-gateway.ts). None named: the server's prices as they stand, for the actions it still lists (a server saved
|
|
331
386
|
// with none: "not metered").
|
|
@@ -339,6 +394,8 @@ export async function composioSave(body, control, save, name, signal, savedUrl)
|
|
|
339
394
|
const madeHere = [];
|
|
340
395
|
let url;
|
|
341
396
|
try {
|
|
397
|
+
if (ownConfig && standsOn)
|
|
398
|
+
await standsOn(ownConfig);
|
|
342
399
|
const kit = await ask("reading the toolkit", "GET", `/api/v3/toolkits/${encodeURIComponent(toolkit)}`, undefined, notFound(toolkit));
|
|
343
400
|
// Every slug is one the toolkit lists (at its latest version), before anything is made: Composio makes a server
|
|
344
401
|
// allowing a slug it doesn't have, which then serves nothing under that name. A list longer than MAX_PAGES refuses
|
|
@@ -367,6 +424,9 @@ export async function composioSave(body, control, save, name, signal, savedUrl)
|
|
|
367
424
|
throw invalid([issue("auth_config_id", "wrong_toolkit", `The auth config ${ownConfig} is ${of ? `the ${of} toolkit's` : "no toolkit's Composio names"}, not ${toolkit}'s: use one of ${toolkit}'s. Nothing was saved.`)]);
|
|
368
425
|
if (config.status === "DISABLED")
|
|
369
426
|
throw invalid([issue("auth_config_id", "disabled", `The auth config ${ownConfig} is disabled in Composio: enable it there, or use another. Nothing was saved.`)]);
|
|
427
|
+
// The id checked (standsOn) and recorded is the one sent: Composio answering another (another letter case, say) is refused.
|
|
428
|
+
if (text(config.id) !== ownConfig)
|
|
429
|
+
throw invalid([issue("auth_config_id", "not_found", `Composio answers the auth config ${ownConfig} as ${text(config.id) || "one with no id"}: send its id exactly as Composio shows it. Nothing was saved.`)]);
|
|
370
430
|
authConfig = ownConfig;
|
|
371
431
|
}
|
|
372
432
|
else if (!noAuth) {
|
|
@@ -380,6 +440,39 @@ export async function composioSave(body, control, save, name, signal, savedUrl)
|
|
|
380
440
|
madeHere.push({ kind: "auth_config", id: authConfig });
|
|
381
441
|
}
|
|
382
442
|
}
|
|
443
|
+
// The auth config found, checked by the caller before anything is made against it, as a named one was before anything
|
|
444
|
+
// was sent (an API token's save: never one a server the owner saved stands on, McpServersOverStore.tokenStandsOn).
|
|
445
|
+
// One made just now is no other's.
|
|
446
|
+
if (authConfig && !madeConfig && !ownConfig && standsOn)
|
|
447
|
+
await standsOn(authConfig);
|
|
448
|
+
// Only an account under this server's auth config serves it: one ACTIVE under another config (a custom one) doesn't.
|
|
449
|
+
// Looked for before anything is made, so the caller's check (accountOn) leaves nothing made. It asks Composio for ACTIVE
|
|
450
|
+
// ones alone, so the bound counts only them, and checks every one, on every page: Composio may serve any of them for
|
|
451
|
+
// this user and config. Past MAX_PAGES a save with that check is refused, since it can't check them all; one without
|
|
452
|
+
// it (the owner's) goes on with what it read.
|
|
453
|
+
let active;
|
|
454
|
+
if (authConfig && !perRun) {
|
|
455
|
+
const actives = [];
|
|
456
|
+
let cursor;
|
|
457
|
+
for (let page = 0;; page++) {
|
|
458
|
+
if (page === MAX_PAGES) {
|
|
459
|
+
if (accountOn)
|
|
460
|
+
throw new ApiError("forbidden", `Composio lists more than ${MAX_PAGES} pages of connected accounts for the user_id ${given} under the auth config ${authConfig} (${ACCOUNT_PAGE} a page), so this save can't check that each ACTIVE one is one a server the API token saved connected: an API token's server never stands on one it can't check. Name another user_id. Nothing was saved.`);
|
|
461
|
+
break;
|
|
462
|
+
}
|
|
463
|
+
const listed = await ask("checking the connected account", "GET", `/api/v3/connected_accounts?user_ids=${encodeURIComponent(user)}&toolkit_slugs=${encodeURIComponent(toolkit)}&auth_config_ids=${encodeURIComponent(authConfig)}&statuses=ACTIVE&limit=${ACCOUNT_PAGE}${cursor ? `&cursor=${encodeURIComponent(cursor)}` : ""}`);
|
|
464
|
+
// Only this save's user's (the mapped one): an account Composio answers under another user, or with no user_id, is
|
|
465
|
+
// never counted.
|
|
466
|
+
actives.push(...(Array.isArray(listed.items) ? listed.items : []).filter((a) => isObject(a) && a.user_id === user && a.status === "ACTIVE" && isObject(a.auth_config) && a.auth_config.id === authConfig));
|
|
467
|
+
cursor = text(listed.next_cursor) || undefined;
|
|
468
|
+
if (!cursor)
|
|
469
|
+
break;
|
|
470
|
+
}
|
|
471
|
+
if (accountOn)
|
|
472
|
+
for (const one of actives)
|
|
473
|
+
await accountOn(given, text(one.id));
|
|
474
|
+
active = actives[0];
|
|
475
|
+
}
|
|
383
476
|
const made = await ask("making the MCP server", "POST", "/api/v3.1/mcp/servers/custom", {
|
|
384
477
|
name: `ar-${name.slice(0, 18)}-${randomBytes(3).toString("hex")}`, toolkits: [toolkit], ...(authConfig ? { auth_config_ids: [authConfig] } : {}), allowed_tools: tools, managed_auth_via_composio: true,
|
|
385
478
|
});
|
|
@@ -396,9 +489,6 @@ export async function composioSave(body, control, save, name, signal, savedUrl)
|
|
|
396
489
|
let connect;
|
|
397
490
|
const accounts = [];
|
|
398
491
|
if (authConfig && !perRun) {
|
|
399
|
-
// Only an account under this server's auth config serves it: one ACTIVE under another config (a custom one) doesn't.
|
|
400
|
-
const listed = await ask("checking the connected account", "GET", `/api/v3/connected_accounts?user_ids=${encodeURIComponent(user)}&toolkit_slugs=${encodeURIComponent(toolkit)}&auth_config_ids=${encodeURIComponent(authConfig)}`);
|
|
401
|
-
const active = (Array.isArray(listed.items) ? listed.items : []).find((a) => isObject(a) && a.status === "ACTIVE" && isObject(a.auth_config) && a.auth_config.id === authConfig);
|
|
402
492
|
if (active) {
|
|
403
493
|
if (text(active.id))
|
|
404
494
|
accounts.push({ id: text(active.id), made: false });
|
|
@@ -479,6 +569,12 @@ export const composioServerId = (address) => {
|
|
|
479
569
|
return undefined;
|
|
480
570
|
}
|
|
481
571
|
};
|
|
572
|
+
/** The Composio user a saved preset address calls as (its user_id), or undefined: none named, or not a preset address. */
|
|
573
|
+
export const composioAddressUser = (address) => {
|
|
574
|
+
if (composioServerId(address) === undefined)
|
|
575
|
+
return undefined;
|
|
576
|
+
return new URL(address).searchParams.get(ADDRESS_USER) ?? undefined;
|
|
577
|
+
};
|
|
482
578
|
/** A thing at Composio as the words name it; `removed`: as a removal names it (an account its connect link with it). */
|
|
483
579
|
const named = (thing, removed = false) => thing.kind === "mcp" ? `the MCP server ${thing.id}` : thing.kind === "auth_config" ? `the auth config ${thing.id}` : `the connected account ${thing.id}${removed ? " (its connect link with it)" : ""}`;
|
|
484
580
|
/** "a", "a and b", "a, b and c" (or "a, b or c"). */
|
|
@@ -150,10 +150,10 @@ export declare class ComposioTriggers implements TriggerUpstream {
|
|
|
150
150
|
/** The project's subscription for a trigger: made here if there is none (undone with `undo`), reused if it is this
|
|
151
151
|
* server's, moved here only when `move`. Answers its hook. */
|
|
152
152
|
private subscribe;
|
|
153
|
-
/** The id of the one ACTIVE account the server's user has for its toolkit
|
|
154
|
-
* on (as its MCP server serves only those; every config, for a server saved
|
|
155
|
-
* with the link to connect it under that config; several: refused, naming
|
|
156
|
-
* owner disconnects the ones it shouldn't run as. */
|
|
153
|
+
/** The id of the one ACTIVE account the server's user has for its toolkit (accountsUnder: never another user's), under
|
|
154
|
+
* the auth config the server's save stands on (as its MCP server serves only those; every config, for a server saved
|
|
155
|
+
* before that was recorded); none: refused, with the link to connect it under that config; several: refused, naming
|
|
156
|
+
* each with when it was connected, so the owner disconnects the ones it shouldn't run as. */
|
|
157
157
|
private accountOf;
|
|
158
158
|
}
|
|
159
159
|
export {};
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
// asked anything.
|
|
26
26
|
import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
|
|
27
27
|
import { ApiError, invalid } from "./errors.js";
|
|
28
|
-
import { asking, managedConfig } from "./composio-preset.js";
|
|
28
|
+
import { accountsUnder, asking, managedConfig } from "./composio-preset.js";
|
|
29
29
|
import { COMPOSIO_HOOK, COMPOSIO_SECRET, CONFIG_SECRET, CONFIG_UNLISTED, configScope, configSecrets, MOVE_FIELD, SEALED_FIELD, SEALED_MASK, sealableValue, sealedConfigFields, sealedKept, sealedSchemaFields, shownSource } from "./trigger-composio.js";
|
|
30
30
|
import { isObject } from "./validate.js";
|
|
31
31
|
/** Where the owner does by hand what this server could not do on Composio. */
|
|
@@ -632,14 +632,13 @@ export class ComposioTriggers {
|
|
|
632
632
|
this.deps.say({ condition: "composio_subscription_moved", from: sub.webhook_url, hook });
|
|
633
633
|
return hook;
|
|
634
634
|
}
|
|
635
|
-
/** The id of the one ACTIVE account the server's user has for its toolkit
|
|
636
|
-
* on (as its MCP server serves only those; every config, for a server saved
|
|
637
|
-
* with the link to connect it under that config; several: refused, naming
|
|
638
|
-
* owner disconnects the ones it shouldn't run as. */
|
|
635
|
+
/** The id of the one ACTIVE account the server's user has for its toolkit (accountsUnder: never another user's), under
|
|
636
|
+
* the auth config the server's save stands on (as its MCP server serves only those; every config, for a server saved
|
|
637
|
+
* before that was recorded); none: refused, with the link to connect it under that config; several: refused, naming
|
|
638
|
+
* each with when it was connected, so the owner disconnects the ones it shouldn't run as. */
|
|
639
639
|
async accountOf(ask, credential, server) {
|
|
640
640
|
const config = credential.auth_config;
|
|
641
|
-
const
|
|
642
|
-
const active = (Array.isArray(accounts.items) ? accounts.items : []).filter((a) => isObject(a) && a.status === "ACTIVE" && !!text(a.id) && (!config || (isObject(a.auth_config) && a.auth_config.id === config)));
|
|
641
|
+
const active = (await accountsUnder(ask, { user: credential.user, toolkit: credential.toolkit, ...(config ? { auth_config: config } : {}) }, true)).filter((a) => !!text(a.id));
|
|
643
642
|
if (active.length === 1)
|
|
644
643
|
return text(active[0].id);
|
|
645
644
|
const under = config ? ` under auth config ${config}` : "";
|
package/dist/compute-cost.js
CHANGED
|
@@ -29,6 +29,15 @@
|
|
|
29
29
|
import { PROVIDERS } from "@parcha/agentrun-computer";
|
|
30
30
|
import { paidStep } from "./paid-calls.js";
|
|
31
31
|
import { logLine } from "./print.js";
|
|
32
|
+
/** Each computer step that is owed, by name: booked and held past the cap's rule (kernel/cap port.ts), for money its
|
|
33
|
+
* provider is owed once the computer is made. The one place this file sets owed (owed-pin.test.mjs pins the list and
|
|
34
|
+
* each name's one use). A computer not yet made is never held owed: the hold before its create is the cap's to refuse. */
|
|
35
|
+
const OWED = {
|
|
36
|
+
/** The time it ran, booked each stretch and at its settle. */
|
|
37
|
+
bookedTime: { owed: true },
|
|
38
|
+
/** The first stretch of a computer already made. */
|
|
39
|
+
madeFirstStretch: { owed: true },
|
|
40
|
+
};
|
|
32
41
|
/** The unit each resource's time is counted in. */
|
|
33
42
|
export const COMPUTE_UNITS = { vcpu: "vcpu_second", memory: "gib_second", gpu: "gpu_second", disk: "gb_month" };
|
|
34
43
|
/** A month of disk, as providers bill one: 730 hours. */
|
|
@@ -143,7 +152,7 @@ export function computeMeter(options) {
|
|
|
143
152
|
await Promise.all(one.priced.map(async (resource) => {
|
|
144
153
|
const usd = resource.usdPerSecond * (ms / 1000);
|
|
145
154
|
const tag = computeTag(resource);
|
|
146
|
-
const stepped = await paidStep(paid, undefined, { name: `${one.provider}'s computer time (${tag})`, holdUsd: usd, basis: `${ms / 1000} s of ${resource.perSecond} ${COMPUTE_UNITS[resource.resource]} at $${resource.rate}`, by: one.provider, tool: COMPUTE_TOOL, tag,
|
|
155
|
+
const stepped = await paidStep(paid, undefined, { name: `${one.provider}'s computer time (${tag})`, holdUsd: usd, basis: `${ms / 1000} s of ${resource.perSecond} ${COMPUTE_UNITS[resource.resource]} at $${resource.rate}`, by: one.provider, tool: COMPUTE_TOOL, tag, ...OWED.bookedTime, ref: `compute:${one.provider}:${one.providerId}:${tag}@${from}-${from + ms}` }, async () => undefined, () => usd).catch((error) => ({ refused: String(error?.message ?? error) }));
|
|
147
156
|
if ("refused" in stepped)
|
|
148
157
|
log(logLine("compute_spend_unbooked", { said: `${ms / 1000} s of ${one.provider} ${one.providerId}'s ${tag} time was not booked on the run's ledger (${stepped.refused.slice(0, 200)})` }));
|
|
149
158
|
}));
|
|
@@ -221,7 +230,7 @@ export function computeMeter(options) {
|
|
|
221
230
|
// its create let go. The stretch's ticks wait for it, so a tick never drops a hold this has not set yet. Made
|
|
222
231
|
// while the run's spec is built, the hold waits for the spec's cap: then nothing waits on it (a stop while the spec
|
|
223
232
|
// fails would wait forever), and the hold, once the cap can judge, is let go at once if the computer was stopped.
|
|
224
|
-
const first = holdOf(provider, stretchUsd(priced), basisOf(provider, priced),
|
|
233
|
+
const first = holdOf(provider, stretchUsd(priced), basisOf(provider, priced), OWED.madeFirstStretch).then((answer) => {
|
|
225
234
|
if ("hold" in answer) {
|
|
226
235
|
if (one.stopped)
|
|
227
236
|
void answer.hold.drop();
|
|
@@ -3,7 +3,7 @@ import type { Duplex } from "node:stream";
|
|
|
3
3
|
import { type AttachHub, type AttachSocket, type HelloResult, type MachineTokens } from "@parcha/agentrun-computer";
|
|
4
4
|
import { WebSocket } from "ws";
|
|
5
5
|
import { type LiveReach } from "./live-reach.js";
|
|
6
|
-
import type
|
|
6
|
+
import { type MintedTokens, type PairedComputerRow, type PairedComputers, type Runners } from "./store/index.js";
|
|
7
7
|
import { type Route, type RouteSettings } from "./workspace/paired-route.js";
|
|
8
8
|
export { liveRelays, type RelayRow } from "./runner/presence.js";
|
|
9
9
|
export { RELAY_CONNECT_MS } from "./live-reach.js";
|
|
@@ -54,7 +54,8 @@ export declare function pairBodyOf(body: unknown): {
|
|
|
54
54
|
hello: HelloResult;
|
|
55
55
|
};
|
|
56
56
|
/** Why a driver's hello may not pair here, in the version rule's words (attach.ts helloMismatch), or undefined: its
|
|
57
|
-
* protocol version must be this server
|
|
57
|
+
* protocol version must be one this server takes (helloProblem: 0.2 or a later 0.x). The words name the side to
|
|
58
|
+
* update, and the code stays good, for the driver once it is updated. */
|
|
58
59
|
export declare function pairRefusal(name: string, hello: HelloResult): string | undefined;
|
|
59
60
|
/** A paired computer as GET /v2/computers lists it under `paired`: whatever its hello says it is (its os and version, its
|
|
60
61
|
* device, its screen, its groups and features: the live hello's while it is attached, else its last one), the
|
|
@@ -186,7 +187,9 @@ export declare function createAttachRoutes(options: AttachRoutesOptions): {
|
|
|
186
187
|
runs_refused: string | null;
|
|
187
188
|
}>;
|
|
188
189
|
remove: (id: string) => Promise<void>;
|
|
189
|
-
upgrade: (req: IncomingMessage, socket: Duplex, head: Buffer, deny: (status: string, words?: string, headers?: Record<string, string>) => void
|
|
190
|
+
upgrade: (req: IncomingMessage, socket: Duplex, head: Buffer, deny: (status: string, words?: string, headers?: Record<string, string>) => void, hop?: {
|
|
191
|
+
readonly tokenSha256: string;
|
|
192
|
+
}) => void;
|
|
190
193
|
close: () => Promise<void>;
|
|
191
194
|
machineTokens: MachineTokens;
|
|
192
195
|
daemon: (authorization: string | undefined, arch: string | null) => Promise<string>;
|