@halonicjs/testing 0.1.1 → 0.1.2
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/dist/adapters/http-kit/src/connector-host-class.d.ts +14 -0
- package/dist/adapters/http-kit/src/connector-host-class.js +34 -0
- package/dist/adapters/http-kit/src/index.d.ts +2 -0
- package/dist/adapters/http-kit/src/index.js +2 -0
- package/dist/adapters/http-kit/src/ollama-tags.d.ts +20 -0
- package/dist/adapters/http-kit/src/ollama-tags.js +38 -0
- package/dist/adapters/integration-kit/src/index.d.ts +2 -1
- package/dist/adapters/integration-kit/src/index.js +1 -0
- package/dist/adapters/integration-kit/src/loader.d.ts +2 -12
- package/dist/adapters/integration-kit/src/loader.js +3 -20
- package/dist/adapters/integration-kit/src/workspace-choices.d.ts +37 -0
- package/dist/adapters/integration-kit/src/workspace-choices.js +37 -0
- package/dist/core/events/src/connector-listing-failed.d.ts +18 -0
- package/dist/core/events/src/connector-listing-failed.js +1 -0
- package/dist/core/events/src/home-path.d.ts +4 -1
- package/dist/core/events/src/home-path.js +14 -3
- package/dist/core/events/src/index.d.ts +4 -2
- package/dist/core/events/src/index.js +2 -0
- package/dist/core/events/src/provider-notes.d.ts +16 -0
- package/dist/core/events/src/provider-notes.js +24 -0
- package/dist/core/events/src/run-basics.d.ts +103 -5
- package/dist/core/events/src/run-event.d.ts +72 -7
- package/dist/core/events/src/run-summary.d.ts +11 -1
- package/dist/core/events/src/sandbox-opened-read.d.ts +2 -1
- package/dist/core/events/src/sandbox-opened-read.js +27 -2
- package/dist/core/events/src/sandbox-opened.d.ts +37 -4
- package/dist/core/events/src/sandbox-opened.js +13 -3
- package/dist/core/events/src/summarize.js +3 -0
- package/dist/core/events/src/tool-failure-cause.d.ts +25 -0
- package/dist/core/events/src/tool-failure-cause.js +66 -0
- package/dist/core/format/src/index.d.ts +3 -2
- package/dist/core/format/src/index.js +3 -1
- package/dist/core/format/src/kinds/agent/harness-limits.d.ts +14 -0
- package/dist/core/format/src/kinds/agent/harness-limits.js +27 -0
- package/dist/core/format/src/kinds/agent/schema.d.ts +5 -0
- package/dist/core/format/src/kinds/agent/schema.js +3 -0
- package/dist/core/format/src/kinds/connector/kind.js +24 -3
- package/dist/core/format/src/kinds/connector/schema.d.ts +14 -0
- package/dist/core/format/src/kinds/connector/schema.js +18 -0
- package/dist/core/format/src/kinds/integration/schema.js +1 -1
- package/dist/core/format/src/kinds/integration/sign-in-checks.d.ts +2 -1
- package/dist/core/format/src/kinds/integration/sign-in-checks.js +33 -3
- package/dist/core/format/src/kinds/plugin/checks.d.ts +3 -2
- package/dist/core/format/src/kinds/plugin/checks.js +17 -5
- package/dist/core/format/src/kinds/plugin/schema.js +24 -4
- package/dist/core/format/src/kinds/provider/kind.js +40 -1
- package/dist/core/format/src/kinds/provider/types.d.ts +19 -0
- package/dist/core/format/src/kinds/provider/types.js +22 -0
- package/dist/core/format/src/kinds/routine/schema.d.ts +10 -5
- package/dist/core/format/src/kinds/routine/schema.js +21 -15
- package/dist/core/format/src/kinds/workspace/schema.js +5 -4
- package/dist/core/format/src/parse-file.js +3 -1
- package/dist/core/format/src/shared/fields.d.ts +9 -2
- package/dist/core/format/src/shared/fields.js +15 -6
- package/dist/core/format/src/shared/guard.d.ts +8 -0
- package/dist/core/format/src/shared/guard.js +50 -1
- package/dist/core/format/src/shared/missing-keys.d.ts +17 -0
- package/dist/core/format/src/shared/missing-keys.js +110 -0
- package/dist/core/ports/src/chat.d.ts +8 -0
- package/dist/core/ports/src/connector-start-failure.d.ts +31 -0
- package/dist/core/ports/src/connector-start-failure.js +32 -0
- package/dist/core/ports/src/connector-tool-error.d.ts +33 -0
- package/dist/core/ports/src/connector-tool-error.js +40 -0
- package/dist/core/ports/src/definition-store-left-out.d.ts +46 -0
- package/dist/core/ports/src/definition-store-left-out.js +47 -0
- package/dist/core/ports/src/definition-store.d.ts +13 -3
- package/dist/core/ports/src/definition-store.js +1 -1
- package/dist/core/ports/src/deploy-target.d.ts +358 -0
- package/dist/core/ports/src/deploy-target.js +2 -0
- package/dist/core/ports/src/harness-bridge-server.d.ts +55 -4
- package/dist/core/ports/src/harness.d.ts +33 -2
- package/dist/core/ports/src/host-too-old.d.ts +23 -0
- package/dist/core/ports/src/host-too-old.js +27 -0
- package/dist/core/ports/src/index.d.ts +16 -5
- package/dist/core/ports/src/index.js +15 -3
- package/dist/core/ports/src/llm-provider.d.ts +37 -6
- package/dist/core/ports/src/llm-provider.js +43 -3
- package/dist/core/ports/src/pairing-codes.d.ts +111 -0
- package/dist/core/ports/src/pairing-codes.js +336 -0
- package/dist/core/ports/src/pairing-qr-bytes.d.ts +32 -0
- package/dist/core/ports/src/pairing-qr-bytes.js +116 -0
- package/dist/core/ports/src/port-versions.d.ts +6 -2
- package/dist/core/ports/src/port-versions.js +8 -0
- package/dist/core/ports/src/remote-control.d.ts +159 -0
- package/dist/core/ports/src/remote-control.js +26 -0
- package/dist/core/ports/src/remote-gateway-protocol.d.ts +220 -0
- package/dist/core/ports/src/remote-gateway-protocol.js +62 -0
- package/dist/core/ports/src/remote-gateway-session.d.ts +194 -0
- package/dist/core/ports/src/remote-gateway-session.js +241 -0
- package/dist/core/ports/src/run-executor.d.ts +39 -3
- package/dist/core/ports/src/run-executor.js +1 -1
- package/dist/core/ports/src/sandbox.d.ts +19 -0
- package/dist/core/ports/src/sandbox.js +14 -0
- package/dist/core/ports/src/secrets.d.ts +32 -1
- package/dist/core/ports/src/secrets.js +19 -2
- package/dist/core/ports/src/tunnel-provider.d.ts +117 -0
- package/dist/core/ports/src/tunnel-provider.js +65 -0
- package/dist/core/ports/src/tunnel-resolver.d.ts +83 -0
- package/dist/core/ports/src/tunnel-resolver.js +36 -0
- package/dist/core/ports/src/vcs.d.ts +30 -0
- package/dist/core/schema-kit/src/builders.d.ts +5 -0
- package/dist/core/schema-kit/src/builders.js +5 -0
- package/dist/core/std/src/hidden-characters.d.ts +9 -0
- package/dist/core/std/src/hidden-characters.js +18 -0
- package/dist/core/std/src/index.d.ts +3 -1
- package/dist/core/std/src/index.js +3 -1
- package/dist/core/std/src/path-overlap.d.ts +22 -0
- package/dist/core/std/src/path-overlap.js +57 -0
- package/dist/core/std/src/public-suffixes.generated.d.ts +1 -1
- package/dist/core/std/src/public-suffixes.generated.js +0 -1
- package/dist/core/std/src/word-diff.d.ts +28 -0
- package/dist/core/std/src/word-diff.js +77 -0
- package/dist/core/yaml/src/edit-data.d.ts +7 -0
- package/dist/core/yaml/src/edit-data.js +62 -3
- package/dist/core/yaml/src/edit.d.ts +7 -0
- package/dist/core/yaml/src/edit.js +34 -3
- package/dist/core/yaml/src/splice-node.d.ts +6 -0
- package/dist/core/yaml/src/splice-node.js +10 -0
- package/dist/core/yaml/src/splice.js +20 -10
- package/dist/testing/integration/src/checks.d.ts +5 -3
- package/dist/testing/integration/src/checks.js +31 -3
- package/package.json +9 -2
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The end-to-end session around the remote gateway protocol: the Noise
|
|
3
|
+
* handshakes, the binary frames they travel in, the two cleartext refusals,
|
|
4
|
+
* and the limits and times both sides keep (requirement
|
|
5
|
+
* `ports.remote-gateway-session`, ADR "Pairing and the end-to-end session").
|
|
6
|
+
* No crypto is done here: a Noise library does it behind an adapter.
|
|
7
|
+
*/
|
|
8
|
+
/** The Noise handshake that pairs a new phone, on the QR and the typed route alike. */
|
|
9
|
+
export const gatewayPairingPattern = "Noise_XXpsk3_25519_ChaChaPoly_SHA256";
|
|
10
|
+
/** The Noise handshake a paired phone reconnects with, to the host key it pinned. */
|
|
11
|
+
export const gatewayReconnectPattern = "Noise_IK_25519_ChaChaPoly_SHA256";
|
|
12
|
+
/**
|
|
13
|
+
* The Noise prologue of both handshakes. It names the protocol version, so a
|
|
14
|
+
* peer of another version fails the handshake instead of negotiating.
|
|
15
|
+
*/
|
|
16
|
+
export const gatewayNoisePrologue = "halonic-gateway/2";
|
|
17
|
+
/**
|
|
18
|
+
* The first byte of every binary WebSocket frame, which says what follows.
|
|
19
|
+
*
|
|
20
|
+
* - `pair1` to `pair3` carry the three messages of the pairing handshake,
|
|
21
|
+
* `resume1` and `resume2` the two of the reconnect handshake.
|
|
22
|
+
* - `message` carries one Noise transport message holding one gateway message.
|
|
23
|
+
* - `rekey` carries an empty transport message, the sender's last under its
|
|
24
|
+
* old key: it rekeys its sending direction after it, and the reader rekeys
|
|
25
|
+
* its receiving direction after reading it.
|
|
26
|
+
* - `handshake-failed` and `pair-refused` are the only cleartext frames. They
|
|
27
|
+
* are informative: anyone on the path could fake one, and neither may make
|
|
28
|
+
* the phone clear anything.
|
|
29
|
+
*
|
|
30
|
+
* Any other first byte, a frame of a kind the other side doesn't send, a
|
|
31
|
+
* handshake frame out of order or a text frame closes the connection.
|
|
32
|
+
*/
|
|
33
|
+
export const gatewayFrameKinds = {
|
|
34
|
+
pair1: 0x01,
|
|
35
|
+
pair2: 0x02,
|
|
36
|
+
pair3: 0x03,
|
|
37
|
+
resume1: 0x11,
|
|
38
|
+
resume2: 0x12,
|
|
39
|
+
message: 0x20,
|
|
40
|
+
rekey: 0x21,
|
|
41
|
+
"handshake-failed": 0x30,
|
|
42
|
+
"pair-refused": 0x31,
|
|
43
|
+
};
|
|
44
|
+
/** The largest Noise message, handshake or transport, by the Noise spec. */
|
|
45
|
+
export const noiseMaxMessageBytes = 65_535;
|
|
46
|
+
/** The largest binary frame: a kind byte and one Noise message. */
|
|
47
|
+
export const gatewayMaxFrameBytes = 1 + noiseMaxMessageBytes;
|
|
48
|
+
/**
|
|
49
|
+
* The largest handshake message, without its kind byte. The longest, pairing
|
|
50
|
+
* message 3, is 32 + 16 bytes of key and tag and a payload with a name of at
|
|
51
|
+
* most {@link gatewayMaxNameBytes} and a nonce, so a larger one is an attack.
|
|
52
|
+
*/
|
|
53
|
+
export const gatewayMaxHandshakeBytes = 1_024;
|
|
54
|
+
/** The longest name in a handshake payload, the host's or the phone's, in bytes of UTF-8. */
|
|
55
|
+
export const gatewayMaxNameBytes = 64;
|
|
56
|
+
/** What the phone's commitment starts with, in ASCII: it names the use and its version. */
|
|
57
|
+
export const pairCommitLabel = "halonic pair commit v1";
|
|
58
|
+
/** The length of the fresh nonce in pairing message 3's payload, in bytes. */
|
|
59
|
+
export const pairCommitNonceBytes = 16;
|
|
60
|
+
/**
|
|
61
|
+
* The bytes the phone's commitment hashes: {@link pairCommitLabel} in ASCII,
|
|
62
|
+
* the phone's static public key, and the exact bytes of its message 3 payload.
|
|
63
|
+
* Throws a `RangeError` for a key that isn't 32 bytes. The hash itself is the
|
|
64
|
+
* adapter's, like every other primitive.
|
|
65
|
+
*/
|
|
66
|
+
export function pairCommitInput(phoneStaticKey, payload3) {
|
|
67
|
+
if (phoneStaticKey.length !== 32) {
|
|
68
|
+
throw new RangeError("a phone's static key is 32 bytes");
|
|
69
|
+
}
|
|
70
|
+
const label = Uint8Array.from(pairCommitLabel, (c) => c.charCodeAt(0));
|
|
71
|
+
const input = new Uint8Array(label.length + 32 + payload3.length);
|
|
72
|
+
input.set(label, 0);
|
|
73
|
+
input.set(phoneStaticKey, label.length);
|
|
74
|
+
input.set(payload3, label.length + 32);
|
|
75
|
+
return input;
|
|
76
|
+
}
|
|
77
|
+
/** The name a host sends when nothing of its own name is left to show. */
|
|
78
|
+
export const gatewayFallbackHostName = "Computer";
|
|
79
|
+
/**
|
|
80
|
+
* The code points the phone refuses in a host name, as unreadable (requirement
|
|
81
|
+
* `ports.remote-gateway-host-name`): control characters, the line and
|
|
82
|
+
* paragraph separators, the bidi marks, embeddings, overrides and isolates,
|
|
83
|
+
* the zero width space, the word joiner and invisible operators, and the byte
|
|
84
|
+
* order mark. The zero width non-joiner and joiner (U+200C, U+200D) stay:
|
|
85
|
+
* Persian, the Indic scripts and emoji need them. Written as numbers, so the
|
|
86
|
+
* source holds no invisible character itself.
|
|
87
|
+
*/
|
|
88
|
+
const notPlainRanges = [
|
|
89
|
+
[0x0000, 0x001f],
|
|
90
|
+
[0x007f, 0x009f],
|
|
91
|
+
[0x061c, 0x061c],
|
|
92
|
+
[0x200b, 0x200b],
|
|
93
|
+
[0x200e, 0x200f],
|
|
94
|
+
[0x2028, 0x202e],
|
|
95
|
+
[0x2060, 0x2064],
|
|
96
|
+
[0x2066, 0x2069],
|
|
97
|
+
[0xfeff, 0xfeff],
|
|
98
|
+
];
|
|
99
|
+
/**
|
|
100
|
+
* The host's own name as it sends it in pairing message 2, so the phone can
|
|
101
|
+
* read it: without the code points the phone refuses, without spaces at either
|
|
102
|
+
* end, and cut at a whole code point to {@link gatewayMaxNameBytes} bytes of
|
|
103
|
+
* UTF-8. A lone surrogate becomes U+FFFD, since JSON can't carry it as UTF-8.
|
|
104
|
+
* When nothing is left, it is {@link gatewayFallbackHostName}.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* gatewayHostName(`Desk${String.fromCodePoint(0x202e)}kseD`); // "DeskkseD"
|
|
108
|
+
* gatewayHostName("\n"); // "Computer"
|
|
109
|
+
*/
|
|
110
|
+
export function gatewayHostName(name) {
|
|
111
|
+
return gatewayReadableName(name, gatewayFallbackHostName);
|
|
112
|
+
}
|
|
113
|
+
/** The name a host shows and keeps for a phone when nothing of the phone's own name is left. */
|
|
114
|
+
export const gatewayFallbackPhoneName = "Phone";
|
|
115
|
+
/**
|
|
116
|
+
* A name one side sent, as the other may show it: cleaned by the rules of
|
|
117
|
+
* {@link gatewayHostName}, or `fallback` when nothing is left. The host
|
|
118
|
+
* cleans a phone's name from pairing message 3 this way, with
|
|
119
|
+
* {@link gatewayFallbackPhoneName}, before it shows it next to the check code.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* gatewayReadableName(`Pixel${String.fromCodePoint(0x202e)} 8`, gatewayFallbackPhoneName); // "Pixel 8"
|
|
123
|
+
*/
|
|
124
|
+
export function gatewayReadableName(name, fallback) {
|
|
125
|
+
let plain = "";
|
|
126
|
+
for (const character of name.toWellFormed()) {
|
|
127
|
+
const point = character.codePointAt(0) ?? 0;
|
|
128
|
+
if (!notPlainRanges.some(([first, last]) => point >= first && point <= last)) {
|
|
129
|
+
plain += character;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
let kept = "";
|
|
133
|
+
let bytes = 0;
|
|
134
|
+
for (const character of plain.trim()) {
|
|
135
|
+
bytes += utf8Length(character.codePointAt(0) ?? 0);
|
|
136
|
+
if (bytes > gatewayMaxNameBytes)
|
|
137
|
+
break;
|
|
138
|
+
kept += character;
|
|
139
|
+
}
|
|
140
|
+
return kept.trimEnd() || fallback;
|
|
141
|
+
}
|
|
142
|
+
/** How many bytes of UTF-8 a code point takes. */
|
|
143
|
+
function utf8Length(point) {
|
|
144
|
+
if (point < 0x80)
|
|
145
|
+
return 1;
|
|
146
|
+
if (point < 0x800)
|
|
147
|
+
return 2;
|
|
148
|
+
if (point < 0x10000)
|
|
149
|
+
return 3;
|
|
150
|
+
return 4;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* The session's times and counts. A handshake not finished
|
|
154
|
+
* `handshakeTimeoutMs` after its first frame is closed. A sender sends a
|
|
155
|
+
* `rekey` frame at the latest `rekeyAfterMs` after its last one, or as its
|
|
156
|
+
* `rekeyAfterMessages`-th transport message since, whichever comes first; a
|
|
157
|
+
* reader closes the connection when one more message arrives without it. The
|
|
158
|
+
* host ends a session `sessionMaxMs` after its handshake, and the phone
|
|
159
|
+
* reconnects with IK.
|
|
160
|
+
*/
|
|
161
|
+
export const gatewaySessionLimits = {
|
|
162
|
+
handshakeTimeoutMs: 10_000,
|
|
163
|
+
rekeyAfterMs: 30 * 60_000,
|
|
164
|
+
rekeyAfterMessages: 10_000,
|
|
165
|
+
sessionMaxMs: 24 * 60 * 60_000,
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* The host's pairing rules, kept in memory only (build plan decision 6). A
|
|
169
|
+
* code lives `codeLifetimeMs` and pairs at most one phone: the first pairing
|
|
170
|
+
* message 3 that decrypts with it uses it up. The host then waits
|
|
171
|
+
* `allowWaitMs` for Allow. A message 3 that doesn't decrypt, or whose
|
|
172
|
+
* commitment doesn't match, is a wrong try and doesn't use the code up. So is
|
|
173
|
+
* a pairing handshake the host answered with message 2 that closes, drops or
|
|
174
|
+
* times out before a message 3 that decrypts and matches, so a leaked code
|
|
175
|
+
* can't be tried against the host's check code for free.
|
|
176
|
+
* `wrongTriesPerCode` wrong tries end the code, and the host takes at most
|
|
177
|
+
* `failedTriesPerMinute` failed tries across all codes before it refuses
|
|
178
|
+
* pairing message 1 until the minute is over.
|
|
179
|
+
*/
|
|
180
|
+
export const pairingRules = {
|
|
181
|
+
codeLifetimeMs: 5 * 60_000,
|
|
182
|
+
allowWaitMs: 2 * 60_000,
|
|
183
|
+
wrongTriesPerCode: 5,
|
|
184
|
+
failedTriesPerMinute: 10,
|
|
185
|
+
};
|
|
186
|
+
/**
|
|
187
|
+
* Why the host refused a pairing before the phone's message 3 decrypted, in
|
|
188
|
+
* the order of the byte that encodes each.
|
|
189
|
+
*
|
|
190
|
+
* - `wrong-code`: message 3 didn't decrypt; `triesLeft` is 1 to 4.
|
|
191
|
+
* - `code-ended`: the code ran out, had its last wrong try, or its dialog was
|
|
192
|
+
* closed, or no pairing is open.
|
|
193
|
+
* - `code-used`: another phone's message 3 already used the code.
|
|
194
|
+
* - `rate-limited`: the host has had too many failed tries this minute.
|
|
195
|
+
*/
|
|
196
|
+
export const pairRefusedReasons = [
|
|
197
|
+
"wrong-code",
|
|
198
|
+
"code-ended",
|
|
199
|
+
"code-used",
|
|
200
|
+
"rate-limited",
|
|
201
|
+
];
|
|
202
|
+
/**
|
|
203
|
+
* Writes a cleartext frame: one kind byte, and for `pair-refused` the index of
|
|
204
|
+
* its reason in {@link pairRefusedReasons} and `triesLeft`. Throws a
|
|
205
|
+
* `RangeError` for a `triesLeft` the rules don't allow.
|
|
206
|
+
*/
|
|
207
|
+
export function encodeCleartextFrame(frame) {
|
|
208
|
+
if (frame.kind === "handshake-failed") {
|
|
209
|
+
return Uint8Array.of(gatewayFrameKinds["handshake-failed"]);
|
|
210
|
+
}
|
|
211
|
+
const most = frame.reason === "wrong-code" ? pairingRules.wrongTriesPerCode - 1 : 0;
|
|
212
|
+
const least = frame.reason === "wrong-code" ? 1 : 0;
|
|
213
|
+
if (!Number.isInteger(frame.triesLeft) || frame.triesLeft < least || frame.triesLeft > most) {
|
|
214
|
+
throw new RangeError(`triesLeft for ${frame.reason} must be ${least} to ${most}`);
|
|
215
|
+
}
|
|
216
|
+
return Uint8Array.of(gatewayFrameKinds["pair-refused"], pairRefusedReasons.indexOf(frame.reason), frame.triesLeft);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Reads a cleartext frame, exactly as {@link encodeCleartextFrame} writes it.
|
|
220
|
+
* Anything else, including a reason or a `triesLeft` it would refuse to
|
|
221
|
+
* write, is `undefined`: the phone treats it as bytes it can't read.
|
|
222
|
+
*/
|
|
223
|
+
export function decodeCleartextFrame(bytes) {
|
|
224
|
+
const [kind, reasonByte, triesLeft] = bytes;
|
|
225
|
+
if (kind === gatewayFrameKinds["handshake-failed"] && bytes.length === 1) {
|
|
226
|
+
return { kind: "handshake-failed" };
|
|
227
|
+
}
|
|
228
|
+
if (kind !== gatewayFrameKinds["pair-refused"] || bytes.length !== 3)
|
|
229
|
+
return undefined;
|
|
230
|
+
const reason = pairRefusedReasons[reasonByte];
|
|
231
|
+
if (reason === undefined || triesLeft === undefined)
|
|
232
|
+
return undefined;
|
|
233
|
+
const frame = { kind: "pair-refused", reason, triesLeft };
|
|
234
|
+
try {
|
|
235
|
+
encodeCleartextFrame(frame);
|
|
236
|
+
}
|
|
237
|
+
catch {
|
|
238
|
+
return undefined;
|
|
239
|
+
}
|
|
240
|
+
return frame;
|
|
241
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { CantTryStep, ModelSkipReason, RunEvent, RunKind, RunSummary, RunTrigger, RunVersion } from "../../events/src/index.js";
|
|
1
|
+
import type { ApprovalResolver, CantTryStep, ModelSkipReason, RunEvent, RunKind, RunSummary, RunTrigger, RunVersion } from "../../events/src/index.js";
|
|
2
2
|
import type { ChatMessage, ChatParams, ChatResponse, ToolDefinition } from "./chat.js";
|
|
3
3
|
/** Version of the {@link RunExecutor} port. A breaking change bumps it and comes with an ADR. */
|
|
4
|
-
export declare const runExecutorVersion =
|
|
4
|
+
export declare const runExecutorVersion = 2;
|
|
5
5
|
/**
|
|
6
6
|
* Start a workflow run. Subflows are not started through this port: the
|
|
7
7
|
* engine starts them inside the executor, which also tells the parent when a
|
|
@@ -73,6 +73,24 @@ export interface SendOptions {
|
|
|
73
73
|
* next one by accident. Absent: no check.
|
|
74
74
|
*/
|
|
75
75
|
readonly callId?: string;
|
|
76
|
+
/**
|
|
77
|
+
* The wait step the event is meant for, as the run's summary names it: its
|
|
78
|
+
* state and the time it started waiting (`lastWaitingAt`). When it is given
|
|
79
|
+
* and the run now waits at another step, or has waited again since, `send`
|
|
80
|
+
* is refused before anything is recorded: a person who answered a wait
|
|
81
|
+
* card that has since moved on must not answer the next wait step by
|
|
82
|
+
* accident. Absent: no check.
|
|
83
|
+
*/
|
|
84
|
+
readonly wait?: {
|
|
85
|
+
readonly state: string;
|
|
86
|
+
readonly since: string;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Where a person's answer to an approval came from, so the run log can say
|
|
90
|
+
* so: `person` at the screen, `remote-device` from a phone. The host sets
|
|
91
|
+
* it from who is signed in, never from what a phone sends. Absent: `person`.
|
|
92
|
+
*/
|
|
93
|
+
readonly by?: Extract<ApprovalResolver, "person" | "remote-device">;
|
|
76
94
|
}
|
|
77
95
|
/** An agent's model settings for a chat turn that aren't saved in a file yet. */
|
|
78
96
|
export interface ChatAgentSettings {
|
|
@@ -128,6 +146,18 @@ export interface ChatTurnRefusal {
|
|
|
128
146
|
/** Why, as plain text. Text a server wrote is cut and escaped before it gets here. */
|
|
129
147
|
reason: string;
|
|
130
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* A listed tool a chat turn left out because nobody approved it yet, as data
|
|
151
|
+
* a status view can read (requirement `ports.chat-turn-waiting`). Waiting
|
|
152
|
+
* isn't a refusal: the tool broke no rule, and it is offered once a person
|
|
153
|
+
* approves it. It never goes to the model.
|
|
154
|
+
*/
|
|
155
|
+
export interface ChatTurnWaiting {
|
|
156
|
+
/** The id of the connector that lists the tool. */
|
|
157
|
+
source: string;
|
|
158
|
+
/** The name the server lists the tool under, cut to 64 characters and escaped. */
|
|
159
|
+
name: string;
|
|
160
|
+
}
|
|
131
161
|
/**
|
|
132
162
|
* A model alias a chat turn skipped before calling it. It is what an
|
|
133
163
|
* `llm.skipped` run log event says, for a turn that has no run log.
|
|
@@ -160,6 +190,11 @@ export interface ChatTurnResponse extends ChatResponse {
|
|
|
160
190
|
turn?: ChatMessage[];
|
|
161
191
|
/** What the turn refused, in the order it happened. Absent or empty when it refused nothing. */
|
|
162
192
|
refusals?: ChatTurnRefusal[];
|
|
193
|
+
/**
|
|
194
|
+
* The listed tools left out because they wait for a person's approval.
|
|
195
|
+
* Absent or empty when none did.
|
|
196
|
+
*/
|
|
197
|
+
waiting?: ChatTurnWaiting[];
|
|
163
198
|
/** The model aliases skipped before any call, in order. Absent or empty when none was. */
|
|
164
199
|
skipped?: ChatTurnSkip[];
|
|
165
200
|
}
|
|
@@ -232,7 +267,8 @@ export interface RunExecutor {
|
|
|
232
267
|
* Delivers an event to a waiting run, such as "approve".
|
|
233
268
|
*
|
|
234
269
|
* @throws when the run doesn't exist, doesn't accept the event now, or
|
|
235
|
-
* doesn't wait on the call that `options.callId`
|
|
270
|
+
* doesn't wait on the call that `options.callId` or the step that
|
|
271
|
+
* `options.wait` names
|
|
236
272
|
*/
|
|
237
273
|
send(runId: string, event: string, payload?: unknown, options?: SendOptions): Promise<RunSummary>;
|
|
238
274
|
/**
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** Version of the {@link RunExecutor} port. A breaking change bumps it and comes with an ADR. */
|
|
2
|
-
export const runExecutorVersion =
|
|
2
|
+
export const runExecutorVersion = 2;
|
|
@@ -81,17 +81,36 @@ export type SandboxUnavailableReason = (typeof sandboxUnavailableReasons)[number
|
|
|
81
81
|
* Studio words the refusal from `reason`.
|
|
82
82
|
* - `fix`, when set, is what fixes it on this machine, as data (since
|
|
83
83
|
* HAL-5393; optional, so the port stays at its version). See {@link SandboxFix}.
|
|
84
|
+
* - `residuals`, on an `ok` check, are limits that hold on this machine only
|
|
85
|
+
* (HAL-5398; optional). See {@link SandboxResidual}.
|
|
84
86
|
*/
|
|
85
87
|
export type SandboxCheck = {
|
|
86
88
|
ok: true;
|
|
87
89
|
reason: null;
|
|
88
90
|
missing: [];
|
|
91
|
+
residuals?: SandboxResidual[];
|
|
89
92
|
} | {
|
|
90
93
|
ok: false;
|
|
91
94
|
reason: SandboxUnavailableReason;
|
|
92
95
|
missing: string[];
|
|
93
96
|
fix?: SandboxFix;
|
|
94
97
|
};
|
|
98
|
+
/**
|
|
99
|
+
* Every limit an `ok` check can find on this machine that isn't a fact of the backend:
|
|
100
|
+
*
|
|
101
|
+
* - `kept-roots-readable` is srt on Windows set up by another program with its
|
|
102
|
+
* profile read grant (or a setup that couldn't be read), so every sandboxed
|
|
103
|
+
* session can read the profile.
|
|
104
|
+
* - `docker-desktop-visible` is srt in Halonic's WSL distro where Docker
|
|
105
|
+
* Desktop's socket or its `/mnt/wsl/docker-desktop*` folders show (HAL-12445).
|
|
106
|
+
*
|
|
107
|
+
* The list is closed, and a new one is a port change. Readers that check a
|
|
108
|
+
* check's shape, such as the agent host's client, take the list from here so
|
|
109
|
+
* a new code reaches them too (HAL-12932).
|
|
110
|
+
*/
|
|
111
|
+
export declare const sandboxResiduals: readonly ["kept-roots-readable", "docker-desktop-visible"];
|
|
112
|
+
/** A limit an `ok` check found on this machine: one of {@link sandboxResiduals}. */
|
|
113
|
+
export type SandboxResidual = (typeof sandboxResiduals)[number];
|
|
95
114
|
/**
|
|
96
115
|
* Every package manager a {@link SandboxFix} can name: `apt` (Debian,
|
|
97
116
|
* Ubuntu), `dnf` (Fedora), `pacman` (Arch), `zypper` (openSUSE) and `brew`
|
|
@@ -62,6 +62,20 @@ export const sandboxUnavailableReasons = [
|
|
|
62
62
|
"sign-in-needed",
|
|
63
63
|
"other",
|
|
64
64
|
];
|
|
65
|
+
/**
|
|
66
|
+
* Every limit an `ok` check can find on this machine that isn't a fact of the backend:
|
|
67
|
+
*
|
|
68
|
+
* - `kept-roots-readable` is srt on Windows set up by another program with its
|
|
69
|
+
* profile read grant (or a setup that couldn't be read), so every sandboxed
|
|
70
|
+
* session can read the profile.
|
|
71
|
+
* - `docker-desktop-visible` is srt in Halonic's WSL distro where Docker
|
|
72
|
+
* Desktop's socket or its `/mnt/wsl/docker-desktop*` folders show (HAL-12445).
|
|
73
|
+
*
|
|
74
|
+
* The list is closed, and a new one is a port change. Readers that check a
|
|
75
|
+
* check's shape, such as the agent host's client, take the list from here so
|
|
76
|
+
* a new code reaches them too (HAL-12932).
|
|
77
|
+
*/
|
|
78
|
+
export const sandboxResiduals = ["kept-roots-readable", "docker-desktop-visible"];
|
|
65
79
|
/**
|
|
66
80
|
* Every package manager a {@link SandboxFix} can name: `apt` (Debian,
|
|
67
81
|
* Ubuntu), `dnf` (Fedora), `pacman` (Arch), `zypper` (openSUSE) and `brew`
|
|
@@ -122,6 +122,12 @@ export declare function describeSecretName(name: string): string;
|
|
|
122
122
|
* the sign-in password. Only Halonic reads them; no workspace may pick them.
|
|
123
123
|
*/
|
|
124
124
|
export declare const halonicSecretNames: readonly string[];
|
|
125
|
+
/**
|
|
126
|
+
* The secrets only the agent host keeps, for itself: the remote host's static
|
|
127
|
+
* key (tunnel phase B). Like {@link halonicSecretNames}, no workspace may pick
|
|
128
|
+
* them, but no deployment needs them, so they aren't in that list.
|
|
129
|
+
*/
|
|
130
|
+
export declare const hostSecretNames: readonly string[];
|
|
125
131
|
/**
|
|
126
132
|
* The prefix of a token's name in a store that also holds secrets, such as
|
|
127
133
|
* the desktop keychain. A secret name with this prefix is a token, so no
|
|
@@ -130,7 +136,7 @@ export declare const halonicSecretNames: readonly string[];
|
|
|
130
136
|
export declare const tokenNamePrefix = "halonic_token_";
|
|
131
137
|
/**
|
|
132
138
|
* Whether a secret name belongs to Halonic: one of {@link halonicSecretNames}
|
|
133
|
-
* or a token name under {@link tokenNamePrefix}. Names are compared in their
|
|
139
|
+
* or {@link hostSecretNames}, or a token name under {@link tokenNamePrefix}. Names are compared in their
|
|
134
140
|
* `secretKey` form, so `Token_Key` is `token-key`.
|
|
135
141
|
*
|
|
136
142
|
* @throws RangeError when the name breaks the rule of the `Secrets` port
|
|
@@ -199,3 +205,28 @@ export declare function workspaceSecrets(secrets: Secrets): Secrets;
|
|
|
199
205
|
* await own.get("plugin__rain__acme-key"); // throws a RangeError
|
|
200
206
|
*/
|
|
201
207
|
export declare function pluginSecrets(secrets: Secrets, pluginId: string): Secrets;
|
|
208
|
+
/** The most origins one key may be allowed to go to. A short list on purpose: each one is a place the key can leak to. */
|
|
209
|
+
export declare const maxAllowedOrigins = 8;
|
|
210
|
+
/**
|
|
211
|
+
* Where the keys in a {@link Secrets} store may be sent. A key has either a
|
|
212
|
+
* list of allowed origins, or none recorded (a key saved before origins
|
|
213
|
+
* existed), which the caller treats by the older rules.
|
|
214
|
+
*
|
|
215
|
+
* Names match as `secretKey` matches them. An origin is the scheme, host and
|
|
216
|
+
* port, as {@link originOf} writes it, and is compared as a whole string,
|
|
217
|
+
* never by prefix.
|
|
218
|
+
*/
|
|
219
|
+
export interface KeyOrigins {
|
|
220
|
+
/**
|
|
221
|
+
* The origins the key may go to, or `undefined` when none is recorded.
|
|
222
|
+
* Never an empty list, and never the key.
|
|
223
|
+
*
|
|
224
|
+
* @throws RangeError when the name breaks the secret name rule
|
|
225
|
+
*/
|
|
226
|
+
allowedOrigins(name: string): Promise<readonly string[] | undefined>;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* The key origins of a host that has no list yet, so every key has none
|
|
230
|
+
* recorded. A host passes it on purpose, to say its key store can't hold them.
|
|
231
|
+
*/
|
|
232
|
+
export declare const noKeyOrigins: KeyOrigins;
|
|
@@ -91,17 +91,23 @@ export function describeSecretName(name) {
|
|
|
91
91
|
* the sign-in password. Only Halonic reads them; no workspace may pick them.
|
|
92
92
|
*/
|
|
93
93
|
export const halonicSecretNames = ["token-key", "serve-password"];
|
|
94
|
+
/**
|
|
95
|
+
* The secrets only the agent host keeps, for itself: the remote host's static
|
|
96
|
+
* key (tunnel phase B). Like {@link halonicSecretNames}, no workspace may pick
|
|
97
|
+
* them, but no deployment needs them, so they aren't in that list.
|
|
98
|
+
*/
|
|
99
|
+
export const hostSecretNames = ["remote-host-key"];
|
|
94
100
|
/**
|
|
95
101
|
* The prefix of a token's name in a store that also holds secrets, such as
|
|
96
102
|
* the desktop keychain. A secret name with this prefix is a token, so no
|
|
97
103
|
* workspace may pick it.
|
|
98
104
|
*/
|
|
99
105
|
export const tokenNamePrefix = "halonic_token_";
|
|
100
|
-
const halonicSecretKeys = new Set(halonicSecretNames.map(secretKey));
|
|
106
|
+
const halonicSecretKeys = new Set([...halonicSecretNames, ...hostSecretNames].map(secretKey));
|
|
101
107
|
const tokenKeyPrefix = secretKey(tokenNamePrefix);
|
|
102
108
|
/**
|
|
103
109
|
* Whether a secret name belongs to Halonic: one of {@link halonicSecretNames}
|
|
104
|
-
* or a token name under {@link tokenNamePrefix}. Names are compared in their
|
|
110
|
+
* or {@link hostSecretNames}, or a token name under {@link tokenNamePrefix}. Names are compared in their
|
|
105
111
|
* `secretKey` form, so `Token_Key` is `token-key`.
|
|
106
112
|
*
|
|
107
113
|
* @throws RangeError when the name breaks the rule of the `Secrets` port
|
|
@@ -198,3 +204,14 @@ export function pluginSecrets(secrets, pluginId) {
|
|
|
198
204
|
},
|
|
199
205
|
};
|
|
200
206
|
}
|
|
207
|
+
// The addresses a stored key may be sent to (HAL-11871, step B of HAL-11343). The key store
|
|
208
|
+
// keeps them next to the key; the model resolver reads them on every call.
|
|
209
|
+
/** The most origins one key may be allowed to go to. A short list on purpose: each one is a place the key can leak to. */
|
|
210
|
+
export const maxAllowedOrigins = 8;
|
|
211
|
+
/**
|
|
212
|
+
* The key origins of a host that has no list yet, so every key has none
|
|
213
|
+
* recorded. A host passes it on purpose, to say its key store can't hold them.
|
|
214
|
+
*/
|
|
215
|
+
export const noKeyOrigins = {
|
|
216
|
+
allowedOrigins: async () => undefined,
|
|
217
|
+
};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/** Version of the {@link TunnelProvider} port. A breaking change bumps it and comes with an ADR. */
|
|
2
|
+
export declare const tunnelProviderVersion = 1;
|
|
3
|
+
/** The four states a tunnel reports, in the order a healthy start passes through the first two. */
|
|
4
|
+
export declare const tunnelStates: readonly ["starting", "ready", "degraded", "down"];
|
|
5
|
+
/** One of {@link tunnelStates}. */
|
|
6
|
+
export type TunnelState = (typeof tunnelStates)[number];
|
|
7
|
+
/**
|
|
8
|
+
* Why a tunnel is `degraded` or `down`. Studio words each code; there is no
|
|
9
|
+
* free-text fallback, so a provider maps its own errors onto this list.
|
|
10
|
+
*/
|
|
11
|
+
export declare const tunnelReasons: readonly ["not-installed", "signed-out", "offline", "provider-error", "public-refused", "stopped"];
|
|
12
|
+
/** One of {@link tunnelReasons}. */
|
|
13
|
+
export type TunnelReason = (typeof tunnelReasons)[number];
|
|
14
|
+
/** What a provider can do, read before `start` so Studio can explain the choice. */
|
|
15
|
+
export interface TunnelCapabilities {
|
|
16
|
+
/** The provider's id, such as "tailscale", "lan" or "fake". */
|
|
17
|
+
readonly id: string;
|
|
18
|
+
/**
|
|
19
|
+
* `true` when the endpoint can be reached from the public internet (a
|
|
20
|
+
* Cloudflare quick tunnel, Tailscale Funnel). Studio treats such a host as
|
|
21
|
+
* public; the remote gateway still accepts only paired devices.
|
|
22
|
+
*/
|
|
23
|
+
readonly public: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* `true` when the provider encrypts the path itself (WireGuard, TLS). The
|
|
26
|
+
* gateway protocol always runs inside Halonic's own end-to-end session as
|
|
27
|
+
* well, so this never replaces it.
|
|
28
|
+
*/
|
|
29
|
+
readonly encryptsPath: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The one thing a tunnel may point at: the remote gateway, on loopback. The
|
|
33
|
+
* host is a literal loopback address, so a config can't name another
|
|
34
|
+
* interface. The bridge, the model gateway, MCP servers and secrets never get
|
|
35
|
+
* a `TunnelConfig` (ADR "Only the remote gateway is reachable by a tunnel").
|
|
36
|
+
*/
|
|
37
|
+
export interface TunnelConfig {
|
|
38
|
+
readonly gateway: {
|
|
39
|
+
readonly host: "127.0.0.1" | "::1";
|
|
40
|
+
readonly port: number;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Checks at runtime what {@link TunnelConfig} says at compile time, for a
|
|
45
|
+
* config read from JSON or a setting: exactly a `gateway` with exactly a
|
|
46
|
+
* loopback `host` and a whole-number `port` from 1 to 65535. Throws a
|
|
47
|
+
* `RangeError` otherwise. Every provider's `start` rejects such a config.
|
|
48
|
+
*/
|
|
49
|
+
export declare function assertTunnelConfig(config: unknown): asserts config is TunnelConfig;
|
|
50
|
+
/**
|
|
51
|
+
* The host's check before it calls `TunnelProvider.start`: the config passes
|
|
52
|
+
* {@link assertTunnelConfig} and its port is `gatewayPort`, the port the
|
|
53
|
+
* host's own remote gateway listener is bound to. Any other port (the
|
|
54
|
+
* bridge's, the model gateway's) throws a `RangeError`, so the provider is
|
|
55
|
+
* never called for it.
|
|
56
|
+
*/
|
|
57
|
+
export declare function assertGatewayTunnelConfig(config: unknown, gatewayPort: number): asserts config is TunnelConfig;
|
|
58
|
+
/**
|
|
59
|
+
* Where a phone reaches the gateway. `url` uses `https:`, `wss:` or `tcp:`;
|
|
60
|
+
* plain `http:` and `ws:` are never given, so an iOS client needs no
|
|
61
|
+
* exception. A `tcp:` stream carries only the end-to-end session.
|
|
62
|
+
*/
|
|
63
|
+
export interface TunnelEndpoint {
|
|
64
|
+
/** The provider that made the endpoint, the same as `TunnelCapabilities.id`. */
|
|
65
|
+
readonly providerId: string;
|
|
66
|
+
readonly url: string;
|
|
67
|
+
/** The same as `TunnelCapabilities.public` for this provider. */
|
|
68
|
+
readonly public: boolean;
|
|
69
|
+
}
|
|
70
|
+
/** One change of a tunnel's state. `reason` is set exactly when `state` is `degraded` or `down`. */
|
|
71
|
+
export type TunnelStatus = {
|
|
72
|
+
readonly state: "starting" | "ready";
|
|
73
|
+
readonly at: string;
|
|
74
|
+
} | {
|
|
75
|
+
readonly state: "degraded" | "down";
|
|
76
|
+
readonly reason: TunnelReason;
|
|
77
|
+
readonly at: string;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Makes the remote gateway reachable from a phone, and nothing more: it
|
|
81
|
+
* carries bytes. Pairing, encryption and what a phone may do are not its
|
|
82
|
+
* concern (tunnel phase A; requirement `ports.tunnel-provider`).
|
|
83
|
+
*
|
|
84
|
+
* `start` rejects with a `RangeError` a config that fails
|
|
85
|
+
* {@link assertTunnelConfig}. The host calls {@link assertGatewayTunnelConfig}
|
|
86
|
+
* before `start`, so no other port ever reaches a provider. The endpoint's
|
|
87
|
+
* `public` equals `capabilities().public`.
|
|
88
|
+
*
|
|
89
|
+
* A provider handles one tunnel at a time. `start` while a tunnel is up
|
|
90
|
+
* returns its endpoint unchanged when the config is the same, and rejects
|
|
91
|
+
* with a `RangeError` when it isn't. A provider that would expose the gateway
|
|
92
|
+
* publicly while `capabilities().public` is `false` refuses with status
|
|
93
|
+
* `down`, reason `public-refused`, instead of starting.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* const config = { gateway: { host: "127.0.0.1", port: gateway.port } };
|
|
97
|
+
* assertGatewayTunnelConfig(config, gateway.port);
|
|
98
|
+
* const endpoint = await provider.start(config);
|
|
99
|
+
* for await (const status of provider.status()) indicator.show(status.state);
|
|
100
|
+
*/
|
|
101
|
+
export interface TunnelProvider {
|
|
102
|
+
capabilities(): Promise<TunnelCapabilities>;
|
|
103
|
+
/**
|
|
104
|
+
* Opens the tunnel and resolves with its endpoint once the state is
|
|
105
|
+
* `ready`. Rejects when the tunnel goes `down` first; the status stream
|
|
106
|
+
* says why.
|
|
107
|
+
*/
|
|
108
|
+
start(config: TunnelConfig): Promise<TunnelEndpoint>;
|
|
109
|
+
/**
|
|
110
|
+
* The current state first, then every change, never the same state and
|
|
111
|
+
* reason twice in a row. Each call gives a new stream. A stream ends after
|
|
112
|
+
* `stop` has reported `down` with reason `stopped`.
|
|
113
|
+
*/
|
|
114
|
+
status(): AsyncIterable<TunnelStatus>;
|
|
115
|
+
/** Closes the tunnel. Calling it when no tunnel is up does nothing. */
|
|
116
|
+
stop(): Promise<void>;
|
|
117
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/** Version of the {@link TunnelProvider} port. A breaking change bumps it and comes with an ADR. */
|
|
2
|
+
export const tunnelProviderVersion = 1;
|
|
3
|
+
/** The four states a tunnel reports, in the order a healthy start passes through the first two. */
|
|
4
|
+
export const tunnelStates = ["starting", "ready", "degraded", "down"];
|
|
5
|
+
/**
|
|
6
|
+
* Why a tunnel is `degraded` or `down`. Studio words each code; there is no
|
|
7
|
+
* free-text fallback, so a provider maps its own errors onto this list.
|
|
8
|
+
*/
|
|
9
|
+
export const tunnelReasons = [
|
|
10
|
+
"not-installed",
|
|
11
|
+
"signed-out",
|
|
12
|
+
"offline",
|
|
13
|
+
"provider-error",
|
|
14
|
+
"public-refused",
|
|
15
|
+
"stopped",
|
|
16
|
+
];
|
|
17
|
+
const loopbackHosts = ["127.0.0.1", "::1"];
|
|
18
|
+
function isPort(value) {
|
|
19
|
+
return Number.isInteger(value) && value >= 1 && value <= 65_535;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Checks at runtime what {@link TunnelConfig} says at compile time, for a
|
|
23
|
+
* config read from JSON or a setting: exactly a `gateway` with exactly a
|
|
24
|
+
* loopback `host` and a whole-number `port` from 1 to 65535. Throws a
|
|
25
|
+
* `RangeError` otherwise. Every provider's `start` rejects such a config.
|
|
26
|
+
*/
|
|
27
|
+
export function assertTunnelConfig(config) {
|
|
28
|
+
const why = tunnelConfigProblem(config);
|
|
29
|
+
if (why !== undefined)
|
|
30
|
+
throw new RangeError(`not a tunnel config: ${why}`);
|
|
31
|
+
}
|
|
32
|
+
function tunnelConfigProblem(config) {
|
|
33
|
+
if (typeof config !== "object" || config === null)
|
|
34
|
+
return "not an object";
|
|
35
|
+
if (Object.keys(config).join() !== "gateway")
|
|
36
|
+
return "it has fields other than gateway";
|
|
37
|
+
const { gateway } = config;
|
|
38
|
+
if (typeof gateway !== "object" || gateway === null)
|
|
39
|
+
return "gateway is not an object";
|
|
40
|
+
if (Object.keys(gateway).sort().join() !== "host,port") {
|
|
41
|
+
return "gateway is not exactly host and port";
|
|
42
|
+
}
|
|
43
|
+
const { host, port } = gateway;
|
|
44
|
+
if (!loopbackHosts.includes(host))
|
|
45
|
+
return `host is not 127.0.0.1 or ::1: ${String(host)}`;
|
|
46
|
+
if (!isPort(port))
|
|
47
|
+
return `port is not a whole number from 1 to 65535: ${String(port)}`;
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The host's check before it calls `TunnelProvider.start`: the config passes
|
|
52
|
+
* {@link assertTunnelConfig} and its port is `gatewayPort`, the port the
|
|
53
|
+
* host's own remote gateway listener is bound to. Any other port (the
|
|
54
|
+
* bridge's, the model gateway's) throws a `RangeError`, so the provider is
|
|
55
|
+
* never called for it.
|
|
56
|
+
*/
|
|
57
|
+
export function assertGatewayTunnelConfig(config, gatewayPort) {
|
|
58
|
+
if (!isPort(gatewayPort)) {
|
|
59
|
+
throw new RangeError(`gateway port is not a whole number from 1 to 65535: ${gatewayPort}`);
|
|
60
|
+
}
|
|
61
|
+
assertTunnelConfig(config);
|
|
62
|
+
if (config.gateway.port !== gatewayPort) {
|
|
63
|
+
throw new RangeError(`a tunnel may point only at the remote gateway on port ${gatewayPort}, not ${config.gateway.port}`);
|
|
64
|
+
}
|
|
65
|
+
}
|