@hop-top/kit 0.5.0-alpha.2 → 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 (188) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/LICENSE +1 -1
  3. package/README.md +48 -480
  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-DgOEOsPB.d.ts → cli-8rfITnv4.d.ts} +13 -4
  46. package/dist/cli.d.ts +4 -3
  47. package/dist/cli.js +50 -1056
  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-Do8Qji43.d.ts +231 -0
  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--C7Mtsmm.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 -13
  59. package/dist/index.js +40 -5792
  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-VFFLqor9.d.ts → output-CjZWmL8s.d.ts} +29 -130
  75. package/dist/output.d.ts +2 -1
  76. package/dist/output.js +137 -958
  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-D8yWMrTc.d.ts +646 -0
  88. package/dist/serve.d.ts +3 -0
  89. package/dist/serve.js +75 -0
  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 -4
  94. package/dist/tui/index.js +17 -373
  95. package/dist/upgrade.js +6 -114
  96. package/dist/xdg.js +14 -128
  97. package/package.json +135 -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 +3 -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 +167 -1
  158. package/src/output/formatters/README.md +50 -0
  159. package/src/output.ts +26 -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.test.ts +1257 -0
  170. package/src/serve.ts +1665 -0
  171. package/src/telemetry/README.md +48 -0
  172. package/src/telemetry/client.ts +5 -5
  173. package/src/toolspec.test.ts +2 -2
  174. package/src/triton/README.md +34 -0
  175. package/src/tui/README.md +42 -0
  176. package/src/wizard.test.ts +7 -7
  177. package/test/llm/conformance-helpers.ts +100 -0
  178. package/test/output/dispatch.test.ts +1 -2
  179. package/test/output/error.test.ts +38 -2
  180. package/test/output/smoke-capture.ts +2 -2
  181. package/test/output/smoke.test.ts +2 -2
  182. package/test/output/taxonomy-contract.test.ts +148 -0
  183. package/test/setup-env.ts +16 -0
  184. package/tsconfig.json +3 -1
  185. package/tsconfig.test.json +10 -0
  186. package/vitest.config.ts +9 -0
  187. package/dist/llm-B5XUWH8T.d.ts +0 -231
  188. package/dist/routellm-PGSt2D1y.d.ts +0 -75
@@ -1,616 +1,32 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
29
2
 
30
- // src/telemetry/index.ts
31
- var telemetry_exports = {};
32
- __export(telemetry_exports, {
33
- Client: () => Client,
34
- Mode: () => Mode,
35
- consentPath: () => consentPath,
36
- deniedConsent: () => deniedConsent,
37
- getInstallId: () => getInstallId,
38
- installIdPath: () => installIdPath,
39
- loadConsent: () => loadConsent,
40
- parseMode: () => parseMode,
41
- redact: () => redact,
42
- redactString: () => redactString,
43
- resetForTest: () => resetForTest,
44
- resolveMode: () => resolveMode,
45
- rotate: () => rotate
46
- });
47
- module.exports = __toCommonJS(telemetry_exports);
48
3
 
49
- // src/telemetry/mode.ts
50
- var Mode = {
51
- Off: "off",
52
- Anon: "anon",
53
- Full: "full"
54
- };
55
- function parseMode(s) {
56
- if (s === void 0 || s === null || s === "") {
57
- return [Mode.Off, true];
58
- }
59
- const low = s.trim().toLowerCase();
60
- if (low === "") {
61
- return [Mode.Off, true];
62
- }
63
- for (const m of Object.values(Mode)) {
64
- if (m === low) {
65
- return [m, true];
66
- }
67
- }
68
- return [Mode.Off, false];
69
- }
70
- function resolveAppPrefix(env) {
71
- return (env.KIT_APP_PREFIX ?? "").trim().toUpperCase();
72
- }
73
- function resolveMode(env = process.env) {
74
- const app = resolveAppPrefix(env);
75
- if (app) {
76
- const v2 = (env[`${app}_TELEMETRY_MODE`] ?? "").trim();
77
- if (v2) {
78
- const [m, ok] = parseMode(v2);
79
- if (ok) {
80
- return m;
81
- }
82
- }
83
- }
84
- const v = (env.KIT_TELEMETRY_MODE ?? "").trim();
85
- if (v) {
86
- const [m, ok] = parseMode(v);
87
- if (ok) {
88
- return m;
89
- }
90
- }
91
- return Mode.Off;
92
- }
93
4
 
