@wirecat/notion-cli 0.1.0 → 0.3.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 (212) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/README.md +14 -4
  3. package/contracts/wirecat.json +698 -1
  4. package/dist/bin/notion.js +2 -2
  5. package/dist/bundle/{all-profiles-OETMCOLN.js → all-profiles-4IONYZB6.js} +10 -10
  6. package/dist/bundle/{anthropic-5Y3O2TYM.js → anthropic-OXF74J4P.js} +6 -6
  7. package/dist/bundle/{app-server-IVWBIVHC.js → app-server-M2VF6ABM.js} +61 -52
  8. package/dist/bundle/{bun-EO636SAD.js → bun-DLA6QRLL.js} +2 -2
  9. package/dist/bundle/{bun-sqlite-C2T7QJ2M.js → bun-sqlite-F4BYLW3F.js} +7 -7
  10. package/dist/bundle/{chunk-QBC23NHD.js → chunk-2MHMKNWD.js} +1 -1
  11. package/dist/bundle/{chunk-TSCIIXN3.js → chunk-4KUJTSHG.js} +2 -2
  12. package/dist/bundle/{chunk-24FAYAML.js → chunk-4TQVZXOV.js} +3 -3
  13. package/dist/bundle/{chunk-FF4DDBCB.js → chunk-5LBJNTEJ.js} +6 -6
  14. package/dist/bundle/chunk-5UA2TYMI.js +29 -0
  15. package/dist/bundle/{chunk-DIM5YWBU.js → chunk-5XP4KQ2F.js} +1 -1
  16. package/dist/bundle/{chunk-WM7663C2.js → chunk-6GN7KU7X.js} +9 -9
  17. package/dist/bundle/chunk-6JBLIQQN.js +16 -0
  18. package/dist/bundle/{chunk-CLG2ISQH.js → chunk-7NF3V5L2.js} +4 -4
  19. package/dist/bundle/{chunk-TR7R5DL4.js → chunk-7NGFGFE5.js} +12 -63
  20. package/dist/bundle/{chunk-YA4LSSDZ.js → chunk-7NVPM55S.js} +2913 -2371
  21. package/dist/bundle/{chunk-XC5CKHX2.js → chunk-7YZPBAQX.js} +1 -1
  22. package/dist/bundle/{chunk-RSIS7BR7.js → chunk-AYU5TFDU.js} +21 -21
  23. package/dist/bundle/{chunk-64D5VUZ4.js → chunk-BEPFGITI.js} +68 -64
  24. package/dist/bundle/{chunk-HRTIRRXR.js → chunk-CBGBFAYJ.js} +41 -6
  25. package/dist/bundle/{chunk-QC3KOJT4.js → chunk-CDGZZNGY.js} +6 -6
  26. package/dist/bundle/{chunk-JK44XO2S.js → chunk-CIVXTBJY.js} +56 -56
  27. package/dist/bundle/{chunk-OWJDC4CB.js → chunk-COH7OEER.js} +14 -13
  28. package/dist/bundle/{chunk-XL2HXHP3.js → chunk-D6RCRBDH.js} +2 -2
  29. package/dist/bundle/{chunk-47R43UVJ.js → chunk-EQPAZ33O.js} +19 -19
  30. package/dist/bundle/{chunk-AE2KQ37N.js → chunk-EY6S7FV3.js} +6 -6
  31. package/dist/bundle/chunk-FEMHUSGO.js +88 -0
  32. package/dist/bundle/{chunk-NLDYZBTC.js → chunk-FSJHASRQ.js} +1146 -2555
  33. package/dist/bundle/chunk-GBFEEHQC.js +385 -0
  34. package/dist/bundle/{chunk-IQWEJEB5.js → chunk-GCCPFKSU.js} +26264 -21086
  35. package/dist/bundle/{chunk-RDZ7SVBZ.js → chunk-GK4GLPG2.js} +3 -3
  36. package/dist/bundle/{chunk-B2XKEEFX.js → chunk-GSNE7OB4.js} +4 -4
  37. package/dist/bundle/{chunk-UWW24JQF.js → chunk-HTKSCSJU.js} +4 -4
  38. package/dist/bundle/{chunk-7FII4DCE.js → chunk-IJMFG7HB.js} +7 -7
  39. package/dist/bundle/{chunk-WVZFXI36.js → chunk-JIRRF6BM.js} +4 -4
  40. package/dist/bundle/{chunk-ST2UC7FS.js → chunk-JODE2XED.js} +31 -27
  41. package/dist/bundle/{chunk-CWVAYQXI.js → chunk-K5I64ZVI.js} +9 -9
  42. package/dist/bundle/chunk-KFVDL2QS.js +146 -0
  43. package/dist/bundle/{chunk-JKIN5TOU.js → chunk-KL3P5TQK.js} +4 -4
  44. package/dist/bundle/chunk-L62XTC7N.js +726 -0
  45. package/dist/bundle/chunk-L6H7PY4X.js +170 -0
  46. package/dist/bundle/{chunk-F6MLJ3V5.js → chunk-LIQMUDIZ.js} +2 -2
  47. package/dist/bundle/{chunk-HWRKURQH.js → chunk-M2EEIYBU.js} +2 -2
  48. package/dist/bundle/chunk-M6DGZ2O6.js +823 -0
  49. package/dist/bundle/chunk-MGUEZYFA.js +5546 -0
  50. package/dist/bundle/{chunk-UWIA2G6Q.js → chunk-MRA62W5K.js} +404 -537
  51. package/dist/bundle/{chunk-XYIT2XB3.js → chunk-MVA5HVKL.js} +20 -0
  52. package/dist/bundle/{chunk-GA3URWIF.js → chunk-NO2LIHWA.js} +1 -1
  53. package/dist/bundle/{chunk-ESZT4WW3.js → chunk-OCDJ4FFA.js} +4 -4
  54. package/dist/bundle/{chunk-B4B65XIO.js → chunk-OI5DWZJG.js} +3 -3
  55. package/dist/bundle/chunk-P3P6DA6K.js +259 -0
  56. package/dist/bundle/chunk-QX3TPFEX.js +1977 -0
  57. package/dist/bundle/{chunk-EU5WCOMQ.js → chunk-R6SDRSZK.js} +76 -35
  58. package/dist/bundle/{chunk-K5TWMQSY.js → chunk-RMJMID5D.js} +8 -8
  59. package/dist/bundle/{chunk-RLSFOR2D.js → chunk-SGBS5QCU.js} +4 -4
  60. package/dist/bundle/{chunk-3D3PFXBP.js → chunk-T5UNSFES.js} +10 -15
  61. package/dist/bundle/{chunk-RAZKIHGH.js → chunk-TFNRCCGR.js} +4 -4
  62. package/dist/bundle/{chunk-WK3OSDNV.js → chunk-TJCPTRYD.js} +7 -7
  63. package/dist/bundle/{chunk-BWICUW7W.js → chunk-TXONV3HW.js} +2 -2
  64. package/dist/bundle/{chunk-AQZO3ITW.js → chunk-TZ2QJ53V.js} +2 -2
  65. package/dist/bundle/{chunk-35K5T6WV.js → chunk-UKE3CGHK.js} +1 -1
  66. package/dist/bundle/{chunk-7N5QB6NL.js → chunk-UROEWCOG.js} +5 -3
  67. package/dist/bundle/chunk-WHJWURZB.js +335 -0
  68. package/dist/bundle/{chunk-R6ZM45NF.js → chunk-WU3XHGOB.js} +185 -57
  69. package/dist/bundle/{chunk-2YR3RYT4.js → chunk-WZEEEQGC.js} +3 -3
  70. package/dist/bundle/{chunk-B2WFKFYL.js → chunk-XCTOCVMW.js} +20 -116
  71. package/dist/bundle/chunk-XFLCVHSQ.js +50 -0
  72. package/dist/bundle/{chunk-EGTBL3MJ.js → chunk-Y5LAJWR5.js} +1 -1
  73. package/dist/bundle/{chunk-66PL7P4C.js → chunk-YAPDU3SV.js} +1 -1
  74. package/dist/bundle/{chunk-WWMB4UHF.js → chunk-YFWLHTNO.js} +1 -1
  75. package/dist/bundle/{chunk-KHOVVPLC.js → chunk-YGCI3DHS.js} +1 -1
  76. package/dist/bundle/{chunk-4GC5DBHW.js → chunk-Z53LYX4M.js} +3 -3
  77. package/dist/bundle/{chunk-EPAZ7DJB.js → chunk-ZC6ZQQ55.js} +48 -45
  78. package/dist/bundle/command-contract-UBXS6NHI.js +38 -0
  79. package/dist/bundle/{command-server-entry-A66DJ3MH.js → command-server-entry-2SORMVRM.js} +27 -24
  80. package/dist/bundle/decode-5O7IEFPN.js +297 -0
  81. package/dist/bundle/{dispatch-FEKU5UXC.js → dispatch-YHQX6FEJ.js} +8 -8
  82. package/dist/bundle/{dist-YFKABFFF.js → dist-ILNOLGYN.js} +1 -1
  83. package/dist/bundle/{echarts-XD2JSWU4.js → echarts-ARLMVQC7.js} +2 -2
  84. package/dist/bundle/{embed-F3HYGAF7.js → embed-FUDUKQ3K.js} +7 -7
  85. package/dist/bundle/{embedder-GSEDDUH7.js → embedder-HDRV7GX3.js} +10 -10
  86. package/dist/bundle/{failure-HDJLR2YJ.js → failure-JHXICWIL.js} +3 -3
  87. package/dist/bundle/first-run-BGEFTXOE.js +29 -0
  88. package/dist/bundle/first-screen-F5F3VS6Y.js +38 -0
  89. package/dist/bundle/{instructions-NZGJ4FW5.js → instructions-MEFIKCDI.js} +1 -1
  90. package/dist/bundle/{mcp-VFIOZDVY.js → mcp-VMS6PBCU.js} +2 -2
  91. package/dist/bundle/mdast-util-from-markdown-R66F4HZA.js +1958 -0
  92. package/dist/bundle/mdast-util-gfm-LN2ELINH.js +2699 -0
  93. package/dist/bundle/meeting-combined-HNSS3FQY.js +24 -0
  94. package/dist/bundle/meeting-model-REZVYGQW.js +26 -0
  95. package/dist/bundle/meeting-semantic-R4CSLVRG.js +22 -0
  96. package/dist/bundle/micromark-extension-gfm-5X7YT43T.js +1838 -0
  97. package/dist/bundle/{node-RPKPDYQS.js → node-MAQALPLA.js} +2 -2
  98. package/dist/bundle/{node-sqlite-KH2UUYVO.js → node-sqlite-J7IJYNBO.js} +8 -8
  99. package/dist/bundle/notion.js +14 -14
  100. package/dist/bundle/{oauth-NKAI7TQD.js → oauth-AMV4YGJD.js} +8 -8
  101. package/dist/bundle/{open-WSAEAA2V.js → open-AB27MTGR.js} +6 -6
  102. package/dist/bundle/{openai-JPVDGHG5.js → openai-D77MU5XV.js} +31 -29
  103. package/dist/bundle/{process-5ZFVKOQX.js → process-SIOWTRJ6.js} +1 -1
  104. package/dist/bundle/{program-M3D56D6T.js → program-QC5MX4ZJ.js} +7533 -1997
  105. package/dist/bundle/{prompt-FROYQ5LV.js → prompt-W77YDHA6.js} +6 -6
  106. package/dist/bundle/{recognize-NYCHQMCX.js → recognize-3JAXQQ36.js} +5 -5
  107. package/dist/bundle/{remote-4OERF3Z4.js → remote-PSOJXCXO.js} +11 -11
  108. package/dist/bundle/{rerank-TEGXFUWY.js → rerank-EE44ZTGL.js} +8 -8
  109. package/dist/bundle/{schemas-MZNNOEYN.js → schemas-LBYUMBC6.js} +2 -2
  110. package/dist/bundle/{serve-HLYYBAXY.js → serve-XJMGAMFW.js} +10 -10
  111. package/dist/bundle/{server-D5OYNEUW.js → server-ASU6CP5R.js} +53 -44
  112. package/dist/bundle/server-WSPQ5EOA.js +72 -0
  113. package/dist/bundle/services-PT4PA4J6.js +588 -0
  114. package/dist/bundle/{sqlite-runtime-H2S5RR2F.js → sqlite-runtime-YHXRTVXE.js} +7 -7
  115. package/dist/bundle/{state-OPOXCDZL.js → state-T6ZKFWGD.js} +7 -7
  116. package/dist/bundle/{store-NHMXEJPD.js → store-3MUCZEI3.js} +20 -14
  117. package/dist/bundle/{store-Y3KRLCJ7.js → store-E5EE25FY.js} +30 -21
  118. package/dist/bundle/store-maintenance-command-ZZ55BBBG.js +63 -0
  119. package/dist/commands/api.d.ts.map +1 -1
  120. package/dist/commands/api.js +13 -4
  121. package/dist/commands/api.js.map +1 -1
  122. package/dist/commands/documents.d.ts +10 -1
  123. package/dist/commands/documents.d.ts.map +1 -1
  124. package/dist/commands/documents.js +175 -5
  125. package/dist/commands/documents.js.map +1 -1
  126. package/dist/commands/library.d.ts +10 -0
  127. package/dist/commands/library.d.ts.map +1 -0
  128. package/dist/commands/library.js +470 -0
  129. package/dist/commands/library.js.map +1 -0
  130. package/dist/commands/session.d.ts.map +1 -1
  131. package/dist/commands/session.js +4 -3
  132. package/dist/commands/session.js.map +1 -1
  133. package/dist/config.d.ts +19 -0
  134. package/dist/config.d.ts.map +1 -1
  135. package/dist/config.js +73 -5
  136. package/dist/config.js.map +1 -1
  137. package/dist/context.d.ts +8 -0
  138. package/dist/context.d.ts.map +1 -1
  139. package/dist/context.js +15 -3
  140. package/dist/context.js.map +1 -1
  141. package/dist/generated/types.d.ts +485 -375
  142. package/dist/generated/types.d.ts.map +1 -1
  143. package/dist/identity.d.ts.map +1 -1
  144. package/dist/identity.js +1 -0
  145. package/dist/identity.js.map +1 -1
  146. package/dist/knowledge.d.ts +27 -0
  147. package/dist/knowledge.d.ts.map +1 -0
  148. package/dist/knowledge.js +87 -0
  149. package/dist/knowledge.js.map +1 -0
  150. package/dist/library.d.ts +44 -0
  151. package/dist/library.d.ts.map +1 -0
  152. package/dist/library.js +149 -0
  153. package/dist/library.js.map +1 -0
  154. package/dist/notion/client.d.ts +4 -1
  155. package/dist/notion/client.d.ts.map +1 -1
  156. package/dist/notion/client.js +5 -2
  157. package/dist/notion/client.js.map +1 -1
  158. package/dist/notion/errors.d.ts +5 -0
  159. package/dist/notion/errors.d.ts.map +1 -1
  160. package/dist/notion/errors.js +33 -1
  161. package/dist/notion/errors.js.map +1 -1
  162. package/dist/notion/reads.d.ts +4 -0
  163. package/dist/notion/reads.d.ts.map +1 -1
  164. package/dist/notion/writes.d.ts +40 -0
  165. package/dist/notion/writes.d.ts.map +1 -0
  166. package/dist/notion/writes.js +112 -0
  167. package/dist/notion/writes.js.map +1 -0
  168. package/dist/program.js +2 -2
  169. package/dist/program.js.map +1 -1
  170. package/dist/sync/cursor.d.ts +93 -0
  171. package/dist/sync/cursor.d.ts.map +1 -1
  172. package/dist/sync/cursor.js +63 -2
  173. package/dist/sync/cursor.js.map +1 -1
  174. package/dist/sync/files.d.ts +87 -0
  175. package/dist/sync/files.d.ts.map +1 -0
  176. package/dist/sync/files.js +31 -0
  177. package/dist/sync/files.js.map +1 -0
  178. package/dist/sync/markdown.d.ts +4 -1
  179. package/dist/sync/markdown.d.ts.map +1 -1
  180. package/dist/sync/markdown.js +8 -6
  181. package/dist/sync/markdown.js.map +1 -1
  182. package/dist/sync/source.d.ts +6 -59
  183. package/dist/sync/source.d.ts.map +1 -1
  184. package/dist/sync/source.js +650 -271
  185. package/dist/sync/source.js.map +1 -1
  186. package/dist/version.d.ts +1 -1
  187. package/dist/version.js +1 -1
  188. package/package.json +3 -3
  189. package/skills/notion-cli/SKILL.md +18 -1
  190. package/dist/bundle/command-contract-6G5DC2FN.js +0 -35
  191. package/dist/bundle/decode-7XOFRAAT.js +0 -163
  192. package/dist/bundle/first-run-TXNTIUSP.js +0 -28
  193. package/dist/bundle/first-screen-JZPJND7J.js +0 -33
  194. package/dist/bundle/server-LWZGVMNW.js +0 -62
  195. package/dist/bundle/store-maintenance-command-D4W7WSLQ.js +0 -53
  196. package/dist/commands/comments.d.ts +0 -3
  197. package/dist/commands/comments.d.ts.map +0 -1
  198. package/dist/commands/comments.js +0 -114
  199. package/dist/commands/comments.js.map +0 -1
  200. package/dist/sample/comments.d.ts +0 -61
  201. package/dist/sample/comments.d.ts.map +0 -1
  202. package/dist/sample/comments.js +0 -39
  203. package/dist/sample/comments.js.map +0 -1
  204. package/dist/sample/records.d.ts +0 -16
  205. package/dist/sample/records.d.ts.map +0 -1
  206. package/dist/sample/records.js +0 -22
  207. package/dist/sample/records.js.map +0 -1
  208. package/dist/sample/transport.d.ts +0 -42
  209. package/dist/sample/transport.d.ts.map +0 -1
  210. package/dist/sample/transport.js +0 -153
  211. package/dist/sample/transport.js.map +0 -1
  212. /package/dist/bundle/{chunk-ZI3YTXSF.js → chunk-SHTHNBHG.js} +0 -0
