@wirecat/drive-cli 0.43.0 → 0.45.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 (182) hide show
  1. package/README.md +1 -1
  2. package/dist/bin/drive.js +35 -40
  3. package/dist/bundle/all-profiles-LTHNCWQW.js +26 -0
  4. package/dist/bundle/anthropic-NOJEF3V2.js +71 -0
  5. package/dist/bundle/bun-ADJVI4HY.js +169 -0
  6. package/dist/bundle/bun-sqlite-GNXLBF2A.js +70 -0
  7. package/dist/bundle/chunk-2FTZBZOB.js +2315 -0
  8. package/dist/bundle/chunk-2YU3CXFD.js +3391 -0
  9. package/dist/bundle/chunk-35GRI4DI.js +375 -0
  10. package/dist/bundle/chunk-37MAA6F2.js +5624 -0
  11. package/dist/bundle/chunk-3V6NPZY7.js +2352 -0
  12. package/dist/bundle/chunk-4TIC23D2.js +9 -0
  13. package/dist/bundle/chunk-4TQSNQVV.js +1071 -0
  14. package/dist/bundle/chunk-4UE7AVHZ.js +150 -0
  15. package/dist/bundle/chunk-5DPV7X27.js +663 -0
  16. package/dist/bundle/chunk-5FONRUG6.js +24805 -0
  17. package/dist/bundle/chunk-5ZVLM6YR.js +19 -0
  18. package/dist/bundle/chunk-64WJYT2F.js +3954 -0
  19. package/dist/bundle/chunk-65GGKAQ7.js +82 -0
  20. package/dist/bundle/chunk-66N2DGGC.js +515 -0
  21. package/dist/bundle/chunk-6KFA6HOM.js +2941 -0
  22. package/dist/bundle/chunk-6Y2BYFXQ.js +65 -0
  23. package/dist/bundle/chunk-7NCG2SHR.js +74 -0
  24. package/dist/bundle/chunk-7PVNJAQ2.js +73 -0
  25. package/dist/bundle/chunk-7XWUOCGW.js +190 -0
  26. package/dist/bundle/chunk-A6ZKTNTZ.js +168 -0
  27. package/dist/bundle/chunk-ADLS6FVG.js +24600 -0
  28. package/dist/bundle/chunk-AH3SNVCV.js +498 -0
  29. package/dist/bundle/chunk-AN3GVZTU.js +76 -0
  30. package/dist/bundle/chunk-BPBIBVFH.js +166 -0
  31. package/dist/bundle/chunk-C4XP5T73.js +264 -0
  32. package/dist/bundle/chunk-C6SMAEED.js +18102 -0
  33. package/dist/bundle/chunk-CDI67JSB.js +1092 -0
  34. package/dist/bundle/chunk-CEO5HPRL.js +25 -0
  35. package/dist/bundle/chunk-CFT7UHF6.js +15572 -0
  36. package/dist/bundle/chunk-DC4T3FNP.js +1913 -0
  37. package/dist/bundle/chunk-DCTXOMOR.js +35 -0
  38. package/dist/bundle/chunk-DFDN6AUB.js +21 -0
  39. package/dist/bundle/chunk-EVWXODYV.js +754 -0
  40. package/dist/bundle/chunk-GKHM6I64.js +2356 -0
  41. package/dist/bundle/chunk-GNI7INK6.js +18 -0
  42. package/dist/bundle/chunk-GTYY6BIE.js +58 -0
  43. package/dist/bundle/chunk-GX4WEMAG.js +164 -0
  44. package/dist/bundle/chunk-HA3WCVGY.js +8179 -0
  45. package/dist/bundle/chunk-HLONHTSG.js +281 -0
  46. package/dist/bundle/chunk-HOIUIKWS.js +236 -0
  47. package/dist/bundle/chunk-HTQTIKWP.js +928 -0
  48. package/dist/bundle/chunk-I5EJHKNC.js +111 -0
  49. package/dist/bundle/chunk-ICKNJIGE.js +31 -0
  50. package/dist/bundle/chunk-IGB5CJCA.js +62 -0
  51. package/dist/bundle/chunk-IP4OK7RQ.js +24 -0
  52. package/dist/bundle/chunk-IVQ6342B.js +2 -0
  53. package/dist/bundle/chunk-K4N2DKE5.js +17 -0
  54. package/dist/bundle/chunk-LNB7BIZL.js +844 -0
  55. package/dist/bundle/chunk-LVDHWNJF.js +193 -0
  56. package/dist/bundle/chunk-LW2G4U6W.js +570 -0
  57. package/dist/bundle/chunk-LWT55XC5.js +60 -0
  58. package/dist/bundle/chunk-LY26NW3I.js +6848 -0
  59. package/dist/bundle/chunk-MJR2OTO4.js +1714 -0
  60. package/dist/bundle/chunk-MWUITL6N.js +42 -0
  61. package/dist/bundle/chunk-N47CYWEM.js +454 -0
  62. package/dist/bundle/chunk-NKZ6V4JW.js +263 -0
  63. package/dist/bundle/chunk-NQ6LLDDC.js +161 -0
  64. package/dist/bundle/chunk-NZIHPYY5.js +215 -0
  65. package/dist/bundle/chunk-OECPFZLP.js +3541 -0
  66. package/dist/bundle/chunk-P5KGFT7U.js +18 -0
  67. package/dist/bundle/chunk-PDH2QQQV.js +484 -0
  68. package/dist/bundle/chunk-PIN5RZ3D.js +63 -0
  69. package/dist/bundle/chunk-PJDO7AFZ.js +421 -0
  70. package/dist/bundle/chunk-PWKXHDBQ.js +18078 -0
  71. package/dist/bundle/chunk-QLZGLPJL.js +100 -0
  72. package/dist/bundle/chunk-SBZB7HMU.js +1055 -0
  73. package/dist/bundle/chunk-SGOPYPVW.js +835 -0
  74. package/dist/bundle/chunk-TDC6JGDA.js +630 -0
  75. package/dist/bundle/chunk-TOYPN2XX.js +288 -0
  76. package/dist/bundle/chunk-UC44ZMQV.js +78 -0
  77. package/dist/bundle/chunk-V7GN5BI7.js +99 -0
  78. package/dist/bundle/chunk-VO4KOLQZ.js +119 -0
  79. package/dist/bundle/chunk-WPGCDWPU.js +1855 -0
  80. package/dist/bundle/chunk-WQMVSQPP.js +886 -0
  81. package/dist/bundle/chunk-WZUJKUBK.js +384 -0
  82. package/dist/bundle/chunk-X5DFDGWS.js +2 -0
  83. package/dist/bundle/chunk-XFLCVHSQ.js +50 -0
  84. package/dist/bundle/chunk-XPEWOPJR.js +431 -0
  85. package/dist/bundle/chunk-Y5E2WNWB.js +35 -0
  86. package/dist/bundle/chunk-Y5EJSZXV.js +220 -0
  87. package/dist/bundle/chunk-YE3J6DLY.js +106 -0
  88. package/dist/bundle/chunk-YFLKH3NZ.js +48 -0
  89. package/dist/bundle/chunk-YJX4X564.js +138 -0
  90. package/dist/bundle/chunk-YJZBJ2TM.js +71 -0
  91. package/dist/bundle/chunk-Z4O6C7WR.js +1973 -0
  92. package/dist/bundle/chunk-ZIHLE7LG.js +15992 -0
  93. package/dist/bundle/chunk-ZPMLLONT.js +1054 -0
  94. package/dist/bundle/chunk-ZQNXKWUY.js +35584 -0
  95. package/dist/bundle/chunk-ZS635F4O.js +45 -0
  96. package/dist/bundle/chunk-ZU732VCC.js +122 -0
  97. package/dist/bundle/chunk-ZVVMGPBJ.js +50 -0
  98. package/dist/bundle/command-contract-HX35D7KV.js +38 -0
  99. package/dist/bundle/dist-MWTMOYWT.js +7577 -0
  100. package/dist/bundle/dist-PY3MVR3G.js +21 -0
  101. package/dist/bundle/drive.js +50 -0
  102. package/dist/bundle/echarts-RFTK737T.js +42501 -0
  103. package/dist/bundle/embed-5NAGJUMD.js +37 -0
  104. package/dist/bundle/embedder-EWXLIGBY.js +110 -0
  105. package/dist/bundle/entry-YCPJ6H6U.js +15 -0
  106. package/dist/bundle/failure-XBWHHBEW.js +37 -0
  107. package/dist/bundle/first-run-LNAZDBB4.js +24 -0
  108. package/dist/bundle/first-screen-P5NNFJD7.js +36 -0
  109. package/dist/bundle/google-5FFKRHHC.js +32 -0
  110. package/dist/bundle/google-api-TJCFOOAP.js +82 -0
  111. package/dist/bundle/identity-53ZMPL2O.js +10 -0
  112. package/dist/bundle/instructions-FHNL7CMW.js +9 -0
  113. package/dist/bundle/login-VXXZZR6G.js +158 -0
  114. package/dist/bundle/mcp-2CJCJXSW.js +95 -0
  115. package/dist/bundle/mcp-F4XZO76F.js +507 -0
  116. package/dist/bundle/mcp-IXFC2VVR.js +165 -0
  117. package/dist/bundle/mdast-util-from-markdown-FXEPSNER.js +1958 -0
  118. package/dist/bundle/mdast-util-gfm-SZM5GBDF.js +2103 -0
  119. package/dist/bundle/micromark-extension-gfm-GRL24TU6.js +1838 -0
  120. package/dist/bundle/node-P4E63KXA.js +2340 -0
  121. package/dist/bundle/node-TLZSIHIJ.js +21 -0
  122. package/dist/bundle/node-ZMCACJVS.js +176 -0
  123. package/dist/bundle/node-sqlite-QJQ5S7KS.js +46 -0
  124. package/dist/bundle/oauth-TZFDPAFE.js +18 -0
  125. package/dist/bundle/open-IYM25QTL.js +20 -0
  126. package/dist/bundle/process-ZPTLNVQS.js +91 -0
  127. package/dist/bundle/program-YX7DZMPR.js +24100 -0
  128. package/dist/bundle/prompt-TGWTVIEK.js +13 -0
  129. package/dist/bundle/reasons-Q5LOQESQ.js +11 -0
  130. package/dist/bundle/recognize-AGPMWKIY.js +191 -0
  131. package/dist/bundle/remote-QV7QSLAK.js +28 -0
  132. package/dist/bundle/rerank-HZKJJCS4.js +51 -0
  133. package/dist/bundle/serve-NRJQOVT4.js +20 -0
  134. package/dist/bundle/server-2UQDEWTS.js +818 -0
  135. package/dist/bundle/server-R4JUHFSW.js +56 -0
  136. package/dist/bundle/services-NZQWVMOE.js +333 -0
  137. package/dist/bundle/sqlite-runtime-6MXHTYYU.js +17 -0
  138. package/dist/bundle/state-IF2FLTSY.js +34 -0
  139. package/dist/bundle/store-HBD54IRL.js +142 -0
  140. package/dist/bundle/store-HVIBXOXS.js +125 -0
  141. package/dist/bundle/store-maintenance-command-U3F4RGJB.js +57 -0
  142. package/dist/bundle/terminal-TFCTWLOS.js +11 -0
  143. package/dist/bundle/tokens-5D5YUA2Q.js +103 -0
  144. package/dist/commands/config.js +1 -1
  145. package/dist/commands/config.js.map +1 -1
  146. package/dist/commands/mcp.d.ts.map +1 -1
  147. package/dist/commands/mcp.js +106 -54
  148. package/dist/commands/mcp.js.map +1 -1
  149. package/dist/config.d.ts +3 -1
  150. package/dist/config.d.ts.map +1 -1
  151. package/dist/config.js +3 -1
  152. package/dist/config.js.map +1 -1
  153. package/dist/contract-overrides.d.ts.map +1 -1
  154. package/dist/contract-overrides.js +123 -83
  155. package/dist/contract-overrides.js.map +1 -1
  156. package/dist/mcp.d.ts +14 -6
  157. package/dist/mcp.d.ts.map +1 -1
  158. package/dist/mcp.js +26 -12
  159. package/dist/mcp.js.map +1 -1
  160. package/dist/program.d.ts.map +1 -1
  161. package/dist/program.js +7 -5
  162. package/dist/program.js.map +1 -1
  163. package/dist/reasons.d.ts.map +1 -1
  164. package/dist/reasons.js +0 -1
  165. package/dist/reasons.js.map +1 -1
  166. package/dist/registry.d.ts +2 -2
  167. package/dist/registry.d.ts.map +1 -1
  168. package/dist/registry.js +8 -2
  169. package/dist/registry.js.map +1 -1
  170. package/dist/state.d.ts +6 -3
  171. package/dist/state.d.ts.map +1 -1
  172. package/dist/state.js +6 -3
  173. package/dist/state.js.map +1 -1
  174. package/dist/tokens.d.ts +4 -1
  175. package/dist/tokens.d.ts.map +1 -1
  176. package/dist/tokens.js +44 -8
  177. package/dist/tokens.js.map +1 -1
  178. package/dist/version.d.ts +1 -1
  179. package/dist/version.js +1 -1
  180. package/package.json +7 -5
  181. package/scenarios/agent-access.md +2 -2
  182. package/skills/drive-cli/SKILL.md +2 -1
