@juspay/neurolink 5.1.0 → 5.2.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 (166) hide show
  1. package/CHANGELOG.md +15 -9
  2. package/README.md +123 -126
  3. package/dist/agent/direct-tools.d.ts +6 -6
  4. package/dist/cli/commands/config.d.ts +3 -3
  5. package/dist/cli/commands/mcp.js +8 -7
  6. package/dist/cli/factories/command-factory.d.ts +4 -0
  7. package/dist/cli/factories/command-factory.js +57 -3
  8. package/dist/cli/index.js +87 -140
  9. package/dist/core/base-provider.d.ts +423 -0
  10. package/dist/core/base-provider.js +365 -0
  11. package/dist/core/constants.d.ts +1 -1
  12. package/dist/core/constants.js +1 -1
  13. package/dist/core/dynamic-models.d.ts +6 -6
  14. package/dist/core/evaluation.d.ts +19 -80
  15. package/dist/core/evaluation.js +185 -484
  16. package/dist/core/factory.d.ts +3 -3
  17. package/dist/core/factory.js +31 -91
  18. package/dist/core/service-registry.d.ts +47 -0
  19. package/dist/core/service-registry.js +112 -0
  20. package/dist/core/types.d.ts +8 -1
  21. package/dist/factories/compatibility-factory.js +1 -1
  22. package/dist/factories/provider-factory.d.ts +72 -0
  23. package/dist/factories/provider-factory.js +144 -0
  24. package/dist/factories/provider-registry.d.ts +38 -0
  25. package/dist/factories/provider-registry.js +107 -0
  26. package/dist/index.d.ts +4 -3
  27. package/dist/index.js +2 -4
  28. package/dist/lib/agent/direct-tools.d.ts +6 -6
  29. package/dist/lib/core/base-provider.d.ts +423 -0
  30. package/dist/lib/core/base-provider.js +365 -0
  31. package/dist/lib/core/constants.d.ts +1 -1
  32. package/dist/lib/core/constants.js +1 -1
  33. package/dist/lib/core/dynamic-models.d.ts +6 -6
  34. package/dist/lib/core/evaluation.d.ts +19 -80
  35. package/dist/lib/core/evaluation.js +185 -484
  36. package/dist/lib/core/factory.d.ts +3 -3
  37. package/dist/lib/core/factory.js +30 -91
  38. package/dist/lib/core/service-registry.d.ts +47 -0
  39. package/dist/lib/core/service-registry.js +112 -0
  40. package/dist/lib/core/types.d.ts +8 -1
  41. package/dist/lib/factories/compatibility-factory.js +1 -1
  42. package/dist/lib/factories/provider-factory.d.ts +72 -0
  43. package/dist/lib/factories/provider-factory.js +144 -0
  44. package/dist/lib/factories/provider-registry.d.ts +38 -0
  45. package/dist/lib/factories/provider-registry.js +107 -0
  46. package/dist/lib/index.d.ts +4 -3
  47. package/dist/lib/index.js +2 -4
  48. package/dist/lib/mcp/config.js +28 -3
  49. package/dist/lib/mcp/function-calling.js +1 -1
  50. package/dist/lib/mcp/initialize-tools.d.ts +1 -1
  51. package/dist/lib/mcp/initialize-tools.js +45 -1
  52. package/dist/lib/mcp/initialize.js +16 -6
  53. package/dist/lib/mcp/servers/agent/direct-tools-server.d.ts +8 -0
  54. package/dist/lib/mcp/servers/agent/direct-tools-server.js +109 -0
  55. package/dist/lib/mcp/servers/ai-providers/ai-core-server.js +3 -1
  56. package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.d.ts +2 -2
  57. package/dist/lib/mcp/unified-registry.d.ts +4 -0
  58. package/dist/lib/mcp/unified-registry.js +42 -9
  59. package/dist/lib/neurolink.d.ts +156 -117
  60. package/dist/lib/neurolink.js +619 -404
  61. package/dist/lib/providers/amazon-bedrock.d.ts +32 -0
  62. package/dist/lib/providers/amazon-bedrock.js +143 -0
  63. package/dist/lib/providers/analytics-helper.js +7 -4
  64. package/dist/lib/providers/anthropic-baseprovider.d.ts +23 -0
  65. package/dist/lib/providers/anthropic-baseprovider.js +114 -0
  66. package/dist/lib/providers/anthropic.d.ts +19 -43
  67. package/dist/lib/providers/anthropic.js +82 -306
  68. package/dist/lib/providers/azure-openai.d.ts +20 -0
  69. package/dist/lib/providers/azure-openai.js +89 -0
  70. package/dist/lib/providers/google-ai-studio.d.ts +23 -0
  71. package/dist/lib/providers/google-ai-studio.js +107 -0
  72. package/dist/lib/providers/google-vertex.d.ts +47 -0
  73. package/dist/lib/providers/google-vertex.js +205 -0
  74. package/dist/lib/providers/huggingFace.d.ts +32 -25
  75. package/dist/lib/providers/huggingFace.js +97 -431
  76. package/dist/lib/providers/index.d.ts +9 -9
  77. package/dist/lib/providers/index.js +9 -9
  78. package/dist/lib/providers/mcp-provider.js +4 -0
  79. package/dist/lib/providers/mistral.d.ts +42 -0
  80. package/dist/lib/providers/mistral.js +160 -0
  81. package/dist/lib/providers/ollama.d.ts +52 -36
  82. package/dist/lib/providers/ollama.js +297 -520
  83. package/dist/lib/providers/openAI.d.ts +19 -18
  84. package/dist/lib/providers/openAI.js +76 -275
  85. package/dist/lib/sdk/tool-extension.d.ts +181 -0
  86. package/dist/lib/sdk/tool-extension.js +283 -0
  87. package/dist/lib/sdk/tool-registration.d.ts +95 -0
  88. package/dist/lib/sdk/tool-registration.js +167 -0
  89. package/dist/lib/types/generate-types.d.ts +1 -0
  90. package/dist/lib/types/mcp-types.d.ts +116 -0
  91. package/dist/lib/types/mcp-types.js +5 -0
  92. package/dist/lib/types/stream-types.d.ts +30 -18
  93. package/dist/lib/types/universal-provider-options.d.ts +87 -0
  94. package/dist/lib/types/universal-provider-options.js +53 -0
  95. package/dist/mcp/config.js +28 -3
  96. package/dist/mcp/function-calling.js +1 -1
  97. package/dist/mcp/initialize-tools.d.ts +1 -1
  98. package/dist/mcp/initialize-tools.js +45 -1
  99. package/dist/mcp/initialize.js +16 -6
  100. package/dist/mcp/servers/agent/direct-tools-server.d.ts +8 -0
  101. package/dist/mcp/servers/agent/direct-tools-server.js +109 -0
  102. package/dist/mcp/servers/ai-providers/ai-core-server.js +3 -1
  103. package/dist/mcp/servers/ai-providers/ai-workflow-tools.d.ts +2 -2
  104. package/dist/mcp/unified-registry.d.ts +4 -0
  105. package/dist/mcp/unified-registry.js +42 -9
  106. package/dist/neurolink.d.ts +156 -117
  107. package/dist/neurolink.js +619 -404
  108. package/dist/providers/amazon-bedrock.d.ts +32 -0
  109. package/dist/providers/amazon-bedrock.js +143 -0
  110. package/dist/providers/analytics-helper.js +7 -4
  111. package/dist/providers/anthropic-baseprovider.d.ts +23 -0
  112. package/dist/providers/anthropic-baseprovider.js +114 -0
  113. package/dist/providers/anthropic.d.ts +19 -43
  114. package/dist/providers/anthropic.js +81 -305
  115. package/dist/providers/azure-openai.d.ts +20 -0
  116. package/dist/providers/azure-openai.js +89 -0
  117. package/dist/providers/google-ai-studio.d.ts +23 -0
  118. package/dist/providers/google-ai-studio.js +108 -0
  119. package/dist/providers/google-vertex.d.ts +47 -0
  120. package/dist/providers/google-vertex.js +205 -0
  121. package/dist/providers/huggingFace.d.ts +32 -25
  122. package/dist/providers/huggingFace.js +96 -430
  123. package/dist/providers/index.d.ts +9 -9
  124. package/dist/providers/index.js +9 -9
  125. package/dist/providers/mcp-provider.js +4 -0
  126. package/dist/providers/mistral.d.ts +42 -0
  127. package/dist/providers/mistral.js +160 -0
  128. package/dist/providers/ollama.d.ts +52 -36
  129. package/dist/providers/ollama.js +297 -519
  130. package/dist/providers/openAI.d.ts +19 -18
  131. package/dist/providers/openAI.js +76 -276
  132. package/dist/sdk/tool-extension.d.ts +181 -0
  133. package/dist/sdk/tool-extension.js +283 -0
  134. package/dist/sdk/tool-registration.d.ts +95 -0
  135. package/dist/sdk/tool-registration.js +168 -0
  136. package/dist/types/generate-types.d.ts +1 -0
  137. package/dist/types/mcp-types.d.ts +116 -0
  138. package/dist/types/mcp-types.js +5 -0
  139. package/dist/types/stream-types.d.ts +30 -18
  140. package/dist/types/universal-provider-options.d.ts +87 -0
  141. package/dist/types/universal-provider-options.js +53 -0
  142. package/package.json +15 -10
  143. package/dist/lib/providers/agent-enhanced-provider.d.ts +0 -93
  144. package/dist/lib/providers/agent-enhanced-provider.js +0 -605
  145. package/dist/lib/providers/amazonBedrock.d.ts +0 -28
  146. package/dist/lib/providers/amazonBedrock.js +0 -364
  147. package/dist/lib/providers/azureOpenAI.d.ts +0 -42
  148. package/dist/lib/providers/azureOpenAI.js +0 -347
  149. package/dist/lib/providers/googleAIStudio.d.ts +0 -42
  150. package/dist/lib/providers/googleAIStudio.js +0 -364
  151. package/dist/lib/providers/googleVertexAI.d.ts +0 -34
  152. package/dist/lib/providers/googleVertexAI.js +0 -547
  153. package/dist/lib/providers/mistralAI.d.ts +0 -37
  154. package/dist/lib/providers/mistralAI.js +0 -325
  155. package/dist/providers/agent-enhanced-provider.d.ts +0 -93
  156. package/dist/providers/agent-enhanced-provider.js +0 -606
  157. package/dist/providers/amazonBedrock.d.ts +0 -28
  158. package/dist/providers/amazonBedrock.js +0 -364
  159. package/dist/providers/azureOpenAI.d.ts +0 -42
  160. package/dist/providers/azureOpenAI.js +0 -348
  161. package/dist/providers/googleAIStudio.d.ts +0 -42
  162. package/dist/providers/googleAIStudio.js +0 -364
  163. package/dist/providers/googleVertexAI.d.ts +0 -34
  164. package/dist/providers/googleVertexAI.js +0 -547
  165. package/dist/providers/mistralAI.d.ts +0 -37
  166. package/dist/providers/mistralAI.js +0 -325
