@cjhyy/code-shell 0.1.6 → 0.2.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 (171) hide show
  1. package/dist/anthropic-OVRWAZRD.js +1 -0
  2. package/dist/arena/index.js +1 -104
  3. package/dist/arena-64T2EQD4.js +3 -0
  4. package/dist/bwrap-PVZMLHZR.js +2 -0
  5. package/dist/chunk-2EUIMKJA.js +1 -0
  6. package/dist/chunk-2GJ7H5NC.js +641 -0
  7. package/dist/chunk-2OD6VR4N.js +2 -0
  8. package/dist/chunk-3QP5BQ3L.js +1 -0
  9. package/dist/chunk-A4M2Y42L.js +2 -0
  10. package/dist/chunk-DEYFK6FP.js +1 -0
  11. package/dist/chunk-DTPABBSV.js +2 -0
  12. package/dist/chunk-EU3J7TBP.js +1 -0
  13. package/dist/chunk-FU7AHZNN.js +1 -0
  14. package/dist/chunk-L7B2ORID.js +4 -0
  15. package/dist/chunk-M7VU4YVY.js +49 -0
  16. package/dist/chunk-MGP35GKD.js +254 -0
  17. package/dist/chunk-MLCTC53I.js +1 -0
  18. package/dist/chunk-O5HFCH2U.js +1 -0
  19. package/dist/chunk-P6JSTIFM.js +1 -0
  20. package/dist/chunk-Q3RSX66I.js +1 -0
  21. package/dist/chunk-QTWU7UNA.js +5 -0
  22. package/dist/chunk-RERBX75D.js +251 -0
  23. package/dist/chunk-SNFAPSLA.js +1 -0
  24. package/dist/chunk-T222K6IV.js +18 -0
  25. package/dist/chunk-TKJA6W36.js +3 -0
  26. package/dist/chunk-VKKU4LOM.js +3 -0
  27. package/dist/chunk-WI6FSWGU.js +1 -0
  28. package/dist/chunk-XXCZE2U2.js +2 -0
  29. package/dist/chunk-ZSAONDT6.js +2 -0
  30. package/dist/cli/main.js +303 -22060
  31. package/dist/cli/onboarding.d.ts +7 -2
  32. package/dist/client-base-F5FCRSB3.js +1 -0
  33. package/dist/compaction-L3Y6NG4N.js +1 -0
  34. package/dist/context/compaction.d.ts +2 -1
  35. package/dist/data/static-catalogs.d.ts +25 -0
  36. package/dist/devtools-SGDUOOM4.js +1 -0
  37. package/dist/engine/engine.d.ts +24 -0
  38. package/dist/engine/turn-loop.d.ts +20 -0
  39. package/dist/export-md-U72T7NW7.js +22 -0
  40. package/dist/file-history-7FQFEQOL.js +1 -0
  41. package/dist/index.d.ts +1 -1
  42. package/dist/index.js +1 -347
  43. package/dist/llm/capabilities/index.d.ts +20 -0
  44. package/dist/llm/capabilities/rules.d.ts +26 -0
  45. package/dist/llm/capabilities/types.d.ts +108 -0
  46. package/dist/llm/model-pool.d.ts +7 -0
  47. package/dist/llm/provider-catalog.d.ts +2 -0
  48. package/dist/llm/provider-kinds.d.ts +1 -1
  49. package/dist/llm/providers/openai.d.ts +22 -0
  50. package/dist/llm/token-counter.d.ts +17 -0
  51. package/dist/llm/types.d.ts +8 -0
  52. package/dist/logging/logger.d.ts +10 -2
  53. package/dist/logging/session-recorder.d.ts +16 -3
  54. package/dist/manager-J6FXEUEK.js +1 -0
  55. package/dist/mcp-manager-27EVBKRT.js +1 -0
  56. package/dist/memory-BNI4WEWL.js +1 -0
  57. package/dist/model-cache-HEDXI7UJ.js +1 -0
  58. package/dist/model-fetcher-X5W5EASG.js +1 -0
  59. package/dist/off-7SDVMMXW.js +1 -0
  60. package/dist/openai-3QEADSYL.js +1 -0
  61. package/dist/openrouter-models-GZVCRWD2.js +1 -0
  62. package/dist/openrouter-sync-WG4AG5NC.js +1 -0
  63. package/dist/product/index.js +1 -21
  64. package/dist/protocol/client.d.ts +1 -1
  65. package/dist/run/index.js +1 -48
  66. package/dist/seatbelt-L54CNI2Y.js +37 -0
  67. package/dist/session/session-manager.d.ts +2 -0
  68. package/dist/session-manager-AGWS5SMJ.js +1 -0
  69. package/dist/settings/schema.d.ts +147 -21
  70. package/dist/tool-summary-V2B3MD5N.js +2 -0
  71. package/dist/tool-system/builtin/bash.d.ts +7 -1
  72. package/dist/tool-system/context.d.ts +7 -0
  73. package/dist/tool-system/executor.d.ts +4 -0
  74. package/dist/tool-system/sandbox/bwrap.d.ts +13 -0
  75. package/dist/tool-system/sandbox/index.d.ts +78 -0
  76. package/dist/tool-system/sandbox/off.d.ts +2 -0
  77. package/dist/tool-system/sandbox/seatbelt.d.ts +18 -0
  78. package/dist/tool-system/task-guard.d.ts +30 -0
  79. package/dist/types.d.ts +17 -0
  80. package/dist/ui/components/SessionPicker.d.ts +2 -0
  81. package/dist/ui/components/SpinnerWithVerb.d.ts +7 -2
  82. package/dist/ui/components/StatusLine.d.ts +7 -3
  83. package/dist/updater-OCNU2K2Z.js +1 -0
  84. package/package.json +7 -10
  85. package/dist/anthropic-IBTI4WL2.cjs +0 -10
  86. package/dist/anthropic-PRZZKHEZ.js +0 -10
  87. package/dist/arena/index.cjs +0 -104
  88. package/dist/arena-2LTLIXOL.js +0 -261
  89. package/dist/arena-ADB7DRFI.cjs +0 -261
  90. package/dist/chunk-2YW4FPFG.cjs +0 -101
  91. package/dist/chunk-3OA5G4TM.js +0 -47
  92. package/dist/chunk-3QO25N6E.js +0 -4711
  93. package/dist/chunk-3SBSUOWZ.js +0 -447
  94. package/dist/chunk-52LGZKT3.cjs +0 -47
  95. package/dist/chunk-55XGPMAP.cjs +0 -146
  96. package/dist/chunk-6QVAYW7C.cjs +0 -438
  97. package/dist/chunk-6S4BJ65N.js +0 -113
  98. package/dist/chunk-76HYEPDM.js +0 -307
  99. package/dist/chunk-7BI3V74Y.cjs +0 -447
  100. package/dist/chunk-7EG3V4JY.cjs +0 -113
  101. package/dist/chunk-7JVTYEEC.js +0 -340
  102. package/dist/chunk-7QIM3BKD.js +0 -44
  103. package/dist/chunk-7Y6S3OCX.js +0 -438
  104. package/dist/chunk-ABRRONJ7.js +0 -107
  105. package/dist/chunk-BSW22MPA.js +0 -146
  106. package/dist/chunk-BXCY2FSE.js +0 -203
  107. package/dist/chunk-BZ5TNE7L.js +0 -5128
  108. package/dist/chunk-DDB6QOKJ.cjs +0 -1252
  109. package/dist/chunk-HEKQCI7B.cjs +0 -224
  110. package/dist/chunk-IK4EWJBP.cjs +0 -203
  111. package/dist/chunk-ILHE7XLT.cjs +0 -107
  112. package/dist/chunk-JMR33QVF.cjs +0 -169
  113. package/dist/chunk-KAQHULYN.js +0 -54
  114. package/dist/chunk-KE4EQOWA.js +0 -294
  115. package/dist/chunk-KOVYSDHZ.cjs +0 -340
  116. package/dist/chunk-KS3RYAYL.cjs +0 -45
  117. package/dist/chunk-MD32R22I.js +0 -50
  118. package/dist/chunk-MV7YI4WO.cjs +0 -293
  119. package/dist/chunk-MY5XHADU.cjs +0 -216
  120. package/dist/chunk-NUNC3VFB.cjs +0 -307
  121. package/dist/chunk-PKGRTCCY.js +0 -9092
  122. package/dist/chunk-QARL3IDQ.js +0 -1252
  123. package/dist/chunk-S754JHLR.cjs +0 -54
  124. package/dist/chunk-SFXHZSRF.js +0 -101
  125. package/dist/chunk-SIHHIQLO.js +0 -224
  126. package/dist/chunk-T6VYG46N.js +0 -105
  127. package/dist/chunk-TNLGBJYS.cjs +0 -44
  128. package/dist/chunk-TUY2T5KP.cjs +0 -105
  129. package/dist/chunk-UXOCVJJ6.cjs +0 -9092
  130. package/dist/chunk-VIAGTYYW.js +0 -169
  131. package/dist/chunk-WASS5YWB.js +0 -215
  132. package/dist/chunk-WZJV6DJC.cjs +0 -5128
  133. package/dist/chunk-YIQBXAYU.cjs +0 -264
  134. package/dist/chunk-YKIAELDZ.cjs +0 -4711
  135. package/dist/chunk-ZBPSQCPU.js +0 -264
  136. package/dist/cli/main.cjs +0 -22156
  137. package/dist/client-base-HTF236ZD.cjs +0 -9
  138. package/dist/client-base-QKRKCOWB.js +0 -9
  139. package/dist/compaction-6VU2T643.js +0 -33
  140. package/dist/compaction-OKUNTCA7.cjs +0 -33
  141. package/dist/devtools-T2NIZBJK.cjs +0 -6
  142. package/dist/devtools-YXWHOVKR.js +0 -6
  143. package/dist/export-md-RXDW6F5W.cjs +0 -135
  144. package/dist/export-md-XXKZANW5.js +0 -135
  145. package/dist/file-history-KYPE3ECT.cjs +0 -7
  146. package/dist/file-history-LF4F7X26.js +0 -7
  147. package/dist/index.cjs +0 -347
  148. package/dist/manager-D65VFAPX.js +0 -7
  149. package/dist/manager-TTF5VHJC.cjs +0 -7
  150. package/dist/mcp-manager-QMKWPBZ4.js +0 -8
  151. package/dist/mcp-manager-Z3OKI74O.cjs +0 -8
  152. package/dist/memory-5LWZ6FI2.cjs +0 -9
  153. package/dist/memory-VIJLBAMQ.js +0 -9
  154. package/dist/model-cache-5KIYL5SL.js +0 -13
  155. package/dist/model-cache-OED3IM4R.cjs +0 -13
  156. package/dist/model-fetcher-HKGICACL.js +0 -8
  157. package/dist/model-fetcher-UR6WJOQP.cjs +0 -8
  158. package/dist/openai-JR2WEKOF.js +0 -10
  159. package/dist/openai-YBTOET4O.cjs +0 -10
  160. package/dist/openrouter-models-H56GHBHN.js +0 -15
  161. package/dist/openrouter-models-TWUFWZ5T.cjs +0 -15
  162. package/dist/openrouter-sync-5VMGN6C2.cjs +0 -11
  163. package/dist/openrouter-sync-ALEMF5IU.js +0 -11
  164. package/dist/product/index.cjs +0 -21
  165. package/dist/run/index.cjs +0 -48
  166. package/dist/session-manager-Q22BBMD3.js +0 -8
  167. package/dist/session-manager-XODQVL3C.cjs +0 -8
  168. package/dist/tool-summary-63DPIS7G.cjs +0 -31
  169. package/dist/tool-summary-NP5CDBKG.js +0 -31
  170. package/dist/updater-I7QBW4DP.cjs +0 -17
  171. package/dist/updater-NVME5S3Z.js +0 -17
