@daytonaio/sdk 0.0.0-dev

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.
Files changed (59) hide show
  1. package/README.md +146 -0
  2. package/package.json +39 -0
  3. package/src/Daytona.d.ts +331 -0
  4. package/src/Daytona.js +400 -0
  5. package/src/Daytona.js.map +1 -0
  6. package/src/FileSystem.d.ts +270 -0
  7. package/src/FileSystem.js +302 -0
  8. package/src/FileSystem.js.map +1 -0
  9. package/src/Git.d.ts +211 -0
  10. package/src/Git.js +275 -0
  11. package/src/Git.js.map +1 -0
  12. package/src/Image.d.ts +264 -0
  13. package/src/Image.js +565 -0
  14. package/src/Image.js.map +1 -0
  15. package/src/LspServer.d.ts +173 -0
  16. package/src/LspServer.js +209 -0
  17. package/src/LspServer.js.map +1 -0
  18. package/src/ObjectStorage.d.ts +85 -0
  19. package/src/ObjectStorage.js +231 -0
  20. package/src/ObjectStorage.js.map +1 -0
  21. package/src/Process.d.ts +246 -0
  22. package/src/Process.js +290 -0
  23. package/src/Process.js.map +1 -0
  24. package/src/Sandbox.d.ts +266 -0
  25. package/src/Sandbox.js +389 -0
  26. package/src/Sandbox.js.map +1 -0
  27. package/src/Snapshot.d.ts +116 -0
  28. package/src/Snapshot.js +187 -0
  29. package/src/Snapshot.js.map +1 -0
  30. package/src/Volume.d.ts +79 -0
  31. package/src/Volume.js +97 -0
  32. package/src/Volume.js.map +1 -0
  33. package/src/code-toolbox/SandboxPythonCodeToolbox.d.ts +11 -0
  34. package/src/code-toolbox/SandboxPythonCodeToolbox.js +358 -0
  35. package/src/code-toolbox/SandboxPythonCodeToolbox.js.map +1 -0
  36. package/src/code-toolbox/SandboxTsCodeToolbox.d.ts +5 -0
  37. package/src/code-toolbox/SandboxTsCodeToolbox.js +17 -0
  38. package/src/code-toolbox/SandboxTsCodeToolbox.js.map +1 -0
  39. package/src/errors/DaytonaError.d.ts +10 -0
  40. package/src/errors/DaytonaError.js +20 -0
  41. package/src/errors/DaytonaError.js.map +1 -0
  42. package/src/index.d.ts +15 -0
  43. package/src/index.js +32 -0
  44. package/src/index.js.map +1 -0
  45. package/src/types/Charts.d.ts +151 -0
  46. package/src/types/Charts.js +46 -0
  47. package/src/types/Charts.js.map +1 -0
  48. package/src/types/ExecuteResponse.d.ts +26 -0
  49. package/src/types/ExecuteResponse.js +7 -0
  50. package/src/types/ExecuteResponse.js.map +1 -0
  51. package/src/utils/ArtifactParser.d.ts +13 -0
  52. package/src/utils/ArtifactParser.js +55 -0
  53. package/src/utils/ArtifactParser.js.map +1 -0
  54. package/src/utils/Path.d.ts +1 -0
  55. package/src/utils/Path.js +61 -0
  56. package/src/utils/Path.js.map +1 -0
  57. package/src/utils/Stream.d.ts +13 -0
  58. package/src/utils/Stream.js +82 -0
  59. package/src/utils/Stream.js.map +1 -0
