@desplega.ai/agent-swarm 2.2.0 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (266) hide show
  1. package/README.md +1 -0
  2. package/dist/{acp-adapter-k0vwfyvn.js → acp-adapter-kedstxx6.js} +6 -6
  3. package/dist/{actions-w4pnb8vz.js → actions-vget6r1k.js} +18 -16
  4. package/dist/{amp-adapter-0cmxb2t5.js → amp-adapter-xeb5mktv.js} +2 -2
  5. package/dist/{app-zneem7g9.js → app-mqap8t8m.js} +3 -3
  6. package/dist/{assistant-wbzd2rnr.js → assistant-h0gv97mv.js} +20 -18
  7. package/dist/{boot-reembed-4kx69j3g.js → boot-reembed-qr8a894z.js} +1 -1
  8. package/dist/{boot-reembed-db0wwgy1.js → boot-reembed-rj85jjhw.js} +1 -1
  9. package/dist/{boot-scrub-sweep-tfv4d3mm.js → boot-scrub-sweep-eyfvn6v9.js} +3 -3
  10. package/dist/{boot-seeds-w2hmkxn5.js → boot-seeds-xs9a8dx1.js} +4 -4
  11. package/dist/{claude-adapter-5qrc2paq.js → claude-adapter-bm23cye7.js} +5 -5
  12. package/dist/{claude-managed-adapter-n7ahjyx6.js → claude-managed-adapter-1mwrsm9d.js} +2 -2
  13. package/dist/{claude-managed-setup-7ra32em4.js → claude-managed-setup-gkfgks4j.js} +1 -1
  14. package/dist/{claude-sdk-session-cd02gc76.js → claude-sdk-session-apb4ypz3.js} +5 -5
  15. package/dist/cli-02vhhssk.js +848 -0
  16. package/dist/{cli-4ync7m60.js → cli-0ebey9hg.js} +1 -1
  17. package/dist/{cli-665j3feb.js → cli-0xk505e8.js} +1 -1
  18. package/dist/{cli-8c1m9mhy.js → cli-1cevz46c.js} +5 -5
  19. package/dist/{cli-gzvb3d4a.js → cli-1jx0srjt.js} +3 -3
  20. package/dist/{cli-zj4d6afs.js → cli-1pa3rz69.js} +21 -6
  21. package/dist/{cli-vmbakbq0.js → cli-2rwet3r7.js} +1 -1
  22. package/dist/{cli-azs9bhc5.js → cli-3wjs22x3.js} +2 -2
  23. package/dist/{cli-tba8fxf9.js → cli-4fhyq711.js} +45 -36
  24. package/dist/{cli-ak4c12mh.js → cli-5ff2sjyt.js} +1 -1
  25. package/dist/{cli-6q7pyd3k.js → cli-5s5hx57y.js} +5 -3
  26. package/dist/{cli-h23mr2s6.js → cli-6ftrrwm1.js} +9 -371
  27. package/dist/{cli-9ac0mkg5.js → cli-8b9wvjps.js} +1 -1
  28. package/dist/cli-8cxkw1f5.js +382 -0
  29. package/dist/{cli-xhgtay7w.js → cli-8rwvksbc.js} +2 -2
  30. package/dist/{cli-e09hj50q.js → cli-8wkb09q5.js} +11 -11
  31. package/dist/{cli-ksrphveb.js → cli-a1esmmee.js} +14 -2
  32. package/dist/{cli-xnp2vkx7.js → cli-avmqhatn.js} +7 -7
  33. package/dist/{cli-xx13gqf3.js → cli-b80a1100.js} +1 -1
  34. package/dist/{cli-z1hh99j0.js → cli-bfc3k1x5.js} +3 -3
  35. package/dist/{cli-0k9rcwfy.js → cli-bhwa8rzc.js} +33 -15
  36. package/dist/{cli-8cvvytad.js → cli-bn26xbcs.js} +2 -2
  37. package/dist/{cli-k28p6xh7.js → cli-c8fwpgqb.js} +1 -1
  38. package/dist/{cli-rc3r0bnh.js → cli-ccn0eybf.js} +1 -1
  39. package/dist/{cli-9td5ss65.js → cli-dsgj3e7a.js} +2 -2
  40. package/dist/{cli-jrk8mj0t.js → cli-ecshf504.js} +2 -2
  41. package/dist/{cli-raejy0mp.js → cli-eqgfs202.js} +1 -1
  42. package/dist/{cli-ppapy34w.js → cli-f3nx1h8z.js} +2 -2
  43. package/dist/{cli-c9vrwcpb.js → cli-ffbrkh1r.js} +74 -35
  44. package/dist/{cli-mnry16kh.js → cli-kk2r80n5.js} +4 -4
  45. package/dist/{cli-c0dpzwnx.js → cli-kz116kvw.js} +3 -3
  46. package/dist/{cli-e5y285rg.js → cli-mvg2hf8p.js} +4 -4
  47. package/dist/{cli-2jm992rm.js → cli-mz1ezzzh.js} +2 -2
  48. package/dist/{cli-dw0njd9q.js → cli-nme7wery.js} +6 -6
  49. package/dist/{cli-mvsfbbgq.js → cli-nrrg0fvy.js} +18 -4
  50. package/dist/{cli-8jtrekpy.js → cli-p1m2b6gc.js} +7 -7
  51. package/dist/{cli-4c7k75rq.js → cli-rg7ntypm.js} +378 -84
  52. package/dist/{cli-z3dk189k.js → cli-rsd7ga7v.js} +10 -8
  53. package/dist/{cli-etvn5ej2.js → cli-sppc0cmw.js} +1 -1
  54. package/dist/{cli-8w65vwee.js → cli-tg9ksbn8.js} +1 -1
  55. package/dist/{cli-th8krqbf.js → cli-tgvpmnwz.js} +2 -2
  56. package/dist/{cli-hwc4a9xm.js → cli-tj4j2ts4.js} +6 -6
  57. package/dist/{cli-jhhb2v9n.js → cli-ttaz6c7m.js} +2 -2
  58. package/dist/{cli-w7z94e6c.js → cli-tx00c0h6.js} +4 -2
  59. package/dist/{cli-4g629sgr.js → cli-wrv09v7q.js} +20 -1
  60. package/dist/{cli-cby329ny.js → cli-wyrr38xm.js} +2 -2
  61. package/dist/{cli-5ks6x36q.js → cli-x1p5dhq2.js} +3 -3
  62. package/dist/{cli-bddxamg7.js → cli-x719j3vs.js} +220 -629
  63. package/dist/{cli-ztcxv5nv.js → cli-xfe63zx3.js} +1 -1
  64. package/dist/{cli-q6gw45wj.js → cli-ywyrffff.js} +1 -1
  65. package/dist/{cli-p46xdr1m.js → cli-zvze9rbm.js} +1 -1
  66. package/dist/cli.js +15 -15
  67. package/dist/{codex-adapter-m0fx3v3s.js → codex-adapter-pp2gq8gr.js} +3 -3
  68. package/dist/{codex-hook-x6tm6y5m.js → codex-hook-qwzccd64.js} +1 -1
  69. package/dist/{codex-session-runner-j9m2gfyy.js → codex-session-runner-0vzn09t8.js} +3 -3
  70. package/dist/{commands-ktnqwrv4.js → commands-psqhkttb.js} +2 -2
  71. package/dist/{controller-nex2he8v.js → controller-t20vz2k8.js} +2 -2
  72. package/dist/{controllers-connect-6yhwqv9v.js → controllers-connect-gkxmqw9d.js} +24 -20
  73. package/dist/{cursor-adapter-02s5ekva.js → cursor-adapter-3v542qe5.js} +1 -1
  74. package/dist/{db-jvr86v7f.js → db-2xbyenjr.js} +2 -2
  75. package/dist/{db-19tw9r5s.js → db-nc1rd869.js} +3 -2
  76. package/dist/{dispatcher-d3mnsg2y.js → dispatcher-ewceb8ts.js} +17 -15
  77. package/dist/{dsh-adapter-63rvej88.js → dsh-adapter-75xwh78t.js} +1 -1
  78. package/dist/{easter-egg-3d-6hg2r942.js → easter-egg-3d-xsc47jwf.js} +1 -1
  79. package/dist/{execute-bcqc69a5.js → execute-gzmw1mnw.js} +1 -1
  80. package/dist/{external-channel-44cwer32.js → external-channel-a5dsmxn4.js} +2 -2
  81. package/dist/{google-generative-ai-phpmwxvg.js → google-generative-ai-bmq8gkf3.js} +1 -1
  82. package/dist/{google-vertex-es9ybgdy.js → google-vertex-b1rvp52s.js} +1 -1
  83. package/dist/{grok-adapter-ysp907f6.js → grok-adapter-vj88xr23.js} +7 -7
  84. package/dist/handlers-zbs90bny.js +39 -0
  85. package/dist/{heartbeat-2etacsqq.js → heartbeat-t2m9r3wa.js} +20 -18
  86. package/dist/{hook-mzxxs5n2.js → hook-8femx1bg.js} +4 -4
  87. package/dist/{hook-3kvmax6d.js → hook-xa677f8r.js} +5 -5
  88. package/dist/{http-fn978m0g.js → http-xpmmq028.js} +940 -269
  89. package/dist/{index-e4tsa1h7.js → index-8pwc1jc8.js} +17 -15
  90. package/dist/{index-w2wr89xd.js → index-cdzyfrsp.js} +1 -1
  91. package/dist/{index-1r8hw4vd.js → index-dg2tmj99.js} +17 -15
  92. package/dist/index-nxa6me0q.js +41 -0
  93. package/dist/{index-039x2sag.js → index-s7ckdajq.js} +42 -14
  94. package/dist/{index-wgsw9xcz.js → index-syztqdt6.js} +1 -1
  95. package/dist/{index-x0q2a4f9.js → index-ysd45kgc.js} +1 -1
  96. package/dist/{index-g909y089.js → index-zgvqzjsw.js} +8 -8
  97. package/dist/{keepalive-d4nzs76x.js → keepalive-3nr4st3r.js} +3 -3
  98. package/dist/{lead-8h5n9k5f.js → lead-td8h2sfn.js} +33 -31
  99. package/dist/{maintenance-ea6jfw42.js → maintenance-verwpe2c.js} +1 -1
  100. package/dist/{oauth-refresh-sweep-3f25djq3.js → oauth-refresh-sweep-9q2t0y3q.js} +2 -2
  101. package/dist/{onboard-pvk7hdb2.js → onboard-aytqedmq.js} +2 -2
  102. package/dist/{opencode-adapter-eeesgfqk.js → opencode-adapter-f4hryjny.js} +4 -4
  103. package/dist/{otel-impl-qb7nhgdp.js → otel-impl-hckw4wt1.js} +1 -1
  104. package/dist/{pi-mono-adapter-zasp3ze3.js → pi-mono-adapter-hxby0ce1.js} +6 -6
  105. package/dist/{pricing-refresh-6ehwkcmp.js → pricing-refresh-5nvme3sm.js} +3 -3
  106. package/dist/{rbac-roles-km0f9cmm.js → rbac-roles-pd8c26m1.js} +5 -3
  107. package/dist/{rbac-roles-9648nh00.js → rbac-roles-vbpy21mg.js} +2 -2
  108. package/dist/{render-v2-xkze1wef.js → render-v2-7nqgvk2q.js} +3 -3
  109. package/dist/{resume-tq0bbvt5.js → resume-b6djcj3c.js} +6 -6
  110. package/dist/{runtime-ar8310ba.js → runtime-txrxc9za.js} +1 -1
  111. package/dist/session-access-fc3f9y12.js +25 -0
  112. package/dist/{setup-rnrazxvd.js → setup-n39szm6b.js} +1 -1
  113. package/dist/{virtual-modules-wzk6jf3a.js → virtual-modules-wyp2k6z3.js} +2 -2
  114. package/dist/{work-objects-e75q2rqs.js → work-objects-jem2fre0.js} +20 -18
  115. package/dist/{worker-4ww4hjef.js → worker-wr6xgfr2.js} +33 -31
  116. package/openapi.json +1011 -115
  117. package/package.json +2 -2
  118. package/src/apps/action-caller.ts +6 -0
  119. package/src/apps/script-types.ts +16 -3
  120. package/src/be/asset-key-audit.ts +4 -13
  121. package/src/be/db/active-sessions.ts +5 -0
  122. package/src/be/db/session-visibility.ts +29 -0
  123. package/src/be/db/tasks/read.ts +61 -3
  124. package/src/be/db/tasks/write.ts +15 -6
  125. package/src/be/db.ts +149 -66
  126. package/src/be/events.ts +11 -0
  127. package/src/be/migrations/227_inbox_item_state_last_read_at.sql +1 -0
  128. package/src/be/migrations/230_session_shares.sql +23 -0
  129. package/src/be/rbac-roles.ts +2 -0
  130. package/src/be/seed-scripts/catalog/heartbeat-jev-gate.ts +22 -4
  131. package/src/be/session-shares.ts +244 -0
  132. package/src/be/swarm-config-guard.ts +23 -2
  133. package/src/commands/runner.ts +11 -0
  134. package/src/heartbeat/heartbeat.ts +25 -7
  135. package/src/http/active-sessions.ts +13 -2
  136. package/src/http/agents.ts +10 -3
  137. package/src/http/all-routes.ts +1 -0
  138. package/src/http/api-keys.ts +3 -1
  139. package/src/http/approval-requests.ts +2 -1
  140. package/src/http/apps.ts +36 -11
  141. package/src/http/assets.ts +26 -4
  142. package/src/http/config.ts +3 -0
  143. package/src/http/context.ts +2 -0
  144. package/src/http/core.ts +39 -2
  145. package/src/http/events.ts +6 -2
  146. package/src/http/favorite-owner.ts +1 -1
  147. package/src/http/fs.ts +38 -3
  148. package/src/http/inbox-state.ts +58 -8
  149. package/src/http/index.ts +3 -1
  150. package/src/http/memory.ts +3 -1
  151. package/src/http/ranking.ts +367 -0
  152. package/src/http/realtime.ts +26 -21
  153. package/src/http/route-def.ts +77 -11
  154. package/src/http/script-runs.ts +2 -1
  155. package/src/http/scripts.ts +8 -0
  156. package/src/http/session-access.ts +179 -0
  157. package/src/http/session-data.ts +10 -2
  158. package/src/http/sessions.ts +212 -12
  159. package/src/http/stats.ts +7 -3
  160. package/src/http/tasks.ts +83 -7
  161. package/src/http/used-by.ts +11 -3
  162. package/src/kv-reserved-namespaces.ts +1 -0
  163. package/src/prompts/session-templates.ts +3 -1
  164. package/src/providers/amp-adapter.ts +1 -1
  165. package/src/ranking/telemetry-ranking.ts +147 -0
  166. package/src/ranking/usage.ts +57 -0
  167. package/src/rbac/admission.ts +22 -7
  168. package/src/rbac/legacy-policy.ts +2 -0
  169. package/src/rbac/permissions.ts +9 -0
  170. package/src/realtime/auth.ts +69 -0
  171. package/src/realtime/tickets.ts +4 -1
  172. package/src/realtime/transport.ts +77 -9
  173. package/src/slack/blocks.ts +18 -0
  174. package/src/slack/dm.ts +29 -0
  175. package/src/telemetry-contract/EVENTS.md +3 -0
  176. package/src/telemetry-contract/SOURCE.json +37 -4
  177. package/src/telemetry-contract/catalog.json +69 -0
  178. package/src/telemetry-contract/ranking/fixtures/expected.json +30 -0
  179. package/src/telemetry-contract/ranking/fixtures/invalid/bad-category.json +11 -0
  180. package/src/telemetry-contract/ranking/fixtures/invalid/bad-claim.json +11 -0
  181. package/src/telemetry-contract/ranking/fixtures/invalid/blank-description.json +11 -0
  182. package/src/telemetry-contract/ranking/fixtures/invalid/blank-name.json +11 -0
  183. package/src/telemetry-contract/ranking/fixtures/invalid/description-too-long.json +11 -0
  184. package/src/telemetry-contract/ranking/fixtures/invalid/domain-uppercase.json +11 -0
  185. package/src/telemetry-contract/ranking/fixtures/invalid/domain-with-scheme.json +11 -0
  186. package/src/telemetry-contract/ranking/fixtures/invalid/domain-with-www.json +11 -0
  187. package/src/telemetry-contract/ranking/fixtures/invalid/http-source-url.json +11 -0
  188. package/src/telemetry-contract/ranking/fixtures/invalid/missing-description.json +10 -0
  189. package/src/telemetry-contract/ranking/fixtures/invalid/missing-version.json +10 -0
  190. package/src/telemetry-contract/ranking/fixtures/invalid/name-not-string.json +11 -0
  191. package/src/telemetry-contract/ranking/fixtures/invalid/name-too-long.json +11 -0
  192. package/src/telemetry-contract/ranking/fixtures/invalid/not-object.json +1 -0
  193. package/src/telemetry-contract/ranking/fixtures/invalid/null.json +1 -0
  194. package/src/telemetry-contract/ranking/fixtures/invalid/other-with-subcategory.json +11 -0
  195. package/src/telemetry-contract/ranking/fixtures/invalid/oversize.json +1 -0
  196. package/src/telemetry-contract/ranking/fixtures/invalid/short-claim.json +11 -0
  197. package/src/telemetry-contract/ranking/fixtures/invalid/subcategory-other-category.json +11 -0
  198. package/src/telemetry-contract/ranking/fixtures/invalid/trailing-data.json +1 -0
  199. package/src/telemetry-contract/ranking/fixtures/invalid/unknown-field.json +12 -0
  200. package/src/telemetry-contract/ranking/fixtures/invalid/unsupported-version.json +11 -0
  201. package/src/telemetry-contract/ranking/fixtures/invalid/updated-at-not-date.json +11 -0
  202. package/src/telemetry-contract/ranking/fixtures/invalid/updated-at-offset.json +11 -0
  203. package/src/telemetry-contract/ranking/fixtures/invalid/wrong-case-field.json +11 -0
  204. package/src/telemetry-contract/ranking/fixtures/valid/category-without-subcategory.json +11 -0
  205. package/src/telemetry-contract/ranking/fixtures/valid/full.json +11 -0
  206. package/src/telemetry-contract/ranking/fixtures/valid/minimal.json +11 -0
  207. package/src/telemetry-contract/ranking/fixtures/valid/padded-text.json +11 -0
  208. package/src/telemetry-contract/ranking/fixtures/valid/unicode-name.json +11 -0
  209. package/src/telemetry-contract/ranking/listing.v1.schema.json +61 -0
  210. package/src/telemetry-contract/ranking/taxonomy.json +8 -0
  211. package/src/telemetry-contract/ranking-taxonomy.gen.ts +11 -0
  212. package/src/telemetry-contract/types.gen.ts +708 -1
  213. package/src/telemetry.ts +26 -2
  214. package/src/tests/apps-rbac.test.ts +189 -2
  215. package/src/tests/apps-script-types.test.ts +16 -3
  216. package/src/tests/asset-key-api.test.ts +128 -0
  217. package/src/tests/asset-key-invariants.test.ts +179 -3
  218. package/src/tests/asset-key-migration.test.ts +35 -0
  219. package/src/tests/check-pr-body.test.ts +23 -0
  220. package/src/tests/check-ranking-entry.test.ts +146 -0
  221. package/src/tests/db-extraction-contract.test.ts +1 -0
  222. package/src/tests/db-task-read-contract.test.ts +1 -0
  223. package/src/tests/docs-index-footprint.test.js +2 -2
  224. package/src/tests/heartbeat-checklist.test.ts +88 -0
  225. package/src/tests/heartbeat-jev-gate.test.ts +394 -10
  226. package/src/tests/inbox-state.test.ts +167 -0
  227. package/src/tests/kv-tool.test.ts +15 -0
  228. package/src/tests/org-identity.test.ts +44 -0
  229. package/src/tests/ranking-listing.test.ts +112 -0
  230. package/src/tests/ranking-route.test.ts +319 -0
  231. package/src/tests/ranking-usage.test.ts +50 -0
  232. package/src/tests/rbac-admission-e2e.test.ts +8 -0
  233. package/src/tests/rbac-admission.test.ts +38 -0
  234. package/src/tests/rbac-charact-http.test.ts +4 -3
  235. package/src/tests/rbac-engine.test.ts +2 -0
  236. package/src/tests/rbac-roles.test.ts +2 -0
  237. package/src/tests/realtime-room-surfaces.test.ts +3 -1
  238. package/src/tests/realtime-session-join-race.test.ts +142 -0
  239. package/src/tests/realtime-tickets.test.ts +24 -17
  240. package/src/tests/realtime-transport.test.ts +91 -0
  241. package/src/tests/script-connections.test.ts +2 -0
  242. package/src/tests/session-route-posture.test.ts +639 -0
  243. package/src/tests/session-sharing-routes.test.ts +282 -0
  244. package/src/tests/session-sharing.test.ts +526 -0
  245. package/src/tests/sessions-detail-batch.test.ts +7 -1
  246. package/src/tests/slack-tool-blocks.test.ts +101 -0
  247. package/src/tests/slack-update.test.ts +55 -0
  248. package/src/tests/slack-user-dm.test.ts +177 -0
  249. package/src/tests/used-by-route.test.ts +10 -0
  250. package/src/tools/slack-post.ts +18 -12
  251. package/src/tools/slack-read.ts +13 -1
  252. package/src/tools/slack-reply.ts +7 -10
  253. package/src/tools/slack-start-thread.ts +18 -11
  254. package/src/tools/slack-update.ts +2 -9
  255. package/src/types.ts +37 -0
  256. package/src/utils/org-identity.ts +33 -0
  257. package/templates/skills/apps/SKILL.md +17 -0
  258. package/templates/skills/apps/content.md +17 -0
  259. package/templates/skills/code-quality/content.md +2 -2
  260. package/templates/skills/pages/content.md +4 -0
  261. package/templates/skills/swarm-scripts/SKILL.md +6 -0
  262. package/templates/skills/swarm-scripts/content.md +6 -0
  263. package/dist/handlers-t5pbabwf.js +0 -37
  264. package/dist/index-qyjbb7br.js +0 -39
  265. package/dist/{cli-n5mrsg0f.js → cli-60cgh1rv.js} +3 -3
  266. /package/dist/{cli-j0v75y13.js → cli-y83zk5sb.js} +0 -0
