@powerhousedao/switchboard 6.2.3-dev.89 → 6.2.3-dev.90

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 (67) hide show
  1. package/.tsbuild/test/boot-desktop-auth.test.d.ts +2 -0
  2. package/.tsbuild/test/boot-desktop-auth.test.d.ts.map +1 -0
  3. package/.tsbuild/test/delegated-publish.test.d.ts +2 -0
  4. package/.tsbuild/test/delegated-publish.test.d.ts.map +1 -0
  5. package/.tsbuild/tsconfig.tsbuildinfo +1 -1
  6. package/CHANGELOG.md +35 -0
  7. package/dist/boot.d.mts +2 -2
  8. package/dist/boot.mjs +2 -2
  9. package/dist/config/from-env.d.mts +1 -1
  10. package/dist/config/from-env.mjs +3 -3
  11. package/dist/config/schema.d.mts +1 -1
  12. package/dist/config/schema.mjs +3 -3
  13. package/dist/{from-env-DuUwngOC.mjs → from-env-DJ4iQ3QZ.mjs} +5 -5
  14. package/dist/from-env-DJ4iQ3QZ.mjs.map +1 -0
  15. package/dist/index.mjs +3 -3
  16. package/dist/{plugin-host-C0bSz1Oe.d.mts → plugin-host-BHEUSn9G.d.mts} +2 -2
  17. package/dist/{plugin-host-C0bSz1Oe.d.mts.map → plugin-host-BHEUSn9G.d.mts.map} +1 -1
  18. package/dist/plugins/ai.d.mts +1 -1
  19. package/dist/plugins/ai.d.mts.map +1 -1
  20. package/dist/plugins/ai.mjs +68 -20
  21. package/dist/plugins/ai.mjs.map +1 -1
  22. package/dist/plugins/attachments.d.mts +1 -1
  23. package/dist/plugins/attachments.mjs +3 -3
  24. package/dist/plugins/mcp.d.mts +1 -1
  25. package/dist/plugins/privacy.d.mts +1 -1
  26. package/dist/plugins/workflows.d.mts +3 -3
  27. package/dist/plugins/workflows.mjs +3 -3
  28. package/dist/{schema-XEZrdmag.mjs → schema-1yj85yQD.mjs} +15 -5
  29. package/dist/schema-1yj85yQD.mjs.map +1 -0
  30. package/dist/{schema-DhempFjb.d.mts → schema-ugrJupVH.d.mts} +5 -1
  31. package/dist/schema-ugrJupVH.d.mts.map +1 -0
  32. package/dist/{server-BJk9-9n4.mjs → server-CgDvrUqE.mjs} +129 -30
  33. package/dist/server-CgDvrUqE.mjs.map +1 -0
  34. package/dist/server.d.mts +8 -306
  35. package/dist/server.d.mts.map +1 -1
  36. package/dist/server.mjs +4 -4
  37. package/dist/types-DzO3_320.d.mts +308 -0
  38. package/dist/types-DzO3_320.d.mts.map +1 -0
  39. package/dist/utils-Cm0TE6dP.mjs +148 -0
  40. package/dist/utils-Cm0TE6dP.mjs.map +1 -0
  41. package/dist/utils.d.mts +21 -3
  42. package/dist/utils.d.mts.map +1 -1
  43. package/dist/utils.mjs +4 -4
  44. package/dist/{worker-pool-BWHBLBJd.mjs → worker-pool-gyxJnCxA.mjs} +4 -4
  45. package/dist/worker-pool-gyxJnCxA.mjs.map +1 -0
  46. package/dist/workflow-runtime-CF5pc8mt.d.mts.map +1 -1
  47. package/dist/{workflows-krankcQT.mjs → workflows-C9BQlyT0.mjs} +31 -7
  48. package/dist/workflows-C9BQlyT0.mjs.map +1 -0
  49. package/package.json +29 -19
  50. package/test/ai-gateway.test.ts +58 -1
  51. package/test/boot-desktop-auth.test.ts +278 -0
  52. package/test/boot-preconditions.test.ts +13 -0
  53. package/test/config-merge.test.ts +11 -0
  54. package/test/default-drive-protocol-versions.test.ts +1 -24
  55. package/test/default-drive-slug.test.ts +170 -2
  56. package/test/delegated-publish.test.ts +435 -0
  57. package/test/fatal-shutdown.test.ts +40 -0
  58. package/test/pglite-store.test.ts +179 -2
  59. package/test/workflow-runtime.test.ts +119 -0
  60. package/dist/from-env-DuUwngOC.mjs.map +0 -1
  61. package/dist/schema-DhempFjb.d.mts.map +0 -1
  62. package/dist/schema-XEZrdmag.mjs.map +0 -1
  63. package/dist/server-BJk9-9n4.mjs.map +0 -1
  64. package/dist/utils-C6AIF38Z.mjs +0 -133
  65. package/dist/utils-C6AIF38Z.mjs.map +0 -1
  66. package/dist/worker-pool-BWHBLBJd.mjs.map +0 -1
  67. package/dist/workflows-krankcQT.mjs.map +0 -1
package/dist/server.d.mts CHANGED
@@ -1,18 +1,13 @@
1
- import { a as SwitchboardConfigInput, i as SwitchboardConfig } from "./schema-DhempFjb.mjs";
1
+ import { a as SwitchboardConfigInput, i as SwitchboardConfig } from "./schema-ugrJupVH.mjs";
2
2
  import { n as WorkflowTriggersCapability } from "./workflow-runtime-CF5pc8mt.mjs";
3
+ import { a as SwitchboardDriveDocumentType, i as SwitchboardDeps, n as StartServerOptions, o as SwitchboardDriveInput, r as StorageOptions, s as SwitchboardReactor, t as IdentityOptions } from "./types-DzO3_320.mjs";
3
4
  import { ILogger } from "document-model";
