@daytonaio/sdk 0.9.2 → 0.10.0

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 (221) hide show
  1. package/dist/Daytona.d.ts +239 -47
  2. package/dist/Daytona.js +274 -63
  3. package/dist/FileSystem.d.ts +183 -32
  4. package/dist/FileSystem.js +168 -28
  5. package/dist/Git.d.ts +178 -30
  6. package/dist/Git.js +178 -30
  7. package/dist/LspServer.d.ts +170 -22
  8. package/dist/LspServer.js +162 -18
  9. package/dist/Process.d.ts +187 -37
  10. package/dist/Process.js +185 -44
  11. package/dist/Workspace.d.ts +252 -36
  12. package/dist/Workspace.js +239 -49
  13. package/dist/code-toolbox/WorkspacePythonCodeToolbox.d.ts +2 -1
  14. package/dist/code-toolbox/WorkspacePythonCodeToolbox.js +4 -2
  15. package/dist/code-toolbox/WorkspaceTsCodeToolbox.d.ts +2 -1
  16. package/dist/code-toolbox/WorkspaceTsCodeToolbox.js +4 -2
  17. package/dist/errors/DaytonaError.d.ts +8 -0
  18. package/dist/errors/DaytonaError.js +12 -0
  19. package/dist/index.d.ts +4 -0
  20. package/dist/index.js +12 -1
  21. package/dist/utils/Axios.d.ts +6 -0
  22. package/dist/utils/Axios.js +28 -0
  23. package/dist/utils/errors.d.ts +10 -0
  24. package/dist/utils/errors.js +36 -0
  25. package/dist/utils/timeout.d.ts +35 -0
  26. package/dist/utils/timeout.js +73 -0
  27. package/package.json +9 -8
  28. package/dist/client/apis/ApiKeyApi.d.ts +0 -54
  29. package/dist/client/apis/ApiKeyApi.js +0 -135
  30. package/dist/client/apis/BuildApi.d.ts +0 -95
  31. package/dist/client/apis/BuildApi.js +0 -228
  32. package/dist/client/apis/ContainerRegistryApi.d.ts +0 -68
  33. package/dist/client/apis/ContainerRegistryApi.js +0 -163
  34. package/dist/client/apis/DefaultApi.d.ts +0 -31
  35. package/dist/client/apis/DefaultApi.js +0 -72
  36. package/dist/client/apis/GitProviderApi.d.ts +0 -197
  37. package/dist/client/apis/GitProviderApi.js +0 -477
  38. package/dist/client/apis/PrebuildApi.d.ts +0 -97
  39. package/dist/client/apis/PrebuildApi.js +0 -241
  40. package/dist/client/apis/ProfileApi.d.ts +0 -51
  41. package/dist/client/apis/ProfileApi.js +0 -128
  42. package/dist/client/apis/ProjectConfigApi.d.ts +0 -94
  43. package/dist/client/apis/ProjectConfigApi.js +0 -220
  44. package/dist/client/apis/ProviderApi.d.ts +0 -71
  45. package/dist/client/apis/ProviderApi.js +0 -160
  46. package/dist/client/apis/SampleApi.d.ts +0 -28
  47. package/dist/client/apis/SampleApi.js +0 -73
  48. package/dist/client/apis/ServerApi.d.ts +0 -61
  49. package/dist/client/apis/ServerApi.js +0 -156
  50. package/dist/client/apis/TargetApi.d.ts +0 -67
  51. package/dist/client/apis/TargetApi.js +0 -159
  52. package/dist/client/apis/WorkspaceApi.d.ts +0 -141
  53. package/dist/client/apis/WorkspaceApi.js +0 -330
  54. package/dist/client/apis/WorkspaceToolboxApi.d.ts +0 -464
  55. package/dist/client/apis/WorkspaceToolboxApi.js +0 -1248
  56. package/dist/client/apis/index.d.ts +0 -14
  57. package/dist/client/apis/index.js +0 -32
  58. package/dist/client/index.d.ts +0 -3
  59. package/dist/client/index.js +0 -21
  60. package/dist/client/models/ApiKey.d.ts +0 -45
  61. package/dist/client/models/ApiKey.js +0 -60
  62. package/dist/client/models/ApikeyApiKeyType.d.ts +0 -26
  63. package/dist/client/models/ApikeyApiKeyType.js +0 -52
  64. package/dist/client/models/Build.d.ts +0 -98
  65. package/dist/client/models/Build.js +0 -91
  66. package/dist/client/models/BuildBuildState.d.ts +0 -31
  67. package/dist/client/models/BuildBuildState.js +0 -57
  68. package/dist/client/models/BuildConfig.d.ts +0 -40
  69. package/dist/client/models/BuildConfig.js +0 -57
  70. package/dist/client/models/CachedBuild.d.ts +0 -38
  71. package/dist/client/models/CachedBuild.js +0 -55
  72. package/dist/client/models/CloneTarget.d.ts +0 -25
  73. package/dist/client/models/CloneTarget.js +0 -51
  74. package/dist/client/models/CompletionContext.d.ts +0 -38
  75. package/dist/client/models/CompletionContext.js +0 -53
  76. package/dist/client/models/CompletionItem.d.ts +0 -68
  77. package/dist/client/models/CompletionItem.js +0 -63
  78. package/dist/client/models/CompletionList.d.ts +0 -39
  79. package/dist/client/models/CompletionList.js +0 -56
  80. package/dist/client/models/ContainerConfig.d.ts +0 -38
  81. package/dist/client/models/ContainerConfig.js +0 -55
  82. package/dist/client/models/ContainerRegistry.d.ts +0 -44
  83. package/dist/client/models/ContainerRegistry.js +0 -59
  84. package/dist/client/models/CreateBuildDTO.d.ts +0 -52
  85. package/dist/client/models/CreateBuildDTO.js +0 -62
  86. package/dist/client/models/CreatePrebuildDTO.d.ts +0 -56
  87. package/dist/client/models/CreatePrebuildDTO.js +0 -59
  88. package/dist/client/models/CreateProjectConfigDTO.d.ts +0 -71
  89. package/dist/client/models/CreateProjectConfigDTO.js +0 -72
  90. package/dist/client/models/CreateProjectDTO.d.ts +0 -72
  91. package/dist/client/models/CreateProjectDTO.js +0 -73
  92. package/dist/client/models/CreateProjectSourceDTO.d.ts +0 -33
  93. package/dist/client/models/CreateProjectSourceDTO.js +0 -52
  94. package/dist/client/models/CreateProviderTargetDTO.d.ts +0 -45
  95. package/dist/client/models/CreateProviderTargetDTO.js +0 -60
  96. package/dist/client/models/CreateWorkspaceDTO.d.ts +0 -51
  97. package/dist/client/models/CreateWorkspaceDTO.js +0 -64
  98. package/dist/client/models/DevcontainerConfig.d.ts +0 -32
  99. package/dist/client/models/DevcontainerConfig.js +0 -51
  100. package/dist/client/models/ExecuteRequest.d.ts +0 -38
  101. package/dist/client/models/ExecuteRequest.js +0 -53
  102. package/dist/client/models/ExecuteResponse.d.ts +0 -38
  103. package/dist/client/models/ExecuteResponse.js +0 -55
  104. package/dist/client/models/FRPSConfig.d.ts +0 -44
  105. package/dist/client/models/FRPSConfig.js +0 -59
  106. package/dist/client/models/FileInfo.d.ts +0 -74
  107. package/dist/client/models/FileInfo.js +0 -79
  108. package/dist/client/models/FileStatus.d.ts +0 -51
  109. package/dist/client/models/FileStatus.js +0 -64
  110. package/dist/client/models/GetRepositoryContext.d.ts +0 -80
  111. package/dist/client/models/GetRepositoryContext.js +0 -67
  112. package/dist/client/models/GitAddRequest.d.ts +0 -38
  113. package/dist/client/models/GitAddRequest.js +0 -55
  114. package/dist/client/models/GitBranch.d.ts +0 -38
  115. package/dist/client/models/GitBranch.js +0 -55
  116. package/dist/client/models/GitBranchRequest.d.ts +0 -38
  117. package/dist/client/models/GitBranchRequest.js +0 -55
  118. package/dist/client/models/GitCloneRequest.d.ts +0 -62
  119. package/dist/client/models/GitCloneRequest.js +0 -63
  120. package/dist/client/models/GitCommitInfo.d.ts +0 -56
  121. package/dist/client/models/GitCommitInfo.js +0 -67
  122. package/dist/client/models/GitCommitRequest.d.ts +0 -50
  123. package/dist/client/models/GitCommitRequest.js +0 -63
  124. package/dist/client/models/GitCommitResponse.d.ts +0 -32
  125. package/dist/client/models/GitCommitResponse.js +0 -51
  126. package/dist/client/models/GitNamespace.d.ts +0 -38
  127. package/dist/client/models/GitNamespace.js +0 -55
  128. package/dist/client/models/GitProvider.d.ts +0 -75
  129. package/dist/client/models/GitProvider.js +0 -76
  130. package/dist/client/models/GitPullRequest.d.ts +0 -68
  131. package/dist/client/models/GitPullRequest.js +0 -75
  132. package/dist/client/models/GitRepoRequest.d.ts +0 -44
  133. package/dist/client/models/GitRepoRequest.js +0 -55
  134. package/dist/client/models/GitRepository.d.ts +0 -87
  135. package/dist/client/models/GitRepository.js +0 -84
  136. package/dist/client/models/GitStatus.d.ts +0 -57
  137. package/dist/client/models/GitStatus.js +0 -62
  138. package/dist/client/models/GitUser.d.ts +0 -50
  139. package/dist/client/models/GitUser.js +0 -63
  140. package/dist/client/models/InstallProviderRequest.d.ts +0 -40
  141. package/dist/client/models/InstallProviderRequest.js +0 -55
  142. package/dist/client/models/ListBranchResponse.d.ts +0 -32
  143. package/dist/client/models/ListBranchResponse.js +0 -51
  144. package/dist/client/models/LogFileConfig.d.ts +0 -62
  145. package/dist/client/models/LogFileConfig.js +0 -67
  146. package/dist/client/models/LspCompletionParams.d.ts +0 -58
  147. package/dist/client/models/LspCompletionParams.js +0 -69
  148. package/dist/client/models/LspDocumentRequest.d.ts +0 -44
  149. package/dist/client/models/LspDocumentRequest.js +0 -59
  150. package/dist/client/models/LspLocation.d.ts +0 -39
  151. package/dist/client/models/LspLocation.js +0 -56
  152. package/dist/client/models/LspPosition.d.ts +0 -38
  153. package/dist/client/models/LspPosition.js +0 -55
  154. package/dist/client/models/LspRange.d.ts +0 -39
  155. package/dist/client/models/LspRange.js +0 -56
  156. package/dist/client/models/LspServerRequest.d.ts +0 -38
  157. package/dist/client/models/LspServerRequest.js +0 -55
  158. package/dist/client/models/LspSymbol.d.ts +0 -45
  159. package/dist/client/models/LspSymbol.js +0 -60
  160. package/dist/client/models/Match.d.ts +0 -44
  161. package/dist/client/models/Match.js +0 -59
  162. package/dist/client/models/NetworkKey.d.ts +0 -32
  163. package/dist/client/models/NetworkKey.js +0 -51
  164. package/dist/client/models/Position.d.ts +0 -38
  165. package/dist/client/models/Position.js +0 -55
  166. package/dist/client/models/PrebuildConfig.d.ts +0 -56
  167. package/dist/client/models/PrebuildConfig.js +0 -67
  168. package/dist/client/models/PrebuildDTO.d.ts +0 -62
  169. package/dist/client/models/PrebuildDTO.js +0 -68
  170. package/dist/client/models/ProfileData.d.ts +0 -34
  171. package/dist/client/models/ProfileData.js +0 -51
  172. package/dist/client/models/Project.d.ts +0 -91
  173. package/dist/client/models/Project.js +0 -88
  174. package/dist/client/models/ProjectConfig.d.ts +0 -84
  175. package/dist/client/models/ProjectConfig.js +0 -87
  176. package/dist/client/models/ProjectDirResponse.d.ts +0 -32
  177. package/dist/client/models/ProjectDirResponse.js +0 -49
  178. package/dist/client/models/ProjectInfo.d.ts +0 -56
  179. package/dist/client/models/ProjectInfo.js +0 -65
  180. package/dist/client/models/ProjectState.d.ts +0 -45
  181. package/dist/client/models/ProjectState.js +0 -60
  182. package/dist/client/models/Provider.d.ts +0 -44
  183. package/dist/client/models/Provider.js +0 -57
  184. package/dist/client/models/ProviderProviderInfo.d.ts +0 -44
  185. package/dist/client/models/ProviderProviderInfo.js +0 -57
  186. package/dist/client/models/ProviderProviderTargetProperty.d.ts +0 -72
  187. package/dist/client/models/ProviderProviderTargetProperty.js +0 -64
  188. package/dist/client/models/ProviderProviderTargetPropertyType.d.ts +0 -29
  189. package/dist/client/models/ProviderProviderTargetPropertyType.js +0 -55
  190. package/dist/client/models/ProviderTarget.d.ts +0 -51
  191. package/dist/client/models/ProviderTarget.js +0 -64
  192. package/dist/client/models/ReplaceRequest.d.ts +0 -44
  193. package/dist/client/models/ReplaceRequest.js +0 -59
  194. package/dist/client/models/ReplaceResult.d.ts +0 -44
  195. package/dist/client/models/ReplaceResult.js +0 -53
  196. package/dist/client/models/RepositoryUrl.d.ts +0 -32
  197. package/dist/client/models/RepositoryUrl.js +0 -51
  198. package/dist/client/models/Sample.d.ts +0 -44
  199. package/dist/client/models/Sample.js +0 -59
  200. package/dist/client/models/SearchFilesResponse.d.ts +0 -32
  201. package/dist/client/models/SearchFilesResponse.js +0 -51
  202. package/dist/client/models/ServerConfig.d.ts +0 -130
  203. package/dist/client/models/ServerConfig.js +0 -119
  204. package/dist/client/models/SetGitProviderConfig.d.ts +0 -75
  205. package/dist/client/models/SetGitProviderConfig.js +0 -70
  206. package/dist/client/models/SetProjectState.d.ts +0 -39
  207. package/dist/client/models/SetProjectState.js +0 -56
  208. package/dist/client/models/SigningMethod.d.ts +0 -25
  209. package/dist/client/models/SigningMethod.js +0 -51
  210. package/dist/client/models/Status.d.ts +0 -31
  211. package/dist/client/models/Status.js +0 -57
  212. package/dist/client/models/Workspace.d.ts +0 -51
  213. package/dist/client/models/Workspace.js +0 -64
  214. package/dist/client/models/WorkspaceDTO.d.ts +0 -58
  215. package/dist/client/models/WorkspaceDTO.js +0 -67
  216. package/dist/client/models/WorkspaceInfo.d.ts +0 -45
  217. package/dist/client/models/WorkspaceInfo.js +0 -58
  218. package/dist/client/models/index.d.ts +0 -79
  219. package/dist/client/models/index.js +0 -97
  220. package/dist/client/runtime.d.ts +0 -182
  221. package/dist/client/runtime.js +0 -340
