@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 CHANGED
@@ -4071,11 +4071,12 @@ 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__ */ ((TemplateType3) => {
4075
- TemplateType3["CODE_INTERPRETER"] = "CodeInterpreter";
4076
- TemplateType3["BROWSER"] = "Browser";
4077
- TemplateType3["AIO"] = "AllInOne";
4078
- return TemplateType3;
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;
4079
4080
  })(exports.TemplateType || {});
4080
4081
  exports.SandboxState = /* @__PURE__ */ ((SandboxState2) => {
4081
4082
  SandboxState2["CREATING"] = "Creating";
@@ -4103,618 +4104,675 @@ var init_model4 = __esm({
4103
4104
  })(exports.CodeLanguage || {});
4104
4105
  }
4105
4106
  });
4106
-
4107
- // src/sandbox/sandbox.ts
4108
- exports.Sandbox = void 0;
4109
- var init_sandbox = __esm({
4110
- "src/sandbox/sandbox.ts"() {
4107
+ exports.CodeInterpreterDataAPI = void 0;
4108
+ var init_code_interpreter_data = __esm({
4109
+ "src/sandbox/api/code-interpreter-data.ts"() {
4111
4110
  init_config();
4112
- init_resource();
4111
+ init_exception();
4112
+ init_log();
4113
4113
  init_model4();
4114
- exports.Sandbox = class _Sandbox extends ResourceBase {
4115
- templateType;
4116
- /**
4117
- * 沙箱 ID / Sandbox ID
4118
- */
4119
- sandboxId;
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
+ }
4120
4124
  /**
4121
- * 沙箱名称 / Sandbox Name
4125
+ * List directory contents
4122
4126
  */
4123
- sandboxName;
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
+ }
4124
4137
  /**
4125
- * 模板 ID / Template ID
4138
+ * Get file/directory stats
4126
4139
  */
4127
- templateId;
4140
+ async stat(params) {
4141
+ const query = {
4142
+ path: params.path
4143
+ };
4144
+ return this.get({ path: "/filesystem/stat", query, config: params.config });
4145
+ }
4128
4146
  /**
4129
- * 模板名称 / Template Name
4147
+ * Create directory
4130
4148
  */
4131
- templateName;
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
+ }
4132
4157
  /**
4133
- * 沙箱状态 / Sandbox State
4158
+ * Move file or directory
4134
4159
  */
4135
- state;
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
+ }
4136
4167
  /**
4137
- * 状态原因 / State Reason
4168
+ * Remove file or directory
4138
4169
  */
4139
- stateReason;
4170
+ async removeFile(params) {
4171
+ const data = {
4172
+ path: params.path
4173
+ };
4174
+ return this.post({ path: "/filesystem/remove", data, config: params.config });
4175
+ }
4140
4176
  /**
4141
- * 沙箱创建时间 / Sandbox Creation Time
4177
+ * List code execution contexts
4142
4178
  */
4143
- createdAt;
4179
+ async listContexts(params) {
4180
+ return this.get({ path: "/contexts", config: params?.config });
4181
+ }
4144
4182
  /**
4145
- * 最后更新时间 / Last Updated Time
4183
+ * Create a new code execution context
4146
4184
  */
4147
- lastUpdatedAt;
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
+ }
4148
4199
  /**
4149
- * 沙箱空闲超时时间(秒) / Sandbox Idle Timeout (seconds)
4200
+ * Get context details
4150
4201
  */
4151
- sandboxIdleTimeoutSeconds;
4202
+ async getContext(params) {
4203
+ return this.get({ path: `/contexts/${params.contextId}`, config: params.config });
4204
+ }
4152
4205
  /**
4153
- * 沙箱结束时间 / Sandbox End Time
4206
+ * Execute code in a context
4154
4207
  */
4155
- endedAt;
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
+ }
4156
4229
  /**
4157
- * 元数据 / Metadata
4230
+ * Delete a context
4158
4231
  */
4159
- metadata;
4232
+ async deleteContext(params) {
4233
+ return this.delete({ path: `/contexts/${params.contextId}`, config: params.config });
4234
+ }
4160
4235
  /**
4161
- * 沙箱全局唯一资源名称 / Sandbox ARN
4236
+ * Read file contents
4162
4237
  */
4163
- sandboxArn;
4238
+ async readFile(params) {
4239
+ const query = {
4240
+ path: params.path
4241
+ };
4242
+ return this.get({ path: "/files", query, config: params.config });
4243
+ }
4164
4244
  /**
4165
- * 沙箱空闲 TTL(秒) / Sandbox Idle TTL (seconds)
4245
+ * Write file contents
4166
4246
  */
4167
- sandboxIdleTTLInSeconds;
4168
- _config;
4169
- constructor(data, config2) {
4170
- super();
4171
- if (data) {
4172
- updateObjectProperties(this, data);
4173
- }
4174
- this._config = config2;
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 });
4175
4256
  }
4176
4257
  /**
4177
- * Create sandbox from SDK response object
4178
- * 从 SDK 响应对象创建沙箱 / Create Sandbox from SDK Response Object
4258
+ * Upload file to sandbox
4179
4259
  */
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();
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
+ });
4205
4267
  }
4206
4268
  /**
4207
- * Create a new Sandbox
4208
- * 创建新沙箱 / Create a New Sandbox
4269
+ * Download file from sandbox
4209
4270
  */
4210
- static async create(input, config2) {
4211
- return await _Sandbox.getClient().createSandbox({ input, config: config2 });
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
+ });
4212
4279
  }
