@openclaw/mattermost 2026.9.5 → 2026.9.7

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 (380) hide show
  1. package/assets/icon.png +0 -0
  2. package/dist/.setup/{channel-plugin-api-N-mnrhds.mjs → channel-plugin-api-Bc8Qc1-t.mjs} +2 -2
  3. package/dist/.setup/{channel-plugin-api-CKz3b0dp.mjs → channel-plugin-api-DXqHarCt.mjs} +2 -2
  4. package/dist/.setup/{channel-plugin-runtime-Ca4cZHq2.mjs → channel-plugin-runtime-B0CAMiHe.mjs} +146 -176
  5. package/dist/.setup/channel.runtime-E2B5dNrh.mjs +383 -0
  6. package/dist/.setup/{client-Cx71KZ1x.mjs → client-CVeeTqCO.mjs} +55 -46
  7. package/dist/.setup/doctor-contract-BI6SB2cd.mjs +175 -0
  8. package/dist/.setup/{interactions-BG-CQbVD.mjs → interactions-DMSZYnEx.mjs} +170 -80
  9. package/dist/.setup/{channel.runtime-C074p7wv.mjs → monitor-BZyzPkkb.mjs} +237 -726
  10. package/dist/.setup/{monitor-auth-DBoM2Bja.mjs → monitor-auth-aZ0b1gqx.mjs} +11 -16
  11. package/dist/.setup/{normalize-BQzx2u8S.mjs → normalize-BCjtmxtp.mjs} +8 -17
  12. package/dist/.setup/rolldown-runtime-BBjsoOtd.mjs +27 -0
  13. package/dist/.setup/send-ClgX-usq.mjs +438 -0
  14. package/dist/.setup/{slash-state-CmyIYDIc.mjs → slash-state-Dni1XNc1.mjs} +144 -764
  15. package/dist/api.js +2 -2
  16. package/dist/channel-plugin-api.js +2 -2
  17. package/dist/channel-plugin-runtime.js +1 -1
  18. package/dist/doctor-contract-api.js +1 -1
  19. package/dist/policy-api.js +1 -1
  20. package/dist/runtime-api.js +2 -23
  21. package/dist/setup-entry.js +1 -1
  22. package/dist/slash-route-api.js +1 -1
  23. package/node_modules/zod/README.md +2 -2
  24. package/node_modules/zod/compile.cjs +19 -0
  25. package/node_modules/zod/index.cjs +19 -0
  26. package/node_modules/zod/locales/index.cjs +19 -0
  27. package/node_modules/zod/mini/index.cjs +19 -0
  28. package/node_modules/zod/package.json +8 -7
  29. package/node_modules/zod/src/v3/helpers/errorUtil.ts +1 -1
  30. package/node_modules/zod/src/v4/classic/external.ts +2 -0
  31. package/node_modules/zod/src/v4/classic/from-json-schema.ts +248 -25
  32. package/node_modules/zod/src/v4/classic/schemas.ts +243 -168
  33. package/node_modules/zod/src/v4/classic/tests/assignability.test.ts +60 -9
  34. package/node_modules/zod/src/v4/classic/tests/bigint.test.ts +6 -0
  35. package/node_modules/zod/src/v4/classic/tests/continuability.test.ts +2 -2
  36. package/node_modules/zod/src/v4/classic/tests/cyclic-data.test.ts +265 -0
  37. package/node_modules/zod/src/v4/classic/tests/discriminated-unions.test.ts +112 -6
  38. package/node_modules/zod/src/v4/classic/tests/enum.test.ts +9 -0
  39. package/node_modules/zod/src/v4/classic/tests/error.test.ts +130 -1
  40. package/node_modules/zod/src/v4/classic/tests/from-json-schema.test.ts +157 -0
  41. package/node_modules/zod/src/v4/classic/tests/iban.test.ts +81 -0
  42. package/node_modules/zod/src/v4/classic/tests/instance-footprint.test.ts +40 -2
  43. package/node_modules/zod/src/v4/classic/tests/instanceof.test.ts +27 -7
  44. package/node_modules/zod/src/v4/classic/tests/issue-schema.test.ts +88 -56
  45. package/node_modules/zod/src/v4/classic/tests/number.test.ts +39 -0
  46. package/node_modules/zod/src/v4/classic/tests/object.test.ts +56 -0
  47. package/node_modules/zod/src/v4/classic/tests/optin-ladder.test.ts +3 -2
  48. package/node_modules/zod/src/v4/classic/tests/prefault.test.ts +70 -0
  49. package/node_modules/zod/src/v4/classic/tests/properties.test.ts +141 -0
  50. package/node_modules/zod/src/v4/classic/tests/recursive-types.test.ts +46 -1
  51. package/node_modules/zod/src/v4/classic/tests/standard-schema.test.ts +19 -0
  52. package/node_modules/zod/src/v4/classic/tests/string.test.ts +95 -1
  53. package/node_modules/zod/src/v4/classic/tests/template-literal.test.ts +33 -1
  54. package/node_modules/zod/src/v4/classic/tests/to-json-schema.test.ts +234 -38
  55. package/node_modules/zod/src/v4/classic/tests/validate.test.ts +569 -0
  56. package/node_modules/zod/src/v4/core/api.ts +44 -28
  57. package/node_modules/zod/src/v4/core/checks.ts +62 -102
  58. package/node_modules/zod/src/v4/core/compile.ts +218 -93
  59. package/node_modules/zod/src/v4/core/core.ts +1 -3
  60. package/node_modules/zod/src/v4/core/doc.ts +6 -2
  61. package/node_modules/zod/src/v4/core/errors.ts +3 -6
  62. package/node_modules/zod/src/v4/core/json-schema-generator.ts +2 -2
  63. package/node_modules/zod/src/v4/core/json-schema-processors.ts +185 -81
  64. package/node_modules/zod/src/v4/core/memoizer.ts +75 -28
  65. package/node_modules/zod/src/v4/core/parse.ts +37 -16
  66. package/node_modules/zod/src/v4/core/regexes.ts +14 -4
  67. package/node_modules/zod/src/v4/core/schemas.ts +296 -132
  68. package/node_modules/zod/src/v4/core/tests/cached.test.ts +54 -0
  69. package/node_modules/zod/src/v4/core/tests/compile-differential.test.ts +35 -0
  70. package/node_modules/zod/src/v4/core/tests/compile-generative.test.ts +445 -0
  71. package/node_modules/zod/src/v4/core/tests/compile.test.ts +399 -2
  72. package/node_modules/zod/src/v4/core/tests/email-regex.test.ts +140 -0
  73. package/node_modules/zod/src/v4/core/tests/locales/tg.test.ts +85 -0
  74. package/node_modules/zod/src/v4/core/tests/polyfill-collision.test.ts +46 -0
  75. package/node_modules/zod/src/v4/core/tests/url-no-canparse.test.ts +118 -16
  76. package/node_modules/zod/src/v4/core/to-json-schema.ts +9 -7
  77. package/node_modules/zod/src/v4/core/util.ts +218 -147
  78. package/node_modules/zod/src/v4/core/versions.ts +2 -2
  79. package/node_modules/zod/src/v4/locales/ar.ts +2 -0
  80. package/node_modules/zod/src/v4/locales/az.ts +2 -0
  81. package/node_modules/zod/src/v4/locales/be.ts +2 -0
  82. package/node_modules/zod/src/v4/locales/bg.ts +2 -0
  83. package/node_modules/zod/src/v4/locales/bn.ts +2 -0
  84. package/node_modules/zod/src/v4/locales/ca.ts +2 -0
  85. package/node_modules/zod/src/v4/locales/ckb.ts +2 -0
  86. package/node_modules/zod/src/v4/locales/cs.ts +2 -0
  87. package/node_modules/zod/src/v4/locales/da.ts +2 -0
  88. package/node_modules/zod/src/v4/locales/de.ts +2 -0
  89. package/node_modules/zod/src/v4/locales/el.ts +2 -0
  90. package/node_modules/zod/src/v4/locales/en.ts +2 -0
  91. package/node_modules/zod/src/v4/locales/eo.ts +2 -0
  92. package/node_modules/zod/src/v4/locales/es.ts +2 -0
  93. package/node_modules/zod/src/v4/locales/fa.ts +2 -0
  94. package/node_modules/zod/src/v4/locales/fi.ts +2 -0
  95. package/node_modules/zod/src/v4/locales/fr-CA.ts +2 -0
  96. package/node_modules/zod/src/v4/locales/fr.ts +2 -0
  97. package/node_modules/zod/src/v4/locales/gu.ts +2 -0
  98. package/node_modules/zod/src/v4/locales/he.ts +2 -0
  99. package/node_modules/zod/src/v4/locales/hi.ts +2 -0
  100. package/node_modules/zod/src/v4/locales/hr.ts +2 -0
  101. package/node_modules/zod/src/v4/locales/hu.ts +2 -0
  102. package/node_modules/zod/src/v4/locales/hy.ts +2 -0
  103. package/node_modules/zod/src/v4/locales/id.ts +2 -0
  104. package/node_modules/zod/src/v4/locales/index.ts +1 -0
  105. package/node_modules/zod/src/v4/locales/is.ts +2 -0
  106. package/node_modules/zod/src/v4/locales/it.ts +2 -0
  107. package/node_modules/zod/src/v4/locales/ja.ts +2 -0
  108. package/node_modules/zod/src/v4/locales/ka.ts +2 -0
  109. package/node_modules/zod/src/v4/locales/km.ts +2 -0
  110. package/node_modules/zod/src/v4/locales/kn.ts +2 -0
  111. package/node_modules/zod/src/v4/locales/ko.ts +2 -0
  112. package/node_modules/zod/src/v4/locales/lt.ts +2 -0
  113. package/node_modules/zod/src/v4/locales/mk.ts +2 -0
  114. package/node_modules/zod/src/v4/locales/ms.ts +2 -0
  115. package/node_modules/zod/src/v4/locales/ne.ts +2 -0
  116. package/node_modules/zod/src/v4/locales/nl.ts +2 -0
  117. package/node_modules/zod/src/v4/locales/nn.ts +2 -0
  118. package/node_modules/zod/src/v4/locales/no.ts +2 -0
  119. package/node_modules/zod/src/v4/locales/ota.ts +2 -0
  120. package/node_modules/zod/src/v4/locales/pl.ts +2 -0
  121. package/node_modules/zod/src/v4/locales/ps.ts +2 -0
  122. package/node_modules/zod/src/v4/locales/pt-BR.ts +2 -0
  123. package/node_modules/zod/src/v4/locales/pt.ts +2 -0
  124. package/node_modules/zod/src/v4/locales/ro.ts +2 -0
  125. package/node_modules/zod/src/v4/locales/ru.ts +2 -0
  126. package/node_modules/zod/src/v4/locales/sk.ts +2 -0
  127. package/node_modules/zod/src/v4/locales/sl.ts +2 -0
  128. package/node_modules/zod/src/v4/locales/sv.ts +2 -0
  129. package/node_modules/zod/src/v4/locales/ta.ts +2 -0
  130. package/node_modules/zod/src/v4/locales/tg.ts +135 -0
  131. package/node_modules/zod/src/v4/locales/th.ts +2 -0
  132. package/node_modules/zod/src/v4/locales/tk.ts +2 -0
  133. package/node_modules/zod/src/v4/locales/tr.ts +2 -0
  134. package/node_modules/zod/src/v4/locales/uk.ts +2 -0
  135. package/node_modules/zod/src/v4/locales/ur.ts +2 -0
  136. package/node_modules/zod/src/v4/locales/uz.ts +2 -0
  137. package/node_modules/zod/src/v4/locales/vi.ts +2 -0
  138. package/node_modules/zod/src/v4/locales/yo.ts +2 -0
  139. package/node_modules/zod/src/v4/locales/zh-CN.ts +2 -0
  140. package/node_modules/zod/src/v4/locales/zh-TW.ts +2 -0
  141. package/node_modules/zod/src/v4/mini/external.ts +2 -0
  142. package/node_modules/zod/src/v4/mini/schemas.ts +32 -7
  143. package/node_modules/zod/src/v4/mini/tests/checks.test.ts +1 -1
  144. package/node_modules/zod/src/v4/mini/tests/computed.test.ts +11 -17
  145. package/node_modules/zod/src/v4/mini/tests/index.test.ts +86 -0
  146. package/node_modules/zod/src/v4/mini/tests/recursive-types.test.ts +16 -0
  147. package/node_modules/zod/src/v4/mini/tests/string.test.ts +23 -0
  148. package/node_modules/zod/v3/ZodError.cjs +19 -0
  149. package/node_modules/zod/v3/errors.cjs +19 -0
  150. package/node_modules/zod/v3/external.cjs +19 -0
  151. package/node_modules/zod/v3/helpers/enumUtil.cjs +19 -0
  152. package/node_modules/zod/v3/helpers/errorUtil.cjs +20 -1
  153. package/node_modules/zod/v3/helpers/errorUtil.js +1 -1
  154. package/node_modules/zod/v3/helpers/parseUtil.cjs +19 -0
  155. package/node_modules/zod/v3/helpers/partialUtil.cjs +19 -0
  156. package/node_modules/zod/v3/helpers/typeAliases.cjs +19 -0
  157. package/node_modules/zod/v3/helpers/util.cjs +19 -0
  158. package/node_modules/zod/v3/index.cjs +19 -0
  159. package/node_modules/zod/v3/standard-schema.cjs +19 -0
  160. package/node_modules/zod/v3/types.cjs +19 -0
  161. package/node_modules/zod/v4/classic/checks.cjs +19 -0
  162. package/node_modules/zod/v4/classic/coerce.cjs +19 -0
  163. package/node_modules/zod/v4/classic/compat.cjs +19 -0
  164. package/node_modules/zod/v4/classic/deep-partial.cjs +19 -0
  165. package/node_modules/zod/v4/classic/errors.cjs +19 -0
  166. package/node_modules/zod/v4/classic/external.cjs +22 -1
  167. package/node_modules/zod/v4/classic/external.d.cts +1 -1
  168. package/node_modules/zod/v4/classic/external.d.ts +1 -1
  169. package/node_modules/zod/v4/classic/external.js +1 -1
  170. package/node_modules/zod/v4/classic/from-json-schema.cjs +264 -24
  171. package/node_modules/zod/v4/classic/from-json-schema.js +245 -24
  172. package/node_modules/zod/v4/classic/in-out.cjs +19 -0
  173. package/node_modules/zod/v4/classic/index.cjs +19 -0
  174. package/node_modules/zod/v4/classic/iso.cjs +19 -0
  175. package/node_modules/zod/v4/classic/parse.cjs +19 -0
  176. package/node_modules/zod/v4/classic/schemas.cjs +100 -35
  177. package/node_modules/zod/v4/classic/schemas.d.cts +15 -1
  178. package/node_modules/zod/v4/classic/schemas.d.ts +15 -1
  179. package/node_modules/zod/v4/classic/schemas.js +77 -33
  180. package/node_modules/zod/v4/core/api.cjs +45 -22
  181. package/node_modules/zod/v4/core/api.d.cts +12 -6
  182. package/node_modules/zod/v4/core/api.d.ts +12 -6
  183. package/node_modules/zod/v4/core/api.js +25 -22
  184. package/node_modules/zod/v4/core/checks.cjs +51 -97
  185. package/node_modules/zod/v4/core/checks.d.cts +17 -1
  186. package/node_modules/zod/v4/core/checks.d.ts +17 -1
  187. package/node_modules/zod/v4/core/checks.js +31 -96
  188. package/node_modules/zod/v4/core/compile.cjs +173 -78
  189. package/node_modules/zod/v4/core/compile.d.cts +18 -4
  190. package/node_modules/zod/v4/core/compile.d.ts +18 -4
  191. package/node_modules/zod/v4/core/compile.js +154 -79
  192. package/node_modules/zod/v4/core/core.cjs +20 -1
  193. package/node_modules/zod/v4/core/core.js +1 -1
  194. package/node_modules/zod/v4/core/doc.cjs +26 -2
  195. package/node_modules/zod/v4/core/doc.js +7 -2
  196. package/node_modules/zod/v4/core/errors.cjs +21 -5
  197. package/node_modules/zod/v4/core/errors.js +2 -5
  198. package/node_modules/zod/v4/core/index.cjs +19 -0
  199. package/node_modules/zod/v4/core/json-schema-generator.cjs +20 -1
  200. package/node_modules/zod/v4/core/json-schema-generator.js +2 -2
  201. package/node_modules/zod/v4/core/json-schema-processors.cjs +188 -72
  202. package/node_modules/zod/v4/core/json-schema-processors.d.cts +16 -0
  203. package/node_modules/zod/v4/core/json-schema-processors.d.ts +16 -0
  204. package/node_modules/zod/v4/core/json-schema-processors.js +170 -74
  205. package/node_modules/zod/v4/core/json-schema.cjs +19 -0
  206. package/node_modules/zod/v4/core/memoizer.cjs +111 -23
  207. package/node_modules/zod/v4/core/memoizer.js +69 -23
  208. package/node_modules/zod/v4/core/parse.cjs +56 -16
  209. package/node_modules/zod/v4/core/parse.js +37 -16
  210. package/node_modules/zod/v4/core/regexes.cjs +31 -6
  211. package/node_modules/zod/v4/core/regexes.d.cts +3 -0
  212. package/node_modules/zod/v4/core/regexes.d.ts +3 -0
  213. package/node_modules/zod/v4/core/regexes.js +10 -4
  214. package/node_modules/zod/v4/core/registries.cjs +19 -0
  215. package/node_modules/zod/v4/core/schemas.cjs +302 -114
  216. package/node_modules/zod/v4/core/schemas.d.cts +28 -8
  217. package/node_modules/zod/v4/core/schemas.d.ts +28 -8
  218. package/node_modules/zod/v4/core/schemas.js +279 -113
  219. package/node_modules/zod/v4/core/standard-schema.cjs +19 -0
  220. package/node_modules/zod/v4/core/to-json-schema.cjs +28 -7
  221. package/node_modules/zod/v4/core/to-json-schema.d.cts +4 -3
  222. package/node_modules/zod/v4/core/to-json-schema.d.ts +4 -3
  223. package/node_modules/zod/v4/core/to-json-schema.js +7 -6
  224. package/node_modules/zod/v4/core/util.cjs +177 -143
  225. package/node_modules/zod/v4/core/util.d.cts +25 -4
  226. package/node_modules/zod/v4/core/util.d.ts +25 -4
  227. package/node_modules/zod/v4/core/util.js +156 -143
  228. package/node_modules/zod/v4/core/versions.cjs +21 -2
  229. package/node_modules/zod/v4/core/versions.d.cts +1 -1
  230. package/node_modules/zod/v4/core/versions.d.ts +1 -1
  231. package/node_modules/zod/v4/core/versions.js +2 -2
  232. package/node_modules/zod/v4/core/visit.cjs +19 -0
  233. package/node_modules/zod/v4/index.cjs +19 -0
  234. package/node_modules/zod/v4/locales/ar.cjs +2 -0
  235. package/node_modules/zod/v4/locales/ar.js +2 -0
  236. package/node_modules/zod/v4/locales/az.cjs +2 -0
  237. package/node_modules/zod/v4/locales/az.js +2 -0
  238. package/node_modules/zod/v4/locales/be.cjs +2 -0
  239. package/node_modules/zod/v4/locales/be.js +2 -0
  240. package/node_modules/zod/v4/locales/bg.cjs +2 -0
  241. package/node_modules/zod/v4/locales/bg.js +2 -0
  242. package/node_modules/zod/v4/locales/bn.cjs +2 -0
  243. package/node_modules/zod/v4/locales/bn.js +2 -0
  244. package/node_modules/zod/v4/locales/ca.cjs +2 -0
  245. package/node_modules/zod/v4/locales/ca.js +2 -0
  246. package/node_modules/zod/v4/locales/ckb.cjs +2 -0
  247. package/node_modules/zod/v4/locales/ckb.js +2 -0
  248. package/node_modules/zod/v4/locales/cs.cjs +2 -0
  249. package/node_modules/zod/v4/locales/cs.js +2 -0
  250. package/node_modules/zod/v4/locales/da.cjs +2 -0
  251. package/node_modules/zod/v4/locales/da.js +2 -0
  252. package/node_modules/zod/v4/locales/de.cjs +2 -0
  253. package/node_modules/zod/v4/locales/de.js +2 -0
  254. package/node_modules/zod/v4/locales/el.cjs +2 -0
  255. package/node_modules/zod/v4/locales/el.js +2 -0
  256. package/node_modules/zod/v4/locales/en.cjs +2 -0
  257. package/node_modules/zod/v4/locales/en.js +2 -0
  258. package/node_modules/zod/v4/locales/eo.cjs +2 -0
  259. package/node_modules/zod/v4/locales/eo.js +2 -0
  260. package/node_modules/zod/v4/locales/es.cjs +2 -0
  261. package/node_modules/zod/v4/locales/es.js +2 -0
  262. package/node_modules/zod/v4/locales/fa.cjs +2 -0
  263. package/node_modules/zod/v4/locales/fa.js +2 -0
  264. package/node_modules/zod/v4/locales/fi.cjs +2 -0
  265. package/node_modules/zod/v4/locales/fi.js +2 -0
  266. package/node_modules/zod/v4/locales/fr-CA.cjs +2 -0
  267. package/node_modules/zod/v4/locales/fr-CA.js +2 -0
  268. package/node_modules/zod/v4/locales/fr.cjs +2 -0
  269. package/node_modules/zod/v4/locales/fr.js +2 -0
  270. package/node_modules/zod/v4/locales/gu.cjs +2 -0
  271. package/node_modules/zod/v4/locales/gu.js +2 -0
  272. package/node_modules/zod/v4/locales/he.cjs +2 -0
  273. package/node_modules/zod/v4/locales/he.js +2 -0
  274. package/node_modules/zod/v4/locales/hi.cjs +2 -0
  275. package/node_modules/zod/v4/locales/hi.js +2 -0
  276. package/node_modules/zod/v4/locales/hr.cjs +2 -0
  277. package/node_modules/zod/v4/locales/hr.js +2 -0
  278. package/node_modules/zod/v4/locales/hu.cjs +2 -0
  279. package/node_modules/zod/v4/locales/hu.js +2 -0
  280. package/node_modules/zod/v4/locales/hy.cjs +2 -0
  281. package/node_modules/zod/v4/locales/hy.js +2 -0
  282. package/node_modules/zod/v4/locales/id.cjs +2 -0
  283. package/node_modules/zod/v4/locales/id.js +2 -0
  284. package/node_modules/zod/v4/locales/index.cjs +22 -1
  285. package/node_modules/zod/v4/locales/index.d.cts +1 -0
  286. package/node_modules/zod/v4/locales/index.d.ts +1 -0
  287. package/node_modules/zod/v4/locales/index.js +1 -0
  288. package/node_modules/zod/v4/locales/is.cjs +2 -0
  289. package/node_modules/zod/v4/locales/is.js +2 -0
  290. package/node_modules/zod/v4/locales/it.cjs +2 -0
  291. package/node_modules/zod/v4/locales/it.js +2 -0
  292. package/node_modules/zod/v4/locales/ja.cjs +2 -0
  293. package/node_modules/zod/v4/locales/ja.js +2 -0
  294. package/node_modules/zod/v4/locales/ka.cjs +2 -0
  295. package/node_modules/zod/v4/locales/ka.js +2 -0
  296. package/node_modules/zod/v4/locales/km.cjs +2 -0
  297. package/node_modules/zod/v4/locales/km.js +2 -0
  298. package/node_modules/zod/v4/locales/kn.cjs +2 -0
  299. package/node_modules/zod/v4/locales/kn.js +2 -0
  300. package/node_modules/zod/v4/locales/ko.cjs +2 -0
  301. package/node_modules/zod/v4/locales/ko.js +2 -0
  302. package/node_modules/zod/v4/locales/lt.cjs +2 -0
  303. package/node_modules/zod/v4/locales/lt.js +2 -0
  304. package/node_modules/zod/v4/locales/mk.cjs +2 -0
  305. package/node_modules/zod/v4/locales/mk.js +2 -0
  306. package/node_modules/zod/v4/locales/ms.cjs +2 -0
  307. package/node_modules/zod/v4/locales/ms.js +2 -0
  308. package/node_modules/zod/v4/locales/ne.cjs +2 -0
  309. package/node_modules/zod/v4/locales/ne.js +2 -0
  310. package/node_modules/zod/v4/locales/nl.cjs +2 -0
  311. package/node_modules/zod/v4/locales/nl.js +2 -0
  312. package/node_modules/zod/v4/locales/nn.cjs +2 -0
  313. package/node_modules/zod/v4/locales/nn.js +2 -0
  314. package/node_modules/zod/v4/locales/no.cjs +2 -0
  315. package/node_modules/zod/v4/locales/no.js +2 -0
  316. package/node_modules/zod/v4/locales/ota.cjs +2 -0
  317. package/node_modules/zod/v4/locales/ota.js +2 -0
  318. package/node_modules/zod/v4/locales/pl.cjs +2 -0
  319. package/node_modules/zod/v4/locales/pl.js +2 -0
  320. package/node_modules/zod/v4/locales/ps.cjs +2 -0
  321. package/node_modules/zod/v4/locales/ps.js +2 -0
  322. package/node_modules/zod/v4/locales/pt-BR.cjs +2 -0
  323. package/node_modules/zod/v4/locales/pt-BR.js +2 -0
  324. package/node_modules/zod/v4/locales/pt.cjs +2 -0
  325. package/node_modules/zod/v4/locales/pt.js +2 -0
  326. package/node_modules/zod/v4/locales/ro.cjs +2 -0
  327. package/node_modules/zod/v4/locales/ro.js +2 -0
  328. package/node_modules/zod/v4/locales/ru.cjs +2 -0
  329. package/node_modules/zod/v4/locales/ru.js +2 -0
  330. package/node_modules/zod/v4/locales/sk.cjs +2 -0
  331. package/node_modules/zod/v4/locales/sk.js +2 -0
  332. package/node_modules/zod/v4/locales/sl.cjs +2 -0
  333. package/node_modules/zod/v4/locales/sl.js +2 -0
  334. package/node_modules/zod/v4/locales/sv.cjs +2 -0
  335. package/node_modules/zod/v4/locales/sv.js +2 -0
  336. package/node_modules/zod/v4/locales/ta.cjs +2 -0
  337. package/node_modules/zod/v4/locales/ta.js +2 -0
  338. package/node_modules/zod/v4/locales/tg.cjs +144 -0
  339. package/node_modules/zod/v4/locales/tg.d.cts +5 -0
  340. package/node_modules/zod/v4/locales/tg.d.ts +4 -0
  341. package/node_modules/zod/v4/locales/tg.js +117 -0
  342. package/node_modules/zod/v4/locales/th.cjs +2 -0
  343. package/node_modules/zod/v4/locales/th.js +2 -0
  344. package/node_modules/zod/v4/locales/tk.cjs +2 -0
  345. package/node_modules/zod/v4/locales/tk.js +2 -0
  346. package/node_modules/zod/v4/locales/tr.cjs +2 -0
  347. package/node_modules/zod/v4/locales/tr.js +2 -0
  348. package/node_modules/zod/v4/locales/uk.cjs +2 -0
  349. package/node_modules/zod/v4/locales/uk.js +2 -0
  350. package/node_modules/zod/v4/locales/ur.cjs +2 -0
  351. package/node_modules/zod/v4/locales/ur.js +2 -0
  352. package/node_modules/zod/v4/locales/uz.cjs +2 -0
  353. package/node_modules/zod/v4/locales/uz.js +2 -0
  354. package/node_modules/zod/v4/locales/vi.cjs +2 -0
  355. package/node_modules/zod/v4/locales/vi.js +2 -0
  356. package/node_modules/zod/v4/locales/yo.cjs +2 -0
  357. package/node_modules/zod/v4/locales/yo.js +2 -0
  358. package/node_modules/zod/v4/locales/zh-CN.cjs +2 -0
  359. package/node_modules/zod/v4/locales/zh-CN.js +2 -0
  360. package/node_modules/zod/v4/locales/zh-TW.cjs +2 -0
  361. package/node_modules/zod/v4/locales/zh-TW.js +2 -0
  362. package/node_modules/zod/v4/mini/checks.cjs +19 -0
  363. package/node_modules/zod/v4/mini/coerce.cjs +19 -0
  364. package/node_modules/zod/v4/mini/deep-partial.cjs +19 -0
  365. package/node_modules/zod/v4/mini/external.cjs +22 -1
  366. package/node_modules/zod/v4/mini/external.d.cts +1 -1
  367. package/node_modules/zod/v4/mini/external.d.ts +1 -1
  368. package/node_modules/zod/v4/mini/external.js +1 -1
  369. package/node_modules/zod/v4/mini/in-out.cjs +19 -0
  370. package/node_modules/zod/v4/mini/index.cjs +19 -0
  371. package/node_modules/zod/v4/mini/iso.cjs +19 -0
  372. package/node_modules/zod/v4/mini/parse.cjs +19 -0
  373. package/node_modules/zod/v4/mini/schemas.cjs +44 -8
  374. package/node_modules/zod/v4/mini/schemas.d.cts +6 -1
  375. package/node_modules/zod/v4/mini/schemas.d.ts +6 -1
  376. package/node_modules/zod/v4/mini/schemas.js +21 -6
  377. package/node_modules/zod/v4-mini/index.cjs +19 -0
  378. package/openclaw.plugin.json +20 -0
  379. package/package.json +5 -5
  380. package/dist/.setup/doctor-contract-mvORF4f6.mjs +0 -18
