@powerhousedao/switchboard 6.0.0-dev.153 → 6.0.0-dev.155

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/index.d.mts +1 -0
  3. package/dist/index.mjs +128 -0
  4. package/dist/index.mjs.map +1 -0
  5. package/dist/install-packages.d.mts +1 -0
  6. package/dist/install-packages.mjs +31 -0
  7. package/dist/install-packages.mjs.map +1 -0
  8. package/dist/migrate.d.mts +1 -0
  9. package/dist/migrate.mjs +55 -0
  10. package/dist/migrate.mjs.map +1 -0
  11. package/dist/server-DaWxxH2k.mjs +249 -0
  12. package/dist/server-DaWxxH2k.mjs.map +1 -0
  13. package/dist/server.d.mts +76 -0
  14. package/dist/server.d.mts.map +1 -0
  15. package/dist/server.mjs +4 -0
  16. package/dist/utils-DFl0ezBT.mjs +44 -0
  17. package/dist/utils-DFl0ezBT.mjs.map +1 -0
  18. package/dist/utils.d.mts +9 -0
  19. package/dist/utils.d.mts.map +1 -0
  20. package/dist/utils.mjs +2 -0
  21. package/package.json +26 -25
  22. package/tsconfig.json +2 -6
  23. package/tsdown.config.ts +16 -0
  24. package/dist/src/config.d.ts +0 -12
  25. package/dist/src/config.d.ts.map +0 -1
  26. package/dist/src/config.js +0 -33
  27. package/dist/src/config.js.map +0 -1
  28. package/dist/src/feature-flags.d.ts +0 -2
  29. package/dist/src/feature-flags.d.ts.map +0 -1
  30. package/dist/src/feature-flags.js +0 -9
  31. package/dist/src/feature-flags.js.map +0 -1
  32. package/dist/src/index.d.ts +0 -3
  33. package/dist/src/index.d.ts.map +0 -1
  34. package/dist/src/index.js +0 -49
  35. package/dist/src/index.js.map +0 -1
  36. package/dist/src/install-packages.d.ts +0 -2
  37. package/dist/src/install-packages.d.ts.map +0 -1
  38. package/dist/src/install-packages.js +0 -36
  39. package/dist/src/install-packages.js.map +0 -1
  40. package/dist/src/metrics.d.ts +0 -7
  41. package/dist/src/metrics.d.ts.map +0 -1
  42. package/dist/src/metrics.js +0 -34
  43. package/dist/src/metrics.js.map +0 -1
  44. package/dist/src/migrate.d.ts +0 -3
  45. package/dist/src/migrate.d.ts.map +0 -1
  46. package/dist/src/migrate.js +0 -65
  47. package/dist/src/migrate.js.map +0 -1
  48. package/dist/src/profiler.d.ts +0 -9
  49. package/dist/src/profiler.d.ts.map +0 -1
  50. package/dist/src/profiler.js +0 -43
  51. package/dist/src/profiler.js.map +0 -1
  52. package/dist/src/renown.d.ts +0 -24
  53. package/dist/src/renown.d.ts.map +0 -1
  54. package/dist/src/renown.js +0 -45
  55. package/dist/src/renown.js.map +0 -1
  56. package/dist/src/server.d.ts +0 -5
  57. package/dist/src/server.d.ts.map +0 -1
  58. package/dist/src/server.js +0 -293
  59. package/dist/src/server.js.map +0 -1
  60. package/dist/src/types.d.ts +0 -73
  61. package/dist/src/types.d.ts.map +0 -1
  62. package/dist/src/types.js +0 -2
  63. package/dist/src/types.js.map +0 -1
  64. package/dist/src/utils.d.ts +0 -5
  65. package/dist/src/utils.d.ts.map +0 -1
  66. package/dist/src/utils.js +0 -63
  67. package/dist/src/utils.js.map +0 -1
  68. package/dist/test/metrics.test.d.ts +0 -2
  69. package/dist/test/metrics.test.d.ts.map +0 -1
  70. package/dist/test/metrics.test.js +0 -121
  71. package/dist/test/metrics.test.js.map +0 -1
  72. package/dist/tsconfig.tsbuildinfo +0 -1
  73. package/dist/vitest.config.d.ts +0 -3
  74. package/dist/vitest.config.d.ts.map +0 -1
  75. package/dist/vitest.config.js +0 -11
  76. package/dist/vitest.config.js.map +0 -1
