@powerhousedao/switchboard 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 (68) hide show
  1. package/.tsbuild/test/boot-helpers.d.ts +2 -1
  2. package/.tsbuild/test/boot-helpers.d.ts.map +1 -1
  3. package/.tsbuild/test/boot-identity-files.test.d.ts +2 -0
  4. package/.tsbuild/test/boot-identity-files.test.d.ts.map +1 -0
  5. package/.tsbuild/tsconfig.tsbuildinfo +1 -1
  6. package/CHANGELOG.md +59 -0
  7. package/README.md +12 -10
  8. package/dist/boot.d.mts +1 -1
  9. package/dist/boot.mjs +1 -1
  10. package/dist/config/from-env.d.mts +1 -1
  11. package/dist/config/from-env.d.mts.map +1 -1
  12. package/dist/config/from-env.mjs +3 -3
  13. package/dist/config/schema.d.mts +1 -1
  14. package/dist/config/schema.mjs +3 -3
  15. package/dist/{from-env-DKK_wPrO.mjs → from-env-CLImR6qa.mjs} +4 -28
  16. package/dist/from-env-CLImR6qa.mjs.map +1 -0
  17. package/dist/index.mjs +3 -3
  18. package/dist/migrate.mjs +9 -4
  19. package/dist/migrate.mjs.map +1 -1
  20. package/dist/{plugin-host-tTjDTNz0.d.mts → plugin-host-Z-4Ruypj.d.mts} +19 -2
  21. package/dist/plugin-host-Z-4Ruypj.d.mts.map +1 -0
  22. package/dist/plugins/ai.d.mts +1 -1
  23. package/dist/plugins/attachments.d.mts +1 -1
  24. package/dist/plugins/attachments.mjs +3 -3
  25. package/dist/plugins/mcp.d.mts +1 -1
  26. package/dist/plugins/privacy.d.mts +1 -1
  27. package/dist/plugins/workflows.d.mts +2 -2
  28. package/dist/plugins/workflows.mjs +3 -3
  29. package/dist/{schema-BJ-OFAox.mjs → schema-BbwISVSO.mjs} +15 -13
  30. package/dist/schema-BbwISVSO.mjs.map +1 -0
  31. package/dist/{schema-w1lShimw.d.mts → schema-CZsLzAZg.d.mts} +9 -4
  32. package/dist/schema-CZsLzAZg.d.mts.map +1 -0
  33. package/dist/{server-BS-PFzoK.mjs → server-BMRdMNvC.mjs} +172 -244
  34. package/dist/server-BMRdMNvC.mjs.map +1 -0
  35. package/dist/server.d.mts +2 -2
  36. package/dist/server.d.mts.map +1 -1
  37. package/dist/server.mjs +4 -4
  38. package/dist/{types-Bk4T4D9F.d.mts → types-Crizw8W4.d.mts} +13 -8
  39. package/dist/types-Crizw8W4.d.mts.map +1 -0
  40. package/dist/{utils-Cm0TE6dP.mjs → utils-D8yHRVjT.mjs} +4 -18
  41. package/dist/{utils-Cm0TE6dP.mjs.map → utils-D8yHRVjT.mjs.map} +1 -1
  42. package/dist/utils.d.mts +1 -6
  43. package/dist/utils.d.mts.map +1 -1
  44. package/dist/utils.mjs +4 -4
  45. package/dist/{workflows-mdYUh3Us.mjs → workflows-D2r6IKou.mjs} +4 -4
  46. package/dist/{workflows-mdYUh3Us.mjs.map → workflows-D2r6IKou.mjs.map} +1 -1
  47. package/package.json +17 -17
  48. package/test/ai-gateway.test.ts +0 -2
  49. package/test/boot-auth-config.test.ts +1 -1
  50. package/test/boot-helpers.ts +3 -1
  51. package/test/boot-identity-files.test.ts +68 -0
  52. package/test/boot-mcp-auth.test.ts +0 -1
  53. package/test/boot-mcp-enabled.test.ts +0 -2
  54. package/test/boot-port-zero.test.ts +1 -2
  55. package/test/boot-ready-drives.test.ts +1 -2
  56. package/test/config-from-env.test.ts +0 -9
  57. package/test/config-merge.test.ts +47 -47
  58. package/test/config-schema.test.ts +16 -4
  59. package/test/default-composition.test.ts +61 -65
  60. package/test/default-drive-protocol-versions.test.ts +13 -6
  61. package/test/default-drive-slug.test.ts +6 -11
  62. package/test/plugin-presence.test.ts +15 -16
  63. package/dist/from-env-DKK_wPrO.mjs.map +0 -1
  64. package/dist/plugin-host-tTjDTNz0.d.mts.map +0 -1
  65. package/dist/schema-BJ-OFAox.mjs.map +0 -1
  66. package/dist/schema-w1lShimw.d.mts.map +0 -1
  67. package/dist/server-BS-PFzoK.mjs.map +0 -1
  68. package/dist/types-Bk4T4D9F.d.mts.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,62 @@
