@powerhousedao/ph-cli 6.2.3-dev.8 → 6.2.3-dev.80

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 (162) hide show
  1. package/dist/{auth-AR3VxAIk.mjs → auth-BFUq7CvE.mjs} +3 -3
  2. package/dist/{auth-AR3VxAIk.mjs.map → auth-BFUq7CvE.mjs.map} +1 -1
  3. package/dist/auth-CNhbN5UM.mjs +4 -0
  4. package/dist/build-t5pFQx0f.mjs +304 -0
  5. package/dist/build-t5pFQx0f.mjs.map +1 -0
  6. package/dist/build-wvc_NiGr.mjs +4 -0
  7. package/dist/check-ecwBLzrg.mjs +56 -0
  8. package/dist/check-ecwBLzrg.mjs.map +1 -0
  9. package/dist/{cli-connect-override-D3hh4aH_.mjs → cli-connect-override-DW7OYAGx.mjs} +39 -27
  10. package/dist/cli-connect-override-DW7OYAGx.mjs.map +1 -0
  11. package/dist/cli.d.mts +2 -1
  12. package/dist/cli.mjs +35 -1179
  13. package/dist/cli.mjs.map +1 -1
  14. package/dist/compound-C7GuPnTP-Ba4ce2Xa.mjs +2813 -0
  15. package/dist/compound-C7GuPnTP-Ba4ce2Xa.mjs.map +1 -0
  16. package/dist/connect-build-7nmQw9c5.mjs +253 -0
  17. package/dist/connect-build-7nmQw9c5.mjs.map +1 -0
  18. package/dist/{connect-config-BWGiW3IB.mjs → connect-config-CfQwxG8G.mjs} +19 -12
  19. package/dist/connect-config-CfQwxG8G.mjs.map +1 -0
  20. package/dist/connect-plugin-configs-CXN8_KL0.mjs +50 -0
  21. package/dist/connect-plugin-configs-CXN8_KL0.mjs.map +1 -0
  22. package/dist/connect-preview-l0Car-nX.mjs +217 -0
  23. package/dist/connect-preview-l0Car-nX.mjs.map +1 -0
  24. package/dist/connect-studio-Cac3eE_U.mjs +81 -0
  25. package/dist/connect-studio-Cac3eE_U.mjs.map +1 -0
  26. package/dist/connect-studio-Cf6UZvOo.mjs +4 -0
  27. package/dist/dist-DcARVrSg.mjs +643 -0
  28. package/dist/dist-DcARVrSg.mjs.map +1 -0
  29. package/dist/explain-Rx7JW1OU.mjs +230 -0
  30. package/dist/explain-Rx7JW1OU.mjs.map +1 -0
  31. package/dist/export-ZnJeAtLS.mjs +42 -0
  32. package/dist/export-ZnJeAtLS.mjs.map +1 -0
  33. package/dist/feature-flags-xwqcHEWC.mjs +4 -0
  34. package/dist/{generate-all-DrT4ZxHX.mjs → generate-all-5Om0CB4N.mjs} +9 -3
  35. package/dist/generate-all-5Om0CB4N.mjs.map +1 -0
  36. package/dist/generate-app-hm6CJ_4O.mjs +72 -0
  37. package/dist/generate-app-hm6CJ_4O.mjs.map +1 -0
  38. package/dist/generate-desktop-shell-DzEzNspp.mjs +318 -0
  39. package/dist/generate-desktop-shell-DzEzNspp.mjs.map +1 -0
  40. package/dist/generate-document-model-CiW13Vf7.mjs +60 -0
  41. package/dist/generate-document-model-CiW13Vf7.mjs.map +1 -0
  42. package/dist/generate-editor-kTiUOmDW.mjs +64 -0
  43. package/dist/generate-editor-kTiUOmDW.mjs.map +1 -0
  44. package/dist/generate-hosts-BFmPIW2X.mjs +18 -0
  45. package/dist/generate-hosts-BFmPIW2X.mjs.map +1 -0
  46. package/dist/generate-hosts-RWj7WPHZ.mjs +4 -0
  47. package/dist/generate-migration-file-yK8uA70U.mjs +20 -0
  48. package/dist/generate-migration-file-yK8uA70U.mjs.map +1 -0
  49. package/dist/generate-piece-C6ymlErL.mjs +73 -0
  50. package/dist/generate-piece-C6ymlErL.mjs.map +1 -0
  51. package/dist/generate-piece-action-uYRdKtQA.mjs +29 -0
  52. package/dist/generate-piece-action-uYRdKtQA.mjs.map +1 -0
  53. package/dist/generate-piece-trigger-CZaDD-cc.mjs +30 -0
  54. package/dist/generate-piece-trigger-CZaDD-cc.mjs.map +1 -0
  55. package/dist/generate-processor-BVjOsfjJ.mjs +58 -0
  56. package/dist/generate-processor-BVjOsfjJ.mjs.map +1 -0
  57. package/dist/generate-subgraph-CrHbYK91.mjs +64 -0
  58. package/dist/generate-subgraph-CrHbYK91.mjs.map +1 -0
  59. package/dist/get-version-C-oL2owF.mjs +11 -0
  60. package/dist/get-version-C-oL2owF.mjs.map +1 -0
  61. package/dist/index-CJN_BRkc.d.mts +4459 -0
  62. package/dist/index-CJN_BRkc.d.mts.map +1 -0
  63. package/dist/{init-BZP6gvYd.mjs → init-Ch1rCksS.mjs} +16 -12
  64. package/dist/init-Ch1rCksS.mjs.map +1 -0
  65. package/dist/{inspect-DXjbQEV_.mjs → inspect-zWJnBDMJ.mjs} +11 -4
  66. package/dist/inspect-zWJnBDMJ.mjs.map +1 -0
  67. package/dist/install-added-dependencies-DnZFR3aE.mjs +18 -0
  68. package/dist/install-added-dependencies-DnZFR3aE.mjs.map +1 -0
  69. package/dist/mcp-DvyBEajv.mjs +262 -0
  70. package/dist/mcp-DvyBEajv.mjs.map +1 -0
  71. package/dist/member-config-0tHtiVN_.mjs +154 -0
  72. package/dist/member-config-0tHtiVN_.mjs.map +1 -0
  73. package/dist/migrate-CIJaE3iZ.mjs +177 -0
  74. package/dist/migrate-CIJaE3iZ.mjs.map +1 -0
  75. package/dist/module-dir-1avCXsBi.mjs +17 -0
  76. package/dist/module-dir-1avCXsBi.mjs.map +1 -0
  77. package/dist/offered-routes-imports-CQInWI6y.mjs +4 -0
  78. package/dist/offered-routes-imports-CalXK9dh.mjs +96 -0
  79. package/dist/offered-routes-imports-CalXK9dh.mjs.map +1 -0
  80. package/dist/ph-cli-commands-C8eWT5mr.mjs +1600 -0
  81. package/dist/ph-cli-commands-C8eWT5mr.mjs.map +1 -0
  82. package/dist/ph-cli-commands-DviLBBKz.mjs +4 -0
  83. package/dist/precompress-P6cJDPVC.mjs +77 -0
  84. package/dist/precompress-P6cJDPVC.mjs.map +1 -0
  85. package/dist/{registry-auth-DxEWCJu2.mjs → registry-auth-Bm5AR-fB.mjs} +4 -4
  86. package/dist/{registry-auth-DxEWCJu2.mjs.map → registry-auth-Bm5AR-fB.mjs.map} +1 -1
  87. package/dist/run-sugar-CRzZsmVo.mjs +39 -0
  88. package/dist/run-sugar-CRzZsmVo.mjs.map +1 -0
  89. package/dist/runners/connect.d.mts +1153 -0
  90. package/dist/runners/connect.d.mts.map +1 -0
  91. package/dist/runners/connect.mjs +300 -0
  92. package/dist/runners/connect.mjs.map +1 -0
  93. package/dist/runners/switchboard.d.mts +1481 -0
  94. package/dist/runners/switchboard.d.mts.map +1 -0
  95. package/dist/runners/switchboard.mjs +535 -0
  96. package/dist/runners/switchboard.mjs.map +1 -0
  97. package/dist/schemas-ByfuhvAb.mjs +5752 -0
  98. package/dist/schemas-ByfuhvAb.mjs.map +1 -0
  99. package/dist/scripts/emit-runner-schemas.ts +24 -0
  100. package/dist/scripts/generate-commands-docs.ts +12 -0
  101. package/dist/scripts/manage-environment +0 -0
  102. package/dist/scripts/setup.sh +0 -0
  103. package/dist/start-run-CRVBqQ8L.mjs +124 -0
  104. package/dist/start-run-CRVBqQ8L.mjs.map +1 -0
  105. package/dist/superseded-config-CbSTFun2.mjs +53 -0
  106. package/dist/superseded-config-CbSTFun2.mjs.map +1 -0
  107. package/dist/switchboard-B7mvNWcd.mjs +4 -0
  108. package/dist/switchboard-Cqs5IBNF.mjs +168 -0
  109. package/dist/switchboard-Cqs5IBNF.mjs.map +1 -0
  110. package/dist/{switchboard-migrate-NQ7LHWSi.mjs → switchboard-migrate-Docb8Cjv.mjs} +6 -5
  111. package/dist/{switchboard-migrate-NQ7LHWSi.mjs.map → switchboard-migrate-Docb8Cjv.mjs.map} +1 -1
  112. package/dist/switchboard-proxy-CGfMtENM.mjs +37 -0
  113. package/dist/switchboard-proxy-CGfMtENM.mjs.map +1 -0
  114. package/dist/{switchboard-reset-BcQXlcVf.mjs → switchboard-reset-MtTB_GAI.mjs} +8 -6
  115. package/dist/switchboard-reset-MtTB_GAI.mjs.map +1 -0
  116. package/dist/sync-connect-routes-BtAsFPXN.mjs +4 -0
  117. package/dist/sync-connect-routes-t0Slg-P6.mjs +25 -0
  118. package/dist/sync-connect-routes-t0Slg-P6.mjs.map +1 -0
  119. package/dist/{utils-C4isxXSO.mjs → utils-9KyRM0mf.mjs} +6 -34
  120. package/dist/{utils-C4isxXSO.mjs.map → utils-9KyRM0mf.mjs.map} +1 -1
  121. package/dist/utils-DAux4Ga7.mjs +4 -0
  122. package/dist/{vetra-DkF6EJMY.mjs → vetra-DZYtcHqV.mjs} +130 -147
  123. package/dist/vetra-DZYtcHqV.mjs.map +1 -0
  124. package/dist/vetra-launch-DQDZxGTV.mjs +343 -0
  125. package/dist/vetra-launch-DQDZxGTV.mjs.map +1 -0
  126. package/dist/warn-subgraph-type-conflicts-BOHBmThq.mjs +19 -0
  127. package/dist/warn-subgraph-type-conflicts-BOHBmThq.mjs.map +1 -0
  128. package/package.json +42 -18
  129. package/dist/auth-BNkN6kS9.mjs +0 -4
  130. package/dist/build-C-A5-ipO.mjs +0 -4
  131. package/dist/build-uQXq6_HU.mjs +0 -71
  132. package/dist/build-uQXq6_HU.mjs.map +0 -1
  133. package/dist/cli-connect-override-D3hh4aH_.mjs.map +0 -1
  134. package/dist/connect-build-WL4axo4z.mjs +0 -43
  135. package/dist/connect-build-WL4axo4z.mjs.map +0 -1
  136. package/dist/connect-config-BWGiW3IB.mjs.map +0 -1
  137. package/dist/connect-preview-D7ypzFDc.mjs +0 -28
  138. package/dist/connect-preview-D7ypzFDc.mjs.map +0 -1
  139. package/dist/connect-studio-BIQzyq5B.mjs +0 -5
  140. package/dist/connect-studio-D6rfWCNB.mjs +0 -31
  141. package/dist/connect-studio-D6rfWCNB.mjs.map +0 -1
  142. package/dist/generate-all-DrT4ZxHX.mjs.map +0 -1
  143. package/dist/generate-app-DNNqA-H3.mjs +0 -48
  144. package/dist/generate-app-DNNqA-H3.mjs.map +0 -1
  145. package/dist/generate-document-model-BJXyODfm.mjs +0 -34
  146. package/dist/generate-document-model-BJXyODfm.mjs.map +0 -1
  147. package/dist/generate-editor-BejvaVVT.mjs +0 -48
  148. package/dist/generate-editor-BejvaVVT.mjs.map +0 -1
  149. package/dist/generate-processor-_WOx-mMe.mjs +0 -40
  150. package/dist/generate-processor-_WOx-mMe.mjs.map +0 -1
  151. package/dist/generate-subgraph-BsHUstpl.mjs +0 -38
  152. package/dist/generate-subgraph-BsHUstpl.mjs.map +0 -1
  153. package/dist/init-BZP6gvYd.mjs.map +0 -1
  154. package/dist/inspect-DXjbQEV_.mjs.map +0 -1
  155. package/dist/migrate-jGKfE02L.mjs +0 -83
  156. package/dist/migrate-jGKfE02L.mjs.map +0 -1
  157. package/dist/switchboard-CJMoMzWx.mjs +0 -75
  158. package/dist/switchboard-CJMoMzWx.mjs.map +0 -1
  159. package/dist/switchboard-iRFugh8I.mjs +0 -4
  160. package/dist/switchboard-reset-BcQXlcVf.mjs.map +0 -1
  161. package/dist/utils-BzwczAW-.mjs +0 -4
  162. package/dist/vetra-DkF6EJMY.mjs.map +0 -1
