@juspay/neurolink 6.0.0 → 6.2.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 +14 -3
- package/dist/cli/commands/config.d.ts +13 -13
- package/dist/cli/index.js +3 -9
- package/dist/core/analytics.d.ts +11 -1
- package/dist/core/analytics.js +2 -2
- package/dist/core/base-provider.js +4 -18
- package/dist/core/dynamic-models.d.ts +8 -8
- package/dist/core/factory.js +3 -11
- package/dist/index.d.ts +2 -4
- package/dist/index.js +2 -11
- package/dist/lib/core/analytics.d.ts +11 -1
- package/dist/lib/core/analytics.js +2 -2
- package/dist/lib/core/base-provider.js +4 -18
- package/dist/lib/core/dynamic-models.d.ts +8 -8
- package/dist/lib/core/factory.js +3 -11
- package/dist/lib/index.d.ts +2 -4
- package/dist/lib/index.js +2 -11
- package/dist/lib/mcp/factory.d.ts +1 -1
- package/dist/lib/mcp/index.d.ts +7 -19
- package/dist/lib/mcp/index.js +15 -56
- package/dist/lib/neurolink.d.ts +1 -9
- package/dist/lib/neurolink.js +21 -70
- package/dist/lib/providers/amazon-bedrock.js +5 -16
- package/dist/lib/providers/anthropic-baseprovider.js +3 -21
- package/dist/lib/providers/anthropic.js +4 -7
- package/dist/lib/providers/azure-openai.js +4 -2
- package/dist/lib/providers/google-vertex.js +5 -9
- package/dist/lib/providers/huggingFace.js +5 -10
- package/dist/lib/providers/mistral.js +5 -8
- package/dist/lib/providers/openAI.js +4 -7
- package/dist/lib/utils/providerConfig.d.ts +117 -0
- package/dist/lib/utils/providerConfig.js +353 -0
- package/dist/lib/utils/providerUtils.d.ts +2 -1
- package/dist/lib/utils/providerUtils.js +53 -36
- package/dist/lib/utils/timeout.d.ts +72 -1
- package/dist/lib/utils/timeout.js +203 -2
- package/dist/mcp/factory.d.ts +1 -1
- package/dist/mcp/index.d.ts +7 -19
- package/dist/mcp/index.js +15 -56
- package/dist/neurolink.d.ts +1 -9
- package/dist/neurolink.js +21 -70
- package/dist/providers/amazon-bedrock.js +5 -16
- package/dist/providers/anthropic-baseprovider.js +3 -21
- package/dist/providers/anthropic.js +4 -7
- package/dist/providers/azure-openai.js +4 -2
- package/dist/providers/google-vertex.js +5 -9
- package/dist/providers/huggingFace.js +5 -10
- package/dist/providers/mistral.js +5 -8
- package/dist/providers/openAI.js +4 -7
- package/dist/utils/providerConfig.d.ts +117 -0
- package/dist/utils/providerConfig.js +353 -0
- package/dist/utils/providerUtils.d.ts +2 -1
- package/dist/utils/providerUtils.js +53 -36
- package/dist/utils/timeout.d.ts +72 -1
- package/dist/utils/timeout.js +203 -2
- package/package.json +2 -1
- package/dist/chat/client-utils.d.ts +0 -95
- package/dist/chat/client-utils.js +0 -315
- package/dist/chat/index.d.ts +0 -24
- package/dist/chat/index.js +0 -33
- package/dist/chat/session-storage.d.ts +0 -77
- package/dist/chat/session-storage.js +0 -233
- package/dist/chat/session.d.ts +0 -96
- package/dist/chat/session.js +0 -257
- package/dist/chat/sse-handler.d.ts +0 -49
- package/dist/chat/sse-handler.js +0 -259
- package/dist/chat/types.d.ts +0 -74
- package/dist/chat/types.js +0 -5
- package/dist/chat/websocket-chat-handler.d.ts +0 -37
- package/dist/chat/websocket-chat-handler.js +0 -262
- package/dist/cli/commands/mcp.d.ts +0 -20
- package/dist/cli/commands/mcp.js +0 -1272
- package/dist/core/defaults.d.ts +0 -19
- package/dist/core/defaults.js +0 -29
- package/dist/core/evaluation-config.d.ts +0 -29
- package/dist/core/evaluation-config.js +0 -144
- package/dist/factories/compatibility-factory.d.ts +0 -35
- package/dist/factories/compatibility-factory.js +0 -71
- package/dist/factories/provider-generate-factory.d.ts +0 -20
- package/dist/factories/provider-generate-factory.js +0 -93
- package/dist/lib/chat/client-utils.d.ts +0 -95
- package/dist/lib/chat/client-utils.js +0 -315
- package/dist/lib/chat/index.d.ts +0 -24
- package/dist/lib/chat/index.js +0 -33
- package/dist/lib/chat/session-storage.d.ts +0 -77
- package/dist/lib/chat/session-storage.js +0 -233
- package/dist/lib/chat/session.d.ts +0 -96
- package/dist/lib/chat/session.js +0 -257
- package/dist/lib/chat/sse-handler.d.ts +0 -49
- package/dist/lib/chat/sse-handler.js +0 -259
- package/dist/lib/chat/types.d.ts +0 -74
- package/dist/lib/chat/types.js +0 -5
- package/dist/lib/chat/websocket-chat-handler.d.ts +0 -37
- package/dist/lib/chat/websocket-chat-handler.js +0 -262
- package/dist/lib/core/defaults.d.ts +0 -19
- package/dist/lib/core/defaults.js +0 -29
- package/dist/lib/core/evaluation-config.d.ts +0 -29
- package/dist/lib/core/evaluation-config.js +0 -144
- package/dist/lib/factories/compatibility-factory.d.ts +0 -35
- package/dist/lib/factories/compatibility-factory.js +0 -71
- package/dist/lib/factories/provider-generate-factory.d.ts +0 -20
- package/dist/lib/factories/provider-generate-factory.js +0 -93
- package/dist/lib/mcp/adapters/plugin-bridge.d.ts +0 -40
- package/dist/lib/mcp/adapters/plugin-bridge.js +0 -89
- package/dist/lib/mcp/auto-discovery.d.ts +0 -62
- package/dist/lib/mcp/auto-discovery.js +0 -149
- package/dist/lib/mcp/client.d.ts +0 -68
- package/dist/lib/mcp/client.js +0 -248
- package/dist/lib/mcp/config.d.ts +0 -31
- package/dist/lib/mcp/config.js +0 -99
- package/dist/lib/mcp/context-manager.d.ts +0 -171
- package/dist/lib/mcp/context-manager.js +0 -362
- package/dist/lib/mcp/contracts/mcp-contract.d.ts +0 -169
- package/dist/lib/mcp/contracts/mcp-contract.js +0 -58
- package/dist/lib/mcp/core/plugin-manager.d.ts +0 -46
- package/dist/lib/mcp/core/plugin-manager.js +0 -110
- package/dist/lib/mcp/demo/plugin-demo.d.ts +0 -20
- package/dist/lib/mcp/demo/plugin-demo.js +0 -118
- package/dist/lib/mcp/dynamic-chain-executor.d.ts +0 -225
- package/dist/lib/mcp/dynamic-chain-executor.js +0 -489
- package/dist/lib/mcp/dynamic-orchestrator.d.ts +0 -115
- package/dist/lib/mcp/dynamic-orchestrator.js +0 -351
- package/dist/lib/mcp/ecosystem.d.ts +0 -75
- package/dist/lib/mcp/ecosystem.js +0 -161
- package/dist/lib/mcp/error-manager.d.ts +0 -254
- package/dist/lib/mcp/error-manager.js +0 -501
- package/dist/lib/mcp/error-recovery.d.ts +0 -159
- package/dist/lib/mcp/error-recovery.js +0 -405
- package/dist/lib/mcp/external-client.d.ts +0 -88
- package/dist/lib/mcp/external-client.js +0 -331
- package/dist/lib/mcp/external-manager.d.ts +0 -112
- package/dist/lib/mcp/external-manager.js +0 -308
- package/dist/lib/mcp/function-calling.d.ts +0 -65
- package/dist/lib/mcp/function-calling.js +0 -642
- package/dist/lib/mcp/health-monitor.d.ts +0 -257
- package/dist/lib/mcp/health-monitor.js +0 -630
- package/dist/lib/mcp/initialize-tools.d.ts +0 -29
- package/dist/lib/mcp/initialize-tools.js +0 -261
- package/dist/lib/mcp/initialize.d.ts +0 -18
- package/dist/lib/mcp/initialize.js +0 -62
- package/dist/lib/mcp/manager.d.ts +0 -68
- package/dist/lib/mcp/manager.js +0 -176
- package/dist/lib/mcp/neurolink-mcp-client.d.ts +0 -97
- package/dist/lib/mcp/neurolink-mcp-client.js +0 -462
- package/dist/lib/mcp/orchestrator.d.ts +0 -302
- package/dist/lib/mcp/orchestrator.js +0 -703
- package/dist/lib/mcp/plugin-manager.d.ts +0 -98
- package/dist/lib/mcp/plugin-manager.js +0 -296
- package/dist/lib/mcp/plugins/core/filesystem-mcp.d.ts +0 -36
- package/dist/lib/mcp/plugins/core/filesystem-mcp.js +0 -142
- package/dist/lib/mcp/plugins/filesystem-mcp.d.ts +0 -37
- package/dist/lib/mcp/plugins/filesystem-mcp.js +0 -54
- package/dist/lib/mcp/security-manager.d.ts +0 -87
- package/dist/lib/mcp/security-manager.js +0 -344
- package/dist/lib/mcp/semaphore-manager.d.ts +0 -137
- package/dist/lib/mcp/semaphore-manager.js +0 -329
- package/dist/lib/mcp/session-manager.d.ts +0 -187
- package/dist/lib/mcp/session-manager.js +0 -400
- package/dist/lib/mcp/session-persistence.d.ts +0 -93
- package/dist/lib/mcp/session-persistence.js +0 -301
- package/dist/lib/mcp/tool-integration.d.ts +0 -58
- package/dist/lib/mcp/tool-integration.js +0 -203
- package/dist/lib/mcp/transport-manager.d.ts +0 -154
- package/dist/lib/mcp/transport-manager.js +0 -334
- package/dist/lib/mcp/unified-mcp.d.ts +0 -133
- package/dist/lib/mcp/unified-mcp.js +0 -251
- package/dist/lib/mcp/unified-registry.d.ts +0 -165
- package/dist/lib/mcp/unified-registry.js +0 -538
- package/dist/lib/providers/analytics-helper.d.ts +0 -38
- package/dist/lib/providers/analytics-helper.js +0 -216
- package/dist/lib/providers/function-calling-provider.d.ts +0 -142
- package/dist/lib/providers/function-calling-provider.js +0 -630
- package/dist/lib/providers/mcp-provider.d.ts +0 -75
- package/dist/lib/providers/mcp-provider.js +0 -283
- package/dist/lib/providers/timeout-wrapper.d.ts +0 -40
- package/dist/lib/providers/timeout-wrapper.js +0 -100
- package/dist/lib/sdk/tool-extension.d.ts +0 -181
- package/dist/lib/sdk/tool-extension.js +0 -284
- package/dist/lib/services/streaming/streaming-manager.d.ts +0 -29
- package/dist/lib/services/streaming/streaming-manager.js +0 -245
- package/dist/lib/services/types.d.ts +0 -156
- package/dist/lib/services/types.js +0 -2
- package/dist/lib/services/websocket/websocket-server.d.ts +0 -34
- package/dist/lib/services/websocket/websocket-server.js +0 -305
- package/dist/lib/utils/provider-validation.d.ts +0 -36
- package/dist/lib/utils/provider-validation.js +0 -625
- package/dist/lib/utils/providerUtils-fixed.d.ts +0 -8
- package/dist/lib/utils/providerUtils-fixed.js +0 -94
- package/dist/lib/utils/streaming-utils.d.ts +0 -79
- package/dist/lib/utils/streaming-utils.js +0 -198
- package/dist/lib/utils/timeout-manager.d.ts +0 -75
- package/dist/lib/utils/timeout-manager.js +0 -244
- package/dist/mcp/adapters/plugin-bridge.d.ts +0 -40
- package/dist/mcp/adapters/plugin-bridge.js +0 -89
- package/dist/mcp/auto-discovery.d.ts +0 -62
- package/dist/mcp/auto-discovery.js +0 -149
- package/dist/mcp/client.d.ts +0 -68
- package/dist/mcp/client.js +0 -248
- package/dist/mcp/config.d.ts +0 -31
- package/dist/mcp/config.js +0 -99
- package/dist/mcp/context-manager.d.ts +0 -171
- package/dist/mcp/context-manager.js +0 -362
- package/dist/mcp/contracts/mcp-contract.d.ts +0 -169
- package/dist/mcp/contracts/mcp-contract.js +0 -58
- package/dist/mcp/core/plugin-manager.d.ts +0 -46
- package/dist/mcp/core/plugin-manager.js +0 -110
- package/dist/mcp/demo/plugin-demo.d.ts +0 -20
- package/dist/mcp/demo/plugin-demo.js +0 -118
- package/dist/mcp/dynamic-chain-executor.d.ts +0 -225
- package/dist/mcp/dynamic-chain-executor.js +0 -489
- package/dist/mcp/dynamic-orchestrator.d.ts +0 -115
- package/dist/mcp/dynamic-orchestrator.js +0 -351
- package/dist/mcp/ecosystem.d.ts +0 -75
- package/dist/mcp/ecosystem.js +0 -162
- package/dist/mcp/error-manager.d.ts +0 -254
- package/dist/mcp/error-manager.js +0 -501
- package/dist/mcp/error-recovery.d.ts +0 -159
- package/dist/mcp/error-recovery.js +0 -405
- package/dist/mcp/external-client.d.ts +0 -88
- package/dist/mcp/external-client.js +0 -331
- package/dist/mcp/external-manager.d.ts +0 -112
- package/dist/mcp/external-manager.js +0 -308
- package/dist/mcp/function-calling.d.ts +0 -65
- package/dist/mcp/function-calling.js +0 -642
- package/dist/mcp/health-monitor.d.ts +0 -257
- package/dist/mcp/health-monitor.js +0 -630
- package/dist/mcp/initialize-tools.d.ts +0 -29
- package/dist/mcp/initialize-tools.js +0 -262
- package/dist/mcp/initialize.d.ts +0 -18
- package/dist/mcp/initialize.js +0 -62
- package/dist/mcp/manager.d.ts +0 -68
- package/dist/mcp/manager.js +0 -176
- package/dist/mcp/neurolink-mcp-client.d.ts +0 -97
- package/dist/mcp/neurolink-mcp-client.js +0 -462
- package/dist/mcp/orchestrator.d.ts +0 -302
- package/dist/mcp/orchestrator.js +0 -703
- package/dist/mcp/plugin-manager.d.ts +0 -98
- package/dist/mcp/plugin-manager.js +0 -297
- package/dist/mcp/plugins/core/filesystem-mcp.d.ts +0 -36
- package/dist/mcp/plugins/core/filesystem-mcp.js +0 -142
- package/dist/mcp/plugins/core/neurolink-mcp.json +0 -17
- package/dist/mcp/plugins/filesystem-mcp.d.ts +0 -37
- package/dist/mcp/plugins/filesystem-mcp.js +0 -54
- package/dist/mcp/security-manager.d.ts +0 -87
- package/dist/mcp/security-manager.js +0 -344
- package/dist/mcp/semaphore-manager.d.ts +0 -137
- package/dist/mcp/semaphore-manager.js +0 -329
- package/dist/mcp/session-manager.d.ts +0 -187
- package/dist/mcp/session-manager.js +0 -400
- package/dist/mcp/session-persistence.d.ts +0 -93
- package/dist/mcp/session-persistence.js +0 -302
- package/dist/mcp/tool-integration.d.ts +0 -58
- package/dist/mcp/tool-integration.js +0 -203
- package/dist/mcp/transport-manager.d.ts +0 -154
- package/dist/mcp/transport-manager.js +0 -335
- package/dist/mcp/unified-mcp.d.ts +0 -133
- package/dist/mcp/unified-mcp.js +0 -251
- package/dist/mcp/unified-registry.d.ts +0 -165
- package/dist/mcp/unified-registry.js +0 -539
- package/dist/providers/analytics-helper.d.ts +0 -38
- package/dist/providers/analytics-helper.js +0 -216
- package/dist/providers/function-calling-provider.d.ts +0 -142
- package/dist/providers/function-calling-provider.js +0 -630
- package/dist/providers/mcp-provider.d.ts +0 -75
- package/dist/providers/mcp-provider.js +0 -283
- package/dist/providers/timeout-wrapper.d.ts +0 -40
- package/dist/providers/timeout-wrapper.js +0 -100
- package/dist/sdk/tool-extension.d.ts +0 -181
- package/dist/sdk/tool-extension.js +0 -284
- package/dist/services/streaming/streaming-manager.d.ts +0 -29
- package/dist/services/streaming/streaming-manager.js +0 -245
- package/dist/services/types.d.ts +0 -156
- package/dist/services/types.js +0 -2
- package/dist/services/websocket/websocket-server.d.ts +0 -34
- package/dist/services/websocket/websocket-server.js +0 -306
- package/dist/utils/provider-validation.d.ts +0 -36
- package/dist/utils/provider-validation.js +0 -625
- package/dist/utils/providerUtils-fixed.d.ts +0 -8
- package/dist/utils/providerUtils-fixed.js +0 -94
- package/dist/utils/streaming-utils.d.ts +0 -79
- package/dist/utils/streaming-utils.js +0 -198
- package/dist/utils/timeout-manager.d.ts +0 -75
- package/dist/utils/timeout-manager.js +0 -244
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Enhanced Analytics Helper for All Providers
|
|
3
|
-
* Ensures consistent analytics data format across providers
|
|
4
|
-
* Integrates with Universal Evaluation System
|
|
5
|
-
*/
|
|
6
|
-
// Type guard for checking if an unknown value is a number
|
|
7
|
-
function isNumber(value) {
|
|
8
|
-
return typeof value === "number" && !isNaN(value);
|
|
9
|
-
}
|
|
10
|
-
// Type guard for checking if an unknown value is an object
|
|
11
|
-
function isRecord(value) {
|
|
12
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Create standardized analytics data from provider response
|
|
16
|
-
*/
|
|
17
|
-
export function createAnalytics(provider, model, result, responseTime, context) {
|
|
18
|
-
// Handle different token usage formats across providers
|
|
19
|
-
const tokenUsage = result?.usage || {};
|
|
20
|
-
// Standardize token field names across providers
|
|
21
|
-
const inputTokens = (typeof tokenUsage.promptTokens === "number"
|
|
22
|
-
? tokenUsage.promptTokens
|
|
23
|
-
: 0) ||
|
|
24
|
-
(typeof tokenUsage.input_tokens === "number"
|
|
25
|
-
? tokenUsage.input_tokens
|
|
26
|
-
: 0) ||
|
|
27
|
-
(typeof tokenUsage.inputTokens === "number" ? tokenUsage.inputTokens : 0) ||
|
|
28
|
-
0;
|
|
29
|
-
const outputTokens = (typeof tokenUsage.completionTokens === "number"
|
|
30
|
-
? tokenUsage.completionTokens
|
|
31
|
-
: 0) ||
|
|
32
|
-
(typeof tokenUsage.output_tokens === "number"
|
|
33
|
-
? tokenUsage.output_tokens
|
|
34
|
-
: 0) ||
|
|
35
|
-
(typeof tokenUsage.outputTokens === "number"
|
|
36
|
-
? tokenUsage.outputTokens
|
|
37
|
-
: 0) ||
|
|
38
|
-
0;
|
|
39
|
-
const totalTokens = (typeof tokenUsage.totalTokens === "number" ? tokenUsage.totalTokens : 0) ||
|
|
40
|
-
(typeof tokenUsage.total_tokens === "number"
|
|
41
|
-
? tokenUsage.total_tokens
|
|
42
|
-
: 0) ||
|
|
43
|
-
inputTokens + outputTokens ||
|
|
44
|
-
0;
|
|
45
|
-
// Simple cost estimation for synchronous use
|
|
46
|
-
const estimatedCost = totalTokens > 0 ? totalTokens * 0.00001 : 0;
|
|
47
|
-
return {
|
|
48
|
-
provider,
|
|
49
|
-
model,
|
|
50
|
-
tokens: {
|
|
51
|
-
input: inputTokens,
|
|
52
|
-
output: outputTokens,
|
|
53
|
-
total: totalTokens,
|
|
54
|
-
},
|
|
55
|
-
cost: estimatedCost,
|
|
56
|
-
responseTime,
|
|
57
|
-
timestamp: new Date().toISOString(),
|
|
58
|
-
context: context,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Create enhanced analytics data with accurate cost calculations (async version)
|
|
63
|
-
*/
|
|
64
|
-
export async function createEnhancedAnalytics(provider, model, result, responseTime, context) {
|
|
65
|
-
// Handle different token usage formats across providers
|
|
66
|
-
const tokenUsage = result?.usage || {};
|
|
67
|
-
// Standardize token field names across providers
|
|
68
|
-
const inputTokens = (typeof tokenUsage.promptTokens === "number"
|
|
69
|
-
? tokenUsage.promptTokens
|
|
70
|
-
: 0) ||
|
|
71
|
-
(typeof tokenUsage.input_tokens === "number"
|
|
72
|
-
? tokenUsage.input_tokens
|
|
73
|
-
: 0) ||
|
|
74
|
-
(typeof tokenUsage.inputTokens === "number" ? tokenUsage.inputTokens : 0) ||
|
|
75
|
-
0;
|
|
76
|
-
const outputTokens = (typeof tokenUsage.completionTokens === "number"
|
|
77
|
-
? tokenUsage.completionTokens
|
|
78
|
-
: 0) ||
|
|
79
|
-
(typeof tokenUsage.output_tokens === "number"
|
|
80
|
-
? tokenUsage.output_tokens
|
|
81
|
-
: 0) ||
|
|
82
|
-
(typeof tokenUsage.outputTokens === "number"
|
|
83
|
-
? tokenUsage.outputTokens
|
|
84
|
-
: 0) ||
|
|
85
|
-
0;
|
|
86
|
-
const totalTokens = (typeof tokenUsage.totalTokens === "number" ? tokenUsage.totalTokens : 0) ||
|
|
87
|
-
(typeof tokenUsage.total_tokens === "number"
|
|
88
|
-
? tokenUsage.total_tokens
|
|
89
|
-
: 0) ||
|
|
90
|
-
inputTokens + outputTokens ||
|
|
91
|
-
0;
|
|
92
|
-
// Enhanced cost calculation using provider configuration
|
|
93
|
-
const { costDetails, estimatedCost } = await calculateEnhancedCost(provider, inputTokens, outputTokens);
|
|
94
|
-
return {
|
|
95
|
-
provider,
|
|
96
|
-
model,
|
|
97
|
-
tokens: {
|
|
98
|
-
input: inputTokens,
|
|
99
|
-
output: outputTokens,
|
|
100
|
-
total: totalTokens,
|
|
101
|
-
},
|
|
102
|
-
cost: estimatedCost,
|
|
103
|
-
responseTime,
|
|
104
|
-
timestamp: new Date().toISOString(),
|
|
105
|
-
context: context,
|
|
106
|
-
costDetails,
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Calculate enhanced cost details using provider configurations
|
|
111
|
-
*/
|
|
112
|
-
export async function calculateEnhancedCost(provider, inputTokens, outputTokens) {
|
|
113
|
-
try {
|
|
114
|
-
// Import provider configuration dynamically
|
|
115
|
-
const { getProviderConfig } = await import("../core/evaluation-providers.js");
|
|
116
|
-
const providerConfig = getProviderConfig(provider);
|
|
117
|
-
if (!providerConfig?.costPerToken) {
|
|
118
|
-
// Fallback to rough estimation
|
|
119
|
-
const estimatedCost = (inputTokens + outputTokens) * 0.00001;
|
|
120
|
-
return {
|
|
121
|
-
costDetails: {
|
|
122
|
-
inputCost: inputTokens * 0.00001,
|
|
123
|
-
outputCost: outputTokens * 0.00001,
|
|
124
|
-
totalCost: estimatedCost,
|
|
125
|
-
currency: "USD",
|
|
126
|
-
},
|
|
127
|
-
estimatedCost,
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
// Use accurate provider costs
|
|
131
|
-
const inputCost = inputTokens * providerConfig.costPerToken.input;
|
|
132
|
-
const outputCost = outputTokens * providerConfig.costPerToken.output;
|
|
133
|
-
const totalCost = inputCost + outputCost;
|
|
134
|
-
return {
|
|
135
|
-
costDetails: {
|
|
136
|
-
inputCost,
|
|
137
|
-
outputCost,
|
|
138
|
-
totalCost,
|
|
139
|
-
currency: "USD",
|
|
140
|
-
},
|
|
141
|
-
estimatedCost: totalCost,
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
catch (error) {
|
|
145
|
-
// Fallback on error
|
|
146
|
-
const estimatedCost = (inputTokens + outputTokens) * 0.00001;
|
|
147
|
-
return {
|
|
148
|
-
costDetails: {
|
|
149
|
-
inputCost: inputTokens * 0.00001,
|
|
150
|
-
outputCost: outputTokens * 0.00001,
|
|
151
|
-
totalCost: estimatedCost,
|
|
152
|
-
currency: "USD",
|
|
153
|
-
},
|
|
154
|
-
estimatedCost,
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Enhance analytics with evaluation data
|
|
160
|
-
*/
|
|
161
|
-
export function enhanceAnalyticsWithEvaluation(analytics, evaluationResult) {
|
|
162
|
-
// Helper function to safely extract number values with fallback
|
|
163
|
-
const getNumberValue = (obj, ...keys) => {
|
|
164
|
-
for (const key of keys) {
|
|
165
|
-
const value = obj[key];
|
|
166
|
-
if (isNumber(value)) {
|
|
167
|
-
return value;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
return 1; // Default minimum score
|
|
171
|
-
};
|
|
172
|
-
// Helper function to safely extract evaluation config cost
|
|
173
|
-
const getEvaluationCost = (obj) => {
|
|
174
|
-
const evaluationConfig = obj.evaluationConfig;
|
|
175
|
-
if (isRecord(evaluationConfig)) {
|
|
176
|
-
const costEstimate = evaluationConfig.costEstimate;
|
|
177
|
-
return isNumber(costEstimate) ? costEstimate : 0;
|
|
178
|
-
}
|
|
179
|
-
return 0;
|
|
180
|
-
};
|
|
181
|
-
// Helper function to safely get existing total cost
|
|
182
|
-
const getExistingTotalCost = (costDetails) => {
|
|
183
|
-
if (!costDetails) {
|
|
184
|
-
return 0;
|
|
185
|
-
}
|
|
186
|
-
const totalCost = costDetails.totalCost;
|
|
187
|
-
return isNumber(totalCost) ? totalCost : 0;
|
|
188
|
-
};
|
|
189
|
-
const evaluationCost = getEvaluationCost(evaluationResult);
|
|
190
|
-
return {
|
|
191
|
-
...analytics,
|
|
192
|
-
evaluation: {
|
|
193
|
-
relevanceScore: getNumberValue(evaluationResult, "relevance", "relevanceScore"),
|
|
194
|
-
accuracyScore: getNumberValue(evaluationResult, "accuracy", "accuracyScore"),
|
|
195
|
-
completenessScore: getNumberValue(evaluationResult, "completeness", "completenessScore"),
|
|
196
|
-
overall: getNumberValue(evaluationResult, "overall"),
|
|
197
|
-
evaluationProvider: typeof evaluationResult.evaluationProvider === "string"
|
|
198
|
-
? evaluationResult.evaluationProvider
|
|
199
|
-
: undefined,
|
|
200
|
-
evaluationTime: isNumber(evaluationResult.evaluationTime)
|
|
201
|
-
? evaluationResult.evaluationTime
|
|
202
|
-
: undefined,
|
|
203
|
-
evaluationAttempt: isNumber(evaluationResult.evaluationAttempt)
|
|
204
|
-
? evaluationResult.evaluationAttempt
|
|
205
|
-
: undefined,
|
|
206
|
-
},
|
|
207
|
-
// Add evaluation cost if available
|
|
208
|
-
costDetails: analytics.costDetails
|
|
209
|
-
? {
|
|
210
|
-
...analytics.costDetails,
|
|
211
|
-
evaluationCost,
|
|
212
|
-
totalCost: getExistingTotalCost(analytics.costDetails) + evaluationCost,
|
|
213
|
-
}
|
|
214
|
-
: undefined,
|
|
215
|
-
};
|
|
216
|
-
}
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Enhanced AI Provider with Real Function Calling Support
|
|
3
|
-
* Integrates MCP tools directly with AI SDK's function calling capabilities
|
|
4
|
-
* This is the missing piece that enables true AI function calling!
|
|
5
|
-
*/
|
|
6
|
-
import type { AIProvider, TextGenerationOptions, EnhancedGenerateResult } from "../core/types.js";
|
|
7
|
-
import { type Schema } from "ai";
|
|
8
|
-
import type { GenerateResult } from "../types/generate-types.js";
|
|
9
|
-
import type { ZodType, ZodTypeDef } from "zod";
|
|
10
|
-
import type { StreamOptions, StreamResult } from "../types/stream-types.js";
|
|
11
|
-
/**
|
|
12
|
-
* Enhanced provider that enables real function calling with MCP tools
|
|
13
|
-
*/
|
|
14
|
-
export declare class FunctionCallingProvider implements AIProvider {
|
|
15
|
-
private baseProvider;
|
|
16
|
-
private enableFunctionCalling;
|
|
17
|
-
private sessionId;
|
|
18
|
-
private userId;
|
|
19
|
-
private cachedToolsObject;
|
|
20
|
-
private cachedToolMap;
|
|
21
|
-
private cacheTimestamp;
|
|
22
|
-
private readonly cacheExpiryMs;
|
|
23
|
-
constructor(baseProvider: AIProvider, options?: {
|
|
24
|
-
enableFunctionCalling?: boolean;
|
|
25
|
-
sessionId?: string;
|
|
26
|
-
userId?: string;
|
|
27
|
-
cacheExpiryMs?: number;
|
|
28
|
-
});
|
|
29
|
-
/**
|
|
30
|
-
* PRIMARY METHOD: Stream content using AI (recommended for new code)
|
|
31
|
-
* Future-ready for multi-modal capabilities with current text focus
|
|
32
|
-
*/
|
|
33
|
-
stream(optionsOrPrompt: StreamOptions | string, analysisSchema?: Schema): Promise<StreamResult>;
|
|
34
|
-
/**
|
|
35
|
-
* Generate text with real function calling support
|
|
36
|
-
*/
|
|
37
|
-
generate(optionsOrPrompt: TextGenerationOptions | string, analysisSchema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>): Promise<GenerateResult>;
|
|
38
|
-
/**
|
|
39
|
-
* Generate text with tools using the AI SDK's generate function (with tools object)
|
|
40
|
-
*/
|
|
41
|
-
private generateWithToolsObject;
|
|
42
|
-
/**
|
|
43
|
-
* Generate text using AI SDK's native function calling (legacy array-based)
|
|
44
|
-
*/
|
|
45
|
-
private generateWithTools;
|
|
46
|
-
/**
|
|
47
|
-
* Get the model from the base provider
|
|
48
|
-
* This is a temporary solution - ideally we'd have a getModel() method on AIProvider
|
|
49
|
-
*/
|
|
50
|
-
private getModelFromProvider;
|
|
51
|
-
/**
|
|
52
|
-
* Sanitize tool name to comply with AI provider requirements
|
|
53
|
-
*/
|
|
54
|
-
private sanitizeToolName;
|
|
55
|
-
/**
|
|
56
|
-
* Wrap tools with proper execution context (for object-based tools)
|
|
57
|
-
*/
|
|
58
|
-
private wrapToolsWithExecution;
|
|
59
|
-
/**
|
|
60
|
-
* Convert our tools to AI SDK format with proper execution (legacy array-based)
|
|
61
|
-
*/
|
|
62
|
-
private convertToAISDKTools;
|
|
63
|
-
/**
|
|
64
|
-
* Create function-aware system prompt
|
|
65
|
-
*/
|
|
66
|
-
private createFunctionAwareSystemPrompt;
|
|
67
|
-
/**
|
|
68
|
-
* Alias for generate() - CLI-SDK consistency
|
|
69
|
-
*/
|
|
70
|
-
/**
|
|
71
|
-
* Clear cached tools - Cache Invalidation Strategy
|
|
72
|
-
*
|
|
73
|
-
* WHEN TO CALL clearToolsCache():
|
|
74
|
-
*
|
|
75
|
-
* 1. **MCP Server Changes**: When MCP servers are added, removed, or restarted
|
|
76
|
-
* - After calling unifiedRegistry.addServer() or removeServer()
|
|
77
|
-
* - When MCP server configurations change
|
|
78
|
-
* - After MCP server restart or reconnection
|
|
79
|
-
*
|
|
80
|
-
* 2. **Tool Registration Changes**: When custom tools are modified
|
|
81
|
-
* - After registering new SDK tools via registerTool()
|
|
82
|
-
* - When tool implementations change
|
|
83
|
-
* - After unregistering tools
|
|
84
|
-
*
|
|
85
|
-
* 3. **Provider Reinitialization**: When the provider context changes
|
|
86
|
-
* - Before switching between different AI providers
|
|
87
|
-
* - When session context changes significantly
|
|
88
|
-
* - After provider authentication refresh
|
|
89
|
-
*
|
|
90
|
-
* 4. **Error Recovery**: When tool execution encounters systematic failures
|
|
91
|
-
* - After MCP connection errors are resolved
|
|
92
|
-
* - When tool discovery needs to be re-run
|
|
93
|
-
* - During error recovery workflows
|
|
94
|
-
*
|
|
95
|
-
* 5. **Development/Testing**: During development and testing cycles
|
|
96
|
-
* - Between test cases that modify tool availability
|
|
97
|
-
* - When testing different tool configurations
|
|
98
|
-
* - During hot reloading scenarios
|
|
99
|
-
*
|
|
100
|
-
* CACHE LIFECYCLE:
|
|
101
|
-
* - Cache is populated on first generate() call via getAvailableFunctionTools()
|
|
102
|
-
* - Cache persists across multiple generate() calls for performance
|
|
103
|
-
* - Cache is invalidated by calling this method
|
|
104
|
-
* - Next generate() call will rebuild cache from current tool state
|
|
105
|
-
*
|
|
106
|
-
* PERFORMANCE IMPACT:
|
|
107
|
-
* - Clearing cache forces tool discovery on next usage (~100-500ms overhead)
|
|
108
|
-
* - Recommended to clear cache proactively rather than reactively
|
|
109
|
-
* - Consider batching tool changes before clearing cache
|
|
110
|
-
*
|
|
111
|
-
* THREAD SAFETY:
|
|
112
|
-
* - This method is not thread-safe
|
|
113
|
-
* - Avoid calling during active generate() operations
|
|
114
|
-
* - Safe to call between separate AI generation requests
|
|
115
|
-
*/
|
|
116
|
-
clearToolsCache(): void;
|
|
117
|
-
/**
|
|
118
|
-
* Short alias for generate() - CLI-SDK consistency
|
|
119
|
-
*/
|
|
120
|
-
gen(optionsOrPrompt: TextGenerationOptions | string, analysisSchema?: Schema): Promise<EnhancedGenerateResult | null>;
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Create a function-calling enhanced version of any AI provider
|
|
124
|
-
*/
|
|
125
|
-
export declare function createFunctionCallingProvider(baseProvider: AIProvider, options?: {
|
|
126
|
-
enableFunctionCalling?: boolean;
|
|
127
|
-
sessionId?: string;
|
|
128
|
-
userId?: string;
|
|
129
|
-
cacheExpiryMs?: number;
|
|
130
|
-
}): AIProvider;
|
|
131
|
-
/**
|
|
132
|
-
* Enhanced MCP Provider Factory that creates function-calling enabled providers
|
|
133
|
-
*/
|
|
134
|
-
export declare function createMCPAwareProviderV3(baseProvider: AIProvider, options?: {
|
|
135
|
-
providerName?: string;
|
|
136
|
-
modelName?: string;
|
|
137
|
-
enableMCP?: boolean;
|
|
138
|
-
enableFunctionCalling?: boolean;
|
|
139
|
-
sessionId?: string;
|
|
140
|
-
userId?: string;
|
|
141
|
-
cacheExpiryMs?: number;
|
|
142
|
-
}): AIProvider;
|