@@ -245,6 +245,25 @@ function isoTimestamp(message$1) {
245
245
  }
246
246
  __name(isoTimestamp, "isoTimestamp");
247
247
  // @__NO_SIDE_EFFECTS__
248
+ function maxEntries(requirement, message$1) {
249
+ return {
250
+ kind: "validation",
251
+ type: "max_entries",
252
+ reference: maxEntries,
253
+ async: false,
254
+ expects: `<=${requirement}`,
255
+ requirement,
256
+ message: message$1,
257
+ "~run"(dataset, config$1) {
258
+ if (!dataset.typed) return dataset;
259
+ const count = Object.keys(dataset.value).length;
260
+ if (dataset.typed && count > this.requirement) _addIssue(this, "entries", dataset, config$1, { received: `${count}` });
261
+ return dataset;
262
+ }
263
+ };
264
+ }
265
+ __name(maxEntries, "maxEntries");
266
+ // @__NO_SIDE_EFFECTS__
248
267
  function maxLength(requirement, message$1) {
249
268
  return {
250
269
  kind: "validation",
@@ -1328,6 +1347,7 @@ export {
1328
1347
  integer,
1329
1348
  isoDate,
1330
1349
  isoTimestamp,
1350
+ maxEntries,
1331
1351
  maxLength,
1332
1352
  maxValue,
1333
1353
  minLength,
@@ -4,7 +4,7 @@ import {
4
4
  __name
5
5
  } from "./chunk-ZVVMGPBJ.js";
6
6
 
7
- // node_modules/.pnpm/@wirecat+cli-base@0.101.0_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/executable.js
7
+ // node_modules/.pnpm/@wirecat+cli-base@0.106.0_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/executable.js
8
8
  import { existsSync } from "node:fs";
9
9
  import { win32 } from "node:path";
10
10
  var variable = /* @__PURE__ */ __name((env, name) => Object.entries(env).find(([key]) => key.toUpperCase() === name)?.[1], "variable");
@@ -3,26 +3,26 @@ const require = __bundleRequire(import.meta.url);
3
3
  import {
4
4
  executableEnvironment,
5
5
  executableOnPath
6
- } from "./chunk-GA3URWIF.js";
6
+ } from "./chunk-NO2LIHWA.js";
7
7
  import {
8
8
  require_cross_spawn
9
9
  } from "./chunk-D72URWJE.js";
10
10
  import {
11
11
  loadConfigFile,
12
12
  saveConfigFile
13
- } from "./chunk-RSIS7BR7.js";
13
+ } from "./chunk-AYU5TFDU.js";
14
14
  import {
15
15
  number,
16
16
  object,
17
17
  optional,
18
18
  string
19
- } from "./chunk-XYIT2XB3.js";
19
+ } from "./chunk-MVA5HVKL.js";
20
20
  import {
21
21
  __name,
22
22
  __toESM
23
23
  } from "./chunk-ZVVMGPBJ.js";
