@vectorx/xhs-cloud-cli 0.0.0-beta-20260109055258 → 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
package/bin/rcb.js
CHANGED
|
@@ -5,8 +5,6 @@ const { program } = require("commander");
|
|
|
5
5
|
const logSymbols = require("log-symbols");
|
|
6
6
|
const didYouMean = require("didyoumean");
|
|
7
7
|
const updateNotifier = require("update-notifier");
|
|
8
|
-
const { Confirm } = require("enquirer");
|
|
9
|
-
const execa = require("execa");
|
|
10
8
|
const semver = require("semver");
|
|
11
9
|
const { registerCommands, ALL_COMMANDS } = require("../lib");
|
|
12
10
|
|
|
@@ -32,17 +30,55 @@ async function main() {
|
|
|
32
30
|
process.exit(1);
|
|
33
31
|
}
|
|
34
32
|
|
|
35
|
-
// 输出版本信息
|
|
36
|
-
console.log(chalk.gray(`RedCloudBase CLI ${pkg.version}`));
|
|
37
|
-
console.log(`[API Config] Env: ${process.env.AGENT_BUILD_ENV || 'production'}`);
|
|
38
|
-
|
|
39
33
|
const yargsParsedResult = yargsParser(process.argv.slice(2));
|
|
40
34
|
|
|
35
|
+
// 检查是否是版本请求,如果是则自定义输出
|
|
36
|
+
if (process.argv.includes("-V") || process.argv.includes("--version")) {
|
|
37
|
+
const version = pkg.version;
|
|
38
|
+
const isBeta = version.indexOf("-") > -1;
|
|
39
|
+
const versionColor = isBeta ? chalk.yellow : chalk.green;
|
|
40
|
+
|
|
41
|
+
console.log();
|
|
42
|
+
console.log(
|
|
43
|
+
chalk.cyan.bold(" ╭─────────────────────────────────╮")
|
|
44
|
+
);
|
|
45
|
+
console.log(
|
|
46
|
+
chalk.cyan.bold(" │"),
|
|
47
|
+
chalk.white.bold(" rcb"),
|
|
48
|
+
chalk.gray("v"),
|
|
49
|
+
versionColor.bold(version),
|
|
50
|
+
isBeta ? chalk.yellow(" (beta)") : "",
|
|
51
|
+
chalk.cyan.bold(" │")
|
|
52
|
+
);
|
|
53
|
+
console.log(
|
|
54
|
+
chalk.cyan.bold(" │"),
|
|
55
|
+
chalk.gray(" 小红书云服务 CLI"),
|
|
56
|
+
chalk.cyan.bold(" │")
|
|
57
|
+
);
|
|
58
|
+
console.log(
|
|
59
|
+
chalk.cyan.bold(" ╰─────────────────────────────────╯")
|
|
60
|
+
);
|
|
61
|
+
console.log();
|
|
62
|
+
process.exit(0);
|
|
63
|
+
}
|
|
64
|
+
|
|
41
65
|
await registerCommands();
|
|
42
66
|
|
|
43
|
-
// 设置 options
|
|
67
|
+
// 设置 options 选项(必须在添加任何选项之前调用)
|
|
44
68
|
program.storeOptionsAsProperties(false);
|
|
45
|
-
|
|
69
|
+
|
|
70
|
+
// 配置 commander 帮助格式,对齐 nrm 格式
|
|
71
|
+
program
|
|
72
|
+
.name("rcb")
|
|
73
|
+
.description("小红书云服务 CLI,用于 agent 调试、发布和 cloud 云函数的调试、部署")
|
|
74
|
+
.usage("[options] [command]")
|
|
75
|
+
.version(pkg.version, "-V, --version", "output the version number");
|
|
76
|
+
|
|
77
|
+
// 配置帮助输出格式
|
|
78
|
+
program.configureHelp({
|
|
79
|
+
sortSubcommands: true,
|
|
80
|
+
subcommandTerm: (cmd) => cmd.name(),
|
|
81
|
+
});
|
|
46
82
|
|
|
47
83
|
const isCommandEmpty = yargsParsedResult._.length === 0;
|
|
48
84
|
|
|
@@ -63,9 +99,8 @@ async function main() {
|
|
|
63
99
|
console.log(`💡使用 ${chalk.bold("rcb -h")} 查看所有命令`);
|
|
64
100
|
});
|
|
65
101
|
|
|
66
|
-
//
|
|
102
|
+
// 没有使用命令时,直接输出帮助信息
|
|
67
103
|
if (isCommandEmpty) {
|
|
68
|
-
program.outputHelp();
|
|
69
104
|
// 需要隐藏的选项
|
|
70
105
|
const hideArgs = ["-h", "--help"];
|
|
71
106
|
hideArgs.forEach((arg) => {
|
|
@@ -74,8 +109,8 @@ async function main() {
|
|
|
74
109
|
processArgv.splice(index, 1);
|
|
75
110
|
}
|
|
76
111
|
});
|
|
77
|
-
|
|
78
|
-
|
|
112
|
+
// 使用 commander 内置的帮助输出
|
|
113
|
+
program.outputHelp();
|
|
79
114
|
}
|
|
80
115
|
|
|
81
116
|
try {
|
|
@@ -87,151 +122,6 @@ async function main() {
|
|
|
87
122
|
console.log(errMsg);
|
|
88
123
|
}
|
|
89
124
|
|
|
90
|
-
/**
|
|
91
|
-
* 处理异常
|
|
92
|
-
*/
|
|
93
|
-
async function errorHandler(err) {
|
|
94
|
-
process.emit("processExit");
|
|
95
|
-
|
|
96
|
-
// 3 空格,兼容中文字符编码长度问题
|
|
97
|
-
if (err && err.message) {
|
|
98
|
-
let errMsg = logSymbols.error + " " + err.message;
|
|
99
|
-
errMsg += err.requestId ? `\n${err.requestId}` : "";
|
|
100
|
-
console.log(errMsg);
|
|
101
|
-
|
|
102
|
-
// 多地域错误提示
|
|
103
|
-
if (errMsg.includes("Environment") && errMsg.includes("not found")) {
|
|
104
|
-
// 检查是否已经指定了 -r 或 --region 参数,如未指定则尝试获取地域信息
|
|
105
|
-
const regionSpecified =
|
|
106
|
-
processArgv.indexOf("-r") !== -1 ||
|
|
107
|
-
processArgv.indexOf("--region") !== -1;
|
|
108
|
-
const region = yargsParsedResult.r || yargsParsedResult.region;
|
|
109
|
-
const multiRegionErrMsg = `\n此环境可能不属于当前账号,或为非${
|
|
110
|
-
regionSupportedMap[region] || "上海"
|
|
111
|
-
}地域环境,如需切换地域请追加参数(例:-r gz),请检查环境归属,参考多地域使用方法:https://docs.cloudbase.net/cli-v1/region.html`;
|
|
112
|
-
if (!regionSpecified) {
|
|
113
|
-
// 从 -e 参数、--envId 参数和配置文件中获取环境 id
|
|
114
|
-
const envId =
|
|
115
|
-
yargsParsedResult.e || yargsParsedResult.envId || config.envId;
|
|
116
|
-
|
|
117
|
-
// 调用 API 接口尝试查询环境信息
|
|
118
|
-
const predictRegion = await tryTellEnvRegion(envId);
|
|
119
|
-
|
|
120
|
-
if (regionSupported.includes(predictRegion)) {
|
|
121
|
-
// 让用户选择是否切换地域
|
|
122
|
-
const prompt = new Confirm({
|
|
123
|
-
type: "confirm",
|
|
124
|
-
name: "confirm",
|
|
125
|
-
message: `该环境可能属于 ${regionSupportedMap[predictRegion]} 地域,是否切换地域并重新执行命令?`,
|
|
126
|
-
initial: "Y",
|
|
127
|
-
});
|
|
128
|
-
const confirm = await prompt.run();
|
|
129
|
-
if (confirm) {
|
|
130
|
-
// 检查原始命令是否已经追加了 -r 参数,如果有则替换,如果没有则追加
|
|
131
|
-
const regionArgIndex = processArgv.indexOf("-r");
|
|
132
|
-
if (regionArgIndex !== -1) {
|
|
133
|
-
processArgv[regionArgIndex + 1] = predictRegion;
|
|
134
|
-
} else {
|
|
135
|
-
processArgv.push("-r", predictRegion);
|
|
136
|
-
}
|
|
137
|
-
// 重新执行命令
|
|
138
|
-
const newArgvStr = processArgv.slice(2).join(" ");
|
|
139
|
-
console.log(
|
|
140
|
-
`\n${chalk.yellow.bold(
|
|
141
|
-
"正在重新执行命令:"
|
|
142
|
-
)} tcb ${newArgvStr}\n`
|
|
143
|
-
);
|
|
144
|
-
await execa("tcb", processArgv.slice(2), {
|
|
145
|
-
stdio: "inherit",
|
|
146
|
-
});
|
|
147
|
-
process.emit("tcbExit");
|
|
148
|
-
process.exit(0);
|
|
149
|
-
} else {
|
|
150
|
-
console.log(chalk.yellow.bold(multiRegionErrMsg));
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
} else {
|
|
154
|
-
console.log(chalk.yellow.bold(multiRegionErrMsg));
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// 输出详细的错误信息
|
|
160
|
-
if (processArgv.includes("--verbose")) {
|
|
161
|
-
console.log(err);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
process.emit("processError");
|
|
165
|
-
setTimeout(() => {
|
|
166
|
-
process.exit(1);
|
|
167
|
-
}, 1000);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const isTokenExpired = (credential, gap = 120) =>
|
|
171
|
-
credential.accessTokenExpired &&
|
|
172
|
-
Number(credential.accessTokenExpired) < Date.now() + gap * 1000;
|
|
173
|
-
|
|
174
|
-
async function tryTellEnvRegion(envId) {
|
|
175
|
-
// 依次调用不同地域的 API 接口查询环境信息
|
|
176
|
-
const fetchedRegion = await Promise.all(
|
|
177
|
-
regionSupported.map(async (region) => {
|
|
178
|
-
const { EnvList = [] } = await fetchEnvInfoWithRegion(envId, region);
|
|
179
|
-
if (
|
|
180
|
-
EnvList.length !== 0 &&
|
|
181
|
-
EnvList.find((item) => item.EnvId === envId)
|
|
182
|
-
) {
|
|
183
|
-
return res.EnvList[0].Region;
|
|
184
|
-
}
|
|
185
|
-
return "";
|
|
186
|
-
})
|
|
187
|
-
);
|
|
188
|
-
|
|
189
|
-
let predictRegion = "";
|
|
190
|
-
fetchedRegion.forEach((region) => {
|
|
191
|
-
if (region) {
|
|
192
|
-
predictRegion = region;
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
return predictRegion;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// 在指定地域调用 API 接口查询环境信息
|
|
199
|
-
async function fetchEnvInfoWithRegion(envId, region) {
|
|
200
|
-
let commonCredential = {};
|
|
201
|
-
const commonOpts = {
|
|
202
|
-
service: "tcb",
|
|
203
|
-
version: "2019-09-24",
|
|
204
|
-
proxy: getProxy(),
|
|
205
|
-
timeout: 15000,
|
|
206
|
-
getCredential: async () => {
|
|
207
|
-
if (commonCredential.secretId && !isTokenExpired(commonCredential)) {
|
|
208
|
-
return commonCredential;
|
|
209
|
-
}
|
|
210
|
-
const credential = await getCredentialWithoutCheck();
|
|
211
|
-
if (!credential) {
|
|
212
|
-
throw new Error("无有效身份信息,请使用 cloudbase login 登录");
|
|
213
|
-
}
|
|
214
|
-
commonCredential = credential;
|
|
215
|
-
return {
|
|
216
|
-
...credential,
|
|
217
|
-
tokenExpired: Number(credential.accessTokenExpired),
|
|
218
|
-
};
|
|
219
|
-
},
|
|
220
|
-
};
|
|
221
|
-
const apiName = "DescribeEnvs";
|
|
222
|
-
const tcbApi = new CloudApiService({
|
|
223
|
-
...commonOpts,
|
|
224
|
-
region,
|
|
225
|
-
});
|
|
226
|
-
const res = await tcbApi.request(apiName, {
|
|
227
|
-
EnvId: envId,
|
|
228
|
-
});
|
|
229
|
-
return res;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
process.on("uncaughtException", errorHandler);
|
|
233
|
-
process.on("unhandledRejection", errorHandler);
|
|
234
|
-
|
|
235
125
|
// 检查更新
|
|
236
126
|
const ONE_DAY = 86400000;
|
|
237
127
|
// Beta 版 1 个小时检查一次,稳定版 1 天检查一次
|
|
@@ -26,10 +26,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
27
|
exports.AgentDevCommand = void 0;
|
|
28
28
|
const fs_1 = __importDefault(require("fs"));
|
|
29
|
+
const agent_simulator_1 = require("@vectorx/agent-simulator");
|
|
29
30
|
const cloud_toolkit_1 = require("@vectorx/cloud-toolkit");
|
|
31
|
+
const App_1 = require("@vectorx/function-debugger/lib/App");
|
|
30
32
|
const chalk_1 = __importDefault(require("chalk"));
|
|
31
33
|
const base_1 = require("../../core/base");
|
|
32
34
|
const decorators_1 = require("../../decorators");
|
|
35
|
+
const agent_check_1 = require("../../utils/agent-check");
|
|
33
36
|
const prefix = chalk_1.default.bgGreenBright(" 🚀 [rcb-ff log] ");
|
|
34
37
|
let AgentDevCommand = class AgentDevCommand extends base_1.Command {
|
|
35
38
|
execute(options, log) {
|
|
@@ -38,25 +41,45 @@ let AgentDevCommand = class AgentDevCommand extends base_1.Command {
|
|
|
38
41
|
if (!fs_1.default.existsSync(workDir)) {
|
|
39
42
|
throw new Error(`目录不存在: ${workDir}`);
|
|
40
43
|
}
|
|
44
|
+
const useIde = options.useIde !== false;
|
|
45
|
+
const watch = options.watch !== false;
|
|
41
46
|
try {
|
|
42
|
-
|
|
47
|
+
yield (0, agent_check_1.checkAndGuideAgentProject)(workDir);
|
|
48
|
+
const { simulatorPort, ideUrl } = yield (0, cloud_toolkit_1.startDev)({
|
|
43
49
|
workDir,
|
|
44
50
|
port: options.port ? Number.parseInt(options.port) : undefined,
|
|
45
51
|
simulatorPort: options.simulatorport ? Number.parseInt(options.simulatorport) : undefined,
|
|
46
|
-
watch
|
|
52
|
+
watch,
|
|
47
53
|
open: false,
|
|
48
54
|
enableRedLangfuse: Boolean(options.enableRedLangfuse),
|
|
55
|
+
mode: "agent",
|
|
56
|
+
useIde,
|
|
57
|
+
deps: { AgentSimulator: agent_simulator_1.AgentSimulator, startFunctionDebugger: App_1.startFunctionDebugger },
|
|
49
58
|
});
|
|
50
59
|
if (options.open) {
|
|
51
|
-
|
|
52
|
-
|
|
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("开发环境启动完成!")}`);
|
|
53
77
|
}
|
|
54
|
-
log.info(`${prefix} ${chalk_1.default.greenBright("开发环境启动完成!")}`);
|
|
55
78
|
this.setupProcessCleanup(log);
|
|
56
79
|
}
|
|
57
80
|
catch (error) {
|
|
58
81
|
log.error(`${prefix} 启动开发环境失败: ${error.message}`);
|
|
59
|
-
|
|
82
|
+
process.exit(1);
|
|
60
83
|
}
|
|
61
84
|
});
|
|
62
85
|
}
|
|
@@ -93,12 +116,24 @@ let AgentDevCommand = class AgentDevCommand extends base_1.Command {
|
|
|
93
116
|
},
|
|
94
117
|
{
|
|
95
118
|
flags: "-w, --watch",
|
|
96
|
-
desc: "
|
|
119
|
+
desc: "启用文件监听模式,文件变化时自动重启服务(默认开启)",
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
flags: "--no-watch",
|
|
123
|
+
desc: "禁用文件监听模式",
|
|
97
124
|
},
|
|
98
125
|
{
|
|
99
126
|
flags: "--enableRedLangfuse",
|
|
100
127
|
desc: "开启 Red Langfuse 上报",
|
|
101
128
|
},
|
|
129
|
+
{
|
|
130
|
+
flags: "--use-ide",
|
|
131
|
+
desc: "使用 Web IDE 模式调试 Agent(默认开启)",
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
flags: "--no-use-ide",
|
|
135
|
+
desc: "禁用 Web IDE 模式,仅启动 Agent 模拟器",
|
|
136
|
+
},
|
|
102
137
|
],
|
|
103
138
|
};
|
|
104
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
|
-
|
|
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
|
}
|