@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.
Files changed (122) hide show
  1. package/dist/adapters/http-kit/src/connector-host-class.d.ts +14 -0
  2. package/dist/adapters/http-kit/src/connector-host-class.js +34 -0
  3. package/dist/adapters/http-kit/src/index.d.ts +2 -0
  4. package/dist/adapters/http-kit/src/index.js +2 -0
  5. package/dist/adapters/http-kit/src/ollama-tags.d.ts +20 -0
  6. package/dist/adapters/http-kit/src/ollama-tags.js +38 -0
  7. package/dist/adapters/integration-kit/src/index.d.ts +2 -1
  8. package/dist/adapters/integration-kit/src/index.js +1 -0
  9. package/dist/adapters/integration-kit/src/loader.d.ts +2 -12
  10. package/dist/adapters/integration-kit/src/loader.js +3 -20
  11. package/dist/adapters/integration-kit/src/workspace-choices.d.ts +37 -0
  12. package/dist/adapters/integration-kit/src/workspace-choices.js +37 -0
  13. package/dist/core/events/src/connector-listing-failed.d.ts +18 -0
  14. package/dist/core/events/src/connector-listing-failed.js +1 -0
  15. package/dist/core/events/src/home-path.d.ts +4 -1
  16. package/dist/core/events/src/home-path.js +14 -3
  17. package/dist/core/events/src/index.d.ts +4 -2
  18. package/dist/core/events/src/index.js +2 -0
  19. package/dist/core/events/src/provider-notes.d.ts +16 -0
  20. package/dist/core/events/src/provider-notes.js +24 -0
  21. package/dist/core/events/src/run-basics.d.ts +103 -5
  22. package/dist/core/events/src/run-event.d.ts +72 -7
  23. package/dist/core/events/src/run-summary.d.ts +11 -1
  24. package/dist/core/events/src/sandbox-opened-read.d.ts +2 -1
  25. package/dist/core/events/src/sandbox-opened-read.js +27 -2
  26. package/dist/core/events/src/sandbox-opened.d.ts +37 -4
  27. package/dist/core/events/src/sandbox-opened.js +13 -3
  28. package/dist/core/events/src/summarize.js +3 -0
  29. package/dist/core/events/src/tool-failure-cause.d.ts +25 -0
  30. package/dist/core/events/src/tool-failure-cause.js +66 -0
  31. package/dist/core/format/src/index.d.ts +3 -2
  32. package/dist/core/format/src/index.js +3 -1
  33. package/dist/core/format/src/kinds/agent/harness-limits.d.ts +14 -0
  34. package/dist/core/format/src/kinds/agent/harness-limits.js +27 -0
  35. package/dist/core/format/src/kinds/agent/schema.d.ts +5 -0
  36. package/dist/core/format/src/kinds/agent/schema.js +3 -0
  37. package/dist/core/format/src/kinds/connector/kind.js +24 -3
  38. package/dist/core/format/src/kinds/connector/schema.d.ts +14 -0
  39. package/dist/core/format/src/kinds/connector/schema.js +18 -0
  40. package/dist/core/format/src/kinds/integration/schema.js +1 -1
  41. package/dist/core/format/src/kinds/integration/sign-in-checks.d.ts +2 -1
  42. package/dist/core/format/src/kinds/integration/sign-in-checks.js +33 -3
  43. package/dist/core/format/src/kinds/plugin/checks.d.ts +3 -2
  44. package/dist/core/format/src/kinds/plugin/checks.js +17 -5
  45. package/dist/core/format/src/kinds/plugin/schema.js +24 -4
  46. package/dist/core/format/src/kinds/provider/kind.js +40 -1
  47. package/dist/core/format/src/kinds/provider/types.d.ts +19 -0
  48. package/dist/core/format/src/kinds/provider/types.js +22 -0
  49. package/dist/core/format/src/kinds/routine/schema.d.ts +10 -5
  50. package/dist/core/format/src/kinds/routine/schema.js +21 -15
  51. package/dist/core/format/src/kinds/workspace/schema.js +5 -4
  52. package/dist/core/format/src/parse-file.js +3 -1
  53. package/dist/core/format/src/shared/fields.d.ts +9 -2
  54. package/dist/core/format/src/shared/fields.js +15 -6
  55. package/dist/core/format/src/shared/guard.d.ts +8 -0
  56. package/dist/core/format/src/shared/guard.js +50 -1
  57. package/dist/core/format/src/shared/missing-keys.d.ts +17 -0
  58. package/dist/core/format/src/shared/missing-keys.js +110 -0
  59. package/dist/core/ports/src/chat.d.ts +8 -0
  60. package/dist/core/ports/src/connector-start-failure.d.ts +31 -0
  61. package/dist/core/ports/src/connector-start-failure.js +32 -0
  62. package/dist/core/ports/src/connector-tool-error.d.ts +33 -0
  63. package/dist/core/ports/src/connector-tool-error.js +40 -0
  64. package/dist/core/ports/src/definition-store-left-out.d.ts +46 -0
  65. package/dist/core/ports/src/definition-store-left-out.js +47 -0
  66. package/dist/core/ports/src/definition-store.d.ts +13 -3
  67. package/dist/core/ports/src/definition-store.js +1 -1
  68. package/dist/core/ports/src/deploy-target.d.ts +358 -0
  69. package/dist/core/ports/src/deploy-target.js +2 -0
  70. package/dist/core/ports/src/harness-bridge-server.d.ts +55 -4
  71. package/dist/core/ports/src/harness.d.ts +33 -2
  72. package/dist/core/ports/src/host-too-old.d.ts +23 -0
  73. package/dist/core/ports/src/host-too-old.js +27 -0
  74. package/dist/core/ports/src/index.d.ts +16 -5
  75. package/dist/core/ports/src/index.js +15 -3
  76. package/dist/core/ports/src/llm-provider.d.ts +37 -6
  77. package/dist/core/ports/src/llm-provider.js +43 -3
  78. package/dist/core/ports/src/pairing-codes.d.ts +111 -0
  79. package/dist/core/ports/src/pairing-codes.js +336 -0
  80. package/dist/core/ports/src/pairing-qr-bytes.d.ts +32 -0
  81. package/dist/core/ports/src/pairing-qr-bytes.js +116 -0
  82. package/dist/core/ports/src/port-versions.d.ts +6 -2
  83. package/dist/core/ports/src/port-versions.js +8 -0
  84. package/dist/core/ports/src/remote-control.d.ts +159 -0
  85. package/dist/core/ports/src/remote-control.js +26 -0
  86. package/dist/core/ports/src/remote-gateway-protocol.d.ts +220 -0
  87. package/dist/core/ports/src/remote-gateway-protocol.js +62 -0
  88. package/dist/core/ports/src/remote-gateway-session.d.ts +194 -0
  89. package/dist/core/ports/src/remote-gateway-session.js +241 -0
  90. package/dist/core/ports/src/run-executor.d.ts +39 -3
  91. package/dist/core/ports/src/run-executor.js +1 -1
  92. package/dist/core/ports/src/sandbox.d.ts +19 -0
  93. package/dist/core/ports/src/sandbox.js +14 -0
  94. package/dist/core/ports/src/secrets.d.ts +32 -1
  95. package/dist/core/ports/src/secrets.js +19 -2
  96. package/dist/core/ports/src/tunnel-provider.d.ts +117 -0
  97. package/dist/core/ports/src/tunnel-provider.js +65 -0
  98. package/dist/core/ports/src/tunnel-resolver.d.ts +83 -0
  99. package/dist/core/ports/src/tunnel-resolver.js +36 -0
  100. package/dist/core/ports/src/vcs.d.ts +30 -0
  101. package/dist/core/schema-kit/src/builders.d.ts +5 -0
  102. package/dist/core/schema-kit/src/builders.js +5 -0
  103. package/dist/core/std/src/hidden-characters.d.ts +9 -0
  104. package/dist/core/std/src/hidden-characters.js +18 -0
  105. package/dist/core/std/src/index.d.ts +3 -1
  106. package/dist/core/std/src/index.js +3 -1
  107. package/dist/core/std/src/path-overlap.d.ts +22 -0
  108. package/dist/core/std/src/path-overlap.js +57 -0
  109. package/dist/core/std/src/public-suffixes.generated.d.ts +1 -1
  110. package/dist/core/std/src/public-suffixes.generated.js +0 -1
  111. package/dist/core/std/src/word-diff.d.ts +28 -0
  112. package/dist/core/std/src/word-diff.js +77 -0
  113. package/dist/core/yaml/src/edit-data.d.ts +7 -0
  114. package/dist/core/yaml/src/edit-data.js +62 -3
  115. package/dist/core/yaml/src/edit.d.ts +7 -0
  116. package/dist/core/yaml/src/edit.js +34 -3
  117. package/dist/core/yaml/src/splice-node.d.ts +6 -0
  118. package/dist/core/yaml/src/splice-node.js +10 -0
  119. package/dist/core/yaml/src/splice.js +20 -10
  120. package/dist/testing/integration/src/checks.d.ts +5 -3
  121. package/dist/testing/integration/src/checks.js +31 -3
  122. package/package.json +9 -2
