@desplega.ai/agent-swarm 2.13.1 → 2.13.2

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 (183) hide show
  1. package/README.md +1 -1
  2. package/dist/{acp-adapter-xtj40wd8.js → acp-adapter-x1qqgzwx.js} +5 -5
  3. package/dist/{acp-targets-n7vm5atw.js → acp-targets-mz8c5dnt.js} +4 -4
  4. package/dist/{actions-hq6wp9xv.js → actions-5ft3qp5a.js} +25 -25
  5. package/dist/{agent-fs-provision-y0qc1rdd.js → agent-fs-provision-6fgz7wvz.js} +4 -4
  6. package/dist/{amp-adapter-1qqs6h91.js → amp-adapter-nthn8ezm.js} +1 -1
  7. package/dist/{app-7m4z44rv.js → app-535m78qw.js} +8 -8
  8. package/dist/{approval-notifications-8sr41gjx.js → approval-notifications-dewbk403.js} +9 -9
  9. package/dist/{assistant-hkczwfv6.js → assistant-39zyabv2.js} +25 -25
  10. package/dist/{boot-args-schema-8025snev.js → boot-args-schema-bqv5bf77.js} +1 -1
  11. package/dist/{boot-reembed-4bbpxjh1.js → boot-reembed-157c0gcz.js} +1 -1
  12. package/dist/{boot-reembed-15m87nr1.js → boot-reembed-fas7z3zn.js} +1 -1
  13. package/dist/{boot-scrub-sweep-eajr97e9.js → boot-scrub-sweep-tmec0be2.js} +2 -2
  14. package/dist/{boot-seeds-9cwy39jx.js → boot-seeds-32zm50x2.js} +4 -4
  15. package/dist/{claude-adapter-g61wa4rt.js → claude-adapter-gwq7x2nj.js} +2 -2
  16. package/dist/{claude-managed-adapter-znkk0prm.js → claude-managed-adapter-rkvw6fvq.js} +2 -2
  17. package/dist/{claude-managed-setup-f1wndkr2.js → claude-managed-setup-0vgz4d1j.js} +4 -4
  18. package/dist/{claude-sdk-session-687xzf21.js → claude-sdk-session-5wbwxy8c.js} +11964 -11769
  19. package/dist/{cli-snypfjgj.js → cli-0f7n3td3.js} +1 -1
  20. package/dist/{cli-0m77n7ej.js → cli-1f48qdnb.js} +54 -12
  21. package/dist/{cli-04103ryh.js → cli-1gevjrc1.js} +1 -1
  22. package/dist/{cli-a8ts6x1n.js → cli-2wde56gv.js} +5 -5
  23. package/dist/{cli-aebswqmz.js → cli-31vt7baf.js} +14 -14
  24. package/dist/{cli-cn6fpa1p.js → cli-4djg31jh.js} +1 -1
  25. package/dist/{cli-bjmq14k9.js → cli-5k1hvycs.js} +3 -3
  26. package/dist/{cli-mmw2sjaf.js → cli-62fjschk.js} +1 -1
  27. package/dist/{cli-t90k0phh.js → cli-69eq6gdk.js} +15 -15
  28. package/dist/{cli-dd57p1gd.js → cli-6rmryz03.js} +2 -2
  29. package/dist/{cli-byxsctca.js → cli-7m6bbtab.js} +6 -6
  30. package/dist/{cli-c8kqmzzf.js → cli-8a4qg44m.js} +1 -1
  31. package/dist/{cli-8rbkw18r.js → cli-8qvte9hn.js} +2 -2
  32. package/dist/{cli-h03j6je3.js → cli-a6rzw649.js} +2 -2
  33. package/dist/{cli-w41bvvms.js → cli-b0kqw55g.js} +1 -1
  34. package/dist/{cli-84xtgbn6.js → cli-b0m3bg0f.js} +100 -2
  35. package/dist/{cli-zaate0rd.js → cli-c9bwawf9.js} +2 -2
  36. package/dist/{cli-4mj5g29m.js → cli-cs26ed89.js} +6 -6
  37. package/dist/{cli-yeh3g1q6.js → cli-d0jb2qnt.js} +23 -23
  38. package/dist/{cli-cp0m07wb.js → cli-d528acsw.js} +1 -1
  39. package/dist/{cli-fn8aj7gb.js → cli-dnvmwsvc.js} +95 -68
  40. package/dist/{cli-w6c6dj91.js → cli-e87fg3en.js} +1 -1
  41. package/dist/{cli-h9bejmkf.js → cli-erh1rgh4.js} +49 -26
  42. package/dist/{cli-9xx36trj.js → cli-ewb028rs.js} +2 -2
  43. package/dist/{cli-hs3mqswp.js → cli-f1sdh8ca.js} +4 -4
  44. package/dist/{cli-zvpkrgsc.js → cli-fcwrd7bh.js} +3 -3
  45. package/dist/{cli-sfajkbd7.js → cli-fgm2mad9.js} +2 -2
  46. package/dist/{cli-32xndx6b.js → cli-g0b3ma7r.js} +1 -1
  47. package/dist/{cli-nk8swfpx.js → cli-gc7jkf4a.js} +3 -3
  48. package/dist/{cli-z6m6xzxt.js → cli-getrvmtx.js} +26 -5
  49. package/dist/{cli-y6qqbpwc.js → cli-j2ybkdk2.js} +1 -1
  50. package/dist/{cli-1dr5at77.js → cli-jkkcm72j.js} +10 -10
  51. package/dist/{cli-cqxwjb93.js → cli-ka13xx6b.js} +1 -1
  52. package/dist/{cli-4h90xaet.js → cli-m1wddksc.js} +1 -1
  53. package/dist/{cli-qx1dwrr5.js → cli-n14r8h4n.js} +2 -2
  54. package/dist/{cli-jhtvt7gn.js → cli-n46d87mj.js} +3 -3
  55. package/dist/{cli-13t0smbk.js → cli-nkfv398a.js} +185 -58
  56. package/dist/{cli-p7g7wd9n.js → cli-nvqq3232.js} +7 -7
  57. package/dist/{cli-0a336ze7.js → cli-r4fphq38.js} +3 -3
  58. package/dist/{cli-4tbvndmm.js → cli-r8ddn0hf.js} +1 -1
  59. package/dist/{cli-3m8vqehw.js → cli-rvhaahfv.js} +2 -2
  60. package/dist/{cli-cd9acnvd.js → cli-s08zsqva.js} +2 -2
  61. package/dist/{cli-w24f3j49.js → cli-sjk85d7v.js} +6 -5
  62. package/dist/{cli-grcc2h2g.js → cli-t9nxq30h.js} +6 -6
  63. package/dist/{cli-6r1dwegd.js → cli-tbdw3f92.js} +2 -2
  64. package/dist/{cli-0fx95c06.js → cli-tceqvv6h.js} +2 -2
  65. package/dist/{cli-tzzas8rb.js → cli-tgmate57.js} +2 -2
  66. package/dist/{cli-3zyme1wt.js → cli-wdtqkqnq.js} +3 -3
  67. package/dist/{cli-8cmjkbvj.js → cli-x7aqhxj5.js} +1 -1
  68. package/dist/{cli-7ewre3dm.js → cli-xerdrnqs.js} +2 -2
  69. package/dist/{cli-c0tyzt73.js → cli-xysy1g8x.js} +1 -1
  70. package/dist/{cli-1b5axkt1.js → cli-zm6bkx3e.js} +2 -2
  71. package/dist/{cli-1carhg8g.js → cli-zqy28rwx.js} +2 -2
  72. package/dist/cli.js +17 -16
  73. package/dist/{codex-adapter-ysfg6ty3.js → codex-adapter-x25xfbnh.js} +2 -2
  74. package/dist/{codex-session-runner-823scr6g.js → codex-session-runner-kn5xnrvp.js} +2 -2
  75. package/dist/{commands-5rbm07fz.js → commands-8n59gxmy.js} +3 -3
  76. package/dist/{controllers-connect-34jzhfft.js → controllers-connect-09gvkrhc.js} +24 -24
  77. package/dist/core-2b8bv6ny.js +42 -0
  78. package/dist/{db-6bkgbfwk.js → db-e71keqxk.js} +3 -3
  79. package/dist/{db-hcj16x7z.js → db-spg81qtr.js} +1 -1
  80. package/dist/{dispatcher-jgjqrfzv.js → dispatcher-fr4vawwb.js} +23 -23
  81. package/dist/{easter-egg-3d-w17nsny6.js → easter-egg-3d-ac9tv9a6.js} +1 -1
  82. package/dist/{embedding-space-v06fwy7b.js → embedding-space-an77f45k.js} +6 -6
  83. package/dist/{embeddings-g50dxea4.js → embeddings-jkrehejr.js} +1 -1
  84. package/dist/{execute-1n36haw1.js → execute-3mys4nta.js} +1 -1
  85. package/dist/{external-channel-43tv8pg6.js → external-channel-s6zxpts9.js} +2 -2
  86. package/dist/{fx-adapter-bvh05t4a.js → fx-adapter-4yet1c4f.js} +6 -6
  87. package/dist/{grok-adapter-my5j8mdf.js → grok-adapter-8ge6tw7m.js} +6 -6
  88. package/dist/handlers-0r9evrdj.js +41 -0
  89. package/dist/{heartbeat-sf3nk937.js → heartbeat-jjpb44e5.js} +25 -25
  90. package/dist/{hook-m1m9dm6w.js → hook-68gbs87k.js} +1 -1
  91. package/dist/{hook-dqph1e05.js → hook-y6n23zzj.js} +1 -1
  92. package/dist/{http-w0th1cz9.js → http-8c6y008s.js} +297 -97
  93. package/dist/{index-ffba0z8q.js → index-0vthtbc2.js} +20 -18
  94. package/dist/index-1v23363p.js +39 -0
  95. package/dist/index-30qw6vyw.js +44 -0
  96. package/dist/index-6bm3w6cn.js +40 -0
  97. package/dist/{index-gkpfgpg7.js → index-6h3r0vpe.js} +1 -1
  98. package/dist/{index-e8pz8qdg.js → index-7dgxveck.js} +2 -2
  99. package/dist/{index-k8ajc0g0.js → index-maddg9ys.js} +1 -1
  100. package/dist/{index-y4vd4mhn.js → index-mbpxhc4w.js} +1 -1
  101. package/dist/index-rz8ve510.js +569 -0
  102. package/dist/{index-c0e8en64.js → index-we3nd2t0.js} +1 -1
  103. package/dist/{index-pb03vans.js → index-xcw7hjt5.js} +25 -25
  104. package/dist/{index-ez823q84.js → index-ym9fgxad.js} +1 -1
  105. package/dist/{keepalive-2v06q2e8.js → keepalive-7e9r5dvp.js} +4 -4
  106. package/dist/lead-3jpc7kcr.js +79 -0
  107. package/dist/{maintenance-vx7vjhhy.js → maintenance-d3erjvcg.js} +1 -1
  108. package/dist/{oauth-refresh-sweep-g06k4bza.js → oauth-refresh-sweep-0qh70988.js} +3 -3
  109. package/dist/{object-webhooks-3dzdq4fm.js → object-webhooks-ac7v2q5p.js} +7 -7
  110. package/dist/{onboard-232pazny.js → onboard-5yphtken.js} +3 -3
  111. package/dist/{opencode-adapter-t0paqbh8.js → opencode-adapter-0xvyba4m.js} +3 -3
  112. package/dist/{otel-impl-kmpkyp4y.js → otel-impl-svqp691q.js} +1 -1
  113. package/dist/{pending-x0z3vx1x.js → pending-bn4xe5br.js} +24 -24
  114. package/dist/{pi-mono-adapter-7pmypn6d.js → pi-mono-adapter-763s8a3w.js} +6 -6
  115. package/dist/{pricing-refresh-ytjmtyd7.js → pricing-refresh-kfc215mf.js} +2 -2
  116. package/dist/{rbac-roles-fgm5mxr2.js → rbac-roles-3bznvkpt.js} +3 -3
  117. package/dist/{rbac-roles-xyaxekh3.js → rbac-roles-6r4h2ghj.js} +2 -2
  118. package/dist/{render-v2-ws972g4r.js → render-v2-f3qedbpy.js} +8 -8
  119. package/dist/{resume-m6mjzhkp.js → resume-vcag4ann.js} +11 -11
  120. package/dist/{runtime-zzpc0c8a.js → runtime-x0s55z2t.js} +1 -1
  121. package/dist/{session-access-vp35xs91.js → session-access-nwzve8q2.js} +5 -5
  122. package/dist/{session-source-backfill-p73e8zbe.js → session-source-backfill-jpqfzmgz.js} +1 -1
  123. package/dist/{setup-r4kd7rxg.js → setup-d2smwaem.js} +1 -1
  124. package/dist/thread-buffer-8fc703jc.js +42 -0
  125. package/dist/{tree-visibility-07h2tbs2.js → tree-visibility-dwzc8en0.js} +2 -2
  126. package/dist/{user-merge-jobs-96vg9rpe.js → user-merge-jobs-4ce7kma2.js} +3 -3
  127. package/dist/{virtual-modules-vgn3f2x4.js → virtual-modules-78a6yw71.js} +1 -1
  128. package/dist/{work-objects-74hbcx3e.js → work-objects-m0w1e7q8.js} +26 -26
  129. package/dist/worker-3p2vq107.js +79 -0
  130. package/dist/{worker-follow-up-ezavwn5d.js → worker-follow-up-e3t6f895.js} +23 -23
  131. package/openapi.json +3 -2
  132. package/package.json +6 -5
  133. package/src/be/migrations/341_user_token_expiry.sql +4 -0
  134. package/src/be/scripts/run-credential.ts +55 -1
  135. package/src/be/scripts/typecheck.ts +4 -4
  136. package/src/be/scripts/user-code-mode.ts +160 -0
  137. package/src/be/users.ts +48 -7
  138. package/src/commands/onboard/agent-fs-version.ts +1 -1
  139. package/src/http/script-connection-proxy.ts +18 -6
  140. package/src/http/scripts.ts +2 -11
  141. package/src/http/users.ts +1 -0
  142. package/src/integrations/chat-sdk/adapters.ts +29 -0
  143. package/src/integrations/chat-sdk/limits.ts +3 -0
  144. package/src/integrations/chat-sdk/rocketchat/README.md +8 -0
  145. package/src/integrations/chat-sdk/rocketchat/index.ts +790 -0
  146. package/src/integrations/chat-sdk/rocketchat/markdown.ts +210 -0
  147. package/src/integrations/chat-sdk/rocketchat/types.ts +249 -0
  148. package/src/integrations/chat-sdk/runtime.ts +11 -5
  149. package/src/integrations/chat-sdk/schema.ts +37 -3
  150. package/src/integrations/chat-sdk/status.ts +9 -0
  151. package/src/providers/amp-adapter.ts +1 -1
  152. package/src/rbac/legacy-policy.ts +1 -0
  153. package/src/rbac/permissions.ts +4 -0
  154. package/src/scripts-runtime/executors/native.ts +225 -67
  155. package/src/scripts-runtime/mcp-client.ts +2 -1
  156. package/src/scripts-runtime/swarm-sdk.ts +2 -1
  157. package/src/scripts-runtime/types/stdlib.d.ts +4 -4
  158. package/src/scripts-runtime/types/swarm-sdk.d.ts +4 -4
  159. package/src/server-user.ts +98 -0
  160. package/src/tests/chat-sdk-rocketchat-vendored.test.ts +67 -0
  161. package/src/tests/chat-sdk-status-route.test.ts +13 -1
  162. package/src/tests/codex-app-server.test.ts +4 -6
  163. package/src/tests/mcp-user-route.test.ts +10 -1
  164. package/src/tests/script-connections-mcp.test.ts +14 -10
  165. package/src/tests/script-connections-sql.test.ts +6 -2
  166. package/src/tests/script-connections.test.ts +2 -0
  167. package/src/tools/script-common.ts +37 -22
  168. package/src/tools/script-query-types.ts +1 -1
  169. package/src/tools/script-run.ts +1 -1
  170. package/src/tools/script-search.ts +12 -10
  171. package/src/tools/utils.ts +7 -1
  172. package/templates/skills/chat-sdk/content.md +2 -2
  173. package/templates/skills/swarm-docs/content.md +2 -0
  174. package/dist/core-kdehq26g.js +0 -42
  175. package/dist/handlers-wyymeeqh.js +0 -41
  176. package/dist/index-22khdtby.js +0 -44
  177. package/dist/index-np0582ac.js +0 -40
  178. package/dist/index-vgkrj1jt.js +0 -39
  179. package/dist/lead-55z813ng.js +0 -79
  180. package/dist/thread-buffer-cm2nzq6t.js +0 -42
  181. package/dist/worker-5pn2vzx6.js +0 -79
  182. package/dist/{cli-5v6b2am8.js → cli-bp2rt28p.js} +4 -4
  183. /package/dist/{cli-m4ejz4nj.js → cli-cah298e5.js} +0 -0
