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