@powerhousedao/switchboard 6.3.0-dev.9 → 6.4.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.tsbuild/test/boot-helpers.d.ts +2 -1
- package/.tsbuild/test/boot-helpers.d.ts.map +1 -1
- package/.tsbuild/test/boot-identity-files.test.d.ts +2 -0
- package/.tsbuild/test/boot-identity-files.test.d.ts.map +1 -0
- package/.tsbuild/tsconfig.tsbuildinfo +1 -1
- package/CHANGELOG.md +59 -0
- package/README.md +12 -10
- package/dist/boot.d.mts +1 -1
- package/dist/boot.mjs +1 -1
- package/dist/config/from-env.d.mts +1 -1
- package/dist/config/from-env.d.mts.map +1 -1
- package/dist/config/from-env.mjs +3 -3
- package/dist/config/schema.d.mts +1 -1
- package/dist/config/schema.mjs +3 -3
- package/dist/{from-env-DKK_wPrO.mjs → from-env-CLImR6qa.mjs} +4 -28
- package/dist/from-env-CLImR6qa.mjs.map +1 -0
- package/dist/index.mjs +3 -3
- package/dist/migrate.mjs +9 -4
- package/dist/migrate.mjs.map +1 -1
- package/dist/{plugin-host-tTjDTNz0.d.mts → plugin-host-Z-4Ruypj.d.mts} +19 -2
- package/dist/plugin-host-Z-4Ruypj.d.mts.map +1 -0
- package/dist/plugins/ai.d.mts +1 -1
- package/dist/plugins/attachments.d.mts +1 -1
- package/dist/plugins/attachments.mjs +3 -3
- package/dist/plugins/mcp.d.mts +1 -1
- package/dist/plugins/privacy.d.mts +1 -1
- package/dist/plugins/workflows.d.mts +2 -2
- package/dist/plugins/workflows.mjs +3 -3
- package/dist/{schema-BJ-OFAox.mjs → schema-BbwISVSO.mjs} +15 -13
- package/dist/schema-BbwISVSO.mjs.map +1 -0
- package/dist/{schema-w1lShimw.d.mts → schema-CZsLzAZg.d.mts} +9 -4
- package/dist/schema-CZsLzAZg.d.mts.map +1 -0
- package/dist/{server-BS-PFzoK.mjs → server-BMRdMNvC.mjs} +172 -244
- package/dist/server-BMRdMNvC.mjs.map +1 -0
- package/dist/server.d.mts +2 -2
- package/dist/server.d.mts.map +1 -1
- package/dist/server.mjs +4 -4
- package/dist/{types-Bk4T4D9F.d.mts → types-Crizw8W4.d.mts} +13 -8
- package/dist/types-Crizw8W4.d.mts.map +1 -0
- package/dist/{utils-Cm0TE6dP.mjs → utils-D8yHRVjT.mjs} +4 -18
- package/dist/{utils-Cm0TE6dP.mjs.map → utils-D8yHRVjT.mjs.map} +1 -1
- package/dist/utils.d.mts +1 -6
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +4 -4
- package/dist/{workflows-mdYUh3Us.mjs → workflows-D2r6IKou.mjs} +4 -4
- package/dist/{workflows-mdYUh3Us.mjs.map → workflows-D2r6IKou.mjs.map} +1 -1
- package/package.json +17 -17
- package/test/ai-gateway.test.ts +0 -2
- package/test/boot-auth-config.test.ts +1 -1
- package/test/boot-helpers.ts +3 -1
- package/test/boot-identity-files.test.ts +68 -0
- package/test/boot-mcp-auth.test.ts +0 -1
- package/test/boot-mcp-enabled.test.ts +0 -2
- package/test/boot-port-zero.test.ts +1 -2
- package/test/boot-ready-drives.test.ts +1 -2
- package/test/config-from-env.test.ts +0 -9
- package/test/config-merge.test.ts +47 -47
- package/test/config-schema.test.ts +16 -4
- package/test/default-composition.test.ts +61 -65
- package/test/default-drive-protocol-versions.test.ts +13 -6
- package/test/default-drive-slug.test.ts +6 -11
- package/test/plugin-presence.test.ts +15 -16
- package/dist/from-env-DKK_wPrO.mjs.map +0 -1
- package/dist/plugin-host-tTjDTNz0.d.mts.map +0 -1
- package/dist/schema-BJ-OFAox.mjs.map +0 -1
- package/dist/schema-w1lShimw.d.mts.map +0 -1
- package/dist/server-BS-PFzoK.mjs.map +0 -1
- package/dist/types-Bk4T4D9F.d.mts.map +0 -1
|
@@ -1,15 +1,14 @@
|
|
|
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]="
|
|
3
|
-
import { a as loadNodeFsClass, c as openForVerify, d as ATTACHMENT_URL_SIGNING_SECRET_ENV, f as resolveAttachmentUrlSigning, i as isSupportedMajor, l as pgliteModuleSpec, n as StoredDocumentsRefusedError, o as loadPGliteModule, r as resolveUnsupportedStoredDocuments, s as loadPgDump, t as switchboardConfigFromEnv, u as readPgVersionFile } from "./from-env-
|
|
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]="d67a8a44-1f86-538e-a806-a6a54e5ca978")}catch(e){}}();
|
|
3
|
+
import { a as loadNodeFsClass, c as openForVerify, d as ATTACHMENT_URL_SIGNING_SECRET_ENV, f as resolveAttachmentUrlSigning, i as isSupportedMajor, l as pgliteModuleSpec, n as StoredDocumentsRefusedError, o as loadPGliteModule, r as resolveUnsupportedStoredDocuments, s as loadPgDump, t as switchboardConfigFromEnv, u as readPgVersionFile } from "./from-env-CLImR6qa.mjs";
|
|
4
4
|
import { a as resolveWorkerModelSources, l as resolveProjectionWorkerOptions, n as keepImportableSources, o as resolveWorkerPoolOptions, p as workerPoolIssues, s as assertProjectionWorkerSupported, t as buildWorkerDbConfig } from "./worker-pool-gyxJnCxA.mjs";
|
|
5
5
|
import { t as isPostgresUrl } from "./postgres-url-DTDhBjXX.mjs";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { _ as triggerFatalShutdown, a as workflowsPlugin, c as WORKFLOW_TELEMETRY_SCOPE, d as isWorkflowSingletonConflict, f as modelManifestSource, g as raiseSigterm, h as installFatalErrorShutdown, l as assertWorkflowPackageLoadable, m as workflowSingletonLossHandler, p as retryWorkflowSingleton, s as WORKFLOW_PACKAGE_NAME, u as composeWorkflowRuntime } from "./workflows-mdYUh3Us.mjs";
|
|
6
|
+
import { i as switchboardConfigSchema, o as mergeSwitchboardConfig } from "./schema-BbwISVSO.mjs";
|
|
7
|
+
import { a as workflowsPlugin, c as WORKFLOW_TELEMETRY_SCOPE, d as modelManifestSource, f as workflowSingletonLossHandler, h as triggerFatalShutdown, l as assertWorkflowPackageLoadable, m as raiseSigterm, p as installFatalErrorShutdown, s as WORKFLOW_PACKAGE_NAME, u as composeWorkflowRuntime } from "./workflows-D2r6IKou.mjs";
|
|
9
8
|
import { t as privacyPlugin } from "./privacy-UodgY0i_.mjs";
|
|
10
9
|
import { t as mcpPlugin } from "./mcp-VW52B8KD.mjs";
|
|
11
10
|
import { n as reactorFeatureFlagsOf, t as renownLayers } from "./renown-layers-DmbWLt46.mjs";
|
|
12
|
-
import {
|
|
11
|
+
import { t as ensureDrive } from "./utils-D8yHRVjT.mjs";
|
|
13
12
|
import { createRequire, register } from "node:module";
|
|
14
13
|
import { metrics, trace } from "@opentelemetry/api";
|
|
15
14
|
import { ReactorInstrumentation } from "@powerhousedao/opentelemetry-instrumentation-reactor";
|
|
@@ -23,7 +22,6 @@ import fs, { promises } from "node:fs";
|
|
|
23
22
|
import path, { join, resolve } from "node:path";
|
|
24
23
|
import { z } from "zod";
|
|
25
24
|
import { httpsHooksPath } from "@powerhousedao/reactor-api/https-hooks";
|
|
26
|
-
import { AttachmentAlreadyExists, AttachmentNotFound, AttachmentPending, AttachmentReferenceReadModel, AttachmentSchemaCompiler, HashMismatch, InvalidAttachmentMetadata, InvalidAttachmentRef, ReservationNotFound, SizeMismatch, UploadTooLarge, createRef, createRemoteAttachmentService, parseAttachmentDownloadTarget, validateReserveMetadata } from "@powerhousedao/reactor-attachments";
|
|
27
25
|
import { createAttachmentClient } from "@powerhousedao/reactor-attachments/client";
|
|
28
26
|
import { DriveNodeView, NodeProcessor, REACTOR_DRIVE_DOCUMENT_TYPE, ReactorDriveClient, createReactorDriveWriteStrategy } from "@powerhousedao/reactor-drive";
|
|
29
27
|
import { REACTOR_DRIVE_SUBGRAPH_NAME, createReactorDriveResolvers, reactorDriveSubgraphTypeDefs } from "@powerhousedao/reactor-drive/subgraph";
|
|
@@ -33,6 +31,7 @@ import { Kysely, PostgresDialect, sql } from "kysely";
|
|
|
33
31
|
import net from "node:net";
|
|
34
32
|
import path$1 from "path";
|
|
35
33
|
import { Pool } from "pg";
|
|
34
|
+
import { AttachmentAlreadyExists, AttachmentNotFound, AttachmentPending, AttachmentReferenceReadModel, AttachmentSchemaCompiler, HashMismatch, InvalidAttachmentMetadata, InvalidAttachmentRef, ReservationNotFound, SizeMismatch, UploadTooLarge, createRef, createRemoteAttachmentService, parseAttachmentDownloadTarget, validateReserveMetadata } from "@powerhousedao/reactor-attachments";
|
|
36
35
|
import { Readable } from "node:stream";
|
|
37
36
|
import { mergeContributions, resolveOrder, runObserveHook, runObserveHookSequential, runTransformHook } from "@powerhousedao/host-core";
|
|
38
37
|
import { defaultStoreDirs, resolvePhDir } from "@powerhousedao/shared/clis/ph-dir";
|
|
@@ -223,6 +222,115 @@ async function renameLegacyTables(db, tables) {
|
|
|
223
222
|
});
|
|
224
223
|
}
|
|
225
224
|
//#endregion
|
|
225
|
+
//#region src/workflow/oauth-apps-config.ts
|
|
226
|
+
/**
|
|
227
|
+
* The config file's `workflows.oauthApps`, client file paths made absolute
|
|
228
|
+
* from `dir`, the config file's folder. A malformed entry is left out; a
|
|
229
|
+
* relay that is not an object is dropped and reported, the app kept without
|
|
230
|
+
* it. The relay's fields are checked by the runtime, as for apps a host
|
|
231
|
+
* passes itself.
|
|
232
|
+
*/
|
|
233
|
+
function parseOAuthApps(raw, dir, onDroppedRelay) {
|
|
234
|
+
if (!Array.isArray(raw)) return [];
|
|
235
|
+
const at = (p) => typeof p === "string" && p ? path.resolve(dir, p) : void 0;
|
|
236
|
+
return raw.flatMap((entry) => {
|
|
237
|
+
const app = entry ?? {};
|
|
238
|
+
if (typeof app.id !== "string" || !app.id) return [];
|
|
239
|
+
const desktop = at(app.clients?.desktop);
|
|
240
|
+
const web = at(app.clients?.web);
|
|
241
|
+
let relay;
|
|
242
|
+
if (app.relay !== void 0) {
|
|
243
|
+
if (typeof app.relay === "object" && app.relay !== null && !Array.isArray(app.relay)) relay = app.relay;
|
|
244
|
+
else onDroppedRelay?.(app.id, app.relay);
|
|
245
|
+
}
|
|
246
|
+
return [{
|
|
247
|
+
id: app.id,
|
|
248
|
+
clients: {
|
|
249
|
+
...desktop ? { desktop } : {},
|
|
250
|
+
...web ? { web } : {}
|
|
251
|
+
},
|
|
252
|
+
...relay ? { relay } : {}
|
|
253
|
+
}];
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
//#endregion
|
|
257
|
+
//#region src/attachment-reference-read-model.mts
|
|
258
|
+
const attachmentSchemaCompiler = new AttachmentSchemaCompiler();
|
|
259
|
+
function createAttachmentReferenceReadModel(baseKysely, dependencies, attachmentReferenceWriter) {
|
|
260
|
+
return new AttachmentReferenceReadModel(baseKysely.withSchema(REACTOR_SCHEMA), dependencies.operationIndex, dependencies.writeCache, dependencies.processorManagerConsistencyTracker, dependencies.documentModelRegistry, attachmentSchemaCompiler, attachmentReferenceWriter);
|
|
261
|
+
}
|
|
262
|
+
function registerAttachmentReferenceReadModel(reactorBuilder, registration) {
|
|
263
|
+
reactorBuilder.withReadModelFactory(async ({ documentModelRegistry, operationIndex, writeCache, processorManagerConsistencyTracker }) => {
|
|
264
|
+
const readModel = createAttachmentReferenceReadModel(registration.baseKysely, {
|
|
265
|
+
operationIndex,
|
|
266
|
+
writeCache,
|
|
267
|
+
processorManagerConsistencyTracker,
|
|
268
|
+
documentModelRegistry
|
|
269
|
+
}, registration.attachmentReferenceWriter);
|
|
270
|
+
await readModel.init();
|
|
271
|
+
return readModel;
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
async function registerAttachmentReferenceReadModelOnModule(clientModule, attachmentReferenceWriter) {
|
|
275
|
+
const reactorModule = clientModule.reactorModule;
|
|
276
|
+
if (!reactorModule) return {
|
|
277
|
+
status: "unavailable",
|
|
278
|
+
reason: "in-process-reactor-module-unavailable"
|
|
279
|
+
};
|
|
280
|
+
const coordinator = reactorModule.readModelCoordinator;
|
|
281
|
+
if (!supportsLiveReadModelRegistration(coordinator)) return {
|
|
282
|
+
status: "unavailable",
|
|
283
|
+
reason: "live-read-model-registration-unsupported"
|
|
284
|
+
};
|
|
285
|
+
const readModel = createAttachmentReferenceReadModel(reactorModule.database, {
|
|
286
|
+
operationIndex: reactorModule.operationIndex,
|
|
287
|
+
writeCache: reactorModule.writeCache,
|
|
288
|
+
processorManagerConsistencyTracker: reactorModule.processorManagerConsistencyTracker,
|
|
289
|
+
documentModelRegistry: reactorModule.documentModelRegistry
|
|
290
|
+
}, attachmentReferenceWriter);
|
|
291
|
+
await readModel.init();
|
|
292
|
+
coordinator.addReadModel(readModel, "pre_ready");
|
|
293
|
+
await readModel.init();
|
|
294
|
+
return { status: "available" };
|
|
295
|
+
}
|
|
296
|
+
//#endregion
|
|
297
|
+
//#region src/builder-defaults.mts
|
|
298
|
+
/**
|
|
299
|
+
* Apply switchboard's standard configuration to a reactor + client builder
|
|
300
|
+
* pair. Each piece is opt-out via the options object; defaults mirror what
|
|
301
|
+
* `startSwitchboard` does when building a reactor itself. Mutates both
|
|
302
|
+
* builders in place.
|
|
303
|
+
*
|
|
304
|
+
* Does NOT touch kysely or read models — callers wire those themselves
|
|
305
|
+
* (see `withKysely` / `withReadModelFactory` on the reactor builder).
|
|
306
|
+
*/
|
|
307
|
+
/** The models switchboard always registers alongside package models. */
|
|
308
|
+
function switchboardBaseDocumentModels() {
|
|
309
|
+
return baseDocumentModels.map(([, model]) => model);
|
|
310
|
+
}
|
|
311
|
+
function applySwitchboardReactorDefaults(reactorBuilder, clientBuilder, options = {}) {
|
|
312
|
+
const baseModels = options.includeBaseModels !== false ? switchboardBaseDocumentModels() : [];
|
|
313
|
+
const extra = options.documentModels ?? [];
|
|
314
|
+
if (baseModels.length || extra.length) reactorBuilder.withDocumentModelSources(getUniqueDocumentModels(baseModels, extra));
|
|
315
|
+
if (options.upgradeManifests?.length) reactorBuilder.withUpgradeManifests(options.upgradeManifests);
|
|
316
|
+
const scheme = options.channelScheme === void 0 ? ChannelScheme.SWITCHBOARD : options.channelScheme;
|
|
317
|
+
if (scheme !== false) reactorBuilder.withChannelScheme(scheme);
|
|
318
|
+
if (options.signalHandlers !== false) reactorBuilder.withSignalHandlers();
|
|
319
|
+
if (options.executorConfig?.maxSkipThreshold !== void 0 || options.executorConfig?.featureFlags !== void 0) reactorBuilder.withExecutorConfig({
|
|
320
|
+
...options.executorConfig.maxSkipThreshold !== void 0 ? { maxSkipThreshold: options.executorConfig.maxSkipThreshold } : {},
|
|
321
|
+
...options.executorConfig.featureFlags !== void 0 ? { featureFlags: options.executorConfig.featureFlags } : {}
|
|
322
|
+
});
|
|
323
|
+
if (options.documentModelLoader) reactorBuilder.withDocumentModelLoader(options.documentModelLoader);
|
|
324
|
+
if (options.logger) reactorBuilder.withLogger(options.logger);
|
|
325
|
+
if (options.signer) {
|
|
326
|
+
clientBuilder.withSigner(options.signer);
|
|
327
|
+
reactorBuilder.withSigner(options.signer.signer, options.signer.workerSigner);
|
|
328
|
+
}
|
|
329
|
+
if (options.createSignaturePolicy) clientBuilder.withCreateSignaturePolicy(options.createSignaturePolicy);
|
|
330
|
+
const trust = options.trustPolicy ?? options.signer;
|
|
331
|
+
if (trust?.trustPolicy) reactorBuilder.withTrustPolicy(trust.trustPolicy, trust.workerTrustPolicy);
|
|
332
|
+
}
|
|
333
|
+
//#endregion
|
|
226
334
|
//#region src/attachments/auth.ts
|
|
227
335
|
const ANONYMOUS_ACTOR = {
|
|
228
336
|
user: void 0,
|
|
@@ -863,115 +971,6 @@ function signerFromEnvironment(backend, env) {
|
|
|
863
971
|
return signing.signer;
|
|
864
972
|
}
|
|
865
973
|
//#endregion
|
|
866
|
-
//#region src/workflow/oauth-apps-config.ts
|
|
867
|
-
/**
|
|
868
|
-
* The config file's `workflows.oauthApps`, client file paths made absolute
|
|
869
|
-
* from `dir`, the config file's folder. A malformed entry is left out; a
|
|
870
|
-
* relay that is not an object is dropped and reported, the app kept without
|
|
871
|
-
* it. The relay's fields are checked by the runtime, as for apps a host
|
|
872
|
-
* passes itself.
|
|
873
|
-
*/
|
|
874
|
-
function parseOAuthApps(raw, dir, onDroppedRelay) {
|
|
875
|
-
if (!Array.isArray(raw)) return [];
|
|
876
|
-
const at = (p) => typeof p === "string" && p ? path.resolve(dir, p) : void 0;
|
|
877
|
-
return raw.flatMap((entry) => {
|
|
878
|
-
const app = entry ?? {};
|
|
879
|
-
if (typeof app.id !== "string" || !app.id) return [];
|
|
880
|
-
const desktop = at(app.clients?.desktop);
|
|
881
|
-
const web = at(app.clients?.web);
|
|
882
|
-
let relay;
|
|
883
|
-
if (app.relay !== void 0) {
|
|
884
|
-
if (typeof app.relay === "object" && app.relay !== null && !Array.isArray(app.relay)) relay = app.relay;
|
|
885
|
-
else onDroppedRelay?.(app.id, app.relay);
|
|
886
|
-
}
|
|
887
|
-
return [{
|
|
888
|
-
id: app.id,
|
|
889
|
-
clients: {
|
|
890
|
-
...desktop ? { desktop } : {},
|
|
891
|
-
...web ? { web } : {}
|
|
892
|
-
},
|
|
893
|
-
...relay ? { relay } : {}
|
|
894
|
-
}];
|
|
895
|
-
});
|
|
896
|
-
}
|
|
897
|
-
//#endregion
|
|
898
|
-
//#region src/attachment-reference-read-model.mts
|
|
899
|
-
const attachmentSchemaCompiler = new AttachmentSchemaCompiler();
|
|
900
|
-
function createAttachmentReferenceReadModel(baseKysely, dependencies, attachmentReferenceWriter) {
|
|
901
|
-
return new AttachmentReferenceReadModel(baseKysely.withSchema(REACTOR_SCHEMA), dependencies.operationIndex, dependencies.writeCache, dependencies.processorManagerConsistencyTracker, dependencies.documentModelRegistry, attachmentSchemaCompiler, attachmentReferenceWriter);
|
|
902
|
-
}
|
|
903
|
-
function registerAttachmentReferenceReadModel(reactorBuilder, registration) {
|
|
904
|
-
reactorBuilder.withReadModelFactory(async ({ documentModelRegistry, operationIndex, writeCache, processorManagerConsistencyTracker }) => {
|
|
905
|
-
const readModel = createAttachmentReferenceReadModel(registration.baseKysely, {
|
|
906
|
-
operationIndex,
|
|
907
|
-
writeCache,
|
|
908
|
-
processorManagerConsistencyTracker,
|
|
909
|
-
documentModelRegistry
|
|
910
|
-
}, registration.attachmentReferenceWriter);
|
|
911
|
-
await readModel.init();
|
|
912
|
-
return readModel;
|
|
913
|
-
});
|
|
914
|
-
}
|
|
915
|
-
async function registerAttachmentReferenceReadModelOnModule(clientModule, attachmentReferenceWriter) {
|
|
916
|
-
const reactorModule = clientModule.reactorModule;
|
|
917
|
-
if (!reactorModule) return {
|
|
918
|
-
status: "unavailable",
|
|
919
|
-
reason: "in-process-reactor-module-unavailable"
|
|
920
|
-
};
|
|
921
|
-
const coordinator = reactorModule.readModelCoordinator;
|
|
922
|
-
if (!supportsLiveReadModelRegistration(coordinator)) return {
|
|
923
|
-
status: "unavailable",
|
|
924
|
-
reason: "live-read-model-registration-unsupported"
|
|
925
|
-
};
|
|
926
|
-
const readModel = createAttachmentReferenceReadModel(reactorModule.database, {
|
|
927
|
-
operationIndex: reactorModule.operationIndex,
|
|
928
|
-
writeCache: reactorModule.writeCache,
|
|
929
|
-
processorManagerConsistencyTracker: reactorModule.processorManagerConsistencyTracker,
|
|
930
|
-
documentModelRegistry: reactorModule.documentModelRegistry
|
|
931
|
-
}, attachmentReferenceWriter);
|
|
932
|
-
await readModel.init();
|
|
933
|
-
coordinator.addReadModel(readModel, "pre_ready");
|
|
934
|
-
await readModel.init();
|
|
935
|
-
return { status: "available" };
|
|
936
|
-
}
|
|
937
|
-
//#endregion
|
|
938
|
-
//#region src/builder-defaults.mts
|
|
939
|
-
/**
|
|
940
|
-
* Apply switchboard's standard configuration to a reactor + client builder
|
|
941
|
-
* pair. Each piece is opt-out via the options object; defaults mirror what
|
|
942
|
-
* `startSwitchboard` does when building a reactor itself. Mutates both
|
|
943
|
-
* builders in place.
|
|
944
|
-
*
|
|
945
|
-
* Does NOT touch kysely or read models — callers wire those themselves
|
|
946
|
-
* (see `withKysely` / `withReadModelFactory` on the reactor builder).
|
|
947
|
-
*/
|
|
948
|
-
/** The models switchboard always registers alongside package models. */
|
|
949
|
-
function switchboardBaseDocumentModels() {
|
|
950
|
-
return baseDocumentModels.map(([, model]) => model);
|
|
951
|
-
}
|
|
952
|
-
function applySwitchboardReactorDefaults(reactorBuilder, clientBuilder, options = {}) {
|
|
953
|
-
const baseModels = options.includeBaseModels !== false ? switchboardBaseDocumentModels() : [];
|
|
954
|
-
const extra = options.documentModels ?? [];
|
|
955
|
-
if (baseModels.length || extra.length) reactorBuilder.withDocumentModelSources(getUniqueDocumentModels(baseModels, extra));
|
|
956
|
-
if (options.upgradeManifests?.length) reactorBuilder.withUpgradeManifests(options.upgradeManifests);
|
|
957
|
-
const scheme = options.channelScheme === void 0 ? ChannelScheme.SWITCHBOARD : options.channelScheme;
|
|
958
|
-
if (scheme !== false) reactorBuilder.withChannelScheme(scheme);
|
|
959
|
-
if (options.signalHandlers !== false) reactorBuilder.withSignalHandlers();
|
|
960
|
-
if (options.executorConfig?.maxSkipThreshold !== void 0 || options.executorConfig?.featureFlags !== void 0) reactorBuilder.withExecutorConfig({
|
|
961
|
-
...options.executorConfig.maxSkipThreshold !== void 0 ? { maxSkipThreshold: options.executorConfig.maxSkipThreshold } : {},
|
|
962
|
-
...options.executorConfig.featureFlags !== void 0 ? { featureFlags: options.executorConfig.featureFlags } : {}
|
|
963
|
-
});
|
|
964
|
-
if (options.documentModelLoader) reactorBuilder.withDocumentModelLoader(options.documentModelLoader);
|
|
965
|
-
if (options.logger) reactorBuilder.withLogger(options.logger);
|
|
966
|
-
if (options.signer) {
|
|
967
|
-
clientBuilder.withSigner(options.signer);
|
|
968
|
-
reactorBuilder.withSigner(options.signer.signer, options.signer.workerSigner);
|
|
969
|
-
}
|
|
970
|
-
if (options.createSignaturePolicy) clientBuilder.withCreateSignaturePolicy(options.createSignaturePolicy);
|
|
971
|
-
const trust = options.trustPolicy ?? options.signer;
|
|
972
|
-
if (trust?.trustPolicy) reactorBuilder.withTrustPolicy(trust.trustPolicy, trust.workerTrustPolicy);
|
|
973
|
-
}
|
|
974
|
-
//#endregion
|
|
975
974
|
//#region src/plugins/attachments.mts
|
|
976
975
|
/** No entry config: presence is the whole activation. A typo'd config key
|
|
977
976
|
* fails at resolution instead of being silently ignored. */
|
|
@@ -1055,6 +1054,15 @@ function defaultSwitchboardPlugins(switches) {
|
|
|
1055
1054
|
return true;
|
|
1056
1055
|
});
|
|
1057
1056
|
}
|
|
1057
|
+
/**
|
|
1058
|
+
* The notice for a boot that `workflows.enabled` in powerhouse.config.json
|
|
1059
|
+
* switched workflows on before 6.4: no declared composition, and neither
|
|
1060
|
+
* PH_WORKFLOWS_ENABLED nor the caller says anything. The key no longer does.
|
|
1061
|
+
*/
|
|
1062
|
+
function configFileWorkflowsNotice(boot) {
|
|
1063
|
+
if (boot.declaredComposition || boot.workflows !== void 0 || boot.configFileEnabled !== true) return;
|
|
1064
|
+
return "powerhouse.config.json workflows.enabled no longer switches workflows on in Switchboard since 6.4, so they stay off. Set PH_WORKFLOWS_ENABLED=1, or list \"@powerhousedao/switchboard/plugins/workflows\" under runner.plugins in hosts/switchboard/host.js.";
|
|
1065
|
+
}
|
|
1058
1066
|
function createSwitchboardPluginHost(ctx, resolved) {
|
|
1059
1067
|
resolved ??= builtinSwitchboardPlugins();
|
|
1060
1068
|
const ordered = resolveOrder(resolved.map((r) => r.plugin));
|
|
@@ -1757,13 +1765,6 @@ function resolveKeyframes(configured, fromFile, configPath) {
|
|
|
1757
1765
|
if (configured) return configured;
|
|
1758
1766
|
return fromFile === void 0 ? void 0 : parseKeyframeSettings(fromFile, `${configPath} reactor.keyframes`);
|
|
1759
1767
|
}
|
|
1760
|
-
function readConfigWorkflowsEnabled(configPath) {
|
|
1761
|
-
try {
|
|
1762
|
-
return getConfig(configPath).workflows?.enabled ?? false;
|
|
1763
|
-
} catch {
|
|
1764
|
-
return false;
|
|
1765
|
-
}
|
|
1766
|
-
}
|
|
1767
1768
|
async function resolveServerPort(requested, strictPort, logger) {
|
|
1768
1769
|
if (requested === 0 || strictPort) return requested;
|
|
1769
1770
|
for (let i = 0; i < PORT_FALLBACK_ATTEMPTS; i++) {
|
|
@@ -1855,23 +1856,21 @@ async function captureInSentry(error) {
|
|
|
1855
1856
|
}
|
|
1856
1857
|
async function initServer(requestedPort, options, config, renown, renownConfig, reportError, opening) {
|
|
1857
1858
|
const { dev, packages = [], remoteDrives = [], logger = defaultLogger } = options;
|
|
1858
|
-
const pluginHost =
|
|
1859
|
+
const pluginHost = createSwitchboardPluginHost({
|
|
1859
1860
|
logger,
|
|
1860
1861
|
options,
|
|
1861
1862
|
config,
|
|
1862
1863
|
renown
|
|
1863
|
-
},
|
|
1864
|
+
}, options.pluginComposition ?? defaultSwitchboardPlugins({
|
|
1864
1865
|
mcp: options.mcp !== false,
|
|
1865
1866
|
workflows: options.workflows?.enabled === true
|
|
1866
1867
|
}));
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
options.workflows
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
};
|
|
1874
|
-
}
|
|
1868
|
+
options = await pluginHost.transformOptions(options);
|
|
1869
|
+
options.mcp ??= false;
|
|
1870
|
+
options.workflows = {
|
|
1871
|
+
...options.workflows,
|
|
1872
|
+
enabled: options.workflows?.enabled === true
|
|
1873
|
+
};
|
|
1875
1874
|
logger.level = config.logLevel;
|
|
1876
1875
|
const dbPath = config.storage.readModel.url;
|
|
1877
1876
|
const reactorDbUrl = config.storage.reactor.url;
|
|
@@ -1960,7 +1959,6 @@ async function initServer(requestedPort, options, config, renown, renownConfig,
|
|
|
1960
1959
|
raiseSigterm();
|
|
1961
1960
|
};
|
|
1962
1961
|
const workflowsEnabled = options.workflows?.enabled === true;
|
|
1963
|
-
const privacyConfig = pluginHost ? { enabled: false } : resolvePrivacy(options.privacy, {});
|
|
1964
1962
|
if (workflowsEnabled) {
|
|
1965
1963
|
await assertWorkflowPackageLoadable();
|
|
1966
1964
|
if (!packages.includes("@powerhousedao/workflow")) packages.push(WORKFLOW_PACKAGE_NAME);
|
|
@@ -2279,30 +2277,20 @@ async function initServer(requestedPort, options, config, renown, renownConfig,
|
|
|
2279
2277
|
localCredentialCheck = createLocalCredentialVerifier(localRenownRequest, { onError: (error) => logger.error("Renown read model query failed: @error", error) });
|
|
2280
2278
|
logger.info("Renown credentials will be verified against this switchboard's own renown read model");
|
|
2281
2279
|
}
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
await pluginHost.observe("onHttpMounting");
|
|
2287
|
-
attachmentService = pluginHost.ctx.attachmentService;
|
|
2288
|
-
} else {
|
|
2289
|
-
registerAttachmentRoutes(api, { config: config.attachments });
|
|
2290
|
-
attachmentService = createRemoteAttachmentService(deriveAttachmentServiceConfig(options, serverPort, renown));
|
|
2291
|
-
}
|
|
2280
|
+
pluginHost.ctx.api = api;
|
|
2281
|
+
pluginHost.ctx.serverPort = serverPort;
|
|
2282
|
+
await pluginHost.observe("onHttpMounting");
|
|
2283
|
+
const attachmentService = pluginHost.ctx.attachmentService;
|
|
2292
2284
|
if (process.env.SENTRY_DSN) api.httpAdapter.setupSentryErrorHandler(await import("@sentry/node"));
|
|
2293
2285
|
const { client, read, write, graphqlManager, documentModelRegistry } = api;
|
|
2294
2286
|
const lateSubgraphs = [];
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
await pluginHost.observe("onReactorReady");
|
|
2303
|
-
}
|
|
2304
|
-
let workflows;
|
|
2305
|
-
let workflowsRetry;
|
|
2287
|
+
pluginHost.ctx.client = client;
|
|
2288
|
+
pluginHost.ctx.read = read;
|
|
2289
|
+
pluginHost.ctx.write = write;
|
|
2290
|
+
pluginHost.ctx.graphqlManager = graphqlManager;
|
|
2291
|
+
pluginHost.ctx.lateSubgraphs = lateSubgraphs;
|
|
2292
|
+
pluginHost.ctx.reactorClientModule = options.reactor ?? ownedReactorModule;
|
|
2293
|
+
await pluginHost.observe("onReactorReady");
|
|
2306
2294
|
const composeWorkflows = () => composeWorkflowRuntime({
|
|
2307
2295
|
reactorClient: client,
|
|
2308
2296
|
clientModule: options.reactor ?? ownedReactorModule,
|
|
@@ -2345,85 +2333,22 @@ async function initServer(requestedPort, options, config, renown, renownConfig,
|
|
|
2345
2333
|
reportFailure(reporting, error, "Failed to register workflow-runtime subgraph: @error");
|
|
2346
2334
|
});
|
|
2347
2335
|
};
|
|
2348
|
-
|
|
2349
|
-
workflows
|
|
2336
|
+
pluginHost.ctx.workflowsOrchestration = {
|
|
2337
|
+
enabled: options.workflows?.enabled === true,
|
|
2338
|
+
composeWorkflows,
|
|
2339
|
+
registerWorkflowSubgraph,
|
|
2340
|
+
updateRouter: () => graphqlManager.updateRouter(true),
|
|
2341
|
+
reportMountFailure: (error) => reportFailure(reporting, error, "Mounting the late workflow-runtime subgraph failed: @error"),
|
|
2342
|
+
setWorkflowsFact: () => api.inspection?.facts.setWorkflows(true)
|
|
2343
|
+
};
|
|
2344
|
+
try {
|
|
2345
|
+
await pluginHost.observe("onSubgraphsRegistering");
|
|
2350
2346
|
} catch (error) {
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
try {
|
|
2357
|
-
await composed.start();
|
|
2358
|
-
} catch (error) {
|
|
2359
|
-
try {
|
|
2360
|
-
await composed.stop();
|
|
2361
|
-
} catch (stopError) {
|
|
2362
|
-
logger.error("Stopping the late workflow runtime failed: @error", stopError);
|
|
2363
|
-
}
|
|
2364
|
-
throw error;
|
|
2365
|
-
}
|
|
2366
|
-
logger.info("Workflow runtime started");
|
|
2367
|
-
workflows = composed;
|
|
2368
|
-
await registerWorkflowSubgraph(composed);
|
|
2369
|
-
try {
|
|
2370
|
-
await graphqlManager.updateRouter(true);
|
|
2371
|
-
} catch (error) {
|
|
2372
|
-
reportFailure(reporting, error, "Mounting the late workflow-runtime subgraph failed: @error");
|
|
2373
|
-
}
|
|
2374
|
-
},
|
|
2375
|
-
logger
|
|
2376
|
-
});
|
|
2377
|
-
}
|
|
2378
|
-
if (workflows) {
|
|
2379
|
-
lateSubgraphs.push(registerWorkflowSubgraph(workflows));
|
|
2380
|
-
const runtime = workflows;
|
|
2381
|
-
await withProgressHeartbeat({
|
|
2382
|
-
logger,
|
|
2383
|
-
label: "Starting the workflow runtime"
|
|
2384
|
-
}, () => runtime.start());
|
|
2385
|
-
logger.info("Workflow runtime started");
|
|
2386
|
-
api.inspection?.facts.setWorkflows(true);
|
|
2387
|
-
}
|
|
2388
|
-
if (pluginHost) {
|
|
2389
|
-
pluginHost.ctx.workflowsOrchestration = {
|
|
2390
|
-
enabled: options.workflows?.enabled === true,
|
|
2391
|
-
composeWorkflows,
|
|
2392
|
-
registerWorkflowSubgraph,
|
|
2393
|
-
updateRouter: () => graphqlManager.updateRouter(true),
|
|
2394
|
-
reportMountFailure: (error) => reportFailure(reporting, error, "Mounting the late workflow-runtime subgraph failed: @error"),
|
|
2395
|
-
setWorkflowsFact: () => api.inspection?.facts.setWorkflows(true)
|
|
2396
|
-
};
|
|
2397
|
-
try {
|
|
2398
|
-
await pluginHost.observe("onSubgraphsRegistering");
|
|
2399
|
-
} catch (error) {
|
|
2400
|
-
await pluginHost.ctx.workflowsRetry?.stop();
|
|
2401
|
-
await pluginHost.ctx.workflows?.stop();
|
|
2402
|
-
await pluginHost.ctx.privacy?.stop();
|
|
2403
|
-
await abortBoot(api);
|
|
2404
|
-
throw error;
|
|
2405
|
-
}
|
|
2406
|
-
}
|
|
2407
|
-
let privacy;
|
|
2408
|
-
if (!pluginHost && privacyConfig.enabled) {
|
|
2409
|
-
const signer = options.reactor ? options.privacy?.signer : options.privacy?.signer ?? renown?.signer;
|
|
2410
|
-
try {
|
|
2411
|
-
privacy = await startPrivacy({
|
|
2412
|
-
config: privacyConfig,
|
|
2413
|
-
reactorModule: (options.reactor ?? ownedReactorModule)?.reactorModule,
|
|
2414
|
-
signer,
|
|
2415
|
-
authorizationService: api.authorizationService,
|
|
2416
|
-
documentPermissionService: api.documentPermissionService,
|
|
2417
|
-
graphqlManager,
|
|
2418
|
-
readClient: read,
|
|
2419
|
-
logger: logger.child(["privacy"])
|
|
2420
|
-
});
|
|
2421
|
-
} catch (error) {
|
|
2422
|
-
await workflowsRetry?.stop();
|
|
2423
|
-
await workflows?.stop();
|
|
2424
|
-
await abortBoot(api);
|
|
2425
|
-
throw error;
|
|
2426
|
-
}
|
|
2347
|
+
await pluginHost.ctx.workflowsRetry?.stop();
|
|
2348
|
+
await pluginHost.ctx.workflows?.stop();
|
|
2349
|
+
await pluginHost.ctx.privacy?.stop();
|
|
2350
|
+
await abortBoot(api);
|
|
2351
|
+
throw error;
|
|
2427
2352
|
}
|
|
2428
2353
|
const stopCatchUpLoad = ownedReactorModule ? feedCatchUpPriority(catchUpPriority, api.httpServer) : () => {};
|
|
2429
2354
|
const stopTimingLog = startOwnedTimingLog(ownedReactorModule?.reactorModule, processorTiming, config.protocol.processorTimingLogMs, reactorLogger);
|
|
@@ -2433,10 +2358,7 @@ async function initServer(requestedPort, options, config, renown, renownConfig,
|
|
|
2433
2358
|
stopCatchUpLoad();
|
|
2434
2359
|
stopTimingLog();
|
|
2435
2360
|
memoryTelemetry.stop();
|
|
2436
|
-
|
|
2437
|
-
await privacy?.stop();
|
|
2438
|
-
await workflowsRetry?.stop();
|
|
2439
|
-
await workflows?.stop();
|
|
2361
|
+
await pluginHost.observe("onShutdown");
|
|
2440
2362
|
await api.dispose();
|
|
2441
2363
|
})();
|
|
2442
2364
|
apiRef.current = { dispose: drainApi };
|
|
@@ -2530,7 +2452,7 @@ async function initServer(requestedPort, options, config, renown, renownConfig,
|
|
|
2530
2452
|
if (!defaultDriveUrl && driveId) defaultDriveUrl = `${options.https ? "https" : "http"}://localhost:${serverPort}/d/${driveId}`;
|
|
2531
2453
|
}
|
|
2532
2454
|
}
|
|
2533
|
-
|
|
2455
|
+
await pluginHost.observe("onDrivesReady");
|
|
2534
2456
|
return {
|
|
2535
2457
|
defaultDriveUrl,
|
|
2536
2458
|
api,
|
|
@@ -2538,12 +2460,12 @@ async function initServer(requestedPort, options, config, renown, renownConfig,
|
|
|
2538
2460
|
attachmentService,
|
|
2539
2461
|
attachmentReferenceProjection: api.attachmentReferenceProjection,
|
|
2540
2462
|
get workflowTriggers() {
|
|
2541
|
-
return
|
|
2463
|
+
return pluginHost.ctx.workflows?.triggers;
|
|
2542
2464
|
},
|
|
2543
2465
|
workflowsEnabled,
|
|
2544
2466
|
modelManifest: () => workerModels?.modelManifest() ?? [],
|
|
2545
2467
|
privacy: (() => {
|
|
2546
|
-
const running =
|
|
2468
|
+
const running = pluginHost.ctx.privacy;
|
|
2547
2469
|
return running ? { erasure: running.erasure } : void 0;
|
|
2548
2470
|
})(),
|
|
2549
2471
|
mcpEnabled: options.mcp !== false,
|
|
@@ -2585,10 +2507,16 @@ const startSwitchboard = async (input = {}, deps = {}) => {
|
|
|
2585
2507
|
if (process.env.PYROSCOPE_SERVER_ADDRESS) await initProfilerFromEnv(process.env).catch((error) => logger.error("Error starting profiler: @error", error));
|
|
2586
2508
|
const serverPort = await resolveServerPort(config.server.port, config.server.strictPort, logger);
|
|
2587
2509
|
const options = serverOptionsOf(config, deps);
|
|
2588
|
-
if (
|
|
2510
|
+
if (options.pluginComposition === void 0) {
|
|
2589
2511
|
options.mcp = config.features.mcp ?? true;
|
|
2590
|
-
options.workflows = { enabled: config.features.workflows ??
|
|
2512
|
+
options.workflows = { enabled: config.features.workflows ?? false };
|
|
2591
2513
|
}
|
|
2514
|
+
const workflowsNotice = configFileWorkflowsNotice({
|
|
2515
|
+
declaredComposition: options.pluginComposition !== void 0,
|
|
2516
|
+
workflows: config.features.workflows,
|
|
2517
|
+
configFileEnabled: fileConfig.workflows?.enabled
|
|
2518
|
+
});
|
|
2519
|
+
if (workflowsNotice) logger.warn(workflowsNotice);
|
|
2592
2520
|
const renownConfig = resolveRenownConfig(renownLayers(fileConfig.auth?.renown, config.auth.renown), {}, logger);
|
|
2593
2521
|
const userDataDir = config.storage.userDataDir;
|
|
2594
2522
|
options.identity = {
|
|
@@ -2748,5 +2676,5 @@ function feedCatchUpPriority(priority, server) {
|
|
|
2748
2676
|
//#endregion
|
|
2749
2677
|
export { resolveKeyframes as a, attachmentsPlugin as c, initProfilerFromEnv as d, isPortAvailable as i, attachmentsPluginConfigSchema as l, deriveAttachmentServiceConfig as n, resolvePgliteStorageDirs as o, initSwitchboardProcess as r, startSwitchboard as s, createReactorKysely as t, applySwitchboardReactorDefaults as u };
|
|
2750
2678
|
|
|
2751
|
-
//# sourceMappingURL=server-
|
|
2752
|
-
//# debugId=
|
|
2679
|
+
//# sourceMappingURL=server-BMRdMNvC.mjs.map
|
|
2680
|
+
//# debugId=d67a8a44-1f86-538e-a806-a6a54e5ca978
|