@daytonaio/sdk 0.0.0-dev

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/README.md +146 -0
  2. package/package.json +39 -0
  3. package/src/Daytona.d.ts +331 -0
  4. package/src/Daytona.js +400 -0
  5. package/src/Daytona.js.map +1 -0
  6. package/src/FileSystem.d.ts +270 -0
  7. package/src/FileSystem.js +302 -0
  8. package/src/FileSystem.js.map +1 -0
  9. package/src/Git.d.ts +211 -0
  10. package/src/Git.js +275 -0
  11. package/src/Git.js.map +1 -0
  12. package/src/Image.d.ts +264 -0
  13. package/src/Image.js +565 -0
  14. package/src/Image.js.map +1 -0
  15. package/src/LspServer.d.ts +173 -0
  16. package/src/LspServer.js +209 -0
  17. package/src/LspServer.js.map +1 -0
  18. package/src/ObjectStorage.d.ts +85 -0
  19. package/src/ObjectStorage.js +231 -0
  20. package/src/ObjectStorage.js.map +1 -0
  21. package/src/Process.d.ts +246 -0
  22. package/src/Process.js +290 -0
  23. package/src/Process.js.map +1 -0
  24. package/src/Sandbox.d.ts +266 -0
  25. package/src/Sandbox.js +389 -0
  26. package/src/Sandbox.js.map +1 -0
  27. package/src/Snapshot.d.ts +116 -0
  28. package/src/Snapshot.js +187 -0
  29. package/src/Snapshot.js.map +1 -0
  30. package/src/Volume.d.ts +79 -0
  31. package/src/Volume.js +97 -0
  32. package/src/Volume.js.map +1 -0
  33. package/src/code-toolbox/SandboxPythonCodeToolbox.d.ts +11 -0
  34. package/src/code-toolbox/SandboxPythonCodeToolbox.js +358 -0
  35. package/src/code-toolbox/SandboxPythonCodeToolbox.js.map +1 -0
  36. package/src/code-toolbox/SandboxTsCodeToolbox.d.ts +5 -0
  37. package/src/code-toolbox/SandboxTsCodeToolbox.js +17 -0
  38. package/src/code-toolbox/SandboxTsCodeToolbox.js.map +1 -0
  39. package/src/errors/DaytonaError.d.ts +10 -0
  40. package/src/errors/DaytonaError.js +20 -0
  41. package/src/errors/DaytonaError.js.map +1 -0
  42. package/src/index.d.ts +15 -0
  43. package/src/index.js +32 -0
  44. package/src/index.js.map +1 -0
  45. package/src/types/Charts.d.ts +151 -0
  46. package/src/types/Charts.js +46 -0
  47. package/src/types/Charts.js.map +1 -0
  48. package/src/types/ExecuteResponse.d.ts +26 -0
  49. package/src/types/ExecuteResponse.js +7 -0
  50. package/src/types/ExecuteResponse.js.map +1 -0
  51. package/src/utils/ArtifactParser.d.ts +13 -0
  52. package/src/utils/ArtifactParser.js +55 -0
  53. package/src/utils/ArtifactParser.js.map +1 -0
  54. package/src/utils/Path.d.ts +1 -0
  55. package/src/utils/Path.js +61 -0
  56. package/src/utils/Path.js.map +1 -0
  57. package/src/utils/Stream.d.ts +13 -0
  58. package/src/utils/Stream.js +82 -0
  59. package/src/utils/Stream.js.map +1 -0
