@rstreamlabs/webtty 1.6.4 → 1.7.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 CHANGED
@@ -1,3 +1,217 @@
1
1
  # `@rstreamlabs/webtty`
2
2
 
3
- Client-side implementation of the rstream WebTTY protocol.
3
+ Browser-side client for the rstream WebTTY protocol.
4
+
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, stdin/stdout/stderr
7
+ streams, remote process completion, terminal resize events, and heartbeats.
8
+
9
+ For a ready-made React terminal, use
10
+ [`@rstreamlabs/react`](../react/README.md).
11
+
12
+ ## Install
13
+
14
+ ```sh
15
+ npm install @rstreamlabs/webtty
16
+ ```
17
+
18
+ ## Connect to a WebTTY Session
19
+
20
+ ```ts
21
+ import { WebTTY } from "@rstreamlabs/webtty";
22
+
23
+ const decoder = new TextDecoder();
24
+
25
+ const webtty = new WebTTY(
26
+ {
27
+ url: "wss://host.example.t.rstream.io?rstream.token=<token>",
28
+ },
29
+ {
30
+ cmdArgs: ["uname", "-a"],
31
+ interactive: false,
32
+ },
33
+ {
34
+ onConnect: () => {
35
+ console.log("connected");
36
+ },
37
+ onStdout: (chunk) => {
38
+ console.log(decoder.decode(chunk));
39
+ },
40
+ onComplete: (exitCode) => {
41
+ console.log("completed", exitCode);
42
+ },
43
+ onError: (message) => {
44
+ console.error(message);
45
+ },
46
+ },
47
+ );
48
+
49
+ webtty.connect();
50
+ ```
51
+
52
+ ## Interactive Sessions
53
+
54
+ For an interactive terminal, write encoded input to stdin and forward terminal
55
+ resize events.
56
+
57
+ ```ts
58
+ const encoder = new TextEncoder();
59
+
60
+ const webtty = new WebTTY(
61
+ { url: "wss://host.example.t.rstream.io?rstream.token=<token>" },
62
+ { allocateTty: true, interactive: true },
63
+ );
64
+
65
+ webtty.connect();
66
+
67
+ // After onConnect fires:
68
+ webtty.writeStdin(encoder.encode("whoami\n"));
69
+ webtty.resize(40, 120);
70
+ ```
71
+
72
+ Call `closeStdin()` to send EOF, or `disconnect()` to terminate the client
73
+ session.
74
+
75
+ ## Execute Commands
76
+
77
+ For non-interactive agent workflows, use `runWebTTYCommand` or
78
+ `executeWebTTYCommand`. Both open a WebTTY session, collect stdout and stderr,
79
+ and resolve when the remote command exits.
80
+
81
+ ```ts
82
+ import { runWebTTYCommand } from "@rstreamlabs/webtty";
83
+
84
+ const result = await runWebTTYCommand(
85
+ { url: "wss://host.example.t.rstream.io?rstream.token=<token>" },
86
+ "sh",
87
+ ["-lc", "docker ps --format '{{.Names}}'"],
88
+ { timeoutMs: 30_000 },
89
+ );
90
+
91
+ if (!result.success) {
92
+ throw new Error(
93
+ result.stderr || `Remote command exited with ${result.exitCode}`,
94
+ );
95
+ }
96
+
97
+ console.log(result.stdout);
98
+ ```
99
+
100
+ Use `openWebTTYCommand` when you need live control over a running command. It
101
+ returns a command object with replayable stdout/stderr, ordered log iteration,
102
+ stdin writes, EOF handling, `wait()`, and `kill()`/`terminate()` session
103
+ cleanup.
104
+
105
+ ```ts
106
+ import { openWebTTYCommand } from "@rstreamlabs/webtty";
107
+
108
+ const command = openWebTTYCommand(
109
+ { url: "wss://host.example.t.rstream.io?rstream.token=<token>" },
110
+ {
111
+ cmdArgs: ["sh", "-lc", "npm test"],
112
+ timeoutMs: 120_000,
113
+ },
114
+ );
115
+
116
+ for await (const entry of command.logs()) {
117
+ process[entry.stream === "stdout" ? "stdout" : "stderr"].write(entry.data);
118
+ }
119
+
120
+ const status = await command.wait();
121
+
122
+ if (!status.success) {
123
+ throw new Error(`Remote command exited with ${status.exitCode}`);
124
+ }
125
+ ```
126
+
127
+ Use `WebTTYRemoteExecutor` when the URL is resolved lazily, for example from a
128
+ fresh short-lived token. When the WebTTY server is discovered through
129
+ `@rstreamlabs/tunnels`, pass the advertised `exec_path` value as `execPath`
130
+ instead of assuming `/`.
131
+
132
+ ## Filesystem Sidecar
133
+
134
+ When a WebTTY server is started with `--fs-root`, the optional WebDAV sidecar
135
+ advertises an `fs_path` value. Paths passed to the SDK are relative to that
136
+ configured root.
137
+
138
+ ```ts
139
+ import { WebTTYFileSystem } from "@rstreamlabs/webtty";
140
+
141
+ const fs = new WebTTYFileSystem({
142
+ url: "https://host.example.t.rstream.io?rstream.token=<token>",
143
+ });
144
+
145
+ const files = await fs.list("/");
146
+ const compose = await fs.readText("/compose.yaml");
147
+ const stream = await fs.readStream("/large.log");
148
+
149
+ await fs.writeFile("/notes/codex.txt", "checked by Codex\n");
150
+ ```
151
+
152
+ When the WebTTY server is discovered through `@rstreamlabs/tunnels`, pass the
153
+ advertised `fs_path` value as `fsPath` instead of assuming `/fs`.
154
+
155
+ `WebTTYFileSystem` also exposes fs-style aliases such as `readFile`,
156
+ `writeFile`, `readdir`, `mkdir`, `stat`, `rename`, `copyFile`, `rm`, and
157
+ `exists` for code that expects a familiar filesystem shape.
158
+
159
+ The filesystem sidecar is a WebDAV boundary, not a sandbox. It is rooted by the
160
+ server-side `--fs-root` option and runs with the WebTTY server process
161
+ permissions.
162
+
163
+ ## Examples
164
+
165
+ Runnable examples live under `examples/`:
166
+
167
+ - `examples/remote-command` runs collected and streaming commands.
168
+ - `examples/filesystem-sidecar` reads and writes through the WebDAV sidecar.
169
+
170
+ ## Configuration
171
+
172
+ Client-level options:
173
+
174
+ | Option | Purpose |
175
+ | --------------------- | ------------------------------------------------------- |
176
+ | `url` | WebSocket endpoint for the WebTTY server. |
177
+ | `sendHeartbeat` | Send heartbeat messages. Defaults to `true`. |
178
+ | `heartbeatIntervalMs` | Heartbeat interval in milliseconds. Defaults to `5000`. |
179
+
180
+ Execution options:
181
+
182
+ | Option | Purpose |
183
+ | ------------- | ------------------------------------------------------- |
184
+ | `cmdArgs` | Command arguments requested for the remote session. |
185
+ | `envVars` | Environment variables requested for the remote session. |
186
+ | `allocateTty` | Ask the server for a TTY. Defaults to `true`. |
187
+ | `interactive` | Enable stdin. Defaults to `true`. |
188
+ | `username` | Optional user name or numeric user ID. |
189
+ | `workdir` | Optional working directory. |
190
+
191
+ The remote WebTTY server decides which execution options are accepted. Treat
192
+ these values as requests, not local privilege boundaries.
193
+
194
+ ## Events
195
+
196
+ | Event | Purpose |
197
+ | ----------------------------- | ------------------------------------------------------------------ |
198
+ | `onConnect` | Called after the server acknowledges the session. |
199
+ | `onStdout` / `onStderr` | Called with stream chunks from the remote process. |
200
+ | `onStdoutEos` / `onStderrEos` | Called when the corresponding stream reaches EOS. |
201
+ | `onComplete` | Called with the remote process exit code. |
202
+ | `onError` | Called for server errors, protocol errors, or connection failures. |
203
+
204
+ ## Security Notes
205
+
206
+ Browser WebTTY sessions should use short-lived tokens scoped to the specific
207
+ tunnel and path. Do not embed personal access tokens or application credentials
208
+ in frontend code.
209
+
210
+ ## Development
211
+
212
+ ```sh
213
+ npm --workspace @rstreamlabs/webtty run test
214
+ npm --workspace @rstreamlabs/webtty run type-check
215
+ npm --workspace @rstreamlabs/webtty run lint
216
+ npm --workspace @rstreamlabs/webtty run build
217
+ ```
package/dist/index.d.mts CHANGED
@@ -143,4 +143,171 @@ declare class WebTTY {
143
143
  private close;
144
144
  }
