@juspay/neurolink 5.0.0 → 5.1.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 (121) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +51 -60
  3. package/dist/chat/sse-handler.js +5 -4
  4. package/dist/chat/websocket-chat-handler.js +9 -9
  5. package/dist/cli/commands/mcp.js +1 -1
  6. package/dist/cli/commands/ollama.js +3 -3
  7. package/dist/cli/factories/command-factory.d.ts +14 -0
  8. package/dist/cli/factories/command-factory.js +129 -0
  9. package/dist/cli/index.js +27 -26
  10. package/dist/cli/utils/interactive-setup.js +2 -2
  11. package/dist/core/evaluation.d.ts +9 -9
  12. package/dist/core/evaluation.js +14 -14
  13. package/dist/core/types.d.ts +41 -48
  14. package/dist/core/types.js +1 -0
  15. package/dist/factories/compatibility-factory.d.ts +20 -0
  16. package/dist/factories/compatibility-factory.js +69 -0
  17. package/dist/factories/provider-generate-factory.d.ts +20 -0
  18. package/dist/factories/provider-generate-factory.js +87 -0
  19. package/dist/index.d.ts +4 -2
  20. package/dist/index.js +3 -1
  21. package/dist/lib/chat/sse-handler.js +5 -4
  22. package/dist/lib/chat/websocket-chat-handler.js +9 -9
  23. package/dist/lib/core/evaluation.d.ts +9 -9
  24. package/dist/lib/core/evaluation.js +14 -14
  25. package/dist/lib/core/types.d.ts +41 -48
  26. package/dist/lib/core/types.js +1 -0
  27. package/dist/lib/factories/compatibility-factory.d.ts +20 -0
  28. package/dist/lib/factories/compatibility-factory.js +69 -0
  29. package/dist/lib/factories/provider-generate-factory.d.ts +20 -0
  30. package/dist/lib/factories/provider-generate-factory.js +87 -0
  31. package/dist/lib/index.d.ts +4 -2
  32. package/dist/lib/index.js +3 -1
  33. package/dist/lib/mcp/client.js +5 -5
  34. package/dist/lib/mcp/dynamic-orchestrator.js +8 -8
  35. package/dist/lib/mcp/external-client.js +2 -2
  36. package/dist/lib/mcp/factory.d.ts +1 -1
  37. package/dist/lib/mcp/factory.js +1 -1
  38. package/dist/lib/mcp/neurolink-mcp-client.js +10 -10
  39. package/dist/lib/mcp/orchestrator.js +4 -4
  40. package/dist/lib/mcp/servers/ai-providers/ai-analysis-tools.js +10 -10
  41. package/dist/lib/mcp/servers/ai-providers/ai-core-server.js +5 -5
  42. package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.d.ts +2 -2
  43. package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.js +16 -16
  44. package/dist/lib/neurolink.d.ts +21 -73
  45. package/dist/lib/neurolink.js +230 -119
  46. package/dist/lib/providers/agent-enhanced-provider.d.ts +12 -8
  47. package/dist/lib/providers/agent-enhanced-provider.js +87 -96
  48. package/dist/lib/providers/amazonBedrock.d.ts +17 -8
  49. package/dist/lib/providers/amazonBedrock.js +60 -30
  50. package/dist/lib/providers/anthropic.d.ts +14 -10
  51. package/dist/lib/providers/anthropic.js +84 -154
  52. package/dist/lib/providers/azureOpenAI.d.ts +9 -6
  53. package/dist/lib/providers/azureOpenAI.js +70 -159
  54. package/dist/lib/providers/function-calling-provider.d.ts +14 -12
  55. package/dist/lib/providers/function-calling-provider.js +114 -64
  56. package/dist/lib/providers/googleAIStudio.d.ts +12 -19
  57. package/dist/lib/providers/googleAIStudio.js +65 -34
  58. package/dist/lib/providers/googleVertexAI.d.ts +11 -15
  59. package/dist/lib/providers/googleVertexAI.js +146 -118
  60. package/dist/lib/providers/huggingFace.d.ts +10 -11
  61. package/dist/lib/providers/huggingFace.js +61 -24
  62. package/dist/lib/providers/mcp-provider.d.ts +13 -8
  63. package/dist/lib/providers/mcp-provider.js +59 -18
  64. package/dist/lib/providers/mistralAI.d.ts +14 -11
  65. package/dist/lib/providers/mistralAI.js +60 -29
  66. package/dist/lib/providers/ollama.d.ts +9 -8
  67. package/dist/lib/providers/ollama.js +134 -91
  68. package/dist/lib/providers/openAI.d.ts +11 -12
  69. package/dist/lib/providers/openAI.js +132 -97
  70. package/dist/lib/types/generate-types.d.ts +79 -0
  71. package/dist/lib/types/generate-types.js +1 -0
  72. package/dist/lib/types/stream-types.d.ts +83 -0
  73. package/dist/lib/types/stream-types.js +1 -0
  74. package/dist/lib/utils/providerUtils-fixed.js +1 -1
  75. package/dist/lib/utils/streaming-utils.d.ts +14 -2
  76. package/dist/lib/utils/streaming-utils.js +0 -3
  77. package/dist/mcp/client.js +5 -5
  78. package/dist/mcp/dynamic-orchestrator.js +8 -8
  79. package/dist/mcp/external-client.js +2 -2
  80. package/dist/mcp/factory.d.ts +1 -1
  81. package/dist/mcp/factory.js +1 -1
  82. package/dist/mcp/neurolink-mcp-client.js +10 -10
  83. package/dist/mcp/orchestrator.js +4 -4
  84. package/dist/mcp/servers/ai-providers/ai-analysis-tools.js +10 -10
  85. package/dist/mcp/servers/ai-providers/ai-core-server.js +5 -5
  86. package/dist/mcp/servers/ai-providers/ai-workflow-tools.d.ts +2 -2
  87. package/dist/mcp/servers/ai-providers/ai-workflow-tools.js +16 -16
  88. package/dist/neurolink.d.ts +21 -73
  89. package/dist/neurolink.js +230 -119
  90. package/dist/providers/agent-enhanced-provider.d.ts +12 -8
  91. package/dist/providers/agent-enhanced-provider.js +87 -95
  92. package/dist/providers/amazonBedrock.d.ts +17 -8
  93. package/dist/providers/amazonBedrock.js +60 -30
  94. package/dist/providers/anthropic.d.ts +14 -10
  95. package/dist/providers/anthropic.js +84 -154
  96. package/dist/providers/azureOpenAI.d.ts +9 -6
  97. package/dist/providers/azureOpenAI.js +70 -159
  98. package/dist/providers/function-calling-provider.d.ts +14 -12
  99. package/dist/providers/function-calling-provider.js +114 -64
  100. package/dist/providers/googleAIStudio.d.ts +12 -19
  101. package/dist/providers/googleAIStudio.js +65 -34
  102. package/dist/providers/googleVertexAI.d.ts +11 -15
  103. package/dist/providers/googleVertexAI.js +146 -118
  104. package/dist/providers/huggingFace.d.ts +10 -11
  105. package/dist/providers/huggingFace.js +61 -24
  106. package/dist/providers/mcp-provider.d.ts +13 -8
  107. package/dist/providers/mcp-provider.js +59 -18
  108. package/dist/providers/mistralAI.d.ts +14 -11
  109. package/dist/providers/mistralAI.js +60 -29
  110. package/dist/providers/ollama.d.ts +9 -8
  111. package/dist/providers/ollama.js +133 -90
  112. package/dist/providers/openAI.d.ts +11 -12
  113. package/dist/providers/openAI.js +132 -97
  114. package/dist/types/generate-types.d.ts +79 -0
  115. package/dist/types/generate-types.js +1 -0
  116. package/dist/types/stream-types.d.ts +83 -0
  117. package/dist/types/stream-types.js +1 -0
  118. package/dist/utils/providerUtils-fixed.js +1 -1
  119. package/dist/utils/streaming-utils.d.ts +14 -2
  120. package/dist/utils/streaming-utils.js +0 -3
  121. package/package.json +1 -1
