@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.
Files changed (226) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cli/commands/config.d.ts +83 -83
  3. package/dist/cli/commands/mcp.js +39 -9
  4. package/dist/cli/commands/models.js +25 -21
  5. package/dist/cli/commands/ollama.js +2 -2
  6. package/dist/cli/factories/commandFactory.d.ts +8 -0
  7. package/dist/cli/factories/commandFactory.js +65 -65
  8. package/dist/cli/factories/ollamaCommandFactory.js +3 -1
  9. package/dist/cli/factories/sagemakerCommandFactory.js +3 -2
  10. package/dist/cli/index.d.ts +1 -1
  11. package/dist/cli/index.js +11 -11
  12. package/dist/cli/utils/envManager.js +5 -5
  13. package/dist/cli/utils/ollamaUtils.d.ts +12 -0
  14. package/dist/cli/utils/ollamaUtils.js +58 -42
  15. package/dist/config/configManager.js +5 -2
  16. package/dist/config/conversationMemoryConfig.js +5 -0
  17. package/dist/core/analytics.d.ts +2 -24
  18. package/dist/core/analytics.js +12 -17
  19. package/dist/core/baseProvider.d.ts +30 -1
  20. package/dist/core/baseProvider.js +180 -198
  21. package/dist/core/conversationMemoryManager.d.ts +9 -15
  22. package/dist/core/conversationMemoryManager.js +98 -57
  23. package/dist/core/dynamicModels.d.ts +4 -4
  24. package/dist/core/dynamicModels.js +7 -7
  25. package/dist/core/evaluation.d.ts +9 -9
  26. package/dist/core/evaluation.js +117 -65
  27. package/dist/core/evaluationProviders.d.ts +18 -2
  28. package/dist/core/evaluationProviders.js +15 -13
  29. package/dist/core/modelConfiguration.d.ts +63 -0
  30. package/dist/core/modelConfiguration.js +354 -290
  31. package/dist/core/streamAnalytics.d.ts +10 -5
  32. package/dist/core/streamAnalytics.js +10 -10
  33. package/dist/core/types.d.ts +22 -110
  34. package/dist/core/types.js +13 -0
  35. package/dist/factories/providerFactory.js +1 -1
  36. package/dist/index.d.ts +2 -1
  37. package/dist/lib/config/configManager.js +5 -2
  38. package/dist/lib/config/conversationMemoryConfig.js +5 -0
  39. package/dist/lib/core/analytics.d.ts +2 -24
  40. package/dist/lib/core/analytics.js +12 -17
  41. package/dist/lib/core/baseProvider.d.ts +30 -1
  42. package/dist/lib/core/baseProvider.js +180 -198
  43. package/dist/lib/core/conversationMemoryManager.d.ts +9 -15
  44. package/dist/lib/core/conversationMemoryManager.js +98 -57
  45. package/dist/lib/core/dynamicModels.js +7 -7
  46. package/dist/lib/core/evaluation.d.ts +9 -9
  47. package/dist/lib/core/evaluation.js +117 -65
  48. package/dist/lib/core/evaluationProviders.d.ts +18 -2
  49. package/dist/lib/core/evaluationProviders.js +15 -13
  50. package/dist/lib/core/modelConfiguration.d.ts +63 -0
  51. package/dist/lib/core/modelConfiguration.js +354 -290
  52. package/dist/lib/core/streamAnalytics.d.ts +10 -5
  53. package/dist/lib/core/streamAnalytics.js +10 -10
  54. package/dist/lib/core/types.d.ts +22 -110
  55. package/dist/lib/core/types.js +13 -0
  56. package/dist/lib/factories/providerFactory.js +1 -1
  57. package/dist/lib/index.d.ts +2 -1
  58. package/dist/lib/mcp/externalServerManager.js +15 -6
  59. package/dist/lib/mcp/factory.js +1 -1
  60. package/dist/lib/mcp/index.d.ts +1 -1
  61. package/dist/lib/mcp/index.js +1 -1
  62. package/dist/lib/mcp/mcpCircuitBreaker.js +5 -1
  63. package/dist/lib/mcp/mcpClientFactory.js +3 -0
  64. package/dist/lib/mcp/registry.d.ts +3 -3
  65. package/dist/lib/mcp/registry.js +3 -3
  66. package/dist/lib/mcp/servers/aiProviders/aiAnalysisTools.js +5 -5
  67. package/dist/lib/mcp/servers/aiProviders/aiWorkflowTools.js +6 -6
  68. package/dist/lib/mcp/servers/utilities/utilityServer.js +1 -1
  69. package/dist/lib/mcp/toolDiscoveryService.js +8 -2
  70. package/dist/lib/mcp/toolRegistry.js +4 -4
  71. package/dist/lib/middleware/builtin/analytics.js +4 -4
  72. package/dist/lib/middleware/builtin/guardrails.js +2 -2
  73. package/dist/lib/middleware/registry.js +11 -2
  74. package/dist/lib/models/modelRegistry.d.ts +1 -1
  75. package/dist/lib/models/modelRegistry.js +3 -3
  76. package/dist/lib/models/modelResolver.d.ts +1 -1
  77. package/dist/lib/models/modelResolver.js +2 -2
  78. package/dist/lib/neurolink.d.ts +116 -9
  79. package/dist/lib/neurolink.js +718 -956
  80. package/dist/lib/providers/amazonSagemaker.d.ts +1 -1
  81. package/dist/lib/providers/amazonSagemaker.js +12 -3
  82. package/dist/lib/providers/anthropic.d.ts +1 -1
  83. package/dist/lib/providers/anthropic.js +7 -6
  84. package/dist/lib/providers/anthropicBaseProvider.d.ts +1 -1
  85. package/dist/lib/providers/anthropicBaseProvider.js +4 -3
  86. package/dist/lib/providers/azureOpenai.d.ts +1 -1
  87. package/dist/lib/providers/azureOpenai.js +1 -1
  88. package/dist/lib/providers/googleAiStudio.d.ts +1 -1
  89. package/dist/lib/providers/googleAiStudio.js +2 -2
  90. package/dist/lib/providers/googleVertex.d.ts +40 -0
  91. package/dist/lib/providers/googleVertex.js +330 -274
  92. package/dist/lib/providers/huggingFace.js +1 -1
  93. package/dist/lib/providers/mistral.d.ts +1 -1
  94. package/dist/lib/providers/mistral.js +2 -2
  95. package/dist/lib/providers/ollama.d.ts +4 -0
  96. package/dist/lib/providers/ollama.js +38 -18
  97. package/dist/lib/providers/openAI.d.ts +1 -1
  98. package/dist/lib/providers/openAI.js +2 -2
  99. package/dist/lib/providers/sagemaker/adaptive-semaphore.js +7 -4
  100. package/dist/lib/providers/sagemaker/client.js +13 -3
  101. package/dist/lib/providers/sagemaker/config.js +5 -1
  102. package/dist/lib/providers/sagemaker/detection.js +19 -9
  103. package/dist/lib/providers/sagemaker/errors.d.ts +8 -1
  104. package/dist/lib/providers/sagemaker/errors.js +103 -20
  105. package/dist/lib/providers/sagemaker/language-model.d.ts +3 -3
  106. package/dist/lib/providers/sagemaker/language-model.js +4 -4
  107. package/dist/lib/providers/sagemaker/parsers.js +14 -6
  108. package/dist/lib/providers/sagemaker/streaming.js +14 -3
  109. package/dist/lib/providers/sagemaker/types.d.ts +1 -1
  110. package/dist/lib/proxy/awsProxyIntegration.js +1 -1
  111. package/dist/lib/sdk/toolRegistration.d.ts +1 -1
  112. package/dist/lib/types/cli.d.ts +80 -8
  113. package/dist/lib/types/contextTypes.js +2 -2
  114. package/dist/lib/types/conversationTypes.d.ts +10 -0
  115. package/dist/lib/types/generateTypes.d.ts +2 -5
  116. package/dist/lib/types/providers.d.ts +81 -19
  117. package/dist/lib/types/providers.js +6 -6
  118. package/dist/lib/types/streamTypes.d.ts +4 -6
  119. package/dist/lib/types/typeAliases.d.ts +1 -1
  120. package/dist/lib/utils/analyticsUtils.d.ts +33 -0
  121. package/dist/lib/utils/analyticsUtils.js +76 -0
  122. package/dist/lib/utils/conversationMemoryUtils.d.ts +1 -2
  123. package/dist/lib/utils/conversationMemoryUtils.js +6 -7
  124. package/dist/lib/utils/errorHandling.js +4 -1
  125. package/dist/lib/utils/evaluationUtils.d.ts +27 -0
  126. package/dist/lib/utils/evaluationUtils.js +131 -0
  127. package/dist/lib/utils/optionsUtils.js +10 -1
  128. package/dist/lib/utils/performance.d.ts +1 -1
  129. package/dist/lib/utils/performance.js +15 -3
  130. package/dist/lib/utils/providerHealth.d.ts +48 -0
  131. package/dist/lib/utils/providerHealth.js +199 -254
  132. package/dist/lib/utils/providerUtils.js +2 -2
  133. package/dist/lib/utils/timeout.js +8 -3
  134. package/dist/mcp/externalServerManager.js +15 -6
  135. package/dist/mcp/factory.js +1 -1
  136. package/dist/mcp/index.d.ts +1 -1
  137. package/dist/mcp/index.js +1 -1
  138. package/dist/mcp/mcpCircuitBreaker.js +5 -1
  139. package/dist/mcp/mcpClientFactory.js +3 -0
  140. package/dist/mcp/registry.d.ts +3 -3
  141. package/dist/mcp/registry.js +3 -3
  142. package/dist/mcp/servers/aiProviders/aiAnalysisTools.js +5 -5
  143. package/dist/mcp/servers/aiProviders/aiWorkflowTools.js +6 -6
  144. package/dist/mcp/servers/utilities/utilityServer.js +1 -1
  145. package/dist/mcp/toolDiscoveryService.js +8 -2
  146. package/dist/mcp/toolRegistry.js +4 -4
  147. package/dist/middleware/builtin/analytics.js +4 -4
  148. package/dist/middleware/builtin/guardrails.js +2 -2
  149. package/dist/middleware/registry.js +11 -2
  150. package/dist/models/modelRegistry.d.ts +1 -1
  151. package/dist/models/modelRegistry.js +3 -3
  152. package/dist/models/modelResolver.d.ts +1 -1
  153. package/dist/models/modelResolver.js +2 -2
  154. package/dist/neurolink.d.ts +116 -9
  155. package/dist/neurolink.js +718 -956
  156. package/dist/providers/amazonSagemaker.d.ts +1 -1
  157. package/dist/providers/amazonSagemaker.js +12 -3
  158. package/dist/providers/anthropic.d.ts +1 -1
  159. package/dist/providers/anthropic.js +7 -6
  160. package/dist/providers/anthropicBaseProvider.d.ts +1 -1
  161. package/dist/providers/anthropicBaseProvider.js +4 -3
  162. package/dist/providers/azureOpenai.d.ts +1 -1
  163. package/dist/providers/azureOpenai.js +1 -1
  164. package/dist/providers/googleAiStudio.d.ts +1 -1
  165. package/dist/providers/googleAiStudio.js +2 -2
  166. package/dist/providers/googleVertex.d.ts +40 -0
  167. package/dist/providers/googleVertex.js +330 -274
  168. package/dist/providers/huggingFace.js +1 -1
  169. package/dist/providers/mistral.d.ts +1 -1
  170. package/dist/providers/mistral.js +2 -2
  171. package/dist/providers/ollama.d.ts +4 -0
  172. package/dist/providers/ollama.js +38 -18
  173. package/dist/providers/openAI.d.ts +1 -1
  174. package/dist/providers/openAI.js +2 -2
  175. package/dist/providers/sagemaker/adaptive-semaphore.js +7 -4
  176. package/dist/providers/sagemaker/client.js +13 -3
  177. package/dist/providers/sagemaker/config.js +5 -1
  178. package/dist/providers/sagemaker/detection.js +19 -9
  179. package/dist/providers/sagemaker/errors.d.ts +8 -1
  180. package/dist/providers/sagemaker/errors.js +103 -20
  181. package/dist/providers/sagemaker/language-model.d.ts +3 -3
  182. package/dist/providers/sagemaker/language-model.js +4 -4
  183. package/dist/providers/sagemaker/parsers.js +14 -6
  184. package/dist/providers/sagemaker/streaming.js +14 -3
  185. package/dist/providers/sagemaker/types.d.ts +1 -1
  186. package/dist/proxy/awsProxyIntegration.js +1 -1
  187. package/dist/sdk/toolRegistration.d.ts +1 -1
  188. package/dist/types/cli.d.ts +80 -8
  189. package/dist/types/contextTypes.js +2 -2
  190. package/dist/types/conversationTypes.d.ts +10 -0
  191. package/dist/types/generateTypes.d.ts +2 -5
  192. package/dist/types/providers.d.ts +81 -19
  193. package/dist/types/providers.js +6 -6
  194. package/dist/types/streamTypes.d.ts +4 -6
  195. package/dist/types/typeAliases.d.ts +1 -1
  196. package/dist/utils/analyticsUtils.d.ts +33 -0
  197. package/dist/utils/analyticsUtils.js +76 -0
  198. package/dist/utils/conversationMemoryUtils.d.ts +1 -2
  199. package/dist/utils/conversationMemoryUtils.js +6 -7
  200. package/dist/utils/errorHandling.js +4 -1
  201. package/dist/utils/evaluationUtils.d.ts +27 -0
  202. package/dist/utils/evaluationUtils.js +131 -0
  203. package/dist/utils/optionsUtils.js +10 -1
  204. package/dist/utils/performance.d.ts +1 -1
  205. package/dist/utils/performance.js +15 -3
  206. package/dist/utils/providerHealth.d.ts +48 -0
  207. package/dist/utils/providerHealth.js +199 -254
  208. package/dist/utils/providerUtils.js +2 -2
  209. package/dist/utils/timeout.js +8 -3
  210. package/package.json +1 -1
  211. package/dist/context/ContextManager.d.ts +0 -28
  212. package/dist/context/ContextManager.js +0 -113
  213. package/dist/context/config.d.ts +0 -5
  214. package/dist/context/config.js +0 -42
  215. package/dist/context/types.d.ts +0 -20
  216. package/dist/context/types.js +0 -1
  217. package/dist/context/utils.d.ts +0 -7
  218. package/dist/context/utils.js +0 -8
  219. package/dist/lib/context/ContextManager.d.ts +0 -28
  220. package/dist/lib/context/ContextManager.js +0 -113
  221. package/dist/lib/context/config.d.ts +0 -5
  222. package/dist/lib/context/config.js +0 -42
  223. package/dist/lib/context/types.d.ts +0 -20
  224. package/dist/lib/context/types.js +0 -1
  225. package/dist/lib/context/utils.d.ts +0 -7
  226. package/dist/lib/context/utils.js +0 -8
@@ -135,9 +135,9 @@ export class MiddlewareRegistry {
135
135
  /**
136
136
  * Configure middleware with runtime configuration
137
137
  */
138
- configureMiddleware(middleware, config, globalConfig, context) {
138
+ configureMiddleware(middleware, config, globalConfig, _context) {
139
139
  // Merge configurations: global < middleware config < runtime config
140
- const mergedConfig = {
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, inputTokens: number, outputTokens: number): number;
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, inputTokens, outputTokens) {
449
- const inputCost = (inputTokens / 1000) * model.pricing.inputCostPer1K;
450
- const outputCost = (outputTokens / 1000) * model.pricing.outputCostPer1K;
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[], inputTokens?: number, outputTokens?: number): Array<{
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, inputTokens = 1000, outputTokens = 500) {
163
+ static calculateCostComparison(models, input = 1000, output = 500) {
164
164
  return models
165
165
  .map((model) => ({
166
166
  model,
167
- cost: calculateCost(model, inputTokens, outputTokens),
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);
@@ -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,