@juspay/neurolink 7.29.2 → 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 (198) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cli/commands/config.d.ts +83 -83
  3. package/dist/cli/commands/mcp.js +39 -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 +8 -0
  7. package/dist/cli/factories/commandFactory.js +65 -65
  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 +11 -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/modelConfiguration.d.ts +63 -0
  27. package/dist/core/modelConfiguration.js +354 -290
  28. package/dist/core/streamAnalytics.d.ts +10 -5
  29. package/dist/core/streamAnalytics.js +10 -10
  30. package/dist/core/types.d.ts +19 -109
  31. package/dist/core/types.js +13 -0
  32. package/dist/factories/providerFactory.js +1 -1
  33. package/dist/index.d.ts +2 -1
  34. package/dist/lib/config/configManager.js +5 -2
  35. package/dist/lib/core/analytics.d.ts +2 -24
  36. package/dist/lib/core/analytics.js +12 -17
  37. package/dist/lib/core/baseProvider.d.ts +30 -1
  38. package/dist/lib/core/baseProvider.js +180 -198
  39. package/dist/lib/core/dynamicModels.js +7 -7
  40. package/dist/lib/core/evaluation.d.ts +9 -9
  41. package/dist/lib/core/evaluation.js +117 -65
  42. package/dist/lib/core/evaluationProviders.d.ts +18 -2
  43. package/dist/lib/core/evaluationProviders.js +15 -13
  44. package/dist/lib/core/modelConfiguration.d.ts +63 -0
  45. package/dist/lib/core/modelConfiguration.js +354 -290
  46. package/dist/lib/core/streamAnalytics.d.ts +10 -5
  47. package/dist/lib/core/streamAnalytics.js +10 -10
  48. package/dist/lib/core/types.d.ts +19 -109
  49. package/dist/lib/core/types.js +13 -0
  50. package/dist/lib/factories/providerFactory.js +1 -1
  51. package/dist/lib/index.d.ts +2 -1
  52. package/dist/lib/mcp/externalServerManager.js +15 -6
  53. package/dist/lib/mcp/factory.js +1 -1
  54. package/dist/lib/mcp/index.d.ts +1 -1
  55. package/dist/lib/mcp/index.js +1 -1
  56. package/dist/lib/mcp/mcpCircuitBreaker.js +5 -1
  57. package/dist/lib/mcp/mcpClientFactory.js +3 -0
  58. package/dist/lib/mcp/registry.d.ts +3 -3
  59. package/dist/lib/mcp/registry.js +3 -3
  60. package/dist/lib/mcp/servers/aiProviders/aiAnalysisTools.js +5 -5
  61. package/dist/lib/mcp/servers/aiProviders/aiWorkflowTools.js +6 -6
  62. package/dist/lib/mcp/servers/utilities/utilityServer.js +1 -1
  63. package/dist/lib/mcp/toolDiscoveryService.js +8 -2
  64. package/dist/lib/mcp/toolRegistry.js +4 -4
  65. package/dist/lib/middleware/builtin/analytics.js +4 -4
  66. package/dist/lib/middleware/builtin/guardrails.js +2 -2
  67. package/dist/lib/middleware/registry.js +11 -2
  68. package/dist/lib/models/modelRegistry.d.ts +1 -1
  69. package/dist/lib/models/modelRegistry.js +3 -3
  70. package/dist/lib/models/modelResolver.d.ts +1 -1
  71. package/dist/lib/models/modelResolver.js +2 -2
  72. package/dist/lib/neurolink.d.ts +116 -0
  73. package/dist/lib/neurolink.js +716 -922
  74. package/dist/lib/providers/amazonSagemaker.d.ts +1 -1
  75. package/dist/lib/providers/amazonSagemaker.js +12 -3
  76. package/dist/lib/providers/anthropic.d.ts +1 -1
  77. package/dist/lib/providers/anthropic.js +7 -6
  78. package/dist/lib/providers/anthropicBaseProvider.d.ts +1 -1
  79. package/dist/lib/providers/anthropicBaseProvider.js +4 -3
  80. package/dist/lib/providers/azureOpenai.d.ts +1 -1
  81. package/dist/lib/providers/azureOpenai.js +1 -1
  82. package/dist/lib/providers/googleAiStudio.d.ts +1 -1
  83. package/dist/lib/providers/googleAiStudio.js +2 -2
  84. package/dist/lib/providers/googleVertex.d.ts +40 -0
  85. package/dist/lib/providers/googleVertex.js +330 -274
  86. package/dist/lib/providers/huggingFace.js +1 -1
  87. package/dist/lib/providers/mistral.d.ts +1 -1
  88. package/dist/lib/providers/mistral.js +2 -2
  89. package/dist/lib/providers/ollama.d.ts +4 -0
  90. package/dist/lib/providers/ollama.js +38 -18
  91. package/dist/lib/providers/openAI.d.ts +1 -1
  92. package/dist/lib/providers/openAI.js +2 -2
  93. package/dist/lib/providers/sagemaker/adaptive-semaphore.js +7 -4
  94. package/dist/lib/providers/sagemaker/client.js +13 -3
  95. package/dist/lib/providers/sagemaker/config.js +5 -1
  96. package/dist/lib/providers/sagemaker/detection.js +19 -9
  97. package/dist/lib/providers/sagemaker/errors.d.ts +8 -1
  98. package/dist/lib/providers/sagemaker/errors.js +103 -20
  99. package/dist/lib/providers/sagemaker/language-model.d.ts +3 -3
  100. package/dist/lib/providers/sagemaker/language-model.js +4 -4
  101. package/dist/lib/providers/sagemaker/parsers.js +14 -6
  102. package/dist/lib/providers/sagemaker/streaming.js +14 -3
  103. package/dist/lib/providers/sagemaker/types.d.ts +1 -1
  104. package/dist/lib/proxy/awsProxyIntegration.js +1 -1
  105. package/dist/lib/sdk/toolRegistration.d.ts +1 -1
  106. package/dist/lib/types/cli.d.ts +80 -8
  107. package/dist/lib/types/contextTypes.js +2 -2
  108. package/dist/lib/types/generateTypes.d.ts +4 -6
  109. package/dist/lib/types/providers.d.ts +81 -19
  110. package/dist/lib/types/providers.js +6 -6
  111. package/dist/lib/types/streamTypes.d.ts +4 -6
  112. package/dist/lib/types/typeAliases.d.ts +1 -1
  113. package/dist/lib/utils/analyticsUtils.d.ts +33 -0
  114. package/dist/lib/utils/analyticsUtils.js +76 -0
  115. package/dist/lib/utils/errorHandling.js +4 -1
  116. package/dist/lib/utils/evaluationUtils.d.ts +27 -0
  117. package/dist/lib/utils/evaluationUtils.js +131 -0
  118. package/dist/lib/utils/optionsUtils.js +10 -1
  119. package/dist/lib/utils/performance.d.ts +1 -1
  120. package/dist/lib/utils/performance.js +15 -3
  121. package/dist/lib/utils/providerHealth.d.ts +48 -0
  122. package/dist/lib/utils/providerHealth.js +199 -254
  123. package/dist/lib/utils/providerUtils.js +2 -2
  124. package/dist/lib/utils/timeout.js +8 -3
  125. package/dist/mcp/externalServerManager.js +15 -6
  126. package/dist/mcp/factory.js +1 -1
  127. package/dist/mcp/index.d.ts +1 -1
  128. package/dist/mcp/index.js +1 -1
  129. package/dist/mcp/mcpCircuitBreaker.js +5 -1
  130. package/dist/mcp/mcpClientFactory.js +3 -0
  131. package/dist/mcp/registry.d.ts +3 -3
  132. package/dist/mcp/registry.js +3 -3
  133. package/dist/mcp/servers/aiProviders/aiAnalysisTools.js +5 -5
  134. package/dist/mcp/servers/aiProviders/aiWorkflowTools.js +6 -6
  135. package/dist/mcp/servers/utilities/utilityServer.js +1 -1
  136. package/dist/mcp/toolDiscoveryService.js +8 -2
  137. package/dist/mcp/toolRegistry.js +4 -4
  138. package/dist/middleware/builtin/analytics.js +4 -4
  139. package/dist/middleware/builtin/guardrails.js +2 -2
  140. package/dist/middleware/registry.js +11 -2
  141. package/dist/models/modelRegistry.d.ts +1 -1
  142. package/dist/models/modelRegistry.js +3 -3
  143. package/dist/models/modelResolver.d.ts +1 -1
  144. package/dist/models/modelResolver.js +2 -2
  145. package/dist/neurolink.d.ts +116 -0
  146. package/dist/neurolink.js +716 -922
  147. package/dist/providers/amazonSagemaker.d.ts +1 -1
  148. package/dist/providers/amazonSagemaker.js +12 -3
  149. package/dist/providers/anthropic.d.ts +1 -1
  150. package/dist/providers/anthropic.js +7 -6
  151. package/dist/providers/anthropicBaseProvider.d.ts +1 -1
  152. package/dist/providers/anthropicBaseProvider.js +4 -3
  153. package/dist/providers/azureOpenai.d.ts +1 -1
  154. package/dist/providers/azureOpenai.js +1 -1
  155. package/dist/providers/googleAiStudio.d.ts +1 -1
  156. package/dist/providers/googleAiStudio.js +2 -2
  157. package/dist/providers/googleVertex.d.ts +40 -0
  158. package/dist/providers/googleVertex.js +330 -274
  159. package/dist/providers/huggingFace.js +1 -1
  160. package/dist/providers/mistral.d.ts +1 -1
  161. package/dist/providers/mistral.js +2 -2
  162. package/dist/providers/ollama.d.ts +4 -0
  163. package/dist/providers/ollama.js +38 -18
  164. package/dist/providers/openAI.d.ts +1 -1
  165. package/dist/providers/openAI.js +2 -2
  166. package/dist/providers/sagemaker/adaptive-semaphore.js +7 -4
  167. package/dist/providers/sagemaker/client.js +13 -3
  168. package/dist/providers/sagemaker/config.js +5 -1
  169. package/dist/providers/sagemaker/detection.js +19 -9
  170. package/dist/providers/sagemaker/errors.d.ts +8 -1
  171. package/dist/providers/sagemaker/errors.js +103 -20
  172. package/dist/providers/sagemaker/language-model.d.ts +3 -3
  173. package/dist/providers/sagemaker/language-model.js +4 -4
  174. package/dist/providers/sagemaker/parsers.js +14 -6
  175. package/dist/providers/sagemaker/streaming.js +14 -3
  176. package/dist/providers/sagemaker/types.d.ts +1 -1
  177. package/dist/proxy/awsProxyIntegration.js +1 -1
  178. package/dist/sdk/toolRegistration.d.ts +1 -1
  179. package/dist/types/cli.d.ts +80 -8
  180. package/dist/types/contextTypes.js +2 -2
  181. package/dist/types/generateTypes.d.ts +4 -6
  182. package/dist/types/providers.d.ts +81 -19
  183. package/dist/types/providers.js +6 -6
  184. package/dist/types/streamTypes.d.ts +4 -6
  185. package/dist/types/typeAliases.d.ts +1 -1
  186. package/dist/utils/analyticsUtils.d.ts +33 -0
  187. package/dist/utils/analyticsUtils.js +76 -0
  188. package/dist/utils/errorHandling.js +4 -1
  189. package/dist/utils/evaluationUtils.d.ts +27 -0
  190. package/dist/utils/evaluationUtils.js +131 -0
  191. package/dist/utils/optionsUtils.js +10 -1
  192. package/dist/utils/performance.d.ts +1 -1
  193. package/dist/utils/performance.js +15 -3
  194. package/dist/utils/providerHealth.d.ts +48 -0
  195. package/dist/utils/providerHealth.js +199 -254
  196. package/dist/utils/providerUtils.js +2 -2
  197. package/dist/utils/timeout.js +8 -3
  198. package/package.json +1 -1