24
24
 
25
- // node_modules/.pnpm/@wirecat+cli-base@0.101.0_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/update/index.js
25
+ // node_modules/.pnpm/@wirecat+cli-base@0.106.0_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/update/index.js
26
26
  var import_cross_spawn = __toESM(require_cross_spawn(), 1);
27
27
  import { existsSync } from "node:fs";
28
28
  var updateCommand = /* @__PURE__ */ __name((installer, packageName) => {
@@ -2,16 +2,16 @@ import { createRequire as __bundleRequire } from "node:module";
2
2
  const require = __bundleRequire(import.meta.url);
3
3
  import {
4
4
  alive
5
- } from "./chunk-XC5CKHX2.js";
5
+ } from "./chunk-7YZPBAQX.js";
6
6
  import {
7
7
  resolvePaths,
8
8
  writeSecurely
9
- } from "./chunk-RSIS7BR7.js";
9
+ } from "./chunk-AYU5TFDU.js";
10
10
  import {
11
11
  __name
12
12
  } from "./chunk-ZVVMGPBJ.js";
13
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
14
+ // node_modules/.pnpm/@wirecat+cli-core@0.680.0_@wirecat+cli-base@0.106.0_commander@15.0.0_esbuild@0.28.2_typ_620ac9b386657c249f5c9038159a7caa/node_modules/@wirecat/cli-core/dist/background/lock.js
15
15
  import { existsSync, linkSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
16
16
  import { dirname, join } from "node:path";
17
17
  var lockPath = /* @__PURE__ */ __name((app, profile, env) => join(resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).state, "serve", `${profile}.lock`), "lockPath");
