@openclaw/discord 2026.9.5 → 2026.9.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (517) hide show
  1. package/assets/icon.png +0 -0
  2. package/dist/.setup/{account-inspect-BwQj24ht.mjs → account-inspect-De8hOUxG.mjs} +1 -1
  3. package/dist/.setup/{accounts-CwJQoLjM.mjs → accounts-ChaMcixG.mjs} +1 -4
  4. package/dist/.setup/{activities-api-DBwRt5ES.mjs → activities-api-tvbsU2e3.mjs} +38 -66
  5. package/dist/.setup/{api-CBK9zcq5.mjs → api-DVbJwZVt.mjs} +10 -2
  6. package/dist/.setup/{approval-handler.runtime-Du3n5ypX.mjs → approval-handler.runtime-DxCK2Rux.mjs} +49 -125
  7. package/dist/.setup/{approval-message-updates-BN7JtScm.mjs → approval-message-updates-BKFqavHZ.mjs} +2 -2
  8. package/dist/.setup/{audit-C8uaKoa9.mjs → audit-CLg9I71N.mjs} +5 -5
  9. package/dist/.setup/{channel-ChKdlBgH.mjs → channel-DxlUVU9t.mjs} +125 -228
  10. package/dist/.setup/{channel-type-DKnjV1XW.mjs → channel-type-DRCrEMss.mjs} +22 -22
  11. package/dist/.setup/{channel.setup-BlC3-Kzz.mjs → channel.setup-CRo1GjV7.mjs} +6 -9
  12. package/dist/.setup/{components-MqMWUWnE.mjs → components-Cq1PvIpN.mjs} +42 -71
  13. package/dist/.setup/{config-schema-CiZz-mtA.mjs → config-schema-oxELUSDx.mjs} +19 -44
  14. package/dist/.setup/{conversation-binding-route-_rz33QHO.mjs → conversation-binding-route-Caz_XuFH.mjs} +14 -6
  15. package/dist/.setup/{directory-config-BytTftz-.mjs → directory-config-esqNn0Eo.mjs} +6 -9
  16. package/dist/.setup/{directory-live--EGTH0DC.mjs → directory-live-DtKRHuGV.mjs} +6 -12
  17. package/dist/.setup/{discord-BXpHW-cu.mjs → discord-0xJYfdDD.mjs} +82 -386
  18. package/dist/.setup/{doctor-DxcdkXzz.mjs → doctor-BCl1H5tl.mjs} +21 -36
  19. package/dist/.setup/{doctor-contract-Co5vRCZ6.mjs → doctor-contract-CvvgwrrG.mjs} +41 -50
  20. package/dist/.setup/{channel-actions.runtime-CJmiFfps.mjs → handle-action-CUvQWnE7.mjs} +74 -105
  21. package/dist/.setup/{handle-action.guild-admin-DAFyh_yV.mjs → handle-action.guild-admin-Df-8gVle.mjs} +63 -121
  22. package/dist/.setup/{live-policy-config-eKQ-PLdy.mjs → live-policy-config-8Pv20CHc.mjs} +2 -3
  23. package/dist/.setup/{message-handler-DnUrDpaU.mjs → message-handler-B-Jk4oDk.mjs} +18 -93
  24. package/dist/.setup/message-handler.preflight-pluralkit-CWLUBVcx.mjs +141 -0
  25. package/dist/.setup/{message-handler.preflight-CtqaF_fb.mjs → message-handler.preflight-v-__NSDq.mjs} +73 -287
  26. package/dist/.setup/{message-handler.process-Dz1xvuQU.mjs → message-handler.process-BNFFuChn.mjs} +423 -374
  27. package/dist/.setup/{outbound-adapter-C8v79z9Z.mjs → outbound-adapter-BobT-kse.mjs} +105 -19
  28. package/dist/.setup/{outbound-session-route-CqWbuMOm.mjs → outbound-session-route-zVGxxceg.mjs} +142 -109
  29. package/dist/.setup/{pluralkit-CdAt1G0P.mjs → pluralkit-a6_NLfH9.mjs} +1 -1
  30. package/dist/.setup/{preflight-audio-DrnqFA8U.mjs → preflight-audio-DHGIHEpv.mjs} +2 -1
  31. package/dist/.setup/{presence-cache-dYSHPWMx.mjs → presence-cache-Di3H3DIU.mjs} +0 -4
  32. package/dist/.setup/{probe-CupW4we4.mjs → probe-LYrIHlBF.mjs} +13 -4
  33. package/dist/.setup/{provider-72zIvN-i.mjs → provider-B_G5hASF.mjs} +1112 -1668
  34. package/dist/.setup/provider-session.runtime-BYlTBFD2.mjs +6 -0
  35. package/dist/.setup/provider.runtime-CUE3UxER.mjs +2 -0
  36. package/dist/.setup/{realtime-session.runtime-DTccTgTM.mjs → realtime-session.runtime-oUd9DOcz.mjs} +372 -345
  37. package/dist/.setup/receive-recovery-CHPOsnLc.mjs +514 -0
  38. package/dist/.setup/{resolve-allowlist-common-CwMBzbx9.mjs → resolve-allowlist-common-DPdRggu5.mjs} +4 -7
  39. package/dist/.setup/{resolve-channels-BbvsLQOZ.mjs → resolve-channels-BFPNRmVv.mjs} +21 -40
  40. package/dist/.setup/{resolve-users-ByFlR7LQ.mjs → resolve-users-0-aBuCy3.mjs} +4 -4
  41. package/dist/.setup/{retry-DBfcEgmO.mjs → retry-pz_cSha2.mjs} +81 -16
  42. package/dist/.setup/rolldown-runtime-B4FMCO8f.mjs +28 -0
  43. package/dist/.setup/{runtime-SchNfUsQ.mjs → runtime-FN000lxA.mjs} +83 -166
  44. package/dist/.setup/runtime-doctor-migrations-CshUGl36.mjs +159 -0
  45. package/dist/.setup/{runtime-BVoa7hhx.mjs → runtime-sUksZ--Q.mjs} +2 -5
  46. package/dist/.setup/{secret-config-contract-DFu9hfU8.mjs → secret-config-contract-uOE2J7yM.mjs} +15 -85
  47. package/dist/.setup/{security-audit-s5w50-Ly.mjs → security-audit-Cdaegq7C.mjs} +3 -1
  48. package/dist/.setup/{send-CKDczUNL.mjs → send-CrfEI6Bs.mjs} +73 -114
  49. package/dist/.setup/{send.components-DWQjXhPV.mjs → send.components-DxQAMfES.mjs} +62 -107
  50. package/dist/.setup/{send.outbound-D0hQ7s50.mjs → send.outbound-BISKnb-a.mjs} +79 -154
  51. package/dist/.setup/{send.shared-Zwx6BxQ5.mjs → send.shared-DGFkbkQR.mjs} +10 -25
  52. package/dist/.setup/{sender-identity-0Ymgvmaj.mjs → sender-identity-B9X5Vb9R.mjs} +2 -3
  53. package/dist/.setup/setup-plugin-api-BQUBxbhe.mjs +3 -0
  54. package/dist/.setup/{shared-CaA3Vv4n.mjs → shared-B3wZ4hN-.mjs} +25 -32
  55. package/dist/.setup/{subagent-hooks-Bired9q6.mjs → subagent-hooks-nlUE9ow7.mjs} +5 -6
  56. package/dist/.setup/system-events-CdeZnvPV.mjs +33 -0
  57. package/dist/.setup/{target-resolver-B6MrxbYv.mjs → target-resolver-BuLapkhy.mjs} +9 -12
  58. package/dist/.setup/targets-0KUcEIYx.mjs +3 -0
  59. package/dist/.setup/{thread-bindings-CK5272V3.mjs → thread-bindings-D7TfgjR_.mjs} +33 -35
  60. package/dist/.setup/thread-bindings.manager-DN-NissX.mjs +819 -0
  61. package/dist/.setup/thread-bindings.session-updates-CshfKghV.mjs +359 -0
  62. package/dist/.setup/{thread-bindings.state-BThFQEga.mjs → thread-bindings.state-g6v9zAym.mjs} +21 -62
  63. package/dist/.setup/{transcripts-source-CuWYgayu.mjs → transcripts-source-p8EV179h.mjs} +133 -238
  64. package/dist/.setup/{typing-BKZL5fGj.mjs → typing-BiHCzBRu.mjs} +2 -1
  65. package/dist/.setup/{voice-runtime-DHVQ2mFz.mjs → voice-runtime-B46rcwrG.mjs} +633 -1085
  66. package/dist/account-inspect-api.js +1 -1
  67. package/dist/action-runtime-api.js +1 -1
  68. package/dist/activities-api.js +1 -1
  69. package/dist/api.js +18 -18
  70. package/dist/channel-config-api.js +1 -1
  71. package/dist/channel-plugin-api.js +1 -1
  72. package/dist/directory-contract-api.js +1 -1
  73. package/dist/doctor-contract-api.js +4 -4
  74. package/dist/index.js +1 -1
  75. package/dist/runtime-api.js +20 -20
  76. package/dist/secret-contract-api.js +1 -1
  77. package/dist/security-audit-contract-api.js +1 -1
  78. package/dist/setup-entry.js +1 -1
  79. package/dist/setup-plugin-api.js +1 -1
  80. package/dist/src/voice/audio-worker.runtime.js +1056 -0
  81. package/dist/subagent-hooks-api.js +3 -4
  82. package/dist/transcripts-source-api.js +1 -1
  83. package/node_modules/@napi-rs/wasm-runtime/dist/emnapi-plugins.cjs +8 -4
  84. package/node_modules/@napi-rs/wasm-runtime/dist/emnapi-plugins.js +8 -4
  85. package/node_modules/@napi-rs/wasm-runtime/dist/fs-proxy.cjs +1 -1
  86. package/node_modules/@napi-rs/wasm-runtime/dist/fs.js +770 -695
  87. package/node_modules/@napi-rs/wasm-runtime/fs-proxy.js +3 -2
  88. package/node_modules/@napi-rs/wasm-runtime/package.json +1 -1
  89. package/node_modules/@tybys/wasm-util/LICENSE +21 -0
  90. package/node_modules/@tybys/wasm-util/package.json +1 -1
  91. package/node_modules/@types/node/README.md +2 -2
  92. package/node_modules/@types/node/child_process.d.ts +1 -1
  93. package/node_modules/@types/node/crypto.d.ts +20 -8
  94. package/node_modules/@types/node/ffi.d.ts +14 -0
  95. package/node_modules/@types/node/http2.d.ts +3 -2
  96. package/node_modules/@types/node/net.d.ts +16 -4
  97. package/node_modules/@types/node/package.json +2 -17
  98. package/node_modules/@types/node/process.d.ts +1 -0
  99. package/node_modules/@types/node/quic.d.ts +39 -1
  100. package/node_modules/@types/node/stream/iter.d.ts +9 -12
  101. package/node_modules/@types/node/test/reporters.d.ts +1 -0
  102. package/node_modules/@types/node/test.d.ts +72 -0
  103. package/node_modules/@types/node/tls.d.ts +14 -10
  104. package/node_modules/@types/node/vm.d.ts +2 -1
  105. package/node_modules/@types/node/web-globals/streams.d.ts +4 -0
  106. package/node_modules/@types/node/worker_threads.d.ts +4 -1
  107. package/node_modules/typebox/build/compile/code.mjs +1 -2
  108. package/node_modules/typebox/build/compile/validator.mjs +5 -1
  109. package/node_modules/typebox/build/format/iri.mjs +16 -9
  110. package/node_modules/typebox/build/guard/emit.mjs +2 -2
  111. package/node_modules/typebox/build/guard/guard.d.mts +7 -5
  112. package/node_modules/typebox/build/guard/guard.mjs +14 -9
  113. package/node_modules/typebox/build/guard/index.mjs +6 -0
  114. package/node_modules/typebox/build/guard/unicode/unicode.d.mts +6 -0
  115. package/node_modules/typebox/build/guard/unicode/unicode.mjs +35 -0
  116. package/node_modules/typebox/build/guard/{string.mjs → unicode/unicode_segment.mjs} +16 -19
  117. package/node_modules/typebox/build/schema/build.mjs +2 -3
  118. package/node_modules/typebox/build/schema/engine/_pathing.d.mts +1 -0
  119. package/node_modules/typebox/build/schema/engine/_pathing.mjs +11 -0
  120. package/node_modules/typebox/build/schema/engine/_refine.mjs +13 -5
  121. package/node_modules/typebox/build/schema/engine/additionalProperties.mjs +2 -1
  122. package/node_modules/typebox/build/schema/engine/dependencies.mjs +2 -1
  123. package/node_modules/typebox/build/schema/engine/dependentSchemas.mjs +2 -1
  124. package/node_modules/typebox/build/schema/engine/dynamicRef.d.mts +1 -1
  125. package/node_modules/typebox/build/schema/engine/dynamicRef.mjs +2 -2
  126. package/node_modules/typebox/build/schema/engine/format.mjs +9 -2
  127. package/node_modules/typebox/build/schema/engine/patternProperties.mjs +3 -2
  128. package/node_modules/typebox/build/schema/engine/properties.mjs +3 -2
  129. package/node_modules/typebox/build/schema/engine/propertyNames.mjs +2 -1
  130. package/node_modules/typebox/build/schema/engine/recursiveRef.d.mts +1 -1
  131. package/node_modules/typebox/build/schema/engine/recursiveRef.mjs +2 -2
  132. package/node_modules/typebox/build/schema/engine/ref.d.mts +1 -1
  133. package/node_modules/typebox/build/schema/engine/ref.mjs +2 -2
  134. package/node_modules/typebox/build/schema/engine/schema.mjs +24 -24
  135. package/node_modules/typebox/build/schema/parse.mjs +3 -0
  136. package/node_modules/typebox/build/schema/pointer/pointer.d.mts +1 -6
  137. package/node_modules/typebox/build/schema/pointer/pointer.mjs +47 -64
  138. package/node_modules/typebox/build/system/settings/internal.d.mts +2 -0
  139. package/node_modules/typebox/build/system/settings/internal.mjs +20 -0
  140. package/node_modules/typebox/build/system/settings/settings.d.mts +11 -0
  141. package/node_modules/typebox/build/system/settings/settings.mjs +14 -0
  142. package/node_modules/typebox/build/type/extends/inference.d.mts +1 -1
  143. package/node_modules/typebox/build/type/extends/inference.mjs +15 -2
  144. package/node_modules/typebox/build/type/extends/tuple.d.mts +2 -1
  145. package/node_modules/typebox/build/type/extends/tuple.mjs +21 -1
  146. package/node_modules/typebox/build/value/parse/parse.mjs +10 -4
  147. package/node_modules/typebox/package.json +1 -1
  148. package/node_modules/typebox/readme.md +3 -1
  149. package/node_modules/zod/README.md +2 -2
  150. package/node_modules/zod/compile.cjs +19 -0
  151. package/node_modules/zod/index.cjs +19 -0
  152. package/node_modules/zod/locales/index.cjs +19 -0
  153. package/node_modules/zod/mini/index.cjs +19 -0
  154. package/node_modules/zod/package.json +8 -7
  155. package/node_modules/zod/src/v3/helpers/errorUtil.ts +1 -1
  156. package/node_modules/zod/src/v4/classic/external.ts +2 -0
  157. package/node_modules/zod/src/v4/classic/from-json-schema.ts +248 -25
  158. package/node_modules/zod/src/v4/classic/schemas.ts +243 -168
  159. package/node_modules/zod/src/v4/classic/tests/assignability.test.ts +60 -9
  160. package/node_modules/zod/src/v4/classic/tests/bigint.test.ts +6 -0
  161. package/node_modules/zod/src/v4/classic/tests/continuability.test.ts +2 -2
  162. package/node_modules/zod/src/v4/classic/tests/cyclic-data.test.ts +265 -0
  163. package/node_modules/zod/src/v4/classic/tests/discriminated-unions.test.ts +112 -6
  164. package/node_modules/zod/src/v4/classic/tests/enum.test.ts +9 -0
  165. package/node_modules/zod/src/v4/classic/tests/error.test.ts +130 -1
  166. package/node_modules/zod/src/v4/classic/tests/from-json-schema.test.ts +157 -0
  167. package/node_modules/zod/src/v4/classic/tests/iban.test.ts +81 -0
  168. package/node_modules/zod/src/v4/classic/tests/instance-footprint.test.ts +40 -2
  169. package/node_modules/zod/src/v4/classic/tests/instanceof.test.ts +27 -7
  170. package/node_modules/zod/src/v4/classic/tests/issue-schema.test.ts +88 -56
  171. package/node_modules/zod/src/v4/classic/tests/number.test.ts +39 -0
  172. package/node_modules/zod/src/v4/classic/tests/object.test.ts +56 -0
  173. package/node_modules/zod/src/v4/classic/tests/optin-ladder.test.ts +3 -2
  174. package/node_modules/zod/src/v4/classic/tests/prefault.test.ts +70 -0
  175. package/node_modules/zod/src/v4/classic/tests/properties.test.ts +141 -0
  176. package/node_modules/zod/src/v4/classic/tests/recursive-types.test.ts +46 -1
  177. package/node_modules/zod/src/v4/classic/tests/standard-schema.test.ts +19 -0
  178. package/node_modules/zod/src/v4/classic/tests/string.test.ts +95 -1
  179. package/node_modules/zod/src/v4/classic/tests/template-literal.test.ts +33 -1
  180. package/node_modules/zod/src/v4/classic/tests/to-json-schema.test.ts +234 -38
  181. package/node_modules/zod/src/v4/classic/tests/validate.test.ts +569 -0
  182. package/node_modules/zod/src/v4/core/api.ts +44 -28
  183. package/node_modules/zod/src/v4/core/checks.ts +62 -102
  184. package/node_modules/zod/src/v4/core/compile.ts +218 -93
  185. package/node_modules/zod/src/v4/core/core.ts +1 -3
  186. package/node_modules/zod/src/v4/core/doc.ts +6 -2
  187. package/node_modules/zod/src/v4/core/errors.ts +3 -6
  188. package/node_modules/zod/src/v4/core/json-schema-generator.ts +2 -2
  189. package/node_modules/zod/src/v4/core/json-schema-processors.ts +185 -81
  190. package/node_modules/zod/src/v4/core/memoizer.ts +75 -28
  191. package/node_modules/zod/src/v4/core/parse.ts +37 -16
  192. package/node_modules/zod/src/v4/core/regexes.ts +14 -4
  193. package/node_modules/zod/src/v4/core/schemas.ts +296 -132
  194. package/node_modules/zod/src/v4/core/tests/cached.test.ts +54 -0
  195. package/node_modules/zod/src/v4/core/tests/compile-differential.test.ts +35 -0
  196. package/node_modules/zod/src/v4/core/tests/compile-generative.test.ts +445 -0
  197. package/node_modules/zod/src/v4/core/tests/compile.test.ts +399 -2
  198. package/node_modules/zod/src/v4/core/tests/email-regex.test.ts +140 -0
  199. package/node_modules/zod/src/v4/core/tests/locales/tg.test.ts +85 -0
  200. package/node_modules/zod/src/v4/core/tests/polyfill-collision.test.ts +46 -0
  201. package/node_modules/zod/src/v4/core/tests/url-no-canparse.test.ts +118 -16
  202. package/node_modules/zod/src/v4/core/to-json-schema.ts +9 -7
  203. package/node_modules/zod/src/v4/core/util.ts +218 -147
  204. package/node_modules/zod/src/v4/core/versions.ts +2 -2
  205. package/node_modules/zod/src/v4/locales/ar.ts +2 -0
  206. package/node_modules/zod/src/v4/locales/az.ts +2 -0
  207. package/node_modules/zod/src/v4/locales/be.ts +2 -0
  208. package/node_modules/zod/src/v4/locales/bg.ts +2 -0
  209. package/node_modules/zod/src/v4/locales/bn.ts +2 -0
  210. package/node_modules/zod/src/v4/locales/ca.ts +2 -0
  211. package/node_modules/zod/src/v4/locales/ckb.ts +2 -0
  212. package/node_modules/zod/src/v4/locales/cs.ts +2 -0
  213. package/node_modules/zod/src/v4/locales/da.ts +2 -0
  214. package/node_modules/zod/src/v4/locales/de.ts +2 -0
  215. package/node_modules/zod/src/v4/locales/el.ts +2 -0
  216. package/node_modules/zod/src/v4/locales/en.ts +2 -0
  217. package/node_modules/zod/src/v4/locales/eo.ts +2 -0
  218. package/node_modules/zod/src/v4/locales/es.ts +2 -0
  219. package/node_modules/zod/src/v4/locales/fa.ts +2 -0
  220. package/node_modules/zod/src/v4/locales/fi.ts +2 -0
  221. package/node_modules/zod/src/v4/locales/fr-CA.ts +2 -0
  222. package/node_modules/zod/src/v4/locales/fr.ts +2 -0
  223. package/node_modules/zod/src/v4/locales/gu.ts +2 -0
  224. package/node_modules/zod/src/v4/locales/he.ts +2 -0
  225. package/node_modules/zod/src/v4/locales/hi.ts +2 -0
  226. package/node_modules/zod/src/v4/locales/hr.ts +2 -0
  227. package/node_modules/zod/src/v4/locales/hu.ts +2 -0
  228. package/node_modules/zod/src/v4/locales/hy.ts +2 -0
  229. package/node_modules/zod/src/v4/locales/id.ts +2 -0
  230. package/node_modules/zod/src/v4/locales/index.ts +1 -0
  231. package/node_modules/zod/src/v4/locales/is.ts +2 -0
  232. package/node_modules/zod/src/v4/locales/it.ts +2 -0
  233. package/node_modules/zod/src/v4/locales/ja.ts +2 -0
  234. package/node_modules/zod/src/v4/locales/ka.ts +2 -0
  235. package/node_modules/zod/src/v4/locales/km.ts +2 -0
  236. package/node_modules/zod/src/v4/locales/kn.ts +2 -0
  237. package/node_modules/zod/src/v4/locales/ko.ts +2 -0
  238. package/node_modules/zod/src/v4/locales/lt.ts +2 -0
  239. package/node_modules/zod/src/v4/locales/mk.ts +2 -0
  240. package/node_modules/zod/src/v4/locales/ms.ts +2 -0
  241. package/node_modules/zod/src/v4/locales/ne.ts +2 -0
  242. package/node_modules/zod/src/v4/locales/nl.ts +2 -0
  243. package/node_modules/zod/src/v4/locales/nn.ts +2 -0
  244. package/node_modules/zod/src/v4/locales/no.ts +2 -0
  245. package/node_modules/zod/src/v4/locales/ota.ts +2 -0
  246. package/node_modules/zod/src/v4/locales/pl.ts +2 -0
  247. package/node_modules/zod/src/v4/locales/ps.ts +2 -0
  248. package/node_modules/zod/src/v4/locales/pt-BR.ts +2 -0
  249. package/node_modules/zod/src/v4/locales/pt.ts +2 -0
  250. package/node_modules/zod/src/v4/locales/ro.ts +2 -0
  251. package/node_modules/zod/src/v4/locales/ru.ts +2 -0
  252. package/node_modules/zod/src/v4/locales/sk.ts +2 -0
  253. package/node_modules/zod/src/v4/locales/sl.ts +2 -0
  254. package/node_modules/zod/src/v4/locales/sv.ts +2 -0
  255. package/node_modules/zod/src/v4/locales/ta.ts +2 -0
  256. package/node_modules/zod/src/v4/locales/tg.ts +135 -0
  257. package/node_modules/zod/src/v4/locales/th.ts +2 -0
  258. package/node_modules/zod/src/v4/locales/tk.ts +2 -0
  259. package/node_modules/zod/src/v4/locales/tr.ts +2 -0
  260. package/node_modules/zod/src/v4/locales/uk.ts +2 -0
  261. package/node_modules/zod/src/v4/locales/ur.ts +2 -0
  262. package/node_modules/zod/src/v4/locales/uz.ts +2 -0
  263. package/node_modules/zod/src/v4/locales/vi.ts +2 -0
  264. package/node_modules/zod/src/v4/locales/yo.ts +2 -0
  265. package/node_modules/zod/src/v4/locales/zh-CN.ts +2 -0
  266. package/node_modules/zod/src/v4/locales/zh-TW.ts +2 -0
  267. package/node_modules/zod/src/v4/mini/external.ts +2 -0
  268. package/node_modules/zod/src/v4/mini/schemas.ts +32 -7
  269. package/node_modules/zod/src/v4/mini/tests/checks.test.ts +1 -1
  270. package/node_modules/zod/src/v4/mini/tests/computed.test.ts +11 -17
  271. package/node_modules/zod/src/v4/mini/tests/index.test.ts +86 -0
  272. package/node_modules/zod/src/v4/mini/tests/recursive-types.test.ts +16 -0
  273. package/node_modules/zod/src/v4/mini/tests/string.test.ts +23 -0
  274. package/node_modules/zod/v3/ZodError.cjs +19 -0
  275. package/node_modules/zod/v3/errors.cjs +19 -0
  276. package/node_modules/zod/v3/external.cjs +19 -0
  277. package/node_modules/zod/v3/helpers/enumUtil.cjs +19 -0
  278. package/node_modules/zod/v3/helpers/errorUtil.cjs +20 -1
  279. package/node_modules/zod/v3/helpers/errorUtil.js +1 -1
  280. package/node_modules/zod/v3/helpers/parseUtil.cjs +19 -0
  281. package/node_modules/zod/v3/helpers/partialUtil.cjs +19 -0
  282. package/node_modules/zod/v3/helpers/typeAliases.cjs +19 -0
  283. package/node_modules/zod/v3/helpers/util.cjs +19 -0
  284. package/node_modules/zod/v3/index.cjs +19 -0
  285. package/node_modules/zod/v3/standard-schema.cjs +19 -0
  286. package/node_modules/zod/v3/types.cjs +19 -0
  287. package/node_modules/zod/v4/classic/checks.cjs +19 -0
  288. package/node_modules/zod/v4/classic/coerce.cjs +19 -0
  289. package/node_modules/zod/v4/classic/compat.cjs +19 -0
  290. package/node_modules/zod/v4/classic/deep-partial.cjs +19 -0
  291. package/node_modules/zod/v4/classic/errors.cjs +19 -0
  292. package/node_modules/zod/v4/classic/external.cjs +22 -1
  293. package/node_modules/zod/v4/classic/external.d.cts +1 -1
  294. package/node_modules/zod/v4/classic/external.d.ts +1 -1
  295. package/node_modules/zod/v4/classic/external.js +1 -1
  296. package/node_modules/zod/v4/classic/from-json-schema.cjs +264 -24
  297. package/node_modules/zod/v4/classic/from-json-schema.js +245 -24
  298. package/node_modules/zod/v4/classic/in-out.cjs +19 -0
  299. package/node_modules/zod/v4/classic/index.cjs +19 -0
  300. package/node_modules/zod/v4/classic/iso.cjs +19 -0
  301. package/node_modules/zod/v4/classic/parse.cjs +19 -0
  302. package/node_modules/zod/v4/classic/schemas.cjs +100 -35
  303. package/node_modules/zod/v4/classic/schemas.d.cts +15 -1
  304. package/node_modules/zod/v4/classic/schemas.d.ts +15 -1
  305. package/node_modules/zod/v4/classic/schemas.js +77 -33
  306. package/node_modules/zod/v4/core/api.cjs +45 -22
  307. package/node_modules/zod/v4/core/api.d.cts +12 -6
  308. package/node_modules/zod/v4/core/api.d.ts +12 -6
  309. package/node_modules/zod/v4/core/api.js +25 -22
  310. package/node_modules/zod/v4/core/checks.cjs +51 -97
  311. package/node_modules/zod/v4/core/checks.d.cts +17 -1
  312. package/node_modules/zod/v4/core/checks.d.ts +17 -1
  313. package/node_modules/zod/v4/core/checks.js +31 -96
  314. package/node_modules/zod/v4/core/compile.cjs +173 -78
  315. package/node_modules/zod/v4/core/compile.d.cts +18 -4
  316. package/node_modules/zod/v4/core/compile.d.ts +18 -4
  317. package/node_modules/zod/v4/core/compile.js +154 -79
  318. package/node_modules/zod/v4/core/core.cjs +20 -1
  319. package/node_modules/zod/v4/core/core.js +1 -1
  320. package/node_modules/zod/v4/core/doc.cjs +26 -2
  321. package/node_modules/zod/v4/core/doc.js +7 -2
  322. package/node_modules/zod/v4/core/errors.cjs +21 -5
  323. package/node_modules/zod/v4/core/errors.js +2 -5
  324. package/node_modules/zod/v4/core/index.cjs +19 -0
  325. package/node_modules/zod/v4/core/json-schema-generator.cjs +20 -1
  326. package/node_modules/zod/v4/core/json-schema-generator.js +2 -2
  327. package/node_modules/zod/v4/core/json-schema-processors.cjs +188 -72
  328. package/node_modules/zod/v4/core/json-schema-processors.d.cts +16 -0
  329. package/node_modules/zod/v4/core/json-schema-processors.d.ts +16 -0
  330. package/node_modules/zod/v4/core/json-schema-processors.js +170 -74
  331. package/node_modules/zod/v4/core/json-schema.cjs +19 -0
  332. package/node_modules/zod/v4/core/memoizer.cjs +111 -23
  333. package/node_modules/zod/v4/core/memoizer.js +69 -23
  334. package/node_modules/zod/v4/core/parse.cjs +56 -16
  335. package/node_modules/zod/v4/core/parse.js +37 -16
  336. package/node_modules/zod/v4/core/regexes.cjs +31 -6
  337. package/node_modules/zod/v4/core/regexes.d.cts +3 -0
  338. package/node_modules/zod/v4/core/regexes.d.ts +3 -0
  339. package/node_modules/zod/v4/core/regexes.js +10 -4
  340. package/node_modules/zod/v4/core/registries.cjs +19 -0
  341. package/node_modules/zod/v4/core/schemas.cjs +302 -114
  342. package/node_modules/zod/v4/core/schemas.d.cts +28 -8
  343. package/node_modules/zod/v4/core/schemas.d.ts +28 -8
  344. package/node_modules/zod/v4/core/schemas.js +279 -113
  345. package/node_modules/zod/v4/core/standard-schema.cjs +19 -0
  346. package/node_modules/zod/v4/core/to-json-schema.cjs +28 -7
  347. package/node_modules/zod/v4/core/to-json-schema.d.cts +4 -3
  348. package/node_modules/zod/v4/core/to-json-schema.d.ts +4 -3
  349. package/node_modules/zod/v4/core/to-json-schema.js +7 -6
  350. package/node_modules/zod/v4/core/util.cjs +177 -143
  351. package/node_modules/zod/v4/core/util.d.cts +25 -4
  352. package/node_modules/zod/v4/core/util.d.ts +25 -4
  353. package/node_modules/zod/v4/core/util.js +156 -143
  354. package/node_modules/zod/v4/core/versions.cjs +21 -2
  355. package/node_modules/zod/v4/core/versions.d.cts +1 -1
  356. package/node_modules/zod/v4/core/versions.d.ts +1 -1
  357. package/node_modules/zod/v4/core/versions.js +2 -2
  358. package/node_modules/zod/v4/core/visit.cjs +19 -0
  359. package/node_modules/zod/v4/index.cjs +19 -0
  360. package/node_modules/zod/v4/locales/ar.cjs +2 -0
  361. package/node_modules/zod/v4/locales/ar.js +2 -0
  362. package/node_modules/zod/v4/locales/az.cjs +2 -0
  363. package/node_modules/zod/v4/locales/az.js +2 -0
  364. package/node_modules/zod/v4/locales/be.cjs +2 -0
  365. package/node_modules/zod/v4/locales/be.js +2 -0
  366. package/node_modules/zod/v4/locales/bg.cjs +2 -0
  367. package/node_modules/zod/v4/locales/bg.js +2 -0
  368. package/node_modules/zod/v4/locales/bn.cjs +2 -0
  369. package/node_modules/zod/v4/locales/bn.js +2 -0
  370. package/node_modules/zod/v4/locales/ca.cjs +2 -0
  371. package/node_modules/zod/v4/locales/ca.js +2 -0
  372. package/node_modules/zod/v4/locales/ckb.cjs +2 -0
  373. package/node_modules/zod/v4/locales/ckb.js +2 -0
  374. package/node_modules/zod/v4/locales/cs.cjs +2 -0
  375. package/node_modules/zod/v4/locales/cs.js +2 -0
  376. package/node_modules/zod/v4/locales/da.cjs +2 -0
  377. package/node_modules/zod/v4/locales/da.js +2 -0
  378. package/node_modules/zod/v4/locales/de.cjs +2 -0
  379. package/node_modules/zod/v4/locales/de.js +2 -0
  380. package/node_modules/zod/v4/locales/el.cjs +2 -0
  381. package/node_modules/zod/v4/locales/el.js +2 -0
  382. package/node_modules/zod/v4/locales/en.cjs +2 -0
  383. package/node_modules/zod/v4/locales/en.js +2 -0
  384. package/node_modules/zod/v4/locales/eo.cjs +2 -0
  385. package/node_modules/zod/v4/locales/eo.js +2 -0
  386. package/node_modules/zod/v4/locales/es.cjs +2 -0
  387. package/node_modules/zod/v4/locales/es.js +2 -0
  388. package/node_modules/zod/v4/locales/fa.cjs +2 -0
  389. package/node_modules/zod/v4/locales/fa.js +2 -0
  390. package/node_modules/zod/v4/locales/fi.cjs +2 -0
  391. package/node_modules/zod/v4/locales/fi.js +2 -0
  392. package/node_modules/zod/v4/locales/fr-CA.cjs +2 -0
  393. package/node_modules/zod/v4/locales/fr-CA.js +2 -0
  394. package/node_modules/zod/v4/locales/fr.cjs +2 -0
  395. package/node_modules/zod/v4/locales/fr.js +2 -0
  396. package/node_modules/zod/v4/locales/gu.cjs +2 -0
  397. package/node_modules/zod/v4/locales/gu.js +2 -0
  398. package/node_modules/zod/v4/locales/he.cjs +2 -0
  399. package/node_modules/zod/v4/locales/he.js +2 -0
  400. package/node_modules/zod/v4/locales/hi.cjs +2 -0
  401. package/node_modules/zod/v4/locales/hi.js +2 -0
  402. package/node_modules/zod/v4/locales/hr.cjs +2 -0
  403. package/node_modules/zod/v4/locales/hr.js +2 -0
  404. package/node_modules/zod/v4/locales/hu.cjs +2 -0
  405. package/node_modules/zod/v4/locales/hu.js +2 -0
  406. package/node_modules/zod/v4/locales/hy.cjs +2 -0
  407. package/node_modules/zod/v4/locales/hy.js +2 -0
  408. package/node_modules/zod/v4/locales/id.cjs +2 -0
  409. package/node_modules/zod/v4/locales/id.js +2 -0
  410. package/node_modules/zod/v4/locales/index.cjs +22 -1
  411. package/node_modules/zod/v4/locales/index.d.cts +1 -0
  412. package/node_modules/zod/v4/locales/index.d.ts +1 -0
  413. package/node_modules/zod/v4/locales/index.js +1 -0
  414. package/node_modules/zod/v4/locales/is.cjs +2 -0
  415. package/node_modules/zod/v4/locales/is.js +2 -0
  416. package/node_modules/zod/v4/locales/it.cjs +2 -0
  417. package/node_modules/zod/v4/locales/it.js +2 -0
  418. package/node_modules/zod/v4/locales/ja.cjs +2 -0
  419. package/node_modules/zod/v4/locales/ja.js +2 -0
  420. package/node_modules/zod/v4/locales/ka.cjs +2 -0
  421. package/node_modules/zod/v4/locales/ka.js +2 -0
  422. package/node_modules/zod/v4/locales/km.cjs +2 -0
  423. package/node_modules/zod/v4/locales/km.js +2 -0
  424. package/node_modules/zod/v4/locales/kn.cjs +2 -0
  425. package/node_modules/zod/v4/locales/kn.js +2 -0
  426. package/node_modules/zod/v4/locales/ko.cjs +2 -0
  427. package/node_modules/zod/v4/locales/ko.js +2 -0
  428. package/node_modules/zod/v4/locales/lt.cjs +2 -0
  429. package/node_modules/zod/v4/locales/lt.js +2 -0
  430. package/node_modules/zod/v4/locales/mk.cjs +2 -0
  431. package/node_modules/zod/v4/locales/mk.js +2 -0
  432. package/node_modules/zod/v4/locales/ms.cjs +2 -0
  433. package/node_modules/zod/v4/locales/ms.js +2 -0
  434. package/node_modules/zod/v4/locales/ne.cjs +2 -0
  435. package/node_modules/zod/v4/locales/ne.js +2 -0
  436. package/node_modules/zod/v4/locales/nl.cjs +2 -0
  437. package/node_modules/zod/v4/locales/nl.js +2 -0
  438. package/node_modules/zod/v4/locales/nn.cjs +2 -0
  439. package/node_modules/zod/v4/locales/nn.js +2 -0
  440. package/node_modules/zod/v4/locales/no.cjs +2 -0
  441. package/node_modules/zod/v4/locales/no.js +2 -0
  442. package/node_modules/zod/v4/locales/ota.cjs +2 -0
  443. package/node_modules/zod/v4/locales/ota.js +2 -0
  444. package/node_modules/zod/v4/locales/pl.cjs +2 -0
  445. package/node_modules/zod/v4/locales/pl.js +2 -0
  446. package/node_modules/zod/v4/locales/ps.cjs +2 -0
  447. package/node_modules/zod/v4/locales/ps.js +2 -0
  448. package/node_modules/zod/v4/locales/pt-BR.cjs +2 -0
  449. package/node_modules/zod/v4/locales/pt-BR.js +2 -0
  450. package/node_modules/zod/v4/locales/pt.cjs +2 -0
  451. package/node_modules/zod/v4/locales/pt.js +2 -0
  452. package/node_modules/zod/v4/locales/ro.cjs +2 -0
  453. package/node_modules/zod/v4/locales/ro.js +2 -0
  454. package/node_modules/zod/v4/locales/ru.cjs +2 -0
  455. package/node_modules/zod/v4/locales/ru.js +2 -0
  456. package/node_modules/zod/v4/locales/sk.cjs +2 -0
  457. package/node_modules/zod/v4/locales/sk.js +2 -0
  458. package/node_modules/zod/v4/locales/sl.cjs +2 -0
  459. package/node_modules/zod/v4/locales/sl.js +2 -0
  460. package/node_modules/zod/v4/locales/sv.cjs +2 -0
  461. package/node_modules/zod/v4/locales/sv.js +2 -0
  462. package/node_modules/zod/v4/locales/ta.cjs +2 -0
  463. package/node_modules/zod/v4/locales/ta.js +2 -0
  464. package/node_modules/zod/v4/locales/tg.cjs +144 -0
  465. package/node_modules/zod/v4/locales/tg.d.cts +5 -0
  466. package/node_modules/zod/v4/locales/tg.d.ts +4 -0
  467. package/node_modules/zod/v4/locales/tg.js +117 -0
  468. package/node_modules/zod/v4/locales/th.cjs +2 -0
  469. package/node_modules/zod/v4/locales/th.js +2 -0
  470. package/node_modules/zod/v4/locales/tk.cjs +2 -0
  471. package/node_modules/zod/v4/locales/tk.js +2 -0
  472. package/node_modules/zod/v4/locales/tr.cjs +2 -0
  473. package/node_modules/zod/v4/locales/tr.js +2 -0
  474. package/node_modules/zod/v4/locales/uk.cjs +2 -0
  475. package/node_modules/zod/v4/locales/uk.js +2 -0
  476. package/node_modules/zod/v4/locales/ur.cjs +2 -0
  477. package/node_modules/zod/v4/locales/ur.js +2 -0
  478. package/node_modules/zod/v4/locales/uz.cjs +2 -0
  479. package/node_modules/zod/v4/locales/uz.js +2 -0
  480. package/node_modules/zod/v4/locales/vi.cjs +2 -0
  481. package/node_modules/zod/v4/locales/vi.js +2 -0
  482. package/node_modules/zod/v4/locales/yo.cjs +2 -0
  483. package/node_modules/zod/v4/locales/yo.js +2 -0
  484. package/node_modules/zod/v4/locales/zh-CN.cjs +2 -0
  485. package/node_modules/zod/v4/locales/zh-CN.js +2 -0
  486. package/node_modules/zod/v4/locales/zh-TW.cjs +2 -0
  487. package/node_modules/zod/v4/locales/zh-TW.js +2 -0
  488. package/node_modules/zod/v4/mini/checks.cjs +19 -0
  489. package/node_modules/zod/v4/mini/coerce.cjs +19 -0
  490. package/node_modules/zod/v4/mini/deep-partial.cjs +19 -0
  491. package/node_modules/zod/v4/mini/external.cjs +22 -1
  492. package/node_modules/zod/v4/mini/external.d.cts +1 -1
  493. package/node_modules/zod/v4/mini/external.d.ts +1 -1
  494. package/node_modules/zod/v4/mini/external.js +1 -1
  495. package/node_modules/zod/v4/mini/in-out.cjs +19 -0
  496. package/node_modules/zod/v4/mini/index.cjs +19 -0
  497. package/node_modules/zod/v4/mini/iso.cjs +19 -0
  498. package/node_modules/zod/v4/mini/parse.cjs +19 -0
  499. package/node_modules/zod/v4/mini/schemas.cjs +44 -8
  500. package/node_modules/zod/v4/mini/schemas.d.cts +6 -1
  501. package/node_modules/zod/v4/mini/schemas.d.ts +6 -1
  502. package/node_modules/zod/v4/mini/schemas.js +21 -6
  503. package/node_modules/zod/v4-mini/index.cjs +19 -0
  504. package/openclaw.plugin.json +21 -1
  505. package/package.json +9 -6
  506. package/dist/.setup/agent-components.runtime-CEPrf2SY.mjs +0 -4
  507. package/dist/.setup/message-handler.history-CJOsN9w5.mjs +0 -28
  508. package/dist/.setup/probe.runtime-DBQ_AGPe.mjs +0 -2
  509. package/dist/.setup/provider-session.runtime-BW7QrF5C.mjs +0 -6
  510. package/dist/.setup/provider.runtime-DuhmKdDU.mjs +0 -2
  511. package/dist/.setup/security-audit.runtime-DHtYenx9.mjs +0 -2
  512. package/dist/.setup/setup-plugin-api-CINIEBLa.mjs +0 -3
  513. package/dist/.setup/system-events-B2YEEMbS.mjs +0 -34
  514. package/dist/.setup/targets-D1mAB5yO.mjs +0 -3
  515. package/dist/.setup/thread-bindings.manager-eexkKyrG.mjs +0 -678
  516. package/dist/.setup/thread-bindings.session-updates-DCQq1WZ5.mjs +0 -55
  517. /package/node_modules/typebox/build/guard/{string.d.mts → unicode/unicode_segment.d.mts} +0 -0
