@openclaw/discord 2026.9.5 → 2026.9.6

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 (421) hide show
  1. package/dist/.setup/{activities-api-DBwRt5ES.mjs → activities-api-COU4-0nR.mjs} +4 -4
  2. package/dist/.setup/{approval-handler.runtime-Du3n5ypX.mjs → approval-handler.runtime-CbBktBb4.mjs} +5 -5
  3. package/dist/.setup/{approval-message-updates-BN7JtScm.mjs → approval-message-updates-jf9zMaIC.mjs} +1 -1
  4. package/dist/.setup/{audit-C8uaKoa9.mjs → audit-vKbh-LFR.mjs} +3 -3
  5. package/dist/.setup/{channel-ChKdlBgH.mjs → channel-Dv4e3Jpc.mjs} +19 -16
  6. package/dist/.setup/{channel-actions.runtime-CJmiFfps.mjs → channel-actions.runtime-leZuw01r.mjs} +13 -7
  7. package/dist/.setup/{channel.setup-BlC3-Kzz.mjs → channel.setup-0NX6FFwi.mjs} +1 -1
  8. package/dist/.setup/{components-MqMWUWnE.mjs → components-yBEb75bB.mjs} +1 -2
  9. package/dist/.setup/{conversation-binding-route-_rz33QHO.mjs → conversation-binding-route-B7qImK_b.mjs} +6 -3
  10. package/dist/.setup/{doctor-DxcdkXzz.mjs → doctor-D1R-uFIu.mjs} +2 -2
  11. package/dist/.setup/{handle-action.guild-admin-DAFyh_yV.mjs → handle-action.guild-admin-DcFa8NwA.mjs} +3 -3
  12. package/dist/.setup/{message-handler-DnUrDpaU.mjs → message-handler-X6ejmbtY.mjs} +6 -5
  13. package/dist/.setup/{message-handler.preflight-CtqaF_fb.mjs → message-handler.preflight-DE_POxFc.mjs} +14 -117
  14. package/dist/.setup/message-handler.preflight-pluralkit-8Xji34AF.mjs +143 -0
  15. package/dist/.setup/{message-handler.process-Dz1xvuQU.mjs → message-handler.process-CCmIVnxy.mjs} +387 -317
  16. package/dist/.setup/{outbound-adapter-C8v79z9Z.mjs → outbound-adapter-ClIgmu4F.mjs} +5 -5
  17. package/dist/.setup/{outbound-session-route-CqWbuMOm.mjs → outbound-session-route-VulUE0yV.mjs} +7 -6
  18. package/dist/.setup/{preflight-audio-DrnqFA8U.mjs → preflight-audio-DHGIHEpv.mjs} +2 -1
  19. package/dist/.setup/{provider-72zIvN-i.mjs → provider-iOf73HW-.mjs} +425 -286
  20. package/dist/.setup/{provider-session.runtime-BW7QrF5C.mjs → provider-session.runtime-DrGAYnZv.mjs} +3 -3
  21. package/dist/.setup/provider.runtime-BmjW_pIw.mjs +2 -0
  22. package/dist/.setup/{realtime-session.runtime-DTccTgTM.mjs → realtime-session.runtime-Dz8uVutq.mjs} +338 -297
  23. package/dist/.setup/receive-recovery-DHst8WRx.mjs +517 -0
  24. package/dist/.setup/{retry-DBfcEgmO.mjs → retry-BEYkDy0P.mjs} +78 -13
  25. package/dist/.setup/{runtime-SchNfUsQ.mjs → runtime-B8lJfyrA.mjs} +30 -11
  26. package/dist/.setup/{runtime-BVoa7hhx.mjs → runtime-DisDbixd.mjs} +1 -1
  27. package/dist/.setup/{send-CKDczUNL.mjs → send-CIBzvXjS.mjs} +23 -9
  28. package/dist/.setup/{send.components-DWQjXhPV.mjs → send.components-ChY21qr-.mjs} +4 -4
  29. package/dist/.setup/{send.outbound-D0hQ7s50.mjs → send.outbound-QTyuFupn.mjs} +15 -16
  30. package/dist/.setup/{send.shared-Zwx6BxQ5.mjs → send.shared-VNvWfX2T.mjs} +2 -2
  31. package/dist/.setup/setup-plugin-api-Dvr41dyx.mjs +3 -0
  32. package/dist/.setup/{shared-CaA3Vv4n.mjs → shared-DHPDaMSx.mjs} +1 -1
  33. package/dist/.setup/{subagent-hooks-Bired9q6.mjs → subagent-hooks-CjW7r8Pe.mjs} +1 -1
  34. package/dist/.setup/{target-resolver-B6MrxbYv.mjs → target-resolver-BXpy6VT8.mjs} +1 -1
  35. package/dist/.setup/targets-CvemhN3i.mjs +3 -0
  36. package/dist/.setup/{thread-bindings-CK5272V3.mjs → thread-bindings-CEh2dhqP.mjs} +3 -3
  37. package/dist/.setup/{thread-bindings.manager-eexkKyrG.mjs → thread-bindings.manager-ve-i6oqt.mjs} +94 -45
  38. package/dist/.setup/{transcripts-source-CuWYgayu.mjs → transcripts-source-DVegW0WI.mjs} +61 -7
  39. package/dist/.setup/{voice-runtime-DHVQ2mFz.mjs → voice-runtime-elTtjEIG.mjs} +553 -901
  40. package/dist/action-runtime-api.js +1 -1
  41. package/dist/activities-api.js +1 -1
  42. package/dist/api.js +10 -10
  43. package/dist/channel-plugin-api.js +1 -1
  44. package/dist/index.js +1 -1
  45. package/dist/runtime-api.js +12 -12
  46. package/dist/setup-entry.js +1 -1
  47. package/dist/setup-plugin-api.js +1 -1
  48. package/dist/src/voice/audio-worker.runtime.js +1065 -0
  49. package/dist/subagent-hooks-api.js +1 -1
  50. package/dist/transcripts-source-api.js +1 -1
  51. package/node_modules/@napi-rs/wasm-runtime/dist/emnapi-plugins.cjs +8 -4
  52. package/node_modules/@napi-rs/wasm-runtime/dist/emnapi-plugins.js +8 -4
  53. package/node_modules/@napi-rs/wasm-runtime/dist/fs-proxy.cjs +1 -1
  54. package/node_modules/@napi-rs/wasm-runtime/dist/fs.js +770 -695
  55. package/node_modules/@napi-rs/wasm-runtime/fs-proxy.js +3 -2
  56. package/node_modules/@napi-rs/wasm-runtime/package.json +1 -1
  57. package/node_modules/@tybys/wasm-util/LICENSE +21 -0
  58. package/node_modules/@tybys/wasm-util/package.json +1 -1
  59. package/node_modules/@types/node/README.md +1 -1
  60. package/node_modules/@types/node/package.json +2 -2
  61. package/node_modules/@types/node/web-globals/streams.d.ts +4 -0
  62. package/node_modules/zod/README.md +2 -2
  63. package/node_modules/zod/compile.cjs +19 -0
  64. package/node_modules/zod/index.cjs +19 -0
  65. package/node_modules/zod/locales/index.cjs +19 -0
  66. package/node_modules/zod/mini/index.cjs +19 -0
  67. package/node_modules/zod/package.json +8 -7
  68. package/node_modules/zod/src/v3/helpers/errorUtil.ts +1 -1
  69. package/node_modules/zod/src/v4/classic/external.ts +2 -0
  70. package/node_modules/zod/src/v4/classic/from-json-schema.ts +248 -25
  71. package/node_modules/zod/src/v4/classic/schemas.ts +243 -168
  72. package/node_modules/zod/src/v4/classic/tests/assignability.test.ts +60 -9
  73. package/node_modules/zod/src/v4/classic/tests/bigint.test.ts +6 -0
  74. package/node_modules/zod/src/v4/classic/tests/continuability.test.ts +2 -2
  75. package/node_modules/zod/src/v4/classic/tests/cyclic-data.test.ts +265 -0
  76. package/node_modules/zod/src/v4/classic/tests/discriminated-unions.test.ts +112 -6
  77. package/node_modules/zod/src/v4/classic/tests/enum.test.ts +9 -0
  78. package/node_modules/zod/src/v4/classic/tests/error.test.ts +130 -1
  79. package/node_modules/zod/src/v4/classic/tests/from-json-schema.test.ts +157 -0
  80. package/node_modules/zod/src/v4/classic/tests/iban.test.ts +81 -0
  81. package/node_modules/zod/src/v4/classic/tests/instance-footprint.test.ts +40 -2
  82. package/node_modules/zod/src/v4/classic/tests/instanceof.test.ts +27 -7
  83. package/node_modules/zod/src/v4/classic/tests/issue-schema.test.ts +88 -56
  84. package/node_modules/zod/src/v4/classic/tests/number.test.ts +39 -0
  85. package/node_modules/zod/src/v4/classic/tests/object.test.ts +56 -0
  86. package/node_modules/zod/src/v4/classic/tests/optin-ladder.test.ts +3 -2
  87. package/node_modules/zod/src/v4/classic/tests/prefault.test.ts +70 -0
  88. package/node_modules/zod/src/v4/classic/tests/properties.test.ts +141 -0
  89. package/node_modules/zod/src/v4/classic/tests/recursive-types.test.ts +46 -1
  90. package/node_modules/zod/src/v4/classic/tests/standard-schema.test.ts +19 -0
  91. package/node_modules/zod/src/v4/classic/tests/string.test.ts +95 -1
  92. package/node_modules/zod/src/v4/classic/tests/template-literal.test.ts +33 -1
  93. package/node_modules/zod/src/v4/classic/tests/to-json-schema.test.ts +234 -38
  94. package/node_modules/zod/src/v4/classic/tests/validate.test.ts +569 -0
  95. package/node_modules/zod/src/v4/core/api.ts +44 -28
  96. package/node_modules/zod/src/v4/core/checks.ts +62 -102
  97. package/node_modules/zod/src/v4/core/compile.ts +218 -93
  98. package/node_modules/zod/src/v4/core/core.ts +1 -3
  99. package/node_modules/zod/src/v4/core/doc.ts +6 -2
  100. package/node_modules/zod/src/v4/core/errors.ts +3 -6
  101. package/node_modules/zod/src/v4/core/json-schema-generator.ts +2 -2
  102. package/node_modules/zod/src/v4/core/json-schema-processors.ts +185 -81
  103. package/node_modules/zod/src/v4/core/memoizer.ts +75 -28
  104. package/node_modules/zod/src/v4/core/parse.ts +37 -16
  105. package/node_modules/zod/src/v4/core/regexes.ts +14 -4
  106. package/node_modules/zod/src/v4/core/schemas.ts +296 -132
  107. package/node_modules/zod/src/v4/core/tests/cached.test.ts +54 -0
  108. package/node_modules/zod/src/v4/core/tests/compile-differential.test.ts +35 -0
  109. package/node_modules/zod/src/v4/core/tests/compile-generative.test.ts +445 -0
  110. package/node_modules/zod/src/v4/core/tests/compile.test.ts +399 -2
  111. package/node_modules/zod/src/v4/core/tests/email-regex.test.ts +140 -0
  112. package/node_modules/zod/src/v4/core/tests/locales/tg.test.ts +85 -0
  113. package/node_modules/zod/src/v4/core/tests/polyfill-collision.test.ts +46 -0
  114. package/node_modules/zod/src/v4/core/tests/url-no-canparse.test.ts +118 -16
  115. package/node_modules/zod/src/v4/core/to-json-schema.ts +9 -7
  116. package/node_modules/zod/src/v4/core/util.ts +218 -147
  117. package/node_modules/zod/src/v4/core/versions.ts +2 -2
  118. package/node_modules/zod/src/v4/locales/ar.ts +2 -0
  119. package/node_modules/zod/src/v4/locales/az.ts +2 -0
  120. package/node_modules/zod/src/v4/locales/be.ts +2 -0
  121. package/node_modules/zod/src/v4/locales/bg.ts +2 -0
  122. package/node_modules/zod/src/v4/locales/bn.ts +2 -0
  123. package/node_modules/zod/src/v4/locales/ca.ts +2 -0
  124. package/node_modules/zod/src/v4/locales/ckb.ts +2 -0
  125. package/node_modules/zod/src/v4/locales/cs.ts +2 -0
  126. package/node_modules/zod/src/v4/locales/da.ts +2 -0
  127. package/node_modules/zod/src/v4/locales/de.ts +2 -0
  128. package/node_modules/zod/src/v4/locales/el.ts +2 -0
  129. package/node_modules/zod/src/v4/locales/en.ts +2 -0
  130. package/node_modules/zod/src/v4/locales/eo.ts +2 -0
  131. package/node_modules/zod/src/v4/locales/es.ts +2 -0
  132. package/node_modules/zod/src/v4/locales/fa.ts +2 -0
  133. package/node_modules/zod/src/v4/locales/fi.ts +2 -0
  134. package/node_modules/zod/src/v4/locales/fr-CA.ts +2 -0
  135. package/node_modules/zod/src/v4/locales/fr.ts +2 -0
  136. package/node_modules/zod/src/v4/locales/gu.ts +2 -0
  137. package/node_modules/zod/src/v4/locales/he.ts +2 -0
  138. package/node_modules/zod/src/v4/locales/hi.ts +2 -0
  139. package/node_modules/zod/src/v4/locales/hr.ts +2 -0
  140. package/node_modules/zod/src/v4/locales/hu.ts +2 -0
  141. package/node_modules/zod/src/v4/locales/hy.ts +2 -0
  142. package/node_modules/zod/src/v4/locales/id.ts +2 -0
  143. package/node_modules/zod/src/v4/locales/index.ts +1 -0
  144. package/node_modules/zod/src/v4/locales/is.ts +2 -0
  145. package/node_modules/zod/src/v4/locales/it.ts +2 -0
  146. package/node_modules/zod/src/v4/locales/ja.ts +2 -0
  147. package/node_modules/zod/src/v4/locales/ka.ts +2 -0
  148. package/node_modules/zod/src/v4/locales/km.ts +2 -0
  149. package/node_modules/zod/src/v4/locales/kn.ts +2 -0
  150. package/node_modules/zod/src/v4/locales/ko.ts +2 -0
  151. package/node_modules/zod/src/v4/locales/lt.ts +2 -0
  152. package/node_modules/zod/src/v4/locales/mk.ts +2 -0
  153. package/node_modules/zod/src/v4/locales/ms.ts +2 -0
  154. package/node_modules/zod/src/v4/locales/ne.ts +2 -0
  155. package/node_modules/zod/src/v4/locales/nl.ts +2 -0
  156. package/node_modules/zod/src/v4/locales/nn.ts +2 -0
  157. package/node_modules/zod/src/v4/locales/no.ts +2 -0
  158. package/node_modules/zod/src/v4/locales/ota.ts +2 -0
  159. package/node_modules/zod/src/v4/locales/pl.ts +2 -0
  160. package/node_modules/zod/src/v4/locales/ps.ts +2 -0
  161. package/node_modules/zod/src/v4/locales/pt-BR.ts +2 -0
  162. package/node_modules/zod/src/v4/locales/pt.ts +2 -0
  163. package/node_modules/zod/src/v4/locales/ro.ts +2 -0
  164. package/node_modules/zod/src/v4/locales/ru.ts +2 -0
  165. package/node_modules/zod/src/v4/locales/sk.ts +2 -0
  166. package/node_modules/zod/src/v4/locales/sl.ts +2 -0
  167. package/node_modules/zod/src/v4/locales/sv.ts +2 -0
  168. package/node_modules/zod/src/v4/locales/ta.ts +2 -0
  169. package/node_modules/zod/src/v4/locales/tg.ts +135 -0
  170. package/node_modules/zod/src/v4/locales/th.ts +2 -0
  171. package/node_modules/zod/src/v4/locales/tk.ts +2 -0
  172. package/node_modules/zod/src/v4/locales/tr.ts +2 -0
  173. package/node_modules/zod/src/v4/locales/uk.ts +2 -0
  174. package/node_modules/zod/src/v4/locales/ur.ts +2 -0
  175. package/node_modules/zod/src/v4/locales/uz.ts +2 -0
  176. package/node_modules/zod/src/v4/locales/vi.ts +2 -0
  177. package/node_modules/zod/src/v4/locales/yo.ts +2 -0
  178. package/node_modules/zod/src/v4/locales/zh-CN.ts +2 -0
  179. package/node_modules/zod/src/v4/locales/zh-TW.ts +2 -0
  180. package/node_modules/zod/src/v4/mini/external.ts +2 -0
  181. package/node_modules/zod/src/v4/mini/schemas.ts +32 -7
  182. package/node_modules/zod/src/v4/mini/tests/checks.test.ts +1 -1
  183. package/node_modules/zod/src/v4/mini/tests/computed.test.ts +11 -17
  184. package/node_modules/zod/src/v4/mini/tests/index.test.ts +86 -0
  185. package/node_modules/zod/src/v4/mini/tests/recursive-types.test.ts +16 -0
  186. package/node_modules/zod/src/v4/mini/tests/string.test.ts +23 -0
  187. package/node_modules/zod/v3/ZodError.cjs +19 -0
  188. package/node_modules/zod/v3/errors.cjs +19 -0
  189. package/node_modules/zod/v3/external.cjs +19 -0
  190. package/node_modules/zod/v3/helpers/enumUtil.cjs +19 -0
  191. package/node_modules/zod/v3/helpers/errorUtil.cjs +20 -1
  192. package/node_modules/zod/v3/helpers/errorUtil.js +1 -1
  193. package/node_modules/zod/v3/helpers/parseUtil.cjs +19 -0
  194. package/node_modules/zod/v3/helpers/partialUtil.cjs +19 -0
  195. package/node_modules/zod/v3/helpers/typeAliases.cjs +19 -0
  196. package/node_modules/zod/v3/helpers/util.cjs +19 -0
  197. package/node_modules/zod/v3/index.cjs +19 -0
  198. package/node_modules/zod/v3/standard-schema.cjs +19 -0
  199. package/node_modules/zod/v3/types.cjs +19 -0
  200. package/node_modules/zod/v4/classic/checks.cjs +19 -0
  201. package/node_modules/zod/v4/classic/coerce.cjs +19 -0
  202. package/node_modules/zod/v4/classic/compat.cjs +19 -0
  203. package/node_modules/zod/v4/classic/deep-partial.cjs +19 -0
  204. package/node_modules/zod/v4/classic/errors.cjs +19 -0
  205. package/node_modules/zod/v4/classic/external.cjs +22 -1
  206. package/node_modules/zod/v4/classic/external.d.cts +1 -1
  207. package/node_modules/zod/v4/classic/external.d.ts +1 -1
  208. package/node_modules/zod/v4/classic/external.js +1 -1
  209. package/node_modules/zod/v4/classic/from-json-schema.cjs +264 -24
  210. package/node_modules/zod/v4/classic/from-json-schema.js +245 -24
  211. package/node_modules/zod/v4/classic/in-out.cjs +19 -0
  212. package/node_modules/zod/v4/classic/index.cjs +19 -0
  213. package/node_modules/zod/v4/classic/iso.cjs +19 -0
  214. package/node_modules/zod/v4/classic/parse.cjs +19 -0
  215. package/node_modules/zod/v4/classic/schemas.cjs +100 -35
  216. package/node_modules/zod/v4/classic/schemas.d.cts +15 -1
  217. package/node_modules/zod/v4/classic/schemas.d.ts +15 -1
  218. package/node_modules/zod/v4/classic/schemas.js +77 -33
  219. package/node_modules/zod/v4/core/api.cjs +45 -22
  220. package/node_modules/zod/v4/core/api.d.cts +12 -6
  221. package/node_modules/zod/v4/core/api.d.ts +12 -6
  222. package/node_modules/zod/v4/core/api.js +25 -22
  223. package/node_modules/zod/v4/core/checks.cjs +51 -97
  224. package/node_modules/zod/v4/core/checks.d.cts +17 -1
  225. package/node_modules/zod/v4/core/checks.d.ts +17 -1
  226. package/node_modules/zod/v4/core/checks.js +31 -96
  227. package/node_modules/zod/v4/core/compile.cjs +173 -78
  228. package/node_modules/zod/v4/core/compile.d.cts +18 -4
  229. package/node_modules/zod/v4/core/compile.d.ts +18 -4
  230. package/node_modules/zod/v4/core/compile.js +154 -79
  231. package/node_modules/zod/v4/core/core.cjs +20 -1
  232. package/node_modules/zod/v4/core/core.js +1 -1
  233. package/node_modules/zod/v4/core/doc.cjs +26 -2
  234. package/node_modules/zod/v4/core/doc.js +7 -2
  235. package/node_modules/zod/v4/core/errors.cjs +21 -5
  236. package/node_modules/zod/v4/core/errors.js +2 -5
  237. package/node_modules/zod/v4/core/index.cjs +19 -0
  238. package/node_modules/zod/v4/core/json-schema-generator.cjs +20 -1
  239. package/node_modules/zod/v4/core/json-schema-generator.js +2 -2
  240. package/node_modules/zod/v4/core/json-schema-processors.cjs +188 -72
  241. package/node_modules/zod/v4/core/json-schema-processors.d.cts +16 -0
  242. package/node_modules/zod/v4/core/json-schema-processors.d.ts +16 -0
  243. package/node_modules/zod/v4/core/json-schema-processors.js +170 -74
  244. package/node_modules/zod/v4/core/json-schema.cjs +19 -0
  245. package/node_modules/zod/v4/core/memoizer.cjs +111 -23
  246. package/node_modules/zod/v4/core/memoizer.js +69 -23
  247. package/node_modules/zod/v4/core/parse.cjs +56 -16
  248. package/node_modules/zod/v4/core/parse.js +37 -16
  249. package/node_modules/zod/v4/core/regexes.cjs +31 -6
  250. package/node_modules/zod/v4/core/regexes.d.cts +3 -0
  251. package/node_modules/zod/v4/core/regexes.d.ts +3 -0
  252. package/node_modules/zod/v4/core/regexes.js +10 -4
  253. package/node_modules/zod/v4/core/registries.cjs +19 -0
  254. package/node_modules/zod/v4/core/schemas.cjs +302 -114
  255. package/node_modules/zod/v4/core/schemas.d.cts +28 -8
  256. package/node_modules/zod/v4/core/schemas.d.ts +28 -8
  257. package/node_modules/zod/v4/core/schemas.js +279 -113
  258. package/node_modules/zod/v4/core/standard-schema.cjs +19 -0
  259. package/node_modules/zod/v4/core/to-json-schema.cjs +28 -7
  260. package/node_modules/zod/v4/core/to-json-schema.d.cts +4 -3
  261. package/node_modules/zod/v4/core/to-json-schema.d.ts +4 -3
  262. package/node_modules/zod/v4/core/to-json-schema.js +7 -6
  263. package/node_modules/zod/v4/core/util.cjs +177 -143
  264. package/node_modules/zod/v4/core/util.d.cts +25 -4
  265. package/node_modules/zod/v4/core/util.d.ts +25 -4
  266. package/node_modules/zod/v4/core/util.js +156 -143
  267. package/node_modules/zod/v4/core/versions.cjs +21 -2
  268. package/node_modules/zod/v4/core/versions.d.cts +1 -1
  269. package/node_modules/zod/v4/core/versions.d.ts +1 -1
  270. package/node_modules/zod/v4/core/versions.js +2 -2
  271. package/node_modules/zod/v4/core/visit.cjs +19 -0
  272. package/node_modules/zod/v4/index.cjs +19 -0
  273. package/node_modules/zod/v4/locales/ar.cjs +2 -0
  274. package/node_modules/zod/v4/locales/ar.js +2 -0
  275. package/node_modules/zod/v4/locales/az.cjs +2 -0
  276. package/node_modules/zod/v4/locales/az.js +2 -0
  277. package/node_modules/zod/v4/locales/be.cjs +2 -0
  278. package/node_modules/zod/v4/locales/be.js +2 -0
  279. package/node_modules/zod/v4/locales/bg.cjs +2 -0
  280. package/node_modules/zod/v4/locales/bg.js +2 -0
  281. package/node_modules/zod/v4/locales/bn.cjs +2 -0
  282. package/node_modules/zod/v4/locales/bn.js +2 -0
  283. package/node_modules/zod/v4/locales/ca.cjs +2 -0
  284. package/node_modules/zod/v4/locales/ca.js +2 -0
  285. package/node_modules/zod/v4/locales/ckb.cjs +2 -0
  286. package/node_modules/zod/v4/locales/ckb.js +2 -0
  287. package/node_modules/zod/v4/locales/cs.cjs +2 -0
  288. package/node_modules/zod/v4/locales/cs.js +2 -0
  289. package/node_modules/zod/v4/locales/da.cjs +2 -0
  290. package/node_modules/zod/v4/locales/da.js +2 -0
  291. package/node_modules/zod/v4/locales/de.cjs +2 -0
  292. package/node_modules/zod/v4/locales/de.js +2 -0
  293. package/node_modules/zod/v4/locales/el.cjs +2 -0
  294. package/node_modules/zod/v4/locales/el.js +2 -0
  295. package/node_modules/zod/v4/locales/en.cjs +2 -0
  296. package/node_modules/zod/v4/locales/en.js +2 -0
  297. package/node_modules/zod/v4/locales/eo.cjs +2 -0
  298. package/node_modules/zod/v4/locales/eo.js +2 -0
  299. package/node_modules/zod/v4/locales/es.cjs +2 -0
  300. package/node_modules/zod/v4/locales/es.js +2 -0
  301. package/node_modules/zod/v4/locales/fa.cjs +2 -0
  302. package/node_modules/zod/v4/locales/fa.js +2 -0
  303. package/node_modules/zod/v4/locales/fi.cjs +2 -0
  304. package/node_modules/zod/v4/locales/fi.js +2 -0
  305. package/node_modules/zod/v4/locales/fr-CA.cjs +2 -0
  306. package/node_modules/zod/v4/locales/fr-CA.js +2 -0
  307. package/node_modules/zod/v4/locales/fr.cjs +2 -0
  308. package/node_modules/zod/v4/locales/fr.js +2 -0
  309. package/node_modules/zod/v4/locales/gu.cjs +2 -0
  310. package/node_modules/zod/v4/locales/gu.js +2 -0
  311. package/node_modules/zod/v4/locales/he.cjs +2 -0
  312. package/node_modules/zod/v4/locales/he.js +2 -0
  313. package/node_modules/zod/v4/locales/hi.cjs +2 -0
  314. package/node_modules/zod/v4/locales/hi.js +2 -0
  315. package/node_modules/zod/v4/locales/hr.cjs +2 -0
  316. package/node_modules/zod/v4/locales/hr.js +2 -0
  317. package/node_modules/zod/v4/locales/hu.cjs +2 -0
  318. package/node_modules/zod/v4/locales/hu.js +2 -0
  319. package/node_modules/zod/v4/locales/hy.cjs +2 -0
  320. package/node_modules/zod/v4/locales/hy.js +2 -0
  321. package/node_modules/zod/v4/locales/id.cjs +2 -0
  322. package/node_modules/zod/v4/locales/id.js +2 -0
  323. package/node_modules/zod/v4/locales/index.cjs +22 -1
  324. package/node_modules/zod/v4/locales/index.d.cts +1 -0
  325. package/node_modules/zod/v4/locales/index.d.ts +1 -0
  326. package/node_modules/zod/v4/locales/index.js +1 -0
  327. package/node_modules/zod/v4/locales/is.cjs +2 -0
  328. package/node_modules/zod/v4/locales/is.js +2 -0
  329. package/node_modules/zod/v4/locales/it.cjs +2 -0
  330. package/node_modules/zod/v4/locales/it.js +2 -0
  331. package/node_modules/zod/v4/locales/ja.cjs +2 -0
  332. package/node_modules/zod/v4/locales/ja.js +2 -0
  333. package/node_modules/zod/v4/locales/ka.cjs +2 -0
  334. package/node_modules/zod/v4/locales/ka.js +2 -0
  335. package/node_modules/zod/v4/locales/km.cjs +2 -0
  336. package/node_modules/zod/v4/locales/km.js +2 -0
  337. package/node_modules/zod/v4/locales/kn.cjs +2 -0
  338. package/node_modules/zod/v4/locales/kn.js +2 -0
  339. package/node_modules/zod/v4/locales/ko.cjs +2 -0
  340. package/node_modules/zod/v4/locales/ko.js +2 -0
  341. package/node_modules/zod/v4/locales/lt.cjs +2 -0
  342. package/node_modules/zod/v4/locales/lt.js +2 -0
  343. package/node_modules/zod/v4/locales/mk.cjs +2 -0
  344. package/node_modules/zod/v4/locales/mk.js +2 -0
  345. package/node_modules/zod/v4/locales/ms.cjs +2 -0
  346. package/node_modules/zod/v4/locales/ms.js +2 -0
  347. package/node_modules/zod/v4/locales/ne.cjs +2 -0
  348. package/node_modules/zod/v4/locales/ne.js +2 -0
  349. package/node_modules/zod/v4/locales/nl.cjs +2 -0
  350. package/node_modules/zod/v4/locales/nl.js +2 -0
  351. package/node_modules/zod/v4/locales/nn.cjs +2 -0
  352. package/node_modules/zod/v4/locales/nn.js +2 -0
  353. package/node_modules/zod/v4/locales/no.cjs +2 -0
  354. package/node_modules/zod/v4/locales/no.js +2 -0
  355. package/node_modules/zod/v4/locales/ota.cjs +2 -0
  356. package/node_modules/zod/v4/locales/ota.js +2 -0
  357. package/node_modules/zod/v4/locales/pl.cjs +2 -0
  358. package/node_modules/zod/v4/locales/pl.js +2 -0
  359. package/node_modules/zod/v4/locales/ps.cjs +2 -0
  360. package/node_modules/zod/v4/locales/ps.js +2 -0
  361. package/node_modules/zod/v4/locales/pt-BR.cjs +2 -0
  362. package/node_modules/zod/v4/locales/pt-BR.js +2 -0
  363. package/node_modules/zod/v4/locales/pt.cjs +2 -0
  364. package/node_modules/zod/v4/locales/pt.js +2 -0
  365. package/node_modules/zod/v4/locales/ro.cjs +2 -0
  366. package/node_modules/zod/v4/locales/ro.js +2 -0
  367. package/node_modules/zod/v4/locales/ru.cjs +2 -0
  368. package/node_modules/zod/v4/locales/ru.js +2 -0
  369. package/node_modules/zod/v4/locales/sk.cjs +2 -0
  370. package/node_modules/zod/v4/locales/sk.js +2 -0
  371. package/node_modules/zod/v4/locales/sl.cjs +2 -0
  372. package/node_modules/zod/v4/locales/sl.js +2 -0
  373. package/node_modules/zod/v4/locales/sv.cjs +2 -0
  374. package/node_modules/zod/v4/locales/sv.js +2 -0
  375. package/node_modules/zod/v4/locales/ta.cjs +2 -0
  376. package/node_modules/zod/v4/locales/ta.js +2 -0
  377. package/node_modules/zod/v4/locales/tg.cjs +144 -0
  378. package/node_modules/zod/v4/locales/tg.d.cts +5 -0
  379. package/node_modules/zod/v4/locales/tg.d.ts +4 -0
  380. package/node_modules/zod/v4/locales/tg.js +117 -0
  381. package/node_modules/zod/v4/locales/th.cjs +2 -0
  382. package/node_modules/zod/v4/locales/th.js +2 -0
  383. package/node_modules/zod/v4/locales/tk.cjs +2 -0
  384. package/node_modules/zod/v4/locales/tk.js +2 -0
  385. package/node_modules/zod/v4/locales/tr.cjs +2 -0
  386. package/node_modules/zod/v4/locales/tr.js +2 -0
  387. package/node_modules/zod/v4/locales/uk.cjs +2 -0
  388. package/node_modules/zod/v4/locales/uk.js +2 -0
  389. package/node_modules/zod/v4/locales/ur.cjs +2 -0
  390. package/node_modules/zod/v4/locales/ur.js +2 -0
  391. package/node_modules/zod/v4/locales/uz.cjs +2 -0
  392. package/node_modules/zod/v4/locales/uz.js +2 -0
  393. package/node_modules/zod/v4/locales/vi.cjs +2 -0
  394. package/node_modules/zod/v4/locales/vi.js +2 -0
  395. package/node_modules/zod/v4/locales/yo.cjs +2 -0
  396. package/node_modules/zod/v4/locales/yo.js +2 -0
  397. package/node_modules/zod/v4/locales/zh-CN.cjs +2 -0
  398. package/node_modules/zod/v4/locales/zh-CN.js +2 -0
  399. package/node_modules/zod/v4/locales/zh-TW.cjs +2 -0
  400. package/node_modules/zod/v4/locales/zh-TW.js +2 -0
  401. package/node_modules/zod/v4/mini/checks.cjs +19 -0
  402. package/node_modules/zod/v4/mini/coerce.cjs +19 -0
  403. package/node_modules/zod/v4/mini/deep-partial.cjs +19 -0
  404. package/node_modules/zod/v4/mini/external.cjs +22 -1
  405. package/node_modules/zod/v4/mini/external.d.cts +1 -1
  406. package/node_modules/zod/v4/mini/external.d.ts +1 -1
  407. package/node_modules/zod/v4/mini/external.js +1 -1
  408. package/node_modules/zod/v4/mini/in-out.cjs +19 -0
  409. package/node_modules/zod/v4/mini/index.cjs +19 -0
  410. package/node_modules/zod/v4/mini/iso.cjs +19 -0
  411. package/node_modules/zod/v4/mini/parse.cjs +19 -0
  412. package/node_modules/zod/v4/mini/schemas.cjs +44 -8
  413. package/node_modules/zod/v4/mini/schemas.d.cts +6 -1
  414. package/node_modules/zod/v4/mini/schemas.d.ts +6 -1
  415. package/node_modules/zod/v4/mini/schemas.js +21 -6
  416. package/node_modules/zod/v4-mini/index.cjs +19 -0
  417. package/package.json +8 -5
  418. package/dist/.setup/message-handler.history-CJOsN9w5.mjs +0 -28
  419. package/dist/.setup/provider.runtime-DuhmKdDU.mjs +0 -2
  420. package/dist/.setup/setup-plugin-api-CINIEBLa.mjs +0 -3
  421. package/dist/.setup/targets-D1mAB5yO.mjs +0 -3