4
- import { ChannelScheme, Database, IDocumentModelLoader, IInspector, IReactorClient, IStoreMaintenance, InProcessReactorClientModule, JwtHandler, KeyframeSettings, ModelManifestEntry, PoolInstrumentation, ReactorBuilder, ReactorClientBuilder, ReactorFeatureFlags, ReactorStorageFacts, SignerConfig, StoredProtocolRefusal, UnsupportedStoredDocuments, UnsupportedStoredProtocolError } from "@powerhousedao/reactor";
5
- import { AttachmentReferenceProjectionCapability } from "@powerhousedao/reactor-api";
6
- import { PgliteMaintenanceSettings, resolvePgliteMaintenance } from "@powerhousedao/reactor-api/pglite-node";
7
- import { DocumentModelModule, ISigner, SignaturePolicy, UpgradeManifest } from "@powerhousedao/shared/document-model";
8
- import { IErasureService } from "@powerhousedao/reactor-privacy";
9
- import { IAttachmentService } from "@powerhousedao/reactor-attachments";
5
+ import { ChannelScheme, Database, IDocumentModelLoader, IStoreMaintenance, JwtHandler, KeyframeSettings, PoolInstrumentation, ReactorBuilder, ReactorClientBuilder, ReactorFeatureFlags, ReactorStorageFacts, SignerConfig, StoredProtocolRefusal, UnsupportedStoredDocuments, UnsupportedStoredProtocolError } from "@powerhousedao/reactor";
6
+ import { PGliteLike, PgliteMaintenanceSettings, resolvePgliteMaintenance } from "@powerhousedao/reactor-api/pglite-node";
7
+ import { DocumentModelModule, SignaturePolicy, UpgradeManifest } from "@powerhousedao/shared/document-model";
10
8
  import { IRenown } from "@renown/sdk/node";
11
9
  import { Kysely } from "kysely";
12
- import { ResolvedPlugin } from "@powerhousedao/host-core";
13
- import { DriveInput } from "@powerhousedao/shared/document-drive";
14
10
  import "@electric-sql/pglite";
15
- import { IRenown as IRenown$1 } from "@renown/sdk";
16
11
  //#region src/pglite-version.d.ts
17
12
  declare const SUPPORTED_PG_MAJORS: readonly [16, 17];
18
13
  type SupportedPgMajor = (typeof SUPPORTED_PG_MAJORS)[number];
@@ -25,301 +20,6 @@ interface PgliteStoreSettings {
25
20
  workerMemoryMb?: number;
26
21
  }
27
22
  //#endregion
