@desplega.ai/agent-swarm 1.169.0 → 1.171.1

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 (349) hide show
  1. package/README.md +11 -2
  2. package/dist/{acp-adapter-m47zfx4a.js → acp-adapter-wnhq4ydy.js} +6 -6
  3. package/dist/{actions-ws7k3tvq.js → actions-45eyf0ns.js} +31 -29
  4. package/dist/{amp-adapter-nvv8k8j5.js → amp-adapter-f5dr6dm0.js} +6 -6
  5. package/dist/{anthropic-messages-13yn502s.js → anthropic-messages-etkbxhhy.js} +11 -11
  6. package/dist/{app-80w6qspx.js → app-qv86qhzz.js} +9 -9
  7. package/dist/{artifact-fey7dvj9.js → artifact-eczsknc3.js} +6 -3
  8. package/dist/{assistant-jtq439kw.js → assistant-10yaeebp.js} +34 -32
  9. package/dist/{azure-openai-responses-9st34pfz.js → azure-openai-responses-xap57x4b.js} +7 -7
  10. package/dist/{boot-reembed-feda8wn8.js → boot-reembed-p2wbqxm4.js} +8 -8
  11. package/dist/{boot-reembed-3nc0aaed.js → boot-reembed-wyb785et.js} +8 -8
  12. package/dist/{boot-scrub-sweep-grsa2er0.js → boot-scrub-sweep-daaqcs9t.js} +9 -9
  13. package/dist/{boot-seeds-gcfgq44f.js → boot-seeds-1pvzyx4h.js} +12 -12
  14. package/dist/{claude-adapter-pjv2q7t8.js → claude-adapter-v2py1c6g.js} +15 -15
  15. package/dist/{claude-managed-adapter-0wa8se82.js → claude-managed-adapter-kqqqhp2q.js} +2 -2
  16. package/dist/{claude-managed-setup-zxa9p9tx.js → claude-managed-setup-bnmjarjc.js} +11 -8
  17. package/dist/{claude-sdk-session-c9j6k9kx.js → claude-sdk-session-mk938tpt.js} +15 -15
  18. package/dist/cli-0p3enk35.js +188 -0
  19. package/dist/cli-1srmzpr3.js +16 -0
  20. package/dist/{cli-zzev32jw.js → cli-231av4y6.js} +6 -6
  21. package/dist/{cli-eqfbsxsn.js → cli-2aap68ns.js} +14 -11
  22. package/dist/{cli-mv2520nm.js → cli-2bw3w47j.js} +1 -1
  23. package/dist/{cli-km8559dm.js → cli-2k8gyaey.js} +18 -10
  24. package/dist/{cli-efnd2kce.js → cli-2rbt7at8.js} +6 -1
  25. package/dist/{cli-xvc3q9br.js → cli-451ks6aw.js} +1 -1
  26. package/dist/{cli-7vz49g7h.js → cli-48ve9gsj.js} +101 -4
  27. package/dist/{cli-zp38xvtm.js → cli-5rqrj7q0.js} +1 -1
  28. package/dist/{cli-km4x66j0.js → cli-5y67yrt6.js} +13 -13
  29. package/dist/{cli-3ry5gx4f.js → cli-6pxmb99j.js} +2 -2
  30. package/dist/cli-6zx22mv6.js +0 -0
  31. package/dist/{cli-zp67qg5x.js → cli-7a0sde2x.js} +72 -1
  32. package/dist/{cli-v1w7pbd8.js → cli-7jykv7ef.js} +1 -1
  33. package/dist/{cli-rfphkzh5.js → cli-7pz3b7x5.js} +24 -4
  34. package/dist/{cli-mb75wpxf.js → cli-81r1wjyv.js} +1 -1
  35. package/dist/cli-8ntwbxmm.js +1351 -0
  36. package/dist/{cli-f14fvzag.js → cli-a1b9b32n.js} +6 -1
  37. package/dist/{cli-rg1c8ccw.js → cli-amvnn9wz.js} +497 -73
  38. package/dist/{cli-fyeft04q.js → cli-apnwqe6h.js} +2 -2
  39. package/dist/{cli-m23r88re.js → cli-bkdbswyn.js} +3 -3
  40. package/dist/{cli-qg2zhjfc.js → cli-c9cnsnms.js} +8 -8
  41. package/dist/cli-cd0hv9nh.js +32 -0
  42. package/dist/{cli-wt7ccy4r.js → cli-d161g69q.js} +9 -1
  43. package/dist/{cli-rbr91whd.js → cli-d78fccnb.js} +9 -5
  44. package/dist/cli-db3m6zdt.js +362 -0
  45. package/dist/{cli-hf5s9pgf.js → cli-e3pmyt39.js} +1 -1
  46. package/dist/{cli-91r17hb1.js → cli-ehf1dfay.js} +3 -3
  47. package/dist/{cli-61tbnjpf.js → cli-f3vy7ncj.js} +767 -541
  48. package/dist/{cli-sajr098b.js → cli-f651ypy4.js} +3 -3
  49. package/dist/{cli-9k7mqz00.js → cli-ge593j7e.js} +30 -3
  50. package/dist/cli-h8w3fg83.js +17 -0
  51. package/dist/{cli-dv76vq5d.js → cli-hadkza7w.js} +685 -209
  52. package/dist/{cli-jkfxpg1b.js → cli-hrbedqp0.js} +2 -2
  53. package/dist/{cli-xvdgasgy.js → cli-hsem16hb.js} +114 -9
  54. package/dist/{cli-kp3vfknv.js → cli-j8xzym9k.js} +2 -2
  55. package/dist/{cli-swrz3mj8.js → cli-jn9wk8z8.js} +1 -1
  56. package/dist/{cli-a8vps458.js → cli-jr749y58.js} +17274 -17242
  57. package/dist/{cli-b7y8113e.js → cli-k2v5x13t.js} +1 -1
  58. package/dist/{cli-bqrs5ycj.js → cli-m4csbs67.js} +2 -2
  59. package/dist/{cli-yvxfaem2.js → cli-ndvfgmk8.js} +9 -5
  60. package/dist/{cli-r7eeddkq.js → cli-ph3145b7.js} +3 -3
  61. package/dist/cli-ppy4nnnh.js +168 -0
  62. package/dist/{cli-e5qk3m2a.js → cli-pw9x22wp.js} +19 -19
  63. package/dist/{cli-s0k2j7q9.js → cli-pwnxv8pw.js} +10 -10
  64. package/dist/{cli-jv36y8wz.js → cli-rrbctenq.js} +1 -1
  65. package/dist/{cli-vejds37t.js → cli-tb8p51kg.js} +3 -3
  66. package/dist/cli-tqzk05ty.js +832 -0
  67. package/dist/{cli-rh44xx46.js → cli-vtqrsgnm.js} +15 -15
  68. package/dist/{cli-7mhy3ths.js → cli-x61srfpp.js} +5 -5
  69. package/dist/{cli-n4z21pt8.js → cli-xy6sgy6p.js} +1 -1
  70. package/dist/{cli-w6xa5nf5.js → cli-y1j1ggbf.js} +8 -8
  71. package/dist/{cli-jvmtxqtc.js → cli-ywh2a87k.js} +7 -2
  72. package/dist/{cli-3qhyh31j.js → cli-ywm1azg9.js} +6 -0
  73. package/dist/{cli-8xjst8q2.js → cli-z9cvwx5m.js} +11 -11
  74. package/dist/{cli-ysnkvdx6.js → cli-zh93km01.js} +313 -91
  75. package/dist/{cli-z48ggfyq.js → cli-zxm9p3x4.js} +2 -2
  76. package/dist/cli.js +42 -24
  77. package/dist/{codex-adapter-0kpg09ca.js → codex-adapter-cg8vntj1.js} +13 -13
  78. package/dist/{codex-hook-295jpbfa.js → codex-hook-7ba15hjd.js} +5 -3
  79. package/dist/{codex-login-g1cyt5zm.js → codex-login-841kv5fk.js} +7 -5
  80. package/dist/{codex-session-runner-8n672hxh.js → codex-session-runner-jxs6n1qx.js} +13 -13
  81. package/dist/{commands-mhmg5n0x.js → commands-8zhezbzr.js} +10 -10
  82. package/dist/controller-hq5ggpcp.js +193 -0
  83. package/dist/controllers-connect-q0brsq11.js +265 -0
  84. package/dist/{cursor-adapter-wn8n5zzk.js → cursor-adapter-t4pr1m3c.js} +5 -5
  85. package/dist/db-d80sy99v.js +71 -0
  86. package/dist/{db-wa6s1mwv.js → db-ggc4b127.js} +8 -8
  87. package/dist/{devin-adapter-bffjj5n4.js → devin-adapter-xgtj680j.js} +2 -2
  88. package/dist/{dispatcher-nhs2pkr8.js → dispatcher-eascgc1z.js} +30 -28
  89. package/dist/docker-f503k9p0.js +201 -0
  90. package/dist/{dsh-adapter-5423p70m.js → dsh-adapter-2h8m4cab.js} +5 -5
  91. package/dist/e2b-66xra4az.js +202 -0
  92. package/dist/{e2b-nd50eccg.js → e2b-xwhyj8cw.js} +43 -527
  93. package/dist/{event-bus-vnfthafg.js → event-bus-vjtv82gm.js} +2 -2
  94. package/dist/{grok-adapter-28pkdt80.js → grok-adapter-8ram8zse.js} +7 -7
  95. package/dist/{handlers-5rtf9nng.js → handlers-hypxbg7e.js} +33 -31
  96. package/dist/heartbeat-ge72pt7q.js +124 -0
  97. package/dist/{hook-krjfkpzy.js → hook-grgtyrad.js} +20 -17
  98. package/dist/{hook-qkm73zk6.js → hook-xzwg1zwp.js} +13 -13
  99. package/dist/{http-a397xcn4.js → http-2nf2axqq.js} +1958 -205
  100. package/dist/{index-vvsq7v45.js → index-0h5dd9xg.js} +30 -28
  101. package/dist/{index-ac0v8v9d.js → index-27aez391.js} +8 -8
  102. package/dist/{index-rtxg15ah.js → index-57svck0z.js} +39 -29
  103. package/dist/{index-ytdhtdry.js → index-6zehd2p5.js} +31 -22
  104. package/dist/{index-kqre45fr.js → index-9egx96ey.js} +30 -28
  105. package/dist/{keepalive-psfh8ysx.js → keepalive-5pjbsz8f.js} +10 -10
  106. package/dist/{lead-m6rppjn7.js → lead-g19prqhd.js} +48 -46
  107. package/dist/{maintenance-41f837ke.js → maintenance-1brc7q4c.js} +8 -8
  108. package/dist/{node-8zkdq42h.js → node-c9we95xf.js} +9 -9
  109. package/dist/{oauth-refresh-sweep-6hr55hm8.js → oauth-refresh-sweep-rhe857nd.js} +9 -9
  110. package/dist/{onboard-ktrtd7cz.js → onboard-6bcg69eg.js} +25 -15
  111. package/dist/{openai-codex-responses-jzxkta9b.js → openai-codex-responses-pgvtddvv.js} +3 -3
  112. package/dist/{openai-responses-m3g43rrt.js → openai-responses-9dyzwzkr.js} +9 -9
  113. package/dist/{opencode-adapter-yjyqynzf.js → opencode-adapter-f1zby94p.js} +3 -3
  114. package/dist/{otel-impl-dq4f2k3m.js → otel-impl-y237rck3.js} +5 -5
  115. package/dist/{pi-mono-adapter-e5v9w0hv.js → pi-mono-adapter-fx6k5wwh.js} +38 -27
  116. package/dist/{pricing-refresh-kmk7j1ra.js → pricing-refresh-se1qg8wn.js} +10 -10
  117. package/dist/{rbac-roles-9w1dkkxd.js → rbac-roles-b6ca1n23.js} +11 -11
  118. package/dist/{rbac-roles-9ykx9tc5.js → rbac-roles-c58kydph.js} +10 -10
  119. package/dist/{render-v2-ycqm53np.js → render-v2-gqz7z5xt.js} +9 -9
  120. package/dist/{resume-cq2pkp8q.js → resume-yb3y3vda.js} +16 -16
  121. package/dist/{setup-0dcmdvbn.js → setup-1rbr9x3c.js} +7 -5
  122. package/dist/static-t1gr2cr7.js +30 -0
  123. package/dist/{virtual-modules-1x9k4jcs.js → virtual-modules-rdjmcg7q.js} +3 -3
  124. package/dist/{work-objects-x01x2fh8.js → work-objects-nzcp8srm.js} +35 -33
  125. package/dist/{worker-py1ssb1h.js → worker-wnz1h3g0.js} +48 -46
  126. package/dist/{x-ma4gnfgy.js → x-qfmygqqv.js} +2 -2
  127. package/openapi.json +3382 -167
  128. package/package.json +3 -3
  129. package/src/be/db/agents.ts +6 -0
  130. package/src/be/db/instance-signals.ts +30 -0
  131. package/src/be/db/tasks/read.ts +2 -0
  132. package/src/be/db/tasks/write.ts +39 -5
  133. package/src/be/db/workflow-runs.ts +22 -0
  134. package/src/be/db.ts +96 -40
  135. package/src/be/fleet-benchmark-stats.ts +39 -0
  136. package/src/be/migrations/205_favorites_per_dashboard_user.sql +29 -0
  137. package/src/be/migrations/206_runtime_pools.sql +62 -0
  138. package/src/be/migrations/207_runtime_session_tokens.sql +31 -0
  139. package/src/be/migrations/208_task_runtime_dispatch.sql +4 -0
  140. package/src/be/model-tier-resolution.ts +9 -2
  141. package/src/be/multi-runtime.ts +102 -13
  142. package/src/be/org-profile.ts +35 -0
  143. package/src/be/rbac-audit.ts +4 -0
  144. package/src/be/runtime-pools/controllers.ts +150 -0
  145. package/src/be/runtime-pools/db.ts +526 -0
  146. package/src/be/runtime-pools/demand.ts +65 -0
  147. package/src/be/runtime-pools/e2b-images.ts +109 -0
  148. package/src/be/runtime-pools/errors.ts +8 -0
  149. package/src/be/runtime-pools/lifecycle.ts +44 -0
  150. package/src/be/runtime-pools/reachability.ts +30 -0
  151. package/src/be/runtime-pools/recovery.ts +248 -0
  152. package/src/be/runtime-pools/remote-controller.ts +144 -0
  153. package/src/be/runtime-pools/routing.ts +304 -0
  154. package/src/be/runtime-pools/seed.ts +110 -0
  155. package/src/be/runtime-pools/supervisor.ts +981 -0
  156. package/src/be/runtime-pools/tokens.ts +57 -0
  157. package/src/be/scripts/typecheck.ts +48 -3
  158. package/src/be/secret-registry.ts +17 -1
  159. package/src/be/skill-usage.ts +467 -0
  160. package/src/be/swarm-config-guard.ts +59 -2
  161. package/src/be/telemetry-enable.ts +66 -0
  162. package/src/be/telemetry-ingest-anchor.ts +77 -0
  163. package/src/be/users.ts +173 -23
  164. package/src/be/worker-nudge-listener.ts +28 -0
  165. package/src/be/worker-nudges.ts +22 -0
  166. package/src/cli.tsx +22 -3
  167. package/src/commands/controller.ts +180 -0
  168. package/src/commands/onboard/non-interactive.ts +36 -12
  169. package/src/commands/onboard/types.ts +1 -1
  170. package/src/commands/onboard.tsx +3 -0
  171. package/src/commands/push-delivery.ts +230 -0
  172. package/src/commands/runner.ts +560 -276
  173. package/src/e2b/dispatch.ts +15 -1
  174. package/src/extensions/contract-types.generated.ts +1 -1
  175. package/src/fleet-benchmark.ts +157 -0
  176. package/src/heartbeat/heartbeat.ts +53 -135
  177. package/src/hooks/hook.ts +3 -2
  178. package/src/http/agents.ts +21 -0
  179. package/src/http/all-routes.ts +6 -0
  180. package/src/http/apps.ts +4 -2
  181. package/src/http/auth.ts +4 -7
  182. package/src/http/config.ts +58 -21
  183. package/src/http/controllers-connect.ts +206 -0
  184. package/src/http/core.ts +108 -14
  185. package/src/http/favorite-owner.ts +31 -1
  186. package/src/http/fleet-benchmark.ts +206 -0
  187. package/src/http/index.ts +38 -6
  188. package/src/http/mcp.ts +3 -8
  189. package/src/http/poll.ts +31 -2
  190. package/src/http/realtime.ts +1 -1
  191. package/src/http/request-principal.ts +2 -0
  192. package/src/http/runtime-pools.ts +527 -0
  193. package/src/http/session-data.ts +2 -0
  194. package/src/http/sessions.ts +100 -23
  195. package/src/http/skills.ts +173 -0
  196. package/src/http/status.ts +25 -1
  197. package/src/http/tasks.ts +14 -1
  198. package/src/http/telemetry-ui.ts +102 -0
  199. package/src/http/used-by.ts +140 -0
  200. package/src/http/utils.ts +7 -1
  201. package/src/http/workflows.ts +10 -2
  202. package/src/jira/app.ts +1 -2
  203. package/src/kv-reserved-namespaces.ts +1 -0
  204. package/src/linear/app.ts +1 -2
  205. package/src/providers/acp-target-catalog.ts +75 -1
  206. package/src/providers/acp-targets.ts +114 -0
  207. package/src/providers/amp-adapter.ts +1 -1
  208. package/src/providers/claude-adapter.ts +1 -1
  209. package/src/providers/codex-adapter.ts +5 -1
  210. package/src/providers/opencode-adapter.ts +2 -1
  211. package/src/providers/pi-mono-adapter.ts +41 -26
  212. package/src/providers/pricing-sources.md +2 -0
  213. package/src/providers/skill-invoke.ts +39 -3
  214. package/src/rbac/legacy-policy.ts +8 -0
  215. package/src/rbac/permissions.ts +16 -0
  216. package/src/rbac/types.ts +2 -0
  217. package/src/realtime/auth.ts +13 -0
  218. package/src/realtime/channels.ts +24 -0
  219. package/src/realtime/transport.ts +94 -15
  220. package/src/realtime/worker-client.ts +176 -0
  221. package/src/runtime-providers/controller-protocol.ts +97 -0
  222. package/src/runtime-providers/controller.ts +86 -0
  223. package/src/runtime-providers/docker.ts +235 -0
  224. package/src/runtime-providers/e2b.ts +217 -0
  225. package/src/runtime-providers/index.ts +37 -0
  226. package/src/runtime-providers/static.ts +26 -0
  227. package/src/runtime-providers/types.ts +92 -0
  228. package/src/runtime-providers/worker-api-url.ts +11 -0
  229. package/src/scripts-runtime/sdk-allowlist.ts +6 -0
  230. package/src/scripts-runtime/types/stdlib.d.ts +15 -0
  231. package/src/scripts-runtime/types/swarm-extension.d.ts +1 -0
  232. package/src/scripts-runtime/types/swarm-sdk.d.ts +15 -0
  233. package/src/server.ts +12 -0
  234. package/src/slack/router.ts +7 -5
  235. package/src/tasks/worker-follow-up.ts +80 -52
  236. package/src/telemetry-context.ts +6 -0
  237. package/src/telemetry-contract/EVENTS.md +14 -1
  238. package/src/telemetry-contract/SOURCE.json +4 -4
  239. package/src/telemetry-contract/catalog.json +155 -0
  240. package/src/telemetry-contract/types.gen.ts +248 -4
  241. package/src/telemetry-ui-events.ts +130 -0
  242. package/src/telemetry.ts +43 -3
  243. package/src/tests/acp-adapter.test.ts +129 -0
  244. package/src/tests/claude-adapter.test.ts +6 -2
  245. package/src/tests/codex-adapter.test.ts +6 -2
  246. package/src/tests/config-internal-keys.test.ts +27 -0
  247. package/src/tests/config-session-auth.test.ts +19 -3
  248. package/src/tests/db-retention.test.ts +50 -10
  249. package/src/tests/docs-index-footprint.test.js +3 -3
  250. package/src/tests/e2b-dispatch.test.ts +28 -1
  251. package/src/tests/e2e-runtime-pools.test.ts +51 -0
  252. package/src/tests/entrypoint-acp-target-binary.test.ts +38 -1
  253. package/src/tests/favorites.test.ts +188 -0
  254. package/src/tests/fetch-resolved-env.test.ts +59 -1
  255. package/src/tests/fleet-benchmark.test.ts +453 -0
  256. package/src/tests/harness-model-support.test.ts +70 -2
  257. package/src/tests/heartbeat-orphan-resume.test.ts +24 -0
  258. package/src/tests/heartbeat-reboot-live.test.ts +31 -0
  259. package/src/tests/heartbeat-supersede-resume.test.ts +21 -0
  260. package/src/tests/hook-runtime-close.test.ts +64 -0
  261. package/src/tests/http-task-write-ownership.test.ts +8 -1
  262. package/src/tests/integration-disable-flags.test.ts +45 -0
  263. package/src/tests/migration-206-runtime-pools.test.ts +134 -0
  264. package/src/tests/migration-207-runtime-session-tokens.test.ts +45 -0
  265. package/src/tests/migration-208-task-runtime-dispatch.test.ts +30 -0
  266. package/src/tests/multi-runtime-registration.test.ts +219 -4
  267. package/src/tests/onboard-non-interactive.test.ts +104 -6
  268. package/src/tests/opencode-adapter.test.ts +6 -2
  269. package/src/tests/org-website.test.ts +115 -0
  270. package/src/tests/pi-mono-adapter.test.ts +74 -10
  271. package/src/tests/rbac-admission-e2e.test.ts +4 -4
  272. package/src/tests/rbac-engine.test.ts +8 -1
  273. package/src/tests/realtime-room-auth.test.ts +49 -0
  274. package/src/tests/repo-allow-merge-gate.test.ts +8 -1
  275. package/src/tests/runner-exit-after-tasks.test.ts +163 -0
  276. package/src/tests/runner-finish-retry.test.ts +466 -0
  277. package/src/tests/runner-harness-telemetry-env.test.ts +105 -0
  278. package/src/tests/runner-push-delivery.test.ts +670 -0
  279. package/src/tests/runner-slot-reconcile.test.ts +89 -1
  280. package/src/tests/runtime-child-token-cleanup.test.ts +172 -0
  281. package/src/tests/runtime-controller-token.test.ts +254 -0
  282. package/src/tests/runtime-demand.test.ts +119 -0
  283. package/src/tests/runtime-e2b-pools.test.ts +847 -0
  284. package/src/tests/runtime-pool-reachability.test.ts +328 -0
  285. package/src/tests/runtime-pool-routing.test.ts +817 -0
  286. package/src/tests/runtime-pools-db.test.ts +275 -0
  287. package/src/tests/runtime-pools-http.test.ts +506 -0
  288. package/src/tests/runtime-pools-ownership-guards.test.ts +235 -0
  289. package/src/tests/runtime-pools-seed.test.ts +203 -0
  290. package/src/tests/runtime-pools-test-utils.ts +128 -0
  291. package/src/tests/runtime-provider-registration.test.ts +133 -0
  292. package/src/tests/runtime-providers-docker.test.ts +400 -0
  293. package/src/tests/runtime-providers-e2b-transport.test.ts +50 -0
  294. package/src/tests/runtime-providers-e2b.test.ts +335 -0
  295. package/src/tests/runtime-recovery.test.ts +745 -0
  296. package/src/tests/runtime-remote-controller.test.ts +846 -0
  297. package/src/tests/runtime-supervisor-failures.test.ts +387 -0
  298. package/src/tests/runtime-supervisor.test.ts +1039 -0
  299. package/src/tests/runtime-token-auth.test.ts +897 -0
  300. package/src/tests/script-connections.test.ts +7 -0
  301. package/src/tests/secret-scrubber.test.ts +17 -2
  302. package/src/tests/session-costs-codex-recompute.test.ts +49 -0
  303. package/src/tests/session-tokens.test.ts +13 -3
  304. package/src/tests/skill-invoke.test.ts +142 -0
  305. package/src/tests/skill-usage-cohorts.test.ts +232 -0
  306. package/src/tests/skill-usage.test.ts +348 -0
  307. package/src/tests/slack-attachments-block.test.ts +23 -0
  308. package/src/tests/slack-render-v2.test.ts +6 -0
  309. package/src/tests/status-instance.test.ts +71 -0
  310. package/src/tests/task-supersede-resume.test.ts +87 -4
  311. package/src/tests/telemetry-enable.test.ts +113 -0
  312. package/src/tests/telemetry-ui-route.test.ts +195 -0
  313. package/src/tests/tool-annotations.test.ts +1 -1
  314. package/src/tests/used-by-route.test.ts +237 -0
  315. package/src/tests/worker-nudges.test.ts +653 -0
  316. package/src/tests/worker-realtime-client.test.ts +188 -0
  317. package/src/tests/workflow-sub-workflow.test.ts +22 -0
  318. package/src/tools/app-upsert.ts +1 -1
  319. package/src/tools/runtime-controller-list.ts +28 -0
  320. package/src/tools/runtime-pool-bind-agent.ts +29 -0
  321. package/src/tools/runtime-pool-common.ts +37 -0
  322. package/src/tools/runtime-pool-create-agent.ts +29 -0
  323. package/src/tools/runtime-pool-delete.ts +27 -0
  324. package/src/tools/runtime-pool-list.ts +27 -0
  325. package/src/tools/runtime-pool-upsert.ts +31 -0
  326. package/src/tools/script-common.ts +1 -1
  327. package/src/tools/send-task.ts +3 -2
  328. package/src/tools/tool-config.ts +6 -0
  329. package/src/types.ts +137 -2
  330. package/src/utils/config-secrets.ts +1 -0
  331. package/src/utils/lead-monitor-channels.ts +3 -0
  332. package/src/utils/org-website.ts +104 -0
  333. package/src/utils/request-auth-context.ts +10 -2
  334. package/src/utils/runtime-pools-flag.ts +11 -0
  335. package/src/utils/secret-scrubber.ts +9 -0
  336. package/src/utils/session-token-connections.ts +20 -0
  337. package/templates/skills/apps/content.md +1 -1
  338. package/templates/skills/code-quality/content.md +9 -1
  339. package/templates/skills/db-query-guidance/content.md +9 -0
  340. package/templates/skills/swarm-scripts/SKILL.md +1 -1
  341. package/templates/skills/swarm-scripts/content.md +1 -1
  342. package/templates/skills/work-on-task/SKILL.md +1 -1
  343. package/templates/skills/work-on-task/content.md +1 -1
  344. package/dist/{cli-qd97v6z2.js → cli-1qtgd1h1.js} +3 -3
  345. package/dist/{cli-cmxkbzzs.js → cli-j0w59p15.js} +6 -6
  346. package/dist/{google-generative-ai-b8zxrpax.js → google-generative-ai-pvhm0dq1.js} +1 -1
  347. package/dist/{google-vertex-nrdd697t.js → google-vertex-tek9sqe2.js} +4 -4
  348. package/dist/{mistral-conversations-059y51zt.js → mistral-conversations-rjxa9s1j.js} +3 -3
  349. package/dist/{openai-completions-663yncfq.js → openai-completions-44gb0zsk.js} +12 -12