@@ -0,0 +1,375 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ gunzipSync
5
+ } from "./chunk-5DPV7X27.js";
6
+ import {
7
+ filesPresent,
8
+ installFiles,
9
+ megabytes,
10
+ sharedModelsDirectory
11
+ } from "./chunk-C4XP5T73.js";
12
+ import {
13
+ CliError
14
+ } from "./chunk-GKHM6I64.js";
15
+ import {
16
+ importFrom
17
+ } from "./chunk-Y5E2WNWB.js";
18
+ import {
19
+ __name
20
+ } from "./chunk-ZVVMGPBJ.js";
21
+
22
+ // node_modules/.pnpm/@wirecat+cli-core@0.469.0_@wirecat+cli-base@0.65.0_commander@15.0.0_typescript@7.0.2_vi_80b586dbc8b099637a6e461856c2ee6b/node_modules/@wirecat/cli-core/dist/embeddings/embed.js
23
+ import { readFileSync as readFileSync2 } from "node:fs";
24
+ import { availableParallelism } from "node:os";
25
+ import { basename, join as join2 } from "node:path";
26
+
27
+ // node_modules/.pnpm/@wirecat+cli-core@0.469.0_@wirecat+cli-base@0.65.0_commander@15.0.0_typescript@7.0.2_vi_80b586dbc8b099637a6e461856c2ee6b/node_modules/@wirecat/cli-core/dist/embeddings/onnx-runtime.js
28
+ import { createHash } from "node:crypto";
29
+ import { copyFileSync, mkdirSync, mkdtempSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
30
+ import { join } from "node:path";
31
+ var ONNX_RUNTIME_VERSION = "1.30.0";
32
+ var release = /* @__PURE__ */ __name((name, sha256, bytes) => ({
33
+ name,
34
+ url: `https://github.com/microsoft/onnxruntime/releases/download/v${ONNX_RUNTIME_VERSION}/${name}`,
35
+ sha256,
36
+ bytes
37
+ }), "release");
38
+ var npmTarball = {
39
+ name: `onnxruntime-node-${ONNX_RUNTIME_VERSION}.tgz`,
40
+ url: `https://registry.npmjs.org/onnxruntime-node/-/onnxruntime-node-${ONNX_RUNTIME_VERSION}.tgz`,
41
+ sha256: "6e3390d6b783e7be946fad629292799da28d0b42f84856e50d2c1b0383291e75",
42
+ bytes: 113507888
43
+ };
44
+ var NATIVE = {
45
+ "linux-x64": {
46
+ archive: release("onnxruntime-linux-x64-1.30.0.tgz", "a5ed5a3cac51fbb2e90da632ae43d19212faaa20e76484e62bcb7c23ddb3b3fd", 11306877),
47
+ member: "onnxruntime-linux-x64-1.30.0/lib/libonnxruntime.so.1.30.0",
48
+ library: {
49
+ name: "libonnxruntime.so.1",
50
+ sha256: "245a6f8c38127551057a1cd1ffd59f0a186a227ade4f3492dea2494eb565542e",
51
+ bytes: 28985152
52
+ }
53
+ },
54
+ "linux-arm64": {
55
+ archive: release("onnxruntime-linux-aarch64-1.30.0.tgz", "e16a27a8ed330bbc698df7330b0cf56e722f354e3bcc92118682c74ef3c3e3da", 10269495),
56
+ member: "onnxruntime-linux-aarch64-1.30.0/lib/libonnxruntime.so.1.30.0",
57
+ library: {
58
+ name: "libonnxruntime.so.1",
59
+ sha256: "64e903a43a041240fd6bcffe0ac6d4fea47ef87bf24b9d097801bd00a9612a4b",
60
+ bytes: 25135496
61
+ }
62
+ },
63
+ "darwin-arm64": {
64
+ archive: release("onnxruntime-osx-arm64-1.30.0.tgz", "6ebb5062a934537c352937821f9fe9718e7de1a2db1122a93dd363ffd53a7012", 42373116),
65
+ member: "onnxruntime-osx-arm64-1.30.0/lib/libonnxruntime.1.30.0.dylib",
66
+ library: {
67
+ name: "libonnxruntime.1.dylib",
68
+ sha256: "bcc9110f9d638a119de2db7afb3ba9a1da8085f0cb3401e1c48ae1caf450b6fa",
69
+ bytes: 43879424
70
+ }
71
+ },
72
+ "win32-x64": {
73
+ archive: npmTarball,
74
+ member: "package/bin/napi-v6/win32/x64/onnxruntime.dll",
75
+ library: {
76
+ name: "onnxruntime.dll",
77
+ sha256: "508c362f5673483dd3a086379c392795b2e42d10d5e6f3f90ebd7ac21c97af67",
78
+ bytes: 28754232
79
+ }
80
+ },
81
+ "win32-arm64": {
82
+ archive: npmTarball,
83
+ member: "package/bin/napi-v6/win32/arm64/onnxruntime.dll",
84
+ library: {
85
+ name: "onnxruntime.dll",
86
+ sha256: "6c3a2abf5c6aca11c48a0d338a91af309f2266f25ce2e4084e6a87bbcb0fbfd0",
87
+ bytes: 29815136
88
+ }
89
+ }
90
+ };
91
+ var onMusl = /* @__PURE__ */ __name(() => {
92
+ try {
93
+ return readFileSync("/proc/self/maps", "utf8").includes("ld-musl");
94
+ } catch {
95
+ return false;
96
+ }
97
+ }, "onMusl");
98
+ var nativeRuntimeFor = /* @__PURE__ */ __name(({ platform = process.platform, arch = process.arch, musl = platform === "linux" && onMusl() } = {}) => {
99
+ const target = `${platform}-${arch}`;
100
+ const runtime = NATIVE[target];
101
+ return runtime && !musl ? { target, ...runtime } : void 0;
102
+ }, "nativeRuntimeFor");
103
+ var runtimeFolder = /* @__PURE__ */ __name((runtime, env = process.env) => join(sharedModelsDirectory("runtime", env), `onnxruntime-${ONNX_RUNTIME_VERSION}-${runtime.target}`), "runtimeFolder");
104
+ var BINDING = "onnxruntime_binding.node";
105
+ var sizeOf = /* @__PURE__ */ __name((path) => {
106
+ try {
107
+ return statSync(path).size;
108
+ } catch {
109
+ return void 0;
110
+ }
111
+ }, "sizeOf");
112
+ var isInstalled = /* @__PURE__ */ __name((runtime, folder) => sizeOf(join(folder, runtime.library.name)) === runtime.library.bytes && sizeOf(join(folder, BINDING)) !== void 0, "isInstalled");
113
+ var installNativeRuntime = /* @__PURE__ */ __name(async ({ env = process.env, progress = /* @__PURE__ */ __name(() => {
114
+ }, "progress"), fetch, runtime = nativeRuntimeFor(), binding } = {}) => {
115
+ if (!runtime)
116
+ return void 0;
117
+ const source = binding ?? (await importFrom(new URL("embeddings/onnx-runtime.js", import.meta.resolve("@wirecat/cli-core")).href, "@wirecat/cli-core-onnx")).nativeBindingFor();
118
+ if (!source)
119
+ return void 0;
120
+ const folder = runtimeFolder(runtime, env);
121
+ if (isInstalled(runtime, folder))
122
+ return folder;
123
+ progress(`ONNX Runtime ${ONNX_RUNTIME_VERSION} for ${runtime.target}: ${megabytes(runtime.archive.bytes)} from Microsoft`);
124
+ const parent = sharedModelsDirectory("runtime", env);
125
+ mkdirSync(parent, { recursive: true, mode: 448 });
126
+ const staging = mkdtempSync(join(parent, ".onnxruntime-"));
127
+ try {
128
+ const archive = join(staging, runtime.archive.name);
129
+ await installFiles([[runtime.archive, archive]], { ...fetch ? { fetch } : {}, progress });
130
+ const library = tarMember(gunzipSync(readFileSync(archive)), runtime.member);
131
+ rmSync(archive);
132
+ const sha256 = library && createHash("sha256").update(library).digest("hex");
133
+ if (!library || library.length !== runtime.library.bytes || sha256 !== runtime.library.sha256)
134
+ throw new CliError("invalid_response", `${runtime.archive.name} does not hold the ${runtime.library.name} this version expects \u2014 nothing was installed`);
135
+ writeFileSync(join(staging, runtime.library.name), library, { mode: 493 });
136
+ copyFileSync(source, join(staging, BINDING));
137
+ rmSync(folder, { recursive: true, force: true });
138
+ renameSync(staging, folder);
139
+ return folder;
140
+ } finally {
141
+ rmSync(staging, { recursive: true, force: true });
142
+ }
143
+ }, "installNativeRuntime");
144
+ var tarMember = /* @__PURE__ */ __name((tar, member) => {
145
+ const text = /* @__PURE__ */ __name((from, length) => new TextDecoder().decode(tar.subarray(from, from + length)).replace(/\0.*$/s, ""), "text");
146
+ const plain = /* @__PURE__ */ __name((path) => path.replace(/^\.\//, ""), "plain");
147
+ let longName;
148
+ for (let offset = 0; offset + 512 <= tar.length; ) {
149
+ const name = text(offset, 100);
150
+ if (!name)
151
+ return void 0;
152
+ const size = Number.parseInt(text(offset + 124, 12).trim() || "0", 8);
153
+ const type = text(offset + 156, 1);
154
+ const prefix = text(offset + 345, 155);
155
+ const data = tar.subarray(offset + 512, offset + 512 + size);
156
+ offset += 512 + Math.ceil(size / 512) * 512;
157
+ if (type === "x") {
158
+ longName = /(?:^|\n)\d+ path=([^\n]*)\n/.exec(new TextDecoder().decode(data))?.[1] ?? longName;
159
+ continue;
160
+ }
161
+ if (type === "L") {
162
+ longName = new TextDecoder().decode(data).replace(/\0.*$/s, "");
163
+ continue;
164
+ }
165
+ const path = plain(longName ?? (prefix ? `${prefix}/${name}` : name));
166
+ longName = void 0;
167
+ if (path === plain(member) && (type === "0" || type === ""))
168
+ return data;
169
+ }
170
+ return void 0;
171
+ }, "tarMember");
172
+ var opened = /* @__PURE__ */ new Map();
173
+ var onnxRuntime = /* @__PURE__ */ __name((env = process.env) => {
174
+ const runtime = nativeRuntimeFor();
175
+ const folder = runtime ? runtimeFolder(runtime, env) : "";
176
+ let found = opened.get(folder);
177
+ if (!found) {
178
+ found = (async () => {
179
+ const wasm = await importFrom(new URL("embeddings/onnx-runtime.js", import.meta.resolve("@wirecat/cli-core")).href, "@wirecat/cli-core-onnx");
180
+ if (runtime && isInstalled(runtime, folder)) {
181
+ try {
182
+ return { ort: wasm.openNative(join(folder, BINDING)), native: true };
183
+ } catch {
184
+ }
185
+ }
186
+ return { ort: wasm, native: false };
187
+ })();
188
+ opened.set(folder, found);
189
+ }
190
+ return found;
191
+ }, "onnxRuntime");
192
+ var openSession = /* @__PURE__ */ __name(async (bytes, threads, options = {}) => {
193
+ const runtime = await onnxRuntime();
194
+ if (runtime.native) {
195
+ try {
196
+ const session = await runtime.ort.InferenceSession.create(bytes, {
197
+ ...options,
198
+ intraOpNumThreads: threads,
199
+ interOpNumThreads: 1
200
+ });
201
+ return { ort: runtime.ort, session };
202
+ } catch {
203
+ }
204
+ }
205
+ const ort = await importFrom(new URL("embeddings/onnx-runtime.js", import.meta.resolve("@wirecat/cli-core")).href, "@wirecat/cli-core-onnx");
206
+ ort.env.wasm.numThreads = threads;
207
+ return { ort, session: await ort.InferenceSession.create(bytes, options) };
208
+ }, "openSession");
209
+
210
+ // node_modules/.pnpm/@wirecat+cli-core@0.469.0_@wirecat+cli-base@0.65.0_commander@15.0.0_typescript@7.0.2_vi_80b586dbc8b099637a6e461856c2ee6b/node_modules/@wirecat/cli-core/dist/embeddings/embed.js
211
+ var textModelsDirectory = /* @__PURE__ */ __name((env = process.env) => sharedModelsDirectory("text", env), "textModelsDirectory");
212
+ var placedText = /* @__PURE__ */ __name((model, directory) => model.files.map((file) => [file, join2(directory, model.id, file.name)]), "placedText");
213
+ var isTextModelInstalled = /* @__PURE__ */ __name((model, directory) => filesPresent(placedText(model, directory)), "isTextModelInstalled");
214
+ var defaultThreads = /* @__PURE__ */ __name(() => Math.min(8, availableParallelism()), "defaultThreads");
215
+ var WARM_IDLE_MS = 10 * 6e4;
216
+ var runEmbedders = /* @__PURE__ */ __name(() => {
217
+ const held = /* @__PURE__ */ new Map();
218
+ return {
219
+ get: /* @__PURE__ */ __name((key, open) => {
220
+ const one = held.get(key) ?? open();
221
+ held.set(key, one);
222
+ return one;
223
+ }, "get"),
224
+ close: /* @__PURE__ */ __name(async () => {
225
+ await Promise.allSettled([...held.values()].map(async (one) => (await one).close()));
226
+ }, "close")
227
+ };
228
+ }, "runEmbedders");
229
+ var warmEmbedders = /* @__PURE__ */ __name(({ idleMs = WARM_IDLE_MS } = {}) => {
230
+ const held = /* @__PURE__ */ new Map();
231
+ const timers = /* @__PURE__ */ new Map();
232
+ const running = /* @__PURE__ */ new Map();
233
+ const drop = /* @__PURE__ */ __name((key) => {
234
+ const one = held.get(key);
235
+ held.delete(key);
236
+ clearTimeout(timers.get(key));
237
+ timers.delete(key);
238
+ return one;
239
+ }, "drop");
240
+ const rearm = /* @__PURE__ */ __name((key) => {
241
+ clearTimeout(timers.get(key));
242
+ const timer = setTimeout(() => {
243
+ if (running.get(key))
244
+ return;
245
+ drop(key)?.then((one) => one.close()).catch(() => {
246
+ });
247
+ }, idleMs);
248
+ timer.unref?.();
249
+ timers.set(key, timer);
250
+ }, "rearm");
251
+ const hold = /* @__PURE__ */ __name((key, open, serial) => {
252
+ let opening = held.get(key);
253
+ if (!opening) {
254
+ const started = open().then((one) => serial(one, queue({
255
+ starts: /* @__PURE__ */ __name(() => running.set(key, (running.get(key) ?? 0) + 1), "starts"),
256
+ ends: /* @__PURE__ */ __name(() => {
257
+ running.set(key, (running.get(key) ?? 1) - 1);
258
+ rearm(key);
259
+ }, "ends")
260
+ })));
261
+ held.set(key, started);
262
+ started.catch(() => {
263
+ if (held.get(key) === started)
264
+ drop(key);
265
+ });
266
+ opening = started;
267
+ }
268
+ rearm(key);
269
+ return opening;
270
+ }, "hold");
271
+ return {
272
+ get: /* @__PURE__ */ __name((key, open) => hold(key, open, (embedder, run) => ({
273
+ model: embedder.model,
274
+ embed: /* @__PURE__ */ __name((texts, kind) => run.next(() => embedder.embed(texts, kind)), "embed"),
275
+ close: run.closing(() => embedder.close())
276
+ })), "get"),
277
+ reranker: /* @__PURE__ */ __name((key, open) => hold(key, open, (reranker, run) => ({
278
+ model: reranker.model,
279
+ score: /* @__PURE__ */ __name((question, passages) => run.next(() => reranker.score(question, passages)), "score"),
280
+ close: run.closing(() => reranker.close())
281
+ })), "reranker"),
282
+ close: /* @__PURE__ */ __name(async () => {
283
+ const all = [...held.keys()].map(drop);
284
+ await Promise.allSettled(all.map(async (one) => (await one)?.close()));
285
+ }, "close")
286
+ };
287
+ }, "warmEmbedders");
288
+ var queue = /* @__PURE__ */ __name(({ starts, ends }) => {
289
+ let last = Promise.resolve();
290
+ return {
291
+ next: /* @__PURE__ */ __name((work) => {
292
+ starts();
293
+ const next = last.then(work);
294
+ last = next.then(ends, ends);
295
+ return next;
296
+ }, "next"),
297
+ /** Closing waits for the run in progress. */
298
+ closing: /* @__PURE__ */ __name((close) => async () => {
299
+ await last;
300
+ await close();
301
+ }, "closing")
302
+ };
303
+ }, "queue");
304
+ var truncated = /* @__PURE__ */ __name((ids, max) => ids.length <= max ? ids : [...ids.slice(0, max - 1), ids.at(-1)], "truncated");
305
+ var unit = /* @__PURE__ */ __name((vector) => {
306
+ let sum = 0;
307
+ for (const value of vector)
308
+ sum += value * value;
309
+ const length = Math.sqrt(sum);
310
+ return length === 0 ? vector : vector.map((value) => value / length);
311
+ }, "unit");
312
+ var meanOf = /* @__PURE__ */ __name((data, tokens, dims) => {
313
+ const mean = new Float32Array(dims);
314
+ for (let token = 0; token < tokens; token++) {
315
+ for (let dim = 0; dim < dims; dim++)
316
+ mean[dim] = mean[dim] + data[token * dims + dim] / tokens;
317
+ }
318
+ return mean;
319
+ }, "meanOf");
320
+ var loadModel = /* @__PURE__ */ __name(async (model, directory, threads) => {
321
+ const { Tokenizer } = await importFrom(new URL("embeddings/embed.js", import.meta.resolve("@wirecat/cli-core")).href, "@huggingface/tokenizers");
322
+ const path = /* @__PURE__ */ __name((name) => join2(directory, model.id, name), "path");
323
+ const tokenizer = new Tokenizer(JSON.parse(readFileSync2(path("tokenizer.json"), "utf8")), JSON.parse(readFileSync2(path("tokenizer_config.json"), "utf8")));
324
+ const { ort, session } = await openSession(readFileSync2(path(model.onnx)), threads, model.externalData ? { externalData: [{ path: basename(model.externalData), data: readFileSync2(path(model.externalData)) }] } : {});
325
+ return { ort, tokenizer, session };
326
+ }, "loadModel");
327
+ var openEmbedder = /* @__PURE__ */ __name(async (model, directory, { threads = defaultThreads() } = {}) => {
328
+ const { ort, tokenizer, session } = await loadModel(model, directory, threads);
329
+ const typeIds = session.inputNames.includes("token_type_ids");
330
+ const one = /* @__PURE__ */ __name(async (text) => {
331
+ const ids = truncated(tokenizer.encode(text).ids, model.maxTokens);
332
+ const shape = [1, ids.length];
333
+ const feeds = {
334
+ input_ids: new ort.Tensor("int64", BigInt64Array.from(ids, BigInt), shape),
335
+ attention_mask: new ort.Tensor("int64", new BigInt64Array(ids.length).fill(1n), shape)
336
+ };
337
+ if (typeIds)
338
+ feeds.token_type_ids = new ort.Tensor("int64", new BigInt64Array(ids.length), shape);
339
+ const output = await session.run(feeds);
340
+ if (model.pooling === "sentence_embedding") {
341
+ return unit(Float32Array.from(output.sentence_embedding?.data));
342
+ }
343
+ const hidden = output.last_hidden_state;
344
+ if (!hidden)
345
+ throw new Error(`${model.id} gave no last_hidden_state`);
346
+ return unit(meanOf(hidden.data, ids.length, hidden.dims.at(-1)));
347
+ }, "one");
348
+ return {
349
+ model,
350
+ embed: /* @__PURE__ */ __name(async (texts, kind) => {
351
+ const vectors = [];
352
+ for (const text of texts)
353
+ vectors.push(await one(`${model.prefix[kind]}${text}`));
354
+ return vectors;
355
+ }, "embed"),
356
+ close: /* @__PURE__ */ __name(() => session.release(), "close")
357
+ };
358
+ }, "openEmbedder");
359
+
360
+ export {
361
+ installNativeRuntime,
362
+ openSession,
363
+ textModelsDirectory,
364
+ placedText,
365
+ isTextModelInstalled,
366
+ defaultThreads,
367
+ WARM_IDLE_MS,
368
+ runEmbedders,
369
+ warmEmbedders,
370
+ truncated,
371
+ unit,
372
+ meanOf,
373
+ loadModel,
374
+ openEmbedder
375
+ };