@wirecat/attio-cli 0.8.0 → 0.10.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 (207) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/contracts/wirecat.json +1 -0
  3. package/dist/bin/attio.js +11 -11
  4. package/dist/bundle/attio.js +5 -166
  5. package/dist/bundle/{chunk-UXJZISVL.js → chunk-OGWKDPR5.js} +2 -1
  6. package/dist/bundle/chunk-TQAECZFO.js +13 -0
  7. package/dist/bundle/{definitions-FODOIPM2.js → definitions-J73IBAHT.js} +1 -1
  8. package/dist/bundle/program-NSBWZ25F.js +6201 -0
  9. package/dist/bundle/{schemas-YGSTNU6F.js → schemas-G3HFAS45.js} +576 -29
  10. package/dist/commands/api.js +1 -2
  11. package/dist/commands/crm.js +1 -4
  12. package/dist/commands/schedule.js +1 -1
  13. package/dist/commands/session.js +1 -2
  14. package/dist/config.js +1 -2
  15. package/dist/context.js +1 -1
  16. package/dist/identity.js +1 -0
  17. package/dist/program.js +1 -2
  18. package/dist/version.js +1 -1
  19. package/package.json +4 -4
  20. package/dist/activities.d.ts +0 -4
  21. package/dist/activities.d.ts.map +0 -1
  22. package/dist/activities.js.map +0 -1
  23. package/dist/bin/attio.d.ts +0 -3
  24. package/dist/bin/attio.d.ts.map +0 -1
  25. package/dist/bin/attio.js.map +0 -1
  26. package/dist/bundle/agent-GUXXSLT5.js +0 -38
  27. package/dist/bundle/all-profiles-63N3EQ46.js +0 -320
  28. package/dist/bundle/anthropic-B4W7MZQE.js +0 -91
  29. package/dist/bundle/app-server-EXNGTHWO.js +0 -250
  30. package/dist/bundle/bun-OPDGMZZQ.js +0 -169
  31. package/dist/bundle/bun-sqlite-NBAY7FR2.js +0 -76
  32. package/dist/bundle/chunk-2JHVQMVC.js +0 -16
  33. package/dist/bundle/chunk-2QDUP74I.js +0 -794
  34. package/dist/bundle/chunk-2XBDILVW.js +0 -53
  35. package/dist/bundle/chunk-3HC5F3P7.js +0 -24
  36. package/dist/bundle/chunk-3MSHGNVE.js +0 -1243
  37. package/dist/bundle/chunk-3YM4B2GT.js +0 -63
  38. package/dist/bundle/chunk-4N7PP76S.js +0 -6848
  39. package/dist/bundle/chunk-4RBMCXZT.js +0 -1337
  40. package/dist/bundle/chunk-4RSWOPKL.js +0 -323
  41. package/dist/bundle/chunk-5JKTVAXX.js +0 -2788
  42. package/dist/bundle/chunk-5N2V6XO7.js +0 -119
  43. package/dist/bundle/chunk-5WD22IXQ.js +0 -66
  44. package/dist/bundle/chunk-6K4Z6CAM.js +0 -43997
  45. package/dist/bundle/chunk-6TD3DCWC.js +0 -106
  46. package/dist/bundle/chunk-7Z53MLQP.js +0 -388
  47. package/dist/bundle/chunk-AATTOFNY.js +0 -2045
  48. package/dist/bundle/chunk-APARYILG.js +0 -743
  49. package/dist/bundle/chunk-D72URWJE.js +0 -532
  50. package/dist/bundle/chunk-DFDN6AUB.js +0 -21
  51. package/dist/bundle/chunk-DM7KWVDZ.js +0 -3752
  52. package/dist/bundle/chunk-DNCLQPOM.js +0 -7
  53. package/dist/bundle/chunk-DPD4FMHN.js +0 -388
  54. package/dist/bundle/chunk-DPV53EZC.js +0 -206
  55. package/dist/bundle/chunk-DURNR4RO.js +0 -353
  56. package/dist/bundle/chunk-EH6ZEJGT.js +0 -932
  57. package/dist/bundle/chunk-EVUMQKV7.js +0 -76
  58. package/dist/bundle/chunk-EY36BTKZ.js +0 -108
  59. package/dist/bundle/chunk-FH6OEGGN.js +0 -557
  60. package/dist/bundle/chunk-FOP6G45D.js +0 -358
  61. package/dist/bundle/chunk-GGMAIIVE.js +0 -38
  62. package/dist/bundle/chunk-GTEX4IUO.js +0 -334
  63. package/dist/bundle/chunk-HZ3C4WXD.js +0 -142
  64. package/dist/bundle/chunk-IA7LLLEI.js +0 -100
  65. package/dist/bundle/chunk-J6GVVISK.js +0 -185
  66. package/dist/bundle/chunk-JG6LCSEX.js +0 -407
  67. package/dist/bundle/chunk-JIGEJZ4I.js +0 -68943
  68. package/dist/bundle/chunk-KVTNYRDO.js +0 -1007
  69. package/dist/bundle/chunk-L45WN3AR.js +0 -80
  70. package/dist/bundle/chunk-L72WUJAS.js +0 -54
  71. package/dist/bundle/chunk-LKH3UKLO.js +0 -230
  72. package/dist/bundle/chunk-LM3W7YOM.js +0 -274
  73. package/dist/bundle/chunk-M4AC55ZB.js +0 -12733
  74. package/dist/bundle/chunk-MCLQTCGH.js +0 -1202
  75. package/dist/bundle/chunk-NB7EOAUZ.js +0 -123
  76. package/dist/bundle/chunk-NISH4UXM.js +0 -58
  77. package/dist/bundle/chunk-OYEVYOCL.js +0 -259
  78. package/dist/bundle/chunk-P7G5HFY3.js +0 -288
  79. package/dist/bundle/chunk-PAEKXVJW.js +0 -188
  80. package/dist/bundle/chunk-PL5P7UKW.js +0 -25216
  81. package/dist/bundle/chunk-PLPBEWD4.js +0 -170
  82. package/dist/bundle/chunk-PMQ7GP6X.js +0 -95
  83. package/dist/bundle/chunk-Q7ICVP25.js +0 -18
  84. package/dist/bundle/chunk-QPPOIWPY.js +0 -1246
  85. package/dist/bundle/chunk-QSJKSPWF.js +0 -131
  86. package/dist/bundle/chunk-RDVTHFPP.js +0 -338
  87. package/dist/bundle/chunk-RQORQN2V.js +0 -4072
  88. package/dist/bundle/chunk-RRTMPSQR.js +0 -29
  89. package/dist/bundle/chunk-S4UUN6LD.js +0 -1410
  90. package/dist/bundle/chunk-S6JG4YUH.js +0 -72
  91. package/dist/bundle/chunk-SCI7QEHF.js +0 -362
  92. package/dist/bundle/chunk-SSA6JBPA.js +0 -778
  93. package/dist/bundle/chunk-T4J7XFXT.js +0 -9667
  94. package/dist/bundle/chunk-TTF5DP4V.js +0 -1197
  95. package/dist/bundle/chunk-TXDR6YSF.js +0 -23
  96. package/dist/bundle/chunk-TY7NDMFY.js +0 -46
  97. package/dist/bundle/chunk-UDSL3MUU.js +0 -2333
  98. package/dist/bundle/chunk-UKHF37ZU.js +0 -1068
  99. package/dist/bundle/chunk-V57E7PJQ.js +0 -161
  100. package/dist/bundle/chunk-V7IF2K3P.js +0 -52
  101. package/dist/bundle/chunk-VB7FZOYX.js +0 -633
  102. package/dist/bundle/chunk-VZ5PPYDG.js +0 -77
  103. package/dist/bundle/chunk-WOPVBRPV.js +0 -29
  104. package/dist/bundle/chunk-WXQGA6XK.js +0 -50
  105. package/dist/bundle/chunk-XQGN2D44.js +0 -86
  106. package/dist/bundle/chunk-XQUUANA2.js +0 -24600
  107. package/dist/bundle/chunk-Y5E2WNWB.js +0 -35
  108. package/dist/bundle/chunk-YNGU36GW.js +0 -218
  109. package/dist/bundle/chunk-YWDFYQOU.js +0 -82
  110. package/dist/bundle/chunk-ZVVMGPBJ.js +0 -50
  111. package/dist/bundle/chunk-ZZD2YPOX.js +0 -156
  112. package/dist/bundle/command-contract-KCCW4LNI.js +0 -37
  113. package/dist/bundle/command-server-entry-3NPPABQQ.js +0 -166
  114. package/dist/bundle/decode-26M7XE2B.js +0 -297
  115. package/dist/bundle/dispatch-2FTOHA5D.js +0 -411
  116. package/dist/bundle/dist-EM7KLEG4.js +0 -7577
  117. package/dist/bundle/dist-PAKDDIBT.js +0 -191
  118. package/dist/bundle/echarts-O3TNDAXJ.js +0 -42501
  119. package/dist/bundle/embed-XJLEAWXE.js +0 -38
  120. package/dist/bundle/embedder-OEL6PXEH.js +0 -111
  121. package/dist/bundle/failure-OHIXWTR6.js +0 -25
  122. package/dist/bundle/first-run-CIXGBXY6.js +0 -29
  123. package/dist/bundle/first-screen-5FK4D45F.js +0 -38
  124. package/dist/bundle/instructions-AMH5RWVJ.js +0 -11
  125. package/dist/bundle/mcp-5HFPWC3W.js +0 -167
  126. package/dist/bundle/meeting-combined-DMVGQNJ7.js +0 -24
  127. package/dist/bundle/meeting-model-2THAT7OH.js +0 -25
  128. package/dist/bundle/meeting-semantic-Q6XYFYUD.js +0 -22
  129. package/dist/bundle/node-EGMCBAO7.js +0 -176
  130. package/dist/bundle/node-KM3CUABH.js +0 -2340
  131. package/dist/bundle/node-TLZSIHIJ.js +0 -21
  132. package/dist/bundle/node-sqlite-2SWWGW6H.js +0 -74
  133. package/dist/bundle/oauth-V5LGTXF2.js +0 -20
  134. package/dist/bundle/open-25EKOTZA.js +0 -23
  135. package/dist/bundle/openai-VX3OLIHM.js +0 -238
  136. package/dist/bundle/process-SGHEN6MQ.js +0 -91
  137. package/dist/bundle/program-Z5NUNXME.js +0 -34214
  138. package/dist/bundle/prompt-2VSPX5S7.js +0 -17
  139. package/dist/bundle/recognize-NA5XUFKK.js +0 -26
  140. package/dist/bundle/remote-BOME6XOE.js +0 -31
  141. package/dist/bundle/rerank-NG3XMFCV.js +0 -52
  142. package/dist/bundle/serve-MR67OBED.js +0 -199
  143. package/dist/bundle/server-4BWAGJQO.js +0 -80
  144. package/dist/bundle/server-OP2HJNXD.js +0 -213
  145. package/dist/bundle/sqlite-runtime-V5U6F5EB.js +0 -20
  146. package/dist/bundle/state-L4MWAATO.js +0 -36
  147. package/dist/bundle/store-2ALTEH55.js +0 -181
  148. package/dist/bundle/store-CXZFRG5D.js +0 -297
  149. package/dist/bundle/store-maintenance-command-LC55DRQA.js +0 -67
  150. package/dist/bundle/surface-3GRJ7473.js +0 -66
  151. package/dist/commands/api.d.ts +0 -12
  152. package/dist/commands/api.d.ts.map +0 -1
  153. package/dist/commands/api.js.map +0 -1
  154. package/dist/commands/crm.d.ts +0 -7
  155. package/dist/commands/crm.d.ts.map +0 -1
  156. package/dist/commands/crm.js.map +0 -1
  157. package/dist/commands/schedule.d.ts +0 -3
  158. package/dist/commands/schedule.d.ts.map +0 -1
  159. package/dist/commands/schedule.js.map +0 -1
  160. package/dist/commands/session.d.ts +0 -8
  161. package/dist/commands/session.d.ts.map +0 -1
  162. package/dist/commands/session.js.map +0 -1
  163. package/dist/config.d.ts +0 -13
  164. package/dist/config.d.ts.map +0 -1
  165. package/dist/config.js.map +0 -1
  166. package/dist/context.d.ts +0 -37
  167. package/dist/context.d.ts.map +0 -1
  168. package/dist/context.js.map +0 -1
  169. package/dist/generated/definitions.d.ts +0 -3
  170. package/dist/generated/definitions.d.ts.map +0 -1
  171. package/dist/generated/definitions.js.map +0 -1
  172. package/dist/generated/manifest.d.ts +0 -6
  173. package/dist/generated/manifest.d.ts.map +0 -1
  174. package/dist/generated/manifest.js.map +0 -1
  175. package/dist/generated/schemas.d.ts +0 -383
  176. package/dist/generated/schemas.d.ts.map +0 -1
  177. package/dist/generated/schemas.js.map +0 -1
  178. package/dist/generated/types.d.ts +0 -10166
  179. package/dist/generated/types.d.ts.map +0 -1
  180. package/dist/generated/types.js.map +0 -1
  181. package/dist/generated/wirecat-config.d.ts +0 -15
  182. package/dist/generated/wirecat-config.d.ts.map +0 -1
  183. package/dist/generated/wirecat-config.js.map +0 -1
  184. package/dist/hooks.d.ts +0 -33
  185. package/dist/hooks.d.ts.map +0 -1
  186. package/dist/hooks.js.map +0 -1
  187. package/dist/identity.d.ts +0 -33
  188. package/dist/identity.d.ts.map +0 -1
  189. package/dist/identity.js.map +0 -1
  190. package/dist/index.d.ts +0 -3
  191. package/dist/index.d.ts.map +0 -1
  192. package/dist/index.js.map +0 -1
  193. package/dist/links.d.ts +0 -10
  194. package/dist/links.d.ts.map +0 -1
  195. package/dist/links.js.map +0 -1
  196. package/dist/meetings.d.ts +0 -57
  197. package/dist/meetings.d.ts.map +0 -1
  198. package/dist/meetings.js.map +0 -1
  199. package/dist/program.d.ts +0 -6
  200. package/dist/program.d.ts.map +0 -1
  201. package/dist/program.js.map +0 -1
  202. package/dist/version.d.ts +0 -2
  203. package/dist/version.d.ts.map +0 -1
  204. package/dist/version.js.map +0 -1
  205. package/dist/wcat.d.ts +0 -3
  206. package/dist/wcat.d.ts.map +0 -1
  207. package/dist/wcat.js.map +0 -1
