@juspay/neurolink 7.12.0 → 7.14.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 (65) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +90 -25
  3. package/dist/config/conversationMemoryConfig.js +2 -1
  4. package/dist/context/ContextManager.d.ts +28 -0
  5. package/dist/context/ContextManager.js +113 -0
  6. package/dist/context/config.d.ts +5 -0
  7. package/dist/context/config.js +42 -0
  8. package/dist/context/types.d.ts +20 -0
  9. package/dist/context/types.js +1 -0
  10. package/dist/context/utils.d.ts +7 -0
  11. package/dist/context/utils.js +8 -0
  12. package/dist/core/baseProvider.d.ts +16 -1
  13. package/dist/core/baseProvider.js +208 -9
  14. package/dist/core/conversationMemoryManager.js +3 -2
  15. package/dist/core/factory.js +13 -2
  16. package/dist/factories/providerFactory.js +5 -11
  17. package/dist/factories/providerRegistry.js +2 -2
  18. package/dist/lib/config/conversationMemoryConfig.js +2 -1
  19. package/dist/lib/context/ContextManager.d.ts +28 -0
  20. package/dist/lib/context/ContextManager.js +113 -0
  21. package/dist/lib/context/config.d.ts +5 -0
  22. package/dist/lib/context/config.js +42 -0
  23. package/dist/lib/context/types.d.ts +20 -0
  24. package/dist/lib/context/types.js +1 -0
  25. package/dist/lib/context/utils.d.ts +7 -0
  26. package/dist/lib/context/utils.js +8 -0
  27. package/dist/lib/core/baseProvider.d.ts +16 -1
  28. package/dist/lib/core/baseProvider.js +208 -9
  29. package/dist/lib/core/conversationMemoryManager.js +3 -2
  30. package/dist/lib/core/factory.js +13 -2
  31. package/dist/lib/factories/providerFactory.js +5 -11
  32. package/dist/lib/factories/providerRegistry.js +2 -2
  33. package/dist/lib/mcp/externalServerManager.d.ts +115 -0
  34. package/dist/lib/mcp/externalServerManager.js +677 -0
  35. package/dist/lib/mcp/mcpCircuitBreaker.d.ts +184 -0
  36. package/dist/lib/mcp/mcpCircuitBreaker.js +338 -0
  37. package/dist/lib/mcp/mcpClientFactory.d.ts +104 -0
  38. package/dist/lib/mcp/mcpClientFactory.js +416 -0
  39. package/dist/lib/mcp/toolDiscoveryService.d.ts +192 -0
  40. package/dist/lib/mcp/toolDiscoveryService.js +578 -0
  41. package/dist/lib/neurolink.d.ts +128 -16
  42. package/dist/lib/neurolink.js +555 -49
  43. package/dist/lib/providers/googleVertex.d.ts +1 -1
  44. package/dist/lib/providers/googleVertex.js +23 -7
  45. package/dist/lib/types/externalMcp.d.ts +282 -0
  46. package/dist/lib/types/externalMcp.js +6 -0
  47. package/dist/lib/types/generateTypes.d.ts +0 -1
  48. package/dist/lib/types/index.d.ts +1 -0
  49. package/dist/mcp/externalServerManager.d.ts +115 -0
  50. package/dist/mcp/externalServerManager.js +677 -0
  51. package/dist/mcp/mcpCircuitBreaker.d.ts +184 -0
  52. package/dist/mcp/mcpCircuitBreaker.js +338 -0
  53. package/dist/mcp/mcpClientFactory.d.ts +104 -0
  54. package/dist/mcp/mcpClientFactory.js +416 -0
  55. package/dist/mcp/toolDiscoveryService.d.ts +192 -0
  56. package/dist/mcp/toolDiscoveryService.js +578 -0
  57. package/dist/neurolink.d.ts +128 -16
  58. package/dist/neurolink.js +555 -49
  59. package/dist/providers/googleVertex.d.ts +1 -1
  60. package/dist/providers/googleVertex.js +23 -7
  61. package/dist/types/externalMcp.d.ts +282 -0
  62. package/dist/types/externalMcp.js +6 -0
  63. package/dist/types/generateTypes.d.ts +0 -1
  64. package/dist/types/index.d.ts +1 -0
  65. package/package.json +1 -1
