openmagic 0.25.4 → 0.26.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +56 -20
- package/dist/cli.js.map +1 -1
- package/dist/toolbar/index.global.js +1 -1
- package/dist/toolbar/index.global.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1447,7 +1447,7 @@ async function handleLlmChat(params, onChunk, onDone, onError) {
|
|
|
1447
1447
|
}
|
|
1448
1448
|
|
|
1449
1449
|
// src/server.ts
|
|
1450
|
-
var VERSION = "0.
|
|
1450
|
+
var VERSION = "0.26.1";
|
|
1451
1451
|
var __dirname = dirname2(fileURLToPath(import.meta.url));
|
|
1452
1452
|
function attachOpenMagic(httpServer, roots) {
|
|
1453
1453
|
function handleRequest(req, res) {
|
|
@@ -1980,7 +1980,8 @@ process.on("uncaughtException", (err) => {
|
|
|
1980
1980
|
process.exit(1);
|
|
1981
1981
|
});
|
|
1982
1982
|
var childProcesses = [];
|
|
1983
|
-
var
|
|
1983
|
+
var lastDetectedPort = null;
|
|
1984
|
+
var VERSION2 = "0.26.1";
|
|
1984
1985
|
function ask(question) {
|
|
1985
1986
|
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
1986
1987
|
return new Promise((resolve3) => {
|
|
@@ -2105,10 +2106,14 @@ program.name("openmagic").description("AI-powered coding toolbar for any web app
|
|
|
2105
2106
|
if (!started) {
|
|
2106
2107
|
process.exit(1);
|
|
2107
2108
|
}
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2109
|
+
if (lastDetectedPort) {
|
|
2110
|
+
targetPort = lastDetectedPort;
|
|
2111
|
+
} else {
|
|
2112
|
+
const recheck = await detectDevServer();
|
|
2113
|
+
if (recheck) {
|
|
2114
|
+
targetPort = recheck.port;
|
|
2115
|
+
targetHost = recheck.host;
|
|
2116
|
+
}
|
|
2112
2117
|
}
|
|
2113
2118
|
}
|
|
2114
2119
|
} else {
|
|
@@ -2122,15 +2127,19 @@ program.name("openmagic").description("AI-powered coding toolbar for any web app
|
|
|
2122
2127
|
if (!started) {
|
|
2123
2128
|
process.exit(1);
|
|
2124
2129
|
}
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2130
|
+
if (lastDetectedPort) {
|
|
2131
|
+
targetPort = lastDetectedPort;
|
|
2132
|
+
} else {
|
|
2133
|
+
const redetected = await detectDevServer();
|
|
2134
|
+
if (!redetected) {
|
|
2135
|
+
console.log(chalk.red(" \u2717 Could not detect the dev server after starting."));
|
|
2136
|
+
console.log(chalk.dim(" Try specifying the port: npx openmagic --port 3000"));
|
|
2137
|
+
console.log("");
|
|
2138
|
+
process.exit(1);
|
|
2139
|
+
}
|
|
2140
|
+
targetPort = redetected.port;
|
|
2141
|
+
targetHost = redetected.host;
|
|
2131
2142
|
}
|
|
2132
|
-
targetPort = redetected.port;
|
|
2133
|
-
targetHost = redetected.host;
|
|
2134
2143
|
}
|
|
2135
2144
|
}
|
|
2136
2145
|
console.log(
|
|
@@ -2152,15 +2161,15 @@ program.name("openmagic").description("AI-powered coding toolbar for any web app
|
|
|
2152
2161
|
}
|
|
2153
2162
|
const proxyServer = createProxyServer(targetHost, targetPort, roots);
|
|
2154
2163
|
proxyServer.listen(proxyPort, "127.0.0.1", async () => {
|
|
2164
|
+
const proxyUrl = `http://localhost:${proxyPort}`;
|
|
2165
|
+
console.log("");
|
|
2166
|
+
console.log(chalk.bold.green(" Ready!"));
|
|
2155
2167
|
console.log("");
|
|
2156
2168
|
console.log(
|
|
2157
|
-
chalk.bold
|
|
2169
|
+
chalk.bold(" \u2192 ") + chalk.bold.underline.cyan(proxyUrl)
|
|
2158
2170
|
);
|
|
2159
2171
|
console.log("");
|
|
2160
2172
|
await healthCheck(proxyPort, targetPort);
|
|
2161
|
-
console.log(
|
|
2162
|
-
chalk.dim(" Open the URL above in your browser to start.")
|
|
2163
|
-
);
|
|
2164
2173
|
console.log(chalk.dim(" Press Ctrl+C to stop."));
|
|
2165
2174
|
console.log(
|
|
2166
2175
|
chalk.dim(" Errors below are from your dev server, not OpenMagic.")
|
|
@@ -2301,14 +2310,27 @@ async function offerToStartDevServer(expectedPort) {
|
|
|
2301
2310
|
}
|
|
2302
2311
|
childProcesses.push(child);
|
|
2303
2312
|
let childExited = false;
|
|
2313
|
+
let detectedPort = null;
|
|
2314
|
+
function parsePortFromOutput(line) {
|
|
2315
|
+
const clean = line.replace(/\x1b\[[0-9;]*m/g, "").replace(/\u001b\[[0-9;]*m/g, "");
|
|
2316
|
+
const portMatch = clean.match(/https?:\/\/(?:localhost|127\.0\.0\.1|0\.0\.0\.0):(\d+)/);
|
|
2317
|
+
if (portMatch && !detectedPort) {
|
|
2318
|
+
const p = parseInt(portMatch[1], 10);
|
|
2319
|
+
if (p > 0 && p < 65536 && p !== port) {
|
|
2320
|
+
detectedPort = p;
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
}
|
|
2304
2324
|
child.stdout?.on("data", (data) => {
|
|
2305
2325
|
for (const line of data.toString().trim().split("\n")) {
|
|
2326
|
+
parsePortFromOutput(line);
|
|
2306
2327
|
const formatted = formatDevServerLine(line);
|
|
2307
2328
|
if (formatted) process.stdout.write(formatted + "\n");
|
|
2308
2329
|
}
|
|
2309
2330
|
});
|
|
2310
2331
|
child.stderr?.on("data", (data) => {
|
|
2311
2332
|
for (const line of data.toString().trim().split("\n")) {
|
|
2333
|
+
parsePortFromOutput(line);
|
|
2312
2334
|
const formatted = formatDevServerLine(line);
|
|
2313
2335
|
if (formatted) process.stdout.write(formatted + "\n");
|
|
2314
2336
|
}
|
|
@@ -2343,9 +2365,23 @@ async function offerToStartDevServer(expectedPort) {
|
|
|
2343
2365
|
process.on("SIGINT", cleanup);
|
|
2344
2366
|
process.on("SIGTERM", cleanup);
|
|
2345
2367
|
console.log(
|
|
2346
|
-
chalk.dim(` Waiting for
|
|
2368
|
+
chalk.dim(` Waiting for dev server...`)
|
|
2347
2369
|
);
|
|
2348
|
-
const isUp = await waitForPort(port, 3e4, () =>
|
|
2370
|
+
const isUp = await waitForPort(port, 3e4, () => {
|
|
2371
|
+
if (childExited) return true;
|
|
2372
|
+
if (detectedPort) return true;
|
|
2373
|
+
return false;
|
|
2374
|
+
});
|
|
2375
|
+
if (!isUp && detectedPort) {
|
|
2376
|
+
const altUp = await isPortOpen(detectedPort);
|
|
2377
|
+
if (altUp) {
|
|
2378
|
+
console.log(
|
|
2379
|
+
chalk.green(` \u2713 Dev server is on port ${detectedPort} (configured in project, not default ${port})`)
|
|
2380
|
+
);
|
|
2381
|
+
lastDetectedPort = detectedPort;
|
|
2382
|
+
return true;
|
|
2383
|
+
}
|
|
2384
|
+
}
|
|
2349
2385
|
if (childExited && !isUp) {
|
|
2350
2386
|
console.log(
|
|
2351
2387
|
chalk.red(` \u2717 Dev server exited before it was ready.`)
|