@juspay/neurolink 3.0.1 → 4.1.0
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/CHANGELOG.md +66 -6
- package/README.md +318 -27
- package/dist/agent/direct-tools.d.ts +6 -6
- package/dist/chat/client-utils.d.ts +92 -0
- package/dist/chat/client-utils.js +298 -0
- package/dist/chat/index.d.ts +27 -0
- package/dist/chat/index.js +41 -0
- package/dist/chat/session-storage.d.ts +77 -0
- package/dist/chat/session-storage.js +233 -0
- package/dist/chat/session.d.ts +95 -0
- package/dist/chat/session.js +257 -0
- package/dist/chat/sse-handler.d.ts +49 -0
- package/dist/chat/sse-handler.js +266 -0
- package/dist/chat/types.d.ts +73 -0
- package/dist/chat/types.js +5 -0
- package/dist/chat/websocket-chat-handler.d.ts +36 -0
- package/dist/chat/websocket-chat-handler.js +262 -0
- package/dist/cli/commands/config.js +12 -12
- package/dist/cli/commands/mcp.js +3 -4
- package/dist/cli/index.d.ts +0 -7
- package/dist/cli/index.js +247 -28
- package/dist/config/configManager.d.ts +60 -0
- package/dist/config/configManager.js +300 -0
- package/dist/config/types.d.ts +136 -0
- package/dist/config/types.js +43 -0
- package/dist/core/analytics.d.ts +23 -0
- package/dist/core/analytics.js +131 -0
- package/dist/core/constants.d.ts +41 -0
- package/dist/core/constants.js +50 -0
- package/dist/core/defaults.d.ts +18 -0
- package/dist/core/defaults.js +29 -0
- package/dist/core/evaluation-config.d.ts +29 -0
- package/dist/core/evaluation-config.js +144 -0
- package/dist/core/evaluation-providers.d.ts +30 -0
- package/dist/core/evaluation-providers.js +187 -0
- package/dist/core/evaluation.d.ts +117 -0
- package/dist/core/evaluation.js +528 -0
- package/dist/core/factory.js +33 -25
- package/dist/core/types.d.ts +165 -6
- package/dist/core/types.js +3 -4
- package/dist/index.d.ts +9 -4
- package/dist/index.js +25 -4
- package/dist/lib/agent/direct-tools.d.ts +6 -6
- package/dist/lib/chat/client-utils.d.ts +92 -0
- package/dist/lib/chat/client-utils.js +298 -0
- package/dist/lib/chat/index.d.ts +27 -0
- package/dist/lib/chat/index.js +41 -0
- package/dist/lib/chat/session-storage.d.ts +77 -0
- package/dist/lib/chat/session-storage.js +233 -0
- package/dist/lib/chat/session.d.ts +95 -0
- package/dist/lib/chat/session.js +257 -0
- package/dist/lib/chat/sse-handler.d.ts +49 -0
- package/dist/lib/chat/sse-handler.js +266 -0
- package/dist/lib/chat/types.d.ts +73 -0
- package/dist/lib/chat/types.js +5 -0
- package/dist/lib/chat/websocket-chat-handler.d.ts +36 -0
- package/dist/lib/chat/websocket-chat-handler.js +262 -0
- package/dist/lib/config/configManager.d.ts +60 -0
- package/dist/lib/config/configManager.js +300 -0
- package/dist/lib/config/types.d.ts +136 -0
- package/dist/lib/config/types.js +43 -0
- package/dist/lib/core/analytics.d.ts +23 -0
- package/dist/lib/core/analytics.js +131 -0
- package/dist/lib/core/constants.d.ts +41 -0
- package/dist/lib/core/constants.js +50 -0
- package/dist/lib/core/defaults.d.ts +18 -0
- package/dist/lib/core/defaults.js +29 -0
- package/dist/lib/core/evaluation-config.d.ts +29 -0
- package/dist/lib/core/evaluation-config.js +144 -0
- package/dist/lib/core/evaluation-providers.d.ts +30 -0
- package/dist/lib/core/evaluation-providers.js +187 -0
- package/dist/lib/core/evaluation.d.ts +117 -0
- package/dist/lib/core/evaluation.js +528 -0
- package/dist/lib/core/factory.js +33 -26
- package/dist/lib/core/types.d.ts +165 -6
- package/dist/lib/core/types.js +3 -4
- package/dist/lib/index.d.ts +9 -4
- package/dist/lib/index.js +25 -4
- package/dist/lib/mcp/contracts/mcpContract.d.ts +118 -0
- package/dist/lib/mcp/contracts/mcpContract.js +5 -0
- package/dist/lib/mcp/dynamic-chain-executor.d.ts +201 -0
- package/dist/lib/mcp/dynamic-chain-executor.js +489 -0
- package/dist/lib/mcp/dynamic-orchestrator.d.ts +109 -0
- package/dist/lib/mcp/dynamic-orchestrator.js +351 -0
- package/dist/lib/mcp/error-manager.d.ts +254 -0
- package/dist/lib/mcp/error-manager.js +501 -0
- package/dist/lib/mcp/error-recovery.d.ts +158 -0
- package/dist/lib/mcp/error-recovery.js +405 -0
- package/dist/lib/mcp/function-calling.js +11 -3
- package/dist/lib/mcp/health-monitor.d.ts +256 -0
- package/dist/lib/mcp/health-monitor.js +621 -0
- package/dist/lib/mcp/logging.js +5 -0
- package/dist/lib/mcp/neurolink-mcp-client.js +2 -1
- package/dist/lib/mcp/orchestrator.d.ts +136 -5
- package/dist/lib/mcp/orchestrator.js +332 -16
- package/dist/lib/mcp/registry.d.ts +71 -16
- package/dist/lib/mcp/registry.js +104 -6
- package/dist/lib/mcp/semaphore-manager.d.ts +137 -0
- package/dist/lib/mcp/semaphore-manager.js +329 -0
- package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.d.ts +2 -2
- package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.js +5 -4
- package/dist/lib/mcp/session-manager.d.ts +186 -0
- package/dist/lib/mcp/session-manager.js +400 -0
- package/dist/lib/mcp/session-persistence.d.ts +93 -0
- package/dist/lib/mcp/session-persistence.js +298 -0
- package/dist/lib/mcp/tool-integration.js +1 -1
- package/dist/lib/mcp/tool-registry.d.ts +55 -34
- package/dist/lib/mcp/tool-registry.js +111 -97
- package/dist/lib/mcp/transport-manager.d.ts +153 -0
- package/dist/lib/mcp/transport-manager.js +330 -0
- package/dist/lib/mcp/unified-mcp.js +6 -1
- package/dist/lib/mcp/unified-registry.d.ts +54 -5
- package/dist/lib/mcp/unified-registry.js +139 -6
- package/dist/lib/neurolink.d.ts +101 -0
- package/dist/lib/neurolink.js +147 -1
- package/dist/lib/providers/agent-enhanced-provider.d.ts +11 -2
- package/dist/lib/providers/agent-enhanced-provider.js +86 -15
- package/dist/lib/providers/amazonBedrock.d.ts +9 -1
- package/dist/lib/providers/amazonBedrock.js +26 -2
- package/dist/lib/providers/analytics-helper.d.ts +53 -0
- package/dist/lib/providers/analytics-helper.js +151 -0
- package/dist/lib/providers/anthropic.d.ts +11 -1
- package/dist/lib/providers/anthropic.js +29 -4
- package/dist/lib/providers/azureOpenAI.d.ts +3 -1
- package/dist/lib/providers/azureOpenAI.js +28 -4
- package/dist/lib/providers/function-calling-provider.d.ts +9 -1
- package/dist/lib/providers/function-calling-provider.js +14 -1
- package/dist/lib/providers/googleAIStudio.d.ts +15 -1
- package/dist/lib/providers/googleAIStudio.js +32 -2
- package/dist/lib/providers/googleVertexAI.d.ts +9 -1
- package/dist/lib/providers/googleVertexAI.js +31 -2
- package/dist/lib/providers/huggingFace.d.ts +3 -1
- package/dist/lib/providers/huggingFace.js +26 -3
- package/dist/lib/providers/mcp-provider.d.ts +9 -1
- package/dist/lib/providers/mcp-provider.js +12 -0
- package/dist/lib/providers/mistralAI.d.ts +3 -1
- package/dist/lib/providers/mistralAI.js +25 -2
- package/dist/lib/providers/ollama.d.ts +3 -1
- package/dist/lib/providers/ollama.js +27 -4
- package/dist/lib/providers/openAI.d.ts +15 -1
- package/dist/lib/providers/openAI.js +32 -2
- package/dist/lib/proxy/proxy-fetch.js +8 -7
- package/dist/lib/services/streaming/streaming-manager.d.ts +29 -0
- package/dist/lib/services/streaming/streaming-manager.js +244 -0
- package/dist/lib/services/types.d.ts +155 -0
- package/dist/lib/services/types.js +2 -0
- package/dist/lib/services/websocket/websocket-server.d.ts +34 -0
- package/dist/lib/services/websocket/websocket-server.js +304 -0
- package/dist/lib/telemetry/index.d.ts +15 -0
- package/dist/lib/telemetry/index.js +22 -0
- package/dist/lib/telemetry/telemetry-service.d.ts +47 -0
- package/dist/lib/telemetry/telemetry-service.js +259 -0
- package/dist/lib/utils/streaming-utils.d.ts +67 -0
- package/dist/lib/utils/streaming-utils.js +201 -0
- package/dist/mcp/contracts/mcpContract.d.ts +118 -0
- package/dist/mcp/contracts/mcpContract.js +5 -0
- package/dist/mcp/dynamic-chain-executor.d.ts +201 -0
- package/dist/mcp/dynamic-chain-executor.js +489 -0
- package/dist/mcp/dynamic-orchestrator.d.ts +109 -0
- package/dist/mcp/dynamic-orchestrator.js +351 -0
- package/dist/mcp/error-manager.d.ts +254 -0
- package/dist/mcp/error-manager.js +501 -0
- package/dist/mcp/error-recovery.d.ts +158 -0
- package/dist/mcp/error-recovery.js +405 -0
- package/dist/mcp/function-calling.js +11 -3
- package/dist/mcp/health-monitor.d.ts +256 -0
- package/dist/mcp/health-monitor.js +621 -0
- package/dist/mcp/logging.js +5 -0
- package/dist/mcp/neurolink-mcp-client.js +2 -1
- package/dist/mcp/orchestrator.d.ts +136 -5
- package/dist/mcp/orchestrator.js +332 -16
- package/dist/mcp/plugins/core/neurolink-mcp.json +15 -15
- package/dist/mcp/registry.d.ts +71 -16
- package/dist/mcp/registry.js +104 -6
- package/dist/mcp/semaphore-manager.d.ts +137 -0
- package/dist/mcp/semaphore-manager.js +329 -0
- package/dist/mcp/servers/ai-providers/ai-workflow-tools.d.ts +2 -2
- package/dist/mcp/servers/ai-providers/ai-workflow-tools.js +5 -4
- package/dist/mcp/session-manager.d.ts +186 -0
- package/dist/mcp/session-manager.js +400 -0
- package/dist/mcp/session-persistence.d.ts +93 -0
- package/dist/mcp/session-persistence.js +299 -0
- package/dist/mcp/tool-integration.js +1 -1
- package/dist/mcp/tool-registry.d.ts +55 -34
- package/dist/mcp/tool-registry.js +111 -97
- package/dist/mcp/transport-manager.d.ts +153 -0
- package/dist/mcp/transport-manager.js +331 -0
- package/dist/mcp/unified-mcp.js +6 -1
- package/dist/mcp/unified-registry.d.ts +54 -5
- package/dist/mcp/unified-registry.js +139 -6
- package/dist/neurolink.d.ts +101 -0
- package/dist/neurolink.js +147 -1
- package/dist/providers/agent-enhanced-provider.d.ts +11 -2
- package/dist/providers/agent-enhanced-provider.js +86 -15
- package/dist/providers/amazonBedrock.d.ts +9 -1
- package/dist/providers/amazonBedrock.js +26 -2
- package/dist/providers/analytics-helper.d.ts +53 -0
- package/dist/providers/analytics-helper.js +151 -0
- package/dist/providers/anthropic.d.ts +11 -1
- package/dist/providers/anthropic.js +29 -4
- package/dist/providers/azureOpenAI.d.ts +3 -1
- package/dist/providers/azureOpenAI.js +29 -4
- package/dist/providers/function-calling-provider.d.ts +9 -1
- package/dist/providers/function-calling-provider.js +14 -1
- package/dist/providers/googleAIStudio.d.ts +15 -1
- package/dist/providers/googleAIStudio.js +32 -2
- package/dist/providers/googleVertexAI.d.ts +9 -1
- package/dist/providers/googleVertexAI.js +31 -2
- package/dist/providers/huggingFace.d.ts +3 -1
- package/dist/providers/huggingFace.js +26 -3
- package/dist/providers/mcp-provider.d.ts +9 -1
- package/dist/providers/mcp-provider.js +12 -0
- package/dist/providers/mistralAI.d.ts +3 -1
- package/dist/providers/mistralAI.js +25 -2
- package/dist/providers/ollama.d.ts +3 -1
- package/dist/providers/ollama.js +27 -4
- package/dist/providers/openAI.d.ts +15 -1
- package/dist/providers/openAI.js +33 -2
- package/dist/proxy/proxy-fetch.js +8 -7
- package/dist/services/streaming/streaming-manager.d.ts +29 -0
- package/dist/services/streaming/streaming-manager.js +244 -0
- package/dist/services/types.d.ts +155 -0
- package/dist/services/types.js +2 -0
- package/dist/services/websocket/websocket-server.d.ts +34 -0
- package/dist/services/websocket/websocket-server.js +304 -0
- package/dist/telemetry/index.d.ts +15 -0
- package/dist/telemetry/index.js +22 -0
- package/dist/telemetry/telemetry-service.d.ts +47 -0
- package/dist/telemetry/telemetry-service.js +261 -0
- package/dist/utils/streaming-utils.d.ts +67 -0
- package/dist/utils/streaming-utils.js +201 -0
- package/package.json +245 -228
|
@@ -5,14 +5,25 @@ import { MCPRegistry } from "./registry.js";
|
|
|
5
5
|
import { discoverMCPServers, autoRegisterMCPServers, } from "./auto-discovery.js";
|
|
6
6
|
import { unifiedRegistryLogger } from "./logging.js";
|
|
7
7
|
import { MCPToolRegistry, } from "./tool-registry.js";
|
|
8
|
+
import { TransportManager, TransportConfigSchema, } from "./transport-manager.js";
|
|
9
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
10
|
+
import { ErrorManager } from "./error-manager.js";
|
|
8
11
|
/**
|
|
9
12
|
* Unified registry combining multiple sources
|
|
10
13
|
*/
|
|
11
14
|
export class UnifiedMCPRegistry extends MCPToolRegistry {
|
|
15
|
+
errorManager;
|
|
12
16
|
autoDiscoveryEnabled = true;
|
|
13
17
|
autoDiscoveredServers = [];
|
|
14
18
|
manualServers = new Map();
|
|
15
19
|
availableServers = new Set();
|
|
20
|
+
transportManager;
|
|
21
|
+
activeConnections = new Map();
|
|
22
|
+
constructor(errorManager = new ErrorManager()) {
|
|
23
|
+
super();
|
|
24
|
+
this.errorManager = errorManager;
|
|
25
|
+
this.transportManager = new TransportManager(this.errorManager);
|
|
26
|
+
}
|
|
16
27
|
/**
|
|
17
28
|
* Initialize with auto-discovery
|
|
18
29
|
*/
|
|
@@ -79,7 +90,12 @@ export class UnifiedMCPRegistry extends MCPToolRegistry {
|
|
|
79
90
|
try {
|
|
80
91
|
// Get tools from plugin metadata if available
|
|
81
92
|
const tools = await this.listTools();
|
|
82
|
-
allTools.push(...tools)
|
|
93
|
+
allTools.push(...tools.map((tool) => ({
|
|
94
|
+
...tool,
|
|
95
|
+
id: tool.name,
|
|
96
|
+
serverId: tool.serverId || plugin.metadata.name,
|
|
97
|
+
source: "unified",
|
|
98
|
+
})));
|
|
83
99
|
}
|
|
84
100
|
catch (error) {
|
|
85
101
|
unifiedRegistryLogger.warn(`Failed to get tools from ${plugin.metadata.name}:`, error);
|
|
@@ -125,14 +141,22 @@ export class UnifiedMCPRegistry extends MCPToolRegistry {
|
|
|
125
141
|
this.availableServers.add(id);
|
|
126
142
|
}
|
|
127
143
|
/**
|
|
128
|
-
* Get registry statistics
|
|
144
|
+
* Get registry statistics (override parent method)
|
|
129
145
|
*/
|
|
130
|
-
|
|
146
|
+
getStats() {
|
|
147
|
+
// Return execution stats in the expected format
|
|
148
|
+
return super.getStats();
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Get detailed registry statistics
|
|
152
|
+
*/
|
|
153
|
+
async getDetailedStats() {
|
|
131
154
|
const plugins = this.list();
|
|
132
155
|
const bySource = {};
|
|
133
156
|
const byType = {};
|
|
134
157
|
for (const plugin of plugins) {
|
|
135
|
-
|
|
158
|
+
const source = plugin.source || "unknown";
|
|
159
|
+
bySource[source] = (bySource[source] || 0) + 1;
|
|
136
160
|
// Extract type from name or metadata
|
|
137
161
|
const type = plugin.metadata.name.split("/")[1]?.split("-")[0] || "unknown";
|
|
138
162
|
byType[type] = (byType[type] || 0) + 1;
|
|
@@ -147,14 +171,123 @@ export class UnifiedMCPRegistry extends MCPToolRegistry {
|
|
|
147
171
|
};
|
|
148
172
|
}
|
|
149
173
|
/**
|
|
150
|
-
*
|
|
174
|
+
* Add external MCP server programmatically
|
|
175
|
+
*
|
|
176
|
+
* @param serverId - Unique server identifier
|
|
177
|
+
* @param config - Server configuration (stdio, sse, or http)
|
|
151
178
|
*/
|
|
152
|
-
|
|
179
|
+
async addExternalServer(serverId, config) {
|
|
180
|
+
unifiedRegistryLogger.info(`Adding external server: ${serverId} (${config.type})`);
|
|
181
|
+
// Create server metadata
|
|
182
|
+
const serverMeta = {
|
|
183
|
+
metadata: {
|
|
184
|
+
name: serverId,
|
|
185
|
+
version: "1.0.0",
|
|
186
|
+
main: "index.js",
|
|
187
|
+
engine: { neurolink: ">=4.0.0" },
|
|
188
|
+
description: `External ${config.type} server: ${serverId}`,
|
|
189
|
+
permissions: ["network", "filesystem"],
|
|
190
|
+
},
|
|
191
|
+
entryPath: "",
|
|
192
|
+
source: "installed",
|
|
193
|
+
constructor: undefined,
|
|
194
|
+
};
|
|
195
|
+
// Register in internal registry
|
|
196
|
+
this.register(serverMeta);
|
|
197
|
+
this.manualServers.set(serverId, config);
|
|
198
|
+
this.availableServers.add(serverId);
|
|
199
|
+
// Establish actual connection to make server immediately reachable
|
|
200
|
+
try {
|
|
201
|
+
// Validate config for stdio transport (most common case)
|
|
202
|
+
if (config.type === "stdio" && !config.command) {
|
|
203
|
+
throw new Error("Command is required for stdio transport");
|
|
204
|
+
}
|
|
205
|
+
// Create transport with proper type validation
|
|
206
|
+
// Validate config shape before creating transport
|
|
207
|
+
const validatedConfig = TransportConfigSchema.parse(config);
|
|
208
|
+
const transport = await this.transportManager.createTransport(validatedConfig);
|
|
209
|
+
const client = new Client({
|
|
210
|
+
name: "neurolink-client",
|
|
211
|
+
version: "4.1.0",
|
|
212
|
+
}, {
|
|
213
|
+
capabilities: {
|
|
214
|
+
tools: {},
|
|
215
|
+
logging: {},
|
|
216
|
+
},
|
|
217
|
+
});
|
|
218
|
+
// Connect the client
|
|
219
|
+
await client.connect(transport);
|
|
220
|
+
this.activeConnections.set(serverId, client);
|
|
221
|
+
unifiedRegistryLogger.info(`Successfully connected to external server: ${serverId}`);
|
|
222
|
+
unifiedRegistryLogger.info(`Successfully added external server: ${serverId}`);
|
|
223
|
+
}
|
|
224
|
+
catch (error) {
|
|
225
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
226
|
+
unifiedRegistryLogger.warn(`Failed to establish connection to ${serverId}: ${errorMessage}. Server registered but not connected.`);
|
|
227
|
+
unifiedRegistryLogger.info(`Successfully registered external server: ${serverId} but connection failed.`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Get active connection for a server
|
|
232
|
+
*/
|
|
233
|
+
getConnection(serverId) {
|
|
234
|
+
return this.activeConnections.get(serverId);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Check if server is actively connected
|
|
238
|
+
*/
|
|
239
|
+
isConnected(serverId) {
|
|
240
|
+
return this.activeConnections.has(serverId);
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Clear all registries and active connections (synchronous, preserves base API contract)
|
|
244
|
+
*/
|
|
245
|
+
/**
|
|
246
|
+
* Clear registries without closing connections (internal use)
|
|
247
|
+
*/
|
|
248
|
+
clearRegistriesOnly() {
|
|
153
249
|
super.clear();
|
|
154
250
|
this.autoDiscoveredServers = [];
|
|
155
251
|
this.manualServers.clear();
|
|
156
252
|
this.availableServers.clear();
|
|
157
253
|
}
|
|
254
|
+
/**
|
|
255
|
+
* Clear all registries and initiate async connection cleanup
|
|
256
|
+
*/
|
|
257
|
+
clear() {
|
|
258
|
+
// Close all active connections before clearing registries to prevent resource leaks
|
|
259
|
+
const closePromises = [];
|
|
260
|
+
for (const [serverId, client] of this.activeConnections) {
|
|
261
|
+
closePromises.push(client.close().catch((error) => {
|
|
262
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
263
|
+
unifiedRegistryLogger.warn(`Failed to close connection for ${serverId}: ${errorMessage}`);
|
|
264
|
+
}));
|
|
265
|
+
}
|
|
266
|
+
// Handle async cleanup without blocking synchronous clear()
|
|
267
|
+
Promise.allSettled(closePromises).then(() => {
|
|
268
|
+
this.activeConnections.clear();
|
|
269
|
+
});
|
|
270
|
+
// Clear registries after initiating connection cleanup
|
|
271
|
+
this.clearRegistriesOnly();
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Clear all registries and close active connections asynchronously
|
|
275
|
+
*/
|
|
276
|
+
async clearAsync() {
|
|
277
|
+
// Close all active connections first
|
|
278
|
+
for (const [serverId, client] of this.activeConnections) {
|
|
279
|
+
try {
|
|
280
|
+
await client.close();
|
|
281
|
+
}
|
|
282
|
+
catch (error) {
|
|
283
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
284
|
+
unifiedRegistryLogger.warn(`Failed to close connection for ${serverId}: ${errorMessage}`);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
this.activeConnections.clear();
|
|
288
|
+
// Clear registries without attempting to close connections again
|
|
289
|
+
this.clearRegistriesOnly();
|
|
290
|
+
}
|
|
158
291
|
}
|
|
159
292
|
/**
|
|
160
293
|
* Default unified registry instance
|
package/dist/neurolink.d.ts
CHANGED
|
@@ -15,6 +15,15 @@ export interface TextGenerationOptions {
|
|
|
15
15
|
schema?: any;
|
|
16
16
|
timeout?: number | string;
|
|
17
17
|
disableTools?: boolean;
|
|
18
|
+
enableAnalytics?: boolean;
|
|
19
|
+
enableEvaluation?: boolean;
|
|
20
|
+
context?: Record<string, any>;
|
|
21
|
+
evaluationDomain?: string;
|
|
22
|
+
toolUsageContext?: string;
|
|
23
|
+
conversationHistory?: Array<{
|
|
24
|
+
role: string;
|
|
25
|
+
content: string;
|
|
26
|
+
}>;
|
|
18
27
|
}
|
|
19
28
|
export interface StreamTextOptions {
|
|
20
29
|
prompt: string;
|
|
@@ -23,7 +32,12 @@ export interface StreamTextOptions {
|
|
|
23
32
|
temperature?: number;
|
|
24
33
|
maxTokens?: number;
|
|
25
34
|
systemPrompt?: string;
|
|
35
|
+
schema?: any;
|
|
26
36
|
timeout?: number | string;
|
|
37
|
+
disableTools?: boolean;
|
|
38
|
+
enableAnalytics?: boolean;
|
|
39
|
+
enableEvaluation?: boolean;
|
|
40
|
+
context?: Record<string, any>;
|
|
27
41
|
}
|
|
28
42
|
export interface TextGenerationResult {
|
|
29
43
|
content: string;
|
|
@@ -115,4 +129,91 @@ export declare class NeuroLink {
|
|
|
115
129
|
hasServer: boolean;
|
|
116
130
|
}[];
|
|
117
131
|
}>;
|
|
132
|
+
/**
|
|
133
|
+
* Add a new MCP server programmatically
|
|
134
|
+
*
|
|
135
|
+
* Allows dynamic registration of MCP servers at runtime for enhanced
|
|
136
|
+
* tool ecosystem management. Perfect for integrating external services
|
|
137
|
+
* like Bitbucket, Slack, databases, etc.
|
|
138
|
+
*
|
|
139
|
+
* @param serverId - Unique identifier for the server (e.g., 'bitbucket', 'slack-api')
|
|
140
|
+
* @param config - Server configuration with command and execution parameters
|
|
141
|
+
* @returns Promise that resolves when server is successfully added and connected
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* // Add Bitbucket MCP server
|
|
146
|
+
* await neurolink.addMCPServer('bitbucket', {
|
|
147
|
+
* command: 'npx',
|
|
148
|
+
* args: ['-y', '@nexus2520/bitbucket-mcp-server'],
|
|
149
|
+
* env: {
|
|
150
|
+
* BITBUCKET_USERNAME: 'your-username',
|
|
151
|
+
* BITBUCKET_APP_PASSWORD: 'your-app-password'
|
|
152
|
+
* }
|
|
153
|
+
* });
|
|
154
|
+
*
|
|
155
|
+
* // Add custom database connector
|
|
156
|
+
* await neurolink.addMCPServer('database', {
|
|
157
|
+
* command: 'node',
|
|
158
|
+
* args: ['./custom-db-mcp-server.js'],
|
|
159
|
+
* env: { DB_CONNECTION_STRING: 'postgresql://...' }
|
|
160
|
+
* });
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
addMCPServer(serverId: string, config: {
|
|
164
|
+
command: string;
|
|
165
|
+
args?: string[];
|
|
166
|
+
env?: Record<string, string>;
|
|
167
|
+
cwd?: string;
|
|
168
|
+
type?: "stdio" | "sse" | "http";
|
|
169
|
+
url?: string;
|
|
170
|
+
headers?: Record<string, string>;
|
|
171
|
+
timeout?: number;
|
|
172
|
+
}): Promise<void>;
|
|
173
|
+
/**
|
|
174
|
+
* Alias for generateText() - CLI-SDK consistency
|
|
175
|
+
* @param options - Text generation options
|
|
176
|
+
* @returns Promise resolving to text generation result
|
|
177
|
+
*/
|
|
178
|
+
generate(options: TextGenerationOptions): Promise<TextGenerationResult>;
|
|
179
|
+
/**
|
|
180
|
+
* Short alias for generateText() - CLI-SDK consistency
|
|
181
|
+
* @param options - Text generation options
|
|
182
|
+
* @returns Promise resolving to text generation result
|
|
183
|
+
*/
|
|
184
|
+
gen(options: TextGenerationOptions): Promise<TextGenerationResult>;
|
|
185
|
+
/**
|
|
186
|
+
* Get the connection client for a specific MCP server
|
|
187
|
+
* @param serverId - The ID of the server to get connection for
|
|
188
|
+
* @returns Client connection object or undefined if not connected
|
|
189
|
+
*/
|
|
190
|
+
getConnection(serverId: string): import("@modelcontextprotocol/sdk/client/index.js").Client<{
|
|
191
|
+
method: string;
|
|
192
|
+
params?: {
|
|
193
|
+
[x: string]: unknown;
|
|
194
|
+
_meta?: {
|
|
195
|
+
[x: string]: unknown;
|
|
196
|
+
progressToken?: string | number | undefined;
|
|
197
|
+
} | undefined;
|
|
198
|
+
} | undefined;
|
|
199
|
+
}, {
|
|
200
|
+
method: string;
|
|
201
|
+
params?: {
|
|
202
|
+
[x: string]: unknown;
|
|
203
|
+
_meta?: {
|
|
204
|
+
[x: string]: unknown;
|
|
205
|
+
} | undefined;
|
|
206
|
+
} | undefined;
|
|
207
|
+
}, {
|
|
208
|
+
[x: string]: unknown;
|
|
209
|
+
_meta?: {
|
|
210
|
+
[x: string]: unknown;
|
|
211
|
+
} | undefined;
|
|
212
|
+
}> | undefined;
|
|
213
|
+
/**
|
|
214
|
+
* Check if a specific MCP server is currently connected
|
|
215
|
+
* @param serverId - The ID of the server to check
|
|
216
|
+
* @returns True if server is connected, false otherwise
|
|
217
|
+
*/
|
|
218
|
+
isConnected(serverId: string): boolean;
|
|
118
219
|
}
|
package/dist/neurolink.js
CHANGED
|
@@ -135,6 +135,14 @@ export class NeuroLink {
|
|
|
135
135
|
maxTokens: options.maxTokens,
|
|
136
136
|
systemPrompt: enhancedSystemPrompt,
|
|
137
137
|
timeout: options.timeout,
|
|
138
|
+
// NEW: Pass enhancement options
|
|
139
|
+
enableAnalytics: options.enableAnalytics,
|
|
140
|
+
enableEvaluation: options.enableEvaluation,
|
|
141
|
+
context: options.context,
|
|
142
|
+
// NEW: Lighthouse-compatible domain-aware evaluation
|
|
143
|
+
evaluationDomain: options.evaluationDomain,
|
|
144
|
+
toolUsageContext: options.toolUsageContext,
|
|
145
|
+
conversationHistory: options.conversationHistory,
|
|
138
146
|
}, options.schema);
|
|
139
147
|
if (!result) {
|
|
140
148
|
throw new Error("No response received from AI provider");
|
|
@@ -166,6 +174,9 @@ export class NeuroLink {
|
|
|
166
174
|
toolsUsed: metadata.toolsUsed || [],
|
|
167
175
|
enhancedWithTools: metadata.enhancedWithTools || false,
|
|
168
176
|
availableTools: availableTools.length > 0 ? availableTools : undefined,
|
|
177
|
+
// NEW: Preserve enhancement data from provider
|
|
178
|
+
...(result.analytics && { analytics: result.analytics }),
|
|
179
|
+
...(result.evaluation && { evaluation: result.evaluation }),
|
|
169
180
|
};
|
|
170
181
|
}
|
|
171
182
|
catch (error) {
|
|
@@ -225,6 +236,14 @@ export class NeuroLink {
|
|
|
225
236
|
maxTokens: options.maxTokens,
|
|
226
237
|
systemPrompt: options.systemPrompt,
|
|
227
238
|
timeout: options.timeout,
|
|
239
|
+
// NEW: Pass enhancement options
|
|
240
|
+
enableAnalytics: options.enableAnalytics,
|
|
241
|
+
enableEvaluation: options.enableEvaluation,
|
|
242
|
+
context: options.context,
|
|
243
|
+
// NEW: Lighthouse-compatible domain-aware evaluation
|
|
244
|
+
evaluationDomain: options.evaluationDomain,
|
|
245
|
+
toolUsageContext: options.toolUsageContext,
|
|
246
|
+
conversationHistory: options.conversationHistory,
|
|
228
247
|
}, options.schema);
|
|
229
248
|
if (!result) {
|
|
230
249
|
throw new Error("No response received from AI provider");
|
|
@@ -250,6 +269,9 @@ export class NeuroLink {
|
|
|
250
269
|
provider: providerName,
|
|
251
270
|
usage: result.usage,
|
|
252
271
|
responseTime,
|
|
272
|
+
// NEW: Preserve enhancement data from provider
|
|
273
|
+
...(result.analytics && { analytics: result.analytics }),
|
|
274
|
+
...(result.evaluation && { evaluation: result.evaluation }),
|
|
253
275
|
};
|
|
254
276
|
}
|
|
255
277
|
catch (error) {
|
|
@@ -409,7 +431,11 @@ Note: Tool integration is currently in development. Please provide helpful respo
|
|
|
409
431
|
async testProvider(providerName, testPrompt = "test") {
|
|
410
432
|
try {
|
|
411
433
|
const provider = await AIProviderFactory.createProvider(providerName);
|
|
412
|
-
await provider.generateText(
|
|
434
|
+
await provider.generateText({
|
|
435
|
+
prompt: testPrompt,
|
|
436
|
+
enableAnalytics: false,
|
|
437
|
+
enableEvaluation: false,
|
|
438
|
+
});
|
|
413
439
|
return true;
|
|
414
440
|
}
|
|
415
441
|
catch (error) {
|
|
@@ -446,4 +472,124 @@ Note: Tool integration is currently in development. Please provide helpful respo
|
|
|
446
472
|
})),
|
|
447
473
|
};
|
|
448
474
|
}
|
|
475
|
+
/**
|
|
476
|
+
* Add a new MCP server programmatically
|
|
477
|
+
*
|
|
478
|
+
* Allows dynamic registration of MCP servers at runtime for enhanced
|
|
479
|
+
* tool ecosystem management. Perfect for integrating external services
|
|
480
|
+
* like Bitbucket, Slack, databases, etc.
|
|
481
|
+
*
|
|
482
|
+
* @param serverId - Unique identifier for the server (e.g., 'bitbucket', 'slack-api')
|
|
483
|
+
* @param config - Server configuration with command and execution parameters
|
|
484
|
+
* @returns Promise that resolves when server is successfully added and connected
|
|
485
|
+
*
|
|
486
|
+
* @example
|
|
487
|
+
* ```typescript
|
|
488
|
+
* // Add Bitbucket MCP server
|
|
489
|
+
* await neurolink.addMCPServer('bitbucket', {
|
|
490
|
+
* command: 'npx',
|
|
491
|
+
* args: ['-y', '@nexus2520/bitbucket-mcp-server'],
|
|
492
|
+
* env: {
|
|
493
|
+
* BITBUCKET_USERNAME: 'your-username',
|
|
494
|
+
* BITBUCKET_APP_PASSWORD: 'your-app-password'
|
|
495
|
+
* }
|
|
496
|
+
* });
|
|
497
|
+
*
|
|
498
|
+
* // Add custom database connector
|
|
499
|
+
* await neurolink.addMCPServer('database', {
|
|
500
|
+
* command: 'node',
|
|
501
|
+
* args: ['./custom-db-mcp-server.js'],
|
|
502
|
+
* env: { DB_CONNECTION_STRING: 'postgresql://...' }
|
|
503
|
+
* });
|
|
504
|
+
* ```
|
|
505
|
+
*/
|
|
506
|
+
async addMCPServer(serverId, config) {
|
|
507
|
+
const functionTag = "NeuroLink.addMCPServer";
|
|
508
|
+
mcpLogger.info(`[${functionTag}] Adding MCP server: ${serverId}`, {
|
|
509
|
+
command: config.command,
|
|
510
|
+
argsCount: config.args?.length || 0,
|
|
511
|
+
hasEnv: Object.keys(config.env || {}).length > 0,
|
|
512
|
+
});
|
|
513
|
+
try {
|
|
514
|
+
// Ensure MCP is initialized
|
|
515
|
+
await this.initializeMCP();
|
|
516
|
+
// Add server to unified registry with configurable transport type
|
|
517
|
+
const transportType = config.type || "stdio";
|
|
518
|
+
// Validate URL requirement for non-stdio transports
|
|
519
|
+
if ((transportType === "sse" || transportType === "http") &&
|
|
520
|
+
!config.url) {
|
|
521
|
+
throw new Error(`URL is required for ${transportType} transport. Please provide config.url for server '${serverId}'.`);
|
|
522
|
+
}
|
|
523
|
+
const transportConfig = {
|
|
524
|
+
type: transportType,
|
|
525
|
+
...(transportType === "stdio" && {
|
|
526
|
+
command: config.command,
|
|
527
|
+
args: config.args || [],
|
|
528
|
+
env: config.env || {},
|
|
529
|
+
cwd: config.cwd,
|
|
530
|
+
}),
|
|
531
|
+
...(transportType === "sse" && {
|
|
532
|
+
url: config.url,
|
|
533
|
+
headers: config.headers,
|
|
534
|
+
timeout: config.timeout,
|
|
535
|
+
}),
|
|
536
|
+
...(transportType === "http" && {
|
|
537
|
+
url: config.url,
|
|
538
|
+
headers: config.headers,
|
|
539
|
+
timeout: config.timeout,
|
|
540
|
+
}),
|
|
541
|
+
};
|
|
542
|
+
await unifiedRegistry.addExternalServer(serverId, transportConfig);
|
|
543
|
+
// Check if server is actually connected vs just registered
|
|
544
|
+
const isConnected = unifiedRegistry.isConnected(serverId);
|
|
545
|
+
if (isConnected) {
|
|
546
|
+
mcpLogger.info(`[${functionTag}] Successfully connected to MCP server: ${serverId}`);
|
|
547
|
+
}
|
|
548
|
+
else {
|
|
549
|
+
mcpLogger.info(`[${functionTag}] MCP server registered: ${serverId} (connection failed, but server available for retry)`);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
catch (error) {
|
|
553
|
+
mcpLogger.error(`[${functionTag}] Failed to add MCP server: ${serverId}`, {
|
|
554
|
+
error: error instanceof Error ? error.message : String(error),
|
|
555
|
+
});
|
|
556
|
+
const newError = new Error(`Failed to add MCP server '${serverId}': ${error instanceof Error ? error.message : String(error)}`);
|
|
557
|
+
if (error instanceof Error && error.stack) {
|
|
558
|
+
newError.stack = `${newError.stack}\nCaused by: ${error.stack}`;
|
|
559
|
+
}
|
|
560
|
+
throw newError;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* Alias for generateText() - CLI-SDK consistency
|
|
565
|
+
* @param options - Text generation options
|
|
566
|
+
* @returns Promise resolving to text generation result
|
|
567
|
+
*/
|
|
568
|
+
async generate(options) {
|
|
569
|
+
return this.generateText(options);
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* Short alias for generateText() - CLI-SDK consistency
|
|
573
|
+
* @param options - Text generation options
|
|
574
|
+
* @returns Promise resolving to text generation result
|
|
575
|
+
*/
|
|
576
|
+
async gen(options) {
|
|
577
|
+
return this.generateText(options);
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* Get the connection client for a specific MCP server
|
|
581
|
+
* @param serverId - The ID of the server to get connection for
|
|
582
|
+
* @returns Client connection object or undefined if not connected
|
|
583
|
+
*/
|
|
584
|
+
getConnection(serverId) {
|
|
585
|
+
return unifiedRegistry.getConnection(serverId);
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* Check if a specific MCP server is currently connected
|
|
589
|
+
* @param serverId - The ID of the server to check
|
|
590
|
+
* @returns True if server is connected, false otherwise
|
|
591
|
+
*/
|
|
592
|
+
isConnected(serverId) {
|
|
593
|
+
return unifiedRegistry.isConnected(serverId);
|
|
594
|
+
}
|
|
449
595
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Integrates direct tools with AI providers for true agent functionality
|
|
4
4
|
*/
|
|
5
5
|
import { type GenerateTextResult, type StreamTextResult, type ToolSet } from "ai";
|
|
6
|
-
import type { AIProvider, TextGenerationOptions,
|
|
6
|
+
import type { AIProvider, TextGenerationOptions, EnhancedGenerateTextResult, EnhancedStreamTextOptions } from "../core/types.js";
|
|
7
7
|
/**
|
|
8
8
|
* Agent configuration options
|
|
9
9
|
*/
|
|
@@ -30,6 +30,7 @@ interface AgentConfig {
|
|
|
30
30
|
export declare class AgentEnhancedProvider implements AIProvider {
|
|
31
31
|
private config;
|
|
32
32
|
private model;
|
|
33
|
+
private resolvedModelName;
|
|
33
34
|
private mcpSystem;
|
|
34
35
|
private mcpInitialized;
|
|
35
36
|
private mcpInitializing;
|
|
@@ -45,7 +46,7 @@ export declare class AgentEnhancedProvider implements AIProvider {
|
|
|
45
46
|
*/
|
|
46
47
|
private getCombinedTools;
|
|
47
48
|
generateText(optionsOrPrompt: TextGenerationOptions | string): Promise<GenerateTextResult<ToolSet, unknown> | null>;
|
|
48
|
-
streamText(optionsOrPrompt:
|
|
49
|
+
streamText(optionsOrPrompt: EnhancedStreamTextOptions | string): Promise<StreamTextResult<ToolSet, unknown> | null>;
|
|
49
50
|
/**
|
|
50
51
|
* Determine if we should force tool usage based on prompt patterns
|
|
51
52
|
*/
|
|
@@ -68,6 +69,14 @@ export declare class AgentEnhancedProvider implements AIProvider {
|
|
|
68
69
|
* Create multiple agent providers for comparison
|
|
69
70
|
*/
|
|
70
71
|
static createMultiProviderAgents(): Record<string, AgentEnhancedProvider>;
|
|
72
|
+
/**
|
|
73
|
+
* Alias for generateText() - CLI-SDK consistency
|
|
74
|
+
*/
|
|
75
|
+
generate(optionsOrPrompt: TextGenerationOptions | string, analysisSchema?: any): Promise<EnhancedGenerateTextResult | null>;
|
|
76
|
+
/**
|
|
77
|
+
* Short alias for generateText() - CLI-SDK consistency
|
|
78
|
+
*/
|
|
79
|
+
gen(optionsOrPrompt: TextGenerationOptions | string, analysisSchema?: any): Promise<EnhancedGenerateTextResult | null>;
|
|
71
80
|
}
|
|
72
81
|
/**
|
|
73
82
|
* Helper function to create agent provider
|