@powerhousedao/switchboard 6.4.0-next.1 → 6.4.0-next.3

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.
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.mts","names":[],"sources":["../src/pglite-version.ts","../src/pglite-store.mts","../src/builder-defaults.mts","../src/unsupported-stored-documents.mts","../src/server.mts"],"mappings":";;;;;;;;;;;cAYa;KACD,2BAA2B;;;;UCuHtB;EACf;EACA,cAAc;EACd;;;;KClHU;EAIV,iBAAiB;;EAEjB,mBAAmB;;EAEnB;;;;;;;EAOA,gBAAgB;;EAEhB;;EAEA;IACE;IACA,eAAe,QAAQ;;;EAGzB,sBAAsB;EACtB,SAAS;;;;;;EAMT,SAAS;;;;;EAKT,cAAc,KAAK;;EAEnB,wBAAwB;;wBAiBV,gCACd,gBAAgB,gBAChB,eAAe,sBACf,UAAS;;;;wBCrEK,kCACd,OAAO,wCACP,KAAK,OAAO,aACX;;qBAaU,oCAAoC;WACtC,mBAAmB;WACnB;EAET,YAAY,OAAO;SAYH,QACd,iBACC,SAAS;;;;;wBCyJE,uBACd,UAAS,KAAK;;;;;;wBAgCM,gBAAgB,eAAe;;wBA2ErC,iBACd,YAAY,2CACZ,mBACA,qBACC;;;;;;KAmCE;EACH,QAAQ,OAAO;EACf,qBAAqB;EACrB,cAAc;;EAEd,mBAAmB;;wBAGC,oBAAoB;EACxC;EACA;EACA,oBAAoB;EACpB;;EAEA;;EAEA;EACA,iBAAiB;;EAEjB,eAAe;EACf,QAAQ;IACN,QAAQ;iBAkEK;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;;;;;;;;;;;;wBAcc,yBAAyB;EACvC;EACA;;EAEA;;EAEA;EACA;IACE;;wBAmCY,8BACd,SAAS,KAAK,uDACd,oBACA,QAAQ;EACL;EAAmB,YAAY;;;;;;;;;;;;;;;;;;;;qBA6vCvB,mBAAgB,QACpB,wBAAsB,OACvB,oBACL,QAAQ"}
1
+ {"version":3,"file":"server.d.mts","names":[],"sources":["../src/pglite-version.ts","../src/pglite-store.mts","../src/builder-defaults.mts","../src/unsupported-stored-documents.mts","../src/server.mts"],"mappings":";;;;;;;;;;;cAYa;KACD,2BAA2B;;;;UCuHtB;EACf;EACA,cAAc;EACd;;;;KClHU;EAGV,iBAAiB;;EAEjB,mBAAmB;;EAEnB;;;;;;;EAOA,gBAAgB;;EAEhB;;EAEA;IACE;IACA,eAAe,QAAQ;;;EAGzB,sBAAsB;EACtB,SAAS;;;;;;EAMT,SAAS;;;;;EAKT,cAAc,KAAK;;EAEnB,wBAAwB;;wBAiBV,gCACd,gBAAgB,gBAChB,eAAe,sBACf,UAAS;;;;wBCpEK,kCACd,OAAO,wCACP,KAAK,OAAO,aACX;;qBAaU,oCAAoC;WACtC,mBAAmB;WACnB;EAET,YAAY,OAAO;SAYH,QACd,iBACC,SAAS;;;;;wBCyJE,uBACd,UAAS,KAAK;;;;;;wBAgCM,gBAAgB,eAAe;;wBA2ErC,iBACd,YAAY,2CACZ,mBACA,qBACC;;;;;;KAmCE;EACH,QAAQ,OAAO;EACf,qBAAqB;EACrB,cAAc;;EAEd,mBAAmB;;wBAGC,oBAAoB;EACxC;EACA;EACA,oBAAoB;EACpB;;EAEA;;EAEA;EACA,iBAAiB;;EAEjB,eAAe;EACf,QAAQ;IACN,QAAQ;iBAkEK;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;;;;;;;;;;;;wBAcc,yBAAyB;EACvC;EACA;;EAEA;;EAEA;EACA;IACE;;wBAmCY,8BACd,SAAS,KAAK,uDACd,oBACA,QAAQ;EACL;EAAmB,YAAY;;;;;;;;;;;;;;;;;;;;qBAquCvB,mBAAgB,QACpB,wBAAsB,OACvB,oBACL,QAAQ"}
package/dist/server.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { n as StoredDocumentsRefusedError, r as resolveUnsupportedStoredDocuments } from "./from-env-CLImR6qa.mjs";
3
- import { a as resolveKeyframes, i as isPortAvailable, n as deriveAttachmentServiceConfig, o as resolvePgliteStorageDirs, r as initSwitchboardProcess, s as startSwitchboard, t as createReactorKysely, u as applySwitchboardReactorDefaults } from "./server-BMRdMNvC.mjs";
3
+ import { a as resolveKeyframes, i as isPortAvailable, n as deriveAttachmentServiceConfig, o as resolvePgliteStorageDirs, r as initSwitchboardProcess, s as startSwitchboard, t as createReactorKysely, u as applySwitchboardReactorDefaults } from "./server-CrAdM6CN.mjs";
4
4
  export { StoredDocumentsRefusedError, applySwitchboardReactorDefaults, createReactorKysely, deriveAttachmentServiceConfig, initSwitchboardProcess, isPortAvailable, resolveKeyframes, resolvePgliteStorageDirs, resolveUnsupportedStoredDocuments, startSwitchboard };
