@juspay/neurolink 8.3.0 → 8.4.1

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 (123) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +1 -0
  3. package/dist/adapters/providerImageAdapter.d.ts +1 -1
  4. package/dist/adapters/providerImageAdapter.js +62 -0
  5. package/dist/agent/directTools.d.ts +0 -72
  6. package/dist/agent/directTools.js +3 -74
  7. package/dist/cli/commands/config.d.ts +18 -18
  8. package/dist/cli/factories/commandFactory.js +1 -0
  9. package/dist/constants/enums.d.ts +1 -0
  10. package/dist/constants/enums.js +3 -1
  11. package/dist/constants/tokens.d.ts +3 -0
  12. package/dist/constants/tokens.js +3 -0
  13. package/dist/core/baseProvider.d.ts +56 -53
  14. package/dist/core/baseProvider.js +107 -1095
  15. package/dist/core/constants.d.ts +3 -0
  16. package/dist/core/constants.js +6 -3
  17. package/dist/core/modelConfiguration.js +10 -0
  18. package/dist/core/modules/GenerationHandler.d.ts +63 -0
  19. package/dist/core/modules/GenerationHandler.js +230 -0
  20. package/dist/core/modules/MessageBuilder.d.ts +39 -0
  21. package/dist/core/modules/MessageBuilder.js +179 -0
  22. package/dist/core/modules/StreamHandler.d.ts +52 -0
  23. package/dist/core/modules/StreamHandler.js +103 -0
  24. package/dist/core/modules/TelemetryHandler.d.ts +64 -0
  25. package/dist/core/modules/TelemetryHandler.js +170 -0
  26. package/dist/core/modules/ToolsManager.d.ts +98 -0
  27. package/dist/core/modules/ToolsManager.js +521 -0
  28. package/dist/core/modules/Utilities.d.ts +88 -0
  29. package/dist/core/modules/Utilities.js +329 -0
  30. package/dist/factories/providerRegistry.js +1 -1
  31. package/dist/lib/adapters/providerImageAdapter.d.ts +1 -1
  32. package/dist/lib/adapters/providerImageAdapter.js +62 -0
  33. package/dist/lib/agent/directTools.d.ts +0 -72
  34. package/dist/lib/agent/directTools.js +3 -74
  35. package/dist/lib/constants/enums.d.ts +1 -0
  36. package/dist/lib/constants/enums.js +3 -1
  37. package/dist/lib/constants/tokens.d.ts +3 -0
  38. package/dist/lib/constants/tokens.js +3 -0
  39. package/dist/lib/core/baseProvider.d.ts +56 -53
  40. package/dist/lib/core/baseProvider.js +107 -1095
  41. package/dist/lib/core/constants.d.ts +3 -0
  42. package/dist/lib/core/constants.js +6 -3
  43. package/dist/lib/core/modelConfiguration.js +10 -0
  44. package/dist/lib/core/modules/GenerationHandler.d.ts +63 -0
  45. package/dist/lib/core/modules/GenerationHandler.js +231 -0
  46. package/dist/lib/core/modules/MessageBuilder.d.ts +39 -0
  47. package/dist/lib/core/modules/MessageBuilder.js +180 -0
  48. package/dist/lib/core/modules/StreamHandler.d.ts +52 -0
  49. package/dist/lib/core/modules/StreamHandler.js +104 -0
  50. package/dist/lib/core/modules/TelemetryHandler.d.ts +64 -0
  51. package/dist/lib/core/modules/TelemetryHandler.js +171 -0
  52. package/dist/lib/core/modules/ToolsManager.d.ts +98 -0
  53. package/dist/lib/core/modules/ToolsManager.js +522 -0
  54. package/dist/lib/core/modules/Utilities.d.ts +88 -0
  55. package/dist/lib/core/modules/Utilities.js +330 -0
  56. package/dist/lib/factories/providerRegistry.js +1 -1
  57. package/dist/lib/mcp/servers/agent/directToolsServer.js +0 -1
  58. package/dist/lib/memory/mem0Initializer.d.ts +32 -1
  59. package/dist/lib/memory/mem0Initializer.js +55 -2
  60. package/dist/lib/models/modelRegistry.js +44 -0
  61. package/dist/lib/neurolink.d.ts +1 -1
  62. package/dist/lib/neurolink.js +43 -10
  63. package/dist/lib/providers/amazonBedrock.js +59 -10
  64. package/dist/lib/providers/anthropic.js +2 -30
  65. package/dist/lib/providers/azureOpenai.js +2 -24
  66. package/dist/lib/providers/googleAiStudio.js +2 -24
  67. package/dist/lib/providers/googleVertex.js +2 -45
  68. package/dist/lib/providers/huggingFace.js +3 -31
  69. package/dist/lib/providers/litellm.d.ts +1 -1
  70. package/dist/lib/providers/litellm.js +110 -44
  71. package/dist/lib/providers/mistral.js +5 -32
  72. package/dist/lib/providers/ollama.d.ts +1 -0
  73. package/dist/lib/providers/ollama.js +476 -129
  74. package/dist/lib/providers/openAI.js +2 -28
  75. package/dist/lib/providers/openaiCompatible.js +3 -31
  76. package/dist/lib/types/content.d.ts +16 -113
  77. package/dist/lib/types/content.js +16 -2
  78. package/dist/lib/types/conversation.d.ts +3 -17
  79. package/dist/lib/types/generateTypes.d.ts +2 -2
  80. package/dist/lib/types/index.d.ts +2 -0
  81. package/dist/lib/types/index.js +2 -0
  82. package/dist/lib/types/multimodal.d.ts +282 -0
  83. package/dist/lib/types/multimodal.js +101 -0
  84. package/dist/lib/types/streamTypes.d.ts +2 -2
  85. package/dist/lib/utils/imageProcessor.d.ts +1 -1
  86. package/dist/lib/utils/messageBuilder.js +25 -2
  87. package/dist/lib/utils/multimodalOptionsBuilder.d.ts +1 -1
  88. package/dist/lib/utils/pdfProcessor.d.ts +9 -0
  89. package/dist/lib/utils/pdfProcessor.js +67 -9
  90. package/dist/mcp/servers/agent/directToolsServer.js +0 -1
  91. package/dist/memory/mem0Initializer.d.ts +32 -1
  92. package/dist/memory/mem0Initializer.js +55 -2
  93. package/dist/models/modelRegistry.js +44 -0
  94. package/dist/neurolink.d.ts +1 -1
  95. package/dist/neurolink.js +43 -10
  96. package/dist/providers/amazonBedrock.js +59 -10
  97. package/dist/providers/anthropic.js +2 -30
  98. package/dist/providers/azureOpenai.js +2 -24
  99. package/dist/providers/googleAiStudio.js +2 -24
  100. package/dist/providers/googleVertex.js +2 -45
  101. package/dist/providers/huggingFace.js +3 -31
  102. package/dist/providers/litellm.d.ts +1 -1
  103. package/dist/providers/litellm.js +110 -44
  104. package/dist/providers/mistral.js +5 -32
  105. package/dist/providers/ollama.d.ts +1 -0
  106. package/dist/providers/ollama.js +476 -129
  107. package/dist/providers/openAI.js +2 -28
  108. package/dist/providers/openaiCompatible.js +3 -31
  109. package/dist/types/content.d.ts +16 -113
  110. package/dist/types/content.js +16 -2
  111. package/dist/types/conversation.d.ts +3 -17
  112. package/dist/types/generateTypes.d.ts +2 -2
  113. package/dist/types/index.d.ts +2 -0
  114. package/dist/types/index.js +2 -0
  115. package/dist/types/multimodal.d.ts +282 -0
  116. package/dist/types/multimodal.js +100 -0
  117. package/dist/types/streamTypes.d.ts +2 -2
  118. package/dist/utils/imageProcessor.d.ts +1 -1
  119. package/dist/utils/messageBuilder.js +25 -2
  120. package/dist/utils/multimodalOptionsBuilder.d.ts +1 -1
  121. package/dist/utils/pdfProcessor.d.ts +9 -0
  122. package/dist/utils/pdfProcessor.js +67 -9
  123. package/package.json +5 -2
