@wirecat/slack-cli 0.0.0-stage → 0.1.0

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 (295) hide show
  1. package/CHANGELOG.md +104 -0
  2. package/LICENSE +204 -0
  3. package/README.md +131 -2
  4. package/contracts/wirecat.json +5526 -0
  5. package/dist/bin/slack.d.ts +3 -0
  6. package/dist/bin/slack.d.ts.map +1 -0
  7. package/dist/bin/slack.js +40 -0
  8. package/dist/bin/slack.js.map +1 -0
  9. package/dist/bundle/agent-GOFXFUQP.js +37 -0
  10. package/dist/bundle/all-profiles-4C7VOT2D.js +320 -0
  11. package/dist/bundle/anthropic-ZD66TC5S.js +91 -0
  12. package/dist/bundle/app-server-QNCVEDMY.js +249 -0
  13. package/dist/bundle/bun-2FULBYXS.js +169 -0
  14. package/dist/bundle/bun-sqlite-PMS26ZUT.js +76 -0
  15. package/dist/bundle/chunk-2LB5BWC4.js +362 -0
  16. package/dist/bundle/chunk-2ZEYRHZV.js +18 -0
  17. package/dist/bundle/chunk-3IJ3THPV.js +7 -0
  18. package/dist/bundle/chunk-4HSVEQ3R.js +29 -0
  19. package/dist/bundle/chunk-4QPMHVM5.js +1007 -0
  20. package/dist/bundle/chunk-53LIHHXC.js +16 -0
  21. package/dist/bundle/chunk-5F36CXDM.js +794 -0
  22. package/dist/bundle/chunk-5LPREGD3.js +12636 -0
  23. package/dist/bundle/chunk-5R5YRYIP.js +1148 -0
  24. package/dist/bundle/chunk-5RSQTG7L.js +388 -0
  25. package/dist/bundle/chunk-5SXZETJF.js +170 -0
  26. package/dist/bundle/chunk-6PDQP5RM.js +50 -0
  27. package/dist/bundle/chunk-75BLNPN3.js +1197 -0
  28. package/dist/bundle/chunk-7BEO72EN.js +131 -0
  29. package/dist/bundle/chunk-7F6RNAIM.js +230 -0
  30. package/dist/bundle/chunk-AG7FP64Z.js +77 -0
  31. package/dist/bundle/chunk-B7ZM3FCB.js +61 -0
  32. package/dist/bundle/chunk-BRXTN5LJ.js +338 -0
  33. package/dist/bundle/chunk-CABZAU37.js +319 -0
  34. package/dist/bundle/chunk-CCOSG3F2.js +24616 -0
  35. package/dist/bundle/chunk-CDTZSFTN.js +58 -0
  36. package/dist/bundle/chunk-CMZBCWND.js +1246 -0
  37. package/dist/bundle/chunk-CRQEEJNF.js +185 -0
  38. package/dist/bundle/chunk-CWYU4R65.js +358 -0
  39. package/dist/bundle/chunk-CZFR6JQX.js +52 -0
  40. package/dist/bundle/chunk-D72URWJE.js +532 -0
  41. package/dist/bundle/chunk-DFDN6AUB.js +21 -0
  42. package/dist/bundle/chunk-DVHX7R54.js +4072 -0
  43. package/dist/bundle/chunk-DYKOG7QR.js +9596 -0
  44. package/dist/bundle/chunk-ECDI42G6.js +100 -0
  45. package/dist/bundle/chunk-EH6ZEJGT.js +932 -0
  46. package/dist/bundle/chunk-ELY2TLCY.js +259 -0
  47. package/dist/bundle/chunk-ERRVUVKR.js +156 -0
  48. package/dist/bundle/chunk-FBWR4E5D.js +353 -0
  49. package/dist/bundle/chunk-GKS6KL57.js +6848 -0
  50. package/dist/bundle/chunk-H2COZZ55.js +2787 -0
  51. package/dist/bundle/chunk-HGXTEK7R.js +82 -0
  52. package/dist/bundle/chunk-HXLXM7HV.js +726 -0
  53. package/dist/bundle/chunk-IPP4N6HD.js +24 -0
  54. package/dist/bundle/chunk-IWTVR7S7.js +53 -0
  55. package/dist/bundle/chunk-IYJH75D4.js +63 -0
  56. package/dist/bundle/chunk-JCZLRT4Z.js +39 -0
  57. package/dist/bundle/chunk-JGRWMR5H.js +123 -0
  58. package/dist/bundle/chunk-JYRYQJBN.js +633 -0
  59. package/dist/bundle/chunk-KIKLDI74.js +161 -0
  60. package/dist/bundle/chunk-L4WO3XH6.js +2020 -0
  61. package/dist/bundle/chunk-LQDNUAK3.js +274 -0
  62. package/dist/bundle/chunk-LV5ONLQH.js +38 -0
  63. package/dist/bundle/chunk-M27Z23OZ.js +23 -0
  64. package/dist/bundle/chunk-M5XTZHXM.js +142 -0
  65. package/dist/bundle/chunk-MJBEGUIZ.js +76 -0
  66. package/dist/bundle/chunk-N4WOLGIV.js +2333 -0
  67. package/dist/bundle/chunk-N5K4OHPT.js +206 -0
  68. package/dist/bundle/chunk-NYAPUET7.js +108 -0
  69. package/dist/bundle/chunk-P4IFLOIK.js +218 -0
  70. package/dist/bundle/chunk-P6G2QTCD.js +288 -0
  71. package/dist/bundle/chunk-PL5P7UKW.js +25216 -0
  72. package/dist/bundle/chunk-PU7R6XNV.js +80 -0
  73. package/dist/bundle/chunk-QLLBACDR.js +72 -0
  74. package/dist/bundle/chunk-QP7XN5KX.js +407 -0
  75. package/dist/bundle/chunk-QY2F6A3D.js +557 -0
  76. package/dist/bundle/chunk-RLIT7VAZ.js +66 -0
  77. package/dist/bundle/chunk-S4UUN6LD.js +1410 -0
  78. package/dist/bundle/chunk-SKGAKI62.js +86 -0
  79. package/dist/bundle/chunk-SQMZP5MA.js +66653 -0
  80. package/dist/bundle/chunk-UB6NTICY.js +95 -0
  81. package/dist/bundle/chunk-UBHQO5HV.js +778 -0
  82. package/dist/bundle/chunk-UM4RKO24.js +106 -0
  83. package/dist/bundle/chunk-VAHFY732.js +1068 -0
  84. package/dist/bundle/chunk-VGDM4C3F.js +188 -0
  85. package/dist/bundle/chunk-VOUAKCPM.js +41181 -0
  86. package/dist/bundle/chunk-WCCFJ4Q6.js +3736 -0
  87. package/dist/bundle/chunk-WV6EXRDV.js +46 -0
  88. package/dist/bundle/chunk-WVAT5TGY.js +334 -0
  89. package/dist/bundle/chunk-WW76JMKE.js +1243 -0
  90. package/dist/bundle/chunk-XXOMUKC6.js +54 -0
  91. package/dist/bundle/chunk-Y5E2WNWB.js +35 -0
  92. package/dist/bundle/chunk-YDO6RJ2P.js +1337 -0
  93. package/dist/bundle/chunk-ZBCFZCJW.js +388 -0
  94. package/dist/bundle/chunk-ZVVMGPBJ.js +50 -0
  95. package/dist/bundle/command-contract-BWGRUY6L.js +37 -0
  96. package/dist/bundle/command-server-entry-BATOWE3Y.js +166 -0
  97. package/dist/bundle/decode-MZQGYXJH.js +297 -0
  98. package/dist/bundle/definitions-3EONB23J.js +8600 -0
  99. package/dist/bundle/dispatch-NYC4ARWX.js +411 -0
  100. package/dist/bundle/dist-PAKDDIBT.js +191 -0
  101. package/dist/bundle/dist-XZ65GRQ6.js +7577 -0
  102. package/dist/bundle/echarts-7OYGL2GW.js +42501 -0
  103. package/dist/bundle/embed-4I25DVKZ.js +38 -0
  104. package/dist/bundle/embedder-YXKQHAZO.js +111 -0
  105. package/dist/bundle/emoji-4LYX3GOS.js +4271 -0
  106. package/dist/bundle/failure-3YOVYZTX.js +25 -0
  107. package/dist/bundle/first-run-2VL2BOV7.js +29 -0
  108. package/dist/bundle/first-screen-C7FIWZL2.js +37 -0
  109. package/dist/bundle/instructions-UMNDHXG2.js +11 -0
  110. package/dist/bundle/mcp-V27RHILF.js +167 -0
  111. package/dist/bundle/meeting-combined-LS6XO4JH.js +24 -0
  112. package/dist/bundle/meeting-model-VIR465CY.js +25 -0
  113. package/dist/bundle/meeting-semantic-H5J3OOF2.js +22 -0
  114. package/dist/bundle/node-JJ3WDCNJ.js +2340 -0
  115. package/dist/bundle/node-PYFPGL4E.js +176 -0
  116. package/dist/bundle/node-TLZSIHIJ.js +21 -0
  117. package/dist/bundle/node-sqlite-LFWPGDVP.js +74 -0
  118. package/dist/bundle/oauth-42VCSIVL.js +20 -0
  119. package/dist/bundle/open-XJ5R5LHC.js +23 -0
  120. package/dist/bundle/openai-RZBLV4HG.js +238 -0
  121. package/dist/bundle/process-DD6H3K7L.js +91 -0
  122. package/dist/bundle/program-33RT6DER.js +35421 -0
  123. package/dist/bundle/prompt-NQRDM5LY.js +17 -0
  124. package/dist/bundle/recognize-EM7H2IZS.js +26 -0
  125. package/dist/bundle/remote-Z6NU6QQA.js +31 -0
  126. package/dist/bundle/rerank-PNPCSPNF.js +52 -0
  127. package/dist/bundle/schemas-JMKNP4U3.js +2765 -0
  128. package/dist/bundle/serve-SQVGX76J.js +199 -0
  129. package/dist/bundle/server-NPJH45FZ.js +212 -0
  130. package/dist/bundle/server-Z4ZMGRAH.js +79 -0
  131. package/dist/bundle/slack.js +184 -0
  132. package/dist/bundle/sqlite-runtime-F3AJGAPN.js +20 -0
  133. package/dist/bundle/state-JT7ZFSXN.js +36 -0
  134. package/dist/bundle/store-FXGMHRF3.js +181 -0
  135. package/dist/bundle/store-J5ZL2USR.js +295 -0
  136. package/dist/bundle/store-maintenance-command-TIHOIKLZ.js +66 -0
  137. package/dist/bundle/surface-NW6T5OR6.js +65 -0
  138. package/dist/commands/api.d.ts +7 -0
  139. package/dist/commands/api.d.ts.map +1 -0
  140. package/dist/commands/api.js +49 -0
  141. package/dist/commands/api.js.map +1 -0
  142. package/dist/commands/comments.d.ts +3 -0
  143. package/dist/commands/comments.d.ts.map +1 -0
  144. package/dist/commands/comments.js +114 -0
  145. package/dist/commands/comments.js.map +1 -0
  146. package/dist/commands/doctor.d.ts +7 -0
  147. package/dist/commands/doctor.d.ts.map +1 -0
  148. package/dist/commands/doctor.js +53 -0
  149. package/dist/commands/doctor.js.map +1 -0
  150. package/dist/commands/session.d.ts +7 -0
  151. package/dist/commands/session.d.ts.map +1 -0
  152. package/dist/commands/session.js +26 -0
  153. package/dist/commands/session.js.map +1 -0
  154. package/dist/config.d.ts +24 -0
  155. package/dist/config.d.ts.map +1 -0
  156. package/dist/config.js +75 -0
  157. package/dist/config.js.map +1 -0
  158. package/dist/context.d.ts +59 -0
  159. package/dist/context.d.ts.map +1 -0
  160. package/dist/context.js +75 -0
  161. package/dist/context.js.map +1 -0
  162. package/dist/generated/definitions.d.ts +3 -0
  163. package/dist/generated/definitions.d.ts.map +1 -0
  164. package/dist/generated/definitions.js +8596 -0
  165. package/dist/generated/definitions.js.map +1 -0
  166. package/dist/generated/emoji.d.ts +2 -0
  167. package/dist/generated/emoji.d.ts.map +1 -0
  168. package/dist/generated/emoji.js +4265 -0
  169. package/dist/generated/emoji.js.map +1 -0
  170. package/dist/generated/manifest.d.ts +6 -0
  171. package/dist/generated/manifest.d.ts.map +1 -0
  172. package/dist/generated/manifest.js +6139 -0
  173. package/dist/generated/manifest.js.map +1 -0
  174. package/dist/generated/schemas.d.ts +631 -0
  175. package/dist/generated/schemas.d.ts.map +1 -0
  176. package/dist/generated/schemas.js +2426 -0
  177. package/dist/generated/schemas.js.map +1 -0
  178. package/dist/generated/types.d.ts +3220 -0
  179. package/dist/generated/types.d.ts.map +1 -0
  180. package/dist/generated/types.js +5 -0
  181. package/dist/generated/types.js.map +1 -0
  182. package/dist/identity.d.ts +29 -0
  183. package/dist/identity.d.ts.map +1 -0
  184. package/dist/identity.js +32 -0
  185. package/dist/identity.js.map +1 -0
  186. package/dist/index.d.ts +3 -0
  187. package/dist/index.d.ts.map +1 -0
  188. package/dist/index.js +3 -0
  189. package/dist/index.js.map +1 -0
  190. package/dist/messenger.d.ts +12 -0
  191. package/dist/messenger.d.ts.map +1 -0
  192. package/dist/messenger.js +184 -0
  193. package/dist/messenger.js.map +1 -0
  194. package/dist/program.d.ts +6 -0
  195. package/dist/program.d.ts.map +1 -0
  196. package/dist/program.js +116 -0
  197. package/dist/program.js.map +1 -0
  198. package/dist/reasons.d.ts +7 -0
  199. package/dist/reasons.d.ts.map +1 -0
  200. package/dist/reasons.js +20 -0
  201. package/dist/reasons.js.map +1 -0
  202. package/dist/sample/comments.d.ts +61 -0
  203. package/dist/sample/comments.d.ts.map +1 -0
  204. package/dist/sample/comments.js +39 -0
  205. package/dist/sample/comments.js.map +1 -0
  206. package/dist/sample/records.d.ts +16 -0
  207. package/dist/sample/records.d.ts.map +1 -0
  208. package/dist/sample/records.js +22 -0
  209. package/dist/sample/records.js.map +1 -0
  210. package/dist/sample/transport.d.ts +42 -0
  211. package/dist/sample/transport.d.ts.map +1 -0
  212. package/dist/sample/transport.js +153 -0
  213. package/dist/sample/transport.js.map +1 -0
  214. package/dist/setup/flow.d.ts +2 -0
  215. package/dist/setup/flow.d.ts.map +1 -0
  216. package/dist/setup/flow.js +83 -0
  217. package/dist/setup/flow.js.map +1 -0
  218. package/dist/setup/guide.d.ts +6 -0
  219. package/dist/setup/guide.d.ts.map +1 -0
  220. package/dist/setup/guide.js +13 -0
  221. package/dist/setup/guide.js.map +1 -0
  222. package/dist/setup/texts.d.ts +24 -0
  223. package/dist/setup/texts.d.ts.map +1 -0
  224. package/dist/setup/texts.js +24 -0
  225. package/dist/setup/texts.js.map +1 -0
  226. package/dist/slack/adapter.d.ts +36 -0
  227. package/dist/slack/adapter.d.ts.map +1 -0
  228. package/dist/slack/adapter.js +551 -0
  229. package/dist/slack/adapter.js.map +1 -0
  230. package/dist/slack/app-manifest.d.ts +25 -0
  231. package/dist/slack/app-manifest.d.ts.map +1 -0
  232. package/dist/slack/app-manifest.js +51 -0
  233. package/dist/slack/app-manifest.js.map +1 -0
  234. package/dist/slack/client.d.ts +45 -0
  235. package/dist/slack/client.d.ts.map +1 -0
  236. package/dist/slack/client.js +236 -0
  237. package/dist/slack/client.js.map +1 -0
  238. package/dist/slack/map.d.ts +429 -0
  239. package/dist/slack/map.d.ts.map +1 -0
  240. package/dist/slack/map.js +406 -0
  241. package/dist/slack/map.js.map +1 -0
  242. package/dist/slack/mrkdwn.d.ts +9 -0
  243. package/dist/slack/mrkdwn.d.ts.map +1 -0
  244. package/dist/slack/mrkdwn.js +56 -0
  245. package/dist/slack/mrkdwn.js.map +1 -0
  246. package/dist/slack/search.d.ts +24 -0
  247. package/dist/slack/search.d.ts.map +1 -0
  248. package/dist/slack/search.js +99 -0
  249. package/dist/slack/search.js.map +1 -0
  250. package/dist/slack/threads.d.ts +28 -0
  251. package/dist/slack/threads.d.ts.map +1 -0
  252. package/dist/slack/threads.js +56 -0
  253. package/dist/slack/threads.js.map +1 -0
  254. package/dist/slack/tokens.d.ts +17 -0
  255. package/dist/slack/tokens.d.ts.map +1 -0
  256. package/dist/slack/tokens.js +27 -0
  257. package/dist/slack/tokens.js.map +1 -0
  258. package/dist/slack/writes.d.ts +43 -0
  259. package/dist/slack/writes.d.ts.map +1 -0
  260. package/dist/slack/writes.js +277 -0
  261. package/dist/slack/writes.js.map +1 -0
  262. package/dist/version.d.ts +2 -0
  263. package/dist/version.d.ts.map +1 -0
  264. package/dist/version.js +2 -0
  265. package/dist/version.js.map +1 -0
  266. package/dist/wcat.d.ts +3 -0
  267. package/dist/wcat.d.ts.map +1 -0
  268. package/dist/wcat.js +4 -0
  269. package/dist/wcat.js.map +1 -0
  270. package/package.json +89 -4
  271. package/skills/slack-cli/SKILL.md +117 -0
  272. package/skills/slack-cli/references/api/api-admin.md +541 -0
  273. package/skills/slack-cli/references/api/api-api.md +13 -0
  274. package/skills/slack-cli/references/api/api-apps.md +78 -0
  275. package/skills/slack-cli/references/api/api-auth.md +18 -0
  276. package/skills/slack-cli/references/api/api-bots.md +12 -0
  277. package/skills/slack-cli/references/api/api-calls.md +68 -0
  278. package/skills/slack-cli/references/api/api-chat.md +123 -0
  279. package/skills/slack-cli/references/api/api-conversations.md +230 -0
  280. package/skills/slack-cli/references/api/api-dialog.md +13 -0
  281. package/skills/slack-cli/references/api/api-dnd.md +31 -0
  282. package/skills/slack-cli/references/api/api-emoji.md +8 -0
  283. package/skills/slack-cli/references/api/api-files.md +120 -0
  284. package/skills/slack-cli/references/api/api-migration.md +14 -0
  285. package/skills/slack-cli/references/api/api-pins.md +37 -0
  286. package/skills/slack-cli/references/api/api-reactions.md +58 -0
  287. package/skills/slack-cli/references/api/api-reminders.md +51 -0
  288. package/skills/slack-cli/references/api/api-search.md +18 -0
  289. package/skills/slack-cli/references/api/api-stars.md +42 -0
  290. package/skills/slack-cli/references/api/api-team.md +55 -0
  291. package/skills/slack-cli/references/api/api-usergroups.md +80 -0
  292. package/skills/slack-cli/references/api/api-users.md +101 -0
  293. package/skills/slack-cli/references/api/api-views.md +46 -0
  294. package/skills/slack-cli/references/api/api-workflows.md +36 -0
  295. package/skills/slack-cli/references/api.md +35 -0
