ai-remote 0.4.8 → 0.4.9

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.
Files changed (43) hide show
  1. package/dist/index.d.ts +254 -12
  2. package/dist/protocols.d.ts +349 -0
  3. package/package.json +3 -3
  4. package/dist/protocols/index.d.ts +0 -33
  5. package/dist/protocols/rdp/buffer.d.ts +0 -38
  6. package/dist/protocols/rdp/caps.d.ts +0 -49
  7. package/dist/protocols/rdp/cert.d.ts +0 -18
  8. package/dist/protocols/rdp/client.d.ts +0 -56
  9. package/dist/protocols/rdp/cliprdr.d.ts +0 -27
  10. package/dist/protocols/rdp/credssp.d.ts +0 -34
  11. package/dist/protocols/rdp/crypto.d.ts +0 -63
  12. package/dist/protocols/rdp/display.d.ts +0 -38
  13. package/dist/protocols/rdp/gcc.d.ts +0 -23
  14. package/dist/protocols/rdp/keymap.d.ts +0 -9
  15. package/dist/protocols/rdp/mcs.d.ts +0 -40
  16. package/dist/protocols/rdp/ntlm.d.ts +0 -61
  17. package/dist/protocols/rdp/pdu.d.ts +0 -155
  18. package/dist/protocols/rdp/rail.d.ts +0 -119
  19. package/dist/protocols/rdp/rle.d.ts +0 -13
  20. package/dist/protocols/rdp/sec.d.ts +0 -59
  21. package/dist/protocols/rdp/session.d.ts +0 -62
  22. package/dist/protocols/rdp/tls.d.ts +0 -18
  23. package/dist/protocols/rdp/vchannel.d.ts +0 -28
  24. package/dist/protocols/rdp/x224.d.ts +0 -40
  25. package/dist/protocols/ssh/identity.d.ts +0 -39
  26. package/dist/protocols/ssh/kex.d.ts +0 -97
  27. package/dist/protocols/ssh/messages.d.ts +0 -52
  28. package/dist/protocols/ssh/session.d.ts +0 -67
  29. package/dist/protocols/ssh/terminal.d.ts +0 -46
  30. package/dist/protocols/ssh/transport.d.ts +0 -62
  31. package/dist/protocols/ssh/wire.d.ts +0 -52
  32. package/dist/protocols/types.d.ts +0 -127
  33. package/dist/protocols/vnc/des.d.ts +0 -25
  34. package/dist/protocols/vnc/input.d.ts +0 -5
  35. package/dist/protocols/vnc/keysyms.d.ts +0 -16
  36. package/dist/protocols/vnc/rfb.d.ts +0 -64
  37. package/dist/protocols/vnc/session.d.ts +0 -12
  38. package/dist/shared/connection.d.ts +0 -81
  39. package/dist/shared/device.d.ts +0 -26
  40. package/dist/shared/hosts.d.ts +0 -63
  41. package/dist/shared/icons.d.ts +0 -46
  42. package/dist/shared/protocol.d.ts +0 -32
  43. package/dist/shared/signals.d.ts +0 -37