package/src/Sandbox.js ADDED
@@ -0,0 +1,389 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2025 Daytona Platforms Inc.
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.Sandbox = void 0;
8
+ const FileSystem_1 = require("./FileSystem");
9
+ const Git_1 = require("./Git");
10
+ const Process_1 = require("./Process");
11
+ const LspServer_1 = require("./LspServer");
12
+ const DaytonaError_1 = require("./errors/DaytonaError");
13
+ const Path_1 = require("./utils/Path");
14
+ /**
15
+ * Represents a Daytona Sandbox.
16
+ *
17
+ * @property {FileSystem} fs - File system operations interface
18
+ * @property {Git} git - Git operations interface
19
+ * @property {Process} process - Process execution interface
20
+ * @property {string} id - Unique identifier for the Sandbox
21
+ * @property {string} organizationId - Organization ID of the Sandbox
22
+ * @property {string} [snapshot] - Daytona snapshot used to create the Sandbox
23
+ * @property {string} user - OS user running in the Sandbox
24
+ * @property {Record<string, string>} env - Environment variables set in the Sandbox
25
+ * @property {Record<string, string>} labels - Custom labels attached to the Sandbox
26
+ * @property {boolean} public - Whether the Sandbox is publicly accessible
27
+ * @property {string} target - Target location of the runner where the Sandbox runs
28
+ * @property {number} cpu - Number of CPUs allocated to the Sandbox
29
+ * @property {number} gpu - Number of GPUs allocated to the Sandbox
30
+ * @property {number} memory - Amount of memory allocated to the Sandbox in GiB
31
+ * @property {number} disk - Amount of disk space allocated to the Sandbox in GiB
32
+ * @property {SandboxState} state - Current state of the Sandbox (e.g., "started", "stopped")
33
+ * @property {string} [errorReason] - Error message if Sandbox is in error state
34
+ * @property {SandboxBackupStateEnum} [backupState] - Current state of Sandbox backup
35
+ * @property {string} [backupCreatedAt] - When the backup was created
36
+ * @property {number} [autoStopInterval] - Auto-stop interval in minutes
37
+ * @property {number} [autoArchiveInterval] - Auto-archive interval in minutes
38
+ * @property {string} [runnerDomain] - Domain name of the Sandbox runner
39
+ * @property {Array<SandboxVolume>} [volumes] - Volumes attached to the Sandbox
40
+ * @property {BuildInfo} [buildInfo] - Build information for the Sandbox if it was created from dynamic build
41
+ * @property {string} [createdAt] - When the Sandbox was created
42
+ * @property {string} [updatedAt] - When the Sandbox was last updated
43
+ *
44
+ * @class
45
+ */
46
+ class Sandbox {
47
+ sandboxApi;
48
+ toolboxApi;
49
+ codeToolbox;
50
+ fs;
51
+ git;
52
+ process;
53
+ id;
54
+ organizationId;
55
+ snapshot;
56
+ user;
57
+ env;
58
+ labels;
59
+ public;
60
+ target;
61
+ cpu;
62
+ gpu;
63
+ memory;
64
+ disk;
65
+ state;
66
+ errorReason;
67
+ backupState;
68
+ backupCreatedAt;
69
+ autoStopInterval;
70
+ autoArchiveInterval;
71
+ runnerDomain;
72
+ volumes;
73
+ buildInfo;
74
+ createdAt;
75
+ updatedAt;
76
+ rootDir;
77
+ /**
78
+ * Creates a new Sandbox instance
79
+ *
80
+ * @param {SandboxDto} sandboxDto - The API Sandbox instance
81
+ * @param {SandboxApi} sandboxApi - API client for Sandbox operations
82
+ * @param {ToolboxApi} toolboxApi - API client for toolbox operations
83
+ * @param {SandboxCodeToolbox} codeToolbox - Language-specific toolbox implementation
84
+ */
85
+ constructor(sandboxDto, sandboxApi, toolboxApi, codeToolbox) {
86
+ this.sandboxApi = sandboxApi;
87
+ this.toolboxApi = toolboxApi;
88
+ this.codeToolbox = codeToolbox;
89
+ this.processSandboxDto(sandboxDto);
90
+ this.rootDir = '';
91
+ this.fs = new FileSystem_1.FileSystem(this.id, this.toolboxApi, async () => await this.getRootDir());
92
+ this.git = new Git_1.Git(this.id, this.toolboxApi, async () => await this.getRootDir());
93
+ this.process = new Process_1.Process(this.id, this.codeToolbox, this.toolboxApi, async () => await this.getRootDir());
94
+ }
95
+ /**
96
+ * Gets the root directory path for the logged in user inside the Sandbox.
97
+ *
98
+ * @returns {Promise<string | undefined>} The absolute path to the Sandbox root directory for the logged in user
99
+ *
100
+ * @example
101
+ * const rootDir = await sandbox.getUserRootDir();
102
+ * console.log(`Sandbox root: ${rootDir}`);
103
+ */
104
+ async getUserRootDir() {
105
+ const response = await this.toolboxApi.getProjectDir(this.id);
106
+ return response.data.dir;
107
+ }
108
+ /**
109
+ * Creates a new Language Server Protocol (LSP) server instance.
110
+ *
111
+ * The LSP server provides language-specific features like code completion,
112
+ * diagnostics, and more.
113
+ *
114
+ * @param {LspLanguageId} languageId - The language server type (e.g., "typescript")
115
+ * @param {string} pathToProject - Path to the project root directory. Relative paths are resolved based on the user's
116
+ * root directory.
117
+ * @returns {LspServer} A new LSP server instance configured for the specified language
118
+ *
119
+ * @example
120
+ * const lsp = await sandbox.createLspServer('typescript', 'workspace/project');
121
+ */
122
+ async createLspServer(languageId, pathToProject) {
123
+ return new LspServer_1.LspServer(languageId, (0, Path_1.prefixRelativePath)(await this.getRootDir(), pathToProject), this.toolboxApi, this.id);
124
+ }
125
+ /**
126
+ * Sets labels for the Sandbox.
127
+ *
128
+ * Labels are key-value pairs that can be used to organize and identify Sandboxes.
129
+ *
130
+ * @param {Record<string, string>} labels - Dictionary of key-value pairs representing Sandbox labels
131
+ * @returns {Promise<void>}
132
+ *
133
+ * @example
134
+ * // Set sandbox labels
135
+ * await sandbox.setLabels({
136
+ * project: 'my-project',
137
+ * environment: 'development',
138
+ * team: 'backend'
139
+ * });
140
+ */
141
+ async setLabels(labels) {
142
+ this.labels = (await this.sandboxApi.replaceLabels(this.id, { labels })).data.labels;
143
+ return this.labels;
144
+ }
145
+ /**
146
+ * Start the Sandbox.
147
+ *
148
+ * This method starts the Sandbox and waits for it to be ready.
149
+ *
150
+ * @param {number} [timeout] - Maximum time to wait in seconds. 0 means no timeout.
151
+ * Defaults to 60-second timeout.
152
+ * @returns {Promise<void>}
153
+ * @throws {DaytonaError} - `DaytonaError` - If Sandbox fails to start or times out
154
+ *
155
+ * @example
156
+ * const sandbox = await daytona.getCurrentSandbox('my-sandbox');
157
+ * await sandbox.start(40); // Wait up to 40 seconds
158
+ * console.log('Sandbox started successfully');
159
+ */
160
+ async start(timeout = 60) {
161
+ if (timeout < 0) {
162
+ throw new DaytonaError_1.DaytonaError('Timeout must be a non-negative number');
163
+ }
164
+ const startTime = Date.now();
165
+ await this.sandboxApi.startSandbox(this.id, undefined, { timeout: timeout * 1000 });
166
+ await this.refreshData();
167
+ const timeElapsed = Date.now() - startTime;
168
+ await this.waitUntilStarted(timeout ? timeout - timeElapsed / 1000 : 0);
169
+ }
170
+ /**
171
+ * Stops the Sandbox.
172
+ *
173
+ * This method stops the Sandbox and waits for it to be fully stopped.
174
+ *
175
+ * @param {number} [timeout] - Maximum time to wait in seconds. 0 means no timeout.
176
+ * Defaults to 60-second timeout.
177
+ * @returns {Promise<void>}
178
+ *
179
+ * @example
180
+ * const sandbox = await daytona.getCurrentSandbox('my-sandbox');
181
+ * await sandbox.stop();
182
+ * console.log('Sandbox stopped successfully');
183
+ */
184
+ async stop(timeout = 60) {
185
+ if (timeout < 0) {
186
+ throw new DaytonaError_1.DaytonaError('Timeout must be a non-negative number');
187
+ }
188
+ const startTime = Date.now();
189
+ await this.sandboxApi.stopSandbox(this.id, undefined, { timeout: timeout * 1000 });
190
+ await this.refreshData();
191
+ const timeElapsed = Date.now() - startTime;
192
+ await this.waitUntilStopped(timeout ? timeout - timeElapsed / 1000 : 0);
193
+ }
194
+ /**
195
+ * Deletes the Sandbox.
196
+ * @returns {Promise<void>}
197
+ */
198
+ async delete(timeout = 60) {
199
+ await this.sandboxApi.deleteSandbox(this.id, true, undefined, { timeout: timeout * 1000 });
200
+ await this.refreshData();
201
+ }
202
+ /**
203
+ * Waits for the Sandbox to reach the 'started' state.
204
+ *
205
+ * This method polls the Sandbox status until it reaches the 'started' state
206
+ * or encounters an error.
207
+ *
208
+ * @param {number} [timeout] - Maximum time to wait in seconds. 0 means no timeout.
209
+ * Defaults to 60 seconds.
210
+ * @returns {Promise<void>}
211
+ * @throws {DaytonaError} - `DaytonaError` - If the sandbox ends up in an error state or fails to start within the timeout period.
212
+ */
213
+ async waitUntilStarted(timeout = 60) {
214
+ if (timeout < 0) {
215
+ throw new DaytonaError_1.DaytonaError('Timeout must be a non-negative number');
216
+ }
217
+ const checkInterval = 100; // Wait 100 ms between checks
218
+ const startTime = Date.now();
219
+ while (this.state !== 'started') {
220
+ await this.refreshData();
221
+ if (this.state === 'error') {
222
+ const errMsg = `Sandbox ${this.id} failed to start with status: ${this.state}, error reason: ${this.errorReason}`;
223
+ throw new DaytonaError_1.DaytonaError(errMsg);
224
+ }
225
+ if (timeout !== 0 && Date.now() - startTime > timeout * 1000) {
226
+ throw new DaytonaError_1.DaytonaError('Sandbox failed to become ready within the timeout period');
227
+ }
228
+ await new Promise((resolve) => setTimeout(resolve, checkInterval));
229
+ }
230
+ }
231
+ /**
232
+ * Wait for Sandbox to reach 'stopped' state.
233
+ *
234
+ * This method polls the Sandbox status until it reaches the 'stopped' state
235
+ * or encounters an error.
236
+ *
237
+ * @param {number} [timeout] - Maximum time to wait in seconds. 0 means no timeout.
238
+ * Defaults to 60 seconds.
239
+ * @returns {Promise<void>}
240
+ * @throws {DaytonaError} - `DaytonaError` - If the sandbox fails to stop within the timeout period.
241
+ */
242
+ async waitUntilStopped(timeout = 60) {
243
+ if (timeout < 0) {
244
+ throw new DaytonaError_1.DaytonaError('Timeout must be a non-negative number');
245
+ }
246
+ const checkInterval = 100; // Wait 100 ms between checks
247
+ const startTime = Date.now();
248
+ while (this.state !== 'stopped') {
249
+ await this.refreshData();
250
+ if (this.state === 'error') {
251
+ const errMsg = `Sandbox failed to stop with status: ${this.state}, error reason: ${this.errorReason}`;
252
+ throw new DaytonaError_1.DaytonaError(errMsg);
253
+ }
254
+ if (timeout !== 0 && Date.now() - startTime > timeout * 1000) {
255
+ throw new DaytonaError_1.DaytonaError('Sandbox failed to become stopped within the timeout period');
256
+ }
257
+ await new Promise((resolve) => setTimeout(resolve, checkInterval));
258
+ }
259
+ }
260
+ /**
261
+ * Refreshes the Sandbox data from the API.
262
+ *
263
+ * @returns {Promise<void>}
264
+ *
265
+ * @example
266
+ * await sandbox.refreshData();
267
+ * console.log(`Sandbox ${sandbox.id}:`);
268
+ * console.log(`State: ${sandbox.state}`);
269
+ * console.log(`Resources: ${sandbox.cpu} CPU, ${sandbox.memory} GiB RAM`);
270
+ */
271
+ async refreshData() {
272
+ const response = await this.sandboxApi.getSandbox(this.id);
273
+ this.processSandboxDto(response.data);
274
+ }
275
+ /**
276
+ * Set the auto-stop interval for the Sandbox.
277
+ *
278
+ * The Sandbox will automatically stop after being idle (no new events) for the specified interval.
279
+ * Events include any state changes or interactions with the Sandbox through the sdk.
280
+ * Interactions using Sandbox Previews are not included.
281
+ *
282
+ * @param {number} interval - Number of minutes of inactivity before auto-stopping.
283
+ * Set to 0 to disable auto-stop. Default is 15 minutes.
284
+ * @returns {Promise<void>}
285
+ * @throws {DaytonaError} - `DaytonaError` - If interval is not a non-negative integer
286
+ *
287
+ * @example
288
+ * // Auto-stop after 1 hour
289
+ * await sandbox.setAutostopInterval(60);
290
+ * // Or disable auto-stop
291
+ * await sandbox.setAutostopInterval(0);
292
+ */
293
+ async setAutostopInterval(interval) {
294
+ if (!Number.isInteger(interval) || interval < 0) {
295
+ throw new DaytonaError_1.DaytonaError('autoStopInterval must be a non-negative integer');
296
+ }
297
+ await this.sandboxApi.setAutostopInterval(this.id, interval);
298
+ this.autoStopInterval = interval;
299
+ }
300
+ /**
301
+ * Set the auto-archive interval for the Sandbox.
302
+ *
303
+ * The Sandbox will automatically archive after being continuously stopped for the specified interval.
304
+ *
305
+ * @param {number} interval - Number of minutes after which a continuously stopped Sandbox will be auto-archived.
306
+ * Set to 0 for the maximum interval. Default is 7 days.
307
+ * @returns {Promise<void>}
308
+ * @throws {DaytonaError} - `DaytonaError` - If interval is not a non-negative integer
309
+ *
310
+ * @example
311
+ * // Auto-archive after 1 hour
312
+ * await sandbox.setAutoArchiveInterval(60);
313
+ * // Or use the maximum interval
314
+ * await sandbox.setAutoArchiveInterval(0);
315
+ */
316
+ async setAutoArchiveInterval(interval) {
317
+ if (!Number.isInteger(interval) || interval < 0) {
318
+ throw new DaytonaError_1.DaytonaError('autoArchiveInterval must be a non-negative integer');
319
+ }
320
+ await this.sandboxApi.setAutoArchiveInterval(this.id, interval);
321
+ this.autoArchiveInterval = interval;
322
+ }
323
+ /**
324
+ * Retrieves the preview link for the sandbox at the specified port. If the port is closed,
325
+ * it will be opened automatically. For private sandboxes, a token is included to grant access
326
+ * to the URL.
327
+ *
328
+ * @param {number} port - The port to open the preview link on.
329
+ * @returns {PortPreviewUrl} The response object for the preview link, which includes the `url`
330
+ * and the `token` (to access private sandboxes).
331
+ *
332
+ * @example
333
+ * const previewLink = await sandbox.getPreviewLink(3000);
334
+ * console.log(`Preview URL: ${previewLink.url}`);
335
+ * console.log(`Token: ${previewLink.token}`);
336
+ */
337
+ async getPreviewLink(port) {
338
+ return (await this.sandboxApi.getPortPreviewUrl(this.id, port)).data;
339
+ }
340
+ /**
341
+ * Archives the sandbox, making it inactive and preserving its state. When sandboxes are archived, the entire filesystem
342
+ * state is moved to cost-effective object storage, making it possible to keep sandboxes available for an extended period.
343
+ * The tradeoff between archived and stopped states is that starting an archived sandbox takes more time, depending on its size.
344
+ * Sandbox must be stopped before archiving.
345
+ */
346
+ async archive() {
347
+ await this.sandboxApi.archiveSandbox(this.id);
348
+ await this.refreshData();
349
+ }
350
+ async getRootDir() {
351
+ if (!this.rootDir) {
352
+ this.rootDir = (await this.getUserRootDir()) || '';
353
+ }
354
+ return this.rootDir;
355
+ }
356
+ /**
357
+ * Assigns the API sandbox data to the Sandbox object.
358
+ *
359
+ * @param {SandboxDto} sandboxDto - The API sandbox instance to assign data from
360
+ * @returns {void}
361
+ */
362
+ processSandboxDto(sandboxDto) {
363
+ this.id = sandboxDto.id;
364
+ this.organizationId = sandboxDto.organizationId;
365
+ this.snapshot = sandboxDto.snapshot;
366
+ this.user = sandboxDto.user;
367
+ this.env = sandboxDto.env;
368
+ this.labels = sandboxDto.labels;
369
+ this.public = sandboxDto.public;
370
+ this.target = sandboxDto.target;
371
+ this.cpu = sandboxDto.cpu;
372
+ this.gpu = sandboxDto.gpu;
373
+ this.memory = sandboxDto.memory;
374
+ this.disk = sandboxDto.disk;
375
+ this.state = sandboxDto.state;
376
+ this.errorReason = sandboxDto.errorReason;
377
+ this.backupState = sandboxDto.backupState;
378
+ this.backupCreatedAt = sandboxDto.backupCreatedAt;
379
+ this.autoStopInterval = sandboxDto.autoStopInterval;
380
+ this.autoArchiveInterval = sandboxDto.autoArchiveInterval;
381
+ this.runnerDomain = sandboxDto.runnerDomain;
382
+ this.volumes = sandboxDto.volumes;
383
+ this.buildInfo = sandboxDto.buildInfo;
384
+ this.createdAt = sandboxDto.createdAt;
385
+ this.updatedAt = sandboxDto.updatedAt;
386
+ }
387
+ }
388
+ exports.Sandbox = Sandbox;
389
+ //# sourceMappingURL=Sandbox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Sandbox.js","sourceRoot":"","sources":["../../../../libs/sdk-typescript/src/Sandbox.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAaH,6CAAyC;AACzC,+BAA2B;AAC3B,uCAAkD;AAClD,2CAAsD;AACtD,wDAA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I,CAAC,MAAM,GAAG,UAAU,CAAC,MAAM,CAAA;QAC/B,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC,MAAM,CAAA;QAC/B,IAAI,CAAC,GAAG,GAAG,UAAU,CAAC,GAAG,CAAA;QACzB,IAAI,CAAC,GAAG,GAAG,UAAU,CAAC,GAAG,CAAA;QACzB,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC,MAAM,CAAA;QAC/B,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,CAAA;QAC3B,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC,KAAK,CAAA;QAC7B,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,WAAW,CAAA;QACzC,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,WAAW,CAAA;QACzC,IAAI,CAAC,eAAe,GAAG,UAAU,CAAC,eAAe,CAAA;QACjD,IAAI,CAAC,gBAAgB,GAAG,UAAU,CAAC,gBAAgB,CAAA;QACnD,IAAI,CAAC,mBAAmB,GAAG,UAAU,CAAC,mBAAmB,CAAA;QACzD,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,YAAY,CAAA;QAC3C,IAAI,CAAC,OAAO,GAAG,UAAU,CAAC,OAAO,CAAA;QACjC,IAAI,CAAC,SAAS,GAAG,UAAU,CAAC,SAAS,CAAA;QACrC,IAAI,CAAC,SAAS,GAAG,UAAU,CAAC,SAAS,CAAA;QACrC,IAAI,CAAC,SAAS,GAAG,UAAU,CAAC,SAAS,CAAA;IACvC,CAAC;CACF;AAtXD,0BAsXC"}
@@ -0,0 +1,116 @@
1
+ import { ObjectStorageApi, SnapshotDto, SnapshotsApi } from '@daytonaio/api-client';
2
+ import { Image } from './Image';
3
+ import { Resources } from './Daytona';
4
+ /**
5
+ * Represents a Daytona Snapshot which is a pre-configured sandbox.
6
+ *
7
+ * @property {string} id - Unique identifier for the Snapshot.
8
+ * @property {string} organizationId - Organization ID that owns the Snapshot.
9
+ * @property {boolean} general - Whether the Snapshot is general.
10
+ * @property {string} name - Name of the Snapshot.
11
+ * @property {string} imageName - Name of the Image of the Snapshot.
12
+ * @property {boolean} enabled - Whether the Snapshot is enabled.
13
+ * @property {SnapshotState} state - Current state of the Snapshot.
14
+ * @property {number} size - Size of the Snapshot.
15
+ * @property {string[]} entrypoint - Entrypoint of the Snapshot.
16
+ * @property {number} cpu - CPU of the Snapshot.
17
+ * @property {number} gpu - GPU of the Snapshot.
18
+ * @property {number} mem - Memory of the Snapshot in GiB.
19
+ * @property {number} disk - Disk of the Snapshot in GiB.
20
+ * @property {string} errorReason - Error reason of the Snapshot.
21
+ * @property {Date} createdAt - Timestamp when the Snapshot was created.
22
+ * @property {Date} updatedAt - Timestamp when the Snapshot was last updated.
23
+ * @property {Date} lastUsedAt - Timestamp when the Snapshot was last used.
24
+ */
25
+ export type Snapshot = SnapshotDto & {
26
+ __brand: 'Snapshot';
27
+ };
28
+ /**
29
+ * Parameters for creating a new snapshot.
30
+ *
31
+ * @property {string} name - Name of the snapshot.
32
+ * @property {string | Image} image - Image of the snapshot. If a string is provided, it should be available on some registry.
33
+ * If an Image instance is provided, it will be used to create a new image in Daytona.
34
+ * @property {Resources} resources - Resources of the snapshot.
35
+ * @property {string[]} entrypoint - Entrypoint of the snapshot.
36
+ */
37
+ export type CreateSnapshotParams = {
38
+ name: string;
39
+ image: string | Image;
40
+ resources?: Resources;
41
+ entrypoint?: string[];
42
+ };
43
+ /**
44
+ * Service for managing Daytona Snapshots. Can be used to list, get, create and delete Snapshots.
45
+ *
46
+ * @class
47
+ */
48
+ export declare class SnapshotService {
49
+ private snapshotsApi;
50
+ private objectStorageApi;
51
+ constructor(snapshotsApi: SnapshotsApi, objectStorageApi: ObjectStorageApi);
52
+ /**
53
+ * List all Snapshots.
54
+ *
55
+ * @returns {Promise<Snapshot[]>} List of all Snapshots accessible to the user
56
+ *
57
+ * @example
58
+ * const daytona = new Daytona();
59
+ * const snapshots = await daytona.snapshot.list();
60
+ * console.log(`Found ${snapshots.length} snapshots`);
61
+ * snapshots.forEach(snapshot => console.log(`${snapshot.name} (${snapshot.imageName})`));
62
+ */
63
+ list(): Promise<Snapshot[]>;
64
+ /**
65
+ * Gets a Snapshot by its name.
66
+ *
67
+ * @param {string} name - Name of the Snapshot to retrieve
68
+ * @returns {Promise<Snapshot>} The requested Snapshot
69
+ * @throws {Error} If the Snapshot does not exist or cannot be accessed
70
+ *
71
+ * @example
72
+ * const daytona = new Daytona();
73
+ * const snapshot = await daytona.snapshot.get("snapshot-name");
74
+ * console.log(`Snapshot ${snapshot.name} is in state ${snapshot.state}`);
75
+ */
76
+ get(name: string): Promise<Snapshot>;
77
+ /**
78
+ * Deletes a Snapshot.
79
+ *
80
+ * @param {Snapshot} snapshot - Snapshot to delete
81
+ * @returns {Promise<void>}
82
+ * @throws {Error} If the Snapshot does not exist or cannot be deleted
83
+ *
84
+ * @example
85
+ * const daytona = new Daytona();
86
+ * const snapshot = await daytona.snapshot.get("snapshot-name");
87
+ * await daytona.snapshot.delete(snapshot);
88
+ * console.log("Snapshot deleted successfully");
89
+ */
90
+ delete(snapshot: Snapshot): Promise<void>;
91
+ /**
92
+ * Creates and registers a new snapshot from the given Image definition.
93
+ *
94
+ * @param {CreateSnapshotParams} params - Parameters for snapshot creation.
95
+ * @param {object} options - Options for the create operation.
96
+ * @param {boolean} options.onLogs - This callback function handles snapshot creation logs.
97
+ * @param {number} options.timeout - Default is no timeout. Timeout in seconds (0 means no timeout).
98
+ * @returns {Promise<void>}
99
+ *
100
+ * @example
101
+ * const image = Image.debianSlim('3.12').pipInstall('numpy');
102
+ * await daytona.snapshot.create({ name: 'my-snapshot', image: image }, { onLogs: console.log });
103
+ */
104
+ create(params: CreateSnapshotParams, options?: {
105
+ onLogs?: (chunk: string) => void;
106
+ timeout?: number;
107
+ }): Promise<Snapshot>;
108
+ /**
109
+ * Processes the image contexts by uploading them to object storage
110
+ *
111
+ * @private
112
+ * @param {Image} image - The Image instance.
113
+ * @returns {Promise<string[]>} The list of context hashes stored in object storage.
114
+ */
115
+ static processImageContext(objectStorageApi: ObjectStorageApi, image: Image): Promise<string[]>;
116
+ }