@hop-top/kit 0.5.0-alpha.2 → 0.5.0-alpha.4

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 (188) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/LICENSE +1 -1
  3. package/README.md +48 -480
  4. package/dist/{aim-CTp-kJW2.d.ts → aim-DZHwwiIc.d.ts} +1 -1
  5. package/dist/aim.d.ts +1 -1
  6. package/dist/aim.js +13 -414
  7. package/dist/{alias-dhhr08Ei.d.ts → alias-BOj0-VAr.d.ts} +1 -1
  8. package/dist/alias.d.ts +1 -1
  9. package/dist/alias.js +18 -206
  10. package/dist/{api-miiso81x.d.ts → api-DAexsu2H.d.ts} +1 -1
  11. package/dist/api.d.ts +1 -1
  12. package/dist/api.js +10 -164
  13. package/dist/auth.js +6 -40
  14. package/dist/chunk-3FIKGFKI.js +54 -0
  15. package/dist/chunk-4UE5TCMQ.js +104 -0
  16. package/dist/chunk-6HFAEZ52.js +29 -0
  17. package/dist/chunk-6SVOHNIC.js +17 -0
  18. package/dist/chunk-72XZWQX7.js +504 -0
  19. package/dist/chunk-ABQSE7AI.js +513 -0
  20. package/dist/chunk-BDNNPRX6.js +41 -0
  21. package/dist/chunk-BRNEKPWX.js +37 -0
  22. package/dist/chunk-CSJWB6D3.js +151 -0
  23. package/dist/chunk-GGWJRWWA.js +309 -0
  24. package/dist/chunk-IQXEISMC.js +142 -0
  25. package/dist/chunk-JTMPNXVQ.js +1491 -0
  26. package/dist/chunk-KVG7YCTS.js +115 -0
  27. package/dist/chunk-L23O2FFE.js +51 -0
  28. package/dist/chunk-MQXYDYRD.js +968 -0
  29. package/dist/chunk-MUIQVU6E.js +251 -0
  30. package/dist/chunk-POR5L2DG.js +247 -0
  31. package/dist/chunk-PSFYJGDG.js +1445 -0
  32. package/dist/chunk-QJVSKKRQ.js +369 -0
  33. package/dist/chunk-QPUCXQXT.js +67 -0
  34. package/dist/chunk-R5U7XKVJ.js +16 -0
  35. package/dist/chunk-S45UHXQF.js +182 -0
  36. package/dist/chunk-T46YPHKN.js +669 -0
  37. package/dist/chunk-UIOOOK6M.js +334 -0
  38. package/dist/chunk-UKZIAQA7.js +26 -0
  39. package/dist/chunk-WBVO43HU.js +355 -0
  40. package/dist/chunk-WTYDHXPW.js +574 -0
  41. package/dist/chunk-WUOAQVOA.js +86 -0
  42. package/dist/chunk-WWUKGJB5.js +90 -0
  43. package/dist/chunk-YGYQUFGY.js +219 -0
  44. package/dist/chunk-YOBAUCVN.js +583 -0
  45. package/dist/{cli-DgOEOsPB.d.ts → cli-8rfITnv4.d.ts} +13 -4
  46. package/dist/cli.d.ts +4 -3
  47. package/dist/cli.js +50 -1056
  48. package/dist/{config-BUY7_W2n.d.ts → config-Bm9fBXch.d.ts} +35 -4
  49. package/dist/config.d.ts +1 -1
  50. package/dist/config.js +6 -78
  51. package/dist/errcorrect.js +8 -68
  52. package/dist/error-Do8Qji43.d.ts +231 -0
  53. package/dist/id/index.d.ts +1 -1
  54. package/dist/id/index.js +14 -65
  55. package/dist/{index-MLrRDvEG.d.ts → index-B-pqGHhU.d.ts} +113 -19
  56. package/dist/{index--C7Mtsmm.d.ts → index-DEyjGoo2.d.ts} +1 -1
  57. package/dist/{index-QSffbLnj.d.ts → index-VLDcI5NF.d.ts} +3 -2
  58. package/dist/index.d.ts +18 -13
  59. package/dist/index.js +40 -5792
  60. package/dist/llm-DYuR7_uX.d.ts +1069 -0
  61. package/dist/llm-anthropic-Cd_I2xXB.d.ts +67 -0
  62. package/dist/llm-anthropic.d.ts +2 -0
  63. package/dist/llm-anthropic.js +13 -0
  64. package/dist/llm-openai-DyFrucmV.d.ts +87 -0
  65. package/dist/llm-openai.d.ts +2 -0
  66. package/dist/llm-openai.js +19 -0
  67. package/dist/llm.d.ts +1 -1
  68. package/dist/llm.js +101 -356
  69. package/dist/mcp/index.d.ts +2 -1
  70. package/dist/mcp/index.js +155 -1453
  71. package/dist/{netpolicy-asvCfwi8.d.ts → netpolicy-Brx5XZUB.d.ts} +16 -3
  72. package/dist/netpolicy.d.ts +1 -1
  73. package/dist/netpolicy.js +25 -118
  74. package/dist/{output-VFFLqor9.d.ts → output-CjZWmL8s.d.ts} +29 -130
  75. package/dist/output.d.ts +2 -1
  76. package/dist/output.js +137 -958
  77. package/dist/progress.js +6 -55
  78. package/dist/provenance.js +6 -31
  79. package/dist/routellm-B0nv59mH.d.ts +111 -0
  80. package/dist/routellm.d.ts +2 -2
  81. package/dist/routellm.js +13 -255
  82. package/dist/{rpc-D5xLEf8V.d.ts → rpc-D31Lg0Kc.d.ts} +1 -1
  83. package/dist/rpc.d.ts +2 -2
  84. package/dist/rpc.js +4 -98
  85. package/dist/safety.js +6 -43
  86. package/dist/scope.js +20 -377
  87. package/dist/serve-D8yWMrTc.d.ts +646 -0
  88. package/dist/serve.d.ts +3 -0
  89. package/dist/serve.js +75 -0
  90. package/dist/sqlstore.js +6 -39
  91. package/dist/stream.js +8 -51
  92. package/dist/telemetry/index.js +24 -608
  93. package/dist/tui/index.d.ts +5 -4
  94. package/dist/tui/index.js +17 -373
  95. package/dist/upgrade.js +6 -114
  96. package/dist/xdg.js +14 -128
  97. package/package.json +135 -25
  98. package/src/README.md +15 -0
  99. package/src/cli.test.ts +56 -1
  100. package/src/cli.ts +24 -4
  101. package/src/completion-values.test.ts +10 -10
  102. package/src/compliance.test.ts +196 -2
  103. package/src/compliance.ts +440 -20
  104. package/src/config.test.ts +187 -1
  105. package/src/config.ts +173 -7
  106. package/src/gen/crud_pb.ts +7 -7
  107. package/src/id/README.md +38 -0
  108. package/src/id/contract.test.ts +1 -1
  109. package/src/id/index.test.ts +1 -1
  110. package/src/id/index.ts +3 -2
  111. package/src/index.test.ts +12 -0
  112. package/src/index.ts +3 -0
  113. package/src/llm-anthropic.conformance.test.ts +1135 -0
  114. package/src/llm-anthropic.test.ts +152 -0
  115. package/src/llm-anthropic.ts +940 -0
  116. package/src/llm-choice-hermetic.test.ts +335 -0
  117. package/src/llm-config.test.ts +232 -0
  118. package/src/llm-config.ts +106 -0
  119. package/src/llm-endpoint.ts +254 -0
  120. package/src/llm-error.ts +17 -0
  121. package/src/llm-errors.ts +152 -0
  122. package/src/llm-file.ts +126 -0
  123. package/src/llm-http.ts +317 -0
  124. package/src/llm-keys.ts +167 -0
  125. package/src/llm-media.conformance.test.ts +87 -0
  126. package/src/llm-media.test.ts +279 -0
  127. package/src/llm-media.ts +322 -0
  128. package/src/llm-openai.conformance.test.ts +407 -0
  129. package/src/llm-openai.test.ts +510 -0
  130. package/src/llm-openai.ts +708 -0
  131. package/src/llm-payload.ts +155 -0
  132. package/src/llm-quote.ts +46 -0
  133. package/src/llm-routellm.conformance.test.ts +44 -0
  134. package/src/llm-toolnames.conformance.test.ts +112 -0
  135. package/src/llm-toolnames.test.ts +132 -0
  136. package/src/llm-toolnames.ts +298 -0
  137. package/src/llm-uri.ts +99 -0
  138. package/src/llm.test.ts +43 -15
  139. package/src/llm.toolcall.test.ts +175 -0
  140. package/src/llm.ts +602 -190
  141. package/src/mcp/README.md +57 -0
  142. package/src/mcp/conformance.test.ts +24 -3
  143. package/src/mcp/dispatch.ts +4 -4
  144. package/src/mcp/identity.test.ts +166 -0
  145. package/src/mcp/identity.ts +72 -0
  146. package/src/mcp/index.ts +6 -0
  147. package/src/mcp/legacy.ts +21 -8
  148. package/src/mcp/mcp.test.ts +14 -4
  149. package/src/mcp/modern-confirm.ts +1 -1
  150. package/src/mcp/modern.ts +12 -11
  151. package/src/mcp/tasks.ts +1 -1
  152. package/src/mcp/types.ts +80 -8
  153. package/src/netpolicy.test.ts +78 -0
  154. package/src/netpolicy.ts +28 -3
  155. package/src/output/README.md +46 -0
  156. package/src/output/builtins.ts +5 -5
  157. package/src/output/error.ts +167 -1
  158. package/src/output/formatters/README.md +50 -0
  159. package/src/output.ts +26 -1
  160. package/src/published-types.test.ts +115 -0
  161. package/src/routellm.test.ts +209 -28
  162. package/src/routellm.toolcall.test.ts +521 -0
  163. package/src/routellm.ts +213 -177
  164. package/src/router/README.md +44 -0
  165. package/src/router/server.test.ts +41 -0
  166. package/src/router/server.ts +11 -0
  167. package/src/safety.test.ts +19 -9
  168. package/src/scope-defaults.json +29 -29
  169. package/src/serve.test.ts +1257 -0
  170. package/src/serve.ts +1665 -0
  171. package/src/telemetry/README.md +48 -0
  172. package/src/telemetry/client.ts +5 -5
  173. package/src/toolspec.test.ts +2 -2
  174. package/src/triton/README.md +34 -0
  175. package/src/tui/README.md +42 -0
  176. package/src/wizard.test.ts +7 -7
  177. package/test/llm/conformance-helpers.ts +100 -0
  178. package/test/output/dispatch.test.ts +1 -2
  179. package/test/output/error.test.ts +38 -2
  180. package/test/output/smoke-capture.ts +2 -2
  181. package/test/output/smoke.test.ts +2 -2
  182. package/test/output/taxonomy-contract.test.ts +148 -0
  183. package/test/setup-env.ts +16 -0
  184. package/tsconfig.json +3 -1
  185. package/tsconfig.test.json +10 -0
  186. package/vitest.config.ts +9 -0
  187. package/dist/llm-B5XUWH8T.d.ts +0 -231
  188. package/dist/routellm-PGSt2D1y.d.ts +0 -75