package/dist/index.d.ts CHANGED
@@ -1,13 +1,255 @@
1
1
  /**
2
- * The vocabulary every host of this stack shares.
3
- *
4
- * Deliberately no protocol engines: a Worker that only needs to know what a
5
- * host roster is should not pull noVNC or an RDP state machine into its
6
- * bundle. The engines live behind `@remotectl/core/protocols`.
7
- */
8
- export * from './shared/connection';
9
- export * from './shared/device';
10
- export * from './shared/hosts';
11
- export * from './shared/icons';
12
- export * from './shared/protocol';
13
- export * from './shared/signals';
2
+ * The vocabulary both halves of the gateway share.
3
+ *
4
+ * The Worker and the browser have to agree on what a "protocol" is, what ports
5
+ * they default to and how an RDP security layer is named, so those live here
6
+ * rather than being re-declared on each side and drifting apart.
7
+ */
8
+ /** A remote-desktop protocol the session workspace can display. */
9
+ export declare const REMOTE_PROTOCOLS: readonly ['vnc', 'rdp'];
10
+ export type RemoteProtocol = (typeof REMOTE_PROTOCOLS)[number];
11
+ /** Every protocol the gateway relays, including the terminal side panel. */
12
+ export declare const TRANSPORT_PROTOCOLS: readonly ['vnc', 'rdp', 'ssh'];
13
+ export type TransportProtocol = (typeof TRANSPORT_PROTOCOLS)[number];
14
+ /**
15
+ * The RDP security layer. `auto` negotiates with the host, which is right for
16
+ * anything that answers honestly; the rest are for hosts that do not.
17
+ */
18
+ export declare const RDP_SECURITY_MODES: readonly ['auto', 'nla', 'tls', 'rdp'];
19
+ export type RdpSecurity = (typeof RDP_SECURITY_MODES)[number];
20
+ export declare const DEFAULT_PORTS: Record<TransportProtocol, number>;
21
+ export declare const DEFAULT_SSH_PORT: number;
22
+ /** Max time allowed before command start output is detected. */
23
+ export declare const COMMAND_START_MS = 15000;
24
+ /** Max idle silence allowed during command execution. */
25
+ export declare const COMMAND_IDLE_MS: number;
26
+ export declare function isRemoteProtocol(value: unknown): value is RemoteProtocol;
27
+ export declare function isRdpSecurity(value: unknown): value is RdpSecurity;
28
+ /** Coerce anything to a protocol, falling back to what the caller opens on. */
29
+ export declare function toRemoteProtocol(value: unknown, fallback?: RemoteProtocol): RemoteProtocol;
30
+ export declare function toRdpSecurity(value: unknown, fallback?: RdpSecurity): RdpSecurity;
31
+ /** A port number, or the protocol's default when the value is not one. */
32
+ export declare function toPort(value: unknown, fallback: number): number;
33
+ /** A published Windows application launched instead of the full desktop. */
34
+ export interface RemoteAppLaunch {
35
+ /** Alias (`||notepad`) or an executable path. */
36
+ program: string;
37
+ workingDir?: string;
38
+ arguments?: string;
39
+ }
40
+ /** The companion terminal offered beside a desktop. */
41
+ export interface SshCompanion {
42
+ enabled: boolean;
43
+ port: number;
44
+ username: string;
45
+ }
46
+ /** Picture and input options. VNC negotiates them; RDP and SSH ignore what does not apply. */
47
+ export interface DisplaySettings {
48
+ /** RFB quality level, 1 (smallest) to 9 (sharpest). */
49
+ quality: number;
50
+ /** RFB compression level, 0 (fastest) to 9 (smallest). */
51
+ compression: number;
52
+ /** Fit the remote desktop to the pane rather than scrolling it. */
53
+ scaling: boolean;
54
+ /** Watch without sending keyboard or pointer input. */
55
+ viewOnly: boolean;
56
+ }
57
+ /**
58
+ * Everything a session needs. `password` is the only field never persisted
59
+ * anywhere -- not in the device library on the gateway, not in localStorage.
60
+ */
61
+ export interface ConnectionSettings {
62
+ /** Stable identity: protocol, address, port and program. See {@link connectionId}. */
63
+ id: string;
64
+ label: string;
65
+ protocol: RemoteProtocol;
66
+ host: string;
67
+ port: number;
68
+ username: string;
69
+ password: string;
70
+ /** Windows domain or computer name. RDP only. */
71
+ domain: string;
72
+ security: RdpSecurity;
73
+ remoteApp: RemoteAppLaunch | null;
74
+ display: DisplaySettings;
75
+ ssh: SshCompanion;
76
+ /** Open the terminal panel as soon as the desktop appears. */
77
+ openSshOnConnect: boolean;
78
+ }
79
+ export declare const DEFAULT_DISPLAY_SETTINGS: DisplaySettings;
80
+ /**
81
+ * A connection's identity is what it points at, not when it was made. Editing
82
+ * the address therefore makes a different connection rather than silently
83
+ * repointing an existing card, which is the behaviour people expect from a
84
+ * list of machines.
85
+ */
86
+ export declare function connectionId(input: Pick<ConnectionSettings, 'protocol' | 'host' | 'port'> & {
87
+ remoteApp?: RemoteAppLaunch | null;
88
+ }): string;
89
+ /** A blank connection, ready for the dialog to fill in. */
90
+ export declare function emptyConnection(protocol?: RemoteProtocol): ConnectionSettings;
91
+ export declare function normalizeDisplaySettings(value: unknown): DisplaySettings;
92
+ /**
93
+ * Build a complete, valid connection out of whatever a caller happens to have.
94
+ * Partial input from a saved card, a host list entry, a URL or localStorage all
95
+ * arrive here, so the dialog never has to reason about missing fields.
96
+ */
97
+ export declare function normalizeConnection(input: Partial<ConnectionSettings> & Record<string, unknown>): ConnectionSettings;
98
+ /** What a connection is worth remembering by -- never the password. */
99
+ export type PersistedConnection = Omit<ConnectionSettings, 'password'>;
100
+ export declare function withoutPassword(settings: ConnectionSettings): PersistedConnection;
101
+ /** A one-line description for the dialog's summary row and the status bar. */
102
+ export declare function describeConnection(settings: ConnectionSettings): string;
103
+ export interface SavedDevice {
104
+ id: string;
105
+ label: string;
106
+ host: string;
107
+ port: number;
108
+ protocol: RemoteProtocol;
109
+ domain?: string;
110
+ security?: RdpSecurity;
111
+ /** RemoteApp alias (`||notepad`) when this card launches an app, not a desktop. */
112
+ program?: string;
113
+ favorite?: boolean;
114
+ /** Milliseconds since the epoch; drives the "recent" ordering. */
115
+ lastUsed?: number;
116
+ createdAt?: number;
117
+ /** Set when a thumbnail exists, so the client can cache-bust its <img>. */
118
+ thumbnailAt?: number;
119
+ }
120
+ /** Optional SSH access to the same machine, which publishes a terminal for it. */
121
+ export interface HostSshAccess {
122
+ port: number;
123
+ username?: string;
124
+ }
125
+ /** One machine as the gateway's configuration describes it. */
126
+ export interface RemoteHostTarget {
127
+ id: string;
128
+ name: string;
129
+ host: string;
130
+ port: number;
131
+ protocol: RemoteProtocol;
132
+ /** Windows domain or computer name pre-filled in the connect dialog. */
133
+ domain?: string;
134
+ security?: RdpSecurity;
135
+ remoteApp?: RemoteAppLaunch;
136
+ ssh?: HostSshAccess;
137
+ }
138
+ /**
139
+ * Build the target list offered in the connect dialog. `VNC_HOSTS` and
140
+ * `RDP_HOSTS` are merged into one list; each entry may override its protocol,
141
+ * so a single list can carry both kinds of target.
142
+ */
143
+ export declare function parseConfiguredHosts(options: {
144
+ vncHostsJson?: string;
145
+ rdpHostsJson?: string;
146
+ defaultHost?: string;
147
+ defaultPort?: string;
148
+ defaultRdpHost?: string;
149
+ defaultRdpPort?: string;
150
+ }): RemoteHostTarget[];
151
+ /** One allowed network, as a base address and a mask. */
152
+ export interface Subnet {
153
+ base: number;
154
+ mask: number;
155
+ }
156
+ /** Dotted-quad to a 32-bit number, or null for anything that is not one. */
157
+ export declare function ipv4ToInt(value: string): number | null;
158
+ /**
159
+ * The networks this gateway may dial, beyond the machines named in the host
160
+ * lists. Written as `ALLOWED_SUBNETS`, comma-separated:
161
+ *
162
+ * 192.168.8.0/24 a CIDR block
163
+ * 192.168.8.* the same thing, written the way people say it
164
+ * 192.168.8.67 a single address
165
+ *
166
+ * This is what lets a terminal open on a machine that was never listed. Keep it
167
+ * to networks you own: anything inside one can be reached on any port by anyone
168
+ * who gets past the gateway's login.
169
+ */
170
+ export declare function parseAllowedSubnets(value?: string): Subnet[];
171
+ /** Whether a dotted-quad address falls inside one of the allowed networks. */
172
+ export declare function hostInAllowedSubnets(host: string, value?: string): boolean;
173
+ /**
174
+ * Icon path data, shared by the server-rendered login page and the React app.
175
+ *
176
+ * Each value is the inside of a 24x24 stroked `<svg>`; the wrapper differs
177
+ * between the two (a string on the Worker, a component in the browser) but the
178
+ * geometry should not.
179
+ */
180
+ export declare const ICON_PATHS: {
181
+ readonly monitor: '<rect x="2" y="3" width="20" height="14" rx="2"/><path d="M8 21h8M12 17v4"/>';
182
+ readonly link: '<path d="M9 17H7A5 5 0 0 1 7 7h2M15 7h2a5 5 0 1 1 0 10h-2M8 12h8"/>';
183
+ readonly power: '<path d="M12 2v10"/><path d="M18.4 6.6a9 9 0 1 1-12.8 0"/>';
184
+ readonly maximize: '<path d="M8 3H5a2 2 0 0 0-2 2v3M21 8V5a2 2 0 0 0-2-2h-3M3 16v3a2 2 0 0 0 2 2h3M16 21h3a2 2 0 0 0 2-2v-3"/>';
185
+ readonly minimize: '<path d="M8 3v3a2 2 0 0 1-2 2H3M21 8h-3a2 2 0 0 1-2-2V3M3 16h3a2 2 0 0 1 2 2v3M16 21v-3a2 2 0 0 1 2-2h3"/>';
186
+ readonly keyboard: '<rect x="2" y="4" width="20" height="16" rx="2"/><path d="M6 8h.01M10 8h.01M14 8h.01M18 8h.01M8 12h.01M12 12h.01M16 12h.01M7 16h10"/>';
187
+ readonly clipboard: '<rect x="8" y="2" width="8" height="4" rx="1"/><path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"/>';
188
+ readonly check: '<path d="m5 13 4 4 10-10"/>';
189
+ readonly camera: '<path d="M14.5 4h-5L7 7H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-3l-2.5-3z"/><circle cx="12" cy="13" r="3"/>';
190
+ readonly eye: '<path d="M2 12s3.5-6 10-6 10 6 10 6-3.5 6-10 6S2 12 2 12z"/><circle cx="12" cy="12" r="3"/>';
191
+ readonly sliders: '<path d="M4 21v-7M4 10V3M12 21v-9M12 8V3M20 21v-5M20 12V3M2 14h4M10 8h4M18 16h4"/>';
192
+ readonly expand: '<path d="M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"/>';
193
+ readonly shield: '<path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/>';
194
+ readonly chevron: '<path d="m6 9 6 6 6-6"/>';
195
+ readonly back: '<path d="m15 18-6-6 6-6"/>';
196
+ readonly zap: '<path d="M13 2 3 14h9l-1 8 10-12h-9l1-8z"/>';
197
+ readonly cube: '<path d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"/><path d="m3.3 7 8.7 5 8.7-5M12 22V12"/>';
198
+ readonly logout: '<path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4M16 17l5-5-5-5M21 12H9"/>';
199
+ readonly clock: '<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3.5 2"/>';
200
+ readonly activity: '<path d="M22 12h-4l-3 9L9 3l-3 9H2"/>';
201
+ readonly transfer: '<path d="m3 16 4 4 4-4M7 20V4M21 8l-4-4-4 4M17 4v16"/>';
202
+ readonly screen: '<rect x="2" y="5" width="20" height="13" rx="2"/><path d="M7 21h10"/>';
203
+ readonly command: '<path d="M15 6a3 3 0 1 1 3 3h-3zm0 0v12m0 0a3 3 0 1 0 3-3h-3zM9 6a3 3 0 1 0-3 3h3zm0 0v12m0 0a3 3 0 1 1-3-3h3z"/>';
204
+ readonly apps: '<rect x="3" y="3" width="7" height="7" rx="1"/><rect x="14" y="3" width="7" height="7" rx="1"/><rect x="3" y="14" width="7" height="7" rx="1"/><rect x="14" y="14" width="7" height="7" rx="1"/>';
205
+ readonly terminal: '<path d="m4 17 6-6-6-6M12 19h8"/>';
206
+ readonly folder: '<path d="M3 7h6l2 2h10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/><path d="M3 7V6a2 2 0 0 1 2-2h4l2 3"/>';
207
+ readonly close: '<path d="M18 6 6 18M6 6l12 12"/>';
208
+ readonly sparkles: '<path d="m12 3 1.9 5.1L19 10l-5.1 1.9L12 17l-1.9-5.1L5 10l5.1-1.9L12 3z"/><path d="m19 15 .8 2.2 2.2.8-2.2.8L19 21l-.8-2.2-2.2-.8 2.2-.8z"/>';
209
+ readonly broom: '<path d="M10 10V4a2 2 0 0 1 4 0v6"/><path d="M6 10h12a2 2 0 0 1 2 2v2H4v-2a2 2 0 0 1 2-2Z"/><path d="m5 14-2 7h18l-2-7M9 18l-1 3M15 18l1 3"/>';
210
+ readonly panel: '<rect x="3" y="4" width="18" height="16" rx="2"/><path d="M14 4v16"/>';
211
+ readonly menu: '<path d="M4 7h16M4 12h16M4 17h16"/>';
212
+ readonly plus: '<path d="M12 5v14M5 12h14"/>';
213
+ readonly star: '<path d="m12 3 2.9 5.9 6.5.9-4.7 4.6 1.1 6.5L12 17.8 6.2 20.9l1.1-6.5L2.6 9.8l6.5-.9L12 3z"/>';
214
+ readonly trash: '<path d="M3 6h18M8 6V4a1 1 0 0 1 1-1h6a1 1 0 0 1 1 1v2M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"/>';
215
+ };
216
+ export type IconName = keyof typeof ICON_PATHS;
217
+ /** The tab icon: a monitor in Cloudflare orange. */
218
+ export declare const FAVICON_DATA_URI = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23f38020' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='2' y='3' width='20' height='14' rx='2'/%3E%3Cpath d='M8 21h8M12 17v4'/%3E%3C/svg%3E";
219
+ /**
220
+ * Control frames the browser and the gateway exchange on the WebSocket that
221
+ * carries a remote-desktop stream.
222
+ *
223
+ * They are plain strings precisely so they can never be confused with the
224
+ * binary protocol payload flowing in either direction, and both sides import
225
+ * these same literals so the two halves cannot drift apart.
226
+ */
227
+ /** Browser -> gateway: "my WebSocket is open, you may start reading the host". */
228
+ export declare const GATEWAY_READY_SIGNAL = "VNC_GATEWAY_READY_v1";
229
+ /**
230
+ * Browser -> gateway: keep the edge from idling out a silent session.
231
+ * Cloudflare closes a WebSocket with no traffic in either direction for 100s,
232
+ * and an untouched desktop transmits nothing at all.
233
+ */
234
+ export declare const GATEWAY_KEEPALIVE_SIGNAL = "VNC_GATEWAY_KEEPALIVE_v1";
235
+ /**
236
+ * How often the browser nudges the transport. Well inside the edge's 100s
237
+ * window, so a session that is merely being looked at is never torn down
238
+ * without a close frame -- which is what a bare WebSocket 1006 used to mean.
239
+ */
240
+ export declare const KEEPALIVE_INTERVAL_MS = 25000;
241
+ export declare const MAX_CLOSE_REASON_BYTES = 123;
242
+ /** Whether a live desktop ended for a transient transport reason worth retrying. */
243
+ export declare function isRetryableDisconnect(diagnostic: {
244
+ close: {
245
+ code: number;
246
+ reason: string;
247
+ } | null;
248
+ established: boolean;
249
+ }): boolean;
250
+ /** WebSocket close reasons are capped at 123 bytes; trim without splitting a code point. */
251
+ export declare function websocketCloseReason(reason: string): string;
252
+ /** 1005/1006/1015 are reserved and cannot be transmitted in a close frame. */
253
+ export declare function sendableCloseCode(code: number): number;
254
+ /** Normalize any WebSocket message payload to bytes. */
255
+ export declare function messageToBytes(data: unknown): Promise<Uint8Array | null>;
@@ -0,0 +1,349 @@
1
+ /**
2
+ * The vocabulary both halves of the gateway share.
3
+ *
4
+ * The Worker and the browser have to agree on what a "protocol" is, what ports
5
+ * they default to and how an RDP security layer is named, so those live here
6
+ * rather than being re-declared on each side and drifting apart.
7
+ */
8
+ /** A remote-desktop protocol the session workspace can display. */
9
+ declare const REMOTE_PROTOCOLS: readonly ['vnc', 'rdp'];
10
+ type RemoteProtocol = (typeof REMOTE_PROTOCOLS)[number];
11
+ /** Every protocol the gateway relays, including the terminal side panel. */
12
+ declare const TRANSPORT_PROTOCOLS: readonly ['vnc', 'rdp', 'ssh'];
13
+ type TransportProtocol = (typeof TRANSPORT_PROTOCOLS)[number];
14
+ /**
15
+ * The RDP security layer. `auto` negotiates with the host, which is right for
16
+ * anything that answers honestly; the rest are for hosts that do not.
17
+ */
18
+ declare const RDP_SECURITY_MODES: readonly ['auto', 'nla', 'tls', 'rdp'];
19
+ type RdpSecurity = (typeof RDP_SECURITY_MODES)[number];
20
+ declare const DEFAULT_PORTS: Record<TransportProtocol, number>;
21
+ declare const DEFAULT_SSH_PORT: number;
22
+ /**
23
+ * How patient `runCommand` is, in three different senses.
24
+ *
25
+ * A single deadline cannot tell "the shell ignored me" apart from "the
26
+ * installer is three minutes into a download", and a short one turns every
27
+ * real piece of work -- a package install, a build, a large copy -- into a
28
+ * false failure that also leaves the command running on the far side.
29
+ *
30
+ * So the wait is judged by what the shell is doing. It has START_MS to
31
+ * acknowledge the command at all; after that it may take as long as it likes
32
+ * as long as it keeps printing, and only silence longer than IDLE_MS, or a run
33
+ * longer than MAX_MS, is treated as stuck.
34
+ */
35
+ export declare const COMMAND_START_MS = 20000;
36
+ /** Max idle silence allowed during command execution. */
37
+ export declare const COMMAND_IDLE_MS: number;
38
+ declare function isRemoteProtocol(value: unknown): value is RemoteProtocol;
39
+ declare function isRdpSecurity(value: unknown): value is RdpSecurity;
40
+ /** Coerce anything to a protocol, falling back to what the caller opens on. */
41
+ declare function toRemoteProtocol(value: unknown, fallback?: RemoteProtocol): RemoteProtocol;
42
+ declare function toRdpSecurity(value: unknown, fallback?: RdpSecurity): RdpSecurity;
43
+ /** A port number, or the protocol's default when the value is not one. */
44
+ declare function toPort(value: unknown, fallback: number): number;
45
+ /** A published Windows application launched instead of the full desktop. */
46
+ interface RemoteAppLaunch {
47
+ /** Alias (`||notepad`) or an executable path. */
48
+ program: string;
49
+ workingDir?: string;
50
+ arguments?: string;
51
+ }
52
+ /** The companion terminal offered beside a desktop. */
53
+ interface SshCompanion {
54
+ enabled: boolean;
55
+ port: number;
56
+ username: string;
57
+ }
58
+ /** Picture and input options. VNC negotiates them; RDP and SSH ignore what does not apply. */
59
+ interface DisplaySettings {
60
+ /** RFB quality level, 1 (smallest) to 9 (sharpest). */
61
+ quality: number;
62
+ /** RFB compression level, 0 (fastest) to 9 (smallest). */
63
+ compression: number;
64
+ /** Fit the remote desktop to the pane rather than scrolling it. */
65
+ scaling: boolean;
66
+ /** Watch without sending keyboard or pointer input. */
67
+ viewOnly: boolean;
68
+ }
69
+ /**
70
+ * Everything a session needs. `password` is the only field never persisted
71
+ * anywhere -- not in the device library on the gateway, not in localStorage.
72
+ */
73
+ interface ConnectionSettings {
74
+ /** Stable identity: protocol, address, port and program. See {@link connectionId}. */
75
+ id: string;
76
+ label: string;
77
+ protocol: RemoteProtocol;
78
+ host: string;
79
+ port: number;
80
+ username: string;
81
+ password: string;
82
+ /** Windows domain or computer name. RDP only. */
83
+ domain: string;
84
+ security: RdpSecurity;
85
+ remoteApp: RemoteAppLaunch | null;
86
+ display: DisplaySettings;
87
+ ssh: SshCompanion;
88
+ /** Open the terminal panel as soon as the desktop appears. */
89
+ openSshOnConnect: boolean;
90
+ }
91
+ declare const DEFAULT_DISPLAY_SETTINGS: DisplaySettings;
92
+ /**
93
+ * A connection's identity is what it points at, not when it was made. Editing
94
+ * the address therefore makes a different connection rather than silently
95
+ * repointing an existing card, which is the behaviour people expect from a
96
+ * list of machines.
97
+ */
98
+ declare function connectionId(input: Pick<ConnectionSettings, 'protocol' | 'host' | 'port'> & {
99
+ remoteApp?: RemoteAppLaunch | null;
100
+ }): string;
101
+ /** A blank connection, ready for the dialog to fill in. */
102
+ declare function emptyConnection(protocol?: RemoteProtocol): ConnectionSettings;
103
+ declare function normalizeDisplaySettings(value: unknown): DisplaySettings;
104
+ /**
105
+ * Build a complete, valid connection out of whatever a caller happens to have.
106
+ * Partial input from a saved card, a host list entry, a URL or localStorage all
107
+ * arrive here, so the dialog never has to reason about missing fields.
108
+ */
109
+ declare function normalizeConnection(input: Partial<ConnectionSettings> & Record<string, unknown>): ConnectionSettings;
110
+ /** What a connection is worth remembering by -- never the password. */
111
+ type PersistedConnection = Omit<ConnectionSettings, 'password'>;
112
+ declare function withoutPassword(settings: ConnectionSettings): PersistedConnection;
113
+ /** A one-line description for the dialog's summary row and the status bar. */
114
+ declare function describeConnection(settings: ConnectionSettings): string;
115
+ /** Where the pointer may go, in framebuffer pixels. */
116
+ export interface ScreenGeometry {
117
+ width: number;
118
+ height: number;
119
+ viewport: {
120
+ x: number;
121
+ y: number;
122
+ width: number;
123
+ height: number;
124
+ };
125
+ }
126
+ /** Mouse buttons, as the UI names them. */
127
+ type PointerButton = 0 | 1 | 2;
128
+ /** Wheel movement in discrete remote-protocol notches. Positive is right/down. */
129
+ interface ScrollDelta {
130
+ x: number;
131
+ y: number;
132
+ }
133
+ /**
134
+ * A live session. Both drivers expose this, so the AI pane's screen tool and
135
+ * the toolbar never have to ask which protocol they are driving.
136
+ */
137
+ export interface RemoteSession extends EventTarget {
138
+ readonly protocol: RemoteProtocol;
139
+ disconnect(): void;
140
+ /** True once the desktop has been reached. */
141
+ readonly connected: boolean;
142
+ /** Fit the remote desktop to the pane rather than scrolling it. */
143
+ scaleViewport: boolean;
144
+ /** Watch without sending keyboard or pointer input. */
145
+ viewOnly: boolean;
146
+ /** RFB quality level. RDP ignores it. */
147
+ qualityLevel?: number;
148
+ /** RFB compression level. RDP ignores it. */
149
+ compressionLevel?: number;
150
+ /** The transport the metrics rail instruments. Can appear a tick after construction. */
151
+ readonly socket?: WebSocket | null;
152
+ readonly screenGeometry: ScreenGeometry;
153
+ movePointer(x: number, y: number): boolean;
154
+ clickPointer(x: number, y: number, button?: PointerButton): boolean;
155
+ pointerButton(x: number, y: number, button?: PointerButton, pressed?: boolean): boolean;
156
+ scrollPointer(x: number, y: number, delta: ScrollDelta): boolean;
157
+ typeText(text: string): boolean;
158
+ /** Prefer the protocol clipboard for longer text when it can paste reliably. */
159
+ pasteText?(text: string): boolean | Promise<boolean>;
160
+ /** Press or release one key by keysym. */
161
+ sendKey(keysym: number, code: string | null, down?: boolean): void;
162
+ /** Send text to the host's clipboard, when the protocol carries one. */
163
+ sendClipboard?(text: string): void;
164
+ /**
165
+ * Stop taking keystrokes: the workspace has given the keyboard to something
166
+ * local, such as the terminal or the assistant's message box.
167
+ *
168
+ * Both protocols listen on the element they paint into, so a key only leaves
169
+ * for the host while that element holds focus. Handing focus back is the
170
+ * whole mechanism -- plus, for RDP, letting go of anything still held down,
171
+ * which would otherwise stay down on the far side.
172
+ */
173
+ releaseKeyboard?(): void;
174
+ /** Ask the host for a different desktop size, when the protocol allows it. */
175
+ requestDesktopSize?(width: number, height: number): void;
176
+ /** The canvas the session paints into, for screenshots and thumbnails. */
177
+ readonly canvas?: HTMLCanvasElement | null;
178
+ }
179
+ /** What the workspace hands a driver to open a session. */
180
+ export interface SessionOptions {
181
+ credentials: {
182
+ username: string;
183
+ password: string;
184
+ };
185
+ domain: string;
186
+ security: RdpSecurity;
187
+ remoteApp: RemoteAppLaunch | null;
188
+ /** Desktop size to ask the host for. */
189
+ width: number;
190
+ height: number;
191
+ /** False on a phone, where resizing the host would make a portrait strip of it. */
192
+ allowRemoteResize: boolean;
193
+ scaleViewport: boolean;
194
+ viewOnly: boolean;
195
+ quality: number;
196
+ compression: number;
197
+ /** Shown in this driver's own log lines. */
198
+ hostLabel: string;
199
+ }
200
+ /** Wording for the one connect dialog, which is shared markup across protocols. */
201
+ interface DialogCopy {
202
+ usernameLabel: string;
203
+ usernamePlaceholder: string;
204
+ usernameHelp: string;
205
+ passwordLabel: string;
206
+ passwordPlaceholder: string;
207
+ passwordHelp: string;
208
+ /** A VNC session needs some secret; RDP can sign in on the host's own screen. */
209
+ requiresPassword: boolean;
210
+ }
211
+ /** Everything the UI knows about a close, before anyone tries to explain it. */
212
+ interface DisconnectContext {
213
+ code?: number;
214
+ reason: string;
215
+ /** Pre-rendered ` (WebSocket 1006: ...)` tail, so wording stays consistent. */
216
+ suffix: string;
217
+ }
218
+ /** One protocol implementation. */
219
+ export interface ProtocolDriver {
220
+ readonly protocol: RemoteProtocol;
221
+ /** Used as the prefix of this driver's console lines. */
222
+ readonly label: string;
223
+ readonly defaultPort: number;
224
+ readonly dialog: DialogCopy;
225
+ /** The gateway endpoint for this connection, including any query it needs. */
226
+ buildUrl(origin: string, settings: ConnectionSettings): string;
227
+ createSession(container: HTMLElement, url: string, options: SessionOptions): RemoteSession;
228
+ /** Extra detail worth logging once the first server frame has been parsed. */
229
+ describeState(session: RemoteSession): Record<string, unknown>;
230
+ /** Protocol-specific wording for a close, or null to fall back to the shared text. */
231
+ describeDisconnect(context: DisconnectContext): string | null;
232
+ }
233
+ export declare const DEFAULT_PORT = 22;
234
+ export declare const COMMAND_MAX_MS: number;
235
+ /**
236
+ * The one line that runs `command` and marks where its output starts and ends.
237
+ *
238
+ * Each shell gets its own, because none of the three agree on how to print a
239
+ * string, run a command and read back its exit status.
240
+ */
241
+ export declare function frameCommand(family: any, command: string, id: any): string;
242
+ export declare class SshSession extends EventTarget {
243
+ #private;
244
+ /**
245
+ * @param {string} url gateway WebSocket URL
246
+ * @param {object} options
247
+ * @param {string} options.username
248
+ * @param {string} [options.password]
249
+ * @param {SshIdentity[] | (() => Promise<SshIdentity[]>)} [options.identities]
250
+ * @param {'powershell'} [options.preferredShell]
251
+ * @param {(info: object) => Promise<boolean>} [options.verifyHost]
252
+ * @param {(prompt: object) => Promise<string>} [options.requestInput]
253
+ */
254
+ constructor(url: string, options?: {});
255
+ connect(): void;
256
+ disconnect(): void;
257
+ /** Send keystrokes, or anything else the terminal produces, to the shell. */
258
+ write(data: Uint8Array): void;
259
+ /**
260
+ * Run one command in this shell and return what it printed.
261
+ *
262
+ * Deliberately the *same* shell the user is looking at, not a second channel:
263
+ * a command the assistant runs inherits the working directory, the
264
+ * environment and the login the user already has, and it appears in their
265
+ * terminal as it happens. An agent acting on a machine invisibly is worse
266
+ * than an agent that is slower to read.
267
+ *
268
+ * The output is framed by markers rather than measured, because an
269
+ * interactive shell echoes its input and prints a prompt around it. The
270
+ * markers are assembled by the shell from two pieces, so the echoed command
271
+ * line -- which contains the pieces but not the joined marker -- never looks
272
+ * like the real boundary.
273
+ *
274
+ * A `command` event brackets the run so the terminal can label it, and the
275
+ * three deadlines above decide when a command is stuck rather than slow.
276
+ */
277
+ runCommand(command: string, { startMs, idleMs, maxMs, }?: {
278
+ idleMs?: number;
279
+ maxMs?: number;
280
+ startMs?: number;
281
+ }): Promise<unknown>;
282
+ /** Tell the shell its window changed, so full-screen programs redraw. */
283
+ resize(columns: number, rows: number): void;
284
+ }
285
+ export declare class SshTerminal {
286
+ constructor(container: any);
287
+ get columns(): any;
288
+ get rows(): any;
289
+ onData(handler: any): void;
290
+ onResize(handler: any): void;
291
+ write(data: Uint8Array): void;
292
+ /** Gateway-side notices, kept visually apart from what the host prints. */
293
+ notice(text: string, tone?: string): void;
294
+ clear(): void;
295
+ focus(): void;
296
+ /**
297
+ * Size the terminal to the panel, choosing the font so MIN_COLUMNS fit.
298
+ *
299
+ * The columns matter more than the type size here: the commands people run in
300
+ * a side panel -- `ls -l`, `top`, anything in PowerShell that prints a table
301
+ * -- are laid out for 80 columns, and a narrower grid wraps every row into an
302
+ * unreadable stack.
303
+ *
304
+ * `proposeDimensions()` reports the grid the current font size yields, and a
305
+ * monospace cell's width scales with its font size, so `fontSize * cols /
306
+ * MIN_COLUMNS` lands close to the size that gives MIN_COLUMNS. It is measured
307
+ * rather than assumed because the cell-width-to-font-size ratio belongs to
308
+ * whichever font the platform picked. A second pass settles the rounding.
309
+ * Changing the font resizes the element, which the ResizeObserver sees, so
310
+ * the guard keeps that from recursing.
311
+ */
312
+ fit(): void;
313
+ /** The grid the host is being told about, for a status line or a log. */
314
+ get geometry(): {
315
+ columns: any;
316
+ rows: any;
317
+ fontSize: any;
318
+ };
319
+ get selection(): any;
320
+ /**
321
+ * Read one line from the user, for a password or a one-time code the host
322
+ * asked for during authentication. The shell is not open yet, so the
323
+ * terminal is free to be a prompt.
324
+ */
325
+ readLine({ prompt, echo }?: {
326
+ echo?: boolean;
327
+ prompt?: string;
328
+ }): Promise<unknown>;
329
+ destroy(): void;
330
+ }
331
+ export declare const DRIVERS: Record<RemoteProtocol, ProtocolDriver>;
332
+ /** Unknown names fall back to VNC, which is what the dialog opens on. */
333
+ export declare function driverFor(protocol: string | undefined): ProtocolDriver;
334
+ /** What the workspace knows about a session that has just ended. */
335
+ export interface DisconnectDiagnostic {
336
+ protocol: RemoteProtocol;
337
+ /** The transport close, when one arrived. A 1006 means it did not. */
338
+ close: {
339
+ code: number;
340
+ reason: string;
341
+ } | null;
342
+ /** True once the session had reached the desktop. */
343
+ established: boolean;
344
+ }
345
+ /**
346
+ * Explain a disconnect in terms someone can act on. The protocol gets first
347
+ * say, then the close codes that mean the same thing either way.
348
+ */
349
+ export declare function explainDisconnect(diagnostic: DisconnectDiagnostic, clean: boolean, protocolMessage: string): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-remote",
3
- "version": "0.4.8",
3
+ "version": "0.4.9",
4
4
  "description": "RDP, VNC and SSH protocol engines that run in Node, a Worker or a browser -- plus `npx ai-remote`, a CLI that drives a machine and shows you what it is doing",