@@ -1,5 +1,5 @@
1
1
  import type { ValidationSchema } from "../types/typeAliases.js";
2
- import type { Tool, LanguageModelV1 } from "ai";
2
+ import type { Tool, LanguageModelV1, CoreMessage } from "ai";
3
3
  import type { AIProvider, TextGenerationOptions, TextGenerationResult, EnhancedGenerateResult, AnalyticsData } from "../types/index.js";
4
4
  import { AIProviderName } from "../constants/enums.js";
5
5
  import type { EvaluationData } from "../index.js";
@@ -23,6 +23,12 @@ export declare abstract class BaseProvider implements AIProvider {
23
23
  protected sessionId?: string;
24
24
  protected userId?: string;
25
25
  protected neurolink?: NeuroLink;
26
+ private readonly messageBuilder;
27
+ private readonly streamHandler;
28
+ private readonly generationHandler;
29
+ private readonly telemetryHandler;
30
+ private readonly utilities;
31
+ private readonly toolsManager;
26
32
  constructor(modelName?: string, providerName?: AIProviderName, neurolink?: NeuroLink, middleware?: MiddlewareFactoryOptions);
27
33
  /**
28
34
  * Check if this provider supports tool/function calling
@@ -40,32 +46,40 @@ export declare abstract class BaseProvider implements AIProvider {
40
46
  */
41
47
  private prepareGenerationContext;
42
48
  /**
43
- * Build messages array for generation
49
+ * Build messages array for generation - delegated to MessageBuilder
44
50
  */
45
51
  private buildMessages;
46
52
  /**
47
- * Execute the generation with AI SDK
53
+ * Build messages array for streaming operations - delegated to MessageBuilder
54
+ * This is a protected helper method that providers can use to build messages
55
+ * with automatic multimodal detection, eliminating code duplication
56
+ *
57
+ * @param options - Stream options or text generation options
58
+ * @returns Promise resolving to CoreMessage array ready for AI SDK
59
+ */
60
+ protected buildMessagesForStream(options: StreamOptions | TextGenerationOptions): Promise<CoreMessage[]>;
61
+ /**
62
+ * Execute the generation with AI SDK - delegated to GenerationHandler
48
63
  */
49
64
  private executeGeneration;
50
65
  /**
51
- * Log generation completion information
66
+ * Log generation completion information - delegated to GenerationHandler
52
67
  */
53
68
  private logGenerationComplete;
54
69
  /**
55
- * Record performance metrics
70
+ * Record performance metrics - delegated to TelemetryHandler
56
71
  */
57
72
  private recordPerformanceMetrics;
58
73
  /**
59
- * Extract tool information from generation result
74
+ * Extract tool information from generation result - delegated to GenerationHandler
60
75
  */
61
76
  private extractToolInformation;
62
77
  /**
63
- * Format the enhanced result
78
+ * Format the enhanced result - delegated to GenerationHandler
64
79
  */
65
80
  private formatEnhancedResult;
66
81
  /**
67
- * Analyze AI response structure and log detailed debugging information
68
- * Extracted from generate method to reduce complexity
82
+ * Analyze AI response structure and log detailed debugging information - delegated to GenerationHandler
69
83
  */
70
84
  private analyzeAIResponse;
71
85
  /**
@@ -109,63 +123,35 @@ export declare abstract class BaseProvider implements AIProvider {
109
123
  */
110
124
  protected getAISDKModelWithMiddleware(options?: TextGenerationOptions | StreamOptions): Promise<LanguageModelV1>;
111
125
  /**
112
- * Extract middleware options from generation options. This is the single
113
- * source of truth for deciding if middleware should be applied.
126
+ * Extract middleware options - delegated to Utilities
114
127
  */
115
128
  private extractMiddlewareOptions;
116
129
  /**
117
- * Check if a schema is a Zod schema
130
+ * Check if a schema is a Zod schema - delegated to Utilities
118
131
  */
119
132
  private isZodSchema;
120
133
  /**
121
- * Convert tool execution result from MCP format to standard format
122
- * Handles tool failures gracefully to prevent stream termination
134
+ * Convert tool execution result - delegated to Utilities
123
135
  */
124
136
  private convertToolResult;
125
137
  /**
126
- * Create a custom tool from tool definition
127
- */
128
- private createCustomToolFromDefinition;
129
- /**
130
- * Process direct tools with event emission wrapping
131
- */
132
- private processDirectTools;
133
- /**
134
- * Process custom tools from setupToolExecutor
135
- */
136
- private processCustomTools;
137
- /**
138
- * Recursively fix JSON Schema for OpenAI strict mode compatibility
139
- * OpenAI requires additionalProperties: false at ALL levels and preserves required array
138
+ * Fix JSON Schema for OpenAI strict mode - delegated to Utilities
140
139
  */
141
140
  private fixSchemaForOpenAIStrictMode;
142
141
  /**
143
- * Create an external MCP tool
144
- */
145
- private createExternalMCPTool;
146
- /**
147
- * Process external MCP tools
148
- */
149
- private processExternalMCPTools;
150
- /**
151
- * Process MCP tools integration
152
- */
153
- private processMCPTools;
154
- /**
155
- * Get all available tools - direct tools are ALWAYS available
156
- * MCP tools are added when available (without blocking)
142
+ * Get all available tools - delegated to ToolsManager
157
143
  */
158
144
  protected getAllTools(): Promise<Record<string, Tool>>;
159
145
  /**
160
- * Calculate actual cost based on token usage and provider configuration
146
+ * Calculate actual cost - delegated to TelemetryHandler
161
147
  */
162
148
  private calculateActualCost;
163
149
  /**
164
- * Create a permissive Zod schema that accepts all parameters as-is
150
+ * Create a permissive Zod schema - delegated to Utilities
165
151
  */
166
152
  private createPermissiveZodSchema;
167
153
  /**
168
- * Set session context for MCP tools
154
+ * Set session context for MCP tools - delegated to ToolsManager
169
155
  */
170
156
  setSessionContext(sessionId?: string, userId?: string): void;
171
157
  /**
@@ -181,11 +167,11 @@ export declare abstract class BaseProvider implements AIProvider {
181
167
  operationType?: string;
182
168
  }): Promise<T>;
183
169
  /**
184
- * Validate stream options - consolidates validation from 7/10 providers
170
+ * Validate stream options - delegated to StreamHandler
185
171
  */
186
172
  protected validateStreamOptions(options: StreamOptions): void;
187
173
  /**
188
- * Create text stream transformation - consolidates identical logic from 7/10 providers
174
+ * Create text stream transformation - delegated to StreamHandler
189
175
  */
190
176
  protected createTextStream(result: {
191
177
  textStream: AsyncIterable<string>;
@@ -193,22 +179,21 @@ export declare abstract class BaseProvider implements AIProvider {
193
179
  content: string;
194
180
  }>;
195
181
  /**
196
- * Create standardized stream result - consolidates result structure
182
+ * Create standardized stream result - delegated to StreamHandler
197
183
  */
198
184
  protected createStreamResult(stream: AsyncGenerator<{
199
185
  content: string;
200
186
  }>, additionalProps?: Partial<StreamResult>): StreamResult;
201
187
  /**
202
- * Create stream analytics - consolidates analytics from 4/10 providers
188
+ * Create stream analytics - delegated to StreamHandler
203
189
  */
204
190
  protected createStreamAnalytics(result: UnknownRecord, startTime: number, options: StreamOptions): Promise<UnknownRecord | undefined>;
205
191
  /**
206
- * Handle common error patterns - consolidates error handling from multiple providers
192
+ * Handle common error patterns - delegated to Utilities
207
193
  */
208
194
  protected handleCommonErrors(error: unknown): Error | null;
209
195
  /**
210
- * Set up tool executor for a provider to enable actual tool execution
211
- * Consolidates identical setupToolExecutor logic from neurolink.ts (used in 4 places)
196
+ * Set up tool executor - delegated to ToolsManager
212
197
  * @param sdk - The NeuroLinkSDK instance for tool execution
213
198
  * @param functionTag - Function name for logging
214
199
  */
@@ -216,18 +201,36 @@ export declare abstract class BaseProvider implements AIProvider {
216
201
  customTools: Map<string, unknown>;
217
202
  executeTool: (toolName: string, params: unknown) => Promise<unknown>;
218
203
  }, functionTag: string): void;
204
+ /**
205
+ * Normalize text generation options - delegated to Utilities
206
+ */
219
207
  protected normalizeTextOptions(optionsOrPrompt: TextGenerationOptions | string): TextGenerationOptions;
208
+ /**
209
+ * Normalize stream options - delegated to Utilities
210
+ */
220
211
  protected normalizeStreamOptions(optionsOrPrompt: StreamOptions | string): StreamOptions;
221
212
  protected enhanceResult(result: EnhancedGenerateResult, options: TextGenerationOptions, startTime: number): Promise<EnhancedGenerateResult>;
213
+ /**
214
+ * Create analytics - delegated to TelemetryHandler
215
+ */
222
216
  protected createAnalytics(result: EnhancedGenerateResult, responseTime: number, options: TextGenerationOptions): Promise<AnalyticsData>;
217
+ /**
218
+ * Create evaluation - delegated to TelemetryHandler
219
+ */
223
220
  protected createEvaluation(result: EnhancedGenerateResult, options: TextGenerationOptions): Promise<EvaluationData>;
221
+ /**
222
+ * Validate text generation options - delegated to Utilities
223
+ */
224
224
  protected validateOptions(options: TextGenerationOptions): void;
225
+ /**
226
+ * Get provider information - delegated to Utilities
227
+ */
225
228
  protected getProviderInfo(): {
226
229
  provider: string;
227
230
  model: string;
228
231
  };
229
232
  /**
230
- * Get timeout value in milliseconds
233
+ * Get timeout value in milliseconds - delegated to Utilities
231
234
  */
232
235
  getTimeout(options: TextGenerationOptions | StreamOptions): number;
233
236
  /**