@juspay/neurolink 7.29.2 → 7.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/cli/commands/config.d.ts +83 -83
- package/dist/cli/commands/mcp.js +39 -9
- package/dist/cli/commands/models.js +25 -21
- package/dist/cli/commands/ollama.js +2 -2
- package/dist/cli/factories/commandFactory.d.ts +8 -0
- package/dist/cli/factories/commandFactory.js +65 -65
- package/dist/cli/factories/ollamaCommandFactory.js +3 -1
- package/dist/cli/factories/sagemakerCommandFactory.js +3 -2
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +11 -11
- package/dist/cli/utils/envManager.js +5 -5
- package/dist/cli/utils/ollamaUtils.d.ts +12 -0
- package/dist/cli/utils/ollamaUtils.js +58 -42
- package/dist/config/configManager.js +5 -2
- package/dist/config/conversationMemoryConfig.js +5 -0
- package/dist/core/analytics.d.ts +2 -24
- package/dist/core/analytics.js +12 -17
- package/dist/core/baseProvider.d.ts +30 -1
- package/dist/core/baseProvider.js +180 -198
- package/dist/core/conversationMemoryManager.d.ts +9 -15
- package/dist/core/conversationMemoryManager.js +98 -57
- package/dist/core/dynamicModels.d.ts +4 -4
- package/dist/core/dynamicModels.js +7 -7
- package/dist/core/evaluation.d.ts +9 -9
- package/dist/core/evaluation.js +117 -65
- package/dist/core/evaluationProviders.d.ts +18 -2
- package/dist/core/evaluationProviders.js +15 -13
- package/dist/core/modelConfiguration.d.ts +63 -0
- package/dist/core/modelConfiguration.js +354 -290
- package/dist/core/streamAnalytics.d.ts +10 -5
- package/dist/core/streamAnalytics.js +10 -10
- package/dist/core/types.d.ts +22 -110
- package/dist/core/types.js +13 -0
- package/dist/factories/providerFactory.js +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/lib/config/configManager.js +5 -2
- package/dist/lib/config/conversationMemoryConfig.js +5 -0
- package/dist/lib/core/analytics.d.ts +2 -24
- package/dist/lib/core/analytics.js +12 -17
- package/dist/lib/core/baseProvider.d.ts +30 -1
- package/dist/lib/core/baseProvider.js +180 -198
- package/dist/lib/core/conversationMemoryManager.d.ts +9 -15
- package/dist/lib/core/conversationMemoryManager.js +98 -57
- package/dist/lib/core/dynamicModels.js +7 -7
- package/dist/lib/core/evaluation.d.ts +9 -9
- package/dist/lib/core/evaluation.js +117 -65
- package/dist/lib/core/evaluationProviders.d.ts +18 -2
- package/dist/lib/core/evaluationProviders.js +15 -13
- package/dist/lib/core/modelConfiguration.d.ts +63 -0
- package/dist/lib/core/modelConfiguration.js +354 -290
- package/dist/lib/core/streamAnalytics.d.ts +10 -5
- package/dist/lib/core/streamAnalytics.js +10 -10
- package/dist/lib/core/types.d.ts +22 -110
- package/dist/lib/core/types.js +13 -0
- package/dist/lib/factories/providerFactory.js +1 -1
- package/dist/lib/index.d.ts +2 -1
- package/dist/lib/mcp/externalServerManager.js +15 -6
- package/dist/lib/mcp/factory.js +1 -1
- package/dist/lib/mcp/index.d.ts +1 -1
- package/dist/lib/mcp/index.js +1 -1
- package/dist/lib/mcp/mcpCircuitBreaker.js +5 -1
- package/dist/lib/mcp/mcpClientFactory.js +3 -0
- package/dist/lib/mcp/registry.d.ts +3 -3
- package/dist/lib/mcp/registry.js +3 -3
- package/dist/lib/mcp/servers/aiProviders/aiAnalysisTools.js +5 -5
- package/dist/lib/mcp/servers/aiProviders/aiWorkflowTools.js +6 -6
- package/dist/lib/mcp/servers/utilities/utilityServer.js +1 -1
- package/dist/lib/mcp/toolDiscoveryService.js +8 -2
- package/dist/lib/mcp/toolRegistry.js +4 -4
- package/dist/lib/middleware/builtin/analytics.js +4 -4
- package/dist/lib/middleware/builtin/guardrails.js +2 -2
- package/dist/lib/middleware/registry.js +11 -2
- package/dist/lib/models/modelRegistry.d.ts +1 -1
- package/dist/lib/models/modelRegistry.js +3 -3
- package/dist/lib/models/modelResolver.d.ts +1 -1
- package/dist/lib/models/modelResolver.js +2 -2
- package/dist/lib/neurolink.d.ts +116 -9
- package/dist/lib/neurolink.js +718 -956
- package/dist/lib/providers/amazonSagemaker.d.ts +1 -1
- package/dist/lib/providers/amazonSagemaker.js +12 -3
- package/dist/lib/providers/anthropic.d.ts +1 -1
- package/dist/lib/providers/anthropic.js +7 -6
- package/dist/lib/providers/anthropicBaseProvider.d.ts +1 -1
- package/dist/lib/providers/anthropicBaseProvider.js +4 -3
- package/dist/lib/providers/azureOpenai.d.ts +1 -1
- package/dist/lib/providers/azureOpenai.js +1 -1
- package/dist/lib/providers/googleAiStudio.d.ts +1 -1
- package/dist/lib/providers/googleAiStudio.js +2 -2
- package/dist/lib/providers/googleVertex.d.ts +40 -0
- package/dist/lib/providers/googleVertex.js +330 -274
- package/dist/lib/providers/huggingFace.js +1 -1
- package/dist/lib/providers/mistral.d.ts +1 -1
- package/dist/lib/providers/mistral.js +2 -2
- package/dist/lib/providers/ollama.d.ts +4 -0
- package/dist/lib/providers/ollama.js +38 -18
- package/dist/lib/providers/openAI.d.ts +1 -1
- package/dist/lib/providers/openAI.js +2 -2
- package/dist/lib/providers/sagemaker/adaptive-semaphore.js +7 -4
- package/dist/lib/providers/sagemaker/client.js +13 -3
- package/dist/lib/providers/sagemaker/config.js +5 -1
- package/dist/lib/providers/sagemaker/detection.js +19 -9
- package/dist/lib/providers/sagemaker/errors.d.ts +8 -1
- package/dist/lib/providers/sagemaker/errors.js +103 -20
- package/dist/lib/providers/sagemaker/language-model.d.ts +3 -3
- package/dist/lib/providers/sagemaker/language-model.js +4 -4
- package/dist/lib/providers/sagemaker/parsers.js +14 -6
- package/dist/lib/providers/sagemaker/streaming.js +14 -3
- package/dist/lib/providers/sagemaker/types.d.ts +1 -1
- package/dist/lib/proxy/awsProxyIntegration.js +1 -1
- package/dist/lib/sdk/toolRegistration.d.ts +1 -1
- package/dist/lib/types/cli.d.ts +80 -8
- package/dist/lib/types/contextTypes.js +2 -2
- package/dist/lib/types/conversationTypes.d.ts +10 -0
- package/dist/lib/types/generateTypes.d.ts +2 -5
- package/dist/lib/types/providers.d.ts +81 -19
- package/dist/lib/types/providers.js +6 -6
- package/dist/lib/types/streamTypes.d.ts +4 -6
- package/dist/lib/types/typeAliases.d.ts +1 -1
- package/dist/lib/utils/analyticsUtils.d.ts +33 -0
- package/dist/lib/utils/analyticsUtils.js +76 -0
- package/dist/lib/utils/conversationMemoryUtils.d.ts +1 -2
- package/dist/lib/utils/conversationMemoryUtils.js +6 -7
- package/dist/lib/utils/errorHandling.js +4 -1
- package/dist/lib/utils/evaluationUtils.d.ts +27 -0
- package/dist/lib/utils/evaluationUtils.js +131 -0
- package/dist/lib/utils/optionsUtils.js +10 -1
- package/dist/lib/utils/performance.d.ts +1 -1
- package/dist/lib/utils/performance.js +15 -3
- package/dist/lib/utils/providerHealth.d.ts +48 -0
- package/dist/lib/utils/providerHealth.js +199 -254
- package/dist/lib/utils/providerUtils.js +2 -2
- package/dist/lib/utils/timeout.js +8 -3
- package/dist/mcp/externalServerManager.js +15 -6
- package/dist/mcp/factory.js +1 -1
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/mcpCircuitBreaker.js +5 -1
- package/dist/mcp/mcpClientFactory.js +3 -0
- package/dist/mcp/registry.d.ts +3 -3
- package/dist/mcp/registry.js +3 -3
- package/dist/mcp/servers/aiProviders/aiAnalysisTools.js +5 -5
- package/dist/mcp/servers/aiProviders/aiWorkflowTools.js +6 -6
- package/dist/mcp/servers/utilities/utilityServer.js +1 -1
- package/dist/mcp/toolDiscoveryService.js +8 -2
- package/dist/mcp/toolRegistry.js +4 -4
- package/dist/middleware/builtin/analytics.js +4 -4
- package/dist/middleware/builtin/guardrails.js +2 -2
- package/dist/middleware/registry.js +11 -2
- package/dist/models/modelRegistry.d.ts +1 -1
- package/dist/models/modelRegistry.js +3 -3
- package/dist/models/modelResolver.d.ts +1 -1
- package/dist/models/modelResolver.js +2 -2
- package/dist/neurolink.d.ts +116 -9
- package/dist/neurolink.js +718 -956
- package/dist/providers/amazonSagemaker.d.ts +1 -1
- package/dist/providers/amazonSagemaker.js +12 -3
- package/dist/providers/anthropic.d.ts +1 -1
- package/dist/providers/anthropic.js +7 -6
- package/dist/providers/anthropicBaseProvider.d.ts +1 -1
- package/dist/providers/anthropicBaseProvider.js +4 -3
- package/dist/providers/azureOpenai.d.ts +1 -1
- package/dist/providers/azureOpenai.js +1 -1
- package/dist/providers/googleAiStudio.d.ts +1 -1
- package/dist/providers/googleAiStudio.js +2 -2
- package/dist/providers/googleVertex.d.ts +40 -0
- package/dist/providers/googleVertex.js +330 -274
- package/dist/providers/huggingFace.js +1 -1
- package/dist/providers/mistral.d.ts +1 -1
- package/dist/providers/mistral.js +2 -2
- package/dist/providers/ollama.d.ts +4 -0
- package/dist/providers/ollama.js +38 -18
- package/dist/providers/openAI.d.ts +1 -1
- package/dist/providers/openAI.js +2 -2
- package/dist/providers/sagemaker/adaptive-semaphore.js +7 -4
- package/dist/providers/sagemaker/client.js +13 -3
- package/dist/providers/sagemaker/config.js +5 -1
- package/dist/providers/sagemaker/detection.js +19 -9
- package/dist/providers/sagemaker/errors.d.ts +8 -1
- package/dist/providers/sagemaker/errors.js +103 -20
- package/dist/providers/sagemaker/language-model.d.ts +3 -3
- package/dist/providers/sagemaker/language-model.js +4 -4
- package/dist/providers/sagemaker/parsers.js +14 -6
- package/dist/providers/sagemaker/streaming.js +14 -3
- package/dist/providers/sagemaker/types.d.ts +1 -1
- package/dist/proxy/awsProxyIntegration.js +1 -1
- package/dist/sdk/toolRegistration.d.ts +1 -1
- package/dist/types/cli.d.ts +80 -8
- package/dist/types/contextTypes.js +2 -2
- package/dist/types/conversationTypes.d.ts +10 -0
- package/dist/types/generateTypes.d.ts +2 -5
- package/dist/types/providers.d.ts +81 -19
- package/dist/types/providers.js +6 -6
- package/dist/types/streamTypes.d.ts +4 -6
- package/dist/types/typeAliases.d.ts +1 -1
- package/dist/utils/analyticsUtils.d.ts +33 -0
- package/dist/utils/analyticsUtils.js +76 -0
- package/dist/utils/conversationMemoryUtils.d.ts +1 -2
- package/dist/utils/conversationMemoryUtils.js +6 -7
- package/dist/utils/errorHandling.js +4 -1
- package/dist/utils/evaluationUtils.d.ts +27 -0
- package/dist/utils/evaluationUtils.js +131 -0
- package/dist/utils/optionsUtils.js +10 -1
- package/dist/utils/performance.d.ts +1 -1
- package/dist/utils/performance.js +15 -3
- package/dist/utils/providerHealth.d.ts +48 -0
- package/dist/utils/providerHealth.js +199 -254
- package/dist/utils/providerUtils.js +2 -2
- package/dist/utils/timeout.js +8 -3
- package/package.json +1 -1
- package/dist/context/ContextManager.d.ts +0 -28
- package/dist/context/ContextManager.js +0 -113
- package/dist/context/config.d.ts +0 -5
- package/dist/context/config.js +0 -42
- package/dist/context/types.d.ts +0 -20
- package/dist/context/types.js +0 -1
- package/dist/context/utils.d.ts +0 -7
- package/dist/context/utils.js +0 -8
- package/dist/lib/context/ContextManager.d.ts +0 -28
- package/dist/lib/context/ContextManager.js +0 -113
- package/dist/lib/context/config.d.ts +0 -5
- package/dist/lib/context/config.js +0 -42
- package/dist/lib/context/types.d.ts +0 -20
- package/dist/lib/context/types.js +0 -1
- package/dist/lib/context/utils.d.ts +0 -7
- package/dist/lib/context/utils.js +0 -8
|
@@ -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}`,
|
|
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
|
-
|
|
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}`,
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
91
|
+
export declare function createTool(config: SimpleTool): SimpleTool;
|
|
92
92
|
/**
|
|
93
93
|
* Helper to create a validated tool with suggested improvements
|
|
94
94
|
*/
|
package/dist/lib/types/cli.d.ts
CHANGED
|
@@ -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,
|
|
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
|
|
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
|
-
/**
|
|
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
|
|
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,
|
|
@@ -12,6 +12,16 @@ export interface ConversationMemoryConfig {
|
|
|
12
12
|
maxSessions?: number;
|
|
13
13
|
/** Maximum number of conversation turns to keep per session (default: 20) */
|
|
14
14
|
maxTurnsPerSession?: number;
|
|
15
|
+
/** Enable automatic summarization */
|
|
16
|
+
enableSummarization?: boolean;
|
|
17
|
+
/** Turn count to trigger summarization */
|
|
18
|
+
summarizationThresholdTurns?: number;
|
|
19
|
+
/** Target turn count for the summary */
|
|
20
|
+
summarizationTargetTurns?: number;
|
|
21
|
+
/** Provider to use for summarization */
|
|
22
|
+
summarizationProvider?: string;
|
|
23
|
+
/** Model to use for summarization */
|
|
24
|
+
summarizationModel?: string;
|
|
15
25
|
}
|
|
16
26
|
/**
|
|
17
27
|
* Complete memory for a conversation session
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Tool } from "ai";
|
|
2
2
|
import type { ValidationSchema, StandardRecord } from "./typeAliases.js";
|
|
3
3
|
import type { AIProviderName, AnalyticsData, EvaluationData } from "../core/types.js";
|
|
4
|
+
import type { TokenUsage } from "./providers.js";
|
|
4
5
|
/**
|
|
5
6
|
* Generate function options interface - Primary method for content generation
|
|
6
7
|
* Future-ready for multi-modal capabilities while maintaining text focus
|
|
@@ -56,11 +57,7 @@ export interface GenerateResult {
|
|
|
56
57
|
};
|
|
57
58
|
provider?: string;
|
|
58
59
|
model?: string;
|
|
59
|
-
usage?:
|
|
60
|
-
inputTokens: number;
|
|
61
|
-
outputTokens: number;
|
|
62
|
-
totalTokens: number;
|
|
63
|
-
};
|
|
60
|
+
usage?: TokenUsage;
|
|
64
61
|
responseTime?: number;
|
|
65
62
|
toolCalls?: Array<{
|
|
66
63
|
toolCallId: string;
|
|
@@ -21,25 +21,21 @@ export interface ProviderError extends Error {
|
|
|
21
21
|
* Token usage information
|
|
22
22
|
*/
|
|
23
23
|
export interface TokenUsage {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
|
33
|
+
model?: string;
|
|
34
|
+
tokenUsage: TokenUsage;
|
|
34
35
|
requestDuration: number;
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
*
|
|
165
|
+
* Response quality evaluation scores - Comprehensive evaluation interface
|
|
170
166
|
*/
|
|
171
167
|
export interface EvaluationData {
|
|
172
|
-
relevance
|
|
173
|
-
accuracy
|
|
174
|
-
completeness
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
typeof value.
|
|
20
|
-
typeof value.
|
|
21
|
-
typeof value.
|
|
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
|
|
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
|
|
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
|
+
}
|
|
@@ -11,8 +11,7 @@ import type { TextGenerationOptions, TextGenerationResult } from "../core/types.
|
|
|
11
11
|
*/
|
|
12
12
|
export declare function applyConversationMemoryDefaults(userConfig?: Partial<ConversationMemoryConfig>): ConversationMemoryConfig;
|
|
13
13
|
/**
|
|
14
|
-
* Get conversation history as message array
|
|
15
|
-
* Returns proper message array format for AI providers
|
|
14
|
+
* Get conversation history as message array, summarizing if needed.
|
|
16
15
|
*/
|
|
17
16
|
export declare function getConversationMessages(conversationMemory: ConversationMemoryManager | undefined, options: TextGenerationOptions): Promise<ChatMessage[]>;
|
|
18
17
|
/**
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Conversation Memory Utilities
|
|
3
3
|
* Handles configuration merging and conversation memory operations
|
|
4
4
|
*/
|
|
5
|
-
import { getConversationMemoryDefaults } from "../config/conversationMemoryConfig.js";
|
|
5
|
+
import { getConversationMemoryDefaults, } from "../config/conversationMemoryConfig.js";
|
|
6
6
|
import { logger } from "./logger.js";
|
|
7
7
|
/**
|
|
8
8
|
* Apply conversation memory defaults to user configuration
|
|
@@ -11,14 +11,12 @@ import { logger } from "./logger.js";
|
|
|
11
11
|
export function applyConversationMemoryDefaults(userConfig) {
|
|
12
12
|
const defaults = getConversationMemoryDefaults();
|
|
13
13
|
return {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
maxTurnsPerSession: userConfig?.maxTurnsPerSession ?? defaults.maxTurnsPerSession,
|
|
14
|
+
...defaults,
|
|
15
|
+
...userConfig,
|
|
17
16
|
};
|
|
18
17
|
}
|
|
19
18
|
/**
|
|
20
|
-
* Get conversation history as message array
|
|
21
|
-
* Returns proper message array format for AI providers
|
|
19
|
+
* Get conversation history as message array, summarizing if needed.
|
|
22
20
|
*/
|
|
23
21
|
export async function getConversationMessages(conversationMemory, options) {
|
|
24
22
|
if (!conversationMemory || !options.context) {
|
|
@@ -29,6 +27,7 @@ export async function getConversationMessages(conversationMemory, options) {
|
|
|
29
27
|
return [];
|
|
30
28
|
}
|
|
31
29
|
try {
|
|
30
|
+
// Remove duplicate summarization logic - it should be handled in ConversationMemoryManager
|
|
32
31
|
const messages = conversationMemory.buildContextMessages(sessionId);
|
|
33
32
|
logger.debug("Conversation messages retrieved", {
|
|
34
33
|
sessionId,
|
|
@@ -59,7 +58,7 @@ export async function storeConversationTurn(conversationMemory, originalOptions,
|
|
|
59
58
|
return;
|
|
60
59
|
}
|
|
61
60
|
try {
|
|
62
|
-
await conversationMemory.storeConversationTurn(sessionId, userId, originalOptions.prompt || "", result.content);
|
|
61
|
+
await conversationMemory.storeConversationTurn(sessionId, userId, originalOptions.originalPrompt || originalOptions.prompt || "", result.content);
|
|
63
62
|
logger.debug("Conversation turn stored", {
|
|
64
63
|
sessionId,
|
|
65
64
|
userId,
|
|
@@ -218,7 +218,10 @@ export async function withRetry(operation, options) {
|
|
|
218
218
|
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
|
-
|
|
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
|