@juspay/neurolink 7.29.1 → 7.29.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 (234) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cli/commands/config.d.ts +86 -86
  3. package/dist/cli/commands/mcp.js +64 -9
  4. package/dist/cli/commands/models.js +25 -21
  5. package/dist/cli/commands/ollama.js +2 -2
  6. package/dist/cli/factories/commandFactory.d.ts +9 -0
  7. package/dist/cli/factories/commandFactory.js +177 -83
  8. package/dist/cli/factories/ollamaCommandFactory.js +3 -1
  9. package/dist/cli/factories/sagemakerCommandFactory.js +3 -2
  10. package/dist/cli/index.d.ts +1 -1
  11. package/dist/cli/index.js +19 -11
  12. package/dist/cli/utils/envManager.js +5 -5
  13. package/dist/cli/utils/ollamaUtils.d.ts +12 -0
  14. package/dist/cli/utils/ollamaUtils.js +58 -42
  15. package/dist/config/configManager.js +5 -2
  16. package/dist/core/analytics.d.ts +2 -24
  17. package/dist/core/analytics.js +12 -17
  18. package/dist/core/baseProvider.d.ts +30 -1
  19. package/dist/core/baseProvider.js +180 -198
  20. package/dist/core/dynamicModels.d.ts +4 -4
  21. package/dist/core/dynamicModels.js +7 -7
  22. package/dist/core/evaluation.d.ts +9 -9
  23. package/dist/core/evaluation.js +117 -65
  24. package/dist/core/evaluationProviders.d.ts +18 -2
  25. package/dist/core/evaluationProviders.js +15 -13
  26. package/dist/core/factory.js +77 -4
  27. package/dist/core/modelConfiguration.d.ts +63 -0
  28. package/dist/core/modelConfiguration.js +354 -290
  29. package/dist/core/streamAnalytics.d.ts +10 -5
  30. package/dist/core/streamAnalytics.js +10 -10
  31. package/dist/core/types.d.ts +19 -109
  32. package/dist/core/types.js +13 -0
  33. package/dist/factories/providerFactory.js +4 -1
  34. package/dist/factories/providerRegistry.js +2 -2
  35. package/dist/index.d.ts +2 -1
  36. package/dist/lib/config/configManager.js +5 -2
  37. package/dist/lib/core/analytics.d.ts +2 -24
  38. package/dist/lib/core/analytics.js +12 -17
  39. package/dist/lib/core/baseProvider.d.ts +30 -1
  40. package/dist/lib/core/baseProvider.js +180 -198
  41. package/dist/lib/core/dynamicModels.js +7 -7
  42. package/dist/lib/core/evaluation.d.ts +9 -9
  43. package/dist/lib/core/evaluation.js +117 -65
  44. package/dist/lib/core/evaluationProviders.d.ts +18 -2
  45. package/dist/lib/core/evaluationProviders.js +15 -13
  46. package/dist/lib/core/factory.js +77 -4
  47. package/dist/lib/core/modelConfiguration.d.ts +63 -0
  48. package/dist/lib/core/modelConfiguration.js +354 -290
  49. package/dist/lib/core/streamAnalytics.d.ts +10 -5
  50. package/dist/lib/core/streamAnalytics.js +10 -10
  51. package/dist/lib/core/types.d.ts +19 -109
  52. package/dist/lib/core/types.js +13 -0
  53. package/dist/lib/factories/providerFactory.js +4 -1
  54. package/dist/lib/factories/providerRegistry.js +2 -2
  55. package/dist/lib/index.d.ts +2 -1
  56. package/dist/lib/mcp/externalServerManager.js +14 -6
  57. package/dist/lib/mcp/factory.js +1 -1
  58. package/dist/lib/mcp/flexibleToolValidator.d.ts +50 -0
  59. package/dist/lib/mcp/flexibleToolValidator.js +161 -0
  60. package/dist/lib/mcp/index.d.ts +1 -1
  61. package/dist/lib/mcp/index.js +1 -1
  62. package/dist/lib/mcp/mcpCircuitBreaker.js +5 -1
  63. package/dist/lib/mcp/mcpClientFactory.js +3 -0
  64. package/dist/lib/mcp/registry.d.ts +3 -3
  65. package/dist/lib/mcp/registry.js +3 -3
  66. package/dist/lib/mcp/servers/aiProviders/aiAnalysisTools.js +5 -5
  67. package/dist/lib/mcp/servers/aiProviders/aiWorkflowTools.js +6 -6
  68. package/dist/lib/mcp/servers/utilities/utilityServer.js +1 -1
  69. package/dist/lib/mcp/toolDiscoveryService.js +8 -2
  70. package/dist/lib/mcp/toolRegistry.d.ts +2 -2
  71. package/dist/lib/mcp/toolRegistry.js +29 -54
  72. package/dist/lib/middleware/builtin/analytics.js +4 -4
  73. package/dist/lib/middleware/builtin/guardrails.js +2 -2
  74. package/dist/lib/middleware/registry.js +11 -2
  75. package/dist/lib/models/modelRegistry.d.ts +1 -1
  76. package/dist/lib/models/modelRegistry.js +3 -3
  77. package/dist/lib/models/modelResolver.d.ts +1 -1
  78. package/dist/lib/models/modelResolver.js +2 -2
  79. package/dist/lib/neurolink.d.ts +118 -0
  80. package/dist/lib/neurolink.js +814 -952
  81. package/dist/lib/providers/amazonBedrock.d.ts +47 -6
  82. package/dist/lib/providers/amazonBedrock.js +282 -23
  83. package/dist/lib/providers/amazonSagemaker.d.ts +1 -1
  84. package/dist/lib/providers/amazonSagemaker.js +12 -3
  85. package/dist/lib/providers/anthropic.d.ts +1 -1
  86. package/dist/lib/providers/anthropic.js +7 -6
  87. package/dist/lib/providers/anthropicBaseProvider.d.ts +1 -1
  88. package/dist/lib/providers/anthropicBaseProvider.js +4 -3
  89. package/dist/lib/providers/aws/credentialProvider.d.ts +58 -0
  90. package/dist/lib/providers/aws/credentialProvider.js +267 -0
  91. package/dist/lib/providers/aws/credentialTester.d.ts +49 -0
  92. package/dist/lib/providers/aws/credentialTester.js +394 -0
  93. package/dist/lib/providers/azureOpenai.d.ts +1 -1
  94. package/dist/lib/providers/azureOpenai.js +1 -1
  95. package/dist/lib/providers/googleAiStudio.d.ts +1 -1
  96. package/dist/lib/providers/googleAiStudio.js +2 -2
  97. package/dist/lib/providers/googleVertex.d.ts +40 -0
  98. package/dist/lib/providers/googleVertex.js +330 -274
  99. package/dist/lib/providers/huggingFace.js +1 -1
  100. package/dist/lib/providers/mistral.d.ts +1 -1
  101. package/dist/lib/providers/mistral.js +2 -2
  102. package/dist/lib/providers/ollama.d.ts +4 -0
  103. package/dist/lib/providers/ollama.js +38 -18
  104. package/dist/lib/providers/openAI.d.ts +1 -1
  105. package/dist/lib/providers/openAI.js +2 -2
  106. package/dist/lib/providers/sagemaker/adaptive-semaphore.js +7 -4
  107. package/dist/lib/providers/sagemaker/client.js +13 -3
  108. package/dist/lib/providers/sagemaker/config.js +5 -1
  109. package/dist/lib/providers/sagemaker/detection.js +19 -9
  110. package/dist/lib/providers/sagemaker/errors.d.ts +8 -1
  111. package/dist/lib/providers/sagemaker/errors.js +103 -20
  112. package/dist/lib/providers/sagemaker/language-model.d.ts +3 -3
  113. package/dist/lib/providers/sagemaker/language-model.js +4 -4
  114. package/dist/lib/providers/sagemaker/parsers.js +14 -6
  115. package/dist/lib/providers/sagemaker/streaming.js +14 -3
  116. package/dist/lib/providers/sagemaker/types.d.ts +1 -1
  117. package/dist/lib/proxy/awsProxyIntegration.d.ts +23 -0
  118. package/dist/lib/proxy/awsProxyIntegration.js +285 -0
  119. package/dist/lib/proxy/proxyFetch.d.ts +9 -5
  120. package/dist/lib/proxy/proxyFetch.js +232 -98
  121. package/dist/lib/proxy/utils/noProxyUtils.d.ts +39 -0
  122. package/dist/lib/proxy/utils/noProxyUtils.js +149 -0
  123. package/dist/lib/sdk/toolRegistration.d.ts +1 -1
  124. package/dist/lib/types/cli.d.ts +80 -8
  125. package/dist/lib/types/contextTypes.js +2 -2
  126. package/dist/lib/types/generateTypes.d.ts +4 -6
  127. package/dist/lib/types/providers.d.ts +124 -19
  128. package/dist/lib/types/providers.js +6 -6
  129. package/dist/lib/types/streamTypes.d.ts +4 -6
  130. package/dist/lib/types/typeAliases.d.ts +1 -1
  131. package/dist/lib/utils/analyticsUtils.d.ts +33 -0
  132. package/dist/lib/utils/analyticsUtils.js +76 -0
  133. package/dist/lib/utils/errorHandling.js +4 -1
  134. package/dist/lib/utils/evaluationUtils.d.ts +27 -0
  135. package/dist/lib/utils/evaluationUtils.js +131 -0
  136. package/dist/lib/utils/optionsUtils.js +10 -1
  137. package/dist/lib/utils/performance.d.ts +1 -1
  138. package/dist/lib/utils/performance.js +15 -3
  139. package/dist/lib/utils/providerConfig.d.ts +1 -0
  140. package/dist/lib/utils/providerConfig.js +2 -1
  141. package/dist/lib/utils/providerHealth.d.ts +48 -0
  142. package/dist/lib/utils/providerHealth.js +221 -158
  143. package/dist/lib/utils/providerUtils.js +2 -2
  144. package/dist/lib/utils/timeout.js +8 -3
  145. package/dist/mcp/externalServerManager.js +14 -6
  146. package/dist/mcp/factory.js +1 -1
  147. package/dist/mcp/flexibleToolValidator.d.ts +50 -0
  148. package/dist/mcp/flexibleToolValidator.js +161 -0
  149. package/dist/mcp/index.d.ts +1 -1
  150. package/dist/mcp/index.js +1 -1
  151. package/dist/mcp/mcpCircuitBreaker.js +5 -1
  152. package/dist/mcp/mcpClientFactory.js +3 -0
  153. package/dist/mcp/registry.d.ts +3 -3
  154. package/dist/mcp/registry.js +3 -3
  155. package/dist/mcp/servers/aiProviders/aiAnalysisTools.js +5 -5
  156. package/dist/mcp/servers/aiProviders/aiWorkflowTools.js +6 -6
  157. package/dist/mcp/servers/utilities/utilityServer.js +1 -1
  158. package/dist/mcp/toolDiscoveryService.js +8 -2
  159. package/dist/mcp/toolRegistry.d.ts +2 -2
  160. package/dist/mcp/toolRegistry.js +29 -54
  161. package/dist/middleware/builtin/analytics.js +4 -4
  162. package/dist/middleware/builtin/guardrails.js +2 -2
  163. package/dist/middleware/registry.js +11 -2
  164. package/dist/models/modelRegistry.d.ts +1 -1
  165. package/dist/models/modelRegistry.js +3 -3
  166. package/dist/models/modelResolver.d.ts +1 -1
  167. package/dist/models/modelResolver.js +2 -2
  168. package/dist/neurolink.d.ts +118 -0
  169. package/dist/neurolink.js +814 -952
  170. package/dist/providers/amazonBedrock.d.ts +47 -6
  171. package/dist/providers/amazonBedrock.js +282 -23
  172. package/dist/providers/amazonSagemaker.d.ts +1 -1
  173. package/dist/providers/amazonSagemaker.js +12 -3
  174. package/dist/providers/anthropic.d.ts +1 -1
  175. package/dist/providers/anthropic.js +7 -6
  176. package/dist/providers/anthropicBaseProvider.d.ts +1 -1
  177. package/dist/providers/anthropicBaseProvider.js +4 -3
  178. package/dist/providers/aws/credentialProvider.d.ts +58 -0
  179. package/dist/providers/aws/credentialProvider.js +267 -0
  180. package/dist/providers/aws/credentialTester.d.ts +49 -0
  181. package/dist/providers/aws/credentialTester.js +394 -0
  182. package/dist/providers/azureOpenai.d.ts +1 -1
  183. package/dist/providers/azureOpenai.js +1 -1
  184. package/dist/providers/googleAiStudio.d.ts +1 -1
  185. package/dist/providers/googleAiStudio.js +2 -2
  186. package/dist/providers/googleVertex.d.ts +40 -0
  187. package/dist/providers/googleVertex.js +330 -274
  188. package/dist/providers/huggingFace.js +1 -1
  189. package/dist/providers/mistral.d.ts +1 -1
  190. package/dist/providers/mistral.js +2 -2
  191. package/dist/providers/ollama.d.ts +4 -0
  192. package/dist/providers/ollama.js +38 -18
  193. package/dist/providers/openAI.d.ts +1 -1
  194. package/dist/providers/openAI.js +2 -2
  195. package/dist/providers/sagemaker/adaptive-semaphore.js +7 -4
  196. package/dist/providers/sagemaker/client.js +13 -3
  197. package/dist/providers/sagemaker/config.js +5 -1
  198. package/dist/providers/sagemaker/detection.js +19 -9
  199. package/dist/providers/sagemaker/errors.d.ts +8 -1
  200. package/dist/providers/sagemaker/errors.js +103 -20
  201. package/dist/providers/sagemaker/language-model.d.ts +3 -3
  202. package/dist/providers/sagemaker/language-model.js +4 -4
  203. package/dist/providers/sagemaker/parsers.js +14 -6
  204. package/dist/providers/sagemaker/streaming.js +14 -3
  205. package/dist/providers/sagemaker/types.d.ts +1 -1
  206. package/dist/proxy/awsProxyIntegration.d.ts +23 -0
  207. package/dist/proxy/awsProxyIntegration.js +285 -0
  208. package/dist/proxy/proxyFetch.d.ts +9 -5
  209. package/dist/proxy/proxyFetch.js +232 -98
  210. package/dist/proxy/utils/noProxyUtils.d.ts +39 -0
  211. package/dist/proxy/utils/noProxyUtils.js +149 -0
  212. package/dist/sdk/toolRegistration.d.ts +1 -1
  213. package/dist/types/cli.d.ts +80 -8
  214. package/dist/types/contextTypes.js +2 -2
  215. package/dist/types/generateTypes.d.ts +4 -6
  216. package/dist/types/providers.d.ts +124 -19
  217. package/dist/types/providers.js +6 -6
  218. package/dist/types/streamTypes.d.ts +4 -6
  219. package/dist/types/typeAliases.d.ts +1 -1
  220. package/dist/utils/analyticsUtils.d.ts +33 -0
  221. package/dist/utils/analyticsUtils.js +76 -0
  222. package/dist/utils/errorHandling.js +4 -1
  223. package/dist/utils/evaluationUtils.d.ts +27 -0
  224. package/dist/utils/evaluationUtils.js +131 -0
  225. package/dist/utils/optionsUtils.js +10 -1
  226. package/dist/utils/performance.d.ts +1 -1
  227. package/dist/utils/performance.js +15 -3
  228. package/dist/utils/providerConfig.d.ts +1 -0
  229. package/dist/utils/providerConfig.js +2 -1
  230. package/dist/utils/providerHealth.d.ts +48 -0
  231. package/dist/utils/providerHealth.js +221 -158
  232. package/dist/utils/providerUtils.js +2 -2
  233. package/dist/utils/timeout.js +8 -3
  234. package/package.json +5 -1