@@ -0,0 +1,1065 @@
1
+ import { S as setDiscordAudioOutputStatus, _ as getDiscordAudioOutputStatus, b as retireDiscordAudioOutput, f as createRealtimePcmToDiscordConverter, h as DiscordAudioOutputStatus, i as enableDaveReceivePassthrough, l as createDiscordOpusEncodeStream, n as analyzeVoiceReceiveError, p as decodeOpusStreamChunks, s as recoverDaveZeroTransition, u as createDiscordOpusPlaybackStream, v as releaseDiscordAudioInput, x as serializeDiscordAudioError } from "../../.setup/receive-recovery-DHst8WRx.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.onPlayerError = (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.onPlayerError);
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", (error) => this.post({
585
+ type: "error",
586
+ error: serializeDiscordAudioError(error)
587
+ }));
588
+ try {
589
+ await this.sdk.entersState(connection, this.sdk.VoiceConnectionStatus.Ready, AbortSignal.any([this.stopAbort.signal, AbortSignal.timeout(Math.max(1, deadline - Date.now()))]));
590
+ if (this.stopped) return;
591
+ connection.subscribe(this.player);
592
+ connection.on("stateChange", (_old, state) => {
593
+ this.post({
594
+ type: "connection",
595
+ status: state.status
596
+ });
597
+ });
598
+ connection.on(this.sdk.VoiceConnectionStatus.Destroyed, this.onDestroyed);
599
+ connection.on(this.sdk.VoiceConnectionStatus.Disconnected, this.onDisconnected);
600
+ connection.receiver.speaking.on("start", this.onSpeakingStart);
601
+ connection.receiver.speaking.on("end", this.onSpeakingEnd);
602
+ for (const userId of connection.receiver.speaking.users.keys()) this.post({
603
+ type: "speaking",
604
+ userId,
605
+ speaking: true
606
+ });
607
+ this.post({
608
+ type: "connection",
609
+ status: connection.state.status
610
+ });
611
+ this.post({ type: "ready" });
612
+ return;
613
+ } catch (error) {
614
+ if (this.stopped) return;
615
+ if (connection.state.status !== this.sdk.VoiceConnectionStatus.Destroyed) connection.destroy();
616
+ if (attempt === 0 && !this.stopped && Date.now() < deadline && error instanceof Error && error.message.toLowerCase().includes("operation was aborted")) continue;
617
+ throw error;
618
+ }
619
+ }
620
+ }
621
+ receive(command) {
622
+ if (this.stopped) return;
623
+ switch (command.type) {
624
+ case "gateway-server":
625
+ this.adapter?.onVoiceServerUpdate(command.data);
626
+ break;
627
+ case "gateway-state":
628
+ this.adapter?.onVoiceStateUpdate(command.data);
629
+ break;
630
+ case "gateway-failed":
631
+ this.post({
632
+ type: "error",
633
+ error: {
634
+ name: "Error",
635
+ message: "Discord main gateway could not send voice signalling."
636
+ }
637
+ });
638
+ this.adapter?.destroy();
639
+ this.stop();
640
+ break;
641
+ case "stop":
642
+ this.stop();
643
+ break;
644
+ case "continuous-port": {
645
+ const lane = new DiscordContinuousOutput({
646
+ id: command.id,
647
+ enabled: command.enabled,
648
+ port: command.port,
649
+ state: new Int32Array(command.state),
650
+ clock: new BigInt64Array(command.clock),
651
+ player: this.roomPlayer,
652
+ post: this.post,
653
+ logContext: "guild=" + this.options.guildId + " channel=" + this.options.channelId
654
+ });
655
+ this.continuous.set(command.id, lane);
656
+ command.port.once("close", () => this.continuous.delete(command.id));
657
+ break;
658
+ }
659
+ case "continuous-activate":
660
+ this.continuous.get(command.id)?.activate();
661
+ break;
662
+ case "continuous-clear":
663
+ this.continuous.get(command.id)?.clear();
664
+ break;
665
+ case "continuous-flush":
666
+ this.continuous.get(command.id)?.flush(command.marker);
667
+ break;
668
+ case "continuous-close":
669
+ this.continuous.get(command.id)?.close();
670
+ this.continuous.delete(command.id);
671
+ break;
672
+ case "capture":
673
+ this.track(this.capture(command.id, command.userId, command.recordingEpoch));
674
+ break;
675
+ case "capture-stop": {
676
+ const capture = this.captures.get(command.id);
677
+ if (capture) this.stopCapture(capture);
678
+ break;
679
+ }
680
+ case "capture-ack": {
681
+ const capture = this.captures.get(command.id);
682
+ if (capture) {
683
+ capture.pendingPackets = Math.max(0, capture.pendingPackets - 1);
684
+ capture.pendingBytes = Math.max(0, capture.pendingBytes - command.bytes);
685
+ }
686
+ break;
687
+ }
688
+ case "passthrough":
689
+ this.enablePassthrough(command.reason, command.expirySeconds);
690
+ break;
691
+ case "output-create": {
692
+ const output = new DiscordRealtimeOutput({
693
+ player: this.roomPlayer,
694
+ clock: new BigInt64Array(command.clock),
695
+ logContext: "guild=" + this.options.guildId + " channel=" + this.options.channelId,
696
+ continuous: command.continuous,
697
+ onStart: () => this.post({
698
+ type: "output-start",
699
+ id: command.id
700
+ }),
701
+ onClose: (_output, reason) => {
702
+ this.outputs.delete(command.id);
703
+ queueMicrotask(() => this.post({
704
+ type: "output-close",
705
+ id: command.id,
706
+ reason
707
+ }));
708
+ },
709
+ onError: (error) => this.post({
710
+ type: "output-error",
711
+ id: command.id,
712
+ error: serializeDiscordAudioError(error)
713
+ })
714
+ });
715
+ this.outputs.set(command.id, output);
716
+ break;
717
+ }
718
+ case "output-audio":
719
+ this.outputs.get(command.id)?.appendAdmitted(Buffer.from(command.audio), command.audible);
720
+ break;
721
+ case "output-mark":
722
+ this.outputs.get(command.id)?.markPlayback(() => this.post({
723
+ type: "output-mark",
724
+ id: command.id,
725
+ markId: command.markId
726
+ }));
727
+ break;
728
+ case "output-finish":
729
+ this.outputs.get(command.id)?.finish(command.reason, command.playBuffered);
730
+ break;
731
+ case "output-close":
732
+ this.outputs.get(command.id)?.close(command.reason);
733
+ break;
734
+ case "output-hold":
735
+ this.roomPlayer.hold(command.hold);
736
+ break;
737
+ case "output-shutdown":
738
+ this.retireOutputs();
739
+ break;
740
+ case "player-stop":
741
+ this.fileAbort?.abort();
742
+ this.player.stop(true);
743
+ break;
744
+ case "file-play":
745
+ this.track(this.playFile(command.id, command.path));
746
+ break;
747
+ case "stream-play": {
748
+ const stream = new PassThrough();
749
+ this.fileInput = {
750
+ id: command.id,
751
+ stream
752
+ };
753
+ this.track(this.playFile(command.id, stream));
754
+ break;
755
+ }
756
+ case "stream-chunk":
757
+ if (this.fileInput?.id !== command.id) break;
758
+ if (this.fileInput.stream.write(Buffer.from(command.audio))) this.post({
759
+ type: "stream-drain",
760
+ id: command.id
761
+ });
762
+ else this.fileInput.stream.once("drain", () => this.post({
763
+ type: "stream-drain",
764
+ id: command.id
765
+ }));
766
+ break;
767
+ case "stream-end": if (this.fileInput?.id === command.id) this.fileInput.stream.end();
768
+ }
769
+ }
770
+ retireOutputs() {
771
+ this.roomPlayer.transition(() => {
772
+ for (const lane of this.continuous.values()) lane.close();
773
+ this.continuous.clear();
774
+ const retiring = [...this.outputs.values()];
775
+ for (const output of retiring) output.close("session-close");
776
+ });
777
+ }
778
+ async recoverConnection(connection) {
779
+ const recovery = new AbortController();
780
+ const signal = AbortSignal.any([
781
+ this.stopAbort.signal,
782
+ recovery.signal,
783
+ AbortSignal.timeout(this.options.reconnectGraceMs)
784
+ ]);
785
+ try {
786
+ await Promise.race([this.sdk.entersState(connection, this.sdk.VoiceConnectionStatus.Signalling, signal), this.sdk.entersState(connection, this.sdk.VoiceConnectionStatus.Connecting, signal)]);
787
+ } catch (error) {
788
+ if (!this.stopped) {
789
+ this.post({
790
+ type: "error",
791
+ error: serializeDiscordAudioError(error)
792
+ });
793
+ await this.stop();
794
+ }
795
+ } finally {
796
+ recovery.abort();
797
+ }
798
+ }
799
+ enablePassthrough(reason, expirySeconds) {
800
+ if (!this.connection) return;
801
+ enableDaveReceivePassthrough({
802
+ target: {
803
+ guildId: this.options.guildId,
804
+ channelId: this.options.channelId,
805
+ connection: this.connection
806
+ },
807
+ sdk: this.sdk,
808
+ reason,
809
+ expirySeconds,
810
+ onVerbose: (message) => this.post({
811
+ type: "log",
812
+ level: "verbose",
813
+ message
814
+ }),
815
+ onWarn: (message) => this.post({
816
+ type: "log",
817
+ level: "warn",
818
+ message
819
+ })
820
+ });
821
+ }
822
+ stopCapture(capture) {
823
+ if (capture.closed) return;
824
+ capture.closed = true;
825
+ clearTimeout(capture.timer);
826
+ if (!capture.stream.destroyed) capture.stream.destroy();
827
+ }
828
+ finalizeLater(id, capture) {
829
+ clearTimeout(capture.timer);
830
+ capture.timer = setTimeout(() => {
831
+ if (this.captures.get(id) === capture) this.stopCapture(capture);
832
+ }, this.options.captureSilenceGraceMs);
833
+ }
834
+ async capture(id, userId, recordingEpoch) {
835
+ const connection = this.connection;
836
+ if (!connection || this.captures.has(id)) return;
837
+ const stream = connection.receiver.subscribe(userId, { end: { behavior: this.sdk.EndBehaviorType.Manual } });
838
+ const capture = {
839
+ userId,
840
+ stream,
841
+ pendingPackets: 0,
842
+ pendingBytes: 0,
843
+ closed: false
844
+ };
845
+ this.captures.set(id, capture);
846
+ const input = new PassThrough({ objectMode: true });
847
+ const recordingClock = new BigInt64Array(recordingEpoch);
848
+ const receipts = /* @__PURE__ */ new WeakMap();
849
+ let failed = false;
850
+ let abortReported = false;
851
+ let decodedFrames = 0;
852
+ const onError = (error) => {
853
+ if (failed) return;
854
+ const analysis = analyzeVoiceReceiveError(error);
855
+ if (analysis.isAbortLike && !analysis.countsAsDecryptFailure) {
856
+ if (!abortReported) this.post({
857
+ type: "capture-error",
858
+ id,
859
+ error: serializeDiscordAudioError(error)
860
+ });
861
+ abortReported = true;
862
+ return;
863
+ }
864
+ failed = true;
865
+ let recovery = "not-attempted";
866
+ if (analysis.shouldAttemptPassthrough) {
867
+ recovery = recoverDaveZeroTransition({
868
+ target: {
869
+ guildId: this.options.guildId,
870
+ channelId: this.options.channelId,
871
+ connection
872
+ },
873
+ sdk: this.sdk,
874
+ onWarn: (message) => this.post({
875
+ type: "log",
876
+ level: "warn",
877
+ message
878
+ })
879
+ });
880
+ if (recovery !== "failed") this.enablePassthrough("receive decrypt error", 15);
881
+ }
882
+ this.post({
883
+ type: "capture-error",
884
+ id,
885
+ error: {
886
+ ...serializeDiscordAudioError(error),
887
+ ...recovery === "failed" ? { daveRecoveryFailed: true } : {}
888
+ }
889
+ });
890
+ };
891
+ const accept = (packet) => {
892
+ if (failed || capture.closed || !packet.length) return;
893
+ if (capture.pendingPackets >= MAX_CAPTURE_PACKETS || capture.pendingBytes + packet.length > MAX_CAPTURE_BYTES) {
894
+ onError(/* @__PURE__ */ new Error("Discord voice receive backlog exceeded; try speaking again."));
895
+ this.stopCapture(capture);
896
+ input.destroy();
897
+ return;
898
+ }
899
+ capture.pendingPackets += 1;
900
+ capture.pendingBytes += packet.length;
901
+ const owned = Buffer.from(packet);
902
+ receipts.set(owned, {
903
+ receivedAt: Date.now(),
904
+ recordingEpoch: Atomics.load(recordingClock, 0)
905
+ });
906
+ input.write(owned);
907
+ };
908
+ const end = () => input.end();
909
+ const finalized = () => {
910
+ clearTimeout(capture.timer);
911
+ capture.closed = true;
912
+ this.post({
913
+ type: "capture-finalized",
914
+ id
915
+ });
916
+ input.end();
917
+ };
918
+ stream.on("data", accept);
919
+ stream.on("end", end);
920
+ stream.once("close", finalized);
921
+ stream.on("error", onError);
922
+ if (!connection.receiver.speaking.users.has(userId)) this.finalizeLater(id, capture);
923
+ try {
924
+ await decodeOpusStreamChunks(input, {
925
+ onChunk: async (pcm, packet) => {
926
+ const receipt = receipts.get(packet);
927
+ if (!failed && receipt) this.post({
928
+ type: "capture-frame",
929
+ id,
930
+ frame: {
931
+ pcm,
932
+ packet,
933
+ ...receipt
934
+ }
935
+ });
936
+ if (++decodedFrames % 8 === 0) await new Promise((resolve) => {
937
+ setImmediate(resolve);
938
+ });
939
+ },
940
+ onError,
941
+ onVerbose: (message) => this.post({
942
+ type: "log",
943
+ level: "verbose",
944
+ message
945
+ }),
946
+ onWarn: (message) => this.post({
947
+ type: "log",
948
+ level: "warn",
949
+ message
950
+ })
951
+ });
952
+ } finally {
953
+ clearTimeout(capture.timer);
954
+ this.captures.delete(id);
955
+ stream.off("data", accept);
956
+ stream.off("end", end);
957
+ stream.off("error", onError);
958
+ this.stopCapture(capture);
959
+ input.destroy();
960
+ this.post({
961
+ type: "capture-end",
962
+ id
963
+ });
964
+ }
965
+ }
966
+ async playFile(id, input) {
967
+ const abort = new AbortController();
968
+ this.fileAbort?.abort();
969
+ this.fileAbort = abort;
970
+ let error;
971
+ const onError = (cause) => {
972
+ error = serializeDiscordAudioError(cause);
973
+ abort.abort();
974
+ };
975
+ let playbackStarted = false;
976
+ const onIdle = () => {
977
+ if (!playbackStarted) abort.abort();
978
+ };
979
+ this.player.on("error", onError);
980
+ this.player.on(this.sdk.AudioPlayerStatus.Idle, onIdle);
981
+ try {
982
+ this.player.play(this.sdk.createAudioResource(createDiscordOpusPlaybackStream(input), { inputType: this.sdk.StreamType.Opus }));
983
+ await this.sdk.entersState(this.player, this.sdk.AudioPlayerStatus.Playing, AbortSignal.any([AbortSignal.timeout(PLAYBACK_READY_TIMEOUT_MS), abort.signal]));
984
+ playbackStarted = true;
985
+ await this.sdk.entersState(this.player, this.sdk.AudioPlayerStatus.Idle, abort.signal);
986
+ } catch (cause) {
987
+ error ??= serializeDiscordAudioError(cause);
988
+ } finally {
989
+ this.player.off("error", onError);
990
+ this.player.off(this.sdk.AudioPlayerStatus.Idle, onIdle);
991
+ if (this.fileAbort === abort) this.fileAbort = void 0;
992
+ if (this.fileInput?.id === id) {
993
+ this.fileInput.stream.destroy();
994
+ this.fileInput = void 0;
995
+ }
996
+ this.post({
997
+ type: "file-end",
998
+ id,
999
+ ...error ? { error } : {}
1000
+ });
1001
+ }
1002
+ }
1003
+ track(task) {
1004
+ this.tasks.add(task);
1005
+ task.catch((error) => this.post({
1006
+ type: "error",
1007
+ error: serializeDiscordAudioError(error)
1008
+ })).finally(() => this.tasks.delete(task));
1009
+ }
1010
+ async stop() {
1011
+ if (this.stopped) return;
1012
+ this.stopped = true;
1013
+ this.stopAbort.abort();
1014
+ this.post({
1015
+ type: "connection",
1016
+ status: this.sdk.VoiceConnectionStatus.Destroyed
1017
+ });
1018
+ this.retireOutputs();
1019
+ this.roomPlayer.close();
1020
+ this.fileAbort?.abort();
1021
+ this.fileInput?.stream.destroy();
1022
+ for (const capture of this.captures.values()) this.stopCapture(capture);
1023
+ const connection = this.connection;
1024
+ connection?.receiver.speaking.off("start", this.onSpeakingStart);
1025
+ connection?.receiver.speaking.off("end", this.onSpeakingEnd);
1026
+ connection?.off(this.sdk.VoiceConnectionStatus.Disconnected, this.onDisconnected);
1027
+ connection?.off(this.sdk.VoiceConnectionStatus.Destroyed, this.onDestroyed);
1028
+ this.player.off("error", this.onPlayerError);
1029
+ if (connection && connection.state.status !== this.sdk.VoiceConnectionStatus.Destroyed) connection.destroy();
1030
+ this.post({ type: "gateway-destroy" });
1031
+ await Promise.allSettled(this.tasks);
1032
+ this.post({ type: "stopped" });
1033
+ }
1034
+ };
1035
+ //#endregion
1036
+ //#region extensions/discord/src/voice/audio-worker.runtime.ts
1037
+ const port = parentPort;
1038
+ if (!port) throw new Error("Discord audio runtime requires a worker MessagePort.");
1039
+ const media = new DiscordAudioWorker(workerData, (event) => {
1040
+ port.postMessage(event);
1041
+ if (event.type === "stopped") port.close();
1042
+ });
1043
+ port.on("message", (command) => {
1044
+ try {
1045
+ media.receive(command);
1046
+ } catch (error) {
1047
+ port.postMessage({
1048
+ type: "error",
1049
+ error: serializeDiscordAudioError(error)
1050
+ });
1051
+ media.stop();
1052
+ }
1053
+ });
1054
+ port.on("close", () => {
1055
+ media.stop();
1056
+ });
1057
+ media.connect().catch((error) => {
1058
+ port.postMessage({
1059
+ type: "error",
1060
+ error: serializeDiscordAudioError(error)
1061
+ });
1062
+ media.stop();
1063
+ });
1064
+ //#endregion
1065
+ export {};