@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,200 @@
|
|
|
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.AgentDeleteCommand = void 0;
|
|
19
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
20
|
+
const ora_1 = __importDefault(require("ora"));
|
|
21
|
+
const common_1 = require("../common");
|
|
22
|
+
const decorators_1 = require("../../decorators");
|
|
23
|
+
const base_1 = require("./base");
|
|
24
|
+
const utils_1 = require("../utils");
|
|
25
|
+
const constants_1 = require("../constants");
|
|
26
|
+
const i18n_1 = require("../../i18n");
|
|
27
|
+
const base_2 = require("./base");
|
|
28
|
+
let AgentDeleteCommand = class AgentDeleteCommand extends common_1.Command {
|
|
29
|
+
get options() {
|
|
30
|
+
return {
|
|
31
|
+
cmd: 'ag',
|
|
32
|
+
childCmd: 'delete [agentName]',
|
|
33
|
+
options: [
|
|
34
|
+
{
|
|
35
|
+
flags: '-e, --envId <envId>',
|
|
36
|
+
desc: (0, i18n_1.t)('环境 ID')
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
flags: '--agentId <agentId>',
|
|
40
|
+
desc: (0, i18n_1.t)('Agent ID'),
|
|
41
|
+
defaultValue: ''
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
flags: '--force',
|
|
45
|
+
desc: (0, i18n_1.t)('强制删除,不提示确认'),
|
|
46
|
+
defaultValue: false
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
flags: '--all',
|
|
50
|
+
desc: (0, i18n_1.t)('删除配置文件中的所有 Agent'),
|
|
51
|
+
defaultValue: false
|
|
52
|
+
}
|
|
53
|
+
],
|
|
54
|
+
requiredEnvId: false,
|
|
55
|
+
autoRunLogin: true,
|
|
56
|
+
desc: (0, i18n_1.t)('删除 Agent')
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
async execute(ctx, envId, log, params, options) {
|
|
60
|
+
const agentName = params[0];
|
|
61
|
+
const { force, all, agentId: agId } = options;
|
|
62
|
+
if (!envId) {
|
|
63
|
+
envId = await this.selectEnv();
|
|
64
|
+
}
|
|
65
|
+
log.info((0, i18n_1.t)('当前环境:{{envId}}', { envId }));
|
|
66
|
+
const agentService = await (0, base_1.getAgentService)(envId);
|
|
67
|
+
const agentId = agId ? agId : await (0, base_2.getAgentIdFromConfig)(agentName, process.cwd());
|
|
68
|
+
if (all) {
|
|
69
|
+
await this.deleteAllAgents(agentService, force, log);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
await this.deleteAgent({ agentService, agentName, agentId, force, log: log });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async selectEnv() {
|
|
76
|
+
return (0, utils_1.selectEnv)({ source: [constants_1.EnvSource.MINIAPP, constants_1.EnvSource.QCLOUD] });
|
|
77
|
+
}
|
|
78
|
+
async deleteAgent(options) {
|
|
79
|
+
const { agentService, agentName, agentId, force, log } = options;
|
|
80
|
+
try {
|
|
81
|
+
if (!force) {
|
|
82
|
+
const confirmed = await (0, base_1.confirmOperation)((0, i18n_1.t)(`确定要删除 Agent "${agentName}" 吗?此操作不可恢复。`));
|
|
83
|
+
if (!confirmed) {
|
|
84
|
+
log.info((0, i18n_1.t)('删除操作已取消'));
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const spinner = (0, ora_1.default)({
|
|
89
|
+
text: (0, i18n_1.t)('正在删除 Agent...'),
|
|
90
|
+
color: 'red'
|
|
91
|
+
}).start();
|
|
92
|
+
try {
|
|
93
|
+
if (agentId) {
|
|
94
|
+
const deleteRes = await agentService.delete({ agentId });
|
|
95
|
+
console.log('deleteRes', deleteRes);
|
|
96
|
+
}
|
|
97
|
+
await (0, base_1.removeAgentConfig)(agentName);
|
|
98
|
+
spinner.succeed((0, i18n_1.t)('Agent 删除成功'));
|
|
99
|
+
log.success((0, i18n_1.t)(`Agent "${agentName}" 已成功删除`));
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
spinner.fail((0, i18n_1.t)('Agent 删除失败'));
|
|
103
|
+
throw error;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
if (error.code === 'ResourceNotFound' || error.message.includes('not found')) {
|
|
108
|
+
log.warn((0, i18n_1.t)('Agent {{agentId}} 在云端不存在,仅删除本地配置', { agentId }));
|
|
109
|
+
await (0, base_1.removeAgentConfig)(agentId);
|
|
110
|
+
log.success((0, i18n_1.t)('本地配置已删除'));
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async deleteAllAgents(agentService, force, log) {
|
|
118
|
+
try {
|
|
119
|
+
const config = await (0, base_1.getCloudbaseConfig)();
|
|
120
|
+
const agents = config.agents || [];
|
|
121
|
+
if (agents.length === 0) {
|
|
122
|
+
log.info((0, i18n_1.t)('没有找到需要删除的 Agent'));
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
console.log(chalk_1.default.yellow((0, i18n_1.t)('\n将要删除的 Agent:')));
|
|
126
|
+
agents.forEach((agent, index) => {
|
|
127
|
+
console.log(`${index + 1}. ${agent.name}`);
|
|
128
|
+
});
|
|
129
|
+
if (!force) {
|
|
130
|
+
const confirmed = await (0, base_1.confirmOperation)((0, i18n_1.t)('确定要删除以上 {{count}} 个 Agent 吗?此操作不可恢复。', { count: agents.length }), false);
|
|
131
|
+
if (!confirmed) {
|
|
132
|
+
log.info((0, i18n_1.t)('删除操作已取消'));
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const spinner = (0, ora_1.default)({
|
|
137
|
+
text: (0, i18n_1.t)('正在批量删除 Agent...'),
|
|
138
|
+
color: 'red'
|
|
139
|
+
}).start();
|
|
140
|
+
let successCount = 0;
|
|
141
|
+
let failedCount = 0;
|
|
142
|
+
const failedAgents = [];
|
|
143
|
+
for (const agent of agents) {
|
|
144
|
+
try {
|
|
145
|
+
spinner.text = (0, i18n_1.t)(`正在删除 ${agent.name}...`);
|
|
146
|
+
if (agent.id) {
|
|
147
|
+
try {
|
|
148
|
+
await agentService.delete({ agentId: agent.id });
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
if (!(error.code === 'ResourceNotFound' || error.message.includes('not found'))) {
|
|
152
|
+
throw error;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
successCount++;
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
failedCount++;
|
|
160
|
+
failedAgents.push(`${agent.name}`);
|
|
161
|
+
log.warn((0, i18n_1.t)(`删除 ${agent.name} 失败:${error.message}`));
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
await (0, base_1.updateCloudbaseConfig)({ agents: [] });
|
|
165
|
+
if (failedCount === 0) {
|
|
166
|
+
spinner.succeed((0, i18n_1.t)('所有 Agent 删除成功'));
|
|
167
|
+
log.success((0, i18n_1.t)(`成功删除 ${successCount} 个 Agent`));
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
spinner.warn((0, i18n_1.t)('部分 Agent 删除失败'));
|
|
171
|
+
log.info((0, i18n_1.t)(`成功删除 ${successCount} 个,失败 ${failedCount} 个`));
|
|
172
|
+
if (failedAgents.length > 0) {
|
|
173
|
+
console.log(chalk_1.default.red((0, i18n_1.t)('\n删除失败的 Agent:')));
|
|
174
|
+
failedAgents.forEach(agent => {
|
|
175
|
+
console.log(`• ${agent}`);
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
log.error((0, i18n_1.t)(`批量删除失败:${error.message}`));
|
|
182
|
+
throw error;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
__decorate([
|
|
187
|
+
(0, decorators_1.InjectParams)(),
|
|
188
|
+
__param(0, (0, decorators_1.CmdContext)()),
|
|
189
|
+
__param(1, (0, decorators_1.EnvId)()),
|
|
190
|
+
__param(2, (0, decorators_1.Log)()),
|
|
191
|
+
__param(3, (0, decorators_1.ArgsParams)()),
|
|
192
|
+
__param(4, (0, decorators_1.ArgsOptions)()),
|
|
193
|
+
__metadata("design:type", Function),
|
|
194
|
+
__metadata("design:paramtypes", [Object, String, decorators_1.Logger, Array, Object]),
|
|
195
|
+
__metadata("design:returntype", Promise)
|
|
196
|
+
], AgentDeleteCommand.prototype, "execute", null);
|
|
197
|
+
AgentDeleteCommand = __decorate([
|
|
198
|
+
(0, common_1.ICommand)()
|
|
199
|
+
], AgentDeleteCommand);
|
|
200
|
+
exports.AgentDeleteCommand = AgentDeleteCommand;
|
|
@@ -0,0 +1,185 @@
|
|
|
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.AgentDeployCommand = void 0;
|
|
19
|
+
const path_1 = __importDefault(require("path"));
|
|
20
|
+
const ora_1 = __importDefault(require("ora"));
|
|
21
|
+
const common_1 = require("../common");
|
|
22
|
+
const decorators_1 = require("../../decorators");
|
|
23
|
+
const base_1 = require("./base");
|
|
24
|
+
const utils_1 = require("../utils");
|
|
25
|
+
const constants_1 = require("../constants");
|
|
26
|
+
const i18n_1 = require("../../i18n");
|
|
27
|
+
const base_2 = require("../cloudrun/base");
|
|
28
|
+
const base_3 = require("./base");
|
|
29
|
+
let AgentDeployCommand = class AgentDeployCommand extends common_1.Command {
|
|
30
|
+
get options() {
|
|
31
|
+
return {
|
|
32
|
+
cmd: 'ag',
|
|
33
|
+
childCmd: 'deploy [agentName]',
|
|
34
|
+
options: [
|
|
35
|
+
{
|
|
36
|
+
flags: '-e, --envId <envId>',
|
|
37
|
+
desc: (0, i18n_1.t)('环境 ID')
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
flags: '--deployMode <deployMode>',
|
|
41
|
+
desc: (0, i18n_1.t)('部署模式(webFn: Web 函数,cloudrun: 云托管,默认: webFn)')
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
flags: '--force',
|
|
45
|
+
desc: (0, i18n_1.t)('强制部署,跳过确认提示'),
|
|
46
|
+
defaultValue: false
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
flags: '--source <source>',
|
|
50
|
+
desc: (0, i18n_1.t)('指定要部署的代码目录路径')
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
flags: '--port <port>',
|
|
54
|
+
desc: (0, i18n_1.t)('部署模式为云托管时,支持设置服务端口')
|
|
55
|
+
}
|
|
56
|
+
],
|
|
57
|
+
requiredEnvId: false,
|
|
58
|
+
autoRunLogin: true,
|
|
59
|
+
desc: (0, i18n_1.t)('部署 Agent 到云端')
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
async execute(ctx, envId, log, params, options) {
|
|
63
|
+
const agentName = params[0];
|
|
64
|
+
console.log('params', params);
|
|
65
|
+
console.log('options', options);
|
|
66
|
+
const { deployMode = 'webFn', force, source, port } = options;
|
|
67
|
+
const rootDir = process.cwd();
|
|
68
|
+
const cloudbaseConfig = await (0, base_1.getCloudbaseConfig)(rootDir);
|
|
69
|
+
if (!envId) {
|
|
70
|
+
if (cloudbaseConfig.envId) {
|
|
71
|
+
envId = cloudbaseConfig.envId;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
envId = await this.selectEnv();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
log.info((0, i18n_1.t)('当前环境:{{envId}}', { envId }));
|
|
78
|
+
let agentConfig;
|
|
79
|
+
try {
|
|
80
|
+
agentConfig = await (0, base_1.getAgentConfig)(agentName, rootDir);
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
throw new base_1.AgentError((0, i18n_1.t)('未找到 Agent 配置,请先运行 tcb ag create {{agentName}}', { agentName }));
|
|
84
|
+
}
|
|
85
|
+
const agentService = await (0, base_1.getAgentService)(envId);
|
|
86
|
+
const spinner = (0, ora_1.default)({
|
|
87
|
+
text: (0, i18n_1.t)('正在部署 Agent...'),
|
|
88
|
+
color: 'blue'
|
|
89
|
+
}).start();
|
|
90
|
+
const agentRootPath = path_1.default.join(process.cwd(), cloudbaseConfig.agentRoot);
|
|
91
|
+
try {
|
|
92
|
+
console.log('deployMode', deployMode);
|
|
93
|
+
const agentId = await (0, base_3.getAgentIdFromConfig)(agentName, process.cwd());
|
|
94
|
+
if (deployMode === 'cloudrun') {
|
|
95
|
+
await this.deployAgentInCloudrun({
|
|
96
|
+
agentName,
|
|
97
|
+
agentConfig,
|
|
98
|
+
agentPath: source,
|
|
99
|
+
agentRootPath,
|
|
100
|
+
envId,
|
|
101
|
+
log,
|
|
102
|
+
port,
|
|
103
|
+
});
|
|
104
|
+
spinner.stop();
|
|
105
|
+
}
|
|
106
|
+
else if (deployMode === 'webFn') {
|
|
107
|
+
const isFirstDeploy = await this.checkIfFirstDeploy(agentService, agentId);
|
|
108
|
+
const deployConfig = {
|
|
109
|
+
timeout: agentConfig.timeout,
|
|
110
|
+
runtime: agentConfig.runtime,
|
|
111
|
+
memorySize: agentConfig.memorySize,
|
|
112
|
+
installDependency: agentConfig.installDependency || false,
|
|
113
|
+
sessionConfig: agentConfig.sessionConfig,
|
|
114
|
+
ignore: agentConfig.ignore,
|
|
115
|
+
resources: agentConfig.resources,
|
|
116
|
+
functionName: agentConfig.id,
|
|
117
|
+
environment: {
|
|
118
|
+
Variables: Object.entries(agentConfig.environment).map(([key, value]) => ({
|
|
119
|
+
Name: key,
|
|
120
|
+
Value: value
|
|
121
|
+
}))
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
const deployRes = await agentService.deployWebFn({
|
|
125
|
+
agentId,
|
|
126
|
+
name: agentName,
|
|
127
|
+
agentPath: source,
|
|
128
|
+
agentRootPath: agentRootPath,
|
|
129
|
+
deployConfig: {
|
|
130
|
+
...deployConfig,
|
|
131
|
+
}
|
|
132
|
+
}, isFirstDeploy);
|
|
133
|
+
spinner.succeed((0, i18n_1.t)(`Agent ${isFirstDeploy ? '创建' : '更新'}成功`));
|
|
134
|
+
await (0, base_1.updateAgentIdInConfig)(agentConfig.name, deployRes.AgentId, process.cwd());
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
spinner.fail((0, i18n_1.t)('Agent 部署失败'));
|
|
139
|
+
throw error;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
async deployAgentInCloudrun(options) {
|
|
143
|
+
const { agentName, agentConfig, agentPath, agentRootPath, envId, log, port } = options;
|
|
144
|
+
await (0, base_2.cloudRunDeploy)({
|
|
145
|
+
envId,
|
|
146
|
+
serviceName: agentName,
|
|
147
|
+
targetDir: agentPath || path_1.default.resolve(agentRootPath, agentName),
|
|
148
|
+
serverType: 'container',
|
|
149
|
+
port,
|
|
150
|
+
installDependency: 'true',
|
|
151
|
+
log: log
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
async selectEnv() {
|
|
155
|
+
return (0, utils_1.selectEnv)({ source: [constants_1.EnvSource.MINIAPP, constants_1.EnvSource.QCLOUD] });
|
|
156
|
+
}
|
|
157
|
+
async checkIfFirstDeploy(agentService, agentId) {
|
|
158
|
+
if (!agentId) {
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
try {
|
|
162
|
+
const agentInfo = await agentService.getAgentInfo({ agentId });
|
|
163
|
+
console.log('agentInfo', agentInfo);
|
|
164
|
+
return !agentInfo.AgentId;
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
__decorate([
|
|
172
|
+
(0, decorators_1.InjectParams)(),
|
|
173
|
+
__param(0, (0, decorators_1.CmdContext)()),
|
|
174
|
+
__param(1, (0, decorators_1.EnvId)()),
|
|
175
|
+
__param(2, (0, decorators_1.Log)()),
|
|
176
|
+
__param(3, (0, decorators_1.ArgsParams)()),
|
|
177
|
+
__param(4, (0, decorators_1.ArgsOptions)()),
|
|
178
|
+
__metadata("design:type", Function),
|
|
179
|
+
__metadata("design:paramtypes", [Object, String, decorators_1.Logger, Array, Object]),
|
|
180
|
+
__metadata("design:returntype", Promise)
|
|
181
|
+
], AgentDeployCommand.prototype, "execute", null);
|
|
182
|
+
AgentDeployCommand = __decorate([
|
|
183
|
+
(0, common_1.ICommand)()
|
|
184
|
+
], AgentDeployCommand);
|
|
185
|
+
exports.AgentDeployCommand = AgentDeployCommand;
|
|
@@ -0,0 +1,113 @@
|
|
|
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.AgentDetailCommand = void 0;
|
|
19
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
20
|
+
const common_1 = require("../common");
|
|
21
|
+
const decorators_1 = require("../../decorators");
|
|
22
|
+
const base_1 = require("./base");
|
|
23
|
+
const utils_1 = require("../utils");
|
|
24
|
+
const constants_1 = require("../constants");
|
|
25
|
+
const i18n_1 = require("../../i18n");
|
|
26
|
+
let AgentDetailCommand = class AgentDetailCommand extends common_1.Command {
|
|
27
|
+
get options() {
|
|
28
|
+
return {
|
|
29
|
+
cmd: 'ag',
|
|
30
|
+
childCmd: 'detail <agentName>',
|
|
31
|
+
options: [
|
|
32
|
+
{
|
|
33
|
+
flags: '-e, --envId <envId>',
|
|
34
|
+
desc: (0, i18n_1.t)('环境 ID')
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
flags: '--format <format>',
|
|
38
|
+
desc: (0, i18n_1.t)('输出格式(table | json,默认: table)'),
|
|
39
|
+
choices: ['table', 'json'],
|
|
40
|
+
defaultValue: 'table'
|
|
41
|
+
}
|
|
42
|
+
],
|
|
43
|
+
requiredEnvId: false,
|
|
44
|
+
autoRunLogin: true,
|
|
45
|
+
desc: (0, i18n_1.t)('查看 Agent 详情')
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
async execute(ctx, envId, log, params, options) {
|
|
49
|
+
const agentName = params[0];
|
|
50
|
+
const { format } = options;
|
|
51
|
+
if (!envId) {
|
|
52
|
+
envId = await this.selectEnv();
|
|
53
|
+
}
|
|
54
|
+
log.info((0, i18n_1.t)('当前环境:{{envId}}', { envId }));
|
|
55
|
+
const agentService = await (0, base_1.getAgentService)(envId);
|
|
56
|
+
const agentId = await (0, base_1.getAgentIdFromConfig)(agentName, process.cwd());
|
|
57
|
+
if (!agentId) {
|
|
58
|
+
throw new base_1.AgentError((0, i18n_1.t)(`请先部署 Agent: ${agentName}`));
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
const agentDetail = await agentService.getAgentInfo({ agentId });
|
|
62
|
+
if (format === 'json') {
|
|
63
|
+
this.outputJson(agentDetail);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
this.outputTable(agentDetail, log);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
log.error((0, i18n_1.t)('获取 Agent 详情失败:{{error}}', { error: error.message }));
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async selectEnv() {
|
|
75
|
+
return (0, utils_1.selectEnv)({ source: [constants_1.EnvSource.MINIAPP, constants_1.EnvSource.QCLOUD] });
|
|
76
|
+
}
|
|
77
|
+
outputTable(agentDetail, log) {
|
|
78
|
+
console.log(chalk_1.default.green((0, i18n_1.t)('\n=== Agent 基本信息 ===')));
|
|
79
|
+
const basicInfo = [
|
|
80
|
+
[(0, i18n_1.t)('Agent ID'), agentDetail.AgentId],
|
|
81
|
+
[(0, i18n_1.t)('名称'), agentDetail.Name],
|
|
82
|
+
[(0, i18n_1.t)('运行时'), agentDetail.RuntimeConfig.Runtime],
|
|
83
|
+
[(0, i18n_1.t)('内存'), agentDetail.RuntimeConfig.MemorySize],
|
|
84
|
+
[(0, i18n_1.t)('更新时间'), (0, base_1.formatTime)(agentDetail.UpdateTime)]
|
|
85
|
+
];
|
|
86
|
+
basicInfo.forEach(([key, value]) => {
|
|
87
|
+
console.log(`${chalk_1.default.cyan(key + ':')} ${value}`);
|
|
88
|
+
});
|
|
89
|
+
console.log(chalk_1.default.green((0, i18n_1.t)('\n=== 相关操作 ===')));
|
|
90
|
+
console.log(chalk_1.default.white((0, i18n_1.t)(`• 本地调试:tcb ag run ${agentDetail.AgentId}`)));
|
|
91
|
+
console.log(chalk_1.default.white((0, i18n_1.t)(`• 重新部署:tcb ag deploy ${agentDetail.AgentId}`)));
|
|
92
|
+
console.log(chalk_1.default.white((0, i18n_1.t)(`• 调用测试:tcb ag invoke ${agentDetail.AgentId} -d '{"prompt": "test"}'`)));
|
|
93
|
+
console.log(chalk_1.default.white((0, i18n_1.t)(`• 下载代码:tcb ag download ${agentDetail.AgentId}`)));
|
|
94
|
+
}
|
|
95
|
+
outputJson(agentDetail) {
|
|
96
|
+
console.log(JSON.stringify(agentDetail, null, 2));
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
__decorate([
|
|
100
|
+
(0, decorators_1.InjectParams)(),
|
|
101
|
+
__param(0, (0, decorators_1.CmdContext)()),
|
|
102
|
+
__param(1, (0, decorators_1.EnvId)()),
|
|
103
|
+
__param(2, (0, decorators_1.Log)()),
|
|
104
|
+
__param(3, (0, decorators_1.ArgsParams)()),
|
|
105
|
+
__param(4, (0, decorators_1.ArgsOptions)()),
|
|
106
|
+
__metadata("design:type", Function),
|
|
107
|
+
__metadata("design:paramtypes", [Object, String, decorators_1.Logger, Array, Object]),
|
|
108
|
+
__metadata("design:returntype", Promise)
|
|
109
|
+
], AgentDetailCommand.prototype, "execute", null);
|
|
110
|
+
AgentDetailCommand = __decorate([
|
|
111
|
+
(0, common_1.ICommand)()
|
|
112
|
+
], AgentDetailCommand);
|
|
113
|
+
exports.AgentDetailCommand = AgentDetailCommand;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./create"), exports);
|
|
18
|
+
__exportStar(require("./deploy"), exports);
|
|
19
|
+
__exportStar(require("./run"), exports);
|
|
20
|
+
__exportStar(require("./list"), exports);
|
|
21
|
+
__exportStar(require("./detail"), exports);
|
|
22
|
+
__exportStar(require("./delete"), exports);
|
|
@@ -0,0 +1,155 @@
|
|
|
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.AgentListCommand = void 0;
|
|
19
|
+
const cli_table3_1 = __importDefault(require("cli-table3"));
|
|
20
|
+
const common_1 = require("../common");
|
|
21
|
+
const decorators_1 = require("../../decorators");
|
|
22
|
+
const base_1 = require("./base");
|
|
23
|
+
const utils_1 = require("../utils");
|
|
24
|
+
const constants_1 = require("../constants");
|
|
25
|
+
const i18n_1 = require("../../i18n");
|
|
26
|
+
const base_2 = require("./base");
|
|
27
|
+
let AgentListCommand = class AgentListCommand extends common_1.Command {
|
|
28
|
+
get options() {
|
|
29
|
+
return {
|
|
30
|
+
cmd: 'ag',
|
|
31
|
+
childCmd: 'list',
|
|
32
|
+
options: [
|
|
33
|
+
{
|
|
34
|
+
flags: '-e, --envId <envId>',
|
|
35
|
+
desc: (0, i18n_1.t)('环境 ID')
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
flags: '-l, --limit <limit>',
|
|
39
|
+
desc: (0, i18n_1.t)('数据长度(默认值: 20)'),
|
|
40
|
+
defaultValue: 20
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
flags: '-o, --offset <offset>',
|
|
44
|
+
desc: (0, i18n_1.t)('偏移量(默认值: 0)'),
|
|
45
|
+
defaultValue: 0
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
flags: '--format <format>',
|
|
49
|
+
desc: (0, i18n_1.t)('输出格式(table | json,默认: table)'),
|
|
50
|
+
choices: ['table', 'json'],
|
|
51
|
+
defaultValue: 'table'
|
|
52
|
+
}
|
|
53
|
+
],
|
|
54
|
+
requiredEnvId: false,
|
|
55
|
+
autoRunLogin: true,
|
|
56
|
+
desc: (0, i18n_1.t)('查看 Agent 列表')
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
async execute(ctx, envId, log, options) {
|
|
60
|
+
const { limit = 20, offset = 0, format } = options;
|
|
61
|
+
if (!envId) {
|
|
62
|
+
envId = await this.selectEnv();
|
|
63
|
+
}
|
|
64
|
+
log.info((0, i18n_1.t)('当前环境:{{envId}}', { envId }));
|
|
65
|
+
const agentService = await (0, base_1.getAgentService)(envId);
|
|
66
|
+
try {
|
|
67
|
+
const result = await agentService.list({
|
|
68
|
+
limit: parseInt(String(limit)),
|
|
69
|
+
offset: parseInt(String(offset))
|
|
70
|
+
});
|
|
71
|
+
const agents = result.AgentList || [];
|
|
72
|
+
const total = result.Total || 0;
|
|
73
|
+
if (agents.length === 0) {
|
|
74
|
+
log.info((0, i18n_1.t)('当前环境没有 Agent'));
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (format === 'json') {
|
|
78
|
+
this.outputJson(agents, total, limit, offset);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
this.outputTable(agents, total, limit, offset, log);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
log.error((0, i18n_1.t)(`获取 Agent 列表失败:${error.message}`));
|
|
86
|
+
throw new base_2.AgentError((0, i18n_1.t)(`获取 Agent 列表失败:${error.message}`));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async selectEnv() {
|
|
90
|
+
return (0, utils_1.selectEnv)({ source: [constants_1.EnvSource.MINIAPP, constants_1.EnvSource.QCLOUD] });
|
|
91
|
+
}
|
|
92
|
+
outputTable(agents, total, limit, offset, log) {
|
|
93
|
+
const table = new cli_table3_1.default({
|
|
94
|
+
head: [
|
|
95
|
+
(0, i18n_1.t)('Agent ID'),
|
|
96
|
+
(0, i18n_1.t)('名称'),
|
|
97
|
+
(0, i18n_1.t)('运行时'),
|
|
98
|
+
(0, i18n_1.t)('内存'),
|
|
99
|
+
(0, i18n_1.t)('更新时间'),
|
|
100
|
+
],
|
|
101
|
+
style: {
|
|
102
|
+
head: ['green']
|
|
103
|
+
},
|
|
104
|
+
colWidths: [20, 20, 10, 10, 30]
|
|
105
|
+
});
|
|
106
|
+
agents.forEach(agent => {
|
|
107
|
+
table.push([
|
|
108
|
+
agent.AgentId,
|
|
109
|
+
agent.Name,
|
|
110
|
+
agent.RuntimeConfig.Runtime || 'N/A',
|
|
111
|
+
agent.RuntimeConfig.MemorySize ? `${agent.RuntimeConfig.MemorySize}MB` : 'N/A',
|
|
112
|
+
(0, base_1.formatTime)(agent.UpdateTime),
|
|
113
|
+
]);
|
|
114
|
+
});
|
|
115
|
+
console.log(table.toString());
|
|
116
|
+
const currentPage = Math.floor(offset / limit) + 1;
|
|
117
|
+
const totalPages = Math.ceil(total / limit);
|
|
118
|
+
log.info((0, i18n_1.t)(`显示 ${offset + 1}-${Math.min(offset + agents.length, total)} 条,共 ${total} 条 (第 ${currentPage} 页,共 ${totalPages} 页)`));
|
|
119
|
+
if (totalPages > 1) {
|
|
120
|
+
if (currentPage < totalPages) {
|
|
121
|
+
log.info((0, i18n_1.t)(`查看下一页:tcb ag list -o ${offset + limit} -l ${limit}`));
|
|
122
|
+
}
|
|
123
|
+
if (currentPage > 1) {
|
|
124
|
+
log.info((0, i18n_1.t)(`查看上一页:tcb ag list -o ${Math.max(0, offset - limit)} -l ${limit}`));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
outputJson(agents, total, limit, offset) {
|
|
129
|
+
const result = {
|
|
130
|
+
agents,
|
|
131
|
+
pagination: {
|
|
132
|
+
total,
|
|
133
|
+
limit,
|
|
134
|
+
offset,
|
|
135
|
+
count: agents.length,
|
|
136
|
+
hasMore: offset + agents.length < total
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
console.log(JSON.stringify(result, null, 2));
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
__decorate([
|
|
143
|
+
(0, decorators_1.InjectParams)(),
|
|
144
|
+
__param(0, (0, decorators_1.CmdContext)()),
|
|
145
|
+
__param(1, (0, decorators_1.EnvId)()),
|
|
146
|
+
__param(2, (0, decorators_1.Log)()),
|
|
147
|
+
__param(3, (0, decorators_1.ArgsOptions)()),
|
|
148
|
+
__metadata("design:type", Function),
|
|
149
|
+
__metadata("design:paramtypes", [Object, String, decorators_1.Logger, Object]),
|
|
150
|
+
__metadata("design:returntype", Promise)
|
|
151
|
+
], AgentListCommand.prototype, "execute", null);
|
|
152
|
+
AgentListCommand = __decorate([
|
|
153
|
+
(0, common_1.ICommand)()
|
|
154
|
+
], AgentListCommand);
|
|
155
|
+
exports.AgentListCommand = AgentListCommand;
|