145
145
 
146
- export { WebTTY, type WebTTYClientConfig, type WebTTYEvents, type WebTTYExecutionConfig };
146
+ type WebTTYURLProvider = string | URL | (() => Promise<string | URL> | string | URL);
147
+ type WebTTYCommandOutput = "both" | "stderr" | "stdout";
148
+ type WebTTYCommandStream = "stderr" | "stdout";
149
+ interface WebTTYRemoteExecutorConfig {
150
+ execPath?: string;
151
+ heartbeatIntervalMs?: number;
152
+ sendHeartbeat?: boolean;
153
+ url: WebTTYURLProvider;
154
+ }
155
+ interface WebTTYCommandReadOptions {
156
+ signal?: AbortSignal;
157
+ }
158
+ interface ExecuteWebTTYCommandOptions extends WebTTYExecutionConfig {
159
+ execPath?: string;
160
+ input?: string | Uint8Array;
161
+ signal?: AbortSignal;
162
+ timeoutMs?: number;
163
+ }
164
+ interface WebTTYRunCommandOptions extends Omit<ExecuteWebTTYCommandOptions, "cmdArgs" | "envVars" | "input" | "workdir"> {
165
+ cwd?: string;
166
+ env?: Record<string, string | undefined>;
167
+ stdin?: string | Uint8Array;
168
+ }
169
+ interface WebTTYCommandResult {
170
+ exitCode: number;
171
+ stderr: string;
172
+ stdout: string;
173
+ success: boolean;
174
+ }
175
+ interface WebTTYCommandStatus {
176
+ exitCode: number;
177
+ success: boolean;
178
+ }
179
+ interface WebTTYCommandLog {
180
+ data: string;
181
+ stream: WebTTYCommandStream;
182
+ }
183
+ interface WebTTYCommandLogBytes {
184
+ data: Uint8Array;
185
+ stream: WebTTYCommandStream;
186
+ }
187
+ declare function resolveWebTTYExecutionURL(input: string | URL, execPath?: string): URL;
188
+ declare class WebTTYCommand {
189
+ private readonly abort;
190
+ private readonly connected;
191
+ private readonly completion;
192
+ private readonly logsChannel;
193
+ private readonly stderrChannel;
194
+ private readonly stdoutChannel;
195
+ private readonly timer;
196
+ private readonly webtty;
197
+ private settled;
198
+ exitCode: number | null;
199
+ readonly stdin: WritableStream<Uint8Array> | undefined;
200
+ constructor(client: WebTTYClientConfig, options: ExecuteWebTTYCommandOptions);
201
+ closeStdin(): Promise<void>;
202
+ disconnect(): void;
203
+ kill(): Promise<void>;
204
+ logBytes(): AsyncGenerator<WebTTYCommandLogBytes, void, void>;
205
+ logs(): AsyncGenerator<WebTTYCommandLog, void, void>;
206
+ output(stream?: WebTTYCommandOutput, options?: WebTTYCommandReadOptions): Promise<string>;
207
+ stderr(options?: WebTTYCommandReadOptions): Promise<string>;
208
+ stderrBytes(options?: WebTTYCommandReadOptions): Promise<Uint8Array>;
209
+ stderrStream(): ReadableStream<Uint8Array>;
210
+ stdout(options?: WebTTYCommandReadOptions): Promise<string>;
211
+ stdoutBytes(options?: WebTTYCommandReadOptions): Promise<Uint8Array>;
212
+ stdoutStream(): ReadableStream<Uint8Array>;
213
+ wait(options?: WebTTYCommandReadOptions): Promise<WebTTYCommandStatus>;
214
+ terminate(): Promise<void>;
215
+ writeStdin(input: string | Uint8Array): Promise<void>;
216
+ private append;
217
+ private clearTimer;
218
+ private complete;
219
+ private connect;
220
+ private fail;
221
+ }
222
+ declare function openWebTTYCommand(client: WebTTYClientConfig, options?: ExecuteWebTTYCommandOptions): WebTTYCommand;
223
+ declare function runWebTTYCommand(client: WebTTYClientConfig, command: string, args?: readonly string[], options?: WebTTYRunCommandOptions): Promise<WebTTYCommandResult>;
224
+ declare function executeWebTTYCommand(client: WebTTYClientConfig, options?: ExecuteWebTTYCommandOptions): Promise<WebTTYCommandResult>;
225
+ declare class WebTTYRemoteExecutor {
226
+ private readonly config;
227
+ constructor(config: WebTTYRemoteExecutorConfig);
228
+ execute(options?: ExecuteWebTTYCommandOptions): Promise<WebTTYCommandResult>;
229
+ open(options?: ExecuteWebTTYCommandOptions): Promise<WebTTYCommand>;
230
+ openCommand(command: string, args?: readonly string[], options?: WebTTYRunCommandOptions): Promise<WebTTYCommand>;
231
+ runCommand(command: string, args?: readonly string[], options?: WebTTYRunCommandOptions): Promise<WebTTYCommandResult>;
232
+ }
233
+
234
+ interface WebTTYFileSystemConfig {
235
+ authToken?: string;
236
+ fetch?: typeof fetch;
237
+ fsPath?: string;
238
+ headers?: HeadersInit;
239
+ url: WebTTYURLProvider;
240
+ }
241
+ interface WebTTYFileSystemItem {
242
+ kind: "directory" | "file";
243
+ modified?: string;
244
+ path: string;
245
+ size?: number;
246
+ }
247
+ interface WebTTYFileSystemRequestOptions {
248
+ signal?: AbortSignal;
249
+ }
250
+ interface WebTTYFileSystemReadFileOptions extends WebTTYFileSystemRequestOptions {
251
+ encoding?: string | null;
252
+ }
253
+ interface WebTTYFileSystemMkdirOptions extends WebTTYFileSystemRequestOptions {
254
+ recursive?: boolean;
255
+ }
256
+ interface WebTTYFileSystemReaddirOptions extends WebTTYFileSystemRequestOptions {
257
+ withFileTypes?: boolean;
258
+ }
259
+ interface WebTTYFileSystemRmOptions extends WebTTYFileSystemRequestOptions {
260
+ force?: boolean;
261
+ recursive?: boolean;
262
+ }
263
+ interface WebTTYFileSystemWriteFileOptions extends WebTTYFileSystemRequestOptions {
264
+ contentType?: string;
265
+ }
266
+ interface WebTTYFileSystemWriteStreamOptions extends WebTTYFileSystemRequestOptions {
267
+ contentType?: string;
268
+ }
269
+ type WebTTYFileSystemWriteData = BodyInit;
270
+ declare class WebTTYFileSystemError extends Error {
271
+ readonly operation: string;
272
+ readonly status: number;
273
+ constructor(operation: string, status: number, message: string);
274
+ }
275
+ declare function resolveWebTTYFileSystemURL(input: string | URL, remotePath?: string, fsPath?: string): URL;
276
+ declare function parseWebDAVMultiStatus(xml: string, fsPath?: string): WebTTYFileSystemItem[];
277
+ declare class WebTTYFileSystem {
278
+ private readonly config;
279
+ constructor(config: WebTTYFileSystemConfig);
280
+ list(path?: string, options?: WebTTYFileSystemRequestOptions): Promise<WebTTYFileSystemItem[]>;
281
+ readBytes(path: string, options?: WebTTYFileSystemRequestOptions): Promise<Uint8Array>;
282
+ readFile(path: string, options?: {
283
+ encoding?: null;
284
+ signal?: AbortSignal;
285
+ } | null): Promise<Uint8Array>;
286
+ readFile(path: string, options: {
287
+ encoding: string;
288
+ signal?: AbortSignal;
289
+ } | string): Promise<string>;
290
+ readText(path: string, options?: WebTTYFileSystemRequestOptions): Promise<string>;
291
+ readStream(path: string, options?: WebTTYFileSystemRequestOptions): Promise<ReadableStream<Uint8Array>>;
292
+ writeFile(path: string, data: WebTTYFileSystemWriteData, options?: WebTTYFileSystemWriteFileOptions): Promise<void>;
293
+ writeBytes(path: string, data: BodyInit, options?: WebTTYFileSystemRequestOptions): Promise<void>;
294
+ writeStream(path: string, data: ReadableStream<Uint8Array>, options?: WebTTYFileSystemWriteStreamOptions): Promise<void>;
295
+ writeText(path: string, data: string, options?: WebTTYFileSystemRequestOptions): Promise<void>;
296
+ copyFile(sourcePath: string, targetPath: string, options?: WebTTYFileSystemRequestOptions): Promise<void>;
297
+ createDirectory(path: string, options?: WebTTYFileSystemRequestOptions): Promise<void>;
298
+ exists(path: string, options?: WebTTYFileSystemRequestOptions): Promise<boolean>;
299
+ mkdir(path: string, options?: WebTTYFileSystemMkdirOptions): Promise<string | undefined>;
300
+ readdir(path: string, options: WebTTYFileSystemReaddirOptions & {
301
+ withFileTypes: true;
302
+ }): Promise<WebTTYFileSystemItem[]>;
303
+ readdir(path?: string, options?: WebTTYFileSystemReaddirOptions): Promise<string[]>;
304
+ rename(oldPath: string, newPath: string, options?: WebTTYFileSystemRequestOptions): Promise<void>;
305
+ rm(path: string, options?: WebTTYFileSystemRmOptions): Promise<void>;
306
+ stat(path: string, options?: WebTTYFileSystemRequestOptions): Promise<WebTTYFileSystemItem>;
307
+ delete(path: string, options?: WebTTYFileSystemRequestOptions): Promise<void>;
308
+ private createDirectoryRecursive;
309
+ private resourceURL;
310
+ private request;
311
+ }
312
+
313
+ export { type ExecuteWebTTYCommandOptions, WebTTY, type WebTTYClientConfig, WebTTYCommand, type WebTTYCommandLog, type WebTTYCommandLogBytes, type WebTTYCommandOutput, type WebTTYCommandReadOptions, type WebTTYCommandResult, type WebTTYCommandStatus, type WebTTYCommandStream, type WebTTYEvents, type WebTTYExecutionConfig, WebTTYFileSystem, type WebTTYFileSystemConfig, WebTTYFileSystemError, type WebTTYFileSystemItem, type WebTTYFileSystemMkdirOptions, type WebTTYFileSystemReadFileOptions, type WebTTYFileSystemReaddirOptions, type WebTTYFileSystemRequestOptions, type WebTTYFileSystemRmOptions, type WebTTYFileSystemWriteData, type WebTTYFileSystemWriteFileOptions, type WebTTYFileSystemWriteStreamOptions, WebTTYRemoteExecutor, type WebTTYRemoteExecutorConfig, type WebTTYRunCommandOptions, type WebTTYURLProvider, executeWebTTYCommand, openWebTTYCommand, parseWebDAVMultiStatus, resolveWebTTYExecutionURL, resolveWebTTYFileSystemURL, runWebTTYCommand };
package/dist/index.d.ts CHANGED
@@ -143,4 +143,171 @@ declare class WebTTY {
143
143
  private close;
144
144
  }
