@rstreamlabs/webtty 1.11.2 → 1.12.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/README.md +100 -28
- package/dist/{chunk-2XNLPDKP.mjs → chunk-BSMXY5EO.mjs} +1097 -130
- package/dist/index.d.mts +188 -7
- package/dist/index.d.ts +188 -7
- package/dist/index.js +1099 -130
- package/dist/index.mjs +5 -1
- package/dist/node.d.mts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/node.js +1099 -130
- package/dist/node.mjs +5 -1
- package/examples/filesystem-sidecar/package.json +3 -3
- package/examples/remote-command/README.md +15 -0
- package/examples/remote-command/package.json +3 -3
- package/examples/remote-command/src/main.ts +3 -1
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# `@rstreamlabs/webtty`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
WebTTY is rstream's remote terminal and command-execution protocol. A server runs on the remote machine and an operator connects through the CLI or a browser. This package implements the browser client so an application can exchange terminal input/output and track process completion.
|
|
4
4
|
|
|
5
5
|
Use this package when you need to connect a web application to a WebTTY server
|
|
6
6
|
over WebSocket or WebTransport. It handles the protobuf session handshake,
|
|
@@ -52,18 +52,6 @@ webtty.connect();
|
|
|
52
52
|
|
|
53
53
|
## Interactive Sessions
|
|
54
54
|
|
|
55
|
-
Connection failures are delivered once through `onError`, including normal
|
|
56
|
-
WebTransport closure before the stream opens. Disconnecting also releases a
|
|
57
|
-
stream that becomes available after the opening was cancelled. A normal close
|
|
58
|
-
after opening still drains buffered output before reporting the session result.
|
|
59
|
-
|
|
60
|
-
Error messages redact values from the configured endpoint's query parameters,
|
|
61
|
-
userinfo and fragment, including their common URL-encoded forms. Avoid logging
|
|
62
|
-
the endpoint separately. An identifiable browser `SecurityError` points to
|
|
63
|
-
browser policy and `connect-src`; an empty browser error reports that diagnostic
|
|
64
|
-
details are unavailable. Such an error does not establish that CSP is the cause.
|
|
65
|
-
Invalid endpoint configuration still throws synchronously without echoing the URL.
|
|
66
|
-
|
|
67
55
|
For an interactive terminal, write encoded input to stdin and forward terminal
|
|
68
56
|
resize events.
|
|
69
57
|
|
|
@@ -82,8 +70,23 @@ webtty.writeStdin(encoder.encode("whoami\n"));
|
|
|
82
70
|
webtty.resize(40, 120);
|
|
83
71
|
```
|
|
84
72
|
|
|
85
|
-
Call `closeStdin()` to send EOF, or `disconnect()` to
|
|
86
|
-
|
|
73
|
+
Call `closeStdin()` to send EOF, or `disconnect()` to release the reader.
|
|
74
|
+
For an Engine-managed detached execution, releasing the reader leaves the
|
|
75
|
+
command running within its original execution budget.
|
|
76
|
+
|
|
77
|
+
## Connection failures and diagnostics
|
|
78
|
+
|
|
79
|
+
Connection failures are delivered once through `onError`, including normal
|
|
80
|
+
WebTransport closure before the stream opens. Disconnecting also releases a
|
|
81
|
+
stream that becomes available after the opening was cancelled. A normal close
|
|
82
|
+
after opening still drains buffered output before reporting the session result.
|
|
83
|
+
|
|
84
|
+
Error messages redact values from the configured endpoint's query parameters,
|
|
85
|
+
userinfo and fragment, including their common URL-encoded forms. Avoid logging
|
|
86
|
+
the endpoint separately. An identifiable browser `SecurityError` points to
|
|
87
|
+
browser policy and `connect-src`; an empty browser error reports that diagnostic
|
|
88
|
+
details are unavailable. Such an error does not establish that CSP is the cause.
|
|
89
|
+
Invalid endpoint configuration still throws synchronously without echoing the URL.
|
|
87
90
|
|
|
88
91
|
## Execute Commands
|
|
89
92
|
|
|
@@ -112,8 +115,34 @@ console.log(result.stdout);
|
|
|
112
115
|
|
|
113
116
|
Use `openWebTTYCommand` when you need live control over a running command. It
|
|
114
117
|
returns a command object with replayable stdout/stderr, ordered log iteration,
|
|
115
|
-
stdin writes, EOF handling, `wait()`, and `kill()`/`terminate()
|
|
116
|
-
|
|
118
|
+
stdin writes, EOF handling, `wait()`, and explicit `kill()`/`terminate()`.
|
|
119
|
+
|
|
120
|
+
`terminate({ signal?, timeoutMs? })` sends a protocol termination request and
|
|
121
|
+
waits for the native process result, including final stdout/stderr. `kill()` is
|
|
122
|
+
an alias with the same semantics. The default confirmation wait is 65 seconds.
|
|
123
|
+
`wait()` and `exitCode` retain the native result, including a natural exit that
|
|
124
|
+
races with termination. Repeated requests do not restart termination.
|
|
125
|
+
|
|
126
|
+
Missing native support rejects the operation without disconnecting. An aborted
|
|
127
|
+
or timed-out confirmation wait leaves the remote result unknown and the reader
|
|
128
|
+
connected; `wait()` can still observe a later native result. Use `disconnect()`
|
|
129
|
+
when the application is finished with that reader. No local failure invents an
|
|
130
|
+
exit code. Managed clients must also check the Engine's `explicit_termination`
|
|
131
|
+
capability; an older relay can ignore a request even if a new native server
|
|
132
|
+
advertises support, in which case confirmation times out.
|
|
133
|
+
|
|
134
|
+
Low-level `WebTTY.canTerminate()` exposes native support after `onConnect`.
|
|
135
|
+
`WebTTY.requestTermination()` queues the request; only `onComplete` confirms its
|
|
136
|
+
outcome. Managed control permissions still apply independently of support.
|
|
137
|
+
|
|
138
|
+
Command output capture is bounded to 8 MiB by default (`maxOutputBytes` can set
|
|
139
|
+
another positive byte limit), and at most 32,768 nonempty chunks. Exceeding either
|
|
140
|
+
limit raises `WebTTYCommandOutputLimitError` on output readers and requests
|
|
141
|
+
termination. Further output is discarded while the bounded confirmation wait
|
|
142
|
+
continues; `wait()` still reports a native result if one arrives. If termination
|
|
143
|
+
cannot be confirmed, the command reader is disconnected with an unknown result.
|
|
144
|
+
Use the low-level `WebTTY` output callbacks for continuous streaming without
|
|
145
|
+
retaining a replayable command output buffer.
|
|
117
146
|
|
|
118
147
|
```ts
|
|
119
148
|
import { openWebTTYCommand } from "@rstreamlabs/webtty";
|
|
@@ -142,20 +171,62 @@ fresh short-lived token. When the WebTTY server is discovered through
|
|
|
142
171
|
`@rstreamlabs/tunnels`, pass the advertised `exec_path` value as `execPath`
|
|
143
172
|
instead of assuming `/`.
|
|
144
173
|
|
|
174
|
+
### Bounded detached execution
|
|
175
|
+
|
|
176
|
+
Fetch WebTTY capabilities from the same Engine that provides the authenticated
|
|
177
|
+
terminal URL, then pass them as `managed.capabilities`. The object returned by
|
|
178
|
+
`@rstreamlabs/tunnels`' WebTTY capabilities API is directly compatible.
|
|
179
|
+
|
|
180
|
+
```ts
|
|
181
|
+
const command = openWebTTYCommand(
|
|
182
|
+
{
|
|
183
|
+
url: authenticatedTerminalUrl,
|
|
184
|
+
managed: { capabilities, executionSeconds: 300 },
|
|
185
|
+
},
|
|
186
|
+
{ cmdArgs: ["sh", "-c", "run-job"], interactive: false, allocateTty: false },
|
|
187
|
+
);
|
|
188
|
+
await command.ready();
|
|
189
|
+
const executionId = command.managedSessionId;
|
|
190
|
+
// Save executionId before releasing the reader.
|
|
191
|
+
command.disconnect();
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
The SDK checks the advertised transport and maximum duration before connecting.
|
|
195
|
+
`ready()` waits for the relay's confirmation; `managedSessionId` then identifies
|
|
196
|
+
the same execution for later session API calls. `ready({ signal })` cancels only
|
|
197
|
+
that wait. A missing or zero budget preserves the ordinary connection-bound
|
|
198
|
+
lifetime. Detaching does not establish an exit result, and losing the opening
|
|
199
|
+
response does not make retrying the command safe.
|
|
200
|
+
|
|
201
|
+
Use the saved ID to inspect the session or obtain an authorized participant and
|
|
202
|
+
Attach grant. No new Open is needed to recover a running command. The original
|
|
203
|
+
deadline remains unchanged. This does not add restart survival or an output
|
|
204
|
+
cursor; historical output still depends on recording and retention permissions.
|
|
205
|
+
|
|
206
|
+
For any managed connection, including Attach, `managed.capabilities` also gates
|
|
207
|
+
explicit termination: both Engine and native server support are required. An
|
|
208
|
+
Attach without this capability snapshot cannot send Terminate. Current control
|
|
209
|
+
authority is still checked by the Engine for every request.
|
|
210
|
+
|
|
211
|
+
Omitting `executionSeconds` or setting it to zero keeps the ordinary connection
|
|
212
|
+
lifetime, including when the Engine reports `managed_protocol: false`. Supplying
|
|
213
|
+
that capability snapshot still prevents unsupported termination requests.
|
|
214
|
+
|
|
145
215
|
### Managed session attach
|
|
146
216
|
|
|
147
217
|
Engine-managed sessions are joined with a WebTTY `Attach` message. The attach
|
|
148
218
|
grant is obtained from the control-plane API, then sent as the first protobuf
|
|
149
219
|
message on the terminal stream. Terminal input and output stay on the WebTTY
|
|
150
|
-
data path. The
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
220
|
+
data path. The Engine participant stream uses WebSocket, including when the
|
|
221
|
+
original execution used WebTransport. Check the session's `live.attachable`
|
|
222
|
+
state before requesting an Attach grant and use its advertised participant
|
|
223
|
+
transport.
|
|
154
224
|
|
|
155
225
|
```ts
|
|
156
226
|
import { WebTTY } from "@rstreamlabs/webtty";
|
|
157
227
|
|
|
158
228
|
const session = new WebTTY({
|
|
229
|
+
managed: { capabilities },
|
|
159
230
|
attach: {
|
|
160
231
|
attachGrant,
|
|
161
232
|
capabilities: ["read_stream", "request_control"],
|
|
@@ -223,7 +294,7 @@ const files = await fs.list("/");
|
|
|
223
294
|
const compose = await fs.readText("/compose.yaml");
|
|
224
295
|
const stream = await fs.readStream("/large.log");
|
|
225
296
|
|
|
226
|
-
await fs.writeFile("/notes/
|
|
297
|
+
await fs.writeFile("/notes/status.txt", "Ready\n");
|
|
227
298
|
```
|
|
228
299
|
|
|
229
300
|
When the WebTTY server is discovered through `@rstreamlabs/tunnels`, pass the
|
|
@@ -296,12 +367,10 @@ const result = await runWebTTYCommand(
|
|
|
296
367
|
This uses HTTP/1.1 WebSocket with normal TLS verification, a 10-second handshake
|
|
297
368
|
deadline, a 1-second close deadline and the configured `maxMessageSize` limit.
|
|
298
369
|
It works independently of the global WebSocket implementation and does not
|
|
299
|
-
modify other clients or browser bundles. The same option
|
|
300
|
-
`openWebTTYCommand` and `WebTTYRemoteExecutor`.
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
[RFC 8441 endpoint](https://www.rfc-editor.org/rfc/rfc8441.html#section-5);
|
|
304
|
-
the Node factory avoids that runtime-specific failure.
|
|
370
|
+
modify other clients or browser bundles. The same option is accepted by
|
|
371
|
+
`WebTTY`, `runWebTTYCommand`, `openWebTTYCommand` and `WebTTYRemoteExecutor`.
|
|
372
|
+
Choose WebTransport explicitly when the runtime and endpoint support it;
|
|
373
|
+
transport selection preserves the requested protocol.
|
|
305
374
|
|
|
306
375
|
Use WebTransport when the endpoint is published over HTTP/3 WebTransport:
|
|
307
376
|
|
|
@@ -488,6 +557,9 @@ Browser WebTTY sessions should use short-lived tokens scoped to the specific
|
|
|
488
557
|
tunnel and path. Do not embed personal access tokens or application credentials
|
|
489
558
|
in frontend code.
|
|
490
559
|
|
|
560
|
+
The [Node transport dependency baseline](docs/000-dependencies.md) explains the
|
|
561
|
+
qualified `ws` version and bounded automatic Pong behavior.
|
|
562
|
+
|
|
491
563
|
## Development
|
|
492
564
|
|
|
493
565
|
```sh
|