package/dist/Daytona.js CHANGED
@@ -1,32 +1,134 @@
1
1
  "use strict";
2
+ /**
3
+ * Sandboxes are isolated development environments managed by Daytona.
4
+ * This guide covers how to create, manage, and remove Sandboxes using the SDK.
5
+ *
6
+ * @module Daytona
7
+ *
8
+ * @example
9
+ * // Initialize using environment variables (DAYTONA_API_KEY, DAYTONA_SERVER_URL, DAYTONA_TARGET)
10
+ * const daytona = new Daytona();
11
+ *
12
+ * // Create and use a workspace
13
+ * const workspace = await daytona.create({
14
+ * language: 'typescript',
15
+ * envVars: { NODE_ENV: 'development' }
16
+ * });
17
+ *
18
+ * // Execute commands in the workspace
19
+ * const response = await workspace.process.executeCommand('echo "Hello, World!"');
20
+ * console.log(response.result);
21
+ *
22
+ * // Execute code in the workspace
23
+ * const response = await workspace.process.codeRun('console.log("Hello, World!")');
24
+ * console.log(response.result);
25
+ *
26
+ * @example
27
+ * // Initialize with explicit configuration
28
+ * const daytona = new Daytona({
29
+ * apiKey: process.env.CUSTOM_API_KEY,
30
+ * serverUrl: 'https://daytona.example.com',
31
+ * target: 'us'
32
+ * });
33
+ *
34
+ * // Create a custom workspace
35
+ * const workspace = await daytona.create({
36
+ * language: 'typescript',
37
+ * image: 'node:18',
38
+ * resources: {
39
+ * cpu: 2,
40
+ * memory: 4 // 4GB RAM
41
+ * },
42
+ * autoStopInterval: 60 // Auto-stop after 1 hour of inactivity
43
+ * });
44
+ *
45
+ * // Use workspace features
46
+ * await workspace.git.clone('https://github.com/user/repo.git');
47
+ * await workspace.process.executeCommand('npm test');
48
+ */
49
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
50
+ if (k2 === undefined) k2 = k;
51
+ var desc = Object.getOwnPropertyDescriptor(m, k);
52
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
53
+ desc = { enumerable: true, get: function() { return m[k]; } };
54
+ }
55
+ Object.defineProperty(o, k2, desc);
56
+ }) : (function(o, m, k, k2) {
57
+ if (k2 === undefined) k2 = k;
58
+ o[k2] = m[k];
59
+ }));
60
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
61
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
62
+ }) : function(o, v) {
63
+ o["default"] = v;
64
+ });
65
+ var __importStar = (this && this.__importStar) || function (mod) {
66
+ if (mod && mod.__esModule) return mod;
67
+ var result = {};
68
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
69
+ __setModuleDefault(result, mod);
70
+ return result;
71
+ };
2
72
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Daytona = void 0;
73
+ exports.Daytona = exports.CodeLanguage = void 0;
4
74
  const uuid_1 = require("uuid");
