@nimblebrain/synapse 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-42N5BB5O.cjs +118 -0
- package/dist/chunk-42N5BB5O.cjs.map +1 -0
- package/dist/{chunk-AW3YIXLE.cjs → chunk-HLT5UBJF.cjs} +2 -116
- package/dist/chunk-HLT5UBJF.cjs.map +1 -0
- package/dist/{chunk-M4I222LB.js → chunk-JKHGWDZI.js} +3 -114
- package/dist/chunk-JKHGWDZI.js.map +1 -0
- package/dist/chunk-YWX3D24J.js +114 -0
- package/dist/chunk-YWX3D24J.js.map +1 -0
- package/dist/codegen/cli.cjs +58 -47
- package/dist/codegen/cli.cjs.map +1 -1
- package/dist/codegen/cli.js +58 -47
- package/dist/codegen/cli.js.map +1 -1
- package/dist/codegen/index.cjs +9 -8
- package/dist/codegen/index.js +2 -1
- package/dist/schema-reader-776246MJ.js +3 -0
- package/dist/schema-reader-776246MJ.js.map +1 -0
- package/dist/schema-reader-B6LTGBMJ.cjs +20 -0
- package/dist/schema-reader-B6LTGBMJ.cjs.map +1 -0
- package/dist/server-RUCX2TIB.js +204 -0
- package/dist/server-RUCX2TIB.js.map +1 -0
- package/dist/server-SEI7XI3B.cjs +206 -0
- package/dist/server-SEI7XI3B.cjs.map +1 -0
- package/dist/type-generator-MZ4X4DE5.js +3 -0
- package/dist/type-generator-MZ4X4DE5.js.map +1 -0
- package/dist/type-generator-UA3L4OIA.cjs +12 -0
- package/dist/type-generator-UA3L4OIA.cjs.map +1 -0
- package/dist/vite/index.cjs +248 -18
- package/dist/vite/index.cjs.map +1 -1
- package/dist/vite/index.d.cts +26 -12
- package/dist/vite/index.d.ts +26 -12
- package/dist/vite/index.js +248 -18
- package/dist/vite/index.js.map +1 -1
- package/dist/writer-NDK4U6C5.cjs +14 -0
- package/dist/writer-NDK4U6C5.cjs.map +1 -0
- package/dist/writer-ZNBXYUYC.js +12 -0
- package/dist/writer-ZNBXYUYC.js.map +1 -0
- package/package.json +13 -10
- package/dist/chunk-AW3YIXLE.cjs.map +0 -1
- package/dist/chunk-M4I222LB.js.map +0 -1
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { spawn } from 'child_process';
|
|
2
|
+
import { existsSync } from 'fs';
|
|
3
|
+
import { createServer } from 'http';
|
|
4
|
+
import { resolve, join } from 'path';
|
|
5
|
+
|
|
6
|
+
// src/preview/server.ts
|
|
7
|
+
var HOST_HTML = (uiPort, serverPort) => `<!DOCTYPE html>
|
|
8
|
+
<html>
|
|
9
|
+
<head>
|
|
10
|
+
<meta charset="utf-8" />
|
|
11
|
+
<title>Synapse Preview</title>
|
|
12
|
+
<style>
|
|
13
|
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
14
|
+
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: #0f172a; color: #e2e8f0; }
|
|
15
|
+
header { padding: 12px 20px; background: #1e293b; border-bottom: 1px solid #334155; display: flex; align-items: center; gap: 12px; }
|
|
16
|
+
header h1 { font-size: 14px; font-weight: 500; }
|
|
17
|
+
header .dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; }
|
|
18
|
+
header .info { font-size: 12px; color: #94a3b8; margin-left: auto; }
|
|
19
|
+
.theme-toggle { background: #334155; border: none; color: #e2e8f0; padding: 4px 10px; border-radius: 4px; cursor: pointer; font-size: 12px; }
|
|
20
|
+
iframe { width: 100%; height: calc(100vh - 45px); border: none; }
|
|
21
|
+
</style>
|
|
22
|
+
</head>
|
|
23
|
+
<body>
|
|
24
|
+
<header>
|
|
25
|
+
<span class="dot"></span>
|
|
26
|
+
<h1>Synapse Preview</h1>
|
|
27
|
+
<button class="theme-toggle" id="toggle">Toggle Dark/Light</button>
|
|
28
|
+
<span class="info">MCP: localhost:${serverPort} | UI: localhost:${uiPort}</span>
|
|
29
|
+
</header>
|
|
30
|
+
<iframe id="app" src="http://localhost:${uiPort}"></iframe>
|
|
31
|
+
|
|
32
|
+
<script>
|
|
33
|
+
var iframe = document.getElementById("app");
|
|
34
|
+
var darkMode = true;
|
|
35
|
+
|
|
36
|
+
// Minimal NimbleBrain bridge host \u2014 just enough to make Synapse work
|
|
37
|
+
var tokens = darkMode ? {
|
|
38
|
+
"--nb-background": "#0f172a", "--nb-foreground": "#e2e8f0",
|
|
39
|
+
"--nb-card": "#1e293b", "--nb-card-foreground": "#e2e8f0",
|
|
40
|
+
"--nb-primary": "#6366f1", "--nb-primary-foreground": "#ffffff",
|
|
41
|
+
"--nb-muted-foreground": "#94a3b8", "--nb-border": "#334155",
|
|
42
|
+
"--nb-ring": "#6366f1", "--nb-destructive": "#ef4444",
|
|
43
|
+
"--nb-radius": "0.5rem",
|
|
44
|
+
} : {
|
|
45
|
+
"--nb-background": "#ffffff", "--nb-foreground": "#1a1a1a",
|
|
46
|
+
"--nb-card": "#f9fafb", "--nb-card-foreground": "#1a1a1a",
|
|
47
|
+
"--nb-primary": "#6366f1", "--nb-primary-foreground": "#ffffff",
|
|
48
|
+
"--nb-muted-foreground": "#6b7280", "--nb-border": "#e5e7eb",
|
|
49
|
+
"--nb-ring": "#6366f1", "--nb-destructive": "#ef4444",
|
|
50
|
+
"--nb-radius": "0.5rem",
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
function post(msg) { iframe.contentWindow.postMessage(msg, "*"); }
|
|
54
|
+
|
|
55
|
+
window.addEventListener("message", async function (event) {
|
|
56
|
+
if (event.source !== iframe.contentWindow) return;
|
|
57
|
+
var msg = event.data;
|
|
58
|
+
if (!msg || typeof msg !== "object") return;
|
|
59
|
+
|
|
60
|
+
// ext-apps handshake
|
|
61
|
+
if (msg.method === "ui/initialize" && msg.id) {
|
|
62
|
+
post({
|
|
63
|
+
jsonrpc: "2.0", id: msg.id,
|
|
64
|
+
result: {
|
|
65
|
+
protocolVersion: "2026-01-26",
|
|
66
|
+
serverInfo: { name: "nimblebrain", version: "preview" },
|
|
67
|
+
capabilities: { openLinks: {}, serverTools: {} },
|
|
68
|
+
hostContext: { theme: darkMode ? "dark" : "light", primaryColor: "#6366f1", tokens: tokens }
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (msg.method === "ui/notifications/initialized") return;
|
|
75
|
+
|
|
76
|
+
// Tool call proxy \u2014 forward to the MCP server
|
|
77
|
+
if (msg.method === "tools/call" && msg.id) {
|
|
78
|
+
try {
|
|
79
|
+
var resp = await fetch("http://localhost:${serverPort}/mcp", {
|
|
80
|
+
method: "POST",
|
|
81
|
+
headers: { "Content-Type": "application/json" },
|
|
82
|
+
body: JSON.stringify({
|
|
83
|
+
jsonrpc: "2.0", id: msg.id,
|
|
84
|
+
method: "tools/call",
|
|
85
|
+
params: { name: msg.params.name, arguments: msg.params.arguments || {} }
|
|
86
|
+
})
|
|
87
|
+
});
|
|
88
|
+
var result = await resp.json();
|
|
89
|
+
// Forward the JSON-RPC response back to the iframe
|
|
90
|
+
post(result);
|
|
91
|
+
} catch (err) {
|
|
92
|
+
post({ jsonrpc: "2.0", id: msg.id, error: { code: -32000, message: err.message || "Server error" } });
|
|
93
|
+
}
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// ui/chat \u2014 log to console
|
|
98
|
+
if (msg.method === "ui/chat") {
|
|
99
|
+
console.log("[chat]", msg.params?.message);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// ui/action \u2014 log to console
|
|
104
|
+
if (msg.method === "ui/action") {
|
|
105
|
+
console.log("[action]", msg.params?.action, msg.params);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// ui/keydown \u2014 ignore in preview
|
|
110
|
+
if (msg.method === "ui/keydown") return;
|
|
111
|
+
|
|
112
|
+
// ui/stateChanged \u2014 log
|
|
113
|
+
if (msg.method === "ui/stateChanged") {
|
|
114
|
+
console.log("[state]", msg.params?.state);
|
|
115
|
+
post({ jsonrpc: "2.0", method: "ui/stateAcknowledged", params: { truncated: false } });
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
console.log("[bridge] unhandled:", msg.method, msg);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// Theme toggle
|
|
123
|
+
document.getElementById("toggle").addEventListener("click", function () {
|
|
124
|
+
darkMode = !darkMode;
|
|
125
|
+
document.body.style.background = darkMode ? "#0f172a" : "#f1f5f9";
|
|
126
|
+
tokens = darkMode ? {
|
|
127
|
+
"--nb-background": "#0f172a", "--nb-foreground": "#e2e8f0",
|
|
128
|
+
"--nb-card": "#1e293b", "--nb-card-foreground": "#e2e8f0",
|
|
129
|
+
"--nb-primary": "#6366f1", "--nb-primary-foreground": "#ffffff",
|
|
130
|
+
"--nb-muted-foreground": "#94a3b8", "--nb-border": "#334155",
|
|
131
|
+
"--nb-ring": "#6366f1", "--nb-destructive": "#ef4444",
|
|
132
|
+
"--nb-radius": "0.5rem",
|
|
133
|
+
} : {
|
|
134
|
+
"--nb-background": "#ffffff", "--nb-foreground": "#1a1a1a",
|
|
135
|
+
"--nb-card": "#f9fafb", "--nb-card-foreground": "#1a1a1a",
|
|
136
|
+
"--nb-primary": "#6366f1", "--nb-primary-foreground": "#ffffff",
|
|
137
|
+
"--nb-muted-foreground": "#6b7280", "--nb-border": "#e5e7eb",
|
|
138
|
+
"--nb-ring": "#6366f1", "--nb-destructive": "#ef4444",
|
|
139
|
+
"--nb-radius": "0.5rem",
|
|
140
|
+
};
|
|
141
|
+
post({ jsonrpc: "2.0", method: "ui/themeChanged", params: { mode: darkMode ? "dark" : "light", tokens: tokens } });
|
|
142
|
+
});
|
|
143
|
+
</script>
|
|
144
|
+
</body>
|
|
145
|
+
</html>`;
|
|
146
|
+
async function startPreview(options) {
|
|
147
|
+
const { serverCmd, serverPort, uiDir, uiPort, previewPort } = options;
|
|
148
|
+
const children = [];
|
|
149
|
+
console.log(`
|
|
150
|
+
Synapse Preview
|
|
151
|
+
`);
|
|
152
|
+
console.log(` [server] ${serverCmd}`);
|
|
153
|
+
const serverProc = spawn(serverCmd, {
|
|
154
|
+
shell: true,
|
|
155
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
156
|
+
});
|
|
157
|
+
children.push(serverProc);
|
|
158
|
+
serverProc.stdout?.on("data", (d) => process.stdout.write(` [server] ${d}`));
|
|
159
|
+
serverProc.stderr?.on("data", (d) => process.stderr.write(` [server] ${d}`));
|
|
160
|
+
const resolvedUi = resolve(uiDir);
|
|
161
|
+
if (!existsSync(join(resolvedUi, "package.json"))) {
|
|
162
|
+
console.error(` [ui] Error: no package.json found at ${resolvedUi}`);
|
|
163
|
+
process.exit(1);
|
|
164
|
+
}
|
|
165
|
+
console.log(` [ui] cd ${resolvedUi} && npx vite --port ${uiPort}`);
|
|
166
|
+
const uiProc = spawn("npx", ["vite", "--port", String(uiPort)], {
|
|
167
|
+
cwd: resolvedUi,
|
|
168
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
169
|
+
});
|
|
170
|
+
children.push(uiProc);
|
|
171
|
+
uiProc.stdout?.on("data", (d) => process.stdout.write(` [ui] ${d}`));
|
|
172
|
+
uiProc.stderr?.on("data", (d) => process.stderr.write(` [ui] ${d}`));
|
|
173
|
+
const html = HOST_HTML(uiPort, serverPort);
|
|
174
|
+
const host = createServer((_req, res) => {
|
|
175
|
+
res.writeHead(200, { "Content-Type": "text/html" });
|
|
176
|
+
res.end(html);
|
|
177
|
+
});
|
|
178
|
+
host.listen(previewPort, () => {
|
|
179
|
+
console.log(`
|
|
180
|
+
Preview: http://localhost:${previewPort}`);
|
|
181
|
+
console.log(` UI: http://localhost:${uiPort}`);
|
|
182
|
+
console.log(` Server: http://localhost:${serverPort}`);
|
|
183
|
+
console.log(`
|
|
184
|
+
Press Ctrl+C to stop.
|
|
185
|
+
`);
|
|
186
|
+
});
|
|
187
|
+
const shutdown = () => {
|
|
188
|
+
console.log("\n Shutting down...");
|
|
189
|
+
host.close();
|
|
190
|
+
for (const child of children) {
|
|
191
|
+
try {
|
|
192
|
+
child.kill("SIGTERM");
|
|
193
|
+
} catch {
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
process.exit(0);
|
|
197
|
+
};
|
|
198
|
+
process.on("SIGINT", shutdown);
|
|
199
|
+
process.on("SIGTERM", shutdown);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export { startPreview };
|
|
203
|
+
//# sourceMappingURL=server-RUCX2TIB.js.map
|
|
204
|
+
//# sourceMappingURL=server-RUCX2TIB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/preview/server.ts"],"names":[],"mappings":";;;;;;AA6BA,IAAM,SAAA,GAAY,CAAC,MAAA,EAAgB,UAAA,KAAuB,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sCAAA,EAqBlB,UAAU,oBAAoB,MAAM,CAAA;AAAA;AAAA,yCAAA,EAEjC,MAAM,CAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;;AAAA;AAAA;AAAA;AAAA,mDAAA,EAiDI,UAAU,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAAA;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OAAA,CAAQ,GAAA,CAAI,CAAA,6BAAA,EAAgC,UAAU,CAAA,CAAE,CAAA;AACxD,IAAA,OAAA,CAAQ,GAAA,CAAI;AAAA;AAAA,CAA6B,CAAA;AAAA,EAC3C,CAAC,CAAA;AAGD,EAAA,MAAM,WAAW,MAAM;AACrB,IAAA,OAAA,CAAQ,IAAI,sBAAsB,CAAA;AAClC,IAAA,IAAA,CAAK,KAAA,EAAM;AACX,IAAA,KAAA,MAAW,SAAS,QAAA,EAAU;AAC5B,MAAA,IAAI;AACF,QAAA,KAAA,CAAM,KAAK,SAAS,CAAA;AAAA,MACtB,CAAA,CAAA,MAAQ;AAAA,MAER;AAAA,IACF;AACA,IAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,EAChB,CAAA;AACA,EAAA,OAAA,CAAQ,EAAA,CAAG,UAAU,QAAQ,CAAA;AAC7B,EAAA,OAAA,CAAQ,EAAA,CAAG,WAAW,QAAQ,CAAA;AAChC","file":"server-RUCX2TIB.js","sourcesContent":["/**\n * Synapse Preview — standalone dev harness for MCP apps with UIs.\n *\n * Starts the MCP server (HTTP mode) and a minimal bridge host page\n * that iframes the app UI and proxies tool calls to the server.\n *\n * Usage:\n * npx synapse preview --server \"uv run uvicorn mcp_hello.server:app --port 8001\" --ui ./ui\n * npx synapse preview --server \"node dist/index.js\" --ui ./ui --server-port 8001\n */\n\nimport { type ChildProcess, spawn } from \"node:child_process\";\nimport { existsSync } from \"node:fs\";\nimport { createServer, type IncomingMessage, type ServerResponse } from \"node:http\";\nimport { join, resolve } from \"node:path\";\n\nexport interface PreviewOptions {\n /** Shell command to start the MCP server in HTTP mode */\n serverCmd: string;\n /** Port the MCP server listens on (default: 8001) */\n serverPort: number;\n /** Path to the UI directory (must have package.json with dev script) */\n uiDir: string;\n /** Port for the UI Vite dev server (default: 5173) */\n uiPort: number;\n /** Port for the preview harness (default: 5180) */\n previewPort: number;\n}\n\nconst HOST_HTML = (uiPort: number, serverPort: number) => `<!DOCTYPE html>\n<html>\n<head>\n <meta charset=\"utf-8\" />\n <title>Synapse Preview</title>\n <style>\n * { margin: 0; padding: 0; box-sizing: border-box; }\n body { font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif; background: #0f172a; color: #e2e8f0; }\n header { padding: 12px 20px; background: #1e293b; border-bottom: 1px solid #334155; display: flex; align-items: center; gap: 12px; }\n header h1 { font-size: 14px; font-weight: 500; }\n header .dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; }\n header .info { font-size: 12px; color: #94a3b8; margin-left: auto; }\n .theme-toggle { background: #334155; border: none; color: #e2e8f0; padding: 4px 10px; border-radius: 4px; cursor: pointer; font-size: 12px; }\n iframe { width: 100%; height: calc(100vh - 45px); border: none; }\n </style>\n</head>\n<body>\n <header>\n <span class=\"dot\"></span>\n <h1>Synapse Preview</h1>\n <button class=\"theme-toggle\" id=\"toggle\">Toggle Dark/Light</button>\n <span class=\"info\">MCP: localhost:${serverPort} | UI: localhost:${uiPort}</span>\n </header>\n <iframe id=\"app\" src=\"http://localhost:${uiPort}\"></iframe>\n\n <script>\n var iframe = document.getElementById(\"app\");\n var darkMode = true;\n\n // Minimal NimbleBrain bridge host — just enough to make Synapse work\n var tokens = darkMode ? {\n \"--nb-background\": \"#0f172a\", \"--nb-foreground\": \"#e2e8f0\",\n \"--nb-card\": \"#1e293b\", \"--nb-card-foreground\": \"#e2e8f0\",\n \"--nb-primary\": \"#6366f1\", \"--nb-primary-foreground\": \"#ffffff\",\n \"--nb-muted-foreground\": \"#94a3b8\", \"--nb-border\": \"#334155\",\n \"--nb-ring\": \"#6366f1\", \"--nb-destructive\": \"#ef4444\",\n \"--nb-radius\": \"0.5rem\",\n } : {\n \"--nb-background\": \"#ffffff\", \"--nb-foreground\": \"#1a1a1a\",\n \"--nb-card\": \"#f9fafb\", \"--nb-card-foreground\": \"#1a1a1a\",\n \"--nb-primary\": \"#6366f1\", \"--nb-primary-foreground\": \"#ffffff\",\n \"--nb-muted-foreground\": \"#6b7280\", \"--nb-border\": \"#e5e7eb\",\n \"--nb-ring\": \"#6366f1\", \"--nb-destructive\": \"#ef4444\",\n \"--nb-radius\": \"0.5rem\",\n };\n\n function post(msg) { iframe.contentWindow.postMessage(msg, \"*\"); }\n\n window.addEventListener(\"message\", async function (event) {\n if (event.source !== iframe.contentWindow) return;\n var msg = event.data;\n if (!msg || typeof msg !== \"object\") return;\n\n // ext-apps handshake\n if (msg.method === \"ui/initialize\" && msg.id) {\n post({\n jsonrpc: \"2.0\", id: msg.id,\n result: {\n protocolVersion: \"2026-01-26\",\n serverInfo: { name: \"nimblebrain\", version: \"preview\" },\n capabilities: { openLinks: {}, serverTools: {} },\n hostContext: { theme: darkMode ? \"dark\" : \"light\", primaryColor: \"#6366f1\", tokens: tokens }\n }\n });\n return;\n }\n\n if (msg.method === \"ui/notifications/initialized\") return;\n\n // Tool call proxy — forward to the MCP server\n if (msg.method === \"tools/call\" && msg.id) {\n try {\n var resp = await fetch(\"http://localhost:${serverPort}/mcp\", {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n jsonrpc: \"2.0\", id: msg.id,\n method: \"tools/call\",\n params: { name: msg.params.name, arguments: msg.params.arguments || {} }\n })\n });\n var result = await resp.json();\n // Forward the JSON-RPC response back to the iframe\n post(result);\n } catch (err) {\n post({ jsonrpc: \"2.0\", id: msg.id, error: { code: -32000, message: err.message || \"Server error\" } });\n }\n return;\n }\n\n // ui/chat — log to console\n if (msg.method === \"ui/chat\") {\n console.log(\"[chat]\", msg.params?.message);\n return;\n }\n\n // ui/action — log to console\n if (msg.method === \"ui/action\") {\n console.log(\"[action]\", msg.params?.action, msg.params);\n return;\n }\n\n // ui/keydown — ignore in preview\n if (msg.method === \"ui/keydown\") return;\n\n // ui/stateChanged — log\n if (msg.method === \"ui/stateChanged\") {\n console.log(\"[state]\", msg.params?.state);\n post({ jsonrpc: \"2.0\", method: \"ui/stateAcknowledged\", params: { truncated: false } });\n return;\n }\n\n console.log(\"[bridge] unhandled:\", msg.method, msg);\n });\n\n // Theme toggle\n document.getElementById(\"toggle\").addEventListener(\"click\", function () {\n darkMode = !darkMode;\n document.body.style.background = darkMode ? \"#0f172a\" : \"#f1f5f9\";\n tokens = darkMode ? {\n \"--nb-background\": \"#0f172a\", \"--nb-foreground\": \"#e2e8f0\",\n \"--nb-card\": \"#1e293b\", \"--nb-card-foreground\": \"#e2e8f0\",\n \"--nb-primary\": \"#6366f1\", \"--nb-primary-foreground\": \"#ffffff\",\n \"--nb-muted-foreground\": \"#94a3b8\", \"--nb-border\": \"#334155\",\n \"--nb-ring\": \"#6366f1\", \"--nb-destructive\": \"#ef4444\",\n \"--nb-radius\": \"0.5rem\",\n } : {\n \"--nb-background\": \"#ffffff\", \"--nb-foreground\": \"#1a1a1a\",\n \"--nb-card\": \"#f9fafb\", \"--nb-card-foreground\": \"#1a1a1a\",\n \"--nb-primary\": \"#6366f1\", \"--nb-primary-foreground\": \"#ffffff\",\n \"--nb-muted-foreground\": \"#6b7280\", \"--nb-border\": \"#e5e7eb\",\n \"--nb-ring\": \"#6366f1\", \"--nb-destructive\": \"#ef4444\",\n \"--nb-radius\": \"0.5rem\",\n };\n post({ jsonrpc: \"2.0\", method: \"ui/themeChanged\", params: { mode: darkMode ? \"dark\" : \"light\", tokens: tokens } });\n });\n </script>\n</body>\n</html>`;\n\nexport async function startPreview(options: PreviewOptions): Promise<void> {\n const { serverCmd, serverPort, uiDir, uiPort, previewPort } = options;\n const children: ChildProcess[] = [];\n\n console.log(`\\n Synapse Preview\\n`);\n\n // 1. Start MCP server\n console.log(` [server] ${serverCmd}`);\n const serverProc = spawn(serverCmd, {\n shell: true,\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n });\n children.push(serverProc);\n serverProc.stdout?.on(\"data\", (d: Buffer) => process.stdout.write(` [server] ${d}`));\n serverProc.stderr?.on(\"data\", (d: Buffer) => process.stderr.write(` [server] ${d}`));\n\n // 2. Start UI Vite dev server\n const resolvedUi = resolve(uiDir);\n if (!existsSync(join(resolvedUi, \"package.json\"))) {\n console.error(` [ui] Error: no package.json found at ${resolvedUi}`);\n process.exit(1);\n }\n console.log(` [ui] cd ${resolvedUi} && npx vite --port ${uiPort}`);\n const uiProc = spawn(\"npx\", [\"vite\", \"--port\", String(uiPort)], {\n cwd: resolvedUi,\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n });\n children.push(uiProc);\n uiProc.stdout?.on(\"data\", (d: Buffer) => process.stdout.write(` [ui] ${d}`));\n uiProc.stderr?.on(\"data\", (d: Buffer) => process.stderr.write(` [ui] ${d}`));\n\n // 3. Start preview host\n const html = HOST_HTML(uiPort, serverPort);\n const host = createServer((_req: IncomingMessage, res: ServerResponse) => {\n res.writeHead(200, { \"Content-Type\": \"text/html\" });\n res.end(html);\n });\n host.listen(previewPort, () => {\n console.log(`\\n Preview: http://localhost:${previewPort}`);\n console.log(` UI: http://localhost:${uiPort}`);\n console.log(` Server: http://localhost:${serverPort}`);\n console.log(`\\n Press Ctrl+C to stop.\\n`);\n });\n\n // Shutdown\n const shutdown = () => {\n console.log(\"\\n Shutting down...\");\n host.close();\n for (const child of children) {\n try {\n child.kill(\"SIGTERM\");\n } catch {\n /* already dead */\n }\n }\n process.exit(0);\n };\n process.on(\"SIGINT\", shutdown);\n process.on(\"SIGTERM\", shutdown);\n}\n"]}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var child_process = require('child_process');
|
|
4
|
+
var fs = require('fs');
|
|
5
|
+
var http = require('http');
|
|
6
|
+
var path = require('path');
|
|
7
|
+
|
|
8
|
+
// src/preview/server.ts
|
|
9
|
+
var HOST_HTML = (uiPort, serverPort) => `<!DOCTYPE html>
|
|
10
|
+
<html>
|
|
11
|
+
<head>
|
|
12
|
+
<meta charset="utf-8" />
|
|
13
|
+
<title>Synapse Preview</title>
|
|
14
|
+
<style>
|
|
15
|
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
16
|
+
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: #0f172a; color: #e2e8f0; }
|
|
17
|
+
header { padding: 12px 20px; background: #1e293b; border-bottom: 1px solid #334155; display: flex; align-items: center; gap: 12px; }
|
|
18
|
+
header h1 { font-size: 14px; font-weight: 500; }
|
|
19
|
+
header .dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; }
|
|
20
|
+
header .info { font-size: 12px; color: #94a3b8; margin-left: auto; }
|
|
21
|
+
.theme-toggle { background: #334155; border: none; color: #e2e8f0; padding: 4px 10px; border-radius: 4px; cursor: pointer; font-size: 12px; }
|
|
22
|
+
iframe { width: 100%; height: calc(100vh - 45px); border: none; }
|
|
23
|
+
</style>
|
|
24
|
+
</head>
|
|
25
|
+
<body>
|
|
26
|
+
<header>
|
|
27
|
+
<span class="dot"></span>
|
|
28
|
+
<h1>Synapse Preview</h1>
|
|
29
|
+
<button class="theme-toggle" id="toggle">Toggle Dark/Light</button>
|
|
30
|
+
<span class="info">MCP: localhost:${serverPort} | UI: localhost:${uiPort}</span>
|
|
31
|
+
</header>
|
|
32
|
+
<iframe id="app" src="http://localhost:${uiPort}"></iframe>
|
|
33
|
+
|
|
34
|
+
<script>
|
|
35
|
+
var iframe = document.getElementById("app");
|
|
36
|
+
var darkMode = true;
|
|
37
|
+
|
|
38
|
+
// Minimal NimbleBrain bridge host \u2014 just enough to make Synapse work
|
|
39
|
+
var tokens = darkMode ? {
|
|
40
|
+
"--nb-background": "#0f172a", "--nb-foreground": "#e2e8f0",
|
|
41
|
+
"--nb-card": "#1e293b", "--nb-card-foreground": "#e2e8f0",
|
|
42
|
+
"--nb-primary": "#6366f1", "--nb-primary-foreground": "#ffffff",
|
|
43
|
+
"--nb-muted-foreground": "#94a3b8", "--nb-border": "#334155",
|
|
44
|
+
"--nb-ring": "#6366f1", "--nb-destructive": "#ef4444",
|
|
45
|
+
"--nb-radius": "0.5rem",
|
|
46
|
+
} : {
|
|
47
|
+
"--nb-background": "#ffffff", "--nb-foreground": "#1a1a1a",
|
|
48
|
+
"--nb-card": "#f9fafb", "--nb-card-foreground": "#1a1a1a",
|
|
49
|
+
"--nb-primary": "#6366f1", "--nb-primary-foreground": "#ffffff",
|
|
50
|
+
"--nb-muted-foreground": "#6b7280", "--nb-border": "#e5e7eb",
|
|
51
|
+
"--nb-ring": "#6366f1", "--nb-destructive": "#ef4444",
|
|
52
|
+
"--nb-radius": "0.5rem",
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
function post(msg) { iframe.contentWindow.postMessage(msg, "*"); }
|
|
56
|
+
|
|
57
|
+
window.addEventListener("message", async function (event) {
|
|
58
|
+
if (event.source !== iframe.contentWindow) return;
|
|
59
|
+
var msg = event.data;
|
|
60
|
+
if (!msg || typeof msg !== "object") return;
|
|
61
|
+
|
|
62
|
+
// ext-apps handshake
|
|
63
|
+
if (msg.method === "ui/initialize" && msg.id) {
|
|
64
|
+
post({
|
|
65
|
+
jsonrpc: "2.0", id: msg.id,
|
|
66
|
+
result: {
|
|
67
|
+
protocolVersion: "2026-01-26",
|
|
68
|
+
serverInfo: { name: "nimblebrain", version: "preview" },
|
|
69
|
+
capabilities: { openLinks: {}, serverTools: {} },
|
|
70
|
+
hostContext: { theme: darkMode ? "dark" : "light", primaryColor: "#6366f1", tokens: tokens }
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (msg.method === "ui/notifications/initialized") return;
|
|
77
|
+
|
|
78
|
+
// Tool call proxy \u2014 forward to the MCP server
|
|
79
|
+
if (msg.method === "tools/call" && msg.id) {
|
|
80
|
+
try {
|
|
81
|
+
var resp = await fetch("http://localhost:${serverPort}/mcp", {
|
|
82
|
+
method: "POST",
|
|
83
|
+
headers: { "Content-Type": "application/json" },
|
|
84
|
+
body: JSON.stringify({
|
|
85
|
+
jsonrpc: "2.0", id: msg.id,
|
|
86
|
+
method: "tools/call",
|
|
87
|
+
params: { name: msg.params.name, arguments: msg.params.arguments || {} }
|
|
88
|
+
})
|
|
89
|
+
});
|
|
90
|
+
var result = await resp.json();
|
|
91
|
+
// Forward the JSON-RPC response back to the iframe
|
|
92
|
+
post(result);
|
|
93
|
+
} catch (err) {
|
|
94
|
+
post({ jsonrpc: "2.0", id: msg.id, error: { code: -32000, message: err.message || "Server error" } });
|
|
95
|
+
}
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// ui/chat \u2014 log to console
|
|
100
|
+
if (msg.method === "ui/chat") {
|
|
101
|
+
console.log("[chat]", msg.params?.message);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// ui/action \u2014 log to console
|
|
106
|
+
if (msg.method === "ui/action") {
|
|
107
|
+
console.log("[action]", msg.params?.action, msg.params);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// ui/keydown \u2014 ignore in preview
|
|
112
|
+
if (msg.method === "ui/keydown") return;
|
|
113
|
+
|
|
114
|
+
// ui/stateChanged \u2014 log
|
|
115
|
+
if (msg.method === "ui/stateChanged") {
|
|
116
|
+
console.log("[state]", msg.params?.state);
|
|
117
|
+
post({ jsonrpc: "2.0", method: "ui/stateAcknowledged", params: { truncated: false } });
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
console.log("[bridge] unhandled:", msg.method, msg);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// Theme toggle
|
|
125
|
+
document.getElementById("toggle").addEventListener("click", function () {
|
|
126
|
+
darkMode = !darkMode;
|
|
127
|
+
document.body.style.background = darkMode ? "#0f172a" : "#f1f5f9";
|
|
128
|
+
tokens = darkMode ? {
|
|
129
|
+
"--nb-background": "#0f172a", "--nb-foreground": "#e2e8f0",
|
|
130
|
+
"--nb-card": "#1e293b", "--nb-card-foreground": "#e2e8f0",
|
|
131
|
+
"--nb-primary": "#6366f1", "--nb-primary-foreground": "#ffffff",
|
|
132
|
+
"--nb-muted-foreground": "#94a3b8", "--nb-border": "#334155",
|
|
133
|
+
"--nb-ring": "#6366f1", "--nb-destructive": "#ef4444",
|
|
134
|
+
"--nb-radius": "0.5rem",
|
|
135
|
+
} : {
|
|
136
|
+
"--nb-background": "#ffffff", "--nb-foreground": "#1a1a1a",
|
|
137
|
+
"--nb-card": "#f9fafb", "--nb-card-foreground": "#1a1a1a",
|
|
138
|
+
"--nb-primary": "#6366f1", "--nb-primary-foreground": "#ffffff",
|
|
139
|
+
"--nb-muted-foreground": "#6b7280", "--nb-border": "#e5e7eb",
|
|
140
|
+
"--nb-ring": "#6366f1", "--nb-destructive": "#ef4444",
|
|
141
|
+
"--nb-radius": "0.5rem",
|
|
142
|
+
};
|
|
143
|
+
post({ jsonrpc: "2.0", method: "ui/themeChanged", params: { mode: darkMode ? "dark" : "light", tokens: tokens } });
|
|
144
|
+
});
|
|
145
|
+
</script>
|
|
146
|
+
</body>
|
|
147
|
+
</html>`;
|
|
148
|
+
async function startPreview(options) {
|
|
149
|
+
const { serverCmd, serverPort, uiDir, uiPort, previewPort } = options;
|
|
150
|
+
const children = [];
|
|
151
|
+
console.log(`
|
|
152
|
+
Synapse Preview
|
|
153
|
+
`);
|
|
154
|
+
console.log(` [server] ${serverCmd}`);
|
|
155
|
+
const serverProc = child_process.spawn(serverCmd, {
|
|
156
|
+
shell: true,
|
|
157
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
158
|
+
});
|
|
159
|
+
children.push(serverProc);
|
|
160
|
+
serverProc.stdout?.on("data", (d) => process.stdout.write(` [server] ${d}`));
|
|
161
|
+
serverProc.stderr?.on("data", (d) => process.stderr.write(` [server] ${d}`));
|
|
162
|
+
const resolvedUi = path.resolve(uiDir);
|
|
163
|
+
if (!fs.existsSync(path.join(resolvedUi, "package.json"))) {
|
|
164
|
+
console.error(` [ui] Error: no package.json found at ${resolvedUi}`);
|
|
165
|
+
process.exit(1);
|
|
166
|
+
}
|
|
167
|
+
console.log(` [ui] cd ${resolvedUi} && npx vite --port ${uiPort}`);
|
|
168
|
+
const uiProc = child_process.spawn("npx", ["vite", "--port", String(uiPort)], {
|
|
169
|
+
cwd: resolvedUi,
|
|
170
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
171
|
+
});
|
|
172
|
+
children.push(uiProc);
|
|
173
|
+
uiProc.stdout?.on("data", (d) => process.stdout.write(` [ui] ${d}`));
|
|
174
|
+
uiProc.stderr?.on("data", (d) => process.stderr.write(` [ui] ${d}`));
|
|
175
|
+
const html = HOST_HTML(uiPort, serverPort);
|
|
176
|
+
const host = http.createServer((_req, res) => {
|
|
177
|
+
res.writeHead(200, { "Content-Type": "text/html" });
|
|
178
|
+
res.end(html);
|
|
179
|
+
});
|
|
180
|
+
host.listen(previewPort, () => {
|
|
181
|
+
console.log(`
|
|
182
|
+
Preview: http://localhost:${previewPort}`);
|
|
183
|
+
console.log(` UI: http://localhost:${uiPort}`);
|
|
184
|
+
console.log(` Server: http://localhost:${serverPort}`);
|
|
185
|
+
console.log(`
|
|
186
|
+
Press Ctrl+C to stop.
|
|
187
|
+
`);
|
|
188
|
+
});
|
|
189
|
+
const shutdown = () => {
|
|
190
|
+
console.log("\n Shutting down...");
|
|
191
|
+
host.close();
|
|
192
|
+
for (const child of children) {
|
|
193
|
+
try {
|
|
194
|
+
child.kill("SIGTERM");
|
|
195
|
+
} catch {
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
process.exit(0);
|
|
199
|
+
};
|
|
200
|
+
process.on("SIGINT", shutdown);
|
|
201
|
+
process.on("SIGTERM", shutdown);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
exports.startPreview = startPreview;
|
|
205
|
+
//# sourceMappingURL=server-SEI7XI3B.cjs.map
|
|
206
|
+
//# sourceMappingURL=server-SEI7XI3B.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/preview/server.ts"],"names":["spawn","resolve","existsSync","join","createServer"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IACF;AACA,IAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,EAChB,CAAA;AACA,EAAA,OAAA,CAAQ,EAAA,CAAG,UAAU,QAAQ,CAAA;AAC7B,EAAA,OAAA,CAAQ,EAAA,CAAG,WAAW,QAAQ,CAAA;AAChC","file":"server-SEI7XI3B.cjs","sourcesContent":["/**\n * Synapse Preview — standalone dev harness for MCP apps with UIs.\n *\n * Starts the MCP server (HTTP mode) and a minimal bridge host page\n * that iframes the app UI and proxies tool calls to the server.\n *\n * Usage:\n * npx synapse preview --server \"uv run uvicorn mcp_hello.server:app --port 8001\" --ui ./ui\n * npx synapse preview --server \"node dist/index.js\" --ui ./ui --server-port 8001\n */\n\nimport { type ChildProcess, spawn } from \"node:child_process\";\nimport { existsSync } from \"node:fs\";\nimport { createServer, type IncomingMessage, type ServerResponse } from \"node:http\";\nimport { join, resolve } from \"node:path\";\n\nexport interface PreviewOptions {\n /** Shell command to start the MCP server in HTTP mode */\n serverCmd: string;\n /** Port the MCP server listens on (default: 8001) */\n serverPort: number;\n /** Path to the UI directory (must have package.json with dev script) */\n uiDir: string;\n /** Port for the UI Vite dev server (default: 5173) */\n uiPort: number;\n /** Port for the preview harness (default: 5180) */\n previewPort: number;\n}\n\nconst HOST_HTML = (uiPort: number, serverPort: number) => `<!DOCTYPE html>\n<html>\n<head>\n <meta charset=\"utf-8\" />\n <title>Synapse Preview</title>\n <style>\n * { margin: 0; padding: 0; box-sizing: border-box; }\n body { font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif; background: #0f172a; color: #e2e8f0; }\n header { padding: 12px 20px; background: #1e293b; border-bottom: 1px solid #334155; display: flex; align-items: center; gap: 12px; }\n header h1 { font-size: 14px; font-weight: 500; }\n header .dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; }\n header .info { font-size: 12px; color: #94a3b8; margin-left: auto; }\n .theme-toggle { background: #334155; border: none; color: #e2e8f0; padding: 4px 10px; border-radius: 4px; cursor: pointer; font-size: 12px; }\n iframe { width: 100%; height: calc(100vh - 45px); border: none; }\n </style>\n</head>\n<body>\n <header>\n <span class=\"dot\"></span>\n <h1>Synapse Preview</h1>\n <button class=\"theme-toggle\" id=\"toggle\">Toggle Dark/Light</button>\n <span class=\"info\">MCP: localhost:${serverPort} | UI: localhost:${uiPort}</span>\n </header>\n <iframe id=\"app\" src=\"http://localhost:${uiPort}\"></iframe>\n\n <script>\n var iframe = document.getElementById(\"app\");\n var darkMode = true;\n\n // Minimal NimbleBrain bridge host — just enough to make Synapse work\n var tokens = darkMode ? {\n \"--nb-background\": \"#0f172a\", \"--nb-foreground\": \"#e2e8f0\",\n \"--nb-card\": \"#1e293b\", \"--nb-card-foreground\": \"#e2e8f0\",\n \"--nb-primary\": \"#6366f1\", \"--nb-primary-foreground\": \"#ffffff\",\n \"--nb-muted-foreground\": \"#94a3b8\", \"--nb-border\": \"#334155\",\n \"--nb-ring\": \"#6366f1\", \"--nb-destructive\": \"#ef4444\",\n \"--nb-radius\": \"0.5rem\",\n } : {\n \"--nb-background\": \"#ffffff\", \"--nb-foreground\": \"#1a1a1a\",\n \"--nb-card\": \"#f9fafb\", \"--nb-card-foreground\": \"#1a1a1a\",\n \"--nb-primary\": \"#6366f1\", \"--nb-primary-foreground\": \"#ffffff\",\n \"--nb-muted-foreground\": \"#6b7280\", \"--nb-border\": \"#e5e7eb\",\n \"--nb-ring\": \"#6366f1\", \"--nb-destructive\": \"#ef4444\",\n \"--nb-radius\": \"0.5rem\",\n };\n\n function post(msg) { iframe.contentWindow.postMessage(msg, \"*\"); }\n\n window.addEventListener(\"message\", async function (event) {\n if (event.source !== iframe.contentWindow) return;\n var msg = event.data;\n if (!msg || typeof msg !== \"object\") return;\n\n // ext-apps handshake\n if (msg.method === \"ui/initialize\" && msg.id) {\n post({\n jsonrpc: \"2.0\", id: msg.id,\n result: {\n protocolVersion: \"2026-01-26\",\n serverInfo: { name: \"nimblebrain\", version: \"preview\" },\n capabilities: { openLinks: {}, serverTools: {} },\n hostContext: { theme: darkMode ? \"dark\" : \"light\", primaryColor: \"#6366f1\", tokens: tokens }\n }\n });\n return;\n }\n\n if (msg.method === \"ui/notifications/initialized\") return;\n\n // Tool call proxy — forward to the MCP server\n if (msg.method === \"tools/call\" && msg.id) {\n try {\n var resp = await fetch(\"http://localhost:${serverPort}/mcp\", {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n jsonrpc: \"2.0\", id: msg.id,\n method: \"tools/call\",\n params: { name: msg.params.name, arguments: msg.params.arguments || {} }\n })\n });\n var result = await resp.json();\n // Forward the JSON-RPC response back to the iframe\n post(result);\n } catch (err) {\n post({ jsonrpc: \"2.0\", id: msg.id, error: { code: -32000, message: err.message || \"Server error\" } });\n }\n return;\n }\n\n // ui/chat — log to console\n if (msg.method === \"ui/chat\") {\n console.log(\"[chat]\", msg.params?.message);\n return;\n }\n\n // ui/action — log to console\n if (msg.method === \"ui/action\") {\n console.log(\"[action]\", msg.params?.action, msg.params);\n return;\n }\n\n // ui/keydown — ignore in preview\n if (msg.method === \"ui/keydown\") return;\n\n // ui/stateChanged — log\n if (msg.method === \"ui/stateChanged\") {\n console.log(\"[state]\", msg.params?.state);\n post({ jsonrpc: \"2.0\", method: \"ui/stateAcknowledged\", params: { truncated: false } });\n return;\n }\n\n console.log(\"[bridge] unhandled:\", msg.method, msg);\n });\n\n // Theme toggle\n document.getElementById(\"toggle\").addEventListener(\"click\", function () {\n darkMode = !darkMode;\n document.body.style.background = darkMode ? \"#0f172a\" : \"#f1f5f9\";\n tokens = darkMode ? {\n \"--nb-background\": \"#0f172a\", \"--nb-foreground\": \"#e2e8f0\",\n \"--nb-card\": \"#1e293b\", \"--nb-card-foreground\": \"#e2e8f0\",\n \"--nb-primary\": \"#6366f1\", \"--nb-primary-foreground\": \"#ffffff\",\n \"--nb-muted-foreground\": \"#94a3b8\", \"--nb-border\": \"#334155\",\n \"--nb-ring\": \"#6366f1\", \"--nb-destructive\": \"#ef4444\",\n \"--nb-radius\": \"0.5rem\",\n } : {\n \"--nb-background\": \"#ffffff\", \"--nb-foreground\": \"#1a1a1a\",\n \"--nb-card\": \"#f9fafb\", \"--nb-card-foreground\": \"#1a1a1a\",\n \"--nb-primary\": \"#6366f1\", \"--nb-primary-foreground\": \"#ffffff\",\n \"--nb-muted-foreground\": \"#6b7280\", \"--nb-border\": \"#e5e7eb\",\n \"--nb-ring\": \"#6366f1\", \"--nb-destructive\": \"#ef4444\",\n \"--nb-radius\": \"0.5rem\",\n };\n post({ jsonrpc: \"2.0\", method: \"ui/themeChanged\", params: { mode: darkMode ? \"dark\" : \"light\", tokens: tokens } });\n });\n </script>\n</body>\n</html>`;\n\nexport async function startPreview(options: PreviewOptions): Promise<void> {\n const { serverCmd, serverPort, uiDir, uiPort, previewPort } = options;\n const children: ChildProcess[] = [];\n\n console.log(`\\n Synapse Preview\\n`);\n\n // 1. Start MCP server\n console.log(` [server] ${serverCmd}`);\n const serverProc = spawn(serverCmd, {\n shell: true,\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n });\n children.push(serverProc);\n serverProc.stdout?.on(\"data\", (d: Buffer) => process.stdout.write(` [server] ${d}`));\n serverProc.stderr?.on(\"data\", (d: Buffer) => process.stderr.write(` [server] ${d}`));\n\n // 2. Start UI Vite dev server\n const resolvedUi = resolve(uiDir);\n if (!existsSync(join(resolvedUi, \"package.json\"))) {\n console.error(` [ui] Error: no package.json found at ${resolvedUi}`);\n process.exit(1);\n }\n console.log(` [ui] cd ${resolvedUi} && npx vite --port ${uiPort}`);\n const uiProc = spawn(\"npx\", [\"vite\", \"--port\", String(uiPort)], {\n cwd: resolvedUi,\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n });\n children.push(uiProc);\n uiProc.stdout?.on(\"data\", (d: Buffer) => process.stdout.write(` [ui] ${d}`));\n uiProc.stderr?.on(\"data\", (d: Buffer) => process.stderr.write(` [ui] ${d}`));\n\n // 3. Start preview host\n const html = HOST_HTML(uiPort, serverPort);\n const host = createServer((_req: IncomingMessage, res: ServerResponse) => {\n res.writeHead(200, { \"Content-Type\": \"text/html\" });\n res.end(html);\n });\n host.listen(previewPort, () => {\n console.log(`\\n Preview: http://localhost:${previewPort}`);\n console.log(` UI: http://localhost:${uiPort}`);\n console.log(` Server: http://localhost:${serverPort}`);\n console.log(`\\n Press Ctrl+C to stop.\\n`);\n });\n\n // Shutdown\n const shutdown = () => {\n console.log(\"\\n Shutting down...\");\n host.close();\n for (const child of children) {\n try {\n child.kill(\"SIGTERM\");\n } catch {\n /* already dead */\n }\n }\n process.exit(0);\n };\n process.on(\"SIGINT\", shutdown);\n process.on(\"SIGTERM\", shutdown);\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"type-generator-MZ4X4DE5.js"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkHLT5UBJF_cjs = require('./chunk-HLT5UBJF.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "generateTypes", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () { return chunkHLT5UBJF_cjs.generateTypes; }
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=type-generator-UA3L4OIA.cjs.map
|
|
12
|
+
//# sourceMappingURL=type-generator-UA3L4OIA.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"type-generator-UA3L4OIA.cjs"}
|