94
- // src/telemetry/installId.ts
95
- var import_node_fs = require("fs");
96
- var import_node_fs2 = require("fs");
97
- var import_node_crypto = require("crypto");
98
- var import_node_os = require("os");
99
- var path = __toESM(require("path"));
100
- var installIDSize = 32;
101
- var installIDFilePerm = 384;
102
- var installIDDirPerm = 448;
103
- function xdgStateHome() {
104
- return process.env.XDG_STATE_HOME ?? path.join((0, import_node_os.homedir)(), ".local", "state");
105
- }
106
- function installIdPath() {
107
- return path.join(xdgStateHome(), "kit", "telemetry", "installation_id");
108
- }
109
- function sha256Hex(buf) {
110
- return (0, import_node_crypto.createHash)("sha256").update(buf).digest("hex");
111
- }
112
- async function readAndValidate(p) {
113
- const data = await import_node_fs.promises.readFile(p);
114
- if (data.length !== installIDSize) {
115
- throw new Error(
116
- `install_id: file ${p} has wrong size ${data.length} bytes, expected ${installIDSize}`
117
- );
118
- }
119
- return data;
120
- }
121
- async function getInstallId() {
122
- const p = installIdPath();
123
- if ((0, import_node_fs2.existsSync)(p)) {
124
- const data = await readAndValidate(p);
125
- return sha256Hex(data);
126
- }
127
- const parent = path.dirname(p);
128
- await import_node_fs.promises.mkdir(parent, { recursive: true, mode: installIDDirPerm });
129
- try {
130
- await import_node_fs.promises.chmod(parent, installIDDirPerm);
131
- } catch {
132
- }
133
- const fresh = (0, import_node_crypto.randomBytes)(installIDSize);
134
- const tmp = p + ".new";
135
- await import_node_fs.promises.writeFile(tmp, fresh, { mode: installIDFilePerm });
136
- if ((0, import_node_fs2.existsSync)(p)) {
137
- try {
138
- await import_node_fs.promises.unlink(tmp);
139
- } catch {
140
- }
141
- const data = await readAndValidate(p);
142
- return sha256Hex(data);
143
- }
144
- await import_node_fs.promises.rename(tmp, p);
145
- return sha256Hex(fresh);
146
- }
147
- async function rotate() {
148
- const p = installIdPath();
149
- const parent = path.dirname(p);
150
- await import_node_fs.promises.mkdir(parent, { recursive: true, mode: installIDDirPerm });
151
- try {
152
- await import_node_fs.promises.chmod(parent, installIDDirPerm);
153
- } catch {
154
- }
155
- const fresh = (0, import_node_crypto.randomBytes)(installIDSize);
156
- const tmp = p + ".new";
157
- await import_node_fs.promises.writeFile(tmp, fresh, { mode: installIDFilePerm });
158
- await import_node_fs.promises.rename(tmp, p);
159
- return sha256Hex(fresh);
160
- }
161
- async function resetForTest() {
162
- const p = installIdPath();
163
- try {
164
- await import_node_fs.promises.unlink(p);
165
- } catch {
166
- }
167
- try {
168
- await import_node_fs.promises.unlink(p + ".new");
169
- } catch {
170
- }
171
- }
172
5
 
