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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/LICENSE +1 -1
  3. package/README.md +47 -575
  4. package/dist/{aim-CTp-kJW2.d.ts → aim-DZHwwiIc.d.ts} +1 -1
  5. package/dist/aim.d.ts +1 -1
  6. package/dist/aim.js +13 -414
  7. package/dist/{alias-dhhr08Ei.d.ts → alias-BOj0-VAr.d.ts} +1 -1
  8. package/dist/alias.d.ts +1 -1
  9. package/dist/alias.js +18 -206
  10. package/dist/{api-miiso81x.d.ts → api-DAexsu2H.d.ts} +1 -1
  11. package/dist/api.d.ts +1 -1
  12. package/dist/api.js +10 -164
  13. package/dist/auth.js +6 -40
  14. package/dist/chunk-3FIKGFKI.js +54 -0
  15. package/dist/chunk-4UE5TCMQ.js +104 -0
  16. package/dist/chunk-6HFAEZ52.js +29 -0
  17. package/dist/chunk-6SVOHNIC.js +17 -0
  18. package/dist/chunk-72XZWQX7.js +504 -0
  19. package/dist/chunk-ABQSE7AI.js +513 -0
  20. package/dist/chunk-BDNNPRX6.js +41 -0
  21. package/dist/chunk-BRNEKPWX.js +37 -0
  22. package/dist/chunk-CSJWB6D3.js +151 -0
  23. package/dist/chunk-GGWJRWWA.js +309 -0
  24. package/dist/chunk-IQXEISMC.js +142 -0
  25. package/dist/chunk-JTMPNXVQ.js +1491 -0
  26. package/dist/chunk-KVG7YCTS.js +115 -0
  27. package/dist/chunk-L23O2FFE.js +51 -0
  28. package/dist/chunk-MQXYDYRD.js +968 -0
  29. package/dist/chunk-MUIQVU6E.js +251 -0
  30. package/dist/chunk-POR5L2DG.js +247 -0
  31. package/dist/chunk-PSFYJGDG.js +1445 -0
  32. package/dist/chunk-QJVSKKRQ.js +369 -0
  33. package/dist/chunk-QPUCXQXT.js +67 -0
  34. package/dist/chunk-R5U7XKVJ.js +16 -0
  35. package/dist/chunk-S45UHXQF.js +182 -0
  36. package/dist/chunk-T46YPHKN.js +669 -0
  37. package/dist/chunk-UIOOOK6M.js +334 -0
  38. package/dist/chunk-UKZIAQA7.js +26 -0
  39. package/dist/chunk-WBVO43HU.js +355 -0
  40. package/dist/chunk-WTYDHXPW.js +574 -0
  41. package/dist/chunk-WUOAQVOA.js +86 -0
  42. package/dist/chunk-WWUKGJB5.js +90 -0
  43. package/dist/chunk-YGYQUFGY.js +219 -0
  44. package/dist/chunk-YOBAUCVN.js +583 -0
  45. package/dist/{cli-DLygZLi9.d.ts → cli-8rfITnv4.d.ts} +13 -4
  46. package/dist/cli.d.ts +4 -4
  47. package/dist/cli.js +50 -1057
  48. package/dist/{config-BUY7_W2n.d.ts → config-Bm9fBXch.d.ts} +35 -4
  49. package/dist/config.d.ts +1 -1
  50. package/dist/config.js +6 -78
  51. package/dist/errcorrect.js +8 -68
  52. package/dist/{error-DISJKeDu.d.ts → error-Do8Qji43.d.ts} +88 -1
  53. package/dist/id/index.d.ts +1 -1
  54. package/dist/id/index.js +14 -65
  55. package/dist/{index-MLrRDvEG.d.ts → index-B-pqGHhU.d.ts} +113 -19
  56. package/dist/{index-Bc5c7Ty5.d.ts → index-DEyjGoo2.d.ts} +1 -1
  57. package/dist/{index-QSffbLnj.d.ts → index-VLDcI5NF.d.ts} +3 -2
  58. package/dist/index.d.ts +18 -15
  59. package/dist/index.js +39 -6722
  60. package/dist/llm-DYuR7_uX.d.ts +1069 -0
  61. package/dist/llm-anthropic-Cd_I2xXB.d.ts +67 -0
  62. package/dist/llm-anthropic.d.ts +2 -0
  63. package/dist/llm-anthropic.js +13 -0
  64. package/dist/llm-openai-DyFrucmV.d.ts +87 -0
  65. package/dist/llm-openai.d.ts +2 -0
  66. package/dist/llm-openai.js +19 -0
  67. package/dist/llm.d.ts +1 -1
  68. package/dist/llm.js +101 -356
  69. package/dist/mcp/index.d.ts +2 -1
  70. package/dist/mcp/index.js +155 -1453
  71. package/dist/{netpolicy-asvCfwi8.d.ts → netpolicy-Brx5XZUB.d.ts} +16 -3
  72. package/dist/netpolicy.d.ts +1 -1
  73. package/dist/netpolicy.js +25 -118
  74. package/dist/{output-4aXs91GY.d.ts → output-CjZWmL8s.d.ts} +28 -4
  75. package/dist/output.d.ts +2 -2
  76. package/dist/output.js +137 -971
  77. package/dist/progress.js +6 -55
  78. package/dist/provenance.js +6 -31
  79. package/dist/routellm-B0nv59mH.d.ts +111 -0
  80. package/dist/routellm.d.ts +2 -2
  81. package/dist/routellm.js +13 -255
  82. package/dist/{rpc-D5xLEf8V.d.ts → rpc-D31Lg0Kc.d.ts} +1 -1
  83. package/dist/rpc.d.ts +2 -2
  84. package/dist/rpc.js +4 -98
  85. package/dist/safety.js +6 -43
  86. package/dist/scope.js +20 -377
  87. package/dist/{serve-DE-jscpb.d.ts → serve-D8yWMrTc.d.ts} +2 -2
  88. package/dist/serve.d.ts +2 -2
  89. package/dist/serve.js +75 -1019
  90. package/dist/sqlstore.js +6 -39
  91. package/dist/stream.js +8 -51
  92. package/dist/telemetry/index.js +24 -608
  93. package/dist/tui/index.d.ts +5 -5
  94. package/dist/tui/index.js +17 -374
  95. package/dist/upgrade.js +6 -114
  96. package/dist/xdg.js +14 -128
  97. package/package.json +130 -25
  98. package/src/README.md +15 -0
  99. package/src/cli.test.ts +56 -1
  100. package/src/cli.ts +24 -4
  101. package/src/completion-values.test.ts +10 -10
  102. package/src/compliance.test.ts +196 -2
  103. package/src/compliance.ts +440 -20
  104. package/src/config.test.ts +187 -1
  105. package/src/config.ts +173 -7
  106. package/src/gen/crud_pb.ts +7 -7
  107. package/src/id/README.md +38 -0
  108. package/src/id/contract.test.ts +1 -1
  109. package/src/id/index.test.ts +1 -1
  110. package/src/id/index.ts +3 -2
  111. package/src/index.test.ts +12 -0
  112. package/src/index.ts +2 -0
  113. package/src/llm-anthropic.conformance.test.ts +1135 -0
  114. package/src/llm-anthropic.test.ts +152 -0
  115. package/src/llm-anthropic.ts +940 -0
  116. package/src/llm-choice-hermetic.test.ts +335 -0
  117. package/src/llm-config.test.ts +232 -0
  118. package/src/llm-config.ts +106 -0
  119. package/src/llm-endpoint.ts +254 -0
  120. package/src/llm-error.ts +17 -0
  121. package/src/llm-errors.ts +152 -0
  122. package/src/llm-file.ts +126 -0
  123. package/src/llm-http.ts +317 -0
  124. package/src/llm-keys.ts +167 -0
  125. package/src/llm-media.conformance.test.ts +87 -0
  126. package/src/llm-media.test.ts +279 -0
  127. package/src/llm-media.ts +322 -0
  128. package/src/llm-openai.conformance.test.ts +407 -0
  129. package/src/llm-openai.test.ts +510 -0
  130. package/src/llm-openai.ts +708 -0
  131. package/src/llm-payload.ts +155 -0
  132. package/src/llm-quote.ts +46 -0
  133. package/src/llm-routellm.conformance.test.ts +44 -0
  134. package/src/llm-toolnames.conformance.test.ts +112 -0
  135. package/src/llm-toolnames.test.ts +132 -0
  136. package/src/llm-toolnames.ts +298 -0
  137. package/src/llm-uri.ts +99 -0
  138. package/src/llm.test.ts +43 -15
  139. package/src/llm.toolcall.test.ts +175 -0
  140. package/src/llm.ts +602 -190
  141. package/src/mcp/README.md +57 -0
  142. package/src/mcp/conformance.test.ts +24 -3
  143. package/src/mcp/dispatch.ts +4 -4
  144. package/src/mcp/identity.test.ts +166 -0
  145. package/src/mcp/identity.ts +72 -0
  146. package/src/mcp/index.ts +6 -0
  147. package/src/mcp/legacy.ts +21 -8
  148. package/src/mcp/mcp.test.ts +14 -4
  149. package/src/mcp/modern-confirm.ts +1 -1
  150. package/src/mcp/modern.ts +12 -11
  151. package/src/mcp/tasks.ts +1 -1
  152. package/src/mcp/types.ts +80 -8
  153. package/src/netpolicy.test.ts +78 -0
  154. package/src/netpolicy.ts +28 -3
  155. package/src/output/README.md +46 -0
  156. package/src/output/builtins.ts +5 -5
  157. package/src/output/error.ts +144 -1
  158. package/src/output/formatters/README.md +50 -0
  159. package/src/output.ts +24 -1
  160. package/src/published-types.test.ts +115 -0
  161. package/src/routellm.test.ts +209 -28
  162. package/src/routellm.toolcall.test.ts +521 -0
  163. package/src/routellm.ts +213 -177
  164. package/src/router/README.md +44 -0
  165. package/src/router/server.test.ts +41 -0
  166. package/src/router/server.ts +11 -0
  167. package/src/safety.test.ts +19 -9
  168. package/src/scope-defaults.json +29 -29
  169. package/src/serve.ts +1 -1
  170. package/src/telemetry/README.md +48 -0
  171. package/src/telemetry/client.ts +5 -5
  172. package/src/toolspec.test.ts +2 -2
  173. package/src/triton/README.md +34 -0
  174. package/src/tui/README.md +42 -0
  175. package/src/wizard.test.ts +7 -7
  176. package/test/llm/conformance-helpers.ts +100 -0
  177. package/test/output/dispatch.test.ts +1 -2
  178. package/test/output/error.test.ts +33 -2
  179. package/test/output/smoke-capture.ts +2 -2
  180. package/test/output/smoke.test.ts +2 -2
  181. package/test/output/taxonomy-contract.test.ts +148 -0
  182. package/test/setup-env.ts +16 -0
  183. package/tsconfig.json +3 -1
  184. package/tsconfig.test.json +10 -0
  185. package/vitest.config.ts +9 -0
  186. package/dist/llm-B5XUWH8T.d.ts +0 -231
  187. package/dist/routellm-PGSt2D1y.d.ts +0 -75
