@powerhousedao/host-core 6.2.3-dev.82 → 6.2.3-dev.83
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{compound-YHuVvCFd.mjs → compound-GhJAA2dK.mjs} +13 -1
- package/dist/compound-GhJAA2dK.mjs.map +1 -0
- package/dist/compound-NxCal3db.d.mts.map +1 -1
- package/dist/{env-substitution-DBkqQ6sX.mjs → env-substitution-CN_oSVVY.mjs} +13 -1
- package/dist/env-substitution-CN_oSVVY.mjs.map +1 -0
- package/dist/host-schemas-DtKFmLd0.d.mts.map +1 -1
- package/dist/index.d.mts +18 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +123 -65
- package/dist/index.mjs.map +1 -1
- package/dist/projection.d.mts +5 -1
- package/dist/projection.d.mts.map +1 -1
- package/dist/projection.mjs +80 -63
- package/dist/projection.mjs.map +1 -1
- package/dist/runners/compound.mjs +1 -1
- package/dist/schema.mjs +1 -1
- package/package.json +3 -3
- package/dist/compound-YHuVvCFd.mjs.map +0 -1
- package/dist/env-substitution-DBkqQ6sX.mjs.map +0 -1
package/dist/projection.mjs
CHANGED
|
@@ -1,6 +1,82 @@
|
|
|
1
|
-
import { D as runnerKindSchema, G as tokenKeyOf, K as tokenSchema, M as TOKEN_ESCAPE_KEY, g as hostNameSchema, n as substituteBuiltinEnv, t as isBuiltinEnvName } from "./env-substitution-
|
|
1
|
+
import { D as runnerKindSchema, G as tokenKeyOf, K as tokenSchema, M as TOKEN_ESCAPE_KEY, g as hostNameSchema, n as substituteBuiltinEnv, t as isBuiltinEnvName } from "./env-substitution-CN_oSVVY.mjs";
|
|
2
|
+
import "@powerhousedao/shared/host-tokens";
|
|
2
3
|
import { z } from "zod";
|
|
4
|
+
//#region src/backend-projection.ts
|
|
5
|
+
function projectStorage(name, storage) {
|
|
6
|
+
switch (storage.kind) {
|
|
7
|
+
case "idb": return { kind: "idb" };
|
|
8
|
+
case "memory": return { kind: "memory" };
|
|
9
|
+
case "path":
|
|
10
|
+
if (!storage.dataDir) throw new Error(`Backend "${name}": storage kind "path" requires dataDir.`);
|
|
11
|
+
return {
|
|
12
|
+
kind: "path",
|
|
13
|
+
dataDir: storage.dataDir
|
|
14
|
+
};
|
|
15
|
+
case "postgres": throw new Error(`Backend "${name}": storage kind "postgres" is server-side only — a provisioned (in-process/worker) reactor cannot use it. Point a "remote" backend at the switchboard that owns that database instead.`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/** One backend → one descriptor. The protocol's featureFlags ride every
|
|
19
|
+
* descriptor (they are fleet consensus, not per-backend). A remote backend
|
|
20
|
+
* must carry remote.url — provision() requires it. */
|
|
21
|
+
function backendToDescriptor(name, backend, protocol) {
|
|
22
|
+
const descriptor = {
|
|
23
|
+
kind: backend.kind,
|
|
24
|
+
name
|
|
25
|
+
};
|
|
26
|
+
if (descriptor.kind === "remote") {
|
|
27
|
+
const url = backend.remote?.url;
|
|
28
|
+
if (!url) throw new Error(`Backend "${name}" is kind "remote" but has no remote.url — a remote descriptor attaches to an already-running reactor by URL.`);
|
|
29
|
+
descriptor.remote = { url };
|
|
30
|
+
return descriptor;
|
|
31
|
+
}
|
|
32
|
+
if (backend.storage) descriptor.storage = projectStorage(name, backend.storage);
|
|
33
|
+
if (backend.packages) descriptor.packages = backend.packages;
|
|
34
|
+
if (protocol?.featureFlags) descriptor.featureFlags = protocol.featureFlags;
|
|
35
|
+
return descriptor;
|
|
36
|
+
}
|
|
37
|
+
/** All named backends, in placement-primary-first order (the order a
|
|
38
|
+
* createReactorClients step would provision them). */
|
|
39
|
+
function backendsToDescriptors(reactor) {
|
|
40
|
+
const backends = reactor?.backends;
|
|
41
|
+
if (!backends) return [];
|
|
42
|
+
const names = Object.keys(backends);
|
|
43
|
+
const primary = reactor.placement?.primary;
|
|
44
|
+
return (primary && names.includes(primary) ? [primary, ...names.filter((n) => n !== primary)] : names).map((name) => backendToDescriptor(name, backends[name], reactor.protocol));
|
|
45
|
+
}
|
|
46
|
+
const LOCAL_KINDS = /* @__PURE__ */ new Set(["in-process", "worker"]);
|
|
47
|
+
/**
|
|
48
|
+
* Structural multi-reactor (phase 4): true when the block names BOTH a local
|
|
49
|
+
* backend (in-process/worker — the tab's own reactor) and a remote one. This
|
|
50
|
+
* is the shape Connect's routing client serves; a lone remote backend is an
|
|
51
|
+
* attach-only host (assistant/agent shape), not a routed tab.
|
|
52
|
+
*/
|
|
53
|
+
function isStructuralMultiReactor(reactor) {
|
|
54
|
+
const backends = reactor?.backends;
|
|
55
|
+
if (!backends) return false;
|
|
56
|
+
const kinds = Object.values(backends).map((b) => b.kind);
|
|
57
|
+
return kinds.some((k) => LOCAL_KINDS.has(k)) && kinds.some((k) => k === "remote");
|
|
58
|
+
}
|
|
59
|
+
/** The remote backends' drive addresses, placement order. */
|
|
60
|
+
function remoteBackendUrls(reactor) {
|
|
61
|
+
return backendsToDescriptors(reactor).filter((d) => d.kind === "remote").map((d) => d.remote?.url).filter((u) => typeof u === "string");
|
|
62
|
+
}
|
|
63
|
+
/** The remote backends by host key, placement order. */
|
|
64
|
+
function remoteBackends(reactor) {
|
|
65
|
+
return backendsToDescriptors(reactor).flatMap((d) => d.kind === "remote" && d.remote ? [{
|
|
66
|
+
name: d.name,
|
|
67
|
+
url: d.remote.url
|
|
68
|
+
}] : []);
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
3
71
|
//#region src/reactor-config.ts
|
|
72
|
+
/**
|
|
73
|
+
* The shared `reactor` host-config block and its projections onto the
|
|
74
|
+
* Switchboard config / Connect runtime config. Phase 2 of uniform-runners: makes
|
|
75
|
+
* the reactor block live through the bridge runners, BEFORE track R replaces
|
|
76
|
+
* the projection with reactor-monitor's provision(). The headline is
|
|
77
|
+
* single-sourced `reactor.protocol` — both projections read the same block, so
|
|
78
|
+
* client and server cannot diverge, and a contradicting pre-set env fails boot.
|
|
79
|
+
*/
|
|
4
80
|
/** The single primary backend for phase-2 projection (multi-backend routing is
|
|
5
81
|
* track R). Prefers placement.primary, else "main"/"local", else the first. */
|
|
6
82
|
function primaryBackend(reactor) {
|
|
@@ -69,7 +145,7 @@ function reactorClientMode(reactor) {
|
|
|
69
145
|
}
|
|
70
146
|
/** Project the reactor block onto the Connect runtime config: protocol →
|
|
71
147
|
* connect.reactor (same shape), backend topology → instance.reactorWorker
|
|
72
|
-
* (legacy)
|
|
148
|
+
* (legacy), instance.reactorClient and instance.remoteBackends,
|
|
73
149
|
* workflows → app.workflowsEnabled. */
|
|
74
150
|
function projectReactorToConnect(reactor) {
|
|
75
151
|
const connect = {};
|
|
@@ -78,7 +154,8 @@ function projectReactorToConnect(reactor) {
|
|
|
78
154
|
const mode = reactorClientMode(reactor);
|
|
79
155
|
if (backend?.kind !== void 0 || mode !== void 0) connect.instance = {
|
|
80
156
|
...backend?.kind !== void 0 ? { reactorWorker: backend.kind === "worker" } : {},
|
|
81
|
-
...mode !== void 0 ? { reactorClient: mode } : {}
|
|
157
|
+
...mode !== void 0 ? { reactorClient: mode } : {},
|
|
158
|
+
...mode === "router" || mode === "remote" ? { remoteBackends: remoteBackends(reactor) } : {}
|
|
82
159
|
};
|
|
83
160
|
if (reactor?.workflows !== void 0) connect.app = { workflowsEnabled: reactor.workflows };
|
|
84
161
|
return { connect };
|
|
@@ -106,66 +183,6 @@ function assertProtocolConsistency(protocol, env, hostFile = "the host file") {
|
|
|
106
183
|
if (conflict) throw new Error(conflict);
|
|
107
184
|
}
|
|
108
185
|
//#endregion
|
|
109
|
-
//#region src/backend-projection.ts
|
|
110
|
-
function projectStorage(name, storage) {
|
|
111
|
-
switch (storage.kind) {
|
|
112
|
-
case "idb": return { kind: "idb" };
|
|
113
|
-
case "memory": return { kind: "memory" };
|
|
114
|
-
case "path":
|
|
115
|
-
if (!storage.dataDir) throw new Error(`Backend "${name}": storage kind "path" requires dataDir.`);
|
|
116
|
-
return {
|
|
117
|
-
kind: "path",
|
|
118
|
-
dataDir: storage.dataDir
|
|
119
|
-
};
|
|
120
|
-
case "postgres": throw new Error(`Backend "${name}": storage kind "postgres" is server-side only — a provisioned (in-process/worker) reactor cannot use it. Point a "remote" backend at the switchboard that owns that database instead.`);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
/** One backend → one descriptor. The protocol's featureFlags ride every
|
|
124
|
-
* descriptor (they are fleet consensus, not per-backend). A remote backend
|
|
125
|
-
* must carry remote.url — provision() requires it. */
|
|
126
|
-
function backendToDescriptor(name, backend, protocol) {
|
|
127
|
-
const descriptor = {
|
|
128
|
-
kind: backend.kind,
|
|
129
|
-
name
|
|
130
|
-
};
|
|
131
|
-
if (descriptor.kind === "remote") {
|
|
132
|
-
const url = backend.remote?.url;
|
|
133
|
-
if (!url) throw new Error(`Backend "${name}" is kind "remote" but has no remote.url — a remote descriptor attaches to an already-running reactor by URL.`);
|
|
134
|
-
descriptor.remote = { url };
|
|
135
|
-
return descriptor;
|
|
136
|
-
}
|
|
137
|
-
if (backend.storage) descriptor.storage = projectStorage(name, backend.storage);
|
|
138
|
-
if (backend.packages) descriptor.packages = backend.packages;
|
|
139
|
-
if (protocol?.featureFlags) descriptor.featureFlags = protocol.featureFlags;
|
|
140
|
-
return descriptor;
|
|
141
|
-
}
|
|
142
|
-
/** All named backends, in placement-primary-first order (the order a
|
|
143
|
-
* createReactorClients step would provision them). */
|
|
144
|
-
function backendsToDescriptors(reactor) {
|
|
145
|
-
const backends = reactor?.backends;
|
|
146
|
-
if (!backends) return [];
|
|
147
|
-
const names = Object.keys(backends);
|
|
148
|
-
const primary = reactor.placement?.primary;
|
|
149
|
-
return (primary && names.includes(primary) ? [primary, ...names.filter((n) => n !== primary)] : names).map((name) => backendToDescriptor(name, backends[name], reactor.protocol));
|
|
150
|
-
}
|
|
151
|
-
const LOCAL_KINDS = /* @__PURE__ */ new Set(["in-process", "worker"]);
|
|
152
|
-
/**
|
|
153
|
-
* Structural multi-reactor (phase 4): true when the block names BOTH a local
|
|
154
|
-
* backend (in-process/worker — the tab's own reactor) and a remote one. This
|
|
155
|
-
* is the shape Connect's routing client serves; a lone remote backend is an
|
|
156
|
-
* attach-only host (assistant/agent shape), not a routed tab.
|
|
157
|
-
*/
|
|
158
|
-
function isStructuralMultiReactor(reactor) {
|
|
159
|
-
const backends = reactor?.backends;
|
|
160
|
-
if (!backends) return false;
|
|
161
|
-
const kinds = Object.values(backends).map((b) => b.kind);
|
|
162
|
-
return kinds.some((k) => LOCAL_KINDS.has(k)) && kinds.some((k) => k === "remote");
|
|
163
|
-
}
|
|
164
|
-
/** The remote backends' drive addresses, placement order. */
|
|
165
|
-
function remoteBackendUrls(reactor) {
|
|
166
|
-
return backendsToDescriptors(reactor).filter((d) => d.kind === "remote").map((d) => d.remote?.url).filter((u) => typeof u === "string");
|
|
167
|
-
}
|
|
168
|
-
//#endregion
|
|
169
186
|
//#region src/child-wrapper.ts
|
|
170
187
|
/** Generic compound rule: `reactor`/`config` replace, `runner` key-merges. */
|
|
171
188
|
function applyChildWrapper(base, wrapper) {
|