@powerhousedao/switchboard 6.2.3-dev.1 → 6.2.3-dev.100
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.tsbuild/test/ai-gateway.test.d.ts +2 -0
- package/.tsbuild/test/ai-gateway.test.d.ts.map +1 -0
- package/.tsbuild/test/attachments/byte-grants.test.d.ts +2 -0
- package/.tsbuild/test/attachments/byte-grants.test.d.ts.map +1 -0
- package/.tsbuild/test/attachments/byte-routes-read-gate.integration.test.d.ts +2 -0
- package/.tsbuild/test/attachments/byte-routes-read-gate.integration.test.d.ts.map +1 -0
- package/.tsbuild/test/attachments/reserve-metadata-parity.test.d.ts +2 -0
- package/.tsbuild/test/attachments/reserve-metadata-parity.test.d.ts.map +1 -0
- package/.tsbuild/test/attachments/url-signer.test.d.ts +2 -0
- package/.tsbuild/test/attachments/url-signer.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-auth-config.test.d.ts +2 -0
- package/.tsbuild/test/boot-auth-config.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-create-signature-policy.test.d.ts +2 -0
- package/.tsbuild/test/boot-create-signature-policy.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-desktop-auth.test.d.ts +2 -0
- package/.tsbuild/test/boot-desktop-auth.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-env-isolation.test.d.ts +2 -0
- package/.tsbuild/test/boot-env-isolation.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-helpers.d.ts +5 -0
- package/.tsbuild/test/boot-helpers.d.ts.map +1 -0
- package/.tsbuild/test/boot-inspection-enabled.test.d.ts +2 -0
- package/.tsbuild/test/boot-inspection-enabled.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-mcp-auth.test.d.ts +2 -0
- package/.tsbuild/test/boot-mcp-auth.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-mcp-enabled.test.d.ts +2 -0
- package/.tsbuild/test/boot-mcp-enabled.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-port-zero.test.d.ts +2 -0
- package/.tsbuild/test/boot-port-zero.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-preconditions.test.d.ts +2 -0
- package/.tsbuild/test/boot-preconditions.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-privacy.test.d.ts +2 -0
- package/.tsbuild/test/boot-privacy.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-ready-drives.test.d.ts +2 -0
- package/.tsbuild/test/boot-ready-drives.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-undo-v3-flag.test.d.ts +2 -0
- package/.tsbuild/test/boot-undo-v3-flag.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-unsupported-stored-documents.test.d.ts +2 -0
- package/.tsbuild/test/boot-unsupported-stored-documents.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-without-renown.test.d.ts +2 -0
- package/.tsbuild/test/boot-without-renown.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-without-require-signatures.test.d.ts +2 -0
- package/.tsbuild/test/boot-without-require-signatures.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-worker-trust-policy.test.d.ts +2 -0
- package/.tsbuild/test/boot-worker-trust-policy.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-workflow-singleton-conflict.test.d.ts +2 -0
- package/.tsbuild/test/boot-workflow-singleton-conflict.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-workflow-singleton-retry.test.d.ts +2 -0
- package/.tsbuild/test/boot-workflow-singleton-retry.test.d.ts.map +1 -0
- package/.tsbuild/test/builder-defaults.test.d.ts +2 -0
- package/.tsbuild/test/builder-defaults.test.d.ts.map +1 -0
- package/.tsbuild/test/config-from-env.test.d.ts +2 -0
- package/.tsbuild/test/config-from-env.test.d.ts.map +1 -0
- package/.tsbuild/test/config-merge.test.d.ts +2 -0
- package/.tsbuild/test/config-merge.test.d.ts.map +1 -0
- package/.tsbuild/test/config-schema.test.d.ts +2 -0
- package/.tsbuild/test/config-schema.test.d.ts.map +1 -0
- package/.tsbuild/test/create-signature-policy.test.d.ts +2 -0
- package/.tsbuild/test/create-signature-policy.test.d.ts.map +1 -0
- package/.tsbuild/test/default-drive-protocol-versions.test.d.ts +2 -0
- package/.tsbuild/test/default-drive-protocol-versions.test.d.ts.map +1 -0
- package/.tsbuild/test/default-drive-slug.test.d.ts +2 -0
- package/.tsbuild/test/default-drive-slug.test.d.ts.map +1 -0
- package/.tsbuild/test/delegated-publish.test.d.ts +2 -0
- package/.tsbuild/test/delegated-publish.test.d.ts.map +1 -0
- package/.tsbuild/test/durable-node-fs-pg16.test.d.ts +2 -0
- package/.tsbuild/test/durable-node-fs-pg16.test.d.ts.map +1 -0
- package/.tsbuild/test/fatal-shutdown.test.d.ts +2 -0
- package/.tsbuild/test/fatal-shutdown.test.d.ts.map +1 -0
- package/.tsbuild/test/inspection-throttle.test.d.ts +2 -0
- package/.tsbuild/test/inspection-throttle.test.d.ts.map +1 -0
- package/.tsbuild/test/keyframe-reclaim-store.test.d.ts +2 -0
- package/.tsbuild/test/keyframe-reclaim-store.test.d.ts.map +1 -0
- package/.tsbuild/test/observability-signals.test.d.ts +2 -0
- package/.tsbuild/test/observability-signals.test.d.ts.map +1 -0
- package/.tsbuild/test/permissions-backfill.test.d.ts +2 -0
- package/.tsbuild/test/permissions-backfill.test.d.ts.map +1 -0
- package/.tsbuild/test/pglite-preflight.test.d.ts +2 -0
- package/.tsbuild/test/pglite-preflight.test.d.ts.map +1 -0
- package/.tsbuild/test/pglite-storage-dirs.test.d.ts +2 -0
- package/.tsbuild/test/pglite-storage-dirs.test.d.ts.map +1 -0
- package/.tsbuild/test/pglite-store.test.d.ts +2 -0
- package/.tsbuild/test/pglite-store.test.d.ts.map +1 -0
- package/.tsbuild/test/plugin-config-schemas.test.d.ts +2 -0
- package/.tsbuild/test/plugin-config-schemas.test.d.ts.map +1 -0
- package/.tsbuild/test/plugin-presence.test.d.ts +2 -0
- package/.tsbuild/test/plugin-presence.test.d.ts.map +1 -0
- package/.tsbuild/test/port-probe.test.d.ts +2 -0
- package/.tsbuild/test/port-probe.test.d.ts.map +1 -0
- package/.tsbuild/test/processor-timing-log.test.d.ts +2 -0
- package/.tsbuild/test/processor-timing-log.test.d.ts.map +1 -0
- package/.tsbuild/test/redact-webhook-path.test.d.ts +2 -0
- package/.tsbuild/test/redact-webhook-path.test.d.ts.map +1 -0
- package/.tsbuild/test/renown-storage-path.test.d.ts +2 -0
- package/.tsbuild/test/renown-storage-path.test.d.ts.map +1 -0
- package/.tsbuild/test/renown-trust-policy.test.d.ts +2 -0
- package/.tsbuild/test/renown-trust-policy.test.d.ts.map +1 -0
- package/.tsbuild/test/served-schemas.test.d.ts +2 -0
- package/.tsbuild/test/served-schemas.test.d.ts.map +1 -0
- package/.tsbuild/test/shutdown.test.d.ts +2 -0
- package/.tsbuild/test/shutdown.test.d.ts.map +1 -0
- package/.tsbuild/test/snapshot-writer.d.ts +18 -0
- package/.tsbuild/test/snapshot-writer.d.ts.map +1 -0
- package/.tsbuild/test/store-lock.test.d.ts +2 -0
- package/.tsbuild/test/store-lock.test.d.ts.map +1 -0
- package/.tsbuild/test/two-switchboards.test.d.ts +2 -0
- package/.tsbuild/test/two-switchboards.test.d.ts.map +1 -0
- package/.tsbuild/test/unsupported-stored-documents.test.d.ts +2 -0
- package/.tsbuild/test/unsupported-stored-documents.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/harness.d.ts +56 -0
- package/.tsbuild/test/workflow/harness.d.ts.map +1 -0
- package/.tsbuild/test/workflow/oauth-apps-config.test.d.ts +2 -0
- package/.tsbuild/test/workflow/oauth-apps-config.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/oauth.test.d.ts +2 -0
- package/.tsbuild/test/workflow/oauth.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/resolvers.test.d.ts +2 -0
- package/.tsbuild/test/workflow/resolvers.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/runtime-host.test.d.ts +2 -0
- package/.tsbuild/test/workflow/runtime-host.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/waitpoint-routes.test.d.ts +2 -0
- package/.tsbuild/test/workflow/waitpoint-routes.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/waitpoint-runtime.test.d.ts +2 -0
- package/.tsbuild/test/workflow/waitpoint-runtime.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/webhook-dedupe.test.d.ts +2 -0
- package/.tsbuild/test/workflow/webhook-dedupe.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/webhook-signed.test.d.ts +2 -0
- package/.tsbuild/test/workflow/webhook-signed.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/webhook-trigger-test.test.d.ts +2 -0
- package/.tsbuild/test/workflow/webhook-trigger-test.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/webhook-unsigned.test.d.ts +2 -0
- package/.tsbuild/test/workflow/webhook-unsigned.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow-reactor-access.test.d.ts +2 -0
- package/.tsbuild/test/workflow-reactor-access.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow-reactor-enforcement.test.d.ts +2 -0
- package/.tsbuild/test/workflow-reactor-enforcement.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow-read-gate.test.d.ts +2 -0
- package/.tsbuild/test/workflow-read-gate.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow-runtime.test.d.ts +2 -0
- package/.tsbuild/test/workflow-runtime.test.d.ts.map +1 -0
- package/.tsbuild/test/workflows-plugin-config.test.d.ts +2 -0
- package/.tsbuild/test/workflows-plugin-config.test.d.ts.map +1 -0
- package/.tsbuild/tsconfig.tsbuildinfo +1 -1
- package/.tsbuild/tsdown.config.d.ts.map +1 -1
- package/.tsbuild/vitest.config.d.ts.map +1 -1
- package/Auth.md +144 -2
- package/CHANGELOG.md +1356 -0
- package/README.md +102 -22
- package/dist/boot.d.mts +46 -0
- package/dist/boot.d.mts.map +1 -0
- package/dist/boot.mjs +67 -0
- package/dist/boot.mjs.map +1 -0
- package/dist/config/from-env.d.mts +15 -0
- package/dist/config/from-env.d.mts.map +1 -0
- package/dist/config/from-env.mjs +4 -0
- package/dist/config/schema.d.mts +3 -0
- package/dist/config/schema.mjs +4 -0
- package/dist/from-env-FH4fPeIE.mjs +481 -0
- package/dist/from-env-FH4fPeIE.mjs.map +1 -0
- package/dist/index.d.mts +2 -1
- package/dist/index.mjs +98 -80
- package/dist/index.mjs.map +1 -1
- package/dist/install-packages.d.mts +2 -1
- package/dist/install-packages.mjs +2 -2
- package/dist/install-packages.mjs.map +1 -1
- package/dist/mcp-SsBK14Jm.mjs +32 -0
- package/dist/mcp-SsBK14Jm.mjs.map +1 -0
- package/dist/migrate.d.mts +2 -1
- package/dist/migrate.mjs +7 -5
- package/dist/migrate.mjs.map +1 -1
- package/dist/plugin-host-CK9_tVak.d.mts +46 -0
- package/dist/plugin-host-CK9_tVak.d.mts.map +1 -0
- package/dist/plugins/ai.d.mts +37 -0
- package/dist/plugins/ai.d.mts.map +1 -0
- package/dist/plugins/ai.mjs +400 -0
- package/dist/plugins/ai.mjs.map +1 -0
- package/dist/plugins/attachments.d.mts +33 -0
- package/dist/plugins/attachments.d.mts.map +1 -0
- package/dist/plugins/attachments.mjs +4 -0
- package/dist/plugins/mcp.d.mts +31 -0
- package/dist/plugins/mcp.d.mts.map +1 -0
- package/dist/plugins/mcp.mjs +4 -0
- package/dist/plugins/privacy.d.mts +22 -0
- package/dist/plugins/privacy.d.mts.map +1 -0
- package/dist/plugins/privacy.mjs +4 -0
- package/dist/plugins/workflows.d.mts +79 -0
- package/dist/plugins/workflows.d.mts.map +1 -0
- package/dist/plugins/workflows.mjs +4 -0
- package/dist/postgres-url-DTDhBjXX.mjs +11 -0
- package/dist/postgres-url-DTDhBjXX.mjs.map +1 -0
- package/dist/privacy-BO8Q25xI.mjs +44 -0
- package/dist/privacy-BO8Q25xI.mjs.map +1 -0
- package/dist/privacy-DxIJGH4P.mjs +91 -0
- package/dist/privacy-DxIJGH4P.mjs.map +1 -0
- package/dist/renown-layers-DmbWLt46.mjs +42 -0
- package/dist/renown-layers-DmbWLt46.mjs.map +1 -0
- package/dist/schema-CsY8bjsu.mjs +329 -0
- package/dist/schema-CsY8bjsu.mjs.map +1 -0
- package/dist/schema-MAUTnmj1.d.mts +251 -0
- package/dist/schema-MAUTnmj1.d.mts.map +1 -0
- package/dist/server-CirQ9hyu.mjs +2732 -0
- package/dist/server-CirQ9hyu.mjs.map +1 -0
- package/dist/server.d.mts +129 -189
- package/dist/server.d.mts.map +1 -1
- package/dist/server.mjs +5 -5
- package/dist/types-CidZdkhU.d.mts +314 -0
- package/dist/types-CidZdkhU.d.mts.map +1 -0
- package/dist/utils-Cm0TE6dP.mjs +148 -0
- package/dist/utils-Cm0TE6dP.mjs.map +1 -0
- package/dist/utils.d.mts +30 -5
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +5 -4
- package/dist/worker-pool-gyxJnCxA.mjs +304 -0
- package/dist/worker-pool-gyxJnCxA.mjs.map +1 -0
- package/dist/workflow-runtime-CF5pc8mt.d.mts +33 -0
- package/dist/workflow-runtime-CF5pc8mt.d.mts.map +1 -0
- package/dist/workflows-C9BQlyT0.mjs +1943 -0
- package/dist/workflows-C9BQlyT0.mjs.map +1 -0
- package/package.json +85 -24
- package/scripts/install-packages.sh +0 -0
- package/test/ai-gateway.test.ts +612 -0
- package/test/attachment-reference-read-model.test.ts +28 -20
- package/test/attachments/auth.test.ts +85 -0
- package/test/attachments/byte-grants.test.ts +290 -0
- package/test/attachments/byte-routes-read-gate.integration.test.ts +314 -0
- package/test/attachments/download-target.test.ts +211 -32
- package/test/attachments/index.test.ts +47 -4
- package/test/attachments/reserve-metadata-parity.test.ts +96 -0
- package/test/attachments/routes-integration.test.ts +60 -4
- package/test/attachments/routes.test.ts +297 -35
- package/test/attachments/service-config.test.ts +41 -19
- package/test/attachments/url-signer.test.ts +105 -0
- package/test/boot-auth-config.test.ts +109 -0
- package/test/boot-create-signature-policy.test.ts +110 -0
- package/test/boot-desktop-auth.test.ts +278 -0
- package/test/boot-env-isolation.test.ts +26 -0
- package/test/boot-helpers.ts +19 -0
- package/test/boot-inspection-enabled.test.ts +140 -0
- package/test/boot-mcp-auth.test.ts +449 -0
- package/test/boot-mcp-enabled.test.ts +119 -0
- package/test/boot-port-zero.test.ts +101 -0
- package/test/boot-preconditions.test.ts +213 -0
- package/test/boot-privacy.test.ts +232 -0
- package/test/boot-ready-drives.test.ts +141 -0
- package/test/boot-undo-v3-flag.test.ts +120 -0
- package/test/boot-unsupported-stored-documents.test.ts +214 -0
- package/test/boot-without-renown.test.ts +83 -0
- package/test/boot-without-require-signatures.test.ts +76 -0
- package/test/boot-worker-trust-policy.test.ts +91 -0
- package/test/boot-workflow-singleton-conflict.test.ts +109 -0
- package/test/boot-workflow-singleton-retry.test.ts +122 -0
- package/test/builder-defaults.test.ts +80 -0
- package/test/config-from-env.test.ts +963 -0
- package/test/config-merge.test.ts +248 -0
- package/test/config-schema.test.ts +167 -0
- package/test/create-signature-policy.test.ts +69 -0
- package/test/default-drive-protocol-versions.test.ts +79 -0
- package/test/default-drive-slug.test.ts +265 -0
- package/test/delegated-publish.test.ts +435 -0
- package/test/durable-node-fs-pg16.test.ts +80 -0
- package/test/fatal-shutdown.test.ts +205 -0
- package/test/goldens/packages.graphql +797 -0
- package/test/goldens/privacy.graphql +853 -0
- package/test/goldens/reactor-drive-nodes.graphql +827 -0
- package/test/goldens/resolvers.json +327 -0
- package/test/goldens/supergraph.graphql +5918 -0
- package/test/goldens/workflow-runtime.graphql +1548 -0
- package/test/inspection-throttle.test.ts +23 -0
- package/test/keyframe-reclaim-store.test.ts +156 -0
- package/test/observability-signals.test.ts +131 -0
- package/test/permissions-backfill.test.ts +486 -0
- package/test/pglite-dialect.test.ts +237 -2
- package/test/pglite-preflight.test.ts +313 -0
- package/test/pglite-storage-dirs.test.ts +113 -0
- package/test/pglite-store.test.ts +441 -0
- package/test/pglite-version.test.ts +9 -1
- package/test/plugin-config-schemas.test.ts +83 -0
- package/test/plugin-presence.test.ts +262 -0
- package/test/port-probe.test.ts +45 -0
- package/test/processor-timing-log.test.ts +109 -0
- package/test/reactor-feature-flags.test.ts +20 -0
- package/test/redact-webhook-path.test.ts +62 -0
- package/test/renown-storage-path.test.ts +40 -0
- package/test/renown-trust-policy.test.ts +313 -0
- package/test/served-schemas.test.ts +134 -0
- package/test/shutdown.test.ts +278 -0
- package/test/snapshot-writer.ts +94 -0
- package/test/store-lock.test.ts +65 -0
- package/test/two-switchboards.test.ts +146 -0
- package/test/unsupported-stored-documents.test.ts +72 -0
- package/test/worker-pool.test.ts +27 -1
- package/test/workflow/harness.ts +289 -0
- package/test/workflow/oauth-apps-config.test.ts +66 -0
- package/test/workflow/oauth.test.ts +286 -0
- package/test/workflow/resolvers.test.ts +488 -0
- package/test/workflow/runtime-host.test.ts +19 -0
- package/test/workflow/waitpoint-routes.test.ts +306 -0
- package/test/workflow/waitpoint-runtime.test.ts +204 -0
- package/test/workflow/webhook-dedupe.test.ts +295 -0
- package/test/workflow/webhook-signed.test.ts +509 -0
- package/test/workflow/webhook-trigger-test.test.ts +82 -0
- package/test/workflow/webhook-unsigned.test.ts +345 -0
- package/test/workflow-reactor-access.test.ts +384 -0
- package/test/workflow-reactor-enforcement.test.ts +808 -0
- package/test/workflow-read-gate.test.ts +213 -0
- package/test/workflow-runtime.test.ts +1254 -0
- package/test/workflows-plugin-config.test.ts +77 -0
- package/tsconfig.json +11 -2
- package/tsdown.config.ts +13 -1
- package/vitest.config.ts +65 -0
- package/dist/server-B2r6AQ4Q.mjs +0 -1553
- package/dist/server-B2r6AQ4Q.mjs.map +0 -1
- package/dist/utils-Baw7rThP.mjs +0 -80
- package/dist/utils-Baw7rThP.mjs.map +0 -1
|
@@ -0,0 +1,304 @@
|
|
|
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]="0abc3b7a-f473-50e3-9984-427c6dfd9263")}catch(e){}}();
|
|
3
|
+
import { t as isPostgresUrl } from "./postgres-url-DTDhBjXX.mjs";
|
|
4
|
+
import { existsSync, realpathSync } from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
7
|
+
import { readFile } from "node:fs/promises";
|
|
8
|
+
import os from "node:os";
|
|
9
|
+
//#region src/env.mts
|
|
10
|
+
function parseNonNegativeInt(raw, name) {
|
|
11
|
+
if (raw === void 0 || raw.trim() === "") return;
|
|
12
|
+
const value = Number.parseInt(raw, 10);
|
|
13
|
+
if (!Number.isInteger(value) || value < 0 || String(value) !== raw.trim()) throw new Error(`${name} must be a non-negative integer, got "${raw}"`);
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/boot-preconditions.mts
|
|
18
|
+
/** The reactor database the server boots with: its `dbPath` option, then the env. */
|
|
19
|
+
function reactorDbUrlOf(dbPath, env) {
|
|
20
|
+
return dbPath ?? env.PH_REACTOR_DATABASE_URL ?? env.PH_SWITCHBOARD_DATABASE_URL;
|
|
21
|
+
}
|
|
22
|
+
function workerTrustPolicyIssue(facts) {
|
|
23
|
+
if (facts.workers > 0 && facts.authEnforcement && facts.renownSource !== "remote") return "The executor worker pool (REACTOR_WORKERS) cannot verify signers when REACTOR_AUTH_ENFORCEMENT is on and Renown credentials are read from this switchboard (\"self\" or \"kept\" via auth.renown.source or RENOWN_SOURCE): pooled workers have no trust policy and would refuse every signed write. Set RENOWN_SOURCE=remote, or disable the worker pool (REACTOR_WORKERS=0).";
|
|
24
|
+
}
|
|
25
|
+
/** In the order the server checks them; empty when the pool is off. */
|
|
26
|
+
function workerPoolIssues(facts) {
|
|
27
|
+
if (facts.workers <= 0) return [];
|
|
28
|
+
const issues = [];
|
|
29
|
+
if (facts.dev) issues.push("The executor worker pool (REACTOR_WORKERS) is not supported in dev mode: Vite-loaded document models cannot cross a worker-thread boundary");
|
|
30
|
+
const trust = workerTrustPolicyIssue(facts);
|
|
31
|
+
if (trust) issues.push(trust);
|
|
32
|
+
if (!facts.reactorDbUrl || !isPostgresUrl(facts.reactorDbUrl)) issues.push("The executor worker pool (REACTOR_WORKERS) requires a Postgres reactor database — set PH_REACTOR_DATABASE_URL or PH_SWITCHBOARD_DATABASE_URL. PGlite cannot be shared across worker threads.");
|
|
33
|
+
return issues;
|
|
34
|
+
}
|
|
35
|
+
/** The projection worker's preconditions, assuming it is enabled. */
|
|
36
|
+
function projectionWorkerIssues(facts) {
|
|
37
|
+
const issues = [];
|
|
38
|
+
if (facts.dev) issues.push("The projection worker (REACTOR_PROJECTION_WORKER) is not supported in dev mode: Vite-loaded document models cannot cross a worker-thread boundary");
|
|
39
|
+
if (!facts.reactorDbUrl || !isPostgresUrl(facts.reactorDbUrl)) issues.push("The projection worker (REACTOR_PROJECTION_WORKER) requires a Postgres reactor database — set PH_REACTOR_DATABASE_URL or PH_SWITCHBOARD_DATABASE_URL. PGlite cannot be shared across worker threads.");
|
|
40
|
+
return issues;
|
|
41
|
+
}
|
|
42
|
+
function switchboardBootIssues(facts) {
|
|
43
|
+
return [...workerPoolIssues(facts), ...facts.projectionWorker ? projectionWorkerIssues(facts) : []];
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/projection-worker.mts
|
|
47
|
+
const DEFAULT_DB_POOL_SIZE_PROJECTION = 8;
|
|
48
|
+
const ON_TOKENS = [
|
|
49
|
+
"1",
|
|
50
|
+
"true",
|
|
51
|
+
"on",
|
|
52
|
+
"yes"
|
|
53
|
+
];
|
|
54
|
+
const OFF_TOKENS = [
|
|
55
|
+
"0",
|
|
56
|
+
"false",
|
|
57
|
+
"off",
|
|
58
|
+
"no"
|
|
59
|
+
];
|
|
60
|
+
/**
|
|
61
|
+
* Enabled by REACTOR_PROJECTION_WORKER (1/true/on/yes, case-insensitive) or
|
|
62
|
+
* `input.enabled`, which wins when defined; null when off (the default).
|
|
63
|
+
*/
|
|
64
|
+
function resolveProjectionWorkerOptions(input, env) {
|
|
65
|
+
if (!(input?.enabled ?? parseOnOff(env.REACTOR_PROJECTION_WORKER) ?? false)) return null;
|
|
66
|
+
const dbPoolSize = input?.dbPoolSize ?? parseNonNegativeInt(env.REACTOR_DB_POOL_SIZE_PROJECTION, "REACTOR_DB_POOL_SIZE_PROJECTION") ?? DEFAULT_DB_POOL_SIZE_PROJECTION;
|
|
67
|
+
if (dbPoolSize < 1) throw new Error("REACTOR_DB_POOL_SIZE_PROJECTION must be at least 1; the projection worker cannot run without a pool");
|
|
68
|
+
return { dbPoolSize };
|
|
69
|
+
}
|
|
70
|
+
/** Same preconditions as the executor worker pool; message shape mirrors server.mts. */
|
|
71
|
+
function assertProjectionWorkerSupported(args) {
|
|
72
|
+
const issue = projectionWorkerIssues(args).at(0);
|
|
73
|
+
if (issue) throw new Error(issue);
|
|
74
|
+
}
|
|
75
|
+
function parseOnOff(raw) {
|
|
76
|
+
if (raw === void 0 || raw.trim() === "") return;
|
|
77
|
+
const token = raw.trim().toLowerCase();
|
|
78
|
+
if (ON_TOKENS.includes(token)) return true;
|
|
79
|
+
if (OFF_TOKENS.includes(token)) return false;
|
|
80
|
+
throw new Error(`REACTOR_PROJECTION_WORKER must be one of 1, true, on, yes, 0, false, off, no, got "${raw}"`);
|
|
81
|
+
}
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region src/worker-pool.mts
|
|
84
|
+
const DEFAULT_DB_POOL_SIZE_PER_WORKER = 2;
|
|
85
|
+
const DEFAULT_ACQUIRE_TIMEOUT_MS = 5e3;
|
|
86
|
+
const DEFAULT_DB_POOL_SIZE_HOST = 16;
|
|
87
|
+
const AUTO_RESERVED_CORES = 2;
|
|
88
|
+
const AUTO_WORKER_CAP = 8;
|
|
89
|
+
/** Worker count for "auto": always at least 1 — auto sizes the pool, it does not turn worker mode off. */
|
|
90
|
+
function autoWorkerCount(availableCores) {
|
|
91
|
+
return Math.max(1, Math.min(AUTO_WORKER_CAP, availableCores - AUTO_RESERVED_CORES));
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Effective worker-pool config from programmatic options (which win) and the
|
|
95
|
+
* REACTOR_* env vars; null when disabled (numWorkers 0, the default).
|
|
96
|
+
* `"auto"` sizes the pool from the machine's available cores.
|
|
97
|
+
*/
|
|
98
|
+
function resolveWorkerPoolOptions(input, env, availableCores = os.availableParallelism()) {
|
|
99
|
+
const requested = input?.numWorkers ?? parseWorkerCount(env.REACTOR_WORKERS) ?? 0;
|
|
100
|
+
const mode = requested === "auto" ? "auto" : "explicit";
|
|
101
|
+
const numWorkers = requested === "auto" ? autoWorkerCount(availableCores) : requested;
|
|
102
|
+
if (!Number.isInteger(numWorkers) || numWorkers < 0) throw new Error(`workerPool.numWorkers must be "auto" or a non-negative integer, got ${numWorkers}`);
|
|
103
|
+
if (numWorkers === 0) return null;
|
|
104
|
+
return {
|
|
105
|
+
numWorkers,
|
|
106
|
+
mode,
|
|
107
|
+
dbPoolSizePerWorker: input?.dbPoolSizePerWorker ?? parseNonNegativeInt(env.REACTOR_DB_POOL_SIZE_WORKER, "REACTOR_DB_POOL_SIZE_WORKER") ?? DEFAULT_DB_POOL_SIZE_PER_WORKER,
|
|
108
|
+
acquireTimeoutMs: input?.acquireTimeoutMs ?? parseNonNegativeInt(env.REACTOR_DB_ACQUIRE_TIMEOUT_MS, "REACTOR_DB_ACQUIRE_TIMEOUT_MS") ?? DEFAULT_ACQUIRE_TIMEOUT_MS
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Size of the reactor's own (host) Postgres pool. Unlike the worker pool there
|
|
113
|
+
* is no "disabled" state — the host pool is the only Postgres pool in the
|
|
114
|
+
* server path, backing both reactor storage and the read models that reach it
|
|
115
|
+
* via `withSchema` — so 0 is rejected rather than read as "off".
|
|
116
|
+
*
|
|
117
|
+
* The acquire timeout is deliberately not configurable here: the host pool
|
|
118
|
+
* waits indefinitely today, and making it finite converts saturation from a
|
|
119
|
+
* latency problem into a thrown error on the read-model path. That is a
|
|
120
|
+
* behavior change worth making separately, once the retry semantics of a
|
|
121
|
+
* rejected `pool.connect()` inside the read-model coordinator are settled.
|
|
122
|
+
*/
|
|
123
|
+
function resolveHostPoolSize(env) {
|
|
124
|
+
const poolSize = parseNonNegativeInt(env.REACTOR_DB_POOL_SIZE_HOST, "REACTOR_DB_POOL_SIZE_HOST") ?? DEFAULT_DB_POOL_SIZE_HOST;
|
|
125
|
+
if (poolSize < 1) throw new Error("REACTOR_DB_POOL_SIZE_HOST must be at least 1; the host pool cannot be disabled");
|
|
126
|
+
return poolSize;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* DbConfig for each worker's own pool, parsed from a postgres:// URL.
|
|
130
|
+
* Explicit host, database, and user are required — no pg-side defaults.
|
|
131
|
+
*/
|
|
132
|
+
function buildWorkerDbConfig(postgresUrl, options) {
|
|
133
|
+
let parsed;
|
|
134
|
+
try {
|
|
135
|
+
parsed = new URL(postgresUrl);
|
|
136
|
+
} catch {
|
|
137
|
+
throw new Error(`Worker pool requires a valid postgres:// URL for the reactor database, got "${postgresUrl}"`);
|
|
138
|
+
}
|
|
139
|
+
const database = decodeURIComponent(parsed.pathname.replace(/^\//, ""));
|
|
140
|
+
if (!parsed.hostname || !database) throw new Error(`Worker pool requires a postgres URL with a host and database name, got "${postgresUrl}"`);
|
|
141
|
+
if (!parsed.username) throw new Error(`Worker pool requires explicit credentials in the postgres URL (workers open their own connections), got "${postgresUrl}"`);
|
|
142
|
+
const sslmode = parsed.searchParams.get("sslmode");
|
|
143
|
+
const ssl = parsed.searchParams.get("ssl") === "true" || sslmode !== null && sslmode !== "disable";
|
|
144
|
+
return {
|
|
145
|
+
host: parsed.hostname,
|
|
146
|
+
port: parsed.port ? Number(parsed.port) : 5432,
|
|
147
|
+
database,
|
|
148
|
+
user: decodeURIComponent(parsed.username),
|
|
149
|
+
password: decodeURIComponent(parsed.password),
|
|
150
|
+
ssl,
|
|
151
|
+
applicationName: "switchboard-worker",
|
|
152
|
+
poolSize: options.dbPoolSizePerWorker,
|
|
153
|
+
connectionTimeoutMillis: options.acquireTimeoutMs
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
/** Specifiers of the base models switchboard always registers. */
|
|
157
|
+
const BASE_MODEL_SPECIFIERS = [
|
|
158
|
+
"document-model",
|
|
159
|
+
"@powerhousedao/shared/document-drive",
|
|
160
|
+
"@powerhousedao/reactor-drive",
|
|
161
|
+
"@powerhousedao/reactor-group/document-models"
|
|
162
|
+
];
|
|
163
|
+
function isModelModule(value) {
|
|
164
|
+
const candidate = value;
|
|
165
|
+
return typeof candidate?.reducer === "function" && typeof candidate.documentModel?.global?.id === "string";
|
|
166
|
+
}
|
|
167
|
+
async function keepImportableSources(sources, logger) {
|
|
168
|
+
const kept = [];
|
|
169
|
+
for (const source of sources) try {
|
|
170
|
+
const exports = await import(pathToFileURL(source.filePath).href);
|
|
171
|
+
if (Object.values(exports).some(isModelModule)) kept.push(source);
|
|
172
|
+
} catch (error) {
|
|
173
|
+
logger.warn(`Worker model sources: "${source.filePath}" does not import, so workflow pieces will not see its models: ${String(error)}`);
|
|
174
|
+
}
|
|
175
|
+
return kept;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Resolves base models and configured package identifiers to `{ filePath }`
|
|
179
|
+
* sources for the reactor builder. Resolution to absolute paths happens here
|
|
180
|
+
* because workers (and the builder) resolve bare specifiers from the reactor
|
|
181
|
+
* package's own dependency context, which cannot see switchboard or project
|
|
182
|
+
* packages. Unresolvable identifiers are skipped with a warning; the builder
|
|
183
|
+
* fails the boot if a registered model ends up without an importable source.
|
|
184
|
+
*/
|
|
185
|
+
async function resolveWorkerModelSources(packages, logger, options = {}) {
|
|
186
|
+
const sources = [];
|
|
187
|
+
for (const identifier of [...BASE_MODEL_SPECIFIERS, ...packages]) {
|
|
188
|
+
const filePath = await resolveModelModuleFile(identifier) ?? await resolveRemoteSafely(identifier, options.resolveRemote, logger);
|
|
189
|
+
if (!filePath) {
|
|
190
|
+
logger.warn(`Worker model sources: no importable document-models entry for "${identifier}", skipping`);
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
sources.push({ filePath });
|
|
194
|
+
}
|
|
195
|
+
return sources;
|
|
196
|
+
}
|
|
197
|
+
async function resolveRemoteSafely(identifier, resolveRemote, logger) {
|
|
198
|
+
if (!resolveRemote) return null;
|
|
199
|
+
try {
|
|
200
|
+
return await resolveRemote(identifier);
|
|
201
|
+
} catch (error) {
|
|
202
|
+
logger.warn(`Worker model sources: could not cache "${identifier}" from the registry: ${String(error)}`);
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Absolute file path of a source's models barrel. Mirrors reactor-api's
|
|
208
|
+
* import-resolver: import.meta.resolve, then the project's node_modules via
|
|
209
|
+
* the package.json exports map / dist layout.
|
|
210
|
+
*/
|
|
211
|
+
async function resolveModelModuleFile(source) {
|
|
212
|
+
if (isFsPath(source)) return resolveFromPackageDir(source, "./document-models");
|
|
213
|
+
const specifier = BASE_MODEL_SPECIFIERS.includes(source) ? source : `${source}/document-models`;
|
|
214
|
+
try {
|
|
215
|
+
const resolved = import.meta.resolve(specifier);
|
|
216
|
+
if (resolved.startsWith("file:")) return fileURLToPath(resolved);
|
|
217
|
+
} catch {}
|
|
218
|
+
const { packageName, subpath } = splitSpecifier(specifier);
|
|
219
|
+
const packageDir = path.join(process.cwd(), "node_modules", packageName);
|
|
220
|
+
if (!existsSync(packageDir)) return null;
|
|
221
|
+
let realDir;
|
|
222
|
+
try {
|
|
223
|
+
realDir = realpathSync(packageDir);
|
|
224
|
+
} catch {
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
return resolveFromPackageDir(realDir, subpath);
|
|
228
|
+
}
|
|
229
|
+
function splitSpecifier(specifier) {
|
|
230
|
+
const parts = specifier.split("/");
|
|
231
|
+
const packageSegments = specifier.startsWith("@") ? 2 : 1;
|
|
232
|
+
const packageName = parts.slice(0, packageSegments).join("/");
|
|
233
|
+
const rest = parts.slice(packageSegments).join("/");
|
|
234
|
+
return {
|
|
235
|
+
packageName,
|
|
236
|
+
subpath: rest ? `./${rest}` : "."
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
/** Exports-map lookup (import condition), then conventional dist paths. */
|
|
240
|
+
async function resolveFromPackageDir(packageDir, subpath) {
|
|
241
|
+
const fromManifest = await resolveViaManifest(packageDir, subpath);
|
|
242
|
+
if (fromManifest) return fromManifest;
|
|
243
|
+
const candidates = subpath === "." ? [path.join(packageDir, "dist", "index.js")] : [
|
|
244
|
+
path.join(packageDir, "dist", subpath.slice(2), "index.js"),
|
|
245
|
+
path.join(packageDir, "dist", `${subpath.slice(2)}.js`),
|
|
246
|
+
path.join(packageDir, subpath.slice(2), "index.js")
|
|
247
|
+
];
|
|
248
|
+
for (const candidate of candidates) if (existsSync(candidate)) return candidate;
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
async function resolveViaManifest(packageDir, subpath) {
|
|
252
|
+
let raw;
|
|
253
|
+
try {
|
|
254
|
+
raw = await readFile(path.join(packageDir, "package.json"), "utf8");
|
|
255
|
+
} catch {
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
258
|
+
let manifest;
|
|
259
|
+
try {
|
|
260
|
+
manifest = JSON.parse(raw);
|
|
261
|
+
} catch {
|
|
262
|
+
return null;
|
|
263
|
+
}
|
|
264
|
+
let entry;
|
|
265
|
+
const exportsField = manifest.exports;
|
|
266
|
+
if (exportsField !== null && typeof exportsField === "object" && !Array.isArray(exportsField)) {
|
|
267
|
+
const map = exportsField;
|
|
268
|
+
entry = Object.keys(map).some((key) => key.startsWith(".")) ? map[subpath] : subpath === "." ? map : void 0;
|
|
269
|
+
} else if (typeof exportsField === "string" && subpath === ".") entry = exportsField;
|
|
270
|
+
let target = pickImportTarget(entry);
|
|
271
|
+
if (!target && subpath === "." && typeof manifest.main === "string") target = manifest.main;
|
|
272
|
+
if (!target) return null;
|
|
273
|
+
const resolved = path.join(packageDir, target);
|
|
274
|
+
return existsSync(resolved) ? resolved : null;
|
|
275
|
+
}
|
|
276
|
+
function pickImportTarget(entry) {
|
|
277
|
+
if (typeof entry === "string") return entry;
|
|
278
|
+
if (typeof entry !== "object" || entry === null) return null;
|
|
279
|
+
const conditions = entry;
|
|
280
|
+
for (const condition of [
|
|
281
|
+
"import",
|
|
282
|
+
"node",
|
|
283
|
+
"default"
|
|
284
|
+
]) {
|
|
285
|
+
const value = conditions[condition];
|
|
286
|
+
if (typeof value === "string") return value;
|
|
287
|
+
}
|
|
288
|
+
return null;
|
|
289
|
+
}
|
|
290
|
+
function isFsPath(identifier) {
|
|
291
|
+
return path.isAbsolute(identifier) || identifier.startsWith("./") || identifier.startsWith("../");
|
|
292
|
+
}
|
|
293
|
+
function parseWorkerCount(raw) {
|
|
294
|
+
if (raw === void 0 || raw.trim() === "") return;
|
|
295
|
+
if (raw.trim().toLowerCase() === "auto") return "auto";
|
|
296
|
+
const value = Number.parseInt(raw, 10);
|
|
297
|
+
if (!Number.isInteger(value) || value < 0 || String(value) !== raw.trim()) throw new Error(`REACTOR_WORKERS must be "auto" or a non-negative integer, got "${raw}"`);
|
|
298
|
+
return value;
|
|
299
|
+
}
|
|
300
|
+
//#endregion
|
|
301
|
+
export { resolveWorkerModelSources as a, parseOnOff as c, reactorDbUrlOf as d, switchboardBootIssues as f, parseNonNegativeInt as h, resolveHostPoolSize as i, resolveProjectionWorkerOptions as l, workerTrustPolicyIssue as m, keepImportableSources as n, resolveWorkerPoolOptions as o, workerPoolIssues as p, parseWorkerCount as r, assertProjectionWorkerSupported as s, buildWorkerDbConfig as t, projectionWorkerIssues as u };
|
|
302
|
+
|
|
303
|
+
//# sourceMappingURL=worker-pool-gyxJnCxA.mjs.map
|
|
304
|
+
//# debugId=0abc3b7a-f473-50e3-9984-427c6dfd9263
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-pool-gyxJnCxA.mjs","sources":["../src/env.mts","../src/boot-preconditions.mts","../src/projection-worker.mts","../src/worker-pool.mts"],"sourcesContent":["export function parseNonNegativeInt(\n raw: string | undefined,\n name: string,\n): number | undefined {\n if (raw === undefined || raw.trim() === \"\") {\n return undefined;\n }\n const value = Number.parseInt(raw, 10);\n if (!Number.isInteger(value) || value < 0 || String(value) !== raw.trim()) {\n throw new Error(`${name} must be a non-negative integer, got \"${raw}\"`);\n }\n return value;\n}\n","import { isPostgresUrl } from \"./postgres-url.mjs\";\n\n/** What the server refuses to boot with; it throws the first, `ph host check` reports all. */\nexport interface SwitchboardBootFacts {\n dev: boolean;\n /** Executor pool size; 0 when the pool is off. */\n workers: number;\n projectionWorker: boolean;\n reactorDbUrl: string | undefined;\n authEnforcement: boolean;\n renownSource: \"self\" | \"remote\" | \"kept\";\n}\n\n/** The reactor database the server boots with: its `dbPath` option, then the env. */\nexport function reactorDbUrlOf(\n dbPath: string | undefined,\n env: Readonly<Record<string, string | undefined>>,\n): string | undefined {\n return (\n dbPath ?? env.PH_REACTOR_DATABASE_URL ?? env.PH_SWITCHBOARD_DATABASE_URL\n );\n}\n\nexport function workerTrustPolicyIssue(\n facts: Pick<\n SwitchboardBootFacts,\n \"workers\" | \"authEnforcement\" | \"renownSource\"\n >,\n): string | undefined {\n if (\n facts.workers > 0 &&\n facts.authEnforcement &&\n facts.renownSource !== \"remote\"\n ) {\n return (\n \"The executor worker pool (REACTOR_WORKERS) cannot verify signers when \" +\n \"REACTOR_AUTH_ENFORCEMENT is on and Renown credentials are read from \" +\n 'this switchboard (\"self\" or \"kept\" via auth.renown.source or RENOWN_SOURCE): ' +\n \"pooled workers have no trust policy and would refuse every signed \" +\n \"write. Set RENOWN_SOURCE=remote, or disable the worker pool \" +\n \"(REACTOR_WORKERS=0).\"\n );\n }\n return undefined;\n}\n\n/** In the order the server checks them; empty when the pool is off. */\nexport function workerPoolIssues(facts: SwitchboardBootFacts): string[] {\n if (facts.workers <= 0) return [];\n const issues: string[] = [];\n if (facts.dev) {\n issues.push(\n \"The executor worker pool (REACTOR_WORKERS) is not supported in dev mode: Vite-loaded document models cannot cross a worker-thread boundary\",\n );\n }\n const trust = workerTrustPolicyIssue(facts);\n if (trust) issues.push(trust);\n if (!facts.reactorDbUrl || !isPostgresUrl(facts.reactorDbUrl)) {\n issues.push(\n \"The executor worker pool (REACTOR_WORKERS) requires a Postgres reactor database — set PH_REACTOR_DATABASE_URL or PH_SWITCHBOARD_DATABASE_URL. PGlite cannot be shared across worker threads.\",\n );\n }\n return issues;\n}\n\n/** The projection worker's preconditions, assuming it is enabled. */\nexport function projectionWorkerIssues(\n facts: Pick<SwitchboardBootFacts, \"dev\" | \"reactorDbUrl\">,\n): string[] {\n const issues: string[] = [];\n if (facts.dev) {\n issues.push(\n \"The projection worker (REACTOR_PROJECTION_WORKER) is not supported in dev mode: Vite-loaded document models cannot cross a worker-thread boundary\",\n );\n }\n if (!facts.reactorDbUrl || !isPostgresUrl(facts.reactorDbUrl)) {\n issues.push(\n \"The projection worker (REACTOR_PROJECTION_WORKER) requires a Postgres reactor database — set PH_REACTOR_DATABASE_URL or PH_SWITCHBOARD_DATABASE_URL. PGlite cannot be shared across worker threads.\",\n );\n }\n return issues;\n}\n\nexport function switchboardBootIssues(facts: SwitchboardBootFacts): string[] {\n return [\n ...workerPoolIssues(facts),\n ...(facts.projectionWorker ? projectionWorkerIssues(facts) : []),\n ];\n}\n","import { projectionWorkerIssues } from \"./boot-preconditions.mjs\";\nimport { parseNonNegativeInt } from \"./env.mjs\";\n\nexport type SwitchboardProjectionWorkerOptions = {\n dbPoolSize: number;\n};\n\nexport type SwitchboardProjectionWorkerInput = {\n enabled?: boolean;\n dbPoolSize?: number;\n};\n\n// Run 11 of the bench sweep saw chain.depth ~6.5 at one shard, so 8 covers the\n// working set; behind a 25-slot transaction pooler a larger pool is not spendable.\nconst DEFAULT_DB_POOL_SIZE_PROJECTION = 8;\n\nconst ON_TOKENS = [\"1\", \"true\", \"on\", \"yes\"];\nconst OFF_TOKENS = [\"0\", \"false\", \"off\", \"no\"];\n\n/**\n * Enabled by REACTOR_PROJECTION_WORKER (1/true/on/yes, case-insensitive) or\n * `input.enabled`, which wins when defined; null when off (the default).\n */\nexport function resolveProjectionWorkerOptions(\n input: SwitchboardProjectionWorkerInput | undefined,\n env: NodeJS.ProcessEnv,\n): SwitchboardProjectionWorkerOptions | null {\n const enabled =\n input?.enabled ?? parseOnOff(env.REACTOR_PROJECTION_WORKER) ?? false;\n if (!enabled) {\n return null;\n }\n const dbPoolSize =\n input?.dbPoolSize ??\n parseNonNegativeInt(\n env.REACTOR_DB_POOL_SIZE_PROJECTION,\n \"REACTOR_DB_POOL_SIZE_PROJECTION\",\n ) ??\n DEFAULT_DB_POOL_SIZE_PROJECTION;\n if (dbPoolSize < 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 { dbPoolSize };\n}\n\n/** Same preconditions as the executor worker pool; message shape mirrors server.mts. */\nexport function assertProjectionWorkerSupported(args: {\n dev: boolean;\n reactorDbUrl: string | undefined;\n}): void {\n const issue = projectionWorkerIssues(args).at(0);\n if (issue) throw new Error(issue);\n}\n\nexport function parseOnOff(raw: string | undefined): boolean | undefined {\n if (raw === undefined || raw.trim() === \"\") {\n return undefined;\n }\n const token = raw.trim().toLowerCase();\n if (ON_TOKENS.includes(token)) {\n return true;\n }\n if (OFF_TOKENS.includes(token)) {\n return false;\n }\n throw new Error(\n `REACTOR_PROJECTION_WORKER must be one of 1, true, on, yes, 0, false, off, no, got \"${raw}\"`,\n );\n}\n","import type { DbConfig, FileModelSource } from \"@powerhousedao/reactor\";\nimport type { ILogger } from \"document-model\";\nimport { existsSync, realpathSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport os from \"node:os\";\nimport path from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport { parseNonNegativeInt } from \"./env.mjs\";\n\nexport type WorkerCountInput = number | \"auto\";\n\nexport type SwitchboardWorkerPoolOptions = {\n numWorkers: number;\n /** Whether numWorkers was given explicitly or sized from the core count. */\n mode: \"explicit\" | \"auto\";\n dbPoolSizePerWorker: number;\n acquireTimeoutMs: number;\n};\n\nexport type SwitchboardWorkerPoolInput = {\n numWorkers?: WorkerCountInput;\n dbPoolSizePerWorker?: number;\n acquireTimeoutMs?: number;\n};\n\nconst DEFAULT_DB_POOL_SIZE_PER_WORKER = 2;\nconst DEFAULT_ACQUIRE_TIMEOUT_MS = 5000;\n\n// Host reactor pool. pg-pool's own default is 10, below the bench harness's\n// floor of 16 (bench/host/src/main.ts, REACTOR_DB_POOL_SIZE_HOST). Run 8 of\n// the sweep found throughput flat from 16 to 96 but per-op index p50\n// collapsing 262ms -> 43ms, so this buys latency, not throughput — and only\n// up to whatever the connection budget in front of Postgres allows.\nconst DEFAULT_DB_POOL_SIZE_HOST = 16;\n\n// Auto-sizing: reserve cores for the host event loop (queue, read models,\n// HTTP) and cap at the top of the bench sweep envelope, which also bounds\n// the worker Postgres-connection budget.\nconst AUTO_RESERVED_CORES = 2;\nconst AUTO_WORKER_CAP = 8;\n\n/** Worker count for \"auto\": always at least 1 — auto sizes the pool, it does not turn worker mode off. */\nexport function autoWorkerCount(availableCores: number): number {\n return Math.max(\n 1,\n Math.min(AUTO_WORKER_CAP, availableCores - AUTO_RESERVED_CORES),\n );\n}\n\n/**\n * Effective worker-pool config from programmatic options (which win) and the\n * REACTOR_* env vars; null when disabled (numWorkers 0, the default).\n * `\"auto\"` sizes the pool from the machine's available cores.\n */\nexport function resolveWorkerPoolOptions(\n input: SwitchboardWorkerPoolInput | undefined,\n env: NodeJS.ProcessEnv,\n availableCores: number = os.availableParallelism(),\n): SwitchboardWorkerPoolOptions | null {\n const requested =\n input?.numWorkers ?? parseWorkerCount(env.REACTOR_WORKERS) ?? 0;\n const mode = requested === \"auto\" ? \"auto\" : \"explicit\";\n const numWorkers =\n requested === \"auto\" ? autoWorkerCount(availableCores) : requested;\n if (!Number.isInteger(numWorkers) || numWorkers < 0) {\n throw new Error(\n `workerPool.numWorkers must be \"auto\" or a non-negative integer, got ${numWorkers}`,\n );\n }\n if (numWorkers === 0) {\n return null;\n }\n return {\n numWorkers,\n mode,\n dbPoolSizePerWorker:\n input?.dbPoolSizePerWorker ??\n parseNonNegativeInt(\n env.REACTOR_DB_POOL_SIZE_WORKER,\n \"REACTOR_DB_POOL_SIZE_WORKER\",\n ) ??\n DEFAULT_DB_POOL_SIZE_PER_WORKER,\n acquireTimeoutMs:\n input?.acquireTimeoutMs ??\n parseNonNegativeInt(\n env.REACTOR_DB_ACQUIRE_TIMEOUT_MS,\n \"REACTOR_DB_ACQUIRE_TIMEOUT_MS\",\n ) ??\n DEFAULT_ACQUIRE_TIMEOUT_MS,\n };\n}\n\n/**\n * Size of the reactor's own (host) Postgres pool. Unlike the worker pool there\n * is no \"disabled\" state — the host pool is the only Postgres pool in the\n * server path, backing both reactor storage and the read models that reach it\n * via `withSchema` — so 0 is rejected rather than read as \"off\".\n *\n * The acquire timeout is deliberately not configurable here: the host pool\n * waits indefinitely today, and making it finite converts saturation from a\n * latency problem into a thrown error on the read-model path. That is a\n * behavior change worth making separately, once the retry semantics of a\n * rejected `pool.connect()` inside the read-model coordinator are settled.\n */\nexport function resolveHostPoolSize(env: NodeJS.ProcessEnv): number {\n const poolSize =\n parseNonNegativeInt(\n env.REACTOR_DB_POOL_SIZE_HOST,\n \"REACTOR_DB_POOL_SIZE_HOST\",\n ) ?? DEFAULT_DB_POOL_SIZE_HOST;\n if (poolSize < 1) {\n throw new Error(\n \"REACTOR_DB_POOL_SIZE_HOST must be at least 1; the host pool cannot be disabled\",\n );\n }\n return poolSize;\n}\n\n/**\n * DbConfig for each worker's own pool, parsed from a postgres:// URL.\n * Explicit host, database, and user are required — no pg-side defaults.\n */\nexport function buildWorkerDbConfig(\n postgresUrl: string,\n options: Pick<\n SwitchboardWorkerPoolOptions,\n \"dbPoolSizePerWorker\" | \"acquireTimeoutMs\"\n >,\n): DbConfig {\n let parsed: URL;\n try {\n parsed = new URL(postgresUrl);\n } catch {\n throw new Error(\n `Worker pool requires a valid postgres:// URL for the reactor database, got \"${postgresUrl}\"`,\n );\n }\n const database = decodeURIComponent(parsed.pathname.replace(/^\\//, \"\"));\n if (!parsed.hostname || !database) {\n throw new Error(\n `Worker pool requires a postgres URL with a host and database name, got \"${postgresUrl}\"`,\n );\n }\n if (!parsed.username) {\n throw new Error(\n `Worker pool requires explicit credentials in the postgres URL (workers open their own connections), got \"${postgresUrl}\"`,\n );\n }\n const sslmode = parsed.searchParams.get(\"sslmode\");\n const ssl =\n parsed.searchParams.get(\"ssl\") === \"true\" ||\n (sslmode !== null && sslmode !== \"disable\");\n return {\n host: parsed.hostname,\n port: parsed.port ? Number(parsed.port) : 5432,\n database,\n user: decodeURIComponent(parsed.username),\n password: decodeURIComponent(parsed.password),\n ssl,\n applicationName: \"switchboard-worker\",\n poolSize: options.dbPoolSizePerWorker,\n connectionTimeoutMillis: options.acquireTimeoutMs,\n };\n}\n\n/** Specifiers of the base models switchboard always registers. */\nconst BASE_MODEL_SPECIFIERS = [\n \"document-model\",\n \"@powerhousedao/shared/document-drive\",\n \"@powerhousedao/reactor-drive\",\n \"@powerhousedao/reactor-group/document-models\",\n];\n\n// As the reactor builder tells a module from the rest of a source's exports.\nfunction isModelModule(value: unknown): boolean {\n const candidate = value as {\n reducer?: unknown;\n documentModel?: { global?: { id?: unknown } };\n } | null;\n return (\n typeof candidate?.reducer === \"function\" &&\n typeof candidate.documentModel?.global?.id === \"string\"\n );\n}\n\n// Drops sources that fail to import or export no model. For workflow pieces\n// only: a missing model means \"unavailable to pieces\", not a failed boot.\nexport async function keepImportableSources(\n sources: FileModelSource[],\n logger: ILogger,\n): Promise<FileModelSource[]> {\n const kept: FileModelSource[] = [];\n for (const source of sources) {\n try {\n const exports = (await import(\n pathToFileURL(source.filePath).href\n )) as Record<string, unknown>;\n if (Object.values(exports).some(isModelModule)) kept.push(source);\n } catch (error) {\n logger.warn(\n `Worker model sources: \"${source.filePath}\" does not import, so workflow pieces will not see its models: ${String(error)}`,\n );\n }\n }\n return kept;\n}\n\n/**\n * Resolves base models and configured package identifiers to `{ filePath }`\n * sources for the reactor builder. Resolution to absolute paths happens here\n * because workers (and the builder) resolve bare specifiers from the reactor\n * package's own dependency context, which cannot see switchboard or project\n * packages. Unresolvable identifiers are skipped with a warning; the builder\n * fails the boot if a registered model ends up without an importable source.\n */\nexport async function resolveWorkerModelSources(\n packages: string[],\n logger: ILogger,\n options: {\n /** Cached file for a package not installed locally, e.g. from a registry. */\n resolveRemote?: (identifier: string) => Promise<string | null>;\n } = {},\n): Promise<FileModelSource[]> {\n const sources: FileModelSource[] = [];\n for (const identifier of [...BASE_MODEL_SPECIFIERS, ...packages]) {\n const filePath =\n (await resolveModelModuleFile(identifier)) ??\n (await resolveRemoteSafely(identifier, options.resolveRemote, logger));\n if (!filePath) {\n logger.warn(\n `Worker model sources: no importable document-models entry for \"${identifier}\", skipping`,\n );\n continue;\n }\n sources.push({ filePath });\n }\n return sources;\n}\n\nasync function resolveRemoteSafely(\n identifier: string,\n resolveRemote: ((identifier: string) => Promise<string | null>) | undefined,\n logger: ILogger,\n): Promise<string | null> {\n if (!resolveRemote) return null;\n try {\n return await resolveRemote(identifier);\n } catch (error) {\n logger.warn(\n `Worker model sources: could not cache \"${identifier}\" from the registry: ${String(error)}`,\n );\n return null;\n }\n}\n\n/**\n * Absolute file path of a source's models barrel. Mirrors reactor-api's\n * import-resolver: import.meta.resolve, then the project's node_modules via\n * the package.json exports map / dist layout.\n */\nasync function resolveModelModuleFile(source: string): Promise<string | null> {\n if (isFsPath(source)) {\n return resolveFromPackageDir(source, \"./document-models\");\n }\n\n const specifier = BASE_MODEL_SPECIFIERS.includes(source)\n ? source\n : `${source}/document-models`;\n\n try {\n const resolved = import.meta.resolve(specifier);\n if (resolved.startsWith(\"file:\")) {\n return fileURLToPath(resolved);\n }\n } catch {\n // fall through to node_modules resolution from the project dir\n }\n\n const { packageName, subpath } = splitSpecifier(specifier);\n const packageDir = path.join(process.cwd(), \"node_modules\", packageName);\n if (!existsSync(packageDir)) {\n return null;\n }\n let realDir: string;\n try {\n realDir = realpathSync(packageDir);\n } catch {\n return null;\n }\n return resolveFromPackageDir(realDir, subpath);\n}\n\nfunction splitSpecifier(specifier: string): {\n packageName: string;\n subpath: string;\n} {\n const parts = specifier.split(\"/\");\n const packageSegments = specifier.startsWith(\"@\") ? 2 : 1;\n const packageName = parts.slice(0, packageSegments).join(\"/\");\n const rest = parts.slice(packageSegments).join(\"/\");\n return { packageName, subpath: rest ? `./${rest}` : \".\" };\n}\n\n/** Exports-map lookup (import condition), then conventional dist paths. */\nasync function resolveFromPackageDir(\n packageDir: string,\n subpath: string,\n): Promise<string | null> {\n const fromManifest = await resolveViaManifest(packageDir, subpath);\n if (fromManifest) {\n return fromManifest;\n }\n const candidates =\n subpath === \".\"\n ? [path.join(packageDir, \"dist\", \"index.js\")]\n : [\n path.join(packageDir, \"dist\", subpath.slice(2), \"index.js\"),\n path.join(packageDir, \"dist\", `${subpath.slice(2)}.js`),\n path.join(packageDir, subpath.slice(2), \"index.js\"),\n ];\n for (const candidate of candidates) {\n if (existsSync(candidate)) {\n return candidate;\n }\n }\n return null;\n}\n\nasync function resolveViaManifest(\n packageDir: string,\n subpath: string,\n): Promise<string | null> {\n let raw: string;\n try {\n raw = await readFile(path.join(packageDir, \"package.json\"), \"utf8\");\n } catch {\n return null;\n }\n let manifest: { exports?: unknown; main?: unknown };\n try {\n manifest = JSON.parse(raw) as { exports?: unknown; main?: unknown };\n } catch {\n return null;\n }\n\n let entry: unknown;\n const exportsField = manifest.exports;\n if (\n exportsField !== null &&\n typeof exportsField === \"object\" &&\n !Array.isArray(exportsField)\n ) {\n const map = exportsField as Record<string, unknown>;\n const hasSubpathKeys = Object.keys(map).some((key) => key.startsWith(\".\"));\n entry = hasSubpathKeys ? map[subpath] : subpath === \".\" ? map : undefined;\n } else if (typeof exportsField === \"string\" && subpath === \".\") {\n entry = exportsField;\n }\n\n let target = pickImportTarget(entry);\n if (!target && subpath === \".\" && typeof manifest.main === \"string\") {\n target = manifest.main;\n }\n if (!target) {\n return null;\n }\n const resolved = path.join(packageDir, target);\n return existsSync(resolved) ? resolved : null;\n}\n\nfunction pickImportTarget(entry: unknown): string | null {\n if (typeof entry === \"string\") {\n return entry;\n }\n if (typeof entry !== \"object\" || entry === null) {\n return null;\n }\n const conditions = entry as Record<string, unknown>;\n for (const condition of [\"import\", \"node\", \"default\"]) {\n const value = conditions[condition];\n if (typeof value === \"string\") {\n return value;\n }\n }\n return null;\n}\n\nfunction isFsPath(identifier: string): boolean {\n return (\n path.isAbsolute(identifier) ||\n identifier.startsWith(\"./\") ||\n identifier.startsWith(\"../\")\n );\n}\n\nexport function parseWorkerCount(\n raw: string | undefined,\n): WorkerCountInput | undefined {\n if (raw === undefined || raw.trim() === \"\") {\n return undefined;\n }\n if (raw.trim().toLowerCase() === \"auto\") {\n return \"auto\";\n }\n const value = Number.parseInt(raw, 10);\n if (!Number.isInteger(value) || value < 0 || String(value) !== raw.trim()) {\n throw new Error(\n `REACTOR_WORKERS must be \"auto\" or a non-negative integer, got \"${raw}\"`,\n );\n }\n return value;\n}\n"],"names":[],"mappings":";;;;;;;;;AAAA,SAAgB,oBACd,KACA,MACoB;CACpB,IAAI,QAAQ,KAAA,KAAa,IAAI,KAAK,MAAM,IACtC;CAEF,MAAM,QAAQ,OAAO,SAAS,KAAK,EAAE;CACrC,IAAI,CAAC,OAAO,UAAU,KAAK,KAAK,QAAQ,KAAK,OAAO,KAAK,MAAM,IAAI,KAAK,GACtE,MAAM,IAAI,MAAM,GAAG,KAAK,wCAAwC,IAAI,EAAE;CAExE,OAAO;AACT;;;;ACEA,SA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AAO,WAAW,QAAQ,IAAI,WAAW;AAC3C;AAEA,SAAS,iBAAiB,OAA+B;CACvD,IAAI,OAAO,UAAU,UACnB,OAAO;CAET,IAAI,OAAO,UAAU,YAAY,UAAU,MACzC,OAAO;CAET,MAAM,aAAa;CACnB,KAAK,MAAM,aAAa;EAAC;EAAU;EAAQ;CAAS,GAAG;EACrD,MAAM,QAAQ,WAAW;EACzB,IAAI,OAAO,UAAU,UACnB,OAAO;CAEX;CACA,OAAO;AACT;AAEA,SAAS,SAAS,YAA6B;CAC7C,OACE,KAAK,WAAW,UAAU,KAC1B,WAAW,WAAW,IAAI,KAC1B,WAAW,WAAW,KAAK;AAE/B;AAEA,SAAgB,iBACd,KAC8B;CAC9B,IAAI,QAAQ,KAAA,KAAa,IAAI,KAAK,MAAM,IACtC;CAEF,IAAI,IAAI,KAAK,CAAC,CAAC,YAAY,MAAM,QAC/B,OAAO;CAET,MAAM,QAAQ,OAAO,SAAS,KAAK,EAAE;CACrC,IAAI,CAAC,OAAO,UAAU,KAAK,KAAK,QAAQ,KAAK,OAAO,KAAK,MAAM,IAAI,KAAK,GACtE,MAAM,IAAI,MACR,kEAAkE,IAAI,EACxE;CAEF,OAAO;AACT","debug_id":"0abc3b7a-f473-50e3-9984-427c6dfd9263"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ILogger } from "document-model";
|
|
2
|
+
import { IReactorClient, InProcessReactorClientModule, ModelManifestEntry, ReactorBuilder } from "@powerhousedao/reactor";
|
|
3
|
+
import { SubgraphClass } from "@powerhousedao/reactor-api";
|
|
4
|
+
import "@powerhousedao/shared/document-model";
|
|
5
|
+
import * as WorkflowEngine from "@powerhousedao/reactor-workflow";
|
|
6
|
+
import "@powerhousedao/shared/processors";
|
|
7
|
+
//#region src/workflow-runtime.d.mts
|
|
8
|
+
/** Whether the operation intake is indexing. Same shape as the attachment
|
|
9
|
+
* reference projection, because it is the same limitation. */
|
|
10
|
+
type WorkflowTriggersCapability = {
|
|
11
|
+
status: "available";
|
|
12
|
+
} | {
|
|
13
|
+
status: "unavailable";
|
|
14
|
+
reason: "in-process-reactor-module-unavailable" | "live-read-model-registration-unsupported" | "workflow-singleton-lost";
|
|
15
|
+
};
|
|
16
|
+
type WorkflowRuntimeSecrets = WorkflowEngine.WorkflowRuntimeService["secrets"];
|
|
17
|
+
interface ComposedWorkflowRuntime {
|
|
18
|
+
subgraph: SubgraphClass;
|
|
19
|
+
/** Whether document operations reach the runtime at all; unavailable once
|
|
20
|
+
* the singleton is lost. */
|
|
21
|
+
readonly triggers: WorkflowTriggersCapability;
|
|
22
|
+
/** The owner name this host holds the workflow singleton under; undefined
|
|
23
|
+
* when the lease was not taken (a suite that opted out). */
|
|
24
|
+
singletonOwner?: string;
|
|
25
|
+
/** The runtime's secret store, for host secrets its own surface never lists. */
|
|
26
|
+
secrets: WorkflowRuntimeSecrets;
|
|
27
|
+
start(): Promise<void>;
|
|
28
|
+
stop(): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { WorkflowTriggersCapability as n, ComposedWorkflowRuntime as t };
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=workflow-runtime-CF5pc8mt.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow-runtime-CF5pc8mt.d.mts","names":[],"sources":["../src/workflow-runtime.mts"],"mappings":";;;;;;;;;KAsEY;EACN;;EAEA;EACA;;KAiQD,yBAAyB,eAAe;UAE5B;EACf,UAAU;;;WAGD,UAAU;;;EAGnB;;EAEA,SAAS;EACT,SAAS;EACT,QAAQ"}
|