openmagic 0.25.3 → 0.26.0
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 +59 -47
- 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.0";
|
|
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.0";
|
|
1984
1985
|
function ask(question) {
|
|
1985
1986
|
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
1986
1987
|
return new Promise((resolve3) => {
|
|
@@ -2089,34 +2090,11 @@ program.name("openmagic").description("AI-powered coding toolbar for any web app
|
|
|
2089
2090
|
"-r, --root <paths...>",
|
|
2090
2091
|
"Project root directories (defaults to cwd)"
|
|
2091
2092
|
).option("--no-open", "Don't auto-open browser").option("--host <host>", "Dev server host", "127.0.0.1").action(async (opts) => {
|
|
2092
|
-
const g = chalk.hex("#fdcb6e");
|
|
2093
|
-
const p = chalk.hex("#a29bfe");
|
|
2094
|
-
const b = chalk.bold.hex("#6c5ce7");
|
|
2095
2093
|
console.log("");
|
|
2096
|
-
console.log(
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
console.log(
|
|
2100
|
-
console.log(p(" | ") + g("/") + p(" | ") + g("\\"));
|
|
2101
|
-
console.log(p(" . ") + p(".") + g("--") + p("' | '") + g("--") + p("."));
|
|
2102
|
-
console.log(p(" ") + g("--") + p(" ") + b("|||") + p(" ") + g("--"));
|
|
2103
|
-
console.log(p(" . .") + g("--") + p("' ") + b("|||") + p(" '") + g("--") + p("."));
|
|
2104
|
-
console.log(g(" /|\\") + p(" ") + g("--") + p(" ") + b("|||") + p(" ") + g("--"));
|
|
2105
|
-
console.log(p(" | ") + g("--") + p(" ") + b("|||") + p(" ") + g("--"));
|
|
2106
|
-
console.log(p(" . . .") + g("--------") + p(" ") + b("|||||") + p(" ") + g("--------") + p(". . ."));
|
|
2107
|
-
console.log(p(" | ") + g("--") + p(" ") + b("|||") + p(" ") + g("--"));
|
|
2108
|
-
console.log(g(" \\|/") + p(" ") + g("--") + p(" ") + b("|||") + p(" ") + g("--"));
|
|
2109
|
-
console.log(p(" . .") + g("--") + p(". ") + b("|||") + p(" .") + g("--") + p("."));
|
|
2110
|
-
console.log(p(" ") + g("--") + p(" ") + b("|||") + p(" ") + g("--"));
|
|
2111
|
-
console.log(p(" . .") + g("--") + p(". | .") + g("--") + p("."));
|
|
2112
|
-
console.log(g(" \\|/") + p(" ") + g("\\") + p(" | ") + g("/"));
|
|
2113
|
-
console.log(p(" | ") + g("\\") + p(" | ") + g("/"));
|
|
2114
|
-
console.log(p(" . ") + g("\\") + p("|") + g("/"));
|
|
2115
|
-
console.log(p(" |"));
|
|
2116
|
-
console.log(p(" ."));
|
|
2117
|
-
console.log("");
|
|
2118
|
-
console.log(b(" O P E N M A G I C") + chalk.dim(` v${VERSION2}`));
|
|
2119
|
-
console.log(chalk.dim(" AI coding toolbar for any web app"));
|
|
2094
|
+
console.log(
|
|
2095
|
+
" \u{1FA84} " + chalk.bold.hex("#6c5ce7")("OpenMagic") + chalk.dim(` v${VERSION2}`) + " \u2728"
|
|
2096
|
+
);
|
|
2097
|
+
console.log(chalk.dim(" AI coding toolbar for any web app"));
|
|
2120
2098
|
console.log("");
|
|
2121
2099
|
let targetPort;
|
|
2122
2100
|
let targetHost = opts.host;
|
|
@@ -2128,10 +2106,14 @@ program.name("openmagic").description("AI-powered coding toolbar for any web app
|
|
|
2128
2106
|
if (!started) {
|
|
2129
2107
|
process.exit(1);
|
|
2130
2108
|
}
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
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
|
+
}
|
|
2135
2117
|
}
|
|
2136
2118
|
}
|
|
2137
2119
|
} else {
|
|
@@ -2145,15 +2127,19 @@ program.name("openmagic").description("AI-powered coding toolbar for any web app
|
|
|
2145
2127
|
if (!started) {
|
|
2146
2128
|
process.exit(1);
|
|
2147
2129
|
}
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
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;
|
|
2154
2142
|
}
|
|
2155
|
-
targetPort = redetected.port;
|
|
2156
|
-
targetHost = redetected.host;
|
|
2157
2143
|
}
|
|
2158
2144
|
}
|
|
2159
2145
|
console.log(
|
|
@@ -2175,15 +2161,15 @@ program.name("openmagic").description("AI-powered coding toolbar for any web app
|
|
|
2175
2161
|
}
|
|
2176
2162
|
const proxyServer = createProxyServer(targetHost, targetPort, roots);
|
|
2177
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!"));
|
|
2178
2167
|
console.log("");
|
|
2179
2168
|
console.log(
|
|
2180
|
-
chalk.bold
|
|
2169
|
+
chalk.bold(" \u2192 ") + chalk.bold.underline.cyan(proxyUrl)
|
|
2181
2170
|
);
|
|
2182
2171
|
console.log("");
|
|
2183
2172
|
await healthCheck(proxyPort, targetPort);
|
|
2184
|
-
console.log(
|
|
2185
|
-
chalk.dim(" Open the URL above in your browser to start.")
|
|
2186
|
-
);
|
|
2187
2173
|
console.log(chalk.dim(" Press Ctrl+C to stop."));
|
|
2188
2174
|
console.log(
|
|
2189
2175
|
chalk.dim(" Errors below are from your dev server, not OpenMagic.")
|
|
@@ -2324,14 +2310,26 @@ async function offerToStartDevServer(expectedPort) {
|
|
|
2324
2310
|
}
|
|
2325
2311
|
childProcesses.push(child);
|
|
2326
2312
|
let childExited = false;
|
|
2313
|
+
let detectedPort = null;
|
|
2314
|
+
function parsePortFromOutput(line) {
|
|
2315
|
+
const portMatch = line.match(/https?:\/\/(?:localhost|127\.0\.0\.1|0\.0\.0\.0):(\d+)/);
|
|
2316
|
+
if (portMatch && !detectedPort) {
|
|
2317
|
+
const p = parseInt(portMatch[1], 10);
|
|
2318
|
+
if (p > 0 && p < 65536 && p !== port) {
|
|
2319
|
+
detectedPort = p;
|
|
2320
|
+
}
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2327
2323
|
child.stdout?.on("data", (data) => {
|
|
2328
2324
|
for (const line of data.toString().trim().split("\n")) {
|
|
2325
|
+
parsePortFromOutput(line);
|
|
2329
2326
|
const formatted = formatDevServerLine(line);
|
|
2330
2327
|
if (formatted) process.stdout.write(formatted + "\n");
|
|
2331
2328
|
}
|
|
2332
2329
|
});
|
|
2333
2330
|
child.stderr?.on("data", (data) => {
|
|
2334
2331
|
for (const line of data.toString().trim().split("\n")) {
|
|
2332
|
+
parsePortFromOutput(line);
|
|
2335
2333
|
const formatted = formatDevServerLine(line);
|
|
2336
2334
|
if (formatted) process.stdout.write(formatted + "\n");
|
|
2337
2335
|
}
|
|
@@ -2366,9 +2364,23 @@ async function offerToStartDevServer(expectedPort) {
|
|
|
2366
2364
|
process.on("SIGINT", cleanup);
|
|
2367
2365
|
process.on("SIGTERM", cleanup);
|
|
2368
2366
|
console.log(
|
|
2369
|
-
chalk.dim(` Waiting for
|
|
2367
|
+
chalk.dim(` Waiting for dev server...`)
|
|
2370
2368
|
);
|
|
2371
|
-
const isUp = await waitForPort(port, 3e4, () =>
|
|
2369
|
+
const isUp = await waitForPort(port, 3e4, () => {
|
|
2370
|
+
if (childExited) return true;
|
|
2371
|
+
if (detectedPort) return true;
|
|
2372
|
+
return false;
|
|
2373
|
+
});
|
|
2374
|
+
if (!isUp && detectedPort) {
|
|
2375
|
+
const altUp = await isPortOpen(detectedPort);
|
|
2376
|
+
if (altUp) {
|
|
2377
|
+
console.log(
|
|
2378
|
+
chalk.green(` \u2713 Dev server is on port ${detectedPort} (configured in project, not default ${port})`)
|
|
2379
|
+
);
|
|
2380
|
+
lastDetectedPort = detectedPort;
|
|
2381
|
+
return true;
|
|
2382
|
+
}
|
|
2383
|
+
}
|
|
2372
2384
|
if (childExited && !isUp) {
|
|
2373
2385
|
console.log(
|
|
2374
2386
|
chalk.red(` \u2717 Dev server exited before it was ready.`)
|