@@ -4,25 +4,28 @@ import {
4
4
  getEncryptionKey,
5
5
  init_crypto,
6
6
  getDbClient2,
7
- scheduleOrgDomainRecompute,
8
- init_telemetry_identity,
9
7
  rowToAgent,
10
8
  createAgent2,
11
9
  getAgentById2,
12
10
  getAllAgents2,
13
11
  init_agents,
14
- validateRuntimeTokenTtlHours,
15
12
  validateControllerTokenTtlDays,
16
13
  init_swarm_config_guard,
17
14
  registerStoredSecret,
18
15
  init_secret_registry,
19
16
  upsertSwarmConfig2,
20
17
  init_db3
21
- } from "./cli-4c7k75rq.js";
18
+ } from "./cli-rg7ntypm.js";
22
19
  import {
23
20
  createRuntimeProvider,
24
21
  init_runtime_providers
25
22
  } from "./cli-wk8ccrz6.js";
23
+ import {
24
+ closeSessionTokenConnections,
25
+ init_session_token_connections,
26
+ insertSessionToken,
27
+ init_users
28
+ } from "./cli-8cxkw1f5.js";
26
29
  import {
27
30
  RuntimeControllerCreateSchema,
28
31
  RuntimeControllerUpdateSchema,
@@ -30,7 +33,7 @@ import {
30
33
  RuntimePoolUpdateSchema,
31
34
  RuntimePoolCreateAgentSchema,
32
35
  init_types
33
- } from "./cli-ksrphveb.js";
36
+ } from "./cli-a1esmmee.js";
34
37
  import {
35
38
  scrubSecrets,
36
39
  registerVolatileSecret,
@@ -41,371 +44,6 @@ import {
41
44
  __esm
42
45
  } from "./cli-242037k3.js";
43
46
 
44
- // src/utils/session-token-connections.ts
45
- function registerSessionTokenConnection(tokenId, close) {
46
- let callbacks = connections.get(tokenId);
47
- if (!callbacks) {
48
- callbacks = new Set;
49
- connections.set(tokenId, callbacks);
50
- }
51
- callbacks.add(close);
52
- return () => {
53
- callbacks.delete(close);
54
- if (callbacks.size === 0)
55
- connections.delete(tokenId);
56
- };
57
- }
58
- function closeSessionTokenConnections(tokenIds) {
59
- for (const tokenId of tokenIds) {
60
- for (const close of connections.get(tokenId) ?? [])
61
- close();
62
- }
63
- }
64
- var connections;
65
- var init_session_token_connections = __esm(() => {
66
- connections = new Map;
67
- });
68
-
69
- // src/be/users.ts
70
- import { createHash, randomBytes, randomUUID } from "node:crypto";
71
- function actorString(actor) {
72
- return `${actor.kind}:${actor.id}`;
73
- }
74
- function rowToUser(row) {
75
- return {
76
- id: row.id,
77
- name: row.name,
78
- email: row.email ?? undefined,
79
- role: row.role ?? undefined,
80
- notes: row.notes ?? undefined,
81
- emailAliases: row.emailAliases ? JSON.parse(row.emailAliases) : [],
82
- preferredChannel: row.preferredChannel ?? "slack",
83
- timezone: row.timezone ?? undefined,
84
- metadata: row.metadata ? JSON.parse(row.metadata) : undefined,
85
- dailyBudgetUsd: row.dailyBudgetUsd ?? null,
86
- status: row.status ?? "active",
87
- createdAt: row.createdAt,
88
- lastUpdatedAt: row.lastUpdatedAt
89
- };
90
- }
91
- async function findUserById(id) {
92
- const row = await getDbClient2().get("SELECT * FROM users WHERE id = ?", [id]);
93
- return row ? rowToUser(row) : null;
94
- }
95
- async function findUserByExternalId(kind, externalId) {
96
- const row = await getDbClient2().get(`SELECT u.* FROM users u
97
- INNER JOIN user_external_ids x ON x.userId = u.id
98
- WHERE x.kind = ? AND x.externalId = ?`, [kind, externalId]);
99
- return row ? rowToUser(row) : null;
100
- }
101
- async function findUserByEmail(email) {
102
- const lower = email.toLowerCase();
103
- const db = getDbClient2();
104
- const primary = await db.get("SELECT * FROM users WHERE LOWER(email) = LOWER(?)", [
105
- email
106
- ]);
107
- if (primary)
108
- return rowToUser(primary);
109
- const aliasRows = await db.query("SELECT * FROM users WHERE emailAliases IS NOT NULL AND emailAliases != '[]'");
110
- for (const r of aliasRows) {
111
- const aliases = r.emailAliases ? JSON.parse(r.emailAliases) : [];
112
- if (aliases.some((a) => a.toLowerCase() === lower)) {
113
- return rowToUser(r);
114
- }
115
- }
116
- return null;
117
- }
118
- async function findUsersByName(name) {
119
- const trimmed = name.trim();
120
- if (!trimmed)
121
- return [];
122
- const client = getDbClient2();
123
- const exact = await client.query("SELECT * FROM users WHERE LOWER(name) = LOWER(?)", [
124
- trimmed
125
- ]);
126
- if (exact.length > 0)
127
- return exact.map(rowToUser);
128
- const firstToken = trimmed.split(/\s+/)[0] ?? trimmed;
129
- const prefixed = await client.query("SELECT * FROM users WHERE LOWER(name) LIKE LOWER(?) || '%'", [firstToken]);
130
- return prefixed.map(rowToUser);
131
- }
132
- async function getUserIdentities(userId) {
133
- return getDbClient2().query("SELECT kind, externalId FROM user_external_ids WHERE userId = ? ORDER BY kind, externalId", [userId]);
134
- }
135
- function rowToEvent(row) {
136
- return {
137
- id: row.id,
138
- userId: row.userId,
139
- eventType: row.eventType,
140
- actor: row.actor,
141
- before: row.beforeJson == null ? null : JSON.parse(row.beforeJson),
142
- after: row.afterJson == null ? null : JSON.parse(row.afterJson),
143
- createdAt: row.createdAt
144
- };
145
- }
146
- async function listUserEvents(userId, opts = {}) {
147
- const limit = Math.max(1, Math.min(opts.limit ?? 50, 200));
148
- const before = opts.before;
149
- const client = getDbClient2();
150
- if (before) {
151
- const rows = await client.query(`SELECT id, userId, eventType, actor, beforeJson, afterJson, createdAt
152
- FROM user_identity_events
153
- WHERE userId = ? AND createdAt < ?
154
- ORDER BY createdAt DESC, rowid DESC
155
- LIMIT ?`, [userId, before, limit]);
156
- return rows.map(rowToEvent);
157
- }
158
- const rows = await client.query(`SELECT id, userId, eventType, actor, beforeJson, afterJson, createdAt
159
- FROM user_identity_events
160
- WHERE userId = ?
161
- ORDER BY createdAt DESC, rowid DESC
162
- LIMIT ?`, [userId, limit]);
163
- return rows.map(rowToEvent);
164
- }
165
- async function listUserTokens(userId) {
166
- return getDbClient2().query(`SELECT id, userId, label, tokenPreview, createdAt, lastUsedAt, revokedAt
167
- FROM user_tokens
168
- WHERE userId = ?
169
- ORDER BY createdAt DESC`, [userId]);
170
- }
171
- async function recordIdentityEvent(userId, eventType, actor, before, after) {
172
- await getDbClient2().run(`INSERT INTO user_identity_events (id, userId, eventType, actor, beforeJson, afterJson, createdAt)
173
- VALUES (?, ?, ?, ?, ?, ?, ?)`, [
174
- randomUUID().replace(/-/g, ""),
175
- userId,
176
- eventType,
177
- actorString(actor),
178
- before == null ? null : JSON.stringify(before),
179
- after == null ? null : JSON.stringify(after),
180
- new Date().toISOString()
181
- ]);
182
- }
183
- async function findOrCreateUserByEmail(email, hints, actor) {
184
- const existing = await findUserByEmail(email);
185
- if (existing) {
186
- await recordIdentityEvent(existing.id, "auto_merge", actor, null, { email, hints });
187
- return { user: existing, created: false };
188
- }
189
- const id = randomUUID().replace(/-/g, "");
190
- const now = new Date().toISOString();
191
- const name = hints.name?.trim() || email.split("@")[0] || email;
192
- const created = await getDbClient2().transaction(async (tx) => {
193
- await tx.run(`INSERT INTO users (id, name, email, role, notes, emailAliases, preferredChannel, timezone, createdAt, lastUpdatedAt, status)
194
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'active')`, [
195
- id,
196
- name,
197
- email,
198
- hints.role ?? null,
199
- hints.notes ?? null,
200
- "[]",
201
- hints.preferredChannel ?? "slack",
202
- null,
203
- now,
204
- now
205
- ]);
206
- const row = await tx.get("SELECT * FROM users WHERE id = ?", [id]);
207
- if (!row)
208
- throw new Error("Failed to create user");
209
- await recordIdentityEvent(id, "identity_added", actor, null, { email, name });
210
- return rowToUser(row);
211
- });
212
- getDbClient2().afterCommit(scheduleOrgDomainRecompute);
213
- return { user: created, created: true };
214
- }
215
- async function linkIdentity(userId, kind, externalId, actor) {
216
- await getDbClient2().transaction(async (tx) => {
217
- await tx.run("INSERT INTO user_external_ids (userId, kind, externalId) VALUES (?, ?, ?)", [
218
- userId,
219
- kind,
220
- externalId
221
- ]);
222
- await recordIdentityEvent(userId, "identity_added", actor, null, { kind, externalId });
223
- });
224
- }
225
- async function unlinkIdentity(userId, kind, externalId, actor) {
226
- await getDbClient2().transaction(async (tx) => {
227
- await tx.run("DELETE FROM user_external_ids WHERE userId = ? AND kind = ? AND externalId = ?", [
228
- userId,
229
- kind,
230
- externalId
231
- ]);
232
- await recordIdentityEvent(userId, "identity_removed", actor, { kind, externalId }, null);
233
- });
234
- }
235
- function base62(bytes) {
236
- const alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
237
- let out = "";
238
- for (const b of bytes) {
239
- out += alphabet[b % 62];
240
- }
241
- return out;
242
- }
243
- function sha256Hex(input) {
244
- return createHash("sha256").update(input).digest("hex");
245
- }
246
- async function mintToken(userId, label, actor, options = {}) {
247
- const plaintext = `${TOKEN_PREFIX}${base62(randomBytes(24))}`;
248
- const tokenId = randomUUID().replace(/-/g, "");
249
- const hash = sha256Hex(plaintext);
250
- const preview = plaintext.slice(-4);
251
- const now = new Date().toISOString();
252
- await getDbClient2().transaction(async (tx) => {
253
- await tx.run(`INSERT INTO user_tokens (id, userId, label, tokenHash, tokenPreview, createdAt)
254
- VALUES (?, ?, ?, ?, ?, ?)`, [tokenId, userId, label, hash, preview, now]);
255
- await recordIdentityEvent(userId, "token_minted", actor, null, {
256
- tokenId,
257
- label,
258
- preview,
259
- ...options.source ? { source: options.source } : {}
260
- });
261
- });
262
- return { tokenId, plaintext };
263
- }
264
- async function revokeToken(tokenId, actor) {
265
- await getDbClient2().transaction(async (tx) => {
266
- const row = await tx.get("SELECT userId, label, tokenPreview FROM user_tokens WHERE id = ?", [tokenId]);
267
- if (!row) {
268
- throw new Error(`Token not found: ${tokenId}`);
269
- }
270
- await tx.run("UPDATE user_tokens SET revokedAt = ? WHERE id = ?", [
271
- new Date().toISOString(),
272
- tokenId
273
- ]);
274
- await recordIdentityEvent(row.userId, "token_revoked", actor, { tokenId, label: row.label, preview: row.tokenPreview }, null);
275
- });
276
- }
277
- async function resolveUserByToken(plaintext) {
278
- const hash = sha256Hex(plaintext);
279
- const client = getDbClient2();
280
- const row = await client.get("SELECT id, userId, revokedAt FROM user_tokens WHERE tokenHash = ?", [hash]);
281
- if (!row || row.revokedAt !== null)
282
- return null;
283
- try {
284
- await client.run("UPDATE user_tokens SET lastUsedAt = ? WHERE id = ?", [
285
- new Date().toISOString(),
286
- row.id
287
- ]);
288
- } catch {}
289
- return findUserById(row.userId);
290
- }
291
- async function mintSessionToken(agentId, taskId, ttlMs, parent) {
292
- if (parent) {
293
- return await getDbClient2().transaction(async (client) => {
294
- const row = await client.get(`SELECT expiresAt FROM session_tokens WHERE id = ? AND agentId = ? AND runtimeId = ?
295
- AND revokedAt IS NULL AND expiresAt > ?`, [parent.tokenId, agentId, parent.runtimeId, new Date().toISOString()]);
296
- if (!row)
297
- throw new InvalidRuntimeTokenError;
298
- return await insertSessionToken(agentId, taskId, null, ttlMs, parent.runtimeId, row.expiresAt);
299
- });
300
- }
301
- return await insertSessionToken(agentId, taskId, null, ttlMs);
302
- }
303
- function runtimeTokenTtlMs() {
304
- const hours = process.env.RUNTIME_TOKEN_TTL_HOURS ?? "168";
305
- return (validateRuntimeTokenTtlHours(hours) === null ? Number(hours) : 168) * 60 * 60 * 1000;
306
- }
307
- async function mintRuntimeToken(agentId, runtimeId, ttlMs = runtimeTokenTtlMs()) {
308
- return await insertSessionToken(agentId, null, runtimeId, ttlMs);
309
- }
310
- async function insertSessionToken(agentId, taskId, runtimeId, ttlMs, parentRuntimeId = null, expiresAtCeiling, controllerId = null) {
311
- const plaintext = `${SESSION_TOKEN_PREFIX}${base62(randomBytes(24))}`;
312
- const tokenId = randomUUID().replace(/-/g, "");
313
- const hash = sha256Hex(plaintext);
314
- const preview = plaintext.slice(-4);
315
- const now = new Date;
316
- const expiresAt = new Date(Math.min(now.getTime() + ttlMs, expiresAtCeiling ? Date.parse(expiresAtCeiling) : Infinity)).toISOString();
317
- await getDbClient2().run(`INSERT INTO session_tokens
318
- (id, tokenHash, tokenPreview, agentId, taskId, runtimeId, parentRuntimeId, expiresAt, createdAt, controllerId)
319
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
320
- tokenId,
321
- hash,
322
- preview,
323
- agentId,
324
- taskId,
325
- runtimeId,
326
- parentRuntimeId,
327
- expiresAt,
328
- now.toISOString(),
329
- controllerId
330
- ]);
331
- return { tokenId, plaintext };
332
- }
333
- async function revokeSessionToken(tokenId) {
334
- await getDbClient2().transaction(async (client) => {
335
- const row = await client.get("SELECT runtimeId FROM session_tokens WHERE id = ?", [tokenId]);
336
- if (row?.runtimeId) {
337
- await revokeRuntimeTokensForRuntime(row.runtimeId);
338
- } else {
339
- await client.run("UPDATE session_tokens SET revokedAt = ? WHERE id = ? AND revokedAt IS NULL", [new Date().toISOString(), tokenId]);
340
- getDbClient2().afterCommit(() => closeSessionTokenConnections([tokenId]));
341
- }
342
- });
343
- }
344
- async function revokeRuntimeTokensForRuntime(runtimeId) {
345
- await getDbClient2().transaction(async (client) => {
346
- const rows = await client.query("SELECT id FROM session_tokens WHERE runtimeId = ? OR parentRuntimeId = ?", [runtimeId, runtimeId]);
347
- await client.run(`UPDATE session_tokens SET revokedAt = ?
348
- WHERE (runtimeId = ? OR parentRuntimeId = ?) AND revokedAt IS NULL`, [new Date().toISOString(), runtimeId, runtimeId]);
349
- getDbClient2().afterCommit(() => {
350
- unregisterVolatileSecret(`runtime:${runtimeId}`);
351
- closeSessionTokenConnections(rows.map((row) => row.id));
352
- });
353
- });
354
- }
355
- async function resolveSessionToken(plaintext, options = {}) {
356
- if (!plaintext.startsWith(SESSION_TOKEN_PREFIX))
357
- return null;
358
- const hash = sha256Hex(plaintext);
359
- const client = getDbClient2();
360
- const row = await client.get(`SELECT s.id, s.agentId, s.taskId, s.runtimeId, s.controllerId, s.expiresAt, s.revokedAt,
361
- c.placement FROM session_tokens s LEFT JOIN runtime_controllers c ON c.id = s.controllerId
362
- WHERE s.tokenHash = ?`, [hash]);
363
- if (!row || row.revokedAt !== null)
364
- return null;
365
- if (new Date(row.expiresAt) <= new Date)
366
- return null;
367
- if (row.controllerId !== null) {
368
- return row.placement === "remote" ? {
369
- kind: "controller",
370
- controllerId: row.controllerId,
371
- tokenId: row.id,
372
- expiresAt: row.expiresAt
373
- } : null;
374
- }
375
- if (options.touch !== false) {
376
- try {
377
- await client.run("UPDATE session_tokens SET lastUsedAt = ? WHERE id = ?", [
378
- new Date().toISOString(),
379
- row.id
380
- ]);
381
- } catch {}
382
- }
383
- return {
384
- kind: "agent",
385
- tokenId: row.id,
386
- agentId: row.agentId,
387
- taskId: row.taskId,
388
- runtimeId: row.runtimeId,
389
- expiresAt: row.expiresAt
390
- };
391
- }
392
- function fingerprintApiKey(rawKey) {
393
- return `op:${sha256Hex(rawKey).slice(0, 16)}`;
394
- }
395
- var TOKEN_PREFIX = "aswt_", SESSION_TOKEN_PREFIX = "aseph_", InvalidRuntimeTokenError;
396
- var init_users = __esm(() => {
397
- init_telemetry_identity();
398
- init_secret_scrubber();
399
- init_session_token_connections();
400
- init_db3();
401
- init_swarm_config_guard();
402
- InvalidRuntimeTokenError = class InvalidRuntimeTokenError extends Error {
403
- constructor() {
404
- super("Runtime token is no longer valid");
405
- }
406
- };
407
- });
408
-
409
47
  // src/be/runtime-pools/errors.ts
410
48
  var RuntimePoolError2;
411
49
  var init_errors = __esm(() => {
@@ -829,4 +467,4 @@ var init_db = __esm(() => {
829
467
  init_errors();
830
468
  });
831
469
 
832
- export { RuntimePoolError2, registerSessionTokenConnection, init_session_token_connections, findUserById, findUserByExternalId, findUserByEmail, findUsersByName, getUserIdentities, listUserEvents, listUserTokens, recordIdentityEvent, findOrCreateUserByEmail, linkIdentity, unlinkIdentity, mintToken, revokeToken, resolveUserByToken, InvalidRuntimeTokenError, mintSessionToken, mintRuntimeToken, revokeSessionToken, revokeRuntimeTokensForRuntime, resolveSessionToken, fingerprintApiKey, init_users, mintControllerToken, init_tokens, listRuntimeControllers2, getRuntimeController2, getRuntimeControllerTarget2, checkE2bControllerConfig2, createRuntimeController2, updateRuntimeController2, deleteRuntimeController2, listRuntimePools2, getRuntimePool2, createRuntimePool2, updateRuntimePool2, deleteRuntimePool2, bindAgentToPool2, listAgentsForPool2, getPoolForAgent2, resolvePoolDelivery2, createPoolAgent2, loadRuntimeControllerSecrets2, init_db };
470
+ export { RuntimePoolError2, mintControllerToken, init_tokens, listRuntimeControllers2, getRuntimeController2, getRuntimeControllerTarget2, checkE2bControllerConfig2, createRuntimeController2, updateRuntimeController2, deleteRuntimeController2, listRuntimePools2, getRuntimePool2, createRuntimePool2, updateRuntimePool2, deleteRuntimePool2, bindAgentToPool2, listAgentsForPool2, getPoolForAgent2, resolvePoolDelivery2, createPoolAgent2, loadRuntimeControllerSecrets2, init_db };
@@ -21,7 +21,7 @@ import {
21
21
  import {
22
22
  DEFAULT_MODEL_TIER_MAP,
23
23
  init_types
24
- } from "./cli-ksrphveb.js";
24
+ } from "./cli-a1esmmee.js";
25
25
  import {
26
26
  getOpenRouterBaseUrl,
27
27
  getOpenRouterAttributionHeaders,