@powerhousedao/ph-cli 6.2.3-dev.7 → 6.2.3-dev.71
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{auth-AR3VxAIk.mjs → auth-BFUq7CvE.mjs} +3 -3
- package/dist/{auth-AR3VxAIk.mjs.map → auth-BFUq7CvE.mjs.map} +1 -1
- package/dist/auth-CNhbN5UM.mjs +4 -0
- package/dist/build-C78yPntL.mjs +4 -0
- package/dist/build-Dj8qfSSe.mjs +349 -0
- package/dist/build-Dj8qfSSe.mjs.map +1 -0
- package/dist/{cli-connect-override-D3hh4aH_.mjs → cli-connect-override-CEJhQWRX.mjs} +39 -27
- package/dist/cli-connect-override-CEJhQWRX.mjs.map +1 -0
- package/dist/cli.d.mts +2 -1
- package/dist/cli.mjs +31 -1175
- package/dist/cli.mjs.map +1 -1
- package/dist/compound-B6RZMA0Y-Cv3XMQ3Y.mjs +2459 -0
- package/dist/compound-B6RZMA0Y-Cv3XMQ3Y.mjs.map +1 -0
- package/dist/connect-build-BfhOGbha.mjs +253 -0
- package/dist/connect-build-BfhOGbha.mjs.map +1 -0
- package/dist/{connect-config-BWGiW3IB.mjs → connect-config-DblqJgxR.mjs} +19 -12
- package/dist/connect-config-DblqJgxR.mjs.map +1 -0
- package/dist/connect-plugin-configs-D2fwYpMw.mjs +50 -0
- package/dist/connect-plugin-configs-D2fwYpMw.mjs.map +1 -0
- package/dist/connect-preview-8-qLgWKt.mjs +215 -0
- package/dist/connect-preview-8-qLgWKt.mjs.map +1 -0
- package/dist/{connect-studio-D6rfWCNB.mjs → connect-studio-DX7r4iyI.mjs} +18 -11
- package/dist/connect-studio-DX7r4iyI.mjs.map +1 -0
- package/dist/connect-studio-DmjcV8I2.mjs +4 -0
- package/dist/dist-CCLkwpTS.mjs +313 -0
- package/dist/dist-CCLkwpTS.mjs.map +1 -0
- package/dist/explain-DUXbB9jf.mjs +241 -0
- package/dist/explain-DUXbB9jf.mjs.map +1 -0
- package/dist/feature-flags-xwqcHEWC.mjs +4 -0
- package/dist/{generate-all-DrT4ZxHX.mjs → generate-all-Dgyy_kT-.mjs} +9 -3
- package/dist/generate-all-Dgyy_kT-.mjs.map +1 -0
- package/dist/{generate-app-DNNqA-H3.mjs → generate-app-BTs1u-9l.mjs} +7 -5
- package/dist/{generate-app-DNNqA-H3.mjs.map → generate-app-BTs1u-9l.mjs.map} +1 -1
- package/dist/generate-desktop-shell-Bj_3bJDL.mjs +317 -0
- package/dist/generate-desktop-shell-Bj_3bJDL.mjs.map +1 -0
- package/dist/{generate-document-model-BJXyODfm.mjs → generate-document-model-BfFIQ35q.mjs} +19 -7
- package/dist/generate-document-model-BfFIQ35q.mjs.map +1 -0
- package/dist/{generate-editor-BejvaVVT.mjs → generate-editor-CW7Do69u.mjs} +7 -5
- package/dist/{generate-editor-BejvaVVT.mjs.map → generate-editor-CW7Do69u.mjs.map} +1 -1
- package/dist/generate-hosts-BFmPIW2X.mjs +18 -0
- package/dist/generate-hosts-BFmPIW2X.mjs.map +1 -0
- package/dist/generate-hosts-RWj7WPHZ.mjs +4 -0
- package/dist/generate-piece-QTt-ddt2.mjs +65 -0
- package/dist/generate-piece-QTt-ddt2.mjs.map +1 -0
- package/dist/generate-piece-action-DbxrzfKY.mjs +29 -0
- package/dist/generate-piece-action-DbxrzfKY.mjs.map +1 -0
- package/dist/generate-piece-trigger-CqVOcL9g.mjs +30 -0
- package/dist/generate-piece-trigger-CqVOcL9g.mjs.map +1 -0
- package/dist/{generate-processor-_WOx-mMe.mjs → generate-processor-DBtTkgo5.mjs} +15 -8
- package/dist/generate-processor-DBtTkgo5.mjs.map +1 -0
- package/dist/{generate-subgraph-BsHUstpl.mjs → generate-subgraph-CVlTo7qk.mjs} +12 -6
- package/dist/generate-subgraph-CVlTo7qk.mjs.map +1 -0
- package/dist/index-BIbx17vt.d.mts +4459 -0
- package/dist/index-BIbx17vt.d.mts.map +1 -0
- package/dist/{init-BZP6gvYd.mjs → init-ScuT3z7P.mjs} +7 -5
- package/dist/init-ScuT3z7P.mjs.map +1 -0
- package/dist/{inspect-DXjbQEV_.mjs → inspect-zWJnBDMJ.mjs} +11 -4
- package/dist/inspect-zWJnBDMJ.mjs.map +1 -0
- package/dist/install-added-dependencies-DVSbzler.mjs +33 -0
- package/dist/install-added-dependencies-DVSbzler.mjs.map +1 -0
- package/dist/{migrate-jGKfE02L.mjs → migrate-DK4HK7Dn.mjs} +4 -4
- package/dist/{migrate-jGKfE02L.mjs.map → migrate-DK4HK7Dn.mjs.map} +1 -1
- package/dist/ph-cli-commands-BhzvcuzR.mjs +4 -0
- package/dist/ph-cli-commands-pyxDifSE.mjs +1493 -0
- package/dist/ph-cli-commands-pyxDifSE.mjs.map +1 -0
- package/dist/precompress-P6cJDPVC.mjs +77 -0
- package/dist/precompress-P6cJDPVC.mjs.map +1 -0
- package/dist/{registry-auth-DxEWCJu2.mjs → registry-auth-Bm5AR-fB.mjs} +4 -4
- package/dist/{registry-auth-DxEWCJu2.mjs.map → registry-auth-Bm5AR-fB.mjs.map} +1 -1
- package/dist/run-sugar-Ns53R6lU.mjs +39 -0
- package/dist/run-sugar-Ns53R6lU.mjs.map +1 -0
- package/dist/runners/connect.d.mts +1173 -0
- package/dist/runners/connect.d.mts.map +1 -0
- package/dist/runners/connect.mjs +270 -0
- package/dist/runners/connect.mjs.map +1 -0
- package/dist/runners/switchboard.d.mts +340 -0
- package/dist/runners/switchboard.d.mts.map +1 -0
- package/dist/runners/switchboard.mjs +294 -0
- package/dist/runners/switchboard.mjs.map +1 -0
- package/dist/schemas-D5N5U_Mf.mjs +5738 -0
- package/dist/schemas-D5N5U_Mf.mjs.map +1 -0
- package/dist/scripts/emit-runner-schemas.ts +24 -0
- package/dist/scripts/generate-commands-docs.ts +8 -0
- package/dist/scripts/manage-environment +0 -0
- package/dist/scripts/setup.sh +0 -0
- package/dist/start-run-BIaYSpHh.mjs +124 -0
- package/dist/start-run-BIaYSpHh.mjs.map +1 -0
- package/dist/superseded-config-CbSTFun2.mjs +53 -0
- package/dist/superseded-config-CbSTFun2.mjs.map +1 -0
- package/dist/switchboard-C5zgkRl2.mjs +4 -0
- package/dist/switchboard-h4-XgP1h.mjs +129 -0
- package/dist/switchboard-h4-XgP1h.mjs.map +1 -0
- package/dist/{switchboard-migrate-NQ7LHWSi.mjs → switchboard-migrate-7JQZM7-5.mjs} +5 -4
- package/dist/{switchboard-migrate-NQ7LHWSi.mjs.map → switchboard-migrate-7JQZM7-5.mjs.map} +1 -1
- package/dist/{switchboard-reset-BcQXlcVf.mjs → switchboard-reset-MtTB_GAI.mjs} +8 -6
- package/dist/switchboard-reset-MtTB_GAI.mjs.map +1 -0
- package/dist/{utils-C4isxXSO.mjs → utils-9KyRM0mf.mjs} +6 -34
- package/dist/{utils-C4isxXSO.mjs.map → utils-9KyRM0mf.mjs.map} +1 -1
- package/dist/utils-DAux4Ga7.mjs +4 -0
- package/dist/{vetra-DkF6EJMY.mjs → vetra-CnrGDPX0.mjs} +70 -35
- package/dist/vetra-CnrGDPX0.mjs.map +1 -0
- package/dist/warn-subgraph-type-conflicts-BOHBmThq.mjs +19 -0
- package/dist/warn-subgraph-type-conflicts-BOHBmThq.mjs.map +1 -0
- package/package.json +39 -18
- package/dist/auth-BNkN6kS9.mjs +0 -4
- package/dist/build-C-A5-ipO.mjs +0 -4
- package/dist/build-uQXq6_HU.mjs +0 -71
- package/dist/build-uQXq6_HU.mjs.map +0 -1
- package/dist/cli-connect-override-D3hh4aH_.mjs.map +0 -1
- package/dist/connect-build-WL4axo4z.mjs +0 -43
- package/dist/connect-build-WL4axo4z.mjs.map +0 -1
- package/dist/connect-config-BWGiW3IB.mjs.map +0 -1
- package/dist/connect-preview-D7ypzFDc.mjs +0 -28
- package/dist/connect-preview-D7ypzFDc.mjs.map +0 -1
- package/dist/connect-studio-BIQzyq5B.mjs +0 -5
- package/dist/connect-studio-D6rfWCNB.mjs.map +0 -1
- package/dist/generate-all-DrT4ZxHX.mjs.map +0 -1
- package/dist/generate-document-model-BJXyODfm.mjs.map +0 -1
- package/dist/generate-processor-_WOx-mMe.mjs.map +0 -1
- package/dist/generate-subgraph-BsHUstpl.mjs.map +0 -1
- package/dist/init-BZP6gvYd.mjs.map +0 -1
- package/dist/inspect-DXjbQEV_.mjs.map +0 -1
- package/dist/switchboard-CJMoMzWx.mjs +0 -75
- package/dist/switchboard-CJMoMzWx.mjs.map +0 -1
- package/dist/switchboard-iRFugh8I.mjs +0 -4
- package/dist/switchboard-reset-BcQXlcVf.mjs.map +0 -1
- package/dist/utils-BzwczAW-.mjs +0 -4
- 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,15 @@
|
|
|
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";
|
|
6
7
|
import { generateDocumentModelCmd } from "../src/commands/generate-document-model.js";
|
|
7
8
|
import { generateEditorCmd } from "../src/commands/generate-editor.js";
|
|
8
9
|
import { generateMigrationFileCmd } from "../src/commands/generate-migration-file.js";
|
|
10
|
+
import { generatePieceActionCmd } from "../src/commands/generate-piece-action.js";
|
|
11
|
+
import { generatePieceTriggerCmd } from "../src/commands/generate-piece-trigger.js";
|
|
12
|
+
import { generatePieceCmd } from "../src/commands/generate-piece.js";
|
|
9
13
|
import { generateProcessorCmd } from "../src/commands/generate-processor.js";
|
|
10
14
|
import { generateSubgraphCmd } from "../src/commands/generate-subgraph.js";
|
|
11
15
|
import { generate } from "../src/commands/generate.js";
|
|
@@ -27,8 +31,12 @@ const commands = [
|
|
|
27
31
|
{ name: "app", command: generateAppCmd },
|
|
28
32
|
{ name: "processor", command: generateProcessorCmd },
|
|
29
33
|
{ name: "subgraph", command: generateSubgraphCmd },
|
|
34
|
+
{ name: "piece", command: generatePieceCmd },
|
|
35
|
+
{ name: "piece-action", command: generatePieceActionCmd },
|
|
36
|
+
{ name: "piece-trigger", command: generatePieceTriggerCmd },
|
|
30
37
|
{ name: "migration-file", command: generateMigrationFileCmd },
|
|
31
38
|
{ name: "vetra", command: vetra },
|
|
39
|
+
{ name: "build", command: buildCmd },
|
|
32
40
|
{ name: "connect", command: connect },
|
|
33
41
|
{ name: "connect studio", command: studio },
|
|
34
42
|
{ name: "connect build", command: build },
|
|
File without changes
|
package/dist/scripts/setup.sh
CHANGED
|
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]="9f2cd400-8719-5008-b948-dce162fc9198")}catch(e){}}();
|
|
3
|
+
import { A as readProjectName, B as validateDeclaredHost, D as processResolveEnv, E as probeRun, H as writeRunRecord, I as resolveRunnerModule, L as runRecordOutputSource, N as resolveHostOutputs, O as producerOutputsSchemas, S as outputRefsOf, V as validateHost, g as isSchemaLike, h as getVerb, i as clearRunRecord, j as readRunRecord, n as ONE_SHOT_VERBS, v as loadHost, y as loadProducers, z as toStartedHandle } from "./compound-B6RZMA0Y-Cv3XMQ3Y.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-BIaYSpHh.mjs.map
|
|
124
|
+
//# debugId=9f2cd400-8719-5008-b948-dce162fc9198
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"start-run-BIaYSpHh.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":";;;;;;;;;;;;;;;;;;;;;;AAgDA,eAAsB,SAAS,MAAsC;CACnE,MAAM,cAAc,KAAK,eAAe,QAAQ,IAAI;CACpD,MAAM,SAAS,MAAM,SAAS,aAAa,KAAK,IAAI;CACpD,MAAM,EAAE,6BAA6B,MAAM,OAAO;CAClD,yBAAyB,WAAW;CACpC,MAAM,YAAY,OAAO,KAAK,OAAO;CACrC,MAAM,SAAS,MAAM,oBAAoB,aAAa,SAAS;CAC/D,MAAM,OAAO,KAAK,QAAQ;CAC1B,MAAM,KAAK,QAAQ,QAAQ,WAAW,IAAI;CAC1C,MAAM,OAAO,OAAO;CACpB,IAAI,KAAK,OACP,QAAQ,IAAI;EAAE,MAAM,OAAO,KAAK;EAAM,QAAQ;EAAW;CAAK,CAAC;CAGjE,IAAI,OAAO,SAAS,YAAY;EAC9B,qBAAqB,QAAQ,WAAW,OAAO,MAAM,IAAI;EAIzD,OAAO,GAHM,aAAa,QAAQ,WAAW,OAAO,MAAM,MAAM,EAC9D,QAAQ,QACV,CACa,GAAG;GAAE;GAAa;GAAM,KAAK,QAAQ;EAAI,CAAC;CACzD;CAEA,MAAM,cAAc,gBAAgB,WAAW;CAC/C,MAAM,YAAY,MAAM,cAAc,aAAa,aAAa,OAAO,IAAI,CAAC;CAC5E,qBAAqB,QAAQ,WAAW,OAAO,MAAM,MAAM,EACzD,iBAAiB,uBAAuB,SAAS,EACnD,CAAC;CAED,IADgB,eAAe,IAAI,IACzB,GAKR,OAAO,GAHM,aAAa,QAAQ,WAAW,OAAO,MAAM,MAAM,EAC9D,QAAQ,QACV,CACa,GAAG;EAAE;EAAa;EAAM,KAAK,QAAQ;CAAI,CAAC;CAEzD,MAAM,YAAY,aAAa,OAAO,aAAa;CAGnD,IAAI,WAAW,iBAAiB,aAAa,OAAO,KAAK,MAAM,WAAW;CAC1E,MAAM,WAAW,mBAAmB,OAAO,MAAM;EAC/C,SAAS,sBAAsB,aAAa;GAC1C,UAAU,KAAK;GACf;GACA;EACF,CAAC;EACD,GAAG,kBAAkB,WAAW;EAChC,OAAO,SAAS,KAAK,KAAK;CAC5B,CAAC;CAED,MAAM,SAAS,MAAM,GADR,aAAa,QAAQ,WAAW,UAAU,IAC5B,GAAG;EAAE;EAAa;EAAM,KAAK,QAAQ;CAAI,CAAC;CACrE,IAAI,aAAa,WAAW,KAAA,KAAa,WAAW,MAClD,MAAM,eAAe,QAAQ,QAAQ;EACnC;EACA;EACA,UAAU,OAAO,KAAK;EACtB;EACA;CACF,CAAC;CAEH,OAAO;AACT;AAEA,SAAS,iBACP,aACA,UACA,aACM;CACN,MAAM,QAAQ,SAAS,aAAa,UAAU,WAAW;CACzD,IAAI,MAAM,WAAW,UAAU,MAAM,OAAO,QAAQ,QAAQ,KAC1D,MAAM,IAAI,MACR,GAAG,SAAS,4CAA4C,MAAM,OAAO,IAAI,oCAC3E;CAEF,IAAI,MAAM,WAAW,WACnB,MAAM,IAAI,MACR,WAAW,SAAS,0BAA0B,MAAM,OAAO,YAAY,0BAA0B,YAAY,wCAC/G;AAEJ;;;;AAaA,eAAe,eACb,QACA,QACA,QACe;CACf,MAAM,QAAQ,GAAG,OAAO,UAAU,GAAG,OAAO;CAC5C,MAAM,SAAS,gBAAgB,QAAQ,KAAK;CAC5C,MAAM,OAAO,OAAO;CACpB,IAAI;CACJ,IAAI;EACF,IAAI,CAAC,aAAa,OAAO,aAAa,GAAG;EAEzC,iBAAiB,OAAO,aAAa,OAAO,UAAU,IAAI;EAC1D,IAAI,OAAO,OAAO,MAAM,OAAO;EAC/B,MAAM,SAAS,OAAO,cAAc,UAAU,OAAO,OAAO;EAC5D,IAAI,CAAC,OAAO,SAAS;GACnB,MAAM,SAAS,OAAO,MAAM,OACzB,KACE,UACC,OAAO,MAAM,KAAK,IAAI,MAAM,CAAC,CAAC,KAAK,GAAG,KAAK,SAAS,IAAI,MAAM,SAClE,CAAC,CACA,KAAK,IAAI;GACZ,MAAM,IAAI,MACR,GAAG,MAAM,kDAAkD,QAC7D;EACF;EACA,UAAU,OAAO;CACnB,SAAS,OAAO;EACd,MAAM,OAAO,WAAW;EACxB,MAAM;CACR;CAEA,eAAe,OAAO,aAAa;EACjC,SAAS;EACT,MAAM,OAAO;EACb,aAAa;EACb,MAAM;EACN,MAAM,OAAO;EACb,KAAK,QAAQ;EACb,4BAAW,IAAI,KAAK,EAAA,CAAE,YAAY;EACzB;CACX,CAAC;CAKD,QAAQ,GAAG,cAAc;EACvB,IAAI,cAAc,OAAO,aAAa,OAAO,QAAQ,CAAC,EAAE,QAAQ,QAAQ,KACtE,eAAe,OAAO,aAAa,OAAO,QAAQ;CACtD,CAAC;AACH","debug_id":"9f2cd400-8719-5008-b948-dce162fc9198"}
|
|
@@ -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-h4-XgP1h.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]="bbd84a3f-e32a-5edc-b543-3e3bee0152b8")}catch(e){}}();
|
|
4
|
+
//# debugId=bbd84a3f-e32a-5edc-b543-3e3bee0152b8
|
|
@@ -0,0 +1,129 @@
|
|
|
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]="a2511075-368d-5847-9534-acca5aa8a4e3")}catch(e){}}();
|
|
3
|
+
import { DEFAULT_DRIVE_ICON } from "@powerhousedao/shared/clis";
|
|
4
|
+
import { startSwitchboard } from "@powerhousedao/switchboard/server";
|
|
5
|
+
//#region src/utils/drive-icons.ts
|
|
6
|
+
/**
|
|
7
|
+
* Icon for the drives ph-cli creates, inlined as a data URI.
|
|
8
|
+
*
|
|
9
|
+
* This used to be an IPFS URL on a private gateway, which now answers 403 -
|
|
10
|
+
* and a drive stores its icon as a plain URL in document state, so the moment
|
|
11
|
+
* that URL rots every client renders a broken image, for as long as the drive
|
|
12
|
+
* exists. A public gateway would only move the problem: IPFS gateways are
|
|
13
|
+
* frequently overloaded, and a drive icon must not depend on the network at
|
|
14
|
+
* all.
|
|
15
|
+
*
|
|
16
|
+
* A data URI keeps the asset inside this package and inside the drive: no
|
|
17
|
+
* fetch, no gateway, no deploy-base or cross-origin question, and nothing to
|
|
18
|
+
* 404. A few hundred bytes - the size of the string below is the entire cost,
|
|
19
|
+
* paid once in the drive's state.
|
|
20
|
+
*
|
|
21
|
+
* Kept URL-encoded rather than base64 so the markup stays readable and
|
|
22
|
+
* reviewable (`#` must be `%23`; `<`, `>`, `"` and the CSS braces are legal
|
|
23
|
+
* enough in a data URI but are encoded so the value is also safe to paste
|
|
24
|
+
* into markup).
|
|
25
|
+
*/
|
|
26
|
+
/** Encodes an SVG for use in a `data:` URI, smaller than base64 and readable. */
|
|
27
|
+
function svgDataUri(svg) {
|
|
28
|
+
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")}`;
|
|
29
|
+
}
|
|
30
|
+
const PETALS = [
|
|
31
|
+
"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",
|
|
32
|
+
"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",
|
|
33
|
+
"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",
|
|
34
|
+
"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"
|
|
35
|
+
];
|
|
36
|
+
/** Icon for the drives ph-cli creates. */
|
|
37
|
+
const POWERHOUSE_DRIVE_ICON = svgDataUri(`
|
|
38
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="32" height="32">
|
|
39
|
+
<style>
|
|
40
|
+
path { fill: #404345 }
|
|
41
|
+
@media (prefers-color-scheme: dark) { path { fill: #F3F5F7 } }
|
|
42
|
+
</style>
|
|
43
|
+
<path d="${PETALS[0]}"/>
|
|
44
|
+
<path d="${PETALS[1]}"/>
|
|
45
|
+
<path d="${PETALS[2]}"/>
|
|
46
|
+
<path d="${PETALS[3]}"/>
|
|
47
|
+
</svg>`);
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/services/switchboard.ts
|
|
50
|
+
const EGRESS_ALLOW_ENV = "PH_WORKFLOWS_EGRESS_ALLOW_ADDRESSES";
|
|
51
|
+
const LOCALHOST_ADDRESSES = ["127.0.0.1/32", "::1/128"];
|
|
52
|
+
function allowLocalhostEgress(env = process.env) {
|
|
53
|
+
const current = (env[EGRESS_ALLOW_ENV] ?? "").split(",").map((entry) => entry.trim()).filter((entry) => entry !== "");
|
|
54
|
+
const missing = LOCALHOST_ADDRESSES.filter((address) => !current.includes(address));
|
|
55
|
+
if (missing.length > 0) env[EGRESS_ALLOW_ENV] = [...current, ...missing].join(",");
|
|
56
|
+
}
|
|
57
|
+
const defaultSwitchboardOptions = {
|
|
58
|
+
port: 4001,
|
|
59
|
+
drive: {
|
|
60
|
+
id: "powerhouse",
|
|
61
|
+
slug: "powerhouse",
|
|
62
|
+
global: {
|
|
63
|
+
name: "Powerhouse",
|
|
64
|
+
icon: DEFAULT_DRIVE_ICON
|
|
65
|
+
},
|
|
66
|
+
local: {
|
|
67
|
+
availableOffline: true,
|
|
68
|
+
listeners: [],
|
|
69
|
+
sharingType: "public",
|
|
70
|
+
triggers: []
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
mcp: true
|
|
74
|
+
};
|
|
75
|
+
function getDefaultVetraSwitchboardOptions(vetraDriveId) {
|
|
76
|
+
return {
|
|
77
|
+
port: 4001,
|
|
78
|
+
drive: {
|
|
79
|
+
id: vetraDriveId,
|
|
80
|
+
slug: vetraDriveId,
|
|
81
|
+
global: {
|
|
82
|
+
name: "Vetra",
|
|
83
|
+
icon: POWERHOUSE_DRIVE_ICON
|
|
84
|
+
},
|
|
85
|
+
preferredEditor: "vetra-drive-app",
|
|
86
|
+
local: {
|
|
87
|
+
availableOffline: true,
|
|
88
|
+
listeners: [],
|
|
89
|
+
sharingType: "public",
|
|
90
|
+
triggers: []
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
async function startSwitchboard$1(options, logger) {
|
|
96
|
+
const { packages: packagesString, remoteDrives, useVetraDrive, vetraDriveId, useIdentity, keypairPath, requireIdentity, ...serverOptions } = options;
|
|
97
|
+
if (useVetraDrive || serverOptions.dev) allowLocalhostEgress();
|
|
98
|
+
const defaultOptions = useVetraDrive ? getDefaultVetraSwitchboardOptions(vetraDriveId) : defaultSwitchboardOptions;
|
|
99
|
+
const identity = useIdentity || keypairPath || requireIdentity ? {
|
|
100
|
+
keypairPath,
|
|
101
|
+
requireExisting: requireIdentity
|
|
102
|
+
} : void 0;
|
|
103
|
+
const packages = packagesString?.split(",");
|
|
104
|
+
const finalOptions = remoteDrives.length > 0 ? {
|
|
105
|
+
...defaultOptions,
|
|
106
|
+
drive: void 0,
|
|
107
|
+
...serverOptions,
|
|
108
|
+
remoteDrives,
|
|
109
|
+
identity,
|
|
110
|
+
packages,
|
|
111
|
+
logger
|
|
112
|
+
} : {
|
|
113
|
+
...defaultOptions,
|
|
114
|
+
...serverOptions,
|
|
115
|
+
remoteDrives,
|
|
116
|
+
identity,
|
|
117
|
+
packages,
|
|
118
|
+
logger
|
|
119
|
+
};
|
|
120
|
+
return await startSwitchboard({
|
|
121
|
+
...finalOptions,
|
|
122
|
+
fatalErrorShutdown: true
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
//#endregion
|
|
126
|
+
export { POWERHOUSE_DRIVE_ICON as i, defaultSwitchboardOptions as n, startSwitchboard$1 as r, allowLocalhostEgress as t };
|
|
127
|
+
|
|
128
|
+
//# sourceMappingURL=switchboard-h4-XgP1h.mjs.map
|
|
129
|
+
//# debugId=a2511075-368d-5847-9534-acca5aa8a4e3
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"switchboard-h4-XgP1h.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 {\n IdentityOptions,\n StartServerOptions,\n} from \"@powerhousedao/switchboard/server\";\nimport { DEFAULT_DRIVE_ICON } from \"@powerhousedao/shared/clis\";\nimport { startSwitchboard as startSwitchboardServer } 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 async function startSwitchboard(\n options: 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 },\n logger?: ILogger,\n) {\n const {\n packages: packagesString,\n remoteDrives,\n useVetraDrive,\n vetraDriveId,\n useIdentity,\n keypairPath,\n requireIdentity,\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 const reactor = await startSwitchboardServer({\n ...finalOptions,\n fatalErrorShutdown: true,\n });\n\n return reactor;\n}\n"],"names":["startSwitchboard","startSwitchboardServer"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAS,WAAW,KAAqB;CAEvC,OAAO,sBADS,IAAI,QAAQ,QAAQ,GAAG,CAAC,CAAC,KACN,CAAC,CACjC,QAAQ,MAAM,KAAK,CAAC,CACpB,QAAQ,MAAM,KAAK,CAAC,CACpB,QAAQ,MAAM,KAAK,CAAC,CACpB,QAAQ,MAAM,KAAK,CAAC,CACpB,QAAQ,MAAM,KAAK,CAAC,CACpB,QAAQ,OAAO,KAAK,CAAC,CACrB,QAAQ,OAAO,KAAK;AACzB;AAIA,MAAM,SAAS;CACb;CACA;CACA;CACA;AACF;;AA+BA,MAAa,wBAAwB,WAAW;;;;;;aAPnC,OAAO,GAAG;aACV,OAAO,GAAG;aACV,OAAO,GAAG;aACV,OAAO,GAAG;OAIiC;;;AC9DxD,MAAM,mBAAmB;AACzB,MAAM,sBAAsB,CAAC,gBAAgB,SAAS;AAGtD,SAAgB,qBAAqB,MAAyB,QAAQ,KAAK;CACzE,MAAM,WAAW,IAAI,qBAAqB,GAAA,CACvC,MAAM,GAAG,CAAC,CACV,KAAK,UAAU,MAAM,KAAK,CAAC,CAAC,CAC5B,QAAQ,UAAU,UAAU,EAAE;CACjC,MAAM,UAAU,oBAAoB,QACjC,YAAY,CAAC,QAAQ,SAAS,OAAO,CACxC;CACA,IAAI,QAAQ,SAAS,GACnB,IAAI,oBAAoB,CAAC,GAAG,SAAS,GAAG,OAAO,CAAC,CAAC,KAAK,GAAG;AAC7D;AAQA,MAAa,4BAA4B;CACvC,MAAM;CACN,OAAO;EACL,IAAI;EACJ,MAAM;EACN,QAAQ;GACN,MAAM;GACN,MAAM;EACR;EACA,OAAO;GACL,kBAAkB;GAClB,WAAW,CAAC;GACZ,aAAa;GACb,UAAU,CAAC;EACb;CACF;CACA,KAAK;AACP;AAEA,SAAS,kCACP,cAC6B;CAC7B,OAAO;EACL,MAAM;EACN,OAAO;GACL,IAAI;GACJ,MAAM;GACN,QAAQ;IACN,MAAM;IACN,MAAM;GACR;GACA,iBAAiB;GACjB,OAAO;IACL,kBAAkB;IAClB,WAAW,CAAC;IACZ,aAAa;IACb,UAAU,CAAC;GACb;EACF;CACF;AACF;AAEA,eAAsBA,mBACpB,SAUA,QACA;CACA,MAAM,EACJ,UAAU,gBACV,cACA,eACA,cACA,aACA,aACA,iBACA,GAAG,kBACD;CAGJ,IAAI,iBAAiB,cAAc,KAAK,qBAAqB;CAG7D,MAAM,iBAAiB,gBACnB,kCAAkC,YAAY,IAC9C;CAGJ,MAAM,WACJ,eAAe,eAAe,kBAC1B;EACE;EACA,iBAAiB;CACnB,IACA,KAAA;CAEN,MAAM,WAAW,gBAAgB,MAAM,GAAG;CAG1C,MAAM,eACJ,aAAa,SAAS,IAClB;EACE,GAAG;EACH,OAAO,KAAA;EACP,GAAG;EACH;EACA;EACA;EACA;CACF,IACA;EACE,GAAG;EACH,GAAG;EACH;EACA;EACA;EACA;CACF;CAON,OAAO,MALeC,iBAAuB;EAC3C,GAAG;EACH,oBAAoB;CACtB,CAAC;AAGH","debug_id":"a2511075-368d-5847-9534-acca5aa8a4e3"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="8ee54547-f686-5213-81f6-e06f7bd4b297")}catch(e){}}();
|
|
3
3
|
import { Kysely, PostgresDialect } from "kysely";
|
|
4
4
|
import { Pool } from "pg";
|
|
5
5
|
import { REACTOR_SCHEMA, getMigrationStatus, runMigrations } from "@powerhousedao/reactor";
|
|
@@ -15,7 +15,8 @@ async function runSwitchboardMigrations(options) {
|
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
17
17
|
console.log(`Database: ${dbPath}`);
|
|
18
|
-
const
|
|
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-
|
|
53
|
-
//# debugId=
|
|
53
|
+
//# sourceMappingURL=switchboard-migrate-7JQZM7-5.mjs.map
|
|
54
|
+
//# debugId=8ee54547-f686-5213-81f6-e06f7bd4b297
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"switchboard-migrate-
|
|
1
|
+
{"version":3,"file":"switchboard-migrate-7JQZM7-5.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":"8ee54547-f686-5213-81f6-e06f7bd4b297"}
|
|
@@ -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]="
|
|
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 ||
|
|
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 ||
|
|
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-
|
|
87
|
-
//# debugId=
|
|
88
|
+
//# sourceMappingURL=switchboard-reset-MtTB_GAI.mjs.map
|
|
89
|
+
//# debugId=44d0c080-10cc-5316-947d-b0281777aade
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"switchboard-reset-MtTB_GAI.mjs","sources":["../src/services/switchboard-reset.ts"],"sourcesContent":["import { defaultStoreDirs } from \"@powerhousedao/shared/clis/ph-dir\";\nimport { yellow, red, green, cyan } from \"colorette\";\nimport { promises as fs } from \"node:fs\";\n\nexport interface ResetSwitchboardOptions {\n dbPath?: string;\n yes?: boolean;\n}\n\nexport interface ResolvedResetPaths {\n reactorDir: string | null;\n readModelDir: string | null;\n postgresUrl: string | null;\n}\n\nconst CONFIRMATION_TOKEN = \"reset\";\n\nexport function isPostgresUrl(url: string): boolean {\n return url.startsWith(\"postgresql://\") || url.startsWith(\"postgres://\");\n}\n\nfunction isInteractive(): boolean {\n return Boolean(process.stdin.isTTY) && !process.env.CI;\n}\n\n/**\n * Resolves the on-disk PGlite directories that `--reset` would delete.\n * Mirrors the resolution in apps/switchboard/src/server.mts so we touch the\n * same paths the running switchboard uses. When a Postgres URL is configured\n * the corresponding directory is null and `postgresUrl` is populated so the\n * caller can refuse.\n */\nexport function resolveResetPaths(\n options: ResetSwitchboardOptions,\n env: NodeJS.ProcessEnv = process.env,\n): ResolvedResetPaths {\n const defaults = defaultStoreDirs(env);\n const readModelDbPath =\n options.dbPath ?? env.DATABASE_URL ?? env.PH_SWITCHBOARD_DATABASE_URL;\n const readModelPath = readModelDbPath || defaults.readModel;\n const reactorDbUrl =\n options.dbPath ??\n env.PH_REACTOR_DATABASE_URL ??\n env.PH_SWITCHBOARD_DATABASE_URL;\n const reactorPath = reactorDbUrl || defaults.reactor;\n\n const reactorIsPostgres = !!reactorDbUrl && isPostgresUrl(reactorDbUrl);\n const readModelIsPostgres =\n !!readModelDbPath && isPostgresUrl(readModelDbPath);\n\n let postgresUrl: string | null = null;\n if (reactorIsPostgres) postgresUrl = reactorDbUrl as string;\n else if (readModelIsPostgres) postgresUrl = readModelDbPath as string;\n\n return {\n reactorDir: reactorIsPostgres ? null : reactorPath,\n readModelDir: readModelIsPostgres ? null : readModelPath,\n postgresUrl,\n };\n}\n\nasync function promptForConfirmation(): Promise<boolean> {\n const enquirer = await import(\"enquirer\");\n try {\n const answer = await enquirer.default.prompt<{ confirmation: string }>({\n type: \"input\",\n name: \"confirmation\",\n message: `Type \"${CONFIRMATION_TOKEN}\" to confirm wiping the local switchboard databases:`,\n });\n return answer.confirmation.trim() === CONFIRMATION_TOKEN;\n } catch {\n return false;\n }\n}\n\nexport async function resetSwitchboardDatabase(\n options: ResetSwitchboardOptions,\n): Promise<void> {\n const paths = resolveResetPaths(options);\n\n if (paths.postgresUrl) {\n console.error(\n red(\n `Refusing to reset: a PostgreSQL URL is configured (${paths.postgresUrl}).`,\n ),\n );\n console.error(\n yellow(\n \"`ph switchboard --reset` only wipes the local PGlite stores. \" +\n \"To reset a Postgres-backed switchboard, drop/recreate the database manually.\",\n ),\n );\n process.exit(1);\n }\n\n const targets = [paths.reactorDir, paths.readModelDir].filter(\n (d): d is string => d !== null,\n );\n\n if (targets.length === 0) {\n console.error(red(\"No local PGlite directories resolved; nothing to do.\"));\n process.exit(1);\n }\n\n console.log(yellow(\"The following directories will be permanently deleted:\"));\n for (const dir of targets) {\n console.log(` - ${dir}`);\n }\n console.log(\n yellow(\n \"This will wipe all local switchboard state. Migrations will re-run on next `ph switchboard`.\",\n ),\n );\n\n let confirmed = false;\n if (options.yes) {\n confirmed = true;\n } else if (isInteractive()) {\n confirmed = await promptForConfirmation();\n } else {\n console.error(\n red(\n \"Refusing to reset in a non-interactive context without --yes. Re-run with --yes to confirm.\",\n ),\n );\n process.exit(1);\n }\n\n if (!confirmed) {\n console.error(red(\"Aborted: confirmation not provided.\"));\n process.exit(1);\n }\n\n for (const dir of targets) {\n await fs.rm(dir, { recursive: true, force: true });\n console.log(cyan(`Removed ${dir}`));\n }\n\n console.log(\n green(\n \"Switchboard local storage reset. Run `ph switchboard` to re-initialize.\",\n ),\n );\n}\n"],"names":["fs"],"mappings":";;;;;;AAeA,MAAM,qBAAqB;AAE3B,SAAgB,cAAc,KAAsB;CAClD,OAAO,IAAI,WAAW,eAAe,KAAK,IAAI,WAAW,aAAa;AACxE;AAEA,SAAS,gBAAyB;CAChC,OAAO,QAAQ,QAAQ,MAAM,KAAK,KAAK,CAAC,QAAQ,IAAI;AACtD;;;;;;;;AASA,SAAgB,kBACd,SACA,MAAyB,QAAQ,KACb;CACpB,MAAM,WAAW,iBAAiB,GAAG;CACrC,MAAM,kBACJ,QAAQ,UAAU,IAAI,gBAAgB,IAAI;CAC5C,MAAM,gBAAgB,mBAAmB,SAAS;CAClD,MAAM,eACJ,QAAQ,UACR,IAAI,2BACJ,IAAI;CACN,MAAM,cAAc,gBAAgB,SAAS;CAE7C,MAAM,oBAAoB,CAAC,CAAC,gBAAgB,cAAc,YAAY;CACtE,MAAM,sBACJ,CAAC,CAAC,mBAAmB,cAAc,eAAe;CAEpD,IAAI,cAA6B;CACjC,IAAI,mBAAmB,cAAc;MAChC,IAAI,qBAAqB,cAAc;CAE5C,OAAO;EACL,YAAY,oBAAoB,OAAO;EACvC,cAAc,sBAAsB,OAAO;EAC3C;CACF;AACF;AAEA,eAAe,wBAA0C;CACvD,MAAM,WAAW,MAAM,OAAO;CAC9B,IAAI;EAMF,QAAO,MALc,SAAS,QAAQ,OAAiC;GACrE,MAAM;GACN,MAAM;GACN,SAAS,SAAS,mBAAmB;EACvC,CAAC,EAAA,CACa,aAAa,KAAK,MAAM;CACxC,QAAQ;EACN,OAAO;CACT;AACF;AAEA,eAAsB,yBACpB,SACe;CACf,MAAM,QAAQ,kBAAkB,OAAO;CAEvC,IAAI,MAAM,aAAa;EACrB,QAAQ,MACN,IACE,sDAAsD,MAAM,YAAY,GAC1E,CACF;EACA,QAAQ,MACN,OACE,2IAEF,CACF;EACA,QAAQ,KAAK,CAAC;CAChB;CAEA,MAAM,UAAU,CAAC,MAAM,YAAY,MAAM,YAAY,CAAC,CAAC,QACpD,MAAmB,MAAM,IAC5B;CAEA,IAAI,QAAQ,WAAW,GAAG;EACxB,QAAQ,MAAM,IAAI,sDAAsD,CAAC;EACzE,QAAQ,KAAK,CAAC;CAChB;CAEA,QAAQ,IAAI,OAAO,wDAAwD,CAAC;CAC5E,KAAK,MAAM,OAAO,SAChB,QAAQ,IAAI,OAAO,KAAK;CAE1B,QAAQ,IACN,OACE,8FACF,CACF;CAEA,IAAI,YAAY;CAChB,IAAI,QAAQ,KACV,YAAY;MACP,IAAI,cAAc,GACvB,YAAY,MAAM,sBAAsB;MACnC;EACL,QAAQ,MACN,IACE,6FACF,CACF;EACA,QAAQ,KAAK,CAAC;CAChB;CAEA,IAAI,CAAC,WAAW;EACd,QAAQ,MAAM,IAAI,qCAAqC,CAAC;EACxD,QAAQ,KAAK,CAAC;CAChB;CAEA,KAAK,MAAM,OAAO,SAAS;EACzB,MAAMA,SAAG,GAAG,KAAK;GAAE,WAAW;GAAM,OAAO;EAAK,CAAC;EACjD,QAAQ,IAAI,KAAK,WAAW,KAAK,CAAC;CACpC;CAEA,QAAQ,IACN,MACE,yEACF,CACF;AACF","debug_id":"44d0c080-10cc-5316-947d-b0281777aade"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="e3fbf59a-7996-5c5c-9db7-c8d207b68849")}catch(e){}}();
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
import path, { dirname } from "node:path";
|
|
5
5
|
import crypto from "node:crypto";
|
|
@@ -111,36 +111,8 @@ function updateConfigFile(dependencies, projectPath, task = "install", provider
|
|
|
111
111
|
fs.writeFileSync(configPath, JSON.stringify(updatedConfig, null, 2));
|
|
112
112
|
}
|
|
113
113
|
/**
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
* @param projectPath - Path to the project root
|
|
117
|
-
*/
|
|
118
|
-
function updateStylesFile(dependencies, projectPath) {
|
|
119
|
-
const stylesPath = path.join(projectPath, "style.css");
|
|
120
|
-
if (!fs.existsSync(stylesPath)) {
|
|
121
|
-
console.warn("⚠️ Warning: style.css file not found in project root");
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
const currentStyles = fs.readFileSync(stylesPath, "utf-8");
|
|
125
|
-
let updatedStyles = currentStyles;
|
|
126
|
-
for (const dep of dependencies) {
|
|
127
|
-
const cssPath = `./node_modules/${dep.name}/dist/style.css`;
|
|
128
|
-
const fullCssPath = path.join(projectPath, cssPath);
|
|
129
|
-
const importStatement = `@import '${cssPath}';`;
|
|
130
|
-
if (!fs.existsSync(fullCssPath)) {
|
|
131
|
-
console.warn(`⚠️ Warning: CSS file not found at ${cssPath}`);
|
|
132
|
-
continue;
|
|
133
|
-
}
|
|
134
|
-
if (currentStyles.includes(importStatement)) continue;
|
|
135
|
-
const importLines = currentStyles.split("\n").filter((line) => line.trim().startsWith("@import"));
|
|
136
|
-
const lastImport = importLines[importLines.length - 1];
|
|
137
|
-
if (lastImport) updatedStyles = currentStyles.replace(lastImport, `${lastImport}\n${importStatement}`);
|
|
138
|
-
else updatedStyles = `${importStatement}\n${currentStyles}`;
|
|
139
|
-
}
|
|
140
|
-
if (updatedStyles !== currentStyles) fs.writeFileSync(stylesPath, updatedStyles);
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Removes CSS imports for uninstalled packages from styles.css
|
|
114
|
+
* Removes the CSS imports `ph install --local` used to add to style.css for
|
|
115
|
+
* uninstalled packages; Connect now loads a bundled package's CSS with its code.
|
|
144
116
|
*/
|
|
145
117
|
function removeStylesImports(dependencies, projectPath) {
|
|
146
118
|
const stylesPath = path.join(projectPath, "style.css");
|
|
@@ -159,7 +131,7 @@ function removeStylesImports(dependencies, projectPath) {
|
|
|
159
131
|
if (updatedStyles !== currentStyles) fs.writeFileSync(stylesPath, updatedStyles);
|
|
160
132
|
}
|
|
161
133
|
//#endregion
|
|
162
|
-
export { generateProjectDriveId as a, isPowerhouseProject as c, updateConfigFile as d, updatePackagesArray as f, findNodeProjectRoot as i, packageManagers as l, POWERHOUSE_GLOBAL_DIR as n, getPackageManagerFromLockfile as o,
|
|
134
|
+
export { generateProjectDriveId as a, isPowerhouseProject as c, updateConfigFile as d, updatePackagesArray as f, findNodeProjectRoot as i, packageManagers as l, POWERHOUSE_GLOBAL_DIR as n, getPackageManagerFromLockfile as o, defaultPathValidation as r, getProjectInfo as s, POWERHOUSE_CONFIG_FILE as t, removeStylesImports as u };
|
|
163
135
|
|
|
164
|
-
//# sourceMappingURL=utils-
|
|
165
|
-
//# debugId=
|
|
136
|
+
//# sourceMappingURL=utils-9KyRM0mf.mjs.map
|
|
137
|
+
//# debugId=e3fbf59a-7996-5c5c-9db7-c8d207b68849
|