@daytonaio/sdk 0.9.0 → 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 (222) hide show
  1. package/README.md +4 -4
  2. package/dist/Daytona.d.ts +243 -47
  3. package/dist/Daytona.js +278 -60
  4. package/dist/FileSystem.d.ts +183 -32
  5. package/dist/FileSystem.js +168 -28
  6. package/dist/Git.d.ts +178 -30
  7. package/dist/Git.js +178 -30
  8. package/dist/LspServer.d.ts +170 -22
  9. package/dist/LspServer.js +162 -18
  10. package/dist/Process.d.ts +187 -37
  11. package/dist/Process.js +185 -44
  12. package/dist/Workspace.d.ts +257 -35
  13. package/dist/Workspace.js +255 -48
  14. package/dist/code-toolbox/WorkspacePythonCodeToolbox.d.ts +2 -1
  15. package/dist/code-toolbox/WorkspacePythonCodeToolbox.js +4 -2
  16. package/dist/code-toolbox/WorkspaceTsCodeToolbox.d.ts +2 -1
  17. package/dist/code-toolbox/WorkspaceTsCodeToolbox.js +4 -2
  18. package/dist/errors/DaytonaError.d.ts +8 -0
  19. package/dist/errors/DaytonaError.js +12 -0
  20. package/dist/index.d.ts +4 -0
  21. package/dist/index.js +12 -1
  22. package/dist/utils/Axios.d.ts +6 -0
  23. package/dist/utils/Axios.js +28 -0
  24. package/dist/utils/errors.d.ts +10 -0
  25. package/dist/utils/errors.js +36 -0
  26. package/dist/utils/timeout.d.ts +35 -0
  27. package/dist/utils/timeout.js +73 -0
  28. package/package.json +11 -10
  29. package/dist/client/apis/ApiKeyApi.d.ts +0 -54
  30. package/dist/client/apis/ApiKeyApi.js +0 -135
  31. package/dist/client/apis/BuildApi.d.ts +0 -95
  32. package/dist/client/apis/BuildApi.js +0 -228
  33. package/dist/client/apis/ContainerRegistryApi.d.ts +0 -68
  34. package/dist/client/apis/ContainerRegistryApi.js +0 -163
  35. package/dist/client/apis/DefaultApi.d.ts +0 -31
  36. package/dist/client/apis/DefaultApi.js +0 -72
  37. package/dist/client/apis/GitProviderApi.d.ts +0 -197
  38. package/dist/client/apis/GitProviderApi.js +0 -477
  39. package/dist/client/apis/PrebuildApi.d.ts +0 -97
  40. package/dist/client/apis/PrebuildApi.js +0 -241
  41. package/dist/client/apis/ProfileApi.d.ts +0 -51
  42. package/dist/client/apis/ProfileApi.js +0 -128
  43. package/dist/client/apis/ProjectConfigApi.d.ts +0 -94
  44. package/dist/client/apis/ProjectConfigApi.js +0 -220
  45. package/dist/client/apis/ProviderApi.d.ts +0 -71
  46. package/dist/client/apis/ProviderApi.js +0 -160
  47. package/dist/client/apis/SampleApi.d.ts +0 -28
  48. package/dist/client/apis/SampleApi.js +0 -73
  49. package/dist/client/apis/ServerApi.d.ts +0 -61
  50. package/dist/client/apis/ServerApi.js +0 -156
  51. package/dist/client/apis/TargetApi.d.ts +0 -67
  52. package/dist/client/apis/TargetApi.js +0 -159
  53. package/dist/client/apis/WorkspaceApi.d.ts +0 -141
  54. package/dist/client/apis/WorkspaceApi.js +0 -330
  55. package/dist/client/apis/WorkspaceToolboxApi.d.ts +0 -464
  56. package/dist/client/apis/WorkspaceToolboxApi.js +0 -1248
  57. package/dist/client/apis/index.d.ts +0 -14
  58. package/dist/client/apis/index.js +0 -32
  59. package/dist/client/index.d.ts +0 -3
  60. package/dist/client/index.js +0 -21
  61. package/dist/client/models/ApiKey.d.ts +0 -45
  62. package/dist/client/models/ApiKey.js +0 -60
  63. package/dist/client/models/ApikeyApiKeyType.d.ts +0 -26
  64. package/dist/client/models/ApikeyApiKeyType.js +0 -52
  65. package/dist/client/models/Build.d.ts +0 -98
  66. package/dist/client/models/Build.js +0 -91
  67. package/dist/client/models/BuildBuildState.d.ts +0 -31
  68. package/dist/client/models/BuildBuildState.js +0 -57
  69. package/dist/client/models/BuildConfig.d.ts +0 -40
  70. package/dist/client/models/BuildConfig.js +0 -57
  71. package/dist/client/models/CachedBuild.d.ts +0 -38
  72. package/dist/client/models/CachedBuild.js +0 -55
  73. package/dist/client/models/CloneTarget.d.ts +0 -25
  74. package/dist/client/models/CloneTarget.js +0 -51
  75. package/dist/client/models/CompletionContext.d.ts +0 -38
  76. package/dist/client/models/CompletionContext.js +0 -53
  77. package/dist/client/models/CompletionItem.d.ts +0 -68
  78. package/dist/client/models/CompletionItem.js +0 -63
  79. package/dist/client/models/CompletionList.d.ts +0 -39
  80. package/dist/client/models/CompletionList.js +0 -56
  81. package/dist/client/models/ContainerConfig.d.ts +0 -38
  82. package/dist/client/models/ContainerConfig.js +0 -55
  83. package/dist/client/models/ContainerRegistry.d.ts +0 -44
  84. package/dist/client/models/ContainerRegistry.js +0 -59
  85. package/dist/client/models/CreateBuildDTO.d.ts +0 -52
  86. package/dist/client/models/CreateBuildDTO.js +0 -62
  87. package/dist/client/models/CreatePrebuildDTO.d.ts +0 -56
  88. package/dist/client/models/CreatePrebuildDTO.js +0 -59
  89. package/dist/client/models/CreateProjectConfigDTO.d.ts +0 -71
  90. package/dist/client/models/CreateProjectConfigDTO.js +0 -72
  91. package/dist/client/models/CreateProjectDTO.d.ts +0 -72
  92. package/dist/client/models/CreateProjectDTO.js +0 -73
  93. package/dist/client/models/CreateProjectSourceDTO.d.ts +0 -33
  94. package/dist/client/models/CreateProjectSourceDTO.js +0 -52
  95. package/dist/client/models/CreateProviderTargetDTO.d.ts +0 -45
  96. package/dist/client/models/CreateProviderTargetDTO.js +0 -60
  97. package/dist/client/models/CreateWorkspaceDTO.d.ts +0 -51
  98. package/dist/client/models/CreateWorkspaceDTO.js +0 -64
  99. package/dist/client/models/DevcontainerConfig.d.ts +0 -32
  100. package/dist/client/models/DevcontainerConfig.js +0 -51
  101. package/dist/client/models/ExecuteRequest.d.ts +0 -38
  102. package/dist/client/models/ExecuteRequest.js +0 -53
  103. package/dist/client/models/ExecuteResponse.d.ts +0 -38
  104. package/dist/client/models/ExecuteResponse.js +0 -55
  105. package/dist/client/models/FRPSConfig.d.ts +0 -44
  106. package/dist/client/models/FRPSConfig.js +0 -59
  107. package/dist/client/models/FileInfo.d.ts +0 -74
  108. package/dist/client/models/FileInfo.js +0 -79
  109. package/dist/client/models/FileStatus.d.ts +0 -51
  110. package/dist/client/models/FileStatus.js +0 -64
  111. package/dist/client/models/GetRepositoryContext.d.ts +0 -80
  112. package/dist/client/models/GetRepositoryContext.js +0 -67
  113. package/dist/client/models/GitAddRequest.d.ts +0 -38
  114. package/dist/client/models/GitAddRequest.js +0 -55
  115. package/dist/client/models/GitBranch.d.ts +0 -38
  116. package/dist/client/models/GitBranch.js +0 -55
  117. package/dist/client/models/GitBranchRequest.d.ts +0 -38
  118. package/dist/client/models/GitBranchRequest.js +0 -55
  119. package/dist/client/models/GitCloneRequest.d.ts +0 -62
  120. package/dist/client/models/GitCloneRequest.js +0 -63
  121. package/dist/client/models/GitCommitInfo.d.ts +0 -56
  122. package/dist/client/models/GitCommitInfo.js +0 -67
  123. package/dist/client/models/GitCommitRequest.d.ts +0 -50
  124. package/dist/client/models/GitCommitRequest.js +0 -63
  125. package/dist/client/models/GitCommitResponse.d.ts +0 -32
  126. package/dist/client/models/GitCommitResponse.js +0 -51
  127. package/dist/client/models/GitNamespace.d.ts +0 -38
  128. package/dist/client/models/GitNamespace.js +0 -55
  129. package/dist/client/models/GitProvider.d.ts +0 -75
  130. package/dist/client/models/GitProvider.js +0 -76
  131. package/dist/client/models/GitPullRequest.d.ts +0 -68
  132. package/dist/client/models/GitPullRequest.js +0 -75
  133. package/dist/client/models/GitRepoRequest.d.ts +0 -44
  134. package/dist/client/models/GitRepoRequest.js +0 -55
  135. package/dist/client/models/GitRepository.d.ts +0 -87
  136. package/dist/client/models/GitRepository.js +0 -84
  137. package/dist/client/models/GitStatus.d.ts +0 -57
  138. package/dist/client/models/GitStatus.js +0 -62
  139. package/dist/client/models/GitUser.d.ts +0 -50
  140. package/dist/client/models/GitUser.js +0 -63
  141. package/dist/client/models/InstallProviderRequest.d.ts +0 -40
  142. package/dist/client/models/InstallProviderRequest.js +0 -55
  143. package/dist/client/models/ListBranchResponse.d.ts +0 -32
  144. package/dist/client/models/ListBranchResponse.js +0 -51
  145. package/dist/client/models/LogFileConfig.d.ts +0 -62
  146. package/dist/client/models/LogFileConfig.js +0 -67
  147. package/dist/client/models/LspCompletionParams.d.ts +0 -58
  148. package/dist/client/models/LspCompletionParams.js +0 -69
  149. package/dist/client/models/LspDocumentRequest.d.ts +0 -44
  150. package/dist/client/models/LspDocumentRequest.js +0 -59
  151. package/dist/client/models/LspLocation.d.ts +0 -39
  152. package/dist/client/models/LspLocation.js +0 -56
  153. package/dist/client/models/LspPosition.d.ts +0 -38
  154. package/dist/client/models/LspPosition.js +0 -55
  155. package/dist/client/models/LspRange.d.ts +0 -39
  156. package/dist/client/models/LspRange.js +0 -56
  157. package/dist/client/models/LspServerRequest.d.ts +0 -38
  158. package/dist/client/models/LspServerRequest.js +0 -55
  159. package/dist/client/models/LspSymbol.d.ts +0 -45
  160. package/dist/client/models/LspSymbol.js +0 -60
  161. package/dist/client/models/Match.d.ts +0 -44
  162. package/dist/client/models/Match.js +0 -59
  163. package/dist/client/models/NetworkKey.d.ts +0 -32
  164. package/dist/client/models/NetworkKey.js +0 -51
  165. package/dist/client/models/Position.d.ts +0 -38
  166. package/dist/client/models/Position.js +0 -55
  167. package/dist/client/models/PrebuildConfig.d.ts +0 -56
  168. package/dist/client/models/PrebuildConfig.js +0 -67
  169. package/dist/client/models/PrebuildDTO.d.ts +0 -62
  170. package/dist/client/models/PrebuildDTO.js +0 -68
  171. package/dist/client/models/ProfileData.d.ts +0 -34
  172. package/dist/client/models/ProfileData.js +0 -51
  173. package/dist/client/models/Project.d.ts +0 -91
  174. package/dist/client/models/Project.js +0 -88
  175. package/dist/client/models/ProjectConfig.d.ts +0 -84
  176. package/dist/client/models/ProjectConfig.js +0 -87
  177. package/dist/client/models/ProjectDirResponse.d.ts +0 -32
  178. package/dist/client/models/ProjectDirResponse.js +0 -49
  179. package/dist/client/models/ProjectInfo.d.ts +0 -56
  180. package/dist/client/models/ProjectInfo.js +0 -65
  181. package/dist/client/models/ProjectState.d.ts +0 -45
  182. package/dist/client/models/ProjectState.js +0 -60
  183. package/dist/client/models/Provider.d.ts +0 -44
  184. package/dist/client/models/Provider.js +0 -57
  185. package/dist/client/models/ProviderProviderInfo.d.ts +0 -44
  186. package/dist/client/models/ProviderProviderInfo.js +0 -57
  187. package/dist/client/models/ProviderProviderTargetProperty.d.ts +0 -72
  188. package/dist/client/models/ProviderProviderTargetProperty.js +0 -64
  189. package/dist/client/models/ProviderProviderTargetPropertyType.d.ts +0 -29
  190. package/dist/client/models/ProviderProviderTargetPropertyType.js +0 -55
  191. package/dist/client/models/ProviderTarget.d.ts +0 -51
  192. package/dist/client/models/ProviderTarget.js +0 -64
  193. package/dist/client/models/ReplaceRequest.d.ts +0 -44
  194. package/dist/client/models/ReplaceRequest.js +0 -59
  195. package/dist/client/models/ReplaceResult.d.ts +0 -44
  196. package/dist/client/models/ReplaceResult.js +0 -53
  197. package/dist/client/models/RepositoryUrl.d.ts +0 -32
  198. package/dist/client/models/RepositoryUrl.js +0 -51
  199. package/dist/client/models/Sample.d.ts +0 -44
  200. package/dist/client/models/Sample.js +0 -59
  201. package/dist/client/models/SearchFilesResponse.d.ts +0 -32
  202. package/dist/client/models/SearchFilesResponse.js +0 -51
  203. package/dist/client/models/ServerConfig.d.ts +0 -130
  204. package/dist/client/models/ServerConfig.js +0 -119
  205. package/dist/client/models/SetGitProviderConfig.d.ts +0 -75
  206. package/dist/client/models/SetGitProviderConfig.js +0 -70
  207. package/dist/client/models/SetProjectState.d.ts +0 -39
  208. package/dist/client/models/SetProjectState.js +0 -56
  209. package/dist/client/models/SigningMethod.d.ts +0 -25
  210. package/dist/client/models/SigningMethod.js +0 -51
  211. package/dist/client/models/Status.d.ts +0 -31
  212. package/dist/client/models/Status.js +0 -57
  213. package/dist/client/models/Workspace.d.ts +0 -51
  214. package/dist/client/models/Workspace.js +0 -64
  215. package/dist/client/models/WorkspaceDTO.d.ts +0 -58
  216. package/dist/client/models/WorkspaceDTO.js +0 -67
  217. package/dist/client/models/WorkspaceInfo.d.ts +0 -45
  218. package/dist/client/models/WorkspaceInfo.js +0 -58
  219. package/dist/client/models/index.d.ts +0 -79
  220. package/dist/client/models/index.js +0 -97
  221. package/dist/client/runtime.d.ts +0 -182
  222. package/dist/client/runtime.js +0 -340
