@wirecat/notion-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 (243) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/LICENSE +204 -0
  3. package/README.md +36 -2
  4. package/contracts/wirecat.json +1315 -0
  5. package/dist/bin/notion.d.ts +3 -0
  6. package/dist/bin/notion.d.ts.map +1 -0
  7. package/dist/bin/notion.js +40 -0
  8. package/dist/bin/notion.js.map +1 -0
  9. package/dist/bundle/all-profiles-OETMCOLN.js +278 -0
  10. package/dist/bundle/anthropic-5Y3O2TYM.js +91 -0
  11. package/dist/bundle/app-server-IVWBIVHC.js +231 -0
  12. package/dist/bundle/bun-EO636SAD.js +169 -0
  13. package/dist/bundle/bun-sqlite-C2T7QJ2M.js +76 -0
  14. package/dist/bundle/chunk-24FAYAML.js +52 -0
  15. package/dist/bundle/chunk-2YR3RYT4.js +73 -0
  16. package/dist/bundle/chunk-35K5T6WV.js +24 -0
  17. package/dist/bundle/chunk-3D3PFXBP.js +2315 -0
  18. package/dist/bundle/chunk-47R43UVJ.js +1068 -0
  19. package/dist/bundle/chunk-4GC5DBHW.js +100 -0
  20. package/dist/bundle/chunk-5D4AEUVA.js +24783 -0
  21. package/dist/bundle/chunk-64D5VUZ4.js +9564 -0
  22. package/dist/bundle/chunk-66PL7P4C.js +23 -0
  23. package/dist/bundle/chunk-7FII4DCE.js +362 -0
  24. package/dist/bundle/chunk-7N5QB6NL.js +156 -0
  25. package/dist/bundle/chunk-AE2KQ37N.js +95 -0
  26. package/dist/bundle/chunk-AQZO3ITW.js +58 -0
  27. package/dist/bundle/chunk-B2WFKFYL.js +1488 -0
  28. package/dist/bundle/chunk-B2XKEEFX.js +230 -0
  29. package/dist/bundle/chunk-B4B65XIO.js +73 -0
  30. package/dist/bundle/chunk-BWICUW7W.js +288 -0
  31. package/dist/bundle/chunk-CLG2ISQH.js +206 -0
  32. package/dist/bundle/chunk-CWVAYQXI.js +185 -0
  33. package/dist/bundle/chunk-D72URWJE.js +532 -0
  34. package/dist/bundle/chunk-DFDN6AUB.js +21 -0
  35. package/dist/bundle/chunk-DIM5YWBU.js +53 -0
  36. package/dist/bundle/chunk-EGTBL3MJ.js +6848 -0
  37. package/dist/bundle/chunk-EH6ZEJGT.js +932 -0
  38. package/dist/bundle/chunk-EPAZ7DJB.js +783 -0
  39. package/dist/bundle/chunk-ESZT4WW3.js +142 -0
  40. package/dist/bundle/chunk-EU5WCOMQ.js +4001 -0
  41. package/dist/bundle/chunk-F6MLJ3V5.js +72 -0
  42. package/dist/bundle/chunk-FF4DDBCB.js +1028 -0
  43. package/dist/bundle/chunk-GA3URWIF.js +46 -0
  44. package/dist/bundle/chunk-HRTIRRXR.js +3112 -0
  45. package/dist/bundle/chunk-HWRKURQH.js +54 -0
  46. package/dist/bundle/chunk-IQWEJEB5.js +39724 -0
  47. package/dist/bundle/chunk-JK44XO2S.js +392 -0
  48. package/dist/bundle/chunk-JKIN5TOU.js +131 -0
  49. package/dist/bundle/chunk-K5TWMQSY.js +188 -0
  50. package/dist/bundle/chunk-KHOVVPLC.js +18 -0
  51. package/dist/bundle/chunk-NLDYZBTC.js +5862 -0
  52. package/dist/bundle/chunk-OWJDC4CB.js +217 -0
  53. package/dist/bundle/chunk-QBC23NHD.js +38 -0
  54. package/dist/bundle/chunk-QC3KOJT4.js +300 -0
  55. package/dist/bundle/chunk-R6ZM45NF.js +1239 -0
  56. package/dist/bundle/chunk-RAZKIHGH.js +76 -0
  57. package/dist/bundle/chunk-RDZ7SVBZ.js +731 -0
  58. package/dist/bundle/chunk-RLSFOR2D.js +161 -0
  59. package/dist/bundle/chunk-RSIS7BR7.js +2778 -0
  60. package/dist/bundle/chunk-ST2UC7FS.js +1324 -0
  61. package/dist/bundle/chunk-TR7R5DL4.js +370 -0
  62. package/dist/bundle/chunk-TSCIIXN3.js +106 -0
  63. package/dist/bundle/chunk-UWIA2G6Q.js +12737 -0
  64. package/dist/bundle/chunk-UWW24JQF.js +66 -0
  65. package/dist/bundle/chunk-WK3OSDNV.js +1197 -0
  66. package/dist/bundle/chunk-WM7663C2.js +1221 -0
  67. package/dist/bundle/chunk-WVZFXI36.js +274 -0
  68. package/dist/bundle/chunk-WWMB4UHF.js +78 -0
  69. package/dist/bundle/chunk-XC5CKHX2.js +63 -0
  70. package/dist/bundle/chunk-XL2HXHP3.js +82 -0
  71. package/dist/bundle/chunk-XQUUANA2.js +24600 -0
  72. package/dist/bundle/chunk-XYIT2XB3.js +1372 -0
  73. package/dist/bundle/chunk-Y5E2WNWB.js +35 -0
  74. package/dist/bundle/chunk-YA4LSSDZ.js +64499 -0
  75. package/dist/bundle/chunk-ZI3YTXSF.js +2 -0
  76. package/dist/bundle/chunk-ZVVMGPBJ.js +50 -0
  77. package/dist/bundle/command-contract-6G5DC2FN.js +35 -0
  78. package/dist/bundle/command-server-entry-A66DJ3MH.js +164 -0
  79. package/dist/bundle/decode-7XOFRAAT.js +163 -0
  80. package/dist/bundle/definitions-M3U4UYHN.js +45607 -0
  81. package/dist/bundle/dispatch-FEKU5UXC.js +411 -0
  82. package/dist/bundle/dist-YFKABFFF.js +7577 -0
  83. package/dist/bundle/echarts-XD2JSWU4.js +42501 -0
  84. package/dist/bundle/embed-F3HYGAF7.js +38 -0
  85. package/dist/bundle/embedder-GSEDDUH7.js +111 -0
  86. package/dist/bundle/failure-HDJLR2YJ.js +25 -0
  87. package/dist/bundle/first-run-TXNTIUSP.js +28 -0
  88. package/dist/bundle/first-screen-JZPJND7J.js +33 -0
  89. package/dist/bundle/instructions-NZGJ4FW5.js +11 -0
  90. package/dist/bundle/mcp-VFIOZDVY.js +167 -0
  91. package/dist/bundle/node-KM3CUABH.js +2340 -0
  92. package/dist/bundle/node-RPKPDYQS.js +176 -0
  93. package/dist/bundle/node-TLZSIHIJ.js +21 -0
  94. package/dist/bundle/node-sqlite-KH2UUYVO.js +74 -0
  95. package/dist/bundle/notion.js +185 -0
  96. package/dist/bundle/oauth-NKAI7TQD.js +20 -0
  97. package/dist/bundle/open-WSAEAA2V.js +23 -0
  98. package/dist/bundle/openai-JPVDGHG5.js +238 -0
  99. package/dist/bundle/process-5ZFVKOQX.js +91 -0
  100. package/dist/bundle/program-M3D56D6T.js +28854 -0
  101. package/dist/bundle/prompt-FROYQ5LV.js +17 -0
  102. package/dist/bundle/recognize-NYCHQMCX.js +26 -0
  103. package/dist/bundle/remote-4OERF3Z4.js +32 -0
  104. package/dist/bundle/rerank-TEGXFUWY.js +52 -0
  105. package/dist/bundle/schemas-MZNNOEYN.js +12214 -0
  106. package/dist/bundle/serve-HLYYBAXY.js +199 -0
  107. package/dist/bundle/server-D5OYNEUW.js +193 -0
  108. package/dist/bundle/server-LWZGVMNW.js +62 -0
  109. package/dist/bundle/sqlite-runtime-H2S5RR2F.js +20 -0
  110. package/dist/bundle/state-OPOXCDZL.js +36 -0
  111. package/dist/bundle/store-NHMXEJPD.js +164 -0
  112. package/dist/bundle/store-Y3KRLCJ7.js +281 -0
  113. package/dist/bundle/store-maintenance-command-D4W7WSLQ.js +53 -0
  114. package/dist/commands/api.d.ts +4 -0
  115. package/dist/commands/api.d.ts.map +1 -0
  116. package/dist/commands/api.js +140 -0
  117. package/dist/commands/api.js.map +1 -0
  118. package/dist/commands/comments.d.ts +3 -0
  119. package/dist/commands/comments.d.ts.map +1 -0
  120. package/dist/commands/comments.js +114 -0
  121. package/dist/commands/comments.js.map +1 -0
  122. package/dist/commands/databases.d.ts +3 -0
  123. package/dist/commands/databases.d.ts.map +1 -0
  124. package/dist/commands/databases.js +65 -0
  125. package/dist/commands/databases.js.map +1 -0
  126. package/dist/commands/documents.d.ts +3 -0
  127. package/dist/commands/documents.d.ts.map +1 -0
  128. package/dist/commands/documents.js +41 -0
  129. package/dist/commands/documents.js.map +1 -0
  130. package/dist/commands/session.d.ts +3 -0
  131. package/dist/commands/session.d.ts.map +1 -0
  132. package/dist/commands/session.js +104 -0
  133. package/dist/commands/session.js.map +1 -0
  134. package/dist/config.d.ts +5 -0
  135. package/dist/config.d.ts.map +1 -0
  136. package/dist/config.js +13 -0
  137. package/dist/config.js.map +1 -0
  138. package/dist/context.d.ts +46 -0
  139. package/dist/context.d.ts.map +1 -0
  140. package/dist/context.js +58 -0
  141. package/dist/context.js.map +1 -0
  142. package/dist/generated/definitions.d.ts +3 -0
  143. package/dist/generated/definitions.d.ts.map +1 -0
  144. package/dist/generated/definitions.js +45603 -0
  145. package/dist/generated/definitions.js.map +1 -0
  146. package/dist/generated/manifest.d.ts +3 -0
  147. package/dist/generated/manifest.d.ts.map +1 -0
  148. package/dist/generated/manifest.js +2089 -0
  149. package/dist/generated/manifest.js.map +1 -0
  150. package/dist/generated/metadata.d.ts +6 -0
  151. package/dist/generated/metadata.d.ts.map +1 -0
  152. package/dist/generated/metadata.js +24 -0
  153. package/dist/generated/metadata.js.map +1 -0
  154. package/dist/generated/schemas.d.ts +1223 -0
  155. package/dist/generated/schemas.d.ts.map +1 -0
  156. package/dist/generated/schemas.js +11557 -0
  157. package/dist/generated/schemas.js.map +1 -0
  158. package/dist/generated/types.d.ts +11120 -0
  159. package/dist/generated/types.d.ts.map +1 -0
  160. package/dist/generated/types.js +5 -0
  161. package/dist/generated/types.js.map +1 -0
  162. package/dist/identity.d.ts +7 -0
  163. package/dist/identity.d.ts.map +1 -0
  164. package/dist/identity.js +29 -0
  165. package/dist/identity.js.map +1 -0
  166. package/dist/index.d.ts +3 -0
  167. package/dist/index.d.ts.map +1 -0
  168. package/dist/index.js +3 -0
  169. package/dist/index.js.map +1 -0
  170. package/dist/notion/client.d.ts +42 -0
  171. package/dist/notion/client.d.ts.map +1 -0
  172. package/dist/notion/client.js +118 -0
  173. package/dist/notion/client.js.map +1 -0
  174. package/dist/notion/errors.d.ts +24 -0
  175. package/dist/notion/errors.d.ts.map +1 -0
  176. package/dist/notion/errors.js +102 -0
  177. package/dist/notion/errors.js.map +1 -0
  178. package/dist/notion/ids.d.ts +7 -0
  179. package/dist/notion/ids.d.ts.map +1 -0
  180. package/dist/notion/ids.js +37 -0
  181. package/dist/notion/ids.js.map +1 -0
  182. package/dist/notion/links.d.ts +6 -0
  183. package/dist/notion/links.d.ts.map +1 -0
  184. package/dist/notion/links.js +22 -0
  185. package/dist/notion/links.js.map +1 -0
  186. package/dist/notion/notion.d.ts +95 -0
  187. package/dist/notion/notion.d.ts.map +1 -0
  188. package/dist/notion/notion.js +269 -0
  189. package/dist/notion/notion.js.map +1 -0
  190. package/dist/notion/port.d.ts +13 -0
  191. package/dist/notion/port.d.ts.map +1 -0
  192. package/dist/notion/port.js +60 -0
  193. package/dist/notion/port.js.map +1 -0
  194. package/dist/notion/read-posts.d.ts +36 -0
  195. package/dist/notion/read-posts.d.ts.map +1 -0
  196. package/dist/notion/read-posts.js +24 -0
  197. package/dist/notion/read-posts.js.map +1 -0
  198. package/dist/notion/reads.d.ts +327 -0
  199. package/dist/notion/reads.d.ts.map +1 -0
  200. package/dist/notion/reads.js +18 -0
  201. package/dist/notion/reads.js.map +1 -0
  202. package/dist/program.d.ts +6 -0
  203. package/dist/program.d.ts.map +1 -0
  204. package/dist/program.js +62 -0
  205. package/dist/program.js.map +1 -0
  206. package/dist/sample/comments.d.ts +61 -0
  207. package/dist/sample/comments.d.ts.map +1 -0
  208. package/dist/sample/comments.js +39 -0
  209. package/dist/sample/comments.js.map +1 -0
  210. package/dist/sample/records.d.ts +16 -0
  211. package/dist/sample/records.d.ts.map +1 -0
  212. package/dist/sample/records.js +22 -0
  213. package/dist/sample/records.js.map +1 -0
  214. package/dist/sample/transport.d.ts +42 -0
  215. package/dist/sample/transport.d.ts.map +1 -0
  216. package/dist/sample/transport.js +153 -0
  217. package/dist/sample/transport.js.map +1 -0
  218. package/dist/sync/cursor.d.ts +54 -0
  219. package/dist/sync/cursor.d.ts.map +1 -0
  220. package/dist/sync/cursor.js +52 -0
  221. package/dist/sync/cursor.js.map +1 -0
  222. package/dist/sync/front-matter.d.ts +10 -0
  223. package/dist/sync/front-matter.d.ts.map +1 -0
  224. package/dist/sync/front-matter.js +114 -0
  225. package/dist/sync/front-matter.js.map +1 -0
  226. package/dist/sync/markdown.d.ts +8 -0
  227. package/dist/sync/markdown.d.ts.map +1 -0
  228. package/dist/sync/markdown.js +40 -0
  229. package/dist/sync/markdown.js.map +1 -0
  230. package/dist/sync/source.d.ts +64 -0
  231. package/dist/sync/source.d.ts.map +1 -0
  232. package/dist/sync/source.js +634 -0
  233. package/dist/sync/source.js.map +1 -0
  234. package/dist/version.d.ts +2 -0
  235. package/dist/version.d.ts.map +1 -0
  236. package/dist/version.js +2 -0
  237. package/dist/version.js.map +1 -0
  238. package/dist/wcat.d.ts +3 -0
  239. package/dist/wcat.d.ts.map +1 -0
  240. package/dist/wcat.js +4 -0
  241. package/dist/wcat.js.map +1 -0
  242. package/package.json +85 -4
  243. package/skills/notion-cli/SKILL.md +34 -0
