@juspay/neurolink 7.51.1 → 7.51.3

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.
Files changed (48) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/core/baseProvider.js +5 -1
  3. package/dist/core/conversationMemoryFactory.d.ts +1 -4
  4. package/dist/core/redisConversationMemoryManager.d.ts +4 -0
  5. package/dist/core/redisConversationMemoryManager.js +4 -0
  6. package/dist/lib/core/baseProvider.js +5 -1
  7. package/dist/lib/core/conversationMemoryFactory.d.ts +1 -4
  8. package/dist/lib/core/redisConversationMemoryManager.d.ts +4 -0
  9. package/dist/lib/core/redisConversationMemoryManager.js +4 -0
  10. package/dist/lib/neurolink.d.ts +2 -1
  11. package/dist/lib/types/common.d.ts +18 -61
  12. package/dist/lib/types/content.d.ts +21 -10
  13. package/dist/lib/types/contextTypes.d.ts +11 -11
  14. package/dist/lib/types/conversation.d.ts +27 -27
  15. package/dist/lib/types/domainTypes.d.ts +12 -12
  16. package/dist/lib/types/evaluationTypes.d.ts +12 -12
  17. package/dist/lib/types/externalMcp.d.ts +20 -20
  18. package/dist/lib/types/guardrails.d.ts +18 -18
  19. package/dist/lib/types/middlewareTypes.d.ts +86 -23
  20. package/dist/lib/types/providers.d.ts +72 -61
  21. package/dist/lib/types/providers.js +3 -0
  22. package/dist/lib/types/sdkTypes.d.ts +2 -2
  23. package/dist/lib/types/streamTypes.d.ts +8 -8
  24. package/dist/lib/types/tools.d.ts +79 -1
  25. package/dist/lib/types/utilities.d.ts +29 -0
  26. package/dist/lib/types/utilities.js +5 -0
  27. package/dist/lib/utils/providerConfig.d.ts +3 -22
  28. package/dist/lib/utils/timeout.d.ts +1 -16
  29. package/dist/neurolink.d.ts +2 -1
  30. package/dist/types/common.d.ts +18 -61
  31. package/dist/types/content.d.ts +21 -10
  32. package/dist/types/contextTypes.d.ts +11 -11
  33. package/dist/types/conversation.d.ts +27 -27
  34. package/dist/types/domainTypes.d.ts +12 -12
  35. package/dist/types/evaluationTypes.d.ts +12 -12
  36. package/dist/types/externalMcp.d.ts +20 -20
  37. package/dist/types/guardrails.d.ts +18 -18
  38. package/dist/types/middlewareTypes.d.ts +86 -23
  39. package/dist/types/providers.d.ts +72 -61
  40. package/dist/types/providers.js +3 -0
  41. package/dist/types/sdkTypes.d.ts +2 -2
  42. package/dist/types/streamTypes.d.ts +8 -8
  43. package/dist/types/tools.d.ts +79 -1
  44. package/dist/types/utilities.d.ts +29 -0
  45. package/dist/types/utilities.js +4 -0
  46. package/dist/utils/providerConfig.d.ts +3 -22
  47. package/dist/utils/timeout.d.ts +1 -16
  48. package/package.json +1 -1
@@ -6,19 +6,19 @@ import type { ToolExecution } from "./tools.js";
6
6
  * Represents the analysis of the user's query intent.
7
7
  * This provides a basic understanding of what the user is trying to achieve.
8
8
  */
9
- export interface QueryIntentAnalysis {
9
+ export type QueryIntentAnalysis = {
10
10
  /** The type of query, e.g., asking a question or giving a command. */
11
11
  type: "question" | "command" | "greeting" | "unknown";
12
12
  /** The estimated complexity of the query. */
13
13
  complexity: "low" | "medium" | "high";
14
14
  /** Whether the query likely required the use of tools to be answered correctly. */
15
15
  shouldHaveUsedTools: boolean;
16
- }
16
+ };
17
17
  /**
18
18
  * Represents a single turn in an enhanced conversation history,
19
19
  * including tool executions and evaluations for richer context.
20
20
  */