package/dist/Workspace.js CHANGED
@@ -1,23 +1,75 @@
1
1
  "use strict";
2
+ /**
3
+ * The Daytona SDK core Sandbox functionality.
4
+ *
5
+ * Provides the main Workspace class representing a Daytona Sandbox that coordinates file system,
6
+ * Git, process execution, and LSP functionality. It serves as the central point
7
+ * for interacting with Daytona Sandboxes.
8
+ *
9
+ * The Sandbox must be in a 'started' state before performing operations.
10
+ *
11
+ * @module Workspace
12
+ *
13
+ * @example
14
+ * // Create and initialize workspace
15
+ * const daytona = new Daytona();
16
+ * const workspace = await daytona.create();
17
+ *
18
+ * // File operations
19
+ * await workspace.fs.uploadFile(
20
+ * '/app/config.json',
21
+ * new File(['{"setting": "value"}'], 'config.json')
22
+ * );
23
+ * const contentBlob = await workspace.fs.downloadFile('/app/config.json');
24
+ *
25
+ * // Git operations
26
+ * await workspace.git.clone('https://github.com/user/repo.git');
27
+ *
28
+ * // Process execution
29
+ * const response = await workspace.process.executeCommand('ls -la');
30
+ * console.log(response.result);
31
+ *
32
+ * // LSP functionality
33
+ * const lsp = workspace.createLspServer('typescript', '/workspace/project');
34
+ * await lsp.didOpen('/workspace/project/src/index.ts');
35
+ * const completions = await lsp.completions('/workspace/project/src/index.ts', {
36
+ * line: 10,
37
+ * character: 15
38
+ * });
39
+ * console.log(completions);
40
+ *
41
+ */
2
42
  Object.defineProperty(exports, "__esModule", { value: true });