173
- // src/telemetry/consent.ts
174
- var import_node_fs3 = require("fs");
175
- var import_node_fs4 = require("fs");
176
- var import_node_os2 = require("os");
177
- var path2 = __toESM(require("path"));
178
- var yaml = __toESM(require("js-yaml"));
179
- var deniedConsent = {
180
- allowed: false,
181
- promptVersion: 0,
182
- decisionSource: "config"
183
- };
184
- function xdgConfigHome() {
185
- return process.env.XDG_CONFIG_HOME ?? path2.join((0, import_node_os2.homedir)(), ".config");
186
- }
187
- function consentPath() {
188
- return path2.join(xdgConfigHome(), "kit", "config.yaml");
189
- }
190
- function legacyConsentPath() {
191
- return path2.join(xdgConfigHome(), "kit", "telemetry.yaml");
192
- }
193
- async function loadConsent() {
194
- const canonical = await readConsentBlock(consentPath(), "canonical");
195
- if (canonical !== null) {
196
- return canonical;
197
- }
198
- const legacy = await readConsentBlock(legacyConsentPath(), "legacy");
199
- if (legacy !== null) {
200
- return legacy;
201
- }
202
- return deniedConsent;
203
- }
204
- async function readConsentBlock(p, variant) {
205
- if (!(0, import_node_fs4.existsSync)(p)) {
206
- return null;
207
- }
208
- let data;
209
- try {
210
- const raw = await import_node_fs3.promises.readFile(p, "utf8");
211
- data = yaml.load(raw);
212
- } catch {
213
- return null;
214
- }
215
- if (typeof data !== "object" || data === null) {
216
- return null;
217
- }
218
- const root = data;
219
- let telemetry;
220
- if (variant === "canonical") {
221
- const kit = root.kit;
222
- if (typeof kit !== "object" || kit === null) {
223
- return null;
224
- }
225
- telemetry = kit.telemetry;
226
- } else {
227
- telemetry = root.telemetry;
228
- }
229
- if (typeof telemetry !== "object" || telemetry === null) {
230
- return null;
231
- }
232
- const block = telemetry.consent;
233
- if (typeof block !== "object" || block === null) {
234
- return null;
235
- }
236
- const c = block;
237
- const state = c.state;
238
- if (state !== "granted" && state !== "denied") {
239
- return null;
240
- }
241
- return {
242
- allowed: state === "granted",
243
- promptVersion: typeof c.prompt_version === "number" ? c.prompt_version : 0,
244
- decisionSource: typeof c.decision_source === "string" ? c.decision_source : "config",
245
- decidedAt: parseDecidedAt(c.decided_at)
246
- };
247
- }
248
- function parseDecidedAt(v) {
249
- if (typeof v === "string") {
250
- return v;
251
- }
252
- if (v instanceof Date && !Number.isNaN(v.getTime())) {
253
- return v.toISOString().replace(/\.\d{3}Z$/, "Z");
254
- }
255
- return void 0;
256
- }
257
6
 
258
- // src/telemetry/redact.ts
259
- var os = __toESM(require("os"));
260
- var TOKEN_SK = /\bsk-[A-Za-z0-9_-]{8,}\b/g;
261
- var TOKEN_GH = /\bgh[pousr]_[A-Za-z0-9_-]{16,}\b/g;
262
- var TOKEN_XOXB = /\bxoxb-[0-9]+-[0-9]+-[A-Za-z0-9]{24,}\b/g;
263
- var EMAIL = /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g;
264
- 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;
265
- var IPV4 = /\b(?:\d{1,3}\.){3}\d{1,3}\b/g;
266
- function escapeRegex(s) {
267
- return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
268
- }
269
- var HOME = os.homedir();
270
- var HOME_PATTERN = HOME && HOME !== "~" ? new RegExp(escapeRegex(HOME) + "([/\\w.\\-]*)", "g") : /(?!x)x/g;
271
- var REPLACEMENTS = [
272
- [TOKEN_SK, "<redacted:token>"],
273
- [TOKEN_GH, "<redacted:token>"],
274
- [TOKEN_XOXB, "<redacted:token>"],
275
- [EMAIL, "<redacted:email>"],
276
- [IPV6, "<redacted:ipv6>"],
277
- [IPV4, "<redacted:ipv4>"],
278
- [HOME_PATTERN, "$HOME$1"]
279
- ];
280
- function redactString(s) {
281
- let out = s;
282
- for (const [pat, repl] of REPLACEMENTS) {
283
- out = out.replace(pat, repl);
284
- }
285
- return out;
286
- }
287
- function redact(value) {
288
- if (typeof value === "string") return redactString(value);
289
- if (Array.isArray(value)) return value.map(redact);
290
- if (value !== null && typeof value === "object") {
291
- const out = {};
292
- for (const [k, v] of Object.entries(value)) {
293
- out[k] = redact(v);
294
- }
295
- return out;
296
- }
297
- return value;
298
- }
299
7
 