4213
4280
  /**
4214
- * Delete a Sandbox by ID
4281
+ * Execute shell command
4215
4282
  */
4216
- static async delete(params) {
4217
- const { id, config: config2 } = params;
4218
- return await _Sandbox.getClient().deleteSandbox({ id, config: config2 });
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 });
4219
4292
  }
4220
4293
  /**
4221
- * Stop a Sandbox by ID
4294
+ * List running processes
4222
4295
  */
4223
- static async stop(params) {
4224
- const { id, config: config2 } = params;
4225
- return await _Sandbox.getClient().stopSandbox({ id, config: config2 });
4296
+ async listProcesses(params) {
4297
+ return this.get({ path: "/processes", config: params?.config });
4226
4298
  }
4227
4299
  /**
4228
- * Get a Sandbox by ID
4300
+ * Get process details
4229
4301
  */
4230
- static async get(params) {
4231
- const { id, templateType, config: config2 } = params;
4232
- return await _Sandbox.getClient().getSandbox({ id, templateType, config: config2 });
4302
+ async getProcess(params) {
4303
+ return this.get({ path: `/processes/${params.pid}`, config: params.config });
4233
4304
  }
4234
4305
  /**
4235
- * List Sandboxes
4306
+ * Kill a process
4236
4307
  */
4237
- static async list(input, config2) {
4238
- return await _Sandbox.getClient().listSandboxes({ input, config: config2 });
4308
+ async killProcess(params) {
4309
+ return this.delete({ path: `/processes/${params.pid}`, config: params.config });
4239
4310
  }
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
- });
4247
- };
4248
4311
  /**
4249
- * Delete this sandbox
4250
- */
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;
4262
- };
4263
- /**
4264
- * Stop this sandbox
4265
- */
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;
4277
- };
4278
- /**
4279
- * Refresh this sandbox's data
4312
+ * Helper method to upload file using multipart/form-data
4280
4313
  */
4281
- refresh = async (params) => {
4282
- const config2 = params?.config;
4283
- if (!this.sandboxId) {
4284
- throw new Error("sandboxId is required to refresh a Sandbox");
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}`);
4285
4350
  }
4286
- const result = await _Sandbox.get({
4287
- id: this.sandboxId,
4288
- config: config2 ?? this._config
4289
- });
4290
- updateObjectProperties(this, result);
4291
- return this;
4292
- };
4351
+ }
4293
4352
  /**
4294
- * Wait until the sandbox is running
4353
+ * Helper method to download file
4295
4354
  */
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;
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);
4307
4368
  }
4308
- if (this.state === "Failed" /* FAILED */) {
4309
- throw new Error(`Sandbox failed: ${this.stateReason}`);
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;
4310
4379
  }
4311
- await new Promise((resolve) => setTimeout(resolve, interval));
4380
+ logger.error(`Download file error: ${error}`);
4381
+ throw new exports.ClientError(0, `Download file error: ${error}`);
4312
4382
  }
4313
- throw new Error(
4314
- `Timeout waiting for Sandbox to be running after ${options?.timeoutSeconds ?? 300} seconds`
4315
- );
4316
- };
4383
+ }
4317
4384
  };
4318
4385
  }
4319
4386
  });
4320
4387
 
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();
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();
4326
4403
  init_model4();
4327
4404
  init_sandbox();
4328
- exports.BrowserSandbox = class _BrowserSandbox extends exports.Sandbox {
4329
- static templateType = "Browser" /* BROWSER */;
4405
+ FileOperations = class {
4406
+ sandbox;
4407
+ constructor(sandbox) {
4408
+ this.sandbox = sandbox;
4409
+ }
4330
4410
  /**
4331
- * Create a Browser Sandbox from template
4332
- * 从模板创建浏览器沙箱 / Create Browser Sandbox from Template
4411
+ * Read a file from the code interpreter
4333
4412
  */
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;
4413
+ read = async (params) => {
4414
+ return this.sandbox.dataApi.readFile(params);
4415
+ };
4352
4416
  /**
4353
- * Get data API client
4417
+ * Write a file to the code interpreter
4354
4418
  */
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;
4419
+ write = async (params) => {
4420
+ return this.sandbox.dataApi.writeFile(params);
4421
+ };
4422
+ };
4423
+ FileSystemOperations = class {
4424
+ sandbox;
4425
+ constructor(sandbox) {
4426
+ this.sandbox = sandbox;
4366
4427
  }
4367
4428
  /**
4368
- * Check sandbox health
4429
+ * List directory contents
4369
4430
  */
4370
- checkHealth = async (params) => {
4371
- return this.dataApi.checkHealth({
4372
- sandboxId: this.sandboxId,
4373
- config: params?.config
4374
- });
4431
+ list = async (params) => {
4432
+ return this.sandbox.dataApi.listDirectory(params);
4375
4433
  };
4376
4434
  /**
4377
- * Get CDP WebSocket URL for browser automation
4435
+ * Move a file or directory
4378
4436
  */
4379
- getCdpUrl(record) {
4380
- return this.dataApi.getCdpUrl(record);
4381
- }
4437
+ move = async (params) => {
4438
+ return this.sandbox.dataApi.moveFile(params);
4439
+ };
4382
4440
  /**
4383
- * Get VNC WebSocket URL for live view
4441
+ * Remove a file or directory
4384
4442
  */
4385
- getVncUrl(record) {
4386
- return this.dataApi.getVncUrl(record);
4387
- }
4443
+ remove = async (params) => {
4444
+ return this.sandbox.dataApi.removeFile(params);
4445
+ };
4388
4446
  /**
4389
- * List all recordings
4447
+ * Get file or directory statistics
4390
4448
  */
4391
- listRecordings = async (params) => {
4392
- return this.dataApi.listRecordings(params);
4449
+ stat = async (params) => {
4450
+ return this.sandbox.dataApi.stat(params);
4393
4451
  };
4394
4452
  /**
4395
- * Download a recording video file
4453
+ * Create a directory
4396
4454
  */
4397
- downloadRecording = async (params) => {
4398
- return this.dataApi.downloadRecording(params);
4455
+ mkdir = async (params) => {
4456
+ return this.sandbox.dataApi.mkdir(params);
4399
4457
  };
4400
4458
  /**
4401
- * Delete a recording
4459
+ * Upload a file to the code interpreter
4402
4460
  */
4403
- deleteRecording = async (params) => {
4404
- return this.dataApi.deleteRecording(params);
4461
+ upload = async (params) => {
4462
+ return this.sandbox.dataApi.uploadFile(params);
4463
+ };
4464
+ /**
4465
+ * Download a file from the code interpreter
4466
+ */
4467
+ download = async (params) => {
4468
+ return this.sandbox.dataApi.downloadFile(params);
4405
4469
  };
4406
4470
  };
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}`
4424
- });
4471
+ ProcessOperations = class {
4472
+ sandbox;
4473
+ constructor(sandbox) {
4474
+ this.sandbox = sandbox;
4425
4475
  }
4426
4476
  /**
4427
- * List directory contents
4477
+ * Execute a command in the code interpreter
4428
4478
  */
4429
- async listDirectory(params) {
4430
- const query = {};
4431
- if (params?.path !== void 0) {
4432
- query.path = params.path;
4433
- }
4434
- if (params?.depth !== void 0) {
4435
- query.depth = params.depth;
4436
- }
4437
- return this.get({ path: "/filesystem", query, config: params?.config });
4438
- }
4479
+ cmd = async (params) => {
4480
+ return this.sandbox.dataApi.cmd(params);
4481
+ };
4439
4482
  /**
4440
- * Get file/directory stats
4483
+ * List all processes
4441
4484
  */
4442
- async stat(params) {
4443
- const query = {
4444
- path: params.path
4445
- };
4446
- return this.get({ path: "/filesystem/stat", query, config: params.config });
4447
- }
4485
+ list = async (params) => {
4486
+ return this.sandbox.dataApi.listProcesses(params);
4487
+ };
4448
4488
  /**
4449
- * Create directory
4489
+ * Get a specific process by PID
4450
4490
  */
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 });
4491
+ get = async (params) => {
4492
+ return this.sandbox.dataApi.getProcess(params);
4493
+ };
4494
+ /**
4495
+ * Kill a specific process by PID
4496
+ */
4497
+ kill = async (params) => {
4498
+ return this.sandbox.dataApi.killProcess(params);
4499
+ };
4500
+ };
4501
+ ContextOperations = class {
4502
+ sandbox;
4503
+ _contextId;
4504
+ _language;
4505
+ _cwd;
4506
+ constructor(sandbox) {
4507
+ this.sandbox = sandbox;
4458
4508
  }
4459
4509
  /**
4460
- * Move file or directory
4510
+ * Get the current context ID
4461
4511
  */
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 });
4512
+ get contextId() {
4513
+ return this._contextId;
4468
4514
  }