package/dist/aim.js CHANGED
@@ -1,417 +1,16 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
29
2
 
30
- // src/aim.ts
31
- var aim_exports = {};
32
- __export(aim_exports, {
33
- Cache: () => Cache,
34
- ModelsDevSource: () => ModelsDevSource,
35
- Registry: () => Registry,
36
- normalize: () => normalize,
37
- parseQuery: () => parseQuery
38
- });
39
- module.exports = __toCommonJS(aim_exports);
40
- var fs = __toESM(require("fs"));
41
- var path2 = __toESM(require("path"));
42
3
 
43
- // src/xdg.ts
44
- var os = __toESM(require("os"));
45
- var path = __toESM(require("path"));
46
- function platform(override) {
47
- return override ?? process.platform;
48
- }
49
- function cacheDir(tool, plt) {
50
- const xdg = process.env["XDG_CACHE_HOME"];
51
- if (xdg) return path.join(xdg, tool);
52
- const p = platform(plt);
53
- const home = os.homedir();
54
- switch (p) {
55
- case "darwin":
56
- return path.join(home, "Library", "Caches", tool);
57
- case "win32": {
58
- const local = process.env["LocalAppData"];
59
- if (!local) throw new Error("%LocalAppData% is not set");
60
- return path.win32.join(local, tool, "cache");
61
- }
62
- default:
63
- return path.join(home, ".cache", tool);
64
- }
65
- }
66
4
 
