@hop-top/kit 0.5.0-alpha.1 → 0.5.0-alpha.10

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 (285) hide show
  1. package/CHANGELOG.md +251 -0
  2. package/LICENSE +1 -1
  3. package/LICENSE-cobra.txt +174 -0
  4. package/NOTICE +15 -0
  5. package/README.md +55 -259
  6. package/dist/aim-DZHwwiIc.d.ts +139 -0
  7. package/dist/aim.d.ts +1 -116
  8. package/dist/aim.js +13 -414
  9. package/dist/alias-D9_qFlyP.d.ts +174 -0
  10. package/dist/alias.d.ts +2 -73
  11. package/dist/alias.js +27 -207
  12. package/dist/api-DAexsu2H.d.ts +77 -0
  13. package/dist/api.d.ts +1 -62
  14. package/dist/api.js +10 -164
  15. package/dist/auth-2-jfgiHn.d.ts +34 -0
  16. package/dist/auth.d.ts +1 -26
  17. package/dist/auth.js +6 -40
  18. package/dist/chunk-2JV3A7OP.js +1894 -0
  19. package/dist/chunk-3FIKGFKI.js +54 -0
  20. package/dist/chunk-4UE5TCMQ.js +104 -0
  21. package/dist/chunk-6HFAEZ52.js +29 -0
  22. package/dist/chunk-6SVOHNIC.js +17 -0
  23. package/dist/chunk-72XZWQX7.js +504 -0
  24. package/dist/chunk-ABQSE7AI.js +513 -0
  25. package/dist/chunk-BDNNPRX6.js +41 -0
  26. package/dist/chunk-BLS2OBIQ.js +263 -0
  27. package/dist/chunk-BRNEKPWX.js +37 -0
  28. package/dist/chunk-CSJWB6D3.js +151 -0
  29. package/dist/chunk-GGWJRWWA.js +309 -0
  30. package/dist/chunk-GHPJJV5L.js +613 -0
  31. package/dist/chunk-IXVQ62NZ.js +334 -0
  32. package/dist/chunk-JKMQSAJP.js +174 -0
  33. package/dist/chunk-JZ22ZUFA.js +1131 -0
  34. package/dist/chunk-K7VCKJ27.js +814 -0
  35. package/dist/chunk-KVG7YCTS.js +115 -0
  36. package/dist/chunk-L23O2FFE.js +51 -0
  37. package/dist/chunk-MQXYDYRD.js +968 -0
  38. package/dist/chunk-MUIQVU6E.js +251 -0
  39. package/dist/chunk-NLMS7HGP.js +178 -0
  40. package/dist/chunk-POR5L2DG.js +247 -0
  41. package/dist/chunk-PSFYJGDG.js +1445 -0
  42. package/dist/chunk-QJVSKKRQ.js +369 -0
  43. package/dist/chunk-QPUCXQXT.js +67 -0
  44. package/dist/chunk-QQQYCWSC.js +240 -0
  45. package/dist/chunk-R5U7XKVJ.js +16 -0
  46. package/dist/chunk-SNVGDYX7.js +187 -0
  47. package/dist/chunk-T46YPHKN.js +669 -0
  48. package/dist/chunk-UKZIAQA7.js +26 -0
  49. package/dist/chunk-WBVO43HU.js +355 -0
  50. package/dist/chunk-WUOAQVOA.js +86 -0
  51. package/dist/chunk-WWUKGJB5.js +90 -0
  52. package/dist/chunk-XJTRY453.js +868 -0
  53. package/dist/chunk-YGYQUFGY.js +219 -0
  54. package/dist/chunk-YOBAUCVN.js +583 -0
  55. package/dist/cli-C5B5tnpA.d.ts +400 -0
  56. package/dist/cli.d.ts +7 -309
  57. package/dist/cli.js +70 -945
  58. package/dist/completion-csVun6SP.d.ts +112 -0
  59. package/dist/completion-values-By-mnjNt.d.ts +142 -0
  60. package/dist/completion-values.d.ts +1 -0
  61. package/dist/completion-values.js +29 -0
  62. package/dist/completion.d.ts +3 -0
  63. package/dist/completion.js +34 -0
  64. package/dist/compliance-AxFf-uMy.d.ts +60 -0
  65. package/dist/compliance.d.ts +1 -0
  66. package/dist/compliance.js +17 -0
  67. package/dist/config-CaK60ByQ.d.ts +241 -0
  68. package/dist/config.d.ts +1 -97
  69. package/dist/config.js +8 -78
  70. package/dist/errcorrect-BcX1Ft0K.d.ts +44 -0
  71. package/dist/errcorrect.d.ts +1 -37
  72. package/dist/errcorrect.js +8 -68
  73. package/dist/error-Do8Qji43.d.ts +231 -0
  74. package/dist/id/index.d.ts +2 -83
  75. package/dist/id/index.js +14 -65
  76. package/dist/index-BKJZClJx.d.ts +1486 -0
  77. package/dist/index-C3Zw4wDJ.d.ts +359 -0
  78. package/dist/index-DCe1boBz.d.ts +328 -0
  79. package/dist/index-VLDcI5NF.d.ts +95 -0
  80. package/dist/index.d.ts +37 -0
  81. package/dist/index.js +132 -0
  82. package/dist/llm-DYuR7_uX.d.ts +1069 -0
  83. package/dist/llm-anthropic-Cd_I2xXB.d.ts +67 -0
  84. package/dist/llm-anthropic.d.ts +2 -0
  85. package/dist/llm-anthropic.js +13 -0
  86. package/dist/llm-openai-DyFrucmV.d.ts +87 -0
  87. package/dist/llm-openai.d.ts +2 -0
  88. package/dist/llm-openai.js +19 -0
  89. package/dist/llm.d.ts +1 -188
  90. package/dist/llm.js +101 -356
  91. package/dist/log-CkaxMX3U.d.ts +115 -0
  92. package/dist/log.d.ts +2 -0
  93. package/dist/log.js +14 -0
  94. package/dist/mcp/index.d.ts +4 -0
  95. package/dist/mcp/index.js +184 -0
  96. package/dist/netpolicy-Brx5XZUB.d.ts +151 -0
  97. package/dist/netpolicy.d.ts +1 -0
  98. package/dist/netpolicy.js +25 -0
  99. package/dist/output-CjZWmL8s.d.ts +420 -0
  100. package/dist/output.d.ts +3 -213
  101. package/dist/output.js +137 -447
  102. package/dist/parity-CvMuYcVI.d.ts +61 -0
  103. package/dist/progress-CAzyxeWl.d.ts +38 -0
  104. package/dist/progress.d.ts +1 -30
  105. package/dist/progress.js +6 -55
  106. package/dist/provenance-SMFHm5gx.d.ts +30 -0
  107. package/dist/provenance.d.ts +1 -24
  108. package/dist/provenance.js +6 -31
  109. package/dist/routellm-B0nv59mH.d.ts +111 -0
  110. package/dist/routellm.d.ts +2 -64
  111. package/dist/routellm.js +13 -255
  112. package/dist/rpc-D31Lg0Kc.d.ts +32 -0
  113. package/dist/rpc.d.ts +2 -25
  114. package/dist/rpc.js +4 -98
  115. package/dist/safety-CUaYEjZc.d.ts +30 -0
  116. package/dist/safety.d.ts +1 -24
  117. package/dist/safety.js +6 -43
  118. package/dist/scope-BrhYB4ij.d.ts +141 -0
  119. package/dist/scope.d.ts +1 -121
  120. package/dist/scope.js +20 -377
  121. package/dist/serve-D8yWMrTc.d.ts +646 -0
  122. package/dist/serve.d.ts +3 -0
  123. package/dist/serve.js +75 -0
  124. package/dist/sqlstore.js +6 -39
  125. package/dist/stream-CrjeCp0M.d.ts +44 -0
  126. package/dist/stream.d.ts +1 -35
  127. package/dist/stream.js +8 -51
  128. package/dist/telemetry/index.d.ts +1 -315
  129. package/dist/telemetry/index.js +26 -599
  130. package/dist/toolspec-DcPwwoAZ.d.ts +368 -0
  131. package/dist/toolspec.d.ts +2 -0
  132. package/dist/toolspec.js +37 -0
  133. package/dist/tui/index.d.ts +6 -298
  134. package/dist/tui/index.js +17 -381
  135. package/dist/upgrade-p_zh3pvV.d.ts +102 -0
  136. package/dist/upgrade.d.ts +1 -95
  137. package/dist/upgrade.js +6 -114
  138. package/dist/xdg-DB7Shoib.d.ts +179 -0
  139. package/dist/xdg.d.ts +1 -169
  140. package/dist/xdg.js +14 -128
  141. package/package.json +192 -24
  142. package/src/README.md +15 -0
  143. package/src/alias.conformance.test.ts +250 -0
  144. package/src/alias.test.ts +206 -2
  145. package/src/alias.ts +196 -21
  146. package/src/cli.help-command.test.ts +105 -0
  147. package/src/cli.offline.test.ts +93 -0
  148. package/src/cli.parity.test.ts +192 -0
  149. package/src/cli.test.ts +95 -1
  150. package/src/cli.ts +195 -25
  151. package/src/completion-scripts.ts +16 -0
  152. package/src/completion-values.test.ts +76 -16
  153. package/src/completion-values.ts +170 -66
  154. package/src/completion.conformance.test.ts +297 -0
  155. package/src/completion.test.ts +256 -145
  156. package/src/completion.ts +767 -121
  157. package/src/compliance.test.ts +196 -2
  158. package/src/compliance.ts +440 -20
  159. package/src/config-merge.test.ts +425 -0
  160. package/src/config.test.ts +228 -1
  161. package/src/config.ts +429 -16
  162. package/src/gen/crud_pb.ts +7 -7
  163. package/src/id/README.md +38 -0
  164. package/src/id/contract.test.ts +1 -1
  165. package/src/id/index.test.ts +1 -1
  166. package/src/id/index.ts +3 -2
  167. package/src/index.test.ts +71 -0
  168. package/src/index.ts +46 -0
  169. package/src/llm-anthropic.conformance.test.ts +1135 -0
  170. package/src/llm-anthropic.test.ts +152 -0
  171. package/src/llm-anthropic.ts +940 -0
  172. package/src/llm-choice-hermetic.test.ts +335 -0
  173. package/src/llm-config.test.ts +232 -0
  174. package/src/llm-config.ts +106 -0
  175. package/src/llm-endpoint.ts +254 -0
  176. package/src/llm-error.ts +17 -0
  177. package/src/llm-errors.ts +152 -0
  178. package/src/llm-file.ts +126 -0
  179. package/src/llm-http.ts +317 -0
  180. package/src/llm-keys.ts +167 -0
  181. package/src/llm-media.conformance.test.ts +87 -0
  182. package/src/llm-media.test.ts +279 -0
  183. package/src/llm-media.ts +322 -0
  184. package/src/llm-openai.conformance.test.ts +407 -0
  185. package/src/llm-openai.test.ts +510 -0
  186. package/src/llm-openai.ts +708 -0
  187. package/src/llm-payload.ts +155 -0
  188. package/src/llm-quote.ts +46 -0
  189. package/src/llm-routellm.conformance.test.ts +44 -0
  190. package/src/llm-toolnames.conformance.test.ts +112 -0
  191. package/src/llm-toolnames.test.ts +132 -0
  192. package/src/llm-toolnames.ts +298 -0
  193. package/src/llm-uri.ts +99 -0
  194. package/src/llm.test.ts +43 -15
  195. package/src/llm.toolcall.test.ts +175 -0
  196. package/src/llm.ts +602 -190
  197. package/src/log.parity.test.ts +105 -0
  198. package/src/log.test.ts +270 -1
  199. package/src/log.ts +228 -49
  200. package/src/mcp/README.md +63 -0
  201. package/src/mcp/args-separator.test.ts +164 -0
  202. package/src/mcp/args.test.ts +223 -0
  203. package/src/mcp/args.ts +160 -0
  204. package/src/mcp/audit.test.ts +520 -0
  205. package/src/mcp/audit.ts +70 -0
  206. package/src/mcp/bridge.test.ts +222 -0
  207. package/src/mcp/bridge.ts +291 -0
  208. package/src/mcp/conformance.test.ts +357 -0
  209. package/src/mcp/dispatch.ts +359 -0
  210. package/src/mcp/identity.test.ts +166 -0
  211. package/src/mcp/identity.ts +72 -0
  212. package/src/mcp/index.ts +176 -0
  213. package/src/mcp/legacy-notify.test.ts +59 -0
  214. package/src/mcp/legacy.ts +367 -0
  215. package/src/mcp/mcp.test.ts +707 -0
  216. package/src/mcp/modern-confirm.test.ts +520 -0
  217. package/src/mcp/modern-confirm.ts +484 -0
  218. package/src/mcp/modern.ts +788 -0
  219. package/src/mcp/stdio.test.ts +313 -0
  220. package/src/mcp/stdio.ts +254 -0
  221. package/src/mcp/tasks.ts +82 -0
  222. package/src/mcp/testtree.ts +250 -0
  223. package/src/mcp/toolname.test.ts +147 -0
  224. package/src/mcp/types.ts +689 -0
  225. package/src/netpolicy.test.ts +280 -0
  226. package/src/netpolicy.ts +256 -0
  227. package/src/output/README.md +46 -0
  228. package/src/output/builtins.ts +5 -5
  229. package/src/output/dispatch.ts +10 -2
  230. package/src/output/error.ts +459 -0
  231. package/src/output/formatter.ts +29 -5
  232. package/src/output/formatters/README.md +50 -0
  233. package/src/output/formatters/csv.ts +48 -12
  234. package/src/output/formatters/json.ts +4 -25
  235. package/src/output/formatters/project.ts +34 -0
  236. package/src/output/formatters/table.ts +8 -6
  237. package/src/output/formatters/text.ts +7 -3
  238. package/src/output/formatters/yaml.ts +5 -22
  239. package/src/output/projection.test.ts +298 -0
  240. package/src/output/projection.ts +33 -59
  241. package/src/output/template.ts +11 -21
  242. package/src/output.surface.test.ts +41 -0
  243. package/src/output.ts +64 -3
  244. package/src/published-types.test.ts +133 -0
  245. package/src/routellm.test.ts +209 -28
  246. package/src/routellm.toolcall.test.ts +521 -0
  247. package/src/routellm.ts +213 -177
  248. package/src/router/README.md +44 -0
  249. package/src/router/server.test.ts +41 -0
  250. package/src/router/server.ts +11 -0
  251. package/src/safety.test.ts +19 -9
  252. package/src/scope-defaults.json +29 -29
  253. package/src/serve.test.ts +1257 -0
  254. package/src/serve.ts +1665 -0
  255. package/src/telemetry/README.md +48 -0
  256. package/src/telemetry/client.test.ts +31 -0
  257. package/src/telemetry/client.ts +12 -6
  258. package/src/telemetry/offline.test.ts +64 -0
  259. package/src/toolspec-internal.ts +279 -0
  260. package/src/toolspec-manifest.test.ts +167 -0
  261. package/src/toolspec-manifest.ts +410 -0
  262. package/src/toolspec-spec-schemas.ts +12 -0
  263. package/src/toolspec-spec.test.ts +273 -0
  264. package/src/toolspec-spec.ts +458 -0
  265. package/src/toolspec.from-command.test.ts +350 -0
  266. package/src/toolspec.test.ts +2 -2
  267. package/src/toolspec.ts +222 -0
  268. package/src/triton/README.md +34 -0
  269. package/src/tui/README.md +42 -0
  270. package/src/tui/parity.test.ts +120 -31
  271. package/src/tui/parity.ts +58 -7
  272. package/src/wizard.test.ts +7 -7
  273. package/test/llm/conformance-helpers.ts +100 -0
  274. package/test/output/csv.test.ts +164 -0
  275. package/test/output/dispatch.test.ts +1 -2
  276. package/test/output/error.test.ts +277 -0
  277. package/test/output/smoke-capture.ts +2 -2
  278. package/test/output/smoke.test.ts +2 -2
  279. package/test/output/taxonomy-contract.test.ts +148 -0
  280. package/test/setup-env.ts +16 -0
  281. package/test/toolspec/fixture.ts +79 -0
  282. package/tsconfig.json +3 -1
  283. package/tsconfig.test.json +10 -0
  284. package/vitest.config.ts +9 -0
  285. package/src/tui/parity.json +0 -74
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;
@@ -0,0 +1,174 @@
1
+ import { Command } from 'commander';
2
+
3
+ /**
4
+ * alias.ts — YAML-file-based command alias expansion.
5
+ *
6
+ * Port of Go's cli/alias package. Aliases live in per-tool YAML
7
+ * config files with three-tier priority: seeded < global < local.
8
+ */
9
+
10
+ type AliasMap = Record<string, string>;
11
+ interface ExpanderConfig {
12
+ globalPath: string;
13
+ localPath: string;
14
+ seededAliases?: AliasMap;
15
+ builtins?: Set<string>;
16
+ }
17
+ /** Read aliases from a single YAML config file. */
18
+ declare function loadFrom(filePath: string): AliasMap;
19
+ /** Write aliases into a YAML config file, preserving other keys. */
20
+ declare function saveTo(filePath: string, aliases: AliasMap): void;
21
+ /**
22
+ * Find the first non-flag element in a slice.
23
+ * Returns [index, value]. Flags with `=` are self-contained;
24
+ * short flags without `=` consume the next element as their value.
25
+ */
26
+ declare function findFirstNonFlag(slice: string[]): [number, string];
27
+ /**
28
+ * Simple single-file alias store with load/save, set/get/remove,
29
+ * and first-arg expansion.
30
+ */
31
+ declare class AliasStore {
32
+ private filePath;
33
+ private aliases;
34
+ constructor(filePath: string);
35
+ load(): void;
36
+ save(): void;
37
+ set(name: string, target: string): void;
38
+ remove(name: string): void;
39
+ get(name: string): string | undefined;
40
+ /** Returns a shallow copy. */
41
+ all(): AliasMap;
42
+ /** Expand first arg if it matches an alias. */
43
+ expand(args: string[]): string[];
44
+ }
45
+ /**
46
+ * Three-tier alias expander matching Go's Expander.
47
+ * Priority: seeded < global < local.
48
+ */
49
+ declare class Expander {
50
+ private cfg;
51
+ constructor(cfg: ExpanderConfig);
52
+ /** Merged alias map (seeded < global < local). */
53
+ load(): AliasMap;
54
+ /**
55
+ * Rewrite args if args[1] (or first non-flag arg) matches
56
+ * an alias. Returns [rewrittenArgs, wasExpanded].
57
+ */
58
+ expand(args: string[]): [string[], boolean];
59
+ /**
60
+ * Reject names that shadow builtins or contain whitespace; see
61
+ * {@link validateAliasName}, which needs no config files.
62
+ */
63
+ validateName(name: string): void;
64
+ }
65
+ /** The rule an alias name failed; see {@link validateAliasName}. */
66
+ type AliasNameErrorKind = 'empty' | 'whitespace' | 'builtin' | 'duplicate';
67
+ /** An alias name {@link validateAliasName} refused. */
68
+ declare class AliasNameError extends Error {
69
+ readonly kind: AliasNameErrorKind;
70
+ readonly alias: string;
71
+ /** The existing alias's target, for `duplicate`. */
72
+ readonly target?: string;
73
+ constructor(kind: AliasNameErrorKind, alias: string, target?: string);
74
+ }
75
+ /** What {@link validateAliasName} checks a name against. */
76
+ interface AliasNameRules {
77
+ /** Names an alias must not take: the tool's commands and reserved words. */
78
+ builtins?: Iterable<string>;
79
+ /** The alias map the name would join. */
80
+ existing?: AliasMap;
81
+ }
82
+ /**
83
+ * Check an alias name without a store, config file or command tree.
84
+ * Rules run in order and the first failure throws an
85
+ * {@link AliasNameError}: empty, whitespace (any Unicode White_Space
86
+ * character), builtin, duplicate.
87
+ */
88
+ declare function validateAliasName(name: string, rules?: AliasNameRules): void;
89
+ /**
90
+ * Report alias cycles in `aliases` (name -> target). An alias points at
91
+ * another when the first word of its target is a key of the map. Each
92
+ * cycle is a path starting at its smallest name and ending with it
93
+ * again (`['a', 'b', 'a']`); cycles are sorted by first name. An alias
94
+ * that only leads into a cycle is not part of one.
95
+ */
96
+ declare function detectCycles(aliases: AliasMap): string[][];
97
+ /** Walk the Commander program tree to find a command by space-delimited path. */
98
+ declare function findCommand(program: Command, cmdPath: string): Command | undefined;
99
+ /** Runs an alias proxy in place of its target; `cmd.args` holds every argument after the alias, unparsed. */
100
+ type AliasDispatch = (name: string, target: string, cmd: Command) => void | Promise<void>;
101
+ /**
102
+ * Options for {@link bridgeAliases}. Setting any of them registers every
103
+ * alias as a proxy, a root command named after the alias, even for a
104
+ * single-word target that would otherwise take a Commander alias.
105
+ */
106
+ interface BridgeOptions {
107
+ /** Hide proxies from help. Default true. */
108
+ hidden?: boolean;
109
+ /** A proxy's description, in place of `Alias for <target>`. */
110
+ describe?: (name: string, target: string) => string;
111
+ /**
112
+ * true: the proxy owns -h/--help and shows its own help. false (the
113
+ * default): --help reaches the target, or the dispatch handler.
114
+ */
115
+ helpOption?: boolean;
116
+ /**
117
+ * A handler run instead of the target, or false to register proxies
118
+ * that run nothing (register-only). Default: dispatch the target
119
+ * through the program, like a native subcommand.
120
+ */
121
+ dispatch?: AliasDispatch | false;
122
+ }
123
+ /**
124
+ * Register loaded aliases with Commander's native .alias() API.
125
+ *
126
+ * Simple single-command aliases use Commander's built-in .alias(),
127
+ * giving free completion and help display. Multi-word or unresolved
128
+ * targets get a hidden proxy command that dispatches the expanded
129
+ * args from the program, like a native subcommand. With any
130
+ * {@link BridgeOptions} set, every alias gets a proxy shaped by them.
131
+ *
132
+ * Completion offers each alias at most once. A native alias, or a hidden
133
+ * proxy that dispatches its target or runs nothing, is a stand-in:
134
+ * completion lists it as `alias for <target>` and offers a proxy only
135
+ * its help flag. A visible proxy, or one with a dispatch handler, is a
136
+ * real command and completes like any subcommand, with its own flags,
137
+ * including any added after bridging; a hidden one is not listed.
138
+ *
139
+ * `source` is an {@link AliasStore} or a plain alias map, so aliases
140
+ * can come from any storage.
141
+ *
142
+ * Dispatch reuses Commander's own subcommand dispatch rather than
143
+ * calling parse()/parseAsync() again: re-parsing resets program
144
+ * option values mid-parse and fixes the sync/async mode, whereas
145
+ * dispatch returns the target's result as-is. parseAsync() callers
146
+ * thus await async targets (rejections propagate), and parse()
147
+ * callers keep synchronous throws.
148
+ */
149
+ declare function bridgeAliases(program: Command, source: AliasStore | AliasMap, opts?: BridgeOptions): void;
150
+
151
+ type alias_AliasDispatch = AliasDispatch;
152
+ type alias_AliasMap = AliasMap;
153
+ type alias_AliasNameError = AliasNameError;
154
+ declare const alias_AliasNameError: typeof AliasNameError;
155
+ type alias_AliasNameErrorKind = AliasNameErrorKind;
156
+ type alias_AliasNameRules = AliasNameRules;
157
+ type alias_AliasStore = AliasStore;
158
+ declare const alias_AliasStore: typeof AliasStore;
159
+ type alias_BridgeOptions = BridgeOptions;
160
+ type alias_Expander = Expander;
161
+ declare const alias_Expander: typeof Expander;
162
+ type alias_ExpanderConfig = ExpanderConfig;
163
+ declare const alias_bridgeAliases: typeof bridgeAliases;
164
+ declare const alias_detectCycles: typeof detectCycles;
165
+ declare const alias_findCommand: typeof findCommand;
166
+ declare const alias_findFirstNonFlag: typeof findFirstNonFlag;
167
+ declare const alias_loadFrom: typeof loadFrom;
168
+ declare const alias_saveTo: typeof saveTo;
169
+ declare const alias_validateAliasName: typeof validateAliasName;
170
+ declare namespace alias {
171
+ export { type alias_AliasDispatch as AliasDispatch, type alias_AliasMap as AliasMap, alias_AliasNameError as AliasNameError, type alias_AliasNameErrorKind as AliasNameErrorKind, type alias_AliasNameRules as AliasNameRules, alias_AliasStore as AliasStore, type alias_BridgeOptions as BridgeOptions, alias_Expander as Expander, type alias_ExpanderConfig as ExpanderConfig, alias_bridgeAliases as bridgeAliases, alias_detectCycles as detectCycles, alias_findCommand as findCommand, alias_findFirstNonFlag as findFirstNonFlag, alias_loadFrom as loadFrom, alias_saveTo as saveTo, alias_validateAliasName as validateAliasName };
172
+ }
173
+
174
+ export { type AliasDispatch as A, type BridgeOptions as B, Expander as E, alias as a, type AliasMap as b, AliasNameError as c, type AliasNameErrorKind as d, type AliasNameRules as e, AliasStore as f, type ExpanderConfig as g, bridgeAliases as h, detectCycles as i, findCommand as j, findFirstNonFlag as k, loadFrom as l, saveTo as s, validateAliasName as v };
package/dist/alias.d.ts CHANGED
@@ -1,73 +1,2 @@
1
- import { Command } from 'commander';
2
-
3
- /**
4
- * alias.ts — YAML-file-based command alias expansion.
5
- *
6
- * Port of Go's cli/alias package. Aliases live in per-tool YAML
7
- * config files with three-tier priority: seeded < global < local.
8
- */
9
-
10
- type AliasMap = Record<string, string>;
11
- interface ExpanderConfig {
12
- globalPath: string;
13
- localPath: string;
14
- seededAliases?: AliasMap;
15
- builtins?: Set<string>;
16
- }
17
- /** Read aliases from a single YAML config file. */
18
- declare function loadFrom(filePath: string): AliasMap;
19
- /** Write aliases into a YAML config file, preserving other keys. */
20
- declare function saveTo(filePath: string, aliases: AliasMap): void;
21
- /**
22
- * Find the first non-flag element in a slice.
23
- * Returns [index, value]. Flags with `=` are self-contained;
24
- * short flags without `=` consume the next element as their value.
25
- */
26
- declare function findFirstNonFlag(slice: string[]): [number, string];
27
- /**
28
- * Simple single-file alias store with load/save, set/get/remove,
29
- * and first-arg expansion.
30
- */
31
- declare class AliasStore {
32
- private filePath;
33
- private aliases;
34
- constructor(filePath: string);
35
- load(): void;
36
- save(): void;
37
- set(name: string, target: string): void;
38
- remove(name: string): void;
39
- get(name: string): string | undefined;
40
- /** Returns a shallow copy. */
41
- all(): AliasMap;
42
- /** Expand first arg if it matches an alias. */
43
- expand(args: string[]): string[];
44
- }
45
- /**
46
- * Three-tier alias expander matching Go's Expander.
47
- * Priority: seeded < global < local.
48
- */
49
- declare class Expander {
50
- private cfg;
51
- constructor(cfg: ExpanderConfig);
52
- /** Merged alias map (seeded < global < local). */
53
- load(): AliasMap;
54
- /**
55
- * Rewrite args if args[1] (or first non-flag arg) matches
56
- * an alias. Returns [rewrittenArgs, wasExpanded].
57
- */
58
- expand(args: string[]): [string[], boolean];
59
- /** Reject names that shadow builtins or contain whitespace. */
60
- validateName(name: string): void;
61
- }
62
- /** Walk the Commander program tree to find a command by space-delimited path. */
63
- declare function findCommand(program: Command, cmdPath: string): Command | undefined;
64
- /**
65
- * Register loaded aliases with Commander's native .alias() API.
66
- *
67
- * Simple single-command aliases use Commander's built-in .alias(),
68
- * giving free completion and help display. Multi-word or unresolved
69
- * targets get a hidden proxy command that re-parses with expanded args.
70
- */
71
- declare function bridgeAliases(program: Command, store: AliasStore): void;
72
-
73
- export { type AliasMap, AliasStore, Expander, type ExpanderConfig, bridgeAliases, findCommand, findFirstNonFlag, loadFrom, saveTo };
1
+ import 'commander';
2
+ export { A as AliasDispatch, b as AliasMap, c as AliasNameError, d as AliasNameErrorKind, e as AliasNameRules, f as AliasStore, B as BridgeOptions, E as Expander, g as ExpanderConfig, h as bridgeAliases, i as detectCycles, j as findCommand, k as findFirstNonFlag, l as loadFrom, s as saveTo, v as validateAliasName } from './alias-D9_qFlyP.js';