openmagic 0.17.0 → 0.17.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 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.17.0";
1359
+ var VERSION = "0.17.1";
1360
1360
  var __dirname = dirname2(fileURLToPath(import.meta.url));
1361
1361
  function attachOpenMagic(httpServer, roots) {
1362
1362
  function handleRequest(req, res) {
@@ -1376,10 +1376,7 @@ function attachOpenMagic(httpServer, roots) {
1376
1376
  }
1377
1377
  return false;
1378
1378
  }
1379
- const wss = new WebSocketServer({
1380
- server: httpServer,
1381
- path: "/__openmagic__/ws"
1382
- });
1379
+ const wss = new WebSocketServer({ noServer: true });
1383
1380
  const clientStates = /* @__PURE__ */ new WeakMap();
1384
1381
  wss.on("connection", (ws, req) => {
1385
1382
  const origin = req.headers.origin || "";
@@ -1411,7 +1408,17 @@ function attachOpenMagic(httpServer, roots) {
1411
1408
  clientStates.delete(ws);
1412
1409
  });
1413
1410
  });
1414
- return { wss, handleRequest };
1411
+ function handleUpgrade(req, socket, head) {
1412
+ const urlPath = (req.url || "").split("?")[0];
1413
+ if (urlPath === "/__openmagic__/ws") {
1414
+ wss.handleUpgrade(req, socket, head, (ws) => {
1415
+ wss.emit("connection", ws, req);
1416
+ });
1417
+ return true;
1418
+ }
1419
+ return false;
1420
+ }
1421
+ return { wss, handleRequest, handleUpgrade };
1415
1422
  }
1416
1423
  async function handleMessage(ws, msg, state, roots) {
1417
1424
  switch (msg.type) {
@@ -1670,17 +1677,24 @@ ${toolbarScript}
1670
1677
  ${toolbarScript}
1671
1678
  </body></html>`
1672
1679
  );
1680
+ } else if (res && typeof res.destroy === "function") {
1681
+ try {
1682
+ res.destroy();
1683
+ } catch {
1684
+ }
1673
1685
  }
1674
1686
  });
1675
1687
  let omHandle = null;
1688
+ let omUpgrade = null;
1676
1689
  const server = http.createServer((req, res) => {
1677
1690
  if (omHandle && omHandle(req, res)) return;
1678
1691
  proxy.web(req, res);
1679
1692
  });
1680
1693
  const om = attachOpenMagic(server, roots);
1681
1694
  omHandle = om.handleRequest;
1695
+ omUpgrade = om.handleUpgrade;
1682
1696
  server.on("upgrade", (req, socket, head) => {
1683
- if (req.url?.startsWith("/__openmagic__")) return;
1697
+ if (omUpgrade && omUpgrade(req, socket, head)) return;
1684
1698
  proxy.ws(req, socket, head);
1685
1699
  });
1686
1700
  return server;
@@ -1875,7 +1889,7 @@ process.on("uncaughtException", (err) => {
1875
1889
  process.exit(1);
1876
1890
  });
1877
1891
  var childProcesses = [];
1878
- var VERSION2 = "0.17.0";
1892
+ var VERSION2 = "0.17.1";
1879
1893
  function ask(question) {
1880
1894
  const rl = createInterface({ input: process.stdin, output: process.stdout });
1881
1895
  return new Promise((resolve3) => {