@juspay/neurolink 1.6.0 → 1.9.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 +193 -7
- package/README.md +100 -17
- package/dist/agent/direct-tools.d.ts +1203 -0
- package/dist/agent/direct-tools.js +387 -0
- package/dist/cli/commands/agent-generate.d.ts +2 -0
- package/dist/cli/commands/agent-generate.js +70 -0
- package/dist/cli/commands/config.d.ts +6 -6
- package/dist/cli/commands/config.js +326 -273
- package/dist/cli/commands/mcp.d.ts +2 -1
- package/dist/cli/commands/mcp.js +874 -146
- package/dist/cli/commands/ollama.d.ts +1 -1
- package/dist/cli/commands/ollama.js +153 -143
- package/dist/cli/index.js +589 -323
- package/dist/cli/utils/complete-setup.d.ts +19 -0
- package/dist/cli/utils/complete-setup.js +81 -0
- package/dist/cli/utils/env-manager.d.ts +44 -0
- package/dist/cli/utils/env-manager.js +226 -0
- package/dist/cli/utils/interactive-setup.d.ts +48 -0
- package/dist/cli/utils/interactive-setup.js +302 -0
- package/dist/core/dynamic-models.d.ts +208 -0
- package/dist/core/dynamic-models.js +250 -0
- package/dist/core/factory.d.ts +13 -6
- package/dist/core/factory.js +176 -61
- package/dist/core/types.d.ts +4 -2
- package/dist/core/types.js +4 -4
- package/dist/index.d.ts +16 -16
- package/dist/index.js +16 -16
- package/dist/lib/agent/direct-tools.d.ts +1203 -0
- package/dist/lib/agent/direct-tools.js +387 -0
- package/dist/lib/core/dynamic-models.d.ts +208 -0
- package/dist/lib/core/dynamic-models.js +250 -0
- package/dist/lib/core/factory.d.ts +13 -6
- package/dist/lib/core/factory.js +176 -61
- package/dist/lib/core/types.d.ts +4 -2
- package/dist/lib/core/types.js +4 -4
- package/dist/lib/index.d.ts +16 -16
- package/dist/lib/index.js +16 -16
- package/dist/lib/mcp/auto-discovery.d.ts +120 -0
- package/dist/lib/mcp/auto-discovery.js +793 -0
- package/dist/lib/mcp/client.d.ts +66 -0
- package/dist/lib/mcp/client.js +245 -0
- package/dist/lib/mcp/config.d.ts +31 -0
- package/dist/lib/mcp/config.js +74 -0
- package/dist/lib/mcp/context-manager.d.ts +4 -4
- package/dist/lib/mcp/context-manager.js +24 -18
- package/dist/lib/mcp/factory.d.ts +28 -11
- package/dist/lib/mcp/factory.js +36 -29
- package/dist/lib/mcp/function-calling.d.ts +51 -0
- package/dist/lib/mcp/function-calling.js +510 -0
- package/dist/lib/mcp/index.d.ts +190 -0
- package/dist/lib/mcp/index.js +156 -0
- package/dist/lib/mcp/initialize-tools.d.ts +28 -0
- package/dist/lib/mcp/initialize-tools.js +209 -0
- package/dist/lib/mcp/initialize.d.ts +17 -0
- package/dist/lib/mcp/initialize.js +51 -0
- package/dist/lib/mcp/logging.d.ts +71 -0
- package/dist/lib/mcp/logging.js +183 -0
- package/dist/lib/mcp/manager.d.ts +67 -0
- package/dist/lib/mcp/manager.js +176 -0
- package/dist/lib/mcp/neurolink-mcp-client.d.ts +96 -0
- package/dist/lib/mcp/neurolink-mcp-client.js +417 -0
- package/dist/lib/mcp/orchestrator.d.ts +3 -3
- package/dist/lib/mcp/orchestrator.js +46 -43
- package/dist/lib/mcp/registry.d.ts +2 -2
- package/dist/lib/mcp/registry.js +42 -33
- package/dist/lib/mcp/servers/ai-providers/ai-analysis-tools.d.ts +1 -1
- package/dist/lib/mcp/servers/ai-providers/ai-analysis-tools.js +204 -65
- package/dist/lib/mcp/servers/ai-providers/ai-core-server.js +142 -102
- package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.d.ts +6 -6
- package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.js +197 -142
- package/dist/lib/mcp/servers/utilities/utility-server.d.ts +8 -0
- package/dist/lib/mcp/servers/utilities/utility-server.js +326 -0
- package/dist/lib/mcp/tool-integration.d.ts +67 -0
- package/dist/lib/mcp/tool-integration.js +179 -0
- package/dist/lib/mcp/unified-registry.d.ts +269 -0
- package/dist/lib/mcp/unified-registry.js +1411 -0
- package/dist/lib/neurolink.d.ts +68 -6
- package/dist/lib/neurolink.js +304 -42
- package/dist/lib/providers/agent-enhanced-provider.d.ts +59 -0
- package/dist/lib/providers/agent-enhanced-provider.js +242 -0
- package/dist/lib/providers/amazonBedrock.d.ts +3 -3
- package/dist/lib/providers/amazonBedrock.js +54 -50
- package/dist/lib/providers/anthropic.d.ts +2 -2
- package/dist/lib/providers/anthropic.js +92 -84
- package/dist/lib/providers/azureOpenAI.d.ts +2 -2
- package/dist/lib/providers/azureOpenAI.js +97 -86
- package/dist/lib/providers/function-calling-provider.d.ts +70 -0
- package/dist/lib/providers/function-calling-provider.js +359 -0
- package/dist/lib/providers/googleAIStudio.d.ts +10 -5
- package/dist/lib/providers/googleAIStudio.js +60 -38
- package/dist/lib/providers/googleVertexAI.d.ts +3 -3
- package/dist/lib/providers/googleVertexAI.js +96 -86
- package/dist/lib/providers/huggingFace.d.ts +3 -3
- package/dist/lib/providers/huggingFace.js +70 -63
- package/dist/lib/providers/index.d.ts +11 -11
- package/dist/lib/providers/index.js +18 -18
- package/dist/lib/providers/mcp-provider.d.ts +62 -0
- package/dist/lib/providers/mcp-provider.js +183 -0
- package/dist/lib/providers/mistralAI.d.ts +3 -3
- package/dist/lib/providers/mistralAI.js +42 -36
- package/dist/lib/providers/ollama.d.ts +4 -4
- package/dist/lib/providers/ollama.js +113 -98
- package/dist/lib/providers/openAI.d.ts +7 -3
- package/dist/lib/providers/openAI.js +45 -33
- package/dist/lib/utils/logger.js +2 -2
- package/dist/lib/utils/providerUtils.js +53 -31
- package/dist/mcp/auto-discovery.d.ts +120 -0
- package/dist/mcp/auto-discovery.js +794 -0
- package/dist/mcp/client.d.ts +66 -0
- package/dist/mcp/client.js +245 -0
- package/dist/mcp/config.d.ts +31 -0
- package/dist/mcp/config.js +74 -0
- package/dist/mcp/context-manager.d.ts +4 -4
- package/dist/mcp/context-manager.js +24 -18
- package/dist/mcp/factory.d.ts +28 -11
- package/dist/mcp/factory.js +36 -29
- package/dist/mcp/function-calling.d.ts +51 -0
- package/dist/mcp/function-calling.js +510 -0
- package/dist/mcp/index.d.ts +190 -0
- package/dist/mcp/index.js +156 -0
- package/dist/mcp/initialize-tools.d.ts +28 -0
- package/dist/mcp/initialize-tools.js +210 -0
- package/dist/mcp/initialize.d.ts +17 -0
- package/dist/mcp/initialize.js +51 -0
- package/dist/mcp/logging.d.ts +71 -0
- package/dist/mcp/logging.js +183 -0
- package/dist/mcp/manager.d.ts +67 -0
- package/dist/mcp/manager.js +176 -0
- package/dist/mcp/neurolink-mcp-client.d.ts +96 -0
- package/dist/mcp/neurolink-mcp-client.js +417 -0
- package/dist/mcp/orchestrator.d.ts +3 -3
- package/dist/mcp/orchestrator.js +46 -43
- package/dist/mcp/registry.d.ts +2 -2
- package/dist/mcp/registry.js +42 -33
- package/dist/mcp/servers/ai-providers/ai-analysis-tools.d.ts +1 -1
- package/dist/mcp/servers/ai-providers/ai-analysis-tools.js +204 -65
- package/dist/mcp/servers/ai-providers/ai-core-server.js +142 -102
- package/dist/mcp/servers/ai-providers/ai-workflow-tools.d.ts +6 -6
- package/dist/mcp/servers/ai-providers/ai-workflow-tools.js +197 -142
- package/dist/mcp/servers/utilities/utility-server.d.ts +8 -0
- package/dist/mcp/servers/utilities/utility-server.js +326 -0
- package/dist/mcp/tool-integration.d.ts +67 -0
- package/dist/mcp/tool-integration.js +179 -0
- package/dist/mcp/unified-registry.d.ts +269 -0
- package/dist/mcp/unified-registry.js +1411 -0
- package/dist/neurolink.d.ts +68 -6
- package/dist/neurolink.js +304 -42
- package/dist/providers/agent-enhanced-provider.d.ts +59 -0
- package/dist/providers/agent-enhanced-provider.js +242 -0
- package/dist/providers/amazonBedrock.d.ts +3 -3
- package/dist/providers/amazonBedrock.js +54 -50
- package/dist/providers/anthropic.d.ts +2 -2
- package/dist/providers/anthropic.js +92 -84
- package/dist/providers/azureOpenAI.d.ts +2 -2
- package/dist/providers/azureOpenAI.js +97 -86
- package/dist/providers/function-calling-provider.d.ts +70 -0
- package/dist/providers/function-calling-provider.js +359 -0
- package/dist/providers/googleAIStudio.d.ts +10 -5
- package/dist/providers/googleAIStudio.js +60 -38
- package/dist/providers/googleVertexAI.d.ts +3 -3
- package/dist/providers/googleVertexAI.js +96 -86
- package/dist/providers/huggingFace.d.ts +3 -3
- package/dist/providers/huggingFace.js +70 -63
- package/dist/providers/index.d.ts +11 -11
- package/dist/providers/index.js +18 -18
- package/dist/providers/mcp-provider.d.ts +62 -0
- package/dist/providers/mcp-provider.js +183 -0
- package/dist/providers/mistralAI.d.ts +3 -3
- package/dist/providers/mistralAI.js +42 -36
- package/dist/providers/ollama.d.ts +4 -4
- package/dist/providers/ollama.js +113 -98
- package/dist/providers/openAI.d.ts +7 -3
- package/dist/providers/openAI.js +45 -33
- package/dist/utils/logger.js +2 -2
- package/dist/utils/providerUtils.js +53 -31
- package/package.json +175 -161
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { HfInference } from
|
|
2
|
-
import { streamText, generateText, Output } from
|
|
3
|
-
import { logger } from
|
|
1
|
+
import { HfInference } from "@huggingface/inference";
|
|
2
|
+
import { streamText, generateText, Output, } from "ai";
|
|
3
|
+
import { logger } from "../utils/logger.js";
|
|
4
4
|
// Default system context
|
|
5
5
|
const DEFAULT_SYSTEM_CONTEXT = {
|
|
6
|
-
systemPrompt:
|
|
6
|
+
systemPrompt: "You are a helpful AI assistant.",
|
|
7
7
|
};
|
|
8
8
|
// Configuration helpers
|
|
9
9
|
const getHuggingFaceApiKey = () => {
|
|
10
10
|
const apiKey = process.env.HUGGINGFACE_API_KEY || process.env.HF_TOKEN;
|
|
11
11
|
if (!apiKey) {
|
|
12
|
-
throw new Error(
|
|
12
|
+
throw new Error("HUGGINGFACE_API_KEY environment variable is not set");
|
|
13
13
|
}
|
|
14
14
|
return apiKey;
|
|
15
15
|
};
|
|
16
16
|
const getHuggingFaceModelId = () => {
|
|
17
|
-
return process.env.HUGGINGFACE_MODEL ||
|
|
17
|
+
return process.env.HUGGINGFACE_MODEL || "microsoft/DialoGPT-medium";
|
|
18
18
|
};
|
|
19
19
|
const hasValidAuth = () => {
|
|
20
20
|
return !!(process.env.HUGGINGFACE_API_KEY || process.env.HF_TOKEN);
|
|
@@ -33,7 +33,7 @@ const RETRY_CONFIG = {
|
|
|
33
33
|
maxRetries: 3,
|
|
34
34
|
baseDelay: 2000, // 2 seconds
|
|
35
35
|
maxDelay: 30000, // 30 seconds
|
|
36
|
-
backoffMultiplier: 2
|
|
36
|
+
backoffMultiplier: 2,
|
|
37
37
|
};
|
|
38
38
|
// Helper function for exponential backoff retry
|
|
39
39
|
async function retryWithBackoff(operation, retryConfig = RETRY_CONFIG) {
|
|
@@ -45,16 +45,17 @@ async function retryWithBackoff(operation, retryConfig = RETRY_CONFIG) {
|
|
|
45
45
|
catch (error) {
|
|
46
46
|
lastError = error;
|
|
47
47
|
// Check if it's a model loading error (503 status)
|
|
48
|
-
if (error instanceof Error && error.message.includes(
|
|
48
|
+
if (error instanceof Error && error.message.includes("503")) {
|
|
49
49
|
if (attempt < retryConfig.maxRetries) {
|
|
50
|
-
const delay = Math.min(retryConfig.baseDelay *
|
|
51
|
-
|
|
50
|
+
const delay = Math.min(retryConfig.baseDelay *
|
|
51
|
+
Math.pow(retryConfig.backoffMultiplier, attempt), retryConfig.maxDelay);
|
|
52
|
+
logger.debug("HuggingFace model loading, retrying...", {
|
|
52
53
|
attempt: attempt + 1,
|
|
53
54
|
maxRetries: retryConfig.maxRetries,
|
|
54
55
|
delayMs: delay,
|
|
55
|
-
error: error.message
|
|
56
|
+
error: error.message,
|
|
56
57
|
});
|
|
57
|
-
await new Promise(resolve => setTimeout(resolve, delay));
|
|
58
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
58
59
|
continue;
|
|
59
60
|
}
|
|
60
61
|
}
|
|
@@ -66,12 +67,12 @@ async function retryWithBackoff(operation, retryConfig = RETRY_CONFIG) {
|
|
|
66
67
|
}
|
|
67
68
|
// Custom LanguageModelV1 implementation for Hugging Face
|
|
68
69
|
class HuggingFaceLanguageModel {
|
|
69
|
-
specificationVersion =
|
|
70
|
-
provider =
|
|
70
|
+
specificationVersion = "v1";
|
|
71
|
+
provider = "huggingface";
|
|
71
72
|
modelId;
|
|
72
73
|
maxTokens;
|
|
73
74
|
supportsStreaming = true;
|
|
74
|
-
defaultObjectGenerationMode =
|
|
75
|
+
defaultObjectGenerationMode = "json";
|
|
75
76
|
client;
|
|
76
77
|
constructor(modelId, client) {
|
|
77
78
|
this.modelId = modelId;
|
|
@@ -82,20 +83,20 @@ class HuggingFaceLanguageModel {
|
|
|
82
83
|
}
|
|
83
84
|
convertMessagesToPrompt(messages) {
|
|
84
85
|
return messages
|
|
85
|
-
.map(msg => {
|
|
86
|
-
if (typeof msg.content ===
|
|
86
|
+
.map((msg) => {
|
|
87
|
+
if (typeof msg.content === "string") {
|
|
87
88
|
return `${msg.role}: ${msg.content}`;
|
|
88
89
|
}
|
|
89
90
|
else if (Array.isArray(msg.content)) {
|
|
90
91
|
// Handle multi-part content (text, images, etc.)
|
|
91
92
|
return `${msg.role}: ${msg.content
|
|
92
|
-
.filter((part) => part.type ===
|
|
93
|
+
.filter((part) => part.type === "text")
|
|
93
94
|
.map((part) => part.text)
|
|
94
|
-
.join(
|
|
95
|
+
.join(" ")}`;
|
|
95
96
|
}
|
|
96
|
-
return
|
|
97
|
+
return "";
|
|
97
98
|
})
|
|
98
|
-
.join(
|
|
99
|
+
.join("\n");
|
|
99
100
|
}
|
|
100
101
|
async doGenerate(options) {
|
|
101
102
|
const prompt = this.convertMessagesToPrompt(options.prompt);
|
|
@@ -107,11 +108,11 @@ class HuggingFaceLanguageModel {
|
|
|
107
108
|
temperature: options.temperature || 0.7,
|
|
108
109
|
max_new_tokens: options.maxTokens || 500,
|
|
109
110
|
return_full_text: false,
|
|
110
|
-
do_sample: (options.temperature || 0.7) > 0
|
|
111
|
-
}
|
|
111
|
+
do_sample: (options.temperature || 0.7) > 0,
|
|
112
|
+
},
|
|
112
113
|
});
|
|
113
114
|
});
|
|
114
|
-
const generatedText = response.generated_text ||
|
|
115
|
+
const generatedText = response.generated_text || "";
|
|
115
116
|
const promptTokens = this.estimateTokens(prompt);
|
|
116
117
|
const completionTokens = this.estimateTokens(generatedText);
|
|
117
118
|
return {
|
|
@@ -119,12 +120,12 @@ class HuggingFaceLanguageModel {
|
|
|
119
120
|
usage: {
|
|
120
121
|
promptTokens,
|
|
121
122
|
completionTokens,
|
|
122
|
-
totalTokens: promptTokens + completionTokens
|
|
123
|
+
totalTokens: promptTokens + completionTokens,
|
|
123
124
|
},
|
|
124
|
-
finishReason:
|
|
125
|
+
finishReason: "stop",
|
|
125
126
|
logprobs: undefined,
|
|
126
127
|
rawCall: { rawPrompt: prompt, rawSettings: options },
|
|
127
|
-
rawResponse: { headers: {} }
|
|
128
|
+
rawResponse: { headers: {} },
|
|
128
129
|
};
|
|
129
130
|
}
|
|
130
131
|
async doStream(options) {
|
|
@@ -135,15 +136,15 @@ class HuggingFaceLanguageModel {
|
|
|
135
136
|
// Create a ReadableStream that chunks the response
|
|
136
137
|
const stream = new ReadableStream({
|
|
137
138
|
start(controller) {
|
|
138
|
-
const text = response.text ||
|
|
139
|
+
const text = response.text || "";
|
|
139
140
|
const chunkSize = Math.max(1, Math.floor(text.length / 10)); // 10 chunks
|
|
140
141
|
let index = 0;
|
|
141
142
|
const pushChunk = () => {
|
|
142
143
|
if (index < text.length) {
|
|
143
144
|
const chunk = text.slice(index, index + chunkSize);
|
|
144
145
|
controller.enqueue({
|
|
145
|
-
type:
|
|
146
|
-
textDelta: chunk
|
|
146
|
+
type: "text-delta",
|
|
147
|
+
textDelta: chunk,
|
|
147
148
|
});
|
|
148
149
|
index += chunkSize;
|
|
149
150
|
// Add delay to simulate streaming
|
|
@@ -152,21 +153,21 @@ class HuggingFaceLanguageModel {
|
|
|
152
153
|
else {
|
|
153
154
|
// Send finish event
|
|
154
155
|
controller.enqueue({
|
|
155
|
-
type:
|
|
156
|
+
type: "finish",
|
|
156
157
|
finishReason: response.finishReason,
|
|
157
158
|
usage: response.usage,
|
|
158
|
-
logprobs: response.logprobs
|
|
159
|
+
logprobs: response.logprobs,
|
|
159
160
|
});
|
|
160
161
|
controller.close();
|
|
161
162
|
}
|
|
162
163
|
};
|
|
163
164
|
pushChunk();
|
|
164
|
-
}
|
|
165
|
+
},
|
|
165
166
|
});
|
|
166
167
|
return {
|
|
167
168
|
stream,
|
|
168
169
|
rawCall: response.rawCall,
|
|
169
|
-
rawResponse: response.rawResponse
|
|
170
|
+
rawResponse: response.rawResponse,
|
|
170
171
|
};
|
|
171
172
|
}
|
|
172
173
|
}
|
|
@@ -179,25 +180,25 @@ export class HuggingFace {
|
|
|
179
180
|
* @param modelName - Optional model name to override the default from config
|
|
180
181
|
*/
|
|
181
182
|
constructor(modelName) {
|
|
182
|
-
const functionTag =
|
|
183
|
+
const functionTag = "HuggingFace.constructor";
|
|
183
184
|
this.modelName = modelName || getHuggingFaceModelId();
|
|
184
185
|
try {
|
|
185
186
|
this.client = getHuggingFaceClient();
|
|
186
187
|
logger.debug(`[${functionTag}] Initialization started`, {
|
|
187
188
|
modelName: this.modelName,
|
|
188
|
-
hasApiKey: hasValidAuth()
|
|
189
|
+
hasApiKey: hasValidAuth(),
|
|
189
190
|
});
|
|
190
191
|
logger.debug(`[${functionTag}] Initialization completed`, {
|
|
191
192
|
modelName: this.modelName,
|
|
192
|
-
success: true
|
|
193
|
+
success: true,
|
|
193
194
|
});
|
|
194
195
|
}
|
|
195
196
|
catch (err) {
|
|
196
197
|
logger.error(`[${functionTag}] Initialization failed`, {
|
|
197
|
-
message:
|
|
198
|
+
message: "Error in initializing Hugging Face",
|
|
198
199
|
modelName: this.modelName,
|
|
199
200
|
error: err instanceof Error ? err.message : String(err),
|
|
200
|
-
stack: err instanceof Error ? err.stack : undefined
|
|
201
|
+
stack: err instanceof Error ? err.stack : undefined,
|
|
201
202
|
});
|
|
202
203
|
throw err;
|
|
203
204
|
}
|
|
@@ -207,8 +208,8 @@ export class HuggingFace {
|
|
|
207
208
|
* @private
|
|
208
209
|
*/
|
|
209
210
|
getModel() {
|
|
210
|
-
logger.debug(
|
|
211
|
-
modelName: this.modelName
|
|
211
|
+
logger.debug("HuggingFace.getModel - Hugging Face model selected", {
|
|
212
|
+
modelName: this.modelName,
|
|
212
213
|
});
|
|
213
214
|
return new HuggingFaceLanguageModel(this.modelName, this.client);
|
|
214
215
|
}
|
|
@@ -219,15 +220,15 @@ export class HuggingFace {
|
|
|
219
220
|
* @returns Promise resolving to StreamTextResult or null if operation fails
|
|
220
221
|
*/
|
|
221
222
|
async streamText(optionsOrPrompt, analysisSchema) {
|
|
222
|
-
const functionTag =
|
|
223
|
-
const provider =
|
|
223
|
+
const functionTag = "HuggingFace.streamText";
|
|
224
|
+
const provider = "huggingface";
|
|
224
225
|
let chunkCount = 0;
|
|
225
226
|
try {
|
|
226
227
|
// Parse parameters - support both string and options object
|
|
227
|
-
const options = typeof optionsOrPrompt ===
|
|
228
|
+
const options = typeof optionsOrPrompt === "string"
|
|
228
229
|
? { prompt: optionsOrPrompt }
|
|
229
230
|
: optionsOrPrompt;
|
|
230
|
-
const { prompt, temperature = 0.7, maxTokens = 500, systemPrompt = DEFAULT_SYSTEM_CONTEXT.systemPrompt, schema } = options;
|
|
231
|
+
const { prompt, temperature = 0.7, maxTokens = 500, systemPrompt = DEFAULT_SYSTEM_CONTEXT.systemPrompt, schema, } = options;
|
|
231
232
|
// Use schema from options or fallback parameter
|
|
232
233
|
const finalSchema = schema || analysisSchema;
|
|
233
234
|
logger.debug(`[${functionTag}] Stream request started`, {
|
|
@@ -236,7 +237,7 @@ export class HuggingFace {
|
|
|
236
237
|
promptLength: prompt.length,
|
|
237
238
|
temperature,
|
|
238
239
|
maxTokens,
|
|
239
|
-
hasSchema: !!finalSchema
|
|
240
|
+
hasSchema: !!finalSchema,
|
|
240
241
|
});
|
|
241
242
|
const model = this.getModel();
|
|
242
243
|
const streamOptions = {
|
|
@@ -255,7 +256,7 @@ export class HuggingFace {
|
|
|
255
256
|
error: errorMessage,
|
|
256
257
|
stack: errorStack,
|
|
257
258
|
promptLength: prompt.length,
|
|
258
|
-
chunkCount
|
|
259
|
+
chunkCount,
|
|
259
260
|
});
|
|
260
261
|
},
|
|
261
262
|
onFinish: (event) => {
|
|
@@ -266,7 +267,7 @@ export class HuggingFace {
|
|
|
266
267
|
usage: event.usage,
|
|
267
268
|
totalChunks: chunkCount,
|
|
268
269
|
promptLength: prompt.length,
|
|
269
|
-
responseLength: event.text?.length || 0
|
|
270
|
+
responseLength: event.text?.length || 0,
|
|
270
271
|
});
|
|
271
272
|
},
|
|
272
273
|
onChunk: (event) => {
|
|
@@ -276,12 +277,14 @@ export class HuggingFace {
|
|
|
276
277
|
modelName: this.modelName,
|
|
277
278
|
chunkNumber: chunkCount,
|
|
278
279
|
chunkLength: event.chunk.text?.length || 0,
|
|
279
|
-
chunkType: event.chunk.type
|
|
280
|
+
chunkType: event.chunk.type,
|
|
280
281
|
});
|
|
281
|
-
}
|
|
282
|
+
},
|
|
282
283
|
};
|
|
283
284
|
if (finalSchema) {
|
|
284
|
-
streamOptions.experimental_output = Output.object({
|
|
285
|
+
streamOptions.experimental_output = Output.object({
|
|
286
|
+
schema: finalSchema,
|
|
287
|
+
});
|
|
285
288
|
}
|
|
286
289
|
const result = streamText(streamOptions);
|
|
287
290
|
return result;
|
|
@@ -290,9 +293,11 @@ export class HuggingFace {
|
|
|
290
293
|
logger.error(`[${functionTag}] Exception`, {
|
|
291
294
|
provider,
|
|
292
295
|
modelName: this.modelName,
|
|
293
|
-
message:
|
|
296
|
+
message: "Error in streaming text",
|
|
294
297
|
err: String(err),
|
|
295
|
-
promptLength: typeof optionsOrPrompt ===
|
|
298
|
+
promptLength: typeof optionsOrPrompt === "string"
|
|
299
|
+
? optionsOrPrompt.length
|
|
300
|
+
: optionsOrPrompt.prompt.length,
|
|
296
301
|
});
|
|
297
302
|
throw err; // Re-throw error to trigger fallback
|
|
298
303
|
}
|
|
@@ -304,14 +309,14 @@ export class HuggingFace {
|
|
|
304
309
|
* @returns Promise resolving to GenerateTextResult or null if operation fails
|
|
305
310
|
*/
|
|
306
311
|
async generateText(optionsOrPrompt, analysisSchema) {
|
|
307
|
-
const functionTag =
|
|
308
|
-
const provider =
|
|
312
|
+
const functionTag = "HuggingFace.generateText";
|
|
313
|
+
const provider = "huggingface";
|
|
309
314
|
try {
|
|
310
315
|
// Parse parameters - support both string and options object
|
|
311
|
-
const options = typeof optionsOrPrompt ===
|
|
316
|
+
const options = typeof optionsOrPrompt === "string"
|
|
312
317
|
? { prompt: optionsOrPrompt }
|
|
313
318
|
: optionsOrPrompt;
|
|
314
|
-
const { prompt, temperature = 0.7, maxTokens = 500, systemPrompt = DEFAULT_SYSTEM_CONTEXT.systemPrompt, schema } = options;
|
|
319
|
+
const { prompt, temperature = 0.7, maxTokens = 500, systemPrompt = DEFAULT_SYSTEM_CONTEXT.systemPrompt, schema, } = options;
|
|
315
320
|
// Use schema from options or fallback parameter
|
|
316
321
|
const finalSchema = schema || analysisSchema;
|
|
317
322
|
logger.debug(`[${functionTag}] Generate request started`, {
|
|
@@ -319,7 +324,7 @@ export class HuggingFace {
|
|
|
319
324
|
modelName: this.modelName,
|
|
320
325
|
promptLength: prompt.length,
|
|
321
326
|
temperature,
|
|
322
|
-
maxTokens
|
|
327
|
+
maxTokens,
|
|
323
328
|
});
|
|
324
329
|
const model = this.getModel();
|
|
325
330
|
const generateOptions = {
|
|
@@ -327,10 +332,12 @@ export class HuggingFace {
|
|
|
327
332
|
prompt: prompt,
|
|
328
333
|
system: systemPrompt,
|
|
329
334
|
temperature,
|
|
330
|
-
maxTokens
|
|
335
|
+
maxTokens,
|
|
331
336
|
};
|
|
332
337
|
if (finalSchema) {
|
|
333
|
-
generateOptions.experimental_output = Output.object({
|
|
338
|
+
generateOptions.experimental_output = Output.object({
|
|
339
|
+
schema: finalSchema,
|
|
340
|
+
});
|
|
334
341
|
}
|
|
335
342
|
const result = await generateText(generateOptions);
|
|
336
343
|
logger.debug(`[${functionTag}] Generate text completed`, {
|
|
@@ -338,7 +345,7 @@ export class HuggingFace {
|
|
|
338
345
|
modelName: this.modelName,
|
|
339
346
|
usage: result.usage,
|
|
340
347
|
finishReason: result.finishReason,
|
|
341
|
-
responseLength: result.text?.length || 0
|
|
348
|
+
responseLength: result.text?.length || 0,
|
|
342
349
|
});
|
|
343
350
|
return result;
|
|
344
351
|
}
|
|
@@ -346,8 +353,8 @@ export class HuggingFace {
|
|
|
346
353
|
logger.error(`[${functionTag}] Exception`, {
|
|
347
354
|
provider,
|
|
348
355
|
modelName: this.modelName,
|
|
349
|
-
message:
|
|
350
|
-
err: String(err)
|
|
356
|
+
message: "Error in generating text",
|
|
357
|
+
err: String(err),
|
|
351
358
|
});
|
|
352
359
|
throw err; // Re-throw error to trigger fallback
|
|
353
360
|
}
|
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
* Provider exports for Vercel AI SDK integration
|
|
3
3
|
* This file centralizes all AI provider classes for easy import and usage
|
|
4
4
|
*/
|
|
5
|
-
export { GoogleVertexAI } from
|
|
6
|
-
export { AmazonBedrock } from
|
|
7
|
-
export { OpenAI } from
|
|
8
|
-
export { AnthropicProvider } from
|
|
9
|
-
export { AzureOpenAIProvider } from
|
|
10
|
-
export { GoogleAIStudio } from
|
|
11
|
-
export { HuggingFace } from
|
|
12
|
-
export { Ollama } from
|
|
13
|
-
export { MistralAI } from
|
|
14
|
-
export type { AIProvider } from
|
|
5
|
+
export { GoogleVertexAI } from "./googleVertexAI.js";
|
|
6
|
+
export { AmazonBedrock } from "./amazonBedrock.js";
|
|
7
|
+
export { OpenAI } from "./openAI.js";
|
|
8
|
+
export { AnthropicProvider } from "./anthropic.js";
|
|
9
|
+
export { AzureOpenAIProvider } from "./azureOpenAI.js";
|
|
10
|
+
export { GoogleAIStudio } from "./googleAIStudio.js";
|
|
11
|
+
export { HuggingFace } from "./huggingFace.js";
|
|
12
|
+
export { Ollama } from "./ollama.js";
|
|
13
|
+
export { MistralAI } from "./mistralAI.js";
|
|
14
|
+
export type { AIProvider } from "../core/types.js";
|
|
15
15
|
/**
|
|
16
16
|
* Provider registry for dynamic provider instantiation
|
|
17
17
|
*/
|
|
@@ -21,7 +21,7 @@ export declare const PROVIDERS: {
|
|
|
21
21
|
readonly openai: "OpenAI";
|
|
22
22
|
readonly anthropic: "AnthropicProvider";
|
|
23
23
|
readonly azure: "AzureOpenAIProvider";
|
|
24
|
-
readonly
|
|
24
|
+
readonly "google-ai": "GoogleAIStudio";
|
|
25
25
|
readonly huggingface: "HuggingFace";
|
|
26
26
|
readonly ollama: "Ollama";
|
|
27
27
|
readonly mistral: "MistralAI";
|
package/dist/providers/index.js
CHANGED
|
@@ -2,28 +2,28 @@
|
|
|
2
2
|
* Provider exports for Vercel AI SDK integration
|
|
3
3
|
* This file centralizes all AI provider classes for easy import and usage
|
|
4
4
|
*/
|
|
5
|
-
export { GoogleVertexAI } from
|
|
6
|
-
export { AmazonBedrock } from
|
|
7
|
-
export { OpenAI } from
|
|
8
|
-
export { AnthropicProvider } from
|
|
9
|
-
export { AzureOpenAIProvider } from
|
|
10
|
-
export { GoogleAIStudio } from
|
|
11
|
-
export { HuggingFace } from
|
|
12
|
-
export { Ollama } from
|
|
13
|
-
export { MistralAI } from
|
|
5
|
+
export { GoogleVertexAI } from "./googleVertexAI.js";
|
|
6
|
+
export { AmazonBedrock } from "./amazonBedrock.js";
|
|
7
|
+
export { OpenAI } from "./openAI.js";
|
|
8
|
+
export { AnthropicProvider } from "./anthropic.js";
|
|
9
|
+
export { AzureOpenAIProvider } from "./azureOpenAI.js";
|
|
10
|
+
export { GoogleAIStudio } from "./googleAIStudio.js";
|
|
11
|
+
export { HuggingFace } from "./huggingFace.js";
|
|
12
|
+
export { Ollama } from "./ollama.js";
|
|
13
|
+
export { MistralAI } from "./mistralAI.js";
|
|
14
14
|
/**
|
|
15
15
|
* Provider registry for dynamic provider instantiation
|
|
16
16
|
*/
|
|
17
17
|
export const PROVIDERS = {
|
|
18
|
-
vertex:
|
|
19
|
-
bedrock:
|
|
20
|
-
openai:
|
|
21
|
-
anthropic:
|
|
22
|
-
azure:
|
|
23
|
-
|
|
24
|
-
huggingface:
|
|
25
|
-
ollama:
|
|
26
|
-
mistral:
|
|
18
|
+
vertex: "GoogleVertexAI",
|
|
19
|
+
bedrock: "AmazonBedrock",
|
|
20
|
+
openai: "OpenAI",
|
|
21
|
+
anthropic: "AnthropicProvider",
|
|
22
|
+
azure: "AzureOpenAIProvider",
|
|
23
|
+
"google-ai": "GoogleAIStudio",
|
|
24
|
+
huggingface: "HuggingFace",
|
|
25
|
+
ollama: "Ollama",
|
|
26
|
+
mistral: "MistralAI",
|
|
27
27
|
};
|
|
28
28
|
/**
|
|
29
29
|
* List of all available provider names
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NeuroLink MCP-Aware AI Provider
|
|
3
|
+
* Integrates MCP tools with AI providers following Lighthouse's pattern
|
|
4
|
+
*/
|
|
5
|
+
import type { AIProvider, TextGenerationOptions, StreamTextOptions } from "../core/types.js";
|
|
6
|
+
import type { StreamTextResult, ToolSet, Schema, GenerateTextResult } from "ai";
|
|
7
|
+
import type { ZodType, ZodTypeDef } from "zod";
|
|
8
|
+
/**
|
|
9
|
+
* MCP-Aware Provider Configuration
|
|
10
|
+
*/
|
|
11
|
+
export interface MCPProviderConfig {
|
|
12
|
+
baseProvider: AIProvider;
|
|
13
|
+
providerName?: string;
|
|
14
|
+
modelName?: string;
|
|
15
|
+
enableMCP?: boolean;
|
|
16
|
+
sessionId?: string;
|
|
17
|
+
userId?: string;
|
|
18
|
+
organizationId?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* MCP-Aware AI Provider
|
|
22
|
+
* Wraps any AI provider with MCP tool capabilities
|
|
23
|
+
*/
|
|
24
|
+
export declare class MCPAwareProvider implements AIProvider {
|
|
25
|
+
private baseProvider;
|
|
26
|
+
private config;
|
|
27
|
+
private sessionId;
|
|
28
|
+
private mcpInitialized;
|
|
29
|
+
constructor(config: MCPProviderConfig);
|
|
30
|
+
/**
|
|
31
|
+
* Initialize MCP tools for this session
|
|
32
|
+
*/
|
|
33
|
+
private initializeMCP;
|
|
34
|
+
generateText(optionsOrPrompt: TextGenerationOptions | string, analysisSchema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>): Promise<GenerateTextResult<ToolSet, unknown> | null>;
|
|
35
|
+
streamText(optionsOrPrompt: StreamTextOptions | string, analysisSchema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>): Promise<StreamTextResult<ToolSet, unknown> | null>;
|
|
36
|
+
/**
|
|
37
|
+
* Detect if the prompt is requesting tool usage
|
|
38
|
+
*/
|
|
39
|
+
private detectToolRequest;
|
|
40
|
+
/**
|
|
41
|
+
* Get session statistics
|
|
42
|
+
*/
|
|
43
|
+
getSessionStats(): {
|
|
44
|
+
sessionId: string;
|
|
45
|
+
toolCount: number;
|
|
46
|
+
executionCount: number;
|
|
47
|
+
isConnected: boolean;
|
|
48
|
+
uptime: number;
|
|
49
|
+
} | null;
|
|
50
|
+
/**
|
|
51
|
+
* Clean up session
|
|
52
|
+
*/
|
|
53
|
+
cleanup(): Promise<void>;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Create an MCP-aware provider
|
|
57
|
+
*/
|
|
58
|
+
export declare function createMCPAwareProvider(baseProvider: AIProvider, config?: Partial<MCPProviderConfig>): MCPAwareProvider;
|
|
59
|
+
/**
|
|
60
|
+
* Check if a provider is MCP-aware
|
|
61
|
+
*/
|
|
62
|
+
export declare function isMCPAwareProvider(provider: AIProvider): provider is MCPAwareProvider;
|