ccjk 12.0.7 → 12.0.8

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 (299) hide show
  1. package/package.json +1 -1
  2. package/dist/chunks/agent-teams.mjs +0 -136
  3. package/dist/chunks/agent.mjs +0 -1439
  4. package/dist/chunks/agents.mjs +0 -3778
  5. package/dist/chunks/api-cli.mjs +0 -132
  6. package/dist/chunks/api-providers.mjs +0 -129
  7. package/dist/chunks/api.mjs +0 -112
  8. package/dist/chunks/auto-bootstrap.mjs +0 -358
  9. package/dist/chunks/auto-init.mjs +0 -7584
  10. package/dist/chunks/auto-updater.mjs +0 -410
  11. package/dist/chunks/banner.mjs +0 -188
  12. package/dist/chunks/bash.mjs +0 -187
  13. package/dist/chunks/boost.mjs +0 -397
  14. package/dist/chunks/ccjk-agents.mjs +0 -414
  15. package/dist/chunks/ccjk-all.mjs +0 -1028
  16. package/dist/chunks/ccjk-config.mjs +0 -261
  17. package/dist/chunks/ccjk-hooks.mjs +0 -1074
  18. package/dist/chunks/ccjk-mcp.mjs +0 -761
  19. package/dist/chunks/ccjk-setup.mjs +0 -763
  20. package/dist/chunks/ccjk-skills.mjs +0 -514
  21. package/dist/chunks/ccr.mjs +0 -98
  22. package/dist/chunks/ccu.mjs +0 -40
  23. package/dist/chunks/check-updates.mjs +0 -108
  24. package/dist/chunks/claude-code-config-manager.mjs +0 -750
  25. package/dist/chunks/claude-code-incremental-manager.mjs +0 -623
  26. package/dist/chunks/claude-config.mjs +0 -236
  27. package/dist/chunks/claude-wrapper.mjs +0 -85
  28. package/dist/chunks/cleanup-migration.mjs +0 -20
  29. package/dist/chunks/cli-hook.mjs +0 -2285
  30. package/dist/chunks/cloud-sync.mjs +0 -29
  31. package/dist/chunks/codex-config-switch.mjs +0 -451
  32. package/dist/chunks/codex-provider-manager.mjs +0 -236
  33. package/dist/chunks/codex-uninstaller.mjs +0 -404
  34. package/dist/chunks/codex.mjs +0 -2077
  35. package/dist/chunks/commands.mjs +0 -108
  36. package/dist/chunks/commands2.mjs +0 -413
  37. package/dist/chunks/commit.mjs +0 -138
  38. package/dist/chunks/completion.mjs +0 -515
  39. package/dist/chunks/config-consolidator.mjs +0 -172
  40. package/dist/chunks/config-switch.mjs +0 -317
  41. package/dist/chunks/config.mjs +0 -379
  42. package/dist/chunks/config2.mjs +0 -477
  43. package/dist/chunks/config3.mjs +0 -470
  44. package/dist/chunks/constants.mjs +0 -133
  45. package/dist/chunks/context-loader.mjs +0 -343
  46. package/dist/chunks/context.mjs +0 -372
  47. package/dist/chunks/convoy-manager.mjs +0 -880
  48. package/dist/chunks/dashboard.mjs +0 -476
  49. package/dist/chunks/doctor.mjs +0 -964
  50. package/dist/chunks/evolution.mjs +0 -382
  51. package/dist/chunks/features.mjs +0 -698
  52. package/dist/chunks/fish.mjs +0 -181
  53. package/dist/chunks/fs-operations.mjs +0 -192
  54. package/dist/chunks/health-alerts.mjs +0 -304
  55. package/dist/chunks/health-check.mjs +0 -532
  56. package/dist/chunks/help.mjs +0 -340
  57. package/dist/chunks/hook-installer.mjs +0 -45
  58. package/dist/chunks/index.mjs +0 -24
  59. package/dist/chunks/index10.mjs +0 -1171
  60. package/dist/chunks/index11.mjs +0 -1008
  61. package/dist/chunks/index12.mjs +0 -193
  62. package/dist/chunks/index13.mjs +0 -218
  63. package/dist/chunks/index14.mjs +0 -663
  64. package/dist/chunks/index2.mjs +0 -19
  65. package/dist/chunks/index3.mjs +0 -19092
  66. package/dist/chunks/index4.mjs +0 -8
  67. package/dist/chunks/index5.mjs +0 -7600
  68. package/dist/chunks/index6.mjs +0 -171
  69. package/dist/chunks/index7.mjs +0 -3583
  70. package/dist/chunks/index8.mjs +0 -19
  71. package/dist/chunks/index9.mjs +0 -616
  72. package/dist/chunks/init.mjs +0 -1606
  73. package/dist/chunks/installer.mjs +0 -690
  74. package/dist/chunks/installer2.mjs +0 -179
  75. package/dist/chunks/interview.mjs +0 -2927
  76. package/dist/chunks/json-config.mjs +0 -60
  77. package/dist/chunks/linux.mjs +0 -3863
  78. package/dist/chunks/macos.mjs +0 -69
  79. package/dist/chunks/main.mjs +0 -635
  80. package/dist/chunks/manager.mjs +0 -1048
  81. package/dist/chunks/marketplace.mjs +0 -949
  82. package/dist/chunks/mcp-cli.mjs +0 -204
  83. package/dist/chunks/mcp-performance.mjs +0 -187
  84. package/dist/chunks/mcp.mjs +0 -1231
  85. package/dist/chunks/menu.mjs +0 -652
  86. package/dist/chunks/metrics-display.mjs +0 -153
  87. package/dist/chunks/migrator.mjs +0 -178
  88. package/dist/chunks/monitor.mjs +0 -1856
  89. package/dist/chunks/notification.mjs +0 -1864
  90. package/dist/chunks/onboarding.mjs +0 -385
  91. package/dist/chunks/package.mjs +0 -3
  92. package/dist/chunks/paradigm.mjs +0 -74
  93. package/dist/chunks/permission-manager.mjs +0 -132
  94. package/dist/chunks/permissions.mjs +0 -265
  95. package/dist/chunks/persistence-manager.mjs +0 -794
  96. package/dist/chunks/persistence.mjs +0 -667
  97. package/dist/chunks/platform.mjs +0 -391
  98. package/dist/chunks/plugin.mjs +0 -1936
  99. package/dist/chunks/powershell.mjs +0 -213
  100. package/dist/chunks/prompts.mjs +0 -241
  101. package/dist/chunks/providers.mjs +0 -260
  102. package/dist/chunks/quick-actions.mjs +0 -320
  103. package/dist/chunks/quick-provider.mjs +0 -682
  104. package/dist/chunks/quick-setup.mjs +0 -412
  105. package/dist/chunks/remote.mjs +0 -497
  106. package/dist/chunks/session.mjs +0 -878
  107. package/dist/chunks/sessions.mjs +0 -106
  108. package/dist/chunks/silent-updater.mjs +0 -396
  109. package/dist/chunks/simple-config.mjs +0 -98
  110. package/dist/chunks/skill.mjs +0 -117
  111. package/dist/chunks/skill2.mjs +0 -9003
  112. package/dist/chunks/skills-sync.mjs +0 -6460
  113. package/dist/chunks/skills.mjs +0 -567
  114. package/dist/chunks/slash-commands.mjs +0 -207
  115. package/dist/chunks/smart-defaults.mjs +0 -412
  116. package/dist/chunks/smart-guide.mjs +0 -194
  117. package/dist/chunks/startup.mjs +0 -487
  118. package/dist/chunks/stats.mjs +0 -410
  119. package/dist/chunks/status.mjs +0 -289
  120. package/dist/chunks/team.mjs +0 -63
  121. package/dist/chunks/thinking.mjs +0 -626
  122. package/dist/chunks/trace.mjs +0 -57
  123. package/dist/chunks/uninstall.mjs +0 -849
  124. package/dist/chunks/update.mjs +0 -167
  125. package/dist/chunks/upgrade-manager.mjs +0 -204
  126. package/dist/chunks/version-checker.mjs +0 -881
  127. package/dist/chunks/vim.mjs +0 -903
  128. package/dist/chunks/windows.mjs +0 -14
  129. package/dist/chunks/workflows.mjs +0 -633
  130. package/dist/chunks/wsl.mjs +0 -129
  131. package/dist/chunks/zero-config.mjs +0 -374
  132. package/dist/chunks/zsh.mjs +0 -182
  133. package/dist/cli.d.mts +0 -1
  134. package/dist/cli.d.ts +0 -1
  135. package/dist/cli.mjs +0 -2199
  136. package/dist/i18n/locales/en/agent-teams.json +0 -18
  137. package/dist/i18n/locales/en/agentBrowser.json +0 -79
  138. package/dist/i18n/locales/en/agents.json +0 -135
  139. package/dist/i18n/locales/en/api.json +0 -63
  140. package/dist/i18n/locales/en/ccjk-agents.json +0 -33
  141. package/dist/i18n/locales/en/ccjk-all.json +0 -23
  142. package/dist/i18n/locales/en/ccjk-skills.json +0 -22
  143. package/dist/i18n/locales/en/ccjk.json +0 -276
  144. package/dist/i18n/locales/en/ccr.json +0 -65
  145. package/dist/i18n/locales/en/claude-md.json +0 -73
  146. package/dist/i18n/locales/en/cli.json +0 -152
  147. package/dist/i18n/locales/en/cloud-setup.json +0 -31
  148. package/dist/i18n/locales/en/cloud-sync.json +0 -147
  149. package/dist/i18n/locales/en/cloud.json +0 -40
  150. package/dist/i18n/locales/en/cloudPlugins.json +0 -118
  151. package/dist/i18n/locales/en/codex.json +0 -127
  152. package/dist/i18n/locales/en/cometix.json +0 -29
  153. package/dist/i18n/locales/en/common.json +0 -68
  154. package/dist/i18n/locales/en/config.json +0 -108
  155. package/dist/i18n/locales/en/configuration.json +0 -226
  156. package/dist/i18n/locales/en/context.json +0 -85
  157. package/dist/i18n/locales/en/dashboard.json +0 -78
  158. package/dist/i18n/locales/en/errors.json +0 -26
  159. package/dist/i18n/locales/en/evolution.json +0 -54
  160. package/dist/i18n/locales/en/hooks.json +0 -74
  161. package/dist/i18n/locales/en/hooksSync.json +0 -133
  162. package/dist/i18n/locales/en/installation.json +0 -83
  163. package/dist/i18n/locales/en/interview.json +0 -104
  164. package/dist/i18n/locales/en/language.json +0 -19
  165. package/dist/i18n/locales/en/lsp.json +0 -78
  166. package/dist/i18n/locales/en/marketplace.json +0 -116
  167. package/dist/i18n/locales/en/mcp.json +0 -178
  168. package/dist/i18n/locales/en/memory.json +0 -92
  169. package/dist/i18n/locales/en/menu.json +0 -143
  170. package/dist/i18n/locales/en/multi-config.json +0 -79
  171. package/dist/i18n/locales/en/notification.json +0 -307
  172. package/dist/i18n/locales/en/permissions.json +0 -95
  173. package/dist/i18n/locales/en/persistence.json +0 -127
  174. package/dist/i18n/locales/en/plugins.json +0 -146
  175. package/dist/i18n/locales/en/quick-actions.json +0 -78
  176. package/dist/i18n/locales/en/registry.json +0 -54
  177. package/dist/i18n/locales/en/remote.json +0 -93
  178. package/dist/i18n/locales/en/sandbox.json +0 -44
  179. package/dist/i18n/locales/en/setup.json +0 -44
  180. package/dist/i18n/locales/en/shencha.json +0 -14
  181. package/dist/i18n/locales/en/skills.json +0 -100
  182. package/dist/i18n/locales/en/skillsSync.json +0 -74
  183. package/dist/i18n/locales/en/smartGuide.json +0 -49
  184. package/dist/i18n/locales/en/stats.json +0 -20
  185. package/dist/i18n/locales/en/subagent.json +0 -69
  186. package/dist/i18n/locales/en/superpowers.json +0 -117
  187. package/dist/i18n/locales/en/team.json +0 -7
  188. package/dist/i18n/locales/en/thinking.json +0 -65
  189. package/dist/i18n/locales/en/tools.json +0 -42
  190. package/dist/i18n/locales/en/uninstall.json +0 -56
  191. package/dist/i18n/locales/en/updater.json +0 -29
  192. package/dist/i18n/locales/en/vim.json +0 -169
  193. package/dist/i18n/locales/en/workflow.json +0 -55
  194. package/dist/i18n/locales/en/workspace.json +0 -108
  195. package/dist/i18n/locales/zh-CN/agent-teams.json +0 -18
  196. package/dist/i18n/locales/zh-CN/agentBrowser.json +0 -79
  197. package/dist/i18n/locales/zh-CN/agents.json +0 -135
  198. package/dist/i18n/locales/zh-CN/api.json +0 -63
  199. package/dist/i18n/locales/zh-CN/ccjk-agents.json +0 -33
  200. package/dist/i18n/locales/zh-CN/ccjk-all.json +0 -23
  201. package/dist/i18n/locales/zh-CN/ccjk-skills.json +0 -22
  202. package/dist/i18n/locales/zh-CN/ccjk.json +0 -276
  203. package/dist/i18n/locales/zh-CN/ccr.json +0 -65
  204. package/dist/i18n/locales/zh-CN/claude-md.json +0 -73
  205. package/dist/i18n/locales/zh-CN/cli.json +0 -152
  206. package/dist/i18n/locales/zh-CN/cloud-setup.json +0 -31
  207. package/dist/i18n/locales/zh-CN/cloud-sync.json +0 -147
  208. package/dist/i18n/locales/zh-CN/cloud.json +0 -40
  209. package/dist/i18n/locales/zh-CN/cloudPlugins.json +0 -118
  210. package/dist/i18n/locales/zh-CN/codex.json +0 -127
  211. package/dist/i18n/locales/zh-CN/cometix.json +0 -29
  212. package/dist/i18n/locales/zh-CN/common.json +0 -68
  213. package/dist/i18n/locales/zh-CN/config.json +0 -108
  214. package/dist/i18n/locales/zh-CN/configuration.json +0 -224
  215. package/dist/i18n/locales/zh-CN/context.json +0 -85
  216. package/dist/i18n/locales/zh-CN/dashboard.json +0 -78
  217. package/dist/i18n/locales/zh-CN/errors.json +0 -26
  218. package/dist/i18n/locales/zh-CN/evolution.json +0 -54
  219. package/dist/i18n/locales/zh-CN/hooks.json +0 -74
  220. package/dist/i18n/locales/zh-CN/hooksSync.json +0 -133
  221. package/dist/i18n/locales/zh-CN/installation.json +0 -83
  222. package/dist/i18n/locales/zh-CN/interview.json +0 -104
  223. package/dist/i18n/locales/zh-CN/language.json +0 -19
  224. package/dist/i18n/locales/zh-CN/lsp.json +0 -78
  225. package/dist/i18n/locales/zh-CN/marketplace.json +0 -116
  226. package/dist/i18n/locales/zh-CN/mcp.json +0 -178
  227. package/dist/i18n/locales/zh-CN/memory.json +0 -92
  228. package/dist/i18n/locales/zh-CN/menu.json +0 -143
  229. package/dist/i18n/locales/zh-CN/multi-config.json +0 -79
  230. package/dist/i18n/locales/zh-CN/notification.json +0 -307
  231. package/dist/i18n/locales/zh-CN/permissions.json +0 -95
  232. package/dist/i18n/locales/zh-CN/persistence.json +0 -127
  233. package/dist/i18n/locales/zh-CN/plugins.json +0 -146
  234. package/dist/i18n/locales/zh-CN/quick-actions.json +0 -78
  235. package/dist/i18n/locales/zh-CN/registry.json +0 -54
  236. package/dist/i18n/locales/zh-CN/remote.json +0 -93
  237. package/dist/i18n/locales/zh-CN/sandbox.json +0 -44
  238. package/dist/i18n/locales/zh-CN/setup.json +0 -44
  239. package/dist/i18n/locales/zh-CN/shencha.json +0 -14
  240. package/dist/i18n/locales/zh-CN/skills.json +0 -100
  241. package/dist/i18n/locales/zh-CN/skillsSync.json +0 -74
  242. package/dist/i18n/locales/zh-CN/smartGuide.json +0 -49
  243. package/dist/i18n/locales/zh-CN/stats.json +0 -20
  244. package/dist/i18n/locales/zh-CN/subagent.json +0 -69
  245. package/dist/i18n/locales/zh-CN/superpowers.json +0 -117
  246. package/dist/i18n/locales/zh-CN/team.json +0 -7
  247. package/dist/i18n/locales/zh-CN/thinking.json +0 -65
  248. package/dist/i18n/locales/zh-CN/tools.json +0 -42
  249. package/dist/i18n/locales/zh-CN/uninstall.json +0 -56
  250. package/dist/i18n/locales/zh-CN/updater.json +0 -29
  251. package/dist/i18n/locales/zh-CN/vim.json +0 -169
  252. package/dist/i18n/locales/zh-CN/workflow.json +0 -55
  253. package/dist/i18n/locales/zh-CN/workspace.json +0 -108
  254. package/dist/index.d.mts +0 -5295
  255. package/dist/index.d.ts +0 -5295
  256. package/dist/index.mjs +0 -4941
  257. package/dist/shared/ccjk.B364Fu0N.mjs +0 -1819
  258. package/dist/shared/ccjk.BAGoDD49.mjs +0 -36
  259. package/dist/shared/ccjk.BBtCGd_g.mjs +0 -899
  260. package/dist/shared/ccjk.BFQ7yr5S.mjs +0 -16
  261. package/dist/shared/ccjk.BFxsJM0k.mjs +0 -599
  262. package/dist/shared/ccjk.BIxuVL3_.mjs +0 -25
  263. package/dist/shared/ccjk.BRZ9ww8S.mjs +0 -142
  264. package/dist/shared/ccjk.BoApaI4j.mjs +0 -28
  265. package/dist/shared/ccjk.BrPUmTqm.mjs +0 -266
  266. package/dist/shared/ccjk.BtB1e5jm.mjs +0 -171
  267. package/dist/shared/ccjk.BwfbSKN2.mjs +0 -1051
  268. package/dist/shared/ccjk.BxSmJ8B7.mjs +0 -243
  269. package/dist/shared/ccjk.Bx_rmYfN.mjs +0 -69
  270. package/dist/shared/ccjk.C2jHOZVP.mjs +0 -52
  271. package/dist/shared/ccjk.CL4Yat0G.mjs +0 -303
  272. package/dist/shared/ccjk.COweQ1RR.mjs +0 -5
  273. package/dist/shared/ccjk.CePkJq2S.mjs +0 -223
  274. package/dist/shared/ccjk.CfKKcvWy.mjs +0 -126
  275. package/dist/shared/ccjk.Cjgrln_h.mjs +0 -297
  276. package/dist/shared/ccjk.Cjj8SVrn.mjs +0 -54
  277. package/dist/shared/ccjk.CxpGa6MC.mjs +0 -2724
  278. package/dist/shared/ccjk.D5MFQT7w.mjs +0 -400
  279. package/dist/shared/ccjk.D6ycHbak.mjs +0 -270
  280. package/dist/shared/ccjk.D8ZLYSZZ.mjs +0 -299
  281. package/dist/shared/ccjk.DG_o24cZ.mjs +0 -88
  282. package/dist/shared/ccjk.DLLw-h4Y.mjs +0 -460
  283. package/dist/shared/ccjk.DOwtZMk8.mjs +0 -4019
  284. package/dist/shared/ccjk.DS7UESmF.mjs +0 -2451
  285. package/dist/shared/ccjk.DTdjs-qK.mjs +0 -1447
  286. package/dist/shared/ccjk.DXRAZcix.mjs +0 -66
  287. package/dist/shared/ccjk.DsYaCCx4.mjs +0 -317
  288. package/dist/shared/ccjk.J8YiPsOw.mjs +0 -259
  289. package/dist/shared/ccjk.KfSWcGlE.mjs +0 -38
  290. package/dist/shared/ccjk.RyizuzOI.mjs +0 -21
  291. package/dist/shared/ccjk.SPoXMvZD.mjs +0 -1242
  292. package/dist/shared/ccjk.T_cX87dY.mjs +0 -15
  293. package/dist/shared/ccjk.UIvifqNE.mjs +0 -1486
  294. package/dist/shared/ccjk._dESH4Rk.mjs +0 -111
  295. package/dist/shared/ccjk.bQ7Dh1g4.mjs +0 -249
  296. package/dist/shared/ccjk.c-ETfBZ_.mjs +0 -617
  297. package/dist/shared/ccjk.gDEDGD_t.mjs +0 -38
  298. package/dist/shared/ccjk.hoqrwWdN.mjs +0 -333
  299. package/dist/shared/ccjk.waa2ikKJ.mjs +0 -351
