@cloudbase/cli 2.7.7-alpha.0 → 2.7.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
@@ -47,7 +47,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
47
47
  return (mod && mod.__esModule) ? mod : { "default": mod };
48
48
  };
49
49
  Object.defineProperty(exports, "__esModule", { value: true });
50
- exports.CloudRunRunCommand = exports.CloudRunDeployCommand = exports.CloudRunDeleteCommand = exports.CloudRunDownloadCommand = exports.CloudRunListCommand = exports.CloudRunInitCommand = exports.getCloudrunService = void 0;
50
+ exports.CloudRunRunCommand = exports.CloudRunDeployCommand = exports.CloudRunDeleteCommand = exports.CloudRunDownloadCommand = exports.CloudRunListCommand = exports.CloudRunInitCommand = exports.getAgentService = exports.getCloudrunService = void 0;
51
51
  const functions_framework_1 = require("@cloudbase/functions-framework");
52
52
  const iac_core_1 = require("@cloudbase/iac-core");
53
53
  const manager_node_1 = __importDefault(require("@cloudbase/manager-node"));
@@ -55,6 +55,7 @@ const toolbox_1 = require("@cloudbase/toolbox");
55
55
  const camelcase_keys_1 = __importDefault(require("camelcase-keys"));
56
56
  const chalk_1 = __importDefault(require("chalk"));
57
57
  const cli_table3_1 = __importDefault(require("cli-table3"));
58
+ const execa_1 = __importDefault(require("execa"));
58
59
  const fs_extra_1 = __importDefault(require("fs-extra"));
59
60
  const inquirer_1 = __importDefault(require("inquirer"));
60
61
  const nodemon_1 = __importDefault(require("nodemon"));
@@ -89,6 +90,22 @@ function getCloudrunService(envId) {
89
90
  });
90
91
  }
91
92
  exports.getCloudrunService = getCloudrunService;
93
+ function getAgentService(envId) {
94
+ return __awaiter(this, void 0, void 0, function* () {
95
+ const region = yield (0, toolbox_1.getRegion)();
96
+ const { secretId, secretKey, token } = yield (0, utils_1.checkAndGetCredential)(true);
97
+ const app = new manager_node_1.default({
98
+ region,
99
+ token,
100
+ envId,
101
+ secretId,
102
+ secretKey,
103
+ proxy: (0, utils_1.getProxy)()
104
+ });
105
+ return app.agent;
106
+ });
107
+ }
108
+ exports.getAgentService = getAgentService;
92
109
  let CloudRunInitCommand = class CloudRunInitCommand extends common_1.Command {
93
110
  get options() {
94
111
  return {
@@ -282,7 +299,7 @@ let CloudRunDownloadCommand = class CloudRunDownloadCommand extends common_1.Com
282
299
  desc: '环境 ID'
283
300
  },
284
301
  {
285
- flags: '--serviceName <serviceName>',
302
+ flags: '-s, --serviceName <serviceName>',
286
303
  desc: '服务名称',
287
304
  required: true
288
305
  },
@@ -398,7 +415,7 @@ let CloudRunDeleteCommand = class CloudRunDeleteCommand extends common_1.Command
398
415
  desc: '环境 ID'
399
416
  },
400
417
  {
401
- flags: '--serviceName <serviceName>',
418
+ flags: '-s, --serviceName <serviceName>',
402
419
  desc: '服务名称',
403
420
  required: true
404
421
  },
@@ -497,6 +514,10 @@ let CloudRunDeployCommand = class CloudRunDeployCommand extends common_1.Command
497
514
  flags: '--source <source>',
498
515
  desc: '部署代码所在目录路径(绝对路径或相对路径,默认: 当前目录)'
499
516
  },