3
43
  exports.Workspace = void 0;
4
44
  const FileSystem_1 = require("./FileSystem");
5
45
  const Git_1 = require("./Git");
6
- // import { LspLanguageId, LspServer } from './LspServer'
7
46
  const Process_1 = require("./Process");
8
47
  const LspServer_1 = require("./LspServer");
48
+ const DaytonaError_1 = require("./errors/DaytonaError");
9
49
  /**
10
- * Represents a Daytona workspace instance with file system, git, and process management capabilities
11
- * @class Workspace
50
+ * Represents a Daytona Sandbox.
51
+ *
52
+ * A Sandbox provides file system operations, Git operations, process execution,
53
+ * and LSP functionality. It serves as the main interface for interacting with
54
+ * a Daytona workspace.
55
+ *
56
+ * @property {string} id - Unique identifier for the Sandbox
57
+ * @property {WorkspaceInstance} instance - The underlying Sandbox instance
58
+ * @property {WorkspaceApi} workspaceApi - API client for Sandbox operations
59
+ * @property {ToolboxApi} toolboxApi - API client for toolbox operations
60
+ * @property {WorkspaceCodeToolbox} codeToolbox - Language-specific toolbox implementation
61
+ * @property {FileSystem} fs - File system operations interface
62
+ * @property {Git} git - Git operations interface
63
+ * @property {Process} process - Process execution interface
12
64
  */
