@juspay/neurolink 10.12.9 → 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.
- package/CHANGELOG.md +26 -0
- package/dist/browser/neurolink.min.js +407 -409
- package/dist/cli/commands/setup.d.ts +16 -1
- package/dist/cli/commands/setup.js +141 -3
- package/dist/core/baseProvider.js +3 -3
- package/dist/core/dynamicModels.d.ts +1 -1
- package/dist/core/dynamicModels.js +1 -23
- package/dist/core/modelConfiguration.d.ts +1 -70
- package/dist/core/modelConfiguration.js +0 -303
- package/dist/core/modules/GenerationHandler.js +2 -2
- package/dist/core/modules/structuredOutputPolicy.d.ts +2 -2
- package/dist/core/modules/structuredOutputPolicy.js +2 -2
- package/dist/factories/providerFactory.d.ts +15 -0
- package/dist/factories/providerFactory.js +27 -39
- package/dist/factories/providerRegistry.js +2 -2
- package/dist/lib/core/baseProvider.js +3 -3
- package/dist/lib/core/dynamicModels.d.ts +1 -1
- package/dist/lib/core/dynamicModels.js +1 -23
- package/dist/lib/core/modelConfiguration.d.ts +1 -70
- package/dist/lib/core/modelConfiguration.js +0 -303
- package/dist/lib/core/modules/GenerationHandler.js +2 -2
- package/dist/lib/core/modules/structuredOutputPolicy.d.ts +2 -2
- package/dist/lib/core/modules/structuredOutputPolicy.js +2 -2
- package/dist/lib/factories/providerFactory.d.ts +15 -0
- package/dist/lib/factories/providerFactory.js +27 -39
- package/dist/lib/factories/providerRegistry.js +2 -2
- package/dist/lib/models/anthropicModels.d.ts +0 -7
- package/dist/lib/models/anthropicModels.js +0 -9
- package/dist/lib/providers/anthropic/constants.d.ts +0 -1
- package/dist/lib/providers/anthropic/constants.js +0 -2
- package/dist/lib/providers/anthropic/index.d.ts +0 -1
- package/dist/lib/providers/anthropic/index.js +0 -1
- package/dist/lib/providers/googleAiStudio/index.d.ts +0 -1
- package/dist/lib/providers/googleAiStudio/index.js +0 -1
- package/dist/lib/providers/googleNativeGemini3/index.d.ts +0 -1
- package/dist/lib/providers/googleNativeGemini3/index.js +0 -1
- package/dist/lib/providers/googleVertex/client.d.ts +0 -51
- package/dist/lib/providers/googleVertex/client.js +0 -678
- package/dist/lib/providers/huggingFace/client.d.ts +1 -1
- package/dist/lib/providers/huggingFace/client.js +1 -1
- package/dist/lib/providers/huggingFace/index.d.ts +0 -1
- package/dist/lib/providers/huggingFace/index.js +0 -1
- package/dist/lib/providers/jina.d.ts +0 -1
- package/dist/lib/providers/jina.js +0 -1
- package/dist/lib/providers/litellm/index.d.ts +0 -2
- package/dist/lib/providers/litellm/index.js +0 -2
- package/dist/lib/providers/llamaCpp.d.ts +1 -0
- package/dist/lib/providers/llamaCpp.js +3 -0
- package/dist/lib/providers/lmStudio.js +3 -23
- package/dist/lib/providers/nvidiaNim/index.d.ts +0 -1
- package/dist/lib/providers/nvidiaNim/index.js +0 -1
- package/dist/lib/providers/ollama/client.js +1 -23
- package/dist/lib/providers/ollama/index.d.ts +0 -1
- package/dist/lib/providers/ollama/index.js +0 -1
- package/dist/lib/providers/openAI/index.d.ts +0 -2
- package/dist/lib/providers/openAI/index.js +0 -2
- package/dist/lib/providers/openRouter/utils.d.ts +0 -2
- package/dist/lib/providers/openRouter/utils.js +0 -12
- package/dist/lib/providers/openaiChatCompletionsBase.d.ts +9 -0
- package/dist/lib/providers/openaiChatCompletionsBase.js +33 -0
- package/dist/lib/providers/perplexity.d.ts +2 -1
- package/dist/lib/providers/perplexity.js +2 -1
- package/dist/lib/providers/replicate.d.ts +0 -1
- package/dist/lib/providers/replicate.js +22 -9
- package/dist/lib/providers/voyage.d.ts +0 -1
- package/dist/lib/providers/voyage.js +0 -1
- package/dist/lib/types/index.d.ts +0 -1
- package/dist/lib/types/index.js +0 -1
- package/dist/lib/types/providers.d.ts +2 -11
- package/dist/lib/utils/providerConfig.d.ts +0 -8
- package/dist/lib/utils/providerConfig.js +0 -37
- package/dist/lib/utils/providerUtils.js +1 -25
- package/dist/models/anthropicModels.d.ts +0 -7
- package/dist/models/anthropicModels.js +0 -9
- package/dist/providers/anthropic/constants.d.ts +0 -1
- package/dist/providers/anthropic/constants.js +0 -2
- package/dist/providers/anthropic/index.d.ts +0 -1
- package/dist/providers/anthropic/index.js +0 -1
- package/dist/providers/googleAiStudio/index.d.ts +0 -1
- package/dist/providers/googleAiStudio/index.js +0 -1
- package/dist/providers/googleNativeGemini3/index.d.ts +0 -1
- package/dist/providers/googleNativeGemini3/index.js +0 -1
- package/dist/providers/googleVertex/client.d.ts +0 -51
- package/dist/providers/googleVertex/client.js +0 -678
- package/dist/providers/huggingFace/client.d.ts +1 -1
- package/dist/providers/huggingFace/client.js +1 -1
- package/dist/providers/huggingFace/index.d.ts +0 -1
- package/dist/providers/huggingFace/index.js +0 -1
- package/dist/providers/jina.d.ts +0 -1
- package/dist/providers/jina.js +0 -1
- package/dist/providers/litellm/index.d.ts +0 -2
- package/dist/providers/litellm/index.js +0 -2
- package/dist/providers/llamaCpp.d.ts +1 -0
- package/dist/providers/llamaCpp.js +3 -0
- package/dist/providers/lmStudio.js +3 -23
- package/dist/providers/nvidiaNim/index.d.ts +0 -1
- package/dist/providers/nvidiaNim/index.js +0 -1
- package/dist/providers/ollama/client.js +1 -23
- package/dist/providers/ollama/index.d.ts +0 -1
- package/dist/providers/ollama/index.js +0 -1
- package/dist/providers/openAI/index.d.ts +0 -2
- package/dist/providers/openAI/index.js +0 -2
- package/dist/providers/openRouter/utils.d.ts +0 -2
- package/dist/providers/openRouter/utils.js +0 -12
- package/dist/providers/openaiChatCompletionsBase.d.ts +9 -0
- package/dist/providers/openaiChatCompletionsBase.js +33 -0
- package/dist/providers/perplexity.d.ts +2 -1
- package/dist/providers/perplexity.js +2 -1
- package/dist/providers/replicate.d.ts +0 -1
- package/dist/providers/replicate.js +22 -9
- package/dist/providers/voyage.d.ts +0 -1
- package/dist/providers/voyage.js +0 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.js +0 -1
- package/dist/types/providers.d.ts +2 -11
- package/dist/utils/providerConfig.d.ts +0 -8
- package/dist/utils/providerConfig.js +0 -37
- package/dist/utils/providerUtils.js +1 -25
- package/package.json +8 -7
- package/dist/lib/providers/anthropic/utils.d.ts +0 -7
- package/dist/lib/providers/anthropic/utils.js +0 -150
- package/dist/lib/providers/googleAiStudio/utils.d.ts +0 -2
- package/dist/lib/providers/googleAiStudio/utils.js +0 -19
- package/dist/lib/providers/googleNativeGemini3/constants.d.ts +0 -1
- package/dist/lib/providers/googleNativeGemini3/constants.js +0 -2
- package/dist/lib/providers/huggingFace/utils.d.ts +0 -2
- package/dist/lib/providers/huggingFace/utils.js +0 -8
- package/dist/lib/providers/index.d.ts +0 -33
- package/dist/lib/providers/index.js +0 -34
- package/dist/lib/providers/litellm/constants.d.ts +0 -1
- package/dist/lib/providers/litellm/constants.js +0 -3
- package/dist/lib/providers/litellm/utils.d.ts +0 -5
- package/dist/lib/providers/litellm/utils.js +0 -11
- package/dist/lib/providers/nvidiaNim/utils.d.ts +0 -9
- package/dist/lib/providers/nvidiaNim/utils.js +0 -101
- package/dist/lib/providers/ollama/utils.d.ts +0 -8
- package/dist/lib/providers/ollama/utils.js +0 -43
- package/dist/lib/providers/openAI/constants.d.ts +0 -1
- package/dist/lib/providers/openAI/constants.js +0 -3
- package/dist/lib/providers/openAI/utils.d.ts +0 -2
- package/dist/lib/providers/openAI/utils.js +0 -8
- package/dist/lib/types/universalProviderOptions.d.ts +0 -89
- package/dist/lib/types/universalProviderOptions.js +0 -55
- package/dist/providers/anthropic/utils.d.ts +0 -7
- package/dist/providers/anthropic/utils.js +0 -149
- package/dist/providers/googleAiStudio/utils.d.ts +0 -2
- package/dist/providers/googleAiStudio/utils.js +0 -18
- package/dist/providers/googleNativeGemini3/constants.d.ts +0 -1
- package/dist/providers/googleNativeGemini3/constants.js +0 -1
- package/dist/providers/huggingFace/utils.d.ts +0 -2
- package/dist/providers/huggingFace/utils.js +0 -7
- package/dist/providers/index.d.ts +0 -33
- package/dist/providers/index.js +0 -33
- package/dist/providers/litellm/constants.d.ts +0 -1
- package/dist/providers/litellm/constants.js +0 -2
- package/dist/providers/litellm/utils.d.ts +0 -5
- package/dist/providers/litellm/utils.js +0 -10
- package/dist/providers/nvidiaNim/utils.d.ts +0 -9
- package/dist/providers/nvidiaNim/utils.js +0 -100
- package/dist/providers/ollama/utils.d.ts +0 -8
- package/dist/providers/ollama/utils.js +0 -42
- package/dist/providers/openAI/constants.d.ts +0 -1
- package/dist/providers/openAI/constants.js +0 -2
- package/dist/providers/openAI/utils.d.ts +0 -2
- package/dist/providers/openAI/utils.js +0 -7
- package/dist/types/universalProviderOptions.d.ts +0 -89
- package/dist/types/universalProviderOptions.js +0 -54
|
@@ -29,8 +29,8 @@ export declare function isGeminiProvider(providerName: string, modelName: string
|
|
|
29
29
|
* `providerOptions.anthropic.finalResultSchema`, and the provider appends an
|
|
30
30
|
* additive `final_result` tool (see providers/anthropic/structuredOutput.ts) —
|
|
31
31
|
* schema enforcement without giving up tool calling. "bedrock" has no such
|
|
32
|
-
* handling (it
|
|
33
|
-
* falls back to text-mode coercion.
|
|
32
|
+
* handling (it talks to the raw AWS SDK directly, not an ai-sdk provider
|
|
33
|
+
* package) and still falls back to text-mode coercion.
|
|
34
34
|
*/
|
|
35
35
|
export declare function isNativeAnthropicProvider(providerName: string): boolean;
|
|
36
36
|
/**
|
|
@@ -39,8 +39,8 @@ export function isGeminiProvider(providerName, modelName) {
|
|
|
39
39
|
* `providerOptions.anthropic.finalResultSchema`, and the provider appends an
|
|
40
40
|
* additive `final_result` tool (see providers/anthropic/structuredOutput.ts) —
|
|
41
41
|
* schema enforcement without giving up tool calling. "bedrock" has no such
|
|
42
|
-
* handling (it
|
|
43
|
-
* falls back to text-mode coercion.
|
|
42
|
+
* handling (it talks to the raw AWS SDK directly, not an ai-sdk provider
|
|
43
|
+
* package) and still falls back to text-mode coercion.
|
|
44
44
|
*/
|
|
45
45
|
export function isNativeAnthropicProvider(providerName) {
|
|
46
46
|
return providerName === "anthropic" || providerName === "bedrock";
|
|
@@ -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
|
-
|
|
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
|
-
|
|
85
|
-
|
|
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,
|
|
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,
|
|
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 {
|
|
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 =
|
|
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 =
|
|
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,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
|
|
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,31 +546,4 @@ export class ModelConfigurationManager {
|
|
|
822
546
|
* Global instance accessor
|
|
823
547
|
*/
|
|
824
548
|
export const modelConfig = ModelConfigurationManager.getInstance();
|
|
825
|
-
/**
|
|
826
|
-
* Convenience functions for common operations
|
|
827
|
-
*/
|
|
828
|
-
/**
|
|
829
|
-
* Get provider configuration (backwards compatible)
|
|
830
|
-
*/
|
|
831
|
-
export function getProviderConfiguration(provider) {
|
|
832
|
-
return modelConfig.getProviderConfiguration(provider);
|
|
833
|
-
}
|
|
834
|
-
/**
|
|
835
|
-
* Get model for tier (backwards compatible)
|
|
836
|
-
*/
|
|
837
|
-
export function getModelForTier(provider, tier) {
|
|
838
|
-
return modelConfig.getModelForTier(provider, tier);
|
|
839
|
-
}
|
|
840
|
-
/**
|
|
841
|
-
* Get cost information (backwards compatible)
|
|
842
|
-
*/
|
|
843
|
-
export function getCostInfo(provider, model) {
|
|
844
|
-
return modelConfig.getCostInfo(provider, model);
|
|
845
|
-
}
|
|
846
|
-
/**
|
|
847
|
-
* Check provider availability (backwards compatible)
|
|
848
|
-
*/
|
|
849
|
-
export function isProviderAvailable(provider) {
|
|
850
|
-
return modelConfig.isProviderAvailable(provider);
|
|
851
|
-
}
|
|
852
549
|
//# sourceMappingURL=modelConfiguration.js.map
|
|
@@ -247,8 +247,8 @@ export class GenerationHandler {
|
|
|
247
247
|
// JSON Schema to the provider instead: it appends an additive
|
|
248
248
|
// `final_result` tool and returns the answer as that tool's arguments,
|
|
249
249
|
// keeping the real tools callable. Bedrock is deliberately excluded — it
|
|
250
|
-
//
|
|
251
|
-
// handling.
|
|
250
|
+
// talks to the raw AWS SDK directly, not an ai-sdk provider package, and
|
|
251
|
+
// has no such handling.
|
|
252
252
|
const finalResultSchema = this.providerName === "anthropic" &&
|
|
253
253
|
!!options.schema &&
|
|
254
254
|
shouldUseTools &&
|
|
@@ -29,8 +29,8 @@ export declare function isGeminiProvider(providerName: string, modelName: string
|
|
|
29
29
|
* `providerOptions.anthropic.finalResultSchema`, and the provider appends an
|
|
30
30
|
* additive `final_result` tool (see providers/anthropic/structuredOutput.ts) —
|
|
31
31
|
* schema enforcement without giving up tool calling. "bedrock" has no such
|
|
32
|
-
* handling (it
|
|
33
|
-
* falls back to text-mode coercion.
|
|
32
|
+
* handling (it talks to the raw AWS SDK directly, not an ai-sdk provider
|
|
33
|
+
* package) and still falls back to text-mode coercion.
|
|
34
34
|
*/
|
|
35
35
|
export declare function isNativeAnthropicProvider(providerName: string): boolean;
|
|
36
36
|
/**
|
|
@@ -39,8 +39,8 @@ export function isGeminiProvider(providerName, modelName) {
|
|
|
39
39
|
* `providerOptions.anthropic.finalResultSchema`, and the provider appends an
|
|
40
40
|
* additive `final_result` tool (see providers/anthropic/structuredOutput.ts) —
|
|
41
41
|
* schema enforcement without giving up tool calling. "bedrock" has no such
|
|
42
|
-
* handling (it
|
|
43
|
-
* falls back to text-mode coercion.
|
|
42
|
+
* handling (it talks to the raw AWS SDK directly, not an ai-sdk provider
|
|
43
|
+
* package) and still falls back to text-mode coercion.
|
|
44
44
|
*/
|
|
45
45
|
export function isNativeAnthropicProvider(providerName) {
|
|
46
46
|
return providerName === "anthropic" || providerName === "bedrock";
|