@@ -0,0 +1,336 @@
1
+ /**
2
+ * The codes of phone pairing: the 12-character pairing code, the 6-character
3
+ * check code and the QR payload (requirement `ports.pairing-codes`, ADR
4
+ * "Pairing and the end-to-end session"). These are pure codecs. The HKDF
5
+ * steps are done by the Noise adapter, which has the platform's crypto; the
6
+ * test vectors in `golden/pairing-vectors.json` pin both, so the phone's Rust
7
+ * side can check itself against the same values.
8
+ */
9
+ import { cutUtf8, decodeBase64url, encodeBase64url, encodeUtf8, RecordReader, } from "./pairing-qr-bytes.js";
10
+ /**
11
+ * The 31 symbols of both codes: digits and capitals without 0, O, 1, I and L,
12
+ * which are easy to mistake for each other.
13
+ */
14
+ export const pairingAlphabet = "23456789ABCDEFGHJKMNPQRSTUVWXYZ";
15
+ /** A pairing code is this many symbols, about 59 bits, shown in three groups of four. */
16
+ export const pairingCodeLength = 12;
17
+ /** A check code is this many symbols, shown in two groups of three. */
18
+ export const checkCodeLength = 6;
19
+ /**
20
+ * The HKDF-SHA256 info that turns a pairing code into the Noise psk: the
21
+ * input is {@link pairingPskInput}, the salt is empty and the output 32 bytes.
22
+ */
23
+ export const pairingPskInfo = "halonic pair psk v1";
24
+ /**
25
+ * The HKDF-SHA256 info that turns the pairing handshake's hash into the bytes
26
+ * of the check code: the salt is empty and the output
27
+ * {@link checkCodeInputBytes} bytes, for {@link checkCodeFromBytes}.
28
+ */
29
+ export const checkCodeInfo = "halonic pair check v1";
30
+ /** How many HKDF bytes {@link checkCodeFromBytes} reads. */
31
+ export const checkCodeInputBytes = 8;
32
+ const alphabetSize = BigInt(pairingAlphabet.length);
33
+ const symbols = new Set(pairingAlphabet);
34
+ /**
35
+ * How many times {@link newPairingCode} draws 16 bytes. A good source fails to
36
+ * give 12 symbols in 8 draws with a chance far under 2⁻¹⁰⁰.
37
+ */
38
+ const pairingCodeMaxDraws = 8;
39
+ /**
40
+ * A new pairing code from `randomBytes`, which gives that many bytes from a
41
+ * cryptographic source, such as `crypto.getRandomValues`. A byte of 248 or more
42
+ * is skipped, so each symbol is equally likely. Throws an `Error` when
43
+ * {@link pairingCodeMaxDraws} draws don't give 12 symbols: the source is broken.
44
+ */
45
+ export function newPairingCode(randomBytes) {
46
+ let code = "";
47
+ for (let draw = 0; draw < pairingCodeMaxDraws && code.length < pairingCodeLength; draw += 1) {
48
+ for (const byte of randomBytes(16)) {
49
+ if (byte >= 248 || code.length === pairingCodeLength)
50
+ continue;
51
+ code += pairingAlphabet.charAt(byte % pairingAlphabet.length);
52
+ }
53
+ }
54
+ if (code.length < pairingCodeLength) {
55
+ throw new Error(`no pairing code after ${pairingCodeMaxDraws} draws: the random source is broken`);
56
+ }
57
+ return code;
58
+ }
59
+ /**
60
+ * A pairing code as a person typed it: in any case, with spaces, dots,
61
+ * dashes or middle dots anywhere. Gives the code in its plain form, or
62
+ * `undefined` when it isn't 12 symbols of the alphabet. Only ASCII is
63
+ * uppercased, so a character such as `ſ` can't turn into an `S`.
64
+ */
65
+ export function readPairingCode(typed) {
66
+ return readCode(typed, pairingCodeLength);
67
+ }
68
+ /** A check code read the same way as {@link readPairingCode}, or `undefined`. */
69
+ export function readCheckCode(typed) {
70
+ return readCode(typed, checkCodeLength);
71
+ }
72
+ /**
73
+ * The separators a typed code may hold: ASCII whitespace as Rust's
74
+ * `is_ascii_whitespace` has it, dots, dashes and the middle dot of a shown
75
+ * check code. Everything left must be printable ASCII before it is uppercased.
76
+ */
77
+ const separators = /[ \t\n\f\r.\-·]/g;
78
+ function readCode(typed, length) {
79
+ const plain = typed.replace(separators, "");
80
+ if (!/^[\x21-\x7e]*$/.test(plain))
81
+ return undefined;
82
+ const code = plain.toUpperCase();
83
+ if (code.length !== length || ![...code].every((symbol) => symbols.has(symbol))) {
84
+ return undefined;
85
+ }
86
+ return code;
87
+ }
88
+ /** A pairing code as shown: three groups of four, `7KQ2 M9XF 4HTA`. */
89
+ export function formatPairingCode(code) {
90
+ const plain = requireCode(code, pairingCodeLength, "pairing");
91
+ return `${plain.slice(0, 4)} ${plain.slice(4, 8)} ${plain.slice(8)}`;
92
+ }
93
+ /** A check code as shown: two groups of three, `4F7 · 2KQ`. */
94
+ export function formatCheckCode(code) {
95
+ const plain = requireCode(code, checkCodeLength, "check");
96
+ return `${plain.slice(0, 3)} · ${plain.slice(3)}`;
97
+ }
98
+ function requireCode(code, length, kind) {
99
+ const plain = readCode(code, length);
100
+ if (plain === undefined)
101
+ throw new RangeError(`not a ${kind} code: ${code}`);
102
+ return plain;
103
+ }
104
+ /** The HKDF input for the psk: the ASCII bytes of the code in its plain form. */
105
+ export function pairingPskInput(code) {
106
+ return Uint8Array.from(requireCode(code, pairingCodeLength, "pairing"), (symbol) => symbol.charCodeAt(0));
107
+ }
108
+ /**
109
+ * The check code from the 8 HKDF bytes of the handshake hash: read as an
110
+ * unsigned 64-bit big-endian number, reduced mod 31⁶, written in the alphabet
111
+ * most significant symbol first. The bias of the reduction is under 2⁻³⁴.
112
+ */
113
+ export function checkCodeFromBytes(bytes) {
114
+ if (bytes.length !== checkCodeInputBytes) {
115
+ throw new RangeError(`a check code needs ${checkCodeInputBytes} bytes, not ${bytes.length}`);
116
+ }
117
+ return writeNumber(readNumber(bytes) % alphabetSize ** BigInt(checkCodeLength), checkCodeLength);
118
+ }
119
+ function readNumber(bytes) {
120
+ let value = 0n;
121
+ for (const byte of bytes)
122
+ value = (value << 8n) | BigInt(byte);
123
+ return value;
124
+ }
125
+ function writeNumber(value, length) {
126
+ let rest = value;
127
+ let code = "";
128
+ for (let index = 0; index < length; index += 1) {
129
+ code = pairingAlphabet.charAt(Number(rest % alphabetSize)) + code;
130
+ rest /= alphabetSize;
131
+ }
132
+ return code;
133
+ }
134
+ /** The text every pairing QR code starts with. */
135
+ export const pairingQrPrefix = "halonic-pair:";
136
+ /** The longest QR text, in bytes: it fits a version 8 QR code at level M, which holds 152. */
137
+ export const pairingQrMaxBytes = 150;
138
+ /** The longest host name in a QR code, in bytes of UTF-8; a longer one is cut. */
139
+ export const pairingQrMaxHostNameBytes = 32;
140
+ /** The most endpoints in a QR code. */
141
+ export const pairingQrMaxEndpoints = 3;
142
+ const recordVersion = 1;
143
+ const keyBytes = 32;
144
+ const codeBytes = 8;
145
+ /** The schemes of an endpoint, by the number in the low two bits of its kind byte; 3 is unused. */
146
+ const endpointSchemes = ["tcp", "wss", "https"];
147
+ /** The port a scheme has when its URL gives none; `tcp:` has none, so it always gives one. */
148
+ const defaultPorts = {
149
+ tcp: undefined,
150
+ wss: 443,
151
+ https: 443,
152
+ };
153
+ /** The kind byte's other bits: a host name instead of IPv4, `.ts.net` left off the name, a port follows. */
154
+ const kindName = 0b100;
155
+ const kindTailnet = 0b1000;
156
+ const kindPort = 0b1_0000;
157
+ const tailnetSuffix = ".ts.net";
158
+ const maxHostNameLength = 253;
159
+ /**
160
+ * Writes a pairing QR code's text: `halonic-pair:` and base64url, without
161
+ * padding, of a record of the version (1), the host key, the code as one
162
+ * base-31 number in 8 bytes, the host name (a length byte, then UTF-8, cut
163
+ * at a whole character to 32 bytes) and the endpoints (a count, then an
164
+ * entry for each, see {@link writeEndpoint}).
165
+ *
166
+ * The endpoints are kept in their order, and one that would take the text
167
+ * past {@link pairingQrMaxBytes} is left out, so the host lists the LAN
168
+ * endpoint first. `endpoints` in the result are the ones kept. Throws a
169
+ * `RangeError` for a key that isn't 32 bytes, a code that isn't a pairing
170
+ * code, an endpoint that isn't in its canonical form (see
171
+ * {@link PairingQrPayload.endpoints}) or is an IPv6 address, or when no
172
+ * endpoint fits.
173
+ */
174
+ export function encodePairingQr(payload) {
175
+ if (payload.hostKey.length !== keyBytes)
176
+ throw new RangeError("the host key must be 32 bytes");
177
+ const code = requireCode(payload.code, pairingCodeLength, "pairing");
178
+ const name = cutUtf8(payload.hostName, pairingQrMaxHostNameBytes);
179
+ const head = [recordVersion, ...payload.hostKey, ...codeAsBytes(code), name.length, ...name];
180
+ const kept = [];
181
+ const entries = [];
182
+ for (const endpoint of payload.endpoints) {
183
+ const parts = parseEndpoint(endpoint);
184
+ if (parts === undefined) {
185
+ throw new RangeError(`not an endpoint in its canonical form: ${endpoint}`);
186
+ }
187
+ const entry = writeEndpoint(parts);
188
+ // The head, the count byte, the endpoints kept so far and this one.
189
+ const length = head.length + 1 + entries.length + entry.length;
190
+ if (kept.length === pairingQrMaxEndpoints)
191
+ continue;
192
+ if (qrTextBytes(length) > pairingQrMaxBytes)
193
+ continue;
194
+ kept.push(endpoint);
195
+ entries.push(...entry);
196
+ }
197
+ if (kept.length === 0)
198
+ throw new RangeError("no endpoint fits in the QR code");
199
+ const record = Uint8Array.from([...head, kept.length, ...entries]);
200
+ return { text: pairingQrPrefix + encodeBase64url(record), endpoints: kept };
201
+ }
202
+ /**
203
+ * Reads a pairing QR code's text, exactly as {@link encodePairingQr} writes
204
+ * it. Anything else is `undefined`: another prefix, padding or a character
205
+ * outside base64url, another version, a code past 31¹², a name that isn't
206
+ * UTF-8 or is too long, no endpoint or more than three, an endpoint entry
207
+ * that writing wouldn't give, a missing or an extra byte, or a text over 150
208
+ * bytes.
209
+ */
210
+ export function decodePairingQr(text) {
211
+ if (!text.startsWith(pairingQrPrefix) || text.length > pairingQrMaxBytes)
212
+ return undefined;
213
+ const record = decodeBase64url(text.slice(pairingQrPrefix.length));
214
+ if (record === undefined)
215
+ return undefined;
216
+ const reader = new RecordReader(record);
217
+ if (reader.byte() !== recordVersion)
218
+ return undefined;
219
+ const hostKey = reader.bytes(keyBytes);
220
+ const code = codeFromBytes(reader.bytes(codeBytes));
221
+ const hostName = reader.text(pairingQrMaxHostNameBytes);
222
+ const count = reader.byte();
223
+ if (count === undefined || count < 1 || count > pairingQrMaxEndpoints)
224
+ return undefined;
225
+ const endpoints = [];
226
+ for (let index = 0; index < count; index += 1) {
227
+ const endpoint = readEndpoint(reader);
228
+ if (endpoint === undefined)
229
+ return undefined;
230
+ endpoints.push(endpoint);
231
+ }
232
+ if (hostKey === undefined || code === undefined || hostName === undefined || !reader.done()) {
233
+ return undefined;
234
+ }
235
+ return { hostKey, code, hostName, endpoints };
236
+ }
237
+ const ipv4Part = "(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)";
238
+ const ipv4 = new RegExp(`^${ipv4Part}(?:\\.${ipv4Part}){3}$`);
239
+ const nameLabel = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
240
+ const canonicalEndpoint = /^(tcp|wss|https):\/\/([^:/]+)(?::([1-9]\d{0,4}))?$/;
241
+ /**
242
+ * An endpoint's parts when it is in its canonical form, else `undefined`.
243
+ * An IPv4 address has no leading zeros. A host name is dot-separated labels
244
+ * of lower-case letters, digits and inner dashes, at most 253 characters,
245
+ * and its last label starts with a letter, so it can't be read as an address.
246
+ */
247
+ function parseEndpoint(endpoint) {
248
+ const match = canonicalEndpoint.exec(endpoint);
249
+ if (match === null)
250
+ return undefined;
251
+ const scheme = match[1];
252
+ const hostText = match[2] ?? "";
253
+ const port = match[3] === undefined ? undefined : Number(match[3]);
254
+ if (port === undefined ? scheme === "tcp" : port > 65_535 || port === defaultPorts[scheme]) {
255
+ return undefined;
256
+ }
257
+ if (ipv4.test(hostText))
258
+ return { scheme, host: hostText.split(".").map(Number), port };
259
+ return isHostName(hostText) ? { scheme, host: hostText, port } : undefined;
260
+ }
261
+ function isHostName(host) {
262
+ const labels = host.split(".");
263
+ return (host.length <= maxHostNameLength &&
264
+ labels.every((label) => nameLabel.test(label)) &&
265
+ /^[a-z]/.test(labels.at(-1) ?? ""));
266
+ }
267
+ /**
268
+ * An endpoint's entry: a kind byte (the scheme in the low two bits, 0 `tcp`,
269
+ * 1 `wss`, 2 `https`; then {@link kindName}, {@link kindTailnet} and
270
+ * {@link kindPort}; the top three bits zero), then the 4 bytes of an IPv4
271
+ * address or a length byte and the host name without a final `.ts.net`, then
272
+ * the port in 2 bytes, big-endian, when it isn't the default.
273
+ */
274
+ function writeEndpoint({ scheme, host, port }) {
275
+ let kind = endpointSchemes.indexOf(scheme) | (port === undefined ? 0 : kindPort);
276
+ const entry = [];
277
+ if (typeof host === "string") {
278
+ const tailnet = host.endsWith(tailnetSuffix);
279
+ const name = tailnet ? host.slice(0, -tailnetSuffix.length) : host;
280
+ kind |= kindName | (tailnet ? kindTailnet : 0);
281
+ entry.push(name.length, ...encodeUtf8(name));
282
+ }
283
+ else {
284
+ entry.push(...host);
285
+ }
286
+ if (port !== undefined)
287
+ entry.push(port >> 8, port & 0xff);
288
+ return [kind, ...entry];
289
+ }
290
+ /**
291
+ * An entry read back to its URL, or `undefined` when it isn't exactly the
292
+ * entry {@link writeEndpoint} gives for that URL: so a kind byte with a top
293
+ * bit set, a `.ts.net` bit on an IPv4 address, a name left with `.ts.net`, a
294
+ * default port written out, port 0 or a `tcp:` entry without a port are all
295
+ * refused.
296
+ */
297
+ function readEndpoint(reader) {
298
+ const start = reader.offset;
299
+ const kind = reader.byte() ?? 0;
300
+ const scheme = endpointSchemes[kind & 0b11];
301
+ const host = kind & kindName ? readHostName(reader, kind) : reader.bytes(4)?.join(".");
302
+ const port = kind & kindPort ? reader.bytes(2) : undefined;
303
+ if (scheme === undefined || host === undefined)
304
+ return undefined;
305
+ const url = `${scheme}://${host}${port === undefined ? "" : `:${((port[0] ?? 0) << 8) | (port[1] ?? 0)}`}`;
306
+ const parts = parseEndpoint(url);
307
+ if (parts === undefined)
308
+ return undefined;
309
+ const entry = writeEndpoint(parts);
310
+ const read = reader.since(start);
311
+ return entry.length === read.length && entry.every((byte, index) => byte === read[index])
312
+ ? url
313
+ : undefined;
314
+ }
315
+ function readHostName(reader, kind) {
316
+ const name = reader.text(maxHostNameLength);
317
+ return name !== undefined && kind & kindTailnet ? `${name}${tailnetSuffix}` : name;
318
+ }
319
+ function codeAsBytes(code) {
320
+ let value = 0n;
321
+ for (const symbol of code)
322
+ value = value * alphabetSize + BigInt(pairingAlphabet.indexOf(symbol));
323
+ return Array.from({ length: codeBytes }, (_, index) => Number((value >> BigInt(8 * (codeBytes - 1 - index))) & 0xffn));
324
+ }
325
+ function codeFromBytes(bytes) {
326
+ if (bytes === undefined)
327
+ return undefined;
328
+ const value = readNumber(bytes);
329
+ if (value >= alphabetSize ** BigInt(pairingCodeLength))
330
+ return undefined;
331
+ return writeNumber(value, pairingCodeLength);
332
+ }
333
+ /** The length of the QR text for a record of `length` bytes. */
334
+ function qrTextBytes(length) {
335
+ return pairingQrPrefix.length + Math.ceil((length * 4) / 3);
336
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * The byte helpers of the pairing QR record (see `pairing-codes.ts`): UTF-8,
3
+ * a strict record reader and base64url without padding, none of which the
4
+ * core has built in.
5
+ */
6
+ /** The text cut to at most `most` bytes of UTF-8, at a whole code point. */
7
+ export declare function cutUtf8(text: string, most: number): number[];
8
+ /**
9
+ * UTF-8 without `TextEncoder`, which the core doesn't have: from
10
+ * `encodeURIComponent`, which throws on a lone surrogate.
11
+ */
12
+ export declare function encodeUtf8(text: string): number[];
13
+ /** UTF-8 to text, or `undefined` for bytes that aren't UTF-8: `decodeURIComponent` refuses them. */
14
+ export declare function decodeUtf8(bytes: Uint8Array): string | undefined;
15
+ export declare class RecordReader {
16
+ private readonly record;
17
+ private at;
18
+ private broken;
19
+ constructor(record: Uint8Array);
20
+ byte(): number | undefined;
21
+ bytes(length: number): Uint8Array | undefined;
22
+ /** A length byte, then that many bytes of UTF-8, at most `most`. */
23
+ text(most: number): string | undefined;
24
+ /** Where the next byte is read from. */
25
+ get offset(): number;
26
+ /** The bytes read since `start`. */
27
+ since(start: number): Uint8Array;
28
+ done(): boolean;
29
+ }
30
+ export declare function encodeBase64url(bytes: Uint8Array): string;
31
+ /** Strict: base64url characters only, no padding, and only the one text that writes these bytes. */
32
+ export declare function decodeBase64url(text: string): Uint8Array | undefined;
@@ -0,0 +1,116 @@
1
+ /**
2
+ * The byte helpers of the pairing QR record (see `pairing-codes.ts`): UTF-8,
3
+ * a strict record reader and base64url without padding, none of which the
4
+ * core has built in.
5
+ */
6
+ /** The text cut to at most `most` bytes of UTF-8, at a whole code point. */
7
+ export function cutUtf8(text, most) {
8
+ let points = [...text.toWellFormed()];
9
+ let bytes = encodeUtf8(points.join(""));
10
+ while (bytes.length > most) {
11
+ points = points.slice(0, -1);
12
+ bytes = encodeUtf8(points.join(""));
13
+ }
14
+ return bytes;
15
+ }
16
+ /**
17
+ * UTF-8 without `TextEncoder`, which the core doesn't have: from
18
+ * `encodeURIComponent`, which throws on a lone surrogate.
19
+ */
20
+ export function encodeUtf8(text) {
21
+ const escaped = encodeURIComponent(text);
22
+ const bytes = [];
23
+ for (let index = 0; index < escaped.length; index += 1) {
24
+ if (escaped[index] === "%") {
25
+ bytes.push(Number.parseInt(escaped.slice(index + 1, index + 3), 16));
26
+ index += 2;
27
+ }
28
+ else {
29
+ bytes.push(escaped.charCodeAt(index));
30
+ }
31
+ }
32
+ return bytes;
33
+ }
34
+ /** UTF-8 to text, or `undefined` for bytes that aren't UTF-8: `decodeURIComponent` refuses them. */
35
+ export function decodeUtf8(bytes) {
36
+ try {
37
+ return decodeURIComponent([...bytes].map((byte) => `%${byte.toString(16).padStart(2, "0")}`).join(""));
38
+ }
39
+ catch {
40
+ return undefined;
41
+ }
42
+ }
43
+ export class RecordReader {
44
+ record;
45
+ at = 0;
46
+ broken = false;
47
+ constructor(record) {
48
+ this.record = record;
49
+ }
50
+ byte() {
51
+ return this.bytes(1)?.[0];
52
+ }
53
+ bytes(length) {
54
+ if (this.broken || this.at + length > this.record.length) {
55
+ this.broken = true;
56
+ return undefined;
57
+ }
58
+ this.at += length;
59
+ return this.record.slice(this.at - length, this.at);
60
+ }
61
+ /** A length byte, then that many bytes of UTF-8, at most `most`. */
62
+ text(most) {
63
+ const length = this.byte();
64
+ if (length === undefined || length > most) {
65
+ this.broken = true;
66
+ return undefined;
67
+ }
68
+ const bytes = this.bytes(length);
69
+ const text = bytes === undefined ? undefined : decodeUtf8(bytes);
70
+ if (text === undefined)
71
+ this.broken = true;
72
+ return text;
73
+ }
74
+ /** Where the next byte is read from. */
75
+ get offset() {
76
+ return this.at;
77
+ }
78
+ /** The bytes read since `start`. */
79
+ since(start) {
80
+ return this.record.slice(start, this.at);
81
+ }
82
+ done() {
83
+ return !this.broken && this.at === this.record.length;
84
+ }
85
+ }
86
+ const base64urlAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
87
+ export function encodeBase64url(bytes) {
88
+ let text = "";
89
+ for (let index = 0; index < bytes.length; index += 3) {
90
+ const chunk = [bytes[index], bytes[index + 1], bytes[index + 2]];
91
+ const bits = ((chunk[0] ?? 0) << 16) | ((chunk[1] ?? 0) << 8) | (chunk[2] ?? 0);
92
+ const count = chunk.filter((byte) => byte !== undefined).length + 1;
93
+ for (let place = 0; place < count; place += 1) {
94
+ text += base64urlAlphabet.charAt((bits >> (18 - 6 * place)) & 63);
95
+ }
96
+ }
97
+ return text;
98
+ }
99
+ /** Strict: base64url characters only, no padding, and only the one text that writes these bytes. */
100
+ export function decodeBase64url(text) {
101
+ if (text.length % 4 === 1)
102
+ return undefined;
103
+ const values = [...text].map((character) => base64urlAlphabet.indexOf(character));
104
+ if (values.some((value) => value < 0))
105
+ return undefined;
106
+ const bytes = [];
107
+ for (let index = 0; index < values.length; index += 4) {
108
+ const group = values.slice(index, index + 4);
109
+ const bits = group.reduce((sum, value, place) => sum | (value << (18 - 6 * place)), 0);
110
+ for (let place = 0; place < group.length - 1; place += 1) {
111
+ bytes.push((bits >> (16 - 8 * place)) & 255);
112
+ }
113
+ }
114
+ const decoded = Uint8Array.from(bytes);
115
+ return encodeBase64url(decoded) === text ? decoded : undefined;
116
+ }
@@ -13,7 +13,8 @@ export declare const portVersions: {
13
13
  readonly ConnectionSettingsStore: 1;
14
14
  readonly ConnectorClient: 1;
15
15
  readonly Coordination: 1;
16
- readonly DefinitionStore: 2;
16
+ readonly DefinitionStore: 3;
17
+ readonly DeployTarget: 1;
17
18
  readonly Digest: 1;
18
19
  readonly FolderReader: 1;
19
20
  readonly Harness: 3;
@@ -30,8 +31,9 @@ export declare const portVersions: {
30
31
  readonly PluginFolderWriter: 1;
31
32
  readonly ProgramProbe: 2;
32
33
  readonly RecordStore: 2;
34
+ readonly RemoteControl: 1;
33
35
  readonly ResourceProbe: 1;
34
- readonly RunExecutor: 1;
36
+ readonly RunExecutor: 2;
35
37
  readonly RunStore: 1;
36
38
  readonly Sandbox: 7;
37
39
  readonly SandboxSettingStore: 1;
@@ -40,6 +42,8 @@ export declare const portVersions: {
40
42
  readonly TokenStore: 1;
41
43
  readonly ToolApprovalStore: 1;
42
44
  readonly TrustStore: 1;
45
+ readonly TunnelProvider: 1;
46
+ readonly TunnelResolver: 1;
43
47
  readonly UnfencedRunConsentStore: 1;
44
48
  readonly Vcs: 2;
45
49
  };
@@ -5,6 +5,7 @@ import { connectionSettingsStoreVersion } from "./connection-settings-store.js";
5
5
  import { connectorClientVersion } from "./connector-client.js";
6
6
  import { coordinationVersion } from "./coordination.js";
7
7
  import { definitionStoreVersion } from "./definition-store.js";
8
+ import { deployTargetVersion } from "./deploy-target.js";
8
9
  import { digestVersion } from "./digest.js";
9
10
  import { folderReaderVersion } from "./folder-reader.js";
10
11
  import { harnessVersion } from "./harness.js";
@@ -21,6 +22,7 @@ import { passwordHasherVersion } from "./password-hasher.js";
21
22
  import { pluginFolderWriterVersion } from "./plugin-folder-writer.js";
22
23
  import { programProbeVersion } from "./program-probe.js";
23
24
  import { recordStoreVersion } from "./record-store.js";
25
+ import { remoteControlVersion } from "./remote-control.js";
24
26
  import { resourceProbeVersion } from "./resource-probe.js";
25
27
  import { runExecutorVersion } from "./run-executor.js";
26
28
  import { runStoreVersion } from "./run-store.js";
@@ -31,6 +33,8 @@ import { secretsVersion } from "./secrets.js";
31
33
  import { tokenStoreVersion } from "./token-store.js";
32
34
  import { toolApprovalStoreVersion } from "./tool-approval-store.js";
33
35
  import { trustStoreVersion } from "./trust-store.js";
36
+ import { tunnelProviderVersion } from "./tunnel-provider.js";
37
+ import { tunnelResolverVersion } from "./tunnel-resolver.js";
34
38
  import { unfencedRunConsentStoreVersion } from "./unfenced-run-consent-store.js";
35
39
  import { vcsVersion } from "./vcs.js";
36
40
  /**
@@ -49,6 +53,7 @@ export const portVersions = {
49
53
  ConnectorClient: connectorClientVersion,
50
54
  Coordination: coordinationVersion,
51
55
  DefinitionStore: definitionStoreVersion,
56
+ DeployTarget: deployTargetVersion,
52
57
  Digest: digestVersion,
53
58
  FolderReader: folderReaderVersion,
54
59
  Harness: harnessVersion,
@@ -65,6 +70,7 @@ export const portVersions = {
65
70
  PluginFolderWriter: pluginFolderWriterVersion,
66
71
  ProgramProbe: programProbeVersion,
67
72
  RecordStore: recordStoreVersion,
73
+ RemoteControl: remoteControlVersion,
68
74
  ResourceProbe: resourceProbeVersion,
69
75
  RunExecutor: runExecutorVersion,
70
76
  RunStore: runStoreVersion,
@@ -75,6 +81,8 @@ export const portVersions = {
75
81
  TokenStore: tokenStoreVersion,
76
82
  ToolApprovalStore: toolApprovalStoreVersion,
77
83
  TrustStore: trustStoreVersion,
84
+ TunnelProvider: tunnelProviderVersion,
85
+ TunnelResolver: tunnelResolverVersion,
78
86
  UnfencedRunConsentStore: unfencedRunConsentStoreVersion,
79
87
  Vcs: vcsVersion,
80
88
  };