@mmapp/react-compiler 0.1.0-alpha.18 → 0.1.0-alpha.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. package/dist/babel/index.d.mts +1 -1
  2. package/dist/babel/index.d.ts +1 -1
  3. package/dist/babel/index.js +9 -6
  4. package/dist/babel/index.mjs +1 -1
  5. package/dist/chunk-26U577GB.mjs +3465 -0
  6. package/dist/chunk-2FBDFAX6.mjs +2362 -0
  7. package/dist/chunk-2REDFOER.mjs +931 -0
  8. package/dist/{chunk-FPAMQXKB.mjs → chunk-2UTXM2QX.mjs} +10 -20
  9. package/dist/chunk-2YDQTFAL.mjs +879 -0
  10. package/dist/chunk-2ZRKQE74.mjs +175 -0
  11. package/dist/chunk-3QHG2JWV.mjs +154 -0
  12. package/dist/chunk-466OWSTT.mjs +186 -0
  13. package/dist/chunk-467SFYOD.mjs +3127 -0
  14. package/dist/chunk-4AIJO7DZ.mjs +214 -0
  15. package/dist/chunk-4D43TZYL.mjs +7495 -0
  16. package/dist/chunk-4FP5DXY4.mjs +3456 -0
  17. package/dist/chunk-4HX4PI4R.mjs +734 -0
  18. package/dist/chunk-4VU56NTZ.mjs +544 -0
  19. package/dist/chunk-4XHK6FWL.mjs +2058 -0
  20. package/dist/chunk-52C2JKH2.mjs +186 -0
  21. package/dist/chunk-52XHYD2V.mjs +214 -0
  22. package/dist/chunk-5GUFFFGL.mjs +148 -0
  23. package/dist/chunk-5N2FDDS6.mjs +214 -0
  24. package/dist/chunk-5ZSJXWZT.mjs +1646 -0
  25. package/dist/chunk-6CQOAAMV.mjs +1803 -0
  26. package/dist/chunk-6SEVAAVT.mjs +3516 -0
  27. package/dist/chunk-6YLR5ZDA.mjs +2829 -0
  28. package/dist/chunk-77UJB356.mjs +244 -0
  29. package/dist/chunk-7QOAJPQF.mjs +774 -0
  30. package/dist/chunk-A5RCMIBP.mjs +1795 -0
  31. package/dist/chunk-A63R3GKH.mjs +1803 -0
  32. package/dist/chunk-ABNTZXF5.mjs +951 -0
  33. package/dist/chunk-ADHWW56I.mjs +214 -0
  34. package/dist/chunk-AOGY2GK6.mjs +3292 -0
  35. package/dist/chunk-AXXUXRNA.mjs +1434 -0
  36. package/dist/chunk-BZLU5YK5.mjs +1025 -0
  37. package/dist/chunk-C7XCDDBH.mjs +1802 -0
  38. package/dist/chunk-CHLVKMQW.mjs +175 -0
  39. package/dist/chunk-CKGOZAB7.mjs +939 -0
  40. package/dist/chunk-CSXYDIVC.mjs +214 -0
  41. package/dist/chunk-CXTV4VGG.mjs +148 -0
  42. package/dist/chunk-D34RAZUX.mjs +2223 -0
  43. package/dist/chunk-DDIC7WM6.mjs +3127 -0
  44. package/dist/chunk-DPUQOBU6.mjs +4810 -0
  45. package/dist/chunk-E6MDVTGT.mjs +148 -0
  46. package/dist/chunk-EGKMUEM6.mjs +544 -0
  47. package/dist/chunk-EO6SYNCG.mjs +175 -0
  48. package/dist/chunk-EQGA6A6D.mjs +121 -0
  49. package/dist/chunk-EY2CSXYA.mjs +822 -0
  50. package/dist/chunk-EYLOSECJ.mjs +544 -0
  51. package/dist/chunk-FF5BQVII.mjs +148 -0
  52. package/dist/chunk-FIQ65CDR.mjs +925 -0
  53. package/dist/chunk-FOZXJFAR.mjs +186 -0
  54. package/dist/chunk-G2IAZ5Q6.mjs +148 -0
  55. package/dist/chunk-G7SMOWOL.mjs +828 -0
  56. package/dist/chunk-GK7NU6DO.mjs +214 -0
  57. package/dist/chunk-HDSCPEHY.mjs +4061 -0
  58. package/dist/chunk-HJELFNEA.mjs +186 -0
  59. package/dist/chunk-HOIUP6IF.mjs +690 -0
  60. package/dist/chunk-HRJGDPNE.mjs +148 -0
  61. package/dist/chunk-I3AU7GRD.mjs +120 -0
  62. package/dist/chunk-I3VQQJZ6.mjs +2843 -0
  63. package/dist/chunk-I6SSPILI.mjs +550 -0
  64. package/dist/chunk-IPTX5MJU.mjs +3223 -0
  65. package/dist/chunk-ITGUSH2Z.mjs +2783 -0
  66. package/dist/chunk-IXHBCAMF.mjs +3306 -0
  67. package/dist/chunk-J7JUAHS4.mjs +186 -0
  68. package/dist/chunk-J7TWJ3TM.mjs +2784 -0
  69. package/dist/chunk-JDPLDGVF.mjs +4810 -0
  70. package/dist/chunk-JK72MQ4N.mjs +877 -0
  71. package/dist/chunk-K2HHCAS2.mjs +148 -0
  72. package/dist/chunk-K5HX2SVL.mjs +1902 -0
  73. package/dist/chunk-KAUEQ2F3.mjs +148 -0
  74. package/dist/chunk-KFVVOS5N.mjs +925 -0
  75. package/dist/chunk-KIH4AN3Y.mjs +154 -0
  76. package/dist/chunk-KPDMN5IX.mjs +175 -0
  77. package/dist/chunk-LZL2IRCH.mjs +186 -0
  78. package/dist/chunk-MIZV3TAN.mjs +3293 -0
  79. package/dist/chunk-MRH4J7IX.mjs +2846 -0
  80. package/dist/chunk-NKBL5GUC.mjs +186 -0
  81. package/dist/chunk-NQCNSCF6.mjs +148 -0
  82. package/dist/chunk-NRP5J3BR.mjs +4811 -0
  83. package/dist/chunk-NTB7OEX2.mjs +2918 -0
  84. package/dist/chunk-NUPJYPFU.mjs +801 -0
  85. package/dist/chunk-NVQUTSQX.mjs +3128 -0
  86. package/dist/chunk-OGMG64EY.mjs +148 -0
  87. package/dist/chunk-OL5B2HTH.mjs +175 -0
  88. package/dist/chunk-OPJKP747.mjs +7506 -0
  89. package/dist/chunk-OQLGGBNE.mjs +2918 -0
  90. package/dist/chunk-OW4AQUDL.mjs +544 -0
  91. package/dist/chunk-OWI6XWCD.mjs +3375 -0
  92. package/dist/chunk-OZT2EAF2.mjs +2776 -0
  93. package/dist/chunk-PBRBRKIQ.mjs +175 -0
  94. package/dist/chunk-PRUMNNDI.mjs +3192 -0
  95. package/dist/chunk-QPNHDTSM.mjs +4839 -0
  96. package/dist/chunk-RNEIAJDR.mjs +897 -0
  97. package/dist/chunk-RY7POBNT.mjs +3127 -0
  98. package/dist/chunk-S6FJ4DXL.mjs +1813 -0
  99. package/dist/chunk-SU4E6E7B.mjs +3153 -0
  100. package/dist/chunk-SYUUKW5A.mjs +3379 -0
  101. package/dist/chunk-THB5SX2S.mjs +113 -0
  102. package/dist/chunk-THFYE5ZX.mjs +244 -0
  103. package/dist/chunk-TK3QMXIP.mjs +2921 -0
  104. package/dist/chunk-TRR2NPAV.mjs +248 -0
  105. package/dist/chunk-TTTTOT7P.mjs +1803 -0
  106. package/dist/chunk-TXONBY6A.mjs +7509 -0
  107. package/dist/chunk-U2PX3JSY.mjs +1933 -0
  108. package/dist/chunk-U6F7CTHK.mjs +550 -0
  109. package/dist/chunk-UASOWKDI.mjs +186 -0
  110. package/dist/chunk-UDDTWG5J.mjs +734 -0
  111. package/dist/chunk-UIWLAQCL.mjs +175 -0
  112. package/dist/chunk-UL2XZEMA.mjs +3128 -0
  113. package/dist/chunk-US3AVDAI.mjs +3456 -0
  114. package/dist/chunk-V5DIDOTT.mjs +148 -0
  115. package/dist/chunk-VLTKQDJ3.mjs +244 -0
  116. package/dist/chunk-VVC42PTS.mjs +175 -0
  117. package/dist/chunk-VX3T3NIR.mjs +897 -0
  118. package/dist/chunk-WBYMW4NQ.mjs +3450 -0
  119. package/dist/chunk-XMWUHQVV.mjs +939 -0
  120. package/dist/chunk-XUQ5R6F3.mjs +213 -0
  121. package/dist/chunk-Y6FXYEAI.mjs +10 -0
  122. package/dist/chunk-YCWC2SCO.mjs +148 -0
  123. package/dist/chunk-YFS6JMYO.mjs +3342 -0
  124. package/dist/chunk-ZE67HOSN.mjs +148 -0
  125. package/dist/chunk-ZSK5TPIV.mjs +148 -0
  126. package/dist/cli/index.js +329 -653
  127. package/dist/cli/index.mjs +9 -9
  128. package/dist/config-PL24KEWL.mjs +219 -0
  129. package/dist/deploy-VAHWALWB.mjs +9 -0
  130. package/dist/dev-server-Bs_sz2DG.d.mts +111 -0
  131. package/dist/dev-server-Bs_sz2DG.d.ts +111 -0
  132. package/dist/dev-server-RmGHIntF.d.mts +113 -0
  133. package/dist/dev-server-RmGHIntF.d.ts +113 -0
  134. package/dist/dev-server.js +205 -522
  135. package/dist/dev-server.mjs +4 -4
  136. package/dist/engine-binary-KQB23JDR.mjs +97 -0
  137. package/dist/envelope-DD7v0v6E.d.mts +265 -0
  138. package/dist/envelope-DD7v0v6E.d.ts +265 -0
  139. package/dist/envelope.js +9 -6
  140. package/dist/envelope.mjs +2 -2
  141. package/dist/index-B5gSgvnd.d.mts +44 -0
  142. package/dist/index-B5gSgvnd.d.ts +44 -0
  143. package/dist/index-Bs0MnR54.d.mts +103 -0
  144. package/dist/index-Bs0MnR54.d.ts +103 -0
  145. package/dist/index-DR0nNc_f.d.mts +101 -0
  146. package/dist/index-DR0nNc_f.d.ts +101 -0
  147. package/dist/index-revho_gS.d.mts +104 -0
  148. package/dist/index-revho_gS.d.ts +104 -0
  149. package/dist/index-vQjwYekL.d.mts +104 -0
  150. package/dist/index-vQjwYekL.d.ts +104 -0
  151. package/dist/index.d.mts +2 -2
  152. package/dist/index.d.ts +2 -2
  153. package/dist/index.js +210 -525
  154. package/dist/index.mjs +10 -9
  155. package/dist/init-2XLTUF7O.mjs +407 -0
  156. package/dist/init-7FJENUDK.mjs +407 -0
  157. package/dist/init-AVZJHZYY.mjs +538 -0
  158. package/dist/init-DQDX3QK6.mjs +369 -0
  159. package/dist/init-K3GVM4JS.mjs +538 -0
  160. package/dist/init-NXS5BJN3.mjs +454 -0
  161. package/dist/init-UC3FWPIW.mjs +367 -0
  162. package/dist/init-UNV5XIDE.mjs +367 -0
  163. package/dist/project-compiler-2HOPO7GC.mjs +10 -0
  164. package/dist/project-compiler-D245L5QR.mjs +10 -0
  165. package/dist/project-compiler-FUQRMB4X.mjs +10 -0
  166. package/dist/project-compiler-LA5OBI5P.mjs +10 -0
  167. package/dist/project-compiler-OP2VVGJQ.mjs +10 -0
  168. package/dist/project-compiler-PZNFE6AH.mjs +10 -0
  169. package/dist/project-compiler-QBVF6MFI.mjs +10 -0
  170. package/dist/project-compiler-VFR6CSDX.mjs +10 -0
  171. package/dist/project-compiler-WMJZA4UH.mjs +10 -0
  172. package/dist/project-compiler-XXS27TZT.mjs +10 -0
  173. package/dist/project-compiler-YYGDSHY5.mjs +10 -0
  174. package/dist/project-decompiler-5GY2KSG4.mjs +7 -0
  175. package/dist/project-decompiler-7I2OMUVY.mjs +7 -0
  176. package/dist/project-decompiler-QCZYY4TW.mjs +7 -0
  177. package/dist/project-decompiler-US7GAVIC.mjs +7 -0
  178. package/dist/pull-2Q53HF3H.mjs +107 -0
  179. package/dist/pull-5AFHD3QG.mjs +109 -0
  180. package/dist/pull-5WJ4LW4U.mjs +109 -0
  181. package/dist/pull-65GUSX6F.mjs +109 -0
  182. package/dist/pull-6LVI4LMM.mjs +109 -0
  183. package/dist/pull-A2QUHW4K.mjs +109 -0
  184. package/dist/pull-B6T5BUKV.mjs +109 -0
  185. package/dist/pull-CKHWZT33.mjs +109 -0
  186. package/dist/pull-GM74ERRT.mjs +109 -0
  187. package/dist/pull-JBEQWVPE.mjs +109 -0
  188. package/dist/pull-P44LDRWB.mjs +109 -0
  189. package/dist/pull-W2US3T3E.mjs +109 -0
  190. package/dist/testing/index.js +9 -6
  191. package/dist/testing/index.mjs +1 -1
  192. package/dist/verify-3PPS4XAM.mjs +1833 -0
  193. package/dist/verify-GKEH5FZQ.mjs +1833 -0
  194. package/dist/verify-HDKUNHZ4.mjs +1833 -0
  195. package/dist/verify-SEIXUGN4.mjs +1833 -0
  196. package/dist/vite/index.js +10 -7
  197. package/dist/vite/index.mjs +2 -2
  198. package/mm-dev.db +0 -0
  199. package/package.json +2 -2
