@cloudbase/manager-node 4.11.0-alpha.6 → 4.11.0-alpha.7

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.
@@ -11,46 +11,601 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.AgentService = void 0;
13
13
  const cloudrun_1 = require("../cloudrun");
14
+ const type_1 = require("../cloudrun/type");
14
15
  const utils_1 = require("../utils");
15
16
  const path_1 = __importDefault(require("path"));
16
17
  /**
17
18
  * Agent 管理类
19
+ * 支持三种部署方式:
20
+ * - SCF 云函数:轻量级、按需计费
21
+ * - TCBR 云托管-镜像:容器化部署
22
+ * - TCBR 云托管-代码包:源码部署
18
23
  */
19
24
  class AgentService {
20
25
  constructor(environment) {
21
26
  this.environment = environment;
22
27
  this.tcbService = new utils_1.CloudService(environment.cloudBaseContext, 'tcb', '2018-06-08');
23
28
  }
29
+ // ==================== SCF 云函数部署 ====================
24
30
  /**
25
- * 创建函数型 Agent
26
- * @param {string} [cwd=process.cwd()] 工作目录
27
- * @param {ICreateFunctionAgentParams} agentInfo Agent 信息
28
- * @returns {Promise<{ BotId: string; RequestId: string }>} Agent 创建结果
31
+ * 创建 SCF Agent
32
+ * 支持两种方式:
33
+ * 1. 传入 cwd 代码目录,自动打包上传
34
+ * 2. 传入 ZipFile / CosBucketRegion + TempCosObjectName,直接上传
35
+ * @param params 创建参数
36
+ * @returns Agent 创建结果
37
+ */
38
+ async createScfAgent(params) {
39
+ const envConfig = this.environment.lazyEnvironmentConfig;
40
+ // 默认会话配置
41
+ const defaultSessionConfig = {
42
+ SessionSource: 'HEADER',
43
+ SessionName: 'X-Session-Id',
44
+ MaximumConcurrencySessionPerInstance: 1,
45
+ MaximumTTLInSeconds: 21600,
46
+ MaximumIdleTimeInSeconds: 1800,
47
+ MaxConcurrency: 50
48
+ };
49
+ // 构建 Code 参数
50
+ let codeConfig = {};
51
+ // 方式一:传入代码目录,自动打包
52
+ if (params.cwd) {
53
+ const functionService = this.environment.getFunctionService();
54
+ codeConfig = await functionService.getCodeParams({
55
+ func: {
56
+ name: params.AgentId || params.Name,
57
+ runtime: params.Runtime,
58
+ ignore: Array.isArray(params.ignore)
59
+ ? params.ignore
60
+ : params.ignore
61
+ ? [params.ignore]
62
+ : []
63
+ },
64
+ functionPath: params.cwd,
65
+ functionRootPath: path_1.default.dirname(params.cwd),
66
+ deployMode: params.deployMode
67
+ }, params.InstallDependency ? 'TRUE' : 'FALSE');
68
+ }
69
+ else {
70
+ // 方式二:直接传入 ZipFile 或 COS 参数
71
+ if (params.ZipFile) {
72
+ codeConfig.ZipFile = params.ZipFile;
73
+ }
74
+ if (params.CosBucketRegion) {
75
+ codeConfig.CosBucketRegion = params.CosBucketRegion;
76
+ }
77
+ if (params.TempCosObjectName) {
78
+ codeConfig.TempCosObjectName = params.TempCosObjectName;
79
+ }
80
+ }
81
+ const requestBody = {
82
+ EnvId: envConfig.EnvId,
83
+ AgentType: 'scf',
84
+ Name: params.Name,
85
+ AgentId: params.AgentId,
86
+ EnvParams: params.envVariables ? JSON.stringify(params.envVariables) : undefined,
87
+ RuntimeConfig: {
88
+ Code: codeConfig,
89
+ Runtime: params.Runtime,
90
+ Timeout: params.Timeout || 7200,
91
+ MemorySize: params.MemorySize,
92
+ InstallDependency: params.InstallDependency,
93
+ SessionConfig: Object.assign(Object.assign({}, defaultSessionConfig), params.SessionConfig),
94
+ Environment: params.envVariables ? JSON.stringify(params.envVariables) : undefined
95
+ }
96
+ };
97
+ return this.tcbService.request('CreateAgent', requestBody);
98
+ }
99
+ // ==================== Agent 管理操作 ====================
100
+ /**
101
+ * 查询 Agent 列表
102
+ * @param params 查询参数
103
+ * @returns Agent 列表
104
+ */
105
+ async describeAgentList(params = {}) {
106
+ const envConfig = this.environment.lazyEnvironmentConfig;
107
+ return this.tcbService.request('DescribeAgentList', {
108
+ EnvId: envConfig.EnvId,
109
+ PageSize: params.PageSize || 20,
110
+ PageNumber: params.PageNumber || 1,
111
+ AgentId: params.AgentId
112
+ });
113
+ }
114
+ /**
115
+ * 查询单个 Agent 详情(包含可用状态)
116
+ * @param agentId Agent ID
117
+ * @returns Agent 详情,IsReady 表示是否可用
118
+ * @example
119
+ * ```typescript
120
+ * const result = await agentService.describeAgent('agent-xxx')
121
+ * if (result.IsReady) {
122
+ * console.log('Agent 已就绪,可以调用')
123
+ * } else {
124
+ * console.log('Agent 不可用:', result.NotReadyReason)
125
+ * }
126
+ * ```
127
+ */
128
+ async describeAgent(agentId) {
129
+ var _a, _b, _c;
130
+ // 1. 查询 Agent 基本信息
131
+ const agentListRes = await this.describeAgentList({ AgentId: agentId });
132
+ const agentInfo = ((_a = agentListRes.AgentList) === null || _a === void 0 ? void 0 : _a[0]) || null;
133
+ if (!agentInfo) {
134
+ return {
135
+ AgentInfo: null,
136
+ IsReady: false,
137
+ NotReadyReason: 'Agent 不存在',
138
+ RequestId: agentListRes.RequestId
139
+ };
140
+ }
141
+ const serviceId = agentInfo.ServiceId;
142
+ // 2. 根据 Agent 类型查询底层资源状态
143
+ let isReady = false;
144
+ let notReadyReason = '';
145
+ try {
146
+ if (agentInfo.AgentType === 'scf') {
147
+ // SCF 云函数:调用 GetFunction 获取状态
148
+ const functionService = this.environment.getFunctionService();
149
+ const functionDetail = await functionService.getFunctionDetail(serviceId);
150
+ const status = functionDetail.Status;
151
+ if (status === 'Active') {
152
+ isReady = true;
153
+ }
154
+ else {
155
+ // 如果有 StatusReasons,提取详细错误信息
156
+ if (((_b = functionDetail.StatusReasons) === null || _b === void 0 ? void 0 : _b.length) > 0) {
157
+ notReadyReason = functionDetail.StatusReasons.map(r => `[${r.ErrorCode}] ${r.ErrorMessage}`).join('; ');
158
+ }
159
+ else {
160
+ notReadyReason = `云函数状态: ${status}${functionDetail.StatusDesc ? ` (${functionDetail.StatusDesc})` : ''}`;
161
+ }
162
+ }
163
+ }
164
+ else if (agentInfo.AgentType === 'tcbr') {
165
+ // TCBR 云托管:调用 DescribeCloudRunDeployRecord 获取最新部署状态
166
+ const cloudRunService = this.environment.getCloudRunService();
167
+ const deployRecords = await cloudRunService.getDeployRecords({
168
+ serverName: serviceId
169
+ });
170
+ const latestRecord = (_c = deployRecords.DeployRecords) === null || _c === void 0 ? void 0 : _c[0];
171
+ if (!latestRecord) {
172
+ notReadyReason = '未找到部署记录';
173
+ }
174
+ else if (latestRecord.Status === 'running' || latestRecord.Status === 'normal') {
175
+ isReady = true;
176
+ }
177
+ else {
178
+ notReadyReason = `云托管状态: ${latestRecord.Status}`;
179
+ }
180
+ }
181
+ else {
182
+ notReadyReason = `未知的 Agent 类型: ${agentInfo.AgentType}`;
183
+ }
184
+ }
185
+ catch (error) {
186
+ notReadyReason = `获取状态失败: ${error.message}`;
187
+ }
188
+ return {
189
+ AgentInfo: agentInfo,
190
+ IsReady: isReady,
191
+ NotReadyReason: isReady ? undefined : notReadyReason,
192
+ RequestId: agentListRes.RequestId
193
+ };
194
+ }
195
+ /**
196
+ * 删除 Agent
197
+ * 先删除 Agent 记录,再尝试删除底层的云函数或云托管服务
198
+ * @param params 删除参数
199
+ * @returns 操作结果,包含 Agent 和底层资源的删除状态
200
+ */
201
+ async deleteAgent(params) {
202
+ var _a, _b;
203
+ const envConfig = this.environment.lazyEnvironmentConfig;
204
+ const { AgentId } = params;
205
+ // 1. 查询 Agent 类型(用于后续删除底层资源)
206
+ const agentListRes = await this.describeAgentList({ AgentId });
207
+ const agentType = (_b = (_a = agentListRes.AgentList) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.AgentType;
208
+ // 2. 删除 Agent 记录
209
+ const deleteRes = await this.tcbService.request('DeleteAgent', {
210
+ EnvId: envConfig.EnvId,
211
+ AgentId
212
+ });
213
+ const agentDeleted = deleteRes.Affected === 1;
214
+ // 3. 删除底层资源(仅在 Agent 删除成功后执行)
215
+ let resourceResult;
216
+ if (agentDeleted && agentType) {
217
+ const resourceName = agentType === 'scf' ? '云函数' : '云托管服务';
218
+ resourceResult = {
219
+ Type: agentType,
220
+ Name: AgentId,
221
+ Deleted: false
222
+ };
223
+ try {
224
+ if (agentType === 'scf') {
225
+ const functionService = this.environment.getFunctionService();
226
+ await functionService.deleteFunction({ name: AgentId });
227
+ }
228
+ else if (agentType === 'tcbr') {
229
+ const cloudRunService = this.environment.getCloudRunService();
230
+ await cloudRunService.delete({ serverName: AgentId });
231
+ }
232
+ resourceResult.Deleted = true;
233
+ }
234
+ catch (error) {
235
+ resourceResult.Error = error.message || String(error);
236
+ resourceResult.CleanupHint = `请前往${resourceName}侧删除名为 "${AgentId}" 的资源`;
237
+ }
238
+ }
239
+ return {
240
+ RequestId: deleteRes.RequestId,
241
+ AgentDeleted: agentDeleted,
242
+ ResourceResult: resourceResult
243
+ };
244
+ }
245
+ // ==================== Agent 更新操作 ====================
246
+ /**
247
+ * 更新 Agent(自动判断类型)
248
+ * 先查询 Agent 类型,然后调用对应的更新方法
249
+ * @param params 更新参数
250
+ * @returns 操作结果
251
+ */
252
+ async updateAgent(params) {
253
+ const { AgentId } = params;
254
+ // 1. 查询 Agent 获取类型
255
+ const agentListRes = await this.describeAgentList({ AgentId });
256
+ if (!agentListRes.AgentList || agentListRes.AgentList.length === 0) {
257
+ throw new Error(`Agent ${AgentId} 不存在`);
258
+ }
259
+ const agentInfo = agentListRes.AgentList[0];
260
+ const agentType = agentInfo.AgentType;
261
+ // 2. 根据类型调用对应更新方法
262
+ if (agentType === 'scf') {
263
+ return this.updateScfAgent({
264
+ AgentId,
265
+ cwd: params.cwd,
266
+ ZipFile: params.ZipFile,
267
+ envVariables: params.envVariables,
268
+ Runtime: params.Runtime,
269
+ Timeout: params.Timeout,
270
+ MemorySize: params.MemorySize,
271
+ InstallDependency: params.InstallDependency,
272
+ Ignore: params.Ignore
273
+ });
274
+ }
275
+ else {
276
+ throw new Error(`不支持的 Agent 类型: ${agentType}`);
277
+ }
278
+ }
279
+ /**
280
+ * 更新 SCF Agent(云函数)
281
+ * 支持两种方式:本地代码目录、ZIP 文件
282
+ * @param params 更新参数
283
+ * @returns 更新结果,包含耗时信息
284
+ */
285
+ async updateScfAgent(params) {
286
+ const functionService = this.environment.getFunctionService();
287
+ const { AgentId, cwd, ZipFile, envVariables, Runtime, Timeout, MemorySize, InstallDependency, Ignore } = params;
288
+ const result = await functionService.updateFunctionWithProgress({
289
+ name: AgentId,
290
+ code: cwd || ZipFile
291
+ ? {
292
+ functionPath: cwd,
293
+ base64Code: ZipFile
294
+ }
295
+ : undefined,
296
+ config: envVariables !== undefined ||
297
+ Runtime ||
298
+ Timeout ||
299
+ MemorySize !== undefined ||
300
+ InstallDependency !== undefined
301
+ ? {
302
+ runtime: Runtime,
303
+ timeout: Timeout,
304
+ memorySize: MemorySize,
305
+ installDependency: InstallDependency,
306
+ ignore: Ignore,
307
+ envVariables: envVariables
308
+ }
309
+ : undefined
310
+ });
311
+ return Object.assign({ RequestId: '' }, result);
312
+ }
313
+ // ==================== 日志查询方法 ====================
314
+ /**
315
+ * 获取 Agent 调用日志(自动判断类型)
316
+ * @param params 查询参数
317
+ * @returns 日志结果,根据 Agent 类型返回不同结构:
318
+ * - SCF: IFunctionLogDetailRes[]
319
+ * - TCBR: ISearchClsLogResponse
320
+ * @example
321
+ * ```typescript
322
+ * const logs = await agentService.getAgentLogs({
323
+ * AgentId: 'agent-xxx',
324
+ * limit: 20,
325
+ * startTime: '2025-01-01 00:00:00',
326
+ * endTime: '2025-01-01 23:59:59'
327
+ * })
328
+ * ```
329
+ */
330
+ async getAgentLogs(params) {
331
+ const { AgentId } = params;
332
+ // 1. 查询 Agent 获取类型
333
+ const agentListRes = await this.describeAgentList({ AgentId });
334
+ if (!agentListRes.AgentList || agentListRes.AgentList.length === 0) {
335
+ throw new Error(`Agent ${AgentId} 不存在`);
336
+ }
337
+ const agentInfo = agentListRes.AgentList[0];
338
+ const agentType = agentInfo.AgentType;
339
+ // 2. 根据 Agent 类型获取日志
340
+ if (agentType === 'scf') {
341
+ const functionService = this.environment.getFunctionService();
342
+ return functionService.getCompleteFunctionLogs({
343
+ name: AgentId,
344
+ offset: params.offset,
345
+ limit: params.limit,
346
+ startTime: params.startTime,
347
+ endTime: params.endTime,
348
+ requestId: params.requestId
349
+ });
350
+ }
351
+ else if (agentType === 'tcbr') {
352
+ const logService = this.environment.getLogService();
353
+ const { startTime, endTime, limit = 100, requestId } = params;
354
+ // 构建查询语句
355
+ let queryString = `SCF_FunctionName:${AgentId}`;
356
+ if (requestId) {
357
+ queryString += ` AND SCF_RequestId:${requestId}`;
358
+ }
359
+ // 辅助函数:格式化时间
360
+ const formatDateTime = (date) => {
361
+ const pad = (n) => n.toString().padStart(2, '0');
362
+ return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;
363
+ };
364
+ // 默认时间范围:最近1小时
365
+ const defaultStartTime = formatDateTime(new Date(Date.now() - 60 * 60 * 1000));
366
+ const defaultEndTime = formatDateTime(new Date());
367
+ return logService.searchClsLog({
368
+ StartTime: startTime || defaultStartTime,
369
+ EndTime: endTime || defaultEndTime,
370
+ queryString: queryString,
371
+ Limit: limit > 100 ? 100 : limit
372
+ });
373
+ }
374
+ else {
375
+ throw new Error(`不支持的 Agent 类型: ${agentType}`);
376
+ }
377
+ }
378
+ // ==================== TCBR 云托管(内部方法,暂不对外暴露) ====================
379
+ /**
380
+ * 通过镜像创建 TCBR Agent
381
+ * @internal 暂不对外暴露,后续版本开放
382
+ * @param params 创建参数
383
+ * @returns Agent 创建结果
384
+ */
385
+ async createTcbrAgentByImage(params) {
386
+ const envConfig = this.environment.lazyEnvironmentConfig;
387
+ return this.tcbService.request('CreateAgent', {
388
+ EnvId: envConfig.EnvId,
389
+ AgentType: 'tcbr',
390
+ Name: params.Name,
391
+ AgentId: params.AgentId,
392
+ Template: params.Template,
393
+ EnvParams: params.envVariables ? JSON.stringify(params.envVariables) : undefined,
394
+ ImageUrl: params.ImageUrl,
395
+ RepoInfo: {
396
+ Repo: params.RepoInfo.Repo,
397
+ Source: params.RepoInfo.Source
398
+ },
399
+ Avatar: params.Avatar,
400
+ Introduction: params.Introduction
401
+ });
402
+ }
403
+ /**
404
+ * 获取代码包上传信息
405
+ * @internal 暂不对外暴露,后续版本开放
406
+ * @param params 查询参数
407
+ * @returns 上传信息
408
+ */
409
+ async describeCloudBaseBuildService(params) {
410
+ const envConfig = this.environment.lazyEnvironmentConfig;
411
+ return this.tcbService.request('DescribeCloudBaseBuildService', {
412
+ EnvId: envConfig.EnvId,
413
+ ServiceName: params.ServiceName,
414
+ CIBusiness: params.CIBusiness,
415
+ ServiceVersion: params.ServiceVersion,
416
+ Suffix: params.Suffix
417
+ });
418
+ }
419
+ /**
420
+ * 通过代码包信息创建 TCBR Agent(已上传代码包)
421
+ * @internal 暂不对外暴露,后续版本开放
422
+ * @param params 创建参数
423
+ * @returns Agent 创建结果
424
+ */
425
+ async createTcbrAgentByPackage(params) {
426
+ const envConfig = this.environment.lazyEnvironmentConfig;
427
+ return this.tcbService.request('CreateAgent', {
428
+ EnvId: envConfig.EnvId,
429
+ AgentType: 'tcbr',
430
+ Name: params.Name,
431
+ AgentId: params.AgentId,
432
+ Template: params.Template,
433
+ EnvParams: params.envVariables ? JSON.stringify(params.envVariables) : undefined,
434
+ PackageName: params.PackageName,
435
+ PackageVersion: params.PackageVersion,
436
+ Source: params.Source,
437
+ Avatar: params.Avatar,
438
+ Introduction: params.Introduction
439
+ });
440
+ }
441
+ /**
442
+ * 通过本地代码创建 TCBR Agent(自动打包上传)
443
+ * @internal 暂不对外暴露,后续版本开放
444
+ * @param cwd 代码目录,默认当前工作目录
445
+ * @param params 创建参数
446
+ * @returns Agent 创建结果
447
+ */
448
+ async createTcbrAgentByCode(cwd = process.cwd(), params) {
449
+ const targetPath = path_1.default.join(cwd);
450
+ const envConfig = this.environment.lazyEnvironmentConfig;
451
+ // 获取部署包上传信息
452
+ const { UploadUrl: uploadUrl, UploadHeaders: uploadHeaders, PackageName: packageName, PackageVersion: packageVersion } = await this.tcbService.request('DescribeCloudBaseBuildService', {
453
+ EnvId: envConfig.EnvId,
454
+ ServiceName: params.AgentId
455
+ });
456
+ // 打包并上传代码
457
+ const zipFile = await (0, cloudrun_1.codeToZip)(targetPath, { installDependency: true });
458
+ await (0, utils_1.upload)({
459
+ url: uploadUrl,
460
+ file: zipFile,
461
+ headers: (uploadHeaders || []).reduce((map, item) => {
462
+ map[item.Key] = item.Value;
463
+ return map;
464
+ }, {}) || {},
465
+ method: 'PUT'
466
+ });
467
+ // 创建 Agent
468
+ return this.tcbService.request('CreateAgent', {
469
+ EnvId: envConfig.EnvId,
470
+ AgentType: 'tcbr',
471
+ Name: params.Name,
472
+ AgentId: params.AgentId,
473
+ Template: params.Template,
474
+ EnvParams: params.envVariables ? JSON.stringify(params.envVariables) : undefined,
475
+ PackageName: packageName,
476
+ PackageVersion: packageVersion,
477
+ Source: params.Source,
478
+ Avatar: params.Avatar,
479
+ Introduction: params.Introduction
480
+ });
481
+ }
482
+ /**
483
+ * 更新 TCBR Agent(云托管)
484
+ * 支持两种方式:本地代码目录、镜像
485
+ * @internal 暂不对外暴露,后续版本开放
486
+ * @param params 更新参数
487
+ * @returns 操作结果
488
+ */
489
+ async updateTcbrAgent(params) {
490
+ const cloudRunService = this.environment.getCloudRunService();
491
+ const { AgentId, cwd, ImageUrl, envVariables, InstallDependency = true, Cpu, Mem, MinNum, MaxNum, Port, InitialDelaySeconds, CustomLogs } = params;
492
+ // 云托管服务名就是 AgentId
493
+ const serverName = AgentId;
494
+ // 构建服务配置项
495
+ const serverConfig = {};
496
+ if (envVariables !== undefined)
497
+ serverConfig.EnvParams = JSON.stringify(envVariables);
498
+ if (Cpu !== undefined)
499
+ serverConfig.Cpu = Cpu;
500
+ if (Mem !== undefined)
501
+ serverConfig.Mem = Mem;
502
+ if (MinNum !== undefined)
503
+ serverConfig.MinNum = MinNum;
504
+ if (MaxNum !== undefined)
505
+ serverConfig.MaxNum = MaxNum;
506
+ if (Port !== undefined)
507
+ serverConfig.Port = Port;
508
+ if (InitialDelaySeconds !== undefined)
509
+ serverConfig.InitialDelaySeconds = InitialDelaySeconds;
510
+ if (CustomLogs !== undefined)
511
+ serverConfig.CustomLogs = CustomLogs;
512
+ if (ImageUrl) {
513
+ // 镜像方式更新
514
+ const envConfig = this.environment.lazyEnvironmentConfig;
515
+ const tcbrService = new utils_1.CloudService(this.environment.cloudBaseContext, 'tcbr', '2022-02-17');
516
+ // 构建 Items 数组
517
+ const Items = [];
518
+ if (envVariables)
519
+ Items.push({ Key: 'EnvParam', Value: JSON.stringify(envVariables) });
520
+ if (Cpu !== undefined)
521
+ Items.push({ Key: 'CpuSpecs', FloatValue: Cpu });
522
+ if (Mem !== undefined)
523
+ Items.push({ Key: 'MemSpecs', FloatValue: Mem });
524
+ if (MinNum !== undefined)
525
+ Items.push({ Key: 'MinNum', IntValue: MinNum });
526
+ if (MaxNum !== undefined)
527
+ Items.push({ Key: 'MaxNum', IntValue: MaxNum });
528
+ if (Port !== undefined)
529
+ Items.push({ Key: 'Port', IntValue: Port });
530
+ if (InitialDelaySeconds !== undefined)
531
+ Items.push({ Key: 'InitialDelaySeconds', IntValue: InitialDelaySeconds });
532
+ if (CustomLogs)
533
+ Items.push({ Key: 'LogPath', Value: CustomLogs });
534
+ await tcbrService.request('UpdateCloudRunServer', {
535
+ EnvId: envConfig.EnvId,
536
+ ServerName: serverName,
537
+ DeployInfo: {
538
+ DeployType: 'image',
539
+ ImageUrl: ImageUrl
540
+ },
541
+ Items
542
+ });
543
+ }
544
+ else if (cwd) {
545
+ // 代码包方式更新
546
+ await cloudRunService.deploy({
547
+ serverName,
548
+ targetPath: cwd,
549
+ deployInfo: {
550
+ ReleaseType: type_1.ReleaseTypeEnum.FULL
551
+ },
552
+ serverConfig: Object.assign(Object.assign({}, serverConfig), { InstallDependency })
553
+ });
554
+ }
555
+ else if (Object.keys(serverConfig).length > 0) {
556
+ // 仅更新配置(无代码/镜像部署)
557
+ const envConfig = this.environment.lazyEnvironmentConfig;
558
+ const tcbrService = new utils_1.CloudService(this.environment.cloudBaseContext, 'tcbr', '2022-02-17');
559
+ // 构建 Items 数组
560
+ const Items = [];
561
+ if (envVariables)
562
+ Items.push({ Key: 'EnvParam', Value: JSON.stringify(envVariables) });
563
+ if (Cpu !== undefined)
564
+ Items.push({ Key: 'CpuSpecs', FloatValue: Cpu });
565
+ if (Mem !== undefined)
566
+ Items.push({ Key: 'MemSpecs', FloatValue: Mem });
567
+ if (MinNum !== undefined)
568
+ Items.push({ Key: 'MinNum', IntValue: MinNum });
569
+ if (MaxNum !== undefined)
570
+ Items.push({ Key: 'MaxNum', IntValue: MaxNum });
571
+ if (Port !== undefined)
572
+ Items.push({ Key: 'Port', IntValue: Port });
573
+ if (InitialDelaySeconds !== undefined)
574
+ Items.push({ Key: 'InitialDelaySeconds', IntValue: InitialDelaySeconds });
575
+ if (CustomLogs)
576
+ Items.push({ Key: 'LogPath', Value: CustomLogs });
577
+ await tcbrService.request('UpdateCloudRunServer', {
578
+ EnvId: envConfig.EnvId,
579
+ ServerName: serverName,
580
+ Items
581
+ });
582
+ }
583
+ return { RequestId: '' };
584
+ }
585
+ // ==================== 旧版兼容方法(已废弃) ====================
586
+ /**
587
+ * @deprecated 请使用 createTcbrAgentByCode
588
+ * 创建函数型 Agent(旧版)
589
+ * @param cwd 工作目录
590
+ * @param agentInfo Agent 信息
591
+ * @returns Agent 创建结果
29
592
  */
30
593
  async createFunctionAgent(cwd = process.cwd(), agentInfo) {
31
594
  const { BotId } = agentInfo;
32
595
  const targetPath = path_1.default.join(cwd);
33
596
  const envConfig = this.environment.lazyEnvironmentConfig;
34
- /**
35
- * 判断 params.IbotId 的数据格式是否为 ibot-xxx-xxx 的格式
36
- */
597
+ // 判断 params.BotId 的数据格式是否为 ibot-xxx-xxx 的格式
37
598
  if (!/^ibot-[a-z0-9_]+-[a-z0-9_]+$/.test(BotId)) {
38
599
  throw new Error('BotId格式应为"ibot-xxx-xxx",其中 xxx 仅支持小写字母、数字或下划线');
39
600
  }
40
- /**
41
- * 获取函数型云托管服务的名称:ibot-xxx-xxx 中的 ibot-xxx
42
- */
601
+ // 获取函数型云托管服务的名称:ibot-xxx-xxx 中的 ibot-xxx
43
602
  const serverName = BotId.split('-').slice(0, 2).join('-');
44
- /**
45
- * 获取部署包上传信息
46
- */
603
+ // 获取部署包上传信息
47
604
  const { UploadUrl: uploadUrl, UploadHeaders: uploadHeaders, PackageName: packageName, PackageVersion: packageVersion } = await this.tcbService.request('DescribeCloudBaseBuildService', {
48
605
  EnvId: envConfig.EnvId,
49
606
  ServiceName: serverName
50
607
  });
51
- /**
52
- * 上传部署包
53
- */
608
+ // 上传部署包
54
609
  const zipFile = await (0, cloudrun_1.codeToZip)(targetPath, { installDependency: true });
55
610
  await (0, utils_1.upload)({
56
611
  url: uploadUrl,
@@ -65,6 +620,42 @@ class AgentService {
65
620
  }
66
621
  }
67
622
  exports.AgentService = AgentService;
623
+ __decorate([
624
+ (0, utils_1.preLazy)()
625
+ ], AgentService.prototype, "createScfAgent", null);
626
+ __decorate([
627
+ (0, utils_1.preLazy)()
628
+ ], AgentService.prototype, "describeAgentList", null);
629
+ __decorate([
630
+ (0, utils_1.preLazy)()
631
+ ], AgentService.prototype, "describeAgent", null);
632
+ __decorate([
633
+ (0, utils_1.preLazy)()
634
+ ], AgentService.prototype, "deleteAgent", null);
635
+ __decorate([
636
+ (0, utils_1.preLazy)()
637
+ ], AgentService.prototype, "updateAgent", null);
638
+ __decorate([
639
+ (0, utils_1.preLazy)()
640
+ ], AgentService.prototype, "updateScfAgent", null);
641
+ __decorate([
642
+ (0, utils_1.preLazy)()
643
+ ], AgentService.prototype, "getAgentLogs", null);
644
+ __decorate([
645
+ (0, utils_1.preLazy)()
646
+ ], AgentService.prototype, "createTcbrAgentByImage", null);
647
+ __decorate([
648
+ (0, utils_1.preLazy)()
649
+ ], AgentService.prototype, "describeCloudBaseBuildService", null);
650
+ __decorate([
651
+ (0, utils_1.preLazy)()
652
+ ], AgentService.prototype, "createTcbrAgentByPackage", null);
653
+ __decorate([
654
+ (0, utils_1.preLazy)()
655
+ ], AgentService.prototype, "createTcbrAgentByCode", null);
656
+ __decorate([
657
+ (0, utils_1.preLazy)()
658
+ ], AgentService.prototype, "updateTcbrAgent", null);
68
659
  __decorate([
69
660
  (0, utils_1.preLazy)()
70
661
  ], AgentService.prototype, "createFunctionAgent", null);
package/lib/agent/type.js CHANGED
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
+ // ==================== 通用类型 ====================
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -8,6 +8,7 @@ const agent_1 = require("./agent");
8
8
  const storage_1 = require("./storage");
9
9
  const env_1 = require("./env");
10
10
  const common_1 = require("./common");
11
+ const log_1 = require("./log");
11
12
  const error_1 = require("./error");
12
13
  const constant_1 = require("./constant");
13
14
  const utils_1 = require("./utils");
@@ -31,6 +32,7 @@ class Environment {
31
32
  this.databaseService = new database_1.DatabaseService(this);
32
33
  this.storageService = new storage_1.StorageService(this);
33
34
  this.envService = new env_1.EnvService(this);
35
+ this.logService = new log_1.LogService(this);
34
36
  this.hostingService = new hosting_1.HostingService(this);
35
37
  this.thirdService = new third_1.ThirdService(this);
36
38
  this.accessService = new access_1.AccessService(this);
@@ -78,6 +80,9 @@ class Environment {
78
80
  getEnvService() {
79
81
  return this.envService;
80
82
  }
83
+ getLogService() {
84
+ return this.logService;
85
+ }
81
86
  getHostingService() {
82
87
  return this.hostingService;
83
88
  }