@juspay/neurolink 7.29.2 → 7.30.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 +83 -83
- package/dist/cli/commands/mcp.js +39 -9
- package/dist/cli/commands/models.js +25 -21
- package/dist/cli/commands/ollama.js +2 -2
- package/dist/cli/factories/commandFactory.d.ts +8 -0
- package/dist/cli/factories/commandFactory.js +65 -65
- package/dist/cli/factories/ollamaCommandFactory.js +3 -1
- package/dist/cli/factories/sagemakerCommandFactory.js +3 -2
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +11 -11
- package/dist/cli/utils/envManager.js +5 -5
- package/dist/cli/utils/ollamaUtils.d.ts +12 -0
- package/dist/cli/utils/ollamaUtils.js +58 -42
- package/dist/config/configManager.js +5 -2
- package/dist/config/conversationMemoryConfig.js +5 -0
- package/dist/core/analytics.d.ts +2 -24
- package/dist/core/analytics.js +12 -17
- package/dist/core/baseProvider.d.ts +30 -1
- package/dist/core/baseProvider.js +180 -198
- package/dist/core/conversationMemoryManager.d.ts +9 -15
- package/dist/core/conversationMemoryManager.js +98 -57
- package/dist/core/dynamicModels.d.ts +4 -4
- package/dist/core/dynamicModels.js +7 -7
- package/dist/core/evaluation.d.ts +9 -9
- package/dist/core/evaluation.js +117 -65
- package/dist/core/evaluationProviders.d.ts +18 -2
- package/dist/core/evaluationProviders.js +15 -13
- package/dist/core/modelConfiguration.d.ts +63 -0
- package/dist/core/modelConfiguration.js +354 -290
- package/dist/core/streamAnalytics.d.ts +10 -5
- package/dist/core/streamAnalytics.js +10 -10
- package/dist/core/types.d.ts +22 -110
- package/dist/core/types.js +13 -0
- package/dist/factories/providerFactory.js +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/lib/config/configManager.js +5 -2
- package/dist/lib/config/conversationMemoryConfig.js +5 -0
- package/dist/lib/core/analytics.d.ts +2 -24
- package/dist/lib/core/analytics.js +12 -17
- package/dist/lib/core/baseProvider.d.ts +30 -1
- package/dist/lib/core/baseProvider.js +180 -198
- package/dist/lib/core/conversationMemoryManager.d.ts +9 -15
- package/dist/lib/core/conversationMemoryManager.js +98 -57
- package/dist/lib/core/dynamicModels.js +7 -7
- package/dist/lib/core/evaluation.d.ts +9 -9
- package/dist/lib/core/evaluation.js +117 -65
- package/dist/lib/core/evaluationProviders.d.ts +18 -2
- package/dist/lib/core/evaluationProviders.js +15 -13
- package/dist/lib/core/modelConfiguration.d.ts +63 -0
- package/dist/lib/core/modelConfiguration.js +354 -290
- package/dist/lib/core/streamAnalytics.d.ts +10 -5
- package/dist/lib/core/streamAnalytics.js +10 -10
- package/dist/lib/core/types.d.ts +22 -110
- package/dist/lib/core/types.js +13 -0
- package/dist/lib/factories/providerFactory.js +1 -1
- package/dist/lib/index.d.ts +2 -1
- package/dist/lib/mcp/externalServerManager.js +15 -6
- package/dist/lib/mcp/factory.js +1 -1
- package/dist/lib/mcp/index.d.ts +1 -1
- package/dist/lib/mcp/index.js +1 -1
- package/dist/lib/mcp/mcpCircuitBreaker.js +5 -1
- package/dist/lib/mcp/mcpClientFactory.js +3 -0
- package/dist/lib/mcp/registry.d.ts +3 -3
- package/dist/lib/mcp/registry.js +3 -3
- package/dist/lib/mcp/servers/aiProviders/aiAnalysisTools.js +5 -5
- package/dist/lib/mcp/servers/aiProviders/aiWorkflowTools.js +6 -6
- package/dist/lib/mcp/servers/utilities/utilityServer.js +1 -1
- package/dist/lib/mcp/toolDiscoveryService.js +8 -2
- package/dist/lib/mcp/toolRegistry.js +4 -4
- package/dist/lib/middleware/builtin/analytics.js +4 -4
- package/dist/lib/middleware/builtin/guardrails.js +2 -2
- package/dist/lib/middleware/registry.js +11 -2
- package/dist/lib/models/modelRegistry.d.ts +1 -1
- package/dist/lib/models/modelRegistry.js +3 -3
- package/dist/lib/models/modelResolver.d.ts +1 -1
- package/dist/lib/models/modelResolver.js +2 -2
- package/dist/lib/neurolink.d.ts +116 -9
- package/dist/lib/neurolink.js +718 -956
- package/dist/lib/providers/amazonSagemaker.d.ts +1 -1
- package/dist/lib/providers/amazonSagemaker.js +12 -3
- package/dist/lib/providers/anthropic.d.ts +1 -1
- package/dist/lib/providers/anthropic.js +7 -6
- package/dist/lib/providers/anthropicBaseProvider.d.ts +1 -1
- package/dist/lib/providers/anthropicBaseProvider.js +4 -3
- package/dist/lib/providers/azureOpenai.d.ts +1 -1
- package/dist/lib/providers/azureOpenai.js +1 -1
- package/dist/lib/providers/googleAiStudio.d.ts +1 -1
- package/dist/lib/providers/googleAiStudio.js +2 -2
- package/dist/lib/providers/googleVertex.d.ts +40 -0
- package/dist/lib/providers/googleVertex.js +330 -274
- package/dist/lib/providers/huggingFace.js +1 -1
- package/dist/lib/providers/mistral.d.ts +1 -1
- package/dist/lib/providers/mistral.js +2 -2
- package/dist/lib/providers/ollama.d.ts +4 -0
- package/dist/lib/providers/ollama.js +38 -18
- package/dist/lib/providers/openAI.d.ts +1 -1
- package/dist/lib/providers/openAI.js +2 -2
- package/dist/lib/providers/sagemaker/adaptive-semaphore.js +7 -4
- package/dist/lib/providers/sagemaker/client.js +13 -3
- package/dist/lib/providers/sagemaker/config.js +5 -1
- package/dist/lib/providers/sagemaker/detection.js +19 -9
- package/dist/lib/providers/sagemaker/errors.d.ts +8 -1
- package/dist/lib/providers/sagemaker/errors.js +103 -20
- package/dist/lib/providers/sagemaker/language-model.d.ts +3 -3
- package/dist/lib/providers/sagemaker/language-model.js +4 -4
- package/dist/lib/providers/sagemaker/parsers.js +14 -6
- package/dist/lib/providers/sagemaker/streaming.js +14 -3
- package/dist/lib/providers/sagemaker/types.d.ts +1 -1
- package/dist/lib/proxy/awsProxyIntegration.js +1 -1
- package/dist/lib/sdk/toolRegistration.d.ts +1 -1
- package/dist/lib/types/cli.d.ts +80 -8
- package/dist/lib/types/contextTypes.js +2 -2
- package/dist/lib/types/conversationTypes.d.ts +10 -0
- package/dist/lib/types/generateTypes.d.ts +2 -5
- package/dist/lib/types/providers.d.ts +81 -19
- package/dist/lib/types/providers.js +6 -6
- package/dist/lib/types/streamTypes.d.ts +4 -6
- package/dist/lib/types/typeAliases.d.ts +1 -1
- package/dist/lib/utils/analyticsUtils.d.ts +33 -0
- package/dist/lib/utils/analyticsUtils.js +76 -0
- package/dist/lib/utils/conversationMemoryUtils.d.ts +1 -2
- package/dist/lib/utils/conversationMemoryUtils.js +6 -7
- package/dist/lib/utils/errorHandling.js +4 -1
- package/dist/lib/utils/evaluationUtils.d.ts +27 -0
- package/dist/lib/utils/evaluationUtils.js +131 -0
- package/dist/lib/utils/optionsUtils.js +10 -1
- package/dist/lib/utils/performance.d.ts +1 -1
- package/dist/lib/utils/performance.js +15 -3
- package/dist/lib/utils/providerHealth.d.ts +48 -0
- package/dist/lib/utils/providerHealth.js +199 -254
- package/dist/lib/utils/providerUtils.js +2 -2
- package/dist/lib/utils/timeout.js +8 -3
- package/dist/mcp/externalServerManager.js +15 -6
- package/dist/mcp/factory.js +1 -1
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/mcpCircuitBreaker.js +5 -1
- package/dist/mcp/mcpClientFactory.js +3 -0
- package/dist/mcp/registry.d.ts +3 -3
- package/dist/mcp/registry.js +3 -3
- package/dist/mcp/servers/aiProviders/aiAnalysisTools.js +5 -5
- package/dist/mcp/servers/aiProviders/aiWorkflowTools.js +6 -6
- package/dist/mcp/servers/utilities/utilityServer.js +1 -1
- package/dist/mcp/toolDiscoveryService.js +8 -2
- package/dist/mcp/toolRegistry.js +4 -4
- package/dist/middleware/builtin/analytics.js +4 -4
- package/dist/middleware/builtin/guardrails.js +2 -2
- package/dist/middleware/registry.js +11 -2
- package/dist/models/modelRegistry.d.ts +1 -1
- package/dist/models/modelRegistry.js +3 -3
- package/dist/models/modelResolver.d.ts +1 -1
- package/dist/models/modelResolver.js +2 -2
- package/dist/neurolink.d.ts +116 -9
- package/dist/neurolink.js +718 -956
- package/dist/providers/amazonSagemaker.d.ts +1 -1
- package/dist/providers/amazonSagemaker.js +12 -3
- package/dist/providers/anthropic.d.ts +1 -1
- package/dist/providers/anthropic.js +7 -6
- package/dist/providers/anthropicBaseProvider.d.ts +1 -1
- package/dist/providers/anthropicBaseProvider.js +4 -3
- package/dist/providers/azureOpenai.d.ts +1 -1
- package/dist/providers/azureOpenai.js +1 -1
- package/dist/providers/googleAiStudio.d.ts +1 -1
- package/dist/providers/googleAiStudio.js +2 -2
- package/dist/providers/googleVertex.d.ts +40 -0
- package/dist/providers/googleVertex.js +330 -274
- package/dist/providers/huggingFace.js +1 -1
- package/dist/providers/mistral.d.ts +1 -1
- package/dist/providers/mistral.js +2 -2
- package/dist/providers/ollama.d.ts +4 -0
- package/dist/providers/ollama.js +38 -18
- package/dist/providers/openAI.d.ts +1 -1
- package/dist/providers/openAI.js +2 -2
- package/dist/providers/sagemaker/adaptive-semaphore.js +7 -4
- package/dist/providers/sagemaker/client.js +13 -3
- package/dist/providers/sagemaker/config.js +5 -1
- package/dist/providers/sagemaker/detection.js +19 -9
- package/dist/providers/sagemaker/errors.d.ts +8 -1
- package/dist/providers/sagemaker/errors.js +103 -20
- package/dist/providers/sagemaker/language-model.d.ts +3 -3
- package/dist/providers/sagemaker/language-model.js +4 -4
- package/dist/providers/sagemaker/parsers.js +14 -6
- package/dist/providers/sagemaker/streaming.js +14 -3
- package/dist/providers/sagemaker/types.d.ts +1 -1
- package/dist/proxy/awsProxyIntegration.js +1 -1
- package/dist/sdk/toolRegistration.d.ts +1 -1
- package/dist/types/cli.d.ts +80 -8
- package/dist/types/contextTypes.js +2 -2
- package/dist/types/conversationTypes.d.ts +10 -0
- package/dist/types/generateTypes.d.ts +2 -5
- package/dist/types/providers.d.ts +81 -19
- package/dist/types/providers.js +6 -6
- package/dist/types/streamTypes.d.ts +4 -6
- package/dist/types/typeAliases.d.ts +1 -1
- package/dist/utils/analyticsUtils.d.ts +33 -0
- package/dist/utils/analyticsUtils.js +76 -0
- package/dist/utils/conversationMemoryUtils.d.ts +1 -2
- package/dist/utils/conversationMemoryUtils.js +6 -7
- package/dist/utils/errorHandling.js +4 -1
- package/dist/utils/evaluationUtils.d.ts +27 -0
- package/dist/utils/evaluationUtils.js +131 -0
- package/dist/utils/optionsUtils.js +10 -1
- package/dist/utils/performance.d.ts +1 -1
- package/dist/utils/performance.js +15 -3
- package/dist/utils/providerHealth.d.ts +48 -0
- package/dist/utils/providerHealth.js +199 -254
- package/dist/utils/providerUtils.js +2 -2
- package/dist/utils/timeout.js +8 -3
- package/package.json +1 -1
- package/dist/context/ContextManager.d.ts +0 -28
- package/dist/context/ContextManager.js +0 -113
- package/dist/context/config.d.ts +0 -5
- package/dist/context/config.js +0 -42
- package/dist/context/types.d.ts +0 -20
- package/dist/context/types.js +0 -1
- package/dist/context/utils.d.ts +0 -7
- package/dist/context/utils.js +0 -8
- package/dist/lib/context/ContextManager.d.ts +0 -28
- package/dist/lib/context/ContextManager.js +0 -113
- package/dist/lib/context/config.d.ts +0 -5
- package/dist/lib/context/config.js +0 -42
- package/dist/lib/context/types.d.ts +0 -20
- package/dist/lib/context/types.js +0 -1
- package/dist/lib/context/utils.d.ts +0 -7
- package/dist/lib/context/utils.js +0 -8
|
@@ -78,7 +78,7 @@ const OptimizeParametersSchema = z.object({
|
|
|
78
78
|
* AI Usage Analysis Tool
|
|
79
79
|
* Analyzes AI usage patterns, token consumption, and cost optimization opportunities
|
|
80
80
|
*/
|
|
81
|
-
const
|
|
81
|
+
const _analyzeAIUsageTool = {
|
|
82
82
|
name: "analyze-ai-usage",
|
|
83
83
|
description: "Analyze AI usage patterns, token consumption, and cost optimization opportunities",
|
|
84
84
|
category: "ai-analysis",
|
|
@@ -163,7 +163,7 @@ const analyzeAIUsageTool = {
|
|
|
163
163
|
* Provider Performance Benchmarking Tool
|
|
164
164
|
* Benchmarks AI provider performance across latency, quality, and cost metrics
|
|
165
165
|
*/
|
|
166
|
-
const
|
|
166
|
+
const _benchmarkProviderPerformanceTool = {
|
|
167
167
|
name: "benchmark-provider-performance",
|
|
168
168
|
description: "Benchmark AI provider performance across latency, quality, and cost metrics",
|
|
169
169
|
category: "ai-analysis",
|
|
@@ -199,7 +199,7 @@ const benchmarkProviderPerformanceTool = {
|
|
|
199
199
|
});
|
|
200
200
|
if (result && result.usage) {
|
|
201
201
|
totalLatency += Date.now() - testStartTime;
|
|
202
|
-
totalTokens += result.usage.
|
|
202
|
+
totalTokens += result.usage.total || 0;
|
|
203
203
|
successfulTests++;
|
|
204
204
|
}
|
|
205
205
|
}
|
|
@@ -210,7 +210,7 @@ const benchmarkProviderPerformanceTool = {
|
|
|
210
210
|
avgLatency: successfulTests > 0
|
|
211
211
|
? Math.round(totalLatency / successfulTests)
|
|
212
212
|
: 0,
|
|
213
|
-
|
|
213
|
+
total: totalTokens,
|
|
214
214
|
successRate: (successfulTests /
|
|
215
215
|
(testPrompts.length * typedParams.iterations)) *
|
|
216
216
|
100,
|
|
@@ -259,7 +259,7 @@ const benchmarkProviderPerformanceTool = {
|
|
|
259
259
|
* Prompt Parameter Optimization Tool
|
|
260
260
|
* Optimizes prompt parameters (temperature, max tokens) for better AI output quality and efficiency
|
|
261
261
|
*/
|
|
262
|
-
const
|
|
262
|
+
const _optimizePromptParametersTool = {
|
|
263
263
|
name: "optimize-prompt-parameters",
|
|
264
264
|
description: "Optimize prompt parameters (temperature, max tokens) for better AI output quality and efficiency",
|
|
265
265
|
category: "ai-optimization",
|
|
@@ -99,7 +99,7 @@ const debugAIOutputSchema = z.object({
|
|
|
99
99
|
/**
|
|
100
100
|
* Generate test cases for code functions
|
|
101
101
|
*/
|
|
102
|
-
const
|
|
102
|
+
const _generateTestCasesTool = {
|
|
103
103
|
name: "generate-test-cases",
|
|
104
104
|
description: "Generate comprehensive test cases for code functions with various test types and frameworks",
|
|
105
105
|
category: "ai-workflow",
|
|
@@ -203,7 +203,7 @@ Generate 3-5 comprehensive test cases covering the requested types.`;
|
|
|
203
203
|
/**
|
|
204
204
|
* Refactor code for improved quality
|
|
205
205
|
*/
|
|
206
|
-
const
|
|
206
|
+
const _refactorCodeTool = {
|
|
207
207
|
name: "refactor-code",
|
|
208
208
|
description: "AI-powered code refactoring for improved readability, performance, and maintainability",
|
|
209
209
|
category: "ai-workflow",
|
|
@@ -316,7 +316,7 @@ Focus on real, actionable improvements based on the specified objectives.`;
|
|
|
316
316
|
/**
|
|
317
317
|
* Generate documentation from code
|
|
318
318
|
*/
|
|
319
|
-
const
|
|
319
|
+
const _generateDocumentationTool = {
|
|
320
320
|
name: "generate-documentation",
|
|
321
321
|
description: "Automatically generate comprehensive documentation from code",
|
|
322
322
|
category: "ai-workflow",
|
|
@@ -427,7 +427,7 @@ Focus on creating accurate, useful documentation that explains the code's purpos
|
|
|
427
427
|
/**
|
|
428
428
|
* Debug AI-generated output
|
|
429
429
|
*/
|
|
430
|
-
const
|
|
430
|
+
const _debugAIOutputTool = {
|
|
431
431
|
name: "debug-ai-output",
|
|
432
432
|
description: "Analyze and debug AI-generated output to identify issues and suggest improvements",
|
|
433
433
|
category: "ai-workflow",
|
|
@@ -549,13 +549,13 @@ Provide thorough, actionable analysis focused on improving AI output quality.`;
|
|
|
549
549
|
},
|
|
550
550
|
};
|
|
551
551
|
// Helper functions
|
|
552
|
-
function
|
|
552
|
+
function _extractFunctionName(code) {
|
|
553
553
|
const match = code.match(/function\s+(\w+)|const\s+(\w+)\s*=|(\w+)\s*\(/);
|
|
554
554
|
return match
|
|
555
555
|
? match[1] || match[2] || match[3] || "processData"
|
|
556
556
|
: "processData";
|
|
557
557
|
}
|
|
558
|
-
function
|
|
558
|
+
function _simulateRefactoring(code, objectives, _styleGuide) {
|
|
559
559
|
// Simulate basic refactoring
|
|
560
560
|
let refactored = code;
|
|
561
561
|
if (objectives.includes("readability")) {
|
|
@@ -61,7 +61,7 @@ utilityServer.registerTool({
|
|
|
61
61
|
});
|
|
62
62
|
resultData.actualTimezone = timezone;
|
|
63
63
|
}
|
|
64
|
-
catch
|
|
64
|
+
catch {
|
|
65
65
|
const fallbackTimezone = "Asia/Kolkata";
|
|
66
66
|
logger.warn(`[Utility] Invalid timezone '${timezone}', falling back to ${fallbackTimezone}`);
|
|
67
67
|
resultData.localTime = now.toLocaleString("en-US", {
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { EventEmitter } from "events";
|
|
7
7
|
import { mcpLogger } from "../utils/logger.js";
|
|
8
8
|
import { globalCircuitBreakerManager } from "./mcpCircuitBreaker.js";
|
|
9
|
-
import { isObject, isNullish
|
|
9
|
+
import { isObject, isNullish } from "../utils/typeUtils.js";
|
|
10
10
|
import { validateToolName, validateToolDescription, } from "../utils/parameterValidation.js";
|
|
11
11
|
/**
|
|
12
12
|
* ToolDiscoveryService
|
|
@@ -133,6 +133,9 @@ export class ToolDiscoveryService extends EventEmitter {
|
|
|
133
133
|
this.serverToolStorage.set(serverId, []);
|
|
134
134
|
}
|
|
135
135
|
const serverTools = this.serverToolStorage.get(serverId);
|
|
136
|
+
if (!serverTools) {
|
|
137
|
+
throw new Error(`Server tools storage not found for ${serverId}`);
|
|
138
|
+
}
|
|
136
139
|
// Add tool if not already present
|
|
137
140
|
if (!serverTools.find((t) => t.name === tool.name)) {
|
|
138
141
|
serverTools.push({
|
|
@@ -145,7 +148,10 @@ export class ToolDiscoveryService extends EventEmitter {
|
|
|
145
148
|
if (!this.serverTools.has(serverId)) {
|
|
146
149
|
this.serverTools.set(serverId, new Set());
|
|
147
150
|
}
|
|
148
|
-
this.serverTools.get(serverId)
|
|
151
|
+
const serverToolSet = this.serverTools.get(serverId);
|
|
152
|
+
if (serverToolSet) {
|
|
153
|
+
serverToolSet.add(tool.name);
|
|
154
|
+
}
|
|
149
155
|
registeredTools.push(toolInfo);
|
|
150
156
|
// Emit tool registered event
|
|
151
157
|
this.emit("toolRegistered", {
|
package/dist/mcp/toolRegistry.js
CHANGED
|
@@ -81,11 +81,11 @@ export class MCPToolRegistry extends MCPRegistry {
|
|
|
81
81
|
async registerServer(serverInfoOrId, serverConfigOrContext, context) {
|
|
82
82
|
// Handle both signatures for backward compatibility
|
|
83
83
|
let serverInfo;
|
|
84
|
-
let
|
|
84
|
+
let _finalContext;
|
|
85
85
|
if (typeof serverInfoOrId === "string") {
|
|
86
86
|
// Legacy signature: registerServer(serverId, serverConfig, context)
|
|
87
87
|
const serverId = serverInfoOrId;
|
|
88
|
-
|
|
88
|
+
_finalContext = context;
|
|
89
89
|
// Convert legacy call to MCPServerInfo format using smart defaults
|
|
90
90
|
serverInfo = createMCPServerInfo({
|
|
91
91
|
id: serverId,
|
|
@@ -97,7 +97,7 @@ export class MCPToolRegistry extends MCPRegistry {
|
|
|
97
97
|
else {
|
|
98
98
|
// New signature: registerServer(serverInfo, context)
|
|
99
99
|
serverInfo = serverInfoOrId;
|
|
100
|
-
|
|
100
|
+
_finalContext = serverConfigOrContext;
|
|
101
101
|
}
|
|
102
102
|
const serverId = serverInfo.id;
|
|
103
103
|
registryLogger.info(`Registering MCPServerInfo directly: ${serverId}`);
|
|
@@ -348,7 +348,7 @@ export class MCPToolRegistry extends MCPRegistry {
|
|
|
348
348
|
if (filter.permissions && filter.permissions.length > 0) {
|
|
349
349
|
result = result.filter((tool) => {
|
|
350
350
|
const toolPermissions = tool.permissions || [];
|
|
351
|
-
return filter.permissions
|
|
351
|
+
return (filter.permissions?.some((perm) => toolPermissions.includes(perm)) ?? false);
|
|
352
352
|
});
|
|
353
353
|
}
|
|
354
354
|
}
|
|
@@ -30,10 +30,10 @@ export function createAnalyticsMiddleware() {
|
|
|
30
30
|
responseTime,
|
|
31
31
|
timestamp: new Date().toISOString(),
|
|
32
32
|
usage: {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
(result.usage?.completionTokens
|
|
33
|
+
input: result.usage?.promptTokens ?? 0,
|
|
34
|
+
output: result.usage?.completionTokens ?? 0,
|
|
35
|
+
total: (result.usage?.promptTokens ?? 0) +
|
|
36
|
+
(result.usage?.completionTokens ?? 0),
|
|
37
37
|
},
|
|
38
38
|
};
|
|
39
39
|
// Store metrics for potential retrieval
|
|
@@ -13,7 +13,7 @@ export function createGuardrailsMiddleware(config = {}) {
|
|
|
13
13
|
defaultEnabled: true,
|
|
14
14
|
};
|
|
15
15
|
const middleware = {
|
|
16
|
-
wrapGenerate: async ({ doGenerate, params }) => {
|
|
16
|
+
wrapGenerate: async ({ doGenerate, params: _params }) => {
|
|
17
17
|
logger.debug(`[GuardrailsMiddleware] Applying to generate call.`, {
|
|
18
18
|
badWordsEnabled: !!config.badWords?.enabled,
|
|
19
19
|
modelFilterEnabled: !!config.modelFilter?.enabled,
|
|
@@ -53,7 +53,7 @@ export function createGuardrailsMiddleware(config = {}) {
|
|
|
53
53
|
}
|
|
54
54
|
return result;
|
|
55
55
|
},
|
|
56
|
-
wrapStream: async ({ doStream, params }) => {
|
|
56
|
+
wrapStream: async ({ doStream, params: _params }) => {
|
|
57
57
|
logger.debug(`[GuardrailsMiddleware] Applying to stream call.`, {
|
|
58
58
|
badWordsEnabled: !!config.badWords?.enabled,
|
|
59
59
|
});
|
|
@@ -135,9 +135,9 @@ export class MiddlewareRegistry {
|
|
|
135
135
|
/**
|
|
136
136
|
* Configure middleware with runtime configuration
|
|
137
137
|
*/
|
|
138
|
-
configureMiddleware(middleware, config, globalConfig,
|
|
138
|
+
configureMiddleware(middleware, config, globalConfig, _context) {
|
|
139
139
|
// Merge configurations: global < middleware config < runtime config
|
|
140
|
-
const
|
|
140
|
+
const _mergedConfig = {
|
|
141
141
|
...globalConfig,
|
|
142
142
|
...config?.config,
|
|
143
143
|
};
|
|
@@ -149,6 +149,9 @@ export class MiddlewareRegistry {
|
|
|
149
149
|
wrappedMiddleware.transformParams = async (args) => {
|
|
150
150
|
const startTime = Date.now();
|
|
151
151
|
try {
|
|
152
|
+
if (!middleware.transformParams) {
|
|
153
|
+
throw new Error("transformParams method is required");
|
|
154
|
+
}
|
|
152
155
|
const result = await middleware.transformParams(args);
|
|
153
156
|
this.recordExecution(middleware.metadata.id, startTime, true);
|
|
154
157
|
return result;
|
|
@@ -163,6 +166,9 @@ export class MiddlewareRegistry {
|
|
|
163
166
|
wrappedMiddleware.wrapGenerate = async (args) => {
|
|
164
167
|
const startTime = Date.now();
|
|
165
168
|
try {
|
|
169
|
+
if (!middleware.wrapGenerate) {
|
|
170
|
+
throw new Error("wrapGenerate method is required");
|
|
171
|
+
}
|
|
166
172
|
const result = await middleware.wrapGenerate(args);
|
|
167
173
|
this.recordExecution(middleware.metadata.id, startTime, true);
|
|
168
174
|
return result;
|
|
@@ -177,6 +183,9 @@ export class MiddlewareRegistry {
|
|
|
177
183
|
wrappedMiddleware.wrapStream = async (args) => {
|
|
178
184
|
const startTime = Date.now();
|
|
179
185
|
try {
|
|
186
|
+
if (!middleware.wrapStream) {
|
|
187
|
+
throw new Error("wrapStream method is required");
|
|
188
|
+
}
|
|
180
189
|
const result = await middleware.wrapStream(args);
|
|
181
190
|
this.recordExecution(middleware.metadata.id, startTime, true);
|
|
182
191
|
return result;
|
|
@@ -125,7 +125,7 @@ export declare function getAvailableProviders(): AIProviderName[];
|
|
|
125
125
|
/**
|
|
126
126
|
* Calculate estimated cost for a request
|
|
127
127
|
*/
|
|
128
|
-
export declare function calculateCost(model: ModelInfo,
|
|
128
|
+
export declare function calculateCost(model: ModelInfo, input: number, output: number): number;
|
|
129
129
|
/**
|
|
130
130
|
* Format model for display
|
|
131
131
|
*/
|
|
@@ -445,9 +445,9 @@ export function getAvailableProviders() {
|
|
|
445
445
|
/**
|
|
446
446
|
* Calculate estimated cost for a request
|
|
447
447
|
*/
|
|
448
|
-
export function calculateCost(model,
|
|
449
|
-
const inputCost = (
|
|
450
|
-
const outputCost = (
|
|
448
|
+
export function calculateCost(model, input, output) {
|
|
449
|
+
const inputCost = (input / 1000) * model.pricing.inputCostPer1K;
|
|
450
|
+
const outputCost = (output / 1000) * model.pricing.outputCostPer1K;
|
|
451
451
|
return inputCost + outputCost;
|
|
452
452
|
}
|
|
453
453
|
/**
|
|
@@ -76,7 +76,7 @@ export declare class ModelResolver {
|
|
|
76
76
|
/**
|
|
77
77
|
* Calculate cost comparison for models
|
|
78
78
|
*/
|
|
79
|
-
static calculateCostComparison(models: ModelInfo[],
|
|
79
|
+
static calculateCostComparison(models: ModelInfo[], input?: number, output?: number): Array<{
|
|
80
80
|
model: ModelInfo;
|
|
81
81
|
cost: number;
|
|
82
82
|
costPer1K: number;
|
|
@@ -160,11 +160,11 @@ export class ModelResolver {
|
|
|
160
160
|
/**
|
|
161
161
|
* Calculate cost comparison for models
|
|
162
162
|
*/
|
|
163
|
-
static calculateCostComparison(models,
|
|
163
|
+
static calculateCostComparison(models, input = 1000, output = 500) {
|
|
164
164
|
return models
|
|
165
165
|
.map((model) => ({
|
|
166
166
|
model,
|
|
167
|
-
cost: calculateCost(model,
|
|
167
|
+
cost: calculateCost(model, input, output),
|
|
168
168
|
costPer1K: model.pricing.inputCostPer1K + model.pricing.outputCostPer1K,
|
|
169
169
|
}))
|
|
170
170
|
.sort((a, b) => a.cost - b.cost);
|
package/dist/neurolink.d.ts
CHANGED
|
@@ -39,11 +39,9 @@ export interface MCPStatus {
|
|
|
39
39
|
error?: string;
|
|
40
40
|
[key: string]: unknown;
|
|
41
41
|
}
|
|
42
|
-
import type { ContextManagerConfig } from "./context/types.js";
|
|
43
42
|
export declare class NeuroLink {
|
|
44
43
|
private mcpInitialized;
|
|
45
44
|
private emitter;
|
|
46
|
-
private contextManager;
|
|
47
45
|
private autoDiscoveredServerInfos;
|
|
48
46
|
private externalServerManager;
|
|
49
47
|
private toolCircuitBreakers;
|
|
@@ -90,11 +88,71 @@ export declare class NeuroLink {
|
|
|
90
88
|
constructor(config?: {
|
|
91
89
|
conversationMemory?: Partial<ConversationMemoryConfig>;
|
|
92
90
|
});
|
|
91
|
+
/**
|
|
92
|
+
* Log constructor start with comprehensive environment analysis
|
|
93
|
+
*/
|
|
94
|
+
private logConstructorStart;
|
|
95
|
+
/**
|
|
96
|
+
* Initialize provider registry with security settings
|
|
97
|
+
*/
|
|
98
|
+
private initializeProviderRegistry;
|
|
99
|
+
/**
|
|
100
|
+
* Initialize conversation memory if enabled
|
|
101
|
+
*/
|
|
102
|
+
private initializeConversationMemory;
|
|
103
|
+
/**
|
|
104
|
+
* Initialize external server manager with event handlers
|
|
105
|
+
*/
|
|
106
|
+
private initializeExternalServerManager;
|
|
107
|
+
/**
|
|
108
|
+
* Setup event handlers for external server manager
|
|
109
|
+
*/
|
|
110
|
+
private setupExternalServerEventHandlers;
|
|
111
|
+
/**
|
|
112
|
+
* Log constructor completion with final state summary
|
|
113
|
+
*/
|
|
114
|
+
private logConstructorComplete;
|
|
93
115
|
/**
|
|
94
116
|
* Initialize MCP registry with enhanced error handling and resource cleanup
|
|
95
117
|
* Uses isolated async context to prevent hanging
|
|
96
118
|
*/
|
|
97
119
|
private initializeMCP;
|
|
120
|
+
/**
|
|
121
|
+
* Log MCP initialization start
|
|
122
|
+
*/
|
|
123
|
+
private logMCPInitStart;
|
|
124
|
+
/**
|
|
125
|
+
* Log MCP already initialized
|
|
126
|
+
*/
|
|
127
|
+
private logMCPAlreadyInitialized;
|
|
128
|
+
/**
|
|
129
|
+
* Import performance manager with error handling
|
|
130
|
+
*/
|
|
131
|
+
private importPerformanceManager;
|
|
132
|
+
/**
|
|
133
|
+
* Perform main MCP initialization logic
|
|
134
|
+
*/
|
|
135
|
+
private performMCPInitialization;
|
|
136
|
+
/**
|
|
137
|
+
* Initialize tool registry with timeout protection
|
|
138
|
+
*/
|
|
139
|
+
private initializeToolRegistryInternal;
|
|
140
|
+
/**
|
|
141
|
+
* Initialize provider registry
|
|
142
|
+
*/
|
|
143
|
+
private initializeProviderRegistryInternal;
|
|
144
|
+
/**
|
|
145
|
+
* Register direct tools server
|
|
146
|
+
*/
|
|
147
|
+
private registerDirectToolsServerInternal;
|
|
148
|
+
/**
|
|
149
|
+
* Load MCP configuration from .mcp-config.json
|
|
150
|
+
*/
|
|
151
|
+
private loadMCPConfigurationInternal;
|
|
152
|
+
/**
|
|
153
|
+
* Log MCP initialization completion
|
|
154
|
+
*/
|
|
155
|
+
private logMCPInitComplete;
|
|
98
156
|
/**
|
|
99
157
|
* MAIN ENTRY POINT: Enhanced generate method with new function signature
|
|
100
158
|
* Replaces both generateText and legacy methods
|
|
@@ -107,13 +165,6 @@ export declare class NeuroLink {
|
|
|
107
165
|
* @returns The original prompt text as a string.
|
|
108
166
|
*/
|
|
109
167
|
private _extractOriginalPrompt;
|
|
110
|
-
/**
|
|
111
|
-
* Enables automatic context summarization for the NeuroLink instance.
|
|
112
|
-
* Once enabled, the instance will maintain conversation history and
|
|
113
|
-
* automatically summarize it when it exceeds token limits.
|
|
114
|
-
* @param config Optional configuration to override default summarization settings.
|
|
115
|
-
*/
|
|
116
|
-
enableContextSummarization(config?: Partial<ContextManagerConfig>): void;
|
|
117
168
|
/**
|
|
118
169
|
* Generate AI content using the best available provider with MCP tool integration.
|
|
119
170
|
* This is the primary method for text generation with full feature support.
|
|
@@ -179,6 +230,26 @@ export declare class NeuroLink {
|
|
|
179
230
|
* 5. Store conversation turn for future context
|
|
180
231
|
*/
|
|
181
232
|
private generateTextInternal;
|
|
233
|
+
/**
|
|
234
|
+
* Log generateTextInternal start with comprehensive analysis
|
|
235
|
+
*/
|
|
236
|
+
private logGenerateTextInternalStart;
|
|
237
|
+
/**
|
|
238
|
+
* Emit generation start events
|
|
239
|
+
*/
|
|
240
|
+
private emitGenerationStartEvents;
|
|
241
|
+
/**
|
|
242
|
+
* Initialize conversation memory for generation
|
|
243
|
+
*/
|
|
244
|
+
private initializeConversationMemoryForGeneration;
|
|
245
|
+
/**
|
|
246
|
+
* Attempt MCP generation with retry logic
|
|
247
|
+
*/
|
|
248
|
+
private attemptMCPGeneration;
|
|
249
|
+
/**
|
|
250
|
+
* Perform MCP generation with retry logic
|
|
251
|
+
*/
|
|
252
|
+
private performMCPGenerationRetries;
|
|
182
253
|
/**
|
|
183
254
|
* Try MCP-enhanced generation (no fallback recursion)
|
|
184
255
|
*/
|
|
@@ -257,6 +328,42 @@ export declare class NeuroLink {
|
|
|
257
328
|
* @throws {Error} When conversation memory operations fail (if enabled)
|
|
258
329
|
*/
|
|
259
330
|
stream(options: StreamOptions): Promise<StreamResult>;
|
|
331
|
+
/**
|
|
332
|
+
* Log stream entry point with comprehensive analysis
|
|
333
|
+
*/
|
|
334
|
+
private logStreamEntryPoint;
|
|
335
|
+
/**
|
|
336
|
+
* Log performance baseline
|
|
337
|
+
*/
|
|
338
|
+
private logPerformanceBaseline;
|
|
339
|
+
/**
|
|
340
|
+
* Validate stream input with comprehensive error reporting
|
|
341
|
+
*/
|
|
342
|
+
private validateStreamInput;
|
|
343
|
+
/**
|
|
344
|
+
* Emit stream start events
|
|
345
|
+
*/
|
|
346
|
+
private emitStreamStartEvents;
|
|
347
|
+
/**
|
|
348
|
+
* Create MCP stream
|
|
349
|
+
*/
|
|
350
|
+
private createMCPStream;
|
|
351
|
+
/**
|
|
352
|
+
* Process stream result
|
|
353
|
+
*/
|
|
354
|
+
private processStreamResult;
|
|
355
|
+
/**
|
|
356
|
+
* Emit stream end events
|
|
357
|
+
*/
|
|
358
|
+
private emitStreamEndEvents;
|
|
359
|
+
/**
|
|
360
|
+
* Create stream response
|
|
361
|
+
*/
|
|
362
|
+
private createStreamResponse;
|
|
363
|
+
/**
|
|
364
|
+
* Handle stream error with fallback
|
|
365
|
+
*/
|
|
366
|
+
private handleStreamError;
|
|
260
367
|
/**
|
|
261
368
|
* Get the EventEmitter instance to listen to NeuroLink events for real-time monitoring and debugging.
|
|
262
369
|
* This method provides access to the internal event system that emits events during AI generation,
|