@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
|
@@ -1,160 +1,168 @@
|
|
|
1
1
|
import { createMistral } from "@ai-sdk/mistral";
|
|
2
|
-
import { streamText
|
|
2
|
+
import { streamText } from "ai";
|
|
3
3
|
import { BaseProvider } from "../core/base-provider.js";
|
|
4
4
|
import { logger } from "../utils/logger.js";
|
|
5
|
-
import {
|
|
6
|
-
import { DEFAULT_MAX_TOKENS } from "../core/constants.js";
|
|
5
|
+
import { createAnalytics } from "./analytics-helper.js";
|
|
7
6
|
// Configuration helpers
|
|
8
7
|
const getMistralApiKey = () => {
|
|
9
8
|
const apiKey = process.env.MISTRAL_API_KEY;
|
|
10
9
|
if (!apiKey) {
|
|
11
|
-
throw new Error(
|
|
10
|
+
throw new Error("Mistral API key not found. Please set MISTRAL_API_KEY environment variable.");
|
|
12
11
|
}
|
|
13
12
|
return apiKey;
|
|
14
13
|
};
|
|
15
14
|
const getDefaultMistralModel = () => {
|
|
16
|
-
return process.env.MISTRAL_MODEL || "mistral-
|
|
17
|
-
};
|
|
18
|
-
const hasMistralCredentials = () => {
|
|
19
|
-
return !!process.env.MISTRAL_API_KEY;
|
|
15
|
+
return process.env.MISTRAL_MODEL || "mistral-large-latest";
|
|
20
16
|
};
|
|
21
17
|
/**
|
|
22
18
|
* Mistral AI Provider v2 - BaseProvider Implementation
|
|
23
|
-
*
|
|
24
|
-
* PHASE 3.6: Simple BaseProvider wrap around existing @ai-sdk/mistral implementation
|
|
25
|
-
*
|
|
26
|
-
* Features:
|
|
27
|
-
* - Extends BaseProvider for shared functionality
|
|
28
|
-
* - Uses pre-configured Mistral instance for efficiency
|
|
29
|
-
* - Enhanced error handling with setup guidance
|
|
30
|
-
* - Supports all Mistral models (mistral-small, mistral-medium, mistral-large)
|
|
19
|
+
* Supports official AI-SDK integration with all Mistral models
|
|
31
20
|
*/
|
|
32
21
|
export class MistralProvider extends BaseProvider {
|
|
33
|
-
mistral;
|
|
34
22
|
model;
|
|
35
23
|
constructor(modelName, sdk) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
// Initialize Mistral
|
|
42
|
-
|
|
43
|
-
|
|
24
|
+
// Type guard for NeuroLinkSDK parameter validation
|
|
25
|
+
const validatedSdk = sdk && typeof sdk === "object" && "getInMemoryServers" in sdk
|
|
26
|
+
? sdk
|
|
27
|
+
: undefined;
|
|
28
|
+
super(modelName, "mistral", validatedSdk);
|
|
29
|
+
// Initialize Mistral model with API key validation
|
|
30
|
+
const apiKey = getMistralApiKey();
|
|
31
|
+
const mistral = createMistral({
|
|
32
|
+
apiKey: apiKey,
|
|
44
33
|
});
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
logger.debug("Mistral AI BaseProvider v2 initialized", {
|
|
34
|
+
this.model = mistral(this.modelName || getDefaultMistralModel());
|
|
35
|
+
logger.debug("Mistral Provider v2 initialized", {
|
|
48
36
|
modelName: this.modelName,
|
|
49
|
-
|
|
37
|
+
providerName: this.providerName,
|
|
50
38
|
});
|
|
51
39
|
}
|
|
52
|
-
getProviderName() {
|
|
53
|
-
return "mistral";
|
|
54
|
-
}
|
|
55
|
-
getDefaultModel() {
|
|
56
|
-
return getDefaultMistralModel();
|
|
57
|
-
}
|
|
58
40
|
/**
|
|
59
|
-
*
|
|
41
|
+
* Generate text using Mistral API
|
|
60
42
|
*/
|
|
61
|
-
|
|
62
|
-
|
|
43
|
+
async generate(options) {
|
|
44
|
+
const startTime = Date.now();
|
|
45
|
+
try {
|
|
46
|
+
const result = await this.model.doGenerate({
|
|
47
|
+
inputFormat: "prompt",
|
|
48
|
+
mode: { type: "regular" },
|
|
49
|
+
prompt: [
|
|
50
|
+
{
|
|
51
|
+
role: "user",
|
|
52
|
+
content: [{ type: "text", text: options.prompt || "" }],
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
temperature: options.temperature,
|
|
56
|
+
maxTokens: options.maxTokens,
|
|
57
|
+
});
|
|
58
|
+
const responseTime = Date.now() - startTime;
|
|
59
|
+
// Extract token usage and text content
|
|
60
|
+
const tokenUsage = result.usage;
|
|
61
|
+
const textContent = result.text || "";
|
|
62
|
+
// Create analytics data using helper
|
|
63
|
+
const analytics = createAnalytics("mistral", this.modelName, { usage: tokenUsage, content: textContent }, responseTime, { requestId: `mistral-${Date.now()}` });
|
|
64
|
+
return {
|
|
65
|
+
content: textContent,
|
|
66
|
+
usage: {
|
|
67
|
+
inputTokens: tokenUsage?.promptTokens || 0,
|
|
68
|
+
outputTokens: tokenUsage?.completionTokens || 0,
|
|
69
|
+
totalTokens: (tokenUsage?.promptTokens || 0) +
|
|
70
|
+
(tokenUsage?.completionTokens || 0),
|
|
71
|
+
},
|
|
72
|
+
provider: this.providerName,
|
|
73
|
+
model: this.modelName,
|
|
74
|
+
analytics,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
const responseTime = Date.now() - startTime;
|
|
79
|
+
logger.error("Mistral generation failed", {
|
|
80
|
+
error: error instanceof Error ? error.message : String(error),
|
|
81
|
+
responseTime,
|
|
82
|
+
});
|
|
83
|
+
throw new Error(`Mistral generation failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
84
|
+
}
|
|
63
85
|
}
|
|
64
|
-
|
|
65
|
-
|
|
86
|
+
/**
|
|
87
|
+
* Stream text generation using Mistral API
|
|
88
|
+
*/
|
|
89
|
+
async executeStream(options) {
|
|
90
|
+
const startTime = Date.now();
|
|
66
91
|
try {
|
|
67
|
-
|
|
68
|
-
const result = await streamText({
|
|
92
|
+
const stream = await streamText({
|
|
69
93
|
model: this.model,
|
|
70
|
-
prompt: options.
|
|
71
|
-
system: options.systemPrompt,
|
|
72
|
-
maxTokens: options.maxTokens || DEFAULT_MAX_TOKENS,
|
|
94
|
+
prompt: options.prompt || "",
|
|
73
95
|
temperature: options.temperature,
|
|
96
|
+
maxTokens: options.maxTokens,
|
|
74
97
|
});
|
|
75
98
|
return {
|
|
76
99
|
stream: (async function* () {
|
|
77
|
-
for await (const chunk of
|
|
100
|
+
for await (const chunk of stream.textStream) {
|
|
78
101
|
yield { content: chunk };
|
|
79
102
|
}
|
|
80
103
|
})(),
|
|
81
104
|
provider: this.providerName,
|
|
82
105
|
model: this.modelName,
|
|
106
|
+
metadata: {
|
|
107
|
+
startTime,
|
|
108
|
+
},
|
|
83
109
|
};
|
|
84
110
|
}
|
|
85
111
|
catch (error) {
|
|
86
|
-
|
|
112
|
+
logger.error("Mistral streaming failed", {
|
|
113
|
+
error: error instanceof Error ? error.message : String(error),
|
|
114
|
+
});
|
|
115
|
+
throw new Error(`Mistral streaming failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
87
116
|
}
|
|
88
117
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
error.message?.includes("Unauthorized")) {
|
|
95
|
-
return new Error(`❌ Mistral AI Authentication Error\n\nYour API key is invalid or expired.\n\n🔧 Steps to Fix:\n1. Check your MISTRAL_API_KEY in .env file\n2. Verify the API key is correct and active\n3. Generate a new API key if needed at https://console.mistral.ai/\n4. Restart your application after updating`);
|
|
96
|
-
}
|
|
97
|
-
if (error.message?.includes("403") ||
|
|
98
|
-
error.message?.includes("Forbidden")) {
|
|
99
|
-
return new Error(`❌ Mistral AI Access Denied\n\nYour account doesn't have permission to access this model.\n\n🔧 Possible Solutions:\n1. Check if your account has access to the model: ${this.modelName}\n2. Try a different model (e.g., 'mistral-small')\n3. Verify your subscription status\n4. Contact Mistral AI support if needed`);
|
|
100
|
-
}
|
|
101
|
-
if (error.message?.includes("429") ||
|
|
102
|
-
error.message?.includes("rate limit")) {
|
|
103
|
-
return new Error(`❌ Mistral AI Rate Limit Exceeded\n\n${error.message}\n\n🔧 Solutions:\n1. Wait a moment before retrying\n2. Reduce request frequency\n3. Check your usage quotas\n4. Consider upgrading your plan`);
|
|
104
|
-
}
|
|
105
|
-
if (error.message?.includes("400") ||
|
|
106
|
-
error.message?.includes("Bad Request")) {
|
|
107
|
-
return new Error(`❌ Mistral AI Invalid Request\n\n${error.message}\n\n🔧 Check:\n1. Input text is properly formatted\n2. Model name is correct: ${this.modelName}\n3. Parameters are within limits\n4. Request format matches API requirements`);
|
|
108
|
-
}
|
|
109
|
-
if (error.message?.includes("404") ||
|
|
110
|
-
error.message?.includes("Not Found")) {
|
|
111
|
-
return new Error(`❌ Mistral AI Model Not Found\n\nModel '${this.modelName}' is not available.\n\n🔧 Available Models:\n- mistral-small (fastest, cost-effective)\n- mistral-medium (balanced performance)\n- mistral-large (highest quality)\n\n🔧 Fix: Update MISTRAL_MODEL environment variable`);
|
|
112
|
-
}
|
|
113
|
-
return new Error(`❌ Mistral AI Provider Error\n\n${error.message || "Unknown error occurred"}\n\n🔧 Troubleshooting:\n1. Check API key and network connectivity\n2. Verify model availability\n3. Review request parameters\n4. Check Mistral AI status page`);
|
|
118
|
+
/**
|
|
119
|
+
* Get default model name for this provider
|
|
120
|
+
*/
|
|
121
|
+
getDefaultModel() {
|
|
122
|
+
return getDefaultMistralModel();
|
|
114
123
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
(options.maxTokens < 1 || options.maxTokens > 32768)) {
|
|
121
|
-
throw new Error("maxTokens must be between 1 and 32768 for Mistral AI");
|
|
122
|
-
}
|
|
123
|
-
if (options.temperature &&
|
|
124
|
-
(options.temperature < 0 || options.temperature > 1)) {
|
|
125
|
-
throw new Error("temperature must be between 0 and 1");
|
|
126
|
-
}
|
|
124
|
+
/**
|
|
125
|
+
* Get provider name
|
|
126
|
+
*/
|
|
127
|
+
getProviderName() {
|
|
128
|
+
return this.providerName;
|
|
127
129
|
}
|
|
128
130
|
/**
|
|
129
|
-
*
|
|
130
|
-
* @returns Array of available model names
|
|
131
|
+
* Get AI SDK model instance
|
|
131
132
|
*/
|
|
132
|
-
|
|
133
|
-
return
|
|
134
|
-
"mistral-small",
|
|
135
|
-
"mistral-medium",
|
|
136
|
-
"mistral-large",
|
|
137
|
-
"mistral-7b-instruct",
|
|
138
|
-
"mistral-8x7b-instruct",
|
|
139
|
-
"mistral-8x22b-instruct",
|
|
140
|
-
];
|
|
133
|
+
getAISDKModel() {
|
|
134
|
+
return this.model;
|
|
141
135
|
}
|
|
142
136
|
/**
|
|
143
|
-
*
|
|
144
|
-
* @param useCase - The intended use case
|
|
145
|
-
* @returns Recommended model name
|
|
137
|
+
* Handle provider-specific errors
|
|
146
138
|
*/
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
return "mistral-small";
|
|
151
|
-
case "balanced":
|
|
152
|
-
return "mistral-medium";
|
|
153
|
-
case "quality":
|
|
154
|
-
return "mistral-large";
|
|
155
|
-
default:
|
|
156
|
-
return "mistral-small";
|
|
139
|
+
handleProviderError(error) {
|
|
140
|
+
if (error instanceof Error) {
|
|
141
|
+
return error;
|
|
157
142
|
}
|
|
143
|
+
return new Error(`Mistral provider error: ${String(error)}`);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Validate provider configuration
|
|
147
|
+
*/
|
|
148
|
+
async validateConfiguration() {
|
|
149
|
+
try {
|
|
150
|
+
getMistralApiKey();
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Get provider-specific configuration
|
|
159
|
+
*/
|
|
160
|
+
getConfiguration() {
|
|
161
|
+
return {
|
|
162
|
+
provider: this.providerName,
|
|
163
|
+
model: this.modelName,
|
|
164
|
+
defaultModel: getDefaultMistralModel(),
|
|
165
|
+
};
|
|
158
166
|
}
|
|
159
167
|
}
|
|
160
168
|
export default MistralProvider;
|
|
@@ -24,6 +24,7 @@ export declare class OllamaProvider extends BaseProvider {
|
|
|
24
24
|
protected getDefaultModel(): string;
|
|
25
25
|
/**
|
|
26
26
|
* Returns the Vercel AI SDK model instance for Ollama
|
|
27
|
+
* The OllamaLanguageModel implements LanguageModelV1 interface properly
|
|
27
28
|
*/
|
|
28
29
|
protected getAISDKModel(): LanguageModelV1;
|
|
29
30
|
/**
|
|
@@ -52,7 +53,7 @@ export declare class OllamaProvider extends BaseProvider {
|
|
|
52
53
|
supportsTools(): boolean;
|
|
53
54
|
protected executeStream(options: StreamOptions, analysisSchema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>): Promise<StreamResult>;
|
|
54
55
|
private createOllamaStream;
|
|
55
|
-
protected handleProviderError(error:
|
|
56
|
+
protected handleProviderError(error: unknown): Error;
|
|
56
57
|
private validateStreamOptions;
|
|
57
58
|
/**
|
|
58
59
|
* Check if Ollama service is healthy and accessible
|
package/dist/providers/ollama.js
CHANGED
|
@@ -55,7 +55,8 @@ class OllamaLanguageModel {
|
|
|
55
55
|
.join("\n");
|
|
56
56
|
}
|
|
57
57
|
async doGenerate(options) {
|
|
58
|
-
const messages = options
|
|
58
|
+
const messages = options
|
|
59
|
+
.messages || [];
|
|
59
60
|
const prompt = this.convertMessagesToPrompt(messages);
|
|
60
61
|
const response = await fetch(`${this.baseUrl}/api/generate`, {
|
|
61
62
|
method: "POST",
|
|
@@ -81,11 +82,25 @@ class OllamaLanguageModel {
|
|
|
81
82
|
usage: {
|
|
82
83
|
promptTokens: this.estimateTokens(prompt),
|
|
83
84
|
completionTokens: this.estimateTokens(data.response),
|
|
85
|
+
totalTokens: this.estimateTokens(prompt) + this.estimateTokens(data.response),
|
|
86
|
+
},
|
|
87
|
+
finishReason: "stop",
|
|
88
|
+
rawCall: {
|
|
89
|
+
rawPrompt: prompt,
|
|
90
|
+
rawSettings: {
|
|
91
|
+
model: this.modelId,
|
|
92
|
+
temperature: options.temperature,
|
|
93
|
+
num_predict: options.maxTokens,
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
rawResponse: {
|
|
97
|
+
headers: {},
|
|
84
98
|
},
|
|
85
99
|
};
|
|
86
100
|
}
|
|
87
101
|
async doStream(options) {
|
|
88
|
-
const messages = options
|
|
102
|
+
const messages = options
|
|
103
|
+
.messages || [];
|
|
89
104
|
const prompt = this.convertMessagesToPrompt(messages);
|
|
90
105
|
const response = await fetch(`${this.baseUrl}/api/generate`, {
|
|
91
106
|
method: "POST",
|
|
@@ -105,8 +120,32 @@ class OllamaLanguageModel {
|
|
|
105
120
|
if (!response.ok) {
|
|
106
121
|
throw new Error(`Ollama API error: ${response.status} ${response.statusText}`);
|
|
107
122
|
}
|
|
123
|
+
const self = this;
|
|
108
124
|
return {
|
|
109
|
-
stream:
|
|
125
|
+
stream: new ReadableStream({
|
|
126
|
+
async start(controller) {
|
|
127
|
+
try {
|
|
128
|
+
for await (const chunk of self.parseStreamResponse(response)) {
|
|
129
|
+
controller.enqueue(chunk);
|
|
130
|
+
}
|
|
131
|
+
controller.close();
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
controller.error(error);
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
}),
|
|
138
|
+
rawCall: {
|
|
139
|
+
rawPrompt: prompt,
|
|
140
|
+
rawSettings: {
|
|
141
|
+
model: this.modelId,
|
|
142
|
+
temperature: options.temperature,
|
|
143
|
+
num_predict: options.maxTokens,
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
rawResponse: {
|
|
147
|
+
headers: {},
|
|
148
|
+
},
|
|
110
149
|
};
|
|
111
150
|
}
|
|
112
151
|
async *parseStreamResponse(response) {
|
|
@@ -195,6 +234,7 @@ export class OllamaProvider extends BaseProvider {
|
|
|
195
234
|
}
|
|
196
235
|
/**
|
|
197
236
|
* Returns the Vercel AI SDK model instance for Ollama
|
|
237
|
+
* The OllamaLanguageModel implements LanguageModelV1 interface properly
|
|
198
238
|
*/
|
|
199
239
|
getAISDKModel() {
|
|
200
240
|
return this.ollamaModel;
|
|
@@ -16,7 +16,7 @@ export declare class OpenAIProvider extends BaseProvider {
|
|
|
16
16
|
* Returns the Vercel AI SDK model instance for OpenAI
|
|
17
17
|
*/
|
|
18
18
|
protected getAISDKModel(): LanguageModelV1;
|
|
19
|
-
protected handleProviderError(error:
|
|
19
|
+
protected handleProviderError(error: unknown): Error;
|
|
20
20
|
/**
|
|
21
21
|
* executeGenerate method removed - generation is now handled by BaseProvider.
|
|
22
22
|
* For details on the changes and migration steps, refer to the BaseProvider documentation
|
package/dist/providers/openAI.js
CHANGED
|
@@ -52,14 +52,18 @@ export class OpenAIProvider extends BaseProvider {
|
|
|
52
52
|
if (error instanceof TimeoutError) {
|
|
53
53
|
return new Error(`OpenAI request timed out: ${error.message}`);
|
|
54
54
|
}
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
const errorObj = error;
|
|
56
|
+
const message = errorObj?.message && typeof errorObj.message === "string"
|
|
57
|
+
? errorObj.message
|
|
58
|
+
: "Unknown error";
|
|
59
|
+
if (message.includes("API_KEY_INVALID") ||
|
|
60
|
+
message.includes("Invalid API key")) {
|
|
57
61
|
return new Error("Invalid OpenAI API key. Please check your OPENAI_API_KEY environment variable.");
|
|
58
62
|
}
|
|
59
|
-
if (
|
|
63
|
+
if (message.includes("rate limit")) {
|
|
60
64
|
return new Error("OpenAI rate limit exceeded. Please try again later.");
|
|
61
65
|
}
|
|
62
|
-
return new Error(`OpenAI error: ${
|
|
66
|
+
return new Error(`OpenAI error: ${message}`);
|
|
63
67
|
}
|
|
64
68
|
/**
|
|
65
69
|
* executeGenerate method removed - generation is now handled by BaseProvider.
|
|
@@ -40,11 +40,12 @@ export function createProxyFetch() {
|
|
|
40
40
|
dispatcher: dispatcher,
|
|
41
41
|
});
|
|
42
42
|
logger.debug(`[Proxy Fetch] ✅ Request proxied successfully to ${url.hostname}`);
|
|
43
|
-
return response; //
|
|
43
|
+
return response; // undici.fetch returns compatible Response type
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
catch (error) {
|
|
47
|
-
|
|
47
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
48
|
+
logger.warn(`[Proxy Fetch] Proxy failed (${errorMessage}), falling back to direct connection`);
|
|
48
49
|
}
|
|
49
50
|
// Fallback to standard fetch
|
|
50
51
|
return fetch(input, init);
|
|
@@ -16,11 +16,11 @@ export interface CustomTool {
|
|
|
16
16
|
/**
|
|
17
17
|
* Parameters schema using Zod or JSON Schema
|
|
18
18
|
*/
|
|
19
|
-
parameters?: z.ZodSchema | Record<string,
|
|
19
|
+
parameters?: z.ZodSchema | Record<string, unknown>;
|
|
20
20
|
/**
|
|
21
21
|
* Tool execution function
|
|
22
22
|
*/
|
|
23
|
-
execute: (args:
|
|
23
|
+
execute: (args: unknown, context?: ToolContext) => Promise<unknown> | unknown;
|
|
24
24
|
/**
|
|
25
25
|
* Optional metadata
|
|
26
26
|
*/
|
|
@@ -46,7 +46,7 @@ export interface ToolContext {
|
|
|
46
46
|
/**
|
|
47
47
|
* Call another tool
|
|
48
48
|
*/
|
|
49
|
-
callTool: (name: string, args:
|
|
49
|
+
callTool: (name: string, args: unknown) => Promise<unknown>;
|
|
50
50
|
/**
|
|
51
51
|
* Current session information
|
|
52
52
|
*/
|
|
@@ -64,7 +64,7 @@ export interface ToolContext {
|
|
|
64
64
|
/**
|
|
65
65
|
* Tool middleware function
|
|
66
66
|
*/
|
|
67
|
-
export type ToolMiddleware = (toolName: string, args:
|
|
67
|
+
export type ToolMiddleware = (toolName: string, args: unknown, next: () => Promise<unknown>, context: ToolContext) => Promise<unknown>;
|
|
68
68
|
/**
|
|
69
69
|
* Tool permission configuration
|
|
70
70
|
*/
|
|
@@ -72,7 +72,7 @@ export interface ToolPermissions {
|
|
|
72
72
|
allowlist?: string[];
|
|
73
73
|
denylist?: string[];
|
|
74
74
|
requireApproval?: string[];
|
|
75
|
-
customValidator?: (toolName: string, args:
|
|
75
|
+
customValidator?: (toolName: string, args: unknown) => boolean | Promise<boolean>;
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
78
|
* Converts a custom tool to Vercel AI SDK format
|
|
@@ -129,7 +129,7 @@ export declare class ToolRegistry {
|
|
|
129
129
|
/**
|
|
130
130
|
* Execute a tool with middleware
|
|
131
131
|
*/
|
|
132
|
-
execute(name: string, args:
|
|
132
|
+
execute(name: string, args: unknown, context: ToolContext): Promise<unknown>;
|
|
133
133
|
}
|
|
134
134
|
/**
|
|
135
135
|
* Create a simple tool helper
|
|
@@ -139,7 +139,7 @@ export declare function createTool(config: CustomTool): CustomTool;
|
|
|
139
139
|
* Create an async tool helper
|
|
140
140
|
*/
|
|
141
141
|
export declare function createAsyncTool(config: Omit<CustomTool, "execute"> & {
|
|
142
|
-
execute: (args:
|
|
142
|
+
execute: (args: unknown, context?: ToolContext) => Promise<unknown>;
|
|
143
143
|
}): CustomTool;
|
|
144
144
|
/**
|
|
145
145
|
* Create a batch tool that processes multiple items
|
|
@@ -163,16 +163,16 @@ export declare const TestUtils: {
|
|
|
163
163
|
* Test a tool with mock data
|
|
164
164
|
*/
|
|
165
165
|
testTool(tool: CustomTool, testCases: Array<{
|
|
166
|
-
input:
|
|
167
|
-
expected?:
|
|
166
|
+
input: unknown;
|
|
167
|
+
expected?: unknown;
|
|
168
168
|
}>): Promise<({
|
|
169
|
-
input:
|
|
170
|
-
output:
|
|
169
|
+
input: unknown;
|
|
170
|
+
output: unknown;
|
|
171
171
|
success: boolean;
|
|
172
172
|
matches: boolean | undefined;
|
|
173
173
|
error?: undefined;
|
|
174
174
|
} | {
|
|
175
|
-
input:
|
|
175
|
+
input: unknown;
|
|
176
176
|
error: string;
|
|
177
177
|
success: boolean;
|
|
178
178
|
output?: undefined;
|
|
@@ -217,7 +217,8 @@ export function createAsyncTool(config) {
|
|
|
217
217
|
export function createBatchTool(config) {
|
|
218
218
|
return {
|
|
219
219
|
...config,
|
|
220
|
-
execute: async (
|
|
220
|
+
execute: async (args, context) => {
|
|
221
|
+
const { items } = args;
|
|
221
222
|
const batchSize = config.batchSize || 10;
|
|
222
223
|
const results = [];
|
|
223
224
|
for (let i = 0; i < items.length; i += batchSize) {
|
|
@@ -6,18 +6,17 @@ import { z } from "zod";
|
|
|
6
6
|
import type { Tool } from "ai";
|
|
7
7
|
import { logger } from "../utils/logger.js";
|
|
8
8
|
import type { InMemoryMCPServerConfig, InMemoryToolInfo } from "../types/mcp-types.js";
|
|
9
|
+
import type { ToolArgs, ToolContext as CoreToolContext, ToolResult, SimpleTool as CoreSimpleTool } from "../types/tools.js";
|
|
10
|
+
import type { JsonValue } from "../types/common.js";
|
|
9
11
|
/**
|
|
10
12
|
* Context provided to tools during execution
|
|
13
|
+
* Extends the core ToolContext with SDK-specific features
|
|
11
14
|
*/
|
|
12
|
-
export interface ToolContext {
|
|
15
|
+
export interface ToolContext extends CoreToolContext {
|
|
13
16
|
/**
|
|
14
17
|
* Current session ID
|
|
15
18
|
*/
|
|
16
19
|
sessionId: string;
|
|
17
|
-
/**
|
|
18
|
-
* User ID if available
|
|
19
|
-
*/
|
|
20
|
-
userId?: string;
|
|
21
20
|
/**
|
|
22
21
|
* AI provider being used
|
|
23
22
|
*/
|
|
@@ -29,7 +28,7 @@ export interface ToolContext {
|
|
|
29
28
|
/**
|
|
30
29
|
* Call another tool
|
|
31
30
|
*/
|
|
32
|
-
callTool?: (name: string, args:
|
|
31
|
+
callTool?: (name: string, args: ToolArgs) => Promise<ToolResult>;
|
|
33
32
|
/**
|
|
34
33
|
* Logger instance
|
|
35
34
|
*/
|
|
@@ -37,8 +36,9 @@ export interface ToolContext {
|
|
|
37
36
|
}
|
|
38
37
|
/**
|
|
39
38
|
* Simple tool interface for SDK users
|
|
39
|
+
* Extends the core SimpleTool with specific types
|
|
40
40
|
*/
|
|
41
|
-
export interface SimpleTool {
|
|
41
|
+
export interface SimpleTool<TArgs = ToolArgs, TResult = JsonValue> extends Omit<CoreSimpleTool<TArgs, TResult>, "execute"> {
|
|
42
42
|
/**
|
|
43
43
|
* Tool description that helps AI understand when to use it
|
|
44
44
|
*/
|
|
@@ -50,7 +50,7 @@ export interface SimpleTool {
|
|
|
50
50
|
/**
|
|
51
51
|
* Tool execution function
|
|
52
52
|
*/
|
|
53
|
-
execute: (args:
|
|
53
|
+
execute: (args: TArgs, context?: ToolContext) => Promise<TResult> | TResult;
|
|
54
54
|
/**
|
|
55
55
|
* Optional metadata
|
|
56
56
|
*/
|
|
@@ -58,7 +58,9 @@ export interface SimpleTool {
|
|
|
58
58
|
category?: string;
|
|
59
59
|
version?: string;
|
|
60
60
|
author?: string;
|
|
61
|
-
|
|
61
|
+
tags?: string[];
|
|
62
|
+
documentation?: string;
|
|
63
|
+
[key: string]: JsonValue | undefined;
|
|
62
64
|
};
|
|
63
65
|
}
|
|
64
66
|
/**
|
|
@@ -76,18 +78,20 @@ export declare function createMCPServerFromTools(serverId: string, tools: Record
|
|
|
76
78
|
title?: string;
|
|
77
79
|
description?: string;
|
|
78
80
|
category?: string;
|
|
79
|
-
|
|
81
|
+
version?: string;
|
|
82
|
+
author?: string;
|
|
83
|
+
[key: string]: JsonValue | undefined;
|
|
80
84
|
}): InMemoryMCPServerConfig;
|
|
81
85
|
/**
|
|
82
86
|
* Helper to create a tool with type safety
|
|
83
87
|
*/
|
|
84
|
-
export declare function createTool<TParams =
|
|
88
|
+
export declare function createTool<TParams = ToolArgs>(config: SimpleTool): SimpleTool;
|
|
85
89
|
/**
|
|
86
90
|
* Helper to create a tool with typed parameters
|
|
87
91
|
*/
|
|
88
92
|
export declare function createTypedTool<TParams extends z.ZodSchema>(config: Omit<SimpleTool, "execute"> & {
|
|
89
93
|
parameters: TParams;
|
|
90
|
-
execute: (args: z.infer<TParams>, context?: ToolContext) => Promise<
|
|
94
|
+
execute: (args: z.infer<TParams>, context?: ToolContext) => Promise<JsonValue> | JsonValue;
|
|
91
95
|
}): SimpleTool;
|
|
92
96
|
/**
|
|
93
97
|
* Validate tool configuration with detailed error messages
|
|
@@ -42,8 +42,9 @@ export function convertToMCPTool(simpleTool) {
|
|
|
42
42
|
return {
|
|
43
43
|
description: simpleTool.description,
|
|
44
44
|
execute: async (params) => {
|
|
45
|
+
const typedParams = params;
|
|
45
46
|
try {
|
|
46
|
-
const result = await simpleTool.execute(
|
|
47
|
+
const result = await simpleTool.execute(typedParams);
|
|
47
48
|
return {
|
|
48
49
|
success: true,
|
|
49
50
|
data: result,
|
|
@@ -135,7 +136,7 @@ export function validateTool(name, tool) {
|
|
|
135
136
|
// Validate execute function with signature guidance
|
|
136
137
|
if (typeof tool.execute !== "function") {
|
|
137
138
|
throw new Error(`Tool '${name}' must have an execute function. ` +
|
|
138
|
-
`Expected signature: async (params?:
|
|
139
|
+
`Expected signature: async (params?: ToolArgs) => Promise<unknown>. ` +
|
|
139
140
|
`Received: ${typeof tool.execute}. ` +
|
|
140
141
|
`Example: { execute: async (params) => { return { success: true, data: result }; } }`);
|
|
141
142
|
}
|