67
- // src/aim.ts
68
- function normalize(m) {
69
- const n = { ...m };
70
- n.input = n.modalities?.input ?? n.input ?? [];
71
- n.output = n.modalities?.output ?? n.output ?? [];
72
- n.context = n.limit?.context ?? n.context ?? 0;
73
- n.maxOutput = n.limit?.output ?? n.maxOutput ?? 0;
74
- n.costInput = n.cost?.input ?? n.costInput ?? 0;
75
- n.costOutput = n.cost?.output ?? n.costOutput ?? 0;
76
- n.tool_call = n.tool_call ?? false;
77
- n.reasoning = n.reasoning ?? false;
78
- n.open_weights = n.open_weights ?? false;
79
- return n;
80
- }
81
- function validateProviders(raw) {
82
- for (const [key, p] of Object.entries(raw)) {
83
- if (key !== p.id)
84
- throw new Error(`aim: map key "${key}" != provider.id "${p.id}"`);
85
- for (const [id, m] of Object.entries(p.models)) {
86
- const normalized = normalize(m);
87
- if (!normalized.provider) normalized.provider = key;
88
- p.models[id] = normalized;
89
- }
90
- }
91
- return raw;
92
- }
93
- var ModelsDevSource = class {
94
- constructor(opts) {
95
- this.url = opts?.url ?? "https://models.dev/api.json";
96
- this.timeout = opts?.timeout ?? 3e4;
97
- this.maxSize = opts?.maxSize ?? 50 * 1024 * 1024;
98
- }
99
- doFetch(headers, signal) {
100
- const ctrl = new AbortController();
101
- const timer = setTimeout(() => ctrl.abort(), this.timeout);
102
- if (signal) signal.addEventListener("abort", () => ctrl.abort(), { once: true });
103
- return { ctrl, timer, promise: globalThis.fetch(this.url, {
104
- headers,
105
- signal: ctrl.signal
106
- }) };
107
- }
108
- async readBody(resp) {
109
- const text = await resp.text();
110
- if (text.length > this.maxSize)
111
- throw new Error(`aim: response exceeds max size (${this.maxSize} bytes)`);
112
- return validateProviders(JSON.parse(text));
113
- }
114
- async fetch(signal) {
115
- const { timer, promise } = this.doFetch({ Accept: "application/json" }, signal);
116
- try {
117
- const resp = await promise;
118
- if (resp.status !== 200)
119
- throw new Error(`aim: unexpected status ${resp.status} from ${this.url}`);
120
- return this.readBody(resp);
121
- } finally {
122
- clearTimeout(timer);
123
- }
124
- }
125
- async fetchWithETag(etag, signal) {
126
- const hdrs = { Accept: "application/json" };
127
- if (etag) hdrs["If-None-Match"] = etag;
128
- const { timer, promise } = this.doFetch(hdrs, signal);
129
- try {
130
- const resp = await promise;
131
- if (resp.status === 304)
132
- return { providers: null, etag, notModified: true };
133
- if (resp.status !== 200)
134
- throw new Error(`aim: unexpected status ${resp.status} from ${this.url}`);
135
- const providers = await this.readBody(resp);
136
- return {
137
- providers,
138
- notModified: false,
139
- etag: resp.headers.get("etag") ?? ""
140
- };
141
- } finally {
142
- clearTimeout(timer);
143
- }
144
- }
145
- };
146
- var DATA_FILE = "providers.json";
147
- var ETAG_FILE = "etag";
148
- var LOCK_FILE = ".lock";
149
- var LOCK_STALE_MS = 3e4;
150
- var LOCK_POLL_MS = 50;
151
- var LOCK_TIMEOUT_MS = 1e4;
152
- function acquireLock(dir) {
153
- const lockPath = path2.join(dir, LOCK_FILE);
154
- const deadline = Date.now() + LOCK_TIMEOUT_MS;
155
- while (true) {
156
- try {
157
- fs.writeFileSync(lockPath, String(process.pid), { flag: "wx" });
158
- return;
159
- } catch {
160
- try {
161
- const stat = fs.statSync(lockPath);
162
- if (Date.now() - stat.mtimeMs > LOCK_STALE_MS) {
163
- fs.unlinkSync(lockPath);
164
- continue;
165
- }
166
- } catch {
167
- continue;
168
- }
169
- if (Date.now() >= deadline)
170
- throw new Error("aim: lock acquisition timed out");
171
- const until = Date.now() + LOCK_POLL_MS;
172
- while (Date.now() < until) {
173
- }
174
- }
175
- }
176
- }
177
- function releaseLock(dir) {
178
- try {
179
- fs.unlinkSync(path2.join(dir, LOCK_FILE));
180
- } catch {
181
- }
182
- }
183
- var Cache = class {
184
- constructor(src, opts) {
185
- this.src = src;
186
- this.ttl = opts?.ttl ?? 864e5;
187
- this.dir = opts?.dir ?? path2.join(cacheDir(""), "hop/aim");
188
- }
189
- async fetch(signal) {
190
- const env = this.load();
191
- if (env && Date.now() - new Date(env.fetched_at).getTime() < this.ttl)
192
- return env.providers;
193
- try {
194
- return await this.refresh(signal);
195
- } catch {
196
- if (env) return env.providers;
197
- throw new Error("aim: fetch failed and no cached data available");
198
- }
199
- }
200
- async forceRefresh(signal) {
201
- return this.refresh(signal);
202
- }
203
- async refresh(signal) {
204
- fs.mkdirSync(this.dir, { recursive: true, mode: 493 });
205
- acquireLock(this.dir);
206
- try {
207
- let providers;
208
- const src = this.src;
209
- if (typeof src.fetchWithETag === "function") {
210
- const etag = this.readFile(ETAG_FILE);
211
- const r = await src.fetchWithETag(etag, signal);
212
- if (r.notModified) {
213
- const env = this.load();
214
- if (env) {
215
- env.fetched_at = (/* @__PURE__ */ new Date()).toISOString();
216
- this.store(env);
217
- return env.providers;
218
- }
219
- }
220
- providers = r.providers ?? await src.fetch(signal);
221
- if (r.etag) this.writeFile(ETAG_FILE, r.etag);
222
- } else {
223
- providers = await src.fetch(signal);
224
- }
225
- this.store({ fetched_at: (/* @__PURE__ */ new Date()).toISOString(), providers });
226
- return providers;
227
- } finally {
228
- releaseLock(this.dir);
229
- }
230
- }
231
- load() {
232
- try {
233
- const env = JSON.parse(
234
- fs.readFileSync(path2.join(this.dir, DATA_FILE), "utf-8")
235
- );
236
- for (const [key, p] of Object.entries(env.providers)) {
237
- for (const [id, m] of Object.entries(p.models)) {
238
- const n = normalize(m);
239
- if (!n.provider) n.provider = key;
240
- p.models[id] = n;
241
- }
242
- }
243
- return env;
244
- } catch {
245
- return null;
246
- }
247
- }
248
- store(env) {
249
- const tmp = path2.join(this.dir, DATA_FILE + ".tmp");
250
- fs.writeFileSync(tmp, JSON.stringify(env), { mode: 420 });
251
- fs.renameSync(tmp, path2.join(this.dir, DATA_FILE));
252
- }
253
- readFile(name) {
254
- try {
255
- return fs.readFileSync(path2.join(this.dir, name), "utf-8");
256
- } catch {
257
- return "";
258
- }
259
- }
260
- writeFile(name, data) {
261
- const tmp = path2.join(this.dir, name + ".tmp");
262
- try {
263
- fs.writeFileSync(tmp, data, { mode: 420 });
264
- fs.renameSync(tmp, path2.join(this.dir, name));
265
- } catch {
266
- }
267
- }
268
- };
269
- function parseQuery(q) {
270
- const f = {};
271
- const free = [];
272
- for (let i = 0, n = q.length; i < n; ) {
273
- if (q[i] === " " || q[i] === " ") {
274
- i++;
275
- continue;
276
- }
277
- let val;
278
- let quoted = false;
279
- if (q[i] === '"') {
280
- const j = q.indexOf('"', i + 1);
281
- if (j < 0) throw new Error("unterminated quote");
282
- val = q.slice(i + 1, j);
283
- quoted = true;
284
- i = j + 1;
285
- } else {
286
- let j = i;
287
- while (j < n && q[j] !== " " && q[j] !== " ") j++;
288
- val = q.slice(i, j);
289
- i = j;
290
- }
291
- if (quoted) {
292
- free.push(val);
293
- continue;
294
- }
295
- const ci = val.indexOf(":");
296
- if (ci < 0) {
297
- free.push(val);
298
- continue;
299
- }
300
- const key = val.slice(0, ci), v = val.slice(ci + 1);
301
- if (key === "") throw new Error(`malformed tag "${val}": missing key`);
302
- if (v === "") throw new Error(`empty value for tag "${key}"`);
303
- switch (key) {
304
- case "provider":
305
- f.provider = csv(f.provider, v);
306
- break;
307
- case "family":
308
- f.family = csv(f.family, v);
309
- break;
310
- case "in":
311
- f.input = csv(f.input, v);
312
- break;
313
- case "out":
314
- f.output = csv(f.output, v);
315
- break;
316
- case "toolcall":
317
- case "reasoning":
318
- case "openweights": {
319
- const b = toBool(v, key);
320
- if (key === "toolcall") f.toolCall = b;
321
- else if (key === "reasoning") f.reasoning = b;
322
- else f.openWeights = b;
323
- break;
324
- }
325
- default:
326
- throw new Error(`unknown tag "${key}"`);
327
- }
328
- }
329
- if (free.length > 0) f.query = free.join(" ");
330
- return f;
331
- }
332
- function toBool(v, tag) {
333
- if (v === "true") return true;
334
- if (v === "false") return false;
335
- throw new Error(`invalid bool value "${v}" for tag "${tag}": must be true or false`);
336
- }
337
- function csv(a, b) {
338
- return a ? a + "," + b : b;
339
- }
340
- var Registry = class {
341
- constructor(opts) {
342
- this.providers = null;
343
- const sources = opts?.sources ?? [new ModelsDevSource()];
344
- const merged = {
345
- async fetch(signal) {
346
- const r = {};
347
- for (const s of sources) Object.assign(r, await s.fetch(signal));
348
- return r;
349
- }
350
- };
351
- this.cache = new Cache(merged, { dir: opts?.cacheDir, ttl: opts?.cacheTTL });
352
- }
353
- async ensure() {
354
- if (this.providers) return;
355
- try {
356
- this.providers = await this.cache.fetch();
357
- } catch {
358
- this.providers = {};
359
- }
360
- }
361
- async refresh() {
362
- this.providers = await this.cache.forceRefresh();
363
- }
364
- async getProviders() {
365
- await this.ensure();
366
- return Object.values(this.providers).sort((a, b) => a.id.localeCompare(b.id));
367
- }
368
- async models(f) {
369
- await this.ensure();
370
- const out = [];
371
- for (const p of Object.values(this.providers))
372
- for (const m of Object.values(p.models))
373
- if (matchesFilter(m, f)) out.push(m);
374
- out.sort((a, b) => a.provider !== b.provider ? (a.provider ?? "").localeCompare(b.provider ?? "") : a.id.localeCompare(b.id));
375
- return out;
376
- }
377
- async get(provider, model) {
378
- await this.ensure();
379
- return this.providers[provider]?.models[model];
380
- }
381
- async query(q) {
382
- return this.models(parseQuery(q));
383
- }
384
- };
385
- function csvMatch(filter, value) {
386
- return filter.split(",").some((v) => v.trim() === value);
387
- }
388
- function matchesFilter(m, f) {
389
- if (f.provider && !csvMatch(f.provider, m.provider)) return false;
390
- if (f.family && !csvMatch(f.family, m.family)) return false;
391
- if (f.input && !modSubset(f.input, m.input)) return false;
392
- if (f.output && !modSubset(f.output, m.output)) return false;
393
- if (f.toolCall !== void 0 && m.tool_call !== f.toolCall) return false;
394
- if (f.reasoning !== void 0 && m.reasoning !== f.reasoning) return false;
395
- if (f.openWeights !== void 0 && m.open_weights !== f.openWeights) return false;
396
- if (f.query) {
397
- const q = f.query.toLowerCase();
398
- if (!m.id.toLowerCase().includes(q) && !m.name.toLowerCase().includes(q)) return false;
399
- }
400
- return true;
401
- }
402
- function modSubset(filter, mods) {
403
- const set = new Set(mods.map((v) => v.toLowerCase().trim()));
404
- for (const w of filter.split(",")) {
405
- const t = w.toLowerCase().trim();
406
- if (t && !set.has(t)) return false;
407
- }
408
- return true;
409
- }
410
- // Annotate the CommonJS export names for ESM import in node:
411
- 0 && (module.exports = {
412
- Cache,
413
- ModelsDevSource,
414
- Registry,
415
- normalize,
416
- parseQuery
417
- });
5
+
6
+
7
+ var _chunkQJVSKKRQjs = require('./chunk-QJVSKKRQ.js');
8
+ require('./chunk-4UE5TCMQ.js');
9
+ require('./chunk-R5U7XKVJ.js');
10
+
11
+
12
+
13
+
14
+
15
+
16
+ exports.Cache = _chunkQJVSKKRQjs.Cache; exports.ModelsDevSource = _chunkQJVSKKRQjs.ModelsDevSource; exports.Registry = _chunkQJVSKKRQjs.Registry; exports.normalize = _chunkQJVSKKRQjs.normalize; exports.parseQuery = _chunkQJVSKKRQjs.parseQuery;
@@ -85,4 +85,4 @@ declare namespace alias {
85
85
  export { type alias_AliasMap as AliasMap, alias_AliasStore as AliasStore, alias_Expander as Expander, type alias_ExpanderConfig as ExpanderConfig, alias_bridgeAliases as bridgeAliases, alias_findCommand as findCommand, alias_findFirstNonFlag as findFirstNonFlag, alias_loadFrom as loadFrom, alias_saveTo as saveTo };
86
86
  }