@@ -0,0 +1,259 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ textModel,
5
+ vectorModelKey
6
+ } from "./chunk-WHJWURZB.js";
7
+ import {
8
+ OPENAI_URL,
9
+ openRemote,
10
+ remoteKey,
11
+ remoteModel
12
+ } from "./chunk-K5I64ZVI.js";
13
+ import {
14
+ endpointFetch
15
+ } from "./chunk-WZEEEQGC.js";
16
+ import {
17
+ isTextModelInstalled,
18
+ openEmbedder,
19
+ textModelsDirectory
20
+ } from "./chunk-5LBJNTEJ.js";
21
+ import {
22
+ CliError
23
+ } from "./chunk-LIQMUDIZ.js";
24
+ import {
25
+ __name
26
+ } from "./chunk-ZVVMGPBJ.js";
27
+
28
+ // node_modules/.pnpm/@wirecat+cli-core@0.680.0_@wirecat+cli-base@0.106.0_commander@15.0.0_esbuild@0.28.2_typ_620ac9b386657c249f5c9038159a7caa/node_modules/@wirecat/cli-core/dist/services/meeting-model.js
29
+ var integer = /* @__PURE__ */ __name((value, name, max) => {
30
+ if (!Number.isSafeInteger(value) || value < 1 || value > max)
31
+ throw new CliError("validation_error", `Invalid ${name}`);
32
+ return value;
33
+ }, "integer");
34
+ var cancelled = /* @__PURE__ */ __name((signal) => {
35
+ if (signal?.aborted)
36
+ throw new CliError("cancelled", "Meeting embedding was cancelled");
37
+ }, "cancelled");
38
+ var validatedRemote = /* @__PURE__ */ __name((remote) => {
39
+ let url;
40
+ try {
41
+ url = new URL(remote.baseUrl);
42
+ } catch {
43
+ throw new CliError("validation_error", "Invalid embedding endpoint");
44
+ }
45
+ if (!["http:", "https:"].includes(url.protocol) || url.username || url.password || url.search || url.hash)
46
+ throw new CliError("validation_error", "Embedding endpoint requires HTTP/S without credentials, query or fragment");
47
+ if (typeof remote.model !== "string" || !/^[\w./:-]{1,200}$/.test(remote.model))
48
+ throw new CliError("validation_error", "Invalid embedding model name");
49
+ const dims = integer(remote.dims, "embedding dimensions", 8192);
50
+ const baseUrl = remote.baseUrl.replace(/\/+$/, "");
51
+ const result = remoteModel({ model: remote.model, dims, ...baseUrl === OPENAI_URL ? {} : { baseUrl } });
52
+ return result;
53
+ }, "validatedRemote");
54
+ var meetingEmbeddingModel = /* @__PURE__ */ __name((choice, env) => {
55
+ if (typeof choice === "string") {
56
+ const model = textModel(choice, env);
57
+ return { key: vectorModelKey(model), dims: model.dims, kind: "local", model: model.id };
58
+ }
59
+ if (!choice || typeof choice !== "object" || !choice.remote)
60
+ throw new CliError("validation_error", "An explicit embedding model is required");
61
+ const remote = validatedRemote(choice.remote);
62
+ if (choice.concurrency !== void 0 && choice.concurrency !== 1)
63
+ throw new CliError("validation_error", "Meeting embedding supports one remote request worker");
64
+ return { key: remoteKey(remote), dims: remote.dims, kind: "remote", model: remote.model };
65
+ }, "meetingEmbeddingModel");
66
+ var createMeetingRemoteModel = /* @__PURE__ */ __name((input) => {
67
+ try {
68
+ return validatedRemote(remoteModel(input));
69
+ } catch (error) {
70
+ if (error instanceof CliError)
71
+ throw error;
72
+ throw new CliError("validation_error", "Invalid embedding endpoint");
73
+ }
74
+ }, "createMeetingRemoteModel");
75
+ var withAbort = /* @__PURE__ */ __name(async (pending, signal) => {
76
+ cancelled(signal);
77
+ if (!signal)
78
+ return pending;
79
+ let onAbort = /* @__PURE__ */ __name(() => {
80
+ }, "onAbort");
81
+ const interrupted = new Promise((_, reject) => {
82
+ onAbort = /* @__PURE__ */ __name(() => reject(new CliError("cancelled", "Meeting embedding was cancelled")), "onAbort");
83
+ signal.addEventListener("abort", onAbort, { once: true });
84
+ });
85
+ try {
86
+ return await Promise.race([pending, interrupted]);
87
+ } finally {
88
+ signal.removeEventListener("abort", onAbort);
89
+ }
90
+ }, "withAbort");
91
+ var boundedResponse = /* @__PURE__ */ __name(async (response, maxBytes, signal) => {
92
+ const length = response.headers.get("content-length");
93
+ if (length !== null && (!/^\d+$/.test(length) || Number(length) > maxBytes)) {
94
+ void response.body?.cancel().catch(() => {
95
+ });
96
+ throw new CliError("invalid_response", "Embedding response exceeds the byte budget");
97
+ }
98
+ if (!response.body)
99
+ throw new CliError("invalid_response", "Embedding response has no body");
100
+ const reader = response.body.getReader();
101
+ const chunks = [];
102
+ let bytes = 0;
103
+ try {
104
+ for (; ; ) {
105
+ cancelled(signal);
106
+ const part = await withAbort(reader.read(), signal);
107
+ cancelled(signal);
108
+ if (part.done)
109
+ break;
110
+ bytes += part.value.byteLength;
111
+ if (bytes > maxBytes)
112
+ throw new CliError("invalid_response", "Embedding response exceeds the byte budget");
113
+ chunks.push(part.value);
114
+ }
115
+ const body = Buffer.concat(chunks, bytes).toString("utf8");
116
+ try {
117
+ return JSON.parse(body);
118
+ } catch {
119
+ throw new CliError("invalid_response", "Embedding response is not JSON");
120
+ }
121
+ } finally {
122
+ void reader.cancel().catch(() => {
123
+ });
124
+ reader.releaseLock();
125
+ }
126
+ }, "boundedResponse");
127
+ var openMeetingEmbedder = /* @__PURE__ */ __name(async (choice, options = {}) => {
128
+ const descriptor = meetingEmbeddingModel(choice, options.env);
129
+ const { signal } = options;
130
+ cancelled(signal);
131
+ const maxInputBytes = integer(options.maxInputBytes ?? 1024 * 1024, "input byte budget", 16 * 1024 * 1024);
132
+ const maxResponseBytes = integer(options.maxResponseBytes ?? 8 * 1024 * 1024, "response byte budget", 64 * 1024 * 1024);
133
+ if (options.threads !== void 0)
134
+ integer(options.threads, "embedding threads", 128);
135
+ let engine;
136
+ let remoteFailure;
137
+ if (typeof choice === "string") {
138
+ const model = textModel(choice, options.env);
139
+ const directory = options.directory ?? textModelsDirectory(options.env);
140
+ if (!isTextModelInstalled(model, directory))
141
+ throw new CliError("configuration_error", "The explicit local embedding model is not installed");
142
+ engine = await openEmbedder(model, directory, {
143
+ ...options.threads === void 0 ? {} : { threads: options.threads }
144
+ });
145
+ } else {
146
+ const remote = validatedRemote(choice.remote);
147
+ const key = choice.apiKey ?? (remote.provider === "openai" ? (options.env ?? process.env).OPENAI_API_KEY : void 0);
148
+ if (remote.provider === "openai" && !key)
149
+ throw new CliError("authentication_error", "The explicit remote embedding model requires an API key");
150
+ const post = options.fetch ?? endpointFetch(remote.baseUrl, 12e4);
151
+ const guarded = /* @__PURE__ */ __name(async (url, init) => {
152
+ try {
153
+ cancelled(signal);
154
+ const responseTask = post(url, { ...init, redirect: "manual", ...signal ? { signal } : {} }).then((response2) => {
155
+ if (signal?.aborted) {
156
+ void response2.body?.cancel().catch(() => {
157
+ });
158
+ cancelled(signal);
159
+ }
160
+ return response2;
161
+ });
162
+ const response = await withAbort(responseTask, signal);
163
+ if (signal?.aborted) {
164
+ void response.body?.cancel().catch(() => {
165
+ });
166
+ cancelled(signal);
167
+ }
168
+ if (response.status >= 300 && response.status < 400) {
169
+ void response.body?.cancel().catch(() => {
170
+ });
171
+ throw new CliError("invalid_response", "Embedding redirects are refused");
172
+ }
173
+ if (!response.ok) {
174
+ void response.body?.cancel().catch(() => {
175
+ });
176
+ return new Response("{}", { status: response.status });
177
+ }
178
+ const body = await boundedResponse(response, maxResponseBytes, signal);
179
+ if (!body || typeof body !== "object" || !("data" in body) || !Array.isArray(body.data) || body.data.length > 256)
180
+ throw new CliError("invalid_response", "Embedding response lacks vector data");
181
+ for (const entry of body.data) {
182
+ if (!entry || typeof entry !== "object" || !Number.isSafeInteger(entry.index) || entry.index < 0 || !Array.isArray(entry.embedding) || entry.embedding.length !== remote.dims || entry.embedding.some((value) => typeof value !== "number" || !Number.isFinite(value) || !Number.isFinite(Math.fround(value))))
183
+ throw new CliError("invalid_response", "Embedding response contains invalid vectors");
184
+ }
185
+ const indices = body.data.map((entry) => entry.index).sort((a, b) => a - b);
186
+ if (indices.some((index, position) => index !== position))
187
+ throw new CliError("invalid_response", "Embedding response contains invalid vector indices");
188
+ return new Response(JSON.stringify({ data: body.data.map((entry) => ({ index: entry.index, embedding: entry.embedding })) }), { status: response.status });
189
+ } catch (error) {
190
+ remoteFailure = error;
191
+ throw error;
192
+ }
193
+ }, "guarded");
194
+ engine = openRemote(remote, key, { concurrency: 1, fetch: guarded, tries: 1, env: options.env ?? process.env });
195
+ }
196
+ if (signal?.aborted) {
197
+ await engine.close();
198
+ cancelled(signal);
199
+ }
200
+ let closed = false;
201
+ let running = false;
202
+ let active = null;
203
+ let closing = null;
204
+ return {
205
+ ...descriptor,
206
+ async embed(texts, kind) {
207
+ cancelled(signal);
208
+ if (closed)
209
+ throw new CliError("configuration_error", "Meeting embedder is closed");
210
+ if (!Array.isArray(texts) || texts.length > 1e3 || texts.some((text) => typeof text !== "string") || !["query", "passage"].includes(kind))
211
+ throw new CliError("validation_error", "Invalid meeting embedding inputs");
212
+ if (Buffer.byteLength(JSON.stringify(texts), "utf8") > maxInputBytes || texts.length * descriptor.dims * 4 > maxResponseBytes)
213
+ throw new CliError("validation_error", "Meeting embedding input or vector payload exceeds its byte budget");
214
+ if (running)
215
+ throw new CliError("validation_error", "A meeting embedding request is already running");
216
+ running = true;
217
+ let settled = /* @__PURE__ */ __name(() => {
218
+ }, "settled");
219
+ active = new Promise((resolve) => {
220
+ settled = resolve;
221
+ });
222
+ remoteFailure = void 0;
223
+ try {
224
+ const vectors = await engine.embed([...texts], kind);
225
+ cancelled(signal);
226
+ if (vectors.length !== texts.length || vectors.some((vector) => vector.length !== descriptor.dims || !vector.some((value) => value !== 0) || [...vector].some((value) => !Number.isFinite(value))))
227
+ throw new CliError("invalid_response", "Meeting embedder returned invalid vectors");
228
+ return vectors;
229
+ } catch (error) {
230
+ cancelled(signal);
231
+ if (remoteFailure instanceof CliError)
232
+ throw remoteFailure;
233
+ if (error instanceof CliError)
234
+ throw error;
235
+ throw new CliError("provider_error", "Meeting embedding failed");
236
+ } finally {
237
+ running = false;
238
+ settled();
239
+ active = null;
240
+ }
241
+ },
242
+ async close() {
243
+ if (!closing) {
244
+ closed = true;
245
+ closing = (async () => {
246
+ await active;
247
+ await engine.close();
248
+ })();
249
+ }
250
+ await closing;
251
+ }
252
+ };
253
+ }, "openMeetingEmbedder");
254
+
255
+ export {
256
+ meetingEmbeddingModel,
257
+ createMeetingRemoteModel,
258
+ openMeetingEmbedder
259
+ };