ccjk 12.3.5 → 13.3.3

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 (37) hide show
  1. package/dist/chunks/api-cli.mjs +1 -1
  2. package/dist/chunks/api.mjs +2 -2
  3. package/dist/chunks/auto-fix.mjs +148 -0
  4. package/dist/chunks/auto-upgrade.mjs +150 -0
  5. package/dist/chunks/ccjk-agents.mjs +1 -2
  6. package/dist/chunks/ccjk-all.mjs +5 -6
  7. package/dist/chunks/ccjk-hooks.mjs +4 -5
  8. package/dist/chunks/ccjk-mcp.mjs +6 -7
  9. package/dist/chunks/ccjk-setup.mjs +1 -2
  10. package/dist/chunks/ccjk-skills.mjs +5 -6
  11. package/dist/chunks/ccr.mjs +1 -2
  12. package/dist/chunks/commands2.mjs +11 -3
  13. package/dist/chunks/index14.mjs +6 -5
  14. package/dist/chunks/index2.mjs +2 -2
  15. package/dist/chunks/installer2.mjs +74 -150
  16. package/dist/chunks/intent-engine.mjs +142 -0
  17. package/dist/chunks/menu-hierarchical.mjs +1 -2
  18. package/dist/chunks/menu.mjs +15 -0
  19. package/dist/chunks/package.mjs +1 -1
  20. package/dist/chunks/smart-guide.mjs +8 -8
  21. package/dist/chunks/upgrade.mjs +34 -0
  22. package/dist/cli.mjs +39 -12
  23. package/dist/i18n/locales/en/agentBrowser.json +1 -0
  24. package/dist/i18n/locales/en/configuration.json +4 -4
  25. package/dist/i18n/locales/zh-CN/agentBrowser.json +1 -0
  26. package/dist/i18n/locales/zh-CN/configuration.json +4 -4
  27. package/dist/index.d.mts +211 -125
  28. package/dist/index.d.ts +211 -125
  29. package/dist/index.mjs +6 -3
  30. package/dist/shared/{ccjk.CtXhbEqb.mjs → ccjk.CqdbaXqU.mjs} +1 -1
  31. package/dist/shared/{ccjk.DfXjf8EC.mjs → ccjk.Cwa_FiTX.mjs} +1 -1
  32. package/dist/shared/{ccjk.hrRv8G6j.mjs → ccjk.DHXfsrwn.mjs} +1502 -3
  33. package/dist/shared/{ccjk.CL4Yat0G.mjs → ccjk.DopKzo3z.mjs} +3 -1
  34. package/dist/templates/claude-code/common/settings.json +0 -1
  35. package/package.json +1 -1
  36. package/templates/claude-code/common/settings.json +0 -1
  37. package/dist/shared/ccjk.UIvifqNE.mjs +0 -1486
@@ -1,9 +1,582 @@
1
- import { c as consola } from './ccjk.UIvifqNE.mjs';
2
1
  import { promises, existsSync } from 'node:fs';
3
2
  import posix from '../chunks/index9.mjs';
4
3
  import { glob } from 'tinyglobby';
5
4
  import { p as parse } from './ccjk.BBtCGd_g.mjs';
6
5
 
