@cloudbase/cli 2.10.0-beta.0 → 2.11.0-beta.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 (205) hide show
  1. package/lib/auth/login.js +51 -65
  2. package/lib/auth/logout.js +3 -14
  3. package/lib/commands/account/login.js +136 -149
  4. package/lib/commands/account/logout.js +3 -14
  5. package/lib/commands/ag/base.js +203 -0
  6. package/lib/commands/ag/create.js +301 -0
  7. package/lib/commands/ag/debug/index.html +699 -0
  8. package/lib/commands/ag/delete.js +200 -0
  9. package/lib/commands/ag/deploy.js +185 -0
  10. package/lib/commands/ag/detail.js +113 -0
  11. package/lib/commands/ag/index.js +22 -0
  12. package/lib/commands/ag/list.js +155 -0
  13. package/lib/commands/ag/run.js +644 -0
  14. package/lib/commands/ai/index.js +76 -95
  15. package/lib/commands/cloudfunction/base.js +182 -203
  16. package/lib/commands/cloudrun/base.js +578 -603
  17. package/lib/commands/common.js +48 -63
  18. package/lib/commands/config/delete.js +16 -27
  19. package/lib/commands/config/get.js +13 -24
  20. package/lib/commands/config/list.js +16 -27
  21. package/lib/commands/config/set.js +33 -44
  22. package/lib/commands/db/base.js +221 -240
  23. package/lib/commands/env/base.js +36 -49
  24. package/lib/commands/env/domain.js +79 -94
  25. package/lib/commands/env/login.js +120 -135
  26. package/lib/commands/framework/index.js +32 -49
  27. package/lib/commands/fun/base.js +223 -244
  28. package/lib/commands/functions/alias/getRoute.js +33 -44
  29. package/lib/commands/functions/alias/setRoute.js +36 -47
  30. package/lib/commands/functions/code-download.js +43 -54
  31. package/lib/commands/functions/code-update.js +23 -34
  32. package/lib/commands/functions/concurrency/delete.js +11 -22
  33. package/lib/commands/functions/concurrency/list.js +20 -31
  34. package/lib/commands/functions/concurrency/set.js +13 -24
  35. package/lib/commands/functions/config-update.js +30 -41
  36. package/lib/commands/functions/copy.js +12 -23
  37. package/lib/commands/functions/delete.js +30 -41
  38. package/lib/commands/functions/deploy.js +184 -202
  39. package/lib/commands/functions/detail.js +23 -34
  40. package/lib/commands/functions/invoke.js +69 -75
  41. package/lib/commands/functions/layer/bind.js +102 -105
  42. package/lib/commands/functions/layer/create.js +29 -35
  43. package/lib/commands/functions/layer/delete.js +42 -48
  44. package/lib/commands/functions/layer/download.js +52 -58
  45. package/lib/commands/functions/layer/list.js +44 -50
  46. package/lib/commands/functions/layer/sort.js +39 -45
  47. package/lib/commands/functions/list.js +25 -36
  48. package/lib/commands/functions/log.js +65 -73
  49. package/lib/commands/functions/run.js +118 -116
  50. package/lib/commands/functions/trigger-create.js +32 -43
  51. package/lib/commands/functions/trigger-delete.js +50 -61
  52. package/lib/commands/functions/version/list.js +29 -40
  53. package/lib/commands/functions/version/publish.js +11 -22
  54. package/lib/commands/gateway/create.js +50 -61
  55. package/lib/commands/gateway/delete.js +38 -49
  56. package/lib/commands/gateway/domain.js +65 -80
  57. package/lib/commands/gateway/list.js +31 -42
  58. package/lib/commands/gateway/switch.js +48 -61
  59. package/lib/commands/helpers/init.js +226 -249
  60. package/lib/commands/helpers/new.js +35 -46
  61. package/lib/commands/helpers/open.js +22 -33
  62. package/lib/commands/hosting/hosting.js +157 -178
  63. package/lib/commands/index.js +1 -0
  64. package/lib/commands/lowcode/app.js +114 -144
  65. package/lib/commands/lowcode/comps.js +136 -127
  66. package/lib/commands/lowcode/utils.js +11 -22
  67. package/lib/commands/pull/pull.js +33 -46
  68. package/lib/commands/run/delete.js +35 -46
  69. package/lib/commands/run/image/delete.js +32 -39
  70. package/lib/commands/run/image/download.js +26 -33
  71. package/lib/commands/run/image/list.js +41 -48
  72. package/lib/commands/run/image/upload.js +26 -33
  73. package/lib/commands/run/list.js +32 -43
  74. package/lib/commands/run/service/config.js +17 -28
  75. package/lib/commands/run/service/deploy.js +15 -26
  76. package/lib/commands/run/service/list.js +48 -59
  77. package/lib/commands/run/service/update.js +7 -18
  78. package/lib/commands/run/standalonegateway/create.js +35 -42
  79. package/lib/commands/run/standalonegateway/destroy.js +23 -30
  80. package/lib/commands/run/standalonegateway/list.js +19 -26
  81. package/lib/commands/run/standalonegateway/package.js +31 -38
  82. package/lib/commands/run/standalonegateway/turn.js +27 -34
  83. package/lib/commands/run/version/create.js +198 -205
  84. package/lib/commands/run/version/delete.js +31 -38
  85. package/lib/commands/run/version/list.js +42 -49
  86. package/lib/commands/run/version/modify.js +27 -34
  87. package/lib/commands/run/version/update.js +201 -208
  88. package/lib/commands/runf/base.js +216 -237
  89. package/lib/commands/self-update.js +59 -72
  90. package/lib/commands/smart.js +66 -79
  91. package/lib/commands/storage/storage.js +192 -219
  92. package/lib/commands/third/thirdAttach.js +16 -27
  93. package/lib/commands/utils.js +119 -149
  94. package/lib/db/index.js +48 -67
  95. package/lib/decorators/captureError.js +10 -21
  96. package/lib/decorators/guard.js +11 -22
  97. package/lib/decorators/injectParams.js +29 -40
  98. package/lib/decorators/params/common.js +5 -2
  99. package/lib/decorators/params/index.js +3 -12
  100. package/lib/env/domain.js +13 -28
  101. package/lib/env/index.js +25 -44
  102. package/lib/env/login.js +30 -45
  103. package/lib/function/alias.js +31 -44
  104. package/lib/function/base.js +187 -215
  105. package/lib/function/code.js +8 -19
  106. package/lib/function/concurrency.js +43 -58
  107. package/lib/function/create.js +43 -53
  108. package/lib/function/delete.js +22 -35
  109. package/lib/function/layer/attach.js +33 -46
  110. package/lib/function/layer/create.js +34 -45
  111. package/lib/function/layer/delete.js +5 -16
  112. package/lib/function/layer/download.js +11 -22
  113. package/lib/function/layer/list.js +12 -25
  114. package/lib/function/layer/sort.js +6 -17
  115. package/lib/function/trigger.js +65 -82
  116. package/lib/function/update.js +24 -32
  117. package/lib/function/version.js +29 -42
  118. package/lib/function/vpc.js +12 -25
  119. package/lib/gateway/index.js +77 -104
  120. package/lib/hosting.js +157 -188
  121. package/lib/run/delete.js +3 -12
  122. package/lib/run/image/build.js +6 -15
  123. package/lib/run/image/delete.js +3 -12
  124. package/lib/run/image/info.js +3 -12
  125. package/lib/run/image/list.js +6 -15
  126. package/lib/run/list.js +19 -30
  127. package/lib/run/repo.js +6 -15
  128. package/lib/run/service/common.js +160 -173
  129. package/lib/run/service/config.js +44 -57
  130. package/lib/run/service/deployPackage.js +33 -44
  131. package/lib/run/service/list.js +8 -14
  132. package/lib/run/service/showLogs.js +69 -90
  133. package/lib/run/service/update.js +50 -63
  134. package/lib/run/standalonegateway/create.js +3 -12
  135. package/lib/run/standalonegateway/destroy.js +3 -12
  136. package/lib/run/standalonegateway/list.js +3 -12
  137. package/lib/run/standalonegateway/package/list.js +3 -12
  138. package/lib/run/standalonegateway/turn/off.js +3 -12
  139. package/lib/run/standalonegateway/turn/on.js +3 -12
  140. package/lib/run/version/create.js +41 -31
  141. package/lib/run/version/delete.js +3 -12
  142. package/lib/run/version/list.js +3 -12
  143. package/lib/run/version/modify.js +3 -12
  144. package/lib/run/version/repo.js +6 -15
  145. package/lib/run/version/update.js +37 -26
  146. package/lib/storage.js +62 -93
  147. package/lib/third/index.js +6 -17
  148. package/lib/utils/ai/banner.js +49 -60
  149. package/lib/utils/ai/claudeWindows.js +2 -2
  150. package/lib/utils/ai/config.js +169 -206
  151. package/lib/utils/ai/ensureFiles.js +6 -17
  152. package/lib/utils/ai/env.js +16 -27
  153. package/lib/utils/ai/envLocalManager.js +35 -52
  154. package/lib/utils/ai/router.js +927 -1005
  155. package/lib/utils/ai/setup.js +527 -563
  156. package/lib/utils/auth.js +3 -14
  157. package/lib/utils/checkTcbrEnv.js +20 -31
  158. package/lib/utils/cli-table.js +6 -1
  159. package/lib/utils/config.js +4 -13
  160. package/lib/utils/dts.js +98 -113
  161. package/lib/utils/env.js +154 -175
  162. package/lib/utils/function-packer.js +29 -42
  163. package/lib/utils/log.js +10 -21
  164. package/lib/utils/mcp-config-modifier.js +105 -120
  165. package/lib/utils/net/cloud-api-request.js +15 -23
  166. package/lib/utils/net/credential.js +26 -39
  167. package/lib/utils/net/http-request.js +63 -80
  168. package/lib/utils/net/manager-service.js +22 -35
  169. package/lib/utils/notice.js +16 -27
  170. package/lib/utils/output/loading.js +3 -12
  171. package/lib/utils/parallel.js +32 -43
  172. package/lib/utils/platform/mac.js +4 -15
  173. package/lib/utils/platform/port.js +4 -15
  174. package/lib/utils/prompt/select.js +6 -15
  175. package/lib/utils/report.js +28 -33
  176. package/lib/utils/reporter/agree.js +11 -22
  177. package/lib/utils/reporter/download.js +17 -28
  178. package/lib/utils/reporter/usage.js +12 -23
  179. package/lib/utils/store/auth.js +17 -30
  180. package/lib/utils/store/config.js +11 -25
  181. package/lib/utils/store/db.js +17 -36
  182. package/lib/utils/tcbrApi/callTcbrApi.js +19 -28
  183. package/lib/utils/template-manager.js +215 -242
  184. package/lib/utils/template.js +81 -96
  185. package/lib/utils/tools/common.js +45 -56
  186. package/lib/utils/tools/time.js +5 -16
  187. package/lib/utils/url.js +10 -4
  188. package/package.json +2 -2
  189. package/specs/ag-command/design.md +421 -0
  190. package/specs/ag-command/doc.md +204 -0
  191. package/specs/ag-command/requirements.md +173 -0
  192. package/specs/ag-command/summary.md +174 -0
  193. package/specs/ag-command/tasks.md +197 -0
  194. package/specs/ag-command/usage-guide.md +420 -0
  195. package/tsconfig.json +1 -1
  196. package/types/commands/ag/base.d.ts +44 -0
  197. package/types/commands/ag/create.d.ts +25 -0
  198. package/types/commands/ag/delete.d.ts +32 -0
  199. package/types/commands/ag/deploy.d.ts +31 -0
  200. package/types/commands/ag/detail.d.ts +28 -0
  201. package/types/commands/ag/index.d.ts +6 -0
  202. package/types/commands/ag/list.d.ts +35 -0
  203. package/types/commands/ag/run.d.ts +52 -0
  204. package/types/commands/cloudrun/base.d.ts +10 -0
  205. package/types/commands/index.d.ts +1 -0