@@ -0,0 +1,24 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { emittedRunnerSchemas } from "../src/runners/emitted-schemas.js";
5
+
6
+ /**
7
+ * Writes the runners' editor JSON Schemas into clis/ph-cli/schemas/. Run
8
+ * `pnpm --filter @powerhousedao/ph-cli emit-schemas` after changing a
9
+ * runner's hostSchema or outputsSchema; the drift test
10
+ * (test/runner-schemas-drift.test.ts) fails while the files are behind.
11
+ */
12
+ const outDir = path.join(
13
+ path.dirname(fileURLToPath(import.meta.url)),
14
+ "..",
15
+ "schemas",
16
+ );
17
+ fs.mkdirSync(outDir, { recursive: true });
18
+ for (const [file, schema] of Object.entries(emittedRunnerSchemas())) {
19
+ fs.writeFileSync(
20
+ path.join(outDir, file),
21
+ `${JSON.stringify(schema, null, 2)}\n`,
22
+ );
23
+ console.log(`emitted schemas/${file}`);
24
+ }
@@ -1,11 +1,16 @@
1
1
  import { writeCliDocsMarkdownFile } from "@powerhousedao/codegen/file-builders";
2
2
  import { accessToken } from "../src/commands/access-token.js";
3
+ import { build as buildCmd } from "../src/commands/build.js";
3
4
  import { build, connect, preview, studio } from "../src/commands/connect.js";
4
5
  import { generateAllCmd } from "../src/commands/generate-all.js";
5
6
  import { generateAppCmd } from "../src/commands/generate-app.js";
7
+ import { generateConnectRoutesCmd } from "../src/commands/generate-connect-routes.js";
6
8
  import { generateDocumentModelCmd } from "../src/commands/generate-document-model.js";
7
9
  import { generateEditorCmd } from "../src/commands/generate-editor.js";
8
10
  import { generateMigrationFileCmd } from "../src/commands/generate-migration-file.js";
11
+ import { generatePieceActionCmd } from "../src/commands/generate-piece-action.js";
12
+ import { generatePieceTriggerCmd } from "../src/commands/generate-piece-trigger.js";
13
+ import { generatePieceCmd } from "../src/commands/generate-piece.js";
9
14
  import { generateProcessorCmd } from "../src/commands/generate-processor.js";
10
15
  import { generateSubgraphCmd } from "../src/commands/generate-subgraph.js";
11
16
  import { generate } from "../src/commands/generate.js";
@@ -13,6 +18,7 @@ import { inspect } from "../src/commands/inspect.js";
13
18
  import { install } from "../src/commands/install.js";
14
19
  import { list } from "../src/commands/list.js";
15
20
  import { login } from "../src/commands/login.js";
21
+ import { mcp } from "../src/commands/mcp.js";
16
22
  import { migrate } from "../src/commands/migrate.js";
17
23
  import { phCli } from "../src/commands/ph-cli.js";
18
24
  import { switchboard } from "../src/commands/switchboard.js";
