@vectorx/xhs-cloud-cli 1.0.1 → 1.1.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 (73) hide show
  1. package/lib/commands/agent/dev.js +40 -8
  2. package/lib/commands/agent/index.js +2 -0
  3. package/lib/commands/agent/info.js +107 -0
  4. package/lib/commands/agent/list.js +95 -0
  5. package/lib/commands/agent/new.js +32 -6
  6. package/lib/commands/auth/login.js +53 -38
  7. package/lib/commands/env/info.js +3 -1
  8. package/lib/commands/env/set.js +3 -1
  9. package/lib/commands/fun/deploy.js +3 -1
  10. package/lib/commands/fun/dev.js +9 -3
  11. package/lib/commands/fun/new.js +32 -6
  12. package/lib/core/base.js +9 -1
  13. package/lib/decorators/auth.js +2 -1
  14. package/lib/main.js +3 -1
  15. package/lib/utils/agent-check.js +158 -0
  16. package/lib/utils/templates.js +75 -0
  17. package/package.json +10 -8
  18. package/templates/cloud-agents/agent-base-template/project.config.json +6 -0
  19. package/templates/{chatbox-agent → cloud-agents/agent-base-template}/src/index.js +0 -1
  20. package/templates/cloud-agents/agent-doc-template/.env.template +1 -0
  21. package/templates/cloud-agents/agent-doc-template/agent-cloudbase-functions.json +11 -0
  22. package/templates/cloud-agents/agent-doc-template/package.json +11 -0
  23. package/templates/cloud-agents/agent-doc-template/project.config.json +6 -0
  24. package/templates/cloud-agents/agent-doc-template/src/index.js +68 -0
  25. package/templates/cloud-agents/agent-image-template/.env.template +1 -0
  26. package/templates/cloud-agents/agent-image-template/agent-cloudbase-functions.json +11 -0
  27. package/templates/cloud-agents/agent-image-template/package.json +11 -0
  28. package/templates/cloud-agents/agent-image-template/project.config.json +6 -0
  29. package/templates/cloud-agents/agent-image-template/src/index.js +56 -0
  30. package/templates/cloud-agents/agent-text-template/.env.template +1 -0
  31. package/templates/cloud-agents/agent-text-template/agent-cloudbase-functions.json +11 -0
  32. package/templates/cloud-agents/agent-text-template/package.json +11 -0
  33. package/templates/cloud-agents/agent-text-template/project.config.json +6 -0
  34. package/templates/cloud-agents/agent-text-template/src/index.js +38 -0
  35. package/templates/cloud-agents/agent-voice-template/.env.template +1 -0
  36. package/templates/cloud-agents/agent-voice-template/agent-cloudbase-functions.json +11 -0
  37. package/templates/cloud-agents/agent-voice-template/package.json +11 -0
  38. package/templates/cloud-agents/agent-voice-template/project.config.json +6 -0
  39. package/templates/cloud-agents/agent-voice-template/src/index.js +81 -0
  40. package/templates/cloud-agents/templates.json +9 -0
  41. package/templates/cloud-dev/templates.json +6 -0
  42. package/types/commands/agent/index.d.ts +2 -0
  43. package/types/commands/agent/info.d.ts +14 -0
  44. package/types/commands/agent/list.d.ts +14 -0
  45. package/types/commands/auth/login.d.ts +2 -0
  46. package/types/utils/agent-check.d.ts +1 -0
  47. package/types/utils/templates.d.ts +17 -0
  48. package/templates/chatbox-agent/project.config.json +0 -5
  49. package/templates/weather-agent/index.js +0 -92
  50. package/templates/weather-agent/project.config.json +0 -4
  51. /package/templates/{chatbox-agent → cloud-agents/agent-base-template}/.env.template +0 -0
  52. /package/templates/{chatbox-agent → cloud-agents/agent-base-template}/agent-cloudbase-functions.json +0 -0
  53. /package/templates/{chatbox-agent → cloud-agents/agent-base-template}/package.json +0 -0
  54. /package/templates/{ai-cloud-functions-example → cloud-dev/cloudfunction-route-template}/.env.template +0 -0
  55. /package/templates/{ai-cloud-functions-example → cloud-dev/cloudfunction-route-template}/README.md +0 -0
  56. /package/templates/{ai-cloud-functions-example → cloud-dev/cloudfunction-route-template}/agent-cloudbase-functions.json +0 -0
  57. /package/templates/{ai-cloud-functions-example → cloud-dev/cloudfunction-route-template}/package.json +0 -0
  58. /package/templates/{ai-cloud-functions-example → cloud-dev/cloudfunction-route-template}/src/binary/index.js +0 -0
  59. /package/templates/{ai-cloud-functions-example → cloud-dev/cloudfunction-route-template}/src/context/context-service.js +0 -0
  60. /package/templates/{ai-cloud-functions-example → cloud-dev/cloudfunction-route-template}/src/context/index.js +0 -0
  61. /package/templates/{ai-cloud-functions-example → cloud-dev/cloudfunction-route-template}/src/env/index.js +0 -0
  62. /package/templates/{ai-cloud-functions-example → cloud-dev/cloudfunction-route-template}/src/form/index.js +0 -0
  63. /package/templates/{ai-cloud-functions-example → cloud-dev/cloudfunction-route-template}/src/index.js +0 -0
  64. /package/templates/{ai-cloud-functions-example → cloud-dev/cloudfunction-route-template}/src/json/index.js +0 -0
  65. /package/templates/{ai-cloud-functions-example → cloud-dev/cloudfunction-route-template}/src/multipart/index.js +0 -0
  66. /package/templates/{ai-cloud-functions-example → cloud-dev/cloudfunction-route-template}/src/text/index.js +0 -0
  67. /package/templates/{ai-cloud-functions-example → cloud-dev/cloudfunction-route-template}/src/user/index.js +0 -0
  68. /package/templates/{cloudfunction-template → cloud-dev/cloudfunction-template}/.env.template +0 -0
  69. /package/templates/{cloudfunction-template → cloud-dev/cloudfunction-template}/agent-cloudbase-functions.json +0 -0
  70. /package/templates/{cloudfunction-template → cloud-dev/cloudfunction-template}/package.json +0 -0
  71. /package/templates/{cloudfunction-template → cloud-dev/cloudfunction-template}/project.config.json +0 -0
  72. /package/templates/{cloudfunction-template → cloud-dev/cloudfunction-template}/src/echo.js +0 -0
  73. /package/templates/{cloudfunction-template → cloud-dev/cloudfunction-template}/src/index.js +0 -0