6
+ const LogLevels = {
7
+ fatal: 0,
8
+ error: 0,
9
+ warn: 1,
10
+ log: 2,
11
+ info: 3,
12
+ success: 3,
13
+ fail: 3,
14
+ debug: 4,
15
+ trace: 5,
16
+ verbose: Number.POSITIVE_INFINITY
17
+ };
18
+ const LogTypes = {
19
+ // Silent
20
+ silent: {
21
+ level: -1
22
+ },
23
+ // Level 0
24
+ fatal: {
25
+ level: LogLevels.fatal
26
+ },
27
+ error: {
28
+ level: LogLevels.error
29
+ },
30
+ // Level 1
31
+ warn: {
32
+ level: LogLevels.warn
33
+ },
34
+ // Level 2
35
+ log: {
36
+ level: LogLevels.log
37
+ },
38
+ // Level 3
39
+ info: {
40
+ level: LogLevels.info
41
+ },
42
+ success: {
43
+ level: LogLevels.success
44
+ },
45
+ fail: {
46
+ level: LogLevels.fail
47
+ },
48
+ ready: {
49
+ level: LogLevels.info
50
+ },
51
+ start: {
52
+ level: LogLevels.info
53
+ },
54
+ box: {
55
+ level: LogLevels.info
56
+ },
57
+ // Level 4
58
+ debug: {
59
+ level: LogLevels.debug
60
+ },
61
+ // Level 5
62
+ trace: {
63
+ level: LogLevels.trace
64
+ },
65
+ // Verbose
66
+ verbose: {
67
+ level: LogLevels.verbose
68
+ }
69
+ };
70
+
71
+ function isPlainObject$1(value) {
72
+ if (value === null || typeof value !== "object") {
73
+ return false;
74
+ }
75
+ const prototype = Object.getPrototypeOf(value);
76
+ if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
77
+ return false;
78
+ }
79
+ if (Symbol.iterator in value) {
80
+ return false;
81
+ }
82
+ if (Symbol.toStringTag in value) {
83
+ return Object.prototype.toString.call(value) === "[object Module]";
84
+ }
85
+ return true;
86
+ }
87
+
88
+ function _defu(baseObject, defaults, namespace = ".", merger) {
89
+ if (!isPlainObject$1(defaults)) {
90
+ return _defu(baseObject, {}, namespace);
91
+ }
92
+ const object = Object.assign({}, defaults);
93
+ for (const key in baseObject) {
94
+ if (key === "__proto__" || key === "constructor") {
95
+ continue;
96
+ }
97
+ const value = baseObject[key];
98
+ if (value === null || value === void 0) {
99
+ continue;
100
+ }
101
+ if (Array.isArray(value) && Array.isArray(object[key])) {
102
+ object[key] = [...value, ...object[key]];
103
+ } else if (isPlainObject$1(value) && isPlainObject$1(object[key])) {
104
+ object[key] = _defu(
105
+ value,
106
+ object[key],
107
+ (namespace ? `${namespace}.` : "") + key.toString());
108
+ } else {
109
+ object[key] = value;
110
+ }
111
+ }
112
+ return object;
113
+ }
114
+ function createDefu(merger) {
115
+ return (...arguments_) => (
116
+ // eslint-disable-next-line unicorn/no-array-reduce
117
+ arguments_.reduce((p, c) => _defu(p, c, ""), {})
118
+ );
119
+ }
120
+ const defu = createDefu();
121
+
122
+ function isPlainObject(obj) {
123
+ return Object.prototype.toString.call(obj) === "[object Object]";
124
+ }
125
+ function isLogObj(arg) {
126
+ if (!isPlainObject(arg)) {
127
+ return false;
128
+ }
129
+ if (!arg.message && !arg.args) {
130
+ return false;
131
+ }
132
+ if (arg.stack) {
133
+ return false;
134
+ }
135
+ return true;
136
+ }
137
+
138
+ let paused = false;
139
+ const queue = [];
140
+ class Consola {
141
+ options;
142
+ _lastLog;
143
+ _mockFn;
144
+ /**
145
+ * Creates an instance of Consola with specified options or defaults.
146
+ *
147
+ * @param {Partial<ConsolaOptions>} [options={}] - Configuration options for the Consola instance.
148
+ */
149
+ constructor(options = {}) {
150
+ const types = options.types || LogTypes;
151
+ this.options = defu(
152
+ {
153
+ ...options,
154
+ defaults: { ...options.defaults },
155
+ level: _normalizeLogLevel(options.level, types),
156
+ reporters: [...options.reporters || []]
157
+ },
158
+ {
159
+ types: LogTypes,
160
+ throttle: 1e3,
161
+ throttleMin: 5,
162
+ formatOptions: {
163
+ date: true,
164
+ colors: false,
165
+ compact: true
166
+ }
167
+ }
168
+ );
169
+ for (const type in types) {
170
+ const defaults = {
171
+ type,
172
+ ...this.options.defaults,
173
+ ...types[type]
174
+ };
175
+ this[type] = this._wrapLogFn(defaults);
176
+ this[type].raw = this._wrapLogFn(
177
+ defaults,
178
+ true
179
+ );
180
+ }
181
+ if (this.options.mockFn) {
182
+ this.mockTypes();
183
+ }
184
+ this._lastLog = {};
185
+ }
186
+ /**
187
+ * Gets the current log level of the Consola instance.
188
+ *
189
+ * @returns {number} The current log level.
190
+ */
191
+ get level() {
192
+ return this.options.level;
193
+ }
194
+ /**
195
+ * Sets the minimum log level that will be output by the instance.
196
+ *
197
+ * @param {number} level - The new log level to set.
198
+ */
199
+ set level(level) {
200
+ this.options.level = _normalizeLogLevel(
201
+ level,
202
+ this.options.types,
203
+ this.options.level
204
+ );
205
+ }
206
+ /**
207
+ * Displays a prompt to the user and returns the response.
208
+ * Throw an error if `prompt` is not supported by the current configuration.
209
+ *
210
+ * @template T
211
+ * @param {string} message - The message to display in the prompt.
212
+ * @param {T} [opts] - Optional options for the prompt. See {@link PromptOptions}.
213
+ * @returns {promise<T>} A promise that infer with the prompt options. See {@link PromptOptions}.
214
+ */
215
+ prompt(message, opts) {
216
+ if (!this.options.prompt) {
217
+ throw new Error("prompt is not supported!");
218
+ }
219
+ return this.options.prompt(message, opts);
220
+ }
221
+ /**
222
+ * Creates a new instance of Consola, inheriting options from the current instance, with possible overrides.
223
+ *
224
+ * @param {Partial<ConsolaOptions>} options - Optional overrides for the new instance. See {@link ConsolaOptions}.
225
+ * @returns {ConsolaInstance} A new Consola instance. See {@link ConsolaInstance}.
226
+ */
227
+ create(options) {
228
+ const instance = new Consola({
229
+ ...this.options,
230
+ ...options
231
+ });
232
+ if (this._mockFn) {
233
+ instance.mockTypes(this._mockFn);
234
+ }
235
+ return instance;
236
+ }
237
+ /**
238
+ * Creates a new Consola instance with the specified default log object properties.
239
+ *
240
+ * @param {InputLogObject} defaults - Default properties to include in any log from the new instance. See {@link InputLogObject}.
241
+ * @returns {ConsolaInstance} A new Consola instance. See {@link ConsolaInstance}.
242
+ */
243
+ withDefaults(defaults) {
244
+ return this.create({
245
+ ...this.options,
246
+ defaults: {
247
+ ...this.options.defaults,
248
+ ...defaults
249
+ }
250
+ });
251
+ }
252
+ /**
253
+ * Creates a new Consola instance with a specified tag, which will be included in every log.
254
+ *
255
+ * @param {string} tag - The tag to include in each log of the new instance.
256
+ * @returns {ConsolaInstance} A new Consola instance. See {@link ConsolaInstance}.
257
+ */
258
+ withTag(tag) {
259
+ return this.withDefaults({
260
+ tag: this.options.defaults.tag ? this.options.defaults.tag + ":" + tag : tag
261
+ });
262
+ }
263
+ /**
264
+ * Adds a custom reporter to the Consola instance.
265
+ * Reporters will be called for each log message, depending on their implementation and log level.
266
+ *
267
+ * @param {ConsolaReporter} reporter - The reporter to add. See {@link ConsolaReporter}.
268
+ * @returns {Consola} The current Consola instance.
269
+ */
270
+ addReporter(reporter) {
271
+ this.options.reporters.push(reporter);
272
+ return this;
273
+ }
274
+ /**
275
+ * Removes a custom reporter from the Consola instance.
276
+ * If no reporter is specified, all reporters will be removed.
277
+ *
278
+ * @param {ConsolaReporter} reporter - The reporter to remove. See {@link ConsolaReporter}.
279
+ * @returns {Consola} The current Consola instance.
280
+ */
281
+ removeReporter(reporter) {
282
+ if (reporter) {
283
+ const i = this.options.reporters.indexOf(reporter);
284
+ if (i !== -1) {
285
+ return this.options.reporters.splice(i, 1);
286
+ }
287
+ } else {
288
+ this.options.reporters.splice(0);
289
+ }
290
+ return this;
291
+ }
292
+ /**
293
+ * Replaces all reporters of the Consola instance with the specified array of reporters.
294
+ *
295
+ * @param {ConsolaReporter[]} reporters - The new reporters to set. See {@link ConsolaReporter}.
296
+ * @returns {Consola} The current Consola instance.
297
+ */
298
+ setReporters(reporters) {
299
+ this.options.reporters = Array.isArray(reporters) ? reporters : [reporters];
300
+ return this;
301
+ }
302
+ wrapAll() {
303
+ this.wrapConsole();
304
+ this.wrapStd();
305
+ }
306
+ restoreAll() {
307
+ this.restoreConsole();
308
+ this.restoreStd();
309
+ }
310
+ /**
311
+ * Overrides console methods with Consola logging methods for consistent logging.
312
+ */
313
+ wrapConsole() {
314
+ for (const type in this.options.types) {
315
+ if (!console["__" + type]) {
316
+ console["__" + type] = console[type];
317
+ }
318
+ console[type] = this[type].raw;
319
+ }
320
+ }
321
+ /**
322
+ * Restores the original console methods, removing Consola overrides.
323
+ */
324
+ restoreConsole() {
325
+ for (const type in this.options.types) {
326
+ if (console["__" + type]) {
327
+ console[type] = console["__" + type];
328
+ delete console["__" + type];
329
+ }
330
+ }
331
+ }
332
+ /**
333
+ * Overrides standard output and error streams to redirect them through Consola.
334
+ */
335
+ wrapStd() {
336
+ this._wrapStream(this.options.stdout, "log");
337
+ this._wrapStream(this.options.stderr, "log");
338
+ }
339
+ _wrapStream(stream, type) {
340
+ if (!stream) {
341
+ return;
342
+ }
343
+ if (!stream.__write) {
344
+ stream.__write = stream.write;
345
+ }
346
+ stream.write = (data) => {
347
+ this[type].raw(String(data).trim());
348
+ };
349
+ }
350
+ /**
351
+ * Restores the original standard output and error streams, removing the Consola redirection.
352
+ */
353
+ restoreStd() {
354
+ this._restoreStream(this.options.stdout);
355
+ this._restoreStream(this.options.stderr);
356
+ }
357
+ _restoreStream(stream) {
358
+ if (!stream) {
359
+ return;
360
+ }
361
+ if (stream.__write) {
362
+ stream.write = stream.__write;
363
+ delete stream.__write;
364
+ }
365
+ }
366
+ /**
367
+ * Pauses logging, queues incoming logs until resumed.
368
+ */
369
+ pauseLogs() {
370
+ paused = true;
371
+ }
372
+ /**
373
+ * Resumes logging, processing any queued logs.
374
+ */
375
+ resumeLogs() {
376
+ paused = false;
377
+ const _queue = queue.splice(0);
378
+ for (const item of _queue) {
379
+ item[0]._logFn(item[1], item[2]);
380
+ }
381
+ }
382
+ /**
383
+ * Replaces logging methods with mocks if a mock function is provided.
384
+ *
385
+ * @param {ConsolaOptions["mockFn"]} mockFn - The function to use for mocking logging methods. See {@link ConsolaOptions["mockFn"]}.
386
+ */
387
+ mockTypes(mockFn) {
388
+ const _mockFn = mockFn || this.options.mockFn;
389
+ this._mockFn = _mockFn;
390
+ if (typeof _mockFn !== "function") {
391
+ return;
392
+ }
393
+ for (const type in this.options.types) {
394
+ this[type] = _mockFn(type, this.options.types[type]) || this[type];
395
+ this[type].raw = this[type];
396
+ }
397
+ }
398
+ _wrapLogFn(defaults, isRaw) {
399
+ return (...args) => {
400
+ if (paused) {
401
+ queue.push([this, defaults, args, isRaw]);
402
+ return;
403
+ }
404
+ return this._logFn(defaults, args, isRaw);
405
+ };
406
+ }
407
+ _logFn(defaults, args, isRaw) {
408
+ if ((defaults.level || 0) > this.level) {
409
+ return false;
410
+ }
411
+ const logObj = {
412
+ date: /* @__PURE__ */ new Date(),
413
+ args: [],
414
+ ...defaults,
415
+ level: _normalizeLogLevel(defaults.level, this.options.types)
416
+ };
417
+ if (!isRaw && args.length === 1 && isLogObj(args[0])) {
418
+ Object.assign(logObj, args[0]);
419
+ } else {
420
+ logObj.args = [...args];
421
+ }
422
+ if (logObj.message) {
423
+ logObj.args.unshift(logObj.message);
424
+ delete logObj.message;
425
+ }
426
+ if (logObj.additional) {
427
+ if (!Array.isArray(logObj.additional)) {
428
+ logObj.additional = logObj.additional.split("\n");
429
+ }
430
+ logObj.args.push("\n" + logObj.additional.join("\n"));
431
+ delete logObj.additional;
432
+ }
433
+ logObj.type = typeof logObj.type === "string" ? logObj.type.toLowerCase() : "log";
434
+ logObj.tag = typeof logObj.tag === "string" ? logObj.tag : "";
435
+ const resolveLog = (newLog = false) => {
436
+ const repeated = (this._lastLog.count || 0) - this.options.throttleMin;
437
+ if (this._lastLog.object && repeated > 0) {
438
+ const args2 = [...this._lastLog.object.args];
439
+ if (repeated > 1) {
440
+ args2.push(`(repeated ${repeated} times)`);
441
+ }
442
+ this._log({ ...this._lastLog.object, args: args2 });
443
+ this._lastLog.count = 1;
444
+ }
445
+ if (newLog) {
446
+ this._lastLog.object = logObj;
447
+ this._log(logObj);
448
+ }
449
+ };
450
+ clearTimeout(this._lastLog.timeout);
451
+ const diffTime = this._lastLog.time && logObj.date ? logObj.date.getTime() - this._lastLog.time.getTime() : 0;
452
+ this._lastLog.time = logObj.date;
453
+ if (diffTime < this.options.throttle) {
454
+ try {
455
+ const serializedLog = JSON.stringify([
456
+ logObj.type,
457
+ logObj.tag,
458
+ logObj.args
459
+ ]);
460
+ const isSameLog = this._lastLog.serialized === serializedLog;
461
+ this._lastLog.serialized = serializedLog;
462
+ if (isSameLog) {
463
+ this._lastLog.count = (this._lastLog.count || 0) + 1;
464
+ if (this._lastLog.count > this.options.throttleMin) {
465
+ this._lastLog.timeout = setTimeout(
466
+ resolveLog,
467
+ this.options.throttle
468
+ );
469
+ return;
470
+ }
471
+ }
472
+ } catch {
473
+ }
474
+ }
475
+ resolveLog(true);
476
+ }
477
+ _log(logObj) {
478
+ for (const reporter of this.options.reporters) {
479
+ reporter.log(logObj, {
480
+ options: this.options
481
+ });
482
+ }
483
+ }
484
+ }
485
+ function _normalizeLogLevel(input, types = {}, defaultLevel = 3) {
486
+ if (input === void 0) {
487
+ return defaultLevel;
488
+ }
489
+ if (typeof input === "number") {
490
+ return input;
491
+ }
492
+ if (types[input] && types[input].level !== void 0) {
493
+ return types[input].level;
494
+ }
495
+ return defaultLevel;
496
+ }
497
+ Consola.prototype.add = Consola.prototype.addReporter;
498
+ Consola.prototype.remove = Consola.prototype.removeReporter;
499
+ Consola.prototype.clear = Consola.prototype.removeReporter;
500
+ Consola.prototype.withScope = Consola.prototype.withTag;
501
+ Consola.prototype.mock = Consola.prototype.mockTypes;
502
+ Consola.prototype.pause = Consola.prototype.pauseLogs;
503
+ Consola.prototype.resume = Consola.prototype.resumeLogs;
504
+ function createConsola$1(options = {}) {
505
+ return new Consola(options);
506
+ }
507
+
508
+ class BrowserReporter {
509
+ options;
510
+ defaultColor;
511
+ levelColorMap;
512
+ typeColorMap;
513
+ constructor(options) {
514
+ this.options = { ...options };
515
+ this.defaultColor = "#7f8c8d";
516
+ this.levelColorMap = {
517
+ 0: "#c0392b",
518
+ // Red
519
+ 1: "#f39c12",
520
+ // Yellow
521
+ 3: "#00BCD4"
522
+ // Cyan
523
+ };
524
+ this.typeColorMap = {
525
+ success: "#2ecc71"
526
+ // Green
527
+ };
528
+ }
529
+ _getLogFn(level) {
530
+ if (level < 1) {
531
+ return console.__error || console.error;
532
+ }
533
+ if (level === 1) {
534
+ return console.__warn || console.warn;
535
+ }
536
+ return console.__log || console.log;
537
+ }
538
+ log(logObj) {
539
+ const consoleLogFn = this._getLogFn(logObj.level);
540
+ const type = logObj.type === "log" ? "" : logObj.type;
541
+ const tag = logObj.tag || "";
542
+ const color = this.typeColorMap[logObj.type] || this.levelColorMap[logObj.level] || this.defaultColor;
543
+ const style = `
544
+ background: ${color};
545
+ border-radius: 0.5em;
546
+ color: white;
547
+ font-weight: bold;
548
+ padding: 2px 0.5em;
549
+ `;
550
+ const badge = `%c${[tag, type].filter(Boolean).join(":")}`;
551
+ if (typeof logObj.args[0] === "string") {
552
+ consoleLogFn(
553
+ `${badge}%c ${logObj.args[0]}`,
554
+ style,
555
+ // Empty string as style resets to default console style
556
+ "",
557
+ ...logObj.args.slice(1)
558
+ );
559
+ } else {
560
+ consoleLogFn(badge, style, ...logObj.args);
561
+ }
562
+ }
563
+ }
564
+
565
+ function createConsola(options = {}) {
566
+ const consola2 = createConsola$1({
567
+ reporters: options.reporters || [new BrowserReporter({})],
568
+ prompt(message, options2 = {}) {
569
+ if (options2.type === "confirm") {
570
+ return Promise.resolve(confirm(message));
571
+ }
572
+ return Promise.resolve(prompt(message));
573
+ },
574
+ ...options
575
+ });
576
+ return consola2;
577
+ }
578
+ const consola = createConsola();
579
+
7
580
  async function pathExists$5(p) {
8
581
  try {
9
582
  await promises.access(p);
@@ -2401,7 +2974,8 @@ class ProjectAnalyzer {
2401
2974
  }
2402
2975
  const logger = consola.withTag("analyzer");
2403
2976
  const DEFAULT_CONFIG = {
2404
- minConfidence: 0.5,
2977
+ minConfidence: 0.05,
2978
+ // Lower threshold for large projects with many file types
2405
2979
  includeNodeModules: false,
2406
2980
  analyzeTransitiveDeps: true,
2407
2981
  maxFilesToScan: 1e4,
@@ -2447,5 +3021,930 @@ async function detectProjectType(projectPath) {
2447
3021
  });
2448
3022
  return analysis.projectType;
2449
3023
  }
3024
+ async function batchAnalyze(projectPaths, config = {}) {
3025
+ logger.info(`Batch analyzing ${projectPaths.length} projects`);
3026
+ const results = [];
3027
+ for (const path of projectPaths) {
3028
+ try {
3029
+ const analysis = await analyzeProject(path, config);
3030
+ results.push(analysis);
3031
+ } catch (error) {
3032
+ logger.error(`Failed to analyze ${path}:`, error);
3033
+ }
3034
+ }
3035
+ logger.success(`Batch analysis completed: ${results.length}/${projectPaths.length} successful`);
3036
+ return results;
3037
+ }
3038
+
3039
+ const suspectProtoRx = /"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/;
3040
+ const suspectConstructorRx = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
3041
+ const JsonSigRx = /^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;
3042
+ function jsonParseTransform(key, value) {
3043
+ if (key === "__proto__" || key === "constructor" && value && typeof value === "object" && "prototype" in value) {
3044
+ warnKeyDropped(key);
3045
+ return;
3046
+ }
3047
+ return value;
3048
+ }
3049
+ function warnKeyDropped(key) {
3050
+ console.warn(`[destr] Dropping "${key}" key to prevent prototype pollution.`);
3051
+ }
3052
+ function destr(value, options = {}) {
3053
+ if (typeof value !== "string") {
3054
+ return value;
3055
+ }
3056
+ if (value[0] === '"' && value[value.length - 1] === '"' && value.indexOf("\\") === -1) {
3057
+ return value.slice(1, -1);
3058
+ }
3059
+ const _value = value.trim();
3060
+ if (_value.length <= 9) {
3061
+ switch (_value.toLowerCase()) {
3062
+ case "true": {
3063
+ return true;
3064
+ }
3065
+ case "false": {
3066
+ return false;
3067
+ }
3068
+ case "undefined": {
3069
+ return void 0;
3070
+ }
3071
+ case "null": {
3072
+ return null;
3073
+ }
3074
+ case "nan": {
3075
+ return Number.NaN;
3076
+ }
3077
+ case "infinity": {
3078
+ return Number.POSITIVE_INFINITY;
3079
+ }
3080
+ case "-infinity": {
3081
+ return Number.NEGATIVE_INFINITY;
3082
+ }
3083
+ }
3084
+ }
3085
+ if (!JsonSigRx.test(value)) {
3086
+ if (options.strict) {
3087
+ throw new SyntaxError("[destr] Invalid JSON");
3088
+ }
3089
+ return value;
3090
+ }
3091
+ try {
3092
+ if (suspectProtoRx.test(value) || suspectConstructorRx.test(value)) {
3093
+ if (options.strict) {
3094
+ throw new Error("[destr] Possible prototype pollution");
3095
+ }
3096
+ return JSON.parse(value, jsonParseTransform);
3097
+ }
3098
+ return JSON.parse(value);
3099
+ } catch (error) {
3100
+ if (options.strict) {
3101
+ throw error;
3102
+ }
3103
+ return value;
3104
+ }
3105
+ }
3106
+
3107
+ const HASH_RE = /#/g;
3108
+ const AMPERSAND_RE = /&/g;
3109
+ const SLASH_RE = /\//g;
3110
+ const EQUAL_RE = /=/g;
3111
+ const PLUS_RE = /\+/g;
3112
+ const ENC_CARET_RE = /%5e/gi;
3113
+ const ENC_BACKTICK_RE = /%60/gi;
3114
+ const ENC_PIPE_RE = /%7c/gi;
3115
+ const ENC_SPACE_RE = /%20/gi;
3116
+ function encode(text) {
3117
+ return encodeURI("" + text).replace(ENC_PIPE_RE, "|");
3118
+ }
3119
+ function encodeQueryValue(input) {
3120
+ return encode(typeof input === "string" ? input : JSON.stringify(input)).replace(PLUS_RE, "%2B").replace(ENC_SPACE_RE, "+").replace(HASH_RE, "%23").replace(AMPERSAND_RE, "%26").replace(ENC_BACKTICK_RE, "`").replace(ENC_CARET_RE, "^").replace(SLASH_RE, "%2F");
3121
+ }
3122
+ function encodeQueryKey(text) {
3123
+ return encodeQueryValue(text).replace(EQUAL_RE, "%3D");
3124
+ }
3125
+ function decode(text = "") {
3126
+ try {
3127
+ return decodeURIComponent("" + text);
3128
+ } catch {
3129
+ return "" + text;
3130
+ }
3131
+ }
3132
+ function decodeQueryKey(text) {
3133
+ return decode(text.replace(PLUS_RE, " "));
3134
+ }
3135
+ function decodeQueryValue(text) {
3136
+ return decode(text.replace(PLUS_RE, " "));
3137
+ }
3138
+
3139
+ function parseQuery(parametersString = "") {
3140
+ const object = /* @__PURE__ */ Object.create(null);
3141
+ if (parametersString[0] === "?") {
3142
+ parametersString = parametersString.slice(1);
3143
+ }
3144
+ for (const parameter of parametersString.split("&")) {
3145
+ const s = parameter.match(/([^=]+)=?(.*)/) || [];
3146
+ if (s.length < 2) {
3147
+ continue;
3148
+ }
3149
+ const key = decodeQueryKey(s[1]);
3150
+ if (key === "__proto__" || key === "constructor") {
3151
+ continue;
3152
+ }
3153
+ const value = decodeQueryValue(s[2] || "");
3154
+ if (object[key] === void 0) {
3155
+ object[key] = value;
3156
+ } else if (Array.isArray(object[key])) {
3157
+ object[key].push(value);
3158
+ } else {
3159
+ object[key] = [object[key], value];
3160
+ }
3161
+ }
3162
+ return object;
3163
+ }
3164
+ function encodeQueryItem(key, value) {
3165
+ if (typeof value === "number" || typeof value === "boolean") {
3166
+ value = String(value);
3167
+ }
3168
+ if (!value) {
3169
+ return encodeQueryKey(key);
3170
+ }
3171
+ if (Array.isArray(value)) {
3172
+ return value.map(
3173
+ (_value) => `${encodeQueryKey(key)}=${encodeQueryValue(_value)}`
3174
+ ).join("&");
3175
+ }
3176
+ return `${encodeQueryKey(key)}=${encodeQueryValue(value)}`;
3177
+ }
3178
+ function stringifyQuery(query) {
3179
+ return Object.keys(query).filter((k) => query[k] !== void 0).map((k) => encodeQueryItem(k, query[k])).filter(Boolean).join("&");
3180
+ }
3181
+
3182
+ const PROTOCOL_STRICT_REGEX = /^[\s\w\0+.-]{2,}:([/\\]{1,2})/;
3183
+ const PROTOCOL_REGEX = /^[\s\w\0+.-]{2,}:([/\\]{2})?/;
3184
+ const PROTOCOL_RELATIVE_REGEX = /^([/\\]\s*){2,}[^/\\]/;
3185
+ const JOIN_LEADING_SLASH_RE = /^\.?\//;
3186
+ function hasProtocol(inputString, opts = {}) {
3187
+ if (typeof opts === "boolean") {
3188
+ opts = { acceptRelative: opts };
3189
+ }
3190
+ if (opts.strict) {
3191
+ return PROTOCOL_STRICT_REGEX.test(inputString);
3192
+ }
3193
+ return PROTOCOL_REGEX.test(inputString) || (opts.acceptRelative ? PROTOCOL_RELATIVE_REGEX.test(inputString) : false);
3194
+ }
3195
+ function hasTrailingSlash(input = "", respectQueryAndFragment) {
3196
+ {
3197
+ return input.endsWith("/");
3198
+ }
3199
+ }
3200
+ function withoutTrailingSlash(input = "", respectQueryAndFragment) {
3201
+ {
3202
+ return (hasTrailingSlash(input) ? input.slice(0, -1) : input) || "/";
3203
+ }
3204
+ }
3205
+ function withTrailingSlash(input = "", respectQueryAndFragment) {
3206
+ {
3207
+ return input.endsWith("/") ? input : input + "/";
3208
+ }
3209
+ }
3210
+ function withBase(input, base) {
3211
+ if (isEmptyURL(base) || hasProtocol(input)) {
3212
+ return input;
3213
+ }
3214
+ const _base = withoutTrailingSlash(base);
3215
+ if (input.startsWith(_base)) {
3216
+ return input;
3217
+ }
3218
+ return joinURL(_base, input);
3219
+ }
3220
+ function withQuery(input, query) {
3221
+ const parsed = parseURL(input);
3222
+ const mergedQuery = { ...parseQuery(parsed.search), ...query };
3223
+ parsed.search = stringifyQuery(mergedQuery);
3224
+ return stringifyParsedURL(parsed);
3225
+ }
3226
+ function isEmptyURL(url) {
3227
+ return !url || url === "/";
3228
+ }
3229
+ function isNonEmptyURL(url) {
3230
+ return url && url !== "/";
3231
+ }
3232
+ function joinURL(base, ...input) {
3233
+ let url = base || "";
3234
+ for (const segment of input.filter((url2) => isNonEmptyURL(url2))) {
3235
+ if (url) {
3236
+ const _segment = segment.replace(JOIN_LEADING_SLASH_RE, "");
3237
+ url = withTrailingSlash(url) + _segment;
3238
+ } else {
3239
+ url = segment;
3240
+ }
3241
+ }
3242
+ return url;
3243
+ }
3244
+
3245
+ const protocolRelative = Symbol.for("ufo:protocolRelative");
3246
+ function parseURL(input = "", defaultProto) {
3247
+ const _specialProtoMatch = input.match(
3248
+ /^[\s\0]*(blob:|data:|javascript:|vbscript:)(.*)/i
3249
+ );
3250
+ if (_specialProtoMatch) {
3251
+ const [, _proto, _pathname = ""] = _specialProtoMatch;
3252
+ return {
3253
+ protocol: _proto.toLowerCase(),
3254
+ pathname: _pathname,
3255
+ href: _proto + _pathname,
3256
+ auth: "",
3257
+ host: "",
3258
+ search: "",
3259
+ hash: ""
3260
+ };
3261
+ }
3262
+ if (!hasProtocol(input, { acceptRelative: true })) {
3263
+ return parsePath(input);
3264
+ }
3265
+ const [, protocol = "", auth, hostAndPath = ""] = input.replace(/\\/g, "/").match(/^[\s\0]*([\w+.-]{2,}:)?\/\/([^/@]+@)?(.*)/) || [];
3266
+ let [, host = "", path = ""] = hostAndPath.match(/([^#/?]*)(.*)?/) || [];
3267
+ if (protocol === "file:") {
3268
+ path = path.replace(/\/(?=[A-Za-z]:)/, "");
3269
+ }
3270
+ const { pathname, search, hash } = parsePath(path);
3271
+ return {
3272
+ protocol: protocol.toLowerCase(),
3273
+ auth: auth ? auth.slice(0, Math.max(0, auth.length - 1)) : "",
3274
+ host,
3275
+ pathname,
3276
+ search,
3277
+ hash,
3278
+ [protocolRelative]: !protocol
3279
+ };
3280
+ }
3281
+ function parsePath(input = "") {
3282
+ const [pathname = "", search = "", hash = ""] = (input.match(/([^#?]*)(\?[^#]*)?(#.*)?/) || []).splice(1);
3283
+ return {
3284
+ pathname,
3285
+ search,
3286
+ hash
3287
+ };
3288
+ }
3289
+ function stringifyParsedURL(parsed) {
3290
+ const pathname = parsed.pathname || "";
3291
+ const search = parsed.search ? (parsed.search.startsWith("?") ? "" : "?") + parsed.search : "";
3292
+ const hash = parsed.hash || "";
3293
+ const auth = parsed.auth ? parsed.auth + "@" : "";
3294
+ const host = parsed.host || "";
3295
+ const proto = parsed.protocol || parsed[protocolRelative] ? (parsed.protocol || "") + "//" : "";
3296
+ return proto + auth + host + pathname + search + hash;
3297
+ }
3298
+
3299
+ class FetchError extends Error {
3300
+ constructor(message, opts) {
3301
+ super(message, opts);
3302
+ this.name = "FetchError";
3303
+ if (opts?.cause && !this.cause) {
3304
+ this.cause = opts.cause;
3305
+ }
3306
+ }
3307
+ }
3308
+ function createFetchError(ctx) {
3309
+ const errorMessage = ctx.error?.message || ctx.error?.toString() || "";
3310
+ const method = ctx.request?.method || ctx.options?.method || "GET";
3311
+ const url = ctx.request?.url || String(ctx.request) || "/";
3312
+ const requestStr = `[${method}] ${JSON.stringify(url)}`;
3313
+ const statusStr = ctx.response ? `${ctx.response.status} ${ctx.response.statusText}` : "<no response>";
3314
+ const message = `${requestStr}: ${statusStr}${errorMessage ? ` ${errorMessage}` : ""}`;
3315
+ const fetchError = new FetchError(
3316
+ message,
3317
+ ctx.error ? { cause: ctx.error } : void 0
3318
+ );
3319
+ for (const key of ["request", "options", "response"]) {
3320
+ Object.defineProperty(fetchError, key, {
3321
+ get() {
3322
+ return ctx[key];
3323
+ }
3324
+ });
3325
+ }
3326
+ for (const [key, refKey] of [
3327
+ ["data", "_data"],
3328
+ ["status", "status"],
3329
+ ["statusCode", "status"],
3330
+ ["statusText", "statusText"],
3331
+ ["statusMessage", "statusText"]
3332
+ ]) {
3333
+ Object.defineProperty(fetchError, key, {
3334
+ get() {
3335
+ return ctx.response && ctx.response[refKey];
3336
+ }
3337
+ });
3338
+ }
3339
+ return fetchError;
3340
+ }
3341
+
3342
+ const payloadMethods = new Set(
3343
+ Object.freeze(["PATCH", "POST", "PUT", "DELETE"])
3344
+ );
3345
+ function isPayloadMethod(method = "GET") {
3346
+ return payloadMethods.has(method.toUpperCase());
3347
+ }
3348
+ function isJSONSerializable(value) {
3349
+ if (value === void 0) {
3350
+ return false;
3351
+ }
3352
+ const t = typeof value;
3353
+ if (t === "string" || t === "number" || t === "boolean" || t === null) {
3354
+ return true;
3355
+ }
3356
+ if (t !== "object") {
3357
+ return false;
3358
+ }
3359
+ if (Array.isArray(value)) {
3360
+ return true;
3361
+ }
3362
+ if (value.buffer) {
3363
+ return false;
3364
+ }
3365
+ if (value instanceof FormData || value instanceof URLSearchParams) {
3366
+ return false;
3367
+ }
3368
+ return value.constructor && value.constructor.name === "Object" || typeof value.toJSON === "function";
3369
+ }
3370
+ const textTypes = /* @__PURE__ */ new Set([
3371
+ "image/svg",
3372
+ "application/xml",
3373
+ "application/xhtml",
3374
+ "application/html"
3375
+ ]);
3376
+ const JSON_RE = /^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;
3377
+ function detectResponseType(_contentType = "") {
3378
+ if (!_contentType) {
3379
+ return "json";
3380
+ }
3381
+ const contentType = _contentType.split(";").shift() || "";
3382
+ if (JSON_RE.test(contentType)) {
3383
+ return "json";
3384
+ }
3385
+ if (contentType === "text/event-stream") {
3386
+ return "stream";
3387
+ }
3388
+ if (textTypes.has(contentType) || contentType.startsWith("text/")) {
3389
+ return "text";
3390
+ }
3391
+ return "blob";
3392
+ }
3393
+ function resolveFetchOptions(request, input, defaults, Headers) {
3394
+ const headers = mergeHeaders(
3395
+ input?.headers ?? request?.headers,
3396
+ defaults?.headers,
3397
+ Headers
3398
+ );
3399
+ let query;
3400
+ if (defaults?.query || defaults?.params || input?.params || input?.query) {
3401
+ query = {
3402
+ ...defaults?.params,
3403
+ ...defaults?.query,
3404
+ ...input?.params,
3405
+ ...input?.query
3406
+ };
3407
+ }
3408
+ return {
3409
+ ...defaults,
3410
+ ...input,
3411
+ query,
3412
+ params: query,
3413
+ headers
3414
+ };
3415
+ }
3416
+ function mergeHeaders(input, defaults, Headers) {
3417
+ if (!defaults) {
3418
+ return new Headers(input);
3419
+ }
3420
+ const headers = new Headers(defaults);
3421
+ if (input) {
3422
+ for (const [key, value] of Symbol.iterator in input || Array.isArray(input) ? input : new Headers(input)) {
3423
+ headers.set(key, value);
3424
+ }
3425
+ }
3426
+ return headers;
3427
+ }
3428
+ async function callHooks(context, hooks) {
3429
+ if (hooks) {
3430
+ if (Array.isArray(hooks)) {
3431
+ for (const hook of hooks) {
3432
+ await hook(context);
3433
+ }
3434
+ } else {
3435
+ await hooks(context);
3436
+ }
3437
+ }
3438
+ }
3439
+
3440
+ const retryStatusCodes = /* @__PURE__ */ new Set([
3441
+ 408,
3442
+ // Request Timeout
3443
+ 409,
3444
+ // Conflict
3445
+ 425,
3446
+ // Too Early (Experimental)
3447
+ 429,
3448
+ // Too Many Requests
3449
+ 500,
3450
+ // Internal Server Error
3451
+ 502,
3452
+ // Bad Gateway
3453
+ 503,
3454
+ // Service Unavailable
3455
+ 504
3456
+ // Gateway Timeout
3457
+ ]);
3458
+ const nullBodyResponses = /* @__PURE__ */ new Set([101, 204, 205, 304]);
3459
+ function createFetch(globalOptions = {}) {
3460
+ const {
3461
+ fetch = globalThis.fetch,
3462
+ Headers = globalThis.Headers,
3463
+ AbortController = globalThis.AbortController
3464
+ } = globalOptions;
3465
+ async function onError(context) {
3466
+ const isAbort = context.error && context.error.name === "AbortError" && !context.options.timeout || false;
3467
+ if (context.options.retry !== false && !isAbort) {
3468
+ let retries;
3469
+ if (typeof context.options.retry === "number") {
3470
+ retries = context.options.retry;
3471
+ } else {
3472
+ retries = isPayloadMethod(context.options.method) ? 0 : 1;
3473
+ }
3474
+ const responseCode = context.response && context.response.status || 500;
3475
+ if (retries > 0 && (Array.isArray(context.options.retryStatusCodes) ? context.options.retryStatusCodes.includes(responseCode) : retryStatusCodes.has(responseCode))) {
3476
+ const retryDelay = typeof context.options.retryDelay === "function" ? context.options.retryDelay(context) : context.options.retryDelay || 0;
3477
+ if (retryDelay > 0) {
3478
+ await new Promise((resolve) => setTimeout(resolve, retryDelay));
3479
+ }
3480
+ return $fetchRaw(context.request, {
3481
+ ...context.options,
3482
+ retry: retries - 1
3483
+ });
3484
+ }
3485
+ }
3486
+ const error = createFetchError(context);
3487
+ if (Error.captureStackTrace) {
3488
+ Error.captureStackTrace(error, $fetchRaw);
3489
+ }
3490
+ throw error;
3491
+ }
3492
+ const $fetchRaw = async function $fetchRaw2(_request, _options = {}) {
3493
+ const context = {
3494
+ request: _request,
3495
+ options: resolveFetchOptions(
3496
+ _request,
3497
+ _options,
3498
+ globalOptions.defaults,
3499
+ Headers
3500
+ ),
3501
+ response: void 0,
3502
+ error: void 0
3503
+ };
3504
+ if (context.options.method) {
3505
+ context.options.method = context.options.method.toUpperCase();
3506
+ }
3507
+ if (context.options.onRequest) {
3508
+ await callHooks(context, context.options.onRequest);
3509
+ if (!(context.options.headers instanceof Headers)) {
3510
+ context.options.headers = new Headers(
3511
+ context.options.headers || {}
3512
+ /* compat */
3513
+ );
3514
+ }
3515
+ }
3516
+ if (typeof context.request === "string") {
3517
+ if (context.options.baseURL) {
3518
+ context.request = withBase(context.request, context.options.baseURL);
3519
+ }
3520
+ if (context.options.query) {
3521
+ context.request = withQuery(context.request, context.options.query);
3522
+ delete context.options.query;
3523
+ }
3524
+ if ("query" in context.options) {
3525
+ delete context.options.query;
3526
+ }
3527
+ if ("params" in context.options) {
3528
+ delete context.options.params;
3529
+ }
3530
+ }
3531
+ if (context.options.body && isPayloadMethod(context.options.method)) {
3532
+ if (isJSONSerializable(context.options.body)) {
3533
+ const contentType = context.options.headers.get("content-type");
3534
+ if (typeof context.options.body !== "string") {
3535
+ context.options.body = contentType === "application/x-www-form-urlencoded" ? new URLSearchParams(
3536
+ context.options.body
3537
+ ).toString() : JSON.stringify(context.options.body);
3538
+ }
3539
+ if (!contentType) {
3540
+ context.options.headers.set("content-type", "application/json");
3541
+ }
3542
+ if (!context.options.headers.has("accept")) {
3543
+ context.options.headers.set("accept", "application/json");
3544
+ }
3545
+ } else if (
3546
+ // ReadableStream Body
3547
+ "pipeTo" in context.options.body && typeof context.options.body.pipeTo === "function" || // Node.js Stream Body
3548
+ typeof context.options.body.pipe === "function"
3549
+ ) {
3550
+ if (!("duplex" in context.options)) {
3551
+ context.options.duplex = "half";
3552
+ }
3553
+ }
3554
+ }
3555
+ let abortTimeout;
3556
+ if (!context.options.signal && context.options.timeout) {
3557
+ const controller = new AbortController();
3558
+ abortTimeout = setTimeout(() => {
3559
+ const error = new Error(
3560
+ "[TimeoutError]: The operation was aborted due to timeout"
3561
+ );
3562
+ error.name = "TimeoutError";
3563
+ error.code = 23;
3564
+ controller.abort(error);
3565
+ }, context.options.timeout);
3566
+ context.options.signal = controller.signal;
3567
+ }
3568
+ try {
3569
+ context.response = await fetch(
3570
+ context.request,
3571
+ context.options
3572
+ );
3573
+ } catch (error) {
3574
+ context.error = error;
3575
+ if (context.options.onRequestError) {
3576
+ await callHooks(
3577
+ context,
3578
+ context.options.onRequestError
3579
+ );
3580
+ }
3581
+ return await onError(context);
3582
+ } finally {
3583
+ if (abortTimeout) {
3584
+ clearTimeout(abortTimeout);
3585
+ }
3586
+ }
3587
+ const hasBody = (context.response.body || // https://github.com/unjs/ofetch/issues/324
3588
+ // https://github.com/unjs/ofetch/issues/294
3589
+ // https://github.com/JakeChampion/fetch/issues/1454
3590
+ context.response._bodyInit) && !nullBodyResponses.has(context.response.status) && context.options.method !== "HEAD";
3591
+ if (hasBody) {
3592
+ const responseType = (context.options.parseResponse ? "json" : context.options.responseType) || detectResponseType(context.response.headers.get("content-type") || "");
3593
+ switch (responseType) {
3594
+ case "json": {
3595
+ const data = await context.response.text();
3596
+ const parseFunction = context.options.parseResponse || destr;
3597
+ context.response._data = parseFunction(data);
3598
+ break;
3599
+ }
3600
+ case "stream": {
3601
+ context.response._data = context.response.body || context.response._bodyInit;
3602
+ break;
3603
+ }
3604
+ default: {
3605
+ context.response._data = await context.response[responseType]();
3606
+ }
3607
+ }
3608
+ }
3609
+ if (context.options.onResponse) {
3610
+ await callHooks(
3611
+ context,
3612
+ context.options.onResponse
3613
+ );
3614
+ }
3615
+ if (!context.options.ignoreResponseError && context.response.status >= 400 && context.response.status < 600) {
3616
+ if (context.options.onResponseError) {
3617
+ await callHooks(
3618
+ context,
3619
+ context.options.onResponseError
3620
+ );
3621
+ }
3622
+ return await onError(context);
3623
+ }
3624
+ return context.response;
3625
+ };
3626
+ const $fetch = async function $fetch2(request, options) {
3627
+ const r = await $fetchRaw(request, options);
3628
+ return r._data;
3629
+ };
3630
+ $fetch.raw = $fetchRaw;
3631
+ $fetch.native = (...args) => fetch(...args);
3632
+ $fetch.create = (defaultOptions = {}, customGlobalOptions = {}) => createFetch({
3633
+ ...globalOptions,
3634
+ ...customGlobalOptions,
3635
+ defaults: {
3636
+ ...globalOptions.defaults,
3637
+ ...customGlobalOptions.defaults,
3638
+ ...defaultOptions
3639
+ }
3640
+ });
3641
+ return $fetch;
3642
+ }
3643
+
3644
+ const _globalThis = (function() {
3645
+ if (typeof globalThis !== "undefined") {
3646
+ return globalThis;
3647
+ }
3648
+ if (typeof self !== "undefined") {
3649
+ return self;
3650
+ }
3651
+ if (typeof window !== "undefined") {
3652
+ return window;
3653
+ }
3654
+ if (typeof global !== "undefined") {
3655
+ return global;
3656
+ }
3657
+ throw new Error("unable to locate global object");
3658
+ })();
3659
+ const fetch = _globalThis.fetch ? (...args) => _globalThis.fetch(...args) : () => Promise.reject(new Error("[ofetch] global.fetch is not supported!"));
3660
+ const Headers = _globalThis.Headers;
3661
+ const AbortController = _globalThis.AbortController;
3662
+ const ofetch = createFetch({ fetch, Headers, AbortController });
3663
+
3664
+ class TemplatesClient {
3665
+ fetch;
3666
+ baseURL;
3667
+ language;
3668
+ logger = consola.withTag("templates-client");
3669
+ constructor(config = {}) {
3670
+ this.baseURL = config.baseURL || "https://api.claudehome.cn";
3671
+ this.language = config.language || "en";
3672
+ this.fetch = ofetch.create({
3673
+ baseURL: this.baseURL,
3674
+ timeout: config.timeout || 1e4,
3675
+ headers: {
3676
+ "User-Agent": "CCJK/8.2.0"
3677
+ },
3678
+ retry: 2
3679
+ });
3680
+ }
3681
+ // ==========================================================================
3682
+ // Single Template
3683
+ // ==========================================================================
3684
+ /**
3685
+ * Get a single template by ID
3686
+ */
3687
+ async getTemplate(templateId) {
3688
+ try {
3689
+ this.logger.debug(`Fetching template: ${templateId}`);
3690
+ const response = await this.fetch(
3691
+ `/api/v8/templates/${encodeURIComponent(templateId)}`
3692
+ );
3693
+ if (response.code === 200 && response.data) {
3694
+ return response.data;
3695
+ }
3696
+ return null;
3697
+ } catch (error) {
3698
+ this.logger.warn(`Failed to fetch template ${templateId}:`, error);
3699
+ return null;
3700
+ }
3701
+ }
3702
+ // ==========================================================================
3703
+ // Batch Templates
3704
+ // ==========================================================================
3705
+ /**
3706
+ * Batch get templates by IDs
3707
+ */
3708
+ async getTemplates(ids, language) {
3709
+ try {
3710
+ this.logger.debug(`Batch fetching ${ids.length} templates`);
3711
+ const response = await this.fetch(
3712
+ "/api/v8/templates/batch",
3713
+ {
3714
+ method: "POST",
3715
+ body: {
3716
+ ids,
3717
+ language: language || this.language,
3718
+ includeStats: true
3719
+ }
3720
+ }
3721
+ );
3722
+ return {
3723
+ requestId: response.requestId || "",
3724
+ templates: response.templates || {},
3725
+ notFound: response.notFound || [],
3726
+ stats: response.stats
3727
+ };
3728
+ } catch (error) {
3729
+ this.logger.warn("Failed to batch fetch templates:", error);
3730
+ return {
3731
+ requestId: "",
3732
+ templates: {},
3733
+ notFound: ids
3734
+ };
3735
+ }
3736
+ }
3737
+ // ==========================================================================
3738
+ // Search & List
3739
+ // ==========================================================================
3740
+ /**
3741
+ * Search templates
3742
+ */
3743
+ async searchTemplates(query, params = {}) {
3744
+ try {
3745
+ this.logger.debug(`Searching templates: ${query}`);
3746
+ const searchParams = this.buildSearchParams({ ...params, query });
3747
+ const response = await this.fetch(
3748
+ `/api/v8/templates/search?${searchParams}`
3749
+ );
3750
+ if (response.code === 200 && response.data) {
3751
+ return response.data;
3752
+ }
3753
+ return { items: [], total: 0, limit: 20, offset: 0 };
3754
+ } catch (error) {
3755
+ this.logger.warn("Failed to search templates:", error);
3756
+ return { items: [], total: 0, limit: 20, offset: 0 };
3757
+ }
3758
+ }
3759
+ /**
3760
+ * List templates with filters
3761
+ */
3762
+ async listTemplates(params = {}) {
3763
+ try {
3764
+ this.logger.debug("Listing templates with params:", params);
3765
+ const searchParams = this.buildSearchParams(params);
3766
+ const response = await this.fetch(
3767
+ `/api/v8/templates?${searchParams}`
3768
+ );
3769
+ if (response.code === 200 && response.data) {
3770
+ return response.data;
3771
+ }
3772
+ return { items: [], total: 0, limit: 20, offset: 0 };
3773
+ } catch (error) {
3774
+ this.logger.warn("Failed to list templates:", error);
3775
+ return { items: [], total: 0, limit: 20, offset: 0 };
3776
+ }
3777
+ }
3778
+ // ==========================================================================
3779
+ // Type-specific Methods
3780
+ // ==========================================================================
3781
+ /**
3782
+ * Get templates by type
3783
+ */
3784
+ async getTemplatesByType(type, options = {}) {
3785
+ const { items } = await this.listTemplates({
3786
+ type,
3787
+ category: options.category,
3788
+ limit: options.limit || 50,
3789
+ is_official: options.is_official
3790
+ });
3791
+ return items;
3792
+ }
3793
+ /**
3794
+ * Get specialist agents
3795
+ */
3796
+ async getSpecialistAgents(category) {
3797
+ return this.getTemplatesByType("agent", { category, limit: 50 });
3798
+ }
3799
+ /**
3800
+ * Get official MCP servers
3801
+ */
3802
+ async getOfficialMcpServers() {
3803
+ return this.getTemplatesByType("mcp", { is_official: true, limit: 50 });
3804
+ }
3805
+ /**
3806
+ * Get skills by category
3807
+ */
3808
+ async getSkills(category) {
3809
+ return this.getTemplatesByType("skill", { category, limit: 50 });
3810
+ }
3811
+ /**
3812
+ * Get hooks by category
3813
+ */
3814
+ async getHooks(category) {
3815
+ return this.getTemplatesByType("hook", { category, limit: 50 });
3816
+ }
3817
+ // ==========================================================================
3818
+ // Featured & Popular
3819
+ // ==========================================================================
3820
+ /**
3821
+ * Get featured templates
3822
+ */
3823
+ async getFeaturedTemplates(limit = 10) {
3824
+ try {
3825
+ const response = await this.fetch(
3826
+ `/api/v8/templates/featured?limit=${limit}`
3827
+ );
3828
+ if (response.code === 200 && response.data) {
3829
+ return response.data;
3830
+ }
3831
+ return [];
3832
+ } catch (error) {
3833
+ this.logger.warn("Failed to fetch featured templates:", error);
3834
+ return [];
3835
+ }
3836
+ }
3837
+ /**
3838
+ * Get popular templates
3839
+ */
3840
+ async getPopularTemplates(limit = 20) {
3841
+ try {
3842
+ const response = await this.fetch(
3843
+ `/api/v8/templates/popular?limit=${limit}`
3844
+ );
3845
+ if (response.code === 200 && response.data) {
3846
+ return response.data;
3847
+ }
3848
+ return [];
3849
+ } catch (error) {
3850
+ this.logger.warn("Failed to fetch popular templates:", error);
3851
+ return [];
3852
+ }
3853
+ }
3854
+ // ==========================================================================
3855
+ // Categories
3856
+ // ==========================================================================
3857
+ /**
3858
+ * Get all categories
3859
+ */
3860
+ async getCategories() {
3861
+ try {
3862
+ const response = await this.fetch(
3863
+ "/api/v8/templates/categories"
3864
+ );
3865
+ if (response.code === 200 && response.data) {
3866
+ return response.data;
3867
+ }
3868
+ return [];
3869
+ } catch (error) {
3870
+ this.logger.warn("Failed to fetch categories:", error);
3871
+ return [];
3872
+ }
3873
+ }
3874
+ // ==========================================================================
3875
+ // Download Tracking
3876
+ // ==========================================================================
3877
+ /**
3878
+ * Track template download
3879
+ */
3880
+ async trackDownload(templateId) {
3881
+ try {
3882
+ const response = await this.fetch(
3883
+ `/api/v8/templates/${encodeURIComponent(templateId)}/download`,
3884
+ { method: "POST" }
3885
+ );
3886
+ return response.code === 200;
3887
+ } catch (error) {
3888
+ this.logger.warn(`Failed to track download for ${templateId}:`, error);
3889
+ return false;
3890
+ }
3891
+ }
3892
+ // ==========================================================================
3893
+ // Helpers
3894
+ // ==========================================================================
3895
+ /**
3896
+ * Build search params string
3897
+ */
3898
+ buildSearchParams(params) {
3899
+ const searchParams = new URLSearchParams();
3900
+ if (params.query)
3901
+ searchParams.set("query", params.query);
3902
+ if (params.type)
3903
+ searchParams.set("type", params.type);
3904
+ if (params.category)
3905
+ searchParams.set("category", params.category);
3906
+ if (params.tags?.length)
3907
+ searchParams.set("tags", params.tags.join(","));
3908
+ if (params.is_official !== void 0)
3909
+ searchParams.set("is_official", String(params.is_official));
3910
+ if (params.is_featured !== void 0)
3911
+ searchParams.set("is_featured", String(params.is_featured));
3912
+ if (params.is_verified !== void 0)
3913
+ searchParams.set("is_verified", String(params.is_verified));
3914
+ if (params.sortBy)
3915
+ searchParams.set("sortBy", params.sortBy);
3916
+ if (params.order)
3917
+ searchParams.set("order", params.order);
3918
+ if (params.limit)
3919
+ searchParams.set("limit", String(params.limit));
3920
+ if (params.offset)
3921
+ searchParams.set("offset", String(params.offset));
3922
+ return searchParams.toString();
3923
+ }
3924
+ /**
3925
+ * Extract localized name from template
3926
+ */
3927
+ getLocalizedName(template, lang) {
3928
+ const language = lang || this.language;
3929
+ return language === "zh-CN" && template.name_zh_cn ? template.name_zh_cn : template.name_en;
3930
+ }
3931
+ /**
3932
+ * Extract localized description from template
3933
+ */
3934
+ getLocalizedDescription(template, lang) {
3935
+ const language = lang || this.language;
3936
+ return language === "zh-CN" && template.description_zh_cn ? template.description_zh_cn : template.description_en || "";
3937
+ }
3938
+ }
3939
+ let templatesClientInstance = null;
3940
+ function getTemplatesClient(config) {
3941
+ if (!templatesClientInstance) {
3942
+ templatesClientInstance = new TemplatesClient(config);
3943
+ }
3944
+ return templatesClientInstance;
3945
+ }
3946
+ function createTemplatesClient(config) {
3947
+ return new TemplatesClient(config);
3948
+ }
2450
3949
 
2451
- export { ProjectAnalyzer as P, analyzeProject as a };
3950
+ export { ProjectAnalyzer as P, TemplatesClient as T, analyzeProject as a, createTemplatesClient as b, consola as c, analyzeDependencies$1 as d, detectProject as e, detectProjectType as f, getTemplatesClient as g, batchAnalyze as h, ofetch as o };