@openclaw/discord 2026.10.10 → 2026.11.5-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. package/dist/.setup/{account-inspect-X_Xlr42B.mjs → account-inspect-CSz5Qodj.mjs} +1 -1
  2. package/dist/.setup/{accounts-C18HNgge.mjs → accounts-DtjvhJUj.mjs} +9 -6
  3. package/dist/.setup/{active-turn-thread-route-BAc_Xik-.mjs → active-turn-thread-route-DkPnk2x8.mjs} +1 -2
  4. package/dist/.setup/{allow-list-D1ZGfhXh.mjs → allow-list-DahA0Jxh.mjs} +3 -150
  5. package/dist/.setup/{api-Bth1wKF9.mjs → api-Bp0HI4q3.mjs} +10 -20
  6. package/dist/.setup/{approval-handler.runtime-BAoEELJJ.mjs → approval-handler.runtime-Cy53ugTf.mjs} +80 -61
  7. package/dist/.setup/{approval-message-updates-Cks-MSCJ.mjs → approval-message-updates-DqOXxPss.mjs} +2 -2
  8. package/dist/.setup/{audit-Dw_rAZIz.mjs → audit-DoPKOfQE.mjs} +4 -4
  9. package/dist/.setup/{channel-BMpMAeQL.mjs → channel-Ds6iuNdy.mjs} +134 -201
  10. package/dist/.setup/channel-access-DhJhVrdZ.mjs +23 -0
  11. package/dist/.setup/channel.setup-BLt9dkIG.mjs +235 -0
  12. package/dist/.setup/{components-BvOWSPxr.mjs → components-WTfUxead.mjs} +208 -426
  13. package/dist/.setup/components.base-C5sAPHe4.mjs +31 -0
  14. package/dist/.setup/{config-schema-Coyq5wOr.mjs → config-schema-GX2yDgIH.mjs} +6 -7
  15. package/dist/.setup/{conversation-binding-route-DOPUZNYo.mjs → conversation-binding-route-CZdm-X5A.mjs} +2 -2
  16. package/dist/.setup/{directory-config-CIqVnQtn.mjs → directory-config-BXJuh9-J.mjs} +1 -1
  17. package/dist/.setup/{directory-live-DUuPEWub.mjs → directory-live-CEopeb8Q.mjs} +55 -62
  18. package/dist/.setup/{discord-eFlHX1Gn.mjs → discord-r79VFjJp.mjs} +1087 -1664
  19. package/dist/.setup/{doctor-Dty_Ossy.mjs → doctor-UfLW8nye.mjs} +3 -5
  20. package/dist/.setup/endpoint-runtime-BM3x-m6O.mjs +138 -0
  21. package/dist/.setup/guilds-DQucP5Tn.mjs +21 -0
  22. package/dist/.setup/{handle-action-DXY91jF-.mjs → handle-action-BarHOi-v.mjs} +15 -15
  23. package/dist/.setup/{handle-action.guild-admin-BvBCfhXF.mjs → handle-action.guild-admin-oRUb8p_O.mjs} +5 -5
  24. package/dist/.setup/listeners-CHgTENFu.mjs +46 -0
  25. package/dist/.setup/{live-policy-config-DO1Fk2hp.mjs → live-policy-config-EKp4O6zx.mjs} +2 -3
  26. package/dist/.setup/{message-handler-fL1j1NiR.mjs → message-handler-DUeT8Asf.mjs} +154 -113
  27. package/dist/.setup/{message-handler.preflight-DkjwNZAd.mjs → message-handler.preflight-C6TNtKW0.mjs} +30 -104
  28. package/dist/.setup/{message-handler.preflight-pluralkit-DR4BnvMU.mjs → message-handler.preflight-pluralkit-6E9TFmmN.mjs} +9 -22
  29. package/dist/.setup/{message-handler.process-ClOwIPDK.mjs → message-handler.process-D8_oQ5Cp.mjs} +256 -367
  30. package/dist/.setup/outbound-payload-DUsrFICb.mjs +445 -0
  31. package/dist/.setup/{outbound-session-route-TFBPPkoz.mjs → outbound-session-route-Cb8cv4Oi.mjs} +138 -86
  32. package/dist/.setup/{preflight-audio-CwtPIsvk.mjs → preflight-audio-r4BbaJxh.mjs} +1 -5
  33. package/dist/.setup/{presence-cache-CgutE4NN.mjs → presence-cache-B3xj3b0l.mjs} +1 -6
  34. package/dist/.setup/{probe-DNge7OEP.mjs → probe-BUmJyH35.mjs} +5 -9
  35. package/dist/.setup/{provider-BBDuE14w.mjs → provider-Dm2ERSxe.mjs} +3600 -4454
  36. package/dist/.setup/{provider-session.runtime-D8hMXXqJ.mjs → provider-session.runtime-DCIqDsIg.mjs} +3 -3
  37. package/dist/.setup/provider.runtime-DmxPGoUg.mjs +1 -0
  38. package/dist/.setup/proxy-fetch-B8cK6FLQ.mjs +29 -0
  39. package/dist/.setup/{realtime-session.runtime-cetognkp.mjs → realtime-session.runtime-WJL6NdwK.mjs} +43 -81
  40. package/dist/.setup/{receive-recovery-C77CVdGM.mjs → receive-recovery-DV_v5ROf.mjs} +13 -27
  41. package/dist/.setup/{resolve-allowlist-common-CI77288n.mjs → resolve-allowlist-common-C37fgnYG.mjs} +3 -12
  42. package/dist/.setup/{resolve-channels-DYc6-xgV.mjs → resolve-channels-CwpnQ7C2.mjs} +5 -4
  43. package/dist/.setup/{resolve-users-BQT7XWF2.mjs → resolve-users-D6jSwe8R.mjs} +4 -7
  44. package/dist/.setup/{runtime-CcijhTJT.mjs → runtime-B-PgPsGR.mjs} +6 -6
  45. package/dist/.setup/{runtime-CI0UJqeS.mjs → runtime-DhOMlnYS.mjs} +196 -235
  46. package/dist/.setup/{secret-config-contract-BdbCvqnM.mjs → secret-config-contract-CP6teHec.mjs} +4 -9
  47. package/dist/.setup/{send-Cbq-IVsS.mjs → send-DnLL6XoO.mjs} +149 -174
  48. package/dist/.setup/{send.components-BV6ucNpJ.mjs → send.components-xB43CksK.mjs} +61 -71
  49. package/dist/.setup/{send.outbound-CGhBhzjQ.mjs → send.outbound-B11X6TOE.mjs} +75 -129
  50. package/dist/.setup/{send.receipt-Dw-_r5Bx.mjs → send.receipt-CMteCIZS.mjs} +29 -31
  51. package/dist/.setup/{send.shared-D4MioxW_.mjs → send.shared-BcLLZBul.mjs} +38 -112
  52. package/dist/.setup/{sender-identity-DrN5c4ec.mjs → sender-identity-CGNpdJmb.mjs} +3 -9
  53. package/dist/.setup/setup-plugin-api-C6AMx3hu.mjs +2 -0
  54. package/dist/.setup/{shared-Bp0sxD5R.mjs → shared-BEYw16he.mjs} +8 -10
  55. package/dist/.setup/shared-interactive-DKBw4SNV.mjs +311 -0
  56. package/dist/.setup/{subagent-hooks-mQbDkvuD.mjs → subagent-hooks-DlYElpXa.mjs} +1 -1
  57. package/dist/.setup/{system-events-2zc2eGfF.mjs → system-events--Pk6y9aP.mjs} +2 -2
  58. package/dist/.setup/{target-resolver-CAHeVfmZ.mjs → target-resolver-Bo9EpGp_.mjs} +3 -3
  59. package/dist/.setup/{thread-bindings-Dg7X_ZXP.mjs → thread-bindings-BF-hr-bg.mjs} +12 -20
  60. package/dist/.setup/{thread-bindings.manager-DCDYksah.mjs → thread-bindings.manager-CQCkha5r.mjs} +22 -42
  61. package/dist/.setup/{thread-bindings.session-updates-C76plLS3.mjs → thread-bindings.session-updates-C2gJAj_I.mjs} +11 -18
  62. package/dist/.setup/{threading-l0UfrE6x.mjs → threading-HA9C2wYR.mjs} +68 -104
  63. package/dist/.setup/{timeouts-DTrUsJ_W.mjs → timeouts-CT9hnmo4.mjs} +1 -1
  64. package/dist/.setup/{transcripts-source-CGgOaWcu.mjs → transcripts-source-DzpzETZR.mjs} +102 -172
  65. package/dist/.setup/{voice-runtime-DY1EwDfi.mjs → voice-runtime-Bo_nsVvX.mjs} +231 -448
  66. package/dist/.source-module-urls/d6c089460280c5a04184542d6712e04545caeb1ebb290d3504377b4cc5e22fea.json +1 -1
  67. package/dist/account-inspect-api.js +1 -1
  68. package/dist/action-runtime-api.js +1 -1
  69. package/dist/activities-api.js +285 -337
  70. package/dist/api.js +16 -16
  71. package/dist/assets/embedded-app-sdk.mjs +1 -1
  72. package/dist/channel-config-api.js +1 -1
  73. package/dist/channel-plugin-api.js +1 -1
  74. package/dist/directory-contract-api.js +1 -1
  75. package/dist/runtime-api.js +22 -22
  76. package/dist/secret-contract-api.js +1 -1
  77. package/dist/setup-entry.js +1 -1
  78. package/dist/setup-plugin-api.js +1 -1
  79. package/dist/src/voice/audio-worker.runtime.js +56 -68
  80. package/dist/subagent-hooks-api.js +1 -1
  81. package/dist/transcripts-source-api.js +1 -1
  82. package/node_modules/@discord/embedded-app-sdk/output/lib/zod/lib/index.cjs +2 -3
  83. package/node_modules/@discord/embedded-app-sdk/output/lib/zod/lib/index.mjs +2 -3
  84. package/node_modules/@napi-rs/wasm-runtime/dist/fs.js +3339 -4021
  85. package/node_modules/@napi-rs/wasm-runtime/package.json +1 -1
  86. package/node_modules/@types/lodash/README.md +1 -1
  87. package/node_modules/@types/lodash/common/function.d.ts +2 -2
  88. package/node_modules/@types/lodash/package.json +2 -2
  89. package/node_modules/@types/node/README.md +1 -1
  90. package/node_modules/@types/node/package.json +2 -2
  91. package/node_modules/@types/node/util.d.ts +6 -3
  92. package/node_modules/discord-api-types/package.json +4 -4
  93. package/node_modules/discord-api-types/rest/v10/index.d.ts +8 -0
  94. package/node_modules/discord-api-types/rest/v10/index.d.ts.map +1 -1
  95. package/node_modules/discord-api-types/rest/v10/index.js +8 -0
  96. package/node_modules/discord-api-types/rest/v10/index.js.map +1 -1
  97. package/node_modules/discord-api-types/rest/v10/oauth2.d.ts +26 -2
  98. package/node_modules/discord-api-types/rest/v10/oauth2.d.ts.map +1 -1
  99. package/node_modules/discord-api-types/rest/v9/index.d.ts +8 -0
  100. package/node_modules/discord-api-types/rest/v9/index.d.ts.map +1 -1
  101. package/node_modules/discord-api-types/rest/v9/index.js +8 -0
  102. package/node_modules/discord-api-types/rest/v9/index.js.map +1 -1
  103. package/node_modules/discord-api-types/rest/v9/oauth2.d.ts +26 -2
  104. package/node_modules/discord-api-types/rest/v9/oauth2.d.ts.map +1 -1
  105. package/node_modules/typebox/build/format/duration.d.mts +2 -2
  106. package/node_modules/typebox/build/format/duration.mjs +2 -2
  107. package/node_modules/typebox/build/format/idn_email.d.mts +1 -0
  108. package/node_modules/typebox/build/format/idn_email.mjs +1 -0
  109. package/node_modules/typebox/build/format/idn_hostname.d.mts +1 -1
  110. package/node_modules/typebox/build/format/idn_hostname.mjs +1 -1
  111. package/node_modules/typebox/build/format/ipv4.d.mts +2 -2
  112. package/node_modules/typebox/build/format/ipv4.mjs +2 -2
  113. package/node_modules/typebox/build/format/ipv6.d.mts +1 -1
  114. package/node_modules/typebox/build/format/ipv6.mjs +1 -1
  115. package/node_modules/typebox/build/format/relative_json_pointer.d.mts +2 -2
  116. package/node_modules/typebox/build/format/relative_json_pointer.mjs +2 -2
  117. package/node_modules/typebox/build/schema/build.mjs +1 -0
  118. package/node_modules/typebox/build/schema/engine/_unique.d.mts +4 -2
  119. package/node_modules/typebox/build/schema/engine/_unique.mjs +7 -3
  120. package/node_modules/typebox/build/schema/engine/additionalItems.mjs +3 -3
  121. package/node_modules/typebox/build/schema/engine/additionalProperties.d.mts +0 -3
  122. package/node_modules/typebox/build/schema/engine/additionalProperties.mjs +15 -17
  123. package/node_modules/typebox/build/schema/engine/contains.mjs +3 -3
  124. package/node_modules/typebox/build/schema/engine/index.d.mts +1 -0
  125. package/node_modules/typebox/build/schema/engine/index.mjs +1 -0
  126. package/node_modules/typebox/build/schema/engine/items.mjs +7 -4
  127. package/node_modules/typebox/build/schema/engine/maxContains.mjs +2 -2
  128. package/node_modules/typebox/build/schema/engine/minContains.mjs +3 -3
  129. package/node_modules/typebox/build/schema/engine/oneOf.mjs +2 -2
  130. package/node_modules/typebox/build/schema/engine/patternProperties.mjs +2 -2
  131. package/node_modules/typebox/build/schema/engine/propertyNames.mjs +2 -2
  132. package/node_modules/typebox/build/schema/engine/unevaluatedItems.mjs +2 -2
  133. package/node_modules/typebox/build/schema/engine/unevaluatedProperties.mjs +2 -2
  134. package/node_modules/typebox/build/system/hashing/hash.mjs +63 -34
  135. package/node_modules/typebox/build/system/locale/en_US.mjs +2 -1
  136. package/node_modules/typebox/build/system/memory/assign.d.mts +2 -8
  137. package/node_modules/typebox/build/system/memory/assign.mjs +13 -6
  138. package/node_modules/typebox/build/system/memory/clone.d.mts +4 -5
  139. package/node_modules/typebox/build/system/memory/clone.mjs +8 -96
  140. package/node_modules/typebox/build/system/memory/create.d.mts +1 -5
  141. package/node_modules/typebox/build/system/memory/create.mjs +18 -13
  142. package/node_modules/typebox/build/system/memory/deep.d.mts +2 -0
  143. package/node_modules/typebox/build/system/memory/deep.mjs +108 -0
  144. package/node_modules/typebox/build/system/memory/discard.d.mts +1 -1
  145. package/node_modules/typebox/build/system/memory/discard.mjs +9 -8
  146. package/node_modules/typebox/build/system/memory/finalize.d.mts +4 -0
  147. package/node_modules/typebox/build/system/memory/finalize.mjs +30 -0
  148. package/node_modules/typebox/build/system/memory/keys.d.mts +2 -0
  149. package/node_modules/typebox/build/system/memory/keys.mjs +8 -0
  150. package/node_modules/typebox/build/system/memory/update.d.mts +1 -4
  151. package/node_modules/typebox/build/system/memory/update.mjs +43 -16
  152. package/node_modules/typebox/build/type/engine/call/index.d.mts +1 -0
  153. package/node_modules/typebox/build/type/engine/call/index.mjs +1 -0
  154. package/node_modules/typebox/build/type/engine/evaluate/composite.d.mts +2 -24
  155. package/node_modules/typebox/build/type/engine/evaluate/composite.mjs +2 -29
  156. package/node_modules/typebox/build/type/engine/evaluate/index.d.mts +1 -0
  157. package/node_modules/typebox/build/type/engine/evaluate/index.mjs +1 -0
  158. package/node_modules/typebox/build/type/engine/evaluate/narrow.d.mts +5 -1
  159. package/node_modules/typebox/build/type/engine/evaluate/narrow.mjs +6 -1
  160. package/node_modules/typebox/build/type/engine/evaluate/property.d.mts +30 -0
  161. package/node_modules/typebox/build/type/engine/evaluate/property.mjs +29 -0
  162. package/node_modules/typebox/build/type/engine/immutable/instantiate_add.d.mts +1 -3
  163. package/node_modules/typebox/build/type/engine/immutable/instantiate_add.mjs +1 -4
  164. package/node_modules/typebox/build/type/engine/object/from_intersect.d.mts +2 -2
  165. package/node_modules/typebox/build/type/engine/object/from_intersect.mjs +2 -2
  166. package/node_modules/typebox/build/type/engine/object/from_union.d.mts +2 -2
  167. package/node_modules/typebox/build/type/engine/object/from_union.mjs +2 -2
  168. package/node_modules/typebox/build/type/engine/optional/instantiate_add.d.mts +1 -3
  169. package/node_modules/typebox/build/type/engine/optional/instantiate_add.mjs +1 -4
  170. package/node_modules/typebox/build/type/engine/readonly/instantiate_add.d.mts +1 -3
  171. package/node_modules/typebox/build/type/engine/readonly/instantiate_add.mjs +1 -4
  172. package/node_modules/typebox/build/type/engine/this/index.d.mts +1 -0
  173. package/node_modules/typebox/build/type/engine/this/index.mjs +1 -0
  174. package/node_modules/typebox/build/value/clone/clone.d.mts +4 -3
  175. package/node_modules/typebox/build/value/clone/clone.mjs +5 -7
  176. package/node_modules/typebox/build/value/repair/from_cyclic.d.mts +2 -0
  177. package/node_modules/typebox/build/value/repair/from_cyclic.mjs +6 -0
  178. package/node_modules/typebox/build/value/shared/union_priority_sort.mjs +25 -14
  179. package/node_modules/typebox/package.json +1 -1
  180. package/node_modules/typebox/readme.md +1 -1
  181. package/node_modules/undici/docs/docs/api/Interceptors.md +15 -2
  182. package/node_modules/undici/lib/dispatcher/client-h2.js +78 -3
  183. package/node_modules/undici/lib/dispatcher/pool-base.js +20 -3
  184. package/node_modules/undici/package.json +3 -3
  185. package/node_modules/undici/types/api.d.ts +1 -1
  186. package/node_modules/undici/types/utility.d.ts +4 -4
  187. package/node_modules/uuid/package.json +17 -17
  188. package/node_modules/zod/package.json +1 -1
  189. package/node_modules/zod/src/v4/classic/tests/array.test.ts +27 -0
  190. package/node_modules/zod/src/v4/classic/tests/map.test.ts +7 -0
  191. package/node_modules/zod/src/v4/classic/tests/set.test.ts +6 -0
  192. package/node_modules/zod/src/v4/core/compile.ts +9 -0
  193. package/node_modules/zod/src/v4/core/schemas.ts +35 -1
  194. package/node_modules/zod/src/v4/core/util.ts +13 -0
  195. package/node_modules/zod/src/v4/core/versions.ts +1 -1
  196. package/node_modules/zod/v4/core/compile.cjs +8 -0
  197. package/node_modules/zod/v4/core/compile.js +8 -0
  198. package/node_modules/zod/v4/core/schemas.cjs +30 -0
  199. package/node_modules/zod/v4/core/schemas.d.cts +3 -1
  200. package/node_modules/zod/v4/core/schemas.d.ts +3 -1
  201. package/node_modules/zod/v4/core/schemas.js +30 -0
  202. package/node_modules/zod/v4/core/util.cjs +15 -0
  203. package/node_modules/zod/v4/core/util.d.cts +2 -0
  204. package/node_modules/zod/v4/core/util.d.ts +2 -0
  205. package/node_modules/zod/v4/core/util.js +14 -0
  206. package/node_modules/zod/v4/core/versions.cjs +1 -1
  207. package/node_modules/zod/v4/core/versions.js +1 -1
  208. package/openclaw.plugin.json +1 -31
  209. package/package.json +8 -8
  210. package/dist/.setup/channel-access-BPrWoEXM.mjs +0 -47
  211. package/dist/.setup/channel.setup-DVe7Y3Jf.mjs +0 -245
  212. package/dist/.setup/outbound-adapter-DWyAWBFh.mjs +0 -537
  213. package/dist/.setup/provider.runtime-BQ1z4Aq1.mjs +0 -1
  214. package/dist/.setup/setup-plugin-api-B4J6wmL1.mjs +0 -2
  215. package/dist/.setup/targets-BaklhOqq.mjs +0 -3
  216. package/node_modules/typebox/build/system/memory/freeze.d.mts +0 -4
  217. package/node_modules/typebox/build/system/memory/freeze.mjs +0 -6
