@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
@@ -1,30 +1 @@
1
- /**
2
- * @module progress
3
- * @package @hop-top/kit
4
- *
5
- * Factor 9 — Observable Long-Running Operations.
6
- *
7
- * Emits structured progress events (JSON in non-TTY,
8
- * human-readable in TTY).
9
- */
10
- interface ProgressEvent {
11
- phase: string;
12
- step: string;
13
- current: number;
14
- total: number;
15
- percent: number;
16
- message?: string;
17
- }
18
- interface JobHandle {
19
- id: string;
20
- status: 'running' | 'completed' | 'failed' | 'cancelled';
21
- }
22
- declare class ProgressReporter {
23
- private w;
24
- private tty;
25
- constructor(w: NodeJS.WritableStream, isTTY: boolean);
26
- emit(event: ProgressEvent): void;
27
- done(message: string): void;
28
- }
29
-
30
- export { type JobHandle, type ProgressEvent, ProgressReporter };
1
+ export { J as JobHandle, P as ProgressEvent, a as ProgressReporter } from './progress-CAzyxeWl.js';
package/dist/progress.js CHANGED
@@ -1,56 +1,7 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
19
2
 
20
- // src/progress.ts
21
- var progress_exports = {};
22
- __export(progress_exports, {
23
- ProgressReporter: () => ProgressReporter
24
- });
25
- module.exports = __toCommonJS(progress_exports);
26
- var ProgressReporter = class {
27
- constructor(w, isTTY) {
28
- this.w = w;
29
- this.tty = isTTY;
30
- }
31
- emit(event) {
32
- if (this.tty) {
33
- const msg = event.message ? ` ${event.message}` : "";
34
- this.w.write(
35
- `[${event.phase}] ${event.step} ${event.current}/${event.total} (${event.percent}%)${msg}
36
- `
37
- );
38
- return;
39
- }
40
- this.w.write(JSON.stringify(event) + "\n");
41
- }
42
- done(message) {
43
- if (this.tty) {
44
- this.w.write(`done: ${message}
45
- `);
46
- return;
47
- }
48
- this.w.write(
49
- JSON.stringify({ done: true, message }) + "\n"
50
- );
51
- }
52
- };
53
- // Annotate the CommonJS export names for ESM import in node:
54
- 0 && (module.exports = {
55
- ProgressReporter
56
- });
3
+ var _chunkBDNNPRX6js = require('./chunk-BDNNPRX6.js');
4
+ require('./chunk-R5U7XKVJ.js');
5
+
6
+
7
+ exports.ProgressReporter = _chunkBDNNPRX6js.ProgressReporter;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @module provenance
3
+ * @package @hop-top/kit
4
+ *
5
+ * Factor 11 — Provenance.
6
+ *
7
+ * Attaches origin metadata to any data payload for JSON output,
8
+ * enabling consumers to verify source, timing, and method.
9
+ */
10
+ interface Provenance {
11
+ source: string;
12
+ /** ISO 8601 timestamp */
13
+ timestamp: string;
14
+ method: string;
15
+ }
16
+ /**
17
+ * Wraps `data` with provenance metadata under `_meta`.
18
+ */
19
+ declare function withProvenance<T>(data: T, p: Provenance): {
20
+ data: T;
21
+ _meta: Provenance;
22
+ };
23
+
24
+ type provenance_Provenance = Provenance;
25
+ declare const provenance_withProvenance: typeof withProvenance;
26
+ declare namespace provenance {
27
+ export { type provenance_Provenance as Provenance, provenance_withProvenance as withProvenance };
28
+ }
29
+
30
+ export { type Provenance as P, provenance as p, withProvenance as w };
@@ -1,24 +1 @@
1
- /**
2
- * @module provenance
3
- * @package @hop-top/kit
4
- *
5
- * Factor 11 — Provenance.
6
- *
7
- * Attaches origin metadata to any data payload for JSON output,
8
- * enabling consumers to verify source, timing, and method.
9
- */
10
- interface Provenance {
11
- source: string;
12
- /** ISO 8601 timestamp */
13
- timestamp: string;
14
- method: string;
15
- }
16
- /**
17
- * Wraps `data` with provenance metadata under `_meta`.
18
- */
19
- declare function withProvenance<T>(data: T, p: Provenance): {
20
- data: T;
21
- _meta: Provenance;
22
- };
23
-
24
- export { type Provenance, withProvenance };
1
+ export { P as Provenance, w as withProvenance } from './provenance-SMFHm5gx.js';
@@ -1,32 +1,7 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
19
2
 
