@desplega.ai/agent-swarm 2.13.2 → 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 (324) hide show
  1. package/dist/acp-adapter-mr4temec.js +17 -0
  2. package/dist/{acp-targets-mz8c5dnt.js → acp-targets-zrk9k0n7.js} +10 -10
  3. package/dist/{actions-5ft3qp5a.js → actions-acqqj9jn.js} +236 -26
  4. package/dist/{agent-fs-provision-6fgz7wvz.js → agent-fs-provision-zmaykqnd.js} +4 -4
  5. package/dist/{amp-adapter-nthn8ezm.js → amp-adapter-a7ts8tmw.js} +3 -3
  6. package/dist/{app-535m78qw.js → app-tmwa442h.js} +7 -7
  7. package/dist/{approval-notifications-dewbk403.js → approval-notifications-6psaaaye.js} +8 -8
  8. package/dist/{assistant-39zyabv2.js → assistant-564v6emv.js} +25 -25
  9. package/dist/{boot-args-schema-bqv5bf77.js → boot-args-schema-n099e0f2.js} +1 -1
  10. package/dist/{boot-reembed-fas7z3zn.js → boot-reembed-chx66qfk.js} +1 -1
  11. package/dist/{boot-reembed-157c0gcz.js → boot-reembed-epvg4fp9.js} +1 -1
  12. package/dist/{boot-scrub-sweep-tmec0be2.js → boot-scrub-sweep-dhkfp0a7.js} +2 -2
  13. package/dist/{boot-seeds-32zm50x2.js → boot-seeds-m74fc07r.js} +4 -4
  14. package/dist/{boxd-hr8rsxzq.js → boxd-451q55ys.js} +1 -1
  15. package/dist/{claude-adapter-gwq7x2nj.js → claude-adapter-hw63yj3j.js} +12 -9
  16. package/dist/{claude-managed-adapter-rkvw6fvq.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-5wbwxy8c.js → claude-sdk-session-cktyqkpk.js} +27 -13
  19. package/dist/{cli-d528acsw.js → cli-0fgvnb0x.js} +7 -7
  20. package/dist/{cli-2v4xxnx2.js → cli-0h8skzss.js} +1 -1
  21. package/dist/{cli-jkkcm72j.js → cli-0p76my9q.js} +31 -16
  22. package/dist/{cli-fp65jdp2.js → cli-1kvcsd2f.js} +219 -155
  23. package/dist/{cli-gc7jkf4a.js → cli-1vmhnncj.js} +3 -3
  24. package/dist/{cli-tceqvv6h.js → cli-29h5239w.js} +5 -5
  25. package/dist/cli-2ap1the6.js +11 -0
  26. package/dist/{cli-8fj8yfmk.js → cli-2vp0z049.js} +1 -1
  27. package/dist/{cli-ewb028rs.js → cli-3bxrrh53.js} +4 -4
  28. package/dist/{cli-nvqq3232.js → cli-3tzmh38q.js} +9 -9
  29. package/dist/{cli-0xwb7zpt.js → cli-3xqad83h.js} +2 -2
  30. package/dist/{cli-0f7n3td3.js → cli-3zrwrnz7.js} +1 -1
  31. package/dist/{cli-2wde56gv.js → cli-404am6f3.js} +7 -7
  32. package/dist/{cli-r4fphq38.js → cli-49aq3cyn.js} +4 -4
  33. package/dist/{cli-8qvte9hn.js → cli-4fpa0zns.js} +3 -3
  34. package/dist/{cli-x5yb8zc8.js → cli-4pbwg7sn.js} +2 -2
  35. package/dist/{cli-s08zsqva.js → cli-4q2c8rxw.js} +76 -10
  36. package/dist/{cli-3mf04tkh.js → cli-4vynxtrb.js} +1 -1
  37. package/dist/{cli-tbdw3f92.js → cli-5ashycw3.js} +3 -3
  38. package/dist/{cli-c9bwawf9.js → cli-5rgm8p39.js} +3 -3
  39. package/dist/{cli-g0b3ma7r.js → cli-5rxsb3wq.js} +6 -6
  40. package/dist/{cli-a6rzw649.js → cli-60dwk8tx.js} +3 -3
  41. package/dist/{cli-xhkek467.js → cli-7by7vp6m.js} +30 -4
  42. package/dist/{cli-62fjschk.js → cli-7g3fg4gf.js} +7 -7
  43. package/dist/{cli-ka13xx6b.js → cli-7gbff32z.js} +2 -2
  44. package/dist/{cli-q8aq48v1.js → cli-8b4rpnwj.js} +1 -1
  45. package/dist/{cli-1f48qdnb.js → cli-8cas2xvp.js} +3 -3
  46. package/dist/{cli-dnvmwsvc.js → cli-904wk98s.js} +799 -371
  47. package/dist/{cli-m1wddksc.js → cli-93n305hm.js} +2 -2
  48. package/dist/{cli-31vt7baf.js → cli-944w9wb4.js} +21 -17
  49. package/dist/{cli-je587f74.js → cli-94gx6ze9.js} +1 -1
  50. package/dist/{cli-fcwrd7bh.js → cli-9ah37a8a.js} +6 -6
  51. package/dist/{cli-rfejbpe1.js → cli-akm6y2a8.js} +1 -1
  52. package/dist/{cli-f8rcvf2x.js → cli-azj9t1f9.js} +37 -2
  53. package/dist/{cli-mwxez0pz.js → cli-b768ek79.js} +1 -1
  54. package/dist/{cli-cmgdptmx.js → cli-bv4vvnmg.js} +31 -7
  55. package/dist/{cli-1gevjrc1.js → cli-bzcwwebm.js} +1 -1
  56. package/dist/{cli-sjk85d7v.js → cli-cq4am6vg.js} +3 -3
  57. package/dist/{cli-f1sdh8ca.js → cli-d5pc8ep0.js} +103 -9
  58. package/dist/{cli-7m6bbtab.js → cli-ea7nz50q.js} +12 -12
  59. package/dist/{cli-zkbz8m2q.js → cli-fkpnx3vf.js} +1 -1
  60. package/dist/{cli-ya1cj689.js → cli-fw67mnyc.js} +1 -1
  61. package/dist/{cli-5basv0e7.js → cli-gkv0r2hq.js} +1 -1
  62. package/dist/{cli-nkfv398a.js → cli-gse7bp3z.js} +12 -10
  63. package/dist/{cli-4djg31jh.js → cli-gtj12v95.js} +1 -1
  64. package/dist/{cli-qn79645p.js → cli-h9d3sdnc.js} +1 -1
  65. package/dist/{cli-tgmate57.js → cli-hdhpdrka.js} +6 -23
  66. package/dist/{cli-fgm2mad9.js → cli-hhtbandk.js} +2 -2
  67. package/dist/cli-hyqksecw.js +1907 -0
  68. package/dist/{cli-t25rq8mg.js → cli-ja450998.js} +40 -11
  69. package/dist/{cli-43dsqhcp.js → cli-jbrc98qb.js} +4 -4
  70. package/dist/{cli-82j36f2m.js → cli-jjzxsk47.js} +9 -3
  71. package/dist/{cli-xerdrnqs.js → cli-jyhbvdga.js} +3 -3
  72. package/dist/{cli-t9nxq30h.js → cli-jzerrzgc.js} +8 -8
  73. package/dist/{cli-hv3820ez.js → cli-k0nebh10.js} +1 -1
  74. package/dist/{cli-s6fhqbz1.js → cli-ka48vpev.js} +6 -6
  75. package/dist/{cli-d2epqm0y.js → cli-kezzteka.js} +1 -1
  76. package/dist/{cli-getrvmtx.js → cli-kj84fqxz.js} +2 -2
  77. package/dist/{cli-h0ewec3d.js → cli-kr0jpw9c.js} +1 -1
  78. package/dist/{cli-gq6qhmrr.js → cli-m1sns1da.js} +3 -3
  79. package/dist/{cli-bp2rt28p.js → cli-n1kjs58m.js} +5 -5
  80. package/dist/{cli-rvhaahfv.js → cli-nc4pbwmp.js} +9 -9
  81. package/dist/{cli-d0jb2qnt.js → cli-p3knvk62.js} +74 -47
  82. package/dist/{cli-50whymxq.js → cli-p436yrzp.js} +2 -2
  83. package/dist/{cli-cs26ed89.js → cli-phdzn699.js} +8 -8
  84. package/dist/{cli-b0kqw55g.js → cli-pz1dp12c.js} +1 -1
  85. package/dist/{cli-8a4qg44m.js → cli-pz1nq5xm.js} +6 -6
  86. package/dist/{cli-e87fg3en.js → cli-qzz6tz8s.js} +1 -1
  87. package/dist/{cli-69eq6gdk.js → cli-rmgvwcmy.js} +38 -29
  88. package/dist/{cli-5k1hvycs.js → cli-rv3y60bt.js} +4 -4
  89. package/dist/cli-s33bzmk0.js +27 -0
  90. package/dist/{cli-at67kvnp.js → cli-srktrbby.js} +1 -1
  91. package/dist/{cli-6rmryz03.js → cli-t0jmkcah.js} +14 -14
  92. package/dist/{cli-eetzmsy5.js → cli-t9pzz2eq.js} +2 -2
  93. package/dist/{cli-wdtqkqnq.js → cli-tr19nyn9.js} +4 -4
  94. package/dist/{cli-erh1rgh4.js → cli-ts5yv7dn.js} +165 -88
  95. package/dist/{cli-zqy28rwx.js → cli-tsc3pdfd.js} +4 -4
  96. package/dist/{cli-x7aqhxj5.js → cli-tzw1jr2t.js} +2 -2
  97. package/dist/{cli-n14r8h4n.js → cli-x2cem5vy.js} +6 -4
  98. package/dist/{cli-vx9acp12.js → cli-ybte1fqc.js} +1 -1
  99. package/dist/{cli-xysy1g8x.js → cli-ysv0k1we.js} +2 -2
  100. package/dist/{cli-vdfngx2g.js → cli-ywy8yz6t.js} +2 -2
  101. package/dist/{cli-cpkxh68d.js → cli-z1vam71h.js} +2 -2
  102. package/dist/{cli-zm6bkx3e.js → cli-zexwhj3f.js} +3 -3
  103. package/dist/{cli-j2ybkdk2.js → cli-zhwjdhjr.js} +2 -2
  104. package/dist/{cli-gedf48yw.js → cli-zjdhrzm0.js} +8 -8
  105. package/dist/cli.js +20 -20
  106. package/dist/{codex-adapter-x25xfbnh.js → codex-adapter-2fs2c0n6.js} +8 -8
  107. package/dist/{codex-hook-c0nvm30r.js → codex-hook-jxjv6dy5.js} +10 -3
  108. package/dist/{codex-login-ven5cz5j.js → codex-login-ktfg1cxk.js} +1 -1
  109. package/dist/{codex-session-runner-kn5xnrvp.js → codex-session-runner-r55tmx4c.js} +9 -9
  110. package/dist/{commands-8n59gxmy.js → commands-0mxdy9x8.js} +3 -3
  111. package/dist/{controller-wn3vd217.js → controller-g3vkfhr4.js} +4 -4
  112. package/dist/{controllers-connect-09gvkrhc.js → controllers-connect-4wdmncqt.js} +25 -25
  113. package/dist/core-gsvj5f3z.js +42 -0
  114. package/dist/{cursor-adapter-w1681kp1.js → cursor-adapter-t9qb96q2.js} +2 -2
  115. package/dist/{db-e71keqxk.js → db-487vvyv9.js} +3 -3
  116. package/dist/{db-spg81qtr.js → db-76p7w3gr.js} +2 -2
  117. package/dist/{devin-adapter-fs90ab4v.js → devin-adapter-3bp6rape.js} +1 -1
  118. package/dist/{dispatcher-fr4vawwb.js → dispatcher-64rp6w67.js} +22 -22
  119. package/dist/{docker-1h33jvh9.js → docker-a59g3ebm.js} +2 -2
  120. package/dist/{dsh-adapter-g9yqv09y.js → dsh-adapter-8abzqk5c.js} +2 -2
  121. package/dist/{e2b-y7e5kmzf.js → e2b-3ykbe805.js} +2 -2
  122. package/dist/{e2b-jnk0yeva.js → e2b-dc8f6ctq.js} +2 -2
  123. package/dist/{easter-egg-3d-ac9tv9a6.js → easter-egg-3d-jrrwyf55.js} +1 -1
  124. package/dist/{embedding-space-an77f45k.js → embedding-space-001hhhpk.js} +6 -6
  125. package/dist/{embeddings-jkrehejr.js → embeddings-esj19cnw.js} +1 -1
  126. package/dist/{event-bus-08t2b4y2.js → event-bus-7gbsr0g4.js} +1 -1
  127. package/dist/{execute-3mys4nta.js → execute-301hkxqg.js} +1 -1
  128. package/dist/{external-channel-s6zxpts9.js → external-channel-w10e2j05.js} +2 -2
  129. package/dist/fx-adapter-4sjrbdne.js +20 -0
  130. package/dist/grok-adapter-3a0ezfee.js +20 -0
  131. package/dist/handlers-ef3k11hb.js +41 -0
  132. package/dist/{heartbeat-jjpb44e5.js → heartbeat-tbrj7vhq.js} +25 -25
  133. package/dist/hook-3am1sq68.js +22 -0
  134. package/dist/{hook-y6n23zzj.js → hook-tx917rqw.js} +11 -8
  135. package/dist/{http-8c6y008s.js → http-3rmemtqy.js} +340 -1841
  136. package/dist/{index-mbpxhc4w.js → index-126v2d0t.js} +1 -4
  137. package/dist/{index-xcw7hjt5.js → index-2jw11t8s.js} +26 -26
  138. package/dist/{index-p2f5xg64.js → index-3j803vnb.js} +36259 -34299
  139. package/dist/{index-we3nd2t0.js → index-aetfyx6p.js} +1 -1
  140. package/dist/index-e6bq0exk.js +42 -0
  141. package/dist/{index-0vthtbc2.js → index-gfnq66t1.js} +231 -25
  142. package/dist/index-hf2k1vge.js +39 -0
  143. package/dist/{index-6h3r0vpe.js → index-s7xtvc0f.js} +1 -1
  144. package/dist/index-taxmejj3.js +44 -0
  145. package/dist/{k8s-8326q0rq.js → k8s-36gfn847.js} +2 -2
  146. package/dist/{keepalive-7e9r5dvp.js → keepalive-9px3t7qj.js} +5 -5
  147. package/dist/lead-5vt6f174.js +83 -0
  148. package/dist/{maintenance-d3erjvcg.js → maintenance-vwqjwst6.js} +1 -1
  149. package/dist/{oauth-refresh-sweep-0qh70988.js → oauth-refresh-sweep-yqry3wn4.js} +4 -4
  150. package/dist/{object-webhooks-ac7v2q5p.js → object-webhooks-8s1wtths.js} +7 -7
  151. package/dist/{onboard-5yphtken.js → onboard-hb8czx0p.js} +7 -7
  152. package/dist/{opencode-adapter-0xvyba4m.js → opencode-adapter-djd6m6dk.js} +8 -8
  153. package/dist/{otel-impl-svqp691q.js → otel-impl-2ymwyczz.js} +2 -2
  154. package/dist/{pending-bn4xe5br.js → pending-nxavtvx7.js} +23 -23
  155. package/dist/{pi-mono-adapter-763s8a3w.js → pi-mono-adapter-d2cpmcy4.js} +13 -13
  156. package/dist/{pricing-refresh-kfc215mf.js → pricing-refresh-1yz8jkqv.js} +2 -2
  157. package/dist/{rbac-roles-6r4h2ghj.js → rbac-roles-7s6m31xw.js} +6 -4
  158. package/dist/{rbac-roles-3bznvkpt.js → rbac-roles-dbpx0x9v.js} +3 -3
  159. package/dist/{render-v2-f3qedbpy.js → render-v2-7y20rjrn.js} +7 -7
  160. package/dist/{resume-vcag4ann.js → resume-wz546x47.js} +10 -10
  161. package/dist/{runtime-x0s55z2t.js → runtime-cb5bd9tz.js} +1 -1
  162. package/dist/{session-access-nwzve8q2.js → session-access-4vcft8kq.js} +5 -5
  163. package/dist/{session-source-backfill-jpqfzmgz.js → session-source-backfill-57b50tpw.js} +3 -3
  164. package/dist/{setup-d2smwaem.js → setup-e1tevjyj.js} +1 -1
  165. package/dist/thread-buffer-686pa1p1.js +42 -0
  166. package/dist/{tree-visibility-dwzc8en0.js → tree-visibility-07wf1nct.js} +2 -2
  167. package/dist/{user-merge-jobs-4ce7kma2.js → user-merge-jobs-n20qpv6s.js} +3 -3
  168. package/dist/{virtual-modules-78a6yw71.js → virtual-modules-6fxmn1yv.js} +3 -3
  169. package/dist/{work-objects-m0w1e7q8.js → work-objects-eg7y48pe.js} +25 -25
  170. package/dist/worker-4vp616ms.js +83 -0
  171. package/dist/{worker-follow-up-e3t6f895.js → worker-follow-up-jnvnnf2b.js} +22 -22
  172. package/dist/{x-asbrnafg.js → x-d27jj7z7.js} +2 -2
  173. package/openapi.json +478 -28
  174. package/package.json +3 -3
  175. package/src/be/db/approvals.ts +2 -0
  176. package/src/be/db/runtime.ts +5 -0
  177. package/src/be/db/script-run-sources.ts +17 -0
  178. package/src/be/db-retention.ts +1 -1
  179. package/src/be/db.ts +71 -62
  180. package/src/be/design-system.ts +63 -0
  181. package/src/be/migrations/342_script_run_sources.sql +20 -0
  182. package/src/be/migrations/runner.ts +8 -0
  183. package/src/be/migrations/script-run-sources.ts +51 -0
  184. package/src/be/rbac-roles.ts +2 -0
  185. package/src/be/scripts/typecheck.ts +4 -2
  186. package/src/be/seed-scripts/catalog/design-system-seed.ts +158 -0
  187. package/src/be/seed-scripts/index.ts +9 -0
  188. package/src/be/swarm-config-guard.ts +21 -1
  189. package/src/commands/onboard/agent-fs-version.ts +1 -1
  190. package/src/commands/runner.ts +62 -6
  191. package/src/heartbeat/heartbeat.ts +18 -4
  192. package/src/hooks/codex-hook.ts +15 -4
  193. package/src/hooks/hook.ts +7 -0
  194. package/src/http/all-routes.ts +1 -0
  195. package/src/http/approval-chat-answer.ts +99 -0
  196. package/src/http/approval-requests.ts +280 -225
  197. package/src/http/design-system.ts +103 -0
  198. package/src/http/index.ts +10 -6
  199. package/src/http/pages-public.ts +25 -10
  200. package/src/http/pages.ts +17 -0
  201. package/src/http/person-responder.ts +28 -0
  202. package/src/http/session-cost-recompute.ts +3 -1
  203. package/src/http/session-data.ts +3 -0
  204. package/src/integrations/chat-sdk/adapters.ts +33 -3
  205. package/src/integrations/chat-sdk/inbound.ts +6 -18
  206. package/src/integrations/chat-sdk/mentions.ts +188 -0
  207. package/src/integrations/chat-sdk/outbound.ts +20 -3
  208. package/src/integrations/chat-sdk/router.ts +8 -0
  209. package/src/integrations/chat-sdk/telegram-thread.ts +12 -0
  210. package/src/jira/adf.ts +35 -9
  211. package/src/kv-reserved-namespaces.ts +5 -0
  212. package/src/pages/page-head.ts +11 -1
  213. package/src/prompts/base-prompt.ts +1 -1
  214. package/src/prompts/session-templates.ts +1 -1
  215. package/src/providers/acp-targets.ts +2 -2
  216. package/src/providers/amp-adapter.ts +1 -1
  217. package/src/providers/claude-adapter.ts +21 -1
  218. package/src/providers/claude-sdk-session.ts +22 -3
  219. package/src/providers/claude-session-events.ts +76 -1
  220. package/src/providers/cursor-adapter.ts +1 -1
  221. package/src/providers/dsh-adapter.ts +48 -13
  222. package/src/providers/fx-adapter.ts +2 -2
  223. package/src/providers/pricing-sources.md +3 -0
  224. package/src/providers/types.ts +13 -0
  225. package/src/rbac/legacy-policy.ts +4 -0
  226. package/src/rbac/permissions.ts +8 -0
  227. package/src/scheduler/index.ts +1 -0
  228. package/src/scheduler/scheduler.test.ts +32 -1
  229. package/src/scheduler/scheduler.ts +24 -1
  230. package/src/script-workflows/executor.ts +6 -0
  231. package/src/script-workflows/supervisor.ts +2 -1
  232. package/src/scripts-runtime/sdk-allowlist.ts +2 -0
  233. package/src/scripts-runtime/swarm-sdk.ts +12 -23
  234. package/src/scripts-runtime/types/stdlib.d.ts +4 -1
  235. package/src/scripts-runtime/types/swarm-sdk.d.ts +4 -1
  236. package/src/server.ts +2 -0
  237. package/src/slack/actions.ts +3 -0
  238. package/src/slack/approval-actions.ts +148 -0
  239. package/src/slack/approval-buttons.ts +28 -0
  240. package/src/slack/render-v2.ts +27 -7
  241. package/src/tests/base-prompt.test.ts +6 -2
  242. package/src/tests/chat-sdk-mentions.test.ts +183 -0
  243. package/src/tests/claude-adapter.test.ts +115 -0
  244. package/src/tests/create-page-tool.test.ts +5 -0
  245. package/src/tests/dsh-adapter.test.ts +53 -1
  246. package/src/tests/fixtures/compiled-source-schema-boot.ts +24 -0
  247. package/src/tests/fixtures/fx/acp-updates-recorded.jsonl +1 -1
  248. package/src/tests/fixtures/secret-corpus.ts +43 -1
  249. package/src/tests/heartbeat-stall-thresholds.test.ts +174 -0
  250. package/src/tests/internal-ai/complete-structured.test.ts +105 -0
  251. package/src/tests/internal-ai/credentials.test.ts +149 -0
  252. package/src/tests/internal-ai/task-title.test.ts +78 -0
  253. package/src/tests/jira-adf.test.ts +42 -2
  254. package/src/tests/mcp-input-caps.test.ts +16 -11
  255. package/src/tests/merge-gate-detect-changes.test.ts +208 -16
  256. package/src/tests/migration-342-script-run-sources.test.ts +196 -0
  257. package/src/tests/migration-bunfs-compat.test.ts +129 -9
  258. package/src/tests/rbac-e2e-helpers.test.ts +10 -4
  259. package/src/tests/rbac-e2e-helpers.ts +13 -4
  260. package/src/tests/rbac-roles.test.ts +2 -0
  261. package/src/tests/runner-slot-reconcile.test.ts +102 -0
  262. package/src/tests/runtime-e2b-pools.test.ts +7 -1
  263. package/src/tests/schedule-target-type.test.ts +4 -1
  264. package/src/tests/script-connections.test.ts +2 -0
  265. package/src/tests/script-runs-retention.test.ts +43 -16
  266. package/src/tests/script-workflows-runtime-e2e.test.ts +56 -22
  267. package/src/tests/scripts-http.test.ts +9 -3
  268. package/src/tests/sdk-allowlist.test.ts +26 -13
  269. package/src/tests/sdk-store-progress-skipped.test.ts +12 -5
  270. package/src/tests/secret-rules.test.ts +34 -0
  271. package/src/tests/secret-scrub-gate.test.ts +7 -0
  272. package/src/tests/secret-scrubber.test.ts +62 -2
  273. package/src/tests/seed-scripts.test.ts +2 -2
  274. package/src/tests/slack-render-v2.test.ts +85 -0
  275. package/src/tests/system-one-hosts-ui-mirror.test.ts +1 -0
  276. package/src/tests/vcs-azure-devops.test.ts +10 -0
  277. package/src/tests/vcs-provider.test.ts +8 -0
  278. package/src/themes/design-system.ts +163 -0
  279. package/src/themes/page-theme.ts +28 -19
  280. package/src/tools/chat-post.ts +7 -3
  281. package/src/tools/create-page.ts +3 -0
  282. package/src/tools/design-system.ts +102 -0
  283. package/src/tools/mcp-servers/mcp-server-get.ts +1 -1
  284. package/src/tools/mcp-servers/mcp-server-list.ts +1 -1
  285. package/src/tools/register-chat-channel.ts +11 -2
  286. package/src/tools/skills/skill-get-file.ts +1 -1
  287. package/src/tools/skills/skill-get.ts +1 -1
  288. package/src/tools/skills/skill-list.ts +1 -1
  289. package/src/tools/skills/skill-search.ts +1 -1
  290. package/src/tools/utils.ts +49 -4
  291. package/src/tools/workflows/get-workflow-run.ts +1 -1
  292. package/src/tools/workflows/get-workflow.ts +1 -1
  293. package/src/tools/workflows/list-workflow-runs.ts +1 -1
  294. package/src/tools/workflows/list-workflows.ts +1 -1
  295. package/src/types.ts +67 -1
  296. package/src/utils/internal-ai/complete-structured.ts +36 -5
  297. package/src/utils/internal-ai/credentials.ts +78 -2
  298. package/src/utils/internal-ai/models.ts +37 -1
  299. package/src/utils/internal-ai/task-title.ts +31 -1
  300. package/src/utils/secret-rules.generated.ts +149 -149
  301. package/src/utils/secret-scrubber.ts +111 -5
  302. package/src/vcs/azure-devops.ts +22 -1
  303. package/src/vcs/index.ts +3 -1
  304. package/src/workflows/approval-inline.ts +122 -0
  305. package/src/workflows/approval-notifications.ts +7 -2
  306. package/src/workflows/engine.ts +6 -5
  307. package/src/workflows/executors/agent-task.ts +14 -0
  308. package/src/workflows/executors/system-one-providers.ts +23 -0
  309. package/templates/skills/pages/content.md +34 -8
  310. package/templates/skills/swarm-docs/content.md +13 -0
  311. package/templates/skills/workflow-iterate/content.md +1 -1
  312. package/dist/acp-adapter-x1qqgzwx.js +0 -17
  313. package/dist/cli-n46d87mj.js +0 -98
  314. package/dist/core-2b8bv6ny.js +0 -42
  315. package/dist/fx-adapter-4yet1c4f.js +0 -20
  316. package/dist/grok-adapter-8ge6tw7m.js +0 -20
  317. package/dist/handlers-0r9evrdj.js +0 -41
  318. package/dist/hook-68gbs87k.js +0 -19
  319. package/dist/index-1v23363p.js +0 -39
  320. package/dist/index-30qw6vyw.js +0 -44
  321. package/dist/index-6bm3w6cn.js +0 -40
  322. package/dist/lead-3jpc7kcr.js +0 -79
  323. package/dist/thread-buffer-8fc703jc.js +0 -42
  324. package/dist/worker-3p2vq107.js +0 -79
