@kottera/tera-web 0.1.0-rc.6 → 0.1.0-rc.7

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.
@@ -0,0 +1,176 @@
1
+ /** The protocol version this codec speaks. */
2
+ export declare const VERSION = 1;
3
+ /** The WebSocket subprotocol a view negotiates. */
4
+ export declare const SUBPROTOCOL = "tera.terminalwire.v1";
5
+ export declare const HEADER_SIZE = 4;
6
+ /** The bound on a DATA or INPUT payload: the runner link's stream frame. */
7
+ export declare const MAX_DATA_PAYLOAD: number;
8
+ /** The bound on a CBOR control body. */
9
+ export declare const MAX_CONTROL_PAYLOAD: number;
10
+ /** The bound on any frame's payload, a type this version does not know included. */
11
+ export declare const MAX_PAYLOAD: number;
12
+ /** The largest frame, and so the largest message, on the wire. */
13
+ export declare const MAX_FRAME_BYTES: number;
14
+ /**
15
+ * The bound on an output offset, 2^53-1: every offset the wire admits is a
16
+ * number held exactly. An encoder refuses one above it and a decoder reads a
17
+ * body carrying one as malformed, as the Go codec does.
18
+ */
19
+ export declare const MAX_OFFSET: number;
20
+ /**
21
+ * The frame types of version 1. Zero is no frame; a value is never reassigned.
22
+ * SIGNAL carries one keystroke's character outside the input window; its
23
+ * contract is sdk/terminalwire's `TypeSignal` (`encodeSignal`).
24
+ */
25
+ export declare const FrameType: {
26
+ readonly Welcome: 1;
27
+ readonly Data: 2;
28
+ readonly Resync: 3;
29
+ readonly ReplayEnd: 4;
30
+ readonly InputAck: 5;
31
+ readonly Status: 6;
32
+ readonly Close: 7;
33
+ readonly Input: 8;
34
+ readonly Ack: 9;
35
+ readonly Resize: 10;
36
+ readonly Control: 11;
37
+ readonly Signal: 12;
38
+ };
39
+ export type FrameType = (typeof FrameType)[keyof typeof FrameType];
40
+ /** Whether this version knows frame type `t`. A receiver ignores a frame it does not. */
41
+ export declare function isKnownFrameType(t: number): t is FrameType;
42
+ /** The wire name of a frame type: `WELCOME`, `DATA`, …; `FrameType(42)` for one this version does not know. */
43
+ export declare function frameTypeName(t: number): string;
44
+ /** Why a frame was refused, by the corpus's classes, beside the encoder's own. */
45
+ export type TerminalwireErrorKind = "truncated" | "too_large" | "malformed" | "wrong_type" | "not_in_vocabulary";
46
+ export declare class TerminalwireError extends Error {
47
+ readonly kind: TerminalwireErrorKind;
48
+ constructor(kind: TerminalwireErrorKind, message: string);
49
+ }
50
+ /** One frame. `payload` is a view of the buffer the frame was read from. */
51
+ export interface Frame {
52
+ readonly type: number;
53
+ readonly payload: Uint8Array;
54
+ }
55
+ /** A terminal's size in cells. */
56
+ export interface Size {
57
+ cols: number;
58
+ rows: number;
59
+ }
60
+ /** A view's part in its session (ADR-180 D7). */
61
+ export declare const Role: {
62
+ readonly Controller: "controller";
63
+ readonly Viewer: "viewer";
64
+ };
65
+ export type Role = (typeof Role)[keyof typeof Role];
66
+ /** Why a view ended, from a closed set (ADR-180 D4). */
67
+ export declare const CloseReason: {
68
+ readonly Detached: "detached";
69
+ readonly Exited: "exited";
70
+ readonly Handover: "handover";
71
+ readonly Reauthenticate: "reauthenticate";
72
+ readonly NotAttendee: "not-attendee";
73
+ readonly Superseded: "superseded";
74
+ readonly RunnerUnreachable: "runner-unreachable";
75
+ readonly FlowControl: "flow-control";
76
+ readonly Expired: "expired";
77
+ };
78
+ export type CloseReason = (typeof CloseReason)[keyof typeof CloseReason];
79
+ /** What a CONTROL frame asks (ADR-180 D7). */
80
+ export declare const ControlAction: {
81
+ readonly Take: "take";
82
+ readonly Release: "release";
83
+ };
84
+ export type ControlAction = (typeof ControlAction)[keyof typeof ControlAction];
85
+ /** Opens a view, minder → client. */
86
+ export interface Welcome {
87
+ /** The minder's protocol version; a client sends nothing it lacks. */
88
+ version: number;
89
+ /** The view's id, the client's, kept across reconnects. */
90
+ viewId: string;
91
+ role: Role;
92
+ /** Whether this view's RESIZE sizes the pty. */
93
+ setsSize: boolean;
94
+ /** The pty's size. */
95
+ size: Size;
96
+ /** The output offset the following DATA starts at, at most MAX_OFFSET. */
97
+ offset: number;
98
+ /** Whether the DATA that follows is history, ended by REPLAY_END. */
99
+ replay: boolean;
100
+ /** How many views the session has, this one included. */
101
+ views: number;
102
+ }
103
+ /** Moves a view's base offset after its cursor fell out of the ring. */
104
+ export interface Resync {
105
+ offset: number;
106
+ replay: boolean;
107
+ }
108
+ /** The session's state, minder → client. */
109
+ export interface Status {
110
+ /** The receiving view's part. */
111
+ role: Role;
112
+ views: number;
113
+ /** The pty's size, which a view that does not set the size renders at. */
114
+ size: Size;
115
+ /** The controlling view's id; empty when none controls. */
116
+ controller: string;
117
+ /** The id of the view whose RESIZE sizes the pty. */
118
+ sizeSetter: string;
119
+ /** A handover is waiting for the session to go quiet. */
120
+ handoverPending: boolean;
121
+ /** The process exited, with its status and, when a signal ended it, the signal's name. */
122
+ exited: boolean;
123
+ exitStatus: number;
124
+ exitSignal: string;
125
+ }
126
+ /** Ends a view, either way. */
127
+ export interface Close {
128
+ reason: CloseReason;
129
+ /** Reconnect at once with the view id. */
130
+ reconnect: boolean;
131
+ }
132
+ /** Takes or releases control, client → minder. */
133
+ export interface Control {
134
+ action: ControlAction;
135
+ }
136
+ /** Reads a header: the frame type and the payload length. */
137
+ export declare function parseHeader(msg: ArrayBuffer | Uint8Array): {
138
+ type: number;
139
+ length: number;
140
+ };
141
+ /** Reads a message holding exactly one frame. The payload aliases the message. */
142
+ export declare function decodeFrame(msg: ArrayBuffer | Uint8Array): Frame;
143
+ /** A DATA or INPUT frame of `bytes`. */
144
+ export declare function encodeBytes(type: typeof FrameType.Data | typeof FrameType.Input, bytes: Uint8Array): Uint8Array;
145
+ export declare function encodeReplayEnd(): Uint8Array;
146
+ /** An ACK or INPUT_ACK frame of `count` bytes. */
147
+ export declare function encodeCount(type: typeof FrameType.Ack | typeof FrameType.InputAck, count: number): Uint8Array;
148
+ /** An ACK or INPUT_ACK frame's count. Bytes past the first four are a later version's. */
149
+ export declare function decodeCount(f: Frame): number;
150
+ /**
151
+ * A SIGNAL frame of one keystroke's character, `char` the byte the key
152
+ * produces (0x03 for Ctrl-C). It rides outside the input window, so it is how
153
+ * an interrupt reaches a session whose window is full (PRD-031 SC6). The
154
+ * minder signals the foreground process group when the byte is the pty's
155
+ * interrupt, quit or suspend character and ISIG is set, and drops it
156
+ * otherwise; it never queues it and never grants it back. A client sends a
157
+ * keystroke as INPUT while its credit holds it, and a one-byte keystroke the
158
+ * credit cannot hold as one SIGNAL instead of holding it for credit, once per
159
+ * keystroke (sdk/terminalwire `TypeSignal` states the whole contract).
160
+ */
161
+ export declare function encodeSignal(char: number): Uint8Array;
162
+ /** A SIGNAL frame's character. Bytes past the first are a later version's. */
163
+ export declare function decodeSignal(f: Frame): number;
164
+ export declare function encodeResize(size: Size): Uint8Array;
165
+ /** A RESIZE frame's size. Bytes past the first four are a later version's. */
166
+ export declare function decodeResize(f: Frame): Size;
167
+ export declare function encodeWelcome(w: Welcome): Uint8Array;
168
+ export declare function decodeWelcome(f: Frame): Welcome;
169
+ export declare function encodeResync(s: Resync): Uint8Array;
170
+ export declare function decodeResync(f: Frame): Resync;
171
+ export declare function encodeStatus(s: Status): Uint8Array;
172
+ export declare function decodeStatus(f: Frame): Status;
173
+ export declare function encodeClose(c: Close): Uint8Array;
174
+ export declare function decodeClose(f: Frame): Close;
175
+ export declare function encodeControl(c: Control): Uint8Array;
176
+ export declare function decodeControl(f: Frame): Control;