@daytonaio/sdk 0.175.0 → 0.178.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/cjs/CodeInterpreter.d.ts +3 -2
  2. package/cjs/CodeInterpreter.js.map +1 -1
  3. package/cjs/ComputerUse.d.ts +104 -2
  4. package/cjs/ComputerUse.js +851 -763
  5. package/cjs/ComputerUse.js.map +1 -1
  6. package/cjs/Daytona.d.ts +4 -3
  7. package/cjs/Daytona.js +429 -443
  8. package/cjs/Daytona.js.map +1 -1
  9. package/cjs/FileSystem.d.ts +2 -2
  10. package/cjs/FileSystem.js +491 -521
  11. package/cjs/FileSystem.js.map +1 -1
  12. package/cjs/Git.d.ts +2 -1
  13. package/cjs/Git.js +287 -310
  14. package/cjs/Git.js.map +1 -1
  15. package/cjs/LspServer.d.ts +2 -1
  16. package/cjs/LspServer.js +209 -226
  17. package/cjs/LspServer.js.map +1 -1
  18. package/cjs/ObjectStorage.js +170 -166
  19. package/cjs/ObjectStorage.js.map +1 -1
  20. package/cjs/Process.d.ts +4 -3
  21. package/cjs/Process.js +562 -600
  22. package/cjs/Process.js.map +1 -1
  23. package/cjs/PtyHandle.d.ts +2 -2
  24. package/cjs/PtyHandle.js +327 -338
  25. package/cjs/PtyHandle.js.map +1 -1
  26. package/cjs/Sandbox.d.ts +4 -3
  27. package/cjs/Sandbox.js +756 -821
  28. package/cjs/Sandbox.js.map +1 -1
  29. package/cjs/Snapshot.d.ts +3 -2
  30. package/cjs/Snapshot.js +203 -213
  31. package/cjs/Snapshot.js.map +1 -1
  32. package/cjs/Volume.d.ts +2 -1
  33. package/cjs/Volume.js +90 -92
  34. package/cjs/Volume.js.map +1 -1
  35. package/cjs/errors/DaytonaError.d.ts +2 -1
  36. package/cjs/errors/DaytonaError.js.map +1 -1
  37. package/cjs/index.d.ts +2 -2
  38. package/cjs/index.js +2 -1
  39. package/cjs/index.js.map +1 -1
  40. package/cjs/types/CodeInterpreter.d.ts +1 -1
  41. package/cjs/utils/Binary.js +14 -2
  42. package/cjs/utils/Binary.js.map +1 -1
  43. package/cjs/utils/otel.decorator.d.ts +7 -8
  44. package/cjs/utils/otel.decorator.js +24 -30
  45. package/cjs/utils/otel.decorator.js.map +1 -1
  46. package/esm/CodeInterpreter.d.ts +3 -2
  47. package/esm/CodeInterpreter.js.map +1 -1
  48. package/esm/ComputerUse.d.ts +104 -2
  49. package/esm/ComputerUse.js +857 -763
  50. package/esm/ComputerUse.js.map +1 -1
  51. package/esm/Daytona.d.ts +4 -3
  52. package/esm/Daytona.js +431 -444
  53. package/esm/Daytona.js.map +1 -1
  54. package/esm/FileSystem.d.ts +2 -2
  55. package/esm/FileSystem.js +493 -522
  56. package/esm/FileSystem.js.map +1 -1
  57. package/esm/Git.d.ts +2 -1
  58. package/esm/Git.js +289 -311
  59. package/esm/Git.js.map +1 -1
  60. package/esm/LspServer.d.ts +2 -1
  61. package/esm/LspServer.js +211 -227
  62. package/esm/LspServer.js.map +1 -1
  63. package/esm/ObjectStorage.js +172 -167
  64. package/esm/ObjectStorage.js.map +1 -1
  65. package/esm/Process.d.ts +4 -3
  66. package/esm/Process.js +564 -601
  67. package/esm/Process.js.map +1 -1
  68. package/esm/PtyHandle.d.ts +2 -2
  69. package/esm/PtyHandle.js +329 -339
  70. package/esm/PtyHandle.js.map +1 -1
  71. package/esm/Sandbox.d.ts +4 -3
  72. package/esm/Sandbox.js +759 -823
  73. package/esm/Sandbox.js.map +1 -1
  74. package/esm/Snapshot.d.ts +3 -2
  75. package/esm/Snapshot.js +206 -215
  76. package/esm/Snapshot.js.map +1 -1
  77. package/esm/Volume.d.ts +2 -1
  78. package/esm/Volume.js +92 -93
  79. package/esm/Volume.js.map +1 -1
  80. package/esm/errors/DaytonaError.d.ts +2 -1
  81. package/esm/errors/DaytonaError.js.map +1 -1
  82. package/esm/index.d.ts +2 -2
  83. package/esm/index.js +1 -1
  84. package/esm/index.js.map +1 -1
  85. package/esm/types/CodeInterpreter.d.ts +1 -1
  86. package/esm/utils/Binary.js +14 -2
  87. package/esm/utils/Binary.js.map +1 -1
  88. package/esm/utils/otel.decorator.d.ts +7 -8
  89. package/esm/utils/otel.decorator.js +26 -32
  90. package/esm/utils/otel.decorator.js.map +1 -1
  91. package/package.json +3 -3
package/cjs/Process.js CHANGED
@@ -34,614 +34,576 @@ exports.CodeRunParams = CodeRunParams;
34
34
  *
35
35
  * @class
36
36
  */
