@juspay/neurolink 7.37.0 → 7.38.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 +12 -0
- package/dist/cli/commands/config.d.ts +18 -18
- package/dist/cli/factories/commandFactory.d.ts +24 -0
- package/dist/cli/factories/commandFactory.js +297 -245
- package/dist/core/baseProvider.d.ts +44 -3
- package/dist/core/baseProvider.js +729 -352
- package/dist/core/constants.d.ts +2 -30
- package/dist/core/constants.js +15 -43
- package/dist/core/redisConversationMemoryManager.d.ts +98 -15
- package/dist/core/redisConversationMemoryManager.js +665 -203
- package/dist/factories/providerFactory.js +23 -6
- package/dist/index.d.ts +3 -2
- package/dist/index.js +4 -3
- package/dist/lib/core/baseProvider.d.ts +44 -3
- package/dist/lib/core/baseProvider.js +729 -352
- package/dist/lib/core/constants.d.ts +2 -30
- package/dist/lib/core/constants.js +15 -43
- package/dist/lib/core/redisConversationMemoryManager.d.ts +98 -15
- package/dist/lib/core/redisConversationMemoryManager.js +665 -203
- package/dist/lib/factories/providerFactory.js +23 -6
- package/dist/lib/index.d.ts +3 -2
- package/dist/lib/index.js +4 -3
- package/dist/lib/mcp/externalServerManager.js +2 -2
- package/dist/lib/mcp/registry.js +2 -2
- package/dist/lib/mcp/servers/agent/directToolsServer.js +19 -10
- package/dist/lib/mcp/toolRegistry.js +4 -8
- package/dist/lib/neurolink.d.ts +95 -28
- package/dist/lib/neurolink.js +479 -719
- package/dist/lib/providers/amazonBedrock.js +2 -2
- package/dist/lib/providers/anthropic.js +8 -0
- package/dist/lib/providers/anthropicBaseProvider.js +8 -0
- package/dist/lib/providers/azureOpenai.js +8 -0
- package/dist/lib/providers/googleAiStudio.js +8 -0
- package/dist/lib/providers/googleVertex.d.ts +3 -23
- package/dist/lib/providers/googleVertex.js +24 -342
- package/dist/lib/providers/huggingFace.js +8 -0
- package/dist/lib/providers/litellm.js +8 -0
- package/dist/lib/providers/mistral.js +8 -0
- package/dist/lib/providers/openAI.d.ts +23 -0
- package/dist/lib/providers/openAI.js +323 -6
- package/dist/lib/providers/openaiCompatible.js +8 -0
- package/dist/lib/providers/sagemaker/language-model.d.ts +2 -2
- package/dist/lib/sdk/toolRegistration.js +18 -1
- package/dist/lib/types/common.d.ts +98 -0
- package/dist/lib/types/conversation.d.ts +52 -2
- package/dist/lib/types/streamTypes.d.ts +13 -6
- package/dist/lib/types/typeAliases.d.ts +3 -2
- package/dist/lib/utils/conversationMemory.js +3 -1
- package/dist/lib/utils/messageBuilder.d.ts +10 -2
- package/dist/lib/utils/messageBuilder.js +22 -1
- package/dist/lib/utils/parameterValidation.js +6 -25
- package/dist/lib/utils/promptRedaction.js +4 -4
- package/dist/lib/utils/redis.d.ts +10 -6
- package/dist/lib/utils/redis.js +71 -70
- package/dist/lib/utils/schemaConversion.d.ts +14 -0
- package/dist/lib/utils/schemaConversion.js +140 -0
- package/dist/lib/utils/transformationUtils.js +143 -5
- package/dist/mcp/externalServerManager.js +2 -2
- package/dist/mcp/registry.js +2 -2
- package/dist/mcp/servers/agent/directToolsServer.js +19 -10
- package/dist/mcp/toolRegistry.js +4 -8
- package/dist/neurolink.d.ts +95 -28
- package/dist/neurolink.js +479 -719
- package/dist/providers/amazonBedrock.js +2 -2
- package/dist/providers/anthropic.js +8 -0
- package/dist/providers/anthropicBaseProvider.js +8 -0
- package/dist/providers/azureOpenai.js +8 -0
- package/dist/providers/googleAiStudio.js +8 -0
- package/dist/providers/googleVertex.d.ts +3 -23
- package/dist/providers/googleVertex.js +24 -342
- package/dist/providers/huggingFace.js +8 -0
- package/dist/providers/litellm.js +8 -0
- package/dist/providers/mistral.js +8 -0
- package/dist/providers/openAI.d.ts +23 -0
- package/dist/providers/openAI.js +323 -6
- package/dist/providers/openaiCompatible.js +8 -0
- package/dist/providers/sagemaker/language-model.d.ts +2 -2
- package/dist/sdk/toolRegistration.js +18 -1
- package/dist/types/common.d.ts +98 -0
- package/dist/types/conversation.d.ts +52 -2
- package/dist/types/streamTypes.d.ts +13 -6
- package/dist/types/typeAliases.d.ts +3 -2
- package/dist/utils/conversationMemory.js +3 -1
- package/dist/utils/messageBuilder.d.ts +10 -2
- package/dist/utils/messageBuilder.js +22 -1
- package/dist/utils/parameterValidation.js +6 -25
- package/dist/utils/promptRedaction.js +4 -4
- package/dist/utils/redis.d.ts +10 -6
- package/dist/utils/redis.js +71 -70
- package/dist/utils/schemaConversion.d.ts +14 -0
- package/dist/utils/schemaConversion.js +140 -0
- package/dist/utils/transformationUtils.js +143 -5
- package/package.json +3 -2
@@ -2,6 +2,7 @@
|
|
2
2
|
* Object Transformation Utilities
|
3
3
|
* Centralizes repeated object transformation patterns to improve code reuse and maintainability
|
4
4
|
*/
|
5
|
+
import { logger } from "./logger.js";
|
5
6
|
// ============================================================================
|
6
7
|
// TOOL EXECUTION TRANSFORMATIONS
|
7
8
|
// ============================================================================
|
@@ -43,22 +44,109 @@ export function transformToolExecutions(toolExecutions) {
|
|
43
44
|
if (!toolName) {
|
44
45
|
toolName = `tool_execution_${index}`;
|
45
46
|
}
|
47
|
+
// Enhanced tool parameter extraction with structured logging
|
48
|
+
const parameterExtractionData = {
|
49
|
+
executionIndex: index,
|
50
|
+
toolNameExtracted: toolName,
|
51
|
+
primarySources: {
|
52
|
+
hasInput: !!teRecord.input,
|
53
|
+
hasParameters: !!teRecord.parameters,
|
54
|
+
hasArgs: !!teRecord.args,
|
55
|
+
inputType: typeof teRecord.input,
|
56
|
+
parametersType: typeof teRecord.parameters,
|
57
|
+
argsType: typeof teRecord.args,
|
58
|
+
},
|
59
|
+
rawRecordKeys: Object.keys(teRecord),
|
60
|
+
};
|
61
|
+
logger.debug("[TransformationUtils] Tool parameter extraction analysis", parameterExtractionData);
|
46
62
|
// Enhanced input extraction
|
47
63
|
let input = teRecord.input ||
|
48
64
|
teRecord.parameters ||
|
49
65
|
teRecord.args ||
|
50
66
|
{};
|
67
|
+
const primaryExtractionResult = {
|
68
|
+
keysCount: Object.keys(input).length,
|
69
|
+
keys: Object.keys(input),
|
70
|
+
extractionSuccessful: Object.keys(input).length > 0,
|
71
|
+
extractionSource: teRecord.input
|
72
|
+
? "input"
|
73
|
+
: teRecord.parameters
|
74
|
+
? "parameters"
|
75
|
+
: teRecord.args
|
76
|
+
? "args"
|
77
|
+
: "empty",
|
78
|
+
};
|
79
|
+
logger.debug("[TransformationUtils] Primary parameter extraction result", primaryExtractionResult);
|
51
80
|
// Extract input from nested toolCall if available
|
52
81
|
if (Object.keys(input).length === 0 &&
|
53
82
|
teRecord.toolCall &&
|
54
83
|
typeof teRecord.toolCall === "object") {
|
55
84
|
const toolCall = teRecord.toolCall;
|
85
|
+
const nestedExtractionData = {
|
86
|
+
reason: "Primary extraction failed, checking nested toolCall",
|
87
|
+
nestedSources: {
|
88
|
+
hasInput: !!toolCall.input,
|
89
|
+
hasParameters: !!toolCall.parameters,
|
90
|
+
hasArgs: !!toolCall.args,
|
91
|
+
},
|
92
|
+
toolCallKeys: Object.keys(toolCall),
|
93
|
+
};
|
94
|
+
logger.debug("[TransformationUtils] Nested parameter extraction attempt", nestedExtractionData);
|
56
95
|
input =
|
57
96
|
toolCall.input ||
|
58
97
|
toolCall.parameters ||
|
59
98
|
toolCall.args ||
|
60
99
|
{};
|
100
|
+
const nestedExtractionResult = {
|
101
|
+
keysCount: Object.keys(input).length,
|
102
|
+
keys: Object.keys(input),
|
103
|
+
extractionSuccessful: Object.keys(input).length > 0,
|
104
|
+
extractionSource: toolCall.input
|
105
|
+
? "toolCall.input"
|
106
|
+
: toolCall.parameters
|
107
|
+
? "toolCall.parameters"
|
108
|
+
: toolCall.args
|
109
|
+
? "toolCall.args"
|
110
|
+
: "empty",
|
111
|
+
};
|
112
|
+
logger.debug("[TransformationUtils] Nested parameter extraction result", nestedExtractionResult);
|
113
|
+
}
|
114
|
+
// Target tool parameter analysis for critical tools
|
115
|
+
if (toolName &&
|
116
|
+
(toolName.includes("SuccessRateSRByTime") ||
|
117
|
+
toolName.includes("juspay-analytics"))) {
|
118
|
+
const targetToolAnalysis = {
|
119
|
+
toolName,
|
120
|
+
inputKeys: Object.keys(input),
|
121
|
+
keysCount: Object.keys(input).length,
|
122
|
+
hasStartTime: "startTime" in input,
|
123
|
+
hasEndTime: "endTime" in input,
|
124
|
+
startTimeValue: input.startTime || "MISSING",
|
125
|
+
endTimeValue: input.endTime || "MISSING",
|
126
|
+
extractionStatus: Object.keys(input).length === 0 ? "FAILED" : "SUCCESS",
|
127
|
+
};
|
128
|
+
logger.debug("[TransformationUtils] Target tool parameter analysis", targetToolAnalysis);
|
129
|
+
if (Object.keys(input).length === 0) {
|
130
|
+
logger.error("[TransformationUtils] Critical: Target tool parameter extraction failed", {
|
131
|
+
toolName,
|
132
|
+
reason: "Both primary and nested extraction returned empty parameters",
|
133
|
+
impact: "AI response did not contain expected parameter structure",
|
134
|
+
});
|
135
|
+
}
|
61
136
|
}
|
137
|
+
// Final parameter extraction summary
|
138
|
+
const finalExtractionSummary = {
|
139
|
+
toolName,
|
140
|
+
inputKeysCount: Object.keys(input).length,
|
141
|
+
inputKeys: Object.keys(input),
|
142
|
+
hasParameters: Object.keys(input).length > 0,
|
143
|
+
duration: teRecord.duration ??
|
144
|
+
teRecord.executionTime ??
|
145
|
+
teRecord.responseTime ??
|
146
|
+
0,
|
147
|
+
hasOutput: !!(teRecord.output || teRecord.result || teRecord.response),
|
148
|
+
};
|
149
|
+
logger.debug("[TransformationUtils] Final parameter extraction result", finalExtractionSummary);
|
62
150
|
// Enhanced output extraction with success indication
|
63
151
|
const output = teRecord.output ||
|
64
152
|
teRecord.result ||
|
@@ -169,14 +257,61 @@ export function transformAvailableTools(availableTools) {
|
|
169
257
|
}
|
170
258
|
return availableTools.map((tool) => {
|
171
259
|
const toolRecord = tool;
|
260
|
+
let extractedParameters = {};
|
261
|
+
const inputSchema = toolRecord.inputSchema;
|
262
|
+
const directParameters = toolRecord.parameters;
|
263
|
+
const fallbackSchema = toolRecord.schema;
|
264
|
+
if (inputSchema && typeof inputSchema === "object") {
|
265
|
+
if (inputSchema.$ref && inputSchema.definitions) {
|
266
|
+
const definitions = inputSchema.definitions;
|
267
|
+
const refValue = inputSchema.$ref;
|
268
|
+
if (typeof refValue === "string") {
|
269
|
+
const refKey = refValue.replace("#/definitions/", "");
|
270
|
+
if (definitions[refKey] && typeof definitions[refKey] === "object") {
|
271
|
+
const resolvedSchema = definitions[refKey];
|
272
|
+
extractedParameters = {
|
273
|
+
type: resolvedSchema.type || "object",
|
274
|
+
properties: resolvedSchema.properties || {},
|
275
|
+
required: resolvedSchema.required || [],
|
276
|
+
...resolvedSchema, // Include all schema metadata
|
277
|
+
};
|
278
|
+
}
|
279
|
+
}
|
280
|
+
}
|
281
|
+
else if (inputSchema.properties) {
|
282
|
+
extractedParameters = {
|
283
|
+
type: inputSchema.type || "object",
|
284
|
+
properties: inputSchema.properties,
|
285
|
+
required: inputSchema.required || [],
|
286
|
+
...inputSchema,
|
287
|
+
};
|
288
|
+
}
|
289
|
+
else if (inputSchema.type === "object") {
|
290
|
+
extractedParameters = inputSchema;
|
291
|
+
}
|
292
|
+
else {
|
293
|
+
extractedParameters = inputSchema;
|
294
|
+
}
|
295
|
+
}
|
296
|
+
else if (directParameters && typeof directParameters === "object") {
|
297
|
+
extractedParameters = directParameters;
|
298
|
+
}
|
299
|
+
else if (fallbackSchema && typeof fallbackSchema === "object") {
|
300
|
+
extractedParameters = fallbackSchema;
|
301
|
+
}
|
302
|
+
if (!extractedParameters || typeof extractedParameters !== "object") {
|
303
|
+
extractedParameters = {};
|
304
|
+
}
|
305
|
+
if (extractedParameters &&
|
306
|
+
!extractedParameters.type &&
|
307
|
+
extractedParameters.properties) {
|
308
|
+
extractedParameters.type = "object";
|
309
|
+
}
|
172
310
|
return {
|
173
311
|
name: tool.name || "",
|
174
312
|
description: tool.description || "",
|
175
313
|
server: tool.server || "",
|
176
|
-
parameters:
|
177
|
-
toolRecord.parameters ||
|
178
|
-
toolRecord.schema ||
|
179
|
-
{},
|
314
|
+
parameters: extractedParameters,
|
180
315
|
};
|
181
316
|
});
|
182
317
|
}
|
@@ -246,7 +381,10 @@ export function transformSchemaToParameterDescription(schema) {
|
|
246
381
|
.map(([key, value]) => {
|
247
382
|
const typedValue = value;
|
248
383
|
const required = requiredParams.has(key) ? " (required)" : "";
|
249
|
-
|
384
|
+
const description = typedValue.description
|
385
|
+
? ` - ${typedValue.description}`
|
386
|
+
: "";
|
387
|
+
return ` - ${key}: ${typedValue.type || "unknown"}${required}${description}`;
|
250
388
|
})
|
251
389
|
.join("\n");
|
252
390
|
}
|
@@ -89,9 +89,9 @@ export class ExternalServerManager extends EventEmitter {
|
|
89
89
|
enablePerformanceMonitoring: config.enablePerformanceMonitoring ?? true,
|
90
90
|
logLevel: config.logLevel ?? "info",
|
91
91
|
};
|
92
|
-
//
|
92
|
+
// Disable main tool registry integration by default to prevent automatic tool execution
|
93
93
|
this.enableMainRegistryIntegration =
|
94
|
-
options.enableMainRegistryIntegration ??
|
94
|
+
options.enableMainRegistryIntegration ?? false;
|
95
95
|
// Initialize tool discovery service
|
96
96
|
this.toolDiscovery = new ToolDiscoveryService();
|
97
97
|
// Forward tool discovery events
|
package/dist/mcp/registry.js
CHANGED
@@ -13,7 +13,7 @@ export class MCPRegistry {
|
|
13
13
|
*/
|
14
14
|
register(plugin) {
|
15
15
|
this.plugins.set(plugin.metadata.name, plugin);
|
16
|
-
registryLogger.
|
16
|
+
registryLogger.debug(`Registered plugin: ${plugin.metadata.name}`);
|
17
17
|
}
|
18
18
|
/**
|
19
19
|
* Unregister a plugin
|
@@ -21,7 +21,7 @@ export class MCPRegistry {
|
|
21
21
|
unregister(name) {
|
22
22
|
const removed = this.plugins.delete(name);
|
23
23
|
if (removed) {
|
24
|
-
registryLogger.
|
24
|
+
registryLogger.debug(`Unregistered plugin: ${name}`);
|
25
25
|
}
|
26
26
|
return removed;
|
27
27
|
}
|
@@ -46,8 +46,24 @@ if (!shouldDisableBuiltinTools()) {
|
|
46
46
|
execute: async (params, context) => {
|
47
47
|
const startTime = Date.now();
|
48
48
|
try {
|
49
|
-
|
50
|
-
|
49
|
+
if (Object.keys(params || {}).length === 0) {
|
50
|
+
return {
|
51
|
+
success: false,
|
52
|
+
data: null,
|
53
|
+
error: "Tool execution blocked: Empty parameters not allowed during startup",
|
54
|
+
usage: {
|
55
|
+
executionTime: Date.now() - startTime,
|
56
|
+
},
|
57
|
+
metadata: {
|
58
|
+
toolName,
|
59
|
+
serverId: "neurolink-direct",
|
60
|
+
sessionId: context.sessionId,
|
61
|
+
blocked: true,
|
62
|
+
reason: "empty_parameters_startup_prevention",
|
63
|
+
timestamp: Date.now(),
|
64
|
+
},
|
65
|
+
};
|
66
|
+
}
|
51
67
|
if (!execute || typeof execute !== "function") {
|
52
68
|
throw new Error(`Tool ${toolName} has no execute function`);
|
53
69
|
}
|
@@ -104,7 +120,7 @@ if (!shouldDisableBuiltinTools()) {
|
|
104
120
|
});
|
105
121
|
}
|
106
122
|
else {
|
107
|
-
logger.
|
123
|
+
logger.debug("Built-in tools disabled via configuration");
|
108
124
|
}
|
109
125
|
/**
|
110
126
|
* Get tool category based on tool name
|
@@ -126,10 +142,3 @@ function getToolCategory(toolName) {
|
|
126
142
|
return "utility";
|
127
143
|
}
|
128
144
|
}
|
129
|
-
// Log successful registration or disable status
|
130
|
-
if (!shouldDisableBuiltinTools()) {
|
131
|
-
logger.info(`[Direct Tools] Registered ${Object.keys(directAgentTools).length} direct tools`);
|
132
|
-
}
|
133
|
-
else {
|
134
|
-
logger.info("[Direct Tools] 0 direct tools registered (disabled via environment variable)");
|
135
|
-
}
|
package/dist/mcp/toolRegistry.js
CHANGED
@@ -16,13 +16,9 @@ export class MCPToolRegistry extends MCPRegistry {
|
|
16
16
|
builtInServerInfos = []; // DIRECT storage for MCPServerInfo
|
17
17
|
constructor() {
|
18
18
|
super();
|
19
|
-
// 🔧 CONDITIONAL: Only auto-register direct tools if not disabled via configuration
|
20
19
|
if (!shouldDisableBuiltinTools()) {
|
21
20
|
this.registerDirectTools();
|
22
21
|
}
|
23
|
-
else {
|
24
|
-
registryLogger.debug("Built-in direct tools disabled via configuration");
|
25
|
-
}
|
26
22
|
}
|
27
23
|
/**
|
28
24
|
* Register all direct tools from directAgentTools
|
@@ -100,7 +96,6 @@ export class MCPToolRegistry extends MCPRegistry {
|
|
100
96
|
_finalContext = serverConfigOrContext;
|
101
97
|
}
|
102
98
|
const serverId = serverInfo.id;
|
103
|
-
registryLogger.info(`Registering MCPServerInfo directly: ${serverId}`);
|
104
99
|
// Use MCPServerInfo.tools array directly - ZERO conversions!
|
105
100
|
const toolsObject = {};
|
106
101
|
for (const tool of serverInfo.tools) {
|
@@ -133,7 +128,6 @@ export class MCPToolRegistry extends MCPRegistry {
|
|
133
128
|
this.register(plugin);
|
134
129
|
// Use MCPServerInfo.tools array directly - ZERO conversions!
|
135
130
|
const tools = serverInfo.tools;
|
136
|
-
registryLogger.debug(`Registering ${tools.length} tools for server ${serverId}:`, tools.map((t) => t.name));
|
137
131
|
for (const tool of tools) {
|
138
132
|
// For custom tools, use just the tool name to avoid redundant serverId.toolName format
|
139
133
|
// For other tools, use fully-qualified serverId.toolName to avoid collisions
|
@@ -166,7 +160,7 @@ export class MCPToolRegistry extends MCPRegistry {
|
|
166
160
|
serverId: serverInfo.id,
|
167
161
|
}),
|
168
162
|
});
|
169
|
-
|
163
|
+
// Tool registered successfully
|
170
164
|
}
|
171
165
|
// Store MCPServerInfo directly - NO recreation needed!
|
172
166
|
if (tools.length > 0) {
|
@@ -211,9 +205,11 @@ export class MCPToolRegistry extends MCPRegistry {
|
|
211
205
|
async executeTool(toolName, args, context) {
|
212
206
|
const startTime = Date.now();
|
213
207
|
try {
|
214
|
-
registryLogger.info(
|
208
|
+
registryLogger.info(`🔧 [TOOL_EXECUTION] Starting execution: ${toolName}`);
|
209
|
+
registryLogger.info(`🔧 [TOOL_EXECUTION] Starting execution: ${toolName}`, { args, context });
|
215
210
|
// Try to find the tool by fully-qualified name first
|
216
211
|
let tool = this.tools.get(toolName);
|
212
|
+
registryLogger.info(`🔍 [TOOL_LOOKUP] Direct lookup result for '${toolName}':`, !!tool);
|
217
213
|
// If not found, search for tool by name across all entries (for backward compatibility)
|
218
214
|
let toolId = toolName;
|
219
215
|
if (!tool) {
|
package/dist/neurolink.d.ts
CHANGED
@@ -10,10 +10,12 @@ import type { GenerateOptions, GenerateResult } from "./types/generateTypes.js";
|
|
10
10
|
import type { StreamOptions, StreamResult } from "./types/streamTypes.js";
|
11
11
|
import type { MCPServerInfo, MCPExecutableTool } from "./types/mcpTypes.js";
|
12
12
|
import type { ToolInfo } from "./mcp/contracts/mcpContract.js";
|
13
|
+
import type { NeuroLinkEvents, TypedEventEmitter, ToolExecutionContext, ToolExecutionSummary } from "./types/common.js";
|
13
14
|
import type { JsonObject } from "./types/common.js";
|
14
15
|
import type { BatchOperationResult } from "./types/typeAliases.js";
|
15
|
-
import { EventEmitter } from "events";
|
16
16
|
import type { ConversationMemoryConfig, ChatMessage } from "./types/conversation.js";
|
17
|
+
import { ConversationMemoryManager } from "./core/conversationMemoryManager.js";
|
18
|
+
import { RedisConversationMemoryManager } from "./core/redisConversationMemoryManager.js";
|
17
19
|
import type { ExternalMCPServerInstance, ExternalMCPOperationResult, ExternalMCPToolInfo } from "./types/externalMcp.js";
|
18
20
|
export interface ProviderStatus {
|
19
21
|
provider: string;
|
@@ -49,6 +51,9 @@ export declare class NeuroLink {
|
|
49
51
|
private readonly toolCacheDuration;
|
50
52
|
private toolCircuitBreakers;
|
51
53
|
private toolExecutionMetrics;
|
54
|
+
private currentStreamToolExecutions;
|
55
|
+
private toolExecutionHistory;
|
56
|
+
private activeToolExecutions;
|
52
57
|
/**
|
53
58
|
* Helper method to emit tool end event in a consistent way
|
54
59
|
* Used by executeTool in both success and error paths
|
@@ -59,10 +64,15 @@ export declare class NeuroLink {
|
|
59
64
|
* @param error - The error if execution failed (optional)
|
60
65
|
*/
|
61
66
|
private emitToolEndEvent;
|
62
|
-
|
67
|
+
conversationMemory?: ConversationMemoryManager | RedisConversationMemoryManager | null;
|
63
68
|
private conversationMemoryNeedsInit;
|
64
69
|
private conversationMemoryConfig?;
|
65
70
|
private enableOrchestration;
|
71
|
+
/**
|
72
|
+
* Context storage for tool execution
|
73
|
+
* This context will be merged with any runtime context passed by the AI model
|
74
|
+
*/
|
75
|
+
private toolExecutionContext?;
|
66
76
|
/**
|
67
77
|
* Creates a new NeuroLink instance for AI text generation with MCP tool integration.
|
68
78
|
*
|
@@ -101,10 +111,6 @@ export declare class NeuroLink {
|
|
101
111
|
conversationMemory?: Partial<ConversationMemoryConfig>;
|
102
112
|
enableOrchestration?: boolean;
|
103
113
|
});
|
104
|
-
/**
|
105
|
-
* Log constructor start with comprehensive environment analysis
|
106
|
-
*/
|
107
|
-
private logConstructorStart;
|
108
114
|
/**
|
109
115
|
* Initialize provider registry with security settings
|
110
116
|
*/
|
@@ -130,14 +136,6 @@ export declare class NeuroLink {
|
|
130
136
|
* Uses isolated async context to prevent hanging
|
131
137
|
*/
|
132
138
|
private initializeMCP;
|
133
|
-
/**
|
134
|
-
* Log MCP initialization start
|
135
|
-
*/
|
136
|
-
private logMCPInitStart;
|
137
|
-
/**
|
138
|
-
* Log MCP already initialized
|
139
|
-
*/
|
140
|
-
private logMCPAlreadyInitialized;
|
141
139
|
/**
|
142
140
|
* Import performance manager with error handling
|
143
141
|
*/
|
@@ -293,10 +291,6 @@ export declare class NeuroLink {
|
|
293
291
|
* Simplified approach without domain detection - relies on tool registry
|
294
292
|
*/
|
295
293
|
private detectAndExecuteTools;
|
296
|
-
/**
|
297
|
-
* Enhance prompt with tool results (domain-agnostic)
|
298
|
-
*/
|
299
|
-
private enhancePromptWithToolResults;
|
300
294
|
/**
|
301
295
|
* BACKWARD COMPATIBILITY: Legacy streamText method
|
302
296
|
* Internally calls stream() and converts result format
|
@@ -354,14 +348,6 @@ export declare class NeuroLink {
|
|
354
348
|
* @throws {Error} When conversation memory operations fail (if enabled)
|
355
349
|
*/
|
356
350
|
stream(options: StreamOptions): Promise<StreamResult>;
|
357
|
-
/**
|
358
|
-
* Log stream entry point with comprehensive analysis
|
359
|
-
*/
|
360
|
-
private logStreamEntryPoint;
|
361
|
-
/**
|
362
|
-
* Log performance baseline
|
363
|
-
*/
|
364
|
-
private logPerformanceBaseline;
|
365
351
|
/**
|
366
352
|
* Validate stream input with comprehensive error reporting
|
367
353
|
*/
|
@@ -564,13 +550,58 @@ export declare class NeuroLink {
|
|
564
550
|
* @see {@link NeuroLink.stream} for events related to streaming
|
565
551
|
* @see {@link NeuroLink.executeTool} for events related to tool execution
|
566
552
|
*/
|
567
|
-
getEventEmitter():
|
553
|
+
getEventEmitter(): TypedEventEmitter<NeuroLinkEvents>;
|
554
|
+
/**
|
555
|
+
* Emit tool start event with execution tracking
|
556
|
+
* @param toolName - Name of the tool being executed
|
557
|
+
* @param input - Input parameters for the tool
|
558
|
+
* @param startTime - Timestamp when execution started
|
559
|
+
* @returns executionId for tracking this specific execution
|
560
|
+
*/
|
561
|
+
emitToolStart(toolName: string, input: unknown, startTime?: number): string;
|
562
|
+
/**
|
563
|
+
* Emit tool end event with execution summary
|
564
|
+
* @param toolName - Name of the tool that finished
|
565
|
+
* @param result - Result from the tool execution
|
566
|
+
* @param error - Error message if execution failed
|
567
|
+
* @param startTime - When execution started
|
568
|
+
* @param endTime - When execution finished
|
569
|
+
* @param executionId - Optional execution ID for tracking
|
570
|
+
*/
|
571
|
+
emitToolEnd(toolName: string, result?: unknown, error?: string, startTime?: number, endTime?: number, executionId?: string): void;
|
572
|
+
/**
|
573
|
+
* Get current tool execution contexts for stream metadata
|
574
|
+
*/
|
575
|
+
getCurrentToolExecutions(): ToolExecutionContext[];
|
576
|
+
/**
|
577
|
+
* Get tool execution history
|
578
|
+
*/
|
579
|
+
getToolExecutionHistory(): ToolExecutionSummary[];
|
580
|
+
/**
|
581
|
+
* Clear current stream tool executions (called at stream start)
|
582
|
+
*/
|
583
|
+
clearCurrentStreamExecutions(): void;
|
568
584
|
/**
|
569
585
|
* Register a custom tool that will be available to all AI providers
|
570
586
|
* @param name - Unique name for the tool
|
571
587
|
* @param tool - Tool in MCPExecutableTool format (unified MCP protocol type)
|
572
588
|
*/
|
573
589
|
registerTool(name: string, tool: MCPExecutableTool): void;
|
590
|
+
/**
|
591
|
+
* Set the context that will be passed to tools during execution
|
592
|
+
* This context will be merged with any runtime context passed by the AI model
|
593
|
+
* @param context - Context object containing session info, tokens, shop data, etc.
|
594
|
+
*/
|
595
|
+
setToolContext(context: Record<string, unknown>): void;
|
596
|
+
/**
|
597
|
+
* Get the current tool execution context
|
598
|
+
* @returns Current context or undefined if not set
|
599
|
+
*/
|
600
|
+
getToolContext(): Record<string, unknown> | undefined;
|
601
|
+
/**
|
602
|
+
* Clear the tool execution context
|
603
|
+
*/
|
604
|
+
clearToolContext(): void;
|
574
605
|
/**
|
575
606
|
* Register multiple tools at once - Supports both object and array formats
|
576
607
|
* @param tools - Object mapping tool names to MCPExecutableTool format OR Array of tools with names
|
@@ -621,13 +652,19 @@ export declare class NeuroLink {
|
|
621
652
|
* Supports both custom tools and MCP server tools with timeout, retry, and circuit breaker patterns
|
622
653
|
* @param toolName - Name of the tool to execute
|
623
654
|
* @param params - Parameters to pass to the tool
|
624
|
-
* @param options - Execution options
|
655
|
+
* @param options - Execution options including optional authentication context
|
625
656
|
* @returns Tool execution result
|
626
657
|
*/
|
627
658
|
executeTool<T = unknown>(toolName: string, params?: unknown, options?: {
|
628
659
|
timeout?: number;
|
629
660
|
maxRetries?: number;
|
630
661
|
retryDelayMs?: number;
|
662
|
+
authContext?: {
|
663
|
+
userId?: string;
|
664
|
+
sessionId?: string;
|
665
|
+
user?: Record<string, unknown>;
|
666
|
+
[key: string]: unknown;
|
667
|
+
};
|
631
668
|
}): Promise<T>;
|
632
669
|
/**
|
633
670
|
* Internal tool execution method (extracted for better error handling)
|
@@ -813,6 +850,12 @@ export declare class NeuroLink {
|
|
813
850
|
recommendations: string[];
|
814
851
|
}>;
|
815
852
|
}>;
|
853
|
+
/**
|
854
|
+
* Initialize conversation memory if enabled (public method for explicit initialization)
|
855
|
+
* This is useful for testing or when you want to ensure conversation memory is ready
|
856
|
+
* @returns Promise resolving to true if initialization was successful, false otherwise
|
857
|
+
*/
|
858
|
+
ensureConversationMemoryInitialized(): Promise<boolean>;
|
816
859
|
/**
|
817
860
|
* Get conversation memory statistics (public API)
|
818
861
|
*/
|
@@ -831,6 +874,30 @@ export declare class NeuroLink {
|
|
831
874
|
* Clear all conversation history (public API)
|
832
875
|
*/
|
833
876
|
clearAllConversations(): Promise<void>;
|
877
|
+
/**
|
878
|
+
* Store tool executions in conversation memory if enabled and Redis is configured
|
879
|
+
* @param sessionId - Session identifier
|
880
|
+
* @param userId - User identifier (optional)
|
881
|
+
* @param toolCalls - Array of tool calls
|
882
|
+
* @param toolResults - Array of tool results
|
883
|
+
* @returns Promise resolving when storage is complete
|
884
|
+
*/
|
885
|
+
storeToolExecutions(sessionId: string, userId: string | undefined, toolCalls: Array<{
|
886
|
+
toolCallId?: string;
|
887
|
+
toolName?: string;
|
888
|
+
args?: Record<string, unknown>;
|
889
|
+
[key: string]: unknown;
|
890
|
+
}>, toolResults: Array<{
|
891
|
+
toolCallId?: string;
|
892
|
+
result?: unknown;
|
893
|
+
error?: string;
|
894
|
+
[key: string]: unknown;
|
895
|
+
}>): Promise<void>;
|
896
|
+
/**
|
897
|
+
* Check if tool execution storage is available
|
898
|
+
* @returns boolean indicating if Redis storage is configured and available
|
899
|
+
*/
|
900
|
+
isToolExecutionStorageAvailable(): boolean;
|
834
901
|
/**
|
835
902
|
* Add an external MCP server
|
836
903
|
* Automatically discovers and registers tools from the server
|