@openclaw/discord 2026.11.3 → 2026.11.5-beta.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 (220) hide show
  1. package/dist/.setup/{account-inspect-8cCu6uPG.mjs → account-inspect-DGkdWwix.mjs} +1 -1
  2. package/dist/.setup/{accounts-ljrzXBJi.mjs → accounts-C_25wyxC.mjs} +9 -6
  3. package/dist/.setup/{active-turn-thread-route-C4tp9noA.mjs → active-turn-thread-route-KvRTAVE3.mjs} +1 -2
  4. package/dist/.setup/{allow-list-BKqOldGy.mjs → allow-list-BXrS8-R9.mjs} +4 -152
  5. package/dist/.setup/{api-DqmMUZau.mjs → api-BlBD4ism.mjs} +10 -20
  6. package/dist/.setup/{approval-handler.runtime-D0qu1um7.mjs → approval-handler.runtime-BGYjX1t9.mjs} +80 -61
  7. package/dist/.setup/{approval-message-updates-CdurC9Ej.mjs → approval-message-updates-DKsCfxSW.mjs} +2 -2
  8. package/dist/.setup/{audit-ChorIwio.mjs → audit-5b-FXj9R.mjs} +4 -4
  9. package/dist/.setup/{channel-ZilgdF5e.mjs → channel-CWwTHWFo.mjs} +134 -202
  10. package/dist/.setup/channel-access-9cyzozUP.mjs +24 -0
  11. package/dist/.setup/channel.setup-B3MtmBQG.mjs +238 -0
  12. package/dist/.setup/{components-Du9NhD8h.mjs → components-YCvQ6YLS.mjs} +209 -430
  13. package/dist/.setup/components.base-CiS0h_XP.mjs +32 -0
  14. package/dist/.setup/{config-schema-_uBILpQf.mjs → config-schema-BNKN1cu5.mjs} +6 -7
  15. package/dist/.setup/{conversation-binding-route-8Ul1KpGF.mjs → conversation-binding-route-kCTw8cij.mjs} +2 -2
  16. package/dist/.setup/{directory-config-3iVub-3m.mjs → directory-config-Ble81PWH.mjs} +1 -1
  17. package/dist/.setup/{directory-live-BDVl2DoC.mjs → directory-live-DH3tpS3x.mjs} +52 -57
  18. package/dist/.setup/{discord-BMD-JiVS.mjs → discord-DGVSguhx.mjs} +1124 -1710
  19. package/dist/.setup/{doctor-hQKbkNKq.mjs → doctor-eujgbnpZ.mjs} +3 -5
  20. package/dist/.setup/endpoint-runtime-lf4DeLas.mjs +139 -0
  21. package/dist/.setup/guilds-eDq22iSM.mjs +22 -0
  22. package/dist/.setup/{handle-action-B1lmt4ms.mjs → handle-action-CktwmzMz.mjs} +15 -15
  23. package/dist/.setup/{handle-action.guild-admin-B6g31cwt.mjs → handle-action.guild-admin-WLQ7fRqI.mjs} +5 -5
  24. package/dist/.setup/listeners-Df8lx3vK.mjs +47 -0
  25. package/dist/.setup/{live-policy-config-C_Q966Wh.mjs → live-policy-config-DiBVuaU6.mjs} +2 -3
  26. package/dist/.setup/{message-handler-CkI3yMjL.mjs → message-handler-hhNSioxo.mjs} +154 -115
  27. package/dist/.setup/{message-handler.preflight-CEfkFV9U.mjs → message-handler.preflight-BZcZE1o-.mjs} +30 -105
  28. package/dist/.setup/{message-handler.preflight-pluralkit-D5si80_L.mjs → message-handler.preflight-pluralkit-CYZfXXb6.mjs} +9 -22
  29. package/dist/.setup/{message-handler.process-DsMtetRf.mjs → message-handler.process-B0n-mQ99.mjs} +256 -373
  30. package/dist/.setup/outbound-payload-BaZmjewa.mjs +447 -0
  31. package/dist/.setup/{outbound-session-route-BtUpGBTb.mjs → outbound-session-route-Cgx4i9cS.mjs} +139 -86
  32. package/dist/.setup/{preflight-audio-wWgsZG5F.mjs → preflight-audio-C6QtD6HX.mjs} +1 -5
  33. package/dist/.setup/{presence-cache-DCeTsL73.mjs → presence-cache-Dq-3nH7R.mjs} +1 -6
  34. package/dist/.setup/{probe-CBaoCs-c.mjs → probe-DezB-6xz.mjs} +5 -9
  35. package/dist/.setup/{provider-CI_OLfvz.mjs → provider-BN2bCIUp.mjs} +3440 -4308
  36. package/dist/.setup/{provider-session.runtime-TWOo_JZx.mjs → provider-session.runtime-Dr_5X43t.mjs} +3 -3
  37. package/dist/.setup/provider.runtime-BuJpl0Pv.mjs +1 -0
  38. package/dist/.setup/proxy-fetch-BzXwBAXt.mjs +30 -0
  39. package/dist/.setup/{realtime-session.runtime-DvfS4vJj.mjs → realtime-session.runtime-BTDWsV4d.mjs} +44 -81
  40. package/dist/.setup/{receive-recovery-CKvaG2Hf.mjs → receive-recovery-C3Ks4wAQ.mjs} +13 -27
  41. package/dist/.setup/{resolve-allowlist-common-cIjtqh2F.mjs → resolve-allowlist-common-Bk8Fj6Ik.mjs} +3 -13
  42. package/dist/.setup/{resolve-channels-Cj5i7hzj.mjs → resolve-channels-Bp8frXvc.mjs} +7 -8
  43. package/dist/.setup/{resolve-users-BQLbysRB.mjs → resolve-users-Cvcj22sG.mjs} +4 -7
  44. package/dist/.setup/{runtime-RWnuJgWB.mjs → runtime-BJaCvlmq.mjs} +196 -239
  45. package/dist/.setup/{runtime-plifsKg9.mjs → runtime-BMgTyuwg.mjs} +6 -6
  46. package/dist/.setup/{secret-config-contract-z6FhbT8E.mjs → secret-config-contract-B1kE4sDv.mjs} +4 -9
  47. package/dist/.setup/{send-da6ENJ9f.mjs → send-CVW7V-VZ.mjs} +149 -175
  48. package/dist/.setup/{send.components-CWZUuGvA.mjs → send.components-C8YXdnO_.mjs} +59 -71
  49. package/dist/.setup/{send.outbound-qZ3iK3Vq.mjs → send.outbound-Uzcmh3Yd.mjs} +76 -129
  50. package/dist/.setup/{send.receipt-C18khRYH.mjs → send.receipt-NZDOTZBU.mjs} +30 -32
  51. package/dist/.setup/{send.shared-CnlMgoqQ.mjs → send.shared-a_6Oeyg1.mjs} +38 -115
  52. package/dist/.setup/{sender-identity-DgbJykq0.mjs → sender-identity-76HFb8eK.mjs} +3 -9
  53. package/dist/.setup/setup-plugin-api-BExhGEhL.mjs +2 -0
  54. package/dist/.setup/shared-interactive-DmzaoKOM.mjs +316 -0
  55. package/dist/.setup/{shared-CY5vJM48.mjs → shared-yDUSExm2.mjs} +8 -11
  56. package/dist/.setup/{subagent-hooks-CIu2TFz3.mjs → subagent-hooks-CDkdHQyy.mjs} +1 -1
  57. package/dist/.setup/{system-events-DCOLXkwS.mjs → system-events-yfWz150v.mjs} +2 -2
  58. package/dist/.setup/{target-resolver-CApivu3G.mjs → target-resolver-BOOzqxxM.mjs} +3 -3
  59. package/dist/.setup/{thread-bindings-DcvT_JgI.mjs → thread-bindings-zce4cpu_.mjs} +12 -20
  60. package/dist/.setup/{thread-bindings.manager-5Sh7yedN.mjs → thread-bindings.manager-NywKzUtc.mjs} +22 -42
  61. package/dist/.setup/{thread-bindings.session-updates-BMdJeJMc.mjs → thread-bindings.session-updates-D0j7oh8S.mjs} +11 -18
  62. package/dist/.setup/{threading-CzjFeUSe.mjs → threading-DodLYDt-.mjs} +68 -105
  63. package/dist/.setup/{timeouts-CuNARfyw.mjs → timeouts-cIxzatmv.mjs} +1 -1
  64. package/dist/.setup/{transcripts-source-8RDQrSVb.mjs → transcripts-source-ie9GBWaU.mjs} +110 -179
  65. package/dist/.setup/{voice-runtime-BsDILmAv.mjs → voice-runtime-B7V_LTdX.mjs} +231 -452
  66. package/dist/.source-module-urls/d6c089460280c5a04184542d6712e04545caeb1ebb290d3504377b4cc5e22fea.json +1 -0
  67. package/dist/account-inspect-api.js +1 -1
  68. package/dist/action-runtime-api.js +1 -2
  69. package/dist/activities-api.js +286 -341
  70. package/dist/api.js +16 -16
  71. package/dist/channel-config-api.js +1 -2
  72. package/dist/channel-plugin-api.js +1 -2
  73. package/dist/contract-api.js +1 -2
  74. package/dist/directory-contract-api.js +1 -1
  75. package/dist/runtime-api.js +22 -22
  76. package/dist/runtime-setter-api.js +1 -2
  77. package/dist/secret-contract-api.js +1 -2
  78. package/dist/security-audit-contract-api.js +1 -2
  79. package/dist/security-contract-api.js +1 -2
  80. package/dist/session-key-api.js +1 -2
  81. package/dist/setup-entry.js +1 -1
  82. package/dist/setup-plugin-api.js +1 -2
  83. package/dist/src/voice/audio-worker.runtime.js +56 -68
  84. package/dist/subagent-hooks-api.js +1 -1
  85. package/dist/thread-binding-api.js +1 -2
  86. package/dist/transcripts-source-api.js +1 -1
  87. package/node_modules/@napi-rs/wasm-runtime/dist/fs.js +3339 -4021
  88. package/node_modules/@napi-rs/wasm-runtime/package.json +1 -1
  89. package/node_modules/@types/lodash/README.md +1 -1
  90. package/node_modules/@types/lodash/common/function.d.ts +2 -2
  91. package/node_modules/@types/lodash/package.json +2 -2
  92. package/node_modules/@types/node/README.md +1 -1
  93. package/node_modules/@types/node/package.json +2 -2
  94. package/node_modules/@types/node/util.d.ts +6 -3
  95. package/node_modules/discord-api-types/package.json +4 -4
  96. package/node_modules/discord-api-types/rest/v10/index.d.ts +8 -0
  97. package/node_modules/discord-api-types/rest/v10/index.d.ts.map +1 -1
  98. package/node_modules/discord-api-types/rest/v10/index.js +8 -0
  99. package/node_modules/discord-api-types/rest/v10/index.js.map +1 -1
  100. package/node_modules/discord-api-types/rest/v10/oauth2.d.ts +26 -2
  101. package/node_modules/discord-api-types/rest/v10/oauth2.d.ts.map +1 -1
  102. package/node_modules/discord-api-types/rest/v9/index.d.ts +8 -0
  103. package/node_modules/discord-api-types/rest/v9/index.d.ts.map +1 -1
  104. package/node_modules/discord-api-types/rest/v9/index.js +8 -0
  105. package/node_modules/discord-api-types/rest/v9/index.js.map +1 -1
  106. package/node_modules/discord-api-types/rest/v9/oauth2.d.ts +26 -2
  107. package/node_modules/discord-api-types/rest/v9/oauth2.d.ts.map +1 -1
  108. package/node_modules/typebox/build/format/duration.d.mts +2 -2
  109. package/node_modules/typebox/build/format/duration.mjs +2 -2
  110. package/node_modules/typebox/build/format/idn_email.d.mts +1 -0
  111. package/node_modules/typebox/build/format/idn_email.mjs +1 -0
  112. package/node_modules/typebox/build/format/idn_hostname.d.mts +1 -1
  113. package/node_modules/typebox/build/format/idn_hostname.mjs +1 -1
  114. package/node_modules/typebox/build/format/ipv4.d.mts +2 -2
  115. package/node_modules/typebox/build/format/ipv4.mjs +2 -2
  116. package/node_modules/typebox/build/format/ipv6.d.mts +1 -1
  117. package/node_modules/typebox/build/format/ipv6.mjs +1 -1
  118. package/node_modules/typebox/build/format/relative_json_pointer.d.mts +2 -2
  119. package/node_modules/typebox/build/format/relative_json_pointer.mjs +2 -2
  120. package/node_modules/typebox/build/schema/build.mjs +1 -0
  121. package/node_modules/typebox/build/schema/engine/_unique.d.mts +4 -2
  122. package/node_modules/typebox/build/schema/engine/_unique.mjs +7 -3
  123. package/node_modules/typebox/build/schema/engine/additionalItems.mjs +3 -3
  124. package/node_modules/typebox/build/schema/engine/additionalProperties.d.mts +0 -3
  125. package/node_modules/typebox/build/schema/engine/additionalProperties.mjs +15 -17
  126. package/node_modules/typebox/build/schema/engine/contains.mjs +3 -3
  127. package/node_modules/typebox/build/schema/engine/index.d.mts +1 -0
  128. package/node_modules/typebox/build/schema/engine/index.mjs +1 -0
  129. package/node_modules/typebox/build/schema/engine/items.mjs +7 -4
  130. package/node_modules/typebox/build/schema/engine/maxContains.mjs +2 -2
  131. package/node_modules/typebox/build/schema/engine/minContains.mjs +3 -3
  132. package/node_modules/typebox/build/schema/engine/oneOf.mjs +2 -2
  133. package/node_modules/typebox/build/schema/engine/patternProperties.mjs +2 -2
  134. package/node_modules/typebox/build/schema/engine/propertyNames.mjs +2 -2
  135. package/node_modules/typebox/build/schema/engine/unevaluatedItems.mjs +2 -2
  136. package/node_modules/typebox/build/schema/engine/unevaluatedProperties.mjs +2 -2
  137. package/node_modules/typebox/build/system/hashing/hash.mjs +63 -34
  138. package/node_modules/typebox/build/system/locale/en_US.mjs +2 -1
  139. package/node_modules/typebox/build/system/memory/assign.d.mts +2 -8
  140. package/node_modules/typebox/build/system/memory/assign.mjs +13 -6
  141. package/node_modules/typebox/build/system/memory/clone.d.mts +4 -5
  142. package/node_modules/typebox/build/system/memory/clone.mjs +8 -96
  143. package/node_modules/typebox/build/system/memory/create.d.mts +1 -5
  144. package/node_modules/typebox/build/system/memory/create.mjs +18 -13
  145. package/node_modules/typebox/build/system/memory/deep.d.mts +2 -0
  146. package/node_modules/typebox/build/system/memory/deep.mjs +108 -0
  147. package/node_modules/typebox/build/system/memory/discard.d.mts +1 -1
  148. package/node_modules/typebox/build/system/memory/discard.mjs +9 -8
  149. package/node_modules/typebox/build/system/memory/finalize.d.mts +4 -0
  150. package/node_modules/typebox/build/system/memory/finalize.mjs +30 -0
  151. package/node_modules/typebox/build/system/memory/keys.d.mts +2 -0
  152. package/node_modules/typebox/build/system/memory/keys.mjs +8 -0
  153. package/node_modules/typebox/build/system/memory/update.d.mts +1 -4
  154. package/node_modules/typebox/build/system/memory/update.mjs +43 -16
  155. package/node_modules/typebox/build/type/engine/call/index.d.mts +1 -0
  156. package/node_modules/typebox/build/type/engine/call/index.mjs +1 -0
  157. package/node_modules/typebox/build/type/engine/evaluate/composite.d.mts +2 -24
  158. package/node_modules/typebox/build/type/engine/evaluate/composite.mjs +2 -29
  159. package/node_modules/typebox/build/type/engine/evaluate/index.d.mts +1 -0
  160. package/node_modules/typebox/build/type/engine/evaluate/index.mjs +1 -0
  161. package/node_modules/typebox/build/type/engine/evaluate/narrow.d.mts +5 -1
  162. package/node_modules/typebox/build/type/engine/evaluate/narrow.mjs +6 -1
  163. package/node_modules/typebox/build/type/engine/evaluate/property.d.mts +30 -0
  164. package/node_modules/typebox/build/type/engine/evaluate/property.mjs +29 -0
  165. package/node_modules/typebox/build/type/engine/immutable/instantiate_add.d.mts +1 -3
  166. package/node_modules/typebox/build/type/engine/immutable/instantiate_add.mjs +1 -4
  167. package/node_modules/typebox/build/type/engine/object/from_intersect.d.mts +2 -2
  168. package/node_modules/typebox/build/type/engine/object/from_intersect.mjs +2 -2
  169. package/node_modules/typebox/build/type/engine/object/from_union.d.mts +2 -2
  170. package/node_modules/typebox/build/type/engine/object/from_union.mjs +2 -2
  171. package/node_modules/typebox/build/type/engine/optional/instantiate_add.d.mts +1 -3
  172. package/node_modules/typebox/build/type/engine/optional/instantiate_add.mjs +1 -4
  173. package/node_modules/typebox/build/type/engine/readonly/instantiate_add.d.mts +1 -3
  174. package/node_modules/typebox/build/type/engine/readonly/instantiate_add.mjs +1 -4
  175. package/node_modules/typebox/build/type/engine/this/index.d.mts +1 -0
  176. package/node_modules/typebox/build/type/engine/this/index.mjs +1 -0
  177. package/node_modules/typebox/build/value/clone/clone.d.mts +4 -3
  178. package/node_modules/typebox/build/value/clone/clone.mjs +5 -7
  179. package/node_modules/typebox/build/value/repair/from_cyclic.d.mts +2 -0
  180. package/node_modules/typebox/build/value/repair/from_cyclic.mjs +6 -0
  181. package/node_modules/typebox/build/value/shared/union_priority_sort.mjs +25 -14
  182. package/node_modules/typebox/package.json +1 -1
  183. package/node_modules/typebox/readme.md +1 -1
  184. package/node_modules/undici/docs/docs/api/Interceptors.md +15 -2
  185. package/node_modules/undici/lib/dispatcher/client-h2.js +78 -3
  186. package/node_modules/undici/lib/dispatcher/pool-base.js +20 -3
  187. package/node_modules/undici/package.json +3 -3
  188. package/node_modules/undici/types/api.d.ts +1 -1
  189. package/node_modules/undici/types/utility.d.ts +4 -4
  190. package/node_modules/uuid/package.json +17 -17
  191. package/node_modules/zod/package.json +1 -1
  192. package/node_modules/zod/src/v4/classic/tests/array.test.ts +27 -0
  193. package/node_modules/zod/src/v4/classic/tests/map.test.ts +7 -0
  194. package/node_modules/zod/src/v4/classic/tests/set.test.ts +6 -0
  195. package/node_modules/zod/src/v4/core/compile.ts +9 -0
  196. package/node_modules/zod/src/v4/core/schemas.ts +35 -1
  197. package/node_modules/zod/src/v4/core/util.ts +13 -0
  198. package/node_modules/zod/src/v4/core/versions.ts +1 -1
  199. package/node_modules/zod/v4/core/compile.cjs +8 -0
  200. package/node_modules/zod/v4/core/compile.js +8 -0
  201. package/node_modules/zod/v4/core/schemas.cjs +30 -0
  202. package/node_modules/zod/v4/core/schemas.d.cts +3 -1
  203. package/node_modules/zod/v4/core/schemas.d.ts +3 -1
  204. package/node_modules/zod/v4/core/schemas.js +30 -0
  205. package/node_modules/zod/v4/core/util.cjs +15 -0
  206. package/node_modules/zod/v4/core/util.d.cts +2 -0
  207. package/node_modules/zod/v4/core/util.d.ts +2 -0
  208. package/node_modules/zod/v4/core/util.js +14 -0
  209. package/node_modules/zod/v4/core/versions.cjs +1 -1
  210. package/node_modules/zod/v4/core/versions.js +1 -1
  211. package/openclaw.plugin.json +1 -31
  212. package/package.json +8 -8
  213. package/dist/.setup/channel-access-DasWY_OV.mjs +0 -48
  214. package/dist/.setup/channel.setup-DaDQdctj.mjs +0 -249
  215. package/dist/.setup/outbound-adapter-DfAanoCO.mjs +0 -543
  216. package/dist/.setup/provider.runtime-DnionCyo.mjs +0 -2
  217. package/dist/.setup/setup-plugin-api-D1QuM187.mjs +0 -3
  218. package/dist/.setup/targets-UWWZ6gF7.mjs +0 -3
  219. package/node_modules/typebox/build/system/memory/freeze.d.mts +0 -4
  220. package/node_modules/typebox/build/system/memory/freeze.mjs +0 -6
