@slicervm/sdk 0.1.4 → 0.1.6
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 +7 -0
- package/dist/index.cjs +314 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +204 -1
- package/dist/index.d.ts +204 -1
- package/dist/index.js +308 -3
- package/dist/index.js.map +1 -1
- package/dist/shell.cjs +152 -0
- package/dist/shell.cjs.map +1 -0
- package/dist/shell.d.cts +67 -0
- package/dist/shell.d.ts +67 -0
- package/dist/shell.js +143 -0
- package/dist/shell.js.map +1 -0
- package/package.json +11 -1
package/dist/index.d.cts
CHANGED
|
@@ -131,6 +131,91 @@ interface ExecResultBinary {
|
|
|
131
131
|
exitCode: number;
|
|
132
132
|
error?: string;
|
|
133
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* Launch parameters for a background exec. Mirrors the Go SDK's
|
|
136
|
+
* `ExecBackgroundRequest`. The child is detached at launch and survives
|
|
137
|
+
* client disconnect; manage it via `vm.bg.list/info/logs/kill/wait/remove`.
|
|
138
|
+
*
|
|
139
|
+
* `command` + `args` is the always-correct deterministic form (matches the
|
|
140
|
+
* `--cmd` / `--arg` CLI flags). For `$VAR` expansion or shell operators set
|
|
141
|
+
* `shell` to a shell path (e.g. `/bin/bash`) and pass the script as
|
|
142
|
+
* `command`; the agent runs `<shell> -lc "<command>"` in that case.
|
|
143
|
+
*/
|
|
144
|
+
interface BgExecRequest {
|
|
145
|
+
command: string;
|
|
146
|
+
args?: string[];
|
|
147
|
+
env?: string[];
|
|
148
|
+
uid?: number;
|
|
149
|
+
gid?: number;
|
|
150
|
+
cwd?: string;
|
|
151
|
+
/**
|
|
152
|
+
* Empty (default): direct exec. Set to a shell path (e.g. `/bin/bash`) for
|
|
153
|
+
* `$VAR` expansion, globs, and shell operators. With a shell, bash auto-
|
|
154
|
+
* `exec`s the last simple command in `-c` scripts so the daemon is the
|
|
155
|
+
* tracked PID for typical cases. Multi-statement scripts that need clean
|
|
156
|
+
* tree should write `exec` themselves.
|
|
157
|
+
*/
|
|
158
|
+
shell?: string;
|
|
159
|
+
/** Per-process ring buffer cap in bytes. Zero means server default (1 MiB). */
|
|
160
|
+
ringBytes?: number;
|
|
161
|
+
}
|
|
162
|
+
/** Returned by `vm.bg.exec` on success. */
|
|
163
|
+
interface BgExecResponse {
|
|
164
|
+
execId: string;
|
|
165
|
+
pid: number;
|
|
166
|
+
startedAt: string;
|
|
167
|
+
ringBytes: number;
|
|
168
|
+
}
|
|
169
|
+
/** Status of one background exec — returned by `vm.bg.list` and `vm.bg.info`. */
|
|
170
|
+
interface BgExecInfo {
|
|
171
|
+
execId: string;
|
|
172
|
+
pid: number;
|
|
173
|
+
command: string;
|
|
174
|
+
args?: string[];
|
|
175
|
+
cwd?: string;
|
|
176
|
+
uid?: number;
|
|
177
|
+
startedAt: string;
|
|
178
|
+
running: boolean;
|
|
179
|
+
/** Present once the child has exited. */
|
|
180
|
+
exitCode?: number;
|
|
181
|
+
signal?: string;
|
|
182
|
+
endedAt?: string;
|
|
183
|
+
bytesWritten: number;
|
|
184
|
+
bytesDropped: number;
|
|
185
|
+
/** Next frame id the agent will emit on this exec's log ring. */
|
|
186
|
+
nextId: number;
|
|
187
|
+
ringBytes: number;
|
|
188
|
+
}
|
|
189
|
+
interface BgKillOptions {
|
|
190
|
+
/** Signal name (e.g. `TERM`, `KILL`, `HUP`). Default: `TERM`. */
|
|
191
|
+
signal?: string;
|
|
192
|
+
/** Grace period before the agent escalates to `SIGKILL`. Server default 5000ms. */
|
|
193
|
+
graceMs?: number;
|
|
194
|
+
}
|
|
195
|
+
interface BgKillResponse {
|
|
196
|
+
execId: string;
|
|
197
|
+
pid: number;
|
|
198
|
+
running: boolean;
|
|
199
|
+
signalSent: string;
|
|
200
|
+
}
|
|
201
|
+
interface BgWaitExitResponse {
|
|
202
|
+
execId: string;
|
|
203
|
+
running: boolean;
|
|
204
|
+
exitCode?: number;
|
|
205
|
+
signal?: string;
|
|
206
|
+
endedAt?: string;
|
|
207
|
+
timedOut: boolean;
|
|
208
|
+
}
|
|
209
|
+
interface BgDeleteResponse {
|
|
210
|
+
execId: string;
|
|
211
|
+
reaped: boolean;
|
|
212
|
+
}
|
|
213
|
+
interface BgLogOptions {
|
|
214
|
+
/** Stream live frames after replaying ring contents. */
|
|
215
|
+
follow?: boolean;
|
|
216
|
+
/** Start cursor at frame N. Lower than the live cursor replays history; higher waits (when `follow`). */
|
|
217
|
+
fromId?: number;
|
|
218
|
+
}
|
|
134
219
|
interface FSEntry {
|
|
135
220
|
name: string;
|
|
136
221
|
type: 'file' | 'directory' | 'symlink' | string;
|
|
@@ -456,6 +541,7 @@ declare class VM {
|
|
|
456
541
|
readonly createdAt?: string;
|
|
457
542
|
readonly arch?: string;
|
|
458
543
|
readonly fs: VMFileSystem;
|
|
544
|
+
readonly bg: VMBg;
|
|
459
545
|
private readonly transport;
|
|
460
546
|
constructor(transport: TransportClient, init: VMInit);
|
|
461
547
|
delete(): Promise<void>;
|
|
@@ -505,6 +591,57 @@ declare class VM {
|
|
|
505
591
|
}): Promise<ExecResultBinary>;
|
|
506
592
|
execBuffered(req: ExecRequest): Promise<ExecResult>;
|
|
507
593
|
}
|
|
594
|
+
/**
|
|
595
|
+
* Per-VM background-exec operations. A bg exec is detached at launch (its own
|
|
596
|
+
* session leader), survives client disconnect, and writes stdout/stderr into a
|
|
597
|
+
* per-process ring buffer on the agent. Manage one with the `execId` returned
|
|
598
|
+
* from `exec()` plus `info`, `logs`, `kill`, `wait`, `remove`. The ring stays
|
|
599
|
+
* allocated after the child exits — call `remove()` to free its budget.
|
|
600
|
+
*/
|
|
601
|
+
declare class VMBg {
|
|
602
|
+
private readonly transport;
|
|
603
|
+
private readonly hostname;
|
|
604
|
+
constructor(transport: TransportClient, hostname: string);
|
|
605
|
+
/**
|
|
606
|
+
* Launch a long-running process. `command` + `args` is the deterministic
|
|
607
|
+
* exec form (no shell). Set `shell: '/bin/bash'` (or similar) to opt in
|
|
608
|
+
* to shell semantics — `$VAR` expansion, globs, `&&`/`||`, etc.
|
|
609
|
+
*/
|
|
610
|
+
exec(req: BgExecRequest): Promise<BgExecResponse>;
|
|
611
|
+
/** All background execs the agent currently tracks (running + exited-not-reaped). */
|
|
612
|
+
list(): Promise<BgExecInfo[]>;
|
|
613
|
+
/** Latest status snapshot for one bg exec. Throws 404 if reaped or never existed. */
|
|
614
|
+
info(execId: string): Promise<BgExecInfo>;
|
|
615
|
+
/**
|
|
616
|
+
* NDJSON log stream. Yields one frame per log line — `started`, `stdout`,
|
|
617
|
+
* `stderr`, `exit`, plus optional `gap` frames if the ring evicted history
|
|
618
|
+
* before the requested cursor. Frames carry `data` base64-encoded; the SDK
|
|
619
|
+
* also populates `dataBytes` / `stdoutBytes` / `stderrBytes` Buffers.
|
|
620
|
+
*
|
|
621
|
+
* `follow: false` (default) replays from the cursor and ends when the ring
|
|
622
|
+
* is drained. `follow: true` keeps the stream open until the child exits or
|
|
623
|
+
* the caller breaks out.
|
|
624
|
+
*/
|
|
625
|
+
logs(execId: string, opts?: BgLogOptions): AsyncGenerator<ExecFrame, void, void>;
|
|
626
|
+
/**
|
|
627
|
+
* Signal a running bg exec. Default: SIGTERM with a 5 s grace period before
|
|
628
|
+
* the agent escalates to SIGKILL. No-op (running=false) if the child has
|
|
629
|
+
* already exited.
|
|
630
|
+
*/
|
|
631
|
+
kill(execId: string, opts?: BgKillOptions): Promise<BgKillResponse>;
|
|
632
|
+
/**
|
|
633
|
+
* Long-poll until the child exits or `timeoutSec` elapses. Returns
|
|
634
|
+
* `timedOut: true` if the deadline hit. Server default for `timeoutSec=0`
|
|
635
|
+
* is 30 s.
|
|
636
|
+
*/
|
|
637
|
+
wait(execId: string, timeoutSec?: number): Promise<BgWaitExitResponse>;
|
|
638
|
+
/**
|
|
639
|
+
* Reap a bg exec's ring buffer + registry entry. Does NOT kill a running
|
|
640
|
+
* process — pair with `kill()` for "stop and clean up". After remove,
|
|
641
|
+
* info/logs/kill/wait return 410 Gone.
|
|
642
|
+
*/
|
|
643
|
+
remove(execId: string): Promise<BgDeleteResponse>;
|
|
644
|
+
}
|
|
508
645
|
|
|
509
646
|
/**
|
|
510
647
|
* Top-level namespaces on SlicerClient: hostGroups, vms, secrets.
|
|
@@ -575,4 +712,70 @@ declare class SlicerClient {
|
|
|
575
712
|
getInfo(): Promise<SlicerInfo>;
|
|
576
713
|
}
|
|
577
714
|
|
|
578
|
-
|
|
715
|
+
/**
|
|
716
|
+
* Browser-compatible shell adapter for Slicer VMs.
|
|
717
|
+
*
|
|
718
|
+
* Provides frame encode/decode helpers and a `SlicerShellSession` class that
|
|
719
|
+
* wires a standard browser WebSocket to an xterm.js Terminal instance using
|
|
720
|
+
* the Slicer binary shell protocol.
|
|
721
|
+
*
|
|
722
|
+
* This module intentionally avoids Node-only imports so it can be used in
|
|
723
|
+
* browser bundles.
|
|
724
|
+
*/
|
|
725
|
+
declare const FRAME_TYPE_DATA = 1;
|
|
726
|
+
declare const FRAME_TYPE_WINDOW_SIZE = 2;
|
|
727
|
+
declare const FRAME_TYPE_SHUTDOWN = 3;
|
|
728
|
+
declare const FRAME_TYPE_HEARTBEAT = 4;
|
|
729
|
+
declare const FRAME_TYPE_SESSION_CLOSE = 5;
|
|
730
|
+
/** Encode a frame into the 5-byte-header binary protocol. */
|
|
731
|
+
declare function encodeFrame(frameType: number, payload?: Uint8Array): Uint8Array;
|
|
732
|
+
/** Parse a binary frame. Returns null if the data is malformed. */
|
|
733
|
+
declare function parseFrame(data: ArrayBuffer): {
|
|
734
|
+
frameType: number;
|
|
735
|
+
payload: Uint8Array;
|
|
736
|
+
} | null;
|
|
737
|
+
interface ShellSessionOptions {
|
|
738
|
+
/** WebSocket URL for the shell endpoint (ws:// or wss://). */
|
|
739
|
+
url: string;
|
|
740
|
+
/** Heartbeat interval in ms. Default 30000. */
|
|
741
|
+
heartbeatIntervalMs?: number;
|
|
742
|
+
/** Called when connection state changes. */
|
|
743
|
+
onStateChange?: (state: 'connecting' | 'connected' | 'disconnected') => void;
|
|
744
|
+
/** Called on error. */
|
|
745
|
+
onError?: (error: string) => void;
|
|
746
|
+
}
|
|
747
|
+
/**
|
|
748
|
+
* Minimal xterm.js Terminal interface — only the methods SlicerShellSession
|
|
749
|
+
* actually calls. Avoids requiring @xterm/xterm as a dependency.
|
|
750
|
+
*/
|
|
751
|
+
interface XTermLike {
|
|
752
|
+
onData: (cb: (data: string) => void) => {
|
|
753
|
+
dispose: () => void;
|
|
754
|
+
};
|
|
755
|
+
write: (data: string) => void;
|
|
756
|
+
reset: () => void;
|
|
757
|
+
cols: number;
|
|
758
|
+
rows: number;
|
|
759
|
+
}
|
|
760
|
+
declare class SlicerShellSession {
|
|
761
|
+
private readonly terminal;
|
|
762
|
+
private readonly options;
|
|
763
|
+
private ws;
|
|
764
|
+
private heartbeatTimer;
|
|
765
|
+
private dataDisposable;
|
|
766
|
+
constructor(terminal: XTermLike, options: ShellSessionOptions);
|
|
767
|
+
/** True when the WebSocket is open and relaying. */
|
|
768
|
+
get connected(): boolean;
|
|
769
|
+
/** Open the WebSocket and begin relaying. */
|
|
770
|
+
connect(): void;
|
|
771
|
+
/** Send a graceful shutdown frame and close. */
|
|
772
|
+
disconnect(): void;
|
|
773
|
+
/** Send a window resize. Call this from FitAddon's onResize or a ResizeObserver. */
|
|
774
|
+
resize(cols: number, rows: number): void;
|
|
775
|
+
private sendResize;
|
|
776
|
+
private startHeartbeat;
|
|
777
|
+
private stopHeartbeat;
|
|
778
|
+
private teardown;
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
export { type AddressMapping, type AgentHealth, type BgDeleteResponse, type BgExecInfo, type BgExecRequest, type BgExecResponse, type BgKillOptions, type BgKillResponse, type BgLogOptions, type BgWaitExitResponse, type CreateSecretRequest, type CreateVMOptions, type CreateVMRequest, type CreateVMResponse, type DeleteResponse, type ExecFrame, type ExecRequest, type ExecResult, type ExecResultBinary, type ExecStdio, ExecStdioBase64, ExecStdioText, FRAME_TYPE_DATA, FRAME_TYPE_HEARTBEAT, FRAME_TYPE_SESSION_CLOSE, FRAME_TYPE_SHUTDOWN, FRAME_TYPE_WINDOW_SIZE, type FSEntry, type FSMkdirRequest, type FSWatchEvent, type FSWatchEventType, type FSWatchRequest, Forwarder, type ForwarderListener, type ForwarderOptions, GiB, type HostGroup, HostGroupsAPI, type ListOptions, MiB, NonRootUser, type Secret, SecretExistsError, SecretsAPI, type ShellSessionOptions, type ShutdownRequest, SlicerAPIError, SlicerClient, type SlicerClientOptions, type SlicerInfo, SlicerShellSession, type UpdateSecretRequest, VM, VMBg, VMFileSystem, type VMInfo, type VMInit, type VMLogs, type VMSnapshot, type VMStat, VMsAPI, type WaitOptions, type XTermLike, encodeFrame, parseAddressMapping, parseFrame, resolveTransport };
|
package/dist/index.d.ts
CHANGED
|
@@ -131,6 +131,91 @@ interface ExecResultBinary {
|
|
|
131
131
|
exitCode: number;
|
|
132
132
|
error?: string;
|
|
133
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* Launch parameters for a background exec. Mirrors the Go SDK's
|
|
136
|
+
* `ExecBackgroundRequest`. The child is detached at launch and survives
|
|
137
|
+
* client disconnect; manage it via `vm.bg.list/info/logs/kill/wait/remove`.
|
|
138
|
+
*
|
|
139
|
+
* `command` + `args` is the always-correct deterministic form (matches the
|
|
140
|
+
* `--cmd` / `--arg` CLI flags). For `$VAR` expansion or shell operators set
|
|
141
|
+
* `shell` to a shell path (e.g. `/bin/bash`) and pass the script as
|
|
142
|
+
* `command`; the agent runs `<shell> -lc "<command>"` in that case.
|
|
143
|
+
*/
|
|
144
|
+
interface BgExecRequest {
|
|
145
|
+
command: string;
|
|
146
|
+
args?: string[];
|
|
147
|
+
env?: string[];
|
|
148
|
+
uid?: number;
|
|
149
|
+
gid?: number;
|
|
150
|
+
cwd?: string;
|
|
151
|
+
/**
|
|
152
|
+
* Empty (default): direct exec. Set to a shell path (e.g. `/bin/bash`) for
|
|
153
|
+
* `$VAR` expansion, globs, and shell operators. With a shell, bash auto-
|
|
154
|
+
* `exec`s the last simple command in `-c` scripts so the daemon is the
|
|
155
|
+
* tracked PID for typical cases. Multi-statement scripts that need clean
|
|
156
|
+
* tree should write `exec` themselves.
|
|
157
|
+
*/
|
|
158
|
+
shell?: string;
|
|
159
|
+
/** Per-process ring buffer cap in bytes. Zero means server default (1 MiB). */
|
|
160
|
+
ringBytes?: number;
|
|
161
|
+
}
|
|
162
|
+
/** Returned by `vm.bg.exec` on success. */
|
|
163
|
+
interface BgExecResponse {
|
|
164
|
+
execId: string;
|
|
165
|
+
pid: number;
|
|
166
|
+
startedAt: string;
|
|
167
|
+
ringBytes: number;
|
|
168
|
+
}
|
|
169
|
+
/** Status of one background exec — returned by `vm.bg.list` and `vm.bg.info`. */
|
|
170
|
+
interface BgExecInfo {
|
|
171
|
+
execId: string;
|
|
172
|
+
pid: number;
|
|
173
|
+
command: string;
|
|
174
|
+
args?: string[];
|
|
175
|
+
cwd?: string;
|
|
176
|
+
uid?: number;
|
|
177
|
+
startedAt: string;
|
|
178
|
+
running: boolean;
|
|
179
|
+
/** Present once the child has exited. */
|
|
180
|
+
exitCode?: number;
|
|
181
|
+
signal?: string;
|
|
182
|
+
endedAt?: string;
|
|
183
|
+
bytesWritten: number;
|
|
184
|
+
bytesDropped: number;
|
|
185
|
+
/** Next frame id the agent will emit on this exec's log ring. */
|
|
186
|
+
nextId: number;
|
|
187
|
+
ringBytes: number;
|
|
188
|
+
}
|
|
189
|
+
interface BgKillOptions {
|
|
190
|
+
/** Signal name (e.g. `TERM`, `KILL`, `HUP`). Default: `TERM`. */
|
|
191
|
+
signal?: string;
|
|
192
|
+
/** Grace period before the agent escalates to `SIGKILL`. Server default 5000ms. */
|
|
193
|
+
graceMs?: number;
|
|
194
|
+
}
|
|
195
|
+
interface BgKillResponse {
|
|
196
|
+
execId: string;
|
|
197
|
+
pid: number;
|
|
198
|
+
running: boolean;
|
|
199
|
+
signalSent: string;
|
|
200
|
+
}
|
|
201
|
+
interface BgWaitExitResponse {
|
|
202
|
+
execId: string;
|
|
203
|
+
running: boolean;
|
|
204
|
+
exitCode?: number;
|
|
205
|
+
signal?: string;
|
|
206
|
+
endedAt?: string;
|
|
207
|
+
timedOut: boolean;
|
|
208
|
+
}
|
|
209
|
+
interface BgDeleteResponse {
|
|
210
|
+
execId: string;
|
|
211
|
+
reaped: boolean;
|
|
212
|
+
}
|
|
213
|
+
interface BgLogOptions {
|
|
214
|
+
/** Stream live frames after replaying ring contents. */
|
|
215
|
+
follow?: boolean;
|
|
216
|
+
/** Start cursor at frame N. Lower than the live cursor replays history; higher waits (when `follow`). */
|
|
217
|
+
fromId?: number;
|
|
218
|
+
}
|
|
134
219
|
interface FSEntry {
|
|
135
220
|
name: string;
|
|
136
221
|
type: 'file' | 'directory' | 'symlink' | string;
|
|
@@ -456,6 +541,7 @@ declare class VM {
|
|
|
456
541
|
readonly createdAt?: string;
|
|
457
542
|
readonly arch?: string;
|
|
458
543
|
readonly fs: VMFileSystem;
|
|
544
|
+
readonly bg: VMBg;
|
|
459
545
|
private readonly transport;
|
|
460
546
|
constructor(transport: TransportClient, init: VMInit);
|
|
461
547
|
delete(): Promise<void>;
|
|
@@ -505,6 +591,57 @@ declare class VM {
|
|
|
505
591
|
}): Promise<ExecResultBinary>;
|
|
506
592
|
execBuffered(req: ExecRequest): Promise<ExecResult>;
|
|
507
593
|
}
|
|
594
|
+
/**
|
|
595
|
+
* Per-VM background-exec operations. A bg exec is detached at launch (its own
|
|
596
|
+
* session leader), survives client disconnect, and writes stdout/stderr into a
|
|
597
|
+
* per-process ring buffer on the agent. Manage one with the `execId` returned
|
|
598
|
+
* from `exec()` plus `info`, `logs`, `kill`, `wait`, `remove`. The ring stays
|
|
599
|
+
* allocated after the child exits — call `remove()` to free its budget.
|
|
600
|
+
*/
|
|
601
|
+
declare class VMBg {
|
|
602
|
+
private readonly transport;
|
|
603
|
+
private readonly hostname;
|
|
604
|
+
constructor(transport: TransportClient, hostname: string);
|
|
605
|
+
/**
|
|
606
|
+
* Launch a long-running process. `command` + `args` is the deterministic
|
|
607
|
+
* exec form (no shell). Set `shell: '/bin/bash'` (or similar) to opt in
|
|
608
|
+
* to shell semantics — `$VAR` expansion, globs, `&&`/`||`, etc.
|
|
609
|
+
*/
|
|
610
|
+
exec(req: BgExecRequest): Promise<BgExecResponse>;
|
|
611
|
+
/** All background execs the agent currently tracks (running + exited-not-reaped). */
|
|
612
|
+
list(): Promise<BgExecInfo[]>;
|
|
613
|
+
/** Latest status snapshot for one bg exec. Throws 404 if reaped or never existed. */
|
|
614
|
+
info(execId: string): Promise<BgExecInfo>;
|
|
615
|
+
/**
|
|
616
|
+
* NDJSON log stream. Yields one frame per log line — `started`, `stdout`,
|
|
617
|
+
* `stderr`, `exit`, plus optional `gap` frames if the ring evicted history
|
|
618
|
+
* before the requested cursor. Frames carry `data` base64-encoded; the SDK
|
|
619
|
+
* also populates `dataBytes` / `stdoutBytes` / `stderrBytes` Buffers.
|
|
620
|
+
*
|
|
621
|
+
* `follow: false` (default) replays from the cursor and ends when the ring
|
|
622
|
+
* is drained. `follow: true` keeps the stream open until the child exits or
|
|
623
|
+
* the caller breaks out.
|
|
624
|
+
*/
|
|
625
|
+
logs(execId: string, opts?: BgLogOptions): AsyncGenerator<ExecFrame, void, void>;
|
|
626
|
+
/**
|
|
627
|
+
* Signal a running bg exec. Default: SIGTERM with a 5 s grace period before
|
|
628
|
+
* the agent escalates to SIGKILL. No-op (running=false) if the child has
|
|
629
|
+
* already exited.
|
|
630
|
+
*/
|
|
631
|
+
kill(execId: string, opts?: BgKillOptions): Promise<BgKillResponse>;
|
|
632
|
+
/**
|
|
633
|
+
* Long-poll until the child exits or `timeoutSec` elapses. Returns
|
|
634
|
+
* `timedOut: true` if the deadline hit. Server default for `timeoutSec=0`
|
|
635
|
+
* is 30 s.
|
|
636
|
+
*/
|
|
637
|
+
wait(execId: string, timeoutSec?: number): Promise<BgWaitExitResponse>;
|
|
638
|
+
/**
|
|
639
|
+
* Reap a bg exec's ring buffer + registry entry. Does NOT kill a running
|
|
640
|
+
* process — pair with `kill()` for "stop and clean up". After remove,
|
|
641
|
+
* info/logs/kill/wait return 410 Gone.
|
|
642
|
+
*/
|
|
643
|
+
remove(execId: string): Promise<BgDeleteResponse>;
|
|
644
|
+
}
|
|
508
645
|
|
|
509
646
|
/**
|
|
510
647
|
* Top-level namespaces on SlicerClient: hostGroups, vms, secrets.
|
|
@@ -575,4 +712,70 @@ declare class SlicerClient {
|
|
|
575
712
|
getInfo(): Promise<SlicerInfo>;
|
|
576
713
|
}
|
|
577
714
|
|
|
578
|
-
|
|
715
|
+
/**
|
|
716
|
+
* Browser-compatible shell adapter for Slicer VMs.
|
|
717
|
+
*
|
|
718
|
+
* Provides frame encode/decode helpers and a `SlicerShellSession` class that
|
|
719
|
+
* wires a standard browser WebSocket to an xterm.js Terminal instance using
|
|
720
|
+
* the Slicer binary shell protocol.
|
|
721
|
+
*
|
|
722
|
+
* This module intentionally avoids Node-only imports so it can be used in
|
|
723
|
+
* browser bundles.
|
|
724
|
+
*/
|
|
725
|
+
declare const FRAME_TYPE_DATA = 1;
|
|
726
|
+
declare const FRAME_TYPE_WINDOW_SIZE = 2;
|
|
727
|
+
declare const FRAME_TYPE_SHUTDOWN = 3;
|
|
728
|
+
declare const FRAME_TYPE_HEARTBEAT = 4;
|
|
729
|
+
declare const FRAME_TYPE_SESSION_CLOSE = 5;
|
|
730
|
+
/** Encode a frame into the 5-byte-header binary protocol. */
|
|
731
|
+
declare function encodeFrame(frameType: number, payload?: Uint8Array): Uint8Array;
|
|
732
|
+
/** Parse a binary frame. Returns null if the data is malformed. */
|
|
733
|
+
declare function parseFrame(data: ArrayBuffer): {
|
|
734
|
+
frameType: number;
|
|
735
|
+
payload: Uint8Array;
|
|
736
|
+
} | null;
|
|
737
|
+
interface ShellSessionOptions {
|
|
738
|
+
/** WebSocket URL for the shell endpoint (ws:// or wss://). */
|
|
739
|
+
url: string;
|
|
740
|
+
/** Heartbeat interval in ms. Default 30000. */
|
|
741
|
+
heartbeatIntervalMs?: number;
|
|
742
|
+
/** Called when connection state changes. */
|
|
743
|
+
onStateChange?: (state: 'connecting' | 'connected' | 'disconnected') => void;
|
|
744
|
+
/** Called on error. */
|
|
745
|
+
onError?: (error: string) => void;
|
|
746
|
+
}
|
|
747
|
+
/**
|
|
748
|
+
* Minimal xterm.js Terminal interface — only the methods SlicerShellSession
|
|
749
|
+
* actually calls. Avoids requiring @xterm/xterm as a dependency.
|
|
750
|
+
*/
|
|
751
|
+
interface XTermLike {
|
|
752
|
+
onData: (cb: (data: string) => void) => {
|
|
753
|
+
dispose: () => void;
|
|
754
|
+
};
|
|
755
|
+
write: (data: string) => void;
|
|
756
|
+
reset: () => void;
|
|
757
|
+
cols: number;
|
|
758
|
+
rows: number;
|
|
759
|
+
}
|
|
760
|
+
declare class SlicerShellSession {
|
|
761
|
+
private readonly terminal;
|
|
762
|
+
private readonly options;
|
|
763
|
+
private ws;
|
|
764
|
+
private heartbeatTimer;
|
|
765
|
+
private dataDisposable;
|
|
766
|
+
constructor(terminal: XTermLike, options: ShellSessionOptions);
|
|
767
|
+
/** True when the WebSocket is open and relaying. */
|
|
768
|
+
get connected(): boolean;
|
|
769
|
+
/** Open the WebSocket and begin relaying. */
|
|
770
|
+
connect(): void;
|
|
771
|
+
/** Send a graceful shutdown frame and close. */
|
|
772
|
+
disconnect(): void;
|
|
773
|
+
/** Send a window resize. Call this from FitAddon's onResize or a ResizeObserver. */
|
|
774
|
+
resize(cols: number, rows: number): void;
|
|
775
|
+
private sendResize;
|
|
776
|
+
private startHeartbeat;
|
|
777
|
+
private stopHeartbeat;
|
|
778
|
+
private teardown;
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
export { type AddressMapping, type AgentHealth, type BgDeleteResponse, type BgExecInfo, type BgExecRequest, type BgExecResponse, type BgKillOptions, type BgKillResponse, type BgLogOptions, type BgWaitExitResponse, type CreateSecretRequest, type CreateVMOptions, type CreateVMRequest, type CreateVMResponse, type DeleteResponse, type ExecFrame, type ExecRequest, type ExecResult, type ExecResultBinary, type ExecStdio, ExecStdioBase64, ExecStdioText, FRAME_TYPE_DATA, FRAME_TYPE_HEARTBEAT, FRAME_TYPE_SESSION_CLOSE, FRAME_TYPE_SHUTDOWN, FRAME_TYPE_WINDOW_SIZE, type FSEntry, type FSMkdirRequest, type FSWatchEvent, type FSWatchEventType, type FSWatchRequest, Forwarder, type ForwarderListener, type ForwarderOptions, GiB, type HostGroup, HostGroupsAPI, type ListOptions, MiB, NonRootUser, type Secret, SecretExistsError, SecretsAPI, type ShellSessionOptions, type ShutdownRequest, SlicerAPIError, SlicerClient, type SlicerClientOptions, type SlicerInfo, SlicerShellSession, type UpdateSecretRequest, VM, VMBg, VMFileSystem, type VMInfo, type VMInit, type VMLogs, type VMSnapshot, type VMStat, VMsAPI, type WaitOptions, type XTermLike, encodeFrame, parseAddressMapping, parseFrame, resolveTransport };
|