@@ -28,9 +28,11 @@ exports.AgentDevCommand = void 0;
28
28
  const fs_1 = __importDefault(require("fs"));
29
29
  const agent_simulator_1 = require("@vectorx/agent-simulator");
30
30
  const cloud_toolkit_1 = require("@vectorx/cloud-toolkit");
31
+ const App_1 = require("@vectorx/function-debugger/lib/App");
31
32
  const chalk_1 = __importDefault(require("chalk"));
32
33
  const base_1 = require("../../core/base");
33
34
  const decorators_1 = require("../../decorators");
35
+ const agent_check_1 = require("../../utils/agent-check");
34
36
  const prefix = chalk_1.default.bgGreenBright(" 🚀 [rcb-ff log] ");
35
37
  let AgentDevCommand = class AgentDevCommand extends base_1.Command {
36
38
  execute(options, log) {
@@ -39,27 +41,45 @@ let AgentDevCommand = class AgentDevCommand extends base_1.Command {
39
41
  if (!fs_1.default.existsSync(workDir)) {
40
42
  throw new Error(`目录不存在: ${workDir}`);
41
43
  }
44
+ const useIde = options.useIde !== false;
45
+ const watch = options.watch !== false;
42
46
  try {
43
- const { simulatorPort } = yield (0, cloud_toolkit_1.startDev)({
47
+ yield (0, agent_check_1.checkAndGuideAgentProject)(workDir);
48
+ const { simulatorPort, ideUrl } = yield (0, cloud_toolkit_1.startDev)({
44
49
  workDir,
45
50
  port: options.port ? Number.parseInt(options.port) : undefined,
46
51
  simulatorPort: options.simulatorport ? Number.parseInt(options.simulatorport) : undefined,
47
- watch: options.watch,
52
+ watch,
48
53
  open: false,
49
54
  enableRedLangfuse: Boolean(options.enableRedLangfuse),
50
55
  mode: "agent",
51
- deps: { AgentSimulator: agent_simulator_1.AgentSimulator },
56
+ useIde,
57
+ deps: { AgentSimulator: agent_simulator_1.AgentSimulator, startFunctionDebugger: App_1.startFunctionDebugger },
52
58
  });
53
59
  if (options.open) {
54
- log.info(`${prefix} 正在打开浏览器访问 localhost:${simulatorPort}`);
55
- (0, cloud_toolkit_1.openBrowser)("localhost", simulatorPort);
60
+ if (useIde && ideUrl) {
61
+ log.info(`${prefix} 正在打开浏览器访问 Web IDE: ${ideUrl}`);
62
+ const ideUrlObj = new URL(ideUrl);
63
+ (0, cloud_toolkit_1.openBrowser)(ideUrlObj.hostname, Number(ideUrlObj.port));
64
+ }
65
+ else {
66
+ log.info(`${prefix} 正在打开浏览器访问 localhost:${simulatorPort}`);
67
+ (0, cloud_toolkit_1.openBrowser)("localhost", simulatorPort);
68
+ }
69
+ }
70
+ if (useIde && ideUrl) {
71
+ log.info(`${prefix} ${chalk_1.default.greenBright("Web IDE 调试环境启动完成!")}`);
72
+ log.info(`${prefix} Web IDE 地址: ${chalk_1.default.cyan(ideUrl)}`);
73
+ log.info(`${prefix} Agent 模拟器地址: ${chalk_1.default.cyan(`http://localhost:${simulatorPort}`)}`);
74
+ }
75
+ else {
76
+ log.info(`${prefix} ${chalk_1.default.greenBright("开发环境启动完成!")}`);
56
77
  }
57
- log.info(`${prefix} ${chalk_1.default.greenBright("开发环境启动完成!")}`);
58
78
  this.setupProcessCleanup(log);
59
79
  }
60
80
  catch (error) {
61
81
  log.error(`${prefix} 启动开发环境失败: ${error.message}`);
62
- throw error;
82
+ process.exit(1);
63
83
  }
64
84
  });
65
85
  }
@@ -96,12 +116,24 @@ let AgentDevCommand = class AgentDevCommand extends base_1.Command {
96
116
  },
97
117
  {
98
118
  flags: "-w, --watch",
99
- desc: "启用文件监听模式,文件变化时自动重启服务",
119
+ desc: "启用文件监听模式,文件变化时自动重启服务(默认开启)",
120
+ },
121
+ {
122
+ flags: "--no-watch",
123
+ desc: "禁用文件监听模式",
100
124
  },
101
125
  {
102
126
  flags: "--enableRedLangfuse",
103
127
  desc: "开启 Red Langfuse 上报",
104
128
  },
129
+ {
130
+ flags: "--use-ide",
131
+ desc: "使用 Web IDE 模式调试 Agent(默认开启)",
132
+ },
133
+ {
134
+ flags: "--no-use-ide",
135
+ desc: "禁用 Web IDE 模式,仅启动 Agent 模拟器",
136
+ },
105
137
  ],
106
138
  };
107
139
  }