@@ -0,0 +1,297 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ SAMPLE_RATE,
5
+ decodeOgg
6
+ } from "./chunk-7F6RNAIM.js";
7
+ import "./chunk-H2COZZ55.js";
8
+ import "./chunk-CMZBCWND.js";
9
+ import "./chunk-S4UUN6LD.js";
10
+ import {
11
+ importFrom
12
+ } from "./chunk-Y5E2WNWB.js";
13
+ import {
14
+ CliError
15
+ } from "./chunk-QLLBACDR.js";
16
+ import {
17
+ __name
18
+ } from "./chunk-ZVVMGPBJ.js";
19
+
20
+ // node_modules/.pnpm/@wirecat+cli-core@0.738.0_@wirecat+cli-base@0.132.0_@scalar+openapi-upgrader@0.4.6_comm_2f4ef0250212140e76029d09a7f79b43/node_modules/@wirecat/cli-core/dist/speech/decode.js
21
+ import { spawn } from "node:child_process";
22
+ import { mkdtemp, open, readFile, rm, writeFile } from "node:fs/promises";
23
+ import { createRequire } from "node:module";
24
+ import { tmpdir } from "node:os";
25
+ import { join } from "node:path";
26
+ import { pathToFileURL } from "node:url";
27
+ var LONGEST_AUDIO_SECONDS = 3600;
28
+ var FFMPEG_TIMEOUT_MS = 12e4;
29
+ var FFMPEG_FORMATS = "mov,mp4,m4a,3gp,3g2,mj2,aac,mp3,wav,amr,caf,aiff,flac,ogg,matroska,webm,asf";
30
+ var text = /* @__PURE__ */ __name((bytes, from, length) => String.fromCharCode(...bytes.subarray(from, from + length)), "text");
31
+ var contains = /* @__PURE__ */ __name((bytes, needle, within) => Buffer.from(bytes.buffer, bytes.byteOffset, Math.min(bytes.length, within)).includes(needle, 0, "latin1"), "contains");
32
+ var formatOf = /* @__PURE__ */ __name((bytes) => {
33
+ if (text(bytes, 0, 4) === "OggS") {
34
+ if (contains(bytes, "OpusHead", 128))
35
+ return "opus";
36
+ if (contains(bytes, "vorbis", 128))
37
+ return "vorbis";
38
+ return "other";
39
+ }
40
+ if (text(bytes, 0, 4) === "fLaC")
41
+ return "flac";
42
+ const frame = bytes[0] === 255 && ((bytes[1] ?? 0) & 224) === 224 && ((bytes[1] ?? 0) >> 1 & 3) !== 0;
43
+ if (text(bytes, 0, 3) === "ID3" || frame)
44
+ return "mp3";
45
+ return "other";
46
+ }, "formatOf");
47
+ var everyChannel = /* @__PURE__ */ __name((decoded) => {
48
+ if (!decoded.channelData[0] || decoded.samplesDecoded === 0)
49
+ throw new CliError("validation_error", "no audio in that file");
50
+ return decoded.channelData.map((samples) => ({ samples, rate: decoded.sampleRate }));
51
+ }, "everyChannel");
52
+ var load = /* @__PURE__ */ __name((name) => importFrom(new URL("speech/decode.js", import.meta.resolve("@wirecat/cli-core")).href, pathToFileURL(createRequire(new URL("speech/decode.js", import.meta.resolve("@wirecat/cli-core")).href).resolve(name)).href), "load");
53
+ var decodeVorbis = /* @__PURE__ */ __name(async (bytes) => {
54
+ const { OggVorbisDecoder } = await load("@wasm-audio-decoders/ogg-vorbis");
55
+ const decoder = new OggVorbisDecoder();
56
+ await decoder.ready;
57
+ try {
58
+ return everyChannel(await decoder.decodeFile(bytes));
59
+ } finally {
60
+ decoder.free();
61
+ }
62
+ }, "decodeVorbis");
63
+ var decodeFlac = /* @__PURE__ */ __name(async (bytes) => {
64
+ const { FLACDecoder } = await load("@wasm-audio-decoders/flac");
65
+ const decoder = new FLACDecoder();
66
+ await decoder.ready;
67
+ try {
68
+ return everyChannel(await decoder.decodeFile(bytes));
69
+ } finally {
70
+ decoder.free();
71
+ }
72
+ }, "decodeFlac");
73
+ var decodeMp3 = /* @__PURE__ */ __name(async (bytes) => {
74
+ const { MPEGDecoder } = await load("mpg123-decoder");
75
+ const decoder = new MPEGDecoder();
76
+ await decoder.ready;
77
+ try {
78
+ return everyChannel(decoder.decode(bytes));
79
+ } finally {
80
+ decoder.free();
81
+ }
82
+ }, "decodeMp3");
83
+ var tooLongError = /* @__PURE__ */ __name(() => new CliError("validation_error", `the audio is longer than ${LONGEST_AUDIO_SECONDS / 60} minutes`), "tooLongError");
84
+ var FLOAT = 3;
85
+ var LONGEST_HEADER = 64 * 1024;
86
+ var EXTENSIBLE = 65534;
87
+ var wavStream = /* @__PURE__ */ __name((most) => {
88
+ let head = Buffer.alloc(0);
89
+ let channels = 0;
90
+ let rate = 0;
91
+ let rest = Buffer.alloc(0);
92
+ let length = 0;
93
+ let parts = [];
94
+ const header = /* @__PURE__ */ __name(() => {
95
+ if (head.length < 12)
96
+ return false;
97
+ if (head.toString("latin1", 0, 4) !== "RIFF" || head.toString("latin1", 8, 12) !== "WAVE")
98
+ throw new CliError("validation_error", "ffmpeg did not answer with WAV audio");
99
+ for (let at = 12; at + 8 <= head.length; ) {
100
+ const id = head.toString("latin1", at, at + 4);
101
+ const size = head.readUInt32LE(at + 4);
102
+ if (id === "data") {
103
+ rest = head.subarray(at + 8);
104
+ head = Buffer.alloc(0);
105
+ return true;
106
+ }
107
+ if (at + 8 + size > head.length)
108
+ return false;
109
+ if (id === "fmt ") {
110
+ const tag = head.readUInt16LE(at + 8);
111
+ channels = head.readUInt16LE(at + 10);
112
+ rate = head.readUInt32LE(at + 12);
113
+ if (tag !== FLOAT && tag !== EXTENSIBLE || head.readUInt16LE(at + 22) !== 32 || channels < 1)
114
+ throw new CliError("validation_error", "ffmpeg did not answer with 32-bit float samples");
115
+ parts = Array.from({ length: channels }, () => []);
116
+ }
117
+ at += 8 + size + size % 2;
118
+ }
119
+ return false;
120
+ }, "header");
121
+ return {
122
+ push: /* @__PURE__ */ __name((chunk) => {
123
+ if (channels === 0 || head.length > 0) {
124
+ head = Buffer.concat([head, chunk]);
125
+ if (head.length > LONGEST_HEADER)
126
+ throw new CliError("validation_error", "ffmpeg's WAV header never ended");
127
+ if (!header())
128
+ return true;
129
+ chunk = Buffer.alloc(0);
130
+ }
131
+ const bytes = rest.length ? Buffer.concat([rest, chunk]) : chunk;
132
+ const frame = channels * 4;
133
+ const frames = Math.floor(bytes.length / frame);
134
+ rest = Buffer.from(bytes.subarray(frames * frame));
135
+ if (frames === 0)
136
+ return length <= most;
137
+ const view = new DataView(bytes.buffer, bytes.byteOffset, frames * frame);
138
+ for (let channel = 0; channel < channels; channel++) {
139
+ const samples = new Float32Array(frames);
140
+ for (let index = 0; index < frames; index++)
141
+ samples[index] = view.getFloat32(index * frame + channel * 4, true);
142
+ parts[channel]?.push(samples);
143
+ }
144
+ length += frames;
145
+ return length <= most;
146
+ }, "push"),
147
+ end: /* @__PURE__ */ __name(() => {
148
+ if (channels === 0)
149
+ throw new CliError("validation_error", "no audio in that file");
150
+ return parts.map((pieces, channel) => {
151
+ const samples = new Float32Array(length);
152
+ let at = 0;
153
+ for (const piece of pieces) {
154
+ samples.set(piece, at);
155
+ at += piece.length;
156
+ }
157
+ parts[channel] = [];
158
+ return { samples, rate };
159
+ });
160
+ }, "end")
161
+ };
162
+ }, "wavStream");
163
+ var runFfmpegFile = /* @__PURE__ */ __name((path) => new Promise((resolve, reject) => {
164
+ const child = spawn("ffmpeg", [
165
+ "-nostdin",
166
+ "-hide_banner",
167
+ "-loglevel",
168
+ "error",
169
+ "-protocol_whitelist",
170
+ "file",
171
+ "-format_whitelist",
172
+ FFMPEG_FORMATS,
173
+ "-i",
174
+ path,
175
+ "-vn",
176
+ "-af",
177
+ "aformat=channel_layouts=mono|stereo",
178
+ "-ar",
179
+ String(SAMPLE_RATE),
180
+ "-c:a",
181
+ "pcm_f32le",
182
+ "-bitexact",
183
+ "-f",
184
+ "wav",
185
+ "pipe:1"
186
+ ], { stdio: ["ignore", "pipe", "pipe"], timeout: FFMPEG_TIMEOUT_MS });
187
+ const wav = wavStream(LONGEST_AUDIO_SECONDS * SAMPLE_RATE);
188
+ let long = false;
189
+ let broken;
190
+ let errors = "";
191
+ child.stdout.on("data", (chunk) => {
192
+ if (long || broken)
193
+ return;
194
+ try {
195
+ long = !wav.push(chunk);
196
+ } catch (error) {
197
+ broken = error;
198
+ }
199
+ if (long || broken)
200
+ child.kill();
201
+ });
202
+ child.stderr.on("data", (chunk) => {
203
+ errors = (errors + chunk.toString()).slice(-500);
204
+ });
205
+ child.on("error", (error) => reject(error.code === "ENOENT" ? new CliError("validation_error", "only ffmpeg reads this audio format, and ffmpeg is not installed") : error));
206
+ child.on("close", (code) => {
207
+ if (long)
208
+ return reject(tooLongError());
209
+ if (broken)
210
+ return reject(broken);
211
+ if (code !== 0)
212
+ return reject(new CliError("validation_error", `ffmpeg could not read the audio: ${errors.trim() || code}`));
213
+ try {
214
+ resolve(wav.end());
215
+ } catch (error) {
216
+ reject(error);
217
+ }
218
+ });
219
+ }), "runFfmpegFile");
220
+ var runFfmpeg = /* @__PURE__ */ __name(async (bytes) => {
221
+ const directory = await mkdtemp(join(tmpdir(), "wirecat-audio-"));
222
+ try {
223
+ const input = join(directory, "audio");
224
+ await writeFile(input, bytes, { mode: 384 });
225
+ return await runFfmpegFile(input);
226
+ } finally {
227
+ await rm(directory, { recursive: true, force: true });
228
+ }
229
+ }, "runFfmpeg");
230
+ var BUNDLED = {
231
+ opus: decodeOgg,
232
+ vorbis: decodeVorbis,
233
+ flac: decodeFlac,
234
+ mp3: decodeMp3
235
+ };
236
+ var tooLong = /* @__PURE__ */ __name((pcm) => pcm.samples.length / pcm.rate > LONGEST_AUDIO_SECONDS, "tooLong");
237
+ var fromFfmpeg = /* @__PURE__ */ __name((answer) => Array.isArray(answer) ? { channels: answer, mixed: false } : { channels: [answer], mixed: true }, "fromFfmpeg");
238
+ var decodeChannels = /* @__PURE__ */ __name(async (bytes, ffmpeg = runFfmpeg) => {
239
+ const format = formatOf(bytes);
240
+ const decoded = format === "other" ? fromFfmpeg(await ffmpeg(bytes)) : await BUNDLED[format](bytes).then((channels) => ({ channels, mixed: false }), (error) => ffmpeg(bytes).then(fromFfmpeg, () => {
241
+ throw error;
242
+ }));
243
+ if (decoded.channels.length === 0)
244
+ throw new CliError("validation_error", "no audio in that file");
245
+ if (decoded.channels.some(tooLong))
246
+ throw tooLongError();
247
+ return decoded;
248
+ }, "decodeChannels");
249
+ var decodeChannelsFile = /* @__PURE__ */ __name(async (path, { maxBytes = 64 * 1024 * 1024, ffmpegFile = runFfmpegFile } = {}) => {
250
+ const file = await open(path, "r");
251
+ let start;
252
+ let size;
253
+ try {
254
+ size = (await file.stat()).size;
255
+ const head = Buffer.alloc(Math.min(size, 128));
256
+ await file.read(head, 0, head.length, 0);
257
+ start = head;
258
+ } finally {
259
+ await file.close();
260
+ }
261
+ if (formatOf(start) === "other") {
262
+ const channels = await ffmpegFile(path);
263
+ if (channels.some(tooLong))
264
+ throw tooLongError();
265
+ return { channels, mixed: false };
266
+ }
267
+ if (size > maxBytes)
268
+ throw new CliError("validation_error", `the audio file is larger than ${Math.round(maxBytes / 1024 / 1024)} MB`, {
269
+ reason: "file.too-large"
270
+ });
271
+ return decodeChannels(new Uint8Array(await readFile(path)), () => ffmpegFile(path));
272
+ }, "decodeChannelsFile");
273
+ var mixDown = /* @__PURE__ */ __name((channels) => {
274
+ const [first] = channels;
275
+ if (!first)
276
+ throw new CliError("validation_error", "no audio in that file");
277
+ if (channels.length === 1)
278
+ return first;
279
+ const length = channels.reduce((longest, { samples: samples2 }) => Math.max(longest, samples2.length), 0);
280
+ const samples = new Float32Array(length);
281
+ for (const channel of channels)
282
+ for (let index = 0; index < channel.samples.length; index++)
283
+ samples[index] = (samples[index] ?? 0) + (channel.samples[index] ?? 0) / channels.length;
284
+ return { samples, rate: first.rate };
285
+ }, "mixDown");
286
+ var decodeAudio = /* @__PURE__ */ __name(async (bytes, ffmpeg = runFfmpeg) => mixDown((await decodeChannels(bytes, ffmpeg)).channels), "decodeAudio");
287
+ export {
288
+ LONGEST_AUDIO_SECONDS,
289
+ decodeAudio,
290
+ decodeChannels,
291
+ decodeChannelsFile,
292
+ formatOf,
293
+ mixDown,
294
+ runFfmpeg,
295
+ runFfmpegFile,
296
+ wavStream
297
+ };