@@ -0,0 +1,583 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
+
3
+ var _chunkKVG7YCTSjs = require('./chunk-KVG7YCTS.js');
4
+
5
+
6
+ var _chunkR5U7XKVJjs = require('./chunk-R5U7XKVJ.js');
7
+
8
+ // src/telemetry/index.ts
9
+ var telemetry_exports = {};
10
+ _chunkR5U7XKVJjs.__export.call(void 0, telemetry_exports, {
11
+ Client: () => Client,
12
+ Mode: () => Mode,
13
+ consentPath: () => consentPath,
14
+ deniedConsent: () => deniedConsent,
15
+ getInstallId: () => getInstallId,
16
+ installIdPath: () => installIdPath,
17
+ loadConsent: () => loadConsent,
18
+ parseMode: () => parseMode,
19
+ redact: () => redact,
20
+ redactString: () => redactString,
21
+ resetForTest: () => resetForTest,
22
+ resolveMode: () => resolveMode,
23
+ rotate: () => rotate
24
+ });
25
+
26
+ // src/telemetry/mode.ts
27
+ var Mode = {
28
+ Off: "off",
29
+ Anon: "anon",
30
+ Full: "full"
31
+ };
32
+ function parseMode(s) {
33
+ if (s === void 0 || s === null || s === "") {
34
+ return [Mode.Off, true];
35
+ }
36
+ const low = s.trim().toLowerCase();
37
+ if (low === "") {
38
+ return [Mode.Off, true];
39
+ }
40
+ for (const m of Object.values(Mode)) {
41
+ if (m === low) {
42
+ return [m, true];
43
+ }
44
+ }
45
+ return [Mode.Off, false];
46
+ }
47
+ function resolveAppPrefix(env) {
48
+ return (_nullishCoalesce(env.KIT_APP_PREFIX, () => ( ""))).trim().toUpperCase();
49
+ }
50
+ function resolveMode(env = process.env) {
51
+ const app = resolveAppPrefix(env);
52
+ if (app) {
53
+ const v2 = (_nullishCoalesce(env[`${app}_TELEMETRY_MODE`], () => ( ""))).trim();
54
+ if (v2) {
55
+ const [m, ok] = parseMode(v2);
56
+ if (ok) {
57
+ return m;
58
+ }
59
+ }
60
+ }
61
+ const v = (_nullishCoalesce(env.KIT_TELEMETRY_MODE, () => ( ""))).trim();
62
+ if (v) {
63
+ const [m, ok] = parseMode(v);
64
+ if (ok) {
65
+ return m;
66
+ }
67
+ }
68
+ return Mode.Off;
69
+ }
70
+
71
+ // src/telemetry/installId.ts
72
+ var _fs = require('fs');
73
+
74
+ var _crypto = require('crypto');
75
+ var _os = require('os'); var os = _interopRequireWildcard(_os);
76
+ var _path = require('path'); var path = _interopRequireWildcard(_path); var path2 = _interopRequireWildcard(_path); var path3 = _interopRequireWildcard(_path);
77
+ var installIDSize = 32;
78
+ var installIDFilePerm = 384;
79
+ var installIDDirPerm = 448;
80
+ function xdgStateHome() {
81
+ return _nullishCoalesce(process.env.XDG_STATE_HOME, () => ( path.join(_os.homedir.call(void 0, ), ".local", "state")));
82
+ }
83
+ function installIdPath() {
84
+ return path.join(xdgStateHome(), "kit", "telemetry", "installation_id");
85
+ }
86
+ function sha256Hex(buf) {
87
+ return _crypto.createHash.call(void 0, "sha256").update(buf).digest("hex");
88
+ }
89
+ async function readAndValidate(p) {
90
+ const data = await _fs.promises.readFile(p);
91
+ if (data.length !== installIDSize) {
92
+ throw new Error(
93
+ `install_id: file ${p} has wrong size ${data.length} bytes, expected ${installIDSize}`
94
+ );
95
+ }
96
+ return data;
97
+ }
98
+ async function getInstallId() {
99
+ const p = installIdPath();
100
+ if (_fs.existsSync.call(void 0, p)) {
101
+ const data = await readAndValidate(p);
102
+ return sha256Hex(data);
103
+ }
104
+ const parent = path.dirname(p);
105
+ await _fs.promises.mkdir(parent, { recursive: true, mode: installIDDirPerm });
106
+ try {
107
+ await _fs.promises.chmod(parent, installIDDirPerm);
108
+ } catch (e2) {
109
+ }
110
+ const fresh = _crypto.randomBytes.call(void 0, installIDSize);
111
+ const tmp = p + ".new";
112
+ await _fs.promises.writeFile(tmp, fresh, { mode: installIDFilePerm });
113
+ if (_fs.existsSync.call(void 0, p)) {
114
+ try {
115
+ await _fs.promises.unlink(tmp);
116
+ } catch (e3) {
117
+ }
118
+ const data = await readAndValidate(p);
119
+ return sha256Hex(data);
120
+ }
121
+ await _fs.promises.rename(tmp, p);
122
+ return sha256Hex(fresh);
123
+ }
124
+ async function rotate() {
125
+ const p = installIdPath();
126
+ const parent = path.dirname(p);
127
+ await _fs.promises.mkdir(parent, { recursive: true, mode: installIDDirPerm });
128
+ try {
129
+ await _fs.promises.chmod(parent, installIDDirPerm);
130
+ } catch (e4) {
131
+ }
132
+ const fresh = _crypto.randomBytes.call(void 0, installIDSize);
133
+ const tmp = p + ".new";
134
+ await _fs.promises.writeFile(tmp, fresh, { mode: installIDFilePerm });
135
+ await _fs.promises.rename(tmp, p);
136
+ return sha256Hex(fresh);
137
+ }
138
+ async function resetForTest() {
139
+ const p = installIdPath();
140
+ try {
141
+ await _fs.promises.unlink(p);
142
+ } catch (e5) {
143
+ }
144
+ try {
145
+ await _fs.promises.unlink(p + ".new");
146
+ } catch (e6) {
147
+ }
148
+ }
149
+
150
+ // src/telemetry/consent.ts
151
+
152
+
153
+
154
+
155
+ var _jsyaml = require('js-yaml'); var yaml = _interopRequireWildcard(_jsyaml); var yaml2 = _interopRequireWildcard(_jsyaml);
156
+ var deniedConsent = {
157
+ allowed: false,
158
+ promptVersion: 0,
159
+ decisionSource: "config"
160
+ };
161
+ function xdgConfigHome() {
162
+ return _nullishCoalesce(process.env.XDG_CONFIG_HOME, () => ( path2.join(_os.homedir.call(void 0, ), ".config")));
163
+ }
164
+ function consentPath() {
165
+ return path2.join(xdgConfigHome(), "kit", "config.yaml");
166
+ }
167
+ function legacyConsentPath() {
168
+ return path2.join(xdgConfigHome(), "kit", "telemetry.yaml");
169
+ }
170
+ async function loadConsent() {
171
+ const canonical = await readConsentBlock(consentPath(), "canonical");
172
+ if (canonical !== null) {
173
+ return canonical;
174
+ }
175
+ const legacy = await readConsentBlock(legacyConsentPath(), "legacy");
176
+ if (legacy !== null) {
177
+ return legacy;
178
+ }
179
+ return deniedConsent;
180
+ }
181
+ async function readConsentBlock(p, variant) {
182
+ if (!_fs.existsSync.call(void 0, p)) {
183
+ return null;
184
+ }
185
+ let data;
186
+ try {
187
+ const raw = await _fs.promises.readFile(p, "utf8");
188
+ data = yaml.load(raw);
189
+ } catch (e7) {
190
+ return null;
191
+ }
192
+ if (typeof data !== "object" || data === null) {
193
+ return null;
194
+ }
195
+ const root = data;
196
+ let telemetry;
197
+ if (variant === "canonical") {
198
+ const kit = root.kit;
199
+ if (typeof kit !== "object" || kit === null) {
200
+ return null;
201
+ }
202
+ telemetry = kit.telemetry;
203
+ } else {
204
+ telemetry = root.telemetry;
205
+ }
206
+ if (typeof telemetry !== "object" || telemetry === null) {
207
+ return null;
208
+ }
209
+ const block = telemetry.consent;
210
+ if (typeof block !== "object" || block === null) {
211
+ return null;
212
+ }
213
+ const c = block;
214
+ const state = c.state;
215
+ if (state !== "granted" && state !== "denied") {
216
+ return null;
217
+ }
218
+ return {
219
+ allowed: state === "granted",
220
+ promptVersion: typeof c.prompt_version === "number" ? c.prompt_version : 0,
221
+ decisionSource: typeof c.decision_source === "string" ? c.decision_source : "config",
222
+ decidedAt: parseDecidedAt(c.decided_at)
223
+ };
224
+ }
225
+ function parseDecidedAt(v) {
226
+ if (typeof v === "string") {
227
+ return v;
228
+ }
229
+ if (v instanceof Date && !Number.isNaN(v.getTime())) {
230
+ return v.toISOString().replace(/\.\d{3}Z$/, "Z");
231
+ }
232
+ return void 0;
233
+ }
234
+
235
+ // src/telemetry/redact.ts
236
+
237
+ var TOKEN_SK = /\bsk-[A-Za-z0-9_-]{8,}\b/g;
238
+ var TOKEN_GH = /\bgh[pousr]_[A-Za-z0-9_-]{16,}\b/g;
239
+ var TOKEN_XOXB = /\bxoxb-[0-9]+-[0-9]+-[A-Za-z0-9]{24,}\b/g;
240
+ var EMAIL = /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g;
241
+ var IPV6 = /(?<![0-9a-fA-F:])(?:(?:[0-9a-fA-F]{1,4}:){1,7}(?::[0-9a-fA-F]{1,4})+|(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4})(?![0-9a-fA-F:])/g;
242
+ var IPV4 = /\b(?:\d{1,3}\.){3}\d{1,3}\b/g;
243
+ function escapeRegex(s) {
244
+ return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
245
+ }
246
+ var HOME = os.homedir();
247
+ var HOME_PATTERN = HOME && HOME !== "~" ? new RegExp(escapeRegex(HOME) + "([/\\w.\\-]*)", "g") : /(?!x)x/g;
248
+ var REPLACEMENTS = [
249
+ [TOKEN_SK, "<redacted:token>"],
250
+ [TOKEN_GH, "<redacted:token>"],
251
+ [TOKEN_XOXB, "<redacted:token>"],
252
+ [EMAIL, "<redacted:email>"],
253
+ [IPV6, "<redacted:ipv6>"],
254
+ [IPV4, "<redacted:ipv4>"],
255
+ [HOME_PATTERN, "$HOME$1"]
256
+ ];
257
+ function redactString(s) {
258
+ let out = s;
259
+ for (const [pat, repl] of REPLACEMENTS) {
260
+ out = out.replace(pat, repl);
261
+ }
262
+ return out;
263
+ }
264
+ function redact(value) {
265
+ if (typeof value === "string") return redactString(value);
266
+ if (Array.isArray(value)) return value.map(redact);
267
+ if (value !== null && typeof value === "object") {
268
+ const out = {};
269
+ for (const [k, v] of Object.entries(value)) {
270
+ out[k] = redact(v);
271
+ }
272
+ return out;
273
+ }
274
+ return value;
275
+ }
276
+
277
+ // src/telemetry/client.ts
278
+
279
+
280
+
281
+
282
+ var DEFAULT_QUEUE_SIZE = 1024;
283
+ var FLUSH_INTERVAL_MS = 5e3;
284
+ var FLUSH_BATCH_TRIGGER = 64;
285
+ var HTTPS_CONNECT_TIMEOUT_MS = 5e3;
286
+ var HTTPS_TOTAL_TIMEOUT_MS = 1e4;
287
+ var JSONL_ROTATE_BYTES = 10 * 1024 * 1024;
288
+ var FALLBACK_SDK_VERSION = "0.0.0-dev";
289
+ var SCHEMA_VERSION = "1";
290
+ var SDK_LANG = "ts";
291
+ function defaultJsonlSinkFile() {
292
+ const state = _nullishCoalesce(process.env.XDG_STATE_HOME, () => ( path3.join(_os.homedir.call(void 0, ), ".local", "state")));
293
+ return path3.join(state, "kit", "telemetry", "events.jsonl");
294
+ }
295
+ function consentAllowedSync() {
296
+ if (readGrantedFrom(consentPath(), "canonical")) return true;
297
+ if (readGrantedFrom(legacyConsentPath(), "legacy")) return true;
298
+ return false;
299
+ }
300
+ function readGrantedFrom(p, variant) {
301
+ if (!_fs.existsSync.call(void 0, p)) return false;
302
+ let parsed;
303
+ try {
304
+ const raw = _fs.readFileSync.call(void 0, p, "utf8");
305
+ parsed = yaml2.load(raw);
306
+ } catch (e8) {
307
+ return false;
308
+ }
309
+ if (typeof parsed !== "object" || parsed === null) return false;
310
+ const root = parsed;
311
+ let tel;
312
+ if (variant === "canonical") {
313
+ const kit = root.kit;
314
+ if (typeof kit !== "object" || kit === null) return false;
315
+ tel = kit.telemetry;
316
+ } else {
317
+ tel = root.telemetry;
318
+ }
319
+ if (typeof tel !== "object" || tel === null) return false;
320
+ const block = tel.consent;
321
+ if (typeof block !== "object" || block === null) return false;
322
+ return block.state === "granted";
323
+ }
324
+ function resolveSdkVersion(explicit) {
325
+ if (explicit && explicit.length > 0) return explicit;
326
+ try {
327
+ const here = __dirname;
328
+ const candidates = [
329
+ path3.join(here, "..", "..", "package.json"),
330
+ path3.join(here, "..", "..", "..", "package.json")
331
+ ];
332
+ for (const candidate of candidates) {
333
+ try {
334
+ const raw = _fs.readFileSync.call(void 0, candidate, "utf8");
335
+ const pkg = JSON.parse(raw);
336
+ if (typeof pkg.version === "string" && pkg.version.length > 0) {
337
+ return pkg.version;
338
+ }
339
+ } catch (e9) {
340
+ }
341
+ }
342
+ } catch (e10) {
343
+ }
344
+ return FALLBACK_SDK_VERSION;
345
+ }
346
+ var Client = class {
347
+ constructor(opts = {}) {
348
+ this.queue = [];
349
+ this.dropped = 0;
350
+ this.flushing = false;
351
+ this.closed = false;
352
+ const env = process.env;
353
+ this.endpoint = _nullishCoalesce(opts.endpoint, () => ( env.KIT_TELEMETRY_ENDPOINT));
354
+ const rawSink = _nullishCoalesce(opts.sink, () => ( env.KIT_TELEMETRY_SINK));
355
+ this.sinkKind = rawSink === "https" || rawSink === "jsonl" ? rawSink : "jsonl";
356
+ this.sinkFile = _nullishCoalesce(_nullishCoalesce(opts.sinkFile, () => ( env.KIT_TELEMETRY_SINK_FILE)), () => ( defaultJsonlSinkFile()));
357
+ const rawQueue = _nullishCoalesce(opts.queueSize, () => ( parseQueueSize(env.KIT_TELEMETRY_QUEUE_SIZE)));
358
+ this.queueCap = Number.isFinite(rawQueue) && rawQueue > 0 ? Math.floor(rawQueue) : DEFAULT_QUEUE_SIZE;
359
+ this.userRedactor = opts.redactor;
360
+ this.sdkVersion = resolveSdkVersion(opts.sdkVersion);
361
+ this.flushTimer = setInterval(() => {
362
+ void this.drainOnce();
363
+ }, FLUSH_INTERVAL_MS);
364
+ if (typeof this.flushTimer.unref === "function") {
365
+ this.flushTimer.unref();
366
+ }
367
+ }
368
+ /**
369
+ * record enqueues an event for background delivery. Returns
370
+ * synchronously; never throws. Gating order: closed → consent → mode.
371
+ * Queue-full bumps `droppedCount` and returns silently.
372
+ */
373
+ record(event, attrs = {}) {
374
+ if (this.closed) return;
375
+ if (!consentAllowedSync()) return;
376
+ const mode = resolveMode();
377
+ if (mode === Mode.Off) return;
378
+ if (this.queue.length >= this.queueCap) {
379
+ this.dropped += 1;
380
+ return;
381
+ }
382
+ this.queue.push({
383
+ event,
384
+ attrs,
385
+ mode,
386
+ occurred_at: (/* @__PURE__ */ new Date()).toISOString()
387
+ });
388
+ if (this.queue.length >= FLUSH_BATCH_TRIGGER) {
389
+ setImmediate(() => void this.drainOnce());
390
+ }
391
+ }
392
+ /** Saturation counter — reads, not writes. */
393
+ get droppedCount() {
394
+ return this.dropped;
395
+ }
396
+ /**
397
+ * shutdown stops the flush timer, drains pending events to the sink,
398
+ * and resolves once drained OR the timeout elapses (default 5000ms).
399
+ * Idempotent.
400
+ */
401
+ async shutdown(timeoutMs = 5e3) {
402
+ if (this.closed) return;
403
+ this.closed = true;
404
+ if (this.flushTimer) {
405
+ clearInterval(this.flushTimer);
406
+ this.flushTimer = void 0;
407
+ }
408
+ const deadline = Date.now() + timeoutMs;
409
+ while (this.queue.length > 0 && Date.now() < deadline) {
410
+ await this.drainOnce();
411
+ if (this.queue.length > 0) {
412
+ await new Promise((r) => setTimeout(r, 25));
413
+ }
414
+ }
415
+ }
416
+ /**
417
+ * drainOnce ships every event currently in the queue (snapshot at
418
+ * call time) to the configured sink. Errors bump `dropped` but never
419
+ * propagate.
420
+ */
421
+ async drainOnce() {
422
+ if (this.flushing) return;
423
+ if (this.queue.length === 0) return;
424
+ this.flushing = true;
425
+ try {
426
+ const batch = this.queue.splice(0, this.queue.length);
427
+ const envelopes = await this.envelopeBatch(batch);
428
+ if (envelopes.length === 0) return;
429
+ if (this.sinkKind === "https") {
430
+ await this.shipHttps(envelopes);
431
+ } else {
432
+ await this.shipJsonl(envelopes);
433
+ }
434
+ } catch (e11) {
435
+ } finally {
436
+ this.flushing = false;
437
+ }
438
+ }
439
+ /**
440
+ * envelopeBatch materialises pending records into on-wire envelopes,
441
+ * applying the user redactor first and then the default `redact()`
442
+ * pass. install_id is resolved lazily + cached.
443
+ */
444
+ async envelopeBatch(batch) {
445
+ let installationId = "";
446
+ try {
447
+ if (!this.installIdPromise) {
448
+ this.installIdPromise = getInstallId();
449
+ }
450
+ installationId = await this.installIdPromise;
451
+ } catch (e12) {
452
+ this.dropped += batch.length;
453
+ return [];
454
+ }
455
+ return batch.map((p) => {
456
+ let cleaned;
457
+ if (p.mode === Mode.Anon) {
458
+ cleaned = null;
459
+ } else {
460
+ const customised = this.userRedactor ? safeUserRedact(this.userRedactor, p.attrs, () => {
461
+ this.dropped += 1;
462
+ }) : p.attrs;
463
+ cleaned = redact(customised);
464
+ }
465
+ return {
466
+ schema_version: SCHEMA_VERSION,
467
+ sdk_lang: SDK_LANG,
468
+ sdk_version: this.sdkVersion,
469
+ installation_id: installationId,
470
+ mode: p.mode,
471
+ occurred_at: p.occurred_at,
472
+ event: p.event,
473
+ attrs: cleaned
474
+ };
475
+ });
476
+ }
477
+ /**
478
+ * shipHttps POSTs the batch as NDJSON. One retry on 5xx OR network
479
+ * error, then drops the batch. `AbortController` enforces the
480
+ * connect + total timeouts.
481
+ */
482
+ async shipHttps(envelopes) {
483
+ if (!this.endpoint) {
484
+ this.dropped += envelopes.length;
485
+ return;
486
+ }
487
+ const body = envelopes.map((e) => JSON.stringify(e)).join("\n") + "\n";
488
+ const headers = {
489
+ "content-type": "application/x-ndjson",
490
+ "user-agent": `kit-sdk-ts/${this.sdkVersion}`
491
+ };
492
+ for (let attempt = 0; attempt < 2; attempt += 1) {
493
+ const total = new AbortController();
494
+ const totalTimer = setTimeout(
495
+ () => total.abort(),
496
+ HTTPS_TOTAL_TIMEOUT_MS
497
+ );
498
+ const connect = setTimeout(
499
+ () => total.abort(),
500
+ HTTPS_CONNECT_TIMEOUT_MS
501
+ );
502
+ try {
503
+ const res = await _chunkKVG7YCTSjs.observabilityFetch.call(void 0, )(this.endpoint, {
504
+ method: "POST",
505
+ headers,
506
+ body,
507
+ signal: total.signal
508
+ });
509
+ clearTimeout(connect);
510
+ clearTimeout(totalTimer);
511
+ if (res.status < 500) {
512
+ if (res.status >= 400) {
513
+ this.dropped += envelopes.length;
514
+ }
515
+ return;
516
+ }
517
+ } catch (e13) {
518
+ clearTimeout(connect);
519
+ clearTimeout(totalTimer);
520
+ }
521
+ }
522
+ this.dropped += envelopes.length;
523
+ }
524
+ /**
525
+ * shipJsonl appends envelopes as NDJSON to `sinkFile`. Rotates to
526
+ * `<sinkFile>.1` once the file crosses `JSONL_ROTATE_BYTES`. Single
527
+ * append per batch keeps the I/O cost predictable.
528
+ */
529
+ async shipJsonl(envelopes) {
530
+ await _fs.promises.mkdir(path3.dirname(this.sinkFile), { recursive: true });
531
+ await this.maybeRotateJsonl();
532
+ const body = envelopes.map((e) => JSON.stringify(e)).join("\n") + "\n";
533
+ try {
534
+ await _fs.promises.appendFile(this.sinkFile, body, { mode: 384 });
535
+ } catch (e14) {
536
+ this.dropped += envelopes.length;
537
+ }
538
+ }
539
+ /** Rotate the JSONL sink when it crosses the size threshold. */
540
+ async maybeRotateJsonl() {
541
+ try {
542
+ const stat = await _fs.promises.stat(this.sinkFile);
543
+ if (stat.size < JSONL_ROTATE_BYTES) return;
544
+ } catch (e15) {
545
+ return;
546
+ }
547
+ const rotated = this.sinkFile + ".1";
548
+ try {
549
+ await _fs.promises.rename(this.sinkFile, rotated);
550
+ } catch (e16) {
551
+ }
552
+ }
553
+ };
554
+ function parseQueueSize(raw) {
555
+ if (!raw) return DEFAULT_QUEUE_SIZE;
556
+ const n = Number.parseInt(raw, 10);
557
+ return Number.isFinite(n) && n > 0 ? n : DEFAULT_QUEUE_SIZE;
558
+ }
559
+ function safeUserRedact(fn, attrs, onError) {
560
+ try {
561
+ return fn(attrs);
562
+ } catch (e17) {
563
+ onError();
564
+ return attrs;
565
+ }
566
+ }
567
+
568
+
569
+
570
+
571
+
572
+
573
+
574
+
575
+
576
+
577
+
578
+
579
+
580
+
581
+
582
+
583
+ exports.Mode = Mode; exports.parseMode = parseMode; exports.resolveMode = resolveMode; exports.installIdPath = installIdPath; exports.getInstallId = getInstallId; exports.rotate = rotate; exports.resetForTest = resetForTest; exports.deniedConsent = deniedConsent; exports.consentPath = consentPath; exports.loadConsent = loadConsent; exports.redactString = redactString; exports.redact = redact; exports.Client = Client; exports.telemetry_exports = telemetry_exports;
@@ -1,7 +1,7 @@
1
1
  import { Command } from 'commander';