@@ -1,122 +1,18 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-B4FMCO8f.mjs";
2
- import { A as StringSelectMenu, C as LinkButton, D as Row, E as RoleSelectMenu, M as Thumbnail, N as UserSelectMenu, O as Section, S as File, T as MentionableSelectMenu, _ as TextInput, b as ChannelSelectMenu, g as RadioGroup, h as Modal, j as TextDisplay, k as Separator, m as Label, p as CheckboxGroup, tt as parseCustomId, v as AnySelectMenu, w as MediaGallery, x as Container, xt as stripUndefinedFields, y as Button } from "./discord-BMD-JiVS.mjs";
2
+ import { J as stripUndefinedFields, a as Label, c as TextInput, i as CheckboxGroup, o as Modal, s as RadioGroup, u as asSerializableComponent } from "./discord-DGVSguhx.mjs";
3
+ import { i as parseCustomId, r as colorToNumber, t as BaseMessageInteractiveComponent } from "./components.base-CiS0h_XP.mjs";
4
+ import { _ as parseDiscordModalCustomId, c as DISCORD_COMPONENT_CUSTOM_ID_KEY, d as buildDiscordComponentCustomId, f as buildDiscordModalCustomId, g as parseDiscordComponentCustomIdForInteraction, h as parseDiscordComponentCustomId, l as DISCORD_MODAL_CUSTOM_ID_KEY, t as buildDiscordInteractiveComponents, v as parseDiscordModalCustomIdForInteraction } from "./shared-interactive-DmzaoKOM.mjs";
3
5
  import { asBoolean, asOptionalRecord, normalizeLowercaseStringOrEmpty, normalizeOptionalString, readNonBlankString } from "openclaw/plugin-sdk/string-coerce-runtime";
