@juspay/neurolink 5.1.0 → 5.2.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 +15 -9
- package/README.md +123 -126
- package/dist/agent/direct-tools.d.ts +6 -6
- package/dist/cli/commands/config.d.ts +3 -3
- package/dist/cli/commands/mcp.js +8 -7
- package/dist/cli/factories/command-factory.d.ts +4 -0
- package/dist/cli/factories/command-factory.js +57 -3
- package/dist/cli/index.js +87 -140
- package/dist/core/base-provider.d.ts +423 -0
- package/dist/core/base-provider.js +365 -0
- package/dist/core/constants.d.ts +1 -1
- package/dist/core/constants.js +1 -1
- package/dist/core/dynamic-models.d.ts +6 -6
- package/dist/core/evaluation.d.ts +19 -80
- package/dist/core/evaluation.js +185 -484
- package/dist/core/factory.d.ts +3 -3
- package/dist/core/factory.js +31 -91
- package/dist/core/service-registry.d.ts +47 -0
- package/dist/core/service-registry.js +112 -0
- package/dist/core/types.d.ts +8 -1
- package/dist/factories/compatibility-factory.js +1 -1
- package/dist/factories/provider-factory.d.ts +72 -0
- package/dist/factories/provider-factory.js +144 -0
- package/dist/factories/provider-registry.d.ts +38 -0
- package/dist/factories/provider-registry.js +107 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +2 -4
- package/dist/lib/agent/direct-tools.d.ts +6 -6
- package/dist/lib/core/base-provider.d.ts +423 -0
- package/dist/lib/core/base-provider.js +365 -0
- package/dist/lib/core/constants.d.ts +1 -1
- package/dist/lib/core/constants.js +1 -1
- package/dist/lib/core/dynamic-models.d.ts +6 -6
- package/dist/lib/core/evaluation.d.ts +19 -80
- package/dist/lib/core/evaluation.js +185 -484
- package/dist/lib/core/factory.d.ts +3 -3
- package/dist/lib/core/factory.js +30 -91
- package/dist/lib/core/service-registry.d.ts +47 -0
- package/dist/lib/core/service-registry.js +112 -0
- package/dist/lib/core/types.d.ts +8 -1
- package/dist/lib/factories/compatibility-factory.js +1 -1
- package/dist/lib/factories/provider-factory.d.ts +72 -0
- package/dist/lib/factories/provider-factory.js +144 -0
- package/dist/lib/factories/provider-registry.d.ts +38 -0
- package/dist/lib/factories/provider-registry.js +107 -0
- package/dist/lib/index.d.ts +4 -3
- package/dist/lib/index.js +2 -4
- package/dist/lib/mcp/config.js +28 -3
- package/dist/lib/mcp/function-calling.js +1 -1
- package/dist/lib/mcp/initialize-tools.d.ts +1 -1
- package/dist/lib/mcp/initialize-tools.js +45 -1
- package/dist/lib/mcp/initialize.js +16 -6
- package/dist/lib/mcp/servers/agent/direct-tools-server.d.ts +8 -0
- package/dist/lib/mcp/servers/agent/direct-tools-server.js +109 -0
- package/dist/lib/mcp/servers/ai-providers/ai-core-server.js +3 -1
- package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.d.ts +2 -2
- package/dist/lib/mcp/unified-registry.d.ts +4 -0
- package/dist/lib/mcp/unified-registry.js +42 -9
- package/dist/lib/neurolink.d.ts +156 -117
- package/dist/lib/neurolink.js +619 -404
- package/dist/lib/providers/amazon-bedrock.d.ts +32 -0
- package/dist/lib/providers/amazon-bedrock.js +143 -0
- package/dist/lib/providers/analytics-helper.js +7 -4
- package/dist/lib/providers/anthropic-baseprovider.d.ts +23 -0
- package/dist/lib/providers/anthropic-baseprovider.js +114 -0
- package/dist/lib/providers/anthropic.d.ts +19 -43
- package/dist/lib/providers/anthropic.js +82 -306
- package/dist/lib/providers/azure-openai.d.ts +20 -0
- package/dist/lib/providers/azure-openai.js +89 -0
- package/dist/lib/providers/google-ai-studio.d.ts +23 -0
- package/dist/lib/providers/google-ai-studio.js +107 -0
- package/dist/lib/providers/google-vertex.d.ts +47 -0
- package/dist/lib/providers/google-vertex.js +205 -0
- package/dist/lib/providers/huggingFace.d.ts +32 -25
- package/dist/lib/providers/huggingFace.js +97 -431
- package/dist/lib/providers/index.d.ts +9 -9
- package/dist/lib/providers/index.js +9 -9
- package/dist/lib/providers/mcp-provider.js +4 -0
- package/dist/lib/providers/mistral.d.ts +42 -0
- package/dist/lib/providers/mistral.js +160 -0
- package/dist/lib/providers/ollama.d.ts +52 -36
- package/dist/lib/providers/ollama.js +297 -520
- package/dist/lib/providers/openAI.d.ts +19 -18
- package/dist/lib/providers/openAI.js +76 -275
- package/dist/lib/sdk/tool-extension.d.ts +181 -0
- package/dist/lib/sdk/tool-extension.js +283 -0
- package/dist/lib/sdk/tool-registration.d.ts +95 -0
- package/dist/lib/sdk/tool-registration.js +167 -0
- package/dist/lib/types/generate-types.d.ts +1 -0
- package/dist/lib/types/mcp-types.d.ts +116 -0
- package/dist/lib/types/mcp-types.js +5 -0
- package/dist/lib/types/stream-types.d.ts +30 -18
- package/dist/lib/types/universal-provider-options.d.ts +87 -0
- package/dist/lib/types/universal-provider-options.js +53 -0
- package/dist/mcp/config.js +28 -3
- package/dist/mcp/function-calling.js +1 -1
- package/dist/mcp/initialize-tools.d.ts +1 -1
- package/dist/mcp/initialize-tools.js +45 -1
- package/dist/mcp/initialize.js +16 -6
- package/dist/mcp/servers/agent/direct-tools-server.d.ts +8 -0
- package/dist/mcp/servers/agent/direct-tools-server.js +109 -0
- package/dist/mcp/servers/ai-providers/ai-core-server.js +3 -1
- package/dist/mcp/servers/ai-providers/ai-workflow-tools.d.ts +2 -2
- package/dist/mcp/unified-registry.d.ts +4 -0
- package/dist/mcp/unified-registry.js +42 -9
- package/dist/neurolink.d.ts +156 -117
- package/dist/neurolink.js +619 -404
- package/dist/providers/amazon-bedrock.d.ts +32 -0
- package/dist/providers/amazon-bedrock.js +143 -0
- package/dist/providers/analytics-helper.js +7 -4
- package/dist/providers/anthropic-baseprovider.d.ts +23 -0
- package/dist/providers/anthropic-baseprovider.js +114 -0
- package/dist/providers/anthropic.d.ts +19 -43
- package/dist/providers/anthropic.js +81 -305
- package/dist/providers/azure-openai.d.ts +20 -0
- package/dist/providers/azure-openai.js +89 -0
- package/dist/providers/google-ai-studio.d.ts +23 -0
- package/dist/providers/google-ai-studio.js +108 -0
- package/dist/providers/google-vertex.d.ts +47 -0
- package/dist/providers/google-vertex.js +205 -0
- package/dist/providers/huggingFace.d.ts +32 -25
- package/dist/providers/huggingFace.js +96 -430
- package/dist/providers/index.d.ts +9 -9
- package/dist/providers/index.js +9 -9
- package/dist/providers/mcp-provider.js +4 -0
- package/dist/providers/mistral.d.ts +42 -0
- package/dist/providers/mistral.js +160 -0
- package/dist/providers/ollama.d.ts +52 -36
- package/dist/providers/ollama.js +297 -519
- package/dist/providers/openAI.d.ts +19 -18
- package/dist/providers/openAI.js +76 -276
- package/dist/sdk/tool-extension.d.ts +181 -0
- package/dist/sdk/tool-extension.js +283 -0
- package/dist/sdk/tool-registration.d.ts +95 -0
- package/dist/sdk/tool-registration.js +168 -0
- package/dist/types/generate-types.d.ts +1 -0
- package/dist/types/mcp-types.d.ts +116 -0
- package/dist/types/mcp-types.js +5 -0
- package/dist/types/stream-types.d.ts +30 -18
- package/dist/types/universal-provider-options.d.ts +87 -0
- package/dist/types/universal-provider-options.js +53 -0
- package/package.json +15 -10
- package/dist/lib/providers/agent-enhanced-provider.d.ts +0 -93
- package/dist/lib/providers/agent-enhanced-provider.js +0 -605
- package/dist/lib/providers/amazonBedrock.d.ts +0 -28
- package/dist/lib/providers/amazonBedrock.js +0 -364
- package/dist/lib/providers/azureOpenAI.d.ts +0 -42
- package/dist/lib/providers/azureOpenAI.js +0 -347
- package/dist/lib/providers/googleAIStudio.d.ts +0 -42
- package/dist/lib/providers/googleAIStudio.js +0 -364
- package/dist/lib/providers/googleVertexAI.d.ts +0 -34
- package/dist/lib/providers/googleVertexAI.js +0 -547
- package/dist/lib/providers/mistralAI.d.ts +0 -37
- package/dist/lib/providers/mistralAI.js +0 -325
- package/dist/providers/agent-enhanced-provider.d.ts +0 -93
- package/dist/providers/agent-enhanced-provider.js +0 -606
- package/dist/providers/amazonBedrock.d.ts +0 -28
- package/dist/providers/amazonBedrock.js +0 -364
- package/dist/providers/azureOpenAI.d.ts +0 -42
- package/dist/providers/azureOpenAI.js +0 -348
- package/dist/providers/googleAIStudio.d.ts +0 -42
- package/dist/providers/googleAIStudio.js +0 -364
- package/dist/providers/googleVertexAI.d.ts +0 -34
- package/dist/providers/googleVertexAI.js +0 -547
- package/dist/providers/mistralAI.d.ts +0 -37
- package/dist/providers/mistralAI.js +0 -325
|
@@ -1,325 +0,0 @@
|
|
|
1
|
-
import { createMistral } from "@ai-sdk/mistral";
|
|
2
|
-
import { streamText, generateText, Output } from "ai";
|
|
3
|
-
import { logger } from "../utils/logger.js";
|
|
4
|
-
import { createTimeoutController, TimeoutError, getDefaultTimeout, } from "../utils/timeout.js";
|
|
5
|
-
import { DEFAULT_MAX_TOKENS } from "../core/constants.js";
|
|
6
|
-
import { evaluateResponse } from "../core/evaluation.js";
|
|
7
|
-
// Default system context
|
|
8
|
-
const DEFAULT_SYSTEM_CONTEXT = {
|
|
9
|
-
systemPrompt: "You are a helpful AI assistant.",
|
|
10
|
-
};
|
|
11
|
-
// Configuration helpers
|
|
12
|
-
const getMistralApiKey = () => {
|
|
13
|
-
const apiKey = process.env.MISTRAL_API_KEY;
|
|
14
|
-
if (!apiKey) {
|
|
15
|
-
throw new Error("MISTRAL_API_KEY environment variable is not set");
|
|
16
|
-
}
|
|
17
|
-
return apiKey;
|
|
18
|
-
};
|
|
19
|
-
const getMistralModelId = () => {
|
|
20
|
-
return process.env.MISTRAL_MODEL || "mistral-small";
|
|
21
|
-
};
|
|
22
|
-
const hasValidAuth = () => {
|
|
23
|
-
return !!process.env.MISTRAL_API_KEY;
|
|
24
|
-
};
|
|
25
|
-
// Lazy initialization cache
|
|
26
|
-
let _mistralClient = null;
|
|
27
|
-
function getMistralClient() {
|
|
28
|
-
if (!_mistralClient) {
|
|
29
|
-
const apiKey = getMistralApiKey();
|
|
30
|
-
_mistralClient = createMistral({
|
|
31
|
-
apiKey,
|
|
32
|
-
baseURL: process.env.MISTRAL_ENDPOINT || "https://api.mistral.ai/v1",
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
return _mistralClient;
|
|
36
|
-
}
|
|
37
|
-
// Mistral AI class with enhanced error handling
|
|
38
|
-
export class MistralAI {
|
|
39
|
-
modelName;
|
|
40
|
-
client;
|
|
41
|
-
/**
|
|
42
|
-
* Initializes a new instance of MistralAI
|
|
43
|
-
* @param modelName - Optional model name to override the default from config
|
|
44
|
-
*/
|
|
45
|
-
constructor(modelName) {
|
|
46
|
-
const functionTag = "MistralAI.constructor";
|
|
47
|
-
this.modelName = modelName || getMistralModelId();
|
|
48
|
-
try {
|
|
49
|
-
this.client = getMistralClient();
|
|
50
|
-
logger.debug(`[${functionTag}] Initialization started`, {
|
|
51
|
-
modelName: this.modelName,
|
|
52
|
-
hasApiKey: hasValidAuth(),
|
|
53
|
-
});
|
|
54
|
-
logger.debug(`[${functionTag}] Initialization completed`, {
|
|
55
|
-
modelName: this.modelName,
|
|
56
|
-
success: true,
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
catch (err) {
|
|
60
|
-
logger.error(`[${functionTag}] Initialization failed`, {
|
|
61
|
-
message: "Error in initializing Mistral AI",
|
|
62
|
-
modelName: this.modelName,
|
|
63
|
-
error: err instanceof Error ? err.message : String(err),
|
|
64
|
-
stack: err instanceof Error ? err.stack : undefined,
|
|
65
|
-
});
|
|
66
|
-
throw err;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Gets the appropriate model instance
|
|
71
|
-
* @private
|
|
72
|
-
*/
|
|
73
|
-
getModel() {
|
|
74
|
-
logger.debug("MistralAI.getModel - Mistral AI model selected", {
|
|
75
|
-
modelName: this.modelName,
|
|
76
|
-
});
|
|
77
|
-
return this.client(this.modelName);
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* LEGACY METHOD: Use stream() instead for new code
|
|
81
|
-
* @deprecated Use stream() method instead
|
|
82
|
-
*/
|
|
83
|
-
/**
|
|
84
|
-
* PRIMARY METHOD: Stream content using AI (recommended for new code)
|
|
85
|
-
* Future-ready for multi-modal capabilities with current text focus
|
|
86
|
-
*/
|
|
87
|
-
async stream(optionsOrPrompt, analysisSchema) {
|
|
88
|
-
const functionTag = "MistralAI.stream";
|
|
89
|
-
const provider = "mistral";
|
|
90
|
-
let chunkCount = 0;
|
|
91
|
-
const startTime = Date.now();
|
|
92
|
-
try {
|
|
93
|
-
// Parse parameters - support both string and options object
|
|
94
|
-
const options = typeof optionsOrPrompt === "string"
|
|
95
|
-
? { input: { text: optionsOrPrompt } }
|
|
96
|
-
: optionsOrPrompt;
|
|
97
|
-
// Validate input
|
|
98
|
-
if (!options?.input?.text ||
|
|
99
|
-
typeof options.input.text !== "string" ||
|
|
100
|
-
options.input.text.trim() === "") {
|
|
101
|
-
throw new Error("Stream options must include input.text as a non-empty string");
|
|
102
|
-
}
|
|
103
|
-
// Extract parameters
|
|
104
|
-
const { prompt = options.input.text, temperature = 0.7, maxTokens = DEFAULT_MAX_TOKENS, systemPrompt = DEFAULT_SYSTEM_CONTEXT.systemPrompt, schema, timeout = getDefaultTimeout(provider, "stream"), } = options;
|
|
105
|
-
// Use schema from options or fallback parameter
|
|
106
|
-
const finalSchema = schema || analysisSchema;
|
|
107
|
-
logger.debug(`[${functionTag}] Stream request started`, {
|
|
108
|
-
provider,
|
|
109
|
-
modelName: this.modelName,
|
|
110
|
-
promptLength: prompt.length,
|
|
111
|
-
temperature,
|
|
112
|
-
maxTokens,
|
|
113
|
-
hasSchema: !!finalSchema,
|
|
114
|
-
timeout,
|
|
115
|
-
});
|
|
116
|
-
const model = this.getModel();
|
|
117
|
-
// Create timeout controller if timeout is specified
|
|
118
|
-
const timeoutController = createTimeoutController(timeout, provider, "stream");
|
|
119
|
-
const streamOptions = {
|
|
120
|
-
model: model,
|
|
121
|
-
prompt: prompt,
|
|
122
|
-
system: systemPrompt,
|
|
123
|
-
temperature,
|
|
124
|
-
maxTokens,
|
|
125
|
-
// Add abort signal if available
|
|
126
|
-
...(timeoutController && {
|
|
127
|
-
abortSignal: timeoutController.controller.signal,
|
|
128
|
-
}),
|
|
129
|
-
onError: (event) => {
|
|
130
|
-
const error = event.error;
|
|
131
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
132
|
-
const errorStack = error instanceof Error ? error.stack : undefined;
|
|
133
|
-
logger.debug(`[${functionTag}] Stream error`, {
|
|
134
|
-
provider,
|
|
135
|
-
modelName: this.modelName,
|
|
136
|
-
error: errorMessage,
|
|
137
|
-
stack: errorStack,
|
|
138
|
-
promptLength: prompt.length,
|
|
139
|
-
chunkCount,
|
|
140
|
-
});
|
|
141
|
-
},
|
|
142
|
-
onFinish: (event) => {
|
|
143
|
-
logger.debug(`[${functionTag}] Stream finished`, {
|
|
144
|
-
provider,
|
|
145
|
-
modelName: this.modelName,
|
|
146
|
-
finishReason: event.finishReason,
|
|
147
|
-
usage: event.usage,
|
|
148
|
-
totalChunks: chunkCount,
|
|
149
|
-
promptLength: prompt.length,
|
|
150
|
-
responseLength: event.text?.length || 0,
|
|
151
|
-
});
|
|
152
|
-
},
|
|
153
|
-
onChunk: (event) => {
|
|
154
|
-
chunkCount++;
|
|
155
|
-
logger.debug(`[${functionTag}] Stream chunk`, {
|
|
156
|
-
provider,
|
|
157
|
-
modelName: this.modelName,
|
|
158
|
-
chunkNumber: chunkCount,
|
|
159
|
-
chunkLength: event.chunk.text?.length || 0,
|
|
160
|
-
chunkType: event.chunk.type,
|
|
161
|
-
});
|
|
162
|
-
},
|
|
163
|
-
};
|
|
164
|
-
if (finalSchema) {
|
|
165
|
-
streamOptions.experimental_output = Output.object({
|
|
166
|
-
schema: finalSchema,
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
const result = streamText(streamOptions);
|
|
170
|
-
logger.debug(`[${functionTag}] Stream request completed`, {
|
|
171
|
-
provider,
|
|
172
|
-
modelName: this.modelName,
|
|
173
|
-
});
|
|
174
|
-
// Convert to StreamResult format
|
|
175
|
-
return {
|
|
176
|
-
stream: (async function* () {
|
|
177
|
-
for await (const chunk of result.textStream) {
|
|
178
|
-
yield { content: chunk };
|
|
179
|
-
}
|
|
180
|
-
})(),
|
|
181
|
-
provider: "mistral",
|
|
182
|
-
model: this.modelName,
|
|
183
|
-
metadata: {
|
|
184
|
-
streamId: `mistral-${Date.now()}`,
|
|
185
|
-
startTime,
|
|
186
|
-
},
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
catch (err) {
|
|
190
|
-
// Log timeout errors specifically
|
|
191
|
-
if (err instanceof TimeoutError) {
|
|
192
|
-
logger.debug(`[${functionTag}] Timeout error`, {
|
|
193
|
-
provider,
|
|
194
|
-
modelName: this.modelName,
|
|
195
|
-
timeout: err.timeout,
|
|
196
|
-
message: err.message,
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
logger.debug(`[${functionTag}] Exception`, {
|
|
201
|
-
provider,
|
|
202
|
-
modelName: this.modelName,
|
|
203
|
-
message: "Error in streaming content",
|
|
204
|
-
err: String(err),
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
throw err; // Re-throw error to trigger fallback
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Processes text using non-streaming approach with optional schema validation
|
|
212
|
-
* @param prompt - The input text prompt to analyze
|
|
213
|
-
* @param analysisSchema - Optional Zod schema or Schema object for output validation
|
|
214
|
-
* @returns Promise resolving to GenerateResult or null if operation fails
|
|
215
|
-
*/
|
|
216
|
-
async generate(optionsOrPrompt, analysisSchema) {
|
|
217
|
-
const functionTag = "MistralAI.generate";
|
|
218
|
-
const provider = "mistral";
|
|
219
|
-
const startTime = Date.now();
|
|
220
|
-
try {
|
|
221
|
-
// Parse parameters - support both string and options object
|
|
222
|
-
const options = typeof optionsOrPrompt === "string"
|
|
223
|
-
? { prompt: optionsOrPrompt }
|
|
224
|
-
: optionsOrPrompt;
|
|
225
|
-
const { prompt, temperature = 0.7, maxTokens = DEFAULT_MAX_TOKENS, systemPrompt = DEFAULT_SYSTEM_CONTEXT.systemPrompt, schema, timeout = getDefaultTimeout(provider, "generate"), } = options;
|
|
226
|
-
// Use schema from options or fallback parameter
|
|
227
|
-
const finalSchema = schema || analysisSchema;
|
|
228
|
-
logger.debug(`[${functionTag}] Generate request started`, {
|
|
229
|
-
provider,
|
|
230
|
-
modelName: this.modelName,
|
|
231
|
-
promptLength: prompt.length,
|
|
232
|
-
temperature,
|
|
233
|
-
maxTokens,
|
|
234
|
-
timeout,
|
|
235
|
-
});
|
|
236
|
-
const model = this.getModel();
|
|
237
|
-
// Create timeout controller if timeout is specified
|
|
238
|
-
const timeoutController = createTimeoutController(timeout, provider, "generate");
|
|
239
|
-
const generateOptions = {
|
|
240
|
-
model: model,
|
|
241
|
-
prompt: prompt,
|
|
242
|
-
system: systemPrompt,
|
|
243
|
-
temperature,
|
|
244
|
-
maxTokens,
|
|
245
|
-
// Add abort signal if available
|
|
246
|
-
...(timeoutController && {
|
|
247
|
-
abortSignal: timeoutController.controller.signal,
|
|
248
|
-
}),
|
|
249
|
-
};
|
|
250
|
-
if (finalSchema) {
|
|
251
|
-
generateOptions.experimental_output = Output.object({
|
|
252
|
-
schema: finalSchema,
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
try {
|
|
256
|
-
const result = await generateText(generateOptions);
|
|
257
|
-
// Clean up timeout if successful
|
|
258
|
-
timeoutController?.cleanup();
|
|
259
|
-
logger.debug(`[${functionTag}] Generate text completed`, {
|
|
260
|
-
provider,
|
|
261
|
-
modelName: this.modelName,
|
|
262
|
-
usage: result.usage,
|
|
263
|
-
finishReason: result.finishReason,
|
|
264
|
-
responseLength: result.text?.length || 0,
|
|
265
|
-
timeout,
|
|
266
|
-
});
|
|
267
|
-
// Add analytics if enabled
|
|
268
|
-
if (options.enableAnalytics) {
|
|
269
|
-
result.analytics = {
|
|
270
|
-
provider,
|
|
271
|
-
model: this.modelName,
|
|
272
|
-
tokens: result.usage,
|
|
273
|
-
responseTime: Date.now() - startTime,
|
|
274
|
-
context: options.context,
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
// Add evaluation if enabled
|
|
278
|
-
if (options.enableEvaluation) {
|
|
279
|
-
result.evaluation = await evaluateResponse(prompt, result.text, options.context);
|
|
280
|
-
}
|
|
281
|
-
return {
|
|
282
|
-
content: result.text,
|
|
283
|
-
provider: "mistral",
|
|
284
|
-
model: this.modelName,
|
|
285
|
-
usage: result.usage
|
|
286
|
-
? {
|
|
287
|
-
inputTokens: result.usage.promptTokens,
|
|
288
|
-
outputTokens: result.usage.completionTokens,
|
|
289
|
-
totalTokens: result.usage.totalTokens,
|
|
290
|
-
}
|
|
291
|
-
: undefined,
|
|
292
|
-
responseTime: Date.now() - startTime,
|
|
293
|
-
};
|
|
294
|
-
}
|
|
295
|
-
finally {
|
|
296
|
-
// Always cleanup timeout
|
|
297
|
-
timeoutController?.cleanup();
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
catch (err) {
|
|
301
|
-
// Log timeout errors specifically
|
|
302
|
-
if (err instanceof TimeoutError) {
|
|
303
|
-
logger.error(`[${functionTag}] Timeout error`, {
|
|
304
|
-
provider,
|
|
305
|
-
modelName: this.modelName,
|
|
306
|
-
timeout: err.timeout,
|
|
307
|
-
message: err.message,
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
else {
|
|
311
|
-
logger.error(`[${functionTag}] Exception`, {
|
|
312
|
-
provider,
|
|
313
|
-
modelName: this.modelName,
|
|
314
|
-
message: "Error in generating text",
|
|
315
|
-
err: String(err),
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
throw err; // Re-throw error to trigger fallback
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
async gen(optionsOrPrompt, analysisSchema) {
|
|
322
|
-
return this.generate(optionsOrPrompt, analysisSchema);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
export default MistralAI;
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Agent-Enhanced Provider for NeuroLink CLI
|
|
3
|
-
* Integrates direct tools with AI providers for true agent functionality
|
|
4
|
-
*/
|
|
5
|
-
import type { GenerateResult } from "../types/generate-types.js";
|
|
6
|
-
import type { AIProvider, TextGenerationOptions, EnhancedGenerateResult } from "../core/types.js";
|
|
7
|
-
import type { StreamOptions, StreamResult } from "../types/stream-types.js";
|
|
8
|
-
/**
|
|
9
|
-
* Agent configuration options
|
|
10
|
-
*/
|
|
11
|
-
interface AgentConfig {
|
|
12
|
-
provider: "openai" | "google-ai" | "anthropic";
|
|
13
|
-
model?: string;
|
|
14
|
-
toolCategory?: "basic" | "filesystem" | "utility" | "all";
|
|
15
|
-
maxSteps?: number;
|
|
16
|
-
enableTools?: boolean;
|
|
17
|
-
enableMCP?: boolean;
|
|
18
|
-
mcpInitTimeoutMs?: number;
|
|
19
|
-
toolExecutionTimeout?: number | string;
|
|
20
|
-
mcpDiscoveryOptions?: {
|
|
21
|
-
searchPaths?: string[];
|
|
22
|
-
configFiles?: string[];
|
|
23
|
-
autoDiscover?: boolean;
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Agent-Enhanced Provider Class
|
|
28
|
-
* Provides AI generation with tool calling capabilities
|
|
29
|
-
* Now includes MCP tool integration alongside direct tools
|
|
30
|
-
*/
|
|
31
|
-
export declare class AgentEnhancedProvider implements AIProvider {
|
|
32
|
-
private config;
|
|
33
|
-
private model;
|
|
34
|
-
private resolvedModelName;
|
|
35
|
-
private mcpSystem;
|
|
36
|
-
private mcpInitialized;
|
|
37
|
-
private mcpInitializing;
|
|
38
|
-
private mcpInitFailed;
|
|
39
|
-
constructor(config: AgentConfig);
|
|
40
|
-
private createModel;
|
|
41
|
-
/**
|
|
42
|
-
* Initialize MCP registry with auto-discovery
|
|
43
|
-
*/
|
|
44
|
-
private initializeMCP;
|
|
45
|
-
/**
|
|
46
|
-
* Get combined tools: direct tools + MCP tools
|
|
47
|
-
*/
|
|
48
|
-
private getCombinedTools;
|
|
49
|
-
/**
|
|
50
|
-
* PRIMARY METHOD: Stream content using AI (recommended for new code)
|
|
51
|
-
* Future-ready for multi-modal capabilities with current text focus
|
|
52
|
-
*/
|
|
53
|
-
stream(optionsOrPrompt: StreamOptions | string, analysisSchema?: any): Promise<StreamResult>;
|
|
54
|
-
generate(optionsOrPrompt: TextGenerationOptions | string): Promise<GenerateResult>;
|
|
55
|
-
/**
|
|
56
|
-
* Determine if we should force tool usage based on prompt patterns
|
|
57
|
-
*/
|
|
58
|
-
private shouldForceToolUsage;
|
|
59
|
-
getCapabilities(): string[];
|
|
60
|
-
getProviderName(): string;
|
|
61
|
-
getModelName(): string;
|
|
62
|
-
/**
|
|
63
|
-
* Test agent functionality
|
|
64
|
-
*/
|
|
65
|
-
testAgentCapabilities(): Promise<{
|
|
66
|
-
success: boolean;
|
|
67
|
-
results: any[];
|
|
68
|
-
}>;
|
|
69
|
-
/**
|
|
70
|
-
* Create agent-enhanced provider factory
|
|
71
|
-
*/
|
|
72
|
-
static createAgent(config: AgentConfig): AgentEnhancedProvider;
|
|
73
|
-
/**
|
|
74
|
-
* Create multiple agent providers for comparison
|
|
75
|
-
*/
|
|
76
|
-
static createMultiProviderAgents(): Record<string, AgentEnhancedProvider>;
|
|
77
|
-
/**
|
|
78
|
-
* Alias for generate() - CLI-SDK consistency
|
|
79
|
-
*/
|
|
80
|
-
/**
|
|
81
|
-
* Short alias for generate() - CLI-SDK consistency
|
|
82
|
-
*/
|
|
83
|
-
gen(optionsOrPrompt: TextGenerationOptions | string, analysisSchema?: any): Promise<EnhancedGenerateResult | null>;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Helper function to create agent provider
|
|
87
|
-
*/
|
|
88
|
-
export declare function createAgentProvider(provider: "openai" | "google-ai" | "anthropic", options?: Partial<AgentConfig>): AgentEnhancedProvider;
|
|
89
|
-
/**
|
|
90
|
-
* Test all available agent providers
|
|
91
|
-
*/
|
|
92
|
-
export declare function testAllAgentProviders(): Promise<void>;
|
|
93
|
-
export {};
|