@nylorun/core 0.4.0-beta → 0.6.0-beta
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/CHANGELOG.md +57 -0
- package/README.md +1 -1
- package/dist/compatibility.d.ts +54 -1
- package/dist/compatibility.js +191 -1
- package/dist/contracts.d.ts +554 -19
- package/dist/contracts.js +463 -29
- package/dist/define.d.ts +4 -0
- package/dist/define.js +2 -0
- package/dist/definition/sandbox-tools.js +1 -1
- package/dist/definition/variant.d.ts +7 -0
- package/dist/definition/variant.js +87 -0
- package/dist/definition/workflow/build.d.ts +38 -0
- package/dist/definition/workflow/build.js +62 -0
- package/dist/definition/workflow/chain.d.ts +49 -0
- package/dist/definition/workflow/chain.js +41 -0
- package/dist/definition/workflow/diagnostics.d.ts +14 -0
- package/dist/definition/workflow/diagnostics.js +38 -0
- package/dist/definition/workflow/index.d.ts +18 -0
- package/dist/definition/workflow/index.js +10 -0
- package/dist/definition/workflow/loop.d.ts +54 -0
- package/dist/definition/workflow/loop.js +102 -0
- package/dist/definition/workflow/map.d.ts +17 -0
- package/dist/definition/workflow/map.js +46 -0
- package/dist/definition/workflow/parallel.d.ts +19 -0
- package/dist/definition/workflow/parallel.js +37 -0
- package/dist/definition/workflow/patch.d.ts +11 -0
- package/dist/definition/workflow/patch.js +45 -0
- package/dist/definition/workflow/runnable.d.ts +40 -0
- package/dist/definition/workflow/runnable.js +251 -0
- package/dist/definition/workflow/slot.d.ts +23 -0
- package/dist/definition/workflow/slot.js +16 -0
- package/dist/definition/workflow/switch.d.ts +26 -0
- package/dist/definition/workflow/switch.js +66 -0
- package/dist/definition/workflow/types.d.ts +25 -0
- package/dist/definition/workflow/types.js +7 -0
- package/dist/definition/workflow/verdict.d.ts +20 -0
- package/dist/definition/workflow/verdict.js +25 -0
- package/dist/index.d.ts +1 -0
- package/dist/types/observe.d.ts +64 -0
- package/dist/types/workflow.d.ts +106 -0
- package/dist/types/workflow.js +1 -0
- package/dist/utils/hash.d.ts +3 -2
- package/dist/utils/hash.js +4 -4
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,62 @@
|
|
|
1
1
|
# @nylorun/core
|
|
2
2
|
|
|
3
|
+
## 0.6.0-beta
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- bf1c2da: **`nylorun dev --ephemeral` runs on the Docker stack, with a Tenant-level fixture model (breaking beta).**
|
|
8
|
+
|
|
9
|
+
- `nylorun dev --ephemeral` creates a temporary Tenant through `@nylorun/admin` (no Project link written), seeds it from `.env` with the fixture model, opens Studio on it and runs the watcher; the Tenant is deleted with its active work cancelled when the watcher ends, Ctrl-C included. It needs a Runtime that advertises `tenant-fixture-model`.
|
|
10
|
+
- `PUT /v1/tenant/config/seed` accepts `fixtureModel: true`, stored as Tenant setting `model.fixture`: that Tenant's model calls use the Runtime's fixture model while other Tenants on the Host keep theirs. `HOST_PROTOCOL` advertises the new optional feature `tenant-fixture-model` (`OPTIONAL_HOST_FEATURES` in `@nylorun/core/compatibility`); clients do not require it.
|
|
11
|
+
- `startEphemeralRuntime()` keeps its signature but its Tenants live in memory instead of SQLite under the Host root; nothing survives `close()`.
|
|
12
|
+
- Closing a Tenant waits for running advances at most the advance grace period (30 s by default) and then abandons them; their lease lapses and the next advance takes over.
|
|
13
|
+
- A Worker stop, Tenant close or ended Restate attempt no longer fails or cancels the turn it interrupts: outcomes already returned are recorded, nothing is settled, and the next advance resumes the turn from its checkpoint. Only a user cancel settles `cancelled`; an advance deadline fails the turn with the deadline's message.
|
|
14
|
+
|
|
15
|
+
- bf1c2da: **The microsandbox backend is removed; the Runtime runs sandbox tools on the virtual backend only.** The optional `microsandbox` dependency is gone. `sandbox.backend` and `NYLORUN_SANDBOX` accept `auto` or `virtual`, and `auto` selects `virtual`. A Tenant that stored `microsandbox` reads it as `auto`. `nylorun doctor sandbox` and the `nylorun dev` banner report only the virtual shell.
|
|
16
|
+
- bf1c2da: **Tenants are Postgres schemas only; SQLite and the `nylorun-runtime` launcher are removed (breaking beta).**
|
|
17
|
+
|
|
18
|
+
- The Runtime runs on Postgres (the Session Store, one schema per Tenant), Restate (Durable Session Execution: one advance per session, fenced by an ownership epoch, and a per-Tenant sweep) and S2 (Durable Streams: every event is written to a Postgres outbox and relayed to the session's stream, which history and SSE read). `--role api|worker|all` selects the process role; `/ready` covers Postgres, Restate and S2.
|
|
19
|
+
- SQLite Tenants are not migrated. On first start the Runtime moves every `tenants/<id>/` directory that holds a `tenant.sqlite` to `trash/<id>-sqlite-<time>/` and logs `sqlite_tenant_moved_to_trash`; recreate those Tenants.
|
|
20
|
+
- `@nylorun/runtime` has no bin: the `nylorun-runtime` launcher and `host-state.json` are gone. The Runtime runs as the `ghcr.io/nylorun/runtime` image (`nylorun start`); its Host entry requires `NYLORUN_DATABASE_URL`.
|
|
21
|
+
- `openTenantRuntime(config, hooks)` requires the Tenant's opened `store` and `envelope`; `OpenTenantRuntime` receives them from the Tenant store. `HostStateFile` is no longer exported.
|
|
22
|
+
- `@nylorun/core`: `LAUNCHER_PROTOCOL` and the launcher error codes are removed; `QuarantineSchema` drops `locked`, `lockPath` and `lockPid`; `TenantStatusSchema.checks.sqlite` is now `checks.store`. `TenantStatusSchema` gains optional `execution` (stuck invocations) and `streams` (basin, outbox depth, relay lag); `HostAggregateSchema` gains optional `outboxDepth` and `relayLagMs`.
|
|
23
|
+
|
|
24
|
+
- bf1c2da: **Tenants can register a Studio principal.** `CreateTenantRequest` gains optional `studioCredentialHash` behind the new protocol feature `studio-principal`; the Runtime stores it as application principal `studio`, and idempotent create compares it too. `@nylorun/admin` exports `deriveStudioToken(adminKey, tenantId)` (HMAC-SHA256 over `nylorun/studio/v1`, NUL, Tenant id) and `createTenant` sends the hash of that key, so Studio can reach any Tenant's API with a key derived from the admin key. Clients require the new feature, so upgrade the Runtime with them.
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- ba1b239: **`nylorun` sets up the local stack; `@nylorun/cli` becomes the Runtime client `nylo` (breaking beta).**
|
|
29
|
+
|
|
30
|
+
- New unscoped package **`nylorun`**: `npx nylorun up` sets up the Docker stack on the first run and starts it after that, from any directory; `npx nylorun down` stops it (volumes are kept). `up` and `down` are aliases of `start` and `stop`. It also owns `status`, `logs`, `studio`, `reset` and `doctor`, pins the Runtime and Studio images (`package.json` `nylorun.runtime` / `nylorun.studio`), depends on `@nylorun/core` only, and never creates Tenants.
|
|
31
|
+
- **`@nylorun/cli`** is the Runtime client with the command **`nylo`**: `nylo tenant create [name]` (creates the Tenant; in a project, writes the Project link and seeds the model provider and sandbox from `.env`), `nylo tenant current|list|use|status|reset|delete`, `nylo configure`, `nylo env` (was `nylorun status --env`) and `nylo doctor sandbox`. It no longer provides the `nylorun` command or the stack commands.
|
|
32
|
+
- **Removed:** `nylorun dev` and `nylorun dev --ephemeral`. Link once with `nylo tenant create`, then run the project's own `npm run dev`. Moved commands exit 2 and name their replacement.
|
|
33
|
+
- **Starter:** the generated project depends on `@nylorun/agents` only (no Nylorun devDependency); `dev` is `tsx watch --env-file-if-exists=.env src/main.ts`. `npm create @nylorun/agent` installs the project and prints the next steps (`npx nylorun up`, `npx @nylorun/cli tenant create`, `npm run dev`) instead of starting development; `--no-open` is accepted and ignored.
|
|
34
|
+
- `connectAgents` names those steps when it finds no Runtime connection. Runtime repair hints, model errors and core's sandbox message name `nylo` and `nylorun up`.
|
|
35
|
+
|
|
36
|
+
## 0.5.0-beta
|
|
37
|
+
|
|
38
|
+
### Minor Changes
|
|
39
|
+
|
|
40
|
+
- c49efed: **Runtime Clients and Admin API (supporting packages).**
|
|
41
|
+
|
|
42
|
+
- **core:** `AdminStatusSchema`, Project-link schemas, `ERROR_CODES` (launcher codes include `platform_unsupported`, `launcher_failed`, `downgrade_refused`), `admin-status` feature, `newPrincipalId`, `compareVersions`.
|
|
43
|
+
- **runtime:** `/v1/admin/status` (alias `/v1/admin/host`), loopback/`Origin`/content-type checks; the launcher ships as this package's `nylorun-runtime` bin (source under `src/launcher/`, not in `exports`) and runs the Host on the Node it runs on.
|
|
44
|
+
- **studio:** `nylorun-studio` binary; connects via `resolveConnection`; waits for `dev`; never calls Admin API or writes `.nylorun/`.
|
|
45
|
+
|
|
46
|
+
**Prerequisites:** developers install Node 24+ and `@nylorun/runtime` (`npm install --global @nylorun/runtime`) themselves; no package downloads Node or the Runtime, and there are no per-platform Runtime packages. Launcher commands: `version`, `up`, `down`, `restart`, `run`, `status`, `logs` (launcher protocol 1).
|
|
47
|
+
|
|
48
|
+
- c49efed: **Breaking (pre-1.0 minor):** Replace a single SQLite Runtime per Project or home directory with a **Runtime Host** that serves isolated **Tenants**, selected by `Nylorun-Tenant` and negotiated with `Nylorun-Protocol` (protocol `2`, feature `runtime-tenants`). Vocabulary: Host root + Tenant + Project link.
|
|
49
|
+
|
|
50
|
+
- **core:** `PROTOCOL_VERSION = 2`, `HOST_PROTOCOL`, `TENANT_HEADER`, `PROTOCOL_HEADER`, `newTenantId` / `isTenantId`, `checkCompatibility`; health schema gains `hostId` + `protocol` (`service: "nylorun-runtime"`); Tenant/admin wire schemas; Tenant model routes under `/v1/tenant/*`.
|
|
51
|
+
- **runtime:** Host process + Tenant module; Tenant model routes under `/v1/tenant/*`; `startEphemeralRuntime` for tests/embeds; executors via `PUT /v1/executors`; sandbox prefix `nylorun-<tenant-id>-`.
|
|
52
|
+
- **agents:** `createClient({ url, key, tenant })`; Transport sends Tenant + protocol headers; `/health` compatibility cache; `IncompatibleRuntimeError` with upgrade remedies.
|
|
53
|
+
- **cli:** Host root lifecycle (`runtime up|down|status|logs|restart|run`); Project link (`.nylorun/link.json` + `credentials.json`); `tenant` commands; `runtime status --env` exports `NYLORUN_RUNTIME_URL`, `NYLORUN_SERVER_KEY`, `NYLORUN_TENANT`; removed Project/home SQLite selectors.
|
|
54
|
+
- **studio:** `startStudio({ …, tenant: { id, name } })`; proxy forwards Tenant + protocol headers; UI shows Tenant name/short id.
|
|
55
|
+
|
|
56
|
+
- fd9fd87: Add workflows: compose agents and `tool()` with `Chain`, `Switch`, `Parallel`, `Map`, and `Loop`. A workflow is a registered runnable (`kind: "workflow"`) with the same session API as an agent — `export const agents`, `saveAgent` (saves referenced agents first), `createSession`, `input` (`content` or `data`), `observe({ follow })`, `pending`, `approve`, `cancel`. Slots (`{ run, id?, input? }`) reshape data between nodes. The flow engine (`runFlowDurable`) returns effects only; `harness/src/loop/` and `runDurable` are unchanged.
|
|
57
|
+
|
|
58
|
+
HostEffect gains flow kinds `agent`, `tool` (node), `fn`, and `verify`, each with `path`, `key`, and `iterations`. The Runtime drives agent nodes through the public session contract (linked sessions, shared sandbox via `PutSession.sandbox`), offers `fn` / `verify` again on lease expiry, and routes executor Actions by `(workflowId, key)` with claim-scoped `ctx.sandbox`. Optional `message.manifest` is a turn-only variant of the session pin (turn manifests). Studio shows the manifest tree, live node status, and session links. Examples under `examples/agents/{chain,switch,parallel,map,loop,ship-feature}/`.
|
|
59
|
+
|
|
3
60
|
## 0.4.0-beta
|
|
4
61
|
|
|
5
62
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ HTTP client, Node host or SDK dependencies.
|
|
|
9
9
|
- Root: shared contracts and types; no authoring or execution entry points.
|
|
10
10
|
|
|
11
11
|
Applications normally import `@nylorun/agents`. Hosts and the execution engine
|
|
12
|
-
consume core directly.
|
|
12
|
+
consume core directly.
|
|
13
13
|
|
|
14
14
|
A built agent's non-enumerable `getBinding()` retains local functions, tool
|
|
15
15
|
snapshots, ordered declarations and live output schemas. Only its manifest is
|
package/dist/compatibility.d.ts
CHANGED
|
@@ -1,3 +1,56 @@
|
|
|
1
1
|
export { hashManifest } from "./utils/hash.js";
|
|
2
|
-
export declare const PROTOCOL_VERSION =
|
|
2
|
+
export declare const PROTOCOL_VERSION = 2;
|
|
3
|
+
export declare const PROTOCOL_FEATURES: readonly ["runtime-tenants", "admin-status", "studio-principal"];
|
|
4
|
+
export type ProtocolFeature = (typeof PROTOCOL_FEATURES)[number];
|
|
5
|
+
/**
|
|
6
|
+
* Host features no client requires: a client that uses one checks the Host's `/health`
|
|
7
|
+
* for it first. `tenant-fixture-model`: `PUT /v1/tenant/config/seed` accepts
|
|
8
|
+
* `fixtureModel: true` (the Tenant's model calls use the Runtime's fixture model).
|
|
9
|
+
*/
|
|
10
|
+
export declare const OPTIONAL_HOST_FEATURES: readonly ["tenant-fixture-model"];
|
|
11
|
+
export type OptionalHostFeature = (typeof OPTIONAL_HOST_FEATURES)[number];
|
|
12
|
+
export interface ProtocolRange {
|
|
13
|
+
min: number;
|
|
14
|
+
max: number;
|
|
15
|
+
features: readonly string[];
|
|
16
|
+
}
|
|
17
|
+
export declare const HOST_PROTOCOL: ProtocolRange;
|
|
3
18
|
export declare const DEFINITION_SCHEMA_VERSION = 2;
|
|
19
|
+
export declare const TENANT_HEADER = "Nylorun-Tenant";
|
|
20
|
+
export declare const PROTOCOL_HEADER = "Nylorun-Protocol";
|
|
21
|
+
export declare const ERROR_CODES: readonly ["not_found", "protocol_unsupported", "host_rejected", "origin_rejected", "unsupported_media_type", "tenant_conflict", "active_work", "connection_missing", "incompatible_host"];
|
|
22
|
+
export type ErrorCode = (typeof ERROR_CODES)[number];
|
|
23
|
+
export declare const TENANT_ID_PATTERN: RegExp;
|
|
24
|
+
export declare const PRINCIPAL_ID_PATTERN: RegExp;
|
|
25
|
+
export declare function isTenantId(value: unknown): value is string;
|
|
26
|
+
export declare function isPrincipalId(value: unknown): value is string;
|
|
27
|
+
/**
|
|
28
|
+
* Lowercase Crockford ULID with `tn_` prefix; 48-bit time + 80-bit CSPRNG.
|
|
29
|
+
* Same-millisecond calls stay lexicographically monotonic by bumping the random
|
|
30
|
+
* component when the clock does not advance.
|
|
31
|
+
*/
|
|
32
|
+
export declare function newTenantId(now?: number): string;
|
|
33
|
+
/** Principal id: `pr_` + lowercase Crockford ULID (same generator as tenants). */
|
|
34
|
+
export declare function newPrincipalId(now?: number): string;
|
|
35
|
+
/**
|
|
36
|
+
* SemVer 2.0 precedence, including prereleases. Build metadata is ignored.
|
|
37
|
+
* Returns -1 when a < b, 0 when equal, 1 when a > b.
|
|
38
|
+
*/
|
|
39
|
+
export declare function compareVersions(a: string, b: string): -1 | 0 | 1;
|
|
40
|
+
export type Compatibility = {
|
|
41
|
+
ok: true;
|
|
42
|
+
} | {
|
|
43
|
+
ok: false;
|
|
44
|
+
reason: "version";
|
|
45
|
+
client: number;
|
|
46
|
+
host: ProtocolRange;
|
|
47
|
+
} | {
|
|
48
|
+
ok: false;
|
|
49
|
+
reason: "feature";
|
|
50
|
+
missing: readonly string[];
|
|
51
|
+
host: ProtocolRange;
|
|
52
|
+
};
|
|
53
|
+
export declare function checkCompatibility(client: {
|
|
54
|
+
version: number;
|
|
55
|
+
required: readonly string[];
|
|
56
|
+
}, host: ProtocolRange): Compatibility;
|
package/dist/compatibility.js
CHANGED
|
@@ -1,3 +1,193 @@
|
|
|
1
1
|
export { hashManifest } from "./utils/hash.js";
|
|
2
|
-
export const PROTOCOL_VERSION =
|
|
2
|
+
export const PROTOCOL_VERSION = 2;
|
|
3
|
+
export const PROTOCOL_FEATURES = [
|
|
4
|
+
"runtime-tenants",
|
|
5
|
+
"admin-status",
|
|
6
|
+
"studio-principal",
|
|
7
|
+
];
|
|
8
|
+
/**
|
|
9
|
+
* Host features no client requires: a client that uses one checks the Host's `/health`
|
|
10
|
+
* for it first. `tenant-fixture-model`: `PUT /v1/tenant/config/seed` accepts
|
|
11
|
+
* `fixtureModel: true` (the Tenant's model calls use the Runtime's fixture model).
|
|
12
|
+
*/
|
|
13
|
+
export const OPTIONAL_HOST_FEATURES = ["tenant-fixture-model"];
|
|
14
|
+
export const HOST_PROTOCOL = {
|
|
15
|
+
min: 2,
|
|
16
|
+
max: 2,
|
|
17
|
+
features: [...PROTOCOL_FEATURES, ...OPTIONAL_HOST_FEATURES],
|
|
18
|
+
};
|
|
3
19
|
export const DEFINITION_SCHEMA_VERSION = 2;
|
|
20
|
+
export const TENANT_HEADER = "Nylorun-Tenant";
|
|
21
|
+
export const PROTOCOL_HEADER = "Nylorun-Protocol";
|
|
22
|
+
export const ERROR_CODES = [
|
|
23
|
+
"not_found",
|
|
24
|
+
"protocol_unsupported",
|
|
25
|
+
"host_rejected",
|
|
26
|
+
"origin_rejected",
|
|
27
|
+
"unsupported_media_type",
|
|
28
|
+
"tenant_conflict",
|
|
29
|
+
"active_work",
|
|
30
|
+
"connection_missing",
|
|
31
|
+
"incompatible_host",
|
|
32
|
+
];
|
|
33
|
+
/** Crockford Base32 alphabet (lowercase); excludes i, l, o, u. */
|
|
34
|
+
const CROCKFORD = "0123456789abcdefghjkmnpqrstvwxyz";
|
|
35
|
+
export const TENANT_ID_PATTERN = /^tn_[0-9a-hjkmnp-tv-z]{26}$/;
|
|
36
|
+
export const PRINCIPAL_ID_PATTERN = /^pr_[0-9a-hjkmnp-tv-z]{26}$/;
|
|
37
|
+
export function isTenantId(value) {
|
|
38
|
+
return typeof value === "string" && TENANT_ID_PATTERN.test(value);
|
|
39
|
+
}
|
|
40
|
+
export function isPrincipalId(value) {
|
|
41
|
+
return typeof value === "string" && PRINCIPAL_ID_PATTERN.test(value);
|
|
42
|
+
}
|
|
43
|
+
function encodeTime(ms) {
|
|
44
|
+
let value = Math.floor(ms);
|
|
45
|
+
if (!Number.isFinite(value) || value < 0)
|
|
46
|
+
value = 0;
|
|
47
|
+
// ULID time component is 48 bits.
|
|
48
|
+
value = value % 2 ** 48;
|
|
49
|
+
let out = "";
|
|
50
|
+
for (let i = 0; i < 10; i++) {
|
|
51
|
+
out = CROCKFORD[value % 32] + out;
|
|
52
|
+
value = Math.floor(value / 32);
|
|
53
|
+
}
|
|
54
|
+
return out;
|
|
55
|
+
}
|
|
56
|
+
function encodeRandom() {
|
|
57
|
+
const bytes = new Uint8Array(10);
|
|
58
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
59
|
+
let out = "";
|
|
60
|
+
// 80 bits → 16 Crockford chars (5 bits each).
|
|
61
|
+
let buffer = 0;
|
|
62
|
+
let bits = 0;
|
|
63
|
+
for (const byte of bytes) {
|
|
64
|
+
buffer = (buffer << 8) | byte;
|
|
65
|
+
bits += 8;
|
|
66
|
+
while (bits >= 5) {
|
|
67
|
+
bits -= 5;
|
|
68
|
+
out += CROCKFORD[(buffer >> bits) & 31];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
let lastTime = -1;
|
|
74
|
+
let lastRandom = "";
|
|
75
|
+
function newPrefixedId(prefix, now) {
|
|
76
|
+
const ms = now ?? Date.now();
|
|
77
|
+
const time = encodeTime(ms);
|
|
78
|
+
let random = encodeRandom();
|
|
79
|
+
if (ms === lastTime && lastRandom !== "" && random <= lastRandom) {
|
|
80
|
+
random = incrementCrockford(lastRandom);
|
|
81
|
+
}
|
|
82
|
+
lastTime = ms;
|
|
83
|
+
lastRandom = random;
|
|
84
|
+
return `${prefix}${time}${random}`;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Lowercase Crockford ULID with `tn_` prefix; 48-bit time + 80-bit CSPRNG.
|
|
88
|
+
* Same-millisecond calls stay lexicographically monotonic by bumping the random
|
|
89
|
+
* component when the clock does not advance.
|
|
90
|
+
*/
|
|
91
|
+
export function newTenantId(now) {
|
|
92
|
+
return newPrefixedId("tn_", now);
|
|
93
|
+
}
|
|
94
|
+
/** Principal id: `pr_` + lowercase Crockford ULID (same generator as tenants). */
|
|
95
|
+
export function newPrincipalId(now) {
|
|
96
|
+
return newPrefixedId("pr_", now);
|
|
97
|
+
}
|
|
98
|
+
function parseSemVer(version) {
|
|
99
|
+
const match = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/.exec(version);
|
|
100
|
+
if (!match)
|
|
101
|
+
return null;
|
|
102
|
+
return {
|
|
103
|
+
major: Number(match[1]),
|
|
104
|
+
minor: Number(match[2]),
|
|
105
|
+
patch: Number(match[3]),
|
|
106
|
+
prerelease: match[4] ? match[4].split(".") : [],
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function compareIdentifiers(a, b) {
|
|
110
|
+
const aNum = /^\d+$/.test(a);
|
|
111
|
+
const bNum = /^\d+$/.test(b);
|
|
112
|
+
if (aNum && bNum) {
|
|
113
|
+
const aValue = BigInt(a);
|
|
114
|
+
const bValue = BigInt(b);
|
|
115
|
+
if (aValue < bValue)
|
|
116
|
+
return -1;
|
|
117
|
+
if (aValue > bValue)
|
|
118
|
+
return 1;
|
|
119
|
+
return 0;
|
|
120
|
+
}
|
|
121
|
+
if (aNum)
|
|
122
|
+
return -1;
|
|
123
|
+
if (bNum)
|
|
124
|
+
return 1;
|
|
125
|
+
if (a < b)
|
|
126
|
+
return -1;
|
|
127
|
+
if (a > b)
|
|
128
|
+
return 1;
|
|
129
|
+
return 0;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* SemVer 2.0 precedence, including prereleases. Build metadata is ignored.
|
|
133
|
+
* Returns -1 when a < b, 0 when equal, 1 when a > b.
|
|
134
|
+
*/
|
|
135
|
+
export function compareVersions(a, b) {
|
|
136
|
+
const left = parseSemVer(a);
|
|
137
|
+
const right = parseSemVer(b);
|
|
138
|
+
if (!left || !right) {
|
|
139
|
+
if (a === b)
|
|
140
|
+
return 0;
|
|
141
|
+
return a < b ? -1 : 1;
|
|
142
|
+
}
|
|
143
|
+
if (left.major !== right.major)
|
|
144
|
+
return left.major < right.major ? -1 : 1;
|
|
145
|
+
if (left.minor !== right.minor)
|
|
146
|
+
return left.minor < right.minor ? -1 : 1;
|
|
147
|
+
if (left.patch !== right.patch)
|
|
148
|
+
return left.patch < right.patch ? -1 : 1;
|
|
149
|
+
if (left.prerelease.length === 0 && right.prerelease.length === 0)
|
|
150
|
+
return 0;
|
|
151
|
+
if (left.prerelease.length === 0)
|
|
152
|
+
return 1;
|
|
153
|
+
if (right.prerelease.length === 0)
|
|
154
|
+
return -1;
|
|
155
|
+
const limit = Math.max(left.prerelease.length, right.prerelease.length);
|
|
156
|
+
for (let i = 0; i < limit; i++) {
|
|
157
|
+
const aId = left.prerelease[i];
|
|
158
|
+
const bId = right.prerelease[i];
|
|
159
|
+
if (aId === undefined)
|
|
160
|
+
return -1;
|
|
161
|
+
if (bId === undefined)
|
|
162
|
+
return 1;
|
|
163
|
+
const order = compareIdentifiers(aId, bId);
|
|
164
|
+
if (order !== 0)
|
|
165
|
+
return order;
|
|
166
|
+
}
|
|
167
|
+
return 0;
|
|
168
|
+
}
|
|
169
|
+
function incrementCrockford(value) {
|
|
170
|
+
const chars = [...value];
|
|
171
|
+
for (let i = chars.length - 1; i >= 0; i--) {
|
|
172
|
+
const index = CROCKFORD.indexOf(chars[i]);
|
|
173
|
+
if (index < 0)
|
|
174
|
+
continue;
|
|
175
|
+
if (index < 31) {
|
|
176
|
+
chars[i] = CROCKFORD[index + 1];
|
|
177
|
+
return chars.join("");
|
|
178
|
+
}
|
|
179
|
+
chars[i] = CROCKFORD[0];
|
|
180
|
+
}
|
|
181
|
+
return encodeRandom();
|
|
182
|
+
}
|
|
183
|
+
export function checkCompatibility(client, host) {
|
|
184
|
+
if (client.version < host.min || client.version > host.max) {
|
|
185
|
+
return { ok: false, reason: "version", client: client.version, host };
|
|
186
|
+
}
|
|
187
|
+
const advertised = new Set(host.features);
|
|
188
|
+
const missing = client.required.filter((feature) => !advertised.has(feature));
|
|
189
|
+
if (missing.length > 0) {
|
|
190
|
+
return { ok: false, reason: "feature", missing, host };
|
|
191
|
+
}
|
|
192
|
+
return { ok: true };
|
|
193
|
+
}
|