@@ -1,121 +1,18 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-nwUcYXjP.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-eFlHX1Gn.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-r79VFjJp.mjs";
3
+ import { i as parseCustomId, r as colorToNumber, t as BaseMessageInteractiveComponent } from "./components.base-C5sAPHe4.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-DKBw4SNV.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
- // 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
- // extensions/discord/src/component-custom-id.ts
40
- const DISCORD_COMPONENT_CUSTOM_ID_KEY = "occomp";
41
- const DISCORD_MODAL_CUSTOM_ID_KEY = "ocmodal";
42
- const DISCORD_ACTIVITY_CUSTOM_ID_KEY = "ocactivity";
43
- const ENCODED_CUSTOM_ID_VERSION = "1";
44
- const DISCORD_ACTIVITY_CUSTOM_ID_PREFIX = `${DISCORD_ACTIVITY_CUSTOM_ID_KEY}${ENCODED_CUSTOM_ID_VERSION}_`;
45
- function isValidDiscordActivityWidgetId(widgetId) {
46
- return /^[A-Za-z0-9_-]{22}$/.test(widgetId);
47
- }
48
- function buildDiscordActivityCustomId(widgetId) {
49
- return `${DISCORD_ACTIVITY_CUSTOM_ID_PREFIX}${widgetId}`;
50
- }
51
- function parseDiscordActivityCustomId(id) {
52
- if (id.startsWith(DISCORD_ACTIVITY_CUSTOM_ID_PREFIX)) {
53
- const widgetId = id.slice(DISCORD_ACTIVITY_CUSTOM_ID_PREFIX.length);
54
- return isValidDiscordActivityWidgetId(widgetId) ? { widgetId } : null;
55
- }
56
- const parsed = parseCustomId(id);
57
- 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;
58
- return { widgetId: parsed.data.wid };
59
- }
60
- function parseDiscordActivityCustomIdForInteraction(id) {
61
- const parsed = parseDiscordActivityCustomId(id);
62
- return parsed ? {
63
- key: DISCORD_ACTIVITY_CUSTOM_ID_KEY,
64
- data: { widgetId: parsed.widgetId }
65
- } : parseCustomId(id);
66
- }
67
- function decodeParsedCustomIdData(data) {
68
- if (data.e !== ENCODED_CUSTOM_ID_VERSION) return data;
69
- return Object.fromEntries(Object.entries(data).map(([key, value]) => [key, typeof value === "string" ? unescapeCustomIdFieldValue(value) : value]));
70
- }
71
- function buildDiscordFieldCustomId(key, fields) {
72
- const encoded = Object.values(fields).some(needsCustomIdFieldEscaping);
73
- const parts = Object.entries(fields).map(([name, value]) => `${name}=${encoded ? escapeCustomIdFieldValue(value) : value}`);
74
- return (encoded ? `${key}:e=${ENCODED_CUSTOM_ID_VERSION};` : `${key}:`) + parts.join(";");
75
- }
76
- function buildDiscordComponentCustomId(params) {
77
- return buildDiscordFieldCustomId(DISCORD_COMPONENT_CUSTOM_ID_KEY, {
78
- cid: params.componentId,
79
- ...params.modalId ? { mid: params.modalId } : {}
80
- });
81
- }
82
- function buildDiscordModalCustomId(modalId) {
83
- return buildDiscordFieldCustomId(DISCORD_MODAL_CUSTOM_ID_KEY, { mid: modalId });
84
- }
85
- function parseDiscordComponentCustomId(id) {
86
- const parsed = parseCustomId(id);
87
- if (parsed.key !== "occomp") return null;
88
- const data = decodeParsedCustomIdData(parsed.data);
89
- const componentId = readNonBlankString(data.cid);
90
- if (!componentId) return null;
91
- return {
92
- componentId,
93
- modalId: readNonBlankString(data.mid)
94
- };
95
- }
96
- function parseDiscordModalCustomId(id) {
97
- const parsed = parseCustomId(id);
98
- if (parsed.key !== "ocmodal") return null;
99
- return readNonBlankString(decodeParsedCustomIdData(parsed.data).mid) ?? null;
100
- }
101
- function parseDiscordCustomIdForInteraction(id, key) {
102
- if (id === "*" || /^__openclaw_discord_component_[a-z_]+_wildcard__$/.test(id)) return {
103
- key: "*",
104
- data: {}
105
- };
106
- const parsed = parseCustomId(id);
107
- if (parsed.key !== key) return parsed;
108
- return {
109
- key: "*",
110
- data: decodeParsedCustomIdData(parsed.data)
111
- };
112
- }
113
- function parseDiscordComponentCustomIdForInteraction(id) {
114
- return parseDiscordCustomIdForInteraction(id, DISCORD_COMPONENT_CUSTOM_ID_KEY);
115
- }
116
- function parseDiscordModalCustomIdForInteraction(id) {
117
- return parseDiscordCustomIdForInteraction(id, DISCORD_MODAL_CUSTOM_ID_KEY);
118
- }
8
+ // extensions/discord/src/components.types.ts
9
+ const DISCORD_COMPONENT_SELECT_TYPES = [
10
+ "string",
11
+ "user",
12
+ "role",
13
+ "mentionable",
14
+ "channel"
15
+ ];
119
16
  // extensions/discord/src/components.parse.ts
