@rstreamlabs/webtty 1.7.0 → 1.9.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 +218 -8
- package/dist/chunk-7OHAFDJE.mjs +10679 -0
- package/dist/index.d.mts +5157 -5
- package/dist/index.d.ts +5157 -5
- package/dist/index.js +7989 -669
- package/dist/index.mjs +66 -3372
- package/dist/node.d.mts +38 -0
- package/dist/node.d.ts +38 -0
- package/dist/node.js +11129 -0
- package/dist/node.mjs +451 -0
- package/package.json +14 -1
package/README.md
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
Browser-side client for the rstream WebTTY protocol.
|
|
4
4
|
|
|
5
5
|
Use this package when you need to connect a web application to a WebTTY server
|
|
6
|
-
over WebSocket. It handles the protobuf session handshake,
|
|
7
|
-
streams, remote process completion, terminal resize events,
|
|
6
|
+
over WebSocket or WebTransport. It handles the protobuf session handshake,
|
|
7
|
+
stdin/stdout/stderr streams, remote process completion, terminal resize events,
|
|
8
|
+
and heartbeats.
|
|
8
9
|
|
|
9
10
|
For a ready-made React terminal, use
|
|
10
11
|
[`@rstreamlabs/react`](../react/README.md).
|
|
@@ -129,6 +130,70 @@ fresh short-lived token. When the WebTTY server is discovered through
|
|
|
129
130
|
`@rstreamlabs/tunnels`, pass the advertised `exec_path` value as `execPath`
|
|
130
131
|
instead of assuming `/`.
|
|
131
132
|
|
|
133
|
+
### Managed session attach
|
|
134
|
+
|
|
135
|
+
Engine-managed sessions are joined with a WebTTY `Attach` message. The attach
|
|
136
|
+
grant is obtained from the control-plane API, then sent as the first protobuf
|
|
137
|
+
message on the terminal stream. Terminal input and output stay on the WebTTY
|
|
138
|
+
data path. The current engine live participant stream accepts WebSocket-backed
|
|
139
|
+
sessions only; WebTransport attach encoding is available in the protocol/SDK,
|
|
140
|
+
but engines that do not expose a WebTransport participant stream reject those
|
|
141
|
+
sessions before issuing an attach grant.
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
import { WebTTY } from "@rstreamlabs/webtty";
|
|
145
|
+
|
|
146
|
+
const session = new WebTTY({
|
|
147
|
+
attach: {
|
|
148
|
+
attachGrant,
|
|
149
|
+
capabilities: ["read_stream", "request_control"],
|
|
150
|
+
participantId,
|
|
151
|
+
sessionId,
|
|
152
|
+
},
|
|
153
|
+
url: participantStreamUrl,
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
session.connect();
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Recorded Session Replay
|
|
160
|
+
|
|
161
|
+
The package exposes replay helpers for product-managed WebTTY recordings. The
|
|
162
|
+
helpers are public so applications can inspect and audit the decrypt/transcript
|
|
163
|
+
path instead of relying on product UI code.
|
|
164
|
+
|
|
165
|
+
```ts
|
|
166
|
+
import {
|
|
167
|
+
createWebTTYE2EReplayPayloadCryptoFromKeyGrant,
|
|
168
|
+
decryptWebTTYRecordedEvent,
|
|
169
|
+
decryptWebTTYRecordedTextLog,
|
|
170
|
+
} from "@rstreamlabs/webtty";
|
|
171
|
+
|
|
172
|
+
const payloadCrypto = await createWebTTYE2EReplayPayloadCryptoFromKeyGrant(
|
|
173
|
+
decryptMaterialGrant,
|
|
174
|
+
localWorkspaceDeviceWebTTYIdentity,
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
for (const event of recordedEvents) {
|
|
178
|
+
const chunk = await decryptWebTTYRecordedEvent(event, payloadCrypto);
|
|
179
|
+
if (chunk) {
|
|
180
|
+
// chunk.stream is "stdin", "stdout", or "stderr"; chunk.data is bytes.
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const transcript = await decryptWebTTYRecordedTextLog(
|
|
185
|
+
recordedEvents,
|
|
186
|
+
payloadCrypto,
|
|
187
|
+
);
|
|
188
|
+
console.log(transcript.text);
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
`decryptWebTTYRecordedTextLog` renders a readable terminal transcript from
|
|
192
|
+
recorded data events. It omits closed alternate-screen applications from the
|
|
193
|
+
transcript, matching terminal scrollback behavior. If the recording ends while
|
|
194
|
+
alternate screen is still active, the current alternate-screen snapshot is
|
|
195
|
+
included by default. Use raw decrypted events when you need full forensic data.
|
|
196
|
+
|
|
132
197
|
## Filesystem Sidecar
|
|
133
198
|
|
|
134
199
|
When a WebTTY server is started with `--fs-root`, the optional WebDAV sidecar
|
|
@@ -158,7 +223,8 @@ advertised `fs_path` value as `fsPath` instead of assuming `/fs`.
|
|
|
158
223
|
|
|
159
224
|
The filesystem sidecar is a WebDAV boundary, not a sandbox. It is rooted by the
|
|
160
225
|
server-side `--fs-root` option and runs with the WebTTY server process
|
|
161
|
-
permissions.
|
|
226
|
+
permissions. It is not part of the encrypted WebTTY protobuf payload stream and
|
|
227
|
+
is intentionally kept separate from WebTTY E2E payload encryption.
|
|
162
228
|
|
|
163
229
|
## Examples
|
|
164
230
|
|
|
@@ -171,11 +237,12 @@ Runnable examples live under `examples/`:
|
|
|
171
237
|
|
|
172
238
|
Client-level options:
|
|
173
239
|
|
|
174
|
-
| Option | Purpose
|
|
175
|
-
| --------------------- |
|
|
176
|
-
| `url` | WebSocket endpoint for the WebTTY server.
|
|
177
|
-
| `
|
|
178
|
-
| `
|
|
240
|
+
| Option | Purpose |
|
|
241
|
+
| --------------------- | ----------------------------------------------------------- |
|
|
242
|
+
| `url` | WebSocket or WebTransport endpoint for the WebTTY server. |
|
|
243
|
+
| `transport` | Optional transport override: `websocket` or `webtransport`. |
|
|
244
|
+
| `sendHeartbeat` | Send heartbeat messages. Defaults to `true`. |
|
|
245
|
+
| `heartbeatIntervalMs` | Heartbeat interval in milliseconds. Defaults to `5000`. |
|
|
179
246
|
|
|
180
247
|
Execution options:
|
|
181
248
|
|
|
@@ -191,6 +258,149 @@ Execution options:
|
|
|
191
258
|
The remote WebTTY server decides which execution options are accepted. Treat
|
|
192
259
|
these values as requests, not local privilege boundaries.
|
|
193
260
|
|
|
261
|
+
## Transports
|
|
262
|
+
|
|
263
|
+
The browser client uses WebSocket by default:
|
|
264
|
+
|
|
265
|
+
```ts
|
|
266
|
+
const terminal = new WebTTY({ url: "wss://terminal.example/session" });
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
Use WebTransport when the endpoint is published over HTTP/3 WebTransport:
|
|
270
|
+
|
|
271
|
+
```ts
|
|
272
|
+
const terminal = new WebTTY({
|
|
273
|
+
transport: "webtransport",
|
|
274
|
+
url: "https://terminal.example/session",
|
|
275
|
+
});
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
Both transports carry the same WebTTY protobuf messages. WebTransport uses the
|
|
279
|
+
same length-prefixed protobuf framing as the Go WebTransport implementation.
|
|
280
|
+
|
|
281
|
+
For local WebTransport tests that use an ephemeral self-signed certificate, pass
|
|
282
|
+
the browser WebTransport certificate pinning options through `webTransportOptions`:
|
|
283
|
+
|
|
284
|
+
```ts
|
|
285
|
+
const terminal = new WebTTY({
|
|
286
|
+
transport: "webtransport",
|
|
287
|
+
url: "https://127.0.0.1:8443/",
|
|
288
|
+
webTransportOptions: {
|
|
289
|
+
serverCertificateHashes: [
|
|
290
|
+
{ algorithm: "sha-256", value: certificateSha256 },
|
|
291
|
+
],
|
|
292
|
+
},
|
|
293
|
+
});
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
Production endpoints should normally rely on publicly trusted TLS certificates
|
|
297
|
+
and leave `webTransportOptions` unset.
|
|
298
|
+
|
|
299
|
+
## Payload Crypto Hooks
|
|
300
|
+
|
|
301
|
+
Managed WebTTY can keep the protobuf session envelope visible to the server
|
|
302
|
+
while carrying stdin/stdout/stderr bytes as encrypted payloads. This lets the
|
|
303
|
+
server route sessions, record metadata, enforce policy, and track lifecycle
|
|
304
|
+
events without receiving plaintext terminal bytes.
|
|
305
|
+
|
|
306
|
+
The SDK exposes payload crypto hooks through `payloadCrypto`. It also provides
|
|
307
|
+
`generateWebTTYE2EIdentity`, `createWebTTYE2EClientPayloadCrypto`, and
|
|
308
|
+
`createWebTTYE2EServerPayloadCrypto` helpers for WebCrypto-backed E2E payload
|
|
309
|
+
encryption.
|
|
310
|
+
|
|
311
|
+
Implemented E2E suites:
|
|
312
|
+
|
|
313
|
+
| Layer | Suite |
|
|
314
|
+
| ------------- | -------------------------------------------------------------------- |
|
|
315
|
+
| Payload bytes | AES-256-GCM with a fresh 96-bit nonce per WebTTY data message |
|
|
316
|
+
| Key envelope | HPKE Base mode: DHKEM(X25519, HKDF-SHA256), HKDF-SHA256, AES-256-GCM |
|
|
317
|
+
|
|
318
|
+
Crypto helpers attach a `cryptoInfo` object to the returned `payloadCrypto`.
|
|
319
|
+
UI bindings can use it to display runtime security details without hard-coding
|
|
320
|
+
suite names. The object reports the E2E mode, payload cipher, tag and nonce
|
|
321
|
+
sizes, key agreement, key derivation, and key-encryption suites that are
|
|
322
|
+
actually configured for the session.
|
|
323
|
+
|
|
324
|
+
The WebTTY protobuf envelope remains visible for routing and policy; only the
|
|
325
|
+
stdin/stdout/stderr payload bytes are encrypted by these helpers.
|
|
326
|
+
|
|
327
|
+
Key identifiers and X25519 key material can be passed as raw `Uint8Array`
|
|
328
|
+
values or as unpadded base64url strings, matching the local WebTTY identity
|
|
329
|
+
files generated by the rstream CLI.
|
|
330
|
+
|
|
331
|
+
When a client needs replay/decrypt grants to point at product resources instead
|
|
332
|
+
of opaque public keys, pass typed recipients to
|
|
333
|
+
`createWebTTYE2EClientPayloadCrypto`:
|
|
334
|
+
|
|
335
|
+
```ts
|
|
336
|
+
const crypto = await createWebTTYE2EClientPayloadCrypto({
|
|
337
|
+
recipients: [
|
|
338
|
+
{
|
|
339
|
+
id: "keyset-1",
|
|
340
|
+
keyId: workspaceRecipientKeyId,
|
|
341
|
+
kind: "workspace_keyset",
|
|
342
|
+
publicKey: workspaceRecipientPublicKey,
|
|
343
|
+
},
|
|
344
|
+
],
|
|
345
|
+
});
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
The helper builds the WebTTY `key_context` before HPKE wrapping, so the context
|
|
349
|
+
is covered by the HPKE authenticated data. `createWebTTYE2EKeyContext` is also
|
|
350
|
+
available when the application needs to provide the context explicitly with
|
|
351
|
+
workspace, project, or server identifiers.
|
|
352
|
+
|
|
353
|
+
Recorded engine events may expose both `key_context` and `key_context_raw`.
|
|
354
|
+
Replay and decrypt flows must prefer `key_context_raw` when it is present. It is
|
|
355
|
+
the unpadded base64url encoding of the exact context bytes used for HPKE/AAD;
|
|
356
|
+
`key_context` is a readable metadata projection and can be affected by JSON
|
|
357
|
+
normalization after storage.
|
|
358
|
+
|
|
359
|
+
Browser applications do not read environment variables or `.rstream` files. They
|
|
360
|
+
must receive either an explicit known server endpoint identity or a
|
|
361
|
+
workspace-managed trust grant before creating the WebTTY client. When an
|
|
362
|
+
endpoint identity is configured, the browser verifies the server proof before it
|
|
363
|
+
sends the WebTTY `Open` message. When the server requires client authentication,
|
|
364
|
+
the browser also needs a local client endpoint identity so it can sign a
|
|
365
|
+
`ClientProof`.
|
|
366
|
+
|
|
367
|
+
Node.js applications that run beside the rstream CLI can use the local trust
|
|
368
|
+
helper to apply the same WebTTY trust-store resolution as the CLI and native
|
|
369
|
+
clients:
|
|
370
|
+
|
|
371
|
+
```ts
|
|
372
|
+
import { createWebTTYE2EClientPayloadCryptoFromLocalTrust } from "@rstreamlabs/webtty/node";
|
|
373
|
+
|
|
374
|
+
const payloadCrypto = await createWebTTYE2EClientPayloadCryptoFromLocalTrust({
|
|
375
|
+
required: true,
|
|
376
|
+
});
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
The helper resolves `RSTREAM_WEBTTY_KNOWN_SERVER_KEY`,
|
|
380
|
+
`RSTREAM_WEBTTY_KNOWN_SERVERS_FILE`, and the default
|
|
381
|
+
`~/.rstream/webtty/known_servers.json` file. If no trust material exists and
|
|
382
|
+
`required` is not set, it returns `undefined` so plaintext WebTTY sessions remain
|
|
383
|
+
available for unprotected servers.
|
|
384
|
+
|
|
385
|
+
The WebDAV filesystem sidecar is a separate HTTP/WebDAV surface. It is not
|
|
386
|
+
covered by WebTTY payload crypto and should not be presented as protected by
|
|
387
|
+
WebTTY E2E encryption.
|
|
388
|
+
|
|
389
|
+
Protocol suite identifiers currently represented in the WebTTY protobuf
|
|
390
|
+
contract are:
|
|
391
|
+
|
|
392
|
+
| Field | Protocol identifiers |
|
|
393
|
+
| ------------------ | ---------------------------------------------------------------------------------- |
|
|
394
|
+
| `payloadSuite` | `aes-256-gcm`, `chacha20-poly1305` |
|
|
395
|
+
| `keyEnvelopeSuite` | `hpke-x25519-hkdf-sha256-aes-256-gcm`, `hpke-x25519-hkdf-sha256-chacha20-poly1305` |
|
|
396
|
+
|
|
397
|
+
The helpers in this package support only the AES-256-GCM payload suite and the
|
|
398
|
+
HPKE/X25519/HKDF-SHA256/AES-256-GCM key-envelope suite. ChaCha20-Poly1305
|
|
399
|
+
identifiers are reserved for forward compatibility and are rejected by the
|
|
400
|
+
current helpers.
|
|
401
|
+
|
|
402
|
+
Do not derive payload keys from passwords or application strings.
|
|
403
|
+
|
|
194
404
|
## Events
|
|
195
405
|
|
|
196
406
|
| Event | Purpose |
|