5
75
  const WorkspacePythonCodeToolbox_1 = require("./code-toolbox/WorkspacePythonCodeToolbox");
6
76
  const Workspace_1 = require("./Workspace");
7
77
  const api_client_1 = require("@daytonaio/api-client");
8
78
  const WorkspaceTsCodeToolbox_1 = require("./code-toolbox/WorkspaceTsCodeToolbox");
79
+ const axios_1 = __importStar(require("axios"));
80
+ const DaytonaError_1 = require("./errors/DaytonaError");
81
+ /**
82
+ * Supported programming languages for code execution
83
+ */
84
+ var CodeLanguage;
85
+ (function (CodeLanguage) {
86
+ CodeLanguage["PYTHON"] = "python";
87
+ CodeLanguage["TYPESCRIPT"] = "typescript";
88
+ CodeLanguage["JAVASCRIPT"] = "javascript";
89
+ })(CodeLanguage || (exports.CodeLanguage = CodeLanguage = {}));
9
90
  /**
10
- * Main class for interacting with Daytona Server API
11
- * @class Daytona
91
+ * Main class for interacting with Daytona Server API.
92
+ *
93
+ * Provides methods for creating, managing, and interacting with Daytona Sandboxes.
94
+ * Can be initialized either with explicit configuration or using environment variables.
95
+ *
96
+ *
97
+ * @example
98
+ * // Using environment variables
99
+ * // Uses DAYTONA_API_KEY, DAYTONA_SERVER_URL, DAYTONA_TARGET
100
+ * const daytona = new Daytona();
101
+ * const workspace = await daytona.create();
102
+ *
103
+ * @example
104
+ * // Using explicit configuration
105
+ * const config: DaytonaConfig = {
106
+ * apiKey: "your-api-key",
107
+ * serverUrl: "https://your-server.com",
108
+ * target: "us"
109
+ * };
110
+ * const daytona = new Daytona(config);
111
+ *
112
+ * @class
12
113
  */