87
87
 
88
- export { type AliasMap as A, Expander as E, AliasStore as a, type ExpanderConfig as b, alias as c, bridgeAliases as d, findFirstNonFlag as e, findCommand as f, loadFrom as l, saveTo as s };
88
+ export { type AliasMap as A, Expander as E, alias as a, AliasStore as b, type ExpanderConfig as c, bridgeAliases as d, findFirstNonFlag as e, findCommand as f, loadFrom as l, saveTo as s };
package/dist/alias.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  import 'commander';
2
- export { A as AliasMap, a as AliasStore, E as Expander, b as ExpanderConfig, d as bridgeAliases, f as findCommand, e as findFirstNonFlag, l as loadFrom, s as saveTo } from './alias-dhhr08Ei.js';
2
+ export { A as AliasMap, b as AliasStore, E as Expander, c as ExpanderConfig, d as bridgeAliases, f as findCommand, e as findFirstNonFlag, l as loadFrom, s as saveTo } from './alias-BOj0-VAr.js';
package/dist/alias.js CHANGED
@@ -1,207 +1,19 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
29
2
 
30
- // src/alias.ts
31
- var alias_exports = {};
32
- __export(alias_exports, {
33
- AliasStore: () => AliasStore,
34
- Expander: () => Expander,
35
- bridgeAliases: () => bridgeAliases,
36
- findCommand: () => findCommand,
37
- findFirstNonFlag: () => findFirstNonFlag,
38
- loadFrom: () => loadFrom,
39
- saveTo: () => saveTo
40
- });
41
- module.exports = __toCommonJS(alias_exports);
42
- var fs = __toESM(require("fs"));
43
- var path = __toESM(require("path"));
44
- var yaml = __toESM(require("js-yaml"));
45
- var import_commander = require("commander");
46
- function loadFrom(filePath) {
47
- let data;
48
- try {
49
- data = fs.readFileSync(filePath, "utf-8");
50
- } catch {
51
- return {};
52
- }
53
- const raw = yaml.load(data);
54
- if (!raw || typeof raw !== "object" || !raw["aliases"]) return {};
55
- return raw["aliases"];
56
- }
57
- function saveTo(filePath, aliases) {
58
- fs.mkdirSync(path.dirname(filePath), { recursive: true, mode: 488 });
59
- let existing = {};
60
- try {
61
- const data = fs.readFileSync(filePath, "utf-8");
62
- existing = yaml.load(data) ?? {};
63
- } catch {
64
- }
65
- if (Object.keys(aliases).length === 0) {
66
- delete existing["aliases"];
67
- } else {
68
- existing["aliases"] = { ...aliases };
69
- }
70
- fs.writeFileSync(filePath, yaml.dump(existing), { mode: 384 });
71
- }
72
- function findFirstNonFlag(slice) {
73
- for (let i = 0; i < slice.length; i++) {
74
- const a = slice[i];
75
- if (!a.startsWith("-")) return [i, a];
76
- if (a.includes("=")) continue;
77
- if (i + 1 < slice.length && !slice[i + 1].startsWith("-")) {
78
- i++;
79
- }
80
- }
81
- return [-1, ""];
82
- }
83
- var AliasStore = class {
84
- constructor(filePath) {
85
- this.aliases = {};
86
- this.filePath = filePath;
87
- }
88
- load() {
89
- this.aliases = loadFrom(this.filePath);
90
- }
91
- save() {
92
- saveTo(this.filePath, this.aliases);
93
- }
94
- set(name, target) {
95
- this.aliases[name] = target;
96
- }
97
- remove(name) {
98
- delete this.aliases[name];
99
- }
100
- get(name) {
101
- return this.aliases[name];
102
- }
103
- /** Returns a shallow copy. */
104
- all() {
105
- return { ...this.aliases };
106
- }
107
- /** Expand first arg if it matches an alias. */
108
- expand(args) {
109
- if (args.length < 2) return args;
110
- const candidate = args[1];
111
- const expansion = this.aliases[candidate];
112
- if (!expansion) return args;
113
- const parts = expansion.split(/\s+/);
114
- return [args[0], ...parts, ...args.slice(2)];
115
- }
116
- };
117
- var Expander = class {
118
- constructor(cfg) {
119
- this.cfg = cfg;
120
- }
121
- /** Merged alias map (seeded < global < local). */
122
- load() {
123
- const merged = {};
124
- if (this.cfg.seededAliases) {
125
- Object.assign(merged, this.cfg.seededAliases);
126
- }
127
- const global = loadFrom(this.cfg.globalPath);
128
- Object.assign(merged, global);
129
- const local = loadFrom(this.cfg.localPath);
130
- Object.assign(merged, local);
131
- return merged;
132
- }
133
- /**
134
- * Rewrite args if args[1] (or first non-flag arg) matches
135
- * an alias. Returns [rewrittenArgs, wasExpanded].
136
- */
137
- expand(args) {
138
- if (args.length < 2) return [args, false];
139
- const aliases = this.load();
140
- if (Object.keys(aliases).length === 0) return [args, false];
141
- const [firstNonFlag, candidate] = findFirstNonFlag(args.slice(1));
142
- if (candidate === "") return [args, false];
143
- const expansion = aliases[candidate];
144
- if (!expansion) return [args, false];
145
- const parts = expansion.split(/\s+/);
146
- const prefix = args.slice(1, 1 + firstNonFlag);
147
- const suffix = args.slice(1 + firstNonFlag + 1);
148
- const result = [args[0], ...prefix, ...parts, ...suffix];
149
- return [result, true];
150
- }
151
- /** Reject names that shadow builtins or contain whitespace. */
152
- validateName(name) {
153
- if (name === "") {
154
- throw new Error("alias name must not be empty");
155
- }
156
- if (/\s/.test(name)) {
157
- throw new Error("alias name must not contain whitespace");
158
- }
159
- if (this.cfg.builtins?.has(name)) {
160
- throw new Error(`alias "${name}" conflicts with a built-in command`);
161
- }
162
- }
163
- };
164
- function findCommand(program, cmdPath) {
165
- const parts = cmdPath.split(" ");
166
- let cmd = program;
167
- for (const part of parts) {
168
- cmd = cmd?.commands.find((c) => c.name() === part);
169
- if (!cmd) return void 0;
170
- }
171
- return cmd;
172
- }
173
- function bridgeAliases(program, store) {
174
- const all = store.all();
175
- for (const [name, target] of Object.entries(all)) {
176
- const parts = target.split(/\s+/);
177
- if (parts.length === 1) {
178
- const targetCmd = findCommand(program, target);
179
- if (targetCmd) {
180
- targetCmd.alias(name);
181
- continue;
182
- }
183
- }
184
- const proxy = new import_commander.Command(name).description(`Alias for ${target}`).allowUnknownOption(true).allowExcessArguments(true).action(function() {
185
- const expanded = target.split(/\s+/);
186
- program.parse([
187
- "node",
188
- program.name(),
189
- ...expanded,
190
- ...this.args
191
- ]);
192
- });
193
- proxy.helpOption(false);
194
- proxy._hidden = true;
195
- program.addCommand(proxy);
196
- }
197
- }
198
- // Annotate the CommonJS export names for ESM import in node:
199
- 0 && (module.exports = {
200
- AliasStore,
201
- Expander,
202
- bridgeAliases,
203
- findCommand,
204
- findFirstNonFlag,
205
- loadFrom,
206
- saveTo
207
- });
3
+
4
+
5
+
6
+
7
+
8
+
9
+ var _chunkS45UHXQFjs = require('./chunk-S45UHXQF.js');
10
+ require('./chunk-R5U7XKVJ.js');
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+ exports.AliasStore = _chunkS45UHXQFjs.AliasStore; exports.Expander = _chunkS45UHXQFjs.Expander; exports.bridgeAliases = _chunkS45UHXQFjs.bridgeAliases; exports.findCommand = _chunkS45UHXQFjs.findCommand; exports.findFirstNonFlag = _chunkS45UHXQFjs.findFirstNonFlag; exports.loadFrom = _chunkS45UHXQFjs.loadFrom; exports.saveTo = _chunkS45UHXQFjs.saveTo;
@@ -74,4 +74,4 @@ declare namespace api {
74
74
  export { api_APIClient as APIClient, type api_APIClientOptions as APIClientOptions, type api_APIError as APIError, api_APIRequestError as APIRequestError, type api_Entity as Entity, type api_Query as Query, api_WSClient as WSClient, type api_WSMessage as WSMessage };
75
75
  }
76
76
 
77
- export { APIClient as A, type Entity as E, type Query as Q, WSClient as W, type APIClientOptions as a, type APIError as b, APIRequestError as c, type WSMessage as d, api as e };
77
+ export { APIClient as A, type Entity as E, type Query as Q, WSClient as W, api as a, type APIClientOptions as b, type APIError as c, APIRequestError as d, type WSMessage as e };
package/dist/api.d.ts CHANGED
@@ -1 +1 @@
1
- export { A as APIClient, a as APIClientOptions, b as APIError, c as APIRequestError, E as Entity, Q as Query, W as WSClient, d as WSMessage } from './api-miiso81x.js';
1
+ export { A as APIClient, b as APIClientOptions, c as APIError, d as APIRequestError, E as Entity, Q as Query, W as WSClient, e as WSMessage } from './api-DAexsu2H.js';