4
- import { ButtonStyle, MessageFlags, TextInputStyle } from "discord-api-types/v10";
5
- import { resolveAskUserQuestionOptionIndex } from "openclaw/plugin-sdk/reply-payload";
6
+ import { ButtonStyle, ComponentType, MessageFlags, TextInputStyle } from "discord-api-types/v10";
6
7
  import crypto from "node:crypto";
7
- import { legacyInteractiveReplyToPresentation, resolveMessagePresentationActionValue, resolveMessagePresentationButtonAction, resolveMessagePresentationOptionAction } from "openclaw/plugin-sdk/interactive-runtime";
8
- import { buildApprovalResolutionRef } from "openclaw/plugin-sdk/approval-reference-runtime";
9
- //#region extensions/discord/src/custom-id-codec.ts
10
- /**
11
- * URI-component codec for values embedded in `k=v;` custom-id grammars
12
- * (exec approvals, model picker, command args, agent components).
13
- * Decode falls back to the raw value: Discord redelivers old component ids
14
- * indefinitely and historical values may predate strict encoding.
15
- */
16
- const encodeCustomIdComponent = encodeURIComponent;
17
- function decodeCustomIdComponent(value) {
18
- try {
19
- return decodeURIComponent(value);
20
- } catch {
21
- return value;
22
- }
23
- }
24
- /**
25
- * Minimal field escape for the versioned `occomp`/`ocmodal` grammar: only `%`
26
- * and the `;` field separator are escaped to preserve the 100-char custom-id
27
- * budget. The wire format is versioned (`e=1`); do not swap this for the URI
28
- * codec — in-flight component ids must keep decoding byte-exactly.
29
- */
30
- function escapeCustomIdFieldValue(value) {
31
- return value.replace(/%/g, "%25").replace(/;/g, "%3B");
32
- }
33
- function needsCustomIdFieldEscaping(value) {
34
- return /[%;]/.test(value);
35
- }
36
- function unescapeCustomIdFieldValue(value) {
37
- return value.replace(/%(25|3B)/gi, (match) => match.toLowerCase() === "%25" ? "%" : ";");
38
- }
39
- //#endregion
40
- //#region extensions/discord/src/component-custom-id.ts
41
- const DISCORD_COMPONENT_CUSTOM_ID_KEY = "occomp";
42
- const DISCORD_MODAL_CUSTOM_ID_KEY = "ocmodal";
43
- const DISCORD_ACTIVITY_CUSTOM_ID_KEY = "ocactivity";
44
- const ENCODED_CUSTOM_ID_VERSION = "1";
45
- const DISCORD_ACTIVITY_CUSTOM_ID_PREFIX = `${DISCORD_ACTIVITY_CUSTOM_ID_KEY}${ENCODED_CUSTOM_ID_VERSION}_`;
46
- function isValidDiscordActivityWidgetId(widgetId) {
47
- return /^[A-Za-z0-9_-]{22}$/.test(widgetId);
48
- }
49
- function buildDiscordActivityCustomId(widgetId) {
50
- return `${DISCORD_ACTIVITY_CUSTOM_ID_PREFIX}${widgetId}`;
51
- }
52
- function parseDiscordActivityCustomId(id) {
53
- if (id.startsWith(DISCORD_ACTIVITY_CUSTOM_ID_PREFIX)) {
54
- const widgetId = id.slice(DISCORD_ACTIVITY_CUSTOM_ID_PREFIX.length);
55
- return isValidDiscordActivityWidgetId(widgetId) ? { widgetId } : null;
56
- }
57
- const parsed = parseCustomId(id);
58
- if (parsed.key !== DISCORD_ACTIVITY_CUSTOM_ID_KEY || parsed.data.v !== ENCODED_CUSTOM_ID_VERSION || typeof parsed.data.wid !== "string" || !isValidDiscordActivityWidgetId(parsed.data.wid)) return null;
59
- return { widgetId: parsed.data.wid };
60
- }
61
- function parseDiscordActivityCustomIdForInteraction(id) {
62
- const parsed = parseDiscordActivityCustomId(id);
63
- return parsed ? {
64
- key: DISCORD_ACTIVITY_CUSTOM_ID_KEY,
65
- data: { widgetId: parsed.widgetId }
66
- } : parseCustomId(id);
67
- }
68
- function decodeParsedCustomIdData(data) {
69
- if (data.e !== ENCODED_CUSTOM_ID_VERSION) return data;
70
- return Object.fromEntries(Object.entries(data).map(([key, value]) => [key, typeof value === "string" ? unescapeCustomIdFieldValue(value) : value]));
71
- }
72
- function buildDiscordFieldCustomId(key, fields) {
73
- const encoded = Object.values(fields).some(needsCustomIdFieldEscaping);
74
- const parts = Object.entries(fields).map(([name, value]) => `${name}=${encoded ? escapeCustomIdFieldValue(value) : value}`);
75
- return (encoded ? `${key}:e=${ENCODED_CUSTOM_ID_VERSION};` : `${key}:`) + parts.join(";");
76
- }
77
- function buildDiscordComponentCustomId(params) {
78
- return buildDiscordFieldCustomId(DISCORD_COMPONENT_CUSTOM_ID_KEY, {
79
- cid: params.componentId,
80
- ...params.modalId ? { mid: params.modalId } : {}
81
- });
82
- }
83
- function buildDiscordModalCustomId(modalId) {
84
- return buildDiscordFieldCustomId(DISCORD_MODAL_CUSTOM_ID_KEY, { mid: modalId });
85
- }
86
- function parseDiscordComponentCustomId(id) {
87
- const parsed = parseCustomId(id);
88
- if (parsed.key !== "occomp") return null;
89
- const data = decodeParsedCustomIdData(parsed.data);
90
- const componentId = readNonBlankString(data.cid);
91
- if (!componentId) return null;
92
- return {
93
- componentId,
94
- modalId: readNonBlankString(data.mid)
95
- };
96
- }
97
- function parseDiscordModalCustomId(id) {
98
- const parsed = parseCustomId(id);
99
- if (parsed.key !== "ocmodal") return null;
100
- return readNonBlankString(decodeParsedCustomIdData(parsed.data).mid) ?? null;
101
- }
102
- function parseDiscordCustomIdForInteraction(id, key) {
103
- if (id === "*" || /^__openclaw_discord_component_[a-z_]+_wildcard__$/.test(id)) return {
104
- key: "*",
105
- data: {}
106
- };
107
- const parsed = parseCustomId(id);
108
- if (parsed.key !== key) return parsed;
109
- return {
110
- key: "*",
111
- data: decodeParsedCustomIdData(parsed.data)
112
- };
113
- }
114
- function parseDiscordComponentCustomIdForInteraction(id) {
115
- return parseDiscordCustomIdForInteraction(id, DISCORD_COMPONENT_CUSTOM_ID_KEY);
116
- }
117
- function parseDiscordModalCustomIdForInteraction(id) {
118
- return parseDiscordCustomIdForInteraction(id, DISCORD_MODAL_CUSTOM_ID_KEY);
119
- }
8
+ //#region extensions/discord/src/components.types.ts
9
+ const DISCORD_COMPONENT_SELECT_TYPES = [
10
+ "string",
11
+ "user",
12
+ "role",
13
+ "mentionable",
14
+ "channel"
15
+ ];
120
16
  //#endregion
