@cloudbase/cli 2.10.1-beta.0 → 2.11.0

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 (593) hide show
  1. package/bin/ccr +2 -0
  2. package/bin/cloudbase +2 -0
  3. package/bin/cloudbase-mcp +2 -0
  4. package/bin/tcb +2 -0
  5. package/dist/standalone/cli.js +235287 -162247
  6. package/package.json +15 -132
  7. package/.augment-guidelines +0 -119
  8. package/.claude/settings.local.json +0 -6
  9. package/.clinerules/cloudbase-rules.mdc +0 -119
  10. package/.cursor/rules/cloudbase-rules.mdc +0 -119
  11. package/.editorconfig +0 -10
  12. package/.eslintignore +0 -8
  13. package/.eslintrc +0 -35
  14. package/.mcp.json +0 -11
  15. package/.prettierignore +0 -1
  16. package/.prettierrc.js +0 -29
  17. package/.vscode/launch.json +0 -26
  18. package/.yarnrc.yml +0 -1
  19. package/CLAUDE.md +0 -119
  20. package/LICENSE +0 -6
  21. package/bin/ccr.js +0 -3
  22. package/bin/cloudbase.js +0 -7
  23. package/bin/tcb.js +0 -339
  24. package/changelog.md +0 -6
  25. package/cloudbase-cli-2.7.8.tgz +0 -0
  26. package/cloudbaserc.json +0 -13
  27. package/jest.config.js +0 -17
  28. package/lib/auth/index.js +0 -18
  29. package/lib/auth/login.js +0 -111
  30. package/lib/auth/logout.js +0 -20
  31. package/lib/commands/account/index.js +0 -18
  32. package/lib/commands/account/login.js +0 -252
  33. package/lib/commands/account/logout.js +0 -56
  34. package/lib/commands/ai/index.js +0 -200
  35. package/lib/commands/cloudfunction/base.js +0 -369
  36. package/lib/commands/cloudfunction/index.js +0 -17
  37. package/lib/commands/cloudrun/base.js +0 -1040
  38. package/lib/commands/cloudrun/cloudrun-run-ui/index.html +0 -193
  39. package/lib/commands/cloudrun/index.js +0 -17
  40. package/lib/commands/common.js +0 -225
  41. package/lib/commands/config/delete.js +0 -72
  42. package/lib/commands/config/get.js +0 -69
  43. package/lib/commands/config/index.js +0 -21
  44. package/lib/commands/config/interface.js +0 -25
  45. package/lib/commands/config/list.js +0 -72
  46. package/lib/commands/config/set.js +0 -89
  47. package/lib/commands/constants.js +0 -11
  48. package/lib/commands/db/base.js +0 -396
  49. package/lib/commands/db/index.js +0 -17
  50. package/lib/commands/env/base.js +0 -129
  51. package/lib/commands/env/domain.js +0 -222
  52. package/lib/commands/env/index.js +0 -19
  53. package/lib/commands/env/login.js +0 -271
  54. package/lib/commands/framework/index.js +0 -196
  55. package/lib/commands/fun/base.js +0 -434
  56. package/lib/commands/fun/index.js +0 -17
  57. package/lib/commands/functions/alias/getRoute.js +0 -99
  58. package/lib/commands/functions/alias/index.js +0 -18
  59. package/lib/commands/functions/alias/setRoute.js +0 -101
  60. package/lib/commands/functions/code-download.js +0 -123
  61. package/lib/commands/functions/code-update.js +0 -96
  62. package/lib/commands/functions/concurrency/delete.js +0 -71
  63. package/lib/commands/functions/concurrency/index.js +0 -19
  64. package/lib/commands/functions/concurrency/list.js +0 -82
  65. package/lib/commands/functions/concurrency/set.js +0 -73
  66. package/lib/commands/functions/config-update.js +0 -103
  67. package/lib/commands/functions/copy.js +0 -82
  68. package/lib/commands/functions/delete.js +0 -102
  69. package/lib/commands/functions/deploy.js +0 -331
  70. package/lib/commands/functions/detail.js +0 -166
  71. package/lib/commands/functions/index.js +0 -33
  72. package/lib/commands/functions/invoke.js +0 -140
  73. package/lib/commands/functions/layer/bind.js +0 -191
  74. package/lib/commands/functions/layer/common.js +0 -13
  75. package/lib/commands/functions/layer/create.js +0 -88
  76. package/lib/commands/functions/layer/delete.js +0 -92
  77. package/lib/commands/functions/layer/download.js +0 -112
  78. package/lib/commands/functions/layer/index.js +0 -23
  79. package/lib/commands/functions/layer/list.js +0 -105
  80. package/lib/commands/functions/layer/sort.js +0 -98
  81. package/lib/commands/functions/list.js +0 -92
  82. package/lib/commands/functions/log.js +0 -156
  83. package/lib/commands/functions/run.js +0 -245
  84. package/lib/commands/functions/trigger-create.js +0 -99
  85. package/lib/commands/functions/trigger-delete.js +0 -121
  86. package/lib/commands/functions/version/index.js +0 -18
  87. package/lib/commands/functions/version/list.js +0 -97
  88. package/lib/commands/functions/version/publish.js +0 -71
  89. package/lib/commands/gateway/create.js +0 -125
  90. package/lib/commands/gateway/delete.js +0 -111
  91. package/lib/commands/gateway/domain.js +0 -202
  92. package/lib/commands/gateway/index.js +0 -21
  93. package/lib/commands/gateway/list.js +0 -107
  94. package/lib/commands/gateway/switch.js +0 -144
  95. package/lib/commands/helpers/index.js +0 -19
  96. package/lib/commands/helpers/init.js +0 -395
  97. package/lib/commands/helpers/new.js +0 -130
  98. package/lib/commands/helpers/open.js +0 -90
  99. package/lib/commands/hosting/hosting.js +0 -378
  100. package/lib/commands/hosting/index.js +0 -17
  101. package/lib/commands/index.js +0 -38
  102. package/lib/commands/lowcode/app.js +0 -415
  103. package/lib/commands/lowcode/comps.js +0 -373
  104. package/lib/commands/lowcode/index.js +0 -18
  105. package/lib/commands/lowcode/utils.js +0 -83
  106. package/lib/commands/pull/index.js +0 -17
  107. package/lib/commands/pull/pull.js +0 -107
  108. package/lib/commands/run/delete.js +0 -102
  109. package/lib/commands/run/image/common.js +0 -13
  110. package/lib/commands/run/image/delete.js +0 -91
  111. package/lib/commands/run/image/download.js +0 -86
  112. package/lib/commands/run/image/index.js +0 -21
  113. package/lib/commands/run/image/list.js +0 -104
  114. package/lib/commands/run/image/upload.js +0 -114
  115. package/lib/commands/run/index.js +0 -21
  116. package/lib/commands/run/list.js +0 -104
  117. package/lib/commands/run/service/config.js +0 -113
  118. package/lib/commands/run/service/deploy.js +0 -155
  119. package/lib/commands/run/service/index.js +0 -20
  120. package/lib/commands/run/service/list.js +0 -116
  121. package/lib/commands/run/service/update.js +0 -141
  122. package/lib/commands/run/standalonegateway/common.js +0 -13
  123. package/lib/commands/run/standalonegateway/create.js +0 -106
  124. package/lib/commands/run/standalonegateway/destroy.js +0 -82
  125. package/lib/commands/run/standalonegateway/index.js +0 -21
  126. package/lib/commands/run/standalonegateway/list.js +0 -78
  127. package/lib/commands/run/standalonegateway/package.js +0 -87
  128. package/lib/commands/run/standalonegateway/turn.js +0 -87
  129. package/lib/commands/run/version/common.js +0 -13
  130. package/lib/commands/run/version/create.js +0 -329
  131. package/lib/commands/run/version/delete.js +0 -90
  132. package/lib/commands/run/version/index.js +0 -21
  133. package/lib/commands/run/version/list.js +0 -109
  134. package/lib/commands/run/version/modify.js +0 -142
  135. package/lib/commands/run/version/update.js +0 -353
  136. package/lib/commands/runf/base.js +0 -453
  137. package/lib/commands/runf/index.js +0 -17
  138. package/lib/commands/self-update.js +0 -134
  139. package/lib/commands/smart.js +0 -124
  140. package/lib/commands/storage/index.js +0 -17
  141. package/lib/commands/storage/storage.js +0 -515
  142. package/lib/commands/third/index.js +0 -17
  143. package/lib/commands/third/thirdAttach.js +0 -78
  144. package/lib/commands/utils.js +0 -197
  145. package/lib/completion/index.js +0 -15
  146. package/lib/constant.js +0 -142
  147. package/lib/db/index.js +0 -85
  148. package/lib/decorators/captureError.js +0 -30
  149. package/lib/decorators/constants.js +0 -15
  150. package/lib/decorators/deprecate.js +0 -18
  151. package/lib/decorators/guard.js +0 -35
  152. package/lib/decorators/index.js +0 -25
  153. package/lib/decorators/injectParams.js +0 -58
  154. package/lib/decorators/params/common.js +0 -16
  155. package/lib/decorators/params/index.js +0 -34
  156. package/lib/env/domain.js +0 -42
  157. package/lib/env/index.js +0 -80
  158. package/lib/env/login.js +0 -78
  159. package/lib/error.js +0 -17
  160. package/lib/function/alias.js +0 -54
  161. package/lib/function/base.js +0 -266
  162. package/lib/function/code.js +0 -28
  163. package/lib/function/concurrency.js +0 -70
  164. package/lib/function/create.js +0 -72
  165. package/lib/function/delete.js +0 -53
  166. package/lib/function/index.js +0 -27
  167. package/lib/function/layer/attach.js +0 -63
  168. package/lib/function/layer/create.js +0 -63
  169. package/lib/function/layer/delete.js +0 -24
  170. package/lib/function/layer/download.js +0 -37
  171. package/lib/function/layer/index.js +0 -23
  172. package/lib/function/layer/list.js +0 -36
  173. package/lib/function/layer/sort.js +0 -25
  174. package/lib/function/trigger.js +0 -106
  175. package/lib/function/update.js +0 -41
  176. package/lib/function/version.js +0 -52
  177. package/lib/function/vpc.js +0 -35
  178. package/lib/gateway/index.js +0 -136
  179. package/lib/help.js +0 -44
  180. package/lib/hosting.js +0 -244
  181. package/lib/i18n/index.js +0 -73
  182. package/lib/index.js +0 -13
  183. package/lib/logger.js +0 -19
  184. package/lib/run/delete.js +0 -22
  185. package/lib/run/image/build.js +0 -37
  186. package/lib/run/image/delete.js +0 -22
  187. package/lib/run/image/index.js +0 -20
  188. package/lib/run/image/info.js +0 -29
  189. package/lib/run/image/list.js +0 -30
  190. package/lib/run/index.js +0 -23
  191. package/lib/run/list.js +0 -39
  192. package/lib/run/repo.js +0 -31
  193. package/lib/run/service/common.js +0 -271
  194. package/lib/run/service/config.js +0 -70
  195. package/lib/run/service/deployPackage.js +0 -83
  196. package/lib/run/service/index.js +0 -22
  197. package/lib/run/service/list.js +0 -31
  198. package/lib/run/service/showLogs.js +0 -117
  199. package/lib/run/service/update.js +0 -84
  200. package/lib/run/standalonegateway/create.js +0 -32
  201. package/lib/run/standalonegateway/destroy.js +0 -28
  202. package/lib/run/standalonegateway/index.js +0 -21
  203. package/lib/run/standalonegateway/list.js +0 -48
  204. package/lib/run/standalonegateway/package/index.js +0 -17
  205. package/lib/run/standalonegateway/package/list.js +0 -32
  206. package/lib/run/standalonegateway/turn/index.js +0 -18
  207. package/lib/run/standalonegateway/turn/off.js +0 -28
  208. package/lib/run/standalonegateway/turn/on.js +0 -28
  209. package/lib/run/version/create.js +0 -50
  210. package/lib/run/version/delete.js +0 -23
  211. package/lib/run/version/index.js +0 -22
  212. package/lib/run/version/list.js +0 -24
  213. package/lib/run/version/modify.js +0 -24
  214. package/lib/run/version/repo.js +0 -33
  215. package/lib/run/version/update.js +0 -39
  216. package/lib/storage.js +0 -125
  217. package/lib/third/index.js +0 -25
  218. package/lib/types.js +0 -12
  219. package/lib/utils/ai/banner.js +0 -102
  220. package/lib/utils/ai/claudeWindows.js +0 -64
  221. package/lib/utils/ai/config.js +0 -290
  222. package/lib/utils/ai/const.js +0 -178
  223. package/lib/utils/ai/ensureFiles.js +0 -27
  224. package/lib/utils/ai/env.js +0 -37
  225. package/lib/utils/ai/envLocalManager.js +0 -145
  226. package/lib/utils/ai/nodeVersion.js +0 -19
  227. package/lib/utils/ai/router.js +0 -1306
  228. package/lib/utils/ai/setup.js +0 -707
  229. package/lib/utils/auth.js +0 -28
  230. package/lib/utils/checkTcbrEnv.js +0 -76
  231. package/lib/utils/cli-table.js +0 -19
  232. package/lib/utils/commonParamsCheck.js +0 -49
  233. package/lib/utils/config.js +0 -59
  234. package/lib/utils/debug-logger.js +0 -31
  235. package/lib/utils/dts.js +0 -154
  236. package/lib/utils/env.js +0 -222
  237. package/lib/utils/fs/del.js +0 -11
  238. package/lib/utils/fs/index.js +0 -94
  239. package/lib/utils/function-packer.js +0 -87
  240. package/lib/utils/index.js +0 -38
  241. package/lib/utils/log.js +0 -85
  242. package/lib/utils/mcp-config-modifier.js +0 -235
  243. package/lib/utils/net/cloud-api-request.js +0 -64
  244. package/lib/utils/net/credential.js +0 -61
  245. package/lib/utils/net/http-request.js +0 -108
  246. package/lib/utils/net/index.js +0 -21
  247. package/lib/utils/net/manager-service.js +0 -51
  248. package/lib/utils/net/proxy.js +0 -9
  249. package/lib/utils/notice.js +0 -37
  250. package/lib/utils/output/highlight.js +0 -11
  251. package/lib/utils/output/index.js +0 -19
  252. package/lib/utils/output/link.js +0 -16
  253. package/lib/utils/output/loading.js +0 -68
  254. package/lib/utils/parallel.js +0 -65
  255. package/lib/utils/platform/index.js +0 -19
  256. package/lib/utils/platform/mac.js +0 -37
  257. package/lib/utils/platform/os.js +0 -59
  258. package/lib/utils/platform/port.js +0 -26
  259. package/lib/utils/progress-bar.js +0 -44
  260. package/lib/utils/prompt/index.js +0 -17
  261. package/lib/utils/prompt/select.js +0 -54
  262. package/lib/utils/report.js +0 -78
  263. package/lib/utils/reporter/agree.js +0 -31
  264. package/lib/utils/reporter/download.js +0 -37
  265. package/lib/utils/reporter/index.js +0 -19
  266. package/lib/utils/reporter/usage.js +0 -32
  267. package/lib/utils/store/auth.js +0 -59
  268. package/lib/utils/store/common.js +0 -8
  269. package/lib/utils/store/config.js +0 -49
  270. package/lib/utils/store/db.js +0 -84
  271. package/lib/utils/store/index.js +0 -21
  272. package/lib/utils/store/usage.js +0 -9
  273. package/lib/utils/tcbrApi/callTcbrApi.js +0 -39
  274. package/lib/utils/tcbrApi/index.js +0 -17
  275. package/lib/utils/template-manager.js +0 -458
  276. package/lib/utils/template.js +0 -131
  277. package/lib/utils/tools/common.js +0 -74
  278. package/lib/utils/tools/encoding.js +0 -13
  279. package/lib/utils/tools/index.js +0 -20
  280. package/lib/utils/tools/object.js +0 -28
  281. package/lib/utils/tools/time.js +0 -49
  282. package/lib/utils/tools/uid.js +0 -25
  283. package/lib/utils/url.js +0 -19
  284. package/lib/utils/validator.js +0 -72
  285. package/locales/README.md +0 -160
  286. package/locales/i18next-scanner.config.js +0 -206
  287. package/locales/index.js +0 -5
  288. package/locales/langs/en.json +0 -1235
  289. package/locales/langs/zh.json +0 -1235
  290. package/locales/mapping.json +0 -1235
  291. package/patches/@musistudio+claude-code-router+1.0.36.patch +0 -40
  292. package/post-install.js +0 -63
  293. package/rules/cloudbase-platform.mdc +0 -44
  294. package/rules/database.mdc +0 -25
  295. package/rules/miniprogram-development.mdc +0 -61
  296. package/rules/ui-design.mdc +0 -24
  297. package/rules/web-development.mdc +0 -44
  298. package/rules/workflows.mdc +0 -30
  299. package/runtime/nodejs/bootstrap.js +0 -255
  300. package/runtime/nodejs/runtime.js +0 -183
  301. package/specs/ai-cli-bootstrap/QWEN.md +0 -196
  302. package/specs/ai-cli-bootstrap/design.md +0 -185
  303. package/specs/ai-cli-bootstrap/requirements.md +0 -51
  304. package/specs/ai-cli-bootstrap/tasks.md +0 -70
  305. package/specs/ai-cli-bootstrap/technical-docs.md +0 -421
  306. package/specs/cli-install-upgrade/design.md +0 -207
  307. package/specs/cli-install-upgrade/requirements.md +0 -315
  308. package/specs/cli-install-upgrade/tasks.md +0 -120
  309. package/specs/codebuddy-integration/design.md +0 -152
  310. package/specs/codebuddy-integration/requirements.md +0 -85
  311. package/specs/codebuddy-integration/tasks.md +0 -159
  312. package/specs/mcp-global-bin/design.md +0 -57
  313. package/specs/mcp-global-bin/requirements.md +0 -43
  314. package/specs/mcp-global-bin/tasks.md +0 -54
  315. package/specs/ssl-fix/design.md +0 -93
  316. package/specs/ssl-fix/requirements.md +0 -47
  317. package/specs/ssl-fix/tasks.md +0 -65
  318. package/specs/tcb-pull-cnb-support/design.md +0 -137
  319. package/specs/tcb-pull-cnb-support/requirements.md +0 -56
  320. package/specs/tcb-pull-cnb-support/tasks.md +0 -101
  321. package/specs/tcb-pull-mcp-integration/design.md +0 -153
  322. package/specs/tcb-pull-mcp-integration/implementation-summary.md +0 -127
  323. package/specs/tcb-pull-mcp-integration/requirements.md +0 -68
  324. package/specs/tcb-pull-mcp-integration/tasks.md +0 -125
  325. package/specs/template-pull-command/design.md +0 -135
  326. package/specs/template-pull-command/implementation-summary.md +0 -160
  327. package/specs/template-pull-command/requirements.md +0 -73
  328. package/specs/template-pull-command/tasks.md +0 -101
  329. package/templates/html/loginFail.html +0 -90
  330. package/templates/html/loginSuccess.html +0 -86
  331. package/templates/server/node/_gitignore +0 -54
  332. package/templates/server/node/cloudbaserc.json +0 -10
  333. package/templates/server/node/index.js +0 -6
  334. package/templates/server/node/package.json +0 -9
  335. package/test-mcp-integration.js +0 -68
  336. package/tsconfig.json +0 -20
  337. package/tsconfig.test.json +0 -13
  338. package/types/auth/index.d.ts +0 -2
  339. package/types/auth/login.d.ts +0 -25
  340. package/types/auth/logout.d.ts +0 -1
  341. package/types/commands/account/index.d.ts +0 -2
  342. package/types/commands/account/login.d.ts +0 -15
  343. package/types/commands/account/logout.d.ts +0 -12
  344. package/types/commands/ai/index.d.ts +0 -23
  345. package/types/commands/cloudfunction/base.d.ts +0 -43
  346. package/types/commands/cloudfunction/index.d.ts +0 -1
  347. package/types/commands/cloudrun/base.d.ts +0 -160
  348. package/types/commands/cloudrun/index.d.ts +0 -1
  349. package/types/commands/common.d.ts +0 -38
  350. package/types/commands/config/delete.d.ts +0 -13
  351. package/types/commands/config/get.d.ts +0 -13
  352. package/types/commands/config/index.d.ts +0 -5
  353. package/types/commands/config/interface.d.ts +0 -17
  354. package/types/commands/config/list.d.ts +0 -13
  355. package/types/commands/config/set.d.ts +0 -13
  356. package/types/commands/constants.d.ts +0 -8
  357. package/types/commands/db/base.d.ts +0 -44
  358. package/types/commands/db/index.d.ts +0 -1
  359. package/types/commands/env/base.d.ts +0 -27
  360. package/types/commands/env/domain.d.ts +0 -53
  361. package/types/commands/env/index.d.ts +0 -3
  362. package/types/commands/env/login.d.ts +0 -47
  363. package/types/commands/framework/index.d.ts +0 -42
  364. package/types/commands/fun/base.d.ts +0 -43
  365. package/types/commands/fun/index.d.ts +0 -1
  366. package/types/commands/functions/alias/getRoute.d.ts +0 -13
  367. package/types/commands/functions/alias/index.d.ts +0 -2
  368. package/types/commands/functions/alias/setRoute.d.ts +0 -13
  369. package/types/commands/functions/code-download.d.ts +0 -18
  370. package/types/commands/functions/code-update.d.ts +0 -18
  371. package/types/commands/functions/concurrency/delete.d.ts +0 -13
  372. package/types/commands/functions/concurrency/index.d.ts +0 -3
  373. package/types/commands/functions/concurrency/list.d.ts +0 -13
  374. package/types/commands/functions/concurrency/set.d.ts +0 -13
  375. package/types/commands/functions/config-update.d.ts +0 -19
  376. package/types/commands/functions/copy.d.ts +0 -15
  377. package/types/commands/functions/delete.d.ts +0 -14
  378. package/types/commands/functions/deploy.d.ts +0 -22
  379. package/types/commands/functions/detail.d.ts +0 -16
  380. package/types/commands/functions/index.d.ts +0 -17
  381. package/types/commands/functions/invoke.d.ts +0 -15
  382. package/types/commands/functions/layer/bind.d.ts +0 -35
  383. package/types/commands/functions/layer/common.d.ts +0 -8
  384. package/types/commands/functions/layer/create.d.ts +0 -18
  385. package/types/commands/functions/layer/delete.d.ts +0 -18
  386. package/types/commands/functions/layer/download.d.ts +0 -18
  387. package/types/commands/functions/layer/index.d.ts +0 -7
  388. package/types/commands/functions/layer/list.d.ts +0 -19
  389. package/types/commands/functions/layer/sort.d.ts +0 -18
  390. package/types/commands/functions/list.d.ts +0 -14
  391. package/types/commands/functions/log.d.ts +0 -15
  392. package/types/commands/functions/run.d.ts +0 -17
  393. package/types/commands/functions/trigger-create.d.ts +0 -18
  394. package/types/commands/functions/trigger-delete.d.ts +0 -18
  395. package/types/commands/functions/version/index.d.ts +0 -2
  396. package/types/commands/functions/version/list.d.ts +0 -13
  397. package/types/commands/functions/version/publish.d.ts +0 -13
  398. package/types/commands/gateway/create.d.ts +0 -14
  399. package/types/commands/gateway/delete.d.ts +0 -14
  400. package/types/commands/gateway/domain.d.ts +0 -47
  401. package/types/commands/gateway/index.d.ts +0 -5
  402. package/types/commands/gateway/list.d.ts +0 -15
  403. package/types/commands/gateway/switch.d.ts +0 -31
  404. package/types/commands/helpers/index.d.ts +0 -3
  405. package/types/commands/helpers/init.d.ts +0 -22
  406. package/types/commands/helpers/new.d.ts +0 -17
  407. package/types/commands/helpers/open.d.ts +0 -11
  408. package/types/commands/hosting/hosting.d.ts +0 -66
  409. package/types/commands/hosting/index.d.ts +0 -1
  410. package/types/commands/index.d.ts +0 -22
  411. package/types/commands/lowcode/app.d.ts +0 -81
  412. package/types/commands/lowcode/comps.d.ts +0 -77
  413. package/types/commands/lowcode/index.d.ts +0 -2
  414. package/types/commands/lowcode/utils.d.ts +0 -9
  415. package/types/commands/pull/index.d.ts +0 -1
  416. package/types/commands/pull/pull.d.ts +0 -16
  417. package/types/commands/run/delete.d.ts +0 -13
  418. package/types/commands/run/image/common.d.ts +0 -8
  419. package/types/commands/run/image/delete.d.ts +0 -17
  420. package/types/commands/run/image/download.d.ts +0 -17
  421. package/types/commands/run/image/index.d.ts +0 -5
  422. package/types/commands/run/image/list.d.ts +0 -17
  423. package/types/commands/run/image/upload.d.ts +0 -17
  424. package/types/commands/run/index.d.ts +0 -5
  425. package/types/commands/run/list.d.ts +0 -13
  426. package/types/commands/run/service/config.d.ts +0 -14
  427. package/types/commands/run/service/deploy.d.ts +0 -13
  428. package/types/commands/run/service/index.d.ts +0 -4
  429. package/types/commands/run/service/list.d.ts +0 -13
  430. package/types/commands/run/service/update.d.ts +0 -13
  431. package/types/commands/run/standalonegateway/common.d.ts +0 -8
  432. package/types/commands/run/standalonegateway/create.d.ts +0 -17
  433. package/types/commands/run/standalonegateway/destroy.d.ts +0 -17
  434. package/types/commands/run/standalonegateway/index.d.ts +0 -5
  435. package/types/commands/run/standalonegateway/list.d.ts +0 -17
  436. package/types/commands/run/standalonegateway/package.d.ts +0 -17
  437. package/types/commands/run/standalonegateway/turn.d.ts +0 -17
  438. package/types/commands/run/version/common.d.ts +0 -8
  439. package/types/commands/run/version/create.d.ts +0 -17
  440. package/types/commands/run/version/delete.d.ts +0 -17
  441. package/types/commands/run/version/index.d.ts +0 -5
  442. package/types/commands/run/version/list.d.ts +0 -17
  443. package/types/commands/run/version/modify.d.ts +0 -17
  444. package/types/commands/run/version/update.d.ts +0 -17
  445. package/types/commands/runf/base.d.ts +0 -43
  446. package/types/commands/runf/index.d.ts +0 -1
  447. package/types/commands/self-update.d.ts +0 -24
  448. package/types/commands/smart.d.ts +0 -1
  449. package/types/commands/storage/index.d.ts +0 -1
  450. package/types/commands/storage/storage.d.ts +0 -106
  451. package/types/commands/third/index.d.ts +0 -1
  452. package/types/commands/third/thirdAttach.d.ts +0 -15
  453. package/types/commands/utils.d.ts +0 -28
  454. package/types/completion/index.d.ts +0 -4
  455. package/types/constant.d.ts +0 -71
  456. package/types/db/index.d.ts +0 -24
  457. package/types/decorators/captureError.d.ts +0 -1
  458. package/types/decorators/constants.d.ts +0 -11
  459. package/types/decorators/deprecate.d.ts +0 -4
  460. package/types/decorators/guard.d.ts +0 -5
  461. package/types/decorators/index.d.ts +0 -7
  462. package/types/decorators/injectParams.d.ts +0 -1
  463. package/types/decorators/params/common.d.ts +0 -4
  464. package/types/decorators/params/index.d.ts +0 -8
  465. package/types/env/domain.d.ts +0 -11
  466. package/types/env/index.d.ts +0 -12
  467. package/types/env/login.d.ts +0 -16
  468. package/types/error.d.ts +0 -20
  469. package/types/function/alias.d.ts +0 -3
  470. package/types/function/base.d.ts +0 -32
  471. package/types/function/code.d.ts +0 -8
  472. package/types/function/concurrency.d.ts +0 -4
  473. package/types/function/create.d.ts +0 -3
  474. package/types/function/delete.d.ts +0 -8
  475. package/types/function/index.d.ts +0 -11
  476. package/types/function/layer/attach.d.ts +0 -9
  477. package/types/function/layer/create.d.ts +0 -8
  478. package/types/function/layer/delete.d.ts +0 -5
  479. package/types/function/layer/download.d.ts +0 -7
  480. package/types/function/layer/index.d.ts +0 -7
  481. package/types/function/layer/list.d.ts +0 -10
  482. package/types/function/layer/sort.d.ts +0 -10
  483. package/types/function/trigger.d.ts +0 -5
  484. package/types/function/update.d.ts +0 -2
  485. package/types/function/version.d.ts +0 -3
  486. package/types/function/vpc.d.ts +0 -2
  487. package/types/gateway/index.d.ts +0 -18
  488. package/types/help.d.ts +0 -1
  489. package/types/hosting.d.ts +0 -35
  490. package/types/i18n/index.d.ts +0 -3
  491. package/types/index.d.ts +0 -4
  492. package/types/logger.d.ts +0 -3
  493. package/types/run/delete.d.ts +0 -2
  494. package/types/run/image/build.d.ts +0 -10
  495. package/types/run/image/delete.d.ts +0 -2
  496. package/types/run/image/index.d.ts +0 -4
  497. package/types/run/image/info.d.ts +0 -1
  498. package/types/run/image/list.d.ts +0 -3
  499. package/types/run/index.d.ts +0 -7
  500. package/types/run/list.d.ts +0 -2
  501. package/types/run/repo.d.ts +0 -5
  502. package/types/run/service/common.d.ts +0 -42
  503. package/types/run/service/config.d.ts +0 -23
  504. package/types/run/service/deployPackage.d.ts +0 -11
  505. package/types/run/service/index.d.ts +0 -6
  506. package/types/run/service/list.d.ts +0 -2
  507. package/types/run/service/showLogs.d.ts +0 -2
  508. package/types/run/service/update.d.ts +0 -3
  509. package/types/run/standalonegateway/create.d.ts +0 -2
  510. package/types/run/standalonegateway/destroy.d.ts +0 -2
  511. package/types/run/standalonegateway/index.d.ts +0 -5
  512. package/types/run/standalonegateway/list.d.ts +0 -2
  513. package/types/run/standalonegateway/package/index.d.ts +0 -1
  514. package/types/run/standalonegateway/package/list.d.ts +0 -2
  515. package/types/run/standalonegateway/turn/index.d.ts +0 -2
  516. package/types/run/standalonegateway/turn/off.d.ts +0 -2
  517. package/types/run/standalonegateway/turn/on.d.ts +0 -2
  518. package/types/run/version/create.d.ts +0 -10
  519. package/types/run/version/delete.d.ts +0 -2
  520. package/types/run/version/index.d.ts +0 -6
  521. package/types/run/version/list.d.ts +0 -2
  522. package/types/run/version/modify.d.ts +0 -2
  523. package/types/run/version/repo.d.ts +0 -10
  524. package/types/run/version/update.d.ts +0 -6
  525. package/types/storage.d.ts +0 -34
  526. package/types/third/index.d.ts +0 -1
  527. package/types/types.d.ts +0 -590
  528. package/types/utils/ai/banner.d.ts +0 -2
  529. package/types/utils/ai/claudeWindows.d.ts +0 -2
  530. package/types/utils/ai/config.d.ts +0 -89
  531. package/types/utils/ai/const.d.ts +0 -401
  532. package/types/utils/ai/ensureFiles.d.ts +0 -1
  533. package/types/utils/ai/env.d.ts +0 -2
  534. package/types/utils/ai/envLocalManager.d.ts +0 -23
  535. package/types/utils/ai/nodeVersion.d.ts +0 -2
  536. package/types/utils/ai/router.d.ts +0 -55
  537. package/types/utils/ai/setup.d.ts +0 -26
  538. package/types/utils/auth.d.ts +0 -3
  539. package/types/utils/checkTcbrEnv.d.ts +0 -3
  540. package/types/utils/cli-table.d.ts +0 -2
  541. package/types/utils/commonParamsCheck.d.ts +0 -3
  542. package/types/utils/config.d.ts +0 -27
  543. package/types/utils/debug-logger.d.ts +0 -1
  544. package/types/utils/dts.d.ts +0 -6
  545. package/types/utils/env.d.ts +0 -5
  546. package/types/utils/fs/del.d.ts +0 -1
  547. package/types/utils/fs/index.d.ts +0 -7
  548. package/types/utils/function-packer.d.ts +0 -18
  549. package/types/utils/index.d.ts +0 -22
  550. package/types/utils/log.d.ts +0 -22
  551. package/types/utils/mcp-config-modifier.d.ts +0 -7
  552. package/types/utils/net/cloud-api-request.d.ts +0 -9
  553. package/types/utils/net/credential.d.ts +0 -5
  554. package/types/utils/net/http-request.d.ts +0 -8
  555. package/types/utils/net/index.d.ts +0 -5
  556. package/types/utils/net/manager-service.d.ts +0 -4
  557. package/types/utils/net/proxy.d.ts +0 -1
  558. package/types/utils/notice.d.ts +0 -1
  559. package/types/utils/output/highlight.d.ts +0 -1
  560. package/types/utils/output/index.d.ts +0 -3
  561. package/types/utils/output/link.d.ts +0 -1
  562. package/types/utils/output/loading.d.ts +0 -18
  563. package/types/utils/parallel.d.ts +0 -11
  564. package/types/utils/platform/index.d.ts +0 -3
  565. package/types/utils/platform/mac.d.ts +0 -2
  566. package/types/utils/platform/os.d.ts +0 -2
  567. package/types/utils/platform/port.d.ts +0 -1
  568. package/types/utils/progress-bar.d.ts +0 -1
  569. package/types/utils/prompt/index.d.ts +0 -1
  570. package/types/utils/prompt/select.d.ts +0 -4
  571. package/types/utils/report.d.ts +0 -16
  572. package/types/utils/reporter/agree.d.ts +0 -1
  573. package/types/utils/reporter/download.d.ts +0 -1
  574. package/types/utils/reporter/index.d.ts +0 -3
  575. package/types/utils/reporter/usage.d.ts +0 -1
  576. package/types/utils/store/auth.d.ts +0 -8
  577. package/types/utils/store/common.d.ts +0 -2
  578. package/types/utils/store/config.d.ts +0 -8
  579. package/types/utils/store/db.d.ts +0 -17
  580. package/types/utils/store/index.d.ts +0 -5
  581. package/types/utils/store/usage.d.ts +0 -2
  582. package/types/utils/tcbrApi/callTcbrApi.d.ts +0 -1
  583. package/types/utils/tcbrApi/index.d.ts +0 -1
  584. package/types/utils/template-manager.d.ts +0 -27
  585. package/types/utils/template.d.ts +0 -8
  586. package/types/utils/tools/common.d.ts +0 -1
  587. package/types/utils/tools/encoding.d.ts +0 -1
  588. package/types/utils/tools/index.d.ts +0 -4
  589. package/types/utils/tools/object.d.ts +0 -1
  590. package/types/utils/tools/time.d.ts +0 -2
  591. package/types/utils/tools/uid.d.ts +0 -2
  592. package/types/utils/url.d.ts +0 -18
  593. package/types/utils/validator.d.ts +0 -9
