@juspay/neurolink 10.12.8 → 11.0.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 (179) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/dist/browser/neurolink.min.js +399 -401
  3. package/dist/cli/commands/setup.d.ts +16 -1
  4. package/dist/cli/commands/setup.js +141 -3
  5. package/dist/core/baseProvider.js +3 -3
  6. package/dist/core/dynamicModels.d.ts +1 -1
  7. package/dist/core/dynamicModels.js +1 -23
  8. package/dist/core/modelConfiguration.d.ts +1 -70
  9. package/dist/core/modelConfiguration.js +0 -303
  10. package/dist/core/modules/GenerationHandler.js +38 -16
  11. package/dist/core/modules/structuredOutputPolicy.d.ts +2 -2
  12. package/dist/core/modules/structuredOutputPolicy.js +2 -2
  13. package/dist/factories/providerFactory.d.ts +15 -0
  14. package/dist/factories/providerFactory.js +27 -39
  15. package/dist/factories/providerRegistry.js +2 -2
  16. package/dist/lib/core/baseProvider.js +3 -3
  17. package/dist/lib/core/dynamicModels.d.ts +1 -1
  18. package/dist/lib/core/dynamicModels.js +1 -23
  19. package/dist/lib/core/modelConfiguration.d.ts +1 -70
  20. package/dist/lib/core/modelConfiguration.js +0 -303
  21. package/dist/lib/core/modules/GenerationHandler.js +38 -16
  22. package/dist/lib/core/modules/structuredOutputPolicy.d.ts +2 -2
  23. package/dist/lib/core/modules/structuredOutputPolicy.js +2 -2
  24. package/dist/lib/factories/providerFactory.d.ts +15 -0
  25. package/dist/lib/factories/providerFactory.js +27 -39
  26. package/dist/lib/factories/providerRegistry.js +2 -2
  27. package/dist/lib/models/anthropicModels.d.ts +0 -7
  28. package/dist/lib/models/anthropicModels.js +0 -9
  29. package/dist/lib/neurolink.d.ts +15 -0
  30. package/dist/lib/neurolink.js +77 -44
  31. package/dist/lib/providers/anthropic/client.js +17 -1
  32. package/dist/lib/providers/anthropic/constants.d.ts +0 -1
  33. package/dist/lib/providers/anthropic/constants.js +0 -2
  34. package/dist/lib/providers/anthropic/index.d.ts +0 -1
  35. package/dist/lib/providers/anthropic/index.js +0 -1
  36. package/dist/lib/providers/googleAiStudio/index.d.ts +0 -1
  37. package/dist/lib/providers/googleAiStudio/index.js +0 -1
  38. package/dist/lib/providers/googleNativeGemini3/index.d.ts +0 -1
  39. package/dist/lib/providers/googleNativeGemini3/index.js +0 -1
  40. package/dist/lib/providers/googleVertex/client.d.ts +0 -51
  41. package/dist/lib/providers/googleVertex/client.js +0 -678
  42. package/dist/lib/providers/huggingFace/client.d.ts +1 -1
  43. package/dist/lib/providers/huggingFace/client.js +1 -1
  44. package/dist/lib/providers/huggingFace/index.d.ts +0 -1
  45. package/dist/lib/providers/huggingFace/index.js +0 -1
  46. package/dist/lib/providers/jina.d.ts +0 -1
  47. package/dist/lib/providers/jina.js +0 -1
  48. package/dist/lib/providers/litellm/index.d.ts +0 -2
  49. package/dist/lib/providers/litellm/index.js +0 -2
  50. package/dist/lib/providers/llamaCpp.d.ts +1 -0
  51. package/dist/lib/providers/llamaCpp.js +3 -0
  52. package/dist/lib/providers/lmStudio.js +3 -23
  53. package/dist/lib/providers/nvidiaNim/index.d.ts +0 -1
  54. package/dist/lib/providers/nvidiaNim/index.js +0 -1
  55. package/dist/lib/providers/ollama/client.js +1 -23
  56. package/dist/lib/providers/ollama/index.d.ts +0 -1
  57. package/dist/lib/providers/ollama/index.js +0 -1
  58. package/dist/lib/providers/openAI/index.d.ts +0 -2
  59. package/dist/lib/providers/openAI/index.js +0 -2
  60. package/dist/lib/providers/openRouter/utils.d.ts +0 -2
  61. package/dist/lib/providers/openRouter/utils.js +0 -12
  62. package/dist/lib/providers/openaiChatCompletionsBase.d.ts +9 -0
  63. package/dist/lib/providers/openaiChatCompletionsBase.js +33 -0
  64. package/dist/lib/providers/perplexity.d.ts +2 -1
  65. package/dist/lib/providers/perplexity.js +2 -1
  66. package/dist/lib/providers/replicate.d.ts +0 -1
  67. package/dist/lib/providers/replicate.js +22 -9
  68. package/dist/lib/providers/voyage.d.ts +0 -1
  69. package/dist/lib/providers/voyage.js +0 -1
  70. package/dist/lib/types/index.d.ts +0 -1
  71. package/dist/lib/types/index.js +0 -1
  72. package/dist/lib/types/providers.d.ts +2 -11
  73. package/dist/lib/types/utilities.d.ts +29 -0
  74. package/dist/lib/utils/json/coerce.d.ts +21 -1
  75. package/dist/lib/utils/json/coerce.js +148 -11
  76. package/dist/lib/utils/providerConfig.d.ts +0 -8
  77. package/dist/lib/utils/providerConfig.js +0 -37
  78. package/dist/lib/utils/providerUtils.js +1 -25
  79. package/dist/models/anthropicModels.d.ts +0 -7
  80. package/dist/models/anthropicModels.js +0 -9
  81. package/dist/neurolink.d.ts +15 -0
  82. package/dist/neurolink.js +77 -44
  83. package/dist/providers/anthropic/client.js +17 -1
  84. package/dist/providers/anthropic/constants.d.ts +0 -1
  85. package/dist/providers/anthropic/constants.js +0 -2
  86. package/dist/providers/anthropic/index.d.ts +0 -1
  87. package/dist/providers/anthropic/index.js +0 -1
  88. package/dist/providers/googleAiStudio/index.d.ts +0 -1
  89. package/dist/providers/googleAiStudio/index.js +0 -1
  90. package/dist/providers/googleNativeGemini3/index.d.ts +0 -1
  91. package/dist/providers/googleNativeGemini3/index.js +0 -1
  92. package/dist/providers/googleVertex/client.d.ts +0 -51
  93. package/dist/providers/googleVertex/client.js +0 -678
  94. package/dist/providers/huggingFace/client.d.ts +1 -1
  95. package/dist/providers/huggingFace/client.js +1 -1
  96. package/dist/providers/huggingFace/index.d.ts +0 -1
  97. package/dist/providers/huggingFace/index.js +0 -1
  98. package/dist/providers/jina.d.ts +0 -1
  99. package/dist/providers/jina.js +0 -1
  100. package/dist/providers/litellm/index.d.ts +0 -2
  101. package/dist/providers/litellm/index.js +0 -2
  102. package/dist/providers/llamaCpp.d.ts +1 -0
  103. package/dist/providers/llamaCpp.js +3 -0
  104. package/dist/providers/lmStudio.js +3 -23
  105. package/dist/providers/nvidiaNim/index.d.ts +0 -1
  106. package/dist/providers/nvidiaNim/index.js +0 -1
  107. package/dist/providers/ollama/client.js +1 -23
  108. package/dist/providers/ollama/index.d.ts +0 -1
  109. package/dist/providers/ollama/index.js +0 -1
  110. package/dist/providers/openAI/index.d.ts +0 -2
  111. package/dist/providers/openAI/index.js +0 -2
  112. package/dist/providers/openRouter/utils.d.ts +0 -2
  113. package/dist/providers/openRouter/utils.js +0 -12
  114. package/dist/providers/openaiChatCompletionsBase.d.ts +9 -0
  115. package/dist/providers/openaiChatCompletionsBase.js +33 -0
  116. package/dist/providers/perplexity.d.ts +2 -1
  117. package/dist/providers/perplexity.js +2 -1
  118. package/dist/providers/replicate.d.ts +0 -1
  119. package/dist/providers/replicate.js +22 -9
  120. package/dist/providers/voyage.d.ts +0 -1
  121. package/dist/providers/voyage.js +0 -1
  122. package/dist/types/index.d.ts +0 -1
  123. package/dist/types/index.js +0 -1
  124. package/dist/types/providers.d.ts +2 -11
  125. package/dist/types/utilities.d.ts +29 -0
  126. package/dist/utils/json/coerce.d.ts +21 -1
  127. package/dist/utils/json/coerce.js +148 -11
  128. package/dist/utils/providerConfig.d.ts +0 -8
  129. package/dist/utils/providerConfig.js +0 -37
  130. package/dist/utils/providerUtils.js +1 -25
  131. package/package.json +8 -6
  132. package/dist/lib/providers/anthropic/utils.d.ts +0 -7
  133. package/dist/lib/providers/anthropic/utils.js +0 -150
  134. package/dist/lib/providers/googleAiStudio/utils.d.ts +0 -2
  135. package/dist/lib/providers/googleAiStudio/utils.js +0 -19
  136. package/dist/lib/providers/googleNativeGemini3/constants.d.ts +0 -1
  137. package/dist/lib/providers/googleNativeGemini3/constants.js +0 -2
  138. package/dist/lib/providers/huggingFace/utils.d.ts +0 -2
  139. package/dist/lib/providers/huggingFace/utils.js +0 -8
  140. package/dist/lib/providers/index.d.ts +0 -33
  141. package/dist/lib/providers/index.js +0 -34
  142. package/dist/lib/providers/litellm/constants.d.ts +0 -1
  143. package/dist/lib/providers/litellm/constants.js +0 -3
  144. package/dist/lib/providers/litellm/utils.d.ts +0 -5
  145. package/dist/lib/providers/litellm/utils.js +0 -11
  146. package/dist/lib/providers/nvidiaNim/utils.d.ts +0 -9
  147. package/dist/lib/providers/nvidiaNim/utils.js +0 -101
  148. package/dist/lib/providers/ollama/utils.d.ts +0 -8
  149. package/dist/lib/providers/ollama/utils.js +0 -43
  150. package/dist/lib/providers/openAI/constants.d.ts +0 -1
  151. package/dist/lib/providers/openAI/constants.js +0 -3
  152. package/dist/lib/providers/openAI/utils.d.ts +0 -2
  153. package/dist/lib/providers/openAI/utils.js +0 -8
  154. package/dist/lib/types/universalProviderOptions.d.ts +0 -89
  155. package/dist/lib/types/universalProviderOptions.js +0 -55
  156. package/dist/providers/anthropic/utils.d.ts +0 -7
  157. package/dist/providers/anthropic/utils.js +0 -149
  158. package/dist/providers/googleAiStudio/utils.d.ts +0 -2
  159. package/dist/providers/googleAiStudio/utils.js +0 -18
  160. package/dist/providers/googleNativeGemini3/constants.d.ts +0 -1
  161. package/dist/providers/googleNativeGemini3/constants.js +0 -1
  162. package/dist/providers/huggingFace/utils.d.ts +0 -2
  163. package/dist/providers/huggingFace/utils.js +0 -7
  164. package/dist/providers/index.d.ts +0 -33
  165. package/dist/providers/index.js +0 -33
  166. package/dist/providers/litellm/constants.d.ts +0 -1
  167. package/dist/providers/litellm/constants.js +0 -2
  168. package/dist/providers/litellm/utils.d.ts +0 -5
  169. package/dist/providers/litellm/utils.js +0 -10
  170. package/dist/providers/nvidiaNim/utils.d.ts +0 -9
  171. package/dist/providers/nvidiaNim/utils.js +0 -100
  172. package/dist/providers/ollama/utils.d.ts +0 -8
  173. package/dist/providers/ollama/utils.js +0 -42
  174. package/dist/providers/openAI/constants.d.ts +0 -1
  175. package/dist/providers/openAI/constants.js +0 -2
  176. package/dist/providers/openAI/utils.d.ts +0 -2
  177. package/dist/providers/openAI/utils.js +0 -7
  178. package/dist/types/universalProviderOptions.d.ts +0 -89
  179. package/dist/types/universalProviderOptions.js +0 -54
