@juspay/neurolink 7.6.1 → 7.7.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 +9 -4
- package/README.md +78 -3
- package/dist/cli/commands/config.d.ts +275 -3
- package/dist/cli/commands/config.js +121 -0
- package/dist/cli/commands/mcp.js +77 -28
- package/dist/cli/factories/commandFactory.js +359 -6
- package/dist/core/analytics.js +7 -27
- package/dist/core/baseProvider.js +43 -4
- package/dist/core/constants.d.ts +46 -0
- package/dist/core/constants.js +47 -0
- package/dist/core/dynamicModels.d.ts +16 -4
- package/dist/core/dynamicModels.js +130 -26
- package/dist/core/evaluation.js +5 -1
- package/dist/core/evaluationProviders.d.ts +6 -2
- package/dist/core/evaluationProviders.js +41 -125
- package/dist/core/factory.d.ts +5 -0
- package/dist/core/factory.js +62 -50
- package/dist/core/modelConfiguration.d.ts +246 -0
- package/dist/core/modelConfiguration.js +775 -0
- package/dist/core/types.d.ts +22 -3
- package/dist/core/types.js +5 -1
- package/dist/factories/providerRegistry.js +3 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/lib/core/analytics.js +7 -27
- package/dist/lib/core/baseProvider.js +43 -4
- package/dist/lib/core/constants.d.ts +46 -0
- package/dist/lib/core/constants.js +47 -0
- package/dist/lib/core/dynamicModels.d.ts +16 -4
- package/dist/lib/core/dynamicModels.js +130 -26
- package/dist/lib/core/evaluation.js +5 -1
- package/dist/lib/core/evaluationProviders.d.ts +6 -2
- package/dist/lib/core/evaluationProviders.js +41 -125
- package/dist/lib/core/factory.d.ts +5 -0
- package/dist/lib/core/factory.js +63 -50
- package/dist/lib/core/modelConfiguration.d.ts +246 -0
- package/dist/lib/core/modelConfiguration.js +775 -0
- package/dist/lib/core/types.d.ts +22 -3
- package/dist/lib/core/types.js +5 -1
- package/dist/lib/factories/providerRegistry.js +3 -3
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js +1 -1
- package/dist/lib/mcp/factory.d.ts +5 -5
- package/dist/lib/mcp/factory.js +2 -2
- package/dist/lib/mcp/servers/utilities/utilityServer.d.ts +1 -1
- package/dist/lib/mcp/servers/utilities/utilityServer.js +1 -1
- package/dist/lib/mcp/toolRegistry.js +2 -2
- package/dist/lib/neurolink.d.ts +168 -12
- package/dist/lib/neurolink.js +685 -123
- package/dist/lib/providers/anthropic.js +52 -2
- package/dist/lib/providers/googleAiStudio.js +4 -0
- package/dist/lib/providers/googleVertex.d.ts +75 -9
- package/dist/lib/providers/googleVertex.js +365 -46
- package/dist/lib/providers/huggingFace.d.ts +52 -11
- package/dist/lib/providers/huggingFace.js +180 -42
- package/dist/lib/providers/litellm.d.ts +9 -9
- package/dist/lib/providers/litellm.js +103 -16
- package/dist/lib/providers/ollama.d.ts +52 -17
- package/dist/lib/providers/ollama.js +276 -68
- package/dist/lib/sdk/toolRegistration.d.ts +42 -0
- package/dist/lib/sdk/toolRegistration.js +269 -27
- package/dist/lib/telemetry/telemetryService.d.ts +6 -0
- package/dist/lib/telemetry/telemetryService.js +38 -3
- package/dist/lib/types/contextTypes.d.ts +75 -11
- package/dist/lib/types/contextTypes.js +227 -1
- package/dist/lib/types/domainTypes.d.ts +62 -0
- package/dist/lib/types/domainTypes.js +5 -0
- package/dist/lib/types/generateTypes.d.ts +52 -0
- package/dist/lib/types/index.d.ts +1 -0
- package/dist/lib/types/mcpTypes.d.ts +1 -1
- package/dist/lib/types/mcpTypes.js +1 -1
- package/dist/lib/types/streamTypes.d.ts +14 -0
- package/dist/lib/types/universalProviderOptions.d.ts +1 -1
- package/dist/lib/utils/errorHandling.d.ts +142 -0
- package/dist/lib/utils/errorHandling.js +316 -0
- package/dist/lib/utils/factoryProcessing.d.ts +74 -0
- package/dist/lib/utils/factoryProcessing.js +588 -0
- package/dist/lib/utils/optionsConversion.d.ts +54 -0
- package/dist/lib/utils/optionsConversion.js +126 -0
- package/dist/lib/utils/optionsUtils.d.ts +246 -0
- package/dist/lib/utils/optionsUtils.js +960 -0
- package/dist/lib/utils/providerHealth.d.ts +107 -0
- package/dist/lib/utils/providerHealth.js +507 -0
- package/dist/lib/utils/providerUtils.d.ts +17 -0
- package/dist/lib/utils/providerUtils.js +271 -16
- package/dist/lib/utils/timeout.js +1 -1
- package/dist/lib/utils/tokenLimits.d.ts +33 -0
- package/dist/lib/utils/tokenLimits.js +118 -0
- package/dist/mcp/factory.d.ts +5 -5
- package/dist/mcp/factory.js +2 -2
- package/dist/mcp/servers/utilities/utilityServer.d.ts +1 -1
- package/dist/mcp/servers/utilities/utilityServer.js +1 -1
- package/dist/mcp/toolRegistry.js +2 -2
- package/dist/neurolink.d.ts +168 -12
- package/dist/neurolink.js +685 -123
- package/dist/providers/anthropic.js +52 -2
- package/dist/providers/googleAiStudio.js +4 -0
- package/dist/providers/googleVertex.d.ts +75 -9
- package/dist/providers/googleVertex.js +365 -46
- package/dist/providers/huggingFace.d.ts +52 -11
- package/dist/providers/huggingFace.js +181 -43
- package/dist/providers/litellm.d.ts +9 -9
- package/dist/providers/litellm.js +103 -16
- package/dist/providers/ollama.d.ts +52 -17
- package/dist/providers/ollama.js +276 -68
- package/dist/sdk/toolRegistration.d.ts +42 -0
- package/dist/sdk/toolRegistration.js +269 -27
- package/dist/telemetry/telemetryService.d.ts +6 -0
- package/dist/telemetry/telemetryService.js +38 -3
- package/dist/types/contextTypes.d.ts +75 -11
- package/dist/types/contextTypes.js +227 -2
- package/dist/types/domainTypes.d.ts +62 -0
- package/dist/types/domainTypes.js +5 -0
- package/dist/types/generateTypes.d.ts +52 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/mcpTypes.d.ts +1 -1
- package/dist/types/mcpTypes.js +1 -1
- package/dist/types/streamTypes.d.ts +14 -0
- package/dist/types/universalProviderOptions.d.ts +1 -1
- package/dist/types/universalProviderOptions.js +0 -1
- package/dist/utils/errorHandling.d.ts +142 -0
- package/dist/utils/errorHandling.js +316 -0
- package/dist/utils/factoryProcessing.d.ts +74 -0
- package/dist/utils/factoryProcessing.js +588 -0
- package/dist/utils/optionsConversion.d.ts +54 -0
- package/dist/utils/optionsConversion.js +126 -0
- package/dist/utils/optionsUtils.d.ts +246 -0
- package/dist/utils/optionsUtils.js +960 -0
- package/dist/utils/providerHealth.d.ts +107 -0
- package/dist/utils/providerHealth.js +507 -0
- package/dist/utils/providerUtils.d.ts +17 -0
- package/dist/utils/providerUtils.js +271 -16
- package/dist/utils/timeout.js +1 -1
- package/dist/utils/tokenLimits.d.ts +33 -0
- package/dist/utils/tokenLimits.js +118 -0
- package/package.json +2 -2
|
@@ -1,127 +1,49 @@
|
|
|
1
|
+
import { modelConfig } from "./modelConfiguration.js";
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
-
* All 9 NeuroLink providers with cost and performance data
|
|
3
|
+
* Convert new configuration format to legacy format for backwards compatibility
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
provider:
|
|
8
|
-
models:
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
fast: "claude-3-haiku-20240307",
|
|
32
|
-
balanced: "claude-3-sonnet-20240229",
|
|
33
|
-
quality: "claude-3-opus-20240229",
|
|
34
|
-
},
|
|
35
|
-
costPerToken: { input: 0.00025, output: 0.00125 },
|
|
36
|
-
requiresApiKey: ["ANTHROPIC_API_KEY"],
|
|
37
|
-
performance: { speed: 2, quality: 3, cost: 2 },
|
|
38
|
-
},
|
|
39
|
-
vertex: {
|
|
40
|
-
provider: "vertex",
|
|
41
|
-
models: {
|
|
42
|
-
fast: "gemini-2.5-flash",
|
|
43
|
-
balanced: "gemini-2.5-pro",
|
|
44
|
-
quality: "gemini-2.5-pro",
|
|
45
|
-
},
|
|
46
|
-
costPerToken: { input: 0.000075, output: 0.0003 },
|
|
47
|
-
requiresApiKey: [
|
|
48
|
-
"GOOGLE_VERTEX_PROJECT",
|
|
49
|
-
"GOOGLE_APPLICATION_CREDENTIALS",
|
|
50
|
-
],
|
|
51
|
-
performance: { speed: 2, quality: 3, cost: 3 },
|
|
52
|
-
},
|
|
53
|
-
bedrock: {
|
|
54
|
-
provider: "bedrock",
|
|
55
|
-
models: {
|
|
56
|
-
fast: "anthropic.claude-3-haiku-20240307-v1:0",
|
|
57
|
-
balanced: "anthropic.claude-3-sonnet-20240229-v1:0",
|
|
58
|
-
quality: "anthropic.claude-3-opus-20240229-v1:0",
|
|
59
|
-
},
|
|
60
|
-
costPerToken: { input: 0.00025, output: 0.00125 },
|
|
61
|
-
requiresApiKey: ["AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY"],
|
|
62
|
-
performance: { speed: 2, quality: 3, cost: 2 },
|
|
63
|
-
},
|
|
64
|
-
azure: {
|
|
65
|
-
provider: "azure",
|
|
66
|
-
models: {
|
|
67
|
-
fast: "gpt-4o-mini",
|
|
68
|
-
balanced: "gpt-4o",
|
|
69
|
-
quality: "gpt-4o",
|
|
70
|
-
},
|
|
71
|
-
costPerToken: { input: 0.00015, output: 0.0006 },
|
|
72
|
-
requiresApiKey: ["AZURE_OPENAI_API_KEY", "AZURE_OPENAI_ENDPOINT"],
|
|
73
|
-
performance: { speed: 2, quality: 3, cost: 2 },
|
|
74
|
-
},
|
|
75
|
-
ollama: {
|
|
76
|
-
provider: "ollama",
|
|
77
|
-
models: {
|
|
78
|
-
fast: "llama3.2:latest",
|
|
79
|
-
balanced: "llama3.1:8b",
|
|
80
|
-
quality: "llama3.1:70b",
|
|
81
|
-
},
|
|
82
|
-
costPerToken: { input: 0, output: 0 }, // Local model
|
|
83
|
-
requiresApiKey: [], // No API key needed
|
|
84
|
-
performance: { speed: 1, quality: 2, cost: 3 },
|
|
85
|
-
},
|
|
86
|
-
huggingface: {
|
|
87
|
-
provider: "huggingface",
|
|
88
|
-
models: {
|
|
89
|
-
fast: "microsoft/DialoGPT-medium",
|
|
90
|
-
balanced: "microsoft/DialoGPT-large",
|
|
91
|
-
quality: "meta-llama/Llama-2-7b-chat-hf",
|
|
92
|
-
},
|
|
93
|
-
costPerToken: { input: 0.0002, output: 0.0006 },
|
|
94
|
-
requiresApiKey: ["HUGGINGFACE_API_KEY"],
|
|
95
|
-
performance: { speed: 1, quality: 2, cost: 2 },
|
|
96
|
-
},
|
|
97
|
-
mistral: {
|
|
98
|
-
provider: "mistral",
|
|
99
|
-
models: {
|
|
100
|
-
fast: "mistral-small-latest",
|
|
101
|
-
balanced: "mistral-medium-latest",
|
|
102
|
-
quality: "mistral-large-latest",
|
|
103
|
-
},
|
|
104
|
-
costPerToken: { input: 0.0002, output: 0.0006 },
|
|
105
|
-
requiresApiKey: ["MISTRAL_API_KEY"],
|
|
106
|
-
performance: { speed: 2, quality: 2, cost: 2 },
|
|
107
|
-
},
|
|
108
|
-
};
|
|
5
|
+
function convertToLegacyFormat(config) {
|
|
6
|
+
return {
|
|
7
|
+
provider: config.provider,
|
|
8
|
+
models: config.models,
|
|
9
|
+
costPerToken: config.defaultCost,
|
|
10
|
+
requiresApiKey: config.requiredEnvVars,
|
|
11
|
+
performance: config.performance,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Get all provider configurations using the new configuration system
|
|
16
|
+
* Replaces hardcoded EVALUATION_PROVIDER_CONFIGS with configurable system
|
|
17
|
+
*/
|
|
18
|
+
function getEvaluationProviderConfigs() {
|
|
19
|
+
const configs = {};
|
|
20
|
+
const allConfigs = modelConfig.getAllConfigurations();
|
|
21
|
+
for (const [provider, config] of allConfigs) {
|
|
22
|
+
configs[provider] = convertToLegacyFormat(config);
|
|
23
|
+
}
|
|
24
|
+
return configs;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Dynamic provider configurations for evaluation
|
|
28
|
+
* Now uses configurable system instead of hardcoded values
|
|
29
|
+
*/
|
|
30
|
+
export const EVALUATION_PROVIDER_CONFIGS = getEvaluationProviderConfigs();
|
|
109
31
|
/**
|
|
110
32
|
* Get provider configuration by name
|
|
33
|
+
* Now uses the configurable system
|
|
111
34
|
*/
|
|
112
35
|
export function getProviderConfig(providerName) {
|
|
113
|
-
|
|
36
|
+
const config = modelConfig.getProviderConfig(providerName);
|
|
37
|
+
return config ? convertToLegacyFormat(config) : null;
|
|
114
38
|
}
|
|
115
39
|
/**
|
|
116
40
|
* Get all available providers with required API keys present
|
|
41
|
+
* Now uses the configurable system
|
|
117
42
|
*/
|
|
118
43
|
export function getAvailableProviders() {
|
|
119
|
-
return
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
} // Ollama
|
|
123
|
-
return config.requiresApiKey.some((key) => process.env[key]);
|
|
124
|
-
});
|
|
44
|
+
return modelConfig
|
|
45
|
+
.getAvailableProviders()
|
|
46
|
+
.map((config) => convertToLegacyFormat(config));
|
|
125
47
|
}
|
|
126
48
|
/**
|
|
127
49
|
* Sort providers by preference (cost, speed, quality)
|
|
@@ -152,27 +74,21 @@ export function sortProvidersByPreference(providers, preferCheap = true) {
|
|
|
152
74
|
}
|
|
153
75
|
/**
|
|
154
76
|
* Estimate cost for a specific provider and token usage
|
|
77
|
+
* Now uses the configurable system
|
|
155
78
|
*/
|
|
156
79
|
export function estimateProviderCost(providerName, inputTokens, outputTokens) {
|
|
157
|
-
const
|
|
158
|
-
if (!
|
|
80
|
+
const costInfo = modelConfig.getCostInfo(providerName);
|
|
81
|
+
if (!costInfo) {
|
|
159
82
|
return 0;
|
|
160
83
|
}
|
|
161
|
-
return
|
|
162
|
-
outputTokens * config.costPerToken.output);
|
|
84
|
+
return inputTokens * costInfo.input + outputTokens * costInfo.output;
|
|
163
85
|
}
|
|
164
86
|
/**
|
|
165
87
|
* Check if a provider is available (has required API keys)
|
|
88
|
+
* Now uses the configurable system
|
|
166
89
|
*/
|
|
167
90
|
export function isProviderAvailable(providerName) {
|
|
168
|
-
|
|
169
|
-
if (!config) {
|
|
170
|
-
return false;
|
|
171
|
-
}
|
|
172
|
-
if (config.requiresApiKey.length === 0) {
|
|
173
|
-
return true;
|
|
174
|
-
} // Ollama
|
|
175
|
-
return config.requiresApiKey.some((key) => process.env[key]);
|
|
91
|
+
return modelConfig.isProviderAvailable(providerName);
|
|
176
92
|
}
|
|
177
93
|
/**
|
|
178
94
|
* Get the best available provider based on preference
|
package/dist/core/factory.d.ts
CHANGED
|
@@ -9,6 +9,11 @@ export declare class AIProviderFactory {
|
|
|
9
9
|
* Normalize provider name using ProviderFactory
|
|
10
10
|
*/
|
|
11
11
|
private static normalizeProviderName;
|
|
12
|
+
/**
|
|
13
|
+
* Initialize dynamic model provider with timeout protection
|
|
14
|
+
* Prevents hanging on non-responsive endpoints
|
|
15
|
+
*/
|
|
16
|
+
private static initializeDynamicProviderWithTimeout;
|
|
12
17
|
/**
|
|
13
18
|
* Create a provider instance for the specified provider type
|
|
14
19
|
* @param providerName - Name of the provider ('vertex', 'bedrock', 'openai')
|
package/dist/core/factory.js
CHANGED
|
@@ -22,6 +22,31 @@ export class AIProviderFactory {
|
|
|
22
22
|
// If not found in factory, return as-is (will be handled by factory error handling)
|
|
23
23
|
return providerName.toLowerCase();
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Initialize dynamic model provider with timeout protection
|
|
27
|
+
* Prevents hanging on non-responsive endpoints
|
|
28
|
+
*/
|
|
29
|
+
static async initializeDynamicProviderWithTimeout() {
|
|
30
|
+
const functionTag = "AIProviderFactory.initializeDynamicProviderWithTimeout";
|
|
31
|
+
const INIT_TIMEOUT = 10000; // 10 seconds total timeout for initialization
|
|
32
|
+
try {
|
|
33
|
+
// Race the initialization against a timeout
|
|
34
|
+
await Promise.race([
|
|
35
|
+
dynamicModelProvider.initialize(),
|
|
36
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error("Dynamic provider initialization timeout")), INIT_TIMEOUT)),
|
|
37
|
+
]);
|
|
38
|
+
logger.debug(`[${functionTag}] Dynamic model provider initialized successfully`);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
42
|
+
logger.warn(`[${functionTag}] Dynamic model provider initialization failed`, {
|
|
43
|
+
error: errorMessage,
|
|
44
|
+
fallback: "Using static model defaults",
|
|
45
|
+
});
|
|
46
|
+
// Don't throw - graceful degradation to static models
|
|
47
|
+
// This ensures the factory continues to work even if dynamic models fail
|
|
48
|
+
}
|
|
49
|
+
}
|
|
25
50
|
/**
|
|
26
51
|
* Create a provider instance for the specified provider type
|
|
27
52
|
* @param providerName - Name of the provider ('vertex', 'bedrock', 'openai')
|
|
@@ -38,58 +63,45 @@ export class AIProviderFactory {
|
|
|
38
63
|
enableMCP,
|
|
39
64
|
});
|
|
40
65
|
try {
|
|
41
|
-
// DYNAMIC MODEL PROVIDER STATUS (2025):
|
|
42
|
-
//
|
|
43
|
-
// Root Cause: Dynamic model provider initialization can hang when:
|
|
44
|
-
// - Local model server (localhost:3001) is not running or responding
|
|
45
|
-
// - GitHub raw URL requests timeout due to network issues
|
|
46
|
-
// - Local config file doesn't exist
|
|
66
|
+
// DYNAMIC MODEL PROVIDER STATUS (2025): Enhanced with timeout handling
|
|
47
67
|
//
|
|
48
|
-
//
|
|
49
|
-
//
|
|
68
|
+
// ✅ FIXED: Hanging issues resolved with comprehensive timeout implementation
|
|
69
|
+
// - Added robust timeout handling (3s localhost, 5s GitHub, 1s local file)
|
|
70
|
+
// - Implemented health checks for localhost endpoints
|
|
71
|
+
// - Added graceful degradation when all sources fail
|
|
72
|
+
// - Enhanced error handling and logging for debugging
|
|
50
73
|
//
|
|
51
|
-
//
|
|
52
|
-
|
|
53
|
-
//
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
// logger.debug(
|
|
83
|
-
// `[${functionTag}] Dynamic model resolution failed, using fallback`,
|
|
84
|
-
// {
|
|
85
|
-
// error:
|
|
86
|
-
// resolveError instanceof Error
|
|
87
|
-
// ? resolveError.message
|
|
88
|
-
// : String(resolveError),
|
|
89
|
-
// },
|
|
90
|
-
// );
|
|
91
|
-
// }
|
|
92
|
-
// }
|
|
74
|
+
// The dynamic model provider now provides reliable functionality without hanging
|
|
75
|
+
let resolvedModelName = modelName;
|
|
76
|
+
// Enable dynamic model resolution with timeout-protected initialization
|
|
77
|
+
if (!modelName || modelName === "default") {
|
|
78
|
+
try {
|
|
79
|
+
const normalizedProvider = this.normalizeProviderName(providerName);
|
|
80
|
+
// Initialize with timeout protection - won't hang anymore
|
|
81
|
+
if (dynamicModelProvider.needsRefresh()) {
|
|
82
|
+
await this.initializeDynamicProviderWithTimeout();
|
|
83
|
+
}
|
|
84
|
+
const dynamicModel = dynamicModelProvider.resolveModel(normalizedProvider, modelName || undefined);
|
|
85
|
+
if (dynamicModel) {
|
|
86
|
+
resolvedModelName = dynamicModel.id;
|
|
87
|
+
logger.debug(`[${functionTag}] Resolved dynamic model`, {
|
|
88
|
+
provider: normalizedProvider,
|
|
89
|
+
requestedModel: modelName || "default",
|
|
90
|
+
resolvedModel: resolvedModelName,
|
|
91
|
+
displayName: dynamicModel.displayName,
|
|
92
|
+
pricing: dynamicModel.pricing.input,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
catch (resolveError) {
|
|
97
|
+
logger.debug(`[${functionTag}] Dynamic model resolution failed, using static fallback`, {
|
|
98
|
+
error: resolveError instanceof Error
|
|
99
|
+
? resolveError.message
|
|
100
|
+
: String(resolveError),
|
|
101
|
+
});
|
|
102
|
+
// Continue with static model name - no functionality loss
|
|
103
|
+
}
|
|
104
|
+
}
|
|
93
105
|
// CRITICAL FIX: Initialize providers before using them
|
|
94
106
|
await ProviderRegistry.registerAllProviders();
|
|
95
107
|
// PURE FACTORY PATTERN: No switch statements - use ProviderFactory exclusively
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model Configuration System
|
|
3
|
+
*
|
|
4
|
+
* Replaces hardcoded model-specific logic with configurable, runtime-updateable configurations.
|
|
5
|
+
* This addresses GitHub Copilot review comment about making model-specific logic configuration-based.
|
|
6
|
+
*/
|
|
7
|
+
import type { JsonValue } from "../types/common.js";
|
|
8
|
+
/**
|
|
9
|
+
* Model name constants - extracted from hardcoded values for better maintainability
|
|
10
|
+
* These constants can be overridden by environment variables
|
|
11
|
+
*/
|
|
12
|
+
export declare const MODEL_NAMES: {
|
|
13
|
+
readonly GOOGLE_AI: {
|
|
14
|
+
readonly FAST: "gemini-2.5-flash";
|
|
15
|
+
readonly BALANCED: "gemini-2.5-pro";
|
|
16
|
+
readonly QUALITY: "gemini-2.5-pro";
|
|
17
|
+
};
|
|
18
|
+
readonly GOOGLE_VERTEX: {
|
|
19
|
+
readonly FAST: "gemini-2.5-flash";
|
|
20
|
+
readonly BALANCED: "gemini-2.5-pro";
|
|
21
|
+
readonly QUALITY: "gemini-2.5-pro";
|
|
22
|
+
};
|
|
23
|
+
readonly OPENAI: {
|
|
24
|
+
readonly FAST: "gpt-4o-mini";
|
|
25
|
+
readonly BALANCED: "gpt-4o";
|
|
26
|
+
readonly QUALITY: "gpt-4o";
|
|
27
|
+
};
|
|
28
|
+
readonly ANTHROPIC: {
|
|
29
|
+
readonly FAST: "claude-3-haiku-20240307";
|
|
30
|
+
readonly BALANCED: "claude-3-sonnet-20240229";
|
|
31
|
+
readonly QUALITY: "claude-3-5-sonnet-20241022";
|
|
32
|
+
};
|
|
33
|
+
readonly VERTEX: {
|
|
34
|
+
readonly FAST: "gemini-2.5-flash";
|
|
35
|
+
readonly BALANCED: "gemini-2.5-pro";
|
|
36
|
+
readonly QUALITY: "gemini-2.5-pro";
|
|
37
|
+
};
|
|
38
|
+
readonly BEDROCK: {
|
|
39
|
+
readonly FAST: "anthropic.claude-3-haiku-20240307-v1:0";
|
|
40
|
+
readonly BALANCED: "anthropic.claude-3-sonnet-20240229-v1:0";
|
|
41
|
+
readonly QUALITY: "anthropic.claude-3-opus-20240229-v1:0";
|
|
42
|
+
};
|
|
43
|
+
readonly AZURE: {
|
|
44
|
+
readonly FAST: "gpt-4o-mini";
|
|
45
|
+
readonly BALANCED: "gpt-4o";
|
|
46
|
+
readonly QUALITY: "gpt-4o";
|
|
47
|
+
};
|
|
48
|
+
readonly OLLAMA: {
|
|
49
|
+
readonly FAST: "llama3.2:latest";
|
|
50
|
+
readonly BALANCED: "llama3.1:8b";
|
|
51
|
+
readonly QUALITY: "llama3.1:70b";
|
|
52
|
+
};
|
|
53
|
+
readonly HUGGINGFACE: {
|
|
54
|
+
readonly FAST: "microsoft/DialoGPT-medium";
|
|
55
|
+
readonly BALANCED: "microsoft/DialoGPT-large";
|
|
56
|
+
readonly QUALITY: "meta-llama/Llama-2-7b-chat-hf";
|
|
57
|
+
};
|
|
58
|
+
readonly MISTRAL: {
|
|
59
|
+
readonly FAST: "mistral-small-latest";
|
|
60
|
+
readonly BALANCED: "mistral-medium-latest";
|
|
61
|
+
readonly QUALITY: "mistral-large-latest";
|
|
62
|
+
};
|
|
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
|
+
/**
|
|
126
|
+
* Model configuration manager
|
|
127
|
+
*/
|
|
128
|
+
export declare class ModelConfigurationManager {
|
|
129
|
+
private static instance;
|
|
130
|
+
private configurations;
|
|
131
|
+
private configSource;
|
|
132
|
+
private lastUpdated;
|
|
133
|
+
private constructor();
|
|
134
|
+
static getInstance(): ModelConfigurationManager;
|
|
135
|
+
/**
|
|
136
|
+
* Load default configurations (replaces hardcoded values)
|
|
137
|
+
*/
|
|
138
|
+
private loadDefaultConfigurations;
|
|
139
|
+
/**
|
|
140
|
+
* Helper method to get configuration value with fallback and validation
|
|
141
|
+
*/
|
|
142
|
+
private getConfigValue;
|
|
143
|
+
/**
|
|
144
|
+
* Validate configuration values for security and correctness
|
|
145
|
+
*/
|
|
146
|
+
private isValidConfigValue;
|
|
147
|
+
/**
|
|
148
|
+
* Helper method to get configuration array with fallback
|
|
149
|
+
* Parses comma-separated environment variable values
|
|
150
|
+
*/
|
|
151
|
+
private getConfigArray;
|
|
152
|
+
/**
|
|
153
|
+
* Helper method to parse float with fallback
|
|
154
|
+
*/
|
|
155
|
+
private parseFloat;
|
|
156
|
+
/**
|
|
157
|
+
* Helper method to parse int with fallback
|
|
158
|
+
*/
|
|
159
|
+
private parseInt;
|
|
160
|
+
/**
|
|
161
|
+
* Helper method to get configuration object with fallback
|
|
162
|
+
* Parses JSON environment variable values
|
|
163
|
+
*/
|
|
164
|
+
private getConfigObject;
|
|
165
|
+
/**
|
|
166
|
+
* Get provider configuration
|
|
167
|
+
*/
|
|
168
|
+
getProviderConfig(provider: string): ProviderConfig | null;
|
|
169
|
+
/**
|
|
170
|
+
* Get all provider configurations
|
|
171
|
+
*/
|
|
172
|
+
getAllConfigurations(): Map<string, ProviderConfig>;
|
|
173
|
+
/**
|
|
174
|
+
* Update provider configuration (runtime updates)
|
|
175
|
+
*/
|
|
176
|
+
updateProviderConfig(provider: string, config: ProviderConfig): void;
|
|
177
|
+
/**
|
|
178
|
+
* Load configurations from external source
|
|
179
|
+
*/
|
|
180
|
+
loadConfigurationsFromFile(configPath: string): void;
|
|
181
|
+
/**
|
|
182
|
+
* Validate provider configuration structure
|
|
183
|
+
*/
|
|
184
|
+
private isValidProviderConfig;
|
|
185
|
+
/**
|
|
186
|
+
* Apply model name overrides from configuration file
|
|
187
|
+
*/
|
|
188
|
+
private applyModelNameOverrides;
|
|
189
|
+
/**
|
|
190
|
+
* Apply global default configurations
|
|
191
|
+
*/
|
|
192
|
+
private applyGlobalDefaults;
|
|
193
|
+
/**
|
|
194
|
+
* Get configuration metadata
|
|
195
|
+
*/
|
|
196
|
+
getConfigurationMeta(): {
|
|
197
|
+
source: ConfigSource;
|
|
198
|
+
lastUpdated: number;
|
|
199
|
+
providerCount: number;
|
|
200
|
+
};
|
|
201
|
+
/**
|
|
202
|
+
* Get model for specific tier and provider
|
|
203
|
+
*/
|
|
204
|
+
getModelForTier(provider: string, tier: ModelTier): string | null;
|
|
205
|
+
/**
|
|
206
|
+
* Get cost information for provider and model
|
|
207
|
+
*/
|
|
208
|
+
getCostInfo(provider: string, model?: string): {
|
|
209
|
+
input: number;
|
|
210
|
+
output: number;
|
|
211
|
+
} | null;
|
|
212
|
+
/**
|
|
213
|
+
* Check if provider is available (has required environment variables)
|
|
214
|
+
*/
|
|
215
|
+
isProviderAvailable(provider: string): boolean;
|
|
216
|
+
/**
|
|
217
|
+
* Get available providers
|
|
218
|
+
*/
|
|
219
|
+
getAvailableProviders(): ProviderConfig[];
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Global instance accessor
|
|
223
|
+
*/
|
|
224
|
+
export declare const modelConfig: ModelConfigurationManager;
|
|
225
|
+
/**
|
|
226
|
+
* Convenience functions for common operations
|
|
227
|
+
*/
|
|
228
|
+
/**
|
|
229
|
+
* Get provider configuration (backwards compatible)
|
|
230
|
+
*/
|
|
231
|
+
export declare function getProviderConfig(provider: string): ProviderConfig | null;
|
|
232
|
+
/**
|
|
233
|
+
* Get model for tier (backwards compatible)
|
|
234
|
+
*/
|
|
235
|
+
export declare function getModelForTier(provider: string, tier: ModelTier): string | null;
|
|
236
|
+
/**
|
|
237
|
+
* Get cost information (backwards compatible)
|
|
238
|
+
*/
|
|
239
|
+
export declare function getCostInfo(provider: string, model?: string): {
|
|
240
|
+
input: number;
|
|
241
|
+
output: number;
|
|
242
|
+
} | null;
|
|
243
|
+
/**
|
|
244
|
+
* Check provider availability (backwards compatible)
|
|
245
|
+
*/
|
|
246
|
+
export declare function isProviderAvailable(provider: string): boolean;
|