@@ -1,43 +0,0 @@
1
- export async function initProfilerFromEnv(env) {
2
- const { PYROSCOPE_SERVER_ADDRESS: serverAddress, PYROSCOPE_APPLICATION_NAME: appName, PYROSCOPE_USER: basicAuthUser, PYROSCOPE_PASSWORD: basicAuthPassword, PYROSCOPE_WALL_ENABLED: wallEnabled, PYROSCOPE_HEAP_ENABLED: heapEnabled, } = env;
3
- const options = {
4
- serverAddress,
5
- appName,
6
- basicAuthUser,
7
- basicAuthPassword,
8
- // Wall profiling captures wall-clock time (includes async I/O waits)
9
- // This shows GraphQL resolvers even when waiting for database
10
- wall: {
11
- samplingDurationMs: 10000, // 10 second sampling windows
12
- samplingIntervalMicros: 10000, // 10ms sampling interval (100 samples/sec)
13
- collectCpuTime: true, // Also collect CPU time alongside wall time
14
- },
15
- // Heap profiling for memory allocation tracking
16
- heap: {
17
- samplingIntervalBytes: 512 * 1024, // Sample every 512KB allocated
18
- stackDepth: 64, // Capture deeper stacks for better context
19
- },
20
- };
21
- return initProfiler(options, {
22
- wallEnabled: wallEnabled !== "false",
23
- heapEnabled: heapEnabled === "true",
24
- });
25
- }
26
- export async function initProfiler(options, flags = { wallEnabled: true, heapEnabled: false }) {
27
- console.log("Initializing Pyroscope profiler at:", options?.serverAddress);
28
- console.log(" Wall profiling:", flags.wallEnabled ? "enabled" : "disabled");
29
- console.log(" Heap profiling:", flags.heapEnabled ? "enabled" : "disabled");
30
- const { default: Pyroscope } = await import("@pyroscope/nodejs");
31
- Pyroscope.init(options);
32
- // Start wall profiling (captures async I/O time - shows resolvers)
33
- if (flags.wallEnabled) {
34
- Pyroscope.startWallProfiling();
35
- }
36
- // Start CPU profiling (captures CPU-bound work)
37
- Pyroscope.startCpuProfiling();
38
- // Optionally start heap profiling (memory allocations)
39
- if (flags.heapEnabled) {
40
- Pyroscope.startHeapProfiling();
41
- }
42
- }
43
- //# sourceMappingURL=profiler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"profiler.js","sourceRoot":"","sources":["../../src/profiler.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,GAAuB;IAC/D,MAAM,EACJ,wBAAwB,EAAE,aAAa,EACvC,0BAA0B,EAAE,OAAO,EACnC,cAAc,EAAE,aAAa,EAC7B,kBAAkB,EAAE,iBAAiB,EACrC,sBAAsB,EAAE,WAAW,EACnC,sBAAs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AC;IACjC,CAAC;IAED,gDAAgD;IAChD,SAAS,CAAC,iBAAiB,EAAE,CAAC;IAE9B,uDAAuD;IACvD,IAAI,KAAK,CAAC,WAAW,EAAE,CAAC;QACtB,SAAS,CAAC,kBAAkB,EAAE,CAAC;IACjC,CAAC;AACH,CAAC"}
@@ -1,24 +0,0 @@
1
- import type { SignerConfig } from "@powerhousedao/reactor";
2
- import { type IRenown } from "@renown/sdk/node";
3
- export interface RenownOptions {
4
- /** Path to the keypair file. Defaults to .ph/.keypair.json in cwd */
5
- keypairPath?: string;
6
- /** If true, won't generate a new keypair if none exists */
7
- requireExisting?: boolean;
8
- /** Base url of the Renown instance to use */
9
- baseUrl?: string;
10
- }
11
- /**
12
- * Initialize Renown for the Switchboard instance.
13
- * This allows Switchboard to authenticate with remote services
14
- * using the same identity established during `ph login`.
15
- */
16
- export declare function initRenown(options?: RenownOptions): Promise<IRenown | null>;
17
- /**
18
- * Get the signer config for the given renown instance.
19
- *
20
- * @param renown - The renown instance
21
- * @param requireSignature - If true, unsigned actions are rejected
22
- */
23
- export declare function getRenownSignerConfig(renown: IRenown, requireSignature?: boolean): SignerConfig;
24
- //# sourceMappingURL=renown.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"renown.d.ts","sourceRoot":"","sources":["../../src/renown.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAML,KAAK,OAAO,EACb,MAAM,kBAAkB,CAAC;AAK1B,MAAM,WAAW,aAAa;IAC5B,qEAAqE;IACrE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2DAA2D;IAC3D,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,6CAA6C;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;GAIG;AACH,wBAAsB,UAAU,CAC9B,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAqCzB;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,OAAO,EACf,gBAAgB,CAAC,EAAE,OAAO,GACzB,YAAY,CAKd"}
@@ -1,45 +0,0 @@
1
- import { createSignatureVerifier, DEFAULT_RENOWN_URL, NodeKeyStorage, RenownBuilder, RenownCryptoBuilder, } from "@renown/sdk/node";
2
- import { childLogger } from "document-model";
3
- const logger = childLogger(["switchboard", "renown"]);
4
- /**
5
- * Initialize Renown for the Switchboard instance.
6
- * This allows Switchboard to authenticate with remote services
7
- * using the same identity established during `ph login`.
8
- */
9
- export async function initRenown(options = {}) {
10
- const { keypairPath, requireExisting = false, baseUrl = DEFAULT_RENOWN_URL, } = options;
11
- const keyStorage = new NodeKeyStorage(keypairPath, {
12
- logger,
13
- });
14
- // Check if we have an existing keypair
15
- const existingKeyPair = await keyStorage.loadKeyPair();
16
- if (!existingKeyPair && requireExisting) {
17
- throw new Error("No existing keypair found and requireExisting is true. " +
18
- 'Run "ph login" to create one.');
19
- }
20
- if (!existingKeyPair) {
21
- logger.info("No existing keypair found. A new one will be generated.");
22
- }
23
- const renownCrypto = await new RenownCryptoBuilder()
24
- .withKeyPairStorage(keyStorage)
25
- .build();
26
- const renown = await new RenownBuilder("switchboard", {})
27
- .withCrypto(renownCrypto)
28
- .withBaseUrl(baseUrl)
29
- .build();
30
- logger.info("Switchboard identity initialized: @did", renownCrypto.did);
31
- return renown;
32
- }
33
- /**
34
- * Get the signer config for the given renown instance.
35
- *
36
- * @param renown - The renown instance
37
- * @param requireSignature - If true, unsigned actions are rejected
38
- */
39
- export function getRenownSignerConfig(renown, requireSignature) {
40
- return {
41
- signer: renown.signer,
42
- verifier: createSignatureVerifier(requireSignature),
43
- };
44
- }
45
- //# sourceMappingURL=renown.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"renown.js","sourceRoot":"","sources":["../../src/renown.ts"],"names":[],"mappings":"AACA,OAAO,EACL,uBAAuB,EACvB,kBAAkB,EAClB,cAA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B,QAAQ,EAAE,uBAAuB,CAAC,gBAAgB,CAAC;KACpD,CAAC;AACJ,CAAC"}
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env node
2
- import type { StartServerOptions, SwitchboardReactor } from "./types.js";
3
- export declare const startSwitchboard: (options?: StartServerOptions) => Promise<SwitchboardReactor>;
4
- export * from "./types.js";
5
- //# sourceMappingURL=server.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":";AAkDA,OAAO,KAAK,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAySzE,eAAO,MAAM,gBAAgB,GAC3B,UAAS,kBAAuB,KAC/B,OAAO,CAAC,kBAAkB,CAwD5B,CAAC;AAEF,cAAc,YAAY,CAAC"}
@@ -1,293 +0,0 @@
1
- #!/usr/bin/env node
2
- import { ImportPackageLoader, httpsHooksPath, } from "@powerhousedao/reactor-api";
3
- import { register } from "node:module";
4
- // Register HTTP/HTTPS module loader hooks for dynamic package imports
5
- register(httpsHooksPath, import.meta.url);
6
- import { PGlite } from "@electric-sql/pglite";
7
- import { metrics } from "@opentelemetry/api";
8
- import { getConfig } from "@powerhousedao/config/node";
9
- import { ReactorInstrumentation } from "@powerhousedao/opentelemetry-instrumentation-reactor";
10
- import { ChannelScheme, EventBus, ReactorBuilder, ReactorClientBuilder, driveCollectionId, parseDriveUrl, } from "@powerhousedao/reactor";
11
- import { HttpPackageLoader, PackageManagementService, PackagesSubgraph, getUniqueDocumentModels, initializeAndStartAPI, } from "@powerhousedao/reactor-api";
12
- import { VitePackageLoader, createViteLogger, startViteServer, } from "@powerhousedao/reactor-api/vite";
13
- import { driveDocumentModelModule } from "@powerhousedao/shared/document-drive";
14
- import { documentModels as vetraDocumentModels } from "@powerhousedao/vetra";
15
- import { processorFactory as vetraProcessorFactory } from "@powerhousedao/vetra/processors";
16
- import * as Sentry from "@sentry/node";
17
- import { childLogger, documentModelDocumentModelModule } from "document-model";
18
- import dotenv from "dotenv";
19
- import { Kysely, PostgresDialect } from "kysely";
20
- import { PGliteDialect } from "kysely-pglite-dialect";
21
- import path from "path";
22
- import { Pool } from "pg";
23
- import { initFeatureFlags } from "./feature-flags.js";
24
- import { getRenownSignerConfig, initRenown } from "./renown.js";
25
- import { addDefaultDrive, isPostgresUrl } from "./utils.js";
26
- const defaultLogger = childLogger(["switchboard"]);
27
- dotenv.config();
28
- // Feature flag constants
29
- const DOCUMENT_MODEL_SUBGRAPHS_ENABLED = "DOCUMENT_MODEL_SUBGRAPHS_ENABLED";
30
- const DOCUMENT_MODEL_SUBGRAPHS_ENABLED_DEFAULT = true;
31
- const REQUIRE_SIGNATURES = "REQUIRE_SIGNATURES";
32
- const REQUIRE_SIGNATURES_DEFAULT = false;
33
- if (process.env.SENTRY_DSN) {
34
- defaultLogger.info("Initialized Sentry with env: @env", process.env.SENTRY_ENV);
35
- Sentry.init({
36
- dsn: process.env.SENTRY_DSN,
37
- environment: process.env.SENTRY_ENV,
38
- });
39
- }
40
- const DEFAULT_PORT = process.env.PORT ? Number(process.env.PORT) : 4001;
41
- async function initServer(serverPort, options, renown) {
42
- // Register the global MeterProvider before ReactorInstrumentation is
43
- // constructed. setGlobalMeterProvider is a one-way door — once set it cannot
44
- // be unset — so this must happen before initializeClient calls
45
- // instrumentation.start() → createMetrics() → metrics.getMeter().
46
- if (options.meterProvider) {
47
- metrics.setGlobalMeterProvider(options.meterProvider);
48
- }
49
- const { dev, packages = [], remoteDrives = [], logger = defaultLogger, } = options;
50
- const dbPath = options.dbPath ?? process.env.DATABASE_URL;
51
- // use postgres url for read model storage if available, otherwise use local PGlite path
52
- const readModelPath = dbPath || ".ph/read-storage";
53
- // HTTP registry package loading
54
- const configPath = options.configFile ?? path.join(process.cwd(), "powerhouse.config.json");
55
- const config = getConfig(configPath);
56
- const registryUrl = process.env.PH_REGISTRY_URL ?? config.packageRegistryUrl;
57
- const registryPackages = process.env.PH_REGISTRY_PACKAGES;
58
- let httpLoader;
59
- if (registryUrl) {
60
- httpLoader = new HttpPackageLoader({ registryUrl });
61
- registryPackages?.split(",").forEach((p) => {
62
- const name = p.trim();
63
- if (!packages.includes(name)) {
64
- packages.push(name);
65
- }
66
- });
67
- }
68
- const reactorLogger = logger.child(["reactor"]);
69
- const initializeClient = async (documentModels) => {
70
- const eventBus = new EventBus();
71
- const builder = new ReactorBuilder()
72
- .withEventBus(eventBus)
73
- .withDocumentModels(getUniqueDocumentModels([
74
- documentModelDocumentModelModule,
75
- driveDocumentModelModule,
76
- ...vetraDocumentModels,
77
- ...documentModels,
78
- ]))
79
- .withChannelScheme(ChannelScheme.SWITCHBOARD)
80
- .withSignalHandlers()
81
- .withLogger(reactorLogger);
82
- const maxSkipThreshold = parseInt(process.env.MAX_SKIP_THRESHOLD ?? "", 10);
83
- if (!isNaN(maxSkipThreshold) && maxSkipThreshold > 0) {
84
- builder.withExecutorConfig({ maxSkipThreshold });
85
- logger.info(`Reactor maxSkipThreshold set to ${maxSkipThreshold}`);
86
- }
87
- const reactorDbUrl = process.env.PH_REACTOR_DATABASE_URL;
88
- if (reactorDbUrl && isPostgresUrl(reactorDbUrl)) {
89
- const connectionString = reactorDbUrl.includes("?")
90
- ? reactorDbUrl
91
- : `${reactorDbUrl}?sslmode=disable`;
92
- const pool = new Pool({ connectionString });
93
- const kysely = new Kysely({
94
- dialect: new PostgresDialect({ pool }),
95
- });
96
- builder.withKysely(kysely);
97
- logger.info("Using PostgreSQL for reactor storage");
98
- }
99
- else {
100
- const pglitePath = "./.ph/reactor-storage";
101
- const pglite = new PGlite(pglitePath);
102
- const kysely = new Kysely({
103
- dialect: new PGliteDialect(pglite),
104
- });
105
- builder.withKysely(kysely);
106
- logger.info("Using PGlite for reactor storage");
107
- }
108
- if (httpLoader && options.dynamicModelLoading) {
109
- builder.withDocumentModelLoader(httpLoader.documentModelLoader);
110
- }
111
- const clientBuilder = new ReactorClientBuilder().withReactorBuilder(builder);
112
- if (renown) {
113
- const signerConfig = getRenownSignerConfig(renown, options.identity?.requireSignatures);
114
- clientBuilder.withSigner(signerConfig);
115
- }
116
- const module = await clientBuilder.buildModule();
117
- if (module.reactorModule) {
118
- const instrumentation = new ReactorInstrumentation(module.reactorModule);
119
- instrumentation.start();
120
- reactorLogger.info("Reactor metrics instrumentation started");
121
- }
122
- return module;
123
- };
124
- let defaultDriveUrl = undefined;
125
- // TODO get path from powerhouse config
126
- // start vite server if dev mode is enabled
127
- const basePath = process.cwd();
128
- const viteLogger = createViteLogger(logger);
129
- const vite = dev
130
- ? await startViteServer(process.cwd(), viteLogger)
131
- : undefined;
132
- // get paths to local document models
133
- if (!options.disableLocalPackages) {
134
- packages.push(basePath);
135
- }
136
- // create loaders
137
- const packageLoaders = [];
138
- if (vite) {
139
- packageLoaders.push(VitePackageLoader.build(vite));
140
- }
141
- else {
142
- packageLoaders.push(new ImportPackageLoader());
143
- }
144
- if (httpLoader) {
145
- packageLoaders.push(httpLoader);
146
- registryPackages?.split(",").forEach((p) => {
147
- const name = p.trim();
148
- if (!packages.includes(name)) {
149
- packages.push(name);
150
- }
151
- });
152
- }
153
- const apiLogger = logger.child(["reactor-api"]);
154
- const api = await initializeAndStartAPI(initializeClient, {
155
- port: serverPort,
156
- dbPath: readModelPath,
157
- https: options.https,
158
- packageLoaders: packageLoaders.length > 0 ? packageLoaders : undefined,
159
- packages: packages,
160
- processorConfig: options.processorConfig,
161
- processors: {
162
- "@powerhousedao/vetra": [vetraProcessorFactory],
163
- },
164
- configFile: options.configFile ??
165
- path.join(process.cwd(), "powerhouse.config.json"),
166
- mcp: options.mcp ?? true,
167
- logger: apiLogger,
168
- enableDocumentModelSubgraphs: options.enableDocumentModelSubgraphs,
169
- }, "switchboard");
170
- if (process.env.SENTRY_DSN) {
171
- // Register Sentry error handler after all routes are established.
172
- // The adapter calls the framework-specific Sentry setup internally.
173
- api.httpAdapter.setupSentryErrorHandler(Sentry);
174
- }
175
- const { client, graphqlManager, documentModelRegistry } = api;
176
- // Wire up dynamic package management if HTTP loader is configured
177
- if (httpLoader) {
178
- const packageManagementService = new PackageManagementService({
179
- defaultRegistryUrl: registryUrl,
180
- httpLoader,
181
- documentModelRegistry,
182
- });
183
- packageManagementService.setOnModelsChanged(() => {
184
- graphqlManager.regenerateDocumentModelSubgraphs().catch(logger.error);
185
- });
186
- const packagesSubgraph = new PackagesSubgraph({
187
- relationalDb: undefined,
188
- analyticsStore: undefined,
189
- reactorClient: client,
190
- graphqlManager,
191
- syncManager: api.syncManager,
192
- path: graphqlManager.getBasePath(),
193
- packageManagementService,
194
- });
195
- void graphqlManager
196
- .registerSubgraphInstance(packagesSubgraph, "graphql", false)
197
- .then(() => graphqlManager.updateRouter())
198
- .catch((error) => {
199
- logger.error("Failed to register packages subgraph: @error", error);
200
- });
201
- }
202
- // Create default drive if provided
203
- if (options.drive) {
204
- if (!renown) {
205
- throw new Error("Cannot create default drive without Renown identity");
206
- }
207
- defaultDriveUrl = await addDefaultDrive(client, options.drive, serverPort);
208
- }
209
- // add vite middleware after express app is initialized if applicable
210
- if (vite) {
211
- api.httpAdapter.mountRawMiddleware(vite.middlewares);
212
- }
213
- // Connect to remote drives AFTER packages are loaded
214
- if (remoteDrives.length > 0) {
215
- for (const remoteDriveUrl of remoteDrives) {
216
- let driveId;
217
- try {
218
- const { syncManager } = api;
219
- const parsed = parseDriveUrl(remoteDriveUrl);
220
- driveId = parsed.driveId;
221
- const remoteName = `remote-drive-${driveId}-${crypto.randomUUID()}`;
222
- await syncManager.add(remoteName, driveCollectionId("main", driveId), {
223
- type: "gql",
224
- parameters: { url: parsed.graphqlEndpoint },
225
- });
226
- logger.debug("Remote drive @remoteDriveUrl synced", remoteDriveUrl);
227
- }
228
- catch (error) {
229
- if (error instanceof Error &&
230
- error.message.includes("already exists")) {
231
- logger.debug("Remote drive already added: @remoteDriveUrl", remoteDriveUrl);
232
- driveId = remoteDriveUrl.split("/").pop();
233
- }
234
- else {
235
- logger.error("Failed to connect to remote drive @remoteDriveUrl: @error", remoteDriveUrl, error);
236
- }
237
- }
238
- finally {
239
- // Construct local URL once in finally block
240
- if (!defaultDriveUrl && driveId) {
241
- const protocol = options.https ? "https" : "http";
242
- defaultDriveUrl = `${protocol}://localhost:${serverPort}/d/${driveId}`;
243
- }
244
- }
245
- }
246
- }
247
- return {
248
- defaultDriveUrl,
249
- api,
250
- reactor: client,
251
- renown,
252
- };
253
- }
254
- export const startSwitchboard = async (options = {}) => {
255
- const serverPort = options.port ?? DEFAULT_PORT;
256
- // Initialize feature flags
257
- const featureFlags = await initFeatureFlags();
258
- const enableDocumentModelSubgraphs = await featureFlags.getBooleanValue(DOCUMENT_MODEL_SUBGRAPHS_ENABLED, options.enableDocumentModelSubgraphs ??
259
- DOCUMENT_MODEL_SUBGRAPHS_ENABLED_DEFAULT);
260
- options.enableDocumentModelSubgraphs = enableDocumentModelSubgraphs;
261
- const requireSignatures = options.identity?.requireSignatures ??
262
- (await featureFlags.getBooleanValue(REQUIRE_SIGNATURES, REQUIRE_SIGNATURES_DEFAULT));
263
- options.identity = { ...options.identity, requireSignatures };
264
- const logger = options.logger ?? defaultLogger;
265
- logger.info("Feature flags: @flags", JSON.stringify({
266
- DOCUMENT_MODEL_SUBGRAPHS_ENABLED: enableDocumentModelSubgraphs,
267
- REQUIRE_SIGNATURES: requireSignatures,
268
- }, null, 2));
269
- // Initialize Renown if identity options are provided or keypair exists
270
- let renown = null;
271
- try {
272
- renown = await initRenown(options.identity);
273
- }
274
- catch (e) {
275
- logger.warn("Failed to initialize ConnectCrypto: @error", e);
276
- if (options.identity?.requireExisting) {
277
- throw new Error('Identity required but failed to initialize. Run "ph login" first.');
278
- }
279
- }
280
- try {
281
- return await initServer(serverPort, options, renown);
282
- }
283
- catch (e) {
284
- Sentry.captureException(e);
285
- logger.error("App crashed: @error", e);
286
- throw e;
287
- }
288
- };
289
- export * from "./types.js";
290
- if (import.meta.main) {
291
- await startSwitchboard();
292
- }
293
- //# sourceMappingURL=server.js.map
@@ -1 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edao/reactor";
3
- import type { IRenown } from "@renown/sdk";
4
- import type { DriveInput } from "@powerhousedao/shared/document-drive";
5
- import type { ILogger } from "document-model";
6
- export type StorageOptions = {
7
- type: "filesystem" | "memory" | "postgres" | "browser";
8
- filesystemPath?: string;
9
- postgresUrl?: string;
10
- };
11
- export type IdentityOptions = {
12
- /** Path to the keypair file. Defaults to ~/.ph/keypair.json */
13
- keypairPath?: string;
14
- /**
15
- * If true, won't start without an existing keypair.
16
- * Use this to ensure the switchboard only runs with an authenticated identity.
17
- */
18
- requireExisting?: boolean;
19
- /** Base url of the Renown instance to use */
20
- baseUrl?: string;
21
- /** If true, unsigned actions will be rejected */
22
- requireSignatures?: boolean;
23
- };
24
- export type StartServerOptions = {
25
- configFile?: string;
26
- port?: number;
27
- dev?: boolean;
28
- dbPath?: string;
29
- drive?: DriveInput;
30
- packages?: string[];
31
- remoteDrives?: string[];
32
- https?: {
33
- keyPath: string;
34
- certPath: string;
35
- } | boolean | undefined;
36
- auth?: {
37
- enabled: boolean;
38
- guests: string[];
39
- users: string[];
40
- admins: string[];
41
- };
42
- /**
43
- * Identity options for Renown.
44
- * When configured, the switchboard will load the keypair from `ph login`
45
- * and can authenticate with remote services on behalf of the user.
46
- */
47
- identity?: IdentityOptions;
48
- mcp?: boolean;
49
- processorConfig?: Map<string, unknown>;
50
- disableLocalPackages?: boolean;
51
- enableDocumentModelSubgraphs?: boolean;
52
- /**
53
- * When true, enables dynamic loading of document models from the registry
54
- * when an unknown document type is encountered during sync.
55
- * Disabled by default — enable with DYNAMIC_MODEL_LOADING=true env var.
56
- */
57
- dynamicModelLoading?: boolean;
58
- logger?: ILogger;
59
- /**
60
- * OpenTelemetry MeterProvider to register as the global provider before
61
- * ReactorInstrumentation starts. Must be provided here rather than set
62
- * externally to guarantee the registration happens before
63
- * instrumentation.start() reads the global provider via metrics.getMeter().
64
- */
65
- meterProvider?: MeterProvider;
66
- };
67
- export type SwitchboardReactor = {
68
- defaultDriveUrl: string | undefined;
69
- reactor: IReactorClient;
70
- /** The Renown instance if identity was initialized */
71
- renown: IRenown | null;
72
- };
73
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AACvE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAE9C,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,YAAY,GAAG,QAAQ,GAAG,UAAU,GAAG,SAAS,CAAC;IACvD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,+DAA+D;IAC/D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B,6CAA6C;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,iDAAiD;IACjD,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,KAAK,CAAC,EACF;QACE,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,EAAE,MAAM,CAAC;KAClB,GACD,OAAO,GACP,SAAS,CAAC;IACd,IAAI,CAAC,EAAE;QACL,OAAO,EAAE,OAAO,CAAC;QACjB,MAAM,EAAE,MAAM,EAAE,CAAC;QACjB,KAAK,EAAE,MAAM,EAAE,CAAC;QAChB,MAAM,EAAE,MAAM,EAAE,CAAC;KAClB,CAAC;IACF;;;;OAIG;IACH,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,eAAe,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,4BAA4B,CAAC,EAAE,OAAO,CAAC;IACvC;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;;OAKG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,eAAe,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,OAAO,EAAE,cAAc,CAAC;IACxB,sDAAsD;IACtD,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC;CACxB,CAAC"}
package/dist/src/types.js DELETED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
@@ -1,5 +0,0 @@
1
- import type { IReactorClient } from "@powerhousedao/reactor";
2
- import type { DriveInput } from "@powerhousedao/shared/document-drive";
3
- export declare function addDefaultDrive(client: IReactorClient, drive: DriveInput, serverPort: number): Promise<string>;
4
- export declare function isPostgresUrl(url: string): boolean;
5
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAM7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AAGvE,wBAAsB,eAAe,CACnC,MAAM,EAAE,cAAc,EACtB,KAAK,EAAE,UAAU,EACjB,UAAU,EAAE,MAAM,mBA8DnB;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,WAExC"}
package/dist/src/utils.js DELETED
@@ -1,63 +0,0 @@
1
- import { driveCreateDocument, driveCreateState, } from "@powerhousedao/shared/document-drive";
2
- import { generateId } from "@powerhousedao/shared/document-model";
3
- export async function addDefaultDrive(client, drive, serverPort) {
4
- let driveId = drive.id;
5
- if (!driveId || driveId.length === 0) {
6
- driveId = drive.slug;
7
- }
8
- if (!driveId || driveId.length === 0) {
9
- throw new Error("Invalid Drive Id");
10
- }
11
- // check if the drive already exists
12
- let existingDrive;
13
- try {
14
- existingDrive = await client.get(driveId);
15
- }
16
- catch {
17
- //
18
- }
19
- // already exists, return the existing drive url
20
- if (existingDrive) {
21
- return `http://localhost:${serverPort}/d/${driveId}`;
22
- }
23
- const { global } = driveCreateState();
24
- const document = driveCreateDocument({
25
- global: {
26
- ...global,
27
- name: drive.global.name,
28
- icon: drive.global.icon ?? global.icon,
29
- },
30
- local: {
31
- availableOffline: drive.local?.availableOffline ?? false,
32
- sharingType: drive.local?.sharingType ?? "public",
33
- listeners: drive.local?.listeners ?? [],
34
- triggers: drive.local?.triggers ?? [],
35
- },
36
- });
37
- if (drive.id && drive.id.length > 0) {
38
- document.header.id = drive.id;
39
- }
40
- if (drive.slug && drive.slug.length > 0) {
41
- document.header.slug = drive.slug;
42
- }
43
- if (drive.global.name) {
44
- document.header.name = drive.global.name;
45
- }
46
- if (drive.preferredEditor) {
47
- document.header.meta = { preferredEditor: drive.preferredEditor };
48
- }
49
- try {
50
- await client.create(document);
51
- }
52
- catch (e) {
53
- const errorMessage = e instanceof Error ? e.message : String(e);
54
- if (!errorMessage.includes("already exists")) {
55
- throw e;
56
- }
57
- }
58
- return `http://localhost:${serverPort}/d/${driveId}`;
59
- }
60
- export function isPostgresUrl(url) {
61
- return url.startsWith("postgresql") || url.startsWith("postgres");
62
- }
63
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AAElE,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,MAAsB,EACtB,KAAiB,EACjB,UAAkB;IAElB,IAAI,OAAO,GAAG,KAAK,CAAC,EAAE,CAAC;IACvB,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrC,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC;IACvB,CAAC;IAED,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACtC,CAAC;IAED,oCAAoC;IACpC,IAAI,aAAa,CAAC;IAClB,IAAI,CAAC;QACH,aAAa,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC5C,CAAC;IAAC,MAAM,CAAC;QACP,EAAE;IACJ,CAAC;IAED,gDAAgD;IAChD,IAAI,aAAa,EAAE,CAAC;QAClB,OAAO,oBAAoB,UAAU,MAAM,OAAO,EAAE,CAAC;IACvD,CAAC;IAED,MAAM,EAAE,MAAM,EAAE,GAAG,gBAAgB,EAAE,CAAC;IACtC,MAAM,QAAQ,GAAG,mBAAmB,CAAC;QACnC,MAAM,EAAE;YACN,GAAG,MAAM;YACT,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,IAAI;YACvB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E,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,CAAC;YAC7C,MAAM,CAAC,CAAC;QACV,CAAC;IACH,CAAC;IAED,OAAO,oBAAoB,UAAU,MAAM,OAAO,EAAE,CAAC;AACvD,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,GAAW;IACvC,OAAO,GAAG,CAAC,UAAU,CAAC,YAAY,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;AACpE,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=metrics.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"metrics.test.d.ts","sourceRoot":"","sources":["../../test/metrics.test.ts"],"names":[],"mappings":""}