@mmapp/react-compiler 0.1.0-alpha.4 → 0.1.0-alpha.6

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 (103) hide show
  1. package/dist/babel/index.d.mts +2 -2
  2. package/dist/babel/index.d.ts +2 -2
  3. package/dist/babel/index.js +5 -5
  4. package/dist/babel/index.mjs +1 -1
  5. package/dist/cli/index.js +797 -1941
  6. package/dist/cli/index.mjs +179 -77
  7. package/dist/codemod/cli.js +1 -1
  8. package/dist/codemod/cli.mjs +1 -1
  9. package/dist/codemod/index.d.mts +3 -3
  10. package/dist/codemod/index.d.ts +3 -3
  11. package/dist/codemod/index.js +1 -1
  12. package/dist/codemod/index.mjs +1 -1
  13. package/dist/dev-server.d.mts +2 -2
  14. package/dist/dev-server.d.ts +2 -2
  15. package/dist/dev-server.js +86 -1218
  16. package/dist/dev-server.mjs +4 -4
  17. package/dist/envelope.d.mts +2 -2
  18. package/dist/envelope.d.ts +2 -2
  19. package/dist/envelope.js +5 -5
  20. package/dist/envelope.mjs +2 -2
  21. package/dist/index.d.mts +8 -8
  22. package/dist/index.d.ts +8 -8
  23. package/dist/index.js +342 -1266
  24. package/dist/index.mjs +8 -8
  25. package/dist/testing/index.d.mts +8 -8
  26. package/dist/testing/index.d.ts +8 -8
  27. package/dist/testing/index.js +5 -5
  28. package/dist/testing/index.mjs +1 -1
  29. package/dist/vite/index.d.mts +1 -1
  30. package/dist/vite/index.d.ts +1 -1
  31. package/dist/vite/index.js +5 -5
  32. package/dist/vite/index.mjs +2 -2
  33. package/examples/authentication/main.workflow.tsx +1 -1
  34. package/examples/authentication/mm.config.ts +1 -1
  35. package/examples/authentication/pages/LoginPage.tsx +2 -2
  36. package/examples/authentication/pages/SignupPage.tsx +2 -2
  37. package/examples/counter.workflow.tsx +1 -1
  38. package/examples/dashboard.workflow.tsx +1 -1
  39. package/examples/invoice-approval/actions/invoice.server.ts +1 -1
  40. package/examples/invoice-approval/main.workflow.tsx +1 -1
  41. package/examples/invoice-approval/mm.config.ts +1 -1
  42. package/examples/invoice-approval/pages/InvoiceDetailPage.tsx +1 -1
  43. package/examples/invoice-approval/pages/InvoiceFormPage.tsx +1 -1
  44. package/examples/invoice-approval/pages/InvoiceListPage.tsx +1 -1
  45. package/examples/todo-app.workflow.tsx +1 -1
  46. package/examples/uber-app/actions/matching.server.ts +1 -1
  47. package/examples/uber-app/actions/notifications.server.ts +1 -1
  48. package/examples/uber-app/actions/payments.server.ts +1 -1
  49. package/examples/uber-app/actions/pricing.server.ts +1 -1
  50. package/examples/uber-app/app/admin/analytics.tsx +2 -2
  51. package/examples/uber-app/app/admin/fleet.tsx +2 -2
  52. package/examples/uber-app/app/admin/surge-pricing.tsx +2 -2
  53. package/examples/uber-app/app/driver/dashboard.tsx +2 -2
  54. package/examples/uber-app/app/driver/earnings.tsx +2 -2
  55. package/examples/uber-app/app/driver/navigation.tsx +2 -2
  56. package/examples/uber-app/app/driver/ride-acceptance.tsx +2 -2
  57. package/examples/uber-app/app/rider/home.tsx +2 -2
  58. package/examples/uber-app/app/rider/payment-methods.tsx +2 -2
  59. package/examples/uber-app/app/rider/ride-history.tsx +2 -2
  60. package/examples/uber-app/app/rider/ride-tracking.tsx +2 -2
  61. package/examples/uber-app/components/DriverCard.tsx +1 -1
  62. package/examples/uber-app/components/MapView.tsx +3 -3
  63. package/examples/uber-app/components/RatingStars.tsx +2 -2
  64. package/examples/uber-app/components/RideCard.tsx +1 -1
  65. package/examples/uber-app/mm.config.ts +1 -1
  66. package/examples/uber-app/workflows/dispute-resolution.workflow.tsx +2 -2
  67. package/examples/uber-app/workflows/driver-onboarding.workflow.tsx +2 -2
  68. package/examples/uber-app/workflows/payment-processing.workflow.tsx +2 -2
  69. package/examples/uber-app/workflows/ride-request.workflow.tsx +2 -2
  70. package/package.json +13 -9
  71. package/dist/auth-3UK75242.mjs +0 -17
  72. package/dist/chunk-5FTDWKHH.mjs +0 -244
  73. package/dist/chunk-7JRAEFRB.mjs +0 -7510
  74. package/dist/chunk-7T6Q5KAA.mjs +0 -7506
  75. package/dist/chunk-ABYPKRSB.mjs +0 -215
  76. package/dist/chunk-BZEXUPDH.mjs +0 -175
  77. package/dist/chunk-HRYR54PT.mjs +0 -175
  78. package/dist/chunk-J3M4GUS7.mjs +0 -161
  79. package/dist/chunk-JRGFBWTN.mjs +0 -2918
  80. package/dist/chunk-O4AUS7EU.mjs +0 -148
  81. package/dist/chunk-R2DD5GTY.mjs +0 -186
  82. package/dist/chunk-UDDTWG5J.mjs +0 -734
  83. package/dist/chunk-VLTKQDJ3.mjs +0 -244
  84. package/dist/chunk-WVYY32LD.mjs +0 -939
  85. package/dist/chunk-XDVM4YHX.mjs +0 -3450
  86. package/dist/chunk-Z2G5RZ4H.mjs +0 -186
  87. package/dist/chunk-ZE3KCHBM.mjs +0 -2918
  88. package/dist/deploy-YAJGW6II.mjs +0 -9
  89. package/dist/dev-server-CrQ041KP.d.mts +0 -79
  90. package/dist/dev-server-CrQ041KP.d.ts +0 -79
  91. package/dist/envelope-ChEkuHij.d.mts +0 -265
  92. package/dist/envelope-ChEkuHij.d.ts +0 -265
  93. package/dist/index-CEKyyazf.d.mts +0 -104
  94. package/dist/index-CEKyyazf.d.ts +0 -104
  95. package/dist/init-7FJENUDK.mjs +0 -407
  96. package/dist/project-compiler-NNK32MPG.mjs +0 -10
  97. package/dist/project-compiler-ZB4RUYVL.mjs +0 -10
  98. package/dist/project-decompiler-U55HQUHW.mjs +0 -7
  99. package/dist/pull-KOL2QAYQ.mjs +0 -109
  100. package/dist/seed-KOGEPGOJ.mjs +0 -154
  101. package/dist/server-VW6UPCHO.mjs +0 -277
  102. package/dist/verify-BYHUKARQ.mjs +0 -1833
  103. package/dist/verify-OQDEQYMS.mjs +0 -1833