5
5
  "type": "module",
6
6
  "bin": {
@@ -54,12 +54,12 @@
54
54
  "default": "./dist/apple-dh.js"
55
55
  },
56
56
  "./protocols": {
57
- "types": "./dist/protocols/index.d.ts",
57
+ "types": "./dist/protocols.d.ts",
58
58
  "import": "./dist/protocols.js",
59
59
  "default": "./dist/protocols.js"
60
60
  },
61
61
  "./protocols/*": {
62
- "types": "./dist/protocols/index.d.ts",
62
+ "types": "./dist/protocols.d.ts",
63
63
  "import": "./dist/protocols.js",
64
64
  "default": "./dist/protocols.js"
65
65
  }
@@ -1,33 +0,0 @@
1
- /**
2
- * The protocol registry the workspace talks to.
3
- *
4
- * The UI owns the toolbar, the dialogs, the stats rail and the on-screen
5
- * keyboard, none of which care whether a session is VNC or RDP. Everything that
6
- * does differ -- the endpoint, how a client is constructed, the wording of a
7
- * failure, the labels in the connect dialog -- is looked up here instead of
8
- * branching at each site.
9
- */
10
- import type { ProtocolDriver } from './types';
11
- import type { RemoteProtocol } from '../shared/protocol';
12
- export type { ProtocolDriver, RemoteSession, SessionOptions, ScreenGeometry } from './types';
13
- export * from './ssh/session';
14
- export * from './ssh/terminal';
15
- export declare const DRIVERS: Record<RemoteProtocol, ProtocolDriver>;
16
- /** Unknown names fall back to VNC, which is what the dialog opens on. */
17
- export declare function driverFor(protocol: string | undefined): ProtocolDriver;
18
- /** What the workspace knows about a session that has just ended. */
19
- export interface DisconnectDiagnostic {
20
- protocol: RemoteProtocol;
21
- /** The transport close, when one arrived. A 1006 means it did not. */
22
- close: {
23
- code: number;
24
- reason: string;
25
- } | null;
26
- /** True once the session had reached the desktop. */
27
- established: boolean;
28
- }
29
- /**
30
- * Explain a disconnect in terms someone can act on. The protocol gets first
31
- * say, then the close codes that mean the same thing either way.
32
- */
33
- export declare function explainDisconnect(diagnostic: DisconnectDiagnostic, clean: boolean, protocolMessage: string): string;