@linkegringo/mcp 1.0.7 → 1.0.8

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/index.d.ts CHANGED
@@ -108,6 +108,10 @@ declare class BridgeJobStore extends EventEmitter {
108
108
  getWatcherCount(): number;
109
109
  hasActiveWatcher(): boolean;
110
110
  cancelAllPending(reason?: string): number;
111
+ resetQueue(reason?: string): {
112
+ canceledCount: number;
113
+ clearedCount: number;
114
+ };
111
115
  clear(): void;
112
116
  }
113
117
  declare const bridgeJobStore: BridgeJobStore;
package/dist/index.js CHANGED
@@ -150,6 +150,14 @@ var BridgeJobStore = class extends EventEmitter {
150
150
  this.emit("queue:cleared", count);
151
151
  return count;
152
152
  }
153
+ resetQueue(reason = "Cancelado pelo usu\xE1rio via interface web") {
154
+ const canceledCount = this.cancelAllPending(reason);
155
+ const clearedCount = this.jobs.size;
156
+ this.jobs.clear();
157
+ this.pendingQueue = [];
158
+ this.emit("queue:reset", { canceledCount, clearedCount });
159
+ return { canceledCount, clearedCount };
160
+ }
153
161
  clear() {
154
162
  this.jobs.clear();
155
163
  this.pendingQueue = [];
@@ -1704,6 +1712,7 @@ async function parseBody(req) {
1704
1712
  });
1705
1713
  }
1706
1714
  function createBridgeHttpServer(options = {}) {
1715
+ const activeSseClients = /* @__PURE__ */ new Map();
1707
1716
  const server = http.createServer(async (req, res) => {
1708
1717
  setCorsHeaders(res);
1709
1718
  if (req.method === "OPTIONS") {
@@ -1740,11 +1749,25 @@ function createBridgeHttpServer(options = {}) {
1740
1749
  return;
1741
1750
  }
1742
1751
  if (req.method === "POST" && pathname === "/api/bridge/disconnect") {
1743
- const canceledCount = bridgeJobStore.cancelAllPending("Cancelado pelo usu\xE1rio na interface web.");
1752
+ for (const [id, client] of activeSseClients.entries()) {
1753
+ try {
1754
+ client.res.write(
1755
+ `data: ${JSON.stringify({ type: "disconnect", message: "Desconectado pelo usu\xE1rio na interface web." })}
1756
+
1757
+ `
1758
+ );
1759
+ client.res.end();
1760
+ } catch {
1761
+ }
1762
+ client.cleanup();
1763
+ }
1764
+ activeSseClients.clear();
1765
+ const { canceledCount, clearedCount } = bridgeJobStore.resetQueue();
1744
1766
  sendJson(res, 200, {
1745
1767
  ok: true,
1746
1768
  message: "Conex\xE3o cancelada e fila de jobs limpa com sucesso.",
1747
- canceledCount
1769
+ canceledCount,
1770
+ clearedCount
1748
1771
  });
1749
1772
  return;
1750
1773
  }
@@ -1784,13 +1807,16 @@ function createBridgeHttpServer(options = {}) {
1784
1807
 
1785
1808
  `);
1786
1809
  }, 15e3);
1787
- req.on("close", () => {
1810
+ const cleanup = () => {
1788
1811
  clearInterval(heartbeat);
1789
1812
  bridgeJobStore.unregisterWatcher(watcherId);
1790
1813
  bridgeJobStore.off("job:created", onJobCreated);
1791
1814
  bridgeJobStore.off("job:completed", onJobCompleted);
1792
1815
  bridgeJobStore.off("job:failed", onJobFailed);
1793
- });
1816
+ activeSseClients.delete(watcherId);
1817
+ };
1818
+ activeSseClients.set(watcherId, { res, cleanup });
1819
+ req.on("close", cleanup);
1794
1820
  return;
1795
1821
  }
1796
1822
  if (req.method === "POST" && pathname === "/api/jobs") {
@@ -1981,6 +2007,17 @@ function startBridgeWatcher(options = {}) {
1981
2007
  console.log(
1982
2008
  `[LinkeGringo Watcher] \u26A0\uFE0F Job cancelado ou com erro: ${payload.job.id} (${payload.job.error})`
1983
2009
  );
2010
+ } else if (payload.type === "disconnect") {
2011
+ console.log(
2012
+ `
2013
+ [LinkeGringo Watcher] \u{1F6D1} Conex\xE3o encerrada pelo servidor (desconectado via interface web).`
2014
+ );
2015
+ isClosed = true;
2016
+ if (currentReq) {
2017
+ currentReq.destroy();
2018
+ currentReq = null;
2019
+ }
2020
+ setTimeout(() => process.exit(0), 50);
1984
2021
  }
1985
2022
  } catch {
1986
2023
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@linkegringo/mcp",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "Servidor MCP oficial do LinkeGringo para auditoria e otimização de perfis para o mercado internacional",
5
5
  "type": "module",
6
6
  "bin": {