@@ -108,15 +108,15 @@ export const analyzeAIUsageTool = {
108
108
  - "analysis" should contain: timeRange, totalRequests, totalTokens, and a "providers" object.
109
109
  - "insights" should contain: mostUsedProvider, avgCostPerToken, peakUsageHours, costOptimizationPotential, and an array of "recommendations".
110
110
  `;
111
- const result = await provider.generateText({
111
+ const result = await provider.generate({
112
112
  prompt: analysisPrompt,
113
113
  maxTokens: 800,
114
114
  temperature: 0.5,
115
115
  });
116
- if (!result || !result.text) {
116
+ if (!result || !result.content) {
117
117
  throw new Error("AI provider returned no result for usage analysis.");
118
118
  }
119
- const parsedData = JSON.parse(result.text);
119
+ const parsedData = JSON.parse(result.content);
120
120
  const executionTime = Date.now() - startTime;
121
121
  return {
122
122
  success: true,
@@ -190,8 +190,8 @@ export const benchmarkProviderPerformanceTool = {
190
190
  for (const prompt of testPrompts) {
191
191
  for (let i = 0; i < params.iterations; i++) {
192
192
  const testStartTime = Date.now();
193
- const result = await provider.generateText({
194
- prompt,
193
+ const result = await provider.generate({
194
+ prompt: prompt,
195
195
  maxTokens: params.maxTokens,
196
196
  });
197
197
  if (result && result.usage) {
@@ -274,7 +274,7 @@ export const optimizePromptParametersTool = {
274
274
  const optimizationResults = [];
275
275
  const temperatures = [0.2, 0.7, 1.0]; // Test a range of temperatures
276
276
  for (const temp of temperatures) {
277
- const result = await provider.generateText({
277
+ const result = await provider.generate({
278
278
  prompt: params.prompt,
279
279
  temperature: temp,
280
280
  maxTokens: params.targetLength || 250,
@@ -282,7 +282,7 @@ export const optimizePromptParametersTool = {
282
282
  if (result) {
283
283
  optimizationResults.push({
284
284
  parameters: { temperature: temp },
285
- output: result.text,
285
+ output: result.content,
286
286
  usage: result.usage,
287
287
  });
288
288
  }
@@ -300,14 +300,14 @@ export const optimizePromptParametersTool = {
300
300
  Determine which set of parameters is optimal and provide a recommendation.
301
301
  Return a valid JSON object with keys: "optimalParameters", "reasoning", "recommendations".
302
302
  `;
303
- const analysisResult = await analysisProvider.generateText({
303
+ const analysisResult = await analysisProvider.generate({
304
304
  prompt: analysisPrompt,
305
305
  maxTokens: 500,
306
306
  });
307
- if (!analysisResult || !analysisResult.text) {
307
+ if (!analysisResult || !analysisResult.content) {
308
308
  throw new Error("Optimization analysis failed.");
309
309
  }
310
- const parsedAnalysis = JSON.parse(analysisResult.text);
310
+ const parsedAnalysis = JSON.parse(analysisResult.content);
311
311
  const executionTime = Date.now() - startTime;
312
312
  return {
313
313
  success: true,
@@ -75,7 +75,7 @@ const ProviderSelectionSchema = z.object({
75
75
  * Core tool that leverages existing AIProviderFactory for text generation
76
76
  */
77
77
  aiCoreServer.registerTool({
78
- name: "generate-text",
78
+ name: "generate",
79
79
  description: "Generate text using AI providers with automatic fallback and provider selection",
80
80
  category: "text-generation",
81
81
  inputSchema: TextGenerationSchema,
@@ -88,7 +88,7 @@ aiCoreServer.registerTool({
88
88
  const selectedProvider = params.provider || (await getBestProvider(params.provider));
89
89
  const provider = await AIProviderFactory.createBestProvider(selectedProvider);
90
90
  // Generate text using existing NeuroLink patterns
91
- const result = await provider.generateText({
91
+ const result = await provider.generate({
92
92
  prompt: params.prompt,
93
93
  model: params.model,
94
94
  temperature: params.temperature,
@@ -103,7 +103,7 @@ aiCoreServer.registerTool({
103
103
  return {
104
104
  success: true,
105
105
  data: {
106
- text: result.text,
106
+ text: result.content,
107
107
  model: params.model || "default",
108
108
  provider: selectedProvider,
109
109
  generatedAt: new Date().toISOString(),
@@ -115,7 +115,7 @@ aiCoreServer.registerTool({
115
115
  executionTime,
116
116
  },
117
117
  metadata: {
118
- toolName: "generate-text",
118
+ toolName: "generate",
119
119
  serverId: "neurolink-ai-core",
120
120
  sessionId: context.sessionId,
121
121
  timestamp: Date.now(),
@@ -131,7 +131,7 @@ aiCoreServer.registerTool({
131
131
  success: false,
132
132
  error: errorMessage,
133
133
  metadata: {
134
- toolName: "generate-text",
134
+ toolName: "generate",
135
135
  serverId: "neurolink-ai-core",
136
136
  sessionId: context.sessionId,
137
137
  timestamp: Date.now(),
@@ -88,14 +88,14 @@ export declare const workflowToolSchemas: {
88
88
  }, "strip", z.ZodTypeAny, {
89
89
  aiOutput: string;
90
90
  expectedBehavior: string;
91
- outputType: "code" | "text" | "conversation" | "structured-data";
91
+ outputType: "text" | "code" | "conversation" | "structured-data";
92
92
  includeFixSuggestions: boolean;
93
93
  context?: string | undefined;
94
94
  }, {
95
95
  aiOutput: string;
96
96
  expectedBehavior: string;
97
97
  context?: string | undefined;
98
- outputType?: "code" | "text" | "conversation" | "structured-data" | undefined;
98
+ outputType?: "text" | "code" | "conversation" | "structured-data" | undefined;
99
99
  includeFixSuggestions?: boolean | undefined;
100
100
  }>;
101
101
  };
@@ -144,16 +144,16 @@ Return ONLY a valid JSON object with this exact structure:
144
144
  }
145
145
 
146
146
  Generate 3-5 comprehensive test cases covering the requested types.`;
147
- const result = await provider.generateText({
148
- prompt,
147
+ const result = await provider.generate({
148
+ prompt: prompt,
149
149
  maxTokens: Math.floor(DEFAULT_MAX_TOKENS * 1.2),
150
150
  temperature: 0.3, // Lower temperature for more consistent structured output
151
151
  });
152
- if (!result || !result.text) {
152
+ if (!result || !result.content) {
153
153
  throw new Error("AI provider returned no result for test case generation.");
154
154
  }
155
155
  // Parse AI response
156
- const aiResponse = JSON.parse(result.text);
156
+ const aiResponse = JSON.parse(result.content);
157
157
  const testCases = aiResponse.testCases || [];
158
158
  const executionTime = Date.now() - startTime;
159
159
  const responseData = {
@@ -250,16 +250,16 @@ Return ONLY a valid JSON object with this exact structure:
250
250
  }
251
251
 
252
252
  Focus on real, actionable improvements based on the specified objectives.`;
253
- const result = await provider.generateText({
254
- prompt,
253
+ const result = await provider.generate({
254
+ prompt: prompt,
255
255
  maxTokens: DEFAULT_MAX_TOKENS,
256
256
  temperature: 0.2, // Very low temperature for consistent refactoring
257
257
  });
258
- if (!result || !result.text) {
258
+ if (!result || !result.content) {
259
259
  throw new Error("AI provider returned no result for code refactoring.");
260
260
  }
261
261
  // Parse AI response
262
- const aiResponse = JSON.parse(result.text);
262
+ const aiResponse = JSON.parse(result.content);
263
263
  const executionTime = Date.now() - startTime;
264
264
  const responseData = {
265
265
  refactoredCode: aiResponse.refactoredCode || code,
@@ -358,16 +358,16 @@ Return ONLY a valid JSON object with this exact structure:
358
358
  }
359
359
 
360
360
  Focus on creating accurate, useful documentation that explains the code's purpose, parameters, return values, and usage patterns.`;
361
- const result = await provider.generateText({
362
- prompt,
361
+ const result = await provider.generate({
362
+ prompt: prompt,
363
363
  maxTokens: Math.floor(DEFAULT_MAX_TOKENS * 1.2),
364
364
  temperature: 0.3, // Moderate temperature for creative but structured documentation
365
365
  });
366
- if (!result || !result.text) {
366
+ if (!result || !result.content) {
367
367
  throw new Error("AI provider returned no result for documentation generation.");
368
368
  }
369
369
  // Parse AI response
370
- const aiResponse = JSON.parse(result.text);
370
+ const aiResponse = JSON.parse(result.content);
371
371
  const executionTime = Date.now() - startTime;
372
372
  const responseData = {
373
373
  documentation: aiResponse.documentation || "Documentation generated successfully",
@@ -483,16 +483,16 @@ Return ONLY a valid JSON object with this exact structure:
483
483
  }
484
484
 
485
485
  Provide thorough, actionable analysis focused on improving AI output quality.`;
486
- const result = await provider.generateText({
487
- prompt,
486
+ const result = await provider.generate({
487
+ prompt: prompt,
488
488
  maxTokens: DEFAULT_MAX_TOKENS,
489
489
  temperature: 0.4, // Moderate temperature for analytical thinking
490
490
  });
491
- if (!result || !result.text) {
491
+ if (!result || !result.content) {
492
492
  throw new Error("AI provider returned no result for output debugging.");
493
493
  }
494
494
  // Parse AI response
495
- const aiResponse = JSON.parse(result.text);
495
+ const aiResponse = JSON.parse(result.content);
496
496
  const executionTime = Date.now() - startTime;
497
497
  const responseData = {
498
498
  issues: aiResponse.issues || [],
@@ -4,66 +4,9 @@
4
4
  * Enhanced AI provider system with natural MCP tool access.
5
5
  * Uses real MCP infrastructure for tool discovery and execution.
6
6
  */
7
- import type { AIProviderName } from "./core/types.js";
8
- export interface TextGenerationOptions {
9
- prompt: string;
10
- provider?: "openai" | "bedrock" | "vertex" | "anthropic" | "azure" | "google-ai" | "huggingface" | "ollama" | "mistral" | "auto";
11
- model?: string;
12
- temperature?: number;
13
- maxTokens?: number;
14
- systemPrompt?: string;
15
- schema?: any;
16
- timeout?: number | string;
17
- disableTools?: boolean;
18
- enableAnalytics?: boolean;
19
- enableEvaluation?: boolean;
20
- context?: Record<string, any>;
21
- evaluationDomain?: string;
22
- toolUsageContext?: string;
23
- conversationHistory?: Array<{
24
- role: string;
25
- content: string;
26
- }>;
27
- }
28
- export interface StreamTextOptions {
29
- prompt: string;
30
- provider?: "openai" | "bedrock" | "vertex" | "anthropic" | "azure" | "google-ai" | "huggingface" | "ollama" | "mistral" | "auto";
31
- model?: string;
32
- temperature?: number;
33
- maxTokens?: number;
34
- systemPrompt?: string;
35
- schema?: any;
36
- timeout?: number | string;
37
- disableTools?: boolean;
38
- enableAnalytics?: boolean;
39
- enableEvaluation?: boolean;
40
- context?: Record<string, any>;
41
- }
42
- export interface TextGenerationResult {
43
- content: string;
44
- provider?: string;
45
- model?: string;
46
- usage?: {
47
- promptTokens?: number;
48
- completionTokens?: number;
49
- totalTokens?: number;
50
- };
51
- responseTime?: number;
52
- toolsUsed?: string[];
53
- toolExecutions?: Array<{
54
- toolName: string;
55
- executionTime: number;
56
- success: boolean;
57
- serverId?: string;
58
- }>;
59
- enhancedWithTools?: boolean;
60
- availableTools?: Array<{
61
- name: string;
62
- description: string;
63
- server: string;
64
- category?: string;
65
- }>;
66
- }
7
+ import type { AIProviderName, TextGenerationOptions, TextGenerationResult } from "./core/types.js";
8
+ import type { GenerateOptions, GenerateResult } from "./types/generate-types.js";
9
+ import type { StreamOptions, StreamResult } from "./types/stream-types.js";
67
10
  export declare class NeuroLink {
68
11
  private mcpInitialized;
69
12
  private contextManager;
@@ -78,26 +21,37 @@ export declare class NeuroLink {
78
21
  */
79
22
  private doIsolatedMCPInitialization;
80
23
  /**
81
- * Generate text using the best available AI provider with automatic fallback
82
- * Tools are ENABLED BY DEFAULT for natural AI behavior
24
+ * PRIMARY METHOD: Generate content using AI (recommended for new code)
25
+ * Future-ready for multi-modal capabilities with current text focus
26
+ */
27
+ generate(options: GenerateOptions): Promise<GenerateResult>;
28
+ /**
29
+ * BACKWARD COMPATIBILITY: Legacy generateText method
30
+ * Internally calls generate() and converts result format
83
31
  */
84
32
  generateText(options: TextGenerationOptions): Promise<TextGenerationResult>;
85
33
  /**
86
34
  * Generate text with real MCP tool integration using automatic detection
87
35
  */
88
- private generateTextWithTools;
36
+ private generateWithTools;
89
37
  /**
90
38
  * Regular text generation (existing logic)
91
39
  */
92
- private generateTextRegular;
40
+ private generateRegular;
93
41
  /**
94
42
  * Create tool-aware system prompt that informs AI about available tools
95
43
  */
96
44
  private createToolAwareSystemPrompt;
97
45
  /**
98
- * Generate streaming text using the best available AI provider with automatic fallback
46
+ * PRIMARY METHOD: Stream content using AI (recommended for new code)
47
+ * Future-ready for multi-modal capabilities with current text focus
48
+ */
49
+ stream(options: StreamOptions): Promise<StreamResult>;
50
+ /**
51
+ * BACKWARD COMPATIBILITY: Legacy streamText method
52
+ * Internally calls stream() and converts result format
99
53
  */
100
- generateTextStream(options: StreamTextOptions): Promise<AsyncIterable<{
54
+ streamText(options: TextGenerationOptions): Promise<AsyncIterable<{
101
55
  content: string;
102
56
  }>>;
103
57
  /**
@@ -171,13 +125,7 @@ export declare class NeuroLink {
171
125
  timeout?: number;
172
126
  }): Promise<void>;
173
127
  /**
174
- * Alias for generateText() - CLI-SDK consistency
175
- * @param options - Text generation options
176
- * @returns Promise resolving to text generation result
177
- */
178
- generate(options: TextGenerationOptions): Promise<TextGenerationResult>;
179
- /**
180
- * Short alias for generateText() - CLI-SDK consistency
128
+ * Short alias for generate() - CLI-SDK consistency
181
129
  * @param options - Text generation options
182
130
  * @returns Promise resolving to text generation result
183
131
  */