@juspay/neurolink 7.0.0 ā 7.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 +15 -4
- package/README.md +16 -11
- package/dist/cli/commands/config.d.ts +2 -2
- package/dist/cli/commands/config.js +22 -21
- package/dist/cli/commands/mcp.d.ts +79 -0
- package/dist/cli/commands/mcp.js +916 -0
- package/dist/cli/commands/models.d.ts +63 -0
- package/dist/cli/commands/models.js +653 -0
- package/dist/cli/commands/ollama.js +56 -55
- package/dist/cli/factories/commandFactory.d.ts +67 -2
- package/dist/cli/factories/commandFactory.js +840 -92
- package/dist/cli/index.d.ts +6 -0
- package/dist/cli/index.js +42 -999
- package/dist/cli/utils/completeSetup.js +9 -8
- package/dist/cli/utils/envManager.js +7 -6
- package/dist/cli/utils/interactiveSetup.js +20 -19
- package/dist/core/analytics.js +25 -38
- package/dist/core/baseProvider.d.ts +8 -0
- package/dist/core/baseProvider.js +177 -68
- package/dist/core/constants.d.ts +11 -0
- package/dist/core/constants.js +17 -0
- package/dist/core/evaluation.js +25 -14
- package/dist/core/factory.js +21 -18
- package/dist/core/streamAnalytics.d.ts +65 -0
- package/dist/core/streamAnalytics.js +125 -0
- package/dist/factories/providerRegistry.js +3 -1
- package/dist/lib/core/analytics.js +25 -38
- package/dist/lib/core/baseProvider.d.ts +8 -0
- package/dist/lib/core/baseProvider.js +177 -68
- package/dist/lib/core/constants.d.ts +11 -0
- package/dist/lib/core/constants.js +17 -0
- package/dist/lib/core/evaluation.js +25 -14
- package/dist/lib/core/factory.js +22 -18
- package/dist/lib/core/streamAnalytics.d.ts +65 -0
- package/dist/lib/core/streamAnalytics.js +125 -0
- package/dist/lib/factories/providerRegistry.js +3 -1
- package/dist/lib/mcp/toolRegistry.d.ts +5 -0
- package/dist/lib/mcp/toolRegistry.js +60 -0
- package/dist/lib/models/modelRegistry.d.ts +132 -0
- package/dist/lib/models/modelRegistry.js +483 -0
- package/dist/lib/models/modelResolver.d.ts +115 -0
- package/dist/lib/models/modelResolver.js +467 -0
- package/dist/lib/neurolink.d.ts +4 -1
- package/dist/lib/neurolink.js +108 -69
- package/dist/lib/providers/anthropic.js +3 -0
- package/dist/lib/providers/googleAiStudio.js +13 -0
- package/dist/lib/providers/huggingFace.js +15 -3
- package/dist/lib/providers/mistral.js +19 -7
- package/dist/lib/providers/ollama.js +31 -7
- package/dist/lib/providers/openAI.js +12 -0
- package/dist/lib/sdk/toolRegistration.js +17 -0
- package/dist/lib/types/cli.d.ts +56 -1
- package/dist/lib/types/contextTypes.d.ts +110 -0
- package/dist/lib/types/contextTypes.js +176 -0
- package/dist/lib/types/index.d.ts +4 -1
- package/dist/lib/types/mcpTypes.d.ts +118 -7
- package/dist/lib/types/providers.d.ts +81 -0
- package/dist/lib/types/streamTypes.d.ts +44 -7
- package/dist/lib/types/tools.d.ts +9 -0
- package/dist/lib/types/universalProviderOptions.d.ts +3 -1
- package/dist/lib/types/universalProviderOptions.js +2 -1
- package/dist/lib/utils/logger.d.ts +7 -0
- package/dist/lib/utils/logger.js +16 -6
- package/dist/lib/utils/performance.d.ts +105 -0
- package/dist/lib/utils/performance.js +210 -0
- package/dist/lib/utils/providerUtils.js +9 -2
- package/dist/lib/utils/retryHandler.d.ts +89 -0
- package/dist/lib/utils/retryHandler.js +269 -0
- package/dist/mcp/toolRegistry.d.ts +5 -0
- package/dist/mcp/toolRegistry.js +60 -0
- package/dist/models/modelRegistry.d.ts +132 -0
- package/dist/models/modelRegistry.js +483 -0
- package/dist/models/modelResolver.d.ts +115 -0
- package/dist/models/modelResolver.js +468 -0
- package/dist/neurolink.d.ts +4 -1
- package/dist/neurolink.js +108 -69
- package/dist/providers/anthropic.js +3 -0
- package/dist/providers/googleAiStudio.js +13 -0
- package/dist/providers/huggingFace.js +15 -3
- package/dist/providers/mistral.js +19 -7
- package/dist/providers/ollama.js +31 -7
- package/dist/providers/openAI.js +12 -0
- package/dist/sdk/toolRegistration.js +17 -0
- package/dist/types/cli.d.ts +56 -1
- package/dist/types/contextTypes.d.ts +110 -0
- package/dist/types/contextTypes.js +177 -0
- package/dist/types/index.d.ts +4 -1
- package/dist/types/mcpTypes.d.ts +118 -7
- package/dist/types/providers.d.ts +81 -0
- package/dist/types/streamTypes.d.ts +44 -7
- package/dist/types/tools.d.ts +9 -0
- package/dist/types/universalProviderOptions.d.ts +3 -1
- package/dist/types/universalProviderOptions.js +3 -1
- package/dist/utils/logger.d.ts +7 -0
- package/dist/utils/logger.js +16 -6
- package/dist/utils/performance.d.ts +105 -0
- package/dist/utils/performance.js +210 -0
- package/dist/utils/providerUtils.js +9 -2
- package/dist/utils/retryHandler.d.ts +89 -0
- package/dist/utils/retryHandler.js +269 -0
- package/package.json +2 -1
package/dist/utils/logger.js
CHANGED
|
@@ -23,11 +23,7 @@ class NeuroLinkLogger {
|
|
|
23
23
|
process.argv.includes("--debug") ||
|
|
24
24
|
process.env.NEUROLINK_DEBUG === "true";
|
|
25
25
|
// Check NEUROLINK_LOG_LEVEL for consistency with the unified NeuroLink logger
|
|
26
|
-
|
|
27
|
-
// Fallback to MCP_LOG_LEVEL for backward compatibility (if needed)
|
|
28
|
-
if (!envLevel) {
|
|
29
|
-
envLevel = process.env.MCP_LOG_LEVEL?.toLowerCase();
|
|
30
|
-
}
|
|
26
|
+
const envLevel = process.env.NEUROLINK_LOG_LEVEL?.toLowerCase();
|
|
31
27
|
if (envLevel && ["debug", "info", "warn", "error"].includes(envLevel)) {
|
|
32
28
|
this.logLevel = envLevel;
|
|
33
29
|
}
|
|
@@ -36,8 +32,11 @@ class NeuroLinkLogger {
|
|
|
36
32
|
this.logLevel = level;
|
|
37
33
|
}
|
|
38
34
|
shouldLog(level) {
|
|
35
|
+
// Dynamic debug mode check to handle CLI middleware timing
|
|
36
|
+
const currentDebugMode = process.argv.includes("--debug") ||
|
|
37
|
+
process.env.NEUROLINK_DEBUG === "true";
|
|
39
38
|
// Hide all logs except errors unless debugging
|
|
40
|
-
if (!
|
|
39
|
+
if (!currentDebugMode && level !== "error") {
|
|
41
40
|
return false;
|
|
42
41
|
}
|
|
43
42
|
const levels = ["debug", "info", "warn", "error"];
|
|
@@ -122,6 +121,14 @@ class NeuroLinkLogger {
|
|
|
122
121
|
always(...args) {
|
|
123
122
|
console.log(...args);
|
|
124
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Displays tabular data unconditionally using `console.table`.
|
|
126
|
+
*
|
|
127
|
+
* @param data - The data to display in table format
|
|
128
|
+
*/
|
|
129
|
+
table(data) {
|
|
130
|
+
console.table(data);
|
|
131
|
+
}
|
|
125
132
|
}
|
|
126
133
|
// Export singleton instance
|
|
127
134
|
const neuroLinkLogger = new NeuroLinkLogger();
|
|
@@ -167,6 +174,9 @@ export const logger = {
|
|
|
167
174
|
always: (...args) => {
|
|
168
175
|
neuroLinkLogger.always(...args);
|
|
169
176
|
},
|
|
177
|
+
table: (data) => {
|
|
178
|
+
neuroLinkLogger.table(data);
|
|
179
|
+
},
|
|
170
180
|
// Expose structured logging methods
|
|
171
181
|
setLogLevel: (level) => neuroLinkLogger.setLogLevel(level),
|
|
172
182
|
getLogs: (level) => neuroLinkLogger.getLogs(level),
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Performance measurement and memory management utilities
|
|
3
|
+
* Part of Sub-phase 3.3.1-3.3.2 optimization efforts
|
|
4
|
+
*/
|
|
5
|
+
export interface PerformanceMetrics {
|
|
6
|
+
startTime: number;
|
|
7
|
+
endTime?: number;
|
|
8
|
+
duration?: number;
|
|
9
|
+
memoryStart: NodeJS.MemoryUsage;
|
|
10
|
+
memoryEnd?: NodeJS.MemoryUsage;
|
|
11
|
+
memoryDelta?: {
|
|
12
|
+
rss: number;
|
|
13
|
+
heapTotal: number;
|
|
14
|
+
heapUsed: number;
|
|
15
|
+
external: number;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Performance measurement utility for tracking operations
|
|
20
|
+
*/
|
|
21
|
+
export declare class PerformanceTracker {
|
|
22
|
+
private metrics;
|
|
23
|
+
/**
|
|
24
|
+
* Start tracking performance for an operation
|
|
25
|
+
*/
|
|
26
|
+
start(operationName: string): void;
|
|
27
|
+
/**
|
|
28
|
+
* End tracking and calculate metrics
|
|
29
|
+
*/
|
|
30
|
+
end(operationName: string): PerformanceMetrics | null;
|
|
31
|
+
/**
|
|
32
|
+
* Get metrics for an operation
|
|
33
|
+
*/
|
|
34
|
+
getMetrics(operationName: string): PerformanceMetrics | null;
|
|
35
|
+
/**
|
|
36
|
+
* Clear all metrics
|
|
37
|
+
*/
|
|
38
|
+
clear(): void;
|
|
39
|
+
/**
|
|
40
|
+
* Format metrics for display
|
|
41
|
+
*/
|
|
42
|
+
formatMetrics(operationName: string): string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Global performance tracker instance
|
|
46
|
+
*/
|
|
47
|
+
export declare const globalTracker: PerformanceTracker;
|
|
48
|
+
/**
|
|
49
|
+
* Memory management utilities
|
|
50
|
+
*/
|
|
51
|
+
export declare class MemoryManager {
|
|
52
|
+
/**
|
|
53
|
+
* Force garbage collection if available
|
|
54
|
+
*/
|
|
55
|
+
static forceGC(): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Get current memory usage in MB
|
|
58
|
+
*/
|
|
59
|
+
static getMemoryUsageMB(): {
|
|
60
|
+
rss: number;
|
|
61
|
+
heapTotal: number;
|
|
62
|
+
heapUsed: number;
|
|
63
|
+
external: number;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Monitor memory usage and warn if it exceeds threshold
|
|
67
|
+
*/
|
|
68
|
+
static monitorMemory(threshold?: number): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Clean up and optimize memory usage.
|
|
71
|
+
* Attempts to force garbage collection if available.
|
|
72
|
+
*
|
|
73
|
+
* @returns {object|null} Memory usage statistics if cleanup was performed, or null if not possible.
|
|
74
|
+
* - If manual garbage collection is not available (i.e., Node.js not run with --expose-gc),
|
|
75
|
+
* no cleanup is performed and null is returned.
|
|
76
|
+
* - Clearing the require cache is not attempted due to potential side effects.
|
|
77
|
+
*/
|
|
78
|
+
static cleanup(): {
|
|
79
|
+
beforeMB: number;
|
|
80
|
+
afterMB: number;
|
|
81
|
+
freedMB: number;
|
|
82
|
+
} | null;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Decorator for tracking performance of async functions
|
|
86
|
+
*/
|
|
87
|
+
export declare function trackPerformance(operationName: string): <T extends (...args: unknown[]) => Promise<unknown>>(target: unknown, propertyName: string, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T>;
|
|
88
|
+
/**
|
|
89
|
+
* Performance monitoring for CLI operations
|
|
90
|
+
*/
|
|
91
|
+
export declare class CLIPerformanceMonitor {
|
|
92
|
+
private static instance;
|
|
93
|
+
private enabled;
|
|
94
|
+
static getInstance(): CLIPerformanceMonitor;
|
|
95
|
+
enable(): void;
|
|
96
|
+
disable(): void;
|
|
97
|
+
/**
|
|
98
|
+
* Monitor a CLI operation
|
|
99
|
+
*/
|
|
100
|
+
monitorOperation<T>(operationName: string, operation: () => Promise<T>): Promise<T>;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Export singleton monitor for easy access
|
|
104
|
+
*/
|
|
105
|
+
export declare const cliMonitor: CLIPerformanceMonitor;
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Performance measurement and memory management utilities
|
|
3
|
+
* Part of Sub-phase 3.3.1-3.3.2 optimization efforts
|
|
4
|
+
*/
|
|
5
|
+
import { logger } from "./logger.js";
|
|
6
|
+
/**
|
|
7
|
+
* Performance measurement utility for tracking operations
|
|
8
|
+
*/
|
|
9
|
+
export class PerformanceTracker {
|
|
10
|
+
metrics = new Map();
|
|
11
|
+
/**
|
|
12
|
+
* Start tracking performance for an operation
|
|
13
|
+
*/
|
|
14
|
+
start(operationName) {
|
|
15
|
+
this.metrics.set(operationName, {
|
|
16
|
+
startTime: Date.now(),
|
|
17
|
+
memoryStart: process.memoryUsage(),
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* End tracking and calculate metrics
|
|
22
|
+
*/
|
|
23
|
+
end(operationName) {
|
|
24
|
+
const metric = this.metrics.get(operationName);
|
|
25
|
+
if (!metric) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
const endTime = Date.now();
|
|
29
|
+
const memoryEnd = process.memoryUsage();
|
|
30
|
+
const completedMetric = {
|
|
31
|
+
...metric,
|
|
32
|
+
endTime,
|
|
33
|
+
duration: endTime - metric.startTime,
|
|
34
|
+
memoryEnd,
|
|
35
|
+
memoryDelta: {
|
|
36
|
+
rss: memoryEnd.rss - metric.memoryStart.rss,
|
|
37
|
+
heapTotal: memoryEnd.heapTotal - metric.memoryStart.heapTotal,
|
|
38
|
+
heapUsed: memoryEnd.heapUsed - metric.memoryStart.heapUsed,
|
|
39
|
+
external: memoryEnd.external - metric.memoryStart.external,
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
this.metrics.set(operationName, completedMetric);
|
|
43
|
+
return completedMetric;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Get metrics for an operation
|
|
47
|
+
*/
|
|
48
|
+
getMetrics(operationName) {
|
|
49
|
+
return this.metrics.get(operationName) || null;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Clear all metrics
|
|
53
|
+
*/
|
|
54
|
+
clear() {
|
|
55
|
+
this.metrics.clear();
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Format metrics for display
|
|
59
|
+
*/
|
|
60
|
+
formatMetrics(operationName) {
|
|
61
|
+
const metric = this.metrics.get(operationName);
|
|
62
|
+
if (!metric || !metric.duration) {
|
|
63
|
+
return `${operationName}: No metrics available`;
|
|
64
|
+
}
|
|
65
|
+
const memoryMB = (bytes) => (bytes / 1024 / 1024).toFixed(1);
|
|
66
|
+
return [
|
|
67
|
+
`${operationName}:`,
|
|
68
|
+
` Duration: ${metric.duration}ms`,
|
|
69
|
+
` Memory Delta: +${memoryMB(metric.memoryDelta.heapUsed)}MB heap`,
|
|
70
|
+
` RSS Delta: +${memoryMB(metric.memoryDelta.rss)}MB`,
|
|
71
|
+
].join("\n");
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Global performance tracker instance
|
|
76
|
+
*/
|
|
77
|
+
export const globalTracker = new PerformanceTracker();
|
|
78
|
+
/**
|
|
79
|
+
* Memory management utilities
|
|
80
|
+
*/
|
|
81
|
+
export class MemoryManager {
|
|
82
|
+
/**
|
|
83
|
+
* Force garbage collection if available
|
|
84
|
+
*/
|
|
85
|
+
static forceGC() {
|
|
86
|
+
if (typeof global !== "undefined" && global.gc) {
|
|
87
|
+
global.gc();
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Get current memory usage in MB
|
|
94
|
+
*/
|
|
95
|
+
static getMemoryUsageMB() {
|
|
96
|
+
const usage = process.memoryUsage();
|
|
97
|
+
return {
|
|
98
|
+
rss: Math.round(usage.rss / 1024 / 1024),
|
|
99
|
+
heapTotal: Math.round(usage.heapTotal / 1024 / 1024),
|
|
100
|
+
heapUsed: Math.round(usage.heapUsed / 1024 / 1024),
|
|
101
|
+
external: Math.round(usage.external / 1024 / 1024),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Monitor memory usage and warn if it exceeds threshold
|
|
106
|
+
*/
|
|
107
|
+
static monitorMemory(threshold = 100) {
|
|
108
|
+
const usage = this.getMemoryUsageMB();
|
|
109
|
+
if (usage.heapUsed > threshold) {
|
|
110
|
+
logger.warn(`ā ļø High memory usage: ${usage.heapUsed}MB heap (threshold: ${threshold}MB)`);
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Clean up and optimize memory usage.
|
|
117
|
+
* Attempts to force garbage collection if available.
|
|
118
|
+
*
|
|
119
|
+
* @returns {object|null} Memory usage statistics if cleanup was performed, or null if not possible.
|
|
120
|
+
* - If manual garbage collection is not available (i.e., Node.js not run with --expose-gc),
|
|
121
|
+
* no cleanup is performed and null is returned.
|
|
122
|
+
* - Clearing the require cache is not attempted due to potential side effects.
|
|
123
|
+
*/
|
|
124
|
+
static cleanup() {
|
|
125
|
+
const before = this.getMemoryUsageMB();
|
|
126
|
+
const gcForced = this.forceGC();
|
|
127
|
+
if (!gcForced) {
|
|
128
|
+
// Manual garbage collection not available.
|
|
129
|
+
// No cleanup performed. Clearing require cache is dangerous and not attempted.
|
|
130
|
+
// Memory cleanup relies on Node.js natural garbage collection.
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
const after = this.getMemoryUsageMB();
|
|
134
|
+
return {
|
|
135
|
+
beforeMB: before.heapUsed,
|
|
136
|
+
afterMB: after.heapUsed,
|
|
137
|
+
freedMB: before.heapUsed - after.heapUsed,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Decorator for tracking performance of async functions
|
|
143
|
+
*/
|
|
144
|
+
export function trackPerformance(operationName) {
|
|
145
|
+
return function (target, propertyName, descriptor) {
|
|
146
|
+
const method = descriptor.value;
|
|
147
|
+
descriptor.value = async function (...args) {
|
|
148
|
+
globalTracker.start(operationName);
|
|
149
|
+
try {
|
|
150
|
+
const result = await method.apply(this, args);
|
|
151
|
+
globalTracker.end(operationName);
|
|
152
|
+
return result;
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
globalTracker.end(operationName);
|
|
156
|
+
throw error;
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
return descriptor;
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Performance monitoring for CLI operations
|
|
164
|
+
*/
|
|
165
|
+
export class CLIPerformanceMonitor {
|
|
166
|
+
static instance;
|
|
167
|
+
enabled = false;
|
|
168
|
+
static getInstance() {
|
|
169
|
+
if (!CLIPerformanceMonitor.instance) {
|
|
170
|
+
CLIPerformanceMonitor.instance = new CLIPerformanceMonitor();
|
|
171
|
+
}
|
|
172
|
+
return CLIPerformanceMonitor.instance;
|
|
173
|
+
}
|
|
174
|
+
enable() {
|
|
175
|
+
this.enabled = true;
|
|
176
|
+
}
|
|
177
|
+
disable() {
|
|
178
|
+
this.enabled = false;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Monitor a CLI operation
|
|
182
|
+
*/
|
|
183
|
+
async monitorOperation(operationName, operation) {
|
|
184
|
+
if (!this.enabled) {
|
|
185
|
+
return operation();
|
|
186
|
+
}
|
|
187
|
+
globalTracker.start(operationName);
|
|
188
|
+
const startMemory = MemoryManager.getMemoryUsageMB();
|
|
189
|
+
try {
|
|
190
|
+
const result = await operation();
|
|
191
|
+
const metrics = globalTracker.end(operationName);
|
|
192
|
+
const endMemory = MemoryManager.getMemoryUsageMB();
|
|
193
|
+
if (metrics) {
|
|
194
|
+
logger.debug(`\nš Performance: ${operationName}`);
|
|
195
|
+
logger.debug(` Duration: ${metrics.duration}ms`);
|
|
196
|
+
logger.debug(` Memory: ${startMemory.heapUsed}MB ā ${endMemory.heapUsed}MB`);
|
|
197
|
+
logger.debug(` Delta: +${endMemory.heapUsed - startMemory.heapUsed}MB`);
|
|
198
|
+
}
|
|
199
|
+
return result;
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
globalTracker.end(operationName);
|
|
203
|
+
throw error;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Export singleton monitor for easy access
|
|
209
|
+
*/
|
|
210
|
+
export const cliMonitor = CLIPerformanceMonitor.getInstance();
|
|
@@ -105,10 +105,17 @@ export function hasProviderEnvVars(provider) {
|
|
|
105
105
|
case "aws":
|
|
106
106
|
return !!(process.env.AWS_ACCESS_KEY_ID && process.env.AWS_SECRET_ACCESS_KEY);
|
|
107
107
|
case "vertex":
|
|
108
|
+
case "googlevertex":
|
|
108
109
|
case "google":
|
|
109
110
|
case "gemini":
|
|
110
|
-
return !!(process.env.
|
|
111
|
-
process.env.
|
|
111
|
+
return !!((process.env.GOOGLE_CLOUD_PROJECT_ID ||
|
|
112
|
+
process.env.VERTEX_PROJECT_ID ||
|
|
113
|
+
process.env.GOOGLE_VERTEX_PROJECT ||
|
|
114
|
+
process.env.GOOGLE_CLOUD_PROJECT) &&
|
|
115
|
+
(process.env.GOOGLE_APPLICATION_CREDENTIALS ||
|
|
116
|
+
process.env.GOOGLE_SERVICE_ACCOUNT_KEY ||
|
|
117
|
+
(process.env.GOOGLE_AUTH_CLIENT_EMAIL &&
|
|
118
|
+
process.env.GOOGLE_AUTH_PRIVATE_KEY)));
|
|
112
119
|
case "openai":
|
|
113
120
|
case "gpt":
|
|
114
121
|
return !!process.env.OPENAI_API_KEY;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retry and resilience utilities for NeuroLink
|
|
3
|
+
* Part of Sub-phase 3.3.3 - Edge Case Handling
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Calculate exponential backoff delay with jitter
|
|
7
|
+
* @param attempt - Current attempt number (1-based)
|
|
8
|
+
* @param initialDelay - Initial delay in milliseconds
|
|
9
|
+
* @param multiplier - Backoff multiplier for exponential growth
|
|
10
|
+
* @param maxDelay - Maximum delay cap in milliseconds
|
|
11
|
+
* @param addJitter - Whether to add random jitter to prevent thundering herd
|
|
12
|
+
* @returns Calculated delay in milliseconds
|
|
13
|
+
*/
|
|
14
|
+
export declare function calculateBackoffDelay(attempt: number, initialDelay?: number, multiplier?: number, maxDelay?: number, addJitter?: boolean): number;
|
|
15
|
+
export interface RetryOptions {
|
|
16
|
+
maxAttempts?: number;
|
|
17
|
+
initialDelay?: number;
|
|
18
|
+
maxDelay?: number;
|
|
19
|
+
backoffMultiplier?: number;
|
|
20
|
+
retryCondition?: (error: unknown) => boolean;
|
|
21
|
+
onRetry?: (attempt: number, error: unknown) => void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Error types that are typically retryable
|
|
25
|
+
*/
|
|
26
|
+
export declare class NetworkError extends Error {
|
|
27
|
+
readonly cause?: Error | undefined;
|
|
28
|
+
constructor(message: string, cause?: Error | undefined);
|
|
29
|
+
}
|
|
30
|
+
export declare class TemporaryError extends Error {
|
|
31
|
+
readonly cause?: Error | undefined;
|
|
32
|
+
constructor(message: string, cause?: Error | undefined);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Default retry configuration
|
|
36
|
+
*/
|
|
37
|
+
export declare const DEFAULT_RETRY_CONFIG: Required<RetryOptions>;
|
|
38
|
+
/**
|
|
39
|
+
* Execute an operation with retry logic
|
|
40
|
+
*/
|
|
41
|
+
export declare function withRetry<T>(operation: () => Promise<T>, options?: RetryOptions): Promise<T>;
|
|
42
|
+
/**
|
|
43
|
+
* Enhanced timeout with retry for network operations
|
|
44
|
+
*/
|
|
45
|
+
export declare function withTimeoutAndRetry<T>(operation: () => Promise<T>, timeoutMs: number, retryOptions?: RetryOptions): Promise<T>;
|
|
46
|
+
/**
|
|
47
|
+
* Circuit breaker pattern for preventing cascading failures
|
|
48
|
+
*/
|
|
49
|
+
export declare class CircuitBreaker {
|
|
50
|
+
private threshold;
|
|
51
|
+
private timeout;
|
|
52
|
+
private monitorWindow;
|
|
53
|
+
private failures;
|
|
54
|
+
private lastFailureTime;
|
|
55
|
+
private state;
|
|
56
|
+
constructor(threshold?: number, timeout?: number, // 1 minute
|
|
57
|
+
monitorWindow?: number);
|
|
58
|
+
execute<T>(operation: () => Promise<T>): Promise<T>;
|
|
59
|
+
private onSuccess;
|
|
60
|
+
private onFailure;
|
|
61
|
+
getState(): string;
|
|
62
|
+
reset(): void;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Rate limiter to prevent overwhelming APIs
|
|
66
|
+
*/
|
|
67
|
+
export declare class RateLimiter {
|
|
68
|
+
private maxRequests;
|
|
69
|
+
private windowMs;
|
|
70
|
+
private requests;
|
|
71
|
+
constructor(maxRequests: number, windowMs: number);
|
|
72
|
+
acquire(): Promise<void>;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Utility for graceful shutdown handling
|
|
76
|
+
*/
|
|
77
|
+
export declare class GracefulShutdown {
|
|
78
|
+
private operations;
|
|
79
|
+
private shutdownPromise;
|
|
80
|
+
track<T>(operation: Promise<T>): Promise<T>;
|
|
81
|
+
shutdown(timeoutMs?: number): Promise<void>;
|
|
82
|
+
private performShutdown;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Global instances for convenience
|
|
86
|
+
*/
|
|
87
|
+
export declare const globalShutdown: GracefulShutdown;
|
|
88
|
+
export declare const providerCircuitBreaker: CircuitBreaker;
|
|
89
|
+
export declare const apiRateLimiter: RateLimiter;
|