@cloudbase/manager-node 4.6.4 → 4.7.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.
@@ -0,0 +1,119 @@
1
+ ---
2
+ cloudbaseAIVersion:1.8.20
3
+ description: CloudBase AI 开发规则索引 - 防止不同开发场景的规则互相干扰
4
+ globs:
5
+ alwaysApply: true
6
+ ---
7
+
8
+ # AI 开发人机协同规则索引
9
+
10
+ ## 核心行为规则
11
+ 0. 你擅长调用合适的工具来完成完成各项任务
12
+ 1. 你会在对话输出完毕后选择适当的时机向用户提出询问,例如是否需要添加后端能力,是否打开预览,是否需要部署等
13
+ 2. 你首先会阅读当前项目的 README.md,遵照当前项目的说明进行开发,如果不存在则会在生成项目后生成一个 README.md 文件
14
+ 3. 开发的时候,默认就在当前目录下产出所有项目代码,先检查当前目录的文件
15
+ 4. 开发预览的时候,如果本身项目有依赖后端数据库集合和云函数,可以优先部署后端然后再预览前端
16
+ 5. 交互式反馈规则:在需求不明确时主动与用户对话澄清,优先使用自动化工具 interactiveDialog 完成配置。执行高风险操作前必须使用 interactiveDialog 获得用户确认。保持消息简洁并用emoji标记状态。
17
+ 6. 如果涉及到实时通信相关的例如实时对战等,可以使用云开发的实时数据库 watch 能力
18
+
19
+ ## 工作流
20
+
21
+ <workflow>
22
+ 0. 请注意!必须遵守以下的规则,每个环节完成后都需要由我进行确认后才可进行下一个环节;
23
+ 1. 如果你判断我的输入提出的是一个新需求,可以按照下面的标准软件工程的方式独立开展工作,需要时才向我询问,可以采用 interactiveDialog 工具来收集
24
+ 2. 每当我输入新的需求的时候,为了规范需求质量和验收标准,你首先会搞清楚问题和需求,然后再进入下一阶段
25
+ 3. 需求文档和验收标准设计:首先完成需求的设计,按照 EARS 简易需求语法方法来描述,跟我进行确认,最终确认清楚后,需求定稿,然后再进入下一阶段,保存在 `specs/spec_name/requirements.md` 中,参考格式如下
26
+
27
+ ```markdown
28
+ # 需求文档
29
+
30
+ ## 介绍
31
+
32
+ 需求描述
33
+
34
+ ## 需求
35
+
36
+ ### 需求 1 - 需求名称
37
+
38
+ **用户故事:** 用户故事内容
39
+
40
+ #### 验收标准
41
+
42
+ 1. 采用 ERAS 描述的子句 While <可选前置条件>, when <可选触发器>, the <系统名称> shall <系统响应>,例如 When 选择"静音"时,笔记本电脑应当抑制所有音频输出。
43
+ 2. ...
44
+ ...
45
+ ```
46
+ 4. 技术方案设计: 在完成需求的设计之后,你会根据当前的技术架构和前面确认好的需求,进行需求的技术方案设计,精简但是能够准确的描述技术的架构(例如架构、技术栈、技术选型、数据库/接口设计、测试策略、安全性),必要时可以用 mermaid 来绘图,跟我确认清楚后,保存在 `specs/spec_name/design.md` 中,然后再进入下一阶段
47
+ 5. 任务拆分:在完成技术方案设计后,你会根据需求文档和技术方案,细化具体要做的事情,跟我确认清楚后,,保存在`specs/spec_name/tasks.md` 中, 然后再进入下一阶段,开始正式执行任务,同时需要及时更新任务的状态,执行的时候尽可能独立自主运行,保证效率和质量
48
+
49
+ 任务参考格式如下
50
+
51
+ ``` markdown
52
+ # 实施计划
53
+
54
+ - [ ] 1. 任务信息
55
+ - 具体要做的事情
56
+ - ...
57
+ - _需求: 相关的需求点的编号
58
+
59
+ ```
60
+ </workflow>
61
+
62
+ ## 专业领域规则文件
63
+
64
+ **重要:根据具体的开发场景,AI 必须参考对应的规则文件,避免不同场景的规则互相干扰**
65
+
66
+ ### rules/web-development.mdc
67
+ 描述前端+云开发 CloudBase 项目开发的专业规则,包含:
68
+ - Web 项目结构和工程化配置
69
+ - 静态托管部署流程
70
+ - Web SDK 使用和认证方式
71
+ - 适用于纯 Web 项目开发时参考
72
+
73
+ ### rules/miniprogram-development.mdc
74
+ 描述微信小程序开发的专业规则,包含:
75
+ - 小程序项目结构和配置
76
+ - 微信云开发能力集成
77
+ - 小程序特有的 API 和权限处理
78
+ - 适用于微信小程序开发时参考
79
+
80
+ ### rules/cloudbase-platform.mdc
81
+ 描述 CloudBase 平台的核心知识,包含:
82
+ - 云开发环境和认证
83
+ - 云函数、数据库、存储等服务
84
+ - 数据模型和权限管理
85
+ - 控制台管理页面链接
86
+ - 适用于所有使用 CloudBase 平台的项目
87
+
88
+ ### rules/workflows.mdc
89
+ 描述开发工作流程,包含:
90
+ - 部署流程(云函数、静态托管)
91
+ - 素材下载和知识库查询
92
+ - 文档和配置文件生成规则
93
+ - MCP 接口调用规范
94
+ - 适用于项目开发的各个阶段
95
+
96
+ ### rules/database.mdc
97
+ 描述云开发 CloudBase 数据库操作的专业规则,包含:
98
+ - CloudBase 数据库操作注意事项
99
+ - 数据库权限管理
100
+ - 数据更新和错误处理
101
+ - 适用于涉及数据库操作的项目
102
+
103
+ ### rules/ui-design.mdc
104
+ 描述web/小程序等页面设计和 UI 规范,包含:
105
+ - 高保真原型设计流程
106
+ - UI 设计规范和工具选择
107
+ - 前端样式处理
108
+ - 适用于需要设计界面的项目
109
+
110
+ ## 使用指导
111
+ - **Web 项目开发**:主要参考 `rules/web-development.mdc` + `rules/cloudbase-platform.mdc` + `rules/workflows.mdc`
112
+ - **微信小程序开发**:主要参考 `rules/miniprogram-development.mdc` + `rules/cloudbase-platform.mdc` + `rules/workflows.mdc`
113
+ - **数据库相关**:额外参考 `rules/database.mdc`
114
+ - **UI 设计需求**:额外参考 `rules/ui-design.mdc`
115
+
116
+ **重要提醒:开发微信小程序时,严禁参考 Web SDK 的认证方式,必须使用小程序专用的 API 和云开发方式!**
117
+
118
+
119
+
@@ -15,14 +15,18 @@ const utils_1 = require("../utils");
15
15
  const path_1 = __importDefault(require("path"));