37
- class Process {
38
- clientConfig;
39
- apiClient;
40
- getPreviewToken;
41
- language;
42
- constructor(clientConfig, apiClient, getPreviewToken, language) {
43
- this.clientConfig = clientConfig;
44
- this.apiClient = apiClient;
45
- this.getPreviewToken = getPreviewToken;
46
- this.language = language;
47
- }
48
- /**
49
- * Executes a shell command in the Sandbox.
50
- *
51
- * @param {string} command - Shell command to execute
52
- * @param {string} [cwd] - Working directory for command execution. If not specified, uses the sandbox working directory.
53
- * @param {Record<string, string>} [env] - Environment variables to set for the command
54
- * @param {number} [timeout] - Maximum time in seconds to wait for the command to complete.
55
- * @returns {Promise<ExecuteResponse>} Command execution results containing:
56
- * - exitCode: The command's exit status
57
- * - result: Standard output from the command
58
- * - artifacts: ExecutionArtifacts object containing `stdout` (same as result) and `charts` (matplotlib charts metadata)
59
- *
60
- * @example
61
- * // Simple command
62
- * const response = await process.executeCommand('echo "Hello"');
63
- * console.log(response.artifacts.stdout); // Prints: Hello
64
- *
65
- * @example
66
- * // Command with working directory
67
- * const result = await process.executeCommand('ls', 'workspace/src');
68
- *
69
- * @example
70
- * // Command with timeout
71
- * const result = await process.executeCommand('sleep 10', undefined, 5);
72
- */
73
- async executeCommand(command, cwd, env, timeout) {
74
- const response = await this.apiClient.executeCommand({
75
- command,
76
- timeout,
77
- cwd: cwd,
78
- envs: env && Object.keys(env).length ? env : undefined,
79
- });
80
- const result = response.data.result ?? '';
81
- return {
82
- exitCode: response.data.exitCode ?? response.data.code,
83
- result,
84
- artifacts: {
85
- stdout: result,
86
- },
87
- };
88
- }
89
- /**
90
- * Executes code in the Sandbox using the appropriate language runtime.
91
- *
92
- * @param {string} code - Code to execute
93
- * @param {CodeRunParams} params - Parameters for code execution
94
- * @param {number} [timeout] - Maximum time in seconds to wait for execution to complete
95
- * @returns {Promise<ExecuteResponse>} Code execution results containing:
96
- * - exitCode: The execution's exit status
97
- * - result: Standard output from the code
98
- * - artifacts: ExecutionArtifacts object containing `stdout` (same as result) and `charts` (matplotlib charts metadata)
99
- *
100
- * @example
101
- * // Run TypeScript code
102
- * const response = await process.codeRun(`
103
- * const x = 10;
104
- * const y = 20;
105
- * console.log(\`Sum: \${x + y}\`);
106
- * `);
107
- * console.log(response.artifacts.stdout); // Prints: Sum: 30
108
- *
109
- * @example
110
- * // Run Python code with matplotlib
111
- * const response = await process.codeRun(`
112
- * import matplotlib.pyplot as plt
113
- * import numpy as np
114
- *
115
- * x = np.linspace(0, 10, 30)
116
- * y = np.sin(x)
117
- *
118
- * plt.figure(figsize=(8, 5))
119
- * plt.plot(x, y, 'b-', linewidth=2)
120
- * plt.title('Line Chart')
121
- * plt.xlabel('X-axis (seconds)')
122
- * plt.ylabel('Y-axis (amplitude)')
123
- * plt.grid(True)
124
- * plt.show()
125
- * `);
126
- *
127
- * if (response.artifacts?.charts) {
128
- * const chart = response.artifacts.charts[0];
129
- *
130
- * console.log(`Type: ${chart.type}`);
131
- * console.log(`Title: ${chart.title}`);
132
- * if (chart.type === ChartType.LINE) {
133
- * const lineChart = chart as LineChart
134
- * console.log('X Label:', lineChart.x_label)
135
- * console.log('Y Label:', lineChart.y_label)
136
- * console.log('X Ticks:', lineChart.x_ticks)
137
- * console.log('Y Ticks:', lineChart.y_ticks)
138
- * console.log('X Tick Labels:', lineChart.x_tick_labels)
139
- * console.log('Y Tick Labels:', lineChart.y_tick_labels)
140
- * console.log('X Scale:', lineChart.x_scale)
141
- * console.log('Y Scale:', lineChart.y_scale)
142
- * console.log('Elements:')
143
- * console.dir(lineChart.elements, { depth: null })
144
- * }
145
- * }
146
- */
147
- async codeRun(code, params, timeout) {
148
- if (!this.language) {
149
- throw new Error('Code language is required for codeRun');
37
+ let Process = (() => {
38
+ let _instanceExtraInitializers = [];
39
+ let _executeCommand_decorators;
40
+ let _codeRun_decorators;
41
+ let _createSession_decorators;
42
+ let _getSessionCommand_decorators;
43
+ let _executeSessionCommand_decorators;
44
+ let _getSessionCommandLogs_decorators;
45
+ let _getEntrypointLogs_decorators;
46
+ let _listSessions_decorators;
47
+ let _deleteSession_decorators;
48
+ let _createPty_decorators;
49
+ let _connectPty_decorators;
50
+ let _listPtySessions_decorators;
51
+ let _getPtySessionInfo_decorators;
52
+ let _killPtySession_decorators;
53
+ let _resizePtySession_decorators;
54
+ return class Process {
55
+ static {
56
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
57
+ _executeCommand_decorators = [(0, otel_decorator_1.WithInstrumentation)()];
58
+ _codeRun_decorators = [(0, otel_decorator_1.WithInstrumentation)()];
59
+ _createSession_decorators = [(0, otel_decorator_1.WithInstrumentation)()];
60
+ _getSessionCommand_decorators = [(0, otel_decorator_1.WithInstrumentation)()];
61
+ _executeSessionCommand_decorators = [(0, otel_decorator_1.WithInstrumentation)()];
62
+ _getSessionCommandLogs_decorators = [(0, otel_decorator_1.WithInstrumentation)()];
63
+ _getEntrypointLogs_decorators = [(0, otel_decorator_1.WithInstrumentation)()];
64
+ _listSessions_decorators = [(0, otel_decorator_1.WithInstrumentation)()];
65
+ _deleteSession_decorators = [(0, otel_decorator_1.WithInstrumentation)()];
66
+ _createPty_decorators = [(0, otel_decorator_1.WithInstrumentation)()];
67
+ _connectPty_decorators = [(0, otel_decorator_1.WithInstrumentation)()];
68
+ _listPtySessions_decorators = [(0, otel_decorator_1.WithInstrumentation)()];
69
+ _getPtySessionInfo_decorators = [(0, otel_decorator_1.WithInstrumentation)()];
70
+ _killPtySession_decorators = [(0, otel_decorator_1.WithInstrumentation)()];
71
+ _resizePtySession_decorators = [(0, otel_decorator_1.WithInstrumentation)()];
72
+ tslib_1.__esDecorate(this, null, _executeCommand_decorators, { kind: "method", name: "executeCommand", static: false, private: false, access: { has: obj => "executeCommand" in obj, get: obj => obj.executeCommand }, metadata: _metadata }, null, _instanceExtraInitializers);
73
+ tslib_1.__esDecorate(this, null, _codeRun_decorators, { kind: "method", name: "codeRun", static: false, private: false, access: { has: obj => "codeRun" in obj, get: obj => obj.codeRun }, metadata: _metadata }, null, _instanceExtraInitializers);
74
+ tslib_1.__esDecorate(this, null, _createSession_decorators, { kind: "method", name: "createSession", static: false, private: false, access: { has: obj => "createSession" in obj, get: obj => obj.createSession }, metadata: _metadata }, null, _instanceExtraInitializers);
75
+ tslib_1.__esDecorate(this, null, _getSessionCommand_decorators, { kind: "method", name: "getSessionCommand", static: false, private: false, access: { has: obj => "getSessionCommand" in obj, get: obj => obj.getSessionCommand }, metadata: _metadata }, null, _instanceExtraInitializers);
76
+ tslib_1.__esDecorate(this, null, _executeSessionCommand_decorators, { kind: "method", name: "executeSessionCommand", static: false, private: false, access: { has: obj => "executeSessionCommand" in obj, get: obj => obj.executeSessionCommand }, metadata: _metadata }, null, _instanceExtraInitializers);
77
+ tslib_1.__esDecorate(this, null, _getSessionCommandLogs_decorators, { kind: "method", name: "getSessionCommandLogs", static: false, private: false, access: { has: obj => "getSessionCommandLogs" in obj, get: obj => obj.getSessionCommandLogs }, metadata: _metadata }, null, _instanceExtraInitializers);
78
+ tslib_1.__esDecorate(this, null, _getEntrypointLogs_decorators, { kind: "method", name: "getEntrypointLogs", static: false, private: false, access: { has: obj => "getEntrypointLogs" in obj, get: obj => obj.getEntrypointLogs }, metadata: _metadata }, null, _instanceExtraInitializers);
79
+ tslib_1.__esDecorate(this, null, _listSessions_decorators, { kind: "method", name: "listSessions", static: false, private: false, access: { has: obj => "listSessions" in obj, get: obj => obj.listSessions }, metadata: _metadata }, null, _instanceExtraInitializers);
80
+ tslib_1.__esDecorate(this, null, _deleteSession_decorators, { kind: "method", name: "deleteSession", static: false, private: false, access: { has: obj => "deleteSession" in obj, get: obj => obj.deleteSession }, metadata: _metadata }, null, _instanceExtraInitializers);
81
+ tslib_1.__esDecorate(this, null, _createPty_decorators, { kind: "method", name: "createPty", static: false, private: false, access: { has: obj => "createPty" in obj, get: obj => obj.createPty }, metadata: _metadata }, null, _instanceExtraInitializers);
82
+ tslib_1.__esDecorate(this, null, _connectPty_decorators, { kind: "method", name: "connectPty", static: false, private: false, access: { has: obj => "connectPty" in obj, get: obj => obj.connectPty }, metadata: _metadata }, null, _instanceExtraInitializers);
83
+ tslib_1.__esDecorate(this, null, _listPtySessions_decorators, { kind: "method", name: "listPtySessions", static: false, private: false, access: { has: obj => "listPtySessions" in obj, get: obj => obj.listPtySessions }, metadata: _metadata }, null, _instanceExtraInitializers);
84
+ tslib_1.__esDecorate(this, null, _getPtySessionInfo_decorators, { kind: "method", name: "getPtySessionInfo", static: false, private: false, access: { has: obj => "getPtySessionInfo" in obj, get: obj => obj.getPtySessionInfo }, metadata: _metadata }, null, _instanceExtraInitializers);
85
+ tslib_1.__esDecorate(this, null, _killPtySession_decorators, { kind: "method", name: "killPtySession", static: false, private: false, access: { has: obj => "killPtySession" in obj, get: obj => obj.killPtySession }, metadata: _metadata }, null, _instanceExtraInitializers);
86
+ tslib_1.__esDecorate(this, null, _resizePtySession_decorators, { kind: "method", name: "resizePtySession", static: false, private: false, access: { has: obj => "resizePtySession" in obj, get: obj => obj.resizePtySession }, metadata: _metadata }, null, _instanceExtraInitializers);
87
+ if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
150
88
  }
151
- const request = {
152
- code,
153
- language: this.language,
154
- argv: params?.argv,
155
- envs: params?.env,
156
- timeout,
157
- };
158
- const response = await this.apiClient.codeRun(request);
159
- const data = response.data;
160
- const charts = data.artifacts?.charts?.map(Charts_1.parseChart) ?? [];
161
- return {
162
- exitCode: data.exitCode ?? 0,
163
- result: data.result ?? '',
164
- artifacts: {
165
- stdout: data.result ?? '',
166
- charts,
167
- },
168
- };
169
- }
170
- /**
171
- * Creates a new long-running background session in the Sandbox.
172
- *
173
- * Sessions are background processes that maintain state between commands, making them ideal for
174
- * scenarios requiring multiple related commands or persistent environment setup. You can run
175
- * long-running commands and monitor process status.
176
- *
177
- * @param {string} sessionId - Unique identifier for the new session
178
- * @returns {Promise<void>}
179
- *
180
- * @example
181
- * // Create a new session
182
- * const sessionId = 'my-session';
183
- * await process.createSession(sessionId);
184
- * const session = await process.getSession(sessionId);
185
- * // Do work...
186
- * await process.deleteSession(sessionId);
187
- */
188
- async createSession(sessionId) {
189
- await this.apiClient.createSession({
190
- sessionId,
191
- });
192
- }
193
- /**
194
- * Get a session in the sandbox.
195
- *
196
- * @param {string} sessionId - Unique identifier of the session to retrieve
197
- * @returns {Promise<Session>} Session information including:
198
- * - sessionId: The session's unique identifier
199
- * - commands: List of commands executed in the session
200
- *
201
- * @example
202
- * const session = await process.getSession('my-session');
203
- * session.commands.forEach(cmd => {
204
- * console.log(`Command: ${cmd.command}`);
205
- * });
206
- */
207
- async getSession(sessionId) {
208
- const response = await this.apiClient.getSession(sessionId);
209
- return response.data;
210
- }
211
- /**
212
- * Get the sandbox entrypoint session
213
- *
214
- * @returns {Promise<Session>} Entrypoint session information including:
215
- * - sessionId: The entrypoint session's unique identifier
216
- * - commands: List of commands executed in the entrypoint session
217
- *
218
- * @example
219
- * const session = await process.getEntrypointSession();
220
- * session.commands.forEach(cmd => {
221
- * console.log(`Command: ${cmd.command}`);
222
- * });
223
- */
224
- async getEntrypointSession() {
225
- const response = await this.apiClient.getEntrypointSession();
226
- return response.data;
227
- }
228
- /**
229
- * Gets information about a specific command executed in a session.
230
- *
231
- * @param {string} sessionId - Unique identifier of the session
232
- * @param {string} commandId - Unique identifier of the command
233
- * @returns {Promise<Command>} Command information including:
234
- * - id: The command's unique identifier
235
- * - command: The executed command string
236
- * - exitCode: Command's exit status (if completed)
237
- *
238
- * @example
239
- * const cmd = await process.getSessionCommand('my-session', 'cmd-123');
240
- * if (cmd.exitCode === 0) {
241
- * console.log(`Command ${cmd.command} completed successfully`);
242
- * }
243
- */
244
- async getSessionCommand(sessionId, commandId) {
245
- const response = await this.apiClient.getSessionCommand(sessionId, commandId);
246
- return response.data;
247
- }
248
- /**
249
- * Executes a command in an existing session.
250
- *
251
- * @param {string} sessionId - Unique identifier of the session to use
252
- * @param {SessionExecuteRequest} req - Command execution request containing:
253
- * - command: The command to execute
254
- * - runAsync: Whether to execute asynchronously
255
- * - suppressInputEcho: Whether to suppress input echo. Default is `false`.
256
- * @param {number} timeout - Timeout in seconds
257
- * @returns {Promise<SessionExecuteResponse>} Command execution results containing:
258
- * - cmdId: Unique identifier for the executed command
259
- * - output: Combined command output (stdout and stderr) (if synchronous execution)
260
- * - stdout: Standard output from the command
261
- * - stderr: Standard error from the command
262
- * - exitCode: Command exit status (if synchronous execution)
263
- *
264
- * @example
265
- * // Execute commands in sequence, maintaining state
266
- * const sessionId = 'my-session';
267
- *
268
- * // Change directory
269
- * await process.executeSessionCommand(sessionId, {
270
- * command: 'cd /home/daytona'
271
- * });
272
- *
273
- * // Run command in new directory
274
- * const result = await process.executeSessionCommand(sessionId, {
275
- * command: 'pwd'
276
- * });
277
- * console.log('[STDOUT]:', result.stdout);
278
- * console.log('[STDERR]:', result.stderr);
279
- */
280
- async executeSessionCommand(sessionId, req, timeout) {
281
- const response = await this.apiClient.sessionExecuteCommand(sessionId, req, timeout ? { timeout: timeout * 1000 } : {});
282
- return {
283
- ...response.data,
284
- stdout: response.data.stdout ?? '',
285
- stderr: response.data.stderr ?? '',
286
- };
287
- }
288
- async getSessionCommandLogs(sessionId, commandId, onStdout, onStderr) {
289
- if (!onStdout && !onStderr) {
290
- const response = await this.apiClient.getSessionCommandLogs(sessionId, commandId);
89
+ clientConfig = tslib_1.__runInitializers(this, _instanceExtraInitializers);
90
+ apiClient;
91
+ getPreviewToken;
92
+ language;
93
+ constructor(clientConfig, apiClient, getPreviewToken, language) {
94
+ this.clientConfig = clientConfig;
95
+ this.apiClient = apiClient;
96
+ this.getPreviewToken = getPreviewToken;
97
+ this.language = language;
98
+ }
99
+ /**
100
+ * Executes a shell command in the Sandbox.
101
+ *
102
+ * @param {string} command - Shell command to execute
103
+ * @param {string} [cwd] - Working directory for command execution. If not specified, uses the sandbox working directory.
104
+ * @param {Record<string, string>} [env] - Environment variables to set for the command
105
+ * @param {number} [timeout] - Maximum time in seconds to wait for the command to complete.
106
+ * @returns {Promise<ExecuteResponse>} Command execution results containing:
107
+ * - exitCode: The command's exit status
108
+ * - result: Standard output from the command
109
+ * - artifacts: ExecutionArtifacts object containing `stdout` (same as result) and `charts` (matplotlib charts metadata)
110
+ *
111
+ * @example
112
+ * // Simple command
113
+ * const response = await process.executeCommand('echo "Hello"');
114
+ * console.log(response.artifacts.stdout); // Prints: Hello
115
+ *
116
+ * @example
117
+ * // Command with working directory
118
+ * const result = await process.executeCommand('ls', 'workspace/src');
119
+ *
120
+ * @example
121
+ * // Command with timeout
122
+ * const result = await process.executeCommand('sleep 10', undefined, 5);
123
+ */
124
+ async executeCommand(command, cwd, env, timeout) {
125
+ const response = await this.apiClient.executeCommand({
126
+ command,
127
+ timeout,
128
+ cwd: cwd,
129
+ envs: env && Object.keys(env).length ? env : undefined,
130
+ });
131
+ const result = response.data.result ?? '';
291
132
  return {
292
- output: response.data.output ?? '',
293
- stdout: response.data.stdout ?? '',
294
- stderr: response.data.stderr ?? '',
133
+ exitCode: response.data.exitCode ?? response.data.code,
134
+ result,
135
+ artifacts: {
136
+ stdout: result,
137
+ },
138
+ };
139
+ }
140
+ /**
141
+ * Executes code in the Sandbox using the appropriate language runtime.
142
+ *
143
+ * @param {string} code - Code to execute
144
+ * @param {CodeRunParams} params - Parameters for code execution
145
+ * @param {number} [timeout] - Maximum time in seconds to wait for execution to complete
146
+ * @returns {Promise<ExecuteResponse>} Code execution results containing:
147
+ * - exitCode: The execution's exit status
148
+ * - result: Standard output from the code
149
+ * - artifacts: ExecutionArtifacts object containing `stdout` (same as result) and `charts` (matplotlib charts metadata)
150
+ *
151
+ * @example
152
+ * // Run TypeScript code
153
+ * const response = await process.codeRun(`
154
+ * const x = 10;
155
+ * const y = 20;
156
+ * console.log(\`Sum: \${x + y}\`);
157
+ * `);
158
+ * console.log(response.artifacts.stdout); // Prints: Sum: 30
159
+ *
160
+ * @example
161
+ * // Run Python code with matplotlib
162
+ * const response = await process.codeRun(`
163
+ * import matplotlib.pyplot as plt
164
+ * import numpy as np
165
+ *
166
+ * x = np.linspace(0, 10, 30)
167
+ * y = np.sin(x)
168
+ *
169
+ * plt.figure(figsize=(8, 5))
170
+ * plt.plot(x, y, 'b-', linewidth=2)
171
+ * plt.title('Line Chart')
172
+ * plt.xlabel('X-axis (seconds)')
173
+ * plt.ylabel('Y-axis (amplitude)')
174
+ * plt.grid(True)
175
+ * plt.show()
176
+ * `);
177
+ *
178
+ * if (response.artifacts?.charts) {
179
+ * const chart = response.artifacts.charts[0];
180
+ *
181
+ * console.log(`Type: ${chart.type}`);
182
+ * console.log(`Title: ${chart.title}`);
183
+ * if (chart.type === ChartType.LINE) {
184
+ * const lineChart = chart as LineChart
185
+ * console.log('X Label:', lineChart.x_label)
186
+ * console.log('Y Label:', lineChart.y_label)
187
+ * console.log('X Ticks:', lineChart.x_ticks)
188
+ * console.log('Y Ticks:', lineChart.y_ticks)
189
+ * console.log('X Tick Labels:', lineChart.x_tick_labels)
190
+ * console.log('Y Tick Labels:', lineChart.y_tick_labels)
191
+ * console.log('X Scale:', lineChart.x_scale)
192
+ * console.log('Y Scale:', lineChart.y_scale)
193
+ * console.log('Elements:')
194
+ * console.dir(lineChart.elements, { depth: null })
195
+ * }
196
+ * }
197
+ */
198
+ async codeRun(code, params, timeout) {
199
+ if (!this.language) {
200
+ throw new Error('Code language is required for codeRun');
201
+ }
202
+ const request = {
203
+ code,
204
+ language: this.language,
205
+ argv: params?.argv,
206
+ envs: params?.env,
207
+ timeout,
208
+ };
209
+ const response = await this.apiClient.codeRun(request);
210
+ const data = response.data;
211
+ const charts = data.artifacts?.charts?.map(Charts_1.parseChart) ?? [];
212
+ return {
213
+ exitCode: data.exitCode ?? 0,
214
+ result: data.result ?? '',
215
+ artifacts: {
216
+ stdout: data.result ?? '',
217
+ charts,
218
+ },
295
219
  };
296
220
  }
297
- const url = `${this.clientConfig.basePath.replace(/^http/, 'ws')}/process/session/${sessionId}/command/${commandId}/logs?follow=true`;
298
- const ws = await (0, WebSocket_1.createSandboxWebSocket)(url, this.clientConfig.baseOptions?.headers || {}, this.getPreviewToken);
299
- await (0, Stream_1.stdDemuxStream)(ws, onStdout, onStderr);
300
- }
301
- async getEntrypointLogs(onStdout, onStderr) {
302
- if (!onStdout && !onStderr) {
303
- const response = await this.apiClient.getEntrypointLogs();
221
+ /**
222
+ * Creates a new long-running background session in the Sandbox.
223
+ *
224
+ * Sessions are background processes that maintain state between commands, making them ideal for
225
+ * scenarios requiring multiple related commands or persistent environment setup. You can run
226
+ * long-running commands and monitor process status.
227
+ *
228
+ * @param {string} sessionId - Unique identifier for the new session
229
+ * @returns {Promise<void>}
230
+ *
231
+ * @example
232
+ * // Create a new session
233
+ * const sessionId = 'my-session';
234
+ * await process.createSession(sessionId);
235
+ * const session = await process.getSession(sessionId);
236
+ * // Do work...
237
+ * await process.deleteSession(sessionId);
238
+ */
239
+ async createSession(sessionId) {
240
+ await this.apiClient.createSession({
241
+ sessionId,
242
+ });
243
+ }
244
+ /**
245
+ * Get a session in the sandbox.
246
+ *
247
+ * @param {string} sessionId - Unique identifier of the session to retrieve
248
+ * @returns {Promise<Session>} Session information including:
249
+ * - sessionId: The session's unique identifier
250
+ * - commands: List of commands executed in the session
251
+ *
252
+ * @example
253
+ * const session = await process.getSession('my-session');
254
+ * session.commands.forEach(cmd => {
255
+ * console.log(`Command: ${cmd.command}`);
256
+ * });
257
+ */
258
+ async getSession(sessionId) {
259
+ const response = await this.apiClient.getSession(sessionId);
260
+ return response.data;
261
+ }
262
+ /**
263
+ * Get the sandbox entrypoint session
264
+ *
265
+ * @returns {Promise<Session>} Entrypoint session information including:
266
+ * - sessionId: The entrypoint session's unique identifier
267
+ * - commands: List of commands executed in the entrypoint session
268
+ *
269
+ * @example
270
+ * const session = await process.getEntrypointSession();
271
+ * session.commands.forEach(cmd => {
272
+ * console.log(`Command: ${cmd.command}`);
273
+ * });
274
+ */
275
+ async getEntrypointSession() {
276
+ const response = await this.apiClient.getEntrypointSession();
277
+ return response.data;
278
+ }
279
+ /**
280
+ * Gets information about a specific command executed in a session.
281
+ *
282
+ * @param {string} sessionId - Unique identifier of the session
283
+ * @param {string} commandId - Unique identifier of the command
284
+ * @returns {Promise<Command>} Command information including:
285
+ * - id: The command's unique identifier
286
+ * - command: The executed command string
287
+ * - exitCode: Command's exit status (if completed)
288
+ *
289
+ * @example
290
+ * const cmd = await process.getSessionCommand('my-session', 'cmd-123');
291
+ * if (cmd.exitCode === 0) {
292
+ * console.log(`Command ${cmd.command} completed successfully`);
293
+ * }
294
+ */
295
+ async getSessionCommand(sessionId, commandId) {
296
+ const response = await this.apiClient.getSessionCommand(sessionId, commandId);
297
+ return response.data;
298
+ }
299
+ /**
300
+ * Executes a command in an existing session.
301
+ *
302
+ * @param {string} sessionId - Unique identifier of the session to use
303
+ * @param {SessionExecuteRequest} req - Command execution request containing:
304
+ * - command: The command to execute
305
+ * - runAsync: Whether to execute asynchronously
306
+ * - suppressInputEcho: Whether to suppress input echo. Default is `false`.
307
+ * @param {number} timeout - Timeout in seconds
308
+ * @returns {Promise<SessionExecuteResponse>} Command execution results containing:
309
+ * - cmdId: Unique identifier for the executed command
310
+ * - output: Combined command output (stdout and stderr) (if synchronous execution)
311
+ * - stdout: Standard output from the command
312
+ * - stderr: Standard error from the command
313
+ * - exitCode: Command exit status (if synchronous execution)
314
+ *
315
+ * @example
316
+ * // Execute commands in sequence, maintaining state
317
+ * const sessionId = 'my-session';
318
+ *
319
+ * // Change directory
320
+ * await process.executeSessionCommand(sessionId, {
321
+ * command: 'cd /home/daytona'
322
+ * });
323
+ *
324
+ * // Run command in new directory
325
+ * const result = await process.executeSessionCommand(sessionId, {
326
+ * command: 'pwd'
327
+ * });
328
+ * console.log('[STDOUT]:', result.stdout);
329
+ * console.log('[STDERR]:', result.stderr);
330
+ */
331
+ async executeSessionCommand(sessionId, req, timeout) {
332
+ const response = await this.apiClient.sessionExecuteCommand(sessionId, req, timeout ? { timeout: timeout * 1000 } : {});
304
333
  return {
305
- output: response.data.output ?? '',
334
+ ...response.data,
306
335
  stdout: response.data.stdout ?? '',
307
336
  stderr: response.data.stderr ?? '',
308
337
  };
309
338
  }
310
- const url = `${this.clientConfig.basePath.replace(/^http/, 'ws')}/process/session/entrypoint/logs?follow=true`;
311
- const ws = await (0, WebSocket_1.createSandboxWebSocket)(url, this.clientConfig.baseOptions?.headers || {}, this.getPreviewToken);
312
- await (0, Stream_1.stdDemuxStream)(ws, onStdout, onStderr);
313
- }
314
- /**
315
- * Sends input data to a command executed in a session.
316
- *
317
- * @param {string} sessionId - Unique identifier of the session
318
- * @param {string} commandId - Unique identifier of the command
319
- * @param {string} data - Input data to send
320
- * @returns {Promise<void>}
321
- */
322
- async sendSessionCommandInput(sessionId, commandId, data) {
323
- await this.apiClient.sendInput(sessionId, commandId, { data });
324
- }
325
- /**
326
- * Lists all active sessions in the Sandbox.
327
- *
328
- * @returns {Promise<Session[]>} Array of active sessions
329
- *
330
- * @example
331
- * const sessions = await process.listSessions();
332
- * sessions.forEach(session => {
333
- * console.log(`Session ${session.sessionId}:`);
334
- * session.commands.forEach(cmd => {
335
- * console.log(`- ${cmd.command} (${cmd.exitCode})`);
336
- * });
337
- * });
338
- */
339
- async listSessions() {
340
- const response = await this.apiClient.listSessions();
341
- return response.data;
342
- }
343
- /**
344
- * Delete a session from the Sandbox.
345
- *
346
- * @param {string} sessionId - Unique identifier of the session to delete
347
- * @returns {Promise<void>}
348
- *
349
- * @example
350
- * // Clean up a completed session
351
- * await process.deleteSession('my-session');
352
- */
353
- async deleteSession(sessionId) {
354
- await this.apiClient.deleteSession(sessionId);
355
- }
356
- /**
357
- * Create a new PTY (pseudo-terminal) session in the sandbox.
358
- *
359
- * Creates an interactive terminal session that can execute commands and handle user input.
360
- * The PTY session behaves like a real terminal, supporting features like command history.
361
- *
362
- * @param {PtyCreateOptions & PtyConnectOptions} options - PTY session configuration including creation and connection options
363
- * @returns {Promise<PtyHandle>} PTY handle for managing the session
364
- *
365
- * @example
366
- * // Create a PTY session with custom configuration
367
- * const ptyHandle = await process.createPty({
368
- * id: 'my-interactive-session',
369
- * cwd: '/workspace',
370
- * envs: { TERM: 'xterm-256color', LANG: 'en_US.UTF-8' },
371
- * cols: 120,
372
- * rows: 30,
373
- * onData: (data) => {
374
- * // Handle terminal output
375
- * const text = new TextDecoder().decode(data);
376
- * process.stdout.write(text);
377
- * },
378
- * });
379
- *
380
- * // Wait for connection to be established
381
- * await ptyHandle.waitForConnection();
382
- *
383
- * // Send commands to the terminal
384
- * await ptyHandle.sendInput('ls -la\n');
385
- * await ptyHandle.sendInput('echo "Hello, PTY!"\n');
386
- * await ptyHandle.sendInput('exit\n');
387
- *
388
- * // Wait for completion and get result
389
- * const result = await ptyHandle.wait();
390
- * console.log(`PTY session completed with exit code: ${result.exitCode}`);
391
- *
392
- * // Clean up
393
- * await ptyHandle.disconnect();
394
- */
395
- async createPty(options) {
396
- const request = {
397
- id: options.id,
398
- cwd: options.cwd,
399
- envs: options.envs,
400
- cols: options.cols,
401
- rows: options.rows,
402
- lazyStart: true,
403
- };
404
- const response = await this.apiClient.createPtySession(request);
405
- return await this.connectPty(response.data.sessionId, options);
406
- }
407
- /**
408
- * Connect to an existing PTY session in the sandbox.
409
- *
410
- * Establishes a WebSocket connection to an existing PTY session, allowing you to
411
- * interact with a previously created terminal session.
412
- *
413
- * @param {string} sessionId - ID of the PTY session to connect to
414
- * @param {PtyConnectOptions} options - Options for the connection including data handler
415
- * @returns {Promise<PtyHandle>} PTY handle for managing the session
416
- *
417
- * @example
418
- * // Connect to an existing PTY session
419
- * const handle = await process.connectPty('my-session', {
420
- * onData: (data) => {
421
- * // Handle terminal output
422
- * const text = new TextDecoder().decode(data);
423
- * process.stdout.write(text);
424
- * },
425
- * });
426
- *
427
- * // Wait for connection to be established
428
- * await handle.waitForConnection();
429
- *
430
- * // Send commands to the existing session
431
- * await handle.sendInput('pwd\n');
432
- * await handle.sendInput('ls -la\n');
433
- * await handle.sendInput('exit\n');
434
- *
435
- * // Wait for completion
436
- * const result = await handle.wait();
437
- * console.log(`Session exited with code: ${result.exitCode}`);
438
- *
439
- * // Clean up
440
- * await handle.disconnect();
441
- */
442
- async connectPty(sessionId, options) {
443
- const url = `${this.clientConfig.basePath.replace(/^http/, 'ws')}/process/pty/${sessionId}/connect`;
444
- const ws = await (0, WebSocket_1.createSandboxWebSocket)(url, this.clientConfig.baseOptions?.headers || {}, this.getPreviewToken);
445
- const handle = new PtyHandle_1.PtyHandle(ws, (cols, rows) => this.resizePtySession(sessionId, cols, rows), () => this.killPtySession(sessionId), options.onData, sessionId);
446
- await handle.waitForConnection();
447
- return handle;
448
- }
449
- /**
450
- * List all PTY sessions in the sandbox.
451
- *
452
- * Retrieves information about all PTY sessions, both active and inactive,
453
- * that have been created in this sandbox.
454
- *
455
- * @returns {Promise<PtySessionInfo[]>} Array of PTY session information
456
- *
457
- * @example
458
- * // List all PTY sessions
459
- * const sessions = await process.listPtySessions();
460
- *
461
- * for (const session of sessions) {
462
- * console.log(`Session ID: ${session.id}`);
463
- * console.log(`Active: ${session.active}`);
464
- * console.log(`Created: ${session.createdAt}`);
465
- * }
466
- * console.log('---');
467
- * }
468
- */
469
- async listPtySessions() {
470
- return (await this.apiClient.listPtySessions()).data.sessions;
471
- }
472
- /**
473
- * Get detailed information about a specific PTY session.
474
- *
475
- * Retrieves comprehensive information about a PTY session including its current state,
476
- * configuration, and metadata.
477
- *
478
- * @param {string} sessionId - ID of the PTY session to retrieve information for
479
- * @returns {Promise<PtySessionInfo>} PTY session information
480
- *
481
- * @throws {Error} If the PTY session doesn't exist
482
- *
483
- * @example
484
- * // Get details about a specific PTY session
485
- * const session = await process.getPtySessionInfo('my-session');
486
- *
487
- * console.log(`Session ID: ${session.id}`);
488
- * console.log(`Active: ${session.active}`);
489
- * console.log(`Working Directory: ${session.cwd}`);
490
- * console.log(`Terminal Size: ${session.cols}x${session.rows}`);
491
- *
492
- * if (session.processId) {
493
- * console.log(`Process ID: ${session.processId}`);
494
- * }
495
- */
496
- async getPtySessionInfo(sessionId) {
497
- return (await this.apiClient.getPtySession(sessionId)).data;
498
- }
499
- /**
500
- * Kill a PTY session and terminate its associated process.
501
- *
502
- * Forcefully terminates the PTY session and cleans up all associated resources.
503
- * This will close any active connections and kill the underlying shell process.
504
- *
505
- * @param {string} sessionId - ID of the PTY session to kill
506
- * @returns {Promise<void>}
507
- *
508
- * @throws {Error} If the PTY session doesn't exist or cannot be killed
509
- *
510
- * @note This operation is irreversible. Any unsaved work in the terminal session will be lost.
511
- *
512
- * @example
513
- * // Kill a specific PTY session
514
- * await process.killPtySession('my-session');
515
- *
516
- * // Verify the session is no longer active
517
- * try {
518
- * const info = await process.getPtySessionInfo('my-session');
519
- * console.log(`Session still exists but active: ${info.active}`);
520
- * } catch (error) {
521
- * console.log('Session has been completely removed');
522
- * }
523
- */
524
- async killPtySession(sessionId) {
525
- await this.apiClient.deletePtySession(sessionId);
526
- }
527
- /**
528
- * Resize a PTY session's terminal dimensions.
529
- *
530
- * Changes the terminal size of an active PTY session. This is useful when the
531
- * client terminal is resized or when you need to adjust the display for different
532
- * output requirements.
533
- *
534
- * @param {string} sessionId - ID of the PTY session to resize
535
- * @param {number} cols - New number of terminal columns
536
- * @param {number} rows - New number of terminal rows
537
- * @returns {Promise<PtySessionInfo>} Updated session information reflecting the new terminal size
538
- *
539
- * @throws {Error} If the PTY session doesn't exist or resize operation fails
540
- *
541
- * @note The resize operation will send a SIGWINCH signal to the shell process,
542
- * allowing terminal applications to adapt to the new size.
543
- *
544
- * @example
545
- * // Resize a PTY session to a larger terminal
546
- * const updatedInfo = await process.resizePtySession('my-session', 150, 40);
547
- * console.log(`Terminal resized to ${updatedInfo.cols}x${updatedInfo.rows}`);
548
- *
549
- * // You can also use the PtyHandle's resize method
550
- * await ptyHandle.resize(150, 40); // cols, rows
551
- */
552
- async resizePtySession(sessionId, cols, rows) {
553
- return (await this.apiClient.resizePtySession(sessionId, { cols, rows })).data;
554
- }
555
- }
339
+ async getSessionCommandLogs(sessionId, commandId, onStdout, onStderr) {
340
+ if (!onStdout && !onStderr) {
341
+ const response = await this.apiClient.getSessionCommandLogs(sessionId, commandId);
342
+ return {
343
+ output: response.data.output ?? '',
344
+ stdout: response.data.stdout ?? '',
345
+ stderr: response.data.stderr ?? '',
346
+ };
347
+ }
348
+ const url = `${this.clientConfig.basePath.replace(/^http/, 'ws')}/process/session/${sessionId}/command/${commandId}/logs?follow=true`;
349
+ const ws = await (0, WebSocket_1.createSandboxWebSocket)(url, this.clientConfig.baseOptions?.headers || {}, this.getPreviewToken);
350
+ await (0, Stream_1.stdDemuxStream)(ws, onStdout, onStderr);
351
+ }
352
+ async getEntrypointLogs(onStdout, onStderr) {
353
+ if (!onStdout && !onStderr) {
354
+ const response = await this.apiClient.getEntrypointLogs();
355
+ return {
356
+ output: response.data.output ?? '',
357
+ stdout: response.data.stdout ?? '',
358
+ stderr: response.data.stderr ?? '',
359
+ };
360
+ }
361
+ const url = `${this.clientConfig.basePath.replace(/^http/, 'ws')}/process/session/entrypoint/logs?follow=true`;
362
+ const ws = await (0, WebSocket_1.createSandboxWebSocket)(url, this.clientConfig.baseOptions?.headers || {}, this.getPreviewToken);
363
+ await (0, Stream_1.stdDemuxStream)(ws, onStdout, onStderr);
364
+ }
365
+ /**
366
+ * Sends input data to a command executed in a session.
367
+ *
368
+ * @param {string} sessionId - Unique identifier of the session
369
+ * @param {string} commandId - Unique identifier of the command
370
+ * @param {string} data - Input data to send
371
+ * @returns {Promise<void>}
372
+ */
373
+ async sendSessionCommandInput(sessionId, commandId, data) {
374
+ await this.apiClient.sendInput(sessionId, commandId, { data });
375
+ }
376
+ /**
377
+ * Lists all active sessions in the Sandbox.
378
+ *
379
+ * @returns {Promise<Session[]>} Array of active sessions
380
+ *
381
+ * @example
382
+ * const sessions = await process.listSessions();
383
+ * sessions.forEach(session => {
384
+ * console.log(`Session ${session.sessionId}:`);
385
+ * session.commands.forEach(cmd => {
386
+ * console.log(`- ${cmd.command} (${cmd.exitCode})`);
387
+ * });
388
+ * });
389
+ */
390
+ async listSessions() {
391
+ const response = await this.apiClient.listSessions();
392
+ return response.data;
393
+ }
394
+ /**
395
+ * Delete a session from the Sandbox.
396
+ *
397
+ * @param {string} sessionId - Unique identifier of the session to delete
398
+ * @returns {Promise<void>}
399
+ *
400
+ * @example
401
+ * // Clean up a completed session
402
+ * await process.deleteSession('my-session');
403
+ */
404
+ async deleteSession(sessionId) {
405
+ await this.apiClient.deleteSession(sessionId);
406
+ }
407
+ /**
408
+ * Create a new PTY (pseudo-terminal) session in the sandbox.
409
+ *
410
+ * Creates an interactive terminal session that can execute commands and handle user input.
411
+ * The PTY session behaves like a real terminal, supporting features like command history.
412
+ *
413
+ * @param {PtyCreateOptions & PtyConnectOptions} options - PTY session configuration including creation and connection options
414
+ * @returns {Promise<PtyHandle>} PTY handle for managing the session
415
+ *
416
+ * @example
417
+ * // Create a PTY session with custom configuration
418
+ * const ptyHandle = await process.createPty({
419
+ * id: 'my-interactive-session',
420
+ * cwd: '/workspace',
421
+ * envs: { TERM: 'xterm-256color', LANG: 'en_US.UTF-8' },
422
+ * cols: 120,
423
+ * rows: 30,
424
+ * onData: (data) => {
425
+ * // Handle terminal output
426
+ * const text = new TextDecoder().decode(data);
427
+ * process.stdout.write(text);
428
+ * },
429
+ * });
430
+ *
431
+ * // Wait for connection to be established
432
+ * await ptyHandle.waitForConnection();
433
+ *
434
+ * // Send commands to the terminal
435
+ * await ptyHandle.sendInput('ls -la\n');
436
+ * await ptyHandle.sendInput('echo "Hello, PTY!"\n');
437
+ * await ptyHandle.sendInput('exit\n');
438
+ *
439
+ * // Wait for completion and get result
440
+ * const result = await ptyHandle.wait();
441
+ * console.log(`PTY session completed with exit code: ${result.exitCode}`);
442
+ *
443
+ * // Clean up
444
+ * await ptyHandle.disconnect();
445
+ */
446
+ async createPty(options) {
447
+ const request = {
448
+ id: options.id,
449
+ cwd: options.cwd,
450
+ envs: options.envs,
451
+ cols: options.cols,
452
+ rows: options.rows,
453
+ lazyStart: true,
454
+ };
455
+ const response = await this.apiClient.createPtySession(request);
456
+ return await this.connectPty(response.data.sessionId, options);
457
+ }
458
+ /**
459
+ * Connect to an existing PTY session in the sandbox.
460
+ *
461
+ * Establishes a WebSocket connection to an existing PTY session, allowing you to
462
+ * interact with a previously created terminal session.
463
+ *
464
+ * @param {string} sessionId - ID of the PTY session to connect to
465
+ * @param {PtyConnectOptions} options - Options for the connection including data handler
466
+ * @returns {Promise<PtyHandle>} PTY handle for managing the session
467
+ *
468
+ * @example
469
+ * // Connect to an existing PTY session
470
+ * const handle = await process.connectPty('my-session', {
471
+ * onData: (data) => {
472
+ * // Handle terminal output
473
+ * const text = new TextDecoder().decode(data);
474
+ * process.stdout.write(text);
475
+ * },
476
+ * });
477
+ *
478
+ * // Wait for connection to be established
479
+ * await handle.waitForConnection();
480
+ *
481
+ * // Send commands to the existing session
482
+ * await handle.sendInput('pwd\n');
483
+ * await handle.sendInput('ls -la\n');
484
+ * await handle.sendInput('exit\n');
485
+ *
486
+ * // Wait for completion
487
+ * const result = await handle.wait();
488
+ * console.log(`Session exited with code: ${result.exitCode}`);
489
+ *
490
+ * // Clean up
491
+ * await handle.disconnect();
492
+ */
493
+ async connectPty(sessionId, options) {
494
+ const url = `${this.clientConfig.basePath.replace(/^http/, 'ws')}/process/pty/${sessionId}/connect`;
495
+ const ws = await (0, WebSocket_1.createSandboxWebSocket)(url, this.clientConfig.baseOptions?.headers || {}, this.getPreviewToken);
496
+ const handle = new PtyHandle_1.PtyHandle(ws, (cols, rows) => this.resizePtySession(sessionId, cols, rows), () => this.killPtySession(sessionId), options.onData, sessionId);
497
+ await handle.waitForConnection();
498
+ return handle;
499
+ }
500
+ /**
501
+ * List all PTY sessions in the sandbox.
502
+ *
503
+ * Retrieves information about all PTY sessions, both active and inactive,
504
+ * that have been created in this sandbox.
505
+ *
506
+ * @returns {Promise<PtySessionInfo[]>} Array of PTY session information
507
+ *
508
+ * @example
509
+ * // List all PTY sessions
510
+ * const sessions = await process.listPtySessions();
511
+ *
512
+ * for (const session of sessions) {
513
+ * console.log(`Session ID: ${session.id}`);
514
+ * console.log(`Active: ${session.active}`);
515
+ * console.log(`Created: ${session.createdAt}`);
516
+ * }
517
+ * console.log('---');
518
+ * }
519
+ */
520
+ async listPtySessions() {
521
+ return (await this.apiClient.listPtySessions()).data.sessions;
522
+ }
523
+ /**
524
+ * Get detailed information about a specific PTY session.
525
+ *
526
+ * Retrieves comprehensive information about a PTY session including its current state,
527
+ * configuration, and metadata.
528
+ *
529
+ * @param {string} sessionId - ID of the PTY session to retrieve information for
530
+ * @returns {Promise<PtySessionInfo>} PTY session information
531
+ *
532
+ * @throws {Error} If the PTY session doesn't exist
533
+ *
534
+ * @example
535
+ * // Get details about a specific PTY session
536
+ * const session = await process.getPtySessionInfo('my-session');
537
+ *
538
+ * console.log(`Session ID: ${session.id}`);
539
+ * console.log(`Active: ${session.active}`);
540
+ * console.log(`Working Directory: ${session.cwd}`);
541
+ * console.log(`Terminal Size: ${session.cols}x${session.rows}`);
542
+ *
543
+ * if (session.processId) {
544
+ * console.log(`Process ID: ${session.processId}`);
545
+ * }
546
+ */
547
+ async getPtySessionInfo(sessionId) {
548
+ return (await this.apiClient.getPtySession(sessionId)).data;
549
+ }
550
+ /**
551
+ * Kill a PTY session and terminate its associated process.
552
+ *
553
+ * Forcefully terminates the PTY session and cleans up all associated resources.
554
+ * This will close any active connections and kill the underlying shell process.
555
+ *
556
+ * @param {string} sessionId - ID of the PTY session to kill
557
+ * @returns {Promise<void>}
558
+ *
559
+ * @throws {Error} If the PTY session doesn't exist or cannot be killed
560
+ *
561
+ * @note This operation is irreversible. Any unsaved work in the terminal session will be lost.
562
+ *
563
+ * @example
564
+ * // Kill a specific PTY session
565
+ * await process.killPtySession('my-session');
566
+ *
567
+ * // Verify the session is no longer active
568
+ * try {
569
+ * const info = await process.getPtySessionInfo('my-session');
570
+ * console.log(`Session still exists but active: ${info.active}`);
571
+ * } catch (error) {
572
+ * console.log('Session has been completely removed');
573
+ * }
574
+ */
575
+ async killPtySession(sessionId) {
576
+ await this.apiClient.deletePtySession(sessionId);
577
+ }
578
+ /**
579
+ * Resize a PTY session's terminal dimensions.
580
+ *
581
+ * Changes the terminal size of an active PTY session. This is useful when the
582
+ * client terminal is resized or when you need to adjust the display for different
583
+ * output requirements.
584
+ *
585
+ * @param {string} sessionId - ID of the PTY session to resize
586
+ * @param {number} cols - New number of terminal columns
587
+ * @param {number} rows - New number of terminal rows
588
+ * @returns {Promise<PtySessionInfo>} Updated session information reflecting the new terminal size
589
+ *
590
+ * @throws {Error} If the PTY session doesn't exist or resize operation fails
591
+ *
592
+ * @note The resize operation will send a SIGWINCH signal to the shell process,
593
+ * allowing terminal applications to adapt to the new size.
594
+ *
595
+ * @example
596
+ * // Resize a PTY session to a larger terminal
597
+ * const updatedInfo = await process.resizePtySession('my-session', 150, 40);
598
+ * console.log(`Terminal resized to ${updatedInfo.cols}x${updatedInfo.rows}`);
599
+ *
600
+ * // You can also use the PtyHandle's resize method
601
+ * await ptyHandle.resize(150, 40); // cols, rows
602
+ */
603
+ async resizePtySession(sessionId, cols, rows) {
604
+ return (await this.apiClient.resizePtySession(sessionId, { cols, rows })).data;
605
+ }
606
+ };
607
+ })();
556
608
  exports.Process = Process;
557
- tslib_1.__decorate([
558
- (0, otel_decorator_1.WithInstrumentation)(),
559
- tslib_1.__metadata("design:type", Function),
560
- tslib_1.__metadata("design:paramtypes", [String, String, Object, Number]),
561
- tslib_1.__metadata("design:returntype", Promise)
562
- ], Process.prototype, "executeCommand", null);
563
- tslib_1.__decorate([
564
- (0, otel_decorator_1.WithInstrumentation)(),
565
- tslib_1.__metadata("design:type", Function),
566
- tslib_1.__metadata("design:paramtypes", [String, CodeRunParams, Number]),
567
- tslib_1.__metadata("design:returntype", Promise)
568
- ], Process.prototype, "codeRun", null);
569
- tslib_1.__decorate([
570
- (0, otel_decorator_1.WithInstrumentation)(),
571
- tslib_1.__metadata("design:type", Function),
572
- tslib_1.__metadata("design:paramtypes", [String]),
573
- tslib_1.__metadata("design:returntype", Promise)
574
- ], Process.prototype, "createSession", null);
575
- tslib_1.__decorate([
576
- (0, otel_decorator_1.WithInstrumentation)(),
577
- tslib_1.__metadata("design:type", Function),
578
- tslib_1.__metadata("design:paramtypes", [String, String]),
579
- tslib_1.__metadata("design:returntype", Promise)
580
- ], Process.prototype, "getSessionCommand", null);
581
- tslib_1.__decorate([
582
- (0, otel_decorator_1.WithInstrumentation)(),
583
- tslib_1.__metadata("design:type", Function),
584
- tslib_1.__metadata("design:paramtypes", [String, Object, Number]),
585
- tslib_1.__metadata("design:returntype", Promise)
586
- ], Process.prototype, "executeSessionCommand", null);
587
- tslib_1.__decorate([
588
- (0, otel_decorator_1.WithInstrumentation)(),
589
- tslib_1.__metadata("design:type", Function),
590
- tslib_1.__metadata("design:paramtypes", [String, String, Function, Function]),
591
- tslib_1.__metadata("design:returntype", Promise)
592
- ], Process.prototype, "getSessionCommandLogs", null);
593
- tslib_1.__decorate([
594
- (0, otel_decorator_1.WithInstrumentation)(),
595
- tslib_1.__metadata("design:type", Function),
596
- tslib_1.__metadata("design:paramtypes", [Function, Function]),
597
- tslib_1.__metadata("design:returntype", Promise)
598
- ], Process.prototype, "getEntrypointLogs", null);
599
- tslib_1.__decorate([
600
- (0, otel_decorator_1.WithInstrumentation)(),
601
- tslib_1.__metadata("design:type", Function),
602
- tslib_1.__metadata("design:paramtypes", []),
603
- tslib_1.__metadata("design:returntype", Promise)
604
- ], Process.prototype, "listSessions", null);
605
- tslib_1.__decorate([
606
- (0, otel_decorator_1.WithInstrumentation)(),
607
- tslib_1.__metadata("design:type", Function),
608
- tslib_1.__metadata("design:paramtypes", [String]),
609
- tslib_1.__metadata("design:returntype", Promise)
610
- ], Process.prototype, "deleteSession", null);
611
- tslib_1.__decorate([
612
- (0, otel_decorator_1.WithInstrumentation)(),
613
- tslib_1.__metadata("design:type", Function),
614
- tslib_1.__metadata("design:paramtypes", [Object]),
615
- tslib_1.__metadata("design:returntype", Promise)
616
- ], Process.prototype, "createPty", null);
617
- tslib_1.__decorate([
618
- (0, otel_decorator_1.WithInstrumentation)(),
619
- tslib_1.__metadata("design:type", Function),
620
- tslib_1.__metadata("design:paramtypes", [String, Object]),
621
- tslib_1.__metadata("design:returntype", Promise)
622
- ], Process.prototype, "connectPty", null);
623
- tslib_1.__decorate([
624
- (0, otel_decorator_1.WithInstrumentation)(),
625
- tslib_1.__metadata("design:type", Function),
626
- tslib_1.__metadata("design:paramtypes", []),
627
- tslib_1.__metadata("design:returntype", Promise)
628
- ], Process.prototype, "listPtySessions", null);
629
- tslib_1.__decorate([
630
- (0, otel_decorator_1.WithInstrumentation)(),
631
- tslib_1.__metadata("design:type", Function),
632
- tslib_1.__metadata("design:paramtypes", [String]),
633
- tslib_1.__metadata("design:returntype", Promise)
634
- ], Process.prototype, "getPtySessionInfo", null);
635
- tslib_1.__decorate([
636
- (0, otel_decorator_1.WithInstrumentation)(),
637
- tslib_1.__metadata("design:type", Function),
638
- tslib_1.__metadata("design:paramtypes", [String]),
639
- tslib_1.__metadata("design:returntype", Promise)
640
- ], Process.prototype, "killPtySession", null);
641
- tslib_1.__decorate([
642
- (0, otel_decorator_1.WithInstrumentation)(),
643
- tslib_1.__metadata("design:type", Function),
644
- tslib_1.__metadata("design:paramtypes", [String, Number, Number]),
645
- tslib_1.__metadata("design:returntype", Promise)
646
- ], Process.prototype, "resizePtySession", null);
647
609
  //# sourceMappingURL=Process.js.map