@juspay/neurolink 3.0.1 → 4.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 (232) hide show
  1. package/CHANGELOG.md +66 -6
  2. package/README.md +318 -27
  3. package/dist/agent/direct-tools.d.ts +6 -6
  4. package/dist/chat/client-utils.d.ts +92 -0
  5. package/dist/chat/client-utils.js +298 -0
  6. package/dist/chat/index.d.ts +27 -0
  7. package/dist/chat/index.js +41 -0
  8. package/dist/chat/session-storage.d.ts +77 -0
  9. package/dist/chat/session-storage.js +233 -0
  10. package/dist/chat/session.d.ts +95 -0
  11. package/dist/chat/session.js +257 -0
  12. package/dist/chat/sse-handler.d.ts +49 -0
  13. package/dist/chat/sse-handler.js +266 -0
  14. package/dist/chat/types.d.ts +73 -0
  15. package/dist/chat/types.js +5 -0
  16. package/dist/chat/websocket-chat-handler.d.ts +36 -0
  17. package/dist/chat/websocket-chat-handler.js +262 -0
  18. package/dist/cli/commands/config.js +12 -12
  19. package/dist/cli/commands/mcp.js +3 -4
  20. package/dist/cli/index.d.ts +0 -7
  21. package/dist/cli/index.js +247 -28
  22. package/dist/config/configManager.d.ts +60 -0
  23. package/dist/config/configManager.js +300 -0
  24. package/dist/config/types.d.ts +136 -0
  25. package/dist/config/types.js +43 -0
  26. package/dist/core/analytics.d.ts +23 -0
  27. package/dist/core/analytics.js +131 -0
  28. package/dist/core/constants.d.ts +41 -0
  29. package/dist/core/constants.js +50 -0
  30. package/dist/core/defaults.d.ts +18 -0
  31. package/dist/core/defaults.js +29 -0
  32. package/dist/core/evaluation-config.d.ts +29 -0
  33. package/dist/core/evaluation-config.js +144 -0
  34. package/dist/core/evaluation-providers.d.ts +30 -0
  35. package/dist/core/evaluation-providers.js +187 -0
  36. package/dist/core/evaluation.d.ts +117 -0
  37. package/dist/core/evaluation.js +528 -0
  38. package/dist/core/factory.js +33 -25
  39. package/dist/core/types.d.ts +165 -6
  40. package/dist/core/types.js +3 -4
  41. package/dist/index.d.ts +9 -4
  42. package/dist/index.js +25 -4
  43. package/dist/lib/agent/direct-tools.d.ts +6 -6
  44. package/dist/lib/chat/client-utils.d.ts +92 -0
  45. package/dist/lib/chat/client-utils.js +298 -0
  46. package/dist/lib/chat/index.d.ts +27 -0
  47. package/dist/lib/chat/index.js +41 -0
  48. package/dist/lib/chat/session-storage.d.ts +77 -0
  49. package/dist/lib/chat/session-storage.js +233 -0
  50. package/dist/lib/chat/session.d.ts +95 -0
  51. package/dist/lib/chat/session.js +257 -0
  52. package/dist/lib/chat/sse-handler.d.ts +49 -0
  53. package/dist/lib/chat/sse-handler.js +266 -0
  54. package/dist/lib/chat/types.d.ts +73 -0
  55. package/dist/lib/chat/types.js +5 -0
  56. package/dist/lib/chat/websocket-chat-handler.d.ts +36 -0
  57. package/dist/lib/chat/websocket-chat-handler.js +262 -0
  58. package/dist/lib/config/configManager.d.ts +60 -0
  59. package/dist/lib/config/configManager.js +300 -0
  60. package/dist/lib/config/types.d.ts +136 -0
  61. package/dist/lib/config/types.js +43 -0
  62. package/dist/lib/core/analytics.d.ts +23 -0
  63. package/dist/lib/core/analytics.js +131 -0
  64. package/dist/lib/core/constants.d.ts +41 -0
  65. package/dist/lib/core/constants.js +50 -0
  66. package/dist/lib/core/defaults.d.ts +18 -0
  67. package/dist/lib/core/defaults.js +29 -0
  68. package/dist/lib/core/evaluation-config.d.ts +29 -0
  69. package/dist/lib/core/evaluation-config.js +144 -0
  70. package/dist/lib/core/evaluation-providers.d.ts +30 -0
  71. package/dist/lib/core/evaluation-providers.js +187 -0
  72. package/dist/lib/core/evaluation.d.ts +117 -0
  73. package/dist/lib/core/evaluation.js +528 -0
  74. package/dist/lib/core/factory.js +33 -26
  75. package/dist/lib/core/types.d.ts +165 -6
  76. package/dist/lib/core/types.js +3 -4
  77. package/dist/lib/index.d.ts +9 -4
  78. package/dist/lib/index.js +25 -4
  79. package/dist/lib/mcp/contracts/mcpContract.d.ts +118 -0
  80. package/dist/lib/mcp/contracts/mcpContract.js +5 -0
  81. package/dist/lib/mcp/dynamic-chain-executor.d.ts +201 -0
  82. package/dist/lib/mcp/dynamic-chain-executor.js +489 -0
  83. package/dist/lib/mcp/dynamic-orchestrator.d.ts +109 -0
  84. package/dist/lib/mcp/dynamic-orchestrator.js +351 -0
  85. package/dist/lib/mcp/error-manager.d.ts +254 -0
  86. package/dist/lib/mcp/error-manager.js +501 -0
  87. package/dist/lib/mcp/error-recovery.d.ts +158 -0
  88. package/dist/lib/mcp/error-recovery.js +405 -0
  89. package/dist/lib/mcp/function-calling.js +11 -3
  90. package/dist/lib/mcp/health-monitor.d.ts +256 -0
  91. package/dist/lib/mcp/health-monitor.js +621 -0
  92. package/dist/lib/mcp/logging.js +5 -0
  93. package/dist/lib/mcp/neurolink-mcp-client.js +2 -1
  94. package/dist/lib/mcp/orchestrator.d.ts +136 -5
  95. package/dist/lib/mcp/orchestrator.js +332 -16
  96. package/dist/lib/mcp/registry.d.ts +71 -16
  97. package/dist/lib/mcp/registry.js +104 -6
  98. package/dist/lib/mcp/semaphore-manager.d.ts +137 -0
  99. package/dist/lib/mcp/semaphore-manager.js +329 -0
  100. package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.d.ts +2 -2
  101. package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.js +5 -4
  102. package/dist/lib/mcp/session-manager.d.ts +186 -0
  103. package/dist/lib/mcp/session-manager.js +400 -0
  104. package/dist/lib/mcp/session-persistence.d.ts +93 -0
  105. package/dist/lib/mcp/session-persistence.js +298 -0
  106. package/dist/lib/mcp/tool-integration.js +1 -1
  107. package/dist/lib/mcp/tool-registry.d.ts +55 -34
  108. package/dist/lib/mcp/tool-registry.js +111 -97
  109. package/dist/lib/mcp/transport-manager.d.ts +153 -0
  110. package/dist/lib/mcp/transport-manager.js +330 -0
  111. package/dist/lib/mcp/unified-mcp.js +6 -1
  112. package/dist/lib/mcp/unified-registry.d.ts +54 -5
  113. package/dist/lib/mcp/unified-registry.js +139 -6
  114. package/dist/lib/neurolink.d.ts +101 -0
  115. package/dist/lib/neurolink.js +147 -1
  116. package/dist/lib/providers/agent-enhanced-provider.d.ts +11 -2
  117. package/dist/lib/providers/agent-enhanced-provider.js +86 -15
  118. package/dist/lib/providers/amazonBedrock.d.ts +9 -1
  119. package/dist/lib/providers/amazonBedrock.js +26 -2
  120. package/dist/lib/providers/analytics-helper.d.ts +53 -0
  121. package/dist/lib/providers/analytics-helper.js +151 -0
  122. package/dist/lib/providers/anthropic.d.ts +11 -1
  123. package/dist/lib/providers/anthropic.js +29 -4
  124. package/dist/lib/providers/azureOpenAI.d.ts +3 -1
  125. package/dist/lib/providers/azureOpenAI.js +28 -4
  126. package/dist/lib/providers/function-calling-provider.d.ts +9 -1
  127. package/dist/lib/providers/function-calling-provider.js +14 -1
  128. package/dist/lib/providers/googleAIStudio.d.ts +15 -1
  129. package/dist/lib/providers/googleAIStudio.js +32 -2
  130. package/dist/lib/providers/googleVertexAI.d.ts +9 -1
  131. package/dist/lib/providers/googleVertexAI.js +31 -2
  132. package/dist/lib/providers/huggingFace.d.ts +3 -1
  133. package/dist/lib/providers/huggingFace.js +26 -3
  134. package/dist/lib/providers/mcp-provider.d.ts +9 -1
  135. package/dist/lib/providers/mcp-provider.js +12 -0
  136. package/dist/lib/providers/mistralAI.d.ts +3 -1
  137. package/dist/lib/providers/mistralAI.js +25 -2
  138. package/dist/lib/providers/ollama.d.ts +3 -1
  139. package/dist/lib/providers/ollama.js +27 -4
  140. package/dist/lib/providers/openAI.d.ts +15 -1
  141. package/dist/lib/providers/openAI.js +32 -2
  142. package/dist/lib/proxy/proxy-fetch.js +8 -7
  143. package/dist/lib/services/streaming/streaming-manager.d.ts +29 -0
  144. package/dist/lib/services/streaming/streaming-manager.js +244 -0
  145. package/dist/lib/services/types.d.ts +155 -0
  146. package/dist/lib/services/types.js +2 -0
  147. package/dist/lib/services/websocket/websocket-server.d.ts +34 -0
  148. package/dist/lib/services/websocket/websocket-server.js +304 -0
  149. package/dist/lib/telemetry/index.d.ts +15 -0
  150. package/dist/lib/telemetry/index.js +22 -0
  151. package/dist/lib/telemetry/telemetry-service.d.ts +47 -0
  152. package/dist/lib/telemetry/telemetry-service.js +259 -0
  153. package/dist/lib/utils/streaming-utils.d.ts +67 -0
  154. package/dist/lib/utils/streaming-utils.js +201 -0
  155. package/dist/mcp/contracts/mcpContract.d.ts +118 -0
  156. package/dist/mcp/contracts/mcpContract.js +5 -0
  157. package/dist/mcp/dynamic-chain-executor.d.ts +201 -0
  158. package/dist/mcp/dynamic-chain-executor.js +489 -0
  159. package/dist/mcp/dynamic-orchestrator.d.ts +109 -0
  160. package/dist/mcp/dynamic-orchestrator.js +351 -0
  161. package/dist/mcp/error-manager.d.ts +254 -0
  162. package/dist/mcp/error-manager.js +501 -0
  163. package/dist/mcp/error-recovery.d.ts +158 -0
  164. package/dist/mcp/error-recovery.js +405 -0
  165. package/dist/mcp/function-calling.js +11 -3
  166. package/dist/mcp/health-monitor.d.ts +256 -0
  167. package/dist/mcp/health-monitor.js +621 -0
  168. package/dist/mcp/logging.js +5 -0
  169. package/dist/mcp/neurolink-mcp-client.js +2 -1
  170. package/dist/mcp/orchestrator.d.ts +136 -5
  171. package/dist/mcp/orchestrator.js +332 -16
  172. package/dist/mcp/plugins/core/neurolink-mcp.json +15 -15
  173. package/dist/mcp/registry.d.ts +71 -16
  174. package/dist/mcp/registry.js +104 -6
  175. package/dist/mcp/semaphore-manager.d.ts +137 -0
  176. package/dist/mcp/semaphore-manager.js +329 -0
  177. package/dist/mcp/servers/ai-providers/ai-workflow-tools.d.ts +2 -2
  178. package/dist/mcp/servers/ai-providers/ai-workflow-tools.js +5 -4
  179. package/dist/mcp/session-manager.d.ts +186 -0
  180. package/dist/mcp/session-manager.js +400 -0
  181. package/dist/mcp/session-persistence.d.ts +93 -0
  182. package/dist/mcp/session-persistence.js +299 -0
  183. package/dist/mcp/tool-integration.js +1 -1
  184. package/dist/mcp/tool-registry.d.ts +55 -34
  185. package/dist/mcp/tool-registry.js +111 -97
  186. package/dist/mcp/transport-manager.d.ts +153 -0
  187. package/dist/mcp/transport-manager.js +331 -0
  188. package/dist/mcp/unified-mcp.js +6 -1
  189. package/dist/mcp/unified-registry.d.ts +54 -5
  190. package/dist/mcp/unified-registry.js +139 -6
  191. package/dist/neurolink.d.ts +101 -0
  192. package/dist/neurolink.js +147 -1
  193. package/dist/providers/agent-enhanced-provider.d.ts +11 -2
  194. package/dist/providers/agent-enhanced-provider.js +86 -15
  195. package/dist/providers/amazonBedrock.d.ts +9 -1
  196. package/dist/providers/amazonBedrock.js +26 -2
  197. package/dist/providers/analytics-helper.d.ts +53 -0
  198. package/dist/providers/analytics-helper.js +151 -0
  199. package/dist/providers/anthropic.d.ts +11 -1
  200. package/dist/providers/anthropic.js +29 -4
  201. package/dist/providers/azureOpenAI.d.ts +3 -1
  202. package/dist/providers/azureOpenAI.js +29 -4
  203. package/dist/providers/function-calling-provider.d.ts +9 -1
  204. package/dist/providers/function-calling-provider.js +14 -1
  205. package/dist/providers/googleAIStudio.d.ts +15 -1
  206. package/dist/providers/googleAIStudio.js +32 -2
  207. package/dist/providers/googleVertexAI.d.ts +9 -1
  208. package/dist/providers/googleVertexAI.js +31 -2
  209. package/dist/providers/huggingFace.d.ts +3 -1
  210. package/dist/providers/huggingFace.js +26 -3
  211. package/dist/providers/mcp-provider.d.ts +9 -1
  212. package/dist/providers/mcp-provider.js +12 -0
  213. package/dist/providers/mistralAI.d.ts +3 -1
  214. package/dist/providers/mistralAI.js +25 -2
  215. package/dist/providers/ollama.d.ts +3 -1
  216. package/dist/providers/ollama.js +27 -4
  217. package/dist/providers/openAI.d.ts +15 -1
  218. package/dist/providers/openAI.js +33 -2
  219. package/dist/proxy/proxy-fetch.js +8 -7
  220. package/dist/services/streaming/streaming-manager.d.ts +29 -0
  221. package/dist/services/streaming/streaming-manager.js +244 -0
  222. package/dist/services/types.d.ts +155 -0
  223. package/dist/services/types.js +2 -0
  224. package/dist/services/websocket/websocket-server.d.ts +34 -0
  225. package/dist/services/websocket/websocket-server.js +304 -0
  226. package/dist/telemetry/index.d.ts +15 -0
  227. package/dist/telemetry/index.js +22 -0
  228. package/dist/telemetry/telemetry-service.d.ts +47 -0
  229. package/dist/telemetry/telemetry-service.js +261 -0
  230. package/dist/utils/streaming-utils.d.ts +67 -0
  231. package/dist/utils/streaming-utils.js +201 -0
  232. package/package.json +245 -228
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Phase 2: Enhanced Streaming Infrastructure
3
+ * Streaming utilities for progress tracking and metadata enhancement
4
+ */
5
+ import type { StreamingProgressData, StreamingMetadata, ProgressCallback, EnhancedStreamTextOptions } from "../core/types.js";
6
+ export interface UIProgressHandler {
7
+ onProgress: (progress: StreamingProgressData) => void;
8
+ onComplete: (metadata: StreamingMetadata) => void;
9
+ onError: (error: Error) => void;
10
+ }
11
+ export interface StreamingStats {
12
+ totalChunks: number;
13
+ totalBytes: number;
14
+ duration: number;
15
+ averageChunkSize: number;
16
+ provider: string;
17
+ model: string;
18
+ }
19
+ /**
20
+ * Enhanced streaming utilities for progress tracking and metadata
21
+ */
22
+ export declare class StreamingEnhancer {
23
+ /**
24
+ * Add progress tracking to a readable stream
25
+ */
26
+ static addProgressTracking(stream: ReadableStream, callback?: ProgressCallback, options?: {
27
+ streamId?: string;
28
+ bufferSize?: number;
29
+ }): ReadableStream;
30
+ /**
31
+ * Add metadata headers to streaming response
32
+ */
33
+ static addMetadataHeaders(response: Response, stats: StreamingStats): Response;
34
+ /**
35
+ * Create progress callback for UI integration
36
+ */
37
+ static createProgressCallback(ui: UIProgressHandler): ProgressCallback;
38
+ /**
39
+ * Estimate remaining time based on current progress
40
+ */
41
+ static estimateRemainingTime(totalBytes: number, elapsedTime: number, chunkCount: number): number | undefined;
42
+ /**
43
+ * Create enhanced streaming configuration
44
+ */
45
+ static createStreamingConfig(options: EnhancedStreamTextOptions): {
46
+ progressTracking: boolean;
47
+ callback?: ProgressCallback;
48
+ metadata: boolean;
49
+ bufferSize: number;
50
+ headers: boolean;
51
+ };
52
+ }
53
+ /**
54
+ * Streaming performance monitor for debugging and optimization
55
+ */
56
+ export declare class StreamingMonitor {
57
+ private static activeStreams;
58
+ static registerStream(streamId: string): void;
59
+ static updateStream(streamId: string, progress: StreamingProgressData): void;
60
+ static completeStream(streamId: string): void;
61
+ static getActiveStreams(): StreamingProgressData[];
62
+ static getStreamStats(): {
63
+ activeCount: number;
64
+ totalBytesActive: number;
65
+ averageProgress: number;
66
+ };
67
+ }
@@ -0,0 +1,201 @@
1
+ /**
2
+ * Phase 2: Enhanced Streaming Infrastructure
3
+ * Streaming utilities for progress tracking and metadata enhancement
4
+ */
5
+ /**
6
+ * Enhanced streaming utilities for progress tracking and metadata
7
+ */
8
+ export class StreamingEnhancer {
9
+ /**
10
+ * Add progress tracking to a readable stream
11
+ */
12
+ static addProgressTracking(stream, callback, options) {
13
+ const streamId = options?.streamId || `stream_${Date.now()}`;
14
+ const startTime = Date.now();
15
+ let chunkCount = 0;
16
+ let totalBytes = 0;
17
+ let lastProgressTime = startTime;
18
+ return new ReadableStream({
19
+ start(controller) {
20
+ if (callback) {
21
+ callback({
22
+ chunkCount: 0,
23
+ totalBytes: 0,
24
+ chunkSize: 0,
25
+ elapsedTime: 0,
26
+ streamId,
27
+ phase: "initializing",
28
+ });
29
+ }
30
+ },
31
+ async pull(controller) {
32
+ const reader = stream.getReader();
33
+ try {
34
+ const { done, value } = await reader.read();
35
+ if (done) {
36
+ controller.close();
37
+ if (callback) {
38
+ const elapsedTime = Date.now() - startTime;
39
+ callback({
40
+ chunkCount,
41
+ totalBytes,
42
+ chunkSize: totalBytes > 0 ? Math.round(totalBytes / chunkCount) : 0,
43
+ elapsedTime,
44
+ streamId,
45
+ phase: "complete",
46
+ });
47
+ }
48
+ return;
49
+ }
50
+ // Track progress
51
+ chunkCount++;
52
+ const chunkSize = value
53
+ ? new TextEncoder().encode(value.toString()).length
54
+ : 0;
55
+ totalBytes += chunkSize;
56
+ const currentTime = Date.now();
57
+ const elapsedTime = currentTime - startTime;
58
+ const timeSinceLastProgress = currentTime - lastProgressTime;
59
+ // Call progress callback
60
+ if (callback && (timeSinceLastProgress > 100 || chunkCount === 1)) {
61
+ // Throttle to max 10 calls/second
62
+ const estimatedRemaining = StreamingEnhancer.estimateRemainingTime(totalBytes, elapsedTime, chunkCount);
63
+ callback({
64
+ chunkCount,
65
+ totalBytes,
66
+ chunkSize,
67
+ elapsedTime,
68
+ estimatedRemaining,
69
+ streamId,
70
+ phase: "streaming",
71
+ });
72
+ lastProgressTime = currentTime;
73
+ }
74
+ controller.enqueue(value);
75
+ }
76
+ catch (error) {
77
+ controller.error(error);
78
+ if (callback) {
79
+ callback({
80
+ chunkCount,
81
+ totalBytes,
82
+ chunkSize: 0,
83
+ elapsedTime: Date.now() - startTime,
84
+ streamId,
85
+ phase: "error",
86
+ });
87
+ }
88
+ }
89
+ finally {
90
+ reader.releaseLock();
91
+ }
92
+ },
93
+ });
94
+ }
95
+ /**
96
+ * Add metadata headers to streaming response
97
+ */
98
+ static addMetadataHeaders(response, stats) {
99
+ const headers = new Headers(response.headers);
100
+ headers.set("X-Streaming-Chunks", stats.totalChunks.toString());
101
+ headers.set("X-Streaming-Bytes", stats.totalBytes.toString());
102
+ headers.set("X-Streaming-Duration", stats.duration.toString());
103
+ headers.set("X-Streaming-Avg-Chunk-Size", stats.averageChunkSize.toString());
104
+ headers.set("X-Streaming-Provider", stats.provider);
105
+ headers.set("X-Streaming-Model", stats.model);
106
+ headers.set("X-Streaming-Throughput", Math.round(stats.totalBytes / (stats.duration / 1000)).toString());
107
+ return new Response(response.body, {
108
+ status: response.status,
109
+ statusText: response.statusText,
110
+ headers,
111
+ });
112
+ }
113
+ /**
114
+ * Create progress callback for UI integration
115
+ */
116
+ static createProgressCallback(ui) {
117
+ return (progress) => {
118
+ try {
119
+ ui.onProgress(progress);
120
+ if (progress.phase === "complete") {
121
+ ui.onComplete({
122
+ startTime: Date.now() - progress.elapsedTime,
123
+ endTime: Date.now(),
124
+ totalDuration: progress.elapsedTime,
125
+ averageChunkSize: Math.round(progress.totalBytes / progress.chunkCount),
126
+ maxChunkSize: progress.chunkSize, // This would need to be tracked better in real implementation
127
+ minChunkSize: progress.chunkSize, // This would need to be tracked better in real implementation
128
+ throughputBytesPerSecond: Math.round(progress.totalBytes / (progress.elapsedTime / 1000)),
129
+ streamingProvider: "unknown", // Would be passed from provider
130
+ modelUsed: "unknown", // Would be passed from provider
131
+ });
132
+ }
133
+ }
134
+ catch (error) {
135
+ ui.onError(error);
136
+ }
137
+ };
138
+ }
139
+ /**
140
+ * Estimate remaining time based on current progress
141
+ */
142
+ static estimateRemainingTime(totalBytes, elapsedTime, chunkCount) {
143
+ if (elapsedTime < 1000 || chunkCount < 3) {
144
+ return undefined; // Not enough data for estimation
145
+ }
146
+ const bytesPerMs = totalBytes / elapsedTime;
147
+ const avgChunkSize = totalBytes / chunkCount;
148
+ // Rough estimation assuming similar chunk sizes going forward
149
+ // This is a simple heuristic - real implementation might be more sophisticated
150
+ const estimatedTotalBytes = avgChunkSize * (chunkCount + 10); // Assume 10 more chunks
151
+ const remainingBytes = estimatedTotalBytes - totalBytes;
152
+ return Math.max(0, remainingBytes / bytesPerMs);
153
+ }
154
+ /**
155
+ * Create enhanced streaming configuration
156
+ */
157
+ static createStreamingConfig(options) {
158
+ return {
159
+ progressTracking: options.enableProgressTracking ?? false,
160
+ callback: options.progressCallback,
161
+ metadata: options.includeStreamingMetadata ?? false,
162
+ bufferSize: options.streamingBufferSize ?? 8192,
163
+ headers: options.enableStreamingHeaders ?? false,
164
+ };
165
+ }
166
+ }
167
+ /**
168
+ * Streaming performance monitor for debugging and optimization
169
+ */
170
+ export class StreamingMonitor {
171
+ static activeStreams = new Map();
172
+ static registerStream(streamId) {
173
+ this.activeStreams.set(streamId, {
174
+ chunkCount: 0,
175
+ totalBytes: 0,
176
+ chunkSize: 0,
177
+ elapsedTime: 0,
178
+ streamId,
179
+ phase: "initializing",
180
+ });
181
+ }
182
+ static updateStream(streamId, progress) {
183
+ this.activeStreams.set(streamId, progress);
184
+ }
185
+ static completeStream(streamId) {
186
+ this.activeStreams.delete(streamId);
187
+ }
188
+ static getActiveStreams() {
189
+ return Array.from(this.activeStreams.values());
190
+ }
191
+ static getStreamStats() {
192
+ const streams = this.getActiveStreams();
193
+ return {
194
+ activeCount: streams.length,
195
+ totalBytesActive: streams.reduce((sum, s) => sum + s.totalBytes, 0),
196
+ averageProgress: streams.length > 0
197
+ ? streams.reduce((sum, s) => sum + s.elapsedTime, 0) / streams.length
198
+ : 0,
199
+ };
200
+ }
201
+ }
@@ -0,0 +1,118 @@
1
+ /**
2
+ * MCP Contract - Core Type Definitions
3
+ * Industry standard camelCase interfaces for maximum flexibility
4
+ */
5
+ /**
6
+ * Generic execution context for MCP operations
7
+ * All properties optional for maximum flexibility
8
+ */
9
+ export interface ExecutionContext<T = Record<string, unknown>> {
10
+ sessionId?: string;
11
+ userId?: string;
12
+ config?: T;
13
+ metadata?: Record<string, unknown>;
14
+ cacheOptions?: CacheOptions;
15
+ fallbackOptions?: FallbackOptions;
16
+ timeoutMs?: number;
17
+ startTime?: number;
18
+ }
19
+ /**
20
+ * Cache configuration options
21
+ */
22
+ export interface CacheOptions {
23
+ enabled?: boolean;
24
+ ttlMs?: number;
25
+ strategy?: "memory" | "writeThrough" | "cacheAside";
26
+ }
27
+ /**
28
+ * Fallback configuration options
29
+ */
30
+ export interface FallbackOptions {
31
+ enabled?: boolean;
32
+ maxAttempts?: number;
33
+ delayMs?: number;
34
+ circuitBreaker?: boolean;
35
+ }
36
+ /**
37
+ * Tool information with extensibility
38
+ */
39
+ export interface ToolInfo {
40
+ name: string;
41
+ description?: string;
42
+ category?: string;
43
+ serverId?: string;
44
+ inputSchema?: Record<string, unknown>;
45
+ outputSchema?: Record<string, unknown>;
46
+ [key: string]: unknown;
47
+ }
48
+ /**
49
+ * Discovered MCP server/plugin definition
50
+ */
51
+ export interface DiscoveredMcp<TTools = Record<string, unknown>> {
52
+ metadata: McpMetadata;
53
+ tools?: TTools;
54
+ capabilities?: string[];
55
+ version?: string;
56
+ configuration?: Record<string, string | number | boolean>;
57
+ [key: string]: unknown;
58
+ }
59
+ /**
60
+ * MCP server metadata
61
+ */
62
+ export interface McpMetadata {
63
+ name: string;
64
+ description?: string;
65
+ version?: string;
66
+ author?: string;
67
+ homepage?: string;
68
+ repository?: string;
69
+ }
70
+ /**
71
+ * Tool definition schema
72
+ */
73
+ export interface ToolDefinition {
74
+ description?: string;
75
+ inputSchema?: Record<string, unknown>;
76
+ outputSchema?: Record<string, unknown>;
77
+ category?: string;
78
+ examples?: Array<{
79
+ input: Record<string, unknown>;
80
+ output: Record<string, unknown>;
81
+ description?: string;
82
+ }>;
83
+ }
84
+ /**
85
+ * Tool execution result
86
+ */
87
+ export interface ToolExecutionResult<T = unknown> {
88
+ result: T;
89
+ context?: ExecutionContext;
90
+ performance?: {
91
+ duration: number;
92
+ tokensUsed?: number;
93
+ cost?: number;
94
+ };
95
+ validation?: ValidationResult;
96
+ cached?: boolean;
97
+ fallback?: boolean;
98
+ }
99
+ /**
100
+ * Validation result for runtime checks
101
+ */
102
+ export interface ValidationResult {
103
+ valid: boolean;
104
+ missing: string[];
105
+ warnings: string[];
106
+ recommendations: string[];
107
+ }
108
+ /**
109
+ * Provider status information
110
+ */
111
+ export interface ProviderStatus {
112
+ available: boolean;
113
+ lastCheck: number;
114
+ reason?: string;
115
+ model?: string;
116
+ cost?: number;
117
+ latencyMs?: number;
118
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * MCP Contract - Core Type Definitions
3
+ * Industry standard camelCase interfaces for maximum flexibility
4
+ */
5
+ export {};
@@ -0,0 +1,201 @@
1
+ /**
2
+ * Dynamic AI Tool Chain Executor
3
+ * Allows AI to dynamically decide tool execution sequences based on context and results
4
+ */
5
+ import type { MCPOrchestrator } from "./orchestrator.js";
6
+ import type { MCPRegistry } from "./registry.js";
7
+ import type { NeuroLinkExecutionContext } from "./factory.js";
8
+ import { ErrorManager } from "./error-manager.js";
9
+ /**
10
+ * Tool execution result with metadata
11
+ */
12
+ export interface ToolExecutionResult {
13
+ toolName: string;
14
+ success: boolean;
15
+ result?: any;
16
+ error?: Error;
17
+ timestamp: number;
18
+ executionTime: number;
19
+ context?: Record<string, any>;
20
+ }
21
+ /**
22
+ * Chain execution step
23
+ */
24
+ export interface ChainStep {
25
+ stepId: string;
26
+ toolName: string;
27
+ parameters: any;
28
+ reasoning: string;
29
+ confidence: number;
30
+ expectedOutcome: string;
31
+ }
32
+ /**
33
+ * Chain execution context
34
+ */
35
+ export interface ChainExecutionContext {
36
+ goal: string;
37
+ currentStep: number;
38
+ totalSteps?: number;
39
+ executionHistory: ToolExecutionResult[];
40
+ accumulatedContext: Record<string, any>;
41
+ userContext?: NeuroLinkExecutionContext;
42
+ maxSteps: number;
43
+ aiModel?: string;
44
+ }
45
+ /**
46
+ * Chain execution result
47
+ */
48
+ export interface ChainExecutionResult {
49
+ success: boolean;
50
+ goal: string;
51
+ totalSteps: number;
52
+ executionTime: number;
53
+ results: ToolExecutionResult[];
54
+ finalResult?: any;
55
+ reasoning: string;
56
+ error?: Error;
57
+ metadata: {
58
+ toolsUsed: string[];
59
+ averageConfidence: number;
60
+ contextEvolution: Record<string, any>[];
61
+ };
62
+ }
63
+ /**
64
+ * AI Tool Chain Planner interface
65
+ */
66
+ export interface AIChainPlanner {
67
+ name: string;
68
+ planNextStep(goal: string, availableTools: Array<{
69
+ name: string;
70
+ description: string;
71
+ inputSchema: any;
72
+ }>, executionHistory: ToolExecutionResult[], accumulatedContext: Record<string, any>): Promise<ChainStep | null>;
73
+ evaluateResult(step: ChainStep, result: ToolExecutionResult, goal: string): Promise<{
74
+ goalAchieved: boolean;
75
+ confidence: number;
76
+ nextAction: "continue" | "retry" | "abort" | "complete";
77
+ reasoning: string;
78
+ }>;
79
+ }
80
+ /**
81
+ * Simple AI Chain Planner using heuristics
82
+ */
83
+ export declare class HeuristicChainPlanner implements AIChainPlanner {
84
+ name: string;
85
+ planNextStep(goal: string, availableTools: Array<{
86
+ name: string;
87
+ description: string;
88
+ inputSchema: any;
89
+ }>, executionHistory: ToolExecutionResult[], accumulatedContext: Record<string, any>): Promise<ChainStep | null>;
90
+ evaluateResult(step: ChainStep, result: ToolExecutionResult, goal: string): Promise<{
91
+ goalAchieved: boolean;
92
+ confidence: number;
93
+ nextAction: "continue" | "retry" | "abort" | "complete";
94
+ reasoning: string;
95
+ }>;
96
+ private generateParameters;
97
+ }
98
+ /**
99
+ * Advanced AI Chain Planner using actual AI model
100
+ */
101
+ export declare class AIModelChainPlanner implements AIChainPlanner {
102
+ name: string;
103
+ private aiModel;
104
+ constructor(aiModel?: string);
105
+ planNextStep(goal: string, availableTools: Array<{
106
+ name: string;
107
+ description: string;
108
+ inputSchema: any;
109
+ }>, executionHistory: ToolExecutionResult[], accumulatedContext: Record<string, any>): Promise<ChainStep | null>;
110
+ evaluateResult(step: ChainStep, result: ToolExecutionResult, goal: string): Promise<{
111
+ goalAchieved: boolean;
112
+ confidence: number;
113
+ nextAction: "continue" | "retry" | "abort" | "complete";
114
+ reasoning: string;
115
+ }>;
116
+ private buildPlanningPrompt;
117
+ private buildEvaluationPrompt;
118
+ private callAIModel;
119
+ private parseAIResponse;
120
+ private parseEvaluationResponse;
121
+ }
122
+ /**
123
+ * Dynamic Chain Executor
124
+ */
125
+ export declare class DynamicChainExecutor {
126
+ private orchestrator;
127
+ private registry;
128
+ private errorManager;
129
+ private planner;
130
+ constructor(orchestrator: MCPOrchestrator, registry: MCPRegistry, errorManager: ErrorManager, planner?: AIChainPlanner);
131
+ /**
132
+ * Execute dynamic tool chain to achieve a goal
133
+ *
134
+ * @param goal The goal to achieve
135
+ * @param initialContext Initial context data
136
+ * @param userContext User execution context
137
+ * @param options Execution options
138
+ * @returns Chain execution result
139
+ */
140
+ executeChain(goal: string, initialContext?: Record<string, any>, userContext?: NeuroLinkExecutionContext, options?: {
141
+ maxSteps?: number;
142
+ aiModel?: string;
143
+ timeout?: number;
144
+ }): Promise<ChainExecutionResult>;
145
+ /**
146
+ * Execute chain steps iteratively
147
+ *
148
+ * @private
149
+ */
150
+ private executeChainSteps;
151
+ /**
152
+ * Execute a single step
153
+ *
154
+ * @private
155
+ */
156
+ private executeStep;
157
+ /**
158
+ * Update accumulated context with new result
159
+ *
160
+ * @private
161
+ */
162
+ private updateAccumulatedContext;
163
+ /**
164
+ * Calculate average confidence across execution history
165
+ *
166
+ * @private
167
+ */
168
+ private calculateAverageConfidence;
169
+ /**
170
+ * Track context evolution through execution
171
+ *
172
+ * @private
173
+ */
174
+ private trackContextEvolution;
175
+ /**
176
+ * Set AI planner
177
+ *
178
+ * @param planner AI chain planner instance
179
+ */
180
+ setPlanner(planner: AIChainPlanner): void;
181
+ /**
182
+ * Get current planner
183
+ *
184
+ * @returns Current AI chain planner
185
+ */
186
+ getPlanner(): AIChainPlanner;
187
+ }
188
+ /**
189
+ * Default dynamic chain executor instance
190
+ */
191
+ export declare let defaultDynamicChainExecutor: DynamicChainExecutor | null;
192
+ /**
193
+ * Initialize default dynamic chain executor
194
+ *
195
+ * @param orchestrator MCP orchestrator
196
+ * @param registry Tool registry
197
+ * @param errorManager Error manager
198
+ * @param planner Optional AI planner
199
+ * @returns Dynamic chain executor instance
200
+ */
201
+ export declare function initializeDynamicChainExecutor(orchestrator: MCPOrchestrator, registry: MCPRegistry, errorManager: ErrorManager, planner?: AIChainPlanner): DynamicChainExecutor;