@juspay/neurolink 5.0.0 → 5.2.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 +20 -7
- package/README.md +160 -172
- package/dist/agent/direct-tools.d.ts +6 -6
- package/dist/chat/sse-handler.js +5 -4
- package/dist/chat/websocket-chat-handler.js +9 -9
- package/dist/cli/commands/config.d.ts +3 -3
- package/dist/cli/commands/mcp.js +9 -8
- package/dist/cli/commands/ollama.js +3 -3
- package/dist/cli/factories/command-factory.d.ts +18 -0
- package/dist/cli/factories/command-factory.js +183 -0
- package/dist/cli/index.js +105 -157
- package/dist/cli/utils/interactive-setup.js +2 -2
- package/dist/core/base-provider.d.ts +423 -0
- package/dist/core/base-provider.js +365 -0
- package/dist/core/constants.d.ts +1 -1
- package/dist/core/constants.js +1 -1
- package/dist/core/dynamic-models.d.ts +6 -6
- package/dist/core/evaluation.d.ts +19 -80
- package/dist/core/evaluation.js +185 -484
- package/dist/core/factory.d.ts +3 -3
- package/dist/core/factory.js +31 -91
- package/dist/core/service-registry.d.ts +47 -0
- package/dist/core/service-registry.js +112 -0
- package/dist/core/types.d.ts +49 -49
- package/dist/core/types.js +1 -0
- package/dist/factories/compatibility-factory.d.ts +20 -0
- package/dist/factories/compatibility-factory.js +69 -0
- package/dist/factories/provider-factory.d.ts +72 -0
- package/dist/factories/provider-factory.js +144 -0
- package/dist/factories/provider-generate-factory.d.ts +20 -0
- package/dist/factories/provider-generate-factory.js +87 -0
- package/dist/factories/provider-registry.d.ts +38 -0
- package/dist/factories/provider-registry.js +107 -0
- package/dist/index.d.ts +8 -5
- package/dist/index.js +5 -5
- package/dist/lib/agent/direct-tools.d.ts +6 -6
- package/dist/lib/chat/sse-handler.js +5 -4
- package/dist/lib/chat/websocket-chat-handler.js +9 -9
- package/dist/lib/core/base-provider.d.ts +423 -0
- package/dist/lib/core/base-provider.js +365 -0
- package/dist/lib/core/constants.d.ts +1 -1
- package/dist/lib/core/constants.js +1 -1
- package/dist/lib/core/dynamic-models.d.ts +6 -6
- package/dist/lib/core/evaluation.d.ts +19 -80
- package/dist/lib/core/evaluation.js +185 -484
- package/dist/lib/core/factory.d.ts +3 -3
- package/dist/lib/core/factory.js +30 -91
- package/dist/lib/core/service-registry.d.ts +47 -0
- package/dist/lib/core/service-registry.js +112 -0
- package/dist/lib/core/types.d.ts +49 -49
- package/dist/lib/core/types.js +1 -0
- package/dist/lib/factories/compatibility-factory.d.ts +20 -0
- package/dist/lib/factories/compatibility-factory.js +69 -0
- package/dist/lib/factories/provider-factory.d.ts +72 -0
- package/dist/lib/factories/provider-factory.js +144 -0
- package/dist/lib/factories/provider-generate-factory.d.ts +20 -0
- package/dist/lib/factories/provider-generate-factory.js +87 -0
- package/dist/lib/factories/provider-registry.d.ts +38 -0
- package/dist/lib/factories/provider-registry.js +107 -0
- package/dist/lib/index.d.ts +8 -5
- package/dist/lib/index.js +5 -5
- package/dist/lib/mcp/client.js +5 -5
- package/dist/lib/mcp/config.js +28 -3
- package/dist/lib/mcp/dynamic-orchestrator.js +8 -8
- package/dist/lib/mcp/external-client.js +2 -2
- package/dist/lib/mcp/factory.d.ts +1 -1
- package/dist/lib/mcp/factory.js +1 -1
- package/dist/lib/mcp/function-calling.js +1 -1
- package/dist/lib/mcp/initialize-tools.d.ts +1 -1
- package/dist/lib/mcp/initialize-tools.js +45 -1
- package/dist/lib/mcp/initialize.js +16 -6
- package/dist/lib/mcp/neurolink-mcp-client.js +10 -10
- package/dist/lib/mcp/orchestrator.js +4 -4
- package/dist/lib/mcp/servers/agent/direct-tools-server.d.ts +8 -0
- package/dist/lib/mcp/servers/agent/direct-tools-server.js +109 -0
- package/dist/lib/mcp/servers/ai-providers/ai-analysis-tools.js +10 -10
- package/dist/lib/mcp/servers/ai-providers/ai-core-server.js +8 -6
- package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.d.ts +2 -2
- package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.js +16 -16
- package/dist/lib/mcp/unified-registry.d.ts +4 -0
- package/dist/lib/mcp/unified-registry.js +42 -9
- package/dist/lib/neurolink.d.ts +161 -174
- package/dist/lib/neurolink.js +723 -397
- package/dist/lib/providers/amazon-bedrock.d.ts +32 -0
- package/dist/lib/providers/amazon-bedrock.js +143 -0
- package/dist/lib/providers/analytics-helper.js +7 -4
- package/dist/lib/providers/anthropic-baseprovider.d.ts +23 -0
- package/dist/lib/providers/anthropic-baseprovider.js +114 -0
- package/dist/lib/providers/anthropic.d.ts +19 -39
- package/dist/lib/providers/anthropic.js +84 -378
- package/dist/lib/providers/azure-openai.d.ts +20 -0
- package/dist/lib/providers/azure-openai.js +89 -0
- package/dist/lib/providers/function-calling-provider.d.ts +14 -12
- package/dist/lib/providers/function-calling-provider.js +114 -64
- package/dist/lib/providers/google-ai-studio.d.ts +23 -0
- package/dist/lib/providers/google-ai-studio.js +107 -0
- package/dist/lib/providers/google-vertex.d.ts +47 -0
- package/dist/lib/providers/google-vertex.js +205 -0
- package/dist/lib/providers/huggingFace.d.ts +33 -27
- package/dist/lib/providers/huggingFace.js +103 -400
- package/dist/lib/providers/index.d.ts +9 -9
- package/dist/lib/providers/index.js +9 -9
- package/dist/lib/providers/mcp-provider.d.ts +13 -8
- package/dist/lib/providers/mcp-provider.js +63 -18
- package/dist/lib/providers/mistral.d.ts +42 -0
- package/dist/lib/providers/mistral.js +160 -0
- package/dist/lib/providers/ollama.d.ts +52 -35
- package/dist/lib/providers/ollama.js +297 -477
- package/dist/lib/providers/openAI.d.ts +21 -21
- package/dist/lib/providers/openAI.js +81 -245
- package/dist/lib/sdk/tool-extension.d.ts +181 -0
- package/dist/lib/sdk/tool-extension.js +283 -0
- package/dist/lib/sdk/tool-registration.d.ts +95 -0
- package/dist/lib/sdk/tool-registration.js +167 -0
- package/dist/lib/types/generate-types.d.ts +80 -0
- package/dist/lib/types/generate-types.js +1 -0
- package/dist/lib/types/mcp-types.d.ts +116 -0
- package/dist/lib/types/mcp-types.js +5 -0
- package/dist/lib/types/stream-types.d.ts +95 -0
- package/dist/lib/types/stream-types.js +1 -0
- package/dist/lib/types/universal-provider-options.d.ts +87 -0
- package/dist/lib/types/universal-provider-options.js +53 -0
- package/dist/lib/utils/providerUtils-fixed.js +1 -1
- package/dist/lib/utils/streaming-utils.d.ts +14 -2
- package/dist/lib/utils/streaming-utils.js +0 -3
- package/dist/mcp/client.js +5 -5
- package/dist/mcp/config.js +28 -3
- package/dist/mcp/dynamic-orchestrator.js +8 -8
- package/dist/mcp/external-client.js +2 -2
- package/dist/mcp/factory.d.ts +1 -1
- package/dist/mcp/factory.js +1 -1
- package/dist/mcp/function-calling.js +1 -1
- package/dist/mcp/initialize-tools.d.ts +1 -1
- package/dist/mcp/initialize-tools.js +45 -1
- package/dist/mcp/initialize.js +16 -6
- package/dist/mcp/neurolink-mcp-client.js +10 -10
- package/dist/mcp/orchestrator.js +4 -4
- package/dist/mcp/servers/agent/direct-tools-server.d.ts +8 -0
- package/dist/mcp/servers/agent/direct-tools-server.js +109 -0
- package/dist/mcp/servers/ai-providers/ai-analysis-tools.js +10 -10
- package/dist/mcp/servers/ai-providers/ai-core-server.js +8 -6
- package/dist/mcp/servers/ai-providers/ai-workflow-tools.d.ts +2 -2
- package/dist/mcp/servers/ai-providers/ai-workflow-tools.js +16 -16
- package/dist/mcp/unified-registry.d.ts +4 -0
- package/dist/mcp/unified-registry.js +42 -9
- package/dist/neurolink.d.ts +161 -174
- package/dist/neurolink.js +723 -397
- package/dist/providers/amazon-bedrock.d.ts +32 -0
- package/dist/providers/amazon-bedrock.js +143 -0
- package/dist/providers/analytics-helper.js +7 -4
- package/dist/providers/anthropic-baseprovider.d.ts +23 -0
- package/dist/providers/anthropic-baseprovider.js +114 -0
- package/dist/providers/anthropic.d.ts +19 -39
- package/dist/providers/anthropic.js +83 -377
- package/dist/providers/azure-openai.d.ts +20 -0
- package/dist/providers/azure-openai.js +89 -0
- package/dist/providers/function-calling-provider.d.ts +14 -12
- package/dist/providers/function-calling-provider.js +114 -64
- package/dist/providers/google-ai-studio.d.ts +23 -0
- package/dist/providers/google-ai-studio.js +108 -0
- package/dist/providers/google-vertex.d.ts +47 -0
- package/dist/providers/google-vertex.js +205 -0
- package/dist/providers/huggingFace.d.ts +33 -27
- package/dist/providers/huggingFace.js +102 -399
- package/dist/providers/index.d.ts +9 -9
- package/dist/providers/index.js +9 -9
- package/dist/providers/mcp-provider.d.ts +13 -8
- package/dist/providers/mcp-provider.js +63 -18
- package/dist/providers/mistral.d.ts +42 -0
- package/dist/providers/mistral.js +160 -0
- package/dist/providers/ollama.d.ts +52 -35
- package/dist/providers/ollama.js +297 -476
- package/dist/providers/openAI.d.ts +21 -21
- package/dist/providers/openAI.js +81 -246
- package/dist/sdk/tool-extension.d.ts +181 -0
- package/dist/sdk/tool-extension.js +283 -0
- package/dist/sdk/tool-registration.d.ts +95 -0
- package/dist/sdk/tool-registration.js +168 -0
- package/dist/types/generate-types.d.ts +80 -0
- package/dist/types/generate-types.js +1 -0
- package/dist/types/mcp-types.d.ts +116 -0
- package/dist/types/mcp-types.js +5 -0
- package/dist/types/stream-types.d.ts +95 -0
- package/dist/types/stream-types.js +1 -0
- package/dist/types/universal-provider-options.d.ts +87 -0
- package/dist/types/universal-provider-options.js +53 -0
- package/dist/utils/providerUtils-fixed.js +1 -1
- package/dist/utils/streaming-utils.d.ts +14 -2
- package/dist/utils/streaming-utils.js +0 -3
- package/package.json +15 -10
- package/dist/lib/providers/agent-enhanced-provider.d.ts +0 -89
- package/dist/lib/providers/agent-enhanced-provider.js +0 -614
- package/dist/lib/providers/amazonBedrock.d.ts +0 -19
- package/dist/lib/providers/amazonBedrock.js +0 -334
- package/dist/lib/providers/azureOpenAI.d.ts +0 -39
- package/dist/lib/providers/azureOpenAI.js +0 -436
- package/dist/lib/providers/googleAIStudio.d.ts +0 -49
- package/dist/lib/providers/googleAIStudio.js +0 -333
- package/dist/lib/providers/googleVertexAI.d.ts +0 -38
- package/dist/lib/providers/googleVertexAI.js +0 -519
- package/dist/lib/providers/mistralAI.d.ts +0 -34
- package/dist/lib/providers/mistralAI.js +0 -294
- package/dist/providers/agent-enhanced-provider.d.ts +0 -89
- package/dist/providers/agent-enhanced-provider.js +0 -614
- package/dist/providers/amazonBedrock.d.ts +0 -19
- package/dist/providers/amazonBedrock.js +0 -334
- package/dist/providers/azureOpenAI.d.ts +0 -39
- package/dist/providers/azureOpenAI.js +0 -437
- package/dist/providers/googleAIStudio.d.ts +0 -49
- package/dist/providers/googleAIStudio.js +0 -333
- package/dist/providers/googleVertexAI.d.ts +0 -38
- package/dist/providers/googleVertexAI.js +0 -519
- package/dist/providers/mistralAI.d.ts +0 -34
- package/dist/providers/mistralAI.js +0 -294
|
@@ -5,7 +5,7 @@ declare const componentIdentifier = "aiProviderFactory";
|
|
|
5
5
|
*/
|
|
6
6
|
export declare class AIProviderFactory {
|
|
7
7
|
/**
|
|
8
|
-
* Normalize provider name
|
|
8
|
+
* Normalize provider name using ProviderFactory
|
|
9
9
|
*/
|
|
10
10
|
private static normalizeProviderName;
|
|
11
11
|
/**
|
|
@@ -15,7 +15,7 @@ export declare class AIProviderFactory {
|
|
|
15
15
|
* @param enableMCP - Optional flag to enable MCP integration (default: true)
|
|
16
16
|
* @returns AIProvider instance
|
|
17
17
|
*/
|
|
18
|
-
static createProvider(providerName: string, modelName?: string | null, enableMCP?: boolean): Promise<AIProvider>;
|
|
18
|
+
static createProvider(providerName: string, modelName?: string | null, enableMCP?: boolean, sdk?: any): Promise<AIProvider>;
|
|
19
19
|
/**
|
|
20
20
|
* Create a provider instance with specific provider enum and model
|
|
21
21
|
* @param provider - Provider enum value
|
|
@@ -30,7 +30,7 @@ export declare class AIProviderFactory {
|
|
|
30
30
|
* @param enableMCP - Optional flag to enable MCP integration (default: true)
|
|
31
31
|
* @returns AIProvider instance
|
|
32
32
|
*/
|
|
33
|
-
static createBestProvider(requestedProvider?: string, modelName?: string | null, enableMCP?: boolean): Promise<AIProvider>;
|
|
33
|
+
static createBestProvider(requestedProvider?: string, modelName?: string | null, enableMCP?: boolean, sdk?: any): Promise<AIProvider>;
|
|
34
34
|
/**
|
|
35
35
|
* Create primary and fallback provider instances
|
|
36
36
|
* @param primaryProvider - Primary provider name
|
package/dist/lib/core/factory.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
// ✅ CIRCULAR DEPENDENCY FIX: Remove barrel export import
|
|
2
|
+
// Providers are now managed via ProviderFactory instead of direct imports
|
|
3
|
+
import { ProviderFactory } from "../factories/provider-factory.js";
|
|
2
4
|
import { getBestProvider } from "../utils/providerUtils.js";
|
|
3
5
|
import { logger } from "../utils/logger.js";
|
|
4
6
|
const componentIdentifier = "aiProviderFactory";
|
|
@@ -7,45 +9,16 @@ const componentIdentifier = "aiProviderFactory";
|
|
|
7
9
|
*/
|
|
8
10
|
export class AIProviderFactory {
|
|
9
11
|
/**
|
|
10
|
-
* Normalize provider name
|
|
12
|
+
* Normalize provider name using ProviderFactory
|
|
11
13
|
*/
|
|
12
14
|
static normalizeProviderName(providerName) {
|
|
13
|
-
switch
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return "google";
|
|
18
|
-
case "bedrock":
|
|
19
|
-
case "amazon":
|
|
20
|
-
case "aws":
|
|
21
|
-
return "bedrock";
|
|
22
|
-
case "openai":
|
|
23
|
-
case "gpt":
|
|
24
|
-
return "openai";
|
|
25
|
-
case "anthropic":
|
|
26
|
-
case "claude":
|
|
27
|
-
return "anthropic";
|
|
28
|
-
case "azure":
|
|
29
|
-
case "azure-openai":
|
|
30
|
-
return "openai"; // Azure uses OpenAI models
|
|
31
|
-
case "google-ai":
|
|
32
|
-
case "google-studio":
|
|
33
|
-
return "google";
|
|
34
|
-
case "huggingface":
|
|
35
|
-
case "hugging-face":
|
|
36
|
-
case "hf":
|
|
37
|
-
return "huggingface";
|
|
38
|
-
case "ollama":
|
|
39
|
-
case "local":
|
|
40
|
-
case "local-ollama":
|
|
41
|
-
return "ollama";
|
|
42
|
-
case "mistral":
|
|
43
|
-
case "mistral-ai":
|
|
44
|
-
case "mistralai":
|
|
45
|
-
return "mistral";
|
|
46
|
-
default:
|
|
47
|
-
return providerName.toLowerCase();
|
|
15
|
+
// Use ProviderFactory registration - no more legacy switch statements
|
|
16
|
+
const normalized = ProviderFactory.normalizeProviderName(providerName);
|
|
17
|
+
if (normalized) {
|
|
18
|
+
return normalized;
|
|
48
19
|
}
|
|
20
|
+
// If not found in factory, return as-is (will be handled by factory error handling)
|
|
21
|
+
return providerName.toLowerCase();
|
|
49
22
|
}
|
|
50
23
|
/**
|
|
51
24
|
* Create a provider instance for the specified provider type
|
|
@@ -54,8 +27,9 @@ export class AIProviderFactory {
|
|
|
54
27
|
* @param enableMCP - Optional flag to enable MCP integration (default: true)
|
|
55
28
|
* @returns AIProvider instance
|
|
56
29
|
*/
|
|
57
|
-
static async createProvider(providerName, modelName, enableMCP = true) {
|
|
58
|
-
const functionTag = "
|
|
30
|
+
static async createProvider(providerName, modelName, enableMCP = true, sdk) {
|
|
31
|
+
const functionTag = "AIawait ProviderFactory.createProvider";
|
|
32
|
+
// Providers are registered via ProviderFactory.initialize() on first use
|
|
59
33
|
logger.debug(`[${functionTag}] Provider creation started`, {
|
|
60
34
|
providerName,
|
|
61
35
|
modelName: modelName || "default",
|
|
@@ -114,53 +88,18 @@ export class AIProviderFactory {
|
|
|
114
88
|
// }
|
|
115
89
|
// }
|
|
116
90
|
let provider;
|
|
117
|
-
switch
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
case "gpt":
|
|
130
|
-
provider = new OpenAI(resolvedModelName === "default" ? null : resolvedModelName);
|
|
131
|
-
break;
|
|
132
|
-
case "anthropic":
|
|
133
|
-
case "claude":
|
|
134
|
-
provider = new AnthropicProvider();
|
|
135
|
-
break;
|
|
136
|
-
case "azure":
|
|
137
|
-
case "azure-openai":
|
|
138
|
-
provider = new AzureOpenAIProvider();
|
|
139
|
-
break;
|
|
140
|
-
case "google-ai":
|
|
141
|
-
case "google-studio":
|
|
142
|
-
provider = new GoogleAIStudio(resolvedModelName === "default" ? null : resolvedModelName);
|
|
143
|
-
break;
|
|
144
|
-
case "huggingface":
|
|
145
|
-
case "hugging-face":
|
|
146
|
-
case "hf":
|
|
147
|
-
provider = new HuggingFace(resolvedModelName === "default" ? null : resolvedModelName);
|
|
148
|
-
break;
|
|
149
|
-
case "ollama":
|
|
150
|
-
case "local":
|
|
151
|
-
case "local-ollama":
|
|
152
|
-
provider = new Ollama(resolvedModelName === "default"
|
|
153
|
-
? undefined
|
|
154
|
-
: resolvedModelName || undefined);
|
|
155
|
-
break;
|
|
156
|
-
case "mistral":
|
|
157
|
-
case "mistral-ai":
|
|
158
|
-
case "mistralai":
|
|
159
|
-
provider = new MistralAI(resolvedModelName === "default" ? null : resolvedModelName);
|
|
160
|
-
break;
|
|
161
|
-
default:
|
|
162
|
-
throw new Error(`Unknown provider: ${providerName}. Supported providers: vertex, bedrock, openai, anthropic, azure, google-ai, huggingface, ollama, mistral`);
|
|
163
|
-
}
|
|
91
|
+
// PURE FACTORY PATTERN: No switch statements - use ProviderFactory exclusively
|
|
92
|
+
const normalizedName = this.normalizeProviderName(providerName);
|
|
93
|
+
const finalModelName = resolvedModelName === "default" || resolvedModelName === null
|
|
94
|
+
? undefined
|
|
95
|
+
: resolvedModelName;
|
|
96
|
+
provider = await ProviderFactory.createProvider(normalizedName, finalModelName, sdk);
|
|
97
|
+
logger.debug(componentIdentifier, "Pure factory pattern provider created", {
|
|
98
|
+
providerName: normalizedName,
|
|
99
|
+
modelName: finalModelName,
|
|
100
|
+
factoryUsed: true,
|
|
101
|
+
});
|
|
102
|
+
// PURE FACTORY PATTERN: All providers handled by ProviderFactory - no switch statements needed
|
|
164
103
|
// Wrap with MCP if enabled
|
|
165
104
|
if (enableMCP) {
|
|
166
105
|
try {
|
|
@@ -182,7 +121,7 @@ export class AIProviderFactory {
|
|
|
182
121
|
}
|
|
183
122
|
logger.debug(`[${functionTag}] Provider creation succeeded`, {
|
|
184
123
|
providerName,
|
|
185
|
-
modelName:
|
|
124
|
+
modelName: finalModelName || "default",
|
|
186
125
|
providerType: provider.constructor.name,
|
|
187
126
|
mcpEnabled: enableMCP,
|
|
188
127
|
});
|
|
@@ -205,7 +144,7 @@ export class AIProviderFactory {
|
|
|
205
144
|
* @returns AIProvider instance
|
|
206
145
|
*/
|
|
207
146
|
static async createProviderWithModel(provider, model) {
|
|
208
|
-
const functionTag = "
|
|
147
|
+
const functionTag = "AIawait ProviderFactory.createProviderWithModel";
|
|
209
148
|
logger.debug(`[${functionTag}] Provider model creation started`, {
|
|
210
149
|
provider,
|
|
211
150
|
model,
|
|
@@ -236,7 +175,7 @@ export class AIProviderFactory {
|
|
|
236
175
|
* @param enableMCP - Optional flag to enable MCP integration (default: true)
|
|
237
176
|
* @returns AIProvider instance
|
|
238
177
|
*/
|
|
239
|
-
static async createBestProvider(requestedProvider, modelName, enableMCP = true) {
|
|
178
|
+
static async createBestProvider(requestedProvider, modelName, enableMCP = true, sdk) {
|
|
240
179
|
const functionTag = "AIProviderFactory.createBestProvider";
|
|
241
180
|
try {
|
|
242
181
|
const bestProvider = await getBestProvider(requestedProvider);
|
|
@@ -246,7 +185,7 @@ export class AIProviderFactory {
|
|
|
246
185
|
modelName: modelName || "default",
|
|
247
186
|
enableMCP,
|
|
248
187
|
});
|
|
249
|
-
return await this.createProvider(bestProvider, modelName, enableMCP);
|
|
188
|
+
return await this.createProvider(bestProvider, modelName, enableMCP, sdk);
|
|
250
189
|
}
|
|
251
190
|
catch (error) {
|
|
252
191
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
@@ -266,7 +205,7 @@ export class AIProviderFactory {
|
|
|
266
205
|
* @returns Object with primary and fallback providers
|
|
267
206
|
*/
|
|
268
207
|
static async createProviderWithFallback(primaryProvider, fallbackProvider, modelName, enableMCP = true) {
|
|
269
|
-
const functionTag = "
|
|
208
|
+
const functionTag = "AIawait ProviderFactory.createProviderWithFallback";
|
|
270
209
|
logger.debug(`[${functionTag}] Fallback provider setup started`, {
|
|
271
210
|
primaryProvider,
|
|
272
211
|
fallbackProvider,
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service Registry for Dependency Injection
|
|
3
|
+
* Breaks circular dependencies by providing lazy loading and centralized service management
|
|
4
|
+
*/
|
|
5
|
+
export interface ServiceFactory<T = any> {
|
|
6
|
+
(): T | Promise<T>;
|
|
7
|
+
}
|
|
8
|
+
export interface ServiceRegistration {
|
|
9
|
+
factory: ServiceFactory;
|
|
10
|
+
singleton: boolean;
|
|
11
|
+
instance?: any;
|
|
12
|
+
}
|
|
13
|
+
export declare class ServiceRegistry {
|
|
14
|
+
private static services;
|
|
15
|
+
private static initializing;
|
|
16
|
+
/**
|
|
17
|
+
* Register a service with optional singleton behavior
|
|
18
|
+
*/
|
|
19
|
+
static register<T>(name: string, factory: ServiceFactory<T>, options?: {
|
|
20
|
+
singleton?: boolean;
|
|
21
|
+
}): void;
|
|
22
|
+
/**
|
|
23
|
+
* Get a service instance with circular dependency detection
|
|
24
|
+
*/
|
|
25
|
+
static get<T>(name: string): Promise<T>;
|
|
26
|
+
/**
|
|
27
|
+
* Get a service synchronously (throws if async initialization required)
|
|
28
|
+
*/
|
|
29
|
+
static getSync<T>(name: string): T;
|
|
30
|
+
/**
|
|
31
|
+
* Check if a service is registered
|
|
32
|
+
*/
|
|
33
|
+
static has(name: string): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Clear all services (useful for testing)
|
|
36
|
+
*/
|
|
37
|
+
static clear(): void;
|
|
38
|
+
/**
|
|
39
|
+
* Get all registered service names
|
|
40
|
+
*/
|
|
41
|
+
static getRegisteredServices(): string[];
|
|
42
|
+
/**
|
|
43
|
+
* Register multiple services at once
|
|
44
|
+
*/
|
|
45
|
+
static registerBatch(services: Record<string, ServiceFactory>): void;
|
|
46
|
+
}
|
|
47
|
+
export declare const serviceRegistry: typeof ServiceRegistry;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service Registry for Dependency Injection
|
|
3
|
+
* Breaks circular dependencies by providing lazy loading and centralized service management
|
|
4
|
+
*/
|
|
5
|
+
import { logger } from "../utils/logger.js";
|
|
6
|
+
export class ServiceRegistry {
|
|
7
|
+
static services = new Map();
|
|
8
|
+
static initializing = new Set();
|
|
9
|
+
/**
|
|
10
|
+
* Register a service with optional singleton behavior
|
|
11
|
+
*/
|
|
12
|
+
static register(name, factory, options = {}) {
|
|
13
|
+
if (this.services.has(name)) {
|
|
14
|
+
logger.warn(`Service ${name} is already registered. Overwriting.`);
|
|
15
|
+
}
|
|
16
|
+
this.services.set(name, {
|
|
17
|
+
factory,
|
|
18
|
+
singleton: options.singleton ?? true,
|
|
19
|
+
instance: undefined,
|
|
20
|
+
});
|
|
21
|
+
logger.debug(`Service registered: ${name} (singleton: ${options.singleton ?? true})`);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Get a service instance with circular dependency detection
|
|
25
|
+
*/
|
|
26
|
+
static async get(name) {
|
|
27
|
+
const registration = this.services.get(name);
|
|
28
|
+
if (!registration) {
|
|
29
|
+
throw new Error(`Service ${name} not registered. Available services: ${Array.from(this.services.keys()).join(", ")}`);
|
|
30
|
+
}
|
|
31
|
+
// Check for circular dependency
|
|
32
|
+
if (this.initializing.has(name)) {
|
|
33
|
+
throw new Error(`Circular dependency detected: ${name} is already being initialized. Chain: ${Array.from(this.initializing).join(" -> ")} -> ${name}`);
|
|
34
|
+
}
|
|
35
|
+
// Return existing singleton instance if available
|
|
36
|
+
if (registration.singleton && registration.instance !== undefined) {
|
|
37
|
+
return registration.instance;
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
// Mark as initializing to detect circular dependencies
|
|
41
|
+
this.initializing.add(name);
|
|
42
|
+
logger.debug(`Initializing service: ${name}`);
|
|
43
|
+
// Create new instance
|
|
44
|
+
const instance = await registration.factory();
|
|
45
|
+
// Store singleton instance
|
|
46
|
+
if (registration.singleton) {
|
|
47
|
+
registration.instance = instance;
|
|
48
|
+
}
|
|
49
|
+
logger.debug(`Service initialized: ${name}`);
|
|
50
|
+
return instance;
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
logger.error(`Failed to initialize service ${name}:`, error);
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
// Remove from initializing set
|
|
58
|
+
this.initializing.delete(name);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Get a service synchronously (throws if async initialization required)
|
|
63
|
+
*/
|
|
64
|
+
static getSync(name) {
|
|
65
|
+
const registration = this.services.get(name);
|
|
66
|
+
if (!registration) {
|
|
67
|
+
throw new Error(`Service ${name} not registered`);
|
|
68
|
+
}
|
|
69
|
+
if (registration.singleton && registration.instance !== undefined) {
|
|
70
|
+
return registration.instance;
|
|
71
|
+
}
|
|
72
|
+
// Try synchronous initialization
|
|
73
|
+
const result = registration.factory();
|
|
74
|
+
if (result instanceof Promise) {
|
|
75
|
+
throw new Error(`Service ${name} requires asynchronous initialization. Use get() instead.`);
|
|
76
|
+
}
|
|
77
|
+
if (registration.singleton) {
|
|
78
|
+
registration.instance = result;
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Check if a service is registered
|
|
84
|
+
*/
|
|
85
|
+
static has(name) {
|
|
86
|
+
return this.services.has(name);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Clear all services (useful for testing)
|
|
90
|
+
*/
|
|
91
|
+
static clear() {
|
|
92
|
+
this.services.clear();
|
|
93
|
+
this.initializing.clear();
|
|
94
|
+
logger.debug("Service registry cleared");
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Get all registered service names
|
|
98
|
+
*/
|
|
99
|
+
static getRegisteredServices() {
|
|
100
|
+
return Array.from(this.services.keys());
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Register multiple services at once
|
|
104
|
+
*/
|
|
105
|
+
static registerBatch(services) {
|
|
106
|
+
for (const [name, factory] of Object.entries(services)) {
|
|
107
|
+
this.register(name, factory);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// Export singleton instance for convenience
|
|
112
|
+
export const serviceRegistry = ServiceRegistry;
|
package/dist/lib/core/types.d.ts
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
import type { ZodType, ZodTypeDef } from "zod";
|
|
2
|
-
import type {
|
|
2
|
+
import type { Schema, Tool } from "ai";
|
|
3
|
+
import type { GenerateResult } from "../types/generate-types.js";
|
|
4
|
+
import type { StreamOptions, StreamResult } from "../types/stream-types.js";
|
|
5
|
+
export interface TextGenerationResult {
|
|
6
|
+
content: string;
|
|
7
|
+
provider?: string;
|
|
8
|
+
model?: string;
|
|
9
|
+
usage?: {
|
|
10
|
+
promptTokens?: number;
|
|
11
|
+
completionTokens?: number;
|
|
12
|
+
totalTokens?: number;
|
|
13
|
+
};
|
|
14
|
+
responseTime?: number;
|
|
15
|
+
toolsUsed?: string[];
|
|
16
|
+
toolExecutions?: Array<{
|
|
17
|
+
toolName: string;
|
|
18
|
+
executionTime: number;
|
|
19
|
+
success: boolean;
|
|
20
|
+
serverId?: string;
|
|
21
|
+
}>;
|
|
22
|
+
enhancedWithTools?: boolean;
|
|
23
|
+
availableTools?: Array<{
|
|
24
|
+
name: string;
|
|
25
|
+
description: string;
|
|
26
|
+
server: string;
|
|
27
|
+
category?: string;
|
|
28
|
+
}>;
|
|
29
|
+
analytics?: any;
|
|
30
|
+
evaluation?: any;
|
|
31
|
+
}
|
|
3
32
|
/**
|
|
4
33
|
* Supported AI Provider Names
|
|
5
34
|
*/
|
|
@@ -12,7 +41,8 @@ export declare enum AIProviderName {
|
|
|
12
41
|
GOOGLE_AI = "google-ai",
|
|
13
42
|
HUGGINGFACE = "huggingface",
|
|
14
43
|
OLLAMA = "ollama",
|
|
15
|
-
MISTRAL = "mistral"
|
|
44
|
+
MISTRAL = "mistral",
|
|
45
|
+
AUTO = "auto"
|
|
16
46
|
}
|
|
17
47
|
/**
|
|
18
48
|
* Supported Models for Amazon Bedrock
|
|
@@ -72,29 +102,11 @@ export interface StreamingOptions {
|
|
|
72
102
|
* Text generation options interface
|
|
73
103
|
*/
|
|
74
104
|
export interface TextGenerationOptions {
|
|
75
|
-
prompt
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
schema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>;
|
|
81
|
-
tools?: Record<string, Tool>;
|
|
82
|
-
timeout?: number | string;
|
|
83
|
-
enableEvaluation?: boolean;
|
|
84
|
-
enableAnalytics?: boolean;
|
|
85
|
-
context?: Record<string, any>;
|
|
86
|
-
evaluationDomain?: string;
|
|
87
|
-
toolUsageContext?: string;
|
|
88
|
-
conversationHistory?: Array<{
|
|
89
|
-
role: string;
|
|
90
|
-
content: string;
|
|
91
|
-
}>;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Stream text options interface
|
|
95
|
-
*/
|
|
96
|
-
export interface StreamTextOptions {
|
|
97
|
-
prompt: string;
|
|
105
|
+
prompt?: string;
|
|
106
|
+
input?: {
|
|
107
|
+
text: string;
|
|
108
|
+
};
|
|
109
|
+
provider?: AIProviderName;
|
|
98
110
|
model?: string;
|
|
99
111
|
temperature?: number;
|
|
100
112
|
maxTokens?: number;
|
|
@@ -102,6 +114,8 @@ export interface StreamTextOptions {
|
|
|
102
114
|
schema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>;
|
|
103
115
|
tools?: Record<string, Tool>;
|
|
104
116
|
timeout?: number | string;
|
|
117
|
+
disableTools?: boolean;
|
|
118
|
+
maxSteps?: number;
|
|
105
119
|
enableEvaluation?: boolean;
|
|
106
120
|
enableAnalytics?: boolean;
|
|
107
121
|
context?: Record<string, any>;
|
|
@@ -133,10 +147,13 @@ export interface AnalyticsData {
|
|
|
133
147
|
* Updated to match Lighthouse's exact evaluation interface for consistency
|
|
134
148
|
*/
|
|
135
149
|
export interface EvaluationData {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
150
|
+
relevance: number;
|
|
151
|
+
accuracy: number;
|
|
152
|
+
completeness: number;
|
|
139
153
|
overall: number;
|
|
154
|
+
domainAlignment?: number;
|
|
155
|
+
terminologyAccuracy?: number;
|
|
156
|
+
toolEffectiveness?: number;
|
|
140
157
|
isOffTopic: boolean;
|
|
141
158
|
alertSeverity: "low" | "medium" | "high" | "none";
|
|
142
159
|
reasoning: string;
|
|
@@ -207,11 +224,7 @@ export interface ProviderModelConfig {
|
|
|
207
224
|
/**
|
|
208
225
|
* Enhanced result interfaces with optional analytics/evaluation
|
|
209
226
|
*/
|
|
210
|
-
export interface
|
|
211
|
-
analytics?: AnalyticsData;
|
|
212
|
-
evaluation?: EvaluationData;
|
|
213
|
-
}
|
|
214
|
-
export interface EnhancedStreamTextResult extends StreamTextResult<ToolSet, unknown> {
|
|
227
|
+
export interface EnhancedGenerateResult extends GenerateResult {
|
|
215
228
|
analytics?: AnalyticsData;
|
|
216
229
|
evaluation?: EvaluationData;
|
|
217
230
|
}
|
|
@@ -240,26 +253,13 @@ export interface StreamingMetadata {
|
|
|
240
253
|
modelUsed: string;
|
|
241
254
|
}
|
|
242
255
|
export type ProgressCallback = (progress: StreamingProgressData) => void;
|
|
243
|
-
export interface EnhancedStreamTextOptions extends StreamTextOptions {
|
|
244
|
-
enableProgressTracking?: boolean;
|
|
245
|
-
progressCallback?: ProgressCallback;
|
|
246
|
-
includeStreamingMetadata?: boolean;
|
|
247
|
-
streamingBufferSize?: number;
|
|
248
|
-
enableStreamingHeaders?: boolean;
|
|
249
|
-
customStreamingConfig?: {
|
|
250
|
-
chunkDelayMs?: number;
|
|
251
|
-
maxConcurrentChunks?: number;
|
|
252
|
-
compressionEnabled?: boolean;
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
256
|
/**
|
|
256
257
|
* AI Provider interface with flexible parameter support
|
|
257
258
|
*/
|
|
258
259
|
export interface AIProvider {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
gen(optionsOrPrompt: TextGenerationOptions | string, analysisSchema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>): Promise<EnhancedGenerateTextResult | null>;
|
|
260
|
+
stream(optionsOrPrompt: StreamOptions | string, analysisSchema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>): Promise<StreamResult>;
|
|
261
|
+
generate(optionsOrPrompt: TextGenerationOptions | string, analysisSchema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>): Promise<EnhancedGenerateResult | null>;
|
|
262
|
+
gen(optionsOrPrompt: TextGenerationOptions | string, analysisSchema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>): Promise<EnhancedGenerateResult | null>;
|
|
263
263
|
}
|
|
264
264
|
/**
|
|
265
265
|
* Provider attempt result for iteration tracking
|
package/dist/lib/core/types.js
CHANGED
|
@@ -12,6 +12,7 @@ export var AIProviderName;
|
|
|
12
12
|
AIProviderName["HUGGINGFACE"] = "huggingface";
|
|
13
13
|
AIProviderName["OLLAMA"] = "ollama";
|
|
14
14
|
AIProviderName["MISTRAL"] = "mistral";
|
|
15
|
+
AIProviderName["AUTO"] = "auto";
|
|
15
16
|
})(AIProviderName || (AIProviderName = {}));
|
|
16
17
|
/**
|
|
17
18
|
* Supported Models for Amazon Bedrock
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { GenerateOptions, GenerateResult } from "../types/generate-types.js";
|
|
2
|
+
import type { TextGenerationOptions } from "../core/types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Compatibility conversion factory for seamless migration
|
|
5
|
+
* between generateText and generate functions
|
|
6
|
+
*/
|
|
7
|
+
export declare class CompatibilityConversionFactory {
|
|
8
|
+
/**
|
|
9
|
+
* Convert TextGenerationOptions to GenerateOptions
|
|
10
|
+
*/
|
|
11
|
+
static convertTextToGenerate(options: TextGenerationOptions): GenerateOptions;
|
|
12
|
+
/**
|
|
13
|
+
* Convert GenerateResult to legacy TextGenerationResult format
|
|
14
|
+
*/
|
|
15
|
+
static convertGenerateToText(result: GenerateResult): any;
|
|
16
|
+
/**
|
|
17
|
+
* Convert GenerateOptions to TextGenerationOptions
|
|
18
|
+
*/
|
|
19
|
+
static convertGenerateToText_Options(options: GenerateOptions): TextGenerationOptions;
|
|
20
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compatibility conversion factory for seamless migration
|
|
3
|
+
* between generateText and generate functions
|
|
4
|
+
*/
|
|
5
|
+
export class CompatibilityConversionFactory {
|
|
6
|
+
/**
|
|
7
|
+
* Convert TextGenerationOptions to GenerateOptions
|
|
8
|
+
*/
|
|
9
|
+
static convertTextToGenerate(options) {
|
|
10
|
+
const { prompt, ...rest } = options;
|
|
11
|
+
return {
|
|
12
|
+
input: { text: prompt || "" },
|
|
13
|
+
output: { format: "text" },
|
|
14
|
+
provider: rest.provider,
|
|
15
|
+
model: rest.model,
|
|
16
|
+
temperature: rest.temperature,
|
|
17
|
+
maxTokens: rest.maxTokens,
|
|
18
|
+
systemPrompt: rest.systemPrompt,
|
|
19
|
+
schema: rest.schema,
|
|
20
|
+
tools: rest.tools,
|
|
21
|
+
timeout: rest.timeout,
|
|
22
|
+
enableEvaluation: rest.enableEvaluation,
|
|
23
|
+
enableAnalytics: rest.enableAnalytics,
|
|
24
|
+
context: rest.context,
|
|
25
|
+
evaluationDomain: rest.evaluationDomain,
|
|
26
|
+
toolUsageContext: rest.toolUsageContext,
|
|
27
|
+
conversationHistory: rest.conversationHistory,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Convert GenerateResult to legacy TextGenerationResult format
|
|
32
|
+
*/
|
|
33
|
+
static convertGenerateToText(result) {
|
|
34
|
+
return {
|
|
35
|
+
content: result.content,
|
|
36
|
+
provider: result.provider,
|
|
37
|
+
model: result.model,
|
|
38
|
+
usage: result.usage,
|
|
39
|
+
responseTime: result.responseTime,
|
|
40
|
+
toolsUsed: result.toolsUsed,
|
|
41
|
+
toolExecutions: result.toolExecutions,
|
|
42
|
+
enhancedWithTools: result.enhancedWithTools,
|
|
43
|
+
availableTools: result.availableTools,
|
|
44
|
+
analytics: result.analytics,
|
|
45
|
+
evaluation: result.evaluation,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Convert GenerateOptions to TextGenerationOptions
|
|
50
|
+
*/
|
|
51
|
+
static convertGenerateToText_Options(options) {
|
|
52
|
+
return {
|
|
53
|
+
prompt: options.input.text,
|
|
54
|
+
model: options.model,
|
|
55
|
+
temperature: options.temperature,
|
|
56
|
+
maxTokens: options.maxTokens,
|
|
57
|
+
systemPrompt: options.systemPrompt,
|
|
58
|
+
schema: options.schema,
|
|
59
|
+
tools: options.tools,
|
|
60
|
+
timeout: options.timeout,
|
|
61
|
+
enableEvaluation: options.enableEvaluation,
|
|
62
|
+
enableAnalytics: options.enableAnalytics,
|
|
63
|
+
context: options.context,
|
|
64
|
+
evaluationDomain: options.evaluationDomain,
|
|
65
|
+
toolUsageContext: options.toolUsageContext,
|
|
66
|
+
conversationHistory: options.conversationHistory,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|