@halonicjs/testing 0.1.0 → 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/NOTICE +4 -0
- package/README.md +1 -1
- package/dist/adapters/http-kit/src/address-checking.d.ts +19 -0
- package/dist/adapters/http-kit/src/address-checking.js +1 -0
- 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 +3 -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/auth-placement.d.ts +40 -0
- package/dist/adapters/integration-kit/src/auth-placement.js +102 -0
- package/dist/adapters/integration-kit/src/current-secret-forms.d.ts +28 -0
- package/dist/adapters/integration-kit/src/current-secret-forms.js +60 -0
- package/dist/adapters/integration-kit/src/declaration.d.ts +2 -1
- package/dist/adapters/integration-kit/src/declaration.js +4 -3
- package/dist/adapters/integration-kit/src/host.d.ts +7 -1
- package/dist/adapters/integration-kit/src/host.js +1 -0
- package/dist/adapters/integration-kit/src/index.d.ts +5 -2
- package/dist/adapters/integration-kit/src/index.js +2 -0
- package/dist/adapters/integration-kit/src/leak-attempt.d.ts +4 -2
- package/dist/adapters/integration-kit/src/leak-attempt.js +5 -2
- package/dist/adapters/integration-kit/src/limited-http.d.ts +7 -1
- package/dist/adapters/integration-kit/src/limited-http.js +53 -10
- package/dist/adapters/integration-kit/src/loader.d.ts +28 -11
- package/dist/adapters/integration-kit/src/loader.js +36 -21
- package/dist/adapters/integration-kit/src/own-request.d.ts +2 -2
- package/dist/adapters/integration-kit/src/own-request.js +1 -1
- package/dist/adapters/integration-kit/src/plugin-load.d.ts +3 -3
- package/dist/adapters/integration-kit/src/plugin-load.js +5 -5
- package/dist/adapters/integration-kit/src/policy.d.ts +28 -0
- package/dist/adapters/integration-kit/src/response-body.d.ts +6 -2
- package/dist/adapters/integration-kit/src/secret-filter.d.ts +3 -3
- package/dist/adapters/integration-kit/src/secret-filter.js +19 -4
- package/dist/adapters/integration-kit/src/secret-in-request.d.ts +3 -0
- package/dist/adapters/integration-kit/src/secret-in-request.js +8 -2
- package/dist/adapters/integration-kit/src/secret-placement.d.ts +35 -25
- package/dist/adapters/integration-kit/src/secret-placement.js +65 -95
- package/dist/adapters/integration-kit/src/sign-in-placement.d.ts +29 -0
- package/dist/adapters/integration-kit/src/sign-in-placement.js +92 -0
- 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/blocked-sites.d.ts +57 -0
- package/dist/core/events/src/blocked-sites.js +89 -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 +8 -2
- package/dist/core/events/src/index.js +5 -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 +131 -10
- package/dist/core/events/src/run-event.d.ts +120 -11
- package/dist/core/events/src/run-reads.d.ts +25 -0
- package/dist/core/events/src/run-reads.js +44 -0
- package/dist/core/events/src/run-sends.d.ts +47 -0
- package/dist/core/events/src/run-sends.js +68 -0
- 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 +8 -1
- package/dist/core/events/src/timeline-entry.js +1 -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 +9 -6
- package/dist/core/format/src/index.js +7 -3
- package/dist/core/format/src/integration/index.d.ts +3 -2
- package/dist/core/format/src/integration/index.js +2 -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/sandbox-fields.d.ts +15 -5
- package/dist/core/format/src/kinds/agent/sandbox-fields.js +29 -10
- package/dist/core/format/src/kinds/agent/schema.d.ts +5 -0
- package/dist/core/format/src/kinds/agent/schema.js +5 -2
- package/dist/core/format/src/kinds/connector/is-local.js +1 -1
- package/dist/core/format/src/kinds/connector/kind.js +122 -2
- package/dist/core/format/src/kinds/connector/schema.d.ts +38 -0
- package/dist/core/format/src/kinds/connector/schema.js +71 -2
- package/dist/core/format/src/kinds/deployments/kind.js +25 -1
- package/dist/core/format/src/kinds/deployments/schema.d.ts +40 -0
- package/dist/core/format/src/kinds/deployments/schema.js +52 -0
- package/dist/core/format/src/kinds/integration/approved-sign-ins.d.ts +62 -0
- package/dist/core/format/src/kinds/integration/approved-sign-ins.js +125 -0
- package/dist/core/format/src/kinds/integration/host-key.d.ts +7 -0
- package/dist/core/format/src/kinds/integration/host-key.js +8 -0
- package/dist/core/format/src/kinds/integration/kind.d.ts +4 -2
- package/dist/core/format/src/kinds/integration/kind.js +49 -12
- package/dist/core/format/src/kinds/integration/policy.d.ts +47 -2
- package/dist/core/format/src/kinds/integration/policy.js +61 -2
- package/dist/core/format/src/kinds/integration/schema.d.ts +180 -3
- package/dist/core/format/src/kinds/integration/schema.js +133 -7
- package/dist/core/format/src/kinds/integration/sign-in-checks.d.ts +14 -0
- package/dist/core/format/src/kinds/integration/sign-in-checks.js +150 -0
- package/dist/core/format/src/kinds/integration/sign-in-urls.d.ts +19 -0
- package/dist/core/format/src/kinds/integration/sign-in-urls.js +47 -0
- package/dist/core/format/src/kinds/plugin/checks.d.ts +3 -2
- package/dist/core/format/src/kinds/plugin/checks.js +24 -6
- package/dist/core/format/src/kinds/plugin/schema.d.ts +130 -0
- package/dist/core/format/src/kinds/plugin/schema.js +26 -6
- package/dist/core/format/src/kinds/plugin/ui-checks.d.ts +1 -1
- package/dist/core/format/src/kinds/plugin/ui-checks.js +1 -10
- 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/kind.js +38 -1
- package/dist/core/format/src/kinds/routine/schema.d.ts +20 -5
- package/dist/core/format/src/kinds/routine/schema.js +42 -14
- package/dist/core/format/src/kinds/routine/webhook-headers.d.ts +9 -0
- package/dist/core/format/src/kinds/routine/webhook-headers.js +26 -0
- package/dist/core/format/src/kinds/workflow/schema.js +1 -1
- package/dist/core/format/src/kinds/workspace/kind.js +1 -1
- package/dist/core/format/src/kinds/workspace/schema.d.ts +2 -2
- package/dist/core/format/src/kinds/workspace/schema.js +6 -5
- package/dist/core/format/src/parse-file.js +3 -1
- package/dist/core/format/src/shared/fields.d.ts +12 -8
- package/dist/core/format/src/shared/fields.js +48 -19
- 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/agent-runs-not-available.d.ts +21 -0
- package/dist/core/ports/src/agent-runs-not-available.js +25 -0
- package/dist/core/ports/src/blob-store.d.ts +12 -0
- package/dist/core/ports/src/blob-store.js +22 -0
- package/dist/core/ports/src/chat.d.ts +8 -0
- package/dist/core/ports/src/connector-client.d.ts +48 -4
- package/dist/core/ports/src/connector-client.js +17 -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 +36 -5
- 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 +67 -7
- package/dist/core/ports/src/harness-sign-in-command.d.ts +27 -0
- package/dist/core/ports/src/harness-sign-in-command.js +31 -0
- package/dist/core/ports/src/harness.d.ts +79 -15
- package/dist/core/ports/src/harness.js +1 -1
- package/dist/core/ports/src/host-settings-store.d.ts +116 -0
- package/dist/core/ports/src/host-settings-store.js +106 -0
- 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 +32 -13
- package/dist/core/ports/src/index.js +28 -8
- package/dist/core/ports/src/instruction-trust-store.d.ts +81 -0
- package/dist/core/ports/src/instruction-trust-store.js +43 -0
- package/dist/core/ports/src/integration.d.ts +71 -7
- package/dist/core/ports/src/integration.js +22 -4
- package/dist/core/ports/src/llm-provider.d.ts +39 -6
- package/dist/core/ports/src/llm-provider.js +46 -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/password-hasher.d.ts +36 -20
- package/dist/core/ports/src/port-versions.d.ts +13 -6
- package/dist/core/ports/src/port-versions.js +14 -0
- package/dist/core/ports/src/program-probe.d.ts +25 -2
- package/dist/core/ports/src/program-probe.js +1 -1
- package/dist/core/ports/src/provider-default-base-url.d.ts +10 -0
- package/dist/core/ports/src/provider-default-base-url.js +18 -0
- package/dist/core/ports/src/record-store.d.ts +17 -0
- package/dist/core/ports/src/record-store.js +70 -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 +44 -7
- package/dist/core/ports/src/run-executor.js +1 -1
- package/dist/core/ports/src/run-target-not-found.d.ts +34 -0
- package/dist/core/ports/src/run-target-not-found.js +41 -0
- package/dist/core/ports/src/sandbox-setting-store.d.ts +68 -0
- package/dist/core/ports/src/sandbox-setting-store.js +33 -0
- package/dist/core/ports/src/sandbox.d.ts +149 -13
- package/dist/core/ports/src/sandbox.js +52 -2
- package/dist/core/ports/src/secrets.d.ts +105 -1
- package/dist/core/ports/src/secrets.js +75 -2
- package/dist/core/ports/src/tool-approval-store.d.ts +50 -8
- package/dist/core/ports/src/tool-approval-store.js +59 -0
- 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-status.d.ts +8 -0
- package/dist/core/ports/src/vcs-status.js +90 -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/amount.d.ts +13 -0
- package/dist/core/std/src/amount.js +22 -0
- package/dist/core/std/src/hidden-characters.d.ts +28 -0
- package/dist/core/std/src/hidden-characters.js +72 -0
- package/dist/core/std/src/index.d.ts +7 -0
- package/dist/core/std/src/index.js +7 -0
- 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 +9 -0
- package/dist/core/std/src/public-suffixes.generated.js +10428 -0
- package/dist/core/std/src/registrable-domain.d.ts +10 -0
- package/dist/core/std/src/registrable-domain.js +62 -0
- package/dist/core/std/src/secret-variable-name.d.ts +12 -0
- package/dist/core/std/src/secret-variable-name.js +34 -0
- package/dist/core/std/src/site-name.d.ts +35 -0
- package/dist/core/std/src/site-name.js +111 -0
- package/dist/core/std/src/url-host.d.ts +35 -0
- package/dist/core/std/src/url-host.js +170 -0
- 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/dist/testing/integration/src/load.js +3 -1
- package/package.json +9 -2
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/** Version of the {@link InstructionTrustStore} port. A breaking change bumps it and comes with an ADR. */
|
|
2
|
+
export declare const instructionTrustStoreVersion = 1;
|
|
3
|
+
/** What a run's instructions were: a digest per file, and one digest for all of them. */
|
|
4
|
+
export interface InstructionPin {
|
|
5
|
+
/** The digest of the whole set, so two runs with the same instructions share it. */
|
|
6
|
+
readonly digest: string;
|
|
7
|
+
/** Each file's `sha256:` digest, by file name. */
|
|
8
|
+
readonly files: Readonly<Record<string, string>>;
|
|
9
|
+
}
|
|
10
|
+
/** How a set of instructions differs from a trusted pin. */
|
|
11
|
+
export interface InstructionChanges {
|
|
12
|
+
readonly added: readonly string[];
|
|
13
|
+
readonly removed: readonly string[];
|
|
14
|
+
readonly changed: readonly string[];
|
|
15
|
+
}
|
|
16
|
+
/** Which agent's instructions a trusted pin is for. */
|
|
17
|
+
export interface InstructionTrustKey {
|
|
18
|
+
/** The workspace's resolved real path, as in a `TrustRecord`. */
|
|
19
|
+
location: string;
|
|
20
|
+
/** The agent's id in the workspace. */
|
|
21
|
+
agent: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The instructions a person trusted for one agent (requirement
|
|
25
|
+
* `ports.instruction-trust-store`): the pin of its `AGENTS.md` and skills as
|
|
26
|
+
* they were when the person said yes. Without a record, nothing is trusted
|
|
27
|
+
* and a person is asked.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* const trusted: InstructionTrustRecord = {
|
|
31
|
+
* location: "/workspaces/acme",
|
|
32
|
+
* agent: "coder",
|
|
33
|
+
* pin: { digest: "sha256:9f86d0…", files: { "AGENTS.md": "sha256:2c26b4…" } },
|
|
34
|
+
* grantedAt: "2026-11-15T10:00:00.000Z",
|
|
35
|
+
* };
|
|
36
|
+
*/
|
|
37
|
+
export interface InstructionTrustRecord extends InstructionTrustKey {
|
|
38
|
+
/** The instructions the person trusted. */
|
|
39
|
+
pin: InstructionPin;
|
|
40
|
+
/** When the person trusted them, as ISO text. */
|
|
41
|
+
grantedAt: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Each agent's trusted instructions, in the user's profile next to the trust
|
|
45
|
+
* records: the profile folder for the CLI and `serve`, the app data folder
|
|
46
|
+
* for the desktop app, memory for tests and the browser demo. **Never inside
|
|
47
|
+
* a workspace**, so an agent that edits its own instructions can't also trust
|
|
48
|
+
* them.
|
|
49
|
+
*
|
|
50
|
+
* The port only stores pins. `instructionTrust` in `core/app` compares one
|
|
51
|
+
* with the instructions a run has, and the engine asks. Only a person trusts
|
|
52
|
+
* instructions: no tool the model can call reaches this store.
|
|
53
|
+
*
|
|
54
|
+
* A record that exists but can't be read makes `get` throw, never return
|
|
55
|
+
* `null`: the caller then asks the person, never trusts, and says why. The
|
|
56
|
+
* error names the record's key, and `remove` still deletes it.
|
|
57
|
+
*/
|
|
58
|
+
export interface InstructionTrustStore {
|
|
59
|
+
/** The trusted instructions for one agent, or `null` when there are none. */
|
|
60
|
+
get(key: InstructionTrustKey): Promise<InstructionTrustRecord | null>;
|
|
61
|
+
/** Saves trusted instructions, replacing any with the same key. */
|
|
62
|
+
save(record: InstructionTrustRecord): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Deletes the trusted instructions for one agent, even a record that can't
|
|
65
|
+
* be read. Removing a record that isn't there is not an error.
|
|
66
|
+
*/
|
|
67
|
+
remove(key: InstructionTrustKey): Promise<void>;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Whether `value`, as read back from a store, is valid trusted instructions
|
|
71
|
+
* for `key`: exactly the fields of an {@link InstructionTrustRecord}, the key
|
|
72
|
+
* asked for, a pin whose `digest` and every file digest are in `sha256:` form,
|
|
73
|
+
* and a time that is text. Anything else is a damaged or borrowed record, such
|
|
74
|
+
* as a hand edit or a file copied from another agent, and must never count as
|
|
75
|
+
* trust. Every adapter checks what it reads with this, and the service in
|
|
76
|
+
* `core/app` checks what an adapter gives back with it again.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* isInstructionTrustFor(key, JSON.parse(text)); // false for `{ ...record, trusted: true }`
|
|
80
|
+
*/
|
|
81
|
+
export declare function isInstructionTrustFor(key: InstructionTrustKey, value: unknown): value is InstructionTrustRecord;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** Version of the {@link InstructionTrustStore} port. A breaking change bumps it and comes with an ADR. */
|
|
2
|
+
export const instructionTrustStoreVersion = 1;
|
|
3
|
+
const recordFields = ["location", "agent", "pin", "grantedAt"];
|
|
4
|
+
const pinFields = ["digest", "files"];
|
|
5
|
+
const digestPattern = /^sha256:[0-9a-f]{64}$/u;
|
|
6
|
+
/** Whether `value` is a plain object with exactly `fields`, each its own property. */
|
|
7
|
+
function hasExactlyFields(value, fields) {
|
|
8
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
9
|
+
return false;
|
|
10
|
+
return (Object.keys(value).length === fields.length &&
|
|
11
|
+
fields.every((field) => Object.hasOwn(value, field)));
|
|
12
|
+
}
|
|
13
|
+
function isPin(value) {
|
|
14
|
+
if (!hasExactlyFields(value, pinFields))
|
|
15
|
+
return false;
|
|
16
|
+
const digest = value["digest"];
|
|
17
|
+
const files = value["files"];
|
|
18
|
+
if (typeof digest !== "string" || !digestPattern.test(digest))
|
|
19
|
+
return false;
|
|
20
|
+
if (typeof files !== "object" || files === null || Array.isArray(files))
|
|
21
|
+
return false;
|
|
22
|
+
return Object.values(files).every((fileDigest) => typeof fileDigest === "string" && digestPattern.test(fileDigest));
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Whether `value`, as read back from a store, is valid trusted instructions
|
|
26
|
+
* for `key`: exactly the fields of an {@link InstructionTrustRecord}, the key
|
|
27
|
+
* asked for, a pin whose `digest` and every file digest are in `sha256:` form,
|
|
28
|
+
* and a time that is text. Anything else is a damaged or borrowed record, such
|
|
29
|
+
* as a hand edit or a file copied from another agent, and must never count as
|
|
30
|
+
* trust. Every adapter checks what it reads with this, and the service in
|
|
31
|
+
* `core/app` checks what an adapter gives back with it again.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* isInstructionTrustFor(key, JSON.parse(text)); // false for `{ ...record, trusted: true }`
|
|
35
|
+
*/
|
|
36
|
+
export function isInstructionTrustFor(key, value) {
|
|
37
|
+
if (!hasExactlyFields(value, recordFields))
|
|
38
|
+
return false;
|
|
39
|
+
return (value["location"] === key.location &&
|
|
40
|
+
value["agent"] === key.agent &&
|
|
41
|
+
typeof value["grantedAt"] === "string" &&
|
|
42
|
+
isPin(value["pin"]));
|
|
43
|
+
}
|
|
@@ -5,11 +5,13 @@ import type { LlmProvider, ProviderConfig } from "./llm-provider.js";
|
|
|
5
5
|
import type { TokenStore } from "./token-store.js";
|
|
6
6
|
/**
|
|
7
7
|
* Version of the {@link Integration} and {@link IntegrationHost} ports. A
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* change bumps it and comes with an ADR. An integration's permission sheet
|
|
9
|
+
* names the version it was built against (`kit`), and the loader refuses one
|
|
10
|
+
* built against a newer version than this. Version 2 adds the sheet's
|
|
11
|
+
* `signIns` and {@link SignInPlacement}; an integration built for version 1
|
|
12
|
+
* runs unchanged.
|
|
11
13
|
*/
|
|
12
|
-
export declare const integrationVersion =
|
|
14
|
+
export declare const integrationVersion = 2;
|
|
13
15
|
/**
|
|
14
16
|
* The longest {@link IntegrationHost.wait} waits, in milliseconds (30 s). The
|
|
15
17
|
* host enforces it; it is exported so an integration can tell in advance
|
|
@@ -50,10 +52,72 @@ export type SecretPlacement =
|
|
|
50
52
|
as: "form";
|
|
51
53
|
field: string;
|
|
52
54
|
};
|
|
53
|
-
/**
|
|
55
|
+
/**
|
|
56
|
+
* Puts the access token of one sign-in the permission sheet declares into a
|
|
57
|
+
* request. Like a secret, the integration names the sign-in and the host
|
|
58
|
+
* places the token, only on the hosts the sheet lists for that sign-in. The
|
|
59
|
+
* integration can use the token but never read it. Only the access token can
|
|
60
|
+
* be placed: there is no `form` form.
|
|
61
|
+
*/
|
|
62
|
+
export type SignInPlacement =
|
|
63
|
+
/** `Authorization: Bearer <value>`. */
|
|
64
|
+
{
|
|
65
|
+
signIn: string;
|
|
66
|
+
as: "bearer";
|
|
67
|
+
}
|
|
68
|
+
/** `<header>: <prefix><value>`. */
|
|
69
|
+
| {
|
|
70
|
+
signIn: string;
|
|
71
|
+
as: "header";
|
|
72
|
+
header: string;
|
|
73
|
+
prefix?: string;
|
|
74
|
+
};
|
|
75
|
+
/** A secret or a sign-in's access token, placed by the host. `secret` and `signIn` never appear together. */
|
|
76
|
+
export type AuthPlacement = SecretPlacement | SignInPlacement;
|
|
77
|
+
/** A request as an integration sends it: a Web `RequestInit`, plus where to put a secret or token. */
|
|
54
78
|
export interface IntegrationRequestInit extends RequestInit {
|
|
55
|
-
/** The secrets to place in this request. Each must be declared and allowed for the host. */
|
|
56
|
-
auth?:
|
|
79
|
+
/** The secrets and sign-in tokens to place in this request. Each must be declared and allowed for the host. */
|
|
80
|
+
auth?: AuthPlacement | readonly AuthPlacement[];
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Fresh access tokens for one integration's sign-ins, on Halonic's side of
|
|
84
|
+
* the line. The kit asks it for a token to place; it is never given to an
|
|
85
|
+
* integration, so a token can't be read, only used.
|
|
86
|
+
*/
|
|
87
|
+
export interface SignInTokens {
|
|
88
|
+
/**
|
|
89
|
+
* A token valid for at least 60 more seconds, refreshed if needed.
|
|
90
|
+
*
|
|
91
|
+
* @throws {SignInNeededError} when the sign-in isn't signed in, or the
|
|
92
|
+
* server no longer accepts its refresh token, so the user must sign in
|
|
93
|
+
* again. Any other failure, such as a network error, is thrown as it is.
|
|
94
|
+
*/
|
|
95
|
+
access(signIn: string, signal?: AbortSignal): Promise<string>;
|
|
96
|
+
/**
|
|
97
|
+
* The server answered 401 to `value`. Counts only if `value` is the
|
|
98
|
+
* current token of that sign-in.
|
|
99
|
+
*/
|
|
100
|
+
rejected(signIn: string, value: string): void;
|
|
101
|
+
/**
|
|
102
|
+
* Every value the secret filter must remove: access tokens not yet
|
|
103
|
+
* expired, the refresh token and the client secret. Synchronous, so it
|
|
104
|
+
* holds only what has been loaded: before the first `access` for a
|
|
105
|
+
* sign-in it holds nothing for it, and nothing has been placed yet.
|
|
106
|
+
*/
|
|
107
|
+
filterValues(): readonly string[];
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* The user has to sign in (again) before the sign-in's token can be used.
|
|
111
|
+
* {@link SignInTokens.access} throws it when there is no sign-in yet or the
|
|
112
|
+
* server answered `invalid_grant` to the refresh token. The kit turns it into
|
|
113
|
+
* the refusal `sign-in-needed`; a failure that signing in wouldn't fix, such
|
|
114
|
+
* as a network error, is not this error.
|
|
115
|
+
*/
|
|
116
|
+
export declare class SignInNeededError extends Error {
|
|
117
|
+
readonly name = "SignInNeededError";
|
|
118
|
+
/** The sign-in, as the sheet names it. */
|
|
119
|
+
readonly signIn: string;
|
|
120
|
+
constructor(signIn: string, options?: ErrorOptions);
|
|
57
121
|
}
|
|
58
122
|
/**
|
|
59
123
|
* The only way an integration reaches the network. It sends only to the
|
|
@@ -1,13 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Version of the {@link Integration} and {@link IntegrationHost} ports. A
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* change bumps it and comes with an ADR. An integration's permission sheet
|
|
4
|
+
* names the version it was built against (`kit`), and the loader refuses one
|
|
5
|
+
* built against a newer version than this. Version 2 adds the sheet's
|
|
6
|
+
* `signIns` and {@link SignInPlacement}; an integration built for version 1
|
|
7
|
+
* runs unchanged.
|
|
6
8
|
*/
|
|
7
|
-
export const integrationVersion =
|
|
9
|
+
export const integrationVersion = 2;
|
|
8
10
|
/**
|
|
9
11
|
* The longest {@link IntegrationHost.wait} waits, in milliseconds (30 s). The
|
|
10
12
|
* host enforces it; it is exported so an integration can tell in advance
|
|
11
13
|
* that a server asks for a longer pause and give up instead.
|
|
12
14
|
*/
|
|
13
15
|
export const maxIntegrationWaitMs = 30_000;
|
|
16
|
+
/**
|
|
17
|
+
* The user has to sign in (again) before the sign-in's token can be used.
|
|
18
|
+
* {@link SignInTokens.access} throws it when there is no sign-in yet or the
|
|
19
|
+
* server answered `invalid_grant` to the refresh token. The kit turns it into
|
|
20
|
+
* the refusal `sign-in-needed`; a failure that signing in wouldn't fix, such
|
|
21
|
+
* as a network error, is not this error.
|
|
22
|
+
*/
|
|
23
|
+
export class SignInNeededError extends Error {
|
|
24
|
+
name = "SignInNeededError";
|
|
25
|
+
/** The sign-in, as the sheet names it. */
|
|
26
|
+
signIn;
|
|
27
|
+
constructor(signIn, options) {
|
|
28
|
+
super(`The sign-in "${signIn}" needs the user to sign in again.`, options);
|
|
29
|
+
this.signIn = signIn;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RunFailureCause, RunFailureKind } from "../../events/src/index.js";
|
|
1
2
|
import type { ChatRequest, ChatResponse, ChatStreamEvent } from "./chat.js";
|
|
2
3
|
import type { HttpClient } from "./http-client.js";
|
|
3
4
|
import type { Secrets } from "./secrets.js";
|
|
@@ -26,7 +27,7 @@ export interface LlmProvider {
|
|
|
26
27
|
* Makes one model call.
|
|
27
28
|
*
|
|
28
29
|
* @throws {ModelCallError} when the call fails, with the reason why: no
|
|
29
|
-
* key, offline, the model is missing, it can't call tools, it ran out of
|
|
30
|
+
* key, offline, no first answer in time, the model is missing, it can't call tools, it ran out of
|
|
30
31
|
* memory, the key wasn't accepted, the account is out of credit, the
|
|
31
32
|
* provider is busy, or the provider refused. Callers treat any other error as `refused`, except the abort
|
|
32
33
|
* error when `request.signal` aborts the call.
|
|
@@ -46,25 +47,30 @@ export interface LlmProvider {
|
|
|
46
47
|
stream?(request: ChatRequest): AsyncIterable<ChatStreamEvent>;
|
|
47
48
|
}
|
|
48
49
|
/** Every reason a model call can fail with, in {@link ModelCallErrorReason} order. */
|
|
49
|
-
export declare const modelCallErrorReasons: readonly ["no-key", "offline", "model-missing", "model-no-tools", "out-of-memory", "key-refused", "out-of-credit", "provider-busy", "refused"];
|
|
50
|
+
export declare const modelCallErrorReasons: readonly ["no-key", "offline", "model-missing", "model-no-tools", "out-of-memory", "timeout", "key-refused", "out-of-credit", "provider-busy", "refused", "local-only"];
|
|
50
51
|
/**
|
|
51
52
|
* Why a model call failed:
|
|
52
53
|
* - `no-key`: the provider needs a key and its secret isn't set. A provider
|
|
53
54
|
* that has a key and is turned away says `key-refused`.
|
|
54
55
|
* - `offline`: the provider couldn't be reached, such as no network, a DNS
|
|
55
|
-
* failure, a refused connection or a
|
|
56
|
+
* failure, a refused connection or a reply that went silent. The error names the `host`
|
|
56
57
|
* when the provider knows it.
|
|
57
58
|
* - `model-missing`: the provider doesn't have the model asked for.
|
|
58
59
|
* - `model-no-tools`: the model can't call tools and the request offered some.
|
|
59
60
|
* - `out-of-memory`: the model doesn't fit in the memory of the machine that
|
|
60
61
|
* runs it. Providers find it with {@link isModelOutOfMemory}.
|
|
62
|
+
* - `timeout`: the provider was reached but gave no first answer in time (10
|
|
63
|
+
* minutes by default). The error names the `host` when the provider knows it.
|
|
61
64
|
* - `key-refused`: the provider didn't accept the key (HTTP 401 or 403).
|
|
62
65
|
* - `out-of-credit`: the account at the provider has no credit left or
|
|
63
66
|
* reached its spending limit, such as HTTP 402 or OpenAI's 429 with
|
|
64
67
|
* `insufficient_quota`. This is never Halonic's own budget.
|
|
65
68
|
* - `provider-busy`: the provider is overloaded or asked the caller to slow
|
|
66
|
-
* down, such as any other HTTP 429, a
|
|
69
|
+
* down, such as any other HTTP 429, a 500, 502, 503 or 504, or Anthropic's
|
|
70
|
+
* 529. A 501 or 505 says the server doesn't do what was asked, and is `refused`.
|
|
67
71
|
* - `refused`: anything else the provider turned down or failed on.
|
|
72
|
+
* - `local-only`: the workspace is local only (`privacy.localOnly: true`)
|
|
73
|
+
* and the model's provider isn't local, so the engine never called it.
|
|
68
74
|
*/
|
|
69
75
|
export type ModelCallErrorReason = (typeof modelCallErrorReasons)[number];
|
|
70
76
|
/**
|
|
@@ -83,21 +89,48 @@ export declare class ModelCallError extends Error {
|
|
|
83
89
|
readonly name = "ModelCallError";
|
|
84
90
|
readonly reason: ModelCallErrorReason;
|
|
85
91
|
/**
|
|
86
|
-
* With `offline` only: the host that didn't answer, as its name and port,
|
|
92
|
+
* With `offline` and `timeout` only: the host that didn't answer, as its name and port,
|
|
87
93
|
* such as `localhost:11434`. Never a URL with a path, a query or a key.
|
|
88
94
|
*/
|
|
89
95
|
readonly host: string | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* The kind of the typed cause, when the call failed for one the engine
|
|
98
|
+
* logs (requirement `ports.model-call-cause`). Absent otherwise, so
|
|
99
|
+
* `errorKindOf` reads such an error as `internal` and logs no cause.
|
|
100
|
+
*/
|
|
101
|
+
readonly kind?: RunFailureKind;
|
|
102
|
+
/** The code and detail of the typed cause, such as `proxy.refused`; absent without one. */
|
|
103
|
+
readonly failureCause?: Pick<RunFailureCause, "code" | "detail">;
|
|
90
104
|
/**
|
|
91
105
|
* @param reason - why the call failed
|
|
92
106
|
* @param message - plain text for the run log, never a key
|
|
93
107
|
* @param options - `cause` keeps the error this one wraps; `host` names the
|
|
94
|
-
* host that didn't answer, and is kept only with `offline`
|
|
108
|
+
* host that didn't answer, and is kept only with `offline` and `timeout`;
|
|
109
|
+
* `failureCause` is the typed cause the engine puts in `run.failed`, such
|
|
110
|
+
* as {@link networkCauseOf} finds on a network error
|
|
95
111
|
*/
|
|
96
112
|
constructor(reason: ModelCallErrorReason, message: string, options?: {
|
|
97
113
|
cause?: unknown;
|
|
98
114
|
host?: string;
|
|
115
|
+
failureCause?: RunFailureCause | undefined;
|
|
99
116
|
});
|
|
100
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* The typed cause a network error carries, so a provider can pass it on in a
|
|
120
|
+
* {@link ModelCallError} (requirement `ports.model-call-cause`). The HTTP
|
|
121
|
+
* client's `ProxyError` has one, such as `proxy.refused` with the proxy and
|
|
122
|
+
* the host: without it, a proxy that refused reads as no internet.
|
|
123
|
+
*
|
|
124
|
+
* It reads the error's own `kind` and `failureCause` by their fields, not
|
|
125
|
+
* `instanceof`, because the error comes from another package. It doesn't
|
|
126
|
+
* check them: the engine checks every cause before it logs it.
|
|
127
|
+
*
|
|
128
|
+
* @returns `undefined` for an error without a string `kind` and an object `failureCause`
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* new ModelCallError("offline", message, { cause, failureCause: networkCauseOf(cause) });
|
|
132
|
+
*/
|
|
133
|
+
export declare function networkCauseOf(error: unknown): RunFailureCause | undefined;
|
|
101
134
|
/**
|
|
102
135
|
* Whether `value` is a {@link ModelCallError}: an `Error` named
|
|
103
136
|
* "ModelCallError" with one of the known reasons. It works across copies of
|
|
@@ -7,10 +7,12 @@ export const modelCallErrorReasons = [
|
|
|
7
7
|
"model-missing",
|
|
8
8
|
"model-no-tools",
|
|
9
9
|
"out-of-memory",
|
|
10
|
+
"timeout",
|
|
10
11
|
"key-refused",
|
|
11
12
|
"out-of-credit",
|
|
12
13
|
"provider-busy",
|
|
13
14
|
"refused",
|
|
15
|
+
"local-only",
|
|
14
16
|
];
|
|
15
17
|
/**
|
|
16
18
|
* The error an {@link LlmProvider} throws when a model call fails, so the
|
|
@@ -28,7 +30,7 @@ export class ModelCallError extends Error {
|
|
|
28
30
|
name = "ModelCallError";
|
|
29
31
|
reason;
|
|
30
32
|
/**
|
|
31
|
-
* With `offline` only: the host that didn't answer, as its name and port,
|
|
33
|
+
* With `offline` and `timeout` only: the host that didn't answer, as its name and port,
|
|
32
34
|
* such as `localhost:11434`. Never a URL with a path, a query or a key.
|
|
33
35
|
*/
|
|
34
36
|
host;
|
|
@@ -36,14 +38,53 @@ export class ModelCallError extends Error {
|
|
|
36
38
|
* @param reason - why the call failed
|
|
37
39
|
* @param message - plain text for the run log, never a key
|
|
38
40
|
* @param options - `cause` keeps the error this one wraps; `host` names the
|
|
39
|
-
* host that didn't answer, and is kept only with `offline`
|
|
41
|
+
* host that didn't answer, and is kept only with `offline` and `timeout`;
|
|
42
|
+
* `failureCause` is the typed cause the engine puts in `run.failed`, such
|
|
43
|
+
* as {@link networkCauseOf} finds on a network error
|
|
40
44
|
*/
|
|
41
45
|
constructor(reason, message, options) {
|
|
42
46
|
super(message, options);
|
|
43
47
|
this.reason = reason;
|
|
44
|
-
this.host = reason === "offline" ? options?.host : undefined;
|
|
48
|
+
this.host = reason === "offline" || reason === "timeout" ? options?.host : undefined;
|
|
49
|
+
const typed = options?.failureCause;
|
|
50
|
+
if (typed !== undefined) {
|
|
51
|
+
const { kind, ...named } = typed;
|
|
52
|
+
this.kind = kind;
|
|
53
|
+
this.failureCause = named;
|
|
54
|
+
}
|
|
45
55
|
}
|
|
46
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* The typed cause a network error carries, so a provider can pass it on in a
|
|
59
|
+
* {@link ModelCallError} (requirement `ports.model-call-cause`). The HTTP
|
|
60
|
+
* client's `ProxyError` has one, such as `proxy.refused` with the proxy and
|
|
61
|
+
* the host: without it, a proxy that refused reads as no internet.
|
|
62
|
+
*
|
|
63
|
+
* It reads the error's own `kind` and `failureCause` by their fields, not
|
|
64
|
+
* `instanceof`, because the error comes from another package. It doesn't
|
|
65
|
+
* check them: the engine checks every cause before it logs it.
|
|
66
|
+
*
|
|
67
|
+
* @returns `undefined` for an error without a string `kind` and an object `failureCause`
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* new ModelCallError("offline", message, { cause, failureCause: networkCauseOf(cause) });
|
|
71
|
+
*/
|
|
72
|
+
export function networkCauseOf(error) {
|
|
73
|
+
if (!(error instanceof Error))
|
|
74
|
+
return undefined;
|
|
75
|
+
const { kind, failureCause } = error;
|
|
76
|
+
if (typeof kind !== "string" || typeof failureCause !== "object" || failureCause === null) {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
const { code, detail } = failureCause;
|
|
80
|
+
return {
|
|
81
|
+
kind: kind,
|
|
82
|
+
...(typeof code === "string" ? { code } : {}),
|
|
83
|
+
...(typeof detail === "object" && detail !== null
|
|
84
|
+
? { detail: detail }
|
|
85
|
+
: {}),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
47
88
|
/**
|
|
48
89
|
* Whether `value` is a {@link ModelCallError}: an `Error` named
|
|
49
90
|
* "ModelCallError" with one of the known reasons. It works across copies of
|
|
@@ -114,6 +155,8 @@ export function isVendorErrorText(value) {
|
|
|
114
155
|
// messages they pass on. Lower case, matched anywhere in the text.
|
|
115
156
|
const outOfMemoryPhrases = [
|
|
116
157
|
"out of memory",
|
|
158
|
+
// Ollama's llama-server loader: "llama-server reported out-of-memory during startup: …".
|
|
159
|
+
"out-of-memory",
|
|
117
160
|
"requires more system memory",
|
|
118
161
|
"insufficient memory",
|
|
119
162
|
"not enough memory",
|
|
@@ -0,0 +1,111 @@
|
|
|
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
|
+
/**
|
|
10
|
+
* The 31 symbols of both codes: digits and capitals without 0, O, 1, I and L,
|
|
11
|
+
* which are easy to mistake for each other.
|
|
12
|
+
*/
|
|
13
|
+
export declare const pairingAlphabet = "23456789ABCDEFGHJKMNPQRSTUVWXYZ";
|
|
14
|
+
/** A pairing code is this many symbols, about 59 bits, shown in three groups of four. */
|
|
15
|
+
export declare const pairingCodeLength = 12;
|
|
16
|
+
/** A check code is this many symbols, shown in two groups of three. */
|
|
17
|
+
export declare const checkCodeLength = 6;
|
|
18
|
+
/**
|
|
19
|
+
* The HKDF-SHA256 info that turns a pairing code into the Noise psk: the
|
|
20
|
+
* input is {@link pairingPskInput}, the salt is empty and the output 32 bytes.
|
|
21
|
+
*/
|
|
22
|
+
export declare const pairingPskInfo = "halonic pair psk v1";
|
|
23
|
+
/**
|
|
24
|
+
* The HKDF-SHA256 info that turns the pairing handshake's hash into the bytes
|
|
25
|
+
* of the check code: the salt is empty and the output
|
|
26
|
+
* {@link checkCodeInputBytes} bytes, for {@link checkCodeFromBytes}.
|
|
27
|
+
*/
|
|
28
|
+
export declare const checkCodeInfo = "halonic pair check v1";
|
|
29
|
+
/** How many HKDF bytes {@link checkCodeFromBytes} reads. */
|
|
30
|
+
export declare const checkCodeInputBytes = 8;
|
|
31
|
+
/**
|
|
32
|
+
* A new pairing code from `randomBytes`, which gives that many bytes from a
|
|
33
|
+
* cryptographic source, such as `crypto.getRandomValues`. A byte of 248 or more
|
|
34
|
+
* is skipped, so each symbol is equally likely. Throws an `Error` when
|
|
35
|
+
* {@link pairingCodeMaxDraws} draws don't give 12 symbols: the source is broken.
|
|
36
|
+
*/
|
|
37
|
+
export declare function newPairingCode(randomBytes: (length: number) => Uint8Array): string;
|
|
38
|
+
/**
|
|
39
|
+
* A pairing code as a person typed it: in any case, with spaces, dots,
|
|
40
|
+
* dashes or middle dots anywhere. Gives the code in its plain form, or
|
|
41
|
+
* `undefined` when it isn't 12 symbols of the alphabet. Only ASCII is
|
|
42
|
+
* uppercased, so a character such as `ſ` can't turn into an `S`.
|
|
43
|
+
*/
|
|
44
|
+
export declare function readPairingCode(typed: string): string | undefined;
|
|
45
|
+
/** A check code read the same way as {@link readPairingCode}, or `undefined`. */
|
|
46
|
+
export declare function readCheckCode(typed: string): string | undefined;
|
|
47
|
+
/** A pairing code as shown: three groups of four, `7KQ2 M9XF 4HTA`. */
|
|
48
|
+
export declare function formatPairingCode(code: string): string;
|
|
49
|
+
/** A check code as shown: two groups of three, `4F7 · 2KQ`. */
|
|
50
|
+
export declare function formatCheckCode(code: string): string;
|
|
51
|
+
/** The HKDF input for the psk: the ASCII bytes of the code in its plain form. */
|
|
52
|
+
export declare function pairingPskInput(code: string): Uint8Array;
|
|
53
|
+
/**
|
|
54
|
+
* The check code from the 8 HKDF bytes of the handshake hash: read as an
|
|
55
|
+
* unsigned 64-bit big-endian number, reduced mod 31⁶, written in the alphabet
|
|
56
|
+
* most significant symbol first. The bias of the reduction is under 2⁻³⁴.
|
|
57
|
+
*/
|
|
58
|
+
export declare function checkCodeFromBytes(bytes: Uint8Array): string;
|
|
59
|
+
/** What a pairing QR code says. */
|
|
60
|
+
export interface PairingQrPayload {
|
|
61
|
+
/** The host's static X25519 public key, 32 bytes: the phone pins it. */
|
|
62
|
+
readonly hostKey: Uint8Array;
|
|
63
|
+
/** The pairing code, in its plain form. */
|
|
64
|
+
readonly code: string;
|
|
65
|
+
/** The host's name, at most {@link pairingQrMaxHostNameBytes} bytes of UTF-8. */
|
|
66
|
+
readonly hostName: string;
|
|
67
|
+
/**
|
|
68
|
+
* Where the phone reaches the gateway: 1 to 3 URLs, the one to try first
|
|
69
|
+
* first, each in its canonical form: `tcp://`, `wss://` or `https://`, an
|
|
70
|
+
* IPv4 address or a lower-case host name, and a port only when it isn't the
|
|
71
|
+
* scheme's default (443 for `wss:` and `https:`; `tcp:` always has one), as
|
|
72
|
+
* `tcp://192.168.1.20:4100` or `wss://studio.tail1234.ts.net`.
|
|
73
|
+
*/
|
|
74
|
+
readonly endpoints: readonly string[];
|
|
75
|
+
}
|
|
76
|
+
/** The text every pairing QR code starts with. */
|
|
77
|
+
export declare const pairingQrPrefix = "halonic-pair:";
|
|
78
|
+
/** The longest QR text, in bytes: it fits a version 8 QR code at level M, which holds 152. */
|
|
79
|
+
export declare const pairingQrMaxBytes = 150;
|
|
80
|
+
/** The longest host name in a QR code, in bytes of UTF-8; a longer one is cut. */
|
|
81
|
+
export declare const pairingQrMaxHostNameBytes = 32;
|
|
82
|
+
/** The most endpoints in a QR code. */
|
|
83
|
+
export declare const pairingQrMaxEndpoints = 3;
|
|
84
|
+
/**
|
|
85
|
+
* Writes a pairing QR code's text: `halonic-pair:` and base64url, without
|
|
86
|
+
* padding, of a record of the version (1), the host key, the code as one
|
|
87
|
+
* base-31 number in 8 bytes, the host name (a length byte, then UTF-8, cut
|
|
88
|
+
* at a whole character to 32 bytes) and the endpoints (a count, then an
|
|
89
|
+
* entry for each, see {@link writeEndpoint}).
|
|
90
|
+
*
|
|
91
|
+
* The endpoints are kept in their order, and one that would take the text
|
|
92
|
+
* past {@link pairingQrMaxBytes} is left out, so the host lists the LAN
|
|
93
|
+
* endpoint first. `endpoints` in the result are the ones kept. Throws a
|
|
94
|
+
* `RangeError` for a key that isn't 32 bytes, a code that isn't a pairing
|
|
95
|
+
* code, an endpoint that isn't in its canonical form (see
|
|
96
|
+
* {@link PairingQrPayload.endpoints}) or is an IPv6 address, or when no
|
|
97
|
+
* endpoint fits.
|
|
98
|
+
*/
|
|
99
|
+
export declare function encodePairingQr(payload: PairingQrPayload): {
|
|
100
|
+
readonly text: string;
|
|
101
|
+
readonly endpoints: readonly string[];
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Reads a pairing QR code's text, exactly as {@link encodePairingQr} writes
|
|
105
|
+
* it. Anything else is `undefined`: another prefix, padding or a character
|
|
106
|
+
* outside base64url, another version, a code past 31¹², a name that isn't
|
|
107
|
+
* UTF-8 or is too long, no endpoint or more than three, an endpoint entry
|
|
108
|
+
* that writing wouldn't give, a missing or an extra byte, or a text over 150
|
|
109
|
+
* bytes.
|
|
110
|
+
*/
|
|
111
|
+
export declare function decodePairingQr(text: string): PairingQrPayload | undefined;
|