120
17
  const DISCORD_COMPONENT_ATTACHMENT_PREFIX = "attachment://";
121
18
  const BLOCK_ALIASES = /* @__PURE__ */ new Map([["row", "actions"], ["action-row", "actions"]]);
@@ -227,13 +124,7 @@ function parseButtonSpec(raw, label) {
227
124
  function parseSelectSpec(raw, label) {
228
125
  const obj = requireObject(raw, label);
229
126
  return {
230
- type: readOptionalEnum(obj.type, `${label}.type`, [
231
- "string",
232
- "user",
233
- "role",
234
- "mentionable",
235
- "channel"
236
- ]),
127
+ type: readOptionalEnum(obj.type, `${label}.type`, DISCORD_COMPONENT_SELECT_TYPES),
237
128
  callbackData: normalizeOptionalString(obj.callbackData),
238
129
  callbackDataKind: readCallbackDataKind(obj.callbackDataKind, `${label}.callbackDataKind`),
239
130
  placeholder: normalizeOptionalString(obj.placeholder),
@@ -419,82 +310,35 @@ function readDiscordComponentSpec(raw) {
419
310
  function createShortId(prefix) {
420
311
  return `${prefix}${crypto.randomBytes(6).toString("base64url")}`;
421
312
  }
422
- const selectMenuConstructors = {
423
- string: class extends StringSelectMenu {
424
- constructor(..._args) {
425
- super(..._args);
426
- this.customId = "";
427
- this.options = [];
428
- }
429
- },
430
- user: class extends UserSelectMenu {
431
- constructor(..._args2) {
432
- super(..._args2);
433
- this.customId = "";
434
- }
435
- },
436
- role: class extends RoleSelectMenu {
437
- constructor(..._args3) {
438
- super(..._args3);
439
- this.customId = "";
440
- }
441
- },
442
- mentionable: class extends MentionableSelectMenu {
443
- constructor(..._args4) {
444
- super(..._args4);
445
- this.customId = "";
446
- }
447
- },
448
- channel: class extends ChannelSelectMenu {
449
- constructor(..._args5) {
450
- super(..._args5);
451
- this.customId = "";
452
- }
453
- }
454
- };
455
- function createDiscordSelectMenu(type, customId, options) {
456
- const SelectMenu = selectMenuConstructors[type];
457
- const select = new SelectMenu();
458
- select.customId = customId;
459
- if (select instanceof StringSelectMenu) select.options = options ?? [];
460
- return select;
461
- }
462
313
  function createButtonComponent(params) {
463
314
  const style = mapButtonStyle(params.spec.style);
464
- if (style === ButtonStyle.Link || Boolean(params.spec.url)) {
315
+ if (style === ButtonStyle.Link || params.spec.url) {
465
316
  if (!params.spec.url) throw new Error("Link buttons require a url");
466
- const linkUrl = params.spec.url;
467
- class DynamicLinkButton extends LinkButton {
468
- constructor(..._args6) {
469
- super(..._args6);
470
- this.label = params.spec.label;
471
- this.url = linkUrl;
472
- this.emoji = params.spec.emoji;
473
- this.disabled = params.spec.disabled ?? false;
474
- }
475
- }
476
- return { component: new DynamicLinkButton() };
317
+ return { component: stripUndefinedFields({
318
+ type: ComponentType.Button,
319
+ style: ButtonStyle.Link,
320
+ label: params.spec.label,
321
+ url: params.spec.url,
322
+ emoji: params.spec.emoji,
323
+ disabled: params.spec.disabled || void 0
324
+ }) };
477
325
  }
478
326
  const componentId = createShortId("btn_");
479
- const internalCustomId = typeof params.spec.internalCustomId === "string" && params.spec.internalCustomId.trim() ? params.spec.internalCustomId.trim() : void 0;
327
+ const internalCustomId = params.spec.internalCustomId?.trim() || void 0;
480
328
  const customId = internalCustomId ?? buildDiscordComponentCustomId({
481
329
  componentId,
482
330
  modalId: params.modalId
483
331
  });
484
- class DynamicButton extends Button {
485
- constructor(..._args7) {
486
- super(..._args7);
487
- this.label = params.spec.label;
488
- this.customId = customId;
489
- this.style = style;
490
- this.emoji = params.spec.emoji;
491
- this.disabled = params.spec.disabled ?? false;
492
- }
493
- }
494
- if (internalCustomId) return { component: new DynamicButton() };
495
332
  return {
496
- component: new DynamicButton(),
497
- entry: stripUndefinedFields({
333
+ component: stripUndefinedFields({
334
+ type: ComponentType.Button,
335
+ style,
336
+ label: params.spec.label,
337
+ custom_id: customId,
338
+ emoji: params.spec.emoji,
339
+ disabled: params.spec.disabled || void 0
340
+ }),
341
+ entry: internalCustomId ? void 0 : stripUndefinedFields({
498
342
  id: componentId,
499
343
  kind: params.modalId ? "modal-trigger" : "button",
500
344
  label: params.spec.label,
@@ -506,39 +350,6 @@ function createButtonComponent(params) {
506
350
  })
507
351
  };
508
352
  }
509
- function createSelectComponent(params) {
510
- const type = normalizeLowercaseStringOrEmpty(params.spec.type ?? "string");
511
- const componentId = createShortId("sel_");
512
- const customId = buildDiscordComponentCustomId({ componentId });
513
- const options = params.spec.options ?? [];
514
- if (type === "string" && options.length === 0) throw new Error("String select menus require options");
515
- const select = createDiscordSelectMenu(type, customId, options);
516
- select.minValues = params.spec.minValues;
517
- select.maxValues = params.spec.maxValues;
518
- select.placeholder = params.spec.placeholder;
519
- return {
520
- component: select,
521
- entry: stripUndefinedFields({
522
- id: componentId,
523
- kind: "select",
524
- label: params.spec.placeholder ?? {
525
- string: "select",
526
- user: "user select",
527
- role: "role select",
528
- mentionable: "mentionable select",
529
- channel: "channel select"
530
- }[type],
531
- callbackData: params.spec.callbackData,
532
- callbackDataKind: params.spec.callbackDataKind,
533
- selectType: type,
534
- options: type === "string" ? options.map((option) => ({
535
- value: option.value,
536
- label: option.label
537
- })) : void 0,
538
- allowedUsers: params.spec.allowedUsers
539
- })
540
- };
541
- }
542
353
  function buildDiscordComponentMessage(params) {
543
354
  const entries = [];
544
355
  const consumptionGroupId = createShortId("grp_");
@@ -562,34 +373,62 @@ function buildDiscordComponentMessage(params) {
562
373
  return component;
563
374
  };
564
375
  const text = params.spec.text ?? params.fallbackText;
565
- if (text) containerChildren.push(new TextDisplay(text));
376
+ if (text) containerChildren.push({
377
+ type: ComponentType.TextDisplay,
378
+ content: text
379
+ });
566
380
  for (const block of params.spec.blocks ?? []) {
567
381
  if (block.type === "text") {
568
- containerChildren.push(new TextDisplay(block.text));
382
+ containerChildren.push({
383
+ type: ComponentType.TextDisplay,
384
+ content: block.text
385
+ });
569
386
  continue;
570
387
  }
571
388
  if (block.type === "section") {
572
- const displays = (block.texts?.length ? block.texts : block.text ? [block.text] : []).map((entry) => new TextDisplay(entry));
389
+ const displays = (block.texts?.length ? block.texts : block.text ? [block.text] : []).map((content) => ({
390
+ type: ComponentType.TextDisplay,
391
+ content
392
+ }));
573
393
  if (displays.length > 3) throw new Error("Section blocks support up to 3 text displays");
574
394
  let accessory;
575
- if (block.accessory?.type === "thumbnail") accessory = new Thumbnail(block.accessory.url);
395
+ if (block.accessory?.type === "thumbnail") accessory = {
396
+ type: ComponentType.Thumbnail,
397
+ media: { url: block.accessory.url }
398
+ };
576
399
  else if (block.accessory?.type === "button") accessory = buildButton({ spec: block.accessory.button });
577
- containerChildren.push(new Section(displays, accessory));
400
+ containerChildren.push(stripUndefinedFields({
401
+ type: ComponentType.Section,
402
+ components: displays,
403
+ accessory
404
+ }));
578
405
  continue;
579
406
  }
580
407
  if (block.type === "separator") {
581
- containerChildren.push(new Separator({
582
- spacing: block.spacing,
583
- divider: block.divider
584
- }));
408
+ containerChildren.push({
409
+ type: ComponentType.Separator,
410
+ spacing: block.spacing === "large" || block.spacing === 2 ? 2 : 1,
411
+ divider: block.divider ?? true
412
+ });
585
413
  continue;
586
414
  }
587
415
  if (block.type === "media-gallery") {
588
- containerChildren.push(new MediaGallery(block.items));
416
+ containerChildren.push({
417
+ type: ComponentType.MediaGallery,
418
+ items: block.items.map(({ url, description, spoiler }) => ({
419
+ media: { url },
420
+ description,
421
+ spoiler
422
+ }))
423
+ });
589
424
  continue;
590
425
  }
591
426
  if (block.type === "file") {
592
- containerChildren.push(new File(block.file, block.spoiler));
427
+ containerChildren.push(stripUndefinedFields({
428
+ type: ComponentType.File,
429
+ file: { url: block.file },
430
+ spoiler: block.spoiler || void 0
431
+ }));
593
432
  continue;
594
433
  }
595
434
  if (block.type === "actions") {
@@ -598,11 +437,57 @@ function buildDiscordComponentMessage(params) {
598
437
  if (block.buttons.length > 5) throw new Error("Action rows support up to 5 buttons");
599
438
  for (const button of block.buttons) buildButton({ spec: button }, rowComponents);
600
439
  } else if (block.select) {
601
- const { component, entry } = createSelectComponent({ spec: block.select });
602
- rowComponents.push(component);
440
+ const selectSpec = block.select;
441
+ const type = selectSpec.type ?? "string";
442
+ const componentId = createShortId("sel_");
443
+ const customId = buildDiscordComponentCustomId({ componentId });
444
+ const options = selectSpec.options ?? [];
445
+ if (type === "string" && options.length === 0) throw new Error("String select menus require options");
446
+ const fields = stripUndefinedFields({
447
+ custom_id: customId,
448
+ min_values: selectSpec.minValues,
449
+ max_values: selectSpec.maxValues,
450
+ placeholder: selectSpec.placeholder
451
+ });
452
+ const select = type === "string" ? {
453
+ ...fields,
454
+ type: ComponentType.StringSelect,
455
+ options
456
+ } : {
457
+ ...fields,
458
+ type: {
459
+ user: ComponentType.UserSelect,
460
+ role: ComponentType.RoleSelect,
461
+ mentionable: ComponentType.MentionableSelect,
462
+ channel: ComponentType.ChannelSelect
463
+ }[type]
464
+ };
465
+ const entry = stripUndefinedFields({
466
+ id: componentId,
467
+ kind: "select",
468
+ label: selectSpec.placeholder ?? {
469
+ string: "select",
470
+ user: "user select",
471
+ role: "role select",
472
+ mentionable: "mentionable select",
473
+ channel: "channel select"
474
+ }[type],
475
+ callbackData: selectSpec.callbackData,
476
+ callbackDataKind: selectSpec.callbackDataKind,
477
+ selectType: type,
478
+ options: type === "string" ? options.map((option) => ({
479
+ value: option.value,
480
+ label: option.label
481
+ })) : void 0,
482
+ allowedUsers: selectSpec.allowedUsers
483
+ });
484
+ rowComponents.push(select);
603
485
  addEntry(entry);
604
486
  }
605
- containerChildren.push(new Row(rowComponents));
487
+ containerChildren.push({
488
+ type: ComponentType.ActionRow,
489
+ components: rowComponents
490
+ });
606
491
  }
607
492
  }
608
493
  if (params.spec.modal) {
@@ -642,11 +527,19 @@ function buildDiscordComponentMessage(params) {
642
527
  modalId
643
528
  });
644
529
  const lastChild = containerChildren.at(-1);
645
- if (lastChild instanceof Row && lastChild.components.length < 5 && !lastChild.components.some((child) => child instanceof AnySelectMenu)) lastChild.addComponent(component);
646
- else containerChildren.push(new Row([component]));
530
+ if (lastChild?.type === ComponentType.ActionRow && lastChild.components.length < 5 && lastChild.components.every((child) => child.type === ComponentType.Button)) lastChild.components.push(component);
531
+ else containerChildren.push({
532
+ type: ComponentType.ActionRow,
533
+ components: [component]
534
+ });
647
535
  }
648
536
  if (containerChildren.length === 0) throw new Error("components must include at least one block, text, or modal trigger");
649
- const container = new Container(containerChildren, params.spec.container);
537
+ const container = asSerializableComponent(stripUndefinedFields({
538
+ type: ComponentType.Container,
539
+ components: containerChildren,
540
+ accent_color: colorToNumber(params.spec.container?.accentColor),
541
+ spoiler: params.spec.container?.spoiler || void 0
542
+ }));
650
543
  const consumptionGroupEntryIds = entries.map((entry) => entry.id);
651
544
  for (const entry of entries) entry.consumptionGroupEntryIds = consumptionGroupEntryIds;
652
545
  return {
@@ -658,6 +551,59 @@ function buildDiscordComponentMessage(params) {
658
551
  function buildDiscordComponentMessageFlags(components) {
659
552
  return components.some((component) => component.isV2) ? MessageFlags.IsComponentsV2 : void 0;
660
553
  }
554
+ // extensions/discord/src/internal/components.message.ts
555
+ var AnySelectMenu = class extends BaseMessageInteractiveComponent {
556
+ constructor(..._args) {
557
+ super(..._args);
558
+ this.isV2 = false;
559
+ this.defer = false;
560
+ this.ephemeral = false;
561
+ this.customIdParser = parseCustomId;
562
+ this.disabled = false;
563
+ }
564
+ run(_interaction, _data) {}
565
+ serializeOptions() {
566
+ return {
567
+ type: this.type,
568
+ default_values: this.defaultValues
569
+ };
570
+ }
571
+ serialize() {
572
+ return stripUndefinedFields({
573
+ ...this.serializeOptions(),
574
+ custom_id: this.customId,
575
+ placeholder: this.placeholder,
576
+ min_values: this.minValues,
577
+ max_values: this.maxValues,
578
+ disabled: this.disabled || void 0,
579
+ required: this.required
580
+ });
581
+ }
582
+ };
583
+ var StringSelectMenu = class extends AnySelectMenu {
584
+ constructor(..._args2) {
585
+ super(..._args2);
586
+ this.type = ComponentType.StringSelect;
587
+ }
588
+ serializeOptions() {
589
+ return {
590
+ type: this.type,
591
+ options: this.options
592
+ };
593
+ }
594
+ };
595
+ var UserSelectMenu = class extends AnySelectMenu {
596
+ constructor(..._args3) {
597
+ super(..._args3);
598
+ this.type = ComponentType.UserSelect;
599
+ }
600
+ };
601
+ var RoleSelectMenu = class extends AnySelectMenu {
602
+ constructor(..._args4) {
603
+ super(..._args4);
604
+ this.type = ComponentType.RoleSelect;
605
+ }
606
+ };
661
607
  // extensions/discord/src/components.modal.ts
662
608
  function createModalFieldComponent(field) {
663
609
  if (field.type === "text") {
@@ -675,7 +621,23 @@ function createModalFieldComponent(field) {
675
621
  return new DynamicTextInput();
676
622
  }
677
623
  if (field.type === "select" || field.type === "role-select" || field.type === "user-select") {
678
- const select = createDiscordSelectMenu(field.type === "select" ? "string" : field.type === "role-select" ? "role" : "user", field.id, field.options);
624
+ const select = field.type === "select" ? new class extends StringSelectMenu {
625
+ constructor(..._args2) {
626
+ super(..._args2);
627
+ this.customId = field.id;
628
+ this.options = field.options ?? [];
629
+ }
630
+ }() : field.type === "role-select" ? new class extends RoleSelectMenu {
631
+ constructor(..._args3) {
632
+ super(..._args3);
633
+ this.customId = field.id;
634
+ }
635
+ }() : new class extends UserSelectMenu {
636
+ constructor(..._args4) {
637
+ super(..._args4);
638
+ this.customId = field.id;
639
+ }
640
+ }();
679
641
  select.required = field.required;
680
642
  select.minValues = field.minValues;
681
643
  select.maxValues = field.maxValues;
@@ -683,13 +645,13 @@ function createModalFieldComponent(field) {
683
645
  return select;
684
646
  }
685
647
  const group = field.type === "checkbox" ? new class extends CheckboxGroup {
686
- constructor(..._args2) {
687
- super(..._args2);
648
+ constructor(..._args5) {
649
+ super(..._args5);
688
650
  this.customId = field.id;
689
651
  }
690
652
  }() : new class extends RadioGroup {
691
- constructor(..._args3) {
692
- super(..._args3);
653
+ constructor(..._args6) {
654
+ super(..._args6);
693
655
  this.customId = field.id;
694
656
  }
695
657
  }();
@@ -710,8 +672,8 @@ var DiscordFormModal = class extends Modal {
710
672
  this.components = params.fields.map((field) => {
711
673
  const component = createModalFieldComponent(field);
712
674
  class DynamicLabel extends Label {
713
- constructor(..._args4) {
714
- super(..._args4);
675
+ constructor(..._args7) {
676
+ super(..._args7);
715
677
  this.label = field.label;
716
678
  this.description = field.description;
717
679
  this.customId = field.id;
@@ -731,186 +693,6 @@ function createDiscordFormModal(entry) {
731
693
  fields: entry.fields
732
694
  });
733
695
  }
734
- // extensions/discord/src/approval-custom-id.ts
735
- const DISCORD_APPROVAL_CUSTOM_ID_MAX_CHARS = 100;
736
- function encodeDiscordApprovalCustomId(action) {
737
- return `execapproval:kind=${action.approvalKind};id=${encodeURIComponent(action.approvalId)};action=${action.decision}`;
738
- }
739
- function encodeBoundedDiscordApprovalCustomId(action) {
740
- const exact = encodeDiscordApprovalCustomId(action);
741
- if (exact.length <= DISCORD_APPROVAL_CUSTOM_ID_MAX_CHARS) return exact;
742
- return encodeDiscordApprovalCustomId({
743
- ...action,
744
- approvalId: buildApprovalResolutionRef({
745
- approvalId: action.approvalId,
746
- approvalKind: action.approvalKind
747
- })
748
- });
749
- }
750
- function buildDiscordApprovalCustomId(action) {
751
- 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;
752
- return encodeBoundedDiscordApprovalCustomId(action);
753
- }
754
- function buildExecApprovalCustomId(approvalId, approvalKind, decision) {
755
- return encodeBoundedDiscordApprovalCustomId({
756
- type: "approval",
757
- approvalId,
758
- approvalKind,
759
- decision
760
- });
761
- }
762
- function parseExecApprovalData(data) {
763
- if (!data || typeof data !== "object") return null;
764
- const coerce = (value) => typeof value === "string" || typeof value === "number" ? String(value) : "";
765
- const rawId = coerce(data.id);
766
- const rawKind = coerce(data.kind);
767
- const rawAction = coerce(data.action);
768
- if (!rawId || rawKind !== "exec" && rawKind !== "plugin" && rawKind !== "system-agent") return null;
769
- if (rawAction !== "allow-once" && rawAction !== "allow-always" && rawAction !== "deny") return null;
770
- let approvalId;
771
- try {
772
- approvalId = decodeURIComponent(rawId);
773
- } catch {
774
- return null;
775
- }
776
- if (!approvalId) return null;
777
- return {
778
- approvalId,
779
- approvalKind: rawKind,
780
- action: rawAction
781
- };
782
- }
783
- // extensions/discord/src/question-custom-id.ts
784
- const QUESTION_RECORD_ID_PATTERN = /^ask_[a-f0-9]{32}$/u;
785
- function buildDiscordQuestionCustomId(callback) {
786
- if (!QUESTION_RECORD_ID_PATTERN.test(callback.questionId) || !Number.isInteger(callback.optionIndex) || callback.optionIndex < 0 || callback.optionIndex > 3) return;
787
- return `ocq:id=${callback.questionId};i=${callback.optionIndex}`;
788
- }
789
- function parseDiscordQuestionData(data) {
790
- const questionId = typeof data.id === "string" ? data.id : "";
791
- const rawIndex = typeof data.i === "string" ? data.i : typeof data.i === "number" ? String(data.i) : "";
792
- if (!QUESTION_RECORD_ID_PATTERN.test(questionId) || !/^[0-3]$/u.test(rawIndex)) return null;
793
- return {
794
- questionId,
795
- optionIndex: Number(rawIndex)
796
- };
797
- }
798
- // extensions/discord/src/shared-interactive.ts
799
- var shared_interactive_exports = /* @__PURE__ */ __exportAll({
800
- buildDiscordInteractiveComponents: () => buildDiscordInteractiveComponents,
801
- buildDiscordPresentationComponents: () => buildDiscordPresentationComponents
802
- });
803
- const DISCORD_INTERACTIVE_BUTTON_ROW_SIZE = 5;
804
- function buildDiscordButtonComponent(button, options) {
805
- const action = resolveMessagePresentationButtonAction(button);
806
- if (!action) return;
807
- const component = {
808
- label: button.label,
809
- style: button.style ?? "secondary",
810
- ...button.disabled === true ? { disabled: true } : {}
811
- };
812
- if (action.type === "approval") {
813
- const internalCustomId = buildDiscordApprovalCustomId(action);
814
- return internalCustomId ? {
815
- ...component,
816
- internalCustomId
817
- } : void 0;
818
- }
819
- if (action.type === "question") {
820
- if ("intent" in action) return;
821
- const optionIndex = resolveAskUserQuestionOptionIndex({
822
- questionOptionIndices: options.questionOptionIndices,
823
- questionId: action.questionId,
824
- optionValue: action.optionValue
825
- });
826
- if (optionIndex === void 0) return;
827
- const internalCustomId = buildDiscordQuestionCustomId({
828
- questionId: action.questionId,
829
- optionIndex
830
- });
831
- return internalCustomId ? {
832
- ...component,
833
- internalCustomId
834
- } : void 0;
835
- }
836
- if (action.type === "web-app" && action.widgetId && isValidDiscordActivityWidgetId(action.widgetId)) component.internalCustomId = buildDiscordActivityCustomId(action.widgetId);
837
- else if (action.type === "url" || action.type === "web-app") {
838
- if (action.type === "web-app" && !action.url) return;
839
- component.style = "link";
840
- component.url = action.url;
841
- } else {
842
- component.callbackData = action.type === "command" ? action.command : action.value;
843
- if (button.action?.type === "command" || button.action?.type === "callback") component.callbackDataKind = button.action.type;
844
- }
845
- if (button.reusable === true) component.reusable = true;
846
- return component;
847
- }
848
- function appendDiscordSelectBlock(blocks, block) {
849
- const options = [];
850
- let callbackDataKind;
851
- for (const option of block.options) {
852
- const value = resolveMessagePresentationActionValue(resolveMessagePresentationOptionAction(option));
853
- if (!value) continue;
854
- const kind = option.action?.type;
855
- if (kind !== void 0 && kind !== "command" && kind !== "callback" || options.length > 0 && callbackDataKind !== kind) return;
856
- callbackDataKind = kind;
857
- options.push({
858
- label: option.label,
859
- value
860
- });
861
- }
862
- if (options.length === 0) return;
863
- blocks.push({
864
- type: "actions",
865
- select: {
866
- type: "string",
867
- placeholder: block.placeholder,
868
- options,
869
- callbackDataKind
870
- }
871
- });
872
- }
873
- /**
874
- * @deprecated Use buildDiscordPresentationComponents with MessagePresentation.
875
- */
876
- function buildDiscordInteractiveComponents(interactive, options = {}) {
877
- return buildDiscordPresentationComponents(interactive ? legacyInteractiveReplyToPresentation(interactive) : void 0, options);
878
- }
879
- function buildDiscordPresentationComponents(presentation, options = {}) {
880
- if (!presentation) return;
881
- const blocks = [];
882
- if (presentation.title) blocks.push({
883
- type: "text",
884
- text: presentation.title
885
- });
886
- for (const block of presentation.blocks) {
887
- if (block.type === "text" || block.type === "context") {
888
- const text = block.text;
889
- if (text) blocks.push({
890
- type: "text",
891
- text: block.type === "context" ? `-# ${text}` : text
892
- });
893
- continue;
894
- }
895
- if (block.type === "divider") {
896
- blocks.push({ type: "separator" });
897
- continue;
898
- }
899
- if (block.type === "buttons") {
900
- const components = block.buttons.flatMap((button) => {
901
- const component = buildDiscordButtonComponent(button, options);
902
- return component ? [component] : [];
903
- });
904
- for (let index = 0; index < components.length; index += DISCORD_INTERACTIVE_BUTTON_ROW_SIZE) blocks.push({
905
- type: "actions",
906
- buttons: components.slice(index, index + DISCORD_INTERACTIVE_BUTTON_ROW_SIZE)
907
- });
908
- continue;
909
- }
910
- if (block.type === "select") appendDiscordSelectBlock(blocks, block);
911
- }
912
- return blocks.length ? { blocks } : void 0;
913
- }
914
696
  // extensions/discord/src/components.ts
915
697
  var components_exports = /* @__PURE__ */ __exportAll({
916
698
  DISCORD_COMPONENT_ATTACHMENT_PREFIX: () => DISCORD_COMPONENT_ATTACHMENT_PREFIX,
@@ -939,4 +721,4 @@ function formatDiscordComponentEventText(params) {
939
721
  if (values.length === 0) return `Updated "${params.label}".`;
940
722
  return `Selected ${values.join(", ")} from "${params.label}".`;
941
723
  }
942
- 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 };
724
+ 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 };