@hop-top/kit 0.5.0-alpha.3 → 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 (187) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/LICENSE +1 -1
  3. package/README.md +47 -575
  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-DLygZLi9.d.ts → cli-8rfITnv4.d.ts} +13 -4
  46. package/dist/cli.d.ts +4 -4
  47. package/dist/cli.js +50 -1057
  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-DISJKeDu.d.ts → error-Do8Qji43.d.ts} +88 -1
  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-Bc5c7Ty5.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 -15
  59. package/dist/index.js +39 -6722
  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-4aXs91GY.d.ts → output-CjZWmL8s.d.ts} +28 -4
  75. package/dist/output.d.ts +2 -2
  76. package/dist/output.js +137 -971
  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-DE-jscpb.d.ts → serve-D8yWMrTc.d.ts} +2 -2
  88. package/dist/serve.d.ts +2 -2
  89. package/dist/serve.js +75 -1019
  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 -5
  94. package/dist/tui/index.js +17 -374
  95. package/dist/upgrade.js +6 -114
  96. package/dist/xdg.js +14 -128
  97. package/package.json +130 -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 +2 -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 +144 -1
  158. package/src/output/formatters/README.md +50 -0
  159. package/src/output.ts +24 -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.ts +1 -1
  170. package/src/telemetry/README.md +48 -0
  171. package/src/telemetry/client.ts +5 -5
  172. package/src/toolspec.test.ts +2 -2
  173. package/src/triton/README.md +34 -0
  174. package/src/tui/README.md +42 -0
  175. package/src/wizard.test.ts +7 -7
  176. package/test/llm/conformance-helpers.ts +100 -0
  177. package/test/output/dispatch.test.ts +1 -2
  178. package/test/output/error.test.ts +33 -2
  179. package/test/output/smoke-capture.ts +2 -2
  180. package/test/output/smoke.test.ts +2 -2
  181. package/test/output/taxonomy-contract.test.ts +148 -0
  182. package/test/setup-env.ts +16 -0
  183. package/tsconfig.json +3 -1
  184. package/tsconfig.test.json +10 -0
  185. package/vitest.config.ts +9 -0
  186. package/dist/llm-B5XUWH8T.d.ts +0 -231
  187. package/dist/routellm-PGSt2D1y.d.ts +0 -75
