openmagic 0.14.0 → 0.14.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 +40 -33
- 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
|
@@ -1356,7 +1356,7 @@ async function handleLlmChat(params, onChunk, onDone, onError) {
|
|
|
1356
1356
|
}
|
|
1357
1357
|
|
|
1358
1358
|
// src/server.ts
|
|
1359
|
-
var VERSION = "0.14.
|
|
1359
|
+
var VERSION = "0.14.1";
|
|
1360
1360
|
var __dirname = dirname2(fileURLToPath(import.meta.url));
|
|
1361
1361
|
function attachOpenMagic(httpServer, roots) {
|
|
1362
1362
|
function handleRequest(req, res) {
|
|
@@ -1614,25 +1614,43 @@ function createProxyServer(targetHost, targetPort, roots) {
|
|
|
1614
1614
|
proxy.on("proxyRes", (proxyRes, req, res) => {
|
|
1615
1615
|
const contentType = proxyRes.headers["content-type"] || "";
|
|
1616
1616
|
const isHtml = contentType.includes("text/html");
|
|
1617
|
-
|
|
1618
|
-
|
|
1617
|
+
const status = proxyRes.statusCode || 200;
|
|
1618
|
+
if (!isHtml && status < 400) {
|
|
1619
|
+
res.writeHead(status, proxyRes.headers);
|
|
1619
1620
|
proxyRes.pipe(res);
|
|
1620
1621
|
return;
|
|
1621
1622
|
}
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1623
|
+
if (isHtml) {
|
|
1624
|
+
const headers = { ...proxyRes.headers };
|
|
1625
|
+
delete headers["content-length"];
|
|
1626
|
+
delete headers["content-encoding"];
|
|
1627
|
+
delete headers["transfer-encoding"];
|
|
1628
|
+
delete headers["content-security-policy"];
|
|
1629
|
+
delete headers["content-security-policy-report-only"];
|
|
1630
|
+
delete headers["x-content-security-policy"];
|
|
1631
|
+
delete headers["etag"];
|
|
1632
|
+
delete headers["last-modified"];
|
|
1633
|
+
headers["cache-control"] = "no-store";
|
|
1634
|
+
res.writeHead(status, headers);
|
|
1635
|
+
proxyRes.pipe(res, { end: false });
|
|
1636
|
+
proxyRes.on("end", () => {
|
|
1637
|
+
res.end(buildInjectionScript(token));
|
|
1638
|
+
});
|
|
1639
|
+
return;
|
|
1640
|
+
}
|
|
1641
|
+
const chunks = [];
|
|
1642
|
+
proxyRes.on("data", (c) => chunks.push(c));
|
|
1634
1643
|
proxyRes.on("end", () => {
|
|
1635
|
-
|
|
1644
|
+
const body = Buffer.concat(chunks).toString("utf-8").slice(0, 2e3);
|
|
1645
|
+
const toolbarScript = buildInjectionScript(token);
|
|
1646
|
+
res.writeHead(status, { "Content-Type": "text/html", "Cache-Control": "no-store" });
|
|
1647
|
+
res.end(`<html><head><meta charset="utf-8"><title>Error ${status}</title></head>
|
|
1648
|
+
<body style="font-family:system-ui;padding:40px;background:#0f0f1e;color:#e0e0e0;">
|
|
1649
|
+
<h2 style="color:#e94560;">Error ${status}</h2>
|
|
1650
|
+
<pre style="color:#888;white-space:pre-wrap;max-width:800px;overflow:auto;font-size:13px;">${body.replace(/</g, "<")}</pre>
|
|
1651
|
+
<p style="color:#555;font-size:13px;">This error is from your dev server, not OpenMagic. The toolbar is available below.</p>
|
|
1652
|
+
${toolbarScript}
|
|
1653
|
+
</body></html>`);
|
|
1636
1654
|
});
|
|
1637
1655
|
});
|
|
1638
1656
|
proxy.on("error", (err, _req, res) => {
|
|
@@ -1843,7 +1861,7 @@ process.on("uncaughtException", (err) => {
|
|
|
1843
1861
|
process.exit(1);
|
|
1844
1862
|
});
|
|
1845
1863
|
var childProcesses = [];
|
|
1846
|
-
var VERSION2 = "0.14.
|
|
1864
|
+
var VERSION2 = "0.14.1";
|
|
1847
1865
|
function ask(question) {
|
|
1848
1866
|
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
1849
1867
|
return new Promise((resolve3) => {
|
|
@@ -1903,29 +1921,18 @@ function runCommand(cmd, args, cwd = process.cwd()) {
|
|
|
1903
1921
|
}
|
|
1904
1922
|
});
|
|
1905
1923
|
}
|
|
1906
|
-
async function healthCheck(proxyPort,
|
|
1924
|
+
async function healthCheck(proxyPort, _targetPort) {
|
|
1907
1925
|
try {
|
|
1908
1926
|
const controller = new AbortController();
|
|
1909
1927
|
const timeout = setTimeout(() => controller.abort(), 5e3);
|
|
1910
|
-
const res = await fetch(`http://127.0.0.1:${proxyPort}
|
|
1911
|
-
signal: controller.signal
|
|
1912
|
-
headers: { Accept: "text/html" }
|
|
1928
|
+
const res = await fetch(`http://127.0.0.1:${proxyPort}/__openmagic__/health`, {
|
|
1929
|
+
signal: controller.signal
|
|
1913
1930
|
});
|
|
1914
1931
|
clearTimeout(timeout);
|
|
1915
1932
|
if (res.ok) {
|
|
1916
|
-
|
|
1917
|
-
if (text.includes("__OPENMAGIC_LOADED__")) {
|
|
1918
|
-
console.log(chalk.green(" \u2713 Toolbar injection verified."));
|
|
1919
|
-
} else {
|
|
1920
|
-
console.log(chalk.yellow(" \u26A0 Page loaded but toolbar may not have injected (non-HTML response or CSP)."));
|
|
1921
|
-
}
|
|
1933
|
+
console.log(chalk.green(" \u2713 Toolbar ready."));
|
|
1922
1934
|
} else {
|
|
1923
|
-
console.log(
|
|
1924
|
-
chalk.yellow(` \u26A0 Dev server returned ${res.status}. Pages may have errors.`)
|
|
1925
|
-
);
|
|
1926
|
-
console.log(
|
|
1927
|
-
chalk.dim(" The toolbar will still appear on pages that load successfully.")
|
|
1928
|
-
);
|
|
1935
|
+
console.log(chalk.yellow(" \u26A0 Proxy started but toolbar health check failed."));
|
|
1929
1936
|
}
|
|
1930
1937
|
} catch {
|
|
1931
1938
|
console.log(
|