@cloudbase/cli 2.10.0-beta.0 → 2.11.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/auth/login.js +51 -65
- package/lib/auth/logout.js +3 -14
- package/lib/commands/account/login.js +136 -149
- package/lib/commands/account/logout.js +3 -14
- package/lib/commands/ag/base.js +203 -0
- package/lib/commands/ag/create.js +301 -0
- package/lib/commands/ag/debug/index.html +699 -0
- package/lib/commands/ag/delete.js +200 -0
- package/lib/commands/ag/deploy.js +185 -0
- package/lib/commands/ag/detail.js +113 -0
- package/lib/commands/ag/index.js +22 -0
- package/lib/commands/ag/list.js +155 -0
- package/lib/commands/ag/run.js +644 -0
- package/lib/commands/ai/index.js +76 -95
- package/lib/commands/cloudfunction/base.js +182 -203
- package/lib/commands/cloudrun/base.js +578 -603
- package/lib/commands/common.js +48 -63
- package/lib/commands/config/delete.js +16 -27
- package/lib/commands/config/get.js +13 -24
- package/lib/commands/config/list.js +16 -27
- package/lib/commands/config/set.js +33 -44
- package/lib/commands/db/base.js +221 -240
- package/lib/commands/env/base.js +36 -49
- package/lib/commands/env/domain.js +79 -94
- package/lib/commands/env/login.js +120 -135
- package/lib/commands/framework/index.js +32 -49
- package/lib/commands/fun/base.js +223 -244
- package/lib/commands/functions/alias/getRoute.js +33 -44
- package/lib/commands/functions/alias/setRoute.js +36 -47
- package/lib/commands/functions/code-download.js +43 -54
- package/lib/commands/functions/code-update.js +23 -34
- package/lib/commands/functions/concurrency/delete.js +11 -22
- package/lib/commands/functions/concurrency/list.js +20 -31
- package/lib/commands/functions/concurrency/set.js +13 -24
- package/lib/commands/functions/config-update.js +30 -41
- package/lib/commands/functions/copy.js +12 -23
- package/lib/commands/functions/delete.js +30 -41
- package/lib/commands/functions/deploy.js +184 -202
- package/lib/commands/functions/detail.js +23 -34
- package/lib/commands/functions/invoke.js +69 -75
- package/lib/commands/functions/layer/bind.js +102 -105
- package/lib/commands/functions/layer/create.js +29 -35
- package/lib/commands/functions/layer/delete.js +42 -48
- package/lib/commands/functions/layer/download.js +52 -58
- package/lib/commands/functions/layer/list.js +44 -50
- package/lib/commands/functions/layer/sort.js +39 -45
- package/lib/commands/functions/list.js +25 -36
- package/lib/commands/functions/log.js +65 -73
- package/lib/commands/functions/run.js +118 -116
- package/lib/commands/functions/trigger-create.js +32 -43
- package/lib/commands/functions/trigger-delete.js +50 -61
- package/lib/commands/functions/version/list.js +29 -40
- package/lib/commands/functions/version/publish.js +11 -22
- package/lib/commands/gateway/create.js +50 -61
- package/lib/commands/gateway/delete.js +38 -49
- package/lib/commands/gateway/domain.js +65 -80
- package/lib/commands/gateway/list.js +31 -42
- package/lib/commands/gateway/switch.js +48 -61
- package/lib/commands/helpers/init.js +226 -249
- package/lib/commands/helpers/new.js +35 -46
- package/lib/commands/helpers/open.js +22 -33
- package/lib/commands/hosting/hosting.js +157 -178
- package/lib/commands/index.js +1 -0
- package/lib/commands/lowcode/app.js +114 -144
- package/lib/commands/lowcode/comps.js +136 -127
- package/lib/commands/lowcode/utils.js +11 -22
- package/lib/commands/pull/pull.js +33 -46
- package/lib/commands/run/delete.js +35 -46
- package/lib/commands/run/image/delete.js +32 -39
- package/lib/commands/run/image/download.js +26 -33
- package/lib/commands/run/image/list.js +41 -48
- package/lib/commands/run/image/upload.js +26 -33
- package/lib/commands/run/list.js +32 -43
- package/lib/commands/run/service/config.js +17 -28
- package/lib/commands/run/service/deploy.js +15 -26
- package/lib/commands/run/service/list.js +48 -59
- package/lib/commands/run/service/update.js +7 -18
- package/lib/commands/run/standalonegateway/create.js +35 -42
- package/lib/commands/run/standalonegateway/destroy.js +23 -30
- package/lib/commands/run/standalonegateway/list.js +19 -26
- package/lib/commands/run/standalonegateway/package.js +31 -38
- package/lib/commands/run/standalonegateway/turn.js +27 -34
- package/lib/commands/run/version/create.js +198 -205
- package/lib/commands/run/version/delete.js +31 -38
- package/lib/commands/run/version/list.js +42 -49
- package/lib/commands/run/version/modify.js +27 -34
- package/lib/commands/run/version/update.js +201 -208
- package/lib/commands/runf/base.js +216 -237
- package/lib/commands/self-update.js +59 -72
- package/lib/commands/smart.js +66 -79
- package/lib/commands/storage/storage.js +192 -219
- package/lib/commands/third/thirdAttach.js +16 -27
- package/lib/commands/utils.js +119 -149
- package/lib/db/index.js +48 -67
- package/lib/decorators/captureError.js +10 -21
- package/lib/decorators/guard.js +11 -22
- package/lib/decorators/injectParams.js +29 -40
- package/lib/decorators/params/common.js +5 -2
- package/lib/decorators/params/index.js +3 -12
- package/lib/env/domain.js +13 -28
- package/lib/env/index.js +25 -44
- package/lib/env/login.js +30 -45
- package/lib/function/alias.js +31 -44
- package/lib/function/base.js +187 -215
- package/lib/function/code.js +8 -19
- package/lib/function/concurrency.js +43 -58
- package/lib/function/create.js +43 -53
- package/lib/function/delete.js +22 -35
- package/lib/function/layer/attach.js +33 -46
- package/lib/function/layer/create.js +34 -45
- package/lib/function/layer/delete.js +5 -16
- package/lib/function/layer/download.js +11 -22
- package/lib/function/layer/list.js +12 -25
- package/lib/function/layer/sort.js +6 -17
- package/lib/function/trigger.js +65 -82
- package/lib/function/update.js +24 -32
- package/lib/function/version.js +29 -42
- package/lib/function/vpc.js +12 -25
- package/lib/gateway/index.js +77 -104
- package/lib/hosting.js +157 -188
- package/lib/run/delete.js +3 -12
- package/lib/run/image/build.js +6 -15
- package/lib/run/image/delete.js +3 -12
- package/lib/run/image/info.js +3 -12
- package/lib/run/image/list.js +6 -15
- package/lib/run/list.js +19 -30
- package/lib/run/repo.js +6 -15
- package/lib/run/service/common.js +160 -173
- package/lib/run/service/config.js +44 -57
- package/lib/run/service/deployPackage.js +33 -44
- package/lib/run/service/list.js +8 -14
- package/lib/run/service/showLogs.js +69 -90
- package/lib/run/service/update.js +50 -63
- package/lib/run/standalonegateway/create.js +3 -12
- package/lib/run/standalonegateway/destroy.js +3 -12
- package/lib/run/standalonegateway/list.js +3 -12
- package/lib/run/standalonegateway/package/list.js +3 -12
- package/lib/run/standalonegateway/turn/off.js +3 -12
- package/lib/run/standalonegateway/turn/on.js +3 -12
- package/lib/run/version/create.js +41 -31
- package/lib/run/version/delete.js +3 -12
- package/lib/run/version/list.js +3 -12
- package/lib/run/version/modify.js +3 -12
- package/lib/run/version/repo.js +6 -15
- package/lib/run/version/update.js +37 -26
- package/lib/storage.js +62 -93
- package/lib/third/index.js +6 -17
- package/lib/utils/ai/banner.js +49 -60
- package/lib/utils/ai/claudeWindows.js +2 -2
- package/lib/utils/ai/config.js +169 -206
- package/lib/utils/ai/ensureFiles.js +6 -17
- package/lib/utils/ai/env.js +16 -27
- package/lib/utils/ai/envLocalManager.js +35 -52
- package/lib/utils/ai/router.js +927 -1005
- package/lib/utils/ai/setup.js +527 -563
- package/lib/utils/auth.js +3 -14
- package/lib/utils/checkTcbrEnv.js +20 -31
- package/lib/utils/cli-table.js +6 -1
- package/lib/utils/config.js +4 -13
- package/lib/utils/dts.js +98 -113
- package/lib/utils/env.js +154 -175
- package/lib/utils/function-packer.js +29 -42
- package/lib/utils/log.js +10 -21
- package/lib/utils/mcp-config-modifier.js +105 -120
- package/lib/utils/net/cloud-api-request.js +15 -23
- package/lib/utils/net/credential.js +26 -39
- package/lib/utils/net/http-request.js +63 -80
- package/lib/utils/net/manager-service.js +22 -35
- package/lib/utils/notice.js +16 -27
- package/lib/utils/output/loading.js +3 -12
- package/lib/utils/parallel.js +32 -43
- package/lib/utils/platform/mac.js +4 -15
- package/lib/utils/platform/port.js +4 -15
- package/lib/utils/prompt/select.js +6 -15
- package/lib/utils/report.js +28 -33
- package/lib/utils/reporter/agree.js +11 -22
- package/lib/utils/reporter/download.js +17 -28
- package/lib/utils/reporter/usage.js +12 -23
- package/lib/utils/store/auth.js +17 -30
- package/lib/utils/store/config.js +11 -25
- package/lib/utils/store/db.js +17 -36
- package/lib/utils/tcbrApi/callTcbrApi.js +19 -28
- package/lib/utils/template-manager.js +215 -242
- package/lib/utils/template.js +81 -96
- package/lib/utils/tools/common.js +45 -56
- package/lib/utils/tools/time.js +5 -16
- package/lib/utils/url.js +10 -4
- package/package.json +2 -2
- package/specs/ag-command/design.md +421 -0
- package/specs/ag-command/doc.md +204 -0
- package/specs/ag-command/requirements.md +173 -0
- package/specs/ag-command/summary.md +174 -0
- package/specs/ag-command/tasks.md +197 -0
- package/specs/ag-command/usage-guide.md +420 -0
- package/tsconfig.json +1 -1
- package/types/commands/ag/base.d.ts +44 -0
- package/types/commands/ag/create.d.ts +25 -0
- package/types/commands/ag/delete.d.ts +32 -0
- package/types/commands/ag/deploy.d.ts +31 -0
- package/types/commands/ag/detail.d.ts +28 -0
- package/types/commands/ag/index.d.ts +6 -0
- package/types/commands/ag/list.d.ts +35 -0
- package/types/commands/ag/run.d.ts +52 -0
- package/types/commands/cloudrun/base.d.ts +10 -0
- package/types/commands/index.d.ts +1 -0
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.updateAgentIdInConfig = exports.getAgentIdFromConfig = exports.formatTime = exports.formatFileSize = exports.formatAgentStatus = exports.selectEnvironment = exports.confirmOperation = exports.inputAgentName = exports.selectAgent = exports.validateAgentId = exports.removeAgentConfig = exports.updateAgentConfig = exports.getAgentConfig = exports.updateCloudbaseConfig = exports.getCloudbaseConfig = exports.getAgentService = exports.AgentError = void 0;
|
|
7
|
+
const toolbox_1 = require("@cloudbase/toolbox");
|
|
8
|
+
const manager_node_1 = __importDefault(require("@cloudbase/manager-node"));
|
|
9
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
12
|
+
const utils_1 = require("../../utils");
|
|
13
|
+
const error_1 = require("../../error");
|
|
14
|
+
const i18n_1 = require("../../i18n");
|
|
15
|
+
class AgentError extends error_1.CloudBaseError {
|
|
16
|
+
constructor(message, code) {
|
|
17
|
+
super(message, { code });
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.AgentError = AgentError;
|
|
21
|
+
async function getAgentService(envId) {
|
|
22
|
+
const region = await (0, toolbox_1.getRegion)();
|
|
23
|
+
const { secretId, secretKey, token } = await (0, utils_1.checkAndGetCredential)(true);
|
|
24
|
+
const app = new manager_node_1.default({
|
|
25
|
+
region,
|
|
26
|
+
token,
|
|
27
|
+
envId,
|
|
28
|
+
secretId,
|
|
29
|
+
secretKey,
|
|
30
|
+
proxy: (0, utils_1.getProxy)()
|
|
31
|
+
});
|
|
32
|
+
return app.agent;
|
|
33
|
+
}
|
|
34
|
+
exports.getAgentService = getAgentService;
|
|
35
|
+
async function getCloudbaseConfig(cwd = process.cwd()) {
|
|
36
|
+
const configPath = path_1.default.join(cwd, 'cloudbaserc.json');
|
|
37
|
+
if (!(await fs_extra_1.default.pathExists(configPath))) {
|
|
38
|
+
throw new AgentError((0, i18n_1.t)('未找到 cloudbaserc.json 配置文件,请先初始化项目'));
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const config = await fs_extra_1.default.readJson(configPath);
|
|
42
|
+
return config;
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
throw new AgentError((0, i18n_1.t)('cloudbaserc.json 配置文件格式错误'));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.getCloudbaseConfig = getCloudbaseConfig;
|
|
49
|
+
async function updateCloudbaseConfig(config, cwd = process.cwd()) {
|
|
50
|
+
const configPath = path_1.default.join(cwd, 'cloudbaserc.json');
|
|
51
|
+
let existingConfig = { envId: '', agentRoot: '', agents: [] };
|
|
52
|
+
if (await fs_extra_1.default.pathExists(configPath)) {
|
|
53
|
+
try {
|
|
54
|
+
existingConfig = await fs_extra_1.default.readJson(configPath);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const newConfig = { ...existingConfig, ...config };
|
|
60
|
+
await fs_extra_1.default.writeJson(configPath, newConfig, { spaces: 2 });
|
|
61
|
+
}
|
|
62
|
+
exports.updateCloudbaseConfig = updateCloudbaseConfig;
|
|
63
|
+
async function getAgentConfig(agentName, cwd = process.cwd()) {
|
|
64
|
+
const config = await getCloudbaseConfig(cwd);
|
|
65
|
+
if (!config.agents || config.agents.length === 0) {
|
|
66
|
+
throw new AgentError((0, i18n_1.t)('未找到任何 Agent 配置'));
|
|
67
|
+
}
|
|
68
|
+
const agentConfig = config.agents.find(agent => agent.name === agentName);
|
|
69
|
+
if (!agentConfig) {
|
|
70
|
+
throw new AgentError((0, i18n_1.t)(`未找到 Agent: ${agentName}`));
|
|
71
|
+
}
|
|
72
|
+
return agentConfig;
|
|
73
|
+
}
|
|
74
|
+
exports.getAgentConfig = getAgentConfig;
|
|
75
|
+
async function updateAgentConfig(agentName, agentConfig, cwd = process.cwd()) {
|
|
76
|
+
const config = await getCloudbaseConfig(cwd);
|
|
77
|
+
if (!config.agents) {
|
|
78
|
+
config.agents = [];
|
|
79
|
+
}
|
|
80
|
+
const existingIndex = config.agents.findIndex(agent => agent.name === agentName);
|
|
81
|
+
if (existingIndex >= 0) {
|
|
82
|
+
config.agents[existingIndex] = { ...config.agents[existingIndex], ...agentConfig };
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
if (!agentConfig.name) {
|
|
86
|
+
agentConfig.name = agentName;
|
|
87
|
+
}
|
|
88
|
+
config.agents.push(agentConfig);
|
|
89
|
+
}
|
|
90
|
+
await updateCloudbaseConfig(config, cwd);
|
|
91
|
+
}
|
|
92
|
+
exports.updateAgentConfig = updateAgentConfig;
|
|
93
|
+
async function removeAgentConfig(agentName, cwd = process.cwd()) {
|
|
94
|
+
const config = await getCloudbaseConfig(cwd);
|
|
95
|
+
if (!config.agents) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
config.agents = config.agents.filter(agent => agent.name !== agentName);
|
|
99
|
+
await updateCloudbaseConfig(config, cwd);
|
|
100
|
+
}
|
|
101
|
+
exports.removeAgentConfig = removeAgentConfig;
|
|
102
|
+
function validateAgentId(agentId) {
|
|
103
|
+
const pattern = /^ag-[a-zA-Z0-9-_]+$/;
|
|
104
|
+
return pattern.test(agentId);
|
|
105
|
+
}
|
|
106
|
+
exports.validateAgentId = validateAgentId;
|
|
107
|
+
async function selectAgent(agents) {
|
|
108
|
+
if (agents.length === 0) {
|
|
109
|
+
throw new AgentError((0, i18n_1.t)('没有可用的 Agent'));
|
|
110
|
+
}
|
|
111
|
+
if (agents.length === 1) {
|
|
112
|
+
return agents[0].name;
|
|
113
|
+
}
|
|
114
|
+
const { agentName } = await inquirer_1.default.prompt([
|
|
115
|
+
{
|
|
116
|
+
type: 'list',
|
|
117
|
+
name: 'agentName',
|
|
118
|
+
message: (0, i18n_1.t)('请选择 Agent'),
|
|
119
|
+
choices: agents.map(agent => ({
|
|
120
|
+
name: `${agent.name}`,
|
|
121
|
+
value: agent.name
|
|
122
|
+
}))
|
|
123
|
+
}
|
|
124
|
+
]);
|
|
125
|
+
return agentName;
|
|
126
|
+
}
|
|
127
|
+
exports.selectAgent = selectAgent;
|
|
128
|
+
async function inputAgentName(defaultName) {
|
|
129
|
+
const { name } = await inquirer_1.default.prompt([
|
|
130
|
+
{
|
|
131
|
+
type: 'input',
|
|
132
|
+
name: 'name',
|
|
133
|
+
message: (0, i18n_1.t)('请输入 Agent 名称'),
|
|
134
|
+
default: defaultName,
|
|
135
|
+
validate: (input) => {
|
|
136
|
+
if (!input.trim()) {
|
|
137
|
+
return (0, i18n_1.t)('Agent 名称不能为空');
|
|
138
|
+
}
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
]);
|
|
143
|
+
return name;
|
|
144
|
+
}
|
|
145
|
+
exports.inputAgentName = inputAgentName;
|
|
146
|
+
async function confirmOperation(message, defaultValue = false) {
|
|
147
|
+
const { confirm } = await inquirer_1.default.prompt([
|
|
148
|
+
{
|
|
149
|
+
type: 'confirm',
|
|
150
|
+
name: 'confirm',
|
|
151
|
+
message,
|
|
152
|
+
default: defaultValue
|
|
153
|
+
}
|
|
154
|
+
]);
|
|
155
|
+
return confirm;
|
|
156
|
+
}
|
|
157
|
+
exports.confirmOperation = confirmOperation;
|
|
158
|
+
async function selectEnvironment() {
|
|
159
|
+
throw new AgentError((0, i18n_1.t)('环境选择功能待实现'));
|
|
160
|
+
}
|
|
161
|
+
exports.selectEnvironment = selectEnvironment;
|
|
162
|
+
function formatAgentStatus(status) {
|
|
163
|
+
const statusMap = {
|
|
164
|
+
'Active': (0, i18n_1.t)('运行中'),
|
|
165
|
+
'Inactive': (0, i18n_1.t)('已停止'),
|
|
166
|
+
'Deploying': (0, i18n_1.t)('部署中'),
|
|
167
|
+
'Failed': (0, i18n_1.t)('失败'),
|
|
168
|
+
'Unknown': (0, i18n_1.t)('未知')
|
|
169
|
+
};
|
|
170
|
+
return statusMap[status] || status;
|
|
171
|
+
}
|
|
172
|
+
exports.formatAgentStatus = formatAgentStatus;
|
|
173
|
+
function formatFileSize(bytes) {
|
|
174
|
+
if (bytes === 0)
|
|
175
|
+
return '0 B';
|
|
176
|
+
const k = 1024;
|
|
177
|
+
const sizes = ['B', 'KB', 'MB', 'GB'];
|
|
178
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
179
|
+
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
|
|
180
|
+
}
|
|
181
|
+
exports.formatFileSize = formatFileSize;
|
|
182
|
+
function formatTime(timestamp) {
|
|
183
|
+
const date = new Date(timestamp);
|
|
184
|
+
return date.toLocaleString();
|
|
185
|
+
}
|
|
186
|
+
exports.formatTime = formatTime;
|
|
187
|
+
async function getAgentIdFromConfig(agentName, cwd = process.cwd()) {
|
|
188
|
+
var _a;
|
|
189
|
+
const config = await getCloudbaseConfig(cwd);
|
|
190
|
+
const agentId = (_a = config.agents.find(agent => agent.name === agentName)) === null || _a === void 0 ? void 0 : _a.id;
|
|
191
|
+
return agentId;
|
|
192
|
+
}
|
|
193
|
+
exports.getAgentIdFromConfig = getAgentIdFromConfig;
|
|
194
|
+
async function updateAgentIdInConfig(agentName, agentId, cwd = process.cwd()) {
|
|
195
|
+
const config = await getCloudbaseConfig(cwd);
|
|
196
|
+
config.agents.forEach(agent => {
|
|
197
|
+
if (agent.name === agentName) {
|
|
198
|
+
agent.id = agentId;
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
await updateCloudbaseConfig(config, cwd);
|
|
202
|
+
}
|
|
203
|
+
exports.updateAgentIdInConfig = updateAgentIdInConfig;
|
|
@@ -0,0 +1,301 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.AgentCreateCommand = void 0;
|
|
19
|
+
const path_1 = __importDefault(require("path"));
|
|
20
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
21
|
+
const ora_1 = __importDefault(require("ora"));
|
|
22
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
23
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
24
|
+
const common_1 = require("../common");
|
|
25
|
+
const decorators_1 = require("../../decorators");
|
|
26
|
+
const base_1 = require("./base");
|
|
27
|
+
const template_manager_1 = require("../../utils/template-manager");
|
|
28
|
+
const error_1 = require("../../error");
|
|
29
|
+
const i18n_1 = require("../../i18n");
|
|
30
|
+
const AGENT_TEMPLATES = {
|
|
31
|
+
frontend: {
|
|
32
|
+
react: {
|
|
33
|
+
name: 'React',
|
|
34
|
+
url: 'https://7465-test-tooltip-7g3fqqhv48eec964-1259218801.tcb.qcloud.la/ag-client-react.zip',
|
|
35
|
+
desc: '基于 React 的现代化前端框架'
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
backend: {
|
|
39
|
+
node: {
|
|
40
|
+
default: {
|
|
41
|
+
name: 'Node.js 多框架集合',
|
|
42
|
+
url: 'https://7465-test-tooltip-7g3fqqhv48eec964-1259218801.tcb.qcloud.la/ag-server-node.zip',
|
|
43
|
+
desc: '包含多种 Agent 框架的 Node.js 模板'
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
python: {
|
|
47
|
+
default: {
|
|
48
|
+
name: 'Python 多框架集合',
|
|
49
|
+
url: 'https://7465-test-tooltip-7g3fqqhv48eec964-1259218801.tcb.qcloud.la/ag-server-python.zip',
|
|
50
|
+
desc: '包含多种 Agent 框架的 Python 模板'
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
let AgentCreateCommand = class AgentCreateCommand extends common_1.Command {
|
|
56
|
+
get options() {
|
|
57
|
+
return {
|
|
58
|
+
cmd: 'ag',
|
|
59
|
+
childCmd: 'create <agentName>',
|
|
60
|
+
options: [
|
|
61
|
+
{
|
|
62
|
+
flags: '-e, --envId <envId>',
|
|
63
|
+
desc: (0, i18n_1.t)('环境 ID')
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
flags: '--template <template>',
|
|
67
|
+
desc: (0, i18n_1.t)('前端模板 (react, vue)')
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
flags: '--framework <framework>',
|
|
71
|
+
desc: (0, i18n_1.t)('后端 Agent 框架 (default(多框架集合), langgraph, langchain)')
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
flags: '--lang <lang>',
|
|
75
|
+
desc: (0, i18n_1.t)('后端开发语言 (node, python)')
|
|
76
|
+
}
|
|
77
|
+
],
|
|
78
|
+
requiredEnvId: false,
|
|
79
|
+
autoRunLogin: false,
|
|
80
|
+
desc: (0, i18n_1.t)('创建 Agent 项目\n\n示例:\n tcb ag create ag-my-agent\n tcb ag create ag-my-agent --template react --framework langgraph\n tcb ag create ag-my-agent --template vue --framework default')
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
async execute(ctx, envId, log, params, options) {
|
|
84
|
+
const agentName = params[0];
|
|
85
|
+
let { template, framework, lang } = options;
|
|
86
|
+
if (!lang || !framework) {
|
|
87
|
+
const selections = await this.interactiveSelection(lang, framework, template);
|
|
88
|
+
lang = selections.lang;
|
|
89
|
+
framework = selections.framework;
|
|
90
|
+
template = selections.template;
|
|
91
|
+
}
|
|
92
|
+
this.validateSelections(lang, framework, template);
|
|
93
|
+
const workDir = process.cwd();
|
|
94
|
+
const agentDir = path_1.default.join(workDir, agentName);
|
|
95
|
+
if (await fs_extra_1.default.pathExists(agentDir)) {
|
|
96
|
+
throw new base_1.AgentError((0, i18n_1.t)(`目录已存在:${agentDir}`));
|
|
97
|
+
}
|
|
98
|
+
log.info((0, i18n_1.t)(`🚀 开始创建 Agent 项目:${agentName}`));
|
|
99
|
+
log.info((0, i18n_1.t)(`📁 项目目录:${agentDir}`));
|
|
100
|
+
log.info((0, i18n_1.t)(`🔧 后端语言:${lang}`));
|
|
101
|
+
log.info((0, i18n_1.t)(`🔧 Agent 框架:${framework}`));
|
|
102
|
+
if (template) {
|
|
103
|
+
log.info((0, i18n_1.t)(`🎨 前端模板:${template}`));
|
|
104
|
+
}
|
|
105
|
+
await fs_extra_1.default.ensureDir(agentDir);
|
|
106
|
+
try {
|
|
107
|
+
await this.downloadBackendTemplate(lang, framework, agentDir, log);
|
|
108
|
+
if (template) {
|
|
109
|
+
await this.downloadFrontendTemplate(template, agentDir, log);
|
|
110
|
+
}
|
|
111
|
+
await this.addAgentToConfig({ envId, agentName, lang, framework, template }, workDir, log);
|
|
112
|
+
console.log(chalk_1.default.green((0, i18n_1.t)('🎉 Agent 项目创建成功!')));
|
|
113
|
+
console.log(chalk_1.default.cyan((0, i18n_1.t)(`📁 项目路径:${agentDir}`)));
|
|
114
|
+
console.log(chalk_1.default.cyan((0, i18n_1.t)(`⚙️ 配置文件:已更新 cloudbaserc.json`)));
|
|
115
|
+
console.log(chalk_1.default.cyan((0, i18n_1.t)('🚀 快速开始:')));
|
|
116
|
+
console.log(chalk_1.default.white(` cd ${agentName}`));
|
|
117
|
+
if (lang === 'python') {
|
|
118
|
+
console.log(chalk_1.default.white(` pip install -r requirements.txt`));
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
console.log(chalk_1.default.white(` npm install`));
|
|
122
|
+
}
|
|
123
|
+
if (template) {
|
|
124
|
+
console.log(chalk_1.default.white(` cd client && npm install && cd ..`));
|
|
125
|
+
}
|
|
126
|
+
console.log(chalk_1.default.white(`cd .. && tcb ag run ${agentName}`));
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
await fs_extra_1.default.remove(agentDir);
|
|
130
|
+
throw new error_1.CloudBaseError((0, i18n_1.t)(`创建 Agent 项目失败:${error.message}`));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
async addAgentToConfig(config, workDir, log) {
|
|
134
|
+
const { envId, agentName, lang, framework, template } = config;
|
|
135
|
+
try {
|
|
136
|
+
const newAgentConfig = {
|
|
137
|
+
name: agentName,
|
|
138
|
+
timeout: 300,
|
|
139
|
+
environment: {
|
|
140
|
+
key: "value"
|
|
141
|
+
},
|
|
142
|
+
runtime: lang === 'python' ? 'Python3.10' : 'Nodejs20.19',
|
|
143
|
+
memorySize: 2048,
|
|
144
|
+
description: "",
|
|
145
|
+
sessionConfig: {
|
|
146
|
+
enable: true
|
|
147
|
+
},
|
|
148
|
+
ignore: template ? ["client/**", "client/node_modules/**"] : [],
|
|
149
|
+
resources: [],
|
|
150
|
+
installDependency: true
|
|
151
|
+
};
|
|
152
|
+
const configPath = path_1.default.join(workDir, 'cloudbaserc.json');
|
|
153
|
+
let existingAgents = [];
|
|
154
|
+
if (await fs_extra_1.default.pathExists(configPath)) {
|
|
155
|
+
try {
|
|
156
|
+
const existingConfig = await fs_extra_1.default.readJson(configPath);
|
|
157
|
+
existingAgents = existingConfig.agents || [];
|
|
158
|
+
log.info((0, i18n_1.t)('更新现有 cloudbaserc.json 配置'));
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
log.warn((0, i18n_1.t)('读取现有配置失败,将创建新配置'));
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
log.info((0, i18n_1.t)('创建新的 cloudbaserc.json 配置'));
|
|
166
|
+
}
|
|
167
|
+
const existingAgentIndex = existingAgents.findIndex(agent => agent.name === agentName);
|
|
168
|
+
if (existingAgentIndex >= 0) {
|
|
169
|
+
existingAgents[existingAgentIndex] = newAgentConfig;
|
|
170
|
+
log.info((0, i18n_1.t)(`更新 Agent 配置:${agentName}`));
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
existingAgents.push(newAgentConfig);
|
|
174
|
+
log.info((0, i18n_1.t)(`添加 Agent 配置:${agentName}`));
|
|
175
|
+
}
|
|
176
|
+
await (0, base_1.updateCloudbaseConfig)({
|
|
177
|
+
envId: envId,
|
|
178
|
+
agentRoot: "./",
|
|
179
|
+
agents: existingAgents
|
|
180
|
+
}, workDir);
|
|
181
|
+
log.info((0, i18n_1.t)('cloudbaserc.json 配置更新完成'));
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
log.warn((0, i18n_1.t)(`更新 cloudbaserc.json 配置失败:${error.message}`));
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
async interactiveSelection(presetLang, presetFramework, presetTemplate) {
|
|
188
|
+
console.log(chalk_1.default.cyan('\n🚀 欢迎使用 Agent 项目创建向导!\n'));
|
|
189
|
+
let lang = presetLang;
|
|
190
|
+
if (!lang) {
|
|
191
|
+
const langChoices = Object.keys(AGENT_TEMPLATES.backend).map(key => ({
|
|
192
|
+
name: `${key.toUpperCase()} - ${key === 'node' ? 'JavaScript/TypeScript' : 'Python'}`,
|
|
193
|
+
value: key,
|
|
194
|
+
short: key.toUpperCase()
|
|
195
|
+
}));
|
|
196
|
+
const langAnswer = await inquirer_1.default.prompt([{
|
|
197
|
+
type: 'list',
|
|
198
|
+
name: 'lang',
|
|
199
|
+
message: '请选择后端开发语言:',
|
|
200
|
+
choices: langChoices,
|
|
201
|
+
default: 'node'
|
|
202
|
+
}]);
|
|
203
|
+
lang = langAnswer.lang;
|
|
204
|
+
}
|
|
205
|
+
let framework = presetFramework;
|
|
206
|
+
if (!framework) {
|
|
207
|
+
const frameworkChoices = Object.entries(AGENT_TEMPLATES.backend[lang]).map(([key, config]) => ({
|
|
208
|
+
name: `${config.name} - ${config.desc}`,
|
|
209
|
+
value: key,
|
|
210
|
+
short: config.name
|
|
211
|
+
}));
|
|
212
|
+
const frameworkAnswer = await inquirer_1.default.prompt([{
|
|
213
|
+
type: 'list',
|
|
214
|
+
name: 'framework',
|
|
215
|
+
message: `请选择 ${lang.toUpperCase()} Agent 框架:`,
|
|
216
|
+
choices: frameworkChoices,
|
|
217
|
+
default: 'default'
|
|
218
|
+
}]);
|
|
219
|
+
framework = frameworkAnswer.framework;
|
|
220
|
+
}
|
|
221
|
+
let template = presetTemplate;
|
|
222
|
+
if (template === undefined) {
|
|
223
|
+
const needFrontendAnswer = await inquirer_1.default.prompt([{
|
|
224
|
+
type: 'confirm',
|
|
225
|
+
name: 'needFrontend',
|
|
226
|
+
message: '是否需要添加 Web 前端界面?',
|
|
227
|
+
default: false
|
|
228
|
+
}]);
|
|
229
|
+
if (needFrontendAnswer.needFrontend) {
|
|
230
|
+
const templateChoices = Object.entries(AGENT_TEMPLATES.frontend).map(([key, config]) => ({
|
|
231
|
+
name: `${config.name} - ${config.desc}`,
|
|
232
|
+
value: key,
|
|
233
|
+
short: config.name
|
|
234
|
+
}));
|
|
235
|
+
const templateAnswer = await inquirer_1.default.prompt([{
|
|
236
|
+
type: 'list',
|
|
237
|
+
name: 'template',
|
|
238
|
+
message: '请选择前端框架:',
|
|
239
|
+
choices: templateChoices,
|
|
240
|
+
default: 'react'
|
|
241
|
+
}]);
|
|
242
|
+
template = templateAnswer.template;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return { lang, framework, template };
|
|
246
|
+
}
|
|
247
|
+
validateSelections(lang, framework, template) {
|
|
248
|
+
if (!AGENT_TEMPLATES.backend[lang]) {
|
|
249
|
+
throw new base_1.AgentError((0, i18n_1.t)(`不支持的后端语言:${lang}。支持的语言:${Object.keys(AGENT_TEMPLATES.backend).join(', ')}`));
|
|
250
|
+
}
|
|
251
|
+
if (!AGENT_TEMPLATES.backend[lang][framework]) {
|
|
252
|
+
throw new base_1.AgentError((0, i18n_1.t)(`不支持的后端框架:${framework}。支持的框架:${Object.keys(AGENT_TEMPLATES.backend[lang]).join(', ')}`));
|
|
253
|
+
}
|
|
254
|
+
if (template && !AGENT_TEMPLATES.frontend[template]) {
|
|
255
|
+
throw new base_1.AgentError((0, i18n_1.t)(`不支持的前端模板:${template}。支持的模板:${Object.keys(AGENT_TEMPLATES.frontend).join(', ')}`));
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
async downloadBackendTemplate(lang, framework, agentDir, log) {
|
|
259
|
+
const templateConfig = AGENT_TEMPLATES.backend[lang][framework];
|
|
260
|
+
const spinner = (0, ora_1.default)((0, i18n_1.t)(`正在下载 Agent 后端模板 (${templateConfig.name})...`)).start();
|
|
261
|
+
try {
|
|
262
|
+
const templateManager = new template_manager_1.TemplateManager();
|
|
263
|
+
await templateManager.pullTemplate(templateConfig.url, { output: agentDir, force: true }, log);
|
|
264
|
+
spinner.succeed((0, i18n_1.t)('Agent 后端模板下载完成'));
|
|
265
|
+
}
|
|
266
|
+
catch (error) {
|
|
267
|
+
spinner.fail((0, i18n_1.t)('Agent 后端模板下载失败'));
|
|
268
|
+
throw error;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
async downloadFrontendTemplate(template, agentDir, log) {
|
|
272
|
+
const templateConfig = AGENT_TEMPLATES.frontend[template];
|
|
273
|
+
const clientDir = path_1.default.join(agentDir, 'client');
|
|
274
|
+
const spinner = (0, ora_1.default)((0, i18n_1.t)(`正在下载前端模板 (${templateConfig.name})...`)).start();
|
|
275
|
+
try {
|
|
276
|
+
await fs_extra_1.default.ensureDir(clientDir);
|
|
277
|
+
const templateManager = new template_manager_1.TemplateManager();
|
|
278
|
+
await templateManager.pullTemplate(templateConfig.url, { output: clientDir, force: true }, log);
|
|
279
|
+
spinner.succeed((0, i18n_1.t)('前端模板下载完成'));
|
|
280
|
+
}
|
|
281
|
+
catch (error) {
|
|
282
|
+
spinner.fail((0, i18n_1.t)('前端模板下载失败'));
|
|
283
|
+
throw error;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
__decorate([
|
|
288
|
+
(0, decorators_1.InjectParams)(),
|
|
289
|
+
__param(0, (0, decorators_1.CmdContext)()),
|
|
290
|
+
__param(1, (0, decorators_1.EnvId)()),
|
|
291
|
+
__param(2, (0, decorators_1.Log)()),
|
|
292
|
+
__param(3, (0, decorators_1.ArgsParams)()),
|
|
293
|
+
__param(4, (0, decorators_1.ArgsOptions)()),
|
|
294
|
+
__metadata("design:type", Function),
|
|
295
|
+
__metadata("design:paramtypes", [Object, String, decorators_1.Logger, Array, Object]),
|
|
296
|
+
__metadata("design:returntype", Promise)
|
|
297
|
+
], AgentCreateCommand.prototype, "execute", null);
|
|
298
|
+
AgentCreateCommand = __decorate([
|
|
299
|
+
(0, common_1.ICommand)()
|
|
300
|
+
], AgentCreateCommand);
|
|
301
|
+
exports.AgentCreateCommand = AgentCreateCommand;
|