@@ -0,0 +1,569 @@
1
+ import {
2
+ isTableNode2,
3
+ tableToAscii2,
4
+ parseMarkdown2,
5
+ stringifyMarkdown2,
6
+ walkAst2,
7
+ BaseFormatConverter2,
8
+ Message3,
9
+ ConsoleLogger2,
10
+ defaultEmojiResolver2,
11
+ init_dist8
12
+ } from "./cli-vr4eyq6p.js";
13
+ import {
14
+ AdapterRateLimitError,
15
+ AuthenticationError3,
16
+ ResourceNotFoundError,
17
+ PermissionError,
18
+ ValidationError,
19
+ NetworkError,
20
+ normalizeCodeFences,
21
+ init_dist7
22
+ } from "./cli-b0m3bg0f.js";
23
+ import {
24
+ __esm
25
+ } from "./cli-242037k3.js";
26
+
27
+ // src/integrations/chat-sdk/rocketchat/markdown.ts
28
+ function boundary(char) {
29
+ return char in INLINE_PAIRS ? " " : char;
30
+ }
31
+ function text(node, _parent, _state, info) {
32
+ const { before, after } = info;
33
+ const context = [boundary(before.slice(-1)), boundary(after.charAt(0))];
34
+ let value = node.value;
35
+ for (const [marker, pair] of Object.entries(INLINE_PAIRS)) {
36
+ const touchesMarker = value.startsWith(marker) && before.slice(-1) in INLINE_PAIRS || value.endsWith(marker) && after.charAt(0) in INLINE_PAIRS;
37
+ if (touchesMarker || value.includes(marker) && pair.test(`${context[0]}${value}${context[1]}`)) {
38
+ value = value.replaceAll(marker, `\\${marker}`);
39
+ }
40
+ }
41
+ return value.replace(BLOCK_START, (match, lead, symbol, digits, offset = 0) => {
42
+ if (offset === 0 && lead === "" && before !== `
43
+ `) {
44
+ return match;
45
+ }
46
+ return symbol ? `${lead}\\${symbol}` : `${lead}${digits}\\.`;
47
+ });
48
+ }
49
+ function strong(node, _parent, state, info) {
50
+ return `*${state.containerPhrasing(node, { ...info, before: "*", after: "*" })}*`;
51
+ }
52
+ function emphasis(node, _parent, state, info) {
53
+ return `_${state.containerPhrasing(node, { ...info, before: "_", after: "_" })}_`;
54
+ }
55
+ function strikethrough(node, _parent, state, info) {
56
+ return `~${state.containerPhrasing(node, { ...info, before: "~", after: "~" })}~`;
57
+ }
58
+ var INLINE_PAIRS, BLOCK_START, handlers, RocketChatFormatConverter;
59
+ var init_markdown = __esm(() => {
60
+ init_dist7();
61
+ init_dist8();
62
+ INLINE_PAIRS = {
63
+ "*": /(?:^|[^\p{L}\p{N}])\*(?=\S).*?\S\*(?![\p{L}\p{N}])/mu,
64
+ _: /(?:^|[^\p{L}\p{N}])_(?=\S).*?\S_(?![\p{L}\p{N}])/mu,
65
+ "~": /(?:^|[^\p{L}\p{N}])~(?=\S).*?\S~(?![\p{L}\p{N}])/mu,
66
+ "`": /(?:^|[^\p{L}\p{N}])`(?=\S).*?\S`(?![\p{L}\p{N}])/mu
67
+ };
68
+ BLOCK_START = /(^|\n)(?:([>*-])|(\d+)\.)(?= )/g;
69
+ strong.peek = () => "*";
70
+ emphasis.peek = () => "_";
71
+ strikethrough.peek = () => "~";
72
+ handlers = {
73
+ text,
74
+ strong,
75
+ emphasis,
76
+ delete: strikethrough,
77
+ break: () => `
78
+ `
79
+ };
80
+ RocketChatFormatConverter = class RocketChatFormatConverter extends BaseFormatConverter2 {
81
+ fromAst(ast) {
82
+ const transformed = walkAst2(structuredClone(ast), (node) => {
83
+ if (node.type === "heading") {
84
+ const heading = node;
85
+ const children = heading.children.flatMap((child) => child.type === "strong" ? child.children : [child]);
86
+ return {
87
+ type: "paragraph",
88
+ children: [{ type: "strong", children }]
89
+ };
90
+ }
91
+ if (node.type === "thematicBreak") {
92
+ return {
93
+ type: "paragraph",
94
+ children: [{ type: "text", value: "━━━" }]
95
+ };
96
+ }
97
+ if (isTableNode2(node)) {
98
+ return {
99
+ type: "code",
100
+ value: tableToAscii2(node),
101
+ lang: undefined
102
+ };
103
+ }
104
+ return node;
105
+ });
106
+ return stringifyMarkdown2(transformed, {
107
+ emphasis: "_",
108
+ bullet: "-",
109
+ handlers
110
+ }).trim();
111
+ }
112
+ toAst(markdown) {
113
+ return parseMarkdown2(this.toStandardMarkdown(markdown));
114
+ }
115
+ exceedsIncomingBudget(markdown) {
116
+ return markdown.length > this.maxIncomingParseLength || super.exceedsIncomingBudget(this.toStandardMarkdown(markdown));
117
+ }
118
+ toStandardMarkdown(markdown) {
119
+ return normalizeCodeFences(markdown, {
120
+ convertText: (text) => this.fromRocketChatFormat(text)
121
+ });
122
+ }
123
+ renderPostable(message) {
124
+ if (typeof message === "string") {
125
+ return message;
126
+ }
127
+ if ("raw" in message) {
128
+ return message.raw;
129
+ }
130
+ if ("markdown" in message) {
131
+ return this.fromMarkdown(message.markdown);
132
+ }
133
+ if ("ast" in message) {
134
+ return this.fromAst(message.ast);
135
+ }
136
+ return super.renderPostable(message);
137
+ }
138
+ fromRocketChatFormat(text) {
139
+ let result = text.replace(/(?<!\*)\*(?!\*)([^\n*]+?)(?<!\*)\*(?!\*)/g, "**$1**");
140
+ result = result.replace(/(?<!~)~(?!~)([^\n~]+?)(?<!~)~(?!~)/g, "~~$1~~");
141
+ return result;
142
+ }
143
+ };
144
+ });
145
+
146
+ // src/integrations/chat-sdk/rocketchat/index.ts
147
+ import { createHash, timingSafeEqual } from "node:crypto";
148
+
149
+ class RocketChatAdapter {
150
+ name = "rocketchat";
151
+ baseUrl;
152
+ token;
153
+ webhookToken;
154
+ logger;
155
+ formatConverter = new RocketChatFormatConverter;
156
+ chat = null;
157
+ _botUserId;
158
+ _userName;
159
+ get userName() {
160
+ return this._userName;
161
+ }
162
+ get botUserId() {
163
+ return this._botUserId;
164
+ }
165
+ constructor(config = {}) {
166
+ const baseUrl = config.baseUrl ?? process.env.ROCKETCHAT_URL;
167
+ if (!baseUrl) {
168
+ throw new ValidationError("rocketchat", "Server URL is required. Set ROCKETCHAT_URL or provide baseUrl in config.");
169
+ }
170
+ const token = config.token ?? process.env.ROCKETCHAT_TOKEN;
171
+ if (!token) {
172
+ throw new ValidationError("rocketchat", "Authentication is required. Set ROCKETCHAT_TOKEN or provide token in config.");
173
+ }
174
+ const botUserId = config.botUserId ?? process.env.ROCKETCHAT_USER_ID;
175
+ if (!botUserId) {
176
+ throw new ValidationError("rocketchat", "Bot user ID is required. Set ROCKETCHAT_USER_ID or provide botUserId in config.");
177
+ }
178
+ const webhookToken = config.webhookToken ?? process.env.ROCKETCHAT_WEBHOOK_TOKEN;
179
+ if (!webhookToken) {
180
+ throw new ValidationError("rocketchat", "Webhook verification is required. Set ROCKETCHAT_WEBHOOK_TOKEN or provide webhookToken in config.");
181
+ }
182
+ this.baseUrl = trimTrailingSlashes(baseUrl);
183
+ this.token = token;
184
+ this._botUserId = botUserId;
185
+ this.webhookToken = webhookToken;
186
+ this._userName = config.userName ?? process.env.ROCKETCHAT_BOT_USERNAME ?? DEFAULT_USER_NAME;
187
+ this.logger = config.logger ?? new ConsoleLogger2("info").child("rocketchat");
188
+ }
189
+ async initialize(chat) {
190
+ this.chat = chat;
191
+ }
192
+ isSelf(userId) {
193
+ return userId === this._botUserId;
194
+ }
195
+ async request(method, path, options = {}) {
196
+ const url = new URL(`${this.baseUrl}/api/v1${path}`);
197
+ for (const [key, value] of Object.entries(options.query ?? {})) {
198
+ if (value !== undefined) {
199
+ url.searchParams.set(key, String(value));
200
+ }
201
+ }
202
+ const headers = {
203
+ "x-auth-token": this.token,
204
+ "x-user-id": this._botUserId,
205
+ accept: "application/json"
206
+ };
207
+ let body;
208
+ if (options.body !== undefined) {
209
+ headers["content-type"] = "application/json";
210
+ body = JSON.stringify(options.body);
211
+ }
212
+ let response;
213
+ try {
214
+ response = await fetch(url, { method, headers, body, redirect: "error" });
215
+ } catch (error) {
216
+ throw new NetworkError("rocketchat", `Rocket.Chat API request failed: ${method} ${path}`, error instanceof Error ? error : undefined);
217
+ }
218
+ if (!response.ok) {
219
+ await this.throwApiError(response, method, path);
220
+ }
221
+ return await response.json();
222
+ }
223
+ async throwApiError(response, method, path) {
224
+ const detail = await response.text().catch(() => "");
225
+ this.logger.debug("Rocket.Chat API error", {
226
+ method,
227
+ path,
228
+ status: response.status,
229
+ detail
230
+ });
231
+ const parsed = parseRocketChatErrorMessage(detail);
232
+ switch (response.status) {
233
+ case 401:
234
+ throw new AuthenticationError3("rocketchat", "Rocket.Chat rejected the credentials. Check that ROCKETCHAT_TOKEN and ROCKETCHAT_USER_ID are valid.");
235
+ case 403:
236
+ throw new PermissionError("rocketchat", `${method} ${path}`, "api");
237
+ case 404:
238
+ throw new ResourceNotFoundError("rocketchat", "resource", path);
239
+ case 429: {
240
+ const retryAfter = Number.parseInt(response.headers.get("retry-after") ?? "", 10);
241
+ throw new AdapterRateLimitError("rocketchat", Number.isNaN(retryAfter) ? undefined : retryAfter);
242
+ }
243
+ case 400:
244
+ throw new ValidationError("rocketchat", parsed ?? `Invalid request: ${method} ${path}`);
245
+ default:
246
+ throw new NetworkError("rocketchat", `Rocket.Chat API error ${response.status}: ${parsed ?? detail}`);
247
+ }
248
+ }
249
+ async handleWebhook(request, options) {
250
+ const body = await request.text();
251
+ let payload;
252
+ try {
253
+ payload = JSON.parse(body);
254
+ } catch {
255
+ this.logger.error("Rocket.Chat webhook invalid JSON");
256
+ return new Response("Invalid JSON", { status: 400 });
257
+ }
258
+ if (typeof payload !== "object" || payload === null) {
259
+ return new Response("ok", { status: 200 });
260
+ }
261
+ if (!this.verifyToken(payload.token)) {
262
+ this.logger.debug("Rocket.Chat webhook token verification failed");
263
+ return new Response("Invalid token", { status: 401 });
264
+ }
265
+ if (!this.chat) {
266
+ this.logger.warn("Chat instance not initialized, ignoring message");
267
+ return new Response("ok", { status: 200 });
268
+ }
269
+ if (payload.bot || this.isSelf(payload.user_id)) {
270
+ this.logger.debug("Ignoring message from self", {
271
+ messageId: payload.message_id
272
+ });
273
+ return new Response("ok", { status: 200 });
274
+ }
275
+ const message = this.buildMessageFromWebhook(payload);
276
+ this.chat.processMessage(this, message.threadId, message, options);
277
+ return new Response("ok", { status: 200 });
278
+ }
279
+ verifyToken(token) {
280
+ if (!token) {
281
+ return false;
282
+ }
283
+ const expected = createHash("sha256").update(this.webhookToken).digest();
284
+ const received = createHash("sha256").update(token).digest();
285
+ return timingSafeEqual(expected, received);
286
+ }
287
+ buildMessageFromWebhook(payload) {
288
+ const message = {
289
+ _id: payload.message_id,
290
+ msg: payload.text,
291
+ rid: payload.channel_id,
292
+ ts: payload.timestamp,
293
+ u: {
294
+ _id: payload.user_id,
295
+ username: payload.user_name
296
+ },
297
+ ...payload.tmid ? { tmid: payload.tmid } : {}
298
+ };
299
+ return this.buildMessage({ message, roomId: payload.channel_id });
300
+ }
301
+ parseMessage(raw) {
302
+ return this.buildMessage(raw);
303
+ }
304
+ buildMessage(raw) {
305
+ const { message } = raw;
306
+ const threadId = this.encodeThreadId({
307
+ roomId: raw.roomId,
308
+ ...message.tmid ? { tmid: message.tmid } : {}
309
+ });
310
+ const { formatted, text } = this.formatConverter.parseIncoming(message.msg);
311
+ return new Message3({
312
+ id: message._id,
313
+ threadId,
314
+ text,
315
+ formatted,
316
+ raw,
317
+ author: this.parseAuthor(message.u),
318
+ isMention: mentionsUser(text, this._userName),
319
+ metadata: {
320
+ dateSent: parseRocketChatDate(message.ts),
321
+ edited: Boolean(message.editedAt),
322
+ ...message.editedAt ? { editedAt: parseRocketChatDate(message.editedAt) } : {}
323
+ },
324
+ attachments: []
325
+ });
326
+ }
327
+ parseAuthor(user) {
328
+ return {
329
+ userId: user._id,
330
+ userName: user.username,
331
+ fullName: user.name || user.username,
332
+ isBot: "unknown",
333
+ isMe: this.isSelf(user._id)
334
+ };
335
+ }
336
+ renderBody(message) {
337
+ const body = this.formatConverter.renderPostable(message);
338
+ return convertRocketChatEmojiPlaceholders(body);
339
+ }
340
+ async postMessage(threadId, message) {
341
+ const thread = this.decodeThreadId(threadId);
342
+ const text = this.renderBody(message);
343
+ const response = await this.request("POST", "/chat.postMessage", {
344
+ body: {
345
+ roomId: thread.roomId,
346
+ text,
347
+ ...thread.tmid ? { tmid: thread.tmid } : {}
348
+ }
349
+ });
350
+ return {
351
+ id: response.message._id,
352
+ threadId,
353
+ raw: { message: response.message, roomId: thread.roomId }
354
+ };
355
+ }
356
+ async editMessage(threadId, messageId, message) {
357
+ const thread = this.decodeThreadId(threadId);
358
+ const response = await this.request("POST", "/chat.update", {
359
+ body: {
360
+ roomId: thread.roomId,
361
+ msgId: messageId,
362
+ text: this.renderBody(message)
363
+ }
364
+ });
365
+ return {
366
+ id: response.message._id,
367
+ threadId,
368
+ raw: { message: response.message, roomId: thread.roomId }
369
+ };
370
+ }
371
+ async deleteMessage(threadId, messageId) {
372
+ const thread = this.decodeThreadId(threadId);
373
+ await this.request("POST", "/chat.delete", {
374
+ body: { roomId: thread.roomId, msgId: messageId }
375
+ });
376
+ }
377
+ async addReaction(_threadId, messageId, emoji) {
378
+ await this.request("POST", "/chat.react", {
379
+ body: {
380
+ messageId,
381
+ emoji: this.toRocketChatEmoji(emoji),
382
+ shouldReact: true
383
+ }
384
+ });
385
+ }
386
+ async removeReaction(_threadId, messageId, emoji) {
387
+ await this.request("POST", "/chat.react", {
388
+ body: {
389
+ messageId,
390
+ emoji: this.toRocketChatEmoji(emoji),
391
+ shouldReact: false
392
+ }
393
+ });
394
+ }
395
+ toRocketChatEmoji(emoji) {
396
+ const name = typeof emoji === "string" ? emoji : emoji.name;
397
+ return defaultEmojiResolver2.toSlack(name);
398
+ }
399
+ async startTyping(_threadId, _status) {}
400
+ async fetchMessages(threadId, options) {
401
+ const thread = this.decodeThreadId(threadId);
402
+ const limit = options?.limit ?? 50;
403
+ const direction = options?.direction ?? "backward";
404
+ if (thread.tmid) {
405
+ const response = await this.request("GET", "/chat.getThreadMessages", {
406
+ query: {
407
+ tmid: thread.tmid,
408
+ count: limit,
409
+ offset: options?.cursor && /^\d+$/.test(options.cursor) ? Number.parseInt(options.cursor, 10) : undefined,
410
+ sort: JSON.stringify({ ts: direction === "backward" ? -1 : 1 })
411
+ }
412
+ });
413
+ const messages = response.messages.map((message) => this.buildMessage({ message, roomId: thread.roomId })).sort((a, b) => a.metadata.dateSent.getTime() - b.metadata.dateSent.getTime());
414
+ const nextOffset = response.offset + response.count;
415
+ return {
416
+ messages,
417
+ nextCursor: nextOffset < response.total ? String(nextOffset) : undefined
418
+ };
419
+ }
420
+ const response = await this.request("GET", "/rooms.history", {
421
+ query: {
422
+ roomId: thread.roomId,
423
+ count: limit,
424
+ ...direction === "backward" ? { previous: options?.cursor } : { next: options?.cursor }
425
+ }
426
+ });
427
+ const messages = [...response.messages].reverse().map((message) => this.buildMessage({ message, roomId: thread.roomId }));
428
+ const nextCursor = direction === "backward" ? response.cursor?.previous ?? undefined : response.cursor?.next ?? undefined;
429
+ return { messages, nextCursor };
430
+ }
431
+ async fetchMessage(threadId, messageId) {
432
+ const thread = this.decodeThreadId(threadId);
433
+ try {
434
+ const response = await this.request("GET", "/chat.getMessage", {
435
+ query: { msgId: messageId }
436
+ });
437
+ return this.buildMessage({
438
+ message: response.message,
439
+ roomId: thread.roomId
440
+ });
441
+ } catch (error) {
442
+ if (error instanceof ResourceNotFoundError) {
443
+ return null;
444
+ }
445
+ throw error;
446
+ }
447
+ }
448
+ async fetchThread(threadId) {
449
+ const thread = this.decodeThreadId(threadId);
450
+ const response = await this.request("GET", "/rooms.info", {
451
+ query: { roomId: thread.roomId }
452
+ });
453
+ const { room } = response;
454
+ return {
455
+ id: threadId,
456
+ channelId: `rocketchat:${thread.roomId}`,
457
+ channelName: room.fname ?? room.name,
458
+ isDM: room.t === "d",
459
+ metadata: { roomId: thread.roomId, type: room.t, topic: room.topic }
460
+ };
461
+ }
462
+ async fetchChannelInfo(channelId) {
463
+ const roomId = this.decodeChannelId(channelId);
464
+ const response = await this.request("GET", "/rooms.info", {
465
+ query: { roomId }
466
+ });
467
+ const { room } = response;
468
+ return {
469
+ id: channelId,
470
+ name: room.fname ?? room.name ?? roomId,
471
+ isDM: room.t === "d",
472
+ metadata: { roomId, type: room.t, topic: room.topic }
473
+ };
474
+ }
475
+ renderFormatted(content) {
476
+ return this.formatConverter.fromAst(content);
477
+ }
478
+ async getUser(userId) {
479
+ try {
480
+ const response = await this.request("GET", "/users.info", {
481
+ query: { userId }
482
+ });
483
+ const { user } = response;
484
+ return {
485
+ fullName: user.name || user.username,
486
+ isBot: user.type === "bot" || user.type === "app",
487
+ userId: user._id,
488
+ userName: user.username,
489
+ ...user.emails?.[0]?.address ? { email: user.emails[0].address } : {}
490
+ };
491
+ } catch (error) {
492
+ this.logger.debug("Failed to fetch user", { userId, error });
493
+ return null;
494
+ }
495
+ }
496
+ encodeThreadId(platformData) {
497
+ const { roomId, tmid } = platformData;
498
+ return tmid ? `rocketchat:${roomId}:${tmid}` : `rocketchat:${roomId}`;
499
+ }
500
+ decodeThreadId(threadId) {
501
+ const match = threadId.match(THREAD_ID_PATTERN);
502
+ const roomId = match?.[1];
503
+ if (!match || !roomId) {
504
+ throw new ValidationError("rocketchat", `Invalid Rocket.Chat thread ID: ${threadId}`);
505
+ }
506
+ return { roomId, ...match[2] ? { tmid: match[2] } : {} };
507
+ }
508
+ channelIdFromThreadId(threadId) {
509
+ return `rocketchat:${this.decodeThreadId(threadId).roomId}`;
510
+ }
511
+ decodeChannelId(channelId) {
512
+ const roomId = channelId.match(CHANNEL_ID_PATTERN)?.[1];
513
+ if (!roomId) {
514
+ throw new ValidationError("rocketchat", `Invalid Rocket.Chat channel ID: ${channelId}`);
515
+ }
516
+ return roomId;
517
+ }
518
+ }
519
+ function parseRocketChatErrorMessage(detail) {
520
+ let parsed;
521
+ try {
522
+ parsed = JSON.parse(detail);
523
+ } catch {
524
+ return;
525
+ }
526
+ if (typeof parsed !== "object" || parsed === null) {
527
+ return;
528
+ }
529
+ const { error } = parsed;
530
+ return typeof error === "string" ? error : undefined;
531
+ }
532
+ function trimTrailingSlashes(url) {
533
+ let end = url.length;
534
+ while (end > 0 && url[end - 1] === "/") {
535
+ end -= 1;
536
+ }
537
+ return url.slice(0, end);
538
+ }
539
+ function parseRocketChatDate(value) {
540
+ return /^\d+$/.test(value) ? new Date(Number.parseInt(value, 10)) : new Date(value);
541
+ }
542
+ function mentionsUser(text, userName) {
543
+ const pattern = new RegExp(`(?<!\\w)@${userName.replace(REGEX_SPECIAL_PATTERN, "\\$&")}(?![\\w-])`, "i");
544
+ return pattern.test(text);
545
+ }
546
+ function convertRocketChatEmojiPlaceholders(text) {
547
+ return text.replace(EMOJI_PLACEHOLDER_REGEX, (_, emojiName) => {
548
+ return `:${defaultEmojiResolver2.toSlack(emojiName)}:`;
549
+ });
550
+ }
551
+ function createRocketChatAdapter(config) {
552
+ return new RocketChatAdapter(config);
553
+ }
554
+ var DEFAULT_USER_NAME = "rocketchat-bot", THREAD_ID_PATTERN, CHANNEL_ID_PATTERN, REGEX_SPECIAL_PATTERN, EMOJI_PLACEHOLDER_REGEX;
555
+ var init_rocketchat = __esm(() => {
556
+ init_dist7();
557
+ init_dist8();
558
+ init_markdown();
559
+ init_markdown();
560
+ THREAD_ID_PATTERN = /^rocketchat:([^:]+)(?::([^:]+))?$/;
561
+ CHANNEL_ID_PATTERN = /^rocketchat:([^:]+)$/;
562
+ REGEX_SPECIAL_PATTERN = /[.*+?^${}()|[\]\\]/g;
563
+ EMOJI_PLACEHOLDER_REGEX = /\{\{emoji:([a-z0-9_]+)\}\}/gi;
564
+ });
565
+ init_rocketchat();
566
+
567
+ export {
568
+ createRocketChatAdapter
569
+ };
@@ -3,7 +3,7 @@ import {
3
3
  resetEmbeddingProvider2,
4
4
  getMemoryStore2,
5
5
  init_memory
6
- } from "./cli-h9bejmkf.js";
6
+ } from "./cli-erh1rgh4.js";
7
7
  init_memory();