16
16
  /**
17
17
  * Agent 管理类
18
+ * 提供新版 Agent 的完整生命周期管理功能
18
19
  */
19
20
  class AgentService {
20
21
  constructor(environment) {
21
22
  this.environment = environment;
22
23
  this.tcbService = new utils_1.CloudService(environment.cloudBaseContext, 'tcb', '2018-06-08');
24
+ this.scfService = new utils_1.CloudService(environment.cloudBaseContext, 'scf', '2018-04-16');
25
+ this.functionService = environment.getFunctionService();
26
+ this.userService = environment.getUserService();
23
27
  }
24
28
  /**
25
- * 创建函数型 Agent
29
+ * 创建函数型 Agent(兼容旧版本)
26
30
  * @param {string} [cwd=process.cwd()] 工作目录
27
31
  * @param {ICreateFunctionAgentParams} agentInfo Agent 信息
28
32
  * @returns {Promise<{ BotId: string; RequestId: string }>} Agent 创建结果
@@ -63,8 +67,145 @@ class AgentService {
63
67
  });
64
68
  return this.tcbService.request('CreateBot', Object.assign(Object.assign({}, agentInfo), { EnvId: envConfig.EnvId, PackageName: packageName, PackageVersion: packageVersion }));
65
69
  }
70
+ /**
71
+ * 部署新版 Agent 到 web云函数
72
+ * @param {ICreateAgentParams} params 创建参数
73
+ * @returns {Promise<IResponseInfo>} 创建结果
74
+ */
75
+ async deployWebFn(params, isFirstDeploy = true) {
76
+ const envConfig = this.environment.lazyEnvironmentConfig;
77
+ const { name, agentId, agentPath, agentRootPath, deployConfig } = params;
78
+ // 构造部署参数
79
+ const deployAgentData = Object.assign({}, deployConfig);
80
+ // 上传代码包到 COS
81
+ const uploadRes = await this.functionService.uploadFunctionZipToCos({ func: { name: name, ignore: deployConfig.ignore }, functionPath: agentPath, functionRootPath: agentRootPath }, 'FALSE');
82
+ console.log('uploadRes', uploadRes);
83
+ const { Key } = uploadRes;
84
+ console.log('tempobjectkey', Key);
85
+ deployAgentData.code = {
86
+ cosBucketRegion: 'ap-shanghai',
87
+ tempCosObjectName: `/${Key}`
88
+ };
89
+ // 使用 zipFile 上传
90
+ // deployAgentData.code = await this.getCodeParams({ deployConfig, agentPath, agentRootPath })
91
+ try {
92
+ let res;
93
+ if (isFirstDeploy) {
94
+ // 调用创建接口 TODO: 临时屏蔽 resourceList
95
+ res = await this.tcbService.request('CreateAgent', (0, utils_1.upperCaseObjKey)({
96
+ envId: envConfig.EnvId,
97
+ // agentId,
98
+ name,
99
+ runtimeConfig: Object.assign(Object.assign({}, deployAgentData), { ignore: undefined, resources: undefined, environment: undefined, functionName: undefined })
100
+ }));
101
+ console.log('CreateAgent res', res);
102
+ // 等待函数状态正常
103
+ await this.functionService.waitFunctionActive(res.AgentId);
104
+ }
105
+ else {
106
+ // 调用函数代码更新接口
107
+ res = await this.scfService.request('UpdateFunctionCode', {
108
+ FunctionName: agentId,
109
+ Namespace: envConfig.EnvId,
110
+ InstallDependency: 'FALSE',
111
+ Code: deployAgentData.code
112
+ });
113
+ console.log('UpdateFunctionCode res', res);
114
+ // 等待函数状态正常
115
+ await this.functionService.waitFunctionActive(agentId);
116
+ }
117
+ return res;
118
+ }
119
+ catch (error) {
120
+ throw new Error(`${isFirstDeploy ? '创建' : '更新'} Agent 失败: ${error.message}`);
121
+ }
122
+ }
123
+ /**
124
+ * 获取 Agent 列表
125
+ * @param {IListAgentsParams} [params] 查询参数
126
+ * @returns {Promise<IListAgentsResponse>} Agent 列表
127
+ */
128
+ async list(params) {
129
+ const envConfig = this.environment.lazyEnvironmentConfig;
130
+ const { limit = 20, offset = 0, agentId } = params || {};
131
+ // 转化为 pageSize 和 pageNum
132
+ const pageSize = limit;
133
+ const pageNumber = Math.floor(offset / limit) + 1;
134
+ try {
135
+ const params = {
136
+ EnvId: envConfig.EnvId,
137
+ };
138
+ if (agentId) {
139
+ params.AgentId = agentId;
140
+ }
141
+ else {
142
+ params.PageSize = pageSize;
143
+ params.PageNumber = pageNumber;
144
+ }
145
+ const res = await this.tcbService.request('DescribeAgentList', params);
146
+ console.log('DescribeAgentList res', JSON.stringify(res, null, 2));
147
+ const transformAggentList = await Promise.all(res.AgentList.map(async (item) => {
148
+ const fnDetail = await this.functionService.getFunctionDetail(item.AgentId);
149
+ return Object.assign(Object.assign({}, item), { RuntimeConfig: Object.assign(Object.assign({}, item.RuntimeConfig), { Runtime: fnDetail.Runtime, MemorySize: fnDetail.MemorySize, Timeout: fnDetail.Timeout }) });
150
+ }));
151
+ return Object.assign(Object.assign({}, res), { AgentList: transformAggentList });
152
+ }
153
+ catch (error) {
154
+ throw new Error(`获取 Agent 列表失败: ${error.message}`);
155
+ }
156
+ }
157
+ /**
158
+ * 获取 Agent 详情
159
+ * @param {object} params 查询参数
160
+ * @param {string} params.agentId Agent ID
161
+ * @returns {Promise<IAgentDetailResponse>} Agent 详情
162
+ */
163
+ async getAgentInfo(params) {
164
+ const listRes = await this.list({ agentId: params.agentId });
165
+ if (listRes.Total > 0) {
166
+ return listRes.AgentList[0];
167
+ }
168
+ else {
169
+ return null;
170
+ }
171
+ }
172
+ /**
173
+ * 删除 Agent
174
+ * @param {IDeleteAgentParams} params 删除参数
175
+ * @returns {Promise<IResponseInfo>} 删除结果
176
+ */
177
+ async delete(params) {
178
+ const envConfig = this.environment.lazyEnvironmentConfig;
179
+ const { agentId } = params;
180
+ try {
181
+ // 1. 删除 Agent 实体
182
+ const res = await this.tcbService.request('DeleteAgent', {
183
+ EnvId: envConfig.EnvId,
184
+ AgentId: agentId
185
+ });
186
+ // 2. 删除 agentId 对应的函数
187
+ const deleteFunctionRes = await this.functionService.deleteFunction({ name: agentId });
188
+ console.log('deleteFunctionRes', deleteFunctionRes);
189
+ return res;
190
+ }
191
+ catch (error) {
192
+ throw new Error(`删除 Agent 失败: ${error.message}`);
193
+ }
194
+ }
66
195
  }