@@ -1,109 +0,0 @@
1
- import {
2
- decompileProjectEnhanced
3
- } from "./chunk-XDVM4YHX.mjs";
4
- import "./chunk-CIESM3BP.mjs";
5
-
6
- // src/cli/pull.ts
7
- import { mkdirSync, writeFileSync } from "fs";
8
- import { join, dirname } from "path";
9
- async function pull(options) {
10
- const { slug, apiUrl, token } = options;
11
- const outDir = options.outDir ?? slug;
12
- console.log(`[mmrc pull] Fetching "${slug}" from ${apiUrl}...`);
13
- const ir = await fetchDefinition(apiUrl, token, slug);
14
- if (!ir) {
15
- throw new Error(`Definition "${slug}" not found`);
16
- }
17
- console.log(` Found: ${ir.name || ir.slug} (${ir.category || "workflow"}, v${ir.version || "1.0.0"})`);
18
- console.log(` Fields: ${ir.fields?.length ?? 0}, States: ${ir.states?.length ?? 0}, Transitions: ${ir.transitions?.length ?? 0}`);
19
- const result = decompileProjectEnhanced(ir);
20
- mkdirSync(outDir, { recursive: true });
21
- const filesWritten = [];
22
- for (const file of result.files) {
23
- const filePath = join(outDir, file.path);
24
- mkdirSync(dirname(filePath), { recursive: true });
25
- writeFileSync(filePath, file.content, "utf-8");
26
- filesWritten.push(file.path);
27
- console.log(` + ${file.path}`);
28
- }
29
- console.log(`
30
- [mmrc pull] Scaffolded ${filesWritten.length} files in ${outDir}/`);
31
- console.log(` Entry: ${result.entryFile}`);
32
- console.log(`
33
- Next steps:`);
34
- console.log(` cd ${outDir}`);
35
- console.log(` mmrc dev --src .`);
36
- console.log(` # Edit files, then deploy back:`);
37
- console.log(` mmrc deploy --src . --api-url ${apiUrl} --token <token>`);
38
- return { slug, filesWritten, outDir };
39
- }
40
- async function fetchDefinition(apiUrl, token, slug) {
41
- const bySlug = await tryFetch(`${apiUrl}/workflow/definitions?slug=${encodeURIComponent(slug)}`, token);
42
- if (bySlug) return bySlug;
43
- const bySearch = await tryFetch(`${apiUrl}/workflow/catalog/search?q=${encodeURIComponent(slug)}`, token);
44
- if (bySearch) return bySearch;
45
- const modulesRes = await fetch(`${apiUrl}/modules`, {
46
- headers: { Authorization: `Bearer ${token}` }
47
- });
48
- if (modulesRes.ok) {
49
- const modules = await modulesRes.json();
50
- const mod = modules.find((m) => m.module_id === slug || m.name?.toLowerCase() === slug.toLowerCase());
51
- if (mod) {
52
- const fullRes = await fetch(`${apiUrl}/workflow/definitions/${mod.module_id}`, {
53
- headers: { Authorization: `Bearer ${token}` }
54
- });
55
- if (fullRes.ok) {
56
- return normalizeApiResponse(await fullRes.json());
57
- }
58
- }
59
- }
60
- return null;
61
- }
62
- async function tryFetch(url, token) {
63
- try {
64
- const res = await fetch(url, {
65
- headers: { Authorization: `Bearer ${token}` }
66
- });
67
- if (!res.ok) return null;
68
- const data = await res.json();
69
- if (Array.isArray(data)) {
70
- if (data.length === 0) return null;
71
- return normalizeApiResponse(data[0]);
72
- }
73
- const items = data.items ?? data.data;
74
- if (items && Array.isArray(items)) {
75
- if (items.length === 0) return null;
76
- return normalizeApiResponse(items[0]);
77
- }
78
- return normalizeApiResponse(data);
79
- } catch {
80
- return null;
81
- }
82
- }
83
- function normalizeApiResponse(def) {
84
- const ir = {
85
- slug: def.slug,
86
- name: def.name,
87
- version: def.version || "1.0.0",
88
- description: def.description || "",
89
- category: def.category || "workflow",
90
- fields: def.fields || [],
91
- states: def.states || [],
92
- transitions: def.transitions || [],
93
- roles: def.roles || [],
94
- on_event: def.on_event || [],
95
- metadata: {
96
- ...def.metadata || {}
97
- }
98
- };
99
- const experience = def.view || def.experience || def.metadata?.experience;
100
- if (experience) {
101
- ir.experience = experience;
102
- ir.metadata.experience = experience;
103
- ir.view = experience;
104
- }
105
- return ir;
106
- }
107
- export {
108
- pull
109
- };
@@ -1,154 +0,0 @@
1
- import "./chunk-CIESM3BP.mjs";
2
-
3
- // src/cli/seed.ts
4
- import { readFileSync } from "fs";
5
- import { glob } from "glob";
6
- var FIRST_NAMES = ["Alice", "Bob", "Charlie", "Diana", "Eve", "Frank", "Grace", "Henry"];
7
- var LAST_NAMES = ["Smith", "Johnson", "Williams", "Brown", "Jones", "Garcia", "Miller", "Davis"];
8
- var COMPANIES = ["Acme Corp", "TechStart Inc", "GlobalTrade Ltd", "DataFlow Systems", "CloudPeak"];
9
- var LOREM_WORDS = ["lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing", "elit", "sed", "do", "eiusmod", "tempor"];
10
- var DOMAINS = ["example.com", "test.org", "demo.io", "sample.net"];
11
- var _counter = 0;
12
- function randomInt(min, max) {
13
- return Math.floor(Math.random() * (max - min + 1)) + min;
14
- }
15
- function randomPick(arr) {
16
- return arr[Math.floor(Math.random() * arr.length)];
17
- }
18
- function loremSentence(words = 5) {
19
- const result = [];
20
- for (let i = 0; i < words; i++) result.push(randomPick(LOREM_WORDS));
21
- const s = result.join(" ");
22
- return s.charAt(0).toUpperCase() + s.slice(1);
23
- }
24
- function generateFieldValue(field, index) {
25
- if (field.default_value !== void 0 && field.default_value !== null) {
26
- return field.default_value;
27
- }
28
- if (field.options && field.options.length > 0) {
29
- return field.options[index % field.options.length].value;
30
- }
31
- const ft = (field.field_type ?? field.type ?? "text").toLowerCase();
32
- switch (ft) {
33
- case "text":
34
- case "string":
35
- case "textarea":
36
- case "rich_text": {
37
- const name = field.name.toLowerCase();
38
- if (name.includes("email")) return `${randomPick(FIRST_NAMES).toLowerCase()}${++_counter}@${randomPick(DOMAINS)}`;
39
- if (name.includes("name") && name.includes("first")) return randomPick(FIRST_NAMES);
40
- if (name.includes("name") && name.includes("last")) return randomPick(LAST_NAMES);
41
- if (name.includes("name") || name === "title") return `${randomPick(FIRST_NAMES)} ${randomPick(LAST_NAMES)}`;
42
- if (name.includes("company") || name.includes("org")) return randomPick(COMPANIES);
43
- if (name.includes("phone")) return `+1-555-${randomInt(100, 999)}-${randomInt(1e3, 9999)}`;
44
- if (name.includes("url") || name.includes("website")) return `https://${randomPick(DOMAINS)}/${field.name}`;
45
- if (name.includes("description") || name.includes("note") || name.includes("comment")) return loremSentence(randomInt(8, 15));
46
- if (name.includes("address")) return `${randomInt(100, 9999)} ${loremSentence(2)} St`;
47
- return loremSentence(randomInt(2, 5));
48
- }
49
- case "number":
50
- case "numeric":
51
- case "integer":
52
- case "int": {
53
- const name = field.name.toLowerCase();
54
- if (name.includes("price") || name.includes("amount") || name.includes("cost") || name.includes("salary"))
55
- return randomInt(1e3, 99999) / 100;
56
- if (name.includes("age")) return randomInt(18, 65);
57
- if (name.includes("quantity") || name.includes("count") || name.includes("qty")) return randomInt(1, 100);
58
- if (name.includes("percent") || name.includes("rate")) return randomInt(1, 100);
59
- return randomInt(1, 1e3);
60
- }
61
- case "currency":
62
- case "decimal":
63
- return randomInt(100, 999999) / 100;
64
- case "boolean":
65
- case "bool":
66
- case "checkbox":
67
- case "toggle":
68
- return index % 2 === 0;
69
- case "date":
70
- case "datetime":
71
- case "timestamptz": {
72
- const d = /* @__PURE__ */ new Date();
73
- d.setDate(d.getDate() - randomInt(0, 365));
74
- return d.toISOString().split("T")[0];
75
- }
76
- case "select":
77
- case "enum":
78
- case "multi_select":
79
- return field.options?.[index % (field.options?.length || 1)]?.value ?? "option_1";
80
- case "email":
81
- return `${randomPick(FIRST_NAMES).toLowerCase()}${++_counter}@${randomPick(DOMAINS)}`;
82
- case "url":
83
- return `https://${randomPick(DOMAINS)}/${field.name}`;
84
- case "json":
85
- case "object":
86
- return {};
87
- case "array":
88
- return [];
89
- default:
90
- return loremSentence(3);
91
- }
92
- }
93
- function generateInstanceData(fields, index) {
94
- const data = {};
95
- for (const field of fields) {
96
- if (field.name === "id" || field.name === "created_at" || field.name === "updated_at") continue;
97
- data[field.name] = generateFieldValue(field, index);
98
- }
99
- return data;
100
- }
101
- async function seedInstances(options) {
102
- const dir = options.dir ?? "dist/workflows";
103
- const count = options.count ?? 7;
104
- const result = { created: 0, definitions: 0, errors: [] };
105
- const files = await glob(`${dir}/**/*.workflow.json`);
106
- if (files.length === 0) return result;
107
- for (const file of files) {
108
- let def;
109
- try {
110
- def = JSON.parse(readFileSync(file, "utf-8"));
111
- } catch {
112
- continue;
113
- }
114
- if (!def.slug || !def.fields || def.fields.length === 0) continue;
115
- const startState = def.states?.find((s) => s.state_type === "START")?.name ?? def.states?.[0]?.name ?? "initial";
116
- let defCreated = 0;
117
- for (let i = 0; i < count; i++) {
118
- const stateData = generateInstanceData(def.fields, i);
119
- try {
120
- const resp = await fetch(`${options.apiUrl}/workflow/instances`, {
121
- method: "POST",
122
- headers: {
123
- "Content-Type": "application/json",
124
- "Authorization": `Bearer ${options.token}`
125
- },
126
- body: JSON.stringify({
127
- definition_slug: def.slug,
128
- initial_state: startState,
129
- state_data: stateData
130
- })
131
- });
132
- if (resp.ok) {
133
- defCreated++;
134
- } else {
135
- const errText = await resp.text().catch(() => resp.statusText);
136
- result.errors.push(`${def.slug}[${i}]: ${resp.status} ${errText}`);
137
- }
138
- } catch (e) {
139
- result.errors.push(`${def.slug}[${i}]: ${e instanceof Error ? e.message : String(e)}`);
140
- }
141
- }
142
- if (defCreated > 0) {
143
- result.definitions++;
144
- result.created += defCreated;
145
- console.log(` [seed] ${def.slug}: ${defCreated} instances created`);
146
- }
147
- }
148
- return result;
149
- }
150
- export {
151
- generateFieldValue,
152
- generateInstanceData,
153
- seedInstances
154
- };
@@ -1,277 +0,0 @@
1
- import {
2
- __require
3
- } from "./chunk-CIESM3BP.mjs";
4
-
5
- // src/cli/server.ts
6
- import { existsSync, readFileSync, writeFileSync } from "fs";
7
- import { resolve } from "path";
8
- var BINARY_SEARCH_PATHS = [
9
- "engine/target/release/mm-server",
10
- "engine/target/debug/mm-server",
11
- "mm-core/target/release/mm-server",
12
- "mm-core/target/debug/mm-server",
13
- "target/release/mm-server",
14
- "target/debug/mm-server"
15
- ];
16
- function findServerBinary(explicitPath) {
17
- if (explicitPath) {
18
- return existsSync(explicitPath) ? explicitPath : null;
19
- }
20
- for (const rel of BINARY_SEARCH_PATHS) {
21
- const abs = resolve(process.cwd(), rel);
22
- if (existsSync(abs)) return abs;
23
- }
24
- try {
25
- const { execSync } = __require("child_process");
26
- const result = execSync("which mm-server 2>/dev/null || which mm-api 2>/dev/null", {
27
- encoding: "utf-8",
28
- timeout: 5e3
29
- }).trim();
30
- if (result) return result;
31
- } catch {
32
- }
33
- return null;
34
- }
35
- async function serverStart(options) {
36
- const binary = findServerBinary(options.binary);
37
- if (!binary) {
38
- console.error("[mmrc] Error: MindMatrix server binary not found.\n");
39
- console.error("To get the server binary, choose one of:");
40
- console.error("");
41
- console.error(" 1. Build from source:");
42
- console.error(" cd engine && cargo build --release -p mm-api");
43
- console.error("");
44
- console.error(" 2. Docker:");
45
- console.error(" docker pull mindmatrix/mm-server:latest");
46
- console.error(" docker run -p 4200:4200 mindmatrix/mm-server:latest");
47
- console.error("");
48
- console.error(" 3. Download from releases:");
49
- console.error(" https://github.com/mindmatrix/mm-server/releases");
50
- console.error("");
51
- console.error(" 4. Specify path directly:");
52
- console.error(" mmrc server start --binary /path/to/mm-server");
53
- process.exit(1);
54
- }
55
- console.log(`[mmrc] Starting server: ${binary}`);
56
- const args = [];
57
- const configPath = options.config ?? findConfigFile();
58
- if (configPath) {
59
- args.push("--config", configPath);
60
- console.log(`[mmrc] Config: ${configPath}`);
61
- }
62
- if (options.port) {
63
- process.env.PORT = String(options.port);
64
- console.log(`[mmrc] Port: ${options.port}`);
65
- }
66
- if (options.migrate) {
67
- console.log("[mmrc] Running migrations...");
68
- process.env.MM_RUN_MIGRATIONS = "true";
69
- }
70
- const { spawn } = __require("child_process");
71
- const child = spawn(binary, args, {
72
- stdio: "inherit",
73
- env: { ...process.env, MM_CONFIG_PATH: configPath ?? "" }
74
- });
75
- child.on("error", (err) => {
76
- console.error(`[mmrc] Failed to start server: ${err.message}`);
77
- process.exit(1);
78
- });
79
- child.on("exit", (code) => {
80
- process.exit(code ?? 0);
81
- });
82
- const forward = (signal) => {
83
- process.on(signal, () => child.kill(signal));
84
- };
85
- forward("SIGINT");
86
- forward("SIGTERM");
87
- }
88
- async function serverMigrate(options) {
89
- const apiUrl = options.apiUrl ?? "http://localhost:4200";
90
- try {
91
- console.log(`[mmrc] Requesting migration on ${apiUrl}...`);
92
- const res = await fetch(`${apiUrl}/api/v1/admin/migrate`, {
93
- method: "POST",
94
- headers: { "Content-Type": "application/json" }
95
- });
96
- if (res.ok) {
97
- const data = await res.json();
98
- console.log(`[mmrc] Migration complete: ${JSON.stringify(data)}`);
99
- return;
100
- }
101
- if (res.status !== 404) {
102
- console.warn(`[mmrc] Migration request failed: ${res.status}`);
103
- }
104
- } catch {
105
- }
106
- const binary = findServerBinary();
107
- if (!binary) {
108
- console.error("[mmrc] Error: Server not running and binary not found.");
109
- console.error(" Start the server first: mmrc server start");
110
- console.error(" Or build from source: cd engine && cargo build --release -p mm-api");
111
- process.exit(1);
112
- }
113
- console.log(`[mmrc] Running migrations via ${binary}...`);
114
- const { execSync } = __require("child_process");
115
- try {
116
- const configPath = options.config ?? findConfigFile();
117
- const env = { ...process.env, MM_RUN_MIGRATIONS: "true" };
118
- if (configPath) env.MM_CONFIG_PATH = configPath;
119
- execSync(`${binary} --migrate-only`, { stdio: "inherit", env });
120
- console.log("[mmrc] Migrations complete.");
121
- } catch (e) {
122
- console.error(`[mmrc] Migration failed: ${e.message}`);
123
- process.exit(1);
124
- }
125
- }
126
- function serverInit(options) {
127
- const output = options.output ?? "mm-server.toml";
128
- const mode = options.mode ?? "standalone";
129
- const db = options.db ?? "$env:DATABASE_URL";
130
- if (existsSync(output) && output !== "/dev/stdout") {
131
- console.error(`[mmrc] Error: ${output} already exists. Use --output to specify a different path.`);
132
- process.exit(1);
133
- }
134
- const content = generateServerToml(mode, db);
135
- writeFileSync(output, content, "utf-8");
136
- console.log(`[mmrc] Generated ${output} (mode: ${mode})`);
137
- console.log(`[mmrc] Edit the file, then run: mmrc server start`);
138
- }
139
- function generateServerToml(mode = "standalone", db = "$env:DATABASE_URL") {
140
- const lines = [];
141
- lines.push(`# MindMatrix Server Configuration`);
142
- lines.push(`# Generated by: mmrc server init --mode ${mode}`);
143
- lines.push(`# Docs: https://docs.mindmatrix.dev/server/configuration`);
144
- lines.push(`#`);
145
- lines.push(`# Environment variables can be referenced as $env:VAR_NAME`);
146
- lines.push(``);
147
- lines.push(`[server]`);
148
- lines.push(`# Server mode: "standalone" (all-in-one), "gateway" (API + routing), "worker" (action execution)`);
149
- lines.push(`mode = "${mode}"`);
150
- lines.push(`# Listen port (also configurable via PORT env var)`);
151
- lines.push(`port = 4200`);
152
- lines.push(`# Bind address`);
153
- lines.push(`host = "0.0.0.0"`);
154
- lines.push(``);
155
- lines.push(`[database]`);
156
- lines.push(`# PostgreSQL connection URL`);
157
- lines.push(`url = "${db}"`);
158
- lines.push(`# Connection pool size`);
159
- lines.push(`max_connections = 10`);
160
- lines.push(``);
161
- lines.push(`[auth]`);
162
- lines.push(`# JWT signing secret (also configurable via JWT_SECRET env var)`);
163
- lines.push(`jwt_secret = "$env:JWT_SECRET"`);
164
- lines.push(``);
165
- lines.push(`[telemetry]`);
166
- lines.push(`# Log output format: "pretty" (human-readable) or "json" (structured)`);
167
- lines.push(`log_format = "pretty"`);
168
- lines.push(`# Log level filter (RUST_LOG syntax)`);
169
- lines.push(`log_level = "mm_api=info,mm_storage=info,mm_engine=info"`);
170
- lines.push(`# OpenTelemetry OTLP endpoint (optional \u2014 enables distributed tracing)`);
171
- lines.push(`# otlp_endpoint = "http://localhost:4317"`);
172
- lines.push(``);
173
- if (mode === "gateway") {
174
- lines.push(`[gateway]`);
175
- lines.push(`# Worker pool for routing action execution`);
176
- lines.push(`pool = "default"`);
177
- lines.push(`# Maximum concurrent actions per worker`);
178
- lines.push(`max_concurrent = 16`);
179
- lines.push(`# Worker heartbeat interval`);
180
- lines.push(`heartbeat = "30s"`);
181
- lines.push(``);
182
- }
183
- if (mode !== "standalone") {
184
- lines.push(`[redis]`);
185
- lines.push(`# Redis URL for cross-instance communication`);
186
- lines.push(`url = "$env:REDIS_URL"`);
187
- lines.push(``);
188
- }
189
- lines.push(`[secrets]`);
190
- lines.push(`# Secret provider: "env" (environment variables) or "vault" (HashiCorp Vault)`);
191
- lines.push(`provider = "env"`);
192
- lines.push(``);
193
- lines.push(`# \u2500\u2500 Services \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`);
194
- lines.push(`# Register external services for action routing.`);
195
- lines.push(`# Each [[services]] block declares a service that can handle workflow actions.`);
196
- lines.push(`#`);
197
- lines.push(`# [[services]]`);
198
- lines.push(`# name = "email"`);
199
- lines.push(`# type = "webhook"`);
200
- lines.push(`# url = "https://hooks.example.com/email"`);
201
- lines.push(`# actions = ["send_email", "send_sms"]`);
202
- lines.push(`# [services.labels]`);
203
- lines.push(`# tier = "essential"`);
204
- lines.push(``);
205
- return lines.join("\n");
206
- }
207
- async function serverStatus(options) {
208
- const apiUrl = options.apiUrl ?? "http://localhost:4200";
209
- console.log(`[mmrc] Checking server at ${apiUrl}...`);
210
- try {
211
- const res = await fetch(`${apiUrl}/health`, { signal: AbortSignal.timeout(5e3) });
212
- if (!res.ok) {
213
- const result2 = {
214
- reachable: true,
215
- status: `unhealthy (HTTP ${res.status})`
216
- };
217
- console.log(`[mmrc] Server: ${result2.status}`);
218
- return result2;
219
- }
220
- const data = await res.json();
221
- const result = {
222
- reachable: true,
223
- status: data.status ?? "ok",
224
- version: data.version,
225
- uptime: data.uptime,
226
- database: data.database ?? data.db ?? void 0
227
- };
228
- console.log(`[mmrc] Server: ${result.status}`);
229
- if (result.version) console.log(`[mmrc] Version: ${result.version}`);
230
- if (result.uptime) console.log(`[mmrc] Uptime: ${result.uptime}`);
231
- if (result.database) console.log(`[mmrc] Database: ${result.database}`);
232
- return result;
233
- } catch (e) {
234
- const error = e.message;
235
- const result = { reachable: false, error };
236
- console.error(`[mmrc] Server unreachable: ${error}`);
237
- console.error(`[mmrc] Is the server running? Try: mmrc server start`);
238
- return result;
239
- }
240
- }
241
- function serverConfig(options) {
242
- const configPath = options.config ?? findConfigFile();
243
- if (!configPath) {
244
- console.log("[mmrc] No mm-server.toml found.");
245
- console.log("[mmrc] Generate one with: mmrc server init");
246
- return;
247
- }
248
- console.log(`[mmrc] Config file: ${configPath}
249
- `);
250
- const raw = readFileSync(configPath, "utf-8");
251
- const resolved = raw.replace(/\$env:(\w+)/g, (_match, varName) => {
252
- const val = process.env[varName];
253
- return val ? `${val} # \u2190 $env:${varName}` : `(unset) # \u2190 $env:${varName}`;
254
- });
255
- console.log(resolved);
256
- }
257
- function findConfigFile() {
258
- const candidates = [
259
- "mm-server.toml",
260
- "engine/mm-server.toml",
261
- "mm-core/mm-server.toml"
262
- ];
263
- for (const c of candidates) {
264
- const abs = resolve(process.cwd(), c);
265
- if (existsSync(abs)) return abs;
266
- }
267
- return null;
268
- }
269
- export {
270
- findServerBinary,
271
- generateServerToml,
272
- serverConfig,
273
- serverInit,
274
- serverMigrate,
275
- serverStart,
276
- serverStatus
277
- };