@@ -1,29 +1,24 @@
1
+ import { l as isWildcardBindHost } from "./interactions-DMSZYnEx.mjs";
1
2
  import { t as getMattermostRuntime } from "./runtime-CNB4YGqJ.mjs";
2
- import { c as setInteractionSecret, l as isWildcardBindHost, n as buildButtonProps, o as resolveInteractionCallbackUrl } from "./interactions-BG-CQbVD.mjs";
3
- import { a as createMattermostPost, b as uploadMattermostFile, c as fetchMattermostChannelByName, d as fetchMattermostUser, f as fetchMattermostUserByUsername, g as parseMattermostApiStatus, h as normalizeMattermostBaseUrl, i as createMattermostDirectChannelWithRetry, p as fetchMattermostUserTeams, r as createMattermostClient, s as fetchMattermostChannel, u as fetchMattermostMe, v as sendMattermostTyping } from "./client-Cx71KZ1x.mjs";
4
- import { D as sendHttpRequestRejection, b as logTypingFailure, h as isRequestBodyLimitError, i as normalizeMattermostAllowList, l as buildPreparedModelsProviderData, o as resolveMattermostTrustedChatKind, p as createWebhookInFlightLimiter, t as authorizeMattermostCommandInvocation, v as loadOutboundMediaFromUrl, x as readRequestBodyWithLimit } from "./monitor-auth-DBoM2Bja.mjs";
5
- import { a as resolveMattermostPresentation, i as requiresMattermostMediaUpload, u as resolveMattermostAccount } from "./normalize-BQzx2u8S.mjs";
3
+ import { r as createMattermostClient, s as fetchMattermostChannel, v as sendMattermostTyping } from "./client-CVeeTqCO.mjs";
4
+ import { D as sendHttpRequestRejection, b as logTypingFailure, h as isRequestBodyLimitError, i as normalizeMattermostAllowList, l as buildPreparedModelsProviderData, p as createWebhookInFlightLimiter, t as authorizeMattermostCommandInvocation, x as readRequestBodyWithLimit } from "./monitor-auth-aZ0b1gqx.mjs";
5
+ import { a as resolveMattermostPresentation, i as requiresMattermostMediaUpload } from "./normalize-BCjtmxtp.mjs";
6
+ import { t as sendMessageMattermost } from "./send-ClgX-usq.mjs";
6
7
  import { createHash } from "node:crypto";
