@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.
Files changed (241) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/dist/browser/neurolink.min.js +504 -506
  3. package/dist/cli/commands/setup.d.ts +20 -1
  4. package/dist/cli/commands/setup.js +160 -36
  5. package/dist/cli/factories/commandFactory.d.ts +1157 -1
  6. package/dist/cli/factories/commandFactory.js +20 -53
  7. package/dist/core/baseProvider.js +3 -3
  8. package/dist/core/dynamicModels.d.ts +1 -1
  9. package/dist/core/dynamicModels.js +1 -23
  10. package/dist/core/modelConfiguration.d.ts +1 -70
  11. package/dist/core/modelConfiguration.js +0 -303
  12. package/dist/core/modules/GenerationHandler.js +2 -2
  13. package/dist/core/modules/structuredOutputPolicy.d.ts +2 -2
  14. package/dist/core/modules/structuredOutputPolicy.js +2 -2
  15. package/dist/factories/providerDescriptors.d.ts +18 -0
  16. package/dist/factories/providerDescriptors.js +536 -0
  17. package/dist/factories/providerFactory.d.ts +28 -2
  18. package/dist/factories/providerFactory.js +53 -42
  19. package/dist/factories/providerRegistry.js +33 -32
  20. package/dist/index.d.ts +10 -1
  21. package/dist/index.js +13 -3
  22. package/dist/lib/core/baseProvider.js +3 -3
  23. package/dist/lib/core/dynamicModels.d.ts +1 -1
  24. package/dist/lib/core/dynamicModels.js +1 -23
  25. package/dist/lib/core/modelConfiguration.d.ts +1 -70
  26. package/dist/lib/core/modelConfiguration.js +0 -303
  27. package/dist/lib/core/modules/GenerationHandler.js +2 -2
  28. package/dist/lib/core/modules/structuredOutputPolicy.d.ts +2 -2
  29. package/dist/lib/core/modules/structuredOutputPolicy.js +2 -2
  30. package/dist/lib/factories/providerDescriptors.d.ts +18 -0
  31. package/dist/lib/factories/providerDescriptors.js +537 -0
  32. package/dist/lib/factories/providerFactory.d.ts +28 -2
  33. package/dist/lib/factories/providerFactory.js +53 -42
  34. package/dist/lib/factories/providerRegistry.js +33 -32
  35. package/dist/lib/index.d.ts +10 -1
  36. package/dist/lib/index.js +13 -3
  37. package/dist/lib/models/anthropicModels.d.ts +0 -7
  38. package/dist/lib/models/anthropicModels.js +0 -9
  39. package/dist/lib/neurolink.js +25 -37
  40. package/dist/lib/providers/amazonBedrock/client.js +34 -16
  41. package/dist/lib/providers/anthropic/client.js +39 -34
  42. package/dist/lib/providers/anthropic/constants.d.ts +0 -1
  43. package/dist/lib/providers/anthropic/constants.js +0 -2
  44. package/dist/lib/providers/anthropic/index.d.ts +0 -1
  45. package/dist/lib/providers/anthropic/index.js +0 -1
  46. package/dist/lib/providers/azureOpenai.js +17 -15
  47. package/dist/lib/providers/cloudflare.js +12 -21
  48. package/dist/lib/providers/cohere.js +31 -25
  49. package/dist/lib/providers/deepseek.js +23 -26
  50. package/dist/lib/providers/fireworks.js +12 -21
  51. package/dist/lib/providers/googleAiStudio/client.d.ts +2 -0
  52. package/dist/lib/providers/googleAiStudio/client.js +39 -17
  53. package/dist/lib/providers/googleAiStudio/index.d.ts +0 -1
  54. package/dist/lib/providers/googleAiStudio/index.js +0 -1
  55. package/dist/lib/providers/googleNativeGemini3/index.d.ts +0 -1
  56. package/dist/lib/providers/googleNativeGemini3/index.js +0 -1
  57. package/dist/lib/providers/googleVertex/client.d.ts +0 -51
  58. package/dist/lib/providers/googleVertex/client.js +107 -777
  59. package/dist/lib/providers/groq.js +19 -22
  60. package/dist/lib/providers/huggingFace/client.d.ts +1 -1
  61. package/dist/lib/providers/huggingFace/client.js +27 -25
  62. package/dist/lib/providers/huggingFace/index.d.ts +0 -1
  63. package/dist/lib/providers/huggingFace/index.js +0 -1
  64. package/dist/lib/providers/jina.d.ts +0 -1
  65. package/dist/lib/providers/jina.js +0 -1
  66. package/dist/lib/providers/litellm/client.js +54 -39
  67. package/dist/lib/providers/litellm/index.d.ts +0 -2
  68. package/dist/lib/providers/litellm/index.js +0 -2
  69. package/dist/lib/providers/llamaCpp.d.ts +1 -0
  70. package/dist/lib/providers/llamaCpp.js +24 -18
  71. package/dist/lib/providers/lmStudio.js +25 -42
  72. package/dist/lib/providers/mistral.js +12 -24
  73. package/dist/lib/providers/nvidiaNim/client.js +37 -34
  74. package/dist/lib/providers/nvidiaNim/index.d.ts +0 -1
  75. package/dist/lib/providers/nvidiaNim/index.js +0 -1
  76. package/dist/lib/providers/ollama/client.js +51 -58
  77. package/dist/lib/providers/ollama/index.d.ts +0 -1
  78. package/dist/lib/providers/ollama/index.js +0 -1
  79. package/dist/lib/providers/openAI/client.js +37 -40
  80. package/dist/lib/providers/openAI/index.d.ts +0 -2
  81. package/dist/lib/providers/openAI/index.js +0 -2
  82. package/dist/lib/providers/openRouter/client.js +53 -47
  83. package/dist/lib/providers/openRouter/utils.d.ts +0 -2
  84. package/dist/lib/providers/openRouter/utils.js +0 -12
  85. package/dist/lib/providers/openaiChatCompletionsBase.d.ts +9 -0
  86. package/dist/lib/providers/openaiChatCompletionsBase.js +73 -16
  87. package/dist/lib/providers/openaiCompatible/client.js +36 -32
  88. package/dist/lib/providers/perplexity.d.ts +2 -1
  89. package/dist/lib/providers/perplexity.js +14 -22
  90. package/dist/lib/providers/replicate.d.ts +0 -1
  91. package/dist/lib/providers/replicate.js +22 -9
  92. package/dist/lib/providers/togetherAi.js +12 -21
  93. package/dist/lib/providers/voyage.d.ts +0 -1
  94. package/dist/lib/providers/voyage.js +0 -1
  95. package/dist/lib/providers/xai.js +17 -26
  96. package/dist/lib/server/errors.d.ts +1 -1
  97. package/dist/lib/server/errors.js +2 -2
  98. package/dist/lib/server/index.d.ts +2 -2
  99. package/dist/lib/server/index.js +5 -3
  100. package/dist/lib/server/middleware/rateLimit.d.ts +0 -4
  101. package/dist/lib/server/middleware/rateLimit.js +0 -4
  102. package/dist/lib/types/errors.d.ts +35 -0
  103. package/dist/lib/types/index.d.ts +0 -1
  104. package/dist/lib/types/index.js +0 -1
  105. package/dist/lib/types/providers.d.ts +66 -11
  106. package/dist/lib/utils/errorClassifier.d.ts +30 -0
  107. package/dist/lib/utils/errorClassifier.js +94 -0
  108. package/dist/lib/utils/fileDetector.js +6 -43
  109. package/dist/lib/utils/providerConfig.d.ts +0 -8
  110. package/dist/lib/utils/providerConfig.js +0 -37
  111. package/dist/lib/utils/providerHealth.d.ts +42 -7
  112. package/dist/lib/utils/providerHealth.js +115 -122
  113. package/dist/lib/utils/providerUtils.js +21 -87
  114. package/dist/models/anthropicModels.d.ts +0 -7
  115. package/dist/models/anthropicModels.js +0 -9
  116. package/dist/neurolink.js +25 -37
  117. package/dist/providers/amazonBedrock/client.js +34 -16
  118. package/dist/providers/amazonSagemaker.d.ts +1 -1
  119. package/dist/providers/anthropic/client.js +39 -34
  120. package/dist/providers/anthropic/constants.d.ts +0 -1
  121. package/dist/providers/anthropic/constants.js +0 -2
  122. package/dist/providers/anthropic/index.d.ts +0 -1
  123. package/dist/providers/anthropic/index.js +0 -1
  124. package/dist/providers/azureOpenai.js +17 -15
  125. package/dist/providers/cloudflare.js +12 -21
  126. package/dist/providers/cohere.js +31 -25
  127. package/dist/providers/deepseek.js +23 -26
  128. package/dist/providers/fireworks.js +12 -21
  129. package/dist/providers/googleAiStudio/client.d.ts +2 -0
  130. package/dist/providers/googleAiStudio/client.js +39 -17
  131. package/dist/providers/googleAiStudio/index.d.ts +0 -1
  132. package/dist/providers/googleAiStudio/index.js +0 -1
  133. package/dist/providers/googleNativeGemini3/index.d.ts +0 -1
  134. package/dist/providers/googleNativeGemini3/index.js +0 -1
  135. package/dist/providers/googleVertex/client.d.ts +0 -51
  136. package/dist/providers/googleVertex/client.js +107 -777
  137. package/dist/providers/groq.js +19 -22
  138. package/dist/providers/huggingFace/client.d.ts +1 -1
  139. package/dist/providers/huggingFace/client.js +27 -25
  140. package/dist/providers/huggingFace/index.d.ts +0 -1
  141. package/dist/providers/huggingFace/index.js +0 -1
  142. package/dist/providers/jina.d.ts +0 -1
  143. package/dist/providers/jina.js +0 -1
  144. package/dist/providers/litellm/client.js +54 -39
  145. package/dist/providers/litellm/index.d.ts +0 -2
  146. package/dist/providers/litellm/index.js +0 -2
  147. package/dist/providers/llamaCpp.d.ts +1 -0
  148. package/dist/providers/llamaCpp.js +24 -18
  149. package/dist/providers/lmStudio.js +25 -42
  150. package/dist/providers/mistral.js +12 -24
  151. package/dist/providers/nvidiaNim/client.js +37 -34
  152. package/dist/providers/nvidiaNim/index.d.ts +0 -1
  153. package/dist/providers/nvidiaNim/index.js +0 -1
  154. package/dist/providers/ollama/client.js +51 -58
  155. package/dist/providers/ollama/index.d.ts +0 -1
  156. package/dist/providers/ollama/index.js +0 -1
  157. package/dist/providers/openAI/client.js +37 -40
  158. package/dist/providers/openAI/index.d.ts +0 -2
  159. package/dist/providers/openAI/index.js +0 -2
  160. package/dist/providers/openRouter/client.js +53 -47
  161. package/dist/providers/openRouter/utils.d.ts +0 -2
  162. package/dist/providers/openRouter/utils.js +0 -12
  163. package/dist/providers/openaiChatCompletionsBase.d.ts +9 -0
  164. package/dist/providers/openaiChatCompletionsBase.js +73 -16
  165. package/dist/providers/openaiCompatible/client.js +36 -32
  166. package/dist/providers/perplexity.d.ts +2 -1
  167. package/dist/providers/perplexity.js +14 -22
  168. package/dist/providers/replicate.d.ts +0 -1
  169. package/dist/providers/replicate.js +22 -9
  170. package/dist/providers/sagemaker/language-model.d.ts +2 -2
  171. package/dist/providers/togetherAi.js +12 -21
  172. package/dist/providers/voyage.d.ts +0 -1
  173. package/dist/providers/voyage.js +0 -1
  174. package/dist/providers/xai.js +17 -26
  175. package/dist/server/errors.d.ts +1 -1
  176. package/dist/server/errors.js +2 -2
  177. package/dist/server/index.d.ts +2 -2
  178. package/dist/server/index.js +5 -3
  179. package/dist/server/middleware/rateLimit.d.ts +0 -4
  180. package/dist/server/middleware/rateLimit.js +0 -4
  181. package/dist/types/errors.d.ts +35 -0
  182. package/dist/types/index.d.ts +0 -1
  183. package/dist/types/index.js +0 -1
  184. package/dist/types/providers.d.ts +66 -11
  185. package/dist/utils/errorClassifier.d.ts +30 -0
  186. package/dist/utils/errorClassifier.js +93 -0
  187. package/dist/utils/fileDetector.js +6 -43
  188. package/dist/utils/providerConfig.d.ts +0 -8
  189. package/dist/utils/providerConfig.js +0 -37
  190. package/dist/utils/providerHealth.d.ts +42 -7
  191. package/dist/utils/providerHealth.js +115 -122
  192. package/dist/utils/providerUtils.js +21 -87
  193. package/package.json +21 -75
  194. package/dist/lib/providers/anthropic/utils.d.ts +0 -7
  195. package/dist/lib/providers/anthropic/utils.js +0 -150
  196. package/dist/lib/providers/googleAiStudio/utils.d.ts +0 -2
  197. package/dist/lib/providers/googleAiStudio/utils.js +0 -19
  198. package/dist/lib/providers/googleNativeGemini3/constants.d.ts +0 -1
  199. package/dist/lib/providers/googleNativeGemini3/constants.js +0 -2
  200. package/dist/lib/providers/huggingFace/utils.d.ts +0 -2
  201. package/dist/lib/providers/huggingFace/utils.js +0 -8
  202. package/dist/lib/providers/index.d.ts +0 -33
  203. package/dist/lib/providers/index.js +0 -34
  204. package/dist/lib/providers/litellm/constants.d.ts +0 -1
  205. package/dist/lib/providers/litellm/constants.js +0 -3
  206. package/dist/lib/providers/litellm/utils.d.ts +0 -5
  207. package/dist/lib/providers/litellm/utils.js +0 -11
  208. package/dist/lib/providers/nvidiaNim/utils.d.ts +0 -9
  209. package/dist/lib/providers/nvidiaNim/utils.js +0 -101
  210. package/dist/lib/providers/ollama/utils.d.ts +0 -8
  211. package/dist/lib/providers/ollama/utils.js +0 -43
  212. package/dist/lib/providers/openAI/constants.d.ts +0 -1
  213. package/dist/lib/providers/openAI/constants.js +0 -3
  214. package/dist/lib/providers/openAI/utils.d.ts +0 -2
  215. package/dist/lib/providers/openAI/utils.js +0 -8
  216. package/dist/lib/types/universalProviderOptions.d.ts +0 -89
  217. package/dist/lib/types/universalProviderOptions.js +0 -55
  218. package/dist/providers/anthropic/utils.d.ts +0 -7
  219. package/dist/providers/anthropic/utils.js +0 -149
  220. package/dist/providers/googleAiStudio/utils.d.ts +0 -2
  221. package/dist/providers/googleAiStudio/utils.js +0 -18
  222. package/dist/providers/googleNativeGemini3/constants.d.ts +0 -1
  223. package/dist/providers/googleNativeGemini3/constants.js +0 -1
  224. package/dist/providers/huggingFace/utils.d.ts +0 -2
  225. package/dist/providers/huggingFace/utils.js +0 -7
  226. package/dist/providers/index.d.ts +0 -33
  227. package/dist/providers/index.js +0 -33
  228. package/dist/providers/litellm/constants.d.ts +0 -1
  229. package/dist/providers/litellm/constants.js +0 -2
  230. package/dist/providers/litellm/utils.d.ts +0 -5
  231. package/dist/providers/litellm/utils.js +0 -10
  232. package/dist/providers/nvidiaNim/utils.d.ts +0 -9
  233. package/dist/providers/nvidiaNim/utils.js +0 -100
  234. package/dist/providers/ollama/utils.d.ts +0 -8
  235. package/dist/providers/ollama/utils.js +0 -42
  236. package/dist/providers/openAI/constants.d.ts +0 -1
  237. package/dist/providers/openAI/constants.js +0 -2
  238. package/dist/providers/openAI/utils.d.ts +0 -2
  239. package/dist/providers/openAI/utils.js +0 -7
  240. package/dist/types/universalProviderOptions.d.ts +0 -89
  241. package/dist/types/universalProviderOptions.js +0 -54