20
- // src/provenance.ts
21
- var provenance_exports = {};
22
- __export(provenance_exports, {
23
- withProvenance: () => withProvenance
24
- });
25
- module.exports = __toCommonJS(provenance_exports);
26
- function withProvenance(data, p) {
27
- return { data, _meta: p };
28
- }
29
- // Annotate the CommonJS export names for ESM import in node:
30
- 0 && (module.exports = {
31
- withProvenance
32
- });
3
+ var _chunk6SVOHNICjs = require('./chunk-6SVOHNIC.js');
4
+ require('./chunk-R5U7XKVJ.js');
5
+
6
+
7
+ exports.withProvenance = _chunk6SVOHNICjs.withProvenance;
@@ -0,0 +1,111 @@
1
+ import { C as Completer, S as Streamer, T as ToolCaller, a as ToolStreamer, R as ResolvedConfig, b as Request, c as Response, f as ToolStream, d as ToolDef, e as ToolResponse } from './llm-DYuR7_uX.js';
2
+
3
+ /**
4
+ * @packageDocumentation
5
+ *
6
+ * RouteLLM adapter — registers the `routellm` URI scheme.
7
+ *
8
+ * The model field takes either shape a RouteLLM server advertises on
9
+ * `/v1/models`, as in Go:
10
+ *
11
+ * - `router_name:threshold` — `routellm://mf:0.7`, sent as the server's
12
+ * `router-[name]-[threshold]` model. The client picks both.
13
+ * - tier name — `routellm://private`, sent verbatim. The server resolves
14
+ * router and threshold from its own tier config.
15
+ *
16
+ * Delegates to the openai adapter (`@hop-top/kit/openai`) pointed
17
+ * at the RouteLLM server's OpenAI-compatible endpoint.
18
+ * Importing this module registers the openai schemes too.
19
+ */
20
+
21
+ interface EvaConfig {
22
+ contracts: string[];
23
+ enforce: boolean;
24
+ }
25
+ interface RouterConfig {
26
+ baseUrl: string;
27
+ grpcPort: number;
28
+ strongModel: string;
29
+ weakModel: string;
30
+ routers: string[];
31
+ routerConfig: Record<string, unknown>;
32
+ eva: EvaConfig;
33
+ autostart: boolean;
34
+ }
35
+ /**
36
+ * Extract and validate RouteLLM configuration from provider extras.
37
+ * Environment variables (`ROUTELLM_BASE_URL`, `ROUTELLM_STRONG_MODEL`,
38
+ * `ROUTELLM_WEAK_MODEL`, `ROUTELLM_ROUTERS`) override all other
39
+ * sources; with `opts.hermetic` none is read.
40
+ */
41
+ declare function parseRouterConfig(extras?: Record<string, unknown>, opts?: {
42
+ hermetic?: boolean;
43
+ }): RouterConfig;
44
+ /**
45
+ * The model field classified. `isTier` selects `tier`; otherwise
46
+ * `routerName` and `threshold` hold the client-selected pair. The
47
+ * unused shape stays at `""` / `0`.
48
+ */
49
+ interface ParsedModel {
50
+ isTier: boolean;
51
+ tier: string;
52
+ routerName: string;
53
+ threshold: number;
54
+ }
55
+ /**
56
+ * Classify the model field as a `router_name:threshold` pair or a tier
57
+ * name, exactly as Go does.
58
+ *
59
+ * The shapes are told apart by the text after the last colon: when it
60
+ * parses as a finite float (Go `ParseFloat` syntax) the model is a
61
+ * router pair, else a tier sent verbatim — so a tier name may contain
62
+ * colons and `mf:abc` is a tier. A leading or trailing colon leaves a
63
+ * tier. The threshold range is checked by the adapter, not here; an
64
+ * unknown tier fails at the server.
65
+ */
66
+ declare function parseModelField(model: string): ParsedModel;
67
+ /**
68
+ * RouteLLM adapter: complete, stream, callWithTools and streamWithTools.
69
+ *
70
+ * Delegates to an inner {@link OpenAIAdapter} pointed at the RouteLLM
71
+ * server's OpenAI-compatible `/v1` API, so tool calling, tool names
72
+ * (openai rule, `?tool_names=`), size limits, retries and the
73
+ * credential guard are the openai adapter's.
74
+ */
75
+ declare class RouteLLMAdapter implements Completer, Streamer, ToolCaller, ToolStreamer {
76
+ readonly config: RouterConfig;
77
+ /** Client-selected router; `""` for a tier. */
78
+ readonly routerName: string;
79
+ /** Client-selected threshold; `0` for a tier (see {@link isTier}). */
80
+ readonly threshold: number;
81
+ /** Server-resolved tier name; `""` for a router pair. */
82
+ readonly tier: string;
83
+ /** The API root requests go to: the resolved base URL plus `/v1`. */
84
+ readonly baseURL: string;
85
+ private readonly inner;
86
+ constructor(cfg: ResolvedConfig);
87
+ /**
88
+ * Whether the adapter targets a server-resolved tier rather than a
89
+ * client-selected pair; use it instead of `threshold === 0`, which is
90
+ * also a valid client threshold.
91
+ */
92
+ isTier(): boolean;
93
+ complete(req: Request): Promise<Response>;
94
+ stream(req: Request): ToolStream;
95
+ callWithTools(req: Request, tools: ToolDef[]): Promise<ToolResponse>;
96
+ streamWithTools(req: Request, tools: ToolDef[]): ToolStream;
97
+ close(): void;
98
+ }
99
+
100
+ type routellm_EvaConfig = EvaConfig;
101
+ type routellm_ParsedModel = ParsedModel;
102
+ type routellm_RouteLLMAdapter = RouteLLMAdapter;
103
+ declare const routellm_RouteLLMAdapter: typeof RouteLLMAdapter;
104
+ type routellm_RouterConfig = RouterConfig;
105
+ declare const routellm_parseModelField: typeof parseModelField;
106
+ declare const routellm_parseRouterConfig: typeof parseRouterConfig;
107
+ declare namespace routellm {
108
+ export { type routellm_EvaConfig as EvaConfig, type routellm_ParsedModel as ParsedModel, routellm_RouteLLMAdapter as RouteLLMAdapter, type routellm_RouterConfig as RouterConfig, routellm_parseModelField as parseModelField, routellm_parseRouterConfig as parseRouterConfig };
109
+ }
110
+
111
+ export { type EvaConfig as E, type ParsedModel as P, RouteLLMAdapter as R, type RouterConfig as a, parseRouterConfig as b, parseModelField as p, routellm as r };
@@ -1,64 +1,2 @@
1
- import { Completer, Streamer, ResolvedConfig, Request, Response, Token } from './llm.js';
2
-
3
- /**
4
- * @packageDocumentation
5
- *
6
- * RouteLLM adapter — registers the `routellm` URI scheme.
7
- *
8
- * URI format: `routellm://router_name:threshold` (e.g. `routellm://mf:0.7`).
9
- *
10
- * Delegates HTTP completions to an OpenAI-compatible endpoint on the
11
- * RouteLLM server, translating the model field into the server's
12
- * expected `router-[name]-[threshold]` format.
13
- */
14
-
15
- interface EvaConfig {
16
- contracts: string[];
17
- enforce: boolean;
18
- }
19
- interface RouterConfig {
20
- baseUrl: string;
21
- grpcPort: number;
22
- strongModel: string;
23
- weakModel: string;
24
- routers: string[];
25
- routerConfig: Record<string, unknown>;
26
- eva: EvaConfig;
27
- autostart: boolean;
28
- }
29
- /**
30
- * Extract and validate RouteLLM configuration from provider extras.
31
- * Environment variables override all other sources.
32
- */
33
- declare function parseRouterConfig(extras?: Record<string, unknown>): RouterConfig;
34
- interface ParsedModel {
35
- routerName: string;
36
- threshold: number;
37
- }
38
- /**
39
- * Split a model string of the form `router_name:threshold` into its
40
- * components.
41
- */
42
- declare function parseModelField(model: string): ParsedModel;
43
- /**
44
- * RouteLLM adapter implementing Completer and Streamer.
45
- *
46
- * Delegates to an OpenAI-compatible HTTP endpoint on the RouteLLM
47
- * server using the standard fetch API.
48
- */
49
- declare class RouteLLMAdapter implements Completer, Streamer {
50
- readonly config: RouterConfig;
51
- readonly routerName: string;
52
- readonly threshold: number;
53
- private readonly _baseUrl;
54
- private readonly _serverModel;
55
- private readonly _apiKey;
56
- constructor(cfg: ResolvedConfig);
57
- complete(req: Request): Promise<Response>;
58
- stream(req: Request): AsyncGenerator<Token>;
59
- close(): void;
60
- private _buildBody;
61
- private _post;
62
- }
63
-
64
- export { type EvaConfig, type ParsedModel, RouteLLMAdapter, type RouterConfig, parseModelField, parseRouterConfig };
1
+ import './llm-DYuR7_uX.js';
2
+ export { E as EvaConfig, P as ParsedModel, R as RouteLLMAdapter, a as RouterConfig, p as parseModelField, b as parseRouterConfig } from './routellm-B0nv59mH.js';
package/dist/routellm.js CHANGED
@@ -1,258 +1,16 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
19
2
 