5
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="19c1cf15-cfa8-5947-8353-50ac7ed846c4")}catch(e){}}();
6
- //# debugId=19c1cf15-cfa8-5947-8353-50ac7ed846c4
5
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="22faedaa-2c3e-573d-8b7b-4d1af5959a31")}catch(e){}}();
6
+ //# debugId=22faedaa-2c3e-573d-8b7b-4d1af5959a31
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@powerhousedao/switchboard",
3
3
  "type": "module",
4
- "version": "6.4.0-next.1",
4
+ "version": "6.4.0-next.3",
5
5
  "main": "dist/index.mjs",
6
6
  "exports": {
7
7
  ".": {
@@ -68,6 +68,12 @@
68
68
  "types": "./dist/plugins/ai.d.mts",
69
69
  "import": "./dist/plugins/ai.mjs",
70
70
  "default": "./dist/plugins/ai.mjs"
71
+ },
72
+ "./plugins/inspector": {
73
+ "source": "./src/plugins/inspector.mts",
74
+ "types": "./dist/plugins/inspector.d.mts",
75
+ "import": "./dist/plugins/inspector.mjs",
76
+ "default": "./dist/plugins/inspector.mjs"
71
77
  }
72
78
  },
73
79
  "engines": {
@@ -99,23 +105,23 @@
99
105
  "@opentelemetry/sdk-node": "^0.218.0",
100
106
  "@opentelemetry/sdk-trace-base": "^2.7.1",
101
107
  "@opentelemetry/semantic-conventions": "^1.41.1",
102
- "@powerhousedao/config": "6.4.0-next.1",
103
- "@powerhousedao/host-core": "6.4.0-next.1",
104
- "@powerhousedao/opentelemetry-instrumentation-reactor": "6.4.0-next.1",
105
- "@powerhousedao/reactor": "6.4.0-next.1",
106
- "@powerhousedao/reactor-api": "6.4.0-next.1",
107
- "@powerhousedao/reactor-attachments": "6.4.0-next.1",
108
- "@powerhousedao/reactor-drive": "6.4.0-next.1",
109
- "@powerhousedao/reactor-group": "6.4.0-next.1",
110
- "@powerhousedao/reactor-privacy": "6.4.0-next.1",
111
- "@powerhousedao/reactor-workflow": "6.4.0-next.1",
112
- "@powerhousedao/shared": "6.4.0-next.1",
113
- "@powerhousedao/workflow": "6.4.0-next.1",
108
+ "@powerhousedao/config": "6.4.0-next.3",
109
+ "@powerhousedao/host-core": "6.4.0-next.3",
110
+ "@powerhousedao/opentelemetry-instrumentation-reactor": "6.4.0-next.3",
111
+ "@powerhousedao/reactor": "6.4.0-next.3",
112
+ "@powerhousedao/reactor-api": "6.4.0-next.3",
113
+ "@powerhousedao/reactor-attachments": "6.4.0-next.3",
114
+ "@powerhousedao/reactor-drive": "6.4.0-next.3",
115
+ "@powerhousedao/reactor-group": "6.4.0-next.3",
116
+ "@powerhousedao/reactor-privacy": "6.4.0-next.3",
117
+ "@powerhousedao/reactor-workflow": "6.4.0-next.3",
118
+ "@powerhousedao/shared": "6.4.0-next.3",
119
+ "@powerhousedao/workflow": "6.4.0-next.3",
114
120
  "@pyroscope/nodejs": "^0.4.5",
115
- "@renown/sdk": "6.4.0-next.1",
121
+ "@renown/sdk": "6.4.0-next.3",
116
122
  "@sentry/node": "^10.53.1",
117
123
  "@sentry/opentelemetry": "^10.53.1",
118
- "document-model": "6.4.0-next.1",
124
+ "document-model": "6.4.0-next.3",
119
125
  "dotenv": "^16.4.7",
120
126
  "express": "^4.22.1",
121
127
  "graphql": "^16",
@@ -131,7 +137,6 @@
131
137
  "@openfeature/core": "1.9.1",
132
138
  "@openfeature/env-var-provider": "0.3.1",
133
139
  "@openfeature/server-sdk": "1.19.0",
134
- "@powerhousedao/vetra": "6.4.0-next.1",
135
140
  "@types/express": "^4.17.25",
136
141
  "@types/node": "25.2.3",
137
142
  "@types/pg": "8.16.0",
@@ -143,14 +148,10 @@
143
148
  "vitest": "5.0.3"
144
149
  },
