@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
@@ -1,33 +0,0 @@
1
- /**
2
- * Provider exports for Vercel AI SDK integration
3
- * This file centralizes all AI provider classes for easy import and usage
4
- */
5
- export { GoogleVertexProvider as GoogleVertexAI } from "./googleVertex/index.js";
6
- export { AmazonBedrockProvider as AmazonBedrock } from "./amazonBedrock/index.js";
7
- export { AmazonSageMakerProvider as AmazonSageMaker } from "./amazonSagemaker.js";
8
- export { OpenAIProvider as OpenAI } from "./openAI/index.js";
9
- export { OpenAICompatibleProvider as OpenAICompatible } from "./openaiCompatible/index.js";
10
- export { AnthropicProvider as AnthropicProvider } from "./anthropic/index.js";
11
- export { AzureOpenAIProvider } from "./azureOpenai.js";
12
- export { GoogleAIStudioProvider as GoogleAIStudio } from "./googleAiStudio/index.js";
13
- export { HuggingFaceProvider as HuggingFace } from "./huggingFace/index.js";
14
- export { OllamaProvider as Ollama } from "./ollama/index.js";
15
- export { MistralProvider as MistralAI } from "./mistral.js";
16
- export { LiteLLMProvider as LiteLLM } from "./litellm/index.js";
17
- export { DeepSeekProvider as DeepSeek } from "./deepseek.js";
18
- export { NvidiaNimProvider as NvidiaNim } from "./nvidiaNim/index.js";
19
- export { LMStudioProvider as LMStudio } from "./lmStudio.js";
20
- export { LlamaCppProvider as LlamaCpp } from "./llamaCpp.js";
21
- export { XaiProvider as Xai } from "./xai.js";
22
- export { GroqProvider as Groq } from "./groq.js";
23
- export { CohereProvider as Cohere } from "./cohere.js";
24
- export { TogetherAIProvider as TogetherAI } from "./togetherAi.js";
25
- export { FireworksProvider as Fireworks } from "./fireworks.js";
26
- export { PerplexityProvider as Perplexity } from "./perplexity.js";
27
- export { CloudflareProvider as Cloudflare } from "./cloudflare.js";
28
- export { VoyageProvider as Voyage } from "./voyage.js";
29
- export { JinaProvider as Jina } from "./jina.js";
30
- export { StabilityProvider as Stability } from "./stability.js";
31
- export { IdeogramProvider as Ideogram } from "./ideogram.js";
32
- export { RecraftProvider as Recraft } from "./recraft.js";
33
- export { ReplicateProvider as Replicate } from "./replicate.js";
@@ -1 +0,0 @@
1
- export declare const streamTracer: import("@opentelemetry/api").Tracer;
@@ -1,2 +0,0 @@
1
- import { trace } from "@opentelemetry/api";
2
- export const streamTracer = trace.getTracer("neurolink.provider.litellm");
@@ -1,5 +0,0 @@
1
- export declare const getLiteLLMConfig: () => {
2
- baseURL: string;
3
- apiKey: string;
4
- };
5
- export declare const getDefaultLiteLLMModel: () => string;
@@ -1,10 +0,0 @@
1
- import { getProviderModel } from "../../utils/providerConfig.js";
2
- export const getLiteLLMConfig = () => {
3
- return {
4
- baseURL: process.env.LITELLM_BASE_URL || "http://localhost:4000",
5
- apiKey: process.env.LITELLM_API_KEY || "sk-anything",
6
- };
7
- };
8
- export const getDefaultLiteLLMModel = () => {
9
- return getProviderModel("LITELLM_MODEL", "openai/gpt-4o-mini");
10
- };
@@ -1,9 +0,0 @@
1
- import type { NvidiaNimExtraBody } from "../../types/index.js";
2
- export declare const makeLoggingFetch: (provider: string) => typeof fetch;
3
- export declare const envInt: (k: string) => number | undefined;
4
- export declare const envFloat: (k: string) => number | undefined;
5
- export declare const buildNvidiaNimExtraBody: (thinkingEnabled: boolean, maxTokens: number | undefined) => NvidiaNimExtraBody;
6
- export declare const stripReasoningBudget: (body: NvidiaNimExtraBody) => NvidiaNimExtraBody;
7
- export declare const stripChatTemplate: (body: NvidiaNimExtraBody) => NvidiaNimExtraBody;
8
- export declare const getNimApiKey: () => string;
9
- export declare const getDefaultNimModel: () => string;
@@ -1,100 +0,0 @@
1
- import { NvidiaNimModels } from "../../constants/enums.js";
2
- import { createProxyFetch, maskProxyUrl } from "../../proxy/proxyFetch.js";
3
- import { logger } from "../../utils/logger.js";
4
- import { createNvidiaNimConfig, getProviderModel, validateApiKey, } from "../../utils/providerConfig.js";
5
- export const makeLoggingFetch = (provider) => {
6
- const base = createProxyFetch();
7
- return (async (input, init) => {
8
- const url = typeof input === "string"
9
- ? input
10
- : input instanceof URL
11
- ? input.toString()
12
- : input.url;
13
- const reqSize = init?.body && typeof init.body === "string" ? init.body.length : 0;
14
- const response = await base(input, init);
15
- if (!response.ok) {
16
- const safeUrl = maskProxyUrl(url) ?? "<redacted>";
17
- if (process.env.NEUROLINK_DEBUG_HTTP === "1") {
18
- const clone = response.clone();
19
- const body = await clone.text().catch(() => "<unreadable>");
20
- logger.warn(`[${provider}] upstream ${response.status}`, {
21
- url: safeUrl,
22
- body: body.slice(0, 800),
23
- reqSize,
24
- });
25
- }
26
- else {
27
- logger.warn(`[${provider}] upstream ${response.status} url=${safeUrl} reqSize=${reqSize}`);
28
- }
29
- }
30
- return response;
31
- });
32
- };
33
- export const envInt = (k) => {
34
- const v = process.env[k];
35
- if (!v) {
36
- return undefined;
37
- }
38
- const parsed = Number.parseInt(v, 10);
39
- return Number.isFinite(parsed) ? parsed : undefined;
40
- };
41
- export const envFloat = (k) => {
42
- const v = process.env[k];
43
- if (!v) {
44
- return undefined;
45
- }
46
- const parsed = Number.parseFloat(v);
47
- return Number.isFinite(parsed) ? parsed : undefined;
48
- };
49
- export const buildNvidiaNimExtraBody = (thinkingEnabled, maxTokens) => {
50
- const extra = {};
51
- const topK = envInt("NVIDIA_NIM_TOP_K");
52
- if (topK !== undefined && topK !== -1) {
53
- extra.top_k = topK;
54
- }
55
- const minP = envFloat("NVIDIA_NIM_MIN_P");
56
- if (minP !== undefined && minP !== 0) {
57
- extra.min_p = minP;
58
- }
59
- const repPenalty = envFloat("NVIDIA_NIM_REPETITION_PENALTY");
60
- if (repPenalty !== undefined && repPenalty !== 1) {
61
- extra.repetition_penalty = repPenalty;
62
- }
63
- const minTokens = envInt("NVIDIA_NIM_MIN_TOKENS");
64
- if (minTokens !== undefined && minTokens !== 0) {
65
- extra.min_tokens = minTokens;
66
- }
67
- const chatTemplate = process.env.NVIDIA_NIM_CHAT_TEMPLATE;
68
- if (chatTemplate) {
69
- extra.chat_template = chatTemplate;
70
- }
71
- if (thinkingEnabled) {
72
- extra.chat_template_kwargs = {
73
- thinking: true,
74
- enable_thinking: true,
75
- ...(maxTokens ? { reasoning_budget: maxTokens } : {}),
76
- };
77
- }
78
- return extra;
79
- };
80
- export const stripReasoningBudget = (body) => {
81
- const cloned = { ...body };
82
- if (cloned.chat_template_kwargs) {
83
- const { reasoning_budget: _ignored, ...rest } = cloned.chat_template_kwargs;
84
- cloned.chat_template_kwargs = rest;
85
- if (Object.keys(cloned.chat_template_kwargs).length === 0) {
86
- delete cloned.chat_template_kwargs;
87
- }
88
- }
89
- return cloned;
90
- };
91
- export const stripChatTemplate = (body) => {
92
- const { chat_template: _ignored, ...rest } = body;
93
- return rest;
94
- };
95
- export const getNimApiKey = () => {
96
- return validateApiKey(createNvidiaNimConfig());
97
- };
98
- export const getDefaultNimModel = () => {
99
- return getProviderModel("NVIDIA_NIM_MODEL", NvidiaNimModels.LLAMA_3_3_70B_INSTRUCT);
100
- };
@@ -1,8 +0,0 @@
1
- import type { OllamaHttpError } from "../../types/index.js";
2
- export declare function isOllamaHttpError(error: unknown): error is OllamaHttpError;
3
- export declare function createOllamaHttpError(response: Response): Promise<OllamaHttpError>;
4
- export declare const getOllamaBaseUrl: () => string;
5
- export declare const isOpenAICompatibleMode: () => boolean;
6
- export declare const createAbortSignalWithTimeout: (timeoutMs: number) => AbortSignal;
7
- export declare const getDefaultOllamaModel: () => string;
8
- export declare const getOllamaTimeout: () => number;
@@ -1,42 +0,0 @@
1
- import { ProviderError } from "../../types/index.js";
2
- import { DEFAULT_OLLAMA_MODEL } from "./constants.js";
3
- export function isOllamaHttpError(error) {
4
- return (error instanceof ProviderError &&
5
- typeof error.statusCode === "number" &&
6
- typeof error.responseBody === "string");
7
- }
8
- export async function createOllamaHttpError(response) {
9
- let responseBody = "";
10
- try {
11
- responseBody = (await response.text()).trim();
12
- }
13
- catch {
14
- // Ignore unreadable bodies
15
- }
16
- const suffix = responseBody ? ` - ${responseBody.slice(0, 500)}` : "";
17
- const error = new ProviderError(`Ollama API error: ${response.status} ${response.statusText}${suffix}`, "ollama");
18
- error.statusCode = response.status;
19
- error.statusText = response.statusText;
20
- error.responseBody = responseBody;
21
- return error;
22
- }
23
- export const getOllamaBaseUrl = () => {
24
- return process.env.OLLAMA_BASE_URL || "http://localhost:11434";
25
- };
26
- export const isOpenAICompatibleMode = () => {
27
- return process.env.OLLAMA_OPENAI_COMPATIBLE === "true";
28
- };
29
- export const createAbortSignalWithTimeout = (timeoutMs) => {
30
- const controller = new AbortController();
31
- const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
32
- controller.signal.addEventListener("abort", () => {
33
- clearTimeout(timeoutId);
34
- });
35
- return controller.signal;
36
- };
37
- export const getDefaultOllamaModel = () => {
38
- return process.env.OLLAMA_MODEL || DEFAULT_OLLAMA_MODEL;
39
- };
40
- export const getOllamaTimeout = () => {
41
- return parseInt(process.env.OLLAMA_TIMEOUT || "240000", 10);
42
- };
@@ -1 +0,0 @@
1
- export declare const streamTracer: import("@opentelemetry/api").Tracer;
@@ -1,2 +0,0 @@
1
- import { trace } from "@opentelemetry/api";
2
- export const streamTracer = trace.getTracer("neurolink.provider.openai");
@@ -1,2 +0,0 @@
1
- export declare const getOpenAIApiKey: () => string;
2
- export declare const getOpenAIModel: () => string;
@@ -1,7 +0,0 @@
1
- import { createOpenAIConfig, getProviderModel, validateApiKey, } from "../../utils/providerConfig.js";
2
- export const getOpenAIApiKey = () => {
3
- return validateApiKey(createOpenAIConfig());
4
- };
5
- export const getOpenAIModel = () => {
6
- return getProviderModel("OPENAI_MODEL", "gpt-4o");
7
- };
@@ -1,89 +0,0 @@
1
- /**
2
- * Universal Provider Options Interface (Phase 1: Factory Pattern)
3
- * Based on TypeScript factory pattern best practices for AI provider abstraction
4
- */
5
- import type { BaseContext, ContextConfig } from "./context.js";
6
- /**
7
- * Base configuration interface for all AI providers
8
- * Uses Parameter Object Pattern for flexible, extensible configuration
9
- */
10
- export type UniversalProviderOptions = {
11
- prompt?: string;
12
- model?: string;
13
- temperature?: number;
14
- maxTokens?: number;
15
- systemPrompt?: string;
16
- enableAnalytics?: boolean;
17
- enableEvaluation?: boolean;
18
- context?: BaseContext;
19
- contextConfig?: Partial<ContextConfig>;
20
- metadata?: Record<string, unknown>;
21
- extensionOptions?: Record<string, unknown>;
22
- };
23
- /**
24
- * Generic provider options (without providerType)
25
- */
26
- export type GenericProviderOptions = Omit<UniversalProviderOptions, "providerType">;
27
- /**
28
- * Provider-specific configuration extensions
29
- * Discriminated union pattern for type-safe provider configs
30
- */
31
- export type OpenAIProviderOptions = UniversalProviderOptions & {
32
- providerType: "openai";
33
- organization?: string;
34
- seed?: number;
35
- topP?: number;
36
- };
37
- export type GoogleAIProviderOptions = UniversalProviderOptions & {
38
- providerType: "google-ai";
39
- topK?: number;
40
- candidateCount?: number;
41
- stopSequences?: string[];
42
- };
43
- export type AnthropicProviderOptions = UniversalProviderOptions & {
44
- providerType: "anthropic";
45
- topK?: number;
46
- stopSequences?: string[];
47
- };
48
- export type BedrockProviderOptions = UniversalProviderOptions & {
49
- providerType: "bedrock";
50
- inferenceProfileArn?: string;
51
- region?: string;
52
- };
53
- /**
54
- * Discriminated union for type-safe provider configuration
55
- * Enables compile-time type checking for provider-specific options
56
- */
57
- export type ProviderSpecificOptions = OpenAIProviderOptions | GoogleAIProviderOptions | AnthropicProviderOptions | BedrockProviderOptions;
58
- /**
59
- * Factory configuration interface
60
- * Supports both universal and provider-specific parameters
61
- */
62
- export type ProviderFactoryConfig = {
63
- providerName: string;
64
- modelName?: string;
65
- options?: UniversalProviderOptions | ProviderSpecificOptions;
66
- enableMCP?: boolean;
67
- };
68
- /**
69
- * Parameter normalization utilities
70
- * Converts between different parameter formats for backward compatibility
71
- */
72
- export declare class ParameterNormalizer {
73
- /**
74
- * Normalize legacy parameter formats to universal format
75
- */
76
- static normalizeToUniversal(optionsOrPrompt: UniversalProviderOptions | string): UniversalProviderOptions;
77
- /**
78
- * Retrieve the provider type if it exists, otherwise return null
79
- */
80
- private static getProviderType;
81
- /**
82
- * Extract provider-specific parameters safely
83
- */
84
- static extractProviderOptions<T extends ProviderSpecificOptions>(options: UniversalProviderOptions | ProviderSpecificOptions, providerType: T["providerType"]): T | GenericProviderOptions;
85
- /**
86
- * Merge default values with user-provided options
87
- */
88
- static mergeWithDefaults(options: UniversalProviderOptions, defaults: Partial<UniversalProviderOptions>): UniversalProviderOptions;
89
- }
@@ -1,54 +0,0 @@
1
- /**
2
- * Universal Provider Options Interface (Phase 1: Factory Pattern)
3
- * Based on TypeScript factory pattern best practices for AI provider abstraction
4
- */
5
- /**
6
- * Parameter normalization utilities
7
- * Converts between different parameter formats for backward compatibility
8
- */
9
- export class ParameterNormalizer {
10
- /**
11
- * Normalize legacy parameter formats to universal format
12
- */
13
- static normalizeToUniversal(optionsOrPrompt) {
14
- if (typeof optionsOrPrompt === "string") {
15
- return { prompt: optionsOrPrompt };
16
- }
17
- return optionsOrPrompt;
18
- }
19
- /**
20
- * Retrieve the provider type if it exists, otherwise return null
21
- */
22
- static getProviderType(options) {
23
- return "providerType" in options ? options.providerType : null;
24
- }
25
- /**
26
- * Extract provider-specific parameters safely
27
- */
28
- static extractProviderOptions(options, providerType) {
29
- const currentProviderType = ParameterNormalizer.getProviderType(options);
30
- if (currentProviderType === providerType) {
31
- return options;
32
- }
33
- // Handle case where options has providerType but doesn't match
34
- if (currentProviderType !== null) {
35
- const { providerType: _providerType, ...genericOptions } = options;
36
- return genericOptions;
37
- }
38
- // Options don't have providerType, return as generic
39
- return options;
40
- }
41
- /**
42
- * Merge default values with user-provided options
43
- */
44
- static mergeWithDefaults(options, defaults) {
45
- return {
46
- ...defaults,
47
- ...options,
48
- // Merge nested objects (type-safe context merging)
49
- context: { ...defaults.context, ...options.context },
50
- contextConfig: { ...defaults.contextConfig, ...options.contextConfig },
51
- metadata: { ...defaults.metadata, ...options.metadata },
52
- };
53
- }
54
- }