@@ -122,6 +122,10 @@ const ApprovalVoteSchema = z.object({
122
122
  .optional()
123
123
  .describe("The `respondedBy` the client sent. Unverified; display only."),
124
124
  respondedAt: z.string(),
125
+ via: z
126
+ .object({ channel: z.string(), platformUserId: z.string() })
127
+ .optional()
128
+ .describe("Set when the answer came from a chat button: the channel and the platform user."),
125
129
  });
126
130
 
127
131
  const ApprovalProgressSchema = z
@@ -531,257 +535,308 @@ const listRoute = route({
531
535
 
532
536
  // ─── Handler ─────────────────────────────────────────────────────────────────
533
537
 
534
- export async function handleApprovalRequests(
535
- req: IncomingMessage,
536
- res: ServerResponse,
537
- pathSegments: string[],
538
- queryParams: URLSearchParams,
539
- ): Promise<boolean> {
540
- // 4-segment: POST /api/approval-requests/{id}/respond
541
- if (respondRoute.match(req.method, pathSegments)) {
542
- const parsed = await respondRoute.parse(req, res, pathSegments, queryParams);
543
- if (!parsed) return true;
544
-
545
- const responder = await approvalResponder(req);
546
- if (!responder.ok) {
547
- jsonError(res, responder.message, 403);
548
- return true;
549
- }
538
+ export type ApprovalAnswerResult =
539
+ | { kind: "resolved" | "recorded"; request: ApprovalRequest }
540
+ | { kind: "error"; status: 400 | 403 | 404 | 409; message: string }
541
+ /** `authorizeConfigSet` refused and already sent its own HTTP reply. */
542
+ | { kind: "handled" };
543
+
544
+ export interface ApprovalAnswerInput {
545
+ id: string;
546
+ /** Who answers, from a verified identity (`approvalResponder` or `userApprovalResponder`). */
547
+ responder: ApprovalResponder;
548
+ responses: Record<string, unknown>;
549
+ respondedBy?: string;
550
+ via?: ApprovalVote["via"];
551
+ /** HTTP only: checks the caller may write config. Without it a config `set` answer is refused. */
552
+ authorizeConfigSet?: (keys: string[]) => Promise<boolean>;
553
+ }
550
554
 
551
- const existing = await getApprovalRequestById(parsed.params.id);
552
- if (!existing) {
553
- jsonError(res, "Approval request not found", 404);
554
- return true;
555
- }
555
+ /**
556
+ * Answer an approval request as an already verified responder. The respond
557
+ * route and the chat buttons both go through here, so every check (expiry,
558
+ * approver list, required answers, quorum, first-write-wins resolve) and every
559
+ * side effect (`approval.resolved`, the follow-up task) is the same.
560
+ */
561
+ export async function answerApprovalRequest(
562
+ input: ApprovalAnswerInput,
563
+ ): Promise<ApprovalAnswerResult> {
564
+ const { responder } = input;
565
+
566
+ const existing = await getApprovalRequestById(input.id);
567
+ if (!existing) {
568
+ return { kind: "error", status: 404, message: "Approval request not found" };
569
+ }
556
570
 
557
- if (existing.status !== "pending") {
558
- const reason = existing.resolutionReason ? `: ${existing.resolutionReason}` : "";
559
- jsonError(
560
- res,
561
- `Approval request already resolved with status: ${existing.status}${reason}`,
562
- 409,
563
- );
564
- return true;
565
- }
571
+ if (existing.status !== "pending") {
572
+ const reason = existing.resolutionReason ? `: ${existing.resolutionReason}` : "";
573
+ return {
574
+ kind: "error",
575
+ status: 409,
576
+ message: `Approval request already resolved with status: ${existing.status}${reason}`,
577
+ };
578
+ }
566
579
 
567
- // A late answer never resolves the request: it becomes timeout at once.
568
- // A workflow run then routes on its timeout port on the next heartbeat
569
- // tick through getStuckApprovalRuns, so no approval.resolved is emitted.
570
- if (existing.expiresAt && new Date(existing.expiresAt) < new Date()) {
571
- // The status change and the follow-up task commit together.
572
- await getDbClient().transaction(async () => {
573
- const timedOut = await resolveApprovalRequest(existing.id, {
574
- status: "timeout",
575
- resolutionReason: `Timed out: the answer arrived after the deadline ${existing.expiresAt}`,
576
- });
577
- if (timedOut && !existing.workflowRunId) {
578
- await createApprovalFollowUpTask(timedOut, "hitl.timeout");
579
- }
580
+ // A late answer never resolves the request: it becomes timeout at once.
581
+ // A workflow run then routes on its timeout port on the next heartbeat
582
+ // tick through getStuckApprovalRuns, so no approval.resolved is emitted.
583
+ if (existing.expiresAt && new Date(existing.expiresAt) < new Date()) {
584
+ // The status change and the follow-up task commit together.
585
+ await getDbClient().transaction(async () => {
586
+ const timedOut = await resolveApprovalRequest(existing.id, {
587
+ status: "timeout",
588
+ resolutionReason: `Timed out: the answer arrived after the deadline ${existing.expiresAt}`,
580
589
  });
581
- jsonError(res, `Approval request expired at ${existing.expiresAt}`, 409);
582
- return true;
583
- }
590
+ if (timedOut && !existing.workflowRunId) {
591
+ await createApprovalFollowUpTask(timedOut, "hitl.timeout");
592
+ }
593
+ });
594
+ return {
595
+ kind: "error",
596
+ status: 409,
597
+ message: `Approval request expired at ${existing.expiresAt}`,
598
+ };
599
+ }
584
600
 
585
- const unavailableReason = await getWorkflowApprovalUnavailableReason(existing);
586
- if (unavailableReason) {
587
- jsonError(res, unavailableReason, 409);
588
- return true;
589
- }
601
+ const unavailableReason = await getWorkflowApprovalUnavailableReason(existing);
602
+ if (unavailableReason) {
603
+ return { kind: "error", status: 409, message: unavailableReason };
604
+ }
590
605
 
591
- const approvers = existing.approvers as ApproversShape;
592
- if (!isListedApprover(approvers, responder.responder)) {
593
- jsonError(res, "You are not one of this request's approvers", 403);
594
- return true;
595
- }
606
+ const approvers = existing.approvers as ApproversShape;
607
+ if (!isListedApprover(approvers, responder)) {
608
+ return { kind: "error", status: 403, message: "You are not one of this request's approvers" };
609
+ }
596
610
 
597
- const questions = existing.questions as ApprovalQuestion[];
598
- const missingRequired = missingRequiredResponseIds(questions, parsed.body.responses);
599
- if (missingRequired.length > 0) {
600
- jsonError(res, `Responses missing or invalid: ${missingRequired.join(", ")}`, 400);
601
- return true;
602
- }
611
+ const questions = existing.questions as ApprovalQuestion[];
612
+ const missingRequired = missingRequiredResponseIds(questions, input.responses);
613
+ if (missingRequired.length > 0) {
614
+ return {
615
+ kind: "error",
616
+ status: 400,
617
+ message: `Responses missing or invalid: ${missingRequired.join(", ")}`,
618
+ };
619
+ }
603
620
 
604
- // Config answers (D6) are checked here and replaced by their results (D7)
605
- // before the vote exists, so no plaintext reaches any stored or sent copy.
606
- const configQuestions = questions.filter(isConfigQuestion);
607
- const configAnswers = new Map<
608
- string,
609
- { question: StoredConfigQuestion; answer: ConfigAnswer }
610
- >();
611
- for (const question of configQuestions) {
612
- const state = await readConfigState(question.config);
613
- const answer = parseConfigAnswer(question, parsed.body.responses[question.id], state);
614
- if (!answer.ok) {
615
- jsonError(res, answer.error, 400);
616
- return true;
617
- }
618
- configAnswers.set(question.id, { question, answer: answer.answer });
619
- }
620
- if (configAnswers.size > 0 && approvers.policy !== "any") {
621
- jsonError(res, 'Config questions need approvers.policy "any"', 409);
622
- return true;
621
+ // Config answers (D6) are checked here and replaced by their results (D7)
622
+ // before the vote exists, so no plaintext reaches any stored or sent copy.
623
+ const configQuestions = questions.filter(isConfigQuestion);
624
+ const configAnswers = new Map<string, { question: StoredConfigQuestion; answer: ConfigAnswer }>();
625
+ for (const question of configQuestions) {
626
+ const state = await readConfigState(question.config);
627
+ const answer = parseConfigAnswer(question, input.responses[question.id], state);
628
+ if (!answer.ok) {
629
+ return { kind: "error", status: 400, message: answer.error };
623
630
  }
624
- if ([...configAnswers.values()].some(({ answer }) => answer.action === "set")) {
625
- if (!(await ensureConfigAdmin(req, res, "config.write.any"))) return true;
626
- for (const { question, answer } of configAnswers.values()) {
627
- if (answer.action !== "set") continue;
628
- if (!(await ensureHumanOnlyConfigWrite(req, res, question.config.key))) return true;
629
- }
630
- // Admission only checked `approval.respond`; `ensureConfigAdmin` passes
631
- // every user, so check the config write grant here as PUT /api/config would.
632
- const userId = authUserId(getRequestAuth(req));
633
- if (userId && isRbacEnabled()) {
634
- const grant = await getUserGrant(userId);
635
- if (!grant.grantsAll && !grant.verbs.has("config.write.any")) {
636
- jsonError(res, "Forbidden: setting a config value needs 'config.write.any'", 403);
637
- return true;
638
- }
639
- }
631
+ configAnswers.set(question.id, { question, answer: answer.answer });
632
+ }
633
+ if (configAnswers.size > 0 && approvers.policy !== "any") {
634
+ return { kind: "error", status: 409, message: 'Config questions need approvers.policy "any"' };
635
+ }
636
+ const setKeys = [...configAnswers.values()]
637
+ .filter(({ answer }) => answer.action === "set")
638
+ .map(({ question }) => question.config.key);
639
+ if (setKeys.length > 0) {
640
+ if (!input.authorizeConfigSet) {
641
+ return { kind: "error", status: 409, message: "Config values are set on the dashboard" };
640
642
  }
641
- const safeResponses: Record<string, unknown> = { ...parsed.body.responses };
642
- for (const id of configAnswers.keys()) delete safeResponses[id];
643
-
644
- // Determine status from responses: if any approval question has approved: false → rejected
645
- let status: "approved" | "rejected" = "approved";
646
- for (const q of questions) {
647
- if (q.type === "approval") {
648
- const answer = safeResponses[q.id] as { approved?: boolean } | undefined;
649
- if (answer && answer.approved === false) {
650
- status = "rejected";
651
- break;
652
- }
643
+ if (!(await input.authorizeConfigSet(setKeys))) return { kind: "handled" };
644
+ }
645
+ const safeResponses: Record<string, unknown> = { ...input.responses };
646
+ for (const id of configAnswers.keys()) delete safeResponses[id];
647
+
648
+ // Determine status from responses: if any approval question has approved: false → rejected
649
+ let status: "approved" | "rejected" = "approved";
650
+ for (const q of questions) {
651
+ if (q.type === "approval") {
652
+ const answer = safeResponses[q.id] as { approved?: boolean } | undefined;
653
+ if (answer && answer.approved === false) {
654
+ status = "rejected";
655
+ break;
653
656
  }
654
657
  }
658
+ }
655
659
 
656
- const responderId = responderKey(responder.responder);
657
- const respondedAt = new Date().toISOString();
658
- const configWrites: { result: ConfigResult; value: string }[] = [];
659
- // One write transaction (BEGIN IMMEDIATE) so concurrent answers to an
660
- // `all` / `{ min: N }` request append in turn and never drop each other.
661
- // Config writes share it, so a lost race writes nothing.
662
- const outcome = await getDbClient()
663
- .transaction(async () => {
664
- const current = await getApprovalRequestById(parsed.params.id);
665
- if (!current || current.status !== "pending") return { kind: "unavailable" as const };
666
- const prior = current.approvals ?? [];
667
- if (prior.some((v) => v.responder === responderId)) return { kind: "duplicate" as const };
668
-
669
- // Config values are written only when the request resolves approved (D8).
670
- const responses = { ...safeResponses };
671
- for (const [id, { question, answer }] of configAnswers) {
672
- if (status === "rejected" || answer.action === "skip") {
673
- responses[id] = skippedConfigResult(question);
674
- } else if (answer.action === "keep") {
675
- const kept = await keptConfigResult(question);
676
- if (!kept) {
677
- throw new ConfigRespondAbort(
678
- "conflict",
679
- `config question "${id}": the key was removed before the answer was saved`,
680
- );
681
- }
682
- responses[id] = kept;
683
- } else {
684
- const written = await applyConfigAnswer(question, answer.value);
685
- configWrites.push({ result: written, value: answer.value });
686
- responses[id] = written;
660
+ const responderId = responderKey(responder);
661
+ const respondedAt = new Date().toISOString();
662
+ const configWrites: { result: ConfigResult; value: string }[] = [];
663
+ // One write transaction (BEGIN IMMEDIATE) so concurrent answers to an
664
+ // `all` / `{ min: N }` request append in turn and never drop each other.
665
+ // Config writes share it, so a lost race writes nothing.
666
+ const outcome = await getDbClient()
667
+ .transaction(async () => {
668
+ const current = await getApprovalRequestById(input.id);
669
+ if (!current || current.status !== "pending") return { kind: "unavailable" as const };
670
+ const prior = current.approvals ?? [];
671
+ if (prior.some((v) => v.responder === responderId)) return { kind: "duplicate" as const };
672
+
673
+ // Config values are written only when the request resolves approved (D8).
674
+ const responses = { ...safeResponses };
675
+ for (const [id, { question, answer }] of configAnswers) {
676
+ if (status === "rejected" || answer.action === "skip") {
677
+ responses[id] = skippedConfigResult(question);
678
+ } else if (answer.action === "keep") {
679
+ const kept = await keptConfigResult(question);
680
+ if (!kept) {
681
+ throw new ConfigRespondAbort(
682
+ "conflict",
683
+ `config question "${id}": the key was removed before the answer was saved`,
684
+ );
687
685
  }
686
+ responses[id] = kept;
687
+ } else {
688
+ const written = await applyConfigAnswer(question, answer.value);
689
+ configWrites.push({ result: written, value: answer.value });
690
+ responses[id] = written;
688
691
  }
692
+ }
689
693
 
690
- const vote: ApprovalVote = {
691
- responder: responderId,
692
- approved: status === "approved",
693
- responses,
694
- ...(parsed.body.respondedBy ? { claimedRespondedBy: parsed.body.respondedBy } : {}),
695
- respondedAt,
696
- };
697
- const votes = [...prior, vote];
698
- if (status === "rejected" || (await approvalQuorumMet(approvers, votes))) {
699
- const resolved = await resolveApprovalRequest(
700
- parsed.params.id,
701
- { status, responses, approvals: votes, resolvedBy: responderId },
702
- { requireActionableWorkflow: true },
703
- );
704
- if (!resolved && configWrites.length > 0) throw new ConfigRespondAbort("unavailable");
705
- return resolved
706
- ? { kind: "resolved" as const, request: resolved }
707
- : { kind: "unavailable" as const };
708
- }
709
- const recorded = (await recordApprovalVotes(parsed.params.id, votes))
710
- ? await getApprovalRequestById(parsed.params.id)
711
- : null;
712
- return recorded
713
- ? { kind: "recorded" as const, request: recorded }
714
- : { kind: "unavailable" as const };
715
- })
716
- .catch((error: unknown) => {
717
- if (!(error instanceof ConfigRespondAbort)) throw error;
718
- // Rolled back: nothing was written.
719
- configWrites.length = 0;
720
- return error.kind === "conflict"
721
- ? { kind: "conflict" as const, message: error.message }
722
- : { kind: "unavailable" as const };
723
- });
724
-
725
- if (outcome.kind === "conflict") {
726
- jsonError(res, outcome.message, 409);
727
- return true;
728
- }
729
- // The transaction has committed: run what PUT /api/config runs after a write.
730
- for (const { result, value } of configWrites) {
731
- try {
732
- await runConfigWriteSideEffects(result.scope, result.key, value);
733
- } catch (err) {
734
- console.error(
735
- "[approval-requests] Config side effects failed:",
736
- scrubSecrets(err instanceof Error ? err.message : String(err)),
694
+ const vote: ApprovalVote = {
695
+ responder: responderId,
696
+ approved: status === "approved",
697
+ responses,
698
+ ...(input.respondedBy ? { claimedRespondedBy: input.respondedBy } : {}),
699
+ ...(input.via ? { via: input.via } : {}),
700
+ respondedAt,
701
+ };
702
+ const votes = [...prior, vote];
703
+ if (status === "rejected" || (await approvalQuorumMet(approvers, votes))) {
704
+ const resolved = await resolveApprovalRequest(
705
+ input.id,
706
+ { status, responses, approvals: votes, resolvedBy: responderId },
707
+ { requireActionableWorkflow: true },
737
708
  );
709
+ if (!resolved && configWrites.length > 0) throw new ConfigRespondAbort("unavailable");
710
+ return resolved
711
+ ? { kind: "resolved" as const, request: resolved }
712
+ : { kind: "unavailable" as const };
738
713
  }
739
- }
714
+ const recorded = (await recordApprovalVotes(input.id, votes))
715
+ ? await getApprovalRequestById(input.id)
716
+ : null;
717
+ return recorded
718
+ ? { kind: "recorded" as const, request: recorded }
719
+ : { kind: "unavailable" as const };
720
+ })
721
+ .catch((error: unknown) => {
722
+ if (!(error instanceof ConfigRespondAbort)) throw error;
723
+ // Rolled back: nothing was written.
724
+ configWrites.length = 0;
725
+ return error.kind === "conflict"
726
+ ? { kind: "conflict" as const, message: error.message }
727
+ : { kind: "unavailable" as const };
728
+ });
740
729
 
741
- if (outcome.kind === "duplicate") {
742
- jsonError(res, "You already answered this approval request", 409);
743
- return true;
744
- }
745
- if (outcome.kind === "recorded") {
746
- respondRoute.respond(res, 200, {
747
- approvalRequest: await toApprovalRequestResponse(outcome.request),
748
- });
749
- return true;
730
+ if (outcome.kind === "conflict") {
731
+ return { kind: "error", status: 409, message: outcome.message };
732
+ }
733
+ // The transaction has committed: run what PUT /api/config runs after a write.
734
+ for (const { result, value } of configWrites) {
735
+ try {
736
+ await runConfigWriteSideEffects(result.scope, result.key, value);
737
+ } catch (err) {
738
+ console.error(
739
+ "[approval-requests] Config side effects failed:",
740
+ scrubSecrets(err instanceof Error ? err.message : String(err)),
741
+ );
750
742
  }
751
- const updated = outcome.kind === "resolved" ? outcome.request : null;
743
+ }
752
744
 
753
- if (!updated) {
754
- const latest = await getApprovalRequestById(parsed.params.id);
755
- const unavailableAfterRace = latest
756
- ? await getWorkflowApprovalUnavailableReason(latest)
757
- : null;
758
- jsonError(
759
- res,
745
+ if (outcome.kind === "duplicate") {
746
+ return { kind: "error", status: 409, message: "You already answered this approval request" };
747
+ }
748
+ if (outcome.kind === "recorded") {
749
+ return { kind: "recorded", request: outcome.request };
750
+ }
751
+ const updated = outcome.kind === "resolved" ? outcome.request : null;
752
+
753
+ if (!updated) {
754
+ const latest = await getApprovalRequestById(input.id);
755
+ const unavailableAfterRace = latest ? await getWorkflowApprovalUnavailableReason(latest) : null;
756
+ return {
757
+ kind: "error",
758
+ status: 409,
759
+ message:
760
760
  unavailableAfterRace ??
761
- `Failed to resolve approval request (status: ${latest?.status ?? "unknown"})`,
762
- 409,
763
- );
764
- return true;
765
- }
761
+ `Failed to resolve approval request (status: ${latest?.status ?? "unknown"})`,
762
+ };
763
+ }
766
764
 
767
- // Emit for every answered request, workflow or standalone. Workflow resume
768
- // ignores a payload without a run and step id, and the extension bridge
769
- // (`post.approval.resolved`) needs the standalone ones.
770
- workflowEventBus.emit("approval.resolved", {
771
- requestId: updated.id,
772
- status: updated.status,
773
- responses: updated.responses,
774
- workflowRunId: updated.workflowRunId ?? undefined,
775
- workflowRunStepId: updated.workflowRunStepId ?? undefined,
776
- sourceTaskId: updated.sourceTaskId ?? undefined,
777
- });
765
+ // Emit for every answered request, workflow or standalone. Workflow resume
766
+ // ignores a payload without a run and step id, and the extension bridge
767
+ // (`post.approval.resolved`) needs the standalone ones.
768
+ workflowEventBus.emit("approval.resolved", {
769
+ requestId: updated.id,
770
+ status: updated.status,
771
+ responses: updated.responses,
772
+ workflowRunId: updated.workflowRunId ?? undefined,
773
+ workflowRunStepId: updated.workflowRunStepId ?? undefined,
774
+ sourceTaskId: updated.sourceTaskId ?? undefined,
775
+ });
776
+
777
+ // For standalone (non-workflow) requests, create a follow-up task
778
+ // so the requesting agent is notified of the human's response
779
+ await createApprovalFollowUpTask(updated, "hitl.follow_up");
780
+
781
+ return { kind: "resolved", request: updated };
782
+ }
778
783
 
779
- // For standalone (non-workflow) requests, create a follow-up task
780
- // so the requesting agent is notified of the human's response
781
- await createApprovalFollowUpTask(updated, "hitl.follow_up");
784
+ /** The config write checks PUT /api/config runs, for a respond call that sets config values. */
785
+ async function authorizeHttpConfigSet(
786
+ req: IncomingMessage,
787
+ res: ServerResponse,
788
+ keys: string[],
789
+ ): Promise<boolean> {
790
+ if (!(await ensureConfigAdmin(req, res, "config.write.any"))) return false;
791
+ for (const key of keys) {
792
+ if (!(await ensureHumanOnlyConfigWrite(req, res, key))) return false;
793
+ }
794
+ // Admission only checked `approval.respond`; `ensureConfigAdmin` passes
795
+ // every user, so check the config write grant here as PUT /api/config would.
796
+ const userId = authUserId(getRequestAuth(req));
797
+ if (userId && isRbacEnabled()) {
798
+ const grant = await getUserGrant(userId);
799
+ if (!grant.grantsAll && !grant.verbs.has("config.write.any")) {
800
+ jsonError(res, "Forbidden: setting a config value needs 'config.write.any'", 403);
801
+ return false;
802
+ }
803
+ }
804
+ return true;
805
+ }
806
+
807
+ export async function handleApprovalRequests(
808
+ req: IncomingMessage,
809
+ res: ServerResponse,
810
+ pathSegments: string[],
811
+ queryParams: URLSearchParams,
812
+ ): Promise<boolean> {
813
+ // 4-segment: POST /api/approval-requests/{id}/respond
814
+ if (respondRoute.match(req.method, pathSegments)) {
815
+ const parsed = await respondRoute.parse(req, res, pathSegments, queryParams);
816
+ if (!parsed) return true;
782
817
 
818
+ const responder = await approvalResponder(req);
819
+ if (!responder.ok) {
820
+ jsonError(res, responder.message, 403);
821
+ return true;
822
+ }
823
+ const result = await answerApprovalRequest({
824
+ id: parsed.params.id,
825
+ responder: responder.responder,
826
+ responses: parsed.body.responses,
827
+ respondedBy: parsed.body.respondedBy,
828
+ authorizeConfigSet: (keys) => authorizeHttpConfigSet(req, res, keys),
829
+ });
830
+ if (result.kind === "handled") return true;
831
+ if (result.kind === "error") {
832
+ jsonError(res, result.message, result.status);
833
+ return true;
834
+ }
783
835
  respondRoute.respond(res, 200, {
784
- approvalRequest: await toApprovalRequestResponse(updated, { withConfigState: true }),
836
+ approvalRequest: await toApprovalRequestResponse(
837
+ result.request,
838
+ result.kind === "resolved" ? { withConfigState: true } : undefined,
839
+ ),
785
840
  });
786
841
  return true;
787
842
  }
@@ -0,0 +1,103 @@
1
+ import type { IncomingMessage, ServerResponse } from "node:http";
2
+ import { z } from "zod";
3
+ import { getDesignSystem, type StoredDesignSystem, saveDesignSystem } from "../be/design-system";
4
+ import { can } from "../rbac";
5
+ import { buildDesignSystem, DesignSystemError } from "../themes/design-system";
6
+ import { DesignSystemInputSchema, DesignSystemSchema } from "../types";
7
+ import { agentFirstPrincipal } from "./request-principal";
8
+ import { route } from "./route-def";
9
+ import { jsonError } from "./utils";
10
+
11
+ /**
12
+ * The org design system over REST (src/themes/design-system.ts). The MCP
13
+ * tools `design-system-get` / `design-system-set` share the same storage.
14
+ */
15
+
16
+ const DesignSystemStateSchema = z.object({
17
+ status: z.enum(["none", "invalid", "active", "declined"]),
18
+ designSystem: DesignSystemSchema.nullable(),
19
+ invalidReason: z.string().optional(),
20
+ previous: DesignSystemSchema.nullable(),
21
+ });
22
+
23
+ const getDesignSystemRoute = route({
24
+ method: "get",
25
+ path: "/api/design-system",
26
+ pattern: ["api", "design-system"],
27
+ summary: "Get the org design system",
28
+ tags: ["Pages"],
29
+ responses: {
30
+ 200: {
31
+ description: "The org design system and the value it replaced",
32
+ schema: DesignSystemStateSchema,
33
+ },
34
+ },
35
+ });
36
+
37
+ const putDesignSystemRoute = route({
38
+ method: "put",
39
+ path: "/api/design-system",
40
+ pattern: ["api", "design-system"],
41
+ summary: "Set or decline the org design system",
42
+ tags: ["Pages"],
43
+ rbac: { permission: "design-system.write" },
44
+ body: DesignSystemInputSchema,
45
+ responses: {
46
+ 200: {
47
+ description: "The saved, normalized design system",
48
+ schema: z.object({ designSystem: DesignSystemSchema, ignoredTokens: z.array(z.string()) }),
49
+ },
50
+ 400: { description: "Invalid design system" },
51
+ 403: { description: "Permission denied" },
52
+ },
53
+ });
54
+
55
+ function recordOf(stored: StoredDesignSystem) {
56
+ return "record" in stored ? stored.record : null;
57
+ }
58
+
59
+ export async function handleDesignSystem(
60
+ req: IncomingMessage,
61
+ res: ServerResponse,
62
+ pathSegments: string[],
63
+ queryParams: URLSearchParams,
64
+ myAgentId: string | undefined,
65
+ ): Promise<boolean> {
66
+ if (getDesignSystemRoute.match(req.method, pathSegments)) {
67
+ const parsed = await getDesignSystemRoute.parse(req, res, pathSegments, queryParams);
68
+ if (!parsed) return true;
69
+ const { current, previous } = await getDesignSystem();
70
+ getDesignSystemRoute.respond(res, 200, {
71
+ status: current.status,
72
+ designSystem: recordOf(current),
73
+ ...("reason" in current ? { invalidReason: current.reason } : {}),
74
+ previous: recordOf(previous),
75
+ });
76
+ return true;
77
+ }
78
+
79
+ if (putDesignSystemRoute.match(req.method, pathSegments)) {
80
+ const parsed = await putDesignSystemRoute.parse(req, res, pathSegments, queryParams);
81
+ if (!parsed) return true;
82
+ const principal = await agentFirstPrincipal(req, myAgentId);
83
+ const decision = can({ principal, verb: "design-system.write", source: "http" });
84
+ if (!decision.allow) {
85
+ jsonError(res, decision.reason, 403);
86
+ return true;
87
+ }
88
+ try {
89
+ const { record, ignored } = buildDesignSystem(parsed.body, {
90
+ userId: principal.kind === "user" ? principal.userId : null,
91
+ ...(principal.kind === "agent" ? { agentId: principal.agentId } : {}),
92
+ });
93
+ await saveDesignSystem(record);
94
+ putDesignSystemRoute.respond(res, 200, { designSystem: record, ignoredTokens: ignored });
95
+ } catch (err) {
96
+ if (!(err instanceof DesignSystemError)) throw err;
97
+ jsonError(res, err.message, 400);
98
+ }
99
+ return true;
100
+ }
101
+
102
+ return false;
103
+ }