@agentrun/sdk 0.0.3-test.21440027550 → 0.0.3-test.21470120979

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
@@ -3918,7 +3918,7 @@ var init_sandbox_data = __esm({
3918
3918
  });
3919
3919
  const data = {
3920
3920
  templateName: params.templateName,
3921
- sandboxIdleTimeoutInSeconds: params.sandboxIdleTimeoutInSeconds || 600
3921
+ sandboxIdleTimeoutSeconds: params.sandboxIdleTimeoutSeconds || 600
3922
3922
  };
3923
3923
  if (params.nasConfig !== void 0) {
3924
3924
  data.nasConfig = params.nasConfig;
@@ -4078,14 +4078,14 @@ var init_model4 = __esm({
4078
4078
  TemplateType2["CUSTOM"] = "CustomImage";
4079
4079
  return TemplateType2;
4080
4080
  })(exports.TemplateType || {});
4081
- exports.SandboxState = /* @__PURE__ */ ((SandboxState2) => {
4082
- SandboxState2["CREATING"] = "Creating";
4083
- SandboxState2["RUNNING"] = "Running";
4084
- SandboxState2["READY"] = "READY";
4085
- SandboxState2["STOPPED"] = "Stopped";
4086
- SandboxState2["FAILED"] = "Failed";
4087
- SandboxState2["DELETING"] = "Deleting";
4088
- return SandboxState2;
4081
+ exports.SandboxState = /* @__PURE__ */ ((SandboxState3) => {
4082
+ SandboxState3["CREATING"] = "Creating";
4083
+ SandboxState3["RUNNING"] = "Running";
4084
+ SandboxState3["READY"] = "READY";
4085
+ SandboxState3["STOPPED"] = "Stopped";
4086
+ SandboxState3["FAILED"] = "Failed";
4087
+ SandboxState3["DELETING"] = "Deleting";
4088
+ return SandboxState3;
4089
4089
  })(exports.SandboxState || {});
4090
4090
  exports.TemplateNetworkMode = /* @__PURE__ */ ((TemplateNetworkMode2) => {
4091
4091
  TemplateNetworkMode2["PUBLIC"] = "PUBLIC";
@@ -4100,6 +4100,7 @@ var init_model4 = __esm({
4100
4100
  })(exports.TemplateOSSPermission || {});
4101
4101
  exports.CodeLanguage = /* @__PURE__ */ ((CodeLanguage2) => {
4102
4102
  CodeLanguage2["PYTHON"] = "python";
4103
+ CodeLanguage2["JAVASCRIPT"] = "javascript";
4103
4104
  return CodeLanguage2;
4104
4105
  })(exports.CodeLanguage || {});
4105
4106
  }
@@ -4385,6 +4386,59 @@ var init_code_interpreter_data = __esm({
4385
4386
  }
4386
4387
  });
4387
4388
 
4389
+ // src/sandbox/api/aio-data.ts
4390
+ exports.AioDataAPI = void 0;
4391
+ var init_aio_data = __esm({
4392
+ "src/sandbox/api/aio-data.ts"() {
4393
+ init_browser_data();
4394
+ init_code_interpreter_data();
4395
+ exports.AioDataAPI = class extends exports.CodeInterpreterDataAPI {
4396
+ browserAPI;
4397
+ constructor(params) {
4398
+ super({
4399
+ sandboxId: params.sandboxId,
4400
+ config: params.config
4401
+ });
4402
+ this.browserAPI = new exports.BrowserDataAPI({
4403
+ sandboxId: params.sandboxId,
4404
+ config: params.config
4405
+ });
4406
+ }
4407
+ // Browser API methods - delegate to browserAPI
4408
+ /**
4409
+ * Get CDP WebSocket URL for browser automation
4410
+ */
4411
+ getCdpUrl(record) {
4412
+ return this.browserAPI.getCdpUrl(record);
4413
+ }
4414
+ /**
4415
+ * Get VNC WebSocket URL for live view
4416
+ */
4417
+ getVncUrl(record) {
4418
+ return this.browserAPI.getVncUrl(record);
4419
+ }
4420
+ /**
4421
+ * List browser recordings
4422
+ */
4423
+ listRecordings = async (params) => {
4424
+ return this.browserAPI.listRecordings(params);
4425
+ };
4426
+ /**
4427
+ * Delete a recording
4428
+ */
4429
+ deleteRecording = async (params) => {
4430
+ return this.browserAPI.deleteRecording(params);
4431
+ };
4432
+ /**
4433
+ * Download a recording
4434
+ */
4435
+ downloadRecording = async (params) => {
4436
+ return this.browserAPI.downloadRecording(params);
4437
+ };
4438
+ };
4439
+ }
4440
+ });
4441
+
4388
4442
  // src/sandbox/code-interpreter-sandbox.ts
4389
4443
  var code_interpreter_sandbox_exports = {};
4390
4444
  __export(code_interpreter_sandbox_exports, {
@@ -4589,25 +4643,25 @@ var init_code_interpreter_sandbox = __esm({
4589
4643
  return result;
4590
4644
  };
4591
4645
  };
4592
- exports.CodeInterpreterSandbox = class _CodeInterpreterSandbox extends exports.Sandbox {
4646
+ exports.CodeInterpreterSandbox = class extends exports.Sandbox {
4593
4647
  static templateType = "CodeInterpreter" /* CODE_INTERPRETER */;
4594
4648
  /**
4595
4649
  * Create a Code Interpreter Sandbox from template
4596
4650
  * 从模板创建代码解释器沙箱 / Create Code Interpreter Sandbox from Template
4597
4651
  */
4598
4652
  static async createFromTemplate(templateName, options, config2) {
4599
- const sandbox = await exports.Sandbox.create(
4600
- {
4653
+ const sandbox = await exports.Sandbox.create({
4654
+ input: {
4601
4655
  templateName,
4602
- sandboxIdleTimeoutInSeconds: options?.sandboxIdleTimeoutInSeconds,
4656
+ sandboxIdleTimeoutSeconds: options?.sandboxIdleTimeoutSeconds,
4603
4657
  nasConfig: options?.nasConfig,
4604
4658
  ossMountConfig: options?.ossMountConfig,
4605
4659
  polarFsConfig: options?.polarFsConfig
4606
4660
  },
4607
- config2
4608
- );
4609
- const ciSandbox = new _CodeInterpreterSandbox(sandbox, config2);
4610
- return ciSandbox;
4661
+ templateType: "CodeInterpreter" /* CODE_INTERPRETER */,
4662
+ config: config2
4663
+ });
4664
+ return sandbox;
4611
4665
  }
4612
4666
  constructor(sandbox, config2) {
4613
4667
  super(sandbox, config2);
@@ -4684,477 +4738,182 @@ var init_code_interpreter_sandbox = __esm({
4684
4738
  }
4685
4739
  });
4686
4740
 
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"() {
4741
+ // src/sandbox/browser-sandbox.ts
4742
+ var browser_sandbox_exports = {};
4743
+ __export(browser_sandbox_exports, {
4744
+ BrowserSandbox: () => exports.BrowserSandbox
4745
+ });
4746
+ exports.BrowserSandbox = void 0;
4747
+ var init_browser_sandbox = __esm({
4748
+ "src/sandbox/browser-sandbox.ts"() {
4691
4749
  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,
4698
- config: params.config
4699
- });
4700
- this.browserAPI = new exports.BrowserDataAPI({
4701
- sandboxId: params.sandboxId,
4702
- config: params.config
4750
+ init_model4();
4751
+ init_sandbox();
4752
+ exports.BrowserSandbox = class extends exports.Sandbox {
4753
+ static templateType = "Browser" /* BROWSER */;
4754
+ /**
4755
+ * Create a Browser Sandbox from template
4756
+ * 从模板创建浏览器沙箱 / Create Browser Sandbox from Template
4757
+ */
4758
+ static async createFromTemplate(templateName, options, config2) {
4759
+ const sandbox = await exports.Sandbox.create({
4760
+ input: {
4761
+ templateName,
4762
+ sandboxIdleTimeoutSeconds: options?.sandboxIdleTimeoutSeconds,
4763
+ nasConfig: options?.nasConfig,
4764
+ ossMountConfig: options?.ossMountConfig,
4765
+ polarFsConfig: options?.polarFsConfig
4766
+ },
4767
+ templateType: "Browser" /* BROWSER */,
4768
+ config: config2
4703
4769
  });
4770
+ return sandbox;
4704
4771
  }
4705
- // Browser API methods - delegate to browserAPI
4772
+ constructor(sandbox, config2) {
4773
+ super(sandbox, config2);
4774
+ }
4775
+ _dataApi;
4776
+ /**
4777
+ * Get data API client
4778
+ */
4779
+ get dataApi() {
4780
+ if (!this._dataApi) {
4781
+ if (!this.sandboxId) {
4782
+ throw new Error("Sandbox ID is not set");
4783
+ }
4784
+ this._dataApi = new exports.BrowserDataAPI({
4785
+ sandboxId: this.sandboxId,
4786
+ config: this._config
4787
+ });
4788
+ }
4789
+ return this._dataApi;
4790
+ }
4791
+ /**
4792
+ * Check sandbox health
4793
+ */
4794
+ checkHealth = async (params) => {
4795
+ return this.dataApi.checkHealth({
4796
+ sandboxId: this.sandboxId,
4797
+ config: params?.config
4798
+ });
4799
+ };
4706
4800
  /**
4707
4801
  * Get CDP WebSocket URL for browser automation
4708
4802
  */
4709
4803
  getCdpUrl(record) {
4710
- return this.browserAPI.getCdpUrl(record);
4804
+ return this.dataApi.getCdpUrl(record);
4711
4805
  }
4712
4806
  /**
4713
4807
  * Get VNC WebSocket URL for live view
4714
4808
  */
4715
4809
  getVncUrl(record) {
4716
- return this.browserAPI.getVncUrl(record);
4810
+ return this.dataApi.getVncUrl(record);
4717
4811
  }
4718
4812
  /**
4719
- * List browser recordings
4813
+ * List all recordings
4720
4814
  */
4721
4815
  listRecordings = async (params) => {
4722
- return this.browserAPI.listRecordings(params);
4816
+ return this.dataApi.listRecordings(params);
4723
4817
  };
4724
4818
  /**
4725
- * Delete a recording
4819
+ * Download a recording video file
4726
4820
  */
4727
- deleteRecording = async (params) => {
4728
- return this.browserAPI.deleteRecording(params);
4821
+ downloadRecording = async (params) => {
4822
+ return this.dataApi.downloadRecording(params);
4729
4823
  };
4730
4824
  /**
4731
- * Download a recording
4825
+ * Delete a recording
4732
4826
  */
4733
- downloadRecording = async (params) => {
4734
- return this.browserAPI.downloadRecording(params);
4827
+ deleteRecording = async (params) => {
4828
+ return this.dataApi.deleteRecording(params);
4735
4829
  };
4736
4830
  };
4737
4831
  }
4738
4832
  });
4739
4833
 
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
4834
+ // src/sandbox/custom-sandbox.ts
4835
+ var custom_sandbox_exports = {};
4836
+ __export(custom_sandbox_exports, {
4837
+ CustomSandbox: () => CustomSandbox
4748
4838
  });
4749
- var AioFileOperations, AioFileSystemOperations, AioProcessOperations, AioContextOperations; exports.AioSandbox = void 0;
4750
- var init_aio_sandbox = __esm({
4751
- "src/sandbox/aio-sandbox.ts"() {
4752
- init_log();
4753
- init_exception();
4754
- init_aio_data();
4839
+ var CustomSandbox;
4840
+ var init_custom_sandbox = __esm({
4841
+ "src/sandbox/custom-sandbox.ts"() {
4842
+ init_config();
4755
4843
  init_model4();
4756
4844
  init_sandbox();
4757
- AioFileOperations = class {
4758
- sandbox;
4759
- constructor(sandbox) {
4760
- this.sandbox = sandbox;
4761
- }
4845
+ init_sandbox_data();
4846
+ CustomSandbox = class extends exports.Sandbox {
4847
+ static templateType = "CustomImage" /* CUSTOM */;
4762
4848
  /**
4763
- * Read a file from the sandbox
4849
+ * Create a Custom Sandbox from template
4850
+ * 从模板创建自定义沙箱 / Create Custom Sandbox from Template
4764
4851
  */
4765
- read = async (path2) => {
4766
- return this.sandbox.dataApi.readFile({ path: path2 });
4767
- };
4852
+ static async createFromTemplate(templateName, options, config2) {
4853
+ return await exports.Sandbox.create({
4854
+ input: {
4855
+ templateName,
4856
+ sandboxIdleTimeoutSeconds: options?.sandboxIdleTimeoutSeconds,
4857
+ nasConfig: options?.nasConfig,
4858
+ ossMountConfig: options?.ossMountConfig,
4859
+ polarFsConfig: options?.polarFsConfig
4860
+ },
4861
+ templateType: "CustomImage" /* CUSTOM */,
4862
+ config: config2
4863
+ });
4864
+ }
4865
+ constructor(sandbox, config2) {
4866
+ super(sandbox, config2);
4867
+ }
4868
+ _dataApi;
4768
4869
  /**
4769
- * Write a file to the sandbox
4870
+ * Get data API client
4770
4871
  */
4771
- write = async (params) => {
4772
- return this.sandbox.dataApi.writeFile(params);
4773
- };
4774
- };
4775
- AioFileSystemOperations = class {
4776
- sandbox;
4777
- constructor(sandbox) {
4778
- this.sandbox = sandbox;
4872
+ get dataApi() {
4873
+ if (!this._dataApi) {
4874
+ this._dataApi = new exports.SandboxDataAPI({
4875
+ sandboxId: this.sandboxId || "",
4876
+ config: this._config
4877
+ });
4878
+ }
4879
+ return this._dataApi;
4779
4880
  }
4780
4881
  /**
4781
- * List directory contents
4882
+ * Get base URL for the sandbox
4883
+ * 获取沙箱的基础 URL / Get base URL for the sandbox
4884
+ *
4885
+ * @returns 基础 URL / Base URL
4782
4886
  */
4783
- list = async (params) => {
4784
- return this.sandbox.dataApi.listDirectory(params);
4785
- };
4887
+ getBaseUrl() {
4888
+ const cfg = exports.Config.withConfigs(this._config);
4889
+ return `${cfg.dataEndpoint}/sandboxes/${this.sandboxId}`;
4890
+ }
4891
+ };
4892
+ }
4893
+ });
4894
+
4895
+ // src/sandbox/sandbox.ts
4896
+ exports.Sandbox = void 0;
4897
+ var init_sandbox = __esm({
4898
+ "src/sandbox/sandbox.ts"() {
4899
+ init_utils();
4900
+ init_log();
4901
+ init_config();
4902
+ init_resource();
4903
+ init_model4();
4904
+ init_sandbox_data();
4905
+ exports.Sandbox = class _Sandbox extends ResourceBase {
4906
+ templateType;
4786
4907
  /**
4787
- * Move a file or directory
4908
+ * 沙箱 ID / Sandbox ID
4788
4909
  */
4789
- move = async (params) => {
4790
- return this.sandbox.dataApi.moveFile(params);
4791
- };
4910
+ sandboxId;
4792
4911
  /**
4793
- * Remove a file or directory
4912
+ * 沙箱名称 / Sandbox Name
4794
4913
  */
4795
- remove = async (params) => {
4796
- return this.sandbox.dataApi.removeFile(params);
4797
- };
4914
+ sandboxName;
4798
4915
  /**
4799
- * Get file or directory statistics
4800
- */
4801
- stat = async (params) => {
4802
- return this.sandbox.dataApi.stat(params);
4803
- };
4804
- /**
4805
- * Create a directory
4806
- */
4807
- mkdir = async (params) => {
4808
- return this.sandbox.dataApi.mkdir(params);
4809
- };
4810
- /**
4811
- * Upload a file to the sandbox
4812
- */
4813
- upload = async (params) => {
4814
- return this.sandbox.dataApi.uploadFile(params);
4815
- };
4816
- /**
4817
- * Download a file from the sandbox
4818
- */
4819
- download = async (params) => {
4820
- return this.sandbox.dataApi.downloadFile(params);
4821
- };
4822
- };
4823
- AioProcessOperations = class {
4824
- sandbox;
4825
- constructor(sandbox) {
4826
- this.sandbox = sandbox;
4827
- }
4828
- /**
4829
- * Execute a command in the sandbox
4830
- */
4831
- cmd = async (params) => {
4832
- return this.sandbox.dataApi.cmd(params);
4833
- };
4834
- /**
4835
- * List all processes
4836
- */
4837
- list = async (params) => {
4838
- return this.sandbox.dataApi.listProcesses(params);
4839
- };
4840
- /**
4841
- * Get a specific process by PID
4842
- */
4843
- get = async (params) => {
4844
- return this.sandbox.dataApi.getProcess(params);
4845
- };
4846
- /**
4847
- * Kill a specific process by PID
4848
- */
4849
- kill = async (params) => {
4850
- return this.sandbox.dataApi.killProcess(params);
4851
- };
4852
- };
4853
- AioContextOperations = class {
4854
- sandbox;
4855
- _contextId;
4856
- _language;
4857
- _cwd;
4858
- constructor(sandbox) {
4859
- this.sandbox = sandbox;
4860
- }
4861
- /**
4862
- * Get the current context ID
4863
- */
4864
- get contextId() {
4865
- return this._contextId;
4866
- }
4867
- /**
4868
- * List all contexts
4869
- */
4870
- list = async (params) => {
4871
- return this.sandbox.dataApi.listContexts(params);
4872
- };
4873
- /**
4874
- * Create a new context and save its ID
4875
- */
4876
- create = async (params) => {
4877
- const language = params?.language || "python" /* PYTHON */;
4878
- const cwd = params?.cwd || "/home/user";
4879
- const result = await this.sandbox.dataApi.createContext({
4880
- language,
4881
- cwd
4882
- });
4883
- if (result?.id && result?.cwd && result?.language) {
4884
- this._contextId = result.id;
4885
- this._language = result.language;
4886
- this._cwd = result.cwd;
4887
- return this;
4888
- }
4889
- throw new exports.ServerError(500, "Failed to create context");
4890
- };
4891
- /**
4892
- * Get a specific context by ID
4893
- */
4894
- get = async (params) => {
4895
- const id = params?.contextId || this._contextId;
4896
- if (!id) {
4897
- logger.error("context id is not set");
4898
- throw new Error("context id is not set");
4899
- }
4900
- const result = await this.sandbox.dataApi.getContext({ contextId: id });
4901
- if (result?.id && result?.cwd && result?.language) {
4902
- this._contextId = result.id;
4903
- this._language = result.language;
4904
- this._cwd = result.cwd;
4905
- return this;
4906
- }
4907
- throw new exports.ServerError(500, "Failed to get context");
4908
- };
4909
- /**
4910
- * Execute code in a context
4911
- */
4912
- execute = async (params) => {
4913
- const { code, timeout = 30 } = params;
4914
- let { contextId, language } = params;
4915
- if (!contextId) {
4916
- contextId = this._contextId;
4917
- }
4918
- if (!contextId && !language) {
4919
- logger.debug("context id is not set, use default language: python");
4920
- language = "python" /* PYTHON */;
4921
- }
4922
- return this.sandbox.dataApi.executeCode({
4923
- code,
4924
- contextId,
4925
- language,
4926
- timeout
4927
- });
4928
- };
4929
- /**
4930
- * Delete a context
4931
- */
4932
- delete = async (params) => {
4933
- const id = params?.contextId || this._contextId;
4934
- if (!id) {
4935
- throw new Error(
4936
- "context_id is required. Either pass it as parameter or create a context first."
4937
- );
4938
- }
4939
- const result = await this.sandbox.dataApi.deleteContext({ contextId: id });
4940
- this._contextId = void 0;
4941
- return result;
4942
- };
4943
- };
4944
- exports.AioSandbox = class _AioSandbox extends exports.Sandbox {
4945
- static templateType = "AllInOne" /* AIO */;
4946
- /**
4947
- * Create an AIO Sandbox from template
4948
- * 从模板创建 AIO 沙箱 / Create AIO Sandbox from Template
4949
- */
4950
- static async createFromTemplate(templateName, options, config2) {
4951
- const sandbox = await exports.Sandbox.create(
4952
- {
4953
- templateName,
4954
- sandboxIdleTimeoutInSeconds: options?.sandboxIdleTimeoutInSeconds,
4955
- nasConfig: options?.nasConfig,
4956
- ossMountConfig: options?.ossMountConfig,
4957
- polarFsConfig: options?.polarFsConfig
4958
- },
4959
- config2
4960
- );
4961
- const aioSandbox = new _AioSandbox(sandbox, config2);
4962
- return aioSandbox;
4963
- }
4964
- constructor(sandbox, config2) {
4965
- super(sandbox, config2);
4966
- }
4967
- _dataApi;
4968
- _file;
4969
- _fileSystem;
4970
- _context;
4971
- _process;
4972
- /**
4973
- * Get data API client
4974
- */
4975
- get dataApi() {
4976
- if (!this._dataApi) {
4977
- this._dataApi = new exports.AioDataAPI({
4978
- sandboxId: this.sandboxId || "",
4979
- config: this._config
4980
- });
4981
- }
4982
- return this._dataApi;
4983
- }
4984
- /**
4985
- * Access file upload/download operations
4986
- */
4987
- get file() {
4988
- if (!this._file) {
4989
- this._file = new AioFileOperations(this);
4990
- }
4991
- return this._file;
4992
- }
4993
- /**
4994
- * Access file system operations
4995
- */
4996
- get fileSystem() {
4997
- if (!this._fileSystem) {
4998
- this._fileSystem = new AioFileSystemOperations(this);
4999
- }
5000
- return this._fileSystem;
5001
- }
5002
- /**
5003
- * Access context management operations
5004
- */
5005
- get context() {
5006
- if (!this._context) {
5007
- this._context = new AioContextOperations(this);
5008
- }
5009
- return this._context;
5010
- }
5011
- /**
5012
- * Access process management operations
5013
- */
5014
- get process() {
5015
- if (!this._process) {
5016
- this._process = new AioProcessOperations(this);
5017
- }
5018
- return this._process;
5019
- }
5020
- /**
5021
- * Check sandbox health
5022
- */
5023
- checkHealth = async (params) => {
5024
- return this.dataApi.checkHealth({
5025
- sandboxId: this.sandboxId,
5026
- config: params?.config
5027
- });
5028
- };
5029
- // ========================================
5030
- // Browser API Methods
5031
- // ========================================
5032
- /**
5033
- * Get CDP WebSocket URL for browser automation
5034
- */
5035
- getCdpUrl(record) {
5036
- return this.dataApi.getCdpUrl(record);
5037
- }
5038
- /**
5039
- * Get VNC WebSocket URL for live view
5040
- */
5041
- getVncUrl(record) {
5042
- return this.dataApi.getVncUrl(record);
5043
- }
5044
- /**
5045
- * List all browser recordings
5046
- */
5047
- 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);
5055
- };
5056
- /**
5057
- * Delete a recording
5058
- */
5059
- deleteRecording = async (params) => {
5060
- return this.dataApi.deleteRecording(params);
5061
- };
5062
- // ========================================
5063
- // Code Interpreter API Methods
5064
- // ========================================
5065
- /**
5066
- * Execute code (convenience method delegating to context.execute)
5067
- */
5068
- execute = async (params) => {
5069
- return this.context.execute(params);
5070
- };
5071
- };
5072
- }
5073
- });
5074
-
5075
- // src/sandbox/custom-sandbox.ts
5076
- var custom_sandbox_exports = {};
5077
- __export(custom_sandbox_exports, {
5078
- CustomSandbox: () => CustomSandbox
5079
- });
5080
- var CustomSandbox;
5081
- var init_custom_sandbox = __esm({
5082
- "src/sandbox/custom-sandbox.ts"() {
5083
- init_config();
5084
- init_model4();
5085
- 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
- sandboxIdleTimeoutInSeconds: options?.sandboxIdleTimeoutInSeconds,
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);
5109
- }
5110
- _dataApi;
5111
- /**
5112
- * Get data API client
5113
- */
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
- }
5123
- /**
5124
- * Get base URL for the sandbox
5125
- * 获取沙箱的基础 URL / Get base URL for the sandbox
5126
- *
5127
- * @returns 基础 URL / Base URL
5128
- */
5129
- getBaseUrl() {
5130
- const cfg = exports.Config.withConfigs(this._config);
5131
- return `${cfg.dataEndpoint}/sandboxes/${this.sandboxId}`;
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;
5148
- /**
5149
- * 沙箱 ID / Sandbox ID
5150
- */
5151
- sandboxId;
5152
- /**
5153
- * 沙箱名称 / Sandbox Name
5154
- */
5155
- sandboxName;
5156
- /**
5157
- * 模板 ID / Template ID
4916
+ * 模板 ID / Template ID
5158
4917
  */
5159
4918
  templateId;
5160
4919
  /**
@@ -5180,7 +4939,7 @@ var init_sandbox = __esm({
5180
4939
  /**
5181
4940
  * 沙箱空闲超时时间(秒) / Sandbox Idle Timeout (seconds)
5182
4941
  */
5183
- sandboxIdleTimeoutInSeconds;
4942
+ sandboxIdleTimeoutSeconds;
5184
4943
  /**
5185
4944
  * 沙箱结束时间 / Sandbox End Time
5186
4945
  */
@@ -5221,7 +4980,7 @@ var init_sandbox = __esm({
5221
4980
  stateReason: obj.stateReason,
5222
4981
  createdAt: obj.createdAt,
5223
4982
  lastUpdatedAt: obj.lastUpdatedAt,
5224
- sandboxIdleTimeoutInSeconds: obj.sandboxIdleTimeoutInSeconds,
4983
+ sandboxIdleTimeoutSeconds: obj.sandboxIdleTimeoutSeconds,
5225
4984
  // New fields / 新增字段
5226
4985
  endedAt: obj.endedAt,
5227
4986
  metadata: obj.metadata,
@@ -5235,32 +4994,41 @@ var init_sandbox = __esm({
5235
4994
  const { SandboxClient: SandboxClient2 } = (init_client3(), __toCommonJS(client_exports3));
5236
4995
  return new SandboxClient2();
5237
4996
  }
5238
- /**
5239
- * Create a new Sandbox
5240
- * 创建新沙箱 / Create a New Sandbox
5241
- */
5242
- static async create(input, config2) {
5243
- return await _Sandbox.getClient().createSandbox({ input, config: config2 });
4997
+ static async create(arg1, arg2) {
4998
+ return await _Sandbox.getClient().createSandbox(arg1, arg2);
5244
4999
  }
5245
- /**
5246
- * Delete a Sandbox by ID
5247
- */
5248
- static async delete(params) {
5249
- const { id, config: config2 } = params;
5250
- return await _Sandbox.getClient().deleteSandbox({ id, config: config2 });
5000
+ static async delete(arg1, arg2) {
5001
+ if (typeof arg1 === "string") {
5002
+ return await _Sandbox.getClient().deleteSandbox(arg1, arg2);
5003
+ }
5004
+ return await _Sandbox.getClient().deleteSandbox(arg1);
5251
5005
  }
5252
- /**
5253
- * Stop a Sandbox by ID
5254
- */
5255
- static async stop(params) {
5256
- const { id, config: config2 } = params;
5257
- return await _Sandbox.getClient().stopSandbox({ id, config: config2 });
5006
+ static async stop(arg1, arg2) {
5007
+ if (typeof arg1 === "string") {
5008
+ return await _Sandbox.getClient().stopSandbox(arg1, arg2);
5009
+ }
5010
+ return await _Sandbox.getClient().stopSandbox(arg1);
5258
5011
  }
5259
- /**
5260
- * Get a Sandbox by ID
5261
- */
5262
- static async get(params) {
5263
- const { id, templateType, config: config2 } = params;
5012
+ static async get(arg1, arg2, arg3) {
5013
+ let id;
5014
+ let templateType;
5015
+ let config2;
5016
+ if (typeof arg1 === "string") {
5017
+ logger.warn(
5018
+ "Deprecated: Sandbox.get(id, templateType?, config?) is deprecated. Use Sandbox.get({ id, templateType, config }) instead."
5019
+ );
5020
+ id = arg1;
5021
+ if (arg2 && typeof arg2 === "string") {
5022
+ templateType = arg2;
5023
+ config2 = arg3;
5024
+ } else {
5025
+ config2 = arg2;
5026
+ }
5027
+ } else {
5028
+ id = arg1.id;
5029
+ templateType = arg1.templateType;
5030
+ config2 = arg1.config;
5031
+ }
5264
5032
  try {
5265
5033
  const cfg = exports.Config.withConfigs(config2);
5266
5034
  const dataApi = new exports.SandboxDataAPI({
@@ -5311,11 +5079,16 @@ var init_sandbox = __esm({
5311
5079
  throw error;
5312
5080
  }
5313
5081
  }
5314
- /**
5315
- * List Sandboxes
5316
- */
5317
- static async list(input, config2) {
5318
- return await _Sandbox.getClient().listSandboxes({ input, config: config2 });
5082
+ static async list(arg1, arg2) {
5083
+ if (arg2 !== void 0 || arg1 && ("maxResults" in arg1 || "nextToken" in arg1 || "status" in arg1 || "templateName" in arg1)) {
5084
+ return await _Sandbox.getClient().listSandboxes(
5085
+ arg1,
5086
+ arg2
5087
+ );
5088
+ }
5089
+ return await _Sandbox.getClient().listSandboxes(
5090
+ arg1
5091
+ );
5319
5092
  }
5320
5093
  get = async (params) => {
5321
5094
  const { config: config2 } = params ?? {};
@@ -5326,128 +5099,358 @@ var init_sandbox = __esm({
5326
5099
  });
5327
5100
  };
5328
5101
  /**
5329
- * Delete this sandbox
5102
+ * Delete this sandbox
5103
+ */
5104
+ delete = async (params) => {
5105
+ const config2 = params?.config;
5106
+ if (!this.sandboxId) {
5107
+ throw new Error("sandboxId is required to delete a Sandbox");
5108
+ }
5109
+ const result = await _Sandbox.delete({
5110
+ id: this.sandboxId,
5111
+ config: config2 ?? this._config
5112
+ });
5113
+ updateObjectProperties(this, result);
5114
+ return this;
5115
+ };
5116
+ /**
5117
+ * Stop this sandbox
5118
+ */
5119
+ stop = async (params) => {
5120
+ const config2 = params?.config;
5121
+ if (!this.sandboxId) {
5122
+ throw new Error("sandboxId is required to stop a Sandbox");
5123
+ }
5124
+ const result = await _Sandbox.stop({
5125
+ id: this.sandboxId,
5126
+ config: config2 ?? this._config
5127
+ });
5128
+ updateObjectProperties(this, result);
5129
+ return this;
5130
+ };
5131
+ /**
5132
+ * Refresh this sandbox's data
5133
+ */
5134
+ refresh = async (params) => {
5135
+ const config2 = params?.config;
5136
+ if (!this.sandboxId) {
5137
+ throw new Error("sandboxId is required to refresh a Sandbox");
5138
+ }
5139
+ const result = await _Sandbox.get({
5140
+ id: this.sandboxId,
5141
+ config: config2 ?? this._config
5142
+ });
5143
+ updateObjectProperties(this, result);
5144
+ return this;
5145
+ };
5146
+ /**
5147
+ * Wait until the sandbox is running
5148
+ */
5149
+ waitUntilRunning = async (options, config2) => {
5150
+ const timeout = (options?.timeoutSeconds ?? 300) * 1e3;
5151
+ const interval = (options?.intervalSeconds ?? 5) * 1e3;
5152
+ const startTime = Date.now();
5153
+ while (Date.now() - startTime < timeout) {
5154
+ await this.refresh({ config: config2 });
5155
+ if (options?.beforeCheck) {
5156
+ options.beforeCheck(this);
5157
+ }
5158
+ if (this.state === "Running" /* RUNNING */ || this.state === "READY" /* READY */) {
5159
+ return this;
5160
+ }
5161
+ if (this.state === "Failed" /* FAILED */) {
5162
+ throw new Error(`Sandbox failed: ${this.stateReason}`);
5163
+ }
5164
+ await new Promise((resolve) => setTimeout(resolve, interval));
5165
+ }
5166
+ throw new Error(
5167
+ `Timeout waiting for Sandbox to be running after ${options?.timeoutSeconds ?? 300} seconds`
5168
+ );
5169
+ };
5170
+ };
5171
+ }
5172
+ });
5173
+
5174
+ // src/sandbox/aio-sandbox.ts
5175
+ var aio_sandbox_exports = {};
5176
+ __export(aio_sandbox_exports, {
5177
+ AioContextOperations: () => AioContextOperations,
5178
+ AioFileOperations: () => AioFileOperations,
5179
+ AioFileSystemOperations: () => AioFileSystemOperations,
5180
+ AioProcessOperations: () => AioProcessOperations,
5181
+ AioSandbox: () => exports.AioSandbox
5182
+ });
5183
+ var AioFileOperations, AioFileSystemOperations, AioProcessOperations, AioContextOperations; exports.AioSandbox = void 0;
5184
+ var init_aio_sandbox = __esm({
5185
+ "src/sandbox/aio-sandbox.ts"() {
5186
+ init_log();
5187
+ init_exception();
5188
+ init_aio_data();
5189
+ init_model4();
5190
+ init_sandbox();
5191
+ AioFileOperations = class {
5192
+ sandbox;
5193
+ constructor(sandbox) {
5194
+ this.sandbox = sandbox;
5195
+ }
5196
+ /**
5197
+ * Read a file from the sandbox
5198
+ */
5199
+ read = async (path2) => {
5200
+ return this.sandbox.dataApi.readFile({ path: path2 });
5201
+ };
5202
+ /**
5203
+ * Write a file to the sandbox
5204
+ */
5205
+ write = async (params) => {
5206
+ return this.sandbox.dataApi.writeFile(params);
5207
+ };
5208
+ };
5209
+ AioFileSystemOperations = class {
5210
+ sandbox;
5211
+ constructor(sandbox) {
5212
+ this.sandbox = sandbox;
5213
+ }
5214
+ /**
5215
+ * List directory contents
5216
+ */
5217
+ list = async (params) => {
5218
+ return this.sandbox.dataApi.listDirectory(params);
5219
+ };
5220
+ /**
5221
+ * Move a file or directory
5222
+ */
5223
+ move = async (params) => {
5224
+ return this.sandbox.dataApi.moveFile(params);
5225
+ };
5226
+ /**
5227
+ * Remove a file or directory
5228
+ */
5229
+ remove = async (params) => {
5230
+ return this.sandbox.dataApi.removeFile(params);
5231
+ };
5232
+ /**
5233
+ * Get file or directory statistics
5234
+ */
5235
+ stat = async (params) => {
5236
+ return this.sandbox.dataApi.stat(params);
5237
+ };
5238
+ /**
5239
+ * Create a directory
5240
+ */
5241
+ mkdir = async (params) => {
5242
+ return this.sandbox.dataApi.mkdir(params);
5243
+ };
5244
+ /**
5245
+ * Upload a file to the sandbox
5246
+ */
5247
+ upload = async (params) => {
5248
+ return this.sandbox.dataApi.uploadFile(params);
5249
+ };
5250
+ /**
5251
+ * Download a file from the sandbox
5252
+ */
5253
+ download = async (params) => {
5254
+ return this.sandbox.dataApi.downloadFile(params);
5255
+ };
5256
+ };
5257
+ AioProcessOperations = class {
5258
+ sandbox;
5259
+ constructor(sandbox) {
5260
+ this.sandbox = sandbox;
5261
+ }
5262
+ /**
5263
+ * Execute a command in the sandbox
5264
+ */
5265
+ cmd = async (params) => {
5266
+ return this.sandbox.dataApi.cmd(params);
5267
+ };
5268
+ /**
5269
+ * List all processes
5270
+ */
5271
+ list = async (params) => {
5272
+ return this.sandbox.dataApi.listProcesses(params);
5273
+ };
5274
+ /**
5275
+ * Get a specific process by PID
5276
+ */
5277
+ get = async (params) => {
5278
+ return this.sandbox.dataApi.getProcess(params);
5279
+ };
5280
+ /**
5281
+ * Kill a specific process by PID
5282
+ */
5283
+ kill = async (params) => {
5284
+ return this.sandbox.dataApi.killProcess(params);
5285
+ };
5286
+ };
5287
+ AioContextOperations = class {
5288
+ sandbox;
5289
+ _contextId;
5290
+ _language;
5291
+ _cwd;
5292
+ constructor(sandbox) {
5293
+ this.sandbox = sandbox;
5294
+ }
5295
+ /**
5296
+ * Get the current context ID
5297
+ */
5298
+ get contextId() {
5299
+ return this._contextId;
5300
+ }
5301
+ /**
5302
+ * List all contexts
5303
+ */
5304
+ list = async (params) => {
5305
+ return this.sandbox.dataApi.listContexts(params);
5306
+ };
5307
+ /**
5308
+ * Create a new context and save its ID
5330
5309
  */
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
5310
+ create = async (params) => {
5311
+ const language = params?.language || "python" /* PYTHON */;
5312
+ const cwd = params?.cwd || "/home/user";
5313
+ const result = await this.sandbox.dataApi.createContext({
5314
+ language,
5315
+ cwd
5339
5316
  });
5340
- updateObjectProperties(this, result);
5341
- return this;
5317
+ if (result?.id && result?.cwd && result?.language) {
5318
+ this._contextId = result.id;
5319
+ this._language = result.language;
5320
+ this._cwd = result.cwd;
5321
+ return this;
5322
+ }
5323
+ throw new exports.ServerError(500, "Failed to create context");
5342
5324
  };
5343
5325
  /**
5344
- * Stop this sandbox
5326
+ * Get a specific context by ID
5345
5327
  */
5346
- stop = async (params) => {
5347
- const config2 = params?.config;
5348
- if (!this.sandboxId) {
5349
- throw new Error("sandboxId is required to stop a Sandbox");
5328
+ get = async (params) => {
5329
+ const id = params?.contextId || this._contextId;
5330
+ if (!id) {
5331
+ logger.error("context id is not set");
5332
+ throw new Error("context id is not set");
5350
5333
  }
5351
- const result = await _Sandbox.stop({
5352
- id: this.sandboxId,
5353
- config: config2 ?? this._config
5354
- });
5355
- updateObjectProperties(this, result);
5356
- return this;
5334
+ const result = await this.sandbox.dataApi.getContext({ contextId: id });
5335
+ if (result?.id && result?.cwd && result?.language) {
5336
+ this._contextId = result.id;
5337
+ this._language = result.language;
5338
+ this._cwd = result.cwd;
5339
+ return this;
5340
+ }
5341
+ throw new exports.ServerError(500, "Failed to get context");
5357
5342
  };
5358
5343
  /**
5359
- * Refresh this sandbox's data
5344
+ * Execute code in a context
5360
5345
  */
5361
- refresh = async (params) => {
5362
- const config2 = params?.config;
5363
- if (!this.sandboxId) {
5364
- throw new Error("sandboxId is required to refresh a Sandbox");
5346
+ execute = async (params) => {
5347
+ const { code, timeout = 30 } = params;
5348
+ let { contextId, language } = params;
5349
+ if (!contextId) {
5350
+ contextId = this._contextId;
5365
5351
  }
5366
- const result = await _Sandbox.get({
5367
- id: this.sandboxId,
5368
- config: config2 ?? this._config
5352
+ if (!contextId && !language) {
5353
+ logger.debug("context id is not set, use default language: python");
5354
+ language = "python" /* PYTHON */;
5355
+ }
5356
+ return this.sandbox.dataApi.executeCode({
5357
+ code,
5358
+ contextId,
5359
+ language,
5360
+ timeout
5369
5361
  });
5370
- updateObjectProperties(this, result);
5371
- return this;
5372
5362
  };
5373
5363
  /**
5374
- * Wait until the sandbox is running
5364
+ * Delete a context
5375
5365
  */
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));
5366
+ delete = async (params) => {
5367
+ const id = params?.contextId || this._contextId;
5368
+ if (!id) {
5369
+ throw new Error(
5370
+ "context_id is required. Either pass it as parameter or create a context first."
5371
+ );
5392
5372
  }
5393
- throw new Error(
5394
- `Timeout waiting for Sandbox to be running after ${options?.timeoutSeconds ?? 300} seconds`
5395
- );
5373
+ const result = await this.sandbox.dataApi.deleteContext({ contextId: id });
5374
+ this._contextId = void 0;
5375
+ return result;
5396
5376
  };
5397
5377
  };
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 */;
5378
+ exports.AioSandbox = class extends exports.Sandbox {
5379
+ static templateType = "AllInOne" /* AIO */;
5414
5380
  /**
5415
- * Create a Browser Sandbox from template
5416
- * 从模板创建浏览器沙箱 / Create Browser Sandbox from Template
5381
+ * Create an AIO Sandbox from template
5382
+ * 从模板创建 AIO 沙箱 / Create AIO Sandbox from Template
5417
5383
  */
5418
5384
  static async createFromTemplate(templateName, options, config2) {
5419
- const sandbox = await exports.Sandbox.create(
5420
- {
5385
+ const sandbox = await exports.Sandbox.create({
5386
+ input: {
5421
5387
  templateName,
5422
- sandboxIdleTimeoutInSeconds: options?.sandboxIdleTimeoutInSeconds,
5388
+ sandboxIdleTimeoutSeconds: options?.sandboxIdleTimeoutSeconds,
5423
5389
  nasConfig: options?.nasConfig,
5424
5390
  ossMountConfig: options?.ossMountConfig,
5425
5391
  polarFsConfig: options?.polarFsConfig
5426
5392
  },
5427
- config2
5428
- );
5429
- const browserSandbox = new _BrowserSandbox(sandbox, config2);
5430
- return browserSandbox;
5393
+ templateType: "AllInOne" /* AIO */,
5394
+ config: config2
5395
+ });
5396
+ return sandbox;
5431
5397
  }
5432
5398
  constructor(sandbox, config2) {
5433
5399
  super(sandbox, config2);
5434
5400
  }
5435
5401
  _dataApi;
5402
+ _file;
5403
+ _fileSystem;
5404
+ _context;
5405
+ _process;
5436
5406
  /**
5437
5407
  * Get data API client
5438
5408
  */
5439
5409
  get dataApi() {
5440
5410
  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,
5411
+ this._dataApi = new exports.AioDataAPI({
5412
+ sandboxId: this.sandboxId || "",
5446
5413
  config: this._config
5447
5414
  });
5448
5415
  }
5449
5416
  return this._dataApi;
5450
5417
  }
5418
+ /**
5419
+ * Access file upload/download operations
5420
+ */
5421
+ get file() {
5422
+ if (!this._file) {
5423
+ this._file = new AioFileOperations(this);
5424
+ }
5425
+ return this._file;
5426
+ }
5427
+ /**
5428
+ * Access file system operations
5429
+ */
5430
+ get fileSystem() {
5431
+ if (!this._fileSystem) {
5432
+ this._fileSystem = new AioFileSystemOperations(this);
5433
+ }
5434
+ return this._fileSystem;
5435
+ }
5436
+ /**
5437
+ * Access context management operations
5438
+ */
5439
+ get context() {
5440
+ if (!this._context) {
5441
+ this._context = new AioContextOperations(this);
5442
+ }
5443
+ return this._context;
5444
+ }
5445
+ /**
5446
+ * Access process management operations
5447
+ */
5448
+ get process() {
5449
+ if (!this._process) {
5450
+ this._process = new AioProcessOperations(this);
5451
+ }
5452
+ return this._process;
5453
+ }
5451
5454
  /**
5452
5455
  * Check sandbox health
5453
5456
  */
@@ -5457,6 +5460,9 @@ var init_browser_sandbox = __esm({
5457
5460
  config: params?.config
5458
5461
  });
5459
5462
  };
5463
+ // ========================================
5464
+ // Browser API Methods
5465
+ // ========================================
5460
5466
  /**
5461
5467
  * Get CDP WebSocket URL for browser automation
5462
5468
  */
@@ -5470,7 +5476,7 @@ var init_browser_sandbox = __esm({
5470
5476
  return this.dataApi.getVncUrl(record);
5471
5477
  }
5472
5478
  /**
5473
- * List all recordings
5479
+ * List all browser recordings
5474
5480
  */
5475
5481
  listRecordings = async (params) => {
5476
5482
  return this.dataApi.listRecordings(params);
@@ -5487,6 +5493,15 @@ var init_browser_sandbox = __esm({
5487
5493
  deleteRecording = async (params) => {
5488
5494
  return this.dataApi.deleteRecording(params);
5489
5495
  };
5496
+ // ========================================
5497
+ // Code Interpreter API Methods
5498
+ // ========================================
5499
+ /**
5500
+ * Execute code (convenience method delegating to context.execute)
5501
+ */
5502
+ execute = async (params) => {
5503
+ return this.context.execute(params);
5504
+ };
5490
5505
  };
5491
5506
  }
5492
5507
  });
@@ -5570,6 +5585,7 @@ var init_template = __esm({
5570
5585
  super();
5571
5586
  if (data) {
5572
5587
  updateObjectProperties(this, data);
5588
+ this.normalizeNumericFields();
5573
5589
  }
5574
5590
  this._config = config2;
5575
5591
  }
@@ -5582,36 +5598,31 @@ var init_template = __esm({
5582
5598
  * Create a new Template
5583
5599
  */
5584
5600
  static async create(params) {
5585
- const { input, config: config2 } = params;
5586
- return await _Template.getClient().createTemplate({ input, config: config2 });
5601
+ return await _Template.getClient().createTemplate(params);
5587
5602
  }
5588
5603
  /**
5589
5604
  * Delete a Template by name
5590
5605
  */
5591
5606
  static async delete(params) {
5592
- const { name, config: config2 } = params;
5593
- return await _Template.getClient().deleteTemplate({ name, config: config2 });
5607
+ return await _Template.getClient().deleteTemplate(params);
5594
5608
  }
5595
5609
  /**
5596
5610
  * Update a Template by name
5597
5611
  */
5598
5612
  static async update(params) {
5599
- const { name, input, config: config2 } = params;
5600
- return await _Template.getClient().updateTemplate({ name, input, config: config2 });
5613
+ return await _Template.getClient().updateTemplate(params);
5601
5614
  }
5602
5615
  /**
5603
5616
  * Get a Template by name
5604
5617
  */
5605
5618
  static async get(params) {
5606
- const { name, config: config2 } = params;
5607
- return await _Template.getClient().getTemplate({ name, config: config2 });
5619
+ return await _Template.getClient().getTemplate(params);
5608
5620
  }
5609
5621
  /**
5610
5622
  * List Templates
5611
5623
  */
5612
5624
  static async list(params) {
5613
- const { input, config: config2 } = params ?? {};
5614
- return await _Template.getClient().listTemplates({ input, config: config2 });
5625
+ return await _Template.getClient().listTemplates(params);
5615
5626
  }
5616
5627
  /**
5617
5628
  * List all Templates (with pagination)
@@ -5636,6 +5647,7 @@ var init_template = __esm({
5636
5647
  config: config2 ?? this._config
5637
5648
  });
5638
5649
  updateObjectProperties(this, result);
5650
+ this.normalizeNumericFields();
5639
5651
  return this;
5640
5652
  };
5641
5653
  /**
@@ -5652,6 +5664,7 @@ var init_template = __esm({
5652
5664
  config: config2 ?? this._config
5653
5665
  });
5654
5666
  updateObjectProperties(this, result);
5667
+ this.normalizeNumericFields();
5655
5668
  return this;
5656
5669
  };
5657
5670
  /**
@@ -5667,8 +5680,25 @@ var init_template = __esm({
5667
5680
  config: config2 ?? this._config
5668
5681
  });
5669
5682
  updateObjectProperties(this, result);
5683
+ this.normalizeNumericFields();
5670
5684
  return this;
5671
5685
  };
5686
+ normalizeNumericFields() {
5687
+ const toNumber = (value) => {
5688
+ if (typeof value === "number") return value;
5689
+ if (typeof value === "string") {
5690
+ const parsed = Number(value);
5691
+ return Number.isNaN(parsed) ? void 0 : parsed;
5692
+ }
5693
+ return void 0;
5694
+ };
5695
+ this.sandboxIdleTimeoutInSeconds = toNumber(this.sandboxIdleTimeoutInSeconds) ?? this.sandboxIdleTimeoutInSeconds;
5696
+ this.sandboxTtlInSeconds = toNumber(this.sandboxTtlInSeconds) ?? this.sandboxTtlInSeconds;
5697
+ this.shareConcurrencyLimitPerSandbox = toNumber(this.shareConcurrencyLimitPerSandbox) ?? this.shareConcurrencyLimitPerSandbox;
5698
+ this.cpu = toNumber(this.cpu) ?? this.cpu;
5699
+ this.memory = toNumber(this.memory) ?? this.memory;
5700
+ this.diskSize = toNumber(this.diskSize) ?? this.diskSize;
5701
+ }
5672
5702
  };
5673
5703
  }
5674
5704
  });
@@ -5683,9 +5713,12 @@ var init_client3 = __esm({
5683
5713
  "src/sandbox/client.ts"() {
5684
5714
  init_config();
5685
5715
  init_exception();
5716
+ init_log();
5686
5717
  init_control3();
5718
+ init_aio_sandbox();
5687
5719
  init_browser_sandbox();
5688
5720
  init_code_interpreter_sandbox();
5721
+ init_custom_sandbox();
5689
5722
  init_model4();
5690
5723
  init_sandbox();
5691
5724
  init_template();
@@ -5700,8 +5733,19 @@ var init_client3 = __esm({
5700
5733
  /**
5701
5734
  * Create a Template
5702
5735
  */
5703
- createTemplate = async (params) => {
5704
- const { input, config: config2 } = params;
5736
+ createTemplate = async (arg1, arg2) => {
5737
+ let input;
5738
+ let config2;
5739
+ if ("input" in arg1) {
5740
+ input = arg1.input;
5741
+ config2 = arg1.config;
5742
+ } else {
5743
+ logger.warn(
5744
+ "Deprecated: createTemplate(input, config) is deprecated. Use createTemplate({ input, config }) instead."
5745
+ );
5746
+ input = arg1;
5747
+ config2 = arg2;
5748
+ }
5705
5749
  const cfg = exports.Config.withConfigs(this.config, config2);
5706
5750
  try {
5707
5751
  const finalInput = this.prepareTemplateCreateInput(input);
@@ -5725,8 +5769,19 @@ var init_client3 = __esm({
5725
5769
  /**
5726
5770
  * Delete a Template
5727
5771
  */
5728
- deleteTemplate = async (params) => {
5729
- const { name, config: config2 } = params;
5772
+ deleteTemplate = async (arg1, arg2) => {
5773
+ let name;
5774
+ let config2;
5775
+ if (typeof arg1 === "string") {
5776
+ logger.warn(
5777
+ "Deprecated: deleteTemplate(name, config) is deprecated. Use deleteTemplate({ name, config }) instead."
5778
+ );
5779
+ name = arg1;
5780
+ config2 = arg2;
5781
+ } else {
5782
+ name = arg1.name;
5783
+ config2 = arg1.config;
5784
+ }
5730
5785
  const cfg = exports.Config.withConfigs(this.config, config2);
5731
5786
  try {
5732
5787
  const result = await this.controlApi.deleteTemplate({
@@ -5744,8 +5799,22 @@ var init_client3 = __esm({
5744
5799
  /**
5745
5800
  * Update a Template
5746
5801
  */
5747
- updateTemplate = async (params) => {
5748
- const { name, input, config: config2 } = params;
5802
+ updateTemplate = async (arg1, arg2, arg3) => {
5803
+ let name;
5804
+ let input;
5805
+ let config2;
5806
+ if (typeof arg1 === "string") {
5807
+ logger.warn(
5808
+ "Deprecated: updateTemplate(name, input, config) is deprecated. Use updateTemplate({ name, input, config }) instead."
5809
+ );
5810
+ name = arg1;
5811
+ input = arg2;
5812
+ config2 = arg3;
5813
+ } else {
5814
+ name = arg1.name;
5815
+ input = arg1.input;
5816
+ config2 = arg1.config;
5817
+ }
5749
5818
  const cfg = exports.Config.withConfigs(this.config, config2);
5750
5819
  try {
5751
5820
  const result = await this.controlApi.updateTemplate({
@@ -5769,8 +5838,19 @@ var init_client3 = __esm({
5769
5838
  /**
5770
5839
  * Get a Template
5771
5840
  */
5772
- getTemplate = async (params) => {
5773
- const { name, config: config2 } = params;
5841
+ getTemplate = async (arg1, arg2) => {
5842
+ let name;
5843
+ let config2;
5844
+ if (typeof arg1 === "string") {
5845
+ logger.warn(
5846
+ "Deprecated: getTemplate(name, config) is deprecated. Use getTemplate({ name, config }) instead."
5847
+ );
5848
+ name = arg1;
5849
+ config2 = arg2;
5850
+ } else {
5851
+ name = arg1.name;
5852
+ config2 = arg1.config;
5853
+ }
5774
5854
  const cfg = exports.Config.withConfigs(this.config, config2);
5775
5855
  try {
5776
5856
  const result = await this.controlApi.getTemplate({
@@ -5788,8 +5868,20 @@ var init_client3 = __esm({
5788
5868
  /**
5789
5869
  * List Templates
5790
5870
  */
5791
- listTemplates = async (params) => {
5792
- const { input, config: config2 } = params ?? {};
5871
+ listTemplates = async (arg1, arg2) => {
5872
+ let input;
5873
+ let config2;
5874
+ if (arg2 || arg1 && ("pageNumber" in arg1 || "pageSize" in arg1 || "templateType" in arg1)) {
5875
+ logger.warn(
5876
+ "Deprecated: listTemplates(input, config) is deprecated. Use listTemplates({ input, config }) instead."
5877
+ );
5878
+ input = arg1;
5879
+ config2 = arg2;
5880
+ } else {
5881
+ const params = arg1 ?? {};
5882
+ input = params.input;
5883
+ config2 = params.config;
5884
+ }
5793
5885
  const cfg = exports.Config.withConfigs(this.config, config2);
5794
5886
  const request = new $AgentRun3__namespace.ListTemplatesRequest({
5795
5887
  ...input
@@ -5804,18 +5896,41 @@ var init_client3 = __esm({
5804
5896
  /**
5805
5897
  * Create a Sandbox
5806
5898
  */
5807
- createSandbox = async (params) => {
5808
- const { input, config: config2 } = params;
5899
+ createSandbox = async (arg1, arg2) => {
5900
+ let input;
5901
+ let templateType;
5902
+ let config2;
5903
+ if ("templateName" in arg1) {
5904
+ logger.warn(
5905
+ "Deprecated: createSandbox(input, config) is deprecated. Use createSandbox({ input, config }) instead."
5906
+ );
5907
+ input = arg1;
5908
+ config2 = arg2;
5909
+ } else {
5910
+ const params = arg1;
5911
+ input = params.input;
5912
+ templateType = params.templateType;
5913
+ config2 = params.config;
5914
+ }
5809
5915
  const cfg = exports.Config.withConfigs(this.config, config2);
5810
5916
  try {
5811
- console.log({ input });
5812
5917
  const result = await this.controlApi.createSandbox({
5813
5918
  input: new $AgentRun3__namespace.CreateSandboxInput({
5814
5919
  ...input
5815
5920
  }),
5816
5921
  config: cfg
5817
5922
  });
5818
- return exports.Sandbox.fromInnerObject(result, cfg);
5923
+ const state = result.status ?? result.state;
5924
+ const sb = new exports.Sandbox({ ...result, state }, cfg);
5925
+ if (templateType === "CodeInterpreter" /* CODE_INTERPRETER */)
5926
+ return new exports.CodeInterpreterSandbox(sb, cfg);
5927
+ else if (templateType === "Browser" /* BROWSER */)
5928
+ return new exports.BrowserSandbox(sb, cfg);
5929
+ else if (templateType === "AllInOne" /* AIO */)
5930
+ return new exports.AioSandbox(sb, cfg);
5931
+ else if (templateType === "CustomImage" /* CUSTOM */)
5932
+ return new CustomSandbox(sb, cfg);
5933
+ return sb;
5819
5934
  } catch (error) {
5820
5935
  if (error instanceof exports.HTTPError) {
5821
5936
  throw error.toResourceError("Sandbox", input.templateName);
@@ -5850,8 +5965,19 @@ var init_client3 = __esm({
5850
5965
  /**
5851
5966
  * Delete a Sandbox
5852
5967
  */
5853
- deleteSandbox = async (params) => {
5854
- const { id, config: config2 } = params;
5968
+ deleteSandbox = async (arg1, arg2) => {
5969
+ let id;
5970
+ let config2;
5971
+ if (typeof arg1 === "string") {
5972
+ logger.warn(
5973
+ "Deprecated: deleteSandbox(id, config) is deprecated. Use deleteSandbox({ id, config }) instead."
5974
+ );
5975
+ id = arg1;
5976
+ config2 = arg2;
5977
+ } else {
5978
+ id = arg1.id;
5979
+ config2 = arg1.config;
5980
+ }
5855
5981
  const cfg = exports.Config.withConfigs(this.config, config2);
5856
5982
  try {
5857
5983
  const result = await this.controlApi.deleteSandbox({
@@ -5869,7 +5995,14 @@ var init_client3 = __esm({
5869
5995
  /**
5870
5996
  * Stop a Sandbox
5871
5997
  */
5872
- stopSandbox = async (params) => {
5998
+ stopSandbox = async (...args) => {
5999
+ let params = args?.[0];
6000
+ if (typeof args[0] === "string") {
6001
+ logger.warn(
6002
+ "Deprecated: stopSandbox(id, config) is deprecated. Use stopSandbox({ id, config }) instead."
6003
+ );
6004
+ params = { id: args[0], config: args[1] };
6005
+ }
5873
6006
  const { id, config: config2 } = params;
5874
6007
  const cfg = exports.Config.withConfigs(this.config, config2);
5875
6008
  try {
@@ -5892,8 +6025,26 @@ var init_client3 = __esm({
5892
6025
  * @param params.templateType - Template type to cast the result to the appropriate subclass
5893
6026
  * @param params.config - Configuration
5894
6027
  */
5895
- getSandbox = async (params) => {
5896
- const { id, templateType, config: config2 } = params;
6028
+ getSandbox = async (arg1, arg2, arg3) => {
6029
+ let id;
6030
+ let templateType;
6031
+ let config2;
6032
+ if (typeof arg1 === "string") {
6033
+ logger.warn(
6034
+ "Deprecated: getSandbox(id, templateType, config?) is deprecated. Use getSandbox({ id, templateType, config }) instead."
6035
+ );
6036
+ id = arg1;
6037
+ if (arg2 && typeof arg2 === "string") {
6038
+ templateType = arg2;
6039
+ config2 = arg3;
6040
+ } else {
6041
+ config2 = arg2;
6042
+ }
6043
+ } else {
6044
+ id = arg1.id;
6045
+ templateType = arg1.templateType;
6046
+ config2 = arg1.config;
6047
+ }
5897
6048
  const cfg = exports.Config.withConfigs(this.config, config2);
5898
6049
  try {
5899
6050
  const result = await this.controlApi.getSandbox({
@@ -5926,8 +6077,20 @@ var init_client3 = __esm({
5926
6077
  /**
5927
6078
  * List Sandboxes
5928
6079
  */
5929
- listSandboxes = async (params) => {
5930
- const { input, config: config2 } = params ?? {};
6080
+ listSandboxes = async (arg1, arg2) => {
6081
+ let input;
6082
+ let config2;
6083
+ if (arg2 || arg1 && ("maxResults" in arg1 || "nextToken" in arg1 || "status" in arg1 || "templateName" in arg1 || "templateType" in arg1)) {
6084
+ logger.warn(
6085
+ "Deprecated: listSandboxes(input, config) is deprecated. Use listSandboxes({ input, config }) instead."
6086
+ );
6087
+ input = arg1;
6088
+ config2 = arg2;
6089
+ } else {
6090
+ const params = arg1 ?? {};
6091
+ input = params.input;
6092
+ config2 = params.config;
6093
+ }
5931
6094
  const cfg = exports.Config.withConfigs(this.config, config2);
5932
6095
  const request = new $AgentRun3__namespace.ListSandboxesRequest({
5933
6096
  ...input