@daytonaio/sdk 0.127.0 → 0.128.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.
Files changed (277) hide show
  1. package/LICENSE +190 -0
  2. package/{src → cjs}/CodeInterpreter.d.ts +1 -0
  3. package/cjs/CodeInterpreter.d.ts.map +1 -0
  4. package/cjs/CodeInterpreter.js.map +1 -0
  5. package/{src → cjs}/ComputerUse.d.ts +1 -0
  6. package/cjs/ComputerUse.d.ts.map +1 -0
  7. package/cjs/ComputerUse.js.map +1 -0
  8. package/{src → cjs}/Daytona.d.ts +1 -0
  9. package/cjs/Daytona.d.ts.map +1 -0
  10. package/{src → cjs}/Daytona.js +1 -0
  11. package/cjs/Daytona.js.map +1 -0
  12. package/{src → cjs}/FileSystem.d.ts +1 -0
  13. package/cjs/FileSystem.d.ts.map +1 -0
  14. package/cjs/FileSystem.js.map +1 -0
  15. package/{src → cjs}/Git.d.ts +1 -0
  16. package/cjs/Git.d.ts.map +1 -0
  17. package/cjs/Git.js.map +1 -0
  18. package/{src → cjs}/Image.d.ts +21 -0
  19. package/cjs/Image.d.ts.map +1 -0
  20. package/{src → cjs}/Image.js +123 -91
  21. package/cjs/Image.js.map +1 -0
  22. package/{src → cjs}/LspServer.d.ts +1 -0
  23. package/cjs/LspServer.d.ts.map +1 -0
  24. package/cjs/LspServer.js.map +1 -0
  25. package/{src → cjs}/ObjectStorage.d.ts +1 -0
  26. package/cjs/ObjectStorage.d.ts.map +1 -0
  27. package/cjs/ObjectStorage.js.map +1 -0
  28. package/{src → cjs}/Process.d.ts +1 -0
  29. package/cjs/Process.d.ts.map +1 -0
  30. package/cjs/Process.js.map +1 -0
  31. package/{src → cjs}/PtyHandle.d.ts +1 -0
  32. package/cjs/PtyHandle.d.ts.map +1 -0
  33. package/cjs/PtyHandle.js.map +1 -0
  34. package/cjs/README.md +147 -0
  35. package/{src → cjs}/Sandbox.d.ts +2 -17
  36. package/cjs/Sandbox.d.ts.map +1 -0
  37. package/{src → cjs}/Sandbox.js +1 -27
  38. package/cjs/Sandbox.js.map +1 -0
  39. package/{src → cjs}/Snapshot.d.ts +2 -0
  40. package/cjs/Snapshot.d.ts.map +1 -0
  41. package/{src → cjs}/Snapshot.js +9 -1
  42. package/cjs/Snapshot.js.map +1 -0
  43. package/{src → cjs}/Volume.d.ts +1 -0
  44. package/cjs/Volume.d.ts.map +1 -0
  45. package/cjs/Volume.js.map +1 -0
  46. package/{src → cjs}/code-toolbox/SandboxJsCodeToolbox.d.ts +1 -0
  47. package/cjs/code-toolbox/SandboxJsCodeToolbox.d.ts.map +1 -0
  48. package/cjs/code-toolbox/SandboxJsCodeToolbox.js.map +1 -0
  49. package/{src → cjs}/code-toolbox/SandboxPythonCodeToolbox.d.ts +1 -0
  50. package/cjs/code-toolbox/SandboxPythonCodeToolbox.d.ts.map +1 -0
  51. package/cjs/code-toolbox/SandboxPythonCodeToolbox.js.map +1 -0
  52. package/{src → cjs}/code-toolbox/SandboxTsCodeToolbox.d.ts +1 -0
  53. package/cjs/code-toolbox/SandboxTsCodeToolbox.d.ts.map +1 -0
  54. package/cjs/code-toolbox/SandboxTsCodeToolbox.js.map +1 -0
  55. package/{src → cjs}/errors/DaytonaError.d.ts +1 -0
  56. package/cjs/errors/DaytonaError.d.ts.map +1 -0
  57. package/cjs/errors/DaytonaError.js.map +1 -0
  58. package/{src → cjs}/index.d.ts +1 -0
  59. package/cjs/index.d.ts.map +1 -0
  60. package/cjs/index.js.map +1 -0
  61. package/cjs/package.json +3 -0
  62. package/{src → cjs}/types/Charts.d.ts +1 -0
  63. package/cjs/types/Charts.d.ts.map +1 -0
  64. package/cjs/types/Charts.js.map +1 -0
  65. package/{src → cjs}/types/CodeInterpreter.d.ts +1 -0
  66. package/cjs/types/CodeInterpreter.d.ts.map +1 -0
  67. package/cjs/types/CodeInterpreter.js.map +1 -0
  68. package/{src → cjs}/types/ExecuteResponse.d.ts +1 -0
  69. package/cjs/types/ExecuteResponse.d.ts.map +1 -0
  70. package/cjs/types/ExecuteResponse.js.map +1 -0
  71. package/{src → cjs}/types/Pty.d.ts +1 -0
  72. package/cjs/types/Pty.d.ts.map +1 -0
  73. package/cjs/types/Pty.js.map +1 -0
  74. package/{src → cjs}/utils/ArtifactParser.d.ts +1 -0
  75. package/cjs/utils/ArtifactParser.d.ts.map +1 -0
  76. package/cjs/utils/ArtifactParser.js.map +1 -0
  77. package/{src → cjs}/utils/Binary.d.ts +1 -0
  78. package/cjs/utils/Binary.d.ts.map +1 -0
  79. package/cjs/utils/Binary.js.map +1 -0
  80. package/{src → cjs}/utils/FileTransfer.d.ts +1 -0
  81. package/cjs/utils/FileTransfer.d.ts.map +1 -0
  82. package/cjs/utils/FileTransfer.js.map +1 -0
  83. package/{src → cjs}/utils/Import.d.ts +2 -15
  84. package/cjs/utils/Import.d.ts.map +1 -0
  85. package/cjs/utils/Import.js +81 -0
  86. package/cjs/utils/Import.js.map +1 -0
  87. package/{src → cjs}/utils/Multipart.d.ts +1 -0
  88. package/cjs/utils/Multipart.d.ts.map +1 -0
  89. package/cjs/utils/Multipart.js.map +1 -0
  90. package/{src → cjs}/utils/Runtime.d.ts +1 -0
  91. package/cjs/utils/Runtime.d.ts.map +1 -0
  92. package/cjs/utils/Runtime.js.map +1 -0
  93. package/{src → cjs}/utils/Stream.d.ts +1 -0
  94. package/cjs/utils/Stream.d.ts.map +1 -0
  95. package/cjs/utils/Stream.js.map +1 -0
  96. package/{src → cjs}/utils/WebSocket.d.ts +1 -0
  97. package/cjs/utils/WebSocket.d.ts.map +1 -0
  98. package/cjs/utils/WebSocket.js.map +1 -0
  99. package/esm/CodeInterpreter.d.ts +96 -0
  100. package/esm/CodeInterpreter.d.ts.map +1 -0
  101. package/esm/CodeInterpreter.js +295 -0
  102. package/esm/CodeInterpreter.js.map +1 -0
  103. package/esm/ComputerUse.d.ts +443 -0
  104. package/esm/ComputerUse.d.ts.map +1 -0
  105. package/esm/ComputerUse.js +509 -0
  106. package/esm/ComputerUse.js.map +1 -0
  107. package/esm/Daytona.d.ts +354 -0
  108. package/esm/Daytona.d.ts.map +1 -0
  109. package/esm/Daytona.js +410 -0
  110. package/esm/Daytona.js.map +1 -0
  111. package/esm/FileSystem.d.ts +328 -0
  112. package/esm/FileSystem.d.ts.map +1 -0
  113. package/esm/FileSystem.js +331 -0
  114. package/esm/FileSystem.js.map +1 -0
  115. package/esm/Git.d.ts +203 -0
  116. package/esm/Git.d.ts.map +1 -0
  117. package/esm/Git.js +260 -0
  118. package/esm/Git.js.map +1 -0
  119. package/esm/Image.d.ts +285 -0
  120. package/esm/Image.d.ts.map +1 -0
  121. package/esm/Image.js +569 -0
  122. package/esm/Image.js.map +1 -0
  123. package/esm/LspServer.d.ts +172 -0
  124. package/esm/LspServer.d.ts.map +1 -0
  125. package/esm/LspServer.js +204 -0
  126. package/esm/LspServer.js.map +1 -0
  127. package/esm/ObjectStorage.d.ts +79 -0
  128. package/esm/ObjectStorage.d.ts.map +1 -0
  129. package/esm/ObjectStorage.js +187 -0
  130. package/esm/ObjectStorage.js.map +1 -0
  131. package/esm/Process.d.ts +442 -0
  132. package/esm/Process.d.ts.map +1 -0
  133. package/esm/Process.js +644 -0
  134. package/esm/Process.js.map +1 -0
  135. package/esm/PtyHandle.d.ts +155 -0
  136. package/esm/PtyHandle.d.ts.map +1 -0
  137. package/esm/PtyHandle.js +374 -0
  138. package/esm/PtyHandle.js.map +1 -0
  139. package/esm/README.md +147 -0
  140. package/esm/Sandbox.d.ts +359 -0
  141. package/esm/Sandbox.d.ts.map +1 -0
  142. package/esm/Sandbox.js +532 -0
  143. package/esm/Sandbox.js.map +1 -0
  144. package/esm/Snapshot.d.ts +138 -0
  145. package/esm/Snapshot.d.ts.map +1 -0
  146. package/esm/Snapshot.js +207 -0
  147. package/esm/Snapshot.js.map +1 -0
  148. package/esm/Volume.d.ts +84 -0
  149. package/esm/Volume.d.ts.map +1 -0
  150. package/esm/Volume.js +95 -0
  151. package/esm/Volume.js.map +1 -0
  152. package/esm/code-toolbox/SandboxJsCodeToolbox.d.ts +6 -0
  153. package/esm/code-toolbox/SandboxJsCodeToolbox.d.ts.map +1 -0
  154. package/esm/code-toolbox/SandboxJsCodeToolbox.js +13 -0
  155. package/esm/code-toolbox/SandboxJsCodeToolbox.js.map +1 -0
  156. package/esm/code-toolbox/SandboxPythonCodeToolbox.d.ts +12 -0
  157. package/esm/code-toolbox/SandboxPythonCodeToolbox.d.ts.map +1 -0
  158. package/esm/code-toolbox/SandboxPythonCodeToolbox.js +355 -0
  159. package/esm/code-toolbox/SandboxPythonCodeToolbox.js.map +1 -0
  160. package/esm/code-toolbox/SandboxTsCodeToolbox.d.ts +6 -0
  161. package/esm/code-toolbox/SandboxTsCodeToolbox.d.ts.map +1 -0
  162. package/esm/code-toolbox/SandboxTsCodeToolbox.js +14 -0
  163. package/esm/code-toolbox/SandboxTsCodeToolbox.js.map +1 -0
  164. package/esm/errors/DaytonaError.d.ts +32 -0
  165. package/esm/errors/DaytonaError.d.ts.map +1 -0
  166. package/esm/errors/DaytonaError.js +44 -0
  167. package/esm/errors/DaytonaError.js.map +1 -0
  168. package/esm/index.d.ts +22 -0
  169. package/esm/index.d.ts.map +1 -0
  170. package/esm/index.js +22 -0
  171. package/esm/index.js.map +1 -0
  172. package/esm/package.json +3 -0
  173. package/esm/types/Charts.d.ts +152 -0
  174. package/esm/types/Charts.d.ts.map +1 -0
  175. package/esm/types/Charts.js +42 -0
  176. package/esm/types/Charts.js.map +1 -0
  177. package/esm/types/CodeInterpreter.d.ts +77 -0
  178. package/esm/types/CodeInterpreter.d.ts.map +1 -0
  179. package/esm/types/CodeInterpreter.js +6 -0
  180. package/esm/types/CodeInterpreter.js.map +1 -0
  181. package/esm/types/ExecuteResponse.d.ts +26 -0
  182. package/esm/types/ExecuteResponse.d.ts.map +1 -0
  183. package/esm/types/ExecuteResponse.js +6 -0
  184. package/esm/types/ExecuteResponse.js.map +1 -0
  185. package/esm/types/Pty.d.ts +48 -0
  186. package/esm/types/Pty.d.ts.map +1 -0
  187. package/esm/types/Pty.js +6 -0
  188. package/esm/types/Pty.js.map +1 -0
  189. package/esm/utils/ArtifactParser.d.ts +14 -0
  190. package/esm/utils/ArtifactParser.d.ts.map +1 -0
  191. package/esm/utils/ArtifactParser.js +51 -0
  192. package/esm/utils/ArtifactParser.js.map +1 -0
  193. package/esm/utils/Binary.d.ts +39 -0
  194. package/esm/utils/Binary.d.ts.map +1 -0
  195. package/esm/utils/Binary.js +157 -0
  196. package/esm/utils/Binary.js.map +1 -0
  197. package/esm/utils/FileTransfer.d.ts +15 -0
  198. package/esm/utils/FileTransfer.d.ts.map +1 -0
  199. package/esm/utils/FileTransfer.js +209 -0
  200. package/esm/utils/FileTransfer.js.map +1 -0
  201. package/esm/utils/Import.d.ts +211 -0
  202. package/esm/utils/Import.d.ts.map +1 -0
  203. package/esm/utils/Import.js +45 -0
  204. package/esm/utils/Import.js.map +1 -0
  205. package/esm/utils/Multipart.d.ts +27 -0
  206. package/esm/utils/Multipart.d.ts.map +1 -0
  207. package/esm/utils/Multipart.js +107 -0
  208. package/esm/utils/Multipart.js.map +1 -0
  209. package/esm/utils/Runtime.d.ts +37 -0
  210. package/esm/utils/Runtime.d.ts.map +1 -0
  211. package/esm/utils/Runtime.js +57 -0
  212. package/esm/utils/Runtime.js.map +1 -0
  213. package/esm/utils/Stream.d.ts +20 -0
  214. package/esm/utils/Stream.d.ts.map +1 -0
  215. package/esm/utils/Stream.js +360 -0
  216. package/esm/utils/Stream.js.map +1 -0
  217. package/esm/utils/WebSocket.d.ts +10 -0
  218. package/esm/utils/WebSocket.d.ts.map +1 -0
  219. package/esm/utils/WebSocket.js +22 -0
  220. package/esm/utils/WebSocket.js.map +1 -0
  221. package/package.json +20 -8
  222. package/src/CodeInterpreter.js.map +0 -1
  223. package/src/ComputerUse.js.map +0 -1
  224. package/src/Daytona.js.map +0 -1
  225. package/src/FileSystem.js.map +0 -1
  226. package/src/Git.js.map +0 -1
  227. package/src/Image.js.map +0 -1
  228. package/src/LspServer.js.map +0 -1
  229. package/src/ObjectStorage.js.map +0 -1
  230. package/src/Process.js.map +0 -1
  231. package/src/PtyHandle.js.map +0 -1
  232. package/src/Sandbox.js.map +0 -1
  233. package/src/Snapshot.js.map +0 -1
  234. package/src/Volume.js.map +0 -1
  235. package/src/code-toolbox/SandboxJsCodeToolbox.js.map +0 -1
  236. package/src/code-toolbox/SandboxPythonCodeToolbox.js.map +0 -1
  237. package/src/code-toolbox/SandboxTsCodeToolbox.js.map +0 -1
  238. package/src/errors/DaytonaError.js.map +0 -1
  239. package/src/index.js.map +0 -1
  240. package/src/types/Charts.js.map +0 -1
  241. package/src/types/CodeInterpreter.js.map +0 -1
  242. package/src/types/ExecuteResponse.js.map +0 -1
  243. package/src/types/Pty.js.map +0 -1
  244. package/src/utils/ArtifactParser.js.map +0 -1
  245. package/src/utils/Binary.js.map +0 -1
  246. package/src/utils/FileTransfer.js.map +0 -1
  247. package/src/utils/Import.js +0 -77
  248. package/src/utils/Import.js.map +0 -1
  249. package/src/utils/Multipart.js.map +0 -1
  250. package/src/utils/Runtime.js.map +0 -1
  251. package/src/utils/Stream.js.map +0 -1
  252. package/src/utils/WebSocket.js.map +0 -1
  253. /package/{src → cjs}/CodeInterpreter.js +0 -0
  254. /package/{src → cjs}/ComputerUse.js +0 -0
  255. /package/{src → cjs}/FileSystem.js +0 -0
  256. /package/{src → cjs}/Git.js +0 -0
  257. /package/{src → cjs}/LspServer.js +0 -0
  258. /package/{src → cjs}/ObjectStorage.js +0 -0
  259. /package/{src → cjs}/Process.js +0 -0
  260. /package/{src → cjs}/PtyHandle.js +0 -0
  261. /package/{src → cjs}/Volume.js +0 -0
  262. /package/{src → cjs}/code-toolbox/SandboxJsCodeToolbox.js +0 -0
  263. /package/{src → cjs}/code-toolbox/SandboxPythonCodeToolbox.js +0 -0
  264. /package/{src → cjs}/code-toolbox/SandboxTsCodeToolbox.js +0 -0
  265. /package/{src → cjs}/errors/DaytonaError.js +0 -0
  266. /package/{src → cjs}/index.js +0 -0
  267. /package/{src → cjs}/types/Charts.js +0 -0
  268. /package/{src → cjs}/types/CodeInterpreter.js +0 -0
  269. /package/{src → cjs}/types/ExecuteResponse.js +0 -0
  270. /package/{src → cjs}/types/Pty.js +0 -0
  271. /package/{src → cjs}/utils/ArtifactParser.js +0 -0
  272. /package/{src → cjs}/utils/Binary.js +0 -0
  273. /package/{src → cjs}/utils/FileTransfer.js +0 -0
  274. /package/{src → cjs}/utils/Multipart.js +0 -0
  275. /package/{src → cjs}/utils/Runtime.js +0 -0
  276. /package/{src → cjs}/utils/Stream.js +0 -0
  277. /package/{src → cjs}/utils/WebSocket.js +0 -0