@@ -5,8 +5,23 @@
5
5
  * Provides a beautiful welcome experience for new users and guided
6
6
  * provider selection, while delegating to existing setup commands.
7
7
  */
8
- import type { SetupArgs } from "../../lib/types/index.js";
8
+ import type { ProviderConfigOptions, SetupArgs } from "../../lib/types/index.js";
9
+ /**
10
+ * ProviderConfigOptions for the 21 canonical AIProviderName values the
11
+ * interactive wizard above doesn't have a bespoke handleXSetup() for. 16
12
+ * reuse the existing createXConfig() factories in providerConfig.ts; the
13
+ * remaining 5 (ollama, litellm, sagemaker, lm-studio, llamacpp) don't have a
14
+ * factory and are defined inline using their real env var names. lm-studio
15
+ * and llamacpp previously had createLmStudioConfig()/createLlamaCppConfig()
16
+ * factories, but those were removed as dead code in a later cleanup — this
17
+ * mirrors that removal rather than re-adding them.
18
+ */
19
+ export declare const EXTRA_PROVIDER_CONFIGS: Record<string, ProviderConfigOptions>;
9
20
  /**
10
21
  * Main setup command handler
11
22
  */
12
23
  export declare function handleSetup(argv: SetupArgs): Promise<void>;
