@hop-top/kit 0.5.0-alpha.0 → 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 (284) hide show
  1. package/CHANGELOG.md +262 -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 -885
  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 +18 -322
  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 +236 -46
  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 +142 -0
  271. package/src/tui/parity.ts +59 -13
  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
package/dist/llm.js CHANGED
@@ -1,356 +1,101 @@
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);
19
-
20
- // src/llm.ts
21
- var llm_exports = {};
22
- __export(llm_exports, {
23
- AuthError: () => AuthError,
24
- CapabilityNotSupportedError: () => CapabilityNotSupportedError,
25
- FallbackExhaustedError: () => FallbackExhaustedError,
26
- LLMError: () => LLMError,
27
- ModelError: () => ModelError,
28
- ProviderNotFoundError: () => ProviderNotFoundError,
29
- RateLimitError: () => RateLimitError,
30
- clearRegistry: () => clearRegistry,
31
- createLLM: () => createLLM,
32
- isFallbackable: () => isFallbackable,
33
- loadConfig: () => loadConfig,
34
- parseURI: () => parseURI,
35
- register: () => register,
36
- resolve: () => resolve
37
- });
38
- module.exports = __toCommonJS(llm_exports);
39
- var LLMError = class extends Error {
40
- constructor(message) {
41
- super(message);
42
- this.name = "LLMError";
43
- Object.setPrototypeOf(this, new.target.prototype);
44
- }
45
- };
46
- var ProviderNotFoundError = class extends LLMError {
47
- constructor(scheme) {
48
- super(`provider not found: ${scheme}`);
49
- this.name = "ProviderNotFoundError";
50
- this.scheme = scheme;
51
- }
52
- };
53
- var CapabilityNotSupportedError = class extends LLMError {
54
- constructor(capability, provider) {
55
- super(
56
- `capability "${capability}" not supported by provider "${provider}"`
57
- );
58
- this.name = "CapabilityNotSupportedError";
59
- this.capability = capability;
60
- this.provider = provider;
61
- }
62
- };
63
- var AuthError = class extends LLMError {
64
- constructor(provider) {
65
- super(`authentication failed for provider: ${provider}`);
66
- this.name = "AuthError";
67
- this.provider = provider;
68
- }
69
- };
70
- var RateLimitError = class extends LLMError {
71
- constructor(provider, retryAfter) {
72
- super(`rate limit exceeded for provider: ${provider}`);
73
- this.name = "RateLimitError";
74
- this.provider = provider;
75
- this.retryAfter = retryAfter;
76
- this.statusCode = 429;
77
- }
78
- };
79
- var ModelError = class extends LLMError {
80
- constructor(model, provider) {
81
- super(`model "${model}" not available on provider "${provider}"`);
82
- this.name = "ModelError";
83
- this.model = model;
84
- this.provider = provider;
85
- }
86
- };
87
- var FallbackExhaustedError = class extends LLMError {
88
- constructor(errors) {
89
- super(
90
- `all providers exhausted (${errors.length} failures)`
91
- );
92
- this.name = "FallbackExhaustedError";
93
- this.errors = errors;
94
- }
95
- };
96
- function isFallbackable(err) {
97
- if (err instanceof RateLimitError) return true;
98
- if (err instanceof LLMError) {
99
- if (err.code && isConnectionError(err.code)) return true;
100
- if (err.statusCode !== void 0 && err.statusCode >= 500) return true;
101
- return false;
102
- }
103
- const code = err.code;
104
- if (code && isConnectionError(code)) return true;
105
- return false;
106
- }
107
- var CONNECTION_CODES = /* @__PURE__ */ new Set([
108
- "ECONNREFUSED",
109
- "ETIMEDOUT",
110
- "ECONNRESET",
111
- "ENETUNREACH",
112
- "EHOSTUNREACH"
113
- ]);
114
- function isConnectionError(code) {
115
- return CONNECTION_CODES.has(code);
116
- }
117
- function parseURI(raw) {
118
- const sep = "://";
119
- const idx = raw.indexOf(sep);
120
- if (idx < 0) {
121
- throw new LLMError(`invalid LLM URI (missing "://"): ${raw}`);
122
- }
123
- const scheme = raw.slice(0, idx);
124
- if (!scheme) {
125
- throw new LLMError(`invalid LLM URI (empty scheme): ${raw}`);
126
- }
127
- let rest = raw.slice(idx + sep.length);
128
- if (!rest) {
129
- throw new LLMError(`invalid LLM URI (empty model): ${raw}`);
130
- }
131
- let params;
132
- const qIdx = rest.indexOf("?");
133
- if (qIdx >= 0) {
134
- const qs = rest.slice(qIdx + 1);
135
- rest = rest.slice(0, qIdx);
136
- params = {};
137
- for (const pair of qs.split("&")) {
138
- const eqIdx = pair.indexOf("=");
139
- if (eqIdx > 0) {
140
- params[pair.slice(0, eqIdx)] = decodeURIComponent(
141
- pair.slice(eqIdx + 1)
142
- );
143
- }
144
- }
145
- }
146
- if (!rest) {
147
- throw new LLMError(`invalid LLM URI (empty model): ${raw}`);
148
- }
149
- let host;
150
- let model;
151
- const hostPortMatch = rest.match(/^([^/]+:\d+)\/(.+)$/);
152
- if (hostPortMatch) {
153
- host = hostPortMatch[1];
154
- model = hostPortMatch[2];
155
- } else {
156
- model = rest;
157
- }
158
- const uri = { scheme, model };
159
- if (host) uri.host = host;
160
- if (params && Object.keys(params).length > 0) uri.params = params;
161
- return uri;
162
- }
163
- function loadConfig(uriStr) {
164
- const effective = uriStr || process.env["LLM_PROVIDER"];
165
- if (!effective) {
166
- throw new LLMError(
167
- "no LLM URI provided and LLM_PROVIDER env var is not set"
168
- );
169
- }
170
- const uri = parseURI(effective);
171
- const fallbackEnv = process.env["LLM_FALLBACK"];
172
- const fallbacks = fallbackEnv ? fallbackEnv.split(",").map((s) => s.trim()).filter(Boolean) : [];
173
- const provider = {
174
- model: uri.model
175
- };
176
- if (uri.params) provider.params = { ...uri.params };
177
- if (uri.params?.api_key) {
178
- provider.apiKey = uri.params.api_key;
179
- }
180
- if (uri.params?.base_url) {
181
- provider.baseURL = uri.params.base_url;
182
- }
183
- if (uri.host) {
184
- provider.baseURL = `http://${uri.host}`;
185
- }
186
- const envApiKey = process.env["LLM_API_KEY"] || void 0;
187
- const envBaseURL = process.env["LLM_BASE_URL"] || void 0;
188
- if (envApiKey) provider.apiKey = envApiKey;
189
- if (envBaseURL) provider.baseURL = envBaseURL;
190
- return { uri, provider, fallbacks };
191
- }
192
- var registry = /* @__PURE__ */ new Map();
193
- function register(scheme, factory) {
194
- if (registry.has(scheme)) {
195
- throw new LLMError(`provider already registered for scheme: ${scheme}`);
196
- }
197
- registry.set(scheme, factory);
198
- }
199
- function resolve(uriStr) {
200
- const cfg = loadConfig(uriStr);
201
- const factory = registry.get(cfg.uri.scheme);
202
- if (!factory) {
203
- throw new ProviderNotFoundError(cfg.uri.scheme);
204
- }
205
- return factory(cfg);
206
- }
207
- function clearRegistry() {
208
- registry.clear();
209
- }
210
- function createLLM(uri, opts) {
211
- const cfg = loadConfig(uri);
212
- const fallbackURIs = opts?.fallback ?? cfg.fallbacks;
213
- const primary = resolve(uri);
214
- const allURIs = [uri, ...fallbackURIs];
215
- const resolvedProviders = /* @__PURE__ */ new Map();
216
- resolvedProviders.set(0, primary);
217
- function resolveAt(index) {
218
- let p = resolvedProviders.get(index);
219
- if (!p) {
220
- p = resolve(allURIs[index]);
221
- resolvedProviders.set(index, p);
222
- }
223
- return p;
224
- }
225
- async function withFallback(op, fn) {
226
- const errors = [];
227
- for (let i = 0; i < allURIs.length; i++) {
228
- try {
229
- const p = resolveAt(i);
230
- if (!(op in p) || typeof p[op] !== "function") {
231
- throw new CapabilityNotSupportedError(
232
- op,
233
- parseURI(allURIs[i]).scheme
234
- );
235
- }
236
- return await fn(p);
237
- } catch (err) {
238
- const e = err instanceof Error ? err : new Error(String(err));
239
- errors.push(e);
240
- opts?.onError?.(e);
241
- const canContinue = isFallbackable(e) || e instanceof CapabilityNotSupportedError;
242
- if (!canContinue || i === allURIs.length - 1) {
243
- if (errors.length > 1) {
244
- throw new FallbackExhaustedError(errors);
245
- }
246
- throw e;
247
- }
248
- opts?.onFallback?.(i, i + 1, e);
249
- }
250
- }
251
- throw new FallbackExhaustedError(errors);
252
- }
253
- return {
254
- async complete(request) {
255
- opts?.onRequest?.(request);
256
- const start = Date.now();
257
- const resp = await withFallback(
258
- "complete",
259
- (p) => p.complete(request)
260
- );
261
- opts?.onResponse?.(resp, Date.now() - start);
262
- return resp;
263
- },
264
- stream(request) {
265
- return {
266
- [Symbol.asyncIterator]() {
267
- let inner = null;
268
- let initialized = false;
269
- return {
270
- async next() {
271
- if (!initialized) {
272
- initialized = true;
273
- opts?.onRequest?.(request);
274
- const errors = [];
275
- for (let i = 0; i < allURIs.length; i++) {
276
- try {
277
- const p = resolveAt(i);
278
- if (!("stream" in p) || typeof p.stream !== "function") {
279
- throw new CapabilityNotSupportedError(
280
- "stream",
281
- parseURI(allURIs[i]).scheme
282
- );
283
- }
284
- const iterable = p.stream(request);
285
- const iter = iterable[Symbol.asyncIterator]();
286
- const first = await iter.next();
287
- inner = iter;
288
- return first;
289
- } catch (err) {
290
- const e = err instanceof Error ? err : new Error(String(err));
291
- errors.push(e);
292
- opts?.onError?.(e);
293
- const canContinue = isFallbackable(e) || e instanceof CapabilityNotSupportedError;
294
- if (!canContinue || i === allURIs.length - 1) {
295
- if (errors.length > 1)
296
- throw new FallbackExhaustedError(errors);
297
- throw e;
298
- }
299
- opts?.onFallback?.(i, i + 1, e);
300
- }
301
- }
302
- throw new FallbackExhaustedError(errors);
303
- }
304
- return inner.next();
305
- }
306
- };
307
- }
308
- };
309
- },
310
- async callWithTools(request, tools) {
311
- opts?.onRequest?.(request);
312
- const start = Date.now();
313
- const resp = await withFallback(
314
- "callWithTools",
315
- (p) => p.callWithTools(request, tools)
316
- );
317
- opts?.onResponse?.(
318
- { content: resp.content, role: "assistant" },
319
- Date.now() - start
320
- );
321
- return resp;
322
- },
323
- capabilities() {
324
- const caps = [];
325
- if (primary.complete) caps.push("complete");
326
- if (primary.stream) caps.push("stream");
327
- if (primary.callWithTools) caps.push("callWithTools");
328
- return caps;
329
- },
330
- provider() {
331
- return primary;
332
- },
333
- close() {
334
- for (const p of resolvedProviders.values()) {
335
- p.close();
336
- }
337
- }
338
- };
339
- }
340
- // Annotate the CommonJS export names for ESM import in node:
341
- 0 && (module.exports = {
342
- AuthError,
343
- CapabilityNotSupportedError,
344
- FallbackExhaustedError,
345
- LLMError,
346
- ModelError,
347
- ProviderNotFoundError,
348
- RateLimitError,
349
- clearRegistry,
350
- createLLM,
351
- isFallbackable,
352
- loadConfig,
353
- parseURI,
354
- register,
355
- resolve
356
- });
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+ var _chunkPSFYJGDGjs = require('./chunk-PSFYJGDG.js');
50
+ require('./chunk-4UE5TCMQ.js');
51
+ require('./chunk-KVG7YCTS.js');
52
+ require('./chunk-R5U7XKVJ.js');
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+ exports.ANTHROPIC_TOOL_NAMES = _chunkPSFYJGDGjs.ANTHROPIC_TOOL_NAMES; exports.APIError = _chunkPSFYJGDGjs.APIError; exports.AuthError = _chunkPSFYJGDGjs.AuthError; exports.CapabilityNotSupportedError = _chunkPSFYJGDGjs.CapabilityNotSupportedError; exports.DEFAULT_MAX_MEDIA_BYTES = _chunkPSFYJGDGjs.DEFAULT_MAX_MEDIA_BYTES; exports.FallbackExhaustedError = _chunkPSFYJGDGjs.FallbackExhaustedError; exports.GEMINI_TOOL_NAMES = _chunkPSFYJGDGjs.GEMINI_TOOL_NAMES; exports.HTTPStatusError = _chunkPSFYJGDGjs.HTTPStatusError; exports.KeyEndpointError = _chunkPSFYJGDGjs.KeyEndpointError; exports.LLMError = _chunkPSFYJGDGjs.LLMError; exports.MediaTooLargeError = _chunkPSFYJGDGjs.MediaTooLargeError; exports.MediaURLRefusedError = _chunkPSFYJGDGjs.MediaURLRefusedError; exports.MissingKeyError = _chunkPSFYJGDGjs.MissingKeyError; exports.ModelError = _chunkPSFYJGDGjs.ModelError; exports.OPENAI_TOOL_NAMES = _chunkPSFYJGDGjs.OPENAI_TOOL_NAMES; exports.PermissionDeniedError = _chunkPSFYJGDGjs.PermissionDeniedError; exports.ProviderNotFoundError = _chunkPSFYJGDGjs.ProviderNotFoundError; exports.RateLimitError = _chunkPSFYJGDGjs.RateLimitError; exports.ResponseTooLargeError = _chunkPSFYJGDGjs.ResponseTooLargeError; exports.StreamTruncatedError = _chunkPSFYJGDGjs.StreamTruncatedError; exports.TOOL_NAMES_PARAM = _chunkPSFYJGDGjs.TOOL_NAMES_PARAM; exports.ToolNameError = _chunkPSFYJGDGjs.ToolNameError; exports.ToolNames = _chunkPSFYJGDGjs.ToolNames; exports.applyAPIKey = _chunkPSFYJGDGjs.applyAPIKey; exports.checkKeyEndpoint = _chunkPSFYJGDGjs.checkKeyEndpoint; exports.checkToolChoice = _chunkPSFYJGDGjs.checkToolChoice; exports.checkToolLinkage = _chunkPSFYJGDGjs.checkToolLinkage; exports.clearRegistry = _chunkPSFYJGDGjs.clearRegistry; exports.createLLM = _chunkPSFYJGDGjs.createLLM; exports.credentialsTrusted = _chunkPSFYJGDGjs.credentialsTrusted; exports.declarationOf = _chunkPSFYJGDGjs.declarationOf; exports.fileSource = _chunkPSFYJGDGjs.fileSource; exports.inlineSource = _chunkPSFYJGDGjs.inlineSource; exports.isFallbackable = _chunkPSFYJGDGjs.isFallbackable; exports.isPublicAddress = _chunkPSFYJGDGjs.isPublicAddress; exports.isValidToolName = _chunkPSFYJGDGjs.isValidToolName; exports.loadConfig = _chunkPSFYJGDGjs.loadConfig; exports.parseURI = _chunkPSFYJGDGjs.parseURI; exports.redactURI = _chunkPSFYJGDGjs.redactURI; exports.register = _chunkPSFYJGDGjs.register; exports.requestStartedPayload = _chunkPSFYJGDGjs.requestStartedPayload; exports.resolve = _chunkPSFYJGDGjs.resolve; exports.responseReceivedPayload = _chunkPSFYJGDGjs.responseReceivedPayload; exports.sanitizeToolName = _chunkPSFYJGDGjs.sanitizeToolName; exports.toolNameModeOf = _chunkPSFYJGDGjs.toolNameModeOf; exports.urlSource = _chunkPSFYJGDGjs.urlSource; exports.usageCost = _chunkPSFYJGDGjs.usageCost;
@@ -0,0 +1,115 @@
1
+ import { P as ParityData } from './parity-CvMuYcVI.js';
2
+
3
+ /**
4
+ * Structured logger wrapping pino — applies kit's charmtone theme
5
+ * colors to stderr output (or an injected `output` sink).
6
+ *
7
+ * API: `logger.info('msg', 'key', val, 'key2', val2)` (variadic key-value)
8
+ * This matches Go's charm/log API, not pino's native object API.
9
+ * Pino handles transports, serialization, and performance under the hood.
10
+ *
11
+ * The `-V` count → level mapping and the `--quiet` override both come from
12
+ * the parity contract (`parity.json` verbosity block), so the level
13
+ * vocabulary stays identical across the Go, TypeScript and Python ports.
14
+ */
15
+
16
+ interface Logger {
17
+ info(msg: string, ...keyvals: any[]): void;
18
+ warn(msg: string, ...keyvals: any[]): void;
19
+ error(msg: string, ...keyvals: any[]): void;
20
+ debug(msg: string, ...keyvals: any[]): void;
21
+ trace(msg: string, ...keyvals: any[]): void;
22
+ /**
23
+ * Info-level line marked as a success: label `SUCC` in the theme's
24
+ * success colour. Filtered exactly like `info` (not a new level).
25
+ */
26
+ success(msg: string, ...keyvals: any[]): void;
27
+ }
28
+ /** Minimal sink the logger writes rendered lines to. */
29
+ interface LogOutput {
30
+ write(chunk: string): unknown;
31
+ }
32
+ /** Kit level vocabulary (same spellings as Go/py and `parity.json`). */
33
+ type LogLevelName = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal';
34
+ /** One log line, as handed to a custom `formatter`. */
35
+ interface LogRecord {
36
+ level: LogLevelName;
37
+ msg: string;
38
+ /** Key-value pairs in call order (after pino serialization). */
39
+ fields: Record<string, unknown>;
40
+ /** Set on `success()` lines, whose `level` is `'info'`. */
41
+ kind?: 'success';
42
+ }
43
+ /** Renders a record to one line; a missing trailing newline is appended. */
44
+ type LogFormatter = (rec: LogRecord) => string;
45
+ interface LoggerOptions {
46
+ quiet?: boolean;
47
+ noColor?: boolean;
48
+ /**
49
+ * Explicit threshold; wins over the factory default and the `-V` count.
50
+ * `'silent'` drops everything. `quiet` only raises it (to the contract's
51
+ * `quiet_override`), never lowers it — same as Go's `WithLevel`.
52
+ * TS-only option; not a parity verbosity entry.
53
+ */
54
+ level?: LogLevelName | 'silent';
55
+ /**
56
+ * Where rendered lines go. Defaults to `process.stderr`, resolved at
57
+ * write time. Mirrors Go's `(*log.Logger).SetOutput`; useful for
58
+ * capturing output in tests.
59
+ */
60
+ output?: LogOutput;
61
+ /**
62
+ * Line format. `'text'` (default) is `LEVEL msg k=v`; `'json'` is one
63
+ * object per line shaped like Go charm/log's JSONFormatter:
64
+ * `{"level":"info","msg":"...",...kv}` (no time/pid/hostname, no ANSI).
65
+ * `success` lines carry `"level":"info","kind":"success"`. Selected by
66
+ * this option only — no env var or flag.
67
+ */
68
+ format?: 'text' | 'json';
69
+ /**
70
+ * TS extension point: render each line yourself (glyph prefixes, house
71
+ * styles). The returned string is written as-is, plus `\n` if missing.
72
+ * Wins over `format` and `noColor`; level filtering still applies.
73
+ */
74
+ formatter?: LogFormatter;
75
+ }
76
+ /**
77
+ * Resolve a `-V` count against a parity contract's `verbosity.levels`
78
+ * table. Counts above the highest declared key clamp to that key's level;
79
+ * an empty or unresolvable table falls back to `info`.
80
+ *
81
+ * Taking the contract as a parameter (rather than reading the module-level
82
+ * `parity`) keeps the mapping testable against a constructed `ParityData`
83
+ * without mutating the shared `parity.json`.
84
+ */
85
+ declare function verbosityLevel(d: ParityData, verbose: number): string;
86
+ /**
87
+ * Resolve a parity contract's `verbosity.quiet_override` to a pino level
88
+ * name. An unrecognized or absent override falls back to `warn`.
89
+ */
90
+ declare function quietLevel(d: ParityData): string;
91
+ declare function createLogger(opts?: LoggerOptions): Logger;
92
+ /**
93
+ * Map verbose count to a pino level through the parity contract's
94
+ * `verbosity.levels` table. An explicit `level` wins over the count.
95
+ * Quiet raises to the contract's `quiet_override` level.
96
+ */
97
+ declare function withVerbose(opts: LoggerOptions & {
98
+ verbose?: number;
99
+ }): Logger;
100
+
101
+ type log_LogFormatter = LogFormatter;
102
+ type log_LogLevelName = LogLevelName;
103
+ type log_LogOutput = LogOutput;
104
+ type log_LogRecord = LogRecord;
105
+ type log_Logger = Logger;
106
+ type log_LoggerOptions = LoggerOptions;
107
+ declare const log_createLogger: typeof createLogger;
108
+ declare const log_quietLevel: typeof quietLevel;
109
+ declare const log_verbosityLevel: typeof verbosityLevel;
110
+ declare const log_withVerbose: typeof withVerbose;
111
+ declare namespace log {
112
+ export { type log_LogFormatter as LogFormatter, type log_LogLevelName as LogLevelName, type log_LogOutput as LogOutput, type log_LogRecord as LogRecord, type log_Logger as Logger, type log_LoggerOptions as LoggerOptions, log_createLogger as createLogger, log_quietLevel as quietLevel, log_verbosityLevel as verbosityLevel, log_withVerbose as withVerbose };
113
+ }
114
+
115
+ export { type LogFormatter as L, type LogLevelName as a, type LogOutput as b, type LogRecord as c, type Logger as d, type LoggerOptions as e, createLogger as f, log as l, quietLevel as q, verbosityLevel as v, withVerbose as w };
package/dist/log.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import './parity-CvMuYcVI.js';
2
+ export { L as LogFormatter, a as LogLevelName, b as LogOutput, c as LogRecord, d as Logger, e as LoggerOptions, f as createLogger, q as quietLevel, v as verbosityLevel, w as withVerbose } from './log-CkaxMX3U.js';
package/dist/log.js ADDED
@@ -0,0 +1,14 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+
6
+ var _chunkNLMS7HGPjs = require('./chunk-NLMS7HGP.js');
7
+ require('./chunk-QPUCXQXT.js');
8
+ require('./chunk-R5U7XKVJ.js');
9
+
10
+
11
+
12
+
13
+
14
+ exports.createLogger = _chunkNLMS7HGPjs.createLogger; exports.quietLevel = _chunkNLMS7HGPjs.quietLevel; exports.verbosityLevel = _chunkNLMS7HGPjs.verbosityLevel; exports.withVerbose = _chunkNLMS7HGPjs.withVerbose;
@@ -0,0 +1,4 @@
1
+ export { C as CommanderBridgeOptions, D as DEFAULT_MCP_PATH, a as DEFAULT_MCP_SERVER_NAME, b as DEFAULT_MCP_SERVER_VERSION, c as DEFAULT_TOOL_NAME_SEPARATOR, d as DestructiveBlockedError, E as ElicitationConfirmGate, F as FlagSchema, H as HEADER_MCP_METHOD, e as HEADER_MCP_NAME, f as HEADER_MCP_PROTOCOL_VERSION, I as Invocation, g as InvocationMeta, h as InvokeResult, J as JsonRpcErrorObject, j as JsonRpcRequest, L as Leaf, k as LeafArg, l as LegacyMcpHandler, M as MCP_ARGS_PROPERTY, m as MCP_AUDIT_AUTH_REFUSED, n as MCP_AUDIT_CONFIRMATION_DECLINED, o as MCP_AUDIT_CONFIRMATION_REQUIRED, p as MCP_AUDIT_CONFIRMATION_STATE_REJECTED, q as MCP_AUDIT_DESTRUCTIVE_BLOCKED, r as MCP_AUTH_CHALLENGE, s as MCP_CONFIRM_KEY, t as MCP_CONFIRM_REJECTION_STATE, u as MCP_CONFIRM_STATE_TTL_SECONDS, v as MCP_CONFIRM_STATE_VERSION, w as MCP_ERR_HEADER_MISMATCH, x as MCP_ERR_INTERNAL, y as MCP_ERR_INVALID_PARAMS, z as MCP_ERR_INVALID_REQUEST, A as MCP_ERR_METHOD_NOT_FOUND, B as MCP_ERR_MISSING_CLIENT_CAPABILITY, G as MCP_ERR_PARSE, K as MCP_ERR_UNSUPPORTED_VERSION, N as MCP_SPEC_2024_11_05, O as MCP_SPEC_2026_07_28, P as META_KEY_CLIENT_CAPABILITIES, Q as META_KEY_CLIENT_INFO, R as META_KEY_PROTOCOL_VERSION, S as META_KEY_SERVER_INFO, T as McpAuditHook, U as McpAuditRecord, V as McpBridge, W as McpCacheScope, X as McpConfirmBinding, Y as McpConfirmDecision, Z as McpConfirmRejection, _ as McpConfirmStateStatus, $ as McpDispatcher, a0 as McpEra, a1 as McpEstablishment, a2 as McpHandler, a3 as McpHttpRequest, a4 as McpHttpResponse, a5 as McpIdentity, a6 as McpMountOptions, a7 as McpSpecVersion, a8 as McpSplitResult, a9 as McpStdioOptions, aa as McpStdioServer, ab as McpTransport, ac as McpVerifier, ad as ModernMcpHandler, ae as ModernRequestMeta, af as Policy, ag as RESULT_TYPE_COMPLETE, ah as RESULT_TYPE_INPUT_REQUIRED, ai as RawJSON, aj as ResolvedMcpConfig, ak as SCOPES_EXTRA_KEY, al as SURFACE_CLI, am as SURFACE_LIB, an as SURFACE_MCP, ao as SafetyClass, ap as Surface, aq as SurfaceNotEnabledError, ar as TASKS_EXTENSION, as as TASKS_SUPPORTED, at as TASK_METHODS, au as TaskMethod, av as UnknownCommandError, aw as auditRefusal, ax as buildToolEnvelope, ay as canonicalJSONStringify, az as clientSupportsFormElicitation, aA as commanderBridge, aB as createMcpHandler, aC as decodeMcpSentinel, aD as defaultPolicy, aE as detectMcpEra, aF as discoverCapabilities, aG as encodeEnvelope, aH as errorResultBlock, aI as establishCaller, aJ as hasModernMetaMarker, aK as headerConfirmationGate, aL as invocationMeta, aM as isTaskMethod, aN as mcpArgsPublished, aO as mcpConfirmArgsDigest, aP as mcpConfirmPrincipal, aQ as mcpInputSchema, aR as mcpMountConfig, aS as mcpSplitArguments, aT as mcpToolDescription, aU as methodNotAllowedResponse, aV as mintMcpConfirmState, aW as modernInvocationExtra, aX as parseJsonRpcRequest, aY as parseMcpConfirmRetry, aZ as parseModernMeta, a_ as pathFromToolName, a$ as policyAllowed, b0 as rawToolCallName, b1 as renderCallResult, b2 as resolveMcpConfig, b3 as serveStdio, b4 as singleHeaderValue, b5 as toolName, b6 as validModernRequestId, b7 as verifyMcpConfirmState } from '../index-BKJZClJx.js';
2
+ import '@modelcontextprotocol/server';
3
+ import 'node:stream';
4
+ import 'commander';