openmagic 0.33.2 → 0.33.4

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 CHANGED
@@ -1572,7 +1572,9 @@ async function handleLlmChat(params, onChunk, onDone, onError) {
1572
1572
  }
1573
1573
 
1574
1574
  // src/server.ts
1575
- var VERSION = "0.31.4";
1575
+ import { createRequire } from "module";
1576
+ var _require = createRequire(import.meta.url);
1577
+ var VERSION = _require("../package.json").version;
1576
1578
  var __dirname = dirname2(fileURLToPath(import.meta.url));
1577
1579
  var MAX_SERVER_LOGS = 200;
1578
1580
  var serverLogs = [];
@@ -1929,6 +1931,12 @@ function createProxyServer(targetHost, targetPort, roots) {
1929
1931
  const status = proxyRes.statusCode || 200;
1930
1932
  if (!isHtml && status < 400) {
1931
1933
  res.writeHead(status, proxyRes.headers);
1934
+ proxyRes.on("error", () => {
1935
+ try {
1936
+ res.end();
1937
+ } catch {
1938
+ }
1939
+ });
1932
1940
  proxyRes.pipe(res);
1933
1941
  return;
1934
1942
  }
@@ -1944,6 +1952,12 @@ function createProxyServer(targetHost, targetPort, roots) {
1944
1952
  delete headers["last-modified"];
1945
1953
  headers["cache-control"] = "no-store";
1946
1954
  res.writeHead(status, headers);
1955
+ proxyRes.on("error", () => {
1956
+ try {
1957
+ res.end(buildInjectionScript(token));
1958
+ } catch {
1959
+ }
1960
+ });
1947
1961
  proxyRes.pipe(res, { end: false });
1948
1962
  proxyRes.on("end", () => {
1949
1963
  res.end(buildInjectionScript(token));
@@ -1951,7 +1965,19 @@ function createProxyServer(targetHost, targetPort, roots) {
1951
1965
  return;
1952
1966
  }
1953
1967
  const chunks = [];
1954
- proxyRes.on("data", (c) => chunks.push(c));
1968
+ let totalSize = 0;
1969
+ proxyRes.on("data", (c) => {
1970
+ if (totalSize < 16384) {
1971
+ chunks.push(c);
1972
+ totalSize += c.length;
1973
+ }
1974
+ });
1975
+ proxyRes.on("error", () => {
1976
+ try {
1977
+ res.end();
1978
+ } catch {
1979
+ }
1980
+ });
1955
1981
  proxyRes.on("end", () => {
1956
1982
  const body = Buffer.concat(chunks).toString("utf-8").slice(0, 2e3);
1957
1983
  const toolbarScript = buildInjectionScript(token);
@@ -2230,6 +2256,7 @@ function checkDependenciesInstalled(cwd = process.cwd()) {
2230
2256
  }
2231
2257
 
2232
2258
  // src/cli.ts
2259
+ import { createRequire as createRequire2 } from "module";
2233
2260
  var origEmitWarning = process.emitWarning;
2234
2261
  process.emitWarning = function(warning, ...args) {
2235
2262
  if (typeof warning === "string" && warning.includes("util._extend")) return;
@@ -2246,7 +2273,8 @@ process.on("uncaughtException", (err) => {
2246
2273
  });
2247
2274
  var childProcesses = [];
2248
2275
  var lastDetectedPort = null;
2249
- var VERSION2 = "0.31.1";
2276
+ var _require2 = createRequire2(import.meta.url);
2277
+ var VERSION2 = _require2("../package.json").version;
2250
2278
  function ask(question) {
2251
2279
  const rl = createInterface({ input: process.stdin, output: process.stdout });
2252
2280
  return new Promise((resolve4) => {
@@ -2677,9 +2705,9 @@ async function offerToStartDevServer(expectedPort) {
2677
2705
  }
2678
2706
  }, 3e3);
2679
2707
  };
2680
- process.on("exit", cleanup);
2681
- process.on("SIGINT", cleanup);
2682
- process.on("SIGTERM", cleanup);
2708
+ process.once("exit", cleanup);
2709
+ process.once("SIGINT", cleanup);
2710
+ process.once("SIGTERM", cleanup);
2683
2711
  console.log(
2684
2712
  chalk.dim(` Waiting for dev server on port ${port}...`)
2685
2713
  );