@powerhousedao/host-core 6.3.0-dev.9 → 6.4.0-next.1

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 (43) hide show
  1. package/dist/{compound-DKi56SSx.mjs → compound-BWLJ0KBw.mjs} +1617 -488
  2. package/dist/compound-BWLJ0KBw.mjs.map +1 -0
  3. package/dist/{compound-CBqPgk38.d.mts → compound-D2dh2VUh.d.mts} +332 -22
  4. package/dist/compound-D2dh2VUh.d.mts.map +1 -0
  5. package/dist/{env-substitution-C_fVirPh.d.mts → env-substitution-Ct39KFvA.d.mts} +7 -3
  6. package/dist/env-substitution-Ct39KFvA.d.mts.map +1 -0
  7. package/dist/{env-substitution-BXGohOGN.mjs → env-substitution-FJ5Nua4M.mjs} +29 -10
  8. package/dist/env-substitution-FJ5Nua4M.mjs.map +1 -0
  9. package/dist/{host-schemas-BM7F21lf.d.mts → host-schemas-B6_-P11_.d.mts} +52 -19
  10. package/dist/host-schemas-B6_-P11_.d.mts.map +1 -0
  11. package/dist/index.d.mts +196 -131
  12. package/dist/index.d.mts.map +1 -1
  13. package/dist/index.mjs +52 -356
  14. package/dist/index.mjs.map +1 -1
  15. package/dist/kill-tree.d.mts +8 -0
  16. package/dist/kill-tree.d.mts.map +1 -0
  17. package/dist/kill-tree.mjs +73 -0
  18. package/dist/kill-tree.mjs.map +1 -0
  19. package/dist/plugins-DP3YlIWx.mjs +309 -0
  20. package/dist/plugins-DP3YlIWx.mjs.map +1 -0
  21. package/dist/{plugins-Uk84BRay.d.mts → plugins-Dsmfhbn7.d.mts} +53 -3
  22. package/dist/plugins-Dsmfhbn7.d.mts.map +1 -0
  23. package/dist/plugins.d.mts +2 -2
  24. package/dist/plugins.mjs +2 -174
  25. package/dist/projection.d.mts +13 -19
  26. package/dist/projection.d.mts.map +1 -1
  27. package/dist/projection.mjs +18 -11
  28. package/dist/projection.mjs.map +1 -1
  29. package/dist/runners/compound.d.mts +9 -3
  30. package/dist/runners/compound.d.mts.map +1 -1
  31. package/dist/runners/compound.mjs +1 -1
  32. package/dist/schema.d.mts +6 -4
  33. package/dist/schema.d.mts.map +1 -1
  34. package/dist/schema.mjs +5 -4
  35. package/dist/schema.mjs.map +1 -1
  36. package/package.json +9 -3
  37. package/dist/compound-CBqPgk38.d.mts.map +0 -1
  38. package/dist/compound-DKi56SSx.mjs.map +0 -1
  39. package/dist/env-substitution-BXGohOGN.mjs.map +0 -1
  40. package/dist/env-substitution-C_fVirPh.d.mts.map +0 -1
  41. package/dist/host-schemas-BM7F21lf.d.mts.map +0 -1
  42. package/dist/plugins-Uk84BRay.d.mts.map +0 -1
  43. package/dist/plugins.mjs.map +0 -1
