@juspay/neurolink 7.33.2 → 7.33.4
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 +8 -0
- package/dist/cli/commands/config.d.ts +3 -4
- package/dist/cli/commands/config.js +2 -3
- package/dist/constants/index.d.ts +192 -0
- package/dist/constants/index.js +195 -0
- package/dist/constants/performance.d.ts +366 -0
- package/dist/constants/performance.js +389 -0
- package/dist/constants/retry.d.ts +224 -0
- package/dist/constants/retry.js +266 -0
- package/dist/constants/timeouts.d.ts +225 -0
- package/dist/constants/timeouts.js +182 -0
- package/dist/constants/tokens.d.ts +234 -0
- package/dist/constants/tokens.js +314 -0
- package/dist/core/baseProvider.js +26 -1
- package/dist/core/constants.d.ts +12 -3
- package/dist/core/constants.js +22 -6
- package/dist/core/factory.js +19 -0
- package/dist/core/types.d.ts +268 -0
- package/dist/core/types.js +153 -0
- package/dist/factories/providerRegistry.js +2 -0
- package/dist/lib/constants/index.d.ts +192 -0
- package/dist/lib/constants/index.js +195 -0
- package/dist/lib/constants/performance.d.ts +366 -0
- package/dist/lib/constants/performance.js +389 -0
- package/dist/lib/constants/retry.d.ts +224 -0
- package/dist/lib/constants/retry.js +266 -0
- package/dist/lib/constants/timeouts.d.ts +225 -0
- package/dist/lib/constants/timeouts.js +182 -0
- package/dist/lib/constants/tokens.d.ts +234 -0
- package/dist/lib/constants/tokens.js +314 -0
- package/dist/lib/core/baseProvider.js +26 -1
- package/dist/lib/core/constants.d.ts +12 -3
- package/dist/lib/core/constants.js +22 -6
- package/dist/lib/core/factory.js +19 -0
- package/dist/lib/core/types.d.ts +268 -0
- package/dist/lib/core/types.js +153 -0
- package/dist/lib/factories/providerRegistry.js +2 -0
- package/dist/lib/mcp/servers/aiProviders/aiWorkflowTools.js +2 -2
- package/dist/lib/models/modelRegistry.d.ts +1 -1
- package/dist/lib/models/modelRegistry.js +63 -37
- package/dist/lib/neurolink.js +35 -34
- package/dist/lib/providers/amazonBedrock.js +2 -2
- package/dist/lib/providers/anthropic.js +3 -12
- package/dist/lib/providers/anthropicBaseProvider.js +1 -2
- package/dist/lib/providers/azureOpenai.d.ts +1 -1
- package/dist/lib/providers/azureOpenai.js +51 -9
- package/dist/lib/providers/googleAiStudio.js +3 -3
- package/dist/lib/providers/googleVertex.js +2 -2
- package/dist/lib/providers/huggingFace.js +1 -2
- package/dist/lib/providers/litellm.js +1 -2
- package/dist/lib/providers/mistral.js +2 -2
- package/dist/lib/providers/ollama.js +7 -8
- package/dist/lib/providers/openAI.js +2 -2
- package/dist/lib/providers/openaiCompatible.js +5 -2
- package/dist/lib/providers/sagemaker/language-model.d.ts +5 -0
- package/dist/lib/providers/sagemaker/language-model.js +9 -1
- package/dist/lib/utils/providerConfig.d.ts +25 -0
- package/dist/lib/utils/providerConfig.js +24 -3
- package/dist/lib/utils/providerHealth.d.ts +1 -1
- package/dist/lib/utils/providerHealth.js +47 -36
- package/dist/lib/utils/providerSetupMessages.js +7 -6
- package/dist/lib/utils/providerUtils.js +16 -24
- package/dist/lib/utils/tokenLimits.d.ts +2 -2
- package/dist/lib/utils/tokenLimits.js +10 -3
- package/dist/mcp/servers/aiProviders/aiWorkflowTools.js +2 -2
- package/dist/models/modelRegistry.d.ts +1 -1
- package/dist/models/modelRegistry.js +63 -37
- package/dist/neurolink.js +35 -34
- package/dist/providers/amazonBedrock.js +2 -2
- package/dist/providers/anthropic.js +3 -12
- package/dist/providers/anthropicBaseProvider.js +1 -2
- package/dist/providers/azureOpenai.d.ts +1 -1
- package/dist/providers/azureOpenai.js +51 -9
- package/dist/providers/googleAiStudio.js +3 -3
- package/dist/providers/googleVertex.js +2 -2
- package/dist/providers/huggingFace.js +1 -2
- package/dist/providers/litellm.js +1 -2
- package/dist/providers/mistral.js +2 -2
- package/dist/providers/ollama.js +7 -8
- package/dist/providers/openAI.js +2 -2
- package/dist/providers/openaiCompatible.js +5 -2
- package/dist/providers/sagemaker/language-model.d.ts +5 -0
- package/dist/providers/sagemaker/language-model.js +9 -1
- package/dist/utils/providerConfig.d.ts +25 -0
- package/dist/utils/providerConfig.js +24 -3
- package/dist/utils/providerHealth.d.ts +1 -1
- package/dist/utils/providerHealth.js +47 -36
- package/dist/utils/providerSetupMessages.js +7 -6
- package/dist/utils/providerUtils.js +16 -24
- package/dist/utils/tokenLimits.d.ts +2 -2
- package/dist/utils/tokenLimits.js +10 -3
- package/package.json +1 -1
@@ -0,0 +1,389 @@
|
|
1
|
+
/**
|
2
|
+
* Performance and Resource Constants for NeuroLink
|
3
|
+
*
|
4
|
+
* Centralized performance configuration to replace magic numbers throughout the codebase.
|
5
|
+
* Includes memory thresholds, concurrency limits, buffer sizes, and cache configurations.
|
6
|
+
*
|
7
|
+
* @fileoverview Performance constants for optimal resource utilization
|
8
|
+
* @author NeuroLink Team
|
9
|
+
* @version 1.0.0
|
10
|
+
*/
|
11
|
+
import { TIMEOUTS } from "./timeouts.js";
|
12
|
+
/**
|
13
|
+
* Unit conversion constants
|
14
|
+
* Common conversion factors to replace magic numbers
|
15
|
+
*/
|
16
|
+
export const UNIT_CONVERSIONS = {
|
17
|
+
/** Conversion factor from nanoseconds to milliseconds */
|
18
|
+
NANOSECOND_TO_MS_DIVISOR: 1000000, // 1,000,000 - Nanoseconds to milliseconds
|
19
|
+
/** Conversion factor from microseconds to milliseconds */
|
20
|
+
MICROSECOND_TO_MS_DIVISOR: 1000, // 1,000 - Microseconds to milliseconds
|
21
|
+
/** Conversion factor from seconds to milliseconds */
|
22
|
+
SECOND_TO_MS_MULTIPLIER: 1000, // 1,000 - Seconds to milliseconds
|
23
|
+
/** Conversion factor from minutes to milliseconds */
|
24
|
+
MINUTE_TO_MS_MULTIPLIER: 60000, // 60,000 - Minutes to milliseconds
|
25
|
+
/** Conversion factor from hours to milliseconds */
|
26
|
+
HOUR_TO_MS_MULTIPLIER: 3600000, // 3,600,000 - Hours to milliseconds
|
27
|
+
};
|
28
|
+
/**
|
29
|
+
* Text processing constants
|
30
|
+
* Standard lengths for text preview, logging, and truncation
|
31
|
+
*/
|
32
|
+
export const TEXT_PREVIEW_LENGTHS = {
|
33
|
+
/** Very short preview for debugging */
|
34
|
+
VERY_SHORT: 50, // 50 chars - Very short preview
|
35
|
+
/** Short preview for compact logging */
|
36
|
+
SHORT: 100, // 100 chars - Short preview
|
37
|
+
/** Medium preview for standard logging */
|
38
|
+
MEDIUM: 150, // 150 chars - Medium preview
|
39
|
+
/** Standard preview length */
|
40
|
+
STANDARD: 200, // 200 chars - Standard preview
|
41
|
+
/** Long preview for detailed context */
|
42
|
+
LONG: 300, // 300 chars - Long preview
|
43
|
+
/** Extra long preview for comprehensive view */
|
44
|
+
EXTRA_LONG: 500, // 500 chars - Extra long preview
|
45
|
+
/** Maximum preview length before truncation */
|
46
|
+
MAX_PREVIEW: 1000, // 1000 chars - Maximum preview
|
47
|
+
};
|
48
|
+
/**
|
49
|
+
* Performance thresholds for various operations
|
50
|
+
* Unified thresholds to replace scattered magic numbers
|
51
|
+
*/
|
52
|
+
export const PERFORMANCE_THRESHOLDS = {
|
53
|
+
/** Success rate threshold for tool reliability */
|
54
|
+
SUCCESS_RATE_THRESHOLD: 0.8, // 80% - Minimum success rate
|
55
|
+
/** High success rate threshold */
|
56
|
+
HIGH_SUCCESS_RATE: 0.95, // 95% - High success rate
|
57
|
+
/** Low success rate warning threshold */
|
58
|
+
LOW_SUCCESS_RATE_WARNING: 0.6, // 60% - Low success rate warning
|
59
|
+
/** Critical success rate threshold */
|
60
|
+
CRITICAL_SUCCESS_RATE: 0.5, // 50% - Critical success rate
|
61
|
+
/** Tool execution time warning threshold (ms) */
|
62
|
+
TOOL_EXECUTION_WARNING_MS: 10000, // 10s - Tool execution warning
|
63
|
+
/** Large tool collection threshold */
|
64
|
+
LARGE_TOOL_COLLECTION: 100, // 100 tools - Large collection
|
65
|
+
/** Circuit breaker failure threshold */
|
66
|
+
CIRCUIT_BREAKER_FAILURES: 5, // 5 failures - Circuit breaker threshold
|
67
|
+
/** Circuit breaker reset timeout (ms) */
|
68
|
+
CIRCUIT_BREAKER_RESET_MS: TIMEOUTS.CIRCUIT_BREAKER.RESET_MS, // 60s - Circuit breaker reset
|
69
|
+
};
|
70
|
+
/**
|
71
|
+
* Memory threshold configuration
|
72
|
+
* Thresholds for monitoring and alerting on memory usage
|
73
|
+
*/
|
74
|
+
export const MEMORY_THRESHOLDS = {
|
75
|
+
/** Warning threshold for general memory usage */
|
76
|
+
WARNING_MB: 100, // 100MB - Warn about high memory usage
|
77
|
+
/** Critical threshold requiring immediate attention */
|
78
|
+
CRITICAL_MB: 200, // 200MB - Critical memory usage
|
79
|
+
/** Tool-specific memory warning threshold */
|
80
|
+
TOOL_WARNING_MB: 20, // 20MB - Tool-specific memory warning
|
81
|
+
/** Tool critical memory threshold */
|
82
|
+
TOOL_CRITICAL_MB: 50, // 50MB - Tool critical memory usage
|
83
|
+
/** Memory leak detection threshold */
|
84
|
+
LEAK_DETECTION_MB: 300, // 300MB - Potential memory leak
|
85
|
+
/** Maximum allowed memory before forced cleanup */
|
86
|
+
MAX_ALLOWED_MB: 500, // 500MB - Force cleanup threshold
|
87
|
+
/** Heap growth rate warning (MB per minute) */
|
88
|
+
GROWTH_RATE_WARNING_MB_PER_MIN: 10, // 10MB/min - Suspicious growth rate
|
89
|
+
/** Moderate memory usage threshold */
|
90
|
+
MODERATE_USAGE_MB: 30, // 30MB - Moderate memory usage
|
91
|
+
/** Low memory usage threshold */
|
92
|
+
LOW_USAGE_MB: 10, // 10MB - Low memory usage
|
93
|
+
/** Moderate memory delta threshold for operations */
|
94
|
+
OPERATION_MODERATE_MB: 30, // 30MB - Moderate operation memory usage
|
95
|
+
/** Small memory delta threshold for operations */
|
96
|
+
OPERATION_SMALL_MB: 10, // 10MB - Small operation memory usage
|
97
|
+
/** Large memory delta threshold requiring GC */
|
98
|
+
OPERATION_LARGE_MB: 50, // 50MB - Large operation memory usage
|
99
|
+
};
|
100
|
+
/**
|
101
|
+
* Response time threshold configuration
|
102
|
+
* Defines what constitutes fast, acceptable, and slow response times
|
103
|
+
*/
|
104
|
+
export const RESPONSE_TIME_THRESHOLDS = {
|
105
|
+
/** Fast response time - excellent performance */
|
106
|
+
FAST_MS: 1000, // 1s - Fast response
|
107
|
+
/** Acceptable response time - good performance */
|
108
|
+
ACCEPTABLE_MS: 5000, // 5s - Acceptable response
|
109
|
+
/** Slow response time - needs optimization */
|
110
|
+
SLOW_MS: 10000, // 10s - Slow response warning
|
111
|
+
/** Critical response time - unacceptable */
|
112
|
+
CRITICAL_MS: 30000, // 30s - Critical response time
|
113
|
+
/** Tool execution fast threshold */
|
114
|
+
TOOL_FAST_MS: 2000, // 2s - Fast tool execution
|
115
|
+
/** Tool execution slow threshold */
|
116
|
+
TOOL_SLOW_MS: 15000, // 15s - Slow tool execution
|
117
|
+
/** Provider response fast threshold */
|
118
|
+
PROVIDER_FAST_MS: 3000, // 3s - Fast provider response
|
119
|
+
/** Provider response slow threshold */
|
120
|
+
PROVIDER_SLOW_MS: 20000, // 20s - Slow provider response
|
121
|
+
};
|
122
|
+
/**
|
123
|
+
* Concurrency limit configuration
|
124
|
+
* Controls parallel execution to prevent resource exhaustion
|
125
|
+
*/
|
126
|
+
export const CONCURRENCY_LIMITS = {
|
127
|
+
/** Default concurrent operations */
|
128
|
+
DEFAULT: 5, // 5 - Default concurrent operations
|
129
|
+
/** High-load scenario concurrency */
|
130
|
+
HIGH_LOAD: 10, // 10 - High-load scenarios
|
131
|
+
/** Low-resource environment concurrency */
|
132
|
+
LOW_RESOURCE: 2, // 2 - Low-resource environments
|
133
|
+
/** Provider-specific concurrency */
|
134
|
+
PROVIDER: 3, // 3 - Provider-specific limits
|
135
|
+
/** Tool execution concurrency */
|
136
|
+
TOOL_EXECUTION: 4, // 4 - Tool execution concurrency
|
137
|
+
/** MCP server concurrency */
|
138
|
+
MCP_SERVER: 8, // 8 - MCP server operations
|
139
|
+
/** Network request concurrency */
|
140
|
+
NETWORK_REQUEST: 6, // 6 - Network requests
|
141
|
+
/** Maximum concurrent streams */
|
142
|
+
MAX_STREAMS: 3, // 3 - Maximum concurrent streams
|
143
|
+
/** Database operation concurrency */
|
144
|
+
DATABASE: 5, // 5 - Database operations
|
145
|
+
};
|
146
|
+
/**
|
147
|
+
* Buffer size configuration
|
148
|
+
* Optimized buffer sizes for different types of operations
|
149
|
+
*/
|
150
|
+
export const BUFFER_SIZES = {
|
151
|
+
/** Small buffer for lightweight operations */
|
152
|
+
SMALL_BYTES: 1024, // 1KB - Small buffer operations
|
153
|
+
/** Standard buffer for most operations */
|
154
|
+
STANDARD_BYTES: 4096, // 4KB - Standard buffer size
|
155
|
+
/** Large buffer for heavy operations */
|
156
|
+
LARGE_BYTES: 8192, // 8KB - Large buffer operations
|
157
|
+
/** Extra large buffer for file operations */
|
158
|
+
XLARGE_BYTES: 16384, // 16KB - Extra large buffer
|
159
|
+
/** Memory buffer for streaming */
|
160
|
+
STREAM_BYTES: 2048, // 2KB - Streaming buffer
|
161
|
+
/** Network buffer size */
|
162
|
+
NETWORK_BYTES: 4096, // 4KB - Network operations
|
163
|
+
/** File I/O buffer size */
|
164
|
+
FILE_IO_BYTES: 8192, // 8KB - File operations
|
165
|
+
/** Maximum single buffer size */
|
166
|
+
MAX_BYTES: 32768, // 32KB - Maximum buffer size
|
167
|
+
};
|
168
|
+
/**
|
169
|
+
* Cache configuration
|
170
|
+
* Size limits and policies for various cache types
|
171
|
+
*/
|
172
|
+
export const CACHE_CONFIG = {
|
173
|
+
/** Small cache for frequently accessed items */
|
174
|
+
SMALL_SIZE: 100, // 100 entries - Small cache
|
175
|
+
/** Default cache size for most use cases */
|
176
|
+
DEFAULT_SIZE: 1000, // 1000 entries - Default cache
|
177
|
+
/** Large cache for extensive data */
|
178
|
+
LARGE_SIZE: 10000, // 10000 entries - Large cache
|
179
|
+
/** Provider cache size */
|
180
|
+
PROVIDER_CACHE_SIZE: 500, // 500 entries - Provider cache
|
181
|
+
/** Tool registry cache size */
|
182
|
+
TOOL_REGISTRY_SIZE: 200, // 200 entries - Tool cache
|
183
|
+
/** Model configuration cache */
|
184
|
+
MODEL_CONFIG_SIZE: 50, // 50 entries - Model cache
|
185
|
+
/** Session cache size */
|
186
|
+
SESSION_CACHE_SIZE: 1000, // 1000 entries - Session cache
|
187
|
+
/** Maximum cache size */
|
188
|
+
MAX_SIZE: 50000, // 50000 entries - Maximum cache size
|
189
|
+
/** Cache TTL in milliseconds */
|
190
|
+
DEFAULT_TTL_MS: 300000, // 5 minutes - Default cache TTL
|
191
|
+
/** Short TTL for volatile data */
|
192
|
+
SHORT_TTL_MS: 60000, // 1 minute - Short TTL
|
193
|
+
/** Long TTL for stable data */
|
194
|
+
LONG_TTL_MS: 3600000, // 1 hour - Long TTL
|
195
|
+
};
|
196
|
+
/**
|
197
|
+
* Resource monitoring configuration
|
198
|
+
* Intervals and thresholds for monitoring system resources
|
199
|
+
*/
|
200
|
+
export const MONITORING_CONFIG = {
|
201
|
+
/** Default monitoring interval */
|
202
|
+
DEFAULT_INTERVAL_MS: 30000, // 30s - Default monitoring interval
|
203
|
+
/** High-frequency monitoring interval */
|
204
|
+
HIGH_FREQ_INTERVAL_MS: 5000, // 5s - High-frequency monitoring
|
205
|
+
/** Low-frequency monitoring interval */
|
206
|
+
LOW_FREQ_INTERVAL_MS: 60000, // 1m - Low-frequency monitoring
|
207
|
+
/** Memory check interval */
|
208
|
+
MEMORY_CHECK_INTERVAL_MS: 15000, // 15s - Memory monitoring
|
209
|
+
/** Performance metrics collection interval */
|
210
|
+
METRICS_INTERVAL_MS: 10000, // 10s - Metrics collection
|
211
|
+
/** Health check interval */
|
212
|
+
HEALTH_CHECK_INTERVAL_MS: 30000, // 30s - Health checks
|
213
|
+
/** CPU usage check interval */
|
214
|
+
CPU_CHECK_INTERVAL_MS: 20000, // 20s - CPU monitoring
|
215
|
+
/** Disk usage check interval */
|
216
|
+
DISK_CHECK_INTERVAL_MS: 120000, // 2m - Disk monitoring
|
217
|
+
};
|
218
|
+
/**
|
219
|
+
* Performance optimization thresholds
|
220
|
+
* Values that trigger performance optimization actions
|
221
|
+
*/
|
222
|
+
export const OPTIMIZATION_THRESHOLDS = {
|
223
|
+
/** CPU usage threshold for optimization */
|
224
|
+
CPU_USAGE_PERCENT: 80, // 80% - CPU optimization threshold
|
225
|
+
/** Memory usage threshold for cleanup */
|
226
|
+
MEMORY_CLEANUP_PERCENT: 85, // 85% - Memory cleanup threshold
|
227
|
+
/** Disk usage threshold for cleanup */
|
228
|
+
DISK_CLEANUP_PERCENT: 90, // 90% - Disk cleanup threshold
|
229
|
+
/** Connection pool optimization threshold */
|
230
|
+
CONNECTION_POOL_PERCENT: 75, // 75% - Connection pool optimization
|
231
|
+
/** Cache hit rate minimum threshold */
|
232
|
+
CACHE_HIT_RATE_MIN_PERCENT: 60, // 60% - Minimum cache hit rate
|
233
|
+
/** Queue length threshold for scaling */
|
234
|
+
QUEUE_LENGTH_THRESHOLD: 50, // 50 items - Queue scaling threshold
|
235
|
+
/** Error rate threshold for intervention */
|
236
|
+
ERROR_RATE_THRESHOLD_PERCENT: 5, // 5% - Error rate threshold
|
237
|
+
};
|
238
|
+
/**
|
239
|
+
* Garbage collection configuration
|
240
|
+
* Settings for automatic resource cleanup
|
241
|
+
*/
|
242
|
+
export const GC_CONFIG = {
|
243
|
+
/** Memory threshold for forced GC */
|
244
|
+
FORCE_GC_THRESHOLD_MB: 400, // 400MB - Force garbage collection
|
245
|
+
/** Interval for automatic GC checks */
|
246
|
+
AUTO_GC_INTERVAL_MS: 120000, // 2m - Auto GC check interval
|
247
|
+
/** Memory growth rate for GC trigger */
|
248
|
+
GC_TRIGGER_GROWTH_MB: 50, // 50MB - GC trigger growth
|
249
|
+
/** Cache cleanup interval */
|
250
|
+
CACHE_CLEANUP_INTERVAL_MS: 300000, // 5m - Cache cleanup interval
|
251
|
+
/** Temporary file cleanup interval */
|
252
|
+
TEMP_FILE_CLEANUP_MS: 600000, // 10m - Temp file cleanup
|
253
|
+
/** Log rotation threshold */
|
254
|
+
LOG_ROTATION_SIZE_MB: 100, // 100MB - Log rotation size
|
255
|
+
};
|
256
|
+
/**
|
257
|
+
* Server configuration constants
|
258
|
+
* Default configurations for various server types
|
259
|
+
*/
|
260
|
+
export const SERVER_CONFIG = {
|
261
|
+
/** Maximum number of MCP servers */
|
262
|
+
MAX_MCP_SERVERS: 20, // 20 - Maximum MCP servers
|
263
|
+
/** Default Ollama port */
|
264
|
+
DEFAULT_OLLAMA_PORT: 11434, // 11434 - Ollama service port
|
265
|
+
/** Maximum number of event handlers */
|
266
|
+
MAX_EVENT_HANDLERS: 5, // 5 - Maximum event handlers
|
267
|
+
/** Default server startup timeout */
|
268
|
+
STARTUP_TIMEOUT_MS: 15000, // 15s - Server startup timeout
|
269
|
+
/** Provider test timeout */
|
270
|
+
PROVIDER_TEST_TIMEOUT_MS: 5000, // 5s - Provider connectivity test
|
271
|
+
/** MCP connection test timeout */
|
272
|
+
MCP_CONNECTION_TEST_TIMEOUT_MS: 10000, // 10s - MCP connection test
|
273
|
+
/** External tool execution timeout */
|
274
|
+
EXTERNAL_TOOL_TIMEOUT_MS: 30000, // 30s - External tool execution
|
275
|
+
};
|
276
|
+
/**
|
277
|
+
* Performance utility functions
|
278
|
+
*/
|
279
|
+
export const PerformanceUtils = {
|
280
|
+
/**
|
281
|
+
* Get appropriate concurrency limit based on available resources
|
282
|
+
* @param resourceLevel - Resource availability level (low, medium, high)
|
283
|
+
* @returns Recommended concurrency limit
|
284
|
+
*/
|
285
|
+
getConcurrencyLimit: (resourceLevel = "medium") => {
|
286
|
+
switch (resourceLevel) {
|
287
|
+
case "low":
|
288
|
+
return CONCURRENCY_LIMITS.LOW_RESOURCE;
|
289
|
+
case "high":
|
290
|
+
return CONCURRENCY_LIMITS.HIGH_LOAD;
|
291
|
+
default:
|
292
|
+
return CONCURRENCY_LIMITS.DEFAULT;
|
293
|
+
}
|
294
|
+
},
|
295
|
+
/**
|
296
|
+
* Get appropriate buffer size for operation type
|
297
|
+
* @param operationType - Type of operation (network, file, stream, etc.)
|
298
|
+
* @returns Recommended buffer size in bytes
|
299
|
+
*/
|
300
|
+
getBufferSize: (operationType = "standard") => {
|
301
|
+
switch (operationType) {
|
302
|
+
case "network":
|
303
|
+
return BUFFER_SIZES.NETWORK_BYTES;
|
304
|
+
case "file":
|
305
|
+
return BUFFER_SIZES.FILE_IO_BYTES;
|
306
|
+
case "stream":
|
307
|
+
return BUFFER_SIZES.STREAM_BYTES;
|
308
|
+
default:
|
309
|
+
return BUFFER_SIZES.STANDARD_BYTES;
|
310
|
+
}
|
311
|
+
},
|
312
|
+
/**
|
313
|
+
* Get cache configuration for specific use case
|
314
|
+
* @param useCase - Cache use case (provider, tool, model, session)
|
315
|
+
* @returns Cache configuration object
|
316
|
+
*/
|
317
|
+
getCacheConfig: (useCase = "default") => {
|
318
|
+
const baseConfig = {
|
319
|
+
ttl: CACHE_CONFIG.DEFAULT_TTL_MS,
|
320
|
+
maxSize: CACHE_CONFIG.DEFAULT_SIZE,
|
321
|
+
};
|
322
|
+
switch (useCase) {
|
323
|
+
case "provider":
|
324
|
+
return { ...baseConfig, maxSize: CACHE_CONFIG.PROVIDER_CACHE_SIZE };
|
325
|
+
case "tool":
|
326
|
+
return { ...baseConfig, maxSize: CACHE_CONFIG.TOOL_REGISTRY_SIZE };
|
327
|
+
case "model":
|
328
|
+
return {
|
329
|
+
...baseConfig,
|
330
|
+
maxSize: CACHE_CONFIG.MODEL_CONFIG_SIZE,
|
331
|
+
ttl: CACHE_CONFIG.LONG_TTL_MS,
|
332
|
+
};
|
333
|
+
case "session":
|
334
|
+
return {
|
335
|
+
...baseConfig,
|
336
|
+
maxSize: CACHE_CONFIG.SESSION_CACHE_SIZE,
|
337
|
+
ttl: CACHE_CONFIG.SHORT_TTL_MS,
|
338
|
+
};
|
339
|
+
default:
|
340
|
+
return baseConfig;
|
341
|
+
}
|
342
|
+
},
|
343
|
+
/**
|
344
|
+
* Check if memory usage exceeds threshold
|
345
|
+
* @param currentUsageMB - Current memory usage in MB
|
346
|
+
* @param threshold - Threshold type to check against
|
347
|
+
* @returns True if threshold is exceeded
|
348
|
+
*/
|
349
|
+
isMemoryThresholdExceeded: (currentUsageMB, threshold = "warning") => {
|
350
|
+
switch (threshold) {
|
351
|
+
case "critical":
|
352
|
+
return currentUsageMB > MEMORY_THRESHOLDS.CRITICAL_MB;
|
353
|
+
case "tool":
|
354
|
+
return currentUsageMB > MEMORY_THRESHOLDS.TOOL_WARNING_MB;
|
355
|
+
case "leak":
|
356
|
+
return currentUsageMB > MEMORY_THRESHOLDS.LEAK_DETECTION_MB;
|
357
|
+
default:
|
358
|
+
return currentUsageMB > MEMORY_THRESHOLDS.WARNING_MB;
|
359
|
+
}
|
360
|
+
},
|
361
|
+
/**
|
362
|
+
* Categorize response time performance
|
363
|
+
* @param responseTimeMs - Response time in milliseconds
|
364
|
+
* @returns Performance category
|
365
|
+
*/
|
366
|
+
categorizeResponseTime: (responseTimeMs) => {
|
367
|
+
if (responseTimeMs <= RESPONSE_TIME_THRESHOLDS.FAST_MS) {
|
368
|
+
return "fast";
|
369
|
+
}
|
370
|
+
if (responseTimeMs <= RESPONSE_TIME_THRESHOLDS.ACCEPTABLE_MS) {
|
371
|
+
return "acceptable";
|
372
|
+
}
|
373
|
+
if (responseTimeMs <= RESPONSE_TIME_THRESHOLDS.SLOW_MS) {
|
374
|
+
return "slow";
|
375
|
+
}
|
376
|
+
return "critical";
|
377
|
+
},
|
378
|
+
};
|
379
|
+
// Legacy compatibility exports
|
380
|
+
export const HIGH_MEMORY_THRESHOLD = MEMORY_THRESHOLDS.WARNING_MB;
|
381
|
+
export const DEFAULT_CONCURRENCY_LIMIT = CONCURRENCY_LIMITS.DEFAULT;
|
382
|
+
export const MAX_CONCURRENCY_LIMIT = CONCURRENCY_LIMITS.HIGH_LOAD;
|
383
|
+
export const SMALL_BUFFER_SIZE = BUFFER_SIZES.SMALL_BYTES;
|
384
|
+
export const LARGE_BUFFER_SIZE = BUFFER_SIZES.LARGE_BYTES;
|
385
|
+
export const DEFAULT_CACHE_SIZE = CACHE_CONFIG.DEFAULT_SIZE;
|
386
|
+
// New convenience exports for easy access
|
387
|
+
export const NANOSECOND_TO_MS_DIVISOR = UNIT_CONVERSIONS.NANOSECOND_TO_MS_DIVISOR;
|
388
|
+
export const TEXT_PREVIEW_LENGTHS_EXPORT = TEXT_PREVIEW_LENGTHS;
|
389
|
+
export const PERFORMANCE_THRESHOLDS_EXPORT = PERFORMANCE_THRESHOLDS;
|
@@ -0,0 +1,224 @@
|
|
1
|
+
/**
|
2
|
+
* Retry and Circuit Breaker Constants for NeuroLink
|
3
|
+
*
|
4
|
+
* Centralized retry configuration to replace magic numbers throughout the codebase.
|
5
|
+
* Includes retry attempts, delays, backoff strategies, and circuit breaker settings.
|
6
|
+
*
|
7
|
+
* @fileoverview Retry and resilience constants for robust error handling
|
8
|
+
* @author NeuroLink Team
|
9
|
+
* @version 1.0.0
|
10
|
+
*/
|
11
|
+
/**
|
12
|
+
* Retry attempt configuration
|
13
|
+
* Balanced for reliability vs performance across different operation types
|
14
|
+
*/
|
15
|
+
export declare const RETRY_ATTEMPTS: {
|
16
|
+
/** Default retry attempts for most operations */
|
17
|
+
readonly DEFAULT: 3;
|
18
|
+
/** Critical operations that must succeed */
|
19
|
+
readonly CRITICAL: 5;
|
20
|
+
/** Quick operations that should fail fast */
|
21
|
+
readonly QUICK: 2;
|
22
|
+
/** Network operations prone to transient failures */
|
23
|
+
readonly NETWORK: 4;
|
24
|
+
/** Authentication operations */
|
25
|
+
readonly AUTH: 2;
|
26
|
+
/** Database operations */
|
27
|
+
readonly DATABASE: 3;
|
28
|
+
/** File I/O operations */
|
29
|
+
readonly FILE_IO: 2;
|
30
|
+
};
|
31
|
+
/**
|
32
|
+
* Retry delay configuration
|
33
|
+
* Configured to prevent overwhelming services while providing quick recovery
|
34
|
+
*/
|
35
|
+
export declare const RETRY_DELAYS: {
|
36
|
+
/** Base delay for exponential backoff */
|
37
|
+
readonly BASE_MS: 1000;
|
38
|
+
/** Minimum delay between retries */
|
39
|
+
readonly MIN_MS: 500;
|
40
|
+
/** Maximum delay between retries */
|
41
|
+
readonly MAX_MS: 30000;
|
42
|
+
/** Quick retry delay for fast operations */
|
43
|
+
readonly QUICK_MS: 200;
|
44
|
+
/** Network operation base delay */
|
45
|
+
readonly NETWORK_BASE_MS: 2000;
|
46
|
+
/** Authentication delay (security consideration) */
|
47
|
+
readonly AUTH_MS: 3000;
|
48
|
+
};
|
49
|
+
/**
|
50
|
+
* Exponential backoff configuration
|
51
|
+
* Controls how delays increase with each retry attempt
|
52
|
+
*/
|
53
|
+
export declare const BACKOFF_CONFIG: {
|
54
|
+
/** Standard exponential multiplier */
|
55
|
+
readonly MULTIPLIER: 2;
|
56
|
+
/** Conservative multiplier for sensitive operations */
|
57
|
+
readonly CONSERVATIVE_MULTIPLIER: 1.5;
|
58
|
+
/** Aggressive multiplier for operations that should back off quickly */
|
59
|
+
readonly AGGRESSIVE_MULTIPLIER: 3;
|
60
|
+
/** Jitter factor to prevent thundering herd */
|
61
|
+
readonly JITTER_FACTOR: 0.1;
|
62
|
+
/** Maximum jitter amount in milliseconds */
|
63
|
+
readonly MAX_JITTER_MS: 1000;
|
64
|
+
};
|
65
|
+
/**
|
66
|
+
* Circuit breaker configuration
|
67
|
+
* Prevents cascading failures and provides automatic recovery
|
68
|
+
*/
|
69
|
+
export declare const CIRCUIT_BREAKER: {
|
70
|
+
/** Failure threshold before opening circuit */
|
71
|
+
readonly FAILURE_THRESHOLD: 5;
|
72
|
+
/** Success threshold for closing circuit from half-open */
|
73
|
+
readonly SUCCESS_THRESHOLD: 3;
|
74
|
+
/** Minimum calls before calculating failure rate */
|
75
|
+
readonly MIN_CALLS: 10;
|
76
|
+
/** Failure rate threshold (0.0 to 1.0) */
|
77
|
+
readonly FAILURE_RATE_THRESHOLD: 0.5;
|
78
|
+
/** Monitoring window for failure tracking */
|
79
|
+
readonly MONITORING_WINDOW_MS: 300000;
|
80
|
+
/** Half-open max calls for testing recovery */
|
81
|
+
readonly HALF_OPEN_MAX_CALLS: 3;
|
82
|
+
};
|
83
|
+
/**
|
84
|
+
* Provider-specific retry configuration
|
85
|
+
* Different providers may need different retry strategies
|
86
|
+
*/
|
87
|
+
export declare const PROVIDER_RETRY: {
|
88
|
+
/** OpenAI retry configuration */
|
89
|
+
readonly OPENAI: {
|
90
|
+
readonly maxAttempts: 3;
|
91
|
+
readonly baseDelay: 1000;
|
92
|
+
readonly maxDelay: 30000;
|
93
|
+
readonly multiplier: 2;
|
94
|
+
};
|
95
|
+
/** Anthropic retry configuration */
|
96
|
+
readonly ANTHROPIC: {
|
97
|
+
readonly maxAttempts: 3;
|
98
|
+
readonly baseDelay: 1000;
|
99
|
+
readonly maxDelay: 30000;
|
100
|
+
readonly multiplier: 1.5;
|
101
|
+
};
|
102
|
+
/** Google (Vertex/Google AI) retry configuration */
|
103
|
+
readonly GOOGLE: {
|
104
|
+
readonly maxAttempts: 4;
|
105
|
+
readonly baseDelay: 2000;
|
106
|
+
readonly maxDelay: 30000;
|
107
|
+
readonly multiplier: 2;
|
108
|
+
};
|
109
|
+
/** AWS Bedrock retry configuration */
|
110
|
+
readonly BEDROCK: {
|
111
|
+
readonly maxAttempts: 5;
|
112
|
+
readonly baseDelay: 1000;
|
113
|
+
readonly maxDelay: 30000;
|
114
|
+
readonly multiplier: 1.5;
|
115
|
+
};
|
116
|
+
/** Azure OpenAI retry configuration */
|
117
|
+
readonly AZURE: {
|
118
|
+
readonly maxAttempts: 3;
|
119
|
+
readonly baseDelay: 1000;
|
120
|
+
readonly maxDelay: 30000;
|
121
|
+
readonly multiplier: 2;
|
122
|
+
};
|
123
|
+
/** Ollama retry configuration (local service) */
|
124
|
+
readonly OLLAMA: {
|
125
|
+
readonly maxAttempts: 2;
|
126
|
+
readonly baseDelay: 200;
|
127
|
+
readonly maxDelay: 5000;
|
128
|
+
readonly multiplier: 1.5;
|
129
|
+
};
|
130
|
+
};
|
131
|
+
/**
|
132
|
+
* Operation-specific retry configuration
|
133
|
+
* Different operations may require different retry strategies
|
134
|
+
*/
|
135
|
+
export declare const OPERATION_RETRY: {
|
136
|
+
/** Tool execution retry config */
|
137
|
+
readonly TOOL_EXECUTION: {
|
138
|
+
readonly maxAttempts: 3;
|
139
|
+
readonly baseDelay: 1000;
|
140
|
+
readonly circuitBreaker: true;
|
141
|
+
};
|
142
|
+
/** MCP operation retry config */
|
143
|
+
readonly MCP_OPERATION: {
|
144
|
+
readonly maxAttempts: 2;
|
145
|
+
readonly baseDelay: 200;
|
146
|
+
readonly circuitBreaker: false;
|
147
|
+
};
|
148
|
+
/** Network request retry config */
|
149
|
+
readonly NETWORK_REQUEST: {
|
150
|
+
readonly maxAttempts: 4;
|
151
|
+
readonly baseDelay: 2000;
|
152
|
+
readonly circuitBreaker: true;
|
153
|
+
};
|
154
|
+
/** Database operation retry config */
|
155
|
+
readonly DATABASE_OPERATION: {
|
156
|
+
readonly maxAttempts: 3;
|
157
|
+
readonly baseDelay: 1000;
|
158
|
+
readonly circuitBreaker: true;
|
159
|
+
};
|
160
|
+
/** Authentication retry config */
|
161
|
+
readonly AUTHENTICATION: {
|
162
|
+
readonly maxAttempts: 2;
|
163
|
+
readonly baseDelay: 3000;
|
164
|
+
readonly circuitBreaker: false;
|
165
|
+
};
|
166
|
+
};
|
167
|
+
/**
|
168
|
+
* Retry utility functions
|
169
|
+
*/
|
170
|
+
export declare const RetryUtils: {
|
171
|
+
/**
|
172
|
+
* Calculate exponential backoff delay
|
173
|
+
* @param attempt - Current attempt number (0-based)
|
174
|
+
* @param baseDelay - Base delay in milliseconds
|
175
|
+
* @param multiplier - Exponential multiplier
|
176
|
+
* @param maxDelay - Maximum delay cap
|
177
|
+
* @param jitter - Whether to add random jitter
|
178
|
+
* @returns Calculated delay in milliseconds
|
179
|
+
*/
|
180
|
+
readonly calculateBackoffDelay: (attempt: number, baseDelay?: number, multiplier?: number, maxDelay?: number, jitter?: boolean) => number;
|
181
|
+
/**
|
182
|
+
* Check if an error is retriable
|
183
|
+
* @param error - The error to check
|
184
|
+
* @returns True if the error should be retried
|
185
|
+
*/
|
186
|
+
readonly isRetriableError: (error: Error | unknown) => boolean;
|
187
|
+
/**
|
188
|
+
* Get retry configuration for a specific provider
|
189
|
+
* @param provider - Provider name
|
190
|
+
* @returns Retry configuration object
|
191
|
+
*/
|
192
|
+
readonly getProviderRetryConfig: (provider: string) => {
|
193
|
+
readonly maxAttempts: 3;
|
194
|
+
readonly baseDelay: 1000;
|
195
|
+
readonly maxDelay: 30000;
|
196
|
+
readonly multiplier: 2;
|
197
|
+
} | {
|
198
|
+
readonly maxAttempts: 3;
|
199
|
+
readonly baseDelay: 1000;
|
200
|
+
readonly maxDelay: 30000;
|
201
|
+
readonly multiplier: 1.5;
|
202
|
+
} | {
|
203
|
+
readonly maxAttempts: 4;
|
204
|
+
readonly baseDelay: 2000;
|
205
|
+
readonly maxDelay: 30000;
|
206
|
+
readonly multiplier: 2;
|
207
|
+
} | {
|
208
|
+
readonly maxAttempts: 5;
|
209
|
+
readonly baseDelay: 1000;
|
210
|
+
readonly maxDelay: 30000;
|
211
|
+
readonly multiplier: 1.5;
|
212
|
+
} | {
|
213
|
+
readonly maxAttempts: 2;
|
214
|
+
readonly baseDelay: 200;
|
215
|
+
readonly maxDelay: 5000;
|
216
|
+
readonly multiplier: 1.5;
|
217
|
+
};
|
218
|
+
};
|
219
|
+
export declare const DEFAULT_RETRY_ATTEMPTS: 3;
|
220
|
+
export declare const DEFAULT_INITIAL_DELAY: 1000;
|
221
|
+
export declare const DEFAULT_MAX_DELAY: 30000;
|
222
|
+
export declare const DEFAULT_BACKOFF_MULTIPLIER: 2;
|
223
|
+
export declare const CIRCUIT_BREAKER_FAILURE_THRESHOLD: 5;
|
224
|
+
export { CIRCUIT_BREAKER_RESET_MS } from "./timeouts.js";
|