@juspay/neurolink 5.2.0 → 6.0.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 +82 -2
- package/dist/chat/client-utils.d.ts +3 -0
- package/dist/chat/client-utils.js +22 -5
- package/dist/chat/index.d.ts +4 -7
- package/dist/chat/index.js +0 -8
- package/dist/chat/session-storage.d.ts +2 -2
- package/dist/chat/session.d.ts +4 -3
- package/dist/chat/session.js +1 -1
- package/dist/chat/sse-handler.js +13 -21
- package/dist/chat/types.d.ts +3 -2
- package/dist/chat/websocket-chat-handler.d.ts +4 -3
- package/dist/chat/websocket-chat-handler.js +12 -12
- package/dist/cli/commands/config.d.ts +2 -2
- package/dist/cli/commands/mcp.d.ts +3 -2
- package/dist/cli/commands/mcp.js +39 -29
- package/dist/cli/commands/ollama.js +8 -4
- package/dist/cli/factories/command-factory.d.ts +2 -1
- package/dist/cli/factories/command-factory.js +6 -5
- package/dist/cli/index.js +22 -19
- package/dist/core/analytics.d.ts +3 -2
- package/dist/core/analytics.js +16 -7
- package/dist/core/base-provider.d.ts +35 -7
- package/dist/core/base-provider.js +57 -23
- package/dist/core/constants.d.ts +1 -0
- package/dist/core/constants.js +1 -0
- package/dist/core/defaults.d.ts +2 -1
- package/dist/core/evaluation.d.ts +4 -4
- package/dist/core/evaluation.js +17 -7
- package/dist/core/factory.d.ts +3 -2
- package/dist/core/service-registry.d.ts +4 -4
- package/dist/core/types.d.ts +11 -4
- package/dist/factories/compatibility-factory.d.ts +16 -1
- package/dist/factories/compatibility-factory.js +3 -1
- package/dist/factories/provider-factory.d.ts +5 -4
- package/dist/factories/provider-factory.js +15 -24
- package/dist/factories/provider-generate-factory.js +26 -20
- package/dist/lib/chat/client-utils.d.ts +3 -0
- package/dist/lib/chat/client-utils.js +22 -5
- package/dist/lib/chat/index.d.ts +4 -7
- package/dist/lib/chat/index.js +0 -8
- package/dist/lib/chat/session-storage.d.ts +2 -2
- package/dist/lib/chat/session.d.ts +4 -3
- package/dist/lib/chat/session.js +1 -1
- package/dist/lib/chat/sse-handler.js +13 -21
- package/dist/lib/chat/types.d.ts +3 -2
- package/dist/lib/chat/websocket-chat-handler.d.ts +4 -3
- package/dist/lib/chat/websocket-chat-handler.js +12 -12
- package/dist/lib/core/analytics.d.ts +3 -2
- package/dist/lib/core/analytics.js +16 -7
- package/dist/lib/core/base-provider.d.ts +35 -7
- package/dist/lib/core/base-provider.js +57 -23
- package/dist/lib/core/constants.d.ts +1 -0
- package/dist/lib/core/constants.js +1 -0
- package/dist/lib/core/defaults.d.ts +2 -1
- package/dist/lib/core/evaluation.d.ts +4 -4
- package/dist/lib/core/evaluation.js +17 -7
- package/dist/lib/core/factory.d.ts +3 -2
- package/dist/lib/core/service-registry.d.ts +4 -4
- package/dist/lib/core/types.d.ts +11 -4
- package/dist/lib/factories/compatibility-factory.d.ts +16 -1
- package/dist/lib/factories/compatibility-factory.js +3 -1
- package/dist/lib/factories/provider-factory.d.ts +5 -4
- package/dist/lib/factories/provider-factory.js +15 -24
- package/dist/lib/factories/provider-generate-factory.js +26 -20
- package/dist/lib/mcp/adapters/plugin-bridge.d.ts +5 -4
- package/dist/lib/mcp/adapters/plugin-bridge.js +13 -6
- package/dist/lib/mcp/client.d.ts +3 -1
- package/dist/lib/mcp/client.js +13 -10
- package/dist/lib/mcp/context-manager.d.ts +2 -1
- package/dist/lib/mcp/context-manager.js +8 -4
- package/dist/lib/mcp/contracts/mcp-contract.d.ts +15 -8
- package/dist/lib/mcp/core/plugin-manager.d.ts +3 -2
- package/dist/lib/mcp/core/plugin-manager.js +1 -1
- package/dist/lib/mcp/demo/plugin-demo.js +3 -1
- package/dist/lib/mcp/dynamic-chain-executor.d.ts +64 -40
- package/dist/lib/mcp/dynamic-chain-executor.js +3 -3
- package/dist/lib/mcp/dynamic-orchestrator.d.ts +14 -8
- package/dist/lib/mcp/ecosystem.d.ts +4 -4
- package/dist/lib/mcp/error-manager.d.ts +2 -2
- package/dist/lib/mcp/error-recovery.d.ts +4 -3
- package/dist/lib/mcp/external-client.d.ts +1 -1
- package/dist/lib/mcp/external-client.js +14 -10
- package/dist/lib/mcp/external-manager.d.ts +3 -3
- package/dist/lib/mcp/external-manager.js +9 -3
- package/dist/lib/mcp/factory.d.ts +7 -7
- package/dist/lib/mcp/function-calling.d.ts +14 -0
- package/dist/lib/mcp/function-calling.js +133 -34
- package/dist/lib/mcp/health-monitor.d.ts +2 -1
- package/dist/lib/mcp/health-monitor.js +16 -7
- package/dist/lib/mcp/index.d.ts +5 -5
- package/dist/lib/mcp/initialize-tools.d.ts +2 -1
- package/dist/lib/mcp/initialize-tools.js +10 -2
- package/dist/lib/mcp/manager.d.ts +2 -1
- package/dist/lib/mcp/neurolink-mcp-client.d.ts +1 -0
- package/dist/lib/mcp/neurolink-mcp-client.js +22 -6
- package/dist/lib/mcp/orchestrator.d.ts +13 -12
- package/dist/lib/mcp/orchestrator.js +10 -8
- package/dist/lib/mcp/plugin-manager.js +4 -2
- package/dist/lib/mcp/plugins/core/filesystem-mcp.d.ts +3 -2
- package/dist/lib/mcp/plugins/core/filesystem-mcp.js +5 -2
- package/dist/lib/mcp/plugins/filesystem-mcp.d.ts +2 -1
- package/dist/lib/mcp/registry.d.ts +2 -1
- package/dist/lib/mcp/registry.js +2 -1
- package/dist/lib/mcp/security-manager.d.ts +4 -2
- package/dist/lib/mcp/servers/agent/direct-tools-server.js +18 -6
- package/dist/lib/mcp/servers/ai-providers/ai-analysis-tools.d.ts +1 -16
- package/dist/lib/mcp/servers/ai-providers/ai-analysis-tools.js +21 -17
- package/dist/lib/mcp/servers/ai-providers/ai-core-server.d.ts +2 -2
- package/dist/lib/mcp/servers/ai-providers/ai-core-server.js +15 -133
- package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.d.ts +1 -97
- package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.js +18 -18
- package/dist/lib/mcp/session-manager.d.ts +4 -3
- package/dist/lib/mcp/session-persistence.js +5 -2
- package/dist/lib/mcp/tool-integration.d.ts +3 -2
- package/dist/lib/mcp/tool-integration.js +3 -1
- package/dist/lib/mcp/tool-registry.d.ts +18 -1
- package/dist/lib/mcp/tool-registry.js +11 -8
- package/dist/lib/mcp/transport-manager.d.ts +2 -1
- package/dist/lib/mcp/transport-manager.js +5 -1
- package/dist/lib/mcp/unified-mcp.d.ts +5 -5
- package/dist/lib/mcp/unified-registry.d.ts +18 -2
- package/dist/lib/mcp/unified-registry.js +52 -3
- package/dist/lib/neurolink.d.ts +2 -2
- package/dist/lib/neurolink.js +40 -15
- package/dist/lib/providers/amazon-bedrock.d.ts +1 -1
- package/dist/lib/providers/amazon-bedrock.js +8 -7
- package/dist/lib/providers/analytics-helper.d.ts +8 -23
- package/dist/lib/providers/analytics-helper.js +95 -33
- package/dist/lib/providers/anthropic-baseprovider.d.ts +3 -3
- package/dist/lib/providers/anthropic-baseprovider.js +6 -5
- package/dist/lib/providers/anthropic.d.ts +2 -2
- package/dist/lib/providers/anthropic.js +11 -4
- package/dist/lib/providers/azure-openai.d.ts +5 -4
- package/dist/lib/providers/azure-openai.js +10 -4
- package/dist/lib/providers/function-calling-provider.d.ts +66 -4
- package/dist/lib/providers/function-calling-provider.js +209 -10
- package/dist/lib/providers/google-ai-studio.d.ts +2 -2
- package/dist/lib/providers/google-ai-studio.js +9 -3
- package/dist/lib/providers/google-vertex.d.ts +2 -2
- package/dist/lib/providers/google-vertex.js +18 -12
- package/dist/lib/providers/huggingFace.d.ts +1 -1
- package/dist/lib/providers/huggingFace.js +8 -4
- package/dist/lib/providers/mcp-provider.d.ts +3 -3
- package/dist/lib/providers/mcp-provider.js +20 -5
- package/dist/lib/providers/mistral.d.ts +34 -27
- package/dist/lib/providers/mistral.js +115 -107
- package/dist/lib/providers/ollama.d.ts +2 -1
- package/dist/lib/providers/ollama.js +43 -3
- package/dist/lib/providers/openAI.d.ts +1 -1
- package/dist/lib/providers/openAI.js +8 -4
- package/dist/lib/proxy/proxy-fetch.js +3 -2
- package/dist/lib/sdk/tool-extension.d.ts +12 -12
- package/dist/lib/sdk/tool-extension.js +2 -1
- package/dist/lib/sdk/tool-registration.d.ts +16 -12
- package/dist/lib/sdk/tool-registration.js +3 -2
- package/dist/lib/services/streaming/streaming-manager.js +11 -10
- package/dist/lib/services/types.d.ts +5 -4
- package/dist/lib/services/websocket/websocket-server.d.ts +1 -1
- package/dist/lib/services/websocket/websocket-server.js +13 -12
- package/dist/lib/telemetry/telemetry-service.js +9 -8
- package/dist/lib/types/cli.d.ts +247 -0
- package/dist/lib/types/cli.js +22 -0
- package/dist/lib/types/common.d.ts +76 -0
- package/dist/lib/types/common.js +52 -0
- package/dist/lib/types/generate-types.d.ts +6 -6
- package/dist/lib/types/index.d.ts +12 -0
- package/dist/lib/types/index.js +12 -0
- package/dist/lib/types/mcp-types.d.ts +7 -7
- package/dist/lib/types/providers.d.ts +158 -0
- package/dist/lib/types/providers.js +23 -0
- package/dist/lib/types/stream-types.d.ts +4 -3
- package/dist/lib/types/tools.d.ts +154 -0
- package/dist/lib/types/tools.js +24 -0
- package/dist/lib/utils/logger.d.ts +5 -5
- package/dist/lib/utils/provider-validation.d.ts +2 -1
- package/dist/mcp/adapters/plugin-bridge.d.ts +5 -4
- package/dist/mcp/adapters/plugin-bridge.js +13 -6
- package/dist/mcp/client.d.ts +3 -1
- package/dist/mcp/client.js +13 -10
- package/dist/mcp/context-manager.d.ts +2 -1
- package/dist/mcp/context-manager.js +8 -4
- package/dist/mcp/contracts/mcp-contract.d.ts +15 -8
- package/dist/mcp/core/plugin-manager.d.ts +3 -2
- package/dist/mcp/core/plugin-manager.js +1 -1
- package/dist/mcp/demo/plugin-demo.js +3 -1
- package/dist/mcp/dynamic-chain-executor.d.ts +64 -40
- package/dist/mcp/dynamic-chain-executor.js +3 -3
- package/dist/mcp/dynamic-orchestrator.d.ts +14 -8
- package/dist/mcp/dynamic-orchestrator.js +1 -1
- package/dist/mcp/ecosystem.d.ts +4 -4
- package/dist/mcp/error-manager.d.ts +2 -2
- package/dist/mcp/error-recovery.d.ts +4 -3
- package/dist/mcp/external-client.d.ts +1 -1
- package/dist/mcp/external-client.js +14 -10
- package/dist/mcp/external-manager.d.ts +3 -3
- package/dist/mcp/external-manager.js +9 -3
- package/dist/mcp/factory.d.ts +7 -7
- package/dist/mcp/function-calling.d.ts +14 -0
- package/dist/mcp/function-calling.js +133 -34
- package/dist/mcp/health-monitor.d.ts +2 -1
- package/dist/mcp/health-monitor.js +16 -7
- package/dist/mcp/index.d.ts +5 -5
- package/dist/mcp/initialize-tools.d.ts +2 -1
- package/dist/mcp/initialize-tools.js +10 -2
- package/dist/mcp/manager.d.ts +2 -1
- package/dist/mcp/neurolink-mcp-client.d.ts +1 -0
- package/dist/mcp/neurolink-mcp-client.js +22 -6
- package/dist/mcp/orchestrator.d.ts +13 -12
- package/dist/mcp/orchestrator.js +10 -8
- package/dist/mcp/plugin-manager.js +4 -2
- package/dist/mcp/plugins/core/filesystem-mcp.d.ts +3 -2
- package/dist/mcp/plugins/core/filesystem-mcp.js +5 -2
- package/dist/mcp/plugins/filesystem-mcp.d.ts +2 -1
- package/dist/mcp/registry.d.ts +2 -1
- package/dist/mcp/registry.js +2 -1
- package/dist/mcp/security-manager.d.ts +4 -2
- package/dist/mcp/servers/agent/direct-tools-server.js +19 -6
- package/dist/mcp/servers/ai-providers/ai-analysis-tools.d.ts +1 -16
- package/dist/mcp/servers/ai-providers/ai-analysis-tools.js +21 -17
- package/dist/mcp/servers/ai-providers/ai-core-server.d.ts +2 -2
- package/dist/mcp/servers/ai-providers/ai-core-server.js +15 -132
- package/dist/mcp/servers/ai-providers/ai-workflow-tools.d.ts +1 -97
- package/dist/mcp/servers/ai-providers/ai-workflow-tools.js +18 -18
- package/dist/mcp/session-manager.d.ts +4 -3
- package/dist/mcp/session-persistence.js +5 -2
- package/dist/mcp/tool-integration.d.ts +3 -2
- package/dist/mcp/tool-integration.js +3 -1
- package/dist/mcp/tool-registry.d.ts +18 -1
- package/dist/mcp/tool-registry.js +11 -8
- package/dist/mcp/transport-manager.d.ts +2 -1
- package/dist/mcp/transport-manager.js +5 -1
- package/dist/mcp/unified-mcp.d.ts +5 -5
- package/dist/mcp/unified-registry.d.ts +18 -2
- package/dist/mcp/unified-registry.js +52 -3
- package/dist/neurolink.d.ts +2 -2
- package/dist/neurolink.js +40 -15
- package/dist/providers/amazon-bedrock.d.ts +1 -1
- package/dist/providers/amazon-bedrock.js +8 -7
- package/dist/providers/analytics-helper.d.ts +8 -23
- package/dist/providers/analytics-helper.js +95 -33
- package/dist/providers/anthropic-baseprovider.d.ts +3 -3
- package/dist/providers/anthropic-baseprovider.js +6 -5
- package/dist/providers/anthropic.d.ts +2 -2
- package/dist/providers/anthropic.js +11 -4
- package/dist/providers/azure-openai.d.ts +5 -4
- package/dist/providers/azure-openai.js +10 -4
- package/dist/providers/function-calling-provider.d.ts +66 -4
- package/dist/providers/function-calling-provider.js +209 -10
- package/dist/providers/google-ai-studio.d.ts +2 -2
- package/dist/providers/google-ai-studio.js +9 -3
- package/dist/providers/google-vertex.d.ts +2 -2
- package/dist/providers/google-vertex.js +18 -12
- package/dist/providers/huggingFace.d.ts +1 -1
- package/dist/providers/huggingFace.js +8 -4
- package/dist/providers/mcp-provider.d.ts +3 -3
- package/dist/providers/mcp-provider.js +20 -5
- package/dist/providers/mistral.d.ts +34 -27
- package/dist/providers/mistral.js +116 -108
- package/dist/providers/ollama.d.ts +2 -1
- package/dist/providers/ollama.js +43 -3
- package/dist/providers/openAI.d.ts +1 -1
- package/dist/providers/openAI.js +8 -4
- package/dist/proxy/proxy-fetch.js +3 -2
- package/dist/sdk/tool-extension.d.ts +12 -12
- package/dist/sdk/tool-extension.js +2 -1
- package/dist/sdk/tool-registration.d.ts +16 -12
- package/dist/sdk/tool-registration.js +3 -2
- package/dist/services/streaming/streaming-manager.js +11 -10
- package/dist/services/types.d.ts +5 -4
- package/dist/services/websocket/websocket-server.d.ts +1 -1
- package/dist/services/websocket/websocket-server.js +14 -12
- package/dist/telemetry/telemetry-service.js +9 -8
- package/dist/types/cli.d.ts +247 -0
- package/dist/types/cli.js +22 -0
- package/dist/types/common.d.ts +76 -0
- package/dist/types/common.js +52 -0
- package/dist/types/generate-types.d.ts +6 -6
- package/dist/types/index.d.ts +12 -0
- package/dist/types/index.js +12 -0
- package/dist/types/mcp-types.d.ts +7 -7
- package/dist/types/providers.d.ts +158 -0
- package/dist/types/providers.js +23 -0
- package/dist/types/stream-types.d.ts +4 -3
- package/dist/types/tools.d.ts +154 -0
- package/dist/types/tools.js +25 -0
- package/dist/utils/logger.d.ts +5 -5
- package/dist/utils/provider-validation.d.ts +2 -1
- package/package.json +12 -10
|
@@ -3,23 +3,43 @@
|
|
|
3
3
|
* Ensures consistent analytics data format across providers
|
|
4
4
|
* Integrates with Universal Evaluation System
|
|
5
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
|
+
}
|
|
6
14
|
/**
|
|
7
15
|
* Create standardized analytics data from provider response
|
|
8
16
|
*/
|
|
9
17
|
export function createAnalytics(provider, model, result, responseTime, context) {
|
|
10
18
|
// Handle different token usage formats across providers
|
|
11
|
-
const tokenUsage = result
|
|
19
|
+
const tokenUsage = result?.usage || {};
|
|
12
20
|
// Standardize token field names across providers
|
|
13
|
-
const inputTokens = tokenUsage.promptTokens
|
|
14
|
-
tokenUsage.
|
|
15
|
-
|
|
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) ||
|
|
16
28
|
0;
|
|
17
|
-
const outputTokens = tokenUsage.completionTokens
|
|
18
|
-
tokenUsage.
|
|
19
|
-
|
|
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) ||
|
|
20
38
|
0;
|
|
21
|
-
const totalTokens = tokenUsage.totalTokens ||
|
|
22
|
-
tokenUsage.total_tokens
|
|
39
|
+
const totalTokens = (typeof tokenUsage.totalTokens === "number" ? tokenUsage.totalTokens : 0) ||
|
|
40
|
+
(typeof tokenUsage.total_tokens === "number"
|
|
41
|
+
? tokenUsage.total_tokens
|
|
42
|
+
: 0) ||
|
|
23
43
|
inputTokens + outputTokens ||
|
|
24
44
|
0;
|
|
25
45
|
// Simple cost estimation for synchronous use
|
|
@@ -35,7 +55,7 @@ export function createAnalytics(provider, model, result, responseTime, context)
|
|
|
35
55
|
cost: estimatedCost,
|
|
36
56
|
responseTime,
|
|
37
57
|
timestamp: new Date().toISOString(),
|
|
38
|
-
context,
|
|
58
|
+
context: context,
|
|
39
59
|
};
|
|
40
60
|
}
|
|
41
61
|
/**
|
|
@@ -43,18 +63,30 @@ export function createAnalytics(provider, model, result, responseTime, context)
|
|
|
43
63
|
*/
|
|
44
64
|
export async function createEnhancedAnalytics(provider, model, result, responseTime, context) {
|
|
45
65
|
// Handle different token usage formats across providers
|
|
46
|
-
const tokenUsage = result
|
|
66
|
+
const tokenUsage = result?.usage || {};
|
|
47
67
|
// Standardize token field names across providers
|
|
48
|
-
const inputTokens = tokenUsage.promptTokens
|
|
49
|
-
tokenUsage.
|
|
50
|
-
|
|
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) ||
|
|
51
75
|
0;
|
|
52
|
-
const outputTokens = tokenUsage.completionTokens
|
|
53
|
-
tokenUsage.
|
|
54
|
-
|
|
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) ||
|
|
55
85
|
0;
|
|
56
|
-
const totalTokens = tokenUsage.totalTokens ||
|
|
57
|
-
tokenUsage.total_tokens
|
|
86
|
+
const totalTokens = (typeof tokenUsage.totalTokens === "number" ? tokenUsage.totalTokens : 0) ||
|
|
87
|
+
(typeof tokenUsage.total_tokens === "number"
|
|
88
|
+
? tokenUsage.total_tokens
|
|
89
|
+
: 0) ||
|
|
58
90
|
inputTokens + outputTokens ||
|
|
59
91
|
0;
|
|
60
92
|
// Enhanced cost calculation using provider configuration
|
|
@@ -70,7 +102,7 @@ export async function createEnhancedAnalytics(provider, model, result, responseT
|
|
|
70
102
|
cost: estimatedCost,
|
|
71
103
|
responseTime,
|
|
72
104
|
timestamp: new Date().toISOString(),
|
|
73
|
-
context,
|
|
105
|
+
context: context,
|
|
74
106
|
costDetails,
|
|
75
107
|
};
|
|
76
108
|
}
|
|
@@ -127,27 +159,57 @@ export async function calculateEnhancedCost(provider, inputTokens, outputTokens)
|
|
|
127
159
|
* Enhance analytics with evaluation data
|
|
128
160
|
*/
|
|
129
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);
|
|
130
190
|
return {
|
|
131
191
|
...analytics,
|
|
132
192
|
evaluation: {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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,
|
|
143
206
|
},
|
|
144
207
|
// Add evaluation cost if available
|
|
145
208
|
costDetails: analytics.costDetails
|
|
146
209
|
? {
|
|
147
210
|
...analytics.costDetails,
|
|
148
|
-
evaluationCost
|
|
149
|
-
totalCost: (analytics.costDetails
|
|
150
|
-
(evaluationResult.evaluationConfig?.costEstimate || 0),
|
|
211
|
+
evaluationCost,
|
|
212
|
+
totalCost: getExistingTotalCost(analytics.costDetails) + evaluationCost,
|
|
151
213
|
}
|
|
152
214
|
: undefined,
|
|
153
215
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ZodType, ZodTypeDef } from "zod";
|
|
2
|
-
import { type Schema } from "ai";
|
|
2
|
+
import { type Schema, type LanguageModelV1 } from "ai";
|
|
3
3
|
import type { AIProviderName } from "../core/types.js";
|
|
4
4
|
import type { StreamOptions, StreamResult } from "../types/stream-types.js";
|
|
5
5
|
import { BaseProvider } from "../core/base-provider.js";
|
|
@@ -15,8 +15,8 @@ export declare class AnthropicProviderV2 extends BaseProvider {
|
|
|
15
15
|
/**
|
|
16
16
|
* Returns the Vercel AI SDK model instance for Anthropic
|
|
17
17
|
*/
|
|
18
|
-
protected getAISDKModel():
|
|
19
|
-
protected handleProviderError(error:
|
|
18
|
+
protected getAISDKModel(): LanguageModelV1;
|
|
19
|
+
protected handleProviderError(error: unknown): Error;
|
|
20
20
|
private getApiKey;
|
|
21
21
|
protected executeStream(options: StreamOptions, analysisSchema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>): Promise<StreamResult>;
|
|
22
22
|
}
|
|
@@ -38,16 +38,17 @@ export class AnthropicProviderV2 extends BaseProvider {
|
|
|
38
38
|
if (error instanceof TimeoutError) {
|
|
39
39
|
return new Error(`Anthropic request timed out: ${error.message}`);
|
|
40
40
|
}
|
|
41
|
-
|
|
41
|
+
const errorWithStatus = error;
|
|
42
|
+
if (errorWithStatus?.status === 401) {
|
|
42
43
|
return new Error("Invalid Anthropic API key. Please check your ANTHROPIC_API_KEY environment variable.");
|
|
43
44
|
}
|
|
44
|
-
if (
|
|
45
|
+
if (errorWithStatus?.status === 429) {
|
|
45
46
|
return new Error("Anthropic rate limit exceeded. Please try again later.");
|
|
46
47
|
}
|
|
47
|
-
if (
|
|
48
|
-
return new Error(`Anthropic bad request: ${
|
|
48
|
+
if (errorWithStatus?.status === 400) {
|
|
49
|
+
return new Error(`Anthropic bad request: ${errorWithStatus?.message || "Invalid request parameters"}`);
|
|
49
50
|
}
|
|
50
|
-
return new Error(`Anthropic error: ${
|
|
51
|
+
return new Error(`Anthropic error: ${errorWithStatus?.message || String(error) || "Unknown error"}`);
|
|
51
52
|
}
|
|
52
53
|
getApiKey() {
|
|
53
54
|
const apiKey = process.env.ANTHROPIC_API_KEY;
|
|
@@ -9,14 +9,14 @@ import { BaseProvider } from "../core/base-provider.js";
|
|
|
9
9
|
*/
|
|
10
10
|
export declare class AnthropicProvider extends BaseProvider {
|
|
11
11
|
private model;
|
|
12
|
-
constructor(modelName?: string, sdk?:
|
|
12
|
+
constructor(modelName?: string, sdk?: unknown);
|
|
13
13
|
protected getProviderName(): AIProviderName;
|
|
14
14
|
protected getDefaultModel(): string;
|
|
15
15
|
/**
|
|
16
16
|
* Returns the Vercel AI SDK model instance for Anthropic
|
|
17
17
|
*/
|
|
18
18
|
protected getAISDKModel(): LanguageModelV1;
|
|
19
|
-
protected handleProviderError(error:
|
|
19
|
+
protected handleProviderError(error: unknown): Error;
|
|
20
20
|
protected executeStream(options: StreamOptions, analysisSchema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>): Promise<StreamResult>;
|
|
21
21
|
isAvailable(): Promise<boolean>;
|
|
22
22
|
getModel(): LanguageModelV1;
|
|
@@ -47,14 +47,21 @@ export class AnthropicProvider extends BaseProvider {
|
|
|
47
47
|
if (error instanceof TimeoutError) {
|
|
48
48
|
return new Error(`Anthropic request timed out: ${error.message}`);
|
|
49
49
|
}
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
const errorRecord = error;
|
|
51
|
+
if ((typeof errorRecord?.message === "string" &&
|
|
52
|
+
errorRecord.message.includes("API_KEY_INVALID")) ||
|
|
53
|
+
(typeof errorRecord?.message === "string" &&
|
|
54
|
+
errorRecord.message.includes("Invalid API key"))) {
|
|
52
55
|
return new Error("Invalid Anthropic API key. Please check your ANTHROPIC_API_KEY environment variable.");
|
|
53
56
|
}
|
|
54
|
-
if (
|
|
57
|
+
if (typeof errorRecord?.message === "string" &&
|
|
58
|
+
errorRecord.message.includes("rate limit")) {
|
|
55
59
|
return new Error("Anthropic rate limit exceeded. Please try again later.");
|
|
56
60
|
}
|
|
57
|
-
|
|
61
|
+
const message = typeof errorRecord?.message === "string"
|
|
62
|
+
? errorRecord.message
|
|
63
|
+
: "Unknown error";
|
|
64
|
+
return new Error(`Anthropic error: ${message}`);
|
|
58
65
|
}
|
|
59
66
|
// executeGenerate removed - BaseProvider handles all generation with tools
|
|
60
67
|
async executeStream(options, analysisSchema) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type LanguageModelV1 } from "ai";
|
|
1
2
|
import { BaseProvider } from "../core/base-provider.js";
|
|
2
3
|
import type { AIProviderName } from "../core/types.js";
|
|
3
4
|
import type { StreamOptions, StreamResult } from "../types/stream-types.js";
|
|
@@ -7,14 +8,14 @@ export declare class AzureOpenAIProvider extends BaseProvider {
|
|
|
7
8
|
private deployment;
|
|
8
9
|
private apiVersion;
|
|
9
10
|
private azureProvider;
|
|
10
|
-
constructor(modelName?: string);
|
|
11
|
+
constructor(modelName?: string, sdk?: unknown);
|
|
11
12
|
protected getProviderName(): AIProviderName;
|
|
12
13
|
protected getDefaultModel(): string;
|
|
13
14
|
/**
|
|
14
15
|
* Returns the Vercel AI SDK model instance for Azure OpenAI
|
|
15
16
|
*/
|
|
16
|
-
protected getAISDKModel():
|
|
17
|
-
protected handleProviderError(error:
|
|
18
|
-
protected executeStream(options: StreamOptions, analysisSchema?:
|
|
17
|
+
protected getAISDKModel(): LanguageModelV1;
|
|
18
|
+
protected handleProviderError(error: unknown): Error;
|
|
19
|
+
protected executeStream(options: StreamOptions, analysisSchema?: unknown): Promise<StreamResult>;
|
|
19
20
|
}
|
|
20
21
|
export default AzureOpenAIProvider;
|
|
@@ -7,8 +7,8 @@ export class AzureOpenAIProvider extends BaseProvider {
|
|
|
7
7
|
deployment;
|
|
8
8
|
apiVersion;
|
|
9
9
|
azureProvider;
|
|
10
|
-
constructor(modelName) {
|
|
11
|
-
super(modelName, "azure");
|
|
10
|
+
constructor(modelName, sdk) {
|
|
11
|
+
super(modelName, "azure", sdk);
|
|
12
12
|
this.apiKey = process.env.AZURE_OPENAI_API_KEY || "";
|
|
13
13
|
const endpoint = process.env.AZURE_OPENAI_ENDPOINT || "";
|
|
14
14
|
this.resourceName = endpoint
|
|
@@ -52,10 +52,16 @@ export class AzureOpenAIProvider extends BaseProvider {
|
|
|
52
52
|
return this.azureProvider(this.deployment);
|
|
53
53
|
}
|
|
54
54
|
handleProviderError(error) {
|
|
55
|
-
|
|
55
|
+
const errorObj = error;
|
|
56
|
+
if (errorObj?.message &&
|
|
57
|
+
typeof errorObj.message === "string" &&
|
|
58
|
+
errorObj.message.includes("401")) {
|
|
56
59
|
return new Error("Invalid Azure OpenAI API key or endpoint.");
|
|
57
60
|
}
|
|
58
|
-
|
|
61
|
+
const message = errorObj?.message && typeof errorObj.message === "string"
|
|
62
|
+
? errorObj.message
|
|
63
|
+
: "Unknown error";
|
|
64
|
+
return new Error(`Azure OpenAI error: ${message}`);
|
|
59
65
|
}
|
|
60
66
|
// executeGenerate removed - BaseProvider handles all generation with tools
|
|
61
67
|
async executeStream(options, analysisSchema) {
|
|
@@ -16,22 +16,31 @@ export declare class FunctionCallingProvider implements AIProvider {
|
|
|
16
16
|
private enableFunctionCalling;
|
|
17
17
|
private sessionId;
|
|
18
18
|
private userId;
|
|
19
|
+
private cachedToolsObject;
|
|
20
|
+
private cachedToolMap;
|
|
21
|
+
private cacheTimestamp;
|
|
22
|
+
private readonly cacheExpiryMs;
|
|
19
23
|
constructor(baseProvider: AIProvider, options?: {
|
|
20
24
|
enableFunctionCalling?: boolean;
|
|
21
25
|
sessionId?: string;
|
|
22
26
|
userId?: string;
|
|
27
|
+
cacheExpiryMs?: number;
|
|
23
28
|
});
|
|
24
29
|
/**
|
|
25
30
|
* PRIMARY METHOD: Stream content using AI (recommended for new code)
|
|
26
31
|
* Future-ready for multi-modal capabilities with current text focus
|
|
27
32
|
*/
|
|
28
|
-
stream(optionsOrPrompt: StreamOptions | string, analysisSchema?:
|
|
33
|
+
stream(optionsOrPrompt: StreamOptions | string, analysisSchema?: Schema): Promise<StreamResult>;
|
|
29
34
|
/**
|
|
30
35
|
* Generate text with real function calling support
|
|
31
36
|
*/
|
|
32
37
|
generate(optionsOrPrompt: TextGenerationOptions | string, analysisSchema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>): Promise<GenerateResult>;
|
|
33
38
|
/**
|
|
34
|
-
* Generate text using AI SDK's
|
|
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)
|
|
35
44
|
*/
|
|
36
45
|
private generateWithTools;
|
|
37
46
|
/**
|
|
@@ -44,7 +53,11 @@ export declare class FunctionCallingProvider implements AIProvider {
|
|
|
44
53
|
*/
|
|
45
54
|
private sanitizeToolName;
|
|
46
55
|
/**
|
|
47
|
-
*
|
|
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)
|
|
48
61
|
*/
|
|
49
62
|
private convertToAISDKTools;
|
|
50
63
|
/**
|
|
@@ -54,10 +67,57 @@ export declare class FunctionCallingProvider implements AIProvider {
|
|
|
54
67
|
/**
|
|
55
68
|
* Alias for generate() - CLI-SDK consistency
|
|
56
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;
|
|
57
117
|
/**
|
|
58
118
|
* Short alias for generate() - CLI-SDK consistency
|
|
59
119
|
*/
|
|
60
|
-
gen(optionsOrPrompt: TextGenerationOptions | string, analysisSchema?:
|
|
120
|
+
gen(optionsOrPrompt: TextGenerationOptions | string, analysisSchema?: Schema): Promise<EnhancedGenerateResult | null>;
|
|
61
121
|
}
|
|
62
122
|
/**
|
|
63
123
|
* Create a function-calling enhanced version of any AI provider
|
|
@@ -66,6 +126,7 @@ export declare function createFunctionCallingProvider(baseProvider: AIProvider,
|
|
|
66
126
|
enableFunctionCalling?: boolean;
|
|
67
127
|
sessionId?: string;
|
|
68
128
|
userId?: string;
|
|
129
|
+
cacheExpiryMs?: number;
|
|
69
130
|
}): AIProvider;
|
|
70
131
|
/**
|
|
71
132
|
* Enhanced MCP Provider Factory that creates function-calling enabled providers
|
|
@@ -77,4 +138,5 @@ export declare function createMCPAwareProviderV3(baseProvider: AIProvider, optio
|
|
|
77
138
|
enableFunctionCalling?: boolean;
|
|
78
139
|
sessionId?: string;
|
|
79
140
|
userId?: string;
|
|
141
|
+
cacheExpiryMs?: number;
|
|
80
142
|
}): AIProvider;
|