@daytonaio/sdk 0.106.4 → 0.107.0-rc.2
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/package.json +2 -2
- package/src/Process.d.ts +177 -1
- package/src/Process.js +216 -12
- package/src/Process.js.map +1 -1
- package/src/PtyHandle.d.ts +154 -0
- package/src/PtyHandle.js +379 -0
- package/src/PtyHandle.js.map +1 -0
- package/src/index.d.ts +3 -0
- package/src/index.js +4 -0
- package/src/index.js.map +1 -1
- package/src/types/Pty.d.ts +47 -0
- package/src/types/Pty.js +7 -0
- package/src/types/Pty.js.map +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@daytonaio/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.107.0-rc.2",
|
|
4
4
|
"description": "TypeScript SDK for Daytona",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"types": "./src/index.d.ts",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"pathe": "^2.0.3",
|
|
36
36
|
"shell-quote": "^1.8.2",
|
|
37
37
|
"tar": "^6.2.0",
|
|
38
|
-
"@daytonaio/api-client": "0.
|
|
38
|
+
"@daytonaio/api-client": "0.107.0-rc.2"
|
|
39
39
|
},
|
|
40
40
|
"packageManager": "yarn@4.6.0",
|
|
41
41
|
"type": "commonjs"
|
package/src/Process.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { Command, Configuration, Session, SessionExecuteRequest, SessionExecuteResponse as ApiSessionExecuteResponse, PortPreviewUrl, ToolboxApi } from '@daytonaio/api-client';
|
|
1
|
+
import { Command, Configuration, Session, SessionExecuteRequest, SessionExecuteResponse as ApiSessionExecuteResponse, PortPreviewUrl, ToolboxApi, PtySessionInfo } from '@daytonaio/api-client';
|
|
2
2
|
import { SandboxCodeToolbox } from './Sandbox';
|
|
3
3
|
import { ExecuteResponse } from './types/ExecuteResponse';
|
|
4
|
+
import { PtyHandle } from './PtyHandle';
|
|
5
|
+
import { PtyCreateOptions, PtyConnectOptions } from './types/Pty';
|
|
4
6
|
export declare const STDOUT_PREFIX_BYTES: Uint8Array<ArrayBuffer>;
|
|
5
7
|
export declare const STDERR_PREFIX_BYTES: Uint8Array<ArrayBuffer>;
|
|
6
8
|
export declare const MAX_PREFIX_LEN: number;
|
|
@@ -262,4 +264,178 @@ export declare class Process {
|
|
|
262
264
|
* await process.deleteSession('my-session');
|
|
263
265
|
*/
|
|
264
266
|
deleteSession(sessionId: string): Promise<void>;
|
|
267
|
+
/**
|
|
268
|
+
* Create a new PTY (pseudo-terminal) session in the sandbox.
|
|
269
|
+
*
|
|
270
|
+
* Creates an interactive terminal session that can execute commands and handle user input.
|
|
271
|
+
* The PTY session behaves like a real terminal, supporting features like command history.
|
|
272
|
+
*
|
|
273
|
+
* @param {PtyCreateOptions & PtyConnectOptions} options - PTY session configuration including creation and connection options
|
|
274
|
+
* @returns {Promise<PtyHandle>} PTY handle for managing the session
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* // Create a PTY session with custom configuration
|
|
278
|
+
* const ptyHandle = await process.createPty({
|
|
279
|
+
* id: 'my-interactive-session',
|
|
280
|
+
* cwd: '/workspace',
|
|
281
|
+
* envs: { TERM: 'xterm-256color', LANG: 'en_US.UTF-8' },
|
|
282
|
+
* cols: 120,
|
|
283
|
+
* rows: 30,
|
|
284
|
+
* onData: (data) => {
|
|
285
|
+
* // Handle terminal output
|
|
286
|
+
* const text = new TextDecoder().decode(data);
|
|
287
|
+
* process.stdout.write(text);
|
|
288
|
+
* },
|
|
289
|
+
* });
|
|
290
|
+
*
|
|
291
|
+
* // Wait for connection to be established
|
|
292
|
+
* await ptyHandle.waitForConnection();
|
|
293
|
+
*
|
|
294
|
+
* // Send commands to the terminal
|
|
295
|
+
* await ptyHandle.sendInput('ls -la\n');
|
|
296
|
+
* await ptyHandle.sendInput('echo "Hello, PTY!"\n');
|
|
297
|
+
* await ptyHandle.sendInput('exit\n');
|
|
298
|
+
*
|
|
299
|
+
* // Wait for completion and get result
|
|
300
|
+
* const result = await ptyHandle.wait();
|
|
301
|
+
* console.log(`PTY session completed with exit code: ${result.exitCode}`);
|
|
302
|
+
*
|
|
303
|
+
* // Clean up
|
|
304
|
+
* await ptyHandle.disconnect();
|
|
305
|
+
*/
|
|
306
|
+
createPty(options?: PtyCreateOptions & PtyConnectOptions): Promise<PtyHandle>;
|
|
307
|
+
/**
|
|
308
|
+
* Connect to an existing PTY session in the sandbox.
|
|
309
|
+
*
|
|
310
|
+
* Establishes a WebSocket connection to an existing PTY session, allowing you to
|
|
311
|
+
* interact with a previously created terminal session.
|
|
312
|
+
*
|
|
313
|
+
* @param {string} sessionId - ID of the PTY session to connect to
|
|
314
|
+
* @param {PtyConnectOptions} options - Options for the connection including data handler
|
|
315
|
+
* @returns {Promise<PtyHandle>} PTY handle for managing the session
|
|
316
|
+
*
|
|
317
|
+
* @example
|
|
318
|
+
* // Connect to an existing PTY session
|
|
319
|
+
* const handle = await process.connectPty('my-session', {
|
|
320
|
+
* onData: (data) => {
|
|
321
|
+
* // Handle terminal output
|
|
322
|
+
* const text = new TextDecoder().decode(data);
|
|
323
|
+
* process.stdout.write(text);
|
|
324
|
+
* },
|
|
325
|
+
* });
|
|
326
|
+
*
|
|
327
|
+
* // Wait for connection to be established
|
|
328
|
+
* await handle.waitForConnection();
|
|
329
|
+
*
|
|
330
|
+
* // Send commands to the existing session
|
|
331
|
+
* await handle.sendInput('pwd\n');
|
|
332
|
+
* await handle.sendInput('ls -la\n');
|
|
333
|
+
* await handle.sendInput('exit\n');
|
|
334
|
+
*
|
|
335
|
+
* // Wait for completion
|
|
336
|
+
* const result = await handle.wait();
|
|
337
|
+
* console.log(`Session exited with code: ${result.exitCode}`);
|
|
338
|
+
*
|
|
339
|
+
* // Clean up
|
|
340
|
+
* await handle.disconnect();
|
|
341
|
+
*/
|
|
342
|
+
connectPty(sessionId: string, options?: PtyConnectOptions): Promise<PtyHandle>;
|
|
343
|
+
/**
|
|
344
|
+
* List all PTY sessions in the sandbox.
|
|
345
|
+
*
|
|
346
|
+
* Retrieves information about all PTY sessions, both active and inactive,
|
|
347
|
+
* that have been created in this sandbox.
|
|
348
|
+
*
|
|
349
|
+
* @returns {Promise<PtySessionInfo[]>} Array of PTY session information
|
|
350
|
+
*
|
|
351
|
+
* @example
|
|
352
|
+
* // List all PTY sessions
|
|
353
|
+
* const sessions = await process.listPtySessions();
|
|
354
|
+
*
|
|
355
|
+
* for (const session of sessions) {
|
|
356
|
+
* console.log(`Session ID: ${session.id}`);
|
|
357
|
+
* console.log(`Active: ${session.active}`);
|
|
358
|
+
* console.log(`Created: ${session.createdAt}`);
|
|
359
|
+
* }
|
|
360
|
+
* console.log('---');
|
|
361
|
+
* }
|
|
362
|
+
*/
|
|
363
|
+
listPtySessions(): Promise<PtySessionInfo[]>;
|
|
364
|
+
/**
|
|
365
|
+
* Get detailed information about a specific PTY session.
|
|
366
|
+
*
|
|
367
|
+
* Retrieves comprehensive information about a PTY session including its current state,
|
|
368
|
+
* configuration, and metadata.
|
|
369
|
+
*
|
|
370
|
+
* @param {string} sessionId - ID of the PTY session to retrieve information for
|
|
371
|
+
* @returns {Promise<PtySessionInfo>} PTY session information
|
|
372
|
+
*
|
|
373
|
+
* @throws {Error} If the PTY session doesn't exist
|
|
374
|
+
*
|
|
375
|
+
* @example
|
|
376
|
+
* // Get details about a specific PTY session
|
|
377
|
+
* const session = await process.getPtySessionInfo('my-session');
|
|
378
|
+
*
|
|
379
|
+
* console.log(`Session ID: ${session.id}`);
|
|
380
|
+
* console.log(`Active: ${session.active}`);
|
|
381
|
+
* console.log(`Working Directory: ${session.cwd}`);
|
|
382
|
+
* console.log(`Terminal Size: ${session.cols}x${session.rows}`);
|
|
383
|
+
*
|
|
384
|
+
* if (session.processId) {
|
|
385
|
+
* console.log(`Process ID: ${session.processId}`);
|
|
386
|
+
* }
|
|
387
|
+
*/
|
|
388
|
+
getPtySessionInfo(sessionId: string): Promise<PtySessionInfo>;
|
|
389
|
+
/**
|
|
390
|
+
* Kill a PTY session and terminate its associated process.
|
|
391
|
+
*
|
|
392
|
+
* Forcefully terminates the PTY session and cleans up all associated resources.
|
|
393
|
+
* This will close any active connections and kill the underlying shell process.
|
|
394
|
+
*
|
|
395
|
+
* @param {string} sessionId - ID of the PTY session to kill
|
|
396
|
+
* @returns {Promise<void>}
|
|
397
|
+
*
|
|
398
|
+
* @throws {Error} If the PTY session doesn't exist or cannot be killed
|
|
399
|
+
*
|
|
400
|
+
* @note This operation is irreversible. Any unsaved work in the terminal session will be lost.
|
|
401
|
+
*
|
|
402
|
+
* @example
|
|
403
|
+
* // Kill a specific PTY session
|
|
404
|
+
* await process.killPtySession('my-session');
|
|
405
|
+
*
|
|
406
|
+
* // Verify the session is no longer active
|
|
407
|
+
* try {
|
|
408
|
+
* const info = await process.getPtySessionInfo('my-session');
|
|
409
|
+
* console.log(`Session still exists but active: ${info.active}`);
|
|
410
|
+
* } catch (error) {
|
|
411
|
+
* console.log('Session has been completely removed');
|
|
412
|
+
* }
|
|
413
|
+
*/
|
|
414
|
+
killPtySession(sessionId: string): Promise<void>;
|
|
415
|
+
/**
|
|
416
|
+
* Resize a PTY session's terminal dimensions.
|
|
417
|
+
*
|
|
418
|
+
* Changes the terminal size of an active PTY session. This is useful when the
|
|
419
|
+
* client terminal is resized or when you need to adjust the display for different
|
|
420
|
+
* output requirements.
|
|
421
|
+
*
|
|
422
|
+
* @param {string} sessionId - ID of the PTY session to resize
|
|
423
|
+
* @param {number} cols - New number of terminal columns
|
|
424
|
+
* @param {number} rows - New number of terminal rows
|
|
425
|
+
* @returns {Promise<PtySessionInfo>} Updated session information reflecting the new terminal size
|
|
426
|
+
*
|
|
427
|
+
* @throws {Error} If the PTY session doesn't exist or resize operation fails
|
|
428
|
+
*
|
|
429
|
+
* @note The resize operation will send a SIGWINCH signal to the shell process,
|
|
430
|
+
* allowing terminal applications to adapt to the new size.
|
|
431
|
+
*
|
|
432
|
+
* @example
|
|
433
|
+
* // Resize a PTY session to a larger terminal
|
|
434
|
+
* const updatedInfo = await process.resizePtySession('my-session', 150, 40);
|
|
435
|
+
* console.log(`Terminal resized to ${updatedInfo.cols}x${updatedInfo.rows}`);
|
|
436
|
+
*
|
|
437
|
+
* // You can also use the PtyHandle's resize method
|
|
438
|
+
* await ptyHandle.resize(150, 40); // cols, rows
|
|
439
|
+
*/
|
|
440
|
+
resizePtySession(sessionId: string, cols: number, rows: number): Promise<PtySessionInfo>;
|
|
265
441
|
}
|
package/src/Process.js
CHANGED
|
@@ -11,6 +11,7 @@ const Stream_1 = require("./utils/Stream");
|
|
|
11
11
|
const buffer_1 = require("buffer");
|
|
12
12
|
const isomorphic_ws_1 = tslib_1.__importDefault(require("isomorphic-ws"));
|
|
13
13
|
const Runtime_1 = require("./utils/Runtime");
|
|
14
|
+
const PtyHandle_1 = require("./PtyHandle");
|
|
14
15
|
// 3-byte multiplexing markers inserted by the shell labelers
|
|
15
16
|
exports.STDOUT_PREFIX_BYTES = new Uint8Array([0x01, 0x01, 0x01]);
|
|
16
17
|
exports.STDERR_PREFIX_BYTES = new Uint8Array([0x02, 0x02, 0x02]);
|
|
@@ -288,18 +289,7 @@ class Process {
|
|
|
288
289
|
}
|
|
289
290
|
const previewLink = await this.getPreviewLink(2280);
|
|
290
291
|
const url = `${previewLink.url.replace(/^http/, 'ws')}/process/session/${sessionId}/command/${commandId}/logs?follow=true`;
|
|
291
|
-
|
|
292
|
-
if (Runtime_1.RUNTIME === Runtime_1.Runtime.BROWSER) {
|
|
293
|
-
ws = new isomorphic_ws_1.default(url + '&DAYTONA_SANDBOX_AUTH_KEY=' + previewLink.token, `X-Daytona-SDK-Version~${this.clientConfig.baseOptions.headers['X-Daytona-SDK-Version']}`);
|
|
294
|
-
}
|
|
295
|
-
else {
|
|
296
|
-
ws = new isomorphic_ws_1.default(url, {
|
|
297
|
-
headers: {
|
|
298
|
-
...this.clientConfig.baseOptions.headers,
|
|
299
|
-
'X-Daytona-Preview-Token': previewLink.token,
|
|
300
|
-
},
|
|
301
|
-
});
|
|
302
|
-
}
|
|
292
|
+
const ws = createWebSocket(url, previewLink.token, this.clientConfig.baseOptions?.headers || {});
|
|
303
293
|
await (0, Stream_1.stdDemuxStream)(ws, onStdout, onStderr);
|
|
304
294
|
}
|
|
305
295
|
/**
|
|
@@ -333,6 +323,207 @@ class Process {
|
|
|
333
323
|
async deleteSession(sessionId) {
|
|
334
324
|
await this.toolboxApi.deleteSession(this.sandboxId, sessionId);
|
|
335
325
|
}
|
|
326
|
+
/**
|
|
327
|
+
* Create a new PTY (pseudo-terminal) session in the sandbox.
|
|
328
|
+
*
|
|
329
|
+
* Creates an interactive terminal session that can execute commands and handle user input.
|
|
330
|
+
* The PTY session behaves like a real terminal, supporting features like command history.
|
|
331
|
+
*
|
|
332
|
+
* @param {PtyCreateOptions & PtyConnectOptions} options - PTY session configuration including creation and connection options
|
|
333
|
+
* @returns {Promise<PtyHandle>} PTY handle for managing the session
|
|
334
|
+
*
|
|
335
|
+
* @example
|
|
336
|
+
* // Create a PTY session with custom configuration
|
|
337
|
+
* const ptyHandle = await process.createPty({
|
|
338
|
+
* id: 'my-interactive-session',
|
|
339
|
+
* cwd: '/workspace',
|
|
340
|
+
* envs: { TERM: 'xterm-256color', LANG: 'en_US.UTF-8' },
|
|
341
|
+
* cols: 120,
|
|
342
|
+
* rows: 30,
|
|
343
|
+
* onData: (data) => {
|
|
344
|
+
* // Handle terminal output
|
|
345
|
+
* const text = new TextDecoder().decode(data);
|
|
346
|
+
* process.stdout.write(text);
|
|
347
|
+
* },
|
|
348
|
+
* });
|
|
349
|
+
*
|
|
350
|
+
* // Wait for connection to be established
|
|
351
|
+
* await ptyHandle.waitForConnection();
|
|
352
|
+
*
|
|
353
|
+
* // Send commands to the terminal
|
|
354
|
+
* await ptyHandle.sendInput('ls -la\n');
|
|
355
|
+
* await ptyHandle.sendInput('echo "Hello, PTY!"\n');
|
|
356
|
+
* await ptyHandle.sendInput('exit\n');
|
|
357
|
+
*
|
|
358
|
+
* // Wait for completion and get result
|
|
359
|
+
* const result = await ptyHandle.wait();
|
|
360
|
+
* console.log(`PTY session completed with exit code: ${result.exitCode}`);
|
|
361
|
+
*
|
|
362
|
+
* // Clean up
|
|
363
|
+
* await ptyHandle.disconnect();
|
|
364
|
+
*/
|
|
365
|
+
async createPty(options) {
|
|
366
|
+
const request = {
|
|
367
|
+
id: options.id,
|
|
368
|
+
cwd: options.cwd,
|
|
369
|
+
envs: options.envs,
|
|
370
|
+
cols: options.cols,
|
|
371
|
+
rows: options.rows,
|
|
372
|
+
lazyStart: true,
|
|
373
|
+
};
|
|
374
|
+
const response = await this.toolboxApi.createPTYSession(this.sandboxId, request);
|
|
375
|
+
return await this.connectPty(response.data.sessionId, options);
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Connect to an existing PTY session in the sandbox.
|
|
379
|
+
*
|
|
380
|
+
* Establishes a WebSocket connection to an existing PTY session, allowing you to
|
|
381
|
+
* interact with a previously created terminal session.
|
|
382
|
+
*
|
|
383
|
+
* @param {string} sessionId - ID of the PTY session to connect to
|
|
384
|
+
* @param {PtyConnectOptions} options - Options for the connection including data handler
|
|
385
|
+
* @returns {Promise<PtyHandle>} PTY handle for managing the session
|
|
386
|
+
*
|
|
387
|
+
* @example
|
|
388
|
+
* // Connect to an existing PTY session
|
|
389
|
+
* const handle = await process.connectPty('my-session', {
|
|
390
|
+
* onData: (data) => {
|
|
391
|
+
* // Handle terminal output
|
|
392
|
+
* const text = new TextDecoder().decode(data);
|
|
393
|
+
* process.stdout.write(text);
|
|
394
|
+
* },
|
|
395
|
+
* });
|
|
396
|
+
*
|
|
397
|
+
* // Wait for connection to be established
|
|
398
|
+
* await handle.waitForConnection();
|
|
399
|
+
*
|
|
400
|
+
* // Send commands to the existing session
|
|
401
|
+
* await handle.sendInput('pwd\n');
|
|
402
|
+
* await handle.sendInput('ls -la\n');
|
|
403
|
+
* await handle.sendInput('exit\n');
|
|
404
|
+
*
|
|
405
|
+
* // Wait for completion
|
|
406
|
+
* const result = await handle.wait();
|
|
407
|
+
* console.log(`Session exited with code: ${result.exitCode}`);
|
|
408
|
+
*
|
|
409
|
+
* // Clean up
|
|
410
|
+
* await handle.disconnect();
|
|
411
|
+
*/
|
|
412
|
+
async connectPty(sessionId, options) {
|
|
413
|
+
// Get preview link for WebSocket connection
|
|
414
|
+
const previewLink = await this.getPreviewLink(2280);
|
|
415
|
+
const url = `${previewLink.url.replace(/^http/, 'ws')}/process/pty/${sessionId}/connect`;
|
|
416
|
+
const ws = createWebSocket(url, previewLink.token, this.clientConfig.baseOptions?.headers || {});
|
|
417
|
+
const handle = new PtyHandle_1.PtyHandle(ws, (cols, rows) => this.resizePtySession(sessionId, cols, rows), () => this.killPtySession(sessionId), options.onData, sessionId);
|
|
418
|
+
await handle.waitForConnection();
|
|
419
|
+
return handle;
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* List all PTY sessions in the sandbox.
|
|
423
|
+
*
|
|
424
|
+
* Retrieves information about all PTY sessions, both active and inactive,
|
|
425
|
+
* that have been created in this sandbox.
|
|
426
|
+
*
|
|
427
|
+
* @returns {Promise<PtySessionInfo[]>} Array of PTY session information
|
|
428
|
+
*
|
|
429
|
+
* @example
|
|
430
|
+
* // List all PTY sessions
|
|
431
|
+
* const sessions = await process.listPtySessions();
|
|
432
|
+
*
|
|
433
|
+
* for (const session of sessions) {
|
|
434
|
+
* console.log(`Session ID: ${session.id}`);
|
|
435
|
+
* console.log(`Active: ${session.active}`);
|
|
436
|
+
* console.log(`Created: ${session.createdAt}`);
|
|
437
|
+
* }
|
|
438
|
+
* console.log('---');
|
|
439
|
+
* }
|
|
440
|
+
*/
|
|
441
|
+
async listPtySessions() {
|
|
442
|
+
return (await this.toolboxApi.listPTYSessions(this.sandboxId)).data.sessions;
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Get detailed information about a specific PTY session.
|
|
446
|
+
*
|
|
447
|
+
* Retrieves comprehensive information about a PTY session including its current state,
|
|
448
|
+
* configuration, and metadata.
|
|
449
|
+
*
|
|
450
|
+
* @param {string} sessionId - ID of the PTY session to retrieve information for
|
|
451
|
+
* @returns {Promise<PtySessionInfo>} PTY session information
|
|
452
|
+
*
|
|
453
|
+
* @throws {Error} If the PTY session doesn't exist
|
|
454
|
+
*
|
|
455
|
+
* @example
|
|
456
|
+
* // Get details about a specific PTY session
|
|
457
|
+
* const session = await process.getPtySessionInfo('my-session');
|
|
458
|
+
*
|
|
459
|
+
* console.log(`Session ID: ${session.id}`);
|
|
460
|
+
* console.log(`Active: ${session.active}`);
|
|
461
|
+
* console.log(`Working Directory: ${session.cwd}`);
|
|
462
|
+
* console.log(`Terminal Size: ${session.cols}x${session.rows}`);
|
|
463
|
+
*
|
|
464
|
+
* if (session.processId) {
|
|
465
|
+
* console.log(`Process ID: ${session.processId}`);
|
|
466
|
+
* }
|
|
467
|
+
*/
|
|
468
|
+
async getPtySessionInfo(sessionId) {
|
|
469
|
+
return (await this.toolboxApi.getPTYSession(this.sandboxId, sessionId)).data;
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Kill a PTY session and terminate its associated process.
|
|
473
|
+
*
|
|
474
|
+
* Forcefully terminates the PTY session and cleans up all associated resources.
|
|
475
|
+
* This will close any active connections and kill the underlying shell process.
|
|
476
|
+
*
|
|
477
|
+
* @param {string} sessionId - ID of the PTY session to kill
|
|
478
|
+
* @returns {Promise<void>}
|
|
479
|
+
*
|
|
480
|
+
* @throws {Error} If the PTY session doesn't exist or cannot be killed
|
|
481
|
+
*
|
|
482
|
+
* @note This operation is irreversible. Any unsaved work in the terminal session will be lost.
|
|
483
|
+
*
|
|
484
|
+
* @example
|
|
485
|
+
* // Kill a specific PTY session
|
|
486
|
+
* await process.killPtySession('my-session');
|
|
487
|
+
*
|
|
488
|
+
* // Verify the session is no longer active
|
|
489
|
+
* try {
|
|
490
|
+
* const info = await process.getPtySessionInfo('my-session');
|
|
491
|
+
* console.log(`Session still exists but active: ${info.active}`);
|
|
492
|
+
* } catch (error) {
|
|
493
|
+
* console.log('Session has been completely removed');
|
|
494
|
+
* }
|
|
495
|
+
*/
|
|
496
|
+
async killPtySession(sessionId) {
|
|
497
|
+
await this.toolboxApi.deletePTYSession(this.sandboxId, sessionId);
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* Resize a PTY session's terminal dimensions.
|
|
501
|
+
*
|
|
502
|
+
* Changes the terminal size of an active PTY session. This is useful when the
|
|
503
|
+
* client terminal is resized or when you need to adjust the display for different
|
|
504
|
+
* output requirements.
|
|
505
|
+
*
|
|
506
|
+
* @param {string} sessionId - ID of the PTY session to resize
|
|
507
|
+
* @param {number} cols - New number of terminal columns
|
|
508
|
+
* @param {number} rows - New number of terminal rows
|
|
509
|
+
* @returns {Promise<PtySessionInfo>} Updated session information reflecting the new terminal size
|
|
510
|
+
*
|
|
511
|
+
* @throws {Error} If the PTY session doesn't exist or resize operation fails
|
|
512
|
+
*
|
|
513
|
+
* @note The resize operation will send a SIGWINCH signal to the shell process,
|
|
514
|
+
* allowing terminal applications to adapt to the new size.
|
|
515
|
+
*
|
|
516
|
+
* @example
|
|
517
|
+
* // Resize a PTY session to a larger terminal
|
|
518
|
+
* const updatedInfo = await process.resizePtySession('my-session', 150, 40);
|
|
519
|
+
* console.log(`Terminal resized to ${updatedInfo.cols}x${updatedInfo.rows}`);
|
|
520
|
+
*
|
|
521
|
+
* // You can also use the PtyHandle's resize method
|
|
522
|
+
* await ptyHandle.resize(150, 40); // cols, rows
|
|
523
|
+
*/
|
|
524
|
+
async resizePtySession(sessionId, cols, rows) {
|
|
525
|
+
return (await this.toolboxApi.resizePTYSession(this.sandboxId, sessionId, { cols, rows })).data;
|
|
526
|
+
}
|
|
336
527
|
}
|
|
337
528
|
exports.Process = Process;
|
|
338
529
|
/**
|
|
@@ -433,4 +624,17 @@ function findSubarray(haystack, needle) {
|
|
|
433
624
|
}
|
|
434
625
|
return -1;
|
|
435
626
|
}
|
|
627
|
+
function createWebSocket(url, token, headers) {
|
|
628
|
+
if (Runtime_1.RUNTIME === Runtime_1.Runtime.BROWSER) {
|
|
629
|
+
return new isomorphic_ws_1.default(url + '&DAYTONA_SANDBOX_AUTH_KEY=' + token, `X-Daytona-SDK-Version~${headers['X-Daytona-SDK-Version']}`);
|
|
630
|
+
}
|
|
631
|
+
else {
|
|
632
|
+
return new isomorphic_ws_1.default(url, {
|
|
633
|
+
headers: {
|
|
634
|
+
...headers,
|
|
635
|
+
'X-Daytona-Preview-Token': token,
|
|
636
|
+
},
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
}
|
|
436
640
|
//# sourceMappingURL=Process.js.map
|
package/src/Process.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Process.js","sourceRoot":"","sources":["../../../../libs/sdk-typescript/src/Process.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;
|
|
1
|
+
{"version":3,"file":"Process.js","sourceRoot":"","sources":["../../../../libs/sdk-typescript/src/Process.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;AAeH,2DAAuD;AACvD,2CAA+C;AAC/C,mCAA+B;AAC/B,0EAAqC;AACrC,6CAAkD;AAClD,2CAAuC;AAGvC,6DAA6D;AAChD,QAAA,mBAAmB,GAAG,IAAI,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;AACxD,QAAA,mBAAmB,GAAG,IAAI,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;AACxD,QAAA,cAAc,GAAG,IAAI,CAAC,GAAG,CAAC,2BAAmB,CAAC,MAAM,EAAE,2BAAmB,CAAC,MAAM,CAAC,CAAA;AAE9F;;GAEG;AACH,MAAa,aAAa;IACxB;;OAEG;IACH,IAAI,CAAW;IACf;;OAEG;IACH,GAAG,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C,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC1D,IAAI,KAAK,GAAG,IAAI,CAAA;QAChB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACvC,IAAI,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;gBAClC,KAAK,GAAG,KAAK,CAAA;gBACb,MAAK;YACP,CAAC;QACH,CAAC;QACD,IAAI,KAAK;YAAE,OAAO,CAAC,CAAA;IACrB,CAAC;IACD,OAAO,CAAC,CAAC,CAAA;AACX,CAAC;AAED,SAAS,eAAe,CAAC,GAAW,EAAE,KAAa,EAAE,OAA+B;IAClF,IAAI,iBAAO,KAAK,iBAAO,CAAC,OAAO,EAAE,CAAC;QAChC,OAAO,IAAI,uBAAS,CAClB,GAAG,GAAG,4BAA4B,GAAG,KAAK,EAC1C,yBAAyB,OAAO,CAAC,uBAAuB,CAAC,EAAE,CAC5D,CAAA;IACH,CAAC;SAAM,CAAC;QACN,OAAO,IAAI,uBAAS,CAAC,GAAG,EAAE;YACxB,OAAO,EAAE;gBACP,GAAG,OAAO;gBACV,yBAAyB,EAAE,KAAK;aACjC;SACF,CAAC,CAAA;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import WebSocket from 'isomorphic-ws';
|
|
2
|
+
import { PtyResult } from './types/Pty';
|
|
3
|
+
import { PtySessionInfo } from '@daytonaio/api-client';
|
|
4
|
+
/**
|
|
5
|
+
* PTY session handle for managing a single PTY session.
|
|
6
|
+
*
|
|
7
|
+
* Provides methods for sending input, resizing the terminal, waiting for completion,
|
|
8
|
+
* and managing the WebSocket connection to a PTY session.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // Create a PTY session
|
|
13
|
+
* const ptyHandle = await process.createPty({
|
|
14
|
+
* id: 'my-session',
|
|
15
|
+
* cols: 120,
|
|
16
|
+
* rows: 30,
|
|
17
|
+
* onData: (data) => {
|
|
18
|
+
* const text = new TextDecoder().decode(data);
|
|
19
|
+
* process.stdout.write(text);
|
|
20
|
+
* },
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
*
|
|
24
|
+
* // Send commands
|
|
25
|
+
* await ptyHandle.sendInput('ls -la\n');
|
|
26
|
+
* await ptyHandle.sendInput('exit\n');
|
|
27
|
+
*
|
|
28
|
+
* // Wait for completion
|
|
29
|
+
* const result = await ptyHandle.wait();
|
|
30
|
+
* console.log(`PTY exited with code: ${result.exitCode}`);
|
|
31
|
+
*
|
|
32
|
+
* // Clean up
|
|
33
|
+
* await ptyHandle.disconnect();
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare class PtyHandle {
|
|
37
|
+
private readonly ws;
|
|
38
|
+
private readonly handleResize;
|
|
39
|
+
private readonly handleKill;
|
|
40
|
+
private readonly onPty;
|
|
41
|
+
readonly sessionId: string;
|
|
42
|
+
private _exitCode?;
|
|
43
|
+
private _error?;
|
|
44
|
+
private connected;
|
|
45
|
+
private connectionEstablished;
|
|
46
|
+
constructor(ws: WebSocket, handleResize: (cols: number, rows: number) => Promise<PtySessionInfo>, handleKill: () => Promise<void>, onPty: (data: Uint8Array) => void | Promise<void>, sessionId: string);
|
|
47
|
+
/**
|
|
48
|
+
* Exit code of the PTY process (if terminated)
|
|
49
|
+
*/
|
|
50
|
+
get exitCode(): number | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Error message if the PTY failed
|
|
53
|
+
*/
|
|
54
|
+
get error(): string | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* Check if connected to the PTY session
|
|
57
|
+
*/
|
|
58
|
+
isConnected(): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Wait for the WebSocket connection to be established.
|
|
61
|
+
*
|
|
62
|
+
* This method ensures the PTY session is ready to receive input and send output.
|
|
63
|
+
* It waits for the server to confirm the connection is established.
|
|
64
|
+
*
|
|
65
|
+
* @throws {Error} If connection times out (10 seconds) or connection fails
|
|
66
|
+
*/
|
|
67
|
+
waitForConnection(): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Send input data to the PTY session.
|
|
70
|
+
*
|
|
71
|
+
* Sends keyboard input or commands to the terminal session. The data will be
|
|
72
|
+
* processed as if it was typed in the terminal.
|
|
73
|
+
*
|
|
74
|
+
* @param {string | Uint8Array} data - Input data to send (commands, keystrokes, etc.)
|
|
75
|
+
* @throws {Error} If PTY is not connected or sending fails
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* // Send a command
|
|
79
|
+
* await ptyHandle.sendInput('ls -la\n');
|
|
80
|
+
*
|
|
81
|
+
* // Send raw bytes
|
|
82
|
+
* await ptyHandle.sendInput(new Uint8Array([3])); // Ctrl+C
|
|
83
|
+
*/
|
|
84
|
+
sendInput(data: string | Uint8Array): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Resize the PTY terminal dimensions.
|
|
87
|
+
*
|
|
88
|
+
* Changes the terminal size which will notify terminal applications
|
|
89
|
+
* about the new dimensions via SIGWINCH signal.
|
|
90
|
+
*
|
|
91
|
+
* @param {number} cols - New number of terminal columns
|
|
92
|
+
* @param {number} rows - New number of terminal rows
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* // Resize to 120x30
|
|
96
|
+
* await ptyHandle.resize(120, 30);
|
|
97
|
+
*/
|
|
98
|
+
resize(cols: number, rows: number): Promise<PtySessionInfo>;
|
|
99
|
+
/**
|
|
100
|
+
* Disconnect from the PTY session and clean up resources.
|
|
101
|
+
*
|
|
102
|
+
* Closes the WebSocket connection and releases any associated resources.
|
|
103
|
+
* Should be called when done with the PTY session.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* // Always clean up when done
|
|
107
|
+
* try {
|
|
108
|
+
* // ... use PTY session
|
|
109
|
+
* } finally {
|
|
110
|
+
* await ptyHandle.disconnect();
|
|
111
|
+
* }
|
|
112
|
+
*/
|
|
113
|
+
disconnect(): Promise<void>;
|
|
114
|
+
/**
|
|
115
|
+
* Wait for the PTY process to exit and return the result.
|
|
116
|
+
*
|
|
117
|
+
* This method blocks until the PTY process terminates and returns
|
|
118
|
+
* information about how it exited.
|
|
119
|
+
*
|
|
120
|
+
* @returns {Promise<PtyResult>} Result containing exit code and error information
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* // Wait for process to complete
|
|
124
|
+
* const result = await ptyHandle.wait();
|
|
125
|
+
*
|
|
126
|
+
* if (result.exitCode === 0) {
|
|
127
|
+
* console.log('Process completed successfully');
|
|
128
|
+
* } else {
|
|
129
|
+
* console.log(`Process failed with code: ${result.exitCode}`);
|
|
130
|
+
* if (result.error) {
|
|
131
|
+
* console.log(`Error: ${result.error}`);
|
|
132
|
+
* }
|
|
133
|
+
* }
|
|
134
|
+
*/
|
|
135
|
+
wait(): Promise<PtyResult>;
|
|
136
|
+
/**
|
|
137
|
+
* Kill the PTY process and terminate the session.
|
|
138
|
+
*
|
|
139
|
+
* Forcefully terminates the PTY session and its associated process.
|
|
140
|
+
* This operation is irreversible and will cause the PTY to exit immediately.
|
|
141
|
+
*
|
|
142
|
+
* @throws {Error} If the kill operation fails
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* // Kill a long-running process
|
|
146
|
+
* await ptyHandle.kill();
|
|
147
|
+
*
|
|
148
|
+
* // Wait to confirm termination
|
|
149
|
+
* const result = await ptyHandle.wait();
|
|
150
|
+
* console.log(`Process terminated with exit code: ${result.exitCode}`);
|
|
151
|
+
*/
|
|
152
|
+
kill(): Promise<void>;
|
|
153
|
+
private setupWebSocketHandlers;
|
|
154
|
+
}
|
package/src/PtyHandle.js
ADDED
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2025 Daytona Platforms Inc.
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.PtyHandle = void 0;
|
|
8
|
+
const tslib_1 = require("tslib");
|
|
9
|
+
const isomorphic_ws_1 = tslib_1.__importDefault(require("isomorphic-ws"));
|
|
10
|
+
const DaytonaError_1 = require("./errors/DaytonaError");
|
|
11
|
+
/**
|
|
12
|
+
* PTY session handle for managing a single PTY session.
|
|
13
|
+
*
|
|
14
|
+
* Provides methods for sending input, resizing the terminal, waiting for completion,
|
|
15
|
+
* and managing the WebSocket connection to a PTY session.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* // Create a PTY session
|
|
20
|
+
* const ptyHandle = await process.createPty({
|
|
21
|
+
* id: 'my-session',
|
|
22
|
+
* cols: 120,
|
|
23
|
+
* rows: 30,
|
|
24
|
+
* onData: (data) => {
|
|
25
|
+
* const text = new TextDecoder().decode(data);
|
|
26
|
+
* process.stdout.write(text);
|
|
27
|
+
* },
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
*
|
|
31
|
+
* // Send commands
|
|
32
|
+
* await ptyHandle.sendInput('ls -la\n');
|
|
33
|
+
* await ptyHandle.sendInput('exit\n');
|
|
34
|
+
*
|
|
35
|
+
* // Wait for completion
|
|
36
|
+
* const result = await ptyHandle.wait();
|
|
37
|
+
* console.log(`PTY exited with code: ${result.exitCode}`);
|
|
38
|
+
*
|
|
39
|
+
* // Clean up
|
|
40
|
+
* await ptyHandle.disconnect();
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
class PtyHandle {
|
|
44
|
+
ws;
|
|
45
|
+
handleResize;
|
|
46
|
+
handleKill;
|
|
47
|
+
onPty;
|
|
48
|
+
sessionId;
|
|
49
|
+
_exitCode;
|
|
50
|
+
_error;
|
|
51
|
+
connected = false;
|
|
52
|
+
connectionEstablished = false; // Track control message received
|
|
53
|
+
constructor(ws, handleResize, handleKill, onPty, sessionId) {
|
|
54
|
+
this.ws = ws;
|
|
55
|
+
this.handleResize = handleResize;
|
|
56
|
+
this.handleKill = handleKill;
|
|
57
|
+
this.onPty = onPty;
|
|
58
|
+
this.sessionId = sessionId;
|
|
59
|
+
this.setupWebSocketHandlers();
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Exit code of the PTY process (if terminated)
|
|
63
|
+
*/
|
|
64
|
+
get exitCode() {
|
|
65
|
+
return this._exitCode;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Error message if the PTY failed
|
|
69
|
+
*/
|
|
70
|
+
get error() {
|
|
71
|
+
return this._error;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Check if connected to the PTY session
|
|
75
|
+
*/
|
|
76
|
+
isConnected() {
|
|
77
|
+
return this.connected && this.ws.readyState === isomorphic_ws_1.default.OPEN;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Wait for the WebSocket connection to be established.
|
|
81
|
+
*
|
|
82
|
+
* This method ensures the PTY session is ready to receive input and send output.
|
|
83
|
+
* It waits for the server to confirm the connection is established.
|
|
84
|
+
*
|
|
85
|
+
* @throws {Error} If connection times out (10 seconds) or connection fails
|
|
86
|
+
*/
|
|
87
|
+
async waitForConnection() {
|
|
88
|
+
if (this.connectionEstablished) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
return new Promise((resolve, reject) => {
|
|
92
|
+
const timeout = setTimeout(() => {
|
|
93
|
+
reject(new DaytonaError_1.DaytonaError('PTY connection timeout'));
|
|
94
|
+
}, 10000); // 10 second timeout
|
|
95
|
+
const checkConnection = () => {
|
|
96
|
+
if (this.connectionEstablished) {
|
|
97
|
+
clearTimeout(timeout);
|
|
98
|
+
resolve();
|
|
99
|
+
}
|
|
100
|
+
else if (this.ws.readyState === isomorphic_ws_1.default.CLOSED || this._error) {
|
|
101
|
+
clearTimeout(timeout);
|
|
102
|
+
reject(new DaytonaError_1.DaytonaError(this._error || 'Connection failed'));
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
setTimeout(checkConnection, 100);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
checkConnection();
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Send input data to the PTY session.
|
|
113
|
+
*
|
|
114
|
+
* Sends keyboard input or commands to the terminal session. The data will be
|
|
115
|
+
* processed as if it was typed in the terminal.
|
|
116
|
+
*
|
|
117
|
+
* @param {string | Uint8Array} data - Input data to send (commands, keystrokes, etc.)
|
|
118
|
+
* @throws {Error} If PTY is not connected or sending fails
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* // Send a command
|
|
122
|
+
* await ptyHandle.sendInput('ls -la\n');
|
|
123
|
+
*
|
|
124
|
+
* // Send raw bytes
|
|
125
|
+
* await ptyHandle.sendInput(new Uint8Array([3])); // Ctrl+C
|
|
126
|
+
*/
|
|
127
|
+
async sendInput(data) {
|
|
128
|
+
if (!this.isConnected()) {
|
|
129
|
+
throw new DaytonaError_1.DaytonaError('PTY is not connected');
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
if (typeof data === 'string') {
|
|
133
|
+
this.ws.send(new TextEncoder().encode(data));
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
this.ws.send(data);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
141
|
+
throw new DaytonaError_1.DaytonaError(`Failed to send input to PTY: ${errorMessage}`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Resize the PTY terminal dimensions.
|
|
146
|
+
*
|
|
147
|
+
* Changes the terminal size which will notify terminal applications
|
|
148
|
+
* about the new dimensions via SIGWINCH signal.
|
|
149
|
+
*
|
|
150
|
+
* @param {number} cols - New number of terminal columns
|
|
151
|
+
* @param {number} rows - New number of terminal rows
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* // Resize to 120x30
|
|
155
|
+
* await ptyHandle.resize(120, 30);
|
|
156
|
+
*/
|
|
157
|
+
async resize(cols, rows) {
|
|
158
|
+
return await this.handleResize(cols, rows);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Disconnect from the PTY session and clean up resources.
|
|
162
|
+
*
|
|
163
|
+
* Closes the WebSocket connection and releases any associated resources.
|
|
164
|
+
* Should be called when done with the PTY session.
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* // Always clean up when done
|
|
168
|
+
* try {
|
|
169
|
+
* // ... use PTY session
|
|
170
|
+
* } finally {
|
|
171
|
+
* await ptyHandle.disconnect();
|
|
172
|
+
* }
|
|
173
|
+
*/
|
|
174
|
+
async disconnect() {
|
|
175
|
+
if (this.ws) {
|
|
176
|
+
try {
|
|
177
|
+
this.ws.close();
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
// Ignore close errors
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Wait for the PTY process to exit and return the result.
|
|
186
|
+
*
|
|
187
|
+
* This method blocks until the PTY process terminates and returns
|
|
188
|
+
* information about how it exited.
|
|
189
|
+
*
|
|
190
|
+
* @returns {Promise<PtyResult>} Result containing exit code and error information
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* // Wait for process to complete
|
|
194
|
+
* const result = await ptyHandle.wait();
|
|
195
|
+
*
|
|
196
|
+
* if (result.exitCode === 0) {
|
|
197
|
+
* console.log('Process completed successfully');
|
|
198
|
+
* } else {
|
|
199
|
+
* console.log(`Process failed with code: ${result.exitCode}`);
|
|
200
|
+
* if (result.error) {
|
|
201
|
+
* console.log(`Error: ${result.error}`);
|
|
202
|
+
* }
|
|
203
|
+
* }
|
|
204
|
+
*/
|
|
205
|
+
async wait() {
|
|
206
|
+
return new Promise((resolve, reject) => {
|
|
207
|
+
if (this._exitCode !== undefined) {
|
|
208
|
+
resolve({
|
|
209
|
+
exitCode: this._exitCode,
|
|
210
|
+
error: this._error,
|
|
211
|
+
});
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
const checkExit = () => {
|
|
215
|
+
if (this._exitCode !== undefined) {
|
|
216
|
+
resolve({
|
|
217
|
+
exitCode: this._exitCode,
|
|
218
|
+
error: this._error,
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
else if (this._error) {
|
|
222
|
+
reject(new DaytonaError_1.DaytonaError(this._error));
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
setTimeout(checkExit, 100);
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
checkExit();
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Kill the PTY process and terminate the session.
|
|
233
|
+
*
|
|
234
|
+
* Forcefully terminates the PTY session and its associated process.
|
|
235
|
+
* This operation is irreversible and will cause the PTY to exit immediately.
|
|
236
|
+
*
|
|
237
|
+
* @throws {Error} If the kill operation fails
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* // Kill a long-running process
|
|
241
|
+
* await ptyHandle.kill();
|
|
242
|
+
*
|
|
243
|
+
* // Wait to confirm termination
|
|
244
|
+
* const result = await ptyHandle.wait();
|
|
245
|
+
* console.log(`Process terminated with exit code: ${result.exitCode}`);
|
|
246
|
+
*/
|
|
247
|
+
async kill() {
|
|
248
|
+
return await this.handleKill();
|
|
249
|
+
}
|
|
250
|
+
setupWebSocketHandlers() {
|
|
251
|
+
// Set binary type for binary data handling
|
|
252
|
+
if ('binaryType' in this.ws) {
|
|
253
|
+
this.ws.binaryType = 'arraybuffer';
|
|
254
|
+
}
|
|
255
|
+
// Handle WebSocket open
|
|
256
|
+
const handleOpen = async () => {
|
|
257
|
+
this.connected = true;
|
|
258
|
+
};
|
|
259
|
+
// Handle WebSocket messages - control messages and PTY data
|
|
260
|
+
const handleMessage = async (event) => {
|
|
261
|
+
try {
|
|
262
|
+
const data = event && typeof event === 'object' && 'data' in event ? event.data : event;
|
|
263
|
+
if (typeof data === 'string') {
|
|
264
|
+
// Try to parse as control message first
|
|
265
|
+
try {
|
|
266
|
+
const controlMsg = JSON.parse(data);
|
|
267
|
+
if (controlMsg.type === 'control') {
|
|
268
|
+
if (controlMsg.status === 'connected') {
|
|
269
|
+
this.connectionEstablished = true;
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
else if (controlMsg.status === 'error') {
|
|
273
|
+
this._error = controlMsg.error || 'Unknown connection error';
|
|
274
|
+
this.connected = false;
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
catch {
|
|
280
|
+
// Not a control message, treat as PTY output
|
|
281
|
+
}
|
|
282
|
+
// Regular PTY text output
|
|
283
|
+
if (this.onPty) {
|
|
284
|
+
await this.onPty(new TextEncoder().encode(data));
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
// Handle binary data (terminal output)
|
|
289
|
+
let bytes;
|
|
290
|
+
if (data instanceof ArrayBuffer) {
|
|
291
|
+
bytes = new Uint8Array(data);
|
|
292
|
+
}
|
|
293
|
+
else if (ArrayBuffer.isView(data)) {
|
|
294
|
+
bytes = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
295
|
+
}
|
|
296
|
+
else if (data instanceof Blob) {
|
|
297
|
+
const buffer = await data.arrayBuffer();
|
|
298
|
+
bytes = new Uint8Array(buffer);
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
throw new DaytonaError_1.DaytonaError(`Unsupported message data type: ${Object.prototype.toString.call(data)}`);
|
|
302
|
+
}
|
|
303
|
+
if (this.onPty) {
|
|
304
|
+
await this.onPty(bytes);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
catch (error) {
|
|
309
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
310
|
+
throw new DaytonaError_1.DaytonaError(`Error handling PTY message: ${errorMessage}`);
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
// Handle WebSocket errors
|
|
314
|
+
const handleError = async (error) => {
|
|
315
|
+
let errorMessage;
|
|
316
|
+
if (error instanceof Error) {
|
|
317
|
+
errorMessage = error.message;
|
|
318
|
+
}
|
|
319
|
+
else if (error && error instanceof Event) {
|
|
320
|
+
errorMessage = 'WebSocket connection error';
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
errorMessage = String(error);
|
|
324
|
+
}
|
|
325
|
+
this._error = errorMessage;
|
|
326
|
+
this.connected = false;
|
|
327
|
+
};
|
|
328
|
+
// Handle WebSocket close - parse structured exit data
|
|
329
|
+
const handleClose = async (event) => {
|
|
330
|
+
this.connected = false;
|
|
331
|
+
// Parse structured exit data from close reason
|
|
332
|
+
if (event && event.reason) {
|
|
333
|
+
try {
|
|
334
|
+
const exitData = JSON.parse(event.reason);
|
|
335
|
+
if (typeof exitData.exitCode === 'number') {
|
|
336
|
+
this._exitCode = exitData.exitCode;
|
|
337
|
+
// Store exit reason if provided (undefined for exitCode 0)
|
|
338
|
+
if (exitData.exitReason) {
|
|
339
|
+
this._error = exitData.exitReason;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
// Handle error messages from server (e.g., "PTY session not found")
|
|
343
|
+
if (exitData.error) {
|
|
344
|
+
this._error = exitData.error;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
catch {
|
|
348
|
+
if (event.code === 1000) {
|
|
349
|
+
this._exitCode = 0;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
// Default to exit code 0 if we can't parse it and it was a normal close
|
|
354
|
+
if (this._exitCode === undefined && event && event.code === 1000) {
|
|
355
|
+
this._exitCode = 0;
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
// Attach event listeners based on WebSocket implementation
|
|
359
|
+
if (this.ws.addEventListener) {
|
|
360
|
+
// Browser WebSocket
|
|
361
|
+
this.ws.addEventListener('open', handleOpen);
|
|
362
|
+
this.ws.addEventListener('message', handleMessage);
|
|
363
|
+
this.ws.addEventListener('error', handleError);
|
|
364
|
+
this.ws.addEventListener('close', handleClose);
|
|
365
|
+
}
|
|
366
|
+
else if ('on' in this.ws && typeof this.ws.on === 'function') {
|
|
367
|
+
// Node.js WebSocket
|
|
368
|
+
this.ws.on('open', handleOpen);
|
|
369
|
+
this.ws.on('message', handleMessage);
|
|
370
|
+
this.ws.on('error', handleError);
|
|
371
|
+
this.ws.on('close', handleClose);
|
|
372
|
+
}
|
|
373
|
+
else {
|
|
374
|
+
throw new DaytonaError_1.DaytonaError('Unsupported WebSocket implementation');
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
exports.PtyHandle = PtyHandle;
|
|
379
|
+
//# sourceMappingURL=PtyHandle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PtyHandle.js","sourceRoot":"","sources":["../../../../libs/sdk-typescript/src/PtyHandle.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;AAEH,0EAAqC;AAErC,wDAAoD;AAGpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAa,SAAS;IAOD;IACA;IACA;IACA;IACR;IAVH,SAAS,CAAS;IAClB,MAAM,CAAS;IACf,SAAS,GAAG,KAAK,CAAA;IACjB,qBAAqB,GAAG,KAAK,CAAA,CAAC,iCAAiC;IAEvE,YACmB,EAAa,EACb,YAAqE,EACrE,UAA+B,EAC/B,KAAiD,EACzD,SAAiB;QAJT,OAAE,GAAF,EAAE,CAAW;QACb,iBAAY,GAAZ,YAAY,CAAyD;QACrE,eAAU,GAAV,UAAU,CAAqB;QAC/B,UAAK,GAAL,KAAK,CAA4C;QACzD,cAAS,GAAT,SAAS,CAAQ;QAE1B,IAAI,CAAC,sBAA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;YAC9C,IAAI,CAAC,EAAE,CAAC,gBAAgB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAA;QAChD,CAAC;aAAM,IAAI,IAAI,IAAI,IAAI,CAAC,EAAE,IAAI,OAAO,IAAI,CAAC,EAAE,CAAC,EAAE,KAAK,UAAU,EAAE,CAAC;YAC/D,oBAAoB;YACpB,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;YAC9B,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,SAAS,EAAE,aAAa,CAAC,CAAA;YACpC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,CAAC,CAAA;YAChC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,CAAC,CAAA;QAClC,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,2BAAY,CAAC,sCAAsC,CAAC,CAAA;QAChE,CAAC;IACH,CAAC;CACF;AApVD,8BAoVC"}
|
package/src/index.d.ts
CHANGED
|
@@ -15,3 +15,6 @@ export type { BarChart, BoxAndWhiskerChart, Chart, CompositeChart, LineChart, Pi
|
|
|
15
15
|
export { SandboxState } from '@daytonaio/api-client';
|
|
16
16
|
export type { FileInfo, GitStatus, ListBranchResponse, Match, ReplaceResult, SearchFilesResponse, } from '@daytonaio/api-client';
|
|
17
17
|
export type { ScreenshotRegion, ScreenshotOptions } from './ComputerUse';
|
|
18
|
+
export * from './Process';
|
|
19
|
+
export * from './PtyHandle';
|
|
20
|
+
export * from './types/Pty';
|
package/src/index.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.SandboxState = exports.ChartType = exports.Display = exports.Screenshot = exports.Keyboard = exports.Mouse = exports.ComputerUse = exports.Sandbox = exports.Image = exports.DaytonaError = exports.Process = exports.LspLanguageId = exports.Git = exports.FileSystem = exports.Daytona = exports.CodeLanguage = void 0;
|
|
8
|
+
const tslib_1 = require("tslib");
|
|
8
9
|
var Daytona_1 = require("./Daytona");
|
|
9
10
|
Object.defineProperty(exports, "CodeLanguage", { enumerable: true, get: function () { return Daytona_1.CodeLanguage; } });
|
|
10
11
|
Object.defineProperty(exports, "Daytona", { enumerable: true, get: function () { return Daytona_1.Daytona; } });
|
|
@@ -35,4 +36,7 @@ var Charts_1 = require("./types/Charts");
|
|
|
35
36
|
Object.defineProperty(exports, "ChartType", { enumerable: true, get: function () { return Charts_1.ChartType; } });
|
|
36
37
|
var api_client_1 = require("@daytonaio/api-client");
|
|
37
38
|
Object.defineProperty(exports, "SandboxState", { enumerable: true, get: function () { return api_client_1.SandboxState; } });
|
|
39
|
+
tslib_1.__exportStar(require("./Process"), exports);
|
|
40
|
+
tslib_1.__exportStar(require("./PtyHandle"), exports);
|
|
41
|
+
tslib_1.__exportStar(require("./types/Pty"), exports);
|
|
38
42
|
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/sdk-typescript/src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/sdk-typescript/src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;AAEH,qCAAiD;AAAxC,uGAAA,YAAY,OAAA;AAAE,kGAAA,OAAO,OAAA;AAS9B,2CAAyC;AAAhC,wGAAA,UAAU,OAAA;AACnB,6BAA2B;AAAlB,0FAAA,GAAG,OAAA;AACZ,yCAA2C;AAAlC,0GAAA,aAAa,OAAA;AACtB,qCAAmC;AAA1B,kGAAA,OAAO,OAAA;AAChB,0CAA0C;AAC1C,6DAA6D;AAC7D,sDAAoD;AAA3C,4GAAA,YAAY,OAAA;AACrB,iCAA+B;AAAtB,8FAAA,KAAK,OAAA;AACd,qCAAmC;AAA1B,kGAAA,OAAO,OAAA;AAGhB,6CAAiF;AAAxE,0GAAA,WAAW,OAAA;AAAE,oGAAA,KAAK,OAAA;AAAE,uGAAA,QAAQ,OAAA;AAAE,yGAAA,UAAU,OAAA;AAAE,sGAAA,OAAO,OAAA;AAE1D,2BAA2B;AAC3B,yCAA0C;AAAjC,mGAAA,SAAS,OAAA;AAWlB,oDAAoD;AAA3C,0GAAA,YAAY,OAAA;AAYrB,oDAAyB;AACzB,sDAA2B;AAC3B,sDAA2B"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for creating a PTY session
|
|
3
|
+
*/
|
|
4
|
+
export interface PtyCreateOptions {
|
|
5
|
+
/**
|
|
6
|
+
* The unique identifier for the PTY session
|
|
7
|
+
*/
|
|
8
|
+
id: string;
|
|
9
|
+
/**
|
|
10
|
+
* Starting directory for the PTY session, defaults to the sandbox's working directory
|
|
11
|
+
*/
|
|
12
|
+
cwd?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Environment variables for the PTY session
|
|
15
|
+
*/
|
|
16
|
+
envs?: Record<string, string>;
|
|
17
|
+
/**
|
|
18
|
+
* Number of terminal columns
|
|
19
|
+
*/
|
|
20
|
+
cols?: number;
|
|
21
|
+
/**
|
|
22
|
+
* Number of terminal rows
|
|
23
|
+
*/
|
|
24
|
+
rows?: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Options for connecting to a PTY session
|
|
28
|
+
*/
|
|
29
|
+
export interface PtyConnectOptions {
|
|
30
|
+
/**
|
|
31
|
+
* Callback to handle PTY output data
|
|
32
|
+
*/
|
|
33
|
+
onData: (data: Uint8Array) => void | Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* PTY session result on exit
|
|
37
|
+
*/
|
|
38
|
+
export interface PtyResult {
|
|
39
|
+
/**
|
|
40
|
+
* Exit code when the PTY process ends
|
|
41
|
+
*/
|
|
42
|
+
exitCode?: number;
|
|
43
|
+
/**
|
|
44
|
+
* Error message if the PTY failed
|
|
45
|
+
*/
|
|
46
|
+
error?: string;
|
|
47
|
+
}
|
package/src/types/Pty.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Pty.js","sourceRoot":"","sources":["../../../../../libs/sdk-typescript/src/types/Pty.ts"],"names":[],"mappings":";AAAA;;;GAGG"}
|