@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.
- package/CHANGELOG.md +12 -0
- package/dist/cli/commands/config.d.ts +86 -86
- package/dist/cli/commands/mcp.js +64 -9
- package/dist/cli/commands/models.js +25 -21
- package/dist/cli/commands/ollama.js +2 -2
- package/dist/cli/factories/commandFactory.d.ts +9 -0
- package/dist/cli/factories/commandFactory.js +177 -83
- 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 +19 -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/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/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/factory.js +77 -4
- 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 +19 -109
- package/dist/core/types.js +13 -0
- package/dist/factories/providerFactory.js +4 -1
- package/dist/factories/providerRegistry.js +2 -2
- package/dist/index.d.ts +2 -1
- package/dist/lib/config/configManager.js +5 -2
- 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/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/factory.js +77 -4
- 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 +19 -109
- package/dist/lib/core/types.js +13 -0
- package/dist/lib/factories/providerFactory.js +4 -1
- package/dist/lib/factories/providerRegistry.js +2 -2
- package/dist/lib/index.d.ts +2 -1
- package/dist/lib/mcp/externalServerManager.js +14 -6
- package/dist/lib/mcp/factory.js +1 -1
- package/dist/lib/mcp/flexibleToolValidator.d.ts +50 -0
- package/dist/lib/mcp/flexibleToolValidator.js +161 -0
- 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.d.ts +2 -2
- package/dist/lib/mcp/toolRegistry.js +29 -54
- 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 +118 -0
- package/dist/lib/neurolink.js +814 -952
- package/dist/lib/providers/amazonBedrock.d.ts +47 -6
- package/dist/lib/providers/amazonBedrock.js +282 -23
- 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/aws/credentialProvider.d.ts +58 -0
- package/dist/lib/providers/aws/credentialProvider.js +267 -0
- package/dist/lib/providers/aws/credentialTester.d.ts +49 -0
- package/dist/lib/providers/aws/credentialTester.js +394 -0
- 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.d.ts +23 -0
- package/dist/lib/proxy/awsProxyIntegration.js +285 -0
- package/dist/lib/proxy/proxyFetch.d.ts +9 -5
- package/dist/lib/proxy/proxyFetch.js +232 -98
- package/dist/lib/proxy/utils/noProxyUtils.d.ts +39 -0
- package/dist/lib/proxy/utils/noProxyUtils.js +149 -0
- 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/generateTypes.d.ts +4 -6
- package/dist/lib/types/providers.d.ts +124 -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/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/providerConfig.d.ts +1 -0
- package/dist/lib/utils/providerConfig.js +2 -1
- package/dist/lib/utils/providerHealth.d.ts +48 -0
- package/dist/lib/utils/providerHealth.js +221 -158
- package/dist/lib/utils/providerUtils.js +2 -2
- package/dist/lib/utils/timeout.js +8 -3
- package/dist/mcp/externalServerManager.js +14 -6
- package/dist/mcp/factory.js +1 -1
- package/dist/mcp/flexibleToolValidator.d.ts +50 -0
- package/dist/mcp/flexibleToolValidator.js +161 -0
- 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.d.ts +2 -2
- package/dist/mcp/toolRegistry.js +29 -54
- 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 +118 -0
- package/dist/neurolink.js +814 -952
- package/dist/providers/amazonBedrock.d.ts +47 -6
- package/dist/providers/amazonBedrock.js +282 -23
- 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/aws/credentialProvider.d.ts +58 -0
- package/dist/providers/aws/credentialProvider.js +267 -0
- package/dist/providers/aws/credentialTester.d.ts +49 -0
- package/dist/providers/aws/credentialTester.js +394 -0
- 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.d.ts +23 -0
- package/dist/proxy/awsProxyIntegration.js +285 -0
- package/dist/proxy/proxyFetch.d.ts +9 -5
- package/dist/proxy/proxyFetch.js +232 -98
- package/dist/proxy/utils/noProxyUtils.d.ts +39 -0
- package/dist/proxy/utils/noProxyUtils.js +149 -0
- 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/generateTypes.d.ts +4 -6
- package/dist/types/providers.d.ts +124 -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/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/providerConfig.d.ts +1 -0
- package/dist/utils/providerConfig.js +2 -1
- package/dist/utils/providerHealth.d.ts +48 -0
- package/dist/utils/providerHealth.js +221 -158
- package/dist/utils/providerUtils.js +2 -2
- package/dist/utils/timeout.js +8 -3
- package/package.json +5 -1
|
@@ -16,6 +16,55 @@ export class OllamaUtils {
|
|
|
16
16
|
};
|
|
17
17
|
return spawnSync(command, args, defaultOptions);
|
|
18
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Check if Ollama command line is available
|
|
21
|
+
*/
|
|
22
|
+
static isOllamaCommandReady() {
|
|
23
|
+
const cmdCheck = this.safeSpawn("ollama", ["list"]);
|
|
24
|
+
return !cmdCheck.error && cmdCheck.status === 0;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Validate HTTP API response from Ollama
|
|
28
|
+
*/
|
|
29
|
+
static validateApiResponse(output) {
|
|
30
|
+
const httpCodeMatch = output.match(/(\d{3})$/);
|
|
31
|
+
if (!httpCodeMatch || httpCodeMatch[1] !== "200") {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
// Try to parse the JSON response (excluding HTTP code)
|
|
35
|
+
const jsonResponse = output.replace(/\d{3}$/, "");
|
|
36
|
+
try {
|
|
37
|
+
const parsedResponse = JSON.parse(jsonResponse);
|
|
38
|
+
return parsedResponse && typeof parsedResponse === "object";
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
// JSON parsing failed, but HTTP 200 is good enough
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Check if Ollama HTTP API is ready
|
|
47
|
+
*/
|
|
48
|
+
static isOllamaApiReady() {
|
|
49
|
+
try {
|
|
50
|
+
const apiCheck = this.safeSpawn("curl", [
|
|
51
|
+
"-s",
|
|
52
|
+
"--max-time",
|
|
53
|
+
"3",
|
|
54
|
+
"--fail", // Fail on HTTP error codes
|
|
55
|
+
"-w",
|
|
56
|
+
"%{http_code}",
|
|
57
|
+
"http://localhost:11434/api/tags",
|
|
58
|
+
]);
|
|
59
|
+
if (apiCheck.error || apiCheck.status !== 0 || !apiCheck.stdout.trim()) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
return this.validateApiResponse(apiCheck.stdout.trim());
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
19
68
|
/**
|
|
20
69
|
* Wait for Ollama service to become ready with exponential backoff
|
|
21
70
|
*/
|
|
@@ -23,49 +72,16 @@ export class OllamaUtils {
|
|
|
23
72
|
let delay = initialDelay;
|
|
24
73
|
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
25
74
|
try {
|
|
26
|
-
// Try
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"--max-time",
|
|
34
|
-
"3",
|
|
35
|
-
"--fail", // Fail on HTTP error codes
|
|
36
|
-
"-w",
|
|
37
|
-
"%{http_code}",
|
|
38
|
-
"http://localhost:11434/api/tags",
|
|
39
|
-
]);
|
|
40
|
-
if (!apiCheck.error &&
|
|
41
|
-
apiCheck.status === 0 &&
|
|
42
|
-
apiCheck.stdout.trim()) {
|
|
43
|
-
// Validate that we get a proper HTTP 200 response and JSON structure
|
|
44
|
-
const output = apiCheck.stdout.trim();
|
|
45
|
-
const httpCodeMatch = output.match(/(\d{3})$/);
|
|
46
|
-
if (httpCodeMatch && httpCodeMatch[1] === "200") {
|
|
47
|
-
// Try to parse the JSON response (excluding HTTP code)
|
|
48
|
-
const jsonResponse = output.replace(/\d{3}$/, "");
|
|
49
|
-
try {
|
|
50
|
-
const parsedResponse = JSON.parse(jsonResponse);
|
|
51
|
-
// Verify it has the expected structure
|
|
52
|
-
if (parsedResponse && typeof parsedResponse === "object") {
|
|
53
|
-
return true; // Strong verification passed
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
catch {
|
|
57
|
-
// JSON parsing failed, but HTTP 200 is good enough
|
|
58
|
-
return true;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
catch {
|
|
64
|
-
// If curl fails, fall back to command check only
|
|
65
|
-
return true;
|
|
66
|
-
}
|
|
67
|
-
return true; // Command check passed
|
|
75
|
+
// Try command line check first
|
|
76
|
+
if (!this.isOllamaCommandReady()) {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
// If command check passes, verify HTTP API
|
|
80
|
+
if (this.isOllamaApiReady()) {
|
|
81
|
+
return true;
|
|
68
82
|
}
|
|
83
|
+
// Command check passed but API not ready, still consider ready
|
|
84
|
+
return true;
|
|
69
85
|
}
|
|
70
86
|
catch {
|
|
71
87
|
// Service not ready yet
|
|
@@ -6,6 +6,7 @@ import { promises as fs } from "fs";
|
|
|
6
6
|
import path from "path";
|
|
7
7
|
import crypto from "crypto";
|
|
8
8
|
import { logger } from "../utils/logger.js";
|
|
9
|
+
import { DEFAULT_CONFIG } from "./types.js";
|
|
9
10
|
const { readFile, writeFile, readdir, mkdir, unlink, access } = fs;
|
|
10
11
|
/**
|
|
11
12
|
* Enhanced Config Manager with automatic backup/restore capabilities
|
|
@@ -237,7 +238,6 @@ export default ${JSON.stringify(currentConfig, null, 2)};`;
|
|
|
237
238
|
* Generate default configuration
|
|
238
239
|
*/
|
|
239
240
|
async generateDefaultConfig() {
|
|
240
|
-
const { DEFAULT_CONFIG } = await import("./types.js");
|
|
241
241
|
return {
|
|
242
242
|
...DEFAULT_CONFIG,
|
|
243
243
|
lastUpdated: Date.now(),
|
|
@@ -266,7 +266,10 @@ export default ${JSON.stringify(currentConfig, null, 2)};`;
|
|
|
266
266
|
throw new Error("Invalid config file format");
|
|
267
267
|
}
|
|
268
268
|
catch (error) {
|
|
269
|
-
logger.info("Config file not found, generating default..."
|
|
269
|
+
logger.info("Config file not found or invalid, generating default...", {
|
|
270
|
+
error: error instanceof Error ? error.message : String(error),
|
|
271
|
+
configPath: this.configPath,
|
|
272
|
+
});
|
|
270
273
|
return await this.generateDefaultConfig();
|
|
271
274
|
}
|
|
272
275
|
}
|
package/dist/core/analytics.d.ts
CHANGED
|
@@ -4,30 +4,8 @@
|
|
|
4
4
|
* Provides lightweight analytics tracking for AI provider usage,
|
|
5
5
|
* including tokens, costs, performance metrics, and custom context.
|
|
6
6
|
*/
|
|
7
|
-
import type {
|
|
8
|
-
export
|
|
9
|
-
provider: string;
|
|
10
|
-
model: string;
|
|
11
|
-
tokens: {
|
|
12
|
-
input: number;
|
|
13
|
-
output: number;
|
|
14
|
-
total: number;
|
|
15
|
-
};
|
|
16
|
-
cost?: number;
|
|
17
|
-
responseTime: number;
|
|
18
|
-
context?: Record<string, JsonValue>;
|
|
19
|
-
timestamp: string;
|
|
20
|
-
evaluation?: {
|
|
21
|
-
relevanceScore: number;
|
|
22
|
-
accuracyScore: number;
|
|
23
|
-
completenessScore: number;
|
|
24
|
-
overall: number;
|
|
25
|
-
evaluationProvider?: string;
|
|
26
|
-
evaluationTime?: number;
|
|
27
|
-
evaluationAttempt?: number;
|
|
28
|
-
};
|
|
29
|
-
costDetails?: UnknownRecord;
|
|
30
|
-
}
|
|
7
|
+
import type { AnalyticsData } from "../types/providers.js";
|
|
8
|
+
export type { AnalyticsData, TokenUsage } from "../types/providers.js";
|
|
31
9
|
/**
|
|
32
10
|
* Create analytics data structure from AI response
|
|
33
11
|
*/
|
package/dist/core/analytics.js
CHANGED
|
@@ -19,9 +19,9 @@ export function createAnalytics(provider, model, result, responseTime, context)
|
|
|
19
19
|
const analytics = {
|
|
20
20
|
provider,
|
|
21
21
|
model,
|
|
22
|
-
tokens,
|
|
22
|
+
tokenUsage: tokens,
|
|
23
23
|
cost,
|
|
24
|
-
responseTime,
|
|
24
|
+
requestDuration: responseTime,
|
|
25
25
|
context: context,
|
|
26
26
|
timestamp: new Date().toISOString(),
|
|
27
27
|
};
|
|
@@ -40,8 +40,8 @@ export function createAnalytics(provider, model, result, responseTime, context)
|
|
|
40
40
|
return {
|
|
41
41
|
provider,
|
|
42
42
|
model,
|
|
43
|
-
|
|
44
|
-
responseTime,
|
|
43
|
+
tokenUsage: { input: 0, output: 0, total: 0 },
|
|
44
|
+
requestDuration: responseTime,
|
|
45
45
|
context: context,
|
|
46
46
|
timestamp: new Date().toISOString(),
|
|
47
47
|
};
|
|
@@ -56,14 +56,11 @@ function extractTokenUsage(result) {
|
|
|
56
56
|
typeof result.usage === "object" &&
|
|
57
57
|
result.usage !== null) {
|
|
58
58
|
const usage = result.usage;
|
|
59
|
-
// Try BaseProvider normalized format first (
|
|
60
|
-
if (typeof usage.
|
|
61
|
-
typeof usage.
|
|
62
|
-
const
|
|
63
|
-
const
|
|
64
|
-
const total = typeof usage.totalTokens === "number"
|
|
65
|
-
? usage.totalTokens
|
|
66
|
-
: input + output;
|
|
59
|
+
// Try BaseProvider normalized format first (input/output/total)
|
|
60
|
+
if (typeof usage.input === "number" || typeof usage.output === "number") {
|
|
61
|
+
const input = typeof usage.input === "number" ? usage.input : 0;
|
|
62
|
+
const output = typeof usage.output === "number" ? usage.output : 0;
|
|
63
|
+
const total = typeof usage.total === "number" ? usage.total : input + output;
|
|
67
64
|
return { input, output, total };
|
|
68
65
|
}
|
|
69
66
|
// Try OpenAI/Mistral format (promptTokens/completionTokens)
|
|
@@ -71,14 +68,12 @@ function extractTokenUsage(result) {
|
|
|
71
68
|
typeof usage.completionTokens === "number") {
|
|
72
69
|
const input = typeof usage.promptTokens === "number" ? usage.promptTokens : 0;
|
|
73
70
|
const output = typeof usage.completionTokens === "number" ? usage.completionTokens : 0;
|
|
74
|
-
const total = typeof usage.
|
|
75
|
-
? usage.totalTokens
|
|
76
|
-
: input + output;
|
|
71
|
+
const total = typeof usage.total === "number" ? usage.total : input + output;
|
|
77
72
|
return { input, output, total };
|
|
78
73
|
}
|
|
79
74
|
// Handle total-only case
|
|
80
|
-
if (typeof usage.
|
|
81
|
-
return { input: 0, output: 0, total: usage.
|
|
75
|
+
if (typeof usage.total === "number") {
|
|
76
|
+
return { input: 0, output: 0, total: usage.total };
|
|
82
77
|
}
|
|
83
78
|
}
|
|
84
79
|
// Fallback for edge cases
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ValidationSchema } from "../types/typeAliases.js";
|
|
2
2
|
import type { Tool, LanguageModelV1 } from "ai";
|
|
3
|
-
import type { AIProvider, TextGenerationOptions, TextGenerationResult, EnhancedGenerateResult, AnalyticsData, AIProviderName
|
|
3
|
+
import type { AIProvider, TextGenerationOptions, TextGenerationResult, EnhancedGenerateResult, AnalyticsData, AIProviderName } from "../core/types.js";
|
|
4
|
+
import type { EvaluationData } from "../index.js";
|
|
4
5
|
import type { StreamOptions, StreamResult } from "../types/streamTypes.js";
|
|
5
6
|
import type { UnknownRecord } from "../types/common.js";
|
|
6
7
|
import type { NeuroLink } from "../neurolink.js";
|
|
@@ -76,6 +77,34 @@ export declare abstract class BaseProvider implements AIProvider {
|
|
|
76
77
|
* Determine if middleware should be skipped for this request
|
|
77
78
|
*/
|
|
78
79
|
private shouldSkipMiddleware;
|
|
80
|
+
/**
|
|
81
|
+
* Check if a schema is a Zod schema
|
|
82
|
+
*/
|
|
83
|
+
private isZodSchema;
|
|
84
|
+
/**
|
|
85
|
+
* Convert tool execution result from MCP format to standard format
|
|
86
|
+
*/
|
|
87
|
+
private convertToolResult;
|
|
88
|
+
/**
|
|
89
|
+
* Create a custom tool from tool definition
|
|
90
|
+
*/
|
|
91
|
+
private createCustomToolFromDefinition;
|
|
92
|
+
/**
|
|
93
|
+
* Process custom tools from setupToolExecutor
|
|
94
|
+
*/
|
|
95
|
+
private processCustomTools;
|
|
96
|
+
/**
|
|
97
|
+
* Create an external MCP tool
|
|
98
|
+
*/
|
|
99
|
+
private createExternalMCPTool;
|
|
100
|
+
/**
|
|
101
|
+
* Process external MCP tools
|
|
102
|
+
*/
|
|
103
|
+
private processExternalMCPTools;
|
|
104
|
+
/**
|
|
105
|
+
* Process MCP tools integration
|
|
106
|
+
*/
|
|
107
|
+
private processMCPTools;
|
|
79
108
|
/**
|
|
80
109
|
* Get all available tools - direct tools are ALWAYS available
|
|
81
110
|
* MCP tools are added when available (without blocking)
|