openmagic 0.31.4 → 0.31.5

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
@@ -1449,8 +1449,41 @@ async function handleLlmChat(params, onChunk, onDone, onError) {
1449
1449
  }
1450
1450
 
1451
1451
  // src/server.ts
1452
- var VERSION = "0.31.1";
1452
+ var VERSION = "0.31.4";
1453
1453
  var __dirname = dirname2(fileURLToPath(import.meta.url));
1454
+ var MAX_SERVER_LOGS = 200;
1455
+ var serverLogs = [];
1456
+ function captureServerLog(level, ...args) {
1457
+ const msg = args.map((a) => {
1458
+ try {
1459
+ return typeof a === "object" ? JSON.stringify(a).slice(0, 500) : String(a);
1460
+ } catch {
1461
+ return String(a);
1462
+ }
1463
+ }).join(" ");
1464
+ serverLogs.push({ level, msg, ts: Date.now() });
1465
+ if (serverLogs.length > MAX_SERVER_LOGS) serverLogs.shift();
1466
+ }
1467
+ var _origLog = console.log;
1468
+ var _origWarn = console.warn;
1469
+ var _origErr = console.error;
1470
+ var _origInfo = console.info;
1471
+ console.log = (...a) => {
1472
+ captureServerLog("log", ...a);
1473
+ _origLog(...a);
1474
+ };
1475
+ console.warn = (...a) => {
1476
+ captureServerLog("warn", ...a);
1477
+ _origWarn(...a);
1478
+ };
1479
+ console.error = (...a) => {
1480
+ captureServerLog("error", ...a);
1481
+ _origErr(...a);
1482
+ };
1483
+ console.info = (...a) => {
1484
+ captureServerLog("info", ...a);
1485
+ _origInfo(...a);
1486
+ };
1454
1487
  function attachOpenMagic(httpServer, roots) {
1455
1488
  function handleRequest(req, res) {
1456
1489
  if (!req.url?.startsWith("/__openmagic__/")) return false;
@@ -1661,6 +1694,23 @@ async function handleMessage(ws, msg, state, roots) {
1661
1694
  }
1662
1695
  break;
1663
1696
  }
1697
+ case "debug.logs": {
1698
+ send(ws, {
1699
+ id: msg.id,
1700
+ type: "debug.logs",
1701
+ payload: {
1702
+ logs: serverLogs.slice(-100),
1703
+ nodeVersion: process.version,
1704
+ platform: process.platform,
1705
+ arch: process.arch,
1706
+ uptime: Math.round(process.uptime()),
1707
+ memoryMB: Math.round(process.memoryUsage().rss / 1024 / 1024),
1708
+ pid: process.pid,
1709
+ cwd: process.cwd()
1710
+ }
1711
+ });
1712
+ break;
1713
+ }
1664
1714
  default:
1665
1715
  sendError(ws, "unknown_type", `Unknown message type: ${msg.type}`, msg.id);
1666
1716
  }