145
145
 
146
- export { WebTTY, type WebTTYClientConfig, type WebTTYEvents, type WebTTYExecutionConfig };
146
+ type WebTTYURLProvider = string | URL | (() => Promise<string | URL> | string | URL);
147
+ type WebTTYCommandOutput = "both" | "stderr" | "stdout";
148
+ type WebTTYCommandStream = "stderr" | "stdout";
149
+ interface WebTTYRemoteExecutorConfig {
150
+ execPath?: string;
151
+ heartbeatIntervalMs?: number;
152
+ sendHeartbeat?: boolean;
153
+ url: WebTTYURLProvider;
154
+ }
155
+ interface WebTTYCommandReadOptions {
156
+ signal?: AbortSignal;
157
+ }
158
+ interface ExecuteWebTTYCommandOptions extends WebTTYExecutionConfig {
159
+ execPath?: string;
160
+ input?: string | Uint8Array;
161
+ signal?: AbortSignal;
162
+ timeoutMs?: number;
163
+ }
164
+ interface WebTTYRunCommandOptions extends Omit<ExecuteWebTTYCommandOptions, "cmdArgs" | "envVars" | "input" | "workdir"> {
165
+ cwd?: string;
166
+ env?: Record<string, string | undefined>;
167
+ stdin?: string | Uint8Array;
168
+ }
169
+ interface WebTTYCommandResult {
170
+ exitCode: number;
171
+ stderr: string;
172
+ stdout: string;
173
+ success: boolean;
174
+ }
175
+ interface WebTTYCommandStatus {
176
+ exitCode: number;
177
+ success: boolean;
178
+ }
179
+ interface WebTTYCommandLog {
180
+ data: string;
181
+ stream: WebTTYCommandStream;
182
+ }
183
+ interface WebTTYCommandLogBytes {
184
+ data: Uint8Array;
185
+ stream: WebTTYCommandStream;
186
+ }
187
+ declare function resolveWebTTYExecutionURL(input: string | URL, execPath?: string): URL;
188
+ declare class WebTTYCommand {
189
+ private readonly abort;
190
+ private readonly connected;
191
+ private readonly completion;
192
+ private readonly logsChannel;
193
+ private readonly stderrChannel;
194
+ private readonly stdoutChannel;
195
+ private readonly timer;
196
+ private readonly webtty;
197
+ private settled;
198
+ exitCode: number | null;
199
+ readonly stdin: WritableStream<Uint8Array> | undefined;
200
+ constructor(client: WebTTYClientConfig, options: ExecuteWebTTYCommandOptions);
201
+ closeStdin(): Promise<void>;
202
+ disconnect(): void;
203
+ kill(): Promise<void>;
204
+ logBytes(): AsyncGenerator<WebTTYCommandLogBytes, void, void>;
205
+ logs(): AsyncGenerator<WebTTYCommandLog, void, void>;
206
+ output(stream?: WebTTYCommandOutput, options?: WebTTYCommandReadOptions): Promise<string>;
207
+ stderr(options?: WebTTYCommandReadOptions): Promise<string>;
208
+ stderrBytes(options?: WebTTYCommandReadOptions): Promise<Uint8Array>;
209
+ stderrStream(): ReadableStream<Uint8Array>;
210
+ stdout(options?: WebTTYCommandReadOptions): Promise<string>;
211
+ stdoutBytes(options?: WebTTYCommandReadOptions): Promise<Uint8Array>;
212
+ stdoutStream(): ReadableStream<Uint8Array>;
213
+ wait(options?: WebTTYCommandReadOptions): Promise<WebTTYCommandStatus>;
214
+ terminate(): Promise<void>;
215
+ writeStdin(input: string | Uint8Array): Promise<void>;
216
+ private append;
217
+ private clearTimer;
218
+ private complete;
219
+ private connect;
220
+ private fail;
221
+ }
222
+ declare function openWebTTYCommand(client: WebTTYClientConfig, options?: ExecuteWebTTYCommandOptions): WebTTYCommand;
223
+ declare function runWebTTYCommand(client: WebTTYClientConfig, command: string, args?: readonly string[], options?: WebTTYRunCommandOptions): Promise<WebTTYCommandResult>;
224
+ declare function executeWebTTYCommand(client: WebTTYClientConfig, options?: ExecuteWebTTYCommandOptions): Promise<WebTTYCommandResult>;
225
+ declare class WebTTYRemoteExecutor {
226
+ private readonly config;
227
+ constructor(config: WebTTYRemoteExecutorConfig);
228
+ execute(options?: ExecuteWebTTYCommandOptions): Promise<WebTTYCommandResult>;
229
+ open(options?: ExecuteWebTTYCommandOptions): Promise<WebTTYCommand>;
230
+ openCommand(command: string, args?: readonly string[], options?: WebTTYRunCommandOptions): Promise<WebTTYCommand>;
231
+ runCommand(command: string, args?: readonly string[], options?: WebTTYRunCommandOptions): Promise<WebTTYCommandResult>;
232
+ }
233
+
234
+ interface WebTTYFileSystemConfig {
235
+ authToken?: string;
236
+ fetch?: typeof fetch;
237
+ fsPath?: string;
238
+ headers?: HeadersInit;
239
+ url: WebTTYURLProvider;
240
+ }
241
+ interface WebTTYFileSystemItem {
242
+ kind: "directory" | "file";
243
+ modified?: string;
244
+ path: string;
245
+ size?: number;
246
+ }
247
+ interface WebTTYFileSystemRequestOptions {
248
+ signal?: AbortSignal;
249
+ }
250
+ interface WebTTYFileSystemReadFileOptions extends WebTTYFileSystemRequestOptions {
251
+ encoding?: string | null;
252
+ }
253
+ interface WebTTYFileSystemMkdirOptions extends WebTTYFileSystemRequestOptions {
254
+ recursive?: boolean;
255
+ }
256
+ interface WebTTYFileSystemReaddirOptions extends WebTTYFileSystemRequestOptions {
257
+ withFileTypes?: boolean;
258
+ }
259
+ interface WebTTYFileSystemRmOptions extends WebTTYFileSystemRequestOptions {
260
+ force?: boolean;
261
+ recursive?: boolean;
262
+ }
263
+ interface WebTTYFileSystemWriteFileOptions extends WebTTYFileSystemRequestOptions {
264
+ contentType?: string;
265
+ }
266
+ interface WebTTYFileSystemWriteStreamOptions extends WebTTYFileSystemRequestOptions {
267
+ contentType?: string;
268
+ }
269
+ type WebTTYFileSystemWriteData = BodyInit;
270
+ declare class WebTTYFileSystemError extends Error {
271
+ readonly operation: string;
272
+ readonly status: number;
273
+ constructor(operation: string, status: number, message: string);
274
+ }
275
+ declare function resolveWebTTYFileSystemURL(input: string | URL, remotePath?: string, fsPath?: string): URL;
276
+ declare function parseWebDAVMultiStatus(xml: string, fsPath?: string): WebTTYFileSystemItem[];
277
+ declare class WebTTYFileSystem {
278
+ private readonly config;
279
+ constructor(config: WebTTYFileSystemConfig);
280
+ list(path?: string, options?: WebTTYFileSystemRequestOptions): Promise<WebTTYFileSystemItem[]>;
281
+ readBytes(path: string, options?: WebTTYFileSystemRequestOptions): Promise<Uint8Array>;
282
+ readFile(path: string, options?: {
283
+ encoding?: null;
284
+ signal?: AbortSignal;
285
+ } | null): Promise<Uint8Array>;
286
+ readFile(path: string, options: {
287
+ encoding: string;
288
+ signal?: AbortSignal;
289
+ } | string): Promise<string>;
290
+ readText(path: string, options?: WebTTYFileSystemRequestOptions): Promise<string>;
291
+ readStream(path: string, options?: WebTTYFileSystemRequestOptions): Promise<ReadableStream<Uint8Array>>;
292
+ writeFile(path: string, data: WebTTYFileSystemWriteData, options?: WebTTYFileSystemWriteFileOptions): Promise<void>;
293
+ writeBytes(path: string, data: BodyInit, options?: WebTTYFileSystemRequestOptions): Promise<void>;
294
+ writeStream(path: string, data: ReadableStream<Uint8Array>, options?: WebTTYFileSystemWriteStreamOptions): Promise<void>;
295
+ writeText(path: string, data: string, options?: WebTTYFileSystemRequestOptions): Promise<void>;
296
+ copyFile(sourcePath: string, targetPath: string, options?: WebTTYFileSystemRequestOptions): Promise<void>;
297
+ createDirectory(path: string, options?: WebTTYFileSystemRequestOptions): Promise<void>;
298
+ exists(path: string, options?: WebTTYFileSystemRequestOptions): Promise<boolean>;
299
+ mkdir(path: string, options?: WebTTYFileSystemMkdirOptions): Promise<string | undefined>;
300
+ readdir(path: string, options: WebTTYFileSystemReaddirOptions & {
301
+ withFileTypes: true;
302
+ }): Promise<WebTTYFileSystemItem[]>;
303
+ readdir(path?: string, options?: WebTTYFileSystemReaddirOptions): Promise<string[]>;
304
+ rename(oldPath: string, newPath: string, options?: WebTTYFileSystemRequestOptions): Promise<void>;
305
+ rm(path: string, options?: WebTTYFileSystemRmOptions): Promise<void>;
306
+ stat(path: string, options?: WebTTYFileSystemRequestOptions): Promise<WebTTYFileSystemItem>;
307
+ delete(path: string, options?: WebTTYFileSystemRequestOptions): Promise<void>;
308
+ private createDirectoryRecursive;
309
+ private resourceURL;
310
+ private request;
311
+ }
312
+
313
+ export { type ExecuteWebTTYCommandOptions, WebTTY, type WebTTYClientConfig, WebTTYCommand, type WebTTYCommandLog, type WebTTYCommandLogBytes, type WebTTYCommandOutput, type WebTTYCommandReadOptions, type WebTTYCommandResult, type WebTTYCommandStatus, type WebTTYCommandStream, type WebTTYEvents, type WebTTYExecutionConfig, WebTTYFileSystem, type WebTTYFileSystemConfig, WebTTYFileSystemError, type WebTTYFileSystemItem, type WebTTYFileSystemMkdirOptions, type WebTTYFileSystemReadFileOptions, type WebTTYFileSystemReaddirOptions, type WebTTYFileSystemRequestOptions, type WebTTYFileSystemRmOptions, type WebTTYFileSystemWriteData, type WebTTYFileSystemWriteFileOptions, type WebTTYFileSystemWriteStreamOptions, WebTTYRemoteExecutor, type WebTTYRemoteExecutorConfig, type WebTTYRunCommandOptions, type WebTTYURLProvider, executeWebTTYCommand, openWebTTYCommand, parseWebDAVMultiStatus, resolveWebTTYExecutionURL, resolveWebTTYFileSystemURL, runWebTTYCommand };