13
114
  class Daytona {
14
115
  /**
15
- * Creates a new Daytona client instance
116
+ * Creates a new Daytona client instance.
117
+ *
16
118
  * @param {DaytonaConfig} [config] - Configuration options
17
- * @throws {Error} When API key or server URL is missing
119
+ * @throws {DaytonaError} - `DaytonaError` - When API key or server URL is missing
18
120
  */
19
121
  constructor(config) {
20
122
  const apiKey = (config === null || config === void 0 ? void 0 : config.apiKey) || process.env.DAYTONA_API_KEY;
21
123
  if (!apiKey) {
22
- throw new Error('API key is required');
124
+ throw new DaytonaError_1.DaytonaError('API key is required');
23
125
  }
24
126
  const serverUrl = (config === null || config === void 0 ? void 0 : config.serverUrl) || process.env.DAYTONA_SERVER_URL;
25
127
  if (!serverUrl) {
26
- throw new Error('Server URL is required');
128
+ throw new DaytonaError_1.DaytonaError('Server URL is required');
27
129
  }
28
130
  const envTarget = process.env.DAYTONA_TARGET;
29
- const target = (config === null || config === void 0 ? void 0 : config.target) || envTarget;
131
+ const target = (config === null || config === void 0 ? void 0 : config.target) || envTarget || api_client_1.CreateWorkspaceTargetEnum.US;
30
132
  this.apiKey = apiKey;
31
133
  this.serverUrl = serverUrl;
32
134
  this.target = target;
@@ -38,116 +140,225 @@ class Daytona {
38
140
  },
39
141
  },
40
142
  });
