@daytonaio/sdk 0.16.0 → 0.17.0-alpha.1

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/Daytona.d.ts CHANGED
@@ -1,5 +1,17 @@
1
- import { CreateWorkspaceTargetEnum as SandboxTargetRegion } from '@daytonaio/api-client';
1
+ import { CreateWorkspaceTargetEnum as SandboxTargetRegion, WorkspaceVolume } from '@daytonaio/api-client';
2
2
  import { Sandbox, Sandbox as Workspace } from './Sandbox';
3
+ import { VolumeService } from './Volume';
4
+ /**
5
+ * Represents a volume mount for a Sandbox.
6
+ *
7
+ * @interface
8
+ * @property {string} volumeId - ID of the Volume to mount
9
+ * @property {string} mountPath - Path on the Sandbox to mount the Volume
10
+ */
11
+ export interface VolumeMount extends WorkspaceVolume {
12
+ volumeId: string;
13
+ mountPath: string;
14
+ }
3
15
  /**
4
16
  * Configuration options for initializing the Daytona client.
5
17
  *
@@ -126,6 +138,8 @@ export type CreateSandboxParams = {
126
138
  timeout?: number;
127
139
  /** Auto-stop interval in minutes (0 means disabled) (must be a non-negative integer) */
128
140
  autoStopInterval?: number;
141
+ /** List of volumes to mount in the Sandbox */
142
+ volumes?: VolumeMount[];
129
143
  };
130
144
  /**
131
145
  * Filter for Sandboxes.
@@ -140,10 +154,10 @@ export type SandboxFilter = {
140
154
  };
141
155
  /**
142
156
  * Main class for interacting with the Daytona API.
143
- *
144
157
  * Provides methods for creating, managing, and interacting with Daytona Sandboxes.
145
158
  * Can be initialized either with explicit configuration or using environment variables.
146
159
  *
160
+ * @property {VolumeService} volume - Service for managing Daytona Volumes
147
161
  *
148
162
  * @example
149
163
  * // Using environment variables
@@ -170,6 +184,7 @@ export declare class Daytona {
170
184
  private readonly jwtToken?;
171
185
  private readonly organizationId?;
172
186
  private readonly apiUrl;
187
+ readonly volume: VolumeService;
173
188
  /**
174
189
  * Creates a new Daytona client instance.
175
190
  *
package/dist/Daytona.js CHANGED
@@ -44,6 +44,7 @@ const SandboxPythonCodeToolbox_1 = require("./code-toolbox/SandboxPythonCodeTool
44
44
  const SandboxTsCodeToolbox_1 = require("./code-toolbox/SandboxTsCodeToolbox");
45
45
  const DaytonaError_1 = require("./errors/DaytonaError");
46
46
  const Sandbox_1 = require("./Sandbox");
47
+ const Volume_1 = require("./Volume");
47
48
  /**
48
49
  * Supported programming languages for code execution
49
50
  */
@@ -55,10 +56,10 @@ var CodeLanguage;
55
56
  })(CodeLanguage || (exports.CodeLanguage = CodeLanguage = {}));
56
57
  /**
57
58
  * Main class for interacting with the Daytona API.
58
- *
59
59
  * Provides methods for creating, managing, and interacting with Daytona Sandboxes.
60
60
  * Can be initialized either with explicit configuration or using environment variables.
61
61
  *
62
+ * @property {VolumeService} volume - Service for managing Daytona Volumes
62
63
  *
63
64
  * @example
64
65
  * // Using environment variables
@@ -133,7 +134,7 @@ class Daytona {
133
134
  axiosInstance.interceptors.response.use((response) => {
134
135
  return response;
135
136
  }, (error) => {
136
- var _a, _b, _c;
137
+ var _a, _b, _c, _d, _e;
137
138
  let errorMessage;
138
139
  if (error instanceof axios_1.AxiosError && error.message.includes('timeout of')) {
139
140
  errorMessage = 'Operation timed out';
@@ -144,13 +145,19 @@ class Daytona {
144
145
  try {
145
146
  errorMessage = JSON.stringify(errorMessage);
146
147
  }
147
- catch (_d) {
148
+ catch (_f) {
148
149
  errorMessage = String(errorMessage);
149
150
  }
150
- throw new DaytonaError_1.DaytonaError(errorMessage);
151
+ switch ((_e = (_d = error.response) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.statusCode) {
152
+ case 404:
153
+ throw new DaytonaError_1.DaytonaNotFoundError(errorMessage);
154
+ default:
155
+ throw new DaytonaError_1.DaytonaError(errorMessage);
156
+ }
151
157
  });
152
158
  this.sandboxApi = new api_client_1.WorkspaceApi(configuration, '', axiosInstance);
153
159
  this.toolboxApi = new api_client_1.ToolboxApi(configuration, '', axiosInstance);
160
+ this.volume = new Volume_1.VolumeService(new api_client_1.VolumesApi(configuration, '', axiosInstance));
154
161
  }
155
162
  /**
156
163
  * Creates Sandboxes with default or custom configurations. You can specify various parameters,
@@ -182,8 +189,8 @@ class Daytona {
182
189
  * const sandbox = await daytona.create(params, 40);
183
190
  */