@@ -0,0 +1,195 @@
1
+ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } from "bun:test";
2
+ import { Readable } from "node:stream";
3
+ import "../http/all-routes";
4
+ import { isPublicRoute } from "../http/route-def";
5
+ import { handleTelemetryUi } from "../http/telemetry-ui";
6
+ import { getPathSegments, parseQueryParams } from "../http/utils";
7
+ import { _resetTelemetryStateForTests, initTelemetry } from "../telemetry";
8
+ import { UI_EVENT_NAMES, validateUiEvent } from "../telemetry-ui-events";
9
+ import type { HttpRequestAuth } from "../utils/request-auth-context";
10
+ import { setRequestAuth } from "../utils/request-auth-context";
11
+
12
+ const URL_PATH = "/api/telemetry/ui-event";
13
+ const OPERATOR: HttpRequestAuth = { kind: "operator", fingerprint: "op:test" };
14
+
15
+ function jsonReq(body: unknown) {
16
+ const raw = JSON.stringify(body);
17
+ const req = Readable.from([Buffer.from(raw)]) as Readable & {
18
+ method: string;
19
+ url: string;
20
+ headers: Record<string, string>;
21
+ };
22
+ req.method = "POST";
23
+ req.url = URL_PATH;
24
+ req.headers = { "content-type": "application/json" };
25
+ return req;
26
+ }
27
+
28
+ async function post(body: unknown, auth: HttpRequestAuth = OPERATOR) {
29
+ const req = jsonReq(body);
30
+ setRequestAuth(req as never, auth);
31
+ let statusCode = 200;
32
+ const chunks: string[] = [];
33
+ const res = {
34
+ setHeader: () => {},
35
+ writeHead: (code: number) => {
36
+ statusCode = code;
37
+ },
38
+ end: (chunk?: string) => {
39
+ if (chunk) chunks.push(chunk);
40
+ },
41
+ };
42
+ const handled = await handleTelemetryUi(
43
+ req as never,
44
+ res as never,
45
+ getPathSegments(req.url),
46
+ parseQueryParams(req.url),
47
+ undefined,
48
+ );
49
+ return { handled, statusCode, body: chunks.join("") };
50
+ }
51
+
52
+ type Sent = { event: string; source: string; properties: Record<string, unknown> };
53
+
54
+ async function flush(): Promise<void> {
55
+ for (let i = 0; i < 8; i++) await new Promise((resolve) => setTimeout(resolve, 0));
56
+ }
57
+
58
+ describe("POST /api/telemetry/ui-event", () => {
59
+ const originalFetch = globalThis.fetch;
60
+ const originalFlag = process.env.ANONYMIZED_TELEMETRY;
61
+ let sent: Sent[];
62
+
63
+ beforeAll(() => {
64
+ globalThis.fetch = (async (_url: string, init?: { body?: string }) => {
65
+ sent.push(JSON.parse(init?.body ?? "{}"));
66
+ return new Response(null, { status: 202 });
67
+ }) as unknown as typeof fetch;
68
+ });
69
+
70
+ afterAll(() => {
71
+ globalThis.fetch = originalFetch;
72
+ if (originalFlag === undefined) delete process.env.ANONYMIZED_TELEMETRY;
73
+ else process.env.ANONYMIZED_TELEMETRY = originalFlag;
74
+ _resetTelemetryStateForTests();
75
+ });
76
+
77
+ beforeEach(async () => {
78
+ sent = [];
79
+ process.env.ANONYMIZED_TELEMETRY = "true";
80
+ _resetTelemetryStateForTests();
81
+ await initTelemetry(
82
+ "api-server",
83
+ async (key) => {
84
+ if (key === "telemetry_installation_id") return "install_0123456789abcdef";
85
+ if (key === "telemetry_org_id") return "org_0123456789abcdef";
86
+ return undefined;
87
+ },
88
+ async () => {},
89
+ );
90
+ });
91
+
92
+ afterEach(() => {
93
+ process.env.ANONYMIZED_TELEMETRY = "true";
94
+ });
95
+
96
+ test("an allowlisted event is sent with the ui emitter", async () => {
97
+ const result = await post({
98
+ event: "popup.shown",
99
+ properties: { popup: "org_name", trigger: "missing_org_name" },
100
+ });
101
+ await flush();
102
+ expect(result.statusCode).toBe(204);
103
+ expect(sent).toHaveLength(1);
104
+ expect(sent[0]?.event).toBe("popup.shown");
105
+ expect(sent[0]?.source).toBe("ui");
106
+ expect(sent[0]?.properties).toMatchObject({ popup: "org_name", trigger: "missing_org_name" });
107
+ });
108
+
109
+ test("lead.captured with an invented submission_id gets 400 and sends nothing", async () => {
110
+ // The API never sees the Slack Connect submission, so it cannot vouch for a lead.
111
+ const result = await post({
112
+ event: "lead.captured",
113
+ properties: { channel: "slack_connect", consent: true, submission_id: "invented" },
114
+ });
115
+ await flush();
116
+ expect(result.statusCode).toBe(400);
117
+ expect(result.body).toContain("unknown event");
118
+ expect(sent).toHaveLength(0);
119
+ });
120
+
121
+ test("an unknown event name gets 400 and sends nothing", async () => {
122
+ const result = await post({ event: "task.created", properties: {} });
123
+ await flush();
124
+ expect(result.statusCode).toBe(400);
125
+ expect(result.body).toContain("unknown event");
126
+ expect(sent).toHaveLength(0);
127
+ });
128
+
129
+ test("an invalid property gets 400", async () => {
130
+ const result = await post({
131
+ event: "popup.dismissed",
132
+ properties: { popup: "org_name", method: "swipe" },
133
+ });
134
+ expect(result.statusCode).toBe(400);
135
+ expect(result.body).toContain("method");
136
+ });
137
+
138
+ test("telemetry off answers 204 and sends nothing", async () => {
139
+ process.env.ANONYMIZED_TELEMETRY = "false";
140
+ const result = await post({
141
+ event: "popup.shown",
142
+ properties: { popup: "feedback", trigger: "quarterly" },
143
+ });
144
+ await flush();
145
+ expect(result.statusCode).toBe(204);
146
+ expect(sent).toHaveLength(0);
147
+ });
148
+
149
+ test("a guest page session gets 403", async () => {
150
+ const result = await post(
151
+ { event: "popup.shown", properties: { popup: "feedback", trigger: "quarterly" } },
152
+ { kind: "guest" },
153
+ );
154
+ expect(result.statusCode).toBe(403);
155
+ });
156
+
157
+ test("the route requires the API key (not public), so no auth is a 401", () => {
158
+ expect(isPublicRoute("POST", ["api", "telemetry", "ui-event"])).toBe(false);
159
+ });
160
+ });
161
+
162
+ describe("validateUiEvent", () => {
163
+ test("allows only ui events", () => {
164
+ expect(UI_EVENT_NAMES).toContain("popup.shown");
165
+ expect(UI_EVENT_NAMES).toContain("notification.submitted");
166
+ // Server-attributed; the route cannot verify the submission behind it.
167
+ expect(UI_EVENT_NAMES).not.toContain("lead.captured");
168
+ expect(UI_EVENT_NAMES).not.toContain("task.created");
169
+ // The API sends it after an admin-only change; a dashboard user cannot fake it.
170
+ expect(UI_EVENT_NAMES).not.toContain("used_by.consent_changed");
171
+ });
172
+
173
+ test("rejects missing required, unknown keys, wrong types and values below minimum", () => {
174
+ expect(validateUiEvent("popup.shown", { popup: "feedback" })).toEqual([
175
+ 'missing required property "trigger"',
176
+ ]);
177
+ expect(validateUiEvent("notification.viewed", { key: "x", is_cloud: true })).toEqual([
178
+ 'unknown property "is_cloud"',
179
+ ]);
180
+ expect(
181
+ validateUiEvent("popup.submitted", {
182
+ popup: "feedback",
183
+ score: -1,
184
+ has_message: "yes",
185
+ has_contact: false,
186
+ }),
187
+ ).toEqual(['"score" must be at least 0', '"has_message" must be a boolean']);
188
+ expect(validateUiEvent("notification.viewed", { key: "k".repeat(201) })).toEqual([
189
+ '"key" must be at most 200 characters',
190
+ ]);
191
+ expect(validateUiEvent("org.profile_updated", { fields: ["name"], surface: "prompt" })).toEqual(
192
+ [],
193
+ );
194
+ });
195
+ });
@@ -378,7 +378,7 @@ describe("Tool Annotations & Classification", () => {
378
378
  // Includes 11 skill tools, 7 MCP server tools, reusable script tools, and the
379
379
  // native Kapso/WhatsApp tools (register/unregister number + send/reply message).
380
380
  expect(count).toBeGreaterThanOrEqual(45);
381
- expect(count).toBeLessThanOrEqual(151);
381
+ expect(count).toBeLessThanOrEqual(157);
382
382
  });