145
150
  "peerDependencies": {
146
- "@powerhousedao/vetra": "6.4.0-next.1",
147
151
  "react": ">=19.0.0",
148
152
  "vite": "^8.0.0"
149
153
  },
150
154
  "peerDependenciesMeta": {
151
- "@powerhousedao/vetra": {
152
- "optional": true
153
- },
154
155
  "vite": {
155
156
  "optional": true
156
157
  }
@@ -0,0 +1,290 @@
1
+ /**
2
+ * The inspector plugin: what it reports (every loaded document model module,
3
+ * all specification versions), when (ready, each package reload), where (a
4
+ * file, gone at shutdown).
5
+ */
6
+ import type { HostPlugin, ResolvedPlugin } from "@powerhousedao/host-core";
7
+ import {
8
+ documentModelDocumentModelModule,
9
+ type DocumentModelModule,
10
+ type ILogger,
11
+ } from "document-model";
12
+ import { existsSync, readdirSync, readFileSync } from "node:fs";
13
+ import { mkdtemp, rm } from "node:fs/promises";
14
+ import { tmpdir } from "node:os";
15
+ import { join } from "node:path";
16
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
17
+ import type { SwitchboardHostContext } from "../src/plugin-host.mjs";
18
+ import {
19
+ createInspectorPlugin,
20
+ inspectorPluginConfigSchema,
21
+ inspectorReportOf,
22
+ type InspectorReport,
23
+ } from "../src/plugins/inspector.mjs";
24
+ import type { startSwitchboard } from "../src/server.mjs";
25
+ import { bootSwitchboard } from "./boot-helpers.js";
26
+
27
+ function stubLogger(): ILogger {
28
+ const logger = {
29
+ verbose: vi.fn(),
30
+ debug: vi.fn(),
31
+ info: vi.fn(),
32
+ warn: vi.fn(),
33
+ error: vi.fn(),
34
+ child: vi.fn(),
35
+ };
36
+ logger.child.mockReturnValue(logger);
37
+ return logger as unknown as ILogger;
38
+ }
39
+
40
+ /** A module of another type or version, shaped like the base one. */
41
+ function moduleOf(
42
+ id: string,
43
+ name: string,
44
+ version?: number,
45
+ ): DocumentModelModule {
46
+ const base =
47
+ documentModelDocumentModelModule as unknown as DocumentModelModule;
48
+ return {
49
+ ...base,
50
+ ...(version === undefined ? {} : { version }),
51
+ documentModel: {
52
+ ...base.documentModel,
53
+ global: { ...base.documentModel.global, id, name },
54
+ },
55
+ };
56
+ }
57
+
58
+ const readReport = (file: string) =>
59
+ JSON.parse(readFileSync(file, "utf8")) as InspectorReport;
60
+
61
+ let tempRoot: string;
62
+ let reportFile: string;
63
+
64
+ beforeEach(async () => {
65
+ tempRoot = await mkdtemp(join(tmpdir(), "switchboard-inspector-"));
66
+ reportFile = join(tempRoot, "preview", "inspector.json");
67
+ });
68
+
69
+ afterEach(async () => {
70
+ await rm(tempRoot, { recursive: true, force: true });
71
+ });
72
+
73
+ describe("inspector config", () => {
74
+ it("needs a report file and rejects a typo'd key", () => {
75
+ expect(inspectorPluginConfigSchema.safeParse({}).success).toBe(false);
76
+ expect(
77
+ inspectorPluginConfigSchema.safeParse({ reportFile: "a.json" }).success,
78
+ ).toBe(true);
79
+ expect(
80
+ inspectorPluginConfigSchema.safeParse({ reportFile: "a.json", file: "b" })
81
+ .success,
82
+ ).toBe(false);
83
+ expect(() => createInspectorPlugin({})).toThrow();
84
+ });
85
+ });
86
+
87
+ describe("inspectorReportOf", () => {
88
+ it("lists every module with its specifications, the project marked local", () => {
89
+ const report = inspectorReportOf(
90
+ [
91
+ [
92
+ tempRoot,
93
+ [
94
+ moduleOf("acme/invoice", "Invoice", 2),
95
+ moduleOf("acme/contact", "Contact"),
96
+ moduleOf("acme/invoice", "Invoice", 1),
97
+ ],
98
+ ],
99
+ ["@acme/other", [moduleOf("other/thing", "Thing")]],
100
+ ],
101
+ {
102
+ sequence: 3,
103
+ localPackage: tempRoot,
104
+ now: new Date("2026-01-02T03:04:05.000Z"),
105
+ },
106
+ );
107
+
108
+ expect(report).toMatchObject({
109
+ version: 1,
110
+ sequence: 3,
111
+ writtenAt: "2026-01-02T03:04:05.000Z",
112
+ pid: process.pid,
113
+ });
114
+ expect(report.packages.map((p) => [p.name, p.local])).toEqual(
115
+ [
116
+ ["@acme/other", false],
117
+ [tempRoot, true],
118
+ ].sort(([a], [b]) => String(a).localeCompare(String(b))),
119
+ );
120
+ const local = report.packages.find((p) => p.local)!;
121
+ expect(
122
+ local.models.map((m) => [m.documentType, m.name, m.version]),
123
+ ).toEqual([
124
+ ["acme/contact", "Contact", undefined],
125
+ ["acme/invoice", "Invoice", 1],
126
+ ["acme/invoice", "Invoice", 2],
127
+ ]);
128
+ expect(local.models[0]).not.toHaveProperty("version");
129
+ expect(
130
+ local.models[1]!.documentModel.specifications.length,
131
+ ).toBeGreaterThan(0);
132
+ expect(local.models[1]!.documentModel.id).toBe("acme/invoice");
133
+ });
134
+
135
+ it("marks nothing local when the project is not loaded", () => {
136
+ const report = inspectorReportOf([[tempRoot, []]], { sequence: 1 });
137
+ expect(report.packages).toEqual([
138
+ { name: tempRoot, local: false, models: [] },
139
+ ]);
140
+ });
141
+ });
142
+
143
+ describe("inspector hooks", () => {
144
+ function stubContext(
145
+ initial: Map<string, DocumentModelModule[]>,
146
+ options: Record<string, unknown> = {},
147
+ ) {
148
+ const handlers: ((
149
+ models: Record<string, DocumentModelModule[]>,
150
+ ) => unknown)[] = [];
151
+ const logger = stubLogger();
152
+ const ctx = {
153
+ logger,
154
+ options,
155
+ renown: null,
156
+ contributions: {},
157
+ api: {
158
+ packageManager: {
159
+ getDocumentModels: () => new Map(initial),
160
+ onDocumentModelsChange: (
161
+ handler: (models: Record<string, DocumentModelModule[]>) => unknown,
162
+ ) => {
163
+ handlers.push(handler);
164
+ },
165
+ },
166
+ },
167
+ } as unknown as SwitchboardHostContext;
168
+ return {
169
+ ctx,
170
+ logger,
171
+ reload: (models: Record<string, DocumentModelModule[]>) =>
172
+ handlers.forEach((handler) => handler(models)),
173
+ };
174
+ }
175
+
176
+ it("reports at ready and on every reload, and removes the file at shutdown", () => {
177
+ const plugin = createInspectorPlugin({ reportFile });
178
+ const cwd = process.cwd();
179
+ const { ctx, reload } = stubContext(
180
+ new Map([[cwd, [moduleOf("acme/contact", "Contact")]]]),
181
+ );
182
+
183
+ plugin.hooks!.onReactorReady!(ctx);
184
+ const first = readReport(reportFile);
185
+ expect(first.sequence).toBe(1);
186
+ expect(first.packages).toHaveLength(1);
187
+ expect(first.packages[0]).toMatchObject({ name: cwd, local: true });
188
+ expect(first.packages[0]!.models.map((m) => m.documentType)).toEqual([
189
+ "acme/contact",
190
+ ]);
191
+
192
+ reload({
193
+ [cwd]: [
194
+ moduleOf("acme/contact", "Contact"),
195
+ moduleOf("acme/invoice", "Invoice", 1),
196
+ ],
197
+ });
198
+ const second = readReport(reportFile);
199
+ expect(second.sequence).toBe(2);
200
+ expect(second.packages[0]!.models.map((m) => m.documentType)).toEqual([
201
+ "acme/contact",
202
+ "acme/invoice",
203
+ ]);
204
+ // Only the report: the temp file it was written through is gone.
205
+ expect(readdirSync(join(tempRoot, "preview"))).toEqual(["inspector.json"]);
206
+
207
+ plugin.hooks!.onShutdown!(ctx);
208
+ expect(existsSync(reportFile)).toBe(false);
209
+ // A reload that lands after the stop writes nothing.
210
+ reload({ [cwd]: [] });
211
+ expect(existsSync(reportFile)).toBe(false);
212
+ });
213
+
214
+ it("marks no package local on a switchboard that does not load the project", () => {
215
+ const plugin = createInspectorPlugin({ reportFile });
216
+ const { ctx } = stubContext(new Map([[process.cwd(), []]]), {
217
+ disableLocalPackages: true,
218
+ });
219
+ plugin.hooks!.onReactorReady!(ctx);
220
+ expect(readReport(reportFile).packages[0]!.local).toBe(false);
221
+ });
222
+
223
+ it("warns and carries on when the report cannot be written", () => {
224
+ // A folder in the file's place: the rename fails.
225
+ const plugin = createInspectorPlugin({ reportFile: tempRoot });
226
+ const { ctx, logger } = stubContext(new Map());
227
+ expect(() => plugin.hooks!.onReactorReady!(ctx)).not.toThrow();
228
+ expect(logger.warn).toHaveBeenCalledTimes(1);
229
+ });
230
+
231
+ it("accepts the retired codegen setting and changes no server option", () => {
232
+ for (const codegen of [undefined, false, true]) {
233
+ const plugin = createInspectorPlugin({ reportFile, codegen });
234
+ expect(plugin.hooks).not.toHaveProperty("transformServerOptions");
235
+ }
236
+ });
237
+ });
238
+
239
+ describe("a switchboard with the inspector in its composition", () => {
240
+ it("writes the report once ready and removes it at shutdown", async () => {
241
+ const names = ["PH_REACTOR_DATABASE_URL", "MCP_ENABLED"];
242
+ const previous = names.map((name) => [name, process.env[name]] as const);
243
+ process.env.PH_REACTOR_DATABASE_URL = join(tempRoot, "reactor-storage");
244
+ delete process.env.MCP_ENABLED;
245
+ const composition: ResolvedPlugin[] = [
246
+ {
247
+ plugin: createInspectorPlugin({ reportFile }) as HostPlugin,
248
+ provenance: "built-in",
249
+ entry: {
250
+ enabled: true,
251
+ verbs: "*",
252
+ config: { reportFile },
253
+ module: "@powerhousedao/switchboard/plugins/inspector",
254
+ },
255
+ },
256
+ ];
257
+ let switchboard: Awaited<ReturnType<typeof startSwitchboard>> | undefined;
258
+ try {
259
+ switchboard = await bootSwitchboard(
260
+ {
261
+ server: { port: 0 },
262
+ storage: { readModel: { url: join(tempRoot, "read-model") } },
263
+ features: { workflows: false },
264
+ packages: { disableLocal: true },
265
+ identity: { keypairPath: join(tempRoot, "identity.json") },
266
+ drive: { slug: "default-drive", global: { name: "Default Drive" } },
267
+ },
268
+ { logger: stubLogger(), pluginComposition: composition },
269
+ );
270
+ const report = readReport(reportFile);
271
+ expect(report).toMatchObject({
272
+ version: 1,
273
+ sequence: 1,
274
+ pid: process.pid,
275
+ });
276
+ expect(Array.isArray(report.packages)).toBe(true);
277
+ expect(report.packages.every((p) => !p.local)).toBe(true);
278
+
279
+ await switchboard.shutdown();
280
+ switchboard = undefined;
281
+ expect(existsSync(reportFile)).toBe(false);
282
+ } finally {
283
+ await switchboard?.shutdown();
284
+ for (const [name, value] of previous) {
285
+ if (value === undefined) delete process.env[name];
286
+ else process.env[name] = value;
287
+ }
288
+ }
289
+ }, 60_000);
290
+ });
package/tsconfig.json CHANGED
@@ -45,9 +45,6 @@
45
45
  {
46
46
  "path": "../../packages/shared"
47
47
  },
48
- {
49
- "path": "../../packages/vetra"
50
- },
51
48
  {
52
49
  "path": "../../packages/workflow"
53
50
  }
package/tsdown.config.ts CHANGED
@@ -20,6 +20,7 @@ export default defineConfig({
20
20
  "src/plugins/privacy.mts",
21
21
  "src/plugins/workflows.mts",
22
22
  "src/plugins/ai.mts",
23
+ "src/plugins/inspector.mts",
23
24
  ],
24
25
  platform: "node",
25
26
  outDir: "dist",