184
191
  async create(params, timeout = 60) {
185
- // const startTime = Date.now();
186
192
  var _a, _b, _c, _d;
193
+ const startTime = Date.now();
187
194
  if (params == null) {
188
195
  params = { language: 'python' };
189
196
  }
@@ -214,6 +221,7 @@ class Daytona {
214
221
  memory: (_c = params.resources) === null || _c === void 0 ? void 0 : _c.memory,
215
222
  disk: (_d = params.resources) === null || _d === void 0 ? void 0 : _d.disk,
216
223
  autoStopInterval: params.autoStopInterval,
224
+ volumes: params.volumes,
217
225
  }, undefined, {
218
226
  timeout: effectiveTimeout * 1000,
219
227
  });
@@ -224,10 +232,10 @@ class Daytona {
224
232
  name: '',
225
233
  };
226
234
  const sandbox = new Sandbox_1.Sandbox(sandboxInstance.id, sandboxInstance, this.sandboxApi, this.toolboxApi, codeToolbox);
227
- // if (!params.async) {
228
- // const timeElapsed = Date.now() - startTime;
229
- // await sandbox.waitUntilStarted(effectiveTimeout ? effectiveTimeout - (timeElapsed / 1000) : 0);
230
- // }
235
+ if (!params.async) {
236
+ const timeElapsed = Date.now() - startTime;
237
+ await sandbox.waitUntilStarted(effectiveTimeout ? effectiveTimeout - timeElapsed / 1000 : 0);
238
+ }
231
239
  return sandbox;
232
240
  }
