@desplega.ai/agent-swarm 2.13.3 → 2.13.4

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.
Files changed (289) hide show
  1. package/dist/acp-adapter-mr4temec.js +17 -0
  2. package/dist/{acp-targets-k8xs4tj8.js → acp-targets-zrk9k0n7.js} +10 -10
  3. package/dist/{actions-pg5fxjer.js → actions-acqqj9jn.js} +236 -26
  4. package/dist/{agent-fs-provision-vbk3fppw.js → agent-fs-provision-zmaykqnd.js} +4 -4
  5. package/dist/{amp-adapter-adbhxsz9.js → amp-adapter-a7ts8tmw.js} +3 -3
  6. package/dist/{app-b267ggx1.js → app-tmwa442h.js} +7 -7
  7. package/dist/{approval-notifications-evc1a9z5.js → approval-notifications-6psaaaye.js} +8 -8
  8. package/dist/{assistant-wgz2ab84.js → assistant-564v6emv.js} +24 -24
  9. package/dist/{boot-args-schema-6tpk28j4.js → boot-args-schema-n099e0f2.js} +1 -1
  10. package/dist/{boot-reembed-ankp369c.js → boot-reembed-chx66qfk.js} +1 -1
  11. package/dist/{boot-reembed-r1zyvefv.js → boot-reembed-epvg4fp9.js} +1 -1
  12. package/dist/{boot-scrub-sweep-cgb6r5bd.js → boot-scrub-sweep-dhkfp0a7.js} +2 -2
  13. package/dist/{boot-seeds-bjceqg7b.js → boot-seeds-m74fc07r.js} +4 -4
  14. package/dist/{boxd-hr8rsxzq.js → boxd-451q55ys.js} +1 -1
  15. package/dist/{claude-adapter-knztdnff.js → claude-adapter-hw63yj3j.js} +9 -9
  16. package/dist/{claude-managed-adapter-qwejzqkk.js → claude-managed-adapter-z5s7fx6p.js} +3 -3
  17. package/dist/{claude-managed-setup-0vgz4d1j.js → claude-managed-setup-wee1762m.js} +3 -3
  18. package/dist/{claude-sdk-session-c3g6dv0g.js → claude-sdk-session-cktyqkpk.js} +11 -11
  19. package/dist/{cli-7fa6yv98.js → cli-0fgvnb0x.js} +6 -6
  20. package/dist/{cli-2v4xxnx2.js → cli-0h8skzss.js} +1 -1
  21. package/dist/{cli-hhb8kbwd.js → cli-0p76my9q.js} +29 -14
  22. package/dist/{cli-fp65jdp2.js → cli-1kvcsd2f.js} +219 -155
  23. package/dist/{cli-wtffytm8.js → cli-1vmhnncj.js} +3 -3
  24. package/dist/{cli-268b3dgn.js → cli-29h5239w.js} +5 -5
  25. package/dist/{cli-8fj8yfmk.js → cli-2vp0z049.js} +1 -1
  26. package/dist/{cli-bh53ppqm.js → cli-3bxrrh53.js} +4 -4
  27. package/dist/{cli-61fzwtjk.js → cli-3tzmh38q.js} +9 -9
  28. package/dist/{cli-88np9va3.js → cli-3xqad83h.js} +1 -1
  29. package/dist/{cli-gc715jrc.js → cli-3zrwrnz7.js} +1 -1
  30. package/dist/{cli-dw43pnzp.js → cli-404am6f3.js} +7 -7
  31. package/dist/{cli-8pnawt98.js → cli-49aq3cyn.js} +4 -4
  32. package/dist/{cli-fbmgpt72.js → cli-4fpa0zns.js} +3 -3
  33. package/dist/{cli-kwm1bek7.js → cli-4pbwg7sn.js} +2 -2
  34. package/dist/{cli-djwt4mtn.js → cli-4q2c8rxw.js} +9 -9
  35. package/dist/{cli-3mf04tkh.js → cli-4vynxtrb.js} +1 -1
  36. package/dist/{cli-80d5g0fa.js → cli-5ashycw3.js} +3 -3
  37. package/dist/{cli-61p7ty8d.js → cli-5rgm8p39.js} +3 -3
  38. package/dist/{cli-r6xnchva.js → cli-5rxsb3wq.js} +6 -6
  39. package/dist/{cli-a21cwm89.js → cli-60dwk8tx.js} +3 -3
  40. package/dist/{cli-v1v49t36.js → cli-7by7vp6m.js} +2 -2
  41. package/dist/{cli-vgh5adn9.js → cli-7g3fg4gf.js} +7 -7
  42. package/dist/{cli-hxj888w3.js → cli-7gbff32z.js} +2 -2
  43. package/dist/{cli-q8aq48v1.js → cli-8b4rpnwj.js} +1 -1
  44. package/dist/{cli-xc8m5cjn.js → cli-8cas2xvp.js} +3 -3
  45. package/dist/{cli-1606qw3n.js → cli-904wk98s.js} +797 -369
  46. package/dist/{cli-h3drhntp.js → cli-93n305hm.js} +2 -2
  47. package/dist/{cli-1wew39p0.js → cli-944w9wb4.js} +20 -16
  48. package/dist/{cli-je587f74.js → cli-94gx6ze9.js} +1 -1
  49. package/dist/{cli-hpxcfvdm.js → cli-9ah37a8a.js} +6 -6
  50. package/dist/{cli-rfejbpe1.js → cli-akm6y2a8.js} +1 -1
  51. package/dist/{cli-f8rcvf2x.js → cli-azj9t1f9.js} +37 -2
  52. package/dist/{cli-ef590376.js → cli-bv4vvnmg.js} +3 -3
  53. package/dist/{cli-ppf9ap9n.js → cli-bzcwwebm.js} +1 -1
  54. package/dist/{cli-sy2ge2ye.js → cli-cq4am6vg.js} +2 -2
  55. package/dist/{cli-gxqwm3k3.js → cli-d5pc8ep0.js} +102 -8
  56. package/dist/{cli-hd2a204w.js → cli-ea7nz50q.js} +12 -12
  57. package/dist/{cli-zkbz8m2q.js → cli-fkpnx3vf.js} +1 -1
  58. package/dist/{cli-ya1cj689.js → cli-fw67mnyc.js} +1 -1
  59. package/dist/{cli-5basv0e7.js → cli-gkv0r2hq.js} +1 -1
  60. package/dist/{cli-ka4tqjzd.js → cli-gse7bp3z.js} +12 -10
  61. package/dist/{cli-v8rpjrnx.js → cli-gtj12v95.js} +1 -1
  62. package/dist/{cli-g4dhd3pr.js → cli-hdhpdrka.js} +6 -23
  63. package/dist/{cli-dq30fq3q.js → cli-hhtbandk.js} +2 -2
  64. package/dist/cli-hyqksecw.js +1907 -0
  65. package/dist/{cli-t25rq8mg.js → cli-ja450998.js} +40 -11
  66. package/dist/{cli-43dsqhcp.js → cli-jbrc98qb.js} +4 -4
  67. package/dist/{cli-8sayvj48.js → cli-jyhbvdga.js} +3 -3
  68. package/dist/{cli-55fqpd9q.js → cli-jzerrzgc.js} +8 -8
  69. package/dist/{cli-hv3820ez.js → cli-k0nebh10.js} +1 -1
  70. package/dist/{cli-aytna2fm.js → cli-ka48vpev.js} +5 -5
  71. package/dist/{cli-d2epqm0y.js → cli-kezzteka.js} +1 -1
  72. package/dist/{cli-grk77aen.js → cli-kj84fqxz.js} +2 -2
  73. package/dist/{cli-h0ewec3d.js → cli-kr0jpw9c.js} +1 -1
  74. package/dist/{cli-wsnradtk.js → cli-m1sns1da.js} +2 -2
  75. package/dist/{cli-7kv5d674.js → cli-n1kjs58m.js} +4 -4
  76. package/dist/{cli-syqcny89.js → cli-nc4pbwmp.js} +9 -9
  77. package/dist/{cli-9gmkw6xn.js → cli-p3knvk62.js} +48 -42
  78. package/dist/{cli-50whymxq.js → cli-p436yrzp.js} +2 -2
  79. package/dist/{cli-0j4qmc80.js → cli-phdzn699.js} +7 -7
  80. package/dist/{cli-1gnf5c7x.js → cli-pz1dp12c.js} +1 -1
  81. package/dist/{cli-nbawx3s0.js → cli-pz1nq5xm.js} +6 -6
  82. package/dist/{cli-4dyhzhpx.js → cli-qzz6tz8s.js} +1 -1
  83. package/dist/{cli-ea367bdn.js → cli-rmgvwcmy.js} +22 -22
  84. package/dist/{cli-mgr3gatr.js → cli-rv3y60bt.js} +4 -4
  85. package/dist/cli-s33bzmk0.js +27 -0
  86. package/dist/{cli-at67kvnp.js → cli-srktrbby.js} +1 -1
  87. package/dist/{cli-pzsedyb0.js → cli-t0jmkcah.js} +14 -14
  88. package/dist/{cli-eetzmsy5.js → cli-t9pzz2eq.js} +2 -2
  89. package/dist/{cli-w24741sm.js → cli-tr19nyn9.js} +4 -4
  90. package/dist/{cli-e4gx499y.js → cli-ts5yv7dn.js} +163 -86
  91. package/dist/{cli-czeh7x13.js → cli-tsc3pdfd.js} +4 -4
  92. package/dist/{cli-y0q92v4r.js → cli-tzw1jr2t.js} +2 -2
  93. package/dist/{cli-tjf1bh1v.js → cli-x2cem5vy.js} +6 -4
  94. package/dist/{cli-vx9acp12.js → cli-ybte1fqc.js} +1 -1
  95. package/dist/{cli-gkjw33x5.js → cli-ysv0k1we.js} +2 -2
  96. package/dist/{cli-vdfngx2g.js → cli-ywy8yz6t.js} +2 -2
  97. package/dist/{cli-cpkxh68d.js → cli-z1vam71h.js} +2 -2
  98. package/dist/{cli-8m6gqnf1.js → cli-zexwhj3f.js} +3 -3
  99. package/dist/{cli-snwz16eg.js → cli-zhwjdhjr.js} +2 -2
  100. package/dist/{cli-y754psdt.js → cli-zjdhrzm0.js} +4 -4
  101. package/dist/cli.js +19 -19
  102. package/dist/{codex-adapter-493vb8cv.js → codex-adapter-2fs2c0n6.js} +8 -8
  103. package/dist/{codex-hook-ej8hn6z5.js → codex-hook-jxjv6dy5.js} +1 -1
  104. package/dist/{codex-login-ven5cz5j.js → codex-login-ktfg1cxk.js} +1 -1
  105. package/dist/{codex-session-runner-ps5m4z1g.js → codex-session-runner-r55tmx4c.js} +9 -9
  106. package/dist/{commands-shktk0b8.js → commands-0mxdy9x8.js} +3 -3
  107. package/dist/{controller-wn3vd217.js → controller-g3vkfhr4.js} +4 -4
  108. package/dist/{controllers-connect-yft057ws.js → controllers-connect-4wdmncqt.js} +25 -25
  109. package/dist/core-gsvj5f3z.js +42 -0
  110. package/dist/{cursor-adapter-8fpm4dng.js → cursor-adapter-t9qb96q2.js} +2 -2
  111. package/dist/{db-0ezhdhz5.js → db-487vvyv9.js} +3 -3
  112. package/dist/{db-84pz2w5c.js → db-76p7w3gr.js} +2 -2
  113. package/dist/{devin-adapter-fs90ab4v.js → devin-adapter-3bp6rape.js} +1 -1
  114. package/dist/{dispatcher-h2rz69f6.js → dispatcher-64rp6w67.js} +22 -22
  115. package/dist/{docker-1h33jvh9.js → docker-a59g3ebm.js} +2 -2
  116. package/dist/{dsh-adapter-g9yqv09y.js → dsh-adapter-8abzqk5c.js} +2 -2
  117. package/dist/{e2b-y7e5kmzf.js → e2b-3ykbe805.js} +2 -2
  118. package/dist/{e2b-jnk0yeva.js → e2b-dc8f6ctq.js} +2 -2
  119. package/dist/{easter-egg-3d-m41ad78v.js → easter-egg-3d-jrrwyf55.js} +1 -1
  120. package/dist/{embedding-space-yam9zwzj.js → embedding-space-001hhhpk.js} +6 -6
  121. package/dist/{embeddings-g2be0y8q.js → embeddings-esj19cnw.js} +1 -1
  122. package/dist/{event-bus-08t2b4y2.js → event-bus-7gbsr0g4.js} +1 -1
  123. package/dist/{execute-hhdejgzf.js → execute-301hkxqg.js} +1 -1
  124. package/dist/{external-channel-kjt2yzfj.js → external-channel-w10e2j05.js} +2 -2
  125. package/dist/fx-adapter-4sjrbdne.js +20 -0
  126. package/dist/grok-adapter-3a0ezfee.js +20 -0
  127. package/dist/handlers-ef3k11hb.js +41 -0
  128. package/dist/{heartbeat-2e5jdexj.js → heartbeat-tbrj7vhq.js} +25 -25
  129. package/dist/{hook-acg9saz7.js → hook-3am1sq68.js} +6 -6
  130. package/dist/{hook-34s8cmgn.js → hook-tx917rqw.js} +8 -8
  131. package/dist/{http-ra2zr2f8.js → http-3rmemtqy.js} +335 -1829
  132. package/dist/{index-mbpxhc4w.js → index-126v2d0t.js} +1 -4
  133. package/dist/{index-2z1z7qx6.js → index-2jw11t8s.js} +26 -26
  134. package/dist/{index-9q42cr54.js → index-aetfyx6p.js} +1 -1
  135. package/dist/index-e6bq0exk.js +42 -0
  136. package/dist/{index-9r4j0a60.js → index-gfnq66t1.js} +223 -25
  137. package/dist/index-hf2k1vge.js +39 -0
  138. package/dist/{index-93bw5wds.js → index-s7xtvc0f.js} +1 -1
  139. package/dist/index-taxmejj3.js +44 -0
  140. package/dist/{k8s-8326q0rq.js → k8s-36gfn847.js} +2 -2
  141. package/dist/{keepalive-vjnnqbkm.js → keepalive-9px3t7qj.js} +5 -5
  142. package/dist/lead-5vt6f174.js +83 -0
  143. package/dist/{maintenance-px2g599e.js → maintenance-vwqjwst6.js} +1 -1
  144. package/dist/{oauth-refresh-sweep-nkykf09m.js → oauth-refresh-sweep-yqry3wn4.js} +4 -4
  145. package/dist/{object-webhooks-gt9xnq21.js → object-webhooks-8s1wtths.js} +7 -7
  146. package/dist/{onboard-1f134p65.js → onboard-hb8czx0p.js} +7 -7
  147. package/dist/{opencode-adapter-94976yab.js → opencode-adapter-djd6m6dk.js} +8 -8
  148. package/dist/{otel-impl-5d4p2fqs.js → otel-impl-2ymwyczz.js} +2 -2
  149. package/dist/{pending-vkk0vx6n.js → pending-nxavtvx7.js} +23 -23
  150. package/dist/{pi-mono-adapter-cyzdv5er.js → pi-mono-adapter-d2cpmcy4.js} +12 -12
  151. package/dist/{pricing-refresh-jtmjwss9.js → pricing-refresh-1yz8jkqv.js} +2 -2
  152. package/dist/{rbac-roles-1fvmdyeb.js → rbac-roles-7s6m31xw.js} +6 -4
  153. package/dist/{rbac-roles-yd1fgpsn.js → rbac-roles-dbpx0x9v.js} +3 -3
  154. package/dist/{render-v2-kb5s3vx4.js → render-v2-7y20rjrn.js} +7 -7
  155. package/dist/{resume-z1vs44n5.js → resume-wz546x47.js} +10 -10
  156. package/dist/{runtime-gk6ct7r7.js → runtime-cb5bd9tz.js} +1 -1
  157. package/dist/{session-access-nz6nre4d.js → session-access-4vcft8kq.js} +5 -5
  158. package/dist/{session-source-backfill-wb60zjkd.js → session-source-backfill-57b50tpw.js} +3 -3
  159. package/dist/{setup-2x8g8j4s.js → setup-e1tevjyj.js} +1 -1
  160. package/dist/thread-buffer-686pa1p1.js +42 -0
  161. package/dist/{tree-visibility-ts3z30kw.js → tree-visibility-07wf1nct.js} +2 -2
  162. package/dist/{user-merge-jobs-zetg26e0.js → user-merge-jobs-n20qpv6s.js} +3 -3
  163. package/dist/{virtual-modules-674fka8x.js → virtual-modules-6fxmn1yv.js} +3 -3
  164. package/dist/{work-objects-w52yyjxm.js → work-objects-eg7y48pe.js} +25 -25
  165. package/dist/worker-4vp616ms.js +83 -0
  166. package/dist/{worker-follow-up-dyfxyjbj.js → worker-follow-up-jnvnnf2b.js} +22 -22
  167. package/dist/{x-asbrnafg.js → x-d27jj7z7.js} +2 -2
  168. package/openapi.json +475 -28
  169. package/package.json +2 -2
  170. package/src/be/db/approvals.ts +2 -0
  171. package/src/be/db/runtime.ts +5 -0
  172. package/src/be/db/script-run-sources.ts +17 -0
  173. package/src/be/db-retention.ts +1 -1
  174. package/src/be/db.ts +71 -62
  175. package/src/be/design-system.ts +63 -0
  176. package/src/be/migrations/342_script_run_sources.sql +20 -0
  177. package/src/be/migrations/runner.ts +8 -0
  178. package/src/be/migrations/script-run-sources.ts +51 -0
  179. package/src/be/rbac-roles.ts +2 -0
  180. package/src/be/scripts/typecheck.ts +4 -2
  181. package/src/be/seed-scripts/catalog/design-system-seed.ts +158 -0
  182. package/src/be/seed-scripts/index.ts +9 -0
  183. package/src/be/swarm-config-guard.ts +21 -1
  184. package/src/commands/onboard/agent-fs-version.ts +1 -1
  185. package/src/heartbeat/heartbeat.ts +18 -4
  186. package/src/http/all-routes.ts +1 -0
  187. package/src/http/approval-chat-answer.ts +99 -0
  188. package/src/http/approval-requests.ts +280 -225
  189. package/src/http/design-system.ts +103 -0
  190. package/src/http/index.ts +10 -6
  191. package/src/http/pages-public.ts +25 -10
  192. package/src/http/pages.ts +17 -0
  193. package/src/http/person-responder.ts +28 -0
  194. package/src/integrations/chat-sdk/adapters.ts +33 -3
  195. package/src/integrations/chat-sdk/inbound.ts +6 -18
  196. package/src/integrations/chat-sdk/mentions.ts +188 -0
  197. package/src/integrations/chat-sdk/outbound.ts +20 -3
  198. package/src/integrations/chat-sdk/router.ts +8 -0
  199. package/src/integrations/chat-sdk/telegram-thread.ts +12 -0
  200. package/src/jira/adf.ts +35 -9
  201. package/src/kv-reserved-namespaces.ts +5 -0
  202. package/src/pages/page-head.ts +11 -1
  203. package/src/providers/amp-adapter.ts +1 -1
  204. package/src/providers/dsh-adapter.ts +48 -13
  205. package/src/rbac/legacy-policy.ts +4 -0
  206. package/src/rbac/permissions.ts +8 -0
  207. package/src/scheduler/index.ts +1 -0
  208. package/src/scheduler/scheduler.test.ts +32 -1
  209. package/src/scheduler/scheduler.ts +24 -1
  210. package/src/script-workflows/executor.ts +6 -0
  211. package/src/script-workflows/supervisor.ts +2 -1
  212. package/src/scripts-runtime/sdk-allowlist.ts +2 -0
  213. package/src/scripts-runtime/swarm-sdk.ts +12 -23
  214. package/src/scripts-runtime/types/stdlib.d.ts +4 -1
  215. package/src/scripts-runtime/types/swarm-sdk.d.ts +4 -1
  216. package/src/server.ts +2 -0
  217. package/src/slack/actions.ts +3 -0
  218. package/src/slack/approval-actions.ts +148 -0
  219. package/src/slack/approval-buttons.ts +28 -0
  220. package/src/tests/chat-sdk-mentions.test.ts +183 -0
  221. package/src/tests/create-page-tool.test.ts +5 -0
  222. package/src/tests/dsh-adapter.test.ts +53 -1
  223. package/src/tests/fixtures/compiled-source-schema-boot.ts +24 -0
  224. package/src/tests/fixtures/secret-corpus.ts +43 -1
  225. package/src/tests/heartbeat-stall-thresholds.test.ts +174 -0
  226. package/src/tests/jira-adf.test.ts +42 -2
  227. package/src/tests/merge-gate-detect-changes.test.ts +208 -16
  228. package/src/tests/migration-342-script-run-sources.test.ts +196 -0
  229. package/src/tests/migration-bunfs-compat.test.ts +129 -9
  230. package/src/tests/rbac-e2e-helpers.test.ts +10 -4
  231. package/src/tests/rbac-e2e-helpers.ts +13 -4
  232. package/src/tests/rbac-roles.test.ts +2 -0
  233. package/src/tests/runtime-e2b-pools.test.ts +7 -1
  234. package/src/tests/schedule-target-type.test.ts +4 -1
  235. package/src/tests/script-connections.test.ts +2 -0
  236. package/src/tests/script-runs-retention.test.ts +43 -16
  237. package/src/tests/script-workflows-runtime-e2e.test.ts +56 -22
  238. package/src/tests/scripts-http.test.ts +9 -3
  239. package/src/tests/sdk-allowlist.test.ts +26 -13
  240. package/src/tests/sdk-store-progress-skipped.test.ts +12 -5
  241. package/src/tests/secret-rules.test.ts +34 -0
  242. package/src/tests/secret-scrub-gate.test.ts +7 -0
  243. package/src/tests/secret-scrubber.test.ts +62 -2
  244. package/src/tests/seed-scripts.test.ts +2 -2
  245. package/src/tests/system-one-hosts-ui-mirror.test.ts +1 -0
  246. package/src/tests/vcs-azure-devops.test.ts +10 -0
  247. package/src/tests/vcs-provider.test.ts +8 -0
  248. package/src/themes/design-system.ts +163 -0
  249. package/src/themes/page-theme.ts +28 -19
  250. package/src/tools/chat-post.ts +7 -3
  251. package/src/tools/create-page.ts +3 -0
  252. package/src/tools/design-system.ts +102 -0
  253. package/src/tools/mcp-servers/mcp-server-get.ts +1 -1
  254. package/src/tools/mcp-servers/mcp-server-list.ts +1 -1
  255. package/src/tools/register-chat-channel.ts +11 -2
  256. package/src/tools/skills/skill-get-file.ts +1 -1
  257. package/src/tools/skills/skill-get.ts +1 -1
  258. package/src/tools/skills/skill-list.ts +1 -1
  259. package/src/tools/skills/skill-search.ts +1 -1
  260. package/src/tools/utils.ts +49 -4
  261. package/src/tools/workflows/get-workflow-run.ts +1 -1
  262. package/src/tools/workflows/get-workflow.ts +1 -1
  263. package/src/tools/workflows/list-workflow-runs.ts +1 -1
  264. package/src/tools/workflows/list-workflows.ts +1 -1
  265. package/src/types.ts +65 -0
  266. package/src/utils/secret-rules.generated.ts +149 -149
  267. package/src/utils/secret-scrubber.ts +111 -5
  268. package/src/vcs/azure-devops.ts +22 -1
  269. package/src/vcs/index.ts +3 -1
  270. package/src/workflows/approval-inline.ts +122 -0
  271. package/src/workflows/approval-notifications.ts +7 -2
  272. package/src/workflows/engine.ts +6 -5
  273. package/src/workflows/executors/agent-task.ts +14 -0
  274. package/src/workflows/executors/system-one-providers.ts +23 -0
  275. package/templates/skills/pages/content.md +34 -8
  276. package/templates/skills/swarm-docs/content.md +5 -0
  277. package/templates/skills/workflow-iterate/content.md +1 -1
  278. package/dist/acp-adapter-t2q6nsqv.js +0 -17
  279. package/dist/cli-kh973792.js +0 -98
  280. package/dist/core-nheayfgm.js +0 -42
  281. package/dist/fx-adapter-8g7xsp8q.js +0 -20
  282. package/dist/grok-adapter-ztk2zkz1.js +0 -20
  283. package/dist/handlers-9ywssz71.js +0 -41
  284. package/dist/index-6mgbdtv1.js +0 -44
  285. package/dist/index-hqdsn2t2.js +0 -39
  286. package/dist/index-st231bqv.js +0 -40
  287. package/dist/lead-mk0xkth2.js +0 -82
  288. package/dist/thread-buffer-d50rqpev.js +0 -42
  289. package/dist/worker-662x1vse.js +0 -82
