@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.
Files changed (93) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cli/commands/config.d.ts +18 -18
  3. package/dist/cli/factories/commandFactory.d.ts +24 -0
  4. package/dist/cli/factories/commandFactory.js +297 -245
  5. package/dist/core/baseProvider.d.ts +44 -3
  6. package/dist/core/baseProvider.js +729 -352
  7. package/dist/core/constants.d.ts +2 -30
  8. package/dist/core/constants.js +15 -43
  9. package/dist/core/redisConversationMemoryManager.d.ts +98 -15
  10. package/dist/core/redisConversationMemoryManager.js +665 -203
  11. package/dist/factories/providerFactory.js +23 -6
  12. package/dist/index.d.ts +3 -2
  13. package/dist/index.js +4 -3
  14. package/dist/lib/core/baseProvider.d.ts +44 -3
  15. package/dist/lib/core/baseProvider.js +729 -352
  16. package/dist/lib/core/constants.d.ts +2 -30
  17. package/dist/lib/core/constants.js +15 -43
  18. package/dist/lib/core/redisConversationMemoryManager.d.ts +98 -15
  19. package/dist/lib/core/redisConversationMemoryManager.js +665 -203
  20. package/dist/lib/factories/providerFactory.js +23 -6
  21. package/dist/lib/index.d.ts +3 -2
  22. package/dist/lib/index.js +4 -3
  23. package/dist/lib/mcp/externalServerManager.js +2 -2
  24. package/dist/lib/mcp/registry.js +2 -2
  25. package/dist/lib/mcp/servers/agent/directToolsServer.js +19 -10
  26. package/dist/lib/mcp/toolRegistry.js +4 -8
  27. package/dist/lib/neurolink.d.ts +95 -28
  28. package/dist/lib/neurolink.js +479 -719
  29. package/dist/lib/providers/amazonBedrock.js +2 -2
  30. package/dist/lib/providers/anthropic.js +8 -0
  31. package/dist/lib/providers/anthropicBaseProvider.js +8 -0
  32. package/dist/lib/providers/azureOpenai.js +8 -0
  33. package/dist/lib/providers/googleAiStudio.js +8 -0
  34. package/dist/lib/providers/googleVertex.d.ts +3 -23
  35. package/dist/lib/providers/googleVertex.js +24 -342
  36. package/dist/lib/providers/huggingFace.js +8 -0
  37. package/dist/lib/providers/litellm.js +8 -0
  38. package/dist/lib/providers/mistral.js +8 -0
  39. package/dist/lib/providers/openAI.d.ts +23 -0
  40. package/dist/lib/providers/openAI.js +323 -6
  41. package/dist/lib/providers/openaiCompatible.js +8 -0
  42. package/dist/lib/providers/sagemaker/language-model.d.ts +2 -2
  43. package/dist/lib/sdk/toolRegistration.js +18 -1
  44. package/dist/lib/types/common.d.ts +98 -0
  45. package/dist/lib/types/conversation.d.ts +52 -2
  46. package/dist/lib/types/streamTypes.d.ts +13 -6
  47. package/dist/lib/types/typeAliases.d.ts +3 -2
  48. package/dist/lib/utils/conversationMemory.js +3 -1
  49. package/dist/lib/utils/messageBuilder.d.ts +10 -2
  50. package/dist/lib/utils/messageBuilder.js +22 -1
  51. package/dist/lib/utils/parameterValidation.js +6 -25
  52. package/dist/lib/utils/promptRedaction.js +4 -4
  53. package/dist/lib/utils/redis.d.ts +10 -6
  54. package/dist/lib/utils/redis.js +71 -70
  55. package/dist/lib/utils/schemaConversion.d.ts +14 -0
  56. package/dist/lib/utils/schemaConversion.js +140 -0
  57. package/dist/lib/utils/transformationUtils.js +143 -5
  58. package/dist/mcp/externalServerManager.js +2 -2
  59. package/dist/mcp/registry.js +2 -2
  60. package/dist/mcp/servers/agent/directToolsServer.js +19 -10
  61. package/dist/mcp/toolRegistry.js +4 -8
  62. package/dist/neurolink.d.ts +95 -28
  63. package/dist/neurolink.js +479 -719
  64. package/dist/providers/amazonBedrock.js +2 -2
  65. package/dist/providers/anthropic.js +8 -0
  66. package/dist/providers/anthropicBaseProvider.js +8 -0
  67. package/dist/providers/azureOpenai.js +8 -0
  68. package/dist/providers/googleAiStudio.js +8 -0
  69. package/dist/providers/googleVertex.d.ts +3 -23
  70. package/dist/providers/googleVertex.js +24 -342
  71. package/dist/providers/huggingFace.js +8 -0
  72. package/dist/providers/litellm.js +8 -0
  73. package/dist/providers/mistral.js +8 -0
  74. package/dist/providers/openAI.d.ts +23 -0
  75. package/dist/providers/openAI.js +323 -6
  76. package/dist/providers/openaiCompatible.js +8 -0
  77. package/dist/providers/sagemaker/language-model.d.ts +2 -2
  78. package/dist/sdk/toolRegistration.js +18 -1
  79. package/dist/types/common.d.ts +98 -0
  80. package/dist/types/conversation.d.ts +52 -2
  81. package/dist/types/streamTypes.d.ts +13 -6
  82. package/dist/types/typeAliases.d.ts +3 -2
  83. package/dist/utils/conversationMemory.js +3 -1
  84. package/dist/utils/messageBuilder.d.ts +10 -2
  85. package/dist/utils/messageBuilder.js +22 -1
  86. package/dist/utils/parameterValidation.js +6 -25
  87. package/dist/utils/promptRedaction.js +4 -4
  88. package/dist/utils/redis.d.ts +10 -6
  89. package/dist/utils/redis.js +71 -70
  90. package/dist/utils/schemaConversion.d.ts +14 -0
  91. package/dist/utils/schemaConversion.js +140 -0
  92. package/dist/utils/transformationUtils.js +143 -5
  93. package/package.json +3 -2
