ai-remote 0.4.2 → 0.4.4

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 (75) hide show
  1. package/dist/index.js +1 -6
  2. package/dist/{protocols/index.d.ts → protocols.d.ts} +2 -0
  3. package/dist/protocols.js +24 -0
  4. package/package.json +15 -10
  5. package/dist/protocols/index.js +0 -34
  6. package/dist/protocols/rdp/buffer.d.ts +0 -38
  7. package/dist/protocols/rdp/buffer.js +0 -169
  8. package/dist/protocols/rdp/caps.d.ts +0 -49
  9. package/dist/protocols/rdp/caps.js +0 -259
  10. package/dist/protocols/rdp/cert.d.ts +0 -18
  11. package/dist/protocols/rdp/cert.js +0 -134
  12. package/dist/protocols/rdp/client.d.ts +0 -56
  13. package/dist/protocols/rdp/client.js +0 -1069
  14. package/dist/protocols/rdp/cliprdr.d.ts +0 -27
  15. package/dist/protocols/rdp/cliprdr.js +0 -239
  16. package/dist/protocols/rdp/credssp.d.ts +0 -34
  17. package/dist/protocols/rdp/credssp.js +0 -253
  18. package/dist/protocols/rdp/crypto.d.ts +0 -63
  19. package/dist/protocols/rdp/crypto.js +0 -368
  20. package/dist/protocols/rdp/display.d.ts +0 -38
  21. package/dist/protocols/rdp/display.js +0 -588
  22. package/dist/protocols/rdp/gcc.d.ts +0 -23
  23. package/dist/protocols/rdp/gcc.js +0 -131
  24. package/dist/protocols/rdp/keymap.d.ts +0 -9
  25. package/dist/protocols/rdp/keymap.js +0 -131
  26. package/dist/protocols/rdp/mcs.d.ts +0 -40
  27. package/dist/protocols/rdp/mcs.js +0 -222
  28. package/dist/protocols/rdp/ntlm.d.ts +0 -61
  29. package/dist/protocols/rdp/ntlm.js +0 -304
  30. package/dist/protocols/rdp/pdu.d.ts +0 -155
  31. package/dist/protocols/rdp/pdu.js +0 -443
  32. package/dist/protocols/rdp/rail.d.ts +0 -119
  33. package/dist/protocols/rdp/rail.js +0 -382
  34. package/dist/protocols/rdp/rle.d.ts +0 -13
  35. package/dist/protocols/rdp/rle.js +0 -275
  36. package/dist/protocols/rdp/sec.d.ts +0 -59
  37. package/dist/protocols/rdp/sec.js +0 -155
  38. package/dist/protocols/rdp/session.d.ts +0 -62
  39. package/dist/protocols/rdp/session.js +0 -306
  40. package/dist/protocols/rdp/tls.d.ts +0 -18
  41. package/dist/protocols/rdp/tls.js +0 -353
  42. package/dist/protocols/rdp/vchannel.d.ts +0 -28
  43. package/dist/protocols/rdp/vchannel.js +0 -58
  44. package/dist/protocols/rdp/x224.d.ts +0 -40
  45. package/dist/protocols/rdp/x224.js +0 -109
  46. package/dist/protocols/ssh/kex.d.ts +0 -97
  47. package/dist/protocols/ssh/kex.js +0 -176
  48. package/dist/protocols/ssh/messages.d.ts +0 -50
  49. package/dist/protocols/ssh/messages.js +0 -54
  50. package/dist/protocols/ssh/session.d.ts +0 -66
  51. package/dist/protocols/ssh/session.js +0 -608
  52. package/dist/protocols/ssh/terminal.d.ts +0 -46
  53. package/dist/protocols/ssh/terminal.js +0 -190
  54. package/dist/protocols/ssh/transport.d.ts +0 -62
  55. package/dist/protocols/ssh/transport.js +0 -612
  56. package/dist/protocols/ssh/wire.d.ts +0 -52
  57. package/dist/protocols/ssh/wire.js +0 -188
  58. package/dist/protocols/types.d.ts +0 -127
  59. package/dist/protocols/types.js +0 -0
  60. package/dist/protocols/vnc/input.d.ts +0 -5
  61. package/dist/protocols/vnc/input.js +0 -15
  62. package/dist/protocols/vnc/session.d.ts +0 -12
  63. package/dist/protocols/vnc/session.js +0 -258
  64. package/dist/shared/connection.d.ts +0 -81
  65. package/dist/shared/connection.js +0 -113
  66. package/dist/shared/device.d.ts +0 -26
  67. package/dist/shared/device.js +0 -0
  68. package/dist/shared/hosts.d.ts +0 -63
  69. package/dist/shared/hosts.js +0 -132
  70. package/dist/shared/icons.d.ts +0 -46
  71. package/dist/shared/icons.js +0 -41
  72. package/dist/shared/protocol.d.ts +0 -28
  73. package/dist/shared/protocol.js +0 -39
  74. package/dist/shared/signals.d.ts +0 -37
  75. package/dist/shared/signals.js +0 -41
