@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
|
@@ -41,7 +41,8 @@ async function listModelsHandler() {
|
|
|
41
41
|
}
|
|
42
42
|
catch (error) {
|
|
43
43
|
spinner.fail("Failed to list models. Is Ollama installed?");
|
|
44
|
-
|
|
44
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
45
|
+
console.error(chalk.red("Error:", errorMessage));
|
|
45
46
|
console.log(chalk.blue("\nTip: Install Ollama from https://ollama.ai"));
|
|
46
47
|
process.exit(1);
|
|
47
48
|
}
|
|
@@ -57,7 +58,8 @@ async function pullModelHandler(argv) {
|
|
|
57
58
|
}
|
|
58
59
|
catch (error) {
|
|
59
60
|
console.error(chalk.red(`\n❌ Failed to download ${model}`));
|
|
60
|
-
|
|
61
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
62
|
+
console.error(chalk.red("Error:", errorMessage));
|
|
61
63
|
process.exit(1);
|
|
62
64
|
}
|
|
63
65
|
}
|
|
@@ -83,7 +85,8 @@ async function removeModelHandler(argv) {
|
|
|
83
85
|
}
|
|
84
86
|
catch (error) {
|
|
85
87
|
spinner.fail(`Failed to remove ${model}`);
|
|
86
|
-
|
|
88
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
89
|
+
console.error(chalk.red("Error:", errorMessage));
|
|
87
90
|
process.exit(1);
|
|
88
91
|
}
|
|
89
92
|
}
|
|
@@ -163,7 +166,8 @@ async function startHandler() {
|
|
|
163
166
|
}
|
|
164
167
|
catch (error) {
|
|
165
168
|
console.error(chalk.red("Failed to start Ollama service"));
|
|
166
|
-
|
|
169
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
170
|
+
console.error(chalk.red("Error:", errorMessage));
|
|
167
171
|
console.log(chalk.blue("\nTry starting Ollama manually or check installation"));
|
|
168
172
|
process.exit(1);
|
|
169
173
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { CommandModule } from "yargs";
|
|
2
|
+
import type { UnknownRecord } from "../../lib/types/common.js";
|
|
2
3
|
/**
|
|
3
4
|
* CLI Command Factory for generate commands
|
|
4
5
|
*/
|
|
@@ -10,7 +11,7 @@ export declare class CLICommandFactory {
|
|
|
10
11
|
/**
|
|
11
12
|
* Execute provider status command
|
|
12
13
|
*/
|
|
13
|
-
executeProviderStatus(argv:
|
|
14
|
+
executeProviderStatus(argv: UnknownRecord): Promise<void>;
|
|
14
15
|
/**
|
|
15
16
|
* Execute the generate command
|
|
16
17
|
*/
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { NeuroLink } from "../../lib/neurolink.js";
|
|
2
2
|
import ora from "ora";
|
|
3
3
|
import chalk from "chalk";
|
|
4
|
+
import { logger } from "../../lib/utils/logger.js";
|
|
4
5
|
/**
|
|
5
6
|
* CLI Command Factory for generate commands
|
|
6
7
|
*/
|
|
@@ -161,14 +162,14 @@ export class CLICommandFactory {
|
|
|
161
162
|
console.log(result.content);
|
|
162
163
|
}
|
|
163
164
|
if (argv.debug) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
165
|
+
logger.debug("\n" + chalk.yellow("Debug Information:"));
|
|
166
|
+
logger.debug("Provider:", result.provider);
|
|
167
|
+
logger.debug("Model:", result.model);
|
|
167
168
|
if (result.analytics) {
|
|
168
|
-
|
|
169
|
+
logger.debug("Analytics:", JSON.stringify(result.analytics, null, 2));
|
|
169
170
|
}
|
|
170
171
|
if (result.evaluation) {
|
|
171
|
-
|
|
172
|
+
logger.debug("Evaluation:", JSON.stringify(result.evaluation, null, 2));
|
|
172
173
|
}
|
|
173
174
|
}
|
|
174
175
|
// Exit successfully
|
package/dist/cli/index.js
CHANGED
|
@@ -23,10 +23,6 @@ import { addMCPCommands } from "./commands/mcp.js";
|
|
|
23
23
|
import { addOllamaCommands } from "./commands/ollama.js";
|
|
24
24
|
import { CLICommandFactory } from "./factories/command-factory.js";
|
|
25
25
|
import { logger } from "../lib/utils/logger.js";
|
|
26
|
-
/**
|
|
27
|
-
* Helper functions for displaying analytics and evaluation results
|
|
28
|
-
* Addresses DRY principle - extracted shared parts into reusable functions
|
|
29
|
-
*/
|
|
30
26
|
function displayDebugInfo(title, data, debug) {
|
|
31
27
|
if (debug) {
|
|
32
28
|
console.log(chalk.blue(title));
|
|
@@ -45,11 +41,13 @@ function formatAnalytics(analytics) {
|
|
|
45
41
|
console.log(` 🚀 Provider: ${analytics.provider}`);
|
|
46
42
|
console.log(` 🤖 Model: ${analytics.model}`);
|
|
47
43
|
if (analytics.tokens) {
|
|
48
|
-
|
|
44
|
+
const tokens = analytics.tokens;
|
|
45
|
+
console.log(` 💬 Tokens: ${tokens.totalTokens || tokens.total || "unknown"}`);
|
|
49
46
|
}
|
|
50
47
|
console.log(` ⏱️ Response Time: ${analytics.responseTime}ms`);
|
|
51
48
|
if (analytics.context) {
|
|
52
|
-
|
|
49
|
+
const context = analytics.context;
|
|
50
|
+
console.log(` 📋 Context: ${Object.keys(context).length} fields`);
|
|
53
51
|
}
|
|
54
52
|
console.log();
|
|
55
53
|
}
|
|
@@ -537,24 +535,27 @@ const cli = yargs(args)
|
|
|
537
535
|
console.log("\n" + responseText + "\n");
|
|
538
536
|
}
|
|
539
537
|
// Show tool calls if any
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
538
|
+
const typedResultForTools = result;
|
|
539
|
+
if (typedResultForTools &&
|
|
540
|
+
typedResultForTools.toolCalls &&
|
|
541
|
+
typedResultForTools.toolCalls.length > 0) {
|
|
543
542
|
console.log(chalk.blue("🔧 Tools Called:"));
|
|
544
|
-
for (const toolCall of
|
|
545
|
-
|
|
546
|
-
console.log(
|
|
543
|
+
for (const toolCall of typedResultForTools.toolCalls) {
|
|
544
|
+
const toolCallObj = toolCall;
|
|
545
|
+
console.log(`- ${toolCallObj.toolName}`);
|
|
546
|
+
console.log(` Args: ${JSON.stringify(toolCallObj.args)}`);
|
|
547
547
|
}
|
|
548
548
|
console.log();
|
|
549
549
|
}
|
|
550
550
|
// Show tool results if any
|
|
551
|
-
if (
|
|
552
|
-
|
|
553
|
-
|
|
551
|
+
if (typedResultForTools &&
|
|
552
|
+
typedResultForTools.toolResults &&
|
|
553
|
+
typedResultForTools.toolResults.length > 0) {
|
|
554
554
|
console.log(chalk.blue("📋 Tool Results:"));
|
|
555
|
-
for (const toolResult of
|
|
556
|
-
|
|
557
|
-
console.log(
|
|
555
|
+
for (const toolResult of typedResultForTools.toolResults) {
|
|
556
|
+
const toolResultObj = toolResult;
|
|
557
|
+
console.log(`- ${toolResultObj.toolCallId}`);
|
|
558
|
+
console.log(` Result: ${JSON.stringify(toolResultObj.result).substring(0, 200)}...`);
|
|
558
559
|
}
|
|
559
560
|
console.log();
|
|
560
561
|
}
|
|
@@ -578,7 +579,9 @@ const cli = yargs(args)
|
|
|
578
579
|
? result.provider || argv.provider
|
|
579
580
|
: argv.provider,
|
|
580
581
|
usage: responseUsage,
|
|
581
|
-
responseTime: result
|
|
582
|
+
responseTime: result
|
|
583
|
+
? result.responseTime || 0
|
|
584
|
+
: 0,
|
|
582
585
|
}, null, 2));
|
|
583
586
|
if (responseUsage.totalTokens) {
|
|
584
587
|
console.log(chalk.blue(`ℹ️ ${responseUsage.totalTokens} tokens used`));
|
package/dist/core/analytics.d.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
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 { JsonValue, UnknownRecord } from "../types/common.js";
|
|
7
8
|
export interface AnalyticsData {
|
|
8
9
|
provider: string;
|
|
9
10
|
model: string;
|
|
@@ -14,10 +15,10 @@ export interface AnalyticsData {
|
|
|
14
15
|
};
|
|
15
16
|
cost?: number;
|
|
16
17
|
responseTime: number;
|
|
17
|
-
context?: Record<string,
|
|
18
|
+
context?: Record<string, JsonValue>;
|
|
18
19
|
timestamp: string;
|
|
19
20
|
}
|
|
20
21
|
/**
|
|
21
22
|
* Create analytics data structure from AI response
|
|
22
23
|
*/
|
|
23
|
-
export declare function createAnalytics(provider: string, model: string, result:
|
|
24
|
+
export declare function createAnalytics(provider: string, model: string, result: UnknownRecord, responseTime: number, context?: Record<string, JsonValue>): AnalyticsData;
|
package/dist/core/analytics.js
CHANGED
|
@@ -51,23 +51,30 @@ export function createAnalytics(provider, model, result, responseTime, context)
|
|
|
51
51
|
*/
|
|
52
52
|
function extractTokenUsage(result) {
|
|
53
53
|
// Handle different response formats
|
|
54
|
-
if (result.usage
|
|
54
|
+
if (result.usage &&
|
|
55
|
+
typeof result.usage === "object" &&
|
|
56
|
+
result.usage !== null) {
|
|
55
57
|
const usage = result.usage;
|
|
56
58
|
// Standard format
|
|
57
|
-
if (usage.promptTokens
|
|
58
|
-
usage.completionTokens
|
|
59
|
+
if (typeof usage.promptTokens === "number" &&
|
|
60
|
+
typeof usage.completionTokens === "number") {
|
|
59
61
|
return {
|
|
60
62
|
input: usage.promptTokens || 0,
|
|
61
63
|
output: usage.completionTokens || 0,
|
|
62
|
-
total: usage.totalTokens
|
|
64
|
+
total: typeof usage.totalTokens === "number"
|
|
65
|
+
? usage.totalTokens
|
|
66
|
+
: usage.promptTokens + usage.completionTokens,
|
|
63
67
|
};
|
|
64
68
|
}
|
|
65
69
|
// Alternative formats
|
|
66
|
-
if (usage.input_tokens
|
|
70
|
+
if (typeof usage.input_tokens === "number" &&
|
|
71
|
+
typeof usage.output_tokens === "number") {
|
|
67
72
|
return {
|
|
68
73
|
input: usage.input_tokens || 0,
|
|
69
74
|
output: usage.output_tokens || 0,
|
|
70
|
-
total: usage.total_tokens
|
|
75
|
+
total: typeof usage.total_tokens === "number"
|
|
76
|
+
? usage.total_tokens
|
|
77
|
+
: usage.input_tokens + usage.output_tokens,
|
|
71
78
|
};
|
|
72
79
|
}
|
|
73
80
|
// Generic tokens field
|
|
@@ -80,7 +87,9 @@ function extractTokenUsage(result) {
|
|
|
80
87
|
}
|
|
81
88
|
}
|
|
82
89
|
// Fallback: estimate from text length
|
|
83
|
-
const textLength = result.text
|
|
90
|
+
const textLength = (typeof result.text === "string" ? result.text.length : 0) ||
|
|
91
|
+
(typeof result.content === "string" ? result.content.length : 0) ||
|
|
92
|
+
0;
|
|
84
93
|
const estimatedTokens = Math.ceil(textLength / 4); // ~4 chars per token
|
|
85
94
|
return {
|
|
86
95
|
input: 0,
|
|
@@ -1,8 +1,35 @@
|
|
|
1
1
|
import type { ZodType, ZodTypeDef } from "zod";
|
|
2
2
|
import type { Schema } from "ai";
|
|
3
|
-
import type { Tool } from "ai";
|
|
4
|
-
import type { AIProvider, TextGenerationOptions, EnhancedGenerateResult, AnalyticsData, AIProviderName } from "../core/types.js";
|
|
3
|
+
import type { Tool, LanguageModel } from "ai";
|
|
4
|
+
import type { AIProvider, TextGenerationOptions, EnhancedGenerateResult, AnalyticsData, AIProviderName, EvaluationData } from "../core/types.js";
|
|
5
5
|
import type { StreamOptions, StreamResult } from "../types/stream-types.js";
|
|
6
|
+
import type { JsonValue, UnknownRecord } from "../types/common.js";
|
|
7
|
+
import type { ToolResult } from "../types/tools.js";
|
|
8
|
+
/**
|
|
9
|
+
* Interface for SDK with in-memory MCP servers
|
|
10
|
+
*/
|
|
11
|
+
export interface NeuroLinkSDK {
|
|
12
|
+
getInMemoryServers?: () => Map<string, {
|
|
13
|
+
server: {
|
|
14
|
+
title?: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
tools?: Map<string, ToolInfo> | Record<string, ToolInfo>;
|
|
17
|
+
};
|
|
18
|
+
category?: string;
|
|
19
|
+
metadata?: UnknownRecord;
|
|
20
|
+
}>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Interface for tool information in MCP servers
|
|
24
|
+
*/
|
|
25
|
+
interface ToolInfo {
|
|
26
|
+
description?: string;
|
|
27
|
+
inputSchema?: ZodType<JsonValue>;
|
|
28
|
+
parameters?: ZodType<JsonValue>;
|
|
29
|
+
execute: (args: JsonValue) => Promise<JsonValue | ToolResult> | JsonValue | ToolResult;
|
|
30
|
+
isImplemented?: boolean;
|
|
31
|
+
metadata?: UnknownRecord;
|
|
32
|
+
}
|
|
6
33
|
/**
|
|
7
34
|
* Abstract base class for all AI providers
|
|
8
35
|
* Tools are integrated as first-class citizens - always available by default
|
|
@@ -354,8 +381,8 @@ export declare abstract class BaseProvider implements AIProvider {
|
|
|
354
381
|
protected mcpTools?: Record<string, Tool>;
|
|
355
382
|
protected sessionId?: string;
|
|
356
383
|
protected userId?: string;
|
|
357
|
-
protected sdk?:
|
|
358
|
-
constructor(modelName?: string, providerName?: AIProviderName, sdk?:
|
|
384
|
+
protected sdk?: NeuroLinkSDK;
|
|
385
|
+
constructor(modelName?: string, providerName?: AIProviderName, sdk?: NeuroLinkSDK);
|
|
359
386
|
/**
|
|
360
387
|
* Check if this provider supports tool/function calling
|
|
361
388
|
* Override in subclasses to disable tools for specific providers or models
|
|
@@ -392,7 +419,7 @@ export declare abstract class BaseProvider implements AIProvider {
|
|
|
392
419
|
* REQUIRED: Every provider MUST implement this method
|
|
393
420
|
* Returns the Vercel AI SDK model instance for this provider
|
|
394
421
|
*/
|
|
395
|
-
protected abstract getAISDKModel():
|
|
422
|
+
protected abstract getAISDKModel(): LanguageModel | Promise<LanguageModel>;
|
|
396
423
|
/**
|
|
397
424
|
* Get all available tools - direct tools are ALWAYS available
|
|
398
425
|
* MCP tools are added when available (without blocking)
|
|
@@ -405,12 +432,12 @@ export declare abstract class BaseProvider implements AIProvider {
|
|
|
405
432
|
/**
|
|
406
433
|
* Provider-specific error handling
|
|
407
434
|
*/
|
|
408
|
-
protected abstract handleProviderError(error:
|
|
435
|
+
protected abstract handleProviderError(error: unknown): Error;
|
|
409
436
|
protected normalizeTextOptions(optionsOrPrompt: TextGenerationOptions | string): TextGenerationOptions;
|
|
410
437
|
protected normalizeStreamOptions(optionsOrPrompt: StreamOptions | string): StreamOptions;
|
|
411
438
|
protected enhanceResult(result: EnhancedGenerateResult, options: TextGenerationOptions, startTime: number): Promise<EnhancedGenerateResult>;
|
|
412
439
|
protected createAnalytics(result: EnhancedGenerateResult, responseTime: number, options: TextGenerationOptions): Promise<AnalyticsData>;
|
|
413
|
-
protected createEvaluation(result: EnhancedGenerateResult, options: TextGenerationOptions): Promise<
|
|
440
|
+
protected createEvaluation(result: EnhancedGenerateResult, options: TextGenerationOptions): Promise<EvaluationData>;
|
|
414
441
|
protected validateOptions(options: TextGenerationOptions): void;
|
|
415
442
|
protected getProviderInfo(): {
|
|
416
443
|
provider: string;
|
|
@@ -421,3 +448,4 @@ export declare abstract class BaseProvider implements AIProvider {
|
|
|
421
448
|
*/
|
|
422
449
|
getTimeout(options: TextGenerationOptions | StreamOptions): number;
|
|
423
450
|
}
|
|
451
|
+
export {};
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import { logger } from "../utils/logger.js";
|
|
2
2
|
import { directAgentTools } from "../agent/direct-tools.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Validates if a result contains a valid toolsObject structure
|
|
5
|
+
* @param result - The result object to validate
|
|
6
|
+
* @returns true if the result contains a valid toolsObject, false otherwise
|
|
7
|
+
*/
|
|
8
|
+
function isValidToolsObject(result) {
|
|
9
|
+
return (result !== null &&
|
|
10
|
+
typeof result === "object" &&
|
|
11
|
+
"toolsObject" in result &&
|
|
12
|
+
result.toolsObject !== null &&
|
|
13
|
+
typeof result.toolsObject === "object" &&
|
|
14
|
+
Object.keys(result.toolsObject).length > 0);
|
|
15
|
+
}
|
|
7
16
|
/**
|
|
8
17
|
* Abstract base class for all AI providers
|
|
9
18
|
* Tools are integrated as first-class citizens - always available by default
|
|
@@ -89,7 +98,16 @@ export class BaseProvider {
|
|
|
89
98
|
parameters: call.args,
|
|
90
99
|
id: call.toolCallId,
|
|
91
100
|
})),
|
|
92
|
-
toolResults: result?.toolResults
|
|
101
|
+
toolResults: result?.toolResults
|
|
102
|
+
? result.toolResults.map((tr) => ({
|
|
103
|
+
toolName: tr.toolName || "unknown",
|
|
104
|
+
status: (tr.status === "error"
|
|
105
|
+
? "failure"
|
|
106
|
+
: "success"),
|
|
107
|
+
result: tr.result,
|
|
108
|
+
error: tr.error,
|
|
109
|
+
}))
|
|
110
|
+
: undefined,
|
|
93
111
|
};
|
|
94
112
|
}
|
|
95
113
|
catch (error) {
|
|
@@ -142,7 +160,19 @@ export class BaseProvider {
|
|
|
142
160
|
},
|
|
143
161
|
provider: this.providerName,
|
|
144
162
|
model: this.modelName,
|
|
145
|
-
toolCalls: result.toolCalls
|
|
163
|
+
toolCalls: result.toolCalls
|
|
164
|
+
? result.toolCalls.map((tc) => ({
|
|
165
|
+
toolCallId: tc.toolCallId ||
|
|
166
|
+
tc.id ||
|
|
167
|
+
"unknown",
|
|
168
|
+
toolName: tc.toolName ||
|
|
169
|
+
tc.name ||
|
|
170
|
+
"unknown",
|
|
171
|
+
args: tc.args ||
|
|
172
|
+
tc.parameters ||
|
|
173
|
+
{},
|
|
174
|
+
}))
|
|
175
|
+
: [],
|
|
146
176
|
toolResults: result.toolResults,
|
|
147
177
|
};
|
|
148
178
|
// Enhanced result with analytics and evaluation
|
|
@@ -170,16 +200,15 @@ export class BaseProvider {
|
|
|
170
200
|
const tools = {
|
|
171
201
|
...this.directTools, // Always include direct tools
|
|
172
202
|
};
|
|
173
|
-
logger.
|
|
174
|
-
|
|
203
|
+
logger.debug(`[BaseProvider] getAllTools called, SDK available: ${!!this.sdk}, type: ${typeof this.sdk}`);
|
|
204
|
+
logger.debug(`[BaseProvider] Direct tools: ${Object.keys(this.directTools).join(", ")}`);
|
|
175
205
|
// Add custom tools from SDK if available
|
|
176
|
-
|
|
177
|
-
if (this.sdk &&
|
|
178
|
-
|
|
179
|
-
console.log(`[BaseProvider] SDK check passed, loading custom tools`);
|
|
206
|
+
logger.debug(`[BaseProvider] Checking SDK: ${!!this.sdk}, has getInMemoryServers: ${this.sdk && typeof this.sdk.getInMemoryServers}`);
|
|
207
|
+
if (this.sdk && typeof this.sdk.getInMemoryServers === "function") {
|
|
208
|
+
logger.debug(`[BaseProvider] SDK check passed, loading custom tools`);
|
|
180
209
|
try {
|
|
181
210
|
const inMemoryServers = this.sdk.getInMemoryServers();
|
|
182
|
-
|
|
211
|
+
logger.debug(`[BaseProvider] Got servers:`, inMemoryServers.size);
|
|
183
212
|
logger.debug(`[BaseProvider] Loading custom tools from SDK, found ${inMemoryServers.size} servers`);
|
|
184
213
|
if (inMemoryServers && inMemoryServers.size > 0) {
|
|
185
214
|
// Convert in-memory server tools to AI SDK format
|
|
@@ -192,7 +221,7 @@ export class BaseProvider {
|
|
|
192
221
|
: Object.entries(server.tools || {});
|
|
193
222
|
for (const [toolName, toolInfo] of toolEntries) {
|
|
194
223
|
if (toolInfo && typeof toolInfo.execute === "function") {
|
|
195
|
-
|
|
224
|
+
logger.debug(`[BaseProvider] Converting custom tool: ${toolName}`);
|
|
196
225
|
// Convert to AI SDK tool format
|
|
197
226
|
const { tool: createAISDKTool } = await import("ai");
|
|
198
227
|
const { z } = await import("zod");
|
|
@@ -211,7 +240,10 @@ export class BaseProvider {
|
|
|
211
240
|
return result.data;
|
|
212
241
|
}
|
|
213
242
|
else {
|
|
214
|
-
|
|
243
|
+
const errorMsg = typeof result.error === "string"
|
|
244
|
+
? result.error
|
|
245
|
+
: "Tool execution failed";
|
|
246
|
+
throw new Error(errorMsg);
|
|
215
247
|
}
|
|
216
248
|
}
|
|
217
249
|
return result;
|
|
@@ -233,12 +265,13 @@ export class BaseProvider {
|
|
|
233
265
|
try {
|
|
234
266
|
const { getAvailableFunctionTools } = await import("../mcp/function-calling.js");
|
|
235
267
|
const result = await getAvailableFunctionTools();
|
|
236
|
-
if (result
|
|
237
|
-
this.mcpTools =
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
268
|
+
if (isValidToolsObject(result)) {
|
|
269
|
+
this.mcpTools = result.toolsObject;
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
logger.debug(`Invalid or empty toolsObject for ${this.providerName}: Expected an object with at least one key, but got ${typeof result?.toolsObject} with ${result?.toolsObject
|
|
273
|
+
? Object.keys(result.toolsObject).length
|
|
274
|
+
: 0} keys. Full result:`, result);
|
|
242
275
|
}
|
|
243
276
|
}
|
|
244
277
|
catch (error) {
|
|
@@ -250,7 +283,7 @@ export class BaseProvider {
|
|
|
250
283
|
if (this.mcpTools) {
|
|
251
284
|
Object.assign(tools, this.mcpTools);
|
|
252
285
|
}
|
|
253
|
-
|
|
286
|
+
logger.debug(`[BaseProvider] getAllTools returning tools: ${Object.keys(tools).join(", ")}`);
|
|
254
287
|
return tools;
|
|
255
288
|
}
|
|
256
289
|
/**
|
|
@@ -325,7 +358,8 @@ export class BaseProvider {
|
|
|
325
358
|
}
|
|
326
359
|
async createEvaluation(result, options) {
|
|
327
360
|
const { evaluateResponse } = await import("../core/evaluation.js");
|
|
328
|
-
|
|
361
|
+
const evaluation = await evaluateResponse(result.content, options.prompt);
|
|
362
|
+
return evaluation;
|
|
329
363
|
}
|
|
330
364
|
validateOptions(options) {
|
|
331
365
|
if (!options.prompt || options.prompt.trim().length === 0) {
|
package/dist/core/constants.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
export declare const DEFAULT_MAX_TOKENS = 8192;
|
|
6
6
|
export declare const DEFAULT_TEMPERATURE = 0.7;
|
|
7
7
|
export declare const DEFAULT_TIMEOUT = 30000;
|
|
8
|
+
export declare const DEFAULT_MAX_STEPS = 5;
|
|
8
9
|
export declare const DEFAULT_EVALUATION_MAX_TOKENS = 500;
|
|
9
10
|
export declare const DEFAULT_ANALYSIS_MAX_TOKENS = 800;
|
|
10
11
|
export declare const DEFAULT_DOCUMENTATION_MAX_TOKENS = 12000;
|
package/dist/core/constants.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
export const DEFAULT_MAX_TOKENS = 8192; // Changed from 10000 to fix Anthropic error
|
|
7
7
|
export const DEFAULT_TEMPERATURE = 0.7;
|
|
8
8
|
export const DEFAULT_TIMEOUT = 30000;
|
|
9
|
+
export const DEFAULT_MAX_STEPS = 5; // Default multi-turn tool execution steps
|
|
9
10
|
// Specialized Use Case Defaults
|
|
10
11
|
export const DEFAULT_EVALUATION_MAX_TOKENS = 500; // Keep evaluation fast
|
|
11
12
|
export const DEFAULT_ANALYSIS_MAX_TOKENS = 800; // For analysis tools
|
package/dist/core/defaults.d.ts
CHANGED
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
* Default value helper functions for NeuroLink
|
|
3
3
|
* Centralized logic for applying defaults across the system
|
|
4
4
|
*/
|
|
5
|
+
import type { UnknownRecord } from "../types/common.js";
|
|
5
6
|
/**
|
|
6
7
|
* Apply default values to options object
|
|
7
8
|
* User-provided values take precedence over defaults
|
|
8
9
|
*/
|
|
9
|
-
export declare function applyDefaults(options:
|
|
10
|
+
export declare function applyDefaults(options: UnknownRecord): UnknownRecord;
|
|
10
11
|
/**
|
|
11
12
|
* Get default max tokens for a specific provider
|
|
12
13
|
* Can be extended for provider-specific overrides in the future
|
|
@@ -23,7 +23,7 @@ export interface UnifiedEvaluationResult extends EvaluationData {
|
|
|
23
23
|
export interface UnifiedEvaluationContext {
|
|
24
24
|
userQuery: string;
|
|
25
25
|
aiResponse: string;
|
|
26
|
-
context?: Record<string,
|
|
26
|
+
context?: Record<string, unknown>;
|
|
27
27
|
primaryDomain?: string;
|
|
28
28
|
assistantRole?: string;
|
|
29
29
|
conversationHistory?: Array<{
|
|
@@ -33,8 +33,8 @@ export interface UnifiedEvaluationContext {
|
|
|
33
33
|
}>;
|
|
34
34
|
toolUsage?: Array<{
|
|
35
35
|
toolName: string;
|
|
36
|
-
input:
|
|
37
|
-
output:
|
|
36
|
+
input: unknown;
|
|
37
|
+
output: unknown;
|
|
38
38
|
executionTime: number;
|
|
39
39
|
}>;
|
|
40
40
|
expectedOutcome?: string;
|
|
@@ -52,5 +52,5 @@ declare function parseUnifiedEvaluationResult(response: string, context: Unified
|
|
|
52
52
|
* Main unified evaluation function
|
|
53
53
|
*/
|
|
54
54
|
export declare function generateUnifiedEvaluation(context: UnifiedEvaluationContext): Promise<UnifiedEvaluationResult>;
|
|
55
|
-
export declare function evaluateResponse(responseOrContext:
|
|
55
|
+
export declare function evaluateResponse(responseOrContext: unknown, contextOrUserQuery?: unknown, userQuery?: unknown, providedContexts?: unknown, options?: unknown, additionalArgs?: unknown): Promise<unknown>;
|
|
56
56
|
export { getDefaultUnifiedEvaluation, parseUnifiedEvaluationResult };
|
package/dist/core/evaluation.js
CHANGED
|
@@ -90,7 +90,19 @@ function parseUnifiedEvaluationResult(response, context) {
|
|
|
90
90
|
if (match) {
|
|
91
91
|
const value = parseFloat(match[1]);
|
|
92
92
|
if (value >= 1 && value <= 10) {
|
|
93
|
-
|
|
93
|
+
const roundedValue = Math.round(value);
|
|
94
|
+
if (key === "relevance") {
|
|
95
|
+
result.relevance = roundedValue;
|
|
96
|
+
}
|
|
97
|
+
else if (key === "accuracy") {
|
|
98
|
+
result.accuracy = roundedValue;
|
|
99
|
+
}
|
|
100
|
+
else if (key === "completeness") {
|
|
101
|
+
result.completeness = roundedValue;
|
|
102
|
+
}
|
|
103
|
+
else if (key === "overall") {
|
|
104
|
+
result.overall = roundedValue;
|
|
105
|
+
}
|
|
94
106
|
}
|
|
95
107
|
}
|
|
96
108
|
}
|
|
@@ -163,9 +175,7 @@ Overall: [score]
|
|
|
163
175
|
return getDefaultUnifiedEvaluation("no-response", Date.now() - startTime, context);
|
|
164
176
|
}
|
|
165
177
|
// Extract text from result
|
|
166
|
-
const response = typeof result === "string"
|
|
167
|
-
? result
|
|
168
|
-
: result.text || String(result);
|
|
178
|
+
const response = typeof result === "string" ? result : result?.content || String(result);
|
|
169
179
|
// Parse evaluation result
|
|
170
180
|
const parsed = parseUnifiedEvaluationResult(response, context);
|
|
171
181
|
// Validate and enhance result
|
|
@@ -216,12 +226,12 @@ export async function evaluateResponse(responseOrContext, contextOrUserQuery, us
|
|
|
216
226
|
String(contextOrUserQuery || "");
|
|
217
227
|
}
|
|
218
228
|
const evalContext = {
|
|
219
|
-
userQuery: userQuery ||
|
|
229
|
+
userQuery: (typeof userQuery === "string" ? userQuery : "") ||
|
|
220
230
|
context?.userQuery ||
|
|
221
|
-
contextOrUserQuery ||
|
|
231
|
+
(typeof contextOrUserQuery === "string" ? contextOrUserQuery : "") ||
|
|
222
232
|
"Generated response",
|
|
223
233
|
aiResponse,
|
|
224
|
-
context,
|
|
234
|
+
context: context,
|
|
225
235
|
};
|
|
226
236
|
return generateUnifiedEvaluation(evalContext);
|
|
227
237
|
}
|
package/dist/core/factory.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AIProvider, AIProviderName, SupportedModelName } from "./types.js";
|
|
2
|
+
import type { UnknownRecord } from "../types/common.js";
|
|
2
3
|
declare const componentIdentifier = "aiProviderFactory";
|
|
3
4
|
/**
|
|
4
5
|
* Factory for creating AI provider instances with centralized configuration
|
|
@@ -15,7 +16,7 @@ export declare class AIProviderFactory {
|
|
|
15
16
|
* @param enableMCP - Optional flag to enable MCP integration (default: true)
|
|
16
17
|
* @returns AIProvider instance
|
|
17
18
|
*/
|
|
18
|
-
static createProvider(providerName: string, modelName?: string | null, enableMCP?: boolean, sdk?:
|
|
19
|
+
static createProvider(providerName: string, modelName?: string | null, enableMCP?: boolean, sdk?: UnknownRecord): Promise<AIProvider>;
|
|
19
20
|
/**
|
|
20
21
|
* Create a provider instance with specific provider enum and model
|
|
21
22
|
* @param provider - Provider enum value
|
|
@@ -30,7 +31,7 @@ export declare class AIProviderFactory {
|
|
|
30
31
|
* @param enableMCP - Optional flag to enable MCP integration (default: true)
|
|
31
32
|
* @returns AIProvider instance
|
|
32
33
|
*/
|
|
33
|
-
static createBestProvider(requestedProvider?: string, modelName?: string | null, enableMCP?: boolean, sdk?:
|
|
34
|
+
static createBestProvider(requestedProvider?: string, modelName?: string | null, enableMCP?: boolean, sdk?: UnknownRecord): Promise<AIProvider>;
|
|
34
35
|
/**
|
|
35
36
|
* Create primary and fallback provider instances
|
|
36
37
|
* @param primaryProvider - Primary provider name
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
* Service Registry for Dependency Injection
|
|
3
3
|
* Breaks circular dependencies by providing lazy loading and centralized service management
|
|
4
4
|
*/
|
|
5
|
-
export interface ServiceFactory<T =
|
|
5
|
+
export interface ServiceFactory<T = unknown> {
|
|
6
6
|
(): T | Promise<T>;
|
|
7
7
|
}
|
|
8
|
-
export interface ServiceRegistration {
|
|
9
|
-
factory: ServiceFactory
|
|
8
|
+
export interface ServiceRegistration<T = unknown> {
|
|
9
|
+
factory: ServiceFactory<T>;
|
|
10
10
|
singleton: boolean;
|
|
11
|
-
instance?:
|
|
11
|
+
instance?: T;
|
|
12
12
|
}
|
|
13
13
|
export declare class ServiceRegistry {
|
|
14
14
|
private static services;
|
package/dist/core/types.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { ZodType, ZodTypeDef } from "zod";
|
|
|
2
2
|
import type { Schema, Tool } from "ai";
|
|
3
3
|
import type { GenerateResult } from "../types/generate-types.js";
|
|
4
4
|
import type { StreamOptions, StreamResult } from "../types/stream-types.js";
|
|
5
|
+
import type { JsonValue } from "../types/common.js";
|
|
5
6
|
export interface TextGenerationResult {
|
|
6
7
|
content: string;
|
|
7
8
|
provider?: string;
|
|
@@ -26,8 +27,14 @@ export interface TextGenerationResult {
|
|
|
26
27
|
server: string;
|
|
27
28
|
category?: string;
|
|
28
29
|
}>;
|
|
29
|
-
analytics?:
|
|
30
|
-
evaluation?:
|
|
30
|
+
analytics?: AnalyticsData;
|
|
31
|
+
evaluation?: {
|
|
32
|
+
relevance: number;
|
|
33
|
+
accuracy: number;
|
|
34
|
+
completeness: number;
|
|
35
|
+
overall: number;
|
|
36
|
+
reasoning?: string;
|
|
37
|
+
};
|
|
31
38
|
}
|
|
32
39
|
/**
|
|
33
40
|
* Supported AI Provider Names
|
|
@@ -118,7 +125,7 @@ export interface TextGenerationOptions {
|
|
|
118
125
|
maxSteps?: number;
|
|
119
126
|
enableEvaluation?: boolean;
|
|
120
127
|
enableAnalytics?: boolean;
|
|
121
|
-
context?: Record<string,
|
|
128
|
+
context?: Record<string, JsonValue>;
|
|
122
129
|
evaluationDomain?: string;
|
|
123
130
|
toolUsageContext?: string;
|
|
124
131
|
conversationHistory?: Array<{
|
|
@@ -140,7 +147,7 @@ export interface AnalyticsData {
|
|
|
140
147
|
cost?: number;
|
|
141
148
|
responseTime: number;
|
|
142
149
|
timestamp: string;
|
|
143
|
-
context?: Record<string,
|
|
150
|
+
context?: Record<string, JsonValue>;
|
|
144
151
|
}
|
|
145
152
|
/**
|
|
146
153
|
* Response quality evaluation scores (Lighthouse-Compatible Schema)
|