@juspay/neurolink 6.1.0 → 6.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -6
- package/dist/cli/commands/config.d.ts +13 -13
- package/dist/cli/index.js +3 -9
- package/dist/core/analytics.d.ts +11 -1
- package/dist/core/analytics.js +2 -2
- package/dist/core/base-provider.js +4 -18
- package/dist/core/dynamic-models.d.ts +8 -8
- package/dist/core/factory.js +3 -11
- package/dist/index.d.ts +2 -4
- package/dist/index.js +2 -11
- package/dist/lib/core/analytics.d.ts +11 -1
- package/dist/lib/core/analytics.js +2 -2
- package/dist/lib/core/base-provider.js +4 -18
- package/dist/lib/core/dynamic-models.d.ts +8 -8
- package/dist/lib/core/factory.js +3 -11
- package/dist/lib/index.d.ts +2 -4
- package/dist/lib/index.js +2 -11
- package/dist/lib/mcp/factory.d.ts +1 -1
- package/dist/lib/mcp/index.d.ts +7 -19
- package/dist/lib/mcp/index.js +15 -56
- package/dist/lib/neurolink.d.ts +1 -9
- package/dist/lib/neurolink.js +21 -70
- package/dist/lib/providers/amazon-bedrock.js +5 -16
- package/dist/lib/providers/anthropic-baseprovider.js +3 -21
- package/dist/lib/providers/anthropic.js +4 -7
- package/dist/lib/providers/azure-openai.js +4 -2
- package/dist/lib/providers/google-vertex.js +5 -9
- package/dist/lib/providers/huggingFace.js +5 -10
- package/dist/lib/providers/mistral.js +5 -8
- package/dist/lib/providers/openAI.js +4 -7
- package/dist/lib/utils/providerConfig.d.ts +117 -0
- package/dist/lib/utils/providerConfig.js +353 -0
- package/dist/lib/utils/providerUtils.d.ts +2 -1
- package/dist/lib/utils/providerUtils.js +53 -36
- package/dist/lib/utils/timeout.d.ts +72 -1
- package/dist/lib/utils/timeout.js +203 -2
- package/dist/mcp/factory.d.ts +1 -1
- package/dist/mcp/index.d.ts +7 -19
- package/dist/mcp/index.js +15 -56
- package/dist/neurolink.d.ts +1 -9
- package/dist/neurolink.js +21 -70
- package/dist/providers/amazon-bedrock.js +5 -16
- package/dist/providers/anthropic-baseprovider.js +3 -21
- package/dist/providers/anthropic.js +4 -7
- package/dist/providers/azure-openai.js +4 -2
- package/dist/providers/google-vertex.js +5 -9
- package/dist/providers/huggingFace.js +5 -10
- package/dist/providers/mistral.js +5 -8
- package/dist/providers/openAI.js +4 -7
- package/dist/utils/providerConfig.d.ts +117 -0
- package/dist/utils/providerConfig.js +353 -0
- package/dist/utils/providerUtils.d.ts +2 -1
- package/dist/utils/providerUtils.js +53 -36
- package/dist/utils/timeout.d.ts +72 -1
- package/dist/utils/timeout.js +203 -2
- package/package.json +1 -1
- package/dist/chat/client-utils.d.ts +0 -95
- package/dist/chat/client-utils.js +0 -315
- package/dist/chat/index.d.ts +0 -24
- package/dist/chat/index.js +0 -33
- package/dist/chat/session-storage.d.ts +0 -77
- package/dist/chat/session-storage.js +0 -233
- package/dist/chat/session.d.ts +0 -96
- package/dist/chat/session.js +0 -257
- package/dist/chat/sse-handler.d.ts +0 -49
- package/dist/chat/sse-handler.js +0 -259
- package/dist/chat/types.d.ts +0 -74
- package/dist/chat/types.js +0 -5
- package/dist/chat/websocket-chat-handler.d.ts +0 -37
- package/dist/chat/websocket-chat-handler.js +0 -262
- package/dist/cli/commands/mcp.d.ts +0 -20
- package/dist/cli/commands/mcp.js +0 -1272
- package/dist/core/defaults.d.ts +0 -19
- package/dist/core/defaults.js +0 -29
- package/dist/core/evaluation-config.d.ts +0 -29
- package/dist/core/evaluation-config.js +0 -144
- package/dist/factories/compatibility-factory.d.ts +0 -35
- package/dist/factories/compatibility-factory.js +0 -71
- package/dist/factories/provider-generate-factory.d.ts +0 -20
- package/dist/factories/provider-generate-factory.js +0 -93
- package/dist/lib/chat/client-utils.d.ts +0 -95
- package/dist/lib/chat/client-utils.js +0 -315
- package/dist/lib/chat/index.d.ts +0 -24
- package/dist/lib/chat/index.js +0 -33
- package/dist/lib/chat/session-storage.d.ts +0 -77
- package/dist/lib/chat/session-storage.js +0 -233
- package/dist/lib/chat/session.d.ts +0 -96
- package/dist/lib/chat/session.js +0 -257
- package/dist/lib/chat/sse-handler.d.ts +0 -49
- package/dist/lib/chat/sse-handler.js +0 -259
- package/dist/lib/chat/types.d.ts +0 -74
- package/dist/lib/chat/types.js +0 -5
- package/dist/lib/chat/websocket-chat-handler.d.ts +0 -37
- package/dist/lib/chat/websocket-chat-handler.js +0 -262
- package/dist/lib/core/defaults.d.ts +0 -19
- package/dist/lib/core/defaults.js +0 -29
- package/dist/lib/core/evaluation-config.d.ts +0 -29
- package/dist/lib/core/evaluation-config.js +0 -144
- package/dist/lib/factories/compatibility-factory.d.ts +0 -35
- package/dist/lib/factories/compatibility-factory.js +0 -71
- package/dist/lib/factories/provider-generate-factory.d.ts +0 -20
- package/dist/lib/factories/provider-generate-factory.js +0 -93
- package/dist/lib/mcp/adapters/plugin-bridge.d.ts +0 -40
- package/dist/lib/mcp/adapters/plugin-bridge.js +0 -89
- package/dist/lib/mcp/auto-discovery.d.ts +0 -62
- package/dist/lib/mcp/auto-discovery.js +0 -149
- package/dist/lib/mcp/client.d.ts +0 -68
- package/dist/lib/mcp/client.js +0 -248
- package/dist/lib/mcp/config.d.ts +0 -31
- package/dist/lib/mcp/config.js +0 -99
- package/dist/lib/mcp/context-manager.d.ts +0 -171
- package/dist/lib/mcp/context-manager.js +0 -362
- package/dist/lib/mcp/contracts/mcp-contract.d.ts +0 -169
- package/dist/lib/mcp/contracts/mcp-contract.js +0 -58
- package/dist/lib/mcp/core/plugin-manager.d.ts +0 -46
- package/dist/lib/mcp/core/plugin-manager.js +0 -110
- package/dist/lib/mcp/demo/plugin-demo.d.ts +0 -20
- package/dist/lib/mcp/demo/plugin-demo.js +0 -118
- package/dist/lib/mcp/dynamic-chain-executor.d.ts +0 -225
- package/dist/lib/mcp/dynamic-chain-executor.js +0 -489
- package/dist/lib/mcp/dynamic-orchestrator.d.ts +0 -115
- package/dist/lib/mcp/dynamic-orchestrator.js +0 -351
- package/dist/lib/mcp/ecosystem.d.ts +0 -75
- package/dist/lib/mcp/ecosystem.js +0 -161
- package/dist/lib/mcp/error-manager.d.ts +0 -254
- package/dist/lib/mcp/error-manager.js +0 -501
- package/dist/lib/mcp/error-recovery.d.ts +0 -159
- package/dist/lib/mcp/error-recovery.js +0 -405
- package/dist/lib/mcp/external-client.d.ts +0 -88
- package/dist/lib/mcp/external-client.js +0 -331
- package/dist/lib/mcp/external-manager.d.ts +0 -112
- package/dist/lib/mcp/external-manager.js +0 -308
- package/dist/lib/mcp/function-calling.d.ts +0 -65
- package/dist/lib/mcp/function-calling.js +0 -642
- package/dist/lib/mcp/health-monitor.d.ts +0 -257
- package/dist/lib/mcp/health-monitor.js +0 -630
- package/dist/lib/mcp/initialize-tools.d.ts +0 -29
- package/dist/lib/mcp/initialize-tools.js +0 -261
- package/dist/lib/mcp/initialize.d.ts +0 -18
- package/dist/lib/mcp/initialize.js +0 -62
- package/dist/lib/mcp/manager.d.ts +0 -68
- package/dist/lib/mcp/manager.js +0 -176
- package/dist/lib/mcp/neurolink-mcp-client.d.ts +0 -97
- package/dist/lib/mcp/neurolink-mcp-client.js +0 -462
- package/dist/lib/mcp/orchestrator.d.ts +0 -302
- package/dist/lib/mcp/orchestrator.js +0 -703
- package/dist/lib/mcp/plugin-manager.d.ts +0 -98
- package/dist/lib/mcp/plugin-manager.js +0 -296
- package/dist/lib/mcp/plugins/core/filesystem-mcp.d.ts +0 -36
- package/dist/lib/mcp/plugins/core/filesystem-mcp.js +0 -142
- package/dist/lib/mcp/plugins/filesystem-mcp.d.ts +0 -37
- package/dist/lib/mcp/plugins/filesystem-mcp.js +0 -54
- package/dist/lib/mcp/security-manager.d.ts +0 -87
- package/dist/lib/mcp/security-manager.js +0 -344
- package/dist/lib/mcp/semaphore-manager.d.ts +0 -137
- package/dist/lib/mcp/semaphore-manager.js +0 -329
- package/dist/lib/mcp/session-manager.d.ts +0 -187
- package/dist/lib/mcp/session-manager.js +0 -400
- package/dist/lib/mcp/session-persistence.d.ts +0 -93
- package/dist/lib/mcp/session-persistence.js +0 -301
- package/dist/lib/mcp/tool-integration.d.ts +0 -58
- package/dist/lib/mcp/tool-integration.js +0 -203
- package/dist/lib/mcp/transport-manager.d.ts +0 -154
- package/dist/lib/mcp/transport-manager.js +0 -334
- package/dist/lib/mcp/unified-mcp.d.ts +0 -133
- package/dist/lib/mcp/unified-mcp.js +0 -251
- package/dist/lib/mcp/unified-registry.d.ts +0 -165
- package/dist/lib/mcp/unified-registry.js +0 -538
- package/dist/lib/providers/analytics-helper.d.ts +0 -38
- package/dist/lib/providers/analytics-helper.js +0 -216
- package/dist/lib/providers/function-calling-provider.d.ts +0 -142
- package/dist/lib/providers/function-calling-provider.js +0 -630
- package/dist/lib/providers/mcp-provider.d.ts +0 -75
- package/dist/lib/providers/mcp-provider.js +0 -283
- package/dist/lib/providers/timeout-wrapper.d.ts +0 -40
- package/dist/lib/providers/timeout-wrapper.js +0 -100
- package/dist/lib/sdk/tool-extension.d.ts +0 -181
- package/dist/lib/sdk/tool-extension.js +0 -284
- package/dist/lib/services/streaming/streaming-manager.d.ts +0 -29
- package/dist/lib/services/streaming/streaming-manager.js +0 -245
- package/dist/lib/services/types.d.ts +0 -156
- package/dist/lib/services/types.js +0 -2
- package/dist/lib/services/websocket/websocket-server.d.ts +0 -34
- package/dist/lib/services/websocket/websocket-server.js +0 -305
- package/dist/lib/utils/provider-validation.d.ts +0 -36
- package/dist/lib/utils/provider-validation.js +0 -625
- package/dist/lib/utils/providerUtils-fixed.d.ts +0 -8
- package/dist/lib/utils/providerUtils-fixed.js +0 -94
- package/dist/lib/utils/streaming-utils.d.ts +0 -79
- package/dist/lib/utils/streaming-utils.js +0 -198
- package/dist/lib/utils/timeout-manager.d.ts +0 -75
- package/dist/lib/utils/timeout-manager.js +0 -244
- package/dist/mcp/adapters/plugin-bridge.d.ts +0 -40
- package/dist/mcp/adapters/plugin-bridge.js +0 -89
- package/dist/mcp/auto-discovery.d.ts +0 -62
- package/dist/mcp/auto-discovery.js +0 -149
- package/dist/mcp/client.d.ts +0 -68
- package/dist/mcp/client.js +0 -248
- package/dist/mcp/config.d.ts +0 -31
- package/dist/mcp/config.js +0 -99
- package/dist/mcp/context-manager.d.ts +0 -171
- package/dist/mcp/context-manager.js +0 -362
- package/dist/mcp/contracts/mcp-contract.d.ts +0 -169
- package/dist/mcp/contracts/mcp-contract.js +0 -58
- package/dist/mcp/core/plugin-manager.d.ts +0 -46
- package/dist/mcp/core/plugin-manager.js +0 -110
- package/dist/mcp/demo/plugin-demo.d.ts +0 -20
- package/dist/mcp/demo/plugin-demo.js +0 -118
- package/dist/mcp/dynamic-chain-executor.d.ts +0 -225
- package/dist/mcp/dynamic-chain-executor.js +0 -489
- package/dist/mcp/dynamic-orchestrator.d.ts +0 -115
- package/dist/mcp/dynamic-orchestrator.js +0 -351
- package/dist/mcp/ecosystem.d.ts +0 -75
- package/dist/mcp/ecosystem.js +0 -162
- package/dist/mcp/error-manager.d.ts +0 -254
- package/dist/mcp/error-manager.js +0 -501
- package/dist/mcp/error-recovery.d.ts +0 -159
- package/dist/mcp/error-recovery.js +0 -405
- package/dist/mcp/external-client.d.ts +0 -88
- package/dist/mcp/external-client.js +0 -331
- package/dist/mcp/external-manager.d.ts +0 -112
- package/dist/mcp/external-manager.js +0 -308
- package/dist/mcp/function-calling.d.ts +0 -65
- package/dist/mcp/function-calling.js +0 -642
- package/dist/mcp/health-monitor.d.ts +0 -257
- package/dist/mcp/health-monitor.js +0 -630
- package/dist/mcp/initialize-tools.d.ts +0 -29
- package/dist/mcp/initialize-tools.js +0 -262
- package/dist/mcp/initialize.d.ts +0 -18
- package/dist/mcp/initialize.js +0 -62
- package/dist/mcp/manager.d.ts +0 -68
- package/dist/mcp/manager.js +0 -176
- package/dist/mcp/neurolink-mcp-client.d.ts +0 -97
- package/dist/mcp/neurolink-mcp-client.js +0 -462
- package/dist/mcp/orchestrator.d.ts +0 -302
- package/dist/mcp/orchestrator.js +0 -703
- package/dist/mcp/plugin-manager.d.ts +0 -98
- package/dist/mcp/plugin-manager.js +0 -297
- package/dist/mcp/plugins/core/filesystem-mcp.d.ts +0 -36
- package/dist/mcp/plugins/core/filesystem-mcp.js +0 -142
- package/dist/mcp/plugins/core/neurolink-mcp.json +0 -17
- package/dist/mcp/plugins/filesystem-mcp.d.ts +0 -37
- package/dist/mcp/plugins/filesystem-mcp.js +0 -54
- package/dist/mcp/security-manager.d.ts +0 -87
- package/dist/mcp/security-manager.js +0 -344
- package/dist/mcp/semaphore-manager.d.ts +0 -137
- package/dist/mcp/semaphore-manager.js +0 -329
- package/dist/mcp/session-manager.d.ts +0 -187
- package/dist/mcp/session-manager.js +0 -400
- package/dist/mcp/session-persistence.d.ts +0 -93
- package/dist/mcp/session-persistence.js +0 -302
- package/dist/mcp/tool-integration.d.ts +0 -58
- package/dist/mcp/tool-integration.js +0 -203
- package/dist/mcp/transport-manager.d.ts +0 -154
- package/dist/mcp/transport-manager.js +0 -335
- package/dist/mcp/unified-mcp.d.ts +0 -133
- package/dist/mcp/unified-mcp.js +0 -251
- package/dist/mcp/unified-registry.d.ts +0 -165
- package/dist/mcp/unified-registry.js +0 -539
- package/dist/providers/analytics-helper.d.ts +0 -38
- package/dist/providers/analytics-helper.js +0 -216
- package/dist/providers/function-calling-provider.d.ts +0 -142
- package/dist/providers/function-calling-provider.js +0 -630
- package/dist/providers/mcp-provider.d.ts +0 -75
- package/dist/providers/mcp-provider.js +0 -283
- package/dist/providers/timeout-wrapper.d.ts +0 -40
- package/dist/providers/timeout-wrapper.js +0 -100
- package/dist/sdk/tool-extension.d.ts +0 -181
- package/dist/sdk/tool-extension.js +0 -284
- package/dist/services/streaming/streaming-manager.d.ts +0 -29
- package/dist/services/streaming/streaming-manager.js +0 -245
- package/dist/services/types.d.ts +0 -156
- package/dist/services/types.js +0 -2
- package/dist/services/websocket/websocket-server.d.ts +0 -34
- package/dist/services/websocket/websocket-server.js +0 -306
- package/dist/utils/provider-validation.d.ts +0 -36
- package/dist/utils/provider-validation.js +0 -625
- package/dist/utils/providerUtils-fixed.d.ts +0 -8
- package/dist/utils/providerUtils-fixed.js +0 -94
- package/dist/utils/streaming-utils.d.ts +0 -79
- package/dist/utils/streaming-utils.js +0 -198
- package/dist/utils/timeout-manager.d.ts +0 -75
- package/dist/utils/timeout-manager.js +0 -244
|
@@ -1,405 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* NeuroLink Error Recovery System
|
|
3
|
-
* Implements circuit breaker, retry strategies, and pattern detection
|
|
4
|
-
* Based on resilience patterns from reference implementations
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* Circuit breaker states
|
|
8
|
-
*/
|
|
9
|
-
export var CircuitState;
|
|
10
|
-
(function (CircuitState) {
|
|
11
|
-
CircuitState["CLOSED"] = "CLOSED";
|
|
12
|
-
CircuitState["OPEN"] = "OPEN";
|
|
13
|
-
CircuitState["HALF_OPEN"] = "HALF_OPEN";
|
|
14
|
-
})(CircuitState || (CircuitState = {}));
|
|
15
|
-
/**
|
|
16
|
-
* Circuit breaker instance
|
|
17
|
-
*/
|
|
18
|
-
class CircuitBreaker {
|
|
19
|
-
config;
|
|
20
|
-
state = CircuitState.CLOSED;
|
|
21
|
-
failures = 0;
|
|
22
|
-
successes = 0;
|
|
23
|
-
lastFailureTime = 0;
|
|
24
|
-
nextAttemptTime = 0;
|
|
25
|
-
constructor(config) {
|
|
26
|
-
this.config = config;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Check if request should be allowed
|
|
30
|
-
*/
|
|
31
|
-
canExecute() {
|
|
32
|
-
const now = Date.now();
|
|
33
|
-
switch (this.state) {
|
|
34
|
-
case CircuitState.CLOSED:
|
|
35
|
-
return true;
|
|
36
|
-
case CircuitState.OPEN:
|
|
37
|
-
if (now >= this.nextAttemptTime) {
|
|
38
|
-
this.state = CircuitState.HALF_OPEN;
|
|
39
|
-
this.successes = 0;
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
return false;
|
|
43
|
-
case CircuitState.HALF_OPEN:
|
|
44
|
-
return true;
|
|
45
|
-
default:
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Record success
|
|
51
|
-
*/
|
|
52
|
-
recordSuccess() {
|
|
53
|
-
this.failures = 0;
|
|
54
|
-
if (this.state === CircuitState.HALF_OPEN) {
|
|
55
|
-
this.successes++;
|
|
56
|
-
if (this.successes >= this.config.successThreshold) {
|
|
57
|
-
this.state = CircuitState.CLOSED;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Record failure
|
|
63
|
-
*/
|
|
64
|
-
recordFailure() {
|
|
65
|
-
const now = Date.now();
|
|
66
|
-
// Reset failure count if outside monitoring period
|
|
67
|
-
if (now - this.lastFailureTime > this.config.monitoringPeriod) {
|
|
68
|
-
this.failures = 0;
|
|
69
|
-
}
|
|
70
|
-
this.failures++;
|
|
71
|
-
this.lastFailureTime = now;
|
|
72
|
-
if (this.state === CircuitState.HALF_OPEN) {
|
|
73
|
-
this.state = CircuitState.OPEN;
|
|
74
|
-
this.nextAttemptTime = now + this.config.resetTimeout;
|
|
75
|
-
}
|
|
76
|
-
else if (this.failures >= this.config.failureThreshold) {
|
|
77
|
-
this.state = CircuitState.OPEN;
|
|
78
|
-
this.nextAttemptTime = now + this.config.resetTimeout;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Get current state
|
|
83
|
-
*/
|
|
84
|
-
getState() {
|
|
85
|
-
return this.state;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Error Recovery Manager
|
|
90
|
-
*/
|
|
91
|
-
export class ErrorRecovery {
|
|
92
|
-
circuitBreakers = new Map();
|
|
93
|
-
errorPatterns = [];
|
|
94
|
-
recoveryHistory = new Map();
|
|
95
|
-
defaultRetryConfig = {
|
|
96
|
-
maxAttempts: 3,
|
|
97
|
-
initialDelay: 1000,
|
|
98
|
-
maxDelay: 30000,
|
|
99
|
-
backoffMultiplier: 2,
|
|
100
|
-
jitter: true,
|
|
101
|
-
};
|
|
102
|
-
defaultCircuitConfig = {
|
|
103
|
-
failureThreshold: 5,
|
|
104
|
-
resetTimeout: 60000,
|
|
105
|
-
successThreshold: 2,
|
|
106
|
-
monitoringPeriod: 60000,
|
|
107
|
-
};
|
|
108
|
-
constructor() {
|
|
109
|
-
this.initializeDefaultPatterns();
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Initialize default error patterns
|
|
113
|
-
*/
|
|
114
|
-
initializeDefaultPatterns() {
|
|
115
|
-
// Network timeout pattern
|
|
116
|
-
this.addPattern({
|
|
117
|
-
id: "network-timeout",
|
|
118
|
-
name: "Network Timeout Pattern",
|
|
119
|
-
description: "Repeated network timeouts indicating connectivity issues",
|
|
120
|
-
matcher: (errors) => {
|
|
121
|
-
const recentErrors = errors.slice(-5);
|
|
122
|
-
return (recentErrors.length >= 3 &&
|
|
123
|
-
recentErrors.every((e) => e.category === "TIMEOUT_ERROR"));
|
|
124
|
-
},
|
|
125
|
-
severity: "HIGH",
|
|
126
|
-
recoveryStrategy: {
|
|
127
|
-
type: "retry",
|
|
128
|
-
config: {
|
|
129
|
-
maxAttempts: 5,
|
|
130
|
-
initialDelay: 2000,
|
|
131
|
-
maxDelay: 60000,
|
|
132
|
-
backoffMultiplier: 3,
|
|
133
|
-
jitter: true,
|
|
134
|
-
},
|
|
135
|
-
},
|
|
136
|
-
});
|
|
137
|
-
// Rate limit pattern
|
|
138
|
-
this.addPattern({
|
|
139
|
-
id: "rate-limit",
|
|
140
|
-
name: "Rate Limit Pattern",
|
|
141
|
-
description: "API rate limit errors",
|
|
142
|
-
matcher: (errors) => {
|
|
143
|
-
const lastError = errors[errors.length - 1];
|
|
144
|
-
return (lastError &&
|
|
145
|
-
(lastError.error.message.includes("429") ||
|
|
146
|
-
lastError.error.message.toLowerCase().includes("rate limit")));
|
|
147
|
-
},
|
|
148
|
-
severity: "MEDIUM",
|
|
149
|
-
recoveryStrategy: {
|
|
150
|
-
type: "circuit-breaker",
|
|
151
|
-
config: {
|
|
152
|
-
failureThreshold: 3,
|
|
153
|
-
resetTimeout: 120000, // 2 minutes
|
|
154
|
-
successThreshold: 1,
|
|
155
|
-
monitoringPeriod: 60000,
|
|
156
|
-
},
|
|
157
|
-
},
|
|
158
|
-
});
|
|
159
|
-
// Configuration error pattern
|
|
160
|
-
this.addPattern({
|
|
161
|
-
id: "config-error",
|
|
162
|
-
name: "Configuration Error Pattern",
|
|
163
|
-
description: "Missing or invalid configuration",
|
|
164
|
-
matcher: (errors) => {
|
|
165
|
-
const lastError = errors[errors.length - 1];
|
|
166
|
-
return lastError?.category === "CONFIGURATION_ERROR";
|
|
167
|
-
},
|
|
168
|
-
severity: "CRITICAL",
|
|
169
|
-
recoveryStrategy: {
|
|
170
|
-
type: "manual",
|
|
171
|
-
action: async (context) => ({
|
|
172
|
-
success: false,
|
|
173
|
-
message: "Configuration error requires manual intervention. Check environment variables and config files.",
|
|
174
|
-
}),
|
|
175
|
-
},
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Add error pattern
|
|
180
|
-
*/
|
|
181
|
-
addPattern(pattern) {
|
|
182
|
-
this.errorPatterns.push(pattern);
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Detect patterns in error history
|
|
186
|
-
*/
|
|
187
|
-
detectPatterns(errors) {
|
|
188
|
-
return this.errorPatterns.filter((pattern) => pattern.matcher(errors));
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Get circuit breaker for resource
|
|
192
|
-
*/
|
|
193
|
-
getCircuitBreaker(resourceId, config) {
|
|
194
|
-
if (!this.circuitBreakers.has(resourceId)) {
|
|
195
|
-
this.circuitBreakers.set(resourceId, new CircuitBreaker(config || this.defaultCircuitConfig));
|
|
196
|
-
}
|
|
197
|
-
return this.circuitBreakers.get(resourceId);
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* Calculate retry delay with exponential backoff
|
|
201
|
-
*/
|
|
202
|
-
calculateRetryDelay(attemptNumber, config) {
|
|
203
|
-
const exponentialDelay = config.initialDelay *
|
|
204
|
-
Math.pow(config.backoffMultiplier, attemptNumber - 1);
|
|
205
|
-
const delay = Math.min(exponentialDelay, config.maxDelay);
|
|
206
|
-
if (config.jitter) {
|
|
207
|
-
// Add random jitter (±25%)
|
|
208
|
-
const jitter = delay * 0.25 * (Math.random() * 2 - 1);
|
|
209
|
-
return Math.floor(delay + jitter);
|
|
210
|
-
}
|
|
211
|
-
return delay;
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Attempt recovery for an error
|
|
215
|
-
*/
|
|
216
|
-
async attemptRecovery(error, context) {
|
|
217
|
-
// Detect patterns
|
|
218
|
-
const patterns = this.detectPatterns([error]);
|
|
219
|
-
const pattern = patterns[0]; // Use first matching pattern
|
|
220
|
-
// Get recovery history
|
|
221
|
-
const historyKey = `${error.context.toolName || "unknown"}-${error.category}`;
|
|
222
|
-
const history = this.recoveryHistory.get(historyKey) || [];
|
|
223
|
-
// Build recovery context
|
|
224
|
-
const recoveryContext = {
|
|
225
|
-
error,
|
|
226
|
-
pattern,
|
|
227
|
-
attemptNumber: history.length + 1,
|
|
228
|
-
totalAttempts: 0,
|
|
229
|
-
previousAttempts: history,
|
|
230
|
-
executionContext: context,
|
|
231
|
-
};
|
|
232
|
-
// Determine recovery strategy
|
|
233
|
-
const strategy = pattern?.recoveryStrategy || this.getDefaultStrategy(error);
|
|
234
|
-
// Execute recovery
|
|
235
|
-
const startTime = Date.now();
|
|
236
|
-
let result;
|
|
237
|
-
try {
|
|
238
|
-
switch (strategy.type) {
|
|
239
|
-
case "retry":
|
|
240
|
-
result = await this.executeRetryStrategy(recoveryContext, strategy.config);
|
|
241
|
-
break;
|
|
242
|
-
case "circuit-breaker":
|
|
243
|
-
result = await this.executeCircuitBreakerStrategy(recoveryContext, strategy.config);
|
|
244
|
-
break;
|
|
245
|
-
case "fallback":
|
|
246
|
-
result = await this.executeFallbackStrategy(recoveryContext, strategy.config);
|
|
247
|
-
break;
|
|
248
|
-
case "manual":
|
|
249
|
-
result = strategy.action
|
|
250
|
-
? await strategy.action(recoveryContext)
|
|
251
|
-
: { success: false, message: "Manual intervention required" };
|
|
252
|
-
break;
|
|
253
|
-
default:
|
|
254
|
-
result = {
|
|
255
|
-
success: false,
|
|
256
|
-
message: "No recovery strategy available",
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
catch (recoveryError) {
|
|
261
|
-
result = {
|
|
262
|
-
success: false,
|
|
263
|
-
message: `Recovery failed: ${recoveryError instanceof Error ? recoveryError.message : "Unknown error"}`,
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
|
-
// Record attempt
|
|
267
|
-
const attempt = {
|
|
268
|
-
timestamp: Date.now(),
|
|
269
|
-
strategy: strategy.type,
|
|
270
|
-
successful: result.success,
|
|
271
|
-
duration: Date.now() - startTime,
|
|
272
|
-
error: result.success
|
|
273
|
-
? undefined
|
|
274
|
-
: new Error(result.message || "Recovery failed"),
|
|
275
|
-
};
|
|
276
|
-
history.push(attempt);
|
|
277
|
-
this.recoveryHistory.set(historyKey, history.slice(-10)); // Keep last 10 attempts
|
|
278
|
-
return result;
|
|
279
|
-
}
|
|
280
|
-
/**
|
|
281
|
-
* Execute retry strategy
|
|
282
|
-
*/
|
|
283
|
-
async executeRetryStrategy(context, config) {
|
|
284
|
-
const retryConfig = config || this.defaultRetryConfig;
|
|
285
|
-
if (context.attemptNumber > retryConfig.maxAttempts) {
|
|
286
|
-
return {
|
|
287
|
-
success: false,
|
|
288
|
-
message: `Maximum retry attempts (${retryConfig.maxAttempts}) exceeded`,
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
const delay = this.calculateRetryDelay(context.attemptNumber, retryConfig);
|
|
292
|
-
return {
|
|
293
|
-
success: true,
|
|
294
|
-
nextAction: "retry",
|
|
295
|
-
delay,
|
|
296
|
-
message: `Retry attempt ${context.attemptNumber}/${retryConfig.maxAttempts} after ${delay}ms`,
|
|
297
|
-
};
|
|
298
|
-
}
|
|
299
|
-
/**
|
|
300
|
-
* Execute circuit breaker strategy
|
|
301
|
-
*/
|
|
302
|
-
async executeCircuitBreakerStrategy(context, config) {
|
|
303
|
-
const resourceId = context.error.context.toolName || "default";
|
|
304
|
-
const circuitBreaker = this.getCircuitBreaker(resourceId, config);
|
|
305
|
-
if (!circuitBreaker.canExecute()) {
|
|
306
|
-
return {
|
|
307
|
-
success: false,
|
|
308
|
-
message: `Circuit breaker OPEN for ${resourceId}. Service temporarily unavailable.`,
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
// Record the failure for circuit breaker
|
|
312
|
-
circuitBreaker.recordFailure();
|
|
313
|
-
return {
|
|
314
|
-
success: true,
|
|
315
|
-
nextAction: circuitBreaker.getState() === CircuitState.OPEN ? "fail" : "retry",
|
|
316
|
-
message: `Circuit breaker state: ${circuitBreaker.getState()}`,
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
/**
|
|
320
|
-
* Execute fallback strategy
|
|
321
|
-
*/
|
|
322
|
-
async executeFallbackStrategy(context, config) {
|
|
323
|
-
// In a real implementation, this would execute fallback logic
|
|
324
|
-
// For now, just indicate fallback should be used
|
|
325
|
-
return {
|
|
326
|
-
success: true,
|
|
327
|
-
fallbackUsed: true,
|
|
328
|
-
message: "Fallback strategy activated",
|
|
329
|
-
};
|
|
330
|
-
}
|
|
331
|
-
/**
|
|
332
|
-
* Get default recovery strategy based on error
|
|
333
|
-
*/
|
|
334
|
-
getDefaultStrategy(error) {
|
|
335
|
-
switch (error.category) {
|
|
336
|
-
case "NETWORK_ERROR":
|
|
337
|
-
case "TIMEOUT_ERROR":
|
|
338
|
-
return {
|
|
339
|
-
type: "retry",
|
|
340
|
-
config: this.defaultRetryConfig,
|
|
341
|
-
};
|
|
342
|
-
case "CONFIGURATION_ERROR":
|
|
343
|
-
case "PERMISSION_ERROR":
|
|
344
|
-
return {
|
|
345
|
-
type: "manual",
|
|
346
|
-
};
|
|
347
|
-
default:
|
|
348
|
-
return {
|
|
349
|
-
type: "retry",
|
|
350
|
-
config: {
|
|
351
|
-
...this.defaultRetryConfig,
|
|
352
|
-
maxAttempts: 2,
|
|
353
|
-
},
|
|
354
|
-
};
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
/**
|
|
358
|
-
* Get recovery statistics
|
|
359
|
-
*/
|
|
360
|
-
getRecoveryStats() {
|
|
361
|
-
let totalAttempts = 0;
|
|
362
|
-
let successfulRecoveries = 0;
|
|
363
|
-
let failedRecoveries = 0;
|
|
364
|
-
// Calculate from history
|
|
365
|
-
for (const attempts of this.recoveryHistory.values()) {
|
|
366
|
-
for (const attempt of attempts) {
|
|
367
|
-
totalAttempts++;
|
|
368
|
-
if (attempt.successful) {
|
|
369
|
-
successfulRecoveries++;
|
|
370
|
-
}
|
|
371
|
-
else {
|
|
372
|
-
failedRecoveries++;
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
// Get circuit breaker states
|
|
377
|
-
const circuitBreakerStates = {};
|
|
378
|
-
for (const [id, breaker] of this.circuitBreakers) {
|
|
379
|
-
circuitBreakerStates[id] = breaker.getState();
|
|
380
|
-
}
|
|
381
|
-
return {
|
|
382
|
-
totalAttempts,
|
|
383
|
-
successfulRecoveries,
|
|
384
|
-
failedRecoveries,
|
|
385
|
-
circuitBreakerStates,
|
|
386
|
-
patternMatches: {}, // TODO: Track pattern matches
|
|
387
|
-
};
|
|
388
|
-
}
|
|
389
|
-
/**
|
|
390
|
-
* Reset circuit breaker
|
|
391
|
-
*/
|
|
392
|
-
resetCircuitBreaker(resourceId) {
|
|
393
|
-
this.circuitBreakers.delete(resourceId);
|
|
394
|
-
}
|
|
395
|
-
/**
|
|
396
|
-
* Clear recovery history
|
|
397
|
-
*/
|
|
398
|
-
clearHistory() {
|
|
399
|
-
this.recoveryHistory.clear();
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
/**
|
|
403
|
-
* Default error recovery instance
|
|
404
|
-
*/
|
|
405
|
-
export const defaultErrorRecovery = new ErrorRecovery();
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* NeuroLink External MCP Client
|
|
3
|
-
* Connects to external MCP servers via stdio transport following MCP specification
|
|
4
|
-
* Bridges external tools into NeuroLink's factory pattern ecosystem
|
|
5
|
-
*/
|
|
6
|
-
import { EventEmitter } from "events";
|
|
7
|
-
import type { NeuroLinkMCPTool, NeuroLinkExecutionContext, ToolResult } from "./factory.js";
|
|
8
|
-
/**
|
|
9
|
-
* External MCP Server Configuration
|
|
10
|
-
*/
|
|
11
|
-
export interface ExternalMCPServerConfig {
|
|
12
|
-
name: string;
|
|
13
|
-
command: string;
|
|
14
|
-
args: string[];
|
|
15
|
-
transport: "stdio";
|
|
16
|
-
env?: Record<string, string>;
|
|
17
|
-
timeout?: number;
|
|
18
|
-
retryAttempts?: number;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* External MCP Client for stdio transport
|
|
22
|
-
*/
|
|
23
|
-
export declare class ExternalMCPClient extends EventEmitter {
|
|
24
|
-
private config;
|
|
25
|
-
private process;
|
|
26
|
-
private isConnected;
|
|
27
|
-
private messageId;
|
|
28
|
-
private pendingRequests;
|
|
29
|
-
private tools;
|
|
30
|
-
private buffer;
|
|
31
|
-
constructor(config: ExternalMCPServerConfig);
|
|
32
|
-
/**
|
|
33
|
-
* Connect to the external MCP server
|
|
34
|
-
*/
|
|
35
|
-
connect(): Promise<void>;
|
|
36
|
-
/**
|
|
37
|
-
* Initialize MCP session
|
|
38
|
-
*/
|
|
39
|
-
private initialize;
|
|
40
|
-
/**
|
|
41
|
-
* Discover available tools from the server
|
|
42
|
-
*/
|
|
43
|
-
private discoverTools;
|
|
44
|
-
/**
|
|
45
|
-
* Execute a tool on the external server
|
|
46
|
-
*/
|
|
47
|
-
executeTool(toolName: string, params: unknown, context: NeuroLinkExecutionContext): Promise<ToolResult>;
|
|
48
|
-
/**
|
|
49
|
-
* Get available tools as NeuroLink MCP tools
|
|
50
|
-
*/
|
|
51
|
-
getNeuroLinkTools(): Record<string, NeuroLinkMCPTool>;
|
|
52
|
-
/**
|
|
53
|
-
* Send a request to the MCP server
|
|
54
|
-
*/
|
|
55
|
-
private sendRequest;
|
|
56
|
-
/**
|
|
57
|
-
* Handle incoming messages from the server
|
|
58
|
-
*/
|
|
59
|
-
private handleMessage;
|
|
60
|
-
/**
|
|
61
|
-
* Process a parsed MCP message
|
|
62
|
-
*/
|
|
63
|
-
private processMessage;
|
|
64
|
-
/**
|
|
65
|
-
* Disconnect from the server
|
|
66
|
-
*/
|
|
67
|
-
disconnect(): Promise<void>;
|
|
68
|
-
/**
|
|
69
|
-
* Check if connected
|
|
70
|
-
*/
|
|
71
|
-
isConnectedToServer(): boolean;
|
|
72
|
-
/**
|
|
73
|
-
* Get server information
|
|
74
|
-
*/
|
|
75
|
-
getServerInfo(): {
|
|
76
|
-
name: string;
|
|
77
|
-
command: string;
|
|
78
|
-
args: string[];
|
|
79
|
-
transport: "stdio";
|
|
80
|
-
isConnected: boolean;
|
|
81
|
-
toolCount: number;
|
|
82
|
-
tools: string[];
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Create an external MCP client
|
|
87
|
-
*/
|
|
88
|
-
export declare function createExternalMCPClient(config: ExternalMCPServerConfig): ExternalMCPClient;
|