@desplega.ai/agent-swarm 2.10.0 → 2.11.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/dist/acp-adapter-weaaxey3.js +16 -0
- package/dist/{acp-targets-arrwv4f0.js → acp-targets-5wyy2b9m.js} +9 -9
- package/dist/{actions-y0d2n1c2.js → actions-4nxq386s.js} +24 -23
- package/dist/{agent-fs-provision-tpj7sktd.js → agent-fs-provision-v6enh76w.js} +4 -4
- package/dist/{amp-adapter-vmmnmw8d.js → amp-adapter-ze3x22qn.js} +3 -3
- package/dist/{anthropic-messages-zdca3gv1.js → anthropic-messages-88b7s3n9.js} +177 -25
- package/dist/{app-wb7w45dq.js → app-kyqt8ehw.js} +7 -6
- package/dist/{approval-notifications-7mqr6vbd.js → approval-notifications-a0db0esw.js} +7 -6
- package/dist/{assistant-gf60454p.js → assistant-9g5jzq25.js} +26 -25
- package/dist/{azure-openai-responses-b3y7fz36.js → azure-openai-responses-jeaas6x0.js} +10 -10
- package/dist/{boot-args-schema-qxmd59sr.js → boot-args-schema-d7fme4q1.js} +1 -1
- package/dist/{boot-reembed-wb44vc3s.js → boot-reembed-6wpazmpw.js} +1 -1
- package/dist/{boot-reembed-5tmeskj2.js → boot-reembed-jrwxeye2.js} +1 -1
- package/dist/{boot-scrub-sweep-25bxhnw4.js → boot-scrub-sweep-52h7yntp.js} +2 -2
- package/dist/{boot-seeds-nj9za0vk.js → boot-seeds-kb3dxjex.js} +4 -4
- package/dist/{boxd-wn235q80.js → boxd-jrrmkv3w.js} +2 -2
- package/dist/{claude-adapter-d3krpdyb.js → claude-adapter-0c0y8fqp.js} +8 -8
- package/dist/{claude-managed-adapter-t8nfgcgz.js → claude-managed-adapter-w2es07qq.js} +4 -4
- package/dist/{claude-managed-setup-7y4pwd81.js → claude-managed-setup-9ssb7ct4.js} +4 -4
- package/dist/{claude-sdk-session-d138zy0e.js → claude-sdk-session-p6t0gyse.js} +10941 -10412
- package/dist/{cli-p0n7b5rz.js → cli-075ccjh6.js} +344 -130
- package/dist/{cli-3caf7pmg.js → cli-0bgj4rh5.js} +3 -3
- package/dist/{cli-7r162fxe.js → cli-14xdms9a.js} +23 -17
- package/dist/{cli-rqx70rcz.js → cli-17qzb39j.js} +5 -2
- package/dist/{cli-y4ccxtz5.js → cli-1h4njv9y.js} +144 -6
- package/dist/{cli-6ym4jhzp.js → cli-27fat7st.js} +7 -7
- package/dist/{cli-k3q2va86.js → cli-2aacfdcn.js} +5 -5
- package/dist/{cli-vq2eg24x.js → cli-2gvdvsxj.js} +3 -3
- package/dist/{cli-sb4426be.js → cli-2jtfm8kh.js} +5 -5
- package/dist/{cli-6ehs4mta.js → cli-2z2c4k6q.js} +18 -4
- package/dist/{cli-6237rnyr.js → cli-3bpr3wks.js} +1 -1
- package/dist/{cli-5qhfv9rw.js → cli-453497a0.js} +44 -17
- package/dist/{cli-2rnd5j3t.js → cli-4aswccje.js} +2 -2
- package/dist/{cli-4ymxrwg5.js → cli-4dyzzkfb.js} +2 -2
- package/dist/{cli-p0c3vtch.js → cli-4g323fjh.js} +772 -515
- package/dist/{cli-3kd08rej.js → cli-4jjrhy48.js} +1 -1
- package/dist/{cli-fcfbct2j.js → cli-4kzp7r0q.js} +5 -5
- package/dist/{cli-kxn3747f.js → cli-4se3x6qm.js} +1 -26
- package/dist/{cli-zeh2mhkg.js → cli-5ptj757f.js} +1 -1
- package/dist/{cli-539h29es.js → cli-6a3j25xd.js} +224 -189
- package/dist/{cli-hnamkvnc.js → cli-6c9ve77f.js} +2 -2
- package/dist/{cli-3et6fmfe.js → cli-6n7y5ypy.js} +1 -1
- package/dist/{cli-8y43jx2r.js → cli-6p8p2e6r.js} +16 -9
- package/dist/{cli-zk7v5s89.js → cli-6tvh1fwq.js} +3 -3
- package/dist/{cli-p74md7t8.js → cli-7b7rxz22.js} +13 -15
- package/dist/{cli-5a6pqy45.js → cli-7e8sxqv5.js} +1 -1
- package/dist/{cli-6037prsx.js → cli-892y3vfp.js} +13 -13
- package/dist/cli-8mfdbdhe.js +43 -0
- package/dist/{cli-s1zqk1aj.js → cli-8zmpwe79.js} +15 -9
- package/dist/{cli-zcfpsfzf.js → cli-96234j5w.js} +3 -3
- package/dist/{cli-1z4qggfe.js → cli-9fvk9mv8.js} +30 -21
- package/dist/{cli-7mv4h3sn.js → cli-9g12h1aq.js} +2 -2
- package/dist/{cli-aw83sr40.js → cli-9knhkkgr.js} +3 -3
- package/dist/{cli-5mpy301f.js → cli-9t7syepg.js} +1 -1
- package/dist/{cli-qj39vrc6.js → cli-9yjhshah.js} +1 -1
- package/dist/{cli-6cwr32fe.js → cli-a02habn6.js} +422 -140
- package/dist/{cli-7evph51z.js → cli-a49frv85.js} +2 -2
- package/dist/{cli-3f8zbtqa.js → cli-a6q6x15h.js} +9 -8
- package/dist/{cli-j6te8keb.js → cli-atm0hkes.js} +8 -8
- package/dist/{cli-9fjr27ez.js → cli-b82a13ga.js} +13 -13
- package/dist/{cli-7zm3b3f5.js → cli-bf0t77nf.js} +1 -1
- package/dist/{cli-2xv18ywz.js → cli-bmqp0ser.js} +2 -2
- package/dist/{cli-mk7c5ac4.js → cli-bq97k63w.js} +2 -2
- package/dist/{cli-vfqvrd82.js → cli-cstggwq7.js} +2 -2
- package/dist/{cli-md50mj0r.js → cli-czvvnfr9.js} +3 -3
- package/dist/{cli-b6px1k1q.js → cli-dd2k2mcd.js} +1 -1
- package/dist/{cli-fq2rr3jb.js → cli-djt6wmrc.js} +6 -6
- package/dist/{cli-tsa40663.js → cli-ebqx630g.js} +3 -3
- package/dist/{cli-z0m452jr.js → cli-f7dhm7hh.js} +1 -1
- package/dist/{cli-mys27d03.js → cli-f8yhybxr.js} +3 -3
- package/dist/{cli-5gpqgs8b.js → cli-fwjwkw66.js} +2 -2
- package/dist/{cli-gabsjg8x.js → cli-g56fxddf.js} +1 -1
- package/dist/{cli-y8p78ekx.js → cli-h2qtafm4.js} +18 -18
- package/dist/{cli-psffsanb.js → cli-ha4ek2nb.js} +6 -1
- package/dist/{cli-th1dkc2v.js → cli-hnh8erra.js} +2 -2
- package/dist/{cli-w16kwbzw.js → cli-htymm48w.js} +1 -1
- package/dist/{cli-124ntmf0.js → cli-j2r1apqm.js} +138 -59
- package/dist/{cli-43ms35q9.js → cli-k3c13za2.js} +3 -3
- package/dist/{cli-54vrpgm0.js → cli-k3facve0.js} +8 -5
- package/dist/{cli-v8z0yga9.js → cli-k4r5sfaj.js} +4 -4
- package/dist/{cli-91pkxres.js → cli-kbm659dk.js} +2 -2
- package/dist/{cli-q5srsxq2.js → cli-m00c47q6.js} +110 -27
- package/dist/{cli-3aaeb78m.js → cli-mhrr4d5b.js} +95 -10
- package/dist/{cli-xqdz5cqm.js → cli-mz7ycqn8.js} +1 -0
- package/dist/{cli-qrta34nb.js → cli-n6ygvrrm.js} +4 -4
- package/dist/{cli-k5yewqgd.js → cli-nbakg5xh.js} +3 -3
- package/dist/{cli-nstkanmx.js → cli-nc39ym5q.js} +8 -8
- package/dist/{cli-01k6wpr9.js → cli-p1a4khta.js} +7 -7
- package/dist/{cli-t9ga4qmb.js → cli-p8zqbbt1.js} +40 -33
- package/dist/{cli-v46zsvqk.js → cli-ph95yejc.js} +2 -2
- package/dist/{cli-k6nejceb.js → cli-q4z9s6zs.js} +2 -2
- package/dist/{cli-kbtzfrxj.js → cli-q71g5q39.js} +3 -3
- package/dist/{cli-vs9vdpy0.js → cli-qncx2r0s.js} +1 -1
- package/dist/{cli-hg42n3hx.js → cli-qrzq3hvg.js} +8 -8
- package/dist/{cli-x40a0w9j.js → cli-r813c7rb.js} +1 -1
- package/dist/{cli-kpgcm7xy.js → cli-ramn8jae.js} +1 -1
- package/dist/{cli-cc93xzes.js → cli-raqw9fw9.js} +28 -17
- package/dist/cli-rhsc2zyx.js +68 -0
- package/dist/{cli-8st34zhr.js → cli-rpmw4fsv.js} +57 -19
- package/dist/{cli-had1p04a.js → cli-rwgwen5v.js} +4 -4
- package/dist/{cli-tr27kwyg.js → cli-rytq7dm2.js} +261 -6
- package/dist/{cli-s1khw52h.js → cli-s9twe4x0.js} +66 -17
- package/dist/{cli-2v2zdm0a.js → cli-t2s7j5cy.js} +2 -2
- package/dist/{cli-nv4xsvmk.js → cli-tb4j757d.js} +7 -7
- package/dist/{cli-q2d3e1k1.js → cli-thd3005a.js} +1 -1
- package/dist/cli-tsfkcd4v.js +30 -0
- package/dist/{cli-jrbq4djp.js → cli-v3zcnr8g.js} +1 -1
- package/dist/{cli-zfqg6fzn.js → cli-vbppqvte.js} +3 -3
- package/dist/{cli-qx4f057j.js → cli-vy3fn0mz.js} +4 -4
- package/dist/{cli-7sf9sb0w.js → cli-w5dar1bk.js} +1 -1
- package/dist/{cli-w1q68d8x.js → cli-wz4e5am2.js} +9 -9
- package/dist/{cli-m9cvf7vs.js → cli-xqbqwpxr.js} +14 -14
- package/dist/{cli-2spnz7ye.js → cli-ynph3b70.js} +11137 -8332
- package/dist/{cli-43evxwj4.js → cli-yvzxbztc.js} +9 -4
- package/dist/{cli-vsw91x06.js → cli-yzxqwcvq.js} +3 -6
- package/dist/{cli-wafmk3fn.js → cli-zb1hff00.js} +12 -12
- package/dist/{cli-yab6sh8p.js → cli-zcghfsdg.js} +23 -4
- package/dist/{cli-wwp1bd3n.js → cli-zhn4r1rz.js} +519 -75
- package/dist/{cli-tvgqesec.js → cli-zqq57pgx.js} +4 -4
- package/dist/cli.js +28 -27
- package/dist/{cloudflare-workers-ai-system-one-4aysy6rh.js → cloudflare-workers-ai-system-one-w3m0fbf8.js} +2 -2
- package/dist/{codex-adapter-exfdbj73.js → codex-adapter-ssahg4h4.js} +8 -8
- package/dist/{codex-hook-59atdwd8.js → codex-hook-aqtj17yr.js} +1 -1
- package/dist/{codex-login-a239g1ah.js → codex-login-9c7aggxe.js} +1 -1
- package/dist/{codex-session-runner-xhznc4g3.js → codex-session-runner-xn63q3h7.js} +9 -9
- package/dist/{commands-d8g349v4.js → commands-ctey7tr5.js} +3 -3
- package/dist/{controller-mwgdmb8y.js → controller-rqhbppg9.js} +4 -4
- package/dist/{controllers-connect-5v7qx04j.js → controllers-connect-w3qbpbt1.js} +22 -21
- package/dist/{core-sxy4epp2.js → core-df1n049h.js} +19 -18
- package/dist/{cursor-adapter-p2q5h35d.js → cursor-adapter-r819hf1a.js} +2 -2
- package/dist/{db-wcw0b2j8.js → db-2ah39cyx.js} +2 -2
- package/dist/{db-qpganbeb.js → db-p5drc1d1.js} +3 -3
- package/dist/{devin-adapter-zp4tqq53.js → devin-adapter-bc6g0x29.js} +1 -1
- package/dist/{dispatcher-8d8s49yz.js → dispatcher-x6w14pde.js} +19 -18
- package/dist/{docker-09tkkg0n.js → docker-6c4reetq.js} +51 -14
- package/dist/{dsh-adapter-me0twn13.js → dsh-adapter-h8qn14n4.js} +2 -2
- package/dist/{e2b-sm28k0k3.js → e2b-jg7kyyef.js} +6 -6
- package/dist/{e2b-3v1e745x.js → e2b-z4ec0qve.js} +3 -3
- package/dist/{easter-egg-3d-wv7w5ty6.js → easter-egg-3d-1y6r9gxy.js} +1 -1
- package/dist/{embedding-space-e48xchqa.js → embedding-space-z6ptw3jk.js} +6 -6
- package/dist/{embeddings-tgq2afbq.js → embeddings-0sxb1d2h.js} +1 -1
- package/dist/{event-bus-xr83x566.js → event-bus-swr88jg5.js} +1 -1
- package/dist/{execute-8rhwrk7f.js → execute-6m1ex8ce.js} +8 -4
- package/dist/{external-channel-8bt3j2pm.js → external-channel-ezer7pk0.js} +2 -2
- package/dist/fx-adapter-zwmps9re.js +19 -0
- package/dist/{google-generative-ai-bh0djqjp.js → google-generative-ai-sw77egmr.js} +9 -9
- package/dist/{google-vertex-prjbw8dj.js → google-vertex-rrw93g8h.js} +9 -9
- package/dist/grok-adapter-q0avf919.js +19 -0
- package/dist/handlers-g5jq0e4q.js +36 -0
- package/dist/{heartbeat-x0056ra5.js → heartbeat-6c4fr49t.js} +22 -21
- package/dist/{hook-mrd2ayxv.js → hook-02rt5tvq.js} +8 -8
- package/dist/{hook-a7vmn2st.js → hook-t1c5avbv.js} +5 -5
- package/dist/{http-ym9c5svp.js → http-qa3h32a1.js} +2049 -148
- package/dist/index-1f6m47mq.js +37 -0
- package/dist/index-1p1mpqda.js +36 -0
- package/dist/{index-p46tvwtx.js → index-akbgsdhh.js} +25 -24
- package/dist/{index-ny60jcat.js → index-e42j998x.js} +16 -13
- package/dist/{index-b5wgnm78.js → index-kdmkfjt7.js} +4 -4
- package/dist/{index-01ns1pkw.js → index-kqv9ebfj.js} +1 -1
- package/dist/{index-9myfj74s.js → index-kzdqn3dd.js} +3 -3
- package/dist/{index-4a0670yh.js → index-p2f5xg64.js} +6 -6
- package/dist/{index-x6azjwm8.js → index-qpjk2hxk.js} +1 -1
- package/dist/index-tnkd410q.js +41 -0
- package/dist/{k8s-m56sw868.js → k8s-7jrh5va2.js} +73 -14
- package/dist/{keepalive-7yxg8z4c.js → keepalive-jmf6pn8c.js} +4 -4
- package/dist/lead-m5e7xt93.js +75 -0
- package/dist/{llama-cpp-classify-nfgswa1m.js → llama-cpp-classify-yvb8vh7w.js} +2 -2
- package/dist/{maintenance-6tefxmk1.js → maintenance-g7v15tj1.js} +1 -1
- package/dist/{mistral-conversations-tm2vd4gc.js → mistral-conversations-w4bncwbt.js} +7 -7
- package/dist/{node-7qsx5kvm.js → node-z67yjre7.js} +19 -13
- package/dist/{oauth-refresh-sweep-70cavc3a.js → oauth-refresh-sweep-ywgf8tbr.js} +3 -3
- package/dist/{onboard-fja65z08.js → onboard-m3fedypq.js} +3 -3
- package/dist/{openai-codex-responses-sxjv60xx.js → openai-codex-responses-70g39cgz.js} +20 -14
- package/dist/{openai-completions-0c7qnhsx.js → openai-completions-cv3hp4h5.js} +18 -11
- package/dist/{openai-decisions-ytp6w6xh.js → openai-decisions-fyq1p9f9.js} +2 -2
- package/dist/{openai-responses-a7h29chp.js → openai-responses-trsvnks6.js} +13 -11
- package/dist/{opencode-adapter-hakkm7yh.js → opencode-adapter-19ktcbb9.js} +7 -7
- package/dist/{openrouter-images-xr9gme9x.js → openrouter-images-0jj12a2q.js} +6 -6
- package/dist/{otel-impl-7zhnt6gj.js → otel-impl-3ehm1hgc.js} +2 -2
- package/dist/{pending-h01yzpx4.js → pending-fwj2fatd.js} +20 -19
- package/dist/{pi-messages-2j0fpqwq.js → pi-messages-zk3g4esn.js} +1 -1
- package/dist/{pi-mono-adapter-f52hz743.js → pi-mono-adapter-xdeesvc4.js} +18 -17
- package/dist/{pricing-refresh-fzxvk2zf.js → pricing-refresh-4j8dzvxg.js} +2 -2
- package/dist/{rbac-roles-9v6vhgbs.js → rbac-roles-8msjr07m.js} +3 -3
- package/dist/{rbac-roles-hfgh8sba.js → rbac-roles-n7t2acv8.js} +2 -2
- package/dist/{render-v2-1rgspxzf.js → render-v2-j7qggj8h.js} +7 -6
- package/dist/{resume-tqy61x24.js → resume-hj1mn65y.js} +9 -8
- package/dist/{runtime-exkxyx5f.js → runtime-z31mdsgv.js} +2 -2
- package/dist/{session-access-3act7vt4.js → session-access-w38fh09a.js} +4 -4
- package/dist/{session-source-backfill-82qe7fqq.js → session-source-backfill-ax6qxv20.js} +3 -3
- package/dist/{setup-ry1vfdef.js → setup-dsqmpfcr.js} +1 -1
- package/dist/thread-buffer-nf55vwx3.js +39 -0
- package/dist/tree-visibility-6vqmnr71.js +24 -0
- package/dist/{typesafe-system-one-vcfj2ak8.js → typesafe-system-one-qkvkgrcz.js} +2 -2
- package/dist/{user-merge-jobs-bx6bf7db.js → user-merge-jobs-mvheb3ed.js} +3 -3
- package/dist/{virtual-modules-s0rjzcqq.js → virtual-modules-w2qk2wew.js} +32 -10
- package/dist/{work-objects-z2e5tv03.js → work-objects-4ahy5es5.js} +22 -21
- package/dist/worker-ews1nyhw.js +75 -0
- package/dist/{worker-follow-up-y3xeg89w.js → worker-follow-up-1gs4aw7y.js} +19 -18
- package/dist/{x-wg164ss9.js → x-3wr8c5sh.js} +2 -2
- package/openapi.json +995 -49
- package/package.json +9 -8
- package/src/be/db/request-composition.ts +190 -0
- package/src/be/db/runtime.ts +15 -0
- package/src/be/db/slack-trees.ts +220 -10
- package/src/be/db/tasks/human-free.ts +3 -2
- package/src/be/db/workflow-run-retention.ts +101 -0
- package/src/be/db-client.ts +23 -1
- package/src/be/db-retention-defaults.ts +46 -0
- package/src/be/db-retention.ts +55 -6
- package/src/be/mcp-events/catalog.ts +108 -0
- package/src/be/mcp-events/dispatcher.ts +202 -0
- package/src/be/mcp-events/protocol.ts +296 -0
- package/src/be/mcp-events/store.ts +231 -0
- package/src/be/mcp-events/webhook.ts +226 -0
- package/src/be/memory/providers/sqlite-store.ts +110 -24
- package/src/be/memory/review-recall-filter.ts +22 -0
- package/src/be/memory/search-candidates.ts +5 -7
- package/src/be/memory/types.ts +5 -0
- package/src/be/migrations/322_runtime_pool_workspace.sql +8 -0
- package/src/be/migrations/323_slack_task_tree_visibility.sql +9 -0
- package/src/be/migrations/326_slack_reconcile_pages.sql +13 -0
- package/src/be/migrations/327_mcp_event_subscriptions.sql +57 -0
- package/src/be/migrations/329_workflow_run_retention.sql +9 -0
- package/src/be/migrations/330_request_composition.sql +22 -0
- package/src/be/model-profile-check.ts +1 -1
- package/src/be/multi-runtime.ts +32 -4
- package/src/be/runtime-pools/controllers.ts +18 -3
- package/src/be/runtime-pools/db.ts +15 -4
- package/src/be/runtime-pools/supervisor.ts +42 -2
- package/src/be/swarm-config-guard.ts +10 -2
- package/src/commands/context-preamble.ts +11 -4
- package/src/commands/credential-outcome-report.ts +33 -9
- package/src/commands/e2b-stack-wizard.tsx +12 -6
- package/src/commands/runner.ts +116 -12
- package/src/extensions/catalog.generated.json +1 -1
- package/src/github/app.ts +59 -14
- package/src/http/all-routes.ts +2 -0
- package/src/http/config.ts +2 -1
- package/src/http/core.ts +2 -0
- package/src/http/github-token.ts +66 -0
- package/src/http/index.ts +21 -0
- package/src/http/mcp-user.ts +11 -8
- package/src/http/mcp.ts +58 -42
- package/src/http/prompt-templates.ts +1 -0
- package/src/http/request-composition.ts +310 -0
- package/src/http/tasks.ts +6 -1
- package/src/http/tool-schema-estimate.ts +95 -0
- package/src/http/workflows.ts +29 -11
- package/src/integrations/chat-sdk/inbound.ts +2 -2
- package/src/prompts/base-prompt.ts +133 -7
- package/src/prompts/resolver.ts +41 -2
- package/src/providers/amp-adapter.ts +1 -1
- package/src/providers/opencode-adapter.ts +72 -1
- package/src/providers/opencode-swarm-plugin.ts +22 -3
- package/src/providers/pi-mono-adapter.ts +1 -0
- package/src/providers/pi-mono-extension.ts +71 -0
- package/src/providers/pricing-sources.md +4 -0
- package/src/providers/request-composition-hook.ts +312 -0
- package/src/providers/types.ts +5 -0
- package/src/runtime-providers/controller-protocol.ts +7 -0
- package/src/runtime-providers/docker.ts +80 -12
- package/src/runtime-providers/k8s.ts +111 -6
- package/src/runtime-providers/types.ts +17 -0
- package/src/scheduler/scheduler.ts +1 -1
- package/src/server-user.ts +16 -1
- package/src/slack/ack.ts +10 -5
- package/src/slack/actions.ts +3 -3
- package/src/slack/app.ts +2 -0
- package/src/slack/assistant.ts +4 -4
- package/src/slack/blocks.ts +3 -3
- package/src/slack/handlers.ts +3 -3
- package/src/slack/reaction-shortcode.ts +23 -2
- package/src/slack/render-v2.ts +297 -200
- package/src/slack/responses.ts +7 -5
- package/src/slack/thread-buffer.ts +3 -3
- package/src/slack/tree-visibility.ts +64 -0
- package/src/tasks/worker-follow-up.ts +127 -17
- package/src/tests/azure-devops-outbound.test.ts +47 -14
- package/src/tests/base-prompt.test.ts +149 -1
- package/src/tests/check-playwright-version.test.ts +33 -0
- package/src/tests/context-preamble-budget.test.ts +65 -0
- package/src/tests/credential-outcome-report.test.ts +81 -1
- package/src/tests/db-client.test.ts +22 -0
- package/src/tests/db-retention-defaults.test.ts +244 -0
- package/src/tests/db-retention.test.ts +2 -1
- package/src/tests/db-runtime.test.ts +2 -1
- package/src/tests/deploy-release-dispatch.test.ts +332 -0
- package/src/tests/e2b-stack-wizard.test.tsx +156 -0
- package/src/tests/entrypoint-chown-no-follow.test.ts +69 -0
- package/src/tests/entrypoint-repo-clone-target.test.ts +112 -0
- package/src/tests/env-flag.test.ts +4 -2
- package/src/tests/event-loop-lag.test.ts +12 -18
- package/src/tests/extensions-example-slack-reply-gate.test.ts +15 -0
- package/src/tests/fixtures/base-prompt-baseline-cases.ts +78 -0
- package/src/tests/fixtures/base-prompt-baseline.json +18 -0
- package/src/tests/github-app-worker-auth-helper.test.ts +325 -0
- package/src/tests/github-installation-token-route.test.ts +199 -0
- package/src/tests/mcp-user-events.test.ts +708 -0
- package/src/tests/memory-key-paths.test.ts +4 -1
- package/src/tests/memory-search-stall.test.ts +421 -0
- package/src/tests/migration-322-runtime-pool-workspace.test.ts +116 -0
- package/src/tests/migration-329-workflow-run-retention.test.ts +32 -0
- package/src/tests/model-profile-fallbacks.test.ts +236 -2
- package/src/tests/opencode-adapter.test.ts +86 -0
- package/src/tests/pi-mono-extension.test.ts +168 -0
- package/src/tests/preload-env.test.ts +61 -1
- package/src/tests/preload.ts +22 -0
- package/src/tests/prompt-template-resolver.test.ts +85 -0
- package/src/tests/reload-config.test.ts +45 -0
- package/src/tests/request-composition.test.ts +447 -0
- package/src/tests/runner-max-concurrent.test.ts +86 -0
- package/src/tests/runtime-pools-db.test.ts +80 -0
- package/src/tests/runtime-provider-registration.test.ts +8 -0
- package/src/tests/runtime-providers-docker.test.ts +192 -1
- package/src/tests/runtime-providers-k8s.test.ts +127 -0
- package/src/tests/runtime-remote-controller.test.ts +64 -1
- package/src/tests/runtime-supervisor.test.ts +101 -0
- package/src/tests/script-connections.test.ts +8 -0
- package/src/tests/slack-blocks.test.ts +18 -0
- package/src/tests/slack-empty-icon-config.test.ts +113 -0
- package/src/tests/slack-reaction-config.test.ts +38 -2
- package/src/tests/slack-render-v2-query-plans.test.ts +100 -1
- package/src/tests/slack-render-v2-reconcile.test.ts +75 -4
- package/src/tests/slack-render-v2.test.ts +683 -11
- package/src/tests/swarm-config-reserved-keys.test.ts +1 -0
- package/src/tests/task-session-prompts.test.ts +37 -0
- package/src/tests/user-delete-perf.test.ts +36 -9
- package/src/tests/webhook-filter.test.ts +327 -0
- package/src/tests/workflow-async-v2.test.ts +19 -16
- package/src/tests/workflow-definition-telemetry.test.ts +15 -5
- package/src/tests/workflow-e2e.test.ts +1 -9
- package/src/tests/workflow-finalization-races.test.ts +553 -0
- package/src/tests/workflow-foreach.test.ts +2 -0
- package/src/tests/workflow-hitl-routing.test.ts +26 -20
- package/src/tests/workflow-http-v2.test.ts +105 -2
- package/src/tests/workflow-idempotency.test.ts +41 -0
- package/src/tests/workflow-mcp-webhook-filter.test.ts +214 -0
- package/src/tests/workflow-parallel-park.test.ts +297 -0
- package/src/tests/workflow-retry-v2.test.ts +57 -21
- package/src/tests/workflow-retry-validation.test.ts +13 -13
- package/src/tests/workflow-runs-retention.test.ts +533 -0
- package/src/tests/workflow-script-principal.test.ts +7 -2
- package/src/tests/workflow-tla-races.test.ts +7 -2
- package/src/tests/workflow-triggers-v2.test.ts +201 -0
- package/src/tests/workflow-wait-builtin-events.test.ts +3 -1
- package/src/tests/workflow-wait-event.test.ts +28 -2
- package/src/tests/workflow-wait-poller.test.ts +94 -0
- package/src/tests/workflow-wait-time.test.ts +7 -3
- package/src/tests/workflow-wait.test.ts +26 -0
- package/src/tests/workflow-wait.ts +44 -0
- package/src/tools/workflows/create-workflow.ts +7 -3
- package/src/tools/workflows/update-workflow.ts +7 -3
- package/src/types.ts +200 -2
- package/src/utils/credentials.ts +7 -0
- package/src/workflows/checkpoint.ts +18 -0
- package/src/workflows/engine.ts +38 -10
- package/src/workflows/foreach-driver.ts +42 -4
- package/src/workflows/recovery.ts +6 -1
- package/src/workflows/resume.ts +11 -3
- package/src/workflows/retry-poller.ts +17 -4
- package/src/workflows/successor-routing.ts +108 -0
- package/src/workflows/task-step-routing.ts +5 -2
- package/src/workflows/triggers.ts +21 -36
- package/src/workflows/wait-poller.ts +6 -2
- package/src/workflows/webhook-filter.ts +203 -0
- package/templates/extensions/slack-reply-gate/hooks.ts +8 -4
- package/templates/skills/swarm-docs/content.md +2 -0
- package/dist/acp-adapter-bht22g3k.js +0 -16
- package/dist/fx-adapter-adtdb3jb.js +0 -19
- package/dist/grok-adapter-accnn9km.js +0 -19
- package/dist/handlers-1x77561e.js +0 -35
- package/dist/index-48qzcqzj.js +0 -35
- package/dist/index-rkvaambe.js +0 -36
- package/dist/index-xj1mq27m.js +0 -40
- package/dist/lead-enzn86bz.js +0 -74
- package/dist/thread-buffer-3x93yexa.js +0 -38
- package/dist/worker-zfcv2wbf.js +0 -74
|
@@ -4,17 +4,18 @@ import {
|
|
|
4
4
|
VERSION,
|
|
5
5
|
getAgentDir,
|
|
6
6
|
require_proper_lockfile,
|
|
7
|
-
|
|
7
|
+
sliceTail,
|
|
8
8
|
mcpNamespace,
|
|
9
|
+
isClientMetadataDocumentCallback,
|
|
9
10
|
resolveConfigValueOrThrow,
|
|
10
11
|
resolveHeadersOrThrow,
|
|
11
12
|
FileAuthStorageBackend
|
|
12
|
-
} from "./cli-
|
|
13
|
+
} from "./cli-ynph3b70.js";
|
|
13
14
|
import {
|
|
14
15
|
oauthSuccessHtml,
|
|
15
16
|
oauthErrorHtml,
|
|
16
17
|
init_oauth_page
|
|
17
|
-
} from "./cli-
|
|
18
|
+
} from "./cli-a02habn6.js";
|
|
18
19
|
import {
|
|
19
20
|
__toESM
|
|
20
21
|
} from "./cli-242037k3.js";
|
|
@@ -563,8 +564,77 @@ class TransportEvents {
|
|
|
563
564
|
}
|
|
564
565
|
}
|
|
565
566
|
|
|
566
|
-
// node_modules/@earendil-works/pi-mcp/dist/transports/
|
|
567
|
+
// node_modules/@earendil-works/pi-mcp/dist/transports/lines.js
|
|
567
568
|
var DEFAULT_MAX_STDERR_BYTES = 64 * 1024;
|
|
569
|
+
|
|
570
|
+
class JsonRpcLineReader {
|
|
571
|
+
options;
|
|
572
|
+
stdoutChunks = [];
|
|
573
|
+
stdoutPendingBytes = 0;
|
|
574
|
+
stderrBuffer = Buffer.alloc(0);
|
|
575
|
+
constructor(options) {
|
|
576
|
+
this.options = options;
|
|
577
|
+
}
|
|
578
|
+
get stderr() {
|
|
579
|
+
return this.stderrBuffer.toString("utf8");
|
|
580
|
+
}
|
|
581
|
+
readStdout(chunk) {
|
|
582
|
+
const data = Buffer.from(chunk.buffer, chunk.byteOffset, chunk.byteLength);
|
|
583
|
+
const maxMessageBytes = this.options.maxMessageBytes ?? DEFAULT_MAX_MESSAGE_BYTES;
|
|
584
|
+
let start = 0;
|
|
585
|
+
while (true) {
|
|
586
|
+
const newline = data.indexOf(10, start);
|
|
587
|
+
if (newline < 0) {
|
|
588
|
+
if (start < data.length) {
|
|
589
|
+
this.stdoutChunks.push(Buffer.from(data.subarray(start)));
|
|
590
|
+
this.stdoutPendingBytes += data.length - start;
|
|
591
|
+
}
|
|
592
|
+
if (this.stdoutPendingBytes > maxMessageBytes) {
|
|
593
|
+
this.stdoutChunks = [];
|
|
594
|
+
this.stdoutPendingBytes = 0;
|
|
595
|
+
this.options.onError(new Error(`MCP stdio message exceeds ${maxMessageBytes} bytes`));
|
|
596
|
+
}
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
599
|
+
let line = data.subarray(start, newline);
|
|
600
|
+
if (this.stdoutChunks.length > 0) {
|
|
601
|
+
this.stdoutChunks.push(line);
|
|
602
|
+
line = Buffer.concat(this.stdoutChunks, this.stdoutPendingBytes + line.length);
|
|
603
|
+
this.stdoutChunks = [];
|
|
604
|
+
this.stdoutPendingBytes = 0;
|
|
605
|
+
}
|
|
606
|
+
start = newline + 1;
|
|
607
|
+
if (line.length > maxMessageBytes) {
|
|
608
|
+
this.options.onError(new Error(`MCP stdio message exceeds ${maxMessageBytes} bytes`));
|
|
609
|
+
continue;
|
|
610
|
+
}
|
|
611
|
+
const text = line.toString("utf8").replace(/\r$/, "");
|
|
612
|
+
if (!text.trim())
|
|
613
|
+
continue;
|
|
614
|
+
try {
|
|
615
|
+
this.options.onMessage(parseJsonRpcMessage(JSON.parse(text)));
|
|
616
|
+
} catch (error) {
|
|
617
|
+
this.options.onError(error);
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
readStderr(chunk) {
|
|
622
|
+
const maxStderrBytes = this.options.maxStderrBytes ?? DEFAULT_MAX_STDERR_BYTES;
|
|
623
|
+
this.stderrBuffer = Buffer.concat([this.stderrBuffer, chunk]);
|
|
624
|
+
if (this.stderrBuffer.length > maxStderrBytes)
|
|
625
|
+
this.stderrBuffer = this.stderrBuffer.subarray(-maxStderrBytes);
|
|
626
|
+
this.options.onStderr?.(Buffer.from(chunk.buffer, chunk.byteOffset, chunk.byteLength).toString("utf8"));
|
|
627
|
+
}
|
|
628
|
+
end() {
|
|
629
|
+
if (Buffer.concat(this.stdoutChunks).toString("utf8").trim()) {
|
|
630
|
+
this.options.onError(new Error("MCP stdio server closed with an incomplete JSON-RPC message"));
|
|
631
|
+
}
|
|
632
|
+
this.stdoutChunks = [];
|
|
633
|
+
this.stdoutPendingBytes = 0;
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
// node_modules/@earendil-works/pi-mcp/dist/transports/stdio.js
|
|
568
638
|
var DEFAULT_CLOSE_TIMEOUT_MS = 2000;
|
|
569
639
|
var STDIN_CLOSE_GRACE_MS = 500;
|
|
570
640
|
var USE_PROCESS_GROUPS = process2.platform !== "win32";
|
|
@@ -604,19 +674,25 @@ function installExitHook() {
|
|
|
604
674
|
class StdioTransport extends TransportEvents {
|
|
605
675
|
options;
|
|
606
676
|
child;
|
|
607
|
-
|
|
608
|
-
stderrBuffer = Buffer.alloc(0);
|
|
677
|
+
lines;
|
|
609
678
|
started = false;
|
|
610
679
|
closed = false;
|
|
611
680
|
constructor(options) {
|
|
612
681
|
super();
|
|
613
682
|
this.options = Object.freeze({ ...options, args: options.args ? [...options.args] : undefined });
|
|
683
|
+
this.lines = new JsonRpcLineReader({
|
|
684
|
+
maxMessageBytes: this.options.maxMessageBytes,
|
|
685
|
+
maxStderrBytes: this.options.maxStderrBytes,
|
|
686
|
+
onStderr: this.options.onStderr,
|
|
687
|
+
onMessage: (message) => this.emitMessage(message),
|
|
688
|
+
onError: (error) => this.emitError(error)
|
|
689
|
+
});
|
|
614
690
|
}
|
|
615
691
|
get pid() {
|
|
616
692
|
return this.child?.pid;
|
|
617
693
|
}
|
|
618
694
|
get stderr() {
|
|
619
|
-
return this.
|
|
695
|
+
return this.lines.stderr;
|
|
620
696
|
}
|
|
621
697
|
async start() {
|
|
622
698
|
if (this.started)
|
|
@@ -637,22 +713,19 @@ class StdioTransport extends TransportEvents {
|
|
|
637
713
|
if (USE_PROCESS_GROUPS && pid !== undefined) {
|
|
638
714
|
installExitHook();
|
|
639
715
|
liveProcessGroups.add(pid);
|
|
640
|
-
child.once("
|
|
716
|
+
child.once("close", () => liveProcessGroups.delete(pid));
|
|
641
717
|
}
|
|
642
|
-
child.stdout?.on("data", (chunk) => this.
|
|
718
|
+
child.stdout?.on("data", (chunk) => this.lines.readStdout(chunk));
|
|
643
719
|
child.stdout?.on("error", (error) => this.emitError(error));
|
|
644
720
|
child.stdin?.on("error", (error) => {
|
|
645
721
|
if (!this.closed)
|
|
646
722
|
this.emitError(error);
|
|
647
723
|
});
|
|
648
|
-
child.stderr?.on("data", (chunk) => this.
|
|
724
|
+
child.stderr?.on("data", (chunk) => this.lines.readStderr(chunk));
|
|
649
725
|
child.stderr?.on("error", (error) => this.emitError(error));
|
|
650
726
|
child.on("close", () => {
|
|
651
727
|
this.child = undefined;
|
|
652
|
-
|
|
653
|
-
this.emitError(new Error("MCP stdio server closed with an incomplete JSON-RPC message"));
|
|
654
|
-
}
|
|
655
|
-
this.stdoutBuffer = Buffer.alloc(0);
|
|
728
|
+
this.lines.end();
|
|
656
729
|
this.emitClose();
|
|
657
730
|
});
|
|
658
731
|
await new Promise((resolve, reject) => {
|
|
@@ -691,7 +764,7 @@ class StdioTransport extends TransportEvents {
|
|
|
691
764
|
this.emitClose();
|
|
692
765
|
return;
|
|
693
766
|
}
|
|
694
|
-
if (child.exitCode !== null || child.signalCode !== null) {
|
|
767
|
+
if (!USE_PROCESS_GROUPS && (child.exitCode !== null || child.signalCode !== null)) {
|
|
695
768
|
child.stdin?.end();
|
|
696
769
|
return;
|
|
697
770
|
}
|
|
@@ -710,42 +783,6 @@ class StdioTransport extends TransportEvents {
|
|
|
710
783
|
child.stdin?.end();
|
|
711
784
|
});
|
|
712
785
|
}
|
|
713
|
-
handleStdout(chunk) {
|
|
714
|
-
this.stdoutBuffer = Buffer.concat([this.stdoutBuffer, Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)]);
|
|
715
|
-
const maxMessageBytes = this.options.maxMessageBytes ?? DEFAULT_MAX_MESSAGE_BYTES;
|
|
716
|
-
while (true) {
|
|
717
|
-
const newline = this.stdoutBuffer.indexOf(10);
|
|
718
|
-
if (newline < 0) {
|
|
719
|
-
if (this.stdoutBuffer.length > maxMessageBytes) {
|
|
720
|
-
this.stdoutBuffer = Buffer.alloc(0);
|
|
721
|
-
this.emitError(new Error(`MCP stdio message exceeds ${maxMessageBytes} bytes`));
|
|
722
|
-
}
|
|
723
|
-
return;
|
|
724
|
-
}
|
|
725
|
-
const line = this.stdoutBuffer.subarray(0, newline);
|
|
726
|
-
this.stdoutBuffer = this.stdoutBuffer.subarray(newline + 1);
|
|
727
|
-
if (line.length > maxMessageBytes) {
|
|
728
|
-
this.emitError(new Error(`MCP stdio message exceeds ${maxMessageBytes} bytes`));
|
|
729
|
-
continue;
|
|
730
|
-
}
|
|
731
|
-
const text = line.toString("utf8").replace(/\r$/, "");
|
|
732
|
-
if (!text.trim())
|
|
733
|
-
continue;
|
|
734
|
-
try {
|
|
735
|
-
this.emitMessage(parseJsonRpcMessage(JSON.parse(text)));
|
|
736
|
-
} catch (error) {
|
|
737
|
-
this.emitError(error);
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
handleStderr(chunk) {
|
|
742
|
-
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
743
|
-
const maxStderrBytes = this.options.maxStderrBytes ?? DEFAULT_MAX_STDERR_BYTES;
|
|
744
|
-
this.stderrBuffer = Buffer.concat([this.stderrBuffer, buffer]);
|
|
745
|
-
if (this.stderrBuffer.length > maxStderrBytes)
|
|
746
|
-
this.stderrBuffer = this.stderrBuffer.subarray(-maxStderrBytes);
|
|
747
|
-
this.options.onStderr?.(buffer.toString("utf8"));
|
|
748
|
-
}
|
|
749
786
|
}
|
|
750
787
|
|
|
751
788
|
// node_modules/@earendil-works/pi-mcp/dist/transports/streamable-http.js
|
|
@@ -777,8 +814,7 @@ async function consumeSseStream(stream, options) {
|
|
|
777
814
|
dataLines = [];
|
|
778
815
|
dataBytes = 0;
|
|
779
816
|
};
|
|
780
|
-
const processLine = (
|
|
781
|
-
const line = rawLine.endsWith("\r") ? rawLine.slice(0, -1) : rawLine;
|
|
817
|
+
const processLine = (line) => {
|
|
782
818
|
if (line === "") {
|
|
783
819
|
dispatch();
|
|
784
820
|
return;
|
|
@@ -803,27 +839,57 @@ async function consumeSseStream(stream, options) {
|
|
|
803
839
|
} else if (field === "retry" && /^\d+$/.test(value))
|
|
804
840
|
options.onRetry?.(Number(value));
|
|
805
841
|
};
|
|
842
|
+
let skipLeadingLf = false;
|
|
843
|
+
const consumeLines = () => {
|
|
844
|
+
let start = 0;
|
|
845
|
+
for (let i = 0;i < buffered.length; i++) {
|
|
846
|
+
const char = buffered[i];
|
|
847
|
+
if (char !== "\r" && char !== `
|
|
848
|
+
`)
|
|
849
|
+
continue;
|
|
850
|
+
processLine(buffered.slice(start, i));
|
|
851
|
+
if (char === "\r") {
|
|
852
|
+
if (i + 1 < buffered.length) {
|
|
853
|
+
if (buffered[i + 1] === `
|
|
854
|
+
`)
|
|
855
|
+
i++;
|
|
856
|
+
} else {
|
|
857
|
+
skipLeadingLf = true;
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
start = i + 1;
|
|
861
|
+
}
|
|
862
|
+
buffered = buffered.slice(start);
|
|
863
|
+
};
|
|
806
864
|
try {
|
|
807
865
|
while (true) {
|
|
808
866
|
const { done, value } = await reader.read();
|
|
809
867
|
if (done)
|
|
810
868
|
break;
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
`
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
newline = buffered.indexOf(`
|
|
818
|
-
`);
|
|
869
|
+
let text = decoder.decode(value, { stream: true });
|
|
870
|
+
if (skipLeadingLf && text.length > 0) {
|
|
871
|
+
if (text.startsWith(`
|
|
872
|
+
`))
|
|
873
|
+
text = text.slice(1);
|
|
874
|
+
skipLeadingLf = false;
|
|
819
875
|
}
|
|
876
|
+
buffered += text;
|
|
877
|
+
consumeLines();
|
|
820
878
|
if (Buffer.byteLength(buffered) > maxEventBytes)
|
|
821
879
|
throw new Error(`MCP SSE event exceeds ${maxEventBytes} bytes`);
|
|
822
880
|
}
|
|
823
|
-
|
|
881
|
+
let tail = decoder.decode();
|
|
882
|
+
if (skipLeadingLf && tail.startsWith(`
|
|
883
|
+
`))
|
|
884
|
+
tail = tail.slice(1);
|
|
885
|
+
buffered += tail;
|
|
886
|
+
consumeLines();
|
|
824
887
|
if (buffered)
|
|
825
888
|
processLine(buffered);
|
|
826
889
|
dispatch();
|
|
890
|
+
} catch (error) {
|
|
891
|
+
await reader.cancel().catch(() => {});
|
|
892
|
+
throw error;
|
|
827
893
|
} finally {
|
|
828
894
|
reader.releaseLock();
|
|
829
895
|
}
|
|
@@ -871,6 +937,29 @@ function isTransientStatus(status) {
|
|
|
871
937
|
function discard(response) {
|
|
872
938
|
return response.body?.cancel().catch(() => {}) ?? Promise.resolve();
|
|
873
939
|
}
|
|
940
|
+
async function readBodyText(response, maxBytes) {
|
|
941
|
+
if (!response.body)
|
|
942
|
+
return { text: "", truncated: false };
|
|
943
|
+
const reader = response.body.getReader();
|
|
944
|
+
const decoder = new TextDecoder;
|
|
945
|
+
let text = "";
|
|
946
|
+
let remaining = maxBytes;
|
|
947
|
+
try {
|
|
948
|
+
while (true) {
|
|
949
|
+
const { done, value } = await reader.read();
|
|
950
|
+
if (done)
|
|
951
|
+
return { text: text + decoder.decode(), truncated: false };
|
|
952
|
+
if (value.byteLength > remaining) {
|
|
953
|
+
await reader.cancel().catch(() => {});
|
|
954
|
+
return { text: text + decoder.decode(value.subarray(0, remaining), { stream: true }), truncated: true };
|
|
955
|
+
}
|
|
956
|
+
remaining -= value.byteLength;
|
|
957
|
+
text += decoder.decode(value, { stream: true });
|
|
958
|
+
}
|
|
959
|
+
} finally {
|
|
960
|
+
reader.releaseLock();
|
|
961
|
+
}
|
|
962
|
+
}
|
|
874
963
|
function describeHttpFailure(status, body) {
|
|
875
964
|
const text = body.trim();
|
|
876
965
|
const snippet = text.length > ERROR_MESSAGE_BODY_CHARS ? `${text.slice(0, ERROR_MESSAGE_BODY_CHARS - 3)}...` : text;
|
|
@@ -928,7 +1017,11 @@ class StreamableHttpTransport extends TransportEvents {
|
|
|
928
1017
|
}
|
|
929
1018
|
const type = contentType(response);
|
|
930
1019
|
if (type === "application/json") {
|
|
931
|
-
const
|
|
1020
|
+
const maxBytes = this.options.maxMessageBytes ?? DEFAULT_MAX_MESSAGE_BYTES;
|
|
1021
|
+
const { text, truncated } = await readBodyText(response, maxBytes);
|
|
1022
|
+
if (truncated)
|
|
1023
|
+
throw new Error(`MCP JSON response exceeds ${maxBytes} bytes`);
|
|
1024
|
+
const body = JSON.parse(text);
|
|
932
1025
|
for (const item of Array.isArray(body) ? body : [body])
|
|
933
1026
|
this.emitMessage(parseJsonRpcMessage(item));
|
|
934
1027
|
return;
|
|
@@ -1003,7 +1096,7 @@ class StreamableHttpTransport extends TransportEvents {
|
|
|
1003
1096
|
async checkResponse(response) {
|
|
1004
1097
|
if (response.ok)
|
|
1005
1098
|
return;
|
|
1006
|
-
const body =
|
|
1099
|
+
const body = (await readBodyText(response, MAX_ERROR_BODY_BYTES).catch(() => ({ text: "" }))).text;
|
|
1007
1100
|
if (response.status === 401)
|
|
1008
1101
|
throw new McpAuthRequiredError(response, body);
|
|
1009
1102
|
if (response.status === 404 && this.sessionIdValue)
|
|
@@ -1175,119 +1268,207 @@ class StreamableHttpTransport extends TransportEvents {
|
|
|
1175
1268
|
}
|
|
1176
1269
|
}
|
|
1177
1270
|
|
|
1178
|
-
// node_modules/@earendil-works/pi-mcp/dist/oauth/
|
|
1179
|
-
import {
|
|
1180
|
-
function plainText(page) {
|
|
1181
|
-
if (page.ok)
|
|
1182
|
-
return "Authorization complete. You may close this window.";
|
|
1183
|
-
return page.details ? `${page.message}
|
|
1271
|
+
// node_modules/@earendil-works/pi-mcp/dist/oauth/client-settings.js
|
|
1272
|
+
import { createHash } from "node:crypto";
|
|
1184
1273
|
|
|
1185
|
-
|
|
1274
|
+
// node_modules/@earendil-works/pi-mcp/dist/oauth/provider.js
|
|
1275
|
+
class MemoryOAuthStateStore {
|
|
1276
|
+
value;
|
|
1277
|
+
load() {
|
|
1278
|
+
return this.value === undefined ? undefined : structuredClone(this.value);
|
|
1279
|
+
}
|
|
1280
|
+
save(state) {
|
|
1281
|
+
this.value = structuredClone(state);
|
|
1282
|
+
}
|
|
1186
1283
|
}
|
|
1187
1284
|
|
|
1188
|
-
class
|
|
1285
|
+
class McpOAuthProvider {
|
|
1189
1286
|
redirectUrl;
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
this.
|
|
1199
|
-
this.
|
|
1200
|
-
this.
|
|
1287
|
+
clientMetadata;
|
|
1288
|
+
clientMetadataDocument;
|
|
1289
|
+
serverUrl;
|
|
1290
|
+
configuredClient;
|
|
1291
|
+
store;
|
|
1292
|
+
onRedirect;
|
|
1293
|
+
writes = Promise.resolve();
|
|
1294
|
+
constructor(options) {
|
|
1295
|
+
this.serverUrl = String(new URL(options.serverUrl));
|
|
1296
|
+
this.redirectUrl = String(options.redirectUrl);
|
|
1297
|
+
this.clientMetadata = {
|
|
1298
|
+
...options.clientMetadata,
|
|
1299
|
+
redirect_uris: options.clientMetadata.redirect_uris ?? [this.redirectUrl],
|
|
1300
|
+
grant_types: options.clientMetadata.grant_types ?? ["authorization_code", "refresh_token"],
|
|
1301
|
+
response_types: options.clientMetadata.response_types ?? ["code"],
|
|
1302
|
+
token_endpoint_auth_method: options.clientMetadata.token_endpoint_auth_method ?? (options.clientSecret ? "client_secret_post" : "none")
|
|
1303
|
+
};
|
|
1304
|
+
this.clientMetadataDocument = options.clientMetadataDocument;
|
|
1305
|
+
this.configuredClient = options.clientId ? { client_id: options.clientId, ...options.clientSecret ? { client_secret: options.clientSecret } : {} } : undefined;
|
|
1306
|
+
this.store = options.store ?? new MemoryOAuthStateStore;
|
|
1307
|
+
this.onRedirect = options.onRedirect;
|
|
1201
1308
|
}
|
|
1202
|
-
|
|
1203
|
-
const
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1309
|
+
async state() {
|
|
1310
|
+
const existing = (await this.load()).oauthState;
|
|
1311
|
+
if (existing)
|
|
1312
|
+
return existing;
|
|
1313
|
+
const state = Buffer.from(crypto.getRandomValues(new Uint8Array(32))).toString("hex");
|
|
1314
|
+
await this.update((value) => ({ ...value, oauthState: state }));
|
|
1315
|
+
return state;
|
|
1316
|
+
}
|
|
1317
|
+
async clientInformation() {
|
|
1318
|
+
return this.configuredClient ?? (await this.load()).clientInformation;
|
|
1319
|
+
}
|
|
1320
|
+
async saveClientInformation(information) {
|
|
1321
|
+
if (this.configuredClient)
|
|
1322
|
+
return;
|
|
1323
|
+
await this.update((value) => ({ ...value, clientInformation: information }));
|
|
1324
|
+
}
|
|
1325
|
+
async tokens() {
|
|
1326
|
+
return (await this.load()).tokens;
|
|
1327
|
+
}
|
|
1328
|
+
async saveTokens(tokens) {
|
|
1329
|
+
const expiresAt = tokens.expires_in === undefined ? undefined : Date.now() + tokens.expires_in * 1000;
|
|
1330
|
+
await this.update((value) => {
|
|
1331
|
+
const next = { ...value, tokens };
|
|
1332
|
+
if (expiresAt === undefined)
|
|
1333
|
+
delete next.tokensExpireAt;
|
|
1334
|
+
else
|
|
1335
|
+
next.tokensExpireAt = expiresAt;
|
|
1336
|
+
return next;
|
|
1214
1337
|
});
|
|
1215
|
-
const address = server.address();
|
|
1216
|
-
if (!address || typeof address === "string")
|
|
1217
|
-
throw new Error("OAuth callback server did not bind to TCP");
|
|
1218
|
-
instance = new OAuthCallbackServer(server, `http://${redirectHost.includes(":") ? `[${redirectHost}]` : redirectHost}:${address.port}${path}`, [path, ...options.extraPaths ?? []], options.timeoutMs ?? 5 * 60000, options.renderPage);
|
|
1219
|
-
return instance;
|
|
1220
1338
|
}
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1339
|
+
async redirectToAuthorization(url) {
|
|
1340
|
+
await this.onRedirect(url);
|
|
1341
|
+
}
|
|
1342
|
+
async saveCodeVerifier(verifier) {
|
|
1343
|
+
await this.update((value) => ({ ...value, codeVerifier: verifier }));
|
|
1344
|
+
}
|
|
1345
|
+
async codeVerifier() {
|
|
1346
|
+
const verifier = (await this.load()).codeVerifier;
|
|
1347
|
+
if (!verifier)
|
|
1348
|
+
throw new Error("No OAuth PKCE code verifier is stored");
|
|
1349
|
+
return verifier;
|
|
1350
|
+
}
|
|
1351
|
+
async invalidateCredentials(kind) {
|
|
1352
|
+
await this.update((value) => {
|
|
1353
|
+
const next = { ...value };
|
|
1354
|
+
if (kind === "all" || kind === "client")
|
|
1355
|
+
delete next.clientInformation;
|
|
1356
|
+
if (kind === "all" || kind === "tokens") {
|
|
1357
|
+
delete next.tokens;
|
|
1358
|
+
delete next.tokensExpireAt;
|
|
1359
|
+
}
|
|
1360
|
+
if (kind === "all" || kind === "verifier")
|
|
1361
|
+
delete next.codeVerifier;
|
|
1362
|
+
if (kind === "all" || kind === "discovery")
|
|
1363
|
+
delete next.discovery;
|
|
1364
|
+
if (kind === "all")
|
|
1365
|
+
delete next.oauthState;
|
|
1366
|
+
return next;
|
|
1230
1367
|
});
|
|
1231
1368
|
}
|
|
1232
|
-
async
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1369
|
+
async saveDiscoveryState(discovery) {
|
|
1370
|
+
await this.update((value) => ({ ...value, discovery }));
|
|
1371
|
+
}
|
|
1372
|
+
async discoveryState() {
|
|
1373
|
+
return (await this.load()).discovery;
|
|
1374
|
+
}
|
|
1375
|
+
async load() {
|
|
1376
|
+
await this.writes;
|
|
1377
|
+
return this.own(await this.store.load());
|
|
1378
|
+
}
|
|
1379
|
+
async update(update) {
|
|
1380
|
+
this.writes = this.writes.then(async () => {
|
|
1381
|
+
await this.store.save(update(this.own(await this.store.load())));
|
|
1240
1382
|
});
|
|
1383
|
+
await this.writes;
|
|
1241
1384
|
}
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
response.writeHead(status, { "content-type": "text/html; charset=utf-8", "cache-control": "no-store" });
|
|
1245
|
-
response.end(this.renderPage(page));
|
|
1246
|
-
} else {
|
|
1247
|
-
response.writeHead(status, { "content-type": "text/plain; charset=utf-8" }).end(plainText(page));
|
|
1248
|
-
}
|
|
1385
|
+
own(state) {
|
|
1386
|
+
return state?.serverUrl === this.serverUrl ? state : { serverUrl: this.serverUrl };
|
|
1249
1387
|
}
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
return;
|
|
1268
|
-
}
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
// node_modules/@earendil-works/pi-mcp/dist/oauth/client-settings.js
|
|
1391
|
+
function createOAuthClientProvider(options, redirectUrl, onRedirect = () => {}) {
|
|
1392
|
+
const { serverUrl, settings, clientMetadataDocuments: documents } = options;
|
|
1393
|
+
return new McpOAuthProvider({
|
|
1394
|
+
serverUrl,
|
|
1395
|
+
redirectUrl,
|
|
1396
|
+
clientMetadata: { client_name: settings.clientName ?? options.clientName },
|
|
1397
|
+
clientMetadataDocument: offersClientMetadataDocument(settings, documents, redirectUrl) ? (metadata) => {
|
|
1398
|
+
if (!documents?.listsRedirectUrl(redirectUrl)) {
|
|
1399
|
+
throw new Error(`oauth.clientRegistration "cimd" needs Client ID Metadata Documents that list the redirect URI ${redirectUrl}`);
|
|
1400
|
+
}
|
|
1401
|
+
const document = clientMetadataDocument(serverUrl, redirectUrl, metadata, documents.baseUrl);
|
|
1402
|
+
if (!document && settings.clientRegistration === "cimd") {
|
|
1403
|
+
throw new Error('The authorization server does not support Client ID Metadata Documents for public clients; remove oauth.clientRegistration "cimd"');
|
|
1404
|
+
}
|
|
1405
|
+
return document;
|
|
1406
|
+
} : undefined,
|
|
1407
|
+
clientId: settings.clientId,
|
|
1408
|
+
clientSecret: settings.clientSecret,
|
|
1409
|
+
store: options.store,
|
|
1410
|
+
onRedirect
|
|
1411
|
+
});
|
|
1412
|
+
}
|
|
1413
|
+
function offersClientMetadataDocument(settings, documents, redirectUrl) {
|
|
1414
|
+
const registration = settings.clientRegistration ?? "auto";
|
|
1415
|
+
if (registration !== "auto")
|
|
1416
|
+
return registration === "cimd";
|
|
1417
|
+
return !settings.clientId && !settings.clientName && documents?.listsRedirectUrl(redirectUrl) === true;
|
|
1418
|
+
}
|
|
1419
|
+
function clientMetadataDocument(serverUrl, redirectUrl, metadata, baseUrl) {
|
|
1420
|
+
if (!metadata?.client_id_metadata_document_supported || !metadata.token_endpoint_auth_methods_supported?.includes("none")) {
|
|
1421
|
+
return;
|
|
1422
|
+
}
|
|
1423
|
+
if (metadata.authorization_response_iss_parameter_supported)
|
|
1424
|
+
return { url: `${baseUrl}/client.json`, redirectUrl };
|
|
1425
|
+
const redirect = new URL(redirectUrl);
|
|
1426
|
+
redirect.pathname = serverSpecificPath(redirect.pathname, serverUrl);
|
|
1427
|
+
return { url: `${baseUrl}/${callbackId(serverUrl)}/client.json`, redirectUrl: redirect.href };
|
|
1428
|
+
}
|
|
1429
|
+
function serverSpecificPath(path, serverUrl) {
|
|
1430
|
+
return `${path.replace(/\/$/, "")}/${callbackId(serverUrl)}`;
|
|
1431
|
+
}
|
|
1432
|
+
function callbackId(serverUrl) {
|
|
1433
|
+
const url = new URL(serverUrl);
|
|
1434
|
+
url.hash = "";
|
|
1435
|
+
return createHash("sha256").update(url.href).digest().subarray(0, 9).toString("base64url");
|
|
1436
|
+
}
|
|
1437
|
+
function registeredRedirectUrls(client) {
|
|
1438
|
+
return client && "redirect_uris" in client ? client.redirect_uris : [];
|
|
1439
|
+
}
|
|
1440
|
+
var OAUTH_REQUEST_TIMEOUT_MS = 15000;
|
|
1441
|
+
function timedFetch(fetch = globalThis.fetch) {
|
|
1442
|
+
return (input, init) => {
|
|
1443
|
+
const timeout = AbortSignal.timeout(OAUTH_REQUEST_TIMEOUT_MS);
|
|
1444
|
+
return fetch(input, { ...init, signal: init?.signal ? AbortSignal.any([init.signal, timeout]) : timeout });
|
|
1445
|
+
};
|
|
1446
|
+
}
|
|
1447
|
+
var CALLBACK_HOST = "127.0.0.1";
|
|
1448
|
+
var CALLBACK_PATH = "/callback";
|
|
1449
|
+
var DEFAULT_REDIRECT_URL = `http://${CALLBACK_HOST}${CALLBACK_PATH}`;
|
|
1450
|
+
function loopbackSettings(settings) {
|
|
1451
|
+
const configured = settings.callbackUrl ?? DEFAULT_REDIRECT_URL;
|
|
1452
|
+
const url = new URL(configured);
|
|
1453
|
+
const address = url.hostname.replace(/^\[|\]$/g, "");
|
|
1454
|
+
const port = url.port ? Number(url.port) : settings.callbackPort;
|
|
1455
|
+
let fixedRedirectUrl;
|
|
1456
|
+
if (url.port)
|
|
1457
|
+
fixedRedirectUrl = settings.callbackUrl;
|
|
1458
|
+
else if (port !== undefined) {
|
|
1459
|
+
url.port = String(port);
|
|
1460
|
+
fixedRedirectUrl = url.href;
|
|
1289
1461
|
}
|
|
1462
|
+
return {
|
|
1463
|
+
url: configured,
|
|
1464
|
+
host: address === "localhost" ? CALLBACK_HOST : address,
|
|
1465
|
+
redirectHost: address,
|
|
1466
|
+
port,
|
|
1467
|
+
path: url.pathname,
|
|
1468
|
+
fixedRedirectUrl
|
|
1469
|
+
};
|
|
1290
1470
|
}
|
|
1471
|
+
|
|
1291
1472
|
// node_modules/@earendil-works/pi-mcp/dist/oauth/errors.js
|
|
1292
1473
|
class OAuthError extends Error {
|
|
1293
1474
|
code;
|
|
@@ -1339,6 +1520,13 @@ class McpOAuthAuthorizationRequiredError extends Error {
|
|
|
1339
1520
|
}
|
|
1340
1521
|
}
|
|
1341
1522
|
|
|
1523
|
+
class McpRefreshLockBusyError extends Error {
|
|
1524
|
+
constructor() {
|
|
1525
|
+
super("Another process is refreshing the MCP server's tokens");
|
|
1526
|
+
this.name = "McpRefreshLockBusyError";
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1342
1530
|
// node_modules/@earendil-works/pi-mcp/dist/oauth/types.js
|
|
1343
1531
|
function object(value, name) {
|
|
1344
1532
|
if (!isObject(value))
|
|
@@ -1575,6 +1763,7 @@ function selectResource(serverUrl, metadata) {
|
|
|
1575
1763
|
}
|
|
1576
1764
|
return metadata.resource;
|
|
1577
1765
|
}
|
|
1766
|
+
|
|
1578
1767
|
// node_modules/@earendil-works/pi-mcp/dist/oauth/flow.js
|
|
1579
1768
|
function loopback(hostname) {
|
|
1580
1769
|
return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]" || hostname === "::1";
|
|
@@ -1720,7 +1909,7 @@ function stepUpScope(granted, challenged) {
|
|
|
1720
1909
|
const scopes = [granted, challenged].flatMap((scope) => scope?.split(/\s+/).filter(Boolean) ?? []);
|
|
1721
1910
|
return [...new Set(scopes)].join(" ");
|
|
1722
1911
|
}
|
|
1723
|
-
async function runFlow(provider, options) {
|
|
1912
|
+
async function runFlow(provider, options, use = {}) {
|
|
1724
1913
|
const metadataUrl = options.authorizationServerMetadataUrl && secureEndpoint(options.authorizationServerMetadataUrl);
|
|
1725
1914
|
const cached = metadataUrl ? undefined : await provider.discoveryState?.();
|
|
1726
1915
|
const discovered = cached?.authorizationServerUrl ? {
|
|
@@ -1748,16 +1937,26 @@ async function runFlow(provider, options) {
|
|
|
1748
1937
|
const resource = selectResource(options.serverUrl, discovered.resourceMetadata);
|
|
1749
1938
|
const scope = options.scope || discovered.resourceMetadata?.scopes_supported?.join(" ") || provider.clientMetadata.scope;
|
|
1750
1939
|
const stored = await provider.clientInformation();
|
|
1940
|
+
use.storedClientId = stored?.client_id;
|
|
1751
1941
|
const clientDocument = stored ? undefined : provider.clientMetadataDocument?.(metadata);
|
|
1752
1942
|
if (clientDocument) {
|
|
1753
1943
|
const url = new URL(clientDocument.url);
|
|
1754
1944
|
if (url.protocol !== "https:" || url.pathname === "/")
|
|
1755
1945
|
throw new Error("Invalid OAuth client metadata URL");
|
|
1756
1946
|
}
|
|
1947
|
+
const redirectUrl = clientDocument?.redirectUrl ?? String(provider.redirectUrl);
|
|
1948
|
+
if (options.authorizationCode && options.authorizationRedirectUrl !== undefined) {
|
|
1949
|
+
if (redirectUrl !== options.authorizationRedirectUrl) {
|
|
1950
|
+
throw new Error(`The code exchange would use the redirect URI ${redirectUrl}, but the authorization request used ${options.authorizationRedirectUrl}`);
|
|
1951
|
+
}
|
|
1952
|
+
}
|
|
1757
1953
|
let client = stored ?? (clientDocument && { client_id: clientDocument.url });
|
|
1758
1954
|
if (!client) {
|
|
1759
|
-
if (options.
|
|
1760
|
-
|
|
1955
|
+
if (options.refreshOnly)
|
|
1956
|
+
return "REDIRECT";
|
|
1957
|
+
if (options.authorizationCode) {
|
|
1958
|
+
throw new Error("OAuth client information is missing during code exchange: the authorization request's client was removed, or the client settings changed");
|
|
1959
|
+
}
|
|
1761
1960
|
if (!provider.saveClientInformation)
|
|
1762
1961
|
throw new Error("OAuth client information cannot be persisted");
|
|
1763
1962
|
client = await registerClient(discovered.authorizationServerUrl, {
|
|
@@ -1769,7 +1968,6 @@ async function runFlow(provider, options) {
|
|
|
1769
1968
|
});
|
|
1770
1969
|
await provider.saveClientInformation(client);
|
|
1771
1970
|
}
|
|
1772
|
-
const redirectUrl = clientDocument?.redirectUrl ?? provider.redirectUrl;
|
|
1773
1971
|
const tokenOptions = {
|
|
1774
1972
|
metadata,
|
|
1775
1973
|
clientInformation: client,
|
|
@@ -1809,6 +2007,8 @@ async function runFlow(provider, options) {
|
|
|
1809
2007
|
throw error;
|
|
1810
2008
|
}
|
|
1811
2009
|
}
|
|
2010
|
+
if (options.refreshOnly)
|
|
2011
|
+
return "REDIRECT";
|
|
1812
2012
|
const state = await provider.state?.();
|
|
1813
2013
|
const authorization = await startAuthorization(discovered.authorizationServerUrl, {
|
|
1814
2014
|
metadata,
|
|
@@ -1823,11 +2023,19 @@ async function runFlow(provider, options) {
|
|
|
1823
2023
|
return "REDIRECT";
|
|
1824
2024
|
}
|
|
1825
2025
|
async function authorizeMcp(provider, options) {
|
|
2026
|
+
const use = {};
|
|
1826
2027
|
try {
|
|
1827
|
-
return await runFlow(provider, options);
|
|
2028
|
+
return await runFlow(provider, options, use);
|
|
1828
2029
|
} catch (error) {
|
|
1829
2030
|
if (error instanceof OAuthError && ["invalid_client", "unauthorized_client"].includes(error.code)) {
|
|
1830
|
-
|
|
2031
|
+
if (options.refreshOnly) {
|
|
2032
|
+
if ((await provider.clientInformation())?.client_id === use.storedClientId) {
|
|
2033
|
+
for (const kind of ["client", "tokens", "discovery"])
|
|
2034
|
+
await provider.invalidateCredentials?.(kind);
|
|
2035
|
+
}
|
|
2036
|
+
} else {
|
|
2037
|
+
await provider.invalidateCredentials?.("all");
|
|
2038
|
+
}
|
|
1831
2039
|
return runFlow(provider, options);
|
|
1832
2040
|
}
|
|
1833
2041
|
if (error instanceof OAuthError && error.code === "invalid_grant") {
|
|
@@ -1837,159 +2045,389 @@ async function authorizeMcp(provider, options) {
|
|
|
1837
2045
|
throw error;
|
|
1838
2046
|
}
|
|
1839
2047
|
}
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
2048
|
+
|
|
2049
|
+
// node_modules/@earendil-works/pi-mcp/dist/oauth/auth-provider.js
|
|
2050
|
+
var REFRESH_SKEW_MS = 30000;
|
|
2051
|
+
function createMcpAuthProvider(options) {
|
|
2052
|
+
const { store, redirectUrl } = options;
|
|
2053
|
+
let refreshing;
|
|
2054
|
+
const refresh = (staleToken, fetch = globalThis.fetch, challenge) => {
|
|
2055
|
+
refreshing ??= store.withRefreshLock(async () => {
|
|
2056
|
+
const state = await store.load();
|
|
2057
|
+
if (state?.tokens?.access_token !== staleToken)
|
|
2058
|
+
return;
|
|
2059
|
+
if (!state?.tokens?.refresh_token)
|
|
2060
|
+
throw new McpOAuthAuthorizationRequiredError;
|
|
2061
|
+
const client = { ...options, settings: options.settings() };
|
|
2062
|
+
const result = await refreshStoredTokens(client, state, { fetch, challenge, redirectUrl });
|
|
2063
|
+
if (result === "REDIRECT")
|
|
2064
|
+
throw new McpOAuthAuthorizationRequiredError;
|
|
2065
|
+
}).finally(() => {
|
|
2066
|
+
refreshing = undefined;
|
|
2067
|
+
});
|
|
2068
|
+
return refreshing;
|
|
2069
|
+
};
|
|
2070
|
+
return {
|
|
2071
|
+
token: async () => {
|
|
2072
|
+
await refreshing?.catch(() => {
|
|
2073
|
+
return;
|
|
2074
|
+
});
|
|
2075
|
+
const state = await store.load();
|
|
2076
|
+
const token = state?.tokens?.access_token;
|
|
2077
|
+
const expired = state?.tokensExpireAt !== undefined && state.tokensExpireAt - REFRESH_SKEW_MS <= Date.now();
|
|
2078
|
+
if (!expired || !state?.tokens?.refresh_token)
|
|
2079
|
+
return token;
|
|
2080
|
+
await refresh(token).catch(() => {
|
|
2081
|
+
return;
|
|
2082
|
+
});
|
|
2083
|
+
return (await store.load())?.tokens?.access_token;
|
|
2084
|
+
},
|
|
2085
|
+
onUnauthorized: async (context) => {
|
|
2086
|
+
const challenge = parseWwwAuthenticate(context.response.headers.get("www-authenticate"));
|
|
2087
|
+
options.onChallenge(challenge);
|
|
2088
|
+
if (challenge.error === "insufficient_scope")
|
|
2089
|
+
throw new McpOAuthAuthorizationRequiredError;
|
|
2090
|
+
await refresh(context.token, context.fetch, challenge);
|
|
2091
|
+
},
|
|
2092
|
+
settled: async () => {
|
|
2093
|
+
await refreshing?.catch(() => {
|
|
2094
|
+
return;
|
|
2095
|
+
});
|
|
2096
|
+
}
|
|
2097
|
+
};
|
|
2098
|
+
}
|
|
2099
|
+
async function refreshStoredTokens(client, state, options = {}) {
|
|
2100
|
+
const candidates = [
|
|
2101
|
+
options.redirectUrl,
|
|
2102
|
+
loopbackSettings(client.settings).fixedRedirectUrl,
|
|
2103
|
+
registeredRedirectUrls(state.clientInformation)[0]
|
|
2104
|
+
].filter((url) => url !== undefined);
|
|
2105
|
+
const redirectUrl = candidates.find((url) => client.clientMetadataDocuments?.listsRedirectUrl(url)) ?? DEFAULT_REDIRECT_URL;
|
|
2106
|
+
return authorizeMcp(createOAuthClientProvider(client, redirectUrl), {
|
|
2107
|
+
serverUrl: client.serverUrl,
|
|
2108
|
+
resourceMetadataUrl: options.challenge?.resourceMetadataUrl,
|
|
2109
|
+
authorizationServerMetadataUrl: client.settings.authServerMetadataUrl,
|
|
2110
|
+
fetch: timedFetch(options.fetch),
|
|
2111
|
+
refreshOnly: true
|
|
2112
|
+
});
|
|
2113
|
+
}
|
|
2114
|
+
// node_modules/@earendil-works/pi-mcp/dist/oauth/callback.js
|
|
2115
|
+
import { createServer } from "node:http";
|
|
2116
|
+
function plainText(page) {
|
|
2117
|
+
if (page.ok)
|
|
2118
|
+
return "Authorization complete. You may close this window.";
|
|
2119
|
+
return page.details ? `${page.message}
|
|
2120
|
+
|
|
2121
|
+
${page.details}` : page.message;
|
|
1849
2122
|
}
|
|
1850
2123
|
|
|
1851
|
-
class
|
|
2124
|
+
class OAuthCallbackServer {
|
|
1852
2125
|
redirectUrl;
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
this.
|
|
1862
|
-
this.
|
|
1863
|
-
this.
|
|
1864
|
-
...options.clientMetadata,
|
|
1865
|
-
redirect_uris: options.clientMetadata.redirect_uris ?? [this.redirectUrl],
|
|
1866
|
-
grant_types: options.clientMetadata.grant_types ?? ["authorization_code", "refresh_token"],
|
|
1867
|
-
response_types: options.clientMetadata.response_types ?? ["code"],
|
|
1868
|
-
token_endpoint_auth_method: options.clientMetadata.token_endpoint_auth_method ?? (options.clientSecret ? "client_secret_post" : "none")
|
|
1869
|
-
};
|
|
1870
|
-
this.clientMetadataDocument = options.clientMetadataDocument;
|
|
1871
|
-
this.configuredClient = options.clientId ? { client_id: options.clientId, ...options.clientSecret ? { client_secret: options.clientSecret } : {} } : undefined;
|
|
1872
|
-
this.store = options.store ?? new MemoryOAuthStateStore;
|
|
1873
|
-
this.onRedirect = options.onRedirect;
|
|
1874
|
-
}
|
|
1875
|
-
async state() {
|
|
1876
|
-
const existing = (await this.load()).oauthState;
|
|
1877
|
-
if (existing)
|
|
1878
|
-
return existing;
|
|
1879
|
-
const state = Buffer.from(crypto.getRandomValues(new Uint8Array(32))).toString("hex");
|
|
1880
|
-
await this.update((value) => ({ ...value, oauthState: state }));
|
|
1881
|
-
return state;
|
|
1882
|
-
}
|
|
1883
|
-
async clientInformation() {
|
|
1884
|
-
return this.configuredClient ?? (await this.load()).clientInformation;
|
|
1885
|
-
}
|
|
1886
|
-
async saveClientInformation(information) {
|
|
1887
|
-
if (this.configuredClient)
|
|
1888
|
-
return;
|
|
1889
|
-
await this.update((value) => ({ ...value, clientInformation: information }));
|
|
2126
|
+
server;
|
|
2127
|
+
paths;
|
|
2128
|
+
timeoutMs;
|
|
2129
|
+
renderPage;
|
|
2130
|
+
pending = new Map;
|
|
2131
|
+
constructor(server, redirectUrl, paths, timeoutMs, renderPage) {
|
|
2132
|
+
this.server = server;
|
|
2133
|
+
this.redirectUrl = redirectUrl;
|
|
2134
|
+
this.paths = paths;
|
|
2135
|
+
this.timeoutMs = timeoutMs;
|
|
2136
|
+
this.renderPage = renderPage;
|
|
1890
2137
|
}
|
|
1891
|
-
async
|
|
1892
|
-
|
|
2138
|
+
static async listen(options = {}) {
|
|
2139
|
+
const host = options.host ?? "127.0.0.1";
|
|
2140
|
+
const redirectHost = options.redirectHost ?? host;
|
|
2141
|
+
const path = options.path ?? "/callback";
|
|
2142
|
+
let instance;
|
|
2143
|
+
const server = createServer((request, response) => instance?.handle(request.url ?? "/", response));
|
|
2144
|
+
await new Promise((resolve, reject) => {
|
|
2145
|
+
server.once("error", reject);
|
|
2146
|
+
server.listen(options.port ?? 0, host, () => {
|
|
2147
|
+
server.off("error", reject);
|
|
2148
|
+
resolve();
|
|
2149
|
+
});
|
|
2150
|
+
});
|
|
2151
|
+
const address = server.address();
|
|
2152
|
+
if (!address || typeof address === "string")
|
|
2153
|
+
throw new Error("OAuth callback server did not bind to TCP");
|
|
2154
|
+
instance = new OAuthCallbackServer(server, `http://${redirectHost.includes(":") ? `[${redirectHost}]` : redirectHost}:${address.port}${path}`, [path, ...options.extraPaths ?? []], options.timeoutMs ?? 5 * 60000, options.renderPage);
|
|
2155
|
+
return instance;
|
|
1893
2156
|
}
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
delete
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
2157
|
+
waitForCallback(state, path) {
|
|
2158
|
+
if (this.pending.has(state))
|
|
2159
|
+
throw new Error("OAuth state is already pending");
|
|
2160
|
+
return new Promise((resolve, reject) => {
|
|
2161
|
+
const timer = setTimeout(() => {
|
|
2162
|
+
this.pending.delete(state);
|
|
2163
|
+
reject(new Error("OAuth callback timed out"));
|
|
2164
|
+
}, this.timeoutMs);
|
|
2165
|
+
this.pending.set(state, { resolve, reject, timer, path });
|
|
1903
2166
|
});
|
|
1904
2167
|
}
|
|
1905
|
-
async
|
|
1906
|
-
|
|
2168
|
+
async close() {
|
|
2169
|
+
for (const pending of this.pending.values()) {
|
|
2170
|
+
clearTimeout(pending.timer);
|
|
2171
|
+
pending.reject(new Error("OAuth callback server closed"));
|
|
2172
|
+
}
|
|
2173
|
+
this.pending.clear();
|
|
2174
|
+
const closed = new Promise((resolve, reject) => {
|
|
2175
|
+
this.server.close((error) => error ? reject(error) : resolve());
|
|
2176
|
+
});
|
|
2177
|
+
this.server.closeAllConnections();
|
|
2178
|
+
await closed;
|
|
1907
2179
|
}
|
|
1908
|
-
|
|
1909
|
-
|
|
2180
|
+
reply(response, status, page) {
|
|
2181
|
+
if (this.renderPage) {
|
|
2182
|
+
response.writeHead(status, { "content-type": "text/html; charset=utf-8", "cache-control": "no-store" });
|
|
2183
|
+
response.end(this.renderPage(page));
|
|
2184
|
+
} else {
|
|
2185
|
+
response.writeHead(status, { "content-type": "text/plain; charset=utf-8" }).end(plainText(page));
|
|
2186
|
+
}
|
|
1910
2187
|
}
|
|
1911
|
-
|
|
1912
|
-
const
|
|
1913
|
-
if (!
|
|
1914
|
-
|
|
1915
|
-
|
|
2188
|
+
handle(rawUrl, response) {
|
|
2189
|
+
const url = new URL(rawUrl, this.redirectUrl);
|
|
2190
|
+
if (!this.paths.includes(url.pathname)) {
|
|
2191
|
+
this.reply(response, 404, { ok: false, message: "Not found" });
|
|
2192
|
+
return;
|
|
2193
|
+
}
|
|
2194
|
+
const state = url.searchParams.get("state");
|
|
2195
|
+
const pending = state ? this.pending.get(state) : undefined;
|
|
2196
|
+
if (!state || !pending) {
|
|
2197
|
+
this.reply(response, 400, { ok: false, message: "Invalid or expired OAuth state" });
|
|
2198
|
+
return;
|
|
2199
|
+
}
|
|
2200
|
+
clearTimeout(pending.timer);
|
|
2201
|
+
this.pending.delete(state);
|
|
2202
|
+
if (pending.path !== undefined && url.pathname !== pending.path) {
|
|
2203
|
+
pending.reject(new Error("The authorization response arrived on another redirect URI"));
|
|
2204
|
+
this.reply(response, 400, { ok: false, message: "Unexpected redirect URI" });
|
|
2205
|
+
return;
|
|
2206
|
+
}
|
|
2207
|
+
const error = url.searchParams.get("error");
|
|
2208
|
+
if (error) {
|
|
2209
|
+
const description = url.searchParams.get("error_description") ?? error;
|
|
2210
|
+
pending.reject(new Error(description));
|
|
2211
|
+
this.reply(response, 200, {
|
|
2212
|
+
ok: false,
|
|
2213
|
+
message: "Authorization failed. You may close this window.",
|
|
2214
|
+
details: description
|
|
2215
|
+
});
|
|
2216
|
+
return;
|
|
2217
|
+
}
|
|
2218
|
+
const code = url.searchParams.get("code");
|
|
2219
|
+
if (!code) {
|
|
2220
|
+
pending.reject(new Error("OAuth callback did not include an authorization code"));
|
|
2221
|
+
this.reply(response, 400, { ok: false, message: "Missing authorization code" });
|
|
2222
|
+
return;
|
|
2223
|
+
}
|
|
2224
|
+
const iss = url.searchParams.get("iss");
|
|
2225
|
+
pending.resolve({ code, state, ...iss ? { iss } : {} });
|
|
2226
|
+
this.reply(response, 200, { ok: true });
|
|
1916
2227
|
}
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
delete next.tokensExpireAt;
|
|
1925
|
-
}
|
|
1926
|
-
if (kind === "all" || kind === "verifier")
|
|
1927
|
-
delete next.codeVerifier;
|
|
1928
|
-
if (kind === "all" || kind === "discovery")
|
|
1929
|
-
delete next.discovery;
|
|
1930
|
-
if (kind === "all")
|
|
1931
|
-
delete next.oauthState;
|
|
1932
|
-
return next;
|
|
1933
|
-
});
|
|
2228
|
+
}
|
|
2229
|
+
|
|
2230
|
+
// node_modules/@earendil-works/pi-mcp/dist/oauth/sign-in.js
|
|
2231
|
+
class McpSignInCancelledError2 extends Error {
|
|
2232
|
+
constructor() {
|
|
2233
|
+
super("Sign-in cancelled");
|
|
2234
|
+
this.name = "McpSignInCancelledError";
|
|
1934
2235
|
}
|
|
1935
|
-
|
|
1936
|
-
|
|
2236
|
+
}
|
|
2237
|
+
async function startMcpSignIn(options) {
|
|
2238
|
+
if (options.signal?.aborted)
|
|
2239
|
+
throw new McpSignInCancelledError2;
|
|
2240
|
+
const stepUp = options.challenge?.error === "insufficient_scope";
|
|
2241
|
+
if (!stepUp && await refreshBeforeSignIn(options) === "AUTHORIZED")
|
|
2242
|
+
return { kind: "authorized" };
|
|
2243
|
+
return cancellable(options.signal, () => startBrowserStep(options, stepUp));
|
|
2244
|
+
}
|
|
2245
|
+
async function refreshBeforeSignIn(options) {
|
|
2246
|
+
const { store, settings, challenge, redirectUrl, signal } = options;
|
|
2247
|
+
const refreshed = store.withRefreshLock(async () => {
|
|
2248
|
+
if (signal?.aborted)
|
|
2249
|
+
return "REDIRECT";
|
|
2250
|
+
const state = await store.load();
|
|
2251
|
+
if (!state?.tokens?.refresh_token)
|
|
2252
|
+
return "REDIRECT";
|
|
2253
|
+
if (settings.clientRegistration === "cimd" && state.clientInformation && !settings.clientId)
|
|
2254
|
+
return "REDIRECT";
|
|
2255
|
+
return refreshStoredTokens(options, state, { challenge, redirectUrl });
|
|
2256
|
+
});
|
|
2257
|
+
try {
|
|
2258
|
+
return await untilAborted(signal, refreshed);
|
|
2259
|
+
} catch (error) {
|
|
2260
|
+
if (error instanceof McpRefreshLockBusyError)
|
|
2261
|
+
return "REDIRECT";
|
|
2262
|
+
throw error;
|
|
1937
2263
|
}
|
|
1938
|
-
|
|
1939
|
-
|
|
2264
|
+
}
|
|
2265
|
+
function untilAborted(signal, promise) {
|
|
2266
|
+
if (!signal)
|
|
2267
|
+
return promise;
|
|
2268
|
+
return new Promise((resolve, reject) => {
|
|
2269
|
+
const abort = () => reject(new McpSignInCancelledError2);
|
|
2270
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
2271
|
+
promise.then(resolve, reject).finally(() => signal.removeEventListener("abort", abort));
|
|
2272
|
+
});
|
|
2273
|
+
}
|
|
2274
|
+
async function startBrowserStep(options, stepUp) {
|
|
2275
|
+
const { store, settings, redirectUrl, challenge } = options;
|
|
2276
|
+
const stored = await store.load();
|
|
2277
|
+
if (stored)
|
|
2278
|
+
await store.save(stateForSignIn(stored, options));
|
|
2279
|
+
let authorizationUrl;
|
|
2280
|
+
const provider = createOAuthClientProvider(options, redirectUrl, (url) => {
|
|
2281
|
+
authorizationUrl = url;
|
|
2282
|
+
});
|
|
2283
|
+
const scope = mergeScopes(settings.scope, stepUp ? stepUpScope(stored?.tokens?.scope, challenge?.scope) : challenge?.scope);
|
|
2284
|
+
await authorizeMcp(provider, { ...flowOptions(options), scope, skipRefresh: true });
|
|
2285
|
+
if (!authorizationUrl)
|
|
2286
|
+
throw new Error("OAuth flow did not produce an authorization URL");
|
|
2287
|
+
const requestedScope = authorizationUrl.searchParams.get("scope");
|
|
2288
|
+
return {
|
|
2289
|
+
kind: "redirect",
|
|
2290
|
+
authorizationUrl: authorizationUrl.href,
|
|
2291
|
+
redirectUrl: authorizationUrl.searchParams.get("redirect_uri") ?? redirectUrl,
|
|
2292
|
+
state: await provider.state(),
|
|
2293
|
+
...requestedScope ? { scope: requestedScope } : {}
|
|
2294
|
+
};
|
|
2295
|
+
}
|
|
2296
|
+
function stateForSignIn(stored, options) {
|
|
2297
|
+
const { settings, redirectUrl } = options;
|
|
2298
|
+
const next = { ...stored };
|
|
2299
|
+
delete next.oauthState;
|
|
2300
|
+
const keepClient = settings.clientId || (stored.clientInformation ? settings.clientRegistration !== "cimd" && registeredRedirectUrls(stored.clientInformation).includes(redirectUrl) : offersClientMetadataDocument(settings, options.clientMetadataDocuments, redirectUrl));
|
|
2301
|
+
if (!keepClient) {
|
|
2302
|
+
delete next.clientInformation;
|
|
2303
|
+
delete next.tokens;
|
|
2304
|
+
delete next.tokensExpireAt;
|
|
1940
2305
|
}
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
2306
|
+
return next;
|
|
2307
|
+
}
|
|
2308
|
+
function mergeScopes(...scopes) {
|
|
2309
|
+
const merged = [...new Set(scopes.flatMap((scope) => scope?.split(/\s+/).filter(Boolean) ?? []))];
|
|
2310
|
+
return merged.length > 0 ? merged.join(" ") : undefined;
|
|
2311
|
+
}
|
|
2312
|
+
async function completeMcpSignIn(options) {
|
|
2313
|
+
await cancellable(options.signal, async () => {
|
|
2314
|
+
const { authorization, response } = options;
|
|
2315
|
+
if (response.state !== authorization.state) {
|
|
2316
|
+
throw new Error("The authorization response belongs to a different sign-in");
|
|
2317
|
+
}
|
|
2318
|
+
if ((await options.store.load())?.oauthState !== authorization.state) {
|
|
2319
|
+
throw new Error("Another sign-in to this MCP server started since; sign in again");
|
|
2320
|
+
}
|
|
2321
|
+
await authorizeMcp(createOAuthClientProvider(options, options.redirectUrl), {
|
|
2322
|
+
...flowOptions(options),
|
|
2323
|
+
scope: authorization.scope,
|
|
2324
|
+
authorizationRedirectUrl: authorization.redirectUrl,
|
|
2325
|
+
authorizationCode: response.code,
|
|
2326
|
+
iss: response.iss
|
|
2327
|
+
});
|
|
2328
|
+
});
|
|
2329
|
+
}
|
|
2330
|
+
function flowOptions(options) {
|
|
2331
|
+
return {
|
|
2332
|
+
serverUrl: options.serverUrl,
|
|
2333
|
+
fetch: timedFetch(),
|
|
2334
|
+
signal: options.signal,
|
|
2335
|
+
resourceMetadataUrl: options.challenge?.resourceMetadataUrl,
|
|
2336
|
+
authorizationServerMetadataUrl: options.settings.authServerMetadataUrl
|
|
2337
|
+
};
|
|
2338
|
+
}
|
|
2339
|
+
async function cancellable(signal, fn) {
|
|
2340
|
+
if (signal?.aborted)
|
|
2341
|
+
throw new McpSignInCancelledError2;
|
|
2342
|
+
try {
|
|
2343
|
+
return await fn();
|
|
2344
|
+
} catch (error) {
|
|
2345
|
+
if (signal?.aborted)
|
|
2346
|
+
throw new McpSignInCancelledError2;
|
|
2347
|
+
throw error;
|
|
1944
2348
|
}
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
2349
|
+
}
|
|
2350
|
+
|
|
2351
|
+
// node_modules/@earendil-works/pi-mcp/dist/oauth/loopback.js
|
|
2352
|
+
async function listenForLoopbackSignIn(options) {
|
|
2353
|
+
const { settings } = options;
|
|
2354
|
+
const loopback = loopbackSettings(settings);
|
|
2355
|
+
const registered = registeredRedirectUrls((await options.store.load())?.clientInformation)[0];
|
|
2356
|
+
const port = loopback.port ?? (registered ? Number(new URL(registered).port) || undefined : undefined);
|
|
2357
|
+
const offersDocument = offersClientMetadataDocument(settings, options.clientMetadataDocuments, loopback.url);
|
|
2358
|
+
const listenOptions = {
|
|
2359
|
+
host: loopback.host,
|
|
2360
|
+
redirectHost: loopback.redirectHost,
|
|
2361
|
+
path: loopback.path,
|
|
2362
|
+
extraPaths: offersDocument ? [serverSpecificPath(loopback.path, options.serverUrl)] : [],
|
|
2363
|
+
renderPage: options.renderPage
|
|
2364
|
+
};
|
|
2365
|
+
let callback;
|
|
2366
|
+
try {
|
|
2367
|
+
callback = await OAuthCallbackServer.listen({ ...listenOptions, port: port ?? 0 });
|
|
2368
|
+
} catch (error) {
|
|
2369
|
+
if (loopback.port !== undefined || port === undefined)
|
|
2370
|
+
throw error;
|
|
2371
|
+
callback = await OAuthCallbackServer.listen(listenOptions);
|
|
2372
|
+
}
|
|
2373
|
+
return { callback, redirectUrl: loopback.fixedRedirectUrl ?? callback.redirectUrl };
|
|
2374
|
+
}
|
|
2375
|
+
async function waitForLoopbackSignIn(options) {
|
|
2376
|
+
const { authorization } = options;
|
|
2377
|
+
const controller = new AbortController;
|
|
2378
|
+
const signal = options.signal ? AbortSignal.any([controller.signal, options.signal]) : controller.signal;
|
|
2379
|
+
const fromBrowser = options.callback.waitForCallback(authorization.state, new URL(authorization.redirectUrl).pathname);
|
|
2380
|
+
const fromUser = options.promptForRedirectUrl ? options.promptForRedirectUrl(signal).then((input) => {
|
|
2381
|
+
if (!input?.trim())
|
|
2382
|
+
throw new McpSignInCancelledError2;
|
|
2383
|
+
return responseFromRedirectUrl(input, authorization);
|
|
2384
|
+
}) : new Promise((_, reject) => {
|
|
2385
|
+
signal.addEventListener("abort", () => reject(new McpSignInCancelledError2), { once: true });
|
|
2386
|
+
});
|
|
2387
|
+
try {
|
|
2388
|
+
return await cancellable(options.signal, () => Promise.race([fromBrowser, fromUser]));
|
|
2389
|
+
} finally {
|
|
2390
|
+
controller.abort();
|
|
2391
|
+
fromBrowser.catch(() => {
|
|
2392
|
+
return;
|
|
2393
|
+
});
|
|
2394
|
+
fromUser.catch(() => {
|
|
2395
|
+
return;
|
|
1948
2396
|
});
|
|
1949
|
-
await this.writes;
|
|
1950
2397
|
}
|
|
1951
|
-
|
|
1952
|
-
|
|
2398
|
+
}
|
|
2399
|
+
function responseFromRedirectUrl(input, authorization) {
|
|
2400
|
+
let url;
|
|
2401
|
+
try {
|
|
2402
|
+
url = new URL(input.trim());
|
|
2403
|
+
} catch {
|
|
2404
|
+
throw new Error("Expected the full redirect URL from the browser address bar");
|
|
1953
2405
|
}
|
|
2406
|
+
const redirectUrl = new URL(authorization.redirectUrl);
|
|
2407
|
+
if (url.origin !== redirectUrl.origin || url.pathname !== redirectUrl.pathname) {
|
|
2408
|
+
throw new Error("The redirect URL does not match this sign-in's redirect URI");
|
|
2409
|
+
}
|
|
2410
|
+
const error = url.searchParams.get("error");
|
|
2411
|
+
if (error)
|
|
2412
|
+
throw new Error(url.searchParams.get("error_description") ?? error);
|
|
2413
|
+
const state = url.searchParams.get("state");
|
|
2414
|
+
if (state !== authorization.state)
|
|
2415
|
+
throw new Error("The redirect URL belongs to a different sign-in");
|
|
2416
|
+
const code = url.searchParams.get("code");
|
|
2417
|
+
if (!code)
|
|
2418
|
+
throw new Error("The redirect URL does not contain an authorization code");
|
|
2419
|
+
const iss = url.searchParams.get("iss");
|
|
2420
|
+
return { code, state, ...iss ? { iss } : {} };
|
|
1954
2421
|
}
|
|
1955
2422
|
// node_modules/@earendil-works/pi-coding-agent/dist/extensions/mcp/oauth.js
|
|
1956
2423
|
init_oauth_page();
|
|
1957
|
-
import { createHash } from "node:crypto";
|
|
2424
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
1958
2425
|
import { mkdirSync } from "node:fs";
|
|
1959
2426
|
import { join } from "node:path";
|
|
1960
2427
|
var import_proper_lockfile = __toESM(require_proper_lockfile(), 1);
|
|
1961
|
-
var CALLBACK_HOST = "127.0.0.1";
|
|
1962
|
-
var CALLBACK_PATH = "/callback";
|
|
1963
|
-
var CLIENT_METADATA_BASE_URL = "https://pi.dev/oauth";
|
|
1964
|
-
var FALLBACK_REDIRECT_URL = `http://${CALLBACK_HOST}${CALLBACK_PATH}`;
|
|
1965
|
-
var REFRESH_SKEW_MS = 30000;
|
|
1966
|
-
var OAUTH_REQUEST_TIMEOUT_MS = 15000;
|
|
1967
2428
|
var REFRESH_LOCK_STALE_MS = 20000;
|
|
1968
2429
|
var REFRESH_LOCK_WAIT_MS = 25000;
|
|
1969
2430
|
var REFRESH_LOCK_RETRY_MS = 100;
|
|
1970
|
-
function callbackSettings(settings) {
|
|
1971
|
-
const url = new URL(settings.callbackUrl ?? `http://${CALLBACK_HOST}${CALLBACK_PATH}`);
|
|
1972
|
-
const address = url.hostname.replace(/^\[|\]$/g, "");
|
|
1973
|
-
const port = url.port ? Number(url.port) : settings.callbackPort;
|
|
1974
|
-
let fixedRedirectUrl;
|
|
1975
|
-
if (url.port)
|
|
1976
|
-
fixedRedirectUrl = settings.callbackUrl;
|
|
1977
|
-
else if (port !== undefined) {
|
|
1978
|
-
url.port = String(port);
|
|
1979
|
-
fixedRedirectUrl = url.href;
|
|
1980
|
-
}
|
|
1981
|
-
return {
|
|
1982
|
-
host: address === "localhost" ? CALLBACK_HOST : address,
|
|
1983
|
-
redirectHost: address,
|
|
1984
|
-
port,
|
|
1985
|
-
path: url.pathname,
|
|
1986
|
-
fixedRedirectUrl
|
|
1987
|
-
};
|
|
1988
|
-
}
|
|
1989
|
-
function mergeScopes(...scopes) {
|
|
1990
|
-
const merged = [...new Set(scopes.flatMap((scope) => scope?.split(/\s+/).filter(Boolean) ?? []))];
|
|
1991
|
-
return merged.length > 0 ? merged.join(" ") : undefined;
|
|
1992
|
-
}
|
|
1993
2431
|
function parseStates(content) {
|
|
1994
2432
|
if (!content?.trim())
|
|
1995
2433
|
return {};
|
|
@@ -2033,7 +2471,7 @@ class McpOAuthCredentialStore2 {
|
|
|
2033
2471
|
if (!this.lockDir)
|
|
2034
2472
|
return fn();
|
|
2035
2473
|
mkdirSync(this.lockDir, { recursive: true, mode: 448 });
|
|
2036
|
-
const hash =
|
|
2474
|
+
const hash = createHash2("sha256").update(key).digest("hex").slice(0, 16);
|
|
2037
2475
|
const release = await import_proper_lockfile.default.lock(join(this.lockDir, `mcp-auth-refresh-${hash}`), {
|
|
2038
2476
|
realpath: false,
|
|
2039
2477
|
stale: REFRESH_LOCK_STALE_MS,
|
|
@@ -2044,6 +2482,10 @@ class McpOAuthCredentialStore2 {
|
|
|
2044
2482
|
maxTimeout: REFRESH_LOCK_RETRY_MS
|
|
2045
2483
|
},
|
|
2046
2484
|
onCompromised: () => {}
|
|
2485
|
+
}).catch((error) => {
|
|
2486
|
+
if (error instanceof Error && "code" in error && error.code === "ELOCKED")
|
|
2487
|
+
throw new McpRefreshLockBusyError;
|
|
2488
|
+
throw error;
|
|
2047
2489
|
});
|
|
2048
2490
|
try {
|
|
2049
2491
|
return await fn();
|
|
@@ -2077,233 +2519,48 @@ class McpOAuthCredentialStore2 {
|
|
|
2077
2519
|
});
|
|
2078
2520
|
}
|
|
2079
2521
|
}
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2522
|
+
var PI_CLIENT_METADATA_DOCUMENTS = {
|
|
2523
|
+
baseUrl: "https://pi.dev/oauth",
|
|
2524
|
+
listsRedirectUrl: isClientMetadataDocumentCallback
|
|
2525
|
+
};
|
|
2526
|
+
var PI_CLIENT = { clientName: APP_NAME, clientMetadataDocuments: PI_CLIENT_METADATA_DOCUMENTS };
|
|
2527
|
+
function piSettings(settings) {
|
|
2528
|
+
const auto = (settings.clientRegistration ?? "auto") === "auto";
|
|
2529
|
+
return auto && APP_NAME !== "pi" ? { ...settings, clientRegistration: "dcr" } : settings;
|
|
2085
2530
|
}
|
|
2086
|
-
function
|
|
2087
|
-
return
|
|
2531
|
+
function createMcpAuthProvider2(options) {
|
|
2532
|
+
return createMcpAuthProvider({ ...options, ...PI_CLIENT, settings: () => piSettings(options.settings()) });
|
|
2088
2533
|
}
|
|
2089
|
-
function
|
|
2090
|
-
|
|
2091
|
-
url.hash = "";
|
|
2092
|
-
return createHash("sha256").update(url.href).digest().subarray(0, 9).toString("base64url");
|
|
2534
|
+
function renderCallbackPage(page) {
|
|
2535
|
+
return page.ok ? oauthSuccessHtml("Signed in to the MCP server. You may now close this page.") : oauthErrorHtml(page.message, page.details);
|
|
2093
2536
|
}
|
|
2094
|
-
function
|
|
2095
|
-
const
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
if (settings.clientId || settings.clientName || APP_NAME !== "pi")
|
|
2099
|
-
return false;
|
|
2100
|
-
return isClientMetadataDocumentCallback(settings.callbackUrl);
|
|
2101
|
-
}
|
|
2102
|
-
function clientMetadataDocument(serverUrl, redirectUrl, metadata) {
|
|
2103
|
-
if (!metadata?.client_id_metadata_document_supported || !metadata.token_endpoint_auth_methods_supported?.includes("none")) {
|
|
2104
|
-
return;
|
|
2105
|
-
}
|
|
2106
|
-
if (metadata.authorization_response_iss_parameter_supported) {
|
|
2107
|
-
return { url: `${CLIENT_METADATA_BASE_URL}/client.json`, redirectUrl };
|
|
2108
|
-
}
|
|
2109
|
-
const id = callbackId(serverUrl);
|
|
2110
|
-
const redirect = new URL(redirectUrl);
|
|
2111
|
-
redirect.pathname = `${CALLBACK_PATH}/${id}`;
|
|
2112
|
-
return { url: `${CLIENT_METADATA_BASE_URL}/${id}/client.json`, redirectUrl: redirect.href };
|
|
2113
|
-
}
|
|
2114
|
-
function createProvider(serverUrl, store, settings, redirectUrl, onRedirect) {
|
|
2115
|
-
return new McpOAuthProvider({
|
|
2537
|
+
async function signInMcpServer2(options) {
|
|
2538
|
+
const { serverUrl, store, challenge, prompt, signal } = options;
|
|
2539
|
+
const settings = piSettings(options.settings);
|
|
2540
|
+
const { callback, redirectUrl } = await listenForLoopbackSignIn({
|
|
2116
2541
|
serverUrl,
|
|
2117
|
-
redirectUrl,
|
|
2118
|
-
clientMetadata: { client_name: settings.clientName ?? APP_NAME },
|
|
2119
|
-
clientMetadataDocument: offersClientMetadataDocument(settings) ? (metadata) => {
|
|
2120
|
-
const document = clientMetadataDocument(serverUrl, redirectUrl, metadata);
|
|
2121
|
-
if (!document && settings.clientRegistration === "cimd") {
|
|
2122
|
-
throw new Error('The authorization server does not support Client ID Metadata Documents for public clients; remove oauth.clientRegistration "cimd"');
|
|
2123
|
-
}
|
|
2124
|
-
return document;
|
|
2125
|
-
} : undefined,
|
|
2126
|
-
clientId: settings.clientId,
|
|
2127
|
-
clientSecret: settings.clientSecret,
|
|
2128
2542
|
store,
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
function createMcpAuthProvider(options) {
|
|
2133
|
-
const { serverUrl, store } = options;
|
|
2134
|
-
let refreshing;
|
|
2135
|
-
const refresh = (staleToken, fetch = globalThis.fetch, challenge) => {
|
|
2136
|
-
refreshing ??= store.withRefreshLock(async () => {
|
|
2137
|
-
const state = await store.load();
|
|
2138
|
-
if (state?.tokens?.access_token !== staleToken)
|
|
2139
|
-
return;
|
|
2140
|
-
if (!state?.tokens?.refresh_token)
|
|
2141
|
-
throw new McpOAuthAuthorizationRequiredError;
|
|
2142
|
-
const settings = options.settings();
|
|
2143
|
-
const redirectUrl = callbackSettings(settings).fixedRedirectUrl ?? registeredRedirectUrls(state.clientInformation)[0] ?? FALLBACK_REDIRECT_URL;
|
|
2144
|
-
const provider = createProvider(serverUrl, store, settings, redirectUrl, () => {});
|
|
2145
|
-
const result = await authorizeMcp(provider, {
|
|
2146
|
-
serverUrl,
|
|
2147
|
-
resourceMetadataUrl: challenge?.resourceMetadataUrl,
|
|
2148
|
-
authorizationServerMetadataUrl: settings.authServerMetadataUrl,
|
|
2149
|
-
scope: challenge?.scope,
|
|
2150
|
-
fetch: timedFetch(fetch)
|
|
2151
|
-
});
|
|
2152
|
-
if (result === "REDIRECT")
|
|
2153
|
-
throw new McpOAuthAuthorizationRequiredError;
|
|
2154
|
-
}).finally(() => {
|
|
2155
|
-
refreshing = undefined;
|
|
2156
|
-
});
|
|
2157
|
-
return refreshing;
|
|
2158
|
-
};
|
|
2159
|
-
return {
|
|
2160
|
-
token: async () => {
|
|
2161
|
-
await refreshing?.catch(() => {
|
|
2162
|
-
return;
|
|
2163
|
-
});
|
|
2164
|
-
const state = await store.load();
|
|
2165
|
-
const token = state?.tokens?.access_token;
|
|
2166
|
-
const expired = state?.tokensExpireAt !== undefined && state.tokensExpireAt - REFRESH_SKEW_MS <= Date.now();
|
|
2167
|
-
if (!expired || !state?.tokens?.refresh_token)
|
|
2168
|
-
return token;
|
|
2169
|
-
await refresh(token).catch(() => {
|
|
2170
|
-
return;
|
|
2171
|
-
});
|
|
2172
|
-
return (await store.load())?.tokens?.access_token;
|
|
2173
|
-
},
|
|
2174
|
-
onUnauthorized: async (context) => {
|
|
2175
|
-
const challenge = parseWwwAuthenticate(context.response.headers.get("www-authenticate"));
|
|
2176
|
-
options.onChallenge(challenge);
|
|
2177
|
-
if (challenge.error === "insufficient_scope")
|
|
2178
|
-
throw new McpOAuthAuthorizationRequiredError;
|
|
2179
|
-
await refresh(context.token, context.fetch, challenge);
|
|
2180
|
-
},
|
|
2181
|
-
settled: async () => {
|
|
2182
|
-
await refreshing?.catch(() => {
|
|
2183
|
-
return;
|
|
2184
|
-
});
|
|
2185
|
-
}
|
|
2186
|
-
};
|
|
2187
|
-
}
|
|
2188
|
-
|
|
2189
|
-
class McpSignInCancelledError2 extends Error {
|
|
2190
|
-
constructor() {
|
|
2191
|
-
super("Sign-in cancelled");
|
|
2192
|
-
this.name = "McpSignInCancelledError";
|
|
2193
|
-
}
|
|
2194
|
-
}
|
|
2195
|
-
function responseFromRedirectUrl(input, state, redirectUrl) {
|
|
2196
|
-
let url;
|
|
2197
|
-
try {
|
|
2198
|
-
url = new URL(input.trim());
|
|
2199
|
-
} catch {
|
|
2200
|
-
throw new Error("Expected the full redirect URL from the browser address bar");
|
|
2201
|
-
}
|
|
2202
|
-
if (url.origin !== redirectUrl.origin || url.pathname !== redirectUrl.pathname) {
|
|
2203
|
-
throw new Error("The redirect URL does not match this sign-in's redirect URI");
|
|
2204
|
-
}
|
|
2205
|
-
const error = url.searchParams.get("error");
|
|
2206
|
-
if (error)
|
|
2207
|
-
throw new Error(url.searchParams.get("error_description") ?? error);
|
|
2208
|
-
if (url.searchParams.get("state") !== state)
|
|
2209
|
-
throw new Error("The redirect URL belongs to a different sign-in");
|
|
2210
|
-
const code = url.searchParams.get("code");
|
|
2211
|
-
if (!code)
|
|
2212
|
-
throw new Error("The redirect URL does not contain an authorization code");
|
|
2213
|
-
return { code, iss: url.searchParams.get("iss") ?? undefined };
|
|
2214
|
-
}
|
|
2215
|
-
async function waitForAuthorizationResponse(callback, state, redirectUrl, prompt, signal) {
|
|
2216
|
-
const controller = new AbortController;
|
|
2217
|
-
const promptSignal = signal ? AbortSignal.any([controller.signal, signal]) : controller.signal;
|
|
2218
|
-
const fromBrowser = callback.waitForCallback(state, redirectUrl.pathname);
|
|
2219
|
-
const fromUser = prompt.promptForRedirectUrl(promptSignal).then((input) => {
|
|
2220
|
-
if (!input?.trim())
|
|
2221
|
-
throw new McpSignInCancelledError2;
|
|
2222
|
-
return responseFromRedirectUrl(input, state, redirectUrl);
|
|
2543
|
+
settings,
|
|
2544
|
+
clientMetadataDocuments: PI_CLIENT_METADATA_DOCUMENTS,
|
|
2545
|
+
renderPage: renderCallbackPage
|
|
2223
2546
|
});
|
|
2224
2547
|
try {
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
fromBrowser.catch(() => {
|
|
2548
|
+
const signIn = { serverUrl, store, settings, redirectUrl, challenge, signal, ...PI_CLIENT };
|
|
2549
|
+
const authorization = await startMcpSignIn(signIn);
|
|
2550
|
+
if (authorization.kind === "authorized")
|
|
2229
2551
|
return;
|
|
2552
|
+
prompt.showAuthorizationUrl(new URL(authorization.authorizationUrl));
|
|
2553
|
+
const response = await waitForLoopbackSignIn({
|
|
2554
|
+
callback,
|
|
2555
|
+
authorization,
|
|
2556
|
+
promptForRedirectUrl: (promptSignal) => prompt.promptForRedirectUrl(promptSignal),
|
|
2557
|
+
signal
|
|
2230
2558
|
});
|
|
2231
|
-
|
|
2232
|
-
return;
|
|
2233
|
-
});
|
|
2234
|
-
}
|
|
2235
|
-
}
|
|
2236
|
-
async function listenForCallback(settings, extraPaths, port, required) {
|
|
2237
|
-
const options = {
|
|
2238
|
-
host: settings.host,
|
|
2239
|
-
redirectHost: settings.redirectHost,
|
|
2240
|
-
path: settings.path,
|
|
2241
|
-
extraPaths,
|
|
2242
|
-
renderPage: (page) => page.ok ? oauthSuccessHtml("Signed in to the MCP server. You may now close this page.") : oauthErrorHtml(page.message, page.details)
|
|
2243
|
-
};
|
|
2244
|
-
try {
|
|
2245
|
-
return await OAuthCallbackServer.listen({ ...options, port: port ?? 0 });
|
|
2246
|
-
} catch (error) {
|
|
2247
|
-
if (required || port === undefined)
|
|
2248
|
-
throw error;
|
|
2249
|
-
return OAuthCallbackServer.listen(options);
|
|
2250
|
-
}
|
|
2251
|
-
}
|
|
2252
|
-
async function signInMcpServer2(options) {
|
|
2253
|
-
const { serverUrl, store, settings, signal } = options;
|
|
2254
|
-
if (signal?.aborted)
|
|
2255
|
-
throw new McpSignInCancelledError2;
|
|
2256
|
-
const stored = await store.load();
|
|
2257
|
-
const stepUp = options.challenge?.error === "insufficient_scope";
|
|
2258
|
-
const callbackOptions = callbackSettings(settings);
|
|
2259
|
-
const registered = registeredRedirectUrls(stored?.clientInformation)[0];
|
|
2260
|
-
const preferredPort = callbackOptions.port ?? (registered ? Number(new URL(registered).port) || undefined : undefined);
|
|
2261
|
-
const offersDocument = offersClientMetadataDocument(settings);
|
|
2262
|
-
const callback = await listenForCallback(callbackOptions, offersDocument ? [`${CALLBACK_PATH}/${callbackId(serverUrl)}`] : [], preferredPort, callbackOptions.port !== undefined);
|
|
2263
|
-
const redirectUrl = callbackOptions.fixedRedirectUrl ?? callback.redirectUrl;
|
|
2264
|
-
try {
|
|
2265
|
-
if (stored) {
|
|
2266
|
-
const next = { ...stored };
|
|
2267
|
-
delete next.oauthState;
|
|
2268
|
-
const keepClient = settings.clientId || (stored.clientInformation ? settings.clientRegistration !== "cimd" && registeredRedirectUrls(stored.clientInformation).includes(redirectUrl) : offersDocument);
|
|
2269
|
-
if (!keepClient) {
|
|
2270
|
-
delete next.clientInformation;
|
|
2271
|
-
delete next.tokens;
|
|
2272
|
-
delete next.tokensExpireAt;
|
|
2273
|
-
}
|
|
2274
|
-
await store.save(next);
|
|
2275
|
-
}
|
|
2276
|
-
let authorizationUrl;
|
|
2277
|
-
const provider = createProvider(serverUrl, store, settings, redirectUrl, (url) => {
|
|
2278
|
-
authorizationUrl = url;
|
|
2279
|
-
});
|
|
2280
|
-
const flow = {
|
|
2281
|
-
serverUrl,
|
|
2282
|
-
fetch: timedFetch(),
|
|
2283
|
-
signal,
|
|
2284
|
-
resourceMetadataUrl: options.challenge?.resourceMetadataUrl,
|
|
2285
|
-
authorizationServerMetadataUrl: settings.authServerMetadataUrl,
|
|
2286
|
-
scope: mergeScopes(settings.scope, stepUp ? stepUpScope(stored?.tokens?.scope, options.challenge?.scope) : options.challenge?.scope)
|
|
2287
|
-
};
|
|
2288
|
-
const skipRefresh = stepUp;
|
|
2289
|
-
if (await authorizeMcp(provider, { ...flow, skipRefresh }) === "AUTHORIZED")
|
|
2290
|
-
return;
|
|
2291
|
-
if (!authorizationUrl)
|
|
2292
|
-
throw new Error("OAuth flow did not produce an authorization URL");
|
|
2293
|
-
const state = await provider.state();
|
|
2294
|
-
const authorizationRedirectUrl = new URL(authorizationUrl.searchParams.get("redirect_uri") ?? redirectUrl);
|
|
2295
|
-
options.prompt.showAuthorizationUrl(authorizationUrl);
|
|
2296
|
-
const { code, iss } = await waitForAuthorizationResponse(callback, state, authorizationRedirectUrl, options.prompt, signal);
|
|
2297
|
-
await authorizeMcp(provider, { ...flow, authorizationCode: code, iss });
|
|
2298
|
-
} catch (error) {
|
|
2299
|
-
if (signal?.aborted)
|
|
2300
|
-
throw new McpSignInCancelledError2;
|
|
2301
|
-
throw error;
|
|
2559
|
+
await completeMcpSignIn({ ...signIn, authorization, response });
|
|
2302
2560
|
} finally {
|
|
2303
2561
|
await callback.close();
|
|
2304
2562
|
}
|
|
2305
2563
|
}
|
|
2306
|
-
|
|
2307
2564
|
// node_modules/@earendil-works/pi-coding-agent/dist/extensions/mcp/log.js
|
|
2308
2565
|
import { appendFileSync, mkdirSync as mkdirSync2, renameSync, statSync } from "node:fs";
|
|
2309
2566
|
import { dirname } from "node:path";
|
|
@@ -2453,7 +2710,7 @@ class McpServerConnection2 {
|
|
|
2453
2710
|
this.log = options.log;
|
|
2454
2711
|
const url = this.oauthUrl;
|
|
2455
2712
|
const provider = "url" in this.entry.config ? this.entry.config.auth?.provider : undefined;
|
|
2456
|
-
this.authProvider = url ?
|
|
2713
|
+
this.authProvider = url ? createMcpAuthProvider2({
|
|
2457
2714
|
serverUrl: url,
|
|
2458
2715
|
store: options.credentials.forServer(this.entry.name, url),
|
|
2459
2716
|
settings: () => this.oauthSettings(),
|
|
@@ -2640,7 +2897,7 @@ class McpServerConnection2 {
|
|
|
2640
2897
|
} catch (error) {
|
|
2641
2898
|
await closeClient();
|
|
2642
2899
|
if (transport instanceof StdioTransport) {
|
|
2643
|
-
this.stderrTail = transport.stderr.trim()
|
|
2900
|
+
this.stderrTail = sliceTail(transport.stderr.trim(), STDERR_TAIL_CHARS) || undefined;
|
|
2644
2901
|
}
|
|
2645
2902
|
throw error;
|
|
2646
2903
|
} finally {
|
|
@@ -2663,7 +2920,7 @@ ${this.stderrTail}` : errorMessage(error);
|
|
|
2663
2920
|
return;
|
|
2664
2921
|
this.client = undefined;
|
|
2665
2922
|
this.state = "disconnected";
|
|
2666
|
-
const stderr = stdio
|
|
2923
|
+
const stderr = stdio ? sliceTail(stdio.stderr.trim(), STDERR_TAIL_CHARS) : undefined;
|
|
2667
2924
|
this.error = stderr ? `Connection closed
|
|
2668
2925
|
${stderr}` : "Connection closed";
|
|
2669
2926
|
this.changed();
|
|
@@ -2695,4 +2952,4 @@ ${stderr}` : "Connection closed";
|
|
|
2695
2952
|
}
|
|
2696
2953
|
}
|
|
2697
2954
|
|
|
2698
|
-
export {
|
|
2955
|
+
export { McpSignInCancelledError2, McpOAuthCredentialStore2, signInMcpServer2, McpServerLog2, createDefaultTransport2, McpServerConnection2 };
|