41
- this.workspaceApi = new api_client_1.WorkspaceApi(configuration);
42
- this.toolboxApi = new api_client_1.ToolboxApi(configuration);
143
+ const axiosInstance = axios_1.default.create();
144
+ axiosInstance.interceptors.response.use((response) => {
145
+ return response;
146
+ }, (error) => {
147
+ var _a, _b, _c;
148
+ let errorMessage;
149
+ if (error instanceof axios_1.AxiosError && error.message.includes('timeout of')) {
150
+ errorMessage = "Operation timed out";
151
+ }
152
+ else {
153
+ errorMessage =
154
+ ((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.message) ||
155
+ ((_c = error.response) === null || _c === void 0 ? void 0 : _c.data) ||
156
+ error.message ||
157
+ String(error);
158
+ }
159
+ throw new DaytonaError_1.DaytonaError(errorMessage);
160
+ });
161
+ this.workspaceApi = new api_client_1.WorkspaceApi(configuration, '', axiosInstance);
162
+ this.toolboxApi = new api_client_1.ToolboxApi(configuration, '', axiosInstance);
43
163
  }
44
164
  /**
45
- * Creates a new workspace
46
- * @param {CreateWorkspaceParams} [params] - Parameters for workspace creation
47
- * @returns {Promise<Workspace>} The created workspace instance
165
+ * Creates Sandboxes with default or custom configurations. You can specify various parameters,
166
+ * including language, image, resources, environment variables, and volumes for the Sandbox.
167
+ *
168
+ * @param {CreateWorkspaceParams} [params] - Parameters for Sandbox creation
169
+ * @param {number} [timeout] - Timeout in seconds (0 means no timeout, default is 60)
170
+ * @returns {Promise<Workspace>} The created Sandbox instance
171
+ *
172
+ * @example
173
+ * // Create a default workspace
174
+ * const workspace = await daytona.create();
175
+ *
176
+ * @example
177
+ * // Create a custom workspace
178
+ * const params: CreateWorkspaceParams = {
179
+ * language: 'typescript',
180
+ * image: 'node:18',
181
+ * envVars: {
182
+ * NODE_ENV: 'development',
183
+ * DEBUG: 'true'
184
+ * },
185
+ * resources: {
186
+ * cpu: 2,
187
+ * memory: 4 // 4GB RAM
188
+ * },
189
+ * autoStopInterval: 60
190
+ * };
191
+ * const workspace = await daytona.create(params, 40);
48
192
  */