@@ -17,3 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./dev"), exports);
18
18
  __exportStar(require("./build"), exports);
19
19
  __exportStar(require("./new"), exports);
20
+ __exportStar(require("./list"), exports);
21
+ __exportStar(require("./info"), exports);
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
+ return new (P || (P = Promise))(function (resolve, reject) {
17
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
21
+ });
22
+ };
23
+ var __importDefault = (this && this.__importDefault) || function (mod) {
24
+ return (mod && mod.__esModule) ? mod : { "default": mod };
25
+ };
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.AgentInfoCommand = void 0;
28
+ const cloud_toolkit_1 = require("@vectorx/cloud-toolkit");
29
+ const chalk_1 = __importDefault(require("chalk"));
30
+ const base_1 = require("../../core/base");
31
+ const decorators_1 = require("../../decorators");
32
+ const auth_1 = require("../../decorators/auth");
33
+ const prefix = chalk_1.default.bgMagenta(" 🤖 [rcb-agent] ");
34
+ let AgentInfoCommand = class AgentInfoCommand extends base_1.Command {
35
+ execute(options, log) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ var _a, _b, _c, _d, _e, _f, _g, _h;
38
+ const agentId = options.agentId;
39
+ if (!agentId) {
40
+ log.error(`${prefix} 请通过 -a, --agentId 指定要查询的 Agent Id`);
41
+ log.breakLine();
42
+ console.log(chalk_1.default.gray("示例: "));
43
+ console.log(chalk_1.default.cyan(" rcb agent info -a <agentId>"));
44
+ log.breakLine();
45
+ process.exit(1);
46
+ }
47
+ const spinner = log.spinner(`${prefix} 正在查询 Agent 详情(agentId=${agentId})...`);
48
+ try {
49
+ const agent = yield (0, cloud_toolkit_1.getAgentInfoById)(agentId);
50
+ spinner.succeed(`${prefix} Agent 详情查询完成`);
51
+ log.breakLine();
52
+ if (!agent) {
53
+ log.warn(`${prefix} 未找到 Id 为 ${agentId} 的 Agent`);
54
+ log.breakLine();
55
+ return;
56
+ }
57
+ log.info(`${prefix} Agent 详情:`);
58
+ log.breakLine();
59
+ const rows = [
60
+ [chalk_1.default.gray("名称"), chalk_1.default.bold((_a = agent.agentName) !== null && _a !== void 0 ? _a : "-")],
61
+ [chalk_1.default.gray("Agent ID"), chalk_1.default.cyan(agent.agentId)],
62
+ [chalk_1.default.gray("头像"), (_b = agent.agentAvatar) !== null && _b !== void 0 ? _b : "-"],
63
+ [chalk_1.default.gray("类型"), (_c = agent.agentType) !== null && _c !== void 0 ? _c : "-"],
64
+ [chalk_1.default.gray("描述"), (_d = agent.description) !== null && _d !== void 0 ? _d : "-"],
65
+ [chalk_1.default.gray("状态"), (_e = agent.status) !== null && _e !== void 0 ? _e : "-"],
66
+ [chalk_1.default.gray("创建时间"), (_f = agent.createTime) !== null && _f !== void 0 ? _f : "-"],
67
+ [chalk_1.default.gray("更新时间"), (_g = agent.updateTime) !== null && _g !== void 0 ? _g : "-"],
68
+ [chalk_1.default.gray("创建者"), (_h = agent.creator) !== null && _h !== void 0 ? _h : "-"],
69
+ ];
70
+ (0, cloud_toolkit_1.printHorizontalTable)([chalk_1.default.gray("字段"), chalk_1.default.gray("值")], rows);
71
+ log.breakLine();
72
+ }
73
+ catch (error) {
74
+ spinner.fail(`${prefix} Agent 详情查询失败`);
75
+ log.error(`${prefix} 错误信息: ${(error === null || error === void 0 ? void 0 : error.message) || error}`);
76
+ log.breakLine();
77
+ process.exit(1);
78
+ }
79
+ });
80
+ }
81
+ get options() {
82
+ return {
83
+ cmd: "agent",
84
+ childCmd: "info",
85
+ desc: "查看指定 Agent 的详情信息",
86
+ options: [
87
+ {
88
+ flags: "-a, --agentId <agentId>",
89
+ desc: "Agent Id(agent_id)",
90
+ },
91
+ ],
92
+ };
93
+ }
94
+ };
95
+ exports.AgentInfoCommand = AgentInfoCommand;
96
+ __decorate([
97
+ (0, decorators_1.InjectParams)(),
98
+ __param(0, (0, decorators_1.ArgsOptions)()),
99
+ __param(1, (0, decorators_1.Log)()),
100
+ __metadata("design:type", Function),
101
+ __metadata("design:paramtypes", [Object, Function]),
102
+ __metadata("design:returntype", Promise)
103
+ ], AgentInfoCommand.prototype, "execute", null);
104
+ exports.AgentInfoCommand = AgentInfoCommand = __decorate([
105
+ (0, auth_1.AuthGuard)(),
106
+ (0, base_1.ICommand)()
107
+ ], AgentInfoCommand);
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
+ return new (P || (P = Promise))(function (resolve, reject) {
17
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
21
+ });
22
+ };
23
+ var __importDefault = (this && this.__importDefault) || function (mod) {
24
+ return (mod && mod.__esModule) ? mod : { "default": mod };
25
+ };
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.AgentListCommand = void 0;
28
+ const cloud_toolkit_1 = require("@vectorx/cloud-toolkit");
29
+ const chalk_1 = __importDefault(require("chalk"));
30
+ const base_1 = require("../../core/base");
31
+ const decorators_1 = require("../../decorators");
32
+ const auth_1 = require("../../decorators/auth");
33
+ const prefix = chalk_1.default.bgMagenta(" 🤖 [rcb-agent] ");
34
+ let AgentListCommand = class AgentListCommand extends base_1.Command {
35
+ execute(options, log) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ const pageNo = options.pageNo != null ? Number(options.pageNo) : undefined;
38
+ const pageSize = options.pageSize != null ? Number(options.pageSize) : undefined;
39
+ const spinner = log.spinner(`${prefix} 正在查询智能体 Agent 列表...`);
40
+ try {
41
+ const agents = yield (0, cloud_toolkit_1.getAgentList)({ pageNo, pageSize });
42
+ spinner.succeed(`${prefix} Agent 列表查询完成`);
43
+ log.breakLine();
44
+ if (!agents || agents.length === 0) {
45
+ log.info(`${prefix} 当前账号下暂未创建任何智能体 Agent`);
46
+ log.breakLine();
47
+ return;
48
+ }
49
+ log.info(`${prefix} 共查询到 ${agents.length} 个 Agent:`);
50
+ log.breakLine();
51
+ (0, cloud_toolkit_1.printHorizontalTable)(["Agent ID", "名称", "类型", "状态", "创建时间", "更新时间"], agents.map((agent) => {
52
+ var _a, _b, _c, _d, _e;
53
+ return [
54
+ agent.agentId,
55
+ chalk_1.default.bold((_a = agent.agentName) !== null && _a !== void 0 ? _a : "-"),
56
+ (_b = agent.agentType) !== null && _b !== void 0 ? _b : "-",
57
+ agent.status === "online" ? chalk_1.default.green("online") : chalk_1.default.yellow((_c = agent.status) !== null && _c !== void 0 ? _c : "-"),
58
+ (_d = agent.createTime) !== null && _d !== void 0 ? _d : "-",
59
+ (_e = agent.updateTime) !== null && _e !== void 0 ? _e : "-",
60
+ ];
61
+ }));
62
+ }
63
+ catch (error) {
64
+ spinner.fail(`${prefix} Agent 列表查询失败`);
65
+ log.error(`${prefix} 错误信息: ${(error === null || error === void 0 ? void 0 : error.message) || error}`);
66
+ log.breakLine();
67
+ process.exit(1);
68
+ }
69
+ });
70
+ }
71
+ get options() {
72
+ return {
73
+ cmd: "agent",
74
+ childCmd: "list",
75
+ desc: "查看当前账号下的智能体 Agent 列表",
76
+ options: [
77
+ { flags: "-p, --pageNo <pageNo>", desc: "页码" },
78
+ { flags: "--pageSize <pageSize>", desc: "每页条数" },
79
+ ],
80
+ };
81
+ }
82
+ };
83
+ exports.AgentListCommand = AgentListCommand;
84
+ __decorate([
85
+ (0, decorators_1.InjectParams)(),
86
+ __param(0, (0, decorators_1.ArgsOptions)()),
87
+ __param(1, (0, decorators_1.Log)()),
88
+ __metadata("design:type", Function),
89
+ __metadata("design:paramtypes", [Object, Function]),
90
+ __metadata("design:returntype", Promise)
91
+ ], AgentListCommand.prototype, "execute", null);
92
+ exports.AgentListCommand = AgentListCommand = __decorate([
93
+ (0, auth_1.AuthGuard)(),
94
+ (0, base_1.ICommand)()
95
+ ], AgentListCommand);
@@ -28,12 +28,25 @@ exports.AgentNewCommand = void 0;
28
28
  const fs_1 = __importDefault(require("fs"));