300
- // src/telemetry/client.ts
301
- var import_node_fs5 = require("fs");
302
- var import_node_os3 = require("os");
303
- var path3 = __toESM(require("path"));
304
- var yaml2 = __toESM(require("js-yaml"));
305
8
 
306
- // src/netpolicy.ts
307
- var import_node_async_hooks = require("async_hooks");
308
- var store = new import_node_async_hooks.AsyncLocalStorage();
309
- var unguardedBase = /* @__PURE__ */ Symbol.for("hop.top/kit/netpolicy.unguardedBase");
310
- function observabilityFetch() {
311
- const current = globalThis.fetch;
312
- return current?.[unguardedBase] ?? globalThis.fetch;
313
- }
314
9
 
315
- // src/telemetry/client.ts
316
- var DEFAULT_QUEUE_SIZE = 1024;
317
- var FLUSH_INTERVAL_MS = 5e3;
318
- var FLUSH_BATCH_TRIGGER = 64;
319
- var HTTPS_CONNECT_TIMEOUT_MS = 5e3;
320
- var HTTPS_TOTAL_TIMEOUT_MS = 1e4;
321
- var JSONL_ROTATE_BYTES = 10 * 1024 * 1024;
322
- var FALLBACK_SDK_VERSION = "0.0.0-dev";
323
- var SCHEMA_VERSION = "1";
324
- var SDK_LANG = "ts";
325
- function defaultJsonlSinkFile() {
326
- const state = process.env.XDG_STATE_HOME ?? path3.join((0, import_node_os3.homedir)(), ".local", "state");
327
- return path3.join(state, "kit", "telemetry", "events.jsonl");
328
- }
329
- function consentAllowedSync() {
330
- if (readGrantedFrom(consentPath(), "canonical")) return true;
331
- if (readGrantedFrom(legacyConsentPath(), "legacy")) return true;
332
- return false;
333
- }
334
- function readGrantedFrom(p, variant) {
335
- if (!(0, import_node_fs5.existsSync)(p)) return false;
336
- let parsed;
337
- try {
338
- const raw = (0, import_node_fs5.readFileSync)(p, "utf8");
339
- parsed = yaml2.load(raw);
340
- } catch {
341
- return false;
342
- }
343
- if (typeof parsed !== "object" || parsed === null) return false;
344
- const root = parsed;
345
- let tel;
346
- if (variant === "canonical") {
347
- const kit = root.kit;
348
- if (typeof kit !== "object" || kit === null) return false;
349
- tel = kit.telemetry;
350
- } else {
351
- tel = root.telemetry;
352
- }
353
- if (typeof tel !== "object" || tel === null) return false;
354
- const block = tel.consent;
355
- if (typeof block !== "object" || block === null) return false;
356
- return block.state === "granted";
357
- }
358
- function resolveSdkVersion(explicit) {
359
- if (explicit && explicit.length > 0) return explicit;
360
- try {
361
- const here = __dirname;
362
- const candidates = [
363
- path3.join(here, "..", "..", "package.json"),
364
- path3.join(here, "..", "..", "..", "package.json")
365
- ];
366
- for (const candidate of candidates) {
367
- try {
368
- const raw = (0, import_node_fs5.readFileSync)(candidate, "utf8");
369
- const pkg = JSON.parse(raw);
370
- if (typeof pkg.version === "string" && pkg.version.length > 0) {
371
- return pkg.version;
372
- }
373
- } catch {
374
- }
375
- }
376
- } catch {
377
- }
378
- return FALLBACK_SDK_VERSION;
379
- }
380
- var Client = class {
381
- constructor(opts = {}) {
382
- this.queue = [];
383
- this.dropped = 0;
384
- this.flushing = false;
385
- this.closed = false;
386
- const env = process.env;
387
- this.endpoint = opts.endpoint ?? env.KIT_TELEMETRY_ENDPOINT;
388
- const rawSink = opts.sink ?? env.KIT_TELEMETRY_SINK;
389
- this.sinkKind = rawSink === "https" || rawSink === "jsonl" ? rawSink : "jsonl";
390
- this.sinkFile = opts.sinkFile ?? env.KIT_TELEMETRY_SINK_FILE ?? defaultJsonlSinkFile();
391
- const rawQueue = opts.queueSize ?? parseQueueSize(env.KIT_TELEMETRY_QUEUE_SIZE);
392
- this.queueCap = Number.isFinite(rawQueue) && rawQueue > 0 ? Math.floor(rawQueue) : DEFAULT_QUEUE_SIZE;
393
- this.userRedactor = opts.redactor;
394
- this.sdkVersion = resolveSdkVersion(opts.sdkVersion);
395
- this.flushTimer = setInterval(() => {
396
- void this.drainOnce();
397
- }, FLUSH_INTERVAL_MS);
398
- if (typeof this.flushTimer.unref === "function") {
399
- this.flushTimer.unref();
400
- }
401
- }
402
- /**
403
- * record enqueues an event for background delivery. Returns
404
- * synchronously; never throws. Gating order: closed → consent → mode.
405
- * Queue-full bumps `droppedCount` and returns silently.
406
- */
407
- record(event, attrs = {}) {
408
- if (this.closed) return;
409
- if (!consentAllowedSync()) return;
410
- const mode = resolveMode();
411
- if (mode === Mode.Off) return;
412
- if (this.queue.length >= this.queueCap) {
413
- this.dropped += 1;
414
- return;
415
- }
416
- this.queue.push({
417
- event,
418
- attrs,
419
- mode,
420
- occurred_at: (/* @__PURE__ */ new Date()).toISOString()
421
- });
422
- if (this.queue.length >= FLUSH_BATCH_TRIGGER) {
423
- setImmediate(() => void this.drainOnce());
424
- }
425
- }
426
- /** Saturation counter — reads, not writes. */
427
- get droppedCount() {
428
- return this.dropped;
429
- }
430
- /**
431
- * shutdown stops the flush timer, drains pending events to the sink,
432
- * and resolves once drained OR the timeout elapses (default 5000ms).
433
- * Idempotent.
434
- */
435
- async shutdown(timeoutMs = 5e3) {
436
- if (this.closed) return;
437
- this.closed = true;
438
- if (this.flushTimer) {
439
- clearInterval(this.flushTimer);
440
- this.flushTimer = void 0;
441
- }
442
- const deadline = Date.now() + timeoutMs;
443
- while (this.queue.length > 0 && Date.now() < deadline) {
444
- await this.drainOnce();
445
- if (this.queue.length > 0) {
446
- await new Promise((r) => setTimeout(r, 25));
447
- }
448
- }
449
- }
450
- /**
451
- * drainOnce ships every event currently in the queue (snapshot at
452
- * call time) to the configured sink. Errors bump `dropped` but never
453
- * propagate.
454
- */
455
- async drainOnce() {
456
- if (this.flushing) return;
457
- if (this.queue.length === 0) return;
458
- this.flushing = true;
459
- try {
460
- const batch = this.queue.splice(0, this.queue.length);
461
- const envelopes = await this.envelopeBatch(batch);
462
- if (envelopes.length === 0) return;
463
- if (this.sinkKind === "https") {
464
- await this.shipHttps(envelopes);
465
- } else {
466
- await this.shipJsonl(envelopes);
467
- }
468
- } catch {
469
- } finally {
470
- this.flushing = false;
471
- }
472
- }
473
- /**
474
- * envelopeBatch materialises pending records into on-wire envelopes,
475
- * applying the user redactor first and then the default `redact()`
476
- * pass. install_id is resolved lazily + cached.
477
- */
478
- async envelopeBatch(batch) {
479
- let installationId = "";
480
- try {
481
- if (!this.installIdPromise) {
482
- this.installIdPromise = getInstallId();
483
- }
484
- installationId = await this.installIdPromise;
485
- } catch {
486
- this.dropped += batch.length;
487
- return [];
488
- }
489
- return batch.map((p) => {
490
- let cleaned;
491
- if (p.mode === Mode.Anon) {
492
- cleaned = null;
493
- } else {
494
- const customised = this.userRedactor ? safeUserRedact(this.userRedactor, p.attrs, () => {
495
- this.dropped += 1;
496
- }) : p.attrs;
497
- cleaned = redact(customised);
498
- }
499
- return {
500
- schema_version: SCHEMA_VERSION,
501
- sdk_lang: SDK_LANG,
502
- sdk_version: this.sdkVersion,
503
- installation_id: installationId,
504
- mode: p.mode,
505
- occurred_at: p.occurred_at,
506
- event: p.event,
507
- attrs: cleaned
508
- };
509
- });
510
- }
511
- /**
512
- * shipHttps POSTs the batch as NDJSON. One retry on 5xx OR network
513
- * error, then drops the batch. `AbortController` enforces the
514
- * connect + total timeouts.
515
- */
516
- async shipHttps(envelopes) {
517
- if (!this.endpoint) {
518
- this.dropped += envelopes.length;
519
- return;
520
- }
521
- const body = envelopes.map((e) => JSON.stringify(e)).join("\n") + "\n";
522
- const headers = {
523
- "content-type": "application/x-ndjson",
524
- "user-agent": `kit-sdk-ts/${this.sdkVersion}`
525
- };
526
- for (let attempt = 0; attempt < 2; attempt += 1) {
527
- const total = new AbortController();
528
- const totalTimer = setTimeout(
529
- () => total.abort(),
530
- HTTPS_TOTAL_TIMEOUT_MS
531
- );
532
- const connect = setTimeout(
533
- () => total.abort(),
534
- HTTPS_CONNECT_TIMEOUT_MS
535
- );
536
- try {
537
- const res = await observabilityFetch()(this.endpoint, {
538
- method: "POST",
539
- headers,
540
- body,
541
- signal: total.signal
542
- });
543
- clearTimeout(connect);
544
- clearTimeout(totalTimer);
545
- if (res.status < 500) {
546
- if (res.status >= 400) {
547
- this.dropped += envelopes.length;
548
- }
549
- return;
550
- }
551
- } catch {
552
- clearTimeout(connect);
553
- clearTimeout(totalTimer);
554
- }
555
- }
556
- this.dropped += envelopes.length;
557
- }
558
- /**
559
- * shipJsonl appends envelopes as NDJSON to `sinkFile`. Rotates to
560
- * `<sinkFile>.1` once the file crosses `JSONL_ROTATE_BYTES`. Single
561
- * append per batch keeps the I/O cost predictable.
562
- */
563
- async shipJsonl(envelopes) {
564
- await import_node_fs5.promises.mkdir(path3.dirname(this.sinkFile), { recursive: true });
565
- await this.maybeRotateJsonl();
566
- const body = envelopes.map((e) => JSON.stringify(e)).join("\n") + "\n";
567
- try {
568
- await import_node_fs5.promises.appendFile(this.sinkFile, body, { mode: 384 });
569
- } catch {
570
- this.dropped += envelopes.length;
571
- }
572
- }
573
- /** Rotate the JSONL sink when it crosses the size threshold. */
574
- async maybeRotateJsonl() {
575
- try {
576
- const stat = await import_node_fs5.promises.stat(this.sinkFile);
577
- if (stat.size < JSONL_ROTATE_BYTES) return;
578
- } catch {
579
- return;
580
- }
581
- const rotated = this.sinkFile + ".1";
582
- try {
583
- await import_node_fs5.promises.rename(this.sinkFile, rotated);
584
- } catch {
585
- }
586
- }
587
- };
588
- function parseQueueSize(raw) {
589
- if (!raw) return DEFAULT_QUEUE_SIZE;
590
- const n = Number.parseInt(raw, 10);
591
- return Number.isFinite(n) && n > 0 ? n : DEFAULT_QUEUE_SIZE;
592
- }
593
- function safeUserRedact(fn, attrs, onError) {
594
- try {
595
- return fn(attrs);
596
- } catch {
597
- onError();
598
- return attrs;
599
- }
600
- }
601
- // Annotate the CommonJS export names for ESM import in node:
602
- 0 && (module.exports = {
603
- Client,
604
- Mode,
605
- consentPath,
606
- deniedConsent,
607
- getInstallId,
608
- installIdPath,
609
- loadConsent,
610
- parseMode,
611
- redact,
612
- redactString,
613
- resetForTest,
614
- resolveMode,
615
- rotate
616
- });
10
+
11
+
12
+
13
+
14
+
15
+ var _chunkYOBAUCVNjs = require('../chunk-YOBAUCVN.js');
16
+ require('../chunk-KVG7YCTS.js');
17
+ require('../chunk-R5U7XKVJ.js');
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+ exports.Client = _chunkYOBAUCVNjs.Client; exports.Mode = _chunkYOBAUCVNjs.Mode; exports.consentPath = _chunkYOBAUCVNjs.consentPath; exports.deniedConsent = _chunkYOBAUCVNjs.deniedConsent; exports.getInstallId = _chunkYOBAUCVNjs.getInstallId; exports.installIdPath = _chunkYOBAUCVNjs.installIdPath; exports.loadConsent = _chunkYOBAUCVNjs.loadConsent; exports.parseMode = _chunkYOBAUCVNjs.parseMode; exports.redact = _chunkYOBAUCVNjs.redact; exports.redactString = _chunkYOBAUCVNjs.redactString; exports.resetForTest = _chunkYOBAUCVNjs.resetForTest; exports.resolveMode = _chunkYOBAUCVNjs.resolveMode; exports.rotate = _chunkYOBAUCVNjs.rotate;
@@ -1,6 +1,7 @@
1
- export { A as Anim, a as AnimOpts, B as BadgeOpts, C as ConfirmOpts, L as ListItem, b as ListOpts, P as Progress, S as Spinner, c as StatusKind, d as anim, e as badge, f as clamp01, g as confirm, l as list, m as makeGradient, p as pills, h as progress, r as renderBarPlain, s as spinner, j as status } from '../index--C7Mtsmm.js';
2
- import '../cli-DgOEOsPB.js';
1
+ export { A as Anim, a as AnimOpts, B as BadgeOpts, C as ConfirmOpts, L as ListItem, b as ListOpts, P as Progress, S as Spinner, c as StatusKind, d as anim, e as badge, f as clamp01, g as confirm, l as list, m as makeGradient, p as pills, h as progress, r as renderBarPlain, s as spinner, j as status } from '../index-DEyjGoo2.js';
2
+ import '../cli-8rfITnv4.js';
3
3
  import 'commander';
4
- import '../netpolicy-asvCfwi8.js';
4
+ import '../netpolicy-Brx5XZUB.js';
5
5
  import 'node:stream';
6
- import '../output-VFFLqor9.js';
6
+ import '../output-CjZWmL8s.js';
7
+ import '../error-Do8Qji43.js';