@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/dist/Process.d.ts
CHANGED
|
@@ -1,67 +1,217 @@
|
|
|
1
|
-
import { Command, ExecuteResponse, Session, SessionExecuteRequest, SessionExecuteResponse, ToolboxApi, Workspace } from '@daytonaio/api-client';
|
|
2
|
-
import { WorkspaceCodeToolbox } from './Workspace';
|
|
3
1
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* The Daytona SDK provides powerful process and code execution capabilities through
|
|
3
|
+
* the `process` module in Sandboxes. This guide covers all available process operations
|
|
4
|
+
* and best practices.
|
|
5
|
+
*
|
|
6
|
+
* @module Process
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* // Execute a shell command
|
|
10
|
+
* const response = await workspace.process.executeCommand('ls -la');
|
|
11
|
+
* console.log(response.result);
|
|
12
|
+
*
|
|
13
|
+
* // Run TypeScript code
|
|
14
|
+
* const response = await workspace.process.codeRun('console.log("Hello, World!")');
|
|
15
|
+
* console.log(response.result);
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* // Using interactive sessions
|
|
19
|
+
* // Create a new session
|
|
20
|
+
* const sessionId = 'my-session';
|
|
21
|
+
* await workspace.process.createSession(sessionId);
|
|
22
|
+
*
|
|
23
|
+
* // Execute commands in the session
|
|
24
|
+
* const response = await workspace.process.executeSessionCommand(sessionId, {
|
|
25
|
+
* command: 'cd /workspace'
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* const response2 = await workspace.process.executeSessionCommand(sessionId, {
|
|
29
|
+
* command: 'pwd'
|
|
30
|
+
* });
|
|
31
|
+
* console.log(response2.result); // Should print "/workspace"
|
|
32
|
+
*
|
|
33
|
+
* // Clean up
|
|
34
|
+
* await workspace.process.deleteSession(sessionId);
|
|
6
35
|
*/
|
|
36
|
+
import { Command, ExecuteResponse, Session, SessionExecuteRequest, SessionExecuteResponse, ToolboxApi } from '@daytonaio/api-client';
|
|
37
|
+
import { WorkspaceCodeToolbox, WorkspaceInstance } from './Workspace';
|
|
38
|
+
/**
|
|
39
|
+
* Parameters for code execution
|
|
40
|
+
*/
|
|
41
|
+
export declare class CodeRunParams {
|
|
42
|
+
/**
|
|
43
|
+
* Command line arguments
|
|
44
|
+
*/
|
|
45
|
+
argv?: string[];
|
|
46
|
+
/**
|
|
47
|
+
* Environment variables
|
|
48
|
+
*/
|
|
49
|
+
env?: Record<string, string>;
|
|
50
|
+
}
|
|
7
51
|
export declare class Process {
|
|
8
52
|
private readonly codeToolbox;
|
|
9
53
|
private readonly toolboxApi;
|
|
10
54
|
private readonly instance;
|
|
11
|
-
constructor(codeToolbox: WorkspaceCodeToolbox, toolboxApi: ToolboxApi, instance:
|
|
55
|
+
constructor(codeToolbox: WorkspaceCodeToolbox, toolboxApi: ToolboxApi, instance: WorkspaceInstance);
|
|
12
56
|
/**
|
|
13
|
-
* Executes a shell command in the
|
|
14
|
-
*
|
|
15
|
-
* @
|
|
57
|
+
* Executes a shell command in the Sandbox.
|
|
58
|
+
*
|
|
59
|
+
* @param {string} command - Shell command to execute
|
|
60
|
+
* @param {string} [cwd] - Working directory for command execution. If not specified, uses the Sandbox root directory
|
|
61
|
+
* @param {number} [timeout] - Maximum time in seconds to wait for the command to complete. 0 means wait indefinitely.
|
|
62
|
+
* @returns {Promise<ExecuteResponse>} Command execution results containing:
|
|
63
|
+
* - exitCode: The command's exit status
|
|
64
|
+
* - result: Standard output from the command
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* // Simple command
|
|
68
|
+
* const response = await process.executeCommand('echo "Hello"');
|
|
69
|
+
* console.log(response.result); // Prints: Hello
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* // Command with working directory
|
|
73
|
+
* const result = await process.executeCommand('ls', '/workspace/src');
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* // Command with timeout
|
|
77
|
+
* const result = await process.executeCommand('sleep 10', undefined, 5);
|
|
16
78
|
*/
|
|
17
79
|
executeCommand(command: string, cwd?: string, timeout?: number): Promise<ExecuteResponse>;
|
|
18
80
|
/**
|
|
19
|
-
* Executes code in the
|
|
81
|
+
* Executes code in the Sandbox using the appropriate language runtime.
|
|
82
|
+
*
|
|
20
83
|
* @param {string} code - Code to execute
|
|
21
|
-
* @
|
|
84
|
+
* @param {CodeRunParams} params - Parameters for code execution
|
|
85
|
+
* @returns {Promise<ExecuteResponse>} Code execution results containing:
|
|
86
|
+
* - exitCode: The execution's exit status
|
|
87
|
+
* - result: Standard output from the code
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* // Run TypeScript code
|
|
91
|
+
* const response = await process.codeRun(`
|
|
92
|
+
* const x = 10;
|
|
93
|
+
* const y = 20;
|
|
94
|
+
* console.log(\`Sum: \${x + y}\`);
|
|
95
|
+
* `);
|
|
96
|
+
* console.log(response.result); // Prints: Sum: 30
|
|
22
97
|
*/
|
|
23
|
-
codeRun(code: string): Promise<ExecuteResponse>;
|
|
98
|
+
codeRun(code: string, params?: CodeRunParams, timeout?: number): Promise<ExecuteResponse>;
|
|
24
99
|
/**
|
|
25
|
-
* Creates a new
|
|
26
|
-
*
|
|
27
|
-
*
|
|
100
|
+
* Creates a new long-running background session in the Sandbox.
|
|
101
|
+
*
|
|
102
|
+
* Sessions are background processes that maintain state between commands, making them ideal for
|
|
103
|
+
* scenarios requiring multiple related commands or persistent environment setup. You can run
|
|
104
|
+
* long-running commands and monitor process status.
|
|
105
|
+
*
|
|
106
|
+
* @param {string} sessionId - Unique identifier for the new session
|
|
107
|
+
* @returns {Promise<void>}
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* // Create a new session
|
|
111
|
+
* const sessionId = 'my-session';
|
|
112
|
+
* await process.createSession(sessionId);
|
|
113
|
+
* const session = await process.getSession(sessionId);
|
|
114
|
+
* // Do work...
|
|
115
|
+
* await process.deleteSession(sessionId);
|
|
28
116
|
*/
|
|
29
117
|
createSession(sessionId: string): Promise<void>;
|
|
30
118
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* @param {
|
|
34
|
-
* @returns {Promise<
|
|
119
|
+
* Get a session in the workspace.
|
|
120
|
+
*
|
|
121
|
+
* @param {string} sessionId - Unique identifier of the session to retrieve
|
|
122
|
+
* @returns {Promise<Session>} Session information including:
|
|
123
|
+
* - sessionId: The session's unique identifier
|
|
124
|
+
* - commands: List of commands executed in the session
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* const session = await process.getSession('my-session');
|
|
128
|
+
* session.commands.forEach(cmd => {
|
|
129
|
+
* console.log(`Command: ${cmd.command}`);
|
|
130
|
+
* });
|
|
35
131
|
*/
|
|
36
|
-
|
|
132
|
+
getSession(sessionId: string): Promise<Session>;
|
|
37
133
|
/**
|
|
38
|
-
* Gets
|
|
39
|
-
*
|
|
40
|
-
* @param {string}
|
|
41
|
-
* @
|
|
134
|
+
* Gets information about a specific command executed in a session.
|
|
135
|
+
*
|
|
136
|
+
* @param {string} sessionId - Unique identifier of the session
|
|
137
|
+
* @param {string} commandId - Unique identifier of the command
|
|
138
|
+
* @returns {Promise<Command>} Command information including:
|
|
139
|
+
* - id: The command's unique identifier
|
|
140
|
+
* - command: The executed command string
|
|
141
|
+
* - exitCode: Command's exit status (if completed)
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* const cmd = await process.getSessionCommand('my-session', 'cmd-123');
|
|
145
|
+
* if (cmd.exitCode === 0) {
|
|
146
|
+
* console.log(`Command ${cmd.command} completed successfully`);
|
|
147
|
+
* }
|
|
42
148
|
*/
|
|
43
|
-
|
|
149
|
+
getSessionCommand(sessionId: string, commandId: string): Promise<Command>;
|
|
44
150
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* @
|
|
151
|
+
* Executes a command in an existing session.
|
|
152
|
+
*
|
|
153
|
+
* @param {string} sessionId - Unique identifier of the session to use
|
|
154
|
+
* @param {SessionExecuteRequest} req - Command execution request containing:
|
|
155
|
+
* - command: The command to execute
|
|
156
|
+
* - async: Whether to execute asynchronously
|
|
157
|
+
* @param {number} timeout - Timeout in seconds
|
|
158
|
+
* @returns {Promise<SessionExecuteResponse>} Command execution results containing:
|
|
159
|
+
* - cmdId: Unique identifier for the executed command
|
|
160
|
+
* - output: Command output (if synchronous execution)
|
|
161
|
+
* - exitCode: Command exit status (if synchronous execution)
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* // Execute commands in sequence, maintaining state
|
|
165
|
+
* const sessionId = 'my-session';
|
|
166
|
+
*
|
|
167
|
+
* // Change directory
|
|
168
|
+
* await process.executeSessionCommand(sessionId, {
|
|
169
|
+
* command: 'cd /workspace'
|
|
170
|
+
* });
|
|
171
|
+
*
|
|
172
|
+
* // Run command in new directory
|
|
173
|
+
* const result = await process.executeSessionCommand(sessionId, {
|
|
174
|
+
* command: 'pwd'
|
|
175
|
+
* });
|
|
176
|
+
* console.log(result.output); // Prints: /workspace
|
|
48
177
|
*/
|
|
49
|
-
|
|
178
|
+
executeSessionCommand(sessionId: string, req: SessionExecuteRequest, timeout?: number): Promise<SessionExecuteResponse>;
|
|
50
179
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* @param {string}
|
|
54
|
-
* @
|
|
180
|
+
* Get the logs for a command executed in a session.
|
|
181
|
+
*
|
|
182
|
+
* @param {string} sessionId - Unique identifier of the session
|
|
183
|
+
* @param {string} commandId - Unique identifier of the command
|
|
184
|
+
* @returns {Promise<string>} Command logs
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* const logs = await process.getSessionCommandLogs('my-session', 'cmd-123');
|
|
188
|
+
* console.log('Command output:', logs);
|
|
55
189
|
*/
|
|
56
|
-
|
|
190
|
+
getSessionCommandLogs(sessionId: string, commandId: string): Promise<string>;
|
|
57
191
|
/**
|
|
58
|
-
* Lists all sessions in the
|
|
59
|
-
*
|
|
192
|
+
* Lists all active sessions in the Sandbox.
|
|
193
|
+
*
|
|
194
|
+
* @returns {Promise<Session[]>} Array of active sessions
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* const sessions = await process.listSessions();
|
|
198
|
+
* sessions.forEach(session => {
|
|
199
|
+
* console.log(`Session ${session.sessionId}:`);
|
|
200
|
+
* session.commands.forEach(cmd => {
|
|
201
|
+
* console.log(`- ${cmd.command} (${cmd.exitCode})`);
|
|
202
|
+
* });
|
|
203
|
+
* });
|
|
60
204
|
*/
|
|
61
205
|
listSessions(): Promise<Session[]>;
|
|
62
206
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
207
|
+
* Delete a session from the Sandbox.
|
|
208
|
+
*
|
|
209
|
+
* @param {string} sessionId - Unique identifier of the session to delete
|
|
210
|
+
* @returns {Promise<void>}
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* // Clean up a completed session
|
|
214
|
+
* await process.deleteSession('my-session');
|
|
65
215
|
*/
|
|
66
216
|
deleteSession(sessionId: string): Promise<void>;
|
|
67
217
|
}
|
package/dist/Process.js
CHANGED
|
@@ -1,10 +1,47 @@
|
|
|
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 workspace.process.executeCommand('ls -la');
|
|
12
|
+
* console.log(response.result);
|
|
13
|
+
*
|
|
14
|
+
* // Run TypeScript code
|
|
15
|
+
* const response = await workspace.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 workspace.process.createSession(sessionId);
|
|
23
|
+
*
|
|
24
|
+
* // Execute commands in the session
|
|
25
|
+
* const response = await workspace.process.executeSessionCommand(sessionId, {
|
|
26
|
+
* command: 'cd /workspace'
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* const response2 = await workspace.process.executeSessionCommand(sessionId, {
|
|
30
|
+
* command: 'pwd'
|
|
31
|
+
* });
|
|
32
|
+
* console.log(response2.result); // Should print "/workspace"
|
|
33
|
+
*
|
|
34
|
+
* // Clean up
|
|
35
|
+
* await workspace.process.deleteSession(sessionId);
|
|
36
|
+
*/
|
|
2
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Process = void 0;
|
|
38
|
+
exports.Process = exports.CodeRunParams = void 0;
|
|
4
39
|
/**
|
|
5
|
-
*
|
|
6
|
-
* @class Process
|
|
40
|
+
* Parameters for code execution
|
|
7
41
|
*/
|
|
42
|
+
class CodeRunParams {
|
|
43
|
+
}
|
|
44
|
+
exports.CodeRunParams = CodeRunParams;
|
|
8
45
|
class Process {
|
|
9
46
|
constructor(codeToolbox, toolboxApi, instance) {
|
|
10
47
|
this.codeToolbox = codeToolbox;
|
|
@@ -12,9 +49,27 @@ class Process {
|
|
|
12
49
|
this.instance = instance;
|
|
13
50
|
}
|
|
14
51
|
/**
|
|
15
|
-
* Executes a shell command in the
|
|
16
|
-
*
|
|
17
|
-
* @
|
|
52
|
+
* Executes a shell command in the Sandbox.
|
|
53
|
+
*
|
|
54
|
+
* @param {string} command - Shell command to execute
|
|
55
|
+
* @param {string} [cwd] - Working directory for command execution. If not specified, uses the Sandbox root directory
|
|
56
|
+
* @param {number} [timeout] - Maximum time in seconds to wait for the command to complete. 0 means wait indefinitely.
|
|
57
|
+
* @returns {Promise<ExecuteResponse>} Command execution results containing:
|
|
58
|
+
* - exitCode: The command's exit status
|
|
59
|
+
* - result: Standard output from the command
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* // Simple command
|
|
63
|
+
* const response = await process.executeCommand('echo "Hello"');
|
|
64
|
+
* console.log(response.result); // Prints: Hello
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* // Command with working directory
|
|
68
|
+
* const result = await process.executeCommand('ls', '/workspace/src');
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* // Command with timeout
|
|
72
|
+
* const result = await process.executeCommand('sleep 10', undefined, 5);
|
|
18
73
|
*/
|
|
19
74
|
async executeCommand(command, cwd, timeout) {
|
|
20
75
|
const response = await this.toolboxApi.executeCommand(this.instance.id, {
|
|
@@ -25,21 +80,45 @@ class Process {
|
|
|
25
80
|
return response.data;
|
|
26
81
|
}
|
|
27
82
|
/**
|
|
28
|
-
* Executes code in the
|
|
83
|
+
* Executes code in the Sandbox using the appropriate language runtime.
|
|
84
|
+
*
|
|
29
85
|
* @param {string} code - Code to execute
|
|
30
|
-
* @
|
|
86
|
+
* @param {CodeRunParams} params - Parameters for code execution
|
|
87
|
+
* @returns {Promise<ExecuteResponse>} Code execution results containing:
|
|
88
|
+
* - exitCode: The execution's exit status
|
|
89
|
+
* - result: Standard output from the code
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* // Run TypeScript code
|
|
93
|
+
* const response = await process.codeRun(`
|
|
94
|
+
* const x = 10;
|
|
95
|
+
* const y = 20;
|
|
96
|
+
* console.log(\`Sum: \${x + y}\`);
|
|
97
|
+
* `);
|
|
98
|
+
* console.log(response.result); // Prints: Sum: 30
|
|
31
99
|
*/
|
|
32
|
-
async codeRun(code) {
|
|
33
|
-
const runCommand = this.codeToolbox.getRunCommand(code);
|
|
34
|
-
const response = await this.
|
|
35
|
-
|
|
36
|
-
});
|
|
37
|
-
return response.data;
|
|
100
|
+
async codeRun(code, params, timeout) {
|
|
101
|
+
const runCommand = this.codeToolbox.getRunCommand(code, params);
|
|
102
|
+
const response = await this.executeCommand(runCommand, undefined, timeout);
|
|
103
|
+
return response;
|
|
38
104
|
}
|
|
39
105
|
/**
|
|
40
|
-
* Creates a new
|
|
41
|
-
*
|
|
42
|
-
*
|
|
106
|
+
* Creates a new long-running background session in the Sandbox.
|
|
107
|
+
*
|
|
108
|
+
* Sessions are background processes that maintain state between commands, making them ideal for
|
|
109
|
+
* scenarios requiring multiple related commands or persistent environment setup. You can run
|
|
110
|
+
* long-running commands and monitor process status.
|
|
111
|
+
*
|
|
112
|
+
* @param {string} sessionId - Unique identifier for the new session
|
|
113
|
+
* @returns {Promise<void>}
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* // Create a new session
|
|
117
|
+
* const sessionId = 'my-session';
|
|
118
|
+
* await process.createSession(sessionId);
|
|
119
|
+
* const session = await process.getSession(sessionId);
|
|
120
|
+
* // Do work...
|
|
121
|
+
* await process.deleteSession(sessionId);
|
|
43
122
|
*/
|
|
44
123
|
async createSession(sessionId) {
|
|
45
124
|
await this.toolboxApi.createSession(this.instance.id, {
|
|
@@ -47,55 +126,117 @@ class Process {
|
|
|
47
126
|
});
|
|
48
127
|
}
|
|
49
128
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* @param {
|
|
53
|
-
* @returns {Promise<
|
|
129
|
+
* Get a session in the workspace.
|
|
130
|
+
*
|
|
131
|
+
* @param {string} sessionId - Unique identifier of the session to retrieve
|
|
132
|
+
* @returns {Promise<Session>} Session information including:
|
|
133
|
+
* - sessionId: The session's unique identifier
|
|
134
|
+
* - commands: List of commands executed in the session
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* const session = await process.getSession('my-session');
|
|
138
|
+
* session.commands.forEach(cmd => {
|
|
139
|
+
* console.log(`Command: ${cmd.command}`);
|
|
140
|
+
* });
|
|
54
141
|
*/
|
|
55
|
-
async
|
|
56
|
-
const response = await this.toolboxApi.
|
|
142
|
+
async getSession(sessionId) {
|
|
143
|
+
const response = await this.toolboxApi.getSession(this.instance.id, sessionId);
|
|
57
144
|
return response.data;
|
|
58
145
|
}
|
|
59
146
|
/**
|
|
60
|
-
* Gets
|
|
61
|
-
*
|
|
62
|
-
* @param {string}
|
|
63
|
-
* @
|
|
147
|
+
* Gets information about a specific command executed in a session.
|
|
148
|
+
*
|
|
149
|
+
* @param {string} sessionId - Unique identifier of the session
|
|
150
|
+
* @param {string} commandId - Unique identifier of the command
|
|
151
|
+
* @returns {Promise<Command>} Command information including:
|
|
152
|
+
* - id: The command's unique identifier
|
|
153
|
+
* - command: The executed command string
|
|
154
|
+
* - exitCode: Command's exit status (if completed)
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* const cmd = await process.getSessionCommand('my-session', 'cmd-123');
|
|
158
|
+
* if (cmd.exitCode === 0) {
|
|
159
|
+
* console.log(`Command ${cmd.command} completed successfully`);
|
|
160
|
+
* }
|
|
64
161
|
*/
|
|
65
|
-
async
|
|
66
|
-
const response = await this.toolboxApi.
|
|
162
|
+
async getSessionCommand(sessionId, commandId) {
|
|
163
|
+
const response = await this.toolboxApi.getSessionCommand(this.instance.id, sessionId, commandId);
|
|
67
164
|
return response.data;
|
|
68
165
|
}
|
|
69
166
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
* @
|
|
167
|
+
* Executes a command in an existing session.
|
|
168
|
+
*
|
|
169
|
+
* @param {string} sessionId - Unique identifier of the session to use
|
|
170
|
+
* @param {SessionExecuteRequest} req - Command execution request containing:
|
|
171
|
+
* - command: The command to execute
|
|
172
|
+
* - async: Whether to execute asynchronously
|
|
173
|
+
* @param {number} timeout - Timeout in seconds
|
|
174
|
+
* @returns {Promise<SessionExecuteResponse>} Command execution results containing:
|
|
175
|
+
* - cmdId: Unique identifier for the executed command
|
|
176
|
+
* - output: Command output (if synchronous execution)
|
|
177
|
+
* - exitCode: Command exit status (if synchronous execution)
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* // Execute commands in sequence, maintaining state
|
|
181
|
+
* const sessionId = 'my-session';
|
|
182
|
+
*
|
|
183
|
+
* // Change directory
|
|
184
|
+
* await process.executeSessionCommand(sessionId, {
|
|
185
|
+
* command: 'cd /workspace'
|
|
186
|
+
* });
|
|
187
|
+
*
|
|
188
|
+
* // Run command in new directory
|
|
189
|
+
* const result = await process.executeSessionCommand(sessionId, {
|
|
190
|
+
* command: 'pwd'
|
|
191
|
+
* });
|
|
192
|
+
* console.log(result.output); // Prints: /workspace
|
|
73
193
|
*/
|
|
74
|
-
async
|
|
75
|
-
const response = await this.toolboxApi.
|
|
194
|
+
async executeSessionCommand(sessionId, req, timeout) {
|
|
195
|
+
const response = await this.toolboxApi.executeSessionCommand(this.instance.id, sessionId, req, timeout ? { timeout: timeout * 1000 } : {});
|
|
76
196
|
return response.data;
|
|
77
197
|
}
|
|
78
198
|
/**
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* @param {string}
|
|
82
|
-
* @
|
|
199
|
+
* Get the logs for a command executed in a session.
|
|
200
|
+
*
|
|
201
|
+
* @param {string} sessionId - Unique identifier of the session
|
|
202
|
+
* @param {string} commandId - Unique identifier of the command
|
|
203
|
+
* @returns {Promise<string>} Command logs
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* const logs = await process.getSessionCommandLogs('my-session', 'cmd-123');
|
|
207
|
+
* console.log('Command output:', logs);
|
|
83
208
|
*/
|
|
84
|
-
async
|
|
85
|
-
const response = await this.toolboxApi.
|
|
209
|
+
async getSessionCommandLogs(sessionId, commandId) {
|
|
210
|
+
const response = await this.toolboxApi.getSessionCommandLogs(this.instance.id, sessionId, commandId);
|
|
86
211
|
return response.data;
|
|
87
212
|
}
|
|
88
213
|
/**
|
|
89
|
-
* Lists all sessions in the
|
|
90
|
-
*
|
|
214
|
+
* Lists all active sessions in the Sandbox.
|
|
215
|
+
*
|
|
216
|
+
* @returns {Promise<Session[]>} Array of active sessions
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* const sessions = await process.listSessions();
|
|
220
|
+
* sessions.forEach(session => {
|
|
221
|
+
* console.log(`Session ${session.sessionId}:`);
|
|
222
|
+
* session.commands.forEach(cmd => {
|
|
223
|
+
* console.log(`- ${cmd.command} (${cmd.exitCode})`);
|
|
224
|
+
* });
|
|
225
|
+
* });
|
|
91
226
|
*/
|
|
92
227
|
async listSessions() {
|
|
93
228
|
const response = await this.toolboxApi.listSessions(this.instance.id);
|
|
94
229
|
return response.data;
|
|
95
230
|
}
|
|
96
231
|
/**
|
|
97
|
-
*
|
|
98
|
-
*
|
|
232
|
+
* Delete a session from the Sandbox.
|
|
233
|
+
*
|
|
234
|
+
* @param {string} sessionId - Unique identifier of the session to delete
|
|
235
|
+
* @returns {Promise<void>}
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* // Clean up a completed session
|
|
239
|
+
* await process.deleteSession('my-session');
|
|
99
240
|
*/
|
|
100
241
|
async deleteSession(sessionId) {
|
|
101
242
|
await this.toolboxApi.deleteSession(this.instance.id, sessionId);
|