@rstreamlabs/webtty 1.1.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.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # `@rstreamlabs/webtty`
2
+
3
+ Client-side implementation of the rstream WebTTY protocol.
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Client-level configuration for WebTTY.
3
+ */
4
+ interface WebTTYClientConfig {
5
+ /**
6
+ * The remote WebSocket endpoint.
7
+ */
8
+ url: string | URL;
9
+ /**
10
+ * Whether to send heartbeats to keep the session alive.
11
+ *
12
+ * @default true
13
+ */
14
+ sendHeartbeat?: boolean;
15
+ /**
16
+ * Heartbeat interval in milliseconds.
17
+ *
18
+ * @default 5000
19
+ */
20
+ heartbeatIntervalMs?: number;
21
+ }
22
+ /**
23
+ * Execution-level configuration for WebTTY.
24
+ */
25
+ interface WebTTYExecutionConfig {
26
+ /**
27
+ * Command arguments to run on the remote side.
28
+ */
29
+ cmdArgs?: string[];
30
+ /**
31
+ * Environment variables to set for the remote session.
32
+ */
33
+ envVars?: Array<{
34
+ key: string;
35
+ value: string;
36
+ }>;
37
+ /**
38
+ * Whether the server should allocate a TTY.
39
+ *
40
+ * @default true
41
+ */
42
+ allocateTty?: boolean;
43
+ /**
44
+ * Whether the session is interactive.
45
+ *
46
+ * @default true
47
+ */
48
+ interactive?: boolean;
49
+ /**
50
+ * Optional username (by name or ID).
51
+ */
52
+ username?: string | number;
53
+ /**
54
+ * Optional working directory for the remote process.
55
+ */
56
+ workdir?: string;
57
+ }
58
+ /**
59
+ * WebTTY events for handling session state and data streams.
60
+ */
61
+ interface WebTTYEvents {
62
+ /**
63
+ * Called whenever the server sends data on STDOUT.
64
+ */
65
+ onStdout?: (chunk: Uint8Array) => void;
66
+ /**
67
+ * Called whenever STDOUT reaches end-of-stream.
68
+ */
69
+ onStdoutEos?: () => void;
70
+ /**
71
+ * Called whenever the server sends data on STDERR.
72
+ */
73
+ onStderr?: (chunk: Uint8Array) => void;
74
+ /**
75
+ * Called whenever STDERR reaches end-of-stream.
76
+ */
77
+ onStderrEos?: () => void;
78
+ /**
79
+ * Called when the connection is established.
80
+ */
81
+ onConnect?: () => void;
82
+ /**
83
+ * Called when the remote process exits, providing the exit code.
84
+ */
85
+ onComplete?: (exitCode: number) => void;
86
+ /**
87
+ * Called when the server or connection encounters an error.
88
+ */
89
+ onError?: (errMsg: string) => void;
90
+ }
91
+ /**
92
+ * WebTTY client for managing remote execution sessions.
93
+ */
94
+ declare class WebTTY {
95
+ private ws;
96
+ private connectionState;
97
+ private heartbeatTimer;
98
+ private readonly clientConfig;
99
+ private readonly execConfig;
100
+ private readonly events;
101
+ /**
102
+ * Creates a new WebTTY instance.
103
+ *
104
+ * @param clientConfig - WebSocket connection configuration.
105
+ * @param execConfig - Execution parameters.
106
+ * @param events - Event callbacks for the session.
107
+ */
108
+ constructor(clientConfig: WebTTYClientConfig, execConfig?: WebTTYExecutionConfig, events?: WebTTYEvents);
109
+ /**
110
+ * Connects to the WebTTY server and starts the session.
111
+ */
112
+ connect(): void;
113
+ /**
114
+ * Sends data to the remote server's STDIN.
115
+ *
116
+ * @param data - The data to send.
117
+ */
118
+ writeStdin(data: Uint8Array): void;
119
+ /**
120
+ * Closes the remote STDIN stream (EOF).
121
+ */
122
+ closeStdin(): void;
123
+ /**
124
+ * Sends a "resize" request to the remote TTY with the provided rows and columns (and optional pixel sizes).
125
+ */
126
+ resize(rows: number, cols: number, xpixel?: number, ypixel?: number): void;
127
+ /**
128
+ * Terminates the WebTTY session immediately.
129
+ */
130
+ disconnect(): void;
131
+ private handleOpen;
132
+ private handleMessage;
133
+ private handleClose;
134
+ private handleError;
135
+ private sendHeartbeat;
136
+ private send;
137
+ /**
138
+ * Closes the WebTTY session and fires exactly one of:
139
+ * - onComplete(exitCode) // if a number is passed
140
+ * - onError(errorMessage) // if a string is passed
141
+ * If no argument is given, treat as an unknown error scenario.
142
+ */
143
+ private close;
144
+ }
145
+
146
+ export { WebTTY, type WebTTYClientConfig, type WebTTYEvents, type WebTTYExecutionConfig };
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Client-level configuration for WebTTY.
3
+ */
4
+ interface WebTTYClientConfig {
5
+ /**
6
+ * The remote WebSocket endpoint.
7
+ */
8
+ url: string | URL;
9
+ /**
10
+ * Whether to send heartbeats to keep the session alive.
11
+ *
12
+ * @default true
13
+ */
14
+ sendHeartbeat?: boolean;
15
+ /**
16
+ * Heartbeat interval in milliseconds.
17
+ *
18
+ * @default 5000
19
+ */
20
+ heartbeatIntervalMs?: number;
21
+ }
22
+ /**
23
+ * Execution-level configuration for WebTTY.
24
+ */
25
+ interface WebTTYExecutionConfig {
26
+ /**
27
+ * Command arguments to run on the remote side.
28
+ */
29
+ cmdArgs?: string[];
30
+ /**
31
+ * Environment variables to set for the remote session.
32
+ */
33
+ envVars?: Array<{
34
+ key: string;
35
+ value: string;
36
+ }>;
37
+ /**
38
+ * Whether the server should allocate a TTY.
39
+ *
40
+ * @default true
41
+ */
42
+ allocateTty?: boolean;
43
+ /**
44
+ * Whether the session is interactive.
45
+ *
46
+ * @default true
47
+ */
48
+ interactive?: boolean;
49
+ /**
50
+ * Optional username (by name or ID).
51
+ */
52
+ username?: string | number;
53
+ /**
54
+ * Optional working directory for the remote process.
55
+ */
56
+ workdir?: string;
57
+ }
58
+ /**
59
+ * WebTTY events for handling session state and data streams.
60
+ */
61
+ interface WebTTYEvents {
62
+ /**
63
+ * Called whenever the server sends data on STDOUT.
64
+ */
65
+ onStdout?: (chunk: Uint8Array) => void;
66
+ /**
67
+ * Called whenever STDOUT reaches end-of-stream.
68
+ */
69
+ onStdoutEos?: () => void;
70
+ /**
71
+ * Called whenever the server sends data on STDERR.
72
+ */
73
+ onStderr?: (chunk: Uint8Array) => void;
74
+ /**
75
+ * Called whenever STDERR reaches end-of-stream.
76
+ */
77
+ onStderrEos?: () => void;
78
+ /**
79
+ * Called when the connection is established.
80
+ */
81
+ onConnect?: () => void;
82
+ /**
83
+ * Called when the remote process exits, providing the exit code.
84
+ */
85
+ onComplete?: (exitCode: number) => void;
86
+ /**
87
+ * Called when the server or connection encounters an error.
88
+ */
89
+ onError?: (errMsg: string) => void;
90
+ }
91
+ /**
92
+ * WebTTY client for managing remote execution sessions.
93
+ */
94
+ declare class WebTTY {
95
+ private ws;
96
+ private connectionState;
97
+ private heartbeatTimer;
98
+ private readonly clientConfig;
99
+ private readonly execConfig;
100
+ private readonly events;
101
+ /**
102
+ * Creates a new WebTTY instance.
103
+ *
104
+ * @param clientConfig - WebSocket connection configuration.
105
+ * @param execConfig - Execution parameters.
106
+ * @param events - Event callbacks for the session.
107
+ */
108
+ constructor(clientConfig: WebTTYClientConfig, execConfig?: WebTTYExecutionConfig, events?: WebTTYEvents);
109
+ /**
110
+ * Connects to the WebTTY server and starts the session.
111
+ */
112
+ connect(): void;
113
+ /**
114
+ * Sends data to the remote server's STDIN.
115
+ *
116
+ * @param data - The data to send.
117
+ */
118
+ writeStdin(data: Uint8Array): void;
119
+ /**
120
+ * Closes the remote STDIN stream (EOF).
121
+ */
122
+ closeStdin(): void;
123
+ /**
124
+ * Sends a "resize" request to the remote TTY with the provided rows and columns (and optional pixel sizes).
125
+ */
126
+ resize(rows: number, cols: number, xpixel?: number, ypixel?: number): void;
127
+ /**
128
+ * Terminates the WebTTY session immediately.
129
+ */
130
+ disconnect(): void;
131
+ private handleOpen;
132
+ private handleMessage;
133
+ private handleClose;
134
+ private handleError;
135
+ private sendHeartbeat;
136
+ private send;
137
+ /**
138
+ * Closes the WebTTY session and fires exactly one of:
139
+ * - onComplete(exitCode) // if a number is passed
140
+ * - onError(errorMessage) // if a string is passed
141
+ * If no argument is given, treat as an unknown error scenario.
142
+ */
143
+ private close;
144
+ }
145
+
146
+ export { WebTTY, type WebTTYClientConfig, type WebTTYEvents, type WebTTYExecutionConfig };