@@ -0,0 +1,369 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await 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
+ var _chunk4UE5TCMQjs = require('./chunk-4UE5TCMQ.js');
4
+
5
+
6
+ var _chunkR5U7XKVJjs = require('./chunk-R5U7XKVJ.js');
7
+
8
+ // src/aim.ts
9
+ var aim_exports = {};
10
+ _chunkR5U7XKVJjs.__export.call(void 0, aim_exports, {
11
+ Cache: () => Cache,
12
+ ModelsDevSource: () => ModelsDevSource,
13
+ Registry: () => Registry,
14
+ normalize: () => normalize,
15
+ parseQuery: () => parseQuery
16
+ });
17
+ var _fs = require('fs'); var fs = _interopRequireWildcard(_fs);
18
+ var _path = require('path'); var path = _interopRequireWildcard(_path);
19
+ function normalize(m) {
20
+ const n = { ...m };
21
+ n.input = _nullishCoalesce(_nullishCoalesce(_optionalChain([n, 'access', _ => _.modalities, 'optionalAccess', _2 => _2.input]), () => ( n.input)), () => ( []));
22
+ n.output = _nullishCoalesce(_nullishCoalesce(_optionalChain([n, 'access', _3 => _3.modalities, 'optionalAccess', _4 => _4.output]), () => ( n.output)), () => ( []));
23
+ n.context = _nullishCoalesce(_nullishCoalesce(_optionalChain([n, 'access', _5 => _5.limit, 'optionalAccess', _6 => _6.context]), () => ( n.context)), () => ( 0));
24
+ n.maxOutput = _nullishCoalesce(_nullishCoalesce(_optionalChain([n, 'access', _7 => _7.limit, 'optionalAccess', _8 => _8.output]), () => ( n.maxOutput)), () => ( 0));
25
+ n.costInput = _nullishCoalesce(_nullishCoalesce(_optionalChain([n, 'access', _9 => _9.cost, 'optionalAccess', _10 => _10.input]), () => ( n.costInput)), () => ( 0));
26
+ n.costOutput = _nullishCoalesce(_nullishCoalesce(_optionalChain([n, 'access', _11 => _11.cost, 'optionalAccess', _12 => _12.output]), () => ( n.costOutput)), () => ( 0));
27
+ n.tool_call = _nullishCoalesce(n.tool_call, () => ( false));
28
+ n.reasoning = _nullishCoalesce(n.reasoning, () => ( false));
29
+ n.open_weights = _nullishCoalesce(n.open_weights, () => ( false));
30
+ return n;
31
+ }
32
+ function validateProviders(raw) {
33
+ for (const [key, p] of Object.entries(raw)) {
34
+ if (key !== p.id)
35
+ throw new Error(`aim: map key "${key}" != provider.id "${p.id}"`);
36
+ for (const [id, m] of Object.entries(p.models)) {
37
+ const normalized = normalize(m);
38
+ if (!normalized.provider) normalized.provider = key;
39
+ p.models[id] = normalized;
40
+ }
41
+ }
42
+ return raw;
43
+ }
44
+ var ModelsDevSource = class {
45
+ constructor(opts) {
46
+ this.url = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _13 => _13.url]), () => ( "https://models.dev/api.json"));
47
+ this.timeout = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _14 => _14.timeout]), () => ( 3e4));
48
+ this.maxSize = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _15 => _15.maxSize]), () => ( 50 * 1024 * 1024));
49
+ }
50
+ doFetch(headers, signal) {
51
+ const ctrl = new AbortController();
52
+ const timer = setTimeout(() => ctrl.abort(), this.timeout);
53
+ if (signal) signal.addEventListener("abort", () => ctrl.abort(), { once: true });
54
+ return { ctrl, timer, promise: globalThis.fetch(this.url, {
55
+ headers,
56
+ signal: ctrl.signal
57
+ }) };
58
+ }
59
+ async readBody(resp) {
60
+ const text = await resp.text();
61
+ if (text.length > this.maxSize)
62
+ throw new Error(`aim: response exceeds max size (${this.maxSize} bytes)`);
63
+ return validateProviders(JSON.parse(text));
64
+ }
65
+ async fetch(signal) {
66
+ const { timer, promise } = this.doFetch({ Accept: "application/json" }, signal);
67
+ try {
68
+ const resp = await promise;
69
+ if (resp.status !== 200)
70
+ throw new Error(`aim: unexpected status ${resp.status} from ${this.url}`);
71
+ return this.readBody(resp);
72
+ } finally {
73
+ clearTimeout(timer);
74
+ }
75
+ }
76
+ async fetchWithETag(etag, signal) {
77
+ const hdrs = { Accept: "application/json" };
78
+ if (etag) hdrs["If-None-Match"] = etag;
79
+ const { timer, promise } = this.doFetch(hdrs, signal);
80
+ try {
81
+ const resp = await promise;
82
+ if (resp.status === 304)
83
+ return { providers: null, etag, notModified: true };
84
+ if (resp.status !== 200)
85
+ throw new Error(`aim: unexpected status ${resp.status} from ${this.url}`);
86
+ const providers = await this.readBody(resp);
87
+ return {
88
+ providers,
89
+ notModified: false,
90
+ etag: _nullishCoalesce(resp.headers.get("etag"), () => ( ""))
91
+ };
92
+ } finally {
93
+ clearTimeout(timer);
94
+ }
95
+ }
96
+ };
97
+ var DATA_FILE = "providers.json";
98
+ var ETAG_FILE = "etag";
99
+ var LOCK_FILE = ".lock";
100
+ var LOCK_STALE_MS = 3e4;
101
+ var LOCK_POLL_MS = 50;
102
+ var LOCK_TIMEOUT_MS = 1e4;
103
+ function acquireLock(dir) {
104
+ const lockPath = path.join(dir, LOCK_FILE);
105
+ const deadline = Date.now() + LOCK_TIMEOUT_MS;
106
+ while (true) {
107
+ try {
108
+ fs.writeFileSync(lockPath, String(process.pid), { flag: "wx" });
109
+ return;
110
+ } catch (e) {
111
+ try {
112
+ const stat = fs.statSync(lockPath);
113
+ if (Date.now() - stat.mtimeMs > LOCK_STALE_MS) {
114
+ fs.unlinkSync(lockPath);
115
+ continue;
116
+ }
117
+ } catch (e2) {
118
+ continue;
119
+ }
120
+ if (Date.now() >= deadline)
121
+ throw new Error("aim: lock acquisition timed out");
122
+ const until = Date.now() + LOCK_POLL_MS;
123
+ while (Date.now() < until) {
124
+ }
125
+ }
126
+ }
127
+ }
128
+ function releaseLock(dir) {
129
+ try {
130
+ fs.unlinkSync(path.join(dir, LOCK_FILE));
131
+ } catch (e3) {
132
+ }
133
+ }
134
+ var Cache = class {
135
+ constructor(src, opts) {
136
+ this.src = src;
137
+ this.ttl = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _16 => _16.ttl]), () => ( 864e5));
138
+ this.dir = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _17 => _17.dir]), () => ( path.join(_chunk4UE5TCMQjs.cacheDir.call(void 0, ""), "hop/aim")));
139
+ }
140
+ async fetch(signal) {
141
+ const env = this.load();
142
+ if (env && Date.now() - new Date(env.fetched_at).getTime() < this.ttl)
143
+ return env.providers;
144
+ try {
145
+ return await this.refresh(signal);
146
+ } catch (e4) {
147
+ if (env) return env.providers;
148
+ throw new Error("aim: fetch failed and no cached data available");
149
+ }
150
+ }
151
+ async forceRefresh(signal) {
152
+ return this.refresh(signal);
153
+ }
154
+ async refresh(signal) {
155
+ fs.mkdirSync(this.dir, { recursive: true, mode: 493 });
156
+ acquireLock(this.dir);
157
+ try {
158
+ let providers;
159
+ const src = this.src;
160
+ if (typeof src.fetchWithETag === "function") {
161
+ const etag = this.readFile(ETAG_FILE);
162
+ const r = await src.fetchWithETag(etag, signal);
163
+ if (r.notModified) {
164
+ const env = this.load();
165
+ if (env) {
166
+ env.fetched_at = (/* @__PURE__ */ new Date()).toISOString();
167
+ this.store(env);
168
+ return env.providers;
169
+ }
170
+ }
171
+ providers = await _asyncNullishCoalesce(r.providers, async () => ( await src.fetch(signal)));
172
+ if (r.etag) this.writeFile(ETAG_FILE, r.etag);
173
+ } else {
174
+ providers = await src.fetch(signal);
175
+ }
176
+ this.store({ fetched_at: (/* @__PURE__ */ new Date()).toISOString(), providers });
177
+ return providers;
178
+ } finally {
179
+ releaseLock(this.dir);
180
+ }
181
+ }
182
+ load() {
183
+ try {
184
+ const env = JSON.parse(
185
+ fs.readFileSync(path.join(this.dir, DATA_FILE), "utf-8")
186
+ );
187
+ for (const [key, p] of Object.entries(env.providers)) {
188
+ for (const [id, m] of Object.entries(p.models)) {
189
+ const n = normalize(m);
190
+ if (!n.provider) n.provider = key;
191
+ p.models[id] = n;
192
+ }
193
+ }
194
+ return env;
195
+ } catch (e5) {
196
+ return null;
197
+ }
198
+ }
199
+ store(env) {
200
+ const tmp = path.join(this.dir, DATA_FILE + ".tmp");
201
+ fs.writeFileSync(tmp, JSON.stringify(env), { mode: 420 });
202
+ fs.renameSync(tmp, path.join(this.dir, DATA_FILE));
203
+ }
204
+ readFile(name) {
205
+ try {
206
+ return fs.readFileSync(path.join(this.dir, name), "utf-8");
207
+ } catch (e6) {
208
+ return "";
209
+ }
210
+ }
211
+ writeFile(name, data) {
212
+ const tmp = path.join(this.dir, name + ".tmp");
213
+ try {
214
+ fs.writeFileSync(tmp, data, { mode: 420 });
215
+ fs.renameSync(tmp, path.join(this.dir, name));
216
+ } catch (e7) {
217
+ }
218
+ }
219
+ };
220
+ function parseQuery(q) {
221
+ const f = {};
222
+ const free = [];
223
+ for (let i = 0, n = q.length; i < n; ) {
224
+ if (q[i] === " " || q[i] === " ") {
225
+ i++;
226
+ continue;
227
+ }
228
+ let val;
229
+ let quoted = false;
230
+ if (q[i] === '"') {
231
+ const j = q.indexOf('"', i + 1);
232
+ if (j < 0) throw new Error("unterminated quote");
233
+ val = q.slice(i + 1, j);
234
+ quoted = true;
235
+ i = j + 1;
236
+ } else {
237
+ let j = i;
238
+ while (j < n && q[j] !== " " && q[j] !== " ") j++;
239
+ val = q.slice(i, j);
240
+ i = j;
241
+ }
242
+ if (quoted) {
243
+ free.push(val);
244
+ continue;
245
+ }
246
+ const ci = val.indexOf(":");
247
+ if (ci < 0) {
248
+ free.push(val);
249
+ continue;
250
+ }
251
+ const key = val.slice(0, ci), v = val.slice(ci + 1);
252
+ if (key === "") throw new Error(`malformed tag "${val}": missing key`);
253
+ if (v === "") throw new Error(`empty value for tag "${key}"`);
254
+ switch (key) {
255
+ case "provider":
256
+ f.provider = csv(f.provider, v);
257
+ break;
258
+ case "family":
259
+ f.family = csv(f.family, v);
260
+ break;
261
+ case "in":
262
+ f.input = csv(f.input, v);
263
+ break;
264
+ case "out":
265
+ f.output = csv(f.output, v);
266
+ break;
267
+ case "toolcall":
268
+ case "reasoning":
269
+ case "openweights": {
270
+ const b = toBool(v, key);
271
+ if (key === "toolcall") f.toolCall = b;
272
+ else if (key === "reasoning") f.reasoning = b;
273
+ else f.openWeights = b;
274
+ break;
275
+ }
276
+ default:
277
+ throw new Error(`unknown tag "${key}"`);
278
+ }
279
+ }
280
+ if (free.length > 0) f.query = free.join(" ");
281
+ return f;
282
+ }
283
+ function toBool(v, tag) {
284
+ if (v === "true") return true;
285
+ if (v === "false") return false;
286
+ throw new Error(`invalid bool value "${v}" for tag "${tag}": must be true or false`);
287
+ }
288
+ function csv(a, b) {
289
+ return a ? a + "," + b : b;
290
+ }
291
+ var Registry = class {
292
+ constructor(opts) {
293
+ this.providers = null;
294
+ const sources = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _18 => _18.sources]), () => ( [new ModelsDevSource()]));
295
+ const merged = {
296
+ async fetch(signal) {
297
+ const r = {};
298
+ for (const s of sources) Object.assign(r, await s.fetch(signal));
299
+ return r;
300
+ }
301
+ };
302
+ this.cache = new Cache(merged, { dir: _optionalChain([opts, 'optionalAccess', _19 => _19.cacheDir]), ttl: _optionalChain([opts, 'optionalAccess', _20 => _20.cacheTTL]) });
303
+ }
304
+ async ensure() {
305
+ if (this.providers) return;
306
+ try {
307
+ this.providers = await this.cache.fetch();
308
+ } catch (e8) {
309
+ this.providers = {};
310
+ }
311
+ }
312
+ async refresh() {
313
+ this.providers = await this.cache.forceRefresh();
314
+ }
315
+ async getProviders() {
316
+ await this.ensure();
317
+ return Object.values(this.providers).sort((a, b) => a.id.localeCompare(b.id));
318
+ }
319
+ async models(f) {
320
+ await this.ensure();
321
+ const out = [];
322
+ for (const p of Object.values(this.providers))
323
+ for (const m of Object.values(p.models))
324
+ if (matchesFilter(m, f)) out.push(m);
325
+ out.sort((a, b) => a.provider !== b.provider ? (_nullishCoalesce(a.provider, () => ( ""))).localeCompare(_nullishCoalesce(b.provider, () => ( ""))) : a.id.localeCompare(b.id));
326
+ return out;
327
+ }
328
+ async get(provider, model) {
329
+ await this.ensure();
330
+ return _optionalChain([this, 'access', _21 => _21.providers, 'access', _22 => _22[provider], 'optionalAccess', _23 => _23.models, 'access', _24 => _24[model]]);
331
+ }
332
+ async query(q) {
333
+ return this.models(parseQuery(q));
334
+ }
335
+ };
336
+ function csvMatch(filter, value) {
337
+ return filter.split(",").some((v) => v.trim() === value);
338
+ }
339
+ function matchesFilter(m, f) {
340
+ if (f.provider && !csvMatch(f.provider, m.provider)) return false;
341
+ if (f.family && !csvMatch(f.family, m.family)) return false;
342
+ if (f.input && !modSubset(f.input, m.input)) return false;
343
+ if (f.output && !modSubset(f.output, m.output)) return false;
344
+ if (f.toolCall !== void 0 && m.tool_call !== f.toolCall) return false;
345
+ if (f.reasoning !== void 0 && m.reasoning !== f.reasoning) return false;
346
+ if (f.openWeights !== void 0 && m.open_weights !== f.openWeights) return false;
347
+ if (f.query) {
348
+ const q = f.query.toLowerCase();
349
+ if (!m.id.toLowerCase().includes(q) && !m.name.toLowerCase().includes(q)) return false;
350
+ }
351
+ return true;
352
+ }
353
+ function modSubset(filter, mods) {
354
+ const set = new Set(mods.map((v) => v.toLowerCase().trim()));
355
+ for (const w of filter.split(",")) {
356
+ const t = w.toLowerCase().trim();
357
+ if (t && !set.has(t)) return false;
358
+ }
359
+ return true;
360
+ }
361
+
362
+
363
+
364
+
365
+
366
+
367
+
368
+
369
+ exports.normalize = normalize; exports.ModelsDevSource = ModelsDevSource; exports.Cache = Cache; exports.parseQuery = parseQuery; exports.Registry = Registry; exports.aim_exports = aim_exports;
@@ -0,0 +1,67 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// ../../contracts/parity/parity.json
2
+ var parity_default = {
3
+ $schema: "https://json-schema.org/draft/2020-12/schema",
4
+ $id: "https://hop.top/kit/go/console/tui/parity.json",
5
+ description: "Cross-language TUI parity constants. All language implementations MUST load values from here.",
6
+ status: {
7
+ description: "Prefix symbols for status lines. Mirrors Go's InfoType constants in tui/status.go.",
8
+ symbols: {
9
+ info: "\u2139",
10
+ success: "\u2713",
11
+ error: "\u25CF",
12
+ warn: "\u25B2"
13
+ }
14
+ },
15
+ spinner: {
16
+ description: "Braille dot spinner frames and timing.",
17
+ frames: ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"],
18
+ interval_ms: 80
19
+ },
20
+ anim: {
21
+ description: "Gradient character-scramble animation constants.",
22
+ runes: "0123456789abcdefABCDEF~!@#$%^&*()+=_",
23
+ interval_ms: 100,
24
+ default_width: 10
25
+ },
26
+ help: {
27
+ description: "Root --help layout contract. Fang is canonical; TS and Python mirror it.",
28
+ section_order: ["commands", "flags"],
29
+ sections: {
30
+ usage: { title: "USAGE" },
31
+ commands: { title: "COMMANDS" },
32
+ flags: { title: "FLAGS" },
33
+ "global flags": { title: "GLOBAL FLAGS" },
34
+ arguments: { title: "ARGUMENTS" },
35
+ aliases: { title: "ALIASES" },
36
+ examples: { title: "EXAMPLES" },
37
+ streams: { title: "STREAMS" }
38
+ }
39
+ },
40
+ verbosity: {
41
+ description: "Stackable -V flag maps count to log level. --quiet overrides to warn.",
42
+ flag: "-V",
43
+ levels: {
44
+ "0": "info",
45
+ "1": "debug",
46
+ "2": "trace"
47
+ },
48
+ quiet_override: "warn"
49
+ },
50
+ streams: {
51
+ description: "Per-command named output streams toggled via --stream flag.",
52
+ flag: "--stream",
53
+ label_format: "[{name}]",
54
+ output: "stderr"
55
+ },
56
+ extends: [
57
+ "scope-defaults.json",
58
+ "serve.json"
59
+ ]
60
+ };
61
+
62
+ // src/tui/parity.ts
63
+ var parity = parity_default;
64
+
65
+
66
+
67
+ exports.parity = parity;
@@ -0,0 +1,16 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var __defProp = Object.defineProperty;
2
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
4
+ }) : x)(function(x) {
5
+ if (typeof require !== "undefined") return require.apply(this, arguments);
6
+ throw Error('Dynamic require of "' + x + '" is not supported');
7
+ });
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+
13
+
14
+
15
+
16
+ exports.__require = __require; exports.__export = __export;
@@ -0,0 +1,182 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } 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
+ var _chunkR5U7XKVJjs = require('./chunk-R5U7XKVJ.js');
4
+
5
+ // src/alias.ts
6
+ var alias_exports = {};
7
+ _chunkR5U7XKVJjs.__export.call(void 0, alias_exports, {
8
+ AliasStore: () => AliasStore,
9
+ Expander: () => Expander,
10
+ bridgeAliases: () => bridgeAliases,
11
+ findCommand: () => findCommand,
12
+ findFirstNonFlag: () => findFirstNonFlag,
13
+ loadFrom: () => loadFrom,
14
+ saveTo: () => saveTo
15
+ });
16
+ var _fs = require('fs'); var fs = _interopRequireWildcard(_fs);
17
+ var _path = require('path'); var path = _interopRequireWildcard(_path);
18
+ var _jsyaml = require('js-yaml'); var yaml = _interopRequireWildcard(_jsyaml);
19
+ var _commander = require('commander');
20
+ function loadFrom(filePath) {
21
+ let data;
22
+ try {
23
+ data = fs.readFileSync(filePath, "utf-8");
24
+ } catch (e) {
25
+ return {};
26
+ }
27
+ const raw = yaml.load(data);
28
+ if (!raw || typeof raw !== "object" || !raw["aliases"]) return {};
29
+ return raw["aliases"];
30
+ }
31
+ function saveTo(filePath, aliases) {
32
+ fs.mkdirSync(path.dirname(filePath), { recursive: true, mode: 488 });
33
+ let existing = {};
34
+ try {
35
+ const data = fs.readFileSync(filePath, "utf-8");
36
+ existing = _nullishCoalesce(yaml.load(data), () => ( {}));
37
+ } catch (e2) {
38
+ }
39
+ if (Object.keys(aliases).length === 0) {
40
+ delete existing["aliases"];
41
+ } else {
42
+ existing["aliases"] = { ...aliases };
43
+ }
44
+ fs.writeFileSync(filePath, yaml.dump(existing), { mode: 384 });
45
+ }
46
+ function findFirstNonFlag(slice) {
47
+ for (let i = 0; i < slice.length; i++) {
48
+ const a = slice[i];
49
+ if (!a.startsWith("-")) return [i, a];
50
+ if (a.includes("=")) continue;
51
+ if (i + 1 < slice.length && !slice[i + 1].startsWith("-")) {
52
+ i++;
53
+ }
54
+ }
55
+ return [-1, ""];
56
+ }
57
+ var AliasStore = class {
58
+ constructor(filePath) {
59
+ this.aliases = {};
60
+ this.filePath = filePath;
61
+ }
62
+ load() {
63
+ this.aliases = loadFrom(this.filePath);
64
+ }
65
+ save() {
66
+ saveTo(this.filePath, this.aliases);
67
+ }
68
+ set(name, target) {
69
+ this.aliases[name] = target;
70
+ }
71
+ remove(name) {
72
+ delete this.aliases[name];
73
+ }
74
+ get(name) {
75
+ return this.aliases[name];
76
+ }
77
+ /** Returns a shallow copy. */
78
+ all() {
79
+ return { ...this.aliases };
80
+ }
81
+ /** Expand first arg if it matches an alias. */
82
+ expand(args) {
83
+ if (args.length < 2) return args;
84
+ const candidate = args[1];
85
+ const expansion = this.aliases[candidate];
86
+ if (!expansion) return args;
87
+ const parts = expansion.split(/\s+/);
88
+ return [args[0], ...parts, ...args.slice(2)];
89
+ }
90
+ };
91
+ var Expander = class {
92
+ constructor(cfg) {
93
+ this.cfg = cfg;
94
+ }
95
+ /** Merged alias map (seeded < global < local). */
96
+ load() {
97
+ const merged = {};
98
+ if (this.cfg.seededAliases) {
99
+ Object.assign(merged, this.cfg.seededAliases);
100
+ }
101
+ const global = loadFrom(this.cfg.globalPath);
102
+ Object.assign(merged, global);
103
+ const local = loadFrom(this.cfg.localPath);
104
+ Object.assign(merged, local);
105
+ return merged;
106
+ }
107
+ /**
108
+ * Rewrite args if args[1] (or first non-flag arg) matches
109
+ * an alias. Returns [rewrittenArgs, wasExpanded].
110
+ */
111
+ expand(args) {
112
+ if (args.length < 2) return [args, false];
113
+ const aliases = this.load();
114
+ if (Object.keys(aliases).length === 0) return [args, false];
115
+ const [firstNonFlag, candidate] = findFirstNonFlag(args.slice(1));
116
+ if (candidate === "") return [args, false];
117
+ const expansion = aliases[candidate];
118
+ if (!expansion) return [args, false];
119
+ const parts = expansion.split(/\s+/);
120
+ const prefix = args.slice(1, 1 + firstNonFlag);
121
+ const suffix = args.slice(1 + firstNonFlag + 1);
122
+ const result = [args[0], ...prefix, ...parts, ...suffix];
123
+ return [result, true];
124
+ }
125
+ /** Reject names that shadow builtins or contain whitespace. */
126
+ validateName(name) {
127
+ if (name === "") {
128
+ throw new Error("alias name must not be empty");
129
+ }
130
+ if (/\s/.test(name)) {
131
+ throw new Error("alias name must not contain whitespace");
132
+ }
133
+ if (_optionalChain([this, 'access', _ => _.cfg, 'access', _2 => _2.builtins, 'optionalAccess', _3 => _3.has, 'call', _4 => _4(name)])) {
134
+ throw new Error(`alias "${name}" conflicts with a built-in command`);
135
+ }
136
+ }
137
+ };
138
+ function findCommand(program, cmdPath) {
139
+ const parts = cmdPath.split(" ");
140
+ let cmd = program;
141
+ for (const part of parts) {
142
+ cmd = _optionalChain([cmd, 'optionalAccess', _5 => _5.commands, 'access', _6 => _6.find, 'call', _7 => _7((c) => c.name() === part)]);
143
+ if (!cmd) return void 0;
144
+ }
145
+ return cmd;
146
+ }
147
+ function bridgeAliases(program, store) {
148
+ const all = store.all();
149
+ for (const [name, target] of Object.entries(all)) {
150
+ const parts = target.split(/\s+/);
151
+ if (parts.length === 1) {
152
+ const targetCmd = findCommand(program, target);
153
+ if (targetCmd) {
154
+ targetCmd.alias(name);
155
+ continue;
156
+ }
157
+ }
158
+ const proxy = new (0, _commander.Command)(name).description(`Alias for ${target}`).allowUnknownOption(true).allowExcessArguments(true).action(function() {
159
+ const expanded = target.split(/\s+/);
160
+ program.parse([
161
+ "node",
162
+ program.name(),
163
+ ...expanded,
164
+ ...this.args
165
+ ]);
166
+ });
167
+ proxy.helpOption(false);
168
+ proxy._hidden = true;
169
+ program.addCommand(proxy);
170
+ }
171
+ }
172
+
173
+
174
+
175
+
176
+
177
+
178
+
179
+
180
+
181
+
182
+ exports.loadFrom = loadFrom; exports.saveTo = saveTo; exports.findFirstNonFlag = findFirstNonFlag; exports.AliasStore = AliasStore; exports.Expander = Expander; exports.findCommand = findCommand; exports.bridgeAliases = bridgeAliases; exports.alias_exports = alias_exports;