8
8
 
9
9
  export {
@@ -4,24 +4,24 @@ import {
4
4
  SKILL_FILE_LIMITS2,
5
5
  normalizeSkillFilePath2,
6
6
  init_db4
7
- } from "./cli-h9bejmkf.js";
7
+ } from "./cli-erh1rgh4.js";
8
8
  import {
9
9
  runSeeder
10
- } from "./cli-04103ryh.js";
11
- import"./cli-cqxwjb93.js";
12
- import"./cli-w6c6dj91.js";
10
+ } from "./cli-1gevjrc1.js";
11
+ import"./cli-ka13xx6b.js";
12
+ import"./cli-e87fg3en.js";
13
13
  import"./cli-vr4eyq6p.js";
14
- import"./cli-4tbvndmm.js";
14
+ import"./cli-r8ddn0hf.js";
15
15
  import"./cli-vx9acp12.js";
16
- import"./cli-t90k0phh.js";
17
- import"./cli-hs3mqswp.js";
18
- import"./cli-zvpkrgsc.js";
19
- import"./cli-qx1dwrr5.js";
20
- import"./cli-8rbkw18r.js";
21
- import"./cli-4h90xaet.js";
16
+ import"./cli-69eq6gdk.js";
17
+ import"./cli-f1sdh8ca.js";
18
+ import"./cli-fcwrd7bh.js";
19
+ import"./cli-n14r8h4n.js";
20
+ import"./cli-8qvte9hn.js";
21
+ import"./cli-m1wddksc.js";
22
22
  import"./cli-y260hgep.js";