@@ -27,8 +33,13 @@ const commands = [
27
33
  { name: "app", command: generateAppCmd },
28
34
  { name: "processor", command: generateProcessorCmd },
29
35
  { name: "subgraph", command: generateSubgraphCmd },
36
+ { name: "piece", command: generatePieceCmd },
37
+ { name: "piece-action", command: generatePieceActionCmd },
38
+ { name: "piece-trigger", command: generatePieceTriggerCmd },
30
39
  { name: "migration-file", command: generateMigrationFileCmd },
40
+ { name: "connect-routes", command: generateConnectRoutesCmd },
31
41
  { name: "vetra", command: vetra },
42
+ { name: "build", command: buildCmd },
32
43
  { name: "connect", command: connect },
33
44
  { name: "connect studio", command: studio },
34
45
  { name: "connect build", command: build },
@@ -36,6 +47,7 @@ const commands = [
36
47
  { name: "access token", command: accessToken },
37
48
  { name: "inspect", command: inspect },
38
49
  { name: "list", command: list },
50
+ { name: "mcp", command: mcp },
39
51
  { name: "migrate", command: migrate },
40
52
  { name: "switchboard", command: switchboard },
41
53
  { name: "login", command: login },
File without changes
File without changes
@@ -0,0 +1,124 @@
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]="0fb86b5d-2c2e-5fb1-911f-c9a090964afc")}catch(e){}}();
3
+ import { A as loadProducers, B as processResolveEnv, E as isSchemaLike, K as resolveHostOutputs, P as outputRefsOf, S as getVerb, U as readProjectName, V as producerOutputsSchemas, W as readRunRecord, X as runRecordOutputSource, Y as resolveRunnerModule, et as toStartedHandle, it as writeRunRecord, k as loadHost, l as clearRunRecord, nt as validateDeclaredHost, r as ONE_SHOT_VERBS, rt as validateHost, z as probeRun } from "./compound-C7GuPnTP-Ba4ce2Xa.mjs";
4
+ //#region src/services/run/start-run.ts
5
+ /**
6
+ * `ph run <host> [verb]`: dispatch the verb (default `run`) of the host's
7
+ * declared runner. There is deliberately no type→runner registry — what a
8
+ * host does is written in its own file.
9
+ *
10
+ * The pipeline (typed-host-configs 3.5): declared validation (token shapes,
11
+ * `$output` paths against the producers' outputsSchemas, the runner's
12
+ * declaredHostSchema), the live-instance lock, resolution (`$output` from
13
+ * the producers' live run records, `$env` from this process, the
14
+ * `${userData}` sugar), resolved validation, then the verb with the parsed
15
+ * host. A compound runner gets its declared host: its members resolve their
16
+ * own tokens as they start.
17
+ *
18
+ * A reactor runner that exports `outputsSchema` has its handle's outputs
19
+ * published in a v2 `.ph/run/<name>.json` record once ready; this is the only
20
+ * standalone writer (mastra included). Compounds write their own record with
21
+ * the members in it; one-shot verbs (`build`) return nothing and write none.
22
+ */
23
+ async function startRun(args) {
24
+ const projectRoot = args.projectRoot ?? process.cwd();
25
+ const loaded = await loadHost(projectRoot, args.host);
26
+ const { warnSupersededConfigKeys } = await import("./superseded-config-CbSTFun2.mjs");
27
+ warnSupersededConfigKeys(projectRoot);
28
+ const specifier = loaded.host.runner.module;
29
+ const runner = await resolveRunnerModule(projectRoot, specifier);
30
+ const verb = args.verb ?? "run";
31
+ const fn = getVerb(runner, specifier, verb);
32
+ const file = loaded.file;
33
+ if (args.debug) console.log({
34
+ host: loaded.host.name,
35
+ runner: specifier,
36
+ verb
37
+ });
38
+ if (runner.kind === "compound") {
39
+ validateDeclaredHost(runner, specifier, loaded.host, file);
40
+ return fn(validateHost(runner, specifier, loaded.host, file, { tokens: "allow" }), {
41
+ projectRoot,
42
+ verb,
43
+ env: process.env
44
+ });
45
+ }
46
+ const projectName = readProjectName(projectRoot);
47
+ const producers = await loadProducers(projectRoot, outputRefsOf(loaded.host));
48
+ validateDeclaredHost(runner, specifier, loaded.host, file, { outputsSchemaOf: producerOutputsSchemas(producers) });
49
+ if (ONE_SHOT_VERBS.has(verb)) return fn(validateHost(runner, specifier, loaded.host, file, { tokens: "allow" }), {
50
+ projectRoot,
51
+ verb,
52
+ env: process.env
53
+ });
54
+ const publishes = isSchemaLike(runner.outputsSchema);
55
+ if (publishes) assertNotRunning(projectRoot, loaded.host.name, projectName);
56
+ const resolved = resolveHostOutputs(loaded.host, {
57
+ outputs: runRecordOutputSource(projectRoot, {
58
+ consumer: args.host,
59
+ producers,
60
+ projectName
61
+ }),
62
+ ...processResolveEnv(projectRoot),
63
+ where: `hosts/${args.host}/host.js`
64
+ });
65
+ const result = await fn(validateHost(runner, specifier, resolved, file), {
66
+ projectRoot,
67
+ verb,
68
+ env: process.env
69
+ });
70
+ if (publishes && result !== void 0 && result !== null) await publishOutputs(runner, result, {
71
+ projectRoot,
72
+ projectName,
73
+ hostName: loaded.host.name,
74
+ specifier,
75
+ verb
76
+ });
77
+ return result;
78
+ }
79
+ function assertNotRunning(projectRoot, hostName, projectName) {
80
+ const probe = probeRun(projectRoot, hostName, projectName);
81
+ if (probe.status === "live" && probe.record.pid !== process.pid) throw new Error(`${hostName} is already running for this project (pid ${probe.record.pid}). Stop it before starting another.`);
82
+ if (probe.status === "foreign") throw new Error(`.ph/run/${hostName}.json describes a live "${probe.record.projectName}", but this project is "${projectName}". Refusing to start a second instance.`);
83
+ }
84
+ /** Await `ready`, validate the outputs, write the v2 record and clear it on
85
+ * exit. A handle that never gets ready or reports invalid outputs is shut
86
+ * down before the error propagates. */
87
+ async function publishOutputs(runner, result, target) {
88
+ const where = `${target.specifier} ${target.verb}`;
89
+ const handle = toStartedHandle(result, where);
90
+ const name = target.projectName;
91
+ let outputs;
92
+ try {
93
+ if (!isSchemaLike(runner.outputsSchema)) return;
94
+ assertNotRunning(target.projectRoot, target.hostName, name);
95
+ if (handle.ready) await handle.ready;
96
+ const parsed = runner.outputsSchema.safeParse(handle.outputs);
97
+ if (!parsed.success) {
98
+ const issues = parsed.error.issues.map((issue) => ` - ${issue.path.map(String).join(".") || "<root>"}: ${issue.message}`).join("\n");
99
+ throw new Error(`${where} reported outputs that fail its outputsSchema:\n${issues}`);
100
+ }
101
+ outputs = parsed.data;
102
+ } catch (error) {
103
+ await handle.shutdown?.();
104
+ throw error;
105
+ }
106
+ writeRunRecord(target.projectRoot, {
107
+ version: 2,
108
+ host: target.hostName,
109
+ projectName: name,
110
+ kind: "reactor",
111
+ verb: target.verb,
112
+ pid: process.pid,
113
+ startedAt: (/* @__PURE__ */ new Date()).toISOString(),
114
+ outputs
115
+ });
116
+ process.on("exit", () => {
117
+ if (readRunRecord(target.projectRoot, target.hostName)?.pid === process.pid) clearRunRecord(target.projectRoot, target.hostName);
118
+ });
119
+ }
120
+ //#endregion
121
+ export { startRun };
122
+
123
+ //# sourceMappingURL=start-run-CRVBqQ8L.mjs.map
124
+ //# debugId=0fb86b5d-2c2e-5fb1-911f-c9a090964afc
@@ -0,0 +1 @@
1
+ {"version":3,"file":"start-run-CRVBqQ8L.mjs","sources":["../src/services/run/start-run.ts"],"sourcesContent":["import {\n clearRunRecord,\n getVerb,\n isSchemaLike,\n loadHost,\n loadProducers,\n ONE_SHOT_VERBS,\n outputRefsOf,\n probeRun,\n processResolveEnv,\n producerOutputsSchemas,\n readProjectName,\n readRunRecord,\n resolveHostOutputs,\n resolveRunnerModule,\n runRecordOutputSource,\n toStartedHandle,\n validateDeclaredHost,\n validateHost,\n writeRunRecord,\n type RunnerModule,\n} from \"@powerhousedao/host-core\";\n\nexport interface StartRunArgs {\n host: string;\n verb?: string;\n projectRoot?: string;\n debug?: boolean;\n}\n\n/**\n * `ph run <host> [verb]`: dispatch the verb (default `run`) of the host's\n * declared runner. There is deliberately no type→runner registry — what a\n * host does is written in its own file.\n *\n * The pipeline (typed-host-configs 3.5): declared validation (token shapes,\n * `$output` paths against the producers' outputsSchemas, the runner's\n * declaredHostSchema), the live-instance lock, resolution (`$output` from\n * the producers' live run records, `$env` from this process, the\n * `${userData}` sugar), resolved validation, then the verb with the parsed\n * host. A compound runner gets its declared host: its members resolve their\n * own tokens as they start.\n *\n * A reactor runner that exports `outputsSchema` has its handle's outputs\n * published in a v2 `.ph/run/<name>.json` record once ready; this is the only\n * standalone writer (mastra included). Compounds write their own record with\n * the members in it; one-shot verbs (`build`) return nothing and write none.\n */\nexport async function startRun(args: StartRunArgs): Promise<unknown> {\n const projectRoot = args.projectRoot ?? process.cwd();\n const loaded = await loadHost(projectRoot, args.host);\n const { warnSupersededConfigKeys } = await import(\"./superseded-config.js\");\n warnSupersededConfigKeys(projectRoot);\n const specifier = loaded.host.runner.module;\n const runner = await resolveRunnerModule(projectRoot, specifier);\n const verb = args.verb ?? \"run\";\n const fn = getVerb(runner, specifier, verb);\n const file = loaded.file;\n if (args.debug) {\n console.log({ host: loaded.host.name, runner: specifier, verb });\n }\n\n if (runner.kind === \"compound\") {\n validateDeclaredHost(runner, specifier, loaded.host, file);\n const host = validateHost(runner, specifier, loaded.host, file, {\n tokens: \"allow\",\n });\n return fn(host, { projectRoot, verb, env: process.env });\n }\n\n const projectName = readProjectName(projectRoot);\n const producers = await loadProducers(projectRoot, outputRefsOf(loaded.host));\n validateDeclaredHost(runner, specifier, loaded.host, file, {\n outputsSchemaOf: producerOutputsSchemas(producers),\n });\n const oneShot = ONE_SHOT_VERBS.has(verb);\n if (oneShot) {\n // `build` reads no other host's outputs: no producer needs to run.\n const host = validateHost(runner, specifier, loaded.host, file, {\n tokens: \"allow\",\n });\n return fn(host, { projectRoot, verb, env: process.env });\n }\n const publishes = isSchemaLike(runner.outputsSchema);\n // Before the verb starts anything: a second live instance would take\n // over the first one's record (and clear it on exit).\n if (publishes) assertNotRunning(projectRoot, loaded.host.name, projectName);\n const resolved = resolveHostOutputs(loaded.host, {\n outputs: runRecordOutputSource(projectRoot, {\n consumer: args.host,\n producers,\n projectName,\n }),\n ...processResolveEnv(projectRoot),\n where: `hosts/${args.host}/host.js`,\n });\n const host = validateHost(runner, specifier, resolved, file);\n const result = await fn(host, { projectRoot, verb, env: process.env });\n if (publishes && result !== undefined && result !== null) {\n await publishOutputs(runner, result, {\n projectRoot,\n projectName,\n hostName: loaded.host.name,\n specifier,\n verb,\n });\n }\n return result;\n}\n\nfunction assertNotRunning(\n projectRoot: string,\n hostName: string,\n projectName: string,\n): void {\n const probe = probeRun(projectRoot, hostName, projectName);\n if (probe.status === \"live\" && probe.record.pid !== process.pid) {\n throw new Error(\n `${hostName} is already running for this project (pid ${probe.record.pid}). Stop it before starting another.`,\n );\n }\n if (probe.status === \"foreign\") {\n throw new Error(\n `.ph/run/${hostName}.json describes a live \"${probe.record.projectName}\", but this project is \"${projectName}\". Refusing to start a second instance.`,\n );\n }\n}\n\ninterface PublishTarget {\n projectRoot: string;\n projectName: string;\n hostName: string;\n specifier: string;\n verb: string;\n}\n\n/** Await `ready`, validate the outputs, write the v2 record and clear it on\n * exit. A handle that never gets ready or reports invalid outputs is shut\n * down before the error propagates. */\nasync function publishOutputs(\n runner: RunnerModule,\n result: unknown,\n target: PublishTarget,\n): Promise<void> {\n const where = `${target.specifier} ${target.verb}`;\n const handle = toStartedHandle(result, where);\n const name = target.projectName;\n let outputs: unknown;\n try {\n if (!isSchemaLike(runner.outputsSchema)) return;\n // Checked again after the start: an instance that started meanwhile.\n assertNotRunning(target.projectRoot, target.hostName, name);\n if (handle.ready) await handle.ready;\n const parsed = runner.outputsSchema.safeParse(handle.outputs);\n if (!parsed.success) {\n const issues = parsed.error.issues\n .map(\n (issue) =>\n ` - ${issue.path.map(String).join(\".\") || \"<root>\"}: ${issue.message}`,\n )\n .join(\"\\n\");\n throw new Error(\n `${where} reported outputs that fail its outputsSchema:\\n${issues}`,\n );\n }\n outputs = parsed.data;\n } catch (error) {\n await handle.shutdown?.();\n throw error;\n }\n\n writeRunRecord(target.projectRoot, {\n version: 2,\n host: target.hostName,\n projectName: name,\n kind: \"reactor\",\n verb: target.verb,\n pid: process.pid,\n startedAt: new Date().toISOString(),\n outputs: outputs as Record<string, unknown>,\n });\n // No SIGINT/SIGTERM handler: the switchboard reactor's own handler kills\n // the reactor before draining the api, and a parallel shutdown() would\n // break that order. Without an exit event the record keeps a dead pid,\n // which probeRun reports as stale.\n process.on(\"exit\", () => {\n if (readRunRecord(target.projectRoot, target.hostName)?.pid === process.pid)\n clearRunRecord(target.projectRoot, target.hostName);\n });\n}\n"],"names":[],"mappings":"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","debug_id":"0fb86b5d-2c2e-5fb1-911f-c9a090964afc"}
@@ -0,0 +1,53 @@
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]="a89eb2bb-5f68-5a41-b391-a58da5f3c101")}catch(e){}}();
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+ //#region src/services/run/superseded-config.ts
6
+ /**
7
+ * P2.7 — the fixed legacy→hosts mapping table. With hosts/ active, these
8
+ * powerhouse.config.json keys are superseded by host.js structure and the run
9
+ * path ignores them; each present key warns ONCE per run, naming its new home.
10
+ *
11
+ * Keys the scaffolded host files REFERENCE (studio.port, reactor.port,
12
+ * vetra.connectPort, assistant.port, and the WHOLE connect.* block — handed to the runtime
13
+ * unchanged, connect.instance.* included) are expected to remain and are
14
+ * deliberately absent from this table.
15
+ */
16
+ const SUPERSEDED = {
17
+ "studio.host": "hosts/connect/host.js → runner.host",
18
+ "studio.https": "hosts/connect/host.js → runner.https",
19
+ "studio.openBrowser": "hosts/connect/host.js → runner.openBrowser",
20
+ "reactor.https": "hosts/switchboard/host.js → runner.https",
21
+ "reactor.storage": "hosts/switchboard/host.js → reactor.backends.<name>.storage",
22
+ "switchboard.database.url": "hosts/switchboard/host.js → reactor.backends.<name>.storage.url"
23
+ };
24
+ function lookup(config, dottedKey) {
25
+ let cursor = config;
26
+ for (const part of dottedKey.split(".")) {
27
+ if (cursor === null || typeof cursor !== "object") return void 0;
28
+ cursor = cursor[part];
29
+ }
30
+ return cursor;
31
+ }
32
+ /** Warn once per run for each superseded key present in the project config.
33
+ * Returns the warned keys (for tests). Never throws — a malformed config is
34
+ * the loader's problem, not the warner's. */
35
+ function warnSupersededConfigKeys(projectRoot, warn = console.warn) {
36
+ let config;
37
+ try {
38
+ config = JSON.parse(fs.readFileSync(path.join(projectRoot, "powerhouse.config.json"), "utf8"));
39
+ } catch {
40
+ return [];
41
+ }
42
+ const warned = [];
43
+ for (const [key, newHome] of Object.entries(SUPERSEDED)) if (lookup(config, key) !== void 0) {
44
+ warned.push(key);
45
+ warn(`[ph run] powerhouse.config.json "${key}" is ignored in hosts projects — its home is now ${newHome}.`);
46
+ }
47
+ return warned;
48
+ }
49
+ //#endregion
50
+ export { warnSupersededConfigKeys };
51
+
52
+ //# sourceMappingURL=superseded-config-CbSTFun2.mjs.map
53
+ //# debugId=a89eb2bb-5f68-5a41-b391-a58da5f3c101
@@ -0,0 +1 @@
1
+ {"version":3,"file":"superseded-config-CbSTFun2.mjs","sources":["../src/services/run/superseded-config.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\n\n/**\n * P2.7 — the fixed legacy→hosts mapping table. With hosts/ active, these\n * powerhouse.config.json keys are superseded by host.js structure and the run\n * path ignores them; each present key warns ONCE per run, naming its new home.\n *\n * Keys the scaffolded host files REFERENCE (studio.port, reactor.port,\n * vetra.connectPort, assistant.port, and the WHOLE connect.* block — handed to the runtime\n * unchanged, connect.instance.* included) are expected to remain and are\n * deliberately absent from this table.\n */\nconst SUPERSEDED: Record<string, string> = {\n \"studio.host\": \"hosts/connect/host.js → runner.host\",\n \"studio.https\": \"hosts/connect/host.js → runner.https\",\n \"studio.openBrowser\": \"hosts/connect/host.js → runner.openBrowser\",\n \"reactor.https\": \"hosts/switchboard/host.js → runner.https\",\n \"reactor.storage\":\n \"hosts/switchboard/host.js → reactor.backends.<name>.storage\",\n \"switchboard.database.url\":\n \"hosts/switchboard/host.js → reactor.backends.<name>.storage.url\",\n};\n\nfunction lookup(config: unknown, dottedKey: string): unknown {\n let cursor: unknown = config;\n for (const part of dottedKey.split(\".\")) {\n if (cursor === null || typeof cursor !== \"object\") return undefined;\n cursor = (cursor as Record<string, unknown>)[part];\n }\n return cursor;\n}\n\n/** Warn once per run for each superseded key present in the project config.\n * Returns the warned keys (for tests). Never throws — a malformed config is\n * the loader's problem, not the warner's. */\nexport function warnSupersededConfigKeys(\n projectRoot: string,\n warn: (message: string) => void = console.warn,\n): string[] {\n let config: unknown;\n try {\n config = JSON.parse(\n fs.readFileSync(path.join(projectRoot, \"powerhouse.config.json\"), \"utf8\"),\n );\n } catch {\n return [];\n }\n const warned: string[] = [];\n for (const [key, newHome] of Object.entries(SUPERSEDED)) {\n if (lookup(config, key) !== undefined) {\n warned.push(key);\n warn(\n `[ph run] powerhouse.config.json \"${key}\" is ignored in hosts projects — ` +\n `its home is now ${newHome}.`,\n );\n }\n }\n return warned;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAaA,MAAM,aAAqC;CACzC,eAAe;CACf,gBAAgB;CAChB,sBAAsB;CACtB,iBAAiB;CACjB,mBACE;CACF,4BACE;AACJ;AAEA,SAAS,OAAO,QAAiB,WAA4B;CAC3D,IAAI,SAAkB;CACtB,KAAK,MAAM,QAAQ,UAAU,MAAM,GAAG,GAAG;EACvC,IAAI,WAAW,QAAQ,OAAO,WAAW,UAAU,OAAO,KAAA;EAC1D,SAAU,OAAmC;CAC/C;CACA,OAAO;AACT;;;;AAKA,SAAgB,yBACd,aACA,OAAkC,QAAQ,MAChC;CACV,IAAI;CACJ,IAAI;EACF,SAAS,KAAK,MACZ,GAAG,aAAa,KAAK,KAAK,aAAa,wBAAwB,GAAG,MAAM,CAC1E;CACF,QAAQ;EACN,OAAO,CAAC;CACV;CACA,MAAM,SAAmB,CAAC;CAC1B,KAAK,MAAM,CAAC,KAAK,YAAY,OAAO,QAAQ,UAAU,GACpD,IAAI,OAAO,QAAQ,GAAG,MAAM,KAAA,GAAW;EACrC,OAAO,KAAK,GAAG;EACf,KACE,oCAAoC,IAAI,mDACnB,QAAQ,EAC/B;CACF;CAEF,OAAO;AACT","debug_id":"a89eb2bb-5f68-5a41-b391-a58da5f3c101"}
@@ -0,0 +1,4 @@
1
+ import { r as startSwitchboard } from "./switchboard-Cqs5IBNF.mjs";
2
+ export { startSwitchboard };
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]="0f071f3c-57d5-537d-9129-953e376e9ad6")}catch(e){}}();
4
+ //# debugId=0f071f3c-57d5-537d-9129-953e376e9ad6
@@ -0,0 +1,168 @@
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]="9a25cda9-d04e-52e6-af7b-d687ed748199")}catch(e){}}();
3
+ import { DEFAULT_DRIVE_ICON } from "@powerhousedao/shared/clis";
4
+ import { callerOverEnv } from "@powerhousedao/switchboard/config";
5
+ import { switchboardConfigFromEnv } from "@powerhousedao/switchboard/config/env";
6
+ import { initSwitchboardProcess, startSwitchboard } from "@powerhousedao/switchboard/server";
7
+ //#region src/utils/drive-icons.ts
8
+ /**
9
+ * Icon for the drives ph-cli creates, inlined as a data URI.
10
+ *
11
+ * This used to be an IPFS URL on a private gateway, which now answers 403 -
12
+ * and a drive stores its icon as a plain URL in document state, so the moment
13
+ * that URL rots every client renders a broken image, for as long as the drive
14
+ * exists. A public gateway would only move the problem: IPFS gateways are
15
+ * frequently overloaded, and a drive icon must not depend on the network at
16
+ * all.
17
+ *
18
+ * A data URI keeps the asset inside this package and inside the drive: no
19
+ * fetch, no gateway, no deploy-base or cross-origin question, and nothing to
20
+ * 404. A few hundred bytes - the size of the string below is the entire cost,
21
+ * paid once in the drive's state.
22
+ *
23
+ * Kept URL-encoded rather than base64 so the markup stays readable and
24
+ * reviewable (`#` must be `%23`; `<`, `>`, `"` and the CSS braces are legal
25
+ * enough in a data URI but are encoded so the value is also safe to paste
26
+ * into markup).
27
+ */
28
+ /** Encodes an SVG for use in a `data:` URI, smaller than base64 and readable. */
29
+ function svgDataUri(svg) {
30
+ return `data:image/svg+xml,${svg.replace(/\s+/g, " ").trim().replace(/%/g, "%25").replace(/#/g, "%23").replace(/</g, "%3C").replace(/>/g, "%3E").replace(/"/g, "%22").replace(/\{/g, "%7B").replace(/\}/g, "%7D")}`;
31
+ }
32
+ const PETALS = [
33
+ "M0 4.6C0 2.1 2.1 0 4.6 0h21.2c2.5 0 4.6 2.1 4.6 4.6v2.8c0 12.7-10.3 23-23 23H4.6C2.1 30.4 0 28.4 0 25.8V4.6Z",
34
+ "M33.6 56.6c0-12.7 10.3-23 23-23h2.8c2.5 0 4.6 2.1 4.6 4.6v21.2c0 2.5-2.1 4.6-4.6 4.6H38.2c-2.5 0-4.6-2.1-4.6-4.6v-2.8Z",
35
+ "M0 38.2c0-2.5 2.1-4.6 4.6-4.6h2.8c12.7 0 23 10.3 23 23v2.8c0 2.5-2.1 4.6-4.6 4.6H4.6C2.1 64 0 61.9 0 59.4V38.2Z",
36
+ "M33.6 4.6C33.6 2.1 35.6 0 38.2 0h21.2C61.9 0 64 2.1 64 4.6v21.2c0 2.5-2.1 4.6-4.6 4.6h-2.8c-12.7 0-23-10.3-23-23V4.6Z"
37
+ ];
38
+ /** Icon for the drives ph-cli creates. */
39
+ const POWERHOUSE_DRIVE_ICON = svgDataUri(`
40
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="32" height="32">
41
+ <style>
42
+ path { fill: #404345 }
43
+ @media (prefers-color-scheme: dark) { path { fill: #F3F5F7 } }
44
+ </style>
45
+ <path d="${PETALS[0]}"/>
46
+ <path d="${PETALS[1]}"/>
47
+ <path d="${PETALS[2]}"/>
48
+ <path d="${PETALS[3]}"/>
49
+ </svg>`);
50
+ //#endregion
51
+ //#region src/services/switchboard.ts
52
+ const EGRESS_ALLOW_ENV = "PH_WORKFLOWS_EGRESS_ALLOW_ADDRESSES";
53
+ const LOCALHOST_ADDRESSES = ["127.0.0.1/32", "::1/128"];
54
+ function allowLocalhostEgress(env = process.env) {
55
+ const current = (env[EGRESS_ALLOW_ENV] ?? "").split(",").map((entry) => entry.trim()).filter((entry) => entry !== "");
56
+ const missing = LOCALHOST_ADDRESSES.filter((address) => !current.includes(address));
57
+ if (missing.length > 0) env[EGRESS_ALLOW_ENV] = [...current, ...missing].join(",");
58
+ }
59
+ const defaultSwitchboardOptions = {
60
+ port: 4001,
61
+ drive: {
62
+ id: "powerhouse",
63
+ slug: "powerhouse",
64
+ global: {
65
+ name: "Powerhouse",
66
+ icon: DEFAULT_DRIVE_ICON
67
+ },
68
+ local: {
69
+ availableOffline: true,
70
+ listeners: [],
71
+ sharingType: "public",
72
+ triggers: []
73
+ }
74
+ },
75
+ mcp: true
76
+ };
77
+ function getDefaultVetraSwitchboardOptions(vetraDriveId) {
78
+ return {
79
+ port: 4001,
80
+ drive: {
81
+ id: vetraDriveId,
82
+ slug: vetraDriveId,
83
+ global: {
84
+ name: "Vetra",
85
+ icon: POWERHOUSE_DRIVE_ICON
86
+ },
87
+ preferredEditor: "vetra-drive-app",
88
+ local: {
89
+ availableOffline: true,
90
+ listeners: [],
91
+ sharingType: "public",
92
+ triggers: []
93
+ }
94
+ }
95
+ };
96
+ }
97
+ async function startSwitchboard$1(options, logger, base) {
98
+ const { config, finalOptions } = switchboardConfigOf(options, logger, base);
99
+ initSwitchboardProcess(config);
100
+ return await startSwitchboard(config, {
101
+ logger,
102
+ pluginComposition: finalOptions.pluginComposition,
103
+ signalHandlers: finalOptions.signalHandlers,
104
+ fatalErrorShutdown: true
105
+ });
106
+ }
107
+ /** The server config a start runs with: the command's options over `base`. */
108
+ function switchboardConfigOf(options, logger, base) {
109
+ const { packages: packagesString, remoteDrives, useVetraDrive, vetraDriveId, useIdentity, keypairPath, requireIdentity, basePath, ...serverOptions } = options;
110
+ if (useVetraDrive || serverOptions.dev) allowLocalhostEgress();
111
+ const defaultOptions = useVetraDrive ? getDefaultVetraSwitchboardOptions(vetraDriveId) : defaultSwitchboardOptions;
112
+ const identity = useIdentity || keypairPath || requireIdentity ? {
113
+ keypairPath,
114
+ requireExisting: requireIdentity
115
+ } : void 0;
116
+ const packages = packagesString?.split(",");
117
+ const finalOptions = remoteDrives.length > 0 ? {
118
+ ...defaultOptions,
119
+ drive: void 0,
120
+ ...serverOptions,
121
+ remoteDrives,
122
+ identity,
123
+ packages,
124
+ logger
125
+ } : {
126
+ ...defaultOptions,
127
+ ...serverOptions,
128
+ remoteDrives,
129
+ identity,
130
+ packages,
131
+ logger
132
+ };
133
+ return {
134
+ config: callerOverEnv(base ?? switchboardConfigFromEnv(process.env, { logger }), configLayerOf(finalOptions, basePath)),
135
+ finalOptions
136
+ };
137
+ }
138
+ /** The keys of the server's options view this command sets, as a config layer. */
139
+ function configLayerOf(options, basePath) {
140
+ const dbPath = options.dbPath || void 0;
141
+ return {
142
+ server: {
143
+ basePath: basePath || void 0,
144
+ port: options.port,
145
+ strictPort: options.strictPort,
146
+ dev: options.dev,
147
+ https: options.https
148
+ },
149
+ storage: {
150
+ readModel: { url: dbPath },
151
+ reactor: { url: dbPath }
152
+ },
153
+ features: { mcp: options.mcp },
154
+ packages: {
155
+ list: options.packages,
156
+ disableLocal: options.disableLocalPackages
157
+ },
158
+ identity: options.identity,
159
+ drive: options.drive,
160
+ remoteDrives: options.remoteDrives,
161
+ processorConfig: options.processorConfig
162
+ };
163
+ }
164
+ //#endregion
165
+ export { POWERHOUSE_DRIVE_ICON as a, switchboardConfigOf as i, defaultSwitchboardOptions as n, startSwitchboard$1 as r, allowLocalhostEgress as t };
166
+
167
+ //# sourceMappingURL=switchboard-Cqs5IBNF.mjs.map
168
+ //# debugId=9a25cda9-d04e-52e6-af7b-d687ed748199
@@ -0,0 +1 @@
1
+ {"version":3,"file":"switchboard-Cqs5IBNF.mjs","sources":["../src/utils/drive-icons.ts","../src/services/switchboard.ts"],"sourcesContent":["/**\n * Icon for the drives ph-cli creates, inlined as a data URI.\n *\n * This used to be an IPFS URL on a private gateway, which now answers 403 -\n * and a drive stores its icon as a plain URL in document state, so the moment\n * that URL rots every client renders a broken image, for as long as the drive\n * exists. A public gateway would only move the problem: IPFS gateways are\n * frequently overloaded, and a drive icon must not depend on the network at\n * all.\n *\n * A data URI keeps the asset inside this package and inside the drive: no\n * fetch, no gateway, no deploy-base or cross-origin question, and nothing to\n * 404. A few hundred bytes - the size of the string below is the entire cost,\n * paid once in the drive's state.\n *\n * Kept URL-encoded rather than base64 so the markup stays readable and\n * reviewable (`#` must be `%23`; `<`, `>`, `\"` and the CSS braces are legal\n * enough in a data URI but are encoded so the value is also safe to paste\n * into markup).\n */\n\n/** Encodes an SVG for use in a `data:` URI, smaller than base64 and readable. */\nfunction svgDataUri(svg: string): string {\n const compact = svg.replace(/\\s+/g, \" \").trim();\n return `data:image/svg+xml,${compact\n .replace(/%/g, \"%25\")\n .replace(/#/g, \"%23\")\n .replace(/</g, \"%3C\")\n .replace(/>/g, \"%3E\")\n .replace(/\"/g, \"%22\")\n .replace(/\\{/g, \"%7B\")\n .replace(/\\}/g, \"%7D\")}`;\n}\n\n// The Powerhouse mark: four petals on a 64 grid, each a square with one\n// quarter-circle bite taken out of its inner corner.\nconst PETALS = [\n \"M0 4.6C0 2.1 2.1 0 4.6 0h21.2c2.5 0 4.6 2.1 4.6 4.6v2.8c0 12.7-10.3 23-23 23H4.6C2.1 30.4 0 28.4 0 25.8V4.6Z\",\n \"M33.6 56.6c0-12.7 10.3-23 23-23h2.8c2.5 0 4.6 2.1 4.6 4.6v21.2c0 2.5-2.1 4.6-4.6 4.6H38.2c-2.5 0-4.6-2.1-4.6-4.6v-2.8Z\",\n \"M0 38.2c0-2.5 2.1-4.6 4.6-4.6h2.8c12.7 0 23 10.3 23 23v2.8c0 2.5-2.1 4.6-4.6 4.6H4.6C2.1 64 0 61.9 0 59.4V38.2Z\",\n \"M33.6 4.6C33.6 2.1 35.6 0 38.2 0h21.2C61.9 0 64 2.1 64 4.6v21.2c0 2.5-2.1 4.6-4.6 4.6h-2.8c-12.7 0-23-10.3-23-23V4.6Z\",\n];\n\n/** The mark in the light theme's grey. */\nconst LIGHT_FILL = \"#404345\";\n\n/** The mark in the dark theme's grey. */\nconst DARK_FILL = \"#F3F5F7\";\n\n// Drawn in one grey that follows the theme, so the icon sits in the sidebar\n// beside the single-tone `currentcolor` glyphs of the other drives instead of\n// competing with them.\n//\n// A data URI rendered through an `<img>` is its own document and cannot see\n// the host page's `.dark` class, so the theme is read from the embedded\n// document's own color scheme. That is the OS preference by default; the\n// renderer propagates an explicit in-app theme choice by setting\n// `color-scheme` on the `<img>`, which overrides it where the browser\n// supports the propagation.\nconst MARK_SVG = `\n<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 64 64\" width=\"32\" height=\"32\">\n <style>\n path { fill: ${LIGHT_FILL} }\n @media (prefers-color-scheme: dark) { path { fill: ${DARK_FILL} } }\n </style>\n <path d=\"${PETALS[0]}\"/>\n <path d=\"${PETALS[1]}\"/>\n <path d=\"${PETALS[2]}\"/>\n <path d=\"${PETALS[3]}\"/>\n</svg>`;\n\n/** Icon for the drives ph-cli creates. */\nexport const POWERHOUSE_DRIVE_ICON = svgDataUri(MARK_SVG);\n","import type { ResolvedPlugin } from \"@powerhousedao/host-core\";\nimport { DEFAULT_DRIVE_ICON } from \"@powerhousedao/shared/clis\";\nimport {\n callerOverEnv,\n type SwitchboardConfigInput,\n} from \"@powerhousedao/switchboard/config\";\nimport { switchboardConfigFromEnv } from \"@powerhousedao/switchboard/config/env\";\nimport {\n initSwitchboardProcess,\n startSwitchboard as startSwitchboardServer,\n type IdentityOptions,\n type StartServerOptions,\n} from \"@powerhousedao/switchboard/server\";\nimport type { ILogger } from \"document-model\";\nimport type { SwitchboardArgs } from \"../types.js\";\nimport { POWERHOUSE_DRIVE_ICON } from \"../utils/drive-icons.js\";\n\nconst EGRESS_ALLOW_ENV = \"PH_WORKFLOWS_EGRESS_ALLOW_ADDRESSES\";\nconst LOCALHOST_ADDRESSES = [\"127.0.0.1/32\", \"::1/128\"];\n\n// Lets pieces reach services on this machine, keeping any addresses already set\nexport function allowLocalhostEgress(env: NodeJS.ProcessEnv = process.env) {\n const current = (env[EGRESS_ALLOW_ENV] ?? \"\")\n .split(\",\")\n .map((entry) => entry.trim())\n .filter((entry) => entry !== \"\");\n const missing = LOCALHOST_ADDRESSES.filter(\n (address) => !current.includes(address),\n );\n if (missing.length > 0)\n env[EGRESS_ALLOW_ENV] = [...current, ...missing].join(\",\");\n}\n\n// No `dbPath` default here: the classic commands always carry the parsed\n// `dbPath` key (undefined without --db-path) and so always overrode it — the\n// server's own split defaults (`.ph/reactor-storage` for the reactor,\n// `.ph/read-storage` for the read model) are the legacy layout. A default\n// here resurfaces for any caller that omits the key and then names ONE dir\n// for both PGlite stores (two writers on one PGDATA).\nexport const defaultSwitchboardOptions = {\n port: 4001,\n drive: {\n id: \"powerhouse\",\n slug: \"powerhouse\",\n global: {\n name: \"Powerhouse\",\n icon: DEFAULT_DRIVE_ICON,\n },\n local: {\n availableOffline: true,\n listeners: [],\n sharingType: \"public\",\n triggers: [],\n },\n },\n mcp: true,\n} satisfies StartServerOptions;\n\nfunction getDefaultVetraSwitchboardOptions(\n vetraDriveId: string,\n): Partial<StartServerOptions> {\n return {\n port: 4001,\n drive: {\n id: vetraDriveId,\n slug: vetraDriveId,\n global: {\n name: \"Vetra\",\n icon: POWERHOUSE_DRIVE_ICON,\n },\n preferredEditor: \"vetra-drive-app\",\n local: {\n availableOffline: true,\n listeners: [],\n sharingType: \"public\",\n triggers: [],\n },\n },\n };\n}\n\nexport type StartSwitchboardOptions = Omit<SwitchboardArgs, \"mcp\"> & {\n /** A declared composition (R2) leaves this unset: the mcp plugin's presence sets it. */\n mcp?: boolean;\n /** `undefined` suppresses the default drive (declared drives replace it). */\n drive?: StartServerOptions[\"drive\"];\n strictPort?: boolean;\n processorConfig?: Map<string, unknown>;\n /** False under a supervising compound, which owns SIGINT/SIGTERM. */\n signalHandlers?: boolean;\n /** A declared composition (R2), resolved by the runner. */\n pluginComposition?: ResolvedPlugin[];\n};\n\nexport async function startSwitchboard(\n options: StartSwitchboardOptions,\n logger?: ILogger,\n /** The layer under the command's options; default: this process's env. */\n base?: SwitchboardConfigInput,\n) {\n const { config, finalOptions } = switchboardConfigOf(options, logger, base);\n initSwitchboardProcess(config);\n const reactor = await startSwitchboardServer(config, {\n logger,\n pluginComposition: finalOptions.pluginComposition,\n signalHandlers: finalOptions.signalHandlers,\n fatalErrorShutdown: true,\n });\n\n return reactor;\n}\n\n/** The server config a start runs with: the command's options over `base`. */\nexport function switchboardConfigOf(\n options: StartSwitchboardOptions,\n logger?: ILogger,\n base?: SwitchboardConfigInput,\n): {\n config: SwitchboardConfigInput;\n finalOptions: StartServerOptions;\n} {\n const {\n packages: packagesString,\n remoteDrives,\n useVetraDrive,\n vetraDriveId,\n useIdentity,\n keypairPath,\n requireIdentity,\n basePath,\n ...serverOptions\n } = options;\n\n // Vetra and dev mode run against local services\n if (useVetraDrive || serverOptions.dev) allowLocalhostEgress();\n\n // Choose the appropriate default configuration\n const defaultOptions = useVetraDrive\n ? getDefaultVetraSwitchboardOptions(vetraDriveId)\n : defaultSwitchboardOptions;\n\n // Build identity options if enabled\n const identity: IdentityOptions | undefined =\n useIdentity || keypairPath || requireIdentity\n ? {\n keypairPath,\n requireExisting: requireIdentity,\n }\n : undefined;\n\n const packages = packagesString?.split(\",\");\n\n // Only include the default drive if no remote drives are provided\n const finalOptions =\n remoteDrives.length > 0\n ? {\n ...defaultOptions,\n drive: undefined, // Don't create default drive when syncing with remote\n ...serverOptions,\n remoteDrives,\n identity,\n packages,\n logger,\n }\n : {\n ...defaultOptions,\n ...serverOptions,\n remoteDrives,\n identity,\n packages,\n logger,\n };\n\n // The env (or the caller's base) under the command's own options.\n const config = callerOverEnv(\n base ?? switchboardConfigFromEnv(process.env, { logger }),\n configLayerOf(finalOptions, basePath),\n );\n return { config, finalOptions };\n}\n\n/** The keys of the server's options view this command sets, as a config layer. */\nfunction configLayerOf(\n options: StartServerOptions,\n basePath: string | undefined,\n): SwitchboardConfigInput {\n const dbPath = options.dbPath || undefined;\n return {\n server: {\n basePath: basePath || undefined,\n port: options.port,\n strictPort: options.strictPort,\n dev: options.dev,\n https: options.https,\n },\n storage: {\n // `dbPath` names both stores, over the env, as it did as an option.\n readModel: { url: dbPath },\n reactor: { url: dbPath },\n },\n features: { mcp: options.mcp },\n packages: {\n list: options.packages,\n disableLocal: options.disableLocalPackages,\n },\n identity: options.identity,\n drive: options.drive,\n remoteDrives: options.remoteDrives,\n processorConfig: options.processorConfig,\n };\n}\n"],"names":["startSwitchboard","startSwitchboardServer"],"mappings":"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","debug_id":"9a25cda9-d04e-52e6-af7b-d687ed748199"}
@@ -1,8 +1,8 @@
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]="9ca57982-bee9-5f08-aa81-5fb5a7ca8324")}catch(e){}}();
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="ff779d1d-972c-53db-a71e-946208cc05bd")}catch(e){}}();
3
+ import { REACTOR_SCHEMA, getMigrationStatus, runMigrations } from "@powerhousedao/reactor";
3
4
  import { Kysely, PostgresDialect } from "kysely";
