@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
@@ -25,7 +25,7 @@ import { calculateCacheSavingsPercent, extractCacheCreationTokens, extractCacheR
25
25
  import { DEFAULT_MAX_STEPS, DEFAULT_WRAPUP_TIME_LEAD_MS, } from "../constants.js";
26
26
  import { createStepBudgetGuard, estimateFixedOverheadTokens, } from "../../context/stepBudgetGuard.js";
27
27
  import { isTemperatureDeprecatedError, isSchemaComplexityError, isToolsSchemaConflictError, isToolsSchemaExclusionInForce, } from "./structuredOutputPolicy.js";
28
- import { coerceJsonToSchema } from "../../utils/json/coerce.js";
28
+ import { coerceJsonToSchema, recoverScalarRoot, schemaAccepts, } from "../../utils/json/coerce.js";
29
29
  import { convertZodToJsonSchema } from "../../utils/schemaConversion.js";
30
30
  import { NoObjectGeneratedError } from "../../utils/generationErrors.js";
31
31
  import { Output, stepCountIs } from "../../utils/tool.js";
@@ -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 &&
@@ -800,26 +800,35 @@ export class GenerationHandler {
800
800
  }
801
801
  return coerced.content;
802
802
  }
803
- try {
804
- const scalar = JSON.parse(strippedText);
805
- if (scalar === "") {
803
+ const scalar = recoverScalarRoot(strippedText, options.schema);
804
+ switch (scalar.kind) {
805
+ case "empty":
806
806
  // A JSON-encoded empty string is an EMPTY completion, not a
807
807
  // recovered scalar — normalize to a true empty ('' content, no
808
808
  // structuredData) so callers' empty-response handling fires
809
809
  // instead of a literal '""' reaching the user.
810
810
  logger.warn("[GenerationHandler] schema requested but the model returned an empty JSON string; normalizing to empty content", { provider: this.providerName, model: this.modelName });
811
811
  return "";
812
- }
813
- if (scalar !== null && scalar !== undefined) {
814
- structuredData = scalar;
812
+ case "accepted":
813
+ // A JSON scalar root is only real structured data when the caller's
814
+ // schema actually accepts it. Under an OBJECT schema a recovered
815
+ // string/number is the raw completion in disguise (the shape a
816
+ // truncated response degrades to) — publishing it would hand the
817
+ // caller a `structuredData` that violates the schema they passed.
818
+ structuredData = scalar.value;
819
+ return strippedText;
820
+ case "rejected":
821
+ logger.warn("[GenerationHandler] recovered a JSON scalar the requested schema rejects; leaving structuredData unset", {
822
+ provider: this.providerName,
823
+ model: this.modelName,
824
+ scalarType: typeof scalar.value,
825
+ });
826
+ return strippedText;
827
+ case "nullish":
828
+ case "not-json":
829
+ logger.warn("[GenerationHandler] schema requested but no JSON could be recovered from model text; returning raw text", { provider: this.providerName, model: this.modelName });
815
830
  return strippedText;
816
- }
817
- }
818
- catch {
819
- // not JSON at all — fall through to raw text + WARN
820
831
  }
821
- logger.warn("[GenerationHandler] schema requested but no JSON could be recovered from model text; returning raw text", { provider: this.providerName, model: this.modelName });
822
- return strippedText;
823
832
  };