@@ -0,0 +1,309 @@
1
+ import { z } from "zod";
2
+ //#region src/connect-composition.ts
3
+ /**
4
+ * The connect config slices each built-in Connect plugin owns, by specifier
5
+ * (typed-host-configs 1.6). Under a declared composition Connect zeroes a
6
+ * slice whose plugin is absent — presence is activation — so an authored
7
+ * value there is dead config. Connect's built-ins are browser modules with no
8
+ * Node-resolvable identity, so their ownership is declared here as data; a
9
+ * Connect test pins it to plugin-host's zeroing.
10
+ */
11
+ const CONNECT_PLUGIN_OWNED_SLICES = {
12
+ "@powerhousedao/connect/plugins/generic": { slices: [
13
+ {
14
+ path: "drives.allowAddDrive",
15
+ absent: false,
16
+ entryKey: "allowAddDrive"
17
+ },
18
+ {
19
+ path: "drives.sections",
20
+ absent: {
21
+ remote: {
22
+ enabled: false,
23
+ allowAdd: false,
24
+ allowDelete: false
25
+ },
26
+ local: {
27
+ enabled: false,
28
+ allowAdd: false,
29
+ allowDelete: false
30
+ }
31
+ },
32
+ entryKey: "sections"
33
+ },
34
+ {
35
+ path: "drives.icons",
36
+ absent: null,
37
+ entryKey: "icons"
38
+ },
39
+ {
40
+ path: "home.background",
41
+ absent: null,
42
+ entryKey: "homeBackground"
43
+ }
44
+ ] },
45
+ "@powerhousedao/connect/plugins/sentry": { slices: [{
46
+ path: "sentry.dsn",
47
+ absent: null,
48
+ entryKey: "dsn"
49
+ }] },
50
+ "@powerhousedao/connect/plugins/openpanel": {
51
+ slices: [
52
+ {
53
+ path: "openPanel.clientId",
54
+ absent: "",
55
+ entryKey: "clientId"
56
+ },
57
+ {
58
+ path: "openPanel.trackUiEvents",
59
+ absent: false,
60
+ entryKey: "trackUiEvents"
61
+ },
62
+ {
63
+ path: "openPanel.trackOperations",
64
+ absent: false,
65
+ entryKey: "trackOperations"
66
+ }
67
+ ],
68
+ inertUnless: "openPanel.clientId"
69
+ },
70
+ "@powerhousedao/connect/plugins/assistant": { slices: [{
71
+ path: "ai.assistantEnabled",
72
+ absent: false
73
+ }] },
74
+ "@powerhousedao/vetra-studio/connect": { slices: [{
75
+ path: "app.studioMode",
76
+ absent: false
77
+ }] },
78
+ "@powerhousedao/connect/plugins/workflows": { slices: [{
79
+ path: "app.workflowsEnabled",
80
+ absent: false
81
+ }] }
82
+ };
83
+ function valueAt(root, dotted) {
84
+ let current = root;
85
+ for (const key of dotted.split(".")) {
86
+ if (current === null || typeof current !== "object") return void 0;
87
+ current = current[key];
88
+ }
89
+ return current;
90
+ }
91
+ /** Whether Connect already serves what the author wrote: every authored leaf
92
+ * equals the served one. An unset leaf asks for nothing, so a partial object
93
+ * (`sections: { remote: { enabled: false } }`) is satisfied by the zeroed
94
+ * slice. */
95
+ function alreadyServed(authored, served) {
96
+ if (authored === void 0 || Object.is(authored, served)) return true;
97
+ if (authored === null || served === null || typeof authored !== "object" || typeof served !== "object" || Array.isArray(authored) !== Array.isArray(served)) return false;
98
+ if (Array.isArray(authored) && authored.length !== served.length) return false;
99
+ const want = authored;
100
+ const have = served;
101
+ return Object.keys(want).every((key) => alreadyServed(want[key], have[key]));
102
+ }
103
+ /**
104
+ * The composition that serves `config` as it is written, for a host that
105
+ * declares no `runner.plugins`. `config` is the connect block Connect is
106
+ * served without a composition.
107
+ *
108
+ * A built-in configured through its entry is always in it, its entry holding
109
+ * the values `config` has at the slices it owns: composed in, the plugin
110
+ * serves those values again (an unset one falls back to the same default).
111
+ * A built-in whose presence is its switch is in it only where `config`
112
+ * already has that switch on, since composing it in would turn it on.
113
+ */
114
+ function defaultConnectComposition(config) {
115
+ const composition = [];
116
+ for (const [module, { slices }] of Object.entries(CONNECT_PLUGIN_OWNED_SLICES)) {
117
+ const entry = {};
118
+ let configured = false;
119
+ let switchedOn = false;
120
+ for (const { path: slicePath, absent, entryKey } of slices) {
121
+ const value = valueAt(config, slicePath);
122
+ if (entryKey === void 0) {
123
+ switchedOn ||= !alreadyServed(value, absent);
124
+ continue;
125
+ }
126
+ configured = true;
127
+ if (value !== void 0 && value !== null) entry[entryKey] = value;
128
+ }
129
+ if (configured || switchedOn) composition.push({
130
+ module,
131
+ config: entry
132
+ });
133
+ }
134
+ return composition;
135
+ }
136
+ //#endregion
137
+ //#region src/plugins.ts
138
+ /**
139
+ * R1 — the host plugin framework (bridge-runners-to-plugins plan,
140
+ * customization-references/host-core as the blueprint).
141
+ *
142
+ * A plugin is hooks + contributions; hooks are boot wiring (main realm only),
143
+ * contributions are declarative, serializable surface. Host RUNTIMES define
144
+ * the hook vocabulary and interleave their own wiring between stages — they
145
+ * are never plugins themselves.
146
+ *
147
+ * host.js carries the COMPOSITION as `runner.plugins` entries:
148
+ * string | { module, enabled?, verbs?, config? }
149
+ * Presence is activation (enabled defaults true); `verbs` scopes an entry to
150
+ * matching run verbs; `config` is validated against the plugin's declared
151
+ * zod schema. Entries resolve from the PROJECT's dependency tree exactly
152
+ * like runner modules.
153
+ */
154
+ var PluginError = class extends Error {
155
+ constructor(message, hint) {
156
+ super(hint ? `${message}\n Hint: ${hint}` : message);
157
+ this.name = "PluginError";
158
+ }
159
+ };
160
+ const pluginEntryObjectSchema = z.strictObject({
161
+ module: z.string().min(1),
162
+ /** Presence is activation BY DEFAULT; false is the explicit off-switch. */
163
+ enabled: z.boolean().optional(),
164
+ /** "*" (default) or the run verbs this entry is active for. */
165
+ verbs: z.union([z.literal("*"), z.array(z.string().min(1)).min(1)]).optional(),
166
+ /** Validated against the plugin's declared configSchema at resolution. */
167
+ config: z.record(z.string(), z.unknown()).optional()
168
+ });
169
+ const pluginEntrySchema = z.union([z.string().min(1), pluginEntryObjectSchema]);
170
+ function normalizePluginEntry(entry) {
171
+ if (typeof entry === "string") return {
172
+ module: entry,
173
+ enabled: true,
174
+ verbs: "*",
175
+ config: {}
176
+ };
177
+ return {
178
+ module: entry.module,
179
+ enabled: entry.enabled ?? true,
180
+ verbs: entry.verbs ?? "*",
181
+ config: entry.config ?? {}
182
+ };
183
+ }
184
+ /** Module is the identity key: a duplicate makes override targeting and
185
+ * ordering ambiguous, so it fails loudly. */
186
+ function normalizePluginEntries(entries, where) {
187
+ const normalized = entries.map(normalizePluginEntry);
188
+ const seen = /* @__PURE__ */ new Set();
189
+ for (const entry of normalized) {
190
+ if (seen.has(entry.module)) throw new PluginError(`${where}: plugin "${entry.module}" is listed twice.`, "Module specifiers are the identity key of a composition; a plugin meant to run twice needs distinct subpath specifiers.");
191
+ seen.add(entry.module);
192
+ }
193
+ return normalized;
194
+ }
195
+ function entryActiveForVerb(entry, verb) {
196
+ if (!entry.enabled) return false;
197
+ return entry.verbs === "*" || entry.verbs.includes(verb);
198
+ }
199
+ /**
200
+ * The appliesTo hierarchy. "reactor" is the base every reactor host extends;
201
+ * "compound" is its own branch (plugins over the member set — e.g. the clint
202
+ * proxy). Host runtimes register their id with a parent; compatibility walks
203
+ * the parent chain.
204
+ */
205
+ const HOST_TYPE_PARENTS = {
206
+ reactor: null,
207
+ compound: null,
208
+ connect: "reactor",
209
+ switchboard: "reactor",
210
+ mastra: "reactor"
211
+ };
212
+ function registerHostType(id, parent) {
213
+ if (id in HOST_TYPE_PARENTS && HOST_TYPE_PARENTS[id] !== parent) throw new PluginError(`Host type "${id}" is already registered with parent "${String(HOST_TYPE_PARENTS[id])}".`);
214
+ HOST_TYPE_PARENTS[id] = parent;
215
+ }
216
+ function hostTypeSatisfies(hostType, appliesTo) {
217
+ let current = hostType;
218
+ while (current !== null) {
219
+ if (current === appliesTo) return true;
220
+ current = current in HOST_TYPE_PARENTS ? HOST_TYPE_PARENTS[current] : null;
221
+ }
222
+ return false;
223
+ }
224
+ /** Registration order, bucketed pre → normal → post (stable within buckets),
225
+ * then dependsOn topo-sorted within the bucketed order. */
226
+ function resolveOrder(plugins) {
227
+ const buckets = {
228
+ pre: [],
229
+ normal: [],
230
+ post: []
231
+ };
232
+ for (const plugin of plugins) buckets[plugin.enforce ?? "normal"].push(plugin);
233
+ const bucketed = [
234
+ ...buckets.pre,
235
+ ...buckets.normal,
236
+ ...buckets.post
237
+ ];
238
+ const byName = new Map(bucketed.map((p) => [p.name, p]));
239
+ for (const plugin of bucketed) for (const dep of plugin.dependsOn ?? []) if (!byName.has(dep)) throw new PluginError(`Plugin "${plugin.name}" depends on missing plugin "${dep}".`, "dependsOn names PLUGINS only — the host runtime is implied and never named.");
240
+ const ordered = [];
241
+ const state = /* @__PURE__ */ new Map();
242
+ const visit = (plugin, chain) => {
243
+ const mark = state.get(plugin.name);
244
+ if (mark === "done") return;
245
+ if (mark === "visiting") throw new PluginError(`Plugin dependency cycle: ${[...chain, plugin.name].join(" -> ")}.`);
246
+ state.set(plugin.name, "visiting");
247
+ for (const dep of plugin.dependsOn ?? []) visit(byName.get(dep), [...chain, plugin.name]);
248
+ state.set(plugin.name, "done");
249
+ ordered.push(plugin);
250
+ };
251
+ for (const plugin of bucketed) visit(plugin, []);
252
+ return ordered;
253
+ }
254
+ async function runProvideHook(name, plugins, ctx) {
255
+ const impls = plugins.filter((p) => typeof p.hooks?.[name] === "function");
256
+ if (impls.length > 1) throw new PluginError(`Hook "${name}" is provided by ${impls.map((p) => `"${p.name}"`).join(" and ")} — provide hooks have one winner.`);
257
+ const impl = impls[0]?.hooks?.[name];
258
+ return impl ? await impl(ctx) : void 0;
259
+ }
260
+ async function runTransformHook(name, plugins, ctx, seed) {
261
+ let value = seed;
262
+ for (const plugin of plugins) {
263
+ const impl = plugin.hooks?.[name];
264
+ if (typeof impl === "function") value = await impl(value, ctx);
265
+ }
266
+ return value;
267
+ }
268
+ /** Sequential observe, in plugin order — for lifecycle moments whose order
269
+ * is load-bearing (teardown: the switchboard stops privacy before workflows
270
+ * before the api, per the carve map). */
271
+ async function runObserveHookSequential(name, plugins, ctx) {
272
+ for (const plugin of plugins) {
273
+ const impl = plugin.hooks?.[name];
274
+ if (typeof impl === "function") await impl(ctx);
275
+ }
276
+ }
277
+ async function runObserveHook(name, plugins, ctx) {
278
+ await Promise.all(plugins.map(async (plugin) => {
279
+ const impl = plugin.hooks?.[name];
280
+ if (typeof impl === "function") await impl(ctx);
281
+ }));
282
+ }
283
+ /** Array kinds concatenate in provenance-then-order sequence (built-in first,
284
+ * so later sources read as overrides where consumers want last-wins). */
285
+ function mergeContributions(resolved) {
286
+ const rank = {
287
+ "built-in": 0,
288
+ local: 1,
289
+ dependency: 2
290
+ };
291
+ const sorted = [...resolved].sort((a, b) => rank[a.provenance] - rank[b.provenance]);
292
+ const merged = {};
293
+ for (const { plugin, provenance } of sorted) for (const [kind, values] of Object.entries(plugin.contributions ?? {})) {
294
+ if (!values) continue;
295
+ const bucket = merged[kind] ??= [];
296
+ for (const value of values) bucket.push({
297
+ value,
298
+ source: {
299
+ pluginName: plugin.name,
300
+ provenance
301
+ }
302
+ });
303
+ }
304
+ return merged;
305
+ }
306
+ //#endregion
307
+ export { normalizePluginEntries as a, pluginEntrySchema as c, runObserveHook as d, runObserveHookSequential as f, defaultConnectComposition as g, CONNECT_PLUGIN_OWNED_SLICES as h, mergeContributions as i, registerHostType as l, runTransformHook as m, entryActiveForVerb as n, normalizePluginEntry as o, runProvideHook as p, hostTypeSatisfies as r, pluginEntryObjectSchema as s, PluginError as t, resolveOrder as u };
308
+
309
+ //# sourceMappingURL=plugins-DP3YlIWx.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugins-DP3YlIWx.mjs","names":[],"sources":["../src/connect-composition.ts","../src/plugins.ts"],"sourcesContent":["/**\n * The config slices Connect's built-in plugins own, and the composition a\n * Connect without a declared one boots from. Browser-safe: `ph run` (dev,\n * serve) and Connect's own runtime work the default out with the same\n * function.\n */\n\n/** One Connect config value a built-in Connect plugin owns. */\nexport interface OwnedConfigSlice {\n /** Dot path inside the connect config block, e.g. \"drives.allowAddDrive\". */\n path: string;\n /** What Connect serves at `path` while the owning plugin is absent from a\n * declared composition (apps/connect plugin-host.ts zeroAbsentSlices). */\n absent: unknown;\n /** The owning plugin's entry config key that sets this value, when the\n * plugin takes it as config; omitted where presence alone is the switch. */\n entryKey?: string;\n}\n\nexport interface ConnectPluginSlices {\n slices: OwnedConfigSlice[];\n /** A slice whose unset or `absent` value leaves every slice of this plugin\n * inert (OpenPanel tracking does nothing without a clientId), so nothing\n * of it is reported as dead. */\n inertUnless?: string;\n}\n\n/**\n * The connect config slices each built-in Connect plugin owns, by specifier\n * (typed-host-configs 1.6). Under a declared composition Connect zeroes a\n * slice whose plugin is absent — presence is activation — so an authored\n * value there is dead config. Connect's built-ins are browser modules with no\n * Node-resolvable identity, so their ownership is declared here as data; a\n * Connect test pins it to plugin-host's zeroing.\n */\nexport const CONNECT_PLUGIN_OWNED_SLICES: Readonly<\n Record<string, ConnectPluginSlices>\n> = {\n \"@powerhousedao/connect/plugins/generic\": {\n slices: [\n {\n path: \"drives.allowAddDrive\",\n absent: false,\n entryKey: \"allowAddDrive\",\n },\n {\n path: \"drives.sections\",\n absent: {\n remote: { enabled: false, allowAdd: false, allowDelete: false },\n local: { enabled: false, allowAdd: false, allowDelete: false },\n },\n entryKey: \"sections\",\n },\n { path: \"drives.icons\", absent: null, entryKey: \"icons\" },\n { path: \"home.background\", absent: null, entryKey: \"homeBackground\" },\n ],\n },\n \"@powerhousedao/connect/plugins/sentry\": {\n slices: [{ path: \"sentry.dsn\", absent: null, entryKey: \"dsn\" }],\n },\n \"@powerhousedao/connect/plugins/openpanel\": {\n slices: [\n { path: \"openPanel.clientId\", absent: \"\", entryKey: \"clientId\" },\n {\n path: \"openPanel.trackUiEvents\",\n absent: false,\n entryKey: \"trackUiEvents\",\n },\n {\n path: \"openPanel.trackOperations\",\n absent: false,\n entryKey: \"trackOperations\",\n },\n ],\n inertUnless: \"openPanel.clientId\",\n },\n \"@powerhousedao/connect/plugins/assistant\": {\n slices: [{ path: \"ai.assistantEnabled\", absent: false }],\n },\n \"@powerhousedao/vetra-studio/connect\": {\n slices: [{ path: \"app.studioMode\", absent: false }],\n },\n \"@powerhousedao/connect/plugins/workflows\": {\n slices: [{ path: \"app.workflowsEnabled\", absent: false }],\n },\n};\n\nexport function valueAt(root: unknown, dotted: string): unknown {\n let current = root;\n for (const key of dotted.split(\".\")) {\n if (current === null || typeof current !== \"object\") return undefined;\n current = (current as Record<string, unknown>)[key];\n }\n return current;\n}\n\n/** Whether Connect already serves what the author wrote: every authored leaf\n * equals the served one. An unset leaf asks for nothing, so a partial object\n * (`sections: { remote: { enabled: false } }`) is satisfied by the zeroed\n * slice. */\nexport function alreadyServed(authored: unknown, served: unknown): boolean {\n if (authored === undefined || Object.is(authored, served)) return true;\n if (\n authored === null ||\n served === null ||\n typeof authored !== \"object\" ||\n typeof served !== \"object\" ||\n Array.isArray(authored) !== Array.isArray(served)\n ) {\n return false;\n }\n if (\n Array.isArray(authored) &&\n authored.length !== (served as unknown[]).length\n ) {\n return false;\n }\n const want = authored as Record<string, unknown>;\n const have = served as Record<string, unknown>;\n return Object.keys(want).every((key) => alreadyServed(want[key], have[key]));\n}\n\n/**\n * The composition that serves `config` as it is written, for a host that\n * declares no `runner.plugins`. `config` is the connect block Connect is\n * served without a composition.\n *\n * A built-in configured through its entry is always in it, its entry holding\n * the values `config` has at the slices it owns: composed in, the plugin\n * serves those values again (an unset one falls back to the same default).\n * A built-in whose presence is its switch is in it only where `config`\n * already has that switch on, since composing it in would turn it on.\n */\nexport function defaultConnectComposition(\n config: Record<string, unknown> | undefined,\n): { module: string; config: Record<string, unknown> }[] {\n const composition: { module: string; config: Record<string, unknown> }[] = [];\n for (const [module, { slices }] of Object.entries(\n CONNECT_PLUGIN_OWNED_SLICES,\n )) {\n const entry: Record<string, unknown> = {};\n let configured = false;\n let switchedOn = false;\n for (const { path: slicePath, absent, entryKey } of slices) {\n const value = valueAt(config, slicePath);\n if (entryKey === undefined) {\n switchedOn ||= !alreadyServed(value, absent);\n continue;\n }\n configured = true;\n if (value !== undefined && value !== null) entry[entryKey] = value;\n }\n if (configured || switchedOn) composition.push({ module, config: entry });\n }\n return composition;\n}\n","import { z } from \"zod\";\n\n/**\n * R1 — the host plugin framework (bridge-runners-to-plugins plan,\n * customization-references/host-core as the blueprint).\n *\n * A plugin is hooks + contributions; hooks are boot wiring (main realm only),\n * contributions are declarative, serializable surface. Host RUNTIMES define\n * the hook vocabulary and interleave their own wiring between stages — they\n * are never plugins themselves.\n *\n * host.js carries the COMPOSITION as `runner.plugins` entries:\n * string | { module, enabled?, verbs?, config? }\n * Presence is activation (enabled defaults true); `verbs` scopes an entry to\n * matching run verbs; `config` is validated against the plugin's declared\n * zod schema. Entries resolve from the PROJECT's dependency tree exactly\n * like runner modules.\n */\n\nexport class PluginError extends Error {\n constructor(message: string, hint?: string) {\n super(hint ? `${message}\\n Hint: ${hint}` : message);\n this.name = \"PluginError\";\n }\n}\n\n/* ------------------------------------------------------------------ entries */\n\nexport const pluginEntryObjectSchema = z.strictObject({\n module: z.string().min(1),\n /** Presence is activation BY DEFAULT; false is the explicit off-switch. */\n enabled: z.boolean().optional(),\n /** \"*\" (default) or the run verbs this entry is active for. */\n verbs: z\n .union([z.literal(\"*\"), z.array(z.string().min(1)).min(1)])\n .optional(),\n /** Validated against the plugin's declared configSchema at resolution. */\n config: z.record(z.string(), z.unknown()).optional(),\n});\n\nexport const pluginEntrySchema = z.union([\n z.string().min(1),\n pluginEntryObjectSchema,\n]);\n\n/** The validated (runtime) entry shape. Authors write `PluginEntry`\n * (host-types.ts), which types known plugins' configs. */\nexport type PluginEntryData = z.infer<typeof pluginEntrySchema>;\nexport type { PluginEntry } from \"./host-types.js\";\n\nexport interface NormalizedPluginEntry {\n module: string;\n enabled: boolean;\n verbs: \"*\" | string[];\n config: Record<string, unknown>;\n}\n\nexport function normalizePluginEntry(\n entry: PluginEntryData,\n): NormalizedPluginEntry {\n if (typeof entry === \"string\") {\n return { module: entry, enabled: true, verbs: \"*\", config: {} };\n }\n return {\n module: entry.module,\n enabled: entry.enabled ?? true,\n verbs: entry.verbs ?? \"*\",\n config: entry.config ?? {},\n };\n}\n\n/** Module is the identity key: a duplicate makes override targeting and\n * ordering ambiguous, so it fails loudly. */\nexport function normalizePluginEntries(\n entries: readonly PluginEntryData[],\n where: string,\n): NormalizedPluginEntry[] {\n const normalized = entries.map(normalizePluginEntry);\n const seen = new Set<string>();\n for (const entry of normalized) {\n if (seen.has(entry.module)) {\n throw new PluginError(\n `${where}: plugin \"${entry.module}\" is listed twice.`,\n \"Module specifiers are the identity key of a composition; a plugin meant to run twice needs distinct subpath specifiers.\",\n );\n }\n seen.add(entry.module);\n }\n return normalized;\n}\n\nexport function entryActiveForVerb(\n entry: NormalizedPluginEntry,\n verb: string,\n): boolean {\n if (!entry.enabled) return false;\n return entry.verbs === \"*\" || entry.verbs.includes(verb);\n}\n\n/* ---------------------------------------------------------------- hierarchy */\n\n/**\n * The appliesTo hierarchy. \"reactor\" is the base every reactor host extends;\n * \"compound\" is its own branch (plugins over the member set — e.g. the clint\n * proxy). Host runtimes register their id with a parent; compatibility walks\n * the parent chain.\n */\nconst HOST_TYPE_PARENTS: Record<string, string | null> = {\n reactor: null,\n compound: null,\n connect: \"reactor\",\n switchboard: \"reactor\",\n mastra: \"reactor\",\n};\n\nexport function registerHostType(id: string, parent: string | null): void {\n if (id in HOST_TYPE_PARENTS && HOST_TYPE_PARENTS[id] !== parent) {\n throw new PluginError(\n `Host type \"${id}\" is already registered with parent \"${String(HOST_TYPE_PARENTS[id])}\".`,\n );\n }\n HOST_TYPE_PARENTS[id] = parent;\n}\n\nexport function hostTypeSatisfies(\n hostType: string,\n appliesTo: string,\n): boolean {\n let current: string | null = hostType;\n while (current !== null) {\n if (current === appliesTo) return true;\n current = current in HOST_TYPE_PARENTS ? HOST_TYPE_PARENTS[current] : null;\n }\n return false;\n}\n\n/* ------------------------------------------------------------------- plugin */\n\n/** Hook kinds (v1 §2.2). The hook VOCABULARY is defined by host runtimes;\n * plugins implement subsets of it. */\nexport type Provide<T, C> = (ctx: C) => T | Promise<T>;\nexport type Transform<T, C> = (value: T, ctx: C) => T | Promise<T>;\nexport type Observe<C> = (ctx: C) => void | Promise<void>;\n\n/**\n * Core contributions — declarative, serializable, realm-crossing. Host\n * runtimes extend this with their own kinds (UI slots live in connect-host,\n * never here). `drives` entries use the drive declaration shape from\n * drives.ts; kept as unknown here to avoid a cycle — the merge is shape-blind.\n */\nexport interface Contributions {\n drives?: unknown[];\n packages?: string[];\n configDeclarations?: { name: string; type?: string; description?: string }[];\n [kind: string]: unknown[] | undefined;\n}\n\nexport interface HostPlugin<\n THooks = Record<string, unknown>,\n TConfig = unknown,\n> {\n /** Stable id; used in ordering, dependsOn, and every diagnostic. */\n name: string;\n /** Host-type requirement; the entry is rejected on a host outside the\n * hierarchy branch. Default: \"reactor\". */\n appliesTo?: string;\n /** Coarse ordering bucket (Vite-style). Default: \"normal\". */\n enforce?: \"pre\" | \"post\";\n /** Hard dependencies on OTHER PLUGINS — the host runtime is implied and\n * never named. Missing dependency or cycle fails boot naming both sides. */\n dependsOn?: string[];\n /** Declared config shape; entry config is validated against it. A plugin\n * without a schema accepts no config (passing one is a boot error). */\n configSchema?: z.ZodType<TConfig>;\n hooks?: Partial<THooks>;\n contributions?: Contributions;\n}\n\n/** A plugin module default-exports either a HostPlugin object (no config\n * accepted) or a factory `(config) => HostPlugin`. */\nexport type HostPluginModule<\n THooks = Record<string, unknown>,\n TConfig = unknown,\n> =\n | HostPlugin<THooks, TConfig>\n | ((config: TConfig) => HostPlugin<THooks, TConfig>);\n\nexport interface ResolvedPlugin<THooks = Record<string, unknown>> {\n entry: NormalizedPluginEntry;\n plugin: HostPlugin<THooks>;\n /** Provenance for contribution merge ordering. */\n provenance: \"built-in\" | \"local\" | \"dependency\";\n}\n\n/* ----------------------------------------------------------------- ordering */\n\n/** Registration order, bucketed pre → normal → post (stable within buckets),\n * then dependsOn topo-sorted within the bucketed order. */\nexport function resolveOrder<THooks>(\n plugins: readonly HostPlugin<THooks>[],\n): HostPlugin<THooks>[] {\n const buckets: Record<\"pre\" | \"normal\" | \"post\", HostPlugin<THooks>[]> = {\n pre: [],\n normal: [],\n post: [],\n };\n for (const plugin of plugins)\n buckets[plugin.enforce ?? \"normal\"].push(plugin);\n const bucketed = [...buckets.pre, ...buckets.normal, ...buckets.post];\n\n const byName = new Map(bucketed.map((p) => [p.name, p]));\n for (const plugin of bucketed) {\n for (const dep of plugin.dependsOn ?? []) {\n if (!byName.has(dep)) {\n throw new PluginError(\n `Plugin \"${plugin.name}\" depends on missing plugin \"${dep}\".`,\n \"dependsOn names PLUGINS only — the host runtime is implied and never named.\",\n );\n }\n }\n }\n\n const ordered: HostPlugin<THooks>[] = [];\n const state = new Map<string, \"visiting\" | \"done\">();\n const visit = (plugin: HostPlugin<THooks>, chain: string[]): void => {\n const mark = state.get(plugin.name);\n if (mark === \"done\") return;\n if (mark === \"visiting\") {\n throw new PluginError(\n `Plugin dependency cycle: ${[...chain, plugin.name].join(\" -> \")}.`,\n );\n }\n state.set(plugin.name, \"visiting\");\n for (const dep of plugin.dependsOn ?? []) {\n visit(byName.get(dep)!, [...chain, plugin.name]);\n }\n state.set(plugin.name, \"done\");\n ordered.push(plugin);\n };\n for (const plugin of bucketed) visit(plugin, []);\n return ordered;\n}\n\n/* -------------------------------------------------------------------- hooks */\n\nexport async function runProvideHook<T, C>(\n name: string,\n plugins: readonly HostPlugin[],\n ctx: C,\n): Promise<T | undefined> {\n const impls = plugins.filter((p) => typeof p.hooks?.[name] === \"function\");\n if (impls.length > 1) {\n throw new PluginError(\n `Hook \"${name}\" is provided by ${impls.map((p) => `\"${p.name}\"`).join(\" and \")} — provide hooks have one winner.`,\n );\n }\n const impl = impls[0]?.hooks?.[name] as Provide<T, C> | undefined;\n return impl ? await impl(ctx) : undefined;\n}\n\nexport async function runTransformHook<T, C>(\n name: string,\n plugins: readonly HostPlugin[],\n ctx: C,\n seed: T,\n): Promise<T> {\n let value = seed;\n for (const plugin of plugins) {\n const impl = plugin.hooks?.[name] as Transform<T, C> | undefined;\n if (typeof impl === \"function\") value = await impl(value, ctx);\n }\n return value;\n}\n\n/** Sequential observe, in plugin order — for lifecycle moments whose order\n * is load-bearing (teardown: the switchboard stops privacy before workflows\n * before the api, per the carve map). */\nexport async function runObserveHookSequential<C>(\n name: string,\n plugins: readonly HostPlugin[],\n ctx: C,\n): Promise<void> {\n for (const plugin of plugins) {\n const impl = plugin.hooks?.[name] as Observe<C> | undefined;\n if (typeof impl === \"function\") await impl(ctx);\n }\n}\n\nexport async function runObserveHook<C>(\n name: string,\n plugins: readonly HostPlugin[],\n ctx: C,\n): Promise<void> {\n await Promise.all(\n plugins.map(async (plugin) => {\n const impl = plugin.hooks?.[name] as Observe<C> | undefined;\n if (typeof impl === \"function\") await impl(ctx);\n }),\n );\n}\n\n/* ------------------------------------------------------------ contributions */\n\nexport interface ContributionSource {\n pluginName: string;\n provenance: \"built-in\" | \"local\" | \"dependency\";\n}\n\nexport interface MergedContribution<T = unknown> {\n value: T;\n source: ContributionSource;\n}\n\n/** Array kinds concatenate in provenance-then-order sequence (built-in first,\n * so later sources read as overrides where consumers want last-wins). */\nexport function mergeContributions(\n resolved: readonly {\n plugin: HostPlugin;\n provenance: ContributionSource[\"provenance\"];\n }[],\n): Record<string, MergedContribution[]> {\n const rank: Record<ContributionSource[\"provenance\"], number> = {\n \"built-in\": 0,\n local: 1,\n dependency: 2,\n };\n const sorted = [...resolved].sort(\n (a, b) => rank[a.provenance] - rank[b.provenance],\n );\n const merged: Record<string, MergedContribution[]> = {};\n for (const { plugin, provenance } of sorted) {\n for (const [kind, values] of Object.entries(plugin.contributions ?? {})) {\n if (!values) continue;\n const bucket = (merged[kind] ??= []);\n for (const value of values) {\n bucket.push({ value, source: { pluginName: plugin.name, provenance } });\n }\n }\n }\n return merged;\n}\n\n// The default Connect composition is worked out in the browser too.\nexport {\n CONNECT_PLUGIN_OWNED_SLICES,\n defaultConnectComposition,\n type ConnectPluginSlices,\n type OwnedConfigSlice,\n} from \"./connect-composition.js\";\n"],"mappings":";;;;;;;;;;AAmCA,MAAa,8BAET;CACF,0CAA0C,EACxC,QAAQ;EACN;GACE,MAAM;GACN,QAAQ;GACR,UAAU;EACZ;EACA;GACE,MAAM;GACN,QAAQ;IACN,QAAQ;KAAE,SAAS;KAAO,UAAU;KAAO,aAAa;IAAM;IAC9D,OAAO;KAAE,SAAS;KAAO,UAAU;KAAO,aAAa;IAAM;GAC/D;GACA,UAAU;EACZ;EACA;GAAE,MAAM;GAAgB,QAAQ;GAAM,UAAU;EAAQ;EACxD;GAAE,MAAM;GAAmB,QAAQ;GAAM,UAAU;EAAiB;CACtE,EACF;CACA,yCAAyC,EACvC,QAAQ,CAAC;EAAE,MAAM;EAAc,QAAQ;EAAM,UAAU;CAAM,CAAC,EAChE;CACA,4CAA4C;EAC1C,QAAQ;GACN;IAAE,MAAM;IAAsB,QAAQ;IAAI,UAAU;GAAW;GAC/D;IACE,MAAM;IACN,QAAQ;IACR,UAAU;GACZ;GACA;IACE,MAAM;IACN,QAAQ;IACR,UAAU;GACZ;EACF;EACA,aAAa;CACf;CACA,4CAA4C,EAC1C,QAAQ,CAAC;EAAE,MAAM;EAAuB,QAAQ;CAAM,CAAC,EACzD;CACA,uCAAuC,EACrC,QAAQ,CAAC;EAAE,MAAM;EAAkB,QAAQ;CAAM,CAAC,EACpD;CACA,4CAA4C,EAC1C,QAAQ,CAAC;EAAE,MAAM;EAAwB,QAAQ;CAAM,CAAC,EAC1D;AACF;AAEA,SAAgB,QAAQ,MAAe,QAAyB;CAC9D,IAAI,UAAU;CACd,KAAK,MAAM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G,QAAQ,CAAC,CAAC,MAC1B,GAAG,MAAM,KAAK,EAAE,cAAc,KAAK,EAAE,WACxC;CACA,MAAM,SAA+C,CAAC;CACtD,KAAK,MAAM,EAAE,QAAQ,gBAAgB,QACnC,KAAK,MAAM,CAAC,MAAM,WAAW,OAAO,QAAQ,OAAO,iBAAiB,CAAC,CAAC,GAAG;EACvE,IAAI,CAAC,QAAQ;EACb,MAAM,SAAU,OAAO,UAAU,CAAC;EAClC,KAAK,MAAM,SAAS,QAClB,OAAO,KAAK;GAAE;GAAO,QAAQ;IAAE,YAAY,OAAO;IAAM;GAAW;EAAE,CAAC;CAE1E;CAEF,OAAO;AACT"}
@@ -1,4 +1,4 @@
1
- import { k as declaredGenericCompoundHostSchema } from "./host-schemas-BM7F21lf.mjs";
1
+ import { A as declaredGenericCompoundHostSchema } from "./host-schemas-B6_-P11_.mjs";
2
2
  import { z } from "zod";