2
- import { E as ErrOffline, O as OfflineError, g as guardFetch, a as isOffline, b as isOfflineError, w as withOffline } from './netpolicy-asvCfwi8.js';
2
+ import { E as ErrOffline, O as OfflineError, g as guardFetch, i as isOffline, a as isOfflineError, w as withOffline } from './netpolicy-Brx5XZUB.js';
3
3
  import { Writable } from 'node:stream';
4
- import { F as Format } from './output-4aXs91GY.js';
4
+ import { F as Format } from './output-CjZWmL8s.js';
5
5
 
6
6
  /**
7
7
  * @module tui/parity
@@ -192,6 +192,14 @@ declare function verbosityShorthand(d: ParityData): string;
192
192
  declare function verbosityFlagSpec(d: ParityData): string;
193
193
  /** Read the accumulated -V count for a parsed command tree. */
194
194
  declare function verboseCount(cmd: Command): number;
195
+ /**
196
+ * Report whether `--quiet` is in effect for a parsed command tree.
197
+ *
198
+ * `--quiet` wins over `-V`: when set, `verboseCount` reads 0 and the
199
+ * logger level is the contract's `verbosity.quiet_override`. False before
200
+ * parsing and when `disable.quiet` drops the flag.
201
+ */
202
+ declare function isQuiet(cmd: Command): boolean;
195
203
  interface StreamDef {
196
204
  name: string;
197
205
  description: string;
@@ -431,6 +439,7 @@ declare const cli_guardFetch: typeof guardFetch;
431
439
  declare const cli_hintsEnabled: typeof hintsEnabled;
432
440
  declare const cli_isOffline: typeof isOffline;
433
441
  declare const cli_isOfflineError: typeof isOfflineError;
442
+ declare const cli_isQuiet: typeof isQuiet;
434
443
  declare const cli_registerStream: typeof registerStream;
435
444
  declare const cli_registerUpgradeHints: typeof registerUpgradeHints;
436
445
  declare const cli_registerVersionHints: typeof registerVersionHints;
@@ -444,7 +453,7 @@ declare const cli_verbosityFlagSpec: typeof verbosityFlagSpec;
444
453
  declare const cli_verbosityShorthand: typeof verbosityShorthand;
445
454
  declare const cli_withOffline: typeof withOffline;
446
455
  declare namespace cli {
447
- export { type cli_CLIConfig as CLIConfig, type cli_CLIResult as CLIResult, cli_Dark as Dark, cli_ErrOffline as ErrOffline, type cli_Hint as Hint, type cli_HintOptions as HintOptions, cli_HintSet as HintSet, cli_Neon as Neon, cli_OfflineError as OfflineError, type cli_Palette as Palette, type cli_Theme as Theme, cli_active as active, cli_applyHelpTheme as applyHelpTheme, cli_buildTheme as buildTheme, cli_channel as channel, cli_createCLI as createCLI, cli_getCommandGroup as getCommandGroup, cli_getStreamDefs as getStreamDefs, cli_guardFetch as guardFetch, cli_hintsEnabled as hintsEnabled, cli_isOffline as isOffline, cli_isOfflineError as isOfflineError, cli_registerStream as registerStream, cli_registerUpgradeHints as registerUpgradeHints, cli_registerVersionHints as registerVersionHints, cli_renderHints as renderHints, cli_setCommandGroup as setCommandGroup, cli_streamFlagName as streamFlagName, cli_streamLabel as streamLabel, cli_streamOutput as streamOutput, cli_verboseCount as verboseCount, cli_verbosityFlagSpec as verbosityFlagSpec, cli_verbosityShorthand as verbosityShorthand, cli_withOffline as withOffline };
456
+ export { type cli_CLIConfig as CLIConfig, type cli_CLIResult as CLIResult, cli_Dark as Dark, cli_ErrOffline as ErrOffline, type cli_Hint as Hint, type cli_HintOptions as HintOptions, cli_HintSet as HintSet, cli_Neon as Neon, cli_OfflineError as OfflineError, type cli_Palette as Palette, type cli_Theme as Theme, cli_active as active, cli_applyHelpTheme as applyHelpTheme, cli_buildTheme as buildTheme, cli_channel as channel, cli_createCLI as createCLI, cli_getCommandGroup as getCommandGroup, cli_getStreamDefs as getStreamDefs, cli_guardFetch as guardFetch, cli_hintsEnabled as hintsEnabled, cli_isOffline as isOffline, cli_isOfflineError as isOfflineError, cli_isQuiet as isQuiet, cli_registerStream as registerStream, cli_registerUpgradeHints as registerUpgradeHints, cli_registerVersionHints as registerVersionHints, cli_renderHints as renderHints, cli_setCommandGroup as setCommandGroup, cli_streamFlagName as streamFlagName, cli_streamLabel as streamLabel, cli_streamOutput as streamOutput, cli_verboseCount as verboseCount, cli_verbosityFlagSpec as verbosityFlagSpec, cli_verbosityShorthand as verbosityShorthand, cli_withOffline as withOffline };
448
457
  }
449
458
 
450
- export { type CLIConfig as C, Dark as D, type Hint as H, Neon as N, type Palette as P, type Theme as T, type CLIResult as a, type HintOptions as b, HintSet as c, active as d, applyHelpTheme as e, buildTheme as f, channel as g, cli as h, createCLI as i, getCommandGroup as j, getStreamDefs as k, hintsEnabled as l, registerUpgradeHints as m, registerVersionHints as n, renderHints as o, streamFlagName as p, streamLabel as q, registerStream as r, setCommandGroup as s, streamOutput as t, verbosityFlagSpec as u, verboseCount as v, verbosityShorthand as w };
459
+ export { type CLIConfig as C, Dark as D, type Hint as H, Neon as N, type Palette as P, type Theme as T, type CLIResult as a, type HintOptions as b, cli as c, HintSet as d, active as e, applyHelpTheme as f, buildTheme as g, channel as h, createCLI as i, getCommandGroup as j, getStreamDefs as k, hintsEnabled as l, isQuiet as m, registerUpgradeHints as n, registerVersionHints as o, renderHints as p, streamFlagName as q, registerStream as r, setCommandGroup as s, streamLabel as t, streamOutput as u, verboseCount as v, verbosityFlagSpec as w, verbosityShorthand as x };
package/dist/cli.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import 'commander';
2
- export { C as CLIConfig, a as CLIResult, D as Dark, H as Hint, b as HintOptions, c as HintSet, N as Neon, P as Palette, T as Theme, d as active, e as applyHelpTheme, f as buildTheme, g as channel, i as createCLI, j as getCommandGroup, k as getStreamDefs, l as hintsEnabled, r as registerStream, m as registerUpgradeHints, n as registerVersionHints, o as renderHints, s as setCommandGroup, p as streamFlagName, q as streamLabel, t as streamOutput, v as verboseCount, u as verbosityFlagSpec, w as verbosityShorthand } from './cli-DLygZLi9.js';
3
- export { E as ErrOffline, O as OfflineError, g as guardFetch, a as isOffline, b as isOfflineError, w as withOffline } from './netpolicy-asvCfwi8.js';
2
+ export { C as CLIConfig, a as CLIResult, D as Dark, H as Hint, b as HintOptions, d as HintSet, N as Neon, P as Palette, T as Theme, e as active, f as applyHelpTheme, g as buildTheme, h as channel, i as createCLI, j as getCommandGroup, k as getStreamDefs, l as hintsEnabled, m as isQuiet, r as registerStream, n as registerUpgradeHints, o as registerVersionHints, p as renderHints, s as setCommandGroup, q as streamFlagName, t as streamLabel, u as streamOutput, v as verboseCount, w as verbosityFlagSpec, x as verbosityShorthand } from './cli-8rfITnv4.js';
3
+ export { E as ErrOffline, O as OfflineError, g as guardFetch, i as isOffline, a as isOfflineError, w as withOffline } from './netpolicy-Brx5XZUB.js';
4
4
  import 'node:stream';
5
- import './output-4aXs91GY.js';
6
- import './error-DISJKeDu.js';
5
+ import './output-CjZWmL8s.js';
6
+ import './error-Do8Qji43.js';