@agentrun/sdk 0.0.3-test.21197424453 → 0.0.3
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/dist/index.cjs +933 -1059
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -17
- package/dist/index.d.ts +1 -17
- package/dist/index.js +933 -1059
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4038,12 +4038,11 @@ var TemplateType, SandboxState, TemplateNetworkMode, TemplateOSSPermission, Code
|
|
|
4038
4038
|
var init_model4 = __esm({
|
|
4039
4039
|
"src/sandbox/model.ts"() {
|
|
4040
4040
|
init_model();
|
|
4041
|
-
TemplateType = /* @__PURE__ */ ((
|
|
4042
|
-
|
|
4043
|
-
|
|
4044
|
-
|
|
4045
|
-
|
|
4046
|
-
return TemplateType2;
|
|
4041
|
+
TemplateType = /* @__PURE__ */ ((TemplateType3) => {
|
|
4042
|
+
TemplateType3["CODE_INTERPRETER"] = "CodeInterpreter";
|
|
4043
|
+
TemplateType3["BROWSER"] = "Browser";
|
|
4044
|
+
TemplateType3["AIO"] = "AllInOne";
|
|
4045
|
+
return TemplateType3;
|
|
4047
4046
|
})(TemplateType || {});
|
|
4048
4047
|
SandboxState = /* @__PURE__ */ ((SandboxState2) => {
|
|
4049
4048
|
SandboxState2["CREATING"] = "Creating";
|
|
@@ -4071,675 +4070,618 @@ var init_model4 = __esm({
|
|
|
4071
4070
|
})(CodeLanguage || {});
|
|
4072
4071
|
}
|
|
4073
4072
|
});
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4073
|
+
|
|
4074
|
+
// src/sandbox/sandbox.ts
|
|
4075
|
+
var Sandbox;
|
|
4076
|
+
var init_sandbox = __esm({
|
|
4077
|
+
"src/sandbox/sandbox.ts"() {
|
|
4077
4078
|
init_config();
|
|
4078
|
-
|
|
4079
|
-
init_log();
|
|
4079
|
+
init_resource();
|
|
4080
4080
|
init_model4();
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
constructor(params) {
|
|
4084
|
-
super({
|
|
4085
|
-
sandboxId: params.sandboxId,
|
|
4086
|
-
config: params.config,
|
|
4087
|
-
// Set namespace to include sandboxId for correct API path generation
|
|
4088
|
-
namespace: `sandboxes/${params.sandboxId}`
|
|
4089
|
-
});
|
|
4090
|
-
}
|
|
4081
|
+
Sandbox = class _Sandbox extends ResourceBase {
|
|
4082
|
+
templateType;
|
|
4091
4083
|
/**
|
|
4092
|
-
*
|
|
4084
|
+
* 沙箱 ID / Sandbox ID
|
|
4093
4085
|
*/
|
|
4094
|
-
|
|
4095
|
-
const query = {};
|
|
4096
|
-
if (params?.path !== void 0) {
|
|
4097
|
-
query.path = params.path;
|
|
4098
|
-
}
|
|
4099
|
-
if (params?.depth !== void 0) {
|
|
4100
|
-
query.depth = params.depth;
|
|
4101
|
-
}
|
|
4102
|
-
return this.get({ path: "/filesystem", query, config: params?.config });
|
|
4103
|
-
}
|
|
4086
|
+
sandboxId;
|
|
4104
4087
|
/**
|
|
4105
|
-
*
|
|
4088
|
+
* 沙箱名称 / Sandbox Name
|
|
4106
4089
|
*/
|
|
4107
|
-
|
|
4108
|
-
const query = {
|
|
4109
|
-
path: params.path
|
|
4110
|
-
};
|
|
4111
|
-
return this.get({ path: "/filesystem/stat", query, config: params.config });
|
|
4112
|
-
}
|
|
4090
|
+
sandboxName;
|
|
4113
4091
|
/**
|
|
4114
|
-
*
|
|
4092
|
+
* 模板 ID / Template ID
|
|
4115
4093
|
*/
|
|
4116
|
-
|
|
4117
|
-
const data = {
|
|
4118
|
-
path: params.path,
|
|
4119
|
-
parents: params.parents !== void 0 ? params.parents : true,
|
|
4120
|
-
mode: params.mode || "0755"
|
|
4121
|
-
};
|
|
4122
|
-
return this.post({ path: "/filesystem/mkdir", data, config: params.config });
|
|
4123
|
-
}
|
|
4094
|
+
templateId;
|
|
4124
4095
|
/**
|
|
4125
|
-
*
|
|
4096
|
+
* 模板名称 / Template Name
|
|
4126
4097
|
*/
|
|
4127
|
-
|
|
4128
|
-
const data = {
|
|
4129
|
-
source: params.source,
|
|
4130
|
-
destination: params.destination
|
|
4131
|
-
};
|
|
4132
|
-
return this.post({ path: "/filesystem/move", data, config: params.config });
|
|
4133
|
-
}
|
|
4098
|
+
templateName;
|
|
4134
4099
|
/**
|
|
4135
|
-
*
|
|
4100
|
+
* 沙箱状态 / Sandbox State
|
|
4136
4101
|
*/
|
|
4137
|
-
|
|
4138
|
-
const data = {
|
|
4139
|
-
path: params.path
|
|
4140
|
-
};
|
|
4141
|
-
return this.post({ path: "/filesystem/remove", data, config: params.config });
|
|
4142
|
-
}
|
|
4102
|
+
state;
|
|
4143
4103
|
/**
|
|
4144
|
-
*
|
|
4104
|
+
* 状态原因 / State Reason
|
|
4145
4105
|
*/
|
|
4146
|
-
|
|
4147
|
-
return this.get({ path: "/contexts", config: params?.config });
|
|
4148
|
-
}
|
|
4106
|
+
stateReason;
|
|
4149
4107
|
/**
|
|
4150
|
-
*
|
|
4108
|
+
* 沙箱创建时间 / Sandbox Creation Time
|
|
4151
4109
|
*/
|
|
4152
|
-
|
|
4153
|
-
const language = params?.language || "python" /* PYTHON */;
|
|
4154
|
-
const cwd = params?.cwd || "/home/user";
|
|
4155
|
-
if (language !== "python" && language !== "javascript") {
|
|
4156
|
-
throw new Error(
|
|
4157
|
-
`language must be 'python' or 'javascript', got: ${language}`
|
|
4158
|
-
);
|
|
4159
|
-
}
|
|
4160
|
-
const data = {
|
|
4161
|
-
cwd,
|
|
4162
|
-
language
|
|
4163
|
-
};
|
|
4164
|
-
return this.post({ path: "/contexts", data, config: params?.config });
|
|
4165
|
-
}
|
|
4110
|
+
createdAt;
|
|
4166
4111
|
/**
|
|
4167
|
-
*
|
|
4112
|
+
* 最后更新时间 / Last Updated Time
|
|
4168
4113
|
*/
|
|
4169
|
-
|
|
4170
|
-
return this.get({ path: `/contexts/${params.contextId}`, config: params.config });
|
|
4171
|
-
}
|
|
4114
|
+
lastUpdatedAt;
|
|
4172
4115
|
/**
|
|
4173
|
-
*
|
|
4116
|
+
* 沙箱空闲超时时间(秒) / Sandbox Idle Timeout (seconds)
|
|
4174
4117
|
*/
|
|
4175
|
-
|
|
4176
|
-
const { code, contextId, language, timeout = 30, config: config2 } = params;
|
|
4177
|
-
if (language && language !== "python" && language !== "javascript") {
|
|
4178
|
-
throw new Error(
|
|
4179
|
-
`language must be 'python' or 'javascript', got: ${language}`
|
|
4180
|
-
);
|
|
4181
|
-
}
|
|
4182
|
-
const data = {
|
|
4183
|
-
code
|
|
4184
|
-
};
|
|
4185
|
-
if (timeout !== void 0) {
|
|
4186
|
-
data.timeout = timeout;
|
|
4187
|
-
}
|
|
4188
|
-
if (language !== void 0) {
|
|
4189
|
-
data.language = language;
|
|
4190
|
-
}
|
|
4191
|
-
if (contextId !== void 0) {
|
|
4192
|
-
data.contextId = contextId;
|
|
4193
|
-
}
|
|
4194
|
-
return this.post({ path: "/contexts/execute", data, config: config2 });
|
|
4195
|
-
}
|
|
4118
|
+
sandboxIdleTimeoutSeconds;
|
|
4196
4119
|
/**
|
|
4197
|
-
*
|
|
4120
|
+
* 沙箱结束时间 / Sandbox End Time
|
|
4198
4121
|
*/
|
|
4199
|
-
|
|
4200
|
-
return this.delete({ path: `/contexts/${params.contextId}`, config: params.config });
|
|
4201
|
-
}
|
|
4122
|
+
endedAt;
|
|
4202
4123
|
/**
|
|
4203
|
-
*
|
|
4124
|
+
* 元数据 / Metadata
|
|
4204
4125
|
*/
|
|
4205
|
-
|
|
4206
|
-
const query = {
|
|
4207
|
-
path: params.path
|
|
4208
|
-
};
|
|
4209
|
-
return this.get({ path: "/files", query, config: params.config });
|
|
4210
|
-
}
|
|
4126
|
+
metadata;
|
|
4211
4127
|
/**
|
|
4212
|
-
*
|
|
4128
|
+
* 沙箱全局唯一资源名称 / Sandbox ARN
|
|
4213
4129
|
*/
|
|
4214
|
-
|
|
4215
|
-
const data = {
|
|
4216
|
-
path: params.path,
|
|
4217
|
-
content: params.content,
|
|
4218
|
-
mode: params.mode || "644",
|
|
4219
|
-
encoding: params.encoding || "utf-8",
|
|
4220
|
-
createDir: params.createDir !== void 0 ? params.createDir : true
|
|
4221
|
-
};
|
|
4222
|
-
return this.post({ path: "/files", data, config: params.config });
|
|
4223
|
-
}
|
|
4130
|
+
sandboxArn;
|
|
4224
4131
|
/**
|
|
4225
|
-
*
|
|
4132
|
+
* 沙箱空闲 TTL(秒) / Sandbox Idle TTL (seconds)
|
|
4226
4133
|
*/
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
|
|
4232
|
-
|
|
4233
|
-
}
|
|
4134
|
+
sandboxIdleTTLInSeconds;
|
|
4135
|
+
_config;
|
|
4136
|
+
constructor(data, config2) {
|
|
4137
|
+
super();
|
|
4138
|
+
if (data) {
|
|
4139
|
+
updateObjectProperties(this, data);
|
|
4140
|
+
}
|
|
4141
|
+
this._config = config2;
|
|
4234
4142
|
}
|
|
4235
4143
|
/**
|
|
4236
|
-
*
|
|
4144
|
+
* Create sandbox from SDK response object
|
|
4145
|
+
* 从 SDK 响应对象创建沙箱 / Create Sandbox from SDK Response Object
|
|
4237
4146
|
*/
|
|
4238
|
-
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4147
|
+
static fromInnerObject(obj, config2) {
|
|
4148
|
+
return new _Sandbox(
|
|
4149
|
+
{
|
|
4150
|
+
sandboxId: obj.sandboxId,
|
|
4151
|
+
sandboxName: obj.sandboxName,
|
|
4152
|
+
templateId: obj.templateId,
|
|
4153
|
+
templateName: obj.templateName,
|
|
4154
|
+
// API returns "status" field, map it to "state"
|
|
4155
|
+
state: obj.status || obj.state,
|
|
4156
|
+
stateReason: obj.stateReason,
|
|
4157
|
+
createdAt: obj.createdAt,
|
|
4158
|
+
lastUpdatedAt: obj.lastUpdatedAt,
|
|
4159
|
+
sandboxIdleTimeoutSeconds: obj.sandboxIdleTimeoutSeconds,
|
|
4160
|
+
// New fields / 新增字段
|
|
4161
|
+
endedAt: obj.endedAt,
|
|
4162
|
+
metadata: obj.metadata,
|
|
4163
|
+
sandboxArn: obj.sandboxArn,
|
|
4164
|
+
sandboxIdleTTLInSeconds: obj.sandboxIdleTTLInSeconds
|
|
4165
|
+
},
|
|
4166
|
+
config2
|
|
4167
|
+
);
|
|
4168
|
+
}
|
|
4169
|
+
static getClient() {
|
|
4170
|
+
const { SandboxClient: SandboxClient2 } = (init_client3(), __toCommonJS(client_exports3));
|
|
4171
|
+
return new SandboxClient2();
|
|
4246
4172
|
}
|
|
4247
4173
|
/**
|
|
4248
|
-
*
|
|
4174
|
+
* Create a new Sandbox
|
|
4175
|
+
* 创建新沙箱 / Create a New Sandbox
|
|
4249
4176
|
*/
|
|
4250
|
-
async
|
|
4251
|
-
|
|
4252
|
-
command: params.command,
|
|
4253
|
-
cwd: params.cwd
|
|
4254
|
-
};
|
|
4255
|
-
if (params.timeout !== void 0) {
|
|
4256
|
-
data.timeout = params.timeout;
|
|
4257
|
-
}
|
|
4258
|
-
return this.post({ path: "/processes/cmd", data, config: params.config });
|
|
4177
|
+
static async create(input, config2) {
|
|
4178
|
+
return await _Sandbox.getClient().createSandbox({ input, config: config2 });
|
|
4259
4179
|
}
|
|
4260
4180
|
/**
|
|
4261
|
-
*
|
|
4181
|
+
* Delete a Sandbox by ID
|
|
4262
4182
|
*/
|
|
4263
|
-
async
|
|
4264
|
-
|
|
4183
|
+
static async delete(params) {
|
|
4184
|
+
const { id, config: config2 } = params;
|
|
4185
|
+
return await _Sandbox.getClient().deleteSandbox({ id, config: config2 });
|
|
4265
4186
|
}
|
|
4266
4187
|
/**
|
|
4267
|
-
*
|
|
4188
|
+
* Stop a Sandbox by ID
|
|
4268
4189
|
*/
|
|
4269
|
-
async
|
|
4270
|
-
|
|
4190
|
+
static async stop(params) {
|
|
4191
|
+
const { id, config: config2 } = params;
|
|
4192
|
+
return await _Sandbox.getClient().stopSandbox({ id, config: config2 });
|
|
4271
4193
|
}
|
|
4272
4194
|
/**
|
|
4273
|
-
*
|
|
4195
|
+
* Get a Sandbox by ID
|
|
4274
4196
|
*/
|
|
4275
|
-
async
|
|
4276
|
-
|
|
4197
|
+
static async get(params) {
|
|
4198
|
+
const { id, templateType, config: config2 } = params;
|
|
4199
|
+
return await _Sandbox.getClient().getSandbox({ id, templateType, config: config2 });
|
|
4277
4200
|
}
|
|
4278
4201
|
/**
|
|
4279
|
-
*
|
|
4202
|
+
* List Sandboxes
|
|
4280
4203
|
*/
|
|
4281
|
-
async
|
|
4282
|
-
|
|
4283
|
-
const url = this.withPath(params.path, params.query);
|
|
4284
|
-
const reqHeaders = this.prepareHeaders({ headers: params.headers, config: params.config });
|
|
4285
|
-
delete reqHeaders["Content-Type"];
|
|
4286
|
-
try {
|
|
4287
|
-
const fileContent = await fs.promises.readFile(params.localFilePath);
|
|
4288
|
-
const formData = new FormData();
|
|
4289
|
-
formData.append(
|
|
4290
|
-
"file",
|
|
4291
|
-
new Blob([fileContent]),
|
|
4292
|
-
filename
|
|
4293
|
-
);
|
|
4294
|
-
const data = params.formData || {};
|
|
4295
|
-
data.path = params.targetFilePath;
|
|
4296
|
-
Object.entries(data).forEach(([key, value]) => {
|
|
4297
|
-
formData.append(key, String(value));
|
|
4298
|
-
});
|
|
4299
|
-
const cfg = Config.withConfigs(this.config, params.config);
|
|
4300
|
-
const response = await fetch(url, {
|
|
4301
|
-
method: "POST",
|
|
4302
|
-
headers: reqHeaders,
|
|
4303
|
-
body: formData,
|
|
4304
|
-
signal: AbortSignal.timeout(cfg.timeout)
|
|
4305
|
-
});
|
|
4306
|
-
if (!response.ok) {
|
|
4307
|
-
const errorText = await response.text();
|
|
4308
|
-
throw new ClientError(response.status, errorText);
|
|
4309
|
-
}
|
|
4310
|
-
return response.json();
|
|
4311
|
-
} catch (error) {
|
|
4312
|
-
if (error instanceof ClientError) {
|
|
4313
|
-
throw error;
|
|
4314
|
-
}
|
|
4315
|
-
logger.error(`Upload file error: ${error}`);
|
|
4316
|
-
throw new ClientError(0, `Upload file error: ${error}`);
|
|
4317
|
-
}
|
|
4318
|
-
}
|
|
4319
|
-
/**
|
|
4320
|
-
* Helper method to download file
|
|
4321
|
-
*/
|
|
4322
|
-
async getFile(params) {
|
|
4323
|
-
const url = this.withPath(params.path, params.query);
|
|
4324
|
-
const reqHeaders = this.prepareHeaders({ headers: params.headers, config: params.config });
|
|
4325
|
-
try {
|
|
4326
|
-
const cfg = Config.withConfigs(this.config, params.config);
|
|
4327
|
-
const response = await fetch(url, {
|
|
4328
|
-
method: "GET",
|
|
4329
|
-
headers: reqHeaders,
|
|
4330
|
-
signal: AbortSignal.timeout(cfg.timeout)
|
|
4331
|
-
});
|
|
4332
|
-
if (!response.ok) {
|
|
4333
|
-
const errorText = await response.text();
|
|
4334
|
-
throw new ClientError(response.status, errorText);
|
|
4335
|
-
}
|
|
4336
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
4337
|
-
const buffer = Buffer.from(arrayBuffer);
|
|
4338
|
-
await fs.promises.writeFile(params.savePath, buffer);
|
|
4339
|
-
return {
|
|
4340
|
-
savedPath: params.savePath,
|
|
4341
|
-
size: buffer.length
|
|
4342
|
-
};
|
|
4343
|
-
} catch (error) {
|
|
4344
|
-
if (error instanceof ClientError) {
|
|
4345
|
-
throw error;
|
|
4346
|
-
}
|
|
4347
|
-
logger.error(`Download file error: ${error}`);
|
|
4348
|
-
throw new ClientError(0, `Download file error: ${error}`);
|
|
4349
|
-
}
|
|
4350
|
-
}
|
|
4351
|
-
};
|
|
4352
|
-
}
|
|
4353
|
-
});
|
|
4354
|
-
|
|
4355
|
-
// src/sandbox/code-interpreter-sandbox.ts
|
|
4356
|
-
var code_interpreter_sandbox_exports = {};
|
|
4357
|
-
__export(code_interpreter_sandbox_exports, {
|
|
4358
|
-
CodeInterpreterSandbox: () => CodeInterpreterSandbox,
|
|
4359
|
-
ContextOperations: () => ContextOperations,
|
|
4360
|
-
FileOperations: () => FileOperations,
|
|
4361
|
-
FileSystemOperations: () => FileSystemOperations,
|
|
4362
|
-
ProcessOperations: () => ProcessOperations
|
|
4363
|
-
});
|
|
4364
|
-
var FileOperations, FileSystemOperations, ProcessOperations, ContextOperations, CodeInterpreterSandbox;
|
|
4365
|
-
var init_code_interpreter_sandbox = __esm({
|
|
4366
|
-
"src/sandbox/code-interpreter-sandbox.ts"() {
|
|
4367
|
-
init_log();
|
|
4368
|
-
init_exception();
|
|
4369
|
-
init_code_interpreter_data();
|
|
4370
|
-
init_model4();
|
|
4371
|
-
init_sandbox();
|
|
4372
|
-
FileOperations = class {
|
|
4373
|
-
sandbox;
|
|
4374
|
-
constructor(sandbox) {
|
|
4375
|
-
this.sandbox = sandbox;
|
|
4204
|
+
static async list(input, config2) {
|
|
4205
|
+
return await _Sandbox.getClient().listSandboxes({ input, config: config2 });
|
|
4376
4206
|
}
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
|
|
4381
|
-
|
|
4207
|
+
get = async (params) => {
|
|
4208
|
+
const { config: config2 } = params ?? {};
|
|
4209
|
+
return await _Sandbox.get({
|
|
4210
|
+
id: this.sandboxId,
|
|
4211
|
+
templateType: this.templateType,
|
|
4212
|
+
config: Config.withConfigs(this._config, config2)
|
|
4213
|
+
});
|
|
4382
4214
|
};
|
|
4383
4215
|
/**
|
|
4384
|
-
*
|
|
4216
|
+
* Delete this sandbox
|
|
4385
4217
|
*/
|
|
4386
|
-
|
|
4387
|
-
|
|
4218
|
+
delete = async (params) => {
|
|
4219
|
+
const config2 = params?.config;
|
|
4220
|
+
if (!this.sandboxId) {
|
|
4221
|
+
throw new Error("sandboxId is required to delete a Sandbox");
|
|
4222
|
+
}
|
|
4223
|
+
const result = await _Sandbox.delete({
|
|
4224
|
+
id: this.sandboxId,
|
|
4225
|
+
config: config2 ?? this._config
|
|
4226
|
+
});
|
|
4227
|
+
updateObjectProperties(this, result);
|
|
4228
|
+
return this;
|
|
4388
4229
|
};
|
|
4389
|
-
};
|
|
4390
|
-
FileSystemOperations = class {
|
|
4391
|
-
sandbox;
|
|
4392
|
-
constructor(sandbox) {
|
|
4393
|
-
this.sandbox = sandbox;
|
|
4394
|
-
}
|
|
4395
4230
|
/**
|
|
4396
|
-
*
|
|
4231
|
+
* Stop this sandbox
|
|
4397
4232
|
*/
|
|
4398
|
-
|
|
4399
|
-
|
|
4233
|
+
stop = async (params) => {
|
|
4234
|
+
const config2 = params?.config;
|
|
4235
|
+
if (!this.sandboxId) {
|
|
4236
|
+
throw new Error("sandboxId is required to stop a Sandbox");
|
|
4237
|
+
}
|
|
4238
|
+
const result = await _Sandbox.stop({
|
|
4239
|
+
id: this.sandboxId,
|
|
4240
|
+
config: config2 ?? this._config
|
|
4241
|
+
});
|
|
4242
|
+
updateObjectProperties(this, result);
|
|
4243
|
+
return this;
|
|
4400
4244
|
};
|
|
4401
4245
|
/**
|
|
4402
|
-
*
|
|
4246
|
+
* Refresh this sandbox's data
|
|
4403
4247
|
*/
|
|
4404
|
-
|
|
4405
|
-
|
|
4248
|
+
refresh = async (params) => {
|
|
4249
|
+
const config2 = params?.config;
|
|
4250
|
+
if (!this.sandboxId) {
|
|
4251
|
+
throw new Error("sandboxId is required to refresh a Sandbox");
|
|
4252
|
+
}
|
|
4253
|
+
const result = await _Sandbox.get({
|
|
4254
|
+
id: this.sandboxId,
|
|
4255
|
+
config: config2 ?? this._config
|
|
4256
|
+
});
|
|
4257
|
+
updateObjectProperties(this, result);
|
|
4258
|
+
return this;
|
|
4406
4259
|
};
|
|
4407
4260
|
/**
|
|
4408
|
-
*
|
|
4261
|
+
* Wait until the sandbox is running
|
|
4409
4262
|
*/
|
|
4410
|
-
|
|
4411
|
-
|
|
4263
|
+
waitUntilRunning = async (options, config2) => {
|
|
4264
|
+
const timeout = (options?.timeoutSeconds ?? 300) * 1e3;
|
|
4265
|
+
const interval = (options?.intervalSeconds ?? 5) * 1e3;
|
|
4266
|
+
const startTime = Date.now();
|
|
4267
|
+
while (Date.now() - startTime < timeout) {
|
|
4268
|
+
await this.refresh({ config: config2 });
|
|
4269
|
+
if (options?.beforeCheck) {
|
|
4270
|
+
options.beforeCheck(this);
|
|
4271
|
+
}
|
|
4272
|
+
if (this.state === "Running" /* RUNNING */ || this.state === "READY" /* READY */) {
|
|
4273
|
+
return this;
|
|
4274
|
+
}
|
|
4275
|
+
if (this.state === "Failed" /* FAILED */) {
|
|
4276
|
+
throw new Error(`Sandbox failed: ${this.stateReason}`);
|
|
4277
|
+
}
|
|
4278
|
+
await new Promise((resolve) => setTimeout(resolve, interval));
|
|
4279
|
+
}
|
|
4280
|
+
throw new Error(
|
|
4281
|
+
`Timeout waiting for Sandbox to be running after ${options?.timeoutSeconds ?? 300} seconds`
|
|
4282
|
+
);
|
|
4412
4283
|
};
|
|
4284
|
+
};
|
|
4285
|
+
}
|
|
4286
|
+
});
|
|
4287
|
+
|
|
4288
|
+
// src/sandbox/browser-sandbox.ts
|
|
4289
|
+
var BrowserSandbox;
|
|
4290
|
+
var init_browser_sandbox = __esm({
|
|
4291
|
+
"src/sandbox/browser-sandbox.ts"() {
|
|
4292
|
+
init_browser_data();
|
|
4293
|
+
init_model4();
|
|
4294
|
+
init_sandbox();
|
|
4295
|
+
BrowserSandbox = class _BrowserSandbox extends Sandbox {
|
|
4296
|
+
static templateType = "Browser" /* BROWSER */;
|
|
4413
4297
|
/**
|
|
4414
|
-
*
|
|
4298
|
+
* Create a Browser Sandbox from template
|
|
4299
|
+
* 从模板创建浏览器沙箱 / Create Browser Sandbox from Template
|
|
4415
4300
|
*/
|
|
4416
|
-
|
|
4417
|
-
|
|
4418
|
-
|
|
4301
|
+
static async createFromTemplate(templateName, options, config2) {
|
|
4302
|
+
const sandbox = await Sandbox.create(
|
|
4303
|
+
{
|
|
4304
|
+
templateName,
|
|
4305
|
+
sandboxIdleTimeoutSeconds: options?.sandboxIdleTimeoutSeconds,
|
|
4306
|
+
nasConfig: options?.nasConfig,
|
|
4307
|
+
ossMountConfig: options?.ossMountConfig,
|
|
4308
|
+
polarFsConfig: options?.polarFsConfig
|
|
4309
|
+
},
|
|
4310
|
+
config2
|
|
4311
|
+
);
|
|
4312
|
+
const browserSandbox = new _BrowserSandbox(sandbox, config2);
|
|
4313
|
+
return browserSandbox;
|
|
4314
|
+
}
|
|
4315
|
+
constructor(sandbox, config2) {
|
|
4316
|
+
super(sandbox, config2);
|
|
4317
|
+
}
|
|
4318
|
+
_dataApi;
|
|
4419
4319
|
/**
|
|
4420
|
-
*
|
|
4320
|
+
* Get data API client
|
|
4421
4321
|
*/
|
|
4422
|
-
|
|
4423
|
-
|
|
4424
|
-
|
|
4322
|
+
get dataApi() {
|
|
4323
|
+
if (!this._dataApi) {
|
|
4324
|
+
if (!this.sandboxId) {
|
|
4325
|
+
throw new Error("Sandbox ID is not set");
|
|
4326
|
+
}
|
|
4327
|
+
this._dataApi = new BrowserDataAPI({
|
|
4328
|
+
sandboxId: this.sandboxId,
|
|
4329
|
+
config: this._config
|
|
4330
|
+
});
|
|
4331
|
+
}
|
|
4332
|
+
return this._dataApi;
|
|
4333
|
+
}
|
|
4425
4334
|
/**
|
|
4426
|
-
*
|
|
4335
|
+
* Check sandbox health
|
|
4427
4336
|
*/
|
|
4428
|
-
|
|
4429
|
-
return this.
|
|
4337
|
+
checkHealth = async (params) => {
|
|
4338
|
+
return this.dataApi.checkHealth({
|
|
4339
|
+
sandboxId: this.sandboxId,
|
|
4340
|
+
config: params?.config
|
|
4341
|
+
});
|
|
4430
4342
|
};
|
|
4431
4343
|
/**
|
|
4432
|
-
*
|
|
4344
|
+
* Get CDP WebSocket URL for browser automation
|
|
4433
4345
|
*/
|
|
4434
|
-
|
|
4435
|
-
return this.
|
|
4436
|
-
};
|
|
4437
|
-
};
|
|
4438
|
-
ProcessOperations = class {
|
|
4439
|
-
sandbox;
|
|
4440
|
-
constructor(sandbox) {
|
|
4441
|
-
this.sandbox = sandbox;
|
|
4346
|
+
getCdpUrl(record) {
|
|
4347
|
+
return this.dataApi.getCdpUrl(record);
|
|
4442
4348
|
}
|
|
4443
4349
|
/**
|
|
4444
|
-
*
|
|
4350
|
+
* Get VNC WebSocket URL for live view
|
|
4445
4351
|
*/
|
|
4446
|
-
|
|
4447
|
-
return this.
|
|
4448
|
-
}
|
|
4352
|
+
getVncUrl(record) {
|
|
4353
|
+
return this.dataApi.getVncUrl(record);
|
|
4354
|
+
}
|
|
4449
4355
|
/**
|
|
4450
|
-
* List all
|
|
4356
|
+
* List all recordings
|
|
4451
4357
|
*/
|
|
4452
|
-
|
|
4453
|
-
return this.
|
|
4358
|
+
listRecordings = async (params) => {
|
|
4359
|
+
return this.dataApi.listRecordings(params);
|
|
4454
4360
|
};
|
|
4455
4361
|
/**
|
|
4456
|
-
*
|
|
4362
|
+
* Download a recording video file
|
|
4457
4363
|
*/
|
|
4458
|
-
|
|
4459
|
-
return this.
|
|
4364
|
+
downloadRecording = async (params) => {
|
|
4365
|
+
return this.dataApi.downloadRecording(params);
|
|
4460
4366
|
};
|
|
4461
4367
|
/**
|
|
4462
|
-
*
|
|
4368
|
+
* Delete a recording
|
|
4463
4369
|
*/
|
|
4464
|
-
|
|
4465
|
-
return this.
|
|
4370
|
+
deleteRecording = async (params) => {
|
|
4371
|
+
return this.dataApi.deleteRecording(params);
|
|
4466
4372
|
};
|
|
4467
4373
|
};
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
list = async (params) => {
|
|
4486
|
-
return this.sandbox.dataApi.listContexts(params);
|
|
4487
|
-
};
|
|
4488
|
-
/**
|
|
4489
|
-
* Create a new context and save its ID
|
|
4490
|
-
*/
|
|
4491
|
-
create = async (params) => {
|
|
4492
|
-
const language = params?.language || "python" /* PYTHON */;
|
|
4493
|
-
const cwd = params?.cwd || "/home/user";
|
|
4494
|
-
const result = await this.sandbox.dataApi.createContext({
|
|
4495
|
-
language,
|
|
4496
|
-
cwd
|
|
4374
|
+
}
|
|
4375
|
+
});
|
|
4376
|
+
var CodeInterpreterDataAPI;
|
|
4377
|
+
var init_code_interpreter_data = __esm({
|
|
4378
|
+
"src/sandbox/api/code-interpreter-data.ts"() {
|
|
4379
|
+
init_config();
|
|
4380
|
+
init_exception();
|
|
4381
|
+
init_log();
|
|
4382
|
+
init_model4();
|
|
4383
|
+
init_sandbox_data();
|
|
4384
|
+
CodeInterpreterDataAPI = class extends SandboxDataAPI {
|
|
4385
|
+
constructor(params) {
|
|
4386
|
+
super({
|
|
4387
|
+
sandboxId: params.sandboxId,
|
|
4388
|
+
config: params.config,
|
|
4389
|
+
// Set namespace to include sandboxId for correct API path generation
|
|
4390
|
+
namespace: `sandboxes/${params.sandboxId}`
|
|
4497
4391
|
});
|
|
4498
|
-
|
|
4499
|
-
this._contextId = result.id;
|
|
4500
|
-
this._language = result.language;
|
|
4501
|
-
this._cwd = result.cwd;
|
|
4502
|
-
return this;
|
|
4503
|
-
}
|
|
4504
|
-
throw new ServerError(500, "Failed to create context");
|
|
4505
|
-
};
|
|
4392
|
+
}
|
|
4506
4393
|
/**
|
|
4507
|
-
*
|
|
4394
|
+
* List directory contents
|
|
4508
4395
|
*/
|
|
4509
|
-
|
|
4510
|
-
const
|
|
4511
|
-
if (
|
|
4512
|
-
|
|
4513
|
-
throw new Error("context id is not set");
|
|
4396
|
+
async listDirectory(params) {
|
|
4397
|
+
const query = {};
|
|
4398
|
+
if (params?.path !== void 0) {
|
|
4399
|
+
query.path = params.path;
|
|
4514
4400
|
}
|
|
4515
|
-
|
|
4516
|
-
|
|
4517
|
-
this._contextId = result.id;
|
|
4518
|
-
this._language = result.language;
|
|
4519
|
-
this._cwd = result.cwd;
|
|
4520
|
-
return this;
|
|
4401
|
+
if (params?.depth !== void 0) {
|
|
4402
|
+
query.depth = params.depth;
|
|
4521
4403
|
}
|
|
4522
|
-
|
|
4523
|
-
}
|
|
4404
|
+
return this.get({ path: "/filesystem", query, config: params?.config });
|
|
4405
|
+
}
|
|
4524
4406
|
/**
|
|
4525
|
-
*
|
|
4407
|
+
* Get file/directory stats
|
|
4526
4408
|
*/
|
|
4527
|
-
|
|
4528
|
-
const
|
|
4529
|
-
|
|
4530
|
-
|
|
4531
|
-
|
|
4532
|
-
|
|
4533
|
-
if (!contextId && !language) {
|
|
4534
|
-
logger.debug("context id is not set, use default language: python");
|
|
4535
|
-
language = "python" /* PYTHON */;
|
|
4536
|
-
}
|
|
4537
|
-
return this.sandbox.dataApi.executeCode({
|
|
4538
|
-
code,
|
|
4539
|
-
contextId,
|
|
4540
|
-
language,
|
|
4541
|
-
timeout
|
|
4542
|
-
});
|
|
4543
|
-
};
|
|
4409
|
+
async stat(params) {
|
|
4410
|
+
const query = {
|
|
4411
|
+
path: params.path
|
|
4412
|
+
};
|
|
4413
|
+
return this.get({ path: "/filesystem/stat", query, config: params.config });
|
|
4414
|
+
}
|
|
4544
4415
|
/**
|
|
4545
|
-
*
|
|
4416
|
+
* Create directory
|
|
4546
4417
|
*/
|
|
4547
|
-
|
|
4548
|
-
const
|
|
4549
|
-
|
|
4550
|
-
|
|
4551
|
-
|
|
4552
|
-
|
|
4553
|
-
}
|
|
4554
|
-
|
|
4555
|
-
this._contextId = void 0;
|
|
4556
|
-
return result;
|
|
4557
|
-
};
|
|
4558
|
-
};
|
|
4559
|
-
CodeInterpreterSandbox = class _CodeInterpreterSandbox extends Sandbox {
|
|
4560
|
-
static templateType = "CodeInterpreter" /* CODE_INTERPRETER */;
|
|
4418
|
+
async mkdir(params) {
|
|
4419
|
+
const data = {
|
|
4420
|
+
path: params.path,
|
|
4421
|
+
parents: params.parents !== void 0 ? params.parents : true,
|
|
4422
|
+
mode: params.mode || "0755"
|
|
4423
|
+
};
|
|
4424
|
+
return this.post({ path: "/filesystem/mkdir", data, config: params.config });
|
|
4425
|
+
}
|
|
4561
4426
|
/**
|
|
4562
|
-
*
|
|
4563
|
-
* 从模板创建代码解释器沙箱 / Create Code Interpreter Sandbox from Template
|
|
4427
|
+
* Move file or directory
|
|
4564
4428
|
*/
|
|
4565
|
-
|
|
4566
|
-
const
|
|
4567
|
-
|
|
4568
|
-
|
|
4569
|
-
|
|
4570
|
-
|
|
4571
|
-
ossMountConfig: options?.ossMountConfig,
|
|
4572
|
-
polarFsConfig: options?.polarFsConfig
|
|
4573
|
-
},
|
|
4574
|
-
config2
|
|
4575
|
-
);
|
|
4576
|
-
const ciSandbox = new _CodeInterpreterSandbox(sandbox, config2);
|
|
4577
|
-
return ciSandbox;
|
|
4429
|
+
async moveFile(params) {
|
|
4430
|
+
const data = {
|
|
4431
|
+
source: params.source,
|
|
4432
|
+
destination: params.destination
|
|
4433
|
+
};
|
|
4434
|
+
return this.post({ path: "/filesystem/move", data, config: params.config });
|
|
4578
4435
|
}
|
|
4579
|
-
|
|
4580
|
-
|
|
4436
|
+
/**
|
|
4437
|
+
* Remove file or directory
|
|
4438
|
+
*/
|
|
4439
|
+
async removeFile(params) {
|
|
4440
|
+
const data = {
|
|
4441
|
+
path: params.path
|
|
4442
|
+
};
|
|
4443
|
+
return this.post({ path: "/filesystem/remove", data, config: params.config });
|
|
4581
4444
|
}
|
|
4582
|
-
_dataApi;
|
|
4583
|
-
_file;
|
|
4584
|
-
_fileSystem;
|
|
4585
|
-
_context;
|
|
4586
|
-
_process;
|
|
4587
4445
|
/**
|
|
4588
|
-
*
|
|
4446
|
+
* List code execution contexts
|
|
4589
4447
|
*/
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
this._dataApi = new CodeInterpreterDataAPI({
|
|
4593
|
-
sandboxId: this.sandboxId || "",
|
|
4594
|
-
config: this._config
|
|
4595
|
-
});
|
|
4596
|
-
}
|
|
4597
|
-
return this._dataApi;
|
|
4448
|
+
async listContexts(params) {
|
|
4449
|
+
return this.get({ path: "/contexts", config: params?.config });
|
|
4598
4450
|
}
|
|
4599
4451
|
/**
|
|
4600
|
-
*
|
|
4452
|
+
* Create a new code execution context
|
|
4601
4453
|
*/
|
|
4602
|
-
|
|
4603
|
-
|
|
4604
|
-
|
|
4454
|
+
async createContext(params) {
|
|
4455
|
+
const language = params?.language || "python" /* PYTHON */;
|
|
4456
|
+
const cwd = params?.cwd || "/home/user";
|
|
4457
|
+
if (language !== "python" && language !== "javascript") {
|
|
4458
|
+
throw new Error(
|
|
4459
|
+
`language must be 'python' or 'javascript', got: ${language}`
|
|
4460
|
+
);
|
|
4605
4461
|
}
|
|
4606
|
-
|
|
4462
|
+
const data = {
|
|
4463
|
+
cwd,
|
|
4464
|
+
language
|
|
4465
|
+
};
|
|
4466
|
+
return this.post({ path: "/contexts", data, config: params?.config });
|
|
4607
4467
|
}
|
|
4608
4468
|
/**
|
|
4609
|
-
*
|
|
4469
|
+
* Get context details
|
|
4610
4470
|
*/
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
this._fileSystem = new FileSystemOperations(this);
|
|
4614
|
-
}
|
|
4615
|
-
return this._fileSystem;
|
|
4471
|
+
async getContext(params) {
|
|
4472
|
+
return this.get({ path: `/contexts/${params.contextId}`, config: params.config });
|
|
4616
4473
|
}
|
|
4617
4474
|
/**
|
|
4618
|
-
*
|
|
4475
|
+
* Execute code in a context
|
|
4619
4476
|
*/
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
|
|
4477
|
+
async executeCode(params) {
|
|
4478
|
+
const { code, contextId, language, timeout = 30, config: config2 } = params;
|
|
4479
|
+
if (language && language !== "python" && language !== "javascript") {
|
|
4480
|
+
throw new Error(
|
|
4481
|
+
`language must be 'python' or 'javascript', got: ${language}`
|
|
4482
|
+
);
|
|
4623
4483
|
}
|
|
4624
|
-
|
|
4484
|
+
const data = {
|
|
4485
|
+
code
|
|
4486
|
+
};
|
|
4487
|
+
if (timeout !== void 0) {
|
|
4488
|
+
data.timeout = timeout;
|
|
4489
|
+
}
|
|
4490
|
+
if (language !== void 0) {
|
|
4491
|
+
data.language = language;
|
|
4492
|
+
}
|
|
4493
|
+
if (contextId !== void 0) {
|
|
4494
|
+
data.contextId = contextId;
|
|
4495
|
+
}
|
|
4496
|
+
return this.post({ path: "/contexts/execute", data, config: config2 });
|
|
4625
4497
|
}
|
|
4626
4498
|
/**
|
|
4627
|
-
*
|
|
4499
|
+
* Delete a context
|
|
4628
4500
|
*/
|
|
4629
|
-
|
|
4630
|
-
|
|
4631
|
-
this._process = new ProcessOperations(this);
|
|
4632
|
-
}
|
|
4633
|
-
return this._process;
|
|
4501
|
+
async deleteContext(params) {
|
|
4502
|
+
return this.delete({ path: `/contexts/${params.contextId}`, config: params.config });
|
|
4634
4503
|
}
|
|
4635
4504
|
/**
|
|
4636
|
-
*
|
|
4505
|
+
* Read file contents
|
|
4637
4506
|
*/
|
|
4638
|
-
|
|
4639
|
-
|
|
4640
|
-
|
|
4641
|
-
|
|
4642
|
-
});
|
|
4643
|
-
}
|
|
4507
|
+
async readFile(params) {
|
|
4508
|
+
const query = {
|
|
4509
|
+
path: params.path
|
|
4510
|
+
};
|
|
4511
|
+
return this.get({ path: "/files", query, config: params.config });
|
|
4512
|
+
}
|
|
4644
4513
|
/**
|
|
4645
|
-
*
|
|
4514
|
+
* Write file contents
|
|
4646
4515
|
*/
|
|
4647
|
-
|
|
4648
|
-
|
|
4649
|
-
|
|
4650
|
-
|
|
4651
|
-
|
|
4652
|
-
|
|
4653
|
-
|
|
4654
|
-
|
|
4655
|
-
|
|
4656
|
-
|
|
4657
|
-
|
|
4658
|
-
|
|
4659
|
-
|
|
4660
|
-
|
|
4661
|
-
|
|
4662
|
-
|
|
4663
|
-
|
|
4664
|
-
|
|
4516
|
+
async writeFile(params) {
|
|
4517
|
+
const data = {
|
|
4518
|
+
path: params.path,
|
|
4519
|
+
content: params.content,
|
|
4520
|
+
mode: params.mode || "644",
|
|
4521
|
+
encoding: params.encoding || "utf-8",
|
|
4522
|
+
createDir: params.createDir !== void 0 ? params.createDir : true
|
|
4523
|
+
};
|
|
4524
|
+
return this.post({ path: "/files", data, config: params.config });
|
|
4525
|
+
}
|
|
4526
|
+
/**
|
|
4527
|
+
* Upload file to sandbox
|
|
4528
|
+
*/
|
|
4529
|
+
async uploadFile(params) {
|
|
4530
|
+
return this.postFile({
|
|
4531
|
+
path: "/filesystem/upload",
|
|
4532
|
+
localFilePath: params.localFilePath,
|
|
4533
|
+
targetFilePath: params.targetFilePath,
|
|
4665
4534
|
config: params.config
|
|
4666
4535
|
});
|
|
4667
|
-
|
|
4668
|
-
|
|
4536
|
+
}
|
|
4537
|
+
/**
|
|
4538
|
+
* Download file from sandbox
|
|
4539
|
+
*/
|
|
4540
|
+
async downloadFile(params) {
|
|
4541
|
+
const query = { path: params.path };
|
|
4542
|
+
return this.getFile({
|
|
4543
|
+
path: "/filesystem/download",
|
|
4544
|
+
savePath: params.savePath,
|
|
4545
|
+
query,
|
|
4669
4546
|
config: params.config
|
|
4670
4547
|
});
|
|
4671
4548
|
}
|
|
4672
|
-
// Browser API methods - delegate to browserAPI
|
|
4673
4549
|
/**
|
|
4674
|
-
*
|
|
4550
|
+
* Execute shell command
|
|
4675
4551
|
*/
|
|
4676
|
-
|
|
4677
|
-
|
|
4552
|
+
async cmd(params) {
|
|
4553
|
+
const data = {
|
|
4554
|
+
command: params.command,
|
|
4555
|
+
cwd: params.cwd
|
|
4556
|
+
};
|
|
4557
|
+
if (params.timeout !== void 0) {
|
|
4558
|
+
data.timeout = params.timeout;
|
|
4559
|
+
}
|
|
4560
|
+
return this.post({ path: "/processes/cmd", data, config: params.config });
|
|
4678
4561
|
}
|
|
4679
4562
|
/**
|
|
4680
|
-
*
|
|
4563
|
+
* List running processes
|
|
4681
4564
|
*/
|
|
4682
|
-
|
|
4683
|
-
return this.
|
|
4565
|
+
async listProcesses(params) {
|
|
4566
|
+
return this.get({ path: "/processes", config: params?.config });
|
|
4684
4567
|
}
|
|
4685
4568
|
/**
|
|
4686
|
-
*
|
|
4569
|
+
* Get process details
|
|
4687
4570
|
*/
|
|
4688
|
-
|
|
4689
|
-
return this.
|
|
4690
|
-
}
|
|
4571
|
+
async getProcess(params) {
|
|
4572
|
+
return this.get({ path: `/processes/${params.pid}`, config: params.config });
|
|
4573
|
+
}
|
|
4691
4574
|
/**
|
|
4692
|
-
*
|
|
4575
|
+
* Kill a process
|
|
4693
4576
|
*/
|
|
4694
|
-
|
|
4695
|
-
return this.
|
|
4696
|
-
}
|
|
4577
|
+
async killProcess(params) {
|
|
4578
|
+
return this.delete({ path: `/processes/${params.pid}`, config: params.config });
|
|
4579
|
+
}
|
|
4697
4580
|
/**
|
|
4698
|
-
*
|
|
4581
|
+
* Helper method to upload file using multipart/form-data
|
|
4582
|
+
*/
|
|
4583
|
+
async postFile(params) {
|
|
4584
|
+
const filename = nodePath.basename(params.localFilePath);
|
|
4585
|
+
const url = this.withPath(params.path, params.query);
|
|
4586
|
+
const reqHeaders = this.prepareHeaders({ headers: params.headers, config: params.config });
|
|
4587
|
+
delete reqHeaders["Content-Type"];
|
|
4588
|
+
try {
|
|
4589
|
+
const fileContent = await fs.promises.readFile(params.localFilePath);
|
|
4590
|
+
const formData = new FormData();
|
|
4591
|
+
formData.append(
|
|
4592
|
+
"file",
|
|
4593
|
+
new Blob([fileContent]),
|
|
4594
|
+
filename
|
|
4595
|
+
);
|
|
4596
|
+
const data = params.formData || {};
|
|
4597
|
+
data.path = params.targetFilePath;
|
|
4598
|
+
Object.entries(data).forEach(([key, value]) => {
|
|
4599
|
+
formData.append(key, String(value));
|
|
4600
|
+
});
|
|
4601
|
+
const cfg = Config.withConfigs(this.config, params.config);
|
|
4602
|
+
const response = await fetch(url, {
|
|
4603
|
+
method: "POST",
|
|
4604
|
+
headers: reqHeaders,
|
|
4605
|
+
body: formData,
|
|
4606
|
+
signal: AbortSignal.timeout(cfg.timeout)
|
|
4607
|
+
});
|
|
4608
|
+
if (!response.ok) {
|
|
4609
|
+
const errorText = await response.text();
|
|
4610
|
+
throw new ClientError(response.status, errorText);
|
|
4611
|
+
}
|
|
4612
|
+
return response.json();
|
|
4613
|
+
} catch (error) {
|
|
4614
|
+
if (error instanceof ClientError) {
|
|
4615
|
+
throw error;
|
|
4616
|
+
}
|
|
4617
|
+
logger.error(`Upload file error: ${error}`);
|
|
4618
|
+
throw new ClientError(0, `Upload file error: ${error}`);
|
|
4619
|
+
}
|
|
4620
|
+
}
|
|
4621
|
+
/**
|
|
4622
|
+
* Helper method to download file
|
|
4699
4623
|
*/
|
|
4700
|
-
|
|
4701
|
-
|
|
4702
|
-
|
|
4624
|
+
async getFile(params) {
|
|
4625
|
+
const url = this.withPath(params.path, params.query);
|
|
4626
|
+
const reqHeaders = this.prepareHeaders({ headers: params.headers, config: params.config });
|
|
4627
|
+
try {
|
|
4628
|
+
const cfg = Config.withConfigs(this.config, params.config);
|
|
4629
|
+
const response = await fetch(url, {
|
|
4630
|
+
method: "GET",
|
|
4631
|
+
headers: reqHeaders,
|
|
4632
|
+
signal: AbortSignal.timeout(cfg.timeout)
|
|
4633
|
+
});
|
|
4634
|
+
if (!response.ok) {
|
|
4635
|
+
const errorText = await response.text();
|
|
4636
|
+
throw new ClientError(response.status, errorText);
|
|
4637
|
+
}
|
|
4638
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
4639
|
+
const buffer = Buffer.from(arrayBuffer);
|
|
4640
|
+
await fs.promises.writeFile(params.savePath, buffer);
|
|
4641
|
+
return {
|
|
4642
|
+
savedPath: params.savePath,
|
|
4643
|
+
size: buffer.length
|
|
4644
|
+
};
|
|
4645
|
+
} catch (error) {
|
|
4646
|
+
if (error instanceof ClientError) {
|
|
4647
|
+
throw error;
|
|
4648
|
+
}
|
|
4649
|
+
logger.error(`Download file error: ${error}`);
|
|
4650
|
+
throw new ClientError(0, `Download file error: ${error}`);
|
|
4651
|
+
}
|
|
4652
|
+
}
|
|
4703
4653
|
};
|
|
4704
4654
|
}
|
|
4705
4655
|
});
|
|
4706
4656
|
|
|
4707
|
-
// src/sandbox/
|
|
4708
|
-
var
|
|
4709
|
-
|
|
4710
|
-
|
|
4711
|
-
AioFileOperations: () => AioFileOperations,
|
|
4712
|
-
AioFileSystemOperations: () => AioFileSystemOperations,
|
|
4713
|
-
AioProcessOperations: () => AioProcessOperations,
|
|
4714
|
-
AioSandbox: () => AioSandbox
|
|
4715
|
-
});
|
|
4716
|
-
var AioFileOperations, AioFileSystemOperations, AioProcessOperations, AioContextOperations, AioSandbox;
|
|
4717
|
-
var init_aio_sandbox = __esm({
|
|
4718
|
-
"src/sandbox/aio-sandbox.ts"() {
|
|
4657
|
+
// src/sandbox/code-interpreter-sandbox.ts
|
|
4658
|
+
var FileOperations, FileSystemOperations, ProcessOperations, ContextOperations, CodeInterpreterSandbox;
|
|
4659
|
+
var init_code_interpreter_sandbox = __esm({
|
|
4660
|
+
"src/sandbox/code-interpreter-sandbox.ts"() {
|
|
4719
4661
|
init_log();
|
|
4720
4662
|
init_exception();
|
|
4721
|
-
|
|
4663
|
+
init_code_interpreter_data();
|
|
4722
4664
|
init_model4();
|
|
4723
4665
|
init_sandbox();
|
|
4724
|
-
|
|
4666
|
+
FileOperations = class {
|
|
4725
4667
|
sandbox;
|
|
4726
4668
|
constructor(sandbox) {
|
|
4727
4669
|
this.sandbox = sandbox;
|
|
4728
4670
|
}
|
|
4729
4671
|
/**
|
|
4730
|
-
* Read a file from the
|
|
4672
|
+
* Read a file from the code interpreter
|
|
4731
4673
|
*/
|
|
4732
|
-
read = async (
|
|
4733
|
-
return this.sandbox.dataApi.readFile(
|
|
4674
|
+
read = async (params) => {
|
|
4675
|
+
return this.sandbox.dataApi.readFile(params);
|
|
4734
4676
|
};
|
|
4735
4677
|
/**
|
|
4736
|
-
* Write a file to the
|
|
4678
|
+
* Write a file to the code interpreter
|
|
4737
4679
|
*/
|
|
4738
4680
|
write = async (params) => {
|
|
4739
4681
|
return this.sandbox.dataApi.writeFile(params);
|
|
4740
4682
|
};
|
|
4741
4683
|
};
|
|
4742
|
-
|
|
4684
|
+
FileSystemOperations = class {
|
|
4743
4685
|
sandbox;
|
|
4744
4686
|
constructor(sandbox) {
|
|
4745
4687
|
this.sandbox = sandbox;
|
|
@@ -4775,25 +4717,25 @@ var init_aio_sandbox = __esm({
|
|
|
4775
4717
|
return this.sandbox.dataApi.mkdir(params);
|
|
4776
4718
|
};
|
|
4777
4719
|
/**
|
|
4778
|
-
* Upload a file to the
|
|
4720
|
+
* Upload a file to the code interpreter
|
|
4779
4721
|
*/
|
|
4780
4722
|
upload = async (params) => {
|
|
4781
4723
|
return this.sandbox.dataApi.uploadFile(params);
|
|
4782
4724
|
};
|
|
4783
4725
|
/**
|
|
4784
|
-
* Download a file from the
|
|
4726
|
+
* Download a file from the code interpreter
|
|
4785
4727
|
*/
|
|
4786
4728
|
download = async (params) => {
|
|
4787
4729
|
return this.sandbox.dataApi.downloadFile(params);
|
|
4788
4730
|
};
|
|
4789
4731
|
};
|
|
4790
|
-
|
|
4732
|
+
ProcessOperations = class {
|
|
4791
4733
|
sandbox;
|
|
4792
4734
|
constructor(sandbox) {
|
|
4793
4735
|
this.sandbox = sandbox;
|
|
4794
4736
|
}
|
|
4795
4737
|
/**
|
|
4796
|
-
* Execute a command in the
|
|
4738
|
+
* Execute a command in the code interpreter
|
|
4797
4739
|
*/
|
|
4798
4740
|
cmd = async (params) => {
|
|
4799
4741
|
return this.sandbox.dataApi.cmd(params);
|
|
@@ -4817,7 +4759,7 @@ var init_aio_sandbox = __esm({
|
|
|
4817
4759
|
return this.sandbox.dataApi.killProcess(params);
|
|
4818
4760
|
};
|
|
4819
4761
|
};
|
|
4820
|
-
|
|
4762
|
+
ContextOperations = class {
|
|
4821
4763
|
sandbox;
|
|
4822
4764
|
_contextId;
|
|
4823
4765
|
_language;
|
|
@@ -4908,11 +4850,11 @@ var init_aio_sandbox = __esm({
|
|
|
4908
4850
|
return result;
|
|
4909
4851
|
};
|
|
4910
4852
|
};
|
|
4911
|
-
|
|
4912
|
-
static templateType = "
|
|
4853
|
+
CodeInterpreterSandbox = class _CodeInterpreterSandbox extends Sandbox {
|
|
4854
|
+
static templateType = "CodeInterpreter" /* CODE_INTERPRETER */;
|
|
4913
4855
|
/**
|
|
4914
|
-
* Create
|
|
4915
|
-
*
|
|
4856
|
+
* Create a Code Interpreter Sandbox from template
|
|
4857
|
+
* 从模板创建代码解释器沙箱 / Create Code Interpreter Sandbox from Template
|
|
4916
4858
|
*/
|
|
4917
4859
|
static async createFromTemplate(templateName, options, config2) {
|
|
4918
4860
|
const sandbox = await Sandbox.create(
|
|
@@ -4925,8 +4867,8 @@ var init_aio_sandbox = __esm({
|
|
|
4925
4867
|
},
|
|
4926
4868
|
config2
|
|
4927
4869
|
);
|
|
4928
|
-
const
|
|
4929
|
-
return
|
|
4870
|
+
const ciSandbox = new _CodeInterpreterSandbox(sandbox, config2);
|
|
4871
|
+
return ciSandbox;
|
|
4930
4872
|
}
|
|
4931
4873
|
constructor(sandbox, config2) {
|
|
4932
4874
|
super(sandbox, config2);
|
|
@@ -4941,7 +4883,7 @@ var init_aio_sandbox = __esm({
|
|
|
4941
4883
|
*/
|
|
4942
4884
|
get dataApi() {
|
|
4943
4885
|
if (!this._dataApi) {
|
|
4944
|
-
this._dataApi = new
|
|
4886
|
+
this._dataApi = new CodeInterpreterDataAPI({
|
|
4945
4887
|
sandboxId: this.sandboxId || "",
|
|
4946
4888
|
config: this._config
|
|
4947
4889
|
});
|
|
@@ -4949,438 +4891,504 @@ var init_aio_sandbox = __esm({
|
|
|
4949
4891
|
return this._dataApi;
|
|
4950
4892
|
}
|
|
4951
4893
|
/**
|
|
4952
|
-
* Access file upload/download operations
|
|
4894
|
+
* Access file upload/download operations
|
|
4895
|
+
*/
|
|
4896
|
+
get file() {
|
|
4897
|
+
if (!this._file) {
|
|
4898
|
+
this._file = new FileOperations(this);
|
|
4899
|
+
}
|
|
4900
|
+
return this._file;
|
|
4901
|
+
}
|
|
4902
|
+
/**
|
|
4903
|
+
* Access file system operations
|
|
4904
|
+
*/
|
|
4905
|
+
get fileSystem() {
|
|
4906
|
+
if (!this._fileSystem) {
|
|
4907
|
+
this._fileSystem = new FileSystemOperations(this);
|
|
4908
|
+
}
|
|
4909
|
+
return this._fileSystem;
|
|
4910
|
+
}
|
|
4911
|
+
/**
|
|
4912
|
+
* Access context management operations
|
|
4913
|
+
*/
|
|
4914
|
+
get context() {
|
|
4915
|
+
if (!this._context) {
|
|
4916
|
+
this._context = new ContextOperations(this);
|
|
4917
|
+
}
|
|
4918
|
+
return this._context;
|
|
4919
|
+
}
|
|
4920
|
+
/**
|
|
4921
|
+
* Access process management operations
|
|
4922
|
+
*/
|
|
4923
|
+
get process() {
|
|
4924
|
+
if (!this._process) {
|
|
4925
|
+
this._process = new ProcessOperations(this);
|
|
4926
|
+
}
|
|
4927
|
+
return this._process;
|
|
4928
|
+
}
|
|
4929
|
+
/**
|
|
4930
|
+
* Check sandbox health
|
|
4931
|
+
*/
|
|
4932
|
+
checkHealth = async (params) => {
|
|
4933
|
+
return this.dataApi.checkHealth({
|
|
4934
|
+
sandboxId: this.sandboxId,
|
|
4935
|
+
config: params?.config
|
|
4936
|
+
});
|
|
4937
|
+
};
|
|
4938
|
+
/**
|
|
4939
|
+
* Execute code (convenience method delegating to context.execute)
|
|
4940
|
+
*/
|
|
4941
|
+
execute = async (params) => {
|
|
4942
|
+
return this.context.execute(params);
|
|
4943
|
+
};
|
|
4944
|
+
};
|
|
4945
|
+
}
|
|
4946
|
+
});
|
|
4947
|
+
|
|
4948
|
+
// src/sandbox/template.ts
|
|
4949
|
+
var Template;
|
|
4950
|
+
var init_template = __esm({
|
|
4951
|
+
"src/sandbox/template.ts"() {
|
|
4952
|
+
init_resource();
|
|
4953
|
+
Template = class _Template extends ResourceBase {
|
|
4954
|
+
/**
|
|
4955
|
+
* 模板 ARN / Template ARN
|
|
4956
|
+
*/
|
|
4957
|
+
templateArn;
|
|
4958
|
+
/**
|
|
4959
|
+
* 模板 ID / Template ID
|
|
4960
|
+
*/
|
|
4961
|
+
templateId;
|
|
4962
|
+
/**
|
|
4963
|
+
* 模板名称 / Template Name
|
|
4964
|
+
*/
|
|
4965
|
+
templateName;
|
|
4966
|
+
/**
|
|
4967
|
+
* 模板类型 / Template Type
|
|
4968
|
+
*/
|
|
4969
|
+
templateType;
|
|
4970
|
+
/**
|
|
4971
|
+
* CPU 核数 / CPU Cores
|
|
4972
|
+
*/
|
|
4973
|
+
cpu;
|
|
4974
|
+
/**
|
|
4975
|
+
* 内存大小(MB) / Memory Size (MB)
|
|
4976
|
+
*/
|
|
4977
|
+
memory;
|
|
4978
|
+
/**
|
|
4979
|
+
* 创建时间 / Creation Time
|
|
4980
|
+
*/
|
|
4981
|
+
createdAt;
|
|
4982
|
+
/**
|
|
4983
|
+
* 描述 / Description
|
|
4984
|
+
*/
|
|
4985
|
+
description;
|
|
4986
|
+
/**
|
|
4987
|
+
* 执行角色 ARN / Execution Role ARN
|
|
4988
|
+
*/
|
|
4989
|
+
executionRoleArn;
|
|
4990
|
+
/**
|
|
4991
|
+
* 最后更新时间 / Last Updated Time
|
|
4992
|
+
*/
|
|
4993
|
+
lastUpdatedAt;
|
|
4994
|
+
/**
|
|
4995
|
+
* 资源名称 / Resource Name
|
|
4996
|
+
*/
|
|
4997
|
+
resourceName;
|
|
4998
|
+
/**
|
|
4999
|
+
* 沙箱空闲超时时间(秒) / Sandbox Idle Timeout (seconds)
|
|
5000
|
+
*/
|
|
5001
|
+
sandboxIdleTimeoutInSeconds;
|
|
5002
|
+
/**
|
|
5003
|
+
* 沙箱存活时间(秒) / Sandbox TTL (seconds)
|
|
5004
|
+
*/
|
|
5005
|
+
sandboxTtlInSeconds;
|
|
5006
|
+
/**
|
|
5007
|
+
* 每个沙箱的最大并发会话数 / Max Concurrency Limit Per Sandbox
|
|
5008
|
+
*/
|
|
5009
|
+
shareConcurrencyLimitPerSandbox;
|
|
5010
|
+
/**
|
|
5011
|
+
* 状态原因 / Status Reason
|
|
5012
|
+
*/
|
|
5013
|
+
statusReason;
|
|
5014
|
+
/**
|
|
5015
|
+
* 磁盘大小(GB) / Disk Size (GB)
|
|
5016
|
+
*/
|
|
5017
|
+
diskSize;
|
|
5018
|
+
/**
|
|
5019
|
+
* 是否允许匿名管理 / Whether to allow anonymous management
|
|
5020
|
+
*/
|
|
5021
|
+
allowAnonymousManage;
|
|
5022
|
+
_config;
|
|
5023
|
+
constructor(data, config2) {
|
|
5024
|
+
super();
|
|
5025
|
+
if (data) {
|
|
5026
|
+
updateObjectProperties(this, data);
|
|
5027
|
+
}
|
|
5028
|
+
this._config = config2;
|
|
5029
|
+
}
|
|
5030
|
+
uniqIdCallback = () => this.templateId;
|
|
5031
|
+
static getClient() {
|
|
5032
|
+
const { SandboxClient: SandboxClient2 } = (init_client3(), __toCommonJS(client_exports3));
|
|
5033
|
+
return new SandboxClient2();
|
|
5034
|
+
}
|
|
5035
|
+
/**
|
|
5036
|
+
* Create a new Template
|
|
5037
|
+
*/
|
|
5038
|
+
static async create(params) {
|
|
5039
|
+
const { input, config: config2 } = params;
|
|
5040
|
+
return await _Template.getClient().createTemplate({ input, config: config2 });
|
|
5041
|
+
}
|
|
5042
|
+
/**
|
|
5043
|
+
* Delete a Template by name
|
|
5044
|
+
*/
|
|
5045
|
+
static async delete(params) {
|
|
5046
|
+
const { name, config: config2 } = params;
|
|
5047
|
+
return await _Template.getClient().deleteTemplate({ name, config: config2 });
|
|
5048
|
+
}
|
|
5049
|
+
/**
|
|
5050
|
+
* Update a Template by name
|
|
5051
|
+
*/
|
|
5052
|
+
static async update(params) {
|
|
5053
|
+
const { name, input, config: config2 } = params;
|
|
5054
|
+
return await _Template.getClient().updateTemplate({ name, input, config: config2 });
|
|
5055
|
+
}
|
|
5056
|
+
/**
|
|
5057
|
+
* Get a Template by name
|
|
5058
|
+
*/
|
|
5059
|
+
static async get(params) {
|
|
5060
|
+
const { name, config: config2 } = params;
|
|
5061
|
+
return await _Template.getClient().getTemplate({ name, config: config2 });
|
|
5062
|
+
}
|
|
5063
|
+
/**
|
|
5064
|
+
* List Templates
|
|
4953
5065
|
*/
|
|
4954
|
-
|
|
4955
|
-
|
|
4956
|
-
|
|
4957
|
-
}
|
|
4958
|
-
return this._file;
|
|
5066
|
+
static async list(params) {
|
|
5067
|
+
const { input, config: config2 } = params ?? {};
|
|
5068
|
+
return await _Template.getClient().listTemplates({ input, config: config2 });
|
|
4959
5069
|
}
|
|
4960
5070
|
/**
|
|
4961
|
-
*
|
|
5071
|
+
* List all Templates (with pagination)
|
|
4962
5072
|
*/
|
|
4963
|
-
|
|
4964
|
-
|
|
4965
|
-
|
|
4966
|
-
|
|
4967
|
-
|
|
4968
|
-
|
|
5073
|
+
static listAll = listAllResourcesFunction(this.list);
|
|
5074
|
+
get = async (params = {}) => {
|
|
5075
|
+
return await _Template.get({
|
|
5076
|
+
name: this.templateName,
|
|
5077
|
+
config: params.config
|
|
5078
|
+
});
|
|
5079
|
+
};
|
|
4969
5080
|
/**
|
|
4970
|
-
*
|
|
5081
|
+
* Delete this template
|
|
4971
5082
|
*/
|
|
4972
|
-
|
|
4973
|
-
|
|
4974
|
-
|
|
5083
|
+
delete = async (params) => {
|
|
5084
|
+
const config2 = params?.config;
|
|
5085
|
+
if (!this.templateName) {
|
|
5086
|
+
throw new Error("templateName is required to delete a Template");
|
|
4975
5087
|
}
|
|
4976
|
-
|
|
4977
|
-
|
|
5088
|
+
const result = await _Template.delete({
|
|
5089
|
+
name: this.templateName,
|
|
5090
|
+
config: config2 ?? this._config
|
|
5091
|
+
});
|
|
5092
|
+
updateObjectProperties(this, result);
|
|
5093
|
+
return this;
|
|
5094
|
+
};
|
|
4978
5095
|
/**
|
|
4979
|
-
*
|
|
5096
|
+
* Update this template
|
|
4980
5097
|
*/
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
|
|
5098
|
+
update = async (params) => {
|
|
5099
|
+
const { input, config: config2 } = params;
|
|
5100
|
+
if (!this.templateName) {
|
|
5101
|
+
throw new Error("templateName is required to update a Template");
|
|
4984
5102
|
}
|
|
4985
|
-
|
|
4986
|
-
|
|
5103
|
+
const result = await _Template.update({
|
|
5104
|
+
name: this.templateName,
|
|
5105
|
+
input,
|
|
5106
|
+
config: config2 ?? this._config
|
|
5107
|
+
});
|
|
5108
|
+
updateObjectProperties(this, result);
|
|
5109
|
+
return this;
|
|
5110
|
+
};
|
|
4987
5111
|
/**
|
|
4988
|
-
*
|
|
5112
|
+
* Refresh this template's data
|
|
4989
5113
|
*/
|
|
4990
|
-
|
|
4991
|
-
|
|
4992
|
-
|
|
4993
|
-
|
|
5114
|
+
refresh = async (params) => {
|
|
5115
|
+
const config2 = params?.config;
|
|
5116
|
+
if (!this.templateName) {
|
|
5117
|
+
throw new Error("templateName is required to refresh a Template");
|
|
5118
|
+
}
|
|
5119
|
+
const result = await _Template.get({
|
|
5120
|
+
name: this.templateName,
|
|
5121
|
+
config: config2 ?? this._config
|
|
4994
5122
|
});
|
|
5123
|
+
updateObjectProperties(this, result);
|
|
5124
|
+
return this;
|
|
4995
5125
|
};
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
|
|
5126
|
+
};
|
|
5127
|
+
}
|
|
5128
|
+
});
|
|
5129
|
+
|
|
5130
|
+
// src/sandbox/api/aio-data.ts
|
|
5131
|
+
var AioDataAPI;
|
|
5132
|
+
var init_aio_data = __esm({
|
|
5133
|
+
"src/sandbox/api/aio-data.ts"() {
|
|
5134
|
+
init_browser_data();
|
|
5135
|
+
init_code_interpreter_data();
|
|
5136
|
+
AioDataAPI = class extends CodeInterpreterDataAPI {
|
|
5137
|
+
browserAPI;
|
|
5138
|
+
constructor(params) {
|
|
5139
|
+
super({
|
|
5140
|
+
sandboxId: params.sandboxId,
|
|
5141
|
+
config: params.config
|
|
5142
|
+
});
|
|
5143
|
+
this.browserAPI = new BrowserDataAPI({
|
|
5144
|
+
sandboxId: params.sandboxId,
|
|
5145
|
+
config: params.config
|
|
5146
|
+
});
|
|
5147
|
+
}
|
|
5148
|
+
// Browser API methods - delegate to browserAPI
|
|
4999
5149
|
/**
|
|
5000
5150
|
* Get CDP WebSocket URL for browser automation
|
|
5001
5151
|
*/
|
|
5002
5152
|
getCdpUrl(record) {
|
|
5003
|
-
return this.
|
|
5153
|
+
return this.browserAPI.getCdpUrl(record);
|
|
5004
5154
|
}
|
|
5005
5155
|
/**
|
|
5006
5156
|
* Get VNC WebSocket URL for live view
|
|
5007
5157
|
*/
|
|
5008
5158
|
getVncUrl(record) {
|
|
5009
|
-
return this.
|
|
5159
|
+
return this.browserAPI.getVncUrl(record);
|
|
5010
5160
|
}
|
|
5011
5161
|
/**
|
|
5012
|
-
* List
|
|
5162
|
+
* List browser recordings
|
|
5013
5163
|
*/
|
|
5014
5164
|
listRecordings = async (params) => {
|
|
5015
|
-
return this.
|
|
5016
|
-
};
|
|
5017
|
-
/**
|
|
5018
|
-
* Download a recording video file
|
|
5019
|
-
*/
|
|
5020
|
-
downloadRecording = async (params) => {
|
|
5021
|
-
return this.dataApi.downloadRecording(params);
|
|
5165
|
+
return this.browserAPI.listRecordings(params);
|
|
5022
5166
|
};
|
|
5023
5167
|
/**
|
|
5024
5168
|
* Delete a recording
|
|
5025
5169
|
*/
|
|
5026
5170
|
deleteRecording = async (params) => {
|
|
5027
|
-
return this.
|
|
5171
|
+
return this.browserAPI.deleteRecording(params);
|
|
5028
5172
|
};
|
|
5029
|
-
// ========================================
|
|
5030
|
-
// Code Interpreter API Methods
|
|
5031
|
-
// ========================================
|
|
5032
5173
|
/**
|
|
5033
|
-
*
|
|
5174
|
+
* Download a recording
|
|
5034
5175
|
*/
|
|
5035
|
-
|
|
5036
|
-
return this.
|
|
5176
|
+
downloadRecording = async (params) => {
|
|
5177
|
+
return this.browserAPI.downloadRecording(params);
|
|
5037
5178
|
};
|
|
5038
5179
|
};
|
|
5039
5180
|
}
|
|
5040
5181
|
});
|
|
5041
5182
|
|
|
5042
|
-
// src/sandbox/
|
|
5043
|
-
var
|
|
5044
|
-
__export(
|
|
5045
|
-
|
|
5183
|
+
// src/sandbox/aio-sandbox.ts
|
|
5184
|
+
var aio_sandbox_exports = {};
|
|
5185
|
+
__export(aio_sandbox_exports, {
|
|
5186
|
+
AioContextOperations: () => AioContextOperations,
|
|
5187
|
+
AioFileOperations: () => AioFileOperations,
|
|
5188
|
+
AioFileSystemOperations: () => AioFileSystemOperations,
|
|
5189
|
+
AioProcessOperations: () => AioProcessOperations,
|
|
5190
|
+
AioSandbox: () => AioSandbox
|
|
5046
5191
|
});
|
|
5047
|
-
var
|
|
5048
|
-
var
|
|
5049
|
-
"src/sandbox/
|
|
5050
|
-
|
|
5192
|
+
var AioFileOperations, AioFileSystemOperations, AioProcessOperations, AioContextOperations, AioSandbox;
|
|
5193
|
+
var init_aio_sandbox = __esm({
|
|
5194
|
+
"src/sandbox/aio-sandbox.ts"() {
|
|
5195
|
+
init_log();
|
|
5196
|
+
init_exception();
|
|
5197
|
+
init_aio_data();
|
|
5051
5198
|
init_model4();
|
|
5052
5199
|
init_sandbox();
|
|
5053
|
-
|
|
5054
|
-
|
|
5055
|
-
|
|
5056
|
-
|
|
5057
|
-
* Create a Custom Sandbox from template
|
|
5058
|
-
* 从模板创建自定义沙箱 / Create Custom Sandbox from Template
|
|
5059
|
-
*/
|
|
5060
|
-
static async createFromTemplate(templateName, options, config2) {
|
|
5061
|
-
const sandbox = await Sandbox.create(
|
|
5062
|
-
{
|
|
5063
|
-
templateName,
|
|
5064
|
-
sandboxIdleTimeoutSeconds: options?.sandboxIdleTimeoutSeconds,
|
|
5065
|
-
nasConfig: options?.nasConfig,
|
|
5066
|
-
ossMountConfig: options?.ossMountConfig,
|
|
5067
|
-
polarFsConfig: options?.polarFsConfig
|
|
5068
|
-
},
|
|
5069
|
-
config2
|
|
5070
|
-
);
|
|
5071
|
-
const customSandbox = new _CustomSandbox(sandbox, config2);
|
|
5072
|
-
return customSandbox;
|
|
5073
|
-
}
|
|
5074
|
-
constructor(sandbox, config2) {
|
|
5075
|
-
super(sandbox, config2);
|
|
5200
|
+
AioFileOperations = class {
|
|
5201
|
+
sandbox;
|
|
5202
|
+
constructor(sandbox) {
|
|
5203
|
+
this.sandbox = sandbox;
|
|
5076
5204
|
}
|
|
5077
|
-
_dataApi;
|
|
5078
5205
|
/**
|
|
5079
|
-
*
|
|
5206
|
+
* Read a file from the sandbox
|
|
5080
5207
|
*/
|
|
5081
|
-
|
|
5082
|
-
|
|
5083
|
-
|
|
5084
|
-
sandboxId: this.sandboxId || "",
|
|
5085
|
-
config: this._config
|
|
5086
|
-
});
|
|
5087
|
-
}
|
|
5088
|
-
return this._dataApi;
|
|
5089
|
-
}
|
|
5208
|
+
read = async (path2) => {
|
|
5209
|
+
return this.sandbox.dataApi.readFile({ path: path2 });
|
|
5210
|
+
};
|
|
5090
5211
|
/**
|
|
5091
|
-
*
|
|
5092
|
-
* 获取沙箱的基础 URL / Get base URL for the sandbox
|
|
5093
|
-
*
|
|
5094
|
-
* @returns 基础 URL / Base URL
|
|
5212
|
+
* Write a file to the sandbox
|
|
5095
5213
|
*/
|
|
5096
|
-
|
|
5097
|
-
|
|
5098
|
-
|
|
5099
|
-
}
|
|
5214
|
+
write = async (params) => {
|
|
5215
|
+
return this.sandbox.dataApi.writeFile(params);
|
|
5216
|
+
};
|
|
5100
5217
|
};
|
|
5101
|
-
|
|
5102
|
-
|
|
5103
|
-
|
|
5104
|
-
|
|
5105
|
-
|
|
5106
|
-
var init_sandbox = __esm({
|
|
5107
|
-
"src/sandbox/sandbox.ts"() {
|
|
5108
|
-
init_utils();
|
|
5109
|
-
init_config();
|
|
5110
|
-
init_resource();
|
|
5111
|
-
init_model4();
|
|
5112
|
-
init_sandbox_data();
|
|
5113
|
-
Sandbox = class _Sandbox extends ResourceBase {
|
|
5114
|
-
templateType;
|
|
5115
|
-
/**
|
|
5116
|
-
* 沙箱 ID / Sandbox ID
|
|
5117
|
-
*/
|
|
5118
|
-
sandboxId;
|
|
5119
|
-
/**
|
|
5120
|
-
* 沙箱名称 / Sandbox Name
|
|
5121
|
-
*/
|
|
5122
|
-
sandboxName;
|
|
5123
|
-
/**
|
|
5124
|
-
* 模板 ID / Template ID
|
|
5125
|
-
*/
|
|
5126
|
-
templateId;
|
|
5127
|
-
/**
|
|
5128
|
-
* 模板名称 / Template Name
|
|
5129
|
-
*/
|
|
5130
|
-
templateName;
|
|
5131
|
-
/**
|
|
5132
|
-
* 沙箱状态 / Sandbox State
|
|
5133
|
-
*/
|
|
5134
|
-
state;
|
|
5135
|
-
/**
|
|
5136
|
-
* 状态原因 / State Reason
|
|
5137
|
-
*/
|
|
5138
|
-
stateReason;
|
|
5218
|
+
AioFileSystemOperations = class {
|
|
5219
|
+
sandbox;
|
|
5220
|
+
constructor(sandbox) {
|
|
5221
|
+
this.sandbox = sandbox;
|
|
5222
|
+
}
|
|
5139
5223
|
/**
|
|
5140
|
-
*
|
|
5224
|
+
* List directory contents
|
|
5141
5225
|
*/
|
|
5142
|
-
|
|
5226
|
+
list = async (params) => {
|
|
5227
|
+
return this.sandbox.dataApi.listDirectory(params);
|
|
5228
|
+
};
|
|
5143
5229
|
/**
|
|
5144
|
-
*
|
|
5230
|
+
* Move a file or directory
|
|
5145
5231
|
*/
|
|
5146
|
-
|
|
5232
|
+
move = async (params) => {
|
|
5233
|
+
return this.sandbox.dataApi.moveFile(params);
|
|
5234
|
+
};
|
|
5147
5235
|
/**
|
|
5148
|
-
*
|
|
5236
|
+
* Remove a file or directory
|
|
5149
5237
|
*/
|
|
5150
|
-
|
|
5238
|
+
remove = async (params) => {
|
|
5239
|
+
return this.sandbox.dataApi.removeFile(params);
|
|
5240
|
+
};
|
|
5151
5241
|
/**
|
|
5152
|
-
*
|
|
5242
|
+
* Get file or directory statistics
|
|
5153
5243
|
*/
|
|
5154
|
-
|
|
5244
|
+
stat = async (params) => {
|
|
5245
|
+
return this.sandbox.dataApi.stat(params);
|
|
5246
|
+
};
|
|
5155
5247
|
/**
|
|
5156
|
-
*
|
|
5248
|
+
* Create a directory
|
|
5157
5249
|
*/
|
|
5158
|
-
|
|
5250
|
+
mkdir = async (params) => {
|
|
5251
|
+
return this.sandbox.dataApi.mkdir(params);
|
|
5252
|
+
};
|
|
5159
5253
|
/**
|
|
5160
|
-
*
|
|
5254
|
+
* Upload a file to the sandbox
|
|
5161
5255
|
*/
|
|
5162
|
-
|
|
5256
|
+
upload = async (params) => {
|
|
5257
|
+
return this.sandbox.dataApi.uploadFile(params);
|
|
5258
|
+
};
|
|
5163
5259
|
/**
|
|
5164
|
-
*
|
|
5260
|
+
* Download a file from the sandbox
|
|
5165
5261
|
*/
|
|
5166
|
-
|
|
5167
|
-
|
|
5168
|
-
|
|
5169
|
-
|
|
5170
|
-
|
|
5171
|
-
|
|
5172
|
-
|
|
5173
|
-
this.
|
|
5262
|
+
download = async (params) => {
|
|
5263
|
+
return this.sandbox.dataApi.downloadFile(params);
|
|
5264
|
+
};
|
|
5265
|
+
};
|
|
5266
|
+
AioProcessOperations = class {
|
|
5267
|
+
sandbox;
|
|
5268
|
+
constructor(sandbox) {
|
|
5269
|
+
this.sandbox = sandbox;
|
|
5174
5270
|
}
|
|
5175
5271
|
/**
|
|
5176
|
-
*
|
|
5177
|
-
* 从 SDK 响应对象创建沙箱 / Create Sandbox from SDK Response Object
|
|
5272
|
+
* Execute a command in the sandbox
|
|
5178
5273
|
*/
|
|
5179
|
-
|
|
5180
|
-
return
|
|
5181
|
-
|
|
5182
|
-
sandboxId: obj.sandboxId,
|
|
5183
|
-
sandboxName: obj.sandboxName,
|
|
5184
|
-
templateId: obj.templateId,
|
|
5185
|
-
templateName: obj.templateName,
|
|
5186
|
-
// API returns "status" field, map it to "state"
|
|
5187
|
-
state: obj.status || obj.state,
|
|
5188
|
-
stateReason: obj.stateReason,
|
|
5189
|
-
createdAt: obj.createdAt,
|
|
5190
|
-
lastUpdatedAt: obj.lastUpdatedAt,
|
|
5191
|
-
sandboxIdleTimeoutSeconds: obj.sandboxIdleTimeoutSeconds,
|
|
5192
|
-
// New fields / 新增字段
|
|
5193
|
-
endedAt: obj.endedAt,
|
|
5194
|
-
metadata: obj.metadata,
|
|
5195
|
-
sandboxArn: obj.sandboxArn,
|
|
5196
|
-
sandboxIdleTTLInSeconds: obj.sandboxIdleTTLInSeconds
|
|
5197
|
-
},
|
|
5198
|
-
config2
|
|
5199
|
-
);
|
|
5200
|
-
}
|
|
5201
|
-
static getClient() {
|
|
5202
|
-
const { SandboxClient: SandboxClient2 } = (init_client3(), __toCommonJS(client_exports3));
|
|
5203
|
-
return new SandboxClient2();
|
|
5204
|
-
}
|
|
5274
|
+
cmd = async (params) => {
|
|
5275
|
+
return this.sandbox.dataApi.cmd(params);
|
|
5276
|
+
};
|
|
5205
5277
|
/**
|
|
5206
|
-
*
|
|
5207
|
-
* 创建新沙箱 / Create a New Sandbox
|
|
5278
|
+
* List all processes
|
|
5208
5279
|
*/
|
|
5209
|
-
|
|
5210
|
-
return
|
|
5211
|
-
}
|
|
5280
|
+
list = async (params) => {
|
|
5281
|
+
return this.sandbox.dataApi.listProcesses(params);
|
|
5282
|
+
};
|
|
5212
5283
|
/**
|
|
5213
|
-
*
|
|
5284
|
+
* Get a specific process by PID
|
|
5214
5285
|
*/
|
|
5215
|
-
|
|
5216
|
-
|
|
5217
|
-
|
|
5218
|
-
}
|
|
5286
|
+
get = async (params) => {
|
|
5287
|
+
return this.sandbox.dataApi.getProcess(params);
|
|
5288
|
+
};
|
|
5219
5289
|
/**
|
|
5220
|
-
*
|
|
5290
|
+
* Kill a specific process by PID
|
|
5221
5291
|
*/
|
|
5222
|
-
|
|
5223
|
-
|
|
5224
|
-
|
|
5292
|
+
kill = async (params) => {
|
|
5293
|
+
return this.sandbox.dataApi.killProcess(params);
|
|
5294
|
+
};
|
|
5295
|
+
};
|
|
5296
|
+
AioContextOperations = class {
|
|
5297
|
+
sandbox;
|
|
5298
|
+
_contextId;
|
|
5299
|
+
_language;
|
|
5300
|
+
_cwd;
|
|
5301
|
+
constructor(sandbox) {
|
|
5302
|
+
this.sandbox = sandbox;
|
|
5225
5303
|
}
|
|
5226
5304
|
/**
|
|
5227
|
-
* Get
|
|
5305
|
+
* Get the current context ID
|
|
5228
5306
|
*/
|
|
5229
|
-
|
|
5230
|
-
|
|
5231
|
-
try {
|
|
5232
|
-
const cfg = Config.withConfigs(config2);
|
|
5233
|
-
const dataApi = new SandboxDataAPI({
|
|
5234
|
-
sandboxId: id,
|
|
5235
|
-
config: cfg
|
|
5236
|
-
});
|
|
5237
|
-
const result = await dataApi.getSandbox({
|
|
5238
|
-
sandboxId: id,
|
|
5239
|
-
config: cfg
|
|
5240
|
-
});
|
|
5241
|
-
if (result.code !== "SUCCESS") {
|
|
5242
|
-
throw new ClientError(
|
|
5243
|
-
0,
|
|
5244
|
-
`Failed to get sandbox: ${result.message || "Unknown error"}`
|
|
5245
|
-
);
|
|
5246
|
-
}
|
|
5247
|
-
const data = result.data || {};
|
|
5248
|
-
const baseSandbox = _Sandbox.fromInnerObject(data, config2);
|
|
5249
|
-
if (templateType) {
|
|
5250
|
-
switch (templateType) {
|
|
5251
|
-
case "CodeInterpreter" /* CODE_INTERPRETER */: {
|
|
5252
|
-
const { CodeInterpreterSandbox: CodeInterpreterSandbox2 } = await Promise.resolve().then(() => (init_code_interpreter_sandbox(), code_interpreter_sandbox_exports));
|
|
5253
|
-
const sandbox = new CodeInterpreterSandbox2(baseSandbox, config2);
|
|
5254
|
-
return sandbox;
|
|
5255
|
-
}
|
|
5256
|
-
case "Browser" /* BROWSER */: {
|
|
5257
|
-
const { BrowserSandbox: BrowserSandbox2 } = await Promise.resolve().then(() => (init_browser_sandbox(), browser_sandbox_exports));
|
|
5258
|
-
const sandbox = new BrowserSandbox2(baseSandbox, config2);
|
|
5259
|
-
return sandbox;
|
|
5260
|
-
}
|
|
5261
|
-
case "AllInOne" /* AIO */: {
|
|
5262
|
-
const { AioSandbox: AioSandbox2 } = await Promise.resolve().then(() => (init_aio_sandbox(), aio_sandbox_exports));
|
|
5263
|
-
const sandbox = new AioSandbox2(baseSandbox, config2);
|
|
5264
|
-
return sandbox;
|
|
5265
|
-
}
|
|
5266
|
-
case "CustomImage" /* CUSTOM */: {
|
|
5267
|
-
const { CustomSandbox: CustomSandbox2 } = await Promise.resolve().then(() => (init_custom_sandbox(), custom_sandbox_exports));
|
|
5268
|
-
const sandbox = new CustomSandbox2(baseSandbox, config2);
|
|
5269
|
-
return sandbox;
|
|
5270
|
-
}
|
|
5271
|
-
}
|
|
5272
|
-
}
|
|
5273
|
-
return baseSandbox;
|
|
5274
|
-
} catch (error) {
|
|
5275
|
-
if (error instanceof HTTPError) {
|
|
5276
|
-
throw error.toResourceError("Sandbox", id);
|
|
5277
|
-
}
|
|
5278
|
-
throw error;
|
|
5279
|
-
}
|
|
5307
|
+
get contextId() {
|
|
5308
|
+
return this._contextId;
|
|
5280
5309
|
}
|
|
5281
5310
|
/**
|
|
5282
|
-
* List
|
|
5311
|
+
* List all contexts
|
|
5283
5312
|
*/
|
|
5284
|
-
|
|
5285
|
-
return
|
|
5286
|
-
}
|
|
5287
|
-
get = async (params) => {
|
|
5288
|
-
const { config: config2 } = params ?? {};
|
|
5289
|
-
return await _Sandbox.get({
|
|
5290
|
-
id: this.sandboxId,
|
|
5291
|
-
templateType: this.templateType,
|
|
5292
|
-
config: Config.withConfigs(this._config, config2)
|
|
5293
|
-
});
|
|
5313
|
+
list = async (params) => {
|
|
5314
|
+
return this.sandbox.dataApi.listContexts(params);
|
|
5294
5315
|
};
|
|
5295
5316
|
/**
|
|
5296
|
-
*
|
|
5317
|
+
* Create a new context and save its ID
|
|
5297
5318
|
*/
|
|
5298
|
-
|
|
5299
|
-
const
|
|
5300
|
-
|
|
5301
|
-
|
|
5302
|
-
|
|
5303
|
-
|
|
5304
|
-
id: this.sandboxId,
|
|
5305
|
-
config: config2 ?? this._config
|
|
5319
|
+
create = async (params) => {
|
|
5320
|
+
const language = params?.language || "python" /* PYTHON */;
|
|
5321
|
+
const cwd = params?.cwd || "/home/user";
|
|
5322
|
+
const result = await this.sandbox.dataApi.createContext({
|
|
5323
|
+
language,
|
|
5324
|
+
cwd
|
|
5306
5325
|
});
|
|
5307
|
-
|
|
5308
|
-
|
|
5326
|
+
if (result?.id && result?.cwd && result?.language) {
|
|
5327
|
+
this._contextId = result.id;
|
|
5328
|
+
this._language = result.language;
|
|
5329
|
+
this._cwd = result.cwd;
|
|
5330
|
+
return this;
|
|
5331
|
+
}
|
|
5332
|
+
throw new ServerError(500, "Failed to create context");
|
|
5309
5333
|
};
|
|
5310
5334
|
/**
|
|
5311
|
-
*
|
|
5335
|
+
* Get a specific context by ID
|
|
5312
5336
|
*/
|
|
5313
|
-
|
|
5314
|
-
const
|
|
5315
|
-
if (!
|
|
5316
|
-
|
|
5337
|
+
get = async (params) => {
|
|
5338
|
+
const id = params?.contextId || this._contextId;
|
|
5339
|
+
if (!id) {
|
|
5340
|
+
logger.error("context id is not set");
|
|
5341
|
+
throw new Error("context id is not set");
|
|
5317
5342
|
}
|
|
5318
|
-
const result = await
|
|
5319
|
-
|
|
5320
|
-
|
|
5321
|
-
|
|
5322
|
-
|
|
5323
|
-
|
|
5343
|
+
const result = await this.sandbox.dataApi.getContext({ contextId: id });
|
|
5344
|
+
if (result?.id && result?.cwd && result?.language) {
|
|
5345
|
+
this._contextId = result.id;
|
|
5346
|
+
this._language = result.language;
|
|
5347
|
+
this._cwd = result.cwd;
|
|
5348
|
+
return this;
|
|
5349
|
+
}
|
|
5350
|
+
throw new ServerError(500, "Failed to get context");
|
|
5324
5351
|
};
|
|
5325
5352
|
/**
|
|
5326
|
-
*
|
|
5353
|
+
* Execute code in a context
|
|
5327
5354
|
*/
|
|
5328
|
-
|
|
5329
|
-
const
|
|
5330
|
-
|
|
5331
|
-
|
|
5355
|
+
execute = async (params) => {
|
|
5356
|
+
const { code, timeout = 30 } = params;
|
|
5357
|
+
let { contextId, language } = params;
|
|
5358
|
+
if (!contextId) {
|
|
5359
|
+
contextId = this._contextId;
|
|
5332
5360
|
}
|
|
5333
|
-
|
|
5334
|
-
id:
|
|
5335
|
-
|
|
5361
|
+
if (!contextId && !language) {
|
|
5362
|
+
logger.debug("context id is not set, use default language: python");
|
|
5363
|
+
language = "python" /* PYTHON */;
|
|
5364
|
+
}
|
|
5365
|
+
return this.sandbox.dataApi.executeCode({
|
|
5366
|
+
code,
|
|
5367
|
+
contextId,
|
|
5368
|
+
language,
|
|
5369
|
+
timeout
|
|
5336
5370
|
});
|
|
5337
|
-
updateObjectProperties(this, result);
|
|
5338
|
-
return this;
|
|
5339
5371
|
};
|
|
5340
5372
|
/**
|
|
5341
|
-
*
|
|
5373
|
+
* Delete a context
|
|
5342
5374
|
*/
|
|
5343
|
-
|
|
5344
|
-
const
|
|
5345
|
-
|
|
5346
|
-
|
|
5347
|
-
|
|
5348
|
-
|
|
5349
|
-
|
|
5350
|
-
|
|
5351
|
-
|
|
5352
|
-
|
|
5353
|
-
|
|
5354
|
-
|
|
5355
|
-
|
|
5356
|
-
|
|
5357
|
-
}
|
|
5358
|
-
await new Promise((resolve) => setTimeout(resolve, interval));
|
|
5359
|
-
}
|
|
5360
|
-
throw new Error(
|
|
5361
|
-
`Timeout waiting for Sandbox to be running after ${options?.timeoutSeconds ?? 300} seconds`
|
|
5362
|
-
);
|
|
5363
|
-
};
|
|
5364
|
-
};
|
|
5365
|
-
}
|
|
5366
|
-
});
|
|
5367
|
-
|
|
5368
|
-
// src/sandbox/browser-sandbox.ts
|
|
5369
|
-
var browser_sandbox_exports = {};
|
|
5370
|
-
__export(browser_sandbox_exports, {
|
|
5371
|
-
BrowserSandbox: () => BrowserSandbox
|
|
5372
|
-
});
|
|
5373
|
-
var BrowserSandbox;
|
|
5374
|
-
var init_browser_sandbox = __esm({
|
|
5375
|
-
"src/sandbox/browser-sandbox.ts"() {
|
|
5376
|
-
init_browser_data();
|
|
5377
|
-
init_model4();
|
|
5378
|
-
init_sandbox();
|
|
5379
|
-
BrowserSandbox = class _BrowserSandbox extends Sandbox {
|
|
5380
|
-
static templateType = "Browser" /* BROWSER */;
|
|
5375
|
+
delete = async (params) => {
|
|
5376
|
+
const id = params?.contextId || this._contextId;
|
|
5377
|
+
if (!id) {
|
|
5378
|
+
throw new Error(
|
|
5379
|
+
"context_id is required. Either pass it as parameter or create a context first."
|
|
5380
|
+
);
|
|
5381
|
+
}
|
|
5382
|
+
const result = await this.sandbox.dataApi.deleteContext({ contextId: id });
|
|
5383
|
+
this._contextId = void 0;
|
|
5384
|
+
return result;
|
|
5385
|
+
};
|
|
5386
|
+
};
|
|
5387
|
+
AioSandbox = class _AioSandbox extends Sandbox {
|
|
5388
|
+
static templateType = "AllInOne" /* AIO */;
|
|
5381
5389
|
/**
|
|
5382
|
-
* Create
|
|
5383
|
-
*
|
|
5390
|
+
* Create an AIO Sandbox from template
|
|
5391
|
+
* 从模板创建 AIO 沙箱 / Create AIO Sandbox from Template
|
|
5384
5392
|
*/
|
|
5385
5393
|
static async createFromTemplate(templateName, options, config2) {
|
|
5386
5394
|
const sandbox = await Sandbox.create(
|
|
@@ -5393,28 +5401,65 @@ var init_browser_sandbox = __esm({
|
|
|
5393
5401
|
},
|
|
5394
5402
|
config2
|
|
5395
5403
|
);
|
|
5396
|
-
const
|
|
5397
|
-
return
|
|
5404
|
+
const aioSandbox = new _AioSandbox(sandbox, config2);
|
|
5405
|
+
return aioSandbox;
|
|
5398
5406
|
}
|
|
5399
5407
|
constructor(sandbox, config2) {
|
|
5400
5408
|
super(sandbox, config2);
|
|
5401
5409
|
}
|
|
5402
5410
|
_dataApi;
|
|
5411
|
+
_file;
|
|
5412
|
+
_fileSystem;
|
|
5413
|
+
_context;
|
|
5414
|
+
_process;
|
|
5403
5415
|
/**
|
|
5404
5416
|
* Get data API client
|
|
5405
5417
|
*/
|
|
5406
5418
|
get dataApi() {
|
|
5407
5419
|
if (!this._dataApi) {
|
|
5408
|
-
|
|
5409
|
-
|
|
5410
|
-
}
|
|
5411
|
-
this._dataApi = new BrowserDataAPI({
|
|
5412
|
-
sandboxId: this.sandboxId,
|
|
5420
|
+
this._dataApi = new AioDataAPI({
|
|
5421
|
+
sandboxId: this.sandboxId || "",
|
|
5413
5422
|
config: this._config
|
|
5414
5423
|
});
|
|
5415
5424
|
}
|
|
5416
5425
|
return this._dataApi;
|
|
5417
5426
|
}
|
|
5427
|
+
/**
|
|
5428
|
+
* Access file upload/download operations
|
|
5429
|
+
*/
|
|
5430
|
+
get file() {
|
|
5431
|
+
if (!this._file) {
|
|
5432
|
+
this._file = new AioFileOperations(this);
|
|
5433
|
+
}
|
|
5434
|
+
return this._file;
|
|
5435
|
+
}
|
|
5436
|
+
/**
|
|
5437
|
+
* Access file system operations
|
|
5438
|
+
*/
|
|
5439
|
+
get fileSystem() {
|
|
5440
|
+
if (!this._fileSystem) {
|
|
5441
|
+
this._fileSystem = new AioFileSystemOperations(this);
|
|
5442
|
+
}
|
|
5443
|
+
return this._fileSystem;
|
|
5444
|
+
}
|
|
5445
|
+
/**
|
|
5446
|
+
* Access context management operations
|
|
5447
|
+
*/
|
|
5448
|
+
get context() {
|
|
5449
|
+
if (!this._context) {
|
|
5450
|
+
this._context = new AioContextOperations(this);
|
|
5451
|
+
}
|
|
5452
|
+
return this._context;
|
|
5453
|
+
}
|
|
5454
|
+
/**
|
|
5455
|
+
* Access process management operations
|
|
5456
|
+
*/
|
|
5457
|
+
get process() {
|
|
5458
|
+
if (!this._process) {
|
|
5459
|
+
this._process = new AioProcessOperations(this);
|
|
5460
|
+
}
|
|
5461
|
+
return this._process;
|
|
5462
|
+
}
|
|
5418
5463
|
/**
|
|
5419
5464
|
* Check sandbox health
|
|
5420
5465
|
*/
|
|
@@ -5424,6 +5469,9 @@ var init_browser_sandbox = __esm({
|
|
|
5424
5469
|
config: params?.config
|
|
5425
5470
|
});
|
|
5426
5471
|
};
|
|
5472
|
+
// ========================================
|
|
5473
|
+
// Browser API Methods
|
|
5474
|
+
// ========================================
|
|
5427
5475
|
/**
|
|
5428
5476
|
* Get CDP WebSocket URL for browser automation
|
|
5429
5477
|
*/
|
|
@@ -5437,7 +5485,7 @@ var init_browser_sandbox = __esm({
|
|
|
5437
5485
|
return this.dataApi.getVncUrl(record);
|
|
5438
5486
|
}
|
|
5439
5487
|
/**
|
|
5440
|
-
* List all recordings
|
|
5488
|
+
* List all browser recordings
|
|
5441
5489
|
*/
|
|
5442
5490
|
listRecordings = async (params) => {
|
|
5443
5491
|
return this.dataApi.listRecordings(params);
|
|
@@ -5454,187 +5502,14 @@ var init_browser_sandbox = __esm({
|
|
|
5454
5502
|
deleteRecording = async (params) => {
|
|
5455
5503
|
return this.dataApi.deleteRecording(params);
|
|
5456
5504
|
};
|
|
5457
|
-
|
|
5458
|
-
|
|
5459
|
-
|
|
5460
|
-
|
|
5461
|
-
// src/sandbox/template.ts
|
|
5462
|
-
var Template;
|
|
5463
|
-
var init_template = __esm({
|
|
5464
|
-
"src/sandbox/template.ts"() {
|
|
5465
|
-
init_resource();
|
|
5466
|
-
Template = class _Template extends ResourceBase {
|
|
5467
|
-
/**
|
|
5468
|
-
* 模板 ARN / Template ARN
|
|
5469
|
-
*/
|
|
5470
|
-
templateArn;
|
|
5471
|
-
/**
|
|
5472
|
-
* 模板 ID / Template ID
|
|
5473
|
-
*/
|
|
5474
|
-
templateId;
|
|
5475
|
-
/**
|
|
5476
|
-
* 模板名称 / Template Name
|
|
5477
|
-
*/
|
|
5478
|
-
templateName;
|
|
5479
|
-
/**
|
|
5480
|
-
* 模板类型 / Template Type
|
|
5481
|
-
*/
|
|
5482
|
-
templateType;
|
|
5483
|
-
/**
|
|
5484
|
-
* CPU 核数 / CPU Cores
|
|
5485
|
-
*/
|
|
5486
|
-
cpu;
|
|
5487
|
-
/**
|
|
5488
|
-
* 内存大小(MB) / Memory Size (MB)
|
|
5489
|
-
*/
|
|
5490
|
-
memory;
|
|
5491
|
-
/**
|
|
5492
|
-
* 创建时间 / Creation Time
|
|
5493
|
-
*/
|
|
5494
|
-
createdAt;
|
|
5495
|
-
/**
|
|
5496
|
-
* 描述 / Description
|
|
5497
|
-
*/
|
|
5498
|
-
description;
|
|
5499
|
-
/**
|
|
5500
|
-
* 执行角色 ARN / Execution Role ARN
|
|
5501
|
-
*/
|
|
5502
|
-
executionRoleArn;
|
|
5503
|
-
/**
|
|
5504
|
-
* 最后更新时间 / Last Updated Time
|
|
5505
|
-
*/
|
|
5506
|
-
lastUpdatedAt;
|
|
5507
|
-
/**
|
|
5508
|
-
* 资源名称 / Resource Name
|
|
5509
|
-
*/
|
|
5510
|
-
resourceName;
|
|
5511
|
-
/**
|
|
5512
|
-
* 沙箱空闲超时时间(秒) / Sandbox Idle Timeout (seconds)
|
|
5513
|
-
*/
|
|
5514
|
-
sandboxIdleTimeoutInSeconds;
|
|
5515
|
-
/**
|
|
5516
|
-
* 沙箱存活时间(秒) / Sandbox TTL (seconds)
|
|
5517
|
-
*/
|
|
5518
|
-
sandboxTtlInSeconds;
|
|
5519
|
-
/**
|
|
5520
|
-
* 每个沙箱的最大并发会话数 / Max Concurrency Limit Per Sandbox
|
|
5521
|
-
*/
|
|
5522
|
-
shareConcurrencyLimitPerSandbox;
|
|
5523
|
-
/**
|
|
5524
|
-
* 状态原因 / Status Reason
|
|
5525
|
-
*/
|
|
5526
|
-
statusReason;
|
|
5527
|
-
/**
|
|
5528
|
-
* 磁盘大小(GB) / Disk Size (GB)
|
|
5529
|
-
*/
|
|
5530
|
-
diskSize;
|
|
5531
|
-
/**
|
|
5532
|
-
* 是否允许匿名管理 / Whether to allow anonymous management
|
|
5533
|
-
*/
|
|
5534
|
-
allowAnonymousManage;
|
|
5535
|
-
_config;
|
|
5536
|
-
constructor(data, config2) {
|
|
5537
|
-
super();
|
|
5538
|
-
if (data) {
|
|
5539
|
-
updateObjectProperties(this, data);
|
|
5540
|
-
}
|
|
5541
|
-
this._config = config2;
|
|
5542
|
-
}
|
|
5543
|
-
uniqIdCallback = () => this.templateId;
|
|
5544
|
-
static getClient() {
|
|
5545
|
-
const { SandboxClient: SandboxClient2 } = (init_client3(), __toCommonJS(client_exports3));
|
|
5546
|
-
return new SandboxClient2();
|
|
5547
|
-
}
|
|
5548
|
-
/**
|
|
5549
|
-
* Create a new Template
|
|
5550
|
-
*/
|
|
5551
|
-
static async create(params) {
|
|
5552
|
-
const { input, config: config2 } = params;
|
|
5553
|
-
return await _Template.getClient().createTemplate({ input, config: config2 });
|
|
5554
|
-
}
|
|
5555
|
-
/**
|
|
5556
|
-
* Delete a Template by name
|
|
5557
|
-
*/
|
|
5558
|
-
static async delete(params) {
|
|
5559
|
-
const { name, config: config2 } = params;
|
|
5560
|
-
return await _Template.getClient().deleteTemplate({ name, config: config2 });
|
|
5561
|
-
}
|
|
5562
|
-
/**
|
|
5563
|
-
* Update a Template by name
|
|
5564
|
-
*/
|
|
5565
|
-
static async update(params) {
|
|
5566
|
-
const { name, input, config: config2 } = params;
|
|
5567
|
-
return await _Template.getClient().updateTemplate({ name, input, config: config2 });
|
|
5568
|
-
}
|
|
5569
|
-
/**
|
|
5570
|
-
* Get a Template by name
|
|
5571
|
-
*/
|
|
5572
|
-
static async get(params) {
|
|
5573
|
-
const { name, config: config2 } = params;
|
|
5574
|
-
return await _Template.getClient().getTemplate({ name, config: config2 });
|
|
5575
|
-
}
|
|
5576
|
-
/**
|
|
5577
|
-
* List Templates
|
|
5578
|
-
*/
|
|
5579
|
-
static async list(params) {
|
|
5580
|
-
const { input, config: config2 } = params ?? {};
|
|
5581
|
-
return await _Template.getClient().listTemplates({ input, config: config2 });
|
|
5582
|
-
}
|
|
5583
|
-
/**
|
|
5584
|
-
* List all Templates (with pagination)
|
|
5585
|
-
*/
|
|
5586
|
-
static listAll = listAllResourcesFunction(this.list);
|
|
5587
|
-
get = async (params = {}) => {
|
|
5588
|
-
return await _Template.get({
|
|
5589
|
-
name: this.templateName,
|
|
5590
|
-
config: params.config
|
|
5591
|
-
});
|
|
5592
|
-
};
|
|
5593
|
-
/**
|
|
5594
|
-
* Delete this template
|
|
5595
|
-
*/
|
|
5596
|
-
delete = async (params) => {
|
|
5597
|
-
const config2 = params?.config;
|
|
5598
|
-
if (!this.templateName) {
|
|
5599
|
-
throw new Error("templateName is required to delete a Template");
|
|
5600
|
-
}
|
|
5601
|
-
const result = await _Template.delete({
|
|
5602
|
-
name: this.templateName,
|
|
5603
|
-
config: config2 ?? this._config
|
|
5604
|
-
});
|
|
5605
|
-
updateObjectProperties(this, result);
|
|
5606
|
-
return this;
|
|
5607
|
-
};
|
|
5608
|
-
/**
|
|
5609
|
-
* Update this template
|
|
5610
|
-
*/
|
|
5611
|
-
update = async (params) => {
|
|
5612
|
-
const { input, config: config2 } = params;
|
|
5613
|
-
if (!this.templateName) {
|
|
5614
|
-
throw new Error("templateName is required to update a Template");
|
|
5615
|
-
}
|
|
5616
|
-
const result = await _Template.update({
|
|
5617
|
-
name: this.templateName,
|
|
5618
|
-
input,
|
|
5619
|
-
config: config2 ?? this._config
|
|
5620
|
-
});
|
|
5621
|
-
updateObjectProperties(this, result);
|
|
5622
|
-
return this;
|
|
5623
|
-
};
|
|
5505
|
+
// ========================================
|
|
5506
|
+
// Code Interpreter API Methods
|
|
5507
|
+
// ========================================
|
|
5624
5508
|
/**
|
|
5625
|
-
*
|
|
5509
|
+
* Execute code (convenience method delegating to context.execute)
|
|
5626
5510
|
*/
|
|
5627
|
-
|
|
5628
|
-
|
|
5629
|
-
if (!this.templateName) {
|
|
5630
|
-
throw new Error("templateName is required to refresh a Template");
|
|
5631
|
-
}
|
|
5632
|
-
const result = await _Template.get({
|
|
5633
|
-
name: this.templateName,
|
|
5634
|
-
config: config2 ?? this._config
|
|
5635
|
-
});
|
|
5636
|
-
updateObjectProperties(this, result);
|
|
5637
|
-
return this;
|
|
5511
|
+
execute = async (params) => {
|
|
5512
|
+
return this.context.execute(params);
|
|
5638
5513
|
};
|
|
5639
5514
|
};
|
|
5640
5515
|
}
|
|
@@ -5765,7 +5640,7 @@ var init_client3 = __esm({
|
|
|
5765
5640
|
input: request,
|
|
5766
5641
|
config: cfg
|
|
5767
5642
|
});
|
|
5768
|
-
return (result
|
|
5643
|
+
return (result.items || []).map((item) => new Template(item, cfg));
|
|
5769
5644
|
};
|
|
5770
5645
|
// ============ Sandbox Operations ============
|
|
5771
5646
|
/**
|
|
@@ -8614,7 +8489,6 @@ init_template();
|
|
|
8614
8489
|
init_code_interpreter_sandbox();
|
|
8615
8490
|
init_browser_sandbox();
|
|
8616
8491
|
init_aio_sandbox();
|
|
8617
|
-
init_custom_sandbox();
|
|
8618
8492
|
init_sandbox_data();
|
|
8619
8493
|
init_code_interpreter_data();
|
|
8620
8494
|
init_browser_data();
|