@@ -1,1486 +0,0 @@
1
- const LogLevels = {
2
- fatal: 0,
3
- error: 0,
4
- warn: 1,
5
- log: 2,
6
- info: 3,
7
- success: 3,
8
- fail: 3,
9
- debug: 4,
10
- trace: 5,
11
- verbose: Number.POSITIVE_INFINITY
12
- };
13
- const LogTypes = {
14
- // Silent
15
- silent: {
16
- level: -1
17
- },
18
- // Level 0
19
- fatal: {
20
- level: LogLevels.fatal
21
- },
22
- error: {
23
- level: LogLevels.error
24
- },
25
- // Level 1
26
- warn: {
27
- level: LogLevels.warn
28
- },
29
- // Level 2
30
- log: {
31
- level: LogLevels.log
32
- },
33
- // Level 3
34
- info: {
35
- level: LogLevels.info
36
- },
37
- success: {
38
- level: LogLevels.success
39
- },
40
- fail: {
41
- level: LogLevels.fail
42
- },
43
- ready: {
44
- level: LogLevels.info
45
- },
46
- start: {
47
- level: LogLevels.info
48
- },
49
- box: {
50
- level: LogLevels.info
51
- },
52
- // Level 4
53
- debug: {
54
- level: LogLevels.debug
55
- },
56
- // Level 5
57
- trace: {
58
- level: LogLevels.trace
59
- },
60
- // Verbose
61
- verbose: {
62
- level: LogLevels.verbose
63
- }
64
- };
65
-
66
- function isPlainObject$1(value) {
67
- if (value === null || typeof value !== "object") {
68
- return false;
69
- }
70
- const prototype = Object.getPrototypeOf(value);
71
- if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
72
- return false;
73
- }
74
- if (Symbol.iterator in value) {
75
- return false;
76
- }
77
- if (Symbol.toStringTag in value) {
78
- return Object.prototype.toString.call(value) === "[object Module]";
79
- }
80
- return true;
81
- }
82
-
83
- function _defu(baseObject, defaults, namespace = ".", merger) {
84
- if (!isPlainObject$1(defaults)) {
85
- return _defu(baseObject, {}, namespace);
86
- }
87
- const object = Object.assign({}, defaults);
88
- for (const key in baseObject) {
89
- if (key === "__proto__" || key === "constructor") {
90
- continue;
91
- }
92
- const value = baseObject[key];
93
- if (value === null || value === void 0) {
94
- continue;
95
- }
96
- if (Array.isArray(value) && Array.isArray(object[key])) {
97
- object[key] = [...value, ...object[key]];
98
- } else if (isPlainObject$1(value) && isPlainObject$1(object[key])) {
99
- object[key] = _defu(
100
- value,
101
- object[key],
102
- (namespace ? `${namespace}.` : "") + key.toString());
103
- } else {
104
- object[key] = value;
105
- }
106
- }
107
- return object;
108
- }
109
- function createDefu(merger) {
110
- return (...arguments_) => (
111
- // eslint-disable-next-line unicorn/no-array-reduce
112
- arguments_.reduce((p, c) => _defu(p, c, ""), {})
113
- );
114
- }
115
- const defu = createDefu();
116
-
117
- function isPlainObject(obj) {
118
- return Object.prototype.toString.call(obj) === "[object Object]";
119
- }
120
- function isLogObj(arg) {
121
- if (!isPlainObject(arg)) {
122
- return false;
123
- }
124
- if (!arg.message && !arg.args) {
125
- return false;
126
- }
127
- if (arg.stack) {
128
- return false;
129
- }
130
- return true;
131
- }
132
-
133
- let paused = false;
134
- const queue = [];
135
- class Consola {
136
- options;
137
- _lastLog;
138
- _mockFn;
139
- /**
140
- * Creates an instance of Consola with specified options or defaults.
141
- *
142
- * @param {Partial<ConsolaOptions>} [options={}] - Configuration options for the Consola instance.
143
- */
144
- constructor(options = {}) {
145
- const types = options.types || LogTypes;
146
- this.options = defu(
147
- {
148
- ...options,
149
- defaults: { ...options.defaults },
150
- level: _normalizeLogLevel(options.level, types),
151
- reporters: [...options.reporters || []]
152
- },
153
- {
154
- types: LogTypes,
155
- throttle: 1e3,
156
- throttleMin: 5,
157
- formatOptions: {
158
- date: true,
159
- colors: false,
160
- compact: true
161
- }
162
- }
163
- );
164
- for (const type in types) {
165
- const defaults = {
166
- type,
167
- ...this.options.defaults,
168
- ...types[type]
169
- };
170
- this[type] = this._wrapLogFn(defaults);
171
- this[type].raw = this._wrapLogFn(
172
- defaults,
173
- true
174
- );
175
- }
176
- if (this.options.mockFn) {
177
- this.mockTypes();
178
- }
179
- this._lastLog = {};
180
- }
181
- /**
182
- * Gets the current log level of the Consola instance.
183
- *
184
- * @returns {number} The current log level.
185
- */
186
- get level() {
187
- return this.options.level;
188
- }
189
- /**
190
- * Sets the minimum log level that will be output by the instance.
191
- *
192
- * @param {number} level - The new log level to set.
193
- */
194
- set level(level) {
195
- this.options.level = _normalizeLogLevel(
196
- level,
197
- this.options.types,
198
- this.options.level
199
- );
200
- }
201
- /**
202
- * Displays a prompt to the user and returns the response.
203
- * Throw an error if `prompt` is not supported by the current configuration.
204
- *
205
- * @template T
206
- * @param {string} message - The message to display in the prompt.
207
- * @param {T} [opts] - Optional options for the prompt. See {@link PromptOptions}.
208
- * @returns {promise<T>} A promise that infer with the prompt options. See {@link PromptOptions}.
209
- */
210
- prompt(message, opts) {
211
- if (!this.options.prompt) {
212
- throw new Error("prompt is not supported!");
213
- }
214
- return this.options.prompt(message, opts);
215
- }
216
- /**
217
- * Creates a new instance of Consola, inheriting options from the current instance, with possible overrides.
218
- *
219
- * @param {Partial<ConsolaOptions>} options - Optional overrides for the new instance. See {@link ConsolaOptions}.
220
- * @returns {ConsolaInstance} A new Consola instance. See {@link ConsolaInstance}.
221
- */
222
- create(options) {
223
- const instance = new Consola({
224
- ...this.options,
225
- ...options
226
- });
227
- if (this._mockFn) {
228
- instance.mockTypes(this._mockFn);
229
- }
230
- return instance;
231
- }
232
- /**
233
- * Creates a new Consola instance with the specified default log object properties.
234
- *
235
- * @param {InputLogObject} defaults - Default properties to include in any log from the new instance. See {@link InputLogObject}.
236
- * @returns {ConsolaInstance} A new Consola instance. See {@link ConsolaInstance}.
237
- */
238
- withDefaults(defaults) {
239
- return this.create({
240
- ...this.options,
241
- defaults: {
242
- ...this.options.defaults,
243
- ...defaults
244
- }
245
- });
246
- }
247
- /**
248
- * Creates a new Consola instance with a specified tag, which will be included in every log.
249
- *
250
- * @param {string} tag - The tag to include in each log of the new instance.
251
- * @returns {ConsolaInstance} A new Consola instance. See {@link ConsolaInstance}.
252
- */
253
- withTag(tag) {
254
- return this.withDefaults({
255
- tag: this.options.defaults.tag ? this.options.defaults.tag + ":" + tag : tag
256
- });
257
- }
258
- /**
259
- * Adds a custom reporter to the Consola instance.
260
- * Reporters will be called for each log message, depending on their implementation and log level.
261
- *
262
- * @param {ConsolaReporter} reporter - The reporter to add. See {@link ConsolaReporter}.
263
- * @returns {Consola} The current Consola instance.
264
- */
265
- addReporter(reporter) {
266
- this.options.reporters.push(reporter);
267
- return this;
268
- }
269
- /**
270
- * Removes a custom reporter from the Consola instance.
271
- * If no reporter is specified, all reporters will be removed.
272
- *
273
- * @param {ConsolaReporter} reporter - The reporter to remove. See {@link ConsolaReporter}.
274
- * @returns {Consola} The current Consola instance.
275
- */
276
- removeReporter(reporter) {
277
- if (reporter) {
278
- const i = this.options.reporters.indexOf(reporter);
279
- if (i !== -1) {
280
- return this.options.reporters.splice(i, 1);
281
- }
282
- } else {
283
- this.options.reporters.splice(0);
284
- }
285
- return this;
286
- }
287
- /**
288
- * Replaces all reporters of the Consola instance with the specified array of reporters.
289
- *
290
- * @param {ConsolaReporter[]} reporters - The new reporters to set. See {@link ConsolaReporter}.
291
- * @returns {Consola} The current Consola instance.
292
- */
293
- setReporters(reporters) {
294
- this.options.reporters = Array.isArray(reporters) ? reporters : [reporters];
295
- return this;
296
- }
297
- wrapAll() {
298
- this.wrapConsole();
299
- this.wrapStd();
300
- }
301
- restoreAll() {
302
- this.restoreConsole();
303
- this.restoreStd();
304
- }
305
- /**
306
- * Overrides console methods with Consola logging methods for consistent logging.
307
- */
308
- wrapConsole() {
309
- for (const type in this.options.types) {
310
- if (!console["__" + type]) {
311
- console["__" + type] = console[type];
312
- }
313
- console[type] = this[type].raw;
314
- }
315
- }
316
- /**
317
- * Restores the original console methods, removing Consola overrides.
318
- */
319
- restoreConsole() {
320
- for (const type in this.options.types) {
321
- if (console["__" + type]) {
322
- console[type] = console["__" + type];
323
- delete console["__" + type];
324
- }
325
- }
326
- }
327
- /**
328
- * Overrides standard output and error streams to redirect them through Consola.
329
- */
330
- wrapStd() {
331
- this._wrapStream(this.options.stdout, "log");
332
- this._wrapStream(this.options.stderr, "log");
333
- }
334
- _wrapStream(stream, type) {
335
- if (!stream) {
336
- return;
337
- }
338
- if (!stream.__write) {
339
- stream.__write = stream.write;
340
- }
341
- stream.write = (data) => {
342
- this[type].raw(String(data).trim());
343
- };
344
- }
345
- /**
346
- * Restores the original standard output and error streams, removing the Consola redirection.
347
- */
348
- restoreStd() {
349
- this._restoreStream(this.options.stdout);
350
- this._restoreStream(this.options.stderr);
351
- }
352
- _restoreStream(stream) {
353
- if (!stream) {
354
- return;
355
- }
356
- if (stream.__write) {
357
- stream.write = stream.__write;
358
- delete stream.__write;
359
- }
360
- }
361
- /**
362
- * Pauses logging, queues incoming logs until resumed.
363
- */
364
- pauseLogs() {
365
- paused = true;
366
- }
367
- /**
368
- * Resumes logging, processing any queued logs.
369
- */
370
- resumeLogs() {
371
- paused = false;
372
- const _queue = queue.splice(0);
373
- for (const item of _queue) {
374
- item[0]._logFn(item[1], item[2]);
375
- }
376
- }
377
- /**
378
- * Replaces logging methods with mocks if a mock function is provided.
379
- *
380
- * @param {ConsolaOptions["mockFn"]} mockFn - The function to use for mocking logging methods. See {@link ConsolaOptions["mockFn"]}.
381
- */
382
- mockTypes(mockFn) {
383
- const _mockFn = mockFn || this.options.mockFn;
384
- this._mockFn = _mockFn;
385
- if (typeof _mockFn !== "function") {
386
- return;
387
- }
388
- for (const type in this.options.types) {
389
- this[type] = _mockFn(type, this.options.types[type]) || this[type];
390
- this[type].raw = this[type];
391
- }
392
- }
393
- _wrapLogFn(defaults, isRaw) {
394
- return (...args) => {
395
- if (paused) {
396
- queue.push([this, defaults, args, isRaw]);
397
- return;
398
- }
399
- return this._logFn(defaults, args, isRaw);
400
- };
401
- }
402
- _logFn(defaults, args, isRaw) {
403
- if ((defaults.level || 0) > this.level) {
404
- return false;
405
- }
406
- const logObj = {
407
- date: /* @__PURE__ */ new Date(),
408
- args: [],
409
- ...defaults,
410
- level: _normalizeLogLevel(defaults.level, this.options.types)
411
- };
412
- if (!isRaw && args.length === 1 && isLogObj(args[0])) {
413
- Object.assign(logObj, args[0]);
414
- } else {
415
- logObj.args = [...args];
416
- }
417
- if (logObj.message) {
418
- logObj.args.unshift(logObj.message);
419
- delete logObj.message;
420
- }
421
- if (logObj.additional) {
422
- if (!Array.isArray(logObj.additional)) {
423
- logObj.additional = logObj.additional.split("\n");
424
- }
425
- logObj.args.push("\n" + logObj.additional.join("\n"));
426
- delete logObj.additional;
427
- }
428
- logObj.type = typeof logObj.type === "string" ? logObj.type.toLowerCase() : "log";
429
- logObj.tag = typeof logObj.tag === "string" ? logObj.tag : "";
430
- const resolveLog = (newLog = false) => {
431
- const repeated = (this._lastLog.count || 0) - this.options.throttleMin;
432
- if (this._lastLog.object && repeated > 0) {
433
- const args2 = [...this._lastLog.object.args];
434
- if (repeated > 1) {
435
- args2.push(`(repeated ${repeated} times)`);
436
- }
437
- this._log({ ...this._lastLog.object, args: args2 });
438
- this._lastLog.count = 1;
439
- }
440
- if (newLog) {
441
- this._lastLog.object = logObj;
442
- this._log(logObj);
443
- }
444
- };
445
- clearTimeout(this._lastLog.timeout);
446
- const diffTime = this._lastLog.time && logObj.date ? logObj.date.getTime() - this._lastLog.time.getTime() : 0;
447
- this._lastLog.time = logObj.date;
448
- if (diffTime < this.options.throttle) {
449
- try {
450
- const serializedLog = JSON.stringify([
451
- logObj.type,
452
- logObj.tag,
453
- logObj.args
454
- ]);
455
- const isSameLog = this._lastLog.serialized === serializedLog;
456
- this._lastLog.serialized = serializedLog;
457
- if (isSameLog) {
458
- this._lastLog.count = (this._lastLog.count || 0) + 1;
459
- if (this._lastLog.count > this.options.throttleMin) {
460
- this._lastLog.timeout = setTimeout(
461
- resolveLog,
462
- this.options.throttle
463
- );
464
- return;
465
- }
466
- }
467
- } catch {
468
- }
469
- }
470
- resolveLog(true);
471
- }
472
- _log(logObj) {
473
- for (const reporter of this.options.reporters) {
474
- reporter.log(logObj, {
475
- options: this.options
476
- });
477
- }
478
- }
479
- }
480
- function _normalizeLogLevel(input, types = {}, defaultLevel = 3) {
481
- if (input === void 0) {
482
- return defaultLevel;
483
- }
484
- if (typeof input === "number") {
485
- return input;
486
- }
487
- if (types[input] && types[input].level !== void 0) {
488
- return types[input].level;
489
- }
490
- return defaultLevel;
491
- }
492
- Consola.prototype.add = Consola.prototype.addReporter;
493
- Consola.prototype.remove = Consola.prototype.removeReporter;
494
- Consola.prototype.clear = Consola.prototype.removeReporter;
495
- Consola.prototype.withScope = Consola.prototype.withTag;
496
- Consola.prototype.mock = Consola.prototype.mockTypes;
497
- Consola.prototype.pause = Consola.prototype.pauseLogs;
498
- Consola.prototype.resume = Consola.prototype.resumeLogs;
499
- function createConsola$1(options = {}) {
500
- return new Consola(options);
501
- }
502
-
503
- class BrowserReporter {
504
- options;
505
- defaultColor;
506
- levelColorMap;
507
- typeColorMap;
508
- constructor(options) {
509
- this.options = { ...options };
510
- this.defaultColor = "#7f8c8d";
511
- this.levelColorMap = {
512
- 0: "#c0392b",
513
- // Red
514
- 1: "#f39c12",
515
- // Yellow
516
- 3: "#00BCD4"
517
- // Cyan
518
- };
519
- this.typeColorMap = {
520
- success: "#2ecc71"
521
- // Green
522
- };
523
- }
524
- _getLogFn(level) {
525
- if (level < 1) {
526
- return console.__error || console.error;
527
- }
528
- if (level === 1) {
529
- return console.__warn || console.warn;
530
- }
531
- return console.__log || console.log;
532
- }
533
- log(logObj) {
534
- const consoleLogFn = this._getLogFn(logObj.level);
535
- const type = logObj.type === "log" ? "" : logObj.type;
536
- const tag = logObj.tag || "";
537
- const color = this.typeColorMap[logObj.type] || this.levelColorMap[logObj.level] || this.defaultColor;
538
- const style = `
539
- background: ${color};
540
- border-radius: 0.5em;
541
- color: white;
542
- font-weight: bold;
543
- padding: 2px 0.5em;
544
- `;
545
- const badge = `%c${[tag, type].filter(Boolean).join(":")}`;
546
- if (typeof logObj.args[0] === "string") {
547
- consoleLogFn(
548
- `${badge}%c ${logObj.args[0]}`,
549
- style,
550
- // Empty string as style resets to default console style
551
- "",
552
- ...logObj.args.slice(1)
553
- );
554
- } else {
555
- consoleLogFn(badge, style, ...logObj.args);
556
- }
557
- }
558
- }
559
-
560
- function createConsola(options = {}) {
561
- const consola2 = createConsola$1({
562
- reporters: options.reporters || [new BrowserReporter({})],
563
- prompt(message, options2 = {}) {
564
- if (options2.type === "confirm") {
565
- return Promise.resolve(confirm(message));
566
- }
567
- return Promise.resolve(prompt(message));
568
- },
569
- ...options
570
- });
571
- return consola2;
572
- }
573
- const consola = createConsola();
574
-
575
- 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*:/;
576
- 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*:/;
577
- const JsonSigRx = /^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;
578
- function jsonParseTransform(key, value) {
579
- if (key === "__proto__" || key === "constructor" && value && typeof value === "object" && "prototype" in value) {
580
- warnKeyDropped(key);
581
- return;
582
- }
583
- return value;
584
- }
585
- function warnKeyDropped(key) {
586
- console.warn(`[destr] Dropping "${key}" key to prevent prototype pollution.`);
587
- }
588
- function destr(value, options = {}) {
589
- if (typeof value !== "string") {
590
- return value;
591
- }
592
- if (value[0] === '"' && value[value.length - 1] === '"' && value.indexOf("\\") === -1) {
593
- return value.slice(1, -1);
594
- }
595
- const _value = value.trim();
596
- if (_value.length <= 9) {
597
- switch (_value.toLowerCase()) {
598
- case "true": {
599
- return true;
600
- }
601
- case "false": {
602
- return false;
603
- }
604
- case "undefined": {
605
- return void 0;
606
- }
607
- case "null": {
608
- return null;
609
- }
610
- case "nan": {
611
- return Number.NaN;
612
- }
613
- case "infinity": {
614
- return Number.POSITIVE_INFINITY;
615
- }
616
- case "-infinity": {
617
- return Number.NEGATIVE_INFINITY;
618
- }
619
- }
620
- }
621
- if (!JsonSigRx.test(value)) {
622
- if (options.strict) {
623
- throw new SyntaxError("[destr] Invalid JSON");
624
- }
625
- return value;
626
- }
627
- try {
628
- if (suspectProtoRx.test(value) || suspectConstructorRx.test(value)) {
629
- if (options.strict) {
630
- throw new Error("[destr] Possible prototype pollution");
631
- }
632
- return JSON.parse(value, jsonParseTransform);
633
- }
634
- return JSON.parse(value);
635
- } catch (error) {
636
- if (options.strict) {
637
- throw error;
638
- }
639
- return value;
640
- }
641
- }
642
-
643
- const HASH_RE = /#/g;
644
- const AMPERSAND_RE = /&/g;
645
- const SLASH_RE = /\//g;
646
- const EQUAL_RE = /=/g;
647
- const PLUS_RE = /\+/g;
648
- const ENC_CARET_RE = /%5e/gi;
649
- const ENC_BACKTICK_RE = /%60/gi;
650
- const ENC_PIPE_RE = /%7c/gi;
651
- const ENC_SPACE_RE = /%20/gi;
652
- function encode(text) {
653
- return encodeURI("" + text).replace(ENC_PIPE_RE, "|");
654
- }
655
- function encodeQueryValue(input) {
656
- 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");
657
- }
658
- function encodeQueryKey(text) {
659
- return encodeQueryValue(text).replace(EQUAL_RE, "%3D");
660
- }
661
- function decode(text = "") {
662
- try {
663
- return decodeURIComponent("" + text);
664
- } catch {
665
- return "" + text;
666
- }
667
- }
668
- function decodeQueryKey(text) {
669
- return decode(text.replace(PLUS_RE, " "));
670
- }
671
- function decodeQueryValue(text) {
672
- return decode(text.replace(PLUS_RE, " "));
673
- }
674
-
675
- function parseQuery(parametersString = "") {
676
- const object = /* @__PURE__ */ Object.create(null);
677
- if (parametersString[0] === "?") {
678
- parametersString = parametersString.slice(1);
679
- }
680
- for (const parameter of parametersString.split("&")) {
681
- const s = parameter.match(/([^=]+)=?(.*)/) || [];
682
- if (s.length < 2) {
683
- continue;
684
- }
685
- const key = decodeQueryKey(s[1]);
686
- if (key === "__proto__" || key === "constructor") {
687
- continue;
688
- }
689
- const value = decodeQueryValue(s[2] || "");
690
- if (object[key] === void 0) {
691
- object[key] = value;
692
- } else if (Array.isArray(object[key])) {
693
- object[key].push(value);
694
- } else {
695
- object[key] = [object[key], value];
696
- }
697
- }
698
- return object;
699
- }
700
- function encodeQueryItem(key, value) {
701
- if (typeof value === "number" || typeof value === "boolean") {
702
- value = String(value);
703
- }
704
- if (!value) {
705
- return encodeQueryKey(key);
706
- }
707
- if (Array.isArray(value)) {
708
- return value.map(
709
- (_value) => `${encodeQueryKey(key)}=${encodeQueryValue(_value)}`
710
- ).join("&");
711
- }
712
- return `${encodeQueryKey(key)}=${encodeQueryValue(value)}`;
713
- }
714
- function stringifyQuery(query) {
715
- return Object.keys(query).filter((k) => query[k] !== void 0).map((k) => encodeQueryItem(k, query[k])).filter(Boolean).join("&");
716
- }
717
-
718
- const PROTOCOL_STRICT_REGEX = /^[\s\w\0+.-]{2,}:([/\\]{1,2})/;
719
- const PROTOCOL_REGEX = /^[\s\w\0+.-]{2,}:([/\\]{2})?/;
720
- const PROTOCOL_RELATIVE_REGEX = /^([/\\]\s*){2,}[^/\\]/;
721
- const JOIN_LEADING_SLASH_RE = /^\.?\//;
722
- function hasProtocol(inputString, opts = {}) {
723
- if (typeof opts === "boolean") {
724
- opts = { acceptRelative: opts };
725
- }
726
- if (opts.strict) {
727
- return PROTOCOL_STRICT_REGEX.test(inputString);
728
- }
729
- return PROTOCOL_REGEX.test(inputString) || (opts.acceptRelative ? PROTOCOL_RELATIVE_REGEX.test(inputString) : false);
730
- }
731
- function hasTrailingSlash(input = "", respectQueryAndFragment) {
732
- {
733
- return input.endsWith("/");
734
- }
735
- }
736
- function withoutTrailingSlash(input = "", respectQueryAndFragment) {
737
- {
738
- return (hasTrailingSlash(input) ? input.slice(0, -1) : input) || "/";
739
- }
740
- }
741
- function withTrailingSlash(input = "", respectQueryAndFragment) {
742
- {
743
- return input.endsWith("/") ? input : input + "/";
744
- }
745
- }
746
- function withBase(input, base) {
747
- if (isEmptyURL(base) || hasProtocol(input)) {
748
- return input;
749
- }
750
- const _base = withoutTrailingSlash(base);
751
- if (input.startsWith(_base)) {
752
- return input;
753
- }
754
- return joinURL(_base, input);
755
- }
756
- function withQuery(input, query) {
757
- const parsed = parseURL(input);
758
- const mergedQuery = { ...parseQuery(parsed.search), ...query };
759
- parsed.search = stringifyQuery(mergedQuery);
760
- return stringifyParsedURL(parsed);
761
- }
762
- function isEmptyURL(url) {
763
- return !url || url === "/";
764
- }
765
- function isNonEmptyURL(url) {
766
- return url && url !== "/";
767
- }
768
- function joinURL(base, ...input) {
769
- let url = base || "";
770
- for (const segment of input.filter((url2) => isNonEmptyURL(url2))) {
771
- if (url) {
772
- const _segment = segment.replace(JOIN_LEADING_SLASH_RE, "");
773
- url = withTrailingSlash(url) + _segment;
774
- } else {
775
- url = segment;
776
- }
777
- }
778
- return url;
779
- }
780
-
781
- const protocolRelative = Symbol.for("ufo:protocolRelative");
782
- function parseURL(input = "", defaultProto) {
783
- const _specialProtoMatch = input.match(
784
- /^[\s\0]*(blob:|data:|javascript:|vbscript:)(.*)/i
785
- );
786
- if (_specialProtoMatch) {
787
- const [, _proto, _pathname = ""] = _specialProtoMatch;
788
- return {
789
- protocol: _proto.toLowerCase(),
790
- pathname: _pathname,
791
- href: _proto + _pathname,
792
- auth: "",
793
- host: "",
794
- search: "",
795
- hash: ""
796
- };
797
- }
798
- if (!hasProtocol(input, { acceptRelative: true })) {
799
- return parsePath(input);
800
- }
801
- const [, protocol = "", auth, hostAndPath = ""] = input.replace(/\\/g, "/").match(/^[\s\0]*([\w+.-]{2,}:)?\/\/([^/@]+@)?(.*)/) || [];
802
- let [, host = "", path = ""] = hostAndPath.match(/([^#/?]*)(.*)?/) || [];
803
- if (protocol === "file:") {
804
- path = path.replace(/\/(?=[A-Za-z]:)/, "");
805
- }
806
- const { pathname, search, hash } = parsePath(path);
807
- return {
808
- protocol: protocol.toLowerCase(),
809
- auth: auth ? auth.slice(0, Math.max(0, auth.length - 1)) : "",
810
- host,
811
- pathname,
812
- search,
813
- hash,
814
- [protocolRelative]: !protocol
815
- };
816
- }
817
- function parsePath(input = "") {
818
- const [pathname = "", search = "", hash = ""] = (input.match(/([^#?]*)(\?[^#]*)?(#.*)?/) || []).splice(1);
819
- return {
820
- pathname,
821
- search,
822
- hash
823
- };
824
- }
825
- function stringifyParsedURL(parsed) {
826
- const pathname = parsed.pathname || "";
827
- const search = parsed.search ? (parsed.search.startsWith("?") ? "" : "?") + parsed.search : "";
828
- const hash = parsed.hash || "";
829
- const auth = parsed.auth ? parsed.auth + "@" : "";
830
- const host = parsed.host || "";
831
- const proto = parsed.protocol || parsed[protocolRelative] ? (parsed.protocol || "") + "//" : "";
832
- return proto + auth + host + pathname + search + hash;
833
- }
834
-
835
- class FetchError extends Error {
836
- constructor(message, opts) {
837
- super(message, opts);
838
- this.name = "FetchError";
839
- if (opts?.cause && !this.cause) {
840
- this.cause = opts.cause;
841
- }
842
- }
843
- }
844
- function createFetchError(ctx) {
845
- const errorMessage = ctx.error?.message || ctx.error?.toString() || "";
846
- const method = ctx.request?.method || ctx.options?.method || "GET";
847
- const url = ctx.request?.url || String(ctx.request) || "/";
848
- const requestStr = `[${method}] ${JSON.stringify(url)}`;
849
- const statusStr = ctx.response ? `${ctx.response.status} ${ctx.response.statusText}` : "<no response>";
850
- const message = `${requestStr}: ${statusStr}${errorMessage ? ` ${errorMessage}` : ""}`;
851
- const fetchError = new FetchError(
852
- message,
853
- ctx.error ? { cause: ctx.error } : void 0
854
- );
855
- for (const key of ["request", "options", "response"]) {
856
- Object.defineProperty(fetchError, key, {
857
- get() {
858
- return ctx[key];
859
- }
860
- });
861
- }
862
- for (const [key, refKey] of [
863
- ["data", "_data"],
864
- ["status", "status"],
865
- ["statusCode", "status"],
866
- ["statusText", "statusText"],
867
- ["statusMessage", "statusText"]
868
- ]) {
869
- Object.defineProperty(fetchError, key, {
870
- get() {
871
- return ctx.response && ctx.response[refKey];
872
- }
873
- });
874
- }
875
- return fetchError;
876
- }
877
-
878
- const payloadMethods = new Set(
879
- Object.freeze(["PATCH", "POST", "PUT", "DELETE"])
880
- );
881
- function isPayloadMethod(method = "GET") {
882
- return payloadMethods.has(method.toUpperCase());
883
- }
884
- function isJSONSerializable(value) {
885
- if (value === void 0) {
886
- return false;
887
- }
888
- const t = typeof value;
889
- if (t === "string" || t === "number" || t === "boolean" || t === null) {
890
- return true;
891
- }
892
- if (t !== "object") {
893
- return false;
894
- }
895
- if (Array.isArray(value)) {
896
- return true;
897
- }
898
- if (value.buffer) {
899
- return false;
900
- }
901
- if (value instanceof FormData || value instanceof URLSearchParams) {
902
- return false;
903
- }
904
- return value.constructor && value.constructor.name === "Object" || typeof value.toJSON === "function";
905
- }
906
- const textTypes = /* @__PURE__ */ new Set([
907
- "image/svg",
908
- "application/xml",
909
- "application/xhtml",
910
- "application/html"
911
- ]);
912
- const JSON_RE = /^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;
913
- function detectResponseType(_contentType = "") {
914
- if (!_contentType) {
915
- return "json";
916
- }
917
- const contentType = _contentType.split(";").shift() || "";
918
- if (JSON_RE.test(contentType)) {
919
- return "json";
920
- }
921
- if (contentType === "text/event-stream") {
922
- return "stream";
923
- }
924
- if (textTypes.has(contentType) || contentType.startsWith("text/")) {
925
- return "text";
926
- }
927
- return "blob";
928
- }
929
- function resolveFetchOptions(request, input, defaults, Headers) {
930
- const headers = mergeHeaders(
931
- input?.headers ?? request?.headers,
932
- defaults?.headers,
933
- Headers
934
- );
935
- let query;
936
- if (defaults?.query || defaults?.params || input?.params || input?.query) {
937
- query = {
938
- ...defaults?.params,
939
- ...defaults?.query,
940
- ...input?.params,
941
- ...input?.query
942
- };
943
- }
944
- return {
945
- ...defaults,
946
- ...input,
947
- query,
948
- params: query,
949
- headers
950
- };
951
- }
952
- function mergeHeaders(input, defaults, Headers) {
953
- if (!defaults) {
954
- return new Headers(input);
955
- }
956
- const headers = new Headers(defaults);
957
- if (input) {
958
- for (const [key, value] of Symbol.iterator in input || Array.isArray(input) ? input : new Headers(input)) {
959
- headers.set(key, value);
960
- }
961
- }
962
- return headers;
963
- }
964
- async function callHooks(context, hooks) {
965
- if (hooks) {
966
- if (Array.isArray(hooks)) {
967
- for (const hook of hooks) {
968
- await hook(context);
969
- }
970
- } else {
971
- await hooks(context);
972
- }
973
- }
974
- }
975
-
976
- const retryStatusCodes = /* @__PURE__ */ new Set([
977
- 408,
978
- // Request Timeout
979
- 409,
980
- // Conflict
981
- 425,
982
- // Too Early (Experimental)
983
- 429,
984
- // Too Many Requests
985
- 500,
986
- // Internal Server Error
987
- 502,
988
- // Bad Gateway
989
- 503,
990
- // Service Unavailable
991
- 504
992
- // Gateway Timeout
993
- ]);
994
- const nullBodyResponses = /* @__PURE__ */ new Set([101, 204, 205, 304]);
995
- function createFetch(globalOptions = {}) {
996
- const {
997
- fetch = globalThis.fetch,
998
- Headers = globalThis.Headers,
999
- AbortController = globalThis.AbortController
1000
- } = globalOptions;
1001
- async function onError(context) {
1002
- const isAbort = context.error && context.error.name === "AbortError" && !context.options.timeout || false;
1003
- if (context.options.retry !== false && !isAbort) {
1004
- let retries;
1005
- if (typeof context.options.retry === "number") {
1006
- retries = context.options.retry;
1007
- } else {
1008
- retries = isPayloadMethod(context.options.method) ? 0 : 1;
1009
- }
1010
- const responseCode = context.response && context.response.status || 500;
1011
- if (retries > 0 && (Array.isArray(context.options.retryStatusCodes) ? context.options.retryStatusCodes.includes(responseCode) : retryStatusCodes.has(responseCode))) {
1012
- const retryDelay = typeof context.options.retryDelay === "function" ? context.options.retryDelay(context) : context.options.retryDelay || 0;
1013
- if (retryDelay > 0) {
1014
- await new Promise((resolve) => setTimeout(resolve, retryDelay));
1015
- }
1016
- return $fetchRaw(context.request, {
1017
- ...context.options,
1018
- retry: retries - 1
1019
- });
1020
- }
1021
- }
1022
- const error = createFetchError(context);
1023
- if (Error.captureStackTrace) {
1024
- Error.captureStackTrace(error, $fetchRaw);
1025
- }
1026
- throw error;
1027
- }
1028
- const $fetchRaw = async function $fetchRaw2(_request, _options = {}) {
1029
- const context = {
1030
- request: _request,
1031
- options: resolveFetchOptions(
1032
- _request,
1033
- _options,
1034
- globalOptions.defaults,
1035
- Headers
1036
- ),
1037
- response: void 0,
1038
- error: void 0
1039
- };
1040
- if (context.options.method) {
1041
- context.options.method = context.options.method.toUpperCase();
1042
- }
1043
- if (context.options.onRequest) {
1044
- await callHooks(context, context.options.onRequest);
1045
- if (!(context.options.headers instanceof Headers)) {
1046
- context.options.headers = new Headers(
1047
- context.options.headers || {}
1048
- /* compat */
1049
- );
1050
- }
1051
- }
1052
- if (typeof context.request === "string") {
1053
- if (context.options.baseURL) {
1054
- context.request = withBase(context.request, context.options.baseURL);
1055
- }
1056
- if (context.options.query) {
1057
- context.request = withQuery(context.request, context.options.query);
1058
- delete context.options.query;
1059
- }
1060
- if ("query" in context.options) {
1061
- delete context.options.query;
1062
- }
1063
- if ("params" in context.options) {
1064
- delete context.options.params;
1065
- }
1066
- }
1067
- if (context.options.body && isPayloadMethod(context.options.method)) {
1068
- if (isJSONSerializable(context.options.body)) {
1069
- const contentType = context.options.headers.get("content-type");
1070
- if (typeof context.options.body !== "string") {
1071
- context.options.body = contentType === "application/x-www-form-urlencoded" ? new URLSearchParams(
1072
- context.options.body
1073
- ).toString() : JSON.stringify(context.options.body);
1074
- }
1075
- if (!contentType) {
1076
- context.options.headers.set("content-type", "application/json");
1077
- }
1078
- if (!context.options.headers.has("accept")) {
1079
- context.options.headers.set("accept", "application/json");
1080
- }
1081
- } else if (
1082
- // ReadableStream Body
1083
- "pipeTo" in context.options.body && typeof context.options.body.pipeTo === "function" || // Node.js Stream Body
1084
- typeof context.options.body.pipe === "function"
1085
- ) {
1086
- if (!("duplex" in context.options)) {
1087
- context.options.duplex = "half";
1088
- }
1089
- }
1090
- }
1091
- let abortTimeout;
1092
- if (!context.options.signal && context.options.timeout) {
1093
- const controller = new AbortController();
1094
- abortTimeout = setTimeout(() => {
1095
- const error = new Error(
1096
- "[TimeoutError]: The operation was aborted due to timeout"
1097
- );
1098
- error.name = "TimeoutError";
1099
- error.code = 23;
1100
- controller.abort(error);
1101
- }, context.options.timeout);
1102
- context.options.signal = controller.signal;
1103
- }
1104
- try {
1105
- context.response = await fetch(
1106
- context.request,
1107
- context.options
1108
- );
1109
- } catch (error) {
1110
- context.error = error;
1111
- if (context.options.onRequestError) {
1112
- await callHooks(
1113
- context,
1114
- context.options.onRequestError
1115
- );
1116
- }
1117
- return await onError(context);
1118
- } finally {
1119
- if (abortTimeout) {
1120
- clearTimeout(abortTimeout);
1121
- }
1122
- }
1123
- const hasBody = (context.response.body || // https://github.com/unjs/ofetch/issues/324
1124
- // https://github.com/unjs/ofetch/issues/294
1125
- // https://github.com/JakeChampion/fetch/issues/1454
1126
- context.response._bodyInit) && !nullBodyResponses.has(context.response.status) && context.options.method !== "HEAD";
1127
- if (hasBody) {
1128
- const responseType = (context.options.parseResponse ? "json" : context.options.responseType) || detectResponseType(context.response.headers.get("content-type") || "");
1129
- switch (responseType) {
1130
- case "json": {
1131
- const data = await context.response.text();
1132
- const parseFunction = context.options.parseResponse || destr;
1133
- context.response._data = parseFunction(data);
1134
- break;
1135
- }
1136
- case "stream": {
1137
- context.response._data = context.response.body || context.response._bodyInit;
1138
- break;
1139
- }
1140
- default: {
1141
- context.response._data = await context.response[responseType]();
1142
- }
1143
- }
1144
- }
1145
- if (context.options.onResponse) {
1146
- await callHooks(
1147
- context,
1148
- context.options.onResponse
1149
- );
1150
- }
1151
- if (!context.options.ignoreResponseError && context.response.status >= 400 && context.response.status < 600) {
1152
- if (context.options.onResponseError) {
1153
- await callHooks(
1154
- context,
1155
- context.options.onResponseError
1156
- );
1157
- }
1158
- return await onError(context);
1159
- }
1160
- return context.response;
1161
- };
1162
- const $fetch = async function $fetch2(request, options) {
1163
- const r = await $fetchRaw(request, options);
1164
- return r._data;
1165
- };
1166
- $fetch.raw = $fetchRaw;
1167
- $fetch.native = (...args) => fetch(...args);
1168
- $fetch.create = (defaultOptions = {}, customGlobalOptions = {}) => createFetch({
1169
- ...globalOptions,
1170
- ...customGlobalOptions,
1171
- defaults: {
1172
- ...globalOptions.defaults,
1173
- ...customGlobalOptions.defaults,
1174
- ...defaultOptions
1175
- }
1176
- });
1177
- return $fetch;
1178
- }
1179
-
1180
- const _globalThis = (function() {
1181
- if (typeof globalThis !== "undefined") {
1182
- return globalThis;
1183
- }
1184
- if (typeof self !== "undefined") {
1185
- return self;
1186
- }
1187
- if (typeof window !== "undefined") {
1188
- return window;
1189
- }
1190
- if (typeof global !== "undefined") {
1191
- return global;
1192
- }
1193
- throw new Error("unable to locate global object");
1194
- })();
1195
- const fetch = _globalThis.fetch ? (...args) => _globalThis.fetch(...args) : () => Promise.reject(new Error("[ofetch] global.fetch is not supported!"));
1196
- const Headers = _globalThis.Headers;
1197
- const AbortController = _globalThis.AbortController;
1198
- const ofetch = createFetch({ fetch, Headers, AbortController });
1199
-
1200
- class TemplatesClient {
1201
- fetch;
1202
- baseURL;
1203
- language;
1204
- logger = consola.withTag("templates-client");
1205
- constructor(config = {}) {
1206
- this.baseURL = config.baseURL || "https://api.claudehome.cn";
1207
- this.language = config.language || "en";
1208
- this.fetch = ofetch.create({
1209
- baseURL: this.baseURL,
1210
- timeout: config.timeout || 1e4,
1211
- headers: {
1212
- "User-Agent": "CCJK/8.2.0"
1213
- },
1214
- retry: 2
1215
- });
1216
- }
1217
- // ==========================================================================
1218
- // Single Template
1219
- // ==========================================================================
1220
- /**
1221
- * Get a single template by ID
1222
- */
1223
- async getTemplate(templateId) {
1224
- try {
1225
- this.logger.debug(`Fetching template: ${templateId}`);
1226
- const response = await this.fetch(
1227
- `/api/v8/templates/${encodeURIComponent(templateId)}`
1228
- );
1229
- if (response.code === 200 && response.data) {
1230
- return response.data;
1231
- }
1232
- return null;
1233
- } catch (error) {
1234
- this.logger.warn(`Failed to fetch template ${templateId}:`, error);
1235
- return null;
1236
- }
1237
- }
1238
- // ==========================================================================
1239
- // Batch Templates
1240
- // ==========================================================================
1241
- /**
1242
- * Batch get templates by IDs
1243
- */
1244
- async getTemplates(ids, language) {
1245
- try {
1246
- this.logger.debug(`Batch fetching ${ids.length} templates`);
1247
- const response = await this.fetch(
1248
- "/api/v8/templates/batch",
1249
- {
1250
- method: "POST",
1251
- body: {
1252
- ids,
1253
- language: language || this.language,
1254
- includeStats: true
1255
- }
1256
- }
1257
- );
1258
- return {
1259
- requestId: response.requestId || "",
1260
- templates: response.templates || {},
1261
- notFound: response.notFound || [],
1262
- stats: response.stats
1263
- };
1264
- } catch (error) {
1265
- this.logger.warn("Failed to batch fetch templates:", error);
1266
- return {
1267
- requestId: "",
1268
- templates: {},
1269
- notFound: ids
1270
- };
1271
- }
1272
- }
1273
- // ==========================================================================
1274
- // Search & List
1275
- // ==========================================================================
1276
- /**
1277
- * Search templates
1278
- */
1279
- async searchTemplates(query, params = {}) {
1280
- try {
1281
- this.logger.debug(`Searching templates: ${query}`);
1282
- const searchParams = this.buildSearchParams({ ...params, query });
1283
- const response = await this.fetch(
1284
- `/api/v8/templates/search?${searchParams}`
1285
- );
1286
- if (response.code === 200 && response.data) {
1287
- return response.data;
1288
- }
1289
- return { items: [], total: 0, limit: 20, offset: 0 };
1290
- } catch (error) {
1291
- this.logger.warn("Failed to search templates:", error);
1292
- return { items: [], total: 0, limit: 20, offset: 0 };
1293
- }
1294
- }
1295
- /**
1296
- * List templates with filters
1297
- */
1298
- async listTemplates(params = {}) {
1299
- try {
1300
- this.logger.debug("Listing templates with params:", params);
1301
- const searchParams = this.buildSearchParams(params);
1302
- const response = await this.fetch(
1303
- `/api/v8/templates?${searchParams}`
1304
- );
1305
- if (response.code === 200 && response.data) {
1306
- return response.data;
1307
- }
1308
- return { items: [], total: 0, limit: 20, offset: 0 };
1309
- } catch (error) {
1310
- this.logger.warn("Failed to list templates:", error);
1311
- return { items: [], total: 0, limit: 20, offset: 0 };
1312
- }
1313
- }
1314
- // ==========================================================================
1315
- // Type-specific Methods
1316
- // ==========================================================================
1317
- /**
1318
- * Get templates by type
1319
- */
1320
- async getTemplatesByType(type, options = {}) {
1321
- const { items } = await this.listTemplates({
1322
- type,
1323
- category: options.category,
1324
- limit: options.limit || 50,
1325
- is_official: options.is_official
1326
- });
1327
- return items;
1328
- }
1329
- /**
1330
- * Get specialist agents
1331
- */
1332
- async getSpecialistAgents(category) {
1333
- return this.getTemplatesByType("agent", { category, limit: 50 });
1334
- }
1335
- /**
1336
- * Get official MCP servers
1337
- */
1338
- async getOfficialMcpServers() {
1339
- return this.getTemplatesByType("mcp", { is_official: true, limit: 50 });
1340
- }
1341
- /**
1342
- * Get skills by category
1343
- */
1344
- async getSkills(category) {
1345
- return this.getTemplatesByType("skill", { category, limit: 50 });
1346
- }
1347
- /**
1348
- * Get hooks by category
1349
- */
1350
- async getHooks(category) {
1351
- return this.getTemplatesByType("hook", { category, limit: 50 });
1352
- }
1353
- // ==========================================================================
1354
- // Featured & Popular
1355
- // ==========================================================================
1356
- /**
1357
- * Get featured templates
1358
- */
1359
- async getFeaturedTemplates(limit = 10) {
1360
- try {
1361
- const response = await this.fetch(
1362
- `/api/v8/templates/featured?limit=${limit}`
1363
- );
1364
- if (response.code === 200 && response.data) {
1365
- return response.data;
1366
- }
1367
- return [];
1368
- } catch (error) {
1369
- this.logger.warn("Failed to fetch featured templates:", error);
1370
- return [];
1371
- }
1372
- }
1373
- /**
1374
- * Get popular templates
1375
- */
1376
- async getPopularTemplates(limit = 20) {
1377
- try {
1378
- const response = await this.fetch(
1379
- `/api/v8/templates/popular?limit=${limit}`
1380
- );
1381
- if (response.code === 200 && response.data) {
1382
- return response.data;
1383
- }
1384
- return [];
1385
- } catch (error) {
1386
- this.logger.warn("Failed to fetch popular templates:", error);
1387
- return [];
1388
- }
1389
- }
1390
- // ==========================================================================
1391
- // Categories
1392
- // ==========================================================================
1393
- /**
1394
- * Get all categories
1395
- */
1396
- async getCategories() {
1397
- try {
1398
- const response = await this.fetch(
1399
- "/api/v8/templates/categories"
1400
- );
1401
- if (response.code === 200 && response.data) {
1402
- return response.data;
1403
- }
1404
- return [];
1405
- } catch (error) {
1406
- this.logger.warn("Failed to fetch categories:", error);
1407
- return [];
1408
- }
1409
- }
1410
- // ==========================================================================
1411
- // Download Tracking
1412
- // ==========================================================================
1413
- /**
1414
- * Track template download
1415
- */
1416
- async trackDownload(templateId) {
1417
- try {
1418
- const response = await this.fetch(
1419
- `/api/v8/templates/${encodeURIComponent(templateId)}/download`,
1420
- { method: "POST" }
1421
- );
1422
- return response.code === 200;
1423
- } catch (error) {
1424
- this.logger.warn(`Failed to track download for ${templateId}:`, error);
1425
- return false;
1426
- }
1427
- }
1428
- // ==========================================================================
1429
- // Helpers
1430
- // ==========================================================================
1431
- /**
1432
- * Build search params string
1433
- */
1434
- buildSearchParams(params) {
1435
- const searchParams = new URLSearchParams();
1436
- if (params.query)
1437
- searchParams.set("query", params.query);
1438
- if (params.type)
1439
- searchParams.set("type", params.type);
1440
- if (params.category)
1441
- searchParams.set("category", params.category);
1442
- if (params.tags?.length)
1443
- searchParams.set("tags", params.tags.join(","));
1444
- if (params.is_official !== void 0)
1445
- searchParams.set("is_official", String(params.is_official));
1446
- if (params.is_featured !== void 0)
1447
- searchParams.set("is_featured", String(params.is_featured));
1448
- if (params.is_verified !== void 0)
1449
- searchParams.set("is_verified", String(params.is_verified));
1450
- if (params.sortBy)
1451
- searchParams.set("sortBy", params.sortBy);
1452
- if (params.order)
1453
- searchParams.set("order", params.order);
1454
- if (params.limit)
1455
- searchParams.set("limit", String(params.limit));
1456
- if (params.offset)
1457
- searchParams.set("offset", String(params.offset));
1458
- return searchParams.toString();
1459
- }
1460
- /**
1461
- * Extract localized name from template
1462
- */
1463
- getLocalizedName(template, lang) {
1464
- const language = lang || this.language;
1465
- return language === "zh-CN" && template.name_zh_cn ? template.name_zh_cn : template.name_en;
1466
- }
1467
- /**
1468
- * Extract localized description from template
1469
- */
1470
- getLocalizedDescription(template, lang) {
1471
- const language = lang || this.language;
1472
- return language === "zh-CN" && template.description_zh_cn ? template.description_zh_cn : template.description_en || "";
1473
- }
1474
- }
1475
- let templatesClientInstance = null;
1476
- function getTemplatesClient(config) {
1477
- if (!templatesClientInstance) {
1478
- templatesClientInstance = new TemplatesClient(config);
1479
- }
1480
- return templatesClientInstance;
1481
- }
1482
- function createTemplatesClient(config) {
1483
- return new TemplatesClient(config);
1484
- }
1485
-
1486
- export { TemplatesClient as T, createTemplatesClient as a, consola as c, getTemplatesClient as g, ofetch as o };