4
5
  import { Pool } from "pg";
5
- import { REACTOR_SCHEMA, getMigrationStatus, runMigrations } from "@powerhousedao/reactor";
6
6
  //#region src/services/switchboard-migrate.ts
7
7
  function isPostgresUrl(url) {
8
8
  return url.startsWith("postgresql://") || url.startsWith("postgres://");
@@ -15,7 +15,8 @@ async function runSwitchboardMigrations(options) {
15
15
  return;
16
16
  }
17
17
  console.log(`Database: ${dbPath}`);
18
- const db = new Kysely({ dialect: new PostgresDialect({ pool: new Pool({ connectionString: dbPath }) }) });
18
+ const pool = new Pool({ connectionString: dbPath });
19
+ const db = new Kysely({ dialect: new PostgresDialect({ pool }) });
19
20
  try {
20
21
  if (options.statusOnly) {
21
22
  console.log("\nChecking migration status...");
@@ -49,5 +50,5 @@ async function runSwitchboardMigrations(options) {
49
50
  //#endregion
50
51
  export { runSwitchboardMigrations };
51
52
 
52
- //# sourceMappingURL=switchboard-migrate-NQ7LHWSi.mjs.map
53
- //# debugId=9ca57982-bee9-5f08-aa81-5fb5a7ca8324
53
+ //# sourceMappingURL=switchboard-migrate-Docb8Cjv.mjs.map
54
+ //# debugId=ff779d1d-972c-53db-a71e-946208cc05bd
@@ -1 +1 @@
1
- {"version":3,"file":"switchboard-migrate-NQ7LHWSi.mjs","sources":["../src/services/switchboard-migrate.ts"],"sourcesContent":["import { Kysely, PostgresDialect } from \"kysely\";\nimport { Pool } from \"pg\";\nimport {\n runMigrations,\n getMigrationStatus,\n REACTOR_SCHEMA,\n} from \"@powerhousedao/reactor\";\n\ninterface MigrationOptions {\n dbPath?: string;\n statusOnly?: boolean;\n}\n\nfunction isPostgresUrl(url: string): boolean {\n return url.startsWith(\"postgresql://\") || url.startsWith(\"postgres://\");\n}\n\nexport async function runSwitchboardMigrations(\n options: MigrationOptions,\n): Promise<void> {\n const dbPath =\n options.dbPath ??\n process.env.PH_REACTOR_DATABASE_URL ??\n process.env.DATABASE_URL;\n\n if (!dbPath || !isPostgresUrl(dbPath)) {\n console.log(\"No PostgreSQL URL configured. Skipping migrations.\");\n console.log(\"(PGlite migrations are handled automatically on startup)\");\n return;\n }\n\n console.log(`Database: ${dbPath}`);\n\n const pool = new Pool({ connectionString: dbPath });\n\n const db = new Kysely<any>({\n dialect: new PostgresDialect({ pool }),\n });\n\n try {\n if (options.statusOnly) {\n console.log(\"\\nChecking migration status...\");\n const migrations = await getMigrationStatus(db, REACTOR_SCHEMA);\n\n console.log(\"\\nMigration Status:\");\n console.log(\"=================\");\n\n for (const migration of migrations) {\n const status = migration.executedAt\n ? `[OK] Executed at ${migration.executedAt.toISOString()}`\n : \"[--] Pending\";\n console.log(`${status} - ${migration.name}`);\n }\n } else {\n console.log(\"\\nRunning migrations...\");\n const result = await runMigrations(db, REACTOR_SCHEMA);\n\n if (!result.success) {\n console.error(\"Migration failed:\", result.error?.message);\n process.exit(1);\n }\n\n if (result.migrationsExecuted.length === 0) {\n console.log(\"No migrations to run - database is up to date\");\n } else {\n console.log(\n `Successfully executed ${result.migrationsExecuted.length} migration(s):`,\n );\n for (const name of result.migrationsExecuted) {\n console.log(` - ${name}`);\n }\n }\n }\n } catch (error) {\n console.error(\n \"Error:\",\n error instanceof Error ? error.message : String(error),\n );\n process.exit(1);\n } finally {\n await db.destroy();\n }\n}\n"],"names":[],"mappings":";;;;;;AAaA,SAAS,cAAc,KAAsB;AAC3C,QAAO,IAAI,WAAW,gBAAgB,IAAI,IAAI,WAAW,cAAc;;AAGzE,eAAsB,yBACpB,SACe;CACf,MAAM,SACJ,QAAQ,UACR,QAAQ,IAAI,2BACZ,QAAQ,IAAI;AAEd,KAAI,CAAC,UAAU,CAAC,cAAc,OAAO,EAAE;AACrC,UAAQ,IAAI,qDAAqD;AACjE,UAAQ,IAAI,2DAA2D;AACvE;;AAGF,SAAQ,IAAI,aAAa,SAAS;CAIlC,MAAM,KAAK,IAAI,OAAY,EACzB,SAAS,IAAI,gBAAgB,EAAE,MAHpB,IAAI,KAAK,EAAE,kBAAkB,QAAQ,CAAC,EAGZ,CAAC,EACvC,CAAC;AAEF,KAAI;AACF,MAAI,QAAQ,YAAY;AACtB,WAAQ,IAAI,iCAAiC;GAC7C,MAAM,aAAa,MAAM,mBAAmB,IAAI,eAAe;AAE/D,WAAQ,IAAI,sBAAsB;AAClC,WAAQ,IAAI,oBAAoB;AAEhC,QAAK,MAAM,aAAa,YAAY;IAClC,MAAM,SAAS,UAAU,aACrB,oBAAoB,UAAU,WAAW,aAAa,KACtD;AACJ,YAAQ,IAAI,GAAG,OAAO,KAAK,UAAU,OAAO;;SAEzC;AACL,WAAQ,IAAI,0BAA0B;GACtC,MAAM,SAAS,MAAM,cAAc,IAAI,eAAe;AAEtD,OAAI,CAAC,OAAO,SAAS;AACnB,YAAQ,MAAM,qBAAqB,OAAO,OAAO,QAAQ;AACzD,YAAQ,KAAK,EAAE;;AAGjB,OAAI,OAAO,mBAAmB,WAAW,EACvC,SAAQ,IAAI,gDAAgD;QACvD;AACL,YAAQ,IACN,yBAAyB,OAAO,mBAAmB,OAAO,gBAC3D;AACD,SAAK,MAAM,QAAQ,OAAO,mBACxB,SAAQ,IAAI,OAAO,OAAO;;;UAIzB,OAAO;AACd,UAAQ,MACN,UACA,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,CACvD;AACD,UAAQ,KAAK,EAAE;WACP;AACR,QAAM,GAAG,SAAS","debug_id":"9ca57982-bee9-5f08-aa81-5fb5a7ca8324"}
1
+ {"version":3,"file":"switchboard-migrate-Docb8Cjv.mjs","sources":["../src/services/switchboard-migrate.ts"],"sourcesContent":["import { Kysely, PostgresDialect } from \"kysely\";\nimport { Pool } from \"pg\";\nimport {\n runMigrations,\n getMigrationStatus,\n REACTOR_SCHEMA,\n} from \"@powerhousedao/reactor\";\n\ninterface MigrationOptions {\n dbPath?: string;\n statusOnly?: boolean;\n}\n\nfunction isPostgresUrl(url: string): boolean {\n return url.startsWith(\"postgresql://\") || url.startsWith(\"postgres://\");\n}\n\nexport async function runSwitchboardMigrations(\n options: MigrationOptions,\n): Promise<void> {\n const dbPath =\n options.dbPath ??\n process.env.PH_REACTOR_DATABASE_URL ??\n process.env.DATABASE_URL;\n\n if (!dbPath || !isPostgresUrl(dbPath)) {\n console.log(\"No PostgreSQL URL configured. Skipping migrations.\");\n console.log(\"(PGlite migrations are handled automatically on startup)\");\n return;\n }\n\n console.log(`Database: ${dbPath}`);\n\n const pool = new Pool({ connectionString: dbPath });\n\n const db = new Kysely<any>({\n dialect: new PostgresDialect({ pool }),\n });\n\n try {\n if (options.statusOnly) {\n console.log(\"\\nChecking migration status...\");\n const migrations = await getMigrationStatus(db, REACTOR_SCHEMA);\n\n console.log(\"\\nMigration Status:\");\n console.log(\"=================\");\n\n for (const migration of migrations) {\n const status = migration.executedAt\n ? `[OK] Executed at ${migration.executedAt.toISOString()}`\n : \"[--] Pending\";\n console.log(`${status} - ${migration.name}`);\n }\n } else {\n console.log(\"\\nRunning migrations...\");\n const result = await runMigrations(db, REACTOR_SCHEMA);\n\n if (!result.success) {\n console.error(\"Migration failed:\", result.error?.message);\n process.exit(1);\n }\n\n if (result.migrationsExecuted.length === 0) {\n console.log(\"No migrations to run - database is up to date\");\n } else {\n console.log(\n `Successfully executed ${result.migrationsExecuted.length} migration(s):`,\n );\n for (const name of result.migrationsExecuted) {\n console.log(` - ${name}`);\n }\n }\n }\n } catch (error) {\n console.error(\n \"Error:\",\n error instanceof Error ? error.message : String(error),\n );\n process.exit(1);\n } finally {\n await db.destroy();\n }\n}\n"],"names":[],"mappings":";;;;;;AAaA,SAAS,cAAc,KAAsB;CAC3C,OAAO,IAAI,WAAW,eAAe,KAAK,IAAI,WAAW,aAAa;AACxE;AAEA,eAAsB,yBACpB,SACe;CACf,MAAM,SACJ,QAAQ,UACR,QAAQ,IAAI,2BACZ,QAAQ,IAAI;CAEd,IAAI,CAAC,UAAU,CAAC,cAAc,MAAM,GAAG;EACrC,QAAQ,IAAI,oDAAoD;EAChE,QAAQ,IAAI,0DAA0D;EACtE;CACF;CAEA,QAAQ,IAAI,aAAa,QAAQ;CAEjC,MAAM,OAAO,IAAI,KAAK,EAAE,kBAAkB,OAAO,CAAC;CAElD,MAAM,KAAK,IAAI,OAAY,EACzB,SAAS,IAAI,gBAAgB,EAAE,KAAK,CAAC,EACvC,CAAC;CAED,IAAI;EACF,IAAI,QAAQ,YAAY;GACtB,QAAQ,IAAI,gCAAgC;GAC5C,MAAM,aAAa,MAAM,mBAAmB,IAAI,cAAc;GAE9D,QAAQ,IAAI,qBAAqB;GACjC,QAAQ,IAAI,mBAAmB;GAE/B,KAAK,MAAM,aAAa,YAAY;IAClC,MAAM,SAAS,UAAU,aACrB,oBAAoB,UAAU,WAAW,YAAY,MACrD;IACJ,QAAQ,IAAI,GAAG,OAAO,KAAK,UAAU,MAAM;GAC7C;EACF,OAAO;GACL,QAAQ,IAAI,yBAAyB;GACrC,MAAM,SAAS,MAAM,cAAc,IAAI,cAAc;GAErD,IAAI,CAAC,OAAO,SAAS;IACnB,QAAQ,MAAM,qBAAqB,OAAO,OAAO,OAAO;IACxD,QAAQ,KAAK,CAAC;GAChB;GAEA,IAAI,OAAO,mBAAmB,WAAW,GACvC,QAAQ,IAAI,+CAA+C;QACtD;IACL,QAAQ,IACN,yBAAyB,OAAO,mBAAmB,OAAO,eAC5D;IACA,KAAK,MAAM,QAAQ,OAAO,oBACxB,QAAQ,IAAI,OAAO,MAAM;GAE7B;EACF;CACF,SAAS,OAAO;EACd,QAAQ,MACN,UACA,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CACvD;EACA,QAAQ,KAAK,CAAC;CAChB,UAAU;EACR,MAAM,GAAG,QAAQ;CACnB;AACF","debug_id":"ff779d1d-972c-53db-a71e-946208cc05bd"}
@@ -0,0 +1,37 @@
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]="c5e3cd62-660a-5978-8304-6ea0c3f41894")}catch(e){}}();
3
+ import { SWITCHBOARD_PROXY_PATHS, isHtmlNavigation } from "@powerhousedao/shared/connect/origin-placeholder";
4
+ //#region src/utils/switchboard-proxy.ts
5
+ /**
6
+ * Vite proxy rules (dev and preview servers alike) that send the
7
+ * switchboard's paths to `target`, so a browser on Connect's origin reaches
8
+ * the switchboard through it and the served config can name the switchboard
9
+ * as `${origin}` (runner.proxy on the connect host).
10
+ *
11
+ * `/d/<drive>` is both a switchboard endpoint and one of Connect's own
12
+ * routes: a browser navigation there (it accepts HTML) is left to Connect,
13
+ * every other request on the path goes to the switchboard. GraphQL carries
14
+ * the subscriptions websocket, so that rule upgrades too. The Host header
15
+ * is left as the browser sent it: the switchboard builds the URLs it hands
16
+ * out from it, and on the page's origin is where they must point.
17
+ */
18
+ function switchboardProxy(target) {
19
+ const origin = new URL(target).origin;
20
+ const rules = {};
21
+ for (const prefix of SWITCHBOARD_PROXY_PATHS) {
22
+ const key = prefix.endsWith("/") ? `^${escape(prefix)}` : `^${escape(prefix)}(/|$)`;
23
+ rules[key] = {
24
+ target: origin,
25
+ changeOrigin: false,
26
+ ...prefix === "/graphql" ? { ws: true } : {},
27
+ ...prefix === "/d/" ? { bypass: (req) => isHtmlNavigation(req.headers.accept) ? req.url : void 0 } : {}
28
+ };
29
+ }
30
+ return rules;
31
+ }
32
+ const escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
33
+ //#endregion
34
+ export { switchboardProxy as t };
35
+
36
+ //# sourceMappingURL=switchboard-proxy-CGfMtENM.mjs.map
37
+ //# debugId=c5e3cd62-660a-5978-8304-6ea0c3f41894
@@ -0,0 +1 @@
1
+ {"version":3,"file":"switchboard-proxy-CGfMtENM.mjs","sources":["../src/utils/switchboard-proxy.ts"],"sourcesContent":["import {\n isHtmlNavigation,\n SWITCHBOARD_PROXY_PATHS,\n} from \"@powerhousedao/shared/connect/origin-placeholder\";\nimport type { ProxyOptions } from \"vite\";\n\n/**\n * Vite proxy rules (dev and preview servers alike) that send the\n * switchboard's paths to `target`, so a browser on Connect's origin reaches\n * the switchboard through it and the served config can name the switchboard\n * as `${origin}` (runner.proxy on the connect host).\n *\n * `/d/<drive>` is both a switchboard endpoint and one of Connect's own\n * routes: a browser navigation there (it accepts HTML) is left to Connect,\n * every other request on the path goes to the switchboard. GraphQL carries\n * the subscriptions websocket, so that rule upgrades too. The Host header\n * is left as the browser sent it: the switchboard builds the URLs it hands\n * out from it, and on the page's origin is where they must point.\n */\nexport function switchboardProxy(target: string): Record<string, ProxyOptions> {\n const origin = new URL(target).origin;\n const rules: Record<string, ProxyOptions> = {};\n for (const prefix of SWITCHBOARD_PROXY_PATHS) {\n const key = prefix.endsWith(\"/\")\n ? `^${escape(prefix)}`\n : `^${escape(prefix)}(/|$)`;\n rules[key] = {\n target: origin,\n changeOrigin: false,\n ...(prefix === \"/graphql\" ? { ws: true } : {}),\n ...(prefix === \"/d/\"\n ? {\n bypass: (req) =>\n isHtmlNavigation(req.headers.accept) ? req.url : undefined,\n }\n : {}),\n };\n }\n return rules;\n}\n\nconst escape = (s: string) => s.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAmBA,SAAgB,iBAAiB,QAA8C;CAC7E,MAAM,SAAS,IAAI,IAAI,MAAM,CAAC,CAAC;CAC/B,MAAM,QAAsC,CAAC;CAC7C,KAAK,MAAM,UAAU,yBAAyB;EAC5C,MAAM,MAAM,OAAO,SAAS,GAAG,IAC3B,IAAI,OAAO,MAAM,MACjB,IAAI,OAAO,MAAM,EAAE;EACvB,MAAM,OAAO;GACX,QAAQ;GACR,cAAc;GACd,GAAI,WAAW,aAAa,EAAE,IAAI,KAAK,IAAI,CAAC;GAC5C,GAAI,WAAW,QACX,EACE,SAAS,QACP,iBAAiB,IAAI,QAAQ,MAAM,IAAI,IAAI,MAAM,KAAA,EACrD,IACA,CAAC;EACP;CACF;CACA,OAAO;AACT;AAEA,MAAM,UAAU,MAAc,EAAE,QAAQ,uBAAuB,MAAM","debug_id":"c5e3cd62-660a-5978-8304-6ea0c3f41894"}
@@ -1,7 +1,8 @@
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]="6dc443d3-91f6-5215-973e-7898511565eb")}catch(e){}}();
3
- import { cyan, green, red, yellow } from "colorette";
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]="44d0c080-10cc-5316-947d-b0281777aade")}catch(e){}}();
4
3
  import { promises } from "node:fs";