@@ -31,6 +31,20 @@ import { formatVideoFileSize, getVideoMetadataSummary, saveVideoToFile, } from "
31
31
  import { OllamaCommandFactory } from "./ollamaCommandFactory.js";
32
32
  import { SageMakerCommandFactory } from "./sagemakerCommandFactory.js";
33
33
  import { AgentCommandFactory } from "../commands/agent.js";
34
+ import { PROVIDER_DESCRIPTORS } from "../../lib/factories/providerDescriptors.js";
35
+ /**
36
+ * Every provider name + alias, derived from PROVIDER_DESCRIPTORS, plus
37
+ * "auto" and the CLI-only "anthropic-subscription" pseudo-provider (not a
38
+ * real AIProviderName — special-cased at runtime to rewrite
39
+ * options.provider to "anthropic").
40
+ */
41
+ const DERIVED_PROVIDER_CHOICES = [
42
+ "auto",
43
+ ...PROVIDER_DESCRIPTORS.flatMap((d) => [d.name, ...d.aliases]),
44
+ "anthropic-subscription",
45
+ ];
46
+ /** Space-separated form for the bash-completion script, kept in sync with DERIVED_PROVIDER_CHOICES by construction. */
47
+ export const BASH_COMPLETION_PROVIDERS = DERIVED_PROVIDER_CHOICES.join(" ");
34
48
  /**
35
49
  * CLI Command Factory for generate commands
36
50
  */