824
833
  if (useStructuredOutput) {
825
834
  try {
@@ -834,7 +843,20 @@ export class GenerationHandler {
834
843
  // (a string identical to the step text) and coerce it instead.
835
844
  const rawTextEcho = typeof experimentalOutput === "string" &&
836
845
  experimentalOutput === (generateResult.text ?? "");
837
- if (experimentalOutput !== undefined && !rawTextEcho) {
846
+ // The equality check above only catches an EXACT echo. On a multi-step
847
+ // or truncated turn the echo can differ from `text` (a different step's
848
+ // text, a fence, trailing whitespace), and a raw string would then be
849
+ // published as `structuredData` under an object schema — the "returned
850
+ // a string instead of the schema object" failure. A string is trusted
851
+ // as structured output ONLY when the caller's schema accepts it
852
+ // (string-root schemas keep working); otherwise it is coerced like any
853
+ // other raw model text.
854
+ const untrustedStringOutput = typeof experimentalOutput === "string" &&
855
+ !!options.schema &&
856
+ !schemaAccepts(options.schema, experimentalOutput);
857
+ if (experimentalOutput !== undefined &&
858
+ !rawTextEcho &&
859
+ !untrustedStringOutput) {
838
860
  // AI-SDK already parsed + schema-validated the object. Expose it
839
861
  // directly and serialise canonically — no hand-parsing needed.
840
862
  structuredData = experimentalOutput;
@@ -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";
@@ -1,6 +1,21 @@
1
1
  import type { NeuroLink } from "../neurolink.js";
2
2
  import type { AIProviderName } from "../constants/enums.js";
3
3
  import type { AIProvider, NeurolinkCredentials, ProviderConstructor, ProviderRegistration } from "../types/index.js";
4
+ /**
5
+ * Maps registered provider names to NeurolinkCredentials keys. Most names
6
+ * match (openai, anthropic, vertex, bedrock, etc.) but every kebab-case
7
+ * provider whose canonical credentials key is camelCase — or otherwise
8
+ * spelled differently — MUST be mapped here, otherwise per-call/instance
9
+ * credential overrides silently get dropped (createProvider() looks up
10
+ * credentials["lm-studio"], which is undefined, while the caller wrote
11
+ * credentials.lmStudio).
12
+ */
13
+ export declare const CREDENTIAL_KEY_MAP: Record<string, string>;
14
+ /**
15
+ * Resolve a registered provider name to its NeurolinkCredentials key.
16
+ * Falls back to the provider name itself when no remapping is needed.
17
+ */
18
+ export declare function resolveCredentialKey(providerName: string): string;
4
19
  /**
5
20
  * True Factory Pattern implementation for AI Providers
6
21
  * Uses registration-based approach to eliminate switch statements
@@ -1,6 +1,30 @@
1
1
  import { logger } from "../utils/logger.js";
2
2
  // Pure factory pattern with no hardcoded imports
3
3
  // All providers loaded dynamically via registry to avoid circular dependencies
4
+ /**
5
+ * Maps registered provider names to NeurolinkCredentials keys. Most names
6
+ * match (openai, anthropic, vertex, bedrock, etc.) but every kebab-case
7
+ * provider whose canonical credentials key is camelCase — or otherwise
8
+ * spelled differently — MUST be mapped here, otherwise per-call/instance
9
+ * credential overrides silently get dropped (createProvider() looks up
10
+ * credentials["lm-studio"], which is undefined, while the caller wrote
11
+ * credentials.lmStudio).
12
+ */
13
+ export const CREDENTIAL_KEY_MAP = {
14
+ "google-ai": "googleAiStudio",
15
+ "openai-compatible": "openaiCompatible",
16
+ huggingface: "huggingFace",
17
+ "lm-studio": "lmStudio",
18
+ "nvidia-nim": "nvidiaNim",
19
+ "together-ai": "together",
20
+ };
21
+ /**
22
+ * Resolve a registered provider name to its NeurolinkCredentials key.
23
+ * Falls back to the provider name itself when no remapping is needed.
24
+ */
25
+ export function resolveCredentialKey(providerName) {
26
+ return (CREDENTIAL_KEY_MAP[providerName.toLowerCase()] ?? providerName.toLowerCase());
27
+ }
4
28
  /**
5
29
  * True Factory Pattern implementation for AI Providers
6
30
  * Uses registration-based approach to eliminate switch statements
@@ -58,21 +82,7 @@ export class ProviderFactory {
58
82
  // Fallback to registry default if no env var
59
83
  model = model || registration.defaultModel;
60
84
  }
61
- // Map registered provider names to NeurolinkCredentials keys.
62
- // Most names match (openai, anthropic, vertex, bedrock, etc.)
63
- // but every kebab-case provider whose canonical credentials key is
64
- // camelCase MUST be mapped here — otherwise per-call credential
65
- // overrides silently get dropped (the factory looks up
66
- // credentials["lm-studio"] which is undefined while the user wrote
67
- // credentials.lmStudio).
68
- const credentialKeyMap = {
69
- "google-ai": "googleAiStudio",
70
- "openai-compatible": "openaiCompatible",
71
- huggingface: "huggingFace",
72
- "lm-studio": "lmStudio",
73
- "nvidia-nim": "nvidiaNim",
74
- };
75
- const credKey = credentialKeyMap[normalizedName] ?? normalizedName;
85
+ const credKey = resolveCredentialKey(normalizedName);
76
86
  // Extract provider-scoped credential slice (e.g. credentials.openai for OpenAI)
77
87
  const scopedCredentials = credentials
78
88
  ? credentials[credKey]
@@ -81,30 +91,8 @@ export class ProviderFactory {
81
91
  if (typeof registration.constructor !== "function") {
82
92
  throw new Error(`Invalid constructor for provider ${providerName}: not a function`);
83
93
  }
84
- let result;
85
- try {
86
- const factoryResult = registration.constructor(model, resolvedProviderName, sdk, region, scopedCredentials);
87
- // Handle both sync and async results
88
- result =
89
- factoryResult instanceof Promise
90
- ? await factoryResult
91
- : factoryResult;
92
- }
93
- catch (factoryError) {
94
- if (registration.constructor.prototype &&
95
- registration.constructor.prototype.constructor ===
96
- registration.constructor) {
97
- try {
98
- result = new registration.constructor(model, resolvedProviderName, sdk, region, scopedCredentials);
99
- }
100
- catch (constructorError) {
101
- throw new Error(`Both factory function and constructor failed. Factory error: ${factoryError}. Constructor error: ${constructorError}`, { cause: constructorError });
102
- }
103
- }
104
- else {
105
- throw factoryError;
106
- }
107
- }
94
+ const factoryResult = registration.constructor(model, resolvedProviderName, sdk, region, scopedCredentials);
95
+ const result = factoryResult instanceof Promise ? await factoryResult : factoryResult;
108
96
  return result;
109
97
  }
110
98
  catch (error) {
@@ -104,10 +104,10 @@ export class ProviderRegistry {
104
104
  return new GoogleVertexProvider(modelName, providerName, sdk, region, vertexCreds);
105
105
  }, VertexModels.CLAUDE_4_6_SONNET, ["vertex", "googleVertex"]);
106
106
  // Register Hugging Face provider (Unified Router implementation)
107
- ProviderFactory.registerProvider(AIProviderName.HUGGINGFACE, async (modelName, _providerName, _sdk, _region, credentials) => {
107
+ ProviderFactory.registerProvider(AIProviderName.HUGGINGFACE, async (modelName, _providerName, sdk, region, credentials) => {
108
108
  const hfCreds = credentials;
109
109
  const { HuggingFaceProvider } = await import("../providers/huggingFace/index.js");
110
- return new HuggingFaceProvider(modelName, undefined, hfCreds);
110
+ return new HuggingFaceProvider(modelName, sdk, region, hfCreds);
111
111
  }, process.env.HUGGINGFACE_MODEL ||
112
112
  HuggingFaceModels.QWEN_2_5_72B_INSTRUCT, ["huggingface", "hf"]);
113
113
  // Register Mistral AI provider
@@ -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;