@juspay/neurolink 3.0.0 → 4.0.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.
- package/CHANGELOG.md +62 -4
- package/README.md +235 -2
- package/dist/agent/direct-tools.d.ts +6 -6
- package/dist/chat/client-utils.d.ts +92 -0
- package/dist/chat/client-utils.js +298 -0
- package/dist/chat/index.d.ts +27 -0
- package/dist/chat/index.js +41 -0
- package/dist/chat/session-storage.d.ts +77 -0
- package/dist/chat/session-storage.js +233 -0
- package/dist/chat/session.d.ts +95 -0
- package/dist/chat/session.js +257 -0
- package/dist/chat/sse-handler.d.ts +49 -0
- package/dist/chat/sse-handler.js +266 -0
- package/dist/chat/types.d.ts +73 -0
- package/dist/chat/types.js +5 -0
- package/dist/chat/websocket-chat-handler.d.ts +36 -0
- package/dist/chat/websocket-chat-handler.js +262 -0
- package/dist/cli/commands/config.js +12 -12
- package/dist/cli/commands/mcp.js +3 -4
- package/dist/cli/index.d.ts +0 -7
- package/dist/cli/index.js +256 -27
- package/dist/config/configManager.d.ts +60 -0
- package/dist/config/configManager.js +300 -0
- package/dist/config/types.d.ts +136 -0
- package/dist/config/types.js +43 -0
- package/dist/core/analytics.d.ts +23 -0
- package/dist/core/analytics.js +131 -0
- package/dist/core/constants.d.ts +41 -0
- package/dist/core/constants.js +50 -0
- package/dist/core/defaults.d.ts +18 -0
- package/dist/core/defaults.js +29 -0
- package/dist/core/evaluation-config.d.ts +29 -0
- package/dist/core/evaluation-config.js +144 -0
- package/dist/core/evaluation-providers.d.ts +30 -0
- package/dist/core/evaluation-providers.js +187 -0
- package/dist/core/evaluation.d.ts +117 -0
- package/dist/core/evaluation.js +528 -0
- package/dist/core/factory.js +33 -25
- package/dist/core/types.d.ts +165 -6
- package/dist/core/types.js +3 -4
- package/dist/index.d.ts +9 -4
- package/dist/index.js +25 -4
- package/dist/lib/agent/direct-tools.d.ts +6 -6
- package/dist/lib/chat/client-utils.d.ts +92 -0
- package/dist/lib/chat/client-utils.js +298 -0
- package/dist/lib/chat/index.d.ts +27 -0
- package/dist/lib/chat/index.js +41 -0
- package/dist/lib/chat/session-storage.d.ts +77 -0
- package/dist/lib/chat/session-storage.js +233 -0
- package/dist/lib/chat/session.d.ts +95 -0
- package/dist/lib/chat/session.js +257 -0
- package/dist/lib/chat/sse-handler.d.ts +49 -0
- package/dist/lib/chat/sse-handler.js +266 -0
- package/dist/lib/chat/types.d.ts +73 -0
- package/dist/lib/chat/types.js +5 -0
- package/dist/lib/chat/websocket-chat-handler.d.ts +36 -0
- package/dist/lib/chat/websocket-chat-handler.js +262 -0
- package/dist/lib/config/configManager.d.ts +60 -0
- package/dist/lib/config/configManager.js +300 -0
- package/dist/lib/config/types.d.ts +136 -0
- package/dist/lib/config/types.js +43 -0
- package/dist/lib/core/analytics.d.ts +23 -0
- package/dist/lib/core/analytics.js +131 -0
- package/dist/lib/core/constants.d.ts +41 -0
- package/dist/lib/core/constants.js +50 -0
- package/dist/lib/core/defaults.d.ts +18 -0
- package/dist/lib/core/defaults.js +29 -0
- package/dist/lib/core/evaluation-config.d.ts +29 -0
- package/dist/lib/core/evaluation-config.js +144 -0
- package/dist/lib/core/evaluation-providers.d.ts +30 -0
- package/dist/lib/core/evaluation-providers.js +187 -0
- package/dist/lib/core/evaluation.d.ts +117 -0
- package/dist/lib/core/evaluation.js +528 -0
- package/dist/lib/core/factory.js +33 -26
- package/dist/lib/core/types.d.ts +165 -6
- package/dist/lib/core/types.js +3 -4
- package/dist/lib/index.d.ts +9 -4
- package/dist/lib/index.js +25 -4
- package/dist/lib/mcp/contracts/mcpContract.d.ts +118 -0
- package/dist/lib/mcp/contracts/mcpContract.js +5 -0
- package/dist/lib/mcp/function-calling.js +11 -3
- package/dist/lib/mcp/logging.js +5 -0
- package/dist/lib/mcp/neurolink-mcp-client.js +2 -1
- package/dist/lib/mcp/orchestrator.js +18 -9
- package/dist/lib/mcp/registry.d.ts +49 -16
- package/dist/lib/mcp/registry.js +80 -6
- package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.js +5 -4
- package/dist/lib/mcp/tool-integration.js +1 -1
- package/dist/lib/mcp/tool-registry.d.ts +55 -34
- package/dist/lib/mcp/tool-registry.js +111 -97
- package/dist/lib/mcp/unified-mcp.js +6 -1
- package/dist/lib/mcp/unified-registry.d.ts +12 -4
- package/dist/lib/mcp/unified-registry.js +17 -4
- package/dist/lib/neurolink.d.ts +28 -0
- package/dist/lib/neurolink.js +48 -4
- package/dist/lib/providers/agent-enhanced-provider.d.ts +11 -2
- package/dist/lib/providers/agent-enhanced-provider.js +86 -15
- package/dist/lib/providers/amazonBedrock.d.ts +9 -1
- package/dist/lib/providers/amazonBedrock.js +26 -2
- package/dist/lib/providers/analytics-helper.d.ts +53 -0
- package/dist/lib/providers/analytics-helper.js +151 -0
- package/dist/lib/providers/anthropic.d.ts +11 -1
- package/dist/lib/providers/anthropic.js +29 -4
- package/dist/lib/providers/azureOpenAI.d.ts +3 -1
- package/dist/lib/providers/azureOpenAI.js +28 -4
- package/dist/lib/providers/function-calling-provider.d.ts +9 -1
- package/dist/lib/providers/function-calling-provider.js +14 -1
- package/dist/lib/providers/googleAIStudio.d.ts +15 -1
- package/dist/lib/providers/googleAIStudio.js +32 -2
- package/dist/lib/providers/googleVertexAI.d.ts +9 -1
- package/dist/lib/providers/googleVertexAI.js +31 -2
- package/dist/lib/providers/huggingFace.d.ts +3 -1
- package/dist/lib/providers/huggingFace.js +26 -3
- package/dist/lib/providers/mcp-provider.d.ts +9 -1
- package/dist/lib/providers/mcp-provider.js +12 -0
- package/dist/lib/providers/mistralAI.d.ts +3 -1
- package/dist/lib/providers/mistralAI.js +25 -2
- package/dist/lib/providers/ollama.d.ts +3 -1
- package/dist/lib/providers/ollama.js +27 -4
- package/dist/lib/providers/openAI.d.ts +15 -1
- package/dist/lib/providers/openAI.js +32 -2
- package/dist/lib/proxy/proxy-fetch.js +8 -7
- package/dist/lib/services/streaming/streaming-manager.d.ts +29 -0
- package/dist/lib/services/streaming/streaming-manager.js +244 -0
- package/dist/lib/services/types.d.ts +155 -0
- package/dist/lib/services/types.js +2 -0
- package/dist/lib/services/websocket/websocket-server.d.ts +34 -0
- package/dist/lib/services/websocket/websocket-server.js +304 -0
- package/dist/lib/telemetry/index.d.ts +15 -0
- package/dist/lib/telemetry/index.js +22 -0
- package/dist/lib/telemetry/telemetry-service.d.ts +47 -0
- package/dist/lib/telemetry/telemetry-service.js +259 -0
- package/dist/lib/utils/streaming-utils.d.ts +67 -0
- package/dist/lib/utils/streaming-utils.js +201 -0
- package/dist/mcp/contracts/mcpContract.d.ts +118 -0
- package/dist/mcp/contracts/mcpContract.js +5 -0
- package/dist/mcp/function-calling.js +11 -3
- package/dist/mcp/logging.js +5 -0
- package/dist/mcp/neurolink-mcp-client.js +2 -1
- package/dist/mcp/orchestrator.js +18 -9
- package/dist/mcp/registry.d.ts +49 -16
- package/dist/mcp/registry.js +80 -6
- package/dist/mcp/servers/ai-providers/ai-workflow-tools.d.ts +2 -2
- package/dist/mcp/servers/ai-providers/ai-workflow-tools.js +5 -4
- package/dist/mcp/tool-integration.js +1 -1
- package/dist/mcp/tool-registry.d.ts +55 -34
- package/dist/mcp/tool-registry.js +111 -97
- package/dist/mcp/unified-mcp.js +6 -1
- package/dist/mcp/unified-registry.d.ts +12 -4
- package/dist/mcp/unified-registry.js +17 -4
- package/dist/neurolink.d.ts +28 -0
- package/dist/neurolink.js +48 -4
- package/dist/providers/agent-enhanced-provider.d.ts +11 -2
- package/dist/providers/agent-enhanced-provider.js +86 -15
- package/dist/providers/amazonBedrock.d.ts +9 -1
- package/dist/providers/amazonBedrock.js +26 -2
- package/dist/providers/analytics-helper.d.ts +53 -0
- package/dist/providers/analytics-helper.js +151 -0
- package/dist/providers/anthropic.d.ts +11 -1
- package/dist/providers/anthropic.js +29 -4
- package/dist/providers/azureOpenAI.d.ts +3 -1
- package/dist/providers/azureOpenAI.js +29 -4
- package/dist/providers/function-calling-provider.d.ts +9 -1
- package/dist/providers/function-calling-provider.js +14 -1
- package/dist/providers/googleAIStudio.d.ts +15 -1
- package/dist/providers/googleAIStudio.js +32 -2
- package/dist/providers/googleVertexAI.d.ts +9 -1
- package/dist/providers/googleVertexAI.js +31 -2
- package/dist/providers/huggingFace.d.ts +3 -1
- package/dist/providers/huggingFace.js +26 -3
- package/dist/providers/mcp-provider.d.ts +9 -1
- package/dist/providers/mcp-provider.js +12 -0
- package/dist/providers/mistralAI.d.ts +3 -1
- package/dist/providers/mistralAI.js +25 -2
- package/dist/providers/ollama.d.ts +3 -1
- package/dist/providers/ollama.js +27 -4
- package/dist/providers/openAI.d.ts +15 -1
- package/dist/providers/openAI.js +33 -2
- package/dist/proxy/proxy-fetch.js +8 -7
- package/dist/services/streaming/streaming-manager.d.ts +29 -0
- package/dist/services/streaming/streaming-manager.js +244 -0
- package/dist/services/types.d.ts +155 -0
- package/dist/services/types.js +2 -0
- package/dist/services/websocket/websocket-server.d.ts +34 -0
- package/dist/services/websocket/websocket-server.js +304 -0
- package/dist/telemetry/index.d.ts +15 -0
- package/dist/telemetry/index.js +22 -0
- package/dist/telemetry/telemetry-service.d.ts +47 -0
- package/dist/telemetry/telemetry-service.js +261 -0
- package/dist/utils/streaming-utils.d.ts +67 -0
- package/dist/utils/streaming-utils.js +201 -0
- package/package.json +18 -2
|
@@ -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
|
+
}
|
|
@@ -156,7 +156,10 @@ export async function getAvailableFunctionTools() {
|
|
|
156
156
|
let functionName;
|
|
157
157
|
let originalFunctionName;
|
|
158
158
|
// Convert server name to underscore format to check if it's embedded in tool name
|
|
159
|
-
const
|
|
159
|
+
const serverName = typeof toolInfo.serverId === "string"
|
|
160
|
+
? toolInfo.serverId
|
|
161
|
+
: "unknown";
|
|
162
|
+
const sanitizedServerCheck = serverName.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
160
163
|
if (toolInfo.name.includes(sanitizedServerCheck) ||
|
|
161
164
|
toolInfo.name.endsWith("-tools") ||
|
|
162
165
|
toolInfo.name.startsWith("github_com_") ||
|
|
@@ -206,7 +209,10 @@ export async function getAvailableFunctionTools() {
|
|
|
206
209
|
}
|
|
207
210
|
else {
|
|
208
211
|
// Tool name doesn't include server info, create compound name
|
|
209
|
-
const
|
|
212
|
+
const serverName = typeof toolInfo.serverId === "string"
|
|
213
|
+
? toolInfo.serverId
|
|
214
|
+
: "unknown";
|
|
215
|
+
const sanitizedServerName = serverName.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
210
216
|
const sanitizedToolName = toolInfo.name.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
211
217
|
// Check if it's a filesystem tool from MCP
|
|
212
218
|
if (sanitizedServerName.includes("modelcontextprotocol") &&
|
|
@@ -277,7 +283,9 @@ export async function getAvailableFunctionTools() {
|
|
|
277
283
|
tools.push(aiTool);
|
|
278
284
|
// Store mapping for execution - CRITICAL: Use sanitized functionName as key
|
|
279
285
|
toolMap.set(functionName, {
|
|
280
|
-
serverId: toolInfo.
|
|
286
|
+
serverId: typeof toolInfo.serverId === "string"
|
|
287
|
+
? toolInfo.serverId
|
|
288
|
+
: "unknown",
|
|
281
289
|
toolName: toolInfo.name,
|
|
282
290
|
});
|
|
283
291
|
mcpLogger.debug(`[${functionTag}] Converted tool: ${functionName} (original: ${originalFunctionName})`);
|
package/dist/mcp/logging.js
CHANGED
|
@@ -17,6 +17,11 @@ class MCPLogger {
|
|
|
17
17
|
this.logLevel = level;
|
|
18
18
|
}
|
|
19
19
|
shouldLog(level) {
|
|
20
|
+
// CRITICAL: Respect CLI debug flag - hide all logs except errors unless debugging
|
|
21
|
+
const isDebugMode = process.argv.includes("--debug");
|
|
22
|
+
if (!isDebugMode && level !== "error") {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
20
25
|
const levels = ["debug", "info", "warn", "error"];
|
|
21
26
|
return levels.indexOf(level) >= levels.indexOf(this.logLevel);
|
|
22
27
|
}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { EventEmitter } from "events";
|
|
7
7
|
import { logger } from "../utils/logger.js";
|
|
8
8
|
import { v4 as uuidv4 } from "uuid";
|
|
9
|
+
import { DEFAULT_MAX_TOKENS } from "../core/constants.js";
|
|
9
10
|
/**
|
|
10
11
|
* NeuroLink MCP Client with Automatic Tool Detection
|
|
11
12
|
*/
|
|
@@ -381,7 +382,7 @@ Please provide a natural response based on the tool results.`;
|
|
|
381
382
|
const response = await this.provider.generateText({
|
|
382
383
|
prompt: enhancedPrompt,
|
|
383
384
|
temperature: 0.7,
|
|
384
|
-
maxTokens:
|
|
385
|
+
maxTokens: DEFAULT_MAX_TOKENS,
|
|
385
386
|
});
|
|
386
387
|
return response?.text || toolResultsText;
|
|
387
388
|
}
|
package/dist/mcp/orchestrator.js
CHANGED
|
@@ -26,7 +26,10 @@ export class MCPOrchestrator {
|
|
|
26
26
|
async initializeDefaultServers() {
|
|
27
27
|
try {
|
|
28
28
|
await this.registry.registerServer(aiCoreServer.id, aiCoreServer);
|
|
29
|
-
|
|
29
|
+
// Only log in debug mode
|
|
30
|
+
if (process.env.NEUROLINK_DEBUG === "true") {
|
|
31
|
+
console.log("[Orchestrator] Initialized with AI Core Server");
|
|
32
|
+
}
|
|
30
33
|
}
|
|
31
34
|
catch (error) {
|
|
32
35
|
console.warn("[Orchestrator] Failed to register AI Core Server:", error);
|
|
@@ -44,10 +47,14 @@ export class MCPOrchestrator {
|
|
|
44
47
|
async executeTool(toolName, params, contextRequest = {}, options = {}) {
|
|
45
48
|
// Create execution context
|
|
46
49
|
const context = this.contextManager.createContext(contextRequest);
|
|
47
|
-
|
|
50
|
+
if (process.env.NEUROLINK_DEBUG === "true") {
|
|
51
|
+
console.log(`[Orchestrator] Executing tool '${toolName}' in session ${context.sessionId}`);
|
|
52
|
+
}
|
|
48
53
|
// Execute tool through registry
|
|
49
54
|
const result = await this.registry.executeTool(toolName, params, context);
|
|
50
|
-
|
|
55
|
+
if (process.env.NEUROLINK_DEBUG === "true") {
|
|
56
|
+
console.log(`[Orchestrator] Tool '${toolName}' execution ${result.success ? "completed" : "failed"}`);
|
|
57
|
+
}
|
|
51
58
|
return result;
|
|
52
59
|
}
|
|
53
60
|
/**
|
|
@@ -92,9 +99,10 @@ export class MCPOrchestrator {
|
|
|
92
99
|
results.set(stepId, stepResult);
|
|
93
100
|
stepsExecuted++;
|
|
94
101
|
if (!stepResult.success) {
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
102
|
+
const error = stepResult.error;
|
|
103
|
+
const errorMessage = error instanceof Error
|
|
104
|
+
? error.message
|
|
105
|
+
: String(error) || "Unknown error";
|
|
98
106
|
errors.set(stepId, errorMessage);
|
|
99
107
|
if (stopOnError) {
|
|
100
108
|
console.error(`[Orchestrator] Pipeline ${pipelineId} stopped due to error in step ${stepId}`);
|
|
@@ -301,9 +309,10 @@ export class MCPOrchestrator {
|
|
|
301
309
|
const result = await this.registry.executeTool(step.toolName, step.params, context);
|
|
302
310
|
results.set(stepId, result);
|
|
303
311
|
if (!result.success) {
|
|
304
|
-
const
|
|
305
|
-
|
|
306
|
-
|
|
312
|
+
const error = result.error;
|
|
313
|
+
const errorMessage = error instanceof Error
|
|
314
|
+
? error.message
|
|
315
|
+
: String(error) || "Unknown error";
|
|
307
316
|
errors.set(stepId, errorMessage);
|
|
308
317
|
}
|
|
309
318
|
}
|
package/dist/mcp/registry.d.ts
CHANGED
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* MCP Registry -
|
|
2
|
+
* MCP Registry - Industry Standard Interface with camelCase
|
|
3
3
|
*/
|
|
4
|
-
import type {
|
|
4
|
+
import type { DiscoveredMcp, ExecutionContext, ToolInfo } from "./contracts/mcpContract.js";
|
|
5
|
+
/**
|
|
6
|
+
* MCP Registry interface with optional methods for maximum flexibility
|
|
7
|
+
*/
|
|
8
|
+
export interface McpRegistry {
|
|
9
|
+
registerServer?(serverId: string, serverConfig?: unknown, context?: ExecutionContext): Promise<void>;
|
|
10
|
+
executeTool?<T = unknown>(toolName: string, args?: unknown, context?: ExecutionContext): Promise<T>;
|
|
11
|
+
listTools?(context?: ExecutionContext): Promise<ToolInfo[]>;
|
|
12
|
+
}
|
|
5
13
|
/**
|
|
6
14
|
* Simple MCP registry for plugin management
|
|
15
|
+
* Maintains backward compatibility with existing code
|
|
7
16
|
*/
|
|
8
|
-
export declare class MCPRegistry {
|
|
17
|
+
export declare class MCPRegistry implements McpRegistry {
|
|
9
18
|
private plugins;
|
|
10
19
|
/**
|
|
11
20
|
* Register a plugin
|
|
12
21
|
*/
|
|
13
|
-
register(plugin:
|
|
22
|
+
register(plugin: DiscoveredMcp): void;
|
|
14
23
|
/**
|
|
15
24
|
* Unregister a plugin
|
|
16
25
|
*/
|
|
@@ -18,11 +27,11 @@ export declare class MCPRegistry {
|
|
|
18
27
|
/**
|
|
19
28
|
* Get a plugin
|
|
20
29
|
*/
|
|
21
|
-
get(name: string):
|
|
30
|
+
get(name: string): DiscoveredMcp | undefined;
|
|
22
31
|
/**
|
|
23
32
|
* List all plugins
|
|
24
33
|
*/
|
|
25
|
-
list():
|
|
34
|
+
list(): DiscoveredMcp[];
|
|
26
35
|
/**
|
|
27
36
|
* Check if plugin exists
|
|
28
37
|
*/
|
|
@@ -31,17 +40,41 @@ export declare class MCPRegistry {
|
|
|
31
40
|
* Clear all plugins
|
|
32
41
|
*/
|
|
33
42
|
clear(): void;
|
|
43
|
+
/**
|
|
44
|
+
* Register a server (compatible with new interface)
|
|
45
|
+
*/
|
|
46
|
+
registerServer(serverId: string, serverConfig?: unknown, context?: ExecutionContext): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Execute a tool (mock implementation for tests)
|
|
49
|
+
*/
|
|
50
|
+
executeTool<T = unknown>(toolName: string, args?: unknown, context?: ExecutionContext): Promise<T>;
|
|
51
|
+
/**
|
|
52
|
+
* List all tools (compatible with new interface)
|
|
53
|
+
*/
|
|
54
|
+
listTools(context?: ExecutionContext): Promise<ToolInfo[]>;
|
|
55
|
+
/**
|
|
56
|
+
* Register a server (legacy sync version)
|
|
57
|
+
*/
|
|
58
|
+
registerServerSync(plugin: DiscoveredMcp): void;
|
|
59
|
+
/**
|
|
60
|
+
* Execute a tool (legacy sync version)
|
|
61
|
+
*/
|
|
62
|
+
executeToolSync(toolName: string, args?: unknown): any;
|
|
63
|
+
/**
|
|
64
|
+
* List all tools (legacy sync version)
|
|
65
|
+
*/
|
|
66
|
+
listToolsSync(): Array<{
|
|
67
|
+
name: string;
|
|
68
|
+
description?: string;
|
|
69
|
+
}>;
|
|
34
70
|
}
|
|
35
71
|
/**
|
|
36
|
-
*
|
|
72
|
+
* Enhanced MCP Registry implementation with config integration
|
|
73
|
+
* Will be implemented in Phase 3.2
|
|
37
74
|
*/
|
|
38
|
-
export declare
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
preferredSource?: string;
|
|
44
|
-
fallbackEnabled?: boolean;
|
|
45
|
-
validateBeforeExecution?: boolean;
|
|
46
|
-
timeoutMs?: number;
|
|
75
|
+
export declare class McpRegistryImpl implements McpRegistry {
|
|
76
|
+
private baseRegistry;
|
|
77
|
+
registerServer(serverId: string, serverConfig?: unknown, context?: ExecutionContext): Promise<void>;
|
|
78
|
+
executeTool<T = unknown>(toolName: string, args?: unknown, context?: ExecutionContext): Promise<T>;
|
|
79
|
+
listTools(context?: ExecutionContext): Promise<ToolInfo[]>;
|
|
47
80
|
}
|