28
- //#region src/privacy.d.mts
29
- type PrivacyOptions = {
30
- /** Wins over PH_PRIVACY_ENABLED. */
31
- enabled?: boolean;
32
- /** Wins over PH_PRIVACY_DEPLOYMENT_SECRET. */
33
- deploymentSecret?: string;
34
- /** The reactor's signer, for a caller-provided reactor. */
35
- signer?: ISigner;
36
- /** Each wins over its PH_PRIVACY_* env var. */
37
- intervalMs?: number;
38
- deadlineMs?: number;
39
- markerGraceMs?: number;
40
- purgeTimeoutMs?: number;
41
- };
42
- //#endregion
43
- //#region src/types.d.ts
44
- /**
45
- * Drive container document type chosen for the boot-time default drive. The
46
- * legacy `powerhouse/document-drive` keeps the existing behavior; the newer
47
- * `powerhouse/reactor-drive` is wired through `addDefaultReactorDrive` and
48
- * uses the relationship-based child graph.
49
- */
50
- export type SwitchboardDriveDocumentType = "powerhouse/document-drive" | "powerhouse/reactor-drive";
51
- /** A {@link DriveInput} extended with the optional drive-container type. */
52
- export type SwitchboardDriveInput = DriveInput & {
53
- documentType?: SwitchboardDriveDocumentType;
54
- };
55
- export type StorageOptions = {
56
- type: "filesystem" | "memory" | "postgres" | "browser";
57
- filesystemPath?: string;
58
- postgresUrl?: string;
59
- };
60
- export type IdentityOptions = {
61
- /** Path to the keypair file. Defaults to ~/.ph/keypair.json */
62
- keypairPath?: string;
63
- /**
64
- * If true, won't start without an existing keypair.
65
- * Use this to ensure the switchboard only runs with an authenticated identity.
66
- */
67
- requireExisting?: boolean;
68
- /** Base url of the Renown instance to use */
69
- baseUrl?: string;
70
- };
71
- /**
72
- * The options view of a switchboard's config and deps: what plugins'
73
- * `transformServerOptions` hook receives. `startSwitchboard` takes the
74
- * config (`@powerhousedao/switchboard/config`) and {@link SwitchboardDeps}.
75
- */
76
- export type StartServerOptions = {
77
- /**
78
- * Pre-built ReactorClientModule (typically from
79
- * `@powerhousedao/reactor#ReactorClientBuilder.buildModule`). When set, the
80
- * switchboard reuses the caller's reactor instead of building its own,
81
- * and the caller owns the reactor's lifecycle. The API, GraphQL manager,
82
- * MCP, attachments, package management subgraph, and registry HTTP loader
83
- * are still configured around it.
84
- *
85
- * Lifecycle contract: switchboard does NOT wire itself into the caller's
86
- * reactor shutdown. Callers must invoke `shutdown()` on the returned
87
- * `SwitchboardReactor` from their own teardown (and SIGINT handlers) to
88
- * drain `/graphql`, MCP, attachments, etc. Killing the caller's reactor
89
- * alone will not release these resources.
90
- *
91
- * Setup contract: the reactor must have switchboard's expected wiring
92
- * already applied — channel scheme, document models, signal handlers,
93
- * etc. Use `applySwitchboardReactorDefaults` from this module to apply
94
- * the same defaults switchboard uses internally; opt out of individual
95
- * pieces as needed.
96
- */
97
- reactor?: InProcessReactorClientModule;
98
- /**
99
- * Route uncaught exceptions, and unhandled rejections nothing else listens
100
- * for, through the reactor's SIGTERM shutdown, so PGlite stores are flushed
101
- * before the process exits with code 1. Installed once the switchboard's own reactor is built;
102
- * ignored when `reactor` is passed. For process entry points only, since
103
- * it adds process-wide listeners.
104
- */
105
- fatalErrorShutdown?: boolean;
106
- /**
107
- * Install the owned reactor's SIGINT/SIGTERM handlers (default true).
108
- * False when a supervisor owns the process exit (a `ph run` compound
109
- * member): the reactor then stops only through `shutdown()`. Ignored with
110
- * a caller-provided `reactor`.
111
- */
112
- signalHandlers?: boolean;
113
- /**
114
- * `/ready` waits for this too: drives the caller seeds after the server
115
- * starts. A rejection leaves the server not ready.
116
- */
117
- readyAfter?: Promise<unknown>;
118
- /**
119
- * Registry URL for the HttpPackageLoader. Enables `PackagesSubgraph`
120
- * (install/uninstall mutations) plus dynamic package resolution.
121
- * Falls back to PH_REGISTRY_URL env, then `packageRegistryUrl` in the
122
- * powerhouse config file.
123
- */
124
- registryUrl?: string;
125
- configFile?: string;
126
- /**
127
- * 0 binds a port the OS picks, reported on the result's `port`: the only
128
- * race-free choice when several instances start at once. A taken non-zero
129
- * port falls back to the next free one, which another process can still
130
- * claim between the probe and the bind.
131
- */
132
- port?: number;
133
- /**
134
- * If true, fail immediately when the requested port is in use instead of
135
- * falling back to the next free port. Matches the semantics of Vite's
136
- * `--strictPort` flag that flows through the `ph vetra` command.
137
- */
138
- strictPort?: boolean;
139
- dev?: boolean;
140
- dbPath?: string;
141
- drive?: SwitchboardDriveInput;
142
- packages?: string[];
143
- remoteDrives?: string[];
144
- https?: {
145
- keyPath: string;
146
- certPath: string;
147
- } | boolean | undefined;
148
- /**
149
- * Identity options for Renown.
150
- * When configured, the switchboard will load the keypair from `ph login`
151
- * and can authenticate with remote services on behalf of the user.
152
- */
153
- identity?: IdentityOptions;
154
- /** Base URL for the attachment service; defaults to `PH_SWITCHBOARD_PUBLIC_URL` then `http(s)://localhost:${port}`. */
155
- attachmentServiceUrl?: string;
156
- /** Mount the MCP server at `/mcp`. On by default; `false` wins over
157
- * MCP_ENABLED, which can turn it off but never on. */
158
- mcp?: boolean;
159
- /** The plugin composition to boot with (FEATURE_PLUGIN_HOST_ENABLED): the
160
- * resolved host.js runner.plugins entries, supplied by the uniform-runners
161
- * switchboard runner (R2 step 2) or a test. Omitted = the built-in default
162
- * composition. Resolved plugins, not specifiers — resolution happens at the
163
- * runner against the PROJECT dependency tree. */
164
- pluginComposition?: ResolvedPlugin[];
165
- /** Mount the read-only inspection subgraph at `/graphql/inspection`. On by
166
- * default; `false` wins over INSPECTION_ENABLED, which can turn it off. */
167
- inspection?: boolean;
168
- /** Open each PGlite store (reactor-storage, read-storage) in its own worker
169
- * thread. Wins either way over PH_PGLITE_WORKERS; unset, the env var
170
- * decides, then PGLITE_WORKERS_DEFAULT. */
171
- pgliteWorkers?: boolean;
172
- /** Powerhouse workflows: the runtime, its subgraph, its webhooks and its
173
- * document models. Wins over PH_WORKFLOWS_ENABLED and the config file. */
174
- workflows?: {
175
- enabled?: boolean;
176
- /** OAuth2 apps the publisher owns (`oauth_app` on a connection): per app,
177
- * the provider's client files by kind. Wins over the config file's
178
- * `workflows.oauthApps`; relative paths there are from the config file.
179
- * `relay` is a token broker for the app's web client, used for a web
180
- * sign-in when this host has no web client file: the provider needs only
181
- * the broker's one redirect URI, and the secret stays with the broker. */
182
- oauthApps?: {
183
- id: string;
184
- clients: {
185
- desktop?: string;
186
- web?: string;
187
- };
188
- relay?: {
189
- clientId: string;
190
- redirectUri: string;
191
- tokenUrl: string;
192
- };
193
- }[];
194
- };
195
- /** The GDPR add-on; off unless this or PH_PRIVACY_ENABLED turns it on. */
196
- privacy?: PrivacyOptions;
197
- processorConfig?: Map<string, unknown>;
198
- disableLocalPackages?: boolean;
199
- enableDocumentModelSubgraphs?: boolean;
200
- /**
201
- * When true, enables dynamic loading of document models from the registry
202
- * when an unknown document type is encountered during sync.
203
- * Disabled by default — enable with DYNAMIC_MODEL_LOADING=true env var.
204
- */
205
- dynamicModelLoading?: boolean;
206
- logger?: ILogger;
207
- /**
208
- * When true, on startup any local PGLite data dirs whose `PG_VERSION` is
209
- * older than the bundled PGLite are migrated to the current version
210
- * (backup → dump → restore) before the server boots. When false, the
211
- * server logs a warning and runs against the legacy data using the
212
- * matching legacy PGLite module.
213
- *
214
- * Triggered by the `--migrate-pglite` CLI flag or `PH_MIGRATE_PGLITE=true`.
215
- */
216
- migratePglite?: boolean;
217
- /**
218
- * Force a specific PGLite-embedded PG major (16 or 17) on startup.
219
- *
220
- * **Destructive**: any existing local PGLite data dirs are wiped before
221
- * the chosen PGLite re-`initdb`'s them at the requested version. Postgres
222
- * URLs are unaffected. Takes precedence over `migratePglite`.
223
- *
224
- * Triggered by `PH_FORCE_PG_VERSION=16|17`.
225
- */
226
- forcePgVersion?: 16 | 17;
227
- /**
228
- * Executor worker pool: `numWorkers > 0` runs jobs in N worker threads;
229
- * `"auto"` sizes the pool from the machine's available cores; 0 or unset
230
- * keeps the in-process executor (the default). Unset fields fall back to
231
- * the REACTOR_WORKERS / REACTOR_DB_* env vars. Requires a Postgres reactor
232
- * database; incompatible with `dev` mode (Vite-loaded models cannot cross
233
- * a thread boundary).
234
- */
235
- workerPool?: {
236
- numWorkers?: number | "auto";
237
- dbPoolSizePerWorker?: number;
238
- acquireTimeoutMs?: number;
239
- };
240
- /**
241
- * Projection worker: `enabled` runs the built-in document-view /
242
- * document-indexer read models in one worker thread, off the host event
243
- * loop; unset keeps them in-process (the default). Unset fields fall back
244
- * to the REACTOR_PROJECTION_WORKER / REACTOR_DB_POOL_SIZE_PROJECTION env
245
- * vars. Requires a Postgres reactor database and worker-importable
246
- * document-model sources (switchboard resolves them itself); incompatible
247
- * with `dev` mode (Vite-loaded models cannot cross a thread boundary).
248
- */
249
- projectionWorker?: {
250
- enabled?: boolean;
251
- dbPoolSize?: number;
252
- };
253
- /**
254
- * Stored documents at protocol versions this build does not run: "refuse"
255
- * (the default) fails the boot with a StoredDocumentsRefusedError;
256
- * "read-only" starts with a warning and keeps those documents read-only.
257
- * Unset falls back to the REACTOR_UNSUPPORTED_STORED_DOCUMENTS env var.
258
- * Ignored when `reactor` is passed.
259
- */
260
- unsupportedStoredDocuments?: UnsupportedStoredDocuments;
261
- };
262
- /** What a switchboard is started with that is not a setting. */
263
- export type SwitchboardDeps = {
264
- logger?: ILogger;
265
- /** See {@link StartServerOptions.reactor}. */
266
- reactor?: InProcessReactorClientModule;
267
- /** See {@link StartServerOptions.pluginComposition}. */
268
- pluginComposition?: ResolvedPlugin[];
269
- /** Receives failures in background work; Sentry by default. */
270
- reportError?: (error: unknown) => void;
271
- /** See {@link StartServerOptions.fatalErrorShutdown}. */
272
- fatalErrorShutdown?: boolean;
273
- /** See {@link StartServerOptions.signalHandlers}. */
274
- signalHandlers?: boolean;
275
- /** See {@link StartServerOptions.readyAfter}. */
276
- readyAfter?: Promise<unknown>;
277
- /** The privacy add-on's signer, for a caller-provided reactor. */
278
- privacySigner?: ISigner;
279
- };
280
- export type SwitchboardReactor = {
281
- defaultDriveUrl: string | undefined;
282
- reactor: IReactorClient;
283
- /** Switchboard-backed remote attachment service over its own `/attachments/*` API, for downstream consumers.
284
- * Undefined when the attachments plugin is absent from the composition
285
- * (FEATURE_PLUGIN_HOST_ENABLED — presence is activation, rewire R2.3). */
286
- attachmentService: IAttachmentService | undefined;
287
- /** Whether the authoritative attachment-reference projection is active. */
288
- attachmentReferenceProjection: AttachmentReferenceProjectionCapability;
289
- /** Whether the workflow runtime's operation intake is indexing. Undefined
290
- * when workflows are off; unavailable means no document trigger fires. */
291
- workflowTriggers?: WorkflowTriggersCapability;
292
- /** Whether workflows are on, after the option, PH_WORKFLOWS_ENABLED and the config file. */
293
- workflowsEnabled: boolean;
294
- /** The boot list of importable models workers and workflow pieces load; empty when none are resolved. */
295
- modelManifest(): ModelManifestEntry[];
296
- /** Present when the privacy add-on runs: its erasure service. */
297
- privacy?: {
298
- erasure: IErasureService;
299
- };
300
- /** Whether `/mcp` is mounted, after the option and MCP_ENABLED. */
301
- mcpEnabled: boolean;
302
- /** Whether `/graphql/inspection` is mounted, after the option and INSPECTION_ENABLED. */
303
- inspectionEnabled: boolean;
304
- /** The reactor's inspector, as the host reads it (processors, catch-up); undefined without inspection. */
305
- inspector: IInspector | undefined;
306
- /** The Renown instance if identity was initialized */
307
- renown: IRenown$1 | null;
308
- /**
309
- * Port the HTTP server actually bound to: the OS-picked one when 0 was
310
- * requested, the next free one when the requested port was in use.
311
- */
312
- port: number;
313
- /**
314
- * Idempotent. Owned reactor: runs the reactor module's memoized
315
- * `shutdown()` (kill, shutdown hooks incl. the api drain, database).
316
- * Caller-provided reactor: drains the api only (HTTP server, GraphQL
317
- * manager, attachments, MCP, read-model DB); the caller owns the reactor
318
- * and must call this from its own teardown.
319
- */
320
- shutdown: () => Promise<void>;
321
- };
322
- //#endregion
323
23
  //#region src/builder-defaults.d.mts
