@daytonaio/sdk 0.7.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 (215) hide show
  1. package/LICENCE +43 -0
  2. package/README.md +181 -0
  3. package/dist/Daytona.d.ts +106 -0
  4. package/dist/Daytona.js +141 -0
  5. package/dist/FileSystem.d.ts +97 -0
  6. package/dist/FileSystem.js +126 -0
  7. package/dist/Git.d.ts +67 -0
  8. package/dist/Git.js +109 -0
  9. package/dist/LspServer.d.ts +68 -0
  10. package/dist/LspServer.js +93 -0
  11. package/dist/Process.d.ts +54 -0
  12. package/dist/Process.js +84 -0
  13. package/dist/Workspace.d.ts +53 -0
  14. package/dist/Workspace.js +51 -0
  15. package/dist/client/apis/ApiKeyApi.d.ts +54 -0
  16. package/dist/client/apis/ApiKeyApi.js +135 -0
  17. package/dist/client/apis/BuildApi.d.ts +95 -0
  18. package/dist/client/apis/BuildApi.js +228 -0
  19. package/dist/client/apis/ContainerRegistryApi.d.ts +68 -0
  20. package/dist/client/apis/ContainerRegistryApi.js +163 -0
  21. package/dist/client/apis/DefaultApi.d.ts +31 -0
  22. package/dist/client/apis/DefaultApi.js +72 -0
  23. package/dist/client/apis/GitProviderApi.d.ts +197 -0
  24. package/dist/client/apis/GitProviderApi.js +477 -0
  25. package/dist/client/apis/PrebuildApi.d.ts +97 -0
  26. package/dist/client/apis/PrebuildApi.js +241 -0
  27. package/dist/client/apis/ProfileApi.d.ts +51 -0
  28. package/dist/client/apis/ProfileApi.js +128 -0
  29. package/dist/client/apis/ProjectConfigApi.d.ts +94 -0
  30. package/dist/client/apis/ProjectConfigApi.js +220 -0
  31. package/dist/client/apis/ProviderApi.d.ts +71 -0
  32. package/dist/client/apis/ProviderApi.js +160 -0
  33. package/dist/client/apis/SampleApi.d.ts +28 -0
  34. package/dist/client/apis/SampleApi.js +73 -0
  35. package/dist/client/apis/ServerApi.d.ts +61 -0
  36. package/dist/client/apis/ServerApi.js +156 -0
  37. package/dist/client/apis/TargetApi.d.ts +67 -0
  38. package/dist/client/apis/TargetApi.js +159 -0
  39. package/dist/client/apis/WorkspaceApi.d.ts +141 -0
  40. package/dist/client/apis/WorkspaceApi.js +330 -0
  41. package/dist/client/apis/WorkspaceToolboxApi.d.ts +464 -0
  42. package/dist/client/apis/WorkspaceToolboxApi.js +1248 -0
  43. package/dist/client/apis/index.d.ts +14 -0
  44. package/dist/client/apis/index.js +32 -0
  45. package/dist/client/index.d.ts +3 -0
  46. package/dist/client/index.js +21 -0
  47. package/dist/client/models/ApiKey.d.ts +45 -0
  48. package/dist/client/models/ApiKey.js +60 -0
  49. package/dist/client/models/ApikeyApiKeyType.d.ts +26 -0
  50. package/dist/client/models/ApikeyApiKeyType.js +52 -0
  51. package/dist/client/models/Build.d.ts +98 -0
  52. package/dist/client/models/Build.js +91 -0
  53. package/dist/client/models/BuildBuildState.d.ts +31 -0
  54. package/dist/client/models/BuildBuildState.js +57 -0
  55. package/dist/client/models/BuildConfig.d.ts +40 -0
  56. package/dist/client/models/BuildConfig.js +57 -0
  57. package/dist/client/models/CachedBuild.d.ts +38 -0
  58. package/dist/client/models/CachedBuild.js +55 -0
  59. package/dist/client/models/CloneTarget.d.ts +25 -0
  60. package/dist/client/models/CloneTarget.js +51 -0
  61. package/dist/client/models/CompletionContext.d.ts +38 -0
  62. package/dist/client/models/CompletionContext.js +53 -0
  63. package/dist/client/models/CompletionItem.d.ts +68 -0
  64. package/dist/client/models/CompletionItem.js +63 -0
  65. package/dist/client/models/CompletionList.d.ts +39 -0
  66. package/dist/client/models/CompletionList.js +56 -0
  67. package/dist/client/models/ContainerConfig.d.ts +38 -0
  68. package/dist/client/models/ContainerConfig.js +55 -0
  69. package/dist/client/models/ContainerRegistry.d.ts +44 -0
  70. package/dist/client/models/ContainerRegistry.js +59 -0
  71. package/dist/client/models/CreateBuildDTO.d.ts +52 -0
  72. package/dist/client/models/CreateBuildDTO.js +62 -0
  73. package/dist/client/models/CreatePrebuildDTO.d.ts +56 -0
  74. package/dist/client/models/CreatePrebuildDTO.js +59 -0
  75. package/dist/client/models/CreateProjectConfigDTO.d.ts +71 -0
  76. package/dist/client/models/CreateProjectConfigDTO.js +72 -0
  77. package/dist/client/models/CreateProjectDTO.d.ts +72 -0
  78. package/dist/client/models/CreateProjectDTO.js +73 -0
  79. package/dist/client/models/CreateProjectSourceDTO.d.ts +33 -0
  80. package/dist/client/models/CreateProjectSourceDTO.js +52 -0
  81. package/dist/client/models/CreateProviderTargetDTO.d.ts +45 -0
  82. package/dist/client/models/CreateProviderTargetDTO.js +60 -0
  83. package/dist/client/models/CreateWorkspaceDTO.d.ts +51 -0
  84. package/dist/client/models/CreateWorkspaceDTO.js +64 -0
  85. package/dist/client/models/DevcontainerConfig.d.ts +32 -0
  86. package/dist/client/models/DevcontainerConfig.js +51 -0
  87. package/dist/client/models/ExecuteRequest.d.ts +38 -0
  88. package/dist/client/models/ExecuteRequest.js +53 -0
  89. package/dist/client/models/ExecuteResponse.d.ts +38 -0
  90. package/dist/client/models/ExecuteResponse.js +55 -0
  91. package/dist/client/models/FRPSConfig.d.ts +44 -0
  92. package/dist/client/models/FRPSConfig.js +59 -0
  93. package/dist/client/models/FileInfo.d.ts +74 -0
  94. package/dist/client/models/FileInfo.js +79 -0
  95. package/dist/client/models/FileStatus.d.ts +51 -0
  96. package/dist/client/models/FileStatus.js +64 -0
  97. package/dist/client/models/GetRepositoryContext.d.ts +80 -0
  98. package/dist/client/models/GetRepositoryContext.js +67 -0
  99. package/dist/client/models/GitAddRequest.d.ts +38 -0
  100. package/dist/client/models/GitAddRequest.js +55 -0
  101. package/dist/client/models/GitBranch.d.ts +38 -0
  102. package/dist/client/models/GitBranch.js +55 -0
  103. package/dist/client/models/GitBranchRequest.d.ts +38 -0
  104. package/dist/client/models/GitBranchRequest.js +55 -0
  105. package/dist/client/models/GitCloneRequest.d.ts +62 -0
  106. package/dist/client/models/GitCloneRequest.js +63 -0
  107. package/dist/client/models/GitCommitInfo.d.ts +56 -0
  108. package/dist/client/models/GitCommitInfo.js +67 -0
  109. package/dist/client/models/GitCommitRequest.d.ts +50 -0
  110. package/dist/client/models/GitCommitRequest.js +63 -0
  111. package/dist/client/models/GitCommitResponse.d.ts +32 -0
  112. package/dist/client/models/GitCommitResponse.js +51 -0
  113. package/dist/client/models/GitNamespace.d.ts +38 -0
  114. package/dist/client/models/GitNamespace.js +55 -0
  115. package/dist/client/models/GitProvider.d.ts +75 -0
  116. package/dist/client/models/GitProvider.js +76 -0
  117. package/dist/client/models/GitPullRequest.d.ts +68 -0
  118. package/dist/client/models/GitPullRequest.js +75 -0
  119. package/dist/client/models/GitRepoRequest.d.ts +44 -0
  120. package/dist/client/models/GitRepoRequest.js +55 -0
  121. package/dist/client/models/GitRepository.d.ts +87 -0
  122. package/dist/client/models/GitRepository.js +84 -0
  123. package/dist/client/models/GitStatus.d.ts +57 -0
  124. package/dist/client/models/GitStatus.js +62 -0
  125. package/dist/client/models/GitUser.d.ts +50 -0
  126. package/dist/client/models/GitUser.js +63 -0
  127. package/dist/client/models/InstallProviderRequest.d.ts +40 -0
  128. package/dist/client/models/InstallProviderRequest.js +55 -0
  129. package/dist/client/models/ListBranchResponse.d.ts +32 -0
  130. package/dist/client/models/ListBranchResponse.js +51 -0
  131. package/dist/client/models/LogFileConfig.d.ts +62 -0
  132. package/dist/client/models/LogFileConfig.js +67 -0
  133. package/dist/client/models/LspCompletionParams.d.ts +58 -0
  134. package/dist/client/models/LspCompletionParams.js +69 -0
  135. package/dist/client/models/LspDocumentRequest.d.ts +44 -0
  136. package/dist/client/models/LspDocumentRequest.js +59 -0
  137. package/dist/client/models/LspLocation.d.ts +39 -0
  138. package/dist/client/models/LspLocation.js +56 -0
  139. package/dist/client/models/LspPosition.d.ts +38 -0
  140. package/dist/client/models/LspPosition.js +55 -0
  141. package/dist/client/models/LspRange.d.ts +39 -0
  142. package/dist/client/models/LspRange.js +56 -0
  143. package/dist/client/models/LspServerRequest.d.ts +38 -0
  144. package/dist/client/models/LspServerRequest.js +55 -0
  145. package/dist/client/models/LspSymbol.d.ts +45 -0
  146. package/dist/client/models/LspSymbol.js +60 -0
  147. package/dist/client/models/Match.d.ts +44 -0
  148. package/dist/client/models/Match.js +59 -0
  149. package/dist/client/models/NetworkKey.d.ts +32 -0
  150. package/dist/client/models/NetworkKey.js +51 -0
  151. package/dist/client/models/Position.d.ts +38 -0
  152. package/dist/client/models/Position.js +55 -0
  153. package/dist/client/models/PrebuildConfig.d.ts +56 -0
  154. package/dist/client/models/PrebuildConfig.js +67 -0
  155. package/dist/client/models/PrebuildDTO.d.ts +62 -0
  156. package/dist/client/models/PrebuildDTO.js +68 -0
  157. package/dist/client/models/ProfileData.d.ts +34 -0
  158. package/dist/client/models/ProfileData.js +51 -0
  159. package/dist/client/models/Project.d.ts +91 -0
  160. package/dist/client/models/Project.js +88 -0
  161. package/dist/client/models/ProjectConfig.d.ts +84 -0
  162. package/dist/client/models/ProjectConfig.js +87 -0
  163. package/dist/client/models/ProjectDirResponse.d.ts +32 -0
  164. package/dist/client/models/ProjectDirResponse.js +49 -0
  165. package/dist/client/models/ProjectInfo.d.ts +56 -0
  166. package/dist/client/models/ProjectInfo.js +65 -0
  167. package/dist/client/models/ProjectState.d.ts +45 -0
  168. package/dist/client/models/ProjectState.js +60 -0
  169. package/dist/client/models/Provider.d.ts +44 -0
  170. package/dist/client/models/Provider.js +57 -0
  171. package/dist/client/models/ProviderProviderInfo.d.ts +44 -0
  172. package/dist/client/models/ProviderProviderInfo.js +57 -0
  173. package/dist/client/models/ProviderProviderTargetProperty.d.ts +72 -0
  174. package/dist/client/models/ProviderProviderTargetProperty.js +64 -0
  175. package/dist/client/models/ProviderProviderTargetPropertyType.d.ts +29 -0
  176. package/dist/client/models/ProviderProviderTargetPropertyType.js +55 -0
  177. package/dist/client/models/ProviderTarget.d.ts +51 -0
  178. package/dist/client/models/ProviderTarget.js +64 -0
  179. package/dist/client/models/ReplaceRequest.d.ts +44 -0
  180. package/dist/client/models/ReplaceRequest.js +59 -0
  181. package/dist/client/models/ReplaceResult.d.ts +44 -0
  182. package/dist/client/models/ReplaceResult.js +53 -0
  183. package/dist/client/models/RepositoryUrl.d.ts +32 -0
  184. package/dist/client/models/RepositoryUrl.js +51 -0
  185. package/dist/client/models/Sample.d.ts +44 -0
  186. package/dist/client/models/Sample.js +59 -0
  187. package/dist/client/models/SearchFilesResponse.d.ts +32 -0
  188. package/dist/client/models/SearchFilesResponse.js +51 -0
  189. package/dist/client/models/ServerConfig.d.ts +130 -0
  190. package/dist/client/models/ServerConfig.js +119 -0
  191. package/dist/client/models/SetGitProviderConfig.d.ts +75 -0
  192. package/dist/client/models/SetGitProviderConfig.js +70 -0
  193. package/dist/client/models/SetProjectState.d.ts +39 -0
  194. package/dist/client/models/SetProjectState.js +56 -0
  195. package/dist/client/models/SigningMethod.d.ts +25 -0
  196. package/dist/client/models/SigningMethod.js +51 -0
  197. package/dist/client/models/Status.d.ts +31 -0
  198. package/dist/client/models/Status.js +57 -0
  199. package/dist/client/models/Workspace.d.ts +51 -0
  200. package/dist/client/models/Workspace.js +64 -0
  201. package/dist/client/models/WorkspaceDTO.d.ts +58 -0
  202. package/dist/client/models/WorkspaceDTO.js +67 -0
  203. package/dist/client/models/WorkspaceInfo.d.ts +45 -0
  204. package/dist/client/models/WorkspaceInfo.js +58 -0
  205. package/dist/client/models/index.d.ts +79 -0
  206. package/dist/client/models/index.js +97 -0
  207. package/dist/client/runtime.d.ts +182 -0
  208. package/dist/client/runtime.js +340 -0
  209. package/dist/code-toolbox/WorkspacePythonCodeToolbox.d.ts +5 -0
  210. package/dist/code-toolbox/WorkspacePythonCodeToolbox.js +13 -0
  211. package/dist/code-toolbox/WorkspaceTsCodeToolbox.d.ts +5 -0
  212. package/dist/code-toolbox/WorkspaceTsCodeToolbox.js +13 -0
  213. package/dist/index.d.ts +8 -0
  214. package/dist/index.js +13 -0
  215. package/package.json +42 -0