3
3
  //#region src/host-types.d.ts
4
4
  declare global {
@@ -57,6 +57,56 @@ declare global {
57
57
  }
58
58
  }
59
59
  //#endregion
60
+ //#region src/connect-composition.d.ts
61
+ /**
62
+ * The config slices Connect's built-in plugins own, and the composition a
63
+ * Connect without a declared one boots from. Browser-safe: `ph run` (dev,
64
+ * serve) and Connect's own runtime work the default out with the same
65
+ * function.
66
+ */
67
+ /** One Connect config value a built-in Connect plugin owns. */
68
+ interface OwnedConfigSlice {
69
+ /** Dot path inside the connect config block, e.g. "drives.allowAddDrive". */
70
+ path: string;
71
+ /** What Connect serves at `path` while the owning plugin is absent from a
72
+ * declared composition (apps/connect plugin-host.ts zeroAbsentSlices). */
73
+ absent: unknown;
74
+ /** The owning plugin's entry config key that sets this value, when the
75
+ * plugin takes it as config; omitted where presence alone is the switch. */
76
+ entryKey?: string;
77
+ }
78
+ interface ConnectPluginSlices {
79
+ slices: OwnedConfigSlice[];
80
+ /** A slice whose unset or `absent` value leaves every slice of this plugin
81
+ * inert (OpenPanel tracking does nothing without a clientId), so nothing
82
+ * of it is reported as dead. */
83
+ inertUnless?: string;
84
+ }
85
+ /**
86
+ * The connect config slices each built-in Connect plugin owns, by specifier
87
+ * (typed-host-configs 1.6). Under a declared composition Connect zeroes a
88
+ * slice whose plugin is absent — presence is activation — so an authored
89
+ * value there is dead config. Connect's built-ins are browser modules with no
90
+ * Node-resolvable identity, so their ownership is declared here as data; a
91
+ * Connect test pins it to plugin-host's zeroing.
92
+ */
93
+ declare const CONNECT_PLUGIN_OWNED_SLICES: Readonly<Record<string, ConnectPluginSlices>>;
94
+ /**
95
+ * The composition that serves `config` as it is written, for a host that
96
+ * declares no `runner.plugins`. `config` is the connect block Connect is
97
+ * served without a composition.
98
+ *
99
+ * A built-in configured through its entry is always in it, its entry holding
100
+ * the values `config` has at the slices it owns: composed in, the plugin
101
+ * serves those values again (an unset one falls back to the same default).
102
+ * A built-in whose presence is its switch is in it only where `config`
103
+ * already has that switch on, since composing it in would turn it on.
104
+ */
105
+ declare function defaultConnectComposition(config: Record<string, unknown> | undefined): {
106
+ module: string;
107
+ config: Record<string, unknown>;
108
+ }[];
109
+ //#endregion
60
110
  //#region src/plugins.d.ts