49
- async create(params) {
193
+ async create(params, timeout = 60) {
50
194
  var _a, _b, _c, _d;
51
- if ((params === null || params === void 0 ? void 0 : params.autoStopInterval) !== undefined && (!Number.isInteger(params.autoStopInterval) || params.autoStopInterval < 0)) {
52
- throw new Error('autoStopInterval must be a non-negative integer');
195
+ const startTime = Date.now();
196
+ if (params == null) {
197
+ params = { language: 'python' };
53
198
  }
54
- const workspaceId = (params === null || params === void 0 ? void 0 : params.id) || `sandbox-${(0, uuid_1.v4)().slice(0, 8)}`;
55
- const codeToolbox = this.getCodeToolbox(params === null || params === void 0 ? void 0 : params.language);
56
- const labels = (params === null || params === void 0 ? void 0 : params.labels) || {};
57
- if (params === null || params === void 0 ? void 0 : params.language) {
199
+ const labels = params.labels || {};
200
+ if (params.language) {
58
201
  labels[`code-toolbox-language`] = params.language;
59
202
  }
60
- if ((params === null || params === void 0 ? void 0 : params.timeout) && params.timeout < 0) {
61
- throw new Error('Timeout must be a non-negative number');
203
+ params.id = params.id || `sandbox-${(0, uuid_1.v4)().slice(0, 8)}`;
204
+ // remove this when params.timeout is removed
205
+ const effectiveTimeout = params.timeout || timeout;
206
+ if (effectiveTimeout < 0) {
207
+ throw new DaytonaError_1.DaytonaError('Timeout must be a non-negative number');
62
208
  }
63
- const response = await this.workspaceApi.createWorkspace({
64
- id: workspaceId,
65
- name: workspaceId, // todo: remove this after project refactor
66
- image: params === null || params === void 0 ? void 0 : params.image,
67
- user: params === null || params === void 0 ? void 0 : params.user,
68
- env: (params === null || params === void 0 ? void 0 : params.envVars) || {},
69
- target: this.target,
70
- cpu: (_a = params === null || params === void 0 ? void 0 : params.resources) === null || _a === void 0 ? void 0 : _a.cpu,
71
- gpu: (_b = params === null || params === void 0 ? void 0 : params.resources) === null || _b === void 0 ? void 0 : _b.gpu,
72
- memory: (_c = params === null || params === void 0 ? void 0 : params.resources) === null || _c === void 0 ? void 0 : _c.memory,
73
- disk: (_d = params === null || params === void 0 ? void 0 : params.resources) === null || _d === void 0 ? void 0 : _d.disk,
74
- autoStopInterval: params === null || params === void 0 ? void 0 : params.autoStopInterval,
75
- });
76
- const workspaceInstance = response.data;
77
- const workspace = new Workspace_1.Workspace(workspaceId, workspaceInstance, this.workspaceApi, this.toolboxApi, codeToolbox);
78
- if (!(params === null || params === void 0 ? void 0 : params.async)) {
79
- await workspace.waitUntilStarted(params === null || params === void 0 ? void 0 : params.timeout);
209
+ if (params.autoStopInterval !== undefined && (!Number.isInteger(params.autoStopInterval) || params.autoStopInterval < 0)) {
210
+ throw new DaytonaError_1.DaytonaError('autoStopInterval must be a non-negative integer');
211
+ }
212
+ const codeToolbox = this.getCodeToolbox(params.language);
213
+ try {
214
+ const response = await this.workspaceApi.createWorkspace({
215
+ id: params.id,
216
+ name: params.id,
217
+ image: params.image,
218
+ user: params.user,
219
+ env: params.envVars || {},
220
+ labels: params.labels,
221
+ public: params.public,
222
+ target: this.target,
223
+ cpu: (_a = params.resources) === null || _a === void 0 ? void 0 : _a.cpu,
224
+ gpu: (_b = params.resources) === null || _b === void 0 ? void 0 : _b.gpu,
225
+ memory: (_c = params.resources) === null || _c === void 0 ? void 0 : _c.memory,
226
+ disk: (_d = params.resources) === null || _d === void 0 ? void 0 : _d.disk,
227
+ autoStopInterval: params.autoStopInterval,
228
+ }, {
229
+ timeout: effectiveTimeout * 1000
230
+ });
231
+ const workspaceInstance = response.data;
232
+ const workspaceInfo = Workspace_1.Workspace.toWorkspaceInfo(workspaceInstance);
233
+ workspaceInstance.info = workspaceInfo;
234
+ const workspace = new Workspace_1.Workspace(params.id, workspaceInstance, this.workspaceApi, this.toolboxApi, codeToolbox);
235
+ if (!params.async) {
236
+ const timeElapsed = Date.now() - startTime;
237
+ await workspace.waitUntilStarted(effectiveTimeout ? effectiveTimeout - (timeElapsed / 1000) : 0);
238
+ }
239
+ return workspace;
240
+ }
241
+ catch (error) {
242
+ void this.workspaceApi.deleteWorkspace(params.id, true).catch(() => { });
243
+ if (error instanceof DaytonaError_1.DaytonaError && error.message.includes("Operation timed out")) {
244
+ throw new DaytonaError_1.DaytonaError(`Failed to create and start workspace within ${effectiveTimeout} seconds. Operation timed out.`);
245
+ }
246
+ throw error;
80
247
  }
81
- return workspace;
82
248
  }
83
249
  /**
84
- * Gets a workspace by its ID
85
- * @param {string} workspaceId - The ID of the workspace to retrieve
86
- * @returns {Promise<Workspace>} The workspace instance
250
+ * Gets a Sandbox by its ID.
251
+ *
252
+ * @param {string} workspaceId - The ID of the Sandbox to retrieve
253
+ * @returns {Promise<Workspace>} The Sandbox
254
+ *
255
+ * @example
256
+ * const workspace = await daytona.get('my-workspace-id');
257
+ * console.log(`Workspace state: ${workspace.instance.state}`);
87
258
  */
88
259
  async get(workspaceId) {
89
260
  const response = await this.workspaceApi.getWorkspace(workspaceId);
90
261
  const workspaceInstance = response.data;
91
262
  const language = workspaceInstance.labels && workspaceInstance.labels[`code-toolbox-language`];
92
263
  const codeToolbox = this.getCodeToolbox(language);
264
+ const workspaceInfo = Workspace_1.Workspace.toWorkspaceInfo(workspaceInstance);
265
+ workspaceInstance.info = workspaceInfo;
93
266
  return new Workspace_1.Workspace(workspaceId, workspaceInstance, this.workspaceApi, this.toolboxApi, codeToolbox);
94
267
  }
95
268
  /**
96
- * Lists all workspaces
97
- * @returns {Promise<Workspace[]>} The list of workspaces
269
+ * Lists all Sandboxes.
270
+ *
271
+ * @returns {Promise<Workspace[]>} Array of Sandboxes
272
+ *
273
+ * @example
274
+ * const workspaces = await daytona.list();
275
+ * for (const workspace of workspaces) {
276
+ * console.log(`${workspace.id}: ${workspace.instance.state}`);
277
+ * }
98
278
  */
99
279
  async list() {
100
280
  const response = await this.workspaceApi.listWorkspaces();
101
281
  return response.data.map((workspace) => {
102
282
  var _a;
103
283
  const language = (_a = workspace.labels) === null || _a === void 0 ? void 0 : _a[`code-toolbox-language`];
104
- if (language && !['python', 'javascript', 'typescript'].includes(language)) {
105
- throw new Error(`Invalid code-toolbox-language: ${language}`);
106
- }
284
+ const workspaceInfo = Workspace_1.Workspace.toWorkspaceInfo(workspace);
285
+ workspace.info = workspaceInfo;
107
286
  return new Workspace_1.Workspace(workspace.id, workspace, this.workspaceApi, this.toolboxApi, this.getCodeToolbox(language));
108
287
  });
109
288
  }
110
289
  /**
111
- * Starts a workspace
112
- * @param {Workspace} workspace - The workspace to start
290
+ * Starts a Sandbox and waits for it to be ready.
291
+ *
292
+ * @param {Workspace} workspace - The Sandbox to start
293
+ * @param {number} [timeout] - Optional timeout in seconds (0 means no timeout)
294
+ * @returns {Promise<void>}
295
+ *
296
+ * @example
297
+ * const workspace = await daytona.get('my-workspace-id');
298
+ * // Wait up to 60 seconds for the workspace to start
299
+ * await daytona.start(workspace, 60);
113
300
  */
114
301
  async start(workspace, timeout) {
115
302
  await workspace.start(timeout);
116
303
  }
117
304
  /**
118
- * Stops a workspace
119
- * @param {Workspace} workspace - The workspace to stop
305
+ * Stops a Sandbox.
306
+ *
307
+ * @param {Workspace} workspace - The Sandbox to stop
120
308
  * @returns {Promise<void>}
309
+ *
310
+ * @example
311
+ * const workspace = await daytona.get('my-workspace-id');
312
+ * await daytona.stop(workspace);
121
313
  */
122
314
  async stop(workspace) {
123
315
  await workspace.stop();
124
316
  }
125
317
  /**
126
- * Removes a workspace
127
- * @param {Workspace} workspace - The workspace to remove
318
+ * Removes a Sandbox.
319
+ *
320
+ * @param {Workspace} workspace - The Sandbox to remove
321
+ * @param {number} timeout - Timeout in seconds (0 means no timeout, default is 60)
128
322
  * @returns {Promise<void>}
323
+ *
324
+ * @example
325
+ * const workspace = await daytona.get('my-workspace-id');
326
+ * await daytona.remove(workspace);
129
327
  */
130
- async remove(workspace) {
131
- await this.workspaceApi.deleteWorkspace(workspace.id, true);
328
+ async remove(workspace, timeout = 60) {
329
+ await this.workspaceApi.deleteWorkspace(workspace.id, true, { timeout: timeout * 1000 });
132
330
  }
133
331
  /**
134
- * Gets the current workspace by ID
135
- * @param {string} workspaceId - The ID of the workspace to retrieve
136
- * @returns {Promise<Workspace>} The workspace instance
332
+ * Gets the Sandbox by ID.
333
+ *
334
+ * @param {string} workspaceId - The ID of the Sandbox to retrieve
335
+ * @returns {Promise<Workspace>} The Sandbox
336
+ *
337
+ * @example
338
+ * const workspace = await daytona.getCurrentWorkspace('my-workspace-id');
339
+ * console.log(`Current workspace state: ${workspace.instance.state}`);
137
340
  */
138
341
  async getCurrentWorkspace(workspaceId) {
139
342
  return this.get(workspaceId);
140
343
  }
344
+ /**
345
+ * Gets the appropriate code toolbox based on language.
346
+ *
347
+ * @private
348
+ * @param {CodeLanguage} [language] - Programming language for the toolbox
349
+ * @returns {WorkspaceCodeToolbox} The appropriate code toolbox instance
350
+ * @throws {DaytonaError} - `DaytonaError` - When an unsupported language is specified
351
+ */
141
352
  getCodeToolbox(language) {
142
353
  switch (language) {
143
- case 'javascript':
144
- case 'typescript':
354
+ case CodeLanguage.JAVASCRIPT:
355
+ case CodeLanguage.TYPESCRIPT:
145
356
  return new WorkspaceTsCodeToolbox_1.WorkspaceTsCodeToolbox();
146
- case 'python':
357
+ case CodeLanguage.PYTHON:
147
358
  case undefined:
148
359
  return new WorkspacePythonCodeToolbox_1.WorkspacePythonCodeToolbox();
149
360
  default:
150
- throw new Error(`Unsupported language: ${language}`);
361
+ throw new DaytonaError_1.DaytonaError(`Unsupported language: ${language}, supported languages: ${Object.values(CodeLanguage).join(', ')}`);
151
362
  }
152
363
  }
153
364
  }