517
+ {
518
+ flags: '--createAgent',
519
+ desc: '创建函数型 Agent'
520
+ },
500
521
  {
501
522
  flags: '--force',
502
523
  desc: '强制部署,跳过所有确认提示',
@@ -511,7 +532,7 @@ let CloudRunDeployCommand = class CloudRunDeployCommand extends common_1.Command
511
532
  execute(ctx, envId, log, options) {
512
533
  var _a, _b;
513
534
  return __awaiter(this, void 0, void 0, function* () {
514
- let { serviceName, source, force, port } = options;
535
+ let { serviceName, source, force, port, createAgent } = options;
515
536
  const targetDir = path_1.default.resolve(source || process.cwd());
516
537
  if (!envId) {
517
538
  const envConfig = (0, camelcase_keys_1.default)(yield iac_core_1.utils.loadEnv(targetDir));
@@ -523,6 +544,43 @@ let CloudRunDeployCommand = class CloudRunDeployCommand extends common_1.Command
523
544
  }
524
545
  }
525
546
  log.info(`当前环境 Id:${envId}`);
547
+ if (createAgent) {
548
+ const questions = [
549
+ {
550
+ type: 'input',
551
+ name: 'Name',
552
+ message: '请输入函数式 Agent 名称:',
553
+ validate: (input) => {
554
+ if (!input.trim()) {
555
+ return '名称不能为空';
556
+ }
557
+ return true;
558
+ }
559
+ },
560
+ {
561
+ type: 'input',
562
+ name: 'BotId',
563
+ message: '请输入括号内的标识 ibot-(服务名-BotTag)。示例:agent-chat:',
564
+ validate: (input) => {
565
+ if (!/^[a-z0-9_]+-[a-z0-9_]+$/.test(input)) {
566
+ return '标识格式错误,应为"xxx-xxx"';
567
+ }
568
+ return true;
569
+ }
570
+ }
571
+ ];
572
+ const { Name, BotId } = yield inquirer_1.default.prompt(questions);
573
+ const botId = `ibot-${BotId}`;
574
+ const agentService = yield getAgentService(envId);
575
+ yield agentService.createFunctionAgent(source, {
576
+ Name: Name,
577
+ BotId: botId
578
+ });
579
+ (0, utils_2.trackCallback)({
580
+ details: `请打开链接查看部署状态: https://tcb.cloud.tencent.com/dev?envId=${envId}#/ai?tab=agent&agent=${botId}`
581
+ }, log);
582
+ return;
583
+ }
526
584
  if (!serviceName) {
527
585
  let defaultName = '';
528
586
  const config = yield (0, utils_2.getCloudbaserc)(targetDir);
@@ -816,6 +874,7 @@ let CloudRunRunCommand = class CloudRunRunCommand extends common_1.Command {
816
874
  logger.info('Initializing server in watch mode. Changes in source files will trigger a restart.');
817
875
  if (!nodemonInstance._firstStartDone) {
818
876
  nodemonInstance._firstStartDone = true;
877
+ this.checkAndRunTsc();
819
878
  this.openDebugApp(type, port, envId, agentId, openDebugPanel !== 'false');
820
879
  }
821
880
  }))
@@ -840,12 +899,33 @@ let CloudRunRunCommand = class CloudRunRunCommand extends common_1.Command {
840
899
  }
841
900
  else {
842
901
  (0, functions_framework_1.runCLI)();
843
- if (!process.env.FROM_NODEMON && openDebugPanel) {
844
- this.openDebugApp(type, port, envId, agentId, openDebugPanel !== 'false');
902
+ if (!process.env.FROM_NODEMON) {
903
+ this.checkAndRunTsc();
904
+ if (openDebugPanel) {
905
+ this.openDebugApp(type, port, envId, agentId, openDebugPanel !== 'false');
906
+ }
845
907
  }
846
908
  }
847
909
  });
848
910
  }
911
+ checkAndRunTsc() {
912
+ var _a;
913
+ return __awaiter(this, void 0, void 0, function* () {
914
+ const tsConfigPath = path_1.default.join(process.cwd(), 'tsconfig.json');
915
+ if (yield fs_extra_1.default.exists(tsConfigPath)) {
916
+ const child = (0, execa_1.default)('npx', ['tsc', '-w'], {
917
+ cwd: process.cwd(),
918
+ stdio: 'pipe'
919
+ });
920
+ (_a = child.stderr) === null || _a === void 0 ? void 0 : _a.on('data', (data) => {
921
+ console.log(data.toString());
922
+ });
923
+ child.on('exit', (code) => {
924
+ console.log(`子进程退出,退出码 ${code}`);
925
+ });
926
+ }
927
+ });
928
+ }
849
929
  openDebugApp(type, port, envId, agentId, isOpen = true) {
850
930
  return __awaiter(this, void 0, void 0, function* () {
851
931
  let url = `http://127.0.0.1:${port}/cloudrun-run-ui/index.html?type=${type}&envId=${envId}&port=${port}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/cli",
3
- "version": "2.7.7-alpha.0",
3
+ "version": "2.7.8",
4
4
  "description": "cli tool for cloudbase",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -36,7 +36,7 @@
36
36
  "@cloudbase/functions-framework": "1.16.0",
37
37
  "@cloudbase/iac-core": "0.0.3-alpha.11",
38
38
  "@cloudbase/lowcode-cli": "^0.22.2",
39
- "@cloudbase/manager-node": "4.3.2",
39
+ "@cloudbase/manager-node": "4.3.3",
40
40
  "@cloudbase/toolbox": "^0.7.5",
41
41
  "address": "^1.1.2",
42
42
  "camelcase-keys": "^7.0.2",
@@ -1,6 +1,7 @@
1
1
  import { Logger } from '../../decorators';
2
2
  import { Command } from '../common';
3
3
  export declare function getCloudrunService(envId: string): Promise<import("@cloudbase/manager-node/types/cloudrun").CloudRunService>;
4
+ export declare function getAgentService(envId: string): Promise<import("@cloudbase/manager-node/types/agent").AgentService>;
4
5
  export declare class CloudRunInitCommand extends Command {
5
6
  get options(): {
6
7
  cmd: string;
@@ -136,6 +137,7 @@ export declare class CloudRunDeployCommand extends Command {
136
137
  source?: string;
137
138
  force?: boolean;
138
139
  port?: number;
140
+ createAgent?: boolean;
139
141
  }): Promise<void>;
140
142
  }
141
143
  export declare class CloudRunRunCommand extends Command {
@@ -151,6 +153,7 @@ export declare class CloudRunRunCommand extends Command {
151
153
  desc: string;
152
154
  };
153
155
  execute(envId: string, logger: Logger, ctx: any, options: any): Promise<void>;
156
+ private checkAndRunTsc;
154
157
  private openDebugApp;
155
158
  private waitForPort;
156
159
  }