4469
4515
  /**
4470
- * Remove file or directory
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
4530
+ });
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
+ };
4539
+ /**
4540
+ * Get a specific context by ID
4541
+ */
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");
4547
+ }
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;
4554
+ }
4555
+ throw new exports.ServerError(500, "Failed to get context");
4556
+ };
4557
+ /**
4558
+ * Execute code in a context
4559
+ */
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
+ };
4577
+ /**
4578
+ * Delete a context
4471
4579
  */
4472
- async removeFile(params) {
4473
- const data = {
4474
- path: params.path
4475
- };
4476
- return this.post({ path: "/filesystem/remove", data, config: params.config });
4477
- }
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 */;
4478
4594
  /**
4479
- * List code execution contexts
4595
+ * Create a Code Interpreter Sandbox from template
4596
+ * 从模板创建代码解释器沙箱 / Create Code Interpreter Sandbox from Template
4480
4597
  */
4481
- async listContexts(params) {
4482
- return this.get({ path: "/contexts", config: params?.config });
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;
4611
+ }
4612
+ constructor(sandbox, config2) {
4613
+ super(sandbox, config2);
4483
4614
  }
4615
+ _dataApi;
4616
+ _file;
4617
+ _fileSystem;
4618
+ _context;
4619
+ _process;
4484
4620
  /**
4485
- * Create a new code execution context
4621
+ * Get data API client
4486
4622
  */
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
- );
4623
+ get dataApi() {
4624
+ if (!this._dataApi) {
4625
+ this._dataApi = new exports.CodeInterpreterDataAPI({
4626
+ sandboxId: this.sandboxId || "",
4627
+ config: this._config
4628
+ });
4494
4629
  }
4495
- const data = {
4496
- cwd,
4497
- language
4498
- };
4499
- return this.post({ path: "/contexts", data, config: params?.config });
4630
+ return this._dataApi;
4500
4631
  }
4501
4632
  /**
4502
- * Get context details
4633
+ * Access file upload/download operations
4503
4634
  */
