@daytonaio/sdk 0.127.0 → 0.128.0-alpha.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/LICENSE +190 -0
- package/{src → cjs}/CodeInterpreter.d.ts +1 -0
- package/cjs/CodeInterpreter.d.ts.map +1 -0
- package/cjs/CodeInterpreter.js.map +1 -0
- package/{src → cjs}/ComputerUse.d.ts +1 -0
- package/cjs/ComputerUse.d.ts.map +1 -0
- package/cjs/ComputerUse.js.map +1 -0
- package/{src → cjs}/Daytona.d.ts +1 -0
- package/cjs/Daytona.d.ts.map +1 -0
- package/{src → cjs}/Daytona.js +1 -0
- package/cjs/Daytona.js.map +1 -0
- package/{src → cjs}/FileSystem.d.ts +1 -0
- package/cjs/FileSystem.d.ts.map +1 -0
- package/cjs/FileSystem.js.map +1 -0
- package/{src → cjs}/Git.d.ts +1 -0
- package/cjs/Git.d.ts.map +1 -0
- package/cjs/Git.js.map +1 -0
- package/{src → cjs}/Image.d.ts +21 -0
- package/cjs/Image.d.ts.map +1 -0
- package/{src → cjs}/Image.js +123 -91
- package/cjs/Image.js.map +1 -0
- package/{src → cjs}/LspServer.d.ts +1 -0
- package/cjs/LspServer.d.ts.map +1 -0
- package/cjs/LspServer.js.map +1 -0
- package/{src → cjs}/ObjectStorage.d.ts +1 -0
- package/cjs/ObjectStorage.d.ts.map +1 -0
- package/cjs/ObjectStorage.js.map +1 -0
- package/{src → cjs}/Process.d.ts +1 -0
- package/cjs/Process.d.ts.map +1 -0
- package/cjs/Process.js.map +1 -0
- package/{src → cjs}/PtyHandle.d.ts +1 -0
- package/cjs/PtyHandle.d.ts.map +1 -0
- package/cjs/PtyHandle.js.map +1 -0
- package/cjs/README.md +147 -0
- package/{src → cjs}/Sandbox.d.ts +2 -17
- package/cjs/Sandbox.d.ts.map +1 -0
- package/{src → cjs}/Sandbox.js +1 -27
- package/cjs/Sandbox.js.map +1 -0
- package/{src → cjs}/Snapshot.d.ts +2 -0
- package/cjs/Snapshot.d.ts.map +1 -0
- package/{src → cjs}/Snapshot.js +9 -1
- package/cjs/Snapshot.js.map +1 -0
- package/{src → cjs}/Volume.d.ts +1 -0
- package/cjs/Volume.d.ts.map +1 -0
- package/cjs/Volume.js.map +1 -0
- package/{src → cjs}/code-toolbox/SandboxJsCodeToolbox.d.ts +1 -0
- package/cjs/code-toolbox/SandboxJsCodeToolbox.d.ts.map +1 -0
- package/cjs/code-toolbox/SandboxJsCodeToolbox.js.map +1 -0
- package/{src → cjs}/code-toolbox/SandboxPythonCodeToolbox.d.ts +1 -0
- package/cjs/code-toolbox/SandboxPythonCodeToolbox.d.ts.map +1 -0
- package/cjs/code-toolbox/SandboxPythonCodeToolbox.js.map +1 -0
- package/{src → cjs}/code-toolbox/SandboxTsCodeToolbox.d.ts +1 -0
- package/cjs/code-toolbox/SandboxTsCodeToolbox.d.ts.map +1 -0
- package/cjs/code-toolbox/SandboxTsCodeToolbox.js.map +1 -0
- package/{src → cjs}/errors/DaytonaError.d.ts +1 -0
- package/cjs/errors/DaytonaError.d.ts.map +1 -0
- package/cjs/errors/DaytonaError.js.map +1 -0
- package/{src → cjs}/index.d.ts +1 -0
- package/cjs/index.d.ts.map +1 -0
- package/cjs/index.js.map +1 -0
- package/cjs/package.json +3 -0
- package/{src → cjs}/types/Charts.d.ts +1 -0
- package/cjs/types/Charts.d.ts.map +1 -0
- package/cjs/types/Charts.js.map +1 -0
- package/{src → cjs}/types/CodeInterpreter.d.ts +1 -0
- package/cjs/types/CodeInterpreter.d.ts.map +1 -0
- package/cjs/types/CodeInterpreter.js.map +1 -0
- package/{src → cjs}/types/ExecuteResponse.d.ts +1 -0
- package/cjs/types/ExecuteResponse.d.ts.map +1 -0
- package/cjs/types/ExecuteResponse.js.map +1 -0
- package/{src → cjs}/types/Pty.d.ts +1 -0
- package/cjs/types/Pty.d.ts.map +1 -0
- package/cjs/types/Pty.js.map +1 -0
- package/{src → cjs}/utils/ArtifactParser.d.ts +1 -0
- package/cjs/utils/ArtifactParser.d.ts.map +1 -0
- package/cjs/utils/ArtifactParser.js.map +1 -0
- package/{src → cjs}/utils/Binary.d.ts +1 -0
- package/cjs/utils/Binary.d.ts.map +1 -0
- package/cjs/utils/Binary.js.map +1 -0
- package/{src → cjs}/utils/FileTransfer.d.ts +1 -0
- package/cjs/utils/FileTransfer.d.ts.map +1 -0
- package/cjs/utils/FileTransfer.js.map +1 -0
- package/{src → cjs}/utils/Import.d.ts +2 -15
- package/cjs/utils/Import.d.ts.map +1 -0
- package/cjs/utils/Import.js +81 -0
- package/cjs/utils/Import.js.map +1 -0
- package/{src → cjs}/utils/Multipart.d.ts +1 -0
- package/cjs/utils/Multipart.d.ts.map +1 -0
- package/cjs/utils/Multipart.js.map +1 -0
- package/{src → cjs}/utils/Runtime.d.ts +1 -0
- package/cjs/utils/Runtime.d.ts.map +1 -0
- package/cjs/utils/Runtime.js.map +1 -0
- package/{src → cjs}/utils/Stream.d.ts +1 -0
- package/cjs/utils/Stream.d.ts.map +1 -0
- package/cjs/utils/Stream.js.map +1 -0
- package/{src → cjs}/utils/WebSocket.d.ts +1 -0
- package/cjs/utils/WebSocket.d.ts.map +1 -0
- package/cjs/utils/WebSocket.js.map +1 -0
- package/esm/CodeInterpreter.d.ts +96 -0
- package/esm/CodeInterpreter.d.ts.map +1 -0
- package/esm/CodeInterpreter.js +295 -0
- package/esm/CodeInterpreter.js.map +1 -0
- package/esm/ComputerUse.d.ts +443 -0
- package/esm/ComputerUse.d.ts.map +1 -0
- package/esm/ComputerUse.js +509 -0
- package/esm/ComputerUse.js.map +1 -0
- package/esm/Daytona.d.ts +354 -0
- package/esm/Daytona.d.ts.map +1 -0
- package/esm/Daytona.js +410 -0
- package/esm/Daytona.js.map +1 -0
- package/esm/FileSystem.d.ts +328 -0
- package/esm/FileSystem.d.ts.map +1 -0
- package/esm/FileSystem.js +331 -0
- package/esm/FileSystem.js.map +1 -0
- package/esm/Git.d.ts +203 -0
- package/esm/Git.d.ts.map +1 -0
- package/esm/Git.js +260 -0
- package/esm/Git.js.map +1 -0
- package/esm/Image.d.ts +285 -0
- package/esm/Image.d.ts.map +1 -0
- package/esm/Image.js +569 -0
- package/esm/Image.js.map +1 -0
- package/esm/LspServer.d.ts +172 -0
- package/esm/LspServer.d.ts.map +1 -0
- package/esm/LspServer.js +204 -0
- package/esm/LspServer.js.map +1 -0
- package/esm/ObjectStorage.d.ts +79 -0
- package/esm/ObjectStorage.d.ts.map +1 -0
- package/esm/ObjectStorage.js +187 -0
- package/esm/ObjectStorage.js.map +1 -0
- package/esm/Process.d.ts +442 -0
- package/esm/Process.d.ts.map +1 -0
- package/esm/Process.js +644 -0
- package/esm/Process.js.map +1 -0
- package/esm/PtyHandle.d.ts +155 -0
- package/esm/PtyHandle.d.ts.map +1 -0
- package/esm/PtyHandle.js +374 -0
- package/esm/PtyHandle.js.map +1 -0
- package/esm/README.md +147 -0
- package/esm/Sandbox.d.ts +359 -0
- package/esm/Sandbox.d.ts.map +1 -0
- package/esm/Sandbox.js +532 -0
- package/esm/Sandbox.js.map +1 -0
- package/esm/Snapshot.d.ts +138 -0
- package/esm/Snapshot.d.ts.map +1 -0
- package/esm/Snapshot.js +207 -0
- package/esm/Snapshot.js.map +1 -0
- package/esm/Volume.d.ts +84 -0
- package/esm/Volume.d.ts.map +1 -0
- package/esm/Volume.js +95 -0
- package/esm/Volume.js.map +1 -0
- package/esm/code-toolbox/SandboxJsCodeToolbox.d.ts +6 -0
- package/esm/code-toolbox/SandboxJsCodeToolbox.d.ts.map +1 -0
- package/esm/code-toolbox/SandboxJsCodeToolbox.js +13 -0
- package/esm/code-toolbox/SandboxJsCodeToolbox.js.map +1 -0
- package/esm/code-toolbox/SandboxPythonCodeToolbox.d.ts +12 -0
- package/esm/code-toolbox/SandboxPythonCodeToolbox.d.ts.map +1 -0
- package/esm/code-toolbox/SandboxPythonCodeToolbox.js +355 -0
- package/esm/code-toolbox/SandboxPythonCodeToolbox.js.map +1 -0
- package/esm/code-toolbox/SandboxTsCodeToolbox.d.ts +6 -0
- package/esm/code-toolbox/SandboxTsCodeToolbox.d.ts.map +1 -0
- package/esm/code-toolbox/SandboxTsCodeToolbox.js +14 -0
- package/esm/code-toolbox/SandboxTsCodeToolbox.js.map +1 -0
- package/esm/errors/DaytonaError.d.ts +32 -0
- package/esm/errors/DaytonaError.d.ts.map +1 -0
- package/esm/errors/DaytonaError.js +44 -0
- package/esm/errors/DaytonaError.js.map +1 -0
- package/esm/index.d.ts +22 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +22 -0
- package/esm/index.js.map +1 -0
- package/esm/package.json +3 -0
- package/esm/types/Charts.d.ts +152 -0
- package/esm/types/Charts.d.ts.map +1 -0
- package/esm/types/Charts.js +42 -0
- package/esm/types/Charts.js.map +1 -0
- package/esm/types/CodeInterpreter.d.ts +77 -0
- package/esm/types/CodeInterpreter.d.ts.map +1 -0
- package/esm/types/CodeInterpreter.js +6 -0
- package/esm/types/CodeInterpreter.js.map +1 -0
- package/esm/types/ExecuteResponse.d.ts +26 -0
- package/esm/types/ExecuteResponse.d.ts.map +1 -0
- package/esm/types/ExecuteResponse.js +6 -0
- package/esm/types/ExecuteResponse.js.map +1 -0
- package/esm/types/Pty.d.ts +48 -0
- package/esm/types/Pty.d.ts.map +1 -0
- package/esm/types/Pty.js +6 -0
- package/esm/types/Pty.js.map +1 -0
- package/esm/utils/ArtifactParser.d.ts +14 -0
- package/esm/utils/ArtifactParser.d.ts.map +1 -0
- package/esm/utils/ArtifactParser.js +51 -0
- package/esm/utils/ArtifactParser.js.map +1 -0
- package/esm/utils/Binary.d.ts +39 -0
- package/esm/utils/Binary.d.ts.map +1 -0
- package/esm/utils/Binary.js +157 -0
- package/esm/utils/Binary.js.map +1 -0
- package/esm/utils/FileTransfer.d.ts +15 -0
- package/esm/utils/FileTransfer.d.ts.map +1 -0
- package/esm/utils/FileTransfer.js +209 -0
- package/esm/utils/FileTransfer.js.map +1 -0
- package/esm/utils/Import.d.ts +211 -0
- package/esm/utils/Import.d.ts.map +1 -0
- package/esm/utils/Import.js +45 -0
- package/esm/utils/Import.js.map +1 -0
- package/esm/utils/Multipart.d.ts +27 -0
- package/esm/utils/Multipart.d.ts.map +1 -0
- package/esm/utils/Multipart.js +107 -0
- package/esm/utils/Multipart.js.map +1 -0
- package/esm/utils/Runtime.d.ts +37 -0
- package/esm/utils/Runtime.d.ts.map +1 -0
- package/esm/utils/Runtime.js +57 -0
- package/esm/utils/Runtime.js.map +1 -0
- package/esm/utils/Stream.d.ts +20 -0
- package/esm/utils/Stream.d.ts.map +1 -0
- package/esm/utils/Stream.js +360 -0
- package/esm/utils/Stream.js.map +1 -0
- package/esm/utils/WebSocket.d.ts +10 -0
- package/esm/utils/WebSocket.d.ts.map +1 -0
- package/esm/utils/WebSocket.js +22 -0
- package/esm/utils/WebSocket.js.map +1 -0
- package/package.json +20 -8
- package/src/CodeInterpreter.js.map +0 -1
- package/src/ComputerUse.js.map +0 -1
- package/src/Daytona.js.map +0 -1
- package/src/FileSystem.js.map +0 -1
- package/src/Git.js.map +0 -1
- package/src/Image.js.map +0 -1
- package/src/LspServer.js.map +0 -1
- package/src/ObjectStorage.js.map +0 -1
- package/src/Process.js.map +0 -1
- package/src/PtyHandle.js.map +0 -1
- package/src/Sandbox.js.map +0 -1
- package/src/Snapshot.js.map +0 -1
- package/src/Volume.js.map +0 -1
- package/src/code-toolbox/SandboxJsCodeToolbox.js.map +0 -1
- package/src/code-toolbox/SandboxPythonCodeToolbox.js.map +0 -1
- package/src/code-toolbox/SandboxTsCodeToolbox.js.map +0 -1
- package/src/errors/DaytonaError.js.map +0 -1
- package/src/index.js.map +0 -1
- package/src/types/Charts.js.map +0 -1
- package/src/types/CodeInterpreter.js.map +0 -1
- package/src/types/ExecuteResponse.js.map +0 -1
- package/src/types/Pty.js.map +0 -1
- package/src/utils/ArtifactParser.js.map +0 -1
- package/src/utils/Binary.js.map +0 -1
- package/src/utils/FileTransfer.js.map +0 -1
- package/src/utils/Import.js +0 -77
- package/src/utils/Import.js.map +0 -1
- package/src/utils/Multipart.js.map +0 -1
- package/src/utils/Runtime.js.map +0 -1
- package/src/utils/Stream.js.map +0 -1
- package/src/utils/WebSocket.js.map +0 -1
- /package/{src → cjs}/CodeInterpreter.js +0 -0
- /package/{src → cjs}/ComputerUse.js +0 -0
- /package/{src → cjs}/FileSystem.js +0 -0
- /package/{src → cjs}/Git.js +0 -0
- /package/{src → cjs}/LspServer.js +0 -0
- /package/{src → cjs}/ObjectStorage.js +0 -0
- /package/{src → cjs}/Process.js +0 -0
- /package/{src → cjs}/PtyHandle.js +0 -0
- /package/{src → cjs}/Volume.js +0 -0
- /package/{src → cjs}/code-toolbox/SandboxJsCodeToolbox.js +0 -0
- /package/{src → cjs}/code-toolbox/SandboxPythonCodeToolbox.js +0 -0
- /package/{src → cjs}/code-toolbox/SandboxTsCodeToolbox.js +0 -0
- /package/{src → cjs}/errors/DaytonaError.js +0 -0
- /package/{src → cjs}/index.js +0 -0
- /package/{src → cjs}/types/Charts.js +0 -0
- /package/{src → cjs}/types/CodeInterpreter.js +0 -0
- /package/{src → cjs}/types/ExecuteResponse.js +0 -0
- /package/{src → cjs}/types/Pty.js +0 -0
- /package/{src → cjs}/utils/ArtifactParser.js +0 -0
- /package/{src → cjs}/utils/Binary.js +0 -0
- /package/{src → cjs}/utils/FileTransfer.js +0 -0
- /package/{src → cjs}/utils/Multipart.js +0 -0
- /package/{src → cjs}/utils/Runtime.js +0 -0
- /package/{src → cjs}/utils/Stream.js +0 -0
- /package/{src → cjs}/utils/WebSocket.js +0 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import WebSocket from 'isomorphic-ws';
|
|
2
|
+
import { PtyResult } from './types/Pty.js';
|
|
3
|
+
import { PtySessionInfo } from '@daytonaio/toolbox-api-client';
|
|
4
|
+
/**
|
|
5
|
+
* PTY session handle for managing a single PTY session.
|
|
6
|
+
*
|
|
7
|
+
* Provides methods for sending input, resizing the terminal, waiting for completion,
|
|
8
|
+
* and managing the WebSocket connection to a PTY session.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // Create a PTY session
|
|
13
|
+
* const ptyHandle = await process.createPty({
|
|
14
|
+
* id: 'my-session',
|
|
15
|
+
* cols: 120,
|
|
16
|
+
* rows: 30,
|
|
17
|
+
* onData: (data) => {
|
|
18
|
+
* const text = new TextDecoder().decode(data);
|
|
19
|
+
* process.stdout.write(text);
|
|
20
|
+
* },
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
*
|
|
24
|
+
* // Send commands
|
|
25
|
+
* await ptyHandle.sendInput('ls -la\n');
|
|
26
|
+
* await ptyHandle.sendInput('exit\n');
|
|
27
|
+
*
|
|
28
|
+
* // Wait for completion
|
|
29
|
+
* const result = await ptyHandle.wait();
|
|
30
|
+
* console.log(`PTY exited with code: ${result.exitCode}`);
|
|
31
|
+
*
|
|
32
|
+
* // Clean up
|
|
33
|
+
* await ptyHandle.disconnect();
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare class PtyHandle {
|
|
37
|
+
private readonly ws;
|
|
38
|
+
private readonly handleResize;
|
|
39
|
+
private readonly handleKill;
|
|
40
|
+
private readonly onPty;
|
|
41
|
+
readonly sessionId: string;
|
|
42
|
+
private _exitCode?;
|
|
43
|
+
private _error?;
|
|
44
|
+
private connected;
|
|
45
|
+
private connectionEstablished;
|
|
46
|
+
constructor(ws: WebSocket, handleResize: (cols: number, rows: number) => Promise<PtySessionInfo>, handleKill: () => Promise<void>, onPty: (data: Uint8Array) => void | Promise<void>, sessionId: string);
|
|
47
|
+
/**
|
|
48
|
+
* Exit code of the PTY process (if terminated)
|
|
49
|
+
*/
|
|
50
|
+
get exitCode(): number | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Error message if the PTY failed
|
|
53
|
+
*/
|
|
54
|
+
get error(): string | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* Check if connected to the PTY session
|
|
57
|
+
*/
|
|
58
|
+
isConnected(): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Wait for the WebSocket connection to be established.
|
|
61
|
+
*
|
|
62
|
+
* This method ensures the PTY session is ready to receive input and send output.
|
|
63
|
+
* It waits for the server to confirm the connection is established.
|
|
64
|
+
*
|
|
65
|
+
* @throws {Error} If connection times out (10 seconds) or connection fails
|
|
66
|
+
*/
|
|
67
|
+
waitForConnection(): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Send input data to the PTY session.
|
|
70
|
+
*
|
|
71
|
+
* Sends keyboard input or commands to the terminal session. The data will be
|
|
72
|
+
* processed as if it was typed in the terminal.
|
|
73
|
+
*
|
|
74
|
+
* @param {string | Uint8Array} data - Input data to send (commands, keystrokes, etc.)
|
|
75
|
+
* @throws {Error} If PTY is not connected or sending fails
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* // Send a command
|
|
79
|
+
* await ptyHandle.sendInput('ls -la\n');
|
|
80
|
+
*
|
|
81
|
+
* // Send raw bytes
|
|
82
|
+
* await ptyHandle.sendInput(new Uint8Array([3])); // Ctrl+C
|
|
83
|
+
*/
|
|
84
|
+
sendInput(data: string | Uint8Array): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Resize the PTY terminal dimensions.
|
|
87
|
+
*
|
|
88
|
+
* Changes the terminal size which will notify terminal applications
|
|
89
|
+
* about the new dimensions via SIGWINCH signal.
|
|
90
|
+
*
|
|
91
|
+
* @param {number} cols - New number of terminal columns
|
|
92
|
+
* @param {number} rows - New number of terminal rows
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* // Resize to 120x30
|
|
96
|
+
* await ptyHandle.resize(120, 30);
|
|
97
|
+
*/
|
|
98
|
+
resize(cols: number, rows: number): Promise<PtySessionInfo>;
|
|
99
|
+
/**
|
|
100
|
+
* Disconnect from the PTY session and clean up resources.
|
|
101
|
+
*
|
|
102
|
+
* Closes the WebSocket connection and releases any associated resources.
|
|
103
|
+
* Should be called when done with the PTY session.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* // Always clean up when done
|
|
107
|
+
* try {
|
|
108
|
+
* // ... use PTY session
|
|
109
|
+
* } finally {
|
|
110
|
+
* await ptyHandle.disconnect();
|
|
111
|
+
* }
|
|
112
|
+
*/
|
|
113
|
+
disconnect(): Promise<void>;
|
|
114
|
+
/**
|
|
115
|
+
* Wait for the PTY process to exit and return the result.
|
|
116
|
+
*
|
|
117
|
+
* This method blocks until the PTY process terminates and returns
|
|
118
|
+
* information about how it exited.
|
|
119
|
+
*
|
|
120
|
+
* @returns {Promise<PtyResult>} Result containing exit code and error information
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* // Wait for process to complete
|
|
124
|
+
* const result = await ptyHandle.wait();
|
|
125
|
+
*
|
|
126
|
+
* if (result.exitCode === 0) {
|
|
127
|
+
* console.log('Process completed successfully');
|
|
128
|
+
* } else {
|
|
129
|
+
* console.log(`Process failed with code: ${result.exitCode}`);
|
|
130
|
+
* if (result.error) {
|
|
131
|
+
* console.log(`Error: ${result.error}`);
|
|
132
|
+
* }
|
|
133
|
+
* }
|
|
134
|
+
*/
|
|
135
|
+
wait(): Promise<PtyResult>;
|
|
136
|
+
/**
|
|
137
|
+
* Kill the PTY process and terminate the session.
|
|
138
|
+
*
|
|
139
|
+
* Forcefully terminates the PTY session and its associated process.
|
|
140
|
+
* This operation is irreversible and will cause the PTY to exit immediately.
|
|
141
|
+
*
|
|
142
|
+
* @throws {Error} If the kill operation fails
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* // Kill a long-running process
|
|
146
|
+
* await ptyHandle.kill();
|
|
147
|
+
*
|
|
148
|
+
* // Wait to confirm termination
|
|
149
|
+
* const result = await ptyHandle.wait();
|
|
150
|
+
* console.log(`Process terminated with exit code: ${result.exitCode}`);
|
|
151
|
+
*/
|
|
152
|
+
kill(): Promise<void>;
|
|
153
|
+
private setupWebSocketHandlers;
|
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;;;;;;;;;OAeG;IACG,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBzD;;;;;;;;;;;;OAYG;IACG,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAIjE;;;;;;;;;;;;;OAaG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAUjC;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,IAAI,IAAI,OAAO,CAAC,SAAS,CAAC;IA2BhC;;;;;;;;;;;;;;;OAeG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B,OAAO,CAAC,sBAAsB;CA+H/B"}
|
package/esm/PtyHandle.js
ADDED
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Daytona Platforms Inc.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import WebSocket from 'isomorphic-ws';
|
|
6
|
+
import { DaytonaError } from './errors/DaytonaError.js';
|
|
7
|
+
/**
|
|
8
|
+
* PTY session handle for managing a single PTY session.
|
|
9
|
+
*
|
|
10
|
+
* Provides methods for sending input, resizing the terminal, waiting for completion,
|
|
11
|
+
* and managing the WebSocket connection to a PTY session.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* // Create a PTY session
|
|
16
|
+
* const ptyHandle = await process.createPty({
|
|
17
|
+
* id: 'my-session',
|
|
18
|
+
* cols: 120,
|
|
19
|
+
* rows: 30,
|
|
20
|
+
* onData: (data) => {
|
|
21
|
+
* const text = new TextDecoder().decode(data);
|
|
22
|
+
* process.stdout.write(text);
|
|
23
|
+
* },
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
*
|
|
27
|
+
* // Send commands
|
|
28
|
+
* await ptyHandle.sendInput('ls -la\n');
|
|
29
|
+
* await ptyHandle.sendInput('exit\n');
|
|
30
|
+
*
|
|
31
|
+
* // Wait for completion
|
|
32
|
+
* const result = await ptyHandle.wait();
|
|
33
|
+
* console.log(`PTY exited with code: ${result.exitCode}`);
|
|
34
|
+
*
|
|
35
|
+
* // Clean up
|
|
36
|
+
* await ptyHandle.disconnect();
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export class PtyHandle {
|
|
40
|
+
ws;
|
|
41
|
+
handleResize;
|
|
42
|
+
handleKill;
|
|
43
|
+
onPty;
|
|
44
|
+
sessionId;
|
|
45
|
+
_exitCode;
|
|
46
|
+
_error;
|
|
47
|
+
connected = false;
|
|
48
|
+
connectionEstablished = false; // Track control message received
|
|
49
|
+
constructor(ws, handleResize, handleKill, onPty, sessionId) {
|
|
50
|
+
this.ws = ws;
|
|
51
|
+
this.handleResize = handleResize;
|
|
52
|
+
this.handleKill = handleKill;
|
|
53
|
+
this.onPty = onPty;
|
|
54
|
+
this.sessionId = sessionId;
|
|
55
|
+
this.setupWebSocketHandlers();
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Exit code of the PTY process (if terminated)
|
|
59
|
+
*/
|
|
60
|
+
get exitCode() {
|
|
61
|
+
return this._exitCode;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Error message if the PTY failed
|
|
65
|
+
*/
|
|
66
|
+
get error() {
|
|
67
|
+
return this._error;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Check if connected to the PTY session
|
|
71
|
+
*/
|
|
72
|
+
isConnected() {
|
|
73
|
+
return this.connected && this.ws.readyState === WebSocket.OPEN;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Wait for the WebSocket connection to be established.
|
|
77
|
+
*
|
|
78
|
+
* This method ensures the PTY session is ready to receive input and send output.
|
|
79
|
+
* It waits for the server to confirm the connection is established.
|
|
80
|
+
*
|
|
81
|
+
* @throws {Error} If connection times out (10 seconds) or connection fails
|
|
82
|
+
*/
|
|
83
|
+
async waitForConnection() {
|
|
84
|
+
if (this.connectionEstablished) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
return new Promise((resolve, reject) => {
|
|
88
|
+
const timeout = setTimeout(() => {
|
|
89
|
+
reject(new DaytonaError('PTY connection timeout'));
|
|
90
|
+
}, 10000); // 10 second timeout
|
|
91
|
+
const checkConnection = () => {
|
|
92
|
+
if (this.connectionEstablished) {
|
|
93
|
+
clearTimeout(timeout);
|
|
94
|
+
resolve();
|
|
95
|
+
}
|
|
96
|
+
else if (this.ws.readyState === WebSocket.CLOSED || this._error) {
|
|
97
|
+
clearTimeout(timeout);
|
|
98
|
+
reject(new DaytonaError(this._error || 'Connection failed'));
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
setTimeout(checkConnection, 100);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
checkConnection();
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Send input data to the PTY session.
|
|
109
|
+
*
|
|
110
|
+
* Sends keyboard input or commands to the terminal session. The data will be
|
|
111
|
+
* processed as if it was typed in the terminal.
|
|
112
|
+
*
|
|
113
|
+
* @param {string | Uint8Array} data - Input data to send (commands, keystrokes, etc.)
|
|
114
|
+
* @throws {Error} If PTY is not connected or sending fails
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* // Send a command
|
|
118
|
+
* await ptyHandle.sendInput('ls -la\n');
|
|
119
|
+
*
|
|
120
|
+
* // Send raw bytes
|
|
121
|
+
* await ptyHandle.sendInput(new Uint8Array([3])); // Ctrl+C
|
|
122
|
+
*/
|
|
123
|
+
async sendInput(data) {
|
|
124
|
+
if (!this.isConnected()) {
|
|
125
|
+
throw new DaytonaError('PTY is not connected');
|
|
126
|
+
}
|
|
127
|
+
try {
|
|
128
|
+
if (typeof data === 'string') {
|
|
129
|
+
this.ws.send(new TextEncoder().encode(data));
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
this.ws.send(data);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
137
|
+
throw new DaytonaError(`Failed to send input to PTY: ${errorMessage}`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Resize the PTY terminal dimensions.
|
|
142
|
+
*
|
|
143
|
+
* Changes the terminal size which will notify terminal applications
|
|
144
|
+
* about the new dimensions via SIGWINCH signal.
|
|
145
|
+
*
|
|
146
|
+
* @param {number} cols - New number of terminal columns
|
|
147
|
+
* @param {number} rows - New number of terminal rows
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* // Resize to 120x30
|
|
151
|
+
* await ptyHandle.resize(120, 30);
|
|
152
|
+
*/
|
|
153
|
+
async resize(cols, rows) {
|
|
154
|
+
return await this.handleResize(cols, rows);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Disconnect from the PTY session and clean up resources.
|
|
158
|
+
*
|
|
159
|
+
* Closes the WebSocket connection and releases any associated resources.
|
|
160
|
+
* Should be called when done with the PTY session.
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* // Always clean up when done
|
|
164
|
+
* try {
|
|
165
|
+
* // ... use PTY session
|
|
166
|
+
* } finally {
|
|
167
|
+
* await ptyHandle.disconnect();
|
|
168
|
+
* }
|
|
169
|
+
*/
|
|
170
|
+
async disconnect() {
|
|
171
|
+
if (this.ws) {
|
|
172
|
+
try {
|
|
173
|
+
this.ws.close();
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
// Ignore close errors
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Wait for the PTY process to exit and return the result.
|
|
182
|
+
*
|
|
183
|
+
* This method blocks until the PTY process terminates and returns
|
|
184
|
+
* information about how it exited.
|
|
185
|
+
*
|
|
186
|
+
* @returns {Promise<PtyResult>} Result containing exit code and error information
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* // Wait for process to complete
|
|
190
|
+
* const result = await ptyHandle.wait();
|
|
191
|
+
*
|
|
192
|
+
* if (result.exitCode === 0) {
|
|
193
|
+
* console.log('Process completed successfully');
|
|
194
|
+
* } else {
|
|
195
|
+
* console.log(`Process failed with code: ${result.exitCode}`);
|
|
196
|
+
* if (result.error) {
|
|
197
|
+
* console.log(`Error: ${result.error}`);
|
|
198
|
+
* }
|
|
199
|
+
* }
|
|
200
|
+
*/
|
|
201
|
+
async wait() {
|
|
202
|
+
return new Promise((resolve, reject) => {
|
|
203
|
+
if (this._exitCode !== undefined) {
|
|
204
|
+
resolve({
|
|
205
|
+
exitCode: this._exitCode,
|
|
206
|
+
error: this._error,
|
|
207
|
+
});
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const checkExit = () => {
|
|
211
|
+
if (this._exitCode !== undefined) {
|
|
212
|
+
resolve({
|
|
213
|
+
exitCode: this._exitCode,
|
|
214
|
+
error: this._error,
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
else if (this._error) {
|
|
218
|
+
reject(new DaytonaError(this._error));
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
setTimeout(checkExit, 100);
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
checkExit();
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Kill the PTY process and terminate the session.
|
|
229
|
+
*
|
|
230
|
+
* Forcefully terminates the PTY session and its associated process.
|
|
231
|
+
* This operation is irreversible and will cause the PTY to exit immediately.
|
|
232
|
+
*
|
|
233
|
+
* @throws {Error} If the kill operation fails
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* // Kill a long-running process
|
|
237
|
+
* await ptyHandle.kill();
|
|
238
|
+
*
|
|
239
|
+
* // Wait to confirm termination
|
|
240
|
+
* const result = await ptyHandle.wait();
|
|
241
|
+
* console.log(`Process terminated with exit code: ${result.exitCode}`);
|
|
242
|
+
*/
|
|
243
|
+
async kill() {
|
|
244
|
+
return await this.handleKill();
|
|
245
|
+
}
|
|
246
|
+
setupWebSocketHandlers() {
|
|
247
|
+
// Set binary type for binary data handling
|
|
248
|
+
if ('binaryType' in this.ws) {
|
|
249
|
+
this.ws.binaryType = 'arraybuffer';
|
|
250
|
+
}
|
|
251
|
+
// Handle WebSocket open
|
|
252
|
+
const handleOpen = async () => {
|
|
253
|
+
this.connected = true;
|
|
254
|
+
};
|
|
255
|
+
// Handle WebSocket messages - control messages and PTY data
|
|
256
|
+
const handleMessage = async (event) => {
|
|
257
|
+
try {
|
|
258
|
+
const data = event && typeof event === 'object' && 'data' in event ? event.data : event;
|
|
259
|
+
if (typeof data === 'string') {
|
|
260
|
+
// Try to parse as control message first
|
|
261
|
+
try {
|
|
262
|
+
const controlMsg = JSON.parse(data);
|
|
263
|
+
if (controlMsg.type === 'control') {
|
|
264
|
+
if (controlMsg.status === 'connected') {
|
|
265
|
+
this.connectionEstablished = true;
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
else if (controlMsg.status === 'error') {
|
|
269
|
+
this._error = controlMsg.error || 'Unknown connection error';
|
|
270
|
+
this.connected = false;
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
catch {
|
|
276
|
+
// Not a control message, treat as PTY output
|
|
277
|
+
}
|
|
278
|
+
// Regular PTY text output
|
|
279
|
+
if (this.onPty) {
|
|
280
|
+
await this.onPty(new TextEncoder().encode(data));
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
// Handle binary data (terminal output)
|
|
285
|
+
let bytes;
|
|
286
|
+
if (data instanceof ArrayBuffer) {
|
|
287
|
+
bytes = new Uint8Array(data);
|
|
288
|
+
}
|
|
289
|
+
else if (ArrayBuffer.isView(data)) {
|
|
290
|
+
bytes = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
291
|
+
}
|
|
292
|
+
else if (data instanceof Blob) {
|
|
293
|
+
const buffer = await data.arrayBuffer();
|
|
294
|
+
bytes = new Uint8Array(buffer);
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
throw new DaytonaError(`Unsupported message data type: ${Object.prototype.toString.call(data)}`);
|
|
298
|
+
}
|
|
299
|
+
if (this.onPty) {
|
|
300
|
+
await this.onPty(bytes);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
catch (error) {
|
|
305
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
306
|
+
throw new DaytonaError(`Error handling PTY message: ${errorMessage}`);
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
// Handle WebSocket errors
|
|
310
|
+
const handleError = async (error) => {
|
|
311
|
+
let errorMessage;
|
|
312
|
+
if (error instanceof Error) {
|
|
313
|
+
errorMessage = error.message;
|
|
314
|
+
}
|
|
315
|
+
else if (error && error instanceof Event) {
|
|
316
|
+
errorMessage = 'WebSocket connection error';
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
errorMessage = String(error);
|
|
320
|
+
}
|
|
321
|
+
this._error = errorMessage;
|
|
322
|
+
this.connected = false;
|
|
323
|
+
};
|
|
324
|
+
// Handle WebSocket close - parse structured exit data
|
|
325
|
+
const handleClose = async (event) => {
|
|
326
|
+
this.connected = false;
|
|
327
|
+
// Parse structured exit data from close reason
|
|
328
|
+
if (event && event.reason) {
|
|
329
|
+
try {
|
|
330
|
+
const exitData = JSON.parse(event.reason);
|
|
331
|
+
if (typeof exitData.exitCode === 'number') {
|
|
332
|
+
this._exitCode = exitData.exitCode;
|
|
333
|
+
// Store exit reason if provided (undefined for exitCode 0)
|
|
334
|
+
if (exitData.exitReason) {
|
|
335
|
+
this._error = exitData.exitReason;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
// Handle error messages from server (e.g., "PTY session not found")
|
|
339
|
+
if (exitData.error) {
|
|
340
|
+
this._error = exitData.error;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
catch {
|
|
344
|
+
if (event.code === 1000) {
|
|
345
|
+
this._exitCode = 0;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
// Default to exit code 0 if we can't parse it and it was a normal close
|
|
350
|
+
if (this._exitCode === undefined && event && event.code === 1000) {
|
|
351
|
+
this._exitCode = 0;
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
// Attach event listeners based on WebSocket implementation
|
|
355
|
+
if (this.ws.addEventListener) {
|
|
356
|
+
// Browser WebSocket
|
|
357
|
+
this.ws.addEventListener('open', handleOpen);
|
|
358
|
+
this.ws.addEventListener('message', handleMessage);
|
|
359
|
+
this.ws.addEventListener('error', handleError);
|
|
360
|
+
this.ws.addEventListener('close', handleClose);
|
|
361
|
+
}
|
|
362
|
+
else if ('on' in this.ws && typeof this.ws.on === 'function') {
|
|
363
|
+
// Node.js WebSocket
|
|
364
|
+
this.ws.on('open', handleOpen);
|
|
365
|
+
this.ws.on('message', handleMessage);
|
|
366
|
+
this.ws.on('error', handleError);
|
|
367
|
+
this.ws.on('close', handleClose);
|
|
368
|
+
}
|
|
369
|
+
else {
|
|
370
|
+
throw new DaytonaError('Unsupported WebSocket implementation');
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
//# sourceMappingURL=PtyHandle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PtyHandle.js","sourceRoot":"","sources":["../../../../../libs/sdk-typescript/src/PtyHandle.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,SAAS,MAAM,eAAe,CAAA;AAErC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAGpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,OAAO,SAAS;IAOD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IAAI,CAAC,SAAS,GAAG,CAAC,CAAA;YACpB,CAAC;QACH,CAAC,CAAA;QAED,2DAA2D;QAC3D,IAAI,IAAI,CAAC,EAAE,CAAC,gBAAgB,EAAE,CAAC;YAC7B,oBAAoB;YACpB,IAAI,CAAC,EAAE,CAAC,gBAAgB,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;YAC5C,IAAI,CAAC,EAAE,CAAC,gBAAgB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAA;YAClD,IAAI,CAAC,EAAE,CAAC,gBAAgB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAA;YAC9C,IAAI,CAAC,EAAE,CAAC,gBAAgB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAA;QAChD,CAAC;aAAM,IAAI,IAAI,IAAI,IAAI,CAAC,EAAE,IAAI,OAAO,IAAI,CAAC,EAAE,CAAC,EAAE,KAAK,UAAU,EAAE,CAAC;YAC/D,oBAAoB;YACpB,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;YAC9B,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,SAAS,EAAE,aAAa,CAAC,CAAA;YACpC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,CAAC,CAAA;YAChC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,CAAC,CAAA;QAClC,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,YAAY,CAAC,sCAAsC,CAAC,CAAA;QAChE,CAAC;IACH,CAAC;CACF"}
|
package/esm/README.md
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# Daytona SDK for TypeScript
|
|
2
|
+
|
|
3
|
+
A TypeScript SDK for interacting with the Daytona API, providing a simple interface for Daytona Sandbox management, Git operations, file system operations, and language server protocol support.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
You can install the package using npm:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @daytonaio/sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or using yarn:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
yarn add @daytonaio/sdk
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
Here's a simple example of using the SDK:
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { Daytona } from '@daytonaio/sdk'
|
|
25
|
+
|
|
26
|
+
// Initialize using environment variables
|
|
27
|
+
const daytona = new Daytona()
|
|
28
|
+
|
|
29
|
+
// Create a sandbox
|
|
30
|
+
const sandbox = await daytona.create()
|
|
31
|
+
|
|
32
|
+
// Run code in the sandbox
|
|
33
|
+
const response = await sandbox.process.codeRun('console.log("Hello World!")')
|
|
34
|
+
console.log(response.result)
|
|
35
|
+
|
|
36
|
+
// Clean up when done
|
|
37
|
+
await daytona.delete(sandbox)
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Configuration
|
|
41
|
+
|
|
42
|
+
The SDK can be configured using environment variables or by passing a configuration object:
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { Daytona } from '@daytonaio/sdk'
|
|
46
|
+
|
|
47
|
+
// Initialize with configuration
|
|
48
|
+
const daytona = new Daytona({
|
|
49
|
+
apiKey: 'your-api-key',
|
|
50
|
+
apiUrl: 'your-api-url',
|
|
51
|
+
target: 'us',
|
|
52
|
+
})
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Or using environment variables:
|
|
56
|
+
|
|
57
|
+
- `DAYTONA_API_KEY`: Your Daytona API key
|
|
58
|
+
- `DAYTONA_API_URL`: The Daytona API URL
|
|
59
|
+
- `DAYTONA_TARGET`: Your target environment
|
|
60
|
+
|
|
61
|
+
You can also customize sandbox creation:
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
const sandbox = await daytona.create({
|
|
65
|
+
language: 'typescript',
|
|
66
|
+
envVars: { NODE_ENV: 'development' },
|
|
67
|
+
autoStopInterval: 60, // Auto-stop after 1 hour of inactivity,
|
|
68
|
+
autoArchiveInterval: 60, // Auto-archive after a Sandbox has been stopped for 1 hour
|
|
69
|
+
autoDeleteInterval: 120, // Auto-delete after a Sandbox has been stopped for 2 hours
|
|
70
|
+
})
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Features
|
|
74
|
+
|
|
75
|
+
- **Sandbox Management**: Create, manage and remove sandboxes
|
|
76
|
+
- **Git Operations**: Clone repositories, manage branches, and more
|
|
77
|
+
- **File System Operations**: Upload, download, search and manipulate files
|
|
78
|
+
- **Language Server Protocol**: Interact with language servers for code intelligence
|
|
79
|
+
- **Process Management**: Execute code and commands in sandboxes
|
|
80
|
+
|
|
81
|
+
## Examples
|
|
82
|
+
|
|
83
|
+
### Execute Commands
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
// Execute a shell command
|
|
87
|
+
const response = await sandbox.process.executeCommand('echo "Hello, World!"')
|
|
88
|
+
console.log(response.result)
|
|
89
|
+
|
|
90
|
+
// Run TypeScript code
|
|
91
|
+
const response = await sandbox.process.codeRun(`
|
|
92
|
+
const x = 10
|
|
93
|
+
const y = 20
|
|
94
|
+
console.log(\`Sum: \${x + y}\`)
|
|
95
|
+
`)
|
|
96
|
+
console.log(response.result)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### File Operations
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
// Upload a file
|
|
103
|
+
await sandbox.fs.uploadFile(Buffer.from('Hello, World!'), 'path/to/file.txt')
|
|
104
|
+
|
|
105
|
+
// Download a file
|
|
106
|
+
const content = await sandbox.fs.downloadFile('path/to/file.txt')
|
|
107
|
+
|
|
108
|
+
// Search for files
|
|
109
|
+
const matches = await sandbox.fs.findFiles(root_dir, 'search_pattern')
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Git Operations
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
// Clone a repository
|
|
116
|
+
await sandbox.git.clone('https://github.com/example/repo', 'path/to/clone')
|
|
117
|
+
|
|
118
|
+
// List branches
|
|
119
|
+
const branches = await sandbox.git.branches('path/to/repo')
|
|
120
|
+
|
|
121
|
+
// Add files
|
|
122
|
+
await sandbox.git.add('path/to/repo', ['file1.txt', 'file2.txt'])
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Language Server Protocol
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
// Create and start a language server
|
|
129
|
+
const lsp = await sandbox.createLspServer('typescript', 'path/to/project')
|
|
130
|
+
await lsp.start()
|
|
131
|
+
|
|
132
|
+
// Notify the lsp for the file
|
|
133
|
+
await lsp.didOpen('path/to/file.ts')
|
|
134
|
+
|
|
135
|
+
// Get document symbols
|
|
136
|
+
const symbols = await lsp.documentSymbols('path/to/file.ts')
|
|
137
|
+
|
|
138
|
+
// Get completions
|
|
139
|
+
const completions = await lsp.completions('path/to/file.ts', {
|
|
140
|
+
line: 10,
|
|
141
|
+
character: 15,
|
|
142
|
+
})
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Contributing
|
|
146
|
+
|
|
147
|
+
Daytona is Open Source under the [Apache License 2.0](/libs/sdk-typescript//LICENSE), and is the [copyright of its contributors](/NOTICE). If you would like to contribute to the software, read the Developer Certificate of Origin Version 1.1 (https://developercertificate.org/). Afterwards, navigate to the [contributing guide](/CONTRIBUTING.md) to get started.
|