4
+ import { cyan, green, red, yellow } from "colorette";
5
+ import { defaultStoreDirs } from "@powerhousedao/shared/clis/ph-dir";
5
6
  //#region src/services/switchboard-reset.ts
6
7
  const CONFIRMATION_TOKEN = "reset";
7
8
  function isPostgresUrl(url) {
@@ -18,10 +19,11 @@ function isInteractive() {
18
19
  * caller can refuse.
19
20
  */
20
21
  function resolveResetPaths(options, env = process.env) {
22
+ const defaults = defaultStoreDirs(env);
21
23
  const readModelDbPath = options.dbPath ?? env.DATABASE_URL ?? env.PH_SWITCHBOARD_DATABASE_URL;
22
- const readModelPath = readModelDbPath || ".ph/read-storage";
24
+ const readModelPath = readModelDbPath || defaults.readModel;
23
25
  const reactorDbUrl = options.dbPath ?? env.PH_REACTOR_DATABASE_URL ?? env.PH_SWITCHBOARD_DATABASE_URL;
24
- const reactorPath = reactorDbUrl || "./.ph/reactor-storage";
26
+ const reactorPath = reactorDbUrl || defaults.reactor;
25
27
  const reactorIsPostgres = !!reactorDbUrl && isPostgresUrl(reactorDbUrl);
26
28
  const readModelIsPostgres = !!readModelDbPath && isPostgresUrl(readModelDbPath);
27
29
  let postgresUrl = null;
@@ -83,5 +85,5 @@ async function resetSwitchboardDatabase(options) {
83
85
  //#endregion
84
86
  export { resetSwitchboardDatabase };
85
87
 
86
- //# sourceMappingURL=switchboard-reset-BcQXlcVf.mjs.map
87
- //# debugId=6dc443d3-91f6-5215-973e-7898511565eb
88
+ //# sourceMappingURL=switchboard-reset-MtTB_GAI.mjs.map
89
+ //# debugId=44d0c080-10cc-5316-947d-b0281777aade