20
- // src/routellm.ts
21
- var routellm_exports = {};
22
- __export(routellm_exports, {
23
- RouteLLMAdapter: () => RouteLLMAdapter,
24
- parseModelField: () => parseModelField,
25
- parseRouterConfig: () => parseRouterConfig
26
- });
27
- module.exports = __toCommonJS(routellm_exports);
28
3
 
29
- // src/llm.ts
30
- var LLMError = class extends Error {
31
- constructor(message) {
32
- super(message);
33
- this.name = "LLMError";
34
- Object.setPrototypeOf(this, new.target.prototype);
35
- }
36
- };
37
- var registry = /* @__PURE__ */ new Map();
38
- function register(scheme, factory) {
39
- if (registry.has(scheme)) {
40
- throw new LLMError(`provider already registered for scheme: ${scheme}`);
41
- }
42
- registry.set(scheme, factory);
43
- }
44
4
 
45
- // src/routellm.ts
46
- function defaultRouterConfig() {
47
- return {
48
- baseUrl: "http://localhost:6060",
49
- grpcPort: 6061,
50
- strongModel: "",
51
- weakModel: "",
52
- routers: [],
53
- routerConfig: {},
54
- eva: { contracts: [], enforce: false },
55
- autostart: false
56
- };
57
- }
58
- function parseRouterConfig(extras) {
59
- const cfg = defaultRouterConfig();
60
- if (extras) {
61
- const raw = extras["routellm"];
62
- if (raw !== void 0) {
63
- if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
64
- throw new LLMError(
65
- `routellm: expected map, got ${typeof raw}`
66
- );
67
- }
68
- const sub = raw;
69
- if (typeof sub["base_url"] === "string") cfg.baseUrl = sub["base_url"];
70
- if (typeof sub["grpc_port"] === "number") cfg.grpcPort = sub["grpc_port"];
71
- if (typeof sub["strong_model"] === "string") {
72
- cfg.strongModel = sub["strong_model"];
73
- }
74
- if (typeof sub["weak_model"] === "string") {
75
- cfg.weakModel = sub["weak_model"];
76
- }
77
- if (Array.isArray(sub["routers"])) {
78
- cfg.routers = sub["routers"].filter(
79
- (r) => typeof r === "string"
80
- );
81
- }
82
- if (typeof sub["router_config"] === "object" && sub["router_config"] !== null && !Array.isArray(sub["router_config"])) {
83
- cfg.routerConfig = sub["router_config"];
84
- }
85
- if (typeof sub["eva"] === "object" && sub["eva"] !== null) {
86
- const e = sub["eva"];
87
- if (Array.isArray(e["contracts"])) {
88
- cfg.eva.contracts = e["contracts"].filter(
89
- (c) => typeof c === "string"
90
- );
91
- }
92
- if (typeof e["enforce"] === "boolean") cfg.eva.enforce = e["enforce"];
93
- }
94
- if (typeof sub["autostart"] === "boolean") {
95
- cfg.autostart = sub["autostart"];
96
- }
97
- }
98
- }
99
- const envBaseUrl = process.env["ROUTELLM_BASE_URL"];
100
- if (envBaseUrl) cfg.baseUrl = envBaseUrl;
101
- const envStrong = process.env["ROUTELLM_STRONG_MODEL"];
102
- if (envStrong) cfg.strongModel = envStrong;
103
- const envWeak = process.env["ROUTELLM_WEAK_MODEL"];
104
- if (envWeak) cfg.weakModel = envWeak;
105
- const envRouters = process.env["ROUTELLM_ROUTERS"];
106
- if (envRouters) {
107
- cfg.routers = envRouters.split(",").map((r) => r.trim()).filter(Boolean);
108
- }
109
- return cfg;
110
- }
111
- function parseModelField(model) {
112
- if (!model) {
113
- throw new LLMError(
114
- "model field is required (format: router_name:threshold)"
115
- );
116
- }
117
- const idx = model.indexOf(":");
118
- if (idx < 0) {
119
- throw new LLMError(
120
- `invalid model "${model}": expected format router_name:threshold (e.g. mf:0.7)`
121
- );
122
- }
123
- const routerName = model.slice(0, idx);
124
- const rawThreshold = model.slice(idx + 1);
125
- if (!routerName || !rawThreshold) {
126
- throw new LLMError(
127
- `invalid model "${model}": expected format router_name:threshold (e.g. mf:0.7)`
128
- );
129
- }
130
- const threshold = Number(rawThreshold);
131
- if (Number.isNaN(threshold)) {
132
- throw new LLMError(`invalid threshold "${rawThreshold}": not a number`);
133
- }
134
- return { routerName, threshold };
135
- }
136
- var RouteLLMAdapter = class {
137
- constructor(cfg) {
138
- this.config = parseRouterConfig(cfg.provider.extras);
139
- const model = cfg.provider.model || cfg.uri.model;
140
- const parsed = parseModelField(model);
141
- this.routerName = parsed.routerName;
142
- this.threshold = parsed.threshold;
143
- if (this.threshold < 0 || this.threshold > 1) {
144
- throw new LLMError(
145
- `routellm: threshold ${this.threshold} out of range [0, 1]`
146
- );
147
- }
148
- this._serverModel = `router-${this.routerName}-${this.threshold}`;
149
- let baseUrl = this.config.baseUrl;
150
- if (baseUrl === "http://localhost:6060" && cfg.provider.baseURL) {
151
- baseUrl = cfg.provider.baseURL;
152
- }
153
- this._baseUrl = baseUrl;
154
- this._apiKey = cfg.provider.apiKey ?? "";
155
- }
156
- async complete(req) {
157
- const body = this._buildBody(req, false);
158
- const resp = await this._post("/v1/chat/completions", body);
159
- const data = await resp.json();
160
- const choice = data.choices?.[0];
161
- const content = choice?.message?.content ?? "";
162
- const finishReason = choice?.finish_reason ?? "";
163
- const usage = data.usage ? {
164
- promptTokens: data.usage.prompt_tokens ?? 0,
165
- completionTokens: data.usage.completion_tokens ?? 0,
166
- totalTokens: data.usage.total_tokens ?? 0
167
- } : void 0;
168
- return { content, role: "assistant", usage, finishReason };
169
- }
170
- async *stream(req) {
171
- const body = this._buildBody(req, true);
172
- const resp = await this._post("/v1/chat/completions", body);
173
- if (!resp.body) {
174
- throw new LLMError("routellm: streaming response has no body");
175
- }
176
- const reader = resp.body.getReader();
177
- const decoder = new TextDecoder();
178
- let buf = "";
179
- try {
180
- for (; ; ) {
181
- const { done, value } = await reader.read();
182
- if (done) break;
183
- buf += decoder.decode(value, { stream: true });
184
- const lines = buf.split("\n");
185
- buf = lines.pop() ?? "";
186
- for (const line of lines) {
187
- const trimmed = line.trim();
188
- if (!trimmed || !trimmed.startsWith("data: ")) continue;
189
- const payload = trimmed.slice(6);
190
- if (payload === "[DONE]") {
191
- yield { content: "", done: true };
192
- return;
193
- }
194
- const chunk = JSON.parse(payload);
195
- const delta = chunk.choices?.[0]?.delta;
196
- const content = delta?.content ?? "";
197
- const isDone = chunk.choices?.[0]?.finish_reason != null;
198
- yield { content, done: isDone };
199
- }
200
- }
201
- } finally {
202
- reader.releaseLock();
203
- }
204
- }
205
- close() {
206
- }
207
- // ── private ────────────────────────────────────────────────────
208
- _buildBody(req, stream) {
209
- const body = {
210
- model: this._serverModel,
211
- messages: req.messages.map((m) => ({
212
- role: m.role,
213
- content: m.content
214
- })),
215
- stream
216
- };
217
- if (req.temperature !== void 0) body["temperature"] = req.temperature;
218
- if (req.maxTokens !== void 0) body["max_tokens"] = req.maxTokens;
219
- if (req.stopSequences?.length) body["stop"] = req.stopSequences;
220
- return body;
221
- }
222
- async _post(path, body) {
223
- const url = `${this._baseUrl}${path}`;
224
- const headers = {
225
- "Content-Type": "application/json"
226
- };
227
- if (this._apiKey) {
228
- headers["Authorization"] = `Bearer ${this._apiKey}`;
229
- }
230
- const resp = await fetch(url, {
231
- method: "POST",
232
- headers,
233
- body: JSON.stringify(body)
234
- });
235
- if (!resp.ok) {
236
- const text = await resp.text().catch(() => "");
237
- throw new LLMError(
238
- `routellm: HTTP ${resp.status} from ${url}: ${text}`
239
- );
240
- }
241
- return resp;
242
- }
243
- };
244
- function routellmFactory(cfg) {
245
- const adapter = new RouteLLMAdapter(cfg);
246
- return {
247
- complete: (req) => adapter.complete(req),
248
- stream: (req) => adapter.stream(req),
249
- close: () => adapter.close()
250
- };
251
- }
252
- register("routellm", routellmFactory);
253
- // Annotate the CommonJS export names for ESM import in node:
254
- 0 && (module.exports = {
255
- RouteLLMAdapter,
256
- parseModelField,
257
- parseRouterConfig
258
- });
5
+ var _chunkMUIQVU6Ejs = require('./chunk-MUIQVU6E.js');
6
+ require('./chunk-ABQSE7AI.js');
7
+ require('./chunk-YGYQUFGY.js');
8
+ require('./chunk-PSFYJGDG.js');
9
+ require('./chunk-4UE5TCMQ.js');
10
+ require('./chunk-KVG7YCTS.js');
11
+ require('./chunk-R5U7XKVJ.js');
12
+
13
+
14
+
15
+
16
+ exports.RouteLLMAdapter = _chunkMUIQVU6Ejs.RouteLLMAdapter; exports.parseModelField = _chunkMUIQVU6Ejs.parseModelField; exports.parseRouterConfig = _chunkMUIQVU6Ejs.parseRouterConfig;
@@ -0,0 +1,32 @@
1
+ import { E as Entity, Q as Query } from './api-DAexsu2H.js';
2
+
3
+ /**
4
+ * Typed ConnectRPC client for kit EntityService.
5
+ *
6
+ * Thin wrapper over generated Connect stubs, mapping between
7
+ * JS objects and protobuf Struct (JSON intermediate).
8
+ */
9
+
10
+ interface RPCClientOptions {
11
+ baseURL: string;
12
+ auth?: string;
13
+ }
14
+ declare class RPCClient<T extends Entity> {
15
+ private client;
16
+ private auth?;
17
+ constructor(opts: RPCClientOptions);
18
+ create(entity: Omit<T, "id"> | T): Promise<T>;
19
+ get(id: string): Promise<T>;
20
+ list(q?: Query): Promise<T[]>;
21
+ update(entity: T): Promise<T>;
22
+ delete(id: string): Promise<void>;
23
+ }
24
+
25
+ type rpc_RPCClient<T extends Entity> = RPCClient<T>;
26
+ declare const rpc_RPCClient: typeof RPCClient;
27
+ type rpc_RPCClientOptions = RPCClientOptions;
28
+ declare namespace rpc {
29
+ export { rpc_RPCClient as RPCClient, type rpc_RPCClientOptions as RPCClientOptions };
30
+ }
31
+
32
+ export { RPCClient as R, type RPCClientOptions as a, rpc as r };