@desplega.ai/agent-swarm 1.160.0 → 1.162.0
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/README.md +4 -3
- package/dist/{acp-adapter-2mjwcsfh.js → acp-adapter-74m73ae9.js} +163 -49
- package/dist/{actions-e43rxskr.js → actions-4sr14gnt.js} +42 -38
- package/dist/{anthropic-messages-5qx80j9k.js → anthropic-messages-8xxrzky9.js} +22 -26
- package/dist/{app-mc7xfagn.js → app-pt68fbwp.js} +17 -14
- package/dist/{artifact-3v5t9jtg.js → artifact-fey7dvj9.js} +3 -2
- package/dist/{assistant-sedkzv3b.js → assistant-cv3jytks.js} +43 -39
- package/dist/{azure-openai-responses-nfb21z9a.js → azure-openai-responses-f5cqsyj8.js} +15 -10
- package/dist/{boot-reembed-m3656j2n.js → boot-reembed-4ht4gqth.js} +17 -14
- package/dist/{boot-reembed-cqz9swn5.js → boot-reembed-nxpcvpj9.js} +16 -13
- package/dist/{boot-scrub-logs-xbxf5d7w.js → boot-scrub-logs-k93kyw8k.js} +13 -10
- package/dist/boot-seeds-1skcrs0e.js +32 -0
- package/dist/{claude-adapter-dc6289mc.js → claude-adapter-r5g0tzge.js} +39 -30
- package/dist/{claude-managed-adapter-naaw51me.js → claude-managed-adapter-yxkfxg8j.js} +6 -5
- package/dist/{claude-managed-setup-eacvchx0.js → claude-managed-setup-pkyrgshb.js} +27 -27
- package/dist/{claude-sdk-session-bqp2xvym.js → claude-sdk-session-jxyxnrwd.js} +8041 -7910
- package/dist/{cli-4derpgyk.js → cli-2hhfhfq5.js} +6 -1
- package/dist/{cli-rykfmgwg.js → cli-2x0e561b.js} +1 -1
- package/dist/{cli-tzx2ke1v.js → cli-2zy95vhm.js} +137 -64
- package/dist/{cli-0x01kwrd.js → cli-4cwxn7gp.js} +47 -186
- package/dist/{cli-xjcywfsf.js → cli-4dcpaefp.js} +12 -11
- package/dist/{cli-v7fn5gms.js → cli-4x0csdjq.js} +164 -76
- package/dist/{cli-12tszpk9.js → cli-5bcd7sfy.js} +91 -29
- package/dist/{cli-jz4w45qt.js → cli-5k6k8ta3.js} +190 -50
- package/dist/{cli-tpq83z89.js → cli-5xhpb3kv.js} +20 -19
- package/dist/{cli-r1mxd1xh.js → cli-7af8yhav.js} +6 -179
- package/dist/{cli-jajnsm8q.js → cli-7tre70zp.js} +18160 -31345
- package/dist/{cli-447dt1h3.js → cli-8ev9xqnx.js} +218 -25
- package/dist/cli-bsky8g7w.js +449 -0
- package/dist/{cli-0z2v4nhw.js → cli-cat6h73s.js} +1 -1
- package/dist/{cli-25fcq4b4.js → cli-cebmgwsc.js} +15 -11
- package/dist/{cli-shkxm1vn.js → cli-cvatsam7.js} +189 -13
- package/dist/{cli-2658f6at.js → cli-cvk6yzw5.js} +6 -8
- package/dist/cli-dbmwby6a.js +9 -0
- package/dist/{cli-ptr8h7kp.js → cli-eg0b3p0k.js} +5 -218
- package/dist/cli-f9w1semm.js +413 -0
- package/dist/{cli-523679eh.js → cli-g739zqzt.js} +6 -5
- package/dist/{cli-dv6cdjs2.js → cli-gd4favx9.js} +28 -7
- package/dist/{cli-c8a36vcc.js → cli-gpqpmns7.js} +2 -2
- package/dist/{cli-5nbmpy8w.js → cli-hb5c2x5y.js} +1 -1
- package/dist/{cli-741yb0xx.js → cli-hmsw1gpy.js} +55 -169
- package/dist/{cli-qydf22qq.js → cli-jf7wmv1r.js} +2562 -735
- package/dist/{cli-mfe5btp9.js → cli-jxs2ygaw.js} +317 -121
- package/dist/{cli-kmcpfwn2.js → cli-jyy6pm2f.js} +19 -3
- package/dist/cli-kdkwd3yr.js +615 -0
- package/dist/{cli-6cs6wzxt.js → cli-kh04eqwe.js} +2 -2
- package/dist/{cli-9hsgwz4w.js → cli-kp42yek0.js} +1309 -391
- package/dist/cli-ma3zvh39.js +10404 -0
- package/dist/{cli-ybgv4kw2.js → cli-mbssg1xv.js} +9 -2
- package/dist/{cli-jsp14b6c.js → cli-mzfth0bp.js} +38 -1
- package/dist/{cli-r2ap2czm.js → cli-nexqx4ve.js} +6 -0
- package/dist/{cli-f8gy6r2r.js → cli-nq7yqw7b.js} +19 -8
- package/dist/{cli-10nhj6xq.js → cli-nt8hecg9.js} +34 -33
- package/dist/cli-p0r8sxj5.js +303 -0
- package/dist/{cli-58e8yr0d.js → cli-pkd6s2wy.js} +4 -2
- package/dist/{cli-a8dvhzrt.js → cli-q24re23n.js} +7 -5
- package/dist/cli-qjjvzwzd.js +222 -0
- package/dist/cli-qrgt5bqf.js +189 -0
- package/dist/{cli-et8m9xsv.js → cli-rfjw9jw2.js} +22 -10
- package/dist/{cli-7e398j1h.js → cli-rj0gqwwp.js} +3 -3
- package/dist/{cli-btfv8y88.js → cli-rnyzn44p.js} +2 -2
- package/dist/{cli-d5czme6m.js → cli-s3hwpt9v.js} +4754 -4945
- package/dist/{cli-0jwe9034.js → cli-sptrj5f5.js} +3 -3
- package/dist/{cli-0q3avq3s.js → cli-sqvfa090.js} +19 -11
- package/dist/{cli-azhgzetg.js → cli-swfmp1fx.js} +27 -27
- package/dist/{cli-jyk0ynw2.js → cli-t845n9xk.js} +23 -10
- package/dist/{cli-zpep9q5e.js → cli-tcen9p5w.js} +20 -15
- package/dist/{cli-74h9hscv.js → cli-tre4bdgq.js} +1 -1
- package/dist/{cli-pm1rst0h.js → cli-twrh04ap.js} +30 -15
- package/dist/{cli-phsaj4xq.js → cli-v0pvvhfq.js} +1 -1
- package/dist/{cli-ydmcgve1.js → cli-vc9bp061.js} +5 -5
- package/dist/{cli-g2whhdrf.js → cli-vxe6qa4h.js} +1 -1
- package/dist/{cli-vctdqs5h.js → cli-vy3ed88x.js} +15 -2
- package/dist/{cli-br0qdrnp.js → cli-vyqs9ya8.js} +18 -18
- package/dist/{cli-cpvsaqsw.js → cli-w0bwte75.js} +8 -5
- package/dist/cli-wbvnn6tk.js +861 -0
- package/dist/{cli-r94z9p1z.js → cli-wgbezhw2.js} +3 -0
- package/dist/{cli-evvtk35y.js → cli-wjgs5wxe.js} +7 -7
- package/dist/cli-wxkkd0e0.js +33 -0
- package/dist/{cli-0wgxmwf6.js → cli-xk79303e.js} +20 -7
- package/dist/{cli-ktmyrtpn.js → cli-xqpk3rp7.js} +33 -10
- package/dist/{cli-ygwm91nt.js → cli-yy6dew39.js} +1 -1
- package/dist/cli-zp38xvtm.js +9487 -0
- package/dist/{cli-tfky2838.js → cli-zvhd3f64.js} +4 -4
- package/dist/{cli-jayjpjmb.js → cli-zxqx25nz.js} +66 -23
- package/dist/cli.js +40 -32
- package/dist/{cloudflare-workers-ai-system-one-k6fbxw9d.js → cloudflare-workers-ai-system-one-k8ddqjkq.js} +8 -6
- package/dist/{codex-adapter-nmxcatww.js → codex-adapter-esvmnhn7.js} +24 -23
- package/dist/{codex-hook-20me6byw.js → codex-hook-m73jmqgx.js} +19 -3
- package/dist/{codex-login-w6fz4xbz.js → codex-login-cf7mzsgg.js} +2 -2
- package/dist/{codex-session-runner-90aa80ev.js → codex-session-runner-ban9excr.js} +24 -23
- package/dist/{commands-8wcq1kn7.js → commands-75413p2n.js} +13 -10
- package/dist/{db-j40kc4se.js → db-7f5pecwg.js} +17 -10
- package/dist/{dispatcher-4zqy768d.js → dispatcher-fh9at8nz.js} +41 -37
- package/dist/dsh-adapter-wpze65d4.js +24 -0
- package/dist/{e2b-ez07znam.js → e2b-gjgdjp91.js} +12 -9
- package/dist/easter-egg-3d-3w5c2n4c.js +1057 -0
- package/dist/{execute-6e7qeyk4.js → execute-f50wg9nh.js} +203 -49
- package/dist/{google-generative-ai-k6n5nbpp.js → google-generative-ai-jxxpnegy.js} +2 -2
- package/dist/{google-vertex-44xxtcvp.js → google-vertex-x7q1angm.js} +5 -5
- package/dist/{handlers-kjdce1w5.js → handlers-w13787bb.js} +44 -40
- package/dist/{hook-r2t4bqfg.js → hook-46g1jrvx.js} +34 -20
- package/dist/{hook-czx13n12.js → hook-4tpts2ry.js} +25 -21
- package/dist/{http-3bbb19be.js → http-19pzbfrt.js} +1440 -283
- package/dist/{index-668me3f0.js → index-8fd4dm4h.js} +42 -38
- package/dist/{index-fg0dsp6c.js → index-dqmp15bq.js} +41 -37
- package/dist/{index-kkv84jq9.js → index-qb4q1y3e.js} +41 -37
- package/dist/index-s75wc4wd.js +33 -0
- package/dist/{index-zg7vp46x.js → index-scptvdxg.js} +64 -38
- package/dist/{keepalive-yra8dy57.js → keepalive-xa5ts9cd.js} +15 -12
- package/dist/{lead-va0pad2c.js → lead-qp4xkvjq.js} +59 -54
- package/dist/{maintenance-hqewtmyg.js → maintenance-rm5885hm.js} +17 -14
- package/dist/{mistral-conversations-pc3ntnxt.js → mistral-conversations-rw7fbt22.js} +4 -4
- package/dist/{node-a5e00qhp.js → node-8zkdq42h.js} +834 -833
- package/dist/node-f0ykebbv.js +2107 -0
- package/dist/node-wyamey5r.js +19 -0
- package/dist/{oauth-refresh-sweep-7rdt1m9n.js → oauth-refresh-sweep-1csdfebf.js} +14 -11
- package/dist/{onboard-j6ms6d0x.js → onboard-r6b78cs4.js} +10 -10
- package/dist/{openai-codex-responses-bbancrr0.js → openai-codex-responses-efvrgrq3.js} +4 -4
- package/dist/{openai-completions-jpaj5g2b.js → openai-completions-bbbrrz4z.js} +12 -8
- package/dist/{openai-responses-200k1wx4.js → openai-responses-9jjyrcm1.js} +15 -10
- package/dist/{opencode-adapter-89rabkw2.js → opencode-adapter-kb3g6pkf.js} +12 -9
- package/dist/{otel-impl-a792rjz0.js → otel-impl-0y9knpky.js} +6 -6
- package/dist/{pi-mono-adapter-g7qzvr3v.js → pi-mono-adapter-z6s1bme2.js} +128 -37
- package/dist/{pricing-refresh-wx0tp7cb.js → pricing-refresh-mth26tgp.js} +15 -12
- package/dist/{rbac-roles-8tzawacv.js → rbac-roles-kwntb23q.js} +17 -12
- package/dist/rbac-roles-vpk4ebm8.js +45 -0
- package/dist/{registry-v5wytg0s.js → registry-km6t1jd2.js} +1 -1
- package/dist/{render-v2-mm7zswb8.js → render-v2-hcm7h00y.js} +17 -14
- package/dist/{runtime-zyssgse0.js → runtime-vfjsfsc5.js} +5 -4
- package/dist/{setup-8y70ys6t.js → setup-hbyzd65h.js} +2 -2
- package/dist/{virtual-modules-6nmk7h3n.js → virtual-modules-9bv7ry91.js} +9 -7
- package/dist/{work-objects-fg6xkb0n.js → work-objects-m09sxnhe.js} +44 -40
- package/dist/{worker-wmwhxsph.js → worker-0h35rvk4.js} +59 -54
- package/dist/{x-n3e0v3xa.js → x-f1gt1pz3.js} +2 -2
- package/openapi.json +699 -26
- package/package.json +19 -11
- package/src/azure-devops/api.ts +121 -0
- package/src/azure-devops/auth.ts +78 -0
- package/src/azure-devops/handlers.ts +413 -0
- package/src/azure-devops/index.ts +27 -0
- package/src/azure-devops/templates.ts +108 -0
- package/src/azure-devops/types.ts +90 -0
- package/src/be/api-drain.ts +184 -0
- package/src/be/db/tasks/read.ts +32 -7
- package/src/be/db/tasks/write.ts +21 -4
- package/src/be/db-client.ts +11 -2
- package/src/be/db-retention.ts +95 -32
- package/src/be/db.ts +44 -19
- package/src/be/memory/constants.ts +16 -0
- package/src/be/memory/graph-expansion.ts +8 -1
- package/src/be/memory/index-content.ts +20 -1
- package/src/be/memory/key-guard.ts +93 -0
- package/src/be/memory/key-paths.ts +103 -0
- package/src/be/memory/link-resolver.ts +29 -3
- package/src/be/memory/providers/sqlite-store.ts +152 -45
- package/src/be/memory/raters/llm-summarizer.ts +10 -4
- package/src/be/memory/raters/llm.ts +15 -5
- package/src/be/memory/raters/store.ts +6 -3
- package/src/be/memory/raters/types.ts +11 -0
- package/src/be/memory/reranker.ts +38 -7
- package/src/be/memory/types.ts +12 -1
- package/src/be/migrations/190_memory_rating_model.sql +7 -0
- package/src/be/migrations/191_context_versions_previous_index.sql +8 -0
- package/src/be/migrations/192_favorites_agent_fs_path.sql +36 -0
- package/src/be/onboarding.ts +7 -1
- package/src/be/pricing-normalize.ts +4 -2
- package/src/be/scripts/typecheck.ts +4 -3
- package/src/be/seed-pricing.ts +16 -0
- package/src/be/seed-prompt-templates.ts +1 -0
- package/src/be/swarm-config-guard.ts +46 -17
- package/src/be/task-citations.ts +11 -5
- package/src/be/users.ts +3 -0
- package/src/cli.tsx +3 -2
- package/src/comb/agent-fs.ts +39 -0
- package/src/comb/config.ts +37 -0
- package/src/comb/markers.ts +37 -0
- package/src/comb/review-batch.ts +486 -0
- package/src/comb/templates.ts +88 -0
- package/src/commands/claude-managed-setup.ts +33 -31
- package/src/commands/context-preamble.ts +4 -1
- package/src/commands/hook.ts +2 -1
- package/src/commands/provider-credentials.ts +28 -15
- package/src/commands/runner.ts +458 -110
- package/src/commands/templates.ts +10 -0
- package/src/e2b/env.ts +2 -0
- package/src/extensions/catalog.generated.json +17 -0
- package/src/extensions/contract-types.generated.ts +1 -1
- package/src/fs/agent-fs-provider.ts +106 -2
- package/src/github/handlers.ts +10 -74
- package/src/github/reactions.ts +119 -138
- package/src/github/task-reactions.ts +34 -11
- package/src/heartbeat/heartbeat.ts +4 -0
- package/src/hooks/codex-hook.ts +25 -1
- package/src/hooks/hook.ts +14 -1
- package/src/hooks/pr-body-guard.ts +983 -0
- package/src/http/agents.ts +1 -1
- package/src/http/all-routes.ts +1 -0
- package/src/http/assets.ts +5 -17
- package/src/http/comb.ts +131 -0
- package/src/http/core.ts +14 -1
- package/src/http/extensions.ts +51 -27
- package/src/http/fs.ts +9 -17
- package/src/http/index.ts +27 -9
- package/src/http/mcp-user.ts +8 -13
- package/src/http/mcp.ts +19 -12
- package/src/http/memory.ts +80 -14
- package/src/http/onboarding.ts +21 -2
- package/src/http/poll.ts +30 -3
- package/src/http/realtime.ts +62 -0
- package/src/http/request-principal.ts +22 -0
- package/src/http/session-data.ts +6 -4
- package/src/http/stats.ts +1 -0
- package/src/http/status.ts +34 -2
- package/src/http/tasks.ts +17 -3
- package/src/http/users.ts +1 -1
- package/src/http/webhooks.ts +120 -2
- package/src/kv-reserved-namespaces.ts +10 -5
- package/src/providers/claude-adapter.ts +84 -16
- package/src/providers/claude-managed-adapter.ts +29 -2
- package/src/providers/codex-adapter.ts +1 -1
- package/src/providers/codex-skill-resolver.ts +6 -0
- package/src/providers/dsh-adapter.ts +204 -7
- package/src/providers/opencode-adapter.ts +24 -3
- package/src/providers/pi-mono-adapter.ts +154 -5
- package/src/providers/pi-mono-extension.ts +1 -1
- package/src/providers/pricing-sources.md +5 -1
- package/src/providers/reasoning-effort.ts +10 -2
- package/src/providers/types.ts +1 -1
- package/src/rbac/legacy-policy.ts +3 -0
- package/src/rbac/permissions.ts +14 -0
- package/src/realtime/auth.ts +63 -1
- package/src/realtime/tickets.ts +52 -0
- package/src/realtime/transport.ts +51 -22
- package/src/scripts-runtime/types/stdlib.d.ts +13 -5
- package/src/scripts-runtime/types/swarm-extension.d.ts +7 -3
- package/src/scripts-runtime/types/swarm-sdk.d.ts +13 -5
- package/src/tasks/context-key.ts +38 -1
- package/src/telemetry-context.ts +175 -0
- package/src/telemetry-contract/EVENTS.md +81 -0
- package/src/telemetry-contract/SOURCE.json +9 -0
- package/src/telemetry-contract/catalog.json +1335 -0
- package/src/telemetry-contract/index.ts +60 -0
- package/src/telemetry-contract/types.gen.ts +1971 -0
- package/src/telemetry-identity.ts +129 -0
- package/src/telemetry-snapshot.ts +211 -0
- package/src/telemetry-trigger.ts +125 -0
- package/src/telemetry-types.typetest.ts +40 -0
- package/src/telemetry.ts +271 -67
- package/src/tests/api-drain-e2e.test.ts +249 -0
- package/src/tests/api-drain-worker-e2e.test.ts +216 -0
- package/src/tests/api-drain.test.ts +351 -0
- package/src/tests/azure-devops-auth.test.ts +100 -0
- package/src/tests/azure-devops-handlers.test.ts +324 -0
- package/src/tests/azure-devops-webhook-malformed.test.ts +96 -0
- package/src/tests/claude-default-route.test.ts +260 -0
- package/src/tests/claude-managed-adapter.test.ts +47 -0
- package/src/tests/claude-managed-setup.test.ts +48 -0
- package/src/tests/claude-prompt-body-once.test.ts +117 -0
- package/src/tests/claude-routes-e2e.test.ts +316 -0
- package/src/tests/comb-config-guard.test.ts +38 -0
- package/src/tests/comb-links.test.ts +162 -0
- package/src/tests/comb-markers.test.ts +68 -0
- package/src/tests/comb-review-batch.test.ts +770 -0
- package/src/tests/comb-status.test.ts +152 -0
- package/src/tests/context-versions-retention.test.ts +314 -0
- package/src/tests/core-auth.test.ts +7 -0
- package/src/tests/db-retention.test.ts +14 -14
- package/src/tests/db-task-read-contract.test.ts +3 -0
- package/src/tests/db-task-write-contract.test.ts +3 -0
- package/src/tests/docs-index-footprint.test.js +3 -3
- package/src/tests/dsh-adapter.test.ts +134 -2
- package/src/tests/dsh-usage.test.ts +153 -0
- package/src/tests/extensions-catalog.test.ts +1 -0
- package/src/tests/extensions-example-deploy-awareness.test.ts +301 -0
- package/src/tests/extensions-http.test.ts +137 -10
- package/src/tests/extensions-mcp-tools.test.ts +28 -0
- package/src/tests/favorites-agent-fs-path.test.ts +226 -0
- package/src/tests/fetch-resolved-env.test.ts +24 -0
- package/src/tests/fixtures/azure-devops/pull-request-commented.json +129 -0
- package/src/tests/fixtures/azure-devops/pull-request-created.json +88 -0
- package/src/tests/fixtures/fake-claude-routes.ts +229 -0
- package/src/tests/github-handlers-reactions.test.ts +486 -0
- package/src/tests/github-reactions.test.ts +280 -0
- package/src/tests/harness-cli-version.test.ts +62 -0
- package/src/tests/http-api-integration.test.ts +21 -0
- package/src/tests/http-task-write-ownership.test.ts +24 -1
- package/src/tests/internal-ai/complete-structured.test.ts +94 -0
- package/src/tests/internal-ai/credentials.test.ts +22 -0
- package/src/tests/internal-ai/models.test.ts +36 -2
- package/src/tests/internal-ai/schema-parity.test.ts +25 -1
- package/src/tests/internal-ai/summarize-session.test.ts +23 -7
- package/src/tests/mcp-user-route.test.ts +133 -0
- package/src/tests/memory-key-paths.test.ts +1055 -0
- package/src/tests/memory-link-resolver.test.ts +34 -0
- package/src/tests/memory-rate-endpoint.test.ts +66 -0
- package/src/tests/memory-rater-llm-summarizer.test.ts +2 -1
- package/src/tests/memory-rater-llm.test.ts +73 -0
- package/src/tests/memory-rater-store.test.ts +31 -0
- package/src/tests/memory-reranker.test.ts +40 -0
- package/src/tests/onboarding.test.ts +108 -0
- package/src/tests/opencode-adapter.test.ts +57 -0
- package/src/tests/opencode-plugin.test.ts +4 -0
- package/src/tests/pi-codemode.test.ts +82 -4
- package/src/tests/pi-mono-adapter.test.ts +265 -2
- package/src/tests/pr-body-leaks.test.ts +789 -0
- package/src/tests/preload.ts +14 -0
- package/src/tests/provider-registration.test.ts +0 -2
- package/src/tests/providers/pi-cost.test.ts +190 -4
- package/src/tests/rbac-engine.test.ts +25 -1
- package/src/tests/realtime-room-auth.test.ts +104 -1
- package/src/tests/realtime-tickets.test.ts +74 -0
- package/src/tests/realtime-transport.test.ts +131 -4
- package/src/tests/runner-api-drain.test.ts +301 -0
- package/src/tests/runner-fallback-output.test.ts +61 -0
- package/src/tests/runner-fenced-json-output.test.ts +178 -0
- package/src/tests/runner-slot-reconcile.test.ts +199 -0
- package/src/tests/script-connections.test.ts +6 -0
- package/src/tests/send-task-requested-by.test.ts +133 -15
- package/src/tests/session-costs-recompute-all-providers.test.ts +23 -0
- package/src/tests/task-lifecycle-telemetry.test.ts +8 -3
- package/src/tests/task-reactions.test.ts +29 -6
- package/src/tests/telemetry-context.test.ts +314 -0
- package/src/tests/telemetry-init.test.ts +51 -19
- package/src/tests/telemetry-snapshot.test.ts +229 -0
- package/src/tests/telemetry-trigger.test.ts +200 -0
- package/src/tests/template-registry-helpers.ts +1 -0
- package/src/tests/vcs-azure-devops.test.ts +73 -0
- package/src/tests/webhooks-task-blocked.test.ts +23 -0
- package/src/tests/workflow-agent-task-retry.test.ts +363 -0
- package/src/tests/workflow-definition-telemetry.test.ts +4 -4
- package/src/tests/workflow-llm.test.ts +14 -0
- package/src/tools/context-diff.ts +20 -0
- package/src/tools/extension-install.ts +27 -16
- package/src/tools/memory-edit.ts +47 -3
- package/src/tools/memory-search.ts +13 -1
- package/src/tools/memory-store.ts +55 -3
- package/src/tools/poll-task.ts +20 -1
- package/src/tools/send-task.ts +9 -1
- package/src/tools/task-action.ts +11 -0
- package/src/types.ts +45 -8
- package/src/utils/api-drain.ts +24 -0
- package/src/utils/constants.ts +57 -16
- package/src/utils/credentials.test.ts +31 -1
- package/src/utils/credentials.ts +20 -9
- package/src/utils/dsh-usage.ts +53 -0
- package/src/utils/harness-cli-version.ts +6 -4
- package/src/utils/internal-ai/complete-structured.ts +26 -3
- package/src/utils/internal-ai/credentials.ts +23 -9
- package/src/utils/internal-ai/index.ts +8 -1
- package/src/utils/internal-ai/models.ts +34 -8
- package/src/utils/internal-ai/summarize-session.ts +22 -8
- package/src/utils/pr-body-leaks.ts +172 -0
- package/src/utils/secret-scrubber.ts +8 -0
- package/src/utils/task-attachment-links.ts +14 -8
- package/src/vcs/azure-devops.ts +80 -0
- package/src/vcs/index.ts +5 -1
- package/src/vcs/types.ts +2 -2
- package/src/workflows/recovery.ts +26 -1
- package/src/workflows/resume.ts +31 -4
- package/src/workflows/task-step-routing.ts +75 -2
- package/templates/community/open-prompt-showreel/PLAYBOOK.md +336 -0
- package/templates/community/open-prompt-showreel/README.md +33 -0
- package/templates/community/open-prompt-showreel/example/tla-races/facts.ts +145 -0
- package/templates/community/open-prompt-showreel/example/tla-races/facts.v3.json +140 -0
- package/templates/community/open-prompt-showreel/example/tla-races/music.mist-city.json +8 -0
- package/templates/community/open-prompt-showreel/example/tla-races/reel.html +805 -0
- package/templates/community/open-prompt-showreel/example/tla-races/smoke.sh +48 -0
- package/templates/community/open-prompt-showreel/lead-prompt.md +89 -0
- package/templates/community/open-prompt-showreel/setup.sh +167 -0
- package/templates/community/open-prompt-showreel/skills/motion-design-replication/SKILL.md +85 -0
- package/templates/community/open-prompt-showreel/skills/motion-design-video-analysis/SKILL.md +115 -0
- package/templates/community/open-prompt-showreel/skills/open-prompt-showreel/SKILL.md +147 -0
- package/templates/community/open-prompt-showreel/skills/video-generation/SKILL.md +195 -0
- package/templates/community/open-prompt-showreel/tools/fetch-music.sh +65 -0
- package/templates/community/open-prompt-showreel/tools/music-analyze.py +69 -0
- package/templates/community/open-prompt-showreel/tools/music-current.sh +34 -0
- package/templates/community/open-prompt-showreel/tools/music-cut.sh +36 -0
- package/templates/community/open-prompt-showreel/tools/music-refine.py +39 -0
- package/templates/community/open-prompt-showreel/tools/render.mjs +157 -0
- package/templates/community/open-prompt-showreel/tools/sheet.sh +44 -0
- package/templates/community/open-prompt-showreel/tools/web-compress.sh +17 -0
- package/templates/community/open-prompt-showreel/tools/x-reencode.sh +21 -0
- package/templates/extensions/README.md +1 -0
- package/templates/extensions/deploy-awareness/README.md +28 -0
- package/templates/extensions/deploy-awareness/hooks.ts +152 -0
- package/templates/extensions/deploy-awareness/manifest.json +8 -0
- package/templates/skills/memory/config.json +2 -2
- package/templates/skills/memory/content.md +59 -5
- package/templates/skills/swarm-extensions/config.json +1 -1
- package/templates/skills/swarm-extensions/content.md +28 -5
- package/tsconfig.json +3 -0
- package/dist/boot-seeds-gsetbs5y.js +0 -28
- package/dist/cli-j490egb5.js +0 -5632
- package/dist/cli-tjf4cn8z.js +0 -9119
- package/dist/cli-tmqt7dpj.js +0 -572
- package/dist/dsh-adapter-mpnzgztj.js +0 -19
- package/dist/index-7aj368tw.js +0 -30
|
@@ -11,19 +11,20 @@ import {
|
|
|
11
11
|
StreamableHttpTransport,
|
|
12
12
|
isMcpAppResource,
|
|
13
13
|
isObject,
|
|
14
|
+
mcpNamespace,
|
|
14
15
|
require_proper_lockfile,
|
|
15
16
|
resolveConfigValueOrThrow,
|
|
16
17
|
resolveHeadersOrThrow
|
|
17
|
-
} from "./cli-
|
|
18
|
+
} from "./cli-8ev9xqnx.js";
|
|
18
19
|
import {
|
|
19
20
|
APP_NAME,
|
|
20
21
|
VERSION,
|
|
21
22
|
getAgentDir
|
|
22
|
-
} from "./cli-
|
|
23
|
+
} from "./cli-s3hwpt9v.js";
|
|
23
24
|
import {
|
|
24
25
|
oauthErrorHtml,
|
|
25
26
|
oauthSuccessHtml
|
|
26
|
-
} from "./cli-
|
|
27
|
+
} from "./cli-2x0e561b.js";
|
|
27
28
|
import {
|
|
28
29
|
__toESM
|
|
29
30
|
} from "./cli-bc05qbss.js";
|
|
@@ -46,14 +47,14 @@ ${page.details}` : page.message;
|
|
|
46
47
|
class OAuthCallbackServer {
|
|
47
48
|
redirectUrl;
|
|
48
49
|
server;
|
|
49
|
-
|
|
50
|
+
paths;
|
|
50
51
|
timeoutMs;
|
|
51
52
|
renderPage;
|
|
52
53
|
pending = new Map;
|
|
53
|
-
constructor(server, redirectUrl,
|
|
54
|
+
constructor(server, redirectUrl, paths, timeoutMs, renderPage) {
|
|
54
55
|
this.server = server;
|
|
55
56
|
this.redirectUrl = redirectUrl;
|
|
56
|
-
this.
|
|
57
|
+
this.paths = paths;
|
|
57
58
|
this.timeoutMs = timeoutMs;
|
|
58
59
|
this.renderPage = renderPage;
|
|
59
60
|
}
|
|
@@ -73,10 +74,10 @@ class OAuthCallbackServer {
|
|
|
73
74
|
const address = server.address();
|
|
74
75
|
if (!address || typeof address === "string")
|
|
75
76
|
throw new Error("OAuth callback server did not bind to TCP");
|
|
76
|
-
instance = new OAuthCallbackServer(server, `http://${redirectHost.includes(":") ? `[${redirectHost}]` : redirectHost}:${address.port}${path}`, path, options.timeoutMs ?? 5 * 60000, options.renderPage);
|
|
77
|
+
instance = new OAuthCallbackServer(server, `http://${redirectHost.includes(":") ? `[${redirectHost}]` : redirectHost}:${address.port}${path}`, [path, ...options.extraPaths ?? []], options.timeoutMs ?? 5 * 60000, options.renderPage);
|
|
77
78
|
return instance;
|
|
78
79
|
}
|
|
79
|
-
waitForCallback(state) {
|
|
80
|
+
waitForCallback(state, path) {
|
|
80
81
|
if (this.pending.has(state))
|
|
81
82
|
throw new Error("OAuth state is already pending");
|
|
82
83
|
return new Promise((resolve, reject) => {
|
|
@@ -84,7 +85,7 @@ class OAuthCallbackServer {
|
|
|
84
85
|
this.pending.delete(state);
|
|
85
86
|
reject(new Error("OAuth callback timed out"));
|
|
86
87
|
}, this.timeoutMs);
|
|
87
|
-
this.pending.set(state, { resolve, reject, timer });
|
|
88
|
+
this.pending.set(state, { resolve, reject, timer, path });
|
|
88
89
|
});
|
|
89
90
|
}
|
|
90
91
|
async close() {
|
|
@@ -107,7 +108,7 @@ class OAuthCallbackServer {
|
|
|
107
108
|
}
|
|
108
109
|
handle(rawUrl, response) {
|
|
109
110
|
const url = new URL(rawUrl, this.redirectUrl);
|
|
110
|
-
if (url.pathname
|
|
111
|
+
if (!this.paths.includes(url.pathname)) {
|
|
111
112
|
this.reply(response, 404, { ok: false, message: "Not found" });
|
|
112
113
|
return;
|
|
113
114
|
}
|
|
@@ -119,6 +120,11 @@ class OAuthCallbackServer {
|
|
|
119
120
|
}
|
|
120
121
|
clearTimeout(pending.timer);
|
|
121
122
|
this.pending.delete(state);
|
|
123
|
+
if (pending.path !== undefined && url.pathname !== pending.path) {
|
|
124
|
+
pending.reject(new Error("The authorization response arrived on another redirect URI"));
|
|
125
|
+
this.reply(response, 400, { ok: false, message: "Unexpected redirect URI" });
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
122
128
|
const error = url.searchParams.get("error");
|
|
123
129
|
if (error) {
|
|
124
130
|
const description = url.searchParams.get("error_description") ?? error;
|
|
@@ -157,7 +163,7 @@ class OAuthIssuerMismatchError extends Error {
|
|
|
157
163
|
expected;
|
|
158
164
|
received;
|
|
159
165
|
constructor(expected, received) {
|
|
160
|
-
super(`OAuth issuer mismatch: expected ${JSON.stringify(expected)}, received ${JSON.stringify(received)}`);
|
|
166
|
+
super(`OAuth issuer mismatch: expected ${JSON.stringify(expected)}, received ${received === undefined ? "none" : JSON.stringify(received)}`);
|
|
161
167
|
this.name = "OAuthIssuerMismatchError";
|
|
162
168
|
this.expected = expected;
|
|
163
169
|
this.received = received;
|
|
@@ -205,13 +211,16 @@ function requiredString(value, name) {
|
|
|
205
211
|
throw new Error(`Invalid ${name}`);
|
|
206
212
|
return value;
|
|
207
213
|
}
|
|
214
|
+
function absent(value) {
|
|
215
|
+
return value === undefined || value === null || value === "";
|
|
216
|
+
}
|
|
208
217
|
function optionalString(value, name) {
|
|
209
|
-
if (value
|
|
218
|
+
if (absent(value))
|
|
210
219
|
return;
|
|
211
220
|
return requiredString(value, name);
|
|
212
221
|
}
|
|
213
222
|
function optionalStrings(value, name) {
|
|
214
|
-
if (value === undefined)
|
|
223
|
+
if (value === undefined || value === null)
|
|
215
224
|
return;
|
|
216
225
|
if (!Array.isArray(value) || value.some((item) => typeof item !== "string"))
|
|
217
226
|
throw new Error(`Invalid ${name}`);
|
|
@@ -219,13 +228,15 @@ function optionalStrings(value, name) {
|
|
|
219
228
|
}
|
|
220
229
|
function safeUrl(value, name) {
|
|
221
230
|
const text = requiredString(value, name);
|
|
231
|
+
if (!URL.canParse(text))
|
|
232
|
+
throw new Error(`Invalid ${name}`);
|
|
222
233
|
const url = new URL(text);
|
|
223
234
|
if (["javascript:", "data:", "vbscript:"].includes(url.protocol))
|
|
224
235
|
throw new Error(`Invalid ${name}`);
|
|
225
236
|
return text;
|
|
226
237
|
}
|
|
227
238
|
function optionalUrl(value, name) {
|
|
228
|
-
return value
|
|
239
|
+
return absent(value) ? undefined : safeUrl(value, name);
|
|
229
240
|
}
|
|
230
241
|
function parseProtectedResourceMetadata(value) {
|
|
231
242
|
const input = object(value, "OAuth protected resource metadata");
|
|
@@ -252,12 +263,13 @@ function parseAuthorizationServerMetadata(value) {
|
|
|
252
263
|
grant_types_supported: optionalStrings(input.grant_types_supported, "grant_types_supported"),
|
|
253
264
|
token_endpoint_auth_methods_supported: optionalStrings(input.token_endpoint_auth_methods_supported, "token_endpoint_auth_methods_supported"),
|
|
254
265
|
code_challenge_methods_supported: optionalStrings(input.code_challenge_methods_supported, "code_challenge_methods_supported"),
|
|
255
|
-
client_id_metadata_document_supported: typeof input.client_id_metadata_document_supported === "boolean" ? input.client_id_metadata_document_supported : undefined
|
|
266
|
+
client_id_metadata_document_supported: typeof input.client_id_metadata_document_supported === "boolean" ? input.client_id_metadata_document_supported : undefined,
|
|
267
|
+
authorization_response_iss_parameter_supported: typeof input.authorization_response_iss_parameter_supported === "boolean" ? input.authorization_response_iss_parameter_supported : undefined
|
|
256
268
|
});
|
|
257
269
|
}
|
|
258
270
|
function parseOAuthTokens(value) {
|
|
259
271
|
const input = object(value, "OAuth token response");
|
|
260
|
-
const expires = input.expires_in
|
|
272
|
+
const expires = absent(input.expires_in) ? undefined : Number(input.expires_in);
|
|
261
273
|
if (expires !== undefined && !Number.isFinite(expires))
|
|
262
274
|
throw new Error("Invalid expires_in");
|
|
263
275
|
return compact({
|
|
@@ -293,7 +305,7 @@ function pathSuffix(pathname) {
|
|
|
293
305
|
}
|
|
294
306
|
function field(header, name) {
|
|
295
307
|
const match = header.match(new RegExp(String.raw`(?:^|[,\s])${name}=(?:"([^"]*)"|([^\s,]+))`, "i"));
|
|
296
|
-
return match?.[1]
|
|
308
|
+
return match?.[1] || match?.[2] || undefined;
|
|
297
309
|
}
|
|
298
310
|
function parseWwwAuthenticate(header) {
|
|
299
311
|
if (!header)
|
|
@@ -378,6 +390,16 @@ async function discoverOAuthServerInfo(serverUrl, options = {}) {
|
|
|
378
390
|
if (error instanceof TypeError)
|
|
379
391
|
throw error;
|
|
380
392
|
}
|
|
393
|
+
if (options.authorizationServerMetadataUrl) {
|
|
394
|
+
const url = options.authorizationServerMetadataUrl;
|
|
395
|
+
const response = await fetchMetadata(url, options.fetch ?? globalThis.fetch, LATEST_PROTOCOL_VERSION);
|
|
396
|
+
if (!response.ok) {
|
|
397
|
+
discard(response);
|
|
398
|
+
throw new Error(`HTTP ${response.status} loading authorization server metadata from ${url}`);
|
|
399
|
+
}
|
|
400
|
+
const metadata = parseAuthorizationServerMetadata(await response.json());
|
|
401
|
+
return { authorizationServerUrl: metadata.issuer, authorizationServerMetadata: metadata, resourceMetadata };
|
|
402
|
+
}
|
|
381
403
|
const authorizationServerUrl = resourceMetadata?.authorization_servers?.[0] ?? String(new URL("/", serverUrl));
|
|
382
404
|
return {
|
|
383
405
|
authorizationServerUrl,
|
|
@@ -523,8 +545,18 @@ async function refreshAuthorization(authorizationServerUrl, options) {
|
|
|
523
545
|
const tokens = await tokenRequest(authorizationServerUrl, options, new URLSearchParams({ grant_type: "refresh_token", refresh_token: options.refreshToken }));
|
|
524
546
|
return { refresh_token: options.refreshToken, ...tokens };
|
|
525
547
|
}
|
|
548
|
+
function withScope(tokens, scope) {
|
|
549
|
+
return tokens.scope === undefined && scope ? { ...tokens, scope } : tokens;
|
|
550
|
+
}
|
|
551
|
+
function stepUpScope(granted, challenged) {
|
|
552
|
+
if (!challenged)
|
|
553
|
+
return;
|
|
554
|
+
const scopes = [granted, challenged].flatMap((scope) => scope?.split(/\s+/).filter(Boolean) ?? []);
|
|
555
|
+
return [...new Set(scopes)].join(" ");
|
|
556
|
+
}
|
|
526
557
|
async function runFlow(provider, options) {
|
|
527
|
-
const
|
|
558
|
+
const metadataUrl = options.authorizationServerMetadataUrl && secureEndpoint(options.authorizationServerMetadataUrl);
|
|
559
|
+
const cached = metadataUrl ? undefined : await provider.discoveryState?.();
|
|
528
560
|
const discovered = cached?.authorizationServerUrl ? {
|
|
529
561
|
authorizationServerUrl: cached.authorizationServerUrl,
|
|
530
562
|
authorizationServerMetadata: cached.authorizationServerMetadata ?? await discoverAuthorizationServerMetadata(cached.authorizationServerUrl, {
|
|
@@ -534,38 +566,41 @@ async function runFlow(provider, options) {
|
|
|
534
566
|
resourceMetadata: cached.resourceMetadata
|
|
535
567
|
} : await discoverOAuthServerInfo(options.serverUrl, {
|
|
536
568
|
resourceMetadataUrl: options.resourceMetadataUrl,
|
|
569
|
+
authorizationServerMetadataUrl: metadataUrl,
|
|
537
570
|
fetch: options.fetch,
|
|
538
571
|
skipIssuerValidation: options.skipIssuerValidation
|
|
539
572
|
});
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
573
|
+
if (!metadataUrl) {
|
|
574
|
+
await provider.saveDiscoveryState?.({
|
|
575
|
+
...discovered,
|
|
576
|
+
...options.resourceMetadataUrl ? { resourceMetadataUrl: options.resourceMetadataUrl.href } : {}
|
|
577
|
+
});
|
|
578
|
+
}
|
|
544
579
|
const metadata = discovered.authorizationServerMetadata;
|
|
545
580
|
const resource = selectResource(options.serverUrl, discovered.resourceMetadata);
|
|
546
|
-
const scope = options.scope
|
|
547
|
-
|
|
581
|
+
const scope = options.scope || discovered.resourceMetadata?.scopes_supported?.join(" ") || provider.clientMetadata.scope;
|
|
582
|
+
const stored = await provider.clientInformation();
|
|
583
|
+
const clientDocument = stored ? undefined : provider.clientMetadataDocument?.(metadata);
|
|
584
|
+
if (clientDocument) {
|
|
585
|
+
const url = new URL(clientDocument.url);
|
|
586
|
+
if (url.protocol !== "https:" || url.pathname === "/")
|
|
587
|
+
throw new Error("Invalid OAuth client metadata URL");
|
|
588
|
+
}
|
|
589
|
+
let client = stored ?? (clientDocument && { client_id: clientDocument.url });
|
|
548
590
|
if (!client) {
|
|
549
591
|
if (options.authorizationCode)
|
|
550
592
|
throw new Error("OAuth client information is missing during code exchange");
|
|
551
|
-
if (
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
client = await registerClient(discovered.authorizationServerUrl, {
|
|
561
|
-
metadata,
|
|
562
|
-
clientMetadata: provider.clientMetadata,
|
|
563
|
-
scope,
|
|
564
|
-
fetch: options.fetch
|
|
565
|
-
});
|
|
566
|
-
await provider.saveClientInformation(client);
|
|
567
|
-
}
|
|
593
|
+
if (!provider.saveClientInformation)
|
|
594
|
+
throw new Error("OAuth client information cannot be persisted");
|
|
595
|
+
client = await registerClient(discovered.authorizationServerUrl, {
|
|
596
|
+
metadata,
|
|
597
|
+
clientMetadata: provider.clientMetadata,
|
|
598
|
+
scope,
|
|
599
|
+
fetch: options.fetch
|
|
600
|
+
});
|
|
601
|
+
await provider.saveClientInformation(client);
|
|
568
602
|
}
|
|
603
|
+
const redirectUrl = clientDocument?.redirectUrl ?? provider.redirectUrl;
|
|
569
604
|
const tokenOptions = {
|
|
570
605
|
metadata,
|
|
571
606
|
clientInformation: client,
|
|
@@ -574,13 +609,18 @@ async function runFlow(provider, options) {
|
|
|
574
609
|
fetch: options.fetch
|
|
575
610
|
};
|
|
576
611
|
if (options.authorizationCode) {
|
|
612
|
+
const iss = options.iss;
|
|
613
|
+
if (metadata && (iss !== undefined || metadata.authorization_response_iss_parameter_supported)) {
|
|
614
|
+
if (iss !== metadata.issuer)
|
|
615
|
+
throw new OAuthIssuerMismatchError(metadata.issuer, iss);
|
|
616
|
+
}
|
|
577
617
|
const tokens = await exchangeAuthorizationCode(discovered.authorizationServerUrl, {
|
|
578
618
|
...tokenOptions,
|
|
579
619
|
code: options.authorizationCode,
|
|
580
620
|
codeVerifier: await provider.codeVerifier(),
|
|
581
|
-
redirectUrl
|
|
621
|
+
redirectUrl
|
|
582
622
|
});
|
|
583
|
-
await provider.saveTokens(tokens);
|
|
623
|
+
await provider.saveTokens(withScope(tokens, scope));
|
|
584
624
|
return "AUTHORIZED";
|
|
585
625
|
}
|
|
586
626
|
const existing = options.skipRefresh ? undefined : await provider.tokens();
|
|
@@ -590,7 +630,7 @@ async function runFlow(provider, options) {
|
|
|
590
630
|
...tokenOptions,
|
|
591
631
|
refreshToken: existing.refresh_token
|
|
592
632
|
});
|
|
593
|
-
await provider.saveTokens(tokens);
|
|
633
|
+
await provider.saveTokens(withScope(tokens, existing.scope));
|
|
594
634
|
return "AUTHORIZED";
|
|
595
635
|
} catch (error) {
|
|
596
636
|
if (error instanceof OAuthInsecureEndpointError)
|
|
@@ -603,7 +643,7 @@ async function runFlow(provider, options) {
|
|
|
603
643
|
const authorization = await startAuthorization(discovered.authorizationServerUrl, {
|
|
604
644
|
metadata,
|
|
605
645
|
clientInformation: client,
|
|
606
|
-
redirectUrl
|
|
646
|
+
redirectUrl,
|
|
607
647
|
scope,
|
|
608
648
|
state,
|
|
609
649
|
resource
|
|
@@ -641,6 +681,7 @@ class MemoryOAuthStateStore {
|
|
|
641
681
|
class McpOAuthProvider {
|
|
642
682
|
redirectUrl;
|
|
643
683
|
clientMetadata;
|
|
684
|
+
clientMetadataDocument;
|
|
644
685
|
serverUrl;
|
|
645
686
|
configuredClient;
|
|
646
687
|
store;
|
|
@@ -656,6 +697,7 @@ class McpOAuthProvider {
|
|
|
656
697
|
response_types: options.clientMetadata.response_types ?? ["code"],
|
|
657
698
|
token_endpoint_auth_method: options.clientMetadata.token_endpoint_auth_method ?? (options.clientSecret ? "client_secret_post" : "none")
|
|
658
699
|
};
|
|
700
|
+
this.clientMetadataDocument = options.clientMetadataDocument;
|
|
659
701
|
this.configuredClient = options.clientId ? { client_id: options.clientId, ...options.clientSecret ? { client_secret: options.clientSecret } : {} } : undefined;
|
|
660
702
|
this.store = options.store ?? new MemoryOAuthStateStore;
|
|
661
703
|
this.onRedirect = options.onRedirect;
|
|
@@ -747,6 +789,7 @@ import { join } from "node:path";
|
|
|
747
789
|
var import_proper_lockfile = __toESM(require_proper_lockfile(), 1);
|
|
748
790
|
var CALLBACK_HOST = "127.0.0.1";
|
|
749
791
|
var CALLBACK_PATH = "/callback";
|
|
792
|
+
var CLIENT_METADATA_BASE_URL = "https://pi.dev/oauth";
|
|
750
793
|
var FALLBACK_REDIRECT_URL = `http://${CALLBACK_HOST}${CALLBACK_PATH}`;
|
|
751
794
|
var REFRESH_SKEW_MS = 30000;
|
|
752
795
|
var REFRESH_REQUEST_TIMEOUT_MS = 15000;
|
|
@@ -782,6 +825,14 @@ function parseStates(content) {
|
|
|
782
825
|
const parsed = JSON.parse(content);
|
|
783
826
|
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : {};
|
|
784
827
|
}
|
|
828
|
+
function serializeStates(states) {
|
|
829
|
+
return `${JSON.stringify(states, null, 2)}
|
|
830
|
+
`;
|
|
831
|
+
}
|
|
832
|
+
function storeKeys(name, serverUrl) {
|
|
833
|
+
const legacyKey = String(new URL(serverUrl));
|
|
834
|
+
return { key: `${mcpNamespace(name)}|${legacyKey}`, legacyKey };
|
|
835
|
+
}
|
|
785
836
|
|
|
786
837
|
class McpOAuthCredentialStore {
|
|
787
838
|
backend;
|
|
@@ -790,10 +841,17 @@ class McpOAuthCredentialStore {
|
|
|
790
841
|
this.backend = backend ?? new FileAuthStorageBackend(join(getAgentDir(), "mcp-auth.json"));
|
|
791
842
|
this.lockDir = backend ? lockDir : getAgentDir();
|
|
792
843
|
}
|
|
793
|
-
forServer(serverUrl) {
|
|
794
|
-
const key =
|
|
844
|
+
forServer(name, serverUrl) {
|
|
845
|
+
const { key, legacyKey } = storeKeys(name, serverUrl);
|
|
795
846
|
return {
|
|
796
|
-
load: () => this.
|
|
847
|
+
load: () => this.backend.withLock((current) => {
|
|
848
|
+
const states = parseStates(current);
|
|
849
|
+
if (states[key] || !states[legacyKey])
|
|
850
|
+
return { result: states[key] };
|
|
851
|
+
states[key] = states[legacyKey];
|
|
852
|
+
delete states[legacyKey];
|
|
853
|
+
return { result: states[key], next: serializeStates(states) };
|
|
854
|
+
}),
|
|
797
855
|
save: (state) => this.write((states) => {
|
|
798
856
|
states[key] = state;
|
|
799
857
|
}),
|
|
@@ -824,38 +882,56 @@ class McpOAuthCredentialStore {
|
|
|
824
882
|
});
|
|
825
883
|
}
|
|
826
884
|
}
|
|
827
|
-
tokens(serverUrl) {
|
|
828
|
-
|
|
885
|
+
tokens(name, serverUrl) {
|
|
886
|
+
const { key, legacyKey } = storeKeys(name, serverUrl);
|
|
887
|
+
const states = this.backend.withLock((current) => ({ result: parseStates(current) }));
|
|
888
|
+
return (states[key] ?? states[legacyKey])?.tokens;
|
|
829
889
|
}
|
|
830
|
-
remove(serverUrl) {
|
|
831
|
-
const key =
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
890
|
+
remove(name, serverUrl) {
|
|
891
|
+
const { key, legacyKey } = storeKeys(name, serverUrl);
|
|
892
|
+
return this.backend.withLock((current) => {
|
|
893
|
+
const states = parseStates(current);
|
|
894
|
+
const stored = key in states ? key : (legacyKey in states) ? legacyKey : undefined;
|
|
895
|
+
if (!stored)
|
|
896
|
+
return { result: false };
|
|
897
|
+
delete states[stored];
|
|
898
|
+
return { result: true, next: serializeStates(states) };
|
|
836
899
|
});
|
|
837
|
-
return true;
|
|
838
|
-
}
|
|
839
|
-
read() {
|
|
840
|
-
return this.backend.withLock((current) => ({ result: parseStates(current) }));
|
|
841
900
|
}
|
|
842
901
|
write(update) {
|
|
843
902
|
this.backend.withLock((current) => {
|
|
844
903
|
const states = parseStates(current);
|
|
845
904
|
update(states);
|
|
846
|
-
return { result: undefined, next:
|
|
847
|
-
` };
|
|
905
|
+
return { result: undefined, next: serializeStates(states) };
|
|
848
906
|
});
|
|
849
907
|
}
|
|
850
908
|
}
|
|
851
909
|
function registeredRedirectUrls(client) {
|
|
852
910
|
return client && "redirect_uris" in client ? client.redirect_uris : [];
|
|
853
911
|
}
|
|
912
|
+
function callbackId(serverUrl) {
|
|
913
|
+
const url = new URL(serverUrl);
|
|
914
|
+
url.hash = "";
|
|
915
|
+
return createHash("sha256").update(url.href).digest().subarray(0, 9).toString("base64url");
|
|
916
|
+
}
|
|
917
|
+
function clientMetadataDocument(serverUrl, redirectUrl, metadata) {
|
|
918
|
+
if (!metadata?.client_id_metadata_document_supported || !metadata.token_endpoint_auth_methods_supported?.includes("none")) {
|
|
919
|
+
throw new Error('The authorization server does not support Client ID Metadata Documents for public clients; remove oauth.clientRegistration "cimd"');
|
|
920
|
+
}
|
|
921
|
+
if (metadata.authorization_response_iss_parameter_supported) {
|
|
922
|
+
return { url: `${CLIENT_METADATA_BASE_URL}/client.json`, redirectUrl };
|
|
923
|
+
}
|
|
924
|
+
const id = callbackId(serverUrl);
|
|
925
|
+
const redirect = new URL(redirectUrl);
|
|
926
|
+
redirect.pathname = `${CALLBACK_PATH}/${id}`;
|
|
927
|
+
return { url: `${CLIENT_METADATA_BASE_URL}/${id}/client.json`, redirectUrl: redirect.href };
|
|
928
|
+
}
|
|
854
929
|
function createProvider(serverUrl, store, settings, redirectUrl, onRedirect) {
|
|
855
930
|
return new McpOAuthProvider({
|
|
856
931
|
serverUrl,
|
|
857
932
|
redirectUrl,
|
|
858
933
|
clientMetadata: { client_name: settings.clientName ?? APP_NAME },
|
|
934
|
+
clientMetadataDocument: settings.clientRegistration === "cimd" ? (metadata) => clientMetadataDocument(serverUrl, redirectUrl, metadata) : undefined,
|
|
859
935
|
clientId: settings.clientId,
|
|
860
936
|
clientSecret: settings.clientSecret,
|
|
861
937
|
store,
|
|
@@ -878,6 +954,7 @@ function createMcpAuthProvider(options) {
|
|
|
878
954
|
const result = await authorizeMcp(provider, {
|
|
879
955
|
serverUrl,
|
|
880
956
|
resourceMetadataUrl: challenge?.resourceMetadataUrl,
|
|
957
|
+
authorizationServerMetadataUrl: settings.authServerMetadataUrl,
|
|
881
958
|
scope: challenge?.scope,
|
|
882
959
|
fetch: (input, init) => fetch(input, { ...init, signal: AbortSignal.timeout(REFRESH_REQUEST_TIMEOUT_MS) })
|
|
883
960
|
});
|
|
@@ -924,13 +1001,16 @@ class McpSignInCancelledError extends Error {
|
|
|
924
1001
|
this.name = "McpSignInCancelledError";
|
|
925
1002
|
}
|
|
926
1003
|
}
|
|
927
|
-
function
|
|
1004
|
+
function responseFromRedirectUrl(input, state, redirectUrl) {
|
|
928
1005
|
let url;
|
|
929
1006
|
try {
|
|
930
1007
|
url = new URL(input.trim());
|
|
931
1008
|
} catch {
|
|
932
1009
|
throw new Error("Expected the full redirect URL from the browser address bar");
|
|
933
1010
|
}
|
|
1011
|
+
if (url.origin !== redirectUrl.origin || url.pathname !== redirectUrl.pathname) {
|
|
1012
|
+
throw new Error("The redirect URL does not match this sign-in's redirect URI");
|
|
1013
|
+
}
|
|
934
1014
|
const error = url.searchParams.get("error");
|
|
935
1015
|
if (error)
|
|
936
1016
|
throw new Error(url.searchParams.get("error_description") ?? error);
|
|
@@ -939,15 +1019,15 @@ function codeFromRedirectUrl(input, state) {
|
|
|
939
1019
|
const code = url.searchParams.get("code");
|
|
940
1020
|
if (!code)
|
|
941
1021
|
throw new Error("The redirect URL does not contain an authorization code");
|
|
942
|
-
return code;
|
|
1022
|
+
return { code, iss: url.searchParams.get("iss") ?? undefined };
|
|
943
1023
|
}
|
|
944
|
-
async function
|
|
1024
|
+
async function waitForAuthorizationResponse(callback, state, redirectUrl, prompt) {
|
|
945
1025
|
const controller = new AbortController;
|
|
946
|
-
const fromBrowser = callback.waitForCallback(state
|
|
1026
|
+
const fromBrowser = callback.waitForCallback(state, redirectUrl.pathname);
|
|
947
1027
|
const fromUser = prompt.promptForRedirectUrl(controller.signal).then((input) => {
|
|
948
1028
|
if (!input?.trim())
|
|
949
1029
|
throw new McpSignInCancelledError;
|
|
950
|
-
return
|
|
1030
|
+
return responseFromRedirectUrl(input, state, redirectUrl);
|
|
951
1031
|
});
|
|
952
1032
|
try {
|
|
953
1033
|
return await Promise.race([fromBrowser, fromUser]);
|
|
@@ -961,11 +1041,12 @@ async function waitForAuthorizationCode(callback, state, prompt) {
|
|
|
961
1041
|
});
|
|
962
1042
|
}
|
|
963
1043
|
}
|
|
964
|
-
async function listenForCallback(settings, port, required) {
|
|
1044
|
+
async function listenForCallback(settings, extraPaths, port, required) {
|
|
965
1045
|
const options = {
|
|
966
1046
|
host: settings.host,
|
|
967
1047
|
redirectHost: settings.redirectHost,
|
|
968
1048
|
path: settings.path,
|
|
1049
|
+
extraPaths,
|
|
969
1050
|
renderPage: (page) => page.ok ? oauthSuccessHtml("Signed in to the MCP server. You may now close this page.") : oauthErrorHtml(page.message, page.details)
|
|
970
1051
|
};
|
|
971
1052
|
try {
|
|
@@ -979,16 +1060,19 @@ async function listenForCallback(settings, port, required) {
|
|
|
979
1060
|
async function signInMcpServer(options) {
|
|
980
1061
|
const { serverUrl, store, settings } = options;
|
|
981
1062
|
const stored = await store.load();
|
|
1063
|
+
const stepUp = options.challenge?.error === "insufficient_scope";
|
|
982
1064
|
const callbackOptions = callbackSettings(settings);
|
|
983
1065
|
const registered = registeredRedirectUrls(stored?.clientInformation)[0];
|
|
984
1066
|
const preferredPort = callbackOptions.port ?? (registered ? Number(new URL(registered).port) || undefined : undefined);
|
|
985
|
-
const
|
|
1067
|
+
const cimd = settings.clientRegistration === "cimd";
|
|
1068
|
+
const callback = await listenForCallback(callbackOptions, cimd ? [`${CALLBACK_PATH}/${callbackId(serverUrl)}`] : [], preferredPort, callbackOptions.port !== undefined);
|
|
986
1069
|
const redirectUrl = callbackOptions.fixedRedirectUrl ?? callback.redirectUrl;
|
|
987
1070
|
try {
|
|
988
1071
|
if (stored) {
|
|
989
1072
|
const next = { ...stored };
|
|
990
1073
|
delete next.oauthState;
|
|
991
|
-
|
|
1074
|
+
const keepClient = settings.clientId || (cimd ? !stored.clientInformation : registeredRedirectUrls(stored.clientInformation).includes(redirectUrl));
|
|
1075
|
+
if (!keepClient) {
|
|
992
1076
|
delete next.clientInformation;
|
|
993
1077
|
delete next.tokens;
|
|
994
1078
|
delete next.tokensExpireAt;
|
|
@@ -1002,17 +1086,19 @@ async function signInMcpServer(options) {
|
|
|
1002
1086
|
const flow = {
|
|
1003
1087
|
serverUrl,
|
|
1004
1088
|
resourceMetadataUrl: options.challenge?.resourceMetadataUrl,
|
|
1005
|
-
|
|
1089
|
+
authorizationServerMetadataUrl: settings.authServerMetadataUrl,
|
|
1090
|
+
scope: mergeScopes(settings.scope, stepUp ? stepUpScope(stored?.tokens?.scope, options.challenge?.scope) : options.challenge?.scope)
|
|
1006
1091
|
};
|
|
1007
|
-
const skipRefresh =
|
|
1092
|
+
const skipRefresh = stepUp;
|
|
1008
1093
|
if (await authorizeMcp(provider, { ...flow, skipRefresh }) === "AUTHORIZED")
|
|
1009
1094
|
return;
|
|
1010
1095
|
if (!authorizationUrl)
|
|
1011
1096
|
throw new Error("OAuth flow did not produce an authorization URL");
|
|
1012
1097
|
const state = await provider.state();
|
|
1098
|
+
const authorizationRedirectUrl = new URL(authorizationUrl.searchParams.get("redirect_uri") ?? redirectUrl);
|
|
1013
1099
|
options.prompt.showAuthorizationUrl(authorizationUrl);
|
|
1014
|
-
const code = await
|
|
1015
|
-
await authorizeMcp(provider, { ...flow, authorizationCode: code });
|
|
1100
|
+
const { code, iss } = await waitForAuthorizationResponse(callback, state, authorizationRedirectUrl, options.prompt);
|
|
1101
|
+
await authorizeMcp(provider, { ...flow, authorizationCode: code, iss });
|
|
1016
1102
|
} finally {
|
|
1017
1103
|
await callback.close();
|
|
1018
1104
|
}
|
|
@@ -1181,7 +1267,7 @@ class McpServerConnection {
|
|
|
1181
1267
|
const provider = "url" in this.entry.config ? this.entry.config.auth?.provider : undefined;
|
|
1182
1268
|
this.authProvider = url ? createMcpAuthProvider({
|
|
1183
1269
|
serverUrl: url,
|
|
1184
|
-
store: options.credentials.forServer(url),
|
|
1270
|
+
store: options.credentials.forServer(this.entry.name, url),
|
|
1185
1271
|
settings: () => this.oauthSettings(),
|
|
1186
1272
|
onChallenge: (challenge) => {
|
|
1187
1273
|
this.challenge = challenge;
|
|
@@ -1207,7 +1293,9 @@ class McpServerConnection {
|
|
|
1207
1293
|
callbackPort: oauth.callbackPort,
|
|
1208
1294
|
callbackUrl: oauth.callbackUrl,
|
|
1209
1295
|
scope: oauth.scope,
|
|
1210
|
-
clientName: oauth.clientName
|
|
1296
|
+
clientName: oauth.clientName,
|
|
1297
|
+
clientRegistration: oauth.clientRegistration,
|
|
1298
|
+
authServerMetadataUrl: oauth.authServerMetadataUrl ? new URL(oauth.authServerMetadataUrl) : undefined
|
|
1211
1299
|
};
|
|
1212
1300
|
}
|
|
1213
1301
|
getClient() {
|