233
241
  catch (error) {
package/dist/Process.d.ts CHANGED
@@ -168,7 +168,7 @@ export declare class Process {
168
168
  * @param {string} sessionId - Unique identifier of the session to use
169
169
  * @param {SessionExecuteRequest} req - Command execution request containing:
170
170
  * - command: The command to execute
171
- * - async: Whether to execute asynchronously
171
+ * - runAsync: Whether to execute asynchronously
172
172
  * @param {number} timeout - Timeout in seconds
173
173
  * @returns {Promise<SessionExecuteResponse>} Command execution results containing:
174
174
  * - cmdId: Unique identifier for the executed command
package/dist/Process.js CHANGED
@@ -202,7 +202,7 @@ class Process {
202
202
  * @param {string} sessionId - Unique identifier of the session to use
203
203
  * @param {SessionExecuteRequest} req - Command execution request containing:
204
204
  * - command: The command to execute
205
- * - async: Whether to execute asynchronously
205
+ * - runAsync: Whether to execute asynchronously
206
206
  * @param {number} timeout - Timeout in seconds
207
207
  * @returns {Promise<SessionExecuteResponse>} Command execution results containing:
208
208
  * - cmdId: Unique identifier for the executed command
package/dist/Sandbox.d.ts CHANGED
@@ -71,7 +71,7 @@ export interface SandboxInfo extends Omit<ApiSandboxInfo, 'name'> {
71
71
  /** Unique identifier */
72
72
  id: string;
73
73
  /** Docker image */
74
- image: string;
74
+ image?: string;
75
75
  /** OS user */
76
76
  user: string;
77
77
  /** Environment variables */
@@ -0,0 +1,79 @@
1
+ import { VolumeDto, VolumesApi } from '@daytonaio/api-client';
2
+ /**
3
+ * Represents a Daytona Volume which is a shared storage volume for Sandboxes.
4
+ *
5
+ * @property {string} id - Unique identifier for the Volume
6
+ * @property {string} name - Name of the Volume
7
+ * @property {string} organizationId - Organization ID that owns the Volume
8
+ * @property {string} state - Current state of the Volume
9
+ * @property {string} createdAt - Date and time when the Volume was created
10
+ * @property {string} updatedAt - Date and time when the Volume was last updated
11
+ * @property {string} lastUsedAt - Date and time when the Volume was last used
12
+ */
13
+ export type Volume = VolumeDto & {
14
+ __brand: 'Volume';
15
+ };
16
+ /**
17
+ * Service for managing Daytona Volumes.
18
+ *
19
+ * This service provides methods to list, get, create, and delete Volumes.
20
+ *
21
+ * @class
22
+ */
23
+ export declare class VolumeService {
24
+ private volumesApi;
25
+ constructor(volumesApi: VolumesApi);
26
+ /**
27
+ * Lists all available Volumes.
28
+ *
29
+ * @returns {Promise<Volume[]>} List of all Volumes accessible to the user
30
+ *
31
+ * @example
32
+ * const daytona = new Daytona();
33
+ * const volumes = await daytona.volume.list();
34
+ * console.log(`Found ${volumes.length} volumes`);
35
+ * volumes.forEach(vol => console.log(`${vol.name} (${vol.id})`));
36
+ */
37
+ list(): Promise<Volume[]>;
38
+ /**
39
+ * Gets a Volume by its name.
40
+ *
41
+ * @param {string} name - Name of the Volume to retrieve
42
+ * @param {boolean} create - Whether to create the Volume if it does not exist
43
+ * @returns {Promise<Volume>} The requested Volume
44
+ * @throws {Error} If the Volume does not exist or cannot be accessed
45
+ *
46
+ * @example
47
+ * const daytona = new Daytona();
48
+ * const volume = await daytona.volume.get("volume-name", true);
49
+ * console.log(`Volume ${volume.name} is in state ${volume.state}`);
50
+ */
51
+ get(name: string, create?: boolean): Promise<Volume>;
52
+ /**
53
+ * Creates a new Volume with the specified name.
54
+ *
55
+ * @param {string} name - Name for the new Volume
56
+ * @returns {Promise<Volume>} The newly created Volume
57
+ * @throws {Error} If the Volume cannot be created
58
+ *
59
+ * @example
60
+ * const daytona = new Daytona();
61
+ * const volume = await daytona.volume.create("my-data-volume");
62
+ * console.log(`Created volume ${volume.name} with ID ${volume.id}`);
63
+ */
64
+ create(name: string): Promise<Volume>;
65
+ /**
66
+ * Deletes a Volume.
67
+ *
68
+ * @param {Volume} volume - Volume to delete
69
+ * @returns {Promise<void>}
70
+ * @throws {Error} If the Volume does not exist or cannot be deleted
71
+ *
72
+ * @example
73
+ * const daytona = new Daytona();
74
+ * const volume = await daytona.volume.get("volume-name");
75
+ * await daytona.volume.delete(volume);
76
+ * console.log("Volume deleted successfully");
77
+ */
78
+ delete(volume: Volume): Promise<void>;
79
+ }
package/dist/Volume.js ADDED
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VolumeService = void 0;
4
+ const DaytonaError_1 = require("./errors/DaytonaError");
5
+ /**
6
+ * Service for managing Daytona Volumes.
7
+ *
8
+ * This service provides methods to list, get, create, and delete Volumes.
9
+ *
10
+ * @class
11
+ */
12
+ class VolumeService {
13
+ constructor(volumesApi) {
14
+ this.volumesApi = volumesApi;
15
+ }
16
+ /**
17
+ * Lists all available Volumes.
18
+ *
19
+ * @returns {Promise<Volume[]>} List of all Volumes accessible to the user
20
+ *
21
+ * @example
22
+ * const daytona = new Daytona();
23
+ * const volumes = await daytona.volume.list();
24
+ * console.log(`Found ${volumes.length} volumes`);
25
+ * volumes.forEach(vol => console.log(`${vol.name} (${vol.id})`));
26
+ */
27
+ async list() {
28
+ const response = await this.volumesApi.listVolumes();
29
+ return response.data;
30
+ }
31
+ /**
32
+ * Gets a Volume by its name.
33
+ *
34
+ * @param {string} name - Name of the Volume to retrieve
35
+ * @param {boolean} create - Whether to create the Volume if it does not exist
36
+ * @returns {Promise<Volume>} The requested Volume
37
+ * @throws {Error} If the Volume does not exist or cannot be accessed
38
+ *
39
+ * @example
40
+ * const daytona = new Daytona();
41
+ * const volume = await daytona.volume.get("volume-name", true);
42
+ * console.log(`Volume ${volume.name} is in state ${volume.state}`);
43
+ */
44
+ async get(name, create = false) {
45
+ try {
46
+ const response = await this.volumesApi.getVolumeByName(name);
47
+ return response.data;
48
+ }
49
+ catch (error) {
50
+ if (error instanceof DaytonaError_1.DaytonaNotFoundError &&
51
+ create &&
52
+ error.message.match(/Volume with name ([\w-]+) not found/)) {
53
+ return await this.create(name);
54
+ }
55
+ throw error;
56
+ }
57
+ }
58
+ /**
59
+ * Creates a new Volume with the specified name.
60
+ *
61
+ * @param {string} name - Name for the new Volume
62
+ * @returns {Promise<Volume>} The newly created Volume
63
+ * @throws {Error} If the Volume cannot be created
64
+ *
65
+ * @example
66
+ * const daytona = new Daytona();
67
+ * const volume = await daytona.volume.create("my-data-volume");
68
+ * console.log(`Created volume ${volume.name} with ID ${volume.id}`);
69
+ */
70
+ async create(name) {
71
+ const response = await this.volumesApi.createVolume({ name });
72
+ return response.data;
73
+ }
74
+ /**
75
+ * Deletes a Volume.
76
+ *
77
+ * @param {Volume} volume - Volume to delete
78
+ * @returns {Promise<void>}
79
+ * @throws {Error} If the Volume does not exist or cannot be deleted
80
+ *
81
+ * @example
82
+ * const daytona = new Daytona();
83
+ * const volume = await daytona.volume.get("volume-name");
84
+ * await daytona.volume.delete(volume);
85
+ * console.log("Volume deleted successfully");
86
+ */
87
+ async delete(volume) {
88
+ await this.volumesApi.deleteVolume(volume.id);
89
+ }
90
+ }
91
+ exports.VolumeService = VolumeService;
@@ -6,3 +6,5 @@
6
6
  */
7
7
  export declare class DaytonaError extends Error {
8
8
  }
9
+ export declare class DaytonaNotFoundError extends DaytonaError {
10
+ }
@@ -3,10 +3,13 @@
3
3
  * @module Errors
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.DaytonaError = void 0;
6
+ exports.DaytonaNotFoundError = exports.DaytonaError = void 0;
7
7
  /**
8
8
  * Base error for Daytona SDK.
9
9
  */
10
10
  class DaytonaError extends Error {
11
11
  }
12
12
  exports.DaytonaError = DaytonaError;
13
+ class DaytonaNotFoundError extends DaytonaError {
14
+ }
15
+ exports.DaytonaNotFoundError = DaytonaNotFoundError;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { CodeLanguage, Daytona } from './Daytona';
2
- export type { CreateSandboxParams, DaytonaConfig, SandboxResources } from './Daytona';
2
+ export type { CreateSandboxParams, DaytonaConfig, SandboxResources, VolumeMount } from './Daytona';
3
3
  export { FileSystem } from './FileSystem';
4
4
  export { Git } from './Git';
5
5
  export { LspLanguageId } from './LspServer';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@daytonaio/sdk",
3
- "version": "0.16.0",
3
+ "version": "0.17.0-alpha.1",
4
4
  "description": "Daytona client library for AI Agents",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -34,8 +34,9 @@
34
34
  "typescript": "^5.0.0"
35
35
  },
36
36
  "dependencies": {
37
- "@daytonaio/api-client": "^0.17.1",
37
+ "@daytonaio/api-client": "^0.18.0-alpha.0",
38
38
  "uuid": "^11.0.3",
39
- "@dotenvx/dotenvx": "^1.25.1"
39
+ "@dotenvx/dotenvx": "^1.25.1",
40
+ "axios": "^1.6.0"
40
41
  }
41
42
  }