@@ -25,7 +25,7 @@ export declare class GoogleVertexProvider extends BaseProvider {
25
25
  private static readonly MAX_CACHE_SIZE;
26
26
  private static maxTokensCache;
27
27
  private static maxTokensCacheTime;
28
- constructor(modelName?: string, sdk?: unknown);
28
+ constructor(modelName?: string, providerName?: string, sdk?: unknown);
29
29
  protected getProviderName(): AIProviderName;
30
30
  protected getDefaultModel(): string;
31
31
  /**
@@ -125,7 +125,7 @@ export class GoogleVertexProvider extends BaseProvider {
125
125
  // Memory-managed cache for maxTokens handling decisions to optimize streaming performance
126
126
  static maxTokensCache = new Map();
127
127
  static maxTokensCacheTime = 0;
128
- constructor(modelName, sdk) {
128
+ constructor(modelName, providerName, sdk) {
129
129
  super(modelName, "vertex", sdk);
130
130
  // Validate Google Cloud credentials - now using consolidated utility
131
131
  if (!hasGoogleCredentials()) {
@@ -198,6 +198,14 @@ export class GoogleVertexProvider extends BaseProvider {
198
198
  hasSchema: !!analysisSchema,
199
199
  });
200
200
  const model = await this.getModel();
201
+ // Get all available tools (direct + MCP + external) for streaming
202
+ const shouldUseTools = !options.disableTools && this.supportsTools();
203
+ const tools = shouldUseTools ? await this.getAllTools() : {};
204
+ logger.debug(`${functionTag}: Tools for streaming`, {
205
+ shouldUseTools,
206
+ toolCount: Object.keys(tools).length,
207
+ toolNames: Object.keys(tools),
208
+ });
201
209
  // Model-specific maxTokens handling
202
210
  const modelName = this.modelName || getDefaultVertexModel();
203
211
  // Use cached model configuration to determine maxTokens handling for streaming performance
@@ -206,18 +214,19 @@ export class GoogleVertexProvider extends BaseProvider {
206
214
  const maxTokens = shouldSetMaxTokens
207
215
  ? options.maxTokens || DEFAULT_MAX_TOKENS
208
216
  : undefined;
209
- // Get tools consistently with generate method (using BaseProvider pattern)
210
- const shouldUseTools = !options.disableTools && this.supportsTools();
211
- const tools = shouldUseTools ? await this.getAllTools() : {};
212
217
  // Build complete stream options with proper typing
213
218
  let streamOptions = {
214
219
  model: model,
215
220
  messages: messages,
216
221
  temperature: options.temperature,
217
222
  ...(maxTokens && { maxTokens }),
218
- tools,
219
- maxSteps: options.maxSteps || DEFAULT_MAX_STEPS,
220
- toolChoice: shouldUseTools ? "auto" : "none",
223
+ // Add tools support for streaming
224
+ ...(shouldUseTools &&
225
+ Object.keys(tools).length > 0 && {
226
+ tools,
227
+ toolChoice: "auto",
228
+ maxSteps: options.maxSteps || DEFAULT_MAX_STEPS,
229
+ }),
221
230
  abortSignal: timeoutController?.controller.signal,
222
231
  onError: (event) => {
223
232
  const error = event.error;
@@ -258,10 +267,17 @@ export class GoogleVertexProvider extends BaseProvider {
258
267
  timeoutController?.cleanup();
259
268
  // Transform string stream to content object stream using BaseProvider method
260
269
  const transformedStream = this.createTextStream(result);
270
+ // Track tool calls and results for streaming
271
+ const toolCalls = [];
272
+ const toolResults = [];
261
273
  return {
262
274
  stream: transformedStream,
263
275
  provider: this.providerName,
264
276
  model: this.modelName,
277
+ ...(shouldUseTools && {
278
+ toolCalls,
279
+ toolResults,
280
+ }),
265
281
  };
266
282
  }
267
283
  catch (error) {
@@ -0,0 +1,282 @@
1
+ /**
2
+ * External MCP Server Types
3
+ * Comprehensive type system for external MCP server integration
4
+ * Following MCP 2024-11-05 specification
5
+ */
6
+ import type { JsonValue, JsonObject } from "./common.js";
7
+ import type { ChildProcess } from "child_process";
8
+ import type { Client } from "@modelcontextprotocol/sdk/client/index.js";
9
+ import type { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
10
+ /**
11
+ * Supported MCP transport protocols
12
+ */
13
+ export type MCPTransportType = "stdio" | "sse" | "websocket";
14
+ /**
15
+ * External MCP server configuration for process spawning
16
+ */
17
+ export interface ExternalMCPServerConfig {
18
+ /** Unique identifier for the server */
19
+ id: string;
20
+ /** Command to execute (e.g., 'npx', 'node', 'python') */
21
+ command: string;
22
+ /** Arguments to pass to the command */
23
+ args: string[];
24
+ /** Environment variables for the process */
25
+ env?: Record<string, string>;
26
+ /** Transport protocol to use */
27
+ transport: MCPTransportType;
28
+ /** Connection timeout in milliseconds (default: 10000) */
29
+ timeout?: number;
30
+ /** Maximum retry attempts for connection (default: 3) */
31
+ retries?: number;
32
+ /** Health check interval in milliseconds (default: 30000) */
33
+ healthCheckInterval?: number;
34
+ /** Whether to automatically restart on failure (default: true) */
35
+ autoRestart?: boolean;
36
+ /** Working directory for the process */
37
+ cwd?: string;
38
+ /** URL for SSE/WebSocket transports */
39
+ url?: string;
40
+ /** Additional metadata */
41
+ metadata?: Record<string, JsonValue>;
42
+ }
43
+ /**
44
+ * Runtime state of an external MCP server instance
45
+ */
46
+ export interface ExternalMCPServerInstance {
47
+ /** Server configuration */
48
+ config: ExternalMCPServerConfig;
49
+ /** Child process (for stdio transport) */
50
+ process: ChildProcess | null;
51
+ /** MCP client instance */
52
+ client: Client | null;
53
+ /** Transport instance */
54
+ transport: Transport | null;
55
+ /** Current server status */
56
+ status: ExternalMCPServerStatus;
57
+ /** Last error message if any */
58
+ lastError?: string;
59
+ /** When the server was started */
60
+ startTime?: Date;
61
+ /** When the server was last seen healthy */
62
+ lastHealthCheck?: Date;
63
+ /** Number of reconnection attempts */
64
+ reconnectAttempts: number;
65
+ /** Maximum reconnection attempts before giving up */
66
+ maxReconnectAttempts: number;
67
+ /** Available tools from this server */
68
+ tools: Map<string, ExternalMCPToolInfo>;
69
+ /** Server capabilities reported by MCP */
70
+ capabilities?: Record<string, JsonValue>;
71
+ /** Health monitoring timer */
72
+ healthTimer?: NodeJS.Timeout;
73
+ /** Restart backoff timer */
74
+ restartTimer?: NodeJS.Timeout;
75
+ /** Performance metrics */
76
+ metrics: {
77
+ totalConnections: number;
78
+ totalDisconnections: number;
79
+ totalErrors: number;
80
+ totalToolCalls: number;
81
+ averageResponseTime: number;
82
+ lastResponseTime: number;
83
+ };
84
+ }
85
+ /**
86
+ * External MCP server status states
87
+ */
88
+ export type ExternalMCPServerStatus = "initializing" | "connecting" | "connected" | "disconnected" | "failed" | "restarting" | "stopping" | "stopped";
89
+ /**
90
+ * Tool information from external MCP server
91
+ */
92
+ export interface ExternalMCPToolInfo {
93
+ /** Tool name */
94
+ name: string;
95
+ /** Tool description */
96
+ description: string;
97
+ /** Server ID that provides this tool */
98
+ serverId: string;
99
+ /** Input schema (JSON Schema) */
100
+ inputSchema?: JsonObject;
101
+ /** Whether the tool is currently available */
102
+ isAvailable: boolean;
103
+ /** Tool metadata */
104
+ metadata?: Record<string, JsonValue>;
105
+ /** When the tool was last successfully called */
106
+ lastCalled?: Date;
107
+ /** Tool execution statistics */
108
+ stats: {
109
+ totalCalls: number;
110
+ successfulCalls: number;
111
+ failedCalls: number;
112
+ averageExecutionTime: number;
113
+ lastExecutionTime: number;
114
+ };
115
+ }
116
+ /**
117
+ * External MCP server health status
118
+ */
119
+ export interface ExternalMCPServerHealth {
120
+ /** Server ID */
121
+ serverId: string;
122
+ /** Whether the server is healthy */
123
+ isHealthy: boolean;
124
+ /** Current status */
125
+ status: ExternalMCPServerStatus;
126
+ /** When the health check was performed */
127
+ checkedAt: Date;
128
+ /** Response time for health check */
129
+ responseTime?: number;
130
+ /** Number of available tools */
131
+ toolCount: number;
132
+ /** Any health issues detected */
133
+ issues: string[];
134
+ /** Performance metrics */
135
+ performance: {
136
+ uptime: number;
137
+ memoryUsage?: number;
138
+ cpuUsage?: number;
139
+ averageResponseTime: number;
140
+ };
141
+ }
142
+ /**
143
+ * External MCP server configuration validation result
144
+ */
145
+ export interface ExternalMCPConfigValidation {
146
+ /** Whether the configuration is valid */
147
+ isValid: boolean;
148
+ /** Validation errors */
149
+ errors: string[];
150
+ /** Validation warnings */
151
+ warnings: string[];
152
+ /** Suggestions for improvement */
153
+ suggestions: string[];
154
+ }
155
+ /**
156
+ * External MCP server operation result
157
+ */
158
+ export interface ExternalMCPOperationResult<T = unknown> {
159
+ /** Whether the operation was successful */
160
+ success: boolean;
161
+ /** Result data if successful */
162
+ data?: T;
163
+ /** Error message if failed */
164
+ error?: string;
165
+ /** Server ID */
166
+ serverId?: string;
167
+ /** Operation duration in milliseconds */
168
+ duration?: number;
169
+ /** Additional metadata */
170
+ metadata?: {
171
+ timestamp: number;
172
+ operation: string;
173
+ [key: string]: JsonValue;
174
+ };
175
+ }
176
+ /**
177
+ * External MCP tool execution context
178
+ */
179
+ export interface ExternalMCPToolContext {
180
+ /** Execution session ID */
181
+ sessionId: string;
182
+ /** User ID if available */
183
+ userId?: string;
184
+ /** Server ID executing the tool */
185
+ serverId: string;
186
+ /** Tool name being executed */
187
+ toolName: string;
188
+ /** Execution timeout in milliseconds */
189
+ timeout?: number;
190
+ /** Additional context data */
191
+ metadata?: Record<string, JsonValue>;
192
+ }
193
+ /**
194
+ * External MCP tool execution result
195
+ */
196
+ export interface ExternalMCPToolResult {
197
+ /** Whether the execution was successful */
198
+ success: boolean;
199
+ /** Result data if successful */
200
+ data?: unknown;
201
+ /** Error message if failed */
202
+ error?: string;
203
+ /** Execution duration in milliseconds */
204
+ duration: number;
205
+ /** Tool execution metadata */
206
+ metadata?: {
207
+ toolName: string;
208
+ serverId: string;
209
+ timestamp: number;
210
+ [key: string]: JsonValue;
211
+ };
212
+ }
213
+ /**
214
+ * External MCP server events
215
+ */
216
+ export interface ExternalMCPServerEvents {
217
+ /** Server status changed */
218
+ statusChanged: {
219
+ serverId: string;
220
+ oldStatus: ExternalMCPServerStatus;
221
+ newStatus: ExternalMCPServerStatus;
222
+ timestamp: Date;
223
+ };
224
+ /** Server connected successfully */
225
+ connected: {
226
+ serverId: string;
227
+ toolCount: number;
228
+ timestamp: Date;
229
+ };
230
+ /** Server disconnected */
231
+ disconnected: {
232
+ serverId: string;
233
+ reason?: string;
234
+ timestamp: Date;
235
+ };
236
+ /** Server failed */
237
+ failed: {
238
+ serverId: string;
239
+ error: string;
240
+ timestamp: Date;
241
+ };
242
+ /** Tool discovered */
243
+ toolDiscovered: {
244
+ serverId: string;
245
+ toolName: string;
246
+ toolInfo: ExternalMCPToolInfo;
247
+ timestamp: Date;
248
+ };
249
+ /** Tool removed */
250
+ toolRemoved: {
251
+ serverId: string;
252
+ toolName: string;
253
+ timestamp: Date;
254
+ };
255
+ /** Health check completed */
256
+ healthCheck: {
257
+ serverId: string;
258
+ health: ExternalMCPServerHealth;
259
+ timestamp: Date;
260
+ };
261
+ }
262
+ /**
263
+ * External MCP manager configuration
264
+ */
265
+ export interface ExternalMCPManagerConfig {
266
+ /** Maximum number of concurrent servers */
267
+ maxServers?: number;
268
+ /** Default timeout for operations */
269
+ defaultTimeout?: number;
270
+ /** Default health check interval */
271
+ defaultHealthCheckInterval?: number;
272
+ /** Whether to enable automatic restart */
273
+ enableAutoRestart?: boolean;
274
+ /** Maximum restart attempts per server */
275
+ maxRestartAttempts?: number;
276
+ /** Restart backoff multiplier */
277
+ restartBackoffMultiplier?: number;
278
+ /** Whether to enable performance monitoring */
279
+ enablePerformanceMonitoring?: boolean;
280
+ /** Log level for external MCP operations */
281
+ logLevel?: "debug" | "info" | "warn" | "error";
282
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * External MCP Server Types
3
+ * Comprehensive type system for external MCP server integration
4
+ * Following MCP 2024-11-05 specification
5
+ */
6
+ export {};
@@ -73,7 +73,6 @@ export interface GenerateResult {
73
73
  name: string;
74
74
  input: Record<string, unknown>;
75
75
  output: unknown;
76
- duration: number;
77
76
  }>;
78
77
  enhancedWithTools?: boolean;
79
78
  availableTools?: Array<{
@@ -11,6 +11,7 @@ export type { ToolArgs, ToolContext, ToolResult, ToolDefinition, SimpleTool, Ava
11
11
  export type { AISDKModel, ProviderError, TokenUsage, AnalyticsData, EvaluationData, ProviderConfig, } from "./providers.js";
12
12
  export type { BaseCommandArgs, GenerateCommandArgs, MCPCommandArgs, ModelsCommandArgs, CommandResult, GenerateResult, StreamChunk, } from "./cli.js";
13
13
  export type { MCPTransportType, MCPServerStatus, MCPDiscoveredServer, MCPConnectedServer, MCPServerConfig, MCPToolInfo, MCPServerMetadata, MCPToolMetadata, MCPServerRegistryEntry, } from "./mcpTypes.js";
14
+ export type { ExternalMCPServerConfig, ExternalMCPServerInstance, ExternalMCPServerStatus, ExternalMCPToolInfo, ExternalMCPServerHealth, ExternalMCPConfigValidation, ExternalMCPOperationResult, ExternalMCPToolContext, ExternalMCPToolResult, ExternalMCPServerEvents, ExternalMCPManagerConfig, } from "./externalMcp.js";
14
15
  export type { ModelCapability, ModelUseCase, ModelFilter, ModelResolutionContext, ModelStats, ModelPricing, } from "./providers.js";
15
16
  export type { ToolCallResults, ToolCalls, StreamAnalyticsData, } from "./streamTypes.js";
16
17
  export type { DomainType, DomainConfig, DomainTemplate, DomainConfigOptions, DomainEvaluationCriteria, DomainValidationRule, } from "./domainTypes.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juspay/neurolink",
3
- "version": "7.12.0",
3
+ "version": "7.14.0",
4
4
  "description": "Universal AI Development Platform with working MCP integration, multi-provider support, and professional CLI. Built-in tools operational, 58+ external MCP servers discoverable. Connect to filesystem, GitHub, database operations, and more. Build, test, and deploy AI applications with 9 major providers: OpenAI, Anthropic, Google AI, AWS Bedrock, Azure, Hugging Face, Ollama, and Mistral AI.",
5
5
  "author": {
6
6
  "name": "Juspay Technologies",