324
24
  type SwitchboardReactorDefaultsOptions = {
325
25
  documentModels?: DocumentModelModule[];
@@ -404,6 +104,8 @@ export declare function createReactorKysely(opts: {
404
104
  /** Open the PGlite store in its own worker thread. */
405
105
  pgliteWorkers: boolean;
406
106
  pgliteSettings?: PgliteStoreSettings;
107
+ /** The store, when it's already opening. */
108
+ openingStore?: PGliteLike;
407
109
  logger: ILogger;
408
110
  }): Promise<ReactorStorage>;
409
111
  export interface PgliteStorageDirs {
@@ -465,6 +167,6 @@ export declare function deriveAttachmentServiceConfig(options: Pick<StartServerO
465
167
  */
466
168
  export declare const startSwitchboard: (input?: SwitchboardConfigInput, deps?: SwitchboardDeps) => Promise<SwitchboardReactor>;
467
169
  //#endregion
468
- export type { SwitchboardReactorDefaultsOptions, WorkflowTriggersCapability };
170
+ export { IdentityOptions, StartServerOptions, StorageOptions, SwitchboardDeps, SwitchboardDriveDocumentType, SwitchboardDriveInput, SwitchboardReactor, type SwitchboardReactorDefaultsOptions, type WorkflowTriggersCapability };
469
171
  export {};
470
172
  //# sourceMappingURL=server.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.mts","names":[],"sources":["../src/pglite-version.ts","../src/pglite-store.mts","../src/privacy.mts","../src/types.ts","../src/builder-defaults.mts","../src/unsupported-stored-documents.mts","../src/server.mts"],"mappings":";;;;;;;;;;;;;;;;cAYa;KACD,2BAA2B;;;;UCuHtB;EACf;EACA,cAAc;EACd;;;;KC9GU;;EAEV;;EAEA;;EAEA,SAAS;;EAET;EACA;EACA;EACA;;;;;;;;;;YCXU;;YAKA,wBAAwB;EAClC,eAAe;;YAGL;EACV;EACA;EACA;;YAGU;;EAEV;;;;;EAKA;;EAGA;;;;;;;YAQU;;;;;;;;;;;;;;;;;;;;;EAqBV,UAAU;;;;;;;;EAQV;;;;;;;EAOA;;;;;EAKA,aAAa;;;;;;;EAOb;EACA;;;;;;;EAOA;;;;;;EAMA;EACA;EACA;EACA,QAAQ;EACR;EACA;EACA;IAEM;IACA;;;;;;;EASN,WAAW;;EAEX;;;EAGA;;;;;;EAMA,oBAAoB;;;EAGpB;;;;EAIA;;;EAGA;IACE;;;;;;;IAOA;MACE;MACA;QAAW;QAAkB;;MAC7B;QAAU;QAAkB;QAAqB;;;;;EAIrD,UAAU;EACV,kBAAkB;EAClB;EACA;;;;;;EAMA;EACA,SAAS;;;;;;;;;;EAUT;;;;;;;;;;EAUA;;;;;;;;;EASA;IACE;IACA;IACA;;;;;;;;;;;EAWF;IACE;IACA;;;;;;;;;EASF,6BAA6B;;;YAInB;EACV,SAAS;;EAET,UAAU;;EAEV,oBAAoB;;EAEpB,eAAe;;EAEf;;EAEA;;EAEA,aAAa;;EAEb,gBAAgB;;YAGN;EACV;EACA,SAAS;;;;EAIT,mBAAmB;;EAEnB,+BAA+B;;;EAG/B,mBAAmB;;EAEnB;;EAEA,iBAAiB;;EAEjB;IAAY,SAAS;;;EAErB;;EAEA;;EAEA,WAAW;;EAEX,QAAQ;;;;;EAKR;;;;;;;;EAQA,gBAAgB;;;;KCrRN;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;;;;;wBC6JE,uBACd,UAAS,KAAK;;;;;;wBAgCM,gBAAgB,eAAe;;wBA6ErC,iBACd,YAAY,2CACZ,mBACA,qBACC;;;;;;KA2CE;EACH,QAAQ,OAAO;EACf,qBAAqB;EACrB,cAAc;;EAEd,mBAAmB;;wBAGC,oBAAoB;EACxC;EACA;EACA,oBAAoB;EACpB;;EAEA;;EAEA;EACA,iBAAiB;EACjB,QAAQ;IACN,QAAQ;iBA+DK;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;;;;;;;;;;;;wBAcc,yBAAyB;EACvC;EACA;;EAEA;;EAEA;EACA;IACE;;wBAmCY,8BACd,SAAS,KAAK,uDACd,oBACA,QAAQ;EACL;EAAmB,YAAY;;;;;;;;;;;;;;;;;;;;qBAwxCvB,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;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;;;;;wBC+JE,uBACd,UAAS,KAAK;;;;;;wBAgCM,gBAAgB,eAAe;;wBA6ErC,iBACd,YAAY,2CACZ,mBACA,qBACC;;;;;;KA2CE;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;;;;;;;;;;;;;;;;;;;;qBAy1CvB,mBAAgB,QACpB,wBAAsB,OACvB,oBACL,QAAQ"}
package/dist/server.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { n as StoredDocumentsRefusedError, r as resolveUnsupportedStoredDocuments } from "./from-env-DuUwngOC.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-BJk9-9n4.mjs";
2
+ import { n as StoredDocumentsRefusedError, r as resolveUnsupportedStoredDocuments } from "./from-env-DJ4iQ3QZ.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-CgDvrUqE.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]="800514b1-f8ed-531e-b297-2a3d074b6531")}catch(e){}}();
6
- //# debugId=800514b1-f8ed-531e-b297-2a3d074b6531
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]="18bc1baf-624b-52ca-bbc8-6fc13dca85ac")}catch(e){}}();
6
+ //# debugId=18bc1baf-624b-52ca-bbc8-6fc13dca85ac
@@ -0,0 +1,308 @@
1
+ import { n as WorkflowTriggersCapability } from "./workflow-runtime-CF5pc8mt.mjs";
2
+ import { ILogger } from "document-model";
3
+ import { IInspector, IReactorClient, InProcessReactorClientModule, ModelManifestEntry, UnsupportedStoredDocuments } from "@powerhousedao/reactor";
4
+ import { AttachmentReferenceProjectionCapability } from "@powerhousedao/reactor-api";
5
+ import { ISigner } from "@powerhousedao/shared/document-model";
6
+ import { IErasureService } from "@powerhousedao/reactor-privacy";
7
+ import { IAttachmentService } from "@powerhousedao/reactor-attachments";
8
+ import { ResolvedPlugin } from "@powerhousedao/host-core";
9
+ import { DriveInput } from "@powerhousedao/shared/document-drive";
10
+ import { IRenown } from "@renown/sdk";
11
+ //#region src/privacy.d.mts
12
+ type PrivacyOptions = {
13
+ /** Wins over PH_PRIVACY_ENABLED. */
14
+ enabled?: boolean;
15
+ /** Wins over PH_PRIVACY_DEPLOYMENT_SECRET. */
16
+ deploymentSecret?: string;
17
+ /** The reactor's signer, for a caller-provided reactor. */
18
+ signer?: ISigner;
19
+ /** Each wins over its PH_PRIVACY_* env var. */
20
+ intervalMs?: number;
21
+ deadlineMs?: number;
22
+ markerGraceMs?: number;
23
+ purgeTimeoutMs?: number;
24
+ };
25
+ //#endregion
26
+ //#region src/types.d.ts
27
+ /**
28
+ * Drive container document type chosen for the boot-time default drive. The
29
+ * legacy `powerhouse/document-drive` keeps the existing behavior; the newer
30
+ * `powerhouse/reactor-drive` is wired through `ensureDrive` and
31
+ * uses the relationship-based child graph.
32
+ */
33
+ type SwitchboardDriveDocumentType = "powerhouse/document-drive" | "powerhouse/reactor-drive";
34
+ /** A {@link DriveInput} extended with the optional drive-container type. */
35
+ type SwitchboardDriveInput = DriveInput & {
36
+ documentType?: SwitchboardDriveDocumentType;
37
+ };
38
+ type StorageOptions = {
39
+ type: "filesystem" | "memory" | "postgres" | "browser";
40
+ filesystemPath?: string;
41
+ postgresUrl?: string;
42
+ };
43
+ type IdentityOptions = {
44
+ /** Path to the keypair file. Defaults to ~/.ph/keypair.json */
45
+ keypairPath?: string;
46
+ /**
47
+ * If true, won't start without an existing keypair.
48
+ * Use this to ensure the switchboard only runs with an authenticated identity.
49
+ */
50
+ requireExisting?: boolean;
51
+ /** Base url of the Renown instance to use */
52
+ baseUrl?: string;
53
+ };
54
+ /**
55
+ * The options view of a switchboard's config and deps: what plugins'
56
+ * `transformServerOptions` hook receives. `startSwitchboard` takes the
57
+ * config (`@powerhousedao/switchboard/config`) and {@link SwitchboardDeps}.
58
+ */
59
+ type StartServerOptions = {
60
+ /**
61
+ * Pre-built ReactorClientModule (typically from
62
+ * `@powerhousedao/reactor#ReactorClientBuilder.buildModule`). When set, the
63
+ * switchboard reuses the caller's reactor instead of building its own,
64
+ * and the caller owns the reactor's lifecycle. The API, GraphQL manager,
65
+ * MCP, attachments, package management subgraph, and registry HTTP loader
66
+ * are still configured around it.
67
+ *
68
+ * Lifecycle contract: switchboard does NOT wire itself into the caller's
69
+ * reactor shutdown. Callers must invoke `shutdown()` on the returned
70
+ * `SwitchboardReactor` from their own teardown (and SIGINT handlers) to
71
+ * drain `/graphql`, MCP, attachments, etc. Killing the caller's reactor
72
+ * alone will not release these resources.
73
+ *
74
+ * Setup contract: the reactor must have switchboard's expected wiring
75
+ * already applied — channel scheme, document models, signal handlers,
76
+ * etc. Use `applySwitchboardReactorDefaults` from this module to apply
77
+ * the same defaults switchboard uses internally; opt out of individual
78
+ * pieces as needed.
79
+ */
80
+ reactor?: InProcessReactorClientModule;
81
+ /**
82
+ * Route uncaught exceptions, and unhandled rejections nothing else listens
83
+ * for, through the reactor's SIGTERM shutdown, so PGlite stores are flushed
84
+ * before the process exits with code 1. Installed once the switchboard's own reactor is built;
85
+ * ignored when `reactor` is passed. For process entry points only, since
86
+ * it adds process-wide listeners.
87
+ */
88
+ fatalErrorShutdown?: boolean;
89
+ /**
90
+ * Install the owned reactor's SIGINT/SIGTERM handlers (default true).
91
+ * False when a supervisor owns the process exit (a `ph run` compound
92
+ * member): the reactor then stops only through `shutdown()`. Ignored with
93
+ * a caller-provided `reactor`.
94
+ */
95
+ signalHandlers?: boolean;
96
+ /**
97
+ * `/ready` waits for this too: drives the caller seeds after the server
98
+ * starts. A rejection leaves the server not ready.
99
+ */
100
+ readyAfter?: Promise<unknown>;
101
+ /**
102
+ * Registry URL for the HttpPackageLoader. Enables `PackagesSubgraph`
103
+ * (install/uninstall mutations) plus dynamic package resolution.
104
+ * Falls back to PH_REGISTRY_URL env, then `packageRegistryUrl` in the
105
+ * powerhouse config file.
106
+ */
107
+ registryUrl?: string;
108
+ configFile?: string;
109
+ /**
110
+ * 0 binds a port the OS picks, reported on the result's `port`: the only
111
+ * race-free choice when several instances start at once. A taken non-zero
112
+ * port falls back to the next free one, which another process can still
113
+ * claim between the probe and the bind.
114
+ */
115
+ port?: number;
116
+ /**
117
+ * If true, fail immediately when the requested port is in use instead of
118
+ * falling back to the next free port. Matches the semantics of Vite's
119
+ * `--strictPort` flag that flows through the `ph vetra` command.
120
+ */
121
+ strictPort?: boolean;
122
+ dev?: boolean;
123
+ dbPath?: string;
124
+ drive?: SwitchboardDriveInput;
125
+ packages?: string[];
126
+ remoteDrives?: string[];
127
+ https?: {
128
+ keyPath: string;
129
+ certPath: string;
130
+ } | boolean | undefined;
131
+ /**
132
+ * Identity options for Renown.
133
+ * When configured, the switchboard will load the keypair from `ph login`
134
+ * and can authenticate with remote services on behalf of the user.
135
+ */
136
+ identity?: IdentityOptions;
137
+ /** Base URL for the attachment service; defaults to `PH_SWITCHBOARD_PUBLIC_URL` then `http(s)://localhost:${port}`. */
138
+ attachmentServiceUrl?: string;
139
+ /** Mount the MCP server at `/mcp`. On by default; `false` wins over
140
+ * MCP_ENABLED, which can turn it off but never on. */
141
+ mcp?: boolean;
142
+ /** The plugin composition to boot with (FEATURE_PLUGIN_HOST_ENABLED): the
143
+ * resolved host.js runner.plugins entries, supplied by the uniform-runners
144
+ * switchboard runner (R2 step 2) or a test. Omitted = the built-in default
145
+ * composition. Resolved plugins, not specifiers — resolution happens at the
146
+ * runner against the PROJECT dependency tree. */
147
+ pluginComposition?: ResolvedPlugin[];
148
+ /** Mount the read-only inspection subgraph at `/graphql/inspection`. On by
149
+ * default; `false` wins over INSPECTION_ENABLED, which can turn it off. */
150
+ inspection?: boolean;
151
+ /** Open each PGlite store (reactor-storage, read-storage) in its own worker
152
+ * thread. Wins either way over PH_PGLITE_WORKERS; unset, the env var
153
+ * decides, then PGLITE_WORKERS_DEFAULT. */
154
+ pgliteWorkers?: boolean;
155
+ /** Powerhouse workflows: the runtime, its subgraph, its webhooks and its
156
+ * document models. Wins over PH_WORKFLOWS_ENABLED and the config file. */
157
+ workflows?: {
158
+ enabled?: boolean;
159
+ /** OAuth2 apps the publisher owns (`oauth_app` on a connection): per app,
160
+ * the provider's client files by kind. Wins over the config file's
161
+ * `workflows.oauthApps`; relative paths there are from the config file.
162
+ * `relay` is a token broker for the app's web client, used for a web
163
+ * sign-in when this host has no web client file: the provider needs only
164
+ * the broker's one redirect URI, and the secret stays with the broker. */
165
+ oauthApps?: {
166
+ id: string;
167
+ clients: {
168
+ desktop?: string;
169
+ web?: string;
170
+ };
171
+ relay?: {
172
+ clientId: string;
173
+ redirectUri: string;
174
+ tokenUrl: string;
175
+ };
176
+ }[];
177
+ };
178
+ /** The GDPR add-on; off unless this or PH_PRIVACY_ENABLED turns it on. */
179
+ privacy?: PrivacyOptions;
180
+ processorConfig?: Map<string, unknown>;
181
+ disableLocalPackages?: boolean;
182
+ enableDocumentModelSubgraphs?: boolean;
183
+ /**
184
+ * When true, enables dynamic loading of document models from the registry
185
+ * when an unknown document type is encountered during sync.
186
+ * Disabled by default — enable with DYNAMIC_MODEL_LOADING=true env var.
187
+ */
188
+ dynamicModelLoading?: boolean;
189
+ logger?: ILogger;
190
+ /**
191
+ * When true, on startup any local PGLite data dirs whose `PG_VERSION` is
192
+ * older than the bundled PGLite are migrated to the current version
193
+ * (backup → dump → restore) before the server boots. When false, the
194
+ * server logs a warning and runs against the legacy data using the
195
+ * matching legacy PGLite module.
196
+ *
197
+ * Triggered by the `--migrate-pglite` CLI flag or `PH_MIGRATE_PGLITE=true`.
198
+ */
199
+ migratePglite?: boolean;
200
+ /**
201
+ * Force a specific PGLite-embedded PG major (16 or 17) on startup.
202
+ *
203
+ * **Destructive**: any existing local PGLite data dirs are wiped before
204
+ * the chosen PGLite re-`initdb`'s them at the requested version. Postgres
205
+ * URLs are unaffected. Takes precedence over `migratePglite`.
206
+ *
207
+ * Triggered by `PH_FORCE_PG_VERSION=16|17`.
208
+ */
209
+ forcePgVersion?: 16 | 17;
210
+ /**
211
+ * Executor worker pool: `numWorkers > 0` runs jobs in N worker threads;
212
+ * `"auto"` sizes the pool from the machine's available cores; 0 or unset
213
+ * keeps the in-process executor (the default). Unset fields fall back to
214
+ * the REACTOR_WORKERS / REACTOR_DB_* env vars. Requires a Postgres reactor
215
+ * database; incompatible with `dev` mode (Vite-loaded models cannot cross
216
+ * a thread boundary).
217
+ */
218
+ workerPool?: {
219
+ numWorkers?: number | "auto";
220
+ dbPoolSizePerWorker?: number;
221
+ acquireTimeoutMs?: number;
222
+ };
223
+ /**
224
+ * Projection worker: `enabled` runs the built-in document-view /
225
+ * document-indexer read models in one worker thread, off the host event
226
+ * loop; unset keeps them in-process (the default). Unset fields fall back
227
+ * to the REACTOR_PROJECTION_WORKER / REACTOR_DB_POOL_SIZE_PROJECTION env
228
+ * vars. Requires a Postgres reactor database and worker-importable
229
+ * document-model sources (switchboard resolves them itself); incompatible
230
+ * with `dev` mode (Vite-loaded models cannot cross a thread boundary).
231
+ */
232
+ projectionWorker?: {
233
+ enabled?: boolean;
234
+ dbPoolSize?: number;
235
+ };
236
+ /**
237
+ * Stored documents at protocol versions this build does not run: "refuse"
238
+ * (the default) fails the boot with a StoredDocumentsRefusedError;
239
+ * "read-only" starts with a warning and keeps those documents read-only.
240
+ * Unset falls back to the REACTOR_UNSUPPORTED_STORED_DOCUMENTS env var.
241
+ * Ignored when `reactor` is passed.
242
+ */
243
+ unsupportedStoredDocuments?: UnsupportedStoredDocuments;
244
+ };
245
+ /** What a switchboard is started with that is not a setting. */
246
+ type SwitchboardDeps = {
247
+ logger?: ILogger;
248
+ /** See {@link StartServerOptions.reactor}. */
249
+ reactor?: InProcessReactorClientModule;
250
+ /** See {@link StartServerOptions.pluginComposition}. */
251
+ pluginComposition?: ResolvedPlugin[];
252
+ /** Receives failures in background work; Sentry by default. */
253
+ reportError?: (error: unknown) => void;
254
+ /** See {@link StartServerOptions.fatalErrorShutdown}. */
255
+ fatalErrorShutdown?: boolean;
256
+ /** See {@link StartServerOptions.signalHandlers}. */
257
+ signalHandlers?: boolean;
258
+ /** See {@link StartServerOptions.readyAfter}. */
259
+ readyAfter?: Promise<unknown>;
260
+ /** The privacy add-on's signer, for a caller-provided reactor. */
261
+ privacySigner?: ISigner;
262
+ };
263
+ type SwitchboardReactor = {
264
+ defaultDriveUrl: string | undefined;
265
+ reactor: IReactorClient;
266
+ /** Switchboard-backed remote attachment service over its own `/attachments/*` API, for downstream consumers.
267
+ * Undefined when the attachments plugin is absent from the composition
268
+ * (FEATURE_PLUGIN_HOST_ENABLED — presence is activation, rewire R2.3). */
269
+ attachmentService: IAttachmentService | undefined;
270
+ /** Whether the authoritative attachment-reference projection is active. */
271
+ attachmentReferenceProjection: AttachmentReferenceProjectionCapability;
272
+ /** Whether the workflow runtime's operation intake is indexing. Undefined
273
+ * when workflows are off; unavailable means no document trigger fires. */
274
+ workflowTriggers?: WorkflowTriggersCapability;
275
+ /** Whether workflows are on, after the option, PH_WORKFLOWS_ENABLED and the config file. */
276
+ workflowsEnabled: boolean;
277
+ /** The boot list of importable models workers and workflow pieces load; empty when none are resolved. */
278
+ modelManifest(): ModelManifestEntry[];
279
+ /** Present when the privacy add-on runs: its erasure service. */
280
+ privacy?: {
281
+ erasure: IErasureService;
282
+ };
283
+ /** Whether `/mcp` is mounted, after the option and MCP_ENABLED. */
284
+ mcpEnabled: boolean;
285
+ /** Whether `/graphql/inspection` is mounted, after the option and INSPECTION_ENABLED. */
286
+ inspectionEnabled: boolean;
287
+ /** The reactor's inspector, as the host reads it (processors, catch-up); undefined without inspection. */
288
+ inspector: IInspector | undefined;
289
+ /** The Renown instance if identity was initialized */
290
+ renown: IRenown | null;
291
+ /**
292
+ * Port the HTTP server actually bound to: the OS-picked one when 0 was
293
+ * requested, the next free one when the requested port was in use.
294
+ */
295
+ port: number;
296
+ /**
297
+ * Idempotent. Owned reactor: runs the reactor module's memoized
298
+ * `shutdown()` (kill, shutdown hooks incl. the api drain, database).
299
+ * Caller-provided reactor: drains the api only (HTTP server, GraphQL
300
+ * manager, attachments, MCP, read-model DB); the caller owns the reactor
301
+ * and must call this from its own teardown.
302
+ */
303
+ shutdown: () => Promise<void>;
304
+ };
305
+ //#endregion
306
+ export { SwitchboardDriveDocumentType as a, SwitchboardDeps as i, StartServerOptions as n, SwitchboardDriveInput as o, StorageOptions as r, SwitchboardReactor as s, IdentityOptions as t };
307
+ export {};
308
+ //# sourceMappingURL=types-DzO3_320.d.mts.map