package/LICENCE ADDED
@@ -0,0 +1,43 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship
package/README.md ADDED
@@ -0,0 +1,181 @@
1
+ # Daytona SDK for TypeScript
2
+
3
+ A TypeScript SDK for interacting with Daytona Server API, providing a simple interface for Daytona Workspace management, Git operations, file system operations, and language server protocol support.
4
+
5
+ ## Prerequisites
6
+
7
+ Before using the Daytona SDK, you need to have a running Daytona server instance and proper configuration.
8
+
9
+ ### Server Installation
10
+
11
+ For detailed instructions on installing and setting up the Daytona server, please refer to the official installation guide at:
12
+ [https://github.com/daytonaio/daytona](https://github.com/daytonaio/daytona)
13
+
14
+ ### Configuration
15
+
16
+ To use the SDK, you'll need two essential pieces of information:
17
+
18
+ 1. **Server Address**:
19
+
20
+ - Run `daytona server config` to get your server's configuration
21
+ - Look for the `API URL` value in the output
22
+ - For testing and development, you can use the FRP address provided
23
+ - For production environments, it's recommended to use a static address
24
+
25
+ 2. **API Key**:
26
+ - Generate a new API key by running:
27
+ ```bash
28
+ daytona api-key generate
29
+ ```
30
+ - Save this key securely as it will be needed to authenticate with the server
31
+
32
+ ## Installation
33
+
34
+ You can install the package using npm:
35
+
36
+ ```bash
37
+ npm install @daytona/sdk
38
+ ```
39
+
40
+ Or using yarn:
41
+
42
+ ```bash
43
+ yarn add @daytona/sdk
44
+ ```
45
+
46
+ ## Quick Start
47
+
48
+ Here's a simple example of using the SDK:
49
+
50
+ ```typescript
51
+ import { Daytona } from '@daytona/sdk'
52
+
53
+ // Initialize the Daytona client
54
+ const daytona = new Daytona()
55
+
56
+ // Create the workspace instance
57
+ const workspace = await daytona.create({
58
+ language: 'typescript',
59
+ })
60
+
61
+ // Run the code securely inside the workspace
62
+ const response = await workspace.process.code_run('console.log("Hello World!")')
63
+ console.log(response.result)
64
+ ```
65
+
66
+ ## Features
67
+
68
+ - **Workspace Management**: Create, manage and remove workspaces
69
+ - **Git Operations**: Clone repositories, manage branches, and more
70
+ - **File System Operations**: Upload, download, search and manipulate files
71
+ - **Language Server Protocol**: Interact with language servers for code intelligence
72
+ - **Process Management**: Execute code and commands in workspaces
73
+
74
+ ## Configuration
75
+
76
+ The SDK can be configured using environment variables or by passing a configuration object:
77
+
78
+ ```typescript
79
+ import { Daytona, DaytonaConfig } from '@daytona/sdk'
80
+
81
+ const config: DaytonaConfig = {
82
+ apiKey: 'your-api-key',
83
+ serverUrl: 'https://your-daytona-server',
84
+ target: 'your-target',
85
+ }
86
+
87
+ const daytona = new Daytona(config)
88
+ ```
89
+
90
+ Or using environment variables:
91
+
92
+ - `DAYTONA_API_KEY`: Your Daytona API key
93
+ - `DAYTONA_SERVER_URL`: The Daytona server URL
94
+ - `DAYTONA_TARGET`: Your target environment
95
+
96
+ ## Examples
97
+
98
+ ### Execute command
99
+
100
+ ```typescript
101
+ const response = await workspace.process.code_run(
102
+ 'print("Sum of 3 and 4 is " + str(3 + 4))',
103
+ )
104
+ if (response.code !== 0) {
105
+ console.log(`Error: ${response.code} ${response.result}`)
106
+ } else {
107
+ console.log(response.result)
108
+ }
109
+ ```
110
+
111
+ ### File Operations
112
+
113
+ ```typescript
114
+ // Upload a file
115
+ await workspace.fs.uploadFile('/path/to/file.txt', new Blob(['Hello, World!']))
116
+
117
+ // Download a file
118
+ const content = await workspace.fs.downloadFile('/path/to/file.txt')
119
+
120
+ // Search for files
121
+ const matches = await workspace.fs.findFiles(root_dir, 'search_pattern')
122
+ ```
123
+
124
+ ### Git Operations
125
+
126
+ ```typescript
127
+ // Clone a repository
128
+ await workspace.git.clone('https://github.com/example/repo', '/path/to/clone')
129
+
130
+ // List branches
131
+ const branches = await workspace.git.branches('/path/to/repo')
132
+
133
+ // Add files
134
+ await workspace.git.add('/path/to/repo', ['file1.txt', 'file2.txt'])
135
+ ```
136
+
137
+ ### Language Server Protocol
138
+
139
+ ```typescript
140
+ // Create and start a language server
141
+ const lsp = workspace.createLspServer('typescript', '/path/to/project')
142
+ await lsp.start()
143
+
144
+ // Notify the lsp for the file
145
+ await lsp.didOpen('/path/to/file.ts')
146
+
147
+ // Get document symbols
148
+ const symbols = await lsp.documentSymbols('/path/to/file.ts')
149
+
150
+ // Get completions
151
+ const completions = await lsp.completions('/path/to/file.ts', {
152
+ line: 10,
153
+ character: 15,
154
+ })
155
+ ```
156
+
157
+ ## Contributing
158
+
159
+ Contributions are welcome! Please feel free to submit a Pull Request.
160
+
161
+ ## License
162
+
163
+ This project is licensed under the Apache License, Version 2.0 - see below for details:
164
+
165
+ ```
166
+ Copyright 2024 Daytona
167
+
168
+ Licensed under the Apache License, Version 2.0 (the "License");
169
+ you may not use this file except in compliance with the License.
170
+ You may obtain a copy of the License at
171
+
172
+ http://www.apache.org/licenses/LICENSE-2.0
173
+
174
+ Unless required by applicable law or agreed to in writing, software
175
+ distributed under the License is distributed on an "AS IS" BASIS,
176
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
177
+ See the License for the specific language governing permissions and
178
+ limitations under the License.
179
+ ```
180
+
181
+ For the full license text, please see the [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0).
@@ -0,0 +1,106 @@
1
+ import { Workspace } from './Workspace';
2
+ import { CreateWorkspaceTargetEnum } from '@daytonaio/api-client';
3
+ /**
4
+ * Configuration options for initializing the Daytona client
5
+ * @interface DaytonaConfig
6
+ */
7
+ export interface DaytonaConfig {
8
+ /** API key for authentication with Daytona server */
9
+ apiKey: string;
10
+ /** URL of the Daytona server */
11
+ serverUrl: string;
12
+ /** Target environment for workspaces */
13
+ target: CreateWorkspaceTargetEnum;
14
+ }
15
+ /**
16
+ * Supported programming languages for code execution
17
+ */
18
+ export type CodeLanguage = 'python' | 'javascript' | 'typescript';
19
+ /**
20
+ * Resource allocation for a workspace
21
+ * @interface WorkspaceResources
22
+ */
23
+ export interface WorkspaceResources {
24
+ /** CPU allocation for the workspace */
25
+ cpu?: number;
26
+ /** GPU allocation for the workspace */
27
+ gpu?: number;
28
+ /** Memory allocation for the workspace in MB */
29
+ memory?: number;
30
+ /** Disk space allocation for the workspace in MB */
31
+ disk?: number;
32
+ }
33
+ /**
34
+ * Parameters for creating a new workspace
35
+ * @interface CreateWorkspaceParams
36
+ */
37
+ export type CreateWorkspaceParams = {
38
+ /** Optional workspace ID. If not provided, a random ID will be generated */
39
+ id?: string;
40
+ /** Optional Docker image to use for the workspace */
41
+ image?: string;
42
+ /** Optional os user to use for the workspace */
43
+ user?: string;
44
+ /** Programming language for direct code execution */
45
+ language?: CodeLanguage;
46
+ /** Optional environment variables to set in the workspace */
47
+ envVars?: Record<string, string>;
48
+ /** Workspace labels */
49
+ labels?: Record<string, string>;
50
+ /** Is the workspace port preview public */
51
+ public?: boolean;
52
+ /** Target location for the workspace */
53
+ target?: string;
54
+ /** Resource allocation for the workspace */
55
+ resources?: WorkspaceResources;
56
+ /** If true, will not wait for the workspace to be ready before returning */
57
+ async?: boolean;
58
+ };
59
+ /**
60
+ * Main class for interacting with Daytona Server API
61
+ * @class Daytona
62
+ */
63
+ export declare class Daytona {
64
+ private readonly workspaceApi;
65
+ private readonly toolboxApi;
66
+ private readonly target;
67
+ private readonly apiKey;
68
+ private readonly serverUrl;
69
+ /**
70
+ * Creates a new Daytona client instance
71
+ * @param {DaytonaConfig} [config] - Configuration options
72
+ * @throws {Error} When API key or server URL is missing
73
+ */
74
+ constructor(config?: DaytonaConfig);
75
+ /**
76
+ * Creates a new workspace
77
+ * @param {CreateWorkspaceParams} [params] - Parameters for workspace creation
78
+ * @returns {Promise<Workspace>} The created workspace instance
79
+ */
80
+ create(params?: CreateWorkspaceParams): Promise<Workspace>;
81
+ /**
82
+ * Gets a workspace by its ID
83
+ * @param {string} workspaceId - The ID of the workspace to retrieve
84
+ * @returns {Promise<Workspace>} The workspace instance
85
+ */
86
+ get(workspaceId: string): Promise<Workspace>;
87
+ /**
88
+ * Starts a workspace
89
+ * @param {Workspace} workspace - The workspace to start
90
+ */
91
+ start(workspace: Workspace): Promise<void>;
92
+ /**
93
+ * Stops a workspace
94
+ * @param {Workspace} workspace - The workspace to stop
95
+ * @returns {Promise<void>}
96
+ */
97
+ stop(workspace: Workspace): Promise<void>;
98
+ /**
99
+ * Removes a workspace
100
+ * @param {Workspace} workspace - The workspace to remove
101
+ * @returns {Promise<void>}
102
+ */
103
+ remove(workspace: Workspace): Promise<void>;
104
+ waitUntilReady(workspace: Workspace): Promise<void>;
105
+ private getCodeToolbox;
106
+ }
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Daytona = void 0;
4
+ const uuid_1 = require("uuid");
5
+ const WorkspacePythonCodeToolbox_1 = require("./code-toolbox/WorkspacePythonCodeToolbox");
6
+ const Workspace_1 = require("./Workspace");
7
+ const api_client_1 = require("@daytonaio/api-client");
8
+ const WorkspaceTsCodeToolbox_1 = require("./code-toolbox/WorkspaceTsCodeToolbox");
9
+ /**
10
+ * Main class for interacting with Daytona Server API
11
+ * @class Daytona
12
+ */
13
+ class Daytona {
14
+ /**
15
+ * Creates a new Daytona client instance
16
+ * @param {DaytonaConfig} [config] - Configuration options
17
+ * @throws {Error} When API key or server URL is missing
18
+ */
19
+ constructor(config) {
20
+ const apiKey = (config === null || config === void 0 ? void 0 : config.apiKey) || process.env.DAYTONA_API_KEY;
21
+ if (!apiKey) {
22
+ throw new Error('API key is required');
23
+ }
24
+ const serverUrl = (config === null || config === void 0 ? void 0 : config.serverUrl) || process.env.DAYTONA_SERVER_URL;
25
+ if (!serverUrl) {
26
+ throw new Error('Server URL is required');
27
+ }
28
+ const envTarget = process.env.DAYTONA_TARGET;
29
+ const target = (config === null || config === void 0 ? void 0 : config.target) || envTarget;
30
+ this.apiKey = apiKey;
31
+ this.serverUrl = serverUrl;
32
+ this.target = target;
33
+ const configuration = new api_client_1.Configuration({
34
+ basePath: this.serverUrl,
35
+ baseOptions: {
36
+ headers: {
37
+ 'Authorization': `Bearer ${this.apiKey}`,
38
+ },
39
+ },
40
+ });
41
+ this.workspaceApi = new api_client_1.WorkspaceApi(configuration);
42
+ this.toolboxApi = new api_client_1.ToolboxApi(configuration);
43
+ }
44
+ /**
45
+ * Creates a new workspace
46
+ * @param {CreateWorkspaceParams} [params] - Parameters for workspace creation
47
+ * @returns {Promise<Workspace>} The created workspace instance
48
+ */
49
+ async create(params) {
50
+ var _a, _b, _c, _d;
51
+ const workspaceId = (params === null || params === void 0 ? void 0 : params.id) || `sandbox-${(0, uuid_1.v4)().slice(0, 8)}`;
52
+ const codeToolbox = this.getCodeToolbox(params === null || params === void 0 ? void 0 : params.language);
53
+ const labels = (params === null || params === void 0 ? void 0 : params.labels) || {};
54
+ if (params === null || params === void 0 ? void 0 : params.language) {
55
+ labels[`code-toolbox-language`] = params.language;
56
+ }
57
+ const reponse = await this.workspaceApi.createWorkspace({
58
+ id: workspaceId,
59
+ name: workspaceId, // todo: remove this after project refactor
60
+ image: params === null || params === void 0 ? void 0 : params.image,
61
+ user: params === null || params === void 0 ? void 0 : params.user,
62
+ env: (params === null || params === void 0 ? void 0 : params.envVars) || {},
63
+ target: this.target,
64
+ cpu: (_a = params === null || params === void 0 ? void 0 : params.resources) === null || _a === void 0 ? void 0 : _a.cpu,
65
+ gpu: (_b = params === null || params === void 0 ? void 0 : params.resources) === null || _b === void 0 ? void 0 : _b.gpu,
66
+ memory: (_c = params === null || params === void 0 ? void 0 : params.resources) === null || _c === void 0 ? void 0 : _c.memory,
67
+ disk: (_d = params === null || params === void 0 ? void 0 : params.resources) === null || _d === void 0 ? void 0 : _d.disk,
68
+ });
69
+ const workspaceInstance = reponse.data;
70
+ const workspace = new Workspace_1.Workspace(workspaceId, workspaceInstance, this.workspaceApi, this.toolboxApi, codeToolbox);
71
+ if (!(params === null || params === void 0 ? void 0 : params.async)) {
72
+ await this.waitUntilReady(workspace);
73
+ }
74
+ return workspace;
75
+ }
76
+ /**
77
+ * Gets a workspace by its ID
78
+ * @param {string} workspaceId - The ID of the workspace to retrieve
79
+ * @returns {Promise<Workspace>} The workspace instance
80
+ */
81
+ async get(workspaceId) {
82
+ const response = await this.workspaceApi.getWorkspace(workspaceId);
83
+ const workspaceInstance = response.data;
84
+ const language = workspaceInstance.labels && workspaceInstance.labels[`code-toolbox-language`];
85
+ const codeToolbox = this.getCodeToolbox(language);
86
+ return new Workspace_1.Workspace(workspaceId, workspaceInstance, this.workspaceApi, this.toolboxApi, codeToolbox);
87
+ }
88
+ /**
89
+ * Starts a workspace
90
+ * @param {Workspace} workspace - The workspace to start
91
+ */
92
+ async start(workspace) {
93
+ await this.workspaceApi.startWorkspace(workspace.id);
94
+ }
95
+ /**
96
+ * Stops a workspace
97
+ * @param {Workspace} workspace - The workspace to stop
98
+ * @returns {Promise<void>}
99
+ */
100
+ async stop(workspace) {
101
+ await this.workspaceApi.stopWorkspace(workspace.id);
102
+ }
103
+ /**
104
+ * Removes a workspace
105
+ * @param {Workspace} workspace - The workspace to remove
106
+ * @returns {Promise<void>}
107
+ */
108
+ async remove(workspace) {
109
+ await this.workspaceApi.deleteWorkspace(workspace.id, true);
110
+ }
111
+ async waitUntilReady(workspace) {
112
+ const maxAttempts = 60; // 5 minutes with 5 second intervals
113
+ let attempts = 0;
114
+ while (attempts < maxAttempts) {
115
+ const response = await this.workspaceApi.getWorkspace(workspace.id);
116
+ const state = response.data.state;
117
+ if (state === 'started') {
118
+ return;
119
+ }
120
+ if (state === 'error') {
121
+ throw new Error(`Workspace failed to start with status: ${status}`);
122
+ }
123
+ await new Promise(resolve => setTimeout(resolve, 100)); // Wait 100 ms between checks
124
+ attempts++;
125
+ }
126
+ throw new Error('Workspace failed to become ready within the timeout period');
127
+ }
128
+ getCodeToolbox(language) {
129
+ switch (language) {
130
+ case 'javascript':
131
+ case 'typescript':
132
+ return new WorkspaceTsCodeToolbox_1.WorkspaceTsCodeToolbox();
133
+ case 'python':
134
+ case undefined:
135
+ return new WorkspacePythonCodeToolbox_1.WorkspacePythonCodeToolbox();
136
+ default:
137
+ throw new Error(`Unsupported language: ${language}`);
138
+ }
139
+ }
140
+ }
141
+ exports.Daytona = Daytona;
@@ -0,0 +1,97 @@
1
+ import { FileInfo, Match, ReplaceResult, SearchFilesResponse, Workspace as WorkspaceInstance, ToolboxApi } from '@daytonaio/api-client';
2
+ /**
3
+ * Parameters for setting file permissions
4
+ * @interface FilePermissionsParams
5
+ */
6
+ type FilePermissionsParams = {
7
+ /** Group owner of the file */
8
+ group?: string;
9
+ /** File mode/permissions in octal format (e.g. "644") */
10
+ mode?: string;
11
+ /** User owner of the file */
12
+ owner?: string;
13
+ };
14
+ /**
15
+ * Provides file system operations within a workspace
16
+ * @class FileSystem
17
+ */
18
+ export declare class FileSystem {
19
+ private readonly instance;
20
+ private readonly toolboxApi;
21
+ constructor(instance: WorkspaceInstance, toolboxApi: ToolboxApi);
22
+ /**
23
+ * Creates a new folder in the workspace
24
+ * @param {string} path - Path where the folder should be created
25
+ * @param {string} mode - Folder permissions in octal format
26
+ * @returns {Promise<void>}
27
+ */
28
+ createFolder(path: string, mode: string): Promise<void>;
29
+ /**
30
+ * Deletes a file from the workspace
31
+ * @param {string} path - Path to the file to delete
32
+ * @returns {Promise<void>}
33
+ */
34
+ deleteFile(path: string): Promise<void>;
35
+ /**
36
+ * Downloads a file from the workspace
37
+ * @param {string} path - Path to the file to download
38
+ * @returns {Promise<Blob>} The file contents as a Blob
39
+ */
40
+ downloadFile(path: string): Promise<Blob>;
41
+ /**
42
+ * Searches for files matching a pattern
43
+ * @param {string} path - Directory to search in
44
+ * @param {string} pattern - Search pattern
45
+ * @returns {Promise<Array<Match>>} Array of matching files
46
+ */
47
+ findFiles(path: string, pattern: string): Promise<Array<Match>>;
48
+ /**
49
+ * Gets details about a file
50
+ * @param {string} path - Path to the file
51
+ * @returns {Promise<FileInfo>} File information
52
+ */
53
+ getFileDetails(path: string): Promise<FileInfo>;
54
+ /**
55
+ * Lists files in a directory
56
+ * @param {string} path - Directory path to list
57
+ * @returns {Promise<FileInfo[]>} Array of file information
58
+ */
59
+ listFiles(path: string): Promise<FileInfo[]>;
60
+ /**
61
+ * Moves/renames files
62
+ * @param {string} source - Source path
63
+ * @param {string} destination - Destination path
64
+ * @returns {Promise<void>}
65
+ */
66
+ moveFiles(source: string, destination: string): Promise<void>;
67
+ /**
68
+ * Replaces text in multiple files
69
+ * @param {string[]} files - Array of file paths
70
+ * @param {string} pattern - Pattern to replace
71
+ * @param {string} newValue - Replacement value
72
+ * @returns {Promise<Array<ReplaceResult>>} Results of the replace operation
73
+ */
74
+ replaceInFiles(files: string[], pattern: string, newValue: string): Promise<Array<ReplaceResult>>;
75
+ /**
76
+ * Searches for files by name pattern
77
+ * @param {string} path - Directory to search in
78
+ * @param {string} pattern - Search pattern
79
+ * @returns {Promise<SearchFilesResponse>} Search results
80
+ */
81
+ searchFiles(path: string, pattern: string): Promise<SearchFilesResponse>;
82
+ /**
83
+ * Sets file permissions
84
+ * @param {string} path - Path to the file
85
+ * @param {FilePermissionsParams} permissions - Permission settings
86
+ * @returns {Promise<void>}
87
+ */
88
+ setFilePermissions(path: string, permissions: FilePermissionsParams): Promise<void>;
89
+ /**
90
+ * Uploads a file to the workspace
91
+ * @param {string} path - Destination path
92
+ * @param {Blob} file - File contents to upload
93
+ * @returns {Promise<void>}
94
+ */
95
+ uploadFile(path: string, file: File): Promise<void>;
96
+ }
97
+ export {};
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FileSystem = void 0;
4
+ /**
5
+ * Provides file system operations within a workspace
6
+ * @class FileSystem
7
+ */
8
+ class FileSystem {
9
+ constructor(instance, toolboxApi) {
10
+ this.instance = instance;
11
+ this.toolboxApi = toolboxApi;
12
+ }
13
+ /**
14
+ * Creates a new folder in the workspace
15
+ * @param {string} path - Path where the folder should be created
16
+ * @param {string} mode - Folder permissions in octal format
17
+ * @returns {Promise<void>}
18
+ */
19
+ async createFolder(path, mode) {
20
+ const response = await this.toolboxApi.createFolder(this.instance.id, path, mode);
21
+ return response.data;
22
+ }
23
+ /**
24
+ * Deletes a file from the workspace
25
+ * @param {string} path - Path to the file to delete
26
+ * @returns {Promise<void>}
27
+ */
28
+ async deleteFile(path) {
29
+ const response = await this.toolboxApi.deleteFile(this.instance.id, path);
30
+ return response.data;
31
+ }
32
+ /**
33
+ * Downloads a file from the workspace
34
+ * @param {string} path - Path to the file to download
35
+ * @returns {Promise<Blob>} The file contents as a Blob
36
+ */
37
+ async downloadFile(path) {
38
+ const response = await this.toolboxApi.downloadFile(this.instance.id, path);
39
+ return response.data;
40
+ }
41
+ /**
42
+ * Searches for files matching a pattern
43
+ * @param {string} path - Directory to search in
44
+ * @param {string} pattern - Search pattern
45
+ * @returns {Promise<Array<Match>>} Array of matching files
46
+ */
47
+ async findFiles(path, pattern) {
48
+ const response = await this.toolboxApi.findInFiles(this.instance.id, path, pattern);
49
+ return response.data;
50
+ }
51
+ /**
52
+ * Gets details about a file
53
+ * @param {string} path - Path to the file
54
+ * @returns {Promise<FileInfo>} File information
55
+ */
56
+ async getFileDetails(path) {
57
+ const response = await this.toolboxApi.getFileInfo(this.instance.id, path);
58
+ return response.data;
59
+ }
60
+ /**
61
+ * Lists files in a directory
62
+ * @param {string} path - Directory path to list
63
+ * @returns {Promise<FileInfo[]>} Array of file information
64
+ */
65
+ async listFiles(path) {
66
+ const response = await this.toolboxApi.listFiles(this.instance.id, path);
67
+ return response.data;
68
+ }
69
+ /**
70
+ * Moves/renames files
71
+ * @param {string} source - Source path
72
+ * @param {string} destination - Destination path
73
+ * @returns {Promise<void>}
74
+ */
75
+ async moveFiles(source, destination) {
76
+ const response = await this.toolboxApi.moveFile(this.instance.id, source, destination);
77
+ return response.data;
78
+ }
79
+ /**
80
+ * Replaces text in multiple files
81
+ * @param {string[]} files - Array of file paths
82
+ * @param {string} pattern - Pattern to replace
83
+ * @param {string} newValue - Replacement value
84
+ * @returns {Promise<Array<ReplaceResult>>} Results of the replace operation
85
+ */
86
+ async replaceInFiles(files, pattern, newValue) {
87
+ const replaceRequest = {
88
+ files,
89
+ newValue,
90
+ pattern,
91
+ };
92
+ const response = await this.toolboxApi.replaceInFiles(this.instance.id, replaceRequest);
93
+ return response.data;
94
+ }
95
+ /**
96
+ * Searches for files by name pattern
97
+ * @param {string} path - Directory to search in
98
+ * @param {string} pattern - Search pattern
99
+ * @returns {Promise<SearchFilesResponse>} Search results
100
+ */
101
+ async searchFiles(path, pattern) {
102
+ const response = await this.toolboxApi.searchFiles(this.instance.id, path, pattern);
103
+ return response.data;
104
+ }
105
+ /**
106
+ * Sets file permissions
107
+ * @param {string} path - Path to the file
108
+ * @param {FilePermissionsParams} permissions - Permission settings
109
+ * @returns {Promise<void>}
110
+ */
111
+ async setFilePermissions(path, permissions) {
112
+ const response = await this.toolboxApi.setFilePermissions(this.instance.id, path, permissions.owner, permissions.group, permissions.mode);
113
+ return response.data;
114
+ }
115
+ /**
116
+ * Uploads a file to the workspace
117
+ * @param {string} path - Destination path
118
+ * @param {Blob} file - File contents to upload
119
+ * @returns {Promise<void>}
120
+ */
121
+ async uploadFile(path, file) {
122
+ const response = await this.toolboxApi.uploadFile(this.instance.id, path, file);
123
+ return response.data;
124
+ }
125
+ }
126
+ exports.FileSystem = FileSystem;