383
383
 
384
384
  test("core tools are fewer than deferred tools", () => {
@@ -0,0 +1,237 @@
1
+ import { afterAll, beforeAll, beforeEach, describe, expect, test } from "bun:test";
2
+ import { unlink } from "node:fs/promises";
3
+ import { Readable } from "node:stream";
4
+ import { closeDb, createAgent, getSwarmConfigs, initDb, upsertSwarmConfig } from "../be/db";
5
+ import { fillOrgLogoFromWebsite } from "../be/org-profile";
6
+ import { handleUsedBy } from "../http/used-by";
7
+ import { getPathSegments, parseQueryParams } from "../http/utils";
8
+ import type { HttpRequestAuth } from "../utils/request-auth-context";
9
+ import { setRequestAuth } from "../utils/request-auth-context";
10
+
11
+ const TEST_DB_PATH = "./test-used-by-route.sqlite";
12
+ const OPERATOR: HttpRequestAuth = { kind: "operator", fingerprint: "op:test" };
13
+ const WORKER_ID = "bbbb0000-0000-4000-8000-0000000000e1";
14
+
15
+ async function removeDbFiles(): Promise<void> {
16
+ for (const suffix of ["", "-wal", "-shm"]) {
17
+ try {
18
+ await unlink(TEST_DB_PATH + suffix);
19
+ } catch {
20
+ // Not there.
21
+ }
22
+ }
23
+ }
24
+
25
+ async function post(body: unknown, auth: HttpRequestAuth | null, agentId?: string) {
26
+ const req = Readable.from([Buffer.from(JSON.stringify(body))]) as Readable & {
27
+ method: string;
28
+ url: string;
29
+ headers: Record<string, string>;
30
+ };
31
+ req.method = "POST";
32
+ req.url = "/api/used-by";
33
+ req.headers = {
34
+ "content-type": "application/json",
35
+ ...(agentId ? { "x-agent-id": agentId } : {}),
36
+ };
37
+ setRequestAuth(req as never, auth);
38
+ let statusCode = 200;
39
+ const chunks: string[] = [];
40
+ const res = {
41
+ setHeader: () => {},
42
+ writeHead: (code: number) => {
43
+ statusCode = code;
44
+ },
45
+ end: (chunk?: string) => {
46
+ if (chunk) chunks.push(chunk);
47
+ },
48
+ };
49
+ await handleUsedBy(
50
+ req as never,
51
+ res as never,
52
+ getPathSegments(req.url),
53
+ parseQueryParams(req.url),
54
+ agentId,
55
+ );
56
+ return { statusCode, body: chunks.join("") };
57
+ }
58
+
59
+ const configValue = async (key: string) =>
60
+ (await getSwarmConfigs({ scope: "global", key }))?.[0]?.value;
61
+
62
+ describe("POST /api/used-by", () => {
63
+ const originalFetch = globalThis.fetch;
64
+ let proxied: Array<{ url: string; body: Record<string, unknown> }>;
65
+ let proxyStatus: number;
66
+
67
+ beforeAll(async () => {
68
+ await removeDbFiles();
69
+ initDb(TEST_DB_PATH);
70
+ await createAgent({ id: WORKER_ID, name: "Worker", isLead: false, status: "idle" });
71
+ globalThis.fetch = (async (url: string, init?: { body?: string }) => {
72
+ proxied.push({ url: String(url), body: JSON.parse(init?.body ?? "{}") });
73
+ return new Response(null, { status: proxyStatus });
74
+ }) as unknown as typeof fetch;
75
+ });
76
+
77
+ afterAll(async () => {
78
+ globalThis.fetch = originalFetch;
79
+ closeDb();
80
+ await removeDbFiles();
81
+ });
82
+
83
+ beforeEach(async () => {
84
+ proxied = [];
85
+ proxyStatus = 202;
86
+ await upsertSwarmConfig({ scope: "global", key: "SWARM_ORG_NAME", value: "Acme" });
87
+ await upsertSwarmConfig({ scope: "global", key: "SWARM_ORG_WEBSITE", value: "acme.com" });
88
+ });
89
+
90
+ test("a non-lead agent gets 403 and nothing reaches the proxy", async () => {
91
+ const result = await post({ granted: true }, null, WORKER_ID);
92
+ expect(result.statusCode).toBe(403);
93
+ expect(proxied).toEqual([]);
94
+ });
95
+
96
+ test("grant and revoke both reach the proxy and are stored", async () => {
97
+ const grant = await post({ granted: true }, OPERATOR);
98
+ expect(grant.statusCode).toBe(200);
99
+ expect(proxied[0]?.url).toBe("https://proxy.desplega.sh/v1/used-by");
100
+ expect(proxied[0]?.body).toMatchObject({
101
+ org_name: "Acme",
102
+ org_website: "acme.com",
103
+ granted: true,
104
+ });
105
+ expect(await configValue("SWARM_USED_BY_CONSENT")).toBe("true");
106
+
107
+ const revoke = await post({ granted: false }, OPERATOR);
108
+ expect(revoke.statusCode).toBe(200);
109
+ expect(proxied[1]?.body).toMatchObject({ granted: false });
110
+ expect(await configValue("SWARM_USED_BY_CONSENT")).toBe("false");
111
+ });
112
+
113
+ test("with telemetry off the install ID stays home", async () => {
114
+ await upsertSwarmConfig({
115
+ scope: "global",
116
+ key: "telemetry_installation_id",
117
+ value: "install_0123456789abcdef",
118
+ });
119
+ const saved = process.env.ANONYMIZED_TELEMETRY;
120
+ process.env.ANONYMIZED_TELEMETRY = "true";
121
+ await post({ granted: true }, OPERATOR);
122
+ process.env.ANONYMIZED_TELEMETRY = "false";
123
+ await post({ granted: true }, OPERATOR);
124
+ if (saved === undefined) delete process.env.ANONYMIZED_TELEMETRY;
125
+ else process.env.ANONYMIZED_TELEMETRY = saved;
126
+ expect(proxied[0]?.body.install_id).toBe("install_0123456789abcdef");
127
+ expect(proxied[1]?.body).not.toHaveProperty("install_id");
128
+ });
129
+
130
+ test("follows a stubbed feedback_endpoint", async () => {
131
+ await upsertSwarmConfig({
132
+ scope: "global",
133
+ key: "feedback_endpoint",
134
+ value: "http://stub.test/v1/feedback",
135
+ });
136
+ await post({ granted: true }, OPERATOR);
137
+ expect(proxied[0]?.url).toBe("http://stub.test/v1/used-by");
138
+ await upsertSwarmConfig({
139
+ scope: "global",
140
+ key: "feedback_endpoint",
141
+ value: "https://proxy.desplega.sh/v1/feedback",
142
+ });
143
+ });
144
+
145
+ test("a proxy failure is a 502 and leaves the stored consent alone", async () => {
146
+ await upsertSwarmConfig({ scope: "global", key: "SWARM_USED_BY_CONSENT", value: "false" });
147
+ proxyStatus = 500;
148
+ const result = await post({ granted: true }, OPERATOR);
149
+ expect(result.statusCode).toBe(502);
150
+ expect(await configValue("SWARM_USED_BY_CONSENT")).toBe("false");
151
+ });
152
+
153
+ test("a revoke after the website is cleared or changed uses the granted identity", async () => {
154
+ expect((await post({ granted: true }, OPERATOR)).statusCode).toBe(200);
155
+ await upsertSwarmConfig({ scope: "global", key: "SWARM_ORG_WEBSITE", value: "" });
156
+ const revoke = await post({ granted: false }, OPERATOR);
157
+ expect(revoke.statusCode).toBe(200);
158
+ expect(proxied[1]?.body).toMatchObject({
159
+ org_name: "Acme",
160
+ org_website: "acme.com",
161
+ granted: false,
162
+ });
163
+
164
+ await upsertSwarmConfig({ scope: "global", key: "SWARM_ORG_NAME", value: "Acme Labs" });
165
+ await upsertSwarmConfig({ scope: "global", key: "SWARM_ORG_WEBSITE", value: "acme.io" });
166
+ expect((await post({ granted: false }, OPERATOR)).statusCode).toBe(200);
167
+ expect(proxied[2]?.body).toMatchObject({ org_name: "Acme", org_website: "acme.com" });
168
+
169
+ // A new grant sends, and from then on revokes with, the current identity.
170
+ expect((await post({ granted: true }, OPERATOR)).statusCode).toBe(200);
171
+ expect(proxied[3]?.body).toMatchObject({ org_name: "Acme Labs", org_website: "acme.io" });
172
+ await upsertSwarmConfig({ scope: "global", key: "SWARM_ORG_WEBSITE", value: "" });
173
+ await post({ granted: false }, OPERATOR);
174
+ expect(proxied[4]?.body).toMatchObject({ org_name: "Acme Labs", org_website: "acme.io" });
175
+ });
176
+
177
+ test("without a website it is a 400", async () => {
178
+ await upsertSwarmConfig({ scope: "global", key: "SWARM_ORG_WEBSITE", value: "" });
179
+ const result = await post({ granted: true }, OPERATOR);
180
+ expect(result.statusCode).toBe(400);
181
+ expect(proxied).toEqual([]);
182
+ });
183
+ });
184
+
185
+ describe("fillOrgLogoFromWebsite", () => {
186
+ const savedEnvLogo = process.env.SWARM_ORG_LOGO_URL;
187
+
188
+ beforeAll(async () => {
189
+ await removeDbFiles();
190
+ initDb(TEST_DB_PATH);
191
+ delete process.env.SWARM_ORG_LOGO_URL;
192
+ });
193
+
194
+ afterAll(async () => {
195
+ if (savedEnvLogo !== undefined) process.env.SWARM_ORG_LOGO_URL = savedEnvLogo;
196
+ closeDb();
197
+ await removeDbFiles();
198
+ });
199
+
200
+ test("fills an empty logo, follows a website change, and never overwrites a set logo", async () => {
201
+ expect(await fillOrgLogoFromWebsite("acme.com")).toBe(true);
202
+ expect(await configValue("SWARM_ORG_LOGO_URL")).toBe(
203
+ "https://proxy.desplega.sh/v1/logo?domain=acme.com",
204
+ );
205
+
206
+ expect(await fillOrgLogoFromWebsite("acme.io")).toBe(true);
207
+ expect(await configValue("SWARM_ORG_LOGO_URL")).toBe(
208
+ "https://proxy.desplega.sh/v1/logo?domain=acme.io",
209
+ );
210
+
211
+ await upsertSwarmConfig({
212
+ scope: "global",
213
+ key: "SWARM_ORG_LOGO_URL",
214
+ value: "https://cdn.acme.com/logo.svg",
215
+ });
216
+ expect(await fillOrgLogoFromWebsite("acme.com")).toBe(false);
217
+ expect(await configValue("SWARM_ORG_LOGO_URL")).toBe("https://cdn.acme.com/logo.svg");
218
+ });
219
+
220
+ test("a person-set logo on the proxy's path or origin is never overwritten", async () => {
221
+ for (const custom of [
222
+ "https://brand.acme.com/v1/logo?domain=acme.com",
223
+ "https://proxy.desplega.sh/v1/logo?domain=other.com",
224
+ ]) {
225
+ await upsertSwarmConfig({ scope: "global", key: "SWARM_ORG_LOGO_URL", value: custom });
226
+ expect(await fillOrgLogoFromWebsite("acme.com")).toBe(false);
227
+ expect(await configValue("SWARM_ORG_LOGO_URL")).toBe(custom);
228
+ }
229
+ });
230
+
231
+ test("a logo set in the deployment env is not overwritten either", async () => {
232
+ await upsertSwarmConfig({ scope: "global", key: "SWARM_ORG_LOGO_URL", value: "" });
233
+ process.env.SWARM_ORG_LOGO_URL = "https://env.acme.com/logo.png";
234
+ expect(await fillOrgLogoFromWebsite("acme.com")).toBe(false);
235
+ delete process.env.SWARM_ORG_LOGO_URL;
236
+ });
237
+ });