@@ -0,0 +1,544 @@
1
+ import {
2
+ build
3
+ } from "./chunk-TRR2NPAV.mjs";
4
+ import {
5
+ mindmatrixReact
6
+ } from "./chunk-PBRBRKIQ.mjs";
7
+ import {
8
+ __require
9
+ } from "./chunk-CIESM3BP.mjs";
10
+
11
+ // src/dev-server.ts
12
+ var currentErrors = null;
13
+ function escapeHtml(s) {
14
+ return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
15
+ }
16
+ function renderErrorOverlay(errors) {
17
+ const cards = errors.map((err) => {
18
+ const loc = err.line ? `${err.file}:${err.line}${err.column ? ":" + err.column : ""}` : err.file;
19
+ const snippet = err.snippet ? `<pre style="background:#1a1a2e;color:#e0e0e0;padding:12px 16px;border-radius:6px;overflow-x:auto;margin-top:8px;font-size:13px;line-height:1.5">${escapeHtml(err.snippet)}</pre>` : "";
20
+ return `<div style="background:#2d1b1b;border:1px solid #5c2020;border-radius:8px;padding:16px 20px;margin-bottom:12px">
21
+ <div style="color:#ff6b6b;font-family:monospace;font-size:13px;margin-bottom:6px">${escapeHtml(loc)}</div>
22
+ <div style="color:#ffa0a0;font-size:15px;font-weight:500">${escapeHtml(err.message)}</div>${snippet}</div>`;
23
+ }).join("\n");
24
+ return `<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
25
+ <title>Compile Error - MindMatrix Dev</title>
26
+ <style>*{box-sizing:border-box;margin:0;padding:0}body{background:#1a1a2e;color:#e0e0e0;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;padding:40px 20px;min-height:100vh}</style></head>
27
+ <body><div style="max-width:800px;margin:0 auto">
28
+ <div style="display:flex;align-items:center;gap:12px;margin-bottom:24px">
29
+ <div style="background:#5c2020;color:#ff6b6b;font-size:14px;font-weight:600;padding:4px 10px;border-radius:4px">COMPILE ERROR</div>
30
+ <div style="color:#888;font-size:13px">${errors.length} error${errors.length !== 1 ? "s" : ""}</div></div>
31
+ ${cards}
32
+ <div style="color:#666;font-size:12px;margin-top:24px;text-align:center">Fix the error and save -- the page will reload automatically.</div></div>
33
+ <script>const ws=new WebSocket('ws://'+location.host+'/__mm_dev');ws.onmessage=e=>{const m=JSON.parse(e.data);if(m.type==='workflow:compiled'||m.type==='workflow:rebuild')location.reload()};ws.onclose=()=>setTimeout(()=>location.reload(),2000)</script>
34
+ </body></html>`;
35
+ }
36
+ function errorOverlayMiddleware() {
37
+ return (req, res, next) => {
38
+ if (!currentErrors || !req.url) return next();
39
+ const url = req.url;
40
+ if (url.startsWith("/api") || url.startsWith("/health") || url.startsWith("/ws") || url.startsWith("/__mm_dev") || url.startsWith("/@") || url.startsWith("/node_modules")) return next();
41
+ const accept = req.headers?.accept ?? "";
42
+ if (!accept.includes("text/html")) return next();
43
+ res.writeHead(500, { "Content-Type": "text/html; charset=utf-8" });
44
+ res.end(renderErrorOverlay(currentErrors));
45
+ };
46
+ }
47
+ async function resolveDevToken(apiUrl, explicit) {
48
+ if (explicit) return explicit;
49
+ try {
50
+ const { resolveToken } = await import("./auth-3UK75242.mjs");
51
+ const s = resolveToken(apiUrl);
52
+ if (s) return s;
53
+ } catch {
54
+ }
55
+ try {
56
+ const resp = await fetch(`${apiUrl}/auth/login`, {
57
+ method: "POST",
58
+ headers: { "Content-Type": "application/json" },
59
+ body: JSON.stringify({ email: "admin@mindmatrix.com", password: "Admin123!" })
60
+ });
61
+ if (resp.ok) {
62
+ const data = await resp.json();
63
+ const token = data.token ?? data.access_token;
64
+ if (token) {
65
+ try {
66
+ const { saveCredentials } = await import("./auth-3UK75242.mjs");
67
+ saveCredentials(apiUrl, token);
68
+ } catch {
69
+ }
70
+ return token;
71
+ }
72
+ }
73
+ } catch {
74
+ }
75
+ return process.env.MINDMATRIX_TOKEN;
76
+ }
77
+ async function checkBackendHealth(apiUrl) {
78
+ try {
79
+ const base = apiUrl.replace(/\/api\/v1\/?$/, "");
80
+ const resp = await fetch(`${base}/health`, { signal: AbortSignal.timeout(5e3) });
81
+ if (resp.ok) {
82
+ const d = await resp.json();
83
+ return { ok: true, version: d.version, db: d.database };
84
+ }
85
+ return { ok: resp.status < 500 };
86
+ } catch {
87
+ return { ok: false };
88
+ }
89
+ }
90
+ async function initialBuildDeploy(src, outDir, mode, apiUrl, token) {
91
+ console.log("[mm-dev] Compiling project...");
92
+ const buildResult = await build({ src, outDir, mode, skipTypeCheck: true });
93
+ if (buildResult.errors > 0) {
94
+ currentErrors = buildResult.errorDetails.map((e) => ({ file: e.file, message: e.message, line: e.line }));
95
+ console.error(`[mm-dev] Build failed with ${buildResult.errors} error(s) -- error overlay active`);
96
+ return { buildResult, deployed: false, slug: void 0 };
97
+ }
98
+ currentErrors = null;
99
+ if (buildResult.compiled === 0) return { buildResult, deployed: false, slug: void 0 };
100
+ console.log(`[mm-dev] Compiled ${buildResult.compiled} definition(s)`);
101
+ try {
102
+ const { deploy } = await import("./deploy-VAHWALWB.mjs");
103
+ const result = await deploy({ apiUrl, token, dir: outDir });
104
+ const total = result.created.length + result.updated.length + result.versioned.length;
105
+ if (total > 0) console.log(`[mm-dev] Deployed: ${result.created.length} created, ${result.updated.length} updated`);
106
+ return { buildResult, deployed: true, slug: buildResult.definitions?.[0]?.slug };
107
+ } catch (e) {
108
+ console.warn(`[mm-dev] Deploy failed: ${e instanceof Error ? e.message : e}`);
109
+ return { buildResult, deployed: false, slug: void 0 };
110
+ }
111
+ }
112
+ function printBanner(o) {
113
+ const l = "-".repeat(58);
114
+ console.log(`
115
+ ${l}
116
+ MindMatrix Dev Server
117
+ ${l}
118
+ `);
119
+ console.log(` Preview: http://localhost:${o.port}`);
120
+ console.log(` API Proxy: /api/* -> ${o.apiUrl}`);
121
+ console.log(` WebSocket: ws://localhost:${o.port}/__mm_dev`);
122
+ console.log(` Watching: ${o.src} (${o.include.join(", ")})
123
+ `);
124
+ console.log(` Backend: ${o.health.ok ? "connected" : "unreachable"}${o.health.version ? ` (v${o.health.version})` : ""}`);
125
+ if (o.health.db) console.log(` Database: ${o.health.db}`);
126
+ console.log(` Auth: ${o.token ? "authenticated" : "no token"}`);
127
+ if (o.compiled > 0) {
128
+ console.log(` Blueprint: ${o.slug ?? "unknown"} (${o.compiled} defs)`);
129
+ console.log(` Deploy: ${o.deployed ? "synced" : "pending"}`);
130
+ }
131
+ if (o.errors > 0) console.log(` Errors: ${o.errors} compile error(s) -- overlay active`);
132
+ console.log(`
133
+ ${l}
134
+ `);
135
+ }
136
+ function broadcast(clients, data) {
137
+ const msg = JSON.stringify(data);
138
+ for (const c of clients) {
139
+ try {
140
+ if (c.readyState === 1) c.send(msg);
141
+ } catch {
142
+ clients.delete(c);
143
+ }
144
+ }
145
+ }
146
+ async function createDevServer(options = {}) {
147
+ const { existsSync } = await import("fs");
148
+ const { resolve } = await import("path");
149
+ const nodeModulesPath = resolve(process.cwd(), "node_modules");
150
+ if (!existsSync(nodeModulesPath)) {
151
+ console.error(`
152
+ [mmrc] Error: Dependencies not installed.
153
+ `);
154
+ console.error(` Run one of these in your project directory first:
155
+ `);
156
+ console.error(` npm install`);
157
+ console.error(` pnpm install`);
158
+ console.error(` yarn install
159
+ `);
160
+ process.exit(1);
161
+ }
162
+ try {
163
+ await import("vite");
164
+ } catch {
165
+ console.error(`
166
+ [mmrc] Error: 'vite' is not installed.
167
+ `);
168
+ console.error(` Install it:
169
+ `);
170
+ console.error(` npm install -D vite
171
+ `);
172
+ process.exit(1);
173
+ }
174
+ const {
175
+ port = 5199,
176
+ src = ".",
177
+ mode = "infer",
178
+ include = ["models/**/*.ts", "app/**/*.tsx", "**/*.workflow.tsx"],
179
+ outDir = "dist",
180
+ seed = false,
181
+ apiUrl: rawApiUrl = "auto",
182
+ authToken: explicitToken,
183
+ ws: enableWs = true,
184
+ open = false
185
+ } = options;
186
+ const clients = /* @__PURE__ */ new Set();
187
+ let apiUrl;
188
+ if (rawApiUrl === "local" || rawApiUrl === "auto") {
189
+ const localHealth = await checkBackendHealth("http://localhost:4200/api/v1");
190
+ if (localHealth.ok) {
191
+ apiUrl = "http://localhost:4200/api/v1";
192
+ } else if (rawApiUrl === "auto") {
193
+ const defaultRemote = "https://dev.mindmatrix.club/api/v1";
194
+ const remoteHealth = await checkBackendHealth(defaultRemote);
195
+ if (remoteHealth.ok) {
196
+ apiUrl = defaultRemote;
197
+ } else {
198
+ console.error("[mm-dev] No backend detected. Start the engine first:");
199
+ console.error(" mmrc dev (auto-starts engine)");
200
+ console.error(" mmrc engine start (manual start)");
201
+ console.error("[mm-dev] Or specify a remote API: mmrc dev --api-url https://...");
202
+ apiUrl = "http://localhost:4200/api/v1";
203
+ }
204
+ } else {
205
+ console.error("[mm-dev] Local engine not running on port 4200.");
206
+ console.error(" Start it with: mmrc dev (or mmrc engine start)");
207
+ apiUrl = "http://localhost:4200/api/v1";
208
+ }
209
+ } else {
210
+ apiUrl = rawApiUrl;
211
+ }
212
+ const token = await resolveDevToken(apiUrl, explicitToken);
213
+ const health = await checkBackendHealth(apiUrl);
214
+ let initialSlug, initialCompiled = 0, initialDeployed = false, initialErrors = 0;
215
+ if (token && health.ok) {
216
+ const r = await initialBuildDeploy(src, outDir, mode, apiUrl, token);
217
+ initialCompiled = r.buildResult.compiled;
218
+ initialDeployed = r.deployed;
219
+ initialSlug = r.slug;
220
+ initialErrors = r.buildResult.errors;
221
+ }
222
+ if (seed && token && initialDeployed) {
223
+ try {
224
+ const { seedInstances } = await import("./seed-KOGEPGOJ.mjs");
225
+ console.log("[mm-dev] Seeding sample instances...");
226
+ const sr = await seedInstances({ apiUrl, token, dir: outDir });
227
+ console.log(`[mm-dev] Seeded ${sr.created} instance(s) across ${sr.definitions} definition(s)`);
228
+ } catch (e) {
229
+ console.warn(`[mm-dev] Seed failed: ${e instanceof Error ? e.message : e}`);
230
+ }
231
+ }
232
+ const pluginOpts = { mode, include, outDir, seedOnCompile: seed, apiUrl, authToken: token };
233
+ const proxyTarget = apiUrl.replace(/\/api\/v1\/?$/, "") || apiUrl;
234
+ const devPlayerPlugin = {
235
+ name: "mindmatrix-dev-player",
236
+ resolveId(id) {
237
+ if (id === "virtual:mm-dev-player") return "\0virtual:mm-dev-player";
238
+ return null;
239
+ },
240
+ load(id) {
241
+ if (id !== "\0virtual:mm-dev-player") return null;
242
+ return `
243
+ import React from 'react';
244
+ import { createRoot } from 'react-dom/client';
245
+ import { DevPlayer } from '@mmapp/react/player';
246
+
247
+ const tree = window.__MM_DEV_TREE__ || { type: 'Text', props: { children: 'No tree loaded. Compile a workflow to see the preview.' } };
248
+ const scopes = window.__MM_DEV_SCOPES__ || {};
249
+
250
+ function App() {
251
+ const [currentTree, setTree] = React.useState(tree);
252
+ const [currentScopes, setScopes] = React.useState(scopes);
253
+
254
+ React.useEffect(() => {
255
+ const ws = new WebSocket('ws://' + location.host + '/__mm_dev');
256
+ ws.onmessage = (ev) => {
257
+ try {
258
+ const msg = JSON.parse(ev.data);
259
+ if (msg.type === 'workflow:compiled' && msg.tree) setTree(msg.tree);
260
+ if (msg.type === 'workflow:compiled' && msg.scopes) setScopes(msg.scopes);
261
+ } catch {}
262
+ };
263
+ return () => ws.close();
264
+ }, []);
265
+
266
+ return React.createElement(DevPlayer, { tree: currentTree, scopes: currentScopes, title: document.title || 'MindMatrix Dev' });
267
+ }
268
+
269
+ createRoot(document.getElementById('root')).render(React.createElement(App));
270
+ `;
271
+ }
272
+ };
273
+ const { existsSync: fsExists } = await import("fs");
274
+ const projectIndexPath = __require("path").join(process.cwd(), "index.html");
275
+ const hasProjectIndex = fsExists(projectIndexPath);
276
+ if (!hasProjectIndex) {
277
+ const { writeFileSync: fsWrite } = await import("fs");
278
+ fsWrite(projectIndexPath, `<!DOCTYPE html>
279
+ <html lang="en">
280
+ <head>
281
+ <meta charset="UTF-8">
282
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
283
+ <title>MindMatrix Dev</title>
284
+ </head>
285
+ <body>
286
+ <div id="root"></div>
287
+ <script type="module" src="/__mm_dev_entry.tsx"></script>
288
+ </body>
289
+ </html>`, "utf-8");
290
+ }
291
+ const devEntryPlugin = {
292
+ name: "mindmatrix-dev-entry",
293
+ resolveId(id) {
294
+ if (id === "/__mm_dev_entry.tsx") return id;
295
+ return null;
296
+ },
297
+ load(id) {
298
+ if (id !== "/__mm_dev_entry.tsx") return null;
299
+ return `
300
+ import React, { useState, useEffect } from 'react';
301
+ import { createRoot } from 'react-dom/client';
302
+ import { DevPlayer } from '@mmapp/react/player';
303
+ import { PlayerProvider, ExperienceRenderer, createApiResolver } from '@mmapp/react/player';
304
+
305
+ // Detect API base URL \u2014 proxy through dev server or use direct URL
306
+ const API_BASE = window.location.origin + '/api/v1';
307
+ const resolver = createApiResolver({ baseUrl: API_BASE, token: () => localStorage.getItem('auth_token') });
308
+
309
+ /**
310
+ * Prepare experience tree for rendering.
311
+ * Attaches metadata.dataSources to the root node and remaps
312
+ * dataSource slugs to use definition-relative naming.
313
+ *
314
+ * @param definition - The main blueprint definition
315
+ * @param allDefinitions - ALL definitions from the API (used for slug resolution)
316
+ */
317
+ function prepareTree(definition, allDefinitions) {
318
+ const exp = definition.experience;
319
+ if (!exp || typeof exp !== 'object') return null;
320
+
321
+ const meta = definition.metadata || {};
322
+ const dataSources = meta.dataSources || [];
323
+ const mutationTargets = meta.mutationTargets || [];
324
+
325
+ // Build a slug map from ALL deployed definitions
326
+ // This resolves bare model names (e.g. "item") to full slugs (e.g. "tutorial-1-item")
327
+ const blueprintSlug = definition.slug || '';
328
+ const allSlugs = (allDefinitions || []).map(d => d.slug).filter(Boolean);
329
+
330
+ function resolveSlug(bareSlug) {
331
+ if (!bareSlug) return bareSlug;
332
+ // Already a full slug (contains hyphen matching a known definition)
333
+ if (allSlugs.includes(bareSlug)) return bareSlug;
334
+ // Try blueprint-prefixed slug: "item" \u2192 "tutorial-1-item"
335
+ const prefixed = blueprintSlug + '-' + bareSlug;
336
+ if (allSlugs.includes(prefixed)) return prefixed;
337
+ // Try matching by suffix across all definitions
338
+ const match = allSlugs.find(s => s.endsWith('-' + bareSlug));
339
+ if (match) return match;
340
+ // Return original (will attempt as-is)
341
+ return bareSlug;
342
+ }
343
+
344
+ // Clone root node and attach dataSources
345
+ const root = { ...exp };
346
+ if (dataSources.length > 0 && !root.dataSources) {
347
+ root.dataSources = dataSources.map(ds => ({
348
+ ...ds,
349
+ slug: resolveSlug(ds.slug),
350
+ }));
351
+ }
352
+
353
+ // Remap mutation targets the same way
354
+ if (mutationTargets.length > 0) {
355
+ const resolvedTargets = mutationTargets.map(t => resolveSlug(t));
356
+ root.config = { ...(root.config || {}), _mutationTargets: resolvedTargets };
357
+ }
358
+
359
+ return root;
360
+ }
361
+
362
+ function App() {
363
+ const [tree, setTree] = useState(null);
364
+ const [error, setError] = useState(null);
365
+
366
+ useEffect(() => {
367
+ async function loadTree() {
368
+ try {
369
+ const res = await fetch(API_BASE + '/workflow/definitions');
370
+ const json = await res.json();
371
+ const items = json.items || json.data || [];
372
+ // Find the main blueprint definition (has experience tree)
373
+ const main = items.find(d => d.experience && !(Array.isArray(d.category) ? d.category.includes('data') : d.category === 'data')) || items.find(d => d.experience) || items[0];
374
+ if (main?.experience) {
375
+ const prepared = prepareTree(main, items);
376
+ if (prepared) {
377
+ setTree(prepared);
378
+ return;
379
+ }
380
+ }
381
+ if (main) {
382
+ // No experience tree \u2014 show definition info
383
+ setTree({
384
+ type: 'Stack',
385
+ props: { style: { padding: 40, gap: 16 } },
386
+ children: [
387
+ { type: 'Text', props: { children: main.name || main.slug, style: { fontSize: 24, fontWeight: 'bold' } } },
388
+ { type: 'Text', props: { children: (main.states?.length || 0) + ' states, ' + (main.fields?.length || 0) + ' fields', style: { color: '#666' } } },
389
+ ...items.map((d, i) => ({
390
+ type: 'Card',
391
+ props: { key: i, style: { padding: 16, border: '1px solid #ddd', borderRadius: 8 } },
392
+ children: [
393
+ { type: 'Text', props: { children: d.name || d.slug, style: { fontWeight: 600 } } },
394
+ { type: 'Text', props: { children: 'slug: ' + d.slug + ' | ' + (d.states?.length || 0) + ' states', style: { fontSize: 13, color: '#888' } } },
395
+ ],
396
+ })),
397
+ ],
398
+ });
399
+ }
400
+ } catch (e) {
401
+ setError(e.message);
402
+ }
403
+ }
404
+ loadTree();
405
+ }, []);
406
+
407
+ if (error) return React.createElement('div', { style: { padding: 40 } },
408
+ React.createElement('h1', null, 'MindMatrix Dev'),
409
+ React.createElement('p', { style: { color: '#c00' } }, 'Error: ' + error)
410
+ );
411
+
412
+ if (!tree) return React.createElement('div', { style: { display: 'flex', alignItems: 'center', justifyContent: 'center', minHeight: '100vh' } },
413
+ React.createElement('p', null, 'Loading...')
414
+ );
415
+
416
+ // If tree has 'component' field, use ExperienceRenderer; otherwise legacy DevPlayer
417
+ if (tree.component) {
418
+ return React.createElement(PlayerProvider, { resolver },
419
+ React.createElement(ExperienceRenderer, { tree, className: 'mm-experience-root' })
420
+ );
421
+ }
422
+
423
+ return React.createElement(DevPlayer, { tree, title: document.title || 'MindMatrix Dev' });
424
+ }
425
+
426
+ createRoot(document.getElementById('root')).render(React.createElement(App));
427
+ `;
428
+ }
429
+ };
430
+ let deployInFlight = false;
431
+ const compileDeployPlugin = {
432
+ name: "mindmatrix-dev-compile-deploy",
433
+ enforce: "post",
434
+ async handleHotUpdate(ctx) {
435
+ const isWf = include.some((p) => new RegExp(p.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "<<G>>").replace(/\*/g, "[^/]*").replace(/<<G>>/g, ".*").replace(/\?/g, ".")).test(ctx.file));
436
+ if (!isWf) return;
437
+ const fn = ctx.file.split("/").pop() ?? ctx.file;
438
+ console.log(`[mm-dev] Recompiling ${fn}...`);
439
+ const br = await build({ src, outDir, mode, skipTypeCheck: true });
440
+ if (br.errors > 0) {
441
+ currentErrors = br.errorDetails.map((e) => ({ file: e.file, message: e.message, line: e.line }));
442
+ broadcast(clients, { type: "workflow:error", errors: br.errors, timestamp: ctx.timestamp });
443
+ return;
444
+ }
445
+ currentErrors = null;
446
+ if (token && !deployInFlight) {
447
+ deployInFlight = true;
448
+ try {
449
+ const { deploy: d } = await import("./deploy-VAHWALWB.mjs");
450
+ await d({ apiUrl, token, dir: outDir });
451
+ } catch {
452
+ } finally {
453
+ deployInFlight = false;
454
+ }
455
+ }
456
+ broadcast(clients, { type: "workflow:compiled", file: ctx.file, compiled: br.compiled, timestamp: ctx.timestamp });
457
+ }
458
+ };
459
+ const viteConfig = {
460
+ // Use the blueprint directory as Vite root (has node_modules with React).
461
+ root: process.cwd(),
462
+ // Pre-bundle React and the player for fast dev startup.
463
+ optimizeDeps: { include: ["react", "react-dom/client"] },
464
+ server: {
465
+ port,
466
+ open,
467
+ host: true,
468
+ // Allow serving files from the real project directory (fs.allow).
469
+ fs: { allow: [process.cwd(), ".."] },
470
+ proxy: {
471
+ "/api": { target: proxyTarget, changeOrigin: true, secure: true, ws: true },
472
+ "/health": { target: proxyTarget, changeOrigin: true, secure: true },
473
+ "/ws": { target: proxyTarget.replace(/^http/, "ws"), changeOrigin: true, ws: true }
474
+ }
475
+ },
476
+ plugins: [
477
+ mindmatrixReact(pluginOpts),
478
+ compileDeployPlugin,
479
+ devEntryPlugin,
480
+ devPlayerPlugin,
481
+ { name: "mindmatrix-error-overlay", configureServer(server) {
482
+ server.middlewares.use(errorOverlayMiddleware());
483
+ } }
484
+ ],
485
+ logLevel: "warn"
486
+ };
487
+ const { createServer } = await import("vite");
488
+ const vite = await createServer(viteConfig);
489
+ await vite.listen();
490
+ const resolvedPort = vite.config.server.port ?? port;
491
+ if (enableWs && vite.httpServer) {
492
+ try {
493
+ const wsM = await Function('return import("ws")')();
494
+ const WSS = wsM.WebSocketServer ?? wsM.default?.WebSocketServer;
495
+ if (WSS) {
496
+ const wss = new WSS({ server: vite.httpServer, path: "/__mm_dev" });
497
+ wss.on("connection", (s) => {
498
+ clients.add(s);
499
+ s.on("close", () => clients.delete(s));
500
+ s.send(JSON.stringify({ type: "mm:connected", version: "0.1.0", capabilities: ["compile", "deploy", "proxy", "notify", "error-overlay"] }));
501
+ });
502
+ }
503
+ } catch {
504
+ }
505
+ }
506
+ printBanner({ port: resolvedPort, apiUrl, src, include, health, token: !!token, compiled: initialCompiled, deployed: initialDeployed, slug: initialSlug, errors: initialErrors });
507
+ return {
508
+ vite,
509
+ port: resolvedPort,
510
+ clients,
511
+ async rebuild() {
512
+ const r = await build({ src, outDir, mode });
513
+ if (r.errors > 0) {
514
+ currentErrors = r.errorDetails.map((e) => ({ file: e.file, message: e.message, line: e.line }));
515
+ } else {
516
+ currentErrors = null;
517
+ if (token) {
518
+ try {
519
+ const { deploy: d } = await import("./deploy-VAHWALWB.mjs");
520
+ await d({ apiUrl, token, dir: outDir });
521
+ } catch {
522
+ }
523
+ }
524
+ }
525
+ broadcast(clients, { type: "workflow:rebuild", compiled: r.compiled, errors: r.errors, timestamp: Date.now() });
526
+ return r;
527
+ },
528
+ async close() {
529
+ for (const c of clients) {
530
+ try {
531
+ c.close();
532
+ } catch {
533
+ }
534
+ }
535
+ clients.clear();
536
+ currentErrors = null;
537
+ await vite.close();
538
+ }
539
+ };
540
+ }
541
+
542
+ export {
543
+ createDevServer
544
+ };
@@ -0,0 +1,148 @@
1
+ import {
2
+ build
3
+ } from "./chunk-3QHG2JWV.mjs";
4
+ import {
5
+ mindmatrixReact
6
+ } from "./chunk-KPDMN5IX.mjs";
7
+
8
+ // src/dev-server.ts
9
+ async function createDevServer(options = {}) {
10
+ const {
11
+ port = 5199,
12
+ src = "src/workflows",
13
+ mode = "infer",
14
+ include = ["**/*.workflow.tsx"],
15
+ outDir = "dist/workflows",
16
+ seed = false,
17
+ apiUrl = "http://localhost:4200/api/v1",
18
+ authToken = process.env.MINDMATRIX_TOKEN,
19
+ ws: enableWs = true,
20
+ open = false
21
+ } = options;
22
+ const clients = /* @__PURE__ */ new Set();
23
+ const pluginOptions = {
24
+ mode,
25
+ include,
26
+ outDir,
27
+ seedOnCompile: seed,
28
+ apiUrl,
29
+ authToken
30
+ };
31
+ const notifyPlugin = {
32
+ name: "mindmatrix-dev-notify",
33
+ enforce: "post",
34
+ handleHotUpdate(ctx) {
35
+ const isWorkflow = include.some((pattern) => {
36
+ const regex = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "<<GLOBSTAR>>").replace(/\*/g, "[^/]*").replace(/<<GLOBSTAR>>/g, ".*").replace(/\?/g, ".");
37
+ return new RegExp(regex).test(ctx.file);
38
+ });
39
+ if (!isWorkflow) return;
40
+ const message = JSON.stringify({
41
+ type: "workflow:compiled",
42
+ file: ctx.file,
43
+ timestamp: ctx.timestamp
44
+ });
45
+ for (const client of clients) {
46
+ try {
47
+ if (client.readyState === 1) {
48
+ client.send(message);
49
+ }
50
+ } catch {
51
+ clients.delete(client);
52
+ }
53
+ }
54
+ console.log(`[mm-dev] Compiled ${ctx.file.split("/").pop()} \u2014 notified ${clients.size} client(s)`);
55
+ }
56
+ };
57
+ const viteConfig = {
58
+ root: process.cwd(),
59
+ server: {
60
+ port,
61
+ open,
62
+ host: true
63
+ },
64
+ plugins: [
65
+ mindmatrixReact(pluginOptions),
66
+ notifyPlugin
67
+ ],
68
+ logLevel: "info"
69
+ };
70
+ const { createServer } = await import("vite");
71
+ const vite = await createServer(viteConfig);
72
+ await vite.listen();
73
+ const resolvedPort = vite.config.server.port ?? port;
74
+ if (enableWs && vite.httpServer) {
75
+ try {
76
+ const wsModule = await Function('return import("ws")')();
77
+ const WebSocketServer = wsModule.WebSocketServer ?? wsModule.default?.WebSocketServer;
78
+ if (WebSocketServer) {
79
+ const wss = new WebSocketServer({
80
+ server: vite.httpServer,
81
+ path: "/__mm_dev"
82
+ });
83
+ wss.on("connection", (socket) => {
84
+ clients.add(socket);
85
+ console.log(`[mm-dev] Editor connected (${clients.size} total)`);
86
+ socket.on("close", () => {
87
+ clients.delete(socket);
88
+ console.log(`[mm-dev] Editor disconnected (${clients.size} total)`);
89
+ });
90
+ socket.send(JSON.stringify({
91
+ type: "mm:connected",
92
+ version: "0.1.0",
93
+ capabilities: ["compile", "seed", "notify"]
94
+ }));
95
+ });
96
+ }
97
+ } catch {
98
+ console.warn("[mm-dev] ws package not available \u2014 WebSocket notifications disabled");
99
+ }
100
+ }
101
+ console.log(`
102
+ [mm-dev] MindMatrix Dev Server running`);
103
+ console.log(` Local: http://localhost:${resolvedPort}`);
104
+ console.log(` WebSocket: ws://localhost:${resolvedPort}/__mm_dev`);
105
+ console.log(` Watching: ${src} (${include.join(", ")})`);
106
+ if (seed) {
107
+ console.log(` Seeding: ${apiUrl}`);
108
+ }
109
+ console.log();
110
+ return {
111
+ vite,
112
+ port: resolvedPort,
113
+ clients,
114
+ async rebuild() {
115
+ console.log("[mm-dev] Full rebuild triggered...");
116
+ const result = await build({ src, outDir, mode });
117
+ const message = JSON.stringify({
118
+ type: "workflow:rebuild",
119
+ compiled: result.compiled,
120
+ errors: result.errors,
121
+ timestamp: Date.now()
122
+ });
123
+ for (const client of clients) {
124
+ try {
125
+ if (client.readyState === 1) client.send(message);
126
+ } catch {
127
+ clients.delete(client);
128
+ }
129
+ }
130
+ return result;
131
+ },
132
+ async close() {
133
+ for (const client of clients) {
134
+ try {
135
+ client.close();
136
+ } catch {
137
+ }
138
+ }
139
+ clients.clear();
140
+ await vite.close();
141
+ console.log("[mm-dev] Server stopped");
142
+ }
143
+ };
144
+ }
145
+
146
+ export {
147
+ createDevServer
148
+ };