@@ -262,7 +262,11 @@ export class HuggingFaceStreamParser extends BaseStreamingParser {
262
262
  // Error format
263
263
  if (data.error) {
264
264
  const errorMessage = extractApiErrorMessage(data.error);
265
- throw new SageMakerError(`HuggingFace streaming error: ${errorMessage}`, "MODEL_ERROR", 500);
265
+ throw new SageMakerError(`HuggingFace streaming error: ${errorMessage}`, {
266
+ code: "MODEL_ERROR",
267
+ statusCode: 500,
268
+ retryable: false,
269
+ });
266
270
  }
267
271
  return null;
268
272
  }
@@ -274,7 +278,7 @@ export class HuggingFaceStreamParser extends BaseStreamingParser {
274
278
  return {
275
279
  promptTokens: Number(tokens.input) || 0,
276
280
  completionTokens: Number(tokens.generated) || 0,
277
- totalTokens: Number(tokens.total) || 0,
281
+ total: Number(tokens.total) || 0,
278
282
  };
279
283
  }
280
284
  mapFinishReason(reason) {
@@ -379,7 +383,11 @@ export class LlamaStreamParser extends BaseStreamingParser {
379
383
  if (data.error) {
380
384
  const errorData = data.error;
381
385
  const errorMessage = extractApiErrorMessage(errorData);
382
- throw new SageMakerError(`LLaMA streaming error: ${errorMessage}`, "MODEL_ERROR", 500);
386
+ throw new SageMakerError(`LLaMA streaming error: ${errorMessage}`, {
387
+ code: "MODEL_ERROR",
388
+ statusCode: 500,
389
+ retryable: false,
390
+ });
383
391
  }
384
392
  return null;
385
393
  }
@@ -441,7 +449,7 @@ export class LlamaStreamParser extends BaseStreamingParser {
441
449
  return {
442
450
  promptTokens: Number(usage.prompt_tokens) || 0,
443
451
  completionTokens: Number(usage.completion_tokens) || 0,
444
- totalTokens: Number(usage.total_tokens) || 0,
452
+ total: Number(usage.total_tokens) || 0,
445
453
  };
446
454
  }
447
455
  mapFinishReason(reason) {
@@ -563,7 +571,7 @@ export class CustomStreamParser extends BaseStreamingParser {
563
571
  return {
564
572
  promptTokens: Number(usage.prompt_tokens || usage.input_tokens) || 0,
565
573
  completionTokens: Number(usage.completion_tokens || usage.output_tokens) || 0,
566
- totalTokens: Number(usage.total_tokens) || 0,
574
+ total: Number(usage.total_tokens) || 0,
567
575
  };
568
576
  }
569
577
  }
@@ -621,6 +629,6 @@ export function estimateTokenUsage(prompt, completion) {
621
629
  return {
622
630
  promptTokens,
623
631
  completionTokens,
624
- totalTokens: promptTokens + completionTokens,
632
+ total: promptTokens + completionTokens,
625
633
  };
626
634
  }
@@ -69,7 +69,18 @@ async function createProtocolSpecificStream(responseStream, parser, capability,
69
69
  while (true) {
70
70
  // Check for abort signal
71
71
  if (options.abortSignal?.aborted) {
72
- throw new SageMakerError("Stream aborted by user", "NETWORK_ERROR", 499);
72
+ // Clean up upstream iterator before throwing
73
+ try {
74
+ await reader.return?.();
75
+ }
76
+ catch {
77
+ // Ignore cleanup errors, still propagate original abort
78
+ }
79
+ throw new SageMakerError("Stream aborted by user", {
80
+ code: "NETWORK_ERROR",
81
+ statusCode: 499,
82
+ retryable: false,
83
+ });
73
84
  }
74
85
  const { done, value } = await reader.next();
75
86
  if (done) {
@@ -86,7 +97,7 @@ async function createProtocolSpecificStream(responseStream, parser, capability,
86
97
  options.onComplete?.(finalUsage || {
87
98
  promptTokens: 0,
88
99
  completionTokens: 0,
89
- totalTokens: 0,
100
+ total: 0,
90
101
  });
91
102
  controller.close();
92
103
  break;
@@ -315,6 +326,6 @@ export function estimateTokenUsage(prompt, completion) {
315
326
  return {
316
327
  promptTokens,
317
328
  completionTokens,
318
- totalTokens: promptTokens + completionTokens,
329
+ total: promptTokens + completionTokens,
319
330
  };
320
331
  }
@@ -96,7 +96,7 @@ export interface SageMakerUsage {
96
96
  /** Number of completion tokens */
97
97
  completionTokens: number;
98
98
  /** Total tokens used */
99
- totalTokens: number;
99
+ total: number;
100
100
  /** Request processing time in milliseconds */
101
101
  requestTime?: number;
102
102
  /** Model inference time in milliseconds */
@@ -87,7 +87,7 @@ async function configureSocksAgents(proxyUrl) {
87
87
  /**
88
88
  * Minimal HTTP agent configuration (fallback)
89
89
  */
90
- async function configureMinimalHttpAgents(_proxyUrl) {
90
+ async function _configureMinimalHttpAgents(_proxyUrl) {
91
91
  // Remove broken fallback. Use explicit proxy-aware HttpHandler instead.
92
92
  logger.warn("[AWS Proxy] Minimal agent fallback removed; a proper proxy agent is required.");
93
93
  }
@@ -88,7 +88,7 @@ export declare function createMCPServerFromTools(serverId: string, tools: Record
88
88
  /**
89
89
  * Helper to create a tool with type safety
90
90
  */
91
- export declare function createTool<TParams = ToolArgs>(config: SimpleTool): SimpleTool;
91
+ export declare function createTool(config: SimpleTool): SimpleTool;
92
92
  /**
93
93
  * Helper to create a validated tool with suggested improvements
94
94
  */
@@ -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,21 @@ 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;
43
39
  }
44
40
  /**
45
41
  * AWS Credential Configuration for Bedrock provider
@@ -166,16 +162,82 @@ export interface ModelPricing {
166
162
  free?: boolean;
167
163
  }
168
164
  /**
169
- * Evaluation data structure
165
+ * Response quality evaluation scores - Comprehensive evaluation interface
170
166
  */
171
167
  export interface EvaluationData {
172
- relevance?: number;
173
- accuracy?: number;
174
- completeness?: number;
175
- coherence?: number;
176
- overall?: number;
177
- feedback?: string;
178
- [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
+ };
179
241
  }
180
242
  /**
181
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;