@nylorun/core 0.4.0-beta → 0.5.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.
Files changed (42) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/compatibility.d.ts +48 -1
  3. package/dist/compatibility.js +192 -1
  4. package/dist/contracts.d.ts +536 -19
  5. package/dist/contracts.js +399 -29
  6. package/dist/define.d.ts +4 -0
  7. package/dist/define.js +2 -0
  8. package/dist/definition/variant.d.ts +7 -0
  9. package/dist/definition/variant.js +87 -0
  10. package/dist/definition/workflow/build.d.ts +38 -0
  11. package/dist/definition/workflow/build.js +62 -0
  12. package/dist/definition/workflow/chain.d.ts +49 -0
  13. package/dist/definition/workflow/chain.js +41 -0
  14. package/dist/definition/workflow/diagnostics.d.ts +14 -0
  15. package/dist/definition/workflow/diagnostics.js +38 -0
  16. package/dist/definition/workflow/index.d.ts +18 -0
  17. package/dist/definition/workflow/index.js +10 -0
  18. package/dist/definition/workflow/loop.d.ts +54 -0
  19. package/dist/definition/workflow/loop.js +102 -0
  20. package/dist/definition/workflow/map.d.ts +17 -0
  21. package/dist/definition/workflow/map.js +46 -0
  22. package/dist/definition/workflow/parallel.d.ts +19 -0
  23. package/dist/definition/workflow/parallel.js +37 -0
  24. package/dist/definition/workflow/patch.d.ts +11 -0
  25. package/dist/definition/workflow/patch.js +45 -0
  26. package/dist/definition/workflow/runnable.d.ts +40 -0
  27. package/dist/definition/workflow/runnable.js +251 -0
  28. package/dist/definition/workflow/slot.d.ts +23 -0
  29. package/dist/definition/workflow/slot.js +16 -0
  30. package/dist/definition/workflow/switch.d.ts +26 -0
  31. package/dist/definition/workflow/switch.js +66 -0
  32. package/dist/definition/workflow/types.d.ts +25 -0
  33. package/dist/definition/workflow/types.js +7 -0
  34. package/dist/definition/workflow/verdict.d.ts +20 -0
  35. package/dist/definition/workflow/verdict.js +25 -0
  36. package/dist/index.d.ts +1 -0
  37. package/dist/types/observe.d.ts +64 -0
  38. package/dist/types/workflow.d.ts +106 -0
  39. package/dist/types/workflow.js +1 -0
  40. package/dist/utils/hash.d.ts +3 -2
  41. package/dist/utils/hash.js +1 -1
  42. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # @nylorun/core
2
2
 
3
+ ## 0.5.0-beta
4
+
5
+ ### Minor Changes
6
+
7
+ - c49efed: **Runtime Clients and Admin API (supporting packages).**
8
+
9
+ - **core:** `AdminStatusSchema`, Project-link schemas, `ERROR_CODES` (launcher codes include `platform_unsupported`, `launcher_failed`, `downgrade_refused`), `admin-status` feature, `newPrincipalId`, `compareVersions`.
10
+ - **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.
11
+ - **studio:** `nylorun-studio` binary; connects via `resolveConnection`; waits for `dev`; never calls Admin API or writes `.nylorun/`.
12
+
13
+ **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).
14
+
15
+ - 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.
16
+
17
+ - **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/*`.
18
+ - **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>-`.
19
+ - **agents:** `createClient({ url, key, tenant })`; Transport sends Tenant + protocol headers; `/health` compatibility cache; `IncompatibleRuntimeError` with upgrade remedies.
20
+ - **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.
21
+ - **studio:** `startStudio({ …, tenant: { id, name } })`; proxy forwards Tenant + protocol headers; UI shows Tenant name/short id.
22
+
23
+ - 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.
24
+
25
+ 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}/`.
26
+
3
27
  ## 0.4.0-beta
4
28
 
5
29
  ### Minor Changes
@@ -1,3 +1,50 @@
1
1
  export { hashManifest } from "./utils/hash.js";
2
- export declare const PROTOCOL_VERSION = 1;
2
+ export declare const PROTOCOL_VERSION = 2;
3
+ export declare const PROTOCOL_FEATURES: readonly ["runtime-tenants", "admin-status"];
4
+ export type ProtocolFeature = (typeof PROTOCOL_FEATURES)[number];
5
+ export interface ProtocolRange {
6
+ min: number;
7
+ max: number;
8
+ features: readonly string[];
9
+ }
10
+ export declare const HOST_PROTOCOL: ProtocolRange;
3
11
  export declare const DEFINITION_SCHEMA_VERSION = 2;
12
+ export declare const LAUNCHER_PROTOCOL = 1;
13
+ export declare const TENANT_HEADER = "Nylorun-Tenant";
14
+ export declare const PROTOCOL_HEADER = "Nylorun-Protocol";
15
+ 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", "platform_unsupported", "launcher_failed", "lock_timeout", "foreign_port", "host_unresponsive", "host_start_failed", "host_schema_newer", "host_format_newer", "downgrade_refused", "upgrade_failed"];
16
+ export type ErrorCode = (typeof ERROR_CODES)[number];
17
+ export declare const TENANT_ID_PATTERN: RegExp;
18
+ export declare const PRINCIPAL_ID_PATTERN: RegExp;
19
+ export declare function isTenantId(value: unknown): value is string;
20
+ export declare function isPrincipalId(value: unknown): value is string;
21
+ /**
22
+ * Lowercase Crockford ULID with `tn_` prefix; 48-bit time + 80-bit CSPRNG.
23
+ * Same-millisecond calls stay lexicographically monotonic by bumping the random
24
+ * component when the clock does not advance.
25
+ */
26
+ export declare function newTenantId(now?: number): string;
27
+ /** Principal id: `pr_` + lowercase Crockford ULID (same generator as tenants). */
28
+ export declare function newPrincipalId(now?: number): string;
29
+ /**
30
+ * SemVer 2.0 precedence, including prereleases. Build metadata is ignored.
31
+ * Returns -1 when a < b, 0 when equal, 1 when a > b.
32
+ */
33
+ export declare function compareVersions(a: string, b: string): -1 | 0 | 1;
34
+ export type Compatibility = {
35
+ ok: true;
36
+ } | {
37
+ ok: false;
38
+ reason: "version";
39
+ client: number;
40
+ host: ProtocolRange;
41
+ } | {
42
+ ok: false;
43
+ reason: "feature";
44
+ missing: readonly string[];
45
+ host: ProtocolRange;
46
+ };
47
+ export declare function checkCompatibility(client: {
48
+ version: number;
49
+ required: readonly string[];
50
+ }, host: ProtocolRange): Compatibility;
@@ -1,3 +1,194 @@
1
1
  export { hashManifest } from "./utils/hash.js";