@@ -1,1306 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- var __asyncValues = (this && this.__asyncValues) || function (o) {
35
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
36
- var m = o[Symbol.asyncIterator], i;
37
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
38
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
39
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
40
- };
41
- var __importDefault = (this && this.__importDefault) || function (mod) {
42
- return (mod && mod.__esModule) ? mod : { "default": mod };
43
- };
44
- Object.defineProperty(exports, "__esModule", { value: true });
45
- exports.AICommandRouter = void 0;
46
- const child_process_1 = require("child_process");
47
- const config_1 = require("./config");
48
- const error_1 = require("../../error");
49
- const inquirer_1 = __importDefault(require("inquirer"));
50
- const chalk_1 = __importDefault(require("chalk"));
51
- const output_1 = require("../output");
52
- const i18n_1 = require("../../i18n");
53
- const const_1 = require("./const");
54
- const utils_1 = require("../../commands/utils");
55
- const auth_1 = require("../../auth");
56
- const nodeVersion_1 = require("./nodeVersion");
57
- const claudeWindows_1 = require("./claudeWindows");
58
- const env_1 = require("./env");
59
- const url_1 = require("../url");
60
- const IDE_FILE_MAPPINGS = {
61
- cursor: [
62
- { path: '.cursor/rules/cloudbase-rules.mdc' },
63
- { path: '.cursor/mcp.json', isMcpConfig: true }
64
- ],
65
- windsurf: [{ path: '.windsurf/rules/cloudbase-rules.md' }],
66
- codebuddy: [{ path: '.rules/cloudbase-rules.md' }],
67
- 'claude-code': [{ path: 'CLAUDE.md' }, { path: '.mcp.json', isMcpConfig: true }],
68
- cline: [{ path: '.clinerules/cloudbase-rules.mdc' }],
69
- 'gemini-cli': [
70
- { path: '.gemini/GEMINI.md' },
71
- { path: '.gemini/settings.json', isMcpConfig: true }
72
- ],
73
- opencode: [{ path: '.opencode.json', isMcpConfig: true }],
74
- 'qwen-code': [{ path: '.qwen/QWEN.md' }, { path: '.qwen/settings.json', isMcpConfig: true }],
75
- 'baidu-comate': [
76
- { path: '.comate/rules/cloudbase-rules.mdr' },
77
- { path: '.comate/rules/cloudbaase-rules.mdr' },
78
- { path: '.comate/mcp.json', isMcpConfig: true }
79
- ],
80
- 'openai-codex-cli': [{ path: '.codex/config.toml', isMcpConfig: true }, { path: 'AGENTS.md' }],
81
- 'augment-code': [{ path: '.augment-guidelines' }],
82
- 'github-copilot': [{ path: '.github/copilot-instructions.md' }],
83
- roocode: [
84
- { path: '.roo/rules/cloudbaase-rules.md' },
85
- { path: '.roo/mcp.json', isMcpConfig: true }
86
- ],
87
- 'tongyi-lingma': [{ path: '.lingma/rules/cloudbaase-rules.md' }],
88
- trae: [{ path: '.trae/rules/cloudbase-rules.md' }],
89
- vscode: [{ path: '.vscode/mcp.json', isMcpConfig: true }, { path: '.vscode/settings.json' }],
90
- aider: [{ path: 'mcp.json', isMcpConfig: true }]
91
- };
92
- const MCP_CONFIG_SET = new Set(Object.values(IDE_FILE_MAPPINGS).reduce((acc, descriptors) => {
93
- for (const d of descriptors) {
94
- if (d.isMcpConfig)
95
- acc.push(d.path);
96
- }
97
- return acc;
98
- }, []));
99
- function inferConfigFormat(filePath) {
100
- return filePath.toLowerCase().endsWith('.toml') ? 'toml' : 'json';
101
- }
102
- class AICommandRouter {
103
- constructor() {
104
- this.configManager = new config_1.AIConfigManager();
105
- }
106
- execute({ agent, addtionalArgs, log, template, useDefaultConfig }) {
107
- var _a;
108
- return __awaiter(this, void 0, void 0, function* () {
109
- if ((0, config_1.isValidAgent)(agent) !== true) {
110
- log.error((0, i18n_1.t)('❌ 无效的 agent: {{agent}}', { agent }));
111
- return;
112
- }
113
- const config = yield this.configManager.loadConfig();
114
- if (!config) {
115
- log.warn((0, i18n_1.t)("⚠️ 未检测到 AI ToolKit CLI 配置,请运行 'tcb ai --setup' 进行配置"));
116
- return;
117
- }
118
- const agentUpperCased = agent.toUpperCase();
119
- const agentConfig = (_a = config.agents) === null || _a === void 0 ? void 0 : _a[agent];
120
- if (!agentConfig) {
121
- log.warn((0, i18n_1.t)('⚠️ 未找到 {{agent}} 配置,请运行 tcb ai --setup 进行配置', { agent: agentUpperCased }));
122
- return;
123
- }
124
- log.info((0, i18n_1.t)('🚀 启动 {{agent}} AI CLI 工具', { agent: chalk_1.default.bold(agentUpperCased) }));
125
- try {
126
- yield this.checkToolkitConfig({ agent, log, template, useDefaultConfig });
127
- }
128
- catch (e) {
129
- log.warn((0, i18n_1.t)('⚠️ 云开发功能检查失败,但 AI 工具仍可正常使用'));
130
- }
131
- const isValid = yield this.validateAgentConfig(agent, agentConfig, log);
132
- if (!isValid) {
133
- log.warn((0, i18n_1.t)('⚠️ {{agent}} 配置无效,请重新配置', { agent: agent.toUpperCase() }));
134
- return;
135
- }
136
- this.executeAgentWithConfig(agent, agentConfig, this.parseArgs(addtionalArgs), log);
137
- });
138
- }
139
- checkToolkitConfig(checkOptions) {
140
- return __awaiter(this, void 0, void 0, function* () {
141
- const { agent, log, template, useDefaultConfig } = checkOptions;
142
- const { missingFiles } = yield this.configManager.checkToolkitConfig(agent);
143
- if (missingFiles.length > 0) {
144
- const skipTemplate = yield this.checkSkipTemplateConfig();
145
- if (skipTemplate) {
146
- log.info((0, i18n_1.t)('🚫 已跳过模板下载,无法使用云开发 MCP 及 AI 规则。如需使用,请参考 tcb pull --help'));
147
- return;
148
- }
149
- log.log('');
150
- yield this.downloadTemplate({ log, template, agent, useDefaultConfig });
151
- log.log('');
152
- }
153
- });
154
- }
155
- checkSkipTemplateConfig() {
156
- return __awaiter(this, void 0, void 0, function* () {
157
- try {
158
- const fs = yield Promise.resolve().then(() => __importStar(require('fs-extra')));
159
- const path = yield Promise.resolve().then(() => __importStar(require('path')));
160
- const skipFile = path.join(process.cwd(), '.skip-template');
161
- return yield fs.pathExists(skipFile);
162
- }
163
- catch (_a) {
164
- return false;
165
- }
166
- });
167
- }
168
- saveSkipTemplateConfig() {
169
- return __awaiter(this, void 0, void 0, function* () {
170
- try {
171
- const fs = yield Promise.resolve().then(() => __importStar(require('fs-extra')));
172
- const path = yield Promise.resolve().then(() => __importStar(require('path')));
173
- const skipFile = path.join(process.cwd(), '.skip-template');
174
- yield fs.writeFile(skipFile, new Date().toISOString());
175
- }
176
- catch (error) {
177
- }
178
- });
179
- }
180
- downloadTemplate(options) {
181
- return __awaiter(this, void 0, void 0, function* () {
182
- const { log, template, agent, useDefaultConfig } = options;
183
- try {
184
- let templateType;
185
- if (template) {
186
- templateType = template;
187
- }
188
- else {
189
- if (useDefaultConfig) {
190
- templateType = 'rules';
191
- }
192
- else {
193
- const { templateType: selectedType } = yield inquirer_1.default.prompt([
194
- {
195
- type: 'list',
196
- name: 'templateType',
197
- message: (0, i18n_1.t)('下载模板以获取完整的开发体验: {{hint}}', { hint: const_1.LIST_HINT }),
198
- choices: [
199
- { name: (0, i18n_1.t)('🟦 微信小程序 + CloudBase'), value: 'miniprogram' },
200
- { name: (0, i18n_1.t)('🚀 Web 应用 - React + CloudBase'), value: 'react' },
201
- { name: (0, i18n_1.t)('🟢 Web 应用 - Vue + CloudBase'), value: 'vue' },
202
- { name: (0, i18n_1.t)('🌈 跨端应用 - UniApp + CloudBase'), value: 'uniapp' },
203
- { name: (0, i18n_1.t)('🧩 只下载 AI 规则和配置'), value: 'rules' },
204
- { name: (0, i18n_1.t)('🚫 不下载模板'), value: 'none' }
205
- ],
206
- default: 'miniprogram'
207
- }
208
- ]);
209
- templateType = selectedType;
210
- }
211
- }
212
- if (templateType === 'none') {
213
- log.info((0, i18n_1.t)('🚫 跳过模板下载'));
214
- yield this.saveSkipTemplateConfig();
215
- return;
216
- }
217
- log.info((0, i18n_1.t)('📦 正在下载并解压 {{templateType}} 模板...', { templateType }));
218
- yield this.downloadAndExtractTemplate({ templateType, log, agent: agent, useDefaultConfig: useDefaultConfig || false });
219
- log.info((0, i18n_1.t)('✅ {{templateType}} 模板配置完成', { templateType }));
220
- }
221
- catch (error) {
222
- log.error((0, i18n_1.t)('❌ 配置失败: {{error}}', { error: error.message }));
223
- throw new error_1.CloudBaseError((0, i18n_1.t)('模板下载失败'), { original: error });
224
- }
225
- });
226
- }
227
- downloadAndExtractTemplate(options) {
228
- var _a, e_1, _b, _c;
229
- return __awaiter(this, void 0, void 0, function* () {
230
- const fs = yield Promise.resolve().then(() => __importStar(require('fs-extra')));
231
- const path = yield Promise.resolve().then(() => __importStar(require('path')));
232
- const os = yield Promise.resolve().then(() => __importStar(require('os')));
233
- const unzipper = yield Promise.resolve().then(() => __importStar(require('unzipper')));
234
- const https = yield Promise.resolve().then(() => __importStar(require('https')));
235
- let ConfigParser;
236
- const { templateType, log, agent, useDefaultConfig } = options;
237
- try {
238
- ConfigParser = (yield Promise.resolve().then(() => __importStar(require('@cloudbase/toolbox')))).ConfigParser;
239
- }
240
- catch (_d) {
241
- ConfigParser = undefined;
242
- }
243
- const templateMap = {
244
- rules: {
245
- url: 'https://static.cloudbase.net/cloudbase-examples/web-cloudbase-project.zip'
246
- },
247
- react: {
248
- url: 'https://static.cloudbase.net/cloudbase-examples/web-cloudbase-react-template.zip'
249
- },
250
- vue: {
251
- url: 'https://static.cloudbase.net/cloudbase-examples/web-cloudbase-vue-template.zip'
252
- },
253
- miniprogram: {
254
- url: 'https://static.cloudbase.net/cloudbase-examples/miniprogram-cloudbase-miniprogram-template.zip'
255
- },
256
- uniapp: {
257
- url: 'https://static.cloudbase.net/cloudbase-examples/universal-cloudbase-uniapp-template.zip'
258
- }
259
- };
260
- const template = templateMap[templateType];
261
- if (!template)
262
- throw new error_1.CloudBaseError((0, i18n_1.t)('未知模板类型'));
263
- const tmpDir = os.tmpdir();
264
- const zipPath = path.join(tmpDir, `cloudbase-template-${templateType}-${Date.now()}.zip`);
265
- yield new Promise((resolve, reject) => {
266
- const file = fs.createWriteStream(zipPath);
267
- https
268
- .get(template.url, (response) => {
269
- if (response.statusCode !== 200) {
270
- reject(new Error((0, i18n_1.t)('下载失败: {{statusCode}}', { statusCode: response.statusCode })));
271
- return;
272
- }
273
- response.pipe(file);
274
- file.on('finish', () => {
275
- file.close();
276
- resolve();
277
- });
278
- })
279
- .on('error', (err) => {
280
- fs.unlink(zipPath);
281
- reject(err);
282
- });
283
- });
284
- const extractDir = process.cwd();
285
- const zipStream = fs.createReadStream(zipPath).pipe(unzipper.Parse({ forceStream: true }));
286
- const agentDirs = ['.claude', '.codex', '.qwen', '.codebuddy', '.cursor'];
287
- try {
288
- for (var _e = true, _f = __asyncValues(zipStream), _g; _g = yield _f.next(), _a = _g.done, !_a;) {
289
- _c = _g.value;
290
- _e = false;
291
- try {
292
- const entry = _c;
293
- const entryPath = entry.path;
294
- const destPath = path.join(extractDir, entryPath);
295
- if (useDefaultConfig && agent) {
296
- const currentAgentDir = `.${agent}`;
297
- const isAgentDir = agentDirs.some(dir => entryPath.startsWith(dir + '/') || entryPath === dir);
298
- if (isAgentDir && !entryPath.startsWith(currentAgentDir + '/') && entryPath !== currentAgentDir) {
299
- log.debug && log.debug((0, i18n_1.t)('跳过不匹配的 agent 目录: {{entryPath}} (当前 agent: {{agent}})', { entryPath, agent }));
300
- entry.autodrain();
301
- continue;
302
- }
303
- }
304
- if (entry.type === 'Directory') {
305
- yield fs.ensureDir(destPath);
306
- entry.autodrain();
307
- continue;
308
- }
309
- if (MCP_CONFIG_SET.has(entryPath)) {
310
- try {
311
- yield this.mergeMcpConfig(entry, destPath, inferConfigFormat(entryPath), log);
312
- }
313
- catch (e) {
314
- log.warn((0, i18n_1.t)('MCP 配置合并失败 {{entryPath}}:{{error}},已跳过', { entryPath, error: e.message }));
315
- }
316
- continue;
317
- }
318
- if (entryPath === 'cloudbaserc.json' && (yield fs.pathExists(destPath))) {
319
- try {
320
- const templateContent = yield entry.buffer();
321
- const templateJson = JSON.parse(templateContent.toString('utf8'));
322
- const localJson = yield fs.readJson(destPath);
323
- const deepMerge = (target, source) => {
324
- if (typeof target !== 'object' ||
325
- typeof source !== 'object' ||
326
- !target ||
327
- !source)
328
- return target;
329
- const result = Object.assign(Object.assign({}, source), target);
330
- for (const key of Object.keys(source)) {
331
- if (key in target &&
332
- typeof target[key] === 'object' &&
333
- typeof source[key] === 'object') {
334
- result[key] = deepMerge(target[key], source[key]);
335
- }
336
- }
337
- return result;
338
- };
339
- let merged = deepMerge(localJson, templateJson);
340
- yield fs.writeJson(destPath, merged, { spaces: 2 });
341
- }
342
- catch (e) {
343
- log.warn((0, i18n_1.t)('cloudbaserc.json 合并失败,已跳过: {{error}}', { error: e.message }));
344
- }
345
- continue;
346
- }
347
- if (yield fs.pathExists(destPath)) {
348
- if (useDefaultConfig) {
349
- entry.autodrain();
350
- continue;
351
- }
352
- const { confirmOverwriteFile } = yield inquirer_1.default.prompt([
353
- {
354
- type: 'confirm',
355
- name: 'confirmOverwriteFile',
356
- message: (0, i18n_1.t)('检测到已存在文件 {{entryPath}},是否覆盖? {{hint}}', {
357
- entryPath,
358
- hint: (0, const_1.getBooleanHint)(false)
359
- }),
360
- default: false
361
- }
362
- ]);
363
- if (!confirmOverwriteFile) {
364
- entry.autodrain();
365
- continue;
366
- }
367
- }
368
- yield fs.ensureDir(path.dirname(destPath));
369
- yield new Promise((res, rej) => {
370
- entry.pipe(fs.createWriteStream(destPath)).on('finish', res).on('error', rej);
371
- });
372
- }
373
- finally {
374
- _e = true;
375
- }
376
- }
377
- }
378
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
379
- finally {
380
- try {
381
- if (!_e && !_a && (_b = _f.return)) yield _b.call(_f);
382
- }
383
- finally { if (e_1) throw e_1.error; }
384
- }
385
- yield fs.unlink(zipPath);
386
- yield this.modifyMCPConfigs(extractDir, log);
387
- });
388
- }
389
- getInstallCommand(agent) {
390
- switch (agent) {
391
- case 'claude':
392
- return {
393
- success: true,
394
- command: 'npm',
395
- args: ['install', '-g', '@anthropic-ai/claude-code'],
396
- message: 'macOS/Linux/WSL: curl -fsSL claude.ai/install.sh | bash\nWindows PowerShell: irm https://claude.ai/install.ps1 | iex'
397
- };
398
- case 'qwen':
399
- return {
400
- success: true,
401
- command: 'npm',
402
- args: ['install', '-g', '@qwen-code/qwen-code'],
403
- message: 'npm install -g @qwen-code/qwen-code'
404
- };
405
- case 'codex':
406
- return {
407
- success: true,
408
- command: 'npm',
409
- args: ['install', '-g', '@openai/codex-cli'],
410
- message: 'npm install -g @openai/codex-cli'
411
- };
412
- case 'gemini':
413
- return {
414
- success: true,
415
- command: 'npm',
416
- args: ['install', '-g', '@google/gemini-cli'],
417
- message: 'npm install -g @google/gemini-cli'
418
- };
419
- case 'codebuddy':
420
- return {
421
- success: true,
422
- command: 'npm',
423
- args: ['install', '-g', '@tencent-ai/codebuddy-code'],
424
- message: 'npm install -g @tencent-ai/codebuddy-code'
425
- };
426
- default:
427
- return { success: false, message: (0, i18n_1.t)('# 请查阅 {{agent}} 的官方安装文档', { agent }) };
428
- }
429
- }
430
- executeCommand(command, args, env, log) {
431
- return __awaiter(this, void 0, void 0, function* () {
432
- return new Promise((resolve, reject) => {
433
- const useShell = process.platform === 'win32';
434
- const child = (0, child_process_1.spawn)(command, args, {
435
- stdio: 'inherit',
436
- env,
437
- shell: useShell
438
- });
439
- child.on('close', (code) => {
440
- if (code === 0) {
441
- resolve();
442
- }
443
- else {
444
- const errorMsg = (0, i18n_1.t)('命令执行失败: {{command}} {{args}} (退出码: {{code}})', {
445
- command,
446
- args: args.join(' '),
447
- code
448
- });
449
- log.error((0, i18n_1.t)('❌ {{errorMsg}}', { errorMsg }));
450
- if (code === 127) {
451
- log.info((0, i18n_1.t)('💡 命令未找到,请检查是否正确安装'));
452
- log.info((0, i18n_1.t)('📦 安装命令: {{installCmd}}', { installCmd: this.getInstallCommand(command).message }));
453
- }
454
- else if (code === 1) {
455
- log.info((0, i18n_1.t)('💡 可能是参数错误或配置问题'));
456
- log.info((0, i18n_1.t)('🔧 请检查 API 密钥、模型名称等配置是否正确'));
457
- }
458
- if (command === 'ccr') {
459
- log.info((0, i18n_1.t)('🔧 请前往 {{logPath}} 查看日志', { logPath: const_1.CLAUDE_CODE_ROUTER_LOG_PATH }));
460
- }
461
- reject(new Error(errorMsg));
462
- }
463
- });
464
- child.on('error', (err) => {
465
- const errorMsg = (0, i18n_1.t)('启动失败: {{command}} ({{error}})', { command, error: err.message });
466
- log.error((0, i18n_1.t)('❌ {{errorMsg}}', { errorMsg }));
467
- if (err.message.includes('ENOENT')) {
468
- log.info((0, i18n_1.t)('💡 命令不存在,请先安装对应的 AI CLI 工具'));
469
- log.info((0, i18n_1.t)('📦 安装命令: {{installCmd}}', { installCmd: this.getInstallCommand(command).message }));
470
- }
471
- else if (err.message.includes('EACCES')) {
472
- log.info((0, i18n_1.t)('💡 权限不足,请检查文件权限或使用管理员权限'));
473
- }
474
- reject(new Error(errorMsg));
475
- });
476
- });
477
- });
478
- }
479
- isToolAvailable(command) {
480
- return __awaiter(this, void 0, void 0, function* () {
481
- return new Promise((resolve) => {
482
- const child = (0, child_process_1.spawn)(command, ['--version'], {
483
- stdio: 'pipe',
484
- shell: true
485
- });
486
- child.on('close', (code) => {
487
- resolve(code === 0);
488
- });
489
- child.on('error', () => {
490
- resolve(false);
491
- });
492
- });
493
- });
494
- }
495
- validateAgentConfig(agent, agentConfig, log) {
496
- return __awaiter(this, void 0, void 0, function* () {
497
- if (!agentConfig) {
498
- log.error((0, i18n_1.t)('❌ Agent 配置为空'));
499
- return false;
500
- }
501
- const validateResult = (0, const_1.getAgentConfigValidator)(agent)(agentConfig);
502
- if (validateResult.success === true) {
503
- log.debug((0, i18n_1.t)('✅ Agent 配置验证通过'));
504
- return true;
505
- }
506
- else {
507
- log.error((0, i18n_1.t)('❌ {{agent}} 配置无效: {{error}}', { agent, error: validateResult.error }));
508
- return false;
509
- }
510
- });
511
- }
512
- executeAgentWithConfig(agent, agentConfig, additionalArgs, log) {
513
- return __awaiter(this, void 0, void 0, function* () {
514
- switch (agent) {
515
- case const_1.CLAUDE.value:
516
- try {
517
- if (agentConfig.type === 'cloudbase') {
518
- return yield this.executeClaudeCloudbaseAgent(agentConfig, additionalArgs, log);
519
- }
520
- else if (agentConfig.type === 'custom') {
521
- return yield this.executeClaudeAgent(agentConfig, additionalArgs, log);
522
- }
523
- else {
524
- return yield this.executeNoneClaudeAgent(additionalArgs, log);
525
- }
526
- }
527
- catch (_) {
528
- (0, claudeWindows_1.claudeWindowsCheck)(log);
529
- return process.exit(1);
530
- }
531
- case const_1.QWEN.value:
532
- if (agentConfig.type === 'cloudbase') {
533
- return yield this.executeQwenCloudbaseAgent(agentConfig, additionalArgs, log);
534
- }
535
- else if (agentConfig.type === 'custom') {
536
- return yield this.executeQwenAgent(agentConfig, additionalArgs, log);
537
- }
538
- else {
539
- return yield this.executeNoneQwenAgent(additionalArgs, log);
540
- }
541
- case const_1.CODEX.value:
542
- if (agentConfig.type === 'cloudbase') {
543
- return yield this.executeCodexCloudbaseAgent(agentConfig, additionalArgs, log);
544
- }
545
- else if (agentConfig.type === 'custom') {
546
- return yield this.executeCodexAgent(agentConfig, additionalArgs, log);
547
- }
548
- else {
549
- return yield this.executeNoneCodexAgent(additionalArgs, log);
550
- }
551
- case const_1.AIDER.value:
552
- if (agentConfig.type === 'cloudbase') {
553
- return yield this.executeAiderCloudbaseAgent(agentConfig, additionalArgs, log);
554
- }
555
- else {
556
- return yield this.executeAiderAgent(agentConfig, additionalArgs, log);
557
- }
558
- case const_1.CURSOR.value:
559
- return yield this.executeNoneCursorAgent(additionalArgs, log);
560
- case const_1.CODEBUDDY.value:
561
- if (agentConfig.type === 'custom') {
562
- return yield this.executeCodebuddyAgent(agentConfig, additionalArgs, log);
563
- }
564
- else {
565
- return yield this.executeNoneCodebuddyAgent(additionalArgs, log);
566
- }
567
- default:
568
- throw new Error((0, i18n_1.t)('不支持的 AI 工具: {{agent}}', { agent }));
569
- }
570
- });
571
- }
572
- executeClaudeAgent({ apiKey, baseUrl, model }, additionalArgs, log) {
573
- return __awaiter(this, void 0, void 0, function* () {
574
- (0, nodeVersion_1.ensureNodeVersion)('v18.0.0', log);
575
- yield this.ensureClaudeCode(log);
576
- yield this.executeCommand('claude', additionalArgs, Object.assign(Object.assign({}, process.env), { ANTHROPIC_AUTH_TOKEN: apiKey, ANTHROPIC_BASE_URL: baseUrl, ANTHROPIC_MODEL: model }), log);
577
- });
578
- }
579
- executeNoneClaudeAgent(additionalArgs, log) {
580
- return __awaiter(this, void 0, void 0, function* () {
581
- yield this.ensureClaudeCode(log);
582
- yield this.executeCommand('claude', additionalArgs, Object.assign({}, process.env), log);
583
- });
584
- }
585
- executeQwenAgent({ apiKey, baseUrl, model }, additionalArgs, log) {
586
- return __awaiter(this, void 0, void 0, function* () {
587
- (0, nodeVersion_1.ensureNodeVersion)('v20.0.0', log);
588
- yield this.ensureQwenCode(log);
589
- yield this.executeCommand('qwen', additionalArgs, Object.assign(Object.assign({}, process.env), { OPENAI_API_KEY: apiKey, OPENAI_BASE_URL: baseUrl, OPENAI_MODEL: model }), log);
590
- });
591
- }
592
- executeNoneQwenAgent(additionalArgs, log) {
593
- return __awaiter(this, void 0, void 0, function* () {
594
- yield this.ensureQwenCode(log);
595
- yield this.executeCommand('qwen', additionalArgs, Object.assign({}, process.env), log);
596
- });
597
- }
598
- executeQwenCloudbaseAgent({ provider, model }, additionalArgs, log) {
599
- return __awaiter(this, void 0, void 0, function* () {
600
- (0, nodeVersion_1.ensureNodeVersion)('v20.0.0', log);
601
- yield this.ensureQwenCode(log);
602
- const _envId = yield (0, config_1.createConfigParser)().get('envId');
603
- yield (0, auth_1.checkLogin)();
604
- const credential = yield (0, utils_1.getCredential)({}, {});
605
- const envId = yield (0, env_1.ensureValidEnv)(_envId, log);
606
- const accessToken = yield (0, utils_1.rawFetchAccessToken)({
607
- envId,
608
- secretId: credential.secretId,
609
- secretKey: credential.secretKey,
610
- token: credential.token
611
- });
612
- if (!accessToken.access_token) {
613
- log.error((0, i18n_1.t)('获取云开发 Access Token 失败,请运行 tcb login 后再重试,{{token}}', {
614
- token: JSON.stringify(accessToken)
615
- }));
616
- process.exit(1);
617
- }
618
- const baseUrl = `${(0, url_1.getGatewayUrl)(envId)}/v1/ai/${provider}`;
619
- const apiKey = accessToken.access_token;
620
- yield this.executeCommand('qwen', additionalArgs, Object.assign(Object.assign({}, process.env), { OPENAI_API_KEY: apiKey, OPENAI_BASE_URL: baseUrl, OPENAI_MODEL: model }), log);
621
- });
622
- }
623
- executeClaudeCloudbaseAgent({ provider, model, transformer }, additionalArgs, log) {
624
- return __awaiter(this, void 0, void 0, function* () {
625
- (0, nodeVersion_1.ensureNodeVersion)('v18.19.0', log);
626
- yield this.ensureClaudeCodeRouter(log);
627
- yield this.ensureClaudeCode(log);
628
- yield this.configureClaudeCodeRouter(provider, model, transformer, log);
629
- yield this.restartClaudeCodeRouter(log);
630
- yield this.executeCommand('ccr', ['code', ...additionalArgs], Object.assign({}, process.env), log);
631
- });
632
- }
633
- restartClaudeCodeRouter(log) {
634
- return __awaiter(this, void 0, void 0, function* () {
635
- try {
636
- yield this.executeCommand('ccr', ['restart'], process.env, log);
637
- }
638
- catch (e) {
639
- log.error((0, i18n_1.t)('执行 ccr restart 失败,尝试执行 ccr stop && ccr start'));
640
- yield this.executeCommand('ccr', ['stop'], process.env, log);
641
- this.executeCommand('ccr', ['start'], process.env, log);
642
- const max = 3;
643
- let current = 0;
644
- while (current < max) {
645
- current++;
646
- if (current > max) {
647
- throw new Error((0, i18n_1.t)('ccr 重启完成失败,可前往 {{logPath}} 查看日志', { logPath: const_1.CLAUDE_CODE_ROUTER_LOG_PATH }));
648
- }
649
- log.info((0, i18n_1.t)('{{current}}/{{max}}等待 ccr 重启完成...', { current, max }));
650
- const isRunning = yield this.isClaudeCodeRouterRunning();
651
- if (isRunning) {
652
- log.info((0, i18n_1.t)('ccr 重启完成'));
653
- break;
654
- }
655
- }
656
- }
657
- });
658
- }
659
- isClaudeCodeRouterRunning() {
660
- return __awaiter(this, void 0, void 0, function* () {
661
- return new Promise((resolve) => {
662
- const child = (0, child_process_1.spawn)('ccr', ['status'], {
663
- stdio: 'pipe',
664
- env: process.env,
665
- shell: process.platform === 'win32'
666
- });
667
- child.stdout.on('data', (data) => {
668
- const str = data.toString();
669
- if (str.includes('Status: Running')) {
670
- resolve(true);
671
- child.kill();
672
- }
673
- });
674
- setTimeout(() => {
675
- resolve(false);
676
- child.kill();
677
- }, 3000);
678
- });
679
- });
680
- }
681
- configureClaudeCodeRouter(provider, model, transformer, log) {
682
- return __awaiter(this, void 0, void 0, function* () {
683
- const fs = yield Promise.resolve().then(() => __importStar(require('fs-extra')));
684
- const _envId = yield (0, config_1.createConfigParser)().get('envId');
685
- yield (0, auth_1.checkLogin)();
686
- const credential = yield (0, utils_1.getCredential)({}, {});
687
- const envId = yield (0, env_1.ensureValidEnv)(_envId, log);
688
- const accessToken = yield (0, utils_1.rawFetchAccessToken)({
689
- envId,
690
- secretId: credential.secretId,
691
- secretKey: credential.secretKey,
692
- token: credential.token
693
- });
694
- if (!accessToken.access_token) {
695
- log.error((0, i18n_1.t)('获取云开发 Access Token 失败,请运行 tcb login 后再重试,{{token}}', {
696
- token: JSON.stringify(accessToken)
697
- }));
698
- process.exit(1);
699
- }
700
- const cloudbaseProvider = {
701
- name: 'cloudbase',
702
- api_base_url: `${(0, url_1.getGatewayUrl)(envId)}/v1/ai/${provider}/chat/completions`,
703
- api_key: accessToken.access_token,
704
- models: [model]
705
- };
706
- if (transformer && transformer.trim().length > 0) {
707
- cloudbaseProvider.transformer = { use: [transformer] };
708
- }
709
- yield fs.ensureFile(const_1.CLAUDE_CODE_ROUTER_CONFIG_PATH);
710
- const claudeCodeRouterConfig = yield fs.readFile(const_1.CLAUDE_CODE_ROUTER_CONFIG_PATH, 'utf-8');
711
- if (claudeCodeRouterConfig.trim().length === 0) {
712
- log.debug((0, i18n_1.t)('🛠️ claude-code-router 配置为空,写入 Cloudbase 配置...'));
713
- yield fs.writeJson(const_1.CLAUDE_CODE_ROUTER_CONFIG_PATH, { Providers: [cloudbaseProvider] });
714
- log.debug((0, i18n_1.t)('✅ claude-code-router 配置完成'));
715
- }
716
- else {
717
- const config = safeParseJson(claudeCodeRouterConfig);
718
- if (!config) {
719
- const { shouldOverwrite } = yield inquirer_1.default.prompt([
720
- {
721
- type: 'confirm',
722
- name: 'shouldOverwrite',
723
- message: (0, i18n_1.t)('claude-code-router 配置文件非合法 JSON ,是否覆盖? {{hint}}', { hint: (0, const_1.getBooleanHint)() })
724
- }
725
- ]);
726
- if (shouldOverwrite) {
727
- yield fs.writeJson(const_1.CLAUDE_CODE_ROUTER_CONFIG_PATH, {
728
- Providers: [cloudbaseProvider]
729
- }, { spaces: 2 });
730
- log.debug((0, i18n_1.t)('✅ claude-code-router 配置完成'));
731
- }
732
- else {
733
- log.error((0, i18n_1.t)('❌ claude-code-router 配置文件非合法 JSON ,请手动修复'));
734
- process.exit(1);
735
- }
736
- }
737
- if (typeof config !== 'object' || config === null) {
738
- log.error((0, i18n_1.t)('❌ 未知 claude-code-router 配置文件格式请手动修复'));
739
- process.exit(1);
740
- }
741
- if (!('Providers' in config)) {
742
- config.Providers = [cloudbaseProvider];
743
- }
744
- if (!Array.isArray(config.Providers)) {
745
- log.error((0, i18n_1.t)('❌ claude-code-router 配置文件 Providers 字段非数组类型,请手动修复'));
746
- process.exit(1);
747
- }
748
- const providers = config.Providers;
749
- const index = providers.findIndex((p) => typeof p === 'object' && (p === null || p === void 0 ? void 0 : p.name) === 'cloudbase');
750
- if (index !== -1) {
751
- providers[index] = cloudbaseProvider;
752
- }
753
- else {
754
- providers.push(cloudbaseProvider);
755
- }
756
- if (!('Router' in config) ||
757
- typeof config.Router !== 'object' ||
758
- config.Router === null) {
759
- config.Router = {};
760
- }
761
- config.Router.default = `cloudbase,${model}`;
762
- config.Log = true;
763
- yield fs.writeJson(const_1.CLAUDE_CODE_ROUTER_CONFIG_PATH, config, { spaces: 2 });
764
- log.debug((0, i18n_1.t)('✅ claude-code-router 配置完成'));
765
- }
766
- });
767
- }
768
- parseArgs(args) {
769
- return args.filter((arg) => typeof arg === 'string' && arg.trim().length > 0);
770
- }
771
- ensureClaudeCodeRouter(log) {
772
- return __awaiter(this, void 0, void 0, function* () {
773
- const isAvailable = yield new Promise((resolve) => {
774
- const child = (0, child_process_1.spawn)('ccr', ['--version'], {
775
- stdio: 'pipe',
776
- shell: true
777
- });
778
- child.stdout.on('data', (data) => {
779
- data.toString().includes('Usage: ccr [command]') && resolve(true);
780
- });
781
- child.on('close', (code) => {
782
- resolve(code === 0);
783
- });
784
- child.on('error', () => {
785
- resolve(false);
786
- });
787
- });
788
- if (isAvailable) {
789
- log.debug((0, i18n_1.t)('claude code router 已安装!'));
790
- }
791
- else {
792
- const { shouldInstall } = yield inquirer_1.default.prompt([
793
- {
794
- type: 'confirm',
795
- name: 'shouldInstall',
796
- message: (0, i18n_1.t)('AI 开发缺少 claude code router 依赖,是否安装? {{hint}}', {
797
- hint: (0, const_1.getBooleanHint)(true)
798
- })
799
- }
800
- ]);
801
- if (shouldInstall) {
802
- yield this.executeCommand('npm', ['install', '-g', '@musistudio/claude-code-router'], process.env, log);
803
- log.info((0, i18n_1.t)('✅ claude-code-router 安装完成'));
804
- }
805
- else {
806
- log.info((0, i18n_1.t)('❌ claude code router 未安装,请手动安装'));
807
- process.exit(1);
808
- }
809
- }
810
- });
811
- }
812
- ensureClaudeCode(log) {
813
- return __awaiter(this, void 0, void 0, function* () {
814
- if (yield this.isToolAvailable('claude')) {
815
- log.debug((0, i18n_1.t)('claude code 已安装!'));
816
- }
817
- else {
818
- const { shouldInstall } = yield inquirer_1.default.prompt([
819
- {
820
- type: 'confirm',
821
- name: 'shouldInstall',
822
- message: (0, i18n_1.t)('AI 开发缺少 claude code 依赖,是否安装? {{hint}}', { hint: (0, const_1.getBooleanHint)(true) })
823
- }
824
- ]);
825
- if (shouldInstall) {
826
- const platform = process.platform;
827
- if (platform === 'win32') {
828
- yield this.executeCommand('npm', ['install', '-g', '@anthropic-ai/claude-code'], process.env, log);
829
- }
830
- else {
831
- try {
832
- yield this.executeCommand('sh', ['-c', 'curl -fsSL https://claude.ai/install.sh | bash'], process.env, log);
833
- }
834
- catch (error) {
835
- log.warn((0, i18n_1.t)('⚠️ curl 安装失败,尝试使用 npm 安装...'));
836
- try {
837
- yield this.executeCommand('npm', ['install', '-g', '@anthropic-ai/claude-code'], process.env, log);
838
- }
839
- catch (npmError) {
840
- log.error((0, i18n_1.t)('❌ claude code 安装失败'));
841
- log.error((0, i18n_1.t)('请手动安装 claude code:'));
842
- log.error((0, i18n_1.t)('📖 安装文档: {{link}}', {
843
- link: (0, output_1.genClickableLink)('https://docs.anthropic.com/en/docs/claude-code/setup')
844
- }));
845
- process.exit(1);
846
- }
847
- }
848
- }
849
- log.info((0, i18n_1.t)('✅ claude code 安装完成'));
850
- }
851
- else {
852
- log.info((0, i18n_1.t)('❌ claude code 未安装,请手动安装'));
853
- log.info((0, i18n_1.t)('📖 安装文档: {{link}}', {
854
- link: (0, output_1.genClickableLink)('https://docs.anthropic.com/en/docs/claude-code/setup')
855
- }));
856
- process.exit(1);
857
- }
858
- }
859
- });
860
- }
861
- ensureQwenCode(log) {
862
- return __awaiter(this, void 0, void 0, function* () {
863
- if (yield this.isToolAvailable('qwen')) {
864
- log.debug((0, i18n_1.t)('qwen code 已安装!'));
865
- }
866
- else {
867
- const { shouldInstall } = yield inquirer_1.default.prompt([
868
- {
869
- type: 'confirm',
870
- name: 'shouldInstall',
871
- message: (0, i18n_1.t)('AI 开发缺少 qwen code 依赖,是否安装? {{hint}}', { hint: (0, const_1.getBooleanHint)(true) })
872
- }
873
- ]);
874
- if (shouldInstall) {
875
- yield this.executeCommand('npm', ['install', '-g', '@qwen-code/qwen-code'], process.env, log);
876
- log.info((0, i18n_1.t)('✅ qwen code 安装完成'));
877
- }
878
- else {
879
- log.info((0, i18n_1.t)('❌ qwen code 未安装,请手动安装'));
880
- process.exit(1);
881
- }
882
- }
883
- });
884
- }
885
- executeCodexAgent({ apiKey, baseUrl, model }, additionalArgs, log) {
886
- return __awaiter(this, void 0, void 0, function* () {
887
- yield this.ensureCodexCode(log);
888
- const codexArgs = [
889
- ...(model ? ['--config', `model=${model}`] : []),
890
- '--config',
891
- 'model_providers.custom.name=Custom OpenAI',
892
- ...(baseUrl ? ['--config', `model_providers.custom.base_url=${baseUrl}`] : []),
893
- '--config',
894
- 'model_providers.custom.env_key=OPENAI_API_KEY',
895
- '--config',
896
- 'model_provider=custom',
897
- ...additionalArgs
898
- ];
899
- yield this.executeCommand('codex', codexArgs, Object.assign(Object.assign({}, process.env), { OPENAI_API_KEY: apiKey }), log);
900
- });
901
- }
902
- executeNoneCodexAgent(additionalArgs, log) {
903
- return __awaiter(this, void 0, void 0, function* () {
904
- yield this.ensureCodexCode(log);
905
- yield this.executeCommand('codex', additionalArgs, Object.assign({}, process.env), log);
906
- });
907
- }
908
- executeCodexCloudbaseAgent({ provider, model }, additionalArgs, log) {
909
- return __awaiter(this, void 0, void 0, function* () {
910
- yield this.ensureCodexCode(log);
911
- const _envId = yield (0, config_1.createConfigParser)().get('envId');
912
- yield (0, auth_1.checkLogin)();
913
- const credential = yield (0, utils_1.getCredential)({}, {});
914
- const envId = yield (0, env_1.ensureValidEnv)(_envId, log);
915
- const accessToken = yield (0, utils_1.rawFetchAccessToken)({
916
- envId,
917
- secretId: credential.secretId,
918
- secretKey: credential.secretKey,
919
- token: credential.token
920
- });
921
- if (!accessToken.access_token) {
922
- log.error((0, i18n_1.t)('获取云开发 Access Token 失败,请运行 tcb login 后再重试,{{token}}', {
923
- token: JSON.stringify(accessToken)
924
- }));
925
- process.exit(1);
926
- }
927
- const baseUrl = `${(0, url_1.getGatewayUrl)(envId)}/v1/ai/${provider}`;
928
- const apiKey = accessToken.access_token;
929
- const codexArgs = [
930
- '--config',
931
- `model=${model}`,
932
- '--config',
933
- 'model_providers.cloudbase.name=CloudBase AI',
934
- '--config',
935
- `model_providers.cloudbase.base_url=${baseUrl}`,
936
- '--config',
937
- 'model_providers.cloudbase.env_key=CLOUDBASE_ACCESS_TOKEN',
938
- '--config',
939
- 'model_provider=cloudbase',
940
- ...additionalArgs
941
- ];
942
- yield this.executeCommand('codex', codexArgs, Object.assign(Object.assign({}, process.env), { CLOUDBASE_ACCESS_TOKEN: apiKey }), log);
943
- });
944
- }
945
- executeNoneCursorAgent(additionalArgs, log) {
946
- return __awaiter(this, void 0, void 0, function* () {
947
- yield this.ensureCursor(log);
948
- yield this.executeCommand('cursor-agent', additionalArgs, Object.assign({}, process.env), log);
949
- });
950
- }
951
- ensureCursor(log) {
952
- return __awaiter(this, void 0, void 0, function* () {
953
- if (yield this.isToolAvailable('cursor-agent')) {
954
- log.debug((0, i18n_1.t)('Cursor CLI 已安装!'));
955
- }
956
- else {
957
- const { shouldInstall } = yield inquirer_1.default.prompt([
958
- {
959
- type: 'confirm',
960
- name: 'shouldInstall',
961
- message: (0, i18n_1.t)('AI 开发缺少 Cursor CLI 依赖,是否安装? {{hint}}', { hint: (0, const_1.getBooleanHint)(true) })
962
- }
963
- ]);
964
- if (shouldInstall) {
965
- log.info((0, i18n_1.t)('正在安装 Cursor CLI...'));
966
- yield this.executeCommand('sh', ['-c', 'curl https://cursor.com/install -fsS | bash'], process.env, log);
967
- log.info((0, i18n_1.t)('✅ Cursor CLI 安装完成'));
968
- }
969
- else {
970
- log.info((0, i18n_1.t)('❌ Cursor CLI 未安装,请手动安装'));
971
- process.exit(1);
972
- }
973
- }
974
- });
975
- }
976
- ensureCodexCode(log) {
977
- return __awaiter(this, void 0, void 0, function* () {
978
- if (yield this.isToolAvailable('codex')) {
979
- log.debug((0, i18n_1.t)('codex 已安装!'));
980
- }
981
- else {
982
- const { shouldInstall } = yield inquirer_1.default.prompt([
983
- {
984
- type: 'confirm',
985
- name: 'shouldInstall',
986
- message: (0, i18n_1.t)('AI 开发缺少 codex 依赖,是否安装? {{hint}}', { hint: (0, const_1.getBooleanHint)(true) })
987
- }
988
- ]);
989
- if (shouldInstall) {
990
- yield this.executeCommand('npm', ['install', '-g', '@openai/codex'], process.env, log);
991
- log.info((0, i18n_1.t)('✅ codex 安装完成'));
992
- }
993
- else {
994
- log.info((0, i18n_1.t)('❌ codex 未安装,请手动安装'));
995
- process.exit(1);
996
- }
997
- }
998
- });
999
- }
1000
- executeAiderAgent(config, additionalArgs, log) {
1001
- return __awaiter(this, void 0, void 0, function* () {
1002
- yield this.ensureAider(log);
1003
- const { apiKey, baseUrl, model } = config;
1004
- const aiderArgs = ['--model', `openai/${model}`, ...additionalArgs];
1005
- const env = Object.assign(Object.assign({}, process.env), { OPENAI_API_KEY: apiKey, OPENAI_API_BASE: baseUrl });
1006
- yield this.executeCommand('aider', aiderArgs, env, log);
1007
- });
1008
- }
1009
- executeAiderCloudbaseAgent(config, additionalArgs, log) {
1010
- return __awaiter(this, void 0, void 0, function* () {
1011
- yield this.ensureAider(log);
1012
- const { provider, model } = config;
1013
- const _envId = yield (0, config_1.createConfigParser)().get('envId');
1014
- yield (0, auth_1.checkLogin)();
1015
- const credential = yield (0, utils_1.getCredential)({}, {});
1016
- const envId = yield (0, env_1.ensureValidEnv)(_envId, log);
1017
- const accessToken = yield (0, utils_1.rawFetchAccessToken)({
1018
- envId,
1019
- secretId: credential.secretId,
1020
- secretKey: credential.secretKey,
1021
- token: credential.token
1022
- });
1023
- if (!accessToken.access_token) {
1024
- log.error((0, i18n_1.t)('获取云开发 Access Token 失败,请运行 tcb login 后再重试,{{token}}', {
1025
- token: JSON.stringify(accessToken)
1026
- }));
1027
- process.exit(1);
1028
- }
1029
- const baseUrl = `${(0, url_1.getGatewayUrl)(envId)}/v1/ai/${provider}`;
1030
- const apiKey = accessToken.access_token;
1031
- const aiderArgs = ['--model', `openai/${model}`, ...additionalArgs];
1032
- const env = Object.assign(Object.assign({}, process.env), { OPENAI_API_KEY: apiKey, OPENAI_API_BASE: baseUrl });
1033
- yield this.executeCommand('aider', aiderArgs, env, log);
1034
- });
1035
- }
1036
- ensureAider(log) {
1037
- return __awaiter(this, void 0, void 0, function* () {
1038
- if (yield this.isToolAvailable('aider')) {
1039
- log.debug((0, i18n_1.t)('aider 已安装!'));
1040
- }
1041
- else {
1042
- const { shouldInstall } = yield inquirer_1.default.prompt([
1043
- {
1044
- type: 'confirm',
1045
- name: 'shouldInstall',
1046
- message: (0, i18n_1.t)('AI 开发缺少 aider 依赖,是否安装? {{hint}}', { hint: (0, const_1.getBooleanHint)(true) })
1047
- }
1048
- ]);
1049
- if (shouldInstall) {
1050
- log.info((0, i18n_1.t)('正在安装 aider...'));
1051
- const platform = process.platform;
1052
- if (platform === 'win32') {
1053
- yield this.executeCommand('powershell', ['-c', 'irm https://aider.chat/install.ps1 | iex'], process.env, log);
1054
- }
1055
- else {
1056
- yield this.executeCommand('sh', ['-c', 'curl -LsSf https://aider.chat/install.sh | sh'], process.env, log);
1057
- }
1058
- log.info((0, i18n_1.t)('✅ aider 安装完成'));
1059
- }
1060
- else {
1061
- log.info((0, i18n_1.t)('❌ aider 未安装,请手动安装'));
1062
- process.exit(1);
1063
- }
1064
- }
1065
- });
1066
- }
1067
- modifyMCPConfigs(extractDir, log) {
1068
- return __awaiter(this, void 0, void 0, function* () {
1069
- const fs = yield Promise.resolve().then(() => __importStar(require('fs-extra')));
1070
- const path = yield Promise.resolve().then(() => __importStar(require('path')));
1071
- try {
1072
- log.info((0, i18n_1.t)('🔧 正在修改 MCP 配置文件...'));
1073
- for (const [, files] of Object.entries(IDE_FILE_MAPPINGS)) {
1074
- for (const descriptor of files) {
1075
- if (!descriptor.isMcpConfig)
1076
- continue;
1077
- const filePath = path.join(extractDir, descriptor.path);
1078
- if (yield fs.pathExists(filePath)) {
1079
- const format = inferConfigFormat(descriptor.path);
1080
- if (format === 'json') {
1081
- yield this.modifyMCPJsonFile(filePath, log);
1082
- }
1083
- else if (format === 'toml') {
1084
- yield this.modifyMCPTomlFile(filePath, log);
1085
- }
1086
- }
1087
- }
1088
- }
1089
- log.info((0, i18n_1.t)('✅ MCP 配置文件修改完成'));
1090
- }
1091
- catch (error) {
1092
- log.warn((0, i18n_1.t)('⚠️ MCP 配置文件修改失败: {{error}}', { error: error.message }));
1093
- }
1094
- });
1095
- }
1096
- modifyMCPJsonFile(filePath, log) {
1097
- return __awaiter(this, void 0, void 0, function* () {
1098
- const fs = yield Promise.resolve().then(() => __importStar(require('fs-extra')));
1099
- try {
1100
- const content = yield fs.readFile(filePath, 'utf-8');
1101
- const config = JSON.parse(content);
1102
- let modified = false;
1103
- const modifyCommands = (obj) => {
1104
- if (typeof obj !== 'object' || obj === null) {
1105
- return obj;
1106
- }
1107
- if (Array.isArray(obj)) {
1108
- return obj.map((item) => modifyCommands(item));
1109
- }
1110
- const result = Object.assign({}, obj);
1111
- if (result.command === 'npx' && Array.isArray(result.args)) {
1112
- const argsStr = result.args.join(' ');
1113
- if (argsStr.includes('npm-global-exec@latest') &&
1114
- argsStr.includes('@cloudbase/cloudbase-mcp@latest')) {
1115
- result.command = 'cloudbase-mcp';
1116
- result.args = [];
1117
- result.env = {
1118
- INTEGRATION_IDE: process.env.INTEGRATION_IDE || 'CloudBaseCLI'
1119
- };
1120
- modified = true;
1121
- log.debug((0, i18n_1.t)('修改配置文件 {{filePath}}: npx -> cloudbase-mcp', { filePath }));
1122
- }
1123
- }
1124
- for (const [key, value] of Object.entries(result)) {
1125
- result[key] = modifyCommands(value);
1126
- }
1127
- return result;
1128
- };
1129
- const modifiedConfig = modifyCommands(config);
1130
- if (modified) {
1131
- yield fs.writeJson(filePath, modifiedConfig, { spaces: 2 });
1132
- log.debug((0, i18n_1.t)('✅ 已修改 {{filePath}}', { filePath }));
1133
- }
1134
- }
1135
- catch (error) {
1136
- log.warn((0, i18n_1.t)('⚠️ 修改配置文件 {{filePath}} 失败: {{error}}', { filePath, error: error.message }));
1137
- }
1138
- });
1139
- }
1140
- modifyMCPTomlFile(filePath, log) {
1141
- return __awaiter(this, void 0, void 0, function* () {
1142
- const fs = yield Promise.resolve().then(() => __importStar(require('fs-extra')));
1143
- const toml = yield Promise.resolve().then(() => __importStar(require('toml')));
1144
- try {
1145
- const content = yield fs.readFile(filePath, 'utf-8');
1146
- const config = toml.parse(content);
1147
- let modified = false;
1148
- const modifyCommands = (obj) => {
1149
- if (typeof obj !== 'object' || obj === null) {
1150
- return obj;
1151
- }
1152
- if (Array.isArray(obj)) {
1153
- return obj.map((item) => modifyCommands(item));
1154
- }
1155
- const result = Object.assign({}, obj);
1156
- if (result.command === 'npx' && Array.isArray(result.args)) {
1157
- const argsStr = result.args.join(' ');
1158
- if (argsStr.includes('@cloudbase/cloudbase-mcp@latest')) {
1159
- result.command = 'cloudbase-mcp';
1160
- result.args = [];
1161
- result.env = {
1162
- INTEGRATION_IDE: process.env.INTEGRATION_IDE || 'CloudBaseCLI'
1163
- };
1164
- modified = true;
1165
- log.debug((0, i18n_1.t)('修改配置文件 {{filePath}}: npx -> cloudbase-mcp', { filePath }));
1166
- }
1167
- }
1168
- for (const [key, value] of Object.entries(result)) {
1169
- result[key] = modifyCommands(value);
1170
- }
1171
- return result;
1172
- };
1173
- const modifiedConfig = modifyCommands(config);
1174
- if (modified) {
1175
- const tomlString = this.objectToToml(modifiedConfig);
1176
- yield fs.writeFile(filePath, tomlString, 'utf-8');
1177
- log.debug((0, i18n_1.t)('✅ 已修改 {{filePath}}', { filePath }));
1178
- }
1179
- }
1180
- catch (error) {
1181
- log.warn((0, i18n_1.t)('⚠️ 修改配置文件 {{filePath}} 失败: {{error}}', { filePath, error: error.message }));
1182
- }
1183
- });
1184
- }
1185
- mergeMcpConfig(entry, destPath, format, log) {
1186
- return __awaiter(this, void 0, void 0, function* () {
1187
- const fs = yield Promise.resolve().then(() => __importStar(require('fs-extra')));
1188
- const path = yield Promise.resolve().then(() => __importStar(require('path')));
1189
- const incomingStr = (yield entry.buffer()).toString('utf8');
1190
- const deepMerge = (target, source) => {
1191
- if (typeof target !== 'object' || typeof source !== 'object' || !target || !source) {
1192
- return target;
1193
- }
1194
- const result = Array.isArray(target) ? [...target] : Object.assign(Object.assign({}, source), target);
1195
- for (const key of Object.keys(source)) {
1196
- if (key in target &&
1197
- typeof target[key] === 'object' &&
1198
- typeof source[key] === 'object') {
1199
- result[key] = deepMerge(target[key], source[key]);
1200
- }
1201
- }
1202
- return result;
1203
- };
1204
- yield fs.ensureDir(path.dirname(destPath));
1205
- if (format === 'json') {
1206
- const incomingObj = JSON.parse(incomingStr);
1207
- if (yield fs.pathExists(destPath)) {
1208
- const existingObj = yield fs.readJson(destPath);
1209
- const merged = deepMerge(existingObj, incomingObj);
1210
- yield fs.writeJson(destPath, merged, { spaces: 2 });
1211
- }
1212
- else {
1213
- yield fs.writeJson(destPath, incomingObj, { spaces: 2 });
1214
- }
1215
- return;
1216
- }
1217
- const toml = yield Promise.resolve().then(() => __importStar(require('toml')));
1218
- const incomingObj = toml.parse(incomingStr);
1219
- if (yield fs.pathExists(destPath)) {
1220
- const existingStr = yield fs.readFile(destPath, 'utf-8');
1221
- const existingObj = toml.parse(existingStr);
1222
- const merged = deepMerge(existingObj, incomingObj);
1223
- const out = this.objectToToml(merged);
1224
- yield fs.writeFile(destPath, out, 'utf-8');
1225
- }
1226
- else {
1227
- const out = this.objectToToml(incomingObj);
1228
- yield fs.writeFile(destPath, out, 'utf-8');
1229
- }
1230
- });
1231
- }
1232
- objectToToml(obj, prefix = '') {
1233
- const lines = [];
1234
- for (const [key, value] of Object.entries(obj)) {
1235
- const fullKey = prefix ? `${prefix}.${key}` : key;
1236
- if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
1237
- lines.push(`[${fullKey}]`);
1238
- lines.push(this.objectToToml(value, fullKey));
1239
- }
1240
- else if (Array.isArray(value)) {
1241
- const arrayStr = value
1242
- .map((item) => {
1243
- if (typeof item === 'string') {
1244
- return `"${item}"`;
1245
- }
1246
- return item;
1247
- })
1248
- .join(', ');
1249
- lines.push(`${key} = [${arrayStr}]`);
1250
- }
1251
- else if (typeof value === 'string') {
1252
- lines.push(`${key} = "${value}"`);
1253
- }
1254
- else {
1255
- lines.push(`${key} = ${value}`);
1256
- }
1257
- }
1258
- return lines.join('\n');
1259
- }
1260
- executeCodebuddyAgent({ apiKey }, additionalArgs, log) {
1261
- return __awaiter(this, void 0, void 0, function* () {
1262
- yield this.ensureCodebuddy(log);
1263
- yield this.executeCommand('codebuddy', additionalArgs, Object.assign(Object.assign({}, process.env), (apiKey && { CODEBUDDY_API_KEY: apiKey })), log);
1264
- });
1265
- }
1266
- executeNoneCodebuddyAgent(additionalArgs, log) {
1267
- return __awaiter(this, void 0, void 0, function* () {
1268
- yield this.ensureCodebuddy(log);
1269
- yield this.executeCommand('codebuddy', additionalArgs, Object.assign({}, process.env), log);
1270
- });
1271
- }
1272
- ensureCodebuddy(log) {
1273
- return __awaiter(this, void 0, void 0, function* () {
1274
- if (yield this.isToolAvailable('codebuddy')) {
1275
- log.debug((0, i18n_1.t)('codebuddy 已安装!'));
1276
- }
1277
- else {
1278
- const { shouldInstall } = yield inquirer_1.default.prompt([
1279
- {
1280
- type: 'confirm',
1281
- name: 'shouldInstall',
1282
- message: (0, i18n_1.t)('AI 开发缺少 codebuddy 依赖,是否安装? {{hint}}', { hint: (0, const_1.getBooleanHint)(true) })
1283
- }
1284
- ]);
1285
- if (shouldInstall) {
1286
- yield this.executeCommand('npm', ['install', '-g', '@tencent-ai/codebuddy-code'], process.env, log);
1287
- log.info((0, i18n_1.t)('✅ codebuddy 安装完成'));
1288
- }
1289
- else {
1290
- log.info((0, i18n_1.t)('❌ codebuddy 未安装,请手动安装'));
1291
- log.info((0, i18n_1.t)('📦 安装命令: npm install -g @tencent-ai/codebuddy-code'));
1292
- process.exit(1);
1293
- }
1294
- }
1295
- });
1296
- }
1297
- }
1298
- exports.AICommandRouter = AICommandRouter;
1299
- function safeParseJson(json) {
1300
- try {
1301
- return JSON.parse(json);
1302
- }
1303
- catch (_) {
1304
- return null;
1305
- }
1306
- }