@@ -2,7 +2,8 @@
2
2
  * CLI-specific type definitions for NeuroLink
3
3
  */
4
4
  import type { UnknownRecord, JsonValue } from "./common.js";
5
- import type { AnalyticsData, EvaluationData, TokenUsage } from "./providers.js";
5
+ import type { AnalyticsData, TokenUsage } from "./providers.js";
6
+ import type { EvaluationData } from "../index.js";
6
7
  import type { ToolCall, ToolResult } from "./tools.js";
7
8
  /**
8
9
  * Base command arguments interface
@@ -16,6 +17,8 @@ export interface BaseCommandArgs {
16
17
  verbose?: boolean;
17
18
  /** Quiet mode */
18
19
  quiet?: boolean;
20
+ /** Index signature to allow additional properties */
21
+ [key: string]: unknown;
19
22
  }
20
23
  /**
21
24
  * Generate command arguments
@@ -65,6 +68,29 @@ export interface StreamCommandArgs extends BaseCommandArgs {
65
68
  /** Disable tools */
66
69
  disableTools?: boolean;
67
70
  }
71
+ /**
72
+ * Batch command arguments
73
+ */
74
+ export interface BatchCommandArgs extends BaseCommandArgs {
75
+ /** Input file path */
76
+ file?: string;
77
+ /** AI provider to use */
78
+ provider?: string;
79
+ /** Model name */
80
+ model?: string;
81
+ /** System prompt */
82
+ system?: string;
83
+ /** Temperature setting */
84
+ temperature?: number;
85
+ /** Maximum tokens */
86
+ maxTokens?: number;
87
+ /** Delay between requests (ms) */
88
+ delay?: number;
89
+ /** Output file */
90
+ output?: string;
91
+ /** Disable tools */
92
+ disableTools?: boolean;
93
+ }
68
94
  /**
69
95
  * MCP command arguments - Enhanced with transport and server management
70
96
  */