@@ -0,0 +1,231 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2025 Daytona Platforms Inc.
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
19
+ }) : function(o, v) {
20
+ o["default"] = v;
21
+ });
22
+ var __importStar = (this && this.__importStar) || (function () {
23
+ var ownKeys = function(o) {
24
+ ownKeys = Object.getOwnPropertyNames || function (o) {
25
+ var ar = [];
26
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
27
+ return ar;
28
+ };
29
+ return ownKeys(o);
30
+ };
31
+ return function (mod) {
32
+ if (mod && mod.__esModule) return mod;
33
+ var result = {};
34
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
35
+ __setModuleDefault(result, mod);
36
+ return result;
37
+ };
38
+ })();
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.ObjectStorage = void 0;
41
+ const client_s3_1 = require("@aws-sdk/client-s3");
42
+ const lib_storage_1 = require("@aws-sdk/lib-storage");
43
+ const crypto = __importStar(require("crypto"));
44
+ const fs = __importStar(require("fs"));
45
+ const path = __importStar(require("path"));
46
+ const tar = __importStar(require("tar"));
47
+ const stream_1 = require("stream");
48
+ const DaytonaError_1 = require("./errors/DaytonaError");
49
+ /**
50
+ * ObjectStorage class for interacting with object storage services.
51
+ *
52
+ * @class
53
+ * @param {ObjectStorageConfig} config - The configuration for the object storage service.
54
+ */
55
+ class ObjectStorage {
56
+ bucketName;
57
+ s3Client;
58
+ constructor(config) {
59
+ this.bucketName = config.bucketName || 'daytona-volume-builds';
60
+ this.s3Client = new client_s3_1.S3Client({
61
+ region: this.extractAwsRegion(config.endpointUrl) || 'us-east-1',
62
+ endpoint: config.endpointUrl,
63
+ credentials: {
64
+ accessKeyId: config.accessKeyId,
65
+ secretAccessKey: config.secretAccessKey,
66
+ sessionToken: config.sessionToken,
67
+ },
68
+ forcePathStyle: true,
69
+ });
70
+ }
71
+ /**
72
+ * Upload a file or directory to object storage.
73
+ *
74
+ * @param {string} path - The path to the file or directory to upload.
75
+ * @param {string} organizationId - The organization ID to use for the upload.
76
+ * @param {string} [archiveBasePath] - The base path to use for the archive.
77
+ * @returns {Promise<string>} The hash of the uploaded file or directory.
78
+ */
79
+ async upload(path, organizationId, archiveBasePath) {
80
+ if (!fs.existsSync(path)) {
81
+ const errMsg = `Path does not exist: ${path}`;
82
+ throw new DaytonaError_1.DaytonaError(errMsg);
83
+ }
84
+ // Compute hash for the path
85
+ const pathHash = await this.computeHashForPathMd5(path, archiveBasePath);
86
+ // Define the S3 prefix
87
+ const prefix = `${organizationId}/${pathHash}/`;
88
+ const s3Key = `${prefix}context.tar`;
89
+ // Check if it already exists in S3
90
+ if (await this.folderExistsInS3(prefix)) {
91
+ return pathHash;
92
+ }
93
+ // Upload to S3
94
+ await this.uploadAsTar(s3Key, path, archiveBasePath);
95
+ return pathHash;
96
+ }
97
+ /**
98
+ * Compute a hash for a file or directory.
99
+ *
100
+ * @param {string} pathStr - The path to the file or directory to hash.
101
+ * @param {string} [archiveBasePath] - The base path to use for the archive.
102
+ * @returns {Promise<string>} The hash of the file or directory.
103
+ */
104
+ async computeHashForPathMd5(pathStr, archiveBasePath) {
105
+ const md5Hasher = crypto.createHash('md5');
106
+ const absPathStr = path.resolve(pathStr);
107
+ if (!archiveBasePath) {
108
+ archiveBasePath = ObjectStorage.computeArchiveBasePath(pathStr);
109
+ }
110
+ md5Hasher.update(archiveBasePath);
111
+ if (fs.statSync(absPathStr).isFile()) {
112
+ // For files, hash the content
113
+ await this.hashFile(absPathStr, md5Hasher);
114
+ }
115
+ else {
116
+ // For directories, recursively hash all files and their paths
117
+ await this.hashDirectory(absPathStr, pathStr, md5Hasher);
118
+ }
119
+ return md5Hasher.digest('hex');
120
+ }
121
+ /**
122
+ * Recursively hash a directory and its contents.
123
+ *
124
+ * @param {string} dirPath - The path to the directory to hash.
125
+ * @param {string} basePath - The base path to use for the hash.
126
+ * @param {crypto.Hash} hasher - The hasher to use for the hash.
127
+ * @returns {Promise<void>} A promise that resolves when the directory has been hashed.
128
+ */
129
+ async hashDirectory(dirPath, basePath, hasher) {
130
+ const entries = fs.readdirSync(dirPath, { withFileTypes: true });
131
+ const hasSubdirs = entries.some((e) => e.isDirectory());
132
+ const hasFiles = entries.some((e) => e.isFile());
133
+ if (!hasSubdirs && !hasFiles) {
134
+ // Empty directory
135
+ const relDir = path.relative(basePath, dirPath);
136
+ hasher.update(relDir);
137
+ }
138
+ for (const entry of entries) {
139
+ const fullPath = path.join(dirPath, entry.name);
140
+ if (entry.isDirectory()) {
141
+ await this.hashDirectory(fullPath, basePath, hasher);
142
+ }
143
+ else if (entry.isFile()) {
144
+ const relPath = path.relative(basePath, fullPath);
145
+ hasher.update(relPath);
146
+ await this.hashFile(fullPath, hasher);
147
+ }
148
+ }
149
+ }
150
+ /**
151
+ * Hash a file.
152
+ *
153
+ * @param {string} filePath - The path to the file to hash.
154
+ * @param {crypto.Hash} hasher - The hasher to use for the hash.
155
+ * @returns {Promise<void>} A promise that resolves when the file has been hashed.
156
+ */
157
+ async hashFile(filePath, hasher) {
158
+ await new Promise((resolve, reject) => {
159
+ const stream = fs.createReadStream(filePath, { highWaterMark: 8192 });
160
+ stream.on('data', (chunk) => hasher.update(chunk));
161
+ stream.on('end', resolve);
162
+ stream.on('error', reject);
163
+ });
164
+ }
165
+ /**
166
+ * Check if a prefix (folder) exists in S3.
167
+ *
168
+ * @param {string} prefix - The prefix to check.
169
+ * @returns {Promise<boolean>} True if the prefix exists, false otherwise.
170
+ */
171
+ async folderExistsInS3(prefix) {
172
+ const response = await this.s3Client.send(new client_s3_1.ListObjectsV2Command({
173
+ Bucket: this.bucketName,
174
+ Prefix: prefix,
175
+ MaxKeys: 1,
176
+ }));
177
+ return !!response.Contents && response.Contents.length > 0;
178
+ }
179
+ /**
180
+ * Create a tar archive of the specified path and upload it to S3.
181
+ *
182
+ * @param {string} s3Key - The key to use for the uploaded file.
183
+ * @param {string} sourcePath - The path to the file or directory to upload.
184
+ * @param {string} [archiveBasePath] - The base path to use for the archive.
185
+ */
186
+ async uploadAsTar(s3Key, sourcePath, archiveBasePath) {
187
+ sourcePath = path.resolve(sourcePath);
188
+ archiveBasePath ??= ObjectStorage.computeArchiveBasePath(sourcePath);
189
+ const tarStream = tar.create({
190
+ cwd: path.dirname(sourcePath),
191
+ portable: true,
192
+ gzip: false,
193
+ prefix: archiveBasePath,
194
+ }, [sourcePath]);
195
+ const pass = new stream_1.PassThrough();
196
+ tarStream.pipe(pass);
197
+ const uploader = new lib_storage_1.Upload({
198
+ client: this.s3Client,
199
+ params: {
200
+ Bucket: this.bucketName,
201
+ Key: s3Key,
202
+ Body: pass,
203
+ },
204
+ });
205
+ await uploader.done();
206
+ }
207
+ extractAwsRegion(endpoint) {
208
+ const match = endpoint.match(/s3[.-]([a-z0-9-]+)\.amazonaws\.com/);
209
+ return match?.[1];
210
+ }
211
+ /**
212
+ * Compute the base path for an archive. Returns normalized path without the root (drive letter or leading slash).
213
+ *
214
+ * @param {string} pathStr - The path to compute the base path for.
215
+ * @returns {string} The base path for the archive.
216
+ */
217
+ static computeArchiveBasePath(pathStr) {
218
+ // Normalize the path to remove redundant segments
219
+ pathStr = path.normalize(pathStr);
220
+ // On Windows, path.parse().root includes the drive letter (e.g., 'C:\\')
221
+ const parsedPath = path.parse(pathStr);
222
+ const root = parsedPath.root;
223
+ // Remove the root (drive letter or leading slash) from the path
224
+ let pathWithoutRoot = pathStr.slice(root.length);
225
+ // Remove any leading slashes or backslashes
226
+ pathWithoutRoot = pathWithoutRoot.replace(/^[/\\]+/, '');
227
+ return pathWithoutRoot;
228
+ }
229
+ }
230
+ exports.ObjectStorage = ObjectStorage;
231
+ //# sourceMappingURL=ObjectStorage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ObjectStorage.js","sourceRoot":"","sources":["../../../../libs/sdk-typescript/src/ObjectStorage.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,kDAAmE;AACnE,sDAA6C;AAC7C,+CAAgC;AAChC,uCAAwB;AACxB,2CAA4B;AAC5B,yCAA0B;AAC1B,mCAAoC;AACpC,wDAAoD;AAoBpD;;;;;GAKG;AACH,MAAa,aAAa;IAChB,UAAU,CAAQ;IAClB,QAAQ,CAAU;IAE1B,YAAY,MAA2B;QACrC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,IA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GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;QAEjC,yEAAyE;QACzE,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;QACtC,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAA;QAE5B,gEAAgE;QAChE,IAAI,eAAe,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAEhD,4CAA4C;QAC5C,eAAe,GAAG,eAAe,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAA;QAExD,OAAO,eAAe,CAAA;IACxB,CAAC;CACF;AAhND,sCAgNC"}
@@ -0,0 +1,246 @@
1
+ import { Command, Session, SessionExecuteRequest, SessionExecuteResponse, ToolboxApi } from '@daytonaio/api-client';
2
+ import { SandboxCodeToolbox } from './Sandbox';
3
+ import { ExecuteResponse } from './types/ExecuteResponse';
4
+ /**
5
+ * Parameters for code execution.
6
+ */
7
+ export declare class CodeRunParams {
8
+ /**
9
+ * Command line arguments
10
+ */
11
+ argv?: string[];
12
+ /**
13
+ * Environment variables
14
+ */
15
+ env?: Record<string, string>;
16
+ }
17
+ /**
18
+ * Handles process and code execution within a Sandbox.
19
+ *
20
+ * @class
21
+ */
22
+ export declare class Process {
23
+ private readonly sandboxId;
24
+ private readonly codeToolbox;
25
+ private readonly toolboxApi;
26
+ private readonly getRootDir;
27
+ constructor(sandboxId: string, codeToolbox: SandboxCodeToolbox, toolboxApi: ToolboxApi, getRootDir: () => Promise<string>);
28
+ /**
29
+ * Executes a shell command in the Sandbox.
30
+ *
31
+ * @param {string} command - Shell command to execute
32
+ * @param {string} [cwd] - Working directory for command execution. If not specified, uses the Sandbox root directory.
33
+ * Default is the user's root directory.
34
+ * @param {Record<string, string>} [env] - Environment variables to set for the command
35
+ * @param {number} [timeout] - Maximum time in seconds to wait for the command to complete. 0 means wait indefinitely.
36
+ * @returns {Promise<ExecuteResponse>} Command execution results containing:
37
+ * - exitCode: The command's exit status
38
+ * - result: Standard output from the command
39
+ * - artifacts: ExecutionArtifacts object containing `stdout` (same as result) and `charts` (matplotlib charts metadata)
40
+ *
41
+ * @example
42
+ * // Simple command
43
+ * const response = await process.executeCommand('echo "Hello"');
44
+ * console.log(response.artifacts.stdout); // Prints: Hello
45
+ *
46
+ * @example
47
+ * // Command with working directory
48
+ * const result = await process.executeCommand('ls', 'workspace/src');
49
+ *
50
+ * @example
51
+ * // Command with timeout
52
+ * const result = await process.executeCommand('sleep 10', undefined, 5);
53
+ */
54
+ executeCommand(command: string, cwd?: string, env?: Record<string, string>, timeout?: number): Promise<ExecuteResponse>;
55
+ /**
56
+ * Executes code in the Sandbox using the appropriate language runtime.
57
+ *
58
+ * @param {string} code - Code to execute
59
+ * @param {CodeRunParams} params - Parameters for code execution
60
+ * @param {number} [timeout] - Maximum time in seconds to wait for execution to complete
61
+ * @returns {Promise<ExecuteResponse>} Code execution results containing:
62
+ * - exitCode: The execution's exit status
63
+ * - result: Standard output from the code
64
+ * - artifacts: ExecutionArtifacts object containing `stdout` (same as result) and `charts` (matplotlib charts metadata)
65
+ *
66
+ * @example
67
+ * // Run TypeScript code
68
+ * const response = await process.codeRun(`
69
+ * const x = 10;
70
+ * const y = 20;
71
+ * console.log(\`Sum: \${x + y}\`);
72
+ * `);
73
+ * console.log(response.artifacts.stdout); // Prints: Sum: 30
74
+ *
75
+ * @example
76
+ * // Run Python code with matplotlib
77
+ * const response = await process.codeRun(`
78
+ * import matplotlib.pyplot as plt
79
+ * import numpy as np
80
+ *
81
+ * x = np.linspace(0, 10, 30)
82
+ * y = np.sin(x)
83
+ *
84
+ * plt.figure(figsize=(8, 5))
85
+ * plt.plot(x, y, 'b-', linewidth=2)
86
+ * plt.title('Line Chart')
87
+ * plt.xlabel('X-axis (seconds)')
88
+ * plt.ylabel('Y-axis (amplitude)')
89
+ * plt.grid(True)
90
+ * plt.show()
91
+ * `);
92
+ *
93
+ * if (response.artifacts?.charts) {
94
+ * const chart = response.artifacts.charts[0];
95
+ *
96
+ * console.log(`Type: ${chart.type}`);
97
+ * console.log(`Title: ${chart.title}`);
98
+ * if (chart.type === ChartType.LINE) {
99
+ * const lineChart = chart as LineChart
100
+ * console.log('X Label:', lineChart.x_label)
101
+ * console.log('Y Label:', lineChart.y_label)
102
+ * console.log('X Ticks:', lineChart.x_ticks)
103
+ * console.log('Y Ticks:', lineChart.y_ticks)
104
+ * console.log('X Tick Labels:', lineChart.x_tick_labels)
105
+ * console.log('Y Tick Labels:', lineChart.y_tick_labels)
106
+ * console.log('X Scale:', lineChart.x_scale)
107
+ * console.log('Y Scale:', lineChart.y_scale)
108
+ * console.log('Elements:')
109
+ * console.dir(lineChart.elements, { depth: null })
110
+ * }
111
+ * }
112
+ */
113
+ codeRun(code: string, params?: CodeRunParams, timeout?: number): Promise<ExecuteResponse>;
114
+ /**
115
+ * Creates a new long-running background session in the Sandbox.
116
+ *
117
+ * Sessions are background processes that maintain state between commands, making them ideal for
118
+ * scenarios requiring multiple related commands or persistent environment setup. You can run
119
+ * long-running commands and monitor process status.
120
+ *
121
+ * @param {string} sessionId - Unique identifier for the new session
122
+ * @returns {Promise<void>}
123
+ *
124
+ * @example
125
+ * // Create a new session
126
+ * const sessionId = 'my-session';
127
+ * await process.createSession(sessionId);
128
+ * const session = await process.getSession(sessionId);
129
+ * // Do work...
130
+ * await process.deleteSession(sessionId);
131
+ */
132
+ createSession(sessionId: string): Promise<void>;
133
+ /**
134
+ * Get a session in the sandbox.
135
+ *
136
+ * @param {string} sessionId - Unique identifier of the session to retrieve
137
+ * @returns {Promise<Session>} Session information including:
138
+ * - sessionId: The session's unique identifier
139
+ * - commands: List of commands executed in the session
140
+ *
141
+ * @example
142
+ * const session = await process.getSession('my-session');
143
+ * session.commands.forEach(cmd => {
144
+ * console.log(`Command: ${cmd.command}`);
145
+ * });
146
+ */
147
+ getSession(sessionId: string): Promise<Session>;
148
+ /**
149
+ * Gets information about a specific command executed in a session.
150
+ *
151
+ * @param {string} sessionId - Unique identifier of the session
152
+ * @param {string} commandId - Unique identifier of the command
153
+ * @returns {Promise<Command>} Command information including:
154
+ * - id: The command's unique identifier
155
+ * - command: The executed command string
156
+ * - exitCode: Command's exit status (if completed)
157
+ *
158
+ * @example
159
+ * const cmd = await process.getSessionCommand('my-session', 'cmd-123');
160
+ * if (cmd.exitCode === 0) {
161
+ * console.log(`Command ${cmd.command} completed successfully`);
162
+ * }
163
+ */
164
+ getSessionCommand(sessionId: string, commandId: string): Promise<Command>;
165
+ /**
166
+ * Executes a command in an existing session.
167
+ *
168
+ * @param {string} sessionId - Unique identifier of the session to use
169
+ * @param {SessionExecuteRequest} req - Command execution request containing:
170
+ * - command: The command to execute
171
+ * - runAsync: Whether to execute asynchronously
172
+ * @param {number} timeout - Timeout in seconds
173
+ * @returns {Promise<SessionExecuteResponse>} Command execution results containing:
174
+ * - cmdId: Unique identifier for the executed command
175
+ * - output: Command output (if synchronous execution)
176
+ * - exitCode: Command exit status (if synchronous execution)
177
+ *
178
+ * @example
179
+ * // Execute commands in sequence, maintaining state
180
+ * const sessionId = 'my-session';
181
+ *
182
+ * // Change directory
183
+ * await process.executeSessionCommand(sessionId, {
184
+ * command: 'cd /home/daytona'
185
+ * });
186
+ *
187
+ * // Run command in new directory
188
+ * const result = await process.executeSessionCommand(sessionId, {
189
+ * command: 'pwd'
190
+ * });
191
+ * console.log(result.output); // Prints: /home/daytona
192
+ */
193
+ executeSessionCommand(sessionId: string, req: SessionExecuteRequest, timeout?: number): Promise<SessionExecuteResponse>;
194
+ /**
195
+ * Get the logs for a command executed in a session.
196
+ *
197
+ * @param {string} sessionId - Unique identifier of the session
198
+ * @param {string} commandId - Unique identifier of the command
199
+ * @returns {Promise<string>} Command logs
200
+ *
201
+ * @example
202
+ * const logs = await process.getSessionCommandLogs('my-session', 'cmd-123');
203
+ * console.log('Command output:', logs);
204
+ */
205
+ getSessionCommandLogs(sessionId: string, commandId: string): Promise<string>;
206
+ /**
207
+ * Asynchronously retrieve and process the logs for a command executed in a session as they become available.
208
+ *
209
+ * @param {string} sessionId - Unique identifier of the session
210
+ * @param {string} commandId - Unique identifier of the command
211
+ * @param {function} onLogs - Callback function to handle each log chunk
212
+ * @returns {Promise<void>}
213
+ *
214
+ * @example
215
+ * const logs = await process.getSessionCommandLogs('my-session', 'cmd-123', (chunk) => {
216
+ * console.log('Log chunk:', chunk);
217
+ * });
218
+ */
219
+ getSessionCommandLogs(sessionId: string, commandId: string, onLogs: (chunk: string) => void): Promise<void>;
220
+ /**
221
+ * Lists all active sessions in the Sandbox.
222
+ *
223
+ * @returns {Promise<Session[]>} Array of active sessions
224
+ *
225
+ * @example
226
+ * const sessions = await process.listSessions();
227
+ * sessions.forEach(session => {
228
+ * console.log(`Session ${session.sessionId}:`);
229
+ * session.commands.forEach(cmd => {
230
+ * console.log(`- ${cmd.command} (${cmd.exitCode})`);
231
+ * });
232
+ * });
233
+ */
234
+ listSessions(): Promise<Session[]>;
235
+ /**
236
+ * Delete a session from the Sandbox.
237
+ *
238
+ * @param {string} sessionId - Unique identifier of the session to delete
239
+ * @returns {Promise<void>}
240
+ *
241
+ * @example
242
+ * // Clean up a completed session
243
+ * await process.deleteSession('my-session');
244
+ */
245
+ deleteSession(sessionId: string): Promise<void>;
246
+ }