61
111
  /**
62
112
  * R1 — the host plugin framework (bridge-runners-to-plugins plan,
@@ -177,6 +227,6 @@ declare function mergeContributions(resolved: readonly {
177
227
  provenance: ContributionSource["provenance"];
178
228
  }[]): Record<string, MergedContribution[]>;
179
229
  //#endregion
180
- export { runObserveHookSequential as C, PHHostOutputs as D, PHHost as E, PluginEntry as O, runObserveHook as S, runTransformHook as T, normalizePluginEntry as _, MergedContribution as a, registerHostType as b, PluginEntryData as c, ResolvedPlugin as d, Transform as f, normalizePluginEntries as g, mergeContributions as h, HostPluginModule as i, PluginError as l, hostTypeSatisfies as m, Contributions as n, NormalizedPluginEntry as o, entryActiveForVerb as p, HostPlugin as r, Observe as s, ContributionSource as t, Provide as u, pluginEntryObjectSchema as v, runProvideHook as w, resolveOrder as x, pluginEntrySchema as y };
230
+ export { PHHost as A, runObserveHookSequential as C, ConnectPluginSlices as D, CONNECT_PLUGIN_OWNED_SLICES as E, PluginEntry as M, OwnedConfigSlice as O, runObserveHook as S, runTransformHook as T, normalizePluginEntry as _, MergedContribution as a, registerHostType as b, PluginEntryData as c, ResolvedPlugin as d, Transform as f, normalizePluginEntries as g, mergeContributions as h, HostPluginModule as i, PHHostOutputs as j, defaultConnectComposition as k, PluginError as l, hostTypeSatisfies as m, Contributions as n, NormalizedPluginEntry as o, entryActiveForVerb as p, HostPlugin as r, Observe as s, ContributionSource as t, Provide as u, pluginEntryObjectSchema as v, runProvideHook as w, resolveOrder as x, pluginEntrySchema as y };
181
231
  export {};
182
- //# sourceMappingURL=plugins-Uk84BRay.d.mts.map
232
+ //# sourceMappingURL=plugins-Dsmfhbn7.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugins-Dsmfhbn7.d.mts","names":[],"sources":["../src/host-types.ts","../src/connect-composition.ts","../src/plugins.ts"],"mappings":";;;QAUQ;;;YAII;;YAGA;;KAMP,wBAAwB;KAExB,wBAAwB;;;;KAKxB,iBAAiB,GAAG,oBAAoB;EAAY,cAAc;IACnE,KAAK;EACH,QAAQ,KAAK;IACX,QAAQ;IACR,UAAU;;;;;KAON,YACT,KAAK,kBAAkB,cAAc;EAAa,YAAY;IAC3D,iBAAiB,GAAG,cAExB;;KAGU,cAAc,UAAU,mBAClC,cAAc;EAAa,eAAe;IAAM;UAExC,kBAAkB,kBAAkB;EAC5C,QAAQ;;EAER;;EAEA;EACA,SAAS;;KAGN,sBACF,KAAK,kBAAkB,IAAI,kBAAkB,GAAG,gBAAgB,OACjE;;;;;;;;;KAUU,cAEV,4BAA4B;QAKtB;YACI;IACR;MACE,MAAM,EAAE,aAAa;MACrB,SAAS;;;;;;;;;;;;;UC3EE;;EAEf;;;EAGA;;;EAGA;;UAGe;EACf,QAAQ;;;;EAIR;;;;;;;;;;cAWW,6BAA6B,SACxC,eAAe;;;;;;;;;;;;iBAiGD,0BACd,QAAQ;EACL;EAAgB,QAAQ;;;;;;;;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
@@ -1,3 +1,3 @@
1
- import { C as runObserveHookSequential, O as PluginEntry, S as runObserveHook, T as runTransformHook, _ as normalizePluginEntry, a as MergedContribution, b as registerHostType, c as PluginEntryData, d as ResolvedPlugin, f as Transform, g as normalizePluginEntries, h as mergeContributions, i as HostPluginModule, l as PluginError, m as hostTypeSatisfies, n as Contributions, o as NormalizedPluginEntry, p as entryActiveForVerb, r as HostPlugin, s as Observe, t as ContributionSource, u as Provide, v as pluginEntryObjectSchema, w as runProvideHook, x as resolveOrder, y as pluginEntrySchema } from "./plugins-Uk84BRay.mjs";
2
- export { ContributionSource, Contributions, HostPlugin, HostPluginModule, MergedContribution, NormalizedPluginEntry, Observe, type PluginEntry, PluginEntryData, PluginError, Provide, ResolvedPlugin, Transform, entryActiveForVerb, hostTypeSatisfies, mergeContributions, normalizePluginEntries, normalizePluginEntry, pluginEntryObjectSchema, pluginEntrySchema, registerHostType, resolveOrder, runObserveHook, runObserveHookSequential, runProvideHook, runTransformHook };
1
+ import { C as runObserveHookSequential, D as ConnectPluginSlices, E as CONNECT_PLUGIN_OWNED_SLICES, M as PluginEntry, O as OwnedConfigSlice, S as runObserveHook, T as runTransformHook, _ as normalizePluginEntry, a as MergedContribution, b as registerHostType, c as PluginEntryData, d as ResolvedPlugin, f as Transform, g as normalizePluginEntries, h as mergeContributions, i as HostPluginModule, k as defaultConnectComposition, l as PluginError, m as hostTypeSatisfies, n as Contributions, o as NormalizedPluginEntry, p as entryActiveForVerb, r as HostPlugin, s as Observe, t as ContributionSource, u as Provide, v as pluginEntryObjectSchema, w as runProvideHook, x as resolveOrder, y as pluginEntrySchema } from "./plugins-Dsmfhbn7.mjs";
2
+ export { CONNECT_PLUGIN_OWNED_SLICES, type ConnectPluginSlices, ContributionSource, Contributions, HostPlugin, HostPluginModule, MergedContribution, NormalizedPluginEntry, Observe, type OwnedConfigSlice, type PluginEntry, PluginEntryData, PluginError, Provide, ResolvedPlugin, Transform, defaultConnectComposition, entryActiveForVerb, hostTypeSatisfies, mergeContributions, normalizePluginEntries, normalizePluginEntry, pluginEntryObjectSchema, pluginEntrySchema, registerHostType, resolveOrder, runObserveHook, runObserveHookSequential, runProvideHook, runTransformHook };
3
3
  export {};
package/dist/plugins.mjs CHANGED
@@ -1,174 +1,2 @@
1
- import { z } from "zod";
2
- //#region src/plugins.ts
3
- /**
4
- * R1 — the host plugin framework (bridge-runners-to-plugins plan,
5
- * customization-references/host-core as the blueprint).
6
- *
7
- * A plugin is hooks + contributions; hooks are boot wiring (main realm only),
8
- * contributions are declarative, serializable surface. Host RUNTIMES define
9
- * the hook vocabulary and interleave their own wiring between stages — they
10
- * are never plugins themselves.
11
- *
12
- * host.js carries the COMPOSITION as `runner.plugins` entries:
13
- * string | { module, enabled?, verbs?, config? }
14
- * Presence is activation (enabled defaults true); `verbs` scopes an entry to
15
- * matching run verbs; `config` is validated against the plugin's declared
16
- * zod schema. Entries resolve from the PROJECT's dependency tree exactly
17
- * like runner modules.
18
- */
19
- var PluginError = class extends Error {
20
- constructor(message, hint) {
21
- super(hint ? `${message}\n Hint: ${hint}` : message);
22
- this.name = "PluginError";
23
- }
24
- };
25
- const pluginEntryObjectSchema = z.strictObject({
26
- module: z.string().min(1),
27
- /** Presence is activation BY DEFAULT; false is the explicit off-switch. */
28
- enabled: z.boolean().optional(),
29
- /** "*" (default) or the run verbs this entry is active for. */
30
- verbs: z.union([z.literal("*"), z.array(z.string().min(1)).min(1)]).optional(),
31
- /** Validated against the plugin's declared configSchema at resolution. */
32
- config: z.record(z.string(), z.unknown()).optional()
33
- });
34
- const pluginEntrySchema = z.union([z.string().min(1), pluginEntryObjectSchema]);
35
- function normalizePluginEntry(entry) {
36
- if (typeof entry === "string") return {
37
- module: entry,
38
- enabled: true,
39
- verbs: "*",
40
- config: {}
41
- };
42
- return {
43
- module: entry.module,
44
- enabled: entry.enabled ?? true,
45
- verbs: entry.verbs ?? "*",
46
- config: entry.config ?? {}
47
- };
48
- }
49
- /** Module is the identity key: a duplicate makes override targeting and
50
- * ordering ambiguous, so it fails loudly. */
51
- function normalizePluginEntries(entries, where) {
52
- const normalized = entries.map(normalizePluginEntry);
53
- const seen = /* @__PURE__ */ new Set();
54
- for (const entry of normalized) {
55
- if (seen.has(entry.module)) throw new PluginError(`${where}: plugin "${entry.module}" is listed twice.`, "Module specifiers are the identity key of a composition; a plugin meant to run twice needs distinct subpath specifiers.");
56
- seen.add(entry.module);
57
- }
58
- return normalized;
59
- }
60
- function entryActiveForVerb(entry, verb) {
61
- if (!entry.enabled) return false;
62
- return entry.verbs === "*" || entry.verbs.includes(verb);
63
- }
64
- /**
65
- * The appliesTo hierarchy. "reactor" is the base every reactor host extends;
66
- * "compound" is its own branch (plugins over the member set — e.g. the clint
67
- * proxy). Host runtimes register their id with a parent; compatibility walks
68
- * the parent chain.
69
- */
70
- const HOST_TYPE_PARENTS = {
71
- reactor: null,
72
- compound: null,
73
- connect: "reactor",
74
- switchboard: "reactor",
75
- mastra: "reactor"
76
- };
77
- function registerHostType(id, parent) {
78
- if (id in HOST_TYPE_PARENTS && HOST_TYPE_PARENTS[id] !== parent) throw new PluginError(`Host type "${id}" is already registered with parent "${String(HOST_TYPE_PARENTS[id])}".`);
79
- HOST_TYPE_PARENTS[id] = parent;
80
- }
81
- function hostTypeSatisfies(hostType, appliesTo) {
82
- let current = hostType;
83
- while (current !== null) {
84
- if (current === appliesTo) return true;
85
- current = current in HOST_TYPE_PARENTS ? HOST_TYPE_PARENTS[current] : null;
86
- }
87
- return false;
88
- }
89
- /** Registration order, bucketed pre → normal → post (stable within buckets),
90
- * then dependsOn topo-sorted within the bucketed order. */
91
- function resolveOrder(plugins) {
92
- const buckets = {
93
- pre: [],
94
- normal: [],
95
- post: []
96
- };
97
- for (const plugin of plugins) buckets[plugin.enforce ?? "normal"].push(plugin);
98
- const bucketed = [
99
- ...buckets.pre,
100
- ...buckets.normal,
101
- ...buckets.post
102
- ];
103
- const byName = new Map(bucketed.map((p) => [p.name, p]));
104
- for (const plugin of bucketed) for (const dep of plugin.dependsOn ?? []) if (!byName.has(dep)) throw new PluginError(`Plugin "${plugin.name}" depends on missing plugin "${dep}".`, "dependsOn names PLUGINS only — the host runtime is implied and never named.");
105
- const ordered = [];
106
- const state = /* @__PURE__ */ new Map();
107
- const visit = (plugin, chain) => {
108
- const mark = state.get(plugin.name);
109
- if (mark === "done") return;
110
- if (mark === "visiting") throw new PluginError(`Plugin dependency cycle: ${[...chain, plugin.name].join(" -> ")}.`);
111
- state.set(plugin.name, "visiting");
112
- for (const dep of plugin.dependsOn ?? []) visit(byName.get(dep), [...chain, plugin.name]);
113
- state.set(plugin.name, "done");
114
- ordered.push(plugin);
115
- };
116
- for (const plugin of bucketed) visit(plugin, []);
117
- return ordered;
118
- }
119
- async function runProvideHook(name, plugins, ctx) {
120
- const impls = plugins.filter((p) => typeof p.hooks?.[name] === "function");
121
- if (impls.length > 1) throw new PluginError(`Hook "${name}" is provided by ${impls.map((p) => `"${p.name}"`).join(" and ")} — provide hooks have one winner.`);
122
- const impl = impls[0]?.hooks?.[name];
123
- return impl ? await impl(ctx) : void 0;
124
- }
125
- async function runTransformHook(name, plugins, ctx, seed) {
126
- let value = seed;
127
- for (const plugin of plugins) {
128
- const impl = plugin.hooks?.[name];
129
- if (typeof impl === "function") value = await impl(value, ctx);
130
- }
131
- return value;
132
- }
133
- /** Sequential observe, in plugin order — for lifecycle moments whose order
134
- * is load-bearing (teardown: the switchboard stops privacy before workflows
135
- * before the api, per the carve map). */
136
- async function runObserveHookSequential(name, plugins, ctx) {
137
- for (const plugin of plugins) {
138
- const impl = plugin.hooks?.[name];
139
- if (typeof impl === "function") await impl(ctx);
140
- }
141
- }
142
- async function runObserveHook(name, plugins, ctx) {
143
- await Promise.all(plugins.map(async (plugin) => {
144
- const impl = plugin.hooks?.[name];
145
- if (typeof impl === "function") await impl(ctx);
146
- }));
147
- }
148
- /** Array kinds concatenate in provenance-then-order sequence (built-in first,
149
- * so later sources read as overrides where consumers want last-wins). */
150
- function mergeContributions(resolved) {
151
- const rank = {
152
- "built-in": 0,
153
- local: 1,
154
- dependency: 2
155
- };
156
- const sorted = [...resolved].sort((a, b) => rank[a.provenance] - rank[b.provenance]);
157
- const merged = {};
158
- for (const { plugin, provenance } of sorted) for (const [kind, values] of Object.entries(plugin.contributions ?? {})) {
159
- if (!values) continue;
160
- const bucket = merged[kind] ??= [];
161
- for (const value of values) bucket.push({
162
- value,
163
- source: {
164
- pluginName: plugin.name,
165
- provenance
166
- }
167
- });
168
- }
169
- return merged;
170
- }
171
- //#endregion
172
- export { PluginError, entryActiveForVerb, hostTypeSatisfies, mergeContributions, normalizePluginEntries, normalizePluginEntry, pluginEntryObjectSchema, pluginEntrySchema, registerHostType, resolveOrder, runObserveHook, runObserveHookSequential, runProvideHook, runTransformHook };
173
-
174
- //# sourceMappingURL=plugins.mjs.map
1
+ import { a as normalizePluginEntries, c as pluginEntrySchema, d as runObserveHook, f as runObserveHookSequential, g as defaultConnectComposition, h as CONNECT_PLUGIN_OWNED_SLICES, i as mergeContributions, l as registerHostType, m as runTransformHook, n as entryActiveForVerb, o as normalizePluginEntry, p as runProvideHook, r as hostTypeSatisfies, s as pluginEntryObjectSchema, t as PluginError, u as resolveOrder } from "./plugins-DP3YlIWx.mjs";
2
+ export { CONNECT_PLUGIN_OWNED_SLICES, PluginError, defaultConnectComposition, entryActiveForVerb, hostTypeSatisfies, mergeContributions, normalizePluginEntries, normalizePluginEntry, pluginEntryObjectSchema, pluginEntrySchema, registerHostType, resolveOrder, runObserveHook, runObserveHookSequential, runProvideHook, runTransformHook };