13
65
  class Workspace {
14
66
  /**
15
- * Creates a new workspace instance
16
- * @param {string} id - Unique identifier for the workspace
17
- * @param {WorkspaceInstance} instance - The underlying workspace instance
18
- * @param {WorkspaceApi} workspaceApi - API client for workspace operations
19
- * @param {ToolboxApi} toolboxApi - API client for toolbox operations
67
+ * Creates a new Sandbox instance
20
68
  *
69
+ * @param {string} id - Unique identifier for the Sandbox
70
+ * @param {WorkspaceInstance} instance - The underlying Sandbox instance
71
+ * @param {WorkspaceApi} workspaceApi - API client for Sandbox operations
72
+ * @param {ToolboxApi} toolboxApi - API client for toolbox operations
21
73
  * @param {WorkspaceCodeToolbox} codeToolbox - Language-specific toolbox implementation
22
74
  */
23
75
  constructor(id, instance, workspaceApi, toolboxApi, codeToolbox) {
@@ -31,102 +83,200 @@ class Workspace {
31
83
  this.process = new Process_1.Process(this.codeToolbox, this.toolboxApi, instance);
32
84
  }
33
85
  /**
34
- * Gets the root directory path of the workspace
35
- * @returns {Promise<string>} The absolute path to the workspace root
86
+ * Gets the root directory path of the Sandbox.
87
+ *
88
+ * @returns {Promise<string | undefined>} The absolute path to the Sandbox root directory
89
+ *
90
+ * @example
91
+ * const rootDir = await workspace.getWorkspaceRootDir();
92
+ * console.log(`Workspace root: ${rootDir}`);
36
93
  */
37
94
  async getWorkspaceRootDir() {
38
95
  const response = await this.toolboxApi.getProjectDir(this.instance.id);
39
96
  return response.data.dir;
40
97
  }
41
98
  /**
42
- * Creates a new Language Server Protocol (LSP) server instance
43
- * @param {LspLanguageId} languageId - The language server type
44
- * @param {string} pathToProject - Path to the project root
45
- * @returns {LspServer} A new LSP server instance
99
+ * Creates a new Language Server Protocol (LSP) server instance.
100
+ *
101
+ * The LSP server provides language-specific features like code completion,
102
+ * diagnostics, and more.
103
+ *
104
+ * @param {LspLanguageId} languageId - The language server type (e.g., "typescript")
105
+ * @param {string} pathToProject - Absolute path to the project root directory
106
+ * @returns {LspServer} A new LSP server instance configured for the specified language
107
+ *
108
+ * @example
109
+ * const lsp = workspace.createLspServer('typescript', '/workspace/project');
46
110
  */
47
111
  createLspServer(languageId, pathToProject) {
48
112
  return new LspServer_1.LspServer(languageId, pathToProject, this.toolboxApi, this.instance);
49
113
  }
50
114
  /**
51
- * Sets labels for the workspace
52
- * @param {Record<string, string>} labels - The labels to set
115
+ * Sets labels for the Sandbox.
116
+ *
117
+ * Labels are key-value pairs that can be used to organize and identify Sandboxes.
118
+ *
119
+ * @param {Record<string, string>} labels - Dictionary of key-value pairs representing Sandbox labels
120
+ * @returns {Promise<void>}
121
+ *
122
+ * @example
123
+ * // Set workspace labels
124
+ * await workspace.setLabels({
125
+ * project: 'my-project',
126
+ * environment: 'development',
127
+ * team: 'backend'
128
+ * });
53
129
  */
54
130
  async setLabels(labels) {
55
131
  await this.workspaceApi.replaceLabels(this.instance.id, { labels });
56
132
  }
57
133
  /**
58
- * Starts the workspace
134
+ * Start the Sandbox.
135
+ *
136
+ * This method starts the Sandbox and waits for it to be ready.
137
+ *
138
+ * @param {number} [timeout] - Maximum time to wait in seconds. 0 means no timeout.
139
+ * Defaults to 60-second timeout.
59
140
  * @returns {Promise<void>}
141
+ * @throws {DaytonaError} - `DaytonaError` - If Sandbox fails to start or times out
142
+ *
143
+ * @example
144
+ * const workspace = await daytona.getCurrentWorkspace('my-workspace');
145
+ * await workspace.start(40); // Wait up to 40 seconds
146
+ * console.log('Workspace started successfully');
60
147
  */
61
- async start() {
62
- await this.workspaceApi.startWorkspace(this.instance.id);
63
- await this.waitUntilStarted();
148
+ async start(timeout = 60) {
149
+ if (timeout < 0) {
150
+ throw new DaytonaError_1.DaytonaError('Timeout must be a non-negative number');
151
+ }
152
+ const startTime = Date.now();
153
+ await this.workspaceApi.startWorkspace(this.instance.id, { timeout: timeout * 1000 });
154
+ const timeElapsed = Date.now() - startTime;
155
+ await this.waitUntilStarted(timeout ? timeout - (timeElapsed / 1000) : 0);
64
156
  }
65
157
  /**
66
- * Stops the workspace
158
+ * Stops the Sandbox.
159
+ *
160
+ * This method stops the Sandbox and waits for it to be fully stopped.
161
+ *
162
+ * @param {number} [timeout] - Maximum time to wait in seconds. 0 means no timeout.
163
+ * Defaults to 60-second timeout.
67
164
  * @returns {Promise<void>}
165
+ *
166
+ * @example
167
+ * const workspace = await daytona.getCurrentWorkspace('my-workspace');
168
+ * await workspace.stop();
169
+ * console.log('Workspace stopped successfully');
68
170
  */
69
- async stop() {
70
- await this.workspaceApi.stopWorkspace(this.instance.id);
71
- await this.waitUntilStopped();
171
+ async stop(timeout = 60) {
172
+ if (timeout < 0) {
173
+ throw new DaytonaError_1.DaytonaError('Timeout must be a non-negative number');
174
+ }
175
+ const startTime = Date.now();
176
+ await this.workspaceApi.stopWorkspace(this.instance.id, { timeout: timeout * 1000 });
177
+ const timeElapsed = Date.now() - startTime;
178
+ await this.waitUntilStopped(timeout ? timeout - (timeElapsed / 1000) : 0);
72
179
  }
73
180
  /**
74
- * Deletes the workspace
181
+ * Deletes the Sandbox.
75
182
  * @returns {Promise<void>}
76
183
  */
77
184
  async delete() {
78
185
  await this.workspaceApi.deleteWorkspace(this.instance.id, true);
79
186
  }
80
- async waitUntilStarted() {
81
- const maxAttempts = 600;
82
- let attempts = 0;
83
- while (attempts < maxAttempts) {
187
+ /**
188
+ * Waits for the Sandbox to reach the 'started' state.
189
+ *
190
+ * This method polls the Sandbox status until it reaches the 'started' state
191
+ * or encounters an error.
192
+ *
193
+ * @param {number} [timeout] - Maximum time to wait in seconds. 0 means no timeout.
194
+ * Defaults to 60 seconds.
195
+ * @returns {Promise<void>}
196
+ * @throws {DaytonaError} - `DaytonaError` - If the workspace ends up in an error state or fails to start within the timeout period.
197
+ */
198
+ async waitUntilStarted(timeout = 60) {
199
+ if (timeout < 0) {
200
+ throw new DaytonaError_1.DaytonaError('Timeout must be a non-negative number');
201
+ }
202
+ const checkInterval = 100; // Wait 100 ms between checks
203
+ const startTime = Date.now();
204
+ while (timeout === 0 || (Date.now() - startTime) < (timeout * 1000)) {
84
205
  const response = await this.workspaceApi.getWorkspace(this.id);
85
206
  const state = response.data.state;
86
207
  if (state === 'started') {
87
208
  return;
88
209
  }
89
210
  if (state === 'error') {
90
- throw new Error(`Workspace failed to start with status: ${status}`);
211
+ throw new DaytonaError_1.DaytonaError(`Workspace failed to start with status: ${state}, error reason: ${response.data.errorReason}`);
91
212
  }
92
- await new Promise(resolve => setTimeout(resolve, 100)); // Wait 100 ms between checks
93
- attempts++;
213
+ await new Promise(resolve => setTimeout(resolve, checkInterval));
94
214
  }
95
- throw new Error('Workspace failed to become ready within the timeout period');
215
+ throw new DaytonaError_1.DaytonaError(`Workspace failed to become ready within the timeout period`);
96
216
  }
97
- async waitUntilStopped() {
98
- const maxAttempts = 600;
99
- let attempts = 0;
100
- while (attempts < maxAttempts) {
217
+ /**
218
+ * Wait for Sandbox to reach 'stopped' state.
219
+ *
220
+ * This method polls the Sandbox status until it reaches the 'stopped' state
221
+ * or encounters an error.
222
+ *
223
+ * @param {number} [timeout] - Maximum time to wait in seconds. 0 means no timeout.
224
+ * Defaults to 60 seconds.
225
+ * @returns {Promise<void>}
226
+ * @throws {DaytonaError} - `DaytonaError` - If the workspace fails to stop within the timeout period.
227
+ */
228
+ async waitUntilStopped(timeout = 60) {
229
+ if (timeout < 0) {
230
+ throw new DaytonaError_1.DaytonaError('Timeout must be a non-negative number');
231
+ }
232
+ const checkInterval = 100; // Wait 100 ms between checks
233
+ const startTime = Date.now();
234
+ while (timeout === 0 || (Date.now() - startTime) < (timeout * 1000)) {
101
235
  const response = await this.workspaceApi.getWorkspace(this.id);
102
236
  const state = response.data.state;
103
237
  if (state === 'stopped') {
104
238
  return;
105
239
  }
106
240
  if (state === 'error') {
107
- throw new Error(`Workspace failed to stop with status: ${status}`);
241
+ throw new DaytonaError_1.DaytonaError(`Workspace failed to stop with status: ${state}, error reason: ${response.data.errorReason}`);
108
242
  }
109
- await new Promise(resolve => setTimeout(resolve, 100)); // Wait 100 ms between checks
110
- attempts++;
243
+ await new Promise(resolve => setTimeout(resolve, checkInterval));
111
244
  }
112
- throw new Error('Workspace failed to become stopped within the timeout period');
245
+ throw new DaytonaError_1.DaytonaError('Workspace failed to become stopped within the timeout period');
113
246
  }
114
247
  /**
115
- * Get structured information about the workspace
116
- * @returns {Promise<WorkspaceInfo>} Structured workspace information
248
+ * Gets structured information about the Sandbox.
249
+ *
250
+ * @returns {Promise<WorkspaceInfo>} Detailed information about the Sandbox including its
251
+ * configuration, resources, and current state
252
+ *
253
+ * @example
254
+ * const info = await workspace.info();
255
+ * console.log(`Workspace ${info.name}:`);
256
+ * console.log(`State: ${info.state}`);
257
+ * console.log(`Resources: ${info.resources.cpu} CPU, ${info.resources.memory} RAM`);
117
258
  */
118
259
  async info() {
119
- var _a;
120
260
  const response = await this.workspaceApi.getWorkspace(this.id);
121
261
  const instance = response.data;
262
+ return Workspace.toWorkspaceInfo(instance);
263
+ }
264
+ /**
265
+ * Converts an API workspace instance to a WorkspaceInfo object.
266
+ *
267
+ * @param {ApiWorkspace} instance - The API workspace instance to convert
268
+ * @returns {WorkspaceInfo} The converted WorkspaceInfo object
269
+ */
270
+ static toWorkspaceInfo(instance) {
271
+ var _a, _b, _c, _d, _e;
122
272
  const providerMetadata = JSON.parse(((_a = instance.info) === null || _a === void 0 ? void 0 : _a.providerMetadata) || '{}');
273
+ var resourcesData = providerMetadata.resources || providerMetadata;
123
274
  // Extract resources with defaults
124
- const resourcesData = providerMetadata.resources || {};
125
275
  const resources = {
126
276
  cpu: String(resourcesData.cpu || '1'),
127
277
  gpu: resourcesData.gpu ? String(resourcesData.gpu) : null,
128
- memory: String(resourcesData.memory || '2Gi'),
129
- disk: String(resourcesData.disk || '10Gi')
278
+ memory: `${(_b = resourcesData.memory) !== null && _b !== void 0 ? _b : 2}Gi`,
279
+ disk: `${(_c = resourcesData.disk) !== null && _c !== void 0 ? _c : 10}Gi`
130
280
  };
131
281
  return {
132
282
  id: instance.id,
@@ -143,8 +293,65 @@ class Workspace {
143
293
  snapshotState: providerMetadata.snapshotState || null,
144
294
  snapshotStateCreatedAt: providerMetadata.snapshotStateCreatedAt
145
295
  ? new Date(providerMetadata.snapshotStateCreatedAt)
146
- : null
296
+ : null,
297
+ nodeDomain: providerMetadata.nodeDomain || '',
298
+ region: providerMetadata.region || '',
299
+ class: providerMetadata.class || '',
300
+ updatedAt: providerMetadata.updatedAt || '',
301
+ lastSnapshot: providerMetadata.lastSnapshot || null,
302
+ autoStopInterval: providerMetadata.autoStopInterval || 0,
303
+ created: ((_d = instance.info) === null || _d === void 0 ? void 0 : _d.created) || '',
304
+ providerMetadata: (_e = instance.info) === null || _e === void 0 ? void 0 : _e.providerMetadata,
147
305
  };
148
306
  }
307
+ /**
308
+ * Set the auto-stop interval for the Sandbox.
309
+ *
310
+ * The Sandbox will automatically stop after being idle (no new events) for the specified interval.
311
+ * Events include any state changes or interactions with the Sandbox through the sdk.
312
+ * Interactions using Sandbox Previews are not included.
313
+ *
314
+ * @param {number} interval - Number of minutes of inactivity before auto-stopping.
315
+ * Set to 0 to disable auto-stop. Default is 15 minutes.
316
+ * @returns {Promise<void>}
317
+ * @throws {DaytonaError} - `DaytonaError` - If interval is not a non-negative integer
318
+ *
319
+ * @example
320
+ * // Auto-stop after 1 hour
321
+ * await workspace.setAutostopInterval(60);
322
+ * // Or disable auto-stop
323
+ * await workspace.setAutostopInterval(0);
324
+ */
325
+ async setAutostopInterval(interval) {
326
+ if (!Number.isInteger(interval) || interval < 0) {
327
+ throw new DaytonaError_1.DaytonaError('autoStopInterval must be a non-negative integer');
328
+ }
329
+ await this.workspaceApi.setAutostopInterval(this.id, interval);
330
+ this.instance.autoStopInterval = interval;
331
+ }
332
+ /**
333
+ * Gets the preview link for the workspace at a specific port. If the port is not open, it will open it and return the link.
334
+ * @param {number} port - The port to open the preview link on
335
+ * @returns {string} The preview link for the workspace at the specified port
336
+ * @throws {DaytonaError} If the node domain is not found in the provider metadata
337
+ */
338
+ getPreviewLink(port) {
339
+ var _a;
340
+ const providerMetadata = JSON.parse(((_a = this.instance.info) === null || _a === void 0 ? void 0 : _a.providerMetadata) || '{}');
341
+ const nodeDomain = providerMetadata.nodeDomain || '';
342
+ if (!nodeDomain) {
343
+ throw new DaytonaError_1.DaytonaError("Cannot get preview link. Node domain not found in provider metadata. Please contact support.");
344
+ }
345
+ return `https://${port}-${this.id}.${nodeDomain}`;
346
+ }
347
+ /**
348
+ * Archives the workspace, making it inactive and preserving its state. When sandboxes are archived, the entire filesystem
349
+ * state is moved to cost-effective object storage, making it possible to keep sandboxes available for an extended period.
350
+ * The tradeoff between archived and stopped states is that starting an archived sandbox takes more time, depending on its size.
351
+ * Workspace must be stopped before archiving.
352
+ */
353
+ async archive() {
354
+ await this.workspaceApi.archiveWorkspace(this.id);
355
+ }
149
356
  }
150
357
  exports.Workspace = Workspace;
@@ -1,5 +1,6 @@
1
1
  import { WorkspaceCodeToolbox } from '../Workspace';
2
+ import { CodeRunParams } from '../Process';
2
3
  export declare class WorkspacePythonCodeToolbox implements WorkspaceCodeToolbox {
3
4
  getDefaultImage(): string;
4
- getRunCommand(code: string): string;
5
+ getRunCommand(code: string, params?: CodeRunParams): string;
5
6
  }
@@ -5,9 +5,11 @@ class WorkspacePythonCodeToolbox {
5
5
  getDefaultImage() {
6
6
  return 'daytonaio/sdk-python:v0.49.0-2';
7
7
  }
8
- getRunCommand(code) {
8
+ getRunCommand(code, params) {
9
9
  const base64Code = Buffer.from(code).toString('base64');
10
- return `python3 -c "exec(__import__('base64').b64decode('${base64Code}').decode())"`;
10
+ const envVars = (params === null || params === void 0 ? void 0 : params.env) ? Object.entries(params.env).map(([key, value]) => `${key}='${value}'`).join(' ') : '';
11
+ const argv = (params === null || params === void 0 ? void 0 : params.argv) ? params.argv.join(' ') : '';
12
+ return `sh -c '${envVars} python3 -c "exec(__import__(\\\"base64\\\").b64decode(\\\"${base64Code}\\\").decode())" ${argv}'`;
11
13
  }
12
14
  }
13
15
  exports.WorkspacePythonCodeToolbox = WorkspacePythonCodeToolbox;
@@ -1,5 +1,6 @@
1
1
  import { WorkspaceCodeToolbox } from '../Workspace';
2
+ import { CodeRunParams } from '../Process';
2
3
  export declare class WorkspaceTsCodeToolbox implements WorkspaceCodeToolbox {
3
4
  getDefaultImage(): string;
4
- getRunCommand(code: string): string;
5
+ getRunCommand(code: string, params?: CodeRunParams): string;
5
6
  }
@@ -5,9 +5,11 @@ class WorkspaceTsCodeToolbox {
5
5
  getDefaultImage() {
6
6
  return 'daytonaio/sdk-typescript:v0.49.0-3';
7
7
  }
8
- getRunCommand(code) {
8
+ getRunCommand(code, params) {
9
9
  const base64Code = Buffer.from(code).toString('base64');
10
- return `python3 -c "exec(__import__('base64').b64decode('${base64Code}').decode())"`;
10
+ const envVars = (params === null || params === void 0 ? void 0 : params.env) ? Object.entries(params.env).map(([key, value]) => `${key}='${value}'`).join(' ') : '';
11
+ const argv = (params === null || params === void 0 ? void 0 : params.argv) ? params.argv.join(' ') : '';
12
+ return `sh -c 'echo ${base64Code} | base64 --decode | ${envVars} npx ts-node -O "{\\\"module\\\":\\\"CommonJS\\\"}" -e "$(cat)" x ${argv} 2>&1 | grep -vE "npm notice|npm warn exec"'`;
11
13
  }
12
14
  }
13
15
  exports.WorkspaceTsCodeToolbox = WorkspaceTsCodeToolbox;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @module Errors
3
+ */
4
+ /**
5
+ * Base error for Daytona SDK.
6
+ */
7
+ export declare class DaytonaError extends Error {
8
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ /**
3
+ * @module Errors
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.DaytonaError = void 0;
7
+ /**
8
+ * Base error for Daytona SDK.
9
+ */
10
+ class DaytonaError extends Error {
11
+ }
12
+ exports.DaytonaError = DaytonaError;
package/dist/index.d.ts CHANGED
@@ -1,8 +1,12 @@
1
1
  export { Daytona } from './Daytona';
2
2
  export type { DaytonaConfig, CreateWorkspaceParams } from './Daytona';
3
+ export { CodeLanguage } from './Daytona';
3
4
  export { Workspace } from './Workspace';
4
5
  export type { WorkspaceCodeToolbox } from './Workspace';
5
6
  export { FileSystem } from './FileSystem';
6
7
  export { Git } from './Git';
7
8
  export { Process } from './Process';
9
+ export { LspLanguageId } from './LspServer';
10
+ export { DaytonaError } from './errors/DaytonaError';
8
11
  export type { FileInfo, Match, ReplaceResult, SearchFilesResponse, GitStatus, ListBranchResponse, ExecuteResponse, } from '@daytonaio/api-client';
12
+ export { WorkspaceState, CreateWorkspaceTargetEnum as WorkspaceTargetRegion } from '@daytonaio/api-client';
package/dist/index.js CHANGED
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Process = exports.Git = exports.FileSystem = exports.Workspace = exports.Daytona = void 0;
3
+ exports.WorkspaceTargetRegion = exports.WorkspaceState = exports.DaytonaError = exports.LspLanguageId = exports.Process = exports.Git = exports.FileSystem = exports.Workspace = exports.CodeLanguage = exports.Daytona = void 0;
4
4
  var Daytona_1 = require("./Daytona");
5
5
  Object.defineProperty(exports, "Daytona", { enumerable: true, get: function () { return Daytona_1.Daytona; } });
6
+ var Daytona_2 = require("./Daytona");
7
+ Object.defineProperty(exports, "CodeLanguage", { enumerable: true, get: function () { return Daytona_2.CodeLanguage; } });
6
8
  var Workspace_1 = require("./Workspace");
7
9
  Object.defineProperty(exports, "Workspace", { enumerable: true, get: function () { return Workspace_1.Workspace; } });
8
10
  var FileSystem_1 = require("./FileSystem");
@@ -11,3 +13,12 @@ var Git_1 = require("./Git");
11
13
  Object.defineProperty(exports, "Git", { enumerable: true, get: function () { return Git_1.Git; } });
12
14
  var Process_1 = require("./Process");
13
15
  Object.defineProperty(exports, "Process", { enumerable: true, get: function () { return Process_1.Process; } });
16
+ var LspServer_1 = require("./LspServer");
17
+ Object.defineProperty(exports, "LspLanguageId", { enumerable: true, get: function () { return LspServer_1.LspLanguageId; } });
18
+ // export { LspServer } from './LspServer'
19
+ // export type { LspLanguageId, Position } from './LspServer'
20
+ var DaytonaError_1 = require("./errors/DaytonaError");
21
+ Object.defineProperty(exports, "DaytonaError", { enumerable: true, get: function () { return DaytonaError_1.DaytonaError; } });
22
+ var api_client_1 = require("@daytonaio/api-client");
23
+ Object.defineProperty(exports, "WorkspaceState", { enumerable: true, get: function () { return api_client_1.WorkspaceState; } });
24
+ Object.defineProperty(exports, "WorkspaceTargetRegion", { enumerable: true, get: function () { return api_client_1.CreateWorkspaceTargetEnum; } });
@@ -0,0 +1,6 @@
1
+ import { AxiosInstance } from 'axios';
2
+ export declare class Axios {
3
+ private static instance;
4
+ private constructor();
5
+ static getInstance(): AxiosInstance;
6
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Axios = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ class Axios {
9
+ constructor() { }
10
+ static getInstance() {
11
+ if (!Axios.instance) {
12
+ Axios.instance = axios_1.default.create();
13
+ Axios.instance.interceptors.response.use((response) => {
14
+ return response;
15
+ }, (error) => {
16
+ var _a, _b, _c;
17
+ const errorMessage = ((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.message) ||
18
+ ((_c = error.response) === null || _c === void 0 ? void 0 : _c.data) ||
19
+ error.message ||
20
+ String(error);
21
+ throw new Error(errorMessage);
22
+ // return Promise.reject(errorMessage);
23
+ });
24
+ }
25
+ return Axios.instance;
26
+ }
27
+ }
28
+ exports.Axios = Axios;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Helper method to parse API errors and extract meaningful messages.
3
+ * Checks if error is an AxiosError and has response data with a message field.
4
+ * If it does, it will return the message from the response.
5
+ * If it doesn't, it will return the original error message.
6
+ *
7
+ * @param error - The error to parse
8
+ * @returns A formatted error message string
9
+ */
10
+ export declare function parseApiError(error: unknown): string;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseApiError = parseApiError;
4
+ const axios_1 = require("axios");
5
+ /**
6
+ * Helper method to parse API errors and extract meaningful messages.
7
+ * Checks if error is an AxiosError and has response data with a message field.
8
+ * If it does, it will return the message from the response.
9
+ * If it doesn't, it will return the original error message.
10
+ *
11
+ * @param error - The error to parse
12
+ * @returns A formatted error message string
13
+ */
14
+ function parseApiError(error) {
15
+ var _a;
16
+ try {
17
+ // Handle Axios errors
18
+ if (error instanceof axios_1.AxiosError) {
19
+ // Check if we have response data
20
+ if ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) {
21
+ const errorData = error.response.data;
22
+ // If errorData is an object with a message field
23
+ if (typeof errorData === 'object' && errorData !== null) {
24
+ if ('message' in errorData && typeof errorData.message === 'string') {
25
+ return errorData.message;
26
+ }
27
+ // If no message field, we can stringify the error data
28
+ return JSON.stringify(errorData);
29
+ }
30
+ }
31
+ return error.message;
32
+ }
33
+ }
34
+ catch (_b) { }
35
+ return String(error);
36
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Custom error class for timeout-related exceptions
3
+ * @extends Error
4
+ */
5
+ declare class TimeoutError extends Error {
6
+ constructor(message?: string);
7
+ /**
8
+ * Checks if an error is a TimeoutError
9
+ * @param error - The error to check
10
+ */
11
+ static isTimeoutError(error: unknown): error is TimeoutError;
12
+ }
13
+ /**
14
+ * Configuration options for timeout behavior
15
+ */
16
+ interface TimeoutOptions {
17
+ /** Timeout duration in seconds */
18
+ timeout: number;
19
+ /** Whether the operation supports abortion */
20
+ abortable?: boolean;
21
+ /** Optional callback to execute on timeout */
22
+ onTimeout?: () => void;
23
+ /** Optional custom error message for TimeoutError */
24
+ errorMessage?: string;
25
+ }
26
+ /**
27
+ * Wraps a promise with a timeout mechanism
28
+ * @template T - The type of the promise result
29
+ * @param promise - The promise to wrap
30
+ * @param options - Timeout configuration options
31
+ * @returns A promise that will reject if the timeout is exceeded
32
+ * @throws {TimeoutError} When the operation times out
33
+ */
34
+ declare function withTimeout<T>(promise: Promise<T>, options: TimeoutOptions): Promise<T>;
35
+ export { withTimeout, TimeoutError };