7
8
  import { safeEqualSecret } from "openclaw/plugin-sdk/security-runtime";
8
- import { asFiniteNumber, normalizeLowercaseStringOrEmpty, normalizeOptionalString, normalizeStringifiedOptionalString, readStringField } from "openclaw/plugin-sdk/string-coerce-runtime";
9
+ import { asFiniteNumber, normalizeOptionalString, normalizeStringifiedOptionalString, readStringField } from "openclaw/plugin-sdk/string-coerce-runtime";
9
10
  import { createAcceptedChannelDeliveryResult, createChannelPartialDeliveryError, isChannelPartialDeliveryError } from "openclaw/plugin-sdk/channel-inbound";
10
11
  import { asDateTimestampMs, parseStrictInteger, resolveExpiresAtMsFromDurationMs } from "openclaw/plugin-sdk/number-runtime";
11
12
  import { isPrivateNetworkOptInEnabled } from "openclaw/plugin-sdk/ssrf-runtime";
12
- import { createMessageReceiptFromOutboundResults, listMessageReceiptPlatformIds } from "openclaw/plugin-sdk/channel-outbound";
13
13
  import { resolveStoredModelOverride } from "openclaw/plugin-sdk/command-auth-native";
14
- import { resolveChannelMediaMaxBytes } from "openclaw/plugin-sdk/account-helpers";
15
14
  import { deliverTextOrMediaReply, isReasoningReplyPayload, resolveSendableOutboundReplyParts } from "openclaw/plugin-sdk/reply-payload";
16
- import { FormatCapabilityProfile, convertMarkdownTables } from "openclaw/plugin-sdk/text-chunking";
17
- import { getSessionEntry, resolveStorePath } from "openclaw/plugin-sdk/session-store-runtime";
18
- import { getAgentScopedMediaLocalRoots } from "openclaw/plugin-sdk/media-runtime";
19
- import { normalizeProviderId } from "openclaw/plugin-sdk/provider-model-shared";
20
15
  import { truncateUtf16Safe, truncateUtf8Prefix } from "openclaw/plugin-sdk/text-utility-runtime";
21
16
  import { resolveHumanDelayConfig } from "openclaw/plugin-sdk/agent-runtime";
22
- import { finalizeInboundContext } from "openclaw/plugin-sdk/reply-runtime";
23
17
  import { pruneMapToMaxSize } from "openclaw/plugin-sdk/collection-runtime";
24
- import { resolveMarkdownTableMode } from "openclaw/plugin-sdk/markdown-table-runtime";
25
- import { extensionForMime } from "openclaw/plugin-sdk/media-mime";
26
- import { requireRuntimeConfig } from "openclaw/plugin-sdk/plugin-config-runtime";
18
+ import { finalizeInboundContext } from "openclaw/plugin-sdk/reply-runtime";
19
+ import { getSessionEntry, resolveStorePath } from "openclaw/plugin-sdk/session-store-runtime";
20
+ import { normalizeProviderId } from "openclaw/plugin-sdk/provider-model-shared";
21
+ import { getAgentScopedMediaLocalRoots } from "openclaw/plugin-sdk/media-runtime";
27
22
  const MATTERMOST_COMMAND_DESCRIPTION_MAX_BYTES = 128;
28
23
  /**
29
24
  * Built-in OpenClaw commands to register as native slash commands.
@@ -31,107 +26,64 @@ const MATTERMOST_COMMAND_DESCRIPTION_MAX_BYTES = 128;
31
26
  */
