@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.
Files changed (205) hide show
  1. package/lib/auth/login.js +51 -65
  2. package/lib/auth/logout.js +3 -14
  3. package/lib/commands/account/login.js +136 -149
  4. package/lib/commands/account/logout.js +3 -14
  5. package/lib/commands/ag/base.js +203 -0
  6. package/lib/commands/ag/create.js +301 -0
  7. package/lib/commands/ag/debug/index.html +699 -0
  8. package/lib/commands/ag/delete.js +200 -0
  9. package/lib/commands/ag/deploy.js +185 -0
  10. package/lib/commands/ag/detail.js +113 -0
  11. package/lib/commands/ag/index.js +22 -0
  12. package/lib/commands/ag/list.js +155 -0
  13. package/lib/commands/ag/run.js +644 -0
  14. package/lib/commands/ai/index.js +76 -95
  15. package/lib/commands/cloudfunction/base.js +182 -203
  16. package/lib/commands/cloudrun/base.js +578 -603
  17. package/lib/commands/common.js +48 -63
  18. package/lib/commands/config/delete.js +16 -27
  19. package/lib/commands/config/get.js +13 -24
  20. package/lib/commands/config/list.js +16 -27
  21. package/lib/commands/config/set.js +33 -44
  22. package/lib/commands/db/base.js +221 -240
  23. package/lib/commands/env/base.js +36 -49
  24. package/lib/commands/env/domain.js +79 -94
  25. package/lib/commands/env/login.js +120 -135
  26. package/lib/commands/framework/index.js +32 -49
  27. package/lib/commands/fun/base.js +223 -244
  28. package/lib/commands/functions/alias/getRoute.js +33 -44
  29. package/lib/commands/functions/alias/setRoute.js +36 -47
  30. package/lib/commands/functions/code-download.js +43 -54
  31. package/lib/commands/functions/code-update.js +23 -34
  32. package/lib/commands/functions/concurrency/delete.js +11 -22
  33. package/lib/commands/functions/concurrency/list.js +20 -31
  34. package/lib/commands/functions/concurrency/set.js +13 -24
  35. package/lib/commands/functions/config-update.js +30 -41
  36. package/lib/commands/functions/copy.js +12 -23
  37. package/lib/commands/functions/delete.js +30 -41
  38. package/lib/commands/functions/deploy.js +184 -202
  39. package/lib/commands/functions/detail.js +23 -34
  40. package/lib/commands/functions/invoke.js +69 -75
  41. package/lib/commands/functions/layer/bind.js +102 -105
  42. package/lib/commands/functions/layer/create.js +29 -35
  43. package/lib/commands/functions/layer/delete.js +42 -48
  44. package/lib/commands/functions/layer/download.js +52 -58
  45. package/lib/commands/functions/layer/list.js +44 -50
  46. package/lib/commands/functions/layer/sort.js +39 -45
  47. package/lib/commands/functions/list.js +25 -36
  48. package/lib/commands/functions/log.js +65 -73
  49. package/lib/commands/functions/run.js +118 -116
  50. package/lib/commands/functions/trigger-create.js +32 -43
  51. package/lib/commands/functions/trigger-delete.js +50 -61
  52. package/lib/commands/functions/version/list.js +29 -40
  53. package/lib/commands/functions/version/publish.js +11 -22
  54. package/lib/commands/gateway/create.js +50 -61
  55. package/lib/commands/gateway/delete.js +38 -49
  56. package/lib/commands/gateway/domain.js +65 -80
  57. package/lib/commands/gateway/list.js +31 -42
  58. package/lib/commands/gateway/switch.js +48 -61
  59. package/lib/commands/helpers/init.js +226 -249
  60. package/lib/commands/helpers/new.js +35 -46
  61. package/lib/commands/helpers/open.js +22 -33
  62. package/lib/commands/hosting/hosting.js +157 -178
  63. package/lib/commands/index.js +1 -0
  64. package/lib/commands/lowcode/app.js +114 -144
  65. package/lib/commands/lowcode/comps.js +136 -127
  66. package/lib/commands/lowcode/utils.js +11 -22
  67. package/lib/commands/pull/pull.js +33 -46
  68. package/lib/commands/run/delete.js +35 -46
  69. package/lib/commands/run/image/delete.js +32 -39
  70. package/lib/commands/run/image/download.js +26 -33
  71. package/lib/commands/run/image/list.js +41 -48
  72. package/lib/commands/run/image/upload.js +26 -33
  73. package/lib/commands/run/list.js +32 -43
  74. package/lib/commands/run/service/config.js +17 -28
  75. package/lib/commands/run/service/deploy.js +15 -26
  76. package/lib/commands/run/service/list.js +48 -59
  77. package/lib/commands/run/service/update.js +7 -18
  78. package/lib/commands/run/standalonegateway/create.js +35 -42
  79. package/lib/commands/run/standalonegateway/destroy.js +23 -30
  80. package/lib/commands/run/standalonegateway/list.js +19 -26
  81. package/lib/commands/run/standalonegateway/package.js +31 -38
  82. package/lib/commands/run/standalonegateway/turn.js +27 -34
  83. package/lib/commands/run/version/create.js +198 -205
  84. package/lib/commands/run/version/delete.js +31 -38
  85. package/lib/commands/run/version/list.js +42 -49
  86. package/lib/commands/run/version/modify.js +27 -34
  87. package/lib/commands/run/version/update.js +201 -208
  88. package/lib/commands/runf/base.js +216 -237
  89. package/lib/commands/self-update.js +59 -72
  90. package/lib/commands/smart.js +66 -79
  91. package/lib/commands/storage/storage.js +192 -219
  92. package/lib/commands/third/thirdAttach.js +16 -27
  93. package/lib/commands/utils.js +119 -149
  94. package/lib/db/index.js +48 -67
  95. package/lib/decorators/captureError.js +10 -21
  96. package/lib/decorators/guard.js +11 -22
  97. package/lib/decorators/injectParams.js +29 -40
  98. package/lib/decorators/params/common.js +5 -2
  99. package/lib/decorators/params/index.js +3 -12
  100. package/lib/env/domain.js +13 -28
  101. package/lib/env/index.js +25 -44
  102. package/lib/env/login.js +30 -45
  103. package/lib/function/alias.js +31 -44
  104. package/lib/function/base.js +187 -215
  105. package/lib/function/code.js +8 -19
  106. package/lib/function/concurrency.js +43 -58
  107. package/lib/function/create.js +43 -53
  108. package/lib/function/delete.js +22 -35
  109. package/lib/function/layer/attach.js +33 -46
  110. package/lib/function/layer/create.js +34 -45
  111. package/lib/function/layer/delete.js +5 -16
  112. package/lib/function/layer/download.js +11 -22
  113. package/lib/function/layer/list.js +12 -25
  114. package/lib/function/layer/sort.js +6 -17
  115. package/lib/function/trigger.js +65 -82
  116. package/lib/function/update.js +24 -32
  117. package/lib/function/version.js +29 -42
  118. package/lib/function/vpc.js +12 -25
  119. package/lib/gateway/index.js +77 -104
  120. package/lib/hosting.js +157 -188
  121. package/lib/run/delete.js +3 -12
  122. package/lib/run/image/build.js +6 -15
  123. package/lib/run/image/delete.js +3 -12
  124. package/lib/run/image/info.js +3 -12
  125. package/lib/run/image/list.js +6 -15
  126. package/lib/run/list.js +19 -30
  127. package/lib/run/repo.js +6 -15
  128. package/lib/run/service/common.js +160 -173
  129. package/lib/run/service/config.js +44 -57
  130. package/lib/run/service/deployPackage.js +33 -44
  131. package/lib/run/service/list.js +8 -14
  132. package/lib/run/service/showLogs.js +69 -90
  133. package/lib/run/service/update.js +50 -63
  134. package/lib/run/standalonegateway/create.js +3 -12
  135. package/lib/run/standalonegateway/destroy.js +3 -12
  136. package/lib/run/standalonegateway/list.js +3 -12
  137. package/lib/run/standalonegateway/package/list.js +3 -12
  138. package/lib/run/standalonegateway/turn/off.js +3 -12
  139. package/lib/run/standalonegateway/turn/on.js +3 -12
  140. package/lib/run/version/create.js +41 -31
  141. package/lib/run/version/delete.js +3 -12
  142. package/lib/run/version/list.js +3 -12
  143. package/lib/run/version/modify.js +3 -12
  144. package/lib/run/version/repo.js +6 -15
  145. package/lib/run/version/update.js +37 -26
  146. package/lib/storage.js +62 -93
  147. package/lib/third/index.js +6 -17
  148. package/lib/utils/ai/banner.js +49 -60
  149. package/lib/utils/ai/claudeWindows.js +2 -2
  150. package/lib/utils/ai/config.js +169 -206
  151. package/lib/utils/ai/ensureFiles.js +6 -17
  152. package/lib/utils/ai/env.js +16 -27
  153. package/lib/utils/ai/envLocalManager.js +35 -52
  154. package/lib/utils/ai/router.js +927 -1005
  155. package/lib/utils/ai/setup.js +527 -563
  156. package/lib/utils/auth.js +3 -14
  157. package/lib/utils/checkTcbrEnv.js +20 -31
  158. package/lib/utils/cli-table.js +6 -1
  159. package/lib/utils/config.js +4 -13
  160. package/lib/utils/dts.js +98 -113
  161. package/lib/utils/env.js +154 -175
  162. package/lib/utils/function-packer.js +29 -42
  163. package/lib/utils/log.js +10 -21
  164. package/lib/utils/mcp-config-modifier.js +105 -120
  165. package/lib/utils/net/cloud-api-request.js +15 -23
  166. package/lib/utils/net/credential.js +26 -39
  167. package/lib/utils/net/http-request.js +63 -80
  168. package/lib/utils/net/manager-service.js +22 -35
  169. package/lib/utils/notice.js +16 -27
  170. package/lib/utils/output/loading.js +3 -12
  171. package/lib/utils/parallel.js +32 -43
  172. package/lib/utils/platform/mac.js +4 -15
  173. package/lib/utils/platform/port.js +4 -15
  174. package/lib/utils/prompt/select.js +6 -15
  175. package/lib/utils/report.js +28 -33
  176. package/lib/utils/reporter/agree.js +11 -22
  177. package/lib/utils/reporter/download.js +17 -28
  178. package/lib/utils/reporter/usage.js +12 -23
  179. package/lib/utils/store/auth.js +17 -30
  180. package/lib/utils/store/config.js +11 -25
  181. package/lib/utils/store/db.js +17 -36
  182. package/lib/utils/tcbrApi/callTcbrApi.js +19 -28
  183. package/lib/utils/template-manager.js +215 -242
  184. package/lib/utils/template.js +81 -96
  185. package/lib/utils/tools/common.js +45 -56
  186. package/lib/utils/tools/time.js +5 -16
  187. package/lib/utils/url.js +10 -4
  188. package/package.json +2 -2
  189. package/specs/ag-command/design.md +421 -0
  190. package/specs/ag-command/doc.md +204 -0
  191. package/specs/ag-command/requirements.md +173 -0
  192. package/specs/ag-command/summary.md +174 -0
  193. package/specs/ag-command/tasks.md +197 -0
  194. package/specs/ag-command/usage-guide.md +420 -0
  195. package/tsconfig.json +1 -1
  196. package/types/commands/ag/base.d.ts +44 -0
  197. package/types/commands/ag/create.d.ts +25 -0
  198. package/types/commands/ag/delete.d.ts +32 -0
  199. package/types/commands/ag/deploy.d.ts +31 -0
  200. package/types/commands/ag/detail.d.ts +28 -0
  201. package/types/commands/ag/index.d.ts +6 -0
  202. package/types/commands/ag/list.d.ts +35 -0
  203. package/types/commands/ag/run.d.ts +52 -0
  204. package/types/commands/cloudrun/base.d.ts +10 -0
  205. package/types/commands/index.d.ts +1 -0