@@ -1,176 +0,0 @@
1
- import { SshReader, SshWriter, concatBytes, padStart, toBase64, toBase64Url } from "./wire.js";
2
- const subtle = globalThis.crypto?.subtle;
3
- const KEX_ALGORITHMS = {
4
- "curve25519-sha256": { type: "x25519", hash: "SHA-256" },
5
- "curve25519-sha256@libssh.org": { type: "x25519", hash: "SHA-256" },
6
- "ecdh-sha2-nistp256": { type: "ecdh", curve: "P-256", hash: "SHA-256" }
7
- };
8
- const HOST_KEY_ALGORITHMS = {
9
- "ssh-ed25519": { keyType: "ssh-ed25519", kind: "ed25519" },
10
- "rsa-sha2-512": { keyType: "ssh-rsa", kind: "rsa", hash: "SHA-512" },
11
- "rsa-sha2-256": { keyType: "ssh-rsa", kind: "rsa", hash: "SHA-256" },
12
- "ecdsa-sha2-nistp256": { keyType: "ecdsa-sha2-nistp256", kind: "ecdsa", curve: "P-256", hash: "SHA-256" }
13
- };
14
- async function supports(algorithm, usages) {
15
- if (!subtle) return false;
16
- try {
17
- await subtle.generateKey(algorithm, false, usages);
18
- return true;
19
- } catch {
20
- return false;
21
- }
22
- }
23
- let cachedOffer = null;
24
- async function negotiableAlgorithms() {
25
- if (cachedOffer) return cachedOffer;
26
- const [x25519, ed25519] = await Promise.all([
27
- supports({ name: "X25519" }, ["deriveBits"]),
28
- supports({ name: "Ed25519" }, ["sign", "verify"])
29
- ]);
30
- const kex = [];
31
- if (x25519) kex.push("curve25519-sha256", "curve25519-sha256@libssh.org");
32
- kex.push("ecdh-sha2-nistp256");
33
- const hostKey = [];
34
- if (ed25519) hostKey.push("ssh-ed25519");
35
- hostKey.push("rsa-sha2-512", "rsa-sha2-256", "ecdsa-sha2-nistp256");
36
- cachedOffer = { kex, hostKey, x25519, ed25519 };
37
- return cachedOffer;
38
- }
39
- async function createKexClient(algorithmName) {
40
- const algorithm = KEX_ALGORITHMS[algorithmName];
41
- if (!algorithm) throw new Error(`SSH: unsupported key exchange ${algorithmName}`);
42
- if (algorithm.type === "x25519") {
43
- const pair2 = await subtle.generateKey({ name: "X25519" }, false, ["deriveBits"]);
44
- const publicKey2 = new Uint8Array(await subtle.exportKey("raw", pair2.publicKey));
45
- return {
46
- hash: algorithm.hash,
47
- publicKey: publicKey2,
48
- async sharedSecret(serverPublicKey) {
49
- if (serverPublicKey.length !== 32) throw new Error("SSH: the host sent a malformed X25519 key.");
50
- const peer = await subtle.importKey("raw", serverPublicKey, { name: "X25519" }, false, []);
51
- const secret = new Uint8Array(await subtle.deriveBits({ name: "X25519", public: peer }, pair2.privateKey, 256));
52
- if (secret.every((byte) => byte === 0)) {
53
- throw new Error("SSH: the host sent a degenerate X25519 key.");
54
- }
55
- return secret;
56
- }
57
- };
58
- }
59
- const pair = await subtle.generateKey({ name: "ECDH", namedCurve: algorithm.curve }, false, ["deriveBits"]);
60
- const publicKey = new Uint8Array(await subtle.exportKey("raw", pair.publicKey));
61
- return {
62
- hash: algorithm.hash,
63
- publicKey,
64
- async sharedSecret(serverPublicKey) {
65
- const peer = await subtle.importKey(
66
- "raw",
67
- serverPublicKey,
68
- { name: "ECDH", namedCurve: algorithm.curve },
69
- false,
70
- []
71
- );
72
- return new Uint8Array(await subtle.deriveBits({ name: "ECDH", public: peer }, pair.privateKey, 256));
73
- }
74
- };
75
- }
76
- function hostKeyType(keyBlob) {
77
- return new SshReader(keyBlob).string();
78
- }
79
- async function hostKeyFingerprint(keyBlob) {
80
- const digest = new Uint8Array(await subtle.digest("SHA-256", keyBlob));
81
- return `SHA256:${toBase64(digest).replace(/=+$/, "")}`;
82
- }
83
- async function importHostKey(algorithmName, keyBlob) {
84
- const algorithm = HOST_KEY_ALGORITHMS[algorithmName];
85
- if (!algorithm) throw new Error(`SSH: unsupported host key algorithm ${algorithmName}`);
86
- const reader = new SshReader(keyBlob);
87
- const keyType = reader.string();
88
- if (keyType !== algorithm.keyType) {
89
- throw new Error(`SSH: the host key is a ${keyType} but was announced as ${algorithmName}.`);
90
- }
91
- if (algorithm.kind === "ed25519") {
92
- return subtle.importKey("raw", reader.stringBytes(), { name: "Ed25519" }, false, ["verify"]);
93
- }
94
- if (algorithm.kind === "rsa") {
95
- const exponent = reader.mpint();
96
- const modulus = reader.mpint();
97
- return subtle.importKey(
98
- "jwk",
99
- { kty: "RSA", n: toBase64Url(modulus), e: toBase64Url(exponent), ext: true },
100
- { name: "RSASSA-PKCS1-v1_5", hash: algorithm.hash },
101
- false,
102
- ["verify"]
103
- );
104
- }
105
- reader.string();
106
- return subtle.importKey(
107
- "raw",
108
- reader.stringBytes(),
109
- { name: "ECDSA", namedCurve: algorithm.curve },
110
- false,
111
- ["verify"]
112
- );
113
- }
114
- function signatureBytes(algorithmName, signatureBlob) {
115
- const reader = new SshReader(signatureBlob);
116
- const named = reader.string();
117
- if (named !== algorithmName) {
118
- throw new Error(`SSH: the host signed with ${named} after agreeing on ${algorithmName}.`);
119
- }
120
- const raw = reader.stringBytes();
121
- if (HOST_KEY_ALGORITHMS[algorithmName]?.kind !== "ecdsa") return raw;
122
- const parts = new SshReader(raw);
123
- const r = parts.mpint();
124
- const s = parts.mpint();
125
- return concatBytes(padStart(r, 32), padStart(s, 32));
126
- }
127
- async function verifyHostKeySignature({ algorithm, keyBlob, signatureBlob, exchangeHash: exchangeHash2 }) {
128
- const { kind, hash } = HOST_KEY_ALGORITHMS[algorithm];
129
- const key = await importHostKey(algorithm, keyBlob);
130
- const signature = signatureBytes(algorithm, signatureBlob);
131
- const parameters = kind === "ecdsa" ? { name: "ECDSA", hash } : kind === "rsa" ? { name: "RSASSA-PKCS1-v1_5" } : { name: "Ed25519" };
132
- return subtle.verify(parameters, key, signature, exchangeHash2);
133
- }
134
- async function exchangeHash({
135
- hash,
136
- clientVersion,
137
- serverVersion,
138
- clientKexInit,
139
- serverKexInit,
140
- hostKeyBlob,
141
- clientPublicKey,
142
- serverPublicKey,
143
- sharedSecret
144
- }) {
145
- const writer = new SshWriter(1024);
146
- writer.string(clientVersion);
147
- writer.string(serverVersion);
148
- writer.string(clientKexInit);
149
- writer.string(serverKexInit);
150
- writer.string(hostKeyBlob);
151
- writer.string(clientPublicKey);
152
- writer.string(serverPublicKey);
153
- writer.mpint(sharedSecret);
154
- return new Uint8Array(await subtle.digest(hash, writer.take()));
155
- }
156
- async function deriveKey({ hash, sharedSecret, exchangeHash: h, letter, sessionId, length }) {
157
- const prefix = new SshWriter(64 + h.length).mpint(sharedSecret).take();
158
- const seed = concatBytes(prefix, h, new Uint8Array([letter.charCodeAt(0)]), sessionId);
159
- let material = new Uint8Array(await subtle.digest(hash, seed));
160
- while (material.length < length) {
161
- const extension = new Uint8Array(await subtle.digest(hash, concatBytes(prefix, h, material)));
162
- material = concatBytes(material, extension);
163
- }
164
- return material.subarray(0, length);
165
- }
166
- export {
167
- HOST_KEY_ALGORITHMS,
168
- KEX_ALGORITHMS,
169
- createKexClient,
170
- deriveKey,
171
- exchangeHash,
172
- hostKeyFingerprint,
173
- hostKeyType,
174
- negotiableAlgorithms,
175
- verifyHostKeySignature
176
- };
@@ -1,50 +0,0 @@
1
- export declare const MSG: {
2
- DISCONNECT: number;
3
- IGNORE: number;
4
- UNIMPLEMENTED: number;
5
- DEBUG: number;
6
- SERVICE_REQUEST: number;
7
- SERVICE_ACCEPT: number;
8
- EXT_INFO: number;
9
- KEXINIT: number;
10
- NEWKEYS: number;
11
- KEX_ECDH_INIT: number;
12
- KEX_ECDH_REPLY: number;
13
- USERAUTH_REQUEST: number;
14
- USERAUTH_FAILURE: number;
15
- USERAUTH_SUCCESS: number;
16
- USERAUTH_BANNER: number;
17
- USERAUTH_INFO_REQUEST: number;
18
- USERAUTH_INFO_RESPONSE: number;
19
- GLOBAL_REQUEST: number;
20
- REQUEST_SUCCESS: number;
21
- REQUEST_FAILURE: number;
22
- CHANNEL_OPEN: number;
23
- CHANNEL_OPEN_CONFIRMATION: number;
24
- CHANNEL_OPEN_FAILURE: number;
25
- CHANNEL_WINDOW_ADJUST: number;
26
- CHANNEL_DATA: number;
27
- CHANNEL_EXTENDED_DATA: number;
28
- CHANNEL_EOF: number;
29
- CHANNEL_CLOSE: number;
30
- CHANNEL_REQUEST: number;
31
- CHANNEL_SUCCESS: number;
32
- CHANNEL_FAILURE: number;
33
- };
34
- /** SSH_EXTENDED_DATA_STDERR. */
35
- export declare const EXTENDED_DATA_STDERR = 1;
36
- export declare const DISCONNECT_REASON: {
37
- 1: string;
38
- 2: string;
39
- 3: string;
40
- 5: string;
41
- 6: string;
42
- 7: string;
43
- 8: string;
44
- 9: string;
45
- 10: string;
46
- 11: string;
47
- 12: string;
48
- 14: string;
49
- 15: string;
50
- };
@@ -1,54 +0,0 @@
1
- const MSG = {
2
- DISCONNECT: 1,
3
- IGNORE: 2,
4
- UNIMPLEMENTED: 3,
5
- DEBUG: 4,
6
- SERVICE_REQUEST: 5,
7
- SERVICE_ACCEPT: 6,
8
- EXT_INFO: 7,
9
- KEXINIT: 20,
10
- NEWKEYS: 21,
11
- KEX_ECDH_INIT: 30,
12
- KEX_ECDH_REPLY: 31,
13
- USERAUTH_REQUEST: 50,
14
- USERAUTH_FAILURE: 51,
15
- USERAUTH_SUCCESS: 52,
16
- USERAUTH_BANNER: 53,
17
- USERAUTH_INFO_REQUEST: 60,
18
- USERAUTH_INFO_RESPONSE: 61,
19
- GLOBAL_REQUEST: 80,
20
- REQUEST_SUCCESS: 81,
21
- REQUEST_FAILURE: 82,
22
- CHANNEL_OPEN: 90,
23
- CHANNEL_OPEN_CONFIRMATION: 91,
24
- CHANNEL_OPEN_FAILURE: 92,
25
- CHANNEL_WINDOW_ADJUST: 93,
26
- CHANNEL_DATA: 94,
27
- CHANNEL_EXTENDED_DATA: 95,
28
- CHANNEL_EOF: 96,
29
- CHANNEL_CLOSE: 97,
30
- CHANNEL_REQUEST: 98,
31
- CHANNEL_SUCCESS: 99,
32
- CHANNEL_FAILURE: 100
33
- };
34
- const EXTENDED_DATA_STDERR = 1;
35
- const DISCONNECT_REASON = {
36
- 1: "the host reported a protocol error",
37
- 2: "the host could not agree on a key exchange method",
38
- 3: "the key exchange failed",
39
- 5: "the host ran out of resources",
40
- 6: "the connection was lost below SSH",
41
- 7: "the host application ended the connection",
42
- 8: "too many connections",
43
- 9: "authentication was cancelled by the user",
44
- 10: "no more authentication methods are available",
45
- 11: "the host closed the connection",
46
- 12: "authentication was cancelled by the host",
47
- 14: "the host refused the authentication attempt",
48
- 15: "the host closed the connection while authenticating"
49
- };
50
- export {
51
- DISCONNECT_REASON,
52
- EXTENDED_DATA_STDERR,
53
- MSG
54
- };
@@ -1,66 +0,0 @@
1
- export declare const DEFAULT_PORT = 22;
2
- /**
3
- * How patient `runCommand` is, in three different senses.
4
- *
5
- * A single deadline cannot tell "the shell ignored me" apart from "the
6
- * installer is three minutes into a download", and a short one turns every
7
- * real piece of work -- a package install, a build, a large copy -- into a
8
- * false failure that also leaves the command running on the far side.
9
- *
10
- * So the wait is judged by what the shell is doing. It has START_MS to
11
- * acknowledge the command at all; after that it may take as long as it likes
12
- * as long as it keeps printing, and only silence longer than IDLE_MS, or a run
13
- * longer than MAX_MS, is treated as stuck.
14
- */
15
- export declare const COMMAND_START_MS = 20000;
16
- export declare const COMMAND_IDLE_MS: number;
17
- export declare const COMMAND_MAX_MS: number;
18
- /**
19
- * The one line that runs `command` and marks where its output starts and ends.
20
- *
21
- * Each shell gets its own, because none of the three agree on how to print a
22
- * string, run a command and read back its exit status.
23
- */
24
- export declare function frameCommand(family: any, command: string, id: any): string;
25
- export declare class SshSession extends EventTarget {
26
- #private;
27
- /**
28
- * @param {string} url gateway WebSocket URL
29
- * @param {object} options
30
- * @param {string} options.username
31
- * @param {string} [options.password]
32
- * @param {'powershell'} [options.preferredShell]
33
- * @param {(info: object) => Promise<boolean>} [options.verifyHost]
34
- * @param {(prompt: object) => Promise<string>} [options.requestInput]
35
- */
36
- constructor(url: string, options?: {});
37
- connect(): void;
38
- disconnect(): void;
39
- /** Send keystrokes, or anything else the terminal produces, to the shell. */
40
- write(data: Uint8Array): void;
41
- /**
42
- * Run one command in this shell and return what it printed.
43
- *
44
- * Deliberately the *same* shell the user is looking at, not a second channel:
45
- * a command the assistant runs inherits the working directory, the
46
- * environment and the login the user already has, and it appears in their
47
- * terminal as it happens. An agent acting on a machine invisibly is worse
48
- * than an agent that is slower to read.
49
- *
50
- * The output is framed by markers rather than measured, because an
51
- * interactive shell echoes its input and prints a prompt around it. The
52
- * markers are assembled by the shell from two pieces, so the echoed command
53
- * line -- which contains the pieces but not the joined marker -- never looks
54
- * like the real boundary.
55
- *
56
- * A `command` event brackets the run so the terminal can label it, and the
57
- * three deadlines above decide when a command is stuck rather than slow.
58
- */
59
- runCommand(command: string, { startMs, idleMs, maxMs, }?: {
60
- idleMs?: number;
61
- maxMs?: number;
62
- startMs?: number;
63
- }): Promise<unknown>;
64
- /** Tell the shell its window changed, so full-screen programs redraw. */
65
- resize(columns: number, rows: number): void;
66
- }