4504
- async getContext(params) {
4505
- return this.get({ path: `/contexts/${params.contextId}`, config: params.config });
4635
+ get file() {
4636
+ if (!this._file) {
4637
+ this._file = new FileOperations(this);
4638
+ }
4639
+ return this._file;
4506
4640
  }
4507
4641
  /**
4508
- * Execute code in a context
4642
+ * Access file system operations
4509
4643
  */
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
- );
4516
- }
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;
4644
+ get fileSystem() {
4645
+ if (!this._fileSystem) {
4646
+ this._fileSystem = new FileSystemOperations(this);
4528
4647
  }
4529
- return this.post({ path: "/contexts/execute", data, config: config2 });
4648
+ return this._fileSystem;
4530
4649
  }
4531
4650
  /**
4532
- * Delete a context
4651
+ * Access context management operations
4533
4652
  */
4534
- async deleteContext(params) {
4535
- return this.delete({ path: `/contexts/${params.contextId}`, config: params.config });
4653
+ get context() {
4654
+ if (!this._context) {
4655
+ this._context = new ContextOperations(this);
4656
+ }
4657
+ return this._context;
4536
4658
  }
4537
4659
  /**
4538
- * Read file contents
4660
+ * Access process management operations
4539
4661
  */
4540
- async readFile(params) {
4541
- const query = {
4542
- path: params.path
4543
- };
4544
- return this.get({ path: "/files", query, config: params.config });
4662
+ get process() {
4663
+ if (!this._process) {
4664
+ this._process = new ProcessOperations(this);
4665
+ }
4666
+ return this._process;
4545
4667
  }
4546
4668
  /**
4547
- * Write file contents
4669
+ * Check sandbox health
4548
4670
  */
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
- }
4671
+ checkHealth = async (params) => {
4672
+ return this.dataApi.checkHealth({
4673
+ sandboxId: this.sandboxId,
4674
+ config: params?.config
4675
+ });
4676
+ };
4559
4677
  /**
4560
- * Upload file to sandbox
4678
+ * Execute code (convenience method delegating to context.execute)
4561
4679
  */
4562
- async uploadFile(params) {
4563
- return this.postFile({
4564
- path: "/filesystem/upload",
4565
- localFilePath: params.localFilePath,
4566
- targetFilePath: params.targetFilePath,
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,
4567
4698
  config: params.config
4568
4699
  });
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,
4700
+ this.browserAPI = new exports.BrowserDataAPI({
4701
+ sandboxId: params.sandboxId,
4579
4702
  config: params.config
4580
4703
  });
4581
4704
  }
4705
+ // Browser API methods - delegate to browserAPI
4582
4706
  /**
4583
- * Execute shell command
4584
- */
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 });
4594
- }
4595
- /**
4596
- * List running processes
4707
+ * Get CDP WebSocket URL for browser automation
4597
4708
  */
4598
- async listProcesses(params) {
4599
- return this.get({ path: "/processes", config: params?.config });
4709
+ getCdpUrl(record) {
4710
+ return this.browserAPI.getCdpUrl(record);
4600
4711
  }
4601
4712
  /**
4602
- * Get process details
4713
+ * Get VNC WebSocket URL for live view
4603
4714
  */
4604
- async getProcess(params) {
4605
- return this.get({ path: `/processes/${params.pid}`, config: params.config });
4715
+ getVncUrl(record) {
4716
+ return this.browserAPI.getVncUrl(record);
4606
4717
  }
4607
4718
  /**
4608
- * Kill a process
4719
+ * List browser recordings
4609
4720
  */
4610
- async killProcess(params) {
4611
- return this.delete({ path: `/processes/${params.pid}`, config: params.config });
4612
- }
4721
+ listRecordings = async (params) => {
4722
+ return this.browserAPI.listRecordings(params);
4723
+ };
4613
4724
  /**
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
- }
4725
+ * Delete a recording
4726
+ */
4727
+ deleteRecording = async (params) => {
4728
+ return this.browserAPI.deleteRecording(params);
4729
+ };
4654
4730
  /**
4655
- * Helper method to download file
4731
+ * Download a recording
4656
4732
  */
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
- }
4733
+ downloadRecording = async (params) => {
4734
+ return this.browserAPI.downloadRecording(params);
4735
+ };
4686
4736
  };
4687
4737
  }
4688
4738
  });
4689
4739
 
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"() {
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"() {
4694
4752
  init_log();
4695
4753
  init_exception();
4696
- init_code_interpreter_data();
4754
+ init_aio_data();
4697
4755
  init_model4();
4698
4756
  init_sandbox();
