@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
|
@@ -7,7 +7,7 @@ import { streamText as aiStreamText, generateText as aiGenerate, Output, } from
|
|
|
7
7
|
import { getAvailableFunctionTools, executeFunctionCall, isFunctionCallingAvailable, } from "../mcp/function-calling.js";
|
|
8
8
|
import { createExecutionContext } from "../mcp/context-manager.js";
|
|
9
9
|
import { mcpLogger } from "../mcp/logging.js";
|
|
10
|
-
import { DEFAULT_MAX_TOKENS } from "../core/constants.js";
|
|
10
|
+
import { DEFAULT_MAX_TOKENS, DEFAULT_MAX_STEPS } from "../core/constants.js";
|
|
11
11
|
/**
|
|
12
12
|
* Enhanced provider that enables real function calling with MCP tools
|
|
13
13
|
*/
|
|
@@ -16,11 +16,22 @@ export class FunctionCallingProvider {
|
|
|
16
16
|
enableFunctionCalling;
|
|
17
17
|
sessionId;
|
|
18
18
|
userId;
|
|
19
|
+
cachedToolsObject = null;
|
|
20
|
+
cachedToolMap = null;
|
|
21
|
+
cacheTimestamp = null;
|
|
22
|
+
cacheExpiryMs;
|
|
19
23
|
constructor(baseProvider, options = {}) {
|
|
20
24
|
this.baseProvider = baseProvider;
|
|
21
25
|
this.enableFunctionCalling = options.enableFunctionCalling ?? true;
|
|
22
26
|
this.sessionId = options.sessionId || `function-calling-${Date.now()}`;
|
|
23
27
|
this.userId = options.userId || "function-calling-user";
|
|
28
|
+
// Configurable cache expiry: default 5 minutes, with environment override, then constructor option
|
|
29
|
+
const defaultExpiryMs = 5 * 60 * 1000; // 5 minutes
|
|
30
|
+
const envExpiryMs = process.env.NEUROLINK_CACHE_EXPIRY_MS
|
|
31
|
+
? parseInt(process.env.NEUROLINK_CACHE_EXPIRY_MS, 10)
|
|
32
|
+
: undefined;
|
|
33
|
+
this.cacheExpiryMs =
|
|
34
|
+
options.cacheExpiryMs ?? envExpiryMs ?? defaultExpiryMs;
|
|
24
35
|
}
|
|
25
36
|
/**
|
|
26
37
|
* PRIMARY METHOD: Stream content using AI (recommended for new code)
|
|
@@ -91,8 +102,30 @@ export class FunctionCallingProvider {
|
|
|
91
102
|
}
|
|
92
103
|
return result;
|
|
93
104
|
}
|
|
94
|
-
// Get available function tools
|
|
95
|
-
|
|
105
|
+
// Get available function tools (with automatic cache invalidation)
|
|
106
|
+
let toolsObject, toolMap;
|
|
107
|
+
const now = Date.now();
|
|
108
|
+
const isCacheExpired = this.cacheTimestamp === null ||
|
|
109
|
+
now - this.cacheTimestamp > this.cacheExpiryMs;
|
|
110
|
+
if (this.cachedToolsObject && this.cachedToolMap && !isCacheExpired) {
|
|
111
|
+
toolsObject = this.cachedToolsObject;
|
|
112
|
+
toolMap = this.cachedToolMap;
|
|
113
|
+
mcpLogger.debug(`[${functionTag}] Using cached tools (${Math.round((now - this.cacheTimestamp) / 1000)}s old)`);
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
if (isCacheExpired && this.cachedToolsObject) {
|
|
117
|
+
mcpLogger.debug(`[${functionTag}] Cache expired, refreshing tools`);
|
|
118
|
+
}
|
|
119
|
+
const result = await getAvailableFunctionTools();
|
|
120
|
+
toolsObject = result.toolsObject;
|
|
121
|
+
toolMap = result.toolMap;
|
|
122
|
+
// Cache the results for future use with timestamp
|
|
123
|
+
this.cachedToolsObject = toolsObject;
|
|
124
|
+
this.cachedToolMap = toolMap;
|
|
125
|
+
this.cacheTimestamp = now;
|
|
126
|
+
mcpLogger.debug(`[${functionTag}] Cached ${Object.keys(toolsObject).length} tools with expiry in ${this.cacheExpiryMs / 1000}s`);
|
|
127
|
+
}
|
|
128
|
+
const tools = Object.values(toolsObject);
|
|
96
129
|
if (tools.length === 0) {
|
|
97
130
|
mcpLogger.debug(`[${functionTag}] No tools available, using base provider`);
|
|
98
131
|
const result = await this.baseProvider.generate(options, analysisSchema);
|
|
@@ -113,8 +146,8 @@ export class FunctionCallingProvider {
|
|
|
113
146
|
aiProvider: this.baseProvider.constructor.name,
|
|
114
147
|
});
|
|
115
148
|
// Use the AI SDK's native function calling by calling generate directly
|
|
116
|
-
// We
|
|
117
|
-
const result = await this.
|
|
149
|
+
// We can now use the toolsObject directly instead of converting from array
|
|
150
|
+
const result = await this.generateWithToolsObject(options, toolsObject, toolMap, context, analysisSchema);
|
|
118
151
|
if (!result) {
|
|
119
152
|
return {
|
|
120
153
|
content: "No response generated",
|
|
@@ -150,14 +183,83 @@ export class FunctionCallingProvider {
|
|
|
150
183
|
}
|
|
151
184
|
}
|
|
152
185
|
/**
|
|
153
|
-
* Generate text using AI SDK's
|
|
186
|
+
* Generate text with tools using the AI SDK's generate function (with tools object)
|
|
187
|
+
*/
|
|
188
|
+
async generateWithToolsObject(options, toolsObject, toolMap, context, analysisSchema) {
|
|
189
|
+
const functionTag = "FunctionCallingProvider.generateWithToolsObject";
|
|
190
|
+
try {
|
|
191
|
+
// Use the toolsObject directly with proper execution wrapped
|
|
192
|
+
const toolsWithExecution = this.wrapToolsWithExecution(toolsObject, toolMap, context);
|
|
193
|
+
mcpLogger.debug(`[${functionTag}] Using tools object with ${Object.keys(toolsWithExecution).length} tools`);
|
|
194
|
+
// Get the model from base provider
|
|
195
|
+
const modelInfo = await this.getModelFromProvider();
|
|
196
|
+
if (!modelInfo) {
|
|
197
|
+
mcpLogger.warn(`[${functionTag}] Could not get model from provider, falling back to base provider`);
|
|
198
|
+
const result = await this.baseProvider.generate(options, analysisSchema);
|
|
199
|
+
if (!result) {
|
|
200
|
+
return {
|
|
201
|
+
content: "No response generated",
|
|
202
|
+
provider: "function-calling",
|
|
203
|
+
model: "unknown",
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
return result;
|
|
207
|
+
}
|
|
208
|
+
// Use AI SDK's generate directly with tools
|
|
209
|
+
const generateOptions = {
|
|
210
|
+
model: modelInfo.model,
|
|
211
|
+
prompt: options.prompt,
|
|
212
|
+
system: options.systemPrompt || "You are a helpful AI assistant.",
|
|
213
|
+
temperature: options.temperature || 0.7,
|
|
214
|
+
maxTokens: options.maxTokens ?? DEFAULT_MAX_TOKENS,
|
|
215
|
+
tools: toolsWithExecution,
|
|
216
|
+
toolChoice: "auto", // Let the AI decide when to use tools
|
|
217
|
+
maxSteps: options.maxSteps ?? DEFAULT_MAX_STEPS, // Enable multi-turn tool execution
|
|
218
|
+
};
|
|
219
|
+
// Add experimental_output if schema is provided
|
|
220
|
+
if (analysisSchema) {
|
|
221
|
+
generateOptions.experimental_output = Output.object({
|
|
222
|
+
schema: analysisSchema,
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
const result = await aiGenerate(generateOptions);
|
|
226
|
+
mcpLogger.debug(`[${functionTag}] AI SDK generate completed`, {
|
|
227
|
+
toolCalls: result.toolCalls?.length || 0,
|
|
228
|
+
finishReason: result.finishReason,
|
|
229
|
+
usage: result.usage,
|
|
230
|
+
});
|
|
231
|
+
return {
|
|
232
|
+
content: result.text,
|
|
233
|
+
provider: "function-calling",
|
|
234
|
+
model: "unknown",
|
|
235
|
+
usage: result.usage
|
|
236
|
+
? {
|
|
237
|
+
inputTokens: result.usage.promptTokens,
|
|
238
|
+
outputTokens: result.usage.completionTokens,
|
|
239
|
+
totalTokens: result.usage.totalTokens,
|
|
240
|
+
}
|
|
241
|
+
: undefined,
|
|
242
|
+
responseTime: 0,
|
|
243
|
+
toolsUsed: result.toolCalls?.map((tc) => tc.toolName) || [],
|
|
244
|
+
toolExecutions: [],
|
|
245
|
+
enhancedWithTools: (result.toolCalls?.length || 0) > 0,
|
|
246
|
+
availableTools: [],
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
catch (error) {
|
|
250
|
+
mcpLogger.error(`[${functionTag}] Failed to generate text with tools:`, error);
|
|
251
|
+
throw error;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Generate text using AI SDK's native function calling (legacy array-based)
|
|
154
256
|
*/
|
|
155
257
|
async generateWithTools(options, tools, toolMap, context, analysisSchema) {
|
|
156
258
|
const functionTag = "FunctionCallingProvider.generateWithTools";
|
|
157
259
|
try {
|
|
158
260
|
// Convert our tools to AI SDK format with proper execution
|
|
159
261
|
const toolsWithExecution = this.convertToAISDKTools(tools, toolMap, context);
|
|
160
|
-
mcpLogger.debug(`[${functionTag}] Calling AI SDK generate with ${Object.keys(toolsWithExecution).length} tools and maxSteps:
|
|
262
|
+
mcpLogger.debug(`[${functionTag}] Calling AI SDK generate with ${Object.keys(toolsWithExecution).length} tools and maxSteps: ${options.maxSteps ?? DEFAULT_MAX_STEPS}`);
|
|
161
263
|
mcpLogger.debug(`[${functionTag}] Sanitized tool names:`, Object.keys(toolsWithExecution));
|
|
162
264
|
// Log the first few tools to debug the issue
|
|
163
265
|
const toolNames = Object.keys(toolsWithExecution);
|
|
@@ -187,7 +289,7 @@ export class FunctionCallingProvider {
|
|
|
187
289
|
maxTokens: options.maxTokens ?? DEFAULT_MAX_TOKENS,
|
|
188
290
|
tools: toolsWithExecution,
|
|
189
291
|
toolChoice: "auto", // Let the AI decide when to use tools
|
|
190
|
-
maxSteps:
|
|
292
|
+
maxSteps: options.maxSteps ?? DEFAULT_MAX_STEPS, // Enable multi-turn tool execution
|
|
191
293
|
};
|
|
192
294
|
// Add experimental_output if schema is provided
|
|
193
295
|
if (analysisSchema) {
|
|
@@ -242,7 +344,7 @@ export class FunctionCallingProvider {
|
|
|
242
344
|
if (typeof provider.getModel === "function") {
|
|
243
345
|
mcpLogger.debug(`[${functionTag}] Found getModel method on provider`);
|
|
244
346
|
const model = await provider.getModel();
|
|
245
|
-
return { model };
|
|
347
|
+
return { model: model };
|
|
246
348
|
}
|
|
247
349
|
mcpLogger.warn(`[${functionTag}] Could not find model on provider`);
|
|
248
350
|
return null;
|
|
@@ -270,7 +372,52 @@ export class FunctionCallingProvider {
|
|
|
270
372
|
return sanitized;
|
|
271
373
|
}
|
|
272
374
|
/**
|
|
273
|
-
*
|
|
375
|
+
* Wrap tools with proper execution context (for object-based tools)
|
|
376
|
+
*/
|
|
377
|
+
wrapToolsWithExecution(toolsObject, toolMap, context) {
|
|
378
|
+
const functionTag = "FunctionCallingProvider.wrapToolsWithExecution";
|
|
379
|
+
const wrappedTools = {};
|
|
380
|
+
for (const [toolName, tool] of Object.entries(toolsObject)) {
|
|
381
|
+
const toolInfo = toolMap.get(toolName);
|
|
382
|
+
const originalToolName = toolInfo ? toolInfo.toolName : toolName;
|
|
383
|
+
// Create a version with actual MCP execution
|
|
384
|
+
wrappedTools[toolName] = {
|
|
385
|
+
description: tool.description,
|
|
386
|
+
parameters: tool.parameters,
|
|
387
|
+
execute: async (args) => {
|
|
388
|
+
// Debug logging only in debug mode
|
|
389
|
+
if (process.env.NEUROLINK_DEBUG === "true") {
|
|
390
|
+
const providerName = this.baseProvider.constructor.name;
|
|
391
|
+
mcpLogger.debug(`Tool execution - Provider: ${providerName}`);
|
|
392
|
+
mcpLogger.debug(`Tool: ${toolName} (original: ${originalToolName})`);
|
|
393
|
+
mcpLogger.debug(`Args:`, args);
|
|
394
|
+
}
|
|
395
|
+
try {
|
|
396
|
+
// Execute the actual MCP tool
|
|
397
|
+
const result = await executeFunctionCall(toolName, args);
|
|
398
|
+
if (process.env.NEUROLINK_DEBUG === "true") {
|
|
399
|
+
mcpLogger.debug(`Tool result:`, result);
|
|
400
|
+
}
|
|
401
|
+
if (result.success) {
|
|
402
|
+
return result.data || { success: true };
|
|
403
|
+
}
|
|
404
|
+
else {
|
|
405
|
+
return { error: result.error || "Tool execution failed" };
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
catch (error) {
|
|
409
|
+
mcpLogger.error(`[${functionTag}] Tool execution error: ${toolName}`, error);
|
|
410
|
+
return {
|
|
411
|
+
error: error instanceof Error ? error.message : String(error),
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
},
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
return wrappedTools;
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Convert our tools to AI SDK format with proper execution (legacy array-based)
|
|
274
421
|
*/
|
|
275
422
|
convertToAISDKTools(tools, toolMap, context) {
|
|
276
423
|
const functionTag = "FunctionCallingProvider.convertToAISDKTools";
|
|
@@ -394,6 +541,57 @@ These functions provide accurate, real-time data. Use them actively to enhance y
|
|
|
394
541
|
/**
|
|
395
542
|
* Alias for generate() - CLI-SDK consistency
|
|
396
543
|
*/
|
|
544
|
+
/**
|
|
545
|
+
* Clear cached tools - Cache Invalidation Strategy
|
|
546
|
+
*
|
|
547
|
+
* WHEN TO CALL clearToolsCache():
|
|
548
|
+
*
|
|
549
|
+
* 1. **MCP Server Changes**: When MCP servers are added, removed, or restarted
|
|
550
|
+
* - After calling unifiedRegistry.addServer() or removeServer()
|
|
551
|
+
* - When MCP server configurations change
|
|
552
|
+
* - After MCP server restart or reconnection
|
|
553
|
+
*
|
|
554
|
+
* 2. **Tool Registration Changes**: When custom tools are modified
|
|
555
|
+
* - After registering new SDK tools via registerTool()
|
|
556
|
+
* - When tool implementations change
|
|
557
|
+
* - After unregistering tools
|
|
558
|
+
*
|
|
559
|
+
* 3. **Provider Reinitialization**: When the provider context changes
|
|
560
|
+
* - Before switching between different AI providers
|
|
561
|
+
* - When session context changes significantly
|
|
562
|
+
* - After provider authentication refresh
|
|
563
|
+
*
|
|
564
|
+
* 4. **Error Recovery**: When tool execution encounters systematic failures
|
|
565
|
+
* - After MCP connection errors are resolved
|
|
566
|
+
* - When tool discovery needs to be re-run
|
|
567
|
+
* - During error recovery workflows
|
|
568
|
+
*
|
|
569
|
+
* 5. **Development/Testing**: During development and testing cycles
|
|
570
|
+
* - Between test cases that modify tool availability
|
|
571
|
+
* - When testing different tool configurations
|
|
572
|
+
* - During hot reloading scenarios
|
|
573
|
+
*
|
|
574
|
+
* CACHE LIFECYCLE:
|
|
575
|
+
* - Cache is populated on first generate() call via getAvailableFunctionTools()
|
|
576
|
+
* - Cache persists across multiple generate() calls for performance
|
|
577
|
+
* - Cache is invalidated by calling this method
|
|
578
|
+
* - Next generate() call will rebuild cache from current tool state
|
|
579
|
+
*
|
|
580
|
+
* PERFORMANCE IMPACT:
|
|
581
|
+
* - Clearing cache forces tool discovery on next usage (~100-500ms overhead)
|
|
582
|
+
* - Recommended to clear cache proactively rather than reactively
|
|
583
|
+
* - Consider batching tool changes before clearing cache
|
|
584
|
+
*
|
|
585
|
+
* THREAD SAFETY:
|
|
586
|
+
* - This method is not thread-safe
|
|
587
|
+
* - Avoid calling during active generate() operations
|
|
588
|
+
* - Safe to call between separate AI generation requests
|
|
589
|
+
*/
|
|
590
|
+
clearToolsCache() {
|
|
591
|
+
this.cachedToolsObject = null;
|
|
592
|
+
this.cachedToolMap = null;
|
|
593
|
+
this.cacheTimestamp = null;
|
|
594
|
+
}
|
|
397
595
|
/**
|
|
398
596
|
* Short alias for generate() - CLI-SDK consistency
|
|
399
597
|
*/
|
|
@@ -422,6 +620,7 @@ export function createMCPAwareProviderV3(baseProvider, options = {}) {
|
|
|
422
620
|
enableFunctionCalling: options.enableFunctionCalling,
|
|
423
621
|
sessionId: options.sessionId,
|
|
424
622
|
userId: options.userId,
|
|
623
|
+
cacheExpiryMs: options.cacheExpiryMs,
|
|
425
624
|
});
|
|
426
625
|
mcpLogger.debug(`[${functionTag}] Created MCP-aware provider with function calling`, {
|
|
427
626
|
providerName: options.providerName,
|
|
@@ -8,14 +8,14 @@ import { BaseProvider } from "../core/base-provider.js";
|
|
|
8
8
|
* Migrated from original GoogleAIStudio class to new factory pattern
|
|
9
9
|
*/
|
|
10
10
|
export declare class GoogleAIStudioProvider extends BaseProvider {
|
|
11
|
-
constructor(modelName?: string, sdk?:
|
|
11
|
+
constructor(modelName?: string, sdk?: unknown);
|
|
12
12
|
protected getProviderName(): AIProviderName;
|
|
13
13
|
protected getDefaultModel(): string;
|
|
14
14
|
/**
|
|
15
15
|
* 🔧 PHASE 2: Return AI SDK model instance for tool calling
|
|
16
16
|
*/
|
|
17
17
|
protected getAISDKModel(): LanguageModelV1;
|
|
18
|
-
protected handleProviderError(error:
|
|
18
|
+
protected handleProviderError(error: unknown): Error;
|
|
19
19
|
protected executeStream(options: StreamOptions, analysisSchema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>): Promise<StreamResult>;
|
|
20
20
|
private getApiKey;
|
|
21
21
|
private validateStreamOptions;
|
|
@@ -45,13 +45,19 @@ export class GoogleAIStudioProvider extends BaseProvider {
|
|
|
45
45
|
if (error instanceof TimeoutError) {
|
|
46
46
|
return new Error(`Google AI request timed out: ${error.message}`);
|
|
47
47
|
}
|
|
48
|
-
|
|
48
|
+
const errorRecord = error;
|
|
49
|
+
if (typeof errorRecord?.message === "string" &&
|
|
50
|
+
errorRecord.message.includes("API_KEY_INVALID")) {
|
|
49
51
|
return new Error("Invalid Google AI API key. Please check your GOOGLE_AI_API_KEY environment variable.");
|
|
50
52
|
}
|
|
51
|
-
if (
|
|
53
|
+
if (typeof errorRecord?.message === "string" &&
|
|
54
|
+
errorRecord.message.includes("RATE_LIMIT_EXCEEDED")) {
|
|
52
55
|
return new Error("Google AI rate limit exceeded. Please try again later.");
|
|
53
56
|
}
|
|
54
|
-
|
|
57
|
+
const message = typeof errorRecord?.message === "string"
|
|
58
|
+
? errorRecord.message
|
|
59
|
+
: "Unknown error";
|
|
60
|
+
return new Error(`Google AI error: ${message}`);
|
|
55
61
|
}
|
|
56
62
|
// executeGenerate removed - BaseProvider handles all generation with tools
|
|
57
63
|
async executeStream(options, analysisSchema) {
|
|
@@ -21,7 +21,7 @@ export declare class GoogleVertexProvider extends BaseProvider {
|
|
|
21
21
|
private projectId;
|
|
22
22
|
private location;
|
|
23
23
|
private cachedAnthropicModel;
|
|
24
|
-
constructor(modelName?: string);
|
|
24
|
+
constructor(modelName?: string, sdk?: unknown);
|
|
25
25
|
protected getProviderName(): AIProviderName;
|
|
26
26
|
protected getDefaultModel(): string;
|
|
27
27
|
/**
|
|
@@ -30,7 +30,7 @@ export declare class GoogleVertexProvider extends BaseProvider {
|
|
|
30
30
|
*/
|
|
31
31
|
protected getAISDKModel(): Promise<LanguageModelV1>;
|
|
32
32
|
protected executeStream(options: StreamOptions, analysisSchema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>): Promise<StreamResult>;
|
|
33
|
-
protected handleProviderError(error:
|
|
33
|
+
protected handleProviderError(error: unknown): Error;
|
|
34
34
|
private validateStreamOptions;
|
|
35
35
|
/**
|
|
36
36
|
* Check if Anthropic models are available
|
|
@@ -15,7 +15,8 @@ async function getCreateVertexAnthropic() {
|
|
|
15
15
|
_anthropicImportAttempted = true;
|
|
16
16
|
try {
|
|
17
17
|
// Try to import the anthropic module - available in @ai-sdk/google-vertex ^2.2.0+
|
|
18
|
-
|
|
18
|
+
// Use proper dynamic import without eval() for security
|
|
19
|
+
const anthropicModule = (await import("@ai-sdk/google-vertex/anthropic"));
|
|
19
20
|
_createVertexAnthropic = anthropicModule.createVertexAnthropic;
|
|
20
21
|
logger.debug("[GoogleVertexAI] Anthropic module successfully loaded");
|
|
21
22
|
return _createVertexAnthropic;
|
|
@@ -69,8 +70,8 @@ export class GoogleVertexProvider extends BaseProvider {
|
|
|
69
70
|
projectId;
|
|
70
71
|
location;
|
|
71
72
|
cachedAnthropicModel = null;
|
|
72
|
-
constructor(modelName) {
|
|
73
|
-
super(modelName, "vertex");
|
|
73
|
+
constructor(modelName, sdk) {
|
|
74
|
+
super(modelName, "vertex", sdk);
|
|
74
75
|
// Validate Google Cloud credentials
|
|
75
76
|
if (!hasGoogleCredentials()) {
|
|
76
77
|
throw new Error(`❌ Google Vertex AI Provider Configuration Error\n\nMissing Google Cloud authentication. One of the following is required:\n\n🔧 Option 1: Service Account Key File\nGOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json\n\n🔧 Option 2: Service Account Key (Base64)\nGOOGLE_SERVICE_ACCOUNT_KEY=base64_encoded_key\n\n🔧 Option 3: Individual Credentials\nGOOGLE_AUTH_CLIENT_EMAIL=your-service-account@project.iam.gserviceaccount.com\nGOOGLE_AUTH_PRIVATE_KEY=-----BEGIN PRIVATE KEY-----...\n\n🔧 Step 4: Restart Application\nRestart your application to load the new environment variables.`);
|
|
@@ -147,22 +148,27 @@ export class GoogleVertexProvider extends BaseProvider {
|
|
|
147
148
|
}
|
|
148
149
|
}
|
|
149
150
|
handleProviderError(error) {
|
|
150
|
-
|
|
151
|
+
const errorRecord = error;
|
|
152
|
+
if (typeof errorRecord?.name === "string" &&
|
|
153
|
+
errorRecord.name === "TimeoutError") {
|
|
151
154
|
return new TimeoutError(`Google Vertex AI request timed out. Consider increasing timeout or using a lighter model.`, this.defaultTimeout);
|
|
152
155
|
}
|
|
153
|
-
|
|
156
|
+
const message = typeof errorRecord?.message === "string"
|
|
157
|
+
? errorRecord.message
|
|
158
|
+
: "Unknown error occurred";
|
|
159
|
+
if (message.includes("PERMISSION_DENIED")) {
|
|
154
160
|
return new Error(`❌ Google Vertex AI Permission Denied\n\nYour Google Cloud credentials don't have permission to access Vertex AI.\n\n🔧 Required Steps:\n1. Ensure your service account has Vertex AI User role\n2. Check if Vertex AI API is enabled in your project\n3. Verify your project ID is correct\n4. Confirm your location/region has Vertex AI available`);
|
|
155
161
|
}
|
|
156
|
-
if (
|
|
157
|
-
return new Error(`❌ Google Vertex AI Model Not Found\n\n${
|
|
162
|
+
if (message.includes("NOT_FOUND")) {
|
|
163
|
+
return new Error(`❌ Google Vertex AI Model Not Found\n\n${message}\n\n🔧 Check:\n1. Model name is correct (e.g., 'gemini-1.5-pro')\n2. Model is available in your region (${this.location})\n3. Your project has access to the model\n4. Model supports your request parameters`);
|
|
158
164
|
}
|
|
159
|
-
if (
|
|
160
|
-
return new Error(`❌ Google Vertex AI Quota Exceeded\n\n${
|
|
165
|
+
if (message.includes("QUOTA_EXCEEDED")) {
|
|
166
|
+
return new Error(`❌ Google Vertex AI Quota Exceeded\n\n${message}\n\n🔧 Solutions:\n1. Check your Vertex AI quotas in Google Cloud Console\n2. Request quota increase if needed\n3. Try a different model or reduce request frequency\n4. Consider using a different region`);
|
|
161
167
|
}
|
|
162
|
-
if (
|
|
163
|
-
return new Error(`❌ Google Vertex AI Invalid Request\n\n${
|
|
168
|
+
if (message.includes("INVALID_ARGUMENT")) {
|
|
169
|
+
return new Error(`❌ Google Vertex AI Invalid Request\n\n${message}\n\n🔧 Check:\n1. Request parameters are within model limits\n2. Input text is properly formatted\n3. Temperature and other settings are valid\n4. Model supports your request type`);
|
|
164
170
|
}
|
|
165
|
-
return new Error(`❌ Google Vertex AI Provider Error\n\n${
|
|
171
|
+
return new Error(`❌ Google Vertex AI Provider Error\n\n${message}\n\n🔧 Troubleshooting:\n1. Check Google Cloud credentials and permissions\n2. Verify project ID and location settings\n3. Ensure Vertex AI API is enabled\n4. Check network connectivity`);
|
|
166
172
|
}
|
|
167
173
|
validateStreamOptions(options) {
|
|
168
174
|
if (!options.input?.text?.trim()) {
|
|
@@ -33,7 +33,7 @@ export declare class HuggingFaceProvider extends BaseProvider {
|
|
|
33
33
|
* Returns the Vercel AI SDK model instance for HuggingFace
|
|
34
34
|
*/
|
|
35
35
|
protected getAISDKModel(): LanguageModelV1;
|
|
36
|
-
protected handleProviderError(error:
|
|
36
|
+
protected handleProviderError(error: unknown): Error;
|
|
37
37
|
private validateStreamOptions;
|
|
38
38
|
}
|
|
39
39
|
export default HuggingFaceProvider;
|
|
@@ -114,14 +114,18 @@ export class HuggingFaceProvider extends BaseProvider {
|
|
|
114
114
|
if (error instanceof TimeoutError) {
|
|
115
115
|
return new Error(`HuggingFace request timed out: ${error.message}`);
|
|
116
116
|
}
|
|
117
|
-
|
|
118
|
-
|
|
117
|
+
const errorObj = error;
|
|
118
|
+
const message = errorObj?.message && typeof errorObj.message === "string"
|
|
119
|
+
? errorObj.message
|
|
120
|
+
: "Unknown error";
|
|
121
|
+
if (message.includes("API_TOKEN_INVALID") ||
|
|
122
|
+
message.includes("Invalid token")) {
|
|
119
123
|
return new Error("Invalid HuggingFace API token. Please check your HUGGING_FACE_API_KEY environment variable.");
|
|
120
124
|
}
|
|
121
|
-
if (
|
|
125
|
+
if (message.includes("rate limit")) {
|
|
122
126
|
return new Error("HuggingFace rate limit exceeded. Please try again later.");
|
|
123
127
|
}
|
|
124
|
-
return new Error(`HuggingFace error: ${
|
|
128
|
+
return new Error(`HuggingFace error: ${message}`);
|
|
125
129
|
}
|
|
126
130
|
// ===================
|
|
127
131
|
// PRIVATE VALIDATION METHODS
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* NeuroLink MCP-Aware AI Provider
|
|
3
3
|
* Integrates MCP tools with AI providers following Lighthouse's pattern
|
|
4
4
|
*/
|
|
5
|
-
import type { AIProvider, TextGenerationOptions
|
|
5
|
+
import type { AIProvider, TextGenerationOptions } from "../core/types.js";
|
|
6
6
|
import type { Schema } from "ai";
|
|
7
7
|
import type { GenerateResult } from "../types/generate-types.js";
|
|
8
8
|
import type { ZodType, ZodTypeDef } from "zod";
|
|
@@ -37,7 +37,7 @@ export declare class MCPAwareProvider implements AIProvider {
|
|
|
37
37
|
* PRIMARY METHOD: Stream content using AI (recommended for new code)
|
|
38
38
|
* Future-ready for multi-modal capabilities with current text focus
|
|
39
39
|
*/
|
|
40
|
-
stream(optionsOrPrompt: StreamOptions | string, analysisSchema?:
|
|
40
|
+
stream(optionsOrPrompt: StreamOptions | string, analysisSchema?: unknown): Promise<StreamResult>;
|
|
41
41
|
generate(optionsOrPrompt: TextGenerationOptions | string, analysisSchema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>): Promise<GenerateResult>;
|
|
42
42
|
/**
|
|
43
43
|
* Detect if the prompt is requesting tool usage
|
|
@@ -63,7 +63,7 @@ export declare class MCPAwareProvider implements AIProvider {
|
|
|
63
63
|
/**
|
|
64
64
|
* Short alias for generate() - CLI-SDK consistency
|
|
65
65
|
*/
|
|
66
|
-
gen(optionsOrPrompt: TextGenerationOptions | string, analysisSchema?:
|
|
66
|
+
gen(optionsOrPrompt: TextGenerationOptions | string, analysisSchema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>): Promise<GenerateResult>;
|
|
67
67
|
}
|
|
68
68
|
/**
|
|
69
69
|
* Create an MCP-aware provider
|
|
@@ -62,11 +62,26 @@ export class MCPAwareProvider {
|
|
|
62
62
|
exists: async () => false,
|
|
63
63
|
},
|
|
64
64
|
path: {
|
|
65
|
-
join: (...paths) =>
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
join: (...paths) => {
|
|
66
|
+
const pathModule = require("path");
|
|
67
|
+
return pathModule.join(...paths);
|
|
68
|
+
},
|
|
69
|
+
resolve: (...paths) => {
|
|
70
|
+
const pathModule = require("path");
|
|
71
|
+
return pathModule.resolve(...paths);
|
|
72
|
+
},
|
|
73
|
+
relative: (from, to) => {
|
|
74
|
+
const pathModule = require("path");
|
|
75
|
+
return pathModule.relative(from, to);
|
|
76
|
+
},
|
|
77
|
+
dirname: (pathArg) => {
|
|
78
|
+
const pathModule = require("path");
|
|
79
|
+
return pathModule.dirname(pathArg);
|
|
80
|
+
},
|
|
81
|
+
basename: (pathArg, ext) => {
|
|
82
|
+
const pathModule = require("path");
|
|
83
|
+
return pathModule.basename(pathArg, ext);
|
|
84
|
+
},
|
|
70
85
|
},
|
|
71
86
|
grantedPermissions: [],
|
|
72
87
|
log: console.log,
|
|
@@ -1,42 +1,49 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import type { AIProviderName } from "../core/types.js";
|
|
1
|
+
import { type LanguageModelV1 } from "ai";
|
|
2
|
+
import type { AIProviderName, TextGenerationOptions, EnhancedGenerateResult } from "../core/types.js";
|
|
4
3
|
import type { StreamOptions, StreamResult } from "../types/stream-types.js";
|
|
5
4
|
import { BaseProvider } from "../core/base-provider.js";
|
|
6
5
|
/**
|
|
7
6
|
* Mistral AI Provider v2 - BaseProvider Implementation
|
|
8
|
-
*
|
|
9
|
-
* PHASE 3.6: Simple BaseProvider wrap around existing @ai-sdk/mistral implementation
|
|
10
|
-
*
|
|
11
|
-
* Features:
|
|
12
|
-
* - Extends BaseProvider for shared functionality
|
|
13
|
-
* - Uses pre-configured Mistral instance for efficiency
|
|
14
|
-
* - Enhanced error handling with setup guidance
|
|
15
|
-
* - Supports all Mistral models (mistral-small, mistral-medium, mistral-large)
|
|
7
|
+
* Supports official AI-SDK integration with all Mistral models
|
|
16
8
|
*/
|
|
17
9
|
export declare class MistralProvider extends BaseProvider {
|
|
18
|
-
private mistral;
|
|
19
10
|
private model;
|
|
20
|
-
constructor(modelName?: string, sdk?:
|
|
21
|
-
protected getProviderName(): AIProviderName;
|
|
22
|
-
protected getDefaultModel(): string;
|
|
11
|
+
constructor(modelName?: string, sdk?: unknown);
|
|
23
12
|
/**
|
|
24
|
-
*
|
|
13
|
+
* Generate text using Mistral API
|
|
25
14
|
*/
|
|
26
|
-
|
|
27
|
-
protected executeStream(options: StreamOptions, analysisSchema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>): Promise<StreamResult>;
|
|
28
|
-
protected handleProviderError(error: any): Error;
|
|
29
|
-
private validateStreamOptions;
|
|
15
|
+
generate(options: TextGenerationOptions): Promise<EnhancedGenerateResult>;
|
|
30
16
|
/**
|
|
31
|
-
*
|
|
32
|
-
* @returns Array of available model names
|
|
17
|
+
* Stream text generation using Mistral API
|
|
33
18
|
*/
|
|
34
|
-
|
|
19
|
+
executeStream(options: StreamOptions): Promise<StreamResult>;
|
|
35
20
|
/**
|
|
36
|
-
* Get
|
|
37
|
-
* @param useCase - The intended use case
|
|
38
|
-
* @returns Recommended model name
|
|
21
|
+
* Get default model name for this provider
|
|
39
22
|
*/
|
|
40
|
-
|
|
23
|
+
getDefaultModel(): string;
|
|
24
|
+
/**
|
|
25
|
+
* Get provider name
|
|
26
|
+
*/
|
|
27
|
+
getProviderName(): AIProviderName;
|
|
28
|
+
/**
|
|
29
|
+
* Get AI SDK model instance
|
|
30
|
+
*/
|
|
31
|
+
getAISDKModel(): LanguageModelV1;
|
|
32
|
+
/**
|
|
33
|
+
* Handle provider-specific errors
|
|
34
|
+
*/
|
|
35
|
+
handleProviderError(error: unknown): Error;
|
|
36
|
+
/**
|
|
37
|
+
* Validate provider configuration
|
|
38
|
+
*/
|
|
39
|
+
validateConfiguration(): Promise<boolean>;
|
|
40
|
+
/**
|
|
41
|
+
* Get provider-specific configuration
|
|
42
|
+
*/
|
|
43
|
+
getConfiguration(): {
|
|
44
|
+
provider: AIProviderName;
|
|
45
|
+
model: string;
|
|
46
|
+
defaultModel: string;
|
|
47
|
+
};
|
|
41
48
|
}
|
|
42
49
|
export default MistralProvider;
|