@daytonaio/sdk 0.9.2 → 0.10.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.
- package/README.md +52 -59
- package/dist/Daytona.d.ts +239 -47
- package/dist/Daytona.js +274 -63
- package/dist/FileSystem.d.ts +183 -32
- package/dist/FileSystem.js +168 -28
- package/dist/Git.d.ts +178 -30
- package/dist/Git.js +178 -30
- package/dist/LspServer.d.ts +170 -22
- package/dist/LspServer.js +162 -18
- package/dist/Process.d.ts +187 -37
- package/dist/Process.js +185 -44
- package/dist/Workspace.d.ts +252 -36
- package/dist/Workspace.js +239 -49
- package/dist/code-toolbox/WorkspacePythonCodeToolbox.d.ts +2 -1
- package/dist/code-toolbox/WorkspacePythonCodeToolbox.js +4 -2
- package/dist/code-toolbox/WorkspaceTsCodeToolbox.d.ts +2 -1
- package/dist/code-toolbox/WorkspaceTsCodeToolbox.js +4 -2
- package/dist/errors/DaytonaError.d.ts +8 -0
- package/dist/errors/DaytonaError.js +12 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +12 -1
- package/package.json +9 -8
- package/dist/client/apis/ApiKeyApi.d.ts +0 -54
- package/dist/client/apis/ApiKeyApi.js +0 -135
- package/dist/client/apis/BuildApi.d.ts +0 -95
- package/dist/client/apis/BuildApi.js +0 -228
- package/dist/client/apis/ContainerRegistryApi.d.ts +0 -68
- package/dist/client/apis/ContainerRegistryApi.js +0 -163
- package/dist/client/apis/DefaultApi.d.ts +0 -31
- package/dist/client/apis/DefaultApi.js +0 -72
- package/dist/client/apis/GitProviderApi.d.ts +0 -197
- package/dist/client/apis/GitProviderApi.js +0 -477
- package/dist/client/apis/PrebuildApi.d.ts +0 -97
- package/dist/client/apis/PrebuildApi.js +0 -241
- package/dist/client/apis/ProfileApi.d.ts +0 -51
- package/dist/client/apis/ProfileApi.js +0 -128
- package/dist/client/apis/ProjectConfigApi.d.ts +0 -94
- package/dist/client/apis/ProjectConfigApi.js +0 -220
- package/dist/client/apis/ProviderApi.d.ts +0 -71
- package/dist/client/apis/ProviderApi.js +0 -160
- package/dist/client/apis/SampleApi.d.ts +0 -28
- package/dist/client/apis/SampleApi.js +0 -73
- package/dist/client/apis/ServerApi.d.ts +0 -61
- package/dist/client/apis/ServerApi.js +0 -156
- package/dist/client/apis/TargetApi.d.ts +0 -67
- package/dist/client/apis/TargetApi.js +0 -159
- package/dist/client/apis/WorkspaceApi.d.ts +0 -141
- package/dist/client/apis/WorkspaceApi.js +0 -330
- package/dist/client/apis/WorkspaceToolboxApi.d.ts +0 -464
- package/dist/client/apis/WorkspaceToolboxApi.js +0 -1248
- package/dist/client/apis/index.d.ts +0 -14
- package/dist/client/apis/index.js +0 -32
- package/dist/client/index.d.ts +0 -3
- package/dist/client/index.js +0 -21
- package/dist/client/models/ApiKey.d.ts +0 -45
- package/dist/client/models/ApiKey.js +0 -60
- package/dist/client/models/ApikeyApiKeyType.d.ts +0 -26
- package/dist/client/models/ApikeyApiKeyType.js +0 -52
- package/dist/client/models/Build.d.ts +0 -98
- package/dist/client/models/Build.js +0 -91
- package/dist/client/models/BuildBuildState.d.ts +0 -31
- package/dist/client/models/BuildBuildState.js +0 -57
- package/dist/client/models/BuildConfig.d.ts +0 -40
- package/dist/client/models/BuildConfig.js +0 -57
- package/dist/client/models/CachedBuild.d.ts +0 -38
- package/dist/client/models/CachedBuild.js +0 -55
- package/dist/client/models/CloneTarget.d.ts +0 -25
- package/dist/client/models/CloneTarget.js +0 -51
- package/dist/client/models/CompletionContext.d.ts +0 -38
- package/dist/client/models/CompletionContext.js +0 -53
- package/dist/client/models/CompletionItem.d.ts +0 -68
- package/dist/client/models/CompletionItem.js +0 -63
- package/dist/client/models/CompletionList.d.ts +0 -39
- package/dist/client/models/CompletionList.js +0 -56
- package/dist/client/models/ContainerConfig.d.ts +0 -38
- package/dist/client/models/ContainerConfig.js +0 -55
- package/dist/client/models/ContainerRegistry.d.ts +0 -44
- package/dist/client/models/ContainerRegistry.js +0 -59
- package/dist/client/models/CreateBuildDTO.d.ts +0 -52
- package/dist/client/models/CreateBuildDTO.js +0 -62
- package/dist/client/models/CreatePrebuildDTO.d.ts +0 -56
- package/dist/client/models/CreatePrebuildDTO.js +0 -59
- package/dist/client/models/CreateProjectConfigDTO.d.ts +0 -71
- package/dist/client/models/CreateProjectConfigDTO.js +0 -72
- package/dist/client/models/CreateProjectDTO.d.ts +0 -72
- package/dist/client/models/CreateProjectDTO.js +0 -73
- package/dist/client/models/CreateProjectSourceDTO.d.ts +0 -33
- package/dist/client/models/CreateProjectSourceDTO.js +0 -52
- package/dist/client/models/CreateProviderTargetDTO.d.ts +0 -45
- package/dist/client/models/CreateProviderTargetDTO.js +0 -60
- package/dist/client/models/CreateWorkspaceDTO.d.ts +0 -51
- package/dist/client/models/CreateWorkspaceDTO.js +0 -64
- package/dist/client/models/DevcontainerConfig.d.ts +0 -32
- package/dist/client/models/DevcontainerConfig.js +0 -51
- package/dist/client/models/ExecuteRequest.d.ts +0 -38
- package/dist/client/models/ExecuteRequest.js +0 -53
- package/dist/client/models/ExecuteResponse.d.ts +0 -38
- package/dist/client/models/ExecuteResponse.js +0 -55
- package/dist/client/models/FRPSConfig.d.ts +0 -44
- package/dist/client/models/FRPSConfig.js +0 -59
- package/dist/client/models/FileInfo.d.ts +0 -74
- package/dist/client/models/FileInfo.js +0 -79
- package/dist/client/models/FileStatus.d.ts +0 -51
- package/dist/client/models/FileStatus.js +0 -64
- package/dist/client/models/GetRepositoryContext.d.ts +0 -80
- package/dist/client/models/GetRepositoryContext.js +0 -67
- package/dist/client/models/GitAddRequest.d.ts +0 -38
- package/dist/client/models/GitAddRequest.js +0 -55
- package/dist/client/models/GitBranch.d.ts +0 -38
- package/dist/client/models/GitBranch.js +0 -55
- package/dist/client/models/GitBranchRequest.d.ts +0 -38
- package/dist/client/models/GitBranchRequest.js +0 -55
- package/dist/client/models/GitCloneRequest.d.ts +0 -62
- package/dist/client/models/GitCloneRequest.js +0 -63
- package/dist/client/models/GitCommitInfo.d.ts +0 -56
- package/dist/client/models/GitCommitInfo.js +0 -67
- package/dist/client/models/GitCommitRequest.d.ts +0 -50
- package/dist/client/models/GitCommitRequest.js +0 -63
- package/dist/client/models/GitCommitResponse.d.ts +0 -32
- package/dist/client/models/GitCommitResponse.js +0 -51
- package/dist/client/models/GitNamespace.d.ts +0 -38
- package/dist/client/models/GitNamespace.js +0 -55
- package/dist/client/models/GitProvider.d.ts +0 -75
- package/dist/client/models/GitProvider.js +0 -76
- package/dist/client/models/GitPullRequest.d.ts +0 -68
- package/dist/client/models/GitPullRequest.js +0 -75
- package/dist/client/models/GitRepoRequest.d.ts +0 -44
- package/dist/client/models/GitRepoRequest.js +0 -55
- package/dist/client/models/GitRepository.d.ts +0 -87
- package/dist/client/models/GitRepository.js +0 -84
- package/dist/client/models/GitStatus.d.ts +0 -57
- package/dist/client/models/GitStatus.js +0 -62
- package/dist/client/models/GitUser.d.ts +0 -50
- package/dist/client/models/GitUser.js +0 -63
- package/dist/client/models/InstallProviderRequest.d.ts +0 -40
- package/dist/client/models/InstallProviderRequest.js +0 -55
- package/dist/client/models/ListBranchResponse.d.ts +0 -32
- package/dist/client/models/ListBranchResponse.js +0 -51
- package/dist/client/models/LogFileConfig.d.ts +0 -62
- package/dist/client/models/LogFileConfig.js +0 -67
- package/dist/client/models/LspCompletionParams.d.ts +0 -58
- package/dist/client/models/LspCompletionParams.js +0 -69
- package/dist/client/models/LspDocumentRequest.d.ts +0 -44
- package/dist/client/models/LspDocumentRequest.js +0 -59
- package/dist/client/models/LspLocation.d.ts +0 -39
- package/dist/client/models/LspLocation.js +0 -56
- package/dist/client/models/LspPosition.d.ts +0 -38
- package/dist/client/models/LspPosition.js +0 -55
- package/dist/client/models/LspRange.d.ts +0 -39
- package/dist/client/models/LspRange.js +0 -56
- package/dist/client/models/LspServerRequest.d.ts +0 -38
- package/dist/client/models/LspServerRequest.js +0 -55
- package/dist/client/models/LspSymbol.d.ts +0 -45
- package/dist/client/models/LspSymbol.js +0 -60
- package/dist/client/models/Match.d.ts +0 -44
- package/dist/client/models/Match.js +0 -59
- package/dist/client/models/NetworkKey.d.ts +0 -32
- package/dist/client/models/NetworkKey.js +0 -51
- package/dist/client/models/Position.d.ts +0 -38
- package/dist/client/models/Position.js +0 -55
- package/dist/client/models/PrebuildConfig.d.ts +0 -56
- package/dist/client/models/PrebuildConfig.js +0 -67
- package/dist/client/models/PrebuildDTO.d.ts +0 -62
- package/dist/client/models/PrebuildDTO.js +0 -68
- package/dist/client/models/ProfileData.d.ts +0 -34
- package/dist/client/models/ProfileData.js +0 -51
- package/dist/client/models/Project.d.ts +0 -91
- package/dist/client/models/Project.js +0 -88
- package/dist/client/models/ProjectConfig.d.ts +0 -84
- package/dist/client/models/ProjectConfig.js +0 -87
- package/dist/client/models/ProjectDirResponse.d.ts +0 -32
- package/dist/client/models/ProjectDirResponse.js +0 -49
- package/dist/client/models/ProjectInfo.d.ts +0 -56
- package/dist/client/models/ProjectInfo.js +0 -65
- package/dist/client/models/ProjectState.d.ts +0 -45
- package/dist/client/models/ProjectState.js +0 -60
- package/dist/client/models/Provider.d.ts +0 -44
- package/dist/client/models/Provider.js +0 -57
- package/dist/client/models/ProviderProviderInfo.d.ts +0 -44
- package/dist/client/models/ProviderProviderInfo.js +0 -57
- package/dist/client/models/ProviderProviderTargetProperty.d.ts +0 -72
- package/dist/client/models/ProviderProviderTargetProperty.js +0 -64
- package/dist/client/models/ProviderProviderTargetPropertyType.d.ts +0 -29
- package/dist/client/models/ProviderProviderTargetPropertyType.js +0 -55
- package/dist/client/models/ProviderTarget.d.ts +0 -51
- package/dist/client/models/ProviderTarget.js +0 -64
- package/dist/client/models/ReplaceRequest.d.ts +0 -44
- package/dist/client/models/ReplaceRequest.js +0 -59
- package/dist/client/models/ReplaceResult.d.ts +0 -44
- package/dist/client/models/ReplaceResult.js +0 -53
- package/dist/client/models/RepositoryUrl.d.ts +0 -32
- package/dist/client/models/RepositoryUrl.js +0 -51
- package/dist/client/models/Sample.d.ts +0 -44
- package/dist/client/models/Sample.js +0 -59
- package/dist/client/models/SearchFilesResponse.d.ts +0 -32
- package/dist/client/models/SearchFilesResponse.js +0 -51
- package/dist/client/models/ServerConfig.d.ts +0 -130
- package/dist/client/models/ServerConfig.js +0 -119
- package/dist/client/models/SetGitProviderConfig.d.ts +0 -75
- package/dist/client/models/SetGitProviderConfig.js +0 -70
- package/dist/client/models/SetProjectState.d.ts +0 -39
- package/dist/client/models/SetProjectState.js +0 -56
- package/dist/client/models/SigningMethod.d.ts +0 -25
- package/dist/client/models/SigningMethod.js +0 -51
- package/dist/client/models/Status.d.ts +0 -31
- package/dist/client/models/Status.js +0 -57
- package/dist/client/models/Workspace.d.ts +0 -51
- package/dist/client/models/Workspace.js +0 -64
- package/dist/client/models/WorkspaceDTO.d.ts +0 -58
- package/dist/client/models/WorkspaceDTO.js +0 -67
- package/dist/client/models/WorkspaceInfo.d.ts +0 -45
- package/dist/client/models/WorkspaceInfo.js +0 -58
- package/dist/client/models/index.d.ts +0 -79
- package/dist/client/models/index.js +0 -97
- package/dist/client/runtime.d.ts +0 -182
- package/dist/client/runtime.js +0 -340
package/README.md
CHANGED
|
@@ -2,33 +2,6 @@
|
|
|
2
2
|
|
|
3
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
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
5
|
## Installation
|
|
33
6
|
|
|
34
7
|
You can install the package using npm:
|
|
@@ -50,41 +23,33 @@ Here's a simple example of using the SDK:
|
|
|
50
23
|
```typescript
|
|
51
24
|
import { Daytona } from '@daytonaio/sdk'
|
|
52
25
|
|
|
53
|
-
// Initialize
|
|
26
|
+
// Initialize using environment variables
|
|
54
27
|
const daytona = new Daytona()
|
|
55
28
|
|
|
56
|
-
// Create
|
|
57
|
-
const workspace = await daytona.create(
|
|
58
|
-
language: 'typescript',
|
|
59
|
-
})
|
|
29
|
+
// Create a workspace
|
|
30
|
+
const workspace = await daytona.create()
|
|
60
31
|
|
|
61
|
-
// Run
|
|
62
|
-
const response = await workspace.process.
|
|
32
|
+
// Run code in the workspace
|
|
33
|
+
const response = await workspace.process.codeRun('console.log("Hello World!")')
|
|
63
34
|
console.log(response.result)
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
## Features
|
|
67
35
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
- **Language Server Protocol**: Interact with language servers for code intelligence
|
|
72
|
-
- **Process Management**: Execute code and commands in workspaces
|
|
36
|
+
// Clean up when done
|
|
37
|
+
await daytona.remove(workspace)
|
|
38
|
+
```
|
|
73
39
|
|
|
74
40
|
## Configuration
|
|
75
41
|
|
|
76
42
|
The SDK can be configured using environment variables or by passing a configuration object:
|
|
77
43
|
|
|
78
44
|
```typescript
|
|
79
|
-
import { Daytona
|
|
45
|
+
import { Daytona } from '@daytonaio/sdk'
|
|
80
46
|
|
|
81
|
-
|
|
47
|
+
// Initialize with configuration
|
|
48
|
+
const daytona = new Daytona({
|
|
82
49
|
apiKey: 'your-api-key',
|
|
83
|
-
serverUrl: '
|
|
84
|
-
target: '
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const daytona = new Daytona(config)
|
|
50
|
+
serverUrl: 'your-server-url',
|
|
51
|
+
target: 'us',
|
|
52
|
+
})
|
|
88
53
|
```
|
|
89
54
|
|
|
90
55
|
Or using environment variables:
|
|
@@ -93,26 +58,54 @@ Or using environment variables:
|
|
|
93
58
|
- `DAYTONA_SERVER_URL`: The Daytona server URL
|
|
94
59
|
- `DAYTONA_TARGET`: Your target environment
|
|
95
60
|
|
|
61
|
+
You can also customize workspace creation:
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
const workspace = await daytona.create({
|
|
65
|
+
language: 'typescript',
|
|
66
|
+
envVars: { NODE_ENV: 'development' },
|
|
67
|
+
autoStopInterval: 60, // Auto-stop after 1 hour of inactivity
|
|
68
|
+
})
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Features
|
|
72
|
+
|
|
73
|
+
- **Workspace Management**: Create, manage and remove workspaces
|
|
74
|
+
- **Git Operations**: Clone repositories, manage branches, and more
|
|
75
|
+
- **File System Operations**: Upload, download, search and manipulate files
|
|
76
|
+
- **Language Server Protocol**: Interact with language servers for code intelligence
|
|
77
|
+
- **Process Management**: Execute code and commands in workspaces
|
|
78
|
+
|
|
96
79
|
## Examples
|
|
97
80
|
|
|
98
|
-
### Execute
|
|
81
|
+
### Execute Commands
|
|
99
82
|
|
|
100
83
|
```typescript
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
)
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
84
|
+
// Execute a shell command
|
|
85
|
+
const response = await workspace.process.executeCommand('echo "Hello, World!"')
|
|
86
|
+
console.log(response.result)
|
|
87
|
+
|
|
88
|
+
// Run TypeScript code
|
|
89
|
+
const response = await workspace.process.codeRun(`
|
|
90
|
+
const x = 10
|
|
91
|
+
const y = 20
|
|
92
|
+
console.log(\`Sum: \${x + y}\`)
|
|
93
|
+
`)
|
|
94
|
+
console.log(response.result)
|
|
109
95
|
```
|
|
110
96
|
|
|
111
97
|
### File Operations
|
|
112
98
|
|
|
113
99
|
```typescript
|
|
114
100
|
// Upload a file
|
|
115
|
-
await workspace.fs.uploadFile(
|
|
101
|
+
await workspace.fs.uploadFile(
|
|
102
|
+
'/path/to/file.txt',
|
|
103
|
+
new File(
|
|
104
|
+
[Buffer.from('Hello, World!')],
|
|
105
|
+
'file.txt',
|
|
106
|
+
{ type: 'text/plain' }
|
|
107
|
+
)
|
|
108
|
+
)
|
|
116
109
|
|
|
117
110
|
// Download a file
|
|
118
111
|
const content = await workspace.fs.downloadFile('/path/to/file.txt')
|
package/dist/Daytona.d.ts
CHANGED
|
@@ -1,8 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sandboxes are isolated development environments managed by Daytona.
|
|
3
|
+
* This guide covers how to create, manage, and remove Sandboxes using the SDK.
|
|
4
|
+
*
|
|
5
|
+
* @module Daytona
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* // Initialize using environment variables (DAYTONA_API_KEY, DAYTONA_SERVER_URL, DAYTONA_TARGET)
|
|
9
|
+
* const daytona = new Daytona();
|
|
10
|
+
*
|
|
11
|
+
* // Create and use a workspace
|
|
12
|
+
* const workspace = await daytona.create({
|
|
13
|
+
* language: 'typescript',
|
|
14
|
+
* envVars: { NODE_ENV: 'development' }
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* // Execute commands in the workspace
|
|
18
|
+
* const response = await workspace.process.executeCommand('echo "Hello, World!"');
|
|
19
|
+
* console.log(response.result);
|
|
20
|
+
*
|
|
21
|
+
* // Execute code in the workspace
|
|
22
|
+
* const response = await workspace.process.codeRun('console.log("Hello, World!")');
|
|
23
|
+
* console.log(response.result);
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* // Initialize with explicit configuration
|
|
27
|
+
* const daytona = new Daytona({
|
|
28
|
+
* apiKey: process.env.CUSTOM_API_KEY,
|
|
29
|
+
* serverUrl: 'https://daytona.example.com',
|
|
30
|
+
* target: 'us'
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* // Create a custom workspace
|
|
34
|
+
* const workspace = await daytona.create({
|
|
35
|
+
* language: 'typescript',
|
|
36
|
+
* image: 'node:18',
|
|
37
|
+
* resources: {
|
|
38
|
+
* cpu: 2,
|
|
39
|
+
* memory: 4 // 4GB RAM
|
|
40
|
+
* },
|
|
41
|
+
* autoStopInterval: 60 // Auto-stop after 1 hour of inactivity
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* // Use workspace features
|
|
45
|
+
* await workspace.git.clone('https://github.com/user/repo.git');
|
|
46
|
+
* await workspace.process.executeCommand('npm test');
|
|
47
|
+
*/
|
|
1
48
|
import { Workspace } from './Workspace';
|
|
2
|
-
import { CreateWorkspaceTargetEnum } from '@daytonaio/api-client';
|
|
49
|
+
import { CreateWorkspaceTargetEnum as WorkspaceTargetRegion } from '@daytonaio/api-client';
|
|
3
50
|
/**
|
|
4
|
-
* Configuration options for initializing the Daytona client
|
|
5
|
-
*
|
|
51
|
+
* Configuration options for initializing the Daytona client.
|
|
52
|
+
*
|
|
53
|
+
* @interface
|
|
54
|
+
* @property {string} apiKey - API key for authentication with Daytona server
|
|
55
|
+
* @property {string} serverUrl - URL of the Daytona server
|
|
56
|
+
* @property {CreateWorkspaceTargetEnum} target - Target location for Sandboxes
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* const config: DaytonaConfig = {
|
|
60
|
+
* apiKey: "your-api-key",
|
|
61
|
+
* serverUrl: "https://your-server.com",
|
|
62
|
+
* target: "us"
|
|
63
|
+
* };
|
|
64
|
+
* const daytona = new Daytona(config);
|
|
6
65
|
*/
|
|
7
66
|
export interface DaytonaConfig {
|
|
8
67
|
/** API key for authentication with Daytona server */
|
|
@@ -10,59 +69,123 @@ export interface DaytonaConfig {
|
|
|
10
69
|
/** URL of the Daytona server */
|
|
11
70
|
serverUrl: string;
|
|
12
71
|
/** Target environment for workspaces */
|
|
13
|
-
target:
|
|
72
|
+
target: WorkspaceTargetRegion;
|
|
14
73
|
}
|
|
15
74
|
/**
|
|
16
75
|
* Supported programming languages for code execution
|
|
17
76
|
*/
|
|
18
|
-
export
|
|
77
|
+
export declare enum CodeLanguage {
|
|
78
|
+
PYTHON = "python",
|
|
79
|
+
TYPESCRIPT = "typescript",
|
|
80
|
+
JAVASCRIPT = "javascript"
|
|
81
|
+
}
|
|
19
82
|
/**
|
|
20
|
-
* Resource allocation for a
|
|
21
|
-
*
|
|
83
|
+
* Resource allocation for a Sandbox.
|
|
84
|
+
*
|
|
85
|
+
* @interface
|
|
86
|
+
* @property {number} [cpu] - CPU allocation for the Sandbox in cores
|
|
87
|
+
* @property {number} [gpu] - GPU allocation for the Sandbox in units
|
|
88
|
+
* @property {number} [memory] - Memory allocation for the Sandbox in GB
|
|
89
|
+
* @property {number} [disk] - Disk space allocation for the Sandbox in GB
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* const resources: WorkspaceResources = {
|
|
93
|
+
* cpu: 2,
|
|
94
|
+
* memory: 4, // 4GB RAM
|
|
95
|
+
* disk: 20 // 20GB disk
|
|
96
|
+
* };
|
|
22
97
|
*/
|
|
23
98
|
export interface WorkspaceResources {
|
|
24
|
-
/** CPU allocation for the
|
|
99
|
+
/** CPU allocation for the Sandbox */
|
|
25
100
|
cpu?: number;
|
|
26
|
-
/** GPU allocation for the
|
|
101
|
+
/** GPU allocation for the Sandbox */
|
|
27
102
|
gpu?: number;
|
|
28
|
-
/** Memory allocation for the
|
|
103
|
+
/** Memory allocation for the Sandbox in MB */
|
|
29
104
|
memory?: number;
|
|
30
|
-
/** Disk space allocation for the
|
|
105
|
+
/** Disk space allocation for the Sandbox in MB */
|
|
31
106
|
disk?: number;
|
|
32
107
|
}
|
|
33
108
|
/**
|
|
34
|
-
* Parameters for creating a new
|
|
35
|
-
*
|
|
109
|
+
* Parameters for creating a new Sandbox.
|
|
110
|
+
*
|
|
111
|
+
* @interface
|
|
112
|
+
* @property {string} [id] - Optional Sandbox ID. If not provided, a random ID will be generated
|
|
113
|
+
* @property {string} [image] - Optional Docker image to use for the Sandbox
|
|
114
|
+
* @property {string} [user] - Optional os user to use for the Sandbox
|
|
115
|
+
* @property {CodeLanguage} [language] - Programming language for direct code execution
|
|
116
|
+
* @property {Record<string, string>} [envVars] - Optional environment variables to set in the Sandbox
|
|
117
|
+
* @property {Record<string, string>} [labels] - Sandbox labels
|
|
118
|
+
* @property {boolean} [public] - Is the Sandbox port preview public
|
|
119
|
+
* @property {string} [target] - Target location for the Sandbox
|
|
120
|
+
* @property {WorkspaceResources} [resources] - Resource allocation for the Sandbox
|
|
121
|
+
* @property {boolean} [async] - If true, will not wait for the Sandbox to be ready before returning
|
|
122
|
+
* @property {number} [timeout] - Timeout in seconds for the Sandbox to be ready (0 means no timeout)
|
|
123
|
+
* @property {number} [autoStopInterval] - Auto-stop interval in minutes (0 means disabled)
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* const params: CreateWorkspaceParams = {
|
|
127
|
+
* language: 'typescript',
|
|
128
|
+
* envVars: { NODE_ENV: 'development' },
|
|
129
|
+
* resources: {
|
|
130
|
+
* cpu: 2,
|
|
131
|
+
* memory: 4 // 4GB RAM
|
|
132
|
+
* },
|
|
133
|
+
* autoStopInterval: 60 // Auto-stop after 1 hour of inactivity
|
|
134
|
+
* };
|
|
135
|
+
* const workspace = await daytona.create(params, 50);
|
|
36
136
|
*/
|
|
37
137
|
export type CreateWorkspaceParams = {
|
|
38
|
-
/** Optional
|
|
138
|
+
/** Optional Sandbox ID. If not provided, a random ID will be generated */
|
|
39
139
|
id?: string;
|
|
40
|
-
/** Optional Docker image to use for the
|
|
140
|
+
/** Optional Docker image to use for the Sandbox */
|
|
41
141
|
image?: string;
|
|
42
|
-
/** Optional os user to use for the
|
|
142
|
+
/** Optional os user to use for the Sandbox */
|
|
43
143
|
user?: string;
|
|
44
144
|
/** Programming language for direct code execution */
|
|
45
|
-
language?: CodeLanguage;
|
|
145
|
+
language?: CodeLanguage | string;
|
|
46
146
|
/** Optional environment variables to set in the workspace */
|
|
47
147
|
envVars?: Record<string, string>;
|
|
48
|
-
/**
|
|
148
|
+
/** Sandbox labels */
|
|
49
149
|
labels?: Record<string, string>;
|
|
50
|
-
/** Is the
|
|
150
|
+
/** Is the Sandbox port preview public */
|
|
51
151
|
public?: boolean;
|
|
52
|
-
/** Target location for the
|
|
53
|
-
target?: string;
|
|
54
|
-
/** Resource allocation for the
|
|
152
|
+
/** Target location for the Sandbox */
|
|
153
|
+
target?: WorkspaceTargetRegion | string;
|
|
154
|
+
/** Resource allocation for the Sandbox */
|
|
55
155
|
resources?: WorkspaceResources;
|
|
56
|
-
/** If true, will not wait for the
|
|
156
|
+
/** If true, will not wait for the Sandbox to be ready before returning */
|
|
57
157
|
async?: boolean;
|
|
58
|
-
/**
|
|
158
|
+
/**
|
|
159
|
+
* Timeout in seconds, for the Sandbox to be ready (0 means no timeout)
|
|
160
|
+
* @deprecated Use methods with `timeout` parameter instead
|
|
161
|
+
*/
|
|
59
162
|
timeout?: number;
|
|
60
163
|
/** Auto-stop interval in minutes (0 means disabled) (must be a non-negative integer) */
|
|
61
164
|
autoStopInterval?: number;
|
|
62
165
|
};
|
|
63
166
|
/**
|
|
64
|
-
* Main class for interacting with Daytona Server API
|
|
65
|
-
*
|
|
167
|
+
* Main class for interacting with Daytona Server API.
|
|
168
|
+
*
|
|
169
|
+
* Provides methods for creating, managing, and interacting with Daytona Sandboxes.
|
|
170
|
+
* Can be initialized either with explicit configuration or using environment variables.
|
|
171
|
+
*
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* // Using environment variables
|
|
175
|
+
* // Uses DAYTONA_API_KEY, DAYTONA_SERVER_URL, DAYTONA_TARGET
|
|
176
|
+
* const daytona = new Daytona();
|
|
177
|
+
* const workspace = await daytona.create();
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* // Using explicit configuration
|
|
181
|
+
* const config: DaytonaConfig = {
|
|
182
|
+
* apiKey: "your-api-key",
|
|
183
|
+
* serverUrl: "https://your-server.com",
|
|
184
|
+
* target: "us"
|
|
185
|
+
* };
|
|
186
|
+
* const daytona = new Daytona(config);
|
|
187
|
+
*
|
|
188
|
+
* @class
|
|
66
189
|
*/
|
|
67
190
|
export declare class Daytona {
|
|
68
191
|
private readonly workspaceApi;
|
|
@@ -71,50 +194,119 @@ export declare class Daytona {
|
|
|
71
194
|
private readonly apiKey;
|
|
72
195
|
private readonly serverUrl;
|
|
73
196
|
/**
|
|
74
|
-
* Creates a new Daytona client instance
|
|
197
|
+
* Creates a new Daytona client instance.
|
|
198
|
+
*
|
|
75
199
|
* @param {DaytonaConfig} [config] - Configuration options
|
|
76
|
-
* @throws {
|
|
200
|
+
* @throws {DaytonaError} - `DaytonaError` - When API key or server URL is missing
|
|
77
201
|
*/
|
|
78
202
|
constructor(config?: DaytonaConfig);
|
|
79
203
|
/**
|
|
80
|
-
* Creates
|
|
81
|
-
*
|
|
82
|
-
*
|
|
204
|
+
* Creates Sandboxes with default or custom configurations. You can specify various parameters,
|
|
205
|
+
* including language, image, resources, environment variables, and volumes for the Sandbox.
|
|
206
|
+
*
|
|
207
|
+
* @param {CreateWorkspaceParams} [params] - Parameters for Sandbox creation
|
|
208
|
+
* @param {number} [timeout] - Timeout in seconds (0 means no timeout, default is 60)
|
|
209
|
+
* @returns {Promise<Workspace>} The created Sandbox instance
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* // Create a default workspace
|
|
213
|
+
* const workspace = await daytona.create();
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* // Create a custom workspace
|
|
217
|
+
* const params: CreateWorkspaceParams = {
|
|
218
|
+
* language: 'typescript',
|
|
219
|
+
* image: 'node:18',
|
|
220
|
+
* envVars: {
|
|
221
|
+
* NODE_ENV: 'development',
|
|
222
|
+
* DEBUG: 'true'
|
|
223
|
+
* },
|
|
224
|
+
* resources: {
|
|
225
|
+
* cpu: 2,
|
|
226
|
+
* memory: 4 // 4GB RAM
|
|
227
|
+
* },
|
|
228
|
+
* autoStopInterval: 60
|
|
229
|
+
* };
|
|
230
|
+
* const workspace = await daytona.create(params, 40);
|
|
83
231
|
*/
|
|
84
|
-
create(params?: CreateWorkspaceParams): Promise<Workspace>;
|
|
232
|
+
create(params?: CreateWorkspaceParams, timeout?: number): Promise<Workspace>;
|
|
85
233
|
/**
|
|
86
|
-
* Gets a
|
|
87
|
-
*
|
|
88
|
-
* @
|
|
234
|
+
* Gets a Sandbox by its ID.
|
|
235
|
+
*
|
|
236
|
+
* @param {string} workspaceId - The ID of the Sandbox to retrieve
|
|
237
|
+
* @returns {Promise<Workspace>} The Sandbox
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* const workspace = await daytona.get('my-workspace-id');
|
|
241
|
+
* console.log(`Workspace state: ${workspace.instance.state}`);
|
|
89
242
|
*/
|
|
90
243
|
get(workspaceId: string): Promise<Workspace>;
|
|
91
244
|
/**
|
|
92
|
-
* Lists all
|
|
93
|
-
*
|
|
245
|
+
* Lists all Sandboxes.
|
|
246
|
+
*
|
|
247
|
+
* @returns {Promise<Workspace[]>} Array of Sandboxes
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* const workspaces = await daytona.list();
|
|
251
|
+
* for (const workspace of workspaces) {
|
|
252
|
+
* console.log(`${workspace.id}: ${workspace.instance.state}`);
|
|
253
|
+
* }
|
|
94
254
|
*/
|
|
95
255
|
list(): Promise<Workspace[]>;
|
|
96
256
|
/**
|
|
97
|
-
* Starts a
|
|
98
|
-
*
|
|
257
|
+
* Starts a Sandbox and waits for it to be ready.
|
|
258
|
+
*
|
|
259
|
+
* @param {Workspace} workspace - The Sandbox to start
|
|
260
|
+
* @param {number} [timeout] - Optional timeout in seconds (0 means no timeout)
|
|
261
|
+
* @returns {Promise<void>}
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* const workspace = await daytona.get('my-workspace-id');
|
|
265
|
+
* // Wait up to 60 seconds for the workspace to start
|
|
266
|
+
* await daytona.start(workspace, 60);
|
|
99
267
|
*/
|
|
100
268
|
start(workspace: Workspace, timeout?: number): Promise<void>;
|
|
101
269
|
/**
|
|
102
|
-
* Stops a
|
|
103
|
-
*
|
|
270
|
+
* Stops a Sandbox.
|
|
271
|
+
*
|
|
272
|
+
* @param {Workspace} workspace - The Sandbox to stop
|
|
104
273
|
* @returns {Promise<void>}
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* const workspace = await daytona.get('my-workspace-id');
|
|
277
|
+
* await daytona.stop(workspace);
|
|
105
278
|
*/
|
|
106
279
|
stop(workspace: Workspace): Promise<void>;
|
|
107
280
|
/**
|
|
108
|
-
* Removes a
|
|
109
|
-
*
|
|
281
|
+
* Removes a Sandbox.
|
|
282
|
+
*
|
|
283
|
+
* @param {Workspace} workspace - The Sandbox to remove
|
|
284
|
+
* @param {number} timeout - Timeout in seconds (0 means no timeout, default is 60)
|
|
110
285
|
* @returns {Promise<void>}
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
* const workspace = await daytona.get('my-workspace-id');
|
|
289
|
+
* await daytona.remove(workspace);
|
|
111
290
|
*/
|
|
112
|
-
remove(workspace: Workspace): Promise<void>;
|
|
291
|
+
remove(workspace: Workspace, timeout?: number): Promise<void>;
|
|
113
292
|
/**
|
|
114
|
-
* Gets the
|
|
115
|
-
*
|
|
116
|
-
* @
|
|
293
|
+
* Gets the Sandbox by ID.
|
|
294
|
+
*
|
|
295
|
+
* @param {string} workspaceId - The ID of the Sandbox to retrieve
|
|
296
|
+
* @returns {Promise<Workspace>} The Sandbox
|
|
297
|
+
*
|
|
298
|
+
* @example
|
|
299
|
+
* const workspace = await daytona.getCurrentWorkspace('my-workspace-id');
|
|
300
|
+
* console.log(`Current workspace state: ${workspace.instance.state}`);
|
|
117
301
|
*/
|
|
118
302
|
getCurrentWorkspace(workspaceId: string): Promise<Workspace>;
|
|
303
|
+
/**
|
|
304
|
+
* Gets the appropriate code toolbox based on language.
|
|
305
|
+
*
|
|
306
|
+
* @private
|
|
307
|
+
* @param {CodeLanguage} [language] - Programming language for the toolbox
|
|
308
|
+
* @returns {WorkspaceCodeToolbox} The appropriate code toolbox instance
|
|
309
|
+
* @throws {DaytonaError} - `DaytonaError` - When an unsupported language is specified
|
|
310
|
+
*/
|
|
119
311
|
private getCodeToolbox;
|
|
120
312
|
}
|