@@ -68,58 +82,7 @@ export class CLICommandFactory {
68
82
  static commonOptions = {
69
83
  // Core generation options
70
84
  provider: {
71
- choices: [
72
- "auto",
73
- "openai",
74
- "openai-compatible",
75
- "openrouter",
76
- "or",
77
- "bedrock",
78
- "vertex",
79
- "googleVertex",
80
- "anthropic",
81
- "anthropic-subscription", // Anthropic with subscription tier support
82
- "azure",
83
- "google-ai",
84
- "google-ai-studio",
85
- "huggingface",
86
- "ollama",
87
- "mistral",
88
- "litellm",
89
- "sagemaker",
90
- "deepseek",
91
- "ds",
92
- "nvidia-nim",
93
- "nim",
94
- "nvidia",
95
- "lm-studio",
96
- "lmstudio",
97
- "lms",
98
- "llamacpp",
99
- "llama.cpp",
100
- "xai",
101
- "grok",
102
- "groq",
103
- "cohere",
104
- "together-ai",
105
- "together",
106
- "fireworks",
107
- "perplexity",
108
- "pplx",
109
- "cloudflare",
110
- "workers-ai",
111
- "cf-ai",
112
- "replicate",
113
- "voyage",
114
- "voyage-ai",
115
- "jina",
116
- "jina-ai",
117
- "stability",
118
- "stability-ai",
119
- "sd",
120
- "ideogram",
121
- "recraft",
122
- ],
85
+ choices: DERIVED_PROVIDER_CHOICES,
123
86
  default: "auto",
124
87
  description: "AI provider to use (auto-selects best available). Use 'anthropic-subscription' for Claude subscription plans.",
125
88
  alias: "p",
@@ -4431,7 +4394,9 @@ export class CLICommandFactory {
4431
4394
  " generate|gen)\n" +
4432
4395
  ' case "${prev}" in\n' +
4433
4396
  " --provider|-p)\n" +
4434
- ' COMPREPLY=( $(compgen -W "auto openai openai-compatible openrouter or bedrock vertex googleVertex anthropic anthropic-subscription azure google-ai google-ai-studio huggingface ollama mistral litellm sagemaker deepseek ds nvidia-nim nim lm-studio lmstudio llamacpp llama.cpp xai grok groq cohere together-ai together fireworks perplexity pplx cloudflare workers-ai cf-ai replicate voyage voyage-ai jina jina-ai stability stability-ai sd ideogram recraft" -- ${cur}) )\n' +
4397
+ ' COMPREPLY=( $(compgen -W "' +
4398
+ BASH_COMPLETION_PROVIDERS +
4399
+ '" -- ${cur}) )\n' +
4435
4400
  " return 0\n" +
4436
4401
  " ;;\n" +
4437
4402
  " --format|-f|--output-format)\n" +
@@ -4561,4 +4526,6 @@ export class CLICommandFactory {
4561
4526
  }
4562
4527
  }
4563
4528
  }
4529
+ /** Re-export of CLICommandFactory's static option definitions for direct import by tests/tooling. */
4530
+ export const commonOptions = CLICommandFactory.commonOptions;
4564
4531
  //# sourceMappingURL=commandFactory.js.map
@@ -1,6 +1,6 @@
1
1
  import { context, SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
2
2
  import { directAgentTools } from "../agent/directTools.js";
3
- import { IMAGE_GENERATION_MODELS } from "../core/constants.js";
3
+ import { isImageGenerationModel } from "../core/constants.js";
4
4
  import { MiddlewareFactory } from "../middleware/factory.js";
5
5
  import { modelSupports } from "../models/modelRegistry.js";
6
6
  import { ATTR, tracers } from "../telemetry/index.js";
@@ -195,7 +195,7 @@ export class BaseProvider {
195
195
  // Skip this path when the caller explicitly requests non-image output (e.g.
196
196
  // JSON analysis) so dual-mode models like gemini-3.1-flash-image-preview
197
197
  // can still perform text/structured generation.
198
- const isImageModel = IMAGE_GENERATION_MODELS.some((m) => this.modelName.includes(m));
198
+ const isImageModel = isImageGenerationModel(this.modelName);
199
199
  const requestsNonImageOutput = options.output?.format === "json" ||
200
200
  options.output?.format === "structured" ||
201
201
  options.output?.format === "text";
@@ -966,7 +966,7 @@ export class BaseProvider {
966
966
  if (options.output?.mode === "video") {
967
967
  return await this.handleVideoGeneration(options, startTime);
968
968
  }
969
- const isImageModel = IMAGE_GENERATION_MODELS.some((m) => this.modelName.includes(m));
969
+ const isImageModel = isImageGenerationModel(this.modelName);
970
970
  const requestsNonImageOutput = options.output?.format === "json" ||
971
971
  options.output?.format === "structured" ||
972
972
  options.output?.format === "text";
@@ -1,4 +1,4 @@
1
- import type { DynamicModelConfig as ModelConfig } from "../types/index.js";
1
+ import { type DynamicModelConfig as ModelConfig } from "../types/index.js";
2
2
  /**
3
3
  * Dynamic Model Provider
4
4
  * Loads and manages model configurations from external sources
@@ -1,28 +1,6 @@
1
- import { z } from "zod";
2
1
  import { isAbortError } from "../utils/errorHandling.js";
3
2
  import { logger } from "../utils/logger.js";
4
- /**
5
- * Model configuration schema for validation
6
- */
7
- const ModelConfigSchema = z.object({
8
- id: z.string(),
9
- displayName: z.string(),
10
- capabilities: z.array(z.string()),
11
- deprecated: z.boolean(),
12
- pricing: z.object({
13
- input: z.number(),
14
- output: z.number(),
15
- }),
16
- contextWindow: z.number(),
17
- releaseDate: z.string(),
18
- });
19
- const ModelRegistrySchema = z.object({
20
- version: z.string(),
21
- lastUpdated: z.string(),
22
- models: z.record(z.string(), z.record(z.string(), ModelConfigSchema)),
23
- aliases: z.record(z.string(), z.string()).optional(),
24
- defaults: z.record(z.string(), z.string()).optional(),
25
- });
3
+ import { ModelRegistrySchema, } from "../types/index.js";
26
4
  /**
27
5
  * Dynamic Model Provider
28
6
  * Loads and manages model configurations from external sources
@@ -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 { ModelTier, ProviderConfiguration, ConfigSource } from "../types/index.js";
7
+ import type { ModelTier, ProviderConfiguration } from "../types/index.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
@@ -153,53 +153,6 @@ export declare class ModelConfigurationManager {
153
153
  * Get all provider configurations
154
154
  */
155
155
  getAllConfigurations(): Map<string, ProviderConfiguration>;
156
- /**
157
- * Update provider configuration (runtime updates)
158
- */
159
- updateProviderConfiguration(provider: string, config: ProviderConfiguration): void;
160
- /**
161
- * Parse YAML content with basic support
162
- * For full YAML support, would need a proper YAML library
163
- */
164
- private parseYAMLContent;
165
- /**
166
- * Convert simple YAML to JSON object
167
- * Handles basic key-value pairs only
168
- */
169
- private convertSimpleYAMLToJSON;
170
- /**
171
- * Process a single YAML line
172
- * Returns key-value pair if valid, null otherwise
173
- */
174
- private processYAMLLine;
175
- /**
176
- * Convert YAML value to appropriate JavaScript type
177
- */
178
- private convertYAMLValue;
179
- /**
180
- * Load configurations from external source
181
- */
182
- loadConfigurationsFromFile(configPath: string): void;
183
- /**
184
- * Validate provider configuration structure
185
- */
186
- private isValidProviderConfiguration;
187
- /**
188
- * Apply model name overrides from configuration file
189
- */
190
- private applyModelNameOverrides;
191
- /**
192
- * Apply global default configurations
193
- */
194
- private applyGlobalDefaults;
195
- /**
196
- * Get configuration metadata
197
- */
198
- getConfigurationMeta(): {
199
- source: ConfigSource;
200
- lastUpdated: number;
201
- providerCount: number;
202
- };
203
156
  /**
204
157
  * Get model for specific tier and provider
205
158
  */
@@ -224,25 +177,3 @@ export declare class ModelConfigurationManager {
224
177
  * Global instance accessor
225
178
  */
226
179
  export declare const modelConfig: ModelConfigurationManager;
227
- /**
228
- * Convenience functions for common operations
229
- */
230
- /**
231
- * Get provider configuration (backwards compatible)
232
- */
233
- export declare function getProviderConfiguration(provider: string): ProviderConfiguration | null;
234
- /**
235
- * Get model for tier (backwards compatible)
236
- */
237
- export declare function getModelForTier(provider: string, tier: ModelTier): string | null;
238
- /**
239
- * Get cost information (backwards compatible)
240
- */
241
- export declare function getCostInfo(provider: string, model?: string): {
242
- input: number;
243
- output: number;
244
- } | null;
245
- /**
246
- * Check provider availability (backwards compatible)
247
- */
248
- export declare function isProviderAvailable(provider: string): boolean;
@@ -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,30 +546,3 @@ 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
- }
@@ -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
- // runs on the third-party @ai-sdk/amazon-bedrock model, which has no such
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 runs on the third-party @ai-sdk/amazon-bedrock model) and still
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 runs on the third-party @ai-sdk/amazon-bedrock model) and still
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>;