1
+ ## 6.4.0-next.1 (2026-11-22)
2
+
3
+ ### 🚀 Features
4
+
5
+ - **vetra:** move the ideate and build spec documents from vetra-cli ([bfc530d0f3](https://github.com/powerhouse-inc/powerhouse/commit/bfc530d0f3))
6
+
7
+ ### ❤️ Thank You
8
+
9
+ - Claude
10
+ - Wouter Kampmann
11
+
12
+ ## 6.4.0-next.0 (2026-11-22)
13
+
14
+ ### 🚀 Features
15
+
16
+ - **switchboard:** identity.storagePath names the renown user file ([877a9a33d4](https://github.com/powerhouse-inc/powerhouse/commit/877a9a33d4))
17
+ - **codegen,ph-cli,shared:** a package with a cli declares clint as a versioned peer ([40936957cb](https://github.com/powerhouse-inc/powerhouse/commit/40936957cb))
18
+ - **ph-cli,shared:** the cli of a package is its own build, with declared packages external ([8504275af5](https://github.com/powerhouse-inc/powerhouse/commit/8504275af5))
19
+ - **clint-common:** port the chat-session package from ph-clint dev.113 ([d21119c6a9](https://github.com/powerhouse-inc/powerhouse/commit/d21119c6a9))
20
+ - **clint:** add the ./cli package export and the cli runner ([64bb9f10c9](https://github.com/powerhouse-inc/powerhouse/commit/64bb9f10c9))
21
+ - ⚠️ **switchboard:** remove addDefaultDrive and addDefaultReactorDrive ([a398d5ce83](https://github.com/powerhouse-inc/powerhouse/commit/a398d5ce83))
22
+ - ⚠️ **config:** superseded powerhouse.config.json keys are errors ([5db0117db3](https://github.com/powerhouse-inc/powerhouse/commit/5db0117db3))
23
+ - **ph-cli:** ph run connect build takes --base and --packages-registry ([894d5a7f31](https://github.com/powerhouse-inc/powerhouse/commit/894d5a7f31))
24
+ - **switchboard:** say so when a removed switch is still set ([f13ae91013](https://github.com/powerhouse-inc/powerhouse/commit/f13ae91013))
25
+ - ⚠️ **switchboard:** the plugin host is the only boot path ([fc8ba25655](https://github.com/powerhouse-inc/powerhouse/commit/fc8ba25655))
26
+ - ⚠️ **ph-cli:** a project without hosts is an error ([33b90cff3d](https://github.com/powerhouse-inc/powerhouse/commit/33b90cff3d))
27
+
28
+ ### 🩹 Fixes
29
+
30
+ - **host-core,ph-run:** linux failures in the next/6.4 checks ([0fdc5a4797](https://github.com/powerhouse-inc/powerhouse/commit/0fdc5a4797))
31
+
32
+ ### ⚠️ Breaking Changes
33
+
34
+ - **switchboard:** remove addDefaultDrive and addDefaultReactorDrive ([a398d5ce83](https://github.com/powerhouse-inc/powerhouse/commit/a398d5ce83))
35
+ addDefaultDrive and addDefaultReactorDrive are removed from
36
+ @powerhousedao/switchboard/utils. Call ensureDrive; pass
37
+ `documentType: "powerhouse/reactor-drive"` for a reactor drive.
38
+ Co-Authored-By: Claude <noreply@anthropic.com>
39
+ - **config:** superseded powerhouse.config.json keys are errors ([5db0117db3](https://github.com/powerhouse-inc/powerhouse/commit/5db0117db3))
40
+ ph run refuses a project whose powerhouse.config.json sets studio.host,
41
+ studio.https, studio.openBrowser, reactor.https, reactor.storage or switchboard.database.url.
42
+ Run ph migrate, or move the value to the host file and remove the key.
43
+ Co-Authored-By: Claude <noreply@anthropic.com>
44
+ - **switchboard:** the plugin host is the only boot path ([fc8ba25655](https://github.com/powerhouse-inc/powerhouse/commit/fc8ba25655))
45
+ FEATURE_PLUGIN_HOST_ENABLED=false refuses to start, and
46
+ FEATURE_PLUGIN_HOST_ENABLED=1 without declared plugins no longer boots
47
+ every built-in plugin. reactor.workflows in a host file fails validation.
48
+ A host with only readModel.url must name its reactor store. The config
49
+ file's workflows.enabled no longer turns workflows on in Switchboard.
50
+ Co-Authored-By: Claude <noreply@anthropic.com>
51
+ - **ph-cli:** a project without hosts is an error ([33b90cff3d](https://github.com/powerhouse-inc/powerhouse/commit/33b90cff3d))
52
+ the classic commands need a hosts/ folder; run ph migrate.
53
+ Co-Authored-By: Claude <noreply@anthropic.com>
54
+
55
+ ### ❤️ Thank You
56
+
57
+ - Claude
58
+ - Wouter Kampmann
59
+
1
60
  ## 6.3.0-dev.9 (2026-11-22)
2
61
 
3
62
  ### 🚀 Features
package/README.md CHANGED
@@ -102,19 +102,20 @@ pnpm add -g @powerhousedao/switchboard
102
102
 
103
103
  | Variable | Description | Default |
104
104
  | -------------------------------- | ------------------------------------------------------------------------------ | --------------------- |
105
- | `PORT` | Server port | `4001` |
106
- | `DATABASE_URL` | Database connection string | `./.ph/drive-storage` |
107
- | `PH_REACTOR_DATABASE_URL` | PostgreSQL URL (takes precedence) | - |
105
+ | `PORT` | Server port. The bare `switchboard` bin reads `PH_SWITCHBOARD_PORT` instead | `4001` |
106
+ | `DATABASE_URL` | Postgres URL of the read model | `./.ph/read-storage` |
107
+ | `PH_REACTOR_DATABASE_URL` | Postgres URL of the reactor store | PGlite |
108
108
  | `REACTOR_DB_POOL_SIZE_HOST` | Reactor host Postgres pool size | `16` |
109
109
  | `REDIS_URL` | Redis connection URL | - |
110
110
  | `REDIS_TLS_URL` | Redis TLS connection URL | - |
111
111
  | `PYROSCOPE_SERVER_ADDRESS` | Pyroscope server address | - |
112
- | `FEATURE_REACTORV2_ENABLED` | Enable Reactor v2 subgraph feature | `false` |
113
112
  | `MCP_ENABLED` | `false` keeps `/mcp` unmounted | `true` |
114
113
  | `INSPECTION_ENABLED` | `false` keeps inspection unmounted | `true` |
115
114
  | `PH_INSPECTION_CALLS_PER_MINUTE` | `validateDocument`/`driveIntegrity` calls per caller per minute; admins exempt | `6` |
116
115
  | `PH_HOST_VALIDATION` | `refuse` leaves out a model host validation flags; `log` serves it | `log` |
117
116
 
117
+ `PH_SWITCHBOARD_DATABASE_URL` is an older name that is still read: the reactor store falls back to it when `PH_REACTOR_DATABASE_URL` is unset, and the read model when `DATABASE_URL` is unset. The public URL is `PUBLIC_URL`; `PH_SWITCHBOARD_PUBLIC_URL` is a different setting, the address of the attachment service.
118
+
118
119
  See [Observability](#observability) below for Sentry and OpenTelemetry variables.
119
120
 
120
121
  ### Executor Worker Pool
@@ -144,7 +145,7 @@ Requirements when `REACTOR_WORKERS > 0`:
144
145
  so switchboard refuses to start on local PGlite storage.
145
146
  - **Built packages only.** Worker threads import document models by file path,
146
147
  so every configured package needs a built `document-models` entry. `dev`
147
- mode (Vite-loaded models, e.g. `ph vetra`) is rejected.
148
+ mode (Vite-loaded models, e.g. `ph dev`) is rejected.
148
149
  - **Connection budget.** Total Postgres connections are roughly
149
150
  `REACTOR_DB_POOL_SIZE_HOST + REACTOR_WORKERS x REACTOR_DB_POOL_SIZE_WORKER`;
150
151
  keep this under the server's `max_connections`. Behind a connection pooler,
@@ -334,6 +335,7 @@ What runs depends on which environment variables are set:
334
335
  - `ENABLE_TRACING=true` or `NODE_ENV=production`, **and** at least one trace destination is configured (`TEMPO_ENDPOINT` or `SENTRY_DSN`) → OpenTelemetry tracing is initialized. Spans go to Tempo over OTLP HTTP if `TEMPO_ENDPOINT` is set, and/or to Sentry via `SentrySpanProcessor` if `SENTRY_DSN` is set. When both are set, the same trace IDs appear in Tempo and Sentry and cross-link in Grafana.
335
336
  - Tracing requested (prod or `ENABLE_TRACING=true`) but no destination configured → a warning is logged and tracing is **not** started. This avoids the cost of patching `http`/`express`/`pg`/`graphql` and generating spans only to drop them. Set `TEMPO_ENDPOINT` and/or `SENTRY_DSN` to enable.
336
337
  - `OTEL_EXPORTER_OTLP_ENDPOINT` set → metrics export to that OTLP HTTP endpoint via a periodic reader. Reactor metrics emitted by `@powerhousedao/opentelemetry-instrumentation-reactor` flow through the same global meter provider.
338
+ - `SENTRY_TRACING_ENABLED=false` → spans are kept out of Sentry while errors still go there and traces still go to Tempo. It does not switch tracing on or off; `ENABLE_TRACING` does.
337
339
 
338
340
  If neither Sentry nor a tracing destination is configured, the module is a no-op and no exporters or instrumentations are registered.
339
341
 
@@ -345,7 +347,7 @@ If neither Sentry nor a tracing destination is configured, the module is a no-op
345
347
  | `SENTRY_ENV` | `environment` tag passed to `Sentry.init`. | - |
346
348
  | `SENTRY_RELEASE` | Release tag (must match the version uploaded by CI for source maps to resolve). | `v${npm_package_version}` if available |
347
349
  | `SENTRY_TRACES_SAMPLE_RATE` | APM sampling rate (0.0–1.0). | `0.1` |
348
- | `ENABLE_TRACING` | Set to `true` to request tracing outside production. Tracing only starts when a destination is also set. | `false` (also requested when `NODE_ENV=production`) |
350
+ | `ENABLE_TRACING` | The tracing switch: `true` requests tracing outside production. Tracing only starts when a destination is also set. | `false` (also requested when `NODE_ENV=production`) |
349
351
  | `NODE_ENV` | When `production`, tracing is requested automatically. Also exported as `deployment.environment` attribute. | `development` |
350
352
  | `OTEL_SERVICE_NAME` | `service.name` resource attribute. | `switchboard` |
351
353
  | `TENANT_ID` | `tenant.id` resource attribute (used to slice traces by tenant in Grafana). | `default` |
@@ -473,11 +475,11 @@ ph switchboard --db-path postgresql://user:pass@localhost:5432/db --migrate-stat
473
475
 
474
476
  The migration commands check for a PostgreSQL URL in this order:
475
477
 
476
- 1. `PH_REACTOR_DATABASE_URL`
477
- 2. `DATABASE_URL`
478
- 3. Config file (`powerhouse.config.json` -> `switchboard.database.url`)
478
+ 1. `PH_SWITCHBOARD_DATABASE_URL`
479
+ 2. `PH_REACTOR_DATABASE_URL`
480
+ 3. `DATABASE_URL`
479
481
 
480
- If no PostgreSQL URL is found, migrations are skipped with a message (PGlite handles migrations automatically).
482
+ If no PostgreSQL URL is found, migrations are skipped with a message (PGlite handles migrations automatically). `powerhouse.config.json` -> `switchboard.database.url` was removed in 6.4: when it is set and none of the variables is, `pnpm migrate` stops with an error instead of skipping.
481
483
 
482
484
  #### CI/CD Integration
483
485
 
package/dist/boot.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as SwitchboardConfigInput } from "./schema-w1lShimw.mjs";
1
+ import { a as SwitchboardConfigInput } from "./schema-CZsLzAZg.mjs";
2
2
  import { RenownConfig } from "@powerhousedao/reactor-api";
3
3
  //#region src/boot-preconditions.d.mts
4
4
  /** What the server refuses to boot with; it throws the first, `ph host check` reports all. */
package/dist/boot.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  !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]="a17538e0-6085-5bb6-9d91-8f8c2a2b1c82")}catch(e){}}();
3
3
  import { d as reactorDbUrlOf, f as switchboardBootIssues, l as resolveProjectionWorkerOptions, m as workerTrustPolicyIssue, o as resolveWorkerPoolOptions, p as workerPoolIssues, u as projectionWorkerIssues } from "./worker-pool-gyxJnCxA.mjs";
4
- import { i as switchboardConfigSchema } from "./schema-BJ-OFAox.mjs";
4
+ import { i as switchboardConfigSchema } from "./schema-BbwISVSO.mjs";
5
5
  import { r as resolveReactorFeatureFlags, t as renownLayers } from "./renown-layers-DmbWLt46.mjs";
6
6
  //#region src/boot.mts
7
7
  const noop = () => {};
@@ -1,4 +1,4 @@
1
- import { a as SwitchboardConfigInput } from "../schema-w1lShimw.mjs";
1
+ import { a as SwitchboardConfigInput } from "../schema-CZsLzAZg.mjs";
2
2
  import { ILogger } from "document-model";
3
3
  //#region src/config/from-env.d.ts
4
4
  type Env = Readonly<Record<string, string | undefined>>;
@@ -1 +1 @@
1
- {"version":3,"file":"from-env.d.mts","names":[],"sources":["../../src/config/from-env.ts"],"mappings":";;;KAqCK,MAAM,SAAS;KACf,SAAS;iBAEG;;EAEf;EACA,SAAS;;;wBAIK,yBACd,KAAK,KACL,UAAS,kCACR"}
1
+ {"version":3,"file":"from-env.d.mts","names":[],"sources":["../../src/config/from-env.ts"],"mappings":";;;KAoCK,MAAM,SAAS;KACf,SAAS;iBAEG;;EAEf;EACA,SAAS;;;wBAIK,yBACd,KAAK,KACL,UAAS,kCACR"}
@@ -1,4 +1,4 @@
1
- import { t as switchboardConfigFromEnv } from "../from-env-DKK_wPrO.mjs";
1
+ import { t as switchboardConfigFromEnv } from "../from-env-CLImR6qa.mjs";
2
2
  export { switchboardConfigFromEnv };
3
- !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]="84ceaf32-3ebb-5a1a-a4d2-23453a7fd416")}catch(e){}}();
4
- //# debugId=84ceaf32-3ebb-5a1a-a4d2-23453a7fd416
3
+ !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]="3ca02909-01e8-579b-8e62-45c90a982e66")}catch(e){}}();
4
+ //# debugId=3ca02909-01e8-579b-8e62-45c90a982e66
@@ -1,3 +1,3 @@
1
- import { a as SwitchboardConfigInput, c as callerOverEnv, i as SwitchboardConfig, l as mergeSwitchboardConfig, n as SWITCHBOARD_DRIVE_DOCUMENT_TYPES, o as switchboardConfigLayerSchema, r as SWITCHBOARD_LOG_LEVELS, s as switchboardConfigSchema, t as ReactorApiSectionsMatch } from "../schema-w1lShimw.mjs";
1
+ import { a as SwitchboardConfigInput, c as callerOverEnv, i as SwitchboardConfig, l as mergeSwitchboardConfig, n as SWITCHBOARD_DRIVE_DOCUMENT_TYPES, o as switchboardConfigLayerSchema, r as SWITCHBOARD_LOG_LEVELS, s as switchboardConfigSchema, t as ReactorApiSectionsMatch } from "../schema-CZsLzAZg.mjs";
2
2
  export { ReactorApiSectionsMatch, SWITCHBOARD_DRIVE_DOCUMENT_TYPES, SWITCHBOARD_LOG_LEVELS, SwitchboardConfig, SwitchboardConfigInput, callerOverEnv, mergeSwitchboardConfig, switchboardConfigLayerSchema, switchboardConfigSchema };
3
3
  export {};
@@ -1,4 +1,4 @@
1
- import { a as callerOverEnv, i as switchboardConfigSchema, n as SWITCHBOARD_LOG_LEVELS, o as mergeSwitchboardConfig, r as switchboardConfigLayerSchema, t as SWITCHBOARD_DRIVE_DOCUMENT_TYPES } from "../schema-BJ-OFAox.mjs";
1
+ import { a as callerOverEnv, i as switchboardConfigSchema, n as SWITCHBOARD_LOG_LEVELS, o as mergeSwitchboardConfig, r as switchboardConfigLayerSchema, t as SWITCHBOARD_DRIVE_DOCUMENT_TYPES } from "../schema-BbwISVSO.mjs";
2
2
  export { SWITCHBOARD_DRIVE_DOCUMENT_TYPES, SWITCHBOARD_LOG_LEVELS, callerOverEnv, mergeSwitchboardConfig, switchboardConfigLayerSchema, switchboardConfigSchema };
3
- !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]="d14502cb-5df1-559d-89d6-197065648717")}catch(e){}}();
4
- //# debugId=d14502cb-5df1-559d-89d6-197065648717
3
+ !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]="1b337710-1874-5d73-a9fb-7f6da3026a74")}catch(e){}}();
4
+ //# debugId=1b337710-1874-5d73-a9fb-7f6da3026a74
@@ -1,9 +1,9 @@
1
1
 
2
- !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]="07dc4fe8-4324-5fd8-a39e-c856c27d4537")}catch(e){}}();
2
+ !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]="a5dbd86a-bb41-5030-ad5f-2636c1aa825b")}catch(e){}}();
3
3
  import { c as parseOnOff, h as parseNonNegativeInt, i as resolveHostPoolSize, r as parseWorkerCount } from "./worker-pool-gyxJnCxA.mjs";
4
4
  import { t as isPostgresUrl } from "./postgres-url-DTDhBjXX.mjs";
5
5
  import { t as privacyTimingsFromEnv } from "./privacy-HQnhqf2H.mjs";
6
- import { n as SWITCHBOARD_LOG_LEVELS } from "./schema-BJ-OFAox.mjs";
6
+ import { n as SWITCHBOARD_LOG_LEVELS } from "./schema-BbwISVSO.mjs";
7
7
  import { createRequire } from "node:module";
8
8
  import { childLogger } from "document-model";
9
9
  import { isProcessorTimingLevel, parseCatchUpPriority, parseKeyframeSettings, parseMemoryTelemetryOutputs, parseMemoryTelemetrySwitch, storedRefusalName } from "@powerhousedao/reactor";
@@ -146,29 +146,6 @@ async function loadPgDump(major) {
146
146
  return (await import("@electric-sql/pglite-tools/pg_dump")).pgDump;
147
147
  }
148
148
  //#endregion
149
- //#region src/plugin-host-flag.mts
150
- const PLUGIN_HOST_FLAG = "FEATURE_PLUGIN_HOST_ENABLED";
151
- function isPluginHostEnabled(env) {
152
- const value = env[PLUGIN_HOST_FLAG]?.trim().toLowerCase();
153
- return value === "1" || value === "true";
154
- }
155
- /** The values that ask for the deprecated inline boot, the ones the
156
- * deprecation warning names (shared/clis FALSE_VALUES). */
157
- const INLINE_BOOT_VALUES = /* @__PURE__ */ new Set([
158
- "false",
159
- "0",
160
- "off",
161
- "no"
162
- ]);
163
- /** What the variable asks for: true the declared composition, false the
164
- * deprecated inline boot. Blank or any other value asks for nothing, and the
165
- * default composition boots. */
166
- function pluginHostFromEnv(env) {
167
- if (isPluginHostEnabled(env)) return true;
168
- const value = env[PLUGIN_HOST_FLAG]?.trim().toLowerCase();
169
- return value !== void 0 && INLINE_BOOT_VALUES.has(value) ? false : void 0;
170
- }
171
- //#endregion
172
149
  //#region src/unsupported-stored-documents.mts
173
150
  const MODES = ["refuse", "read-only"];
174
151
  /** From REACTOR_UNSUPPORTED_STORED_DOCUMENTS; `input` wins when defined. */
@@ -294,7 +271,6 @@ function switchboardConfigFromEnv(env, options = {}) {
294
271
  mcp: openFeatureFlag(env.MCP_ENABLED),
295
272
  workflows: workflowsFromEnv(env.PH_WORKFLOWS_ENABLED),
296
273
  documentModelSubgraphs: openFeatureFlag(env.DOCUMENT_MODEL_SUBGRAPHS_ENABLED),
297
- pluginHost: pluginHostFromEnv(env),
298
274
  privacy: {
299
275
  enabled: privacyOn,
300
276
  deploymentSecret: env.PH_PRIVACY_DEPLOYMENT_SECRET,
@@ -493,5 +469,5 @@ function withoutUnset(value) {
493
469
  //#endregion
494
470
  export { loadNodeFsClass as a, openForVerify as c, ATTACHMENT_URL_SIGNING_SECRET_ENV as d, resolveAttachmentUrlSigning as f, isSupportedMajor as i, pgliteModuleSpec as l, StoredDocumentsRefusedError as n, loadPGliteModule as o, resolveUnsupportedStoredDocuments as r, loadPgDump as s, switchboardConfigFromEnv as t, readPgVersionFile as u };
495
471
 
496
- //# sourceMappingURL=from-env-DKK_wPrO.mjs.map
497
- //# debugId=07dc4fe8-4324-5fd8-a39e-c856c27d4537
472
+ //# sourceMappingURL=from-env-CLImR6qa.mjs.map
473
+ //# debugId=a5dbd86a-bb41-5030-ad5f-2636c1aa825b
@@ -0,0 +1 @@
1
+ {"version":3,"file":"from-env-CLImR6qa.mjs","sources":["../src/attachments/url-signer.ts","../src/inspection-throttle.mts","../src/pglite-version.ts","../src/unsupported-stored-documents.mts","../src/config/drive-type.ts","../src/config/from-env.ts"],"sourcesContent":["import type { AttachmentHash } from \"@powerhousedao/reactor\";\nimport { createHmac, randomBytes, timingSafeEqual } from \"node:crypto\";\n\nexport const ATTACHMENT_URL_SIGNING_SECRET_ENV =\n \"PH_ATTACHMENT_URL_SIGNING_SECRET\";\n\nconst MIN_SECRET_LENGTH = 32;\nconst EXPIRES_PATTERN = /^[1-9]\\d{0,15}$/;\nconst SIGNATURE_PATTERN = /^[A-Za-z0-9_-]{43}$/;\n\nexport type SignedAttachmentUrl = {\n query: string;\n expiresAtUtc: string;\n};\n\n// The filesystem counterpart of an S3 presigned GET.\nexport class AttachmentUrlSigner {\n constructor(\n private readonly secret: string | Buffer,\n private readonly now: () => number = Date.now,\n ) {}\n\n sign(\n hash: AttachmentHash,\n documentId: string,\n ttlSeconds: number,\n ): SignedAttachmentUrl {\n const expires = Math.floor(this.now() / 1000) + ttlSeconds;\n const params = new URLSearchParams({\n documentId,\n expires: String(expires),\n signature: this.mac(hash, documentId, String(expires)),\n });\n return {\n query: params.toString(),\n expiresAtUtc: new Date(expires * 1000).toISOString(),\n };\n }\n\n verify(\n hash: AttachmentHash,\n documentId: string,\n expires: string,\n signature: string,\n ): boolean {\n if (!EXPIRES_PATTERN.test(expires) || !SIGNATURE_PATTERN.test(signature)) {\n return false;\n }\n if (Number(expires) * 1000 <= this.now()) {\n return false;\n }\n const expected = Buffer.from(this.mac(hash, documentId, expires));\n const presented = Buffer.from(signature);\n return (\n expected.length === presented.length &&\n timingSafeEqual(expected, presented)\n );\n }\n\n private mac(hash: string, documentId: string, expires: string): string {\n return createHmac(\"sha256\", this.secret)\n .update(\n JSON.stringify([\"attachment-download/v1\", hash, documentId, expires]),\n )\n .digest(\"base64url\");\n }\n}\n\nexport type AttachmentUrlSigning =\n | { status: \"configured\"; signer: AttachmentUrlSigner }\n | { status: \"ephemeral\"; signer: AttachmentUrlSigner }\n | { status: \"unconfigured\" };\n\n// Unset: production fails closed, anything else gets a per-process secret.\nexport function resolveAttachmentUrlSigning(\n env: Readonly<Record<string, string | undefined>>,\n): AttachmentUrlSigning {\n const secret = env[ATTACHMENT_URL_SIGNING_SECRET_ENV];\n if (secret !== undefined) {\n if (secret.trim() !== secret || secret.length < MIN_SECRET_LENGTH) {\n throw new Error(\n `${ATTACHMENT_URL_SIGNING_SECRET_ENV} must be at least ${MIN_SECRET_LENGTH} characters with no leading or trailing whitespace`,\n );\n }\n return { status: \"configured\", signer: new AttachmentUrlSigner(secret) };\n }\n if (env.NODE_ENV === \"production\") {\n return { status: \"unconfigured\" };\n }\n return {\n status: \"ephemeral\",\n signer: new AttachmentUrlSigner(randomBytes(32)),\n };\n}\n","import type { InspectionThrottleConfig } from \"@powerhousedao/reactor-api\";\nimport { parseNonNegativeInt } from \"./env.mjs\";\n\nconst NAME = \"PH_INSPECTION_CALLS_PER_MINUTE\";\n\n/** Unset keeps reactor-api's default; an invalid value fails boot. */\nexport function inspectionThrottleFromEnv(\n env: NodeJS.ProcessEnv,\n): Partial<InspectionThrottleConfig> {\n const callsPerMinute = parseNonNegativeInt(env[NAME], NAME);\n if (callsPerMinute === undefined) {\n return {};\n }\n if (callsPerMinute < 1) {\n throw new Error(`${NAME} must be at least 1, got \"${env[NAME]}\"`);\n }\n return { callsPerMinute };\n}\n","import type * as CurrentPGliteModuleNs from \"@electric-sql/pglite\";\nimport type {\n NodeFsClass,\n PGliteModuleSpec,\n VerifyHandle,\n} from \"@powerhousedao/reactor-api/pglite-node\";\nimport { promises as fs } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\n\nexport const CURRENT_PG_MAJOR = 17;\nexport const SUPPORTED_PG_MAJORS = [16, 17] as const;\nexport type SupportedPgMajor = (typeof SUPPORTED_PG_MAJORS)[number];\n\ntype CurrentPGliteModule = typeof CurrentPGliteModuleNs;\n\nexport async function readPgVersionFile(\n dataDir: string,\n): Promise<number | null> {\n try {\n const raw = await fs.readFile(path.join(dataDir, \"PG_VERSION\"), \"utf8\");\n const major = parseInt(raw.trim(), 10);\n return Number.isFinite(major) ? major : null;\n } catch {\n return null;\n }\n}\n\nexport function isSupportedMajor(major: number): major is SupportedPgMajor {\n return (SUPPORTED_PG_MAJORS as readonly number[]).includes(major);\n}\n\n/**\n * Parses the `PH_FORCE_PG_VERSION` env var. Returns the validated major, or\n * `null` when the var is unset/empty. Throws on any value that is not a\n * supported major — invalid configuration must fail before the server starts\n * touching disk.\n */\nexport function parseForcePgVersion(\n raw: string | undefined,\n): SupportedPgMajor | null {\n if (raw === undefined || raw.trim() === \"\") return null;\n const parsed = Number(raw);\n if (Number.isInteger(parsed) && isSupportedMajor(parsed)) return parsed;\n throw new Error(\n `PH_FORCE_PG_VERSION must be one of: ${SUPPORTED_PG_MAJORS.join(\", \")} (got: ${raw})`,\n );\n}\n\nexport async function loadPGliteModule(\n major: SupportedPgMajor,\n): Promise<CurrentPGliteModule> {\n if (major === 16) {\n return (await import(\"pglite-legacy-02\")) as unknown as CurrentPGliteModule;\n }\n return import(\"@electric-sql/pglite\");\n}\n\n/**\n * Where a PGlite worker imports the module that opens `major` dirs from,\n * resolved here because the worker's own package cannot see the\n * `pglite-legacy-02` alias.\n */\nexport function pgliteModuleSpec(major: SupportedPgMajor): PGliteModuleSpec {\n const base = major === 16 ? \"pglite-legacy-02\" : \"@electric-sql/pglite\";\n return {\n pglite: resolveModuleUrl(base),\n nodefs: resolveModuleUrl(`${base}/nodefs`),\n };\n}\n\nfunction resolveModuleUrl(specifier: string): string {\n try {\n return import.meta.resolve(specifier);\n } catch {\n return pathToFileURL(createRequire(import.meta.url).resolve(specifier))\n .href;\n }\n}\n\n/** The stock NodeFS class of the PGlite module that opens `major` dirs. */\nexport async function loadNodeFsClass(\n major: SupportedPgMajor,\n): Promise<NodeFsClass> {\n if (major === 16) {\n const mod = await import(\"pglite-legacy-02/nodefs\");\n return mod.NodeFS as unknown as NodeFsClass;\n }\n const mod = await import(\"@electric-sql/pglite/nodefs\");\n return mod.NodeFS;\n}\n\n/** Opens a converted dir over stock NodeFS so the conversion can check it. */\nexport async function openForVerify(\n major: number,\n dataDir: string,\n): Promise<VerifyHandle> {\n if (!isSupportedMajor(major)) {\n throw new Error(\n `Cannot verify PGlite data dir ${dataDir}: PG_VERSION=${major} is not supported (expected one of ${SUPPORTED_PG_MAJORS.join(\", \")})`,\n );\n }\n const [{ PGlite }, NodeFS] = await Promise.all([\n loadPGliteModule(major),\n loadNodeFsClass(major),\n ]);\n const pg = new PGlite({ fs: new NodeFS(dataDir) });\n await pg.waitReady;\n return pg;\n}\n\ntype PgDumpFn = (options: {\n pg: unknown;\n}) => Promise<{ text(): Promise<string> }>;\n\nexport async function loadPgDump(major: SupportedPgMajor): Promise<PgDumpFn> {\n if (major === 16) {\n const mod = (await import(\"pglite-tools-legacy-02/pg_dump\")) as {\n pgDump: PgDumpFn;\n };\n return mod.pgDump;\n }\n const mod = (await import(\"@electric-sql/pglite-tools/pg_dump\")) as {\n pgDump: PgDumpFn;\n };\n return mod.pgDump;\n}\n","import {\n storedRefusalName,\n type StoredProtocolRefusal,\n type UnsupportedStoredDocuments,\n type UnsupportedStoredProtocolError,\n} from \"@powerhousedao/reactor\";\n\nconst MODES: readonly UnsupportedStoredDocuments[] = [\"refuse\", \"read-only\"];\n\n/** From REACTOR_UNSUPPORTED_STORED_DOCUMENTS; `input` wins when defined. */\nexport function resolveUnsupportedStoredDocuments(\n input: UnsupportedStoredDocuments | undefined,\n env: NodeJS.ProcessEnv,\n): UnsupportedStoredDocuments {\n if (input !== undefined) return input;\n const raw = env.REACTOR_UNSUPPORTED_STORED_DOCUMENTS?.trim();\n if (!raw) return \"refuse\";\n if (!(MODES as readonly string[]).includes(raw)) {\n throw new Error(\n `REACTOR_UNSUPPORTED_STORED_DOCUMENTS must be \"refuse\" or \"read-only\", got \"${raw}\"`,\n );\n }\n return raw as UnsupportedStoredDocuments;\n}\n\n/** The reactor refused to start over documents this build does not run. */\nexport class StoredDocumentsRefusedError extends Error {\n readonly versions: readonly StoredProtocolRefusal[];\n readonly documents: number;\n\n constructor(cause: UnsupportedStoredProtocolError) {\n const named = cause.versions.map(storedRefusalName).join(\", \");\n super(\n `Refusing to start: ${cause.documents} stored document(s) require ${named}, which this switchboard does not run. ` +\n `Either start a switchboard build that runs ${named}, or set REACTOR_UNSUPPORTED_STORED_DOCUMENTS=read-only to start with those documents read-only.`,\n { cause },\n );\n this.name = \"StoredDocumentsRefusedError\";\n this.versions = cause.versions;\n this.documents = cause.documents;\n }\n\n static override isError(\n error: unknown,\n ): error is StoredDocumentsRefusedError {\n return Error.isError(error) && error.name === \"StoredDocumentsRefusedError\";\n }\n}\n","import type { SwitchboardDriveDocumentType } from \"../types.js\";\n\n/** `PH_DEFAULT_DRIVE_TYPE`: the default drive's container type. */\nexport function parseDriveType(\n raw: string | undefined,\n): SwitchboardDriveDocumentType | undefined {\n if (!raw) return undefined;\n if (raw === \"powerhouse/document-drive\" || raw === \"powerhouse/reactor-drive\")\n return raw;\n throw new Error(\n `Invalid PH_DEFAULT_DRIVE_TYPE: ${raw}. Expected \"powerhouse/document-drive\" or \"powerhouse/reactor-drive\".`,\n );\n}\n","import {\n isProcessorTimingLevel,\n parseCatchUpPriority,\n parseKeyframeSettings,\n parseMemoryTelemetryOutputs,\n parseMemoryTelemetrySwitch,\n type MemoryTelemetryOutput,\n type ProcessorTimingLevel,\n} from \"@powerhousedao/reactor\";\nimport {\n type HostValidationMode,\n reactorApiConfigFromEnv,\n resolveRenownConfig,\n} from \"@powerhousedao/reactor-api\";\nimport { resolvePgliteMaintenance } from \"@powerhousedao/reactor-api/pglite-node\";\nimport { resolvePgliteWorkerMemoryMb } from \"@powerhousedao/reactor-api/pglite-node\";\nimport { isSignaturePolicy } from \"@powerhousedao/shared/document-model\";\nimport { childLogger, type ILogger } from \"document-model\";\nimport {\n ATTACHMENT_URL_SIGNING_SECRET_ENV,\n resolveAttachmentUrlSigning,\n} from \"../attachments/url-signer.js\";\nimport { parseNonNegativeInt } from \"../env.mjs\";\nimport { inspectionThrottleFromEnv } from \"../inspection-throttle.mjs\";\nimport { parseForcePgVersion } from \"../pglite-version.js\";\nimport { isPostgresUrl } from \"../postgres-url.mjs\";\nimport { privacyTimingsFromEnv } from \"../privacy.mjs\";\nimport { parseOnOff } from \"../projection-worker.mjs\";\nimport { resolveUnsupportedStoredDocuments } from \"../unsupported-stored-documents.mjs\";\nimport { parseWorkerCount, resolveHostPoolSize } from \"../worker-pool.mjs\";\nimport { parseDriveType } from \"./drive-type.js\";\nimport {\n SWITCHBOARD_LOG_LEVELS,\n type SwitchboardConfigInput,\n} from \"./schema.js\";\n\ntype Env = Readonly<Record<string, string | undefined>>;\ntype Logger = ILogger;\n\nexport interface SwitchboardConfigFromEnvOptions {\n /** The bin's own keys (sb/config.ts) instead of PORT. */\n bin?: boolean;\n logger?: Logger;\n}\n\n/** Only the keys the env sets; today's boot errors throw with their messages. */\nexport function switchboardConfigFromEnv(\n env: Env,\n options: SwitchboardConfigFromEnvOptions = {},\n): SwitchboardConfigInput {\n const logger = options.logger ?? childLogger([\"switchboard\", \"config\"]);\n const api = reactorApiConfigFromEnv(env, logger);\n const reactorUrl = urlFromEnv(\n env.PH_REACTOR_DATABASE_URL ?? env.PH_SWITCHBOARD_DATABASE_URL,\n );\n const executorCount = parseWorkerCount(env.REACTOR_WORKERS);\n const executorOn = executorCount === \"auto\" || (executorCount ?? 0) > 0;\n const projectionOn = parseOnOff(env.REACTOR_PROJECTION_WORKER);\n const privacyOn = flag(env.PH_PRIVACY_ENABLED);\n const pgliteWorkers = openFeatureFlag(env.PH_PGLITE_WORKERS);\n const telemetryOff = telemetrySwitchFromEnv(env, logger) === false;\n\n return withoutUnset({\n logLevel: logLevelFromEnv(env.LOG_LEVEL, logger),\n server: {\n ...api.server,\n port: options.bin\n ? binPortFromEnv(env.PH_SWITCHBOARD_PORT)\n : portFromEnv(env.PORT, logger),\n },\n storage: {\n reactor: { url: reactorUrl },\n readModel: {\n url: urlFromEnv(env.DATABASE_URL ?? env.PH_SWITCHBOARD_DATABASE_URL),\n },\n inMemory:\n env.PH_PGLITE_IN_MEMORY === undefined\n ? undefined\n : env.PH_PGLITE_IN_MEMORY === \"1\",\n userDataDir: env.PH_USER_DATA_DIR || undefined,\n pglite: {\n fsync:\n env.PH_PGLITE_FSYNC === undefined\n ? undefined\n : env.PH_PGLITE_FSYNC !== \"0\",\n workers: pgliteWorkers,\n workerMemoryMb: gated(pgliteWorkers !== false, () =>\n isBlank(env.PH_PGLITE_WORKER_MEMORY_MB)\n ? undefined\n : resolvePgliteWorkerMemoryMb(env),\n ),\n vacuumFull: vacuumFullFromEnv(env),\n },\n migratePglite: options.bin ? flag(env.PH_MIGRATE_PGLITE) : undefined,\n forcePgVersion: options.bin\n ? (parseForcePgVersion(env.PH_FORCE_PG_VERSION) ?? undefined)\n : undefined,\n keyframes: keyframesFromEnv(env.PH_KEYFRAMES),\n },\n protocol: {\n featureFlags: {\n documentDecisions: flag(env.REACTOR_DOCUMENT_DECISIONS),\n authEnforcement: flag(env.REACTOR_AUTH_ENFORCEMENT),\n authGroups: flag(env.REACTOR_AUTH_GROUPS),\n authConditions: flag(env.REACTOR_AUTH_CONDITIONS),\n undoV3:\n env.REACTOR_UNDO_V3 === undefined\n ? undefined\n : env.REACTOR_UNDO_V3 !== \"false\",\n },\n createSignaturePolicy: createSignaturePolicyFromEnv(\n env.CREATE_SIGNATURE_POLICY,\n ),\n unsupportedStoredDocuments:\n env.REACTOR_UNSUPPORTED_STORED_DOCUMENTS?.trim()\n ? resolveUnsupportedStoredDocuments(undefined, env)\n : undefined,\n legacyProcessorIds:\n env.REACTOR_LEGACY_PROCESSOR_IDS === undefined\n ? undefined\n : env.REACTOR_LEGACY_PROCESSOR_IDS !== \"false\",\n maxSkipThreshold: maxSkipThresholdFromEnv(env.MAX_SKIP_THRESHOLD),\n catchUpPriority: catchUpPriorityFromEnv(env.PH_CATCH_UP_PRIORITY, logger),\n processorTiming: telemetryOff\n ? \"off\"\n : processorTimingFromEnv(env.PH_PROCESSOR_TIMING, logger),\n processorTimingWindowMs: positiveIntFromEnv(\n env,\n \"PH_PROCESSOR_TIMING_WINDOW_MS\",\n logger,\n ),\n processorSlowBatchMs: positiveIntFromEnv(\n env,\n \"PH_PROCESSOR_SLOW_BATCH_MS\",\n logger,\n ),\n processorTimingLogMs: positiveIntFromEnv(\n env,\n \"PH_PROCESSOR_TIMING_LOG_MS\",\n logger,\n ),\n },\n telemetry: {\n memory: memoryTelemetryFromEnv(env, telemetryOff, logger),\n dir: blankAsUnset(env.PH_TELEMETRY_DIR),\n heapSnapshotDir: blankAsUnset(env.PH_HEAP_SNAPSHOT_DIR),\n },\n auth: {\n ...api.auth,\n renown: {\n source: renownSourceFromEnv(env, logger),\n url: blankAsUnset(env.RENOWN_URL),\n switchboardUrl: blankAsUnset(env.SWITCHBOARD_URL),\n },\n },\n inspection: {\n ...api.inspection,\n enabled: openFeatureFlag(env.INSPECTION_ENABLED),\n callsPerMinute: inspectionThrottleFromEnv(env).callsPerMinute,\n },\n workers: {\n executor: {\n count: executorCount,\n poolSize: gated(executorOn, () =>\n parseNonNegativeInt(\n env.REACTOR_DB_POOL_SIZE_WORKER,\n \"REACTOR_DB_POOL_SIZE_WORKER\",\n ),\n ),\n acquireTimeoutMs: gated(executorOn, () =>\n parseNonNegativeInt(\n env.REACTOR_DB_ACQUIRE_TIMEOUT_MS,\n \"REACTOR_DB_ACQUIRE_TIMEOUT_MS\",\n ),\n ),\n },\n hostPoolSize: gated(\n reactorUrl !== undefined && isPostgresUrl(reactorUrl),\n () =>\n isBlank(env.REACTOR_DB_POOL_SIZE_HOST)\n ? undefined\n : resolveHostPoolSize(env as NodeJS.ProcessEnv),\n ),\n projection: {\n enabled: projectionOn,\n poolSize: gated(projectionOn === true, () =>\n projectionPoolSizeFromEnv(env.REACTOR_DB_POOL_SIZE_PROJECTION),\n ),\n },\n },\n packages: {\n registryUrl: env.PH_REGISTRY_URL,\n registryPackages: env.PH_REGISTRY_PACKAGES?.split(\",\").map((p) =>\n p.trim(),\n ),\n dynamic: flag(env.DYNAMIC_MODEL_LOADING),\n hostValidation: hostValidationFromEnv(env.PH_HOST_VALIDATION),\n },\n features: {\n mcp: openFeatureFlag(env.MCP_ENABLED),\n workflows: workflowsFromEnv(env.PH_WORKFLOWS_ENABLED),\n documentModelSubgraphs: openFeatureFlag(\n env.DOCUMENT_MODEL_SUBGRAPHS_ENABLED,\n ),\n privacy: {\n enabled: privacyOn,\n deploymentSecret: env.PH_PRIVACY_DEPLOYMENT_SECRET,\n ...gated(privacyOn === true, () =>\n privacyTimingsFromEnv(env as NodeJS.ProcessEnv),\n ),\n },\n },\n attachments: {\n ...api.attachments,\n urlSigningSecret: urlSigningSecretFromEnv(env),\n downloadTargetMaxTtlSeconds: downloadTargetTtlFromEnv(\n env.ATTACHMENT_DOWNLOAD_TARGET_MAX_TTL_SECONDS,\n logger,\n ),\n serviceUrl: env.PH_SWITCHBOARD_PUBLIC_URL,\n },\n drive: options.bin\n ? { documentType: parseDriveType(env.PH_DEFAULT_DRIVE_TYPE) }\n : undefined,\n }) as SwitchboardConfigInput;\n}\n\nfunction flag(raw: string | undefined): boolean | undefined {\n return raw === undefined ? undefined : raw === \"true\";\n}\n\n// As OpenFeature's EnvVarProvider reads a boolean.\nfunction openFeatureFlag(raw: string | undefined): boolean | undefined {\n if (raw === \"true\") return true;\n if (raw === \"false\") return false;\n return undefined;\n}\n\nfunction blankAsUnset(raw: string | undefined): string | undefined {\n const trimmed = raw?.trim();\n return trimmed ? trimmed : undefined;\n}\n\n// A set but invalid RENOWN_SOURCE still overrides the config file, as \"remote\".\nfunction renownSourceFromEnv(\n env: Env,\n logger: Logger,\n): \"self\" | \"remote\" | \"kept\" | undefined {\n if (blankAsUnset(env.RENOWN_SOURCE) === undefined) return undefined;\n return resolveRenownConfig(undefined, env, logger).source;\n}\n\nfunction isBlank(raw: string | undefined): boolean {\n return raw === undefined || raw.trim() === \"\";\n}\n\n// \"\" names no store: the server falls back to the default dir for it.\nfunction urlFromEnv(raw: string | undefined): string | undefined {\n return raw ? raw : undefined;\n}\n\n// Today these throw only once their feature is on; off, a bad value is dropped.\nfunction gated<T>(on: boolean, parse: () => T): T | undefined {\n if (on) return parse();\n try {\n return parse();\n } catch {\n return undefined;\n }\n}\n\nfunction logLevelFromEnv(\n raw: string | undefined,\n logger: Logger,\n): (typeof SWITCHBOARD_LOG_LEVELS)[number] | undefined {\n if (!raw) return undefined;\n if ((SWITCHBOARD_LOG_LEVELS as readonly string[]).includes(raw)) {\n return raw as (typeof SWITCHBOARD_LOG_LEVELS)[number];\n }\n logger.warn(\n `Ignoring invalid LOG_LEVEL=\"${raw}\" (expected one of ${SWITCHBOARD_LOG_LEVELS.join(\", \")}); using info`,\n );\n return undefined;\n}\n\n// Most edges pass a port of their own, so a bad PORT must not fail their boot.\nfunction portFromEnv(\n raw: string | undefined,\n logger: Logger,\n): number | undefined {\n if (!raw) return undefined;\n const port = Number(raw);\n if (Number.isInteger(port) && port >= 0 && port <= 65535) return port;\n logger.warn(`Ignoring invalid PORT=\"${raw}\" (expected a port number)`);\n return undefined;\n}\n\n// Not a number falls through to the config file, as the bin's own config does.\nfunction binPortFromEnv(raw: string | undefined): number | undefined {\n return raw && !isNaN(Number(raw)) ? Number(raw) : undefined;\n}\n\n// A malformed value stops the boot: running on with the defaults would keep\n// writing keyframes the operator asked to bound.\nfunction keyframesFromEnv(raw: string | undefined) {\n if (isBlank(raw)) return undefined;\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw as string);\n } catch (error) {\n throw new Error(\n `PH_KEYFRAMES is not valid JSON: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n return parseKeyframeSettings(parsed, \"PH_KEYFRAMES\");\n}\n\nfunction vacuumFullFromEnv(env: Env) {\n // Throws on an unknown mode, with today's message.\n resolvePgliteMaintenance(env);\n const mode = env.PH_PGLITE_VACUUM_FULL?.trim().toLowerCase() || undefined;\n return {\n mode: mode as \"off\" | \"quiet\" | \"forced\" | undefined,\n aboveMb: nonNegativeNumber(env.PH_PGLITE_VACUUM_FULL_ABOVE_MB),\n quietMs: nonNegativeNumber(env.PH_PGLITE_VACUUM_FULL_QUIET_MS),\n maxDeferMs: nonNegativeNumber(env.PH_PGLITE_VACUUM_FULL_MAX_DEFER_MS),\n };\n}\n\n// Anything else is ignored, as resolvePgliteMaintenance ignores it.\nfunction nonNegativeNumber(raw: string | undefined): number | undefined {\n if (isBlank(raw)) return undefined;\n const parsed = Number(raw);\n return Number.isFinite(parsed) && parsed >= 0 ? parsed : undefined;\n}\n\nfunction createSignaturePolicyFromEnv(\n value: string | undefined,\n): \"legacy\" | \"v2-required\" | undefined {\n const raw = value?.trim();\n if (!raw) return undefined;\n if (!isSignaturePolicy(raw)) {\n throw new Error(\n `CREATE_SIGNATURE_POLICY must be \"legacy\" or \"v2-required\", got \"${raw}\"`,\n );\n }\n return raw;\n}\n\nfunction hostValidationFromEnv(\n value: string | undefined,\n): HostValidationMode | undefined {\n const raw = value?.trim();\n if (!raw) return undefined;\n if (raw !== \"log\" && raw !== \"refuse\") {\n throw new Error(\n `PH_HOST_VALIDATION must be \"log\" or \"refuse\", got \"${raw}\"`,\n );\n }\n return raw;\n}\n\nfunction maxSkipThresholdFromEnv(raw: string | undefined): number | undefined {\n const parsed = parseInt(raw ?? \"\", 10);\n return !isNaN(parsed) && parsed > 0 ? parsed : undefined;\n}\n\nfunction catchUpPriorityFromEnv(\n raw: string | undefined,\n logger: Logger,\n): \"dynamic\" | number | undefined {\n if (raw === undefined) return undefined;\n const setting = parseCatchUpPriority(raw);\n if (setting?.mode === \"fixed\") return setting.level;\n if (setting) return \"dynamic\";\n logger.warn(\n `PH_CATCH_UP_PRIORITY=${JSON.stringify(raw)} is neither dynamic nor a level 0-7; using dynamic`,\n );\n return undefined;\n}\n\n// PH_TELEMETRY=off is the umbrella: it wins over both specific switches.\nfunction telemetrySwitchFromEnv(env: Env, logger: Logger): boolean | undefined {\n const raw = env.PH_TELEMETRY;\n if (raw === undefined) return undefined;\n const value = parseMemoryTelemetrySwitch(raw);\n if (value === undefined) {\n logger.warn(`PH_TELEMETRY=${JSON.stringify(raw)} is neither on nor off`);\n }\n return value;\n}\n\nfunction processorTimingFromEnv(\n raw: string | undefined,\n logger: Logger,\n): ProcessorTimingLevel | undefined {\n if (raw === undefined) return undefined;\n if (isProcessorTimingLevel(raw)) return raw;\n logger.warn(\n `PH_PROCESSOR_TIMING=${JSON.stringify(raw)} is none of off, basic, detailed; using the default`,\n );\n return undefined;\n}\n\nfunction positiveIntFromEnv(\n env: Env,\n name: string,\n logger: Logger,\n): number | undefined {\n const raw = env[name];\n if (raw === undefined) return undefined;\n const value = Number(raw.trim() || Number.NaN);\n if (Number.isInteger(value) && value > 0) return value;\n logger.warn(`${name}=${JSON.stringify(raw)} is not a positive integer`);\n return undefined;\n}\n\nfunction memoryOutputsFromEnv(\n env: Env,\n logger: Logger,\n): MemoryTelemetryOutput[] | undefined {\n const raw = env.PH_MEMORY_TELEMETRY_OUTPUT;\n let outputs: MemoryTelemetryOutput[] | undefined;\n if (raw !== undefined) {\n outputs = parseMemoryTelemetryOutputs(raw);\n if (!outputs) {\n logger.warn(\n `PH_MEMORY_TELEMETRY_OUTPUT=${JSON.stringify(raw)} lists an output other than memory, file, console; using the default`,\n );\n }\n }\n // A file path implies the file output.\n if (env.PH_MEMORY_TELEMETRY_FILE?.trim() && outputs) {\n return outputs.includes(\"file\") ? outputs : [...outputs, \"file\"];\n }\n return outputs;\n}\n\nfunction memoryTelemetryFromEnv(env: Env, off: boolean, logger: Logger) {\n const raw = env.PH_MEMORY_TELEMETRY;\n let enabled = raw === undefined ? undefined : parseMemoryTelemetrySwitch(raw);\n if (raw !== undefined && enabled === undefined) {\n logger.warn(\n `PH_MEMORY_TELEMETRY=${JSON.stringify(raw)} is neither on nor off; leaving it off`,\n );\n }\n if (off) enabled = false;\n const consoleOn = env.PH_MEMORY_TELEMETRY_CONSOLE?.trim() !== \"false\";\n const outputs = memoryOutputsFromEnv(env, logger);\n return {\n enabled,\n intervalMs: positiveIntFromEnv(\n env,\n \"PH_MEMORY_TELEMETRY_INTERVAL_MS\",\n logger,\n ),\n outputs: consoleOn ? outputs : outputs?.filter((o) => o !== \"console\"),\n file: {\n path: blankAsUnset(env.PH_MEMORY_TELEMETRY_FILE),\n maxMb: positiveIntFromEnv(env, \"PH_MEMORY_TELEMETRY_FILE_MAX_MB\", logger),\n keep: positiveIntFromEnv(env, \"PH_MEMORY_TELEMETRY_FILE_KEEP\", logger),\n },\n ringSize: positiveIntFromEnv(env, \"PH_MEMORY_TELEMETRY_RING\", logger),\n consoleIntervalMs: positiveIntFromEnv(\n env,\n \"PH_MEMORY_TELEMETRY_CONSOLE_INTERVAL_MS\",\n logger,\n ),\n workers:\n env.PH_MEMORY_TELEMETRY_WORKERS === undefined\n ? undefined\n : env.PH_MEMORY_TELEMETRY_WORKERS.trim() !== \"false\",\n windowMin: positiveIntFromEnv(\n env,\n \"PH_MEMORY_TELEMETRY_WINDOW_MIN\",\n logger,\n ),\n };\n}\n\nfunction projectionPoolSizeFromEnv(raw: string | undefined) {\n const poolSize = parseNonNegativeInt(raw, \"REACTOR_DB_POOL_SIZE_PROJECTION\");\n if (poolSize !== undefined && poolSize < 1) {\n throw new Error(\n \"REACTOR_DB_POOL_SIZE_PROJECTION must be at least 1; the projection worker cannot run without a pool\",\n );\n }\n return poolSize;\n}\n\n// PH_WORKFLOWS_ENABLED also takes the 1/0 reactor-api took.\nfunction workflowsFromEnv(raw: string | undefined): boolean | undefined {\n const trimmed = raw?.trim();\n if (trimmed === \"1\") return true;\n if (trimmed === \"0\") return false;\n return openFeatureFlag(raw);\n}\n\nfunction urlSigningSecretFromEnv(env: Env): string | undefined {\n const secret = env[ATTACHMENT_URL_SIGNING_SECRET_ENV];\n if (secret === undefined) return undefined;\n // Throws on a short or padded secret, with today's message.\n resolveAttachmentUrlSigning({ [ATTACHMENT_URL_SIGNING_SECRET_ENV]: secret });\n return secret;\n}\n\nfunction downloadTargetTtlFromEnv(\n raw: string | undefined,\n logger: Logger,\n): number | undefined {\n if (raw === undefined) return undefined;\n const parsed = Number(raw);\n if (Number.isInteger(parsed) && parsed > 0) return parsed;\n logger.warn(\n `Ignoring invalid ATTACHMENT_DOWNLOAD_TARGET_MAX_TTL_SECONDS=\"${raw}\" (expected a positive integer number of seconds) — using the default`,\n );\n return undefined;\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return (\n typeof value === \"object\" &&\n value !== null &&\n Object.getPrototypeOf(value) === Object.prototype\n );\n}\n\n// A layer names only what it sets: no unset keys, no emptied sections.\nfunction withoutUnset(value: Record<string, unknown>): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n for (const [key, entry] of Object.entries(value)) {\n if (entry === undefined) continue;\n if (isPlainObject(entry)) {\n const inner = withoutUnset(entry);\n if (Object.keys(inner).length > 0) result[key] = inner;\n continue;\n }\n result[key] = entry;\n }\n return result;\n}\n"],"names":["fs"],"mappings":";;;;;;;;;;;;;;;;;AAGA,MAAa,oCACX;AAEF,MAAM,oBAAoB;AAC1B,MAAM,kBAAkB;AACxB,MAAM,oBAAoB;AAQ1B,IAAa,sBAAb,MAAiC;CAEZ;CACA;CAFnB,YACE,QACA,MAAqC,KAAK,KAC1C;EAFiB,KAAA,SAAA;EACA,KAAA,MAAA;CAChB;CAEH,KACE,MACA,YACA,YACqB;EACrB,MAAM,UAAU,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI,IAAI;EAMhD,OAAO;GACL,OAAO,IANU,gBAAgB;IACjC;IACA,SAAS,OAAO,OAAO;IACvB,WAAW,KAAK,IAAI,MAAM,YAAY,OAAO,OAAO,CAAC;GACvD,CAEc,CAAC,CAAC,SAAS;GACvB,+BAAc,IAAI,KAAK,UAAU,GAAI,EAAA,CAAE,YAAY;EACrD;CACF;CAEA,OACE,MACA,YACA,SACA,WACS;EACT,IAAI,CAAC,gBAAgB,KAAK,OAAO,KAAK,CAAC,kBAAkB,KAAK,SAAS,GACrE,OAAO;EAET,IAAI,OAAO,OAAO,IAAI,OAAQ,KAAK,IAAI,GACrC,OAAO;EAET,MAAM,WAAW,OAAO,KAAK,KAAK,IAAI,MAAM,YAAY,OAAO,CAAC;EAChE,MAAM,YAAY,OAAO,KAAK,SAAS;EACvC,OACE,SAAS,WAAW,UAAU,UAC9B,gBAAgB,UAAU,SAAS;CAEvC;CAEA,IAAY,MAAc,YAAoB,SAAyB;EACrE,OAAO,WAAW,UAAU,KAAK,MAAM,CAA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;CAC1B,IAAI,YAAY,KAAK,OAAO;CAC5B,IAAI,YAAY,KAAK,OAAO;CAC5B,OAAO,gBAAgB,GAAG;AAC5B;AAEA,SAAS,wBAAwB,KAA8B;CAC7D,MAAM,SAAS,IAAI;CACnB,IAAI,WAAW,KAAA,GAAW,OAAO,KAAA;CAEjC,4BAA4B,GAAG,oCAAoC,OAAO,CAAC;CAC3E,OAAO;AACT;AAEA,SAAS,yBACP,KACA,QACoB;CACpB,IAAI,QAAQ,KAAA,GAAW,OAAO,KAAA;CAC9B,MAAM,SAAS,OAAO,GAAG;CACzB,IAAI,OAAO,UAAU,MAAM,KAAK,SAAS,GAAG,OAAO;CACnD,OAAO,KACL,gEAAgE,IAAI,sEACtE;AAEF;AAEA,SAAS,cAAc,OAAkD;CACvE,OACE,OAAO,UAAU,YACjB,UAAU,QACV,OAAO,eAAe,KAAK,MAAM,OAAO;AAE5C;AAGA,SAAS,aAAa,OAAyD;CAC7E,MAAM,SAAkC,CAAC;CACzC,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,KAAK,GAAG;EAChD,IAAI,UAAU,KAAA,GAAW;EACzB,IAAI,cAAc,KAAK,GAAG;GACxB,MAAM,QAAQ,aAAa,KAAK;GAChC,IAAI,OAAO,KAAK,KAAK,CAAC,CAAC,SAAS,GAAG,OAAO,OAAO;GACjD;EACF;EACA,OAAO,OAAO;CAChB;CACA,OAAO;AACT","debug_id":"a5dbd86a-bb41-5030-ad5f-2636c1aa825b"}
package/dist/index.mjs CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  !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]="617eb235-0dbd-55e0-9c2d-121be49b505e")}catch(e){}}();
4
4
  import { n as installObservabilitySignals } from "./observability-CldagyT_.mjs";
5
- import { n as StoredDocumentsRefusedError, t as switchboardConfigFromEnv } from "./from-env-DKK_wPrO.mjs";
6
- import { a as callerOverEnv, o as mergeSwitchboardConfig } from "./schema-BJ-OFAox.mjs";
7
- import { d as initProfilerFromEnv, r as initSwitchboardProcess, s as startSwitchboard } from "./server-BS-PFzoK.mjs";
5
+ import { n as StoredDocumentsRefusedError, t as switchboardConfigFromEnv } from "./from-env-CLImR6qa.mjs";
6
+ import { a as callerOverEnv, o as mergeSwitchboardConfig } from "./schema-BbwISVSO.mjs";
7
+ import { d as initProfilerFromEnv, r as initSwitchboardProcess, s as startSwitchboard } from "./server-BMRdMNvC.mjs";
8
8
  import * as Sentry from "@sentry/node";
9
9
  import { childLogger } from "document-model";
10
10
  import { getConfig } from "@powerhousedao/config/node";
package/dist/migrate.mjs CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- !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]="be192444-eb57-5f26-a00c-ffbb35edea43")}catch(e){}}();
3
+ !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]="1a5616ae-f017-5889-9999-67b88328c6d9")}catch(e){}}();
4
4
  import { getConfig } from "@powerhousedao/config/node";