@@ -0,0 +1,238 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ SAMPLE_RATE,
5
+ toModelRate
6
+ } from "./chunk-B2XKEEFX.js";
7
+ import "./chunk-JK44XO2S.js";
8
+ import {
9
+ OPENAI_URL,
10
+ refuseModelAddress
11
+ } from "./chunk-CWVAYQXI.js";
12
+ import {
13
+ endpointFetch
14
+ } from "./chunk-2YR3RYT4.js";
15
+ import "./chunk-WK3OSDNV.js";
16
+ import "./chunk-FF4DDBCB.js";
17
+ import {
18
+ OPENAI_TRANSCRIBE_MODEL,
19
+ VAD,
20
+ filesPresent,
21
+ modelsDirectory,
22
+ vadPath
23
+ } from "./chunk-WVZFXI36.js";
24
+ import {
25
+ providerWaitMs
26
+ } from "./chunk-QC3KOJT4.js";
27
+ import "./chunk-HWRKURQH.js";
28
+ import {
29
+ DEFAULT_RETRY,
30
+ backoffMs
31
+ } from "./chunk-RSIS7BR7.js";
32
+ import "./chunk-WM7663C2.js";
33
+ import "./chunk-XYIT2XB3.js";
34
+ import "./chunk-Y5E2WNWB.js";
35
+ import {
36
+ CliError
37
+ } from "./chunk-F6MLJ3V5.js";
38
+ import {
39
+ __name
40
+ } from "./chunk-ZVVMGPBJ.js";
41
+
42
+ // node_modules/.pnpm/@wirecat+cli-core@0.663.0_@wirecat+cli-base@0.101.0_commander@15.0.0_esbuild@0.28.2_typ_8be6aa3a41727a76ce87cf0d5a7bd659/node_modules/@wirecat/cli-core/dist/speech/openai.js
43
+ import { setTimeout as wait } from "node:timers/promises";
44
+
45
+ // node_modules/.pnpm/@wirecat+cli-core@0.663.0_@wirecat+cli-base@0.101.0_commander@15.0.0_esbuild@0.28.2_typ_8be6aa3a41727a76ce87cf0d5a7bd659/node_modules/@wirecat/cli-core/dist/speech/wav.js
46
+ var encodeWav = /* @__PURE__ */ __name((samples, sampleRate = 16e3) => {
47
+ const bytes = Buffer.alloc(44 + samples.length * 2);
48
+ bytes.write("RIFF", 0, "ascii");
49
+ bytes.writeUInt32LE(bytes.length - 8, 4);
50
+ bytes.write("WAVEfmt ", 8, "ascii");
51
+ bytes.writeUInt32LE(16, 16);
52
+ bytes.writeUInt16LE(1, 20);
53
+ bytes.writeUInt16LE(1, 22);
54
+ bytes.writeUInt32LE(sampleRate, 24);
55
+ bytes.writeUInt32LE(sampleRate * 2, 28);
56
+ bytes.writeUInt16LE(2, 32);
57
+ bytes.writeUInt16LE(16, 34);
58
+ bytes.write("data", 36, "ascii");
59
+ bytes.writeUInt32LE(samples.length * 2, 40);
60
+ samples.forEach((sample, index) => {
61
+ bytes.writeInt16LE(Math.round(Math.max(-1, Math.min(1, sample || 0)) * 32767), 44 + index * 2);
62
+ });
63
+ return new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.length);
64
+ }, "encodeWav");
65
+
66
+ // node_modules/.pnpm/@wirecat+cli-core@0.663.0_@wirecat+cli-base@0.101.0_commander@15.0.0_esbuild@0.28.2_typ_8be6aa3a41727a76ce87cf0d5a7bd659/node_modules/@wirecat/cli-core/dist/speech/openai.js
67
+ var LONGEST_REQUEST_SECONDS = 600;
68
+ var JOINED_SECONDS = 0.2;
69
+ var PAD_SECONDS = 0.2;
70
+ var LEAD = SAMPLE_RATE / 2;
71
+ var EXHAUSTED = /* @__PURE__ */ new Set([
72
+ "insufficient_quota",
73
+ "credit_balance_exhausted",
74
+ "organization_spend_limit_exceeded",
75
+ "project_spend_limit_exceeded",
76
+ "organization_usage_limit_exceeded"
77
+ ]);
78
+ var RETRY = { ...DEFAULT_RETRY, retries: 4 };
79
+ var interrupted = /* @__PURE__ */ __name((signal) => {
80
+ if (!signal?.aborted)
81
+ return;
82
+ if (signal.reason instanceof CliError)
83
+ throw signal.reason;
84
+ const timeout = signal.reason instanceof Error && signal.reason.name === "TimeoutError";
85
+ throw new CliError(timeout ? "timeout" : "cancelled", "the transcription was interrupted");
86
+ }, "interrupted");
87
+ var sleeping = /* @__PURE__ */ __name((ms, signal) => wait(ms, void 0, signal ? { signal } : {}).then(() => void 0, (error) => {
88
+ interrupted(signal);
89
+ throw error;
90
+ }), "sleeping");
91
+ var formOf = /* @__PURE__ */ __name((wav, options) => {
92
+ const form = new FormData();
93
+ form.append("file", new Blob([wav], { type: "audio/wav" }), "audio.wav");
94
+ form.append("model", options.model ?? OPENAI_TRANSCRIBE_MODEL);
95
+ for (const language of options.languages ?? [])
96
+ form.append("languages[]", language);
97
+ for (const keyword of options.keywords ?? [])
98
+ form.append("keywords[]", keyword);
99
+ if (options.prompt)
100
+ form.append("prompt", options.prompt);
101
+ return form;
102
+ }, "formOf");
103
+ var safe = /* @__PURE__ */ __name((value) => typeof value === "string" && /^[\w.-]{1,64}$/.test(value) ? value : void 0, "safe");
104
+ var failureOf = /* @__PURE__ */ __name(async (response) => {
105
+ try {
106
+ const body = await response.json();
107
+ const code = safe(body.error?.code);
108
+ const type = safe(body.error?.type);
109
+ return { ...code ? { code } : {}, ...type ? { type } : {} };
110
+ } catch {
111
+ return {};
112
+ }
113
+ }, "failureOf");
114
+ var TRANSCRIPTION_TIMEOUT_MS = 6e5;
115
+ var send = /* @__PURE__ */ __name(async (wav, options) => {
116
+ const url = `${(options.baseUrl ?? OPENAI_URL).replace(/\/+$/, "")}/audio/transcriptions`;
117
+ const post = options.fetch ?? endpointFetch(url, TRANSCRIPTION_TIMEOUT_MS);
118
+ const retry = options.retry ?? RETRY;
119
+ const sleep = options.sleep ?? sleeping;
120
+ const random = options.random ?? Math.random;
121
+ for (let attempt = 1; ; attempt++) {
122
+ interrupted(options.signal);
123
+ let response;
124
+ try {
125
+ response = await post(url, {
126
+ method: "POST",
127
+ headers: { authorization: `Bearer ${options.apiKey}` },
128
+ body: formOf(wav, options),
129
+ ...options.signal ? { signal: options.signal } : {}
130
+ });
131
+ } catch {
132
+ interrupted(options.signal);
133
+ if (attempt > retry.retries)
134
+ throw new CliError("network_error", "OpenAI could not be reached", { reason: "network.failed" });
135
+ await sleep(backoffMs(attempt, retry, random), options.signal);
136
+ continue;
137
+ }
138
+ if (response.ok) {
139
+ const body = await response.json().catch(() => interrupted(options.signal));
140
+ if (typeof body?.text !== "string")
141
+ throw new CliError("invalid_response", "OpenAI answered without a transcript", {
142
+ reason: "provider.invalid-response"
143
+ });
144
+ return body.text.trim();
145
+ }
146
+ const { code, type } = await failureOf(response);
147
+ const status = response.status;
148
+ const said = `HTTP ${status}${code ? `, ${code}` : type ? `, ${type}` : ""}`;
149
+ if (status === 401)
150
+ throw new CliError("authentication_error", `OpenAI refused the key (${said}) \u2014 set it again with \`models keys set openai\``, { reason: "auth.failed" });
151
+ if (status === 403)
152
+ throw new CliError("permission_error", `OpenAI refused the request (${said}) \u2014 it answers this when the country or region is not supported, or the key's project may not use the model`, { reason: "access.denied" });
153
+ if (status === 413)
154
+ throw new CliError("validation_error", `OpenAI refused the audio as too large (${said})`, {
155
+ reason: "transcription.too-large"
156
+ });
157
+ if (EXHAUSTED.has(code ?? "") || EXHAUSTED.has(type ?? ""))
158
+ throw new CliError("permission_error", `OpenAI refused: the account's credit, spend limit or usage limit is used up (${said}) \u2014 see the billing page`, { reason: "transcription.quota-exhausted" });
159
+ const again = status === 408 || status === 429 || status >= 500;
160
+ const asked = providerWaitMs(response.headers, () => /* @__PURE__ */ new Date());
161
+ if (again && attempt <= retry.retries && (asked === void 0 || asked <= retry.maxRetryAfterMs)) {
162
+ await sleep(asked ?? backoffMs(attempt, retry, random), options.signal);
163
+ continue;
164
+ }
165
+ if (status === 429)
166
+ throw new CliError("rate_limited", `OpenAI answered ${said}`, {
167
+ reason: "provider.rate-limited",
168
+ ...asked === void 0 ? {} : { retry_after_ms: asked }
169
+ });
170
+ if (status >= 500)
171
+ throw new CliError([502, 503, 504].includes(status) ? "provider_unavailable" : "provider_error", `OpenAI answered ${said}`, { reason: [502, 503, 504].includes(status) ? "provider.unavailable" : "provider.refused" });
172
+ throw new CliError("provider_error", `OpenAI answered ${said}`, { reason: "provider.refused" });
173
+ }
174
+ }, "send");
175
+ var piecesOf = /* @__PURE__ */ __name((spans, limit) => {
176
+ const pieces = [];
177
+ for (const span of spans) {
178
+ const last = pieces.at(-1);
179
+ const joined = last !== void 0 && span.start - last.end < JOINED_SECONDS;
180
+ const fits = last !== void 0 && limit !== void 0 && span.end - last.start <= limit;
181
+ if (last && (fits || joined && span.end - last.start <= LONGEST_REQUEST_SECONDS))
182
+ last.end = span.end;
183
+ else
184
+ pieces.push({ start: span.start, end: span.end });
185
+ }
186
+ return pieces;
187
+ }, "piecesOf");
188
+ var openCutter = /* @__PURE__ */ __name(async (vadModel) => {
189
+ const { openSpeechCutter } = await import("./recognize-NYCHQMCX.js");
190
+ return openSpeechCutter(vadModel);
191
+ }, "openCutter");
192
+ var checkKeywords = /* @__PURE__ */ __name((keywords = []) => {
193
+ const bad = keywords.find((keyword) => typeof keyword !== "string" || !keyword.trim() || /[<>\r\n]/.test(keyword));
194
+ if (bad !== void 0)
195
+ throw new CliError("validation_error", "a keyword must be a non-empty single line without < or > \u2014 OpenAI refuses the whole request otherwise");
196
+ }, "checkKeywords");
197
+ var transcribeOpenAI = /* @__PURE__ */ __name(async (audio, options) => {
198
+ refuseModelAddress(options.env ?? process.env, options.baseUrl ?? OPENAI_URL, "audio");
199
+ if (!options.apiKey)
200
+ throw new CliError("authentication_error", "no OpenAI key \u2014 `models keys set openai`, or OPENAI_API_KEY", {
201
+ reason: "transcription.no-key"
202
+ });
203
+ checkKeywords(options.keywords);
204
+ interrupted(options.signal);
205
+ const pcm = toModelRate(audio.samples, audio.rate);
206
+ const duration = (pcm.length - LEAD) / SAMPLE_RATE;
207
+ if (options.bundle && duration <= LONGEST_REQUEST_SECONDS) {
208
+ const text = await send(encodeWav(pcm.subarray(LEAD)), options);
209
+ return text ? [{ start: 0, end: duration, text }] : [];
210
+ }
211
+ const vadModel = options.vadModel ?? vadPath(modelsDirectory(options.env));
212
+ if (!options.cutter && !filesPresent([[VAD, vadModel]]))
213
+ throw new CliError("not_found", "the voice detector that finds the speech is not on this machine \u2014 it comes with any speech model: `models download`", { reason: "model.not-downloaded", model: "silero_vad" });
214
+ const cutter = await (options.cutter ?? openCutter)(vadModel);
215
+ let spans;
216
+ try {
217
+ spans = cutter.cut(pcm);
218
+ } finally {
219
+ cutter.free();
220
+ }
221
+ const pieces = piecesOf(spans, options.bundle ? LONGEST_REQUEST_SECONDS : void 0);
222
+ const heard = [];
223
+ for (const [index, piece] of pieces.entries()) {
224
+ const end = Math.min(piece.end, duration);
225
+ const from = Math.max(piece.start - PAD_SECONDS, pieces[index - 1]?.end ?? 0);
226
+ const to = Math.min(end + PAD_SECONDS, pieces[index + 1]?.start ?? duration);
227
+ const samples = pcm.subarray(LEAD + Math.floor(from * SAMPLE_RATE), LEAD + Math.ceil(to * SAMPLE_RATE));
228
+ const text = await send(encodeWav(samples), options);
229
+ if (text)
230
+ heard.push({ start: Math.min(piece.start, end), end, text });
231
+ }
232
+ return heard;
233
+ }, "transcribeOpenAI");
234
+ export {
235
+ LONGEST_REQUEST_SECONDS,
236
+ piecesOf,
237
+ transcribeOpenAI
238
+ };
@@ -0,0 +1,91 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import "./chunk-Y5E2WNWB.js";
4
+ import {
5
+ __name
6
+ } from "./chunk-ZVVMGPBJ.js";
7
+
8
+ // node_modules/.pnpm/@wirecat+cli-core@0.663.0_@wirecat+cli-base@0.101.0_commander@15.0.0_esbuild@0.28.2_typ_8be6aa3a41727a76ce87cf0d5a7bd659/node_modules/@wirecat/cli-core/dist/embeddings/process.js
9
+ import { spawn } from "node:child_process";
10
+ import { createInterface } from "node:readline";
11
+ import { fileURLToPath } from "node:url";
12
+ var openProcess = /* @__PURE__ */ __name(async (model, directory, { threads }) => {
13
+ const child = await modelProcess({ model, directory, threads });
14
+ return {
15
+ model,
16
+ embed: /* @__PURE__ */ __name(async (texts, kind) => ((await child.ask({ texts, kind })).vectors ?? []).map((vector) => Float32Array.from(vector)), "embed"),
17
+ close: child.close
18
+ };
19
+ }, "openProcess");
20
+ var openRerankerProcess = /* @__PURE__ */ __name(async (model, directory, { threads }) => {
21
+ const child = await modelProcess({ model, directory, threads, rerank: true });
22
+ return {
23
+ model,
24
+ score: /* @__PURE__ */ __name(async (question, passages) => (await child.ask({ question, texts: passages })).scores ?? [], "score"),
25
+ close: child.close
26
+ };
27
+ }, "openRerankerProcess");
28
+ var modelProcess = /* @__PURE__ */ __name(async (setup) => {
29
+ const child = spawn(process.execPath, [fileURLToPath(new URL("./child.js", new URL("embeddings/process.js", import.meta.resolve("@wirecat/cli-core")).href)), JSON.stringify(setup)], { stdio: ["pipe", "pipe", "pipe"] });
30
+ const pending = /* @__PURE__ */ new Map();
31
+ let said = "";
32
+ child.stderr.setEncoding("utf8").on("data", (text) => {
33
+ said = (said + text).slice(-2e3);
34
+ });
35
+ let ready = /* @__PURE__ */ __name(() => {
36
+ }, "ready");
37
+ let refused = /* @__PURE__ */ __name((_error) => {
38
+ }, "refused");
39
+ const started = new Promise((resolve, reject) => {
40
+ ready = resolve;
41
+ refused = reject;
42
+ });
43
+ let gone;
44
+ const stopped = /* @__PURE__ */ __name((error) => {
45
+ gone ??= error;
46
+ refused(error);
47
+ for (const job of pending.values())
48
+ job.reject(error);
49
+ pending.clear();
50
+ }, "stopped");
51
+ const exited = new Promise((resolve) => {
52
+ child.once("exit", (code) => {
53
+ const last = said.trim().split("\n").at(-1);
54
+ stopped(new Error(`the embedding process stopped (exit ${code})${last ? `: ${last}` : ""}`));
55
+ resolve();
56
+ });
57
+ });
58
+ child.once("error", stopped);
59
+ createInterface({ input: child.stdout }).on("line", (line) => {
60
+ const answer = JSON.parse(line);
61
+ if ("ready" in answer)
62
+ return ready();
63
+ const job = pending.get(answer.id);
64
+ pending.delete(answer.id);
65
+ if (answer.error !== void 0 || !(answer.vectors ?? answer.scores))
66
+ job?.reject(new Error(answer.error ?? "no answer"));
67
+ else
68
+ job?.resolve(answer);
69
+ });
70
+ await started;
71
+ let next = 0;
72
+ return {
73
+ ask: /* @__PURE__ */ __name((request) => new Promise((resolve, reject) => {
74
+ if (gone)
75
+ return reject(gone);
76
+ const id = next++;
77
+ pending.set(id, { resolve, reject });
78
+ child.stdin.write(`${JSON.stringify({ id, ...request })}
79
+ `);
80
+ }), "ask"),
81
+ close: /* @__PURE__ */ __name(async () => {
82
+ if (child.exitCode === null && child.signalCode === null)
83
+ child.stdin.end();
84
+ await exited;
85
+ }, "close")
86
+ };
87
+ }, "modelProcess");
88
+ export {
89
+ openProcess,
90
+ openRerankerProcess
91
+ };