29
29
  const path_1 = __importDefault(require("path"));
30
30
  const chalk_1 = __importDefault(require("chalk"));
31
+ const inquirer_1 = __importDefault(require("inquirer"));
31
32
  const base_1 = require("../../core/base");
32
33
  const decorators_1 = require("../../decorators");
34
+ const templates_1 = require("../../utils/templates");
33
35
  let AgentNewCommand = class AgentNewCommand extends base_1.Command {
34
36
  execute(options, log) {
35
37
  return __awaiter(this, void 0, void 0, function* () {
36
- const { projectName, dir } = options;
38
+ let { projectName, dir, template } = options;
39
+ if (!projectName) {
40
+ const { projectName: inputName } = yield inquirer_1.default.prompt([
41
+ {
42
+ type: "input",
43
+ name: "projectName",
44
+ message: "请输入项目名称:",
45
+ validate: (v) => ((v || "").trim() ? true : "项目名称不能为空"),
46
+ },
47
+ ]);
48
+ projectName = (inputName || "").trim();
49
+ }
37
50
  if (!projectName) {
38
51
  log.error("项目名称不能为空");
39
52
  process.exit(1);
@@ -44,18 +57,20 @@ let AgentNewCommand = class AgentNewCommand extends base_1.Command {
44
57
  log.error(`项目目录已存在: ${projectDir}`);
45
58
  process.exit(1);
46
59
  }
60
+ const templateId = yield (0, templates_1.selectTemplate)("cloud-agents", { template });
61
+ const templateDir = (0, templates_1.resolveTemplatePath)("cloud-agents", templateId);
62
+ if (!fs_1.default.existsSync(templateDir)) {
63
+ log.error(`模板目录不存在: ${templateDir}`);
64
+ throw new Error(`模板目录不存在: ${templateDir}`);
65
+ }
47
66
  log.breakLine();
48
67
  console.log(chalk_1.default.bold.blue("📋 项目创建信息"));
49
68
  console.log(chalk_1.default.gray("─".repeat(40)));
50
69
  console.log(chalk_1.default.bold("创建目录: ") + chalk_1.default.green(projectDir));
51
70
  console.log(chalk_1.default.bold("目录名称: ") + chalk_1.default.cyan(projectName));
71
+ console.log(chalk_1.default.bold("使用模板: ") + chalk_1.default.cyan(templateId));
52
72
  console.log(chalk_1.default.gray("─".repeat(40)));
53
73
  log.breakLine();
54
- const templateDir = path_1.default.join(__dirname, "../../../", "templates", "chatbox-agent");
55
- if (!fs_1.default.existsSync(templateDir)) {
56
- log.error(`模板目录不存在: ${templateDir}`);
57
- throw new Error(`模板目录不存在: ${templateDir}`);
58
- }
59
74
  const spinnerCopy = require("ora")("复制模板文件...").start();
60
75
  try {
61
76
  yield this.copyTemplate(templateDir, projectDir);
@@ -71,6 +86,13 @@ let AgentNewCommand = class AgentNewCommand extends base_1.Command {
71
86
  log.info(` - cd ${projectDir}`);
72
87
  log.info(" - npm install");
73
88
  log.info(" - npm run dev");
89
+ log.breakLine();
90
+ console.log(chalk_1.default.bgYellow.black(" ⚠️ 重要:配置 Agent ID "));
91
+ console.log(chalk_1.default.yellow("请将 project.config.json 中的 agentId 替换为开放平台获取的正确 ID:"));
92
+ console.log(chalk_1.default.gray(" • 前往开放平台创建/获取智能体,复制 agentId 填入 project.config.json"));
93
+ console.log(chalk_1.default.cyan(" • rcb agent list — 查看当前账号下的 Agent 列表"));
94
+ console.log(chalk_1.default.cyan(" • rcb agent info -a <id> — 查询指定 Agent 详情"));
95
+ log.breakLine();
74
96
  });
75
97
  }
76
98
  copyTemplate(sourceDir, targetDir) {
@@ -107,6 +129,10 @@ let AgentNewCommand = class AgentNewCommand extends base_1.Command {
107
129
  flags: "-p, --projectName <projectName>",
108
130
  desc: "指定项目名称,默认为当前目录名称",
109
131
  },
132
+ {
133
+ flags: "-t, --template <template>",
134
+ desc: "指定模板 ID,不传则交互式选择",
135
+ },
110
136
  ],
111
137
  };
112
138
  }
@@ -29,24 +29,24 @@ let LoginCommand = class LoginCommand extends base_1.Command {
29
29
  constructor() {
30
30
  super();
31
31
  this.authService = cloud_toolkit_1.container.get(cloud_toolkit_1.SERVICE_IDENTIFIERS.AuthService);
32
+ this.cloudDevService = cloud_toolkit_1.container.get(cloud_toolkit_1.SERVICE_IDENTIFIERS.CloudDevService);
32
33
  }
33
34
  execute(ctx) {
34
35
  return __awaiter(this, void 0, void 0, function* () {
36
+ var _a, _b;
35
37
  try {
36
38
  const existingLoginInfo = yield this.authService.getLoginInfo();
37
39
  if (existingLoginInfo) {
38
- cloud_toolkit_1.logger.warn("检测到您已经登录,如需切换登录信息,请先退出登录");
40
+ cloud_toolkit_1.logger.warn("检测到您已登录且 Token 尚未过期,继续操作将使用新的密钥覆盖当前登录信息");
39
41
  cloud_toolkit_1.logger.breakLine();
40
42
  console.log(chalk_1.default.bold.blue("📋 当前登录信息"));
41
43
  console.log(chalk_1.default.gray("─".repeat(40)));
42
- console.log(chalk_1.default.bold("Token: ") + chalk_1.default.green("●".repeat(8) + existingLoginInfo.cli_token.slice(-8)));
44
+ console.log(chalk_1.default.bold("Token: ") +
45
+ chalk_1.default.green("●".repeat(8) + existingLoginInfo.cli_token.slice(-8)));
43
46
  console.log(chalk_1.default.bold("过期时间: ") +
44
47
  chalk_1.default.yellow(new Date(existingLoginInfo.create_at + existingLoginInfo.expire_in_sec * 1000).toLocaleString("zh-CN")));
45
48
  console.log(chalk_1.default.gray("─".repeat(40)));
46
49
  cloud_toolkit_1.logger.breakLine();
47
- console.log(chalk_1.default.yellow("💡 提示:如需重新登录,请先执行退出登录命令"));
48
- console.log(chalk_1.default.gray(" 使用命令: ") + chalk_1.default.cyan("rcb logout"));
49
- return;
50
50
  }
51
51
  const { secretId, secretKey } = ctx.options;
52
52
  if (!secretId || !secretKey) {
@@ -60,23 +60,6 @@ let LoginCommand = class LoginCommand extends base_1.Command {
60
60
  cloud_toolkit_1.logger.breakLine();
61
61
  process.exit(1);
62
62
  }
63
- let loginInfo = null;
64
- if (this.authService.hasLogin()) {
65
- loginInfo = yield this.authService.getLoginInfo();
66
- }
67
- if (loginInfo) {
68
- cloud_toolkit_1.logger.error("检测到您已经登录,如需切换登录信息,请先退出登录");
69
- cloud_toolkit_1.logger.breakLine();
70
- console.log(chalk_1.default.bold.blue("📋 当前登录信息"));
71
- console.log(chalk_1.default.gray("─".repeat(40)));
72
- console.log(chalk_1.default.bold("Token: ") + chalk_1.default.green("●".repeat(8) + loginInfo.cli_token.slice(-8)));
73
- console.log(chalk_1.default.bold("过期时间: ") + chalk_1.default.yellow(new Date(loginInfo.expire_in_sec).toLocaleString("zh-CN")));
74
- console.log(chalk_1.default.gray("─".repeat(40)));
75
- cloud_toolkit_1.logger.breakLine();
76
- console.log(chalk_1.default.yellow("💡 提示:如需重新登录,请先执行退出登录命令"));
77
- console.log(chalk_1.default.gray(" 使用命令: ") + chalk_1.default.cyan("rcb logout"));
78
- return;
79
- }
80
63
  const spinner = require("ora")("正在验证小红书云服务密钥信息...").start();
81
64
  try {
82
65
  const nonce = (0, cloud_toolkit_1.getNonce)();
@@ -90,13 +73,14 @@ let LoginCommand = class LoginCommand extends base_1.Command {
90
73
  cloud_toolkit_1.logger.error(`密钥验证失败,请检查密钥是否正确或终端网络是否可用: ${msg}`);
91
74
  process.exit(1);
92
75
  }
76
+ const loginInfo = {
77
+ secret_id: secretId,
78
+ cli_token: cliToken,
79
+ create_at: Date.now(),
80
+ expire_in_sec: data.expire_in_sec,
81
+ };
93
82
  try {
94
- yield this.authService.saveLoginInfo({
95
- secret_id: secretId,
96
- cli_token: cliToken,
97
- create_at: Date.now(),
98
- expire_in_sec: data.expire_in_sec,
99
- });
83
+ yield this.authService.saveLoginInfo(loginInfo);
100
84
  }
101
85
  catch (error) {
102
86
  cloud_toolkit_1.logger.error(`保存登录信息失败: ${error.message}`);
@@ -104,11 +88,22 @@ let LoginCommand = class LoginCommand extends base_1.Command {
104
88
  }
105
89
  spinner.succeed();
106
90
  cloud_toolkit_1.logger.breakLine();
91
+ let userInfo = null;
92
+ try {
93
+ userInfo = yield this.cloudDevService.getUserInfo({
94
+ secret_id: secretId,
95
+ cli_token: cliToken,
96
+ });
97
+ yield this.authService.saveLoginInfo(Object.assign(Object.assign({}, loginInfo), { userInfo }));
98
+ }
99
+ catch (_c) {
100
+ }
107
101
  const expireTime = new Date(Date.now() + data.expire_in_sec * 1000);
108
- cloud_toolkit_1.logger.info(`获取 access_token 成功: ${chalk_1.default.green(data.cli_token)}`);
109
- cloud_toolkit_1.logger.info(`access_token 过期时间: ${chalk_1.default.yellow(expireTime.toLocaleString("zh-CN"))}`);
110
- cloud_toolkit_1.logger.breakLine();
111
- cloud_toolkit_1.logger.success("🎉 登录成功!欢迎使用小红书云服务 CLI");
102
+ const nick = (_b = (_a = userInfo === null || userInfo === void 0 ? void 0 : userInfo.nick) !== null && _a !== void 0 ? _a : userInfo === null || userInfo === void 0 ? void 0 : userInfo.nickname) !== null && _b !== void 0 ? _b : "用户";
103
+ const tokenShort = "●".repeat(8) + data.cli_token.slice(-8);
104
+ console.log(chalk_1.default.cyan(`👤 ${nick},欢迎你登录小红书云开发!`));
105
+ cloud_toolkit_1.logger.success("🎉 登录成功!");
106
+ console.log(chalk_1.default.gray(` Token: ${chalk_1.default.green(tokenShort)} 过期: ${chalk_1.default.yellow(expireTime.toLocaleString("zh-CN"))}`));
112
107
  }
113
108
  catch (error) {
114
109
  spinner.fail("登录验证失败");
@@ -152,27 +147,46 @@ exports.LoginCommand = LoginCommand = __decorate([
152
147
  let GetLoginInfoCommand = class GetLoginInfoCommand extends base_1.Command {
153
148
  constructor() {
154
149
  super();
155
- this.authService = new cloud_toolkit_1.AuthService();
150
+ this.authService = cloud_toolkit_1.container.get(cloud_toolkit_1.SERVICE_IDENTIFIERS.AuthService);
151
+ this.cloudDevService = cloud_toolkit_1.container.get(cloud_toolkit_1.SERVICE_IDENTIFIERS.CloudDevService);
156
152
  }
157
153
  execute(ctx) {
158
154
  return __awaiter(this, void 0, void 0, function* () {
159
- var _a;
155
+ var _a, _b, _c;
160
156
  try {
161
- const loginInfo = yield this.authService.getLoginInfo();
157
+ let loginInfo = yield this.authService.getLoginInfo();
162
158
  if (!loginInfo) {
163
159
  cloud_toolkit_1.logger.error("未登录或登录已过期");
164
160
  cloud_toolkit_1.logger.breakLine();
165
161
  console.log(chalk_1.default.yellow("💡 提示:请先执行登录命令"));
166
- console.log(chalk_1.default.gray(" 使用命令: ") + chalk_1.default.cyan("rcb login --secretId <secretId> --secretKey <secretKey>"));
162
+ console.log(chalk_1.default.gray(" 使用命令: ") +
163
+ chalk_1.default.cyan("rcb login --secretId <secretId> --secretKey <secretKey>"));
167
164
  process.exit(1);
168
165
  }
166
+ if (!loginInfo.userInfo) {
167
+ try {
168
+ const userInfo = yield this.cloudDevService.getUserInfo({
169
+ secret_id: loginInfo.secret_id,
170
+ cli_token: loginInfo.cli_token,
171
+ });
172
+ yield this.authService.saveLoginInfo(Object.assign(Object.assign({}, loginInfo), { userInfo }));
173
+ loginInfo = Object.assign(Object.assign({}, loginInfo), { userInfo });
174
+ }
175
+ catch (_d) {
176
+ }
177
+ }
169
178
  cloud_toolkit_1.logger.breakLine();
179
+ if (loginInfo.userInfo) {
180
+ const nick = (_b = (_a = loginInfo.userInfo.nick) !== null && _a !== void 0 ? _a : loginInfo.userInfo.nickname) !== null && _b !== void 0 ? _b : "用户";
181
+ console.log(chalk_1.default.cyan(`👤 ${nick},欢迎你登录小红书云开发!`));
182
+ cloud_toolkit_1.logger.breakLine();
183
+ }
170
184
  console.log(chalk_1.default.bold.blue("📋 当前登录信息"));
171
185
  console.log(chalk_1.default.gray("─".repeat(40)));
172
186
  console.log(chalk_1.default.bold("Token: ") + chalk_1.default.green("●".repeat(8) + loginInfo.cli_token.slice(-8)));
173
187
  console.log(chalk_1.default.bold("过期时间: ") +
174
188
  chalk_1.default.yellow(new Date(loginInfo.create_at + loginInfo.expire_in_sec * 1000).toLocaleString("zh-CN")));
175
- if ((_a = loginInfo.cloudEnvInfo) === null || _a === void 0 ? void 0 : _a.cloud_env_id) {
189
+ if ((_c = loginInfo.cloudEnvInfo) === null || _c === void 0 ? void 0 : _c.cloud_env_id) {
176
190
  const env = loginInfo.cloudEnvInfo;
177
191
  console.log(chalk_1.default.bold("云服务环境信息: ") +
178
192
  chalk_1.default.cyan(env.cloud_env_name ? `${env.cloud_env_name} (${env.cloud_env_id})` : env.cloud_env_id));
@@ -182,7 +196,8 @@ let GetLoginInfoCommand = class GetLoginInfoCommand extends base_1.Command {
182
196
  }
183
197
  else {
184
198
  console.log(chalk_1.default.bold("云服务环境信息: ") + chalk_1.default.gray("暂未指定 env Id"));
185
- console.log(chalk_1.default.gray(" 可通过以下命令为 CLI 选择默认云环境: ") + chalk_1.default.cyan("rcb env set -e <envId>"));
199
+ console.log(chalk_1.default.gray(" 可通过以下命令为 CLI 选择默认云环境: ") +
200
+ chalk_1.default.cyan("rcb env set -e <envId>"));
186
201
  }
187
202
  console.log(chalk_1.default.gray("─".repeat(40)));
188
203
  cloud_toolkit_1.logger.breakLine();
@@ -61,7 +61,9 @@ let EnvInfoCommand = class EnvInfoCommand extends base_1.Command {
61
61
  [chalk_1.default.gray("ID"), chalk_1.default.cyan(env.cloud_env_id)],
62
62
  [
63
63
  chalk_1.default.gray("状态"),
64
- env.status === 1 ? chalk_1.default.green("启用") : chalk_1.default.yellow(`停用/未知 (${(_a = env.status) !== null && _a !== void 0 ? _a : "N/A"})`),
64
+ env.status === 1
65
+ ? chalk_1.default.green("启用")
66
+ : chalk_1.default.yellow(`停用/未知 (${(_a = env.status) !== null && _a !== void 0 ? _a : "N/A"})`),
65
67
  ],
66
68
  [chalk_1.default.gray("描述"), env.description || "-"],
67
69
  [chalk_1.default.gray("创建时间"), env.create_time || "-"],
@@ -84,7 +84,9 @@ let EnvSetCommand = class EnvSetCommand extends base_1.Command {
84
84
  [chalk_1.default.gray("ID"), chalk_1.default.cyan(targetEnv.cloud_env_id)],
85
85
  [
86
86
  chalk_1.default.gray("状态"),
87
- targetEnv.status === 1 ? chalk_1.default.green("启用") : chalk_1.default.yellow(`停用/未知 (${(_c = targetEnv.status) !== null && _c !== void 0 ? _c : "N/A"})`),
87
+ targetEnv.status === 1
88
+ ? chalk_1.default.green("启用")
89
+ : chalk_1.default.yellow(`停用/未知 (${(_c = targetEnv.status) !== null && _c !== void 0 ? _c : "N/A"})`),
88
90
  ],
89
91
  [chalk_1.default.gray("描述"), targetEnv.description || "-"],
90
92
  [chalk_1.default.gray("创建时间"), targetEnv.create_time || "-"],
@@ -43,7 +43,9 @@ let FunDeployCommand = class FunDeployCommand extends base_1.Command {
43
43
  ? Boolean(options.includeNodeModules)
44
44
  : true;
45
45
  const inputWorkDir = options.dir || process.cwd();
46
- const workDir = path_1.default.isAbsolute(inputWorkDir) ? inputWorkDir : path_1.default.resolve(process.cwd(), inputWorkDir);
46
+ const workDir = path_1.default.isAbsolute(inputWorkDir)
47
+ ? inputWorkDir
48
+ : path_1.default.resolve(process.cwd(), inputWorkDir);
47
49
  const desc = options.desc;
48
50
  if (!fs_1.default.existsSync(workDir)) {
49
51
  log.error(`${prefix} 目录不存在: ${workDir}`);
@@ -38,7 +38,9 @@ let FunDevCommand = class FunDevCommand extends base_1.Command {
38
38
  execute(options, log) {
39
39
  return __awaiter(this, void 0, void 0, function* () {
40
40
  const inputWorkDir = options.dir || process.cwd();
41
- const workDir = path_1.default.isAbsolute(inputWorkDir) ? inputWorkDir : path_1.default.resolve(process.cwd(), inputWorkDir);
41
+ const workDir = path_1.default.isAbsolute(inputWorkDir)
42
+ ? inputWorkDir
43
+ : path_1.default.resolve(process.cwd(), inputWorkDir);
42
44
  if (!fs_1.default.existsSync(workDir)) {
43
45
  throw new Error(`目录不存在: ${workDir}`);
44
46
  }
@@ -127,7 +129,7 @@ let FunDevCommand = class FunDevCommand extends base_1.Command {
127
129
  const runtime = yield (0, cloud_toolkit_1.startFunDev)({
128
130
  workDir,
129
131
  envId,
130
- watch: Boolean(options.watch),
132
+ watch: options.watch !== false,
131
133
  open: Boolean(options.open),
132
134
  mode: "fun",
133
135
  deps: { startFunctionDebugger: App_1.startFunctionDebugger },
@@ -162,7 +164,11 @@ let FunDevCommand = class FunDevCommand extends base_1.Command {
162
164
  },
163
165
  {
164
166
  flags: "-w, --watch",
165
- desc: "启用文件监听模式,文件变化时自动刷新",
167
+ desc: "启用文件监听模式,文件变化时自动刷新(默认开启)",
168
+ },
169
+ {
170
+ flags: "--no-watch",
171
+ desc: "禁用文件监听模式",
166
172
  },
167
173
  ],
168
174
  };