@powerhousedao/switchboard 6.2.3-dev.54 → 6.2.3-dev.56
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/boot-inspection-enabled.test.d.ts +2 -0
- package/.tsbuild/test/boot-inspection-enabled.test.d.ts.map +1 -0
- package/.tsbuild/test/inspection-flag.test.d.ts +2 -0
- package/.tsbuild/test/inspection-flag.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/tsconfig.tsbuildinfo +1 -1
- package/CHANGELOG.md +65 -0
- package/README.md +13 -11
- package/dist/index.mjs +1 -1
- package/dist/{server-J9fpd42v.mjs → server-Cw2WnaCA.mjs} +145 -74
- package/dist/server-Cw2WnaCA.mjs.map +1 -0
- package/dist/server.d.mts +5 -0
- package/dist/server.d.mts.map +1 -1
- package/dist/server.mjs +3 -3
- package/package.json +15 -15
- package/test/attachments/index.test.ts +13 -1
- package/test/attachments/routes.test.ts +105 -1
- package/test/boot-inspection-enabled.test.ts +150 -0
- package/test/inspection-flag.test.ts +62 -0
- package/test/inspection-throttle.test.ts +23 -0
- package/test/workflow-runtime.test.ts +58 -3
- package/dist/server-J9fpd42v.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,68 @@
|
|
|
1
|
+
## 6.2.3-dev.56 (2026-10-14)
|
|
2
|
+
|
|
3
|
+
### 🚀 Features
|
|
4
|
+
|
|
5
|
+
- **desktop:** @powerhousedao/desktop — the desktop runner productized (P6.1-P6.5) ([58ce9a0d4a](https://github.com/powerhouse-inc/powerhouse/commit/58ce9a0d4a))
|
|
6
|
+
- **clint,ph-cli:** one static-serve implementation — connect-server deleted (P5.7) ([c35b0341c6](https://github.com/powerhouse-inc/powerhouse/commit/c35b0341c6))
|
|
7
|
+
- **clint:** mastra-runner — remote reactor attach + OpenAI-compatible agent API (P5.5, P5.6) ([532cb2128f](https://github.com/powerhouse-inc/powerhouse/commit/532cb2128f))
|
|
8
|
+
- **clint:** port the ph-clint framework — core, integrations, TUI, testing + full suite (P5.2, P5.3) ([d1ace0688e](https://github.com/powerhouse-inc/powerhouse/commit/d1ace0688e))
|
|
9
|
+
- **clint:** scaffold @powerhousedao/clint — the ph-clint port lands here (P5.1) ([c7a3435588](https://github.com/powerhouse-inc/powerhouse/commit/c7a3435588))
|
|
10
|
+
- **host-core,ph-cli:** structural multi-reactor — backends drive the routing client (P4.1-P4.3) ([e7c71ca7ac](https://github.com/powerhouse-inc/powerhouse/commit/e7c71ca7ac))
|
|
11
|
+
- **host-core:** shared zod host schemas; bridges adopt strict reactor/profile (P2.1, P2.2) ([1bd9db67be](https://github.com/powerhouse-inc/powerhouse/commit/1bd9db67be))
|
|
12
|
+
- **vetra:** lint project subgraphs for types core or the package's models own ([6855c0ed91](https://github.com/powerhouse-inc/powerhouse/commit/6855c0ed91))
|
|
13
|
+
- **host-core:** generic run records and pid-probe (P1.3, P1.5, P1.6 foundation) ([9a6affd46e](https://github.com/powerhouse-inc/powerhouse/commit/9a6affd46e))
|
|
14
|
+
- **host-core:** move drive projection primitives; add projectDrivesIntoConnect (P1.4) ([6cd1d8ee6e](https://github.com/powerhouse-inc/powerhouse/commit/6cd1d8ee6e))
|
|
15
|
+
- **host-core:** scaffold @powerhousedao/host-core (P1.1) ([c7d9b415b5](https://github.com/powerhouse-inc/powerhouse/commit/c7d9b415b5))
|
|
16
|
+
- **reactor-api:** report background failures through a reportError option ([724796bcc1](https://github.com/powerhouse-inc/powerhouse/commit/724796bcc1))
|
|
17
|
+
- **switchboard:** configure the inspection throttle from PH_INSPECTION_* env ([4eefc0b8aa](https://github.com/powerhouse-inc/powerhouse/commit/4eefc0b8aa))
|
|
18
|
+
- **switchboard:** let INSPECTION_ENABLED=false keep /graphql/inspection unmounted ([aefe93b1e1](https://github.com/powerhouse-inc/powerhouse/commit/aefe93b1e1))
|
|
19
|
+
- **ph-cli:** uniform-runners flag helper and host.js loader (P0.1, P0.2, P0.12) ([4c04163009](https://github.com/powerhouse-inc/powerhouse/commit/4c04163009))
|
|
20
|
+
- ⚠️ **reactor-workflow:** lease warm piece children per request from one pool sized around the reactor's threads ([9ff3834198](https://github.com/powerhouse-inc/powerhouse/commit/9ff3834198))
|
|
21
|
+
|
|
22
|
+
### 🩹 Fixes
|
|
23
|
+
|
|
24
|
+
- **ci:** read duration-watch timings from check runs and warn on API errors ([239683c51d](https://github.com/powerhouse-inc/powerhouse/commit/239683c51d))
|
|
25
|
+
- **switchboard:** new attachment tests use the granted-download helper ([0206932b66](https://github.com/powerhouse-inc/powerhouse/commit/0206932b66))
|
|
26
|
+
- **switchboard:** answer 404 for an attachment whose blob is missing, instead of crashing ([#3110](https://github.com/powerhouse-inc/powerhouse/pull/3110))
|
|
27
|
+
- **tsconfig:** dedup host-core from root references now that ph-cli references it (P1.2) ([988cbc574c](https://github.com/powerhouse-inc/powerhouse/commit/988cbc574c))
|
|
28
|
+
- **switchboard:** report the remaining logged-only background failures ([f20ff3eb16](https://github.com/powerhouse-inc/powerhouse/commit/f20ff3eb16))
|
|
29
|
+
- **switchboard:** fail boot on an invalid PH_INSPECTION_CALLS_PER_MINUTE ([4326aa0c1e](https://github.com/powerhouse-inc/powerhouse/commit/4326aa0c1e))
|
|
30
|
+
- **reactor-workflow:** journal a fire as it queues, re-read a workflow changed during a wait, and sweep up orphaned PENDING runs ([37e9c7917b](https://github.com/powerhouse-inc/powerhouse/commit/37e9c7917b))
|
|
31
|
+
|
|
32
|
+
### ⚠️ Breaking Changes
|
|
33
|
+
|
|
34
|
+
- **reactor-workflow:** lease warm piece children per request from one pool sized around the reactor's threads ([9ff3834198](https://github.com/powerhouse-inc/powerhouse/commit/9ff3834198))
|
|
35
|
+
|
|
36
|
+
### ❤️ Thank You
|
|
37
|
+
|
|
38
|
+
- acaldas
|
|
39
|
+
- Benjamin Jordan
|
|
40
|
+
- Claude Fable 5
|
|
41
|
+
- Claude Opus 5.5
|
|
42
|
+
- Frank @froid1911
|
|
43
|
+
- Wouter Kampmann
|
|
44
|
+
|
|
45
|
+
## 6.2.3-dev.55 (2026-10-13)
|
|
46
|
+
|
|
47
|
+
### 🚀 Features
|
|
48
|
+
|
|
49
|
+
- **reactor-monitor:** build remote inspection queries from the wire fields ([d16699f94e](https://github.com/powerhouse-inc/powerhouse/commit/d16699f94e))
|
|
50
|
+
|
|
51
|
+
### 🩹 Fixes
|
|
52
|
+
|
|
53
|
+
- **switchboard:** release the lease and retry when the late runtime fails to start ([ef83820e0f](https://github.com/powerhouse-inc/powerhouse/commit/ef83820e0f))
|
|
54
|
+
- **switchboard:** log a failed start of the late workflow runtime ([82e9b88f48](https://github.com/powerhouse-inc/powerhouse/commit/82e9b88f48))
|
|
55
|
+
- **switchboard:** mount the late workflow subgraph without the debounce ([ed64d75da4](https://github.com/powerhouse-inc/powerhouse/commit/ed64d75da4))
|
|
56
|
+
- **switchboard:** register the reactor-drive listing subgraph as reactor-drive-nodes ([8beff0a01f](https://github.com/powerhouse-inc/powerhouse/commit/8beff0a01f))
|
|
57
|
+
- **reactor-workflow:** upload a step's output as a file-backed Blob ([8c943bfbeb](https://github.com/powerhouse-inc/powerhouse/commit/8c943bfbeb))
|
|
58
|
+
- **reactor-attachments:** hash and upload attachments without reading the whole file into memory ([f6532d6449](https://github.com/powerhouse-inc/powerhouse/commit/f6532d6449))
|
|
59
|
+
|
|
60
|
+
### ❤️ Thank You
|
|
61
|
+
|
|
62
|
+
- acaldas
|
|
63
|
+
- Benjamin Jordan
|
|
64
|
+
- Claude Opus 5.5
|
|
65
|
+
|
|
1
66
|
## 6.2.3-dev.54 (2026-10-12)
|
|
2
67
|
|
|
3
68
|
This was a version bump only for @powerhousedao/switchboard to align it with other projects, there were no code changes.
|
package/README.md
CHANGED
|
@@ -100,17 +100,19 @@ pnpm add -g @powerhousedao/switchboard
|
|
|
100
100
|
|
|
101
101
|
### Environment Variables
|
|
102
102
|
|
|
103
|
-
| Variable
|
|
104
|
-
|
|
|
105
|
-
| `PORT`
|
|
106
|
-
| `DATABASE_URL`
|
|
107
|
-
| `PH_REACTOR_DATABASE_URL`
|
|
108
|
-
| `REACTOR_DB_POOL_SIZE_HOST`
|
|
109
|
-
| `REDIS_URL`
|
|
110
|
-
| `REDIS_TLS_URL`
|
|
111
|
-
| `PYROSCOPE_SERVER_ADDRESS`
|
|
112
|
-
| `FEATURE_REACTORV2_ENABLED`
|
|
113
|
-
| `MCP_ENABLED`
|
|
103
|
+
| Variable | Description | Default |
|
|
104
|
+
| -------------------------------- | ------------------------------------------------------------------------------ | --------------------- |
|
|
105
|
+
| `PORT` | Server port | `4001` |
|
|
106
|
+
| `DATABASE_URL` | Database connection string | `./.ph/drive-storage` |
|
|
107
|
+
| `PH_REACTOR_DATABASE_URL` | PostgreSQL URL (takes precedence) | - |
|
|
108
|
+
| `REACTOR_DB_POOL_SIZE_HOST` | Reactor host Postgres pool size | `16` |
|
|
109
|
+
| `REDIS_URL` | Redis connection URL | - |
|
|
110
|
+
| `REDIS_TLS_URL` | Redis TLS connection URL | - |
|
|
111
|
+
| `PYROSCOPE_SERVER_ADDRESS` | Pyroscope server address | - |
|
|
112
|
+
| `FEATURE_REACTORV2_ENABLED` | Enable Reactor v2 subgraph feature | `false` |
|
|
113
|
+
| `MCP_ENABLED` | `false` keeps `/mcp` unmounted | `true` |
|
|
114
|
+
| `INSPECTION_ENABLED` | `false` keeps inspection unmounted | `true` |
|
|
115
|
+
| `PH_INSPECTION_CALLS_PER_MINUTE` | `validateDocument`/`driveIntegrity` calls per caller per minute; admins exempt | `6` |
|
|
114
116
|
|
|
115
117
|
See [Observability](#observability) below for Sentry and OpenTelemetry variables.
|
|
116
118
|
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
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]="c9eef974-47b1-5e45-aad6-5ebb1885b76a")}catch(e){}}();
|
|
4
|
-
import { a as StoredDocumentsRefusedError, c as initProfilerFromEnv, i as startSwitchboard, l as parseForcePgVersion } from "./server-
|
|
4
|
+
import { a as StoredDocumentsRefusedError, c as initProfilerFromEnv, i as startSwitchboard, l as parseForcePgVersion } from "./server-Cw2WnaCA.mjs";
|
|
5
5
|
import { metrics } from "@opentelemetry/api";
|
|
6
6
|
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
|
|
7
7
|
import { ExpressInstrumentation } from "@opentelemetry/instrumentation-express";
|
|
@@ -1,22 +1,22 @@
|
|
|
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]="
|
|
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]="99cead54-dc11-5711-a454-9efc98498890")}catch(e){}}();
|
|
3
3
|
import { n as addDefaultReactorDrive, r as isPostgresUrl, t as addDefaultDrive } from "./utils-uaBlzyjS.mjs";
|
|
4
4
|
import { createRequire, register } from "node:module";
|
|
5
5
|
import { metrics, trace } from "@opentelemetry/api";
|
|
6
6
|
import { ReactorInstrumentation } from "@powerhousedao/opentelemetry-instrumentation-reactor";
|
|
7
7
|
import * as Sentry from "@sentry/node";
|
|
8
|
-
import { childLogger,
|
|
8
|
+
import { childLogger, setLogLevel } from "document-model";
|
|
9
9
|
import dotenv from "dotenv";
|
|
10
10
|
import { getConfig } from "@powerhousedao/config/node";
|
|
11
11
|
import { existsSync, promises, realpathSync } from "node:fs";
|
|
12
12
|
import path, { resolve } from "node:path";
|
|
13
13
|
import { createDurableNodeFs, preparePgliteDataDir, removeStalePgliteFiles, resolvePgliteFsync, syncTree } from "@powerhousedao/reactor-api/pglite-node";
|
|
14
14
|
import { ChannelScheme, DriveCollectionId, EventBus, HardenedPGliteDialect, IN_MEMORY_PGLITE_STORAGE_FACTS, PGLITE_PATH_STORAGE_FACTS, POSTGRES_STORAGE_FACTS, REACTOR_SCHEMA, ReactorBuilder, ReactorClientBuilder, UnsupportedStoredProtocolError, createHybridProjectionCoordinatorFactory, instrumentPgPool, parseDriveUrl, supportsLiveReadModelRegistration } from "@powerhousedao/reactor";
|
|
15
|
-
import { AuthorizationPolicy, BaseSubgraph, ForbiddenError, HttpPackageLoader, ImportPackageLoader, PGLITE_UTC_PARSERS, PackageManagementService, PackagesSubgraph, PrivacyPermissionAdapter, callerSubject, createCanonicalDocumentIdResolver, getUniqueDocumentModels, initializeAndStartAPI, resolveRenownConfig } from "@powerhousedao/reactor-api";
|
|
15
|
+
import { AuthorizationPolicy, BaseSubgraph, ForbiddenError, HttpPackageLoader, ImportPackageLoader, PGLITE_UTC_PARSERS, PackageManagementService, PackagesSubgraph, PrivacyPermissionAdapter, baseDocumentModels, callerSubject, createCanonicalDocumentIdResolver, getUniqueDocumentModels, initializeAndStartAPI, reportFailure, resolveRenownConfig, runDetached } from "@powerhousedao/reactor-api";
|
|
16
16
|
import { httpsHooksPath } from "@powerhousedao/reactor-api/https-hooks";
|
|
17
17
|
import { AttachmentAlreadyExists, AttachmentNotFound, AttachmentPending, AttachmentReferenceReadModel, AttachmentSchemaCompiler, HashMismatch, InvalidAttachmentMetadata, InvalidAttachmentRef, ReservationNotFound, SizeMismatch, UploadTooLarge, createRef, createRemoteAttachmentService, parseAttachmentDownloadTarget, parseRef, validateReserveMetadata } from "@powerhousedao/reactor-attachments";
|
|
18
18
|
import { createAttachmentClient } from "@powerhousedao/reactor-attachments/client";
|
|
19
|
-
import { DriveNodeView, NodeProcessor, ReactorDriveClient, createReactorDriveResolvers,
|
|
19
|
+
import { DriveNodeView, NodeProcessor, REACTOR_DRIVE_SUBGRAPH_NAME, ReactorDriveClient, createReactorDriveResolvers, reactorDriveSubgraphTypeDefs } from "@powerhousedao/reactor-drive";
|
|
20
20
|
import { DEFAULT_KEYPAIR_PATH, DEFAULT_RENOWN_URL, NodeKeyStorage, RENOWN_READ_MODEL_SUBGRAPH, RenownBuilder, RenownCryptoBuilder, createLocalCredentialVerifier, createRenownTrustPolicy, resolveSwitchboardEndpoint } from "@renown/sdk/node";
|
|
21
21
|
import { Kysely, PostgresDialect } from "kysely";
|
|
22
22
|
import net from "node:net";
|
|
@@ -25,8 +25,6 @@ import { Pool } from "pg";
|
|
|
25
25
|
import { Readable } from "node:stream";
|
|
26
26
|
import { createHmac, randomBytes, timingSafeEqual } from "node:crypto";
|
|
27
27
|
import { DisclosureService, MIN_DEPLOYMENT_SECRET_BYTES, createModuleErasure, createPrivacySubgraph, registerSubjectDocumentsReadModel } from "@powerhousedao/reactor-privacy";
|
|
28
|
-
import { ReactorGroupV1 } from "@powerhousedao/reactor-group";
|
|
29
|
-
import { driveDocumentModelModule } from "@powerhousedao/shared/document-drive";
|
|
30
28
|
import { DEFAULT_SIGNATURE_POLICY, isSignaturePolicy } from "@powerhousedao/shared/document-model";
|
|
31
29
|
import { readFile } from "node:fs/promises";
|
|
32
30
|
import os from "node:os";
|
|
@@ -194,10 +192,11 @@ function requireAuth(authService, handler, options) {
|
|
|
194
192
|
* mounted through here inherits it without each one remembering to.
|
|
195
193
|
*/
|
|
196
194
|
function mountAuthenticatedNodeRoute(api, method, path, handler, options) {
|
|
195
|
+
const { rawBody, ...authOptions } = options ?? {};
|
|
197
196
|
api.httpAdapter.mountNodeRoute(method, path, requireAuth(api.authService, handler, {
|
|
198
|
-
...
|
|
197
|
+
...authOptions,
|
|
199
198
|
requireAuthenticatedCaller: api.requireAuthenticatedCaller
|
|
200
|
-
}));
|
|
199
|
+
}), { rawBody: rawBody ?? false });
|
|
201
200
|
}
|
|
202
201
|
//#endregion
|
|
203
202
|
//#region src/attachments/routes.ts
|
|
@@ -395,9 +394,28 @@ function makeDownloadHandler(attachments, attachmentAccess, urlSigner) {
|
|
|
395
394
|
res.setHeader("Content-Length", String(header.sizeBytes));
|
|
396
395
|
res.setHeader("Content-Disposition", buildContentDisposition(header.fileName));
|
|
397
396
|
res.setHeader("Attachment-Metadata", buildMetadataHeader(header));
|
|
398
|
-
Readable.fromWeb(body)
|
|
397
|
+
const source = Readable.fromWeb(body);
|
|
398
|
+
source.once("error", (err) => handleDownloadStreamError(res, hash, err));
|
|
399
|
+
source.pipe(res);
|
|
399
400
|
};
|
|
400
401
|
}
|
|
402
|
+
function handleDownloadStreamError(res, hash, err) {
|
|
403
|
+
if (res.headersSent) {
|
|
404
|
+
logger$2.error("Attachment stream failed mid-download: @error", err);
|
|
405
|
+
res.destroy();
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
res.removeHeader("Content-Length");
|
|
409
|
+
res.removeHeader("Content-Disposition");
|
|
410
|
+
res.removeHeader("Attachment-Metadata");
|
|
411
|
+
if (err?.code === "ENOENT") {
|
|
412
|
+
logger$2.warn("Attachment @hash is recorded as available but its blob is missing", hash);
|
|
413
|
+
sendJson(res, 404, ATTACHMENT_NOT_FOUND_BODY);
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
logger$2.error("Attachment stream failed before sending: @error", err);
|
|
417
|
+
sendError(res, 500, "Internal error");
|
|
418
|
+
}
|
|
401
419
|
function toAsciiJson(value) {
|
|
402
420
|
return JSON.stringify(value).replace(/[\u007f-\uffff]/g, (char) => `\\u${char.charCodeAt(0).toString(16).padStart(4, "0")}`);
|
|
403
421
|
}
|
|
@@ -789,7 +807,7 @@ function registerAttachmentRoutes(api, options = {}) {
|
|
|
789
807
|
mountAuthenticatedNodeRoute(api, "POST", "/attachments/reservations", makeReserveHandler(attachments));
|
|
790
808
|
mountAuthenticatedNodeRoute(api, "GET", "/attachments/reservations/:reservationId", makeGetReservationHandler(attachments));
|
|
791
809
|
mountAuthenticatedNodeRoute(api, "DELETE", "/attachments/reservations/:reservationId", makeDeleteReservationHandler(attachments));
|
|
792
|
-
mountAuthenticatedNodeRoute(api, "PUT", "/attachments/reservations/:reservationId", makeUploadHandler(attachments));
|
|
810
|
+
mountAuthenticatedNodeRoute(api, "PUT", "/attachments/reservations/:reservationId", makeUploadHandler(attachments), { rawBody: true });
|
|
793
811
|
mountAuthenticatedNodeRoute(api, "HEAD", "/attachments/:hash", makeStatHandler(attachments, attachmentAccess, urlSigner), { allowAnonymous: true });
|
|
794
812
|
mountAuthenticatedNodeRoute(api, "GET", "/attachments/:hash/download-target", makeDownloadTargetHandler(attachments, attachmentAccess, urlSigner), { allowAnonymous: true });
|
|
795
813
|
mountAuthenticatedNodeRoute(api, "GET", "/attachments/:hash", makeDownloadHandler(attachments, attachmentAccess, urlSigner), { allowAnonymous: true });
|
|
@@ -992,12 +1010,7 @@ async function startPrivacy(deps) {
|
|
|
992
1010
|
*/
|
|
993
1011
|
/** The models switchboard always registers alongside package models. */
|
|
994
1012
|
function switchboardBaseDocumentModels() {
|
|
995
|
-
return [
|
|
996
|
-
documentModelDocumentModelModule,
|
|
997
|
-
driveDocumentModelModule,
|
|
998
|
-
reactorDriveDocumentModelModule,
|
|
999
|
-
ReactorGroupV1
|
|
1000
|
-
];
|
|
1013
|
+
return baseDocumentModels.map(([, model]) => model);
|
|
1001
1014
|
}
|
|
1002
1015
|
function applySwitchboardReactorDefaults(reactorBuilder, clientBuilder, options = {}) {
|
|
1003
1016
|
const baseModels = options.includeBaseModels !== false ? switchboardBaseDocumentModels() : [];
|
|
@@ -1022,6 +1035,51 @@ function applySwitchboardReactorDefaults(reactorBuilder, clientBuilder, options
|
|
|
1022
1035
|
if (trust?.trustPolicy) reactorBuilder.withTrustPolicy(trust.trustPolicy, trust.workerTrustPolicy);
|
|
1023
1036
|
}
|
|
1024
1037
|
//#endregion
|
|
1038
|
+
//#region src/env.mts
|
|
1039
|
+
function parseNonNegativeInt(raw, name) {
|
|
1040
|
+
if (raw === void 0 || raw.trim() === "") return;
|
|
1041
|
+
const value = Number.parseInt(raw, 10);
|
|
1042
|
+
if (!Number.isInteger(value) || value < 0 || String(value) !== raw.trim()) throw new Error(`${name} must be a non-negative integer, got "${raw}"`);
|
|
1043
|
+
return value;
|
|
1044
|
+
}
|
|
1045
|
+
//#endregion
|
|
1046
|
+
//#region src/projection-worker.mts
|
|
1047
|
+
const DEFAULT_DB_POOL_SIZE_PROJECTION = 8;
|
|
1048
|
+
const ON_TOKENS = [
|
|
1049
|
+
"1",
|
|
1050
|
+
"true",
|
|
1051
|
+
"on",
|
|
1052
|
+
"yes"
|
|
1053
|
+
];
|
|
1054
|
+
const OFF_TOKENS = [
|
|
1055
|
+
"0",
|
|
1056
|
+
"false",
|
|
1057
|
+
"off",
|
|
1058
|
+
"no"
|
|
1059
|
+
];
|
|
1060
|
+
/**
|
|
1061
|
+
* Enabled by REACTOR_PROJECTION_WORKER (1/true/on/yes, case-insensitive) or
|
|
1062
|
+
* `input.enabled`, which wins when defined; null when off (the default).
|
|
1063
|
+
*/
|
|
1064
|
+
function resolveProjectionWorkerOptions(input, env) {
|
|
1065
|
+
if (!(input?.enabled ?? parseOnOff(env.REACTOR_PROJECTION_WORKER) ?? false)) return null;
|
|
1066
|
+
const dbPoolSize = input?.dbPoolSize ?? parseNonNegativeInt(env.REACTOR_DB_POOL_SIZE_PROJECTION, "REACTOR_DB_POOL_SIZE_PROJECTION") ?? DEFAULT_DB_POOL_SIZE_PROJECTION;
|
|
1067
|
+
if (dbPoolSize < 1) throw new Error("REACTOR_DB_POOL_SIZE_PROJECTION must be at least 1; the projection worker cannot run without a pool");
|
|
1068
|
+
return { dbPoolSize };
|
|
1069
|
+
}
|
|
1070
|
+
/** Same preconditions as the executor worker pool; message shape mirrors server.mts. */
|
|
1071
|
+
function assertProjectionWorkerSupported(args) {
|
|
1072
|
+
if (args.dev) throw new Error("The projection worker (REACTOR_PROJECTION_WORKER) is not supported in dev mode: Vite-loaded document models cannot cross a worker-thread boundary");
|
|
1073
|
+
if (!args.reactorDbUrl || !isPostgresUrl(args.reactorDbUrl)) throw new Error("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.");
|
|
1074
|
+
}
|
|
1075
|
+
function parseOnOff(raw) {
|
|
1076
|
+
if (raw === void 0 || raw.trim() === "") return;
|
|
1077
|
+
const token = raw.trim().toLowerCase();
|
|
1078
|
+
if (ON_TOKENS.includes(token)) return true;
|
|
1079
|
+
if (OFF_TOKENS.includes(token)) return false;
|
|
1080
|
+
throw new Error(`REACTOR_PROJECTION_WORKER must be one of 1, true, on, yes, 0, false, off, no, got "${raw}"`);
|
|
1081
|
+
}
|
|
1082
|
+
//#endregion
|
|
1025
1083
|
//#region src/worker-pool.mts
|
|
1026
1084
|
const DEFAULT_DB_POOL_SIZE_PER_WORKER = 2;
|
|
1027
1085
|
const DEFAULT_ACQUIRE_TIMEOUT_MS = 5e3;
|
|
@@ -1239,48 +1297,15 @@ function parseWorkerCount(raw) {
|
|
|
1239
1297
|
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}"`);
|
|
1240
1298
|
return value;
|
|
1241
1299
|
}
|
|
1242
|
-
function parseNonNegativeInt(raw, name) {
|
|
1243
|
-
if (raw === void 0 || raw.trim() === "") return;
|
|
1244
|
-
const value = Number.parseInt(raw, 10);
|
|
1245
|
-
if (!Number.isInteger(value) || value < 0 || String(value) !== raw.trim()) throw new Error(`${name} must be a non-negative integer, got "${raw}"`);
|
|
1246
|
-
return value;
|
|
1247
|
-
}
|
|
1248
1300
|
//#endregion
|
|
1249
|
-
//#region src/
|
|
1250
|
-
const
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
"
|
|
1256
|
-
|
|
1257
|
-
const OFF_TOKENS = [
|
|
1258
|
-
"0",
|
|
1259
|
-
"false",
|
|
1260
|
-
"off",
|
|
1261
|
-
"no"
|
|
1262
|
-
];
|
|
1263
|
-
/**
|
|
1264
|
-
* Enabled by REACTOR_PROJECTION_WORKER (1/true/on/yes, case-insensitive) or
|
|
1265
|
-
* `input.enabled`, which wins when defined; null when off (the default).
|
|
1266
|
-
*/
|
|
1267
|
-
function resolveProjectionWorkerOptions(input, env) {
|
|
1268
|
-
if (!(input?.enabled ?? parseOnOff(env.REACTOR_PROJECTION_WORKER) ?? false)) return null;
|
|
1269
|
-
const dbPoolSize = input?.dbPoolSize ?? parseNonNegativeInt(env.REACTOR_DB_POOL_SIZE_PROJECTION, "REACTOR_DB_POOL_SIZE_PROJECTION") ?? DEFAULT_DB_POOL_SIZE_PROJECTION;
|
|
1270
|
-
if (dbPoolSize < 1) throw new Error("REACTOR_DB_POOL_SIZE_PROJECTION must be at least 1; the projection worker cannot run without a pool");
|
|
1271
|
-
return { dbPoolSize };
|
|
1272
|
-
}
|
|
1273
|
-
/** Same preconditions as the executor worker pool; message shape mirrors server.mts. */
|
|
1274
|
-
function assertProjectionWorkerSupported(args) {
|
|
1275
|
-
if (args.dev) throw new Error("The projection worker (REACTOR_PROJECTION_WORKER) is not supported in dev mode: Vite-loaded document models cannot cross a worker-thread boundary");
|
|
1276
|
-
if (!args.reactorDbUrl || !isPostgresUrl(args.reactorDbUrl)) throw new Error("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.");
|
|
1277
|
-
}
|
|
1278
|
-
function parseOnOff(raw) {
|
|
1279
|
-
if (raw === void 0 || raw.trim() === "") return;
|
|
1280
|
-
const token = raw.trim().toLowerCase();
|
|
1281
|
-
if (ON_TOKENS.includes(token)) return true;
|
|
1282
|
-
if (OFF_TOKENS.includes(token)) return false;
|
|
1283
|
-
throw new Error(`REACTOR_PROJECTION_WORKER must be one of 1, true, on, yes, 0, false, off, no, got "${raw}"`);
|
|
1301
|
+
//#region src/inspection-throttle.mts
|
|
1302
|
+
const NAME = "PH_INSPECTION_CALLS_PER_MINUTE";
|
|
1303
|
+
/** Unset keeps reactor-api's default; an invalid value fails boot. */
|
|
1304
|
+
function inspectionThrottleFromEnv(env) {
|
|
1305
|
+
const callsPerMinute = parseNonNegativeInt(env[NAME], NAME);
|
|
1306
|
+
if (callsPerMinute === void 0) return {};
|
|
1307
|
+
if (callsPerMinute < 1) throw new Error(`${NAME} must be at least 1, got "${env[NAME]}"`);
|
|
1308
|
+
return { callsPerMinute };
|
|
1284
1309
|
}
|
|
1285
1310
|
//#endregion
|
|
1286
1311
|
//#region src/feature-flags.ts
|
|
@@ -1290,6 +1315,17 @@ async function initFeatureFlags() {
|
|
|
1290
1315
|
return OpenFeature.getClient();
|
|
1291
1316
|
}
|
|
1292
1317
|
//#endregion
|
|
1318
|
+
//#region src/inspection-flag.mts
|
|
1319
|
+
/** The env var and OpenFeature flag key that can keep the inspection subgraph unmounted. */
|
|
1320
|
+
const INSPECTION_ENABLED = "INSPECTION_ENABLED";
|
|
1321
|
+
/** Whether to mount `/graphql/inspection`. A host's `inspection: false` wins;
|
|
1322
|
+
* otherwise INSPECTION_ENABLED decides, falling back to the host's option and
|
|
1323
|
+
* then INSPECTION_ENABLED_DEFAULT. */
|
|
1324
|
+
async function resolveInspectionEnabled({ featureFlags, option }) {
|
|
1325
|
+
if (option === false) return false;
|
|
1326
|
+
return featureFlags.getBooleanValue(INSPECTION_ENABLED, option ?? true);
|
|
1327
|
+
}
|
|
1328
|
+
//#endregion
|
|
1293
1329
|
//#region src/mcp-flag.mts
|
|
1294
1330
|
/** The env var and OpenFeature flag key that can keep the MCP server unmounted. */
|
|
1295
1331
|
const MCP_ENABLED = "MCP_ENABLED";
|
|
@@ -2217,7 +2253,12 @@ function retryWorkflowSingleton(options) {
|
|
|
2217
2253
|
return;
|
|
2218
2254
|
}
|
|
2219
2255
|
options.logger.info("Claimed the workflow singleton after boot; starting the workflow runtime");
|
|
2220
|
-
|
|
2256
|
+
try {
|
|
2257
|
+
await options.onComposed(workflows);
|
|
2258
|
+
} catch (error) {
|
|
2259
|
+
options.logger.error("Starting the workflow runtime after the singleton came free failed: @error", error);
|
|
2260
|
+
schedule();
|
|
2261
|
+
}
|
|
2221
2262
|
};
|
|
2222
2263
|
const schedule = () => {
|
|
2223
2264
|
if (stopped) return;
|
|
@@ -2451,6 +2492,7 @@ async function composeClaimed(engine, deps, lease, loss) {
|
|
|
2451
2492
|
attachments: deps.attachments,
|
|
2452
2493
|
canReadAttachmentRef: attachmentReadPolicy(deps.attachmentAccess),
|
|
2453
2494
|
logger: deps.logger,
|
|
2495
|
+
...deps.reactorThreads ? { reactorThreads: deps.reactorThreads } : {},
|
|
2454
2496
|
...deps.telemetry ? { telemetry: deps.telemetry } : {}
|
|
2455
2497
|
});
|
|
2456
2498
|
const routes = {};
|
|
@@ -3016,6 +3058,7 @@ async function initServer(serverPort, options, renown, renownConfig) {
|
|
|
3016
3058
|
}
|
|
3017
3059
|
const reactorPgliteMajor = reactorPgliteDir ? resolvePgliteMajorForDir(reactorPgliteDir) : null;
|
|
3018
3060
|
const readModelPgliteMajor = readModelPgliteDir ? resolvePgliteMajorForDir(readModelPgliteDir) : null;
|
|
3061
|
+
const inspectionThrottle = inspectionThrottleFromEnv(process.env);
|
|
3019
3062
|
let workerPool = resolveWorkerPoolOptions(options.workerPool, process.env);
|
|
3020
3063
|
if (workerPool && options.reactor) {
|
|
3021
3064
|
logger.warn("Worker pool configuration ignored: the caller-provided reactor owns its own executor");
|
|
@@ -3221,12 +3264,22 @@ async function initServer(serverPort, options, renown, renownConfig) {
|
|
|
3221
3264
|
const verifyCredential = renownConfig.source === "self" ? (params) => localCredentialCheck ? localCredentialCheck(params) : Promise.reject(/* @__PURE__ */ new Error("The local renown read model is not bound yet")) : void 0;
|
|
3222
3265
|
let defaultDriveUrl = void 0;
|
|
3223
3266
|
const basePath = process.cwd();
|
|
3267
|
+
const reportError = (error) => {
|
|
3268
|
+
Sentry.captureException(error);
|
|
3269
|
+
};
|
|
3270
|
+
const reporting = {
|
|
3271
|
+
logger,
|
|
3272
|
+
report: reportError
|
|
3273
|
+
};
|
|
3224
3274
|
let vite;
|
|
3225
3275
|
let viteLoader;
|
|
3226
3276
|
if (dev) {
|
|
3227
3277
|
const { VitePackageLoader, createViteLogger, startViteServer } = await import("@powerhousedao/reactor-api/vite");
|
|
3228
3278
|
vite = await startViteServer(process.cwd(), createViteLogger(logger));
|
|
3229
|
-
viteLoader = VitePackageLoader.build(vite, {
|
|
3279
|
+
viteLoader = VitePackageLoader.build(vite, {
|
|
3280
|
+
resolveFrom: [import.meta.url],
|
|
3281
|
+
reportError
|
|
3282
|
+
});
|
|
3230
3283
|
}
|
|
3231
3284
|
const vetraProcessorFactory = dev ? (await import("@powerhousedao/vetra/processors")).processorFactory : void 0;
|
|
3232
3285
|
if (!options.disableLocalPackages) packages.push(basePath);
|
|
@@ -3261,7 +3314,9 @@ async function initServer(serverPort, options, renown, renownConfig) {
|
|
|
3261
3314
|
processors: vetraProcessorFactory ? { "@powerhousedao/vetra": [vetraProcessorFactory] } : {},
|
|
3262
3315
|
configFile: configPath,
|
|
3263
3316
|
mcp: options.mcp ?? true,
|
|
3317
|
+
inspection: options.inspection === false ? false : { throttle: inspectionThrottle },
|
|
3264
3318
|
logger: apiLogger,
|
|
3319
|
+
reportError,
|
|
3265
3320
|
enableDocumentModelSubgraphs: options.enableDocumentModelSubgraphs,
|
|
3266
3321
|
renown: renownConfig,
|
|
3267
3322
|
verifyCredential
|
|
@@ -3298,6 +3353,7 @@ async function initServer(serverPort, options, renown, renownConfig) {
|
|
|
3298
3353
|
pieces: api.packageManager,
|
|
3299
3354
|
pieceRegistryUrl: registryUrl,
|
|
3300
3355
|
models: workerModels,
|
|
3356
|
+
reactorThreads: (workerPool?.numWorkers ?? 0) + (projectionWorker ? 1 : 0),
|
|
3301
3357
|
logger: logger.child(["workflow-runtime"]),
|
|
3302
3358
|
exclusiveJournal: readModelPgliteDir !== null,
|
|
3303
3359
|
onSingletonLost: workflowSingletonLossHandler(logger),
|
|
@@ -3320,7 +3376,7 @@ async function initServer(serverPort, options, renown, renownConfig) {
|
|
|
3320
3376
|
attachments: api.attachmentClientProvider
|
|
3321
3377
|
});
|
|
3322
3378
|
return graphqlManager.registerSubgraphInstance(workflowSubgraph, "graphql", false).catch((error) => {
|
|
3323
|
-
|
|
3379
|
+
reportFailure(reporting, error, "Failed to register workflow-runtime subgraph: @error");
|
|
3324
3380
|
});
|
|
3325
3381
|
};
|
|
3326
3382
|
if (workflowsEnabled) try {
|
|
@@ -3331,15 +3387,24 @@ async function initServer(serverPort, options, renown, renownConfig) {
|
|
|
3331
3387
|
workflowsRetry = retryWorkflowSingleton({
|
|
3332
3388
|
compose: composeWorkflows,
|
|
3333
3389
|
onComposed: async (composed) => {
|
|
3390
|
+
try {
|
|
3391
|
+
await composed.start();
|
|
3392
|
+
} catch (error) {
|
|
3393
|
+
try {
|
|
3394
|
+
await composed.stop();
|
|
3395
|
+
} catch (stopError) {
|
|
3396
|
+
logger.error("Stopping the late workflow runtime failed: @error", stopError);
|
|
3397
|
+
}
|
|
3398
|
+
throw error;
|
|
3399
|
+
}
|
|
3400
|
+
logger.info("Workflow runtime started");
|
|
3334
3401
|
workflows = composed;
|
|
3335
3402
|
await registerWorkflowSubgraph(composed);
|
|
3336
3403
|
try {
|
|
3337
|
-
await graphqlManager.updateRouter();
|
|
3404
|
+
await graphqlManager.updateRouter(true);
|
|
3338
3405
|
} catch (error) {
|
|
3339
|
-
|
|
3406
|
+
reportFailure(reporting, error, "Mounting the late workflow-runtime subgraph failed: @error");
|
|
3340
3407
|
}
|
|
3341
|
-
await composed.start();
|
|
3342
|
-
logger.info("Workflow runtime started");
|
|
3343
3408
|
},
|
|
3344
3409
|
logger
|
|
3345
3410
|
});
|
|
@@ -3387,7 +3452,7 @@ async function initServer(serverPort, options, renown, renownConfig) {
|
|
|
3387
3452
|
});
|
|
3388
3453
|
packageManagementService.setOnModelsChanged(() => {
|
|
3389
3454
|
graphqlManager.regenerateDocumentModelSubgraphs().catch((error) => {
|
|
3390
|
-
|
|
3455
|
+
reportFailure(reporting, error, "Failed to regenerate document model subgraphs: @error");
|
|
3391
3456
|
});
|
|
3392
3457
|
});
|
|
3393
3458
|
const packagesSubgraph = new PackagesSubgraph({
|
|
@@ -3403,14 +3468,14 @@ async function initServer(serverPort, options, renown, renownConfig) {
|
|
|
3403
3468
|
attachments: api.attachmentClientProvider
|
|
3404
3469
|
});
|
|
3405
3470
|
lateSubgraphs.push(graphqlManager.registerSubgraphInstance(packagesSubgraph, "graphql", false).catch((error) => {
|
|
3406
|
-
|
|
3471
|
+
reportFailure(reporting, error, "Failed to register packages subgraph: @error");
|
|
3407
3472
|
}));
|
|
3408
3473
|
}
|
|
3409
3474
|
if (driveNodeView) {
|
|
3410
3475
|
graphqlManager.setAdditionalContextFields({ readModel: driveNodeView });
|
|
3411
3476
|
const authorizationService = graphqlManager.getAuthorizationService();
|
|
3412
3477
|
const reactorDriveSubgraph = {
|
|
3413
|
-
name:
|
|
3478
|
+
name: REACTOR_DRIVE_SUBGRAPH_NAME,
|
|
3414
3479
|
path: graphqlManager.getBasePath(),
|
|
3415
3480
|
resolvers: createReactorDriveResolvers({
|
|
3416
3481
|
reactorClient: client,
|
|
@@ -3422,18 +3487,18 @@ async function initServer(serverPort, options, renown, renownConfig) {
|
|
|
3422
3487
|
relationalDb: void 0
|
|
3423
3488
|
};
|
|
3424
3489
|
lateSubgraphs.push(graphqlManager.registerSubgraphInstance(reactorDriveSubgraph, "graphql", false).catch((error) => {
|
|
3425
|
-
|
|
3490
|
+
reportFailure(reporting, error, "Failed to register reactor-drive subgraph: @error");
|
|
3426
3491
|
}));
|
|
3427
3492
|
}
|
|
3428
|
-
(async () => {
|
|
3429
|
-
await Promise.
|
|
3493
|
+
runDetached("Marking the API ready", async () => {
|
|
3494
|
+
await Promise.allSettled(lateSubgraphs);
|
|
3430
3495
|
try {
|
|
3431
3496
|
await graphqlManager.updateRouter(true);
|
|
3432
3497
|
} catch (error) {
|
|
3433
|
-
|
|
3498
|
+
reportFailure(reporting, error, "Final router update before readiness failed: @error");
|
|
3434
3499
|
}
|
|
3435
3500
|
api.readiness.markReady();
|
|
3436
|
-
})
|
|
3501
|
+
}, reporting);
|
|
3437
3502
|
if (options.drive) {
|
|
3438
3503
|
if (!renown) throw new Error("Cannot create default drive without Renown identity");
|
|
3439
3504
|
if ((options.drive.documentType ?? "powerhouse/document-drive") === "powerhouse/reactor-drive") defaultDriveUrl = await addDefaultReactorDrive(client, options.drive, serverPort);
|
|
@@ -3474,6 +3539,7 @@ async function initServer(serverPort, options, renown, renownConfig) {
|
|
|
3474
3539
|
modelManifest: () => workerModels?.modelManifest() ?? [],
|
|
3475
3540
|
privacy: privacy ? { erasure: privacy.erasure } : void 0,
|
|
3476
3541
|
mcpEnabled: options.mcp !== false,
|
|
3542
|
+
inspectionEnabled: options.inspection !== false,
|
|
3477
3543
|
renown,
|
|
3478
3544
|
port: serverPort,
|
|
3479
3545
|
shutdown
|
|
@@ -3508,6 +3574,10 @@ const startSwitchboard = async (options = {}) => {
|
|
|
3508
3574
|
featureFlags,
|
|
3509
3575
|
option: options.mcp
|
|
3510
3576
|
});
|
|
3577
|
+
options.inspection = await resolveInspectionEnabled({
|
|
3578
|
+
featureFlags,
|
|
3579
|
+
option: options.inspection
|
|
3580
|
+
});
|
|
3511
3581
|
const configPathForFlags = resolveConfigPath(options.configFile);
|
|
3512
3582
|
const workflowsEnabled = await resolveWorkflowsEnabled({
|
|
3513
3583
|
featureFlags,
|
|
@@ -3523,6 +3593,7 @@ const startSwitchboard = async (options = {}) => {
|
|
|
3523
3593
|
logger.info("Feature flags: @flags", JSON.stringify({
|
|
3524
3594
|
DOCUMENT_MODEL_SUBGRAPHS_ENABLED: enableDocumentModelSubgraphs,
|
|
3525
3595
|
MCP_ENABLED: options.mcp,
|
|
3596
|
+
INSPECTION_ENABLED: options.inspection,
|
|
3526
3597
|
PH_WORKFLOWS_ENABLED: workflowsEnabled
|
|
3527
3598
|
}, null, 2));
|
|
3528
3599
|
let renown = null;
|
|
@@ -3545,5 +3616,5 @@ if (import.meta.main) await startSwitchboard({ fatalErrorShutdown: true });
|
|
|
3545
3616
|
//#endregion
|
|
3546
3617
|
export { StoredDocumentsRefusedError as a, initProfilerFromEnv as c, startSwitchboard as i, parseForcePgVersion as l, deriveAttachmentServiceConfig as n, resolveUnsupportedStoredDocuments as o, isPortAvailable as r, applySwitchboardReactorDefaults as s, createReactorKysely as t };
|
|
3547
3618
|
|
|
3548
|
-
//# sourceMappingURL=server-
|
|
3549
|
-
//# debugId=
|
|
3619
|
+
//# sourceMappingURL=server-Cw2WnaCA.mjs.map
|
|
3620
|
+
//# debugId=99cead54-dc11-5711-a454-9efc98498890
|