5
+ import { DEPRECATIONS_REMOVED_IN, presentConfigKeys } from "@powerhousedao/shared/clis/deprecations";
5
6
  import { REACTOR_SCHEMA, getMigrationStatus, runMigrations } from "@powerhousedao/reactor";
6
7
  import { getReactorDriveMigrationStatus, runReactorDriveMigrations } from "@powerhousedao/reactor-drive";
7
8
  import dotenv from "dotenv";
@@ -10,13 +11,17 @@ import { Pool } from "pg";
10
11
  import { isDotenvDisabled } from "@powerhousedao/shared/clis/project-env";
11
12
  //#region src/migrate.mts
12
13
  if (!isDotenvDisabled()) dotenv.config();
14
+ const REMOVED_DATABASE_KEY = "switchboard.database.url";
13
15
  function isPostgresUrl(url) {
14
16
  return url.startsWith("postgresql://") || url.startsWith("postgres://");
15
17
  }
16
18
  async function main() {
17
19
  const command = process.argv[2];
18
- const config = getConfig();
19
- const dbPath = process.env.PH_SWITCHBOARD_DATABASE_URL ?? process.env.PH_REACTOR_DATABASE_URL ?? process.env.DATABASE_URL ?? config.switchboard?.database?.url;
20
+ const dbPath = process.env.PH_SWITCHBOARD_DATABASE_URL ?? process.env.PH_REACTOR_DATABASE_URL ?? process.env.DATABASE_URL;
21
+ if (!dbPath && presentConfigKeys(getConfig(), [REMOVED_DATABASE_KEY]).length > 0) {
22
+ console.error(`powerhouse.config.json "${REMOVED_DATABASE_KEY}" was removed in ${DEPRECATIONS_REMOVED_IN} and this command no longer reads it. Set PH_REACTOR_DATABASE_URL to the database URL and remove the key.`);
23
+ process.exit(1);
24
+ }
20
25
  if (!dbPath || !isPostgresUrl(dbPath)) {
21
26
  console.log("No PostgreSQL URL configured. Skipping migrations.");
22
27
  console.log("(PGlite migrations are handled automatically on startup)");
@@ -78,4 +83,4 @@ main();
78
83
  export {};
79
84
 
80
85
  //# sourceMappingURL=migrate.mjs.map
81
- //# debugId=be192444-eb57-5f26-a00c-ffbb35edea43
86
+ //# debugId=1a5616ae-f017-5889-9999-67b88328c6d9
@@ -1 +1 @@
1
- {"version":3,"file":"migrate.mjs","sources":["../src/migrate.mts"],"sourcesContent":["#!/usr/bin/env node\nimport dotenv from \"dotenv\";\nimport { isDotenvDisabled } from \"@powerhousedao/shared/clis/project-env\";\nif (!isDotenvDisabled()) dotenv.config();\n\nimport { Kysely, PostgresDialect } from \"kysely\";\nimport { Pool } from \"pg\";\nimport {\n runMigrations,\n getMigrationStatus,\n REACTOR_SCHEMA,\n} from \"@powerhousedao/reactor\";\nimport {\n getReactorDriveMigrationStatus,\n runReactorDriveMigrations,\n} from \"@powerhousedao/reactor-drive\";\nimport { getConfig } from \"@powerhousedao/config/node\";\n\nfunction isPostgresUrl(url: string): boolean {\n return url.startsWith(\"postgresql://\") || url.startsWith(\"postgres://\");\n}\n\nasync function main() {\n const command = process.argv[2];\n const config = getConfig();\n\n const dbPath =\n process.env.PH_SWITCHBOARD_DATABASE_URL ??\n process.env.PH_REACTOR_DATABASE_URL ??\n process.env.DATABASE_URL ??\n config.switchboard?.database?.url;\n\n if (!dbPath || !isPostgresUrl(dbPath)) {\n console.log(\"No PostgreSQL URL configured. Skipping migrations.\");\n console.log(\"(PGlite migrations are handled automatically on startup)\");\n return;\n }\n\n console.log(`Database: ${dbPath}`);\n\n const pool = new Pool({ connectionString: dbPath });\n\n const db = new Kysely<any>({\n dialect: new PostgresDialect({ pool }),\n });\n\n try {\n if (command === \"status\") {\n console.log(\"\\nChecking migration status...\");\n const migrations = await getMigrationStatus(db, REACTOR_SCHEMA);\n\n console.log(\"\\nReactor Migration Status:\");\n console.log(\"=========================\");\n\n for (const migration of migrations) {\n const status = migration.executedAt\n ? `[OK] Executed at ${migration.executedAt.toISOString()}`\n : \"[--] Pending\";\n console.log(`${status} - ${migration.name}`);\n }\n\n const driveMigrations = await getReactorDriveMigrationStatus(\n db,\n REACTOR_SCHEMA,\n );\n\n console.log(\"\\nReactor-Drive Migration Status:\");\n console.log(\"===============================\");\n\n for (const migration of driveMigrations) {\n const status = migration.executedAt\n ? `[OK] Executed at ${migration.executedAt.toISOString()}`\n : \"[--] Pending\";\n console.log(`${status} - ${migration.name}`);\n }\n } else {\n console.log(\"\\nRunning reactor migrations...\");\n const result = await runMigrations(db, REACTOR_SCHEMA);\n\n if (!result.success) {\n console.error(\"Migration failed:\", result.error?.message);\n process.exit(1);\n }\n\n if (result.migrationsExecuted.length === 0) {\n console.log(\"No reactor migrations to run - database is up to date\");\n } else {\n console.log(\n `Successfully executed ${result.migrationsExecuted.length} reactor migration(s):`,\n );\n for (const name of result.migrationsExecuted) {\n console.log(` - ${name}`);\n }\n }\n\n console.log(\"\\nRunning reactor-drive migrations...\");\n const driveResult = await runReactorDriveMigrations(db, REACTOR_SCHEMA);\n\n if (!driveResult.success) {\n console.error(\n \"Reactor-drive migration failed:\",\n driveResult.error?.message,\n );\n process.exit(1);\n }\n\n if (driveResult.migrationsExecuted.length === 0) {\n console.log(\n \"No reactor-drive migrations to run - database is up to date\",\n );\n } else {\n console.log(\n `Successfully executed ${driveResult.migrationsExecuted.length} reactor-drive migration(s):`,\n );\n for (const name of driveResult.migrationsExecuted) {\n console.log(` - ${name}`);\n }\n }\n }\n } catch (error) {\n console.error(\n \"Error:\",\n error instanceof Error ? error.message : String(error),\n );\n process.exit(1);\n } finally {\n await db.destroy();\n }\n}\n\nvoid main();\n"],"names":[],"mappings":";;;;;;;;;;;AAGA,IAAI,CAAC,iBAAiB,GAAG,OAAO,OAAO;AAevC,SAAS,cAAc,KAAsB;CAC3C,OAAO,IAAI,WAAW,eAAe,KAAK,IAAI,WAAW,aAAa;AACxE;AAEA,eAAe,OAAO;CACpB,MAAM,UAAU,QAAQ,KAAK;CAC7B,MAAM,SAAS,UAAU;CAEzB,MAAM,SACJ,QAAQ,IAAI,+BACZ,QAAQ,IAAI,2BACZ,QAAQ,IAAI,gBACZ,OAAO,aAAa,UAAU;CAEhC,IAAI,CAAC,UAAU,CAAC,cAAc,MAAM,GAAG;EACrC,QAAQ,IAAI,oDAAoD;EAChE,QAAQ,IAAI,0DAA0D;EACtE;CACF;CAEA,QAAQ,IAAI,aAAa,QAAQ;CAEjC,MAAM,OAAO,IAAI,KAAK,EAAE,kBAAkB,OAAO,CAAC;CAElD,MAAM,KAAK,IAAI,OAAY,EACzB,SAAS,IAAI,gBAAgB,EAAE,KAAK,CAAC,EACvC,CAAC;CAED,IAAI;EACF,IAAI,YAAY,UAAU;GACxB,QAAQ,IAAI,gCAAgC;GAC5C,MAAM,aAAa,MAAM,mBAAmB,IAAI,cAAc;GAE9D,QAAQ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iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CACvD;EACA,QAAQ,KAAK,CAAC;CAChB,UAAU;EACR,MAAM,GAAG,QAAQ;CACnB;AACF;AAEK,KAAK","debug_id":"be192444-eb57-5f26-a00c-ffbb35edea43"}
1
+ {"version":3,"file":"migrate.mjs","sources":["../src/migrate.mts"],"sourcesContent":["#!/usr/bin/env node\nimport dotenv from \"dotenv\";\nimport { isDotenvDisabled } from \"@powerhousedao/shared/clis/project-env\";\nimport {\n DEPRECATIONS_REMOVED_IN,\n presentConfigKeys,\n} from \"@powerhousedao/shared/clis/deprecations\";\nif (!isDotenvDisabled()) dotenv.config();\n\nimport { Kysely, PostgresDialect } from \"kysely\";\nimport { Pool } from \"pg\";\nimport {\n runMigrations,\n getMigrationStatus,\n REACTOR_SCHEMA,\n} from \"@powerhousedao/reactor\";\nimport {\n getReactorDriveMigrationStatus,\n runReactorDriveMigrations,\n} from \"@powerhousedao/reactor-drive\";\nimport { getConfig } from \"@powerhousedao/config/node\";\n\nconst REMOVED_DATABASE_KEY = \"switchboard.database.url\";\n\nfunction isPostgresUrl(url: string): boolean {\n return url.startsWith(\"postgresql://\") || url.startsWith(\"postgres://\");\n}\n\nasync function main() {\n const command = process.argv[2];\n\n const dbPath =\n process.env.PH_SWITCHBOARD_DATABASE_URL ??\n process.env.PH_REACTOR_DATABASE_URL ??\n process.env.DATABASE_URL;\n\n // The config key named the database until 6.4. Skipping the migrations\n // because it is no longer read would look like success, so refuse instead.\n if (\n !dbPath &&\n presentConfigKeys(getConfig(), [REMOVED_DATABASE_KEY]).length > 0\n ) {\n console.error(\n `powerhouse.config.json \"${REMOVED_DATABASE_KEY}\" was removed in ${DEPRECATIONS_REMOVED_IN} and this command no longer reads it. ` +\n \"Set PH_REACTOR_DATABASE_URL to the database URL and remove the key.\",\n );\n process.exit(1);\n }\n\n if (!dbPath || !isPostgresUrl(dbPath)) {\n console.log(\"No PostgreSQL URL configured. Skipping migrations.\");\n console.log(\"(PGlite migrations are handled automatically on startup)\");\n return;\n }\n\n console.log(`Database: ${dbPath}`);\n\n const pool = new Pool({ connectionString: dbPath });\n\n const db = new Kysely<any>({\n dialect: new PostgresDialect({ pool }),\n });\n\n try {\n if (command === \"status\") {\n console.log(\"\\nChecking migration status...\");\n const migrations = await getMigrationStatus(db, REACTOR_SCHEMA);\n\n console.log(\"\\nReactor Migration Status:\");\n console.log(\"=========================\");\n\n for (const migration of migrations) {\n const status = migration.executedAt\n ? `[OK] Executed at ${migration.executedAt.toISOString()}`\n : \"[--] Pending\";\n console.log(`${status} - ${migration.name}`);\n }\n\n const driveMigrations = await getReactorDriveMigrationStatus(\n db,\n REACTOR_SCHEMA,\n );\n\n console.log(\"\\nReactor-Drive Migration Status:\");\n console.log(\"===============================\");\n\n for (const migration of driveMigrations) {\n const status = migration.executedAt\n ? `[OK] Executed at ${migration.executedAt.toISOString()}`\n : \"[--] Pending\";\n console.log(`${status} - ${migration.name}`);\n }\n } else {\n console.log(\"\\nRunning reactor migrations...\");\n const result = await runMigrations(db, REACTOR_SCHEMA);\n\n if (!result.success) {\n console.error(\"Migration failed:\", result.error?.message);\n process.exit(1);\n }\n\n if (result.migrationsExecuted.length === 0) {\n console.log(\"No reactor migrations to run - database is up to date\");\n } else {\n console.log(\n `Successfully executed ${result.migrationsExecuted.length} reactor migration(s):`,\n );\n for (const name of result.migrationsExecuted) {\n console.log(` - ${name}`);\n }\n }\n\n console.log(\"\\nRunning reactor-drive migrations...\");\n const driveResult = await runReactorDriveMigrations(db, REACTOR_SCHEMA);\n\n if (!driveResult.success) {\n console.error(\n \"Reactor-drive migration failed:\",\n driveResult.error?.message,\n );\n process.exit(1);\n }\n\n if (driveResult.migrationsExecuted.length === 0) {\n console.log(\n \"No reactor-drive migrations to run - database is up to date\",\n );\n } else {\n console.log(\n `Successfully executed ${driveResult.migrationsExecuted.length} reactor-drive migration(s):`,\n );\n for (const name of driveResult.migrationsExecuted) {\n console.log(` - ${name}`);\n }\n }\n }\n } catch (error) {\n console.error(\n \"Error:\",\n error instanceof Error ? error.message : String(error),\n );\n process.exit(1);\n } finally {\n await db.destroy();\n }\n}\n\nvoid main();\n"],"names":[],"mappings":";;;;;;;;;;;;AAOA,IAAI,CAAC,iBAAiB,GAAG,OAAO,OAAO;AAevC,MAAM,uBAAuB;AAE7B,SAAS,cAAc,KAAsB;CAC3C,OAAO,IAAI,WAAW,eAAe,KAAK,IAAI,WAAW,aAAa;AACxE;AAEA,eAAe,OAAO;CACpB,MAAM,UAAU,QAAQ,KAAK;CAE7B,MAAM,SACJ,QAAQ,IAAI,+BACZ,QAAQ,IAAI,2BACZ,QAAQ,IAAI;CAId,IACE,CAAC,UACD,kBAAkB,UAAU,GAAG,CAAC,oBAAoB,CAAC,CAAC,CAAC,SAAS,GAChE;EACA,QAAQ,MACN,2BAA2B,qBAAqB,mBAAmB,wBAAwB,0GAE7F;EACA,QAAQ,KAAK,CAAC;CAChB;CAEA,IAAI,CAAC,UAAU,CAAC,cAAc,MAAM,GAAG;EACrC,QAAQ,IAAI,oDAAoD;EAChE,QAAQ,IAAI,0DAA0D;EACtE;CACF;CAEA,QAAQ,IAAI,aAAa,QAAQ;CAEjC,MAAM,OAAO,IAAI,KAAK,EAAE,kBAAkB,OAAO,CAAC;CAElD,MAAM,KAAK,IAAI,OAAY,EACzB,SAAS,IAAI,gBAAgB,EAAE,KAAK,CAAC,EACvC,CAAC;CAED,IAAI;EACF,IAAI,YAAY,UAAU;GACxB,QAAQ,IAAI,gCAAgC;GAC5C,MAAM,aAAa,MAAM,mBAAmB,IAAI,cAAc;GAE9D,QAAQ,IAAI,6BAA6B;GACzC,QAAQ,IAAI,2BAA2B;GAEvC,KAAK,MAAM,aAAa,YAAY;IAClC,MAAM,SAAS,UAAU,aACrB,oBAAoB,UAAU,WAAW,YAAY,MACrD;IACJ,QAAQ,IAAI,GAAG,OAAO,KAAK,UAAU,MAAM;GAC7C;GAEA,MAAM,kBAAkB,MAAM,+BAC5B,IACA,cACF;GAEA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chboardConfig } from "./schema-CZsLzAZg.mjs";
2
2
  import { HostPlugin, MergedContribution, ResolvedPlugin } from "@powerhousedao/host-core";
3
3
  //#region src/plugin-host.d.mts
4
+ /**
5
+ * R2 — SwitchboardCore's plugin pipeline (rewire plan, carve map:
6
+ * uniform-runners-plan/rewire/r2-carve-map.md). Every switchboard boots
7
+ * through it: the carved subsystems (mcp, attachments, privacy, workflows) run
8
+ * as built-in plugins through these hook moments. A declared composition
9
+ * (the caller's `pluginComposition`) runs the plugins it lists; without one
10
+ * the default composition runs (defaultSwitchboardPlugins).
11
+ *
12
+ * Hook vocabulary (SwitchboardHooks), anchored to the boot spine:
13
+ * - transformServerOptions — after option/flag resolution, before anything opens
14
+ * - onReadModelsRegistering — inside reactor construction (build-time read models)
15
+ * - onHttpMounting — api exists; routes mount here
16
+ * - onSubgraphsRegistering — push into lateSubgraphs before the drain
17
+ * - onReactorReady — client + graphqlManager destructured
18
+ * - onDrivesReady — after core drive seeding / remote attachment
19
+ * - onShutdown — first in the subsystem-ordered teardown
20
+ */
4
21
  /**
5
22
  * The context plugins receive. Fields are populated as the boot spine reaches
6
23
  * them (api/client/graphqlManager are undefined before stage 17); concrete
@@ -43,4 +60,4 @@ interface SwitchboardHostContext {
43
60
  //#endregion
44
61
  export { SwitchboardHostContext as t };
45
62
  export {};
46
- //# sourceMappingURL=plugin-host-tTjDTNz0.d.mts.map
63
+ //# sourceMappingURL=plugin-host-Z-4Ruypj.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-host-Z-4Ruypj.d.mts","names":[],"sources":["../src/plugin-host.mts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;UAuCiB;;;EAGf;EACA,SAAS;;EAET,SAAS;EACT;EACA;;;EAGA;;;EAGA;EACA;;;EAGA;EACA;EACA;EACA;;EAEA;;EAEA;;EAEA;EACA;EACA;;EAEA,gBAAgB;EAChB,eAAe,eAAe"}
@@ -1,4 +1,4 @@
1
- import { t as SwitchboardHostContext } from "../plugin-host-tTjDTNz0.mjs";
1
+ import { t as SwitchboardHostContext } from "../plugin-host-Z-4Ruypj.mjs";
2
2
  import { z } from "zod";
3
3
  import { HostPlugin } from "@powerhousedao/host-core";
4
4
  //#region src/plugins/ai.d.mts
@@ -1,4 +1,4 @@
1
- import { t as SwitchboardHostContext } from "../plugin-host-tTjDTNz0.mjs";
1
+ import { t as SwitchboardHostContext } from "../plugin-host-Z-4Ruypj.mjs";
2
2
  import { z } from "zod";
3
3
  import { HostPlugin } from "@powerhousedao/host-core";
4
4
  //#region src/plugins/attachments.d.mts
@@ -1,4 +1,4 @@
1
- import { c as attachmentsPlugin, l as attachmentsPluginConfigSchema } from "../server-BS-PFzoK.mjs";
1
+ import { c as attachmentsPlugin, l as attachmentsPluginConfigSchema } from "../server-BMRdMNvC.mjs";
2
2
  export { attachmentsPlugin, attachmentsPlugin as default, attachmentsPluginConfigSchema };
3
- !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]="3e08bd59-0165-5ae0-9574-b4acb63805f2")}catch(e){}}();
4
- //# debugId=3e08bd59-0165-5ae0-9574-b4acb63805f2
3
+ !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]="52cbb932-b837-5ed3-8411-f63b07453e9d")}catch(e){}}();
4
+ //# debugId=52cbb932-b837-5ed3-8411-f63b07453e9d
@@ -1,4 +1,4 @@
1
- import { t as SwitchboardHostContext } from "../plugin-host-tTjDTNz0.mjs";
1
+ import { t as SwitchboardHostContext } from "../plugin-host-Z-4Ruypj.mjs";
2
2
  import { z } from "zod";
3
3
  import { HostPlugin } from "@powerhousedao/host-core";
4
4
  //#region src/plugins/mcp.d.mts
@@ -1,4 +1,4 @@
1
- import { t as SwitchboardHostContext } from "../plugin-host-tTjDTNz0.mjs";
1
+ import { t as SwitchboardHostContext } from "../plugin-host-Z-4Ruypj.mjs";
2
2
  import { z } from "zod";
3
3
  import { HostPlugin } from "@powerhousedao/host-core";
4
4
  //#region src/plugins/privacy.d.mts
@@ -1,4 +1,4 @@
1
- import { t as SwitchboardHostContext } from "../plugin-host-tTjDTNz0.mjs";
1
+ import { t as SwitchboardHostContext } from "../plugin-host-Z-4Ruypj.mjs";
2
2
  import { t as ComposedWorkflowRuntime } from "../workflow-runtime-CF5pc8mt.mjs";
3
3
  import { z } from "zod";
4
4
  import { HostPlugin } from "@powerhousedao/host-core";
@@ -7,7 +7,7 @@ import { HostPlugin } from "@powerhousedao/host-core";
7
7
  * R2.5 — the workflows subsystem as a built-in plugin. Presence is activation
8
8
  * (an explicit options.workflows.enabled === false still wins, mirroring the
9
9
  * mcp carve, and PH_WORKFLOWS_ENABLED=false is one). Turning workflows on from
10
- * the env or the config file works without a declared composition only: the
10
+ * the env works without a declared composition only: the
11
11
  * default composition then lists this plugin.
12
12
  *
13
13
  * The plugin also DECLARES the drive the runtime serves — the Workflows drive
@@ -1,4 +1,4 @@
1
- import { a as workflowsPlugin, i as workflowsDriveDeclaration, n as WORKFLOW_STUDIO_EDITOR_ID, o as workflowsPluginConfigSchema, r as createWorkflowsPlugin, t as DEFAULT_WORKFLOWS_DRIVE } from "../workflows-mdYUh3Us.mjs";
1
+ import { a as workflowsPlugin, i as workflowsDriveDeclaration, n as WORKFLOW_STUDIO_EDITOR_ID, o as workflowsPluginConfigSchema, r as createWorkflowsPlugin, t as DEFAULT_WORKFLOWS_DRIVE } from "../workflows-D2r6IKou.mjs";
2
2
  export { DEFAULT_WORKFLOWS_DRIVE, WORKFLOW_STUDIO_EDITOR_ID, createWorkflowsPlugin, createWorkflowsPlugin as default, workflowsDriveDeclaration, workflowsPlugin, workflowsPluginConfigSchema };
3
- !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]="0190a089-9d76-502d-a0ae-fb5b0a771426")}catch(e){}}();
4
- //# debugId=0190a089-9d76-502d-a0ae-fb5b0a771426
3
+ !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]="97e9607c-7d5c-5404-93ed-272131bab88c")}catch(e){}}();
4
+ //# debugId=97e9607c-7d5c-5404-93ed-272131bab88c