@desplega.ai/agent-swarm 2.10.0 → 2.12.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-11m13kx4.js +16 -0
- package/dist/{acp-targets-arrwv4f0.js → acp-targets-311gcyvw.js} +9 -9
- package/dist/{actions-y0d2n1c2.js → actions-c4chgxp6.js} +27 -24
- package/dist/{agent-fs-provision-tpj7sktd.js → agent-fs-provision-0b9awm5n.js} +10 -5
- package/dist/{amp-adapter-vmmnmw8d.js → amp-adapter-r0veq6x5.js} +3 -3
- package/dist/{anthropic-messages-zdca3gv1.js → anthropic-messages-88b7s3n9.js} +177 -25
- package/dist/{app-wb7w45dq.js → app-hn5fftf5.js} +7 -6
- package/dist/{approval-notifications-7mqr6vbd.js → approval-notifications-3g6yc8nv.js} +7 -6
- package/dist/{assistant-gf60454p.js → assistant-cpjgpjvp.js} +29 -26
- package/dist/{azure-openai-responses-b3y7fz36.js → azure-openai-responses-jeaas6x0.js} +10 -10
- package/dist/{boot-args-schema-qxmd59sr.js → boot-args-schema-hce1av1h.js} +1 -1
- package/dist/{boot-reembed-5tmeskj2.js → boot-reembed-bztbxc4z.js} +1 -1
- package/dist/{boot-reembed-wb44vc3s.js → boot-reembed-d7xcym0j.js} +1 -1
- package/dist/{boot-scrub-sweep-25bxhnw4.js → boot-scrub-sweep-mkmm16gk.js} +2 -2
- package/dist/{boot-seeds-nj9za0vk.js → boot-seeds-arrkbe8t.js} +4 -4
- package/dist/{boxd-wn235q80.js → boxd-68n75y1s.js} +2 -2
- package/dist/{claude-adapter-d3krpdyb.js → claude-adapter-ykpyr5p8.js} +8 -8
- package/dist/{claude-managed-adapter-t8nfgcgz.js → claude-managed-adapter-ssg6z4bt.js} +4 -4
- package/dist/{claude-managed-setup-7y4pwd81.js → claude-managed-setup-trd59v7b.js} +4 -4
- package/dist/{claude-sdk-session-d138zy0e.js → claude-sdk-session-yjcze0j1.js} +10941 -10412
- package/dist/{cli-vq2eg24x.js → cli-01tvvtad.js} +63 -60
- package/dist/cli-04zc3f7b.js +68 -0
- package/dist/{cli-01k6wpr9.js → cli-0k1a0sde.js} +7 -7
- package/dist/{cli-j6te8keb.js → cli-0pp1yjg2.js} +8 -8
- package/dist/{cli-0b4zam62.js → cli-0vcqcwfn.js} +18 -0
- package/dist/{cli-wwp1bd3n.js → cli-12vek61e.js} +564 -97
- package/dist/{cli-rqx70rcz.js → cli-17qzb39j.js} +5 -2
- package/dist/{cli-124ntmf0.js → cli-1htmtqc2.js} +143 -63
- package/dist/{cli-3f8zbtqa.js → cli-2amwhyv2.js} +15 -11
- package/dist/{cli-7sf9sb0w.js → cli-2m6yaq6b.js} +1 -1
- package/dist/{cli-6cwr32fe.js → cli-2tw284hj.js} +422 -140
- package/dist/{cli-6ehs4mta.js → cli-2z2c4k6q.js} +18 -4
- package/dist/{cli-nstkanmx.js → cli-39qm0rtm.js} +8 -8
- package/dist/{cli-hnamkvnc.js → cli-3p288654.js} +2 -2
- package/dist/{cli-4ymxrwg5.js → cli-4dyzzkfb.js} +2 -2
- package/dist/{cli-3kd08rej.js → cli-4jjrhy48.js} +1 -1
- package/dist/{cli-kxn3747f.js → cli-4se3x6qm.js} +1 -26
- package/dist/cli-52nfye5j.js +673 -0
- package/dist/cli-55tc8cj4.js +252 -0
- package/dist/cli-5r95eqbh.js +186 -0
- package/dist/{cli-6037prsx.js → cli-5tg94mdw.js} +13 -13
- package/dist/{cli-2spnz7ye.js → cli-5x03v6en.js} +11137 -8332
- package/dist/{cli-y4ccxtz5.js → cli-5z0g0e8v.js} +153 -6
- package/dist/{cli-8y43jx2r.js → cli-6p8p2e6r.js} +16 -9
- package/dist/{cli-539h29es.js → cli-72yms3ey.js} +224 -189
- package/dist/{cli-y8p78ekx.js → cli-73q4g5nx.js} +21 -21
- package/dist/{cli-p74md7t8.js → cli-7b7rxz22.js} +13 -15
- package/dist/{cli-43ms35q9.js → cli-7wy8gbwb.js} +3 -3
- package/dist/{cli-7mv4h3sn.js → cli-7yn42w6m.js} +2 -2
- package/dist/{cli-gabsjg8x.js → cli-8hp56wat.js} +3 -2
- package/dist/cli-8mfdbdhe.js +43 -0
- package/dist/{cli-zcfpsfzf.js → cli-96234j5w.js} +3 -3
- package/dist/{cli-1z4qggfe.js → cli-9fvk9mv8.js} +30 -21
- package/dist/{cli-2rnd5j3t.js → cli-9qe5y107.js} +2 -2
- package/dist/{cli-5mpy301f.js → cli-9t7syepg.js} +1 -1
- package/dist/{cli-7cp6aa1q.js → cli-9y4tgrkf.js} +23 -177
- package/dist/{cli-7evph51z.js → cli-a49frv85.js} +2 -2
- package/dist/{cli-3aaeb78m.js → cli-agjbj5x0.js} +95 -10
- package/dist/{cli-th1dkc2v.js → cli-b93d81yg.js} +2 -2
- package/dist/{cli-qj39vrc6.js → cli-bhgrhedp.js} +1 -1
- package/dist/{cli-2xv18ywz.js → cli-bmqp0ser.js} +2 -2
- package/dist/{cli-9fjr27ez.js → cli-bp6k9acz.js} +18 -22
- package/dist/{cli-5a6pqy45.js → cli-bpje8n65.js} +31 -4
- package/dist/{cli-2v2zdm0a.js → cli-bz97ff9n.js} +2 -2
- package/dist/{cli-3caf7pmg.js → cli-c7j31hq9.js} +3 -3
- package/dist/{cli-t9ga4qmb.js → cli-cah298e5.js} +40 -33
- package/dist/{cli-aw83sr40.js → cli-cjqyse9q.js} +3 -3
- package/dist/{cli-b6px1k1q.js → cli-dd2k2mcd.js} +1 -1
- package/dist/{cli-nv4xsvmk.js → cli-dkvtfgn4.js} +7 -7
- package/dist/{cli-7r162fxe.js → cli-e3ahxq5y.js} +23 -17
- package/dist/{cli-3et6fmfe.js → cli-e8n0hdzd.js} +1 -1
- package/dist/{cli-tsa40663.js → cli-ebqx630g.js} +3 -3
- package/dist/{cli-kbtzfrxj.js → cli-en6dmkxd.js} +3 -3
- package/dist/{cli-m9cvf7vs.js → cli-eq4kew31.js} +14 -14
- package/dist/{cli-fcfbct2j.js → cli-eqq0hwvx.js} +5 -5
- package/dist/{cli-7zm3b3f5.js → cli-ercwc8xn.js} +1 -1
- package/dist/{cli-vs9vdpy0.js → cli-ex1y88j3.js} +1 -1
- package/dist/{cli-mk7c5ac4.js → cli-fxd1mwtr.js} +2 -2
- package/dist/{cli-91pkxres.js → cli-fy4gb74g.js} +2 -2
- package/dist/{cli-fq2rr3jb.js → cli-fyaq4zdv.js} +6 -6
- package/dist/{cli-cc93xzes.js → cli-gfy6hbd9.js} +28 -17
- package/dist/{cli-s1khw52h.js → cli-h70a2mxy.js} +71 -17
- package/dist/cli-hbvgzjq4.js +69 -0
- package/dist/{cli-qx4f057j.js → cli-hhc47ack.js} +4 -4
- package/dist/{cli-q5srsxq2.js → cli-j5gtytvg.js} +154 -41
- package/dist/{cli-psffsanb.js → cli-js10kdk7.js} +6 -1
- package/dist/{cli-54vrpgm0.js → cli-k3facve0.js} +8 -5
- package/dist/{cli-vsw91x06.js → cli-k5jx8jya.js} +10 -6
- package/dist/{cli-tr27kwyg.js → cli-krbcr00p.js} +261 -6
- package/dist/{cli-5qhfv9rw.js → cli-kwr5qv5g.js} +44 -17
- package/dist/{cli-md50mj0r.js → cli-m5qtmrbc.js} +3 -3
- package/dist/{cli-vfqvrd82.js → cli-ma9ys8rt.js} +2 -2
- package/dist/{cli-w16kwbzw.js → cli-mbwmqb5w.js} +1 -1
- package/dist/{cli-w1q68d8x.js → cli-mcymtvwn.js} +322 -72
- package/dist/{cli-k3q2va86.js → cli-mq2fbgva.js} +66 -5
- package/dist/{cli-xqdz5cqm.js → cli-mz7ycqn8.js} +1 -0
- package/dist/{cli-kpgcm7xy.js → cli-n85m2wkq.js} +1 -1
- package/dist/{cli-v8z0yga9.js → cli-n8f0fs3c.js} +4 -4
- package/dist/{cli-mys27d03.js → cli-nja15knq.js} +3 -3
- package/dist/{cli-zk7v5s89.js → cli-pe3yxedk.js} +3 -3
- package/dist/{cli-v46zsvqk.js → cli-ph95yejc.js} +2 -2
- package/dist/{cli-6237rnyr.js → cli-pqfecppn.js} +1 -1
- package/dist/{cli-qrta34nb.js → cli-q2dywc8h.js} +4 -4
- package/dist/{cli-k6nejceb.js → cli-q4z9s6zs.js} +2 -2
- package/dist/{cli-s1zqk1aj.js → cli-q8tc22bj.js} +15 -9
- package/dist/{cli-hg42n3hx.js → cli-qrzq3hvg.js} +8 -8
- package/dist/{cli-43evxwj4.js → cli-r0mz92by.js} +9 -4
- package/dist/{cli-jrbq4djp.js → cli-r14ac1y0.js} +1 -1
- package/dist/{cli-5gpqgs8b.js → cli-rtmqzat7.js} +2 -2
- package/dist/{cli-tvgqesec.js → cli-s6zk31gr.js} +4 -4
- package/dist/{cli-6ym4jhzp.js → cli-sv2r3bw8.js} +7 -7
- package/dist/{cli-wafmk3fn.js → cli-t75xngj1.js} +12 -12
- package/dist/{cli-x40a0w9j.js → cli-tdk7jtka.js} +1 -1
- package/dist/{cli-zeh2mhkg.js → cli-tm60vtax.js} +1 -1
- package/dist/cli-tsfkcd4v.js +30 -0
- package/dist/{cli-8st34zhr.js → cli-v9ya390t.js} +57 -19
- package/dist/{cli-zfqg6fzn.js → cli-vbppqvte.js} +3 -3
- package/dist/{cli-p0n7b5rz.js → cli-wvjqaqcp.js} +2907 -151
- package/dist/{cli-sb4426be.js → cli-xf4z5bdn.js} +5 -5
- package/dist/{cli-p0c3vtch.js → cli-xm34qj8m.js} +772 -515
- package/dist/{cli-z0m452jr.js → cli-ya3kf4gs.js} +1 -1
- package/dist/{cli-had1p04a.js → cli-yegz2g06.js} +4 -4
- package/dist/{cli-k5yewqgd.js → cli-yfpc6qy9.js} +3 -3
- package/dist/{cli-q2d3e1k1.js → cli-z4f346g5.js} +1 -1
- package/dist/{cli-yab6sh8p.js → cli-zcghfsdg.js} +23 -4
- package/dist/cli.js +34 -30
- 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-wc6e4wct.js} +8 -8
- package/dist/{codex-hook-59atdwd8.js → codex-hook-aqtj17yr.js} +1 -1
- package/dist/{codex-login-a239g1ah.js → codex-login-1ven7yje.js} +1 -1
- package/dist/{codex-session-runner-xhznc4g3.js → codex-session-runner-ppfgjd97.js} +9 -9
- package/dist/{commands-d8g349v4.js → commands-tsv2vx5b.js} +3 -3
- package/dist/{controller-mwgdmb8y.js → controller-ye4sdwsy.js} +4 -4
- package/dist/{controllers-connect-5v7qx04j.js → controllers-connect-zn4dg69h.js} +25 -22
- package/dist/core-dxcy02sc.js +41 -0
- package/dist/{cursor-adapter-p2q5h35d.js → cursor-adapter-q2g9vwts.js} +2 -2
- package/dist/{db-wcw0b2j8.js → db-3r1fyr2n.js} +6 -2
- package/dist/{db-qpganbeb.js → db-g111qn9j.js} +3 -3
- package/dist/{devin-adapter-zp4tqq53.js → devin-adapter-t8d86q9x.js} +1 -1
- package/dist/{dispatcher-8d8s49yz.js → dispatcher-4q8s0mx8.js} +22 -19
- package/dist/{docker-09tkkg0n.js → docker-1b41eysj.js} +51 -14
- package/dist/{dsh-adapter-me0twn13.js → dsh-adapter-mmcw1z5s.js} +2 -2
- package/dist/{e2b-3v1e745x.js → e2b-ew8c5j5v.js} +3 -3
- package/dist/{e2b-sm28k0k3.js → e2b-xm60c8ad.js} +6 -6
- package/dist/{easter-egg-3d-wv7w5ty6.js → easter-egg-3d-04ke6hcp.js} +1 -1
- package/dist/{embedding-space-e48xchqa.js → embedding-space-kcdn52vz.js} +6 -6
- package/dist/{embeddings-tgq2afbq.js → embeddings-jnzcd91a.js} +1 -1
- package/dist/{event-bus-xr83x566.js → event-bus-v4ywhc2p.js} +1 -1
- package/dist/{execute-8rhwrk7f.js → execute-74amghty.js} +8 -4
- package/dist/{external-channel-8bt3j2pm.js → external-channel-v9zgxnxz.js} +2 -2
- package/dist/fx-adapter-0ar6pqm3.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-t6m74fb1.js +19 -0
- package/dist/handlers-9kwcrc4k.js +38 -0
- package/dist/{heartbeat-x0056ra5.js → heartbeat-p8pk1msj.js} +25 -22
- package/dist/{hook-a7vmn2st.js → hook-k1h73zd7.js} +5 -5
- package/dist/{hook-mrd2ayxv.js → hook-p5reemds.js} +8 -8
- package/dist/{http-ym9c5svp.js → http-ms1z5xxy.js} +2549 -224
- package/dist/index-23cdfzr6.js +39 -0
- package/dist/{index-01ns1pkw.js → index-76zzxtzf.js} +1 -1
- package/dist/{index-ny60jcat.js → index-fbkqhvvj.js} +40 -18
- package/dist/index-g7kkjs5b.js +38 -0
- package/dist/{index-x6azjwm8.js → index-gjn6qfgn.js} +1 -1
- package/dist/{index-b5wgnm78.js → index-kdmkfjt7.js} +4 -4
- package/dist/{index-p46tvwtx.js → index-kn63q1gr.js} +28 -25
- package/dist/{index-9myfj74s.js → index-kzdqn3dd.js} +3 -3
- package/dist/{index-4a0670yh.js → index-p2f5xg64.js} +6 -6
- package/dist/index-stk36pa5.js +43 -0
- package/dist/{k8s-m56sw868.js → k8s-fy8hbhkg.js} +73 -14
- package/dist/{keepalive-7yxg8z4c.js → keepalive-031js8jz.js} +4 -4
- package/dist/lead-mfggjtfk.js +77 -0
- package/dist/{llama-cpp-classify-nfgswa1m.js → llama-cpp-classify-yvb8vh7w.js} +2 -2
- package/dist/{maintenance-6tefxmk1.js → maintenance-sq9v3qx9.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-zqmnyvs8.js} +3 -3
- package/dist/object-webhooks-r24wwb5y.js +21 -0
- package/dist/{onboard-fja65z08.js → onboard-p25yhh7t.js} +5 -5
- 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-wcjc4zdk.js} +7 -7
- package/dist/{openrouter-images-xr9gme9x.js → openrouter-images-0jj12a2q.js} +6 -6
- package/dist/{otel-impl-7zhnt6gj.js → otel-impl-ff1gf20m.js} +2 -2
- package/dist/{pending-h01yzpx4.js → pending-hxj5yatb.js} +23 -20
- package/dist/{pi-messages-2j0fpqwq.js → pi-messages-zk3g4esn.js} +1 -1
- package/dist/{pi-mono-adapter-f52hz743.js → pi-mono-adapter-vkp4zz7p.js} +19 -18
- package/dist/{pricing-refresh-fzxvk2zf.js → pricing-refresh-9w7gx41w.js} +2 -2
- package/dist/{rbac-roles-9v6vhgbs.js → rbac-roles-84aw10nz.js} +3 -3
- package/dist/{rbac-roles-hfgh8sba.js → rbac-roles-hz74vckp.js} +2 -2
- package/dist/{registry-32b1mft6.js → registry-eeyx1201.js} +1 -1
- package/dist/{render-v2-1rgspxzf.js → render-v2-nrdkg9gf.js} +7 -6
- package/dist/{resume-tqy61x24.js → resume-s6ey36rh.js} +9 -8
- package/dist/{runtime-exkxyx5f.js → runtime-x0b4pyam.js} +2 -2
- package/dist/{session-access-3act7vt4.js → session-access-xv49tk14.js} +4 -4
- package/dist/{session-source-backfill-82qe7fqq.js → session-source-backfill-r5j988ah.js} +3 -3
- package/dist/{setup-ry1vfdef.js → setup-mj0krk1p.js} +1 -1
- package/dist/thread-buffer-temgaqsy.js +41 -0
- package/dist/tree-visibility-cbrsfaar.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-f9d8nwnw.js} +3 -3
- package/dist/{virtual-modules-s0rjzcqq.js → virtual-modules-ns0ryw05.js} +32 -10
- package/dist/{work-objects-z2e5tv03.js → work-objects-pydhzast.js} +25 -22
- package/dist/worker-efcemc22.js +77 -0
- package/dist/{worker-follow-up-y3xeg89w.js → worker-follow-up-9z2xec5e.js} +22 -19
- package/dist/{x-wg164ss9.js → x-3dtaf2r9.js} +2 -2
- package/openapi.json +2040 -559
- package/package.json +15 -11
- package/src/azure-devops/auth.ts +2 -3
- package/src/be/agent-fs-identity.ts +46 -0
- package/src/be/agent-history.ts +215 -0
- package/src/be/db/agents.ts +34 -12
- 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/tasks/write.ts +2 -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/db.ts +2 -0
- 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/migrations/332_primitive_objects.sql +31 -0
- package/src/be/migrations/334_agent_history.sql +23 -0
- package/src/be/migrations/335_primitive_object_webhooks.sql +36 -0
- package/src/be/model-profile-check.ts +1 -1
- package/src/be/multi-runtime.ts +32 -4
- package/src/be/primitives/boards/elements.ts +717 -0
- package/src/be/primitives/boards/excalifont-metrics.json +516 -0
- package/src/be/primitives/boards/service.ts +121 -0
- package/src/be/primitives/object-webhooks.ts +348 -0
- package/src/be/primitives/objects.ts +686 -0
- package/src/be/primitives/sheets/a1.ts +136 -0
- package/src/be/primitives/sheets/engine-worker.ts +194 -0
- package/src/be/primitives/sheets/engine.ts +199 -0
- package/src/be/primitives/sheets/format.ts +106 -0
- package/src/be/primitives/sheets/service.ts +415 -0
- package/src/be/primitives/write-object.ts +83 -0
- 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/script-credential-broker.ts +8 -27
- package/src/be/scripts/typecheck.ts +216 -0
- package/src/be/seed/agent-fs-provision.ts +18 -0
- package/src/be/swarm-config-guard.ts +10 -2
- package/src/be/users.ts +19 -0
- 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/onboard/agent-fs-version.ts +1 -1
- package/src/commands/onboard/steps/harness.tsx +1 -1
- package/src/commands/provider-credentials.ts +1 -0
- package/src/commands/runner.ts +116 -12
- package/src/e2b/env.ts +3 -1
- package/src/extensions/catalog.generated.json +1 -1
- package/src/fs/agent-fs-provider.ts +33 -2
- package/src/github/app.ts +59 -14
- package/src/gitlab/auth.ts +3 -4
- package/src/heartbeat/heartbeat.ts +11 -11
- package/src/http/agent-lifecycle.ts +152 -0
- package/src/http/agents.ts +12 -0
- package/src/http/all-routes.ts +4 -0
- package/src/http/auth.ts +2 -1
- 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 +36 -0
- package/src/http/mcp-user.ts +11 -8
- package/src/http/mcp.ts +58 -42
- package/src/http/object-webhooks.ts +101 -0
- package/src/http/operator-actor.ts +2 -1
- package/src/http/prompt-templates.ts +1 -0
- package/src/http/request-composition.ts +310 -0
- package/src/http/sessions.ts +7 -0
- package/src/http/tasks.ts +6 -1
- package/src/http/tool-schema-estimate.ts +95 -0
- package/src/http/workflows.ts +61 -11
- package/src/integrations/chat-sdk/inbound.ts +2 -2
- package/src/integrations/chat-sdk/outbound-files.ts +3 -2
- package/src/prompts/base-prompt.ts +133 -7
- package/src/prompts/resolver.ts +41 -2
- package/src/providers/acp-targets.ts +2 -2
- package/src/providers/amp-adapter.ts +1 -1
- package/src/providers/opencode-adapter.ts +76 -2
- 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/rbac/legacy-policy.ts +2 -0
- package/src/rbac/permissions.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/script-workflows/guest-ctx.ts +32 -0
- package/src/script-workflows/workflow-ctx.ts +2 -0
- package/src/scripts-runtime/ctx.ts +9 -1
- package/src/scripts-runtime/executors/native.ts +106 -21
- package/src/scripts-runtime/executors/quickjs-prelude.ts +9 -2
- package/src/scripts-runtime/executors/quickjs-runner.ts +12 -1
- package/src/scripts-runtime/sdk-allowlist.ts +88 -0
- package/src/scripts-runtime/swarm-sdk.ts +51 -3
- package/src/scripts-runtime/types/stdlib.d.ts +267 -0
- package/src/scripts-runtime/types/swarm-sdk.d.ts +267 -0
- package/src/server-user.ts +16 -1
- package/src/server.ts +48 -0
- 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/agent-history.test.ts +313 -0
- package/src/tests/azure-devops-auth.test.ts +6 -0
- package/src/tests/azure-devops-outbound.test.ts +47 -14
- package/src/tests/base-prompt.test.ts +149 -1
- package/src/tests/chat-sdk-outbound-files.test.ts +3 -1
- package/src/tests/check-playwright-version.test.ts +33 -0
- package/src/tests/check-unit-test-allowlist.test.ts +193 -0
- package/src/tests/context-preamble-budget.test.ts +65 -0
- package/src/tests/credential-check.test.ts +12 -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-task-read-contract.test.ts +2 -0
- package/src/tests/db-task-write-contract.test.ts +2 -0
- package/src/tests/deploy-release-dispatch.test.ts +332 -0
- package/src/tests/e2b-stack-wizard.test.tsx +156 -0
- package/src/tests/e2e-coverage-contract.test.ts +6 -2
- package/src/tests/e2e-diff-coverage.test.ts +154 -0
- package/src/tests/e2e-rerun-quarantine.test.ts +180 -0
- package/src/tests/e2e-shards.test.ts +137 -0
- package/src/tests/e2e-tracker-ingest.test.ts +266 -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/extensions-heartbeat.test.ts +34 -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/gitlab-auth.test.ts +10 -0
- package/src/tests/heartbeat.test.ts +38 -0
- package/src/tests/http-api-integration.test.ts +0 -6
- 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 +97 -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/primitives-boards.test.ts +686 -0
- package/src/tests/primitives-object-webhooks.test.ts +642 -0
- package/src/tests/primitives-objects.test.ts +248 -0
- package/src/tests/prompt-template-resolver.test.ts +85 -0
- package/src/tests/reasoning-kind-ui-parity.test.ts +112 -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/script-native-sandbox-identity.test.ts +264 -0
- package/src/tests/scripts-namespaces.test.ts +211 -0
- package/src/tests/secret-scrub-gate.test.ts +1 -0
- package/src/tests/secret-scrubber-convex.test.ts +168 -0
- package/src/tests/secret-scrubber.test.ts +1 -1
- package/src/tests/session-tokens.test.ts +27 -0
- package/src/tests/sheet-engine.test.ts +58 -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-file-tools-attachments.test.ts +74 -6
- package/src/tests/slack-reaction-config.test.ts +38 -2
- package/src/tests/slack-read-boundaries.test.ts +4 -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/task-start-after-commit.test.ts +82 -0
- package/src/tests/ui-logs-parser.test.ts +67 -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-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 +158 -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 +36 -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.ts +44 -0
- package/src/tools/boards.ts +260 -0
- package/src/tools/objects.ts +191 -0
- package/src/tools/sheets.ts +312 -0
- package/src/tools/slack-read.ts +10 -3
- package/src/tools/tool-config.ts +23 -0
- package/src/tools/workflows/create-workflow.ts +18 -4
- package/src/tools/workflows/patch-workflow-node.ts +4 -0
- package/src/tools/workflows/patch-workflow.ts +4 -0
- package/src/tools/workflows/update-workflow.ts +24 -3
- package/src/types.ts +216 -2
- package/src/utils/credentials.ts +7 -0
- package/src/utils/sandboxed-process.ts +47 -2
- package/src/utils/secret-scrubber.ts +61 -6
- package/src/workflows/checkpoint.ts +18 -0
- package/src/workflows/engine.ts +73 -31
- package/src/workflows/foreach-driver.ts +42 -4
- package/src/workflows/input.ts +29 -1
- package/src/workflows/patch-definition.ts +15 -1
- package/src/workflows/recovery.ts +6 -1
- package/src/workflows/resume.ts +11 -3
- package/src/workflows/retry-poller.ts +32 -6
- 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/validation.ts +10 -0
- package/src/workflows/wait-poller.ts +6 -2
- package/src/workflows/webhook-filter.ts +203 -0
- package/templates/ai-toolbox.manifest.json +1 -1
- package/templates/extensions/slack-reply-gate/hooks.ts +8 -4
- package/templates/skills/agent-browser/SKILL.md +1 -0
- package/templates/skills/agent-browser/content.md +1 -0
- package/templates/skills/pages/content.md +5 -0
- package/templates/skills/swarm-docs/content.md +8 -1
- package/templates/skills/swarm-scripts/SKILL.md +1 -0
- package/templates/skills/swarm-scripts/content.md +1 -0
- package/templates/skills/tdd-planning/content.md +5 -2
- package/dist/acp-adapter-bht22g3k.js +0 -16
- package/dist/core-sxy4epp2.js +0 -38
- 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
- package/src/slack/socket-mode-guard.test.ts +0 -25
- package/src/tests/agent-activity.test.ts +0 -247
- package/src/tests/agent-fs-live-url.test.ts +0 -55
- package/src/tests/agentmail-inbox-mapping.test.ts +0 -73
- package/src/tests/approval-sweeps-config.test.ts +0 -47
- package/src/tests/cards.test.ts +0 -169
- package/src/tests/chat-sdk-facts.test.ts +0 -23
- package/src/tests/config-env-export-chat-sdk.test.ts +0 -11
- package/src/tests/core-auth.test.ts +0 -156
- package/src/tests/date-utils.test.ts +0 -48
- package/src/tests/db-context-versions.test.ts +0 -37
- package/src/tests/db-runtime.test.ts +0 -131
- package/src/tests/enabled-capabilities.test.ts +0 -20
- package/src/tests/extensions-example-mcp-install.test.ts +0 -67
- package/src/tests/extensions-lead-equivalence.test.ts +0 -70
- package/src/tests/get-workflow-run-tool.test.ts +0 -98
- package/src/tests/github-event-labels.test.ts +0 -24
- package/src/tests/haiku-5-5-pricing.test.ts +0 -38
- package/src/tests/http-log-scrubbing.test.ts +0 -123
- package/src/tests/http-semconv-attributes.test.ts +0 -92
- package/src/tests/identity.test.ts +0 -117
- package/src/tests/inbox-state.test.ts +0 -167
- package/src/tests/internal-ai/models.test.ts +0 -54
- package/src/tests/launch-password-rejection.test.ts +0 -140
- package/src/tests/list-total-cache.test.ts +0 -88
- package/src/tests/match-route.test.ts +0 -187
- package/src/tests/memory-feature-flags.test.ts +0 -45
- package/src/tests/memory-get-tool.test.ts +0 -269
- package/src/tests/memory-health-endpoint.test.ts +0 -78
- package/src/tests/memory-http-access.test.ts +0 -221
- package/src/tests/memory-retrieval-purge.test.ts +0 -99
- package/src/tests/multi-runtime-enabled-stats.test.ts +0 -229
- package/src/tests/openai-embedding-provider.test.ts +0 -159
- package/src/tests/org-identity.test.ts +0 -44
- package/src/tests/pages-actions-endpoint.test.ts +0 -103
- package/src/tests/pages-browser-sdk.test.ts +0 -76
- package/src/tests/pages-feedback-keys.test.ts +0 -121
- package/src/tests/pages-frame-ancestors.test.ts +0 -189
- package/src/tests/pages-list-endpoint.test.ts +0 -148
- package/src/tests/pages-password-mode.test.ts +0 -266
- package/src/tests/pages-public-authed-401.test.ts +0 -103
- package/src/tests/pages-public-html.test.ts +0 -297
- package/src/tests/pages-public-json-redirect.test.ts +0 -122
- package/src/tests/pages-view-count.test.ts +0 -245
- package/src/tests/prompt-templates-db.test.ts +0 -616
- package/src/tests/rbac-engine.test.ts +0 -742
- package/src/tests/repo-allow-merge-gate.test.ts +0 -389
- package/src/tests/route-def-find-route.test.ts +0 -192
- package/src/tests/runtime-stale-threshold.test.ts +0 -40
- package/src/tests/schedule-validation-helper.test.ts +0 -51
- package/src/tests/scheduled-tasks-api.test.ts +0 -355
- package/src/tests/scheduler-backoff.test.ts +0 -166
- package/src/tests/script-run-token.test.ts +0 -75
- package/src/tests/scripts-extract-signature.test.ts +0 -47
- package/src/tests/scripts-sdk-bridge-tool-failure.test.ts +0 -141
- package/src/tests/seed-workflow-dreaming.test.ts +0 -117
- package/src/tests/short-id.test.ts +0 -23
- package/src/tests/skill-files-http.test.ts +0 -222
- package/src/tests/skill-get-file-tool.test.ts +0 -110
- package/src/tests/skill-script-refs.test.ts +0 -63
- package/src/tests/skill-update-scope.test.ts +0 -252
- package/src/tests/skills-bundle.test.ts +0 -99
- package/src/tests/slack-app-icon.test.ts +0 -94
- package/src/tests/slack-assistant-comention.test.ts +0 -139
- package/src/tests/slack-delete.test.ts +0 -157
- package/src/tests/slack-inbound-diagnostics-auth.test.ts +0 -93
- package/src/tests/slack-manifest.test.ts +0 -23
- package/src/tests/slack-task-output.test.ts +0 -90
- package/src/tests/store-progress-output-guidance.test.ts +0 -34
- package/src/tests/swarm-diff.test.ts +0 -728
- package/src/tests/task-lifecycle-events.test.ts +0 -53
- package/src/tests/template-asset-config.test.ts +0 -18
- package/src/tests/template-fetch.test.ts +0 -490
- package/src/tests/themes-page-theme.test.ts +0 -155
- package/src/tests/tool-annotations.test.ts +0 -442
- package/src/tests/tool-output-agent-id.test.ts +0 -202
- package/src/tests/update-profile-agentid.test.ts +0 -248
- package/src/tests/whoami-route.test.ts +0 -162
- package/src/tests/workflow-definition-telemetry.test.ts +0 -134
- package/src/tests/workflow-patch.test.ts +0 -169
- package/src/tests/workflow-run-steps-index.test.ts +0 -65
- package/src/tests/workflow-schedule-trigger.test.ts +0 -104
- package/src/tests/workflow-step-claims.test.ts +0 -152
- package/src/tests/workflow-step-order.test.ts +0 -92
- package/src/tests/workflow-trigger-schema.test.ts +0 -359
- package/src/tests/workflow-versions.test.ts +0 -240
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
bedrockProviderModule
|
|
3
|
-
} from "./cli-
|
|
3
|
+
} from "./cli-6p8p2e6r.js";
|
|
4
4
|
import {
|
|
5
5
|
auditAssetKeys,
|
|
6
6
|
init_asset_key_audit,
|
|
@@ -8,6 +8,8 @@ import {
|
|
|
8
8
|
placeholderForConfigKey,
|
|
9
9
|
isPrivateAddress,
|
|
10
10
|
assertUrlSafe,
|
|
11
|
+
EgressDeniedError,
|
|
12
|
+
createGuardedFetch,
|
|
11
13
|
init_egress_guard,
|
|
12
14
|
init_credential_broker,
|
|
13
15
|
encryptSecret,
|
|
@@ -24,6 +26,7 @@ import {
|
|
|
24
26
|
init_default_drift,
|
|
25
27
|
init_templates2,
|
|
26
28
|
init_templates3,
|
|
29
|
+
wasDbCreatedThisBoot,
|
|
27
30
|
getDb2,
|
|
28
31
|
closeDb2,
|
|
29
32
|
getDbClient2,
|
|
@@ -89,6 +92,8 @@ import {
|
|
|
89
92
|
rankingFormSchema,
|
|
90
93
|
buildListing,
|
|
91
94
|
init_telemetry_ranking,
|
|
95
|
+
isSlackIconConfigKey,
|
|
96
|
+
init_reaction_shortcode,
|
|
92
97
|
API_DRAINING_HEADER,
|
|
93
98
|
init_api_drain2,
|
|
94
99
|
parseTaskToolManifest,
|
|
@@ -124,6 +129,8 @@ import {
|
|
|
124
129
|
init_date_utils,
|
|
125
130
|
updateAgentCredentialState2,
|
|
126
131
|
updateAgentCredentialMissing2,
|
|
132
|
+
AgentDeletedError2,
|
|
133
|
+
isAgentDeleted2,
|
|
127
134
|
createAgent2,
|
|
128
135
|
getAgentById2,
|
|
129
136
|
EXTENSION_AGENT_ROLE2,
|
|
@@ -144,6 +151,7 @@ import {
|
|
|
144
151
|
getAgentHarnessProviders2,
|
|
145
152
|
updateAgentActivity2,
|
|
146
153
|
resetEmptyPollCount2,
|
|
154
|
+
deleteAgent2,
|
|
147
155
|
hasCapacity2,
|
|
148
156
|
updateAgentStatusFromCapacity2,
|
|
149
157
|
getAgentDailyTaskCounts2,
|
|
@@ -298,6 +306,7 @@ import {
|
|
|
298
306
|
triageSessionList,
|
|
299
307
|
init_session_tree,
|
|
300
308
|
setHumanFreeQueueListener,
|
|
309
|
+
reclassifyTaskHumanFree,
|
|
301
310
|
drainHumanFreeReclassifyQueue,
|
|
302
311
|
init_human_free,
|
|
303
312
|
channelTopic,
|
|
@@ -332,6 +341,8 @@ import {
|
|
|
332
341
|
assertWorkflowIdempotencyKeyUnused,
|
|
333
342
|
recordAcceptedWorkflowOperation,
|
|
334
343
|
init_workflow_idempotency,
|
|
344
|
+
deleteOrphanedRunDefinitions,
|
|
345
|
+
init_workflow_run_definitions,
|
|
335
346
|
recordKeySeatMismatch2,
|
|
336
347
|
recordKeyValidation2,
|
|
337
348
|
retirePoolKeyStatus,
|
|
@@ -463,6 +474,7 @@ import {
|
|
|
463
474
|
listSkills2,
|
|
464
475
|
searchSkills2,
|
|
465
476
|
installSkill2,
|
|
477
|
+
installSystemDefaultSkillsForAgent2,
|
|
466
478
|
uninstallSkill2,
|
|
467
479
|
getAgentSkills2,
|
|
468
480
|
createMcpServer2,
|
|
@@ -542,7 +554,7 @@ import {
|
|
|
542
554
|
countScriptRunJournalSteps2,
|
|
543
555
|
countScriptRunJournalAgentTaskSteps2,
|
|
544
556
|
init_db4
|
|
545
|
-
} from "./cli-
|
|
557
|
+
} from "./cli-12vek61e.js";
|
|
546
558
|
import {
|
|
547
559
|
PRIMARY_ROLE_NAMES2,
|
|
548
560
|
OperatorGrantedTargetError2,
|
|
@@ -556,7 +568,7 @@ import {
|
|
|
556
568
|
assertNotLastAdmin2,
|
|
557
569
|
setUserRoles2,
|
|
558
570
|
init_rbac_roles
|
|
559
|
-
} from "./cli-
|
|
571
|
+
} from "./cli-ma9ys8rt.js";
|
|
560
572
|
import {
|
|
561
573
|
MAX_MODEL_GROUP_MEMBERS,
|
|
562
574
|
listModelGroups,
|
|
@@ -566,16 +578,17 @@ import {
|
|
|
566
578
|
modelGroupReferences,
|
|
567
579
|
deleteModelGroup,
|
|
568
580
|
init_model_groups
|
|
569
|
-
} from "./cli-
|
|
581
|
+
} from "./cli-nja15knq.js";
|
|
570
582
|
import {
|
|
571
583
|
requestModelCatalogRefresh2,
|
|
572
584
|
init_pricing_refresh
|
|
573
|
-
} from "./cli-
|
|
585
|
+
} from "./cli-b93d81yg.js";
|
|
574
586
|
import {
|
|
575
587
|
workflowEventBus2,
|
|
576
588
|
init_event_bus
|
|
577
|
-
} from "./cli-
|
|
578
|
-
import"./cli-
|
|
589
|
+
} from "./cli-z4f346g5.js";
|
|
590
|
+
import"./cli-fxd1mwtr.js";
|
|
591
|
+
import"./cli-04zc3f7b.js";
|
|
579
592
|
import"./cli-9w8712tq.js";
|
|
580
593
|
import"./cli-47hz21se.js";
|
|
581
594
|
import {
|
|
@@ -612,8 +625,8 @@ import {
|
|
|
612
625
|
getSlackHttpReceiver2,
|
|
613
626
|
startSlackApp2,
|
|
614
627
|
stopSlackApp2,
|
|
615
|
-
|
|
616
|
-
} from "./cli-
|
|
628
|
+
init_app4
|
|
629
|
+
} from "./cli-72yms3ey.js";
|
|
617
630
|
import {
|
|
618
631
|
AGENT_MAX_TASKS_CONFIG_KEY,
|
|
619
632
|
reconcileAgentMaxTasksPolicy,
|
|
@@ -641,21 +654,56 @@ import {
|
|
|
641
654
|
dispatchApprovalNotifications2,
|
|
642
655
|
createApprovalFollowUpTask2,
|
|
643
656
|
init_approval_notifications
|
|
644
|
-
} from "./cli-
|
|
657
|
+
} from "./cli-gfy6hbd9.js";
|
|
645
658
|
import {
|
|
646
659
|
retryFailedRun2,
|
|
647
660
|
cancelWorkflowRun2,
|
|
648
661
|
init_resume
|
|
649
|
-
} from "./cli-
|
|
662
|
+
} from "./cli-e3ahxq5y.js";
|
|
650
663
|
import {
|
|
664
|
+
safeParse,
|
|
665
|
+
getObjectShape,
|
|
666
|
+
getLiteralValue,
|
|
667
|
+
init_zod_compat,
|
|
668
|
+
LATEST_PROTOCOL_VERSION,
|
|
651
669
|
DEFAULT_NEGOTIATED_PROTOCOL_VERSION,
|
|
652
670
|
SUPPORTED_PROTOCOL_VERSIONS,
|
|
653
671
|
isJSONRPCRequest,
|
|
654
672
|
isJSONRPCResultResponse,
|
|
673
|
+
ErrorCode,
|
|
655
674
|
isJSONRPCErrorResponse,
|
|
656
675
|
JSONRPCMessageSchema,
|
|
676
|
+
EmptyResultSchema,
|
|
657
677
|
isInitializeRequest,
|
|
678
|
+
InitializeResultSchema,
|
|
679
|
+
CreateTaskResultSchema,
|
|
680
|
+
ListResourcesResultSchema,
|
|
681
|
+
ListResourceTemplatesResultSchema,
|
|
682
|
+
ReadResourceResultSchema,
|
|
683
|
+
ResourceListChangedNotificationSchema,
|
|
684
|
+
ListPromptsResultSchema,
|
|
685
|
+
GetPromptResultSchema,
|
|
686
|
+
PromptListChangedNotificationSchema,
|
|
687
|
+
ListToolsResultSchema,
|
|
688
|
+
CallToolResultSchema,
|
|
689
|
+
ToolListChangedNotificationSchema,
|
|
690
|
+
ListChangedOptionsBaseSchema,
|
|
691
|
+
CreateMessageRequestSchema,
|
|
692
|
+
CreateMessageResultSchema,
|
|
693
|
+
CreateMessageResultWithToolsSchema,
|
|
694
|
+
ElicitRequestSchema,
|
|
695
|
+
ElicitResultSchema,
|
|
696
|
+
CompleteResultSchema,
|
|
697
|
+
McpError,
|
|
658
698
|
init_types,
|
|
699
|
+
Protocol,
|
|
700
|
+
mergeCapabilities,
|
|
701
|
+
init_protocol,
|
|
702
|
+
AjvJsonSchemaValidator,
|
|
703
|
+
init_ajv_provider,
|
|
704
|
+
assertToolsCallTaskCapability,
|
|
705
|
+
assertClientRequestTaskCapability,
|
|
706
|
+
init_helpers,
|
|
659
707
|
McpServer,
|
|
660
708
|
init_mcp,
|
|
661
709
|
referencedBundlePaths,
|
|
@@ -663,6 +711,9 @@ import {
|
|
|
663
711
|
init_manifest_format,
|
|
664
712
|
handleWebhookTrigger,
|
|
665
713
|
verifyHmacSignature,
|
|
714
|
+
decodeStandardWebhookSecret,
|
|
715
|
+
verifyStandardWebhookSignature,
|
|
716
|
+
verifyTokenEquality,
|
|
666
717
|
WebhookError,
|
|
667
718
|
init_triggers,
|
|
668
719
|
snapshotAndUpdateWorkflow,
|
|
@@ -797,6 +848,8 @@ import {
|
|
|
797
848
|
isGitHubEnabled,
|
|
798
849
|
initGitHub,
|
|
799
850
|
verifyWebhookSignature,
|
|
851
|
+
getWorkerInstallationToken,
|
|
852
|
+
init_app,
|
|
800
853
|
handlePullRequest,
|
|
801
854
|
handleIssue,
|
|
802
855
|
handleComment,
|
|
@@ -847,7 +900,7 @@ import {
|
|
|
847
900
|
init_webhook_lifecycle,
|
|
848
901
|
isJiraEnabled,
|
|
849
902
|
initJira,
|
|
850
|
-
|
|
903
|
+
init_app2,
|
|
851
904
|
handleJiraWebhook,
|
|
852
905
|
init_webhook,
|
|
853
906
|
init_jira,
|
|
@@ -858,7 +911,7 @@ import {
|
|
|
858
911
|
init_sync,
|
|
859
912
|
isLinearEnabled,
|
|
860
913
|
initLinear,
|
|
861
|
-
|
|
914
|
+
init_app3,
|
|
862
915
|
init_linear,
|
|
863
916
|
init_slack,
|
|
864
917
|
verifyPageSession,
|
|
@@ -1083,17 +1136,11 @@ import {
|
|
|
1083
1136
|
getEnabledCapabilities,
|
|
1084
1137
|
createServer,
|
|
1085
1138
|
init_server
|
|
1086
|
-
} from "./cli-
|
|
1139
|
+
} from "./cli-wvjqaqcp.js";
|
|
1087
1140
|
import {
|
|
1088
|
-
FilesError,
|
|
1089
|
-
normalizeFilesError,
|
|
1090
|
-
init_provider,
|
|
1091
|
-
agentFsRequestTimeoutMs,
|
|
1092
|
-
AgentFsProvider,
|
|
1093
|
-
init_agent_fs_provider,
|
|
1094
1141
|
getFileStorageProvider2,
|
|
1095
1142
|
init_registry2
|
|
1096
|
-
} from "./cli-
|
|
1143
|
+
} from "./cli-5r95eqbh.js";
|
|
1097
1144
|
import {
|
|
1098
1145
|
RuntimePoolError2,
|
|
1099
1146
|
mintControllerToken,
|
|
@@ -1115,7 +1162,7 @@ import {
|
|
|
1115
1162
|
resolvePoolDelivery2,
|
|
1116
1163
|
createPoolAgent2,
|
|
1117
1164
|
init_db2
|
|
1118
|
-
} from "./cli-
|
|
1165
|
+
} from "./cli-q8tc22bj.js";
|
|
1119
1166
|
import {
|
|
1120
1167
|
duplicateGuardedQueryKey,
|
|
1121
1168
|
warnIfCorsAllowsAnyOrigin,
|
|
@@ -1172,7 +1219,7 @@ import {
|
|
|
1172
1219
|
describeRequestRoute,
|
|
1173
1220
|
route,
|
|
1174
1221
|
init_route_def
|
|
1175
|
-
} from "./cli-
|
|
1222
|
+
} from "./cli-39qm0rtm.js";
|
|
1176
1223
|
import {
|
|
1177
1224
|
startPoolRouting,
|
|
1178
1225
|
stopPoolRouting,
|
|
@@ -1185,28 +1232,28 @@ import {
|
|
|
1185
1232
|
checkHeartbeatChecklist2,
|
|
1186
1233
|
runHeartbeatSweep2,
|
|
1187
1234
|
stopHeartbeat2
|
|
1188
|
-
} from "./cli-
|
|
1189
|
-
import"./cli-
|
|
1235
|
+
} from "./cli-bp6k9acz.js";
|
|
1236
|
+
import"./cli-r0mz92by.js";
|
|
1190
1237
|
import {
|
|
1191
1238
|
runtimeSupervisorStatus,
|
|
1192
1239
|
startRuntimeSupervisor,
|
|
1193
1240
|
stopRuntimeSupervisor
|
|
1194
|
-
} from "./cli-
|
|
1241
|
+
} from "./cli-v9ya390t.js";
|
|
1195
1242
|
import {
|
|
1196
1243
|
TASK_TITLE_TIMEOUT_MS,
|
|
1197
1244
|
generateTaskTitle
|
|
1198
|
-
} from "./cli-
|
|
1245
|
+
} from "./cli-eqq0hwvx.js";
|
|
1199
1246
|
import"./cli-ns59dc6r.js";
|
|
1200
1247
|
import {
|
|
1201
1248
|
ACP_TARGET_IDS
|
|
1202
|
-
} from "./cli-
|
|
1249
|
+
} from "./cli-tdk7jtka.js";
|
|
1203
1250
|
import {
|
|
1204
1251
|
reasoningCapability,
|
|
1205
1252
|
supportedReasoningLevels
|
|
1206
|
-
} from "./cli-
|
|
1253
|
+
} from "./cli-rtmqzat7.js";
|
|
1207
1254
|
import {
|
|
1208
1255
|
MAX_RATE_LIMIT_RESET_MS
|
|
1209
|
-
} from "./cli-
|
|
1256
|
+
} from "./cli-n85m2wkq.js";
|
|
1210
1257
|
import {
|
|
1211
1258
|
isLeadChannelMonitoringEnabled,
|
|
1212
1259
|
ORG_IDENTITY_KEYS,
|
|
@@ -1216,7 +1263,7 @@ import {
|
|
|
1216
1263
|
isUnknownModelError,
|
|
1217
1264
|
checkProviderPoolKey,
|
|
1218
1265
|
writeSkillsToFilesystem
|
|
1219
|
-
} from "./cli-
|
|
1266
|
+
} from "./cli-xf4z5bdn.js";
|
|
1220
1267
|
import {
|
|
1221
1268
|
AgentFsRequestError2,
|
|
1222
1269
|
resolveAgentFsSharedContext2,
|
|
@@ -1225,12 +1272,18 @@ import {
|
|
|
1225
1272
|
getCurrentOrgMembers2,
|
|
1226
1273
|
roleRank2,
|
|
1227
1274
|
agentFsRequest2,
|
|
1228
|
-
resolveApiUrl2
|
|
1229
|
-
|
|
1275
|
+
resolveApiUrl2,
|
|
1276
|
+
init_agent_fs_provision
|
|
1277
|
+
} from "./cli-01tvvtad.js";
|
|
1230
1278
|
import {
|
|
1231
1279
|
Anthropic
|
|
1232
|
-
} from "./cli-
|
|
1233
|
-
import
|
|
1280
|
+
} from "./cli-cah298e5.js";
|
|
1281
|
+
import {
|
|
1282
|
+
objectWebhookSecret2,
|
|
1283
|
+
handleObjectWebhookEvent2,
|
|
1284
|
+
init_object_webhooks
|
|
1285
|
+
} from "./cli-55tc8cj4.js";
|
|
1286
|
+
import"./cli-yegz2g06.js";
|
|
1234
1287
|
import {
|
|
1235
1288
|
createUserMergeJob2,
|
|
1236
1289
|
getUserMergeJob2,
|
|
@@ -1239,7 +1292,7 @@ import {
|
|
|
1239
1292
|
findFailedUserMergeJob2,
|
|
1240
1293
|
requeueUserMergeJob2,
|
|
1241
1294
|
runUserMergeJobs2
|
|
1242
|
-
} from "./cli-
|
|
1295
|
+
} from "./cli-en6dmkxd.js";
|
|
1243
1296
|
import {
|
|
1244
1297
|
isCodexOAuthConfigKey
|
|
1245
1298
|
} from "./cli-j4bwnpkm.js";
|
|
@@ -1250,13 +1303,13 @@ import {
|
|
|
1250
1303
|
import {
|
|
1251
1304
|
runTaskUiAction,
|
|
1252
1305
|
init_actions
|
|
1253
|
-
} from "./cli-
|
|
1306
|
+
} from "./cli-cjqyse9q.js";
|
|
1254
1307
|
import {
|
|
1255
1308
|
RATING_MODEL_MAX_LENGTH,
|
|
1256
1309
|
REFERENCES_SOURCE_MAX_LENGTH,
|
|
1257
1310
|
sanitizeReferencesSource,
|
|
1258
1311
|
init_types2
|
|
1259
|
-
} from "./cli-
|
|
1312
|
+
} from "./cli-bmqp0ser.js";
|
|
1260
1313
|
import {
|
|
1261
1314
|
require_dist,
|
|
1262
1315
|
getMcpOAuthToken,
|
|
@@ -1345,7 +1398,7 @@ import {
|
|
|
1345
1398
|
init_typecheck,
|
|
1346
1399
|
parseSkillContent,
|
|
1347
1400
|
init_skill_parser
|
|
1348
|
-
} from "./cli-
|
|
1401
|
+
} from "./cli-mcymtvwn.js";
|
|
1349
1402
|
import {
|
|
1350
1403
|
signalProcessGroup,
|
|
1351
1404
|
detachedProcessGroup,
|
|
@@ -1362,8 +1415,18 @@ import {
|
|
|
1362
1415
|
forceRefreshAuthorizationOrThrow,
|
|
1363
1416
|
forceRefreshTokenOrThrow,
|
|
1364
1417
|
init_ensure_token
|
|
1365
|
-
} from "./cli-
|
|
1366
|
-
import"./cli-
|
|
1418
|
+
} from "./cli-9qe5y107.js";
|
|
1419
|
+
import"./cli-52nfye5j.js";
|
|
1420
|
+
import"./cli-hbvgzjq4.js";
|
|
1421
|
+
import {
|
|
1422
|
+
FilesError,
|
|
1423
|
+
normalizeFilesError,
|
|
1424
|
+
init_provider,
|
|
1425
|
+
agentFsRequestTimeoutMs,
|
|
1426
|
+
AgentFsProvider,
|
|
1427
|
+
init_agent_fs_provider
|
|
1428
|
+
} from "./cli-9y4tgrkf.js";
|
|
1429
|
+
import"./cli-r14ac1y0.js";
|
|
1367
1430
|
import {
|
|
1368
1431
|
automationIntegrationFixUrl,
|
|
1369
1432
|
preflightAutomation,
|
|
@@ -1371,6 +1434,9 @@ import {
|
|
|
1371
1434
|
listEnabledAutomationPreflightInputs,
|
|
1372
1435
|
setupIntegrationFlags,
|
|
1373
1436
|
init_automation_preflight,
|
|
1437
|
+
serverRefInputKeys,
|
|
1438
|
+
serverRefInputDeniedMessage,
|
|
1439
|
+
init_input,
|
|
1374
1440
|
validateJsonSchema,
|
|
1375
1441
|
init_json_schema_validator,
|
|
1376
1442
|
workflowSaveWarnings,
|
|
@@ -1382,7 +1448,7 @@ import {
|
|
|
1382
1448
|
definitionNodeIds,
|
|
1383
1449
|
validateDefinition,
|
|
1384
1450
|
init_definition2
|
|
1385
|
-
} from "./cli-
|
|
1451
|
+
} from "./cli-j5gtytvg.js";
|
|
1386
1452
|
import {
|
|
1387
1453
|
_fetchHolder,
|
|
1388
1454
|
CLIENT_ID,
|
|
@@ -1398,7 +1464,7 @@ import {
|
|
|
1398
1464
|
loadAllCodexOAuthSlots,
|
|
1399
1465
|
getValidCodexOAuth,
|
|
1400
1466
|
init_storage
|
|
1401
|
-
} from "./cli-
|
|
1467
|
+
} from "./cli-2m6yaq6b.js";
|
|
1402
1468
|
import {
|
|
1403
1469
|
isMultiRuntimeEnabled,
|
|
1404
1470
|
init_multi_runtime2
|
|
@@ -1410,7 +1476,7 @@ import {
|
|
|
1410
1476
|
import {
|
|
1411
1477
|
createRuntimeProvider,
|
|
1412
1478
|
init_runtime_providers
|
|
1413
|
-
} from "./cli-
|
|
1479
|
+
} from "./cli-s6zk31gr.js";
|
|
1414
1480
|
import {
|
|
1415
1481
|
require_content_type
|
|
1416
1482
|
} from "./cli-1jx0srjt.js";
|
|
@@ -1432,12 +1498,12 @@ import {
|
|
|
1432
1498
|
revokeMcpToken,
|
|
1433
1499
|
computeExpiresAt,
|
|
1434
1500
|
init_mcp_wrapper
|
|
1435
|
-
} from "./cli-
|
|
1501
|
+
} from "./cli-bz97ff9n.js";
|
|
1436
1502
|
import"./cli-v41kn3cd.js";
|
|
1437
1503
|
import {
|
|
1438
1504
|
setBedrockProviderModule,
|
|
1439
1505
|
init_bedrock_converse_stream_lazy
|
|
1440
|
-
} from "./cli-
|
|
1506
|
+
} from "./cli-k3facve0.js";
|
|
1441
1507
|
import {
|
|
1442
1508
|
import_websocket,
|
|
1443
1509
|
import_websocket_server,
|
|
@@ -1458,7 +1524,8 @@ import {
|
|
|
1458
1524
|
mintToken,
|
|
1459
1525
|
revokeToken,
|
|
1460
1526
|
revokeAllUserCredentials,
|
|
1461
|
-
|
|
1527
|
+
resolveUserToken,
|
|
1528
|
+
isLiveUserToken,
|
|
1462
1529
|
InvalidRuntimeTokenError,
|
|
1463
1530
|
mintSessionToken,
|
|
1464
1531
|
mintRuntimeToken,
|
|
@@ -1468,13 +1535,10 @@ import {
|
|
|
1468
1535
|
mintAgentToken,
|
|
1469
1536
|
rotateAgentToken,
|
|
1470
1537
|
revokeAgentTokens,
|
|
1538
|
+
revokeAllAgentSessionTokens,
|
|
1471
1539
|
fingerprintApiKey,
|
|
1472
1540
|
init_users
|
|
1473
|
-
} from "./cli-
|
|
1474
|
-
import {
|
|
1475
|
-
resolveGitHubHost,
|
|
1476
|
-
init_github_host
|
|
1477
|
-
} from "./cli-9ttx00s3.js";
|
|
1541
|
+
} from "./cli-k5jx8jya.js";
|
|
1478
1542
|
import {
|
|
1479
1543
|
MAX_PROVIDER_QUOTA_ENTRIES,
|
|
1480
1544
|
ProviderQuotaCapacityError,
|
|
@@ -1483,13 +1547,11 @@ import {
|
|
|
1483
1547
|
providerAccountTelemetrySchema,
|
|
1484
1548
|
rateLimitReplacementSchema,
|
|
1485
1549
|
init_provider_account_telemetry
|
|
1486
|
-
} from "./cli-
|
|
1550
|
+
} from "./cli-7wy8gbwb.js";
|
|
1487
1551
|
import {
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
init_codex_auth_failure
|
|
1492
|
-
} from "./cli-fw2w0kva.js";
|
|
1552
|
+
resolveGitHubHost,
|
|
1553
|
+
init_github_host
|
|
1554
|
+
} from "./cli-9ttx00s3.js";
|
|
1493
1555
|
import {
|
|
1494
1556
|
ASSET_KEY_MAX_LENGTH,
|
|
1495
1557
|
AssetKeyError,
|
|
@@ -1557,6 +1619,7 @@ import {
|
|
|
1557
1619
|
AgentAvatarSchema,
|
|
1558
1620
|
AgentSlackIconSchema,
|
|
1559
1621
|
AgentSchema,
|
|
1622
|
+
AgentHistoryEventSchema,
|
|
1560
1623
|
AgentLatestModelSchema,
|
|
1561
1624
|
AgentAcpStatusSchema,
|
|
1562
1625
|
AgentCredStatusSchema,
|
|
@@ -1647,6 +1710,9 @@ import {
|
|
|
1647
1710
|
ContextSnapshotEventTypeSchema,
|
|
1648
1711
|
ContextFormulaSchema,
|
|
1649
1712
|
ContextSnapshotSchema,
|
|
1713
|
+
RequestCompositionPartInputSchema,
|
|
1714
|
+
RequestCompositionToolLoadingSchema,
|
|
1715
|
+
RequestCompositionSchema,
|
|
1650
1716
|
BudgetScopeSchema,
|
|
1651
1717
|
BudgetSchema,
|
|
1652
1718
|
PricingProviderSchema,
|
|
@@ -1659,12 +1725,22 @@ import {
|
|
|
1659
1725
|
KvKeySchema,
|
|
1660
1726
|
KvEntrySchema,
|
|
1661
1727
|
init_types5
|
|
1662
|
-
} from "./cli-
|
|
1728
|
+
} from "./cli-5z0g0e8v.js";
|
|
1729
|
+
import {
|
|
1730
|
+
CORE_TOOLS,
|
|
1731
|
+
init_tool_config
|
|
1732
|
+
} from "./cli-0vcqcwfn.js";
|
|
1733
|
+
import {
|
|
1734
|
+
CODEX_AUTH_FAILURE_BENCH_THRESHOLD,
|
|
1735
|
+
CODEX_AUTH_WATCH_NAMESPACE,
|
|
1736
|
+
codexAuthBenchMarkerKey,
|
|
1737
|
+
init_codex_auth_failure
|
|
1738
|
+
} from "./cli-fw2w0kva.js";
|
|
1663
1739
|
import {
|
|
1664
1740
|
IDENTITY_FIELD_BUDGETS,
|
|
1665
1741
|
IdentityFieldBudgetError,
|
|
1666
1742
|
init_identity_field_budget
|
|
1667
|
-
} from "./cli-
|
|
1743
|
+
} from "./cli-agjbj5x0.js";
|
|
1668
1744
|
import {
|
|
1669
1745
|
isSteeringEnabled2,
|
|
1670
1746
|
init_steering_enabled
|
|
@@ -1692,7 +1768,7 @@ import {
|
|
|
1692
1768
|
splitCredentialPool,
|
|
1693
1769
|
selectCredential,
|
|
1694
1770
|
init_credentials2
|
|
1695
|
-
} from "./cli-
|
|
1771
|
+
} from "./cli-js10kdk7.js";
|
|
1696
1772
|
import {
|
|
1697
1773
|
getOpenRouterAttributionHeaders,
|
|
1698
1774
|
init_openrouter_base_url
|
|
@@ -1706,10 +1782,10 @@ import {
|
|
|
1706
1782
|
resolveTemplate,
|
|
1707
1783
|
init_resolver,
|
|
1708
1784
|
init_session_templates
|
|
1709
|
-
} from "./cli-
|
|
1785
|
+
} from "./cli-2z2c4k6q.js";
|
|
1710
1786
|
import {
|
|
1711
1787
|
init_zod
|
|
1712
|
-
} from "./cli-
|
|
1788
|
+
} from "./cli-96234j5w.js";
|
|
1713
1789
|
import {
|
|
1714
1790
|
NEVER,
|
|
1715
1791
|
toJSONSchema,
|
|
@@ -1736,7 +1812,7 @@ import {
|
|
|
1736
1812
|
ZodIssueCode,
|
|
1737
1813
|
exports_iso,
|
|
1738
1814
|
exports_coerce
|
|
1739
|
-
} from "./cli-
|
|
1815
|
+
} from "./cli-qrzq3hvg.js";
|
|
1740
1816
|
import {
|
|
1741
1817
|
MAX_PROFILE_FILE_LENGTH,
|
|
1742
1818
|
DEFAULT_APP_URL,
|
|
@@ -1759,7 +1835,7 @@ import {
|
|
|
1759
1835
|
import {
|
|
1760
1836
|
init_package,
|
|
1761
1837
|
package_default
|
|
1762
|
-
} from "./cli-
|
|
1838
|
+
} from "./cli-2amwhyv2.js";
|
|
1763
1839
|
import {
|
|
1764
1840
|
realtimeBus,
|
|
1765
1841
|
init_bus
|
|
@@ -1775,7 +1851,7 @@ import {
|
|
|
1775
1851
|
registerVolatileSecret,
|
|
1776
1852
|
registerEnvSecrets,
|
|
1777
1853
|
init_secret_scrubber
|
|
1778
|
-
} from "./cli-
|
|
1854
|
+
} from "./cli-bpje8n65.js";
|
|
1779
1855
|
import {
|
|
1780
1856
|
__toESM
|
|
1781
1857
|
} from "./cli-242037k3.js";
|
|
@@ -1843,8 +1919,71 @@ init_types5();
|
|
|
1843
1919
|
init_env_flag();
|
|
1844
1920
|
init_secret_scrubber();
|
|
1845
1921
|
init_db4();
|
|
1846
|
-
init_swarm_config_guard();
|
|
1847
1922
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
1923
|
+
|
|
1924
|
+
// src/be/db/workflow-run-retention.ts
|
|
1925
|
+
init_runtime2();
|
|
1926
|
+
init_human_free();
|
|
1927
|
+
init_workflow_run_definitions();
|
|
1928
|
+
init_workflow_runs();
|
|
1929
|
+
var TERMINAL_SQL = "('completed', 'failed', 'skipped', 'cancelled')";
|
|
1930
|
+
var ELIGIBLE_SQL = `r.status IN ${TERMINAL_SQL} AND r.finishedAt < ?1
|
|
1931
|
+
AND NOT EXISTS (SELECT 1 FROM workflow_run_steps parent WHERE parent.id = r.parentStepId)
|
|
1932
|
+
AND NOT EXISTS (
|
|
1933
|
+
WITH RECURSIVE descendants(id, status, finishedAt, depth) AS (
|
|
1934
|
+
SELECT r.id, r.status, r.finishedAt, 0
|
|
1935
|
+
UNION ALL
|
|
1936
|
+
SELECT child.id, child.status, child.finishedAt, descendants.depth + 1
|
|
1937
|
+
FROM descendants
|
|
1938
|
+
JOIN workflow_run_steps step ON step.runId = descendants.id
|
|
1939
|
+
JOIN workflow_runs child ON child.parentStepId = step.id
|
|
1940
|
+
WHERE descendants.depth < ${WORKFLOW_RUN_TREE_MAX_DEPTH}
|
|
1941
|
+
)
|
|
1942
|
+
SELECT 1 FROM descendants
|
|
1943
|
+
WHERE status NOT IN ${TERMINAL_SQL} OR finishedAt IS NULL OR finishedAt >= ?1
|
|
1944
|
+
OR depth = ${WORKFLOW_RUN_TREE_MAX_DEPTH}
|
|
1945
|
+
)`;
|
|
1946
|
+
var WORKFLOW_RETENTION_CANDIDATES_SQL = `SELECT r.id, r.definitionHash
|
|
1947
|
+
FROM workflow_runs r WHERE ${ELIGIBLE_SQL} ORDER BY r.finishedAt, r.id LIMIT ?2`;
|
|
1948
|
+
function workflowRunRetentionStatements(cutoff) {
|
|
1949
|
+
return {
|
|
1950
|
+
backlogSql: `SELECT COUNT(*) AS n FROM workflow_runs r WHERE ${ELIGIBLE_SQL}`,
|
|
1951
|
+
deleteSql: `DELETE FROM workflow_runs WHERE id IN (
|
|
1952
|
+
SELECT r.id FROM workflow_runs r WHERE ${ELIGIBLE_SQL}
|
|
1953
|
+
ORDER BY r.finishedAt, r.id LIMIT ?2
|
|
1954
|
+
)`,
|
|
1955
|
+
params: [cutoff]
|
|
1956
|
+
};
|
|
1957
|
+
}
|
|
1958
|
+
async function deleteWorkflowRunRetentionBatch(cutoff, limit, deadlineAt) {
|
|
1959
|
+
const client = getDbClient2();
|
|
1960
|
+
return await client.transaction(async (tx) => {
|
|
1961
|
+
const started = performance.now();
|
|
1962
|
+
const runs = await tx.query(WORKFLOW_RETENTION_CANDIDATES_SQL, [cutoff, limit]);
|
|
1963
|
+
if (runs.length === 0)
|
|
1964
|
+
return { changes: 0, executionMs: performance.now() - started };
|
|
1965
|
+
const ids = JSON.stringify(runs.map((run) => run.id));
|
|
1966
|
+
const runIds = "SELECT value FROM json_each(?)";
|
|
1967
|
+
const stepIds = `SELECT id FROM workflow_run_steps WHERE runId IN (${runIds})`;
|
|
1968
|
+
const taskWhere = `workflowRunId IN (${runIds}) OR workflowRunStepId IN (${stepIds})`;
|
|
1969
|
+
const tasks = await tx.query(`SELECT id FROM agent_tasks WHERE ${taskWhere}`, [ids, ids]);
|
|
1970
|
+
await tx.run(`UPDATE agent_tasks SET workflowRunId = NULL, workflowRunStepId = NULL WHERE ${taskWhere}`, [ids, ids]);
|
|
1971
|
+
for (const table of ["approval_requests", "wait_states"]) {
|
|
1972
|
+
await tx.run(`DELETE FROM ${table} WHERE workflowRunId IN (${runIds}) OR workflowRunStepId IN (${stepIds})`, [ids, ids]);
|
|
1973
|
+
}
|
|
1974
|
+
await tx.run(`DELETE FROM workflow_run_steps WHERE runId IN (${runIds})`, [ids]);
|
|
1975
|
+
await tx.run(`DELETE FROM workflow_runs WHERE id IN (${runIds})`, [ids]);
|
|
1976
|
+
await reclassifyTaskHumanFree(tasks.map((task) => task.id));
|
|
1977
|
+
await deleteOrphanedRunDefinitions([
|
|
1978
|
+
...new Set(runs.flatMap((run) => run.definitionHash ? [run.definitionHash] : []))
|
|
1979
|
+
]);
|
|
1980
|
+
return { changes: runs.length, executionMs: performance.now() - started };
|
|
1981
|
+
}, { deadlineAt });
|
|
1982
|
+
}
|
|
1983
|
+
|
|
1984
|
+
// src/be/db-retention.ts
|
|
1985
|
+
init_db_client();
|
|
1986
|
+
init_swarm_config_guard();
|
|
1848
1987
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
1849
1988
|
var RETENTION_INTERVAL_MS = 60 * 60 * 1000;
|
|
1850
1989
|
var DEFAULT_TICK_BUDGET_MS = 30000;
|
|
@@ -1860,6 +1999,7 @@ var DB_RETENTION_TABLES = [
|
|
|
1860
1999
|
policy: "age",
|
|
1861
2000
|
timeColumn: "createdAt",
|
|
1862
2001
|
envKey: "SESSION_LOG_RETENTION_DAYS",
|
|
2002
|
+
newInstallDefault: 30,
|
|
1863
2003
|
metricsKey: "sessionLogs"
|
|
1864
2004
|
},
|
|
1865
2005
|
{
|
|
@@ -1867,6 +2007,7 @@ var DB_RETENTION_TABLES = [
|
|
|
1867
2007
|
policy: "age",
|
|
1868
2008
|
timeColumn: "createdAt",
|
|
1869
2009
|
envKey: "AGENT_LOG_RETENTION_DAYS",
|
|
2010
|
+
newInstallDefault: 90,
|
|
1870
2011
|
metricsKey: "agentLog"
|
|
1871
2012
|
},
|
|
1872
2013
|
{
|
|
@@ -1874,6 +2015,7 @@ var DB_RETENTION_TABLES = [
|
|
|
1874
2015
|
policy: "age",
|
|
1875
2016
|
timeColumn: "createdAt",
|
|
1876
2017
|
envKey: "EVENTS_RETENTION_DAYS",
|
|
2018
|
+
newInstallDefault: 90,
|
|
1877
2019
|
metricsKey: "events"
|
|
1878
2020
|
},
|
|
1879
2021
|
{
|
|
@@ -1882,6 +2024,7 @@ var DB_RETENTION_TABLES = [
|
|
|
1882
2024
|
partitionBy: "agentId, field",
|
|
1883
2025
|
rankBy: "version",
|
|
1884
2026
|
envKey: "CONTEXT_VERSIONS_KEEP_LATEST",
|
|
2027
|
+
newInstallDefault: 100,
|
|
1885
2028
|
metricsKey: "contextVersions",
|
|
1886
2029
|
initialBatchSize: 50,
|
|
1887
2030
|
maxBatchSize: 100
|
|
@@ -1895,9 +2038,19 @@ var DB_RETENTION_TABLES = [
|
|
|
1895
2038
|
terminalStatuses: TERMINAL_SCRIPT_RUN_STATUSES,
|
|
1896
2039
|
keepWhenSet: "idempotencyKey",
|
|
1897
2040
|
envKey: "SCRIPT_RUNS_RETENTION_DAYS",
|
|
2041
|
+
newInstallDefault: 30,
|
|
1898
2042
|
metricsKey: "scriptRuns",
|
|
1899
2043
|
initialBatchSize: 100,
|
|
1900
2044
|
maxBatchSize: 500
|
|
2045
|
+
},
|
|
2046
|
+
{
|
|
2047
|
+
table: "workflow_runs",
|
|
2048
|
+
policy: "workflowRuns",
|
|
2049
|
+
envKey: "WORKFLOW_RUNS_RETENTION_DAYS",
|
|
2050
|
+
metricsKey: "workflowRuns",
|
|
2051
|
+
initialBatchSize: 10,
|
|
2052
|
+
minBatchSize: 1,
|
|
2053
|
+
maxBatchSize: 100
|
|
1901
2054
|
}
|
|
1902
2055
|
];
|
|
1903
2056
|
|
|
@@ -2021,6 +2174,10 @@ function maxBatchSize(table) {
|
|
|
2021
2174
|
return "maxBatchSize" in table ? table.maxBatchSize : MAX_BATCH_SIZE;
|
|
2022
2175
|
}
|
|
2023
2176
|
function sweepStatements(table, value, now) {
|
|
2177
|
+
if (table.policy === "workflowRuns") {
|
|
2178
|
+
const iso = new Date(now.getTime() - value * DAY_MS).toISOString();
|
|
2179
|
+
return workflowRunRetentionStatements(`${iso.slice(0, 10)} ${iso.slice(11, 19)}`);
|
|
2180
|
+
}
|
|
2024
2181
|
if (table.policy === "keepLatest") {
|
|
2025
2182
|
const ranked = `SELECT rowid AS rid, ROW_NUMBER() OVER (PARTITION BY ${table.partitionBy} ORDER BY ${table.rankBy} DESC) AS rn FROM ${table.table}`;
|
|
2026
2183
|
return {
|
|
@@ -2081,21 +2238,30 @@ async function sweepTable(table, statements, dryRun, deadline, signal, maxStatem
|
|
|
2081
2238
|
let slowestStatementMs = 0;
|
|
2082
2239
|
let size = batchSizeByTable[table.metricsKey] ?? initialBatchSize(table);
|
|
2083
2240
|
const ceiling = maxBatchSize(table);
|
|
2241
|
+
const floor = "minBatchSize" in table ? table.minBatchSize : MIN_BATCH_SIZE;
|
|
2084
2242
|
try {
|
|
2085
2243
|
while (!signal.aborted && Date.now() < deadline) {
|
|
2086
2244
|
const limitUsed = size;
|
|
2087
|
-
|
|
2245
|
+
let result;
|
|
2246
|
+
try {
|
|
2247
|
+
result = table.policy === "workflowRuns" ? await deleteWorkflowRunRetentionBatch(String(statements.params[0]), limitUsed, deadline) : await client.runTimed(statements.deleteSql, [...statements.params, limitUsed]);
|
|
2248
|
+
} catch (err) {
|
|
2249
|
+
if (table.policy !== "workflowRuns" || !(err instanceof DbTransactionDeadlineError))
|
|
2250
|
+
throw err;
|
|
2251
|
+
size = Math.max(floor, Math.floor(size / 2));
|
|
2252
|
+
break;
|
|
2253
|
+
}
|
|
2088
2254
|
const elapsed = result.executionMs;
|
|
2089
2255
|
bestEffortRecordStatement(table.table, dryRun, elapsed);
|
|
2090
2256
|
slowestStatementMs = Math.max(slowestStatementMs, elapsed);
|
|
2091
2257
|
rowsDeleted += result.changes;
|
|
2092
2258
|
batches += 1;
|
|
2093
2259
|
if (elapsed > maxStatementMs) {
|
|
2094
|
-
size = Math.max(
|
|
2260
|
+
size = Math.max(floor, Math.floor(size / 2));
|
|
2095
2261
|
} else if (elapsed < maxStatementMs / 5) {
|
|
2096
2262
|
size = Math.min(ceiling, size * 2);
|
|
2097
2263
|
}
|
|
2098
|
-
if (result.changes < limitUsed)
|
|
2264
|
+
if (result.changes === 0 || table.policy !== "workflowRuns" && result.changes < limitUsed)
|
|
2099
2265
|
break;
|
|
2100
2266
|
if (signal.aborted || Date.now() >= deadline)
|
|
2101
2267
|
break;
|
|
@@ -2363,6 +2529,35 @@ async function stopDbRetention() {
|
|
|
2363
2529
|
await retentionTickPromise;
|
|
2364
2530
|
}
|
|
2365
2531
|
|
|
2532
|
+
// src/be/db-retention-defaults.ts
|
|
2533
|
+
init_db4();
|
|
2534
|
+
init_runtime2();
|
|
2535
|
+
async function seedDbRetentionDefaults(isNewInstall = wasDbCreatedThisBoot()) {
|
|
2536
|
+
if (!isNewInstall)
|
|
2537
|
+
return [];
|
|
2538
|
+
const seeded = [];
|
|
2539
|
+
await getDbClient2().transaction(async () => {
|
|
2540
|
+
for (const table of DB_RETENTION_TABLES) {
|
|
2541
|
+
if (!("newInstallDefault" in table) || process.env[table.envKey] !== undefined)
|
|
2542
|
+
continue;
|
|
2543
|
+
const existing = await getSwarmConfigs2({ scope: "global", key: table.envKey });
|
|
2544
|
+
if (existing.length > 0)
|
|
2545
|
+
continue;
|
|
2546
|
+
await upsertSwarmConfig2({
|
|
2547
|
+
scope: "global",
|
|
2548
|
+
key: table.envKey,
|
|
2549
|
+
value: String(table.newInstallDefault),
|
|
2550
|
+
description: `New-install default: ${table.table} retention. Rows past it are permanently deleted. Delete this entry to turn the sweep off.`
|
|
2551
|
+
});
|
|
2552
|
+
seeded.push(`${table.envKey}=${table.newInstallDefault}`);
|
|
2553
|
+
}
|
|
2554
|
+
});
|
|
2555
|
+
if (seeded.length > 0) {
|
|
2556
|
+
console.log(`[startup] New database: stored default retention (${seeded.join(", ")}). Rows past these limits are permanently deleted; change or delete each key in Settings → Configuration.`);
|
|
2557
|
+
}
|
|
2558
|
+
return seeded;
|
|
2559
|
+
}
|
|
2560
|
+
|
|
2366
2561
|
// src/http/index.ts
|
|
2367
2562
|
init_event_loop_lag();
|
|
2368
2563
|
|
|
@@ -2422,6 +2617,489 @@ function stopHumanFreeDrain() {
|
|
|
2422
2617
|
passTimer = null;
|
|
2423
2618
|
}
|
|
2424
2619
|
|
|
2620
|
+
// src/be/mcp-events/dispatcher.ts
|
|
2621
|
+
init_db4();
|
|
2622
|
+
init_users();
|
|
2623
|
+
init_constants3();
|
|
2624
|
+
init_secret_scrubber();
|
|
2625
|
+
init_event_bus();
|
|
2626
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
2627
|
+
|
|
2628
|
+
// src/be/mcp-events/catalog.ts
|
|
2629
|
+
init_env_flag();
|
|
2630
|
+
var EVENTS_EXTENSION_ID = "io.modelcontextprotocol/events";
|
|
2631
|
+
function isMcpUserEventsEnabled(env = process.env) {
|
|
2632
|
+
return parseEnvFlag(env.MCP_USER_EVENTS_ENABLED, true);
|
|
2633
|
+
}
|
|
2634
|
+
var EventsErrorCode = {
|
|
2635
|
+
InvalidParams: -32602,
|
|
2636
|
+
NotFound: -32023,
|
|
2637
|
+
Forbidden: -32024,
|
|
2638
|
+
ResourceExhausted: -32025,
|
|
2639
|
+
Unsupported: -32026,
|
|
2640
|
+
CallbackEndpointError: -32027
|
|
2641
|
+
};
|
|
2642
|
+
var ARGUMENTS_SCHEMA = {
|
|
2643
|
+
type: "object",
|
|
2644
|
+
properties: {
|
|
2645
|
+
taskId: {
|
|
2646
|
+
type: "string",
|
|
2647
|
+
description: "Only this task and the tasks created under it. Omit to receive every task you requested."
|
|
2648
|
+
}
|
|
2649
|
+
},
|
|
2650
|
+
additionalProperties: false
|
|
2651
|
+
};
|
|
2652
|
+
var BASE_PAYLOAD_PROPERTIES = {
|
|
2653
|
+
taskId: { type: "string" },
|
|
2654
|
+
parentTaskId: { type: ["string", "null"] },
|
|
2655
|
+
status: { type: "string" },
|
|
2656
|
+
task: { type: "string", description: "The task description, truncated." },
|
|
2657
|
+
url: { type: "string", description: "Dashboard link to the task." }
|
|
2658
|
+
};
|
|
2659
|
+
var EVENT_DESCRIPTORS = [
|
|
2660
|
+
{
|
|
2661
|
+
name: "task.completed",
|
|
2662
|
+
description: "Fires when a task you requested completes. Read the full result with get-task-details.",
|
|
2663
|
+
delivery: ["webhook"],
|
|
2664
|
+
inputSchema: ARGUMENTS_SCHEMA,
|
|
2665
|
+
payloadSchema: {
|
|
2666
|
+
type: "object",
|
|
2667
|
+
properties: {
|
|
2668
|
+
...BASE_PAYLOAD_PROPERTIES,
|
|
2669
|
+
output: { type: "string", description: "The task output, truncated." },
|
|
2670
|
+
truncated: { type: "boolean" }
|
|
2671
|
+
},
|
|
2672
|
+
required: ["taskId", "status", "url"]
|
|
2673
|
+
}
|
|
2674
|
+
},
|
|
2675
|
+
{
|
|
2676
|
+
name: "task.failed",
|
|
2677
|
+
description: "Fires when a task you requested fails. Read the details with get-task-details.",
|
|
2678
|
+
delivery: ["webhook"],
|
|
2679
|
+
inputSchema: ARGUMENTS_SCHEMA,
|
|
2680
|
+
payloadSchema: {
|
|
2681
|
+
type: "object",
|
|
2682
|
+
properties: {
|
|
2683
|
+
...BASE_PAYLOAD_PROPERTIES,
|
|
2684
|
+
failureReason: { type: "string", description: "Why the task failed, truncated." },
|
|
2685
|
+
truncated: { type: "boolean" }
|
|
2686
|
+
},
|
|
2687
|
+
required: ["taskId", "status", "url"]
|
|
2688
|
+
}
|
|
2689
|
+
}
|
|
2690
|
+
];
|
|
2691
|
+
function isTaskEventName(name) {
|
|
2692
|
+
return name === "task.completed" || name === "task.failed";
|
|
2693
|
+
}
|
|
2694
|
+
function parseTaskEventArguments(raw) {
|
|
2695
|
+
if (raw === undefined || raw === null)
|
|
2696
|
+
return {};
|
|
2697
|
+
if (typeof raw !== "object" || Array.isArray(raw))
|
|
2698
|
+
return null;
|
|
2699
|
+
const entries = Object.entries(raw);
|
|
2700
|
+
const out = {};
|
|
2701
|
+
for (const [key, value] of entries) {
|
|
2702
|
+
if (key !== "taskId")
|
|
2703
|
+
return null;
|
|
2704
|
+
if (typeof value !== "string" || value.length === 0 || value.length > 200)
|
|
2705
|
+
return null;
|
|
2706
|
+
out.taskId = value;
|
|
2707
|
+
}
|
|
2708
|
+
return out;
|
|
2709
|
+
}
|
|
2710
|
+
|
|
2711
|
+
// src/be/mcp-events/store.ts
|
|
2712
|
+
init_crypto();
|
|
2713
|
+
init_db4();
|
|
2714
|
+
import { createHash } from "node:crypto";
|
|
2715
|
+
function canonicalJson(value) {
|
|
2716
|
+
if (value === null || typeof value !== "object")
|
|
2717
|
+
return JSON.stringify(value);
|
|
2718
|
+
if (Array.isArray(value))
|
|
2719
|
+
return `[${value.map(canonicalJson).join(",")}]`;
|
|
2720
|
+
const entries = Object.entries(value).filter(([, v]) => v !== undefined).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
2721
|
+
return `{${entries.map(([k, v]) => `${JSON.stringify(k)}:${canonicalJson(v)}`).join(",")}}`;
|
|
2722
|
+
}
|
|
2723
|
+
function subscriptionIdFor(userId, url, eventName, argumentsJson) {
|
|
2724
|
+
const digest = createHash("sha256").update(canonicalJson([userId, url, eventName, argumentsJson])).digest("hex");
|
|
2725
|
+
return `sub_${digest.slice(0, 32)}`;
|
|
2726
|
+
}
|
|
2727
|
+
function sealSecret(secret) {
|
|
2728
|
+
return encryptSecret(secret, getEncryptionKey());
|
|
2729
|
+
}
|
|
2730
|
+
function unsealSecret(sealed) {
|
|
2731
|
+
return decryptSecret(sealed, getEncryptionKey());
|
|
2732
|
+
}
|
|
2733
|
+
async function getSubscription(id) {
|
|
2734
|
+
return getDbClient2().get("SELECT * FROM mcp_event_subscriptions WHERE id = ?", [
|
|
2735
|
+
id
|
|
2736
|
+
]);
|
|
2737
|
+
}
|
|
2738
|
+
async function countLiveSubscriptions(userId, nowIso) {
|
|
2739
|
+
const row = await getDbClient2().get("SELECT COUNT(*) AS n FROM mcp_event_subscriptions WHERE userId = ? AND expiresAt > ?", [userId, nowIso]);
|
|
2740
|
+
return row?.n ?? 0;
|
|
2741
|
+
}
|
|
2742
|
+
async function latestVerification(userId, url, sinceIso, nowIso) {
|
|
2743
|
+
const row = await getDbClient2().get(`SELECT MAX(verifiedAt) AS verifiedAt FROM mcp_event_subscriptions
|
|
2744
|
+
WHERE userId = ? AND url = ? AND verifiedAt > ? AND expiresAt > ?`, [userId, url, sinceIso, nowIso]);
|
|
2745
|
+
return row?.verifiedAt ?? null;
|
|
2746
|
+
}
|
|
2747
|
+
async function deleteExpiredSubscriptions(nowIso) {
|
|
2748
|
+
const result = await getDbClient2().run("DELETE FROM mcp_event_subscriptions WHERE expiresAt <= ?", [nowIso]);
|
|
2749
|
+
return result.changes;
|
|
2750
|
+
}
|
|
2751
|
+
async function upsertSubscription(input) {
|
|
2752
|
+
const sealed = sealSecret(input.secret);
|
|
2753
|
+
return getDbClient2().transaction(async (tx) => {
|
|
2754
|
+
const existing = await tx.get("SELECT * FROM mcp_event_subscriptions WHERE id = ?", [input.id]);
|
|
2755
|
+
if (!existing || existing.expiresAt <= input.nowIso) {
|
|
2756
|
+
const live = await tx.get(`SELECT COUNT(*) AS n FROM mcp_event_subscriptions
|
|
2757
|
+
WHERE userId = ? AND expiresAt > ? AND id != ?`, [input.userId, input.nowIso, input.id]);
|
|
2758
|
+
if ((live?.n ?? 0) >= input.maxActivePerUser)
|
|
2759
|
+
return "limit";
|
|
2760
|
+
}
|
|
2761
|
+
if (!existing) {
|
|
2762
|
+
await tx.run(`INSERT INTO mcp_event_subscriptions
|
|
2763
|
+
(id, userId, tokenId, eventName, argumentsJson, url, secretSealed, verifiedAt,
|
|
2764
|
+
expiresAt, createdAt, updatedAt, created_by, updated_by)
|
|
2765
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
|
|
2766
|
+
input.id,
|
|
2767
|
+
input.userId,
|
|
2768
|
+
input.tokenId,
|
|
2769
|
+
input.eventName,
|
|
2770
|
+
input.argumentsJson,
|
|
2771
|
+
input.url,
|
|
2772
|
+
sealed,
|
|
2773
|
+
input.verifiedAt,
|
|
2774
|
+
input.expiresAt,
|
|
2775
|
+
input.nowIso,
|
|
2776
|
+
input.nowIso,
|
|
2777
|
+
input.userId,
|
|
2778
|
+
input.userId
|
|
2779
|
+
]);
|
|
2780
|
+
} else {
|
|
2781
|
+
const rotated = unsealSecret(existing.secretSealed) !== input.secret;
|
|
2782
|
+
await tx.run(`UPDATE mcp_event_subscriptions
|
|
2783
|
+
SET tokenId = ?,
|
|
2784
|
+
secretSealed = ?,
|
|
2785
|
+
previousSecretSealed = ?,
|
|
2786
|
+
previousSecretUntil = ?,
|
|
2787
|
+
verifiedAt = ?,
|
|
2788
|
+
expiresAt = ?,
|
|
2789
|
+
updatedAt = ?,
|
|
2790
|
+
updated_by = ?
|
|
2791
|
+
WHERE id = ?`, [
|
|
2792
|
+
input.tokenId,
|
|
2793
|
+
sealed,
|
|
2794
|
+
rotated ? existing.secretSealed : existing.previousSecretSealed,
|
|
2795
|
+
rotated ? input.rotationGraceUntil : existing.previousSecretUntil,
|
|
2796
|
+
input.verifiedAt,
|
|
2797
|
+
input.expiresAt,
|
|
2798
|
+
input.nowIso,
|
|
2799
|
+
input.userId,
|
|
2800
|
+
input.id
|
|
2801
|
+
]);
|
|
2802
|
+
}
|
|
2803
|
+
const row = await tx.get("SELECT * FROM mcp_event_subscriptions WHERE id = ?", [input.id]);
|
|
2804
|
+
if (!row)
|
|
2805
|
+
throw new Error(`subscription ${input.id} vanished during upsert`);
|
|
2806
|
+
return row;
|
|
2807
|
+
});
|
|
2808
|
+
}
|
|
2809
|
+
async function deleteSubscription(id, userId) {
|
|
2810
|
+
const result = await getDbClient2().run("DELETE FROM mcp_event_subscriptions WHERE id = ? AND userId = ?", [id, userId]);
|
|
2811
|
+
return result.changes > 0;
|
|
2812
|
+
}
|
|
2813
|
+
async function listLiveSubscriptions(userId, eventName, nowIso) {
|
|
2814
|
+
return getDbClient2().query(`SELECT * FROM mcp_event_subscriptions
|
|
2815
|
+
WHERE userId = ? AND eventName = ? AND expiresAt > ?`, [userId, eventName, nowIso]);
|
|
2816
|
+
}
|
|
2817
|
+
async function recordDeliveryOutcome(id, outcome) {
|
|
2818
|
+
if (outcome.ok) {
|
|
2819
|
+
await getDbClient2().run(`UPDATE mcp_event_subscriptions
|
|
2820
|
+
SET lastDeliveryAt = ?, lastError = NULL, failedSince = NULL
|
|
2821
|
+
WHERE id = ?`, [outcome.atIso, id]);
|
|
2822
|
+
return;
|
|
2823
|
+
}
|
|
2824
|
+
await getDbClient2().run(`UPDATE mcp_event_subscriptions
|
|
2825
|
+
SET lastError = ?, failedSince = COALESCE(failedSince, ?)
|
|
2826
|
+
WHERE id = ?`, [outcome.category, outcome.atIso, id]);
|
|
2827
|
+
}
|
|
2828
|
+
|
|
2829
|
+
// src/be/mcp-events/webhook.ts
|
|
2830
|
+
init_egress_guard();
|
|
2831
|
+
init_env_flag();
|
|
2832
|
+
import { createHmac, randomBytes, timingSafeEqual } from "node:crypto";
|
|
2833
|
+
var SECRET_PREFIX = "whsec_";
|
|
2834
|
+
var MIN_SECRET_BYTES = 24;
|
|
2835
|
+
var MAX_SECRET_BYTES = 64;
|
|
2836
|
+
var BASE64 = /^[A-Za-z0-9+/]+={0,2}$/;
|
|
2837
|
+
var DELIVERY_TIMEOUT_MS = 1e4;
|
|
2838
|
+
var MAX_DELIVERY_BODY_BYTES = 256 * 1024;
|
|
2839
|
+
var MAX_CHALLENGE_RESPONSE_BYTES = 4096;
|
|
2840
|
+
var testOverrides = null;
|
|
2841
|
+
function allowPrivateCallbacks() {
|
|
2842
|
+
return parseEnvFlag(process.env.MCP_USER_EVENTS_ALLOW_PRIVATE_CALLBACKS, false);
|
|
2843
|
+
}
|
|
2844
|
+
function parseWebhookSecret(secret) {
|
|
2845
|
+
if (typeof secret !== "string" || !secret.startsWith(SECRET_PREFIX))
|
|
2846
|
+
return null;
|
|
2847
|
+
const encoded = secret.slice(SECRET_PREFIX.length);
|
|
2848
|
+
if (encoded.length === 0 || encoded.length % 4 !== 0 || !BASE64.test(encoded))
|
|
2849
|
+
return null;
|
|
2850
|
+
const bytes = Buffer.from(encoded, "base64");
|
|
2851
|
+
if (bytes.length < MIN_SECRET_BYTES || bytes.length > MAX_SECRET_BYTES)
|
|
2852
|
+
return null;
|
|
2853
|
+
return bytes;
|
|
2854
|
+
}
|
|
2855
|
+
function callbackUrlProblem(rawUrl) {
|
|
2856
|
+
if (typeof rawUrl !== "string" || rawUrl.length === 0)
|
|
2857
|
+
return "delivery.url is required";
|
|
2858
|
+
if (rawUrl.length > 2048)
|
|
2859
|
+
return "delivery.url is too long";
|
|
2860
|
+
let parsed;
|
|
2861
|
+
try {
|
|
2862
|
+
parsed = assertUrlSafe(rawUrl, {
|
|
2863
|
+
allowInsecure: allowPrivateCallbacks() || testOverrides?.allowInsecure === true,
|
|
2864
|
+
allowPrivateHosts: allowPrivateCallbacks() || testOverrides?.guard?.policy?.allowPrivate === true
|
|
2865
|
+
});
|
|
2866
|
+
} catch (error) {
|
|
2867
|
+
return error instanceof Error ? error.message : "delivery.url is not allowed";
|
|
2868
|
+
}
|
|
2869
|
+
if (parsed.username || parsed.password)
|
|
2870
|
+
return "delivery.url must not carry credentials";
|
|
2871
|
+
return null;
|
|
2872
|
+
}
|
|
2873
|
+
function signWebhook(secrets, webhookId, timestampSec, body) {
|
|
2874
|
+
const content = `${webhookId}.${timestampSec}.${body}`;
|
|
2875
|
+
return secrets.map((secret) => `v1,${createHmac("sha256", secret).update(content).digest("base64")}`).join(" ");
|
|
2876
|
+
}
|
|
2877
|
+
function guardedFetch() {
|
|
2878
|
+
return createGuardedFetch(testOverrides?.baseFetch ?? fetch, {
|
|
2879
|
+
policy: { allowPrivate: allowPrivateCallbacks(), allowlist: null },
|
|
2880
|
+
...testOverrides?.guard
|
|
2881
|
+
});
|
|
2882
|
+
}
|
|
2883
|
+
function categorize(error) {
|
|
2884
|
+
if (error instanceof EgressDeniedError)
|
|
2885
|
+
return "connection_refused";
|
|
2886
|
+
const name = error instanceof Error ? error.name : "";
|
|
2887
|
+
const message = error instanceof Error ? `${error.message} ${String(error.cause ?? "")}` : "";
|
|
2888
|
+
if (name === "TimeoutError" || name === "AbortError" || /timed? ?out/i.test(message)) {
|
|
2889
|
+
return "timeout";
|
|
2890
|
+
}
|
|
2891
|
+
if (/certificate|tls|ssl|self.signed|handshake/i.test(message))
|
|
2892
|
+
return "tls_error";
|
|
2893
|
+
return "connection_refused";
|
|
2894
|
+
}
|
|
2895
|
+
async function readCapped(response, maxBytes) {
|
|
2896
|
+
const reader = response.body?.getReader();
|
|
2897
|
+
if (!reader)
|
|
2898
|
+
return "";
|
|
2899
|
+
const chunks = [];
|
|
2900
|
+
let total = 0;
|
|
2901
|
+
while (total < maxBytes) {
|
|
2902
|
+
const { done, value } = await reader.read();
|
|
2903
|
+
if (done)
|
|
2904
|
+
break;
|
|
2905
|
+
chunks.push(value);
|
|
2906
|
+
total += value.byteLength;
|
|
2907
|
+
}
|
|
2908
|
+
await reader.cancel().catch(() => {});
|
|
2909
|
+
return new TextDecoder().decode(Buffer.concat(chunks).subarray(0, maxBytes));
|
|
2910
|
+
}
|
|
2911
|
+
async function postSignedWebhook(input) {
|
|
2912
|
+
const timestampSec = Math.floor(Date.now() / 1000);
|
|
2913
|
+
let response;
|
|
2914
|
+
try {
|
|
2915
|
+
response = await guardedFetch()(input.url, {
|
|
2916
|
+
method: "POST",
|
|
2917
|
+
redirect: "error",
|
|
2918
|
+
signal: AbortSignal.timeout(DELIVERY_TIMEOUT_MS),
|
|
2919
|
+
headers: {
|
|
2920
|
+
"Content-Type": "application/json",
|
|
2921
|
+
"webhook-id": input.webhookId,
|
|
2922
|
+
"webhook-timestamp": String(timestampSec),
|
|
2923
|
+
"webhook-signature": signWebhook(input.secrets, input.webhookId, timestampSec, input.body),
|
|
2924
|
+
"X-MCP-Subscription-Id": input.subscriptionId
|
|
2925
|
+
},
|
|
2926
|
+
body: input.body
|
|
2927
|
+
});
|
|
2928
|
+
} catch (error) {
|
|
2929
|
+
return { ok: false, category: categorize(error) };
|
|
2930
|
+
}
|
|
2931
|
+
if (response.status >= 200 && response.status < 300) {
|
|
2932
|
+
const text = input.readBody ? await readCapped(response, MAX_CHALLENGE_RESPONSE_BYTES).catch(() => "") : "";
|
|
2933
|
+
if (!input.readBody)
|
|
2934
|
+
await response.body?.cancel().catch(() => {});
|
|
2935
|
+
return { ok: true, status: response.status, text };
|
|
2936
|
+
}
|
|
2937
|
+
await response.body?.cancel().catch(() => {});
|
|
2938
|
+
return {
|
|
2939
|
+
ok: false,
|
|
2940
|
+
status: response.status,
|
|
2941
|
+
category: response.status >= 500 ? "http_5xx" : "http_4xx"
|
|
2942
|
+
};
|
|
2943
|
+
}
|
|
2944
|
+
async function verifyCallbackEndpoint(input) {
|
|
2945
|
+
const challenge = randomBytes(24).toString("base64url");
|
|
2946
|
+
const result = await postSignedWebhook({
|
|
2947
|
+
url: input.url,
|
|
2948
|
+
subscriptionId: input.subscriptionId,
|
|
2949
|
+
webhookId: `msg_verification_${randomBytes(12).toString("hex")}`,
|
|
2950
|
+
secrets: [input.secret],
|
|
2951
|
+
body: JSON.stringify({ type: "verification", challenge }),
|
|
2952
|
+
readBody: true
|
|
2953
|
+
});
|
|
2954
|
+
if (!result.ok)
|
|
2955
|
+
return result.category;
|
|
2956
|
+
let echoed;
|
|
2957
|
+
try {
|
|
2958
|
+
echoed = JSON.parse(result.text).challenge;
|
|
2959
|
+
} catch {
|
|
2960
|
+
return "challenge_failed";
|
|
2961
|
+
}
|
|
2962
|
+
if (typeof echoed !== "string")
|
|
2963
|
+
return "challenge_failed";
|
|
2964
|
+
const expected = Buffer.from(challenge);
|
|
2965
|
+
const actual = Buffer.from(echoed);
|
|
2966
|
+
if (expected.length !== actual.length || !timingSafeEqual(expected, actual)) {
|
|
2967
|
+
return "challenge_failed";
|
|
2968
|
+
}
|
|
2969
|
+
return null;
|
|
2970
|
+
}
|
|
2971
|
+
|
|
2972
|
+
// src/be/mcp-events/dispatcher.ts
|
|
2973
|
+
var DEFAULT_RETRY_DELAYS_MS = [1e4, 60000, 240000, 540000];
|
|
2974
|
+
var MAX_OUTPUT_CHARS = 16000;
|
|
2975
|
+
var MAX_TASK_CHARS = 2000;
|
|
2976
|
+
var MAX_ANCESTOR_HOPS = 32;
|
|
2977
|
+
var retryDelaysMs = DEFAULT_RETRY_DELAYS_MS;
|
|
2978
|
+
var pendingTimers = new Set;
|
|
2979
|
+
var listening = false;
|
|
2980
|
+
function truncate(text, max) {
|
|
2981
|
+
return text.length > max ? { text: text.slice(0, max), truncated: true } : { text, truncated: false };
|
|
2982
|
+
}
|
|
2983
|
+
async function isUnderTask(taskId, filterTaskId) {
|
|
2984
|
+
let current = taskId;
|
|
2985
|
+
for (let hop = 0;current && hop <= MAX_ANCESTOR_HOPS; hop++) {
|
|
2986
|
+
if (current === filterTaskId)
|
|
2987
|
+
return true;
|
|
2988
|
+
const row = await getDbClient2().get("SELECT parentTaskId FROM agent_tasks WHERE id = ?", [current]);
|
|
2989
|
+
current = row?.parentTaskId ?? null;
|
|
2990
|
+
}
|
|
2991
|
+
return false;
|
|
2992
|
+
}
|
|
2993
|
+
function signingSecrets(row, nowIso) {
|
|
2994
|
+
const secrets = [unsealSecret(row.secretSealed)];
|
|
2995
|
+
if (row.previousSecretSealed && row.previousSecretUntil && row.previousSecretUntil > nowIso) {
|
|
2996
|
+
secrets.push(unsealSecret(row.previousSecretSealed));
|
|
2997
|
+
}
|
|
2998
|
+
return secrets.map(parseWebhookSecret).filter((s) => s !== null);
|
|
2999
|
+
}
|
|
3000
|
+
async function attemptDelivery(subscriptionId, eventId, body, attempt) {
|
|
3001
|
+
const nowIso = new Date().toISOString();
|
|
3002
|
+
const row = await getSubscription(subscriptionId);
|
|
3003
|
+
if (!row || row.expiresAt <= nowIso)
|
|
3004
|
+
return;
|
|
3005
|
+
if (!await isLiveUserToken(row.tokenId, row.userId))
|
|
3006
|
+
return;
|
|
3007
|
+
const result = await postSignedWebhook({
|
|
3008
|
+
url: row.url,
|
|
3009
|
+
subscriptionId: row.id,
|
|
3010
|
+
webhookId: eventId,
|
|
3011
|
+
secrets: signingSecrets(row, nowIso),
|
|
3012
|
+
body
|
|
3013
|
+
});
|
|
3014
|
+
const atIso = new Date().toISOString();
|
|
3015
|
+
if (result.ok) {
|
|
3016
|
+
await recordDeliveryOutcome(row.id, { ok: true, atIso });
|
|
3017
|
+
return;
|
|
3018
|
+
}
|
|
3019
|
+
if (result.status === 410 || result.status === 413)
|
|
3020
|
+
return;
|
|
3021
|
+
await recordDeliveryOutcome(row.id, { ok: false, category: result.category, atIso });
|
|
3022
|
+
const delay = retryDelaysMs[attempt];
|
|
3023
|
+
if (delay === undefined)
|
|
3024
|
+
return;
|
|
3025
|
+
const timer = setTimeout(() => {
|
|
3026
|
+
pendingTimers.delete(timer);
|
|
3027
|
+
attemptDelivery(subscriptionId, eventId, body, attempt + 1).catch(logError);
|
|
3028
|
+
}, delay);
|
|
3029
|
+
timer.unref?.();
|
|
3030
|
+
pendingTimers.add(timer);
|
|
3031
|
+
}
|
|
3032
|
+
function logError(err) {
|
|
3033
|
+
console.error("[mcp-events] delivery failed:", scrubSecrets(err instanceof Error ? err.message : String(err)));
|
|
3034
|
+
}
|
|
3035
|
+
async function dispatchTaskEvent(name, payload) {
|
|
3036
|
+
if (!isMcpUserEventsEnabled())
|
|
3037
|
+
return;
|
|
3038
|
+
const { taskId, output, failureReason } = payload ?? {};
|
|
3039
|
+
if (typeof taskId !== "string")
|
|
3040
|
+
return;
|
|
3041
|
+
const task = await getTaskById2(taskId);
|
|
3042
|
+
if (!task?.requestedByUserId)
|
|
3043
|
+
return;
|
|
3044
|
+
const user = await getUserById2(task.requestedByUserId);
|
|
3045
|
+
if (!user || user.status !== "active")
|
|
3046
|
+
return;
|
|
3047
|
+
const now = new Date;
|
|
3048
|
+
const subscriptions = await listLiveSubscriptions(user.id, name, now.toISOString());
|
|
3049
|
+
if (subscriptions.length === 0)
|
|
3050
|
+
return;
|
|
3051
|
+
const rawDetail = name === "task.completed" ? output : failureReason;
|
|
3052
|
+
const detailText = scrubSecrets(typeof rawDetail === "string" ? rawDetail : "");
|
|
3053
|
+
const detail = truncate(detailText, MAX_OUTPUT_CHARS);
|
|
3054
|
+
const description = truncate(scrubSecrets(task.task ?? ""), MAX_TASK_CHARS);
|
|
3055
|
+
const data = {
|
|
3056
|
+
taskId: task.id,
|
|
3057
|
+
parentTaskId: task.parentTaskId ?? null,
|
|
3058
|
+
status: name === "task.completed" ? "completed" : "failed",
|
|
3059
|
+
task: description.text,
|
|
3060
|
+
url: `${getAppUrl()}/tasks/${encodeURIComponent(task.id)}`,
|
|
3061
|
+
[name === "task.completed" ? "output" : "failureReason"]: detail.text,
|
|
3062
|
+
truncated: detail.truncated || description.truncated
|
|
3063
|
+
};
|
|
3064
|
+
const timestamp = task.finishedAt ?? now.toISOString();
|
|
3065
|
+
const attempts = [];
|
|
3066
|
+
for (const subscription of subscriptions) {
|
|
3067
|
+
const args = parseTaskEventArguments(JSON.parse(subscription.argumentsJson));
|
|
3068
|
+
if (!args)
|
|
3069
|
+
continue;
|
|
3070
|
+
if (args.taskId && !await isUnderTask(task.id, args.taskId))
|
|
3071
|
+
continue;
|
|
3072
|
+
const eventId = `evt_${createHash2("sha256").update(`${subscription.id}
|
|
3073
|
+
${name}
|
|
3074
|
+
${task.id}`).digest("hex").slice(0, 32)}`;
|
|
3075
|
+
let body = JSON.stringify({ eventId, name, timestamp, data, cursor: null });
|
|
3076
|
+
if (Buffer.byteLength(body, "utf8") > MAX_DELIVERY_BODY_BYTES) {
|
|
3077
|
+
body = JSON.stringify({
|
|
3078
|
+
eventId,
|
|
3079
|
+
name,
|
|
3080
|
+
timestamp,
|
|
3081
|
+
data: { ...data, output: undefined, failureReason: undefined, truncated: true },
|
|
3082
|
+
cursor: null
|
|
3083
|
+
});
|
|
3084
|
+
}
|
|
3085
|
+
attempts.push(attemptDelivery(subscription.id, eventId, body, 0).catch(logError));
|
|
3086
|
+
}
|
|
3087
|
+
await Promise.all(attempts);
|
|
3088
|
+
}
|
|
3089
|
+
var onCompleted = (payload) => {
|
|
3090
|
+
dispatchTaskEvent("task.completed", payload).catch(logError);
|
|
3091
|
+
};
|
|
3092
|
+
var onFailed = (payload) => {
|
|
3093
|
+
dispatchTaskEvent("task.failed", payload).catch(logError);
|
|
3094
|
+
};
|
|
3095
|
+
function initMcpEventsDispatcher() {
|
|
3096
|
+
if (listening)
|
|
3097
|
+
return;
|
|
3098
|
+
listening = true;
|
|
3099
|
+
workflowEventBus2.on("task.completed", onCompleted);
|
|
3100
|
+
workflowEventBus2.on("task.failed", onFailed);
|
|
3101
|
+
}
|
|
3102
|
+
|
|
2425
3103
|
// src/be/mcp-overflow-sweep.ts
|
|
2426
3104
|
init_kv_overflow();
|
|
2427
3105
|
init_db4();
|
|
@@ -4352,7 +5030,7 @@ init_otel();
|
|
|
4352
5030
|
|
|
4353
5031
|
// src/queue-stall-alarm.ts
|
|
4354
5032
|
init_db4();
|
|
4355
|
-
|
|
5033
|
+
init_app4();
|
|
4356
5034
|
init_secret_scrubber();
|
|
4357
5035
|
var QUEUE_STALL_THRESHOLD_MS = 30 * 60 * 1000;
|
|
4358
5036
|
var QUEUE_STALL_CHECK_INTERVAL_MS = 5 * 60 * 1000;
|
|
@@ -6433,6 +7111,319 @@ async function handleActiveSessions(req, res, pathSegments, queryParams, myAgent
|
|
|
6433
7111
|
return false;
|
|
6434
7112
|
}
|
|
6435
7113
|
|
|
7114
|
+
// src/http/agent-lifecycle.ts
|
|
7115
|
+
init_zod();
|
|
7116
|
+
|
|
7117
|
+
// src/be/agent-history.ts
|
|
7118
|
+
init_types5();
|
|
7119
|
+
init_secret_scrubber();
|
|
7120
|
+
init_db4();
|
|
7121
|
+
init_users();
|
|
7122
|
+
|
|
7123
|
+
class AgentHistoryError extends Error {
|
|
7124
|
+
status;
|
|
7125
|
+
code;
|
|
7126
|
+
blockers;
|
|
7127
|
+
constructor(message, status, code, blockers = []) {
|
|
7128
|
+
super(message);
|
|
7129
|
+
this.status = status;
|
|
7130
|
+
this.code = code;
|
|
7131
|
+
this.blockers = blockers;
|
|
7132
|
+
this.name = "AgentHistoryError";
|
|
7133
|
+
}
|
|
7134
|
+
}
|
|
7135
|
+
var NON_TERMINAL_SQL = `status NOT IN (${TERMINAL_TASK_STATUSES.map((s) => `'${s}'`).join(", ")})`;
|
|
7136
|
+
var COUNT_BLOCKERS = [
|
|
7137
|
+
[
|
|
7138
|
+
"open_tasks",
|
|
7139
|
+
`SELECT COUNT(*) AS n FROM agent_tasks WHERE (agentId = ?1 OR offeredTo = ?1) AND ${NON_TERMINAL_SQL}`,
|
|
7140
|
+
"non-terminal task(s) are assigned or offered to it; finish, cancel or reassign them"
|
|
7141
|
+
],
|
|
7142
|
+
[
|
|
7143
|
+
"schedules",
|
|
7144
|
+
"SELECT COUNT(*) AS n FROM scheduled_tasks WHERE targetAgentId = ?1 AND enabled = 1",
|
|
7145
|
+
"enabled schedule(s) target it; disable or retarget them"
|
|
7146
|
+
],
|
|
7147
|
+
[
|
|
7148
|
+
"owned_skills",
|
|
7149
|
+
"SELECT COUNT(*) AS n FROM skills WHERE ownerAgentId = ?1",
|
|
7150
|
+
"skill(s) are owned by it"
|
|
7151
|
+
],
|
|
7152
|
+
[
|
|
7153
|
+
"owned_mcp_servers",
|
|
7154
|
+
"SELECT COUNT(*) AS n FROM mcp_servers WHERE ownerAgentId = ?1",
|
|
7155
|
+
"MCP server(s) are owned by it"
|
|
7156
|
+
],
|
|
7157
|
+
[
|
|
7158
|
+
"inboxes",
|
|
7159
|
+
"SELECT COUNT(*) AS n FROM agentmail_inbox_mappings WHERE agentId = ?1",
|
|
7160
|
+
"AgentMail inbox(es) map to it"
|
|
7161
|
+
]
|
|
7162
|
+
];
|
|
7163
|
+
async function deleteBlockers(agent) {
|
|
7164
|
+
const blockers = [];
|
|
7165
|
+
if (agent.isLead)
|
|
7166
|
+
blockers.push({ code: "lead", message: "The lead agent cannot be deleted." });
|
|
7167
|
+
if (isExtensionAgent2(agent)) {
|
|
7168
|
+
blockers.push({ code: "extension", message: "Uninstall the extension instead." });
|
|
7169
|
+
}
|
|
7170
|
+
if (agent.status !== "offline") {
|
|
7171
|
+
blockers.push({ code: "not_offline", message: `Agent is ${agent.status}. Stop its worker.` });
|
|
7172
|
+
}
|
|
7173
|
+
if (agent.runtimePoolId) {
|
|
7174
|
+
blockers.push({ code: "pool_bound", message: `Unbind it from pool ${agent.runtimePoolId}.` });
|
|
7175
|
+
}
|
|
7176
|
+
for (const [code, sql, what] of COUNT_BLOCKERS) {
|
|
7177
|
+
const n = (await getDbClient2().get(sql, [agent.id]))?.n ?? 0;
|
|
7178
|
+
if (n > 0)
|
|
7179
|
+
blockers.push({ code, message: `${n} ${what}.` });
|
|
7180
|
+
}
|
|
7181
|
+
return blockers;
|
|
7182
|
+
}
|
|
7183
|
+
function rowToEvent(row) {
|
|
7184
|
+
return {
|
|
7185
|
+
id: row.id,
|
|
7186
|
+
agentId: row.agent_id,
|
|
7187
|
+
event: row.event,
|
|
7188
|
+
actorRef: row.actor_ref,
|
|
7189
|
+
reason: row.reason,
|
|
7190
|
+
snapshot: JSON.parse(row.snapshot_json),
|
|
7191
|
+
createdAt: row.created_at
|
|
7192
|
+
};
|
|
7193
|
+
}
|
|
7194
|
+
async function appendEvent(agentId, event, actorRef, reason) {
|
|
7195
|
+
const snapshot = await getDbClient2().get("SELECT * FROM agents WHERE id = ?", [agentId]);
|
|
7196
|
+
const row = await getDbClient2().get(`INSERT INTO agent_history (id, agent_id, event, actor_ref, reason, snapshot_json, created_at)
|
|
7197
|
+
VALUES (?, ?, ?, ?, ?, ?, ?) RETURNING *`, [
|
|
7198
|
+
crypto.randomUUID(),
|
|
7199
|
+
agentId,
|
|
7200
|
+
event,
|
|
7201
|
+
actorRef,
|
|
7202
|
+
scrubSecrets(reason.trim()),
|
|
7203
|
+
JSON.stringify(snapshot),
|
|
7204
|
+
new Date().toISOString()
|
|
7205
|
+
]);
|
|
7206
|
+
if (!row)
|
|
7207
|
+
throw new Error("Failed to append agent history");
|
|
7208
|
+
return rowToEvent(row);
|
|
7209
|
+
}
|
|
7210
|
+
async function latestEvent(agentId) {
|
|
7211
|
+
return await getDbClient2().get("SELECT * FROM agent_history WHERE agent_id = ? ORDER BY created_at DESC, rowid DESC LIMIT 1", [agentId]);
|
|
7212
|
+
}
|
|
7213
|
+
async function deleteAgentToHistory(agentId, reason, actorRef) {
|
|
7214
|
+
return await getDbClient2().transaction(async () => {
|
|
7215
|
+
const agent = await getAgentById2(agentId);
|
|
7216
|
+
if (!agent)
|
|
7217
|
+
throw new AgentHistoryError("Agent not found", 404, "not_found");
|
|
7218
|
+
const blockers = await deleteBlockers(agent);
|
|
7219
|
+
if (blockers.length > 0) {
|
|
7220
|
+
throw new AgentHistoryError(blockers[0].message, 409, blockers[0].code, blockers);
|
|
7221
|
+
}
|
|
7222
|
+
const event = await appendEvent(agentId, "deleted", actorRef, reason);
|
|
7223
|
+
await revokeAllAgentSessionTokens(agentId);
|
|
7224
|
+
await getDbClient2().run("DELETE FROM agent_skills WHERE agentId = ?", [agentId]);
|
|
7225
|
+
await getDbClient2().run("DELETE FROM agent_mcp_servers WHERE agentId = ?", [agentId]);
|
|
7226
|
+
await deleteAgent2(agentId);
|
|
7227
|
+
return event;
|
|
7228
|
+
});
|
|
7229
|
+
}
|
|
7230
|
+
async function restoreAgentFromHistory(agentId, input, actorRef) {
|
|
7231
|
+
return await getDbClient2().transaction(async () => {
|
|
7232
|
+
if (await getAgentById2(agentId)) {
|
|
7233
|
+
throw new AgentHistoryError("Agent exists; nothing to restore", 409, "not_deleted");
|
|
7234
|
+
}
|
|
7235
|
+
const last = await latestEvent(agentId);
|
|
7236
|
+
if (last?.event !== "deleted") {
|
|
7237
|
+
throw new AgentHistoryError("No deleted agent with this id", 404, "not_found");
|
|
7238
|
+
}
|
|
7239
|
+
const row = JSON.parse(last.snapshot_json);
|
|
7240
|
+
const name = input.newName?.trim() || String(row.name);
|
|
7241
|
+
row.name = name;
|
|
7242
|
+
row.lastUpdatedAt = new Date().toISOString();
|
|
7243
|
+
const taken = await getDbClient2().get("SELECT id FROM agents WHERE name = ?", [name]);
|
|
7244
|
+
if (taken) {
|
|
7245
|
+
throw new AgentHistoryError(`Another agent is named "${name}". Pass newName.`, 409, "name_taken");
|
|
7246
|
+
}
|
|
7247
|
+
const columns = (await getDbClient2().query("SELECT name FROM pragma_table_info('agents')")).map((c) => c.name).filter((c) => (c in row));
|
|
7248
|
+
await getDbClient2().run(`INSERT INTO agents (${columns.map((c) => `"${c}"`).join(", ")}) VALUES (${columns.map(() => "?").join(", ")})`, columns.map((c) => row[c] ?? null));
|
|
7249
|
+
await installSystemDefaultSkillsForAgent2(agentId);
|
|
7250
|
+
const event = await appendEvent(agentId, "restored", actorRef, input.reason);
|
|
7251
|
+
return { agent: await getAgentById2(agentId), event };
|
|
7252
|
+
});
|
|
7253
|
+
}
|
|
7254
|
+
async function listAgentHistory(agentId) {
|
|
7255
|
+
const rows = await getDbClient2().query(`SELECT * FROM agent_history ${agentId ? "WHERE agent_id = ?" : ""}
|
|
7256
|
+
ORDER BY created_at DESC, rowid DESC LIMIT 500`, agentId ? [agentId] : []);
|
|
7257
|
+
return rows.map(rowToEvent);
|
|
7258
|
+
}
|
|
7259
|
+
|
|
7260
|
+
// src/http/agent-lifecycle.ts
|
|
7261
|
+
init_rbac();
|
|
7262
|
+
init_types5();
|
|
7263
|
+
init_secret_scrubber();
|
|
7264
|
+
|
|
7265
|
+
// src/http/operator-actor.ts
|
|
7266
|
+
init_users();
|
|
7267
|
+
init_api_key();
|
|
7268
|
+
init_request_auth_context();
|
|
7269
|
+
init_triggers();
|
|
7270
|
+
init_request_principal();
|
|
7271
|
+
init_utils2();
|
|
7272
|
+
function extractBearer(req) {
|
|
7273
|
+
const raw = req.headers.authorization;
|
|
7274
|
+
const header = Array.isArray(raw) ? raw[0] : raw;
|
|
7275
|
+
if (!header || !header.startsWith("Bearer "))
|
|
7276
|
+
return null;
|
|
7277
|
+
return header.slice(7);
|
|
7278
|
+
}
|
|
7279
|
+
function getOperatorActor(req, res) {
|
|
7280
|
+
if (rejectGuest(req, res))
|
|
7281
|
+
return null;
|
|
7282
|
+
const auth = getRequestAuth(req);
|
|
7283
|
+
const userId = authUserId(auth);
|
|
7284
|
+
if (userId) {
|
|
7285
|
+
const tokenId = auth?.kind === "user" ? auth.tokenId : undefined;
|
|
7286
|
+
return tokenId ? { kind: "user", id: userId, tokenId } : { kind: "user", id: userId };
|
|
7287
|
+
}
|
|
7288
|
+
if (isOperatorAuth(auth)) {
|
|
7289
|
+
return { kind: "operator", id: auth.fingerprint };
|
|
7290
|
+
}
|
|
7291
|
+
const rawKey = extractBearer(req);
|
|
7292
|
+
const swarmKey = getApiKey();
|
|
7293
|
+
if (!swarmKey) {
|
|
7294
|
+
return { kind: "operator", id: fingerprintApiKey("") };
|
|
7295
|
+
}
|
|
7296
|
+
if (!rawKey || !verifyTokenEquality(swarmKey, rawKey)) {
|
|
7297
|
+
jsonError(res, "Unauthorized", 401);
|
|
7298
|
+
return null;
|
|
7299
|
+
}
|
|
7300
|
+
return { kind: "operator", id: fingerprintApiKey(rawKey) };
|
|
7301
|
+
}
|
|
7302
|
+
|
|
7303
|
+
// src/http/agent-lifecycle.ts
|
|
7304
|
+
init_request_principal();
|
|
7305
|
+
init_route_def();
|
|
7306
|
+
init_utils2();
|
|
7307
|
+
var params = object2({ id: string2().min(1) });
|
|
7308
|
+
var reason = string2().trim().min(3).max(2000);
|
|
7309
|
+
var RefusalSchema = object2({
|
|
7310
|
+
error: string2(),
|
|
7311
|
+
code: string2(),
|
|
7312
|
+
blockers: array2(object2({ code: string2(), message: string2() }))
|
|
7313
|
+
});
|
|
7314
|
+
var RBAC = { permission: "agent.lifecycle.manage" };
|
|
7315
|
+
var DENIED = { description: "Operator or user credentials required" };
|
|
7316
|
+
var deleteRoute = route({
|
|
7317
|
+
method: "post",
|
|
7318
|
+
path: "/api/agents/{id}/delete",
|
|
7319
|
+
pattern: ["api", "agents", null, "delete"],
|
|
7320
|
+
summary: "Delete an agent into agent_history",
|
|
7321
|
+
description: "Appends the agent row to `agent_history`, revokes its session tokens, and deletes the row. Refused with 409 while the agent is the lead, an extension identity, not offline, pool-bound, holds open tasks or enabled schedules, or owns skills, MCP servers or inboxes.",
|
|
7322
|
+
tags: ["Agents"],
|
|
7323
|
+
params,
|
|
7324
|
+
body: object2({ reason }),
|
|
7325
|
+
responses: {
|
|
7326
|
+
200: { description: "Agent deleted", schema: object2({ event: AgentHistoryEventSchema }) },
|
|
7327
|
+
400: { description: "Validation error" },
|
|
7328
|
+
403: DENIED,
|
|
7329
|
+
404: { description: "Agent not found" },
|
|
7330
|
+
409: { description: "A blocker refuses the delete", schema: RefusalSchema }
|
|
7331
|
+
},
|
|
7332
|
+
rbac: RBAC
|
|
7333
|
+
});
|
|
7334
|
+
var restoreRoute = route({
|
|
7335
|
+
method: "post",
|
|
7336
|
+
path: "/api/agents/{id}/restore",
|
|
7337
|
+
pattern: ["api", "agents", null, "restore"],
|
|
7338
|
+
summary: "Restore a deleted agent from agent_history",
|
|
7339
|
+
description: "Reinserts the latest deleted snapshot under the same id. Rows a cascading foreign key removed on delete do not come back.",
|
|
7340
|
+
tags: ["Agents"],
|
|
7341
|
+
params,
|
|
7342
|
+
body: object2({ reason, newName: string2().trim().min(1).optional() }),
|
|
7343
|
+
responses: {
|
|
7344
|
+
200: {
|
|
7345
|
+
description: "Agent restored",
|
|
7346
|
+
schema: object2({ agent: AgentSchema, event: AgentHistoryEventSchema })
|
|
7347
|
+
},
|
|
7348
|
+
400: { description: "Validation error" },
|
|
7349
|
+
403: DENIED,
|
|
7350
|
+
404: { description: "No deleted agent with this id" },
|
|
7351
|
+
409: { description: "The agent exists, or its name is taken", schema: RefusalSchema }
|
|
7352
|
+
},
|
|
7353
|
+
rbac: RBAC
|
|
7354
|
+
});
|
|
7355
|
+
var historyRoute = route({
|
|
7356
|
+
method: "get",
|
|
7357
|
+
path: "/api/agent-history",
|
|
7358
|
+
pattern: ["api", "agent-history"],
|
|
7359
|
+
summary: "List agent delete and restore events",
|
|
7360
|
+
description: "Newest first, at most 500. Filter by `agentId`.",
|
|
7361
|
+
tags: ["Agents"],
|
|
7362
|
+
query: object2({ agentId: string2().min(1).optional() }),
|
|
7363
|
+
responses: {
|
|
7364
|
+
200: {
|
|
7365
|
+
description: "Events",
|
|
7366
|
+
schema: object2({ events: array2(AgentHistoryEventSchema) })
|
|
7367
|
+
},
|
|
7368
|
+
403: DENIED
|
|
7369
|
+
},
|
|
7370
|
+
rbac: RBAC
|
|
7371
|
+
});
|
|
7372
|
+
async function handleAgentLifecycle(req, res, pathSegments, queryParams, myAgentId) {
|
|
7373
|
+
const matched = [deleteRoute, restoreRoute, historyRoute].find((r) => r.match(req.method, pathSegments));
|
|
7374
|
+
if (!matched)
|
|
7375
|
+
return false;
|
|
7376
|
+
const decision = can({
|
|
7377
|
+
principal: await agentFirstPrincipal(req, myAgentId),
|
|
7378
|
+
verb: "agent.lifecycle.manage",
|
|
7379
|
+
resource: matched === historyRoute ? { kind: "none" } : { kind: "agent", agentId: pathSegments[2] },
|
|
7380
|
+
source: "http"
|
|
7381
|
+
});
|
|
7382
|
+
if (!decision.allow) {
|
|
7383
|
+
jsonError(res, scrubSecrets(decision.reason), 403);
|
|
7384
|
+
return true;
|
|
7385
|
+
}
|
|
7386
|
+
if (matched === historyRoute) {
|
|
7387
|
+
const parsed = await historyRoute.parse(req, res, pathSegments, queryParams);
|
|
7388
|
+
if (!parsed)
|
|
7389
|
+
return true;
|
|
7390
|
+
historyRoute.respond(res, 200, { events: await listAgentHistory(parsed.query.agentId) });
|
|
7391
|
+
return true;
|
|
7392
|
+
}
|
|
7393
|
+
const operator = getOperatorActor(req, res);
|
|
7394
|
+
if (!operator)
|
|
7395
|
+
return true;
|
|
7396
|
+
const actorRef = operator.kind === "user" ? `user:${operator.id}` : operator.id;
|
|
7397
|
+
try {
|
|
7398
|
+
if (matched === deleteRoute) {
|
|
7399
|
+
const parsed = await deleteRoute.parse(req, res, pathSegments, queryParams);
|
|
7400
|
+
if (!parsed)
|
|
7401
|
+
return true;
|
|
7402
|
+
const event = await deleteAgentToHistory(parsed.params.id, parsed.body.reason, actorRef);
|
|
7403
|
+
deleteRoute.respond(res, 200, { event });
|
|
7404
|
+
return true;
|
|
7405
|
+
}
|
|
7406
|
+
const parsed = await restoreRoute.parse(req, res, pathSegments, queryParams);
|
|
7407
|
+
if (!parsed)
|
|
7408
|
+
return true;
|
|
7409
|
+
restoreRoute.respond(res, 200, await restoreAgentFromHistory(parsed.params.id, parsed.body, actorRef));
|
|
7410
|
+
return true;
|
|
7411
|
+
} catch (error) {
|
|
7412
|
+
if (!(error instanceof AgentHistoryError))
|
|
7413
|
+
throw error;
|
|
7414
|
+
if (error.status === 404) {
|
|
7415
|
+
jsonError(res, error.message, 404);
|
|
7416
|
+
return true;
|
|
7417
|
+
}
|
|
7418
|
+
const body = { error: error.message, code: error.code, blockers: error.blockers };
|
|
7419
|
+
if (matched === restoreRoute)
|
|
7420
|
+
restoreRoute.respond(res, 409, body);
|
|
7421
|
+
else
|
|
7422
|
+
deleteRoute.respond(res, 409, body);
|
|
7423
|
+
return true;
|
|
7424
|
+
}
|
|
7425
|
+
}
|
|
7426
|
+
|
|
6436
7427
|
// src/http/agentfs-proxy.ts
|
|
6437
7428
|
init_api_key();
|
|
6438
7429
|
init_constants3();
|
|
@@ -6869,7 +7860,10 @@ var registerAgent = route({
|
|
|
6869
7860
|
description: "Agent created. Response includes `enabledCapabilities` (see 200).",
|
|
6870
7861
|
schema: RegisterAgentResponseSchema
|
|
6871
7862
|
},
|
|
6872
|
-
400: { description: "Validation error" }
|
|
7863
|
+
400: { description: "Validation error" },
|
|
7864
|
+
410: {
|
|
7865
|
+
description: "An operator deleted this agent id (`agent_deleted`); the worker must stop"
|
|
7866
|
+
}
|
|
6873
7867
|
}
|
|
6874
7868
|
});
|
|
6875
7869
|
var setAgentHarnessProviderRoute = route({
|
|
@@ -7323,6 +8317,8 @@ async function handleAgentRegister(req, res, pathSegments, myAgentId) {
|
|
|
7323
8317
|
}
|
|
7324
8318
|
return { agent: await getAgentById2(agentId), created: false };
|
|
7325
8319
|
}
|
|
8320
|
+
if (await isAgentDeleted2(agentId))
|
|
8321
|
+
return null;
|
|
7326
8322
|
const agent = await createAgent2({
|
|
7327
8323
|
id: agentId,
|
|
7328
8324
|
name: parsed.body.name,
|
|
@@ -7349,6 +8345,10 @@ async function handleAgentRegister(req, res, pathSegments, myAgentId) {
|
|
|
7349
8345
|
}
|
|
7350
8346
|
return { agent, created: true };
|
|
7351
8347
|
});
|
|
8348
|
+
if (!result) {
|
|
8349
|
+
jsonError(res, "agent_deleted", 410);
|
|
8350
|
+
return true;
|
|
8351
|
+
}
|
|
7352
8352
|
if (parsed.body.harnessCliVersion !== undefined) {
|
|
7353
8353
|
await setAgentHarnessCliVersion(agentId, parsed.body.harnessCliVersion.trim() || null);
|
|
7354
8354
|
}
|
|
@@ -9173,6 +10173,7 @@ init_rbac_roles();
|
|
|
9173
10173
|
init_swarm_config_guard();
|
|
9174
10174
|
init_users();
|
|
9175
10175
|
init_rbac();
|
|
10176
|
+
init_reaction_shortcode();
|
|
9176
10177
|
init_types5();
|
|
9177
10178
|
init_request_auth_context();
|
|
9178
10179
|
init_secret_scrubber();
|
|
@@ -9903,7 +10904,7 @@ async function handleConfig(req, res, pathSegments, queryParams) {
|
|
|
9903
10904
|
const presence = {};
|
|
9904
10905
|
for (const key of keys) {
|
|
9905
10906
|
const value = key === "SWARM_ORG_NAME" ? process.env[key]?.trim() : process.env[key];
|
|
9906
|
-
presence[key] = value !== undefined && value !== "";
|
|
10907
|
+
presence[key] = value !== undefined && (isSlackIconConfigKey(key) || value !== "");
|
|
9907
10908
|
}
|
|
9908
10909
|
envPresence.respond(res, 200, { presence });
|
|
9909
10910
|
return true;
|
|
@@ -11087,13 +12088,13 @@ init_types5();
|
|
|
11087
12088
|
init_secret_scrubber();
|
|
11088
12089
|
init_route_def();
|
|
11089
12090
|
init_utils2();
|
|
11090
|
-
import { createHash } from "node:crypto";
|
|
12091
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
11091
12092
|
function apiKeyFingerprint(req) {
|
|
11092
12093
|
const authHeader = req.headers.authorization;
|
|
11093
12094
|
const providedKey = authHeader?.startsWith("Bearer ") ? authHeader.slice(7) : "";
|
|
11094
12095
|
if (!providedKey)
|
|
11095
12096
|
return "";
|
|
11096
|
-
const digest =
|
|
12097
|
+
const digest = createHash3("sha256").update(providedKey).digest("hex").slice(0, 8);
|
|
11097
12098
|
return scrubSecrets(digest);
|
|
11098
12099
|
}
|
|
11099
12100
|
var ScopeIdSchema = string2().max(255).describe("Scope identifier — empty string for global, agent UUID otherwise");
|
|
@@ -16508,7 +17509,13 @@ const shortcode = (raw: string): string | null => {
|
|
|
16508
17509
|
|
|
16509
17510
|
/** The acceptance reactions the engine may have put on the message, deduplicated. */
|
|
16510
17511
|
export const acceptanceReactions = (): string[] => [
|
|
16511
|
-
...new Set(
|
|
17512
|
+
...new Set(
|
|
17513
|
+
ACCEPTANCE_REACTIONS.flatMap(([key, fallback]) => {
|
|
17514
|
+
const raw = process.env[key];
|
|
17515
|
+
if (raw !== undefined && raw.trim() === "") return [];
|
|
17516
|
+
return [shortcode(raw ?? "") ?? fallback];
|
|
17517
|
+
}),
|
|
17518
|
+
),
|
|
16512
17519
|
];
|
|
16513
17520
|
|
|
16514
17521
|
const slackCall = async (
|
|
@@ -16650,9 +17657,7 @@ export const askModel = async (
|
|
|
16650
17657
|
} | null;
|
|
16651
17658
|
if (res?.success === false || body?.success === false) {
|
|
16652
17659
|
const why = \`\${target.provider}: \${String(body?.message ?? body?.error ?? \`HTTP \${res?.status}\`).slice(0, 200)}\`;
|
|
16653
|
-
throw body?.providerUnavailable === true
|
|
16654
|
-
? new ProviderUnavailableError(why)
|
|
16655
|
-
: new Error(why);
|
|
17660
|
+
throw body?.providerUnavailable === true ? new ProviderUnavailableError(why) : new Error(why);
|
|
16656
17661
|
}
|
|
16657
17662
|
const answer = body?.answers?.reason;
|
|
16658
17663
|
const reason = typeof answer?.choice === "string" ? answer.choice : "";
|
|
@@ -17350,7 +18355,7 @@ var patchRoute = route({
|
|
|
17350
18355
|
},
|
|
17351
18356
|
rbac: { permission: "extension.write" }
|
|
17352
18357
|
});
|
|
17353
|
-
var
|
|
18358
|
+
var deleteRoute2 = route({
|
|
17354
18359
|
method: "delete",
|
|
17355
18360
|
path: "/api/extensions/{id}",
|
|
17356
18361
|
pattern: ["api", "extensions", null],
|
|
@@ -17695,8 +18700,8 @@ async function handleExtensions(req, res, pathSegments, queryParams, agentId) {
|
|
|
17695
18700
|
patchRoute.respond(res, 200, { extension: redactExtension(extension) });
|
|
17696
18701
|
return true;
|
|
17697
18702
|
}
|
|
17698
|
-
if (
|
|
17699
|
-
const parsed = await
|
|
18703
|
+
if (deleteRoute2.match(req.method, pathSegments)) {
|
|
18704
|
+
const parsed = await deleteRoute2.parse(req, res, pathSegments, queryParams);
|
|
17700
18705
|
if (!parsed)
|
|
17701
18706
|
return true;
|
|
17702
18707
|
const stored = await getExtensionById(parsed.params.id);
|
|
@@ -17723,7 +18728,7 @@ async function handleExtensions(req, res, pathSegments, queryParams, agentId) {
|
|
|
17723
18728
|
respondLifecycleError(res, error);
|
|
17724
18729
|
return true;
|
|
17725
18730
|
}
|
|
17726
|
-
|
|
18731
|
+
deleteRoute2.respond(res, 200, { deleted: true, assets });
|
|
17727
18732
|
return true;
|
|
17728
18733
|
}
|
|
17729
18734
|
if (enableRoute.match(req.method, pathSegments)) {
|
|
@@ -18197,6 +19202,7 @@ init_zod();
|
|
|
18197
19202
|
// src/be/agent-fs-user-keys.ts
|
|
18198
19203
|
init_secret_scrubber();
|
|
18199
19204
|
init_rbac_roles();
|
|
19205
|
+
init_agent_fs_provision();
|
|
18200
19206
|
init_users();
|
|
18201
19207
|
|
|
18202
19208
|
class AgentFsKeyValidationError extends Error {
|
|
@@ -18342,6 +19348,7 @@ ${block}`, new Date().toISOString(), taskId]);
|
|
|
18342
19348
|
|
|
18343
19349
|
// src/http/fs.ts
|
|
18344
19350
|
init_rbac_roles();
|
|
19351
|
+
init_agent_fs_provision();
|
|
18345
19352
|
init_task_attachment_store();
|
|
18346
19353
|
init_users();
|
|
18347
19354
|
init_config3();
|
|
@@ -19139,6 +20146,65 @@ function sendProviderError(res, error) {
|
|
|
19139
20146
|
return true;
|
|
19140
20147
|
}
|
|
19141
20148
|
|
|
20149
|
+
// src/http/github-token.ts
|
|
20150
|
+
init_zod();
|
|
20151
|
+
init_app();
|
|
20152
|
+
init_request_auth_context();
|
|
20153
|
+
init_request_principal();
|
|
20154
|
+
init_route_def();
|
|
20155
|
+
init_utils2();
|
|
20156
|
+
var installationTokenRoute = route({
|
|
20157
|
+
method: "post",
|
|
20158
|
+
path: "/api/github/installation-token",
|
|
20159
|
+
pattern: ["api", "github", "installation-token"],
|
|
20160
|
+
summary: "Mint a GitHub App installation token for worker git and gh",
|
|
20161
|
+
description: "Internal worker endpoint. Returns a short-lived installation token for the installation in `GITHUB_APP_INSTALLATION_ID`, minted with the API server's GitHub App credentials. The caller cannot choose the installation. Only a registered agent (swarm API key plus X-Agent-ID, or an agent or runtime token) may call it; user, guest and ACP task tokens are refused. 404 when the App or the installation id is not configured, so workers fall back to `GITHUB_TOKEN`.",
|
|
20162
|
+
tags: ["GitHub"],
|
|
20163
|
+
body: object2({}).optional(),
|
|
20164
|
+
responses: {
|
|
20165
|
+
200: {
|
|
20166
|
+
description: "Installation token and its expiry (ISO 8601)",
|
|
20167
|
+
schema: object2({ token: string2(), expiresAt: string2() })
|
|
20168
|
+
},
|
|
20169
|
+
403: { description: "Caller is not a registered agent" },
|
|
20170
|
+
404: { description: "GitHub App worker auth is not configured" },
|
|
20171
|
+
502: { description: "GitHub refused or failed to mint the token" }
|
|
20172
|
+
},
|
|
20173
|
+
auth: { apiKey: true, agentId: true },
|
|
20174
|
+
rbac: {
|
|
20175
|
+
ungated: "the handler admits only registered agent principals and mints for one fixed installation"
|
|
20176
|
+
}
|
|
20177
|
+
});
|
|
20178
|
+
async function handleGitHubToken(req, res, pathSegments, myAgentId) {
|
|
20179
|
+
if (!installationTokenRoute.match(req.method, pathSegments))
|
|
20180
|
+
return false;
|
|
20181
|
+
const parsed = await installationTokenRoute.parse(req, res, pathSegments, new URLSearchParams);
|
|
20182
|
+
if (!parsed)
|
|
20183
|
+
return true;
|
|
20184
|
+
const principal = await resolveRequestPrincipal(req, myAgentId, {
|
|
20185
|
+
precedence: "agent-first",
|
|
20186
|
+
requireRegisteredAgent: true
|
|
20187
|
+
});
|
|
20188
|
+
const auth = getRequestAuth(req);
|
|
20189
|
+
const taskToken = auth?.kind === "agent" && auth.tokenKind === "task";
|
|
20190
|
+
if (principal?.kind !== "agent" || !principal.agentId || taskToken) {
|
|
20191
|
+
jsonError(res, "Only a registered agent may mint a GitHub installation token", 403);
|
|
20192
|
+
return true;
|
|
20193
|
+
}
|
|
20194
|
+
const result = await getWorkerInstallationToken();
|
|
20195
|
+
if (result.status === "unconfigured") {
|
|
20196
|
+
jsonError(res, "GitHub App worker auth is not configured", 404);
|
|
20197
|
+
return true;
|
|
20198
|
+
}
|
|
20199
|
+
if (result.status === "error") {
|
|
20200
|
+
jsonError(res, "GitHub did not mint an installation token", 502);
|
|
20201
|
+
return true;
|
|
20202
|
+
}
|
|
20203
|
+
res.setHeader("Cache-Control", "no-store");
|
|
20204
|
+
installationTokenRoute.respond(res, 200, { token: result.token, expiresAt: result.expiresAt });
|
|
20205
|
+
return true;
|
|
20206
|
+
}
|
|
20207
|
+
|
|
19142
20208
|
// src/http/heartbeat.ts
|
|
19143
20209
|
init_zod();
|
|
19144
20210
|
init_route_def();
|
|
@@ -19621,7 +20687,7 @@ async function handleInboxState(req, res, pathSegments, queryParams) {
|
|
|
19621
20687
|
init_zod();
|
|
19622
20688
|
|
|
19623
20689
|
// src/slack/app-icon.ts
|
|
19624
|
-
|
|
20690
|
+
init_app4();
|
|
19625
20691
|
var import_web_api = __toESM(require_dist4(), 1);
|
|
19626
20692
|
var TTL_MS = 60 * 60 * 1000;
|
|
19627
20693
|
var REQUEST_TIMEOUT_MS = 2500;
|
|
@@ -22175,32 +23241,9 @@ async function handleMcp(req, res, transports, sessionActivity = {}, sessionAgen
|
|
|
22175
23241
|
delete sessionActivity[transport.sessionId];
|
|
22176
23242
|
}
|
|
22177
23243
|
};
|
|
22178
|
-
const configs = await getResolvedConfig2(agentId);
|
|
22179
|
-
const configValue = configs.find((config) => config.key === "SCRIPTS_ONLY_MCP")?.value;
|
|
22180
|
-
const preloadEnabled = parseEnvFlag(configs.find((config) => config.key === "TASK_TOOL_PRELOAD_ENABLED")?.value ?? process.env.TASK_TOOL_PRELOAD_ENABLED, true);
|
|
22181
|
-
let preloadedTools = [];
|
|
22182
23244
|
const sourceTaskId = headerValue(req.headers["x-source-task-id"]);
|
|
22183
23245
|
const sourceTask = sourceTaskId ? await getTaskById2(sourceTaskId) : undefined;
|
|
22184
|
-
const
|
|
22185
|
-
if (preloadEnabled) {
|
|
22186
|
-
if (sourceTask?.agentId === agentId) {
|
|
22187
|
-
const manifestValue = configs.find((config) => config.key === "TASK_TOOL_MANIFESTS")?.value ?? process.env.TASK_TOOL_MANIFESTS ?? "{}";
|
|
22188
|
-
try {
|
|
22189
|
-
preloadedTools = selectTaskTools(parseTaskToolManifest(manifestValue), sourceTask);
|
|
22190
|
-
} catch {
|
|
22191
|
-
console.warn("[MCP] Invalid TASK_TOOL_MANIFESTS; using ordinary tool discovery");
|
|
22192
|
-
}
|
|
22193
|
-
}
|
|
22194
|
-
}
|
|
22195
|
-
const server = await createServer({
|
|
22196
|
-
preloadedTools,
|
|
22197
|
-
excludedTools,
|
|
22198
|
-
enabledTools: configs.find((config) => config.key === "SWARM_ENABLED_TOOLS")?.value ?? process.env.SWARM_ENABLED_TOOLS,
|
|
22199
|
-
scriptsOnly: resolveScriptsOnlyMode({
|
|
22200
|
-
env: process.env.SCRIPTS_ONLY_MCP,
|
|
22201
|
-
configValue
|
|
22202
|
-
})
|
|
22203
|
-
});
|
|
23246
|
+
const server = await createServer(await resolveMcpSessionOptions(agentId, sourceTask));
|
|
22204
23247
|
await server.connect(transport);
|
|
22205
23248
|
} else {
|
|
22206
23249
|
return respondNoMcpSession(res, sessionId);
|
|
@@ -22221,6 +23264,29 @@ async function handleMcp(req, res, transports, sessionActivity = {}, sessionAgen
|
|
|
22221
23264
|
res.end("Method not allowed");
|
|
22222
23265
|
return true;
|
|
22223
23266
|
}
|
|
23267
|
+
async function resolveMcpSessionOptions(agentId, sourceTask) {
|
|
23268
|
+
const configs = await getResolvedConfig2(agentId);
|
|
23269
|
+
const configValue = configs.find((config) => config.key === "SCRIPTS_ONLY_MCP")?.value;
|
|
23270
|
+
const preloadEnabled = parseEnvFlag(configs.find((config) => config.key === "TASK_TOOL_PRELOAD_ENABLED")?.value ?? process.env.TASK_TOOL_PRELOAD_ENABLED, true);
|
|
23271
|
+
let preloadedTools = [];
|
|
23272
|
+
const excludedTools = sourceTask && !isChatSdkTask(sourceTask) ? [...CHAT_TASK_ONLY_TOOLS] : [];
|
|
23273
|
+
if (preloadEnabled) {
|
|
23274
|
+
if (sourceTask?.agentId === agentId) {
|
|
23275
|
+
const manifestValue = configs.find((config) => config.key === "TASK_TOOL_MANIFESTS")?.value ?? process.env.TASK_TOOL_MANIFESTS ?? "{}";
|
|
23276
|
+
try {
|
|
23277
|
+
preloadedTools = selectTaskTools(parseTaskToolManifest(manifestValue), sourceTask);
|
|
23278
|
+
} catch {
|
|
23279
|
+
console.warn("[MCP] Invalid TASK_TOOL_MANIFESTS; using ordinary tool discovery");
|
|
23280
|
+
}
|
|
23281
|
+
}
|
|
23282
|
+
}
|
|
23283
|
+
return {
|
|
23284
|
+
preloadedTools,
|
|
23285
|
+
excludedTools,
|
|
23286
|
+
enabledTools: configs.find((config) => config.key === "SWARM_ENABLED_TOOLS")?.value ?? process.env.SWARM_ENABLED_TOOLS,
|
|
23287
|
+
scriptsOnly: resolveScriptsOnlyMode({ env: process.env.SCRIPTS_ONLY_MCP, configValue })
|
|
23288
|
+
};
|
|
23289
|
+
}
|
|
22224
23290
|
|
|
22225
23291
|
// src/http/index.ts
|
|
22226
23292
|
init_mcp_bridge();
|
|
@@ -23475,6 +24541,198 @@ init_users();
|
|
|
23475
24541
|
init_mcp();
|
|
23476
24542
|
init_zod();
|
|
23477
24543
|
init_package();
|
|
24544
|
+
|
|
24545
|
+
// src/be/mcp-events/protocol.ts
|
|
24546
|
+
init_zod();
|
|
24547
|
+
init_db4();
|
|
24548
|
+
var MAX_SUBSCRIPTIONS_PER_USER = 25;
|
|
24549
|
+
var DEFAULT_TTL_MS = 60 * 60 * 1000;
|
|
24550
|
+
var MIN_TTL_MS = 60 * 1000;
|
|
24551
|
+
var MAX_TTL_MS = 24 * 60 * 60 * 1000;
|
|
24552
|
+
var VERIFICATION_CACHE_MS = 24 * 60 * 60 * 1000;
|
|
24553
|
+
var ROTATION_GRACE_MS = 10 * 60 * 1000;
|
|
24554
|
+
|
|
24555
|
+
class EventsRpcError extends Error {
|
|
24556
|
+
code;
|
|
24557
|
+
data;
|
|
24558
|
+
constructor(code, message, data) {
|
|
24559
|
+
super(message);
|
|
24560
|
+
this.code = code;
|
|
24561
|
+
this.data = data;
|
|
24562
|
+
}
|
|
24563
|
+
}
|
|
24564
|
+
function invalidParams(message) {
|
|
24565
|
+
return new EventsRpcError(EventsErrorCode.InvalidParams, message);
|
|
24566
|
+
}
|
|
24567
|
+
function resourceExhausted() {
|
|
24568
|
+
return new EventsRpcError(EventsErrorCode.ResourceExhausted, "Too many subscriptions", {
|
|
24569
|
+
limit: "subscriptions",
|
|
24570
|
+
max: MAX_SUBSCRIPTIONS_PER_USER
|
|
24571
|
+
});
|
|
24572
|
+
}
|
|
24573
|
+
var EventsListRequestSchema = object2({
|
|
24574
|
+
method: literal2("events/list"),
|
|
24575
|
+
params: unknown().optional()
|
|
24576
|
+
});
|
|
24577
|
+
var EventsSubscribeRequestSchema = object2({
|
|
24578
|
+
method: literal2("events/subscribe"),
|
|
24579
|
+
params: unknown().optional()
|
|
24580
|
+
});
|
|
24581
|
+
var EventsUnsubscribeRequestSchema = object2({
|
|
24582
|
+
method: literal2("events/unsubscribe"),
|
|
24583
|
+
params: unknown().optional()
|
|
24584
|
+
});
|
|
24585
|
+
function asRecord(value) {
|
|
24586
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
24587
|
+
}
|
|
24588
|
+
function parseKey(rawParams) {
|
|
24589
|
+
const params = asRecord(rawParams);
|
|
24590
|
+
if (typeof params.name !== "string")
|
|
24591
|
+
throw invalidParams("name is required");
|
|
24592
|
+
if (!isTaskEventName(params.name)) {
|
|
24593
|
+
throw new EventsRpcError(EventsErrorCode.NotFound, `Unknown event: ${params.name}`, {
|
|
24594
|
+
kind: "event"
|
|
24595
|
+
});
|
|
24596
|
+
}
|
|
24597
|
+
const args = parseTaskEventArguments(params.arguments);
|
|
24598
|
+
if (!args)
|
|
24599
|
+
throw invalidParams("arguments do not match the event's inputSchema");
|
|
24600
|
+
const delivery = asRecord(params.delivery);
|
|
24601
|
+
if (delivery.mode !== undefined && delivery.mode !== "webhook") {
|
|
24602
|
+
throw new EventsRpcError(EventsErrorCode.Unsupported, "Only webhook delivery is offered", {
|
|
24603
|
+
feature: "deliveryMode",
|
|
24604
|
+
value: delivery.mode
|
|
24605
|
+
});
|
|
24606
|
+
}
|
|
24607
|
+
const urlProblem = callbackUrlProblem(delivery.url);
|
|
24608
|
+
if (urlProblem)
|
|
24609
|
+
throw invalidParams(urlProblem);
|
|
24610
|
+
return {
|
|
24611
|
+
name: params.name,
|
|
24612
|
+
arguments: args,
|
|
24613
|
+
argumentsJson: canonicalJson(args),
|
|
24614
|
+
url: delivery.url,
|
|
24615
|
+
delivery
|
|
24616
|
+
};
|
|
24617
|
+
}
|
|
24618
|
+
function grantTtlMs(raw) {
|
|
24619
|
+
if (raw === undefined)
|
|
24620
|
+
return DEFAULT_TTL_MS;
|
|
24621
|
+
if (raw === null)
|
|
24622
|
+
return MAX_TTL_MS;
|
|
24623
|
+
if (typeof raw !== "number" || !Number.isFinite(raw))
|
|
24624
|
+
throw invalidParams("ttlMs must be a number");
|
|
24625
|
+
return Math.min(MAX_TTL_MS, Math.max(MIN_TTL_MS, Math.floor(raw)));
|
|
24626
|
+
}
|
|
24627
|
+
var VERIFICATIONS_PER_USER_PER_HOUR = 30;
|
|
24628
|
+
var VERIFICATIONS_PER_HOUR = 1000;
|
|
24629
|
+
var HOUR_MS = 60 * 60 * 1000;
|
|
24630
|
+
var verificationLog = new Map;
|
|
24631
|
+
function takeVerificationBudget(userId, now) {
|
|
24632
|
+
const recent = (key) => (verificationLog.get(key) ?? []).filter((at) => at > now - HOUR_MS);
|
|
24633
|
+
const mine = recent(userId);
|
|
24634
|
+
const all = recent("*");
|
|
24635
|
+
if (mine.length >= VERIFICATIONS_PER_USER_PER_HOUR || all.length >= VERIFICATIONS_PER_HOUR) {
|
|
24636
|
+
return false;
|
|
24637
|
+
}
|
|
24638
|
+
verificationLog.set(userId, [...mine, now]);
|
|
24639
|
+
verificationLog.set("*", [...all, now]);
|
|
24640
|
+
return true;
|
|
24641
|
+
}
|
|
24642
|
+
async function handleSubscribe(user, tokenId, authorize, rawParams) {
|
|
24643
|
+
const key = parseKey(rawParams);
|
|
24644
|
+
const secretText = key.delivery.secret;
|
|
24645
|
+
const secret = parseWebhookSecret(secretText);
|
|
24646
|
+
if (!secret) {
|
|
24647
|
+
throw invalidParams("delivery.secret must be whsec_ followed by base64 of 24 to 64 bytes");
|
|
24648
|
+
}
|
|
24649
|
+
const ttlMs = grantTtlMs(asRecord(rawParams).ttlMs);
|
|
24650
|
+
if (!await authorize("events/subscribe")) {
|
|
24651
|
+
throw new EventsRpcError(EventsErrorCode.Forbidden, "Forbidden");
|
|
24652
|
+
}
|
|
24653
|
+
if (key.arguments.taskId) {
|
|
24654
|
+
const task = await getTaskById2(key.arguments.taskId);
|
|
24655
|
+
if (!task || task.requestedByUserId !== user.id) {
|
|
24656
|
+
throw new EventsRpcError(EventsErrorCode.Forbidden, "taskId is not one of your tasks");
|
|
24657
|
+
}
|
|
24658
|
+
}
|
|
24659
|
+
const now = Date.now();
|
|
24660
|
+
const nowIso = new Date(now).toISOString();
|
|
24661
|
+
await deleteExpiredSubscriptions(nowIso);
|
|
24662
|
+
const id = subscriptionIdFor(user.id, key.url, key.name, key.argumentsJson);
|
|
24663
|
+
const previous = await getSubscription(id);
|
|
24664
|
+
const refreshing = previous !== null && previous.expiresAt > nowIso;
|
|
24665
|
+
if (!refreshing && await countLiveSubscriptions(user.id, nowIso) >= MAX_SUBSCRIPTIONS_PER_USER) {
|
|
24666
|
+
throw resourceExhausted();
|
|
24667
|
+
}
|
|
24668
|
+
let verifiedAt = await latestVerification(user.id, key.url, new Date(now - VERIFICATION_CACHE_MS).toISOString(), nowIso);
|
|
24669
|
+
if (!verifiedAt) {
|
|
24670
|
+
if (!takeVerificationBudget(user.id, now)) {
|
|
24671
|
+
throw new EventsRpcError(EventsErrorCode.ResourceExhausted, "Too many verifications", {
|
|
24672
|
+
limit: "verifications",
|
|
24673
|
+
max: VERIFICATIONS_PER_USER_PER_HOUR
|
|
24674
|
+
});
|
|
24675
|
+
}
|
|
24676
|
+
const failure = await verifyCallbackEndpoint({ url: key.url, subscriptionId: id, secret });
|
|
24677
|
+
if (failure) {
|
|
24678
|
+
throw new EventsRpcError(EventsErrorCode.CallbackEndpointError, "Callback endpoint verification failed", { reason: failure });
|
|
24679
|
+
}
|
|
24680
|
+
verifiedAt = nowIso;
|
|
24681
|
+
}
|
|
24682
|
+
const row = await upsertSubscription({
|
|
24683
|
+
id,
|
|
24684
|
+
userId: user.id,
|
|
24685
|
+
tokenId,
|
|
24686
|
+
eventName: key.name,
|
|
24687
|
+
argumentsJson: key.argumentsJson,
|
|
24688
|
+
url: key.url,
|
|
24689
|
+
secret: secretText,
|
|
24690
|
+
verifiedAt,
|
|
24691
|
+
expiresAt: new Date(now + ttlMs).toISOString(),
|
|
24692
|
+
nowIso,
|
|
24693
|
+
rotationGraceUntil: new Date(now + ROTATION_GRACE_MS).toISOString(),
|
|
24694
|
+
maxActivePerUser: MAX_SUBSCRIPTIONS_PER_USER
|
|
24695
|
+
});
|
|
24696
|
+
if (row === "limit")
|
|
24697
|
+
throw resourceExhausted();
|
|
24698
|
+
return {
|
|
24699
|
+
resultType: "complete",
|
|
24700
|
+
id: row.id,
|
|
24701
|
+
refreshBefore: row.expiresAt,
|
|
24702
|
+
cursor: null,
|
|
24703
|
+
truncated: false,
|
|
24704
|
+
...refreshing ? {
|
|
24705
|
+
deliveryStatus: {
|
|
24706
|
+
active: true,
|
|
24707
|
+
lastDeliveryAt: row.lastDeliveryAt,
|
|
24708
|
+
lastError: row.lastError,
|
|
24709
|
+
...row.failedSince ? { failedSince: row.failedSince } : {}
|
|
24710
|
+
}
|
|
24711
|
+
} : {}
|
|
24712
|
+
};
|
|
24713
|
+
}
|
|
24714
|
+
async function handleUnsubscribe(user, authorize, rawParams) {
|
|
24715
|
+
const key = parseKey(rawParams);
|
|
24716
|
+
if (!await authorize("events/unsubscribe")) {
|
|
24717
|
+
throw new EventsRpcError(EventsErrorCode.Forbidden, "Forbidden");
|
|
24718
|
+
}
|
|
24719
|
+
await deleteSubscription(subscriptionIdFor(user.id, key.url, key.name, key.argumentsJson), user.id);
|
|
24720
|
+
return { resultType: "complete" };
|
|
24721
|
+
}
|
|
24722
|
+
function registerUserEvents(server, user, tokenId, authorize) {
|
|
24723
|
+
server.server.registerCapabilities({
|
|
24724
|
+
events: {},
|
|
24725
|
+
extensions: { [EVENTS_EXTENSION_ID]: {} }
|
|
24726
|
+
});
|
|
24727
|
+
server.server.setRequestHandler(EventsListRequestSchema, async () => ({
|
|
24728
|
+
resultType: "complete",
|
|
24729
|
+
events: EVENT_DESCRIPTORS
|
|
24730
|
+
}));
|
|
24731
|
+
server.server.setRequestHandler(EventsSubscribeRequestSchema, async (request) => handleSubscribe(user, tokenId, authorize, request.params));
|
|
24732
|
+
server.server.setRequestHandler(EventsUnsubscribeRequestSchema, async (request) => handleUnsubscribe(user, authorize, request.params));
|
|
24733
|
+
}
|
|
24734
|
+
|
|
24735
|
+
// src/server-user.ts
|
|
23478
24736
|
init_rbac_audit();
|
|
23479
24737
|
init_rbac_roles();
|
|
23480
24738
|
init_mcp_limits();
|
|
@@ -23521,7 +24779,7 @@ async function maybeDenyUserToolAdmission(user, toolName, config) {
|
|
|
23521
24779
|
return;
|
|
23522
24780
|
return toolErr(`Forbidden: ${decision.reason}`);
|
|
23523
24781
|
}
|
|
23524
|
-
function createUserServer(user) {
|
|
24782
|
+
function createUserServer(user, tokenId) {
|
|
23525
24783
|
const server = new McpServer({
|
|
23526
24784
|
name: `${package_default.name}-user`,
|
|
23527
24785
|
version: package_default.version,
|
|
@@ -23533,6 +24791,13 @@ function createUserServer(user) {
|
|
|
23533
24791
|
maxToolInputElements: MCP_MAX_TOOL_INPUT_ELEMENTS
|
|
23534
24792
|
});
|
|
23535
24793
|
const registerTool = createToolRegistrar(server);
|
|
24794
|
+
if (tokenId && isMcpUserEventsEnabled()) {
|
|
24795
|
+
const eventsAdmission = { annotations: { readOnlyHint: true } };
|
|
24796
|
+
registerUserEvents(server, user, tokenId, async (method) => {
|
|
24797
|
+
const denied = await maybeDenyUserToolAdmission(user, method, eventsAdmission);
|
|
24798
|
+
return denied === undefined;
|
|
24799
|
+
});
|
|
24800
|
+
}
|
|
23536
24801
|
const sendTaskConfig = {
|
|
23537
24802
|
title: "Send a task",
|
|
23538
24803
|
annotations: { destructiveHint: false },
|
|
@@ -23620,7 +24885,7 @@ function unauthorized2(res) {
|
|
|
23620
24885
|
res.end(JSON.stringify({ error: "Unauthorized" }));
|
|
23621
24886
|
return true;
|
|
23622
24887
|
}
|
|
23623
|
-
function
|
|
24888
|
+
function extractBearer2(req) {
|
|
23624
24889
|
const header = req.headers.authorization;
|
|
23625
24890
|
if (!header?.startsWith("Bearer "))
|
|
23626
24891
|
return null;
|
|
@@ -23628,22 +24893,23 @@ function extractBearer(req) {
|
|
|
23628
24893
|
return token.startsWith("aswt_") ? token : null;
|
|
23629
24894
|
}
|
|
23630
24895
|
async function resolveActiveUser(req) {
|
|
23631
|
-
const token =
|
|
24896
|
+
const token = extractBearer2(req);
|
|
23632
24897
|
if (!token)
|
|
23633
24898
|
return null;
|
|
23634
|
-
const
|
|
23635
|
-
if (!user || user.status !== "active")
|
|
24899
|
+
const resolved = await resolveUserToken(token);
|
|
24900
|
+
if (!resolved?.user || resolved.user.status !== "active")
|
|
23636
24901
|
return null;
|
|
23637
|
-
return user;
|
|
24902
|
+
return { user: resolved.user, tokenId: resolved.tokenId };
|
|
23638
24903
|
}
|
|
23639
24904
|
async function handleMcpUser(req, res, transports, sessionUsers, sessionActivity = {}) {
|
|
23640
24905
|
const sessionId = req.headers["mcp-session-id"];
|
|
23641
24906
|
if (req.url !== "/mcp-user") {
|
|
23642
24907
|
return false;
|
|
23643
24908
|
}
|
|
23644
|
-
const
|
|
23645
|
-
if (!
|
|
24909
|
+
const resolved = await resolveActiveUser(req);
|
|
24910
|
+
if (!resolved)
|
|
23646
24911
|
return unauthorized2(res);
|
|
24912
|
+
const { user, tokenId } = resolved;
|
|
23647
24913
|
setRequestAuth(req, { kind: "user", userId: user.id, user });
|
|
23648
24914
|
if (sessionId && transports[sessionId] && sessionUsers[sessionId] !== user.id) {
|
|
23649
24915
|
return unauthorized2(res);
|
|
@@ -23677,7 +24943,7 @@ async function handleMcpUser(req, res, transports, sessionUsers, sessionActivity
|
|
|
23677
24943
|
delete sessionActivity[transport.sessionId];
|
|
23678
24944
|
}
|
|
23679
24945
|
};
|
|
23680
|
-
const server = createUserServer(user);
|
|
24946
|
+
const server = createUserServer(user, tokenId);
|
|
23681
24947
|
await server.connect(transport);
|
|
23682
24948
|
} else {
|
|
23683
24949
|
return respondNoMcpSession(res, sessionId);
|
|
@@ -27065,6 +28331,86 @@ async function handleOAuthLocks(req, res, pathSegments, queryParams) {
|
|
|
27065
28331
|
return false;
|
|
27066
28332
|
}
|
|
27067
28333
|
|
|
28334
|
+
// src/http/object-webhooks.ts
|
|
28335
|
+
init_zod();
|
|
28336
|
+
init_object_webhooks();
|
|
28337
|
+
init_triggers();
|
|
28338
|
+
init_route_def();
|
|
28339
|
+
init_utils2();
|
|
28340
|
+
var MAX_BODY_BYTES = 64 * 1024;
|
|
28341
|
+
var objectWebhook = route({
|
|
28342
|
+
method: "post",
|
|
28343
|
+
path: "/api/objects/agent-fs-webhook/{id}",
|
|
28344
|
+
pattern: ["api", "objects", "agent-fs-webhook", null],
|
|
28345
|
+
summary: "Receive agent-fs file.changed events that keep primitive objects in sync",
|
|
28346
|
+
tags: ["Webhooks"],
|
|
28347
|
+
params: object2({ id: string2().describe("Receiver id the swarm registered with agent-fs") }),
|
|
28348
|
+
auth: { apiKey: false },
|
|
28349
|
+
rbac: {
|
|
28350
|
+
ungated: "provider webhook: authenticated by the per-drive Standard Webhooks HMAC secret the swarm registered with agent-fs, not a swarm principal"
|
|
28351
|
+
},
|
|
28352
|
+
responses: {
|
|
28353
|
+
200: {
|
|
28354
|
+
description: "Event applied or ignored",
|
|
28355
|
+
schema: object2({
|
|
28356
|
+
action: _enum2(["updated", "tombstoned", "restored", "moved", "ignored"]),
|
|
28357
|
+
path: string2(),
|
|
28358
|
+
id: string2().optional(),
|
|
28359
|
+
reason: string2().optional()
|
|
28360
|
+
})
|
|
28361
|
+
},
|
|
28362
|
+
400: { description: "Body is not a valid event" },
|
|
28363
|
+
401: { description: "Unknown receiver, missing headers or invalid signature" },
|
|
28364
|
+
413: { description: "Body exceeds 64 KiB" },
|
|
28365
|
+
503: { description: "agent-fs could not be read; agent-fs retries the delivery" }
|
|
28366
|
+
}
|
|
28367
|
+
});
|
|
28368
|
+
var header2 = (req, name) => {
|
|
28369
|
+
const value = req.headers[name];
|
|
28370
|
+
return Array.isArray(value) ? value[0] : value;
|
|
28371
|
+
};
|
|
28372
|
+
async function handleObjectWebhooks(req, res, pathSegments) {
|
|
28373
|
+
if (!objectWebhook.match(req.method, pathSegments))
|
|
28374
|
+
return false;
|
|
28375
|
+
if (enforceContentLengthCap(req, res, MAX_BODY_BYTES) === BODY_TOO_LARGE)
|
|
28376
|
+
return true;
|
|
28377
|
+
const chunks = [];
|
|
28378
|
+
let received = 0;
|
|
28379
|
+
for await (const chunk of req) {
|
|
28380
|
+
received += chunk.byteLength;
|
|
28381
|
+
if (received > MAX_BODY_BYTES) {
|
|
28382
|
+
jsonError(res, `Payload too large (max ${MAX_BODY_BYTES} bytes)`, 413);
|
|
28383
|
+
req.resume();
|
|
28384
|
+
return true;
|
|
28385
|
+
}
|
|
28386
|
+
chunks.push(chunk);
|
|
28387
|
+
}
|
|
28388
|
+
const rawBody = Buffer.concat(chunks).toString("utf-8");
|
|
28389
|
+
const id = header2(req, "webhook-id");
|
|
28390
|
+
const timestamp = header2(req, "webhook-timestamp");
|
|
28391
|
+
const signature = header2(req, "webhook-signature");
|
|
28392
|
+
const hook = await objectWebhookSecret2(pathSegments[3] ?? "");
|
|
28393
|
+
const key = hook ? decodeStandardWebhookSecret(hook.secret) : null;
|
|
28394
|
+
if (!hook || !key || !id || !timestamp || !signature || !verifyStandardWebhookSignature(key, rawBody, { id, timestamp, signature })) {
|
|
28395
|
+
jsonError(res, "Invalid webhook signature", 401);
|
|
28396
|
+
return true;
|
|
28397
|
+
}
|
|
28398
|
+
let envelope;
|
|
28399
|
+
try {
|
|
28400
|
+
envelope = JSON.parse(rawBody);
|
|
28401
|
+
} catch {
|
|
28402
|
+
jsonError(res, "Invalid JSON body", 400);
|
|
28403
|
+
return true;
|
|
28404
|
+
}
|
|
28405
|
+
const outcome = await handleObjectWebhookEvent2(hook, envelope);
|
|
28406
|
+
if (outcome.status === 200) {
|
|
28407
|
+
objectWebhook.respond(res, 200, outcome.result);
|
|
28408
|
+
} else {
|
|
28409
|
+
jsonError(res, outcome.error, outcome.status);
|
|
28410
|
+
}
|
|
28411
|
+
return true;
|
|
28412
|
+
}
|
|
28413
|
+
|
|
27068
28414
|
// src/http/onboarding.ts
|
|
27069
28415
|
init_openai2();
|
|
27070
28416
|
init_automation_preflight();
|
|
@@ -28981,7 +30327,7 @@ var supersedeTaskRoute = route({
|
|
|
28981
30327
|
pattern: ["api", "tasks", null, "supersede"],
|
|
28982
30328
|
session: { taskParam: "id" },
|
|
28983
30329
|
summary: "Supersede an in-progress task (terminate + spawn resume follow-up)",
|
|
28984
|
-
description: "Marks the original task `superseded` (terminal) and creates a fresh `taskType=\"resume\"` follow-up so a worker can pick up the work in a new provider session. Workflow-step tasks (those with `workflowRunStepId`) are carved out: the original is marked `failed` with reason `superseded_workflow_task` and no follow-up is created — the workflow engine's retry/failure policy applies, and the task moves to `superseded` once the engine queues the step's retry or the step ends without failing. With `reason: provider_fallback` (and its `errorClass`), the resume runs on the same agent
|
|
30330
|
+
description: "Marks the original task `superseded` (terminal) and creates a fresh `taskType=\"resume\"` follow-up so a worker can pick up the work in a new provider session. Workflow-step tasks (those with `workflowRunStepId`) are carved out: the original is marked `failed` with reason `superseded_workflow_task` and no follow-up is created — the workflow engine's retry/failure policy applies, and the task moves to `superseded` once the engine queues the step's retry or the step ends without failing. With `reason: provider_fallback` (and its `errorClass`), the resume runs on the same agent: on the same profile while a key-scoped error (`rate_limit`, `credits`) leaves another unbenched key in its pool, else on the next fallback profile that passes the profile check; when none is left, or the task is a workflow step, nothing changes and `kind: noFallback` tells the worker to fail the task itself, led by `failureReason` when set.",
|
|
28985
30331
|
tags: ["Tasks"],
|
|
28986
30332
|
params: object2({ id: string2() }),
|
|
28987
30333
|
body: object2({ reason: ResumeReasonSchema, errorClass: ProviderErrorClassSchema.optional() }).refine((body) => body.reason === "provider_fallback" === (body.errorClass !== undefined), {
|
|
@@ -30144,6 +31490,9 @@ async function handleTasks(req, res, pathSegments, queryParams, myAgentId) {
|
|
|
30144
31490
|
return true;
|
|
30145
31491
|
}
|
|
30146
31492
|
fallback = { profile: pick.profile, hop: pick.hop };
|
|
31493
|
+
if (pick.hop.from === pick.profile) {
|
|
31494
|
+
console.log(`[Supersede] Task ${task.id.slice(0, 8)} hit ${pick.hop.errorClass} on ${pick.profile} (key ...${task.credentialKeySuffix ?? "?"}); retrying the profile on another key`);
|
|
31495
|
+
}
|
|
30147
31496
|
}
|
|
30148
31497
|
if (task.workflowRunStepId != null) {
|
|
30149
31498
|
const failed = await failTask2(parsed.params.id, SUPERSEDED_WORKFLOW_TASK_REASON);
|
|
@@ -33506,7 +34855,7 @@ init_multi_runtime();
|
|
|
33506
34855
|
init_server();
|
|
33507
34856
|
|
|
33508
34857
|
// src/slack/channel-activity.ts
|
|
33509
|
-
|
|
34858
|
+
init_app4();
|
|
33510
34859
|
var cachedBotUserId = null;
|
|
33511
34860
|
var channelCache = null;
|
|
33512
34861
|
var CHANNEL_CACHE_TTL_MS = 5 * 60 * 1000;
|
|
@@ -34435,13 +35784,13 @@ init_types5();
|
|
|
34435
35784
|
init_secret_scrubber();
|
|
34436
35785
|
init_route_def();
|
|
34437
35786
|
init_utils2();
|
|
34438
|
-
import { createHash as
|
|
35787
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
34439
35788
|
function apiKeyFingerprint2(req) {
|
|
34440
35789
|
const authHeader = req.headers.authorization;
|
|
34441
35790
|
const providedKey = authHeader?.startsWith("Bearer ") ? authHeader.slice(7) : "";
|
|
34442
35791
|
if (!providedKey)
|
|
34443
35792
|
return "";
|
|
34444
|
-
const digest =
|
|
35793
|
+
const digest = createHash4("sha256").update(providedKey).digest("hex").slice(0, 8);
|
|
34445
35794
|
return scrubSecrets(digest);
|
|
34446
35795
|
}
|
|
34447
35796
|
var PricingTriplePathParams = object2({
|
|
@@ -34641,7 +35990,8 @@ var ResolveResultSchema = object2({
|
|
|
34641
35990
|
templateId: string2().optional(),
|
|
34642
35991
|
scope: string2().optional(),
|
|
34643
35992
|
skipped: boolean(),
|
|
34644
|
-
unresolved: array2(string2())
|
|
35993
|
+
unresolved: array2(string2()),
|
|
35994
|
+
segments: array2(object2({ templateId: string2(), chars: number2().int() })).optional()
|
|
34645
35995
|
});
|
|
34646
35996
|
var DbResolveResultSchema = union3([
|
|
34647
35997
|
object2({ template: PromptTemplateResponseSchema }),
|
|
@@ -35324,6 +36674,957 @@ async function handleRepos(req, res, pathSegments, queryParams, myAgentId) {
|
|
|
35324
36674
|
return false;
|
|
35325
36675
|
}
|
|
35326
36676
|
|
|
36677
|
+
// src/http/request-composition.ts
|
|
36678
|
+
init_zod();
|
|
36679
|
+
init_db4();
|
|
36680
|
+
|
|
36681
|
+
// src/be/db/request-composition.ts
|
|
36682
|
+
init_db4();
|
|
36683
|
+
init_runtime2();
|
|
36684
|
+
var MAX_REQUEST_COMPOSITIONS_PER_TASK = 100;
|
|
36685
|
+
async function createRequestComposition(input) {
|
|
36686
|
+
const id = crypto.randomUUID();
|
|
36687
|
+
const createdAt = new Date().toISOString();
|
|
36688
|
+
const staticEstTokens = input.parts.reduce((sum, part) => sum + part.estTokens, 0);
|
|
36689
|
+
const tokenRatio = input.tokenRatio ?? 1;
|
|
36690
|
+
const seq = await getDbClient2().transaction(async (tx) => {
|
|
36691
|
+
const stored = await tx.get("SELECT COUNT(*) AS count FROM request_composition WHERE taskId = ?", [input.taskId]);
|
|
36692
|
+
if ((stored?.count ?? 0) >= MAX_REQUEST_COMPOSITIONS_PER_TASK)
|
|
36693
|
+
return null;
|
|
36694
|
+
const last = await tx.get("SELECT MAX(seq) AS seq FROM request_composition WHERE sessionId = ?", [input.sessionId]);
|
|
36695
|
+
const next = last?.seq == null ? 0 : last.seq + 1;
|
|
36696
|
+
await tx.run(`INSERT INTO request_composition
|
|
36697
|
+
(id, taskId, agentId, sessionId, seq, provider, model, source, parts, staticEstTokens, tokenRatio, createdAt)
|
|
36698
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
|
|
36699
|
+
id,
|
|
36700
|
+
input.taskId,
|
|
36701
|
+
input.agentId,
|
|
36702
|
+
input.sessionId,
|
|
36703
|
+
next,
|
|
36704
|
+
input.provider,
|
|
36705
|
+
input.model ?? null,
|
|
36706
|
+
input.source,
|
|
36707
|
+
JSON.stringify(input.parts),
|
|
36708
|
+
staticEstTokens,
|
|
36709
|
+
tokenRatio,
|
|
36710
|
+
createdAt
|
|
36711
|
+
]);
|
|
36712
|
+
return next;
|
|
36713
|
+
});
|
|
36714
|
+
if (seq === null)
|
|
36715
|
+
return null;
|
|
36716
|
+
return {
|
|
36717
|
+
id,
|
|
36718
|
+
taskId: input.taskId,
|
|
36719
|
+
agentId: input.agentId,
|
|
36720
|
+
sessionId: input.sessionId,
|
|
36721
|
+
seq,
|
|
36722
|
+
provider: input.provider,
|
|
36723
|
+
model: input.model ?? null,
|
|
36724
|
+
source: input.source,
|
|
36725
|
+
parts: input.parts,
|
|
36726
|
+
staticEstTokens,
|
|
36727
|
+
tokenRatio,
|
|
36728
|
+
createdAt
|
|
36729
|
+
};
|
|
36730
|
+
}
|
|
36731
|
+
async function getRequestCompositionsByTask(taskId, limit = MAX_REQUEST_COMPOSITIONS_PER_TASK) {
|
|
36732
|
+
const rows = await getDbClient2().query(`SELECT id, taskId, agentId, sessionId, seq, provider, model, source, parts, staticEstTokens, tokenRatio, createdAt
|
|
36733
|
+
FROM request_composition WHERE taskId = ? ORDER BY createdAt ASC, seq ASC LIMIT ?`, [taskId, limit]);
|
|
36734
|
+
return rows.map((row) => ({ ...row, parts: JSON.parse(row.parts) }));
|
|
36735
|
+
}
|
|
36736
|
+
async function getLatestWorkerComposition(sessionId) {
|
|
36737
|
+
const row = await getDbClient2().get(`SELECT id, taskId, agentId, sessionId, seq, provider, model, source, parts, staticEstTokens, tokenRatio, createdAt
|
|
36738
|
+
FROM request_composition WHERE sessionId = ? AND source = 'worker'
|
|
36739
|
+
ORDER BY seq DESC LIMIT 1`, [sessionId]);
|
|
36740
|
+
return row ? { ...row, parts: JSON.parse(row.parts) } : null;
|
|
36741
|
+
}
|
|
36742
|
+
var TOKEN_RATIO_KV_NAMESPACE = "swarm";
|
|
36743
|
+
var TOKEN_RATIO_MIN = 0.5;
|
|
36744
|
+
var TOKEN_RATIO_MAX = 2;
|
|
36745
|
+
var TOKEN_RATIO_ALPHA = 0.2;
|
|
36746
|
+
var tokenRatioKey = (provider) => `request-composition/token-ratio/${provider}`;
|
|
36747
|
+
function clampTokenRatio(ratio) {
|
|
36748
|
+
if (!Number.isFinite(ratio))
|
|
36749
|
+
return 1;
|
|
36750
|
+
return Math.min(TOKEN_RATIO_MAX, Math.max(TOKEN_RATIO_MIN, ratio));
|
|
36751
|
+
}
|
|
36752
|
+
function nextTokenRatio(prev, observed) {
|
|
36753
|
+
const obs = clampTokenRatio(observed);
|
|
36754
|
+
if (!prev || prev.samples <= 0)
|
|
36755
|
+
return { ratio: obs, samples: 1 };
|
|
36756
|
+
return {
|
|
36757
|
+
ratio: clampTokenRatio(prev.ratio + TOKEN_RATIO_ALPHA * (obs - prev.ratio)),
|
|
36758
|
+
samples: prev.samples + 1
|
|
36759
|
+
};
|
|
36760
|
+
}
|
|
36761
|
+
function parseTokenRatio(value) {
|
|
36762
|
+
if (typeof value === "number")
|
|
36763
|
+
return { ratio: clampTokenRatio(value), samples: 0 };
|
|
36764
|
+
if (value && typeof value === "object" && "ratio" in value) {
|
|
36765
|
+
const { ratio, samples } = value;
|
|
36766
|
+
if (typeof ratio !== "number")
|
|
36767
|
+
return null;
|
|
36768
|
+
return {
|
|
36769
|
+
ratio: clampTokenRatio(ratio),
|
|
36770
|
+
samples: typeof samples === "number" && samples > 0 ? Math.floor(samples) : 0
|
|
36771
|
+
};
|
|
36772
|
+
}
|
|
36773
|
+
return null;
|
|
36774
|
+
}
|
|
36775
|
+
async function getTokenRatio(provider) {
|
|
36776
|
+
const entry = await getKv2(TOKEN_RATIO_KV_NAMESPACE, tokenRatioKey(provider));
|
|
36777
|
+
return parseTokenRatio(entry?.value)?.ratio ?? 1;
|
|
36778
|
+
}
|
|
36779
|
+
async function recordTokenRatio(provider, observed) {
|
|
36780
|
+
return getDbClient2().transaction(async () => {
|
|
36781
|
+
const key = tokenRatioKey(provider);
|
|
36782
|
+
const entry = await getKv2(TOKEN_RATIO_KV_NAMESPACE, key);
|
|
36783
|
+
const next = nextTokenRatio(parseTokenRatio(entry?.value), observed);
|
|
36784
|
+
await upsertKv2({
|
|
36785
|
+
namespace: TOKEN_RATIO_KV_NAMESPACE,
|
|
36786
|
+
key,
|
|
36787
|
+
value: { ...next, updatedAt: new Date().toISOString() },
|
|
36788
|
+
valueType: "json"
|
|
36789
|
+
});
|
|
36790
|
+
return next;
|
|
36791
|
+
});
|
|
36792
|
+
}
|
|
36793
|
+
|
|
36794
|
+
// src/http/request-composition.ts
|
|
36795
|
+
init_key_browser();
|
|
36796
|
+
init_types5();
|
|
36797
|
+
init_route_def();
|
|
36798
|
+
|
|
36799
|
+
// node_modules/@modelcontextprotocol/sdk/dist/esm/client/index.js
|
|
36800
|
+
init_protocol();
|
|
36801
|
+
init_types();
|
|
36802
|
+
init_ajv_provider();
|
|
36803
|
+
init_zod_compat();
|
|
36804
|
+
|
|
36805
|
+
// node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/client.js
|
|
36806
|
+
init_types();
|
|
36807
|
+
|
|
36808
|
+
class ExperimentalClientTasks {
|
|
36809
|
+
constructor(_client) {
|
|
36810
|
+
this._client = _client;
|
|
36811
|
+
}
|
|
36812
|
+
async* callToolStream(params, resultSchema = CallToolResultSchema, options) {
|
|
36813
|
+
const clientInternal = this._client;
|
|
36814
|
+
const optionsWithTask = {
|
|
36815
|
+
...options,
|
|
36816
|
+
task: options?.task ?? (clientInternal.isToolTask(params.name) ? {} : undefined)
|
|
36817
|
+
};
|
|
36818
|
+
const stream = clientInternal.requestStream({ method: "tools/call", params }, resultSchema, optionsWithTask);
|
|
36819
|
+
const validator = clientInternal.getToolOutputValidator(params.name);
|
|
36820
|
+
for await (const message of stream) {
|
|
36821
|
+
if (message.type === "result" && validator) {
|
|
36822
|
+
const result = message.result;
|
|
36823
|
+
if (!result.structuredContent && !result.isError) {
|
|
36824
|
+
yield {
|
|
36825
|
+
type: "error",
|
|
36826
|
+
error: new McpError(ErrorCode.InvalidRequest, `Tool ${params.name} has an output schema but did not return structured content`)
|
|
36827
|
+
};
|
|
36828
|
+
return;
|
|
36829
|
+
}
|
|
36830
|
+
if (result.structuredContent) {
|
|
36831
|
+
try {
|
|
36832
|
+
const validationResult = validator(result.structuredContent);
|
|
36833
|
+
if (!validationResult.valid) {
|
|
36834
|
+
yield {
|
|
36835
|
+
type: "error",
|
|
36836
|
+
error: new McpError(ErrorCode.InvalidParams, `Structured content does not match the tool's output schema: ${validationResult.errorMessage}`)
|
|
36837
|
+
};
|
|
36838
|
+
return;
|
|
36839
|
+
}
|
|
36840
|
+
} catch (error) {
|
|
36841
|
+
if (error instanceof McpError) {
|
|
36842
|
+
yield { type: "error", error };
|
|
36843
|
+
return;
|
|
36844
|
+
}
|
|
36845
|
+
yield {
|
|
36846
|
+
type: "error",
|
|
36847
|
+
error: new McpError(ErrorCode.InvalidParams, `Failed to validate structured content: ${error instanceof Error ? error.message : String(error)}`)
|
|
36848
|
+
};
|
|
36849
|
+
return;
|
|
36850
|
+
}
|
|
36851
|
+
}
|
|
36852
|
+
}
|
|
36853
|
+
yield message;
|
|
36854
|
+
}
|
|
36855
|
+
}
|
|
36856
|
+
async getTask(taskId, options) {
|
|
36857
|
+
return this._client.getTask({ taskId }, options);
|
|
36858
|
+
}
|
|
36859
|
+
async getTaskResult(taskId, resultSchema, options) {
|
|
36860
|
+
return this._client.getTaskResult({ taskId }, resultSchema, options);
|
|
36861
|
+
}
|
|
36862
|
+
async listTasks(cursor, options) {
|
|
36863
|
+
return this._client.listTasks(cursor ? { cursor } : undefined, options);
|
|
36864
|
+
}
|
|
36865
|
+
async cancelTask(taskId, options) {
|
|
36866
|
+
return this._client.cancelTask({ taskId }, options);
|
|
36867
|
+
}
|
|
36868
|
+
requestStream(request, resultSchema, options) {
|
|
36869
|
+
return this._client.requestStream(request, resultSchema, options);
|
|
36870
|
+
}
|
|
36871
|
+
}
|
|
36872
|
+
|
|
36873
|
+
// node_modules/@modelcontextprotocol/sdk/dist/esm/client/index.js
|
|
36874
|
+
init_helpers();
|
|
36875
|
+
function applyElicitationDefaults(schema, data) {
|
|
36876
|
+
if (!schema || data === null || typeof data !== "object")
|
|
36877
|
+
return;
|
|
36878
|
+
if (schema.type === "object" && schema.properties && typeof schema.properties === "object") {
|
|
36879
|
+
const obj = data;
|
|
36880
|
+
const props = schema.properties;
|
|
36881
|
+
for (const key of Object.keys(props)) {
|
|
36882
|
+
const propSchema = props[key];
|
|
36883
|
+
if (obj[key] === undefined && Object.prototype.hasOwnProperty.call(propSchema, "default")) {
|
|
36884
|
+
obj[key] = propSchema.default;
|
|
36885
|
+
}
|
|
36886
|
+
if (obj[key] !== undefined) {
|
|
36887
|
+
applyElicitationDefaults(propSchema, obj[key]);
|
|
36888
|
+
}
|
|
36889
|
+
}
|
|
36890
|
+
}
|
|
36891
|
+
if (Array.isArray(schema.anyOf)) {
|
|
36892
|
+
for (const sub of schema.anyOf) {
|
|
36893
|
+
if (typeof sub !== "boolean") {
|
|
36894
|
+
applyElicitationDefaults(sub, data);
|
|
36895
|
+
}
|
|
36896
|
+
}
|
|
36897
|
+
}
|
|
36898
|
+
if (Array.isArray(schema.oneOf)) {
|
|
36899
|
+
for (const sub of schema.oneOf) {
|
|
36900
|
+
if (typeof sub !== "boolean") {
|
|
36901
|
+
applyElicitationDefaults(sub, data);
|
|
36902
|
+
}
|
|
36903
|
+
}
|
|
36904
|
+
}
|
|
36905
|
+
}
|
|
36906
|
+
function getSupportedElicitationModes(capabilities) {
|
|
36907
|
+
if (!capabilities) {
|
|
36908
|
+
return { supportsFormMode: false, supportsUrlMode: false };
|
|
36909
|
+
}
|
|
36910
|
+
const hasFormCapability = capabilities.form !== undefined;
|
|
36911
|
+
const hasUrlCapability = capabilities.url !== undefined;
|
|
36912
|
+
const supportsFormMode = hasFormCapability || !hasFormCapability && !hasUrlCapability;
|
|
36913
|
+
const supportsUrlMode = hasUrlCapability;
|
|
36914
|
+
return { supportsFormMode, supportsUrlMode };
|
|
36915
|
+
}
|
|
36916
|
+
|
|
36917
|
+
class Client extends Protocol {
|
|
36918
|
+
constructor(_clientInfo, options) {
|
|
36919
|
+
super(options);
|
|
36920
|
+
this._clientInfo = _clientInfo;
|
|
36921
|
+
this._cachedToolOutputValidators = new Map;
|
|
36922
|
+
this._cachedKnownTaskTools = new Set;
|
|
36923
|
+
this._cachedRequiredTaskTools = new Set;
|
|
36924
|
+
this._listChangedDebounceTimers = new Map;
|
|
36925
|
+
this._capabilities = options?.capabilities ?? {};
|
|
36926
|
+
this._jsonSchemaValidator = options?.jsonSchemaValidator ?? new AjvJsonSchemaValidator;
|
|
36927
|
+
if (options?.listChanged) {
|
|
36928
|
+
this._pendingListChangedConfig = options.listChanged;
|
|
36929
|
+
}
|
|
36930
|
+
}
|
|
36931
|
+
_setupListChangedHandlers(config) {
|
|
36932
|
+
if (config.tools && this._serverCapabilities?.tools?.listChanged) {
|
|
36933
|
+
this._setupListChangedHandler("tools", ToolListChangedNotificationSchema, config.tools, async () => {
|
|
36934
|
+
const result = await this.listTools();
|
|
36935
|
+
return result.tools;
|
|
36936
|
+
});
|
|
36937
|
+
}
|
|
36938
|
+
if (config.prompts && this._serverCapabilities?.prompts?.listChanged) {
|
|
36939
|
+
this._setupListChangedHandler("prompts", PromptListChangedNotificationSchema, config.prompts, async () => {
|
|
36940
|
+
const result = await this.listPrompts();
|
|
36941
|
+
return result.prompts;
|
|
36942
|
+
});
|
|
36943
|
+
}
|
|
36944
|
+
if (config.resources && this._serverCapabilities?.resources?.listChanged) {
|
|
36945
|
+
this._setupListChangedHandler("resources", ResourceListChangedNotificationSchema, config.resources, async () => {
|
|
36946
|
+
const result = await this.listResources();
|
|
36947
|
+
return result.resources;
|
|
36948
|
+
});
|
|
36949
|
+
}
|
|
36950
|
+
}
|
|
36951
|
+
get experimental() {
|
|
36952
|
+
if (!this._experimental) {
|
|
36953
|
+
this._experimental = {
|
|
36954
|
+
tasks: new ExperimentalClientTasks(this)
|
|
36955
|
+
};
|
|
36956
|
+
}
|
|
36957
|
+
return this._experimental;
|
|
36958
|
+
}
|
|
36959
|
+
registerCapabilities(capabilities) {
|
|
36960
|
+
if (this.transport) {
|
|
36961
|
+
throw new Error("Cannot register capabilities after connecting to transport");
|
|
36962
|
+
}
|
|
36963
|
+
this._capabilities = mergeCapabilities(this._capabilities, capabilities);
|
|
36964
|
+
}
|
|
36965
|
+
setRequestHandler(requestSchema, handler) {
|
|
36966
|
+
const shape = getObjectShape(requestSchema);
|
|
36967
|
+
const methodSchema = shape?.method;
|
|
36968
|
+
if (!methodSchema) {
|
|
36969
|
+
throw new Error("Schema is missing a method literal");
|
|
36970
|
+
}
|
|
36971
|
+
const methodValue = getLiteralValue(methodSchema);
|
|
36972
|
+
if (typeof methodValue !== "string") {
|
|
36973
|
+
throw new Error("Schema method literal must be a string");
|
|
36974
|
+
}
|
|
36975
|
+
const method = methodValue;
|
|
36976
|
+
if (method === "elicitation/create") {
|
|
36977
|
+
const wrappedHandler = async (request, extra) => {
|
|
36978
|
+
const validatedRequest = safeParse(ElicitRequestSchema, request);
|
|
36979
|
+
if (!validatedRequest.success) {
|
|
36980
|
+
const errorMessage = validatedRequest.error instanceof Error ? validatedRequest.error.message : String(validatedRequest.error);
|
|
36981
|
+
throw new McpError(ErrorCode.InvalidParams, `Invalid elicitation request: ${errorMessage}`);
|
|
36982
|
+
}
|
|
36983
|
+
const { params } = validatedRequest.data;
|
|
36984
|
+
params.mode = params.mode ?? "form";
|
|
36985
|
+
const { supportsFormMode, supportsUrlMode } = getSupportedElicitationModes(this._capabilities.elicitation);
|
|
36986
|
+
if (params.mode === "form" && !supportsFormMode) {
|
|
36987
|
+
throw new McpError(ErrorCode.InvalidParams, "Client does not support form-mode elicitation requests");
|
|
36988
|
+
}
|
|
36989
|
+
if (params.mode === "url" && !supportsUrlMode) {
|
|
36990
|
+
throw new McpError(ErrorCode.InvalidParams, "Client does not support URL-mode elicitation requests");
|
|
36991
|
+
}
|
|
36992
|
+
const result = await Promise.resolve(handler(request, extra));
|
|
36993
|
+
if (params.task) {
|
|
36994
|
+
const taskValidationResult = safeParse(CreateTaskResultSchema, result);
|
|
36995
|
+
if (!taskValidationResult.success) {
|
|
36996
|
+
const errorMessage = taskValidationResult.error instanceof Error ? taskValidationResult.error.message : String(taskValidationResult.error);
|
|
36997
|
+
throw new McpError(ErrorCode.InvalidParams, `Invalid task creation result: ${errorMessage}`);
|
|
36998
|
+
}
|
|
36999
|
+
return taskValidationResult.data;
|
|
37000
|
+
}
|
|
37001
|
+
const validationResult = safeParse(ElicitResultSchema, result);
|
|
37002
|
+
if (!validationResult.success) {
|
|
37003
|
+
const errorMessage = validationResult.error instanceof Error ? validationResult.error.message : String(validationResult.error);
|
|
37004
|
+
throw new McpError(ErrorCode.InvalidParams, `Invalid elicitation result: ${errorMessage}`);
|
|
37005
|
+
}
|
|
37006
|
+
const validatedResult = validationResult.data;
|
|
37007
|
+
const requestedSchema = params.mode === "form" ? params.requestedSchema : undefined;
|
|
37008
|
+
if (params.mode === "form" && validatedResult.action === "accept" && validatedResult.content && requestedSchema) {
|
|
37009
|
+
if (this._capabilities.elicitation?.form?.applyDefaults) {
|
|
37010
|
+
try {
|
|
37011
|
+
applyElicitationDefaults(requestedSchema, validatedResult.content);
|
|
37012
|
+
} catch {}
|
|
37013
|
+
}
|
|
37014
|
+
}
|
|
37015
|
+
return validatedResult;
|
|
37016
|
+
};
|
|
37017
|
+
return super.setRequestHandler(requestSchema, wrappedHandler);
|
|
37018
|
+
}
|
|
37019
|
+
if (method === "sampling/createMessage") {
|
|
37020
|
+
const wrappedHandler = async (request, extra) => {
|
|
37021
|
+
const validatedRequest = safeParse(CreateMessageRequestSchema, request);
|
|
37022
|
+
if (!validatedRequest.success) {
|
|
37023
|
+
const errorMessage = validatedRequest.error instanceof Error ? validatedRequest.error.message : String(validatedRequest.error);
|
|
37024
|
+
throw new McpError(ErrorCode.InvalidParams, `Invalid sampling request: ${errorMessage}`);
|
|
37025
|
+
}
|
|
37026
|
+
const { params } = validatedRequest.data;
|
|
37027
|
+
const result = await Promise.resolve(handler(request, extra));
|
|
37028
|
+
if (params.task) {
|
|
37029
|
+
const taskValidationResult = safeParse(CreateTaskResultSchema, result);
|
|
37030
|
+
if (!taskValidationResult.success) {
|
|
37031
|
+
const errorMessage = taskValidationResult.error instanceof Error ? taskValidationResult.error.message : String(taskValidationResult.error);
|
|
37032
|
+
throw new McpError(ErrorCode.InvalidParams, `Invalid task creation result: ${errorMessage}`);
|
|
37033
|
+
}
|
|
37034
|
+
return taskValidationResult.data;
|
|
37035
|
+
}
|
|
37036
|
+
const hasTools = params.tools || params.toolChoice;
|
|
37037
|
+
const resultSchema = hasTools ? CreateMessageResultWithToolsSchema : CreateMessageResultSchema;
|
|
37038
|
+
const validationResult = safeParse(resultSchema, result);
|
|
37039
|
+
if (!validationResult.success) {
|
|
37040
|
+
const errorMessage = validationResult.error instanceof Error ? validationResult.error.message : String(validationResult.error);
|
|
37041
|
+
throw new McpError(ErrorCode.InvalidParams, `Invalid sampling result: ${errorMessage}`);
|
|
37042
|
+
}
|
|
37043
|
+
return validationResult.data;
|
|
37044
|
+
};
|
|
37045
|
+
return super.setRequestHandler(requestSchema, wrappedHandler);
|
|
37046
|
+
}
|
|
37047
|
+
return super.setRequestHandler(requestSchema, handler);
|
|
37048
|
+
}
|
|
37049
|
+
assertCapability(capability, method) {
|
|
37050
|
+
if (!this._serverCapabilities?.[capability]) {
|
|
37051
|
+
throw new Error(`Server does not support ${capability} (required for ${method})`);
|
|
37052
|
+
}
|
|
37053
|
+
}
|
|
37054
|
+
async connect(transport, options) {
|
|
37055
|
+
await super.connect(transport);
|
|
37056
|
+
if (transport.sessionId !== undefined) {
|
|
37057
|
+
return;
|
|
37058
|
+
}
|
|
37059
|
+
try {
|
|
37060
|
+
const result = await this.request({
|
|
37061
|
+
method: "initialize",
|
|
37062
|
+
params: {
|
|
37063
|
+
protocolVersion: LATEST_PROTOCOL_VERSION,
|
|
37064
|
+
capabilities: this._capabilities,
|
|
37065
|
+
clientInfo: this._clientInfo
|
|
37066
|
+
}
|
|
37067
|
+
}, InitializeResultSchema, options);
|
|
37068
|
+
if (result === undefined) {
|
|
37069
|
+
throw new Error(`Server sent invalid initialize result: ${result}`);
|
|
37070
|
+
}
|
|
37071
|
+
if (!SUPPORTED_PROTOCOL_VERSIONS.includes(result.protocolVersion)) {
|
|
37072
|
+
throw new Error(`Server's protocol version is not supported: ${result.protocolVersion}`);
|
|
37073
|
+
}
|
|
37074
|
+
this._serverCapabilities = result.capabilities;
|
|
37075
|
+
this._serverVersion = result.serverInfo;
|
|
37076
|
+
if (transport.setProtocolVersion) {
|
|
37077
|
+
transport.setProtocolVersion(result.protocolVersion);
|
|
37078
|
+
}
|
|
37079
|
+
this._instructions = result.instructions;
|
|
37080
|
+
await this.notification({
|
|
37081
|
+
method: "notifications/initialized"
|
|
37082
|
+
});
|
|
37083
|
+
if (this._pendingListChangedConfig) {
|
|
37084
|
+
this._setupListChangedHandlers(this._pendingListChangedConfig);
|
|
37085
|
+
this._pendingListChangedConfig = undefined;
|
|
37086
|
+
}
|
|
37087
|
+
} catch (error) {
|
|
37088
|
+
this.close();
|
|
37089
|
+
throw error;
|
|
37090
|
+
}
|
|
37091
|
+
}
|
|
37092
|
+
getServerCapabilities() {
|
|
37093
|
+
return this._serverCapabilities;
|
|
37094
|
+
}
|
|
37095
|
+
getServerVersion() {
|
|
37096
|
+
return this._serverVersion;
|
|
37097
|
+
}
|
|
37098
|
+
getInstructions() {
|
|
37099
|
+
return this._instructions;
|
|
37100
|
+
}
|
|
37101
|
+
assertCapabilityForMethod(method) {
|
|
37102
|
+
switch (method) {
|
|
37103
|
+
case "logging/setLevel":
|
|
37104
|
+
if (!this._serverCapabilities?.logging) {
|
|
37105
|
+
throw new Error(`Server does not support logging (required for ${method})`);
|
|
37106
|
+
}
|
|
37107
|
+
break;
|
|
37108
|
+
case "prompts/get":
|
|
37109
|
+
case "prompts/list":
|
|
37110
|
+
if (!this._serverCapabilities?.prompts) {
|
|
37111
|
+
throw new Error(`Server does not support prompts (required for ${method})`);
|
|
37112
|
+
}
|
|
37113
|
+
break;
|
|
37114
|
+
case "resources/list":
|
|
37115
|
+
case "resources/templates/list":
|
|
37116
|
+
case "resources/read":
|
|
37117
|
+
case "resources/subscribe":
|
|
37118
|
+
case "resources/unsubscribe":
|
|
37119
|
+
if (!this._serverCapabilities?.resources) {
|
|
37120
|
+
throw new Error(`Server does not support resources (required for ${method})`);
|
|
37121
|
+
}
|
|
37122
|
+
if (method === "resources/subscribe" && !this._serverCapabilities.resources.subscribe) {
|
|
37123
|
+
throw new Error(`Server does not support resource subscriptions (required for ${method})`);
|
|
37124
|
+
}
|
|
37125
|
+
break;
|
|
37126
|
+
case "tools/call":
|
|
37127
|
+
case "tools/list":
|
|
37128
|
+
if (!this._serverCapabilities?.tools) {
|
|
37129
|
+
throw new Error(`Server does not support tools (required for ${method})`);
|
|
37130
|
+
}
|
|
37131
|
+
break;
|
|
37132
|
+
case "completion/complete":
|
|
37133
|
+
if (!this._serverCapabilities?.completions) {
|
|
37134
|
+
throw new Error(`Server does not support completions (required for ${method})`);
|
|
37135
|
+
}
|
|
37136
|
+
break;
|
|
37137
|
+
case "initialize":
|
|
37138
|
+
break;
|
|
37139
|
+
case "ping":
|
|
37140
|
+
break;
|
|
37141
|
+
}
|
|
37142
|
+
}
|
|
37143
|
+
assertNotificationCapability(method) {
|
|
37144
|
+
switch (method) {
|
|
37145
|
+
case "notifications/roots/list_changed":
|
|
37146
|
+
if (!this._capabilities.roots?.listChanged) {
|
|
37147
|
+
throw new Error(`Client does not support roots list changed notifications (required for ${method})`);
|
|
37148
|
+
}
|
|
37149
|
+
break;
|
|
37150
|
+
case "notifications/initialized":
|
|
37151
|
+
break;
|
|
37152
|
+
case "notifications/cancelled":
|
|
37153
|
+
break;
|
|
37154
|
+
case "notifications/progress":
|
|
37155
|
+
break;
|
|
37156
|
+
}
|
|
37157
|
+
}
|
|
37158
|
+
assertRequestHandlerCapability(method) {
|
|
37159
|
+
if (!this._capabilities) {
|
|
37160
|
+
return;
|
|
37161
|
+
}
|
|
37162
|
+
switch (method) {
|
|
37163
|
+
case "sampling/createMessage":
|
|
37164
|
+
if (!this._capabilities.sampling) {
|
|
37165
|
+
throw new Error(`Client does not support sampling capability (required for ${method})`);
|
|
37166
|
+
}
|
|
37167
|
+
break;
|
|
37168
|
+
case "elicitation/create":
|
|
37169
|
+
if (!this._capabilities.elicitation) {
|
|
37170
|
+
throw new Error(`Client does not support elicitation capability (required for ${method})`);
|
|
37171
|
+
}
|
|
37172
|
+
break;
|
|
37173
|
+
case "roots/list":
|
|
37174
|
+
if (!this._capabilities.roots) {
|
|
37175
|
+
throw new Error(`Client does not support roots capability (required for ${method})`);
|
|
37176
|
+
}
|
|
37177
|
+
break;
|
|
37178
|
+
case "tasks/get":
|
|
37179
|
+
case "tasks/list":
|
|
37180
|
+
case "tasks/result":
|
|
37181
|
+
case "tasks/cancel":
|
|
37182
|
+
if (!this._capabilities.tasks) {
|
|
37183
|
+
throw new Error(`Client does not support tasks capability (required for ${method})`);
|
|
37184
|
+
}
|
|
37185
|
+
break;
|
|
37186
|
+
case "ping":
|
|
37187
|
+
break;
|
|
37188
|
+
}
|
|
37189
|
+
}
|
|
37190
|
+
assertTaskCapability(method) {
|
|
37191
|
+
assertToolsCallTaskCapability(this._serverCapabilities?.tasks?.requests, method, "Server");
|
|
37192
|
+
}
|
|
37193
|
+
assertTaskHandlerCapability(method) {
|
|
37194
|
+
if (!this._capabilities) {
|
|
37195
|
+
return;
|
|
37196
|
+
}
|
|
37197
|
+
assertClientRequestTaskCapability(this._capabilities.tasks?.requests, method, "Client");
|
|
37198
|
+
}
|
|
37199
|
+
async ping(options) {
|
|
37200
|
+
return this.request({ method: "ping" }, EmptyResultSchema, options);
|
|
37201
|
+
}
|
|
37202
|
+
async complete(params, options) {
|
|
37203
|
+
return this.request({ method: "completion/complete", params }, CompleteResultSchema, options);
|
|
37204
|
+
}
|
|
37205
|
+
async setLoggingLevel(level, options) {
|
|
37206
|
+
return this.request({ method: "logging/setLevel", params: { level } }, EmptyResultSchema, options);
|
|
37207
|
+
}
|
|
37208
|
+
async getPrompt(params, options) {
|
|
37209
|
+
return this.request({ method: "prompts/get", params }, GetPromptResultSchema, options);
|
|
37210
|
+
}
|
|
37211
|
+
async listPrompts(params, options) {
|
|
37212
|
+
return this.request({ method: "prompts/list", params }, ListPromptsResultSchema, options);
|
|
37213
|
+
}
|
|
37214
|
+
async listResources(params, options) {
|
|
37215
|
+
return this.request({ method: "resources/list", params }, ListResourcesResultSchema, options);
|
|
37216
|
+
}
|
|
37217
|
+
async listResourceTemplates(params, options) {
|
|
37218
|
+
return this.request({ method: "resources/templates/list", params }, ListResourceTemplatesResultSchema, options);
|
|
37219
|
+
}
|
|
37220
|
+
async readResource(params, options) {
|
|
37221
|
+
return this.request({ method: "resources/read", params }, ReadResourceResultSchema, options);
|
|
37222
|
+
}
|
|
37223
|
+
async subscribeResource(params, options) {
|
|
37224
|
+
return this.request({ method: "resources/subscribe", params }, EmptyResultSchema, options);
|
|
37225
|
+
}
|
|
37226
|
+
async unsubscribeResource(params, options) {
|
|
37227
|
+
return this.request({ method: "resources/unsubscribe", params }, EmptyResultSchema, options);
|
|
37228
|
+
}
|
|
37229
|
+
async callTool(params, resultSchema = CallToolResultSchema, options) {
|
|
37230
|
+
if (this.isToolTaskRequired(params.name)) {
|
|
37231
|
+
throw new McpError(ErrorCode.InvalidRequest, `Tool "${params.name}" requires task-based execution. Use client.experimental.tasks.callToolStream() instead.`);
|
|
37232
|
+
}
|
|
37233
|
+
const result = await this.request({ method: "tools/call", params }, resultSchema, options);
|
|
37234
|
+
const validator = this.getToolOutputValidator(params.name);
|
|
37235
|
+
if (validator) {
|
|
37236
|
+
if (!result.structuredContent && !result.isError) {
|
|
37237
|
+
throw new McpError(ErrorCode.InvalidRequest, `Tool ${params.name} has an output schema but did not return structured content`);
|
|
37238
|
+
}
|
|
37239
|
+
if (result.structuredContent) {
|
|
37240
|
+
try {
|
|
37241
|
+
const validationResult = validator(result.structuredContent);
|
|
37242
|
+
if (!validationResult.valid) {
|
|
37243
|
+
throw new McpError(ErrorCode.InvalidParams, `Structured content does not match the tool's output schema: ${validationResult.errorMessage}`);
|
|
37244
|
+
}
|
|
37245
|
+
} catch (error) {
|
|
37246
|
+
if (error instanceof McpError) {
|
|
37247
|
+
throw error;
|
|
37248
|
+
}
|
|
37249
|
+
throw new McpError(ErrorCode.InvalidParams, `Failed to validate structured content: ${error instanceof Error ? error.message : String(error)}`);
|
|
37250
|
+
}
|
|
37251
|
+
}
|
|
37252
|
+
}
|
|
37253
|
+
return result;
|
|
37254
|
+
}
|
|
37255
|
+
isToolTask(toolName) {
|
|
37256
|
+
if (!this._serverCapabilities?.tasks?.requests?.tools?.call) {
|
|
37257
|
+
return false;
|
|
37258
|
+
}
|
|
37259
|
+
return this._cachedKnownTaskTools.has(toolName);
|
|
37260
|
+
}
|
|
37261
|
+
isToolTaskRequired(toolName) {
|
|
37262
|
+
return this._cachedRequiredTaskTools.has(toolName);
|
|
37263
|
+
}
|
|
37264
|
+
cacheToolMetadata(tools) {
|
|
37265
|
+
this._cachedToolOutputValidators.clear();
|
|
37266
|
+
this._cachedKnownTaskTools.clear();
|
|
37267
|
+
this._cachedRequiredTaskTools.clear();
|
|
37268
|
+
for (const tool of tools) {
|
|
37269
|
+
if (tool.outputSchema) {
|
|
37270
|
+
const toolValidator = this._jsonSchemaValidator.getValidator(tool.outputSchema);
|
|
37271
|
+
this._cachedToolOutputValidators.set(tool.name, toolValidator);
|
|
37272
|
+
}
|
|
37273
|
+
const taskSupport = tool.execution?.taskSupport;
|
|
37274
|
+
if (taskSupport === "required" || taskSupport === "optional") {
|
|
37275
|
+
this._cachedKnownTaskTools.add(tool.name);
|
|
37276
|
+
}
|
|
37277
|
+
if (taskSupport === "required") {
|
|
37278
|
+
this._cachedRequiredTaskTools.add(tool.name);
|
|
37279
|
+
}
|
|
37280
|
+
}
|
|
37281
|
+
}
|
|
37282
|
+
getToolOutputValidator(toolName) {
|
|
37283
|
+
return this._cachedToolOutputValidators.get(toolName);
|
|
37284
|
+
}
|
|
37285
|
+
async listTools(params, options) {
|
|
37286
|
+
const result = await this.request({ method: "tools/list", params }, ListToolsResultSchema, options);
|
|
37287
|
+
this.cacheToolMetadata(result.tools);
|
|
37288
|
+
return result;
|
|
37289
|
+
}
|
|
37290
|
+
_setupListChangedHandler(listType, notificationSchema, options, fetcher) {
|
|
37291
|
+
const parseResult = ListChangedOptionsBaseSchema.safeParse(options);
|
|
37292
|
+
if (!parseResult.success) {
|
|
37293
|
+
throw new Error(`Invalid ${listType} listChanged options: ${parseResult.error.message}`);
|
|
37294
|
+
}
|
|
37295
|
+
if (typeof options.onChanged !== "function") {
|
|
37296
|
+
throw new Error(`Invalid ${listType} listChanged options: onChanged must be a function`);
|
|
37297
|
+
}
|
|
37298
|
+
const { autoRefresh, debounceMs } = parseResult.data;
|
|
37299
|
+
const { onChanged } = options;
|
|
37300
|
+
const refresh = async () => {
|
|
37301
|
+
if (!autoRefresh) {
|
|
37302
|
+
onChanged(null, null);
|
|
37303
|
+
return;
|
|
37304
|
+
}
|
|
37305
|
+
try {
|
|
37306
|
+
const items = await fetcher();
|
|
37307
|
+
onChanged(null, items);
|
|
37308
|
+
} catch (e) {
|
|
37309
|
+
const error = e instanceof Error ? e : new Error(String(e));
|
|
37310
|
+
onChanged(error, null);
|
|
37311
|
+
}
|
|
37312
|
+
};
|
|
37313
|
+
const handler = () => {
|
|
37314
|
+
if (debounceMs) {
|
|
37315
|
+
const existingTimer = this._listChangedDebounceTimers.get(listType);
|
|
37316
|
+
if (existingTimer) {
|
|
37317
|
+
clearTimeout(existingTimer);
|
|
37318
|
+
}
|
|
37319
|
+
const timer = setTimeout(refresh, debounceMs);
|
|
37320
|
+
this._listChangedDebounceTimers.set(listType, timer);
|
|
37321
|
+
} else {
|
|
37322
|
+
refresh();
|
|
37323
|
+
}
|
|
37324
|
+
};
|
|
37325
|
+
this.setNotificationHandler(notificationSchema, handler);
|
|
37326
|
+
}
|
|
37327
|
+
async sendRootsListChanged() {
|
|
37328
|
+
return this.notification({ method: "notifications/roots/list_changed" });
|
|
37329
|
+
}
|
|
37330
|
+
}
|
|
37331
|
+
|
|
37332
|
+
// node_modules/@modelcontextprotocol/sdk/dist/esm/inMemory.js
|
|
37333
|
+
class InMemoryTransport {
|
|
37334
|
+
constructor() {
|
|
37335
|
+
this._messageQueue = [];
|
|
37336
|
+
}
|
|
37337
|
+
static createLinkedPair() {
|
|
37338
|
+
const clientTransport = new InMemoryTransport;
|
|
37339
|
+
const serverTransport = new InMemoryTransport;
|
|
37340
|
+
clientTransport._otherTransport = serverTransport;
|
|
37341
|
+
serverTransport._otherTransport = clientTransport;
|
|
37342
|
+
return [clientTransport, serverTransport];
|
|
37343
|
+
}
|
|
37344
|
+
async start() {
|
|
37345
|
+
while (this._messageQueue.length > 0) {
|
|
37346
|
+
const queuedMessage = this._messageQueue.shift();
|
|
37347
|
+
this.onmessage?.(queuedMessage.message, queuedMessage.extra);
|
|
37348
|
+
}
|
|
37349
|
+
}
|
|
37350
|
+
async close() {
|
|
37351
|
+
const other = this._otherTransport;
|
|
37352
|
+
this._otherTransport = undefined;
|
|
37353
|
+
await other?.close();
|
|
37354
|
+
this.onclose?.();
|
|
37355
|
+
}
|
|
37356
|
+
async send(message, options) {
|
|
37357
|
+
if (!this._otherTransport) {
|
|
37358
|
+
throw new Error("Not connected");
|
|
37359
|
+
}
|
|
37360
|
+
if (this._otherTransport.onmessage) {
|
|
37361
|
+
this._otherTransport.onmessage(message, { authInfo: options?.authInfo });
|
|
37362
|
+
} else {
|
|
37363
|
+
this._otherTransport._messageQueue.push({ message, extra: { authInfo: options?.authInfo } });
|
|
37364
|
+
}
|
|
37365
|
+
}
|
|
37366
|
+
}
|
|
37367
|
+
|
|
37368
|
+
// src/http/tool-schema-estimate.ts
|
|
37369
|
+
init_server();
|
|
37370
|
+
init_tool_config();
|
|
37371
|
+
var isAlwaysLoad = (tool) => tool._meta?.["anthropic/alwaysLoad"] === true;
|
|
37372
|
+
function measureToolSchemas(tools, loading) {
|
|
37373
|
+
if (loading === "none")
|
|
37374
|
+
return { chars: 0, loadedCount: 0, deferredCount: 0 };
|
|
37375
|
+
const isLoaded = (tool) => {
|
|
37376
|
+
if (loading === "all")
|
|
37377
|
+
return true;
|
|
37378
|
+
if (loading === "core")
|
|
37379
|
+
return CORE_TOOLS.has(tool.name) || isAlwaysLoad(tool);
|
|
37380
|
+
return isAlwaysLoad(tool);
|
|
37381
|
+
};
|
|
37382
|
+
let chars = 0;
|
|
37383
|
+
let loadedCount = 0;
|
|
37384
|
+
for (const tool of tools) {
|
|
37385
|
+
if (isLoaded(tool)) {
|
|
37386
|
+
loadedCount++;
|
|
37387
|
+
chars += JSON.stringify({
|
|
37388
|
+
name: tool.name,
|
|
37389
|
+
description: tool.description ?? "",
|
|
37390
|
+
input_schema: tool.inputSchema
|
|
37391
|
+
}).length;
|
|
37392
|
+
} else {
|
|
37393
|
+
chars += tool.name.length + 1;
|
|
37394
|
+
}
|
|
37395
|
+
}
|
|
37396
|
+
return { chars, loadedCount, deferredCount: tools.length - loadedCount };
|
|
37397
|
+
}
|
|
37398
|
+
async function listSessionTools(opts) {
|
|
37399
|
+
const server = await createServer(opts);
|
|
37400
|
+
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
37401
|
+
await server.connect(serverTransport);
|
|
37402
|
+
const client = new Client({ name: "request-composition-estimate", version: "1" });
|
|
37403
|
+
try {
|
|
37404
|
+
await client.connect(clientTransport);
|
|
37405
|
+
return (await client.listTools()).tools;
|
|
37406
|
+
} finally {
|
|
37407
|
+
await client.close();
|
|
37408
|
+
await server.close();
|
|
37409
|
+
}
|
|
37410
|
+
}
|
|
37411
|
+
var MAX_MEMO_ENTRIES = 32;
|
|
37412
|
+
var toolListMemo = new Map;
|
|
37413
|
+
function listSessionToolsMemo(opts) {
|
|
37414
|
+
const key = JSON.stringify({
|
|
37415
|
+
opts,
|
|
37416
|
+
capabilities: process.env.CAPABILITIES ?? null,
|
|
37417
|
+
chatSdk: process.env.CHAT_SDK_ENABLED ?? null
|
|
37418
|
+
});
|
|
37419
|
+
const cached = toolListMemo.get(key);
|
|
37420
|
+
if (cached)
|
|
37421
|
+
return cached;
|
|
37422
|
+
if (toolListMemo.size >= MAX_MEMO_ENTRIES)
|
|
37423
|
+
toolListMemo.clear();
|
|
37424
|
+
const pending = listSessionTools(opts);
|
|
37425
|
+
toolListMemo.set(key, pending);
|
|
37426
|
+
pending.catch(() => toolListMemo.delete(key));
|
|
37427
|
+
return pending;
|
|
37428
|
+
}
|
|
37429
|
+
|
|
37430
|
+
// src/http/request-composition.ts
|
|
37431
|
+
init_utils2();
|
|
37432
|
+
var PostRequestCompositionResponseSchema = object2({
|
|
37433
|
+
ok: literal2(true),
|
|
37434
|
+
id: uuid(),
|
|
37435
|
+
seq: number2().int().min(0)
|
|
37436
|
+
});
|
|
37437
|
+
var GetRequestCompositionResponseSchema = object2({
|
|
37438
|
+
manifests: array2(RequestCompositionSchema)
|
|
37439
|
+
});
|
|
37440
|
+
var postRequestComposition = route({
|
|
37441
|
+
method: "post",
|
|
37442
|
+
path: "/api/tasks/{id}/request-composition",
|
|
37443
|
+
pattern: ["api", "tasks", null, "request-composition"],
|
|
37444
|
+
session: { taskParam: "id" },
|
|
37445
|
+
rbac: {
|
|
37446
|
+
ungated: "worker session telemetry, same posture as POST /api/tasks/{id}/context"
|
|
37447
|
+
},
|
|
37448
|
+
summary: "Record the request composition manifest of a task session",
|
|
37449
|
+
description: "The worker posts the size of each prompt part it assembled. The server adds the MCP tool-schema estimate for the agent's effective tool surface and stores the manifest as the session's next seq. A `harness-hook` post (pi, opencode) carries exact sizes measured from the request payload plus the call's prompt tokens: the server merges it with the session's worker manifest and folds the observed chars-to-tokens ratio into the provider's average. Only the agent assigned to the task may post, and a task keeps at most 100 manifests.",
|
|
37450
|
+
tags: ["Tasks"],
|
|
37451
|
+
params: object2({ id: string2() }),
|
|
37452
|
+
body: object2({
|
|
37453
|
+
sessionId: string2().min(1),
|
|
37454
|
+
provider: string2().min(1),
|
|
37455
|
+
model: string2().optional(),
|
|
37456
|
+
toolLoading: RequestCompositionToolLoadingSchema,
|
|
37457
|
+
parts: array2(RequestCompositionPartInputSchema).max(200),
|
|
37458
|
+
source: _enum2(["worker", "harness-hook"]).default("worker"),
|
|
37459
|
+
harness: object2({
|
|
37460
|
+
systemChars: number2().int().min(0),
|
|
37461
|
+
payloadChars: number2().int().min(0),
|
|
37462
|
+
promptTokens: number2().int().min(0),
|
|
37463
|
+
firstMessageChars: number2().int().min(0).optional()
|
|
37464
|
+
}).optional()
|
|
37465
|
+
}),
|
|
37466
|
+
responses: {
|
|
37467
|
+
200: { description: "Manifest recorded", schema: PostRequestCompositionResponseSchema },
|
|
37468
|
+
400: { description: "Validation error" },
|
|
37469
|
+
403: { description: "Task is assigned to another agent" },
|
|
37470
|
+
404: { description: "Task not found" },
|
|
37471
|
+
429: { description: "The task already holds the maximum number of manifests" }
|
|
37472
|
+
},
|
|
37473
|
+
auth: { apiKey: true, agentId: true }
|
|
37474
|
+
});
|
|
37475
|
+
var getRequestComposition = route({
|
|
37476
|
+
method: "get",
|
|
37477
|
+
path: "/api/tasks/{id}/request-composition",
|
|
37478
|
+
pattern: ["api", "tasks", null, "request-composition"],
|
|
37479
|
+
session: { taskParam: "id" },
|
|
37480
|
+
summary: "Get the request composition manifests of a task",
|
|
37481
|
+
tags: ["Tasks"],
|
|
37482
|
+
params: object2({ id: string2() }),
|
|
37483
|
+
query: object2({
|
|
37484
|
+
limit: exports_coerce.number().int().min(1).max(MAX_REQUEST_COMPOSITIONS_PER_TASK).default(MAX_REQUEST_COMPOSITIONS_PER_TASK)
|
|
37485
|
+
}),
|
|
37486
|
+
responses: {
|
|
37487
|
+
200: { description: "Manifests, oldest first", schema: GetRequestCompositionResponseSchema },
|
|
37488
|
+
404: { description: "Task not found" }
|
|
37489
|
+
},
|
|
37490
|
+
auth: { apiKey: true }
|
|
37491
|
+
});
|
|
37492
|
+
var TOOL_SCHEMA_LABELS = {
|
|
37493
|
+
all: "swarm tool schemas",
|
|
37494
|
+
core: "swarm tool schemas (core + preloaded; deferred tools load into history)",
|
|
37495
|
+
preloaded: "swarm tool schemas (preloaded only; deferred tools load into history)"
|
|
37496
|
+
};
|
|
37497
|
+
async function toolSchemaPart(agentId, task, loading) {
|
|
37498
|
+
if (loading === "none")
|
|
37499
|
+
return null;
|
|
37500
|
+
try {
|
|
37501
|
+
const tools = await listSessionToolsMemo(await resolveMcpSessionOptions(agentId, task));
|
|
37502
|
+
const { chars } = measureToolSchemas(tools, loading);
|
|
37503
|
+
return {
|
|
37504
|
+
kind: "tool_schemas",
|
|
37505
|
+
id: "mcp:agent-swarm",
|
|
37506
|
+
label: TOOL_SCHEMA_LABELS[loading],
|
|
37507
|
+
chars,
|
|
37508
|
+
estTokens: estimateTokens(chars),
|
|
37509
|
+
fidelity: "estimate"
|
|
37510
|
+
};
|
|
37511
|
+
} catch (err) {
|
|
37512
|
+
console.warn(`[request-composition] Tool schema estimate failed: ${err instanceof Error ? err.message : err}`);
|
|
37513
|
+
return null;
|
|
37514
|
+
}
|
|
37515
|
+
}
|
|
37516
|
+
var SYSTEM_PROMPT_KINDS = new Set([
|
|
37517
|
+
"system_section",
|
|
37518
|
+
"persona",
|
|
37519
|
+
"claude_md",
|
|
37520
|
+
"operator_prompt"
|
|
37521
|
+
]);
|
|
37522
|
+
function mergeHookParts(hookParts, harness, worker) {
|
|
37523
|
+
const exactPart = (id, label, chars) => ({
|
|
37524
|
+
kind: "system_section",
|
|
37525
|
+
id,
|
|
37526
|
+
label,
|
|
37527
|
+
chars,
|
|
37528
|
+
estTokens: estimateTokens(chars),
|
|
37529
|
+
fidelity: "exact"
|
|
37530
|
+
});
|
|
37531
|
+
const hookSkillsChars = hookParts.filter((part) => part.kind === "skills_listing").reduce((sum, part) => sum + part.chars, 0);
|
|
37532
|
+
const harnessSystemChars = Math.max(0, harness.systemChars - hookSkillsChars);
|
|
37533
|
+
if (!worker) {
|
|
37534
|
+
return [exactPart("harness:system", "system prompt as sent", harnessSystemChars), ...hookParts];
|
|
37535
|
+
}
|
|
37536
|
+
const carried = worker.parts.filter((part) => part.kind !== "tool_schemas" && !(part.kind === "skills_listing" && hookSkillsChars > 0));
|
|
37537
|
+
const ours = carried.filter((part) => SYSTEM_PROMPT_KINDS.has(part.kind)).reduce((sum, part) => sum + part.chars, 0);
|
|
37538
|
+
const baseChars = harnessSystemChars - ours;
|
|
37539
|
+
const messageExtraChars = harness.firstMessageChars === undefined ? 0 : harness.firstMessageChars - carried.filter((part) => part.kind === "task_prompt" || part.kind === "memories").reduce((sum, part) => sum + part.chars, 0);
|
|
37540
|
+
return [
|
|
37541
|
+
...carried,
|
|
37542
|
+
...baseChars > 0 ? [exactPart("harness:base", "harness base prompt", baseChars)] : [],
|
|
37543
|
+
...messageExtraChars > 0 ? [exactPart("harness:messages", "harness context in the first message", messageExtraChars)] : [],
|
|
37544
|
+
...hookParts
|
|
37545
|
+
];
|
|
37546
|
+
}
|
|
37547
|
+
function observedTokenRatio(promptTokens, payloadChars) {
|
|
37548
|
+
if (!(promptTokens > 0) || !(payloadChars > 0))
|
|
37549
|
+
return null;
|
|
37550
|
+
return promptTokens / (payloadChars / 4);
|
|
37551
|
+
}
|
|
37552
|
+
async function handleRequestComposition(req, res, pathSegments, queryParams, myAgentId) {
|
|
37553
|
+
if (postRequestComposition.match(req.method, pathSegments)) {
|
|
37554
|
+
if (!myAgentId) {
|
|
37555
|
+
jsonError(res, "Missing X-Agent-ID header", 400);
|
|
37556
|
+
return true;
|
|
37557
|
+
}
|
|
37558
|
+
const parsed = await postRequestComposition.parse(req, res, pathSegments, queryParams);
|
|
37559
|
+
if (!parsed)
|
|
37560
|
+
return true;
|
|
37561
|
+
const task = await getTaskById2(parsed.params.id);
|
|
37562
|
+
if (!task) {
|
|
37563
|
+
jsonError(res, "Task not found", 404);
|
|
37564
|
+
return true;
|
|
37565
|
+
}
|
|
37566
|
+
if (task.agentId !== myAgentId) {
|
|
37567
|
+
jsonError(res, "Task is assigned to another agent", 403);
|
|
37568
|
+
return true;
|
|
37569
|
+
}
|
|
37570
|
+
const { body } = parsed;
|
|
37571
|
+
let parts = body.parts.map((part) => ({
|
|
37572
|
+
...part,
|
|
37573
|
+
estTokens: estimateTokens(part.chars)
|
|
37574
|
+
}));
|
|
37575
|
+
let tokenRatio;
|
|
37576
|
+
if (body.source === "harness-hook") {
|
|
37577
|
+
if (!body.harness) {
|
|
37578
|
+
jsonError(res, "harness-hook manifests require `harness` totals", 400);
|
|
37579
|
+
return true;
|
|
37580
|
+
}
|
|
37581
|
+
parts = mergeHookParts(parts, body.harness, await getLatestWorkerComposition(body.sessionId));
|
|
37582
|
+
const observed = observedTokenRatio(body.harness.promptTokens, body.harness.payloadChars);
|
|
37583
|
+
if (observed === null) {
|
|
37584
|
+
tokenRatio = await getTokenRatio(body.provider);
|
|
37585
|
+
} else {
|
|
37586
|
+
tokenRatio = clampTokenRatio(observed);
|
|
37587
|
+
await recordTokenRatio(body.provider, observed);
|
|
37588
|
+
}
|
|
37589
|
+
} else {
|
|
37590
|
+
const toolPart = await toolSchemaPart(myAgentId, task, body.toolLoading);
|
|
37591
|
+
if (toolPart)
|
|
37592
|
+
parts.push(toolPart);
|
|
37593
|
+
tokenRatio = await getTokenRatio(body.provider);
|
|
37594
|
+
}
|
|
37595
|
+
const manifest = await createRequestComposition({
|
|
37596
|
+
taskId: task.id,
|
|
37597
|
+
agentId: myAgentId,
|
|
37598
|
+
sessionId: body.sessionId,
|
|
37599
|
+
provider: body.provider,
|
|
37600
|
+
model: body.model,
|
|
37601
|
+
source: body.source,
|
|
37602
|
+
parts,
|
|
37603
|
+
tokenRatio
|
|
37604
|
+
});
|
|
37605
|
+
if (!manifest) {
|
|
37606
|
+
jsonError(res, `Task already holds ${MAX_REQUEST_COMPOSITIONS_PER_TASK} request composition manifests`, 429);
|
|
37607
|
+
return true;
|
|
37608
|
+
}
|
|
37609
|
+
postRequestComposition.respond(res, 200, { ok: true, id: manifest.id, seq: manifest.seq });
|
|
37610
|
+
return true;
|
|
37611
|
+
}
|
|
37612
|
+
if (getRequestComposition.match(req.method, pathSegments)) {
|
|
37613
|
+
const parsed = await getRequestComposition.parse(req, res, pathSegments, queryParams);
|
|
37614
|
+
if (!parsed)
|
|
37615
|
+
return true;
|
|
37616
|
+
const task = await getTaskById2(parsed.params.id);
|
|
37617
|
+
if (!task) {
|
|
37618
|
+
jsonError(res, "Task not found", 404);
|
|
37619
|
+
return true;
|
|
37620
|
+
}
|
|
37621
|
+
const manifests = await getRequestCompositionsByTask(task.id, parsed.query.limit);
|
|
37622
|
+
getRequestComposition.respond(res, 200, { manifests });
|
|
37623
|
+
return true;
|
|
37624
|
+
}
|
|
37625
|
+
return false;
|
|
37626
|
+
}
|
|
37627
|
+
|
|
35327
37628
|
// src/http/rooms.ts
|
|
35328
37629
|
init_zod();
|
|
35329
37630
|
init_auth2();
|
|
@@ -36074,8 +38375,8 @@ function daysBetween(firstDay, lastDay) {
|
|
|
36074
38375
|
}
|
|
36075
38376
|
var sliceCache = new Map;
|
|
36076
38377
|
var SLICE_TTL_MS = 2 * MINUTE_MS;
|
|
36077
|
-
var
|
|
36078
|
-
var FLEET_SLICE_TTL_MS =
|
|
38378
|
+
var HOUR_MS2 = 60 * MINUTE_MS;
|
|
38379
|
+
var FLEET_SLICE_TTL_MS = HOUR_MS2 + 2 * MINUTE_MS;
|
|
36079
38380
|
var FIRST_DAY_SCAN_CONCURRENCY = 2;
|
|
36080
38381
|
var scansInFlight = 0;
|
|
36081
38382
|
var scanWaiters = [];
|
|
@@ -36339,7 +38640,7 @@ async function clipFirstDay(buckets, window, firstDay, fleet, sql = (q, p) => ge
|
|
|
36339
38640
|
const startMs = Date.parse(window.start);
|
|
36340
38641
|
if (window.start === dayStartIso(firstDay))
|
|
36341
38642
|
return false;
|
|
36342
|
-
const sliceStart = fleet ? new Date(Math.floor(startMs /
|
|
38643
|
+
const sliceStart = fleet ? new Date(Math.floor(startMs / HOUR_MS2) * HOUR_MS2).toISOString() : window.start;
|
|
36343
38644
|
const first = buckets.filter((b) => b.day === firstDay);
|
|
36344
38645
|
if (first.length === 0)
|
|
36345
38646
|
return false;
|
|
@@ -36783,7 +39084,7 @@ async function clipScriptFirstDay(jobs, window, firstDay, opts) {
|
|
|
36783
39084
|
const startMs = Date.parse(window.start);
|
|
36784
39085
|
if (window.start === dayStartIso(firstDay))
|
|
36785
39086
|
return false;
|
|
36786
|
-
const sliceStart = fleet ? new Date(Math.floor(startMs /
|
|
39087
|
+
const sliceStart = fleet ? new Date(Math.floor(startMs / HOUR_MS2) * HOUR_MS2).toISOString() : window.start;
|
|
36787
39088
|
if (![...jobs.values()].some((j) => j.days.has(firstDay)))
|
|
36788
39089
|
return false;
|
|
36789
39090
|
const slice = { start: sliceStart, end: dayStartIso(utcDay(startMs + DAY_MS3)) };
|
|
@@ -41534,7 +43835,7 @@ var searchRoute = route({
|
|
|
41534
43835
|
},
|
|
41535
43836
|
rbac: { permission: "script.search" }
|
|
41536
43837
|
});
|
|
41537
|
-
var
|
|
43838
|
+
var deleteRoute3 = route({
|
|
41538
43839
|
method: "delete",
|
|
41539
43840
|
path: "/api/scripts/{name}",
|
|
41540
43841
|
pattern: ["api", "scripts", null],
|
|
@@ -42125,8 +44426,8 @@ async function handleScripts(req, res, pathSegments, queryParams, agentId) {
|
|
|
42125
44426
|
});
|
|
42126
44427
|
return true;
|
|
42127
44428
|
}
|
|
42128
|
-
if (
|
|
42129
|
-
const parsed = await
|
|
44429
|
+
if (deleteRoute3.match(req.method, pathSegments)) {
|
|
44430
|
+
const parsed = await deleteRoute3.parse(req, res, pathSegments, queryParams);
|
|
42130
44431
|
if (!parsed)
|
|
42131
44432
|
return true;
|
|
42132
44433
|
const agent = await requireAgent2(res, agentId);
|
|
@@ -42165,7 +44466,7 @@ async function handleScripts(req, res, pathSegments, queryParams, agentId) {
|
|
|
42165
44466
|
}, 409);
|
|
42166
44467
|
return true;
|
|
42167
44468
|
}
|
|
42168
|
-
|
|
44469
|
+
deleteRoute3.respond(res, 200, { deleted: outcome.deleted });
|
|
42169
44470
|
return true;
|
|
42170
44471
|
}
|
|
42171
44472
|
if (createScriptApiRoute.match(req.method, pathSegments)) {
|
|
@@ -42738,7 +45039,7 @@ init_bus();
|
|
|
42738
45039
|
|
|
42739
45040
|
// src/slack/channel-labels.ts
|
|
42740
45041
|
init_session_labels();
|
|
42741
|
-
|
|
45042
|
+
init_app4();
|
|
42742
45043
|
init_render_v2();
|
|
42743
45044
|
var LABEL_TTL_MS = 24 * 60 * 60 * 1000;
|
|
42744
45045
|
var FAILURE_TTL_MS = 10 * 60 * 1000;
|
|
@@ -42985,7 +45286,8 @@ var mintAgentTokenRoute = route({
|
|
|
42985
45286
|
},
|
|
42986
45287
|
403: { description: "Operator or user credentials required" },
|
|
42987
45288
|
404: { description: "Agent not found and no name given" },
|
|
42988
|
-
409: { description: "Agent already holds an active token" }
|
|
45289
|
+
409: { description: "Agent already holds an active token" },
|
|
45290
|
+
410: { description: "An operator deleted this agent id (`agent_deleted`); restore it first" }
|
|
42989
45291
|
},
|
|
42990
45292
|
rbac: { permission: "agent.token.manage" }
|
|
42991
45293
|
});
|
|
@@ -43102,8 +45404,14 @@ async function handleAgentTokens(req, res, pathSegments, queryParams) {
|
|
|
43102
45404
|
}).catch((error) => {
|
|
43103
45405
|
if (error instanceof AgentTokenExistsError)
|
|
43104
45406
|
return { status: 409 };
|
|
45407
|
+
if (error instanceof AgentDeletedError2)
|
|
45408
|
+
return { status: 410 };
|
|
43105
45409
|
throw error;
|
|
43106
45410
|
});
|
|
45411
|
+
if (result.status === 410) {
|
|
45412
|
+
jsonError(res, "agent_deleted", 410);
|
|
45413
|
+
return true;
|
|
45414
|
+
}
|
|
43107
45415
|
if (result.status === 404) {
|
|
43108
45416
|
jsonError(res, "Agent not found; pass name to create it", 404);
|
|
43109
45417
|
return true;
|
|
@@ -44984,7 +47292,7 @@ async function handleSkills(req, res, pathSegments, queryParams, myAgentId) {
|
|
|
44984
47292
|
}
|
|
44985
47293
|
|
|
44986
47294
|
// src/http/slack-events.ts
|
|
44987
|
-
|
|
47295
|
+
init_app4();
|
|
44988
47296
|
init_config4();
|
|
44989
47297
|
init_route_def();
|
|
44990
47298
|
init_utils2();
|
|
@@ -45014,7 +47322,7 @@ var slackEventsRoute = route({
|
|
|
45014
47322
|
}
|
|
45015
47323
|
});
|
|
45016
47324
|
var SLACK_EVENTS_MAX_BODY_BYTES = 1024 * 1024;
|
|
45017
|
-
function
|
|
47325
|
+
function header3(req, name) {
|
|
45018
47326
|
const value = req.headers[name];
|
|
45019
47327
|
return Array.isArray(value) ? value[0] : value;
|
|
45020
47328
|
}
|
|
@@ -45054,11 +47362,11 @@ async function handleSlackEvents(req, res, pathSegments) {
|
|
|
45054
47362
|
return true;
|
|
45055
47363
|
const result = await receiver.handle({
|
|
45056
47364
|
rawBody: Buffer.concat(chunks),
|
|
45057
|
-
signature:
|
|
45058
|
-
timestamp:
|
|
45059
|
-
contentType:
|
|
45060
|
-
retryNum:
|
|
45061
|
-
retryReason:
|
|
47365
|
+
signature: header3(req, "x-slack-signature"),
|
|
47366
|
+
timestamp: header3(req, "x-slack-request-timestamp"),
|
|
47367
|
+
contentType: header3(req, "content-type"),
|
|
47368
|
+
retryNum: header3(req, "x-slack-retry-num"),
|
|
47369
|
+
retryReason: header3(req, "x-slack-retry-reason"),
|
|
45062
47370
|
signingSecret: process.env.SLACK_SIGNING_SECRET
|
|
45063
47371
|
});
|
|
45064
47372
|
res.writeHead(result.status, {
|
|
@@ -45651,7 +47959,7 @@ var toolHookRoute = route({
|
|
|
45651
47959
|
400: { description: "Invalid body or missing X-Agent-ID header" }
|
|
45652
47960
|
}
|
|
45653
47961
|
});
|
|
45654
|
-
function
|
|
47962
|
+
function header4(req, name) {
|
|
45655
47963
|
const raw = req.headers[name];
|
|
45656
47964
|
return Array.isArray(raw) ? raw[0] : raw;
|
|
45657
47965
|
}
|
|
@@ -45669,9 +47977,9 @@ async function handleToolHooks(req, res, pathSegments, queryParams, myAgentId) {
|
|
|
45669
47977
|
const requestInfo = {
|
|
45670
47978
|
sessionId: undefined,
|
|
45671
47979
|
agentId: myAgentId,
|
|
45672
|
-
runtimeInstanceId:
|
|
45673
|
-
sourceTaskId:
|
|
45674
|
-
contextKey:
|
|
47980
|
+
runtimeInstanceId: header4(req, "x-runtime-instance-id"),
|
|
47981
|
+
sourceTaskId: header4(req, "x-source-task-id"),
|
|
47982
|
+
contextKey: header4(req, "x-context-key"),
|
|
45675
47983
|
callOrigin: "native",
|
|
45676
47984
|
harness: body.harness
|
|
45677
47985
|
};
|
|
@@ -45713,7 +48021,7 @@ async function handleToolHooks(req, res, pathSegments, queryParams, myAgentId) {
|
|
|
45713
48021
|
// src/http/trackers/jira.ts
|
|
45714
48022
|
init_zod();
|
|
45715
48023
|
init_oauth();
|
|
45716
|
-
|
|
48024
|
+
init_app2();
|
|
45717
48025
|
init_metadata();
|
|
45718
48026
|
init_webhook();
|
|
45719
48027
|
init_webhook_lifecycle();
|
|
@@ -46127,11 +48435,11 @@ async function handleJiraTracker(req, res, pathSegments) {
|
|
|
46127
48435
|
// src/http/trackers/linear.ts
|
|
46128
48436
|
init_zod();
|
|
46129
48437
|
init_oauth();
|
|
46130
|
-
|
|
48438
|
+
init_app3();
|
|
46131
48439
|
|
|
46132
48440
|
// src/linear/webhook.ts
|
|
46133
48441
|
init_sync();
|
|
46134
|
-
import { createHmac, timingSafeEqual } from "node:crypto";
|
|
48442
|
+
import { createHmac as createHmac2, timingSafeEqual as timingSafeEqual2 } from "node:crypto";
|
|
46135
48443
|
var recentDeliveries = new Map;
|
|
46136
48444
|
var DEDUP_TTL_MS = 5 * 60 * 1000;
|
|
46137
48445
|
function cleanupDeliveries() {
|
|
@@ -46142,9 +48450,9 @@ function cleanupDeliveries() {
|
|
|
46142
48450
|
}
|
|
46143
48451
|
}
|
|
46144
48452
|
function verifyLinearWebhook(rawBody, signature, secret) {
|
|
46145
|
-
const expected =
|
|
48453
|
+
const expected = createHmac2("sha256", secret).update(rawBody).digest("hex");
|
|
46146
48454
|
try {
|
|
46147
|
-
return
|
|
48455
|
+
return timingSafeEqual2(Buffer.from(signature), Buffer.from(expected));
|
|
46148
48456
|
} catch {
|
|
46149
48457
|
return false;
|
|
46150
48458
|
}
|
|
@@ -46459,45 +48767,6 @@ init_rbac_roles();
|
|
|
46459
48767
|
init_users();
|
|
46460
48768
|
init_rbac();
|
|
46461
48769
|
init_types5();
|
|
46462
|
-
|
|
46463
|
-
// src/http/operator-actor.ts
|
|
46464
|
-
init_users();
|
|
46465
|
-
init_api_key();
|
|
46466
|
-
init_request_auth_context();
|
|
46467
|
-
init_request_principal();
|
|
46468
|
-
init_utils2();
|
|
46469
|
-
function extractBearer2(req) {
|
|
46470
|
-
const raw = req.headers.authorization;
|
|
46471
|
-
const header = Array.isArray(raw) ? raw[0] : raw;
|
|
46472
|
-
if (!header || !header.startsWith("Bearer "))
|
|
46473
|
-
return null;
|
|
46474
|
-
return header.slice(7);
|
|
46475
|
-
}
|
|
46476
|
-
function getOperatorActor(req, res) {
|
|
46477
|
-
if (rejectGuest(req, res))
|
|
46478
|
-
return null;
|
|
46479
|
-
const auth = getRequestAuth(req);
|
|
46480
|
-
const userId = authUserId(auth);
|
|
46481
|
-
if (userId) {
|
|
46482
|
-
const tokenId = auth?.kind === "user" ? auth.tokenId : undefined;
|
|
46483
|
-
return tokenId ? { kind: "user", id: userId, tokenId } : { kind: "user", id: userId };
|
|
46484
|
-
}
|
|
46485
|
-
if (isOperatorAuth(auth)) {
|
|
46486
|
-
return { kind: "operator", id: auth.fingerprint };
|
|
46487
|
-
}
|
|
46488
|
-
const rawKey = extractBearer2(req);
|
|
46489
|
-
const swarmKey = getApiKey();
|
|
46490
|
-
if (!swarmKey) {
|
|
46491
|
-
return { kind: "operator", id: fingerprintApiKey("") };
|
|
46492
|
-
}
|
|
46493
|
-
if (!rawKey || rawKey !== swarmKey) {
|
|
46494
|
-
jsonError(res, "Unauthorized", 401);
|
|
46495
|
-
return null;
|
|
46496
|
-
}
|
|
46497
|
-
return { kind: "operator", id: fingerprintApiKey(rawKey) };
|
|
46498
|
-
}
|
|
46499
|
-
|
|
46500
|
-
// src/http/user-roles.ts
|
|
46501
48770
|
init_request_principal();
|
|
46502
48771
|
init_route_def();
|
|
46503
48772
|
init_utils2();
|
|
@@ -48005,11 +50274,11 @@ init_agentmail();
|
|
|
48005
50274
|
// src/agentmail/inbound-archive.ts
|
|
48006
50275
|
init_db4();
|
|
48007
50276
|
init_secret_scrubber();
|
|
48008
|
-
import { createHash as
|
|
50277
|
+
import { createHash as createHash5 } from "node:crypto";
|
|
48009
50278
|
var INBOUND_ARCHIVE_NAMESPACE = "agentmail-inbound";
|
|
48010
50279
|
var INBOUND_ARCHIVE_TTL_MS = 30 * 24 * 60 * 60 * 1000;
|
|
48011
50280
|
var text = (value, limit) => typeof value === "string" ? scrubSecrets(value).slice(0, limit) : "";
|
|
48012
|
-
var inboundArchiveKey = (inboxId, messageId) =>
|
|
50281
|
+
var inboundArchiveKey = (inboxId, messageId) => createHash5("sha256").update(JSON.stringify([inboxId, messageId])).digest("hex");
|
|
48013
50282
|
async function archiveInboundMessage(payload) {
|
|
48014
50283
|
if (![
|
|
48015
50284
|
"message.received",
|
|
@@ -49166,6 +51435,7 @@ init_types5();
|
|
|
49166
51435
|
init_workflows();
|
|
49167
51436
|
init_definition2();
|
|
49168
51437
|
init_engine();
|
|
51438
|
+
init_input();
|
|
49169
51439
|
init_json_schema_validator();
|
|
49170
51440
|
init_model_validation();
|
|
49171
51441
|
init_patch_definition();
|
|
@@ -49264,6 +51534,7 @@ var createWorkflowRoute = route({
|
|
|
49264
51534
|
responses: {
|
|
49265
51535
|
201: { description: "Workflow created", schema: WorkflowSaveResponseSchema },
|
|
49266
51536
|
400: { description: "Invalid definition, or a malformed Idempotency-Key" },
|
|
51537
|
+
403: { description: "Env var or secret input requires config.read.secrets" },
|
|
49267
51538
|
409: { description: "Idempotency-Key was already used for a different request" },
|
|
49268
51539
|
410: { description: "The workflow created under this Idempotency-Key was deleted" }
|
|
49269
51540
|
}
|
|
@@ -49315,6 +51586,7 @@ var updateWorkflowRoute = route({
|
|
|
49315
51586
|
schema: WorkflowSaveResponseSchema
|
|
49316
51587
|
},
|
|
49317
51588
|
400: { description: "Invalid definition" },
|
|
51589
|
+
403: { description: "Env var or secret input requires config.read.secrets" },
|
|
49318
51590
|
404: { description: "Workflow not found" }
|
|
49319
51591
|
}
|
|
49320
51592
|
});
|
|
@@ -49332,6 +51604,7 @@ var patchWorkflowRoute = route({
|
|
|
49332
51604
|
schema: WorkflowSaveResponseSchema
|
|
49333
51605
|
},
|
|
49334
51606
|
400: { description: "Invalid patch or resulting definition" },
|
|
51607
|
+
403: { description: "Stored env var or secret input requires config.read.secrets" },
|
|
49335
51608
|
404: { description: "Workflow not found" }
|
|
49336
51609
|
}
|
|
49337
51610
|
});
|
|
@@ -49349,6 +51622,7 @@ var patchWorkflowNodeRoute = route({
|
|
|
49349
51622
|
schema: WorkflowSaveResponseSchema
|
|
49350
51623
|
},
|
|
49351
51624
|
400: { description: "Invalid patch or resulting definition" },
|
|
51625
|
+
403: { description: "Stored env var or secret input requires config.read.secrets" },
|
|
49352
51626
|
404: { description: "Workflow or node not found" }
|
|
49353
51627
|
}
|
|
49354
51628
|
});
|
|
@@ -49531,12 +51805,22 @@ var webhookTriggerRoute = route({
|
|
|
49531
51805
|
auth: { apiKey: false },
|
|
49532
51806
|
responses: {
|
|
49533
51807
|
200: {
|
|
49534
|
-
description: "Delivery skipped
|
|
49535
|
-
schema:
|
|
49536
|
-
|
|
49537
|
-
|
|
49538
|
-
|
|
49539
|
-
|
|
51808
|
+
description: "Delivery skipped after signature verification and before a run was saved. event-not-allowed: the events allowlist missed. filter-not-matched: a header or JSON body field missed. The received value is not echoed for a filter miss.",
|
|
51809
|
+
schema: discriminatedUnion("reason", [
|
|
51810
|
+
object2({
|
|
51811
|
+
skipped: literal2(true),
|
|
51812
|
+
reason: literal2("event-not-allowed"),
|
|
51813
|
+
event: string2().nullable()
|
|
51814
|
+
}),
|
|
51815
|
+
object2({
|
|
51816
|
+
skipped: literal2(true),
|
|
51817
|
+
reason: literal2("filter-not-matched"),
|
|
51818
|
+
match: object2({
|
|
51819
|
+
source: _enum2(["header", "body"]),
|
|
51820
|
+
path: string2()
|
|
51821
|
+
})
|
|
51822
|
+
})
|
|
51823
|
+
])
|
|
49540
51824
|
},
|
|
49541
51825
|
201: { description: "Webhook processed", schema: object2({ runId: string2() }) },
|
|
49542
51826
|
401: { description: "Invalid signature" },
|
|
@@ -49610,11 +51894,19 @@ async function handleWorkflows(req, res, pathSegments, queryParams, myAgentId) {
|
|
|
49610
51894
|
return true;
|
|
49611
51895
|
}
|
|
49612
51896
|
if (result.skipped) {
|
|
49613
|
-
|
|
49614
|
-
|
|
49615
|
-
|
|
49616
|
-
|
|
49617
|
-
|
|
51897
|
+
if (result.reason === "event-not-allowed") {
|
|
51898
|
+
webhookTriggerRoute.respond(res, 200, {
|
|
51899
|
+
skipped: true,
|
|
51900
|
+
reason: result.reason,
|
|
51901
|
+
event: result.event
|
|
51902
|
+
});
|
|
51903
|
+
} else {
|
|
51904
|
+
webhookTriggerRoute.respond(res, 200, {
|
|
51905
|
+
skipped: true,
|
|
51906
|
+
reason: result.reason,
|
|
51907
|
+
match: result.match
|
|
51908
|
+
});
|
|
51909
|
+
}
|
|
49618
51910
|
} else {
|
|
49619
51911
|
webhookTriggerRoute.respond(res, 201, { runId: result.runId });
|
|
49620
51912
|
}
|
|
@@ -49702,6 +51994,11 @@ async function handleWorkflows(req, res, pathSegments, queryParams, myAgentId) {
|
|
|
49702
51994
|
jsonError(res, `Invalid definition: ${modelErrors.join("; ")}`, 400);
|
|
49703
51995
|
return true;
|
|
49704
51996
|
}
|
|
51997
|
+
const refKeys = serverRefInputKeys(parsed.body.input);
|
|
51998
|
+
if (refKeys.length > 0 && await requestSecretReadScope(req) !== "all") {
|
|
51999
|
+
jsonError(res, serverRefInputDeniedMessage(refKeys), 403);
|
|
52000
|
+
return true;
|
|
52001
|
+
}
|
|
49705
52002
|
const trustedUserId = await resolveHttpAuditUserId(req, myAgentId);
|
|
49706
52003
|
let key;
|
|
49707
52004
|
try {
|
|
@@ -49790,6 +52087,7 @@ async function handleWorkflows(req, res, pathSegments, queryParams, myAgentId) {
|
|
|
49790
52087
|
registry: getExecutorRegistry2(),
|
|
49791
52088
|
snapshotAgentId: myAgentId,
|
|
49792
52089
|
snapshotOptional: true,
|
|
52090
|
+
serverRefInputAllowed: await requestSecretReadScope(req) === "all",
|
|
49793
52091
|
updates: { updatedBy: updatedBy0 }
|
|
49794
52092
|
});
|
|
49795
52093
|
if (!result.ok) {
|
|
@@ -49798,6 +52096,10 @@ async function handleWorkflows(req, res, pathSegments, queryParams, myAgentId) {
|
|
|
49798
52096
|
res.end();
|
|
49799
52097
|
return true;
|
|
49800
52098
|
}
|
|
52099
|
+
if (result.reason === "forbidden") {
|
|
52100
|
+
jsonError(res, result.errors.join("; "), 403);
|
|
52101
|
+
return true;
|
|
52102
|
+
}
|
|
49801
52103
|
if (result.reason === "patch") {
|
|
49802
52104
|
jsonError(res, result.errors.join("; "), 404);
|
|
49803
52105
|
return true;
|
|
@@ -49845,6 +52147,7 @@ async function handleWorkflows(req, res, pathSegments, queryParams, myAgentId) {
|
|
|
49845
52147
|
registry: getExecutorRegistry2(),
|
|
49846
52148
|
snapshotAgentId: myAgentId,
|
|
49847
52149
|
snapshotOptional: true,
|
|
52150
|
+
serverRefInputAllowed: await requestSecretReadScope(req) === "all",
|
|
49848
52151
|
updates: updateArgs
|
|
49849
52152
|
});
|
|
49850
52153
|
if (!result.ok) {
|
|
@@ -49853,6 +52156,10 @@ async function handleWorkflows(req, res, pathSegments, queryParams, myAgentId) {
|
|
|
49853
52156
|
res.end();
|
|
49854
52157
|
return true;
|
|
49855
52158
|
}
|
|
52159
|
+
if (result.reason === "forbidden") {
|
|
52160
|
+
jsonError(res, result.errors.join("; "), 403);
|
|
52161
|
+
return true;
|
|
52162
|
+
}
|
|
49856
52163
|
jsonError(res, result.reason === "patch" ? result.errors.join("; ") : `Invalid definition: ${result.errors.join("; ")}`, 400);
|
|
49857
52164
|
return true;
|
|
49858
52165
|
}
|
|
@@ -49891,6 +52198,11 @@ async function handleWorkflows(req, res, pathSegments, queryParams, myAgentId) {
|
|
|
49891
52198
|
return true;
|
|
49892
52199
|
}
|
|
49893
52200
|
}
|
|
52201
|
+
const refKeys = serverRefInputKeys(body.input !== undefined ? body.input : body.definition ? existing.input : undefined);
|
|
52202
|
+
if (refKeys.length > 0 && await requestSecretReadScope(req) !== "all") {
|
|
52203
|
+
jsonError(res, serverRefInputDeniedMessage(refKeys), 403);
|
|
52204
|
+
return true;
|
|
52205
|
+
}
|
|
49894
52206
|
const updatedBy2 = await resolveHttpAuditUserId(req, myAgentId) ?? undefined;
|
|
49895
52207
|
let key;
|
|
49896
52208
|
if (body.key !== undefined) {
|
|
@@ -50133,10 +52445,10 @@ init_secret_scrubber();
|
|
|
50133
52445
|
init_json_schema_validator();
|
|
50134
52446
|
init_route_def();
|
|
50135
52447
|
init_utils2();
|
|
50136
|
-
import { timingSafeEqual as
|
|
52448
|
+
import { timingSafeEqual as timingSafeEqual3 } from "node:crypto";
|
|
50137
52449
|
var DEFAULT_TIMEOUT_MS = 60000;
|
|
50138
52450
|
var TIMEOUT_HEADER = "x-swarm-timeout-ms";
|
|
50139
|
-
var
|
|
52451
|
+
var MAX_BODY_BYTES2 = 1 * 1024 * 1024;
|
|
50140
52452
|
var XScriptErrorSchema = object2({
|
|
50141
52453
|
type: string2(),
|
|
50142
52454
|
message: string2(),
|
|
@@ -50187,7 +52499,7 @@ function timingSafeEqualStr(a, b) {
|
|
|
50187
52499
|
const bb = Buffer.from(b);
|
|
50188
52500
|
if (ab.length !== bb.length)
|
|
50189
52501
|
return false;
|
|
50190
|
-
return
|
|
52502
|
+
return timingSafeEqual3(ab, bb);
|
|
50191
52503
|
}
|
|
50192
52504
|
function resolveTimeoutMs(req) {
|
|
50193
52505
|
const raw = req.headers[TIMEOUT_HEADER];
|
|
@@ -50240,7 +52552,7 @@ async function handleX(req, res, pathSegments) {
|
|
|
50240
52552
|
return true;
|
|
50241
52553
|
}
|
|
50242
52554
|
}
|
|
50243
|
-
if (enforceContentLengthCap(req, res,
|
|
52555
|
+
if (enforceContentLengthCap(req, res, MAX_BODY_BYTES2) === BODY_TOO_LARGE)
|
|
50244
52556
|
return true;
|
|
50245
52557
|
let args;
|
|
50246
52558
|
try {
|
|
@@ -50448,9 +52760,12 @@ var httpServer = createHttpServer(async (req, res) => {
|
|
|
50448
52760
|
() => handleSessionData(req, res, pathSegments, queryParams, myAgentId),
|
|
50449
52761
|
() => handleTrackers(req, res, pathSegments),
|
|
50450
52762
|
() => handleWebhooks(req, res, pathSegments),
|
|
52763
|
+
() => handleObjectWebhooks(req, res, pathSegments),
|
|
52764
|
+
() => handleAgentLifecycle(req, res, pathSegments, queryParams, myAgentId),
|
|
50451
52765
|
() => handleAgentsRest(req, res, pathSegments, queryParams, myAgentId),
|
|
50452
52766
|
() => handleBudgets(req, res, pathSegments, queryParams, myAgentId),
|
|
50453
52767
|
() => handleContext(req, res, pathSegments, queryParams, myAgentId),
|
|
52768
|
+
() => handleRequestComposition(req, res, pathSegments, queryParams, myAgentId),
|
|
50454
52769
|
() => handleAssets(req, res, pathSegments, queryParams, myAgentId),
|
|
50455
52770
|
() => handleTasks(req, res, pathSegments, queryParams, myAgentId),
|
|
50456
52771
|
() => handleStats(req, res, pathSegments, queryParams, myAgentId),
|
|
@@ -50468,6 +52783,7 @@ var httpServer = createHttpServer(async (req, res) => {
|
|
|
50468
52783
|
() => handlePoolKeys(req, res, pathSegments, queryParams),
|
|
50469
52784
|
() => handleConfig(req, res, pathSegments, queryParams),
|
|
50470
52785
|
() => handleFs(req, res, pathSegments, queryParams, myAgentId),
|
|
52786
|
+
() => handleGitHubToken(req, res, pathSegments, myAgentId),
|
|
50471
52787
|
() => handleAgentFsProxy(req, res),
|
|
50472
52788
|
() => handleComb(req, res, pathSegments, queryParams, myAgentId),
|
|
50473
52789
|
() => handleKv(req, res, pathSegments, queryParams),
|
|
@@ -50546,7 +52862,7 @@ var httpServer = createHttpServer(async (req, res) => {
|
|
|
50546
52862
|
});
|
|
50547
52863
|
});
|
|
50548
52864
|
var detachRealtime = attachRealtimeTransport(httpServer);
|
|
50549
|
-
var { attachControllerTransport } = await import("./controllers-connect-
|
|
52865
|
+
var { attachControllerTransport } = await import("./controllers-connect-zn4dg69h.js");
|
|
50550
52866
|
var detachControllers = attachControllerTransport(httpServer);
|
|
50551
52867
|
var stopWorkerNudges = startWorkerNudgeListener();
|
|
50552
52868
|
var taskAutoTitles = startTaskAutoTitleListener();
|
|
@@ -50577,7 +52893,7 @@ async function shutdown() {
|
|
|
50577
52893
|
sessionsProcessed: getServerSessionsProcessed()
|
|
50578
52894
|
});
|
|
50579
52895
|
if (hasCapability("scheduling")) {
|
|
50580
|
-
const { stopScheduler } = await import("./index-
|
|
52896
|
+
const { stopScheduler } = await import("./index-23cdfzr6.js");
|
|
50581
52897
|
stopScheduler();
|
|
50582
52898
|
}
|
|
50583
52899
|
stopHeartbeat2();
|
|
@@ -50589,7 +52905,7 @@ async function shutdown() {
|
|
|
50589
52905
|
await stopSlackApp2();
|
|
50590
52906
|
await stopChatSdk();
|
|
50591
52907
|
if (!isEnvFlagEnabled("OAUTH_KEEPALIVE_DISABLE", false)) {
|
|
50592
|
-
const { stopOAuthKeepalive } = await import("./keepalive-
|
|
52908
|
+
const { stopOAuthKeepalive } = await import("./keepalive-031js8jz.js");
|
|
50593
52909
|
await stopOAuthKeepalive();
|
|
50594
52910
|
}
|
|
50595
52911
|
stopOAuthPendingGc();
|
|
@@ -50648,6 +52964,11 @@ if (!globalState.__runId) {
|
|
|
50648
52964
|
}
|
|
50649
52965
|
startApiGcInterval();
|
|
50650
52966
|
startEventLoopLagProbe();
|
|
52967
|
+
try {
|
|
52968
|
+
await seedDbRetentionDefaults();
|
|
52969
|
+
} catch (err) {
|
|
52970
|
+
console.warn("[startup] Retention defaults seed failed (non-fatal):", scrubSecrets(err instanceof Error ? err.message : String(err)));
|
|
52971
|
+
}
|
|
50651
52972
|
var startupConfigsInjected = [];
|
|
50652
52973
|
try {
|
|
50653
52974
|
startupConfigsInjected = await loadGlobalConfigsIntoEnv2(true);
|
|
@@ -50674,21 +52995,21 @@ try {
|
|
|
50674
52995
|
console.warn("[startup] CAPABILITIES upgrade seed failed (non-fatal):", err);
|
|
50675
52996
|
}
|
|
50676
52997
|
try {
|
|
50677
|
-
const { ensurePricingSeeded } = await import("./boot-seeds-
|
|
52998
|
+
const { ensurePricingSeeded } = await import("./boot-seeds-arrkbe8t.js");
|
|
50678
52999
|
ensurePricingSeeded();
|
|
50679
|
-
const { startPricingRefreshLoop } = await import("./pricing-refresh-
|
|
53000
|
+
const { startPricingRefreshLoop } = await import("./pricing-refresh-9w7gx41w.js");
|
|
50680
53001
|
startPricingRefreshLoop();
|
|
50681
53002
|
} catch (err) {
|
|
50682
53003
|
console.error("[startup] Failed to seed pricing rows:", err);
|
|
50683
53004
|
}
|
|
50684
53005
|
try {
|
|
50685
|
-
const { ensureModelProfilesSeeded } = await import("./boot-seeds-
|
|
53006
|
+
const { ensureModelProfilesSeeded } = await import("./boot-seeds-arrkbe8t.js");
|
|
50686
53007
|
await ensureModelProfilesSeeded();
|
|
50687
53008
|
} catch (err) {
|
|
50688
53009
|
console.error("[startup] Failed to seed model profiles:", err);
|
|
50689
53010
|
}
|
|
50690
53011
|
try {
|
|
50691
|
-
const { ensureRbacSeeded } = await import("./boot-seeds-
|
|
53012
|
+
const { ensureRbacSeeded } = await import("./boot-seeds-arrkbe8t.js");
|
|
50692
53013
|
ensureRbacSeeded();
|
|
50693
53014
|
} catch (err) {
|
|
50694
53015
|
console.error("[startup] Failed to sync RBAC seed rows:", err);
|
|
@@ -50696,13 +53017,13 @@ try {
|
|
|
50696
53017
|
throw err;
|
|
50697
53018
|
}
|
|
50698
53019
|
try {
|
|
50699
|
-
const { runAllSeeders } = await import("./index-
|
|
53020
|
+
const { runAllSeeders } = await import("./index-fbkqhvvj.js");
|
|
50700
53021
|
await runAllSeeders({ scriptEmbeddingMode: "skip" });
|
|
50701
53022
|
} catch (err) {
|
|
50702
53023
|
console.error("[startup] Failed to seed built-in entities:", err);
|
|
50703
53024
|
}
|
|
50704
53025
|
try {
|
|
50705
|
-
const { runImports } = await import("./index-
|
|
53026
|
+
const { runImports } = await import("./index-kn63q1gr.js");
|
|
50706
53027
|
await runImports();
|
|
50707
53028
|
} catch (err) {
|
|
50708
53029
|
console.error("[startup] File import failed:", scrubSecrets(err instanceof Error ? err.message : String(err)));
|
|
@@ -50753,14 +53074,18 @@ httpServer.listen(port, async () => {
|
|
|
50753
53074
|
startChatSdk().catch((err) => {
|
|
50754
53075
|
console.error("[chat-sdk] Failed to start, continuing without Chat SDK:", scrubSecrets(err instanceof Error ? err.message : String(err)));
|
|
50755
53076
|
});
|
|
50756
|
-
import("./agent-fs-provision-
|
|
53077
|
+
import("./agent-fs-provision-0b9awm5n.js").then(({ syncAgentFsOrgSwarmUrl }) => syncAgentFsOrgSwarmUrl(getConfiguredAppUrls()[0])).catch((err) => {
|
|
50757
53078
|
console.warn("[agent-fs] Failed to set the org swarm URL:", scrubSecrets(err instanceof Error ? err.message : String(err)));
|
|
50758
53079
|
});
|
|
53080
|
+
import("./object-webhooks-r24wwb5y.js").then(({ ensureObjectWebhooksForKnownDrives }) => ensureObjectWebhooksForKnownDrives()).catch((err) => {
|
|
53081
|
+
console.warn("[objects] agent-fs webhook boot check failed:", scrubSecrets(err instanceof Error ? err.message : String(err)));
|
|
53082
|
+
});
|
|
50759
53083
|
startQueueStallAlarm();
|
|
50760
53084
|
initGitHub();
|
|
50761
53085
|
initGitLab();
|
|
50762
53086
|
initAzureDevOps();
|
|
50763
53087
|
initAzureDevOpsOutbound();
|
|
53088
|
+
initMcpEventsDispatcher();
|
|
50764
53089
|
initBitbucket();
|
|
50765
53090
|
initAgentMail();
|
|
50766
53091
|
await initLinear();
|
|
@@ -50768,25 +53093,25 @@ httpServer.listen(port, async () => {
|
|
|
50768
53093
|
await initWorkflows2();
|
|
50769
53094
|
await startScriptRunSupervisor(getMcpBaseUrl());
|
|
50770
53095
|
if (hasCapability("scheduling")) {
|
|
50771
|
-
const { startScheduler } = await import("./index-
|
|
50772
|
-
const { getExecutorRegistry } = await import("./index-
|
|
53096
|
+
const { startScheduler } = await import("./index-23cdfzr6.js");
|
|
53097
|
+
const { getExecutorRegistry } = await import("./index-stk36pa5.js");
|
|
50773
53098
|
const intervalMs = Number(process.env.SCHEDULER_INTERVAL_MS) || 1e4;
|
|
50774
53099
|
startScheduler(getExecutorRegistry(), intervalMs, {
|
|
50775
53100
|
runId: globalState.__runId
|
|
50776
53101
|
});
|
|
50777
53102
|
}
|
|
50778
53103
|
if (!isEnvFlagEnabled("HEARTBEAT_DISABLE", false)) {
|
|
50779
|
-
const { parseHeartbeatIntervalMs, startHeartbeat } = await import("./index-
|
|
53104
|
+
const { parseHeartbeatIntervalMs, startHeartbeat } = await import("./index-g7kkjs5b.js");
|
|
50780
53105
|
startHeartbeat(parseHeartbeatIntervalMs(process.env.HEARTBEAT_INTERVAL_MS));
|
|
50781
53106
|
}
|
|
50782
53107
|
startPoolRouting();
|
|
50783
53108
|
startRuntimeSupervisor();
|
|
50784
53109
|
if (!isEnvFlagEnabled("OAUTH_KEEPALIVE_DISABLE", false)) {
|
|
50785
|
-
const { startOAuthKeepalive } = await import("./keepalive-
|
|
53110
|
+
const { startOAuthKeepalive } = await import("./keepalive-031js8jz.js");
|
|
50786
53111
|
startOAuthKeepalive();
|
|
50787
53112
|
}
|
|
50788
53113
|
if (!isEnvFlagEnabled("OAUTH_REFRESH_SWEEP_DISABLE", false)) {
|
|
50789
|
-
const { startOAuthRefreshSweep } = await import("./oauth-refresh-sweep-
|
|
53114
|
+
const { startOAuthRefreshSweep } = await import("./oauth-refresh-sweep-zqmnyvs8.js");
|
|
50790
53115
|
startOAuthRefreshSweep();
|
|
50791
53116
|
}
|
|
50792
53117
|
startOAuthPendingGc();
|
|
@@ -50796,22 +53121,22 @@ httpServer.listen(port, async () => {
|
|
|
50796
53121
|
startSavingsRollup(savingsRollupSql);
|
|
50797
53122
|
startHumanFreeDrain();
|
|
50798
53123
|
startTaskSearchBackfill();
|
|
50799
|
-
import("./embedding-space-
|
|
53124
|
+
import("./embedding-space-kcdn52vz.js").then(({ runEmbeddingMaintenance, setDeploymentEnvReader }) => {
|
|
50800
53125
|
setDeploymentEnvReader(getDeploymentEnvValue2);
|
|
50801
53126
|
return runEmbeddingMaintenance({ backfill: true });
|
|
50802
53127
|
}).catch((err) => {
|
|
50803
53128
|
console.error("[embedding-space] startup maintenance failed (non-fatal):", err);
|
|
50804
53129
|
});
|
|
50805
|
-
import("./boot-args-schema-
|
|
53130
|
+
import("./boot-args-schema-hce1av1h.js").then(({ runBootArgsSchemaBackfill }) => runBootArgsSchemaBackfill()).catch((err) => {
|
|
50806
53131
|
console.error("[boot-args-schema] startup backfill failed (non-fatal):", err);
|
|
50807
53132
|
});
|
|
50808
|
-
import("./boot-scrub-sweep-
|
|
53133
|
+
import("./boot-scrub-sweep-mkmm16gk.js").then(({ runBootScrubSweep }) => runBootScrubSweep()).catch((err) => {
|
|
50809
53134
|
console.error("[boot-scrub-sweep] startup scrub failed (non-fatal):", err);
|
|
50810
53135
|
});
|
|
50811
|
-
import("./user-merge-jobs-
|
|
53136
|
+
import("./user-merge-jobs-f9d8nwnw.js").then(({ resumeUserMergeJobs }) => resumeUserMergeJobs()).catch((err) => {
|
|
50812
53137
|
console.error("[user-merge] startup resume failed (non-fatal):", err);
|
|
50813
53138
|
});
|
|
50814
|
-
import("./session-source-backfill-
|
|
53139
|
+
import("./session-source-backfill-r5j988ah.js").then(({ runSessionSourceBackfill }) => runSessionSourceBackfill()).catch((err) => {
|
|
50815
53140
|
console.error("[session-source-backfill] startup run failed (non-fatal):", err);
|
|
50816
53141
|
});
|
|
50817
53142
|
}).on("error", (err) => {
|