@cloudbase/manager-node 5.1.1 → 5.2.0-beta.1
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/environment.js +5 -0
- package/lib/index.js +3 -0
- package/lib/sandbox/index.js +562 -0
- package/lib/sandbox/types.js +2 -0
- package/package.json +1 -1
- package/types/environment.d.ts +3 -0
- package/types/index.d.ts +2 -0
- package/types/sandbox/index.d.ts +98 -0
- package/types/sandbox/types.d.ts +618 -0
- package/cloudbase-manager-node/.claude/settings.local.json +0 -9
- package/cloudbase-manager-node/.editorconfig +0 -8
- package/cloudbase-manager-node/.eslintignore +0 -3
- package/cloudbase-manager-node/.eslintrc.js +0 -27
- package/cloudbase-manager-node/.prettierrc.js +0 -31
- package/cloudbase-manager-node/CHANGELOG.md +0 -109
- package/cloudbase-manager-node/LICENSE +0 -6
- package/cloudbase-manager-node/README.md +0 -46
- package/cloudbase-manager-node/jest.config.js +0 -18
- package/cloudbase-manager-node/package.json +0 -70
- package/cloudbase-manager-node/scripts/link.js +0 -98
- package/cloudbase-manager-node/tsconfig.json +0 -19
- package/cloudbase-manager-node/tsconfig.test.json +0 -14
package/lib/environment.js
CHANGED
|
@@ -20,6 +20,7 @@ const cloudBaseRun_1 = require("./cloudBaseRun");
|
|
|
20
20
|
const mysql_1 = require("./mysql");
|
|
21
21
|
const cloudApp_1 = require("./cloudApp");
|
|
22
22
|
const permission_1 = require("./permission");
|
|
23
|
+
const sandbox_1 = require("./sandbox");
|
|
23
24
|
class Environment {
|
|
24
25
|
constructor(context, envId) {
|
|
25
26
|
this.inited = false;
|
|
@@ -43,6 +44,7 @@ class Environment {
|
|
|
43
44
|
this.mysqlService = new mysql_1.MysqlService(this);
|
|
44
45
|
this.permissionService = new permission_1.PermissionService(this);
|
|
45
46
|
this.cloudAppService = new cloudApp_1.CloudAppService(this);
|
|
47
|
+
this.sandboxService = new sandbox_1.SandboxService(this);
|
|
46
48
|
}
|
|
47
49
|
async lazyInit() {
|
|
48
50
|
if (!this.inited) {
|
|
@@ -111,6 +113,9 @@ class Environment {
|
|
|
111
113
|
getPermissionService() {
|
|
112
114
|
return this.permissionService;
|
|
113
115
|
}
|
|
116
|
+
getSandboxService() {
|
|
117
|
+
return this.sandboxService;
|
|
118
|
+
}
|
|
114
119
|
getCommonService(serviceType = 'tcb', serviceVersion) {
|
|
115
120
|
return new common_1.CommonService(this, serviceType, serviceVersion);
|
|
116
121
|
}
|
package/lib/index.js
CHANGED
|
@@ -116,6 +116,9 @@ class CloudBase {
|
|
|
116
116
|
get permission() {
|
|
117
117
|
return this.currentEnvironment().getPermissionService();
|
|
118
118
|
}
|
|
119
|
+
get sandbox() {
|
|
120
|
+
return this.currentEnvironment().getSandboxService();
|
|
121
|
+
}
|
|
119
122
|
get docs() {
|
|
120
123
|
if (!this.docsService) {
|
|
121
124
|
this.docsService = new docs_1.DocsService();
|
|
@@ -0,0 +1,562 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SandboxService = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
class SandboxService {
|
|
6
|
+
constructor(environment) {
|
|
7
|
+
this.environment = environment;
|
|
8
|
+
this.agsService = new utils_1.CloudService(environment.cloudBaseContext, 'ags', '2025-09-20');
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 更新沙箱工具
|
|
12
|
+
* 更新指定沙箱工具的描述、网络配置、标签和自定义配置等信息。
|
|
13
|
+
* @param {UpdateSandboxToolOptions} options 更新参数
|
|
14
|
+
* @returns {Promise<UpdateSandboxToolResp>}
|
|
15
|
+
*/
|
|
16
|
+
async updateSandboxTool(options) {
|
|
17
|
+
const { toolId, description, networkConfiguration, tags, customConfiguration } = options;
|
|
18
|
+
// ToolId 校验:必填
|
|
19
|
+
if (typeof toolId !== 'string' || toolId.trim().length === 0) {
|
|
20
|
+
throw new Error('toolId is required');
|
|
21
|
+
}
|
|
22
|
+
// Description 校验:最大 200 字符
|
|
23
|
+
if (description !== undefined && description.length > 200) {
|
|
24
|
+
throw new Error('description length must be <= 200');
|
|
25
|
+
}
|
|
26
|
+
// NetworkConfiguration 校验
|
|
27
|
+
if (networkConfiguration !== undefined) {
|
|
28
|
+
const validModes = ['PUBLIC', 'VPC', 'SANDBOX'];
|
|
29
|
+
if (!networkConfiguration.NetworkMode || !validModes.includes(networkConfiguration.NetworkMode)) {
|
|
30
|
+
throw new Error(`NetworkMode must be one of: ${validModes.join(', ')}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// Tags 校验
|
|
34
|
+
if (tags !== undefined) {
|
|
35
|
+
if (!Array.isArray(tags)) {
|
|
36
|
+
throw new Error('tags must be an array');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
// CustomConfiguration 校验
|
|
40
|
+
if (customConfiguration !== undefined) {
|
|
41
|
+
// Image 镜像地址格式基本校验
|
|
42
|
+
if (customConfiguration.Image !== undefined) {
|
|
43
|
+
if (typeof customConfiguration.Image !== 'string' || customConfiguration.Image.trim().length === 0) {
|
|
44
|
+
throw new Error('Image must be a non-empty string');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// ImageRegistryType 校验
|
|
48
|
+
if (customConfiguration.ImageRegistryType !== undefined) {
|
|
49
|
+
const validTypes = ['enterprise', 'personal'];
|
|
50
|
+
if (!validTypes.includes(customConfiguration.ImageRegistryType)) {
|
|
51
|
+
throw new Error(`ImageRegistryType must be one of: ${validTypes.join(', ')}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Ports 校验
|
|
55
|
+
if (customConfiguration.Ports !== undefined) {
|
|
56
|
+
if (!Array.isArray(customConfiguration.Ports)) {
|
|
57
|
+
throw new Error('Ports must be an array');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// Env 校验
|
|
61
|
+
if (customConfiguration.Env !== undefined) {
|
|
62
|
+
if (!Array.isArray(customConfiguration.Env)) {
|
|
63
|
+
throw new Error('Env must be an array');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// DNSConfig.Servers 校验:文档标注为必填
|
|
67
|
+
if (customConfiguration.DNSConfig !== undefined) {
|
|
68
|
+
if (!Array.isArray(customConfiguration.DNSConfig.Servers) || customConfiguration.DNSConfig.Servers.length === 0) {
|
|
69
|
+
throw new Error('DNSConfig.Servers is required and must be a non-empty array');
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// 构造请求体
|
|
74
|
+
const reqData = {
|
|
75
|
+
ToolId: toolId
|
|
76
|
+
};
|
|
77
|
+
if (description !== undefined) {
|
|
78
|
+
reqData.Description = description;
|
|
79
|
+
}
|
|
80
|
+
if (networkConfiguration !== undefined) {
|
|
81
|
+
reqData.NetworkConfiguration = networkConfiguration;
|
|
82
|
+
}
|
|
83
|
+
if (tags !== undefined) {
|
|
84
|
+
reqData.Tags = tags;
|
|
85
|
+
}
|
|
86
|
+
if (customConfiguration !== undefined) {
|
|
87
|
+
reqData.CustomConfiguration = customConfiguration;
|
|
88
|
+
}
|
|
89
|
+
return this.agsService.request('UpdateSandboxTool', reqData);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* 查询沙箱工具列表
|
|
93
|
+
* @param {DescribeSandboxToolListOptions} options 查询参数
|
|
94
|
+
* @returns {Promise<DescribeSandboxToolListResp>}
|
|
95
|
+
*/
|
|
96
|
+
async describeSandboxToolList(options = {}) {
|
|
97
|
+
const { toolIds, offset, limit, filters } = options;
|
|
98
|
+
// ToolIds 校验
|
|
99
|
+
if (toolIds !== undefined) {
|
|
100
|
+
if (!Array.isArray(toolIds)) {
|
|
101
|
+
throw new Error('toolIds must be an array');
|
|
102
|
+
}
|
|
103
|
+
if (toolIds.length > 100) {
|
|
104
|
+
throw new Error('toolIds length must be <= 100');
|
|
105
|
+
}
|
|
106
|
+
const invalidId = toolIds.find(id => typeof id !== 'string' || id.trim().length === 0);
|
|
107
|
+
if (invalidId !== undefined) {
|
|
108
|
+
throw new Error('toolIds contains invalid item');
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// Offset 校验
|
|
112
|
+
if (offset !== undefined && (!Number.isInteger(offset) || offset < 0)) {
|
|
113
|
+
throw new Error('offset must be a non-negative integer');
|
|
114
|
+
}
|
|
115
|
+
// Limit 校验
|
|
116
|
+
if (limit !== undefined && (!Number.isInteger(limit) || limit < 1 || limit > 100)) {
|
|
117
|
+
throw new Error('limit must be an integer between 1 and 100');
|
|
118
|
+
}
|
|
119
|
+
// Filters 校验
|
|
120
|
+
if (filters !== undefined) {
|
|
121
|
+
if (!Array.isArray(filters)) {
|
|
122
|
+
throw new Error('filters must be an array');
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
// 构造请求体
|
|
126
|
+
const reqData = {};
|
|
127
|
+
if (toolIds !== undefined && toolIds.length > 0) {
|
|
128
|
+
reqData.ToolIds = toolIds;
|
|
129
|
+
}
|
|
130
|
+
if (offset !== undefined) {
|
|
131
|
+
reqData.Offset = offset;
|
|
132
|
+
}
|
|
133
|
+
if (limit !== undefined) {
|
|
134
|
+
reqData.Limit = limit;
|
|
135
|
+
}
|
|
136
|
+
if (filters !== undefined && filters.length > 0) {
|
|
137
|
+
reqData.Filters = filters;
|
|
138
|
+
}
|
|
139
|
+
return this.agsService.request('DescribeSandboxToolList', reqData);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* 创建沙箱工具
|
|
143
|
+
* @param {CreateSandboxToolOptions} options 创建参数
|
|
144
|
+
* @returns {Promise<CreateSandboxToolResp>}
|
|
145
|
+
*/
|
|
146
|
+
async createSandboxTool(options) {
|
|
147
|
+
const { toolName, toolType, networkConfiguration, description, defaultTimeout, tags, clientToken, roleArn, storageMounts, customConfiguration, logConfiguration } = options;
|
|
148
|
+
// ToolName 校验:必填,1-50 字符,英文/数字/下划线/连接线
|
|
149
|
+
if (typeof toolName !== 'string' || toolName.trim().length === 0) {
|
|
150
|
+
throw new Error('toolName is required');
|
|
151
|
+
}
|
|
152
|
+
if (toolName.length > 50) {
|
|
153
|
+
throw new Error('toolName length must be <= 50');
|
|
154
|
+
}
|
|
155
|
+
if (!/^[a-zA-Z0-9_-]+$/.test(toolName)) {
|
|
156
|
+
throw new Error('toolName can only contain letters, digits, underscores and hyphens');
|
|
157
|
+
}
|
|
158
|
+
// ToolType 校验:必填,枚举
|
|
159
|
+
const validToolTypes = ['browser', 'code-interpreter', 'custom'];
|
|
160
|
+
if (!toolType || !validToolTypes.includes(toolType)) {
|
|
161
|
+
throw new Error(`toolType must be one of: ${validToolTypes.join(', ')}`);
|
|
162
|
+
}
|
|
163
|
+
// NetworkConfiguration 校验:必填
|
|
164
|
+
if (!networkConfiguration) {
|
|
165
|
+
throw new Error('networkConfiguration is required');
|
|
166
|
+
}
|
|
167
|
+
const validModes = ['PUBLIC', 'VPC', 'SANDBOX'];
|
|
168
|
+
if (!networkConfiguration.NetworkMode || !validModes.includes(networkConfiguration.NetworkMode)) {
|
|
169
|
+
throw new Error(`NetworkMode must be one of: ${validModes.join(', ')}`);
|
|
170
|
+
}
|
|
171
|
+
// Description 校验
|
|
172
|
+
if (description !== undefined && description.length > 200) {
|
|
173
|
+
throw new Error('description length must be <= 200');
|
|
174
|
+
}
|
|
175
|
+
// DefaultTimeout 校验:格式如 5m、300s、1h
|
|
176
|
+
if (defaultTimeout !== undefined) {
|
|
177
|
+
if (typeof defaultTimeout !== 'string' || !/^\d+[smh]$/.test(defaultTimeout)) {
|
|
178
|
+
throw new Error('defaultTimeout must match format like 5m, 300s, 1h');
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
// ClientToken 校验:最大 64 字符
|
|
182
|
+
if (clientToken !== undefined && clientToken.length > 64) {
|
|
183
|
+
throw new Error('clientToken length must be <= 64');
|
|
184
|
+
}
|
|
185
|
+
// Tags 校验
|
|
186
|
+
if (tags !== undefined) {
|
|
187
|
+
if (!Array.isArray(tags)) {
|
|
188
|
+
throw new Error('tags must be an array');
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
// StorageMounts 校验
|
|
192
|
+
if (storageMounts !== undefined) {
|
|
193
|
+
if (!Array.isArray(storageMounts)) {
|
|
194
|
+
throw new Error('storageMounts must be an array');
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
// CustomConfiguration 校验
|
|
198
|
+
if (customConfiguration !== undefined) {
|
|
199
|
+
if (customConfiguration.Image !== undefined) {
|
|
200
|
+
if (typeof customConfiguration.Image !== 'string' || customConfiguration.Image.trim().length === 0) {
|
|
201
|
+
throw new Error('Image must be a non-empty string');
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (customConfiguration.ImageRegistryType !== undefined) {
|
|
205
|
+
const validTypes = ['enterprise', 'personal'];
|
|
206
|
+
if (!validTypes.includes(customConfiguration.ImageRegistryType)) {
|
|
207
|
+
throw new Error(`ImageRegistryType must be one of: ${validTypes.join(', ')}`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
if (customConfiguration.DNSConfig !== undefined) {
|
|
211
|
+
if (!Array.isArray(customConfiguration.DNSConfig.Servers) || customConfiguration.DNSConfig.Servers.length === 0) {
|
|
212
|
+
throw new Error('DNSConfig.Servers is required and must be a non-empty array');
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
// 构造请求体
|
|
217
|
+
const reqData = {
|
|
218
|
+
ToolName: toolName,
|
|
219
|
+
ToolType: toolType,
|
|
220
|
+
NetworkConfiguration: networkConfiguration
|
|
221
|
+
};
|
|
222
|
+
if (description !== undefined) {
|
|
223
|
+
reqData.Description = description;
|
|
224
|
+
}
|
|
225
|
+
if (defaultTimeout !== undefined) {
|
|
226
|
+
reqData.DefaultTimeout = defaultTimeout;
|
|
227
|
+
}
|
|
228
|
+
if (tags !== undefined) {
|
|
229
|
+
reqData.Tags = tags;
|
|
230
|
+
}
|
|
231
|
+
if (clientToken !== undefined) {
|
|
232
|
+
reqData.ClientToken = clientToken;
|
|
233
|
+
}
|
|
234
|
+
if (roleArn !== undefined) {
|
|
235
|
+
reqData.RoleArn = roleArn;
|
|
236
|
+
}
|
|
237
|
+
if (storageMounts !== undefined) {
|
|
238
|
+
reqData.StorageMounts = storageMounts;
|
|
239
|
+
}
|
|
240
|
+
if (customConfiguration !== undefined) {
|
|
241
|
+
reqData.CustomConfiguration = customConfiguration;
|
|
242
|
+
}
|
|
243
|
+
if (logConfiguration !== undefined) {
|
|
244
|
+
reqData.LogConfiguration = logConfiguration;
|
|
245
|
+
}
|
|
246
|
+
return this.agsService.request('CreateSandboxTool', reqData);
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* 删除沙箱工具
|
|
250
|
+
* @param {DeleteSandboxToolOptions} options 删除参数
|
|
251
|
+
* @returns {Promise<DeleteSandboxToolResp>}
|
|
252
|
+
*/
|
|
253
|
+
async deleteSandboxTool(options) {
|
|
254
|
+
const { toolId } = options;
|
|
255
|
+
// ToolId 校验:必填
|
|
256
|
+
if (typeof toolId !== 'string' || toolId.trim().length === 0) {
|
|
257
|
+
throw new Error('toolId is required');
|
|
258
|
+
}
|
|
259
|
+
const reqData = {
|
|
260
|
+
ToolId: toolId
|
|
261
|
+
};
|
|
262
|
+
return this.agsService.request('DeleteSandboxTool', reqData);
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* 恢复沙箱实例
|
|
266
|
+
* @param {ResumeSandboxInstanceOptions} options 恢复参数
|
|
267
|
+
* @returns {Promise<ResumeSandboxInstanceResp>}
|
|
268
|
+
*/
|
|
269
|
+
async resumeSandboxInstance(options) {
|
|
270
|
+
const { instanceId } = options;
|
|
271
|
+
// InstanceId 校验:必填
|
|
272
|
+
if (typeof instanceId !== 'string' || instanceId.trim().length === 0) {
|
|
273
|
+
throw new Error('instanceId is required');
|
|
274
|
+
}
|
|
275
|
+
const reqData = {
|
|
276
|
+
InstanceId: instanceId
|
|
277
|
+
};
|
|
278
|
+
return this.agsService.request('ResumeSandboxInstance', reqData);
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* 暂停沙箱实例
|
|
282
|
+
* @param {PauseSandboxInstanceOptions} options 暂停参数
|
|
283
|
+
* @returns {Promise<PauseSandboxInstanceResp>}
|
|
284
|
+
*/
|
|
285
|
+
async pauseSandboxInstance(options) {
|
|
286
|
+
const { instanceId } = options;
|
|
287
|
+
// InstanceId 校验:必填
|
|
288
|
+
if (typeof instanceId !== 'string' || instanceId.trim().length === 0) {
|
|
289
|
+
throw new Error('instanceId is required');
|
|
290
|
+
}
|
|
291
|
+
const reqData = {
|
|
292
|
+
InstanceId: instanceId
|
|
293
|
+
};
|
|
294
|
+
return this.agsService.request('PauseSandboxInstance', reqData);
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* 更新沙箱实例
|
|
298
|
+
* 更新指定沙箱实例的超时时间和元数据等信息。
|
|
299
|
+
* @param {UpdateSandboxInstanceOptions} options 更新参数
|
|
300
|
+
* @returns {Promise<UpdateSandboxInstanceResp>}
|
|
301
|
+
*/
|
|
302
|
+
async updateSandboxInstance(options) {
|
|
303
|
+
const { instanceId, timeout, metadata } = options;
|
|
304
|
+
// InstanceId 校验:必填
|
|
305
|
+
if (typeof instanceId !== 'string' || instanceId.trim().length === 0) {
|
|
306
|
+
throw new Error('instanceId is required');
|
|
307
|
+
}
|
|
308
|
+
// Timeout 校验:格式如 30s、5m、1h,最小 30s,最大 24h
|
|
309
|
+
if (timeout !== undefined) {
|
|
310
|
+
if (typeof timeout !== 'string' || !/^\d+[smh]$/.test(timeout)) {
|
|
311
|
+
throw new Error('timeout must match format like 30s, 5m, 1h');
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
// Metadata 校验
|
|
315
|
+
if (metadata !== undefined) {
|
|
316
|
+
if (!Array.isArray(metadata)) {
|
|
317
|
+
throw new Error('metadata must be an array');
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
// 构造请求体
|
|
321
|
+
const reqData = {
|
|
322
|
+
InstanceId: instanceId
|
|
323
|
+
};
|
|
324
|
+
if (timeout !== undefined) {
|
|
325
|
+
reqData.Timeout = timeout;
|
|
326
|
+
}
|
|
327
|
+
if (metadata !== undefined) {
|
|
328
|
+
reqData.Metadata = metadata;
|
|
329
|
+
}
|
|
330
|
+
return this.agsService.request('UpdateSandboxInstance', reqData);
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* 停止沙箱实例
|
|
334
|
+
* @param {StopSandboxInstanceOptions} options 停止参数
|
|
335
|
+
* @returns {Promise<StopSandboxInstanceResp>}
|
|
336
|
+
*/
|
|
337
|
+
async stopSandboxInstance(options) {
|
|
338
|
+
const { instanceId } = options;
|
|
339
|
+
// InstanceId 校验:必填
|
|
340
|
+
if (typeof instanceId !== 'string' || instanceId.trim().length === 0) {
|
|
341
|
+
throw new Error('instanceId is required');
|
|
342
|
+
}
|
|
343
|
+
const reqData = {
|
|
344
|
+
InstanceId: instanceId
|
|
345
|
+
};
|
|
346
|
+
return this.agsService.request('StopSandboxInstance', reqData);
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* 启动沙箱实例
|
|
350
|
+
* @param {StartSandboxInstanceOptions} options 启动参数
|
|
351
|
+
* @returns {Promise<StartSandboxInstanceResp>}
|
|
352
|
+
*/
|
|
353
|
+
async startSandboxInstance(options) {
|
|
354
|
+
const { toolId, toolName, timeout, clientToken, mountOptions, customConfiguration, authMode, metadata } = options;
|
|
355
|
+
// ToolId 与 ToolName 至少有一个要填
|
|
356
|
+
const hasToolId = toolId !== undefined && toolId.trim().length > 0;
|
|
357
|
+
const hasToolName = toolName !== undefined && toolName.trim().length > 0;
|
|
358
|
+
if (!hasToolId && !hasToolName) {
|
|
359
|
+
throw new Error('toolId or toolName is required, at least one must be provided');
|
|
360
|
+
}
|
|
361
|
+
// Timeout 校验:格式如 30s、5m、1h
|
|
362
|
+
if (timeout !== undefined) {
|
|
363
|
+
if (typeof timeout !== 'string' || !/^\d+[smh]$/.test(timeout)) {
|
|
364
|
+
throw new Error('timeout must match format like 30s, 5m, 1h');
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
// ClientToken 校验:最大 64 字符
|
|
368
|
+
if (clientToken !== undefined && clientToken.length > 64) {
|
|
369
|
+
throw new Error('clientToken length must be <= 64');
|
|
370
|
+
}
|
|
371
|
+
// MountOptions 校验
|
|
372
|
+
if (mountOptions !== undefined) {
|
|
373
|
+
if (!Array.isArray(mountOptions)) {
|
|
374
|
+
throw new Error('mountOptions must be an array');
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
// AuthMode 校验
|
|
378
|
+
if (authMode !== undefined) {
|
|
379
|
+
const validAuthModes = ['DEFAULT', 'TOKEN', 'NONE'];
|
|
380
|
+
if (!validAuthModes.includes(authMode)) {
|
|
381
|
+
throw new Error(`authMode must be one of: ${validAuthModes.join(', ')}`);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
// CustomConfiguration 校验
|
|
385
|
+
if (customConfiguration !== undefined) {
|
|
386
|
+
if (customConfiguration.Image !== undefined) {
|
|
387
|
+
if (typeof customConfiguration.Image !== 'string' || customConfiguration.Image.trim().length === 0) {
|
|
388
|
+
throw new Error('Image must be a non-empty string');
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
if (customConfiguration.ImageRegistryType !== undefined) {
|
|
392
|
+
const validTypes = ['enterprise', 'personal'];
|
|
393
|
+
if (!validTypes.includes(customConfiguration.ImageRegistryType)) {
|
|
394
|
+
throw new Error(`ImageRegistryType must be one of: ${validTypes.join(', ')}`);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
if (customConfiguration.DNSConfig !== undefined) {
|
|
398
|
+
if (!Array.isArray(customConfiguration.DNSConfig.Servers) || customConfiguration.DNSConfig.Servers.length === 0) {
|
|
399
|
+
throw new Error('DNSConfig.Servers is required and must be a non-empty array');
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
// Metadata 校验
|
|
404
|
+
if (metadata !== undefined) {
|
|
405
|
+
if (!Array.isArray(metadata)) {
|
|
406
|
+
throw new Error('metadata must be an array');
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
// 构造请求体
|
|
410
|
+
const reqData = {};
|
|
411
|
+
if (toolId !== undefined) {
|
|
412
|
+
reqData.ToolId = toolId;
|
|
413
|
+
}
|
|
414
|
+
if (toolName !== undefined) {
|
|
415
|
+
reqData.ToolName = toolName;
|
|
416
|
+
}
|
|
417
|
+
if (timeout !== undefined) {
|
|
418
|
+
reqData.Timeout = timeout;
|
|
419
|
+
}
|
|
420
|
+
if (clientToken !== undefined) {
|
|
421
|
+
reqData.ClientToken = clientToken;
|
|
422
|
+
}
|
|
423
|
+
if (mountOptions !== undefined) {
|
|
424
|
+
reqData.MountOptions = mountOptions;
|
|
425
|
+
}
|
|
426
|
+
if (customConfiguration !== undefined) {
|
|
427
|
+
reqData.CustomConfiguration = customConfiguration;
|
|
428
|
+
}
|
|
429
|
+
if (authMode !== undefined) {
|
|
430
|
+
reqData.AuthMode = authMode;
|
|
431
|
+
}
|
|
432
|
+
if (metadata !== undefined) {
|
|
433
|
+
reqData.Metadata = metadata;
|
|
434
|
+
}
|
|
435
|
+
return this.agsService.request('StartSandboxInstance', reqData);
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* 查询沙箱实例列表
|
|
439
|
+
* @param {DescribeSandboxInstanceListOptions} options 查询参数
|
|
440
|
+
* @returns {Promise<DescribeSandboxInstanceListResp>}
|
|
441
|
+
*/
|
|
442
|
+
async describeSandboxInstanceList(options = {}) {
|
|
443
|
+
const { instanceIds, toolId, offset, limit, filters } = options;
|
|
444
|
+
// InstanceIds 校验
|
|
445
|
+
if (instanceIds !== undefined) {
|
|
446
|
+
if (!Array.isArray(instanceIds)) {
|
|
447
|
+
throw new Error('instanceIds must be an array');
|
|
448
|
+
}
|
|
449
|
+
if (instanceIds.length > 100) {
|
|
450
|
+
throw new Error('instanceIds length must be <= 100');
|
|
451
|
+
}
|
|
452
|
+
const invalidId = instanceIds.find(id => typeof id !== 'string' || id.trim().length === 0);
|
|
453
|
+
if (invalidId !== undefined) {
|
|
454
|
+
throw new Error('instanceIds contains invalid item');
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
// ToolId 校验
|
|
458
|
+
if (toolId !== undefined) {
|
|
459
|
+
if (typeof toolId !== 'string' || toolId.trim().length === 0) {
|
|
460
|
+
throw new Error('toolId must be a non-empty string');
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
// Offset 校验
|
|
464
|
+
if (offset !== undefined && (!Number.isInteger(offset) || offset < 0)) {
|
|
465
|
+
throw new Error('offset must be a non-negative integer');
|
|
466
|
+
}
|
|
467
|
+
// Limit 校验
|
|
468
|
+
if (limit !== undefined && (!Number.isInteger(limit) || limit < 1 || limit > 100)) {
|
|
469
|
+
throw new Error('limit must be an integer between 1 and 100');
|
|
470
|
+
}
|
|
471
|
+
// Filters 校验
|
|
472
|
+
if (filters !== undefined) {
|
|
473
|
+
if (!Array.isArray(filters)) {
|
|
474
|
+
throw new Error('filters must be an array');
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
// 构造请求体
|
|
478
|
+
const reqData = {};
|
|
479
|
+
if (instanceIds !== undefined && instanceIds.length > 0) {
|
|
480
|
+
reqData.InstanceIds = instanceIds;
|
|
481
|
+
}
|
|
482
|
+
if (toolId !== undefined) {
|
|
483
|
+
reqData.ToolId = toolId;
|
|
484
|
+
}
|
|
485
|
+
if (offset !== undefined) {
|
|
486
|
+
reqData.Offset = offset;
|
|
487
|
+
}
|
|
488
|
+
if (limit !== undefined) {
|
|
489
|
+
reqData.Limit = limit;
|
|
490
|
+
}
|
|
491
|
+
if (filters !== undefined && filters.length > 0) {
|
|
492
|
+
reqData.Filters = filters;
|
|
493
|
+
}
|
|
494
|
+
return this.agsService.request('DescribeSandboxInstanceList', reqData);
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* 获取沙箱实例访问 Token
|
|
498
|
+
* 获取访问沙箱工具时所需要使用的访问 Token,创建沙箱实例后需调用此接口获取沙箱实例访问 Token。
|
|
499
|
+
* 此 Token 可用于调用代码沙箱实例执行代码,或浏览器沙箱实例进行浏览器操作等。
|
|
500
|
+
* @param {AcquireSandboxInstanceTokenOptions} options 请求参数
|
|
501
|
+
* @returns {Promise<AcquireSandboxInstanceTokenResp>}
|
|
502
|
+
*/
|
|
503
|
+
async acquireSandboxInstanceToken(options) {
|
|
504
|
+
const { instanceId } = options;
|
|
505
|
+
// InstanceId 校验:必填
|
|
506
|
+
if (typeof instanceId !== 'string' || instanceId.trim().length === 0) {
|
|
507
|
+
throw new Error('instanceId is required');
|
|
508
|
+
}
|
|
509
|
+
const reqData = {
|
|
510
|
+
InstanceId: instanceId
|
|
511
|
+
};
|
|
512
|
+
return this.agsService.request('AcquireSandboxInstanceToken', reqData);
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* 获取 API 密钥列表
|
|
516
|
+
* 获取 API 密钥简略信息列表,包含名称、创建时间等。
|
|
517
|
+
* @returns {Promise<DescribeAPIKeyListResp>}
|
|
518
|
+
*/
|
|
519
|
+
async describeAPIKeyList() {
|
|
520
|
+
return this.agsService.request('DescribeAPIKeyList', {});
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* 创建 API 密钥
|
|
524
|
+
* 创建新的 API 密钥,用于调用 Agent Sandbox 接口。
|
|
525
|
+
* 注意:生成的 APIKey 仅在此次响应中返回,后续无法再次获取,请妥善保管。
|
|
526
|
+
* @param {CreateAPIKeyOptions} options 创建参数
|
|
527
|
+
* @returns {Promise<CreateAPIKeyResp>}
|
|
528
|
+
*/
|
|
529
|
+
async createAPIKey(options = {}) {
|
|
530
|
+
const { name } = options;
|
|
531
|
+
// Name 校验
|
|
532
|
+
if (name !== undefined) {
|
|
533
|
+
if (typeof name !== 'string' || name.trim().length === 0) {
|
|
534
|
+
throw new Error('name must be a non-empty string');
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
// 构造请求体
|
|
538
|
+
const reqData = {};
|
|
539
|
+
if (name !== undefined) {
|
|
540
|
+
reqData.Name = name;
|
|
541
|
+
}
|
|
542
|
+
return this.agsService.request('CreateAPIKey', reqData);
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* 删除 API 密钥
|
|
546
|
+
* 注意:本接口删除的是 Agent Sandbox 专用 API Key,区别于腾讯云 Secret ID / Secret Key。
|
|
547
|
+
* @param {DeleteAPIKeyOptions} options 删除参数
|
|
548
|
+
* @returns {Promise<DeleteAPIKeyResp>}
|
|
549
|
+
*/
|
|
550
|
+
async deleteAPIKey(options) {
|
|
551
|
+
const { keyId } = options;
|
|
552
|
+
// KeyId 校验:必填
|
|
553
|
+
if (typeof keyId !== 'string' || keyId.trim().length === 0) {
|
|
554
|
+
throw new Error('keyId is required');
|
|
555
|
+
}
|
|
556
|
+
const reqData = {
|
|
557
|
+
KeyId: keyId
|
|
558
|
+
};
|
|
559
|
+
return this.agsService.request('DeleteAPIKey', reqData);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
exports.SandboxService = SandboxService;
|
package/package.json
CHANGED
package/types/environment.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ import { MysqlService } from './mysql';
|
|
|
16
16
|
import { CloudAppService } from './cloudApp';
|
|
17
17
|
import { EnvInfo } from './interfaces';
|
|
18
18
|
import { PermissionService } from './permission';
|
|
19
|
+
import { SandboxService } from './sandbox';
|
|
19
20
|
export declare class Environment {
|
|
20
21
|
inited: boolean;
|
|
21
22
|
cloudBaseContext: CloudBaseContext;
|
|
@@ -37,6 +38,7 @@ export declare class Environment {
|
|
|
37
38
|
private mysqlService;
|
|
38
39
|
private permissionService;
|
|
39
40
|
private cloudAppService;
|
|
41
|
+
private sandboxService;
|
|
40
42
|
constructor(context: CloudBaseContext, envId: string);
|
|
41
43
|
lazyInit(): Promise<any>;
|
|
42
44
|
getEnvId(): string;
|
|
@@ -56,6 +58,7 @@ export declare class Environment {
|
|
|
56
58
|
getMysqlService(): MysqlService;
|
|
57
59
|
getCloudAppService(): CloudAppService;
|
|
58
60
|
getPermissionService(): PermissionService;
|
|
61
|
+
getSandboxService(): SandboxService;
|
|
59
62
|
getCommonService(serviceType: string, serviceVersion: any): CommonService;
|
|
60
63
|
getServicesEnvInfo(): Promise<any>;
|
|
61
64
|
getAuthConfig(): {
|
package/types/index.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ import { CloudBaseRunService } from './cloudBaseRun';
|
|
|
16
16
|
import { MysqlService } from './mysql';
|
|
17
17
|
import { DocsService } from './docs';
|
|
18
18
|
import { PermissionService } from './permission';
|
|
19
|
+
import { SandboxService } from './sandbox';
|
|
19
20
|
import { CloudAppService } from './cloudApp';
|
|
20
21
|
interface CloudBaseConfig {
|
|
21
22
|
secretId?: string;
|
|
@@ -80,6 +81,7 @@ declare class CloudBase {
|
|
|
80
81
|
get third(): ThirdService;
|
|
81
82
|
get user(): UserService;
|
|
82
83
|
get permission(): PermissionService;
|
|
84
|
+
get sandbox(): SandboxService;
|
|
83
85
|
get docs(): DocsService;
|
|
84
86
|
getEnvironmentManager(): EnvironmentManager;
|
|
85
87
|
getManagerConfig(): CloudBaseConfig;
|