@juspay/neurolink 7.32.0 → 7.33.1
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 +8 -0
- package/dist/agent/directTools.d.ts +6 -6
- package/dist/cli/commands/config.d.ts +68 -68
- package/dist/cli/utils/interactiveSetup.d.ts +1 -1
- package/dist/cli/utils/interactiveSetup.js +1 -1
- package/dist/core/analytics.d.ts +1 -2
- package/dist/core/baseProvider.d.ts +7 -1
- package/dist/core/baseProvider.js +59 -42
- package/dist/core/dynamicModels.d.ts +1 -132
- package/dist/core/dynamicModels.js +0 -7
- package/dist/core/evaluation.d.ts +1 -39
- package/dist/core/evaluationProviders.d.ts +1 -17
- package/dist/core/evaluationProviders.js +1 -1
- package/dist/core/factory.d.ts +1 -3
- package/dist/core/factory.js +0 -1
- package/dist/core/modelConfiguration.d.ts +8 -69
- package/dist/core/modelConfiguration.js +11 -11
- package/dist/core/serviceRegistry.d.ts +1 -8
- package/dist/core/streamAnalytics.d.ts +2 -45
- package/dist/factories/providerFactory.d.ts +1 -1
- package/dist/factories/providerRegistry.js +1 -1
- package/dist/index.d.ts +8 -9
- package/dist/index.js +1 -1
- package/dist/lib/core/analytics.d.ts +1 -2
- package/dist/lib/core/baseProvider.d.ts +7 -1
- package/dist/lib/core/baseProvider.js +59 -42
- package/dist/lib/core/dynamicModels.d.ts +1 -132
- package/dist/lib/core/dynamicModels.js +0 -7
- package/dist/lib/core/evaluation.d.ts +1 -39
- package/dist/lib/core/evaluationProviders.d.ts +1 -17
- package/dist/lib/core/evaluationProviders.js +1 -1
- package/dist/lib/core/factory.d.ts +1 -3
- package/dist/lib/core/factory.js +0 -1
- package/dist/lib/core/modelConfiguration.d.ts +8 -69
- package/dist/lib/core/modelConfiguration.js +11 -11
- package/dist/lib/core/serviceRegistry.d.ts +1 -8
- package/dist/lib/core/streamAnalytics.d.ts +2 -45
- package/dist/lib/factories/providerFactory.d.ts +1 -1
- package/dist/lib/factories/providerRegistry.js +1 -1
- package/dist/lib/index.d.ts +5 -6
- package/dist/lib/index.js +1 -1
- package/dist/lib/models/modelRegistry.d.ts +1 -1
- package/dist/lib/models/modelRegistry.js +1 -1
- package/dist/lib/models/modelResolver.d.ts +1 -1
- package/dist/lib/neurolink.d.ts +1 -1
- package/dist/lib/neurolink.js +1 -1
- package/dist/lib/providers/amazonBedrock.d.ts +1 -2
- package/dist/lib/providers/amazonSagemaker.d.ts +1 -1
- package/dist/lib/providers/anthropic.d.ts +1 -1
- package/dist/lib/providers/anthropic.js +1 -1
- package/dist/lib/providers/anthropicBaseProvider.d.ts +1 -1
- package/dist/lib/providers/anthropicBaseProvider.js +1 -1
- package/dist/lib/providers/azureOpenai.d.ts +1 -1
- package/dist/lib/providers/googleAiStudio.d.ts +1 -1
- package/dist/lib/providers/googleAiStudio.js +1 -1
- package/dist/lib/providers/googleVertex.d.ts +1 -1
- package/dist/lib/providers/googleVertex.js +1 -1
- package/dist/lib/providers/huggingFace.d.ts +1 -1
- package/dist/lib/providers/index.d.ts +1 -1
- package/dist/lib/providers/litellm.d.ts +1 -1
- package/dist/lib/providers/mistral.d.ts +1 -1
- package/dist/lib/providers/ollama.d.ts +1 -1
- package/dist/lib/providers/ollama.js +1 -1
- package/dist/lib/providers/openAI.d.ts +1 -1
- package/dist/lib/providers/openAI.js +1 -1
- package/dist/lib/providers/openaiCompatible.d.ts +1 -1
- package/dist/lib/providers/sagemaker/language-model.d.ts +2 -2
- package/dist/lib/types/analytics.d.ts +53 -0
- package/dist/lib/types/analytics.js +5 -0
- package/dist/lib/types/cli.d.ts +1 -1
- package/dist/lib/types/evaluation.d.ts +119 -0
- package/dist/lib/types/evaluation.js +5 -0
- package/dist/lib/types/evaluationProviders.d.ts +104 -0
- package/dist/lib/types/evaluationProviders.js +5 -0
- package/dist/lib/types/generateTypes.d.ts +89 -18
- package/dist/lib/types/index.d.ts +10 -2
- package/dist/lib/types/index.js +12 -0
- package/dist/lib/types/modelTypes.d.ts +242 -0
- package/dist/lib/types/modelTypes.js +30 -0
- package/dist/lib/types/providers.d.ts +193 -127
- package/dist/lib/types/providers.js +110 -18
- package/dist/lib/types/serviceTypes.d.ts +79 -0
- package/dist/lib/types/serviceTypes.js +5 -0
- package/dist/lib/types/streamTypes.d.ts +101 -21
- package/dist/lib/utils/analyticsUtils.d.ts +5 -1
- package/dist/lib/utils/analyticsUtils.js +13 -0
- package/dist/lib/utils/conversationMemoryUtils.d.ts +1 -1
- package/dist/lib/utils/evaluationUtils.d.ts +1 -1
- package/dist/lib/utils/factoryProcessing.d.ts +1 -1
- package/dist/lib/utils/messageBuilder.d.ts +1 -1
- package/dist/lib/utils/providerHealth.d.ts +1 -1
- package/dist/lib/utils/providerHealth.js +1 -1
- package/dist/lib/utils/providerUtils.d.ts +5 -0
- package/dist/lib/utils/providerUtils.js +6 -0
- package/dist/models/modelRegistry.d.ts +1 -1
- package/dist/models/modelRegistry.js +1 -1
- package/dist/models/modelResolver.d.ts +1 -1
- package/dist/neurolink.d.ts +1 -1
- package/dist/neurolink.js +1 -1
- package/dist/providers/amazonBedrock.d.ts +1 -2
- package/dist/providers/amazonSagemaker.d.ts +1 -1
- package/dist/providers/anthropic.d.ts +1 -1
- package/dist/providers/anthropic.js +1 -1
- package/dist/providers/anthropicBaseProvider.d.ts +1 -1
- package/dist/providers/anthropicBaseProvider.js +1 -1
- package/dist/providers/azureOpenai.d.ts +1 -1
- package/dist/providers/googleAiStudio.d.ts +1 -1
- package/dist/providers/googleAiStudio.js +1 -1
- package/dist/providers/googleVertex.d.ts +1 -1
- package/dist/providers/googleVertex.js +1 -1
- package/dist/providers/huggingFace.d.ts +1 -1
- package/dist/providers/index.d.ts +1 -1
- package/dist/providers/litellm.d.ts +1 -1
- package/dist/providers/mistral.d.ts +1 -1
- package/dist/providers/ollama.d.ts +1 -1
- package/dist/providers/ollama.js +1 -1
- package/dist/providers/openAI.d.ts +1 -1
- package/dist/providers/openAI.js +1 -1
- package/dist/providers/openaiCompatible.d.ts +1 -1
- package/dist/types/analytics.d.ts +53 -0
- package/dist/types/analytics.js +5 -0
- package/dist/types/cli.d.ts +1 -1
- package/dist/types/evaluation.d.ts +119 -0
- package/dist/types/evaluation.js +5 -0
- package/dist/types/evaluationProviders.d.ts +104 -0
- package/dist/types/evaluationProviders.js +5 -0
- package/dist/types/generateTypes.d.ts +89 -18
- package/dist/types/index.d.ts +10 -2
- package/dist/types/index.js +12 -0
- package/dist/types/modelTypes.d.ts +242 -0
- package/dist/types/modelTypes.js +30 -0
- package/dist/types/providers.d.ts +193 -127
- package/dist/types/providers.js +110 -18
- package/dist/types/serviceTypes.d.ts +79 -0
- package/dist/types/serviceTypes.js +5 -0
- package/dist/types/streamTypes.d.ts +101 -21
- package/dist/utils/analyticsUtils.d.ts +5 -1
- package/dist/utils/analyticsUtils.js +13 -0
- package/dist/utils/conversationMemoryUtils.d.ts +1 -1
- package/dist/utils/evaluationUtils.d.ts +1 -1
- package/dist/utils/factoryProcessing.d.ts +1 -1
- package/dist/utils/messageBuilder.d.ts +1 -1
- package/dist/utils/providerHealth.d.ts +1 -1
- package/dist/utils/providerHealth.js +1 -1
- package/dist/utils/providerUtils.d.ts +5 -0
- package/dist/utils/providerUtils.js +6 -0
- package/package.json +1 -1
- package/dist/core/types.d.ts +0 -223
- package/dist/core/types.js +0 -111
- package/dist/lib/core/types.d.ts +0 -223
- package/dist/lib/core/types.js +0 -111
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ValidationSchema } from "../types/typeAliases.js";
|
|
2
2
|
import type { Tool, LanguageModelV1 } from "ai";
|
|
3
|
-
import type { AIProvider, TextGenerationOptions, TextGenerationResult, EnhancedGenerateResult, AnalyticsData, AIProviderName } from "../
|
|
3
|
+
import type { AIProvider, TextGenerationOptions, TextGenerationResult, EnhancedGenerateResult, AnalyticsData, AIProviderName } from "../types/index.js";
|
|
4
4
|
import type { EvaluationData } from "../index.js";
|
|
5
5
|
import type { MiddlewareFactoryOptions } from "../types/middlewareTypes.js";
|
|
6
6
|
import type { StreamOptions, StreamResult } from "../types/streamTypes.js";
|
|
@@ -37,6 +37,8 @@ export declare abstract class BaseProvider implements AIProvider {
|
|
|
37
37
|
/**
|
|
38
38
|
* Text generation method - implements AIProvider interface
|
|
39
39
|
* Tools are always available unless explicitly disabled
|
|
40
|
+
* IMPLEMENTATION NOTE: Uses streamText() under the hood and accumulates results
|
|
41
|
+
* for consistency and better performance
|
|
40
42
|
*/
|
|
41
43
|
generate(optionsOrPrompt: TextGenerationOptions | string, _analysisSchema?: ValidationSchema): Promise<EnhancedGenerateResult | null>;
|
|
42
44
|
/**
|
|
@@ -110,6 +112,10 @@ export declare abstract class BaseProvider implements AIProvider {
|
|
|
110
112
|
* MCP tools are added when available (without blocking)
|
|
111
113
|
*/
|
|
112
114
|
protected getAllTools(): Promise<Record<string, Tool>>;
|
|
115
|
+
/**
|
|
116
|
+
* Calculate actual cost based on token usage and provider configuration
|
|
117
|
+
*/
|
|
118
|
+
private calculateActualCost;
|
|
113
119
|
/**
|
|
114
120
|
* Convert MCP JSON Schema to Zod schema for AI SDK tools
|
|
115
121
|
* Handles common MCP schema patterns safely
|
|
@@ -10,6 +10,7 @@ import { getKeysAsString, getKeyCount } from "../utils/transformationUtils.js";
|
|
|
10
10
|
import { validateStreamOptions as validateStreamOpts, validateTextGenerationOptions, ValidationError, createValidationSummary, } from "../utils/parameterValidation.js";
|
|
11
11
|
import { recordProviderPerformanceFromMetrics, getPerformanceOptimizedProvider, } from "./evaluationProviders.js";
|
|
12
12
|
import { modelConfig } from "./modelConfiguration.js";
|
|
13
|
+
// Provider types moved to ../types/providers.js
|
|
13
14
|
/**
|
|
14
15
|
* Abstract base class for all AI providers
|
|
15
16
|
* Tools are integrated as first-class citizens - always available by default
|
|
@@ -146,6 +147,8 @@ export class BaseProvider {
|
|
|
146
147
|
/**
|
|
147
148
|
* Text generation method - implements AIProvider interface
|
|
148
149
|
* Tools are always available unless explicitly disabled
|
|
150
|
+
* IMPLEMENTATION NOTE: Uses streamText() under the hood and accumulates results
|
|
151
|
+
* for consistency and better performance
|
|
149
152
|
*/
|
|
150
153
|
async generate(optionsOrPrompt, _analysisSchema) {
|
|
151
154
|
const options = this.normalizeTextOptions(optionsOrPrompt);
|
|
@@ -153,8 +156,9 @@ export class BaseProvider {
|
|
|
153
156
|
this.validateOptions(options);
|
|
154
157
|
const startTime = Date.now();
|
|
155
158
|
try {
|
|
156
|
-
// Import
|
|
157
|
-
|
|
159
|
+
// Import streamText dynamically to avoid circular dependencies
|
|
160
|
+
// Using streamText instead of generateText for unified implementation
|
|
161
|
+
const { streamText } = await import("ai");
|
|
158
162
|
// Get ALL available tools (direct + MCP + external from options)
|
|
159
163
|
const shouldUseTools = !options.disableTools && this.supportsTools();
|
|
160
164
|
const baseTools = shouldUseTools ? await this.getAllTools() : {};
|
|
@@ -175,7 +179,8 @@ export class BaseProvider {
|
|
|
175
179
|
const model = await this.getAISDKModelWithMiddleware(options);
|
|
176
180
|
// Build proper message array with conversation history
|
|
177
181
|
const messages = buildMessagesArray(options);
|
|
178
|
-
|
|
182
|
+
// Use streamText and accumulate results instead of generateText
|
|
183
|
+
const streamResult = await streamText({
|
|
179
184
|
model,
|
|
180
185
|
messages: messages,
|
|
181
186
|
tools,
|
|
@@ -184,31 +189,30 @@ export class BaseProvider {
|
|
|
184
189
|
temperature: options.temperature,
|
|
185
190
|
maxTokens: options.maxTokens || 8192,
|
|
186
191
|
});
|
|
192
|
+
// Accumulate the streamed content
|
|
193
|
+
let accumulatedContent = "";
|
|
194
|
+
// Wait for the stream to complete and accumulate content
|
|
195
|
+
for await (const chunk of streamResult.textStream) {
|
|
196
|
+
accumulatedContent += chunk;
|
|
197
|
+
}
|
|
198
|
+
// Get the final result - this should include usage, toolCalls, etc.
|
|
199
|
+
const usage = await streamResult.usage;
|
|
200
|
+
const toolCalls = await streamResult.toolCalls;
|
|
201
|
+
const toolResults = await streamResult.toolResults;
|
|
187
202
|
const responseTime = Date.now() - startTime;
|
|
203
|
+
// Create a result object compatible with generateText format
|
|
204
|
+
const result = {
|
|
205
|
+
text: accumulatedContent,
|
|
206
|
+
usage: usage,
|
|
207
|
+
toolCalls: toolCalls,
|
|
208
|
+
toolResults: toolResults,
|
|
209
|
+
steps: streamResult.steps, // Include steps for tool execution tracking
|
|
210
|
+
};
|
|
188
211
|
try {
|
|
189
|
-
|
|
190
|
-
const calculateActualCost = () => {
|
|
191
|
-
try {
|
|
192
|
-
const costInfo = modelConfig.getCostInfo(this.providerName, this.modelName);
|
|
193
|
-
if (!costInfo) {
|
|
194
|
-
return 0; // No cost info available
|
|
195
|
-
}
|
|
196
|
-
const promptTokens = result.usage?.promptTokens || 0;
|
|
197
|
-
const completionTokens = result.usage?.completionTokens || 0;
|
|
198
|
-
// Calculate cost per 1K tokens
|
|
199
|
-
const inputCost = (promptTokens / 1000) * costInfo.input;
|
|
200
|
-
const outputCost = (completionTokens / 1000) * costInfo.output;
|
|
201
|
-
return inputCost + outputCost;
|
|
202
|
-
}
|
|
203
|
-
catch (error) {
|
|
204
|
-
logger.debug(`Cost calculation failed for ${this.providerName}:`, error);
|
|
205
|
-
return 0; // Fallback to 0 on any error
|
|
206
|
-
}
|
|
207
|
-
};
|
|
208
|
-
const actualCost = calculateActualCost();
|
|
212
|
+
const actualCost = await this.calculateActualCost(usage || { promptTokens: 0, completionTokens: 0, totalTokens: 0 });
|
|
209
213
|
recordProviderPerformanceFromMetrics(this.providerName, {
|
|
210
214
|
responseTime,
|
|
211
|
-
tokensGenerated:
|
|
215
|
+
tokensGenerated: usage?.totalTokens || 0,
|
|
212
216
|
cost: actualCost,
|
|
213
217
|
success: true,
|
|
214
218
|
});
|
|
@@ -216,7 +220,7 @@ export class BaseProvider {
|
|
|
216
220
|
const optimizedProvider = getPerformanceOptimizedProvider("speed");
|
|
217
221
|
logger.debug(`🚀 Performance recorded for ${this.providerName}:`, {
|
|
218
222
|
responseTime: `${responseTime}ms`,
|
|
219
|
-
tokens:
|
|
223
|
+
tokens: usage?.totalTokens || 0,
|
|
220
224
|
estimatedCost: `$${actualCost.toFixed(6)}`,
|
|
221
225
|
recommendedSpeedProvider: optimizedProvider?.provider || "none",
|
|
222
226
|
});
|
|
@@ -228,11 +232,9 @@ export class BaseProvider {
|
|
|
228
232
|
// AI SDK puts tool calls in steps array for multi-step generation
|
|
229
233
|
const toolsUsed = [];
|
|
230
234
|
// First check direct tool calls (fallback)
|
|
231
|
-
if (
|
|
232
|
-
toolsUsed.push(...
|
|
233
|
-
return
|
|
234
|
-
tc.name ||
|
|
235
|
-
"unknown");
|
|
235
|
+
if (toolCalls && toolCalls.length > 0) {
|
|
236
|
+
toolsUsed.push(...toolCalls.map((tc) => {
|
|
237
|
+
return tc.toolName || "unknown";
|
|
236
238
|
}));
|
|
237
239
|
}
|
|
238
240
|
// Then check steps for tool calls (primary source for multi-step)
|
|
@@ -326,20 +328,14 @@ export class BaseProvider {
|
|
|
326
328
|
},
|
|
327
329
|
provider: this.providerName,
|
|
328
330
|
model: this.modelName,
|
|
329
|
-
toolCalls:
|
|
330
|
-
?
|
|
331
|
-
toolCallId: tc.toolCallId ||
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
toolName: tc.toolName ||
|
|
335
|
-
tc.name ||
|
|
336
|
-
"unknown",
|
|
337
|
-
args: tc.args ||
|
|
338
|
-
tc.parameters ||
|
|
339
|
-
{},
|
|
331
|
+
toolCalls: toolCalls
|
|
332
|
+
? toolCalls.map((tc) => ({
|
|
333
|
+
toolCallId: tc.toolCallId || "unknown",
|
|
334
|
+
toolName: tc.toolName || "unknown",
|
|
335
|
+
args: tc.args || {},
|
|
340
336
|
}))
|
|
341
337
|
: [],
|
|
342
|
-
toolResults:
|
|
338
|
+
toolResults: toolResults || [],
|
|
343
339
|
toolsUsed: uniqueToolsUsed,
|
|
344
340
|
toolExecutions, // ✅ Add extracted tool executions
|
|
345
341
|
availableTools: Object.keys(tools).map((name) => {
|
|
@@ -655,6 +651,27 @@ export class BaseProvider {
|
|
|
655
651
|
logger.debug(`[BaseProvider] getAllTools returning tools: ${getKeysAsString(tools)}`);
|
|
656
652
|
return tools;
|
|
657
653
|
}
|
|
654
|
+
/**
|
|
655
|
+
* Calculate actual cost based on token usage and provider configuration
|
|
656
|
+
*/
|
|
657
|
+
async calculateActualCost(usage) {
|
|
658
|
+
try {
|
|
659
|
+
const costInfo = modelConfig.getCostInfo(this.providerName, this.modelName);
|
|
660
|
+
if (!costInfo) {
|
|
661
|
+
return 0; // No cost info available
|
|
662
|
+
}
|
|
663
|
+
const promptTokens = usage?.promptTokens || 0;
|
|
664
|
+
const completionTokens = usage?.completionTokens || 0;
|
|
665
|
+
// Calculate cost per 1K tokens
|
|
666
|
+
const inputCost = (promptTokens / 1000) * costInfo.input;
|
|
667
|
+
const outputCost = (completionTokens / 1000) * costInfo.output;
|
|
668
|
+
return inputCost + outputCost;
|
|
669
|
+
}
|
|
670
|
+
catch (error) {
|
|
671
|
+
logger.debug(`Cost calculation failed for ${this.providerName}:`, error);
|
|
672
|
+
return 0; // Fallback to 0 on any error
|
|
673
|
+
}
|
|
674
|
+
}
|
|
658
675
|
/**
|
|
659
676
|
* Convert MCP JSON Schema to Zod schema for AI SDK tools
|
|
660
677
|
* Handles common MCP schema patterns safely
|
|
@@ -1,129 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
/**
|
|
3
|
-
* Model configuration schema for validation
|
|
4
|
-
*/
|
|
5
|
-
declare const ModelConfigSchema: z.ZodObject<{
|
|
6
|
-
id: z.ZodString;
|
|
7
|
-
displayName: z.ZodString;
|
|
8
|
-
capabilities: z.ZodArray<z.ZodString, "many">;
|
|
9
|
-
deprecated: z.ZodBoolean;
|
|
10
|
-
pricing: z.ZodObject<{
|
|
11
|
-
input: z.ZodNumber;
|
|
12
|
-
output: z.ZodNumber;
|
|
13
|
-
}, "strip", z.ZodTypeAny, {
|
|
14
|
-
input: number;
|
|
15
|
-
output: number;
|
|
16
|
-
}, {
|
|
17
|
-
input: number;
|
|
18
|
-
output: number;
|
|
19
|
-
}>;
|
|
20
|
-
contextWindow: z.ZodNumber;
|
|
21
|
-
releaseDate: z.ZodString;
|
|
22
|
-
}, "strip", z.ZodTypeAny, {
|
|
23
|
-
id: string;
|
|
24
|
-
capabilities: string[];
|
|
25
|
-
displayName: string;
|
|
26
|
-
deprecated: boolean;
|
|
27
|
-
pricing: {
|
|
28
|
-
input: number;
|
|
29
|
-
output: number;
|
|
30
|
-
};
|
|
31
|
-
contextWindow: number;
|
|
32
|
-
releaseDate: string;
|
|
33
|
-
}, {
|
|
34
|
-
id: string;
|
|
35
|
-
capabilities: string[];
|
|
36
|
-
displayName: string;
|
|
37
|
-
deprecated: boolean;
|
|
38
|
-
pricing: {
|
|
39
|
-
input: number;
|
|
40
|
-
output: number;
|
|
41
|
-
};
|
|
42
|
-
contextWindow: number;
|
|
43
|
-
releaseDate: string;
|
|
44
|
-
}>;
|
|
45
|
-
declare const ModelRegistrySchema: z.ZodObject<{
|
|
46
|
-
version: z.ZodString;
|
|
47
|
-
lastUpdated: z.ZodString;
|
|
48
|
-
models: z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
49
|
-
id: z.ZodString;
|
|
50
|
-
displayName: z.ZodString;
|
|
51
|
-
capabilities: z.ZodArray<z.ZodString, "many">;
|
|
52
|
-
deprecated: z.ZodBoolean;
|
|
53
|
-
pricing: z.ZodObject<{
|
|
54
|
-
input: z.ZodNumber;
|
|
55
|
-
output: z.ZodNumber;
|
|
56
|
-
}, "strip", z.ZodTypeAny, {
|
|
57
|
-
input: number;
|
|
58
|
-
output: number;
|
|
59
|
-
}, {
|
|
60
|
-
input: number;
|
|
61
|
-
output: number;
|
|
62
|
-
}>;
|
|
63
|
-
contextWindow: z.ZodNumber;
|
|
64
|
-
releaseDate: z.ZodString;
|
|
65
|
-
}, "strip", z.ZodTypeAny, {
|
|
66
|
-
id: string;
|
|
67
|
-
capabilities: string[];
|
|
68
|
-
displayName: string;
|
|
69
|
-
deprecated: boolean;
|
|
70
|
-
pricing: {
|
|
71
|
-
input: number;
|
|
72
|
-
output: number;
|
|
73
|
-
};
|
|
74
|
-
contextWindow: number;
|
|
75
|
-
releaseDate: string;
|
|
76
|
-
}, {
|
|
77
|
-
id: string;
|
|
78
|
-
capabilities: string[];
|
|
79
|
-
displayName: string;
|
|
80
|
-
deprecated: boolean;
|
|
81
|
-
pricing: {
|
|
82
|
-
input: number;
|
|
83
|
-
output: number;
|
|
84
|
-
};
|
|
85
|
-
contextWindow: number;
|
|
86
|
-
releaseDate: string;
|
|
87
|
-
}>>>;
|
|
88
|
-
aliases: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
89
|
-
defaults: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
90
|
-
}, "strip", z.ZodTypeAny, {
|
|
91
|
-
models: Record<string, Record<string, {
|
|
92
|
-
id: string;
|
|
93
|
-
capabilities: string[];
|
|
94
|
-
displayName: string;
|
|
95
|
-
deprecated: boolean;
|
|
96
|
-
pricing: {
|
|
97
|
-
input: number;
|
|
98
|
-
output: number;
|
|
99
|
-
};
|
|
100
|
-
contextWindow: number;
|
|
101
|
-
releaseDate: string;
|
|
102
|
-
}>>;
|
|
103
|
-
version: string;
|
|
104
|
-
lastUpdated: string;
|
|
105
|
-
defaults?: Record<string, string> | undefined;
|
|
106
|
-
aliases?: Record<string, string> | undefined;
|
|
107
|
-
}, {
|
|
108
|
-
models: Record<string, Record<string, {
|
|
109
|
-
id: string;
|
|
110
|
-
capabilities: string[];
|
|
111
|
-
displayName: string;
|
|
112
|
-
deprecated: boolean;
|
|
113
|
-
pricing: {
|
|
114
|
-
input: number;
|
|
115
|
-
output: number;
|
|
116
|
-
};
|
|
117
|
-
contextWindow: number;
|
|
118
|
-
releaseDate: string;
|
|
119
|
-
}>>;
|
|
120
|
-
version: string;
|
|
121
|
-
lastUpdated: string;
|
|
122
|
-
defaults?: Record<string, string> | undefined;
|
|
123
|
-
aliases?: Record<string, string> | undefined;
|
|
124
|
-
}>;
|
|
125
|
-
export type ModelConfig = z.infer<typeof ModelConfigSchema>;
|
|
126
|
-
export type ModelRegistry = z.infer<typeof ModelRegistrySchema>;
|
|
1
|
+
import type { DynamicModelConfig as ModelConfig } from "../types/index.js";
|
|
127
2
|
/**
|
|
128
3
|
* Dynamic Model Provider
|
|
129
4
|
* Loads and manages model configurations from external sources
|
|
@@ -150,11 +25,6 @@ export declare class DynamicModelProvider {
|
|
|
150
25
|
* Prevents hanging on non-responsive local servers
|
|
151
26
|
*/
|
|
152
27
|
private healthCheckLocalhost;
|
|
153
|
-
/**
|
|
154
|
-
* Load configuration from a source (URL or file path) - Legacy method for compatibility
|
|
155
|
-
* @deprecated Use loadFromSourceWithTimeout instead
|
|
156
|
-
*/
|
|
157
|
-
private loadFromSource;
|
|
158
28
|
/**
|
|
159
29
|
* Get all available models for a provider
|
|
160
30
|
*/
|
|
@@ -217,4 +87,3 @@ export declare class DynamicModelProvider {
|
|
|
217
87
|
} | null;
|
|
218
88
|
}
|
|
219
89
|
export declare const dynamicModelProvider: DynamicModelProvider;
|
|
220
|
-
export {};
|
|
@@ -190,13 +190,6 @@ export class DynamicModelProvider {
|
|
|
190
190
|
});
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
|
-
/**
|
|
194
|
-
* Load configuration from a source (URL or file path) - Legacy method for compatibility
|
|
195
|
-
* @deprecated Use loadFromSourceWithTimeout instead
|
|
196
|
-
*/
|
|
197
|
-
async loadFromSource(source) {
|
|
198
|
-
return this.loadFromSourceWithTimeout(source, 10000); // 10s default timeout
|
|
199
|
-
}
|
|
200
193
|
/**
|
|
201
194
|
* Get all available models for a provider
|
|
202
195
|
*/
|
|
@@ -1,45 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* NeuroLink Evaluation System
|
|
3
3
|
*/
|
|
4
|
-
import type {
|
|
5
|
-
export interface EvaluationResult extends EvaluationData {
|
|
6
|
-
domainAlignment?: number;
|
|
7
|
-
terminologyAccuracy?: number;
|
|
8
|
-
toolEffectiveness?: number;
|
|
9
|
-
contextUtilization?: {
|
|
10
|
-
conversationUsed: boolean;
|
|
11
|
-
toolsUsed: boolean;
|
|
12
|
-
domainKnowledgeUsed: boolean;
|
|
13
|
-
};
|
|
14
|
-
evaluationContext?: {
|
|
15
|
-
domain: string;
|
|
16
|
-
toolsEvaluated: string[];
|
|
17
|
-
conversationTurns: number;
|
|
18
|
-
};
|
|
19
|
-
isOffTopic: boolean;
|
|
20
|
-
alertSeverity: "low" | "medium" | "high" | "none";
|
|
21
|
-
reasoning: string;
|
|
22
|
-
}
|
|
23
|
-
export interface EvaluationContext {
|
|
24
|
-
userQuery: string;
|
|
25
|
-
aiResponse: string;
|
|
26
|
-
context?: Record<string, unknown>;
|
|
27
|
-
primaryDomain?: string;
|
|
28
|
-
assistantRole?: string;
|
|
29
|
-
conversationHistory?: Array<{
|
|
30
|
-
role: "user" | "assistant";
|
|
31
|
-
content: string;
|
|
32
|
-
timestamp?: string;
|
|
33
|
-
}>;
|
|
34
|
-
toolUsage?: Array<{
|
|
35
|
-
toolName: string;
|
|
36
|
-
input: unknown;
|
|
37
|
-
output: unknown;
|
|
38
|
-
executionTime: number;
|
|
39
|
-
}>;
|
|
40
|
-
expectedOutcome?: string;
|
|
41
|
-
evaluationCriteria?: string[];
|
|
42
|
-
}
|
|
4
|
+
import type { EnhancedEvaluationResult as EvaluationResult, EvaluationContext } from "../types/index.js";
|
|
43
5
|
/**
|
|
44
6
|
* Get default evaluation when evaluation fails
|
|
45
7
|
*/
|
|
@@ -1,19 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
provider: string;
|
|
3
|
-
models: string[];
|
|
4
|
-
costPerToken?: number | {
|
|
5
|
-
input: number;
|
|
6
|
-
output: number;
|
|
7
|
-
};
|
|
8
|
-
requiresApiKey?: string[];
|
|
9
|
-
performance?: {
|
|
10
|
-
averageLatency?: number;
|
|
11
|
-
reliability?: number;
|
|
12
|
-
speed?: number;
|
|
13
|
-
quality?: number;
|
|
14
|
-
cost?: number;
|
|
15
|
-
};
|
|
16
|
-
}
|
|
1
|
+
import type { ProviderModelConfig } from "../types/index.js";
|
|
17
2
|
/**
|
|
18
3
|
* Dynamic provider configurations for evaluation
|
|
19
4
|
* Now uses configurable system instead of hardcoded values
|
|
@@ -73,4 +58,3 @@ export declare function getProviderPerformanceAnalytics(): Record<string, {
|
|
|
73
58
|
* @param providerName - (Optional) The name of the provider to reset. If omitted, resets all providers.
|
|
74
59
|
*/
|
|
75
60
|
export declare function resetProviderMetrics(providerName?: string): void;
|
|
76
|
-
export {};
|
|
@@ -40,7 +40,7 @@ export const EVALUATION_PROVIDER_CONFIGS = getEvaluationProviderConfigs();
|
|
|
40
40
|
* Now uses the configurable system
|
|
41
41
|
*/
|
|
42
42
|
export function getProviderConfig(providerName) {
|
|
43
|
-
const config = modelConfig.
|
|
43
|
+
const config = modelConfig.getProviderConfiguration(providerName);
|
|
44
44
|
return config ? convertToLegacyFormat(config) : null;
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type { AIProvider, AIProviderName, SupportedModelName } from "
|
|
1
|
+
import type { AIProvider, AIProviderName, SupportedModelName } from "../types/index.js";
|
|
2
2
|
import type { UnknownRecord } from "../types/common.js";
|
|
3
3
|
import type { ProviderPairResult } from "../types/typeAliases.js";
|
|
4
|
-
declare const componentIdentifier = "aiProviderFactory";
|
|
5
4
|
/**
|
|
6
5
|
* Factory for creating AI provider instances with centralized configuration
|
|
7
6
|
*/
|
|
@@ -48,4 +47,3 @@ export declare class AIProviderFactory {
|
|
|
48
47
|
*/
|
|
49
48
|
static createProviderWithFallback(primaryProvider: string, fallbackProvider: string, modelName?: string | null, enableMCP?: boolean): Promise<ProviderPairResult<AIProvider>>;
|
|
50
49
|
}
|
|
51
|
-
export { componentIdentifier };
|
package/dist/lib/core/factory.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Replaces hardcoded model-specific logic with configurable, runtime-updateable configurations.
|
|
5
5
|
* This addresses GitHub Copilot review comment about making model-specific logic configuration-based.
|
|
6
6
|
*/
|
|
7
|
-
import type {
|
|
7
|
+
import type { ModelTier, ProviderConfiguration, ConfigSource } from "../types/modelTypes.js";
|
|
8
8
|
/**
|
|
9
9
|
* Model name constants - extracted from hardcoded values for better maintainability
|
|
10
10
|
* These constants can be overridden by environment variables
|
|
@@ -61,67 +61,6 @@ export declare const MODEL_NAMES: {
|
|
|
61
61
|
readonly QUALITY: "mistral-large-latest";
|
|
62
62
|
};
|
|
63
63
|
};
|
|
64
|
-
/**
|
|
65
|
-
* Model performance tier definition
|
|
66
|
-
*/
|
|
67
|
-
export type ModelTier = "fast" | "balanced" | "quality";
|
|
68
|
-
/**
|
|
69
|
-
* Model configuration for a specific provider
|
|
70
|
-
*/
|
|
71
|
-
export interface ModelConfig {
|
|
72
|
-
/** Model identifier */
|
|
73
|
-
id: string;
|
|
74
|
-
/** Display name */
|
|
75
|
-
name: string;
|
|
76
|
-
/** Performance tier */
|
|
77
|
-
tier: ModelTier;
|
|
78
|
-
/** Cost per 1K tokens */
|
|
79
|
-
cost: {
|
|
80
|
-
input: number;
|
|
81
|
-
output: number;
|
|
82
|
-
};
|
|
83
|
-
/** Model capabilities */
|
|
84
|
-
capabilities: string[];
|
|
85
|
-
/** Model-specific options */
|
|
86
|
-
options?: Record<string, JsonValue>;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Provider configuration with models
|
|
90
|
-
*/
|
|
91
|
-
export interface ProviderConfig {
|
|
92
|
-
/** Provider name */
|
|
93
|
-
provider: string;
|
|
94
|
-
/** Available models by tier */
|
|
95
|
-
models: Record<ModelTier, string>;
|
|
96
|
-
/** Default cost per token (fallback) */
|
|
97
|
-
defaultCost: {
|
|
98
|
-
input: number;
|
|
99
|
-
output: number;
|
|
100
|
-
};
|
|
101
|
-
/** Required environment variables */
|
|
102
|
-
requiredEnvVars: string[];
|
|
103
|
-
/** Provider-specific performance metrics */
|
|
104
|
-
performance: {
|
|
105
|
-
speed: number;
|
|
106
|
-
quality: number;
|
|
107
|
-
cost: number;
|
|
108
|
-
};
|
|
109
|
-
/** Provider-specific model configurations */
|
|
110
|
-
modelConfigs?: Record<string, ModelConfig>;
|
|
111
|
-
/** Provider-specific model behavior configurations */
|
|
112
|
-
modelBehavior?: {
|
|
113
|
-
/** Models that have issues with maxTokens parameter */
|
|
114
|
-
maxTokensIssues?: string[];
|
|
115
|
-
/** Models that require special handling */
|
|
116
|
-
specialHandling?: Record<string, JsonValue>;
|
|
117
|
-
/** Models that support tool calling (Ollama-specific) */
|
|
118
|
-
toolCapableModels?: string[];
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Configuration source type
|
|
123
|
-
*/
|
|
124
|
-
export type ConfigSource = "default" | "environment" | "file" | "dynamic";
|
|
125
64
|
/**
|
|
126
65
|
* Model configuration manager
|
|
127
66
|
*/
|
|
@@ -147,7 +86,7 @@ export declare class ModelConfigurationManager {
|
|
|
147
86
|
/**
|
|
148
87
|
* Create all provider configurations - centralized approach
|
|
149
88
|
*/
|
|
150
|
-
private
|
|
89
|
+
private createAllProviderConfigurations;
|
|
151
90
|
/**
|
|
152
91
|
* Create Anthropic provider configuration
|
|
153
92
|
*/
|
|
@@ -209,15 +148,15 @@ export declare class ModelConfigurationManager {
|
|
|
209
148
|
/**
|
|
210
149
|
* Get provider configuration
|
|
211
150
|
*/
|
|
212
|
-
|
|
151
|
+
getProviderConfiguration(provider: string): ProviderConfiguration | null;
|
|
213
152
|
/**
|
|
214
153
|
* Get all provider configurations
|
|
215
154
|
*/
|
|
216
|
-
getAllConfigurations(): Map<string,
|
|
155
|
+
getAllConfigurations(): Map<string, ProviderConfiguration>;
|
|
217
156
|
/**
|
|
218
157
|
* Update provider configuration (runtime updates)
|
|
219
158
|
*/
|
|
220
|
-
|
|
159
|
+
updateProviderConfiguration(provider: string, config: ProviderConfiguration): void;
|
|
221
160
|
/**
|
|
222
161
|
* Parse YAML content with basic support
|
|
223
162
|
* For full YAML support, would need a proper YAML library
|
|
@@ -244,7 +183,7 @@ export declare class ModelConfigurationManager {
|
|
|
244
183
|
/**
|
|
245
184
|
* Validate provider configuration structure
|
|
246
185
|
*/
|
|
247
|
-
private
|
|
186
|
+
private isValidProviderConfiguration;
|
|
248
187
|
/**
|
|
249
188
|
* Apply model name overrides from configuration file
|
|
250
189
|
*/
|
|
@@ -279,7 +218,7 @@ export declare class ModelConfigurationManager {
|
|
|
279
218
|
/**
|
|
280
219
|
* Get available providers
|
|
281
220
|
*/
|
|
282
|
-
getAvailableProviders():
|
|
221
|
+
getAvailableProviders(): ProviderConfiguration[];
|
|
283
222
|
}
|
|
284
223
|
/**
|
|
285
224
|
* Global instance accessor
|
|
@@ -291,7 +230,7 @@ export declare const modelConfig: ModelConfigurationManager;
|
|
|
291
230
|
/**
|
|
292
231
|
* Get provider configuration (backwards compatible)
|
|
293
232
|
*/
|
|
294
|
-
export declare function
|
|
233
|
+
export declare function getProviderConfiguration(provider: string): ProviderConfiguration | null;
|
|
295
234
|
/**
|
|
296
235
|
* Get model for tier (backwards compatible)
|
|
297
236
|
*/
|
|
@@ -175,7 +175,7 @@ export class ModelConfigurationManager {
|
|
|
175
175
|
/**
|
|
176
176
|
* Create all provider configurations - centralized approach
|
|
177
177
|
*/
|
|
178
|
-
|
|
178
|
+
createAllProviderConfigurations() {
|
|
179
179
|
return {
|
|
180
180
|
"google-ai": this.createGoogleAIConfig(),
|
|
181
181
|
"google-vertex": this.createVertexConfig(),
|
|
@@ -383,7 +383,7 @@ export class ModelConfigurationManager {
|
|
|
383
383
|
*/
|
|
384
384
|
loadDefaultConfigurations() {
|
|
385
385
|
// Load all provider configurations using centralized method
|
|
386
|
-
const defaultConfigs = this.
|
|
386
|
+
const defaultConfigs = this.createAllProviderConfigurations();
|
|
387
387
|
// Load configurations
|
|
388
388
|
for (const [provider, config] of Object.entries(defaultConfigs)) {
|
|
389
389
|
this.configurations.set(provider, config);
|
|
@@ -484,7 +484,7 @@ export class ModelConfigurationManager {
|
|
|
484
484
|
/**
|
|
485
485
|
* Get provider configuration
|
|
486
486
|
*/
|
|
487
|
-
|
|
487
|
+
getProviderConfiguration(provider) {
|
|
488
488
|
return this.configurations.get(provider) || null;
|
|
489
489
|
}
|
|
490
490
|
/**
|
|
@@ -496,7 +496,7 @@ export class ModelConfigurationManager {
|
|
|
496
496
|
/**
|
|
497
497
|
* Update provider configuration (runtime updates)
|
|
498
498
|
*/
|
|
499
|
-
|
|
499
|
+
updateProviderConfiguration(provider, config) {
|
|
500
500
|
this.configurations.set(provider, config);
|
|
501
501
|
this.lastUpdated = Date.now();
|
|
502
502
|
this.configSource = "dynamic";
|
|
@@ -596,7 +596,7 @@ export class ModelConfigurationManager {
|
|
|
596
596
|
if (config.providers && typeof config.providers === "object") {
|
|
597
597
|
const providers = config.providers;
|
|
598
598
|
for (const [providerName, providerConfig] of Object.entries(providers)) {
|
|
599
|
-
if (this.
|
|
599
|
+
if (this.isValidProviderConfiguration(providerConfig)) {
|
|
600
600
|
this.configurations.set(providerName, providerConfig);
|
|
601
601
|
logger.debug(`Loaded configuration for provider: ${providerName}`);
|
|
602
602
|
}
|
|
@@ -629,7 +629,7 @@ export class ModelConfigurationManager {
|
|
|
629
629
|
/**
|
|
630
630
|
* Validate provider configuration structure
|
|
631
631
|
*/
|
|
632
|
-
|
|
632
|
+
isValidProviderConfiguration(config) {
|
|
633
633
|
if (!config || typeof config !== "object") {
|
|
634
634
|
return false;
|
|
635
635
|
}
|
|
@@ -769,14 +769,14 @@ export class ModelConfigurationManager {
|
|
|
769
769
|
* Get model for specific tier and provider
|
|
770
770
|
*/
|
|
771
771
|
getModelForTier(provider, tier) {
|
|
772
|
-
const config = this.
|
|
772
|
+
const config = this.getProviderConfiguration(provider);
|
|
773
773
|
return config?.models[tier] || null;
|
|
774
774
|
}
|
|
775
775
|
/**
|
|
776
776
|
* Get cost information for provider and model
|
|
777
777
|
*/
|
|
778
778
|
getCostInfo(provider, model) {
|
|
779
|
-
const config = this.
|
|
779
|
+
const config = this.getProviderConfiguration(provider);
|
|
780
780
|
if (!config) {
|
|
781
781
|
return null;
|
|
782
782
|
}
|
|
@@ -790,7 +790,7 @@ export class ModelConfigurationManager {
|
|
|
790
790
|
* Check if provider is available (has required environment variables)
|
|
791
791
|
*/
|
|
792
792
|
isProviderAvailable(provider) {
|
|
793
|
-
const config = this.
|
|
793
|
+
const config = this.getProviderConfiguration(provider);
|
|
794
794
|
if (!config) {
|
|
795
795
|
return false;
|
|
796
796
|
}
|
|
@@ -816,8 +816,8 @@ export const modelConfig = ModelConfigurationManager.getInstance();
|
|
|
816
816
|
/**
|
|
817
817
|
* Get provider configuration (backwards compatible)
|
|
818
818
|
*/
|
|
819
|
-
export function
|
|
820
|
-
return modelConfig.
|
|
819
|
+
export function getProviderConfiguration(provider) {
|
|
820
|
+
return modelConfig.getProviderConfiguration(provider);
|
|
821
821
|
}
|
|
822
822
|
/**
|
|
823
823
|
* Get model for tier (backwards compatible)
|