@juspay/neurolink 7.53.4 → 7.54.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 +8 -0
- package/dist/cli/commands/config.d.ts +18 -18
- package/dist/index.d.ts +1 -1
- package/dist/lib/agent/directTools.d.ts +3 -3
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/neurolink.js +2 -74
- package/dist/lib/providers/sagemaker/language-model.d.ts +2 -2
- package/dist/lib/types/common.d.ts +6 -5
- package/dist/lib/types/modelTypes.d.ts +31 -14
- package/dist/lib/types/tools.d.ts +16 -1
- package/dist/lib/types/utilities.d.ts +131 -0
- package/dist/lib/types/utilities.js +1 -1
- package/dist/lib/utils/errorHandling.d.ts +2 -28
- package/dist/lib/utils/errorHandling.js +1 -20
- package/dist/lib/utils/logger.d.ts +23 -23
- package/dist/lib/utils/logger.js +35 -0
- package/dist/lib/utils/modelRouter.d.ts +1 -17
- package/dist/lib/utils/optionsConversion.d.ts +0 -5
- package/dist/lib/utils/optionsUtils.d.ts +1 -70
- package/dist/lib/utils/parameterValidation.d.ts +9 -22
- package/dist/lib/utils/performance.d.ts +1 -13
- package/dist/lib/utils/promptRedaction.d.ts +1 -8
- package/dist/lib/utils/providerUtils.d.ts +2 -10
- package/dist/lib/utils/redis.d.ts +1 -1
- package/dist/lib/utils/redis.js +0 -1
- package/dist/lib/utils/retryHandler.d.ts +1 -8
- package/dist/neurolink.js +2 -74
- package/dist/providers/sagemaker/language-model.d.ts +2 -2
- package/dist/types/common.d.ts +6 -5
- package/dist/types/modelTypes.d.ts +17 -0
- package/dist/types/tools.d.ts +16 -1
- package/dist/types/utilities.d.ts +131 -0
- package/dist/types/utilities.js +1 -1
- package/dist/utils/errorHandling.d.ts +2 -28
- package/dist/utils/errorHandling.js +1 -20
- package/dist/utils/logger.d.ts +23 -23
- package/dist/utils/logger.js +35 -0
- package/dist/utils/modelRouter.d.ts +1 -17
- package/dist/utils/optionsConversion.d.ts +0 -5
- package/dist/utils/optionsUtils.d.ts +1 -70
- package/dist/utils/parameterValidation.d.ts +9 -22
- package/dist/utils/performance.d.ts +1 -13
- package/dist/utils/promptRedaction.d.ts +1 -8
- package/dist/utils/providerUtils.d.ts +2 -10
- package/dist/utils/redis.d.ts +1 -1
- package/dist/utils/redis.js +0 -1
- package/dist/utils/retryHandler.d.ts +1 -8
- package/package.json +1 -1
|
@@ -2,34 +2,8 @@
|
|
|
2
2
|
* Robust Error Handling Utilities for NeuroLink
|
|
3
3
|
* Provides structured error management for tool execution and system operations
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
TIMEOUT = "timeout",
|
|
8
|
-
NETWORK = "network",
|
|
9
|
-
RESOURCE = "resource",
|
|
10
|
-
PERMISSION = "permission",
|
|
11
|
-
CONFIGURATION = "configuration",
|
|
12
|
-
EXECUTION = "execution",
|
|
13
|
-
SYSTEM = "system"
|
|
14
|
-
}
|
|
15
|
-
export declare enum ErrorSeverity {
|
|
16
|
-
LOW = "low",
|
|
17
|
-
MEDIUM = "medium",
|
|
18
|
-
HIGH = "high",
|
|
19
|
-
CRITICAL = "critical"
|
|
20
|
-
}
|
|
21
|
-
export type StructuredError = {
|
|
22
|
-
code: string;
|
|
23
|
-
message: string;
|
|
24
|
-
category: ErrorCategory;
|
|
25
|
-
severity: ErrorSeverity;
|
|
26
|
-
retriable: boolean;
|
|
27
|
-
context?: Record<string, unknown>;
|
|
28
|
-
originalError?: Error;
|
|
29
|
-
timestamp: Date;
|
|
30
|
-
toolName?: string;
|
|
31
|
-
serverId?: string;
|
|
32
|
-
};
|
|
5
|
+
import { ErrorCategory, ErrorSeverity } from "../constants/enums.js";
|
|
6
|
+
import type { StructuredError } from "../types/utilities.js";
|
|
33
7
|
export declare const ERROR_CODES: {
|
|
34
8
|
readonly TOOL_NOT_FOUND: "TOOL_NOT_FOUND";
|
|
35
9
|
readonly TOOL_EXECUTION_FAILED: "TOOL_EXECUTION_FAILED";
|
|
@@ -2,27 +2,8 @@
|
|
|
2
2
|
* Robust Error Handling Utilities for NeuroLink
|
|
3
3
|
* Provides structured error management for tool execution and system operations
|
|
4
4
|
*/
|
|
5
|
+
import { ErrorCategory, ErrorSeverity } from "../constants/enums.js";
|
|
5
6
|
import { logger } from "./logger.js";
|
|
6
|
-
// Error categories for proper handling
|
|
7
|
-
export var ErrorCategory;
|
|
8
|
-
(function (ErrorCategory) {
|
|
9
|
-
ErrorCategory["VALIDATION"] = "validation";
|
|
10
|
-
ErrorCategory["TIMEOUT"] = "timeout";
|
|
11
|
-
ErrorCategory["NETWORK"] = "network";
|
|
12
|
-
ErrorCategory["RESOURCE"] = "resource";
|
|
13
|
-
ErrorCategory["PERMISSION"] = "permission";
|
|
14
|
-
ErrorCategory["CONFIGURATION"] = "configuration";
|
|
15
|
-
ErrorCategory["EXECUTION"] = "execution";
|
|
16
|
-
ErrorCategory["SYSTEM"] = "system";
|
|
17
|
-
})(ErrorCategory || (ErrorCategory = {}));
|
|
18
|
-
// Error severity levels
|
|
19
|
-
export var ErrorSeverity;
|
|
20
|
-
(function (ErrorSeverity) {
|
|
21
|
-
ErrorSeverity["LOW"] = "low";
|
|
22
|
-
ErrorSeverity["MEDIUM"] = "medium";
|
|
23
|
-
ErrorSeverity["HIGH"] = "high";
|
|
24
|
-
ErrorSeverity["CRITICAL"] = "critical";
|
|
25
|
-
})(ErrorSeverity || (ErrorSeverity = {}));
|
|
26
7
|
// Error codes for different scenarios
|
|
27
8
|
export const ERROR_CODES = {
|
|
28
9
|
// Tool errors
|
|
@@ -13,34 +13,28 @@
|
|
|
13
13
|
* - Structured data support for complex objects
|
|
14
14
|
* - Tabular data display
|
|
15
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
|
|
22
|
-
*/
|
|
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
|
-
*/
|
|
28
|
-
interface LogEntry {
|
|
29
|
-
/** The severity level of the log entry */
|
|
30
|
-
level: LogLevel;
|
|
31
|
-
/** The text message to be logged */
|
|
32
|
-
message: string;
|
|
33
|
-
/** When the log entry was created */
|
|
34
|
-
timestamp: Date;
|
|
35
|
-
/** Optional additional data associated with the log entry (objects, arrays, etc.) */
|
|
36
|
-
data?: unknown;
|
|
37
|
-
}
|
|
16
|
+
import type { LogEntry, LogLevel } from "../types/utilities.js";
|
|
38
17
|
declare class NeuroLinkLogger {
|
|
39
18
|
private logLevel;
|
|
40
19
|
private logs;
|
|
41
20
|
private maxLogs;
|
|
42
21
|
private isDebugMode;
|
|
22
|
+
private eventEmitter?;
|
|
43
23
|
constructor();
|
|
24
|
+
/**
|
|
25
|
+
* Sets the event emitter that will receive log events.
|
|
26
|
+
* When set, all log operations will emit a "log-event" event.
|
|
27
|
+
*
|
|
28
|
+
* @param emitter - The event emitter instance
|
|
29
|
+
*/
|
|
30
|
+
setEventEmitter(emitter: {
|
|
31
|
+
emit: (event: string, ...args: unknown[]) => boolean;
|
|
32
|
+
}): void;
|
|
33
|
+
/**
|
|
34
|
+
* Clears the event emitter reference.
|
|
35
|
+
* Should be called when a NeuroLink instance is disposed to prevent memory leaks.
|
|
36
|
+
*/
|
|
37
|
+
clearEventEmitter(): void;
|
|
44
38
|
/**
|
|
45
39
|
* Sets the minimum log level that will be processed and output.
|
|
46
40
|
* Log messages with a level lower than this will be ignored.
|
|
@@ -84,6 +78,7 @@ declare class NeuroLinkLogger {
|
|
|
84
78
|
* 2. Storing entries in the log history
|
|
85
79
|
* 3. Managing log rotation to prevent memory issues
|
|
86
80
|
* 4. Outputting formatted logs to the console
|
|
81
|
+
* 5. Emitting log events if an event emitter is configured
|
|
87
82
|
*
|
|
88
83
|
* This is the central method called by all specific logging methods (debug, info, etc.)
|
|
89
84
|
*
|
|
@@ -185,6 +180,7 @@ declare class NeuroLinkLogger {
|
|
|
185
180
|
* - Unconditional logging (always, table)
|
|
186
181
|
* - Log level control and configuration
|
|
187
182
|
* - Log history management
|
|
183
|
+
* - Event emission for all log operations (when emitter is configured)
|
|
188
184
|
*/
|
|
189
185
|
export declare const logger: {
|
|
190
186
|
debug: (...args: unknown[]) => void;
|
|
@@ -196,6 +192,10 @@ export declare const logger: {
|
|
|
196
192
|
setLogLevel: (level: LogLevel) => void;
|
|
197
193
|
getLogs: (level?: LogLevel) => LogEntry[];
|
|
198
194
|
clearLogs: () => void;
|
|
195
|
+
setEventEmitter: (emitter: {
|
|
196
|
+
emit: (event: string, ...args: unknown[]) => boolean;
|
|
197
|
+
}) => void;
|
|
198
|
+
clearEventEmitter: () => void;
|
|
199
199
|
};
|
|
200
200
|
/**
|
|
201
201
|
* MCP compatibility exports - all use the same unified logger instance.
|
|
@@ -236,4 +236,4 @@ export declare const LogLevels: {
|
|
|
236
236
|
readonly warn: "warn";
|
|
237
237
|
readonly error: "error";
|
|
238
238
|
};
|
|
239
|
-
export
|
|
239
|
+
export {};
|
package/dist/lib/utils/logger.js
CHANGED
|
@@ -25,6 +25,7 @@ class NeuroLinkLogger {
|
|
|
25
25
|
logs = [];
|
|
26
26
|
maxLogs = 1000;
|
|
27
27
|
isDebugMode;
|
|
28
|
+
eventEmitter;
|
|
28
29
|
constructor() {
|
|
29
30
|
// Cache debug mode check to avoid repeated array searches
|
|
30
31
|
this.isDebugMode =
|
|
@@ -36,6 +37,22 @@ class NeuroLinkLogger {
|
|
|
36
37
|
this.logLevel = envLevel;
|
|
37
38
|
}
|
|
38
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Sets the event emitter that will receive log events.
|
|
42
|
+
* When set, all log operations will emit a "log-event" event.
|
|
43
|
+
*
|
|
44
|
+
* @param emitter - The event emitter instance
|
|
45
|
+
*/
|
|
46
|
+
setEventEmitter(emitter) {
|
|
47
|
+
this.eventEmitter = emitter;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Clears the event emitter reference.
|
|
51
|
+
* Should be called when a NeuroLink instance is disposed to prevent memory leaks.
|
|
52
|
+
*/
|
|
53
|
+
clearEventEmitter() {
|
|
54
|
+
this.eventEmitter = undefined;
|
|
55
|
+
}
|
|
39
56
|
/**
|
|
40
57
|
* Sets the minimum log level that will be processed and output.
|
|
41
58
|
* Log messages with a level lower than this will be ignored.
|
|
@@ -106,6 +123,7 @@ class NeuroLinkLogger {
|
|
|
106
123
|
* 2. Storing entries in the log history
|
|
107
124
|
* 3. Managing log rotation to prevent memory issues
|
|
108
125
|
* 4. Outputting formatted logs to the console
|
|
126
|
+
* 5. Emitting log events if an event emitter is configured
|
|
109
127
|
*
|
|
110
128
|
* This is the central method called by all specific logging methods (debug, info, etc.)
|
|
111
129
|
*
|
|
@@ -123,6 +141,20 @@ class NeuroLinkLogger {
|
|
|
123
141
|
timestamp: new Date(),
|
|
124
142
|
data,
|
|
125
143
|
};
|
|
144
|
+
// Emit log event if emitter is configured
|
|
145
|
+
if (this.eventEmitter) {
|
|
146
|
+
try {
|
|
147
|
+
this.eventEmitter.emit("log-event", {
|
|
148
|
+
level,
|
|
149
|
+
message,
|
|
150
|
+
timestamp: new Date().getTime(),
|
|
151
|
+
data,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
// Silently ignore emitter errors to avoid disrupting logging
|
|
156
|
+
}
|
|
157
|
+
}
|
|
126
158
|
// Store log entry
|
|
127
159
|
this.logs.push(entry);
|
|
128
160
|
// Trim old logs
|
|
@@ -277,6 +309,7 @@ function processLoggerArgs(args, logMethod) {
|
|
|
277
309
|
* - Unconditional logging (always, table)
|
|
278
310
|
* - Log level control and configuration
|
|
279
311
|
* - Log history management
|
|
312
|
+
* - Event emission for all log operations (when emitter is configured)
|
|
280
313
|
*/
|
|
281
314
|
export const logger = {
|
|
282
315
|
debug: (...args) => {
|
|
@@ -309,6 +342,8 @@ export const logger = {
|
|
|
309
342
|
setLogLevel: (level) => neuroLinkLogger.setLogLevel(level),
|
|
310
343
|
getLogs: (level) => neuroLinkLogger.getLogs(level),
|
|
311
344
|
clearLogs: () => neuroLinkLogger.clearLogs(),
|
|
345
|
+
setEventEmitter: (emitter) => neuroLinkLogger.setEventEmitter(emitter),
|
|
346
|
+
clearEventEmitter: () => neuroLinkLogger.clearEventEmitter(),
|
|
312
347
|
};
|
|
313
348
|
/**
|
|
314
349
|
* MCP compatibility exports - all use the same unified logger instance.
|
|
@@ -2,23 +2,7 @@
|
|
|
2
2
|
* Model Router for NeuroLink Orchestration
|
|
3
3
|
* Routes tasks to optimal models based on classification and requirements
|
|
4
4
|
*/
|
|
5
|
-
import type {
|
|
6
|
-
export type ModelRoute = {
|
|
7
|
-
provider: string;
|
|
8
|
-
model: string;
|
|
9
|
-
reasoning: string;
|
|
10
|
-
confidence: number;
|
|
11
|
-
};
|
|
12
|
-
export type ModelRoutingOptions = {
|
|
13
|
-
/** Override the task classification */
|
|
14
|
-
forceTaskType?: TaskType;
|
|
15
|
-
/** Require specific performance characteristics */
|
|
16
|
-
requireFast?: boolean;
|
|
17
|
-
/** Require specific capability (reasoning, creativity, etc.) */
|
|
18
|
-
requireCapability?: string;
|
|
19
|
-
/** Fallback strategy if primary choice fails */
|
|
20
|
-
fallbackStrategy?: "fast" | "reasoning" | "auto";
|
|
21
|
-
};
|
|
5
|
+
import type { ModelRoute, ModelRoutingOptions } from "../types/modelTypes.js";
|
|
22
6
|
/**
|
|
23
7
|
* Model configurations for different task types and providers
|
|
24
8
|
*/
|
|
@@ -17,11 +17,6 @@ export declare function convertGenerateToStreamOptions(generateOptions: Generate
|
|
|
17
17
|
* Useful for fallback scenarios and unified processing
|
|
18
18
|
*/
|
|
19
19
|
export declare function convertStreamToGenerateOptions(streamOptions: StreamOptions): GenerateOptions;
|
|
20
|
-
/**
|
|
21
|
-
* Create a unified options interface that works with both methods
|
|
22
|
-
* Useful for factory utilities that need to work with either type
|
|
23
|
-
*/
|
|
24
|
-
export type UnifiedOptions = GenerateOptions & StreamOptions;
|
|
25
20
|
/**
|
|
26
21
|
* Check if options object has factory configuration
|
|
27
22
|
* Useful for determining if enhanced processing is needed
|
|
@@ -5,60 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { GenerateOptions, UnifiedGenerationOptions } from "../types/generateTypes.js";
|
|
7
7
|
import type { StreamOptions } from "../types/streamTypes.js";
|
|
8
|
-
import type {
|
|
9
|
-
/**
|
|
10
|
-
* Enhancement types for different optimization strategies
|
|
11
|
-
*/
|
|
12
|
-
export type EnhancementType = "streaming-optimization" | "mcp-integration" | "legacy-migration" | "context-conversion" | "domain-configuration" | "batch-parallel-enhancement" | "batch-hybrid-enhancement" | "batch-dependency-enhancement";
|
|
13
|
-
/**
|
|
14
|
-
* Enhancement options for modifying GenerateOptions
|
|
15
|
-
*/
|
|
16
|
-
export interface EnhancementOptions {
|
|
17
|
-
enhancementType: EnhancementType;
|
|
18
|
-
streamingOptions?: {
|
|
19
|
-
enabled?: boolean;
|
|
20
|
-
chunkSize?: number;
|
|
21
|
-
bufferSize?: number;
|
|
22
|
-
enableProgress?: boolean;
|
|
23
|
-
preferStreaming?: boolean;
|
|
24
|
-
};
|
|
25
|
-
mcpOptions?: {
|
|
26
|
-
enableToolRegistry?: boolean;
|
|
27
|
-
contextAware?: boolean;
|
|
28
|
-
executionContext?: ExecutionContext;
|
|
29
|
-
};
|
|
30
|
-
legacyMigration?: {
|
|
31
|
-
legacyContext?: Record<string, unknown>;
|
|
32
|
-
domainType?: string;
|
|
33
|
-
preserveFields?: boolean;
|
|
34
|
-
};
|
|
35
|
-
domainConfiguration?: {
|
|
36
|
-
domainType: string;
|
|
37
|
-
keyTerms?: string[];
|
|
38
|
-
failurePatterns?: string[];
|
|
39
|
-
successPatterns?: string[];
|
|
40
|
-
evaluationCriteria?: Record<string, unknown>;
|
|
41
|
-
};
|
|
42
|
-
performance?: {
|
|
43
|
-
enableAnalytics?: boolean;
|
|
44
|
-
enableEvaluation?: boolean;
|
|
45
|
-
timeout?: number;
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Enhancement result with metadata
|
|
50
|
-
*/
|
|
51
|
-
export interface EnhancementResult {
|
|
52
|
-
options: UnifiedGenerationOptions;
|
|
53
|
-
metadata: {
|
|
54
|
-
enhancementApplied: boolean;
|
|
55
|
-
enhancementType: EnhancementType;
|
|
56
|
-
processingTime: number;
|
|
57
|
-
configurationUsed: Record<string, unknown>;
|
|
58
|
-
warnings: string[];
|
|
59
|
-
recommendations: string[];
|
|
60
|
-
};
|
|
61
|
-
}
|
|
8
|
+
import type { ConflictDetectionPlugin, EnhancementOptions, EnhancementResult, EnhancementType } from "../types/utilities.js";
|
|
62
9
|
/**
|
|
63
10
|
* Options Enhancement Utility Class
|
|
64
11
|
* Main utility for enhancing GenerateOptions with factory patterns
|
|
@@ -176,22 +123,6 @@ export declare function migrateLegacyContext(options: GenerateOptions, legacyCon
|
|
|
176
123
|
* Automatically detects independent enhancements for parallel processing
|
|
177
124
|
*/
|
|
178
125
|
export declare function batchEnhance(options: GenerateOptions, enhancements: EnhancementOptions[]): EnhancementResult;
|
|
179
|
-
/**
|
|
180
|
-
* Plugin-based conflict detection system
|
|
181
|
-
* Extensible and configurable enhancement conflict resolution
|
|
182
|
-
*/
|
|
183
|
-
export interface ConflictDetectionPlugin {
|
|
184
|
-
/** Plugin name for identification */
|
|
185
|
-
name: string;
|
|
186
|
-
/** Plugin version for compatibility checks */
|
|
187
|
-
version: string;
|
|
188
|
-
/** Check if two enhancement types conflict */
|
|
189
|
-
detectConflict(enhancementA: EnhancementType, enhancementB: EnhancementType, optionsA?: EnhancementOptions, optionsB?: EnhancementOptions): boolean;
|
|
190
|
-
/** Get conflict severity (low, medium, high) */
|
|
191
|
-
getConflictSeverity?(enhancementA: EnhancementType, enhancementB: EnhancementType): "low" | "medium" | "high";
|
|
192
|
-
/** Suggest resolution strategies */
|
|
193
|
-
suggestResolution?(enhancementA: EnhancementType, enhancementB: EnhancementType): string[];
|
|
194
|
-
}
|
|
195
126
|
/**
|
|
196
127
|
* Plugin registry for managing conflict detection plugins
|
|
197
128
|
*/
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Provides consistent parameter validation across all tool interfaces
|
|
4
4
|
*/
|
|
5
5
|
import type { ValidationSchema, StringArray } from "../types/typeAliases.js";
|
|
6
|
+
import type { EnhancedValidationResult } from "../types/tools.js";
|
|
6
7
|
/**
|
|
7
8
|
* Custom error class for parameter validation failures
|
|
8
9
|
* Provides detailed information about validation errors including field context and suggestions
|
|
@@ -20,20 +21,6 @@ export declare class ValidationError extends Error {
|
|
|
20
21
|
*/
|
|
21
22
|
constructor(message: string, field?: string | undefined, code?: string | undefined, suggestions?: StringArray | undefined);
|
|
22
23
|
}
|
|
23
|
-
/**
|
|
24
|
-
* Result of a validation operation
|
|
25
|
-
* Contains validation status, errors, warnings, and suggestions for improvement
|
|
26
|
-
*/
|
|
27
|
-
export interface ValidationResult {
|
|
28
|
-
/** Whether the validation passed without errors */
|
|
29
|
-
isValid: boolean;
|
|
30
|
-
/** Array of validation errors that must be fixed */
|
|
31
|
-
errors: ValidationError[];
|
|
32
|
-
/** Array of warning messages that should be addressed */
|
|
33
|
-
warnings: string[];
|
|
34
|
-
/** Array of suggestions to improve the validated object */
|
|
35
|
-
suggestions: StringArray;
|
|
36
|
-
}
|
|
37
24
|
/**
|
|
38
25
|
* Validate that a string parameter is present and non-empty
|
|
39
26
|
*/
|
|
@@ -61,23 +48,23 @@ export declare function validateToolDescription(description: unknown): Validatio
|
|
|
61
48
|
/**
|
|
62
49
|
* Validate MCP tool structure comprehensively
|
|
63
50
|
*/
|
|
64
|
-
export declare function validateMCPTool(tool: unknown):
|
|
51
|
+
export declare function validateMCPTool(tool: unknown): EnhancedValidationResult;
|
|
65
52
|
/**
|
|
66
53
|
* Validate text generation options
|
|
67
54
|
*/
|
|
68
|
-
export declare function validateTextGenerationOptions(options: unknown):
|
|
55
|
+
export declare function validateTextGenerationOptions(options: unknown): EnhancedValidationResult;
|
|
69
56
|
/**
|
|
70
57
|
* Validate stream options
|
|
71
58
|
*/
|
|
72
|
-
export declare function validateStreamOptions(options: unknown):
|
|
59
|
+
export declare function validateStreamOptions(options: unknown): EnhancedValidationResult;
|
|
73
60
|
/**
|
|
74
61
|
* Validate generate options (unified interface)
|
|
75
62
|
*/
|
|
76
|
-
export declare function validateGenerateOptions(options: unknown):
|
|
63
|
+
export declare function validateGenerateOptions(options: unknown): EnhancedValidationResult;
|
|
77
64
|
/**
|
|
78
65
|
* Validate tool execution parameters
|
|
79
66
|
*/
|
|
80
|
-
export declare function validateToolExecutionParams(toolName: string, params: unknown, expectedSchema?: ValidationSchema):
|
|
67
|
+
export declare function validateToolExecutionParams(toolName: string, params: unknown, expectedSchema?: ValidationSchema): EnhancedValidationResult;
|
|
81
68
|
/**
|
|
82
69
|
* Validate multiple tools at once
|
|
83
70
|
*/
|
|
@@ -85,13 +72,13 @@ export declare function validateToolBatch(tools: Record<string, unknown>): {
|
|
|
85
72
|
isValid: boolean;
|
|
86
73
|
validTools: string[];
|
|
87
74
|
invalidTools: string[];
|
|
88
|
-
results: Record<string,
|
|
75
|
+
results: Record<string, EnhancedValidationResult>;
|
|
89
76
|
};
|
|
90
77
|
/**
|
|
91
78
|
* Create a validation error summary for logging
|
|
92
79
|
*/
|
|
93
|
-
export declare function createValidationSummary(result:
|
|
80
|
+
export declare function createValidationSummary(result: EnhancedValidationResult): string;
|
|
94
81
|
/**
|
|
95
82
|
* Check if validation result has only warnings (no errors)
|
|
96
83
|
*/
|
|
97
|
-
export declare function hasOnlyWarnings(result:
|
|
84
|
+
export declare function hasOnlyWarnings(result: EnhancedValidationResult): boolean;
|
|
@@ -2,19 +2,7 @@
|
|
|
2
2
|
* Performance measurement and memory management utilities
|
|
3
3
|
* Part of Sub-phase 3.3.1-3.3.2 optimization efforts
|
|
4
4
|
*/
|
|
5
|
-
|
|
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
|
-
}
|
|
5
|
+
import type { PerformanceMetrics } from "../types/analytics.js";
|
|
18
6
|
/**
|
|
19
7
|
* Performance measurement utility for tracking operations
|
|
20
8
|
*/
|
|
@@ -2,14 +2,7 @@
|
|
|
2
2
|
* Prompt redaction utilities for safe logging
|
|
3
3
|
* Provides consistent prompt masking across NeuroLink components
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
/** Maximum length of redacted prompt */
|
|
7
|
-
maxLength?: number;
|
|
8
|
-
/** Whether to show word count */
|
|
9
|
-
showWordCount?: boolean;
|
|
10
|
-
/** Mask character to use for redaction */
|
|
11
|
-
maskChar?: string;
|
|
12
|
-
}
|
|
5
|
+
import type { PromptRedactionOptions } from "../types/utilities.js";
|
|
13
6
|
/**
|
|
14
7
|
* Redact a prompt for safe logging
|
|
15
8
|
* Truncates to maxLength and optionally shows word count
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { ProviderError } from "../types/
|
|
1
|
+
import type { ProviderError } from "../types/providers.js";
|
|
2
|
+
import type { EnvVarValidationResult } from "../types/utilities.js";
|
|
2
3
|
/**
|
|
3
4
|
* Get the best available provider based on real-time availability checks
|
|
4
5
|
* Enhanced version consolidated from providerUtils-fixed.ts
|
|
@@ -6,15 +7,6 @@ import type { ProviderError } from "../types/index.js";
|
|
|
6
7
|
* @returns The best provider name to use
|
|
7
8
|
*/
|
|
8
9
|
export declare function getBestProvider(requestedProvider?: string): Promise<string>;
|
|
9
|
-
/**
|
|
10
|
-
* Validation results for environment variables
|
|
11
|
-
*/
|
|
12
|
-
export interface EnvVarValidationResult {
|
|
13
|
-
isValid: boolean;
|
|
14
|
-
missingVars: string[];
|
|
15
|
-
invalidVars: string[];
|
|
16
|
-
warnings: string[];
|
|
17
|
-
}
|
|
18
10
|
/**
|
|
19
11
|
* Validate environment variable values for a provider
|
|
20
12
|
* Addresses GitHub Copilot comment about adding environment variable validation
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* Helper functions for Redis storage operations
|
|
4
4
|
*/
|
|
5
5
|
import { createClient } from "redis";
|
|
6
|
-
type RedisClient = ReturnType<typeof createClient>;
|
|
7
6
|
import type { RedisStorageConfig, RedisConversationObject } from "../types/conversation.js";
|
|
7
|
+
type RedisClient = ReturnType<typeof createClient>;
|
|
8
8
|
/**
|
|
9
9
|
* Creates a Redis client with the provided configuration
|
|
10
10
|
*/
|
package/dist/lib/utils/redis.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Retry and resilience utilities for NeuroLink
|
|
3
3
|
* Part of Sub-phase 3.3.3 - Edge Case Handling
|
|
4
4
|
*/
|
|
5
|
+
import type { RetryOptions } from "../types/utilities.js";
|
|
5
6
|
/**
|
|
6
7
|
* Calculate exponential backoff delay with jitter
|
|
7
8
|
* @param attempt - Current attempt number (1-based)
|
|
@@ -12,14 +13,6 @@
|
|
|
12
13
|
* @returns Calculated delay in milliseconds
|
|
13
14
|
*/
|
|
14
15
|
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
16
|
/**
|
|
24
17
|
* Error types that are typically retryable
|
|
25
18
|
*/
|
package/dist/neurolink.js
CHANGED
|
@@ -187,6 +187,7 @@ export class NeuroLink {
|
|
|
187
187
|
this.observabilityConfig = config?.observability;
|
|
188
188
|
// Initialize orchestration setting
|
|
189
189
|
this.enableOrchestration = config?.enableOrchestration ?? false;
|
|
190
|
+
logger.setEventEmitter(this.emitter);
|
|
190
191
|
// Read tool cache duration from environment variables, with a default
|
|
191
192
|
const cacheDurationEnv = process.env.NEUROLINK_TOOL_CACHE_DURATION;
|
|
192
193
|
this.toolCacheDuration = cacheDurationEnv
|
|
@@ -1945,36 +1946,11 @@ export class NeuroLink {
|
|
|
1945
1946
|
finally {
|
|
1946
1947
|
// Store memory after stream consumption is complete
|
|
1947
1948
|
if (self.conversationMemory && enhancedOptions.context?.sessionId) {
|
|
1948
|
-
const storageStartTime = Date.now();
|
|
1949
1949
|
const sessionId = enhancedOptions.context?.sessionId;
|
|
1950
1950
|
const userId = enhancedOptions.context
|
|
1951
1951
|
?.userId;
|
|
1952
1952
|
try {
|
|
1953
|
-
self.emitter.emit("log-event", {
|
|
1954
|
-
type: "log-event:storage:start",
|
|
1955
|
-
data: {
|
|
1956
|
-
operation: "storeConversationTurn",
|
|
1957
|
-
sessionId,
|
|
1958
|
-
userId,
|
|
1959
|
-
timestamp: storageStartTime,
|
|
1960
|
-
source: "stream-finally-block",
|
|
1961
|
-
userInputLength: originalPrompt?.length ?? 0,
|
|
1962
|
-
responseLength: accumulatedContent.length,
|
|
1963
|
-
},
|
|
1964
|
-
});
|
|
1965
1953
|
await self.conversationMemory.storeConversationTurn(sessionId, userId, originalPrompt ?? "", accumulatedContent, new Date(startTime));
|
|
1966
|
-
self.emitter.emit("log-event", {
|
|
1967
|
-
type: "log-event:storage:end",
|
|
1968
|
-
data: {
|
|
1969
|
-
operation: "storeConversationTurn",
|
|
1970
|
-
sessionId,
|
|
1971
|
-
userId,
|
|
1972
|
-
timestamp: Date.now(),
|
|
1973
|
-
duration: Date.now() - storageStartTime,
|
|
1974
|
-
source: "stream-finally-block",
|
|
1975
|
-
success: true,
|
|
1976
|
-
},
|
|
1977
|
-
});
|
|
1978
1954
|
logger.debug("Stream conversation turn stored", {
|
|
1979
1955
|
sessionId,
|
|
1980
1956
|
userInputLength: originalPrompt?.length ?? 0,
|
|
@@ -1982,18 +1958,6 @@ export class NeuroLink {
|
|
|
1982
1958
|
});
|
|
1983
1959
|
}
|
|
1984
1960
|
catch (error) {
|
|
1985
|
-
self.emitter.emit("log-event", {
|
|
1986
|
-
type: "log-event:storage:error",
|
|
1987
|
-
data: {
|
|
1988
|
-
operation: "storeConversationTurn",
|
|
1989
|
-
sessionId,
|
|
1990
|
-
userId,
|
|
1991
|
-
timestamp: Date.now(),
|
|
1992
|
-
duration: Date.now() - storageStartTime,
|
|
1993
|
-
source: "stream-finally-block",
|
|
1994
|
-
error: error instanceof Error ? error.message : String(error),
|
|
1995
|
-
},
|
|
1996
|
-
});
|
|
1997
1961
|
logger.warn("Failed to store stream conversation turn", {
|
|
1998
1962
|
error: error instanceof Error ? error.message : String(error),
|
|
1999
1963
|
});
|
|
@@ -2187,36 +2151,11 @@ export class NeuroLink {
|
|
|
2187
2151
|
finally {
|
|
2188
2152
|
// Store memory after fallback stream consumption is complete
|
|
2189
2153
|
if (self.conversationMemory && enhancedOptions?.context?.sessionId) {
|
|
2190
|
-
const storageStartTime = Date.now();
|
|
2191
2154
|
const sessionId = enhancedOptions?.context?.sessionId;
|
|
2192
2155
|
const userId = enhancedOptions?.context
|
|
2193
2156
|
?.userId;
|
|
2194
2157
|
try {
|
|
2195
|
-
self.emitter.emit("log", {
|
|
2196
|
-
type: "log-event:storage:start",
|
|
2197
|
-
data: {
|
|
2198
|
-
operation: "storeConversationTurn",
|
|
2199
|
-
sessionId,
|
|
2200
|
-
userId,
|
|
2201
|
-
timestamp: storageStartTime,
|
|
2202
|
-
source: "fallback-stream-finally-block",
|
|
2203
|
-
userInputLength: originalPrompt?.length ?? 0,
|
|
2204
|
-
responseLength: fallbackAccumulatedContent.length,
|
|
2205
|
-
},
|
|
2206
|
-
});
|
|
2207
2158
|
await self.conversationMemory.storeConversationTurn(sessionId || options.context?.sessionId, userId || options.context?.userId, originalPrompt ?? "", fallbackAccumulatedContent, new Date(startTime));
|
|
2208
|
-
self.emitter.emit("log", {
|
|
2209
|
-
type: "log-event:storage:end",
|
|
2210
|
-
data: {
|
|
2211
|
-
operation: "storeConversationTurn",
|
|
2212
|
-
sessionId,
|
|
2213
|
-
userId,
|
|
2214
|
-
timestamp: Date.now(),
|
|
2215
|
-
duration: Date.now() - storageStartTime,
|
|
2216
|
-
source: "fallback-stream-finally-block",
|
|
2217
|
-
success: true,
|
|
2218
|
-
},
|
|
2219
|
-
});
|
|
2220
2159
|
logger.debug("Fallback stream conversation turn stored", {
|
|
2221
2160
|
sessionId: sessionId || options.context?.sessionId,
|
|
2222
2161
|
userInputLength: originalPrompt?.length ?? 0,
|
|
@@ -2224,18 +2163,6 @@ export class NeuroLink {
|
|
|
2224
2163
|
});
|
|
2225
2164
|
}
|
|
2226
2165
|
catch (error) {
|
|
2227
|
-
self.emitter.emit("log-event", {
|
|
2228
|
-
type: "log-event:storage:error",
|
|
2229
|
-
data: {
|
|
2230
|
-
operation: "storeConversationTurn",
|
|
2231
|
-
sessionId,
|
|
2232
|
-
userId,
|
|
2233
|
-
timestamp: Date.now(),
|
|
2234
|
-
duration: Date.now() - storageStartTime,
|
|
2235
|
-
source: "fallback-stream-finally-block",
|
|
2236
|
-
error: error instanceof Error ? error.message : String(error),
|
|
2237
|
-
},
|
|
2238
|
-
});
|
|
2239
2166
|
logger.warn("Failed to store fallback stream conversation turn", {
|
|
2240
2167
|
error: error instanceof Error ? error.message : String(error),
|
|
2241
2168
|
});
|
|
@@ -4254,6 +4181,7 @@ export class NeuroLink {
|
|
|
4254
4181
|
try {
|
|
4255
4182
|
logger.debug("[NeuroLink] Removing all event listeners...");
|
|
4256
4183
|
this.emitter.removeAllListeners();
|
|
4184
|
+
logger.clearEventEmitter();
|
|
4257
4185
|
logger.debug("[NeuroLink] Event listeners removed successfully");
|
|
4258
4186
|
}
|
|
4259
4187
|
catch (error) {
|