@@ -49,16 +49,33 @@ export class ProviderFactory {
49
49
  model = model || registration.defaultModel;
50
50
  }
51
51
  try {
52
+ if (typeof registration.constructor !== "function") {
53
+ throw new Error(`Invalid constructor for provider ${providerName}: not a function`);
54
+ }
52
55
  let result;
53
56
  try {
54
- // Try as async factory function first (most providers are async functions)
55
- result = await registration.constructor(model, providerName, sdk);
57
+ const factoryResult = registration.constructor(model, providerName, sdk);
58
+ // Handle both sync and async results
59
+ result =
60
+ factoryResult instanceof Promise
61
+ ? await factoryResult
62
+ : factoryResult;
56
63
  }
57
- catch {
58
- // Fallback to constructor - ensure parameters are maintained
59
- result = new registration.constructor(model, providerName, sdk);
64
+ catch (factoryError) {
65
+ if (registration.constructor.prototype &&
66
+ registration.constructor.prototype.constructor ===
67
+ registration.constructor) {
68
+ try {
69
+ result = new registration.constructor(model, providerName, sdk);
70
+ }
71
+ catch (constructorError) {
72
+ throw new Error(`Both factory function and constructor failed. Factory error: ${factoryError}. Constructor error: ${constructorError}`);
73
+ }
74
+ }
75
+ else {
76
+ throw factoryError;
77
+ }
60
78
  }
61
- // Return result (no need to await again if already awaited in try block)
62
79
  return result;
63
80
  }
64
81
  catch (error) {
package/dist/index.d.ts CHANGED
@@ -17,7 +17,8 @@ export { BedrockModels, OpenAIModels, VertexModels, DEFAULT_PROVIDER_CONFIGS, }
17
17
  export { getBestProvider, getAvailableProviders, isValidProvider, } from "./utils/providerUtils.js";
18
18
  export { dynamicModelProvider } from "./core/dynamicModels.js";
19
19
  export type { DynamicModelConfig, ModelRegistry } from "./types/modelTypes.js";
20
- export { NeuroLink } from "./neurolink.js";
20
+ import { NeuroLink } from "./neurolink.js";
21
+ export { NeuroLink };
21
22
  export type { ProviderStatus, MCPStatus } from "./neurolink.js";
22
23
  export type { MCPServerInfo } from "./types/mcpTypes.js";
23
24
  export type { NeuroLinkMiddleware, MiddlewareContext, MiddlewareFactoryOptions, MiddlewarePreset, MiddlewareConfig, } from "./types/middlewareTypes.js";
@@ -102,4 +103,4 @@ export type { TextGenerationOptions, TextGenerationResult, AnalyticsData, Evalua
102
103
  * console.log(result.content);
103
104
  * ```
104
105
  */
105
- export declare function generateText(options: import("./types/index.js").TextGenerationOptions): Promise<import("./types/index.js").TextGenerationResult>;
106
+ export declare function generateText(options: import("./core/types.js").TextGenerationOptions): Promise<import("./core/types.js").TextGenerationResult>;
package/dist/index.js CHANGED
@@ -17,7 +17,8 @@ export { getBestProvider, getAvailableProviders, isValidProvider, } from "./util
17
17
  // Dynamic Models exports
18
18
  export { dynamicModelProvider } from "./core/dynamicModels.js";
19
19
  // Main NeuroLink wrapper class and diagnostic types
20
- export { NeuroLink } from "./neurolink.js";
20
+ import { NeuroLink } from "./neurolink.js";
21
+ export { NeuroLink };
21
22
  export { MiddlewareFactory } from "./middleware/factory.js";
22
23
  // Version
23
24
  export const VERSION = "1.0.0";
@@ -127,7 +128,7 @@ export function getTelemetryStatus() {
127
128
  * ```
128
129
  */
129
130
  export async function generateText(options) {
130
- // Import neurolink instance to avoid circular dependencies
131
- const { neurolink } = await import("./neurolink.js");
131
+ // Create instance on-demand without auto-instantiation
132
+ const neurolink = new NeuroLink();
132
133
  return await neurolink.generateText(options);
133
134
  }
@@ -34,6 +34,39 @@ export declare abstract class BaseProvider implements AIProvider {
34
34
  * When tools are involved, falls back to generate() with synthetic streaming
35
35
  */
36
36
  stream(optionsOrPrompt: StreamOptions | string, analysisSchema?: ValidationSchema): Promise<StreamResult>;
37
+ /**
38
+ * Prepare generation context including tools and model
39
+ */
40
+ private prepareGenerationContext;
41
+ /**
42
+ * Build messages array for generation
43
+ */
44
+ private buildMessages;
45
+ /**
46
+ * Execute the generation with AI SDK
47
+ */
48
+ private executeGeneration;
49
+ /**
50
+ * Log generation completion information
51
+ */
52
+ private logGenerationComplete;
53
+ /**
54
+ * Record performance metrics
55
+ */
56
+ private recordPerformanceMetrics;
57
+ /**
58
+ * Extract tool information from generation result
59
+ */
60
+ private extractToolInformation;
61
+ /**
62
+ * Format the enhanced result
63
+ */
64
+ private formatEnhancedResult;
65
+ /**
66
+ * Analyze AI response structure and log detailed debugging information
67
+ * Extracted from generate method to reduce complexity
68
+ */
69
+ private analyzeAIResponse;
37
70
  /**
38
71
  * Text generation method - implements AIProvider interface
39
72
  * Tools are always available unless explicitly disabled
@@ -85,12 +118,17 @@ export declare abstract class BaseProvider implements AIProvider {
85
118
  private isZodSchema;
86
119
  /**
87
120
  * Convert tool execution result from MCP format to standard format
121
+ * Handles tool failures gracefully to prevent stream termination
88
122
  */
89
123
  private convertToolResult;
90
124
  /**
91
125
  * Create a custom tool from tool definition
92
126
  */
93
127
  private createCustomToolFromDefinition;
128
+ /**
129
+ * Process direct tools with event emission wrapping
130
+ */
131
+ private processDirectTools;
94
132
  /**
95
133
  * Process custom tools from setupToolExecutor
96
134
  */
@@ -117,10 +155,9 @@ export declare abstract class BaseProvider implements AIProvider {
117
155
  */
118
156
  private calculateActualCost;
119
157
  /**
120
- * Convert MCP JSON Schema to Zod schema for AI SDK tools
121
- * Handles common MCP schema patterns safely
158
+ * Create a permissive Zod schema that accepts all parameters as-is
122
159
  */
123
- private convertMCPSchemaToZod;
160
+ private createPermissiveZodSchema;
124
161
  /**
125
162
  * Set session context for MCP tools
126
163
  */
@@ -187,6 +224,10 @@ export declare abstract class BaseProvider implements AIProvider {
187
224
  * Get timeout value in milliseconds
188
225
  */
189
226
  getTimeout(options: TextGenerationOptions | StreamOptions): number;
227
+ /**
228
+ * Check if tool executions should be stored and handle storage
229
+ */
230
+ protected handleToolExecutionStorage(toolCalls: unknown[], toolResults: unknown[], options: TextGenerationOptions | StreamOptions): Promise<void>;
190
231
  /**
191
232
  * Utility method to chunk large prompts into smaller pieces
192
233
  * @param prompt The prompt to chunk