@juspay/neurolink 7.30.0 → 7.31.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 +12 -0
- package/dist/core/baseProvider.d.ts +6 -6
- package/dist/core/baseProvider.js +30 -34
- package/dist/core/conversationMemoryManager.js +15 -9
- package/dist/core/types.d.ts +2 -0
- package/dist/factories/providerRegistry.js +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -0
- package/dist/lib/core/baseProvider.d.ts +6 -6
- package/dist/lib/core/baseProvider.js +30 -34
- package/dist/lib/core/conversationMemoryManager.js +15 -9
- package/dist/lib/core/types.d.ts +2 -0
- package/dist/lib/factories/providerRegistry.js +1 -1
- package/dist/lib/index.d.ts +3 -1
- package/dist/lib/index.js +2 -0
- package/dist/lib/middleware/builtin/analytics.d.ts +1 -1
- package/dist/lib/middleware/builtin/guardrails.d.ts +1 -1
- package/dist/lib/middleware/factory.d.ts +1 -1
- package/dist/lib/middleware/index.d.ts +1 -1
- package/dist/lib/middleware/registry.d.ts +1 -1
- package/dist/lib/providers/amazonBedrock.d.ts +28 -59
- package/dist/lib/providers/amazonBedrock.js +913 -330
- package/dist/lib/types/streamTypes.d.ts +2 -0
- package/dist/lib/utils/conversationMemoryUtils.js +1 -1
- package/dist/lib/utils/logger.d.ts +164 -4
- package/dist/lib/utils/logger.js +163 -10
- package/dist/lib/utils/providerUtils.js +9 -6
- package/dist/middleware/builtin/analytics.d.ts +1 -1
- package/dist/middleware/builtin/guardrails.d.ts +1 -1
- package/dist/middleware/factory.d.ts +1 -1
- package/dist/middleware/index.d.ts +1 -1
- package/dist/middleware/registry.d.ts +1 -1
- package/dist/providers/amazonBedrock.d.ts +28 -59
- package/dist/providers/amazonBedrock.js +913 -330
- package/dist/types/streamTypes.d.ts +2 -0
- package/dist/utils/conversationMemoryUtils.js +1 -1
- package/dist/utils/logger.d.ts +164 -4
- package/dist/utils/logger.js +163 -10
- package/dist/utils/providerUtils.js +9 -6
- package/package.json +2 -3
- package/dist/lib/providers/aws/credentialProvider.d.ts +0 -58
- package/dist/lib/providers/aws/credentialProvider.js +0 -267
- package/dist/lib/providers/aws/credentialTester.d.ts +0 -49
- package/dist/lib/providers/aws/credentialTester.js +0 -394
- package/dist/providers/aws/credentialProvider.d.ts +0 -58
- package/dist/providers/aws/credentialProvider.js +0 -267
- package/dist/providers/aws/credentialTester.d.ts +0 -49
- package/dist/providers/aws/credentialTester.js +0 -394
- /package/dist/lib/{middleware/types.d.ts → types/middlewareTypes.d.ts} +0 -0
- /package/dist/lib/{middleware/types.js → types/middlewareTypes.js} +0 -0
- /package/dist/{middleware/types.d.ts → types/middlewareTypes.d.ts} +0 -0
- /package/dist/{middleware/types.js → types/middlewareTypes.js} +0 -0
|
@@ -5,6 +5,7 @@ import type { EvaluationData } from "../index.js";
|
|
|
5
5
|
import type { TokenUsage } from "./providers.js";
|
|
6
6
|
import type { UnknownRecord, JsonValue } from "./common.js";
|
|
7
7
|
import type { ChatMessage } from "./conversationTypes.js";
|
|
8
|
+
import type { MiddlewareFactoryOptions } from "../types/middlewareTypes.js";
|
|
8
9
|
/**
|
|
9
10
|
* Interface for tool execution calls (AI SDK compatible)
|
|
10
11
|
*/
|
|
@@ -111,6 +112,7 @@ export interface StreamOptions {
|
|
|
111
112
|
fallbackToGenerate?: boolean;
|
|
112
113
|
};
|
|
113
114
|
conversationMessages?: ChatMessage[];
|
|
115
|
+
middleware?: MiddlewareFactoryOptions;
|
|
114
116
|
}
|
|
115
117
|
/**
|
|
116
118
|
* Stream function result interface - Primary output format for streaming
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Conversation Memory Utilities
|
|
3
3
|
* Handles configuration merging and conversation memory operations
|
|
4
4
|
*/
|
|
5
|
-
import { getConversationMemoryDefaults
|
|
5
|
+
import { getConversationMemoryDefaults } from "../config/conversationMemoryConfig.js";
|
|
6
6
|
import { logger } from "./logger.js";
|
|
7
7
|
/**
|
|
8
8
|
* Apply conversation memory defaults to user configuration
|
|
@@ -1,15 +1,38 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* NeuroLink Unified Logger Utility
|
|
3
3
|
*
|
|
4
|
-
* Centralized logging for the entire NeuroLink ecosystem
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Centralized logging for the entire NeuroLink ecosystem.
|
|
5
|
+
* Provides structured logging with different severity levels and consistent formatting.
|
|
6
|
+
* Supports both CLI --debug flag and NEUROLINK_DEBUG environment variable.
|
|
7
|
+
* Maintains compatibility with MCP logging while providing enhanced features.
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - Multiple log levels (debug, info, warn, error)
|
|
11
|
+
* - Log history retention with configurable limits
|
|
12
|
+
* - Conditional logging based on environment settings
|
|
13
|
+
* - Structured data support for complex objects
|
|
14
|
+
* - Tabular data display
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Represents the available logging severity levels.
|
|
18
|
+
* - debug: Detailed information for debugging purposes
|
|
19
|
+
* - info: General information about system operation
|
|
20
|
+
* - warn: Potential issues that don't prevent operation
|
|
21
|
+
* - error: Critical issues that may cause failures
|
|
7
22
|
*/
|
|
8
23
|
export type LogLevel = "debug" | "info" | "warn" | "error";
|
|
24
|
+
/**
|
|
25
|
+
* Represents a single log entry in the logging system.
|
|
26
|
+
* Each entry contains metadata about the log event along with the actual message.
|
|
27
|
+
*/
|
|
9
28
|
interface LogEntry {
|
|
29
|
+
/** The severity level of the log entry */
|
|
10
30
|
level: LogLevel;
|
|
31
|
+
/** The text message to be logged */
|
|
11
32
|
message: string;
|
|
33
|
+
/** When the log entry was created */
|
|
12
34
|
timestamp: Date;
|
|
35
|
+
/** Optional additional data associated with the log entry (objects, arrays, etc.) */
|
|
13
36
|
data?: unknown;
|
|
14
37
|
}
|
|
15
38
|
declare class NeuroLinkLogger {
|
|
@@ -18,8 +41,33 @@ declare class NeuroLinkLogger {
|
|
|
18
41
|
private maxLogs;
|
|
19
42
|
private isDebugMode;
|
|
20
43
|
constructor();
|
|
44
|
+
/**
|
|
45
|
+
* Sets the minimum log level that will be processed and output.
|
|
46
|
+
* Log messages with a level lower than this will be ignored.
|
|
47
|
+
*
|
|
48
|
+
* @param level - The minimum log level to process ("debug", "info", "warn", or "error")
|
|
49
|
+
*/
|
|
21
50
|
setLogLevel(level: LogLevel): void;
|
|
51
|
+
/**
|
|
52
|
+
* Determines whether a message with the given log level should be processed.
|
|
53
|
+
* This method considers both the configured log level and the current debug mode.
|
|
54
|
+
*
|
|
55
|
+
* Logic:
|
|
56
|
+
* 1. If not in debug mode, only error messages are allowed
|
|
57
|
+
* 2. If in debug mode, messages at or above the configured log level are allowed
|
|
58
|
+
*
|
|
59
|
+
* @param level - The log level to check
|
|
60
|
+
* @returns True if a message with this level should be logged, false otherwise
|
|
61
|
+
*/
|
|
22
62
|
shouldLog(level: LogLevel): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Generates a standardized prefix for log messages.
|
|
65
|
+
* The prefix includes a timestamp and the log level in a consistent format.
|
|
66
|
+
*
|
|
67
|
+
* @param timestamp - ISO string representation of the log timestamp
|
|
68
|
+
* @param level - The log level for this message
|
|
69
|
+
* @returns Formatted prefix string like "[2025-08-18T13:45:30.123Z] [NEUROLINK:ERROR]"
|
|
70
|
+
*/
|
|
23
71
|
private getLogPrefix;
|
|
24
72
|
/**
|
|
25
73
|
* Outputs a log entry to the console based on the log level.
|
|
@@ -30,12 +78,64 @@ declare class NeuroLinkLogger {
|
|
|
30
78
|
* @param data - Optional additional data to log.
|
|
31
79
|
*/
|
|
32
80
|
private outputToConsole;
|
|
81
|
+
/**
|
|
82
|
+
* Core internal logging method that handles:
|
|
83
|
+
* 1. Creating log entries with consistent format
|
|
84
|
+
* 2. Storing entries in the log history
|
|
85
|
+
* 3. Managing log rotation to prevent memory issues
|
|
86
|
+
* 4. Outputting formatted logs to the console
|
|
87
|
+
*
|
|
88
|
+
* This is the central method called by all specific logging methods (debug, info, etc.)
|
|
89
|
+
*
|
|
90
|
+
* @param level - The severity level for this log entry
|
|
91
|
+
* @param message - The message text to log
|
|
92
|
+
* @param data - Optional additional context data to include
|
|
93
|
+
*/
|
|
33
94
|
private log;
|
|
95
|
+
/**
|
|
96
|
+
* Logs a message at the debug level.
|
|
97
|
+
* Used for detailed troubleshooting information.
|
|
98
|
+
*
|
|
99
|
+
* @param message - The message to log
|
|
100
|
+
* @param data - Optional additional context data
|
|
101
|
+
*/
|
|
34
102
|
debug(message: string, data?: unknown): void;
|
|
103
|
+
/**
|
|
104
|
+
* Logs a message at the info level.
|
|
105
|
+
* Used for general information about system operation.
|
|
106
|
+
*
|
|
107
|
+
* @param message - The message to log
|
|
108
|
+
* @param data - Optional additional context data
|
|
109
|
+
*/
|
|
35
110
|
info(message: string, data?: unknown): void;
|
|
111
|
+
/**
|
|
112
|
+
* Logs a message at the warn level.
|
|
113
|
+
* Used for potentially problematic situations that don't prevent operation.
|
|
114
|
+
*
|
|
115
|
+
* @param message - The message to log
|
|
116
|
+
* @param data - Optional additional context data
|
|
117
|
+
*/
|
|
36
118
|
warn(message: string, data?: unknown): void;
|
|
119
|
+
/**
|
|
120
|
+
* Logs a message at the error level.
|
|
121
|
+
* Used for critical issues that may cause failures.
|
|
122
|
+
*
|
|
123
|
+
* @param message - The message to log
|
|
124
|
+
* @param data - Optional additional context data
|
|
125
|
+
*/
|
|
37
126
|
error(message: string, data?: unknown): void;
|
|
127
|
+
/**
|
|
128
|
+
* Retrieves stored log entries, optionally filtered by log level.
|
|
129
|
+
* Returns a copy of the log entries to prevent external modification.
|
|
130
|
+
*
|
|
131
|
+
* @param level - Optional log level to filter by
|
|
132
|
+
* @returns Array of log entries, either all or filtered by level
|
|
133
|
+
*/
|
|
38
134
|
getLogs(level?: LogLevel): LogEntry[];
|
|
135
|
+
/**
|
|
136
|
+
* Removes all stored log entries.
|
|
137
|
+
* Useful for testing or when log history is no longer needed.
|
|
138
|
+
*/
|
|
39
139
|
clearLogs(): void;
|
|
40
140
|
/**
|
|
41
141
|
* Logs messages unconditionally using `console.log`.
|
|
@@ -44,16 +144,48 @@ declare class NeuroLinkLogger {
|
|
|
44
144
|
* It bypasses the structured logging mechanism and should only be used when
|
|
45
145
|
* unstructured, unconditional logging is required.
|
|
46
146
|
*
|
|
147
|
+
* Use with caution in production environments as it outputs to the console
|
|
148
|
+
* regardless of the current log level or debug mode settings.
|
|
149
|
+
*
|
|
150
|
+
* Use cases:
|
|
151
|
+
* - Critical system information that must always be visible
|
|
152
|
+
* - Status messages during initialization before logging is fully configured
|
|
153
|
+
* - Debugging in environments where normal logging might be suppressed
|
|
154
|
+
*
|
|
47
155
|
* @param args - The arguments to log. These are passed directly to `console.log`.
|
|
48
156
|
*/
|
|
49
157
|
always(...args: unknown[]): void;
|
|
50
158
|
/**
|
|
51
159
|
* Displays tabular data unconditionally using `console.table`.
|
|
52
160
|
*
|
|
53
|
-
*
|
|
161
|
+
* Similar to the `always` method, this bypasses log level checks and
|
|
162
|
+
* will display data regardless of current logging settings.
|
|
163
|
+
*
|
|
164
|
+
* Important differences from other logging methods:
|
|
165
|
+
* - Does NOT store entries in the log history
|
|
166
|
+
* - Does NOT use the structured logging format with timestamps and prefixes
|
|
167
|
+
* - Outputs directly to console without additional formatting
|
|
168
|
+
*
|
|
169
|
+
* Particularly useful for:
|
|
170
|
+
* - Displaying structured data in a readable format during debugging
|
|
171
|
+
* - Showing configuration options and their current values
|
|
172
|
+
* - Presenting comparison data between different system states
|
|
173
|
+
* - Performance metrics and timing data
|
|
174
|
+
*
|
|
175
|
+
* @param data - The data to display in table format. Can be an array of objects or an object with key-value pairs.
|
|
54
176
|
*/
|
|
55
177
|
table(data: unknown): void;
|
|
56
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* Main unified logger export that provides a simplified API for logging.
|
|
181
|
+
* This is the primary interface that should be used by application code.
|
|
182
|
+
*
|
|
183
|
+
* Features:
|
|
184
|
+
* - Convenient logging methods (debug, info, warn, error)
|
|
185
|
+
* - Unconditional logging (always, table)
|
|
186
|
+
* - Log level control and configuration
|
|
187
|
+
* - Log history management
|
|
188
|
+
*/
|
|
57
189
|
export declare const logger: {
|
|
58
190
|
debug: (...args: unknown[]) => void;
|
|
59
191
|
info: (...args: unknown[]) => void;
|
|
@@ -65,11 +197,39 @@ export declare const logger: {
|
|
|
65
197
|
getLogs: (level?: LogLevel) => LogEntry[];
|
|
66
198
|
clearLogs: () => void;
|
|
67
199
|
};
|
|
200
|
+
/**
|
|
201
|
+
* MCP compatibility exports - all use the same unified logger instance.
|
|
202
|
+
* These exports maintain backward compatibility with code that expects
|
|
203
|
+
* separate loggers for different MCP components, while actually using
|
|
204
|
+
* the same underlying logger instance.
|
|
205
|
+
*/
|
|
68
206
|
export declare const mcpLogger: NeuroLinkLogger;
|
|
69
207
|
export declare const autoDiscoveryLogger: NeuroLinkLogger;
|
|
70
208
|
export declare const registryLogger: NeuroLinkLogger;
|
|
71
209
|
export declare const unifiedRegistryLogger: NeuroLinkLogger;
|
|
210
|
+
/**
|
|
211
|
+
* Sets the global log level for all MCP-related logging.
|
|
212
|
+
* This function provides a convenient way to adjust logging verbosity
|
|
213
|
+
* for all MCP components at once.
|
|
214
|
+
*
|
|
215
|
+
* @param level - The log level to set ("debug", "info", "warn", or "error")
|
|
216
|
+
*/
|
|
72
217
|
export declare function setGlobalMCPLogLevel(level: LogLevel): void;
|
|
218
|
+
/**
|
|
219
|
+
* Export LogLevel enum for runtime use.
|
|
220
|
+
* Provides type-safe log level constants for use in application code.
|
|
221
|
+
*
|
|
222
|
+
* Example usage:
|
|
223
|
+
* ```
|
|
224
|
+
* import { logger, LogLevels } from './logger'; // Import from your project's path
|
|
225
|
+
*
|
|
226
|
+
* // Using the LogLevels constants (recommended for type safety):
|
|
227
|
+
* logger.setLogLevel(LogLevels.debug);
|
|
228
|
+
*
|
|
229
|
+
* // Or directly using string values:
|
|
230
|
+
* logger.setLogLevel('debug');
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
73
233
|
export declare const LogLevels: {
|
|
74
234
|
readonly debug: "debug";
|
|
75
235
|
readonly info: "info";
|
package/dist/lib/utils/logger.js
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* NeuroLink Unified Logger Utility
|
|
3
3
|
*
|
|
4
|
-
* Centralized logging for the entire NeuroLink ecosystem
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Centralized logging for the entire NeuroLink ecosystem.
|
|
5
|
+
* Provides structured logging with different severity levels and consistent formatting.
|
|
6
|
+
* Supports both CLI --debug flag and NEUROLINK_DEBUG environment variable.
|
|
7
|
+
* Maintains compatibility with MCP logging while providing enhanced features.
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - Multiple log levels (debug, info, warn, error)
|
|
11
|
+
* - Log history retention with configurable limits
|
|
12
|
+
* - Conditional logging based on environment settings
|
|
13
|
+
* - Structured data support for complex objects
|
|
14
|
+
* - Tabular data display
|
|
7
15
|
*/
|
|
8
16
|
// Pre-computed uppercase log levels for performance optimization
|
|
9
17
|
const UPPERCASE_LOG_LEVELS = {
|
|
@@ -28,9 +36,26 @@ class NeuroLinkLogger {
|
|
|
28
36
|
this.logLevel = envLevel;
|
|
29
37
|
}
|
|
30
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Sets the minimum log level that will be processed and output.
|
|
41
|
+
* Log messages with a level lower than this will be ignored.
|
|
42
|
+
*
|
|
43
|
+
* @param level - The minimum log level to process ("debug", "info", "warn", or "error")
|
|
44
|
+
*/
|
|
31
45
|
setLogLevel(level) {
|
|
32
46
|
this.logLevel = level;
|
|
33
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Determines whether a message with the given log level should be processed.
|
|
50
|
+
* This method considers both the configured log level and the current debug mode.
|
|
51
|
+
*
|
|
52
|
+
* Logic:
|
|
53
|
+
* 1. If not in debug mode, only error messages are allowed
|
|
54
|
+
* 2. If in debug mode, messages at or above the configured log level are allowed
|
|
55
|
+
*
|
|
56
|
+
* @param level - The log level to check
|
|
57
|
+
* @returns True if a message with this level should be logged, false otherwise
|
|
58
|
+
*/
|
|
34
59
|
shouldLog(level) {
|
|
35
60
|
// Dynamic debug mode check to handle CLI middleware timing
|
|
36
61
|
const currentDebugMode = process.argv.includes("--debug") ||
|
|
@@ -42,6 +67,14 @@ class NeuroLinkLogger {
|
|
|
42
67
|
const levels = ["debug", "info", "warn", "error"];
|
|
43
68
|
return levels.indexOf(level) >= levels.indexOf(this.logLevel);
|
|
44
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Generates a standardized prefix for log messages.
|
|
72
|
+
* The prefix includes a timestamp and the log level in a consistent format.
|
|
73
|
+
*
|
|
74
|
+
* @param timestamp - ISO string representation of the log timestamp
|
|
75
|
+
* @param level - The log level for this message
|
|
76
|
+
* @returns Formatted prefix string like "[2025-08-18T13:45:30.123Z] [NEUROLINK:ERROR]"
|
|
77
|
+
*/
|
|
45
78
|
getLogPrefix(timestamp, level) {
|
|
46
79
|
return `[${timestamp}] [NEUROLINK:${UPPERCASE_LOG_LEVELS[level]}]`;
|
|
47
80
|
}
|
|
@@ -67,6 +100,19 @@ class NeuroLinkLogger {
|
|
|
67
100
|
logMethod(prefix, message);
|
|
68
101
|
}
|
|
69
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Core internal logging method that handles:
|
|
105
|
+
* 1. Creating log entries with consistent format
|
|
106
|
+
* 2. Storing entries in the log history
|
|
107
|
+
* 3. Managing log rotation to prevent memory issues
|
|
108
|
+
* 4. Outputting formatted logs to the console
|
|
109
|
+
*
|
|
110
|
+
* This is the central method called by all specific logging methods (debug, info, etc.)
|
|
111
|
+
*
|
|
112
|
+
* @param level - The severity level for this log entry
|
|
113
|
+
* @param message - The message text to log
|
|
114
|
+
* @param data - Optional additional context data to include
|
|
115
|
+
*/
|
|
70
116
|
log(level, message, data) {
|
|
71
117
|
if (!this.shouldLog(level)) {
|
|
72
118
|
return;
|
|
@@ -88,24 +134,63 @@ class NeuroLinkLogger {
|
|
|
88
134
|
const prefix = this.getLogPrefix(timestamp, level);
|
|
89
135
|
this.outputToConsole(level, prefix, message, data);
|
|
90
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Logs a message at the debug level.
|
|
139
|
+
* Used for detailed troubleshooting information.
|
|
140
|
+
*
|
|
141
|
+
* @param message - The message to log
|
|
142
|
+
* @param data - Optional additional context data
|
|
143
|
+
*/
|
|
91
144
|
debug(message, data) {
|
|
92
145
|
this.log("debug", message, data);
|
|
93
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* Logs a message at the info level.
|
|
149
|
+
* Used for general information about system operation.
|
|
150
|
+
*
|
|
151
|
+
* @param message - The message to log
|
|
152
|
+
* @param data - Optional additional context data
|
|
153
|
+
*/
|
|
94
154
|
info(message, data) {
|
|
95
155
|
this.log("info", message, data);
|
|
96
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Logs a message at the warn level.
|
|
159
|
+
* Used for potentially problematic situations that don't prevent operation.
|
|
160
|
+
*
|
|
161
|
+
* @param message - The message to log
|
|
162
|
+
* @param data - Optional additional context data
|
|
163
|
+
*/
|
|
97
164
|
warn(message, data) {
|
|
98
165
|
this.log("warn", message, data);
|
|
99
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* Logs a message at the error level.
|
|
169
|
+
* Used for critical issues that may cause failures.
|
|
170
|
+
*
|
|
171
|
+
* @param message - The message to log
|
|
172
|
+
* @param data - Optional additional context data
|
|
173
|
+
*/
|
|
100
174
|
error(message, data) {
|
|
101
175
|
this.log("error", message, data);
|
|
102
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* Retrieves stored log entries, optionally filtered by log level.
|
|
179
|
+
* Returns a copy of the log entries to prevent external modification.
|
|
180
|
+
*
|
|
181
|
+
* @param level - Optional log level to filter by
|
|
182
|
+
* @returns Array of log entries, either all or filtered by level
|
|
183
|
+
*/
|
|
103
184
|
getLogs(level) {
|
|
104
185
|
if (level) {
|
|
105
186
|
return this.logs.filter((log) => log.level === level);
|
|
106
187
|
}
|
|
107
188
|
return [...this.logs];
|
|
108
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* Removes all stored log entries.
|
|
192
|
+
* Useful for testing or when log history is no longer needed.
|
|
193
|
+
*/
|
|
109
194
|
clearLogs() {
|
|
110
195
|
this.logs = [];
|
|
111
196
|
}
|
|
@@ -116,6 +201,14 @@ class NeuroLinkLogger {
|
|
|
116
201
|
* It bypasses the structured logging mechanism and should only be used when
|
|
117
202
|
* unstructured, unconditional logging is required.
|
|
118
203
|
*
|
|
204
|
+
* Use with caution in production environments as it outputs to the console
|
|
205
|
+
* regardless of the current log level or debug mode settings.
|
|
206
|
+
*
|
|
207
|
+
* Use cases:
|
|
208
|
+
* - Critical system information that must always be visible
|
|
209
|
+
* - Status messages during initialization before logging is fully configured
|
|
210
|
+
* - Debugging in environments where normal logging might be suppressed
|
|
211
|
+
*
|
|
119
212
|
* @param args - The arguments to log. These are passed directly to `console.log`.
|
|
120
213
|
*/
|
|
121
214
|
always(...args) {
|
|
@@ -124,15 +217,41 @@ class NeuroLinkLogger {
|
|
|
124
217
|
/**
|
|
125
218
|
* Displays tabular data unconditionally using `console.table`.
|
|
126
219
|
*
|
|
127
|
-
*
|
|
220
|
+
* Similar to the `always` method, this bypasses log level checks and
|
|
221
|
+
* will display data regardless of current logging settings.
|
|
222
|
+
*
|
|
223
|
+
* Important differences from other logging methods:
|
|
224
|
+
* - Does NOT store entries in the log history
|
|
225
|
+
* - Does NOT use the structured logging format with timestamps and prefixes
|
|
226
|
+
* - Outputs directly to console without additional formatting
|
|
227
|
+
*
|
|
228
|
+
* Particularly useful for:
|
|
229
|
+
* - Displaying structured data in a readable format during debugging
|
|
230
|
+
* - Showing configuration options and their current values
|
|
231
|
+
* - Presenting comparison data between different system states
|
|
232
|
+
* - Performance metrics and timing data
|
|
233
|
+
*
|
|
234
|
+
* @param data - The data to display in table format. Can be an array of objects or an object with key-value pairs.
|
|
128
235
|
*/
|
|
129
236
|
table(data) {
|
|
130
237
|
console.table(data);
|
|
131
238
|
}
|
|
132
239
|
}
|
|
133
|
-
// Export singleton instance
|
|
240
|
+
// Export singleton instance to ensure consistent logging across the application
|
|
134
241
|
const neuroLinkLogger = new NeuroLinkLogger();
|
|
135
|
-
|
|
242
|
+
/**
|
|
243
|
+
* Helper function to process logger arguments with minimal overhead.
|
|
244
|
+
* Handles variable argument patterns and ensures safe serialization of objects.
|
|
245
|
+
*
|
|
246
|
+
* This function:
|
|
247
|
+
* 1. Extracts the first argument as the message
|
|
248
|
+
* 2. Handles serialization of non-string first arguments
|
|
249
|
+
* 3. Collects remaining arguments as additional data
|
|
250
|
+
* 4. Passes the processed arguments to the actual logging method
|
|
251
|
+
*
|
|
252
|
+
* @param args - Array of arguments passed to the logger
|
|
253
|
+
* @param logMethod - Function that will perform the actual logging
|
|
254
|
+
*/
|
|
136
255
|
function processLoggerArgs(args, logMethod) {
|
|
137
256
|
if (args.length === 0) {
|
|
138
257
|
return;
|
|
@@ -149,7 +268,16 @@ function processLoggerArgs(args, logMethod) {
|
|
|
149
268
|
const data = args.length === 2 ? args[1] : args.length > 2 ? args.slice(1) : undefined;
|
|
150
269
|
logMethod(message, data);
|
|
151
270
|
}
|
|
152
|
-
|
|
271
|
+
/**
|
|
272
|
+
* Main unified logger export that provides a simplified API for logging.
|
|
273
|
+
* This is the primary interface that should be used by application code.
|
|
274
|
+
*
|
|
275
|
+
* Features:
|
|
276
|
+
* - Convenient logging methods (debug, info, warn, error)
|
|
277
|
+
* - Unconditional logging (always, table)
|
|
278
|
+
* - Log level control and configuration
|
|
279
|
+
* - Log history management
|
|
280
|
+
*/
|
|
153
281
|
export const logger = {
|
|
154
282
|
debug: (...args) => {
|
|
155
283
|
if (neuroLinkLogger.shouldLog("debug")) {
|
|
@@ -182,16 +310,41 @@ export const logger = {
|
|
|
182
310
|
getLogs: (level) => neuroLinkLogger.getLogs(level),
|
|
183
311
|
clearLogs: () => neuroLinkLogger.clearLogs(),
|
|
184
312
|
};
|
|
185
|
-
|
|
313
|
+
/**
|
|
314
|
+
* MCP compatibility exports - all use the same unified logger instance.
|
|
315
|
+
* These exports maintain backward compatibility with code that expects
|
|
316
|
+
* separate loggers for different MCP components, while actually using
|
|
317
|
+
* the same underlying logger instance.
|
|
318
|
+
*/
|
|
186
319
|
export const mcpLogger = neuroLinkLogger;
|
|
187
320
|
export const autoDiscoveryLogger = neuroLinkLogger;
|
|
188
321
|
export const registryLogger = neuroLinkLogger;
|
|
189
322
|
export const unifiedRegistryLogger = neuroLinkLogger;
|
|
190
|
-
|
|
323
|
+
/**
|
|
324
|
+
* Sets the global log level for all MCP-related logging.
|
|
325
|
+
* This function provides a convenient way to adjust logging verbosity
|
|
326
|
+
* for all MCP components at once.
|
|
327
|
+
*
|
|
328
|
+
* @param level - The log level to set ("debug", "info", "warn", or "error")
|
|
329
|
+
*/
|
|
191
330
|
export function setGlobalMCPLogLevel(level) {
|
|
192
331
|
neuroLinkLogger.setLogLevel(level);
|
|
193
332
|
}
|
|
194
|
-
|
|
333
|
+
/**
|
|
334
|
+
* Export LogLevel enum for runtime use.
|
|
335
|
+
* Provides type-safe log level constants for use in application code.
|
|
336
|
+
*
|
|
337
|
+
* Example usage:
|
|
338
|
+
* ```
|
|
339
|
+
* import { logger, LogLevels } from './logger'; // Import from your project's path
|
|
340
|
+
*
|
|
341
|
+
* // Using the LogLevels constants (recommended for type safety):
|
|
342
|
+
* logger.setLogLevel(LogLevels.debug);
|
|
343
|
+
*
|
|
344
|
+
* // Or directly using string values:
|
|
345
|
+
* logger.setLogLevel('debug');
|
|
346
|
+
* ```
|
|
347
|
+
*/
|
|
195
348
|
export const LogLevels = {
|
|
196
349
|
debug: "debug",
|
|
197
350
|
info: "info",
|
|
@@ -14,21 +14,24 @@ import { ProviderHealthChecker } from "./providerHealth.js";
|
|
|
14
14
|
export async function getBestProvider(requestedProvider) {
|
|
15
15
|
// Check requested provider FIRST - explicit user choice overrides defaults
|
|
16
16
|
if (requestedProvider && requestedProvider !== "auto") {
|
|
17
|
-
// For explicit provider requests,
|
|
17
|
+
// For explicit provider requests, ALWAYS honor the request
|
|
18
|
+
// Never override explicit provider selection with health-based fallbacks
|
|
19
|
+
logger.debug(`[getBestProvider] Using explicitly requested provider: ${requestedProvider}`);
|
|
20
|
+
// Optional health check for logging purposes only
|
|
18
21
|
try {
|
|
19
22
|
const health = await ProviderHealthChecker.checkProviderHealth(requestedProvider, { includeConnectivityTest: false, cacheResults: true });
|
|
20
23
|
if (health.isHealthy) {
|
|
21
|
-
logger.debug(`[getBestProvider]
|
|
22
|
-
return requestedProvider;
|
|
24
|
+
logger.debug(`[getBestProvider] Explicitly requested provider ${requestedProvider} is healthy`);
|
|
23
25
|
}
|
|
24
26
|
else {
|
|
25
|
-
logger.warn(`[getBestProvider]
|
|
27
|
+
logger.warn(`[getBestProvider] Explicitly requested provider ${requestedProvider} may have issues, but using anyway`, { error: health.error });
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
30
|
catch (error) {
|
|
29
|
-
logger.warn(`[getBestProvider] Health check failed for ${requestedProvider}, using anyway`, { error: error instanceof Error ? error.message : String(error) });
|
|
30
|
-
return requestedProvider; // Return anyway for explicit requests
|
|
31
|
+
logger.warn(`[getBestProvider] Health check failed for explicitly requested provider ${requestedProvider}, using anyway`, { error: error instanceof Error ? error.message : String(error) });
|
|
31
32
|
}
|
|
33
|
+
// ALWAYS return the explicitly requested provider
|
|
34
|
+
return requestedProvider;
|
|
32
35
|
}
|
|
33
36
|
// Use health checker to get best available provider
|
|
34
37
|
const healthyProvider = await ProviderHealthChecker.getBestHealthyProvider();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { NeuroLinkMiddleware } from "
|
|
1
|
+
import type { NeuroLinkMiddleware } from "../../types/middlewareTypes.js";
|
|
2
2
|
/**
|
|
3
3
|
* Create analytics middleware for tracking AI model usage
|
|
4
4
|
* Collects metrics on token usage, response times, and model performance
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { LanguageModelV1 } from "ai";
|
|
2
|
-
import type { MiddlewareContext, MiddlewareConfig, MiddlewareFactoryOptions, MiddlewareChainStats, MiddlewarePreset, NeuroLinkMiddleware, MiddlewareRegistrationOptions } from "
|
|
2
|
+
import type { MiddlewareContext, MiddlewareConfig, MiddlewareFactoryOptions, MiddlewareChainStats, MiddlewarePreset, NeuroLinkMiddleware, MiddlewareRegistrationOptions } from "../types/middlewareTypes.js";
|
|
3
3
|
import { MiddlewareRegistry } from "./registry.js";
|
|
4
4
|
/**
|
|
5
5
|
* Middleware factory for creating and applying middleware chains.
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* of language models with features like analytics, guardrails, caching, and more.
|
|
7
7
|
*/
|
|
8
8
|
import { MiddlewareFactory } from "./factory.js";
|
|
9
|
-
export type { NeuroLinkMiddleware, MiddlewareConfig, MiddlewareContext, MiddlewareConditions, MiddlewareRegistrationOptions, MiddlewareExecutionResult, MiddlewareChainStats, MiddlewarePreset, MiddlewareFactoryOptions, BuiltInMiddlewareType, } from "
|
|
9
|
+
export type { NeuroLinkMiddleware, MiddlewareConfig, MiddlewareContext, MiddlewareConditions, MiddlewareRegistrationOptions, MiddlewareExecutionResult, MiddlewareChainStats, MiddlewarePreset, MiddlewareFactoryOptions, BuiltInMiddlewareType, } from "../types/middlewareTypes.js";
|
|
10
10
|
export type { LanguageModelV1Middleware } from "ai";
|
|
11
11
|
export { MiddlewareFactory };
|
|
12
12
|
export default MiddlewareFactory;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { LanguageModelV1Middleware } from "ai";
|
|
2
|
-
import type { NeuroLinkMiddleware, MiddlewareConfig, MiddlewareContext, MiddlewareRegistrationOptions, MiddlewareExecutionResult } from "
|
|
2
|
+
import type { NeuroLinkMiddleware, MiddlewareConfig, MiddlewareContext, MiddlewareRegistrationOptions, MiddlewareExecutionResult } from "../types/middlewareTypes.js";
|
|
3
3
|
/**
|
|
4
4
|
* Manages the registration, configuration, and execution of middleware for a single factory instance.
|
|
5
5
|
*/
|