2
- export const PROTOCOL_VERSION = 1;
2
+ export const PROTOCOL_VERSION = 2;
3
+ export const PROTOCOL_FEATURES = ["runtime-tenants", "admin-status"];
4
+ export const HOST_PROTOCOL = {
5
+ min: 2,
6
+ max: 2,
7
+ features: PROTOCOL_FEATURES,
8
+ };
3
9
  export const DEFINITION_SCHEMA_VERSION = 2;
10
+ export const LAUNCHER_PROTOCOL = 1;
11
+ export const TENANT_HEADER = "Nylorun-Tenant";
12
+ export const PROTOCOL_HEADER = "Nylorun-Protocol";
13
+ export const ERROR_CODES = [
14
+ "not_found",
15
+ "protocol_unsupported",
16
+ "host_rejected",
17
+ "origin_rejected",
18
+ "unsupported_media_type",
19
+ "tenant_conflict",
20
+ "active_work",
21
+ "connection_missing",
22
+ "incompatible_host",
23
+ "platform_unsupported",
24
+ "launcher_failed",
25
+ "lock_timeout",
26
+ "foreign_port",
27
+ "host_unresponsive",
28
+ "host_start_failed",
29
+ "host_schema_newer",
30
+ "host_format_newer",
31
+ "downgrade_refused",
32
+ "upgrade_failed",
33
+ ];
34
+ /** Crockford Base32 alphabet (lowercase); excludes i, l, o, u. */
35
+ const CROCKFORD = "0123456789abcdefghjkmnpqrstvwxyz";
36
+ export const TENANT_ID_PATTERN = /^tn_[0-9a-hjkmnp-tv-z]{26}$/;
37
+ export const PRINCIPAL_ID_PATTERN = /^pr_[0-9a-hjkmnp-tv-z]{26}$/;
38
+ export function isTenantId(value) {
39
+ return typeof value === "string" && TENANT_ID_PATTERN.test(value);
40
+ }
41
+ export function isPrincipalId(value) {
42
+ return typeof value === "string" && PRINCIPAL_ID_PATTERN.test(value);
43
+ }
44
+ function encodeTime(ms) {
45
+ let value = Math.floor(ms);
46
+ if (!Number.isFinite(value) || value < 0)
47
+ value = 0;
48
+ // ULID time component is 48 bits.
49
+ value = value % 2 ** 48;
50
+ let out = "";
51
+ for (let i = 0; i < 10; i++) {
52
+ out = CROCKFORD[value % 32] + out;
53
+ value = Math.floor(value / 32);
54
+ }
55
+ return out;
56
+ }
57
+ function encodeRandom() {
58
+ const bytes = new Uint8Array(10);
59
+ globalThis.crypto.getRandomValues(bytes);
60
+ let out = "";
61
+ // 80 bits → 16 Crockford chars (5 bits each).
62
+ let buffer = 0;
63
+ let bits = 0;
64
+ for (const byte of bytes) {
65
+ buffer = (buffer << 8) | byte;
66
+ bits += 8;
67
+ while (bits >= 5) {
68
+ bits -= 5;
69
+ out += CROCKFORD[(buffer >> bits) & 31];
70
+ }
71
+ }
72
+ return out;
73
+ }
74
+ let lastTime = -1;
75
+ let lastRandom = "";
76
+ function newPrefixedId(prefix, now) {
77
+ const ms = now ?? Date.now();
78
+ const time = encodeTime(ms);
79
+ let random = encodeRandom();
80
+ if (ms === lastTime && lastRandom !== "" && random <= lastRandom) {
81
+ random = incrementCrockford(lastRandom);
82
+ }
83
+ lastTime = ms;
84
+ lastRandom = random;
85
+ return `${prefix}${time}${random}`;
86
+ }
87
+ /**
88
+ * Lowercase Crockford ULID with `tn_` prefix; 48-bit time + 80-bit CSPRNG.
89
+ * Same-millisecond calls stay lexicographically monotonic by bumping the random
90
+ * component when the clock does not advance.
91
+ */
92
+ export function newTenantId(now) {
93
+ return newPrefixedId("tn_", now);
94
+ }
95
+ /** Principal id: `pr_` + lowercase Crockford ULID (same generator as tenants). */
96
+ export function newPrincipalId(now) {
97
+ return newPrefixedId("pr_", now);
98
+ }
99
+ function parseSemVer(version) {
100
+ 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);
101
+ if (!match)
102
+ return null;
103
+ return {
104
+ major: Number(match[1]),
105
+ minor: Number(match[2]),
106
+ patch: Number(match[3]),
107
+ prerelease: match[4] ? match[4].split(".") : [],
108
+ };
109
+ }
110
+ function compareIdentifiers(a, b) {
111
+ const aNum = /^\d+$/.test(a);
112
+ const bNum = /^\d+$/.test(b);
113
+ if (aNum && bNum) {
114
+ const aValue = BigInt(a);
115
+ const bValue = BigInt(b);
116
+ if (aValue < bValue)
117
+ return -1;
118
+ if (aValue > bValue)
119
+ return 1;
120
+ return 0;
121
+ }
122
+ if (aNum)
123
+ return -1;
124
+ if (bNum)
125
+ return 1;
126
+ if (a < b)
127
+ return -1;
128
+ if (a > b)
129
+ return 1;
130
+ return 0;
131
+ }
132
+ /**
133
+ * SemVer 2.0 precedence, including prereleases. Build metadata is ignored.
134
+ * Returns -1 when a < b, 0 when equal, 1 when a > b.
135
+ */
136
+ export function compareVersions(a, b) {
137
+ const left = parseSemVer(a);
138
+ const right = parseSemVer(b);
139
+ if (!left || !right) {
140
+ if (a === b)
141
+ return 0;
142
+ return a < b ? -1 : 1;
143
+ }
144
+ if (left.major !== right.major)
145
+ return left.major < right.major ? -1 : 1;
146
+ if (left.minor !== right.minor)
147
+ return left.minor < right.minor ? -1 : 1;
148
+ if (left.patch !== right.patch)
149
+ return left.patch < right.patch ? -1 : 1;
150
+ if (left.prerelease.length === 0 && right.prerelease.length === 0)
151
+ return 0;
152
+ if (left.prerelease.length === 0)
153
+ return 1;
154
+ if (right.prerelease.length === 0)
155
+ return -1;
156
+ const limit = Math.max(left.prerelease.length, right.prerelease.length);
157
+ for (let i = 0; i < limit; i++) {
158
+ const aId = left.prerelease[i];
159
+ const bId = right.prerelease[i];
160
+ if (aId === undefined)
161
+ return -1;
162
+ if (bId === undefined)
163
+ return 1;
164
+ const order = compareIdentifiers(aId, bId);
165
+ if (order !== 0)
166
+ return order;
167
+ }
168
+ return 0;
169
+ }
170
+ function incrementCrockford(value) {
171
+ const chars = [...value];
172
+ for (let i = chars.length - 1; i >= 0; i--) {
173
+ const index = CROCKFORD.indexOf(chars[i]);
174
+ if (index < 0)
175
+ continue;
176
+ if (index < 31) {
177
+ chars[i] = CROCKFORD[index + 1];
178
+ return chars.join("");
179
+ }
180
+ chars[i] = CROCKFORD[0];
181
+ }
182
+ return encodeRandom();
183
+ }
184
+ export function checkCompatibility(client, host) {
185
+ if (client.version < host.min || client.version > host.max) {
186
+ return { ok: false, reason: "version", client: client.version, host };
187
+ }
188
+ const advertised = new Set(host.features);
189
+ const missing = client.required.filter((feature) => !advertised.has(feature));
190
+ if (missing.length > 0) {
191
+ return { ok: false, reason: "feature", missing, host };
192
+ }
193
+ return { ok: true };
194
+ }