121
17
  //#region extensions/discord/src/components.parse.ts
122
18
  const DISCORD_COMPONENT_ATTACHMENT_PREFIX = "attachment://";
@@ -229,13 +125,7 @@ function parseButtonSpec(raw, label) {
229
125
  function parseSelectSpec(raw, label) {
230
126
  const obj = requireObject(raw, label);
231
127
  return {
232
- type: readOptionalEnum(obj.type, `${label}.type`, [
233
- "string",
234
- "user",
235
- "role",
236
- "mentionable",
237
- "channel"
238
- ]),
128
+ type: readOptionalEnum(obj.type, `${label}.type`, DISCORD_COMPONENT_SELECT_TYPES),
239
129
  callbackData: normalizeOptionalString(obj.callbackData),
240
130
  callbackDataKind: readCallbackDataKind(obj.callbackDataKind, `${label}.callbackDataKind`),
241
131
  placeholder: normalizeOptionalString(obj.placeholder),
@@ -422,82 +312,35 @@ function readDiscordComponentSpec(raw) {
422
312
  function createShortId(prefix) {
423
313
  return `${prefix}${crypto.randomBytes(6).toString("base64url")}`;
424
314
  }
425
- const selectMenuConstructors = {
426
- string: class extends StringSelectMenu {
427
- constructor(..._args) {
428
- super(..._args);
429
- this.customId = "";
430
- this.options = [];
431
- }
432
- },
433
- user: class extends UserSelectMenu {
434
- constructor(..._args2) {
435
- super(..._args2);
436
- this.customId = "";
437
- }
438
- },
439
- role: class extends RoleSelectMenu {
440
- constructor(..._args3) {
441
- super(..._args3);
442
- this.customId = "";
443
- }
444
- },
445
- mentionable: class extends MentionableSelectMenu {
446
- constructor(..._args4) {
447
- super(..._args4);
448
- this.customId = "";
449
- }
450
- },
451
- channel: class extends ChannelSelectMenu {
452
- constructor(..._args5) {
453
- super(..._args5);
454
- this.customId = "";
455
- }
456
- }
457
- };
458
- function createDiscordSelectMenu(type, customId, options) {
459
- const SelectMenu = selectMenuConstructors[type];
460
- const select = new SelectMenu();
461
- select.customId = customId;
462
- if (select instanceof StringSelectMenu) select.options = options ?? [];
463
- return select;
464
- }
465
315
  function createButtonComponent(params) {
466
316
  const style = mapButtonStyle(params.spec.style);
467
- if (style === ButtonStyle.Link || Boolean(params.spec.url)) {
317
+ if (style === ButtonStyle.Link || params.spec.url) {
468
318
  if (!params.spec.url) throw new Error("Link buttons require a url");
469
- const linkUrl = params.spec.url;
470
- class DynamicLinkButton extends LinkButton {
471
- constructor(..._args6) {
472
- super(..._args6);
473
- this.label = params.spec.label;
474
- this.url = linkUrl;
475
- this.emoji = params.spec.emoji;
476
- this.disabled = params.spec.disabled ?? false;
477
- }
478
- }
479
- return { component: new DynamicLinkButton() };
319
+ return { component: stripUndefinedFields({
320
+ type: ComponentType.Button,
321
+ style: ButtonStyle.Link,
322
+ label: params.spec.label,
323
+ url: params.spec.url,
324
+ emoji: params.spec.emoji,
325
+ disabled: params.spec.disabled || void 0
326
+ }) };
480
327
  }
481
328
  const componentId = createShortId("btn_");
482
- const internalCustomId = typeof params.spec.internalCustomId === "string" && params.spec.internalCustomId.trim() ? params.spec.internalCustomId.trim() : void 0;
329
+ const internalCustomId = params.spec.internalCustomId?.trim() || void 0;
483
330
  const customId = internalCustomId ?? buildDiscordComponentCustomId({
484
331
  componentId,
485
332
  modalId: params.modalId
486
333
  });
487
- class DynamicButton extends Button {
488
- constructor(..._args7) {
489
- super(..._args7);
490
- this.label = params.spec.label;
491
- this.customId = customId;
492
- this.style = style;
493
- this.emoji = params.spec.emoji;
494
- this.disabled = params.spec.disabled ?? false;
495
- }
496
- }
497
- if (internalCustomId) return { component: new DynamicButton() };
498
334
  return {
499
- component: new DynamicButton(),
500
- entry: stripUndefinedFields({
335
+ component: stripUndefinedFields({
336
+ type: ComponentType.Button,
337
+ style,
338
+ label: params.spec.label,
339
+ custom_id: customId,
340
+ emoji: params.spec.emoji,
341
+ disabled: params.spec.disabled || void 0
342
+ }),
343
+ entry: internalCustomId ? void 0 : stripUndefinedFields({
501
344
  id: componentId,
502
345
  kind: params.modalId ? "modal-trigger" : "button",
503
346
  label: params.spec.label,
@@ -509,39 +352,6 @@ function createButtonComponent(params) {
509
352
  })
510
353
  };
511
354
  }
512
- function createSelectComponent(params) {
513
- const type = normalizeLowercaseStringOrEmpty(params.spec.type ?? "string");
514
- const componentId = createShortId("sel_");
515
- const customId = buildDiscordComponentCustomId({ componentId });
516
- const options = params.spec.options ?? [];
517
- if (type === "string" && options.length === 0) throw new Error("String select menus require options");
518
- const select = createDiscordSelectMenu(type, customId, options);
519
- select.minValues = params.spec.minValues;
520
- select.maxValues = params.spec.maxValues;
521
- select.placeholder = params.spec.placeholder;
522
- return {
523
- component: select,
524
- entry: stripUndefinedFields({
525
- id: componentId,
526
- kind: "select",
527
- label: params.spec.placeholder ?? {
528
- string: "select",
529
- user: "user select",
530
- role: "role select",
531
- mentionable: "mentionable select",
532
- channel: "channel select"
533
- }[type],
534
- callbackData: params.spec.callbackData,
535
- callbackDataKind: params.spec.callbackDataKind,
536
- selectType: type,
537
- options: type === "string" ? options.map((option) => ({
538
- value: option.value,
539
- label: option.label
540
- })) : void 0,
541
- allowedUsers: params.spec.allowedUsers
542
- })
543
- };
544
- }
545
355
  function buildDiscordComponentMessage(params) {
546
356
  const entries = [];
547
357
  const consumptionGroupId = createShortId("grp_");
@@ -565,34 +375,62 @@ function buildDiscordComponentMessage(params) {
565
375
  return component;
566
376
  };
567
377
  const text = params.spec.text ?? params.fallbackText;
568
- if (text) containerChildren.push(new TextDisplay(text));
378
+ if (text) containerChildren.push({
379
+ type: ComponentType.TextDisplay,
380
+ content: text
381
+ });
569
382
  for (const block of params.spec.blocks ?? []) {
570
383
  if (block.type === "text") {
571
- containerChildren.push(new TextDisplay(block.text));
384
+ containerChildren.push({
385
+ type: ComponentType.TextDisplay,
386
+ content: block.text
387
+ });
572
388
  continue;
573
389
  }
574
390
  if (block.type === "section") {
575
- const displays = (block.texts?.length ? block.texts : block.text ? [block.text] : []).map((entry) => new TextDisplay(entry));
391
+ const displays = (block.texts?.length ? block.texts : block.text ? [block.text] : []).map((content) => ({
392
+ type: ComponentType.TextDisplay,
393
+ content
394
+ }));
576
395
  if (displays.length > 3) throw new Error("Section blocks support up to 3 text displays");
577
396
  let accessory;
578
- if (block.accessory?.type === "thumbnail") accessory = new Thumbnail(block.accessory.url);
397
+ if (block.accessory?.type === "thumbnail") accessory = {
398
+ type: ComponentType.Thumbnail,
399
+ media: { url: block.accessory.url }
400
+ };
579
401
  else if (block.accessory?.type === "button") accessory = buildButton({ spec: block.accessory.button });
580
- containerChildren.push(new Section(displays, accessory));
402
+ containerChildren.push(stripUndefinedFields({
403
+ type: ComponentType.Section,
404
+ components: displays,
405
+ accessory
406
+ }));
581
407
  continue;
582
408
  }
583
409
  if (block.type === "separator") {
584
- containerChildren.push(new Separator({
585
- spacing: block.spacing,
586
- divider: block.divider
587
- }));
410
+ containerChildren.push({
411
+ type: ComponentType.Separator,
412
+ spacing: block.spacing === "large" || block.spacing === 2 ? 2 : 1,
413
+ divider: block.divider ?? true
414
+ });
588
415
  continue;
589
416
  }
590
417
  if (block.type === "media-gallery") {
591
- containerChildren.push(new MediaGallery(block.items));
418
+ containerChildren.push({
419
+ type: ComponentType.MediaGallery,
420
+ items: block.items.map(({ url, description, spoiler }) => ({
421
+ media: { url },
422
+ description,
423
+ spoiler
424
+ }))
425
+ });
592
426
  continue;
593
427
  }
594
428
  if (block.type === "file") {
595
- containerChildren.push(new File(block.file, block.spoiler));
429
+ containerChildren.push(stripUndefinedFields({
430
+ type: ComponentType.File,
431
+ file: { url: block.file },
432
+ spoiler: block.spoiler || void 0
433
+ }));
596
434
  continue;
597
435
  }
598
436
  if (block.type === "actions") {
@@ -601,11 +439,57 @@ function buildDiscordComponentMessage(params) {
601
439
  if (block.buttons.length > 5) throw new Error("Action rows support up to 5 buttons");
602
440
  for (const button of block.buttons) buildButton({ spec: button }, rowComponents);
603
441
  } else if (block.select) {
604
- const { component, entry } = createSelectComponent({ spec: block.select });
605
- rowComponents.push(component);
442
+ const selectSpec = block.select;
443
+ const type = selectSpec.type ?? "string";
444
+ const componentId = createShortId("sel_");
445
+ const customId = buildDiscordComponentCustomId({ componentId });
446
+ const options = selectSpec.options ?? [];
447
+ if (type === "string" && options.length === 0) throw new Error("String select menus require options");
448
+ const fields = stripUndefinedFields({
449
+ custom_id: customId,
450
+ min_values: selectSpec.minValues,
451
+ max_values: selectSpec.maxValues,
452
+ placeholder: selectSpec.placeholder
453
+ });
454
+ const select = type === "string" ? {
455
+ ...fields,
456
+ type: ComponentType.StringSelect,
457
+ options
458
+ } : {
459
+ ...fields,
460
+ type: {
461
+ user: ComponentType.UserSelect,
462
+ role: ComponentType.RoleSelect,
463
+ mentionable: ComponentType.MentionableSelect,
464
+ channel: ComponentType.ChannelSelect
465
+ }[type]
466
+ };
467
+ const entry = stripUndefinedFields({
468
+ id: componentId,
469
+ kind: "select",
470
+ label: selectSpec.placeholder ?? {
471
+ string: "select",
472
+ user: "user select",
473
+ role: "role select",
474
+ mentionable: "mentionable select",
475
+ channel: "channel select"
476
+ }[type],
477
+ callbackData: selectSpec.callbackData,
478
+ callbackDataKind: selectSpec.callbackDataKind,
479
+ selectType: type,
480
+ options: type === "string" ? options.map((option) => ({
481
+ value: option.value,
482
+ label: option.label
483
+ })) : void 0,
484
+ allowedUsers: selectSpec.allowedUsers
485
+ });
486
+ rowComponents.push(select);
606
487
  addEntry(entry);
607
488
  }
608
- containerChildren.push(new Row(rowComponents));
489
+ containerChildren.push({
490
+ type: ComponentType.ActionRow,
491
+ components: rowComponents
492
+ });
609
493
  }
610
494
  }
611
495
  if (params.spec.modal) {
@@ -645,11 +529,19 @@ function buildDiscordComponentMessage(params) {
645
529
  modalId
646
530
  });
647
531
  const lastChild = containerChildren.at(-1);
648
- if (lastChild instanceof Row && lastChild.components.length < 5 && !lastChild.components.some((child) => child instanceof AnySelectMenu)) lastChild.addComponent(component);
649
- else containerChildren.push(new Row([component]));
532
+ if (lastChild?.type === ComponentType.ActionRow && lastChild.components.length < 5 && lastChild.components.every((child) => child.type === ComponentType.Button)) lastChild.components.push(component);
533
+ else containerChildren.push({
534
+ type: ComponentType.ActionRow,
535
+ components: [component]
536
+ });
650
537
  }
651
538
  if (containerChildren.length === 0) throw new Error("components must include at least one block, text, or modal trigger");
652
- const container = new Container(containerChildren, params.spec.container);
539
+ const container = asSerializableComponent(stripUndefinedFields({
540
+ type: ComponentType.Container,
541
+ components: containerChildren,
542
+ accent_color: colorToNumber(params.spec.container?.accentColor),
543
+ spoiler: params.spec.container?.spoiler || void 0
544
+ }));
653
545
  const consumptionGroupEntryIds = entries.map((entry) => entry.id);
654
546
  for (const entry of entries) entry.consumptionGroupEntryIds = consumptionGroupEntryIds;
655
547
  return {
@@ -662,6 +554,60 @@ function buildDiscordComponentMessageFlags(components) {
662
554
  return components.some((component) => component.isV2) ? MessageFlags.IsComponentsV2 : void 0;
663
555
  }
664
556
  //#endregion
557
+ //#region extensions/discord/src/internal/components.message.ts
558
+ var AnySelectMenu = class extends BaseMessageInteractiveComponent {
559
+ constructor(..._args) {
560
+ super(..._args);
561
+ this.isV2 = false;
562
+ this.defer = false;
563
+ this.ephemeral = false;
564
+ this.customIdParser = parseCustomId;
565
+ this.disabled = false;
566
+ }
567
+ run(_interaction, _data) {}
568
+ serializeOptions() {
569
+ return {
570
+ type: this.type,
571
+ default_values: this.defaultValues
572
+ };
573
+ }
574
+ serialize() {
575
+ return stripUndefinedFields({
576
+ ...this.serializeOptions(),
577
+ custom_id: this.customId,
578
+ placeholder: this.placeholder,
579
+ min_values: this.minValues,
580
+ max_values: this.maxValues,
581
+ disabled: this.disabled || void 0,
582
+ required: this.required
583
+ });
584
+ }
585
+ };
586
+ var StringSelectMenu = class extends AnySelectMenu {
587
+ constructor(..._args2) {
588
+ super(..._args2);
589
+ this.type = ComponentType.StringSelect;
590
+ }
591
+ serializeOptions() {
592
+ return {
593
+ type: this.type,
594
+ options: this.options
595
+ };
596
+ }
597
+ };
598
+ var UserSelectMenu = class extends AnySelectMenu {
599
+ constructor(..._args3) {
600
+ super(..._args3);
601
+ this.type = ComponentType.UserSelect;
602
+ }
603
+ };
604
+ var RoleSelectMenu = class extends AnySelectMenu {
605
+ constructor(..._args4) {
606
+ super(..._args4);
607
+ this.type = ComponentType.RoleSelect;
608
+ }
609
+ };
610
+ //#endregion
665
611
  //#region extensions/discord/src/components.modal.ts
666
612
  function createModalFieldComponent(field) {
667
613
  if (field.type === "text") {
@@ -679,7 +625,23 @@ function createModalFieldComponent(field) {
679
625
  return new DynamicTextInput();
680
626
  }
681
627
  if (field.type === "select" || field.type === "role-select" || field.type === "user-select") {
682
- const select = createDiscordSelectMenu(field.type === "select" ? "string" : field.type === "role-select" ? "role" : "user", field.id, field.options);
628
+ const select = field.type === "select" ? new class extends StringSelectMenu {
629
+ constructor(..._args2) {
630
+ super(..._args2);
631
+ this.customId = field.id;
632
+ this.options = field.options ?? [];
633
+ }
634
+ }() : field.type === "role-select" ? new class extends RoleSelectMenu {
635
+ constructor(..._args3) {
636
+ super(..._args3);
637
+ this.customId = field.id;
638
+ }
639
+ }() : new class extends UserSelectMenu {
640
+ constructor(..._args4) {
641
+ super(..._args4);
642
+ this.customId = field.id;
643
+ }
644
+ }();
683
645
  select.required = field.required;
684
646
  select.minValues = field.minValues;
685
647
  select.maxValues = field.maxValues;
@@ -687,13 +649,13 @@ function createModalFieldComponent(field) {
687
649
  return select;
688
650
  }
689
651
  const group = field.type === "checkbox" ? new class extends CheckboxGroup {
690
- constructor(..._args2) {
691
- super(..._args2);
652
+ constructor(..._args5) {
653
+ super(..._args5);
692
654
  this.customId = field.id;
693
655
  }
694
656
  }() : new class extends RadioGroup {
695
- constructor(..._args3) {
696
- super(..._args3);
657
+ constructor(..._args6) {
658
+ super(..._args6);
697
659
  this.customId = field.id;
698
660
  }
699
661
  }();
@@ -714,8 +676,8 @@ var DiscordFormModal = class extends Modal {
714
676
  this.components = params.fields.map((field) => {
715
677
  const component = createModalFieldComponent(field);
716
678
  class DynamicLabel extends Label {
717
- constructor(..._args4) {
718
- super(..._args4);
679
+ constructor(..._args7) {
680
+ super(..._args7);
719
681
  this.label = field.label;
720
682
  this.description = field.description;
721
683
  this.customId = field.id;
@@ -736,189 +698,6 @@ function createDiscordFormModal(entry) {
736
698
  });
737
699
  }
738
700
  //#endregion
739
- //#region extensions/discord/src/approval-custom-id.ts
740
- const DISCORD_APPROVAL_CUSTOM_ID_MAX_CHARS = 100;
741
- function encodeDiscordApprovalCustomId(action) {
742
- return `execapproval:kind=${action.approvalKind};id=${encodeURIComponent(action.approvalId)};action=${action.decision}`;
743
- }
744
- function encodeBoundedDiscordApprovalCustomId(action) {
745
- const exact = encodeDiscordApprovalCustomId(action);
746
- if (exact.length <= DISCORD_APPROVAL_CUSTOM_ID_MAX_CHARS) return exact;
747
- return encodeDiscordApprovalCustomId({
748
- ...action,
749
- approvalId: buildApprovalResolutionRef({
750
- approvalId: action.approvalId,
751
- approvalKind: action.approvalKind
752
- })
753
- });
754
- }
755
- function buildDiscordApprovalCustomId(action) {
756
- if (!action.approvalId || action.approvalKind !== "exec" && action.approvalKind !== "plugin" && action.approvalKind !== "system-agent" || action.decision !== "allow-once" && action.decision !== "allow-always" && action.decision !== "deny") return;
757
- return encodeBoundedDiscordApprovalCustomId(action);
758
- }
759
- function buildExecApprovalCustomId(approvalId, approvalKind, decision) {
760
- return encodeBoundedDiscordApprovalCustomId({
761
- type: "approval",
762
- approvalId,
763
- approvalKind,
764
- decision
765
- });
766
- }
767
- function parseExecApprovalData(data) {
768
- if (!data || typeof data !== "object") return null;
769
- const coerce = (value) => typeof value === "string" || typeof value === "number" ? String(value) : "";
770
- const rawId = coerce(data.id);
771
- const rawKind = coerce(data.kind);
772
- const rawAction = coerce(data.action);
773
- if (!rawId || rawKind !== "exec" && rawKind !== "plugin" && rawKind !== "system-agent") return null;
774
- if (rawAction !== "allow-once" && rawAction !== "allow-always" && rawAction !== "deny") return null;
775
- let approvalId;
776
- try {
777
- approvalId = decodeURIComponent(rawId);
778
- } catch {
779
- return null;
780
- }
781
- if (!approvalId) return null;
782
- return {
783
- approvalId,
784
- approvalKind: rawKind,
785
- action: rawAction
786
- };
787
- }
788
- //#endregion
789
- //#region extensions/discord/src/question-custom-id.ts
790
- const QUESTION_RECORD_ID_PATTERN = /^ask_[a-f0-9]{32}$/u;
791
- function buildDiscordQuestionCustomId(callback) {
792
- if (!QUESTION_RECORD_ID_PATTERN.test(callback.questionId) || !Number.isInteger(callback.optionIndex) || callback.optionIndex < 0 || callback.optionIndex > 3) return;
793
- return `ocq:id=${callback.questionId};i=${callback.optionIndex}`;
794
- }
795
- function parseDiscordQuestionData(data) {
796
- const questionId = typeof data.id === "string" ? data.id : "";
797
- const rawIndex = typeof data.i === "string" ? data.i : typeof data.i === "number" ? String(data.i) : "";
798
- if (!QUESTION_RECORD_ID_PATTERN.test(questionId) || !/^[0-3]$/u.test(rawIndex)) return null;
799
- return {
800
- questionId,
801
- optionIndex: Number(rawIndex)
802
- };
803
- }
804
- //#endregion
805
- //#region extensions/discord/src/shared-interactive.ts
806
- var shared_interactive_exports = /* @__PURE__ */ __exportAll({
807
- buildDiscordInteractiveComponents: () => buildDiscordInteractiveComponents,
808
- buildDiscordPresentationComponents: () => buildDiscordPresentationComponents
809
- });
810
- const DISCORD_INTERACTIVE_BUTTON_ROW_SIZE = 5;
811
- function buildDiscordButtonComponent(button, options) {
812
- const action = resolveMessagePresentationButtonAction(button);
813
- if (!action) return;
814
- const component = {
815
- label: button.label,
816
- style: button.style ?? "secondary",
817
- ...button.disabled === true ? { disabled: true } : {}
818
- };
819
- if (action.type === "approval") {
820
- const internalCustomId = buildDiscordApprovalCustomId(action);
821
- return internalCustomId ? {
822
- ...component,
823
- internalCustomId
824
- } : void 0;
825
- }
826
- if (action.type === "question") {
827
- if ("intent" in action) return;
828
- const optionIndex = resolveAskUserQuestionOptionIndex({
829
- questionOptionIndices: options.questionOptionIndices,
830
- questionId: action.questionId,
831
- optionValue: action.optionValue
832
- });
833
- if (optionIndex === void 0) return;
834
- const internalCustomId = buildDiscordQuestionCustomId({
835
- questionId: action.questionId,
836
- optionIndex
837
- });
838
- return internalCustomId ? {
839
- ...component,
840
- internalCustomId
841
- } : void 0;
842
- }
843
- if (action.type === "web-app" && action.widgetId && isValidDiscordActivityWidgetId(action.widgetId)) component.internalCustomId = buildDiscordActivityCustomId(action.widgetId);
844
- else if (action.type === "url" || action.type === "web-app") {
845
- if (action.type === "web-app" && !action.url) return;
846
- component.style = "link";
847
- component.url = action.url;
848
- } else {
849
- component.callbackData = action.type === "command" ? action.command : action.value;
850
- if (button.action?.type === "command" || button.action?.type === "callback") component.callbackDataKind = button.action.type;
851
- }
852
- if (button.reusable === true) component.reusable = true;
853
- return component;
854
- }
855
- function appendDiscordSelectBlock(blocks, block) {
856
- const options = [];
857
- let callbackDataKind;
858
- for (const option of block.options) {
859
- const value = resolveMessagePresentationActionValue(resolveMessagePresentationOptionAction(option));
860
- if (!value) continue;
861
- const kind = option.action?.type;
862
- if (kind !== void 0 && kind !== "command" && kind !== "callback" || options.length > 0 && callbackDataKind !== kind) return;
863
- callbackDataKind = kind;
864
- options.push({
865
- label: option.label,
866
- value
867
- });
868
- }
869
- if (options.length === 0) return;
870
- blocks.push({
871
- type: "actions",
872
- select: {
873
- type: "string",
874
- placeholder: block.placeholder,
875
- options,
876
- callbackDataKind
877
- }
878
- });
879
- }
880
- /**
881
- * @deprecated Use buildDiscordPresentationComponents with MessagePresentation.
882
- */
883
- function buildDiscordInteractiveComponents(interactive, options = {}) {
884
- return buildDiscordPresentationComponents(interactive ? legacyInteractiveReplyToPresentation(interactive) : void 0, options);
885
- }
886
- function buildDiscordPresentationComponents(presentation, options = {}) {
887
- if (!presentation) return;
888
- const blocks = [];
889
- if (presentation.title) blocks.push({
890
- type: "text",
891
- text: presentation.title
892
- });
893
- for (const block of presentation.blocks) {
894
- if (block.type === "text" || block.type === "context") {
895
- const text = block.text;
896
- if (text) blocks.push({
897
- type: "text",
898
- text: block.type === "context" ? `-# ${text}` : text
899
- });
900
- continue;
901
- }
902
- if (block.type === "divider") {
903
- blocks.push({ type: "separator" });
904
- continue;
905
- }
906
- if (block.type === "buttons") {
907
- const components = block.buttons.flatMap((button) => {
908
- const component = buildDiscordButtonComponent(button, options);
909
- return component ? [component] : [];
910
- });
911
- for (let index = 0; index < components.length; index += DISCORD_INTERACTIVE_BUTTON_ROW_SIZE) blocks.push({
912
- type: "actions",
913
- buttons: components.slice(index, index + DISCORD_INTERACTIVE_BUTTON_ROW_SIZE)
914
- });
915
- continue;
916
- }
917
- if (block.type === "select") appendDiscordSelectBlock(blocks, block);
918
- }
919
- return blocks.length ? { blocks } : void 0;
920
- }
921
- //#endregion
922
701
  //#region extensions/discord/src/components.ts
923
702
  var components_exports = /* @__PURE__ */ __exportAll({
924
703
  DISCORD_COMPONENT_ATTACHMENT_PREFIX: () => DISCORD_COMPONENT_ATTACHMENT_PREFIX,
@@ -948,4 +727,4 @@ function formatDiscordComponentEventText(params) {
948
727
  return `Selected ${values.join(", ")} from "${params.label}".`;
949
728
  }
950
729
  //#endregion
951
- export { parseDiscordActivityCustomIdForInteraction as C, parseDiscordModalCustomIdForInteraction as D, parseDiscordModalCustomId as E, decodeCustomIdComponent as O, parseDiscordActivityCustomId as S, parseDiscordComponentCustomIdForInteraction as T, DISCORD_COMPONENT_CUSTOM_ID_KEY as _, shared_interactive_exports as a, buildDiscordComponentCustomId as b, parseExecApprovalData as c, buildDiscordComponentMessage as d, buildDiscordComponentMessageFlags as f, resolveDiscordComponentAttachmentName as g, readDiscordComponentSpec as h, buildDiscordPresentationComponents as i, encodeCustomIdComponent as k, DiscordFormModal as l, coerceDiscordComponentParam as m, formatDiscordComponentEventText as n, parseDiscordQuestionData as o, DISCORD_COMPONENT_ATTACHMENT_PREFIX as p, buildDiscordInteractiveComponents as r, buildExecApprovalCustomId as s, components_exports as t, createDiscordFormModal as u, DISCORD_MODAL_CUSTOM_ID_KEY as v, parseDiscordComponentCustomId as w, buildDiscordModalCustomId as x, buildDiscordActivityCustomId as y };
730
+ export { buildDiscordComponentMessage as a, coerceDiscordComponentParam as c, createDiscordFormModal as i, readDiscordComponentSpec as l, formatDiscordComponentEventText as n, buildDiscordComponentMessageFlags as o, DiscordFormModal as r, DISCORD_COMPONENT_ATTACHMENT_PREFIX as s, components_exports as t, resolveDiscordComponentAttachmentName as u };