32
27
  const DEFAULT_COMMAND_SPECS = [
33
28
  {
34
- trigger: "oc_status",
35
29
  originalName: "status",
36
- description: "Show session status (model, usage, uptime)",
37
- autoComplete: true
30
+ description: "Show session status (model, usage, uptime)"
38
31
  },
39
32
  {
40
- trigger: "oc_model",
41
33
  originalName: "model",
42
34
  description: "View or change the current model",
43
- autoComplete: true,
44
35
  autoCompleteHint: "[model-name] [--runtime runtime]"
45
36
  },
46
37
  {
47
- trigger: "oc_models",
48
38
  originalName: "models",
49
39
  description: "Browse available models",
50
- autoComplete: true,
51
40
  autoCompleteHint: "[provider]"
52
41
  },
53
42
  {
54
- trigger: "oc_new",
55
43
  originalName: "new",
56
- description: "Start a new conversation session",
57
- autoComplete: true
44
+ description: "Start a new conversation session"
58
45
  },
59
46
  {
60
- trigger: "oc_help",
61
47
  originalName: "help",
62
- description: "Show available commands",
63
- autoComplete: true
48
+ description: "Show available commands"
64
49
  },
65
50
  {
66
- trigger: "oc_think",
67
51
  originalName: "think",
68
52
  description: "Set thinking/reasoning level",
69
- autoComplete: true,
70
53
  autoCompleteHint: "[off|low|medium|high]"
71
54
  },
72
55
  {
73
- trigger: "oc_reasoning",
74
56
  originalName: "reasoning",
75
57
  description: "Toggle reasoning mode",
76
- autoComplete: true,
77
58
  autoCompleteHint: "[on|off]"
78
59
  },
79
60
  {
80
- trigger: "oc_verbose",
81
61
  originalName: "verbose",
82
62
  description: "Toggle verbose mode",
83
- autoComplete: true,
84
63
  autoCompleteHint: "[on|off]"
85
64
  },
86
65
  {
87
- trigger: "oc_queue",
88
66
  originalName: "queue",
89
67
  description: "Adjust active-run queue behavior",
90
- autoComplete: true,
91
68
  autoCompleteHint: "[steer|followup|collect|interrupt] [debounce:2s] [cap:N] [drop:old|new|summarize]"
92
69
  }
93
- ];
94
- /**
95
- * List existing custom slash commands for a team.
96
- */
70
+ ].map((spec) => Object.assign(spec, {
71
+ trigger: `oc_${spec.originalName}`,
72
+ autoComplete: true
73
+ }));
97
74
  async function listMattermostCommands(client, teamId, init) {
98
75
  return await client.request(`/commands?team_id=${encodeURIComponent(teamId)}&custom_only=true`, init);
99
76
  }
100
- /**
101
- * Get a custom slash command by id.
102
- */
103
77
  async function getMattermostCommand(client, commandId, init) {
104
78
  return await client.request(`/commands/${encodeURIComponent(commandId)}`, init);
105
79
  }