@@ -34,20 +34,11 @@ var __metadata = (this && this.__metadata) || function (k, v) {
34
34
  var __param = (this && this.__param) || function (paramIndex, decorator) {
35
35
  return function (target, key) { decorator(target, key, paramIndex); }
36
36
  };
37
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
38
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
39
- return new (P || (P = Promise))(function (resolve, reject) {
40
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
41
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
42
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
43
- step((generator = generator.apply(thisArg, _arguments || [])).next());
44
- });
45
- };
46
37
  var __importDefault = (this && this.__importDefault) || function (mod) {
47
38
  return (mod && mod.__esModule) ? mod : { "default": mod };
48
39
  };
49
40
  Object.defineProperty(exports, "__esModule", { value: true });
50
- exports.CloudRunRunCommand = exports.CloudRunDeployCommand = exports.CloudRunDeleteCommand = exports.CloudRunDownloadCommand = exports.CloudRunListCommand = exports.CloudRunInitCommand = exports.getAgentService = exports.getCloudrunService = void 0;
41
+ exports.CloudRunRunCommand = exports.CloudRunDeployCommand = exports.CloudRunDeleteCommand = exports.CloudRunDownloadCommand = exports.CloudRunListCommand = exports.CloudRunInitCommand = exports.cloudRunDeploy = exports.getAgentService = exports.getCloudrunService = void 0;
51
42
  const functions_framework_1 = require("@cloudbase/functions-framework");
52
43
  const iac_core_1 = require("@cloudbase/iac-core");
53
44
  const manager_node_1 = __importDefault(require("@cloudbase/manager-node"));