4699
- FileOperations = class {
4757
+ AioFileOperations = class {
4700
4758
  sandbox;
4701
4759
  constructor(sandbox) {
4702
4760
  this.sandbox = sandbox;
4703
4761
  }
4704
4762
  /**
4705
- * Read a file from the code interpreter
4763
+ * Read a file from the sandbox
4706
4764
  */
4707
- read = async (params) => {
4708
- return this.sandbox.dataApi.readFile(params);
4765
+ read = async (path2) => {
4766
+ return this.sandbox.dataApi.readFile({ path: path2 });
4709
4767
  };
4710
4768
  /**
4711
- * Write a file to the code interpreter
4769
+ * Write a file to the sandbox
4712
4770
  */
4713
4771
  write = async (params) => {
4714
4772
  return this.sandbox.dataApi.writeFile(params);
4715
4773
  };
4716
4774
  };
4717
- FileSystemOperations = class {
4775
+ AioFileSystemOperations = class {
4718
4776
  sandbox;
4719
4777
  constructor(sandbox) {
4720
4778
  this.sandbox = sandbox;
@@ -4750,25 +4808,25 @@ var init_code_interpreter_sandbox = __esm({
4750
4808
  return this.sandbox.dataApi.mkdir(params);
4751
4809
  };
4752
4810
  /**
4753
- * Upload a file to the code interpreter
4811
+ * Upload a file to the sandbox
4754
4812
  */
4755
4813
  upload = async (params) => {
4756
4814
  return this.sandbox.dataApi.uploadFile(params);
4757
4815
  };
4758
4816
  /**
4759
- * Download a file from the code interpreter
4817
+ * Download a file from the sandbox
4760
4818
  */
4761
4819
  download = async (params) => {
4762
4820
  return this.sandbox.dataApi.downloadFile(params);
4763
4821
  };
4764
4822
  };
4765
- ProcessOperations = class {
4823
+ AioProcessOperations = class {
4766
4824
  sandbox;
4767
4825
  constructor(sandbox) {
4768
4826
  this.sandbox = sandbox;
4769
4827
  }
4770
4828
  /**
4771
- * Execute a command in the code interpreter
4829
+ * Execute a command in the sandbox
4772
4830
  */
4773
4831
  cmd = async (params) => {
4774
4832
  return this.sandbox.dataApi.cmd(params);
@@ -4792,7 +4850,7 @@ var init_code_interpreter_sandbox = __esm({
4792
4850
  return this.sandbox.dataApi.killProcess(params);
4793
4851
  };
4794
4852
  };
4795
- ContextOperations = class {
4853
+ AioContextOperations = class {
4796
4854
  sandbox;
4797
4855
  _contextId;
4798
4856
  _language;
@@ -4883,11 +4941,11 @@ var init_code_interpreter_sandbox = __esm({
4883
4941
  return result;
4884
4942
  };
4885
4943
  };
4886
- exports.CodeInterpreterSandbox = class _CodeInterpreterSandbox extends exports.Sandbox {
4887
- static templateType = "CodeInterpreter" /* CODE_INTERPRETER */;
4944
+ exports.AioSandbox = class _AioSandbox extends exports.Sandbox {
4945
+ static templateType = "AllInOne" /* AIO */;
4888
4946
  /**
4889
- * Create a Code Interpreter Sandbox from template
4890
- * 从模板创建代码解释器沙箱 / Create Code Interpreter Sandbox from Template
4947
+ * Create an AIO Sandbox from template
4948
+ * 从模板创建 AIO 沙箱 / Create AIO Sandbox from Template
4891
4949
  */
4892
4950
  static async createFromTemplate(templateName, options, config2) {
4893
4951
  const sandbox = await exports.Sandbox.create(
@@ -4900,8 +4958,8 @@ var init_code_interpreter_sandbox = __esm({
4900
4958
  },
4901
4959
  config2
4902
4960
  );
4903
- const ciSandbox = new _CodeInterpreterSandbox(sandbox, config2);
4904
- return ciSandbox;
4961
+ const aioSandbox = new _AioSandbox(sandbox, config2);
4962
+ return aioSandbox;
4905
4963
  }
4906
4964
  constructor(sandbox, config2) {
4907
4965
  super(sandbox, config2);
@@ -4916,512 +4974,446 @@ var init_code_interpreter_sandbox = __esm({
4916
4974
  */
4917
4975
  get dataApi() {
4918
4976
  if (!this._dataApi) {
4919
- this._dataApi = new exports.CodeInterpreterDataAPI({
4977
+ this._dataApi = new exports.AioDataAPI({
4920
4978
  sandboxId: this.sandboxId || "",
4921
4979
  config: this._config
4922
4980
  });
4923
4981
  }
4924
- return this._dataApi;
4925
- }
4926
- /**
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 });
4982
+ return this._dataApi;
5088
4983
  }
5089
4984
  /**
5090
- * Get a Template by name
4985
+ * Access file upload/download operations
5091
4986
  */
5092
- static async get(params) {
5093
- const { name, config: config2 } = params;
5094
- return await _Template.getClient().getTemplate({ name, config: config2 });
4987
+ get file() {
4988
+ if (!this._file) {
4989
+ this._file = new AioFileOperations(this);
4990
+ }
4991
+ return this._file;
5095
4992
  }
5096
4993
  /**
5097
- * List Templates
4994
+ * Access file system operations
5098
4995
  */
5099
- static async list(params) {
5100
- const { input, config: config2 } = params ?? {};
5101
- return await _Template.getClient().listTemplates({ input, config: config2 });
4996
+ get fileSystem() {
4997
+ if (!this._fileSystem) {
4998
+ this._fileSystem = new AioFileSystemOperations(this);
4999
+ }
5000
+ return this._fileSystem;
5102
5001
  }
5103
5002
  /**
5104
- * List all Templates (with pagination)
5105
- */
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
- };
5113
- /**
5114
- * Delete this template
5003
+ * Access context management operations
5115
5004
  */
5116
- delete = async (params) => {
5117
- const config2 = params?.config;
5118
- if (!this.templateName) {
5119
- throw new Error("templateName is required to delete a Template");
5005
+ get context() {
5006
+ if (!this._context) {
5007
+ this._context = new AioContextOperations(this);
5120
5008
  }
5121
- const result = await _Template.delete({
5122
- name: this.templateName,
5123
- config: config2 ?? this._config
5124
- });
5125
- updateObjectProperties(this, result);
5126
- return this;
5127
- };
5009
+ return this._context;
5010
+ }
5128
5011
  /**
5129
- * Update this template
5012
+ * Access process management operations
5130
5013
  */
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");
5014
+ get process() {
5015
+ if (!this._process) {
5016
+ this._process = new AioProcessOperations(this);
5135
5017
  }
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
- };
5018
+ return this._process;
5019
+ }
5144
5020
  /**
5145
- * Refresh this template's data
5021
+ * Check sandbox health
5146
5022
  */
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
5023
+ checkHealth = async (params) => {
5024
+ return this.dataApi.checkHealth({
5025
+ sandboxId: this.sandboxId,
5026
+ config: params?.config
5155
5027
  });
5156
- updateObjectProperties(this, result);
5157
- return this;
5158
5028
  };
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
5029
+ // ========================================
5030
+ // Browser API Methods
5031
+ // ========================================
5182
5032
  /**
5183
5033
  * Get CDP WebSocket URL for browser automation
5184
5034
  */
5185
5035
  getCdpUrl(record) {
5186
- return this.browserAPI.getCdpUrl(record);
5036
+ return this.dataApi.getCdpUrl(record);
5187
5037
  }
5188
5038
  /**
5189
5039
  * Get VNC WebSocket URL for live view
5190
5040
  */
5191
5041
  getVncUrl(record) {
5192
- return this.browserAPI.getVncUrl(record);
5042
+ return this.dataApi.getVncUrl(record);
5193
5043
  }
5194
5044
  /**
5195
- * List browser recordings
5045
+ * List all browser recordings
5196
5046
  */
5197
5047
  listRecordings = async (params) => {
5198
- return this.browserAPI.listRecordings(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);
5199
5055
  };
5200
5056
  /**
5201
5057
  * Delete a recording
5202
5058
  */
5203
5059
  deleteRecording = async (params) => {
5204
- return this.browserAPI.deleteRecording(params);
5060
+ return this.dataApi.deleteRecording(params);
5205
5061
  };
5062
+ // ========================================
5063
+ // Code Interpreter API Methods
5064
+ // ========================================
5206
5065
  /**
5207
- * Download a recording
5066
+ * Execute code (convenience method delegating to context.execute)
5208
5067
  */
5209
- downloadRecording = async (params) => {
5210
- return this.browserAPI.downloadRecording(params);
5068
+ execute = async (params) => {
5069
+ return this.context.execute(params);
5211
5070
  };
5212
5071
  };
5213
5072
  }
5214
5073
  });
5215
5074
 
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
5075
+ // src/sandbox/custom-sandbox.ts
5076
+ var custom_sandbox_exports = {};
5077
+ __export(custom_sandbox_exports, {
5078
+ CustomSandbox: () => CustomSandbox
5224
5079
  });
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();
5080
+ var CustomSandbox;
5081
+ var init_custom_sandbox = __esm({
5082
+ "src/sandbox/custom-sandbox.ts"() {
5083
+ init_config();
5231
5084
  init_model4();
5232
5085
  init_sandbox();
5233
- AioFileOperations = class {
5234
- sandbox;
5235
- constructor(sandbox) {
5236
- this.sandbox = 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;
5237
5106
  }
5107
+ constructor(sandbox, config2) {
5108
+ super(sandbox, config2);
5109
+ }
5110
+ _dataApi;
5238
5111
  /**
5239
- * Read a file from the sandbox
5112
+ * Get data API client
5240
5113
  */
5241
- read = async (path2) => {
5242
- return this.sandbox.dataApi.readFile({ path: path2 });
5243
- };
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
+ }
5244
5123
  /**
5245
- * Write a file to the sandbox
5124
+ * Get base URL for the sandbox
5125
+ * 获取沙箱的基础 URL / Get base URL for the sandbox
5126
+ *
5127
+ * @returns 基础 URL / Base URL
5246
5128
  */
5247
- write = async (params) => {
5248
- return this.sandbox.dataApi.writeFile(params);
5249
- };
5250
- };
5251
- AioFileSystemOperations = class {
5252
- sandbox;
5253
- constructor(sandbox) {
5254
- this.sandbox = sandbox;
5129
+ getBaseUrl() {
5130
+ const cfg = exports.Config.withConfigs(this._config);
5131
+ return `${cfg.dataEndpoint}/sandboxes/${this.sandboxId}`;
5255
5132
  }
5133
+ };
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;
5256
5148
  /**
5257
- * List directory contents
5149
+ * 沙箱 ID / Sandbox ID
5258
5150
  */
5259
- list = async (params) => {
5260
- return this.sandbox.dataApi.listDirectory(params);
5261
- };
5151
+ sandboxId;
5262
5152
  /**
5263
- * Move a file or directory
5153
+ * 沙箱名称 / Sandbox Name
5264
5154
  */
5265
- move = async (params) => {
5266
- return this.sandbox.dataApi.moveFile(params);
5267
- };
5155
+ sandboxName;
5268
5156
  /**
5269
- * Remove a file or directory
5157
+ * 模板 ID / Template ID
5270
5158
  */
5271
- remove = async (params) => {
5272
- return this.sandbox.dataApi.removeFile(params);
5273
- };
5159
+ templateId;
5274
5160
  /**
5275
- * Get file or directory statistics
5161
+ * 模板名称 / Template Name
5276
5162
  */
5277
- stat = async (params) => {
5278
- return this.sandbox.dataApi.stat(params);
5279
- };
5163
+ templateName;
5164
+ /**
5165
+ * 沙箱状态 / Sandbox State
5166
+ */
5167
+ state;
5168
+ /**
5169
+ * 状态原因 / State Reason
5170
+ */
5171
+ stateReason;
5172
+ /**
5173
+ * 沙箱创建时间 / Sandbox Creation Time
5174
+ */
5175
+ createdAt;
5176
+ /**
5177
+ * 最后更新时间 / Last Updated Time
5178
+ */
5179
+ lastUpdatedAt;
5180
+ /**
5181
+ * 沙箱空闲超时时间(秒) / Sandbox Idle Timeout (seconds)
5182
+ */
5183
+ sandboxIdleTimeoutSeconds;
5184
+ /**
5185
+ * 沙箱结束时间 / Sandbox End Time
5186
+ */
5187
+ endedAt;
5280
5188
  /**
5281
- * Create a directory
5189
+ * 元数据 / Metadata
5282
5190
  */
5283
- mkdir = async (params) => {
5284
- return this.sandbox.dataApi.mkdir(params);
5285
- };
5191
+ metadata;
5286
5192
  /**
5287
- * Upload a file to the sandbox
5193
+ * 沙箱全局唯一资源名称 / Sandbox ARN
5288
5194
  */
5289
- upload = async (params) => {
5290
- return this.sandbox.dataApi.uploadFile(params);
5291
- };
5195
+ sandboxArn;
5292
5196
  /**
5293
- * Download a file from the sandbox
5197
+ * 沙箱空闲 TTL(秒) / Sandbox Idle TTL (seconds)
5294
5198
  */
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;
5199
+ sandboxIdleTTLInSeconds;
5200
+ _config;
5201
+ constructor(data, config2) {
5202
+ super();
5203
+ if (data) {
5204
+ updateObjectProperties(this, data);
5205
+ }
5206
+ this._config = config2;
5303
5207
  }
5304
5208
  /**
5305
- * Execute a command in the sandbox
5209
+ * Create sandbox from SDK response object
5210
+ * 从 SDK 响应对象创建沙箱 / Create Sandbox from SDK Response Object
5306
5211
  */
5307
- cmd = async (params) => {
5308
- return this.sandbox.dataApi.cmd(params);
5309
- };
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
+ }
5310
5238
  /**
5311
- * List all processes
5239
+ * Create a new Sandbox
5240
+ * 创建新沙箱 / Create a New Sandbox
5312
5241
  */
5313
- list = async (params) => {
5314
- return this.sandbox.dataApi.listProcesses(params);
5315
- };
5242
+ static async create(input, config2) {
5243
+ return await _Sandbox.getClient().createSandbox({ input, config: config2 });
5244
+ }
5316
5245
  /**
5317
- * Get a specific process by PID
5246
+ * Delete a Sandbox by ID
5318
5247
  */
5319
- get = async (params) => {
5320
- return this.sandbox.dataApi.getProcess(params);
5321
- };
5248
+ static async delete(params) {
5249
+ const { id, config: config2 } = params;
5250
+ return await _Sandbox.getClient().deleteSandbox({ id, config: config2 });
5251
+ }
5322
5252
  /**
5323
- * Kill a specific process by PID
5253
+ * Stop a Sandbox by ID
5324
5254
  */
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;
5255
+ static async stop(params) {
5256
+ const { id, config: config2 } = params;
5257
+ return await _Sandbox.getClient().stopSandbox({ id, config: config2 });
5336
5258
  }
5337
5259
  /**
5338
- * Get the current context ID
5260
+ * Get a Sandbox by ID
5339
5261
  */
5340
- get contextId() {
5341
- return this._contextId;
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
+ }
5342
5313
  }
5343
5314
  /**
5344
- * List all contexts
5315
+ * List Sandboxes
5345
5316
  */
5346
- list = async (params) => {
5347
- return this.sandbox.dataApi.listContexts(params);
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
+ });
5348
5327
  };
5349
5328
  /**
5350
- * Create a new context and save its ID
5329
+ * Delete this sandbox
5351
5330
  */
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
5358
- });
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;
5331
+ delete = async (params) => {
5332
+ const config2 = params?.config;
5333
+ if (!this.sandboxId) {
5334
+ throw new Error("sandboxId is required to delete a Sandbox");
5364
5335
  }
5365
- throw new exports.ServerError(500, "Failed to create context");
5336
+ const result = await _Sandbox.delete({
5337
+ id: this.sandboxId,
5338
+ config: config2 ?? this._config
5339
+ });
5340
+ updateObjectProperties(this, result);
5341
+ return this;
5366
5342
  };
5367
5343
  /**
5368
- * Get a specific context by ID
5344
+ * Stop this sandbox
5369
5345
  */
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");
5375
- }
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;
5346
+ stop = async (params) => {
5347
+ const config2 = params?.config;
5348
+ if (!this.sandboxId) {
5349
+ throw new Error("sandboxId is required to stop a Sandbox");
5382
5350
  }
5383
- throw new exports.ServerError(500, "Failed to get context");
5351
+ const result = await _Sandbox.stop({
5352
+ id: this.sandboxId,
5353
+ config: config2 ?? this._config
5354
+ });
5355
+ updateObjectProperties(this, result);
5356
+ return this;
5384
5357
  };
5385
5358
  /**
5386
- * Execute code in a context
5359
+ * Refresh this sandbox's data
5387
5360
  */
5388
- execute = async (params) => {
5389
- const { code, timeout = 30 } = params;
5390
- let { contextId, language } = params;
5391
- if (!contextId) {
5392
- contextId = this._contextId;
5393
- }
5394
- if (!contextId && !language) {
5395
- logger.debug("context id is not set, use default language: python");
5396
- language = "python" /* PYTHON */;
5361
+ refresh = async (params) => {
5362
+ const config2 = params?.config;
5363
+ if (!this.sandboxId) {
5364
+ throw new Error("sandboxId is required to refresh a Sandbox");
5397
5365
  }
5398
- return this.sandbox.dataApi.executeCode({
5399
- code,
5400
- contextId,
5401
- language,
5402
- timeout
5366
+ const result = await _Sandbox.get({
5367
+ id: this.sandboxId,
5368
+ config: config2 ?? this._config
5403
5369
  });
5370
+ updateObjectProperties(this, result);
5371
+ return this;
5404
5372
  };
5405
5373
  /**
5406
- * Delete a context
5374
+ * Wait until the sandbox is running
5407
5375
  */
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
- );
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));
5414
5392
  }
5415
- const result = await this.sandbox.dataApi.deleteContext({ contextId: id });
5416
- this._contextId = void 0;
5417
- return result;
5393
+ throw new Error(
5394
+ `Timeout waiting for Sandbox to be running after ${options?.timeoutSeconds ?? 300} seconds`
5395
+ );
5418
5396
  };
5419
5397
  };
5420
- exports.AioSandbox = class _AioSandbox extends exports.Sandbox {
5421
- static templateType = "AllInOne" /* AIO */;
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 */;
5422
5414
  /**
5423
- * Create an AIO Sandbox from template
5424
- * 从模板创建 AIO 沙箱 / Create AIO Sandbox from Template
5415
+ * Create a Browser Sandbox from template
5416
+ * 从模板创建浏览器沙箱 / Create Browser Sandbox from Template
5425
5417
  */
5426
5418
  static async createFromTemplate(templateName, options, config2) {
5427
5419
  const sandbox = await exports.Sandbox.create(
@@ -5434,65 +5426,28 @@ var init_aio_sandbox = __esm({
5434
5426
  },
5435
5427
  config2
5436
5428
  );
5437
- const aioSandbox = new _AioSandbox(sandbox, config2);
5438
- return aioSandbox;
5429
+ const browserSandbox = new _BrowserSandbox(sandbox, config2);
5430
+ return browserSandbox;
5439
5431
  }
5440
5432
  constructor(sandbox, config2) {
5441
5433
  super(sandbox, config2);
5442
5434
  }
5443
5435
  _dataApi;
5444
- _file;
5445
- _fileSystem;
5446
- _context;
5447
- _process;
5448
5436
  /**
5449
5437
  * Get data API client
5450
5438
  */
5451
5439
  get dataApi() {
5452
5440
  if (!this._dataApi) {
5453
- this._dataApi = new exports.AioDataAPI({
5454
- sandboxId: this.sandboxId || "",
5441
+ if (!this.sandboxId) {
5442
+ throw new Error("Sandbox ID is not set");
5443
+ }
5444
+ this._dataApi = new exports.BrowserDataAPI({
5445
+ sandboxId: this.sandboxId,
5455
5446
  config: this._config
5456
5447
  });
5457
5448
  }
5458
5449
  return this._dataApi;
5459
5450
  }
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
- }
5496
5451
  /**
5497
5452
  * Check sandbox health
5498
5453
  */
@@ -5502,9 +5457,6 @@ var init_aio_sandbox = __esm({
5502
5457
  config: params?.config
5503
5458
  });
5504
5459
  };
5505
- // ========================================
5506
- // Browser API Methods
5507
- // ========================================
5508
5460
  /**
5509
5461
  * Get CDP WebSocket URL for browser automation
5510
5462
  */
@@ -5518,7 +5470,7 @@ var init_aio_sandbox = __esm({
5518
5470
  return this.dataApi.getVncUrl(record);
5519
5471
  }
5520
5472
  /**
5521
- * List all browser recordings
5473
+ * List all recordings
5522
5474
  */
5523
5475
  listRecordings = async (params) => {
5524
5476
  return this.dataApi.listRecordings(params);
@@ -5535,14 +5487,187 @@ var init_aio_sandbox = __esm({
5535
5487
  deleteRecording = async (params) => {
5536
5488
  return this.dataApi.deleteRecording(params);
5537
5489
  };
5538
- // ========================================
5539
- // Code Interpreter API Methods
5540
- // ========================================
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 {
5541
5500
  /**
5542
- * Execute code (convenience method delegating to context.execute)
5501
+ * 模板 ARN / Template ARN
5543
5502
  */
5544
- execute = async (params) => {
5545
- return this.context.execute(params);
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
+ };
5657
+ /**
5658
+ * Refresh this template's data
5659
+ */
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;
5546
5671
  };
5547
5672
  };
5548
5673
  }
@@ -5673,7 +5798,7 @@ var init_client3 = __esm({
5673
5798
  input: request,
5674
5799
  config: cfg
5675
5800
  });
5676
- return (result.items || []).map((item) => new exports.Template(item, cfg));
5801
+ return (result?.items || []).map((item) => new exports.Template(item, cfg));
5677
5802
  };
5678
5803
  // ============ Sandbox Operations ============
5679
5804
  /**
@@ -8522,6 +8647,7 @@ init_template();
8522
8647
  init_code_interpreter_sandbox();
8523
8648
  init_browser_sandbox();
8524
8649
  init_aio_sandbox();
8650
+ init_custom_sandbox();
8525
8651
  init_sandbox_data();
8526
8652
  init_code_interpreter_data();
8527
8653
  init_browser_data();