@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
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `events/list`, `events/subscribe` and `events/unsubscribe` for the user MCP
|
|
3
|
+
* (SEP-3415 draft, webhook delivery only).
|
|
4
|
+
*
|
|
5
|
+
* Backward compatibility: nothing here runs unless a client sends an
|
|
6
|
+
* `events/*` request. The only change a non-events client sees is the added
|
|
7
|
+
* capability keys in the `initialize` result.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
11
|
+
import type { ServerCapabilities } from "@modelcontextprotocol/sdk/types.js";
|
|
12
|
+
import * as z from "zod";
|
|
13
|
+
import { getTaskById } from "@/be/db";
|
|
14
|
+
import type { User } from "@/types";
|
|
15
|
+
import {
|
|
16
|
+
EVENT_DESCRIPTORS,
|
|
17
|
+
EVENTS_EXTENSION_ID,
|
|
18
|
+
EventsErrorCode,
|
|
19
|
+
isTaskEventName,
|
|
20
|
+
parseTaskEventArguments,
|
|
21
|
+
} from "./catalog";
|
|
22
|
+
import {
|
|
23
|
+
canonicalJson,
|
|
24
|
+
countLiveSubscriptions,
|
|
25
|
+
deleteExpiredSubscriptions,
|
|
26
|
+
deleteSubscription,
|
|
27
|
+
getSubscription,
|
|
28
|
+
latestVerification,
|
|
29
|
+
subscriptionIdFor,
|
|
30
|
+
upsertSubscription,
|
|
31
|
+
} from "./store";
|
|
32
|
+
import { callbackUrlProblem, parseWebhookSecret, verifyCallbackEndpoint } from "./webhook";
|
|
33
|
+
|
|
34
|
+
export const MAX_SUBSCRIPTIONS_PER_USER = 25;
|
|
35
|
+
export const DEFAULT_TTL_MS = 60 * 60 * 1000;
|
|
36
|
+
export const MIN_TTL_MS = 60 * 1000;
|
|
37
|
+
export const MAX_TTL_MS = 24 * 60 * 60 * 1000;
|
|
38
|
+
/** How long a passed verification challenge covers this user's later subscribes to the URL. */
|
|
39
|
+
export const VERIFICATION_CACHE_MS = 24 * 60 * 60 * 1000;
|
|
40
|
+
/** Dual-signing window after a client rotates its secret. */
|
|
41
|
+
export const ROTATION_GRACE_MS = 10 * 60 * 1000;
|
|
42
|
+
|
|
43
|
+
class EventsRpcError extends Error {
|
|
44
|
+
constructor(
|
|
45
|
+
readonly code: number,
|
|
46
|
+
message: string,
|
|
47
|
+
readonly data?: Record<string, unknown>,
|
|
48
|
+
) {
|
|
49
|
+
super(message);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function invalidParams(message: string): EventsRpcError {
|
|
54
|
+
return new EventsRpcError(EventsErrorCode.InvalidParams, message);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function resourceExhausted(): EventsRpcError {
|
|
58
|
+
return new EventsRpcError(EventsErrorCode.ResourceExhausted, "Too many subscriptions", {
|
|
59
|
+
limit: "subscriptions",
|
|
60
|
+
max: MAX_SUBSCRIPTIONS_PER_USER,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Loose params: validation happens in the handler so a bad request gets
|
|
65
|
+
// InvalidParams with a useful message instead of a schema-parse InternalError.
|
|
66
|
+
const EventsListRequestSchema = z.object({
|
|
67
|
+
method: z.literal("events/list"),
|
|
68
|
+
params: z.unknown().optional(),
|
|
69
|
+
});
|
|
70
|
+
const EventsSubscribeRequestSchema = z.object({
|
|
71
|
+
method: z.literal("events/subscribe"),
|
|
72
|
+
params: z.unknown().optional(),
|
|
73
|
+
});
|
|
74
|
+
const EventsUnsubscribeRequestSchema = z.object({
|
|
75
|
+
method: z.literal("events/unsubscribe"),
|
|
76
|
+
params: z.unknown().optional(),
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
type SubscriptionKey = {
|
|
80
|
+
name: "task.completed" | "task.failed";
|
|
81
|
+
arguments: { taskId?: string };
|
|
82
|
+
argumentsJson: string;
|
|
83
|
+
url: string;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
function asRecord(value: unknown): Record<string, unknown> {
|
|
87
|
+
return value !== null && typeof value === "object" && !Array.isArray(value)
|
|
88
|
+
? (value as Record<string, unknown>)
|
|
89
|
+
: {};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function parseKey(rawParams: unknown): SubscriptionKey & { delivery: Record<string, unknown> } {
|
|
93
|
+
const params = asRecord(rawParams);
|
|
94
|
+
if (typeof params.name !== "string") throw invalidParams("name is required");
|
|
95
|
+
if (!isTaskEventName(params.name)) {
|
|
96
|
+
throw new EventsRpcError(EventsErrorCode.NotFound, `Unknown event: ${params.name}`, {
|
|
97
|
+
kind: "event",
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
const args = parseTaskEventArguments(params.arguments);
|
|
101
|
+
if (!args) throw invalidParams("arguments do not match the event's inputSchema");
|
|
102
|
+
const delivery = asRecord(params.delivery);
|
|
103
|
+
if (delivery.mode !== undefined && delivery.mode !== "webhook") {
|
|
104
|
+
throw new EventsRpcError(EventsErrorCode.Unsupported, "Only webhook delivery is offered", {
|
|
105
|
+
feature: "deliveryMode",
|
|
106
|
+
value: delivery.mode,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
const urlProblem = callbackUrlProblem(delivery.url);
|
|
110
|
+
if (urlProblem) throw invalidParams(urlProblem);
|
|
111
|
+
return {
|
|
112
|
+
name: params.name,
|
|
113
|
+
arguments: args,
|
|
114
|
+
argumentsJson: canonicalJson(args),
|
|
115
|
+
url: delivery.url as string,
|
|
116
|
+
delivery,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Client suggestion → granted TTL. Never grants no-expiry; clamps instead of rejecting. */
|
|
121
|
+
export function grantTtlMs(raw: unknown): number {
|
|
122
|
+
if (raw === undefined) return DEFAULT_TTL_MS;
|
|
123
|
+
if (raw === null) return MAX_TTL_MS;
|
|
124
|
+
if (typeof raw !== "number" || !Number.isFinite(raw))
|
|
125
|
+
throw invalidParams("ttlMs must be a number");
|
|
126
|
+
return Math.min(MAX_TTL_MS, Math.max(MIN_TTL_MS, Math.floor(raw)));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export type EventsAuthorizer = (method: string) => Promise<boolean>;
|
|
130
|
+
|
|
131
|
+
/** Verification POSTs allowed per user, and in total, per rolling hour. */
|
|
132
|
+
export const VERIFICATIONS_PER_USER_PER_HOUR = 30;
|
|
133
|
+
export const VERIFICATIONS_PER_HOUR = 1000;
|
|
134
|
+
const HOUR_MS = 60 * 60 * 1000;
|
|
135
|
+
// shortcut: in-memory and per API process, upgrade if the API runs several replicas.
|
|
136
|
+
const verificationLog = new Map<string, number[]>();
|
|
137
|
+
|
|
138
|
+
/** Records one verification POST unless the user or global hourly budget is spent. */
|
|
139
|
+
function takeVerificationBudget(userId: string, now: number): boolean {
|
|
140
|
+
const recent = (key: string) =>
|
|
141
|
+
(verificationLog.get(key) ?? []).filter((at) => at > now - HOUR_MS);
|
|
142
|
+
const mine = recent(userId);
|
|
143
|
+
const all = recent("*");
|
|
144
|
+
if (mine.length >= VERIFICATIONS_PER_USER_PER_HOUR || all.length >= VERIFICATIONS_PER_HOUR) {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
verificationLog.set(userId, [...mine, now]);
|
|
148
|
+
verificationLog.set("*", [...all, now]);
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async function handleSubscribe(
|
|
153
|
+
user: User,
|
|
154
|
+
tokenId: string,
|
|
155
|
+
authorize: EventsAuthorizer,
|
|
156
|
+
rawParams: unknown,
|
|
157
|
+
) {
|
|
158
|
+
const key = parseKey(rawParams);
|
|
159
|
+
const secretText = key.delivery.secret;
|
|
160
|
+
const secret = parseWebhookSecret(secretText);
|
|
161
|
+
if (!secret) {
|
|
162
|
+
throw invalidParams("delivery.secret must be whsec_ followed by base64 of 24 to 64 bytes");
|
|
163
|
+
}
|
|
164
|
+
const ttlMs = grantTtlMs(asRecord(rawParams).ttlMs);
|
|
165
|
+
if (!(await authorize("events/subscribe"))) {
|
|
166
|
+
throw new EventsRpcError(EventsErrorCode.Forbidden, "Forbidden");
|
|
167
|
+
}
|
|
168
|
+
if (key.arguments.taskId) {
|
|
169
|
+
const task = await getTaskById(key.arguments.taskId);
|
|
170
|
+
// One answer for "missing" and "not yours", so the filter is not an existence oracle.
|
|
171
|
+
if (!task || task.requestedByUserId !== user.id) {
|
|
172
|
+
throw new EventsRpcError(EventsErrorCode.Forbidden, "taskId is not one of your tasks");
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const now = Date.now();
|
|
177
|
+
const nowIso = new Date(now).toISOString();
|
|
178
|
+
await deleteExpiredSubscriptions(nowIso);
|
|
179
|
+
const id = subscriptionIdFor(user.id, key.url, key.name, key.argumentsJson);
|
|
180
|
+
const previous = await getSubscription(id);
|
|
181
|
+
const refreshing = previous !== null && previous.expiresAt > nowIso;
|
|
182
|
+
// Checked again inside the upsert transaction; this early check keeps a
|
|
183
|
+
// capped user from sending verification POSTs to new URLs.
|
|
184
|
+
if (
|
|
185
|
+
!refreshing &&
|
|
186
|
+
(await countLiveSubscriptions(user.id, nowIso)) >= MAX_SUBSCRIPTIONS_PER_USER
|
|
187
|
+
) {
|
|
188
|
+
throw resourceExhausted();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
let verifiedAt = await latestVerification(
|
|
192
|
+
user.id,
|
|
193
|
+
key.url,
|
|
194
|
+
new Date(now - VERIFICATION_CACHE_MS).toISOString(),
|
|
195
|
+
nowIso,
|
|
196
|
+
);
|
|
197
|
+
if (!verifiedAt) {
|
|
198
|
+
// Unsubscribe or expiry frees a live slot, so the live cap alone does not
|
|
199
|
+
// bound challenge POSTs; this budget does.
|
|
200
|
+
if (!takeVerificationBudget(user.id, now)) {
|
|
201
|
+
throw new EventsRpcError(EventsErrorCode.ResourceExhausted, "Too many verifications", {
|
|
202
|
+
limit: "verifications",
|
|
203
|
+
max: VERIFICATIONS_PER_USER_PER_HOUR,
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
const failure = await verifyCallbackEndpoint({ url: key.url, subscriptionId: id, secret });
|
|
207
|
+
if (failure) {
|
|
208
|
+
throw new EventsRpcError(
|
|
209
|
+
EventsErrorCode.CallbackEndpointError,
|
|
210
|
+
"Callback endpoint verification failed",
|
|
211
|
+
{ reason: failure },
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
verifiedAt = nowIso;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const row = await upsertSubscription({
|
|
218
|
+
id,
|
|
219
|
+
userId: user.id,
|
|
220
|
+
tokenId,
|
|
221
|
+
eventName: key.name,
|
|
222
|
+
argumentsJson: key.argumentsJson,
|
|
223
|
+
url: key.url,
|
|
224
|
+
secret: secretText as string,
|
|
225
|
+
verifiedAt,
|
|
226
|
+
expiresAt: new Date(now + ttlMs).toISOString(),
|
|
227
|
+
nowIso,
|
|
228
|
+
rotationGraceUntil: new Date(now + ROTATION_GRACE_MS).toISOString(),
|
|
229
|
+
maxActivePerUser: MAX_SUBSCRIPTIONS_PER_USER,
|
|
230
|
+
});
|
|
231
|
+
if (row === "limit") throw resourceExhausted();
|
|
232
|
+
|
|
233
|
+
return {
|
|
234
|
+
resultType: "complete",
|
|
235
|
+
id: row.id,
|
|
236
|
+
refreshBefore: row.expiresAt,
|
|
237
|
+
// task.* events are emit-only: no replay, so no cursor.
|
|
238
|
+
cursor: null,
|
|
239
|
+
truncated: false,
|
|
240
|
+
...(refreshing
|
|
241
|
+
? {
|
|
242
|
+
deliveryStatus: {
|
|
243
|
+
active: true,
|
|
244
|
+
lastDeliveryAt: row.lastDeliveryAt,
|
|
245
|
+
lastError: row.lastError,
|
|
246
|
+
...(row.failedSince ? { failedSince: row.failedSince } : {}),
|
|
247
|
+
},
|
|
248
|
+
}
|
|
249
|
+
: {}),
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
async function handleUnsubscribe(user: User, authorize: EventsAuthorizer, rawParams: unknown) {
|
|
254
|
+
const key = parseKey(rawParams);
|
|
255
|
+
if (!(await authorize("events/unsubscribe"))) {
|
|
256
|
+
throw new EventsRpcError(EventsErrorCode.Forbidden, "Forbidden");
|
|
257
|
+
}
|
|
258
|
+
// Idempotent: an unknown or already-expired key is a successful no-op.
|
|
259
|
+
await deleteSubscription(
|
|
260
|
+
subscriptionIdFor(user.id, key.url, key.name, key.argumentsJson),
|
|
261
|
+
user.id,
|
|
262
|
+
);
|
|
263
|
+
return { resultType: "complete" };
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Advertises the events capability and registers the `events/*` handlers on
|
|
268
|
+
* one user session's server. Call before `connect`.
|
|
269
|
+
*
|
|
270
|
+
* Two capability keys, because the two documents disagree: SEP-3415 puts the
|
|
271
|
+
* extension under `capabilities.extensions[EVENTS_EXTENSION_ID]`, while the
|
|
272
|
+
* design sketch and OpenAI's ChatGPT guide use `capabilities.events` in the
|
|
273
|
+
* `initialize` result.
|
|
274
|
+
*/
|
|
275
|
+
export function registerUserEvents(
|
|
276
|
+
server: McpServer,
|
|
277
|
+
user: User,
|
|
278
|
+
tokenId: string,
|
|
279
|
+
authorize: EventsAuthorizer,
|
|
280
|
+
): void {
|
|
281
|
+
server.server.registerCapabilities({
|
|
282
|
+
events: {},
|
|
283
|
+
extensions: { [EVENTS_EXTENSION_ID]: {} },
|
|
284
|
+
} as ServerCapabilities);
|
|
285
|
+
|
|
286
|
+
server.server.setRequestHandler(EventsListRequestSchema, async () => ({
|
|
287
|
+
resultType: "complete",
|
|
288
|
+
events: EVENT_DESCRIPTORS,
|
|
289
|
+
}));
|
|
290
|
+
server.server.setRequestHandler(EventsSubscribeRequestSchema, async (request) =>
|
|
291
|
+
handleSubscribe(user, tokenId, authorize, request.params),
|
|
292
|
+
);
|
|
293
|
+
server.server.setRequestHandler(EventsUnsubscribeRequestSchema, async (request) =>
|
|
294
|
+
handleUnsubscribe(user, authorize, request.params),
|
|
295
|
+
);
|
|
296
|
+
}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage for MCP Events webhook subscriptions (`mcp_event_subscriptions`,
|
|
3
|
+
* migration 325). Secrets are sealed at rest with the swarm encryption key.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { createHash } from "node:crypto";
|
|
7
|
+
import { decryptSecret, encryptSecret, getEncryptionKey } from "@/be/crypto";
|
|
8
|
+
import { getDbClient } from "@/be/db";
|
|
9
|
+
import type { DeliveryErrorCategory } from "./webhook";
|
|
10
|
+
|
|
11
|
+
export type SubscriptionRow = {
|
|
12
|
+
id: string;
|
|
13
|
+
userId: string;
|
|
14
|
+
tokenId: string;
|
|
15
|
+
eventName: string;
|
|
16
|
+
argumentsJson: string;
|
|
17
|
+
url: string;
|
|
18
|
+
secretSealed: string;
|
|
19
|
+
previousSecretSealed: string | null;
|
|
20
|
+
previousSecretUntil: string | null;
|
|
21
|
+
verifiedAt: string;
|
|
22
|
+
expiresAt: string;
|
|
23
|
+
lastDeliveryAt: string | null;
|
|
24
|
+
lastError: DeliveryErrorCategory | null;
|
|
25
|
+
failedSince: string | null;
|
|
26
|
+
createdAt: string;
|
|
27
|
+
updatedAt: string;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/** Canonical JSON: object keys sorted at every depth, so key order is irrelevant. */
|
|
31
|
+
export function canonicalJson(value: unknown): string {
|
|
32
|
+
if (value === null || typeof value !== "object") return JSON.stringify(value);
|
|
33
|
+
if (Array.isArray(value)) return `[${value.map(canonicalJson).join(",")}]`;
|
|
34
|
+
const entries = Object.entries(value as Record<string, unknown>)
|
|
35
|
+
.filter(([, v]) => v !== undefined)
|
|
36
|
+
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
|
|
37
|
+
return `{${entries.map(([k, v]) => `${JSON.stringify(k)}:${canonicalJson(v)}`).join(",")}}`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Deterministic id over the subscription key (principal, url, name, arguments). */
|
|
41
|
+
export function subscriptionIdFor(
|
|
42
|
+
userId: string,
|
|
43
|
+
url: string,
|
|
44
|
+
eventName: string,
|
|
45
|
+
argumentsJson: string,
|
|
46
|
+
): string {
|
|
47
|
+
const digest = createHash("sha256")
|
|
48
|
+
.update(canonicalJson([userId, url, eventName, argumentsJson]))
|
|
49
|
+
.digest("hex");
|
|
50
|
+
return `sub_${digest.slice(0, 32)}`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function sealSecret(secret: string): string {
|
|
54
|
+
return encryptSecret(secret, getEncryptionKey());
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function unsealSecret(sealed: string): string {
|
|
58
|
+
return decryptSecret(sealed, getEncryptionKey());
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export async function getSubscription(id: string): Promise<SubscriptionRow | null> {
|
|
62
|
+
return getDbClient().get<SubscriptionRow>("SELECT * FROM mcp_event_subscriptions WHERE id = ?", [
|
|
63
|
+
id,
|
|
64
|
+
]);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export async function countLiveSubscriptions(userId: string, nowIso: string): Promise<number> {
|
|
68
|
+
const row = await getDbClient().get<{ n: number }>(
|
|
69
|
+
"SELECT COUNT(*) AS n FROM mcp_event_subscriptions WHERE userId = ? AND expiresAt > ?",
|
|
70
|
+
[userId, nowIso],
|
|
71
|
+
);
|
|
72
|
+
return row?.n ?? 0;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The latest verification time, after `sinceIso`, of this user's live
|
|
77
|
+
* subscriptions to `url`; null when none. A new subscription reuses that time,
|
|
78
|
+
* so skipping the challenge never extends the verification window.
|
|
79
|
+
*/
|
|
80
|
+
export async function latestVerification(
|
|
81
|
+
userId: string,
|
|
82
|
+
url: string,
|
|
83
|
+
sinceIso: string,
|
|
84
|
+
nowIso: string,
|
|
85
|
+
): Promise<string | null> {
|
|
86
|
+
const row = await getDbClient().get<{ verifiedAt: string | null }>(
|
|
87
|
+
`SELECT MAX(verifiedAt) AS verifiedAt FROM mcp_event_subscriptions
|
|
88
|
+
WHERE userId = ? AND url = ? AND verifiedAt > ? AND expiresAt > ?`,
|
|
89
|
+
[userId, url, sinceIso, nowIso],
|
|
90
|
+
);
|
|
91
|
+
return row?.verifiedAt ?? null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export async function deleteExpiredSubscriptions(nowIso: string): Promise<number> {
|
|
95
|
+
const result = await getDbClient().run(
|
|
96
|
+
"DELETE FROM mcp_event_subscriptions WHERE expiresAt <= ?",
|
|
97
|
+
[nowIso],
|
|
98
|
+
);
|
|
99
|
+
return result.changes;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export async function upsertSubscription(input: {
|
|
103
|
+
id: string;
|
|
104
|
+
userId: string;
|
|
105
|
+
tokenId: string;
|
|
106
|
+
eventName: string;
|
|
107
|
+
argumentsJson: string;
|
|
108
|
+
url: string;
|
|
109
|
+
secret: string;
|
|
110
|
+
verifiedAt: string;
|
|
111
|
+
expiresAt: string;
|
|
112
|
+
nowIso: string;
|
|
113
|
+
rotationGraceUntil: string;
|
|
114
|
+
/** Live subscriptions a user may hold; a new key past it is refused. */
|
|
115
|
+
maxActivePerUser: number;
|
|
116
|
+
}): Promise<SubscriptionRow | "limit"> {
|
|
117
|
+
const sealed = sealSecret(input.secret);
|
|
118
|
+
return getDbClient().transaction(async (tx) => {
|
|
119
|
+
const existing = await tx.get<SubscriptionRow>(
|
|
120
|
+
"SELECT * FROM mcp_event_subscriptions WHERE id = ?",
|
|
121
|
+
[input.id],
|
|
122
|
+
);
|
|
123
|
+
if (!existing || existing.expiresAt <= input.nowIso) {
|
|
124
|
+
// Counted inside the write transaction, so concurrent subscribes cannot overshoot.
|
|
125
|
+
const live = await tx.get<{ n: number }>(
|
|
126
|
+
`SELECT COUNT(*) AS n FROM mcp_event_subscriptions
|
|
127
|
+
WHERE userId = ? AND expiresAt > ? AND id != ?`,
|
|
128
|
+
[input.userId, input.nowIso, input.id],
|
|
129
|
+
);
|
|
130
|
+
if ((live?.n ?? 0) >= input.maxActivePerUser) return "limit";
|
|
131
|
+
}
|
|
132
|
+
if (!existing) {
|
|
133
|
+
await tx.run(
|
|
134
|
+
`INSERT INTO mcp_event_subscriptions
|
|
135
|
+
(id, userId, tokenId, eventName, argumentsJson, url, secretSealed, verifiedAt,
|
|
136
|
+
expiresAt, createdAt, updatedAt, created_by, updated_by)
|
|
137
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
138
|
+
[
|
|
139
|
+
input.id,
|
|
140
|
+
input.userId,
|
|
141
|
+
input.tokenId,
|
|
142
|
+
input.eventName,
|
|
143
|
+
input.argumentsJson,
|
|
144
|
+
input.url,
|
|
145
|
+
sealed,
|
|
146
|
+
input.verifiedAt,
|
|
147
|
+
input.expiresAt,
|
|
148
|
+
input.nowIso,
|
|
149
|
+
input.nowIso,
|
|
150
|
+
input.userId,
|
|
151
|
+
input.userId,
|
|
152
|
+
],
|
|
153
|
+
);
|
|
154
|
+
} else {
|
|
155
|
+
// A changed secret is a rotation: keep the old one for a dual-signing window.
|
|
156
|
+
const rotated = unsealSecret(existing.secretSealed) !== input.secret;
|
|
157
|
+
await tx.run(
|
|
158
|
+
`UPDATE mcp_event_subscriptions
|
|
159
|
+
SET tokenId = ?,
|
|
160
|
+
secretSealed = ?,
|
|
161
|
+
previousSecretSealed = ?,
|
|
162
|
+
previousSecretUntil = ?,
|
|
163
|
+
verifiedAt = ?,
|
|
164
|
+
expiresAt = ?,
|
|
165
|
+
updatedAt = ?,
|
|
166
|
+
updated_by = ?
|
|
167
|
+
WHERE id = ?`,
|
|
168
|
+
[
|
|
169
|
+
input.tokenId,
|
|
170
|
+
sealed,
|
|
171
|
+
rotated ? existing.secretSealed : existing.previousSecretSealed,
|
|
172
|
+
rotated ? input.rotationGraceUntil : existing.previousSecretUntil,
|
|
173
|
+
input.verifiedAt,
|
|
174
|
+
input.expiresAt,
|
|
175
|
+
input.nowIso,
|
|
176
|
+
input.userId,
|
|
177
|
+
input.id,
|
|
178
|
+
],
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
const row = await tx.get<SubscriptionRow>(
|
|
182
|
+
"SELECT * FROM mcp_event_subscriptions WHERE id = ?",
|
|
183
|
+
[input.id],
|
|
184
|
+
);
|
|
185
|
+
if (!row) throw new Error(`subscription ${input.id} vanished during upsert`);
|
|
186
|
+
return row;
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export async function deleteSubscription(id: string, userId: string): Promise<boolean> {
|
|
191
|
+
const result = await getDbClient().run(
|
|
192
|
+
"DELETE FROM mcp_event_subscriptions WHERE id = ? AND userId = ?",
|
|
193
|
+
[id, userId],
|
|
194
|
+
);
|
|
195
|
+
return result.changes > 0;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export async function listLiveSubscriptions(
|
|
199
|
+
userId: string,
|
|
200
|
+
eventName: string,
|
|
201
|
+
nowIso: string,
|
|
202
|
+
): Promise<SubscriptionRow[]> {
|
|
203
|
+
return getDbClient().query<SubscriptionRow>(
|
|
204
|
+
`SELECT * FROM mcp_event_subscriptions
|
|
205
|
+
WHERE userId = ? AND eventName = ? AND expiresAt > ?`,
|
|
206
|
+
[userId, eventName, nowIso],
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export async function recordDeliveryOutcome(
|
|
211
|
+
id: string,
|
|
212
|
+
outcome:
|
|
213
|
+
| { ok: true; atIso: string }
|
|
214
|
+
| { ok: false; category: DeliveryErrorCategory; atIso: string },
|
|
215
|
+
): Promise<void> {
|
|
216
|
+
if (outcome.ok) {
|
|
217
|
+
await getDbClient().run(
|
|
218
|
+
`UPDATE mcp_event_subscriptions
|
|
219
|
+
SET lastDeliveryAt = ?, lastError = NULL, failedSince = NULL
|
|
220
|
+
WHERE id = ?`,
|
|
221
|
+
[outcome.atIso, id],
|
|
222
|
+
);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
await getDbClient().run(
|
|
226
|
+
`UPDATE mcp_event_subscriptions
|
|
227
|
+
SET lastError = ?, failedSince = COALESCE(failedSince, ?)
|
|
228
|
+
WHERE id = ?`,
|
|
229
|
+
[outcome.category, outcome.atIso, id],
|
|
230
|
+
);
|
|
231
|
+
}
|