@@ -0,0 +1,1056 @@
1
+ import { _ as releaseDiscordAudioInput, b as serializeDiscordAudioError, c as createDiscordOpusEncodeStream, d as createRealtimePcmToDiscordConverter, f as decodeOpusStreamChunks, g as getDiscordAudioOutputStatus, i as enableDaveReceivePassthrough, l as createDiscordOpusPlaybackStream, m as DiscordAudioOutputStatus, n as analyzeVoiceReceiveError, o as recoverDaveZeroTransition, x as setDiscordAudioOutputStatus, y as retireDiscordAudioOutput } from "../../.setup/receive-recovery-CHPOsnLc.mjs";
2
+ import { createRequire } from "node:module";
3
+ import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
4
+ import { createSubsystemLogger } from "openclaw/plugin-sdk/runtime-env";
5
+ import { parentPort, workerData } from "node:worker_threads";
6
+ import { PassThrough, pipeline } from "node:stream";
7
+ import { REALTIME_VOICE_AUDIO_FORMAT_PCM16_24KHZ } from "openclaw/plugin-sdk/realtime-voice-provider";
8
+ import { createRealtimeVoiceOutputActivityTracker, isRealtimeVoiceAudioAudible } from "openclaw/plugin-sdk/realtime-voice";
9
+ //#region extensions/discord/src/voice/sdk-runtime.ts
10
+ let cachedDiscordVoiceSdk = null;
11
+ function loadDiscordVoiceSdk() {
12
+ if (cachedDiscordVoiceSdk) return cachedDiscordVoiceSdk;
13
+ cachedDiscordVoiceSdk = createRequire(import.meta.url)("@discordjs/voice");
14
+ return cachedDiscordVoiceSdk;
15
+ }
16
+ //#endregion
17
+ //#region extensions/discord/src/voice/realtime-player.runtime.ts
18
+ const DISCORD_REALTIME_PLAYBACK_IDLE_MS = 2e3;
19
+ /** One physical player serves every speaker lane in the room. */
20
+ var DiscordRealtimePlayer = class {
21
+ hold(hold) {
22
+ this.holds = Math.max(0, this.holds + (hold ? 1 : -1));
23
+ this.drain();
24
+ }
25
+ constructor(player) {
26
+ this.player = player;
27
+ this.queue = [];
28
+ this.changing = false;
29
+ this.closed = false;
30
+ this.holds = 0;
31
+ this.onIdle = () => {
32
+ const request = this.current;
33
+ this.current = void 0;
34
+ if (request) this.transition(() => request.onIdle());
35
+ };
36
+ const stop = player.stop.bind(player);
37
+ player.stop = (force) => {
38
+ const request = this.current;
39
+ if (request && !force && !request.onRetiring()) return false;
40
+ return stop(force);
41
+ };
42
+ player.on(loadDiscordVoiceSdk().AudioPlayerStatus.Idle, this.onIdle);
43
+ }
44
+ enqueue(request) {
45
+ if (this.closed || this.current === request) return;
46
+ if (!this.queue.includes(request)) this.queue.push(request);
47
+ this.drain();
48
+ }
49
+ isRetiring(request) {
50
+ if (this.current !== request) return false;
51
+ const state = this.player.state;
52
+ return state.status !== loadDiscordVoiceSdk().AudioPlayerStatus.Idle && state.resource.silenceRemaining >= 0;
53
+ }
54
+ cancel(request) {
55
+ this.queue = this.queue.filter((queued) => queued !== request);
56
+ if (this.current !== request) {
57
+ this.drain();
58
+ return;
59
+ }
60
+ this.current = void 0;
61
+ this.transition(() => this.player.stop(true));
62
+ }
63
+ close() {
64
+ if (this.closed) return;
65
+ this.closed = true;
66
+ this.queue = [];
67
+ this.current = void 0;
68
+ this.player.off(loadDiscordVoiceSdk().AudioPlayerStatus.Idle, this.onIdle);
69
+ this.player.stop(true);
70
+ }
71
+ /** Prevent retiring one lane from granting playback to a sibling that is also retiring. */
72
+ transition(action) {
73
+ const wasChanging = this.changing;
74
+ this.changing = true;
75
+ try {
76
+ action();
77
+ } finally {
78
+ this.changing = wasChanging;
79
+ this.drain();
80
+ }
81
+ }
82
+ drain() {
83
+ if (this.closed || this.changing || this.current || this.holds > 0) return;
84
+ const next = this.queue[0];
85
+ if (!next?.isReady()) return;
86
+ this.queue.shift();
87
+ this.current = next;
88
+ this.transition(() => {
89
+ try {
90
+ this.player.play(next.createResource());
91
+ next.onStart();
92
+ } catch (error) {
93
+ this.current = void 0;
94
+ this.player.stop(true);
95
+ next.onError(error);
96
+ }
97
+ });
98
+ }
99
+ };
100
+ //#endregion
101
+ //#region extensions/discord/src/voice/realtime-output.runtime.ts
102
+ const logger = createSubsystemLogger("discord/voice");
103
+ const DISCORD_RAW_PCM_FRAME_BYTES = 3840;
104
+ const DISCORD_RAW_PCM_BYTES_PER_MS = 192;
105
+ const DISCORD_REALTIME_OUTPUT_PREROLL_FRAMES = 25;
106
+ const DISCORD_CONTINUOUS_PREROLL_FRAMES = 6;
107
+ const DISCORD_CONTINUOUS_START_DEADLINE_MS = 120;
108
+ const DISCORD_REALTIME_OUTPUT_PLAYBACK_WATCHDOG_MARGIN_MS = 3e3;
109
+ /** One output stream retains ownership through queued and audible playback. */
110
+ var DiscordRealtimeOutput = class {
111
+ constructor(params) {
112
+ this.params = params;
113
+ this.activity = createRealtimeVoiceOutputActivityTracker();
114
+ this.converter = createRealtimePcmToDiscordConverter();
115
+ this.stream = new PassThrough({ highWaterMark: DISCORD_RAW_PCM_FRAME_BYTES * 128 });
116
+ this.ready = false;
117
+ this.playbackMarks = [];
118
+ this.playedPcmBytes = 0;
119
+ this.lastAudiblePcmEndBytes = 0;
120
+ this.buffers = [];
121
+ this.bufferedBytes = 0;
122
+ this.closed = false;
123
+ this.failed = false;
124
+ this.stream.once("close", () => {
125
+ if (!this.activity.snapshot().playbackStarted) this.close("stream-close");
126
+ });
127
+ }
128
+ pendingBytes() {
129
+ return this.closed ? 0 : Math.max(0, this.activity.snapshot().sourceAudioBytes * 4 - this.playedPcmBytes);
130
+ }
131
+ isAcceptingAudio() {
132
+ return !this.closed && getDiscordAudioOutputStatus(this.params.clock) < DiscordAudioOutputStatus.Retiring && !this.activity.snapshot().streamEnding && (!this.request || !this.params.player.isRetiring(this.request));
133
+ }
134
+ hasUnplayedAudibleAudio() {
135
+ return !this.closed && this.playedPcmBytes < this.lastAudiblePcmEndBytes;
136
+ }
137
+ markPlayback(acknowledge) {
138
+ if (!this.closed) this.playbackMarks.push({
139
+ endBytes: this.activity.snapshot().sinkAudioBytes,
140
+ acknowledge
141
+ });
142
+ }
143
+ append(sourcePcm, audible) {
144
+ if (!this.isAcceptingAudio()) return;
145
+ const previous = this.activity.snapshot();
146
+ const sinkBytes = Math.floor((previous.sourceAudioBytes + sourcePcm.length) / 2) * 8;
147
+ const audioMs = (sinkBytes - previous.sinkAudioBytes) / DISCORD_RAW_PCM_BYTES_PER_MS;
148
+ this.activity.markAudio({
149
+ audioMs,
150
+ sourceAudioBytes: sourcePcm.length,
151
+ sinkAudioBytes: sinkBytes - previous.sinkAudioBytes
152
+ });
153
+ if (audible) {
154
+ this.clearSilenceTimer();
155
+ this.silentSince = void 0;
156
+ this.lastAudiblePcmEndBytes = this.activity.snapshot().sinkAudioBytes;
157
+ }
158
+ this.writeConverted(this.converter.process(sourcePcm));
159
+ this.scheduleSilenceRetirement();
160
+ if (this.params.continuous) this.enqueuePlayback();
161
+ const prerollFrames = this.params.continuous ? DISCORD_CONTINUOUS_PREROLL_FRAMES : DISCORD_REALTIME_OUTPUT_PREROLL_FRAMES;
162
+ if (this.activity.snapshot().sinkAudioBytes >= DISCORD_RAW_PCM_FRAME_BYTES * prerollFrames) this.startPlayback();
163
+ else if (this.params.continuous && !this.ready && !this.startupTimer) {
164
+ this.startupTimer = setTimeout(() => {
165
+ this.startupTimer = void 0;
166
+ this.startPlayback();
167
+ }, DISCORD_CONTINUOUS_START_DEADLINE_MS);
168
+ this.startupTimer.unref?.();
169
+ }
170
+ }
171
+ appendAdmitted(sourcePcm, audible) {
172
+ try {
173
+ this.append(sourcePcm, audible);
174
+ } finally {
175
+ releaseDiscordAudioInput(this.params.clock);
176
+ }
177
+ }
178
+ writeConverted(pcm) {
179
+ if (pcm.length === 0 || this.closed) return;
180
+ if (this.activity.snapshot().playbackStarted && !this.drainHandler) {
181
+ if (!this.stream.write(pcm)) this.waitForDrain();
182
+ return;
183
+ }
184
+ this.buffers.push(pcm);
185
+ this.bufferedBytes += pcm.length;
186
+ }
187
+ finish(reason, playBuffered) {
188
+ if (this.closed) return;
189
+ this.publishRetiring();
190
+ this.clearSilenceTimer();
191
+ if (playBuffered) this.writeConverted(this.converter.flush());
192
+ this.activity.markStreamEnding();
193
+ const activity = this.activity.snapshot();
194
+ logger.info(`discord voice: realtime audio playback finishing reason=${reason} ${this.params.logContext} audioMs=${Math.floor(activity.audioMs)} chunks=${activity.chunks}`);
195
+ if (!playBuffered) {
196
+ this.close(reason);
197
+ return;
198
+ }
199
+ this.startPlayback();
200
+ if (this.activity.snapshot().playbackStarted) {
201
+ this.scheduleWatchdog(reason);
202
+ if (!this.drainHandler) this.stream.end();
203
+ }
204
+ }
205
+ close(reason) {
206
+ if (this.closed) return;
207
+ const playbackRetirement = reason === "player-idle" || reason === "output-pipeline-error" || reason === "playback-watchdog";
208
+ const heardMarks = playbackRetirement ? this.playbackMarks.filter((mark) => mark.endBytes <= this.playedPcmBytes) : [];
209
+ const lostPlaybackMarks = playbackRetirement && this.playbackMarks.some((mark) => mark.endBytes > this.playedPcmBytes);
210
+ this.closed = true;
211
+ setDiscordAudioOutputStatus(this.params.clock, DiscordAudioOutputStatus.Closed);
212
+ this.clearSilenceTimer();
213
+ clearTimeout(this.startupTimer);
214
+ this.startupTimer = void 0;
215
+ this.playbackMarks = [];
216
+ this.clearWatchdog();
217
+ const activity = this.activity.snapshot();
218
+ logger.info(`discord voice: realtime audio playback stopped reason=${reason} ${this.params.logContext} audioMs=${Math.floor(activity.audioMs)} elapsedMs=${this.activity.elapsedPlaybackMs()} chunks=${activity.chunks} discordBytes=${activity.sinkAudioBytes} realtimeBytes=${activity.sourceAudioBytes}`);
219
+ this.buffers = [];
220
+ this.bufferedBytes = 0;
221
+ if (this.drainHandler) {
222
+ this.stream.off("drain", this.drainHandler);
223
+ this.drainHandler = void 0;
224
+ }
225
+ this.stream.end();
226
+ this.stream.destroy();
227
+ if (lostPlaybackMarks) this.params.onError(/* @__PURE__ */ new Error(`Discord realtime audio stopped before playback completed: ${reason}`));
228
+ this.params.onClose(this, reason);
229
+ if (this.request) {
230
+ this.params.player.cancel(this.request);
231
+ this.request = void 0;
232
+ }
233
+ try {
234
+ for (const mark of heardMarks) mark.acknowledge();
235
+ } catch (error) {
236
+ this.params.onError(error);
237
+ }
238
+ }
239
+ startPlayback() {
240
+ if (this.closed || this.ready) return;
241
+ clearTimeout(this.startupTimer);
242
+ this.startupTimer = void 0;
243
+ if (this.bufferedBytes < DISCORD_RAW_PCM_FRAME_BYTES) this.writeConverted(this.converter.drain());
244
+ this.ready = true;
245
+ this.enqueuePlayback();
246
+ }
247
+ publishRetiring() {
248
+ if (!this.closed) setDiscordAudioOutputStatus(this.params.clock, DiscordAudioOutputStatus.Retiring);
249
+ }
250
+ enqueuePlayback() {
251
+ this.request ??= {
252
+ isReady: () => this.ready,
253
+ createResource: () => this.createResource(),
254
+ onStart: () => {
255
+ this.activity.markPlaybackStarted();
256
+ setDiscordAudioOutputStatus(this.params.clock, this.activity.snapshot().streamEnding ? DiscordAudioOutputStatus.Retiring : DiscordAudioOutputStatus.Playing);
257
+ Atomics.store(this.params.clock, 2, 1n);
258
+ this.params.onStart();
259
+ if (this.activity.snapshot().streamEnding) {
260
+ this.scheduleWatchdog("player-start");
261
+ if (!this.drainHandler) this.stream.end();
262
+ }
263
+ },
264
+ onRetiring: () => this.activity.snapshot().sinkAudioBytes <= this.playedPcmBytes && retireDiscordAudioOutput(this.params.clock),
265
+ onIdle: () => this.close(this.failed ? "output-pipeline-error" : "player-idle"),
266
+ onError: this.params.onError
267
+ };
268
+ this.params.player.enqueue(this.request);
269
+ }
270
+ createResource() {
271
+ const voiceSdk = loadDiscordVoiceSdk();
272
+ const opusStream = createDiscordOpusEncodeStream();
273
+ opusStream.once("error", () => {
274
+ this.failed = true;
275
+ });
276
+ pipeline(this.stream, opusStream, (error) => {
277
+ if (!error || this.closed) return;
278
+ logger.warn(`discord voice: realtime output pipeline failed ${this.params.logContext}: ${formatErrorMessage(error)}`);
279
+ this.close("output-pipeline-error");
280
+ });
281
+ const buffered = Buffer.concat(this.buffers, this.bufferedBytes);
282
+ this.buffers = [];
283
+ this.bufferedBytes = 0;
284
+ if (buffered.length > 0 && !this.stream.write(buffered)) this.waitForDrain();
285
+ if (this.params.continuous && buffered.length > 0 && buffered.length < DISCORD_RAW_PCM_FRAME_BYTES) opusStream.flushPartialFrameWhenReady();
286
+ const resource = voiceSdk.createAudioResource(opusStream, { inputType: voiceSdk.StreamType.Opus });
287
+ const read = resource.read.bind(resource);
288
+ resource.read = () => {
289
+ if (this.params.isOpen?.() === false || getDiscordAudioOutputStatus(this.params.clock) === DiscordAudioOutputStatus.Closed) {
290
+ this.close("port-closed");
291
+ return null;
292
+ }
293
+ let packet;
294
+ try {
295
+ packet = read();
296
+ if (!packet && opusStream.flushPartialFrame()) packet = read();
297
+ if (packet) {
298
+ this.playedPcmBytes += opusStream.takePcmBytes(packet);
299
+ Atomics.store(this.params.clock, 0, BigInt(this.playedPcmBytes));
300
+ if (resource.silenceRemaining >= 0) this.publishRetiring();
301
+ const remaining = this.activity.snapshot().sinkAudioBytes - this.playedPcmBytes;
302
+ if (remaining > 0 && remaining <= DISCORD_RAW_PCM_FRAME_BYTES) this.writeConverted(this.converter.drain());
303
+ this.scheduleSilenceRetirement();
304
+ }
305
+ } catch (error) {
306
+ opusStream.destroy(error instanceof Error ? error : new Error(formatErrorMessage(error)));
307
+ return null;
308
+ }
309
+ if (this.playbackMarks.length > 0) queueMicrotask(() => this.acknowledgePlayedMarks());
310
+ return packet;
311
+ };
312
+ return resource;
313
+ }
314
+ acknowledgePlayedMarks() {
315
+ try {
316
+ while (!this.closed) {
317
+ const mark = this.playbackMarks[0];
318
+ if (!mark || mark.endBytes > this.playedPcmBytes) return;
319
+ this.playbackMarks.shift();
320
+ mark.acknowledge();
321
+ }
322
+ } catch (error) {
323
+ this.params.onError(error);
324
+ }
325
+ }
326
+ scheduleSilenceRetirement() {
327
+ const activity = this.activity.snapshot();
328
+ if (!this.params.continuous || this.closed || activity.streamEnding || !activity.playbackStarted || this.hasUnplayedAudibleAudio()) return;
329
+ this.silentSince ??= performance.now();
330
+ if (activity.sinkAudioBytes <= this.lastAudiblePcmEndBytes || this.silenceTimer) return;
331
+ this.silenceTimer = setTimeout(() => {
332
+ this.silenceTimer = void 0;
333
+ if (!this.closed && !this.activity.snapshot().streamEnding && !this.hasUnplayedAudibleAudio() && retireDiscordAudioOutput(this.params.clock)) this.finish("continuous-idle", true);
334
+ }, Math.max(0, DISCORD_REALTIME_PLAYBACK_IDLE_MS - (performance.now() - this.silentSince)));
335
+ this.silenceTimer.unref?.();
336
+ }
337
+ clearSilenceTimer() {
338
+ clearTimeout(this.silenceTimer);
339
+ this.silenceTimer = void 0;
340
+ }
341
+ waitForDrain() {
342
+ if (this.drainHandler || this.closed) return;
343
+ logger.info(`discord voice: realtime audio playback buffering ${this.params.logContext} bufferedBytes=${this.stream.writableLength + this.stream.readableLength}`);
344
+ this.drainHandler = () => {
345
+ this.drainHandler = void 0;
346
+ if (this.closed) return;
347
+ let refreshWatchdog = this.activity.snapshot().streamEnding;
348
+ while (this.buffers.length > 0) {
349
+ const buffered = this.buffers.shift();
350
+ if (!buffered) break;
351
+ this.bufferedBytes -= buffered.length;
352
+ const writable = this.stream.write(buffered);
353
+ if (refreshWatchdog) {
354
+ this.scheduleWatchdog("output-drain");
355
+ refreshWatchdog = false;
356
+ }
357
+ if (!writable) {
358
+ this.waitForDrain();
359
+ return;
360
+ }
361
+ }
362
+ if (this.activity.snapshot().streamEnding) this.stream.end();
363
+ };
364
+ this.stream.once("drain", this.drainHandler);
365
+ }
366
+ scheduleWatchdog(reason) {
367
+ this.clearWatchdog();
368
+ const timeoutMs = this.activity.playbackWatchdogDelayMs({
369
+ marginMs: DISCORD_REALTIME_OUTPUT_PLAYBACK_WATCHDOG_MARGIN_MS,
370
+ minMs: DISCORD_REALTIME_OUTPUT_PLAYBACK_WATCHDOG_MARGIN_MS
371
+ });
372
+ if (timeoutMs === void 0) return;
373
+ this.watchdog = setTimeout(() => {
374
+ this.watchdog = void 0;
375
+ logger.warn(`discord voice: realtime audio playback watchdog fired reason=${reason} ${this.params.logContext} audioMs=${Math.floor(this.activity.snapshot().audioMs)} elapsedMs=${this.activity.elapsedPlaybackMs()}`);
376
+ this.close("playback-watchdog");
377
+ }, timeoutMs);
378
+ }
379
+ clearWatchdog() {
380
+ clearTimeout(this.watchdog);
381
+ this.watchdog = void 0;
382
+ }
383
+ };
384
+ //#endregion
385
+ //#region extensions/discord/src/voice/continuous-output.runtime.ts
386
+ /** A transferred endpoint is owned by one already-admitted provider generation.
387
+ * No socket, response policy, credential, or speaker admission crosses this port. */
388
+ var DiscordContinuousOutput = class {
389
+ constructor(params) {
390
+ this.params = params;
391
+ this.outputs = /* @__PURE__ */ new Set();
392
+ this.closed = false;
393
+ this.enabled = params.enabled;
394
+ params.port.on("message", (message) => {
395
+ try {
396
+ if (this.closed || Atomics.load(params.state, 0) !== 0) return;
397
+ if (message.type === "flushed") {
398
+ params.post({
399
+ type: "continuous-flushed",
400
+ id: params.id,
401
+ marker: message.marker
402
+ });
403
+ return;
404
+ }
405
+ if (!this.enabled) return;
406
+ if (message.type === "audio") this.append(Buffer.from(message.audio));
407
+ else if (message.type === "clear") this.clear();
408
+ } catch (error) {
409
+ this.fail(error);
410
+ } finally {
411
+ if (message.type === "audio") params.port.postMessage({ type: "ack" }, []);
412
+ }
413
+ });
414
+ params.port.on("messageerror", (error) => this.fail(error));
415
+ params.port.on("close", () => this.close());
416
+ }
417
+ append(audio) {
418
+ if (!audio.length) return;
419
+ if (this.generating && !this.generating.isAcceptingAudio()) this.generating = void 0;
420
+ const audible = isRealtimeVoiceAudioAudible(audio, REALTIME_VOICE_AUDIO_FORMAT_PCM16_24KHZ);
421
+ if (!audible && !this.generating) return;
422
+ if ([...this.outputs].reduce((total, output) => total + output.pendingBytes(), 0) + audio.length * 4 > 2304e4 || !this.generating && this.outputs.size >= 32) throw new Error("Discord realtime direct audio backlog exceeded.");
423
+ if (!this.generating) {
424
+ const latch = Atomics.load(this.params.clock, 2);
425
+ const speechEpoch = latch < 0n ? -latch : latch;
426
+ const output = new DiscordRealtimeOutput({
427
+ player: this.params.player,
428
+ clock: new BigInt64Array(new SharedArrayBuffer(24)),
429
+ continuous: true,
430
+ logContext: this.params.logContext,
431
+ isOpen: () => {
432
+ const current = Atomics.load(this.params.clock, 2);
433
+ return !this.closed && this.enabled && Atomics.load(this.params.state, 0) === 0 && (current === speechEpoch || current === -speechEpoch);
434
+ },
435
+ onStart: () => {
436
+ const current = Atomics.compareExchange(this.params.clock, 2, speechEpoch, -speechEpoch);
437
+ if (current !== speechEpoch && current !== -speechEpoch) {
438
+ output.close("exact-speech-retired");
439
+ return;
440
+ }
441
+ this.params.post({
442
+ type: "continuous-start",
443
+ id: this.params.id,
444
+ speechEpoch
445
+ });
446
+ },
447
+ onClose: (closed) => {
448
+ this.outputs.delete(closed);
449
+ if (this.generating === closed) this.generating = void 0;
450
+ Atomics.store(this.params.clock, 0, BigInt(this.outputs.size));
451
+ if (this.outputs.size === 0) {
452
+ Atomics.store(this.params.clock, 1, 0n);
453
+ this.params.post({
454
+ type: "continuous-idle",
455
+ id: this.params.id,
456
+ speechEpoch
457
+ });
458
+ }
459
+ },
460
+ onError: (error) => this.fail(error)
461
+ });
462
+ this.outputs.add(output);
463
+ this.generating = output;
464
+ Atomics.store(this.params.clock, 0, BigInt(this.outputs.size));
465
+ }
466
+ Atomics.add(this.params.clock, 1, BigInt(audio.length));
467
+ this.generating.append(audio, audible);
468
+ }
469
+ activate() {
470
+ this.enabled = true;
471
+ }
472
+ flush(marker) {
473
+ if (!this.closed) this.params.port.postMessage({
474
+ type: "flush",
475
+ marker
476
+ }, []);
477
+ }
478
+ clear() {
479
+ this.generating = void 0;
480
+ this.params.player.transition(() => {
481
+ for (const output of [...this.outputs].toReversed()) output.close("provider-clear");
482
+ });
483
+ }
484
+ close() {
485
+ if (this.closed) return;
486
+ this.closed = true;
487
+ Atomics.store(this.params.state, 0, 1);
488
+ this.clear();
489
+ this.params.port.close();
490
+ }
491
+ fail(error) {
492
+ if (this.closed) return;
493
+ this.params.post({
494
+ type: "continuous-error",
495
+ id: this.params.id,
496
+ error: serializeDiscordAudioError(error)
497
+ });
498
+ this.close();
499
+ }
500
+ };
501
+ //#endregion
502
+ //#region extensions/discord/src/voice/audio-worker.ts
503
+ const PLAYBACK_READY_TIMEOUT_MS = 6e4;
504
+ const MAX_CAPTURE_PACKETS = 1e3;
505
+ const MAX_CAPTURE_BYTES = 1048576;
506
+ /** Owns every Discord socket, codec, resource and packet deadline in one isolate. */
507
+ var DiscordAudioWorker = class {
508
+ constructor(options, post) {
509
+ this.options = options;
510
+ this.post = post;
511
+ this.sdk = loadDiscordVoiceSdk();
512
+ this.captures = /* @__PURE__ */ new Map();
513
+ this.outputs = /* @__PURE__ */ new Map();
514
+ this.continuous = /* @__PURE__ */ new Map();
515
+ this.stopped = false;
516
+ this.stopAbort = new AbortController();
517
+ this.tasks = /* @__PURE__ */ new Set();
518
+ this.onError = (error) => this.post({
519
+ type: "error",
520
+ error: serializeDiscordAudioError(error)
521
+ });
522
+ this.onDisconnected = () => {
523
+ if (!this.stopped && this.connection) this.recoverConnection(this.connection);
524
+ };
525
+ this.onDestroyed = () => {
526
+ this.stop();
527
+ };
528
+ this.onSpeakingStart = (userId) => {
529
+ if (this.stopped) return;
530
+ for (const capture of this.captures.values()) if (capture.userId === userId) {
531
+ clearTimeout(capture.timer);
532
+ capture.timer = void 0;
533
+ }
534
+ this.post({
535
+ type: "speaking",
536
+ userId,
537
+ speaking: true
538
+ });
539
+ };
540
+ this.onSpeakingEnd = (userId) => {
541
+ if (this.stopped) return;
542
+ for (const [id, capture] of this.captures) if (capture.userId === userId) this.finalizeLater(id, capture);
543
+ this.post({
544
+ type: "speaking",
545
+ userId,
546
+ speaking: false
547
+ });
548
+ };
549
+ this.player = options.realtime ? this.sdk.createAudioPlayer({ behaviors: { maxMissedFrames: DISCORD_REALTIME_PLAYBACK_IDLE_MS / 20 } }) : this.sdk.createAudioPlayer();
550
+ this.roomPlayer = new DiscordRealtimePlayer(this.player);
551
+ this.player.on("stateChange", (_old, state) => this.post({
552
+ type: "player",
553
+ status: state.status
554
+ }));
555
+ this.player.on("error", this.onError);
556
+ }
557
+ async connect() {
558
+ const deadline = Date.now() + this.options.connectTimeoutMs;
559
+ for (let attempt = 0; attempt < 2; attempt += 1) {
560
+ if (this.stopped) return;
561
+ const connection = this.sdk.joinVoiceChannel({
562
+ guildId: this.options.guildId,
563
+ channelId: this.options.channelId,
564
+ group: this.options.group,
565
+ selfDeaf: this.options.selfDeaf,
566
+ selfMute: this.options.selfMute,
567
+ daveEncryption: this.options.daveEncryption,
568
+ decryptionFailureTolerance: this.options.decryptionFailureTolerance,
569
+ adapterCreator: (methods) => {
570
+ this.adapter = methods;
571
+ return {
572
+ sendPayload: (payload) => {
573
+ this.post({
574
+ type: "gateway-send",
575
+ payload
576
+ });
577
+ return true;
578
+ },
579
+ destroy: () => {}
580
+ };
581
+ }
582
+ });
583
+ this.connection = connection;
584
+ connection.on("error", this.onError);
585
+ try {
586
+ await this.sdk.entersState(connection, this.sdk.VoiceConnectionStatus.Ready, AbortSignal.any([this.stopAbort.signal, AbortSignal.timeout(Math.max(1, deadline - Date.now()))]));
587
+ if (this.stopped) return;
588
+ connection.subscribe(this.player);
589
+ connection.on("stateChange", (_old, state) => {
590
+ this.post({
591
+ type: "connection",
592
+ status: state.status
593
+ });
594
+ });
595
+ connection.on(this.sdk.VoiceConnectionStatus.Destroyed, this.onDestroyed);
596
+ connection.on(this.sdk.VoiceConnectionStatus.Disconnected, this.onDisconnected);
597
+ connection.receiver.speaking.on("start", this.onSpeakingStart);
598
+ connection.receiver.speaking.on("end", this.onSpeakingEnd);
599
+ for (const userId of connection.receiver.speaking.users.keys()) this.post({
600
+ type: "speaking",
601
+ userId,
602
+ speaking: true
603
+ });
604
+ this.post({
605
+ type: "connection",
606
+ status: connection.state.status
607
+ });
608
+ this.post({ type: "ready" });
609
+ return;
610
+ } catch (error) {
611
+ if (this.stopped) return;
612
+ if (connection.state.status !== this.sdk.VoiceConnectionStatus.Destroyed) connection.destroy();
613
+ if (attempt === 0 && !this.stopped && Date.now() < deadline && error instanceof Error && error.message.toLowerCase().includes("operation was aborted")) continue;
614
+ throw error;
615
+ }
616
+ }
617
+ }
618
+ receive(command) {
619
+ if (this.stopped) return;
620
+ switch (command.type) {
621
+ case "gateway-server":
622
+ this.adapter?.onVoiceServerUpdate(command.data);
623
+ break;
624
+ case "gateway-state":
625
+ this.adapter?.onVoiceStateUpdate(command.data);
626
+ break;
627
+ case "gateway-failed":
628
+ this.post({
629
+ type: "error",
630
+ error: {
631
+ name: "Error",
632
+ message: "Discord main gateway could not send voice signalling."
633
+ }
634
+ });
635
+ this.adapter?.destroy();
636
+ this.stop();
637
+ break;
638
+ case "stop":
639
+ this.stop();
640
+ break;
641
+ case "continuous-port": {
642
+ const lane = new DiscordContinuousOutput({
643
+ id: command.id,
644
+ enabled: command.enabled,
645
+ port: command.port,
646
+ state: new Int32Array(command.state),
647
+ clock: new BigInt64Array(command.clock),
648
+ player: this.roomPlayer,
649
+ post: this.post,
650
+ logContext: "guild=" + this.options.guildId + " channel=" + this.options.channelId
651
+ });
652
+ this.continuous.set(command.id, lane);
653
+ command.port.once("close", () => this.continuous.delete(command.id));
654
+ break;
655
+ }
656
+ case "continuous-activate":
657
+ this.continuous.get(command.id)?.activate();
658
+ break;
659
+ case "continuous-clear":
660
+ this.continuous.get(command.id)?.clear();
661
+ break;
662
+ case "continuous-flush":
663
+ this.continuous.get(command.id)?.flush(command.marker);
664
+ break;
665
+ case "continuous-close":
666
+ this.continuous.get(command.id)?.close();
667
+ this.continuous.delete(command.id);
668
+ break;
669
+ case "capture":
670
+ this.track(this.capture(command.id, command.userId, command.recordingEpoch));
671
+ break;
672
+ case "capture-stop": {
673
+ const capture = this.captures.get(command.id);
674
+ if (capture) this.stopCapture(capture);
675
+ break;
676
+ }
677
+ case "capture-ack": {
678
+ const capture = this.captures.get(command.id);
679
+ if (capture) {
680
+ capture.pendingPackets = Math.max(0, capture.pendingPackets - 1);
681
+ capture.pendingBytes = Math.max(0, capture.pendingBytes - command.bytes);
682
+ }
683
+ break;
684
+ }
685
+ case "passthrough":
686
+ this.enablePassthrough(command.reason, command.expirySeconds);
687
+ break;
688
+ case "output-create": {
689
+ const output = new DiscordRealtimeOutput({
690
+ player: this.roomPlayer,
691
+ clock: new BigInt64Array(command.clock),
692
+ logContext: "guild=" + this.options.guildId + " channel=" + this.options.channelId,
693
+ continuous: command.continuous,
694
+ onStart: () => this.post({
695
+ type: "output-start",
696
+ id: command.id
697
+ }),
698
+ onClose: (_output, reason) => {
699
+ this.outputs.delete(command.id);
700
+ queueMicrotask(() => this.post({
701
+ type: "output-close",
702
+ id: command.id,
703
+ reason
704
+ }));
705
+ },
706
+ onError: (error) => this.post({
707
+ type: "output-error",
708
+ id: command.id,
709
+ error: serializeDiscordAudioError(error)
710
+ })
711
+ });
712
+ this.outputs.set(command.id, output);
713
+ break;
714
+ }
715
+ case "output-audio":
716
+ this.outputs.get(command.id)?.appendAdmitted(Buffer.from(command.audio), command.audible);
717
+ break;
718
+ case "output-mark":
719
+ this.outputs.get(command.id)?.markPlayback(() => this.post({
720
+ type: "output-mark",
721
+ id: command.id,
722
+ markId: command.markId
723
+ }));
724
+ break;
725
+ case "output-finish":
726
+ this.outputs.get(command.id)?.finish(command.reason, command.playBuffered);
727
+ break;
728
+ case "output-close":
729
+ this.outputs.get(command.id)?.close(command.reason);
730
+ break;
731
+ case "output-hold":
732
+ this.roomPlayer.hold(command.hold);
733
+ break;
734
+ case "output-shutdown":
735
+ this.retireOutputs();
736
+ break;
737
+ case "player-stop":
738
+ this.fileAbort?.abort();
739
+ this.player.stop(true);
740
+ break;
741
+ case "file-play":
742
+ this.track(this.playFile(command.id, command.path));
743
+ break;
744
+ case "stream-play": {
745
+ const stream = new PassThrough();
746
+ this.fileInput = {
747
+ id: command.id,
748
+ stream
749
+ };
750
+ this.track(this.playFile(command.id, stream));
751
+ break;
752
+ }
753
+ case "stream-chunk":
754
+ if (this.fileInput?.id !== command.id) break;
755
+ if (this.fileInput.stream.write(Buffer.from(command.audio))) this.post({
756
+ type: "stream-drain",
757
+ id: command.id
758
+ });
759
+ else this.fileInput.stream.once("drain", () => this.post({
760
+ type: "stream-drain",
761
+ id: command.id
762
+ }));
763
+ break;
764
+ case "stream-end": if (this.fileInput?.id === command.id) this.fileInput.stream.end();
765
+ }
766
+ }
767
+ retireOutputs() {
768
+ this.roomPlayer.transition(() => {
769
+ for (const lane of this.continuous.values()) lane.close();
770
+ this.continuous.clear();
771
+ const retiring = [...this.outputs.values()];
772
+ for (const output of retiring) output.close("session-close");
773
+ });
774
+ }
775
+ async recoverConnection(connection) {
776
+ const recovery = new AbortController();
777
+ const signal = AbortSignal.any([
778
+ this.stopAbort.signal,
779
+ recovery.signal,
780
+ AbortSignal.timeout(this.options.reconnectGraceMs)
781
+ ]);
782
+ try {
783
+ await Promise.race([this.sdk.entersState(connection, this.sdk.VoiceConnectionStatus.Signalling, signal), this.sdk.entersState(connection, this.sdk.VoiceConnectionStatus.Connecting, signal)]);
784
+ } catch (error) {
785
+ if (!this.stopped) {
786
+ this.post({
787
+ type: "error",
788
+ error: serializeDiscordAudioError(error)
789
+ });
790
+ await this.stop();
791
+ }
792
+ } finally {
793
+ recovery.abort();
794
+ }
795
+ }
796
+ enablePassthrough(reason, expirySeconds) {
797
+ if (!this.connection) return;
798
+ enableDaveReceivePassthrough({
799
+ target: {
800
+ guildId: this.options.guildId,
801
+ channelId: this.options.channelId,
802
+ connection: this.connection
803
+ },
804
+ sdk: this.sdk,
805
+ reason,
806
+ expirySeconds,
807
+ onVerbose: (message) => this.post({
808
+ type: "log",
809
+ level: "verbose",
810
+ message
811
+ }),
812
+ onWarn: (message) => this.post({
813
+ type: "log",
814
+ level: "warn",
815
+ message
816
+ })
817
+ });
818
+ }
819
+ stopCapture(capture) {
820
+ if (capture.closed) return;
821
+ capture.closed = true;
822
+ clearTimeout(capture.timer);
823
+ if (!capture.stream.destroyed) capture.stream.destroy();
824
+ }
825
+ finalizeLater(id, capture) {
826
+ clearTimeout(capture.timer);
827
+ capture.timer = setTimeout(() => {
828
+ if (this.captures.get(id) === capture) this.stopCapture(capture);
829
+ }, this.options.captureSilenceGraceMs);
830
+ }
831
+ async capture(id, userId, recordingEpoch) {
832
+ const connection = this.connection;
833
+ if (!connection || this.captures.has(id)) return;
834
+ const stream = connection.receiver.subscribe(userId, { end: { behavior: this.sdk.EndBehaviorType.Manual } });
835
+ const capture = {
836
+ userId,
837
+ stream,
838
+ pendingPackets: 0,
839
+ pendingBytes: 0,
840
+ closed: false
841
+ };
842
+ this.captures.set(id, capture);
843
+ const input = new PassThrough({ objectMode: true });
844
+ const recordingClock = new BigInt64Array(recordingEpoch);
845
+ const receipts = /* @__PURE__ */ new WeakMap();
846
+ let failed = false;
847
+ let abortReported = false;
848
+ let decodedFrames = 0;
849
+ const onError = (error) => {
850
+ if (failed) return;
851
+ const analysis = analyzeVoiceReceiveError(error);
852
+ if (analysis.isAbortLike && !analysis.countsAsDecryptFailure) {
853
+ if (!abortReported) this.post({
854
+ type: "capture-error",
855
+ id,
856
+ error: serializeDiscordAudioError(error)
857
+ });
858
+ abortReported = true;
859
+ return;
860
+ }
861
+ failed = true;
862
+ let recovery = "not-attempted";
863
+ if (analysis.shouldAttemptPassthrough) {
864
+ recovery = recoverDaveZeroTransition({
865
+ target: {
866
+ guildId: this.options.guildId,
867
+ channelId: this.options.channelId,
868
+ connection
869
+ },
870
+ sdk: this.sdk,
871
+ onWarn: (message) => this.post({
872
+ type: "log",
873
+ level: "warn",
874
+ message
875
+ })
876
+ });
877
+ if (recovery !== "failed") this.enablePassthrough("receive decrypt error", 15);
878
+ }
879
+ this.post({
880
+ type: "capture-error",
881
+ id,
882
+ error: {
883
+ ...serializeDiscordAudioError(error),
884
+ ...recovery === "failed" ? { daveRecoveryFailed: true } : {}
885
+ }
886
+ });
887
+ };
888
+ const accept = (packet) => {
889
+ if (failed || capture.closed || !packet.length) return;
890
+ if (capture.pendingPackets >= MAX_CAPTURE_PACKETS || capture.pendingBytes + packet.length > MAX_CAPTURE_BYTES) {
891
+ onError(/* @__PURE__ */ new Error("Discord voice receive backlog exceeded; try speaking again."));
892
+ this.stopCapture(capture);
893
+ input.destroy();
894
+ return;
895
+ }
896
+ capture.pendingPackets += 1;
897
+ capture.pendingBytes += packet.length;
898
+ const owned = Buffer.from(packet);
899
+ receipts.set(owned, {
900
+ receivedAt: Date.now(),
901
+ recordingEpoch: Atomics.load(recordingClock, 0)
902
+ });
903
+ input.write(owned);
904
+ };
905
+ const end = () => input.end();
906
+ const finalized = () => {
907
+ clearTimeout(capture.timer);
908
+ capture.closed = true;
909
+ this.post({
910
+ type: "capture-finalized",
911
+ id
912
+ });
913
+ input.end();
914
+ };
915
+ stream.on("data", accept);
916
+ stream.on("end", end);
917
+ stream.once("close", finalized);
918
+ stream.on("error", onError);
919
+ if (!connection.receiver.speaking.users.has(userId)) this.finalizeLater(id, capture);
920
+ try {
921
+ await decodeOpusStreamChunks(input, {
922
+ onChunk: async (pcm, packet) => {
923
+ const receipt = receipts.get(packet);
924
+ if (!failed && receipt) this.post({
925
+ type: "capture-frame",
926
+ id,
927
+ frame: {
928
+ pcm,
929
+ packet,
930
+ ...receipt
931
+ }
932
+ });
933
+ if (++decodedFrames % 8 === 0) await new Promise((resolve) => {
934
+ setImmediate(resolve);
935
+ });
936
+ },
937
+ onError,
938
+ onVerbose: (message) => this.post({
939
+ type: "log",
940
+ level: "verbose",
941
+ message
942
+ }),
943
+ onWarn: (message) => this.post({
944
+ type: "log",
945
+ level: "warn",
946
+ message
947
+ })
948
+ });
949
+ } finally {
950
+ clearTimeout(capture.timer);
951
+ this.captures.delete(id);
952
+ stream.off("data", accept);
953
+ stream.off("end", end);
954
+ stream.off("error", onError);
955
+ this.stopCapture(capture);
956
+ input.destroy();
957
+ this.post({
958
+ type: "capture-end",
959
+ id
960
+ });
961
+ }
962
+ }
963
+ async playFile(id, input) {
964
+ const abort = new AbortController();
965
+ this.fileAbort?.abort();
966
+ this.fileAbort = abort;
967
+ let error;
968
+ const onError = (cause) => {
969
+ error = serializeDiscordAudioError(cause);
970
+ abort.abort();
971
+ };
972
+ let playbackStarted = false;
973
+ const onIdle = () => {
974
+ if (!playbackStarted) abort.abort();
975
+ };
976
+ this.player.on("error", onError);
977
+ this.player.on(this.sdk.AudioPlayerStatus.Idle, onIdle);
978
+ try {
979
+ this.player.play(this.sdk.createAudioResource(createDiscordOpusPlaybackStream(input), { inputType: this.sdk.StreamType.Opus }));
980
+ await this.sdk.entersState(this.player, this.sdk.AudioPlayerStatus.Playing, AbortSignal.any([AbortSignal.timeout(PLAYBACK_READY_TIMEOUT_MS), abort.signal]));
981
+ playbackStarted = true;
982
+ await this.sdk.entersState(this.player, this.sdk.AudioPlayerStatus.Idle, abort.signal);
983
+ } catch (cause) {
984
+ error ??= serializeDiscordAudioError(cause);
985
+ } finally {
986
+ this.player.off("error", onError);
987
+ this.player.off(this.sdk.AudioPlayerStatus.Idle, onIdle);
988
+ if (this.fileAbort === abort) this.fileAbort = void 0;
989
+ if (this.fileInput?.id === id) {
990
+ this.fileInput.stream.destroy();
991
+ this.fileInput = void 0;
992
+ }
993
+ this.post({
994
+ type: "file-end",
995
+ id,
996
+ ...error ? { error } : {}
997
+ });
998
+ }
999
+ }
1000
+ track(task) {
1001
+ this.tasks.add(task);
1002
+ task.catch(this.onError).finally(() => this.tasks.delete(task));
1003
+ }
1004
+ async stop() {
1005
+ if (this.stopped) return;
1006
+ this.stopped = true;
1007
+ this.stopAbort.abort();
1008
+ this.post({
1009
+ type: "connection",
1010
+ status: this.sdk.VoiceConnectionStatus.Destroyed
1011
+ });
1012
+ this.retireOutputs();
1013
+ this.roomPlayer.close();
1014
+ this.fileAbort?.abort();
1015
+ this.fileInput?.stream.destroy();
1016
+ for (const capture of this.captures.values()) this.stopCapture(capture);
1017
+ const connection = this.connection;
1018
+ connection?.receiver.speaking.off("start", this.onSpeakingStart);
1019
+ connection?.receiver.speaking.off("end", this.onSpeakingEnd);
1020
+ connection?.off(this.sdk.VoiceConnectionStatus.Disconnected, this.onDisconnected);
1021
+ connection?.off(this.sdk.VoiceConnectionStatus.Destroyed, this.onDestroyed);
1022
+ this.player.off("error", this.onError);
1023
+ if (connection && connection.state.status !== this.sdk.VoiceConnectionStatus.Destroyed) connection.destroy();
1024
+ this.post({ type: "gateway-destroy" });
1025
+ await Promise.allSettled(this.tasks);
1026
+ this.post({ type: "stopped" });
1027
+ }
1028
+ };
1029
+ //#endregion
1030
+ //#region extensions/discord/src/voice/audio-worker.runtime.ts
1031
+ const port = parentPort;
1032
+ if (!port) throw new Error("Discord audio runtime requires a worker MessagePort.");
1033
+ const media = new DiscordAudioWorker(workerData, (event) => {
1034
+ port.postMessage(event);
1035
+ if (event.type === "stopped") port.close();
1036
+ });
1037
+ const fail = (error) => {
1038
+ port.postMessage({
1039
+ type: "error",
1040
+ error: serializeDiscordAudioError(error)
1041
+ });
1042
+ media.stop();
1043
+ };
1044
+ port.on("message", (command) => {
1045
+ try {
1046
+ media.receive(command);
1047
+ } catch (error) {
1048
+ fail(error);
1049
+ }
1050
+ });
1051
+ port.on("close", () => {
1052
+ media.stop();
1053
+ });
1054
+ media.connect().catch(fail);
1055
+ //#endregion
1056
+ export {};