@@ -0,0 +1,138 @@
1
+ import { ObjectStorageApi, SnapshotDto, SnapshotsApi, Configuration, PaginatedSnapshots as PaginatedSnapshotsDto } from '@daytonaio/api-client';
2
+ import { Image } from './Image.js';
3
+ import { Resources } from './Daytona.js';
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 {SnapshotState} state - Current state of the Snapshot.
13
+ * @property {number} size - Size of the Snapshot.
14
+ * @property {string[]} entrypoint - Entrypoint of the Snapshot.
15
+ * @property {number} cpu - CPU of the Snapshot.
16
+ * @property {number} gpu - GPU of the Snapshot.
17
+ * @property {number} mem - Memory of the Snapshot in GiB.
18
+ * @property {number} disk - Disk of the Snapshot in GiB.
19
+ * @property {string} errorReason - Error reason of the Snapshot.
20
+ * @property {Date} createdAt - Timestamp when the Snapshot was created.
21
+ * @property {Date} updatedAt - Timestamp when the Snapshot was last updated.
22
+ * @property {Date} lastUsedAt - Timestamp when the Snapshot was last used.
23
+ */
24
+ export type Snapshot = SnapshotDto & {
25
+ __brand: 'Snapshot';
26
+ };
27
+ /**
28
+ * Represents a paginated list of Daytona Snapshots.
29
+ *
30
+ * @property {Snapshot[]} items - List of Snapshot instances in the current page.
31
+ * @property {number} total - Total number of Snapshots across all pages.
32
+ * @property {number} page - Current page number.
33
+ * @property {number} totalPages - Total number of pages available.
34
+ */
35
+ export interface PaginatedSnapshots extends Omit<PaginatedSnapshotsDto, 'items'> {
36
+ items: Snapshot[];
37
+ }
38
+ /**
39
+ * Parameters for creating a new snapshot.
40
+ *
41
+ * @property {string} name - Name of the snapshot.
42
+ * @property {string | Image} image - Image of the snapshot. If a string is provided, it should be available on some registry.
43
+ * If an Image instance is provided, it will be used to create a new image in Daytona.
44
+ * @property {Resources} resources - Resources of the snapshot.
45
+ * @property {string[]} entrypoint - Entrypoint of the snapshot.
46
+ */
47
+ export type CreateSnapshotParams = {
48
+ name: string;
49
+ image: string | Image;
50
+ resources?: Resources;
51
+ entrypoint?: string[];
52
+ skipValidation?: boolean;
53
+ };
54
+ /**
55
+ * Service for managing Daytona Snapshots. Can be used to list, get, create and delete Snapshots.
56
+ *
57
+ * @class
58
+ */
59
+ export declare class SnapshotService {
60
+ private clientConfig;
61
+ private snapshotsApi;
62
+ private objectStorageApi;
63
+ constructor(clientConfig: Configuration, snapshotsApi: SnapshotsApi, objectStorageApi: ObjectStorageApi);
64
+ /**
65
+ * List paginated list of Snapshots.
66
+ *
67
+ * @param {number} [page] - Page number for pagination (starting from 1)
68
+ * @param {number} [limit] - Maximum number of items per page
69
+ * @returns {Promise<PaginatedSnapshots>} Paginated list of Snapshots
70
+ *
71
+ * @example
72
+ * const daytona = new Daytona();
73
+ * const result = await daytona.snapshot.list(2, 10);
74
+ * console.log(`Found ${result.total} snapshots`);
75
+ * result.items.forEach(snapshot => console.log(`${snapshot.name} (${snapshot.imageName})`));
76
+ */
77
+ list(page?: number, limit?: number): Promise<PaginatedSnapshots>;
78
+ /**
79
+ * Gets a Snapshot by its name.
80
+ *
81
+ * @param {string} name - Name of the Snapshot to retrieve
82
+ * @returns {Promise<Snapshot>} The requested Snapshot
83
+ * @throws {Error} If the Snapshot does not exist or cannot be accessed
84
+ *
85
+ * @example
86
+ * const daytona = new Daytona();
87
+ * const snapshot = await daytona.snapshot.get("snapshot-name");
88
+ * console.log(`Snapshot ${snapshot.name} is in state ${snapshot.state}`);
89
+ */
90
+ get(name: string): Promise<Snapshot>;
91
+ /**
92
+ * Deletes a Snapshot.
93
+ *
94
+ * @param {Snapshot} snapshot - Snapshot to delete
95
+ * @returns {Promise<void>}
96
+ * @throws {Error} If the Snapshot does not exist or cannot be deleted
97
+ *
98
+ * @example
99
+ * const daytona = new Daytona();
100
+ * const snapshot = await daytona.snapshot.get("snapshot-name");
101
+ * await daytona.snapshot.delete(snapshot);
102
+ * console.log("Snapshot deleted successfully");
103
+ */
104
+ delete(snapshot: Snapshot): Promise<void>;
105
+ /**
106
+ * Creates and registers a new snapshot from the given Image definition.
107
+ *
108
+ * @param {CreateSnapshotParams} params - Parameters for snapshot creation.
109
+ * @param {object} options - Options for the create operation.
110
+ * @param {boolean} options.onLogs - This callback function handles snapshot creation logs.
111
+ * @param {number} options.timeout - Default is no timeout. Timeout in seconds (0 means no timeout).
112
+ * @returns {Promise<void>}
113
+ *
114
+ * @example
115
+ * const image = Image.debianSlim('3.12').pipInstall('numpy');
116
+ * await daytona.snapshot.create({ name: 'my-snapshot', image: image }, { onLogs: console.log });
117
+ */
118
+ create(params: CreateSnapshotParams, options?: {
119
+ onLogs?: (chunk: string) => void;
120
+ timeout?: number;
121
+ }): Promise<Snapshot>;
122
+ /**
123
+ * Activates a snapshot.
124
+ *
125
+ * @param {Snapshot} snapshot - Snapshot to activate
126
+ * @returns {Promise<Snapshot>} The activated Snapshot instance
127
+ */
128
+ activate(snapshot: Snapshot): Promise<Snapshot>;
129
+ /**
130
+ * Processes the image contexts by uploading them to object storage
131
+ *
132
+ * @private
133
+ * @param {Image} image - The Image instance.
134
+ * @returns {Promise<string[]>} The list of context hashes stored in object storage.
135
+ */
136
+ static processImageContext(objectStorageApi: ObjectStorageApi, image: Image): Promise<string[]>;
137
+ }
138
+ //# sourceMappingURL=Snapshot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Snapshot.d.ts","sourceRoot":"","sources":["../../../../../libs/sdk-typescript/src/Snapshot.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,YAAY,EAGZ,aAAa,EACb,kBAAkB,IAAI,qBAAqB,EAC5C,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAIrC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,MAAM,QAAQ,GAAG,WAAW,GAAG;IAAE,OAAO,EAAE,UAAU,CAAA;CAAE,CAAA;AAE5D;;;;;;;GAOG;AACH,MAAM,WAAW,kBAAmB,SAAQ,IAAI,CAAC,qBAAqB,EAAE,OAAO,CAAC;IAC9E,KAAK,EAAE,QAAQ,EAAE,CAAA;CAClB;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,GAAG,KAAK,CAAA;IACrB,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB,CAAA;AAED;;;;GAIG;AACH,qBAAa,eAAe;IAExB,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,gBAAgB;gBAFhB,YAAY,EAAE,aAAa,EAC3B,YAAY,EAAE,YAAY,EAC1B,gBAAgB,EAAE,gBAAgB;IAG5C;;;;;;;;;;;;OAYG;IACG,IAAI,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAUtE;;;;;;;;;;;OAWG;IACG,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAK1C;;;;;;;;;;;;OAYG;IACG,MAAM,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/C;;;;;;;;;;;;OAYG;IACU,MAAM,CACjB,MAAM,EAAE,oBAAoB,EAC5B,OAAO,GAAE;QAAE,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAO,GACnE,OAAO,CAAC,QAAQ,CAAC;IAmGpB;;;;;OAKG;IACG,QAAQ,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAIrD;;;;;;OAMG;WACU,mBAAmB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CA2BtG"}
@@ -0,0 +1,207 @@
1
+ /*
2
+ * Copyright 2025 Daytona Platforms Inc.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { SnapshotState, } from '@daytonaio/api-client';
6
+ import { DaytonaError } from './errors/DaytonaError.js';
7
+ import { processStreamingResponse } from './utils/Stream.js';
8
+ import { dynamicImport } from './utils/Import.js';
9
+ /**
10
+ * Service for managing Daytona Snapshots. Can be used to list, get, create and delete Snapshots.
11
+ *
12
+ * @class
13
+ */
14
+ export class SnapshotService {
15
+ clientConfig;
16
+ snapshotsApi;
17
+ objectStorageApi;
18
+ constructor(clientConfig, snapshotsApi, objectStorageApi) {
19
+ this.clientConfig = clientConfig;
20
+ this.snapshotsApi = snapshotsApi;
21
+ this.objectStorageApi = objectStorageApi;
22
+ }
23
+ /**
24
+ * List paginated list of Snapshots.
25
+ *
26
+ * @param {number} [page] - Page number for pagination (starting from 1)
27
+ * @param {number} [limit] - Maximum number of items per page
28
+ * @returns {Promise<PaginatedSnapshots>} Paginated list of Snapshots
29
+ *
30
+ * @example
31
+ * const daytona = new Daytona();
32
+ * const result = await daytona.snapshot.list(2, 10);
33
+ * console.log(`Found ${result.total} snapshots`);
34
+ * result.items.forEach(snapshot => console.log(`${snapshot.name} (${snapshot.imageName})`));
35
+ */
36
+ async list(page, limit) {
37
+ const response = await this.snapshotsApi.getAllSnapshots(undefined, page, limit);
38
+ return {
39
+ items: response.data.items.map((snapshot) => snapshot),
40
+ total: response.data.total,
41
+ page: response.data.page,
42
+ totalPages: response.data.totalPages,
43
+ };
44
+ }
45
+ /**
46
+ * Gets a Snapshot by its name.
47
+ *
48
+ * @param {string} name - Name of the Snapshot to retrieve
49
+ * @returns {Promise<Snapshot>} The requested Snapshot
50
+ * @throws {Error} If the Snapshot does not exist or cannot be accessed
51
+ *
52
+ * @example
53
+ * const daytona = new Daytona();
54
+ * const snapshot = await daytona.snapshot.get("snapshot-name");
55
+ * console.log(`Snapshot ${snapshot.name} is in state ${snapshot.state}`);
56
+ */
57
+ async get(name) {
58
+ const response = await this.snapshotsApi.getSnapshot(name);
59
+ return response.data;
60
+ }
61
+ /**
62
+ * Deletes a Snapshot.
63
+ *
64
+ * @param {Snapshot} snapshot - Snapshot to delete
65
+ * @returns {Promise<void>}
66
+ * @throws {Error} If the Snapshot does not exist or cannot be deleted
67
+ *
68
+ * @example
69
+ * const daytona = new Daytona();
70
+ * const snapshot = await daytona.snapshot.get("snapshot-name");
71
+ * await daytona.snapshot.delete(snapshot);
72
+ * console.log("Snapshot deleted successfully");
73
+ */
74
+ async delete(snapshot) {
75
+ await this.snapshotsApi.removeSnapshot(snapshot.id);
76
+ }
77
+ /**
78
+ * Creates and registers a new snapshot from the given Image definition.
79
+ *
80
+ * @param {CreateSnapshotParams} params - Parameters for snapshot creation.
81
+ * @param {object} options - Options for the create operation.
82
+ * @param {boolean} options.onLogs - This callback function handles snapshot creation logs.
83
+ * @param {number} options.timeout - Default is no timeout. Timeout in seconds (0 means no timeout).
84
+ * @returns {Promise<void>}
85
+ *
86
+ * @example
87
+ * const image = Image.debianSlim('3.12').pipInstall('numpy');
88
+ * await daytona.snapshot.create({ name: 'my-snapshot', image: image }, { onLogs: console.log });
89
+ */
90
+ async create(params, options = {}) {
91
+ const createSnapshotReq = {
92
+ name: params.name,
93
+ };
94
+ if (typeof params.image === 'string') {
95
+ createSnapshotReq.imageName = params.image;
96
+ createSnapshotReq.entrypoint = params.entrypoint;
97
+ }
98
+ else {
99
+ const contextHashes = await SnapshotService.processImageContext(this.objectStorageApi, params.image);
100
+ createSnapshotReq.buildInfo = {
101
+ contextHashes,
102
+ dockerfileContent: params.entrypoint
103
+ ? params.image.entrypoint(params.entrypoint).dockerfile
104
+ : params.image.dockerfile,
105
+ };
106
+ }
107
+ if (params.resources) {
108
+ createSnapshotReq.cpu = params.resources.cpu;
109
+ createSnapshotReq.gpu = params.resources.gpu;
110
+ createSnapshotReq.memory = params.resources.memory;
111
+ createSnapshotReq.disk = params.resources.disk;
112
+ }
113
+ if (params.skipValidation !== undefined) {
114
+ createSnapshotReq.skipValidation = params.skipValidation;
115
+ }
116
+ let createdSnapshot = (await this.snapshotsApi.createSnapshot(createSnapshotReq, undefined, {
117
+ timeout: (options.timeout || 0) * 1000,
118
+ })).data;
119
+ if (!createdSnapshot) {
120
+ throw new DaytonaError("Failed to create snapshot. Didn't receive a snapshot from the server API.");
121
+ }
122
+ const terminalStates = [SnapshotState.ACTIVE, SnapshotState.ERROR, SnapshotState.BUILD_FAILED];
123
+ const logTerminalStates = [
124
+ ...terminalStates,
125
+ SnapshotState.PENDING_VALIDATION,
126
+ SnapshotState.VALIDATING,
127
+ ];
128
+ const snapshotRef = { createdSnapshot: createdSnapshot };
129
+ let streamPromise;
130
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
131
+ const startLogStreaming = async (onChunk = () => { }) => {
132
+ if (!streamPromise) {
133
+ const url = `${this.clientConfig.basePath}/snapshots/${createdSnapshot.id}/build-logs?follow=true`;
134
+ streamPromise = processStreamingResponse(() => fetch(url, { method: 'GET', headers: this.clientConfig.baseOptions.headers }), (chunk) => onChunk(chunk.trimEnd()), async () => logTerminalStates.includes(snapshotRef.createdSnapshot.state));
135
+ }
136
+ };
137
+ if (options.onLogs) {
138
+ options.onLogs(`Creating snapshot ${createdSnapshot.name} (${createdSnapshot.state})`);
139
+ if (createdSnapshot.state !== SnapshotState.PENDING) {
140
+ await startLogStreaming(options.onLogs);
141
+ }
142
+ }
143
+ let previousState = createdSnapshot.state;
144
+ while (!terminalStates.includes(createdSnapshot.state)) {
145
+ if (options.onLogs && previousState !== createdSnapshot.state) {
146
+ if (createdSnapshot.state !== SnapshotState.PENDING && !streamPromise) {
147
+ await startLogStreaming(options.onLogs);
148
+ }
149
+ options.onLogs(`Creating snapshot ${createdSnapshot.name} (${createdSnapshot.state})`);
150
+ previousState = createdSnapshot.state;
151
+ }
152
+ await new Promise((resolve) => setTimeout(resolve, 1000));
153
+ createdSnapshot = await this.get(createdSnapshot.name);
154
+ snapshotRef.createdSnapshot = createdSnapshot;
155
+ }
156
+ if (options.onLogs) {
157
+ if (streamPromise) {
158
+ await streamPromise;
159
+ }
160
+ if (createdSnapshot.state === SnapshotState.ACTIVE) {
161
+ options.onLogs(`Created snapshot ${createdSnapshot.name} (${createdSnapshot.state})`);
162
+ }
163
+ }
164
+ if (createdSnapshot.state === SnapshotState.ERROR || createdSnapshot.state === SnapshotState.BUILD_FAILED) {
165
+ const errMsg = `Failed to create snapshot. Name: ${createdSnapshot.name} Reason: ${createdSnapshot.errorReason}`;
166
+ throw new DaytonaError(errMsg);
167
+ }
168
+ return createdSnapshot;
169
+ }
170
+ /**
171
+ * Activates a snapshot.
172
+ *
173
+ * @param {Snapshot} snapshot - Snapshot to activate
174
+ * @returns {Promise<Snapshot>} The activated Snapshot instance
175
+ */
176
+ async activate(snapshot) {
177
+ return (await this.snapshotsApi.activateSnapshot(snapshot.id)).data;
178
+ }
179
+ /**
180
+ * Processes the image contexts by uploading them to object storage
181
+ *
182
+ * @private
183
+ * @param {Image} image - The Image instance.
184
+ * @returns {Promise<string[]>} The list of context hashes stored in object storage.
185
+ */
186
+ static async processImageContext(objectStorageApi, image) {
187
+ if (!image.contextList || !image.contextList.length) {
188
+ return [];
189
+ }
190
+ const ObjectStorageModule = await dynamicImport('ObjectStorage', '"processImageContext" is not supported: ');
191
+ const pushAccessCreds = (await objectStorageApi.getPushAccess()).data;
192
+ const objectStorage = new ObjectStorageModule.ObjectStorage({
193
+ endpointUrl: pushAccessCreds.storageUrl,
194
+ accessKeyId: pushAccessCreds.accessKey,
195
+ secretAccessKey: pushAccessCreds.secret,
196
+ sessionToken: pushAccessCreds.sessionToken,
197
+ bucketName: pushAccessCreds.bucket,
198
+ });
199
+ const contextHashes = [];
200
+ for (const context of image.contextList) {
201
+ const contextHash = await objectStorage.upload(context.sourcePath, pushAccessCreds.organizationId, context.archivePath);
202
+ contextHashes.push(contextHash);
203
+ }
204
+ return contextHashes;
205
+ }
206
+ }
207
+ //# sourceMappingURL=Snapshot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Snapshot.js","sourceRoot":"","sources":["../../../../../libs/sdk-typescript/src/Snapshot.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAIL,aAAa,GAId,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAGpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAA;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAqD9C;;;;GAIG;AACH,MAAM,OAAO,eAAe;IAEhB;IACA;IACA;IAHV,YACU,YAA2B,EAC3B,YAA0B,EAC1B,gBAAkC;QAFlC,iBAAY,GAAZ,YAAY,CAAe;QAC3B,iBAAY,GAAZ,YAAY,CAAc;QAC1B,qBAAgB,GAAhB,gBAAgB,CAAkB;IACzC,CAAC;IAE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MAAM,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,IAAgB,CAAA;IACjF,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,KAAK,CAAC,mBAAmB,CAAC,gBAAkC,EAAE,KAAY;QAC/E,IAAI,CAAC,KAAK,CAAC,WAAW,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;YACpD,OAAO,EAAE,CAAA;QACX,CAAC;QAED,MAAM,mBAAmB,GAAG,MAAM,aAAa,CAAC,eAAe,EAAE,0CAA0C,CAAC,CAAA;QAC5G,MAAM,eAAe,GAAG,CAAC,MAAM,gBAAgB,CAAC,aAAa,EAAE,CAAC,CAAC,IAAI,CAAA;QACrE,MAAM,aAAa,GAAG,IAAI,mBAAmB,CAAC,aAAa,CAAC;YAC1D,WAAW,EAAE,eAAe,CAAC,UAAU;YACvC,WAAW,EAAE,eAAe,CAAC,SAAS;YACtC,eAAe,EAAE,eAAe,CAAC,MAAM;YACvC,YAAY,EAAE,eAAe,CAAC,YAAY;YAC1C,UAAU,EAAE,eAAe,CAAC,MAAM;SACnC,CAAC,CAAA;QAEF,MAAM,aAAa,GAAG,EAAE,CAAA;QACxB,KAAK,MAAM,OAAO,IAAI,KAAK,CAAC,WAAW,EAAE,CAAC;YACxC,MAAM,WAAW,GAAG,MAAM,aAAa,CAAC,MAAM,CAC5C,OAAO,CAAC,UAAU,EAClB,eAAe,CAAC,cAAc,EAC9B,OAAO,CAAC,WAAW,CACpB,CAAA;YACD,aAAa,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;QACjC,CAAC;QAED,OAAO,aAAa,CAAA;IACtB,CAAC;CACF"}
@@ -0,0 +1,84 @@
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
+ * Volumes can be mounted to Sandboxes with an optional subpath parameter to mount
22
+ * only a specific S3 prefix within the volume. When no subpath is specified,
23
+ * the entire volume is mounted.
24
+ *
25
+ * @class
26
+ */
27
+ export declare class VolumeService {
28
+ private volumesApi;
29
+ constructor(volumesApi: VolumesApi);
30
+ /**
31
+ * Lists all available Volumes.
32
+ *
33
+ * @returns {Promise<Volume[]>} List of all Volumes accessible to the user
34
+ *
35
+ * @example
36
+ * const daytona = new Daytona();
37
+ * const volumes = await daytona.volume.list();
38
+ * console.log(`Found ${volumes.length} volumes`);
39
+ * volumes.forEach(vol => console.log(`${vol.name} (${vol.id})`));
40
+ */
41
+ list(): Promise<Volume[]>;
42
+ /**
43
+ * Gets a Volume by its name.
44
+ *
45
+ * @param {string} name - Name of the Volume to retrieve
46
+ * @param {boolean} create - Whether to create the Volume if it does not exist
47
+ * @returns {Promise<Volume>} The requested Volume
48
+ * @throws {Error} If the Volume does not exist or cannot be accessed
49
+ *
50
+ * @example
51
+ * const daytona = new Daytona();
52
+ * const volume = await daytona.volume.get("volume-name", true);
53
+ * console.log(`Volume ${volume.name} is in state ${volume.state}`);
54
+ */
55
+ get(name: string, create?: boolean): Promise<Volume>;
56
+ /**
57
+ * Creates a new Volume with the specified name.
58
+ *
59
+ * @param {string} name - Name for the new Volume
60
+ * @returns {Promise<Volume>} The newly created Volume
61
+ * @throws {Error} If the Volume cannot be created
62
+ *
63
+ * @example
64
+ * const daytona = new Daytona();
65
+ * const volume = await daytona.volume.create("my-data-volume");
66
+ * console.log(`Created volume ${volume.name} with ID ${volume.id}`);
67
+ */
68
+ create(name: string): Promise<Volume>;
69
+ /**
70
+ * Deletes a Volume.
71
+ *
72
+ * @param {Volume} volume - Volume to delete
73
+ * @returns {Promise<void>}
74
+ * @throws {Error} If the Volume does not exist or cannot be deleted
75
+ *
76
+ * @example
77
+ * const daytona = new Daytona();
78
+ * const volume = await daytona.volume.get("volume-name");
79
+ * await daytona.volume.delete(volume);
80
+ * console.log("Volume deleted successfully");
81
+ */
82
+ delete(volume: Volume): Promise<void>;
83
+ }
84
+ //# sourceMappingURL=Volume.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Volume.d.ts","sourceRoot":"","sources":["../../../../../libs/sdk-typescript/src/Volume.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAG7D;;;;;;;;;;GAUG;AACH,MAAM,MAAM,MAAM,GAAG,SAAS,GAAG;IAAE,OAAO,EAAE,QAAQ,CAAA;CAAE,CAAA;AAEtD;;;;;;;;;;GAUG;AACH,qBAAa,aAAa;IACZ,OAAO,CAAC,UAAU;gBAAV,UAAU,EAAE,UAAU;IAE1C;;;;;;;;;;OAUG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAK/B;;;;;;;;;;;;OAYG;IACG,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,UAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;IAYxD;;;;;;;;;;;OAWG;IACG,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAK3C;;;;;;;;;;;;OAYG;IACG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAG5C"}
package/esm/Volume.js ADDED
@@ -0,0 +1,95 @@
1
+ /*
2
+ * Copyright 2025 Daytona Platforms Inc.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { DaytonaNotFoundError } from './errors/DaytonaError.js';
6
+ /**
7
+ * Service for managing Daytona Volumes.
8
+ *
9
+ * This service provides methods to list, get, create, and delete Volumes.
10
+ *
11
+ * Volumes can be mounted to Sandboxes with an optional subpath parameter to mount
12
+ * only a specific S3 prefix within the volume. When no subpath is specified,
13
+ * the entire volume is mounted.
14
+ *
15
+ * @class
16
+ */
17
+ export class VolumeService {
18
+ volumesApi;
19
+ constructor(volumesApi) {
20
+ this.volumesApi = volumesApi;
21
+ }
22
+ /**
23
+ * Lists all available Volumes.
24
+ *
25
+ * @returns {Promise<Volume[]>} List of all Volumes accessible to the user
26
+ *
27
+ * @example
28
+ * const daytona = new Daytona();
29
+ * const volumes = await daytona.volume.list();
30
+ * console.log(`Found ${volumes.length} volumes`);
31
+ * volumes.forEach(vol => console.log(`${vol.name} (${vol.id})`));
32
+ */
33
+ async list() {
34
+ const response = await this.volumesApi.listVolumes();
35
+ return response.data;
36
+ }
37
+ /**
38
+ * Gets a Volume by its name.
39
+ *
40
+ * @param {string} name - Name of the Volume to retrieve
41
+ * @param {boolean} create - Whether to create the Volume if it does not exist
42
+ * @returns {Promise<Volume>} The requested Volume
43
+ * @throws {Error} If the Volume does not exist or cannot be accessed
44
+ *
45
+ * @example
46
+ * const daytona = new Daytona();
47
+ * const volume = await daytona.volume.get("volume-name", true);
48
+ * console.log(`Volume ${volume.name} is in state ${volume.state}`);
49
+ */
50
+ async get(name, create = false) {
51
+ try {
52
+ const response = await this.volumesApi.getVolumeByName(name);
53
+ return response.data;
54
+ }
55
+ catch (error) {
56
+ if (error instanceof DaytonaNotFoundError && create) {
57
+ return await this.create(name);
58
+ }
59
+ throw error;
60
+ }
61
+ }
62
+ /**
63
+ * Creates a new Volume with the specified name.
64
+ *
65
+ * @param {string} name - Name for the new Volume
66
+ * @returns {Promise<Volume>} The newly created Volume
67
+ * @throws {Error} If the Volume cannot be created
68
+ *
69
+ * @example
70
+ * const daytona = new Daytona();
71
+ * const volume = await daytona.volume.create("my-data-volume");
72
+ * console.log(`Created volume ${volume.name} with ID ${volume.id}`);
73
+ */
74
+ async create(name) {
75
+ const response = await this.volumesApi.createVolume({ name });
76
+ return response.data;
77
+ }
78
+ /**
79
+ * Deletes a Volume.
80
+ *
81
+ * @param {Volume} volume - Volume to delete
82
+ * @returns {Promise<void>}
83
+ * @throws {Error} If the Volume does not exist or cannot be deleted
84
+ *
85
+ * @example
86
+ * const daytona = new Daytona();
87
+ * const volume = await daytona.volume.get("volume-name");
88
+ * await daytona.volume.delete(volume);
89
+ * console.log("Volume deleted successfully");
90
+ */
91
+ async delete(volume) {
92
+ await this.volumesApi.deleteVolume(volume.id);
93
+ }
94
+ }
95
+ //# sourceMappingURL=Volume.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Volume.js","sourceRoot":"","sources":["../../../../../libs/sdk-typescript/src/Volume.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AAe5D;;;;;;;;;;GAUG;AACH,MAAM,OAAO,aAAa;IACJ;IAApB,YAAoB,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;IAAG,CAAC;IAE9C;;;;;;;;;;OAUG;IACH,KAAK,CAAC,IAAI;QACR,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE,CAAA;QACpD,OAAO,QAAQ,CAAC,IAAgB,CAAA;IAClC,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,GAAG,CAAC,IAAY,EAAE,MAAM,GAAG,KAAK;QACpC,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,IAAI,CAAC,CAAA;YAC5D,OAAO,QAAQ,CAAC,IAAc,CAAA;QAChC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,oBAAoB,IAAI,MAAM,EAAE,CAAC;gBACpD,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;YAChC,CAAC;YACD,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,MAAM,CAAC,IAAY;QACvB,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,CAAC,CAAA;QAC7D,OAAO,QAAQ,CAAC,IAAc,CAAA;IAChC,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,MAAM,CAAC,MAAc;QACzB,MAAM,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;IAC/C,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ import { SandboxCodeToolbox } from '../Sandbox.js';
2
+ import { CodeRunParams } from '../Process.js';
3
+ export declare class SandboxJsCodeToolbox implements SandboxCodeToolbox {
4
+ getRunCommand(code: string, params?: CodeRunParams): string;
5
+ }
6
+ //# sourceMappingURL=SandboxJsCodeToolbox.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SandboxJsCodeToolbox.d.ts","sourceRoot":"","sources":["../../../../../../libs/sdk-typescript/src/code-toolbox/SandboxJsCodeToolbox.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAG1C,qBAAa,oBAAqB,YAAW,kBAAkB;IACtD,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,aAAa,GAAG,MAAM;CAMnE"}
@@ -0,0 +1,13 @@
1
+ /*
2
+ * Copyright 2025 Daytona Platforms Inc.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { Buffer } from 'buffer';
6
+ export class SandboxJsCodeToolbox {
7
+ getRunCommand(code, params) {
8
+ const base64Code = Buffer.from(code).toString('base64');
9
+ const argv = params?.argv ? params.argv.join(' ') : '';
10
+ return `sh -c 'echo ${base64Code} | base64 --decode | node -e "$(cat)" ${argv} 2>&1 | grep -vE "npm notice"'`;
11
+ }
12
+ }
13
+ //# sourceMappingURL=SandboxJsCodeToolbox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SandboxJsCodeToolbox.js","sourceRoot":"","sources":["../../../../../../libs/sdk-typescript/src/code-toolbox/SandboxJsCodeToolbox.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/B,MAAM,OAAO,oBAAoB;IACxB,aAAa,CAAC,IAAY,EAAE,MAAsB;QACvD,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;QACvD,MAAM,IAAI,GAAG,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;QAEtD,OAAO,eAAe,UAAU,yCAAyC,IAAI,gCAAgC,CAAA;IAC/G,CAAC;CACF"}
@@ -0,0 +1,12 @@
1
+ import { SandboxCodeToolbox } from '../Sandbox.js';
2
+ import { CodeRunParams } from '../Process.js';
3
+ export declare class SandboxPythonCodeToolbox implements SandboxCodeToolbox {
4
+ getRunCommand(code: string, params?: CodeRunParams): string;
5
+ /**
6
+ * Checks if matplotlib is imported in the given Python code string.
7
+ * @param codeString Python code as a string
8
+ * @returns True if matplotlib is imported, false otherwise
9
+ */
10
+ private static isMatplotlibImported;
11
+ }
12
+ //# sourceMappingURL=SandboxPythonCodeToolbox.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SandboxPythonCodeToolbox.d.ts","sourceRoot":"","sources":["../../../../../../libs/sdk-typescript/src/code-toolbox/SandboxPythonCodeToolbox.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAG1C,qBAAa,wBAAyB,YAAW,kBAAkB;IAC1D,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,aAAa,GAAG,MAAM;IAoBlE;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,oBAAoB;CAyBpC"}