@vectorx/xhs-cloud-cli 0.0.0-beta-20260108133839 → 0.0.0-beta-20260320063305
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.
- package/bin/rcb.js +47 -157
- package/lib/commands/agent/dev.js +42 -7
- package/lib/commands/agent/index.js +2 -0
- package/lib/commands/agent/info.js +107 -0
- package/lib/commands/agent/list.js +95 -0
- package/lib/commands/agent/new.js +32 -6
- package/lib/commands/auth/login.js +63 -35
- package/lib/commands/env/create.js +156 -0
- package/lib/commands/env/index.js +20 -0
- package/lib/commands/env/info.js +108 -0
- package/lib/commands/env/list.js +93 -0
- package/lib/commands/env/set.js +131 -0
- package/lib/commands/fun/deploy.js +184 -0
- package/lib/commands/fun/dev.js +189 -0
- package/lib/commands/fun/index.js +20 -0
- package/lib/commands/fun/list.js +77 -0
- package/lib/commands/fun/new.js +151 -0
- package/lib/commands/index.js +2 -0
- package/lib/constants/cmd.js +9 -9
- package/lib/core/base.js +83 -1
- package/lib/decorators/auth.js +8 -1
- package/lib/decorators/captureError.js +1 -0
- package/lib/main.js +8 -0
- package/lib/utils/agent-check.js +158 -0
- package/lib/utils/templates.js +75 -0
- package/package.json +12 -9
- package/templates/cloud-agents/agent-base-template/project.config.json +6 -0
- package/templates/{chatbox-agent → cloud-agents/agent-base-template}/src/index.js +0 -1
- package/templates/cloud-agents/agent-doc-template/.env.template +1 -0
- package/templates/cloud-agents/agent-doc-template/agent-cloudbase-functions.json +11 -0
- package/templates/cloud-agents/agent-doc-template/package.json +11 -0
- package/templates/cloud-agents/agent-doc-template/project.config.json +6 -0
- package/templates/cloud-agents/agent-doc-template/src/index.js +68 -0
- package/templates/cloud-agents/agent-image-template/.env.template +1 -0
- package/templates/cloud-agents/agent-image-template/agent-cloudbase-functions.json +11 -0
- package/templates/cloud-agents/agent-image-template/package.json +11 -0
- package/templates/cloud-agents/agent-image-template/project.config.json +6 -0
- package/templates/cloud-agents/agent-image-template/src/index.js +56 -0
- package/templates/cloud-agents/agent-text-template/.env.template +1 -0
- package/templates/cloud-agents/agent-text-template/agent-cloudbase-functions.json +11 -0
- package/templates/cloud-agents/agent-text-template/package.json +11 -0
- package/templates/cloud-agents/agent-text-template/project.config.json +6 -0
- package/templates/cloud-agents/agent-text-template/src/index.js +38 -0
- package/templates/cloud-agents/agent-voice-template/.env.template +1 -0
- package/templates/cloud-agents/agent-voice-template/agent-cloudbase-functions.json +11 -0
- package/templates/cloud-agents/agent-voice-template/package.json +11 -0
- package/templates/cloud-agents/agent-voice-template/project.config.json +6 -0
- package/templates/cloud-agents/agent-voice-template/src/index.js +81 -0
- package/templates/cloud-agents/templates.json +9 -0
- package/templates/cloud-dev/cloudfunction-route-template/.env.template +1 -0
- package/templates/cloud-dev/cloudfunction-route-template/README.md +277 -0
- package/templates/cloud-dev/cloudfunction-route-template/agent-cloudbase-functions.json +83 -0
- package/templates/cloud-dev/cloudfunction-route-template/package.json +10 -0
- package/templates/cloud-dev/cloudfunction-route-template/src/binary/index.js +207 -0
- package/templates/cloud-dev/cloudfunction-route-template/src/context/context-service.js +94 -0
- package/templates/cloud-dev/cloudfunction-route-template/src/context/index.js +57 -0
- package/templates/cloud-dev/cloudfunction-route-template/src/env/index.js +264 -0
- package/templates/cloud-dev/cloudfunction-route-template/src/form/index.js +138 -0
- package/templates/cloud-dev/cloudfunction-route-template/src/index.js +0 -0
- package/templates/cloud-dev/cloudfunction-route-template/src/json/index.js +194 -0
- package/templates/cloud-dev/cloudfunction-route-template/src/multipart/index.js +189 -0
- package/templates/cloud-dev/cloudfunction-route-template/src/text/index.js +319 -0
- package/templates/cloud-dev/cloudfunction-route-template/src/user/index.js +82 -0
- package/templates/cloud-dev/cloudfunction-template/.env.template +2 -0
- package/templates/cloud-dev/cloudfunction-template/agent-cloudbase-functions.json +17 -0
- package/templates/cloud-dev/cloudfunction-template/package.json +11 -0
- package/templates/cloud-dev/cloudfunction-template/src/echo.js +27 -0
- package/templates/cloud-dev/cloudfunction-template/src/index.js +34 -0
- package/templates/cloud-dev/templates.json +6 -0
- package/types/commands/agent/index.d.ts +2 -0
- package/types/commands/agent/info.d.ts +14 -0
- package/types/commands/agent/list.d.ts +14 -0
- package/types/commands/auth/login.d.ts +2 -0
- package/types/commands/env/create.d.ts +19 -0
- package/types/commands/env/index.d.ts +4 -0
- package/types/commands/env/info.d.ts +14 -0
- package/types/commands/env/list.d.ts +11 -0
- package/types/commands/env/set.d.ts +14 -0
- package/types/commands/fun/deploy.d.ts +14 -0
- package/types/commands/fun/dev.d.ts +14 -0
- package/types/commands/fun/index.d.ts +4 -0
- package/types/commands/fun/list.d.ts +14 -0
- package/types/commands/fun/new.d.ts +16 -0
- package/types/commands/index.d.ts +2 -0
- package/types/utils/agent-check.d.ts +1 -0
- package/types/utils/templates.d.ts +17 -0
- package/templates/weather-agent/index.js +0 -92
- package/templates/weather-agent/project.config.json +0 -4
- /package/templates/{chatbox-agent → cloud-agents/agent-base-template}/.env.template +0 -0
- /package/templates/{chatbox-agent → cloud-agents/agent-base-template}/agent-cloudbase-functions.json +0 -0
- /package/templates/{chatbox-agent → cloud-agents/agent-base-template}/package.json +0 -0
- /package/templates/{chatbox-agent → cloud-dev/cloudfunction-template}/project.config.json +0 -0
|
@@ -0,0 +1,151 @@
|
|
|
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.FunNewCommand = void 0;
|
|
28
|
+
const fs_1 = __importDefault(require("fs"));
|
|
29
|
+
const path_1 = __importDefault(require("path"));
|
|
30
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
31
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
32
|
+
const base_1 = require("../../core/base");
|
|
33
|
+
const decorators_1 = require("../../decorators");
|
|
34
|
+
const templates_1 = require("../../utils/templates");
|
|
35
|
+
let FunNewCommand = class FunNewCommand extends base_1.Command {
|
|
36
|
+
execute(options, log) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
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
|
+
}
|
|
50
|
+
if (!projectName) {
|
|
51
|
+
log.error("项目名称不能为空");
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
54
|
+
const targetDir = dir || process.cwd();
|
|
55
|
+
const projectDir = path_1.default.join(targetDir, projectName);
|
|
56
|
+
if (fs_1.default.existsSync(projectDir)) {
|
|
57
|
+
log.error(`项目目录已存在: ${projectDir}`);
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
const templateId = yield (0, templates_1.selectTemplate)("cloud-dev", { template });
|
|
61
|
+
const templateDir = (0, templates_1.resolveTemplatePath)("cloud-dev", templateId);
|
|
62
|
+
if (!fs_1.default.existsSync(templateDir)) {
|
|
63
|
+
log.error(`模板目录不存在: ${templateDir}`);
|
|
64
|
+
throw new Error(`模板目录不存在: ${templateDir}`);
|
|
65
|
+
}
|
|
66
|
+
log.breakLine();
|
|
67
|
+
console.log(chalk_1.default.bold.blue("📋 云函数项目创建信息"));
|
|
68
|
+
console.log(chalk_1.default.gray("─".repeat(40)));
|
|
69
|
+
console.log(chalk_1.default.bold("创建目录: ") + chalk_1.default.green(projectDir));
|
|
70
|
+
console.log(chalk_1.default.bold("目录名称: ") + chalk_1.default.cyan(projectName));
|
|
71
|
+
console.log(chalk_1.default.bold("使用模板: ") + chalk_1.default.cyan(templateId));
|
|
72
|
+
console.log(chalk_1.default.gray("─".repeat(40)));
|
|
73
|
+
log.breakLine();
|
|
74
|
+
const spinnerCopy = require("ora")("复制模板文件...").start();
|
|
75
|
+
try {
|
|
76
|
+
yield this.copyTemplate(templateDir, projectDir);
|
|
77
|
+
spinnerCopy.succeed("模板文件复制完成");
|
|
78
|
+
}
|
|
79
|
+
catch (e) {
|
|
80
|
+
spinnerCopy.fail("模板文件复制失败: " + e.message);
|
|
81
|
+
throw e;
|
|
82
|
+
}
|
|
83
|
+
log.breakLine();
|
|
84
|
+
log.info(`✔️ 云函数项目创建成功: ${projectDir}`);
|
|
85
|
+
log.info("下一步操作:");
|
|
86
|
+
log.info(` - cd ${projectDir}`);
|
|
87
|
+
log.info(" - npm install");
|
|
88
|
+
log.info(" - npm run dev");
|
|
89
|
+
log.breakLine();
|
|
90
|
+
console.log(chalk_1.default.bgYellow.black(" ⚠️ 重要:配置云环境 "));
|
|
91
|
+
console.log(chalk_1.default.yellow("云函数发布前需指定目标云环境:"));
|
|
92
|
+
console.log(chalk_1.default.gray(" • 前往开放平台创建云环境(若尚未创建)"));
|
|
93
|
+
console.log(chalk_1.default.cyan(" • rcb env list — 查看当前账号下的云环境列表"));
|
|
94
|
+
console.log(chalk_1.default.cyan(" • rcb env set -e <envId> — 指定当前云函数要发布的环境"));
|
|
95
|
+
log.breakLine();
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
copyTemplate(sourceDir, targetDir) {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
if (!fs_1.default.existsSync(targetDir)) {
|
|
101
|
+
fs_1.default.mkdirSync(targetDir, { recursive: true });
|
|
102
|
+
}
|
|
103
|
+
const files = fs_1.default.readdirSync(sourceDir);
|
|
104
|
+
for (const file of files) {
|
|
105
|
+
const sourcePath = path_1.default.join(sourceDir, file);
|
|
106
|
+
const targetPath = path_1.default.join(targetDir, file);
|
|
107
|
+
const stat = fs_1.default.statSync(sourcePath);
|
|
108
|
+
if (stat.isDirectory()) {
|
|
109
|
+
yield this.copyTemplate(sourcePath, targetPath);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
fs_1.default.copyFileSync(sourcePath, targetPath);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
get options() {
|
|
118
|
+
return {
|
|
119
|
+
cmd: "fun",
|
|
120
|
+
childCmd: "new",
|
|
121
|
+
desc: "创建新的云函数项目",
|
|
122
|
+
usage: "rcb fun new [projectName]",
|
|
123
|
+
options: [
|
|
124
|
+
{
|
|
125
|
+
flags: "-d, --dir <dir>",
|
|
126
|
+
desc: "指定项目创建的目标目录,默认为当前目录",
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
flags: "-p, --projectName <projectName>",
|
|
130
|
+
desc: "指定项目名称,默认为当前目录名称",
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
flags: "-t, --template <template>",
|
|
134
|
+
desc: "指定模板 ID,不传则交互式选择",
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
exports.FunNewCommand = FunNewCommand;
|
|
141
|
+
__decorate([
|
|
142
|
+
(0, decorators_1.InjectParams)(),
|
|
143
|
+
__param(0, (0, decorators_1.ArgsOptions)()),
|
|
144
|
+
__param(1, (0, decorators_1.Log)()),
|
|
145
|
+
__metadata("design:type", Function),
|
|
146
|
+
__metadata("design:paramtypes", [Object, Function]),
|
|
147
|
+
__metadata("design:returntype", Promise)
|
|
148
|
+
], FunNewCommand.prototype, "execute", null);
|
|
149
|
+
exports.FunNewCommand = FunNewCommand = __decorate([
|
|
150
|
+
(0, base_1.ICommand)()
|
|
151
|
+
], FunNewCommand);
|
package/lib/commands/index.js
CHANGED
|
@@ -16,3 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./auth"), exports);
|
|
18
18
|
__exportStar(require("./agent"), exports);
|
|
19
|
+
__exportStar(require("./fun"), exports);
|
|
20
|
+
__exportStar(require("./env"), exports);
|
package/lib/constants/cmd.js
CHANGED
|
@@ -25,13 +25,13 @@ exports.ALL_COMMANDS = [
|
|
|
25
25
|
"env domain list",
|
|
26
26
|
"env domain create",
|
|
27
27
|
"env domain delete",
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
28
|
+
"fun list",
|
|
29
|
+
"fun download",
|
|
30
|
+
"fun deploy",
|
|
31
|
+
"fun delete",
|
|
32
|
+
"fun detail",
|
|
33
|
+
"fun code update",
|
|
34
|
+
"fun invoke",
|
|
35
|
+
"fun publish-version",
|
|
36
|
+
"fun list-function-versions",
|
|
37
37
|
];
|
package/lib/core/base.js
CHANGED
|
@@ -8,10 +8,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.Command = exports.registrableCommands = void 0;
|
|
13
16
|
exports.ICommand = ICommand;
|
|
17
|
+
const cloud_toolkit_1 = require("@vectorx/cloud-toolkit");
|
|
14
18
|
const commander_1 = require("commander");
|
|
19
|
+
const ora_1 = __importDefault(require("ora"));
|
|
15
20
|
exports.registrableCommands = [];
|
|
16
21
|
function ICommand() {
|
|
17
22
|
return (target) => {
|
|
@@ -23,6 +28,11 @@ class Command {
|
|
|
23
28
|
init() {
|
|
24
29
|
const { cmd, childCmd, childSubCmd, deprecateCmd } = this.options;
|
|
25
30
|
let instance;
|
|
31
|
+
const mainCommandDescriptions = {
|
|
32
|
+
agent: "开发与构建 AI Agent",
|
|
33
|
+
fun: "管理 Fun 云函数调试与部署",
|
|
34
|
+
env: "管理云环境(Environment)",
|
|
35
|
+
};
|
|
26
36
|
if (cmdMap.has(cmd)) {
|
|
27
37
|
instance = cmdMap.get(cmd);
|
|
28
38
|
}
|
|
@@ -30,6 +40,9 @@ class Command {
|
|
|
30
40
|
instance = commander_1.program.command(cmd);
|
|
31
41
|
instance._helpDescription = "输出帮助信息";
|
|
32
42
|
instance.addHelpCommand("help [command]", "查看命令帮助信息");
|
|
43
|
+
if (childCmd && mainCommandDescriptions[cmd]) {
|
|
44
|
+
instance.description(mainCommandDescriptions[cmd]);
|
|
45
|
+
}
|
|
33
46
|
cmdMap.set(cmd, instance);
|
|
34
47
|
}
|
|
35
48
|
if (childCmd) {
|
|
@@ -85,10 +98,79 @@ class Command {
|
|
|
85
98
|
});
|
|
86
99
|
instance.description(desc);
|
|
87
100
|
instance.action((...args) => __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
const loading = (0, ora_1.default)({ text: "执行中...", color: "cyan" }).start();
|
|
88
102
|
const params = args.slice(0, -1);
|
|
103
|
+
const commandObj = args[args.length - 1];
|
|
89
104
|
const cmdOptions = instance.opts();
|
|
105
|
+
const normalizeCmdPath = (raw) => {
|
|
106
|
+
var _a, _b;
|
|
107
|
+
const parts = String(raw || "")
|
|
108
|
+
.trim()
|
|
109
|
+
.split(/\s+/)
|
|
110
|
+
.filter(Boolean);
|
|
111
|
+
if (!parts.length)
|
|
112
|
+
return cmd;
|
|
113
|
+
const head = (_b = (_a = parts[0]) === null || _a === void 0 ? void 0 : _a.toLowerCase) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
114
|
+
if (head === "rcb" || head === "tcb") {
|
|
115
|
+
parts.shift();
|
|
116
|
+
}
|
|
117
|
+
return parts.join(" ");
|
|
118
|
+
};
|
|
119
|
+
const buildFullCmdPath = () => {
|
|
120
|
+
const { childCmd, childSubCmd } = this.options;
|
|
121
|
+
const cmdParts = [cmd];
|
|
122
|
+
if (childCmd) {
|
|
123
|
+
const childCmdName = typeof childCmd === "string" ? childCmd : childCmd.cmd;
|
|
124
|
+
cmdParts.push(childCmdName);
|
|
125
|
+
}
|
|
126
|
+
if (childSubCmd) {
|
|
127
|
+
cmdParts.push(childSubCmd);
|
|
128
|
+
}
|
|
129
|
+
return cmdParts.join(" ");
|
|
130
|
+
};
|
|
131
|
+
const rawCmdPath = typeof (commandObj === null || commandObj === void 0 ? void 0 : commandObj.commandPath) === "function"
|
|
132
|
+
? commandObj.commandPath()
|
|
133
|
+
:
|
|
134
|
+
typeof (instance === null || instance === void 0 ? void 0 : instance.commandPath) === "function"
|
|
135
|
+
?
|
|
136
|
+
instance.commandPath()
|
|
137
|
+
: null;
|
|
138
|
+
let cmdPath = rawCmdPath ? normalizeCmdPath(rawCmdPath) : buildFullCmdPath();
|
|
139
|
+
const expectedParts = [cmd];
|
|
140
|
+
if (this.options.childCmd) {
|
|
141
|
+
expectedParts.push(typeof this.options.childCmd === "string"
|
|
142
|
+
? this.options.childCmd
|
|
143
|
+
: this.options.childCmd.cmd);
|
|
144
|
+
}
|
|
145
|
+
if (this.options.childSubCmd) {
|
|
146
|
+
expectedParts.push(this.options.childSubCmd);
|
|
147
|
+
}
|
|
148
|
+
const cmdPathParts = cmdPath.split(/\s+/).filter(Boolean);
|
|
149
|
+
if (cmdPathParts.length < expectedParts.length) {
|
|
150
|
+
cmdPath = buildFullCmdPath();
|
|
151
|
+
}
|
|
152
|
+
const optionsKeys = Object.keys(cmdOptions || {})
|
|
153
|
+
.filter((k) => !k.startsWith("_"))
|
|
154
|
+
.filter((k) => k !== "help" && k !== "version")
|
|
155
|
+
.filter((k) => typeof (cmdOptions === null || cmdOptions === void 0 ? void 0 : cmdOptions[k]) !== "undefined");
|
|
156
|
+
const tracker = (0, cloud_toolkit_1.createCliCommandTracker)({
|
|
157
|
+
cmd_path: cmdPath,
|
|
158
|
+
cmd_root: cmd,
|
|
159
|
+
params_count: params.length,
|
|
160
|
+
options_keys: optionsKeys,
|
|
161
|
+
});
|
|
162
|
+
const startTime = Date.now();
|
|
90
163
|
const ctx = { cmd, params, options: cmdOptions };
|
|
91
|
-
|
|
164
|
+
loading.stop();
|
|
165
|
+
try {
|
|
166
|
+
const res = yield this.execute(ctx);
|
|
167
|
+
tracker.reportSuccess(Date.now() - startTime);
|
|
168
|
+
return res;
|
|
169
|
+
}
|
|
170
|
+
catch (err) {
|
|
171
|
+
tracker.reportFail(Date.now() - startTime, err);
|
|
172
|
+
throw err;
|
|
173
|
+
}
|
|
92
174
|
}));
|
|
93
175
|
}
|
|
94
176
|
}
|
package/lib/decorators/auth.js
CHANGED
|
@@ -35,10 +35,17 @@ function AuthGuard() {
|
|
|
35
35
|
cloud_toolkit_1.logger.error(`Warning: 执行当前命令需要先登录~`);
|
|
36
36
|
cloud_toolkit_1.logger.breakLine();
|
|
37
37
|
console.log(chalk_1.default.yellow("💡提示:请先执行登录命令"));
|
|
38
|
-
console.log(chalk_1.default.gray(" 使用命令: ") +
|
|
38
|
+
console.log(chalk_1.default.gray(" 使用命令: ") +
|
|
39
|
+
chalk_1.default.cyan("rcb login --secretId <secretId> --secretKey <secretKey>"));
|
|
39
40
|
cloud_toolkit_1.logger.breakLine();
|
|
40
41
|
console.log(chalk_1.default.gray("🔗 获取登录秘钥:https://miniapp.xiaohongshu.com/console-panel"));
|
|
41
42
|
cloud_toolkit_1.logger.breakLine();
|
|
43
|
+
try {
|
|
44
|
+
(0, cloud_toolkit_1.reportCliException)("uncaughtException", new Error("Auth required: please login first"));
|
|
45
|
+
yield new Promise((r) => setTimeout(r, 250));
|
|
46
|
+
}
|
|
47
|
+
catch (_a) {
|
|
48
|
+
}
|
|
42
49
|
process.exit(1);
|
|
43
50
|
}
|
|
44
51
|
return originalExecute.call(this, ctx);
|
|
@@ -20,6 +20,7 @@ const CaptureError = () => (target, key, descriptor) => {
|
|
|
20
20
|
}
|
|
21
21
|
catch (e) {
|
|
22
22
|
const errMsg = (e === null || e === void 0 ? void 0 : e.message) || (typeof (e === null || e === void 0 ? void 0 : e.toString) === "function" ? e.toString() : "") || "Unknown Error";
|
|
23
|
+
throw e;
|
|
23
24
|
}
|
|
24
25
|
});
|
|
25
26
|
};
|
package/lib/main.js
CHANGED
|
@@ -11,10 +11,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.registerCommands = registerCommands;
|
|
13
13
|
require("reflect-metadata");
|
|
14
|
+
const cloud_toolkit_1 = require("@vectorx/cloud-toolkit");
|
|
14
15
|
const base_1 = require("./core/base");
|
|
15
16
|
require("./commands");
|
|
16
17
|
function registerCommands() {
|
|
17
18
|
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
try {
|
|
20
|
+
(0, cloud_toolkit_1.initCliApm)({
|
|
21
|
+
cliVersion: (process === null || process === void 0 ? void 0 : process.CLI_VERSION) || "unknown",
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
}
|
|
18
26
|
base_1.registrableCommands.forEach(({ Command }) => new Command().init());
|
|
19
27
|
});
|
|
20
28
|
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.checkAndGuideAgentProject = checkAndGuideAgentProject;
|
|
16
|
+
const fs_1 = __importDefault(require("fs"));
|
|
17
|
+
const path_1 = __importDefault(require("path"));
|
|
18
|
+
const cloud_toolkit_1 = require("@vectorx/cloud-toolkit");
|
|
19
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
20
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
21
|
+
const open_1 = __importDefault(require("open"));
|
|
22
|
+
const OPEN_PLATFORM_URL = "https://miniapp.xiaohongshu.com/app-choose";
|
|
23
|
+
function isPlaceholder(value) {
|
|
24
|
+
if (!value || !value.trim())
|
|
25
|
+
return true;
|
|
26
|
+
const v = value.trim();
|
|
27
|
+
return v.startsWith("[") || v.includes("从开放平台获取");
|
|
28
|
+
}
|
|
29
|
+
function readProjectConfig(workDir) {
|
|
30
|
+
const configPath = path_1.default.join(workDir, "project.config.json");
|
|
31
|
+
if (!fs_1.default.existsSync(configPath))
|
|
32
|
+
return null;
|
|
33
|
+
try {
|
|
34
|
+
return JSON.parse(fs_1.default.readFileSync(configPath, "utf-8"));
|
|
35
|
+
}
|
|
36
|
+
catch (_a) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function writeProjectConfig(workDir, updates) {
|
|
41
|
+
var _a;
|
|
42
|
+
const configPath = path_1.default.join(workDir, "project.config.json");
|
|
43
|
+
const existing = (_a = readProjectConfig(workDir)) !== null && _a !== void 0 ? _a : {};
|
|
44
|
+
const next = Object.assign(Object.assign(Object.assign(Object.assign({}, existing), { agentId: updates.agentId }), (updates.name !== undefined ? { name: updates.name } : {})), (updates.desc !== undefined ? { desc: updates.desc } : {}));
|
|
45
|
+
fs_1.default.writeFileSync(configPath, JSON.stringify(next, null, 2), "utf-8");
|
|
46
|
+
}
|
|
47
|
+
function openUrl(url) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
try {
|
|
50
|
+
yield (0, open_1.default)(url);
|
|
51
|
+
}
|
|
52
|
+
catch (_a) {
|
|
53
|
+
console.log(chalk_1.default.cyan(`请手动访问:${url}`));
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function checkAndGuideAgentProject(workDir) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
var _a, _b, _c, _d, _e, _f;
|
|
60
|
+
const config = readProjectConfig(workDir);
|
|
61
|
+
if (!config || !("agentId" in config)) {
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
const rawAgentId = config.agentId;
|
|
65
|
+
if (isPlaceholder(rawAgentId)) {
|
|
66
|
+
console.log(chalk_1.default.yellow("\n⚠️ 检测到 project.config.json 中的 agentId 尚未配置,正在引导您关联智能体..."));
|
|
67
|
+
return yield selectAndBindAgent(workDir);
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
const detail = yield (0, cloud_toolkit_1.getAgentInfoById)(rawAgentId);
|
|
71
|
+
if (!detail) {
|
|
72
|
+
console.log(chalk_1.default.yellow(`\n⚠️ project.config.json 中的 agentId「${rawAgentId}」在当前账号下未找到,正在引导您重新关联...`));
|
|
73
|
+
return yield selectAndBindAgent(workDir);
|
|
74
|
+
}
|
|
75
|
+
const remoteName = (_a = detail.agentName) !== null && _a !== void 0 ? _a : "";
|
|
76
|
+
const remoteDesc = (_b = detail.description) !== null && _b !== void 0 ? _b : "";
|
|
77
|
+
const localName = (_c = config.name) !== null && _c !== void 0 ? _c : "";
|
|
78
|
+
const localDesc = (_d = config.desc) !== null && _d !== void 0 ? _d : "";
|
|
79
|
+
const localAgentId = (_e = config.agentId) !== null && _e !== void 0 ? _e : "";
|
|
80
|
+
const needsUpdate = localAgentId !== detail.agentId || localName !== remoteName || localDesc !== remoteDesc;
|
|
81
|
+
if (needsUpdate) {
|
|
82
|
+
writeProjectConfig(workDir, {
|
|
83
|
+
agentId: detail.agentId,
|
|
84
|
+
name: remoteName,
|
|
85
|
+
desc: remoteDesc,
|
|
86
|
+
});
|
|
87
|
+
console.log(chalk_1.default.green(`✅ 已同步 project.config.json(agentId: ${detail.agentId},name: ${remoteName || "(空)"},desc: ${remoteDesc || "(空)"})`));
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
console.log(chalk_1.default.gray(`ℹ️ project.config.json 与开放平台一致,无需更新(agentId: ${detail.agentId})`));
|
|
91
|
+
}
|
|
92
|
+
return detail.agentId;
|
|
93
|
+
}
|
|
94
|
+
catch (err) {
|
|
95
|
+
console.warn(chalk_1.default.yellow(`\n⚠️ 校验 agentId 时出现错误(${(_f = err === null || err === void 0 ? void 0 : err.message) !== null && _f !== void 0 ? _f : String(err)}),将跳过校验直接启动。`));
|
|
96
|
+
return rawAgentId;
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
function selectAndBindAgent(workDir) {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
var _a, _b, _c, _d;
|
|
103
|
+
let agentList = [];
|
|
104
|
+
try {
|
|
105
|
+
agentList = yield (0, cloud_toolkit_1.getAgentList)({ pageNo: 1, pageSize: 50 });
|
|
106
|
+
}
|
|
107
|
+
catch (err) {
|
|
108
|
+
console.warn(chalk_1.default.yellow(`\n⚠️ 获取智能体列表失败(${(_a = err === null || err === void 0 ? void 0 : err.message) !== null && _a !== void 0 ? _a : String(err)}),将跳过关联直接启动。`));
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
if (!agentList || agentList.length === 0) {
|
|
112
|
+
console.log("");
|
|
113
|
+
console.log(chalk_1.default.bold.yellow("你好,您当前的账号下没有智能体,请先去开放平台创建智能体:"));
|
|
114
|
+
console.log(chalk_1.default.cyan(OPEN_PLATFORM_URL));
|
|
115
|
+
console.log("");
|
|
116
|
+
yield openUrl(OPEN_PLATFORM_URL);
|
|
117
|
+
process.exit(0);
|
|
118
|
+
}
|
|
119
|
+
let selectedId;
|
|
120
|
+
if (agentList.length === 1) {
|
|
121
|
+
const only = agentList[0];
|
|
122
|
+
selectedId = only.agentId;
|
|
123
|
+
console.log(chalk_1.default.green(`\n✅ 检测到您账号下只有一个智能体,已自动关联:${only.agentName}(${only.agentId})`));
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
console.log("");
|
|
127
|
+
const { chosenId } = yield inquirer_1.default.prompt([
|
|
128
|
+
{
|
|
129
|
+
type: "list",
|
|
130
|
+
name: "chosenId",
|
|
131
|
+
message: "检测到您账号下有多个智能体,请选择要开发的智能体:",
|
|
132
|
+
choices: agentList.map((a) => ({
|
|
133
|
+
name: `${a.agentName} ${chalk_1.default.gray(`(${a.agentId})`)}`,
|
|
134
|
+
value: a.agentId,
|
|
135
|
+
})),
|
|
136
|
+
},
|
|
137
|
+
]);
|
|
138
|
+
selectedId = chosenId;
|
|
139
|
+
}
|
|
140
|
+
try {
|
|
141
|
+
const detail = yield (0, cloud_toolkit_1.getAgentInfoById)(selectedId);
|
|
142
|
+
if (detail) {
|
|
143
|
+
writeProjectConfig(workDir, {
|
|
144
|
+
agentId: detail.agentId,
|
|
145
|
+
name: (_b = detail.agentName) !== null && _b !== void 0 ? _b : "",
|
|
146
|
+
desc: (_c = detail.description) !== null && _c !== void 0 ? _c : "",
|
|
147
|
+
});
|
|
148
|
+
console.log(chalk_1.default.green(`✅ project.config.json 已更新(agentId: ${detail.agentId},name: ${detail.agentName || "(空)"},desc: ${detail.description || "(空)"})`));
|
|
149
|
+
return detail.agentId;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
catch (err) {
|
|
153
|
+
console.warn(chalk_1.default.yellow(`\n⚠️ 获取智能体详情失败(${(_d = err === null || err === void 0 ? void 0 : err.message) !== null && _d !== void 0 ? _d : String(err)}),将直接写入 agentId。`));
|
|
154
|
+
}
|
|
155
|
+
writeProjectConfig(workDir, { agentId: selectedId });
|
|
156
|
+
return selectedId;
|
|
157
|
+
});
|
|
158
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.TEMPLATE_CATEGORIES = void 0;
|
|
16
|
+
exports.loadTemplatesConfig = loadTemplatesConfig;
|
|
17
|
+
exports.resolveTemplatePath = resolveTemplatePath;
|
|
18
|
+
exports.selectTemplate = selectTemplate;
|
|
19
|
+
const fs_1 = __importDefault(require("fs"));
|
|
20
|
+
const path_1 = __importDefault(require("path"));
|
|
21
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
22
|
+
const TEMPLATES_ROOT = path_1.default.join(__dirname, "../../templates");
|
|
23
|
+
exports.TEMPLATE_CATEGORIES = {
|
|
24
|
+
"cloud-agents": path_1.default.join(TEMPLATES_ROOT, "cloud-agents"),
|
|
25
|
+
"cloud-dev": path_1.default.join(TEMPLATES_ROOT, "cloud-dev"),
|
|
26
|
+
};
|
|
27
|
+
function loadTemplatesConfig(category) {
|
|
28
|
+
const categoryDir = exports.TEMPLATE_CATEGORIES[category];
|
|
29
|
+
const configPath = path_1.default.join(categoryDir, "templates.json");
|
|
30
|
+
if (!fs_1.default.existsSync(configPath)) {
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
const content = fs_1.default.readFileSync(configPath, "utf-8");
|
|
35
|
+
const config = JSON.parse(content);
|
|
36
|
+
if (!Array.isArray(config.templates))
|
|
37
|
+
return [];
|
|
38
|
+
return config.templates.filter((t) => {
|
|
39
|
+
const templateDir = path_1.default.join(categoryDir, t.id);
|
|
40
|
+
return fs_1.default.existsSync(templateDir) && fs_1.default.statSync(templateDir).isDirectory();
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
catch (_a) {
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function resolveTemplatePath(category, templateId) {
|
|
48
|
+
return path_1.default.join(exports.TEMPLATE_CATEGORIES[category], templateId);
|
|
49
|
+
}
|
|
50
|
+
function selectTemplate(category, options) {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
const templates = loadTemplatesConfig(category);
|
|
53
|
+
if (templates.length === 0) {
|
|
54
|
+
throw new Error(`未找到可用模板,请检查 ${exports.TEMPLATE_CATEGORIES[category]}/templates.json`);
|
|
55
|
+
}
|
|
56
|
+
if (options.template) {
|
|
57
|
+
const found = templates.find((t) => t.id === options.template);
|
|
58
|
+
if (found)
|
|
59
|
+
return found.id;
|
|
60
|
+
throw new Error(`模板 "${options.template}" 不存在。可用: ${templates.map((t) => t.id).join(", ")}`);
|
|
61
|
+
}
|
|
62
|
+
const { templateId } = yield inquirer_1.default.prompt([
|
|
63
|
+
{
|
|
64
|
+
type: "list",
|
|
65
|
+
name: "templateId",
|
|
66
|
+
message: "请选择模板:",
|
|
67
|
+
choices: templates.map((t) => ({
|
|
68
|
+
name: `${t.name} - ${t.desc}`,
|
|
69
|
+
value: t.id,
|
|
70
|
+
})),
|
|
71
|
+
},
|
|
72
|
+
]);
|
|
73
|
+
return templateId;
|
|
74
|
+
});
|
|
75
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vectorx/xhs-cloud-cli",
|
|
3
|
-
"version": "0.0.0-beta-
|
|
3
|
+
"version": "0.0.0-beta-20260320063305",
|
|
4
4
|
"description": "xhs-cloud-cli 主要用于如下场景: - agent 调试、发布 - cloud 云函数的调试、部署",
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": ">=20.0.0"
|
|
7
|
+
},
|
|
5
8
|
"main": "lib/index.js",
|
|
6
9
|
"types": "types/index.d.ts",
|
|
7
10
|
"bin": {
|
|
@@ -16,9 +19,6 @@
|
|
|
16
19
|
],
|
|
17
20
|
"dependencies": {
|
|
18
21
|
"@koa/router": "^12.0.1",
|
|
19
|
-
"@vectorx/agent-simulator": "0.0.0-beta-20260108133839",
|
|
20
|
-
"@vectorx/cloud-toolkit": "0.0.0-beta-20260108133839",
|
|
21
|
-
"@vectorx/functions-framework": "0.0.0-beta-20260108133839",
|
|
22
22
|
"address": "^1.1.2",
|
|
23
23
|
"archiver": "^6.0.1",
|
|
24
24
|
"camelcase-keys": "^7.0.2",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"execa": "^4.0.3",
|
|
35
35
|
"fs-extra": "^8.1.0",
|
|
36
36
|
"https-proxy-agent": "^5.0.1",
|
|
37
|
-
"inquirer": "^6.5.
|
|
37
|
+
"inquirer": "^6.5.2",
|
|
38
38
|
"inversify": "^7.5.2",
|
|
39
39
|
"json-schema-to-typescript": "^14.0.5",
|
|
40
40
|
"koa": "^2.16.1",
|
|
@@ -65,12 +65,16 @@
|
|
|
65
65
|
"ws": "^8.18.2",
|
|
66
66
|
"xdg-basedir": "^4.0.0",
|
|
67
67
|
"yargs": "^16.2.0",
|
|
68
|
-
"yargs-parser": "^21.0.1"
|
|
68
|
+
"yargs-parser": "^21.0.1",
|
|
69
|
+
"@vectorx/agent-simulator": "0.0.0-beta-20260320063305",
|
|
70
|
+
"@vectorx/cloud-toolkit": "0.0.0-beta-20260320063305",
|
|
71
|
+
"@vectorx/function-debugger": "0.0.0-beta-20260320063305",
|
|
72
|
+
"@vectorx/functions-framework": "0.0.0-beta-20260320063305"
|
|
69
73
|
},
|
|
70
74
|
"devDependencies": {
|
|
71
75
|
"@types/archiver": "^5.3.2",
|
|
72
76
|
"@types/fs-extra": "^11.0.4",
|
|
73
|
-
"@types/inquirer": "^9.0.
|
|
77
|
+
"@types/inquirer": "^9.0.9",
|
|
74
78
|
"@types/jest": "^27",
|
|
75
79
|
"@types/koa": "^2.13.12",
|
|
76
80
|
"@types/koa-bodyparser": "^4.3.12",
|
|
@@ -99,6 +103,5 @@
|
|
|
99
103
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
100
104
|
"dev": "rimraf lib types && tsc -w",
|
|
101
105
|
"gen:command": "ts-node scripts/generate-command.ts"
|
|
102
|
-
}
|
|
103
|
-
"readme": "# xhs cloud 命令行工具\nxhs-cloud-cli 主要用于如下场景:\n - agent 调试、发布\n - cloud 云函数的调试、部署\n\n使用方式:\n - xhs-cloud-cli agent dev \n\n - xhs-cloud-cli cloud dev\n\n## 安装 CloudBase CLI\n\nsrc/\n├── commands/\n│ └── agent/\n│ └── dev.ts # agent dev 命令实现\n├── core/\n│ └── server/\n│ ├── server.node.ts # Koa 服务器实现\n│ └── function-loader.ts # 函数加载器实现\n\n### npm\n\n```shell\nnpm install -g @cloudbase/cli\n```\n\n## 命令\n> xhs-cloud-cli\n\n## 命令\n- deploy\n- dev\n\n"
|
|
106
|
+
}
|
|
104
107
|
}
|
|
@@ -10,7 +10,6 @@ let test_answer = "你好,我是开放平台智能体,我可以为你做很
|
|
|
10
10
|
*/
|
|
11
11
|
class MyAgent extends AgentRuntime {
|
|
12
12
|
async sendMessage(message) {
|
|
13
|
-
console.log("==== message ====", JSON.stringify(message, null, 2));
|
|
14
13
|
return new Promise((res) => {
|
|
15
14
|
const charArr = test_answer.split("")
|
|
16
15
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# 环境变量模板,复制为 .env 后填写
|