@@ -1,293 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
-
3
-
4
-
5
- var _chunkKS3RYAYLcjs = require('./chunk-KS3RYAYL.cjs');
6
-
7
- // src/cli/updater.ts
8
- _chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
9
- var _child_process = require('child_process');
10
- var _fs = require('fs');
11
- var _promises = require('fs/promises');
12
- var _module = require('module');
13
- var _os = require('os');
14
- var _path = require('path');
15
-
16
- var _url = require('url');
17
- var _util = require('util');
18
-
19
- // src/utils/semver.ts
20
- _chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
21
- var _semver = require('semver');
22
- function gt(a, b) {
23
- return _semver.gt.call(void 0, a, b);
24
- }
25
-
26
- // src/cli/updater.ts
27
- var execFileAsync = _util.promisify.call(void 0, _child_process.execFile);
28
- var PACKAGE_NAME = "@cjhyy/code-shell";
29
- var LOCK_FILE = ".update.lock";
30
- var LOCK_TIMEOUT_MS = 5 * 60 * 1e3;
31
- var NPM_VIEW_TIMEOUT_MS = 5e3;
32
- var _updateInfo;
33
- var _exitHookInstalled = false;
34
- var _disabledReason = null;
35
- function checkForUpdate(packageName = PACKAGE_NAME) {
36
- void runCheck(packageName);
37
- }
38
- function getUpdateAvailable() {
39
- return _updateInfo;
40
- }
41
- function getAutoUpdateDisabledReason() {
42
- return _disabledReason;
43
- }
44
- function scheduleAutoInstallOnExit() {
45
- if (_exitHookInstalled) return;
46
- _exitHookInstalled = true;
47
- const fire = () => {
48
- const info = _updateInfo;
49
- if (!info || !info.canAutoInstall) return;
50
- try {
51
- launchDetachedInstall(info.latestVersion);
52
- } catch (e) {
53
- }
54
- };
55
- process.once("exit", fire);
56
- }
57
- var _cachedVersion;
58
- function getCurrentVersion() {
59
- if (_cachedVersion) return _cachedVersion;
60
- const found = resolveVersion();
61
- _cachedVersion = found;
62
- return found;
63
- }
64
- function resolveVersion() {
65
- try {
66
- const here = typeof import.meta !== "undefined" && _chunkKS3RYAYLcjs.importMetaUrl ? _path.dirname.call(void 0, _url.fileURLToPath.call(void 0, _chunkKS3RYAYLcjs.importMetaUrl)) : __dirname;
67
- let dir = here;
68
- for (let i = 0; i < 6; i++) {
69
- try {
70
- const pkg = JSON.parse(_fs.readFileSync.call(void 0, _path.resolve.call(void 0, dir, "package.json"), "utf-8"));
71
- if (pkg && typeof pkg.version === "string") return pkg.version;
72
- } catch (e2) {
73
- }
74
- const parent = _path.dirname.call(void 0, dir);
75
- if (parent === dir) break;
76
- dir = parent;
77
- }
78
- } catch (e3) {
79
- }
80
- try {
81
- const req = _module.createRequire.call(void 0, _nullishCoalesce(_chunkKS3RYAYLcjs.importMetaUrl, () => ( __filename)));
82
- const pkg = req("../../package.json");
83
- if (_optionalChain([pkg, 'optionalAccess', _ => _.version])) return pkg.version;
84
- } catch (e4) {
85
- }
86
- return "0.0.0";
87
- }
88
- async function runCheck(packageName) {
89
- const disabled = isAutoUpdaterDisabled();
90
- if (disabled) {
91
- _disabledReason = disabled;
92
- return;
93
- }
94
- _disabledReason = null;
95
- try {
96
- const currentVersion = getCurrentVersion();
97
- const latestVersion = await getLatestVersion(packageName);
98
- if (!latestVersion) return;
99
- let isNewer = false;
100
- try {
101
- isNewer = gt(latestVersion, currentVersion);
102
- } catch (e5) {
103
- isNewer = latestVersion !== currentVersion;
104
- }
105
- if (!isNewer) {
106
- _updateInfo = void 0;
107
- return;
108
- }
109
- const { hasPermissions, npmPrefix } = await checkGlobalInstallPermissions();
110
- _updateInfo = { latestVersion, canAutoInstall: hasPermissions, npmPrefix };
111
- } catch (e6) {
112
- }
113
- }
114
- async function getLatestVersion(packageName) {
115
- try {
116
- const { stdout } = await execFileAsync(
117
- "npm",
118
- ["view", `${packageName}@latest`, "version", "--prefer-online"],
119
- { cwd: _os.homedir.call(void 0, ), timeout: NPM_VIEW_TIMEOUT_MS }
120
- );
121
- const v = stdout.trim();
122
- return v.length > 0 ? v : null;
123
- } catch (e7) {
124
- return null;
125
- }
126
- }
127
- async function checkGlobalInstallPermissions() {
128
- let prefix = null;
129
- try {
130
- const { stdout } = await execFileAsync(
131
- "npm",
132
- ["-g", "config", "get", "prefix"],
133
- { cwd: _os.homedir.call(void 0, ), timeout: 5e3 }
134
- );
135
- prefix = stdout.trim();
136
- } catch (e8) {
137
- return { hasPermissions: false, npmPrefix: null };
138
- }
139
- if (!prefix) return { hasPermissions: false, npmPrefix: null };
140
- try {
141
- await _promises.access.call(void 0, prefix, _fs.constants.W_OK);
142
- return { hasPermissions: true, npmPrefix: prefix };
143
- } catch (e9) {
144
- return { hasPermissions: false, npmPrefix: prefix };
145
- }
146
- }
147
- function userHome() {
148
- return _nullishCoalesce(process.env.HOME, () => ( _os.homedir.call(void 0, )));
149
- }
150
- function configDir() {
151
- return _path.join.call(void 0, userHome(), ".code-shell");
152
- }
153
- function getLockFilePath() {
154
- return _path.join.call(void 0, configDir(), LOCK_FILE);
155
- }
156
- function getUpdateLogPath() {
157
- return _path.join.call(void 0, configDir(), "update.log");
158
- }
159
- async function acquireLock() {
160
- const lockPath = getLockFilePath();
161
- try {
162
- const s = await _promises.stat.call(void 0, lockPath);
163
- if (Date.now() - s.mtimeMs < LOCK_TIMEOUT_MS) return false;
164
- try {
165
- const recheck = await _promises.stat.call(void 0, lockPath);
166
- if (Date.now() - recheck.mtimeMs < LOCK_TIMEOUT_MS) return false;
167
- await _promises.unlink.call(void 0, lockPath);
168
- } catch (err) {
169
- if (!isENOENT(err)) return false;
170
- }
171
- } catch (err) {
172
- if (!isENOENT(err)) return false;
173
- }
174
- try {
175
- await _promises.writeFile.call(void 0, lockPath, String(process.pid), { encoding: "utf8", flag: "wx" });
176
- return true;
177
- } catch (err) {
178
- const code = errnoCode(err);
179
- if (code === "EEXIST") return false;
180
- if (code === "ENOENT") {
181
- try {
182
- await _promises.mkdir.call(void 0, configDir(), { recursive: true });
183
- await _promises.writeFile.call(void 0, lockPath, String(process.pid), { encoding: "utf8", flag: "wx" });
184
- return true;
185
- } catch (e10) {
186
- return false;
187
- }
188
- }
189
- return false;
190
- }
191
- }
192
- async function releaseLock() {
193
- const lockPath = getLockFilePath();
194
- try {
195
- const data = await _promises.readFile.call(void 0, lockPath, "utf8");
196
- if (data === String(process.pid)) await _promises.unlink.call(void 0, lockPath);
197
- } catch (e11) {
198
- }
199
- }
200
- function launchDetachedInstall(version) {
201
- const lockPath = getLockFilePath();
202
- try {
203
- try {
204
- const fs2 = _chunkKS3RYAYLcjs.__require.call(void 0, "fs");
205
- fs2.mkdirSync(configDir(), { recursive: true });
206
- fs2.writeFileSync(lockPath, String(process.pid), { encoding: "utf8", flag: "wx" });
207
- } catch (err) {
208
- if (errnoCode(err) === "EEXIST") {
209
- try {
210
- const fs2 = _chunkKS3RYAYLcjs.__require.call(void 0, "fs");
211
- const s = fs2.statSync(lockPath);
212
- if (Date.now() - s.mtimeMs < LOCK_TIMEOUT_MS) return;
213
- fs2.unlinkSync(lockPath);
214
- fs2.writeFileSync(lockPath, String(process.pid), { encoding: "utf8", flag: "wx" });
215
- } catch (e12) {
216
- return;
217
- }
218
- } else {
219
- return;
220
- }
221
- }
222
- } catch (e13) {
223
- return;
224
- }
225
- const fs = _chunkKS3RYAYLcjs.__require.call(void 0, "fs");
226
- const logFd = fs.openSync(getUpdateLogPath(), "a");
227
- try {
228
- fs.writeSync(
229
- logFd,
230
- `
231
- [${(/* @__PURE__ */ new Date()).toISOString()}] code-shell auto-update: installing ${PACKAGE_NAME}@${version} (pid=${process.pid})
232
- `
233
- );
234
- } catch (e14) {
235
- }
236
- const cmd = [
237
- `npm install -g ${PACKAGE_NAME}@${shellEscape(version)}`,
238
- `; rm -f ${shellEscape(lockPath)}`
239
- ].join(" ");
240
- try {
241
- const child = _child_process.spawn.call(void 0, "sh", ["-c", cmd], {
242
- detached: true,
243
- stdio: ["ignore", logFd, logFd],
244
- cwd: _os.homedir.call(void 0, )
245
- });
246
- child.unref();
247
- } catch (e15) {
248
- try {
249
- fs.unlinkSync(lockPath);
250
- } catch (e16) {
251
- }
252
- }
253
- }
254
- function isAutoUpdaterDisabled() {
255
- if (process.env.NODE_ENV === "development") return "development build";
256
- if (isEnvTruthy(process.env.DISABLE_AUTOUPDATER)) return "DISABLE_AUTOUPDATER set";
257
- if (readAutoUpdatesFlagFromDisk() === false) return "settings.autoUpdates = false";
258
- return null;
259
- }
260
- function readAutoUpdatesFlagFromDisk() {
261
- const path = _path.join.call(void 0, userHome(), ".code-shell", "settings.json");
262
- try {
263
- const raw = _fs.readFileSync.call(void 0, path, "utf8");
264
- const parsed = JSON.parse(raw);
265
- if (typeof parsed.autoUpdates === "boolean") return parsed.autoUpdates;
266
- } catch (e17) {
267
- }
268
- return void 0;
269
- }
270
- function isEnvTruthy(v) {
271
- if (!v) return false;
272
- const lower = v.toLowerCase();
273
- return lower === "1" || lower === "true" || lower === "yes" || lower === "on";
274
- }
275
- function errnoCode(err) {
276
- return typeof err === "object" && err !== null && "code" in err ? String(err.code) : void 0;
277
- }
278
- function isENOENT(err) {
279
- return errnoCode(err) === "ENOENT";
280
- }
281
- function shellEscape(s) {
282
- return `'${s.replace(/'/g, `'\\''`)}'`;
283
- }
284
- var __internal = { acquireLock, releaseLock, getLockFilePath };
285
-
286
-
287
-
288
-
289
-
290
-
291
-
292
-
293
- exports.checkForUpdate = checkForUpdate; exports.getUpdateAvailable = getUpdateAvailable; exports.getAutoUpdateDisabledReason = getAutoUpdateDisabledReason; exports.scheduleAutoInstallOnExit = scheduleAutoInstallOnExit; exports.getCurrentVersion = getCurrentVersion; exports.__internal = __internal;
@@ -1,216 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
-
3
-
4
-
5
- var _chunk52LGZKT3cjs = require('./chunk-52LGZKT3.cjs');
6
-
7
-
8
-
9
- var _chunkKS3RYAYLcjs = require('./chunk-KS3RYAYL.cjs');
10
-
11
- // src/llm/model-fetcher.ts
12
- _chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
13
- var _fs = require('fs');
14
- var _url = require('url');
15
- var _path = require('path');
16
-
17
- // src/llm/provider-kinds.ts
18
- _chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
19
- var NON_CHAT_PATTERNS = /(?:^|[-_/])(?:embed(?:ding)?|whisper|tts|audio|image|dall-?e|moderation|rerank|guard|vision-only)(?:$|[-_/])/i;
20
- var isChatLike = (id) => !NON_CHAT_PATTERNS.test(id);
21
- var bearer = (k) => k ? { Authorization: `Bearer ${k}` } : {};
22
- var PROVIDER_KINDS = {
23
- openai: {
24
- label: "OpenAI",
25
- defaultBaseUrl: "https://api.openai.com/v1",
26
- modelsPath: "/models",
27
- protocol: "openai-compat",
28
- authHeader: bearer,
29
- chatFilter: isChatLike
30
- },
31
- anthropic: {
32
- label: "Anthropic",
33
- defaultBaseUrl: "https://api.anthropic.com/v1",
34
- modelsPath: "/models",
35
- protocol: "anthropic-style",
36
- authHeader: (k) => k ? { "x-api-key": k, "anthropic-version": "2023-06-01" } : { "anthropic-version": "2023-06-01" },
37
- chatFilter: isChatLike
38
- },
39
- deepseek: {
40
- label: "DeepSeek",
41
- defaultBaseUrl: "https://api.deepseek.com/v1",
42
- modelsPath: "/models",
43
- protocol: "openai-compat",
44
- authHeader: bearer,
45
- chatFilter: isChatLike
46
- },
47
- xai: {
48
- label: "xAI (Grok)",
49
- defaultBaseUrl: "https://api.x.ai/v1",
50
- modelsPath: "/models",
51
- protocol: "openai-compat",
52
- authHeader: bearer,
53
- chatFilter: isChatLike
54
- },
55
- mistral: {
56
- label: "Mistral",
57
- defaultBaseUrl: "https://api.mistral.ai/v1",
58
- modelsPath: "/models",
59
- protocol: "openai-compat",
60
- authHeader: bearer,
61
- chatFilter: isChatLike
62
- },
63
- groq: {
64
- label: "Groq",
65
- defaultBaseUrl: "https://api.groq.com/openai/v1",
66
- modelsPath: "/models",
67
- protocol: "openai-compat",
68
- authHeader: bearer,
69
- chatFilter: isChatLike
70
- },
71
- google: {
72
- label: "Google Gemini",
73
- defaultBaseUrl: "https://generativelanguage.googleapis.com/v1beta",
74
- modelsPath: "/models",
75
- protocol: "gemini",
76
- authHeader: () => ({}),
77
- authQuery: (k) => k ? { key: k } : {},
78
- chatFilter: (id) => isChatLike(id) && /gemini/i.test(id)
79
- },
80
- openrouter: {
81
- label: "OpenRouter",
82
- defaultBaseUrl: "https://openrouter.ai/api/v1",
83
- modelsPath: "/models",
84
- protocol: "openai-compat",
85
- authHeader: bearer,
86
- chatFilter: isChatLike
87
- },
88
- ollama: {
89
- label: "Ollama (local)",
90
- defaultBaseUrl: "http://localhost:11434",
91
- modelsPath: "/api/tags",
92
- protocol: "ollama",
93
- authHeader: () => ({}),
94
- chatFilter: isChatLike
95
- },
96
- custom: {
97
- label: "Custom",
98
- defaultBaseUrl: "",
99
- modelsPath: "/models",
100
- protocol: "openai-compat",
101
- authHeader: bearer,
102
- chatFilter: isChatLike
103
- }
104
- };
105
- function getKindMeta(kind) {
106
- return _nullishCoalesce(PROVIDER_KINDS[kind], () => ( PROVIDER_KINDS.custom));
107
- }
108
-
109
- // src/llm/model-fetcher.ts
110
- var HERE = _path.dirname.call(void 0, _url.fileURLToPath.call(void 0, _chunkKS3RYAYLcjs.importMetaUrl));
111
- var OPENROUTER_SNAPSHOT = _path.join.call(void 0, HERE, "..", "data", "openrouter-models.json");
112
- async function fetchModelList(provider, opts) {
113
- const meta = getKindMeta(provider.kind);
114
- if (!opts.refresh) {
115
- const cached = _chunk52LGZKT3cjs.readCache.call(void 0, opts.cacheDir, provider.key);
116
- if (cached && !_chunk52LGZKT3cjs.isStale.call(void 0, cached)) return { ...cached, fromCache: true };
117
- }
118
- if (provider.kind === "openrouter") {
119
- return loadOpenRouterSnapshot(provider.key, opts.cacheDir);
120
- }
121
- try {
122
- const path = _nullishCoalesce(provider.modelsPath, () => ( meta.modelsPath));
123
- const url = new URL(joinUrl(provider.baseUrl, path));
124
- const headers = meta.authHeader(_nullishCoalesce(provider.apiKey, () => ( "")));
125
- if (meta.authQuery) {
126
- const q = meta.authQuery(_nullishCoalesce(provider.apiKey, () => ( "")));
127
- for (const [k, v] of Object.entries(q)) url.searchParams.set(k, v);
128
- }
129
- const res = await fetch(url.toString(), {
130
- headers: { Accept: "application/json", ...headers },
131
- signal: AbortSignal.timeout(_nullishCoalesce(opts.timeoutMs, () => ( 2e4)))
132
- });
133
- if (!res.ok) {
134
- return errorResult(provider.key, opts.cacheDir, `HTTP ${res.status}`);
135
- }
136
- const payload = await res.json();
137
- const raw = normalize(payload, meta.protocol);
138
- const filtered = raw.filter((m) => meta.chatFilter(m.id));
139
- const file = _chunk52LGZKT3cjs.writeCache.call(void 0, opts.cacheDir, provider.key, filtered);
140
- return file;
141
- } catch (err) {
142
- const msg = err.message || String(err);
143
- return errorResult(provider.key, opts.cacheDir, msg);
144
- }
145
- }
146
- function normalize(payload, protocol) {
147
- switch (protocol) {
148
- case "ollama": {
149
- const p = payload;
150
- return (_nullishCoalesce(p.models, () => ( []))).map((m) => ({ id: m.name, contextLength: 0, maxOutputTokens: 0 }));
151
- }
152
- case "anthropic-style": {
153
- const p = payload;
154
- return (_nullishCoalesce(p.data, () => ( []))).map((m) => ({
155
- id: m.id,
156
- contextLength: _nullishCoalesce(m.context_window, () => ( 2e5)),
157
- maxOutputTokens: _nullishCoalesce(m.max_output_tokens, () => ( 0))
158
- }));
159
- }
160
- case "gemini": {
161
- const p = payload;
162
- return (_nullishCoalesce(p.models, () => ( []))).map((m) => ({
163
- id: m.name.replace(/^models\//, ""),
164
- contextLength: _nullishCoalesce(m.inputTokenLimit, () => ( 0)),
165
- maxOutputTokens: _nullishCoalesce(m.outputTokenLimit, () => ( 0))
166
- }));
167
- }
168
- case "openai-compat": {
169
- const p = payload;
170
- return (_nullishCoalesce(p.data, () => ( []))).map((m) => ({
171
- id: m.id,
172
- contextLength: _nullishCoalesce(_nullishCoalesce(m.context_window, () => ( m.context_length)), () => ( 0)),
173
- maxOutputTokens: _nullishCoalesce(m.max_completion_tokens, () => ( 0))
174
- }));
175
- }
176
- }
177
- const _exhaustive = protocol;
178
- return _exhaustive;
179
- }
180
- function loadOpenRouterSnapshot(providerKey, cacheDir) {
181
- if (!_fs.existsSync.call(void 0, OPENROUTER_SNAPSHOT)) {
182
- return errorResult(providerKey, cacheDir, "openrouter snapshot missing");
183
- }
184
- try {
185
- const snapshot = JSON.parse(
186
- _fs.readFileSync.call(void 0, OPENROUTER_SNAPSHOT, "utf-8")
187
- );
188
- const models = (_nullishCoalesce(snapshot.models, () => ( []))).map((m) => ({
189
- id: m.id,
190
- contextLength: _nullishCoalesce(m.contextLength, () => ( 0)),
191
- maxOutputTokens: _nullishCoalesce(m.maxOutputTokens, () => ( 0))
192
- }));
193
- return _chunk52LGZKT3cjs.writeCache.call(void 0, cacheDir, providerKey, models);
194
- } catch (err) {
195
- return errorResult(providerKey, cacheDir, err.message);
196
- }
197
- }
198
- function errorResult(providerKey, cacheDir, error) {
199
- const stale = _chunk52LGZKT3cjs.readCache.call(void 0, cacheDir, providerKey);
200
- if (stale) return { ...stale, error, fromCache: true };
201
- return {
202
- fetchedAt: (/* @__PURE__ */ new Date()).toISOString(),
203
- providerKey,
204
- models: [],
205
- error
206
- };
207
- }
208
- function joinUrl(base, path) {
209
- if (!base) return path;
210
- return `${base.replace(/\/$/, "")}${path.startsWith("/") ? "" : "/"}${path}`;
211
- }
212
-
213
-
214
-
215
-
216
- exports.PROVIDER_KINDS = PROVIDER_KINDS; exports.fetchModelList = fetchModelList;