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