@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,230 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ importFrom
5
+ } from "./chunk-Y5E2WNWB.js";
6
+ import {
7
+ CliError
8
+ } from "./chunk-F6MLJ3V5.js";
9
+ import {
10
+ __name
11
+ } from "./chunk-ZVVMGPBJ.js";
12
+
13
+ // 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/recognize.js
14
+ import { createRequire } from "node:module";
15
+
16
+ // 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/ogg-limit.js
17
+ var invalid = /* @__PURE__ */ __name(() => new CliError("validation_error", "local transcription needs a complete mono or stereo Ogg Opus recording"), "invalid");
18
+ var checkOggDuration = /* @__PURE__ */ __name((bytes) => {
19
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
20
+ let offset = 0;
21
+ let serial;
22
+ let packet = 0;
23
+ let length = 0;
24
+ const prefix = [];
25
+ while (offset < bytes.length) {
26
+ if (offset + 27 > bytes.length || view.getUint32(offset, false) !== 1332176723 || bytes[offset + 4] !== 0)
27
+ throw invalid();
28
+ const stream = view.getUint32(offset + 14, true);
29
+ if (serial !== void 0 && serial !== stream)
30
+ throw invalid();
31
+ serial = stream;
32
+ const segments = bytes[offset + 26] ?? 0;
33
+ let data = offset + 27 + segments;
34
+ if (data > bytes.length || Boolean((bytes[offset + 5] ?? 0) & 1) !== length > 0)
35
+ throw invalid();
36
+ for (let index = 0; index < segments; index++) {
37
+ const size = bytes[offset + 27 + index] ?? 0;
38
+ if (data + size > bytes.length)
39
+ throw invalid();
40
+ const take = Math.min(size, 19 - prefix.length);
41
+ for (let i = 0; i < take; i++)
42
+ prefix.push(bytes[data + i] ?? 0);
43
+ length += size;
44
+ data += size;
45
+ if (size === 255)
46
+ continue;
47
+ if (packet === 0) {
48
+ if (length < 19 || String.fromCharCode(...prefix.slice(0, 8)) !== "OpusHead" || ![1, 2].includes(prefix[9] ?? 0) || prefix[18] !== 0)
49
+ throw invalid();
50
+ } else if (packet === 1) {
51
+ if (length < 8 || String.fromCharCode(...prefix.slice(0, 8)) !== "OpusTags")
52
+ throw invalid();
53
+ } else {
54
+ if (length < 1)
55
+ throw invalid();
56
+ const toc = prefix[0] ?? 0;
57
+ const config = toc >> 3;
58
+ const frame = config >= 16 ? 120 << (config & 3) : config >= 12 ? 480 << (config & 1) : (config & 3) === 3 ? 2880 : 480 << (config & 3);
59
+ const count = (toc & 3) === 0 ? 1 : (toc & 3) === 3 ? length >= 2 ? (prefix[1] ?? 0) & 63 : 0 : 2;
60
+ if (count < 1 || frame * count > 5760)
61
+ throw invalid();
62
+ }
63
+ packet++;
64
+ length = 0;
65
+ prefix.length = 0;
66
+ }
67
+ offset = data;
68
+ }
69
+ if (length !== 0 || packet < 3)
70
+ throw invalid();
71
+ }, "checkOggDuration");
72
+
73
+ // 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/recognize.js
74
+ var SAMPLE_RATE = 16e3;
75
+ var LEAD = SAMPLE_RATE / 2;
76
+ var toModelRate = /* @__PURE__ */ __name((samples, rate) => {
77
+ const step = rate / SAMPLE_RATE;
78
+ const length = Math.floor(samples.length / step);
79
+ const pcm = new Float32Array(LEAD + length);
80
+ for (let i = 0; i < length; i++) {
81
+ const from = Math.floor(i * step);
82
+ const to = Math.max(from + 1, Math.floor((i + 1) * step));
83
+ let sum = 0;
84
+ for (let j = from; j < to; j++)
85
+ sum += samples[j] ?? 0;
86
+ pcm[LEAD + i] = sum / (to - from);
87
+ }
88
+ return pcm;
89
+ }, "toModelRate");
90
+ var decodeOgg = /* @__PURE__ */ __name(async (bytes) => {
91
+ checkOggDuration(bytes);
92
+ const { OggOpusDecoder } = await importFrom(new URL("speech/recognize.js", import.meta.resolve("@wirecat/cli-core")).href, "ogg-opus-decoder");
93
+ const decoder = new OggOpusDecoder();
94
+ await decoder.ready;
95
+ try {
96
+ const { channelData, sampleRate, samplesDecoded } = await decoder.decodeFile(bytes);
97
+ if (!channelData[0] || samplesDecoded === 0)
98
+ throw new Error("no Ogg Opus audio in it");
99
+ return channelData.map((samples) => ({ samples, rate: sampleRate }));
100
+ } finally {
101
+ decoder.free();
102
+ }
103
+ }, "decodeOgg");
104
+ var WINDOW = 512;
105
+ var detector = /* @__PURE__ */ __name((vadModel) => ({
106
+ sileroVad: {
107
+ model: vadModel,
108
+ // At the default 0.5 a quietly spoken stretch in the middle of a voice message never counted as
109
+ // speech and was lost; 0.3 keeps it for both models and changes nothing on clear speech (126508, 2026-09-30).
110
+ threshold: 0.3,
111
+ minSilenceDuration: 0.5,
112
+ minSpeechDuration: 0.25,
113
+ maxSpeechDuration: 20,
114
+ windowSize: WINDOW
115
+ },
116
+ sampleRate: SAMPLE_RATE,
117
+ numThreads: 1,
118
+ provider: "cpu",
119
+ debug: 0,
120
+ bufferSizeInSeconds: 30
121
+ }), "detector");
122
+ var cut = /* @__PURE__ */ __name((vad, pcm, each) => {
123
+ vad.reset();
124
+ const last = Math.max(0, pcm.length - LEAD);
125
+ const drain = /* @__PURE__ */ __name(() => {
126
+ for (; !vad.isEmpty(); vad.pop()) {
127
+ const { start, samples } = vad.front();
128
+ each({
129
+ start: Math.min(last, Math.max(0, start - LEAD)) / SAMPLE_RATE,
130
+ end: Math.min(last, Math.max(0, start + samples.length - LEAD)) / SAMPLE_RATE,
131
+ samples
132
+ });
133
+ }
134
+ }, "drain");
135
+ for (let i = 0; i + WINDOW <= pcm.length; i += WINDOW) {
136
+ vad.acceptWaveform(pcm.subarray(i, i + WINDOW));
137
+ drain();
138
+ }
139
+ vad.flush();
140
+ drain();
141
+ }, "cut");
142
+ var openSpeechCutter = /* @__PURE__ */ __name((vadModel) => {
143
+ const vad = loadSherpa().createVad(detector(vadModel));
144
+ return {
145
+ cut: /* @__PURE__ */ __name((pcm) => {
146
+ const spans = [];
147
+ cut(vad, pcm, ({ start, end }) => spans.push({ start, end }));
148
+ return spans;
149
+ }, "cut"),
150
+ free: /* @__PURE__ */ __name(() => vad.free(), "free")
151
+ };
152
+ }, "openSpeechCutter");
153
+ var loaded;
154
+ var loadSherpa = /* @__PURE__ */ __name(() => {
155
+ if (loaded)
156
+ return loaded;
157
+ const load = createRequire(new URL("speech/recognize.js", import.meta.resolve("@wirecat/cli-core")).href);
158
+ const wasm = {};
159
+ load("sherpa-onnx/sherpa-onnx-wasm-nodejs.js")(wasm);
160
+ const stdout = wasm.FS?.getStream(1);
161
+ if (stdout)
162
+ stdout.nfd = 2;
163
+ const asr = load("sherpa-onnx/sherpa-onnx-asr.js");
164
+ const vad = load("sherpa-onnx/sherpa-onnx-vad.js");
165
+ loaded = {
166
+ createOfflineRecognizer: /* @__PURE__ */ __name((config) => new asr.OfflineRecognizer(config, wasm), "createOfflineRecognizer"),
167
+ createVad: /* @__PURE__ */ __name((config) => vad.createVad(wasm, config), "createVad")
168
+ };
169
+ return loaded;
170
+ }, "loadSherpa");
171
+ var openRecognizer = /* @__PURE__ */ __name((model, path, vadModel) => {
172
+ const sherpa = loadSherpa();
173
+ const engine = sherpa.createOfflineRecognizer({
174
+ featConfig: { sampleRate: SAMPLE_RATE, featureDim: model.featureDim },
175
+ modelConfig: { ...model.config(path), numThreads: 1, provider: "cpu", debug: 0 },
176
+ decodingMethod: "greedy_search"
177
+ });
178
+ const vad = sherpa.createVad(detector(vadModel));
179
+ const piece = /* @__PURE__ */ __name((samples) => {
180
+ const stream = engine.createStream();
181
+ try {
182
+ stream.acceptWaveform(SAMPLE_RATE, samples);
183
+ engine.decode(stream);
184
+ return engine.getResult(stream).text.trim();
185
+ } finally {
186
+ stream.free();
187
+ }
188
+ }, "piece");
189
+ const pieces = /* @__PURE__ */ __name((pcm) => {
190
+ const heard = [];
191
+ cut(vad, pcm, ({ start, end, samples }) => {
192
+ const text = piece(samples);
193
+ if (text)
194
+ heard.push({ start, end, text });
195
+ });
196
+ return heard;
197
+ }, "pieces");
198
+ const piecesUntil = /* @__PURE__ */ __name(async (pcm, signal) => {
199
+ const spans = [];
200
+ cut(vad, pcm, (span) => spans.push(span));
201
+ const heard = [];
202
+ for (const { start, end, samples } of spans) {
203
+ await new Promise((resolve) => setImmediate(resolve));
204
+ signal.throwIfAborted();
205
+ const text = piece(samples);
206
+ if (text)
207
+ heard.push({ start, end, text });
208
+ }
209
+ return heard;
210
+ }, "piecesUntil");
211
+ return {
212
+ recognize: /* @__PURE__ */ __name((pcm) => pieces(pcm).map(({ text }) => text).join(" "), "recognize"),
213
+ pieces,
214
+ piecesUntil,
215
+ free: /* @__PURE__ */ __name(() => {
216
+ vad.free();
217
+ engine.free();
218
+ }, "free")
219
+ };
220
+ }, "openRecognizer");
221
+
222
+ export {
223
+ SAMPLE_RATE,
224
+ toModelRate,
225
+ decodeOgg,
226
+ detector,
227
+ openSpeechCutter,
228
+ loadSherpa,
229
+ openRecognizer
230
+ };
@@ -0,0 +1,73 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ alive
5
+ } from "./chunk-XC5CKHX2.js";
6
+ import {
7
+ resolvePaths,
8
+ writeSecurely
9
+ } from "./chunk-RSIS7BR7.js";
10
+ import {
11
+ __name
12
+ } from "./chunk-ZVVMGPBJ.js";
13
+
14
+ // 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/background/lock.js
15
+ import { existsSync, linkSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
16
+ import { dirname, join } from "node:path";
17
+ var lockPath = /* @__PURE__ */ __name((app, profile, env) => join(resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).state, "serve", `${profile}.lock`), "lockPath");
18
+ var readLock = /* @__PURE__ */ __name((path) => {
19
+ try {
20
+ const lock = JSON.parse(readFileSync(path, "utf8"));
21
+ return typeof lock.pid === "number" && typeof lock.startedAt === "string" ? lock : void 0;
22
+ } catch {
23
+ return void 0;
24
+ }
25
+ }, "readLock");
26
+ var holdLock = /* @__PURE__ */ __name((path, lock) => writeSecurely(path, `${JSON.stringify(lock)}
27
+ `, 384), "holdLock");
28
+ var takeLock = /* @__PURE__ */ __name((path, lock) => {
29
+ mkdirSync(dirname(path), { recursive: true, mode: 448 });
30
+ const draft = `${path}.${lock.pid}.tmp`;
31
+ writeFileSync(draft, `${JSON.stringify(lock)}
32
+ `, { mode: 384 });
33
+ try {
34
+ for (let attempt = 0; attempt < 5; attempt++) {
35
+ try {
36
+ linkSync(draft, path);
37
+ return void 0;
38
+ } catch (error) {
39
+ if (error.code !== "EEXIST")
40
+ throw error;
41
+ }
42
+ const held = readLock(path);
43
+ if (held && held.pid !== lock.pid && alive(held.pid))
44
+ return held;
45
+ rmSync(path, { force: true });
46
+ }
47
+ throw new Error(`could not take the lock ${path}: it keeps changing`);
48
+ } finally {
49
+ rmSync(draft, { force: true });
50
+ }
51
+ }, "takeLock");
52
+ var releaseLock = /* @__PURE__ */ __name((path, pid = process.pid) => {
53
+ if (readLock(path)?.pid === pid)
54
+ rmSync(path, { force: true });
55
+ }, "releaseLock");
56
+ var servingProfiles = /* @__PURE__ */ __name((app, env) => {
57
+ const dir = dirname(lockPath(app, "default", env));
58
+ if (!existsSync(dir))
59
+ return [];
60
+ return readdirSync(dir).filter((name) => name.endsWith(".lock")).map((name) => name.slice(0, -".lock".length)).filter((profile) => {
61
+ const lock = readLock(lockPath(app, profile, env));
62
+ return lock !== void 0 && alive(lock.pid);
63
+ });
64
+ }, "servingProfiles");
65
+
66
+ export {
67
+ lockPath,
68
+ readLock,
69
+ holdLock,
70
+ takeLock,
71
+ releaseLock,
72
+ servingProfiles
73
+ };
@@ -0,0 +1,288 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ OAuthError,
5
+ OAuthErrorCode
6
+ } from "./chunk-5D4AEUVA.js";
7
+ import {
8
+ ACCESS_SECONDS,
9
+ REFRESH_SECONDS,
10
+ readStored
11
+ } from "./chunk-RLSFOR2D.js";
12
+ import {
13
+ __name
14
+ } from "./chunk-ZVVMGPBJ.js";
15
+
16
+ // 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/mcp/http/oauth.js
17
+ import { createHash, randomBytes, randomInt, timingSafeEqual } from "node:crypto";
18
+ import { chmodSync, mkdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
19
+ import { dirname } from "node:path";
20
+ var AUTH_CODE_MS = 60 * 1e3;
21
+ var LOGIN_CODE_MS = 10 * 60 * 1e3;
22
+ var WRONG_TRIES = 5;
23
+ var WRONG_CODE_WAIT_MS = 3e4;
24
+ var MAX_CLIENTS = 10;
25
+ var CODE_ALPHABET = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
26
+ var hash = /* @__PURE__ */ __name((value) => createHash("sha256").update(value).digest("base64url"), "hash");
27
+ var secret = /* @__PURE__ */ __name(() => randomBytes(32).toString("base64url"), "secret");
28
+ var same = /* @__PURE__ */ __name((given, expected) => {
29
+ const left = Buffer.from(given);
30
+ const right = Buffer.from(expected);
31
+ return left.byteLength === right.byteLength && timingSafeEqual(left, right);
32
+ }, "same");
33
+ var tokenFile = /* @__PURE__ */ __name((path) => ({
34
+ read: /* @__PURE__ */ __name(() => readStored(path), "read"),
35
+ write: /* @__PURE__ */ __name((stored) => {
36
+ mkdirSync(dirname(path), { recursive: true, mode: 448 });
37
+ const temporary = `${path}.${randomBytes(16).toString("hex")}.tmp`;
38
+ writeFileSync(temporary, JSON.stringify(stored), { mode: 384, flag: "wx" });
39
+ chmodSync(temporary, 384);
40
+ renameSync(temporary, path);
41
+ }, "write")
42
+ }), "tokenFile");
43
+ var revokeAll = /* @__PURE__ */ __name((path) => rmSync(path, { force: true }), "revokeAll");
44
+ var json = /* @__PURE__ */ __name((body, status = 200) => new Response(JSON.stringify(body), {
45
+ status,
46
+ headers: { "content-type": "application/json", "cache-control": "no-store" }
47
+ }), "json");
48
+ var oauthError = /* @__PURE__ */ __name((error, description, status = 400) => json({ error, error_description: description }, status), "oauthError");
49
+ var escapeHtml = /* @__PURE__ */ __name((value) => value.replace(/[&<>"']/g, (character) => `&#${character.charCodeAt(0)};`), "escapeHtml");
50
+ var redirectAllowed = /* @__PURE__ */ __name((uri) => {
51
+ try {
52
+ const url = new URL(uri);
53
+ if (url.hash)
54
+ return false;
55
+ return url.protocol === "https:" || url.protocol === "http:" && ["localhost", "127.0.0.1"].includes(url.hostname);
56
+ } catch {
57
+ return false;
58
+ }
59
+ }, "redirectAllowed");
60
+ var ownerLogin = /* @__PURE__ */ __name(({ issuer, resource, file, appName, reaches = `your ${appName} data`, onCode, now = /* @__PURE__ */ __name(() => Date.now(), "now") }) => {
61
+ const store = tokenFile(file);
62
+ const codes = /* @__PURE__ */ new Map();
63
+ let login = { value: "", expires: 0 };
64
+ let wrong = 0;
65
+ let retryAt = 0;
66
+ let renewal;
67
+ const freshCode = /* @__PURE__ */ __name(() => {
68
+ const part = /* @__PURE__ */ __name(() => Array.from({ length: 4 }, () => CODE_ALPHABET[randomInt(CODE_ALPHABET.length)]).join(""), "part");
69
+ login = { value: `${part()}-${part()}`, expires: now() + LOGIN_CODE_MS };
70
+ clearTimeout(renewal);
71
+ renewal = setTimeout(freshCode, LOGIN_CODE_MS);
72
+ renewal.unref();
73
+ onCode(login.value, new Date(login.expires));
74
+ }, "freshCode");
75
+ freshCode();
76
+ const base = issuer.pathname.replace(/\/+$/, "");
77
+ const endpoint = /* @__PURE__ */ __name((path) => new URL(`${base}${path}`, issuer.origin).href, "endpoint");
78
+ const metadata = {
79
+ issuer: issuer.href,
80
+ authorization_endpoint: endpoint("/authorize"),
81
+ token_endpoint: endpoint("/token"),
82
+ registration_endpoint: endpoint("/register"),
83
+ response_types_supported: ["code"],
84
+ grant_types_supported: ["authorization_code", "refresh_token"],
85
+ code_challenge_methods_supported: ["S256"],
86
+ token_endpoint_auth_methods_supported: ["none", "client_secret_post", "client_secret_basic"]
87
+ };
88
+ const issue = /* @__PURE__ */ __name((stored, clientId) => {
89
+ const access = secret();
90
+ const refresh = secret();
91
+ const seconds = Math.floor(now() / 1e3);
92
+ stored.tokens = stored.tokens.filter((one) => one.expiresAt > seconds);
93
+ stored.tokens.push({ hash: hash(access), kind: "access", clientId, expiresAt: seconds + ACCESS_SECONDS }, { hash: hash(refresh), kind: "refresh", clientId, expiresAt: seconds + REFRESH_SECONDS });
94
+ store.write(stored);
95
+ return json({ access_token: access, token_type: "Bearer", expires_in: ACCESS_SECONDS, refresh_token: refresh });
96
+ }, "issue");
97
+ const clientOf = /* @__PURE__ */ __name((stored, request, form) => {
98
+ let id = form.get("client_id") ?? "";
99
+ let given = form.get("client_secret") ?? void 0;
100
+ const basic = request.headers.get("authorization");
101
+ if (basic?.startsWith("Basic ")) {
102
+ const [user = "", password = ""] = Buffer.from(basic.slice(6), "base64").toString().split(":");
103
+ id = decodeURIComponent(user);
104
+ given = decodeURIComponent(password);
105
+ }
106
+ const client = stored.clients.find((one) => one.id === id);
107
+ if (!client)
108
+ return void 0;
109
+ if (client.authMethod === "none")
110
+ return client;
111
+ return given !== void 0 && client.secretHash && same(hash(given), client.secretHash) ? client : void 0;
112
+ }, "clientOf");
113
+ const register = /* @__PURE__ */ __name(async (request) => {
114
+ const body = await request.json().catch(() => null);
115
+ const uris = Array.isArray(body?.redirect_uris) ? body.redirect_uris.filter((one) => typeof one === "string") : [];
116
+ if (uris.length === 0 || !uris.every(redirectAllowed))
117
+ return oauthError("invalid_redirect_uri", "redirect_uris must be https URLs");
118
+ const requested = body?.token_endpoint_auth_method;
119
+ const authMethod = requested === "client_secret_post" || requested === "client_secret_basic" ? requested : "none";
120
+ const clientSecret = authMethod === "none" ? void 0 : secret();
121
+ const name = typeof body?.client_name === "string" ? body.client_name.slice(0, 100) : void 0;
122
+ const client = {
123
+ id: secret(),
124
+ redirectUris: uris,
125
+ authMethod,
126
+ issuedAt: Math.floor(now() / 1e3),
127
+ ...name ? { name } : {},
128
+ ...clientSecret ? { secretHash: hash(clientSecret) } : {}
129
+ };
130
+ const stored = store.read();
131
+ const seconds = Math.floor(now() / 1e3);
132
+ const holding = new Set(stored.tokens.filter((one) => one.expiresAt > seconds).map((one) => one.clientId));
133
+ stored.clients.push(client);
134
+ while (stored.clients.length > MAX_CLIENTS) {
135
+ const idle = stored.clients.findIndex((one) => !holding.has(one.id));
136
+ if (idle === -1)
137
+ return oauthError("invalid_client_metadata", "too many logged-in apps \u2014 run mcp revoke first");
138
+ stored.clients.splice(idle, 1);
139
+ }
140
+ store.write(stored);
141
+ return json({
142
+ client_id: client.id,
143
+ client_id_issued_at: client.issuedAt,
144
+ redirect_uris: uris,
145
+ token_endpoint_auth_method: authMethod,
146
+ grant_types: ["authorization_code", "refresh_token"],
147
+ response_types: ["code"],
148
+ ...name ? { client_name: name } : {},
149
+ ...clientSecret ? { client_secret: clientSecret, client_secret_expires_at: 0 } : {}
150
+ }, 201);
151
+ }, "register");
152
+ const page = /* @__PURE__ */ __name((params, client, message) => {
153
+ const hidden = ["response_type", "client_id", "redirect_uri", "code_challenge", "code_challenge_method", "state"].map((name) => `<input type="hidden" name="${name}" value="${escapeHtml(params.get(name) ?? "")}">`).join("");
154
+ const who = escapeHtml(client.name ?? "an application");
155
+ const target = new URL(params.get("redirect_uri") ?? "");
156
+ const html = `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>${escapeHtml(appName)} login</title><style>body{font:16px system-ui,sans-serif;max-width:28rem;margin:3rem auto;padding:0 1rem;color:#1d2430}input[type=text]{font:20px ui-monospace,monospace;letter-spacing:.1em;width:100%;padding:.5rem;margin:.5rem 0 1rem;box-sizing:border-box}button{font:inherit;padding:.5rem 1rem}.error{color:#b42318}</style></head><body><h1>${escapeHtml(appName)}</h1><p>An app that calls itself <strong>${who}</strong> asks to reach ${escapeHtml(reaches)} through <code>${escapeHtml(appName)} mcp serve --http</code>.</p><p>After you allow it, the login goes to <strong>${escapeHtml(target.host)}</strong>. Allow only if that is the app you are connecting, such as chatgpt.com or claude.ai.</p><p>Type the code shown in WireCat Desktop, or in the terminal where the server runs. If you did not start this login, close this page.</p>${message ? `<p class="error">${escapeHtml(message)}</p>` : ""}<form method="post" action="${escapeHtml(`${base}/authorize`)}">${hidden}<label>Login code<input type="text" name="login_code" autocomplete="off" autofocus required></label><button type="submit">Allow</button></form></body></html>`;
157
+ return new Response(html, {
158
+ status: message ? 400 : 200,
159
+ headers: {
160
+ "content-type": "text/html; charset=utf-8",
161
+ "cache-control": "no-store",
162
+ "x-frame-options": "DENY",
163
+ "content-security-policy": `default-src 'none'; style-src 'unsafe-inline'; form-action 'self' ${target.origin}; frame-ancestors 'none'`,
164
+ // no-referrer makes the browser post this form with `Origin: null`, which the Origin check refuses.
165
+ "referrer-policy": "same-origin"
166
+ }
167
+ });
168
+ }, "page");
169
+ const authorize = /* @__PURE__ */ __name(async (request) => {
170
+ const params = request.method === "POST" ? new URLSearchParams(await request.text()) : new URL(request.url).searchParams;
171
+ const stored = store.read();
172
+ const client = stored.clients.find((one) => one.id === params.get("client_id"));
173
+ const redirectUri = params.get("redirect_uri") ?? "";
174
+ if (!client?.redirectUris.includes(redirectUri))
175
+ return new Response("Unknown client or redirect address.", { status: 400 });
176
+ if (params.get("response_type") !== "code" || params.get("code_challenge_method") !== "S256" || !params.get("code_challenge"))
177
+ return new Response("This server needs response_type=code and PKCE with S256.", { status: 400 });
178
+ if (request.method !== "POST")
179
+ return page(params, client);
180
+ const throttled = /* @__PURE__ */ __name(() => new Response("Too many wrong codes. Wait, then try the new code.", {
181
+ status: 429,
182
+ headers: { "retry-after": String(Math.ceil((retryAt - now()) / 1e3)) }
183
+ }), "throttled");
184
+ if (wrong >= WRONG_TRIES) {
185
+ if (now() < retryAt)
186
+ return throttled();
187
+ wrong = 0;
188
+ freshCode();
189
+ }
190
+ const typed = (params.get("login_code") ?? "").trim().toUpperCase();
191
+ if (login.expires < now()) {
192
+ freshCode();
193
+ return page(params, client, "The code expired. A new one is shown in WireCat Desktop and in the terminal.");
194
+ }
195
+ if (!same(typed, login.value)) {
196
+ wrong += 1;
197
+ if (wrong >= WRONG_TRIES) {
198
+ retryAt = now() + WRONG_CODE_WAIT_MS;
199
+ return throttled();
200
+ }
201
+ return page(params, client, `Wrong code. Each code works for one login: after an app logs in, a new one appears in WireCat Desktop and in "${appName} mcp server status". ${WRONG_TRIES - wrong} tries left.`);
202
+ }
203
+ wrong = 0;
204
+ freshCode();
205
+ const code = secret();
206
+ codes.set(hash(code), {
207
+ clientId: client.id,
208
+ redirectUri,
209
+ challenge: params.get("code_challenge") ?? "",
210
+ expires: now() + AUTH_CODE_MS
211
+ });
212
+ const target = new URL(redirectUri);
213
+ target.searchParams.set("code", code);
214
+ const state = params.get("state");
215
+ if (state)
216
+ target.searchParams.set("state", state);
217
+ target.searchParams.set("iss", issuer.href);
218
+ return new Response(null, { status: 302, headers: { location: target.href, "cache-control": "no-store" } });
219
+ }, "authorize");
220
+ const token = /* @__PURE__ */ __name(async (request) => {
221
+ const form = new URLSearchParams(await request.text());
222
+ const stored = store.read();
223
+ const client = clientOf(stored, request, form);
224
+ if (!client)
225
+ return oauthError("invalid_client", "unknown client or wrong secret", 401);
226
+ const requestedResource = form.get("resource");
227
+ if (requestedResource && requestedResource !== resource.href)
228
+ return oauthError("invalid_target", "this server issues tokens only for its own MCP endpoint");
229
+ if (form.get("grant_type") === "authorization_code") {
230
+ const key = hash(form.get("code") ?? "");
231
+ const entry = codes.get(key);
232
+ codes.delete(key);
233
+ const verifier2 = form.get("code_verifier") ?? "";
234
+ const challenge = createHash("sha256").update(verifier2).digest("base64url");
235
+ if (!entry || entry.expires < now() || entry.clientId !== client.id || entry.redirectUri !== form.get("redirect_uri") || !same(challenge, entry.challenge))
236
+ return oauthError("invalid_grant", "the code is wrong, used or expired");
237
+ return issue(stored, client.id);
238
+ }
239
+ if (form.get("grant_type") === "refresh_token") {
240
+ const key = hash(form.get("refresh_token") ?? "");
241
+ const seconds = Math.floor(now() / 1e3);
242
+ const found = stored.tokens.find((one) => one.kind === "refresh" && one.hash === key);
243
+ if (!found || found.clientId !== client.id || found.expiresAt <= seconds)
244
+ return oauthError("invalid_grant", "the refresh token is wrong, used or expired");
245
+ stored.tokens = stored.tokens.filter((one) => one !== found);
246
+ return issue(stored, client.id);
247
+ }
248
+ return oauthError("unsupported_grant_type", "use authorization_code or refresh_token");
249
+ }, "token");
250
+ const verifier = {
251
+ verifyAccessToken: /* @__PURE__ */ __name(async (presented) => {
252
+ const seconds = Math.floor(now() / 1e3);
253
+ const stored = store.read();
254
+ const found = stored.tokens.find((one) => one.kind === "access" && one.hash === hash(presented));
255
+ if (!found || found.expiresAt <= seconds)
256
+ throw new OAuthError(OAuthErrorCode.InvalidToken, "the token is unknown or expired");
257
+ const clientName = stored.clients.find((one) => one.id === found.clientId)?.name;
258
+ return {
259
+ token: presented,
260
+ clientId: found.clientId,
261
+ scopes: [],
262
+ expiresAt: found.expiresAt,
263
+ resource,
264
+ ...clientName ? { extra: { clientName } } : {}
265
+ };
266
+ }, "verifyAccessToken")
267
+ };
268
+ return {
269
+ code: /* @__PURE__ */ __name(() => login.value, "code"),
270
+ close: /* @__PURE__ */ __name(() => clearTimeout(renewal), "close"),
271
+ metadata,
272
+ verifier,
273
+ handle: /* @__PURE__ */ __name(async (request, path = new URL(request.url).pathname) => {
274
+ if (path === `${base}/register` && request.method === "POST")
275
+ return register(request);
276
+ if (path === `${base}/authorize` && (request.method === "GET" || request.method === "POST"))
277
+ return authorize(request);
278
+ if (path === `${base}/token` && request.method === "POST")
279
+ return token(request);
280
+ return void 0;
281
+ }, "handle")
282
+ };
283
+ }, "ownerLogin");
284
+
285
+ export {
286
+ revokeAll,
287
+ ownerLogin
288
+ };