@juspay/neurolink 12.2.4 → 12.2.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.
@@ -9,10 +9,6 @@
9
9
  import { EventEmitter } from "events";
10
10
  import { ToolDiscoveryService } from "./toolDiscoveryService.js";
11
11
  import type { HITLManager, JsonObject, ServerLoadResult, ExternalMCPServerInstance, ExternalMCPServerHealth, ExternalMCPConfigValidation, ExternalMCPOperationResult, ExternalMCPManagerConfig, ExternalMCPToolInfo, MCPServerInfo } from "../types/index.js";
12
- /**
13
- * ExternalServerManager
14
- * Core class for managing external MCP servers
15
- */
16
12
  export declare class ExternalServerManager extends EventEmitter {
17
13
  private servers;
18
14
  private config;
@@ -164,6 +164,31 @@ function isValidExternalMCPServerConfig(config) {
164
164
  * ExternalServerManager
165
165
  * Core class for managing external MCP servers
166
166
  */
167
+ /**
168
+ * Process-signal cleanup, shared across every manager instance.
169
+ *
170
+ * Each delegated worker constructs its own NeuroLink and therefore its own
171
+ * manager; registering SIGINT/SIGTERM/beforeExit per instance leaked listeners
172
+ * (never removed) and crossed Node's 10-listener default on multi-worker runs.
173
+ * One process-level trio walks the live set instead; `shutdown()` removes the
174
+ * instance from the set, so a disposed manager costs nothing.
175
+ */
176
+ const liveManagers = new Set();
177
+ let processCleanupInstalled = false;
178
+ const shutdownLiveManagers = () => {
179
+ for (const manager of liveManagers) {
180
+ void manager.shutdown();
181
+ }
182
+ };
183
+ const registerManagerForProcessCleanup = (manager) => {
184
+ liveManagers.add(manager);
185
+ if (!processCleanupInstalled) {
186
+ processCleanupInstalled = true;
187
+ process.on("SIGINT", shutdownLiveManagers);
188
+ process.on("SIGTERM", shutdownLiveManagers);
189
+ process.on("beforeExit", shutdownLiveManagers);
190
+ }
191
+ };
167
192
  export class ExternalServerManager extends EventEmitter {
168
193
  servers = new Map();
169
194
  config;
@@ -205,10 +230,12 @@ export class ExternalServerManager extends EventEmitter {
205
230
  serverName: this.getServerName(event.serverId),
206
231
  });
207
232
  });
208
- // Handle process cleanup
209
- process.on("SIGINT", () => this.shutdown());
210
- process.on("SIGTERM", () => this.shutdown());
211
- process.on("beforeExit", () => this.shutdown());
233
+ // Handle process cleanup through the SHARED handler set: one trio of process
234
+ // listeners for every manager, however many instances a run constructs.
235
+ // Per-instance `process.on(...)` here crossed Node's 10-listener default as
236
+ // soon as an agent delegated to a handful of workers (each worker builds its
237
+ // own NeuroLink, which builds its own manager) and warned MaxListenersExceeded.
238
+ registerManagerForProcessCleanup(this);
212
239
  }
213
240
  /**
214
241
  * Attach a McpOutputNormalizer to the underlying ToolDiscoveryService.
@@ -1230,6 +1257,7 @@ export class ExternalServerManager extends EventEmitter {
1230
1257
  return;
1231
1258
  }
1232
1259
  this.isShuttingDown = true;
1260
+ liveManagers.delete(this);
1233
1261
  mcpLogger.info("[ExternalServerManager] Shutting down all servers...");
1234
1262
  const shutdownPromises = Array.from(this.servers.keys()).map((serverId) => this.stopServer(serverId).catch((error) => {
1235
1263
  mcpLogger.error(`[ExternalServerManager] Error shutting down ${serverId}:`, error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juspay/neurolink",
3
- "version": "12.2.4",
3
+ "version": "12.2.5",
4
4
  "packageManager": "pnpm@10.15.1",
5
5
  "description": "TypeScript AI SDK with 24+ LLM providers behind one consistent API. MCP-native (connect any MCP server), voice TTS/STT/realtime, RAG, agents, memory, context compaction. OpenAI · Anthropic · Gemini · Bedrock · Azure · Ollama · DeepSeek · NVIDIA NIM and more.",
6
6
  "author": {