@juspay/neurolink 7.47.0 → 7.47.2
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 +12 -0
- package/dist/core/baseProvider.d.ts +1 -1
- package/dist/core/baseProvider.js +3 -3
- package/dist/core/conversationMemoryManager.d.ts +1 -1
- package/dist/core/conversationMemoryManager.js +1 -1
- package/dist/core/redisConversationMemoryManager.d.ts +2 -2
- package/dist/core/redisConversationMemoryManager.js +15 -9
- package/dist/factories/providerRegistry.js +1 -1
- package/dist/lib/core/baseProvider.d.ts +1 -1
- package/dist/lib/core/baseProvider.js +3 -3
- package/dist/lib/core/conversationMemoryManager.d.ts +1 -1
- package/dist/lib/core/conversationMemoryManager.js +1 -1
- package/dist/lib/core/redisConversationMemoryManager.d.ts +2 -2
- package/dist/lib/core/redisConversationMemoryManager.js +15 -9
- package/dist/lib/factories/providerRegistry.js +1 -1
- package/dist/lib/neurolink.d.ts +6 -1
- package/dist/lib/neurolink.js +37 -33
- package/dist/lib/providers/anthropic.js +1 -1
- package/dist/lib/providers/anthropicBaseProvider.js +1 -1
- package/dist/lib/providers/azureOpenai.js +1 -1
- package/dist/lib/providers/googleAiStudio.js +1 -1
- package/dist/lib/providers/googleVertex.js +1 -1
- package/dist/lib/providers/huggingFace.js +1 -1
- package/dist/lib/providers/litellm.js +1 -1
- package/dist/lib/providers/mistral.js +1 -1
- package/dist/lib/providers/openAI.js +1 -1
- package/dist/lib/providers/openaiCompatible.js +1 -1
- package/dist/lib/utils/conversationMemory.d.ts +1 -1
- package/dist/lib/utils/conversationMemory.js +2 -2
- package/dist/lib/utils/conversationMemoryUtils.d.ts +1 -1
- package/dist/lib/utils/conversationMemoryUtils.js +2 -2
- package/dist/neurolink.d.ts +6 -1
- package/dist/neurolink.js +37 -33
- package/dist/providers/anthropic.js +1 -1
- package/dist/providers/anthropicBaseProvider.js +1 -1
- package/dist/providers/azureOpenai.js +1 -1
- package/dist/providers/googleAiStudio.js +1 -1
- package/dist/providers/googleVertex.js +1 -1
- package/dist/providers/huggingFace.js +1 -1
- package/dist/providers/litellm.js +1 -1
- package/dist/providers/mistral.js +1 -1
- package/dist/providers/openAI.js +1 -1
- package/dist/providers/openaiCompatible.js +1 -1
- package/dist/utils/conversationMemory.d.ts +1 -1
- package/dist/utils/conversationMemory.js +2 -2
- package/dist/utils/conversationMemoryUtils.d.ts +1 -1
- package/dist/utils/conversationMemoryUtils.js +2 -2
- package/package.json +1 -1
package/dist/lib/neurolink.js
CHANGED
|
@@ -18,7 +18,7 @@ import { mcpLogger } from "./utils/logger.js";
|
|
|
18
18
|
import { SYSTEM_LIMITS } from "./core/constants.js";
|
|
19
19
|
import { NANOSECOND_TO_MS_DIVISOR, TOOL_TIMEOUTS, RETRY_ATTEMPTS, RETRY_DELAYS, CIRCUIT_BREAKER, CIRCUIT_BREAKER_RESET_MS, MEMORY_THRESHOLDS, PROVIDER_TIMEOUTS, PERFORMANCE_THRESHOLDS, } from "./constants/index.js";
|
|
20
20
|
import pLimit from "p-limit";
|
|
21
|
-
import {
|
|
21
|
+
import { MCPToolRegistry } from "./mcp/toolRegistry.js";
|
|
22
22
|
import { logger } from "./utils/logger.js";
|
|
23
23
|
import { getBestProvider } from "./utils/providerUtils.js";
|
|
24
24
|
import { ProviderRegistry } from "./factories/providerRegistry.js";
|
|
@@ -45,6 +45,7 @@ import { isZodSchema } from "./utils/schemaConversion.js";
|
|
|
45
45
|
export class NeuroLink {
|
|
46
46
|
mcpInitialized = false;
|
|
47
47
|
emitter = new EventEmitter();
|
|
48
|
+
toolRegistry;
|
|
48
49
|
autoDiscoveredServerInfos = [];
|
|
49
50
|
// External MCP server management
|
|
50
51
|
externalServerManager;
|
|
@@ -140,6 +141,7 @@ export class NeuroLink {
|
|
|
140
141
|
* @param config.hitl.dangerousActions - Keywords that trigger confirmation (default: ['delete', 'remove', 'drop'])
|
|
141
142
|
* @param config.hitl.timeout - Confirmation timeout in milliseconds (default: 30000)
|
|
142
143
|
* @param config.hitl.allowArgumentModification - Allow users to modify tool parameters (default: true)
|
|
144
|
+
* @param config.toolRegistry - Optional tool registry instance for advanced use cases (default: new MCPToolRegistry())
|
|
143
145
|
*
|
|
144
146
|
* @example
|
|
145
147
|
* ```typescript
|
|
@@ -177,6 +179,7 @@ export class NeuroLink {
|
|
|
177
179
|
* @throws {Error} When HITL configuration is invalid (if enabled)
|
|
178
180
|
*/
|
|
179
181
|
constructor(config) {
|
|
182
|
+
this.toolRegistry = config?.toolRegistry || new MCPToolRegistry();
|
|
180
183
|
// Initialize orchestration setting
|
|
181
184
|
this.enableOrchestration = config?.enableOrchestration ?? false;
|
|
182
185
|
// Read tool cache duration from environment variables, with a default
|
|
@@ -278,7 +281,7 @@ export class NeuroLink {
|
|
|
278
281
|
// Initialize HITL manager
|
|
279
282
|
this.hitlManager = new HITLManager(config.hitl);
|
|
280
283
|
// Inject HITL manager into tool registry
|
|
281
|
-
toolRegistry.setHITLManager(this.hitlManager);
|
|
284
|
+
this.toolRegistry.setHITLManager(this.hitlManager);
|
|
282
285
|
// Inject HITL manager into external server manager
|
|
283
286
|
this.externalServerManager.setHITLManager(this.hitlManager);
|
|
284
287
|
// Set up HITL event forwarding to main emitter
|
|
@@ -627,7 +630,7 @@ export class NeuroLink {
|
|
|
627
630
|
mcpLogger.debug("Direct tools server are disabled via environment variable.");
|
|
628
631
|
}
|
|
629
632
|
else {
|
|
630
|
-
await toolRegistry.registerServer("neurolink-direct", directToolsServer);
|
|
633
|
+
await this.toolRegistry.registerServer("neurolink-direct", directToolsServer);
|
|
631
634
|
mcpLogger.debug("[NeuroLink] Direct tools server registered successfully", {
|
|
632
635
|
serverId: "neurolink-direct",
|
|
633
636
|
});
|
|
@@ -1225,13 +1228,13 @@ export class NeuroLink {
|
|
|
1225
1228
|
await this.initializeConversationMemoryForGeneration(generateInternalId, generateInternalStartTime, generateInternalHrTimeStart);
|
|
1226
1229
|
const mcpResult = await this.attemptMCPGeneration(options, generateInternalId, generateInternalStartTime, generateInternalHrTimeStart, functionTag);
|
|
1227
1230
|
if (mcpResult) {
|
|
1228
|
-
await storeConversationTurn(this.conversationMemory, options, mcpResult);
|
|
1231
|
+
await storeConversationTurn(this.conversationMemory, options, mcpResult, new Date(generateInternalStartTime));
|
|
1229
1232
|
this.emitter.emit("response:end", mcpResult.content || "");
|
|
1230
1233
|
return mcpResult;
|
|
1231
1234
|
}
|
|
1232
1235
|
const directResult = await this.directProviderGeneration(options);
|
|
1233
1236
|
logger.debug(`[${functionTag}] Direct generation successful`);
|
|
1234
|
-
await storeConversationTurn(this.conversationMemory, options, directResult);
|
|
1237
|
+
await storeConversationTurn(this.conversationMemory, options, directResult, new Date(generateInternalStartTime));
|
|
1235
1238
|
this.emitter.emit("response:end", directResult.content || "");
|
|
1236
1239
|
this.emitter.emit("message", `Text generation completed successfully`);
|
|
1237
1240
|
return directResult;
|
|
@@ -1371,7 +1374,7 @@ export class NeuroLink {
|
|
|
1371
1374
|
mcpInitialized: this.mcpInitialized,
|
|
1372
1375
|
mcpComponents: {
|
|
1373
1376
|
hasExternalServerManager: !!this.externalServerManager,
|
|
1374
|
-
hasToolRegistry: !!toolRegistry,
|
|
1377
|
+
hasToolRegistry: !!this.toolRegistry,
|
|
1375
1378
|
hasProviderRegistry: !!AIProviderFactory,
|
|
1376
1379
|
},
|
|
1377
1380
|
fallbackReason: "MCP_NOT_INITIALIZED",
|
|
@@ -1800,7 +1803,7 @@ export class NeuroLink {
|
|
|
1800
1803
|
try {
|
|
1801
1804
|
await self.conversationMemory.storeConversationTurn(enhancedOptions.context
|
|
1802
1805
|
?.sessionId, enhancedOptions.context
|
|
1803
|
-
?.userId, originalPrompt ?? "", accumulatedContent);
|
|
1806
|
+
?.userId, originalPrompt ?? "", accumulatedContent, new Date(startTime));
|
|
1804
1807
|
logger.debug("Stream conversation turn stored", {
|
|
1805
1808
|
sessionId: enhancedOptions.context
|
|
1806
1809
|
?.sessionId,
|
|
@@ -2005,7 +2008,7 @@ export class NeuroLink {
|
|
|
2005
2008
|
const sessionId = enhancedOptions?.context?.sessionId;
|
|
2006
2009
|
const userId = enhancedOptions?.context
|
|
2007
2010
|
?.userId;
|
|
2008
|
-
await self.conversationMemory.storeConversationTurn(sessionId || options.context?.sessionId, userId || options.context?.userId, originalPrompt ?? "", fallbackAccumulatedContent);
|
|
2011
|
+
await self.conversationMemory.storeConversationTurn(sessionId || options.context?.sessionId, userId || options.context?.userId, originalPrompt ?? "", fallbackAccumulatedContent, new Date(startTime));
|
|
2009
2012
|
logger.debug("Fallback stream conversation turn stored", {
|
|
2010
2013
|
sessionId: sessionId || options.context?.sessionId,
|
|
2011
2014
|
userInputLength: originalPrompt?.length ?? 0,
|
|
@@ -2403,7 +2406,7 @@ export class NeuroLink {
|
|
|
2403
2406
|
// SMART DEFAULTS: Use utility to eliminate boilerplate creation
|
|
2404
2407
|
const mcpServerInfo = createCustomToolServerInfo(name, convertedTool);
|
|
2405
2408
|
// Register with toolRegistry using MCPServerInfo directly
|
|
2406
|
-
toolRegistry.registerServer(mcpServerInfo);
|
|
2409
|
+
this.toolRegistry.registerServer(mcpServerInfo);
|
|
2407
2410
|
// Emit tool registration success event
|
|
2408
2411
|
this.emitter.emit("tools-register:end", {
|
|
2409
2412
|
toolName: name,
|
|
@@ -2475,7 +2478,7 @@ export class NeuroLink {
|
|
|
2475
2478
|
unregisterTool(name) {
|
|
2476
2479
|
this.invalidateToolCache(); // Invalidate cache when a tool is unregistered
|
|
2477
2480
|
const serverId = `custom-tool-${name}`;
|
|
2478
|
-
const removed = toolRegistry.unregisterServer(serverId);
|
|
2481
|
+
const removed = this.toolRegistry.unregisterServer(serverId);
|
|
2479
2482
|
if (removed) {
|
|
2480
2483
|
logger.info(`Unregistered custom tool: ${name}`);
|
|
2481
2484
|
}
|
|
@@ -2487,7 +2490,7 @@ export class NeuroLink {
|
|
|
2487
2490
|
*/
|
|
2488
2491
|
getCustomTools() {
|
|
2489
2492
|
// Get tools from toolRegistry with smart category detection
|
|
2490
|
-
const customTools = toolRegistry.getToolsByCategory(detectCategory({ isCustomTool: true }));
|
|
2493
|
+
const customTools = this.toolRegistry.getToolsByCategory(detectCategory({ isCustomTool: true }));
|
|
2491
2494
|
const toolMap = new Map();
|
|
2492
2495
|
for (const tool of customTools) {
|
|
2493
2496
|
const effectiveSchema = tool.inputSchema || tool.parameters;
|
|
@@ -2545,7 +2548,7 @@ export class NeuroLink {
|
|
|
2545
2548
|
hasShopId: !!executionContext.shopId,
|
|
2546
2549
|
sessionId: executionContext.sessionId,
|
|
2547
2550
|
});
|
|
2548
|
-
return await toolRegistry.executeTool(tool.name, params, executionContext);
|
|
2551
|
+
return await this.toolRegistry.executeTool(tool.name, params, executionContext);
|
|
2549
2552
|
},
|
|
2550
2553
|
});
|
|
2551
2554
|
}
|
|
@@ -2566,7 +2569,7 @@ export class NeuroLink {
|
|
|
2566
2569
|
serverInfo.tools = [];
|
|
2567
2570
|
}
|
|
2568
2571
|
// ZERO CONVERSIONS: Pass MCPServerInfo directly to toolRegistry
|
|
2569
|
-
await toolRegistry.registerServer(serverInfo);
|
|
2572
|
+
await this.toolRegistry.registerServer(serverInfo);
|
|
2570
2573
|
mcpLogger.info(`[NeuroLink] Successfully registered in-memory server: ${serverId}`, {
|
|
2571
2574
|
category: serverInfo.metadata?.category,
|
|
2572
2575
|
provider: serverInfo.metadata?.provider,
|
|
@@ -2584,7 +2587,7 @@ export class NeuroLink {
|
|
|
2584
2587
|
*/
|
|
2585
2588
|
getInMemoryServers() {
|
|
2586
2589
|
// Get in-memory servers from toolRegistry
|
|
2587
|
-
const serverInfos = toolRegistry.getBuiltInServerInfos();
|
|
2590
|
+
const serverInfos = this.toolRegistry.getBuiltInServerInfos();
|
|
2588
2591
|
const serverMap = new Map();
|
|
2589
2592
|
for (const serverInfo of serverInfos) {
|
|
2590
2593
|
if (detectCategory({
|
|
@@ -2603,7 +2606,7 @@ export class NeuroLink {
|
|
|
2603
2606
|
*/
|
|
2604
2607
|
getInMemoryServerInfos() {
|
|
2605
2608
|
// Get in-memory servers from centralized tool registry
|
|
2606
|
-
const allServers = toolRegistry.getBuiltInServerInfos();
|
|
2609
|
+
const allServers = this.toolRegistry.getBuiltInServerInfos();
|
|
2607
2610
|
return allServers.filter((server) => detectCategory({
|
|
2608
2611
|
existingCategory: server.metadata?.category,
|
|
2609
2612
|
serverId: server.id,
|
|
@@ -2855,7 +2858,7 @@ export class NeuroLink {
|
|
|
2855
2858
|
storedContextKeys: Object.keys(storedContext),
|
|
2856
2859
|
finalContextKeys: Object.keys(context),
|
|
2857
2860
|
});
|
|
2858
|
-
const result = (await toolRegistry.executeTool(toolName, params, context));
|
|
2861
|
+
const result = (await this.toolRegistry.executeTool(toolName, params, context));
|
|
2859
2862
|
// ADD: Check if result indicates a failure and emit error event
|
|
2860
2863
|
if (result &&
|
|
2861
2864
|
typeof result === "object" &&
|
|
@@ -2905,9 +2908,9 @@ export class NeuroLink {
|
|
|
2905
2908
|
getAllToolsHrTimeStart: getAllToolsHrTimeStart.toString(),
|
|
2906
2909
|
// 🔧 Tool registry state
|
|
2907
2910
|
toolRegistryState: {
|
|
2908
|
-
hasToolRegistry: !!toolRegistry,
|
|
2911
|
+
hasToolRegistry: !!this.toolRegistry,
|
|
2909
2912
|
toolRegistrySize: 0, // Not accessible as size property
|
|
2910
|
-
toolRegistryType: toolRegistry?.constructor?.name || "NOT_SET",
|
|
2913
|
+
toolRegistryType: this.toolRegistry?.constructor?.name || "NOT_SET",
|
|
2911
2914
|
hasExternalServerManager: !!this.externalServerManager,
|
|
2912
2915
|
externalServerManagerType: this.externalServerManager?.constructor?.name || "NOT_SET",
|
|
2913
2916
|
},
|
|
@@ -2926,7 +2929,7 @@ export class NeuroLink {
|
|
|
2926
2929
|
// Optimized: Collect all tools with minimal object creation
|
|
2927
2930
|
const allTools = new Map();
|
|
2928
2931
|
// 1. Add MCP server tools (built-in direct tools)
|
|
2929
|
-
const mcpToolsRaw = await toolRegistry.listTools();
|
|
2932
|
+
const mcpToolsRaw = await this.toolRegistry.listTools();
|
|
2930
2933
|
for (const tool of mcpToolsRaw) {
|
|
2931
2934
|
if (!allTools.has(tool.name)) {
|
|
2932
2935
|
const optimizedTool = optimizeToolForCollection(tool, {
|
|
@@ -2936,7 +2939,7 @@ export class NeuroLink {
|
|
|
2936
2939
|
}
|
|
2937
2940
|
}
|
|
2938
2941
|
// 2. Add custom tools from this NeuroLink instance
|
|
2939
|
-
const customToolsRaw = toolRegistry.getToolsByCategory(detectCategory({ isCustomTool: true }));
|
|
2942
|
+
const customToolsRaw = this.toolRegistry.getToolsByCategory(detectCategory({ isCustomTool: true }));
|
|
2940
2943
|
for (const tool of customToolsRaw) {
|
|
2941
2944
|
if (!allTools.has(tool.name)) {
|
|
2942
2945
|
const optimizedTool = optimizeToolForCollection(tool, {
|
|
@@ -2952,7 +2955,7 @@ export class NeuroLink {
|
|
|
2952
2955
|
}
|
|
2953
2956
|
}
|
|
2954
2957
|
// 3. Add tools from in-memory MCP servers
|
|
2955
|
-
const inMemoryToolsRaw = toolRegistry.getToolsByCategory("in-memory");
|
|
2958
|
+
const inMemoryToolsRaw = this.toolRegistry.getToolsByCategory("in-memory");
|
|
2956
2959
|
for (const tool of inMemoryToolsRaw) {
|
|
2957
2960
|
if (!allTools.has(tool.name)) {
|
|
2958
2961
|
const optimizedTool = optimizeToolForCollection(tool, {
|
|
@@ -3231,13 +3234,13 @@ export class NeuroLink {
|
|
|
3231
3234
|
// Initialize MCP if not already initialized (loads external servers from config)
|
|
3232
3235
|
await this.initializeMCP();
|
|
3233
3236
|
// Get built-in tools
|
|
3234
|
-
const allTools = await toolRegistry.listTools();
|
|
3237
|
+
const allTools = await this.toolRegistry.listTools();
|
|
3235
3238
|
// Get external MCP server statistics
|
|
3236
3239
|
const externalStats = this.externalServerManager.getStatistics();
|
|
3237
3240
|
// DIRECT RETURNS - ZERO conversion
|
|
3238
3241
|
const externalMCPServers = this.externalServerManager.listServers();
|
|
3239
3242
|
const inMemoryServerInfos = this.getInMemoryServerInfos();
|
|
3240
|
-
const builtInServerInfos = toolRegistry.getBuiltInServerInfos();
|
|
3243
|
+
const builtInServerInfos = this.toolRegistry.getBuiltInServerInfos();
|
|
3241
3244
|
const autoDiscoveredServerInfos = this.getAutoDiscoveredServerInfos();
|
|
3242
3245
|
// Calculate totals
|
|
3243
3246
|
const totalServers = externalMCPServers.length +
|
|
@@ -3255,7 +3258,7 @@ export class NeuroLink {
|
|
|
3255
3258
|
autoDiscoveredCount: autoDiscoveredServerInfos.length,
|
|
3256
3259
|
totalTools,
|
|
3257
3260
|
autoDiscoveredServers: autoDiscoveredServerInfos,
|
|
3258
|
-
customToolsCount: toolRegistry.getToolsByCategory(detectCategory({ isCustomTool: true })).length,
|
|
3261
|
+
customToolsCount: this.toolRegistry.getToolsByCategory(detectCategory({ isCustomTool: true })).length,
|
|
3259
3262
|
inMemoryServersCount: inMemoryServerInfos.length,
|
|
3260
3263
|
externalMCPServersCount: externalMCPServers.length,
|
|
3261
3264
|
externalMCPConnectedCount: externalStats.connectedServers,
|
|
@@ -3271,7 +3274,7 @@ export class NeuroLink {
|
|
|
3271
3274
|
autoDiscoveredCount: 0,
|
|
3272
3275
|
totalTools: 0,
|
|
3273
3276
|
autoDiscoveredServers: [],
|
|
3274
|
-
customToolsCount: toolRegistry.getToolsByCategory(detectCategory({ isCustomTool: true })).length,
|
|
3277
|
+
customToolsCount: this.toolRegistry.getToolsByCategory(detectCategory({ isCustomTool: true })).length,
|
|
3275
3278
|
inMemoryServersCount: 0,
|
|
3276
3279
|
externalMCPServersCount: 0,
|
|
3277
3280
|
externalMCPConnectedCount: 0,
|
|
@@ -3290,7 +3293,7 @@ export class NeuroLink {
|
|
|
3290
3293
|
return [
|
|
3291
3294
|
...this.externalServerManager.listServers(), // Direct return
|
|
3292
3295
|
...this.getInMemoryServerInfos(), // Direct return
|
|
3293
|
-
...toolRegistry.getBuiltInServerInfos(), // Direct return
|
|
3296
|
+
...this.toolRegistry.getBuiltInServerInfos(), // Direct return
|
|
3294
3297
|
...this.getAutoDiscoveredServerInfos(), // Direct return
|
|
3295
3298
|
];
|
|
3296
3299
|
}
|
|
@@ -3303,7 +3306,7 @@ export class NeuroLink {
|
|
|
3303
3306
|
try {
|
|
3304
3307
|
// Test built-in tools
|
|
3305
3308
|
if (serverId === "neurolink-direct") {
|
|
3306
|
-
const tools = await toolRegistry.listTools();
|
|
3309
|
+
const tools = await this.toolRegistry.listTools();
|
|
3307
3310
|
return tools.length > 0;
|
|
3308
3311
|
}
|
|
3309
3312
|
// Test in-memory servers
|
|
@@ -3480,7 +3483,7 @@ export class NeuroLink {
|
|
|
3480
3483
|
const tools = {};
|
|
3481
3484
|
let healthyCount = 0;
|
|
3482
3485
|
// Get all tool names from toolRegistry
|
|
3483
|
-
const allTools = await toolRegistry.listTools();
|
|
3486
|
+
const allTools = await this.toolRegistry.listTools();
|
|
3484
3487
|
const allToolNames = new Set(allTools.map((tool) => tool.name));
|
|
3485
3488
|
for (const toolName of allToolNames) {
|
|
3486
3489
|
const metrics = this.toolExecutionMetrics.get(toolName);
|
|
@@ -3630,9 +3633,10 @@ export class NeuroLink {
|
|
|
3630
3633
|
* @param userId - User identifier (optional)
|
|
3631
3634
|
* @param toolCalls - Array of tool calls
|
|
3632
3635
|
* @param toolResults - Array of tool results
|
|
3636
|
+
* @param currentTime - Date when the tool execution occurred (optional)
|
|
3633
3637
|
* @returns Promise resolving when storage is complete
|
|
3634
3638
|
*/
|
|
3635
|
-
async storeToolExecutions(sessionId, userId, toolCalls, toolResults) {
|
|
3639
|
+
async storeToolExecutions(sessionId, userId, toolCalls, toolResults, currentTime) {
|
|
3636
3640
|
// Check if tools are not empty
|
|
3637
3641
|
const hasToolData = (toolCalls && toolCalls.length > 0) ||
|
|
3638
3642
|
(toolResults && toolResults.length > 0);
|
|
@@ -3648,7 +3652,7 @@ export class NeuroLink {
|
|
|
3648
3652
|
const redisMemory = this
|
|
3649
3653
|
.conversationMemory;
|
|
3650
3654
|
try {
|
|
3651
|
-
await redisMemory.storeToolExecution(sessionId, userId, toolCalls, toolResults);
|
|
3655
|
+
await redisMemory.storeToolExecution(sessionId, userId, toolCalls, toolResults, currentTime);
|
|
3652
3656
|
}
|
|
3653
3657
|
catch (error) {
|
|
3654
3658
|
logger.warn("Failed to store tool executions", {
|
|
@@ -3908,7 +3912,7 @@ export class NeuroLink {
|
|
|
3908
3912
|
try {
|
|
3909
3913
|
const externalTools = this.externalServerManager.getServerTools(serverId);
|
|
3910
3914
|
for (const tool of externalTools) {
|
|
3911
|
-
toolRegistry.removeTool(tool.name);
|
|
3915
|
+
this.toolRegistry.removeTool(tool.name);
|
|
3912
3916
|
mcpLogger.debug(`[NeuroLink] Unregistered external MCP tool from main registry: ${tool.name}`);
|
|
3913
3917
|
}
|
|
3914
3918
|
}
|
|
@@ -3921,7 +3925,7 @@ export class NeuroLink {
|
|
|
3921
3925
|
*/
|
|
3922
3926
|
unregisterExternalMCPToolFromRegistry(toolName) {
|
|
3923
3927
|
try {
|
|
3924
|
-
toolRegistry.removeTool(toolName);
|
|
3928
|
+
this.toolRegistry.removeTool(toolName);
|
|
3925
3929
|
mcpLogger.debug(`[NeuroLink] Unregistered external MCP tool from main registry: ${toolName}`);
|
|
3926
3930
|
}
|
|
3927
3931
|
catch (error) {
|
|
@@ -3979,7 +3983,7 @@ export class NeuroLink {
|
|
|
3979
3983
|
try {
|
|
3980
3984
|
const externalTools = this.externalServerManager.getAllTools();
|
|
3981
3985
|
for (const tool of externalTools) {
|
|
3982
|
-
toolRegistry.removeTool(tool.name);
|
|
3986
|
+
this.toolRegistry.removeTool(tool.name);
|
|
3983
3987
|
}
|
|
3984
3988
|
mcpLogger.debug(`[NeuroLink] Unregistered ${externalTools.length} external MCP tools from main registry`);
|
|
3985
3989
|
}
|
|
@@ -105,7 +105,7 @@ export class AnthropicProvider extends BaseProvider {
|
|
|
105
105
|
toolChoice: shouldUseTools ? "auto" : "none",
|
|
106
106
|
abortSignal: timeoutController?.controller.signal,
|
|
107
107
|
onStepFinish: ({ toolCalls, toolResults }) => {
|
|
108
|
-
this.handleToolExecutionStorage(toolCalls, toolResults, options).catch((error) => {
|
|
108
|
+
this.handleToolExecutionStorage(toolCalls, toolResults, options, new Date()).catch((error) => {
|
|
109
109
|
logger.warn("[AnthropicProvider] Failed to store tool executions", {
|
|
110
110
|
provider: this.providerName,
|
|
111
111
|
error: error instanceof Error ? error.message : String(error),
|
|
@@ -72,7 +72,7 @@ export class AnthropicProviderV2 extends BaseProvider {
|
|
|
72
72
|
toolChoice: "auto",
|
|
73
73
|
abortSignal: timeoutController?.controller.signal,
|
|
74
74
|
onStepFinish: ({ toolCalls, toolResults }) => {
|
|
75
|
-
this.handleToolExecutionStorage(toolCalls, toolResults, options).catch((error) => {
|
|
75
|
+
this.handleToolExecutionStorage(toolCalls, toolResults, options, new Date()).catch((error) => {
|
|
76
76
|
logger.warn("[AnthropicBaseProvider] Failed to store tool executions", {
|
|
77
77
|
provider: this.providerName,
|
|
78
78
|
error: error instanceof Error ? error.message : String(error),
|
|
@@ -157,7 +157,7 @@ export class AzureOpenAIProvider extends BaseProvider {
|
|
|
157
157
|
tools,
|
|
158
158
|
toolChoice: shouldUseTools ? "auto" : "none",
|
|
159
159
|
onStepFinish: ({ toolCalls, toolResults }) => {
|
|
160
|
-
this.handleToolExecutionStorage(toolCalls, toolResults, options).catch((error) => {
|
|
160
|
+
this.handleToolExecutionStorage(toolCalls, toolResults, options, new Date()).catch((error) => {
|
|
161
161
|
logger.warn("[AzureOpenaiProvider] Failed to store tool executions", {
|
|
162
162
|
provider: this.providerName,
|
|
163
163
|
error: error instanceof Error ? error.message : String(error),
|
|
@@ -136,7 +136,7 @@ export class GoogleAIStudioProvider extends BaseProvider {
|
|
|
136
136
|
toolChoice: shouldUseTools ? "auto" : "none",
|
|
137
137
|
abortSignal: timeoutController?.controller.signal,
|
|
138
138
|
onStepFinish: ({ toolCalls, toolResults }) => {
|
|
139
|
-
this.handleToolExecutionStorage(toolCalls, toolResults, options).catch((error) => {
|
|
139
|
+
this.handleToolExecutionStorage(toolCalls, toolResults, options, new Date()).catch((error) => {
|
|
140
140
|
logger.warn("[GoogleAiStudioProvider] Failed to store tool executions", {
|
|
141
141
|
provider: this.providerName,
|
|
142
142
|
error: error instanceof Error ? error.message : String(error),
|
|
@@ -682,7 +682,7 @@ export class GoogleVertexProvider extends BaseProvider {
|
|
|
682
682
|
onStepFinish: ({ toolCalls, toolResults }) => {
|
|
683
683
|
logger.info("Tool execution completed", { toolResults, toolCalls });
|
|
684
684
|
// Handle tool execution storage
|
|
685
|
-
this.handleToolExecutionStorage(toolCalls, toolResults, options).catch((error) => {
|
|
685
|
+
this.handleToolExecutionStorage(toolCalls, toolResults, options, new Date()).catch((error) => {
|
|
686
686
|
logger.warn("[GoogleVertexProvider] Failed to store tool executions", {
|
|
687
687
|
provider: this.providerName,
|
|
688
688
|
error: error instanceof Error ? error.message : String(error),
|
|
@@ -124,7 +124,7 @@ export class HuggingFaceProvider extends BaseProvider {
|
|
|
124
124
|
toolChoice: streamOptions.toolChoice, // Tool choice handled by prepareStreamOptions
|
|
125
125
|
abortSignal: timeoutController?.controller.signal,
|
|
126
126
|
onStepFinish: ({ toolCalls, toolResults }) => {
|
|
127
|
-
this.handleToolExecutionStorage(toolCalls, toolResults, options).catch((error) => {
|
|
127
|
+
this.handleToolExecutionStorage(toolCalls, toolResults, options, new Date()).catch((error) => {
|
|
128
128
|
logger.warn("[HuggingFaceProvider] Failed to store tool executions", {
|
|
129
129
|
provider: this.providerName,
|
|
130
130
|
error: error instanceof Error ? error.message : String(error),
|
|
@@ -132,7 +132,7 @@ export class LiteLLMProvider extends BaseProvider {
|
|
|
132
132
|
toolChoice: "auto",
|
|
133
133
|
abortSignal: timeoutController?.controller.signal,
|
|
134
134
|
onStepFinish: ({ toolCalls, toolResults }) => {
|
|
135
|
-
this.handleToolExecutionStorage(toolCalls, toolResults, options).catch((error) => {
|
|
135
|
+
this.handleToolExecutionStorage(toolCalls, toolResults, options, new Date()).catch((error) => {
|
|
136
136
|
logger.warn("LiteLLMProvider] Failed to store tool executions", {
|
|
137
137
|
provider: this.providerName,
|
|
138
138
|
error: error instanceof Error ? error.message : String(error),
|
|
@@ -61,7 +61,7 @@ export class MistralProvider extends BaseProvider {
|
|
|
61
61
|
toolChoice: shouldUseTools ? "auto" : "none",
|
|
62
62
|
abortSignal: timeoutController?.controller.signal,
|
|
63
63
|
onStepFinish: ({ toolCalls, toolResults }) => {
|
|
64
|
-
this.handleToolExecutionStorage(toolCalls, toolResults, options).catch((error) => {
|
|
64
|
+
this.handleToolExecutionStorage(toolCalls, toolResults, options, new Date()).catch((error) => {
|
|
65
65
|
logger.warn("[MistralProvider] Failed to store tool executions", {
|
|
66
66
|
provider: this.providerName,
|
|
67
67
|
error: error instanceof Error ? error.message : String(error),
|
|
@@ -276,7 +276,7 @@ export class OpenAIProvider extends BaseProvider {
|
|
|
276
276
|
onStepFinish: ({ toolCalls, toolResults }) => {
|
|
277
277
|
logger.info("Tool execution completed", { toolResults, toolCalls });
|
|
278
278
|
// Handle tool execution storage
|
|
279
|
-
this.handleToolExecutionStorage(toolCalls, toolResults, options).catch((error) => {
|
|
279
|
+
this.handleToolExecutionStorage(toolCalls, toolResults, options, new Date()).catch((error) => {
|
|
280
280
|
logger.warn("[OpenAIProvider] Failed to store tool executions", {
|
|
281
281
|
provider: this.providerName,
|
|
282
282
|
error: error instanceof Error ? error.message : String(error),
|
|
@@ -168,7 +168,7 @@ export class OpenAICompatibleProvider extends BaseProvider {
|
|
|
168
168
|
toolChoice: "auto",
|
|
169
169
|
abortSignal: timeoutController?.controller.signal,
|
|
170
170
|
onStepFinish: ({ toolCalls, toolResults }) => {
|
|
171
|
-
this.handleToolExecutionStorage(toolCalls, toolResults, options).catch((error) => {
|
|
171
|
+
this.handleToolExecutionStorage(toolCalls, toolResults, options, new Date()).catch((error) => {
|
|
172
172
|
logger.warn("[OpenAiCompatibleProvider] Failed to store tool executions", {
|
|
173
173
|
provider: this.providerName,
|
|
174
174
|
error: error instanceof Error ? error.message : String(error),
|
|
@@ -19,4 +19,4 @@ export declare function getConversationMessages(conversationMemory: Conversation
|
|
|
19
19
|
* Store conversation turn for future context
|
|
20
20
|
* Saves user messages and AI responses for conversation memory
|
|
21
21
|
*/
|
|
22
|
-
export declare function storeConversationTurn(conversationMemory: ConversationMemoryManager | RedisConversationMemoryManager | null | undefined, originalOptions: TextGenerationOptions, result: TextGenerationResult): Promise<void>;
|
|
22
|
+
export declare function storeConversationTurn(conversationMemory: ConversationMemoryManager | RedisConversationMemoryManager | null | undefined, originalOptions: TextGenerationOptions, result: TextGenerationResult, startTimeStamp?: Date | undefined): Promise<void>;
|
|
@@ -71,7 +71,7 @@ export async function getConversationMessages(conversationMemory, options) {
|
|
|
71
71
|
* Store conversation turn for future context
|
|
72
72
|
* Saves user messages and AI responses for conversation memory
|
|
73
73
|
*/
|
|
74
|
-
export async function storeConversationTurn(conversationMemory, originalOptions, result) {
|
|
74
|
+
export async function storeConversationTurn(conversationMemory, originalOptions, result, startTimeStamp) {
|
|
75
75
|
logger.debug("[conversationMemoryUtils] storeConversationTurn called", {
|
|
76
76
|
hasMemory: !!conversationMemory,
|
|
77
77
|
memoryType: conversationMemory?.constructor?.name || "NONE",
|
|
@@ -102,7 +102,7 @@ export async function storeConversationTurn(conversationMemory, originalOptions,
|
|
|
102
102
|
const userMessage = originalOptions.originalPrompt || originalOptions.prompt || "";
|
|
103
103
|
const aiResponse = result.content;
|
|
104
104
|
try {
|
|
105
|
-
await conversationMemory.storeConversationTurn(sessionId, userId, userMessage, aiResponse);
|
|
105
|
+
await conversationMemory.storeConversationTurn(sessionId, userId, userMessage, aiResponse, startTimeStamp);
|
|
106
106
|
logger.debug("[conversationMemoryUtils] Conversation turn stored successfully", {
|
|
107
107
|
sessionId,
|
|
108
108
|
userId,
|
|
@@ -18,7 +18,7 @@ export declare function getConversationMessages(conversationMemory: Conversation
|
|
|
18
18
|
* Store conversation turn for future context
|
|
19
19
|
* Saves user messages and AI responses for conversation memory
|
|
20
20
|
*/
|
|
21
|
-
export declare function storeConversationTurn(conversationMemory: ConversationMemoryManager | undefined, originalOptions: TextGenerationOptions, result: TextGenerationResult): Promise<void>;
|
|
21
|
+
export declare function storeConversationTurn(conversationMemory: ConversationMemoryManager | undefined, originalOptions: TextGenerationOptions, result: TextGenerationResult, startTimeStamp?: Date | undefined): Promise<void>;
|
|
22
22
|
/**
|
|
23
23
|
* Check if Redis is available for conversation memory
|
|
24
24
|
*/
|
|
@@ -48,7 +48,7 @@ export async function getConversationMessages(conversationMemory, options) {
|
|
|
48
48
|
* Store conversation turn for future context
|
|
49
49
|
* Saves user messages and AI responses for conversation memory
|
|
50
50
|
*/
|
|
51
|
-
export async function storeConversationTurn(conversationMemory, originalOptions, result) {
|
|
51
|
+
export async function storeConversationTurn(conversationMemory, originalOptions, result, startTimeStamp) {
|
|
52
52
|
if (!conversationMemory || !originalOptions.context) {
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
@@ -59,7 +59,7 @@ export async function storeConversationTurn(conversationMemory, originalOptions,
|
|
|
59
59
|
return;
|
|
60
60
|
}
|
|
61
61
|
try {
|
|
62
|
-
await conversationMemory.storeConversationTurn(sessionId, userId, originalOptions.originalPrompt || originalOptions.prompt || "", result.content);
|
|
62
|
+
await conversationMemory.storeConversationTurn(sessionId, userId, originalOptions.originalPrompt || originalOptions.prompt || "", result.content, startTimeStamp);
|
|
63
63
|
logger.debug("Conversation turn stored", {
|
|
64
64
|
sessionId,
|
|
65
65
|
userId,
|
package/dist/neurolink.d.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* Uses real MCP infrastructure for tool discovery and execution.
|
|
7
7
|
*/
|
|
8
8
|
import type { TextGenerationOptions, TextGenerationResult } from "./types/index.js";
|
|
9
|
+
import { MCPToolRegistry } from "./mcp/toolRegistry.js";
|
|
9
10
|
import type { GenerateOptions, GenerateResult } from "./types/generateTypes.js";
|
|
10
11
|
import type { StreamOptions, StreamResult } from "./types/streamTypes.js";
|
|
11
12
|
import type { MCPServerInfo, MCPExecutableTool } from "./types/mcpTypes.js";
|
|
@@ -46,6 +47,7 @@ export interface MCPStatus {
|
|
|
46
47
|
export declare class NeuroLink {
|
|
47
48
|
private mcpInitialized;
|
|
48
49
|
private emitter;
|
|
50
|
+
private toolRegistry;
|
|
49
51
|
private autoDiscoveredServerInfos;
|
|
50
52
|
private externalServerManager;
|
|
51
53
|
private toolCache;
|
|
@@ -99,6 +101,7 @@ export declare class NeuroLink {
|
|
|
99
101
|
* @param config.hitl.dangerousActions - Keywords that trigger confirmation (default: ['delete', 'remove', 'drop'])
|
|
100
102
|
* @param config.hitl.timeout - Confirmation timeout in milliseconds (default: 30000)
|
|
101
103
|
* @param config.hitl.allowArgumentModification - Allow users to modify tool parameters (default: true)
|
|
104
|
+
* @param config.toolRegistry - Optional tool registry instance for advanced use cases (default: new MCPToolRegistry())
|
|
102
105
|
*
|
|
103
106
|
* @example
|
|
104
107
|
* ```typescript
|
|
@@ -139,6 +142,7 @@ export declare class NeuroLink {
|
|
|
139
142
|
conversationMemory?: Partial<ConversationMemoryConfig>;
|
|
140
143
|
enableOrchestration?: boolean;
|
|
141
144
|
hitl?: HITLConfig;
|
|
145
|
+
toolRegistry?: MCPToolRegistry;
|
|
142
146
|
});
|
|
143
147
|
/**
|
|
144
148
|
* Initialize provider registry with security settings
|
|
@@ -919,6 +923,7 @@ export declare class NeuroLink {
|
|
|
919
923
|
* @param userId - User identifier (optional)
|
|
920
924
|
* @param toolCalls - Array of tool calls
|
|
921
925
|
* @param toolResults - Array of tool results
|
|
926
|
+
* @param currentTime - Date when the tool execution occurred (optional)
|
|
922
927
|
* @returns Promise resolving when storage is complete
|
|
923
928
|
*/
|
|
924
929
|
storeToolExecutions(sessionId: string, userId: string | undefined, toolCalls: Array<{
|
|
@@ -931,7 +936,7 @@ export declare class NeuroLink {
|
|
|
931
936
|
result?: unknown;
|
|
932
937
|
error?: string;
|
|
933
938
|
[key: string]: unknown;
|
|
934
|
-
}
|
|
939
|
+
}>, currentTime?: Date): Promise<void>;
|
|
935
940
|
/**
|
|
936
941
|
* Check if tool execution storage is available
|
|
937
942
|
* @returns boolean indicating if Redis storage is configured and available
|