67
196
  exports.AgentService = AgentService;
68
197
  __decorate([
69
198
  (0, utils_1.preLazy)()
70
199
  ], AgentService.prototype, "createFunctionAgent", null);
200
+ __decorate([
201
+ (0, utils_1.preLazy)()
202
+ ], AgentService.prototype, "deployWebFn", null);
203
+ __decorate([
204
+ (0, utils_1.preLazy)()
205
+ ], AgentService.prototype, "list", null);
206
+ __decorate([
207
+ (0, utils_1.preLazy)()
208
+ ], AgentService.prototype, "getAgentInfo", null);
209
+ __decorate([
210
+ (0, utils_1.preLazy)()
211
+ ], AgentService.prototype, "delete", null);
@@ -180,7 +180,7 @@ class CloudRunService {
180
180
  /**
181
181
  * 上传部署包
182
182
  */
183
- const zipFile = await codeToZip(targetPath, { installDependency: true });
183
+ const zipFile = await codeToZip(targetPath, { installDependency: (serverConfig === null || serverConfig === void 0 ? void 0 : serverConfig.InstallDependency) !== undefined ? serverConfig.InstallDependency : true });
184
184
  await (0, utils_1.upload)({
185
185
  url: uploadUrl,
186
186
  file: zipFile,
@@ -23,6 +23,7 @@ class Environment {
23
23
  this.cloudBaseContext = context;
24
24
  this.envType = context.envType;
25
25
  // 拉取当前环境 的环境信息 todo
26
+ this.userService = new user_1.UserService(this);
26
27
  this.functionService = new function_1.FunctionService(this);
27
28
  this.cloudRunService = new cloudrun_1.CloudRunService(this);
28
29
  this.agentService = new agent_1.AgentService(this);
@@ -32,7 +33,6 @@ class Environment {
32
33
  this.hostingService = new hosting_1.HostingService(this);
33
34
  this.thirdService = new third_1.ThirdService(this);
34
35
  this.accessService = new access_1.AccessService(this);
35
- this.userService = new user_1.UserService(this);
36
36
  this.cloudBaseRunService = new cloudBaseRun_1.CloudBaseRunService(this);
37
37
  }
38
38
  async lazyInit() {
@@ -17,6 +17,7 @@ const packer_1 = require("./packer");
17
17
  const error_1 = require("../error");
18
18
  const utils_1 = require("../utils");
19
19
  const constant_1 = require("../constant");
20
+ const cos_nodejs_sdk_v5_1 = __importDefault(require("cos-nodejs-sdk-v5"));
20
21
  // 是否为 Node 函数
21
22
  function isNodeFunction(runtime) {
22
23
  // 不严格限制
@@ -85,6 +86,7 @@ class FunctionService {
85
86
  this.scfService = new utils_1.CloudService(environment.cloudBaseContext, 'scf', '2018-04-16');
86
87
  this.vpcService = new utils_1.CloudService(environment.cloudBaseContext, 'vpc', '2017-03-12');
87
88
  this.tcbService = new utils_1.CloudService(environment.cloudBaseContext, 'tcb', '2018-06-08');
89
+ this.userService = environment.getUserService();
88
90
  }
89
91
  /**
90
92
  * 增量更新函数代码
@@ -989,6 +991,45 @@ class FunctionService {
989
991
  LayerVersion: version
990
992
  });
991
993
  }
994
+ // 检查函数状态,部分操作在函数更新中时不可进行
995
+ async waitFunctionActive(funcName, codeSecret) {
996
+ let ticker;
997
+ let timer;
998
+ let resolved;
999
+ return new Promise((resolve, reject) => {
1000
+ // 超时时间 5 分钟
1001
+ timer = setTimeout(() => {
1002
+ clearInterval(ticker);
1003
+ if (!resolved) {
1004
+ reject(new error_1.CloudBaseError('函数状态异常,检查超时'));
1005
+ }
1006
+ }, 300000);
1007
+ ticker = setInterval(async () => {
1008
+ try {
1009
+ const { Status, StatusDesc, StatusReasons, RequestId } = await this.getFunctionDetail(funcName, codeSecret);
1010
+ // 更新中
1011
+ if (Status === constant_1.SCF_STATUS.CREATING || Status === constant_1.SCF_STATUS.UPDATING)
1012
+ return;
1013
+ // 创建失败
1014
+ if (Status === constant_1.SCF_STATUS.CREATE_FAILED) {
1015
+ StatusDesc && console.log(`函数状态描述: ${StatusDesc}`);
1016
+ const errorDetails = StatusReasons.map(item => `[${item.ErrorCode}] ${item.ErrorMessage}`).join('\n');
1017
+ throw new error_1.CloudBaseError(`云函数创建失败\n失败信息: ${errorDetails}\nRequestId: ${RequestId}`);
1018
+ }
1019
+ // 函数状态正常
1020
+ clearInterval(ticker);
1021
+ clearTimeout(timer);
1022
+ resolve();
1023
+ }
1024
+ catch (e) {
1025
+ clearInterval(ticker);
1026
+ clearTimeout(timer);
1027
+ reject(e);
1028
+ }
1029
+ resolved = true;
1030
+ }, 1000);
1031
+ });
1032
+ }
992
1033
  /**
993
1034
  * 设置预置并发
994
1035
  * @private
@@ -1104,6 +1145,56 @@ class FunctionService {
1104
1145
  Namespace: namespace
1105
1146
  });
1106
1147
  }
1148
+ async uploadFunctionZipToCos(options, installDependency) {
1149
+ const { func, functionPath, functionRootPath, base64Code } = options;
1150
+ const { env } = await this.getFunctionConfig();
1151
+ const { CloudAppId } = await this.userService.getTcbAccountInfo();
1152
+ const objectPath = `${CloudAppId}/${env}/${func.name}.zip`;
1153
+ console.log('objectPath', objectPath);
1154
+ // 1. 生成存放函数包的临时 Cos 目录
1155
+ const { Date, Sign, RequestId } = await this.scfService.request('GetTempCosInfo', {
1156
+ ObjectPath: `${objectPath}`
1157
+ });
1158
+ // 2. 本地压缩
1159
+ const codeType = packer_1.CodeType.File;
1160
+ // 云端安装依赖,自动忽略 node_modules 目录
1161
+ const ignore = installDependency === 'TRUE'
1162
+ ? ['node_modules/**/*', 'node_modules', ...(func.ignore || [])]
1163
+ : [...(func.ignore || [])];
1164
+ const packer = new packer_1.FunctionPacker({
1165
+ ignore,
1166
+ codeType,
1167
+ functionPath,
1168
+ name: func.name,
1169
+ root: functionRootPath
1170
+ });
1171
+ const zipFilePath = await packer.compressFiles();
1172
+ // 3. 初始化 cos 并上传
1173
+ const tempCosObjectName = `/${Date}/${objectPath}`;
1174
+ const TEMP_COS_APPID = '1253665819';
1175
+ const uploadParams = {
1176
+ Bucket: `shtempcos-${TEMP_COS_APPID}`,
1177
+ Key: tempCosObjectName,
1178
+ Region: 'ap-shanghai',
1179
+ FilePath: zipFilePath,
1180
+ };
1181
+ const cos = new cos_nodejs_sdk_v5_1.default({
1182
+ getAuthorization: function (options, callback) {
1183
+ // 注入上一步获取的临时密钥
1184
+ callback(Sign);
1185
+ }
1186
+ });
1187
+ return new Promise((resolve, reject) => {
1188
+ cos.sliceUploadFile(uploadParams, (err, data) => {
1189
+ if (err) {
1190
+ reject(err);
1191
+ }
1192
+ else {
1193
+ resolve(data);
1194
+ }
1195
+ });
1196
+ });
1197
+ }
1107
1198
  async createAccessPath(name, path) {
1108
1199
  const access = this.environment.getAccessService();
1109
1200
  try {
@@ -1250,45 +1341,6 @@ class FunctionService {
1250
1341
  });
1251
1342
  return SubnetSet;
1252
1343
  }
1253
- // 检查函数状态,部分操作在函数更新中时不可进行
1254
- async waitFunctionActive(funcName, codeSecret) {
1255
- let ticker;
1256
- let timer;
1257
- let resolved;
1258
- return new Promise((resolve, reject) => {
1259
- // 超时时间 5 分钟
1260
- timer = setTimeout(() => {
1261
- clearInterval(ticker);
1262
- if (!resolved) {
1263
- reject(new error_1.CloudBaseError('函数状态异常,检查超时'));
1264
- }
1265
- }, 300000);
1266
- ticker = setInterval(async () => {
1267
- try {
1268
- const { Status, StatusDesc, StatusReasons, RequestId } = await this.getFunctionDetail(funcName, codeSecret);
1269
- // 更新中
1270
- if (Status === constant_1.SCF_STATUS.CREATING || Status === constant_1.SCF_STATUS.UPDATING)
1271
- return;
1272
- // 创建失败
1273
- if (Status === constant_1.SCF_STATUS.CREATE_FAILED) {
1274
- StatusDesc && console.log(`函数状态描述: ${StatusDesc}`);
1275
- const errorDetails = StatusReasons.map(item => `[${item.ErrorCode}] ${item.ErrorMessage}`).join('\n');
1276
- throw new error_1.CloudBaseError(`云函数创建失败\n失败信息: ${errorDetails}\nRequestId: ${RequestId}`);
1277
- }
1278
- // 函数状态正常
1279
- clearInterval(ticker);
1280
- clearTimeout(timer);
1281
- resolve();
1282
- }
1283
- catch (e) {
1284
- clearInterval(ticker);
1285
- clearTimeout(timer);
1286
- reject(e);
1287
- }
1288
- resolved = true;
1289
- }, 1000);
1290
- });
1291
- }
1292
1344
  }
1293
1345
  exports.FunctionService = FunctionService;
1294
1346
  __decorate([
@@ -1399,6 +1451,9 @@ __decorate([
1399
1451
  __decorate([
1400
1452
  (0, utils_1.preLazy)()
1401
1453
  ], FunctionService.prototype, "getFunctionAlias", null);
1454
+ __decorate([
1455
+ (0, utils_1.preLazy)()
1456
+ ], FunctionService.prototype, "uploadFunctionZipToCos", null);
1402
1457
  __decorate([
1403
1458
  (0, utils_1.preLazy)()
1404
1459
  ], FunctionService.prototype, "createAccessPath", null);
@@ -88,6 +88,7 @@ class FunctionPacker {
88
88
  zipOption.pattern = this.incrementalPath;
89
89
  }
90
90
  await (0, utils_1.compressToZip)(zipOption);
91
+ return this.zipFilePath;
91
92
  }
92
93
  // 获取 Java 代码
93
94
  getJavaFile() {
package/lib/user/index.js CHANGED
@@ -111,6 +111,9 @@ class UserService {
111
111
  }]
112
112
  });
113
113
  }
114
+ async getTcbAccountInfo() {
115
+ return this.tcbService.request('DescribeTcbAccountInfo');
116
+ }
114
117
  isValidStr(obj) {
115
118
  return typeof obj === 'string' && obj.trim().length > 0;
116
119
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/manager-node",
3
- "version": "4.6.4",
3
+ "version": "4.7.0-beta.0",
4
4
  "description": "The node manage service api for cloudbase.",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -1,14 +1,19 @@
1
1
  import { Environment } from '../environment';
2
- import { ICreateFunctionAgentParams } from './type';
2
+ import { IResponseInfo } from '../interfaces';
3
+ import { ICreateFunctionAgentParams, ICreateAgentParams, IAgentListItem, IListAgentsParams, IListAgentsResponse, IDeleteAgentParams } from './type';
3
4
  /**
4
5
  * Agent 管理类
6
+ * 提供新版 Agent 的完整生命周期管理功能
5
7
  */
6
8
  export declare class AgentService {
7
9
  private environment;
8
10
  private tcbService;
11
+ private scfService;
12
+ private functionService;
13
+ private userService;
9
14
  constructor(environment: Environment);
10
15
  /**
11
- * 创建函数型 Agent
16
+ * 创建函数型 Agent(兼容旧版本)
12
17
  * @param {string} [cwd=process.cwd()] 工作目录
13
18
  * @param {ICreateFunctionAgentParams} agentInfo Agent 信息
14
19
  * @returns {Promise<{ BotId: string; RequestId: string }>} Agent 创建结果
@@ -17,4 +22,33 @@ export declare class AgentService {
17
22
  BotId: string;
18
23
  RequestId: string;
19
24
  }>;
25
+ /**
26
+ * 部署新版 Agent 到 web云函数
27
+ * @param {ICreateAgentParams} params 创建参数
28
+ * @returns {Promise<IResponseInfo>} 创建结果
29
+ */
30
+ deployWebFn(params: ICreateAgentParams, isFirstDeploy?: boolean): Promise<IResponseInfo & {
31
+ AgentId?: string;
32
+ }>;
33
+ /**
34
+ * 获取 Agent 列表
35
+ * @param {IListAgentsParams} [params] 查询参数
36
+ * @returns {Promise<IListAgentsResponse>} Agent 列表
37
+ */
38
+ list(params?: IListAgentsParams): Promise<IListAgentsResponse>;
39
+ /**
40
+ * 获取 Agent 详情
41
+ * @param {object} params 查询参数
42
+ * @param {string} params.agentId Agent ID
43
+ * @returns {Promise<IAgentDetailResponse>} Agent 详情
44
+ */
45
+ getAgentInfo(params: {
46
+ agentId: string;
47
+ }): Promise<IAgentListItem | null>;
48
+ /**
49
+ * 删除 Agent
50
+ * @param {IDeleteAgentParams} params 删除参数
51
+ * @returns {Promise<IResponseInfo>} 删除结果
52
+ */
53
+ delete(params: IDeleteAgentParams): Promise<IResponseInfo>;
20
54
  }
@@ -20,3 +20,357 @@ export interface ICreateFunctionAgentParams {
20
20
  */
21
21
  Avatar?: string;
22
22
  }
23
+ export interface IEnvironmentVariable {
24
+ Name: string;
25
+ Value: string;
26
+ }
27
+ export interface IEnvironment {
28
+ Variables: IEnvironmentVariable[];
29
+ }
30
+ /**
31
+ * Agent 配置接口
32
+ */
33
+ export interface IAgentConfig {
34
+ /**
35
+ * 函数名称
36
+ */
37
+ functionName: string;
38
+ /**
39
+ * 代码结构
40
+ */
41
+ code?: {
42
+ cosBucketRegion?: string;
43
+ cosBucketName?: string;
44
+ cosObjectName?: string;
45
+ tempCosObjectName?: string;
46
+ zipFile?: string;
47
+ };
48
+ /**
49
+ * 超时时间(秒)
50
+ */
51
+ timeout?: number;
52
+ /**
53
+ * 环境变量
54
+ */
55
+ environment?: IEnvironment;
56
+ /**
57
+ * 运行时
58
+ */
59
+ runtime?: string;
60
+ /**
61
+ * 内存大小(MB)
62
+ */
63
+ memorySize?: number;
64
+ /**
65
+ * 描述
66
+ */
67
+ description?: string;
68
+ /**
69
+ * 会话配置
70
+ */
71
+ sessionConfig?: {
72
+ enable: boolean;
73
+ };
74
+ /**
75
+ * 绑定的资源
76
+ */
77
+ resourceList?: IAgentResource[];
78
+ /**
79
+ * 忽略的文件或目录
80
+ */
81
+ ignore?: string[];
82
+ installDependency?: boolean;
83
+ }
84
+ /**
85
+ * Agent 资源接口
86
+ */
87
+ export interface IAgentResource {
88
+ agentId: string;
89
+ /**
90
+ * 资源 ID
91
+ */
92
+ resourceId: string;
93
+ /**
94
+ * 资源类型
95
+ */
96
+ resourceType: string;
97
+ /**
98
+ * 子类型
99
+ */
100
+ subType: string;
101
+ /**
102
+ * 资源配置
103
+ */
104
+ resourceConfig: {
105
+ apiKey: string;
106
+ };
107
+ }
108
+ /**
109
+ * Agent 创建参数
110
+ */
111
+ export interface ICreateAgentParams {
112
+ /**
113
+ * Agent ID
114
+ */
115
+ agentId?: string;
116
+ /**
117
+ * Agent 名称
118
+ */
119
+ name: string;
120
+ /**
121
+ * 指定的 Agent 路径
122
+ */
123
+ agentPath: string;
124
+ /**
125
+ * Agent 根路径
126
+ */
127
+ agentRootPath: string;
128
+ deployConfig: IAgentConfig;
129
+ }
130
+ export interface ICreateAgentRes {
131
+ /**
132
+ *
133
+ */
134
+ agentId: string;
135
+ }
136
+ /**
137
+ * Agent 更新参数
138
+ */
139
+ export type IUpdateAgentParams = ICreateAgentParams;
140
+ /**
141
+ * Agent 列表查询参数
142
+ */
143
+ export interface IListAgentsParams {
144
+ /**
145
+ * 每页数量
146
+ */
147
+ limit?: number;
148
+ /**
149
+ * 偏移量
150
+ */
151
+ offset?: number;
152
+ /**
153
+ * Agent ID
154
+ */
155
+ agentId?: string;
156
+ }
157
+ /**
158
+ * Agent 列表响应
159
+ */
160
+ export interface IListAgentsResponse {
161
+ /**
162
+ * Agent 列表
163
+ */
164
+ AgentList: IAgentListItem[];
165
+ /**
166
+ * 总数
167
+ */
168
+ Total: number;
169
+ }
170
+ /**
171
+ * Agent 列表项
172
+ */
173
+ export interface IAgentListItem {
174
+ /**
175
+ * Agent ID
176
+ */
177
+ AgentId: string;
178
+ /**
179
+ * Agent 名称
180
+ */
181
+ Name: string;
182
+ /**
183
+ * 状态
184
+ */
185
+ UpdateTime: string;
186
+ /**
187
+ * 运行时配置
188
+ */
189
+ RuntimeConfig: IRuntimeConfig;
190
+ }
191
+ export interface IRuntimeConfig {
192
+ Runtime: string;
193
+ MemorySize: number;
194
+ Timeout: number;
195
+ Environment: string;
196
+ SessionConfig: {
197
+ Enable: boolean;
198
+ };
199
+ }
200
+ export interface IAgentDetailParams {
201
+ agentId: string;
202
+ }
203
+ /**
204
+ * Agent 详情响应
205
+ */
206
+ export interface IAgentDetailResponse {
207
+ /**
208
+ * Agent ID
209
+ */
210
+ id: string;
211
+ /**
212
+ * Agent 名称
213
+ */
214
+ name: string;
215
+ /**
216
+ * 状态
217
+ */
218
+ status: string;
219
+ /**
220
+ * 运行时
221
+ */
222
+ runtime: string;
223
+ /**
224
+ * 内存大小(MB)
225
+ */
226
+ memorySize: number;
227
+ /**
228
+ * 超时时间(秒)
229
+ */
230
+ timeout: number;
231
+ /**
232
+ * 描述
233
+ */
234
+ description: string;
235
+ /**
236
+ * 创建时间
237
+ */
238
+ createTime: string;
239
+ /**
240
+ * 更新时间
241
+ */
242
+ updateTime: string;
243
+ /**
244
+ * 环境变量
245
+ */
246
+ environment: IEnvironment;
247
+ /**
248
+ * 会话配置
249
+ */
250
+ sessionConfig: {
251
+ enable: boolean;
252
+ };
253
+ /**
254
+ * 绑定的资源
255
+ */
256
+ resources: IAgentResource[];
257
+ /**
258
+ * 部署信息
259
+ */
260
+ deployInfo?: {
261
+ mode: string;
262
+ version: string;
263
+ codeSize: number;
264
+ lastDeploy: string;
265
+ };
266
+ }
267
+ /**
268
+ * Agent 删除参数
269
+ */
270
+ export interface IDeleteAgentParams {
271
+ /**
272
+ * Agent ID
273
+ */
274
+ agentId: string;
275
+ }
276
+ /**
277
+ * Agent 代码下载参数
278
+ */
279
+ export interface IDownloadAgentCodeParams {
280
+ /**
281
+ * Agent ID
282
+ */
283
+ agentId: string;
284
+ /**
285
+ * 目标路径
286
+ */
287
+ targetPath: string;
288
+ }
289
+ /**
290
+ * 资源绑定参数
291
+ */
292
+ export interface IBindResourceParams {
293
+ /**
294
+ * Agent ID
295
+ */
296
+ agentId: string;
297
+ /**
298
+ * 资源列表
299
+ */
300
+ resourceList: IAgentResource[];
301
+ }
302
+ export interface IBindResourceRes {
303
+ /**
304
+ * 受影响的行数
305
+ */
306
+ Affected: number;
307
+ }
308
+ /**
309
+ * 资源解绑参数
310
+ */
311
+ export interface IUnbindResourceParams {
312
+ /**
313
+ * Agent ID
314
+ */
315
+ agentId: string;
316
+ /**
317
+ * 资源 ID
318
+ */
319
+ resourceId: string;
320
+ }
321
+ /**
322
+ * 资源解绑响应
323
+ */
324
+ export interface IUnbindResourceRes {
325
+ /**
326
+ *
327
+ */
328
+ Affected: number;
329
+ }
330
+ /**
331
+ * 获取资源绑定参数
332
+ */
333
+ export interface IGetResourceBindingParams {
334
+ /**
335
+ * Agent ID
336
+ */
337
+ agentId: string;
338
+ /**
339
+ * 资源 ID
340
+ */
341
+ resourceId: string;
342
+ /**
343
+ * 资源类型
344
+ */
345
+ resourceType: string;
346
+ }
347
+ /**
348
+ * 获取 Agent 资源参数
349
+ */
350
+ export interface IGetAgentResourcesParams {
351
+ /**
352
+ * Agent ID
353
+ */
354
+ agentId: string;
355
+ }
356
+ /**
357
+ * 资源绑定响应
358
+ */
359
+ export interface IResourceBindingResponse {
360
+ Total: number;
361
+ AgentResourceList: IAgentResource[];
362
+ }
363
+ /**
364
+ * Agent 资源响应
365
+ */
366
+ export interface IAgentResourcesResponse {
367
+ /**
368
+ * 资源列表
369
+ */
370
+ resources: IAgentResource[];
371
+ }
372
+ export interface IAgentCodeOptions {
373
+ deployConfig: IAgentConfig;
374
+ agentRootPath?: string;
375
+ agentPath?: string;
376
+ }
@@ -99,7 +99,7 @@ export declare class CloudRunService {
99
99
  deploy(params: {
100
100
  serverName: string;
101
101
  targetPath: string;
102
- serverConfig?: Partial<Pick<ICloudrunServerBaseConfig, 'OpenAccessTypes' | 'Cpu' | 'Mem' | 'MinNum' | 'MaxNum' | 'PolicyDetails' | 'CustomLogs' | 'EnvParams' | 'Port' | 'Dockerfile' | 'BuildDir' | 'InternalAccess' | 'InternalDomain' | 'EntryPoint' | 'Cmd'>>;
102
+ serverConfig?: Partial<Pick<ICloudrunServerBaseConfig, 'OpenAccessTypes' | 'Cpu' | 'Mem' | 'MinNum' | 'MaxNum' | 'PolicyDetails' | 'CustomLogs' | 'EnvParams' | 'Port' | 'Dockerfile' | 'BuildDir' | 'InternalAccess' | 'InternalDomain' | 'EntryPoint' | 'Cmd' | 'InstallDependency'>>;
103
103
  }): Promise<IResponseInfo>;
104
104
  /**
105
105
  * 获取云托管服务模板列表
@@ -245,6 +245,10 @@ export interface ICloudrunServerBaseConfig {
245
245
  * @example ["echo", "test"]
246
246
  */
247
247
  Cmd?: string[];
248
+ /**
249
+ * 是否在线安装依赖,true 则本地不打包 node_modules,依赖在线装(如Docker)
250
+ */
251
+ InstallDependency?: boolean;
248
252
  }
249
253
  export interface IDiffConfigItem {
250
254
  Key: string;
@@ -225,6 +225,7 @@ export declare class FunctionService {
225
225
  private vpcService;
226
226
  private scfService;
227
227
  private tcbService;
228
+ private userService;
228
229
  constructor(environment: Environment);
229
230
  /**
230
231
  * 增量更新函数代码
@@ -425,6 +426,7 @@ export declare class FunctionService {
425
426
  listLayerVersions(options: IVersionListOptions): Promise<IListLayerVersionsRes>;
426
427
  listLayers(options: ILayerListOptions): Promise<IListLayerRes>;
427
428
  getLayerVersion(options: ILayerOptions): Promise<IGetLayerVersionRes>;
429
+ waitFunctionActive(funcName: string, codeSecret?: string): Promise<void>;
428
430
  /**
429
431
  * 设置预置并发
430
432
  * @private
@@ -477,6 +479,9 @@ export declare class FunctionService {
477
479
  * @memberof FunctionService
478
480
  */
479
481
  getFunctionAlias(params: IGetFunctionAlias): Promise<IGetFunctionAliasRes>;
482
+ uploadFunctionZipToCos(options: IFunctionCode, installDependency: 'TRUE' | 'FALSE'): Promise<{
483
+ Key: string;
484
+ }>;
480
485
  private createAccessPath;
481
486
  private getCodeParams;
482
487
  private getTempCosInfo;
@@ -503,5 +508,4 @@ export declare class FunctionService {
503
508
  * @returns
504
509
  */
505
510
  private getSubnets;
506
- private waitFunctionActive;
507
511
  }
@@ -27,7 +27,7 @@ export declare class FunctionPacker {
27
27
  incrementalPath: string;
28
28
  codeType: CodeType;
29
29
  constructor(options: IPackerOptions);
30
- compressFiles(): Promise<void>;
30
+ compressFiles(): Promise<string>;
31
31
  getJavaFile(): void;
32
32
  build(): Promise<void>;
33
33
  isBigFile(): Promise<boolean>;
@@ -48,5 +48,11 @@ export declare class UserService {
48
48
  }): Promise<{
49
49
  RequestId: string;
50
50
  }>;
51
+ getTcbAccountInfo(): Promise<{
52
+ CloudUin: string;
53
+ CloudAppId: string;
54
+ WxAppId: string;
55
+ Channel: "ide" | "low_code";
56
+ }>;
51
57
  private isValidStr;
52
58
  }