21
- export interface EnhancedConversationTurn {
21
+ export type EnhancedConversationTurn = {
22
22
  /** The role of the speaker, either 'user' or 'assistant'. */
23
23
  role: "user" | "assistant";
24
24
  /** The content of the message. */
@@ -29,12 +29,12 @@ export interface EnhancedConversationTurn {
29
29
  toolExecutions?: ToolExecution[];
30
30
  /** The evaluation result for this turn, if applicable. */
31
31
  evaluation?: EvaluationResult;
32
- }
32
+ };
33
33
  /**
34
34
  * Contains all the rich context needed for a thorough, RAGAS-style evaluation.
35
35
  * This object is constructed by the `ContextBuilder` and used by the `RAGASEvaluator`.
36
36
  */
37
- export interface EnhancedEvaluationContext {
37
+ export type EnhancedEvaluationContext = {
38
38
  /** The original user query. */
39
39
  userQuery: string;
40
40
  /** An analysis of the user's query intent. */
@@ -63,11 +63,11 @@ export interface EnhancedEvaluationContext {
63
63
  previousEvaluations?: EvaluationResult[];
64
64
  /** The current attempt number for this evaluation (1-based). */
65
65
  attemptNumber: number;
66
- }
66
+ };
67
67
  /**
68
68
  * Represents the result of a single evaluation attempt, based on RAGAS principles.
69
69
  */
70
- export interface EvaluationResult {
70
+ export type EvaluationResult = {
71
71
  /** The final, overall score for the response, typically from 1 to 10. */
72
72
  finalScore: number;
73
73
  /** How well the response addresses the user's query. */
@@ -90,11 +90,11 @@ export interface EvaluationResult {
90
90
  evaluationTime: number;
91
91
  /** The attempt number for this evaluation. */
92
92
  attemptNumber: number;
93
- }
93
+ };
94
94
  /**
95
95
  * Provides detailed information when a response fails quality assurance checks.
96
96
  */
97
- export interface QualityErrorDetails {
97
+ export type QualityErrorDetails = {
98
98
  /** The history of all evaluation attempts for this response. */
99
99
  evaluationHistory: EvaluationResult[];
100
100
  /** The final score of the last attempt. */
@@ -103,11 +103,11 @@ export interface QualityErrorDetails {
103
103
  attempts: number;
104
104
  /** A summary message of the failure. */
105
105
  message: string;
106
- }
106
+ };
107
107
  /**
108
108
  * Configuration for the main `Evaluator` class.
109
109
  */
110
- export interface EvaluationConfig {
110
+ export type EvaluationConfig = {
111
111
  /** The minimum score (1-10) for a response to be considered passing. */
112
112
  threshold?: number;
113
113
  /** The evaluation strategy to use. Currently only 'ragas' is supported. */
@@ -129,7 +129,7 @@ export interface EvaluationConfig {
129
129
  highSeverityThreshold?: number;
130
130
  /** An optional function to generate custom evaluation prompts. */
131
131
  promptGenerator?: GetPromptFunction;
132
- }
132
+ };
133
133
  /**
134
134
  * A function that generates the main body of an evaluation prompt.
135
135
  */
@@ -14,7 +14,7 @@ export type MCPTransportType = "stdio" | "sse" | "websocket";
14
14
  /**
15
15
  * External MCP server configuration for process spawning
16
16
  */
17
- export interface ExternalMCPServerConfig {
17
+ export type ExternalMCPServerConfig = {
18
18
  /** Unique identifier for the server */
19
19
  id: string;
20
20
  /** Command to execute (e.g., 'npx', 'node', 'python') */
@@ -39,11 +39,11 @@ export interface ExternalMCPServerConfig {
39
39
  url?: string;
40
40
  /** Additional metadata */
41
41
  metadata?: Record<string, JsonValue>;
42
- }
42
+ };
43
43
  /**
44
44
  * Runtime state of an external MCP server instance
45
45
  */
46
- export interface ExternalMCPServerInstance {
46
+ export type ExternalMCPServerInstance = {
47
47
  /** Server configuration */
48
48
  config: ExternalMCPServerConfig;
49
49
  /** Child process (for stdio transport) */
@@ -87,7 +87,7 @@ export interface ExternalMCPServerInstance {
87
87
  averageResponseTime: number;
88
88
  lastResponseTime: number;
89
89
  };
90
- }
90
+ };
91
91
  /**
92
92
  * External MCP server status states
93
93
  */
@@ -95,7 +95,7 @@ export type ExternalMCPServerStatus = "initializing" | "connecting" | "connected
95
95
  /**
96
96
  * Tool information from external MCP server
97
97
  */
98
- export interface ExternalMCPToolInfo {
98
+ export type ExternalMCPToolInfo = {
99
99
  /** Tool name */
100
100
  name: string;
101
101
  /** Tool description */
@@ -118,11 +118,11 @@ export interface ExternalMCPToolInfo {
118
118
  averageExecutionTime: number;
119
119
  lastExecutionTime: number;
120
120
  };
121
- }
121
+ };
122
122
  /**
123
123
  * External MCP server health status
124
124
  */
125
- export interface ExternalMCPServerHealth {
125
+ export type ExternalMCPServerHealth = {
126
126
  /** Server ID */
127
127
  serverId: string;
128
128
  /** Whether the server is healthy */
@@ -144,11 +144,11 @@ export interface ExternalMCPServerHealth {
144
144
  cpuUsage?: number;
145
145
  averageResponseTime: number;
146
146
  };
147
- }
147
+ };
148
148
  /**
149
149
  * External MCP server configuration validation result
150
150
  */
151
- export interface ExternalMCPConfigValidation {
151
+ export type ExternalMCPConfigValidation = {
152
152
  /** Whether the configuration is valid */
153
153
  isValid: boolean;
154
154
  /** Validation errors */
@@ -157,11 +157,11 @@ export interface ExternalMCPConfigValidation {
157
157
  warnings: string[];
158
158
  /** Suggestions for improvement */
159
159
  suggestions: string[];
160
- }
160
+ };
161
161
  /**
162
162
  * External MCP server operation result
163
163
  */
164
- export interface ExternalMCPOperationResult<T = unknown> {
164
+ export type ExternalMCPOperationResult<T = unknown> = {
165
165
  /** Whether the operation was successful */
166
166
  success: boolean;
167
167
  /** Result data if successful */
@@ -178,11 +178,11 @@ export interface ExternalMCPOperationResult<T = unknown> {
178
178
  operation: string;
179
179
  [key: string]: JsonValue;
180
180
  };
181
- }
181
+ };
182
182
  /**
183
183
  * External MCP tool execution context
184
184
  */
185
- export interface ExternalMCPToolContext {
185
+ export type ExternalMCPToolContext = {
186
186
  /** Execution session ID */
187
187
  sessionId: string;
188
188
  /** User ID if available */
@@ -195,11 +195,11 @@ export interface ExternalMCPToolContext {
195
195
  timeout?: number;
196
196
  /** Additional context data */
197
197
  metadata?: Record<string, JsonValue>;
198
- }
198
+ };
199
199
  /**
200
200
  * External MCP tool execution result
201
201
  */
202
- export interface ExternalMCPToolResult {
202
+ export type ExternalMCPToolResult = {
203
203
  /** Whether the execution was successful */
204
204
  success: boolean;
205
205
  /** Result data if successful */
@@ -215,11 +215,11 @@ export interface ExternalMCPToolResult {
215
215
  timestamp: number;
216
216
  [key: string]: JsonValue;
217
217
  };
218
- }
218
+ };
219
219
  /**
220
220
  * External MCP server events
221
221
  */
222
- export interface ExternalMCPServerEvents {
222
+ export type ExternalMCPServerEvents = {
223
223
  /** Server status changed */
224
224
  statusChanged: {
225
225
  serverId: string;
@@ -264,11 +264,11 @@ export interface ExternalMCPServerEvents {
264
264
  health: ExternalMCPServerHealth;
265
265
  timestamp: Date;
266
266
  };
267
- }
267
+ };
268
268
  /**
269
269
  * External MCP manager configuration
270
270
  */
271
- export interface ExternalMCPManagerConfig {
271
+ export type ExternalMCPManagerConfig = {
272
272
  /** Maximum number of concurrent servers */
273
273
  maxServers?: number;
274
274
  /** Default timeout for operations */
@@ -285,4 +285,4 @@ export interface ExternalMCPManagerConfig {
285
285
  enablePerformanceMonitoring?: boolean;
286
286
  /** Log level for external MCP operations */
287
287
  logLevel?: "debug" | "info" | "warn" | "error";
288
- }
288
+ };
@@ -2,7 +2,7 @@ import type { LanguageModelV1 } from "ai";
2
2
  /**
3
3
  * Result from precall evaluation of user input
4
4
  */
5
- export interface PrecallEvaluationResult {
5
+ export type PrecallEvaluationResult = {
6
6
  overall: "safe" | "unsafe" | "suspicious" | "inappropriate";
7
7
  safetyScore: number;
8
8
  appropriatenessScore: number;
@@ -14,25 +14,25 @@ export interface PrecallEvaluationResult {
14
14
  }[];
15
15
  suggestedAction: "allow" | "block" | "sanitize" | "warn";
16
16
  reasoning?: string;
17
- }
17
+ };
18
18
  export type IssueCategory = "explicit_content" | "hate_speech" | "violence" | "personal_info" | "spam" | "other";
19
19
  export type IssueSeverity = "low" | "medium" | "high" | "critical";
20
20
  export type EvaluationAction = "allow" | "block" | "sanitize" | "warn";
21
21
  export type SafetyStatus = "safe" | "unsafe" | "suspicious" | "inappropriate";
22
- export interface EvaluationActions {
22
+ export type EvaluationActions = {
23
23
  onUnsafe?: "block" | "sanitize" | "warn" | "log";
24
24
  onInappropriate?: "block" | "sanitize" | "warn" | "log";
25
25
  onSuspicious?: "warn" | "log" | "allow";
26
- }
27
- export interface EvaluationThresholds {
26
+ };
27
+ export type EvaluationThresholds = {
28
28
  safetyScore?: number;
29
29
  appropriatenessScore?: number;
30
30
  confidenceLevel?: number;
31
- }
31
+ };
32
32
  /**
33
33
  * Configuration for precall evaluation using AI models
34
34
  */
35
- export interface PrecallEvaluationConfig {
35
+ export type PrecallEvaluationConfig = {
36
36
  enabled?: boolean;
37
37
  provider?: string;
38
38
  evaluationModel?: string;
@@ -63,8 +63,8 @@ export interface PrecallEvaluationConfig {
63
63
  * - '[FILTERED]'
64
64
  */
65
65
  replacementText?: string;
66
- }
67
- export interface BadWordsConfig {
66
+ };
67
+ export type BadWordsConfig = {
68
68
  enabled?: boolean;
69
69
  list?: string[];
70
70
  regexPatterns?: string[];
@@ -79,25 +79,25 @@ export interface BadWordsConfig {
79
79
  * - '[FILTERED]'
80
80
  */
81
81
  replacementText?: string;
82
- }
83
- export interface ModelFilterConfig {
82
+ };
83
+ export type ModelFilterConfig = {
84
84
  enabled?: boolean;
85
85
  filterModel?: LanguageModelV1;
86
- }
86
+ };
87
87
  /**
88
88
  * Configuration for the Guardrails middleware
89
89
  */
90
- export interface GuardrailsMiddlewareConfig {
90
+ export type GuardrailsMiddlewareConfig = {
91
91
  badWords?: BadWordsConfig;
92
92
  modelFilter?: ModelFilterConfig;
93
93
  precallEvaluation?: PrecallEvaluationConfig;
94
- }
95
- export interface EvaluationActionResult {
94
+ };
95
+ export type EvaluationActionResult = {
96
96
  shouldBlock: boolean;
97
97
  sanitizedInput?: string;
98
- }
99
- export interface EvaluationIssue {
98
+ };
99
+ export type EvaluationIssue = {
100
100
  category: IssueCategory;
101
101
  severity: IssueSeverity;
102
102
  description: string;
103
- }
103
+ };
@@ -3,10 +3,10 @@ import type { JsonValue } from "../types/common.js";
3
3
  import type { EvaluationData } from "./evaluation.js";
4
4
  import type { GetPromptFunction } from "./evaluationTypes.js";
5
5
  /**
6
- * Metadata interface for NeuroLink middleware
6
+ * Metadata type for NeuroLink middleware
7
7
  * Provides additional information about middleware without affecting execution
8
8
  */
9
- export interface NeuroLinkMiddlewareMetadata {
9
+ export type NeuroLinkMiddlewareMetadata = {
10
10
  /** Unique identifier for the middleware */
11
11
  id: string;
12
12
  /** Human-readable name */
@@ -19,30 +19,30 @@ export interface NeuroLinkMiddlewareMetadata {
19
19
  defaultEnabled?: boolean;
20
20
  /** Configuration schema for the middleware */
21
21
  configSchema?: Record<string, unknown>;
22
- }
22
+ };
23
23
  /**
24
24
  * NeuroLink middleware with metadata
25
25
  * Combines standard AI SDK middleware with NeuroLink-specific metadata
26
26
  */
27
- export interface NeuroLinkMiddleware extends LanguageModelV1Middleware {
27
+ export type NeuroLinkMiddleware = LanguageModelV1Middleware & {
28
28
  /** Middleware metadata */
29
29
  readonly metadata: NeuroLinkMiddlewareMetadata;
30
- }
30
+ };
31
31
  /**
32
32
  * Middleware configuration options
33
33
  */
34
- export interface MiddlewareConfig {
34
+ export type MiddlewareConfig = {
35
35
  /** Whether the middleware is enabled */
36
36
  enabled?: boolean;
37
37
  /** Middleware-specific configuration */
38
38
  config?: Record<string, unknown>;
39
39
  /** Conditions under which to apply this middleware */
40
40
  conditions?: MiddlewareConditions;
41
- }
41
+ };
42
42
  /**
43
43
  * Conditions for applying middleware
44
44
  */
45
- export interface MiddlewareConditions {
45
+ export type MiddlewareConditions = {
46
46
  /** Apply only to specific providers */
47
47
  providers?: string[];
48
48
  /** Apply only to specific models */
@@ -51,11 +51,11 @@ export interface MiddlewareConditions {
51
51
  options?: Record<string, unknown>;
52
52
  /** Custom condition function */
53
53
  custom?: (context: MiddlewareContext) => boolean;
54
- }
54
+ };
55
55
  /**
56
56
  * Context passed to middleware for decision making
57
57
  */
58
- export interface MiddlewareContext {
58
+ export type MiddlewareContext = {
59
59
  /** Provider name */
60
60
  provider: string;
61
61
  /** Model name */
@@ -69,22 +69,22 @@ export interface MiddlewareContext {
69
69
  };
70
70
  /** Additional metadata */
71
71
  metadata?: Record<string, JsonValue>;
72
- }
72
+ };
73
73
  /**
74
74
  * Middleware registration options
75
75
  */
76
- export interface MiddlewareRegistrationOptions {
76
+ export type MiddlewareRegistrationOptions = {
77
77
  /** Whether to replace existing middleware with same ID */
78
78
  replace?: boolean;
79
79
  /** Whether to enable the middleware by default */
80
80
  defaultEnabled?: boolean;
81
81
  /** Global configuration for the middleware */
82
82
  globalConfig?: Record<string, JsonValue>;
83
- }
83
+ };
84
84
  /**
85
85
  * Middleware execution result
86
86
  */
87
- export interface MiddlewareExecutionResult {
87
+ export type MiddlewareExecutionResult = {
88
88
  /** Whether the middleware was applied */
89
89
  applied: boolean;
90
90
  /** Execution time in milliseconds */
@@ -93,11 +93,11 @@ export interface MiddlewareExecutionResult {
93
93
  error?: Error;
94
94
  /** Additional metadata from the middleware */
95
95
  metadata?: Record<string, JsonValue>;
96
- }
96
+ };
97
97
  /**
98
98
  * Middleware chain execution statistics
99
99
  */
100
- export interface MiddlewareChainStats {
100
+ export type MiddlewareChainStats = {
101
101
  /** Total number of middleware in the chain */
102
102
  totalMiddleware: number;
103
103
  /** Number of middleware that were applied */
@@ -106,7 +106,7 @@ export interface MiddlewareChainStats {
106
106
  totalExecutionTime: number;
107
107
  /** Individual middleware execution results */
108
108
  results: Record<string, MiddlewareExecutionResult>;
109
- }
109
+ };
110
110
  /**
111
111
  * Built-in middleware types
112
112
  */
@@ -114,18 +114,18 @@ export type BuiltInMiddlewareType = "analytics" | "guardrails" | "logging" | "ca
114
114
  /**
115
115
  * Middleware preset configurations
116
116
  */
117
- export interface MiddlewarePreset {
117
+ export type MiddlewarePreset = {
118
118
  /** Preset name */
119
119
  name: string;
120
120
  /** Description of the preset */
121
121
  description: string;
122
122
  /** Middleware configurations in the preset */
123
123
  config: Record<string, MiddlewareConfig>;
124
- }
124
+ };
125
125
  /**
126
126
  * Factory options for middleware
127
127
  */
128
- export interface MiddlewareFactoryOptions {
128
+ export type MiddlewareFactoryOptions = {
129
129
  /** Custom middleware to register on initialization */
130
130
  middleware?: NeuroLinkMiddleware[];
131
131
  /** Enable specific middleware */
@@ -145,11 +145,11 @@ export interface MiddlewareFactoryOptions {
145
145
  /** Whether to collect execution statistics */
146
146
  collectStats?: boolean;
147
147
  };
148
- }
148
+ };
149
149
  /**
150
150
  * Configuration for the Auto-Evaluation Middleware.
151
151
  */
152
- export interface AutoEvaluationConfig {
152
+ export type AutoEvaluationConfig = {
153
153
  /** The minimum score (1-10) for a response to be considered passing. */
154
154
  threshold?: number;
155
155
  /** The maximum number of retry attempts before failing. */
@@ -169,4 +169,67 @@ export interface AutoEvaluationConfig {
169
169
  highSeverityThreshold?: number;
170
170
  promptGenerator?: GetPromptFunction;
171
171
  provider?: string;
172
- }
172
+ };
173
+ /**
174
+ * Middleware factory configuration options
175
+ */
176
+ export type MiddlewareFactoryConfig = {
177
+ enabled: boolean;
178
+ type: string;
179
+ priority?: number;
180
+ config?: Record<string, unknown>;
181
+ };
182
+ /**
183
+ * Middleware registry entry
184
+ */
185
+ export type MiddlewareRegistryEntry = {
186
+ name: string;
187
+ factory: MiddlewareFactory;
188
+ defaultConfig: Record<string, unknown>;
189
+ description?: string;
190
+ version?: string;
191
+ };
192
+ /**
193
+ * Middleware factory function type
194
+ */
195
+ export type MiddlewareFactory = (config: Record<string, unknown>) => LanguageModelV1Middleware;
196
+ /**
197
+ * Middleware validation result
198
+ */
199
+ export type MiddlewareValidationResult = {
200
+ valid: boolean;
201
+ errors: string[];
202
+ warnings: string[];
203
+ };
204
+ /**
205
+ * Middleware execution context
206
+ */
207
+ export type MiddlewareExecutionContext = {
208
+ requestId: string;
209
+ timestamp: number;
210
+ provider: string;
211
+ model: string;
212
+ userId?: string;
213
+ sessionId?: string;
214
+ metadata?: Record<string, unknown>;
215
+ };
216
+ /**
217
+ * Middleware performance metrics
218
+ */
219
+ export type MiddlewareMetrics = {
220
+ name: string;
221
+ executionTime: number;
222
+ status: "success" | "error" | "skipped";
223
+ error?: string;
224
+ inputSize: number;
225
+ outputSize: number;
226
+ };
227
+ /**
228
+ * Middleware chain configuration
229
+ */
230
+ export type MiddlewareChainConfig = {
231
+ middlewares: MiddlewareFactoryConfig[];
232
+ errorHandling: "continue" | "stop" | "rollback";
233
+ timeout?: number;
234
+ retries?: number;
235
+ };