106
- /**
107
- * Create a custom slash command on a Mattermost team.
108
- */
109
- async function createMattermostCommand(client, params) {
110
- return await client.request("/commands", {
111
- method: "POST",
112
- body: JSON.stringify(params)
113
- });
114
- }
115
- /**
116
- * Delete a custom slash command.
117
- */
118
80
  async function deleteMattermostCommand(client, commandId) {
119
- await client.request(`/commands/${encodeURIComponent(commandId)}`, { method: "DELETE" });
120
- }
121
- /**
122
- * Update an existing custom slash command.
123
- */
124
- async function updateMattermostCommand(client, params) {
125
- return await client.request(`/commands/${encodeURIComponent(params.id)}`, {
126
- method: "PUT",
127
- body: JSON.stringify(params)
81
+ await client.request(`/commands/${encodeURIComponent(commandId)}`, {
82
+ method: "DELETE",
83
+ discardResponse: true
128
84
  });
129
85
  }
130
- /**
131
- * Register all OpenClaw slash commands for a given team.
132
- * Skips commands that are already registered with the same trigger + callback URL.
133
- * Returns the list of newly created command IDs.
134
- */
86
+ /** Reconcile owned commands without modifying another integration's trigger. */
135
87
  async function registerSlashCommands(params) {
136
88
  const { client, teamId, creatorUserId, callbackUrl, commands, log } = params;
137
89
  const normalizedCreatorUserId = creatorUserId.trim();
@@ -154,48 +106,47 @@ async function registerSlashCommands(params) {
154
106
  const description = truncateUtf8Prefix(spec.description, MATTERMOST_COMMAND_DESCRIPTION_MAX_BYTES);
155
107
  const existingForTrigger = existingByTrigger.get(spec.trigger) ?? [];
156
108
  const ownedCommands = existingForTrigger.filter((cmd) => cmd.creator_id?.trim() === normalizedCreatorUserId);
157
- const foreignCommands = existingForTrigger.filter((cmd) => cmd.creator_id?.trim() !== normalizedCreatorUserId);
158
- if (ownedCommands.length === 0 && foreignCommands.length > 0) {
109
+ if (ownedCommands.length === 0 && existingForTrigger.length > 0) {
159
110
  log?.(`mattermost: trigger /${spec.trigger} already used by non-OpenClaw command(s); skipping to avoid mutating external integrations`);
160
111
  continue;
161
112
  }
162
113
  if (ownedCommands.length > 1) log?.(`mattermost: multiple owned commands found for /${spec.trigger}; using the first and leaving extras untouched`);
163
114
  const existingCmd = ownedCommands[0];
164
- const existingNeedsUpdate = existingCmd ? existingCmd.url !== callbackUrl || existingCmd.method !== "P" : false;
165
- if (existingCmd && !existingNeedsUpdate) {
166
- log?.(`mattermost: command /${spec.trigger} already registered (id=${existingCmd.id})`);
115
+ const command = {
116
+ team_id: teamId,
117
+ trigger: spec.trigger,
118
+ method: "P",
119
+ url: callbackUrl,
120
+ description,
121
+ auto_complete: spec.autoComplete,
122
+ auto_complete_desc: description,
123
+ auto_complete_hint: spec.autoCompleteHint
124
+ };
125
+ const recordCommand = (receipt, managed) => {
167
126
  registered.push({
168
- id: existingCmd.id,
127
+ id: receipt.id,
169
128
  trigger: spec.trigger,
170
129
  teamId,
171
- token: existingCmd.token,
130
+ token: receipt.token,
172
131
  url: callbackUrl,
173
- managed: false
132
+ managed
174
133
  });
134
+ };
135
+ if (existingCmd?.url === callbackUrl && existingCmd.method === "P") {
136
+ log?.(`mattermost: command /${spec.trigger} already registered (id=${existingCmd.id})`);
137
+ recordCommand(existingCmd, false);
175
138
  continue;
176
139
  }
177
- if (existingCmd && existingNeedsUpdate) {
140
+ if (existingCmd) {
178
141
  log?.(`mattermost: command /${spec.trigger} exists with different callback settings; updating (id=${existingCmd.id})`);
179
142
  try {
180
- const updated = await updateMattermostCommand(client, {
181
- id: existingCmd.id,
182
- team_id: teamId,
183
- trigger: spec.trigger,
184
- method: "P",
185
- url: callbackUrl,
186
- description,
187
- auto_complete: spec.autoComplete,
188
- auto_complete_desc: description,
189
- auto_complete_hint: spec.autoCompleteHint
190
- });
191
- registered.push({
192
- id: updated.id,
193
- trigger: spec.trigger,
194
- teamId,
195
- token: updated.token,
196
- url: callbackUrl,
197
- managed: false
198
- });
143
+ recordCommand(await client.request(`/commands/${encodeURIComponent(existingCmd.id)}`, {
144
+ method: "PUT",
145
+ body: JSON.stringify({
146
+ id: existingCmd.id,
147
+ ...command
148
+ })
149
+ }), false);
199
150
  continue;
200
151
  } catch (err) {
201
152
  log?.(`mattermost: failed to update command /${spec.trigger} (id=${existingCmd.id}): ${String(err)}`);
@@ -209,34 +160,18 @@ async function registerSlashCommands(params) {
209
160
  }
210
161
  }
211
162
  try {
212
- const created = await createMattermostCommand(client, {
213
- team_id: teamId,
214
- trigger: spec.trigger,
215
- method: "P",
216
- url: callbackUrl,
217
- description,
218
- auto_complete: spec.autoComplete,
219
- auto_complete_desc: description,
220
- auto_complete_hint: spec.autoCompleteHint
163
+ const created = await client.request("/commands", {
164
+ method: "POST",
165
+ body: JSON.stringify(command)
221
166
  });
222
167
  log?.(`mattermost: registered command /${spec.trigger} (id=${created.id})`);
223
- registered.push({
224
- id: created.id,
225
- trigger: spec.trigger,
226
- teamId,
227
- token: created.token,
228
- url: callbackUrl,
229
- managed: true
230
- });
168
+ recordCommand(created, true);
231
169
  } catch (err) {
232
170
  log?.(`mattermost: failed to register command /${spec.trigger}: ${String(err)}`);
233
171
  }
234
172
  }
235
173
  return registered;
236
174
  }
237
- /**
238
- * Clean up all registered slash commands.
239
- */
240
175
  async function cleanupSlashCommands(params) {
241
176
  const { client, commands, log } = params;
242
177
  for (const cmd of commands) {
@@ -249,53 +184,34 @@ async function cleanupSlashCommands(params) {
249
184
  }
250
185
  }
251
186
  }
252
- /**
253
- * Parse a Mattermost slash command callback payload from a URL-encoded or JSON body.
254
- */
255
187
  function parseSlashCommandPayload(body, contentType) {
256
188
  if (!body) return null;
257
189
  try {
258
- if (contentType?.includes("application/json")) {
259
- const parsed = JSON.parse(body);
260
- const token = typeof parsed.token === "string" ? parsed.token : "";
261
- const teamId = typeof parsed.team_id === "string" ? parsed.team_id : "";
262
- const channelId = typeof parsed.channel_id === "string" ? parsed.channel_id : "";
263
- const userId = typeof parsed.user_id === "string" ? parsed.user_id : "";
264
- const command = typeof parsed.command === "string" ? parsed.command : "";
265
- if (!token || !teamId || !channelId || !userId || !command) return null;
266
- return {
267
- token,
268
- team_id: teamId,
269
- team_domain: typeof parsed.team_domain === "string" ? parsed.team_domain : void 0,
270
- channel_id: channelId,
271
- channel_name: typeof parsed.channel_name === "string" ? parsed.channel_name : void 0,
272
- user_id: userId,
273
- user_name: typeof parsed.user_name === "string" ? parsed.user_name : void 0,
274
- command,
275
- text: typeof parsed.text === "string" ? parsed.text : "",
276
- trigger_id: typeof parsed.trigger_id === "string" ? parsed.trigger_id : void 0,
277
- response_url: typeof parsed.response_url === "string" ? parsed.response_url : void 0
278
- };
279
- }
280
- const params = new URLSearchParams(body);
281
- const token = params.get("token");
282
- const teamId = params.get("team_id");
283
- const channelId = params.get("channel_id");
284
- const userId = params.get("user_id");
285
- const command = params.get("command");
190
+ const json = contentType?.includes("application/json");
191
+ const parsed = json ? JSON.parse(body) : void 0;
192
+ const form = json ? void 0 : new URLSearchParams(body);
193
+ const read = (key) => {
194
+ const value = form ? form.get(key) : parsed?.[key];
195
+ return typeof value === "string" ? value : void 0;
196
+ };
197
+ const token = read("token");
198
+ const teamId = read("team_id");
199
+ const channelId = read("channel_id");
200
+ const userId = read("user_id");
201
+ const command = read("command");
286
202
  if (!token || !teamId || !channelId || !userId || !command) return null;
287
203
  return {
288
204
  token,
289
205
  team_id: teamId,
290
- team_domain: params.get("team_domain") ?? void 0,
206
+ team_domain: read("team_domain"),
291
207
  channel_id: channelId,
292
- channel_name: params.get("channel_name") ?? void 0,
208
+ channel_name: read("channel_name"),
293
209
  user_id: userId,
294
- user_name: params.get("user_name") ?? void 0,
210
+ user_name: read("user_name"),
295
211
  command,
296
- text: params.get("text") ?? "",
297
- trigger_id: params.get("trigger_id") ?? void 0,
298
- response_url: params.get("response_url") ?? void 0
212
+ text: read("text") ?? "",
213
+ trigger_id: read("trigger_id"),
214
+ response_url: read("response_url")
299
215
  };
300
216
  } catch {
301
217
  return null;
@@ -332,13 +248,8 @@ function resolveSlashCommandConfig(raw) {
332
248
  };
333
249
  }
334
250
  function isSlashCommandsEnabled(config) {
335
- if (config.native === true) return true;
336
- if (config.native === false) return false;
337
- return false;
251
+ return config.native === true;
338
252
  }
339
- /**
340
- * Build the callback URL that Mattermost will POST to when a command is invoked.
341
- */
342
253
  function resolveCallbackUrl(params) {
343
254
  if (params.config.callbackUrl) return params.config.callbackUrl;
344
255
  let host = params.gatewayHost && !isWildcardBindHost(params.gatewayHost) ? params.gatewayHost : "localhost";
@@ -369,16 +280,8 @@ function splitModelRef(modelRef) {
369
280
  model
370
281
  };
371
282
  }
372
- function readContextString(context, key, fallback = "") {
373
- return readStringField(context, key) ?? fallback;
374
- }
375
- function readContextNumber(context, key) {
376
- const value = context[key];
377
- return asFiniteNumber(value) ?? parseStrictInteger(value);
378
- }
379
283
  function normalizePage(value) {
380
- if (!Number.isFinite(value)) return 1;
381
- return Math.max(1, Math.floor(value));
284
+ return Math.max(1, Math.floor(asFiniteNumber(value) ?? 1));
382
285
  }
383
286
  function paginateItems(items, page, pageSize = MODELS_PAGE_SIZE) {
384
287
  const totalPages = Math.max(1, Math.ceil(items.length / pageSize));
@@ -393,16 +296,6 @@ function paginateItems(items, page, pageSize = MODELS_PAGE_SIZE) {
393
296
  totalItems: items.length
394
297
  };
395
298
  }
396
- function buildContext(state) {
397
- return {
398
- [MATTERMOST_MODEL_PICKER_CONTEXT_KEY]: true,
399
- ...state
400
- };
401
- }
402
- function buildButtonId(state) {
403
- const digest = createHash("sha256").update(JSON.stringify(state)).digest("hex").slice(0, 12);
404
- return `${ACTION_IDS[state.action]}${digest}`;
405
- }
406
299
  function buildButton(params) {
407
300
  const baseState = params.action === "providers" || params.action === "back" ? {
408
301
  action: params.action,
@@ -419,11 +312,15 @@ function buildButton(params) {
419
312
  page: normalizePage(params.page),
420
313
  model: normalizeStringifiedOptionalString(params.model) ?? ""
421
314
  };
315
+ const digest = createHash("sha256").update(JSON.stringify(baseState)).digest("hex").slice(0, 12);
422
316
  return {
423
- id: buildButtonId(baseState),
317
+ id: `${ACTION_IDS[baseState.action]}${digest}`,
424
318
  text: params.text,
425
319
  ...params.style ? { style: params.style } : {},
426
- context: buildContext(baseState)
320
+ context: {
321
+ [MATTERMOST_MODEL_PICKER_CONTEXT_KEY]: true,
322
+ ...baseState
323
+ }
427
324
  };
428
325
  }
429
326
  function getProviderModels(data, provider) {
@@ -447,15 +344,15 @@ function resolveMattermostModelPickerEntry(commandText) {
447
344
  }
448
345
  function parseMattermostModelPickerContext(context) {
449
346
  if (!context || context[MATTERMOST_MODEL_PICKER_CONTEXT_KEY] !== true) return null;
450
- const ownerUserId = normalizeOptionalString(readContextString(context, "ownerUserId")) ?? "";
451
- const action = normalizeOptionalString(readContextString(context, "action")) ?? "";
347
+ const ownerUserId = normalizeOptionalString(context.ownerUserId) ?? "";
348
+ const action = normalizeOptionalString(context.action) ?? "";
452
349
  if (!ownerUserId) return null;
453
350
  if (action === "providers" || action === "back") return {
454
351
  action,
455
352
  ownerUserId
456
353
  };
457
- const provider = normalizeProviderId(readContextString(context, "provider"));
458
- const page = readContextNumber(context, "page");
354
+ const provider = normalizeProviderId(readStringField(context, "provider") ?? "");
355
+ const page = asFiniteNumber(context.page) ?? parseStrictInteger(context.page);
459
356
  if (!provider) return null;
460
357
  if (action === "list") return {
461
358
  action,
@@ -464,7 +361,7 @@ function parseMattermostModelPickerContext(context) {
464
361
  page: normalizePage(page)
465
362
  };
466
363
  if (action === "select") {
467
- const model = normalizeOptionalString(readContextString(context, "model")) ?? "";
364
+ const model = normalizeOptionalString(context.model) ?? "";
468
365
  if (!model) return null;
469
366
  return {
470
367
  action,
@@ -485,18 +382,15 @@ function resolveMattermostModelPickerCurrentModel(params) {
485
382
  const fallback = `${params.data.resolvedDefault.provider}/${params.data.resolvedDefault.model}`;
486
383
  try {
487
384
  const storePath = resolveStorePath(params.cfg.session?.store, { agentId: params.route.agentId });
488
- const sessionEntry = getSessionEntry({
385
+ const loadSessionEntry = (sessionKey) => getSessionEntry({
489
386
  storePath,
490
- sessionKey: params.route.sessionKey,
387
+ sessionKey,
491
388
  ...params.readConsistency === "latest" ? { readConsistency: "latest" } : {}
492
389
  });
390
+ const sessionEntry = loadSessionEntry(params.route.sessionKey);
493
391
  const override = resolveStoredModelOverride({
494
392
  sessionEntry,
495
- loadSessionEntry: (sessionKey) => getSessionEntry({
496
- storePath,
497
- sessionKey,
498
- ...params.readConsistency === "latest" ? { readConsistency: "latest" } : {}
499
- }),
393
+ loadSessionEntry,
500
394
  sessionKey: params.route.sessionKey,
501
395
  parentSessionKey: sessionEntry?.parentSessionKey,
502
396
  defaultProvider: params.data.resolvedDefault.provider
@@ -674,431 +568,6 @@ async function deliverMattermostReplyPayload(params) {
674
568
  };
675
569
  }
676
570
  //#endregion
677
- //#region extensions/mattermost/src/mattermost/target-resolution.ts
678
- const MATTERMOST_OPAQUE_TARGET_CACHE_MAX_ENTRIES = 1024;
679
- const MATTERMOST_OPAQUE_TARGET_CACHE_TTL_MS = 3e5;
680
- const mattermostOpaqueTargetCache = /* @__PURE__ */ new Map();
681
- function cacheMattermostOpaqueTarget(key, kind) {
682
- mattermostOpaqueTargetCache.set(key, {
683
- kind,
684
- expiresAt: Date.now() + MATTERMOST_OPAQUE_TARGET_CACHE_TTL_MS
685
- });
686
- pruneMapToMaxSize(mattermostOpaqueTargetCache, MATTERMOST_OPAQUE_TARGET_CACHE_MAX_ENTRIES);
687
- }
688
- function getCachedMattermostOpaqueTargetKind(key) {
689
- const cached = mattermostOpaqueTargetCache.get(key);
690
- if (!cached) return;
691
- if (cached.expiresAt <= Date.now()) {
692
- mattermostOpaqueTargetCache.delete(key);
693
- return;
694
- }
695
- return cached.kind;
696
- }
697
- function cacheKey$1(baseUrl, token, id) {
698
- return `${baseUrl}::${token}::${id}`;
699
- }
700
- /** Mattermost IDs are 26-character lowercase alphanumeric strings. */
701
- function isMattermostId(value) {
702
- return /^[a-z0-9]{26}$/.test(value);
703
- }
704
- function parseMattermostTarget(raw) {
705
- const trimmed = raw.trim();
706
- if (!trimmed) throw new Error("Recipient is required for Mattermost sends");
707
- const lower = normalizeLowercaseStringOrEmpty(trimmed);
708
- if (lower.startsWith("channel:")) {
709
- const id = trimmed.slice(8).trim();
710
- if (!id) throw new Error("Channel id is required for Mattermost sends");
711
- if (id.startsWith("#")) {
712
- const name = id.slice(1).trim();
713
- if (!name) throw new Error("Channel name is required for Mattermost sends");
714
- return {
715
- kind: "channel-name",
716
- name
717
- };
718
- }
719
- if (!isMattermostId(id)) return {
720
- kind: "channel-name",
721
- name: id
722
- };
723
- return {
724
- kind: "channel",
725
- id
726
- };
727
- }
728
- if (lower.startsWith("user:")) {
729
- const id = trimmed.slice(5).trim();
730
- if (!id) throw new Error("User id is required for Mattermost sends");
731
- return {
732
- kind: "user",
733
- id
734
- };
735
- }
736
- if (lower.startsWith("mattermost:")) {
737
- const id = trimmed.slice(11).trim();
738
- if (!id) throw new Error("User id is required for Mattermost sends");
739
- return {
740
- kind: "user",
741
- id
742
- };
743
- }
744
- if (trimmed.startsWith("@")) {
745
- const username = trimmed.slice(1).trim();
746
- if (!username) throw new Error("Username is required for Mattermost sends");
747
- return {
748
- kind: "user",
749
- username
750
- };
751
- }
752
- if (trimmed.startsWith("#")) {
753
- const name = trimmed.slice(1).trim();
754
- if (!name) throw new Error("Channel name is required for Mattermost sends");
755
- return {
756
- kind: "channel-name",
757
- name
758
- };
759
- }
760
- if (!isMattermostId(trimmed)) return {
761
- kind: "channel-name",
762
- name: trimmed
763
- };
764
- return {
765
- kind: "channel",
766
- id: trimmed
767
- };
768
- }
769
- function isExplicitMattermostTarget(raw) {
770
- const trimmed = raw.trim();
771
- if (!trimmed) return false;
772
- return /^(channel|user|mattermost):/i.test(trimmed) || trimmed.startsWith("@") || trimmed.startsWith("#");
773
- }
774
- async function resolveMattermostOpaqueTarget(params) {
775
- const input = params.input.trim();
776
- if (!input || isExplicitMattermostTarget(input) || !isMattermostId(input)) return null;
777
- let client;
778
- if ("client" in params) client = params.client;
779
- else {
780
- const account = resolveMattermostAccount({
781
- cfg: params.cfg,
782
- accountId: params.accountId
783
- });
784
- if (!account.enabled) throw new Error(`Mattermost account "${account.accountId}" is disabled`);
785
- const token = normalizeOptionalString(account.botToken);
786
- const baseUrl = normalizeMattermostBaseUrl(account.baseUrl);
787
- if (!token || !baseUrl) return null;
788
- client = createMattermostClient({
789
- baseUrl,
790
- botToken: token,
791
- allowPrivateNetwork: isPrivateNetworkOptInEnabled(account.config)
792
- });
793
- }
794
- const key = cacheKey$1(client.baseUrl, client.token, input);
795
- const cachedKind = getCachedMattermostOpaqueTargetKind(key);
796
- if (cachedKind) return {
797
- kind: cachedKind,
798
- id: input,
799
- to: cachedKind === "user" ? `user:${input}` : `channel:${input}`
800
- };
801
- try {
802
- await fetchMattermostUser(client, input);
803
- cacheMattermostOpaqueTarget(key, "user");
804
- return {
805
- kind: "user",
806
- id: input,
807
- to: `user:${input}`
808
- };
809
- } catch (err) {
810
- if (parseMattermostApiStatus(err) !== 404) return {
811
- kind: "channel",
812
- id: input,
813
- to: `channel:${input}`
814
- };
815
- }
816
- try {
817
- const channel = await fetchMattermostChannel(client, input);
818
- const channelKind = resolveMattermostTrustedChatKind({ channelType: channel.type }) === "group" ? "group" : "channel";
819
- cacheMattermostOpaqueTarget(key, channelKind);
820
- return {
821
- kind: channelKind,
822
- id: input,
823
- to: `channel:${input}`
824
- };
825
- } catch {
826
- return {
827
- kind: "channel",
828
- id: input,
829
- to: `channel:${input}`
830
- };
831
- }
832
- }
833
- //#endregion
834
- //#region extensions/mattermost/src/mattermost/send.ts
835
- const MATTERMOST_BOT_USER_CACHE_MAX_ENTRIES = 64;
836
- const MATTERMOST_TARGET_CACHE_MAX_ENTRIES = 1024;
837
- const MATTERMOST_FORMAT_PROFILE = FormatCapabilityProfile.define({
838
- mechanism: "markdown",
839
- chunk: {
840
- limit: 16383,
841
- unit: "chars"
842
- }
843
- });
844
- function renderMattermostMarkdown(markdown, tableMode) {
845
- return tableMode === "off" && MATTERMOST_FORMAT_PROFILE.constructs.table === "native" ? markdown : convertMarkdownTables(markdown, tableMode);
846
- }
847
- const botUserCache = /* @__PURE__ */ new Map();
848
- const userByNameCache = /* @__PURE__ */ new Map();
849
- const channelByNameCache = /* @__PURE__ */ new Map();
850
- const dmChannelCache = /* @__PURE__ */ new Map();
851
- function cacheOutboundEntry(cache, key, value, maxEntries) {
852
- cache.delete(key);
853
- cache.set(key, value);
854
- pruneMapToMaxSize(cache, maxEntries);
855
- }
856
- const getCore = () => getMattermostRuntime();
857
- function createMattermostSendReceipt(params) {
858
- return createMessageReceiptFromOutboundResults({
859
- kind: params.kind,
860
- ...params.replyToId ? { replyToId: params.replyToId } : {},
861
- results: [{
862
- channel: "mattermost",
863
- messageId: params.messageId,
864
- channelId: params.channelId
865
- }]
866
- });
867
- }
868
- function resolveMattermostReceiptKind(params) {
869
- if (params.fileIds?.length) return "media";
870
- if (params.buttons?.length || params.props) return "card";
871
- return "text";
872
- }
873
- function recordMattermostOutboundActivity(accountId) {
874
- try {
875
- getCore().channel.activity.record({
876
- channel: "mattermost",
877
- accountId,
878
- direction: "outbound"
879
- });
880
- } catch (error) {
881
- if (!(error instanceof Error) || error.message !== "Mattermost runtime not initialized") throw error;
882
- }
883
- }
884
- function cacheKey(baseUrl, token) {
885
- return `${baseUrl}::${token}`;
886
- }
887
- function normalizeMessage(text, mediaUrl) {
888
- return [normalizeOptionalString(text) ?? "", normalizeOptionalString(mediaUrl)].filter(Boolean).join("\n");
889
- }
890
- function isHttpUrl(value) {
891
- return /^https?:\/\//i.test(value);
892
- }
893
- async function resolveBotUser(client) {
894
- const key = cacheKey(client.baseUrl, client.token);
895
- const cached = botUserCache.get(key);
896
- if (cached) return cached;
897
- const user = await fetchMattermostMe(client);
898
- cacheOutboundEntry(botUserCache, key, user, MATTERMOST_BOT_USER_CACHE_MAX_ENTRIES);
899
- return user;
900
- }
901
- async function resolveUserIdByUsername(params) {
902
- const { client, username } = params;
903
- const key = `${cacheKey(client.baseUrl, client.token)}::${normalizeLowercaseStringOrEmpty(username)}`;
904
- const cached = userByNameCache.get(key);
905
- if (cached?.id) return cached.id;
906
- const user = await fetchMattermostUserByUsername(client, username);
907
- cacheOutboundEntry(userByNameCache, key, user, MATTERMOST_TARGET_CACHE_MAX_ENTRIES);
908
- return user.id;
909
- }
910
- async function resolveChannelIdByName(params) {
911
- const { client, name } = params;
912
- const key = `${cacheKey(client.baseUrl, client.token)}::channel::${normalizeLowercaseStringOrEmpty(name)}`;
913
- const cached = channelByNameCache.get(key);
914
- if (cached) return cached;
915
- const me = await fetchMattermostMe(client);
916
- const teams = await fetchMattermostUserTeams(client, me.id);
917
- for (const team of teams) try {
918
- const channel = await fetchMattermostChannelByName(client, team.id, name);
919
- if (channel?.id) {
920
- cacheOutboundEntry(channelByNameCache, key, channel.id, MATTERMOST_TARGET_CACHE_MAX_ENTRIES);
921
- return channel.id;
922
- }
923
- } catch (error) {
924
- if (parseMattermostApiStatus(error) !== 404) throw error;
925
- }
926
- throw new Error(`Mattermost channel "#${name}" not found in any team the bot belongs to`);
927
- }
928
- function mergeDmRetryOptions(base, override) {
929
- const merged = {
930
- maxRetries: override?.maxRetries ?? base?.maxRetries,
931
- initialDelayMs: override?.initialDelayMs ?? base?.initialDelayMs,
932
- maxDelayMs: override?.maxDelayMs ?? base?.maxDelayMs,
933
- timeoutMs: override?.timeoutMs ?? base?.timeoutMs,
934
- onRetry: override?.onRetry
935
- };
936
- if (merged.maxRetries === void 0 && merged.initialDelayMs === void 0 && merged.maxDelayMs === void 0 && merged.timeoutMs === void 0 && merged.onRetry === void 0) return;
937
- return merged;
938
- }
939
- async function resolveTargetChannelId(params) {
940
- if (params.target.kind === "channel") return params.target.id;
941
- if (params.target.kind === "channel-name") return await resolveChannelIdByName({
942
- client: params.client,
943
- name: params.target.name
944
- });
945
- const userId = params.target.id ? params.target.id : await resolveUserIdByUsername({
946
- client: params.client,
947
- username: params.target.username ?? ""
948
- });
949
- const dmKey = `${cacheKey(params.client.baseUrl, params.client.token)}::dm::${userId}`;
950
- const cachedDm = dmChannelCache.get(dmKey);
951
- if (cachedDm) return cachedDm;
952
- const botUser = await resolveBotUser(params.client);
953
- const channel = await createMattermostDirectChannelWithRetry(params.client, [botUser.id, userId], {
954
- ...params.dmRetryOptions,
955
- onRetry: (attempt, delayMs, error) => {
956
- params.dmRetryOptions?.onRetry?.(attempt, delayMs, error);
957
- if (params.logger) params.logger.warn?.(`DM channel creation retry ${attempt} after ${delayMs}ms: ${error.message}`);
958
- }
959
- });
960
- cacheOutboundEntry(dmChannelCache, dmKey, channel.id, MATTERMOST_TARGET_CACHE_MAX_ENTRIES);
961
- return channel.id;
962
- }
963
- async function resolveMattermostSendContext(to, opts) {
964
- const core = getCore();
965
- const logger = core.logging.getChildLogger({ module: "mattermost" });
966
- if (!opts?.cfg) throw new Error("Mattermost send requires a resolved runtime config. Load and resolve config at the command or gateway boundary, then pass cfg through the runtime path.");
967
- const cfg = requireRuntimeConfig(opts.cfg, "Mattermost send");
968
- const account = resolveMattermostAccount({
969
- cfg,
970
- accountId: opts.accountId
971
- });
972
- const token = normalizeOptionalString(opts.botToken) ?? normalizeOptionalString(account.botToken);
973
- if (!token) throw new Error(`Mattermost bot token missing for account "${account.accountId}" (set channels.mattermost.accounts.${account.accountId}.botToken or MATTERMOST_BOT_TOKEN for default).`);
974
- const baseUrl = normalizeMattermostBaseUrl(opts.baseUrl ?? account.baseUrl);
975
- if (!baseUrl) throw new Error(`Mattermost baseUrl missing for account "${account.accountId}" (set channels.mattermost.accounts.${account.accountId}.baseUrl or MATTERMOST_URL for default).`);
976
- const client = createMattermostClient({
977
- baseUrl,
978
- botToken: token,
979
- allowPrivateNetwork: isPrivateNetworkOptInEnabled(account.config)
980
- });
981
- const trimmedTo = normalizeOptionalString(to) ?? "";
982
- const channelId = await resolveTargetChannelId({
983
- target: parseMattermostTarget((await resolveMattermostOpaqueTarget({
984
- input: trimmedTo,
985
- client
986
- }))?.to ?? trimmedTo),
987
- client,
988
- dmRetryOptions: mergeDmRetryOptions(account.config.dmChannelRetry ? {
989
- maxRetries: account.config.dmChannelRetry.maxRetries,
990
- initialDelayMs: account.config.dmChannelRetry.initialDelayMs,
991
- maxDelayMs: account.config.dmChannelRetry.maxDelayMs,
992
- timeoutMs: account.config.dmChannelRetry.timeoutMs
993
- } : void 0, opts.dmRetryOptions),
994
- logger: core.logging.shouldLogVerbose() ? logger : void 0
995
- });
996
- return {
997
- cfg,
998
- accountId: account.accountId,
999
- client,
1000
- channelId,
1001
- mediaMaxBytes: resolveChannelMediaMaxBytes({
1002
- cfg,
1003
- accountId: account.accountId,
1004
- resolveChannelLimitMb: () => account.config.mediaMaxMb
1005
- })
1006
- };
1007
- }
1008
- async function sendMessageMattermost(to, text, opts) {
1009
- const core = getCore();
1010
- const logger = core.logging.getChildLogger({ module: "mattermost" });
1011
- const { cfg, accountId, client, channelId, mediaMaxBytes } = await resolveMattermostSendContext(to, opts);
1012
- let props = opts.props;
1013
- if (!props && Array.isArray(opts.buttons) && opts.buttons.length > 0) {
1014
- setInteractionSecret(accountId, client.token);
1015
- props = buildButtonProps({
1016
- callbackUrl: resolveInteractionCallbackUrl(accountId, {
1017
- gateway: cfg.gateway,
1018
- interactions: resolveMattermostAccount({
1019
- cfg,
1020
- accountId
1021
- }).config?.interactions
1022
- }),
1023
- accountId,
1024
- channelId,
1025
- buttons: opts.buttons,
1026
- text: opts.attachmentText
1027
- });
1028
- }
1029
- let message = normalizeOptionalString(text) ?? "";
1030
- let fileIds;
1031
- let uploadError;
1032
- const mediaUrl = opts.mediaUrl?.trim();
1033
- if (mediaUrl) try {
1034
- const media = await loadOutboundMediaFromUrl(mediaUrl, {
1035
- maxBytes: mediaMaxBytes,
1036
- mediaLocalRoots: opts.mediaLocalRoots,
1037
- mediaReadFile: opts.mediaReadFile,
1038
- workspaceDir: opts.workspaceDir
1039
- });
1040
- fileIds = [(await uploadMattermostFile(client, {
1041
- channelId,
1042
- buffer: media.buffer,
1043
- fileName: media.fileName ?? `upload${extensionForMime(media.contentType) ?? ""}`,
1044
- contentType: media.contentType ?? void 0
1045
- })).id];
1046
- } catch (err) {
1047
- uploadError = err instanceof Error ? err : new Error(String(err));
1048
- if (opts.requireMediaUpload || mediaMaxBytes !== void 0) throw new Error(`Mattermost media upload failed: ${uploadError.message}`, { cause: err });
1049
- if (core.logging.shouldLogVerbose()) logger.debug?.(`mattermost send: media upload failed, falling back to URL text: ${String(err)}`);
1050
- message = normalizeMessage(message, isHttpUrl(mediaUrl) ? mediaUrl : "");
1051
- }
1052
- if (message) {
1053
- const tableMode = resolveMarkdownTableMode({
1054
- cfg,
1055
- channel: "mattermost",
1056
- accountId
1057
- });
1058
- message = renderMattermostMarkdown(message, tableMode);
1059
- }
1060
- if (!message && (!fileIds || fileIds.length === 0)) {
1061
- if (uploadError) throw new Error(`Mattermost media upload failed: ${uploadError.message}`, { cause: uploadError });
1062
- throw new Error("Mattermost message is empty");
1063
- }
1064
- const post = await createMattermostPost(client, {
1065
- channelId,
1066
- message,
1067
- rootId: opts.replyToId,
1068
- fileIds,
1069
- props
1070
- });
1071
- const messageId = post.id;
1072
- const receipt = createMattermostSendReceipt({
1073
- messageId,
1074
- channelId,
1075
- kind: resolveMattermostReceiptKind({
1076
- fileIds,
1077
- buttons: opts.buttons,
1078
- props
1079
- }),
1080
- replyToId: opts.replyToId
1081
- });
1082
- const result = {
1083
- messageId,
1084
- channelId,
1085
- receipt,
1086
- content: post.message ?? message
1087
- };
1088
- try {
1089
- await opts.onDeliveryResult?.(result);
1090
- recordMattermostOutboundActivity(accountId);
1091
- } catch (error) {
1092
- throw createChannelPartialDeliveryError(error, {
1093
- messageIds: listMessageReceiptPlatformIds(receipt),
1094
- receipt,
1095
- visibleReplySent: true,
1096
- content: result.content
1097
- });
1098
- }
1099
- return result;
1100
- }
1101
- //#endregion
1102
571
  //#region extensions/mattermost/src/mattermost/slash-http.ts
1103
572
  const MAX_BODY_BYTES = 65536;
1104
573
  const BODY_READ_TIMEOUT_MS = 5e3;
@@ -1120,17 +589,7 @@ const SECRET_LOG_KEYS = /* @__PURE__ */ new Set([
1120
589
  "refresh_token",
1121
590
  "token"
1122
591
  ]);
1123
- /**
1124
- * Read the full request body as a string.
1125
- */
1126
- function readBody(req, maxBytes, timeoutMs = BODY_READ_TIMEOUT_MS) {
1127
- return readRequestBodyWithLimit(req, {
1128
- maxBytes,
1129
- timeoutMs,
1130
- destroyOnLimit: false
1131
- });
1132
- }
1133
- function sendJsonResponse(res, status, body) {
592
+ function sendSlashCommandResponse(res, status, body) {
1134
593
  res.statusCode = status;
1135
594
  res.setHeader("Content-Type", "application/json; charset=utf-8");
1136
595
  res.end(JSON.stringify(body));
@@ -1174,9 +633,11 @@ function commandLookupKey(client, registered, accountId) {
1174
633
  return `${client.apiBaseUrl}:${accountId}:${registered.teamId}:${registered.id}`;
1175
634
  }
1176
635
  function clearMattermostSlashCommandValidationCacheForAccount(accountId) {
1177
- for (const [key, entry] of commandValidationFailureCache) if (entry.accountId === accountId) commandValidationFailureCache.delete(key);
1178
- for (const [key, entry] of commandLookupInflight) if (entry.accountId === accountId) commandLookupInflight.delete(key);
1179
- for (const [key, entry] of commandValidationLookupRateLimit) if (entry.accountId === accountId) commandValidationLookupRateLimit.delete(key);
636
+ for (const cache of [
637
+ commandValidationFailureCache,
638
+ commandLookupInflight,
639
+ commandValidationLookupRateLimit
640
+ ]) for (const [key, entry] of cache) if (entry.accountId === accountId) cache.delete(key);
1180
641
  }
1181
642
  function sweepCommandValidationFailureCache(now = Date.now()) {
1182
643
  const validNow = asDateTimestampMs(now);
@@ -1188,22 +649,11 @@ function sweepCommandValidationFailureCache(now = Date.now()) {
1188
649
  const expiresAt = asDateTimestampMs(entry.expiresAt);
1189
650
  if (expiresAt === void 0 || expiresAt <= validNow) commandValidationFailureCache.delete(key);
1190
651
  }
1191
- while (commandValidationFailureCache.size > COMMAND_VALIDATION_FAILURE_CACHE_MAX_KEYS) {
1192
- const oldestKey = commandValidationFailureCache.keys().next().value;
1193
- if (!oldestKey) break;
1194
- commandValidationFailureCache.delete(oldestKey);
1195
- }
652
+ pruneMapToMaxSize(commandValidationFailureCache, COMMAND_VALIDATION_FAILURE_CACHE_MAX_KEYS);
1196
653
  }
1197
654
  function hasCachedCommandValidationFailure(key, now = Date.now()) {
1198
655
  sweepCommandValidationFailureCache(now);
1199
- const validNow = asDateTimestampMs(now);
1200
- if (validNow === void 0) return false;
1201
- const cached = commandValidationFailureCache.get(key);
1202
- if (!cached) return false;
1203
- const expiresAt = asDateTimestampMs(cached.expiresAt);
1204
- if (expiresAt !== void 0 && expiresAt > validNow) return true;
1205
- commandValidationFailureCache.delete(key);
1206
- return false;
656
+ return commandValidationFailureCache.has(key);
1207
657
  }
1208
658
  function cacheCommandValidationFailure(key, accountId) {
1209
659
  const now = Date.now();
@@ -1229,11 +679,7 @@ function sweepCommandValidationLookupRateLimit(now = Date.now()) {
1229
679
  const updatedAt = asDateTimestampMs(entry.updatedAt);
1230
680
  if (updatedAt === void 0 || validNow - updatedAt > staleAfterMs) commandValidationLookupRateLimit.delete(key);
1231
681
  }
1232
- while (commandValidationLookupRateLimit.size > COMMAND_VALIDATION_LOOKUP_RATE_LIMIT_MAX_KEYS) {
1233
- const oldestKey = commandValidationLookupRateLimit.keys().next().value;
1234
- if (!oldestKey) break;
1235
- commandValidationLookupRateLimit.delete(oldestKey);
1236
- }
682
+ pruneMapToMaxSize(commandValidationLookupRateLimit, COMMAND_VALIDATION_LOOKUP_RATE_LIMIT_MAX_KEYS);
1237
683
  }
1238
684
  function reserveCommandValidationLookup(params) {
1239
685
  const rawNow = params.now ?? Date.now();
@@ -1415,12 +861,6 @@ async function authorizeSlashInvocation(params) {
1415
861
  denyResponse: void 0
1416
862
  };
1417
863
  }
1418
- /**
1419
- * Create the HTTP request handler for Mattermost slash command callbacks.
1420
- *
1421
- * This handler is registered as a plugin HTTP route and receives POSTs
1422
- * from the Mattermost server when a user invokes a registered slash command.
1423
- */
1424
864
  function createSlashCommandHttpHandler(params) {
1425
865
  const { account, cfg, runtime, registeredCommands, triggerMap, log, bodyTimeoutMs } = params;
1426
866
  return async (req, res, bufferedBody, onRequestAuthenticated) => {
@@ -1432,7 +872,11 @@ function createSlashCommandHttpHandler(params) {
1432
872
  }
1433
873
  let body;
1434
874
  try {
1435
- body = bufferedBody ?? await readBody(req, MAX_BODY_BYTES, bodyTimeoutMs);
875
+ body = bufferedBody ?? await readRequestBodyWithLimit(req, {
876
+ maxBytes: MAX_BODY_BYTES,
877
+ timeoutMs: bodyTimeoutMs ?? BODY_READ_TIMEOUT_MS,
878
+ destroyOnLimit: false
879
+ });
1436
880
  } catch (error) {
1437
881
  if (isRequestBodyLimitError(error, "REQUEST_BODY_TIMEOUT")) {
1438
882
  await sendHttpRequestRejection(req, res, 408, "Request body timeout");
@@ -1444,7 +888,7 @@ function createSlashCommandHttpHandler(params) {
1444
888
  const contentType = req.headers["content-type"] ?? "";
1445
889
  const payload = parseSlashCommandPayload(body, contentType);
1446
890
  if (!payload) {
1447
- sendJsonResponse(res, 400, {
891
+ sendSlashCommandResponse(res, 400, {
1448
892
  response_type: "ephemeral",
1449
893
  text: "Invalid slash command payload."
1450
894
  });
@@ -1455,7 +899,7 @@ function createSlashCommandHttpHandler(params) {
1455
899
  payload
1456
900
  });
1457
901
  if (!registeredCommand || !safeEqualSecret(payload.token, registeredCommand.token)) {
1458
- sendJsonResponse(res, 401, {
902
+ sendSlashCommandResponse(res, 401, {
1459
903
  response_type: "ephemeral",
1460
904
  text: "Unauthorized: invalid command token."
1461
905
  });
@@ -1473,7 +917,7 @@ function createSlashCommandHttpHandler(params) {
1473
917
  payload,
1474
918
  log
1475
919
  })) {
1476
- sendJsonResponse(res, 401, {
920
+ sendSlashCommandResponse(res, 401, {
1477
921
  response_type: "ephemeral",
1478
922
  text: "Unauthorized: invalid command token."
1479
923
  });
@@ -1496,14 +940,14 @@ function createSlashCommandHttpHandler(params) {
1496
940
  log
1497
941
  });
1498
942
  if (!auth.ok) {
1499
- sendJsonResponse(res, 200, auth.denyResponse ?? {
943
+ sendSlashCommandResponse(res, 200, auth.denyResponse ?? {
1500
944
  response_type: "ephemeral",
1501
945
  text: "Unauthorized."
1502
946
  });
1503
947
  return;
1504
948
  }
1505
949
  log?.(`mattermost: slash command /${sanitizeMattermostLogValue(trigger)} from ${sanitizeMattermostLogValue(senderName)} in ${sanitizeMattermostLogValue(channelId)}`);
1506
- sendJsonResponse(res, 200, {
950
+ sendSlashCommandResponse(res, 200, {
1507
951
  response_type: "ephemeral",
1508
952
  text: "Processing..."
1509
953
  });
@@ -1521,7 +965,6 @@ function createSlashCommandHttpHandler(params) {
1521
965
  triggerId: payload.trigger_id,
1522
966
  kind: auth.kind,
1523
967
  chatType: auth.chatType,
1524
- channelName: auth.channelName,
1525
968
  channelDisplay: auth.channelDisplay,
1526
969
  roomLabel: auth.roomLabel,
1527
970
  commandAuthorized: auth.commandAuthorized,
@@ -1530,7 +973,8 @@ function createSlashCommandHttpHandler(params) {
1530
973
  } catch (err) {
1531
974
  log?.(`mattermost: slash command handler error: ${sanitizeCommandLookupError(err)}`);
1532
975
  try {
1533
- await sendMessageMattermost(`channel:${channelId}`, "Sorry, something went wrong processing that command.", {
976
+ const to = `channel:${channelId}`;
977
+ await sendMessageMattermost(to, "Sorry, something went wrong processing that command.", {
1534
978
  cfg,
1535
979
  accountId: account.accountId
1536
980
  });
@@ -1539,7 +983,7 @@ function createSlashCommandHttpHandler(params) {
1539
983
  };
1540
984
  }
1541
985
  async function handleSlashCommandAsync(params) {
1542
- const { account, cfg, runtime, client, commandText, channelId, senderId, senderName, teamId, kind, chatType, channelName: _channelName, channelDisplay, roomLabel, commandAuthorized, triggerId, log } = params;
986
+ const { account, cfg, runtime, client, commandText, channelId, senderId, senderName, teamId, kind, chatType, channelDisplay, roomLabel, commandAuthorized, triggerId, log } = params;
1543
987
  const core = getMattermostRuntime();
1544
988
  const route = core.channel.routing.resolveAgentRoute({
1545
989
  cfg,
@@ -1568,24 +1012,19 @@ async function handleSlashCommandAsync(params) {
1568
1012
  });
1569
1013
  return;
1570
1014
  }
1571
- const currentModel = resolveMattermostModelPickerCurrentModel({
1572
- cfg,
1573
- route,
1574
- data
1575
- });
1576
- const view = pickerEntry.kind === "summary" ? renderMattermostModelSummaryView({
1577
- ownerUserId: senderId,
1578
- currentModel
1579
- }) : pickerEntry.kind === "providers" ? renderMattermostProviderPickerView({
1580
- ownerUserId: senderId,
1581
- data,
1582
- currentModel
1583
- }) : renderMattermostModelsPickerView({
1015
+ const viewParams = {
1584
1016
  ownerUserId: senderId,
1585
1017
  data,
1018
+ currentModel: resolveMattermostModelPickerCurrentModel({
1019
+ cfg,
1020
+ route,
1021
+ data
1022
+ })
1023
+ };
1024
+ const view = pickerEntry.kind === "summary" ? renderMattermostModelSummaryView(viewParams) : pickerEntry.kind === "providers" ? renderMattermostProviderPickerView(viewParams) : renderMattermostModelsPickerView({
1025
+ ...viewParams,
1586
1026
  provider: pickerEntry.provider,
1587
- page: 1,
1588
- currentModel
1027
+ page: 1
1589
1028
  });
1590
1029
  await sendMessageMattermost(`channel:${channelId}`, [data.refreshWarning, view.text].filter(Boolean).join("\n\n"), {
1591
1030
  cfg,
@@ -1677,17 +1116,6 @@ async function handleSlashCommandAsync(params) {
1677
1116
  }
1678
1117
  //#endregion
1679
1118
  //#region extensions/mattermost/src/mattermost/slash-state.ts
1680
- /**
1681
- * Shared state for Mattermost slash commands.
1682
- *
1683
- * Bridges the plugin registration phase (HTTP route) with the monitor phase
1684
- * (command registration with MM API). The HTTP handler needs to know which
1685
- * tokens are known for fast-path routing, and the monitor needs to store
1686
- * registered command IDs.
1687
- *
1688
- * State is kept per-account so that multi-account deployments don't
1689
- * overwrite each other's tokens, registered commands, or handlers.
1690
- */
1691
1119
  const MULTI_ACCOUNT_BODY_MAX_BYTES = 65536;
1692
1120
  const MULTI_ACCOUNT_BODY_TIMEOUT_MS = 5e3;
1693
1121
  const slashRouteInFlightLimiter = createWebhookInFlightLimiter();
@@ -1719,9 +1147,9 @@ function resolveSlashRouteInFlightKey(authorization) {
1719
1147
  for (const state of accountStates.values()) for (const commandToken of state.commandTokens) matched = safeEqualSecret(token, commandToken) || matched;
1720
1148
  return matched ? `${SLASH_AUTHENTICATED_IN_FLIGHT_KEY}:${createHash("sha256").update(`${SLASH_AUTHENTICATED_IN_FLIGHT_KEY}:${token}`).digest("hex")}` : SLASH_ROUTE_IN_FLIGHT_KEY;
1721
1149
  }
1722
- function resolveSlashHandlerForToken(token) {
1150
+ function resolveSlashHandler(source, matchesState) {
1723
1151
  const matches = [];
1724
- for (const [accountId, state] of accountStates) if (state.commandTokens.has(token) && state.handler) matches.push({
1152
+ for (const [accountId, state] of accountStates) if (state.handler && matchesState(state)) matches.push({
1725
1153
  accountId,
1726
1154
  handler: state.handler
1727
1155
  });
@@ -1731,45 +1159,22 @@ function resolveSlashHandlerForToken(token) {
1731
1159
  if (!match) return { kind: "none" };
1732
1160
  return {
1733
1161
  kind: "single",
1734
- source: "token",
1162
+ source,
1735
1163
  handler: match.handler,
1736
1164
  accountIds: [match.accountId]
1737
1165
  };
1738
1166
  }
1739
1167
  return {
1740
1168
  kind: "ambiguous",
1741
- source: "token",
1169
+ source,
1742
1170
  accountIds: matches.map((entry) => entry.accountId)
1743
1171
  };
1744
1172
  }
1745
1173
  function resolveSlashHandlerForCommand(params) {
1746
1174
  const trigger = normalizeSlashCommandTrigger(params.command);
1747
1175
  if (!trigger) return { kind: "none" };
1748
- const matches = [];
1749
- for (const [accountId, state] of accountStates) if (state.handler && state.registeredCommands.some((cmd) => cmd.teamId === params.teamId && cmd.trigger === trigger)) matches.push({
1750
- accountId,
1751
- handler: state.handler
1752
- });
1753
- if (matches.length === 0) return { kind: "none" };
1754
- if (matches.length === 1) {
1755
- const match = matches[0];
1756
- if (!match) return { kind: "none" };
1757
- return {
1758
- kind: "single",
1759
- source: "command",
1760
- handler: match.handler,
1761
- accountIds: [match.accountId]
1762
- };
1763
- }
1764
- return {
1765
- kind: "ambiguous",
1766
- source: "command",
1767
- accountIds: matches.map((entry) => entry.accountId)
1768
- };
1176
+ return resolveSlashHandler("command", (state) => state.registeredCommands.some((cmd) => cmd.teamId === params.teamId && cmd.trigger === trigger));
1769
1177
  }
1770
- /**
1771
- * Get the slash command state for a specific account, or null if not activated.
1772
- */
1773
1178
  function getSlashCommandState(accountId) {
1774
1179
  return accountStates.get(accountId) ?? null;
1775
1180
  }
@@ -1780,7 +1185,6 @@ function getSlashCommandState(accountId) {
1780
1185
  function activateSlashCommands(params) {
1781
1186
  const { account, commandTokens, registeredCommands, triggerMap, api, log } = params;
1782
1187
  const accountId = account.accountId;
1783
- const tokenSet = new Set(commandTokens);
1784
1188
  const handler = createSlashCommandHttpHandler({
1785
1189
  account,
1786
1190
  cfg: api.cfg,
@@ -1790,35 +1194,20 @@ function activateSlashCommands(params) {
1790
1194
  log
1791
1195
  });
1792
1196
  accountStates.set(accountId, {
1793
- commandTokens: tokenSet,
1197
+ commandTokens: new Set(commandTokens),
1794
1198
  registeredCommands,
1795
- handler,
1796
- account,
1797
- triggerMap: triggerMap ?? /* @__PURE__ */ new Map()
1199
+ handler
1798
1200
  });
1799
1201
  log?.(`mattermost: slash commands activated for account ${accountId} (${registeredCommands.length} commands)`);
1800
1202
  }
1801
- /**
1802
- * Deactivate slash commands for a specific account (on shutdown/disconnect).
1803
- */
1804
1203
  function deactivateSlashCommands(accountId) {
1805
- if (accountId) {
1806
- const state = accountStates.get(accountId);
1807
- if (state) {
1808
- state.commandTokens.clear();
1809
- state.registeredCommands = [];
1810
- state.handler = null;
1811
- clearMattermostSlashCommandValidationCacheForAccount(accountId);
1812
- accountStates.delete(accountId);
1813
- }
1814
- } else {
1815
- for (const [stateAccountId, state] of accountStates) {
1816
- state.commandTokens.clear();
1817
- state.registeredCommands = [];
1818
- state.handler = null;
1819
- clearMattermostSlashCommandValidationCacheForAccount(stateAccountId);
1820
- }
1821
- accountStates.clear();
1204
+ for (const [stateAccountId, state] of accountStates) {
1205
+ if (accountId && stateAccountId !== accountId) continue;
1206
+ state.commandTokens.clear();
1207
+ state.registeredCommands = [];
1208
+ state.handler = null;
1209
+ clearMattermostSlashCommandValidationCacheForAccount(stateAccountId);
1210
+ accountStates.delete(stateAccountId);
1822
1211
  }
1823
1212
  }
1824
1213
  /**
@@ -1850,23 +1239,19 @@ function registerSlashCommandRoute(api) {
1850
1239
  }
1851
1240
  const dispatchRoute = async (req, res, onRequestAuthenticated) => {
1852
1241
  if (accountStates.size === 0) {
1853
- res.statusCode = 503;
1854
- res.setHeader("Content-Type", "application/json; charset=utf-8");
1855
- res.end(JSON.stringify({
1242
+ sendSlashCommandResponse(res, 503, {
1856
1243
  response_type: "ephemeral",
1857
1244
  text: "Slash commands are not yet initialized. Please try again in a moment."
1858
- }));
1245
+ });
1859
1246
  return;
1860
1247
  }
1861
1248
  if (accountStates.size === 1) {
1862
1249
  const state = accountStates.values().next().value;
1863
1250
  if (!state?.handler) {
1864
- res.statusCode = 503;
1865
- res.setHeader("Content-Type", "application/json; charset=utf-8");
1866
- res.end(JSON.stringify({
1251
+ sendSlashCommandResponse(res, 503, {
1867
1252
  response_type: "ephemeral",
1868
1253
  text: "Slash commands are not yet initialized. Please try again in a moment."
1869
- }));
1254
+ });
1870
1255
  return;
1871
1256
  }
1872
1257
  await state.handler(req, res, void 0, onRequestAuthenticated);
@@ -1893,7 +1278,7 @@ function registerSlashCommandRoute(api) {
1893
1278
  if (ct.includes("application/json")) token = JSON.parse(bodyStr).token ?? null;
1894
1279
  else token = new URLSearchParams(bodyStr).get("token");
1895
1280
  } catch {}
1896
- let match = token ? resolveSlashHandlerForToken(token) : { kind: "none" };
1281
+ let match = token ? resolveSlashHandler("token", (state) => state.commandTokens.has(token)) : { kind: "none" };
1897
1282
  if (match.kind === "none") {
1898
1283
  const payload = parseSlashCommandPayload(bodyStr, ct);
1899
1284
  if (payload) match = resolveSlashHandlerForCommand({
@@ -1902,23 +1287,18 @@ function registerSlashCommandRoute(api) {
1902
1287
  });
1903
1288
  }
1904
1289
  if (match.kind === "none") {
1905
- res.statusCode = 401;
1906
- res.setHeader("Content-Type", "application/json; charset=utf-8");
1907
- res.end(JSON.stringify({
1290
+ sendSlashCommandResponse(res, 401, {
1908
1291
  response_type: "ephemeral",
1909
1292
  text: "Unauthorized: invalid command token."
1910
- }));
1293
+ });
1911
1294
  return;
1912
1295
  }
1913
1296
  if (match.kind === "ambiguous") {
1914
1297
  api.logger.warn?.(`mattermost: slash callback matched multiple accounts via ${match.source} (${match.accountIds.join(", ")})`);
1915
- const conflictText = match.source === "token" ? "Conflict: command token is not unique across accounts." : "Conflict: slash command is not unique across accounts.";
1916
- res.statusCode = 409;
1917
- res.setHeader("Content-Type", "application/json; charset=utf-8");
1918
- res.end(JSON.stringify({
1298
+ sendSlashCommandResponse(res, 409, {
1919
1299
  response_type: "ephemeral",
1920
- text: conflictText
1921
- }));
1300
+ text: match.source === "token" ? "Conflict: command token is not unique across accounts." : "Conflict: slash command is not unique across accounts."
1301
+ });
1922
1302
  return;
1923
1303
  }
1924
1304
  await match.handler(req, res, bodyStr, onRequestAuthenticated);
@@ -1948,4 +1328,4 @@ function registerSlashCommandRoute(api) {
1948
1328
  });
1949
1329
  }
1950
1330
  //#endregion
1951
- export { registerSlashCommands as _, sendMessageMattermost as a, joinMattermostVisibleContent as c, renderMattermostModelsPickerView as d, renderMattermostProviderPickerView as f, isSlashCommandsEnabled as g, cleanupSlashCommands as h, registerSlashCommandRoute as i, buildMattermostAllowedModelRefs as l, DEFAULT_COMMAND_SPECS as m, deactivateSlashCommands as n, resolveMattermostOpaqueTarget as o, resolveMattermostModelPickerCurrentModel as p, getSlashCommandState as r, deliverMattermostReplyPayload as s, activateSlashCommands as t, parseMattermostModelPickerContext as u, resolveCallbackUrl as v, resolveSlashCommandConfig as y };
1331
+ export { resolveSlashCommandConfig as _, deliverMattermostReplyPayload as a, parseMattermostModelPickerContext as c, resolveMattermostModelPickerCurrentModel as d, DEFAULT_COMMAND_SPECS as f, resolveCallbackUrl as g, registerSlashCommands as h, registerSlashCommandRoute as i, renderMattermostModelsPickerView as l, isSlashCommandsEnabled as m, deactivateSlashCommands as n, joinMattermostVisibleContent as o, cleanupSlashCommands as p, getSlashCommandState as r, buildMattermostAllowedModelRefs as s, activateSlashCommands as t, renderMattermostProviderPickerView as u };