@@ -61,7 +52,7 @@ const inquirer_1 = __importDefault(require("inquirer"));
61
52
  const nodemon = (() => { try {
62
53
  return require('nodemon');
63
54
  }
64
- catch (_a) {
55
+ catch {
65
56
  return null;
66
57
  } })();
67
58
  const open_1 = __importDefault(require("open"));
@@ -84,38 +75,112 @@ const ResourceTitle = {
84
75
  container: (0, i18n_1.t)('容器型云托管'),
85
76
  function: (0, i18n_1.t)('函数型云托管')
86
77
  };
87
- function getCloudrunService(envId) {
88
- return __awaiter(this, void 0, void 0, function* () {
89
- const region = yield (0, toolbox_1.getRegion)();
90
- const { secretId, secretKey, token } = yield (0, utils_1.checkAndGetCredential)(true);
91
- const app = new manager_node_1.default({
92
- region,
93
- token,
94
- envId,
95
- secretId,
96
- secretKey,
97
- proxy: (0, utils_1.getProxy)()
98
- });
99
- return app.cloudrun;
78
+ async function getCloudrunService(envId) {
79
+ const region = await (0, toolbox_1.getRegion)();
80
+ const { secretId, secretKey, token } = await (0, utils_1.checkAndGetCredential)(true);
81
+ const app = new manager_node_1.default({
82
+ region,
83
+ token,
84
+ envId,
85
+ secretId,
86
+ secretKey,
87
+ proxy: (0, utils_1.getProxy)()
100
88
  });
89
+ return app.cloudrun;
101
90
  }
102
91
  exports.getCloudrunService = getCloudrunService;
103
- function getAgentService(envId) {
104
- return __awaiter(this, void 0, void 0, function* () {
105
- const region = yield (0, toolbox_1.getRegion)();
106
- const { secretId, secretKey, token } = yield (0, utils_1.checkAndGetCredential)(true);
107
- const app = new manager_node_1.default({
108
- region,
109
- token,
110
- envId,
111
- secretId,
112
- secretKey,
113
- proxy: (0, utils_1.getProxy)()
114
- });
115
- return app.agent;
92
+ async function getAgentService(envId) {
93
+ const region = await (0, toolbox_1.getRegion)();
94
+ const { secretId, secretKey, token } = await (0, utils_1.checkAndGetCredential)(true);
95
+ const app = new manager_node_1.default({
96
+ region,
97
+ token,
98
+ envId,
99
+ secretId,
100
+ secretKey,
101
+ proxy: (0, utils_1.getProxy)()
116
102
  });
103
+ return app.agent;
117
104
  }
118
105
  exports.getAgentService = getAgentService;
106
+ async function cloudRunDeploy(deployOptions) {
107
+ const { envId, serviceName, targetDir, serverType, port, installDependency, log } = deployOptions;
108
+ try {
109
+ const cloudrunService = await getCloudrunService(envId);
110
+ utils_2.trackCallback === null || utils_2.trackCallback === void 0 ? void 0 : (0, utils_2.trackCallback)({
111
+ details: (0, i18n_1.t)('正在提交{{serverType}} {{serviceName}} 中,请稍候...', { serverType: ResourceTitle[serverType], serviceName }),
112
+ status: 'progress'
113
+ }, log);
114
+ await cloudrunService.deploy({
115
+ serverName: serviceName,
116
+ targetPath: targetDir,
117
+ serverConfig: {
118
+ ...(port ? { Port: Number(port) } : {}),
119
+ InstallDependency: installDependency !== 'false'
120
+ }
121
+ });
122
+ utils_2.trackCallback === null || utils_2.trackCallback === void 0 ? void 0 : (0, utils_2.trackCallback)({
123
+ details: (0, i18n_1.t)('提交{{serverType}} {{serviceName}} 已完成!', { serverType: ResourceTitle[serverType], serviceName }),
124
+ status: 'done'
125
+ }, log);
126
+ await (0, utils_2.upsertCloudbaserc)(targetDir, {
127
+ envId,
128
+ cloudrun: { name: serviceName }
129
+ });
130
+ (0, utils_2.trackCallback)({
131
+ details: (0, i18n_1.t)('请打开链接查看部署状态: {{url}}', { url: `${utils_1.EUrl.DevPlatform}?envId=${envId}#/platform-run/service/detail?serverName=${serviceName}&tabId=deploy&envId=${envId}` })
132
+ }, log);
133
+ }
134
+ catch (e) {
135
+ if ((e === null || e === void 0 ? void 0 : e.action) === 'UpdateCloudRunServer' && (e === null || e === void 0 ? void 0 : e.code) === 'ResourceInUse') {
136
+ inquirer_1.default
137
+ .prompt([
138
+ {
139
+ type: 'confirm',
140
+ name: 'confirm',
141
+ message: (0, i18n_1.t)('平台当前有部署发布任务正在运行中。确认继续部署,正在执行的部署任务将被取消,并立即部署最新的代码'),
142
+ default: true
143
+ }
144
+ ])
145
+ .then(async (answers) => {
146
+ if (answers.confirm) {
147
+ try {
148
+ const { task } = await CloudAPI.tcbrServiceRequest('DescribeServerManageTask', {
149
+ envId,
150
+ serverName: serviceName,
151
+ taskId: 0
152
+ });
153
+ const id = task === null || task === void 0 ? void 0 : task.id;
154
+ await CloudAPI.tcbrServiceRequest('OperateServerManage', {
155
+ envId,
156
+ operateType: 'cancel',
157
+ serverName: serviceName,
158
+ taskId: id
159
+ });
160
+ await cloudRunDeploy(deployOptions);
161
+ }
162
+ catch (e) {
163
+ const error = e instanceof Error ? e : new Error(String(e));
164
+ (0, utils_2.trackCallback)({
165
+ type: 'error',
166
+ details: error.message,
167
+ originalError: error
168
+ }, log);
169
+ }
170
+ }
171
+ });
172
+ }
173
+ else {
174
+ (0, utils_2.trackCallback)({
175
+ type: 'error',
176
+ details: `${e.message}`,
177
+ originalError: e
178
+ }, log);
179
+ throw e;
180
+ }
181
+ }
182
+ }
183
+ exports.cloudRunDeploy = cloudRunDeploy;
119
184
  let CloudRunInitCommand = class CloudRunInitCommand extends common_1.Command {
120
185
  get options() {
121
186
  return {
@@ -144,55 +209,53 @@ let CloudRunInitCommand = class CloudRunInitCommand extends common_1.Command {
144
209
  desc: (0, i18n_1.t)('初始化云托管服务代码项目')
145
210
  };
146
211
  }
147
- execute(ctx, envId, log, options) {
148
- return __awaiter(this, void 0, void 0, function* () {
149
- let { serviceName, targetPath, template } = options;
150
- const targetDir = path_1.default.resolve(targetPath || process.cwd());
151
- if (!envId) {
152
- envId = yield _selectEnv();
153
- }
154
- const cloudrunService = yield getCloudrunService(envId);
155
- if (!serviceName) {
156
- serviceName = yield _inputServiceName();
157
- }
158
- if (!template) {
159
- const templates = yield cloudrunService.getTemplates();
160
- const { templateId } = yield inquirer_1.default.prompt([
161
- {
162
- type: 'list',
163
- name: 'templateId',
164
- message: (0, i18n_1.t)('请选择模板'),
165
- choices: templates.map((t) => ({
166
- name: `${t.title}(${t.identifier})`,
167
- value: t.identifier
168
- }))
169
- }
170
- ]);
171
- template = templateId;
172
- }
173
- const spinner = (0, ora_1.default)({
174
- text: (0, i18n_1.t)('正在初始化项目代码...'),
175
- color: 'blue'
176
- }).start();
177
- try {
178
- const { projectDir } = yield cloudrunService.init({
179
- serverName: serviceName,
180
- template,
181
- targetPath: targetDir
182
- });
183
- yield (0, utils_2.upsertCloudbaserc)(path_1.default.resolve(targetDir, serviceName), {
184
- envId,
185
- cloudrun: { name: serviceName }
186
- });
187
- spinner.succeed((0, i18n_1.t)('项目初始化成功'));
188
- console.log(chalk_1.default.green((0, i18n_1.t)('项目路径:{{projectDir}}', { projectDir })));
189
- }
190
- catch (e) {
191
- spinner.fail((0, i18n_1.t)('项目初始化失败'));
192
- const error = e instanceof Error ? e : new Error(String(e));
193
- log.error(error.message);
194
- }
195
- });
212
+ async execute(ctx, envId, log, options) {
213
+ let { serviceName, targetPath, template } = options;
214
+ const targetDir = path_1.default.resolve(targetPath || process.cwd());
215
+ if (!envId) {
216
+ envId = await _selectEnv();
217
+ }
218
+ const cloudrunService = await getCloudrunService(envId);
219
+ if (!serviceName) {
220
+ serviceName = await _inputServiceName();
221
+ }
222
+ if (!template) {
223
+ const templates = await cloudrunService.getTemplates();
224
+ const { templateId } = await inquirer_1.default.prompt([
225
+ {
226
+ type: 'list',
227
+ name: 'templateId',
228
+ message: (0, i18n_1.t)('请选择模板'),
229
+ choices: templates.map((t) => ({
230
+ name: `${t.title}(${t.identifier})`,
231
+ value: t.identifier
232
+ }))
233
+ }
234
+ ]);
235
+ template = templateId;
236
+ }
237
+ const spinner = (0, ora_1.default)({
238
+ text: (0, i18n_1.t)('正在初始化项目代码...'),
239
+ color: 'blue'
240
+ }).start();
241
+ try {
242
+ const { projectDir } = await cloudrunService.init({
243
+ serverName: serviceName,
244
+ template,
245
+ targetPath: targetDir
246
+ });
247
+ await (0, utils_2.upsertCloudbaserc)(path_1.default.resolve(targetDir, serviceName), {
248
+ envId,
249
+ cloudrun: { name: serviceName }
250
+ });
251
+ spinner.succeed((0, i18n_1.t)('项目初始化成功'));
252
+ console.log(chalk_1.default.green((0, i18n_1.t)('项目路径:{{projectDir}}', { projectDir })));
253
+ }
254
+ catch (e) {
255
+ spinner.fail((0, i18n_1.t)('项目初始化失败'));
256
+ const error = e instanceof Error ? e : new Error(String(e));
257
+ log.error(error.message);
258
+ }
196
259
  }
197
260
  };
198
261
  __decorate([
@@ -244,44 +307,42 @@ let CloudRunListCommand = class CloudRunListCommand extends common_1.Command {
244
307
  desc: (0, i18n_1.t)('查看云托管服务列表')
245
308
  };
246
309
  }
247
- execute(ctx, envId, log, options) {
248
- return __awaiter(this, void 0, void 0, function* () {
249
- const { pageSize, pageNum, serviceName, serverType } = options;
250
- if (!envId) {
251
- envId = yield _selectEnv();
252
- }
253
- log.info((0, i18n_1.t)('当前环境:{{envId}}', { envId }));
254
- const cloudrunService = yield getCloudrunService(envId);
255
- const services = yield cloudrunService.list({
256
- pageSize: parseInt(pageSize),
257
- pageNum: parseInt(pageNum),
258
- serverName: serviceName,
259
- serverType: serverType
260
- });
261
- const table = new cli_table3_1.default({
262
- head: [(0, i18n_1.t)('服务名称'), (0, i18n_1.t)('类型'), (0, i18n_1.t)('更新时间'), (0, i18n_1.t)('运行状态'), (0, i18n_1.t)('公网访问')],
263
- style: {
264
- head: ['green']
265
- }
266
- });
267
- const serverTypeTitleMap = {
268
- function: (0, i18n_1.t)('函数型服务'),
269
- container: (0, i18n_1.t)('容器型服务')
270
- };
271
- services.ServerList.forEach((service) => {
272
- table.push([
273
- service.ServerName,
274
- serverTypeTitleMap[service.ServerType] || service.ServerType,
275
- service.UpdateTime,
276
- service.Status,
277
- isPublicAccessOpen(service.AccessTypes) ? (0, i18n_1.t)('允许') : (0, i18n_1.t)('不允许')
278
- ]);
279
- });
280
- console.log(table.toString());
281
- function isPublicAccessOpen(accessTypes) {
282
- return (accessTypes === null || accessTypes === void 0 ? void 0 : accessTypes.includes(AccessType.PUBLIC)) || false;
310
+ async execute(ctx, envId, log, options) {
311
+ const { pageSize, pageNum, serviceName, serverType } = options;
312
+ if (!envId) {
313
+ envId = await _selectEnv();
314
+ }
315
+ log.info((0, i18n_1.t)('当前环境:{{envId}}', { envId }));
316
+ const cloudrunService = await getCloudrunService(envId);
317
+ const services = await cloudrunService.list({
318
+ pageSize: parseInt(pageSize),
319
+ pageNum: parseInt(pageNum),
320
+ serverName: serviceName,
321
+ serverType: serverType
322
+ });
323
+ const table = new cli_table3_1.default({
324
+ head: [(0, i18n_1.t)('服务名称'), (0, i18n_1.t)('类型'), (0, i18n_1.t)('更新时间'), (0, i18n_1.t)('运行状态'), (0, i18n_1.t)('公网访问')],
325
+ style: {
326
+ head: ['green']
283
327
  }
284
328
  });
329
+ const serverTypeTitleMap = {
330
+ function: (0, i18n_1.t)('函数型服务'),
331
+ container: (0, i18n_1.t)('容器型服务')
332
+ };
333
+ services.ServerList.forEach((service) => {
334
+ table.push([
335
+ service.ServerName,
336
+ serverTypeTitleMap[service.ServerType] || service.ServerType,
337
+ service.UpdateTime,
338
+ service.Status,
339
+ isPublicAccessOpen(service.AccessTypes) ? (0, i18n_1.t)('允许') : (0, i18n_1.t)('不允许')
340
+ ]);
341
+ });
342
+ console.log(table.toString());
343
+ function isPublicAccessOpen(accessTypes) {
344
+ return (accessTypes === null || accessTypes === void 0 ? void 0 : accessTypes.includes(AccessType.PUBLIC)) || false;
345
+ }
285
346
  }
286
347
  };
287
348
  __decorate([
@@ -329,75 +390,73 @@ let CloudRunDownloadCommand = class CloudRunDownloadCommand extends common_1.Com
329
390
  desc: (0, i18n_1.t)('下载云托管服务代码')
330
391
  };
331
392
  }
332
- execute(ctx, envId, log, options) {
393
+ async execute(ctx, envId, log, options) {
333
394
  var _a;
334
- return __awaiter(this, void 0, void 0, function* () {
335
- let { serviceName, targetPath, force } = options;
336
- let targetDir = path_1.default.resolve(targetPath || process.cwd());
337
- if (!envId) {
338
- envId = yield _selectEnv();
339
- }
340
- log.info((0, i18n_1.t)('当前环境:{{envId}}', { envId }));
341
- const cloudrunService = yield getCloudrunService(envId);
342
- const maybeInProject = yield fs_extra_1.default.pathExists(path_1.default.join(targetDir, 'README.md'));
343
- if (!serviceName) {
344
- let defaultName = '';
345
- if (maybeInProject) {
346
- const config = yield (0, utils_2.getCloudbaserc)(targetDir);
347
- if ((_a = config === null || config === void 0 ? void 0 : config['cloudrun']) === null || _a === void 0 ? void 0 : _a['name']) {
348
- defaultName = config['cloudrun']['name'];
395
+ let { serviceName, targetPath, force } = options;
396
+ let targetDir = path_1.default.resolve(targetPath || process.cwd());
397
+ if (!envId) {
398
+ envId = await _selectEnv();
399
+ }
400
+ log.info((0, i18n_1.t)('当前环境:{{envId}}', { envId }));
401
+ const cloudrunService = await getCloudrunService(envId);
402
+ const maybeInProject = await fs_extra_1.default.pathExists(path_1.default.join(targetDir, 'README.md'));
403
+ if (!serviceName) {
404
+ let defaultName = '';
405
+ if (maybeInProject) {
406
+ const config = await (0, utils_2.getCloudbaserc)(targetDir);
407
+ if ((_a = config === null || config === void 0 ? void 0 : config['cloudrun']) === null || _a === void 0 ? void 0 : _a['name']) {
408
+ defaultName = config['cloudrun']['name'];
409
+ }
410
+ else {
411
+ const { shortName } = await (0, utils_2.getPackageJsonName)(path_1.default.join(targetDir, 'package.json'));
412
+ if (shortName) {
413
+ defaultName = shortName;
349
414
  }
350
415
  else {
351
- const { shortName } = yield (0, utils_2.getPackageJsonName)(path_1.default.join(targetDir, 'package.json'));
352
- if (shortName) {
353
- defaultName = shortName;
354
- }
355
- else {
356
- defaultName = path_1.default.basename(targetDir);
357
- }
416
+ defaultName = path_1.default.basename(targetDir);
358
417
  }
359
418
  }
360
- serviceName = yield _inputServiceName(defaultName);
361
419
  }
362
- if (!targetPath) {
363
- targetPath = yield _inputTargetPath(maybeInProject ? targetDir : path_1.default.resolve(targetDir, serviceName));
364
- targetDir = path_1.default.resolve(targetPath);
365
- }
366
- const needTips = !force && !(yield (0, utils_2.isDirectoryEmptyOrNotExists)(targetDir));
367
- if (needTips) {
368
- const answers = yield inquirer_1.default.prompt([
369
- {
370
- type: 'confirm',
371
- name: 'confirm',
372
- message: (0, i18n_1.t)('下载将覆盖 {{targetDir}} 目录下的代码,是否继续?', { targetDir }),
373
- default: true
374
- }
375
- ]);
376
- if (!answers.confirm) {
377
- log.info((0, i18n_1.t)('用户已取消下载操作'));
378
- return;
420
+ serviceName = await _inputServiceName(defaultName);
421
+ }
422
+ if (!targetPath) {
423
+ targetPath = await _inputTargetPath(maybeInProject ? targetDir : path_1.default.resolve(targetDir, serviceName));
424
+ targetDir = path_1.default.resolve(targetPath);
425
+ }
426
+ const needTips = !force && !(await (0, utils_2.isDirectoryEmptyOrNotExists)(targetDir));
427
+ if (needTips) {
428
+ const answers = await inquirer_1.default.prompt([
429
+ {
430
+ type: 'confirm',
431
+ name: 'confirm',
432
+ message: (0, i18n_1.t)('下载将覆盖 {{targetDir}} 目录下的代码,是否继续?', { targetDir }),
433
+ default: true
379
434
  }
435
+ ]);
436
+ if (!answers.confirm) {
437
+ log.info((0, i18n_1.t)('用户已取消下载操作'));
438
+ return;
380
439
  }
381
- try {
382
- yield cloudrunService.download({
383
- serverName: serviceName,
384
- targetPath: targetDir
385
- });
386
- yield (0, utils_2.upsertCloudbaserc)(targetDir, {
387
- envId,
388
- cloudrun: { name: serviceName }
389
- });
390
- log.success((0, i18n_1.t)('云托管服务 {{serviceName}} 代码已成功下载到: {{targetDir}}', { serviceName, targetDir }));
391
- }
392
- catch (e) {
393
- const error = e instanceof Error ? e : new Error(String(e));
394
- (0, utils_2.trackCallback)({
395
- type: 'error',
396
- details: error.message,
397
- originalError: error
398
- }, log);
399
- }
400
- });
440
+ }
441
+ try {
442
+ await cloudrunService.download({
443
+ serverName: serviceName,
444
+ targetPath: targetDir
445
+ });
446
+ await (0, utils_2.upsertCloudbaserc)(targetDir, {
447
+ envId,
448
+ cloudrun: { name: serviceName }
449
+ });
450
+ log.success((0, i18n_1.t)('云托管服务 {{serviceName}} 代码已成功下载到: {{targetDir}}', { serviceName, targetDir }));
451
+ }
452
+ catch (e) {
453
+ const error = e instanceof Error ? e : new Error(String(e));
454
+ (0, utils_2.trackCallback)({
455
+ type: 'error',
456
+ details: error.message,
457
+ originalError: error
458
+ }, log);
459
+ }
401
460
  }
402
461
  };
403
462
  __decorate([
@@ -440,52 +499,50 @@ let CloudRunDeleteCommand = class CloudRunDeleteCommand extends common_1.Command
440
499
  desc: (0, i18n_1.t)('删除云托管服务')
441
500
  };
442
501
  }
443
- execute(ctx, envId, log, options) {
502
+ async execute(ctx, envId, log, options) {
444
503
  var _a;
445
- return __awaiter(this, void 0, void 0, function* () {
446
- let { serviceName, force } = options;
447
- if (!envId) {
448
- envId = yield _selectEnv();
449
- }
450
- log.info((0, i18n_1.t)('当前环境:{{envId}}', { envId }));
451
- const cloudrunService = yield getCloudrunService(envId);
452
- if (!serviceName) {
453
- const config = yield (0, utils_2.getCloudbaserc)(process.cwd());
454
- let detaultName = '';
455
- if ((_a = config === null || config === void 0 ? void 0 : config['cloudrun']) === null || _a === void 0 ? void 0 : _a['name']) {
456
- detaultName = config['cloudrun']['name'];
457
- }
458
- serviceName = yield _inputServiceName(detaultName);
459
- }
460
- if (!force) {
461
- const answers = yield inquirer_1.default.prompt([
462
- {
463
- type: 'confirm',
464
- name: 'confirm',
465
- message: (0, i18n_1.t)('确定要删除云托管服务 {{serviceName}} 吗?', { serviceName }),
466
- default: false
467
- }
468
- ]);
469
- if (!answers.confirm) {
470
- log.info((0, i18n_1.t)('已取消删除操作'));
471
- return;
504
+ let { serviceName, force } = options;
505
+ if (!envId) {
506
+ envId = await _selectEnv();
507
+ }
508
+ log.info((0, i18n_1.t)('当前环境:{{envId}}', { envId }));
509
+ const cloudrunService = await getCloudrunService(envId);
510
+ if (!serviceName) {
511
+ const config = await (0, utils_2.getCloudbaserc)(process.cwd());
512
+ let detaultName = '';
513
+ if ((_a = config === null || config === void 0 ? void 0 : config['cloudrun']) === null || _a === void 0 ? void 0 : _a['name']) {
514
+ detaultName = config['cloudrun']['name'];
515
+ }
516
+ serviceName = await _inputServiceName(detaultName);
517
+ }
518
+ if (!force) {
519
+ const answers = await inquirer_1.default.prompt([
520
+ {
521
+ type: 'confirm',
522
+ name: 'confirm',
523
+ message: (0, i18n_1.t)('确定要删除云托管服务 {{serviceName}} 吗?', { serviceName }),
524
+ default: false
472
525
  }
526
+ ]);
527
+ if (!answers.confirm) {
528
+ log.info((0, i18n_1.t)('已取消删除操作'));
529
+ return;
473
530
  }
474
- try {
475
- yield cloudrunService.delete({
476
- serverName: serviceName
477
- });
478
- log.success((0, i18n_1.t)('云托管服务 {{serviceName}} 删除成功', { serviceName }));
479
- }
480
- catch (e) {
481
- const error = e instanceof Error ? e : new Error(String(e));
482
- (0, utils_2.trackCallback)({
483
- type: 'error',
484
- details: error.message,
485
- originalError: error
486
- }, log);
487
- }
488
- });
531
+ }
532
+ try {
533
+ await cloudrunService.delete({
534
+ serverName: serviceName
535
+ });
536
+ log.success((0, i18n_1.t)('云托管服务 {{serviceName}} 删除成功', { serviceName }));
537
+ }
538
+ catch (e) {
539
+ const error = e instanceof Error ? e : new Error(String(e));
540
+ (0, utils_2.trackCallback)({
541
+ type: 'error',
542
+ details: error.message,
543
+ originalError: error
544
+ }, log);
545
+ }
489
546
  }
490
547
  };
491
548
  __decorate([
@@ -544,191 +601,123 @@ let CloudRunDeployCommand = class CloudRunDeployCommand extends common_1.Command
544
601
  desc: (0, i18n_1.t)('部署云托管服务')
545
602
  };
546
603
  }
547
- execute(ctx, envId, log, options) {
604
+ async execute(ctx, envId, log, options) {
548
605
  var _a, _b;
549
- return __awaiter(this, void 0, void 0, function* () {
550
- let { serviceName, source, force, port, createAgent, installDependency = true } = options;
551
- const targetDir = path_1.default.resolve(source || process.cwd());
552
- if (!envId) {
553
- const envConfig = (0, camelcase_keys_1.default)(yield iac_core_1.utils.loadEnv(targetDir));
554
- if (envConfig === null || envConfig === void 0 ? void 0 : envConfig.envId) {
555
- envId = envConfig.envId;
556
- }
557
- else {
558
- envId = yield _selectEnv();
559
- }
606
+ let { serviceName, source, force, port, createAgent, installDependency = 'true' } = options;
607
+ const targetDir = path_1.default.resolve(source || process.cwd());
608
+ if (!envId) {
609
+ const envConfig = (0, camelcase_keys_1.default)(await iac_core_1.utils.loadEnv(targetDir));
610
+ if (envConfig === null || envConfig === void 0 ? void 0 : envConfig.envId) {
611
+ envId = envConfig.envId;
560
612
  }
561
- log.info((0, i18n_1.t)('当前环境 Id:{{envId}}', { envId }));
562
- if (createAgent) {
563
- const questions = [
564
- {
565
- type: 'input',
566
- name: 'Name',
567
- message: (0, i18n_1.t)('请输入函数式 Agent 名称:'),
568
- validate: (input) => {
569
- if (!input.trim()) {
570
- return (0, i18n_1.t)('名称不能为空');
571
- }
572
- return true;
573
- }
574
- },
575
- {
576
- type: 'input',
577
- name: 'BotId',
578
- message: (0, i18n_1.t)('请输入括号内的标识 ibot-(服务名-BotTag)。示例:agent-chat:'),
579
- validate: (input) => {
580
- if (!/^[a-z0-9_]+-[a-z0-9_]+$/.test(input)) {
581
- return (0, i18n_1.t)('标识格式错误,应为"xxx-xxx"');
582
- }
583
- return true;
613
+ else {
614
+ envId = await _selectEnv();
615
+ }
616
+ }
617
+ log.info((0, i18n_1.t)('当前环境 Id:{{envId}}', { envId }));
618
+ if (createAgent) {
619
+ const questions = [
620
+ {
621
+ type: 'input',
622
+ name: 'Name',
623
+ message: (0, i18n_1.t)('请输入函数式 Agent 名称:'),
624
+ validate: (input) => {
625
+ if (!input.trim()) {
626
+ return (0, i18n_1.t)('名称不能为空');
584
627
  }
628
+ return true;
585
629
  }
586
- ];
587
- const { Name, BotId } = yield inquirer_1.default.prompt(questions);
588
- const botId = `ibot-${BotId}`;
589
- const agentService = yield getAgentService(envId);
590
- yield agentService.createFunctionAgent(source, {
591
- Name: Name,
592
- BotId: botId
593
- });
594
- (0, utils_2.trackCallback)({
595
- details: (0, i18n_1.t)('请打开链接查看部署状态: {{url}}', { url: `${utils_1.EUrl.DevPlatform}?envId=${envId}#/ai?tab=agent&agent=${botId}` })
596
- }, log);
597
- return;
598
- }
599
- if (!serviceName) {
600
- let defaultName = '';
601
- const config = yield (0, utils_2.getCloudbaserc)(targetDir);
602
- if ((_a = config === null || config === void 0 ? void 0 : config['cloudrun']) === null || _a === void 0 ? void 0 : _a['name']) {
603
- defaultName = config['cloudrun']['name'];
604
- }
605
- else {
606
- const { shortName } = yield (0, utils_2.getPackageJsonName)(path_1.default.join(targetDir, 'package.json'));
607
- defaultName = shortName;
608
- }
609
- serviceName = yield _inputServiceName(defaultName);
610
- }
611
- const containerConfigFile = 'container.config.json';
612
- const containerConfigPath = path_1.default.join(targetDir, containerConfigFile);
613
- if (yield fs_extra_1.default.pathExists(containerConfigPath)) {
614
- log.warn((0, i18n_1.t)('CLI 中 {{containerConfigFile}} 文件将不会生效,请通过命令行参数进行配置!', { containerConfigFile }));
615
- }
616
- if (!force) {
617
- const answers = yield inquirer_1.default.prompt([
618
- {
619
- type: 'confirm',
620
- name: 'confirm',
621
- message: (0, i18n_1.t)('即将开始部署,是否确认继续?'),
622
- default: true
630
+ },
631
+ {
632
+ type: 'input',
633
+ name: 'BotId',
634
+ message: (0, i18n_1.t)('请输入括号内的标识 ibot-(服务名-BotTag)。示例:agent-chat:'),
635
+ validate: (input) => {
636
+ if (!/^[a-z0-9_]+-[a-z0-9_]+$/.test(input)) {
637
+ return (0, i18n_1.t)('标识格式错误,应为"xxx-xxx"');
638
+ }
639
+ return true;
623
640
  }
624
- ]);
625
- if (!answers.confirm) {
626
- return;
627
641
  }
628
- }
629
- yield iac_core_1.IAC.init({
630
- cwd: targetDir,
631
- getCredential: () => {
632
- return (0, utils_2.getCredential)(ctx, options);
633
- },
634
- polyRepoMode: true
642
+ ];
643
+ const { Name, BotId } = await inquirer_1.default.prompt(questions);
644
+ const botId = `ibot-${BotId}`;
645
+ const agentService = await getAgentService(envId);
646
+ await agentService.createFunctionAgent(source, {
647
+ Name: Name,
648
+ BotId: botId
635
649
  });
636
- const cloudrunService = yield getCloudrunService(envId);
637
- let serverType;
638
- try {
639
- const details = yield cloudrunService.detail({ serverName: serviceName });
640
- serverType = (_b = details.BaseInfo) === null || _b === void 0 ? void 0 : _b.ServerType;
650
+ (0, utils_2.trackCallback)({
651
+ details: (0, i18n_1.t)('请打开链接查看部署状态: {{url}}', { url: `${utils_1.EUrl.DevPlatform}?envId=${envId}#/ai?tab=agent&agent=${botId}` })
652
+ }, log);
653
+ return;
654
+ }
655
+ if (!serviceName) {
656
+ let defaultName = '';
657
+ const config = await (0, utils_2.getCloudbaserc)(targetDir);
658
+ if ((_a = config === null || config === void 0 ? void 0 : config['cloudrun']) === null || _a === void 0 ? void 0 : _a['name']) {
659
+ defaultName = config['cloudrun']['name'];
641
660
  }
642
- catch (e) {
643
- const dockerfilePath = path_1.default.join(targetDir, 'Dockerfile');
644
- if (yield fs_extra_1.default.pathExists(dockerfilePath)) {
645
- serverType = 'container';
646
- }
647
- else {
648
- serverType = 'function';
661
+ else {
662
+ const { shortName } = await (0, utils_2.getPackageJsonName)(path_1.default.join(targetDir, 'package.json'));
663
+ defaultName = shortName;
664
+ }
665
+ serviceName = await _inputServiceName(defaultName);
666
+ }
667
+ const containerConfigFile = 'container.config.json';
668
+ const containerConfigPath = path_1.default.join(targetDir, containerConfigFile);
669
+ if (await fs_extra_1.default.pathExists(containerConfigPath)) {
670
+ log.warn((0, i18n_1.t)('CLI 中 {{containerConfigFile}} 文件将不会生效,请通过命令行参数进行配置!', { containerConfigFile }));
671
+ }
672
+ if (!force) {
673
+ const answers = await inquirer_1.default.prompt([
674
+ {
675
+ type: 'confirm',
676
+ name: 'confirm',
677
+ message: (0, i18n_1.t)('即将开始部署,是否确认继续?'),
678
+ default: true
649
679
  }
680
+ ]);
681
+ if (!answers.confirm) {
682
+ return;
650
683
  }
651
- if (!serverType) {
652
- throw new Error((0, i18n_1.t)('无法判断云托管服务类型'));
653
- }
654
- if (!['container', 'function'].includes(serverType)) {
655
- throw new Error((0, i18n_1.t)('不支持的云托管服务类型:{{serverType}}', { serverType }));
656
- }
657
- yield _runDeploy();
658
- function _runDeploy() {
659
- return __awaiter(this, void 0, void 0, function* () {
660
- try {
661
- utils_2.trackCallback === null || utils_2.trackCallback === void 0 ? void 0 : (0, utils_2.trackCallback)({
662
- details: (0, i18n_1.t)('正在提交{{serverType}} {{serviceName}} 中,请稍候...', { serverType: ResourceTitle[serverType], serviceName }),
663
- status: 'progress'
664
- }, log);
665
- yield cloudrunService.deploy({
666
- serverName: serviceName,
667
- targetPath: targetDir,
668
- serverConfig: Object.assign(Object.assign({}, (port ? { Port: Number(port) } : {})), { InstallDependency: installDependency !== 'false' })
669
- });
670
- utils_2.trackCallback === null || utils_2.trackCallback === void 0 ? void 0 : (0, utils_2.trackCallback)({
671
- details: (0, i18n_1.t)('提交{{serverType}} {{serviceName}} 已完成!', { serverType: ResourceTitle[serverType], serviceName }),
672
- status: 'done'
673
- }, log);
674
- yield (0, utils_2.upsertCloudbaserc)(targetDir, {
675
- envId,
676
- cloudrun: { name: serviceName }
677
- });
678
- (0, utils_2.trackCallback)({
679
- details: (0, i18n_1.t)('请打开链接查看部署状态: {{url}}', { url: `${utils_1.EUrl.DevPlatform}?envId=${envId}#/platform-run/service/detail?serverName=${serviceName}&tabId=deploy&envId=${envId}` })
680
- }, log);
681
- }
682
- catch (e) {
683
- if ((e === null || e === void 0 ? void 0 : e.action) === 'UpdateCloudRunServer' && (e === null || e === void 0 ? void 0 : e.code) === 'ResourceInUse') {
684
- inquirer_1.default
685
- .prompt([
686
- {
687
- type: 'confirm',
688
- name: 'confirm',
689
- message: (0, i18n_1.t)('平台当前有部署发布任务正在运行中。确认继续部署,正在执行的部署任务将被取消,并立即部署最新的代码'),
690
- default: true
691
- }
692
- ])
693
- .then((answers) => __awaiter(this, void 0, void 0, function* () {
694
- if (answers.confirm) {
695
- try {
696
- const { task } = yield CloudAPI.tcbrServiceRequest('DescribeServerManageTask', {
697
- envId,
698
- serverName: serviceName,
699
- taskId: 0
700
- });
701
- const id = task === null || task === void 0 ? void 0 : task.id;
702
- yield CloudAPI.tcbrServiceRequest('OperateServerManage', {
703
- envId,
704
- operateType: 'cancel',
705
- serverName: serviceName,
706
- taskId: id
707
- });
708
- yield _runDeploy();
709
- }
710
- catch (e) {
711
- const error = e instanceof Error ? e : new Error(String(e));
712
- (0, utils_2.trackCallback)({
713
- type: 'error',
714
- details: error.message,
715
- originalError: error
716
- }, log);
717
- }
718
- }
719
- }));
720
- }
721
- else {
722
- (0, utils_2.trackCallback)({
723
- type: 'error',
724
- details: `${e.message}`,
725
- originalError: e
726
- }, log);
727
- throw e;
728
- }
729
- }
730
- });
684
+ }
685
+ await iac_core_1.IAC.init({
686
+ cwd: targetDir,
687
+ getCredential: () => {
688
+ return (0, utils_2.getCredential)(ctx, options);
689
+ },
690
+ polyRepoMode: true
691
+ });
692
+ const cloudrunService = await getCloudrunService(envId);
693
+ let serverType;
694
+ try {
695
+ const details = await cloudrunService.detail({ serverName: serviceName });
696
+ serverType = (_b = details.BaseInfo) === null || _b === void 0 ? void 0 : _b.ServerType;
697
+ }
698
+ catch (e) {
699
+ const dockerfilePath = path_1.default.join(targetDir, 'Dockerfile');
700
+ if (await fs_extra_1.default.pathExists(dockerfilePath)) {
701
+ serverType = 'container';
731
702
  }
703
+ else {
704
+ serverType = 'function';
705
+ }
706
+ }
707
+ if (!serverType) {
708
+ throw new Error((0, i18n_1.t)('无法判断云托管服务类型'));
709
+ }
710
+ if (!['container', 'function'].includes(serverType)) {
711
+ throw new Error((0, i18n_1.t)('不支持的云托管服务类型:{{serverType}}', { serverType }));
712
+ }
713
+ await cloudRunDeploy({
714
+ envId,
715
+ serviceName,
716
+ targetDir,
717
+ serverType,
718
+ port,
719
+ installDependency,
720
+ log
732
721
  });
733
722
  }
734
723
  };
@@ -802,173 +791,165 @@ let CloudRunRunCommand = class CloudRunRunCommand extends common_1.Command {
802
791
  desc: (0, i18n_1.t)('本地运行函数型云托管服务(不支持容器型云托管服务)')
803
792
  };
804
793
  }
805
- execute(envId, logger, ctx, options) {
806
- return __awaiter(this, void 0, void 0, function* () {
807
- debugger;
808
- let { runMode = 'normal', agentId, openDebugPanel = true } = options;
809
- const type = runMode;
810
- console.log(chalk_1.default.green((0, i18n_1.t)('当前运行模式: {{type}}', { type })));
811
- if (!process.argv.some((arg) => arg.includes('--dotEnvFilePath='))) {
812
- process.argv.push('--dotEnvFilePath=.env.local');
794
+ async execute(envId, logger, ctx, options) {
795
+ debugger;
796
+ let { runMode = 'normal', agentId, openDebugPanel = true } = options;
797
+ const type = runMode;
798
+ console.log(chalk_1.default.green((0, i18n_1.t)('当前运行模式: {{type}}', { type })));
799
+ if (!process.argv.some((arg) => arg.includes('--dotEnvFilePath='))) {
800
+ process.argv.push('--dotEnvFilePath=.env.local');
801
+ }
802
+ const args = process.argv.slice(2);
803
+ const watchFlag = ['--watch', '-w'];
804
+ const defaultIgnoreFiles = ['logs/*.*'];
805
+ if (!envId) {
806
+ const envConfig = (0, camelcase_keys_1.default)(await iac_core_1.utils.loadEnv(process.cwd()));
807
+ if (envConfig === null || envConfig === void 0 ? void 0 : envConfig.envId) {
808
+ envId = envConfig.envId;
813
809
  }
814
- const args = process.argv.slice(2);
815
- const watchFlag = ['--watch', '-w'];
816
- const defaultIgnoreFiles = ['logs/*.*'];
817
- if (!envId) {
818
- const envConfig = (0, camelcase_keys_1.default)(yield iac_core_1.utils.loadEnv(process.cwd()));
819
- if (envConfig === null || envConfig === void 0 ? void 0 : envConfig.envId) {
820
- envId = envConfig.envId;
821
- }
822
- else {
823
- envId = yield _selectEnv();
824
- }
810
+ else {
811
+ envId = await _selectEnv();
825
812
  }
826
- logger.info((0, i18n_1.t)('当前环境 Id:{{envId}}', { envId }));
827
- if (type === 'agent') {
828
- if (!agentId) {
829
- const answers = yield inquirer_1.default.prompt([
830
- {
831
- type: 'input',
832
- name: 'agentId',
833
- message: (0, i18n_1.t)('请输入 Agent ID(如没有请填写任意值):'),
834
- validate: (val) => {
835
- return val.trim() ? true : (0, i18n_1.t)('Agent ID 不能为空');
836
- }
813
+ }
814
+ logger.info((0, i18n_1.t)('当前环境 Id:{{envId}}', { envId }));
815
+ if (type === 'agent') {
816
+ if (!agentId) {
817
+ const answers = await inquirer_1.default.prompt([
818
+ {
819
+ type: 'input',
820
+ name: 'agentId',
821
+ message: (0, i18n_1.t)('请输入 Agent ID(如没有请填写任意值):'),
822
+ validate: (val) => {
823
+ return val.trim() ? true : (0, i18n_1.t)('Agent ID 不能为空');
837
824
  }
838
- ]);
839
- agentId = answers.agentId;
840
- }
841
- logger.info((0, i18n_1.t)('当前 Agent ID: {{agentId}}', { agentId }));
842
- }
843
- const credential = yield (0, utils_2.getCredential)(ctx, options);
844
- process.env.EXTENDED_CONTEXT = JSON.stringify({
845
- tmpSecret: {
846
- secretId: credential.secretId,
847
- secretKey: credential.secretKey,
848
- token: credential.token
849
- },
850
- source: 'local_dev',
851
- envId,
852
- accessToken: `Bearer ${yield (0, utils_2.fetchAccessToken)({
853
- envId,
854
- secretId: credential.secretId,
855
- secretKey: credential.secretKey,
856
- token: credential.token
857
- })}`
858
- });
859
- process.env.STATIC_SERVE_ROOT = __dirname;
860
- process.env.ENABLE_CORS = 'true';
861
- process.env.ALLOWED_ORIGINS = '*';
862
- const port = options.port || process.env.PORT || 3000;
863
- if (watchFlag.some((flag) => args.includes(flag))) {
864
- const cmd = args.filter((arg) => !watchFlag.includes(arg)).join(' ');
865
- const nodemonInstance = nodemon({
866
- script: '',
867
- exec: `${process.argv[1]} ${cmd} --envId=${envId} --runMode=${type} --agentId=${agentId}`,
868
- watchOptions: {
869
- usePolling: true,
870
- ignorePermissionErrors: true,
871
- ignored: defaultIgnoreFiles.join(','),
872
- persistent: true,
873
- interval: 500
874
- },
875
- env: {
876
- FROM_NODEMON: 'true'
877
- },
878
- ext: 'js,mjs,cjs,json,ts,yaml,yml'
879
- })
880
- .on('start', () => __awaiter(this, void 0, void 0, function* () {
881
- logger.info('Initializing server in watch mode. Changes in source files will trigger a restart.');
882
- if (!process.env.NODEMON_FIRST_START) {
883
- process.env.NODEMON_FIRST_START = 'true';
884
- this.checkAndRunTsc();
885
- this.openDebugApp(type, port, envId, agentId, openDebugPanel !== 'false');
886
825
  }
887
- }))
888
- .on('quit', (e) => {
889
- logger.info(`Nodemon quit with code ${e}.`);
890
- process.exit(0);
891
- })
892
- .on('restart', (e) => {
893
- var _a, _b;
894
- logger.info(`Server restarted due to changed files: ${(_b = (_a = e === null || e === void 0 ? void 0 : e.matched) === null || _a === void 0 ? void 0 : _a.result) === null || _b === void 0 ? void 0 : _b.join(', ')}`);
895
- })
896
- .on('log', (e) => {
897
- logger.info(`[nodemon ${e.type}] ${e.message}`);
898
- })
899
- .on('crash', () => {
900
- logger.error('Server crashed.');
901
- process.exit(1);
902
- })
903
- .on('exit', (e) => {
904
- logger.info(`Server exited with code ${e}.`);
905
- });
906
- }
907
- else {
908
- (0, functions_framework_1.runCLI)();
909
- if (!process.env.FROM_NODEMON) {
826
+ ]);
827
+ agentId = answers.agentId;
828
+ }
829
+ logger.info((0, i18n_1.t)('当前 Agent ID: {{agentId}}', { agentId }));
830
+ }
831
+ const credential = await (0, utils_2.getCredential)(ctx, options);
832
+ process.env.EXTENDED_CONTEXT = JSON.stringify({
833
+ tmpSecret: {
834
+ secretId: credential.secretId,
835
+ secretKey: credential.secretKey,
836
+ token: credential.token
837
+ },
838
+ source: 'local_dev',
839
+ envId,
840
+ accessToken: `Bearer ${await (0, utils_2.fetchAccessToken)({
841
+ envId,
842
+ secretId: credential.secretId,
843
+ secretKey: credential.secretKey,
844
+ token: credential.token
845
+ })}`
846
+ });
847
+ process.env.STATIC_SERVE_ROOT = __dirname;
848
+ process.env.ENABLE_CORS = 'true';
849
+ process.env.ALLOWED_ORIGINS = '*';
850
+ const port = options.port || process.env.PORT || 3000;
851
+ if (watchFlag.some((flag) => args.includes(flag))) {
852
+ const cmd = args.filter((arg) => !watchFlag.includes(arg)).join(' ');
853
+ const nodemonInstance = nodemon({
854
+ script: '',
855
+ exec: `${process.argv[1]} ${cmd} --envId=${envId} --runMode=${type} --agentId=${agentId}`,
856
+ watchOptions: {
857
+ usePolling: true,
858
+ ignorePermissionErrors: true,
859
+ ignored: defaultIgnoreFiles.join(','),
860
+ persistent: true,
861
+ interval: 500
862
+ },
863
+ env: {
864
+ FROM_NODEMON: 'true'
865
+ },
866
+ ext: 'js,mjs,cjs,json,ts,yaml,yml'
867
+ })
868
+ .on('start', async () => {
869
+ logger.info('Initializing server in watch mode. Changes in source files will trigger a restart.');
870
+ if (!process.env.NODEMON_FIRST_START) {
871
+ process.env.NODEMON_FIRST_START = 'true';
910
872
  this.checkAndRunTsc();
911
- if (openDebugPanel) {
912
- this.openDebugApp(type, port, envId, agentId, openDebugPanel !== 'false');
913
- }
873
+ this.openDebugApp(type, port, envId, agentId, openDebugPanel !== 'false');
874
+ }
875
+ })
876
+ .on('quit', (e) => {
877
+ logger.info(`Nodemon quit with code ${e}.`);
878
+ process.exit(0);
879
+ })
880
+ .on('restart', (e) => {
881
+ var _a, _b;
882
+ logger.info(`Server restarted due to changed files: ${(_b = (_a = e === null || e === void 0 ? void 0 : e.matched) === null || _a === void 0 ? void 0 : _a.result) === null || _b === void 0 ? void 0 : _b.join(', ')}`);
883
+ })
884
+ .on('log', (e) => {
885
+ logger.info(`[nodemon ${e.type}] ${e.message}`);
886
+ })
887
+ .on('crash', () => {
888
+ logger.error('Server crashed.');
889
+ process.exit(1);
890
+ })
891
+ .on('exit', (e) => {
892
+ logger.info(`Server exited with code ${e}.`);
893
+ });
894
+ }
895
+ else {
896
+ (0, functions_framework_1.runCLI)();
897
+ if (!process.env.FROM_NODEMON) {
898
+ this.checkAndRunTsc();
899
+ if (openDebugPanel) {
900
+ this.openDebugApp(type, port, envId, agentId, openDebugPanel !== 'false');
914
901
  }
915
902
  }
916
- });
903
+ }
917
904
  }
918
- checkAndRunTsc() {
905
+ async checkAndRunTsc() {
919
906
  var _a;
920
- return __awaiter(this, void 0, void 0, function* () {
921
- const tsConfigPath = path_1.default.join(process.cwd(), 'tsconfig.json');
922
- if (yield fs_extra_1.default.exists(tsConfigPath)) {
923
- const child = (0, execa_1.default)('npx', ['tsc', '-w'], {
924
- cwd: process.cwd(),
925
- stdio: 'pipe'
926
- });
927
- (_a = child.stderr) === null || _a === void 0 ? void 0 : _a.on('data', (data) => {
928
- console.log(data.toString());
929
- });
930
- child.on('exit', (code) => {
931
- console.log((0, i18n_1.t)('子进程退出,退出码 {{code}}', { code }));
932
- });
933
- }
934
- });
907
+ const tsConfigPath = path_1.default.join(process.cwd(), 'tsconfig.json');
908
+ if (await fs_extra_1.default.exists(tsConfigPath)) {
909
+ const child = (0, execa_1.default)('npx', ['tsc', '-w'], {
910
+ cwd: process.cwd(),
911
+ stdio: 'pipe'
912
+ });
913
+ (_a = child.stderr) === null || _a === void 0 ? void 0 : _a.on('data', (data) => {
914
+ console.log(data.toString());
915
+ });
916
+ child.on('exit', (code) => {
917
+ console.log((0, i18n_1.t)('子进程退出,退出码 {{code}}', { code }));
918
+ });
919
+ }
935
920
  }
936
- openDebugApp(type, port, envId, agentId, isOpen = true) {
937
- return __awaiter(this, void 0, void 0, function* () {
938
- let url = `http://127.0.0.1:${port}/cloudrun-run-ui/index.html?type=${type}&envId=${envId}&port=${port}`;
939
- if (type === 'agent') {
940
- url += `&agentId=${agentId}`;
941
- console.log(chalk_1.default.green((0, i18n_1.t)('点击 [{{url}}] 可以打开 Agent 调试应用', { url })));
942
- }
943
- else {
944
- console.log(chalk_1.default.green((0, i18n_1.t)('点击 [{{url}}] 可以打开函数调试面板', { url })));
945
- }
946
- if (isOpen) {
947
- yield this.waitForPort(url);
948
- (0, open_1.default)(url, { wait: false });
949
- }
950
- });
921
+ async openDebugApp(type, port, envId, agentId, isOpen = true) {
922
+ let url = `http://127.0.0.1:${port}/cloudrun-run-ui/index.html?type=${type}&envId=${envId}&port=${port}`;
923
+ if (type === 'agent') {
924
+ url += `&agentId=${agentId}`;
925
+ console.log(chalk_1.default.green((0, i18n_1.t)('点击 [{{url}}] 可以打开 Agent 调试应用', { url })));
926
+ }
927
+ else {
928
+ console.log(chalk_1.default.green((0, i18n_1.t)('点击 [{{url}}] 可以打开函数调试面板', { url })));
929
+ }
930
+ if (isOpen) {
931
+ await this.waitForPort(url);
932
+ (0, open_1.default)(url, { wait: false });
933
+ }
951
934
  }
952
- waitForPort(url, timeout = 10000) {
953
- return __awaiter(this, void 0, void 0, function* () {
954
- const startTime = Date.now();
955
- const { default: fetch } = yield Promise.resolve().then(() => __importStar(require('node-fetch')));
956
- while (Date.now() - startTime < timeout) {
957
- try {
958
- const response = yield fetch(url, {
959
- timeout: 1000,
960
- method: 'HEAD'
961
- });
962
- if (response.ok) {
963
- return;
964
- }
965
- }
966
- catch (e) {
935
+ async waitForPort(url, timeout = 10000) {
936
+ const startTime = Date.now();
937
+ const { default: fetch } = await Promise.resolve().then(() => __importStar(require('node-fetch')));
938
+ while (Date.now() - startTime < timeout) {
939
+ try {
940
+ const response = await fetch(url, {
941
+ timeout: 1000,
942
+ method: 'HEAD'
943
+ });
944
+ if (response.ok) {
945
+ return;
967
946
  }
968
- yield new Promise((resolve) => setTimeout(resolve, 500));
969
947
  }
970
- throw new Error((0, i18n_1.t)('等待服务{{url}}就绪超时', { url }));
971
- });
948
+ catch (e) {
949
+ }
950
+ await new Promise((resolve) => setTimeout(resolve, 500));
951
+ }
952
+ throw new Error((0, i18n_1.t)('等待服务{{url}}就绪超时', { url }));
972
953
  }
973
954
  };
974
955
  __decorate([
@@ -985,56 +966,50 @@ CloudRunRunCommand = __decorate([
985
966
  (0, common_1.ICommand)()
986
967
  ], CloudRunRunCommand);
987
968
  exports.CloudRunRunCommand = CloudRunRunCommand;
988
- function _selectEnv() {
989
- return __awaiter(this, void 0, void 0, function* () {
990
- return (0, utils_2.selectEnv)({ source: [constants_1.EnvSource.MINIAPP, constants_1.EnvSource.QCLOUD] });
991
- });
969
+ async function _selectEnv() {
970
+ return (0, utils_2.selectEnv)({ source: [constants_1.EnvSource.MINIAPP, constants_1.EnvSource.QCLOUD] });
992
971
  }
993
- function _inputServiceName(defaultVal = '') {
994
- return __awaiter(this, void 0, void 0, function* () {
995
- const questions = [
996
- {
997
- type: 'input',
998
- name: 'serviceName',
999
- message: (0, i18n_1.t)('请输入服务名称'),
1000
- default: defaultVal,
1001
- validate: (val) => {
1002
- const isValid = !val.startsWith('lcap') &&
1003
- !val.startsWith('lowcode') &&
1004
- /^[A-Za-z][\w-_]{0,43}[A-Za-z0-9]$/.test(val);
1005
- return isValid
1006
- ? true
1007
- : (0, i18n_1.t)('支持大小写字母、数字、-和_,但必须以字母开头、以字母和数字结尾,不支持以lcap、lowcode开头,最长45个字符');
1008
- }
1009
- }
1010
- ];
1011
- const answers = yield inquirer_1.default.prompt(questions);
1012
- return answers['serviceName'];
1013
- });
972
+ async function _inputServiceName(defaultVal = '') {
973
+ const questions = [
974
+ {
975
+ type: 'input',
976
+ name: 'serviceName',
977
+ message: (0, i18n_1.t)('请输入服务名称'),
978
+ default: defaultVal,
979
+ validate: (val) => {
980
+ const isValid = !val.startsWith('lcap') &&
981
+ !val.startsWith('lowcode') &&
982
+ /^[A-Za-z][\w-_]{0,43}[A-Za-z0-9]$/.test(val);
983
+ return isValid
984
+ ? true
985
+ : (0, i18n_1.t)('支持大小写字母、数字、-和_,但必须以字母开头、以字母和数字结尾,不支持以lcap、lowcode开头,最长45个字符');
986
+ }
987
+ }
988
+ ];
989
+ const answers = await inquirer_1.default.prompt(questions);
990
+ return answers['serviceName'];
1014
991
  }
1015
- function _inputTargetPath(defaultVal = process.cwd()) {
1016
- return __awaiter(this, void 0, void 0, function* () {
1017
- const questions = [
1018
- {
1019
- type: 'input',
1020
- name: 'targetPath',
1021
- message: (0, i18n_1.t)('请输入目标路径(目录名称或绝对路径)'),
1022
- default: defaultVal,
1023
- validate: (val) => {
1024
- try {
1025
- path_1.default.resolve(val);
1026
- return true;
1027
- }
1028
- catch (e) {
1029
- return (0, i18n_1.t)('请输入有效的路径');
1030
- }
1031
- },
1032
- filter: (val) => {
1033
- return path_1.default.normalize(val);
992
+ async function _inputTargetPath(defaultVal = process.cwd()) {
993
+ const questions = [
994
+ {
995
+ type: 'input',
996
+ name: 'targetPath',
997
+ message: (0, i18n_1.t)('请输入目标路径(目录名称或绝对路径)'),
998
+ default: defaultVal,
999
+ validate: (val) => {
1000
+ try {
1001
+ path_1.default.resolve(val);
1002
+ return true;
1034
1003
  }
1035
- }
1036
- ];
1037
- const answers = yield inquirer_1.default.prompt(questions);
1038
- return answers['targetPath'];
1039
- });
1004
+ catch (e) {
1005
+ return (0, i18n_1.t)('请输入有效的路径');
1006
+ }
1007
+ },
1008
+ filter: (val) => {
1009
+ return path_1.default.normalize(val);
1010
+ }
1011
+ }
1012
+ ];
1013
+ const answers = await inquirer_1.default.prompt(questions);
1014
+ return answers['targetPath'];
1040
1015
  }