@daytonaio/sdk 0.11.2 → 0.12.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.
- package/README.md +3 -3
- package/dist/Daytona.d.ts +18 -59
- package/dist/Daytona.js +14 -54
- package/dist/FileSystem.d.ts +2 -68
- package/dist/FileSystem.js +1 -67
- package/dist/Git.d.ts +15 -61
- package/dist/Git.js +10 -62
- package/dist/LspServer.d.ts +13 -75
- package/dist/LspServer.js +11 -71
- package/dist/Process.d.ts +51 -39
- package/dist/Process.js +60 -41
- package/dist/Sandbox.d.ts +5 -47
- package/dist/Sandbox.js +2 -44
- package/dist/code-toolbox/SandboxPythonCodeToolbox.d.ts +6 -0
- package/dist/code-toolbox/SandboxPythonCodeToolbox.js +344 -2
- package/dist/index.d.ts +9 -8
- package/dist/index.js +7 -5
- package/dist/types/Charts.d.ts +151 -0
- package/dist/types/Charts.js +40 -0
- package/dist/types/ExecuteResponse.d.ts +26 -0
- package/dist/types/ExecuteResponse.js +2 -0
- package/dist/utils/ArtifactParser.d.ts +13 -0
- package/dist/utils/ArtifactParser.js +50 -0
- package/package.json +1 -4
package/dist/Process.js
CHANGED
|
@@ -1,47 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* The Daytona SDK provides powerful process and code execution capabilities through
|
|
4
|
-
* the `process` module in Sandboxes. This guide covers all available process operations
|
|
5
|
-
* and best practices.
|
|
6
|
-
*
|
|
7
|
-
* @module Process
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* // Execute a shell command
|
|
11
|
-
* const response = await sandbox.process.executeCommand('ls -la');
|
|
12
|
-
* console.log(response.result);
|
|
13
|
-
*
|
|
14
|
-
* // Run TypeScript code
|
|
15
|
-
* const response = await sandbox.process.codeRun('console.log("Hello, World!")');
|
|
16
|
-
* console.log(response.result);
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* // Using interactive sessions
|
|
20
|
-
* // Create a new session
|
|
21
|
-
* const sessionId = 'my-session';
|
|
22
|
-
* await sandbox.process.createSession(sessionId);
|
|
23
|
-
*
|
|
24
|
-
* // Execute commands in the session
|
|
25
|
-
* const response = await sandbox.process.executeSessionCommand(sessionId, {
|
|
26
|
-
* command: 'cd /workspace'
|
|
27
|
-
* });
|
|
28
|
-
*
|
|
29
|
-
* const response2 = await sandbox.process.executeSessionCommand(sessionId, {
|
|
30
|
-
* command: 'pwd'
|
|
31
|
-
* });
|
|
32
|
-
* console.log(response2.result); // Should print "/workspace"
|
|
33
|
-
*
|
|
34
|
-
* // Clean up
|
|
35
|
-
* await sandbox.process.deleteSession(sessionId);
|
|
36
|
-
*/
|
|
37
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
3
|
exports.Process = exports.CodeRunParams = void 0;
|
|
4
|
+
const ArtifactParser_1 = require("./utils/ArtifactParser");
|
|
39
5
|
/**
|
|
40
|
-
* Parameters for code execution
|
|
6
|
+
* Parameters for code execution.
|
|
41
7
|
*/
|
|
42
8
|
class CodeRunParams {
|
|
43
9
|
}
|
|
44
10
|
exports.CodeRunParams = CodeRunParams;
|
|
11
|
+
/**
|
|
12
|
+
* Handles process and code execution within a Sandbox.
|
|
13
|
+
*
|
|
14
|
+
* @class
|
|
15
|
+
*/
|
|
45
16
|
class Process {
|
|
46
17
|
constructor(codeToolbox, toolboxApi, instance) {
|
|
47
18
|
this.codeToolbox = codeToolbox;
|
|
@@ -57,11 +28,12 @@ class Process {
|
|
|
57
28
|
* @returns {Promise<ExecuteResponse>} Command execution results containing:
|
|
58
29
|
* - exitCode: The command's exit status
|
|
59
30
|
* - result: Standard output from the command
|
|
31
|
+
* - artifacts: ExecutionArtifacts object containing `stdout` (same as result) and `charts` (matplotlib charts metadata)
|
|
60
32
|
*
|
|
61
33
|
* @example
|
|
62
34
|
* // Simple command
|
|
63
35
|
* const response = await process.executeCommand('echo "Hello"');
|
|
64
|
-
* console.log(response.
|
|
36
|
+
* console.log(response.artifacts.stdout); // Prints: Hello
|
|
65
37
|
*
|
|
66
38
|
* @example
|
|
67
39
|
* // Command with working directory
|
|
@@ -77,16 +49,26 @@ class Process {
|
|
|
77
49
|
timeout,
|
|
78
50
|
cwd,
|
|
79
51
|
});
|
|
80
|
-
|
|
52
|
+
// console.log(response)
|
|
53
|
+
// Parse artifacts from the output
|
|
54
|
+
const artifacts = ArtifactParser_1.ArtifactParser.parseArtifacts(response.data.result);
|
|
55
|
+
// Return enhanced response with parsed artifacts
|
|
56
|
+
return {
|
|
57
|
+
...response.data,
|
|
58
|
+
result: artifacts.stdout,
|
|
59
|
+
artifacts,
|
|
60
|
+
};
|
|
81
61
|
}
|
|
82
62
|
/**
|
|
83
63
|
* Executes code in the Sandbox using the appropriate language runtime.
|
|
84
64
|
*
|
|
85
65
|
* @param {string} code - Code to execute
|
|
86
66
|
* @param {CodeRunParams} params - Parameters for code execution
|
|
67
|
+
* @param {number} [timeout] - Maximum time in seconds to wait for execution to complete
|
|
87
68
|
* @returns {Promise<ExecuteResponse>} Code execution results containing:
|
|
88
69
|
* - exitCode: The execution's exit status
|
|
89
70
|
* - result: Standard output from the code
|
|
71
|
+
* - artifacts: ExecutionArtifacts object containing `stdout` (same as result) and `charts` (matplotlib charts metadata)
|
|
90
72
|
*
|
|
91
73
|
* @example
|
|
92
74
|
* // Run TypeScript code
|
|
@@ -95,12 +77,49 @@ class Process {
|
|
|
95
77
|
* const y = 20;
|
|
96
78
|
* console.log(\`Sum: \${x + y}\`);
|
|
97
79
|
* `);
|
|
98
|
-
* console.log(response.
|
|
80
|
+
* console.log(response.artifacts.stdout); // Prints: Sum: 30
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* // Run Python code with matplotlib
|
|
84
|
+
* const response = await process.codeRun(`
|
|
85
|
+
* import matplotlib.pyplot as plt
|
|
86
|
+
* import numpy as np
|
|
87
|
+
*
|
|
88
|
+
* x = np.linspace(0, 10, 30)
|
|
89
|
+
* y = np.sin(x)
|
|
90
|
+
*
|
|
91
|
+
* plt.figure(figsize=(8, 5))
|
|
92
|
+
* plt.plot(x, y, 'b-', linewidth=2)
|
|
93
|
+
* plt.title('Line Chart')
|
|
94
|
+
* plt.xlabel('X-axis (seconds)')
|
|
95
|
+
* plt.ylabel('Y-axis (amplitude)')
|
|
96
|
+
* plt.grid(True)
|
|
97
|
+
* plt.show()
|
|
98
|
+
* `);
|
|
99
|
+
*
|
|
100
|
+
* if (response.artifacts?.charts) {
|
|
101
|
+
* const chart = response.artifacts.charts[0];
|
|
102
|
+
*
|
|
103
|
+
* console.log(`Type: ${chart.type}`);
|
|
104
|
+
* console.log(`Title: ${chart.title}`);
|
|
105
|
+
* if (chart.type === ChartType.LINE) {
|
|
106
|
+
* const lineChart = chart as LineChart
|
|
107
|
+
* console.log('X Label:', lineChart.x_label)
|
|
108
|
+
* console.log('Y Label:', lineChart.y_label)
|
|
109
|
+
* console.log('X Ticks:', lineChart.x_ticks)
|
|
110
|
+
* console.log('Y Ticks:', lineChart.y_ticks)
|
|
111
|
+
* console.log('X Tick Labels:', lineChart.x_tick_labels)
|
|
112
|
+
* console.log('Y Tick Labels:', lineChart.y_tick_labels)
|
|
113
|
+
* console.log('X Scale:', lineChart.x_scale)
|
|
114
|
+
* console.log('Y Scale:', lineChart.y_scale)
|
|
115
|
+
* console.log('Elements:')
|
|
116
|
+
* console.dir(lineChart.elements, { depth: null })
|
|
117
|
+
* }
|
|
118
|
+
* }
|
|
99
119
|
*/
|
|
100
120
|
async codeRun(code, params, timeout) {
|
|
101
121
|
const runCommand = this.codeToolbox.getRunCommand(code, params);
|
|
102
|
-
|
|
103
|
-
return response;
|
|
122
|
+
return this.executeCommand(runCommand, undefined, timeout);
|
|
104
123
|
}
|
|
105
124
|
/**
|
|
106
125
|
* Creates a new long-running background session in the Sandbox.
|
package/dist/Sandbox.d.ts
CHANGED
|
@@ -1,43 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The Daytona SDK core Sandbox functionality.
|
|
3
|
-
*
|
|
4
|
-
* Provides the main Sandbox class representing a Daytona Sandbox that coordinates file system,
|
|
5
|
-
* Git, process execution, and LSP functionality. It serves as the central point
|
|
6
|
-
* for interacting with Daytona Sandboxes.
|
|
7
|
-
*
|
|
8
|
-
* The Sandbox must be in a 'started' state before performing operations.
|
|
9
|
-
*
|
|
10
|
-
* @module Sandbox
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* // Create and initialize sandbox
|
|
14
|
-
* const daytona = new Daytona();
|
|
15
|
-
* const sandbox = await daytona.create();
|
|
16
|
-
*
|
|
17
|
-
* // File operations
|
|
18
|
-
* await sandbox.fs.uploadFile(
|
|
19
|
-
* '/app/config.json',
|
|
20
|
-
* new File(['{"setting": "value"}'], 'config.json')
|
|
21
|
-
* );
|
|
22
|
-
* const contentBlob = await sandbox.fs.downloadFile('/app/config.json');
|
|
23
|
-
*
|
|
24
|
-
* // Git operations
|
|
25
|
-
* await sandbox.git.clone('https://github.com/user/repo.git');
|
|
26
|
-
*
|
|
27
|
-
* // Process execution
|
|
28
|
-
* const response = await sandbox.process.executeCommand('ls -la');
|
|
29
|
-
* console.log(response.result);
|
|
30
|
-
*
|
|
31
|
-
* // LSP functionality
|
|
32
|
-
* const lsp = sandbox.createLspServer('typescript', '/workspace/project');
|
|
33
|
-
* await lsp.didOpen('/workspace/project/src/index.ts');
|
|
34
|
-
* const completions = await lsp.completions('/workspace/project/src/index.ts', {
|
|
35
|
-
* line: 10,
|
|
36
|
-
* character: 15
|
|
37
|
-
* });
|
|
38
|
-
* console.log(completions);
|
|
39
|
-
*
|
|
40
|
-
*/
|
|
41
1
|
import { ToolboxApi, WorkspaceState as SandboxState, WorkspaceApi as SandboxApi, Workspace as ApiSandbox, WorkspaceInfo as ApiSandboxInfo, CreateNodeClassEnum as SandboxClass, CreateNodeRegionEnum as SandboxTargetRegion, Workspace as ApiWorkspace } from '@daytonaio/api-client';
|
|
42
2
|
import { FileSystem } from './FileSystem';
|
|
43
3
|
import { Git } from './Git';
|
|
@@ -51,7 +11,7 @@ export interface SandboxInstance extends Omit<ApiSandbox, 'info'> {
|
|
|
51
11
|
/**
|
|
52
12
|
* Resources allocated to a Sandbox
|
|
53
13
|
*
|
|
54
|
-
* @interface
|
|
14
|
+
* @interface
|
|
55
15
|
* @property {string} cpu - Number of CPU cores allocated (e.g., "1", "2")
|
|
56
16
|
* @property {string | null} gpu - Number of GPUs allocated (e.g., "1") or null if no GPU
|
|
57
17
|
* @property {string} memory - Amount of memory allocated with unit (e.g., "2Gi", "4Gi")
|
|
@@ -81,7 +41,7 @@ export interface SandboxResources {
|
|
|
81
41
|
* This interface provides detailed information about a Sandbox's configuration,
|
|
82
42
|
* resources, and current state.
|
|
83
43
|
*
|
|
84
|
-
* @interface
|
|
44
|
+
* @interface
|
|
85
45
|
* @property {string} id - Unique identifier for the Sandbox
|
|
86
46
|
* @property {string} name - Display name of the Sandbox
|
|
87
47
|
* @property {string} image - Docker image used for the Sandbox
|
|
@@ -148,7 +108,7 @@ export interface SandboxInfo extends ApiSandboxInfo {
|
|
|
148
108
|
}
|
|
149
109
|
/**
|
|
150
110
|
* Interface defining methods that a code toolbox must implement
|
|
151
|
-
* @interface
|
|
111
|
+
* @interface
|
|
152
112
|
*/
|
|
153
113
|
export interface SandboxCodeToolbox {
|
|
154
114
|
/** Generates a command to run the provided code */
|
|
@@ -157,10 +117,6 @@ export interface SandboxCodeToolbox {
|
|
|
157
117
|
/**
|
|
158
118
|
* Represents a Daytona Sandbox.
|
|
159
119
|
*
|
|
160
|
-
* A Sandbox provides file system operations, Git operations, process execution,
|
|
161
|
-
* and LSP functionality. It serves as the main interface for interacting with
|
|
162
|
-
* a Daytona sandbox.
|
|
163
|
-
*
|
|
164
120
|
* @property {string} id - Unique identifier for the Sandbox
|
|
165
121
|
* @property {SandboxInstance} instance - The underlying Sandbox instance
|
|
166
122
|
* @property {SandboxApi} sandboxApi - API client for Sandbox operations
|
|
@@ -169,6 +125,8 @@ export interface SandboxCodeToolbox {
|
|
|
169
125
|
* @property {FileSystem} fs - File system operations interface
|
|
170
126
|
* @property {Git} git - Git operations interface
|
|
171
127
|
* @property {Process} process - Process execution interface
|
|
128
|
+
*
|
|
129
|
+
* @class
|
|
172
130
|
*/
|
|
173
131
|
export declare class Sandbox {
|
|
174
132
|
readonly id: string;
|
package/dist/Sandbox.js
CHANGED
|
@@ -1,44 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* The Daytona SDK core Sandbox functionality.
|
|
4
|
-
*
|
|
5
|
-
* Provides the main Sandbox 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 Sandbox
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* // Create and initialize sandbox
|
|
15
|
-
* const daytona = new Daytona();
|
|
16
|
-
* const sandbox = await daytona.create();
|
|
17
|
-
*
|
|
18
|
-
* // File operations
|
|
19
|
-
* await sandbox.fs.uploadFile(
|
|
20
|
-
* '/app/config.json',
|
|
21
|
-
* new File(['{"setting": "value"}'], 'config.json')
|
|
22
|
-
* );
|
|
23
|
-
* const contentBlob = await sandbox.fs.downloadFile('/app/config.json');
|
|
24
|
-
*
|
|
25
|
-
* // Git operations
|
|
26
|
-
* await sandbox.git.clone('https://github.com/user/repo.git');
|
|
27
|
-
*
|
|
28
|
-
* // Process execution
|
|
29
|
-
* const response = await sandbox.process.executeCommand('ls -la');
|
|
30
|
-
* console.log(response.result);
|
|
31
|
-
*
|
|
32
|
-
* // LSP functionality
|
|
33
|
-
* const lsp = sandbox.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
|
-
*/
|
|
42
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
3
|
exports.Sandbox = void 0;
|
|
44
4
|
const FileSystem_1 = require("./FileSystem");
|
|
@@ -49,10 +9,6 @@ const DaytonaError_1 = require("./errors/DaytonaError");
|
|
|
49
9
|
/**
|
|
50
10
|
* Represents a Daytona Sandbox.
|
|
51
11
|
*
|
|
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 sandbox.
|
|
55
|
-
*
|
|
56
12
|
* @property {string} id - Unique identifier for the Sandbox
|
|
57
13
|
* @property {SandboxInstance} instance - The underlying Sandbox instance
|
|
58
14
|
* @property {SandboxApi} sandboxApi - API client for Sandbox operations
|
|
@@ -61,6 +17,8 @@ const DaytonaError_1 = require("./errors/DaytonaError");
|
|
|
61
17
|
* @property {FileSystem} fs - File system operations interface
|
|
62
18
|
* @property {Git} git - Git operations interface
|
|
63
19
|
* @property {Process} process - Process execution interface
|
|
20
|
+
*
|
|
21
|
+
* @class
|
|
64
22
|
*/
|
|
65
23
|
class Sandbox {
|
|
66
24
|
/**
|
|
@@ -3,4 +3,10 @@ import { CodeRunParams } from '../Process';
|
|
|
3
3
|
export declare class SandboxPythonCodeToolbox implements SandboxCodeToolbox {
|
|
4
4
|
getDefaultImage(): string;
|
|
5
5
|
getRunCommand(code: string, params?: CodeRunParams): string;
|
|
6
|
+
/**
|
|
7
|
+
* Checks if matplotlib is imported in the given Python code string.
|
|
8
|
+
* @param codeString Python code as a string
|
|
9
|
+
* @returns True if matplotlib is imported, false otherwise
|
|
10
|
+
*/
|
|
11
|
+
private static isMatplotlibImported;
|
|
6
12
|
}
|