23
- import"./cli-0fx95c06.js";
24
- import"./cli-a8ts6x1n.js";
23
+ import"./cli-tceqvv6h.js";
24
+ import"./cli-2wde56gv.js";
25
25
  import {
26
26
  getExecutorRegistry2,
27
27
  init_workflows,
@@ -30,12 +30,12 @@ import {
30
30
  skillSpecOf,
31
31
  skillHash,
32
32
  init_assets
33
- } from "./cli-fn8aj7gb.js";
33
+ } from "./cli-dnvmwsvc.js";
34
34
  import {
35
35
  installImportedSkills,
36
36
  prepareSeeders,
37
37
  init_seeders
38
- } from "./cli-bjmq14k9.js";
38
+ } from "./cli-5k1hvycs.js";
39
39
  import {
40
40
  validateScriptImports,
41
41
  init_import_allowlist,
@@ -47,19 +47,19 @@ import {
47
47
  init_typecheck,
48
48
  parseSkillContent,
49
49
  init_skill_parser
50
- } from "./cli-13t0smbk.js";
51
- import"./cli-7ewre3dm.js";
52
- import"./cli-3zyme1wt.js";
53
- import"./cli-y6qqbpwc.js";
54
- import"./cli-cn6fpa1p.js";
50
+ } from "./cli-nkfv398a.js";
51
+ import"./cli-xerdrnqs.js";
52
+ import"./cli-wdtqkqnq.js";
53
+ import"./cli-j2ybkdk2.js";
54
+ import"./cli-4djg31jh.js";
55
55
  import {
56
56
  validateDefinition,
57
57
  init_definition2
58
- } from "./cli-1dr5at77.js";
59
- import"./cli-84xtgbn6.js";
60
- import"./cli-w41bvvms.js";
61
- import"./cli-c0tyzt73.js";
62
- import"./cli-z6m6xzxt.js";
58
+ } from "./cli-jkkcm72j.js";
59
+ import"./cli-b0m3bg0f.js";
60
+ import"./cli-b0kqw55g.js";
61
+ import"./cli-xysy1g8x.js";
62
+ import"./cli-getrvmtx.js";
63
63
  import {
64
64
  IDENTITY_MD_MAX_CHARS,
65
65
  init_identity_field_budget
@@ -30,7 +30,7 @@ import {
30
30
  NetworkError,
31
31
  cardToFallbackText3,
32
32
  init_dist7
33
- } from "./cli-84xtgbn6.js";
33
+ } from "./cli-b0m3bg0f.js";
34
34
  import {
35
35
  __esm
36
36
  } from "./cli-242037k3.js";
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  listKeepAliveAuthorizations,
3
3
  init_oauth
4
- } from "./cli-h9bejmkf.js";
4
+ } from "./cli-erh1rgh4.js";
5
5
  import {
6
6
  ensureAuthorizationTokenOrThrow,
7
7
  init_ensure_token
8
- } from "./cli-7ewre3dm.js";
9
- import"./cli-c0tyzt73.js";
8
+ } from "./cli-xerdrnqs.js";
9
+ import"./cli-xysy1g8x.js";
10
10
  import {
11
11
  scrubSecrets,
12
12
  init_secret_scrubber
@@ -60,7 +60,7 @@ async function notifySlack(text) {
60
60
  return;
61
61
  }
62
62
  try {
63
- const { getSlackApp } = await import("./app-7m4z44rv.js");
63
+ const { getSlackApp } = await import("./app-535m78qw.js");
64
64
  const app = getSlackApp();
65
65
  if (!app) {
66
66
  console.warn("[OAuth Keepalive] Slack not available, cannot send notification");