@@ -0,0 +1,421 @@
1
+ # AG 命令设计方案
2
+
3
+ ## 1. 整体架构
4
+
5
+ 基于 doc.md 的设计要求,ag 命令将作为 CloudBase CLI 的一个子模块,用于管理新版 Agent(基于 Web 云函数的 Serverless 服务类型 Agent)。
6
+
7
+ ### 1.1 命令结构
8
+
9
+ ```
10
+ tcb ag <subcommand> [agentId] [options]
11
+ ```
12
+
13
+ ### 1.2 子命令列表
14
+
15
+ | 子命令 | 功能 | 参数 |
16
+ |--------|------|------|
17
+ | `create` | 初始化 Agent 项目 | `agentId` |
18
+ | `deploy` | 部署 Agent | `agentId` |
19
+ | `run` | 本地运行 Agent | `agentId` |
20
+ | `web` | 本地运行 Agent Web 应用 | `agentId` |
21
+ | `invoke` | 请求云端 Agent | `agentId` |
22
+ | `list` | 查询 Agent 列表 | - |
23
+ | `detail` | 查看 Agent 详情 | `agentId` |
24
+ | `delete` | 删除 Agent | `[agentId]` |
25
+ | `download` | 下载 Agent 代码 | `agentId` |
26
+ | `resource` | 资源管理 | - |
27
+
28
+ ## 2. 配置文件设计
29
+
30
+ ### 2.1 cloudbaserc.json 扩展
31
+
32
+ ```json
33
+ {
34
+ "envId": "dev-xxxx",
35
+ "agents": [
36
+ {
37
+ "id": "ag-xxx",
38
+ "name": "app",
39
+ "timeout": 5,
40
+ "environment": {
41
+ "key": "value"
42
+ },
43
+ "runtime": "Nodejs18.15",
44
+ "memorySize": 10,
45
+ "description": "",
46
+ "sessionConfig": {
47
+ "enable": true
48
+ },
49
+ "resources": [
50
+ {
51
+ "ResourceId": "",
52
+ "ResourceType": "",
53
+ "ResourceConfig": {
54
+ "Type": "",
55
+ "ApiKey": ""
56
+ }
57
+ }
58
+ ]
59
+ }
60
+ ]
61
+ }
62
+ ```
63
+
64
+ ### 2.2 TypeScript 类型定义
65
+
66
+ ```typescript
67
+ interface AgentConfig {
68
+ id: string;
69
+ name: string;
70
+ timeout?: number;
71
+ environment?: Record<string, string>;
72
+ runtime?: string;
73
+ memorySize?: number;
74
+ description?: string;
75
+ sessionConfig?: {
76
+ enable: boolean;
77
+ };
78
+ resources?: Array<{
79
+ ResourceId: string;
80
+ ResourceType: string;
81
+ ResourceConfig: {
82
+ Type: string;
83
+ ApiKey: string;
84
+ };
85
+ }>;
86
+ }
87
+
88
+ interface CloudbaseConfig {
89
+ envId: string;
90
+ agents?: AgentConfig[];
91
+ }
92
+ ```
93
+
94
+ ## 3. 命令实现设计
95
+
96
+ ### 3.1 基础服务类
97
+
98
+ 参考 cloudrun 模块的 `getCloudrunService` 实现,创建 `getAgentService`:
99
+
100
+ ```typescript
101
+ export async function getAgentService(envId: string) {
102
+ const region = await getRegion()
103
+ const { secretId, secretKey, token } = await checkAndGetCredential(true)
104
+
105
+ const app = new CloudBase({
106
+ region,
107
+ token,
108
+ envId,
109
+ secretId,
110
+ secretKey,
111
+ proxy: getProxy()
112
+ })
113
+ return app.agent
114
+ }
115
+ ```
116
+
117
+ ### 3.2 命令类设计
118
+
119
+ 每个子命令对应一个 Command 类,使用装饰器模式:
120
+
121
+ ```typescript
122
+ @ICommand()
123
+ export class AgentCreateCommand extends Command {
124
+ get options() {
125
+ return {
126
+ cmd: 'ag',
127
+ childCmd: 'create <agentId>',
128
+ options: [
129
+ {
130
+ flags: '-e, --envId <envId>',
131
+ desc: t('环境 ID')
132
+ },
133
+ {
134
+ flags: '--template <template>',
135
+ desc: t('模板名称')
136
+ },
137
+ {
138
+ flags: '--targetPath <targetPath>',
139
+ desc: t('项目初始化目标路径')
140
+ }
141
+ ],
142
+ requiredEnvId: false,
143
+ autoRunLogin: true,
144
+ desc: t('初始化 Agent 项目')
145
+ }
146
+ }
147
+
148
+ @InjectParams()
149
+ async execute(
150
+ @CmdContext() ctx: any,
151
+ @EnvId() envId: string,
152
+ @Log() log: Logger,
153
+ @ArgsParams() params: string[],
154
+ @ArgsOptions() options: {
155
+ template?: string;
156
+ targetPath?: string;
157
+ }
158
+ ) {
159
+ // 实现逻辑
160
+ }
161
+ }
162
+ ```
163
+
164
+ ## 4. 详细功能设计
165
+
166
+ ### 4.1 ag create - 初始化 Agent 项目
167
+
168
+ **功能**:创建新的 Agent 项目结构
169
+
170
+ **参数**:
171
+ - `agentId`:Agent 标识符(必需)
172
+ - `--template`:模板名称(可选)
173
+ - `--targetPath`:目标路径(可选,默认当前目录)
174
+
175
+ **实现逻辑**:
176
+ 1. 验证 agentId 格式
177
+ 2. 选择或指定模板
178
+ 3. 下载模板到指定目录
179
+ 4. 更新 cloudbaserc.json 配置
180
+ 5. 初始化项目依赖
181
+
182
+ ### 4.2 ag deploy - 部署 Agent
183
+
184
+ **功能**:部署 Agent 到云端
185
+
186
+ **参数**:
187
+ - `agentId`:Agent 标识符(必需)
188
+ - `--mode`:部署模式(webFn | cloudrun,默认 webFn)
189
+ - `--force`:强制部署(可选)
190
+
191
+ **实现逻辑**:
192
+ 1. 读取配置文件
193
+ 2. 检查 Agent 是否存在(首次部署 vs 更新部署)
194
+ 3. 打包代码
195
+ 4. 调用相应的部署接口
196
+ 5. 更新配置信息
197
+
198
+ ### 4.3 ag run - 本地运行 Agent
199
+
200
+ **功能**:本地调试运行 Agent
201
+
202
+ **参数**:
203
+ - `agentId`:Agent 标识符(必需)
204
+ - `--extendedContext`:扩展上下文(可选)
205
+ - `--port`:端口号(可选,默认 3000)
206
+
207
+ **实现逻辑**:
208
+ 1. 读取 Agent 配置
209
+ 2. 设置本地环境变量
210
+ 3. 启动本地服务
211
+ 4. 打开调试界面
212
+
213
+ ### 4.4 ag web - 本地运行 Agent Web 应用
214
+
215
+ **功能**:启动 Agent Web 服务
216
+
217
+ **参数**:
218
+ - `agentId`:Agent 标识符(必需)
219
+ - `--port`:端口号(可选,默认 8080)
220
+
221
+ **实现逻辑**:
222
+ 1. 读取 Agent 配置
223
+ 2. 启动 Web 服务器
224
+ 3. 提供访问地址
225
+
226
+ ### 4.5 ag invoke - 请求云端 Agent
227
+
228
+ **功能**:调用云端 Agent 服务
229
+
230
+ **参数**:
231
+ - `agentId`:Agent 标识符(必需)
232
+ - `-d, --data`:请求数据 JSON
233
+ - `-h, --headers`:请求头 JSON
234
+
235
+ **实现逻辑**:
236
+ 1. 构建请求参数
237
+ 2. 发送 HTTP 请求到 Agent 服务
238
+ 3. 输出响应结果
239
+
240
+ ### 4.6 ag list - 查询 Agent 列表
241
+
242
+ **功能**:列出环境中的所有 Agent
243
+
244
+ **参数**:
245
+ - `-l, --limit`:数据长度(可选)
246
+ - `-o, --offset`:偏移量(可选)
247
+
248
+ **实现逻辑**:
249
+ 1. 调用列表接口
250
+ 2. 格式化输出表格
251
+ 3. 显示 Agent 基本信息
252
+
253
+ ### 4.7 ag detail - 查看 Agent 详情
254
+
255
+ **功能**:查看指定 Agent 的详细信息
256
+
257
+ **参数**:
258
+ - `agentId`:Agent 标识符(必需)
259
+
260
+ **实现逻辑**:
261
+ 1. 调用详情接口
262
+ 2. 查询绑定的资源信息
263
+ 3. 格式化输出详细信息
264
+
265
+ ### 4.8 ag delete - 删除 Agent
266
+
267
+ **功能**:删除指定的 Agent 或所有 Agent
268
+
269
+ **参数**:
270
+ - `[agentId]`:Agent 标识符(可选,不指定则删除所有)
271
+ - `--force`:强制删除(可选)
272
+
273
+ **实现逻辑**:
274
+ 1. 确认删除操作
275
+ 2. 调用删除接口
276
+ 3. 更新本地配置文件
277
+
278
+ ### 4.9 ag download - 下载 Agent 代码
279
+
280
+ **功能**:下载云端 Agent 代码到本地
281
+
282
+ **参数**:
283
+ - `agentId`:Agent 标识符(必需)
284
+ - `--destPath`:目标目录(可选)
285
+ - `--force`:强制覆盖(可选)
286
+
287
+ **实现逻辑**:
288
+ 1. 选择目标目录
289
+ 2. 检查覆盖确认
290
+ 3. 下载代码文件
291
+ 4. 更新本地配置
292
+
293
+ ### 4.10 ag resource - 资源管理
294
+
295
+ **子命令**:
296
+ - `ag resource bind`:绑定资源
297
+ - `ag resource unbind`:解绑资源
298
+ - `ag resource detail`:查询绑定资源
299
+
300
+ **实现逻辑**:
301
+ 1. 根据子命令调用相应接口
302
+ 2. 处理资源绑定关系
303
+ 3. 更新配置信息
304
+
305
+ ## 5. 错误处理设计
306
+
307
+ ### 5.1 通用错误处理
308
+
309
+ ```typescript
310
+ export class AgentError extends CloudBaseError {
311
+ constructor(message: string, code?: string) {
312
+ super(message, code)
313
+ this.name = 'AgentError'
314
+ }
315
+ }
316
+ ```
317
+
318
+ ### 5.2 错误类型
319
+
320
+ - 配置文件错误
321
+ - Agent 不存在错误
322
+ - 部署失败错误
323
+ - 网络请求错误
324
+ - 权限不足错误
325
+
326
+ ## 6. 工具函数设计
327
+
328
+ ### 6.1 配置文件操作
329
+
330
+ ```typescript
331
+ // 读取 Agent 配置
332
+ export async function getAgentConfig(agentId: string): Promise<AgentConfig>
333
+
334
+ // 更新 Agent 配置
335
+ export async function updateAgentConfig(agentId: string, config: Partial<AgentConfig>): Promise<void>
336
+
337
+ // 验证 Agent ID 格式
338
+ export function validateAgentId(agentId: string): boolean
339
+ ```
340
+
341
+ ### 6.2 交互式输入
342
+
343
+ ```typescript
344
+ // 选择 Agent
345
+ export async function selectAgent(agents: AgentConfig[]): Promise<string>
346
+
347
+ // 输入 Agent 名称
348
+ export async function inputAgentName(defaultName?: string): Promise<string>
349
+
350
+ // 确认操作
351
+ export async function confirmOperation(message: string): Promise<boolean>
352
+ ```
353
+
354
+ ## 7. 测试策略
355
+
356
+ ### 7.1 单元测试
357
+
358
+ - 配置文件操作测试
359
+ - 工具函数测试
360
+ - 错误处理测试
361
+
362
+ ### 7.2 集成测试
363
+
364
+ - 命令执行流程测试
365
+ - API 接口调用测试
366
+ - 文件操作测试
367
+
368
+ ### 7.3 端到端测试
369
+
370
+ - 完整的 Agent 生命周期测试
371
+ - 多环境部署测试
372
+ - 错误场景测试
373
+
374
+ ## 8. 国际化支持
375
+
376
+ 所有用户可见的文本都需要支持国际化,使用 `t()` 函数包装:
377
+
378
+ ```typescript
379
+ desc: t('初始化 Agent 项目')
380
+ message: t('请输入 Agent 名称')
381
+ ```
382
+
383
+ ## 9. 日志和监控
384
+
385
+ ### 9.1 操作日志
386
+
387
+ - 记录关键操作步骤
388
+ - 记录错误信息和堆栈
389
+ - 记录性能指标
390
+
391
+ ### 9.2 用户反馈
392
+
393
+ - 操作进度提示
394
+ - 成功/失败状态反馈
395
+ - 帮助信息和建议
396
+
397
+ ## 10. 兼容性考虑
398
+
399
+ ### 10.1 向后兼容
400
+
401
+ - 支持旧版配置文件格式
402
+ - 提供迁移工具和指导
403
+
404
+ ### 10.2 平台兼容
405
+
406
+ - 支持 Windows、macOS、Linux
407
+ - 支持不同 Node.js 版本
408
+
409
+ ## 11. 安全性设计
410
+
411
+ ### 11.1 凭证管理
412
+
413
+ - 安全存储访问凭证
414
+ - 支持临时凭证
415
+ - 避免凭证泄露
416
+
417
+ ### 11.2 代码保护
418
+
419
+ - 支持代码加密
420
+ - 安全的代码传输
421
+ - 访问权限控制
@@ -0,0 +1,204 @@
1
+ # 背景
2
+ 云开发平台 Agent 架构后续统一切换为基于 Web 云函数的 Serverless 服务类型 Agent,且Agent 实现统一基于 AG-Kit 框架完成,CLI 需针对新版 Agent 完成 开发调试,部署,管理等工作
3
+
4
+ # 设计
5
+
6
+ ## Agent 配置文件 cloudbaserc.json
7
+
8
+ ``` json
9
+ {
10
+ // 关联环境 ID
11
+ "envId": "dev-xxxx",
12
+ // agent 项目的上级目录
13
+ "agentRoot": "./",
14
+ // agent 配置
15
+ "agents": [
16
+ {
17
+ // agent id,也是 agent 代码目录名称
18
+ "id": "ag-xxx",
19
+ // agent 名称
20
+ "name": "app",
21
+ // 超时时间,单位:秒 S
22
+ "timeout": 5,
23
+ // 环境变量
24
+ "environment": {
25
+ "key": "value"
26
+ },
27
+ "runtime": "Nodejs18.15",
28
+ "memorySize": 10,
29
+ "description": "",
30
+ "sessionConfig": {
31
+ "enable": true // 是否开启会话配置
32
+ },
33
+ "resources": [ // 要绑定的资源
34
+ {
35
+ "ResourceId": "", // 资源id
36
+ "RecourceType": "", // 资源种类
37
+ "RecourceConfig": {
38
+ "Type": "", // 资源的子类型
39
+ "ApiKey": "" // 密钥
40
+ }
41
+ }
42
+ ]
43
+ }
44
+ ]
45
+ }
46
+ ```
47
+
48
+
49
+ ## 本地运行 Agent
50
+
51
+ ```
52
+ tcb ag run agId [options]
53
+ ```
54
+
55
+ | 命令行参数 | 含义 |
56
+ | ------ | ------ |
57
+ | -e <envId> | 可选,环境 ID |
58
+ | --extendedContext <extendedContext> | 可选,示例:--extendedContext '{"a":1,"b":2}' |
59
+ | -h | 查看命令帮助信息 |
60
+
61
+ 示例
62
+
63
+ ```
64
+ tcb ag run ag-xxx
65
+ ```
66
+
67
+ 本地运行后可类似 函数式 Agent 启动后打开浏览器渲染 Agent-UI 组件进行调试对话
68
+
69
+ ## 本地运行 Agent Web 应用
70
+
71
+ ```
72
+ tcb ag web agId [options]
73
+ ```
74
+ | 命令行参数 | 含义 |
75
+ | ------ | ------ |
76
+ | --port | Web 服务端口号 |
77
+
78
+ 示例
79
+
80
+ ```
81
+ tcb ag web ag-xxx --port 8080
82
+ ```
83
+
84
+ ## 请求云端 Agent
85
+ HTTP API 形式
86
+
87
+ ```
88
+ curl -L 'https://${ag-xxxxaaaaaa-xxx}.ag.tcloudbase.com?webfn=true' \
89
+ -H 'Content-Type: application/json' \
90
+ -H 'Accept: application/json' \
91
+ -H 'Authorization: Bearer <ACCESS_TOKEN>' \
92
+ -d '{}'
93
+ ```
94
+
95
+ 命令形式
96
+ ```
97
+ tcb ag invoke agId [options]
98
+ ```
99
+ | 命令行参数 | 含义 |
100
+ | ------ | ------ |
101
+ | -d | 触发调用的 data JSON 串,如 '{"prompt": "Hello world!"}' |
102
+ | -h | 触发调用的header JSON 串, 如 '{"Authorization": "Bearer <ACCESS_TOKEN>"}' |
103
+
104
+ ## 部署 Agent
105
+
106
+ 内部实现区分首次部署及后续更新部署,命令不做区分
107
+ ```
108
+ tcb ag deploy agId [options]
109
+ ```
110
+ | 命令行参数 | 含义 |
111
+ | ------ | ------ |
112
+ | --mode | webFn:默认值,部署到 Web 函数,cloudrun:部署到托管 |
113
+ - 部署函数
114
+ 部署 Agent 会参照 Agent JSON 配置文件
115
+ 实现:先检查当前是否存在该 agId 对应的agent,不存在则为首次部署,调用 Create 接口,存在则为更新部署,调用 Update 接口,更新配置信息仍读 Agent 配置文件
116
+ ~~首次部署时 CLI 处理给角色授权~~
117
+
118
+ - 部署托管
119
+ 参照原云托管部署流程
120
+
121
+ ## 查询 Agent 列表
122
+ ```
123
+ tcb ag list [options]
124
+ ```
125
+ | 命令行参数 | 含义 |
126
+ | ------ | ------ |
127
+ | -l | 数据长度 |
128
+ | -o | 偏移量 |
129
+ | -h | 查看命令帮助信息 |
130
+
131
+ 示例
132
+ ```
133
+ tcb ag list -l 10 -o 10
134
+ ```
135
+ ## 查看 Agent 详情
136
+
137
+ ```
138
+ tcb ag detail ag-xxx
139
+ ```
140
+ 这里查询会同时查绑定的 resource 信息
141
+
142
+ ## 删除 Agent
143
+
144
+ 删除指定的 Agent
145
+ ```
146
+ tcb ag delete ag-xxx
147
+ ```
148
+ 删除配置文件中所有 Agent
149
+ ```
150
+ tcb ag delete
151
+ ```
152
+
153
+ ## 初始化 Agent 项目
154
+
155
+ 用户准备项目目录,进入目录后执行该命令生成 Agent 初始项目
156
+ ```
157
+ tcb ag create agId [options]
158
+ ```
159
+ | 命令行参数 | 含义 |
160
+ | ------ | ------ |
161
+ | --template <template> | agent 项目模板 |
162
+ | -h | 查看命令帮助信息 |
163
+
164
+ ```
165
+ tcb ag create ag-xxx chat-bot
166
+ ```
167
+ 实现上可通过下载 Agent 模板项目或者 调用 @ag-kit/cli 命令 <code>ag-kit init</code> 完成初始化
168
+
169
+ ## 下载 Agent 代码
170
+
171
+ 将指定的Agent 项目代码下载到本地指定目录
172
+ ```
173
+ tcb ag download ag-xxx [options]
174
+ ```
175
+ | 命令行参数 | 含义 |
176
+ | ------ | ------ |
177
+ | --destPath | 目标目录 |
178
+ | -h | 查看命令帮助信息 |
179
+
180
+ ## 解绑资源
181
+ ```
182
+ tcb ag resource unbind [options]
183
+ ```
184
+ | 命令行参数 | 含义 |
185
+ | ------ | ------ |
186
+ | --envId | 环境ID |
187
+ | --agId | 要解绑的 agent 标识 |
188
+ | --resourceId | 资源ID |
189
+ | --recourceType | 资源类型 |
190
+ | -h | 查看命令帮助信息 |
191
+
192
+ ## 查询绑定资源
193
+ ```
194
+ tcb ag resource detail [options]
195
+ ```
196
+ | 命令行参数 | 含义 |
197
+ | ------ | ------ |
198
+ | --envId | 环境ID |
199
+ | --agId | agent 标识 |
200
+ | --resourceId | 资源ID |
201
+ | --recourceType | 资源类型 |
202
+ | -h | 查看命令帮助信息 |
203
+
204
+ # 讨论