@juspay/neurolink 10.12.9 → 11.1.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 +32 -0
- package/dist/browser/neurolink.min.js +504 -506
- package/dist/cli/commands/setup.d.ts +20 -1
- package/dist/cli/commands/setup.js +160 -36
- package/dist/cli/factories/commandFactory.d.ts +1157 -1
- package/dist/cli/factories/commandFactory.js +20 -53
- package/dist/core/baseProvider.js +3 -3
- package/dist/core/dynamicModels.d.ts +1 -1
- package/dist/core/dynamicModels.js +1 -23
- package/dist/core/modelConfiguration.d.ts +1 -70
- package/dist/core/modelConfiguration.js +0 -303
- package/dist/core/modules/GenerationHandler.js +2 -2
- package/dist/core/modules/structuredOutputPolicy.d.ts +2 -2
- package/dist/core/modules/structuredOutputPolicy.js +2 -2
- package/dist/factories/providerDescriptors.d.ts +18 -0
- package/dist/factories/providerDescriptors.js +536 -0
- package/dist/factories/providerFactory.d.ts +28 -2
- package/dist/factories/providerFactory.js +53 -42
- package/dist/factories/providerRegistry.js +33 -32
- package/dist/index.d.ts +10 -1
- package/dist/index.js +13 -3
- package/dist/lib/core/baseProvider.js +3 -3
- package/dist/lib/core/dynamicModels.d.ts +1 -1
- package/dist/lib/core/dynamicModels.js +1 -23
- package/dist/lib/core/modelConfiguration.d.ts +1 -70
- package/dist/lib/core/modelConfiguration.js +0 -303
- package/dist/lib/core/modules/GenerationHandler.js +2 -2
- package/dist/lib/core/modules/structuredOutputPolicy.d.ts +2 -2
- package/dist/lib/core/modules/structuredOutputPolicy.js +2 -2
- package/dist/lib/factories/providerDescriptors.d.ts +18 -0
- package/dist/lib/factories/providerDescriptors.js +537 -0
- package/dist/lib/factories/providerFactory.d.ts +28 -2
- package/dist/lib/factories/providerFactory.js +53 -42
- package/dist/lib/factories/providerRegistry.js +33 -32
- package/dist/lib/index.d.ts +10 -1
- package/dist/lib/index.js +13 -3
- package/dist/lib/models/anthropicModels.d.ts +0 -7
- package/dist/lib/models/anthropicModels.js +0 -9
- package/dist/lib/neurolink.js +25 -37
- package/dist/lib/providers/amazonBedrock/client.js +34 -16
- package/dist/lib/providers/anthropic/client.js +39 -34
- package/dist/lib/providers/anthropic/constants.d.ts +0 -1
- package/dist/lib/providers/anthropic/constants.js +0 -2
- package/dist/lib/providers/anthropic/index.d.ts +0 -1
- package/dist/lib/providers/anthropic/index.js +0 -1
- package/dist/lib/providers/azureOpenai.js +17 -15
- package/dist/lib/providers/cloudflare.js +12 -21
- package/dist/lib/providers/cohere.js +31 -25
- package/dist/lib/providers/deepseek.js +23 -26
- package/dist/lib/providers/fireworks.js +12 -21
- package/dist/lib/providers/googleAiStudio/client.d.ts +2 -0
- package/dist/lib/providers/googleAiStudio/client.js +39 -17
- package/dist/lib/providers/googleAiStudio/index.d.ts +0 -1
- package/dist/lib/providers/googleAiStudio/index.js +0 -1
- package/dist/lib/providers/googleNativeGemini3/index.d.ts +0 -1
- package/dist/lib/providers/googleNativeGemini3/index.js +0 -1
- package/dist/lib/providers/googleVertex/client.d.ts +0 -51
- package/dist/lib/providers/googleVertex/client.js +107 -777
- package/dist/lib/providers/groq.js +19 -22
- package/dist/lib/providers/huggingFace/client.d.ts +1 -1
- package/dist/lib/providers/huggingFace/client.js +27 -25
- package/dist/lib/providers/huggingFace/index.d.ts +0 -1
- package/dist/lib/providers/huggingFace/index.js +0 -1
- package/dist/lib/providers/jina.d.ts +0 -1
- package/dist/lib/providers/jina.js +0 -1
- package/dist/lib/providers/litellm/client.js +54 -39
- package/dist/lib/providers/litellm/index.d.ts +0 -2
- package/dist/lib/providers/litellm/index.js +0 -2
- package/dist/lib/providers/llamaCpp.d.ts +1 -0
- package/dist/lib/providers/llamaCpp.js +24 -18
- package/dist/lib/providers/lmStudio.js +25 -42
- package/dist/lib/providers/mistral.js +12 -24
- package/dist/lib/providers/nvidiaNim/client.js +37 -34
- package/dist/lib/providers/nvidiaNim/index.d.ts +0 -1
- package/dist/lib/providers/nvidiaNim/index.js +0 -1
- package/dist/lib/providers/ollama/client.js +51 -58
- package/dist/lib/providers/ollama/index.d.ts +0 -1
- package/dist/lib/providers/ollama/index.js +0 -1
- package/dist/lib/providers/openAI/client.js +37 -40
- package/dist/lib/providers/openAI/index.d.ts +0 -2
- package/dist/lib/providers/openAI/index.js +0 -2
- package/dist/lib/providers/openRouter/client.js +53 -47
- package/dist/lib/providers/openRouter/utils.d.ts +0 -2
- package/dist/lib/providers/openRouter/utils.js +0 -12
- package/dist/lib/providers/openaiChatCompletionsBase.d.ts +9 -0
- package/dist/lib/providers/openaiChatCompletionsBase.js +73 -16
- package/dist/lib/providers/openaiCompatible/client.js +36 -32
- package/dist/lib/providers/perplexity.d.ts +2 -1
- package/dist/lib/providers/perplexity.js +14 -22
- package/dist/lib/providers/replicate.d.ts +0 -1
- package/dist/lib/providers/replicate.js +22 -9
- package/dist/lib/providers/togetherAi.js +12 -21
- package/dist/lib/providers/voyage.d.ts +0 -1
- package/dist/lib/providers/voyage.js +0 -1
- package/dist/lib/providers/xai.js +17 -26
- package/dist/lib/server/errors.d.ts +1 -1
- package/dist/lib/server/errors.js +2 -2
- package/dist/lib/server/index.d.ts +2 -2
- package/dist/lib/server/index.js +5 -3
- package/dist/lib/server/middleware/rateLimit.d.ts +0 -4
- package/dist/lib/server/middleware/rateLimit.js +0 -4
- package/dist/lib/types/errors.d.ts +35 -0
- package/dist/lib/types/index.d.ts +0 -1
- package/dist/lib/types/index.js +0 -1
- package/dist/lib/types/providers.d.ts +66 -11
- package/dist/lib/utils/errorClassifier.d.ts +30 -0
- package/dist/lib/utils/errorClassifier.js +94 -0
- package/dist/lib/utils/fileDetector.js +6 -43
- package/dist/lib/utils/providerConfig.d.ts +0 -8
- package/dist/lib/utils/providerConfig.js +0 -37
- package/dist/lib/utils/providerHealth.d.ts +42 -7
- package/dist/lib/utils/providerHealth.js +115 -122
- package/dist/lib/utils/providerUtils.js +21 -87
- package/dist/models/anthropicModels.d.ts +0 -7
- package/dist/models/anthropicModels.js +0 -9
- package/dist/neurolink.js +25 -37
- package/dist/providers/amazonBedrock/client.js +34 -16
- package/dist/providers/amazonSagemaker.d.ts +1 -1
- package/dist/providers/anthropic/client.js +39 -34
- package/dist/providers/anthropic/constants.d.ts +0 -1
- package/dist/providers/anthropic/constants.js +0 -2
- package/dist/providers/anthropic/index.d.ts +0 -1
- package/dist/providers/anthropic/index.js +0 -1
- package/dist/providers/azureOpenai.js +17 -15
- package/dist/providers/cloudflare.js +12 -21
- package/dist/providers/cohere.js +31 -25
- package/dist/providers/deepseek.js +23 -26
- package/dist/providers/fireworks.js +12 -21
- package/dist/providers/googleAiStudio/client.d.ts +2 -0
- package/dist/providers/googleAiStudio/client.js +39 -17
- package/dist/providers/googleAiStudio/index.d.ts +0 -1
- package/dist/providers/googleAiStudio/index.js +0 -1
- package/dist/providers/googleNativeGemini3/index.d.ts +0 -1
- package/dist/providers/googleNativeGemini3/index.js +0 -1
- package/dist/providers/googleVertex/client.d.ts +0 -51
- package/dist/providers/googleVertex/client.js +107 -777
- package/dist/providers/groq.js +19 -22
- package/dist/providers/huggingFace/client.d.ts +1 -1
- package/dist/providers/huggingFace/client.js +27 -25
- package/dist/providers/huggingFace/index.d.ts +0 -1
- package/dist/providers/huggingFace/index.js +0 -1
- package/dist/providers/jina.d.ts +0 -1
- package/dist/providers/jina.js +0 -1
- package/dist/providers/litellm/client.js +54 -39
- package/dist/providers/litellm/index.d.ts +0 -2
- package/dist/providers/litellm/index.js +0 -2
- package/dist/providers/llamaCpp.d.ts +1 -0
- package/dist/providers/llamaCpp.js +24 -18
- package/dist/providers/lmStudio.js +25 -42
- package/dist/providers/mistral.js +12 -24
- package/dist/providers/nvidiaNim/client.js +37 -34
- package/dist/providers/nvidiaNim/index.d.ts +0 -1
- package/dist/providers/nvidiaNim/index.js +0 -1
- package/dist/providers/ollama/client.js +51 -58
- package/dist/providers/ollama/index.d.ts +0 -1
- package/dist/providers/ollama/index.js +0 -1
- package/dist/providers/openAI/client.js +37 -40
- package/dist/providers/openAI/index.d.ts +0 -2
- package/dist/providers/openAI/index.js +0 -2
- package/dist/providers/openRouter/client.js +53 -47
- package/dist/providers/openRouter/utils.d.ts +0 -2
- package/dist/providers/openRouter/utils.js +0 -12
- package/dist/providers/openaiChatCompletionsBase.d.ts +9 -0
- package/dist/providers/openaiChatCompletionsBase.js +73 -16
- package/dist/providers/openaiCompatible/client.js +36 -32
- package/dist/providers/perplexity.d.ts +2 -1
- package/dist/providers/perplexity.js +14 -22
- package/dist/providers/replicate.d.ts +0 -1
- package/dist/providers/replicate.js +22 -9
- package/dist/providers/sagemaker/language-model.d.ts +2 -2
- package/dist/providers/togetherAi.js +12 -21
- package/dist/providers/voyage.d.ts +0 -1
- package/dist/providers/voyage.js +0 -1
- package/dist/providers/xai.js +17 -26
- package/dist/server/errors.d.ts +1 -1
- package/dist/server/errors.js +2 -2
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.js +5 -3
- package/dist/server/middleware/rateLimit.d.ts +0 -4
- package/dist/server/middleware/rateLimit.js +0 -4
- package/dist/types/errors.d.ts +35 -0
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.js +0 -1
- package/dist/types/providers.d.ts +66 -11
- package/dist/utils/errorClassifier.d.ts +30 -0
- package/dist/utils/errorClassifier.js +93 -0
- package/dist/utils/fileDetector.js +6 -43
- package/dist/utils/providerConfig.d.ts +0 -8
- package/dist/utils/providerConfig.js +0 -37
- package/dist/utils/providerHealth.d.ts +42 -7
- package/dist/utils/providerHealth.js +115 -122
- package/dist/utils/providerUtils.js +21 -87
- package/package.json +21 -75
- package/dist/lib/providers/anthropic/utils.d.ts +0 -7
- package/dist/lib/providers/anthropic/utils.js +0 -150
- package/dist/lib/providers/googleAiStudio/utils.d.ts +0 -2
- package/dist/lib/providers/googleAiStudio/utils.js +0 -19
- package/dist/lib/providers/googleNativeGemini3/constants.d.ts +0 -1
- package/dist/lib/providers/googleNativeGemini3/constants.js +0 -2
- package/dist/lib/providers/huggingFace/utils.d.ts +0 -2
- package/dist/lib/providers/huggingFace/utils.js +0 -8
- package/dist/lib/providers/index.d.ts +0 -33
- package/dist/lib/providers/index.js +0 -34
- package/dist/lib/providers/litellm/constants.d.ts +0 -1
- package/dist/lib/providers/litellm/constants.js +0 -3
- package/dist/lib/providers/litellm/utils.d.ts +0 -5
- package/dist/lib/providers/litellm/utils.js +0 -11
- package/dist/lib/providers/nvidiaNim/utils.d.ts +0 -9
- package/dist/lib/providers/nvidiaNim/utils.js +0 -101
- package/dist/lib/providers/ollama/utils.d.ts +0 -8
- package/dist/lib/providers/ollama/utils.js +0 -43
- package/dist/lib/providers/openAI/constants.d.ts +0 -1
- package/dist/lib/providers/openAI/constants.js +0 -3
- package/dist/lib/providers/openAI/utils.d.ts +0 -2
- package/dist/lib/providers/openAI/utils.js +0 -8
- package/dist/lib/types/universalProviderOptions.d.ts +0 -89
- package/dist/lib/types/universalProviderOptions.js +0 -55
- package/dist/providers/anthropic/utils.d.ts +0 -7
- package/dist/providers/anthropic/utils.js +0 -149
- package/dist/providers/googleAiStudio/utils.d.ts +0 -2
- package/dist/providers/googleAiStudio/utils.js +0 -18
- package/dist/providers/googleNativeGemini3/constants.d.ts +0 -1
- package/dist/providers/googleNativeGemini3/constants.js +0 -1
- package/dist/providers/huggingFace/utils.d.ts +0 -2
- package/dist/providers/huggingFace/utils.js +0 -7
- package/dist/providers/index.d.ts +0 -33
- package/dist/providers/index.js +0 -33
- package/dist/providers/litellm/constants.d.ts +0 -1
- package/dist/providers/litellm/constants.js +0 -2
- package/dist/providers/litellm/utils.d.ts +0 -5
- package/dist/providers/litellm/utils.js +0 -10
- package/dist/providers/nvidiaNim/utils.d.ts +0 -9
- package/dist/providers/nvidiaNim/utils.js +0 -100
- package/dist/providers/ollama/utils.d.ts +0 -8
- package/dist/providers/ollama/utils.js +0 -42
- package/dist/providers/openAI/constants.d.ts +0 -1
- package/dist/providers/openAI/constants.js +0 -2
- package/dist/providers/openAI/utils.d.ts +0 -2
- package/dist/providers/openAI/utils.js +0 -7
- package/dist/types/universalProviderOptions.d.ts +0 -89
- package/dist/types/universalProviderOptions.js +0 -54
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
* This addresses GitHub Copilot review comment about making model-specific logic configuration-based.
|
|
6
6
|
*/
|
|
7
7
|
import { logger } from "../utils/logger.js";
|
|
8
|
-
import fs from "fs";
|
|
9
|
-
import path from "path";
|
|
10
8
|
/**
|
|
11
9
|
* Model name constants - extracted from hardcoded values for better maintainability
|
|
12
10
|
* These constants can be overridden by environment variables
|
|
@@ -503,280 +501,6 @@ export class ModelConfigurationManager {
|
|
|
503
501
|
getAllConfigurations() {
|
|
504
502
|
return new Map(this.configurations);
|
|
505
503
|
}
|
|
506
|
-
/**
|
|
507
|
-
* Update provider configuration (runtime updates)
|
|
508
|
-
*/
|
|
509
|
-
updateProviderConfiguration(provider, config) {
|
|
510
|
-
this.configurations.set(provider, config);
|
|
511
|
-
this.lastUpdated = Date.now();
|
|
512
|
-
this.configSource = "dynamic";
|
|
513
|
-
logger.debug(`Updated configuration for provider: ${provider}`);
|
|
514
|
-
}
|
|
515
|
-
/**
|
|
516
|
-
* Parse YAML content with basic support
|
|
517
|
-
* For full YAML support, would need a proper YAML library
|
|
518
|
-
*/
|
|
519
|
-
parseYAMLContent(configContent) {
|
|
520
|
-
// Basic YAML parsing for simple configurations
|
|
521
|
-
try {
|
|
522
|
-
return JSON.parse(configContent);
|
|
523
|
-
}
|
|
524
|
-
catch {
|
|
525
|
-
return this.convertSimpleYAMLToJSON(configContent);
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
/**
|
|
529
|
-
* Convert simple YAML to JSON object
|
|
530
|
-
* Handles basic key-value pairs only
|
|
531
|
-
*/
|
|
532
|
-
convertSimpleYAMLToJSON(configContent) {
|
|
533
|
-
const yamlLines = configContent.split("\n");
|
|
534
|
-
const jsonObj = {};
|
|
535
|
-
for (const line of yamlLines) {
|
|
536
|
-
const processedLine = this.processYAMLLine(line);
|
|
537
|
-
if (processedLine) {
|
|
538
|
-
jsonObj[processedLine.key] = processedLine.value;
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
return jsonObj;
|
|
542
|
-
}
|
|
543
|
-
/**
|
|
544
|
-
* Process a single YAML line
|
|
545
|
-
* Returns key-value pair if valid, null otherwise
|
|
546
|
-
*/
|
|
547
|
-
processYAMLLine(line) {
|
|
548
|
-
const trimmedLine = line.trim();
|
|
549
|
-
if (!trimmedLine || trimmedLine.startsWith("#")) {
|
|
550
|
-
return null;
|
|
551
|
-
}
|
|
552
|
-
const colonIndex = trimmedLine.indexOf(":");
|
|
553
|
-
if (colonIndex <= 0) {
|
|
554
|
-
return null;
|
|
555
|
-
}
|
|
556
|
-
const key = trimmedLine.substring(0, colonIndex).trim();
|
|
557
|
-
const value = trimmedLine.substring(colonIndex + 1).trim();
|
|
558
|
-
return {
|
|
559
|
-
key,
|
|
560
|
-
value: this.convertYAMLValue(value),
|
|
561
|
-
};
|
|
562
|
-
}
|
|
563
|
-
/**
|
|
564
|
-
* Convert YAML value to appropriate JavaScript type
|
|
565
|
-
*/
|
|
566
|
-
convertYAMLValue(value) {
|
|
567
|
-
if (value === "true") {
|
|
568
|
-
return true;
|
|
569
|
-
}
|
|
570
|
-
if (value === "false") {
|
|
571
|
-
return false;
|
|
572
|
-
}
|
|
573
|
-
if (!isNaN(Number(value))) {
|
|
574
|
-
return Number(value);
|
|
575
|
-
}
|
|
576
|
-
return value.replace(/['"]/g, "");
|
|
577
|
-
}
|
|
578
|
-
/**
|
|
579
|
-
* Load configurations from external source
|
|
580
|
-
*/
|
|
581
|
-
loadConfigurationsFromFile(configPath) {
|
|
582
|
-
try {
|
|
583
|
-
// Check if file exists
|
|
584
|
-
if (!fs.existsSync(configPath)) {
|
|
585
|
-
throw new Error(`Configuration file not found: ${configPath}`);
|
|
586
|
-
}
|
|
587
|
-
// Read and parse configuration file
|
|
588
|
-
const configContent = fs.readFileSync(configPath, "utf8");
|
|
589
|
-
const fileExtension = path.extname(configPath).toLowerCase();
|
|
590
|
-
let configData;
|
|
591
|
-
if (fileExtension === ".json") {
|
|
592
|
-
configData = JSON.parse(configContent);
|
|
593
|
-
}
|
|
594
|
-
else if (fileExtension === ".yaml" || fileExtension === ".yml") {
|
|
595
|
-
configData = this.parseYAMLContent(configContent);
|
|
596
|
-
}
|
|
597
|
-
else {
|
|
598
|
-
throw new Error(`Unsupported configuration file format: ${fileExtension}. Supported formats: .json, .yaml, .yml`);
|
|
599
|
-
}
|
|
600
|
-
// Validate configuration structure
|
|
601
|
-
if (!configData || typeof configData !== "object") {
|
|
602
|
-
throw new Error("Invalid configuration format: must be an object");
|
|
603
|
-
}
|
|
604
|
-
const config = configData;
|
|
605
|
-
// Load provider configurations from file
|
|
606
|
-
if (config.providers && typeof config.providers === "object") {
|
|
607
|
-
const providers = config.providers;
|
|
608
|
-
for (const [providerName, providerConfig] of Object.entries(providers)) {
|
|
609
|
-
if (this.isValidProviderConfiguration(providerConfig)) {
|
|
610
|
-
this.configurations.set(providerName, providerConfig);
|
|
611
|
-
logger.debug(`Loaded configuration for provider: ${providerName}`);
|
|
612
|
-
}
|
|
613
|
-
else {
|
|
614
|
-
logger.warn(`Invalid configuration for provider: ${providerName}, skipping`);
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
// Load global model name overrides
|
|
619
|
-
if (config.modelNames && typeof config.modelNames === "object") {
|
|
620
|
-
const modelNames = config.modelNames;
|
|
621
|
-
this.applyModelNameOverrides(modelNames);
|
|
622
|
-
}
|
|
623
|
-
// Load global defaults
|
|
624
|
-
if (config.defaults && typeof config.defaults === "object") {
|
|
625
|
-
const defaults = config.defaults;
|
|
626
|
-
this.applyGlobalDefaults(defaults);
|
|
627
|
-
}
|
|
628
|
-
this.configSource = "file";
|
|
629
|
-
this.lastUpdated = Date.now();
|
|
630
|
-
logger.info(`Successfully loaded configurations from file: ${configPath}`);
|
|
631
|
-
logger.debug(`Loaded ${this.configurations.size} provider configurations`);
|
|
632
|
-
}
|
|
633
|
-
catch (error) {
|
|
634
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
635
|
-
logger.error(`Failed to load configurations from file: ${errorMessage}`);
|
|
636
|
-
throw new Error(`Configuration loading failed: ${errorMessage}`, {
|
|
637
|
-
cause: error,
|
|
638
|
-
});
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
/**
|
|
642
|
-
* Validate provider configuration structure
|
|
643
|
-
*/
|
|
644
|
-
isValidProviderConfiguration(config) {
|
|
645
|
-
if (!config || typeof config !== "object") {
|
|
646
|
-
return false;
|
|
647
|
-
}
|
|
648
|
-
const providerConfig = config;
|
|
649
|
-
// Check required fields
|
|
650
|
-
const requiredFields = [
|
|
651
|
-
"provider",
|
|
652
|
-
"models",
|
|
653
|
-
"defaultCost",
|
|
654
|
-
"requiredEnvVars",
|
|
655
|
-
"performance",
|
|
656
|
-
];
|
|
657
|
-
for (const field of requiredFields) {
|
|
658
|
-
if (!(field in providerConfig)) {
|
|
659
|
-
return false;
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
// Validate models structure
|
|
663
|
-
if (typeof providerConfig.models !== "object" || !providerConfig.models) {
|
|
664
|
-
return false;
|
|
665
|
-
}
|
|
666
|
-
const models = providerConfig.models;
|
|
667
|
-
const requiredTiers = ["fast", "balanced", "quality"];
|
|
668
|
-
for (const tier of requiredTiers) {
|
|
669
|
-
if (typeof models[tier] !== "string") {
|
|
670
|
-
return false;
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
// Validate defaultCost structure
|
|
674
|
-
if (typeof providerConfig.defaultCost !== "object" ||
|
|
675
|
-
!providerConfig.defaultCost) {
|
|
676
|
-
return false;
|
|
677
|
-
}
|
|
678
|
-
const defaultCost = providerConfig.defaultCost;
|
|
679
|
-
if (typeof defaultCost.input !== "number" ||
|
|
680
|
-
typeof defaultCost.output !== "number") {
|
|
681
|
-
return false;
|
|
682
|
-
}
|
|
683
|
-
// Validate requiredEnvVars
|
|
684
|
-
if (!Array.isArray(providerConfig.requiredEnvVars)) {
|
|
685
|
-
return false;
|
|
686
|
-
}
|
|
687
|
-
// Validate performance structure
|
|
688
|
-
if (typeof providerConfig.performance !== "object" ||
|
|
689
|
-
!providerConfig.performance) {
|
|
690
|
-
return false;
|
|
691
|
-
}
|
|
692
|
-
const performance = providerConfig.performance;
|
|
693
|
-
const perfFields = ["speed", "quality", "cost"];
|
|
694
|
-
for (const field of perfFields) {
|
|
695
|
-
if (typeof performance[field] !== "number") {
|
|
696
|
-
return false;
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
return true;
|
|
700
|
-
}
|
|
701
|
-
/**
|
|
702
|
-
* Apply model name overrides from configuration file
|
|
703
|
-
*/
|
|
704
|
-
applyModelNameOverrides(modelNames) {
|
|
705
|
-
try {
|
|
706
|
-
// Apply overrides to existing configurations
|
|
707
|
-
for (const [providerKey, providerModels] of Object.entries(modelNames)) {
|
|
708
|
-
if (typeof providerModels === "object" && providerModels) {
|
|
709
|
-
const models = providerModels;
|
|
710
|
-
const existingConfig = this.configurations.get(providerKey);
|
|
711
|
-
if (existingConfig) {
|
|
712
|
-
// Update existing configuration
|
|
713
|
-
for (const [tier, model] of Object.entries(models)) {
|
|
714
|
-
if (typeof model === "string" &&
|
|
715
|
-
["fast", "balanced", "quality"].includes(tier)) {
|
|
716
|
-
existingConfig.models[tier] = model;
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
this.configurations.set(providerKey, existingConfig);
|
|
720
|
-
logger.debug(`Applied model name overrides for provider: ${providerKey}`);
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
catch (error) {
|
|
726
|
-
logger.warn(`Failed to apply model name overrides: ${error instanceof Error ? error.message : String(error)}`);
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
/**
|
|
730
|
-
* Apply global default configurations
|
|
731
|
-
*/
|
|
732
|
-
applyGlobalDefaults(defaults) {
|
|
733
|
-
try {
|
|
734
|
-
// Apply global defaults to all existing configurations
|
|
735
|
-
for (const [providerName, config] of this.configurations.entries()) {
|
|
736
|
-
let updated = false;
|
|
737
|
-
// Apply default cost overrides
|
|
738
|
-
if (defaults.defaultCost && typeof defaults.defaultCost === "object") {
|
|
739
|
-
const defaultCost = defaults.defaultCost;
|
|
740
|
-
if (typeof defaultCost.input === "number") {
|
|
741
|
-
config.defaultCost.input = defaultCost.input;
|
|
742
|
-
updated = true;
|
|
743
|
-
}
|
|
744
|
-
if (typeof defaultCost.output === "number") {
|
|
745
|
-
config.defaultCost.output = defaultCost.output;
|
|
746
|
-
updated = true;
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
// Apply performance overrides
|
|
750
|
-
if (defaults.performance && typeof defaults.performance === "object") {
|
|
751
|
-
const performance = defaults.performance;
|
|
752
|
-
["speed", "quality", "cost"].forEach((field) => {
|
|
753
|
-
if (typeof performance[field] === "number") {
|
|
754
|
-
config.performance[field] =
|
|
755
|
-
performance[field];
|
|
756
|
-
updated = true;
|
|
757
|
-
}
|
|
758
|
-
});
|
|
759
|
-
}
|
|
760
|
-
if (updated) {
|
|
761
|
-
this.configurations.set(providerName, config);
|
|
762
|
-
logger.debug(`Applied global defaults to provider: ${providerName}`);
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
catch (error) {
|
|
767
|
-
logger.warn(`Failed to apply global defaults: ${error instanceof Error ? error.message : String(error)}`);
|
|
768
|
-
}
|
|
769
|
-
}
|
|
770
|
-
/**
|
|
771
|
-
* Get configuration metadata
|
|
772
|
-
*/
|
|
773
|
-
getConfigurationMeta() {
|
|
774
|
-
return {
|
|
775
|
-
source: this.configSource,
|
|
776
|
-
lastUpdated: this.lastUpdated,
|
|
777
|
-
providerCount: this.configurations.size,
|
|
778
|
-
};
|
|
779
|
-
}
|
|
780
504
|
/**
|
|
781
505
|
* Get model for specific tier and provider
|
|
782
506
|
*/
|
|
@@ -822,31 +546,4 @@ export class ModelConfigurationManager {
|
|
|
822
546
|
* Global instance accessor
|
|
823
547
|
*/
|
|
824
548
|
export const modelConfig = ModelConfigurationManager.getInstance();
|
|
825
|
-
/**
|
|
826
|
-
* Convenience functions for common operations
|
|
827
|
-
*/
|
|
828
|
-
/**
|
|
829
|
-
* Get provider configuration (backwards compatible)
|
|
830
|
-
*/
|
|
831
|
-
export function getProviderConfiguration(provider) {
|
|
832
|
-
return modelConfig.getProviderConfiguration(provider);
|
|
833
|
-
}
|
|
834
|
-
/**
|
|
835
|
-
* Get model for tier (backwards compatible)
|
|
836
|
-
*/
|
|
837
|
-
export function getModelForTier(provider, tier) {
|
|
838
|
-
return modelConfig.getModelForTier(provider, tier);
|
|
839
|
-
}
|
|
840
|
-
/**
|
|
841
|
-
* Get cost information (backwards compatible)
|
|
842
|
-
*/
|
|
843
|
-
export function getCostInfo(provider, model) {
|
|
844
|
-
return modelConfig.getCostInfo(provider, model);
|
|
845
|
-
}
|
|
846
|
-
/**
|
|
847
|
-
* Check provider availability (backwards compatible)
|
|
848
|
-
*/
|
|
849
|
-
export function isProviderAvailable(provider) {
|
|
850
|
-
return modelConfig.isProviderAvailable(provider);
|
|
851
|
-
}
|
|
852
549
|
//# sourceMappingURL=modelConfiguration.js.map
|
|
@@ -247,8 +247,8 @@ export class GenerationHandler {
|
|
|
247
247
|
// JSON Schema to the provider instead: it appends an additive
|
|
248
248
|
// `final_result` tool and returns the answer as that tool's arguments,
|
|
249
249
|
// keeping the real tools callable. Bedrock is deliberately excluded — it
|
|
250
|
-
//
|
|
251
|
-
// handling.
|
|
250
|
+
// talks to the raw AWS SDK directly, not an ai-sdk provider package, and
|
|
251
|
+
// has no such handling.
|
|
252
252
|
const finalResultSchema = this.providerName === "anthropic" &&
|
|
253
253
|
!!options.schema &&
|
|
254
254
|
shouldUseTools &&
|
|
@@ -29,8 +29,8 @@ export declare function isGeminiProvider(providerName: string, modelName: string
|
|
|
29
29
|
* `providerOptions.anthropic.finalResultSchema`, and the provider appends an
|
|
30
30
|
* additive `final_result` tool (see providers/anthropic/structuredOutput.ts) —
|
|
31
31
|
* schema enforcement without giving up tool calling. "bedrock" has no such
|
|
32
|
-
* handling (it
|
|
33
|
-
* falls back to text-mode coercion.
|
|
32
|
+
* handling (it talks to the raw AWS SDK directly, not an ai-sdk provider
|
|
33
|
+
* package) and still falls back to text-mode coercion.
|
|
34
34
|
*/
|
|
35
35
|
export declare function isNativeAnthropicProvider(providerName: string): boolean;
|
|
36
36
|
/**
|
|
@@ -39,8 +39,8 @@ export function isGeminiProvider(providerName, modelName) {
|
|
|
39
39
|
* `providerOptions.anthropic.finalResultSchema`, and the provider appends an
|
|
40
40
|
* additive `final_result` tool (see providers/anthropic/structuredOutput.ts) —
|
|
41
41
|
* schema enforcement without giving up tool calling. "bedrock" has no such
|
|
42
|
-
* handling (it
|
|
43
|
-
* falls back to text-mode coercion.
|
|
42
|
+
* handling (it talks to the raw AWS SDK directly, not an ai-sdk provider
|
|
43
|
+
* package) and still falls back to text-mode coercion.
|
|
44
44
|
*/
|
|
45
45
|
export function isNativeAnthropicProvider(providerName) {
|
|
46
46
|
return providerName === "anthropic" || providerName === "bedrock";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AIProviderName } from "../constants/enums.js";
|
|
2
|
+
import type { ProviderDescriptor } from "../types/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Single source of truth for provider identity, credentials, defaults, and
|
|
5
|
+
* runtime behavior classification. Pure data — no provider-class imports,
|
|
6
|
+
* no dynamic import(), no side effects beyond building the two derived
|
|
7
|
+
* lookup maps below. Order follows the AIProviderName enum declaration
|
|
8
|
+
* order (enums.ts:8-40) so this file stays easy to diff against it.
|
|
9
|
+
*/
|
|
10
|
+
export declare const PROVIDER_DESCRIPTORS: readonly ProviderDescriptor[];
|
|
11
|
+
/** O(1) canonical-name → descriptor lookup. */
|
|
12
|
+
export declare const PROVIDER_DESCRIPTORS_BY_NAME: ReadonlyMap<AIProviderName, ProviderDescriptor>;
|
|
13
|
+
/**
|
|
14
|
+
* O(1) alias → canonical-name lookup, covering both `aliases` and each
|
|
15
|
+
* descriptor's own lowercased `name`. Replaces the O(n) linear scan in
|
|
16
|
+
* ProviderFactory.normalizeProviderName().
|
|
17
|
+
*/
|
|
18
|
+
export declare const PROVIDER_ALIAS_INDEX: ReadonlyMap<string, AIProviderName>;
|