24
+ /**
25
+ * Delegate to existing provider setup commands
26
+ */
27
+ export declare function delegateToProviderSetup(providerId: string): Promise<void>;
@@ -19,6 +19,7 @@ import { handleBedrockSetup } from "./setup-bedrock.js";
19
19
  import { handleGCPSetup } from "./setup-gcp.js";
20
20
  import { handleHuggingFaceSetup } from "./setup-huggingface.js";
21
21
  import { handleMistralSetup } from "./setup-mistral.js";
22
+ import { createCloudflareConfig, createCohereConfig, createDeepSeekConfig, createFireworksConfig, createGroqConfig, createIdeogramConfig, createJinaConfig, createNvidiaNimConfig, createOpenAICompatibleConfig, createPerplexityConfig, createRecraftConfig, createReplicateConfig, createStabilityConfig, createTogetherAIConfig, createVoyageConfig, createXaiConfig, } from "../../lib/utils/providerConfig.js";
22
23
  // Provider information database
23
24
  const PROVIDERS = [
24
25
  {
@@ -139,6 +140,137 @@ const PROVIDERS = [
139
140
  setupCommand: "neurolink setup --provider openrouter",
140
141
  },
141
142
  ];
143
+ /**
144
+ * ProviderConfigOptions for the 21 canonical AIProviderName values the
145
+ * interactive wizard above doesn't have a bespoke handleXSetup() for. 16
146
+ * reuse the existing createXConfig() factories in providerConfig.ts; the
147
+ * remaining 5 (ollama, litellm, sagemaker, lm-studio, llamacpp) don't have a
148
+ * factory and are defined inline using their real env var names. lm-studio
149
+ * and llamacpp previously had createLmStudioConfig()/createLlamaCppConfig()
150
+ * factories, but those were removed as dead code in a later cleanup — this
151
+ * mirrors that removal rather than re-adding them.
152
+ */
153
+ export const EXTRA_PROVIDER_CONFIGS = {
154
+ "openai-compatible": createOpenAICompatibleConfig(),
155
+ deepseek: createDeepSeekConfig(),
156
+ "nvidia-nim": createNvidiaNimConfig(),
157
+ xai: createXaiConfig(),
158
+ groq: createGroqConfig(),
159
+ cohere: createCohereConfig(),
160
+ replicate: createReplicateConfig(),
161
+ "together-ai": createTogetherAIConfig(),
162
+ fireworks: createFireworksConfig(),
163
+ perplexity: createPerplexityConfig(),
164
+ voyage: createVoyageConfig(),
165
+ jina: createJinaConfig(),
166
+ stability: createStabilityConfig(),
167
+ ideogram: createIdeogramConfig(),
168
+ recraft: createRecraftConfig(),
169
+ cloudflare: createCloudflareConfig(),
170
+ ollama: {
171
+ providerName: "Ollama",
172
+ envVarName: "OLLAMA_BASE_URL",
173
+ setupUrl: "https://ollama.com/download",
174
+ description: "Run open-source models locally via Ollama's OpenAI-compatible API.",
175
+ instructions: [
176
+ "Install Ollama from https://ollama.com/download",
177
+ "Pull a model: ollama pull llama3.1",
178
+ "Ollama serves its API at http://localhost:11434 by default — set OLLAMA_BASE_URL only to override.",
179
+ "Optionally set OLLAMA_MODEL to choose the default model.",
180
+ ],
181
+ optional: true,
182
+ },
183
+ litellm: {
184
+ providerName: "LiteLLM",
185
+ envVarName: "LITELLM_API_KEY",
186
+ setupUrl: "https://docs.litellm.ai/docs/simple_proxy",
187
+ description: "Route through a LiteLLM proxy server for unified access to 100+ upstream providers.",
188
+ instructions: [
189
+ "Start a LiteLLM proxy server (see https://docs.litellm.ai/docs/simple_proxy).",
190
+ "Set LITELLM_BASE_URL to the proxy's URL (defaults to http://localhost:4000).",
191
+ "Set LITELLM_API_KEY to the proxy's virtual key (defaults to a permissive placeholder for local proxies without auth).",
192
+ ],
193
+ fallbackEnvVars: ["LITELLM_BASE_URL"],
194
+ optional: true,
195
+ },
196
+ sagemaker: {
197
+ providerName: "Amazon SageMaker",
198
+ envVarName: "SAGEMAKER_ENDPOINT_NAME",
199
+ setupUrl: "https://docs.aws.amazon.com/sagemaker/latest/dg/realtime-endpoints.html",
200
+ description: "Invoke a self-hosted model on an Amazon SageMaker real-time inference endpoint.",
201
+ instructions: [
202
+ "Deploy a model to a SageMaker real-time endpoint (see AWS docs above).",
203
+ "Set SAGEMAKER_ENDPOINT_NAME to the deployed endpoint's name.",
204
+ "Set SAGEMAKER_REGION to the AWS region hosting the endpoint.",
205
+ "Set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY (or use an AWS credential provider chain) for authentication.",
206
+ ],
207
+ fallbackEnvVars: [
208
+ "SAGEMAKER_REGION",
209
+ "AWS_ACCESS_KEY_ID",
210
+ "AWS_SECRET_ACCESS_KEY",
211
+ ],
212
+ optional: false,
213
+ },
214
+ "lm-studio": {
215
+ providerName: "LM Studio",
216
+ envVarName: "LM_STUDIO_BASE_URL",
217
+ setupUrl: "https://lmstudio.ai/",
218
+ description: "Run open-source models locally via LM Studio's OpenAI-compatible API.",
219
+ instructions: [
220
+ "Install LM Studio from https://lmstudio.ai/",
221
+ 'Load a model in the LM Studio app and click "Start Server".',
222
+ "LM Studio serves its API at http://localhost:1234/v1 by default — set LM_STUDIO_BASE_URL only to override.",
223
+ "Optionally set LM_STUDIO_API_KEY if running behind an auth-proxying reverse proxy.",
224
+ "Optionally set LM_STUDIO_MODEL to choose the default model.",
225
+ ],
226
+ fallbackEnvVars: ["LM_STUDIO_API_KEY", "LM_STUDIO_MODEL"],
227
+ optional: true,
228
+ },
229
+ llamacpp: {
230
+ providerName: "llama.cpp",
231
+ envVarName: "LLAMACPP_BASE_URL",
232
+ setupUrl: "https://github.com/ggerganov/llama.cpp",
233
+ description: "Run a self-hosted GGUF model locally via llama.cpp's OpenAI-compatible llama-server.",
234
+ instructions: [
235
+ "Build or install llama.cpp from https://github.com/ggerganov/llama.cpp",
236
+ "Start the server: ./llama-server -m model.gguf --port 8080",
237
+ "llama-server serves its API at http://localhost:8080/v1 by default — set LLAMACPP_BASE_URL only to override.",
238
+ "Optionally set LLAMACPP_API_KEY if running behind an auth-proxying reverse proxy.",
239
+ "Optionally set LLAMACPP_MODEL to choose the default model.",
240
+ ],
241
+ fallbackEnvVars: ["LLAMACPP_API_KEY", "LLAMACPP_MODEL"],
242
+ optional: true,
243
+ },
244
+ };
245
+ /**
246
+ * Generic, data-driven setup printout for providers without a bespoke
247
+ * interactive handler — reads directly from a ProviderConfigOptions entry.
248
+ */
249
+ function printGenericProviderSetup(providerId, config) {
250
+ logger.always("");
251
+ logger.always(chalk.blue(`🔧 ${config.providerName} Setup`));
252
+ logger.always("");
253
+ logger.always(config.description);
254
+ logger.always("");
255
+ logger.always(chalk.yellow("Setup steps:"));
256
+ config.instructions.forEach((step, index) => {
257
+ logger.always(` ${index + 1}. ${step}`);
258
+ });
259
+ logger.always("");
260
+ logger.always(chalk.yellow("Environment variable:"));
261
+ const optionalNote = config.optional
262
+ ? " (optional — has a working local default)"
263
+ : "";
264
+ logger.always(chalk.cyan(` export ${config.envVarName}=your_value_here${optionalNote}`));
265
+ if (config.fallbackEnvVars?.length) {
266
+ logger.always(chalk.cyan(` Also relevant: ${config.fallbackEnvVars.join(", ")}`));
267
+ }
268
+ logger.always("");
269
+ logger.always(chalk.yellow("Test the configuration:"));
270
+ logger.always(chalk.cyan(` neurolink generate "Hello!" --provider ${providerId}`));
271
+ logger.always("");
272
+ logger.always(chalk.gray(`Docs: ${config.setupUrl}`));
273
+ }
142
274
  /**
143
275
  * Main setup command handler
144
276
  */
@@ -364,7 +496,7 @@ async function runProviderSelection() {
364
496
  /**
365
497
  * Delegate to existing provider setup commands
366
498
  */
367
- async function delegateToProviderSetup(providerId) {
499
+ export async function delegateToProviderSetup(providerId) {
368
500
  const setupArgs = {
369
501
  nonInteractive: false,
370
502
  "non-interactive": false,
@@ -400,8 +532,14 @@ async function delegateToProviderSetup(providerId) {
400
532
  case "openrouter":
401
533
  await handleOpenRouterSetup();
402
534
  break;
403
- default:
404
- throw new Error(`Unknown provider: ${providerId}`);
535
+ default: {
536
+ const genericConfig = EXTRA_PROVIDER_CONFIGS[providerId];
537
+ if (!genericConfig) {
538
+ throw new Error(`Unknown provider: ${providerId}`);
539
+ }
540
+ printGenericProviderSetup(providerId, genericConfig);
541
+ break;
542
+ }
405
543
  }
406
544
  // After successful setup, show completion message
407
545
  await showSetupCompletion(providerId);
@@ -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
- }