@@ -1,15 +1,48 @@
1
1
  /**
2
2
  * NeuroLink - Unified AI Interface with Real MCP Tool Integration
3
3
  *
4
+ * REDESIGNED FALLBACK CHAIN - NO CIRCULAR DEPENDENCIES
4
5
  * Enhanced AI provider system with natural MCP tool access.
5
6
  * Uses real MCP infrastructure for tool discovery and execution.
6
7
  */
7
- import type { AIProviderName, TextGenerationOptions, TextGenerationResult } from "./core/types.js";
8
+ import type { TextGenerationOptions, TextGenerationResult } from "./core/types.js";
8
9
  import type { GenerateOptions, GenerateResult } from "./types/generate-types.js";
9
10
  import type { StreamOptions, StreamResult } from "./types/stream-types.js";
11
+ import type { SimpleTool } from "./sdk/tool-registration.js";
12
+ import type { InMemoryMCPServerConfig } from "./types/mcp-types.js";
13
+ export interface ProviderStatus {
14
+ provider: string;
15
+ status: "working" | "failed" | "not-configured";
16
+ configured: boolean;
17
+ authenticated: boolean;
18
+ error?: string;
19
+ responseTime?: number;
20
+ model?: string;
21
+ }
22
+ export interface MCPStatus {
23
+ mcpInitialized: boolean;
24
+ totalServers: number;
25
+ availableServers: number;
26
+ autoDiscoveredCount: number;
27
+ totalTools: number;
28
+ autoDiscoveredServers: MCPServerInfo[];
29
+ customToolsCount: number;
30
+ inMemoryServersCount: number;
31
+ error?: string;
32
+ }
33
+ export interface MCPServerInfo {
34
+ id: string;
35
+ name: string;
36
+ source: string;
37
+ status: "connected" | "discovered" | "failed";
38
+ hasServer: boolean;
39
+ metadata?: any;
40
+ }
10
41
  export declare class NeuroLink {
11
42
  private mcpInitialized;
12
43
  private contextManager;
44
+ private customTools;
45
+ private inMemoryServers;
13
46
  constructor();
14
47
  /**
15
48
  * Initialize MCP registry with enhanced error handling and resource cleanup
@@ -17,151 +50,157 @@ export declare class NeuroLink {
17
50
  */
18
51
  private initializeMCP;
19
52
  /**
20
- * Isolated MCP initialization to prevent context-dependent hanging
21
- */
22
- private doIsolatedMCPInitialization;
23
- /**
24
- * PRIMARY METHOD: Generate content using AI (recommended for new code)
25
- * Future-ready for multi-modal capabilities with current text focus
53
+ * MAIN ENTRY POINT: Enhanced generate method with new function signature
54
+ * Replaces both generateText and legacy methods
26
55
  */
27
- generate(options: GenerateOptions): Promise<GenerateResult>;
56
+ generate(optionsOrPrompt: GenerateOptions | string): Promise<GenerateResult>;
28
57
  /**
29
58
  * BACKWARD COMPATIBILITY: Legacy generateText method
30
59
  * Internally calls generate() and converts result format
31
60
  */
32
61
  generateText(options: TextGenerationOptions): Promise<TextGenerationResult>;
33
62
  /**
34
- * Generate text with real MCP tool integration using automatic detection
63
+ * REDESIGNED INTERNAL GENERATION - NO CIRCULAR DEPENDENCIES
64
+ *
65
+ * This method implements a clean fallback chain:
66
+ * 1. Try MCP-enhanced generation if available
67
+ * 2. Fall back to direct provider generation
68
+ * 3. No recursive calls - each method has a specific purpose
69
+ */
70
+ private generateTextInternal;
71
+ /**
72
+ * Try MCP-enhanced generation (no fallback recursion)
35
73
  */
36
- private generateWithTools;
74
+ private tryMCPGeneration;
37
75
  /**
38
- * Regular text generation (existing logic)
76
+ * Direct provider generation (no MCP, no recursion)
39
77
  */
40
- private generateRegular;
78
+ private directProviderGeneration;
41
79
  /**
42
80
  * Create tool-aware system prompt that informs AI about available tools
43
81
  */
44
82
  private createToolAwareSystemPrompt;
83
+ /**
84
+ * BACKWARD COMPATIBILITY: Legacy streamText method
85
+ * Internally calls stream() and converts result format
86
+ */
87
+ streamText(prompt: string, options?: Partial<StreamOptions>): Promise<AsyncIterable<string>>;
45
88
  /**
46
89
  * PRIMARY METHOD: Stream content using AI (recommended for new code)
47
90
  * Future-ready for multi-modal capabilities with current text focus
48
91
  */
49
92
  stream(options: StreamOptions): Promise<StreamResult>;
50
93
  /**
51
- * BACKWARD COMPATIBILITY: Legacy streamText method
52
- * Internally calls stream() and converts result format
94
+ * Register a custom tool that will be available to all AI providers
95
+ * @param name - Unique name for the tool
96
+ * @param tool - Tool configuration
53
97
  */
54
- streamText(options: TextGenerationOptions): Promise<AsyncIterable<{
55
- content: string;
56
- }>>;
98
+ registerTool(name: string, tool: SimpleTool): void;
57
99
  /**
58
- * Get the best available AI provider
100
+ * Register multiple tools at once
101
+ * @param tools - Object mapping tool names to configurations
59
102
  */
60
- getBestProvider(): Promise<string>;
103
+ registerTools(tools: Record<string, SimpleTool>): void;
61
104
  /**
62
- * Test a specific provider
105
+ * Unregister a custom tool
106
+ * @param name - Name of the tool to remove
107
+ * @returns true if the tool was removed, false if it didn't exist
63
108
  */
64
- testProvider(providerName: AIProviderName, testPrompt?: string): Promise<boolean>;
109
+ unregisterTool(name: string): boolean;
65
110
  /**
66
- * Get access to the unified MCP registry for tool inspection and management
111
+ * Get all registered custom tools
112
+ * @returns Map of tool names to configurations
67
113
  */
68
- getUnifiedRegistry(): import("./mcp/unified-registry.js").UnifiedMCPRegistry;
114
+ getCustomTools(): Map<string, SimpleTool>;
69
115
  /**
70
- * Initialize MCP and return discovery statistics
116
+ * Add an in-memory MCP server (from git diff)
117
+ * Allows registration of pre-instantiated server objects
118
+ * @param serverId - Unique identifier for the server
119
+ * @param config - Server configuration
71
120
  */
72
- getMCPStatus(): Promise<{
73
- mcpInitialized: boolean;
74
- totalServers: number;
75
- availableServers: number;
76
- autoDiscoveredCount: number;
77
- totalTools: number;
78
- autoDiscoveredServers: {
79
- id: string;
80
- name: string;
81
- source: "core" | "project" | "installed";
82
- status: string;
83
- hasServer: boolean;
84
- }[];
85
- }>;
121
+ addInMemoryMCPServer(serverId: string, config: InMemoryMCPServerConfig): Promise<void>;
86
122
  /**
87
- * Add a new MCP server programmatically
88
- *
89
- * Allows dynamic registration of MCP servers at runtime for enhanced
90
- * tool ecosystem management. Perfect for integrating external services
91
- * like Bitbucket, Slack, databases, etc.
92
- *
93
- * @param serverId - Unique identifier for the server (e.g., 'bitbucket', 'slack-api')
94
- * @param config - Server configuration with command and execution parameters
95
- * @returns Promise that resolves when server is successfully added and connected
96
- *
97
- * @example
98
- * ```typescript
99
- * // Add Bitbucket MCP server
100
- * await neurolink.addMCPServer('bitbucket', {
101
- * command: 'npx',
102
- * args: ['-y', '@nexus2520/bitbucket-mcp-server'],
103
- * env: {
104
- * BITBUCKET_USERNAME: 'your-username',
105
- * BITBUCKET_APP_PASSWORD: 'your-app-password'
106
- * }
107
- * });
108
- *
109
- * // Add custom database connector
110
- * await neurolink.addMCPServer('database', {
111
- * command: 'node',
112
- * args: ['./custom-db-mcp-server.js'],
113
- * env: { DB_CONNECTION_STRING: 'postgresql://...' }
114
- * });
115
- * ```
116
- */
117
- addMCPServer(serverId: string, config: {
118
- command: string;
119
- args?: string[];
120
- env?: Record<string, string>;
121
- cwd?: string;
122
- type?: "stdio" | "sse" | "http";
123
- url?: string;
124
- headers?: Record<string, string>;
123
+ * Get all registered in-memory servers
124
+ * @returns Map of server IDs to configurations
125
+ */
126
+ getInMemoryServers(): Map<string, InMemoryMCPServerConfig>;
127
+ /**
128
+ * Execute a specific tool by name (from git diff)
129
+ * Supports both custom tools and MCP server tools
130
+ * @param toolName - Name of the tool to execute
131
+ * @param params - Parameters to pass to the tool
132
+ * @param options - Execution options
133
+ * @returns Tool execution result
134
+ */
135
+ executeTool<T = any>(toolName: string, params?: any, options?: {
125
136
  timeout?: number;
126
- }): Promise<void>;
127
- /**
128
- * Short alias for generate() - CLI-SDK consistency
129
- * @param options - Text generation options
130
- * @returns Promise resolving to text generation result
131
- */
132
- gen(options: TextGenerationOptions): Promise<TextGenerationResult>;
133
- /**
134
- * Get the connection client for a specific MCP server
135
- * @param serverId - The ID of the server to get connection for
136
- * @returns Client connection object or undefined if not connected
137
- */
138
- getConnection(serverId: string): import("@modelcontextprotocol/sdk/client/index.js").Client<{
139
- method: string;
140
- params?: {
141
- [x: string]: unknown;
142
- _meta?: {
143
- [x: string]: unknown;
144
- progressToken?: string | number | undefined;
145
- } | undefined;
146
- } | undefined;
147
- }, {
148
- method: string;
149
- params?: {
150
- [x: string]: unknown;
151
- _meta?: {
152
- [x: string]: unknown;
153
- } | undefined;
154
- } | undefined;
155
- }, {
156
- [x: string]: unknown;
157
- _meta?: {
158
- [x: string]: unknown;
159
- } | undefined;
160
- }> | undefined;
161
- /**
162
- * Check if a specific MCP server is currently connected
163
- * @param serverId - The ID of the server to check
164
- * @returns True if server is connected, false otherwise
165
- */
166
- isConnected(serverId: string): boolean;
137
+ }): Promise<T>;
138
+ /**
139
+ * Get all available tools including custom and in-memory ones
140
+ * @returns Array of available tools with metadata
141
+ */
142
+ getAllAvailableTools(): Promise<{
143
+ serverId: string;
144
+ serverTitle: string;
145
+ toolName: string;
146
+ namespacedName: string;
147
+ description: string;
148
+ isImplemented: boolean;
149
+ }[]>;
150
+ /**
151
+ * Get comprehensive status of all AI providers
152
+ * Primary method for provider health checking and diagnostics
153
+ */
154
+ getProviderStatus(): Promise<ProviderStatus[]>;
155
+ /**
156
+ * Test a specific AI provider's connectivity and authentication
157
+ * @param providerName - Name of the provider to test
158
+ * @returns Promise resolving to true if provider is working
159
+ */
160
+ testProvider(providerName: string): Promise<boolean>;
161
+ /**
162
+ * Internal method to test provider connection with minimal generation call
163
+ */
164
+ private testProviderConnection;
165
+ /**
166
+ * Check if a provider has required environment variables configured
167
+ * @param providerName - Name of the provider to check
168
+ * @returns True if provider has required environment variables
169
+ */
170
+ hasProviderEnvVars(providerName: string): Promise<boolean>;
171
+ /**
172
+ * Get the best available AI provider based on configuration and availability
173
+ * @param requestedProvider - Optional preferred provider name
174
+ * @returns Promise resolving to the best provider name
175
+ */
176
+ getBestProvider(requestedProvider?: string): Promise<string>;
177
+ /**
178
+ * Get list of all available AI provider names
179
+ * @returns Array of supported provider names
180
+ */
181
+ getAvailableProviders(): Promise<string[]>;
182
+ /**
183
+ * Validate if a provider name is supported
184
+ * @param providerName - Provider name to validate
185
+ * @returns True if provider name is valid
186
+ */
187
+ isValidProvider(providerName: string): Promise<boolean>;
188
+ /**
189
+ * Get comprehensive MCP (Model Context Protocol) status information
190
+ * @returns Promise resolving to MCP status details
191
+ */
192
+ getMCPStatus(): Promise<MCPStatus>;
193
+ /**
194
+ * List all configured MCP servers with their status
195
+ * @returns Promise resolving to array of MCP server information
196
+ */
197
+ listMCPServers(): Promise<MCPServerInfo[]>;
198
+ /**
199
+ * Test connectivity to a specific MCP server
200
+ * @param serverId - ID of the MCP server to test
201
+ * @returns Promise resolving to true if server is reachable
202
+ */
203
+ testMCPServer(serverId: string): Promise<boolean>;
167
204
  }
205
+ export declare const neurolink: NeuroLink;
206
+ export default neurolink;