@@ -1,166 +0,0 @@
1
- import { createRequire as __bundleRequire } from "node:module";
2
- const require = __bundleRequire(import.meta.url);
3
- import {
4
- COMMAND_SERVER_CONCURRENT,
5
- enterCommandServer,
6
- serveCommands
7
- } from "./chunk-PAEKXVJW.js";
8
- import "./chunk-Q7ICVP25.js";
9
- import {
10
- ensureSqlite
11
- } from "./chunk-6TD3DCWC.js";
12
- import "./chunk-QSJKSPWF.js";
13
- import {
14
- commandServerRequest,
15
- exitCodeSet,
16
- inCommandServerRequest
17
- } from "./chunk-M4AC55ZB.js";
18
- import "./chunk-SCI7QEHF.js";
19
- import "./chunk-V7IF2K3P.js";
20
- import "./chunk-GTEX4IUO.js";
21
- import "./chunk-3YM4B2GT.js";
22
- import "./chunk-5WD22IXQ.js";
23
- import {
24
- asOwnProcess
25
- } from "./chunk-AATTOFNY.js";
26
- import "./chunk-ZZD2YPOX.js";
27
- import "./chunk-RRTMPSQR.js";
28
- import "./chunk-RQORQN2V.js";
29
- import "./chunk-DNCLQPOM.js";
30
- import "./chunk-7Z53MLQP.js";
31
- import "./chunk-TTF5DP4V.js";
32
- import "./chunk-LM3W7YOM.js";
33
- import "./chunk-L72WUJAS.js";
34
- import "./chunk-PMQ7GP6X.js";
35
- import "./chunk-GGMAIIVE.js";
36
- import "./chunk-5JKTVAXX.js";
37
- import {
38
- catchCrashes
39
- } from "./chunk-QPPOIWPY.js";
40
- import "./chunk-S4UUN6LD.js";
41
- import "./chunk-Y5E2WNWB.js";
42
- import {
43
- CliError
44
- } from "./chunk-S6JG4YUH.js";
45
- import {
46
- __name
47
- } from "./chunk-ZVVMGPBJ.js";
48
-
49
- // node_modules/.pnpm/@wirecat+cli-core@1.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_dd5172c52281f8f1e2dd1d4e9555d5c3/node_modules/@wirecat/cli-core/dist/cli/command-server-entry.js
50
- import { PassThrough } from "node:stream";
51
- var route = /* @__PURE__ */ __name((stream, sink) => {
52
- const original = stream.write;
53
- stream.write = ((chunk, encoding, callback) => {
54
- sink()(typeof chunk === "string" ? Buffer.from(chunk, typeof encoding === "string" ? encoding : "utf8") : Buffer.from(chunk));
55
- const done = typeof encoding === "function" ? encoding : callback;
56
- if (done)
57
- process.nextTick(done);
58
- return true;
59
- });
60
- return () => {
61
- stream.write = original;
62
- };
63
- }, "route");
64
- var closedStdin = /* @__PURE__ */ __name(() => {
65
- const stdin = new PassThrough();
66
- stdin.end();
67
- return stdin;
68
- }, "closedStdin");
69
- var useStdin = /* @__PURE__ */ __name((outside) => Object.defineProperty(process, "stdin", {
70
- get: /* @__PURE__ */ __name(() => commandServerRequest()?.stdin ?? outside, "get"),
71
- configurable: true,
72
- enumerable: true
73
- }), "useStdin");
74
- var roomFor = /* @__PURE__ */ __name((runs) => {
75
- const emitters = [process, process.stdout, process.stderr];
76
- const before = emitters.map((emitter) => emitter.getMaxListeners());
77
- for (const emitter of emitters)
78
- emitter.setMaxListeners(emitter.getMaxListeners() + 2 * runs);
79
- return () => {
80
- for (const [at, emitter] of emitters.entries())
81
- emitter.setMaxListeners(before[at]);
82
- };
83
- }, "roomFor");
84
- var serveEntry = /* @__PURE__ */ __name(async (entry, io, { firstRunAt, commanderExit }) => {
85
- const release = catchCrashes({
86
- cli: entry.app.command,
87
- interactive: false,
88
- ...entry.reasons ? { reasons: entry.reasons } : {},
89
- target: io.signals
90
- });
91
- const stopper = new AbortController();
92
- const stop = /* @__PURE__ */ __name(() => stopper.abort(new CliError("cancelled", "the command server was stopped", { retryable: false })), "stop");
93
- const protocol = io.stdout.write.bind(io.stdout);
94
- const ownStderr = io.stderr.write.bind(io.stderr);
95
- const toStderr = /* @__PURE__ */ __name((chunk) => {
96
- ownStderr(chunk);
97
- }, "toStderr");
98
- const sink = /* @__PURE__ */ __name((pick) => () => {
99
- const request = commandServerRequest();
100
- return request ? (chunk) => pick(request).push(chunk) : toStderr;
101
- }, "sink");
102
- const unrouteOut = route(process.stdout, sink((request) => request.stdout));
103
- const unrouteErr = route(process.stderr, sink((request) => request.stderr));
104
- const stdin = Object.getOwnPropertyDescriptor(process, "stdin");
105
- const requests = io.stdin;
106
- useStdin(closedStdin());
107
- const unroom = roomFor(COMMAND_SERVER_CONCURRENT);
108
- io.signals.on("SIGINT", stop).on("SIGTERM", stop);
109
- io.stdout.on("error", stop);
110
- const run = /* @__PURE__ */ __name(async (argv, alone) => {
111
- const request = { stdout: [], stderr: [], stdin: closedStdin(), alone };
112
- const requestIo = { ...io, argv: [...io.argv.slice(0, 2), ...argv], stdin: request.stdin };
113
- const context = {
114
- args: argv,
115
- env: io.env,
116
- tty: false,
117
- signal: stopper.signal,
118
- atStart: /* @__PURE__ */ __name(async (command) => {
119
- await enterCommandServer(command, entry.app.command);
120
- await firstRunAt(entry, requestIo, () => true)(command);
121
- }, "atStart"),
122
- ask: /* @__PURE__ */ __name(async () => false, "ask"),
123
- openBrowser: /* @__PURE__ */ __name(async () => void 0, "openBrowser"),
124
- outputClosed: /* @__PURE__ */ __name(() => false, "outputClosed"),
125
- setExitCode: /* @__PURE__ */ __name((code2) => {
126
- request.exitCode = code2;
127
- }, "setExitCode")
128
- };
129
- const code = await inCommandServerRequest(request, () => asOwnProcess(async () => {
130
- try {
131
- const returned = await entry.run(context);
132
- return typeof returned === "number" ? returned : exitCodeSet() ?? 0;
133
- } catch (error) {
134
- return commanderExit(error) ?? entry.fail(error, context);
135
- }
136
- }));
137
- const text = /* @__PURE__ */ __name((chunks) => Buffer.concat(chunks).toString("utf8"), "text");
138
- return { code, stdout: text(request.stdout), stderr: text(request.stderr) };
139
- }, "run");
140
- try {
141
- if (entry.sqlite)
142
- await ensureSqlite();
143
- await serveCommands({
144
- input: requests,
145
- write: /* @__PURE__ */ __name((line) => new Promise((resolve) => protocol(line) ? resolve() : io.stdout.once("drain", resolve)), "write"),
146
- run,
147
- cli: entry.app.command,
148
- concurrent: COMMAND_SERVER_CONCURRENT,
149
- version: entry.app.version,
150
- signal: stopper.signal
151
- });
152
- io.setExitCode(0);
153
- } finally {
154
- io.signals.off("SIGINT", stop).off("SIGTERM", stop);
155
- unroom();
156
- unrouteOut();
157
- unrouteErr();
158
- if (stdin)
159
- Object.defineProperty(process, "stdin", stdin);
160
- requests.destroy?.();
161
- release();
162
- }
163
- }, "serveEntry");
164
- export {
165
- serveEntry
166
- };
@@ -1,297 +0,0 @@
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-LKH3UKLO.js";
7
- import "./chunk-5JKTVAXX.js";
8
- import "./chunk-QPPOIWPY.js";
9
- import "./chunk-S4UUN6LD.js";
10
- import {
11
- importFrom
12
- } from "./chunk-Y5E2WNWB.js";
13
- import {
14
- CliError
15
- } from "./chunk-S6JG4YUH.js";
16
- import {
17
- __name
18
- } from "./chunk-ZVVMGPBJ.js";
19
-
20
- // node_modules/.pnpm/@wirecat+cli-core@1.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_dd5172c52281f8f1e2dd1d4e9555d5c3/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
- };