@@ -113,17 +139,65 @@ export interface MCPCommandArgs extends BaseCommandArgs {
113
139
  /**
114
140
  * Models command arguments - Enhanced for model management
115
141
  */
116
- export interface ModelsCommandArgs extends BaseCommandArgs {
117
- /** AI provider to query */
118
- provider?: string;
119
- /** Model capability filter */
142
+ export interface ModelsCommandArgs extends Omit<BaseCommandArgs, "format"> {
143
+ /** AI provider to query (single or array) */
144
+ provider?: string | string[];
145
+ /** Model category filter */
146
+ category?: string;
147
+ /** Model capability filter (array) */
148
+ capability?: string[];
149
+ /** Include deprecated models */
150
+ deprecated?: boolean;
151
+ /** Search query (capability, use case, or model name) */
120
152
  query?: string;
121
153
  /** Model use case filter */
122
154
  useCase?: string;
123
- /** Require vision capability */
155
+ /** Maximum cost per 1K tokens (USD) */
156
+ maxCost?: number;
157
+ /** Minimum context window size (tokens) */
158
+ minContext?: number;
159
+ /** Maximum context window size (tokens) */
160
+ maxContext?: number;
161
+ /** Required performance level */
162
+ performance?: "fast" | "medium" | "slow" | "high" | "low";
163
+ /** Optimize for code generation and programming */
164
+ coding?: boolean;
165
+ /** Optimize for creative writing and content */
166
+ creative?: boolean;
167
+ /** Optimize for data analysis and research */
168
+ analysis?: boolean;
169
+ /** Optimize for conversational interactions */
170
+ conversation?: boolean;
171
+ /** Optimize for logical reasoning tasks */
172
+ reasoning?: boolean;
173
+ /** Optimize for language translation */
174
+ translation?: boolean;
175
+ /** Optimize for text summarization */
176
+ summarization?: boolean;
177
+ /** Prioritize cost-effectiveness */
178
+ costEffective?: boolean;
179
+ /** Prioritize output quality over cost */
180
+ highQuality?: boolean;
181
+ /** Prioritize response speed */
182
+ fast?: boolean;
183
+ /** Require vision/image processing capability */
124
184
  requireVision?: boolean;
125
185
  /** Require function calling capability */
126
186
  requireFunctionCalling?: boolean;
187
+ /** Exclude specific providers */
188
+ excludeProviders?: string[];
189
+ /** Prefer local/offline models */
190
+ preferLocal?: boolean;
191
+ /** Model name, alias, or partial match to resolve */
192
+ model?: string;
193
+ /** Enable fuzzy matching for partial names */
194
+ fuzzy?: boolean;
195
+ /** Model IDs or aliases to compare */
196
+ models?: string[];
197
+ /** Show detailed statistics breakdown */
198
+ detailed?: boolean;
199
+ /** Output format for models command */
200
+ format?: "table" | "json" | "compact";
127
201
  /** List all available models */
128
202
  list?: boolean;
129
203
  /** Show model statistics */
@@ -132,8 +206,6 @@ export interface ModelsCommandArgs extends BaseCommandArgs {
132
206
  pricing?: boolean;
133
207
  /** Resolve best model for criteria */
134
208
  resolve?: boolean;
135
- /** Maximum cost filter */
136
- maxCost?: number;
137
209
  /** Maximum tokens filter */
138
210
  maxTokens?: number;
139
211
  }
@@ -284,7 +284,7 @@ export class ContextFactory {
284
284
  /**
285
285
  * Type guard to check if value is valid context
286
286
  */
287
- function isValidContext(value) {
287
+ function _isValidContext(value) {
288
288
  return ContextFactory.validateContext(value) !== null;
289
289
  }
290
290
  export class ContextConverter {
@@ -293,7 +293,7 @@ export class ContextConverter {
293
293
  * Based on business context patterns
294
294
  */
295
295
  static convertBusinessContext(legacyContext, domainType, options = {}) {
296
- const { preserveLegacyFields = false, validateDomainData = true, includeMetadata = true, } = options;
296
+ const { preserveLegacyFields = false, validateDomainData: _validateDomainData = true, includeMetadata = true, } = options;
297
297
  return {
298
298
  sessionId: legacyContext.sessionId,
299
299
  userId: legacyContext.userId,
@@ -1,6 +1,8 @@
1
1
  import type { Tool } from "ai";
2
2
  import type { ValidationSchema, StandardRecord } from "./typeAliases.js";
3
- import type { AIProviderName, AnalyticsData, EvaluationData } from "../core/types.js";
3
+ import type { AIProviderName, AnalyticsData } from "../core/types.js";
4
+ import type { EvaluationData } from "../index.js";
5
+ import type { TokenUsage } from "./providers.js";
4
6
  /**
5
7
  * Generate function options interface - Primary method for content generation
6
8
  * Future-ready for multi-modal capabilities while maintaining text focus
@@ -56,11 +58,7 @@ export interface GenerateResult {
56
58
  };
57
59
  provider?: string;
58
60
  model?: string;
59
- usage?: {
60
- inputTokens: number;
61
- outputTokens: number;
62
- totalTokens: number;
63
- };
61
+ usage?: TokenUsage;
64
62
  responseTime?: number;
65
63
  toolCalls?: Array<{
66
64
  toolCallId: string;
@@ -21,25 +21,64 @@ export interface ProviderError extends Error {
21
21
  * Token usage information
22
22
  */
23
23
  export interface TokenUsage {
24
- inputTokens: number;
25
- outputTokens: number;
26
- totalTokens: number;
24
+ input: number;
25
+ output: number;
26
+ total: number;
27
27
  }
28
28
  /**
29
29
  * Analytics data structure
30
30
  */
31
31
  export interface AnalyticsData {
32
32
  provider: string;
33
- model: string;
33
+ model?: string;
34
+ tokenUsage: TokenUsage;
34
35
  requestDuration: number;
35
- tokenUsage: {
36
- inputTokens: number;
37
- outputTokens: number;
38
- totalTokens: number;
39
- };
40
- timestamp: number;
36
+ timestamp: string;
37
+ cost?: number;
41
38
  context?: JsonValue;
42
- [key: string]: JsonValue | undefined;
39
+ }
40
+ /**
41
+ * AWS Credential Configuration for Bedrock provider
42
+ */
43
+ export interface AWSCredentialConfig {
44
+ region?: string;
45
+ profile?: string;
46
+ roleArn?: string;
47
+ roleSessionName?: string;
48
+ timeout?: number;
49
+ /** @deprecated Prefer maxAttempts to match AWS SDK v3 config */
50
+ maxRetries?: number;
51
+ /** Number of attempts as per AWS SDK v3 ("retry-mode") */
52
+ maxAttempts?: number;
53
+ enableDebugLogging?: boolean;
54
+ /** Optional service endpoint override (e.g., VPC/Gov endpoints) */
55
+ endpoint?: string;
56
+ }
57
+ /**
58
+ * AWS Credential Validation Result
59
+ */
60
+ export interface CredentialValidationResult {
61
+ isValid: boolean;
62
+ credentialSource: string;
63
+ region: string;
64
+ hasExpiration: boolean;
65
+ expirationTime?: Date;
66
+ error?: string;
67
+ debugInfo: {
68
+ accessKeyId: string;
69
+ hasSessionToken: boolean;
70
+ providerConfig: Readonly<Required<AWSCredentialConfig>>;
71
+ };
72
+ }
73
+ /**
74
+ * Service Connectivity Test Result
75
+ */
76
+ export interface ServiceConnectivityResult {
77
+ bedrockAccessible: boolean;
78
+ availableModels: number;
79
+ responseTimeMs: number;
80
+ error?: string;
81
+ sampleModels: string[];
43
82
  }
44
83
  /**
45
84
  * Model Capabilities - Maximally Reusable
@@ -123,16 +162,82 @@ export interface ModelPricing {
123
162
  free?: boolean;
124
163
  }
125
164
  /**
126
- * Evaluation data structure
165
+ * Response quality evaluation scores - Comprehensive evaluation interface
127
166
  */
128
167
  export interface EvaluationData {
129
- relevance?: number;
130
- accuracy?: number;
131
- completeness?: number;
132
- coherence?: number;
133
- overall?: number;
134
- feedback?: string;
135
- [key: string]: JsonValue | undefined;
168
+ relevance: number;
169
+ accuracy: number;
170
+ completeness: number;
171
+ overall: number;
172
+ domainAlignment?: number;
173
+ terminologyAccuracy?: number;
174
+ toolEffectiveness?: number;
175
+ isOffTopic: boolean;
176
+ alertSeverity: "low" | "medium" | "high" | "none";
177
+ reasoning: string;
178
+ suggestedImprovements?: string;
179
+ evaluationModel: string;
180
+ evaluationTime: number;
181
+ evaluationDomain?: string;
182
+ evaluationProvider?: string;
183
+ evaluationAttempt?: number;
184
+ evaluationConfig?: {
185
+ mode: string;
186
+ fallbackUsed: boolean;
187
+ costEstimate: number;
188
+ };
189
+ domainConfig?: {
190
+ domainName: string;
191
+ domainDescription: string;
192
+ keyTerms: string[];
193
+ failurePatterns: string[];
194
+ successPatterns: string[];
195
+ evaluationCriteria?: Record<string, unknown>;
196
+ };
197
+ domainEvaluation?: {
198
+ domainRelevance: number;
199
+ terminologyAccuracy: number;
200
+ domainExpertise: number;
201
+ domainSpecificInsights: string[];
202
+ };
203
+ }
204
+ /**
205
+ * Enhanced evaluation context for comprehensive response assessment
206
+ */
207
+ export interface EvaluationContext {
208
+ userQuery: string;
209
+ aiResponse: string;
210
+ context?: Record<string, unknown>;
211
+ primaryDomain?: string;
212
+ assistantRole?: string;
213
+ conversationHistory?: Array<{
214
+ role: "user" | "assistant";
215
+ content: string;
216
+ timestamp?: string;
217
+ }>;
218
+ toolUsage?: Array<{
219
+ toolName: string;
220
+ input: unknown;
221
+ output: unknown;
222
+ executionTime: number;
223
+ }>;
224
+ expectedOutcome?: string;
225
+ evaluationCriteria?: string[];
226
+ }
227
+ /**
228
+ * Evaluation result interface that extends EvaluationData with additional context
229
+ */
230
+ export interface EvaluationResult extends EvaluationData {
231
+ contextUtilization?: {
232
+ conversationUsed: boolean;
233
+ toolsUsed: boolean;
234
+ domainKnowledgeUsed: boolean;
235
+ };
236
+ evaluationContext?: {
237
+ domain: string;
238
+ toolsEvaluated: string[];
239
+ conversationTurns: number;
240
+ };
136
241
  }
137
242
  /**
138
243
  * Provider capabilities
@@ -13,10 +13,10 @@ export function isProviderError(error) {
13
13
  export function isTokenUsage(value) {
14
14
  return (typeof value === "object" &&
15
15
  value !== null &&
16
- "inputTokens" in value &&
17
- "outputTokens" in value &&
18
- "totalTokens" in value &&
19
- typeof value.inputTokens === "number" &&
20
- typeof value.outputTokens === "number" &&
21
- typeof value.totalTokens === "number");
16
+ "input" in value &&
17
+ "output" in value &&
18
+ "total" in value &&
19
+ typeof value.input === "number" &&
20
+ typeof value.output === "number" &&
21
+ typeof value.total === "number");
22
22
  }
@@ -1,6 +1,8 @@
1
1
  import type { Tool } from "ai";
2
2
  import type { ValidationSchema, StandardRecord } from "./typeAliases.js";
3
- import type { AIProviderName, AnalyticsData, EvaluationData } from "../core/types.js";
3
+ import type { AIProviderName, AnalyticsData } from "../core/types.js";
4
+ import type { EvaluationData } from "../index.js";
5
+ import type { TokenUsage } from "./providers.js";
4
6
  import type { UnknownRecord, JsonValue } from "./common.js";
5
7
  import type { ChatMessage } from "./conversationTypes.js";
6
8
  /**
@@ -120,11 +122,7 @@ export interface StreamResult {
120
122
  }>;
121
123
  provider?: string;
122
124
  model?: string;
123
- usage?: {
124
- inputTokens?: number;
125
- outputTokens?: number;
126
- totalTokens?: number;
127
- };
125
+ usage?: TokenUsage;
128
126
  finishReason?: string;
129
127
  toolCalls?: ToolCall[];
130
128
  toolResults?: ToolResult[];
@@ -382,7 +382,7 @@ export type NetworkTransportResult = {
382
382
  * Re-export commonly used types from other modules
383
383
  * Provides one-stop shop for type imports
384
384
  */
385
- export type { JsonValue, JsonObject, UnknownRecord } from "./common.js";
385
+ export type { JsonValue, JsonObject } from "./common.js";
386
386
  /**
387
387
  * Type guard for checking if value is a StandardRecord
388
388
  *
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Analytics utility functions for TokenUsage and AnalyticsData
3
+ * Provides helper functions to avoid manual field access patterns
4
+ */
5
+ import type { TokenUsage, AnalyticsData } from "../types/providers.js";
6
+ /**
7
+ * Format token usage as a human-readable string
8
+ */
9
+ export declare function formatTokenUsage(usage: TokenUsage): string;
10
+ /**
11
+ * Calculate cost based on token usage and cost per token
12
+ */
13
+ export declare function calculateTokenCost(usage: TokenUsage, costPerToken: number): number;
14
+ /**
15
+ * Combine multiple token usage objects into a single total
16
+ */
17
+ export declare function combineTokenUsage(usages: TokenUsage[]): TokenUsage;
18
+ /**
19
+ * Format analytics data for display
20
+ */
21
+ export declare function formatAnalyticsForDisplay(analytics: AnalyticsData): string;
22
+ /**
23
+ * Check if analytics data contains valid token usage
24
+ */
25
+ export declare function hasValidTokenUsage(analytics: AnalyticsData): boolean;
26
+ /**
27
+ * Extract summary metrics from analytics data
28
+ */
29
+ export declare function getAnalyticsSummary(analytics: AnalyticsData): {
30
+ totalTokens: number;
31
+ costPerToken: number | null;
32
+ requestsPerSecond: number;
33
+ };
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Analytics utility functions for TokenUsage and AnalyticsData
3
+ * Provides helper functions to avoid manual field access patterns
4
+ */
5
+ /**
6
+ * Format token usage as a human-readable string
7
+ */
8
+ export function formatTokenUsage(usage) {
9
+ return `${usage.input}/${usage.output}/${usage.total}`;
10
+ }
11
+ /**
12
+ * Calculate cost based on token usage and cost per token
13
+ */
14
+ export function calculateTokenCost(usage, costPerToken) {
15
+ return usage.total * costPerToken;
16
+ }
17
+ /**
18
+ * Combine multiple token usage objects into a single total
19
+ */
20
+ export function combineTokenUsage(usages) {
21
+ return usages.reduce((total, current) => ({
22
+ input: total.input + current.input,
23
+ output: total.output + current.output,
24
+ total: total.total + current.total,
25
+ }), { input: 0, output: 0, total: 0 });
26
+ }
27
+ /**
28
+ * Format analytics data for display
29
+ */
30
+ export function formatAnalyticsForDisplay(analytics) {
31
+ const parts = [];
32
+ // Provider and model
33
+ parts.push(`Provider: ${analytics.provider}`);
34
+ if (analytics.model) {
35
+ parts.push(`Model: ${analytics.model}`);
36
+ }
37
+ // Token usage
38
+ parts.push(`Tokens: ${formatTokenUsage(analytics.tokenUsage)}`);
39
+ // Cost
40
+ if (analytics.cost !== undefined) {
41
+ parts.push(`Cost: $${analytics.cost.toFixed(5)}`);
42
+ }
43
+ // Duration
44
+ const timeInSeconds = (analytics.requestDuration / 1000).toFixed(1);
45
+ parts.push(`Time: ${timeInSeconds}s`);
46
+ return parts.join(" | ");
47
+ }
48
+ /**
49
+ * Check if analytics data contains valid token usage
50
+ */
51
+ export function hasValidTokenUsage(analytics) {
52
+ return !!(analytics.tokenUsage &&
53
+ typeof analytics.tokenUsage.input === "number" &&
54
+ typeof analytics.tokenUsage.output === "number" &&
55
+ typeof analytics.tokenUsage.total === "number");
56
+ }
57
+ /**
58
+ * Extract summary metrics from analytics data
59
+ */
60
+ export function getAnalyticsSummary(analytics) {
61
+ const totalTokens = analytics.tokenUsage.total;
62
+ let costPerToken = null;
63
+ if (analytics.cost !== null &&
64
+ analytics.cost !== undefined &&
65
+ Number.isFinite(analytics.cost) &&
66
+ totalTokens > 0) {
67
+ const computed = analytics.cost / (totalTokens / 1000);
68
+ costPerToken = Number.isFinite(computed) ? computed : null;
69
+ }
70
+ const requestsPerSecond = analytics.requestDuration > 0 ? 1000 / analytics.requestDuration : 0;
71
+ return {
72
+ totalTokens,
73
+ costPerToken,
74
+ requestsPerSecond,
75
+ };
76
+ }
@@ -218,7 +218,10 @@ export async function withRetry(operation, options) {
218
218
  await new Promise((resolve) => setTimeout(resolve, delayMs));
219
219
  }
220
220
  }
221
- throw lastError;
221
+ if (lastError) {
222
+ throw lastError;
223
+ }
224
+ throw new Error("Retry operation failed with no error information");
222
225
  }
223
226
  /**
224
227
  * Circuit breaker for preventing cascading failures
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Evaluation utilities for normalizing EvaluationData objects
3
+ * Provides helper functions to handle partial evaluation data and ensure
4
+ * complete EvaluationData objects with safe defaults
5
+ */
6
+ import type { EvaluationData } from "../types/providers.js";
7
+ /**
8
+ * Normalize partial EvaluationData into a complete EvaluationData object
9
+ * with safe defaults for missing required fields
10
+ */
11
+ export declare function normalizeEvaluationData(partial: Partial<EvaluationData>): EvaluationData;
12
+ /**
13
+ * Create a default EvaluationData object for cases where no evaluation was performed
14
+ */
15
+ export declare function createDefaultEvaluationData(overrides?: Partial<EvaluationData>): EvaluationData;
16
+ /**
17
+ * Check if EvaluationData indicates a successful evaluation
18
+ */
19
+ export declare function isValidEvaluation(evaluation: EvaluationData): boolean;
20
+ /**
21
+ * Create EvaluationData for a failed evaluation attempt
22
+ */
23
+ export declare function createFailedEvaluationData(error: string, overrides?: Partial<EvaluationData>): EvaluationData;
24
+ /**
25
+ * Merge multiple partial evaluation data objects into a normalized result
26
+ */
27
+ export declare function mergeEvaluationData(...partials: Partial<EvaluationData>[]): EvaluationData;
@@ -0,0 +1,131 @@
1
+ /**
2
+ * Evaluation utilities for normalizing EvaluationData objects
3
+ * Provides helper functions to handle partial evaluation data and ensure
4
+ * complete EvaluationData objects with safe defaults
5
+ */
6
+ /**
7
+ * Default values for required EvaluationData fields
8
+ */
9
+ const DEFAULT_EVALUATION_DATA = {
10
+ // Core scores (1-10 scale)
11
+ relevance: 0,
12
+ accuracy: 0,
13
+ completeness: 0,
14
+ overall: 0,
15
+ // Advanced insights
16
+ isOffTopic: false,
17
+ alertSeverity: "none",
18
+ reasoning: "",
19
+ // Metadata
20
+ evaluationModel: "unknown",
21
+ evaluationTime: 0,
22
+ // Enhanced metadata defaults
23
+ evaluationProvider: "unknown",
24
+ evaluationAttempt: 0,
25
+ evaluationConfig: {
26
+ mode: "default",
27
+ fallbackUsed: false,
28
+ costEstimate: 0,
29
+ },
30
+ };
31
+ /**
32
+ * Normalize partial EvaluationData into a complete EvaluationData object
33
+ * with safe defaults for missing required fields
34
+ */
35
+ export function normalizeEvaluationData(partial) {
36
+ const normalized = {
37
+ ...DEFAULT_EVALUATION_DATA,
38
+ ...partial,
39
+ };
40
+ // Ensure scores are within valid range (0-10)
41
+ normalized.relevance = Math.max(0, Math.min(10, normalized.relevance));
42
+ normalized.accuracy = Math.max(0, Math.min(10, normalized.accuracy));
43
+ normalized.completeness = Math.max(0, Math.min(10, normalized.completeness));
44
+ normalized.overall = Math.max(0, Math.min(10, normalized.overall));
45
+ // Optional scores
46
+ if (normalized.domainAlignment !== undefined) {
47
+ normalized.domainAlignment = Math.max(0, Math.min(10, normalized.domainAlignment));
48
+ }
49
+ if (normalized.terminologyAccuracy !== undefined) {
50
+ normalized.terminologyAccuracy = Math.max(0, Math.min(10, normalized.terminologyAccuracy));
51
+ }
52
+ if (normalized.toolEffectiveness !== undefined) {
53
+ normalized.toolEffectiveness = Math.max(0, Math.min(10, normalized.toolEffectiveness));
54
+ }
55
+ // Validate alertSeverity enum
56
+ const validSeverities = ["low", "medium", "high", "none"];
57
+ if (!validSeverities.includes(normalized.alertSeverity)) {
58
+ normalized.alertSeverity = "none";
59
+ }
60
+ // Truncate reasoning and suggestedImprovements to enforce length constraints
61
+ normalized.reasoning = truncateString(normalized.reasoning, 150);
62
+ if (normalized.suggestedImprovements) {
63
+ normalized.suggestedImprovements = truncateString(normalized.suggestedImprovements, 100);
64
+ }
65
+ // Ensure evaluationTime is non-negative
66
+ normalized.evaluationTime = Math.max(0, normalized.evaluationTime);
67
+ // Ensure evaluationAttempt is positive
68
+ if (normalized.evaluationAttempt !== undefined) {
69
+ normalized.evaluationAttempt = Math.max(0, normalized.evaluationAttempt);
70
+ }
71
+ // Ensure evaluationConfig has required fields
72
+ if (normalized.evaluationConfig) {
73
+ normalized.evaluationConfig = {
74
+ mode: normalized.evaluationConfig.mode || "default",
75
+ fallbackUsed: Boolean(normalized.evaluationConfig.fallbackUsed),
76
+ costEstimate: Math.max(0, normalized.evaluationConfig.costEstimate || 0),
77
+ };
78
+ }
79
+ return normalized;
80
+ }
81
+ /**
82
+ * Create a default EvaluationData object for cases where no evaluation was performed
83
+ */
84
+ export function createDefaultEvaluationData(overrides = {}) {
85
+ return normalizeEvaluationData({
86
+ ...overrides,
87
+ reasoning: overrides.reasoning || "No evaluation performed",
88
+ evaluationModel: overrides.evaluationModel || "none",
89
+ });
90
+ }
91
+ /**
92
+ * Check if EvaluationData indicates a successful evaluation
93
+ */
94
+ export function isValidEvaluation(evaluation) {
95
+ return (evaluation.evaluationModel !== "unknown" &&
96
+ evaluation.evaluationModel !== "none" &&
97
+ evaluation.reasoning.length > 0 &&
98
+ evaluation.overall > 0);
99
+ }
100
+ /**
101
+ * Create EvaluationData for a failed evaluation attempt
102
+ */
103
+ export function createFailedEvaluationData(error, overrides = {}) {
104
+ return normalizeEvaluationData({
105
+ ...overrides,
106
+ reasoning: `Evaluation failed: ${truncateString(error, 100)}`,
107
+ alertSeverity: "medium",
108
+ evaluationModel: overrides.evaluationModel || "error",
109
+ evaluationConfig: {
110
+ mode: "error",
111
+ fallbackUsed: true,
112
+ costEstimate: 0,
113
+ },
114
+ });
115
+ }
116
+ /**
117
+ * Helper function to truncate strings to a maximum length
118
+ */
119
+ function truncateString(str, maxLength) {
120
+ if (str.length <= maxLength) {
121
+ return str;
122
+ }
123
+ return str.substring(0, maxLength - 3) + "...";
124
+ }
125
+ /**
126
+ * Merge multiple partial evaluation data objects into a normalized result
127
+ */
128
+ export function mergeEvaluationData(...partials) {
129
+ const merged = partials.reduce((acc, partial) => ({ ...acc, ...partial }), {});
130
+ return normalizeEvaluationData(merged);
131
+ }