@powerhousedao/ph-cli 6.2.3-staging.0 → 6.3.0-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -0
- package/dist/build-1BN9BD49.mjs +4 -0
- package/dist/build-CWm9MOFJ.mjs +3063 -0
- package/dist/build-CWm9MOFJ.mjs.map +1 -0
- package/dist/check-BZOXiSys.mjs +4 -0
- package/dist/check-C9kQub0h.mjs +81 -0
- package/dist/check-C9kQub0h.mjs.map +1 -0
- package/dist/check-D0b-uWwK.mjs +65 -0
- package/dist/check-D0b-uWwK.mjs.map +1 -0
- package/dist/classic-args-mH_DVsgC.mjs +48 -0
- package/dist/classic-args-mH_DVsgC.mjs.map +1 -0
- package/dist/classic-warnings-kQsFGSeA.mjs +179 -0
- package/dist/classic-warnings-kQsFGSeA.mjs.map +1 -0
- package/dist/{cli-connect-override-b4kKqgOZ.mjs → cli-connect-override-31gBnNxd.mjs} +6 -29
- package/dist/cli-connect-override-31gBnNxd.mjs.map +1 -0
- package/dist/cli.mjs +46 -1341
- package/dist/cli.mjs.map +1 -1
- package/dist/compound-CDrU3CLt-gW8JNJQK.mjs +2910 -0
- package/dist/compound-CDrU3CLt-gW8JNJQK.mjs.map +1 -0
- package/dist/connect-build-is3cmf0E.mjs +322 -0
- package/dist/connect-build-is3cmf0E.mjs.map +1 -0
- package/dist/{connect-config-_kiSMsbG.mjs → connect-config-Dj3E8CaW.mjs} +5 -5
- package/dist/{connect-config-_kiSMsbG.mjs.map → connect-config-Dj3E8CaW.mjs.map} +1 -1
- package/dist/connect-preview-CdFvlANO.mjs +49 -0
- package/dist/connect-preview-CdFvlANO.mjs.map +1 -0
- package/dist/{connect-studio-f3K1qPWd.mjs → connect-studio-BNSe_8PI.mjs} +3 -3
- package/dist/connect-studio-CBtduPet.mjs +94 -0
- package/dist/connect-studio-CBtduPet.mjs.map +1 -0
- package/dist/definitions-worker.d.mts +98 -0
- package/dist/definitions-worker.d.mts.map +1 -0
- package/dist/definitions-worker.mjs +28 -0
- package/dist/definitions-worker.mjs.map +1 -0
- package/dist/dist-seTzvoSw.mjs +480 -0
- package/dist/dist-seTzvoSw.mjs.map +1 -0
- package/dist/evidence-CavwC5YV.mjs +134 -0
- package/dist/evidence-CavwC5YV.mjs.map +1 -0
- package/dist/explain-DTa32gEY.mjs +230 -0
- package/dist/explain-DTa32gEY.mjs.map +1 -0
- package/dist/export-YEBE-Gvl.mjs +42 -0
- package/dist/export-YEBE-Gvl.mjs.map +1 -0
- package/dist/external-M25AgDIE.d.mts +4277 -0
- package/dist/external-M25AgDIE.d.mts.map +1 -0
- package/dist/files-D6_euBBn.mjs +457 -0
- package/dist/files-D6_euBBn.mjs.map +1 -0
- package/dist/{generate-all-CIwP-3aa.mjs → generate-all-DKuaLgz1.mjs} +10 -5
- package/dist/generate-all-DKuaLgz1.mjs.map +1 -0
- package/dist/generate-app-hm6CJ_4O.mjs +72 -0
- package/dist/generate-app-hm6CJ_4O.mjs.map +1 -0
- package/dist/generate-desktop-shell-Dh9_bhLa.mjs +372 -0
- package/dist/generate-desktop-shell-Dh9_bhLa.mjs.map +1 -0
- package/dist/generate-document-model-OQPfeHs-.mjs +118 -0
- package/dist/generate-document-model-OQPfeHs-.mjs.map +1 -0
- package/dist/generate-editor-DBj_Pxwa.mjs +64 -0
- package/dist/generate-editor-DBj_Pxwa.mjs.map +1 -0
- 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-migration-file-yK8uA70U.mjs +20 -0
- package/dist/generate-migration-file-yK8uA70U.mjs.map +1 -0
- package/dist/{generate-piece-QTt-ddt2.mjs → generate-piece-5Nyr2UZj.mjs} +18 -10
- package/dist/generate-piece-5Nyr2UZj.mjs.map +1 -0
- package/dist/{generate-piece-action-C5WTHsqu.mjs → generate-piece-action-DqR8BcoO.mjs} +10 -7
- package/dist/generate-piece-action-DqR8BcoO.mjs.map +1 -0
- package/dist/{generate-piece-trigger-DR10CPOG.mjs → generate-piece-trigger-CZaDD-cc.mjs} +8 -7
- package/dist/generate-piece-trigger-CZaDD-cc.mjs.map +1 -0
- package/dist/{generate-processor-DBtTkgo5.mjs → generate-processor-BVjOsfjJ.mjs} +20 -9
- package/dist/generate-processor-BVjOsfjJ.mjs.map +1 -0
- package/dist/generate-subgraph-DJZCr0Tk.mjs +86 -0
- package/dist/generate-subgraph-DJZCr0Tk.mjs.map +1 -0
- package/dist/get-version-CrerlHgg.mjs +11 -0
- package/dist/get-version-CrerlHgg.mjs.map +1 -0
- package/dist/index-Dy3U1WqW.d.mts +192 -0
- package/dist/index-Dy3U1WqW.d.mts.map +1 -0
- package/dist/{init-CIEMyAug.mjs → init-CJB6RiIy.mjs} +23 -13
- package/dist/init-CJB6RiIy.mjs.map +1 -0
- package/dist/inspect-CulIpVsF.mjs +52 -0
- package/dist/inspect-CulIpVsF.mjs.map +1 -0
- package/dist/{inspect-BpCB0TPo.mjs → inspect-zWJnBDMJ.mjs} +4 -4
- package/dist/{inspect-BpCB0TPo.mjs.map → inspect-zWJnBDMJ.mjs.map} +1 -1
- package/dist/install-added-dependencies-DnZFR3aE.mjs +18 -0
- package/dist/install-added-dependencies-DnZFR3aE.mjs.map +1 -0
- package/dist/keyframes-bFo9iDhT.mjs +201 -0
- package/dist/keyframes-bFo9iDhT.mjs.map +1 -0
- package/dist/mcp-DJKiREkL.mjs +263 -0
- package/dist/mcp-DJKiREkL.mjs.map +1 -0
- package/dist/migrate-Bg-HBsYa.mjs +208 -0
- package/dist/migrate-Bg-HBsYa.mjs.map +1 -0
- package/dist/migrate-subgraphs-Bm3zpsO9.mjs +214 -0
- package/dist/migrate-subgraphs-Bm3zpsO9.mjs.map +1 -0
- package/dist/migrate-subgraphs-De_rX4Hv.mjs +4 -0
- package/dist/module-dir-1avCXsBi.mjs +17 -0
- package/dist/module-dir-1avCXsBi.mjs.map +1 -0
- package/dist/npm-args-g1Tgel4s.mjs +78 -0
- package/dist/npm-args-g1Tgel4s.mjs.map +1 -0
- package/dist/offered-routes-imports-CQInWI6y.mjs +4 -0
- package/dist/offered-routes-imports-CalXK9dh.mjs +96 -0
- package/dist/offered-routes-imports-CalXK9dh.mjs.map +1 -0
- package/dist/ph-cli-commands-C6cJJQlA.mjs +1787 -0
- package/dist/ph-cli-commands-C6cJJQlA.mjs.map +1 -0
- package/dist/ph-cli-commands-CCCVUIzM.mjs +4 -0
- package/dist/render-3M3DwFzO.mjs +4 -0
- package/dist/render-SVfj3m8A.mjs +77 -0
- package/dist/render-SVfj3m8A.mjs.map +1 -0
- package/dist/run--de_-WAz.mjs +112 -0
- package/dist/run--de_-WAz.mjs.map +1 -0
- package/dist/run-LRGy7zGo.mjs +4 -0
- package/dist/run-sugar-ByAIbE2x.mjs +56 -0
- package/dist/run-sugar-ByAIbE2x.mjs.map +1 -0
- package/dist/runners/connect.d.mts +17 -0
- package/dist/runners/connect.d.mts.map +1 -0
- package/dist/runners/connect.mjs +83 -0
- package/dist/runners/connect.mjs.map +1 -0
- package/dist/runners/switchboard.d.mts +24 -0
- package/dist/runners/switchboard.d.mts.map +1 -0
- package/dist/runners/switchboard.mjs +178 -0
- package/dist/runners/switchboard.mjs.map +1 -0
- package/dist/schemas-DzgKfQIx.mjs +6024 -0
- package/dist/schemas-DzgKfQIx.mjs.map +1 -0
- package/dist/scripts/emit-runner-schemas.ts +24 -0
- package/dist/scripts/generate-commands-docs.ts +19 -0
- package/dist/scripts/manage-environment +0 -0
- package/dist/scripts/setup.sh +0 -0
- package/dist/subgraph-gate-BJ2PWXVY.mjs +26 -0
- package/dist/subgraph-gate-BJ2PWXVY.mjs.map +1 -0
- package/dist/subgraph-gate-j9ywj6KA.mjs +4 -0
- package/dist/subgraphs-7OYWwP-C.mjs +134 -0
- package/dist/subgraphs-7OYWwP-C.mjs.map +1 -0
- package/dist/{switchboard-migrate-7JQZM7-5.mjs → switchboard-migrate-BqSdKJ7u.mjs} +4 -5
- package/dist/switchboard-migrate-BqSdKJ7u.mjs.map +1 -0
- package/dist/switchboard-proxy-CGfMtENM.mjs +37 -0
- package/dist/switchboard-proxy-CGfMtENM.mjs.map +1 -0
- package/dist/{switchboard-reset-Ctegiqdm.mjs → switchboard-reset-MtTB_GAI.mjs} +8 -6
- package/dist/switchboard-reset-MtTB_GAI.mjs.map +1 -0
- package/dist/sync-connect-routes-BtAsFPXN.mjs +4 -0
- package/dist/sync-connect-routes-t0Slg-P6.mjs +25 -0
- package/dist/sync-connect-routes-t0Slg-P6.mjs.map +1 -0
- package/dist/{utils-CvmDmCVd.mjs → utils-9KyRM0mf.mjs} +6 -34
- package/dist/{utils-CvmDmCVd.mjs.map → utils-9KyRM0mf.mjs.map} +1 -1
- package/dist/utils-TO9lB8Xs.mjs +4 -0
- package/dist/verify-CIWOkZZV.mjs +71 -0
- package/dist/verify-CIWOkZZV.mjs.map +1 -0
- package/dist/vetra-CmTg8Lja.mjs +351 -0
- package/dist/vetra-CmTg8Lja.mjs.map +1 -0
- package/dist/vetra-host-C0Q0oMUW.mjs +79 -0
- package/dist/vetra-host-C0Q0oMUW.mjs.map +1 -0
- package/dist/vetra-instance-B0bXPj7g.mjs +201 -0
- package/dist/vetra-instance-B0bXPj7g.mjs.map +1 -0
- package/dist/vetra-launch-T_uLKaR3.mjs +236 -0
- package/dist/vetra-launch-T_uLKaR3.mjs.map +1 -0
- package/dist/vetra-switchboard-BrkozIm7.mjs +4 -0
- package/dist/vetra-switchboard-tzdc14KA.mjs +230 -0
- package/dist/vetra-switchboard-tzdc14KA.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 +40 -14
- package/dist/build-CTvPQFMi.mjs +0 -4
- package/dist/build-sO3PcZxl.mjs +0 -166
- package/dist/build-sO3PcZxl.mjs.map +0 -1
- package/dist/cli-connect-override-b4kKqgOZ.mjs.map +0 -1
- package/dist/connect-build-BMaR9w4G.mjs +0 -153
- package/dist/connect-build-BMaR9w4G.mjs.map +0 -1
- package/dist/connect-preview-CzDqR-JN.mjs +0 -32
- package/dist/connect-preview-CzDqR-JN.mjs.map +0 -1
- package/dist/connect-studio-_-O1-oef.mjs +0 -36
- package/dist/connect-studio-_-O1-oef.mjs.map +0 -1
- package/dist/generate-all-CIwP-3aa.mjs.map +0 -1
- package/dist/generate-app-BTs1u-9l.mjs +0 -50
- package/dist/generate-app-BTs1u-9l.mjs.map +0 -1
- package/dist/generate-document-model-DhDQ_06X.mjs +0 -44
- package/dist/generate-document-model-DhDQ_06X.mjs.map +0 -1
- package/dist/generate-editor-CW7Do69u.mjs +0 -50
- package/dist/generate-editor-CW7Do69u.mjs.map +0 -1
- package/dist/generate-piece-QTt-ddt2.mjs.map +0 -1
- package/dist/generate-piece-action-C5WTHsqu.mjs.map +0 -1
- package/dist/generate-piece-trigger-DR10CPOG.mjs.map +0 -1
- package/dist/generate-processor-DBtTkgo5.mjs.map +0 -1
- package/dist/generate-subgraph-Dm27O59o.mjs +0 -42
- package/dist/generate-subgraph-Dm27O59o.mjs.map +0 -1
- package/dist/init-CIEMyAug.mjs.map +0 -1
- package/dist/install-added-dependencies-DVSbzler.mjs +0 -33
- package/dist/install-added-dependencies-DVSbzler.mjs.map +0 -1
- package/dist/migrate-B6QBYDNX.mjs +0 -83
- package/dist/migrate-B6QBYDNX.mjs.map +0 -1
- package/dist/switchboard-CgVB4U76.mjs +0 -87
- package/dist/switchboard-CgVB4U76.mjs.map +0 -1
- package/dist/switchboard-migrate-7JQZM7-5.mjs.map +0 -1
- package/dist/switchboard-nHCI3pha.mjs +0 -4
- package/dist/switchboard-reset-Ctegiqdm.mjs.map +0 -1
- package/dist/utils-C3c5YG6v.mjs +0 -4
- package/dist/vetra-s8gWslse.mjs +0 -627
- package/dist/vetra-s8gWslse.mjs.map +0 -1
|
@@ -0,0 +1,52 @@
|
|
|
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]="b5cb1a95-360f-5775-943b-344d627fa2c2")}catch(e){}}();
|
|
3
|
+
import { t as readProjectSubgraphs } from "./subgraphs-7OYWwP-C.mjs";
|
|
4
|
+
import { n as processStreams, r as runModelCommand } from "./run--de_-WAz.mjs";
|
|
5
|
+
import { n as renderInspectionReport } from "./render-SVfj3m8A.mjs";
|
|
6
|
+
import { inspectProjectDefinitions, withSubgraphInspection } from "document-model/tooling";
|
|
7
|
+
//#region src/services/model/inspect.ts
|
|
8
|
+
/** `<documentType>@<version>`; a document type may itself contain `@`. */
|
|
9
|
+
function parseModelSelector(selector) {
|
|
10
|
+
const at = selector.lastIndexOf("@");
|
|
11
|
+
const documentType = at === -1 ? "" : selector.slice(0, at);
|
|
12
|
+
const version = at === -1 ? "" : selector.slice(at + 1);
|
|
13
|
+
if (documentType === "" || !/^[1-9][0-9]*$/.test(version) || !Number.isSafeInteger(Number(version))) return {
|
|
14
|
+
ok: false,
|
|
15
|
+
message: `Expected <documentType>@<version> with a positive whole version, such as acme/invoice@1. Received ${JSON.stringify(selector)}.`
|
|
16
|
+
};
|
|
17
|
+
return {
|
|
18
|
+
ok: true,
|
|
19
|
+
selection: {
|
|
20
|
+
documentType,
|
|
21
|
+
version: Number(version)
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/** `ph model inspect [<documentType>@<version>]`. Returns the exit code. */
|
|
26
|
+
async function runModelInspect(args, options = {}) {
|
|
27
|
+
let selection;
|
|
28
|
+
if (args.selector !== void 0) {
|
|
29
|
+
const parsed = parseModelSelector(args.selector);
|
|
30
|
+
if (!parsed.ok) {
|
|
31
|
+
(options.streams ?? processStreams).err(`${parsed.message}\n`);
|
|
32
|
+
return 2;
|
|
33
|
+
}
|
|
34
|
+
selection = parsed.selection;
|
|
35
|
+
}
|
|
36
|
+
return await runModelCommand({
|
|
37
|
+
name: "ph model inspect",
|
|
38
|
+
json: args.json,
|
|
39
|
+
read: async (project, modules) => {
|
|
40
|
+
if (selection !== void 0) return inspectProjectDefinitions(project, { selection });
|
|
41
|
+
const report = inspectProjectDefinitions(project);
|
|
42
|
+
const subgraphs = await readProjectSubgraphs(project, modules);
|
|
43
|
+
return subgraphs === void 0 ? report : withSubgraphInspection(project, report, subgraphs.input);
|
|
44
|
+
},
|
|
45
|
+
render: renderInspectionReport
|
|
46
|
+
}, options);
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
export { runModelInspect };
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=inspect-CulIpVsF.mjs.map
|
|
52
|
+
//# debugId=b5cb1a95-360f-5775-943b-344d627fa2c2
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inspect-CulIpVsF.mjs","sources":["../src/services/model/inspect.ts"],"sourcesContent":["import {\n inspectProjectDefinitions,\n withSubgraphInspection,\n} from \"document-model/tooling\";\nimport {\n type ModelRunOptions,\n processStreams,\n runModelCommand,\n} from \"./run.js\";\nimport { renderInspectionReport } from \"./render.js\";\nimport { readProjectSubgraphs } from \"./subgraphs.js\";\n\ntype Selection = { readonly documentType: string; readonly version: number };\n\n/** `<documentType>@<version>`; a document type may itself contain `@`. */\nfunction parseModelSelector(\n selector: string,\n):\n | { readonly ok: true; readonly selection: Selection }\n | { readonly ok: false; readonly message: string } {\n const at = selector.lastIndexOf(\"@\");\n const documentType = at === -1 ? \"\" : selector.slice(0, at);\n const version = at === -1 ? \"\" : selector.slice(at + 1);\n if (\n documentType === \"\" ||\n !/^[1-9][0-9]*$/.test(version) ||\n !Number.isSafeInteger(Number(version))\n ) {\n return {\n ok: false,\n message: `Expected <documentType>@<version> with a positive whole version, such as acme/invoice@1. Received ${JSON.stringify(selector)}.`,\n };\n }\n return { ok: true, selection: { documentType, version: Number(version) } };\n}\n\n/** `ph model inspect [<documentType>@<version>]`. Returns the exit code. */\nexport async function runModelInspect(\n args: { readonly selector?: string; readonly json: boolean },\n options: ModelRunOptions = {},\n): Promise<number> {\n let selection: Selection | undefined;\n if (args.selector !== undefined) {\n const parsed = parseModelSelector(args.selector);\n if (!parsed.ok) {\n (options.streams ?? processStreams).err(`${parsed.message}\\n`);\n return 2;\n }\n selection = parsed.selection;\n }\n return await runModelCommand(\n {\n name: \"ph model inspect\",\n json: args.json,\n read: async (project, modules) => {\n if (selection !== undefined) {\n return inspectProjectDefinitions(project, { selection });\n }\n const report = inspectProjectDefinitions(project);\n const subgraphs = await readProjectSubgraphs(project, modules);\n return subgraphs === undefined\n ? report\n : withSubgraphInspection(project, report, subgraphs.input);\n },\n render: renderInspectionReport,\n },\n options,\n );\n}\n"],"names":[],"mappings":";;;;;;;;AAeA,SAAS,mBACP,UAGmD;CACnD,MAAM,KAAK,SAAS,YAAY,GAAG;CACnC,MAAM,eAAe,OAAO,KAAK,KAAK,SAAS,MAAM,GAAG,EAAE;CAC1D,MAAM,UAAU,OAAO,KAAK,KAAK,SAAS,MAAM,KAAK,CAAC;CACtD,IACE,iBAAiB,MACjB,CAAC,gBAAgB,KAAK,OAAO,KAC7B,CAAC,OAAO,cAAc,OAAO,OAAO,CAAC,GAErC,OAAO;EACL,IAAI;EACJ,SAAS,qGAAqG,KAAK,UAAU,QAAQ,EAAE;CACzI;CAEF,OAAO;EAAE,IAAI;EAAM,WAAW;GAAE;GAAc,SAAS,OAAO,OAAO;EAAE;CAAE;AAC3E;;AAGA,eAAsB,gBACpB,MACA,UAA2B,CAAC,GACX;CACjB,IAAI;CACJ,IAAI,KAAK,aAAa,KAAA,GAAW;EAC/B,MAAM,SAAS,mBAAmB,KAAK,QAAQ;EAC/C,IAAI,CAAC,OAAO,IAAI;GACd,CAAC,QAAQ,WAAW,eAAA,CAAgB,IAAI,GAAG,OAAO,QAAQ,GAAG;GAC7D,OAAO;EACT;EACA,YAAY,OAAO;CACrB;CACA,OAAO,MAAM,gBACX;EACE,MAAM;EACN,MAAM,KAAK;EACX,MAAM,OAAO,SAAS,YAAY;GAChC,IAAI,cAAc,KAAA,GAChB,OAAO,0BAA0B,SAAS,EAAE,UAAU,CAAC;GAEzD,MAAM,SAAS,0BAA0B,OAAO;GAChD,MAAM,YAAY,MAAM,qBAAqB,SAAS,OAAO;GAC7D,OAAO,cAAc,KAAA,IACjB,SACA,uBAAuB,SAAS,QAAQ,UAAU,KAAK;EAC7D;EACA,QAAQ;CACV,GACA,OACF;AACF","debug_id":"b5cb1a95-360f-5775-943b-344d627fa2c2"}
|
|
@@ -1,6 +1,6 @@
|
|
|
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 { s as getProjectInfo } from "./utils-
|
|
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]="1d6b31fa-5089-5315-ae6f-2eda35033167")}catch(e){}}();
|
|
3
|
+
import { s as getProjectInfo } from "./utils-9KyRM0mf.mjs";
|
|
4
4
|
import fs from "node:fs";
|
|
5
5
|
//#region src/services/inspect.ts
|
|
6
6
|
function startInspect(args) {
|
|
@@ -51,5 +51,5 @@ function startInspect(args) {
|
|
|
51
51
|
//#endregion
|
|
52
52
|
export { startInspect };
|
|
53
53
|
|
|
54
|
-
//# sourceMappingURL=inspect-
|
|
55
|
-
//# debugId=
|
|
54
|
+
//# sourceMappingURL=inspect-zWJnBDMJ.mjs.map
|
|
55
|
+
//# debugId=1d6b31fa-5089-5315-ae6f-2eda35033167
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inspect-
|
|
1
|
+
{"version":3,"file":"inspect-zWJnBDMJ.mjs","sources":["../src/services/inspect.ts"],"sourcesContent":["import type { Manifest } from \"@powerhousedao/shared/document-model\";\nimport fs from \"node:fs\";\nimport type { InspectArgs } from \"../types.js\";\nimport { getProjectInfo } from \"../utils.js\";\nexport function startInspect(args: InspectArgs) {\n if (args.debug) {\n console.log(\">>> command arguments\", args);\n }\n\n const projectInfo = getProjectInfo(args.debug);\n const { packageName } = args;\n\n if (args.debug) {\n console.log(\"\\n>>> projectInfo\", projectInfo);\n }\n\n try {\n const loadManifest = (path: string) =>\n JSON.parse(fs.readFileSync(path, \"utf-8\")) as Manifest;\n const manifest = loadManifest(\n `${process.cwd()}/node_modules/${packageName}/dist/powerhouse.manifest.json`,\n );\n\n console.log(manifest.name);\n if (manifest.documentModels) {\n console.log(\"\\nDocument Models:\");\n manifest.documentModels.forEach((model) => {\n console.log(`- ${model.name} (${model.id})`);\n });\n }\n\n if (manifest.editors) {\n console.log(\"\\nEditors:\");\n manifest.editors.forEach((editor) => {\n console.log(`- ${editor.name} (${editor.id})`);\n });\n }\n\n if (manifest.processors) {\n console.log(\"\\nProcessors:\");\n manifest.processors.forEach((processor) => {\n console.log(`- ${processor.name} (${processor.id})`);\n });\n }\n\n if (manifest.subgraphs) {\n console.log(\"\\nSubgraphs:\");\n manifest.subgraphs.forEach((subgraph) => {\n console.log(`- ${subgraph.name} (${subgraph.id})`);\n });\n }\n\n if (manifest.pieces) {\n console.log(\"\\nPieces:\");\n manifest.pieces.forEach((piece) => {\n const version = piece.version ? ` v${piece.version}` : \"\";\n console.log(`- ${piece.name} (${piece.id})${version}`);\n });\n }\n } catch (e) {\n if (args.debug) {\n console.error(e);\n } else {\n console.log(\"No manifest found in the package\");\n }\n }\n}\n"],"names":[],"mappings":";;;;;AAIA,SAAgB,aAAa,MAAmB;CAC9C,IAAI,KAAK,OACP,QAAQ,IAAI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f,QAAQ,IAAI,kCAAkC;CAElD;AACF","debug_id":"1d6b31fa-5089-5315-ae6f-2eda35033167"}
|
|
@@ -0,0 +1,18 @@
|
|
|
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]="fca57a41-fe01-54fe-b4d1-97cd65f0b4ce")}catch(e){}}();
|
|
3
|
+
import { boolean, flag, optional } from "cmd-ts";
|
|
4
|
+
import { installAddedDependencies } from "@powerhousedao/codegen";
|
|
5
|
+
//#region src/utils/install-added-dependencies.ts
|
|
6
|
+
const skipInstallArgs = { skipInstall: flag({
|
|
7
|
+
type: optional(boolean),
|
|
8
|
+
long: "skip-install",
|
|
9
|
+
description: "Don't install the dependencies the command adds to package.json"
|
|
10
|
+
}) };
|
|
11
|
+
async function installAddedDependencies$1(added, projectDir, skipInstall) {
|
|
12
|
+
await installAddedDependencies(added, projectDir, { skipInstall });
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { skipInstallArgs as n, installAddedDependencies$1 as t };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=install-added-dependencies-DnZFR3aE.mjs.map
|
|
18
|
+
//# debugId=fca57a41-fe01-54fe-b4d1-97cd65f0b4ce
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"install-added-dependencies-DnZFR3aE.mjs","sources":["../src/utils/install-added-dependencies.ts"],"sourcesContent":["import { installAddedDependencies as install } from \"@powerhousedao/codegen\";\nimport { boolean, flag, optional } from \"cmd-ts\";\n\nexport const skipInstallArgs = {\n skipInstall: flag({\n type: optional(boolean),\n long: \"skip-install\",\n description:\n \"Don't install the dependencies the command adds to package.json\",\n }),\n};\n\n// Installs what a generate command just added to package.json. A failed\n// install doesn't fail the command: the files are written, so say what to run.\nexport async function installAddedDependencies(\n added: readonly string[],\n projectDir: string,\n skipInstall?: boolean,\n) {\n await install(added, projectDir, { skipInstall });\n}\n"],"names":["installAddedDependencies","install"],"mappings":";;;;;AAGA,MAAa,kBAAkB,EAC7B,aAAa,KAAK;CAChB,MAAM,SAAS,OAAO;CACtB,MAAM;CACN,aACE;AACJ,CAAC,EACH;AAIA,eAAsBA,2BACpB,OACA,YACA,aACA;CACA,MAAMC,yBAAQ,OAAO,YAAY,EAAE,YAAY,CAAC;AAClD","debug_id":"fca57a41-fe01-54fe-b4d1-97cd65f0b4ce"}
|
|
@@ -0,0 +1,201 @@
|
|
|
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]="872a0a4c-a394-510e-9f86-0be9f6fa07cd")}catch(e){}}();
|
|
3
|
+
import { DEFAULT_SWITCHBOARD_PORT } from "@powerhousedao/shared/clis/constants";
|
|
4
|
+
import { getConfig } from "@powerhousedao/shared/clis";
|
|
5
|
+
import { KEYFRAME_ADMIN_OPERATIONS } from "@powerhousedao/reactor";
|
|
6
|
+
//#region src/services/keyframes.ts
|
|
7
|
+
const POLL_INTERVAL_MS = 2e3;
|
|
8
|
+
/** The endpoint inspection-admin is mounted at, beside `/graphql`. */
|
|
9
|
+
function keyframesEndpoint(url) {
|
|
10
|
+
const trimmed = url.replace(/\/+$/, "");
|
|
11
|
+
return trimmed.endsWith("/inspection-admin") ? trimmed : `${trimmed}/inspection-admin`;
|
|
12
|
+
}
|
|
13
|
+
function formatBytes(bytes) {
|
|
14
|
+
if (bytes >= 1024 ** 3) return `${(bytes / 1024 ** 3).toFixed(2)} GB`;
|
|
15
|
+
if (bytes >= 1024 ** 2) return `${(bytes / 1024 ** 2).toFixed(1)} MB`;
|
|
16
|
+
if (bytes >= 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
17
|
+
return `${bytes} B`;
|
|
18
|
+
}
|
|
19
|
+
/** The result of a run as lines of text. */
|
|
20
|
+
function runReport(run) {
|
|
21
|
+
const lines = [
|
|
22
|
+
`${run.dryRun ? "Preview" : "Clean-up"}: ${run.state}, ${run.documentsSeen} of ${run.documentsTotal} documents`,
|
|
23
|
+
`Keyframes: ${run.totals.rows} (${formatBytes(run.totals.bytes)}) in ${run.totals.streams} streams`,
|
|
24
|
+
`${run.dryRun ? "Would remove" : "To remove"}: ${run.totals.removableRows} (${formatBytes(run.totals.removableBytes)})`
|
|
25
|
+
];
|
|
26
|
+
if (!run.dryRun) lines.push(`Removed: ${run.totals.removedRows} (${formatBytes(run.totals.removedBytes)})`);
|
|
27
|
+
if (run.error !== null) lines.push(`Error: ${run.error}`);
|
|
28
|
+
if (run.reasons.length > 0) {
|
|
29
|
+
lines.push("", "By reason:");
|
|
30
|
+
for (const reason of run.reasons) lines.push(` ${reason.reason}: ${reason.rows} (${formatBytes(reason.bytes)})`);
|
|
31
|
+
}
|
|
32
|
+
if (run.types.length > 0) {
|
|
33
|
+
lines.push("", "By document type:");
|
|
34
|
+
for (const type of run.types) lines.push(` ${type.documentType} (interval ${type.interval}, keep ${type.keep ?? "all"}): ${type.rows} keyframes, ${formatBytes(type.bytes)}; remove ${type.removableRows}, ${formatBytes(type.removableBytes)}`);
|
|
35
|
+
}
|
|
36
|
+
if (run.topStreams.length > 0) {
|
|
37
|
+
lines.push("", "Largest streams:");
|
|
38
|
+
for (const stream of run.topStreams) lines.push(` ${stream.documentId} ${stream.scope}/${stream.branch} (${stream.documentType}, ${stream.reason}): remove ${stream.removableRows} of ${stream.rows}, ${formatBytes(stream.removableBytes)}`);
|
|
39
|
+
}
|
|
40
|
+
return lines;
|
|
41
|
+
}
|
|
42
|
+
function reclaimReport(reclaim) {
|
|
43
|
+
const lines = [`Reclaim: ${reclaim.state}`, reclaim.message];
|
|
44
|
+
if (reclaim.tableBytesBefore !== null) {
|
|
45
|
+
const after = reclaim.tableBytesAfter === null ? "" : ` to ${formatBytes(reclaim.tableBytesAfter)}`;
|
|
46
|
+
lines.push(`Keyframe table: ${formatBytes(reclaim.tableBytesBefore)}${after}`);
|
|
47
|
+
}
|
|
48
|
+
return lines;
|
|
49
|
+
}
|
|
50
|
+
function sleep(ms) {
|
|
51
|
+
return new Promise((resolve) => {
|
|
52
|
+
setTimeout(resolve, ms);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
async function followRun(started, deps) {
|
|
56
|
+
let run = started;
|
|
57
|
+
let reported = -1;
|
|
58
|
+
while (run.state === "running") {
|
|
59
|
+
if (run.documentsSeen !== reported) {
|
|
60
|
+
reported = run.documentsSeen;
|
|
61
|
+
deps.output.err(`${run.documentsSeen} of ${run.documentsTotal} documents, ${run.totals.removedRows} removed${run.parked ? " (paused: catch-up priority 0)" : ""}`);
|
|
62
|
+
}
|
|
63
|
+
await sleep(deps.pollIntervalMs);
|
|
64
|
+
const latest = await deps.request(KEYFRAME_ADMIN_OPERATIONS.cleanup);
|
|
65
|
+
if (latest.inspectionKeyframeCleanup === null) throw new Error("The host lost the run: did it restart?");
|
|
66
|
+
run = latest.inspectionKeyframeCleanup;
|
|
67
|
+
}
|
|
68
|
+
return run;
|
|
69
|
+
}
|
|
70
|
+
async function followReclaim(started, deps) {
|
|
71
|
+
let reclaim = started;
|
|
72
|
+
while (reclaim.state === "running") {
|
|
73
|
+
await sleep(deps.pollIntervalMs);
|
|
74
|
+
const latest = await deps.request(KEYFRAME_ADMIN_OPERATIONS.reclaimStatus);
|
|
75
|
+
if (latest.inspectionKeyframeReclaim === null) throw new Error("The host lost the reclaim: did it restart?");
|
|
76
|
+
reclaim = latest.inspectionKeyframeReclaim;
|
|
77
|
+
}
|
|
78
|
+
return reclaim;
|
|
79
|
+
}
|
|
80
|
+
function printRun(run, args, deps) {
|
|
81
|
+
if (args.json) {
|
|
82
|
+
deps.output.out(JSON.stringify(run, null, 2));
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
for (const line of runReport(run)) deps.output.out(line);
|
|
86
|
+
}
|
|
87
|
+
function printReclaim(reclaim, args, deps) {
|
|
88
|
+
if (args.json) {
|
|
89
|
+
deps.output.out(JSON.stringify(reclaim, null, 2));
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
for (const line of reclaimReport(reclaim)) deps.output.out(line);
|
|
93
|
+
}
|
|
94
|
+
async function startAndFollow(dryRun, args, deps) {
|
|
95
|
+
const run = await followRun((await deps.request(KEYFRAME_ADMIN_OPERATIONS.startCleanup, { dryRun })).inspectionStartKeyframeCleanup, deps);
|
|
96
|
+
printRun(run, args, deps);
|
|
97
|
+
return run.state === "done" ? 0 : 1;
|
|
98
|
+
}
|
|
99
|
+
/** The action against a host, by way of `deps.request`. Answers the exit code. */
|
|
100
|
+
async function executeKeyframesAction(args, deps) {
|
|
101
|
+
switch (args.action) {
|
|
102
|
+
case "preview": return startAndFollow(true, args, deps);
|
|
103
|
+
case "clean":
|
|
104
|
+
if (!args.yes) {
|
|
105
|
+
deps.output.err("clean deletes keyframes. Run `ph keyframes preview` first, then add --yes.");
|
|
106
|
+
return 1;
|
|
107
|
+
}
|
|
108
|
+
return startAndFollow(false, args, deps);
|
|
109
|
+
case "status": {
|
|
110
|
+
const { inspectionKeyframeCleanup: run } = await deps.request(KEYFRAME_ADMIN_OPERATIONS.cleanup);
|
|
111
|
+
const { inspectionKeyframeReclaim: reclaim } = await deps.request(KEYFRAME_ADMIN_OPERATIONS.reclaimStatus);
|
|
112
|
+
if (args.json) {
|
|
113
|
+
deps.output.out(JSON.stringify({
|
|
114
|
+
run,
|
|
115
|
+
reclaim
|
|
116
|
+
}, null, 2));
|
|
117
|
+
return 0;
|
|
118
|
+
}
|
|
119
|
+
if (run === null) deps.output.out("No clean-up has run since the host started.");
|
|
120
|
+
else printRun(run, args, deps);
|
|
121
|
+
if (reclaim !== null) printReclaim(reclaim, args, deps);
|
|
122
|
+
return 0;
|
|
123
|
+
}
|
|
124
|
+
case "cancel":
|
|
125
|
+
await deps.request(KEYFRAME_ADMIN_OPERATIONS.cancelCleanup);
|
|
126
|
+
deps.output.out("The running clean-up stops after its current statement.");
|
|
127
|
+
return 0;
|
|
128
|
+
case "reclaim": {
|
|
129
|
+
if (!args.yes) {
|
|
130
|
+
deps.output.err("reclaim rewrites the Keyframe table; the store answers nothing while it does. Add --yes.");
|
|
131
|
+
return 1;
|
|
132
|
+
}
|
|
133
|
+
const reclaim = await followReclaim((await deps.request(KEYFRAME_ADMIN_OPERATIONS.reclaim)).inspectionReclaimKeyframeSpace, deps);
|
|
134
|
+
printReclaim(reclaim, args, deps);
|
|
135
|
+
return reclaim.state === "done" || reclaim.state === "unsupported" ? 0 : 1;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/** A request against `endpoint` with `bearer`, refusing a GraphQL error. */
|
|
140
|
+
function keyframesRequest(endpoint, bearer, fetchImpl = fetch) {
|
|
141
|
+
return async (query, variables = {}) => {
|
|
142
|
+
const response = await fetchImpl(endpoint, {
|
|
143
|
+
method: "POST",
|
|
144
|
+
headers: {
|
|
145
|
+
"content-type": "application/json",
|
|
146
|
+
...bearer ? { authorization: `Bearer ${bearer}` } : {}
|
|
147
|
+
},
|
|
148
|
+
body: JSON.stringify({
|
|
149
|
+
query,
|
|
150
|
+
variables
|
|
151
|
+
})
|
|
152
|
+
});
|
|
153
|
+
const text = await response.text();
|
|
154
|
+
let body;
|
|
155
|
+
try {
|
|
156
|
+
body = JSON.parse(text);
|
|
157
|
+
} catch {
|
|
158
|
+
throw new Error(`${endpoint} answered ${response.status} without GraphQL. Is inspection-admin served (INSPECTION_ADMIN_ENABLED=true)?`);
|
|
159
|
+
}
|
|
160
|
+
const failure = body.errors?.[0];
|
|
161
|
+
if (failure) {
|
|
162
|
+
const hint = failure.extensions?.code === "FORBIDDEN" ? " The caller must be one of the host's auth admins." : "";
|
|
163
|
+
throw new Error(`${failure.message}${hint}`);
|
|
164
|
+
}
|
|
165
|
+
if (!body.data) throw new Error(`${endpoint} answered ${response.status} with no data`);
|
|
166
|
+
return body.data;
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
function defaultGraphqlUrl() {
|
|
170
|
+
return `http://localhost:${getConfig().reactor?.port ?? DEFAULT_SWITCHBOARD_PORT}/graphql`;
|
|
171
|
+
}
|
|
172
|
+
async function bearerToken(given) {
|
|
173
|
+
const known = given ?? process.env.PH_ACCESS_TOKEN;
|
|
174
|
+
if (known) return known;
|
|
175
|
+
const { generateAccessToken } = await import("@renown/sdk/node");
|
|
176
|
+
const { getRenown } = await import("./auth-CNhbN5UM.mjs");
|
|
177
|
+
const { token } = await generateAccessToken(await getRenown(), { expiresIn: 3600 });
|
|
178
|
+
return token;
|
|
179
|
+
}
|
|
180
|
+
/** Runs `ph keyframes <action>`; answers the process exit code. */
|
|
181
|
+
async function runKeyframesCommand(args) {
|
|
182
|
+
const output = {
|
|
183
|
+
out: (line) => console.log(line),
|
|
184
|
+
err: (line) => console.error(line)
|
|
185
|
+
};
|
|
186
|
+
try {
|
|
187
|
+
return await executeKeyframesAction(args, {
|
|
188
|
+
request: keyframesRequest(keyframesEndpoint(args.url ?? defaultGraphqlUrl()), await bearerToken(args.token)),
|
|
189
|
+
output,
|
|
190
|
+
pollIntervalMs: POLL_INTERVAL_MS
|
|
191
|
+
});
|
|
192
|
+
} catch (error) {
|
|
193
|
+
output.err(error instanceof Error ? error.message : String(error));
|
|
194
|
+
return 1;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
//#endregion
|
|
198
|
+
export { runKeyframesCommand };
|
|
199
|
+
|
|
200
|
+
//# sourceMappingURL=keyframes-bFo9iDhT.mjs.map
|
|
201
|
+
//# debugId=872a0a4c-a394-510e-9f86-0be9f6fa07cd
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyframes-bFo9iDhT.mjs","sources":["../src/services/keyframes.ts"],"sourcesContent":["import {\n KEYFRAME_ADMIN_OPERATIONS,\n type KeyframeCleanupRun,\n type KeyframeReclaim,\n} from \"@powerhousedao/reactor\";\nimport { getConfig } from \"@powerhousedao/shared/clis\";\nimport { DEFAULT_SWITCHBOARD_PORT } from \"@powerhousedao/shared/clis/constants\";\n\nexport type KeyframesAction =\n | \"preview\"\n | \"clean\"\n | \"status\"\n | \"cancel\"\n | \"reclaim\";\n\nexport type KeyframesCommandArgs = {\n action: KeyframesAction;\n url?: string;\n token?: string;\n yes?: boolean;\n json?: boolean;\n};\n\ntype GraphqlResponse<T> = {\n data?: T | null;\n errors?: { message: string; extensions?: { code?: string } }[];\n};\n\n/** One call to the host's `inspection-admin` subgraph. */\nexport type KeyframesRequest = <T>(\n query: string,\n variables?: Record<string, unknown>,\n) => Promise<T>;\n\nexport type KeyframesOutput = {\n out: (line: string) => void;\n err: (line: string) => void;\n};\n\nexport type KeyframesDeps = {\n request: KeyframesRequest;\n output: KeyframesOutput;\n pollIntervalMs: number;\n};\n\nconst POLL_INTERVAL_MS = 2_000;\n\n/** The endpoint inspection-admin is mounted at, beside `/graphql`. */\nexport function keyframesEndpoint(url: string): string {\n const trimmed = url.replace(/\\/+$/, \"\");\n return trimmed.endsWith(\"/inspection-admin\")\n ? trimmed\n : `${trimmed}/inspection-admin`;\n}\n\nexport function formatBytes(bytes: number): string {\n if (bytes >= 1024 ** 3) return `${(bytes / 1024 ** 3).toFixed(2)} GB`;\n if (bytes >= 1024 ** 2) return `${(bytes / 1024 ** 2).toFixed(1)} MB`;\n if (bytes >= 1024) return `${(bytes / 1024).toFixed(1)} KB`;\n return `${bytes} B`;\n}\n\n/** The result of a run as lines of text. */\nexport function runReport(run: KeyframeCleanupRun): string[] {\n const lines = [\n `${run.dryRun ? \"Preview\" : \"Clean-up\"}: ${run.state}, ${run.documentsSeen} of ${run.documentsTotal} documents`,\n `Keyframes: ${run.totals.rows} (${formatBytes(run.totals.bytes)}) in ${run.totals.streams} streams`,\n `${run.dryRun ? \"Would remove\" : \"To remove\"}: ${run.totals.removableRows} (${formatBytes(run.totals.removableBytes)})`,\n ];\n if (!run.dryRun) {\n lines.push(\n `Removed: ${run.totals.removedRows} (${formatBytes(run.totals.removedBytes)})`,\n );\n }\n if (run.error !== null) {\n lines.push(`Error: ${run.error}`);\n }\n if (run.reasons.length > 0) {\n lines.push(\"\", \"By reason:\");\n for (const reason of run.reasons) {\n lines.push(\n ` ${reason.reason}: ${reason.rows} (${formatBytes(reason.bytes)})`,\n );\n }\n }\n if (run.types.length > 0) {\n lines.push(\"\", \"By document type:\");\n for (const type of run.types) {\n lines.push(\n ` ${type.documentType} (interval ${type.interval}, keep ${type.keep ?? \"all\"}): ${type.rows} keyframes, ${formatBytes(type.bytes)}; remove ${type.removableRows}, ${formatBytes(type.removableBytes)}`,\n );\n }\n }\n if (run.topStreams.length > 0) {\n lines.push(\"\", \"Largest streams:\");\n for (const stream of run.topStreams) {\n lines.push(\n ` ${stream.documentId} ${stream.scope}/${stream.branch} (${stream.documentType}, ${stream.reason}): remove ${stream.removableRows} of ${stream.rows}, ${formatBytes(stream.removableBytes)}`,\n );\n }\n }\n return lines;\n}\n\nfunction reclaimReport(reclaim: KeyframeReclaim): string[] {\n const lines = [`Reclaim: ${reclaim.state}`, reclaim.message];\n if (reclaim.tableBytesBefore !== null) {\n const after =\n reclaim.tableBytesAfter === null\n ? \"\"\n : ` to ${formatBytes(reclaim.tableBytesAfter)}`;\n lines.push(\n `Keyframe table: ${formatBytes(reclaim.tableBytesBefore)}${after}`,\n );\n }\n return lines;\n}\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve) => {\n setTimeout(resolve, ms);\n });\n}\n\nasync function followRun(\n started: KeyframeCleanupRun,\n deps: KeyframesDeps,\n): Promise<KeyframeCleanupRun> {\n let run = started;\n let reported = -1;\n while (run.state === \"running\") {\n if (run.documentsSeen !== reported) {\n reported = run.documentsSeen;\n deps.output.err(\n `${run.documentsSeen} of ${run.documentsTotal} documents, ${run.totals.removedRows} removed${run.parked ? \" (paused: catch-up priority 0)\" : \"\"}`,\n );\n }\n await sleep(deps.pollIntervalMs);\n const latest = await deps.request<{\n inspectionKeyframeCleanup: KeyframeCleanupRun | null;\n }>(KEYFRAME_ADMIN_OPERATIONS.cleanup);\n if (latest.inspectionKeyframeCleanup === null) {\n throw new Error(\"The host lost the run: did it restart?\");\n }\n run = latest.inspectionKeyframeCleanup;\n }\n return run;\n}\n\nasync function followReclaim(\n started: KeyframeReclaim,\n deps: KeyframesDeps,\n): Promise<KeyframeReclaim> {\n let reclaim = started;\n while (reclaim.state === \"running\") {\n await sleep(deps.pollIntervalMs);\n const latest = await deps.request<{\n inspectionKeyframeReclaim: KeyframeReclaim | null;\n }>(KEYFRAME_ADMIN_OPERATIONS.reclaimStatus);\n if (latest.inspectionKeyframeReclaim === null) {\n throw new Error(\"The host lost the reclaim: did it restart?\");\n }\n reclaim = latest.inspectionKeyframeReclaim;\n }\n return reclaim;\n}\n\nfunction printRun(\n run: KeyframeCleanupRun,\n args: KeyframesCommandArgs,\n deps: KeyframesDeps,\n): void {\n if (args.json) {\n deps.output.out(JSON.stringify(run, null, 2));\n return;\n }\n for (const line of runReport(run)) deps.output.out(line);\n}\n\nfunction printReclaim(\n reclaim: KeyframeReclaim,\n args: KeyframesCommandArgs,\n deps: KeyframesDeps,\n): void {\n if (args.json) {\n deps.output.out(JSON.stringify(reclaim, null, 2));\n return;\n }\n for (const line of reclaimReport(reclaim)) deps.output.out(line);\n}\n\nasync function startAndFollow(\n dryRun: boolean,\n args: KeyframesCommandArgs,\n deps: KeyframesDeps,\n): Promise<number> {\n const started = await deps.request<{\n inspectionStartKeyframeCleanup: KeyframeCleanupRun;\n }>(KEYFRAME_ADMIN_OPERATIONS.startCleanup, { dryRun });\n const run = await followRun(started.inspectionStartKeyframeCleanup, deps);\n printRun(run, args, deps);\n return run.state === \"done\" ? 0 : 1;\n}\n\n/** The action against a host, by way of `deps.request`. Answers the exit code. */\nexport async function executeKeyframesAction(\n args: KeyframesCommandArgs,\n deps: KeyframesDeps,\n): Promise<number> {\n switch (args.action) {\n case \"preview\":\n return startAndFollow(true, args, deps);\n case \"clean\":\n if (!args.yes) {\n deps.output.err(\n \"clean deletes keyframes. Run `ph keyframes preview` first, then add --yes.\",\n );\n return 1;\n }\n return startAndFollow(false, args, deps);\n case \"status\": {\n const { inspectionKeyframeCleanup: run } = await deps.request<{\n inspectionKeyframeCleanup: KeyframeCleanupRun | null;\n }>(KEYFRAME_ADMIN_OPERATIONS.cleanup);\n const { inspectionKeyframeReclaim: reclaim } = await deps.request<{\n inspectionKeyframeReclaim: KeyframeReclaim | null;\n }>(KEYFRAME_ADMIN_OPERATIONS.reclaimStatus);\n if (args.json) {\n deps.output.out(JSON.stringify({ run, reclaim }, null, 2));\n return 0;\n }\n if (run === null) {\n deps.output.out(\"No clean-up has run since the host started.\");\n } else {\n printRun(run, args, deps);\n }\n if (reclaim !== null) {\n printReclaim(reclaim, args, deps);\n }\n return 0;\n }\n case \"cancel\":\n await deps.request(KEYFRAME_ADMIN_OPERATIONS.cancelCleanup);\n deps.output.out(\n \"The running clean-up stops after its current statement.\",\n );\n return 0;\n case \"reclaim\": {\n if (!args.yes) {\n deps.output.err(\n \"reclaim rewrites the Keyframe table; the store answers nothing while it does. Add --yes.\",\n );\n return 1;\n }\n const started = await deps.request<{\n inspectionReclaimKeyframeSpace: KeyframeReclaim;\n }>(KEYFRAME_ADMIN_OPERATIONS.reclaim);\n const reclaim = await followReclaim(\n started.inspectionReclaimKeyframeSpace,\n deps,\n );\n printReclaim(reclaim, args, deps);\n return reclaim.state === \"done\" || reclaim.state === \"unsupported\"\n ? 0\n : 1;\n }\n }\n}\n\n/** A request against `endpoint` with `bearer`, refusing a GraphQL error. */\nexport function keyframesRequest(\n endpoint: string,\n bearer: string | undefined,\n fetchImpl: typeof fetch = fetch,\n): KeyframesRequest {\n return async <T>(query: string, variables: Record<string, unknown> = {}) => {\n const response = await fetchImpl(endpoint, {\n method: \"POST\",\n headers: {\n \"content-type\": \"application/json\",\n ...(bearer ? { authorization: `Bearer ${bearer}` } : {}),\n },\n body: JSON.stringify({ query, variables }),\n });\n const text = await response.text();\n let body: GraphqlResponse<T>;\n try {\n body = JSON.parse(text) as GraphqlResponse<T>;\n } catch {\n throw new Error(\n `${endpoint} answered ${response.status} without GraphQL. Is inspection-admin served (INSPECTION_ADMIN_ENABLED=true)?`,\n );\n }\n const failure = body.errors?.[0];\n if (failure) {\n const hint =\n failure.extensions?.code === \"FORBIDDEN\"\n ? \" The caller must be one of the host's auth admins.\"\n : \"\";\n throw new Error(`${failure.message}${hint}`);\n }\n if (!body.data) {\n throw new Error(`${endpoint} answered ${response.status} with no data`);\n }\n return body.data;\n };\n}\n\nfunction defaultGraphqlUrl(): string {\n const port = getConfig().reactor?.port ?? DEFAULT_SWITCHBOARD_PORT;\n return `http://localhost:${port}/graphql`;\n}\n\nasync function bearerToken(given: string | undefined): Promise<string> {\n const known = given ?? process.env.PH_ACCESS_TOKEN;\n if (known) return known;\n const { generateAccessToken } = await import(\"@renown/sdk/node\");\n const { getRenown } = await import(\"./auth.js\");\n const { token } = await generateAccessToken(await getRenown(), {\n expiresIn: 3600,\n });\n return token;\n}\n\n/** Runs `ph keyframes <action>`; answers the process exit code. */\nexport async function runKeyframesCommand(\n args: KeyframesCommandArgs,\n): Promise<number> {\n const output: KeyframesOutput = {\n out: (line) => console.log(line),\n err: (line) => console.error(line),\n };\n try {\n const request = keyframesRequest(\n keyframesEndpoint(args.url ?? defaultGraphqlUrl()),\n await bearerToken(args.token),\n );\n return await executeKeyframesAction(args, {\n request,\n output,\n pollIntervalMs: POLL_INTERVAL_MS,\n });\n } catch (error) {\n output.err(error instanceof Error ? error.message : String(error));\n return 1;\n }\n}\n"],"names":[],"mappings":";;;;;;AA6CA,MAAM,mBAAmB;;AAGzB,SAAgB,kBAAkB,KAAqB;CACrD,MAAM,UAAU,IAAI,QAAQ,QAAQ,EAAE;CACtC,OAAO,QAAQ,SAAS,mBAAmB,IACvC,UAC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,IAAI,MAAM,GAAG,SAAS,YAAY,SAAS,OAAO,cAAc;EAExE,OAAO,KAAK;CACd;AACF;AAEA,SAAS,oBAA4B;CAEnC,OAAO,oBADM,UAAU,CAAC,CAAC,SAAS,QAAQ,yBACV;AAClC;AAEA,eAAe,YAAY,OAA4C;CACrE,MAAM,QAAQ,SAAS,QAAQ,IAAI;CACnC,IAAI,OAAO,OAAO;CAClB,MAAM,EAAE,wBAAwB,MAAM,OAAO;CAC7C,MAAM,EAAE,cAAc,MAAM,OAAO;CACnC,MAAM,EAAE,UAAU,MAAM,oBAAoB,MAAM,UAAU,GAAG,EAC7D,WAAW,KACb,CAAC;CACD,OAAO;AACT;;AAGA,eAAsB,oBACpB,MACiB;CACjB,MAAM,SAA0B;EAC9B,MAAM,SAAS,QAAQ,IAAI,IAAI;EAC/B,MAAM,SAAS,QAAQ,MAAM,IAAI;CACnC;CACA,IAAI;EAKF,OAAO,MAAM,uBAAuB,MAAM;GACxC,SALc,iBACd,kBAAkB,KAAK,OAAO,kBAAkB,CAAC,GACjD,MAAM,YAAY,KAAK,KAAK,CAGtB;GACN;GACA,gBAAgB;EAClB,CAAC;CACH,SAAS,OAAO;EACd,OAAO,IAAI,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;EACjE,OAAO;CACT;AACF","debug_id":"872a0a4c-a394-510e-9f86-0be9f6fa07cd"}
|
|
@@ -0,0 +1,263 @@
|
|
|
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]="cc2a9f35-4f55-5a31-9317-d0010916b18b")}catch(e){}}();
|
|
3
|
+
import { t as getVersion } from "./get-version-CrerlHgg.mjs";
|
|
4
|
+
import { s as readVetraRuntime } from "./vetra-instance-B0bXPj7g.mjs";
|
|
5
|
+
import { a as vetraCommandFor, n as ensureVetra, r as restartVetra, t as VetraStartError } from "./vetra-launch-T_uLKaR3.mjs";
|
|
6
|
+
import { resolveSwitchboardPortDefault } from "@powerhousedao/shared/clis/args";
|
|
7
|
+
import fs from "node:fs";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
10
|
+
import { StreamableHTTPClientTransport, StreamableHTTPError } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
11
|
+
import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
|
|
12
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
13
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
14
|
+
import { CallToolRequestSchema, CallToolResultSchema, ListResourceTemplatesRequestSchema, ListResourcesRequestSchema, ListToolsRequestSchema, McpError, ReadResourceRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
15
|
+
import { createServer } from "@powerhousedao/reactor-mcp";
|
|
16
|
+
//#region src/services/mcp.ts
|
|
17
|
+
const CALL_TIMEOUT_MS = 6e5;
|
|
18
|
+
const CONFIG_FILE = "powerhouse.config.json";
|
|
19
|
+
/** The nearest directory at or above `start` holding powerhouse.config.json. */
|
|
20
|
+
function findProjectDir(start) {
|
|
21
|
+
let dir = path.resolve(start);
|
|
22
|
+
for (;;) {
|
|
23
|
+
if (fs.existsSync(path.join(dir, CONFIG_FILE))) return dir;
|
|
24
|
+
const parent = path.dirname(dir);
|
|
25
|
+
if (parent === dir) return void 0;
|
|
26
|
+
dir = parent;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const reactorlessClient = new Proxy({}, { get(_target, property) {
|
|
30
|
+
if (property === "then") return void 0;
|
|
31
|
+
return () => {
|
|
32
|
+
throw new Error("reactor-mcp's local tool list has no reactor");
|
|
33
|
+
};
|
|
34
|
+
} });
|
|
35
|
+
/** reactor-mcp's own server, in-process, for the tool list and resources. */
|
|
36
|
+
async function connectLocalReactorMcp() {
|
|
37
|
+
const server = await createServer({ client: reactorlessClient });
|
|
38
|
+
const [clientSide, serverSide] = InMemoryTransport.createLinkedPair();
|
|
39
|
+
await server.connect(serverSide);
|
|
40
|
+
const client = new Client({
|
|
41
|
+
name: "ph-mcp",
|
|
42
|
+
version: getVersion()
|
|
43
|
+
});
|
|
44
|
+
await client.connect(clientSide);
|
|
45
|
+
return client;
|
|
46
|
+
}
|
|
47
|
+
function toolError(message) {
|
|
48
|
+
return {
|
|
49
|
+
isError: true,
|
|
50
|
+
content: [{
|
|
51
|
+
type: "text",
|
|
52
|
+
text: message
|
|
53
|
+
}]
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/** The call never reached a live session: Vetra is down, or restarted since. */
|
|
57
|
+
function isStaleConnection(error) {
|
|
58
|
+
if (error instanceof StreamableHTTPError) return error.code === 404 || error.code === 400;
|
|
59
|
+
for (let e = error; e instanceof Error; e = e.cause) if (e.code === "ECONNREFUSED") return true;
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
const restartVetraTool = {
|
|
63
|
+
name: "restartVetra",
|
|
64
|
+
description: "Restart this project's Vetra (its Switchboard and Studio) and wait until it is ready. Use it after a change Vetra reads only at startup, such as the reactor or packages settings in powerhouse.config.json; Studio restarts by itself for connect.* changes. Returns the new Connect, Switchboard and MCP URLs.",
|
|
65
|
+
inputSchema: {
|
|
66
|
+
type: "object",
|
|
67
|
+
properties: {}
|
|
68
|
+
},
|
|
69
|
+
outputSchema: {
|
|
70
|
+
type: "object",
|
|
71
|
+
properties: {
|
|
72
|
+
pid: { type: "number" },
|
|
73
|
+
connectUrl: { type: "string" },
|
|
74
|
+
switchboardUrl: { type: "string" },
|
|
75
|
+
mcpUrl: { type: "string" }
|
|
76
|
+
},
|
|
77
|
+
required: ["pid", "mcpUrl"]
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
function vetraUrls(record) {
|
|
81
|
+
return {
|
|
82
|
+
pid: record.pid,
|
|
83
|
+
...record.connectUrl ? { connectUrl: record.connectUrl } : {},
|
|
84
|
+
switchboardUrl: record.switchboardUrl ?? `http://localhost:${record.switchboardPort}/graphql`,
|
|
85
|
+
mcpUrl: record.mcpUrl || `http://localhost:${record.switchboardPort}/mcp`
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function projectName(projectDir) {
|
|
89
|
+
try {
|
|
90
|
+
return JSON.parse(fs.readFileSync(path.join(projectDir, "package.json"), "utf8")).name;
|
|
91
|
+
} catch {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
var Upstream = class {
|
|
96
|
+
projectDir;
|
|
97
|
+
options;
|
|
98
|
+
#client;
|
|
99
|
+
/** The Vetra the client talks to; another pid in the record means it restarted. */
|
|
100
|
+
#pid;
|
|
101
|
+
/** The calls waiting on the connection, told how Vetra's start goes. */
|
|
102
|
+
#waiting = /* @__PURE__ */ new Set();
|
|
103
|
+
constructor(projectDir, options) {
|
|
104
|
+
this.projectDir = projectDir;
|
|
105
|
+
this.options = options;
|
|
106
|
+
}
|
|
107
|
+
get(onProgress) {
|
|
108
|
+
if (this.#client && this.#pid !== void 0 && this.projectDir) {
|
|
109
|
+
if (readVetraRuntime(this.projectDir)?.pid !== this.#pid) this.reset();
|
|
110
|
+
}
|
|
111
|
+
this.#client ??= this.#connect(ensureVetra).catch((error) => {
|
|
112
|
+
this.#client = void 0;
|
|
113
|
+
throw error;
|
|
114
|
+
});
|
|
115
|
+
return this.#waitWith(this.#client, onProgress);
|
|
116
|
+
}
|
|
117
|
+
async #waitWith(task, onProgress) {
|
|
118
|
+
if (onProgress) this.#waiting.add(onProgress);
|
|
119
|
+
try {
|
|
120
|
+
return await task;
|
|
121
|
+
} finally {
|
|
122
|
+
if (onProgress) this.#waiting.delete(onProgress);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
#report = (message) => {
|
|
126
|
+
for (const progress of this.#waiting) progress(message);
|
|
127
|
+
};
|
|
128
|
+
reset() {
|
|
129
|
+
const stale = this.#client;
|
|
130
|
+
this.#client = void 0;
|
|
131
|
+
this.#pid = void 0;
|
|
132
|
+
stale?.then((client) => client.close()).catch(() => {});
|
|
133
|
+
}
|
|
134
|
+
/** Restarts Vetra and connects to the new one; resolves to its record. */
|
|
135
|
+
async restart(onProgress) {
|
|
136
|
+
this.reset();
|
|
137
|
+
let record;
|
|
138
|
+
const connected = this.#connect(async (options) => {
|
|
139
|
+
record = await restartVetra(options);
|
|
140
|
+
return record;
|
|
141
|
+
});
|
|
142
|
+
this.#client = connected.catch((error) => {
|
|
143
|
+
this.#client = void 0;
|
|
144
|
+
throw error;
|
|
145
|
+
});
|
|
146
|
+
await this.#waitWith(this.#client, onProgress);
|
|
147
|
+
return record;
|
|
148
|
+
}
|
|
149
|
+
async #connect(start) {
|
|
150
|
+
const { projectDir } = this;
|
|
151
|
+
if (!projectDir) throw new VetraStartError(`No Powerhouse project (${CONFIG_FILE}) at or above ${process.cwd()}. Run \`ph mcp\` inside the project, or pass --project-dir.`);
|
|
152
|
+
const name = projectName(projectDir);
|
|
153
|
+
if (!name) throw new VetraStartError(`${projectDir} has no package.json name.`);
|
|
154
|
+
console.error(`[ph mcp] connecting to Vetra for ${name}...`);
|
|
155
|
+
const record = await start({
|
|
156
|
+
projectDir,
|
|
157
|
+
projectName: name,
|
|
158
|
+
switchboardPort: resolveSwitchboardPortDefault(),
|
|
159
|
+
command: this.options.vetraCommand ?? vetraCommandFor(projectDir),
|
|
160
|
+
timeoutMs: this.options.startTimeoutSeconds * 1e3,
|
|
161
|
+
onProgress: this.#report
|
|
162
|
+
});
|
|
163
|
+
const { mcpUrl } = vetraUrls(record);
|
|
164
|
+
const client = new Client({
|
|
165
|
+
name: "ph-mcp",
|
|
166
|
+
version: getVersion()
|
|
167
|
+
});
|
|
168
|
+
await client.connect(new StreamableHTTPClientTransport(new URL(mcpUrl)));
|
|
169
|
+
this.#pid = record.pid;
|
|
170
|
+
console.error(`[ph mcp] forwarding tool calls to ${mcpUrl}`);
|
|
171
|
+
return client;
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
async function forwardToolCall(upstream, params, signal, onProgress) {
|
|
175
|
+
for (let attempt = 0;; attempt++) {
|
|
176
|
+
const client = await upstream.get(onProgress);
|
|
177
|
+
try {
|
|
178
|
+
return await client.request({
|
|
179
|
+
method: "tools/call",
|
|
180
|
+
params
|
|
181
|
+
}, CallToolResultSchema, {
|
|
182
|
+
signal,
|
|
183
|
+
timeout: CALL_TIMEOUT_MS
|
|
184
|
+
});
|
|
185
|
+
} catch (error) {
|
|
186
|
+
if (attempt > 0 || !isStaleConnection(error)) throw error;
|
|
187
|
+
upstream.reset();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/** `ph mcp`: tools listed by in-process reactor-mcp, calls forwarded to Vetra (started on first call). */
|
|
192
|
+
async function startMcpLauncher(options) {
|
|
193
|
+
console.log = console.error;
|
|
194
|
+
console.info = console.error;
|
|
195
|
+
const projectDir = findProjectDir(options.projectDir ?? process.env.PH_CALLER_CWD ?? process.cwd());
|
|
196
|
+
if (projectDir) process.chdir(projectDir);
|
|
197
|
+
const local = await connectLocalReactorMcp();
|
|
198
|
+
const upstream = new Upstream(projectDir, options);
|
|
199
|
+
const server = new Server(local.getServerVersion() ?? {
|
|
200
|
+
name: "reactor-mcp-server",
|
|
201
|
+
version: ""
|
|
202
|
+
}, {
|
|
203
|
+
capabilities: {
|
|
204
|
+
tools: {},
|
|
205
|
+
resources: {}
|
|
206
|
+
},
|
|
207
|
+
instructions: local.getInstructions()
|
|
208
|
+
});
|
|
209
|
+
server.setRequestHandler(ListToolsRequestSchema, async (request) => {
|
|
210
|
+
const listed = await local.listTools(request.params);
|
|
211
|
+
return {
|
|
212
|
+
...listed,
|
|
213
|
+
tools: [...listed.tools, restartVetraTool]
|
|
214
|
+
};
|
|
215
|
+
});
|
|
216
|
+
server.setRequestHandler(ListResourcesRequestSchema, (request) => local.listResources(request.params));
|
|
217
|
+
server.setRequestHandler(ListResourceTemplatesRequestSchema, (request) => local.listResourceTemplates(request.params));
|
|
218
|
+
server.setRequestHandler(ReadResourceRequestSchema, (request) => local.readResource(request.params));
|
|
219
|
+
server.setRequestHandler(CallToolRequestSchema, async (request, extra) => {
|
|
220
|
+
const token = request.params._meta?.progressToken;
|
|
221
|
+
let progress = 0;
|
|
222
|
+
const onProgress = (message) => {
|
|
223
|
+
if (token === void 0) {
|
|
224
|
+
console.error(`[ph mcp] ${message}`);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
extra.sendNotification({
|
|
228
|
+
method: "notifications/progress",
|
|
229
|
+
params: {
|
|
230
|
+
progressToken: token,
|
|
231
|
+
progress: ++progress,
|
|
232
|
+
message
|
|
233
|
+
}
|
|
234
|
+
}).catch(() => {});
|
|
235
|
+
};
|
|
236
|
+
try {
|
|
237
|
+
if (request.params.name === "restartVetra") {
|
|
238
|
+
const urls = vetraUrls(await upstream.restart(onProgress));
|
|
239
|
+
return {
|
|
240
|
+
content: [{
|
|
241
|
+
type: "text",
|
|
242
|
+
text: JSON.stringify(urls)
|
|
243
|
+
}],
|
|
244
|
+
structuredContent: urls
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
return await forwardToolCall(upstream, request.params, extra.signal, onProgress);
|
|
248
|
+
} catch (error) {
|
|
249
|
+
if (error instanceof McpError) throw error;
|
|
250
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
251
|
+
return toolError(error instanceof VetraStartError ? message : `reactor-mcp request failed: ${message}`);
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
const transport = new StdioServerTransport();
|
|
255
|
+
transport.onclose = () => process.exit(0);
|
|
256
|
+
process.stdin.once("end", () => process.exit(0));
|
|
257
|
+
await server.connect(transport);
|
|
258
|
+
}
|
|
259
|
+
//#endregion
|
|
260
|
+
export { startMcpLauncher };
|
|
261
|
+
|
|
262
|
+
//# sourceMappingURL=mcp-DJKiREkL.mjs.map
|
|
263
|
+
//# debugId=cc2a9f35-4f55-5a31-9317-d0010916b18b
|