package/src/http/index.ts CHANGED
@@ -94,6 +94,7 @@ import { handleConfig } from "./config";
94
94
  import { handleContext } from "./context";
95
95
  import { getDeploymentEnvValue, handleCore, loadGlobalConfigsIntoEnv } from "./core";
96
96
  import { handleDbQuery } from "./db-query";
97
+ import { handleDesignSystem } from "./design-system";
97
98
  import { handleEvents } from "./events";
98
99
  import { handleExtensions } from "./extensions";
99
100
  import { handleFavorites } from "./favorites";
@@ -434,6 +435,7 @@ const httpServer = createHttpServer(async (req, res) => {
434
435
  () => handlePagesPublic(req, res, pathSegments, queryParams),
435
436
  () => handlePageProxy(req, res),
436
437
  () => handlePages(req, res, pathSegments, queryParams, myAgentId),
438
+ () => handleDesignSystem(req, res, pathSegments, queryParams, myAgentId),
437
439
  () => handleApiKeys(req, res, pathSegments, queryParams),
438
440
  () => handleHeartbeat(req, res, pathSegments),
439
441
  () => handleEvents(req, res, pathSegments, queryParams, myAgentId),
@@ -921,14 +923,16 @@ httpServer
921
923
  // Reconcile durable script workflow subprocesses
922
924
  await startScriptRunSupervisor(getMcpBaseUrl());
923
925
 
924
- // Start scheduler (if enabled)
926
+ // Start scheduler (if enabled). The interval is read post-hydration, like
927
+ // heartbeat below, and parsed so an unusable value keeps the 10s default (#3169).
925
928
  if (hasCapability("scheduling")) {
926
- const { startScheduler } = await import("../scheduler");
929
+ const { parseSchedulerIntervalMs, startScheduler } = await import("../scheduler");
927
930
  const { getExecutorRegistry } = await import("../workflows");
928
- const intervalMs = Number(process.env.SCHEDULER_INTERVAL_MS) || 10000;
929
- startScheduler(getExecutorRegistry(), intervalMs, {
930
- runId: globalState.__runId!,
931
- });
931
+ startScheduler(
932
+ getExecutorRegistry(),
933
+ parseSchedulerIntervalMs(process.env.SCHEDULER_INTERVAL_MS),
934
+ { runId: globalState.__runId! },
935
+ );
932
936
  }
933
937
 
934
938
  // Start heartbeat triage (unless disabled). Read post-hydration (this block
@@ -24,6 +24,7 @@
24
24
  import type { IncomingMessage, ServerResponse } from "node:http";
25
25
  import { z } from "zod";
26
26
  import { getPage, incrementPageViewCount } from "../be/db";
27
+ import { getActiveDesignSystem } from "../be/design-system";
27
28
  import { BROWSER_SDK_JS, SWARM_UI_JS } from "../pages/browser-sdk";
28
29
  import { COLOR_LITERAL_THRESHOLD, countColorLiterals } from "../pages/color-literals";
29
30
  import {
@@ -38,6 +39,7 @@ import {
38
39
  PAGE_THEME_PARAM,
39
40
  } from "../pages/page-head";
40
41
  import { resolvePageTheme } from "../themes/page-theme";
42
+ import { getThemePreset } from "../themes/presets";
41
43
  import { type Page, PageSchema } from "../types";
42
44
  import { getAppUrl, getConfiguredAppUrls, getLocalDevAppOrigins } from "../utils/constants";
43
45
  import {
@@ -111,24 +113,37 @@ const publicPageJsonRoute = route({
111
113
  /**
112
114
  * The `<head>` defaults for a page's design version (`src/pages/page-head.ts`).
113
115
  * Version 1 is the frozen original head and ignores the viewer params. Version
114
- * 2 resolves the theme: the page `theme`, else the viewer's `__swarm-theme`
115
- * preset, else Hive, plus the page `themeTokens` on top. It is dark only for
116
- * `__swarm-mode=dark`, and a `?print=1` export is always light. A body with
116
+ * 2 resolves the theme: the page `theme`, else the org design system, else the
117
+ * viewer's `__swarm-theme` preset, else Hive, plus the page `themeTokens` on
118
+ * top. The org design system (its tokens, fonts and mode lock) applies only to
119
+ * a page without its own `theme`. The page is dark for `__swarm-mode=dark`, or
120
+ * always when the design system locks `mode: "dark"`; `mode: "light"` keeps it
121
+ * light. A `?print=1` export is always light. A body with
117
122
  * `COLOR_LITERAL_THRESHOLD` or more hardcoded colors also stays light: its
118
123
  * hardcoded light surfaces would get the dark-mode text color.
119
124
  */
120
- function pageHead(page: Page, queryParams: URLSearchParams, wantsPrint: boolean): string {
125
+ async function pageHead(
126
+ page: Page,
127
+ queryParams: URLSearchParams,
128
+ wantsPrint: boolean,
129
+ ): Promise<string> {
121
130
  if (page.designVersion === 1) return PAGE_HEAD_V1;
131
+ const designSystem = getThemePreset(page.theme) ? null : await getActiveDesignSystem();
122
132
  const theme = resolvePageTheme({
123
133
  pageTheme: page.theme,
124
134
  viewerTheme: queryParams.get(PAGE_THEME_PARAM),
125
135
  overrides: page.themeTokens,
136
+ designSystem,
137
+ });
138
+ const mode = designSystem?.mode ?? "viewer";
139
+ const wantsDark =
140
+ mode === "dark" || (mode === "viewer" && queryParams.get(PAGE_MODE_PARAM) === "dark");
141
+ const dark = !wantsPrint && wantsDark && countColorLiterals(page.body) < COLOR_LITERAL_THRESHOLD;
142
+ return buildPageHeadV2({
143
+ theme,
144
+ mode: dark ? "dark" : "light",
145
+ fontsHref: designSystem?.fontsHref,
126
146
  });
127
- const dark =
128
- !wantsPrint &&
129
- queryParams.get(PAGE_MODE_PARAM) === "dark" &&
130
- countColorLiterals(page.body) < COLOR_LITERAL_THRESHOLD;
131
- return buildPageHeadV2({ theme, mode: dark ? "dark" : "light" });
132
147
  }
133
148
 
134
149
  /** A doctype at the start of a body (`\s` also matches a BOM). */
@@ -703,7 +718,7 @@ export async function handlePagesPublic(
703
718
  const html =
704
719
  injectBrowserSdk(page.body, {
705
720
  // The viewer meta goes after the head defaults, which start with <base target>.
706
- head: `${pageHead(page, queryParams, wantsPrint)}<meta name="swarm-viewer" content="${pageViewer(cookiePayload)}">`,
721
+ head: `${await pageHead(page, queryParams, wantsPrint)}<meta name="swarm-viewer" content="${pageViewer(cookiePayload)}">`,
707
722
  headFirst: feedback ? feedbackKeyGuardScript() : "",
708
723
  standardsMode: page.designVersion !== 1,
709
724
  }) +
package/src/http/pages.ts CHANGED
@@ -24,6 +24,7 @@ import { snapshotPage } from "../pages/version";
24
24
  import { resolveTemplate } from "../prompts/resolver";
25
25
  // Side-effect import: registers `task.page.feedback`.
26
26
  import "../prompts/session-templates";
27
+ import { can } from "../rbac";
27
28
  import { createTaskWithSiblingAwareness } from "../tasks/sibling-awareness";
28
29
  import { readThemeFields } from "../themes/page-fields";
29
30
  import { THEME_PRESET_IDS } from "../themes/presets";
@@ -41,6 +42,7 @@ import { getAppUrl, getPublicMcpBaseUrl } from "../utils/constants";
41
42
  import { isLocalDevPageRequest, pageSessionSetCookies } from "../utils/page-session";
42
43
  import { authUser, getRequestAuth, isOperatorAuth } from "../utils/request-auth-context";
43
44
  import { resolveHttpFavoriteOwner } from "./favorite-owner";
45
+ import { resolveRequestPrincipal } from "./request-principal";
44
46
  import { route } from "./route-def";
45
47
  import { resolveTaskRequester } from "./tasks";
46
48
  import {
@@ -229,9 +231,11 @@ const launchPageRoute = route({
229
231
  summary: "Launch a page session (issues HttpOnly cookie)",
230
232
  tags: ["Pages"],
231
233
  params: z.object({ id: z.string() }),
234
+ rbac: { permission: "page.launch" },
232
235
  responses: {
233
236
  204: { description: "Cookie issued" },
234
237
  400: { description: "Launch not supported for this page (e.g. password mode)" },
238
+ 403: { description: "Caller may not open pages" },
235
239
  404: { description: "Page not found" },
236
240
  },
237
241
  });
@@ -1031,6 +1035,19 @@ export async function handlePages(
1031
1035
  const parsed = await launchPageRoute.parse(req, res, pathSegments, queryParams);
1032
1036
  if (!parsed) return true;
1033
1037
 
1038
+ // Role grants were checked at admission; this refuses guest and controller sessions.
1039
+ const principal = await resolveRequestPrincipal(req, myAgentId, {
1040
+ unauthenticatedFallback: "operator",
1041
+ });
1042
+ const decision = principal
1043
+ ? can({ principal, verb: "page.launch", resource: { kind: "none" }, source: "http" })
1044
+ : { allow: false as const, reason: "no authenticated principal" };
1045
+ if (!decision.allow) {
1046
+ applyLaunchCors(req, res);
1047
+ jsonError(res, decision.reason, 403);
1048
+ return true;
1049
+ }
1050
+
1034
1051
  const page = await getPage(parsed.params.id);
1035
1052
  if (!page) {
1036
1053
  applyLaunchCors(req, res);
@@ -1,5 +1,6 @@
1
1
  import type { IncomingMessage } from "node:http";
2
2
  import { getUserGrant } from "../be/rbac-roles";
3
+ import { findUserById } from "../be/users";
3
4
  import { can, isRbacEnabled, type PermissionVerb } from "../rbac";
4
5
  import type { User } from "../types";
5
6
  import { getRequestAuth } from "../utils/request-auth-context";
@@ -64,3 +65,30 @@ export async function approvalResponder(
64
65
  export function responderKey(responder: ApprovalResponder): string {
65
66
  return responder.kind === "user" ? responder.user.id : "operator";
66
67
  }
68
+
69
+ /**
70
+ * The responder for a person identified outside HTTP, such as a chat user
71
+ * mapped through `user_external_ids`. Applies the checks `approvalResponder`
72
+ * applies to a user credential: an active, unmerged account (what credential
73
+ * resolution requires), the `approval.respond` verb and, with RBAC on, a role
74
+ * that grants it.
75
+ */
76
+ export async function userApprovalResponder(
77
+ userId: string,
78
+ ): Promise<{ ok: true; responder: ApprovalResponder } | { ok: false; message: string }> {
79
+ const refused = {
80
+ ok: false as const,
81
+ message: "You are not allowed to answer approval requests.",
82
+ };
83
+ const user = await findUserById(userId);
84
+ // Credential resolution refuses invited, suspended and merged-away users, so
85
+ // a chat identity mapped to one must not answer either.
86
+ if (!user || user.status !== "active" || user.mergedIntoUserId) return refused;
87
+ const verb: PermissionVerb = "approval.respond";
88
+ if (!can({ principal: { kind: "user", userId }, verb, source: "http" }).allow) return refused;
89
+ if (isRbacEnabled()) {
90
+ const grant = await getUserGrant(userId);
91
+ if (!grant.grantsAll && !grant.verbs.has(verb)) return refused;
92
+ }
93
+ return { ok: true, responder: { kind: "user", user } };
94
+ }
@@ -3,6 +3,11 @@ import type { Adapter, Logger } from "chat";
3
3
  import { type ChatSdkAdapterName, type ResolvedAdapterConfig, readApiUrlOverrides } from "./config";
4
4
  import { isTelegramReplyToBot, type TelegramRawMessage } from "./facts";
5
5
  import { withInfoFilter } from "./logger";
6
+ import {
7
+ type DiscordGatewayMessage,
8
+ discordJsMentionLookup,
9
+ resolveDiscordMentions,
10
+ } from "./mentions";
6
11
  import { getChatSdkTestHooks } from "./test-hooks";
7
12
 
8
13
  /**
@@ -110,15 +115,40 @@ export async function loadAdapter(
110
115
  } as Parameters<typeof createSlackAdapter>[0]);
111
116
  }
112
117
  case "discord": {
113
- const { createDiscordAdapter } = await import("@chat-adapter/discord");
118
+ const { DiscordAdapter } = await import("@chat-adapter/discord");
119
+ // The adapter turns `<@id>`, `<@&id>` and `<#id>` into bare `@id` /
120
+ // `#id`, so agents would see numbers. The Gateway message carries the
121
+ // names in `mentions`; write them into the content first. The view
122
+ // reads every other field from the real message.
123
+ class SwarmDiscordAdapter extends DiscordAdapter {
124
+ // The parameter is a discord.js `Message`; discord.js is not a direct dependency.
125
+ protected override handleGatewayMessage(
126
+ message: DiscordGatewayMessage,
127
+ isMentioned: boolean,
128
+ ): Promise<void> {
129
+ const content = resolveDiscordMentions(
130
+ message.content,
131
+ this.botUserId,
132
+ discordJsMentionLookup(message.mentions),
133
+ );
134
+ if (content === message.content) {
135
+ return super.handleGatewayMessage(message as never, isMentioned);
136
+ }
137
+ const view = new Proxy(message, {
138
+ get: (target, prop) =>
139
+ prop === "content" ? content : Reflect.get(target, prop, target),
140
+ });
141
+ return super.handleGatewayMessage(view as never, isMentioned);
142
+ }
143
+ }
114
144
  // `[]` (not undefined) blocks the DISCORD_RESPOND_TO_CHANNEL_IDS and
115
145
  // DISCORD_MENTION_ROLE_IDS env fallbacks.
116
- return createDiscordAdapter({
146
+ return new SwarmDiscordAdapter({
117
147
  ...base,
118
148
  logger: withInfoFilter(logger, keepDiscordInfoLine),
119
149
  respondToChannelIds: config.respondToChannelIds ?? [],
120
150
  mentionRoleIds: config.mentionRoleIds ?? [],
121
- } as Parameters<typeof createDiscordAdapter>[0]);
151
+ } as ConstructorParameters<typeof DiscordAdapter>[0]);
122
152
  }
123
153
  case "teams": {
124
154
  const { createTeamsAdapter } = await import("@chat-adapter/teams");
@@ -1,4 +1,4 @@
1
- import type { Adapter, Message, Thread } from "chat";
1
+ import type { Message, Thread } from "chat";
2
2
  import { z } from "zod";
3
3
  import { sessionGroupKey } from "@/assets/key";
4
4
  import { sessionSourceKey } from "@/assets/source-key";
@@ -35,6 +35,7 @@ import {
35
35
  import { getChatThreadResetAt } from "./commands";
36
36
  import { type ChatAddressedReason, formatChatHeaderFacts, readChatMessageFacts } from "./facts";
37
37
  import { errorMessage } from "./logger";
38
+ import { botMentionForms, stripBotMention } from "./mentions";
38
39
  import { chatMessageText } from "./message-text";
39
40
  import { emitChatMessageSent, postChatMessage } from "./outbound";
40
41
  import {
@@ -82,22 +83,6 @@ export const ChatRouteModifySchema = z
82
83
  const THREAD_CONTEXT_LIMIT = 20;
83
84
  const AGENT_MESSAGE_TRUNCATE = 500;
84
85
 
85
- function escapeRegex(value: string): string {
86
- return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
87
- }
88
-
89
- /** Remove the bot's own `@name` / `<@id>` mention; other mentions stay. */
90
- function stripBotMention(text: string, adapter: Adapter): string {
91
- let out = text;
92
- if (adapter.userName) {
93
- out = out.replace(new RegExp(`(?<!\\w)@${escapeRegex(adapter.userName)}(?![\\w-])`, "gi"), "");
94
- }
95
- if (adapter.botUserId) {
96
- out = out.replace(new RegExp(`<@${escapeRegex(adapter.botUserId)}>`, "g"), "");
97
- }
98
- return out.trim();
99
- }
100
-
101
86
  /** The adapter name is the thread id's first segment; the rest of the id is opaque. */
102
87
  function adapterOf(threadId: string): string {
103
88
  const i = threadId.indexOf(":");
@@ -124,7 +109,10 @@ export async function handleChatInbound(
124
109
  messageId: message.id,
125
110
  });
126
111
 
127
- let text = stripBotMention(chatMessageText(message), thread.adapter);
112
+ let text = stripBotMention(
113
+ chatMessageText(message),
114
+ await botMentionForms(thread.adapter, message),
115
+ );
128
116
  const immediate = /^!now\b/i.test(text);
129
117
  if (immediate) text = text.replace(/^!now\s*/i, "").trim();
130
118
  const attachments = message.attachments ?? [];
@@ -0,0 +1,188 @@
1
+ /**
2
+ * Mention handling for inbound chat text, over adapter payload shapes. No
3
+ * database access; `botMentionForms` reads the Slack adapter's user cache.
4
+ * Used by `inbound.ts` and `adapters.ts`.
5
+ *
6
+ * Each adapter renders the bot's own mention differently by the time the
7
+ * handler sees the text (checked against the 4.45.0 adapter sources):
8
+ * - Discord: `<@id>` / `<@!id>` becomes bare `@id`.
9
+ * - Slack: `<@U…>` becomes `@<display name>` from `users.info`.
10
+ * - Teams: `<at>Name</at>` becomes `@Name`, the name the client typed.
11
+ * - Telegram and Rocket.Chat: `@username`, the adapter `userName`.
12
+ */
13
+
14
+ import type { Adapter, Message } from "chat";
15
+
16
+ export interface BotMentionForms {
17
+ /** Display names or handles; matched as `@name`, case-insensitive. */
18
+ names: readonly string[];
19
+ /** Platform user ids; matched as `<@id>`, `<@!id>` and bare `@id`. */
20
+ ids: readonly string[];
21
+ }
22
+
23
+ function escapeRegex(value: string): string {
24
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
25
+ }
26
+
27
+ /** Remove the bot's own mention in every form the adapters produce; other mentions stay. */
28
+ export function stripBotMention(text: string, forms: BotMentionForms): string {
29
+ let out = text;
30
+ const names = [...new Set(forms.names.map((name) => name.trim()).filter(Boolean))];
31
+ // Longest first, so `@Agent Swarm` is not cut to ` Swarm` by an `@Agent` handle.
32
+ names.sort((a, b) => b.length - a.length);
33
+ for (const name of names) {
34
+ out = out.replace(new RegExp(`(?<!\\w)@${escapeRegex(name)}(?![\\w-])`, "gi"), "");
35
+ }
36
+ for (const id of new Set(forms.ids.filter(Boolean))) {
37
+ const escaped = escapeRegex(id);
38
+ out = out.replace(new RegExp(`<@!?${escaped}>`, "g"), "");
39
+ out = out.replace(new RegExp(`(?<![\\w<&])@${escaped}(?!\\w)`, "g"), "");
40
+ }
41
+ return out.trim();
42
+ }
43
+
44
+ /** The part of a Teams mention entity this reads. */
45
+ interface TeamsMentionEntity {
46
+ type?: unknown;
47
+ text?: unknown;
48
+ mentioned?: { id?: unknown; name?: unknown };
49
+ }
50
+
51
+ /** Teams ids carry a channel prefix (`28:<appId>`); compare the part after the last colon. */
52
+ function teamsIdTail(id: string): string {
53
+ return id.slice(id.lastIndexOf(":") + 1).toLowerCase();
54
+ }
55
+
56
+ /**
57
+ * Names the bot was mentioned by in a Teams Activity: `mentioned.name` and
58
+ * the `<at>…</at>` label of each mention entity that points at the bot.
59
+ * The adapter renders that label as `@label`.
60
+ */
61
+ export function teamsBotMentionNames(raw: unknown, botUserId: string | undefined): string[] {
62
+ if (!botUserId || !raw || typeof raw !== "object") return [];
63
+ const entities = (raw as { entities?: unknown }).entities;
64
+ if (!Array.isArray(entities)) return [];
65
+ const bot = teamsIdTail(botUserId);
66
+ const names: string[] = [];
67
+ for (const entity of entities as TeamsMentionEntity[]) {
68
+ if (entity?.type !== "mention") continue;
69
+ const id = entity.mentioned?.id;
70
+ if (typeof id !== "string" || teamsIdTail(id) !== bot) continue;
71
+ if (typeof entity.mentioned?.name === "string") names.push(entity.mentioned.name);
72
+ if (typeof entity.text === "string") {
73
+ const label = /<at\b[^>]*>(.*?)<\/at>/is.exec(entity.text)?.[1];
74
+ if (label) names.push(decodeTeamsLabel(label));
75
+ }
76
+ }
77
+ return names;
78
+ }
79
+
80
+ function decodeTeamsLabel(label: string): string {
81
+ return label
82
+ .replace(/<[^>]*>/g, "")
83
+ .replace(/&quot;/g, '"')
84
+ .replace(/&lt;/g, "<")
85
+ .replace(/&gt;/g, ">")
86
+ .replace(/&amp;/g, "&")
87
+ .trim();
88
+ }
89
+
90
+ /** Name lookups for the ids in one Discord message. `undefined` keeps the id. */
91
+ export interface DiscordMentionLookup {
92
+ user(id: string): string | undefined;
93
+ role(id: string): string | undefined;
94
+ channel(id: string): string | undefined;
95
+ }
96
+
97
+ /**
98
+ * Rewrite Discord mention markup to names before the adapter parses it:
99
+ * `<@id>` / `<@!id>` to `@name`, `<@&id>` to `@role`, `<#id>` to `#channel`.
100
+ * The bot's own mention and any id without a name stay as markup, so the
101
+ * adapter still turns them into `@id` / `#id` and no text is lost.
102
+ */
103
+ export function resolveDiscordMentions(
104
+ content: string,
105
+ botUserId: string | undefined,
106
+ lookup: DiscordMentionLookup,
107
+ ): string {
108
+ return content.replace(/<(@!?|@&|#)(\d+)>/g, (markup, kind: string, id: string) => {
109
+ if (kind === "#") {
110
+ const name = lookup.channel(id);
111
+ return name ? `#${name}` : markup;
112
+ }
113
+ if (kind === "@&") {
114
+ const name = lookup.role(id);
115
+ return name ? `@${name}` : markup;
116
+ }
117
+ if (id === botUserId) return markup;
118
+ const name = lookup.user(id);
119
+ return name ? `@${name}` : markup;
120
+ });
121
+ }
122
+
123
+ /** The part of a discord.js `Message` the lookup reads. */
124
+ export interface DiscordJsMentions {
125
+ users?: { get(id: string): { displayName?: string; username?: string } | undefined };
126
+ members?: { get(id: string): { displayName?: string } | undefined } | null;
127
+ roles?: { get(id: string): { name?: string } | undefined };
128
+ channels?: { get(id: string): object | undefined };
129
+ }
130
+
131
+ /** The part of a discord.js Gateway `Message` the swarm rewrites. */
132
+ export interface DiscordGatewayMessage {
133
+ content: string;
134
+ mentions?: DiscordJsMentions;
135
+ }
136
+
137
+ function safeName(read: () => unknown): string | undefined {
138
+ try {
139
+ const value = read();
140
+ return typeof value === "string" && value.trim() ? value : undefined;
141
+ } catch {
142
+ return undefined;
143
+ }
144
+ }
145
+
146
+ /**
147
+ * Lookup over a Gateway message's `mentions` collections. Discord sends the
148
+ * mentioned users (with guild member data) in the message; roles and
149
+ * channels resolve from the guild cache the Guilds intent fills.
150
+ */
151
+ export function discordJsMentionLookup(
152
+ mentions: DiscordJsMentions | undefined,
153
+ ): DiscordMentionLookup {
154
+ return {
155
+ user: (id) =>
156
+ safeName(() => mentions?.members?.get(id)?.displayName) ??
157
+ safeName(() => mentions?.users?.get(id)?.displayName) ??
158
+ safeName(() => mentions?.users?.get(id)?.username),
159
+ role: (id) => safeName(() => mentions?.roles?.get(id)?.name),
160
+ channel: (id) =>
161
+ safeName(() => (mentions?.channels?.get(id) as { name?: unknown } | undefined)?.name),
162
+ };
163
+ }
164
+
165
+ /** The part of the Slack adapter used for the bot's own display name (protected in its types). */
166
+ type SlackUserLookup = {
167
+ lookupUser?: (userId: string) => Promise<{ displayName?: string } | null>;
168
+ };
169
+
170
+ /**
171
+ * Every form the bot's own mention takes in this message's text. Slack and
172
+ * Teams render it under a display name that can differ from `userName`.
173
+ */
174
+ export async function botMentionForms(
175
+ adapter: Adapter,
176
+ message: Message,
177
+ ): Promise<BotMentionForms> {
178
+ const names = [adapter.userName];
179
+ const ids = adapter.botUserId ? [adapter.botUserId] : [];
180
+ if (adapter.name === "teams") names.push(...teamsBotMentionNames(message.raw, adapter.botUserId));
181
+ if (adapter.name === "slack" && adapter.botUserId) {
182
+ const lookup = (adapter as Adapter & SlackUserLookup).lookupUser;
183
+ // Cached by the adapter: it already looked the bot up to render the mention.
184
+ const bot = await lookup?.call(adapter, adapter.botUserId).catch(() => null);
185
+ if (bot?.displayName) names.push(bot.displayName);
186
+ }
187
+ return { names, ids };
188
+ }
@@ -10,8 +10,10 @@ import {
10
10
  TELEGRAM_PHOTO_LIMIT,
11
11
  } from "./limits";
12
12
  import { errorMessage } from "./logger";
13
+ import { getChatChannelMapping } from "./router";
13
14
  import { getChatInstance } from "./runtime";
14
15
  import { assertTrustedChatTarget } from "./teams-origin";
16
+ import { assertTelegramTopicThreadId } from "./telegram-thread";
15
17
 
16
18
  /** The adapter is not configured, failed to start, or is shutting down. */
17
19
  export class ChatAdapterUnavailableError extends Error {
@@ -370,9 +372,24 @@ export async function postChatMessage(args: {
370
372
  files?: OutboundChatFile[];
371
373
  replyToMessageId?: string;
372
374
  }): Promise<ChatPostResult> {
375
+ let threadId = args.threadId;
376
+ if (!threadId && args.channelId && args.adapter === "telegram") {
377
+ const mapping = await getChatChannelMapping(args.adapter, args.channelId);
378
+ if (mapping?.defaultThreadId !== undefined) {
379
+ assertTelegramTopicThreadId(mapping.defaultThreadId, args.channelId);
380
+ threadId = mapping.defaultThreadId;
381
+ }
382
+ }
383
+ if (
384
+ args.adapter === "telegram" &&
385
+ threadId?.split(":").length === 3 &&
386
+ !threadId.startsWith("telegram:biz:")
387
+ ) {
388
+ assertTelegramTopicThreadId(threadId);
389
+ }
373
390
  // Ids come from tools and stored context keys. Check the Teams origin
374
391
  // before the adapter sends its token.
375
- assertTrustedChatTarget(args.threadId ?? args.channelId ?? "");
392
+ assertTrustedChatTarget(threadId ?? args.channelId ?? "");
376
393
  const chat = getChatInstance(args.adapter);
377
394
  if (!chat) throw new ChatAdapterUnavailableError(args.adapter);
378
395
  const parts = (typeof args.text === "string" ? [args.text] : args.text).map(scrubSecrets);
@@ -383,8 +400,8 @@ export async function postChatMessage(args: {
383
400
 
384
401
  let result: ChatPostResult;
385
402
  let target: PostTarget;
386
- if (args.threadId) {
387
- const thread = chat.thread(args.threadId);
403
+ if (threadId) {
404
+ const thread = chat.thread(threadId);
388
405
  target = thread;
389
406
  // Only adapters with a native reply (Telegram in this SDK version) anchor;
390
407
  // the others post unanchored, as before.
@@ -11,6 +11,7 @@ import { isAgentReachable } from "@/be/runtime-pools/reachability";
11
11
  import { chatSdkContextKey } from "@/tasks/context-key";
12
12
  import type { Agent, RoutingReason } from "@/types";
13
13
  import { scrubSecrets } from "@/utils/secret-scrubber";
14
+ import { assertTelegramTopicThreadId } from "./telegram-thread";
14
15
 
15
16
  /** KV namespace of the channel-to-agent/workflow mapping, written by `register-chat-channel`. */
16
17
  export const CHAT_CHANNELS_NAMESPACE = "integrations:chat:channels";
@@ -18,6 +19,7 @@ export const CHAT_CHANNELS_NAMESPACE = "integrations:chat:channels";
18
19
  export interface ChatChannelMapping {
19
20
  agentId?: string;
20
21
  workflowId?: string;
22
+ defaultThreadId?: string;
21
23
  name?: string;
22
24
  createdAt?: string;
23
25
  }
@@ -66,6 +68,12 @@ export async function putChatChannelMapping(
66
68
  mapping: ChatChannelMapping,
67
69
  ): Promise<string> {
68
70
  const key = chatChannelKey(adapter, channelId);
71
+ if (mapping.defaultThreadId !== undefined) {
72
+ if (adapter !== "telegram") {
73
+ throw new Error("Default topics are supported only for Telegram channels.");
74
+ }
75
+ assertTelegramTopicThreadId(mapping.defaultThreadId, key);
76
+ }
69
77
  await upsertKv({
70
78
  namespace: CHAT_CHANNELS_NAMESPACE,
71
79
  key,
@@ -0,0 +1,12 @@
1
+ /** Validate a topic ID before the adapter's permissive parseInt can change its destination. */
2
+ export function assertTelegramTopicThreadId(threadId: string, channelId?: string): void {
3
+ const match = /^telegram:([^:]+):([1-9]\d*)$/.exec(threadId);
4
+ if (!match || match[1] === "biz" || !Number.isSafeInteger(Number(match[2]))) {
5
+ throw new Error(
6
+ "Invalid Telegram topic threadId. Use telegram:<chatId>:<positive integer topicId>.",
7
+ );
8
+ }
9
+ if (channelId !== undefined && `telegram:${match[1]}` !== channelId) {
10
+ throw new Error("The default Telegram topic must belong to the registered channel.");
11
+ }
12
+ }
package/src/jira/adf.ts CHANGED
@@ -8,9 +8,10 @@
8
8
  * Reference: https://developer.atlassian.com/cloud/jira/platform/apis/document/structure/
9
9
  *
10
10
  * Supported node types: paragraph, heading, bulletList, orderedList, listItem,
11
- * text, mention, hardBreak, codeBlock, blockquote. Unknown types descend into
12
- * `content` if present, else are skipped silently. In non-prod environments a
13
- * debug line is emitted so unhandled cases surface during dev.
11
+ * text, mention, hardBreak, codeBlock, blockquote, inlineCard, blockCard,
12
+ * embedCard. Unknown types descend into `content` if present, else are skipped
13
+ * silently. In non-prod environments a debug line is emitted so unhandled cases
14
+ * surface during dev.
14
15
  */
15
16
 
16
17
  import { getNodeEnv } from "../utils/node-env";
@@ -33,17 +34,22 @@ function asNodeArray(value: unknown): AdfNode[] {
33
34
 
34
35
  /**
35
36
  * Recursively concatenate text from an ADF tree. Mentions are inlined as
36
- * `@<displayName>` (or `@<accountId>` if no displayName is present).
37
+ * `@<displayName>` (or `@<accountId>` if no displayName is present). Card nodes
38
+ * emit their `attrs.url`, since a pasted Confluence or GitHub link carries no
39
+ * text content of its own.
37
40
  *
38
41
  * Block-level nodes insert a trailing newline so consecutive paragraphs render
39
- * as separate lines. Hard breaks and list items also produce newlines.
42
+ * as separate lines. Hard breaks and list items also produce newlines. Ordered
43
+ * list items are numbered from `attrs.order` (default 1).
40
44
  */
41
45
  export function extractText(adf: unknown): string {
42
46
  if (!isNode(adf)) return "";
43
47
 
44
48
  const out: string[] = [];
45
49
 
46
- const visit = (node: AdfNode): void => {
50
+ // A list passes each listItem its marker ("- " or "3. "); every other node
51
+ // visits its children without one.
52
+ const visit = (node: AdfNode, marker?: string): void => {
47
53
  const type = typeof node.type === "string" ? node.type : "";
48
54
 
49
55
  switch (type) {
@@ -73,13 +79,23 @@ export function extractText(adf: unknown): string {
73
79
  out.push("\n");
74
80
  return;
75
81
  }
76
- case "bulletList":
82
+ case "bulletList": {
83
+ for (const child of asNodeArray(node.content)) visit(child, "- ");
84
+ return;
85
+ }
77
86
  case "orderedList": {
78
- for (const child of asNodeArray(node.content)) visit(child);
87
+ // ADF allows an `order` of 0 or more, so a zero-start list keeps its 0;
88
+ // only a missing or non-integer value falls back to 1.
89
+ const order = node.attrs?.order;
90
+ const start =
91
+ typeof order === "number" && Number.isInteger(order) && order >= 0 ? order : 1;
92
+ asNodeArray(node.content).forEach((child, index) => {
93
+ visit(child, `${start + index}. `);
94
+ });
79
95
  return;
80
96
  }
81
97
  case "listItem": {
82
- out.push("- ");
98
+ out.push(marker ?? "- ");
83
99
  for (const child of asNodeArray(node.content)) visit(child);
84
100
  // Block children inside a listItem already trail a newline, so we don't
85
101
  // double-add. But if the listItem only contained inline content, ensure
@@ -89,6 +105,16 @@ export function extractText(adf: unknown): string {
89
105
  }
90
106
  return;
91
107
  }
108
+ case "inlineCard":
109
+ case "blockCard":
110
+ case "embedCard": {
111
+ const url = node.attrs?.url;
112
+ if (typeof url === "string" && url.length > 0) out.push(url);
113
+ // Block and embed cards stand alone on their own line; an inline card
114
+ // sits inside a line of text.
115
+ if (type !== "inlineCard") out.push("\n");
116
+ return;
117
+ }
92
118
  case "doc": {
93
119
  for (const child of asNodeArray(node.content)) visit(child);
94
120
  return;