@juspay/neurolink 5.0.0 → 5.1.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 +7 -0
- package/README.md +51 -60
- package/dist/chat/sse-handler.js +5 -4
- package/dist/chat/websocket-chat-handler.js +9 -9
- package/dist/cli/commands/mcp.js +1 -1
- package/dist/cli/commands/ollama.js +3 -3
- package/dist/cli/factories/command-factory.d.ts +14 -0
- package/dist/cli/factories/command-factory.js +129 -0
- package/dist/cli/index.js +27 -26
- package/dist/cli/utils/interactive-setup.js +2 -2
- package/dist/core/evaluation.d.ts +9 -9
- package/dist/core/evaluation.js +14 -14
- package/dist/core/types.d.ts +41 -48
- 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-generate-factory.d.ts +20 -0
- package/dist/factories/provider-generate-factory.js +87 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +3 -1
- package/dist/lib/chat/sse-handler.js +5 -4
- package/dist/lib/chat/websocket-chat-handler.js +9 -9
- package/dist/lib/core/evaluation.d.ts +9 -9
- package/dist/lib/core/evaluation.js +14 -14
- package/dist/lib/core/types.d.ts +41 -48
- 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-generate-factory.d.ts +20 -0
- package/dist/lib/factories/provider-generate-factory.js +87 -0
- package/dist/lib/index.d.ts +4 -2
- package/dist/lib/index.js +3 -1
- package/dist/lib/mcp/client.js +5 -5
- 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/neurolink-mcp-client.js +10 -10
- package/dist/lib/mcp/orchestrator.js +4 -4
- package/dist/lib/mcp/servers/ai-providers/ai-analysis-tools.js +10 -10
- package/dist/lib/mcp/servers/ai-providers/ai-core-server.js +5 -5
- 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/neurolink.d.ts +21 -73
- package/dist/lib/neurolink.js +230 -119
- package/dist/lib/providers/agent-enhanced-provider.d.ts +12 -8
- package/dist/lib/providers/agent-enhanced-provider.js +87 -96
- package/dist/lib/providers/amazonBedrock.d.ts +17 -8
- package/dist/lib/providers/amazonBedrock.js +60 -30
- package/dist/lib/providers/anthropic.d.ts +14 -10
- package/dist/lib/providers/anthropic.js +84 -154
- package/dist/lib/providers/azureOpenAI.d.ts +9 -6
- package/dist/lib/providers/azureOpenAI.js +70 -159
- 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/googleAIStudio.d.ts +12 -19
- package/dist/lib/providers/googleAIStudio.js +65 -34
- package/dist/lib/providers/googleVertexAI.d.ts +11 -15
- package/dist/lib/providers/googleVertexAI.js +146 -118
- package/dist/lib/providers/huggingFace.d.ts +10 -11
- package/dist/lib/providers/huggingFace.js +61 -24
- package/dist/lib/providers/mcp-provider.d.ts +13 -8
- package/dist/lib/providers/mcp-provider.js +59 -18
- package/dist/lib/providers/mistralAI.d.ts +14 -11
- package/dist/lib/providers/mistralAI.js +60 -29
- package/dist/lib/providers/ollama.d.ts +9 -8
- package/dist/lib/providers/ollama.js +134 -91
- package/dist/lib/providers/openAI.d.ts +11 -12
- package/dist/lib/providers/openAI.js +132 -97
- package/dist/lib/types/generate-types.d.ts +79 -0
- package/dist/lib/types/generate-types.js +1 -0
- package/dist/lib/types/stream-types.d.ts +83 -0
- package/dist/lib/types/stream-types.js +1 -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/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/neurolink-mcp-client.js +10 -10
- package/dist/mcp/orchestrator.js +4 -4
- package/dist/mcp/servers/ai-providers/ai-analysis-tools.js +10 -10
- package/dist/mcp/servers/ai-providers/ai-core-server.js +5 -5
- 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/neurolink.d.ts +21 -73
- package/dist/neurolink.js +230 -119
- package/dist/providers/agent-enhanced-provider.d.ts +12 -8
- package/dist/providers/agent-enhanced-provider.js +87 -95
- package/dist/providers/amazonBedrock.d.ts +17 -8
- package/dist/providers/amazonBedrock.js +60 -30
- package/dist/providers/anthropic.d.ts +14 -10
- package/dist/providers/anthropic.js +84 -154
- package/dist/providers/azureOpenAI.d.ts +9 -6
- package/dist/providers/azureOpenAI.js +70 -159
- package/dist/providers/function-calling-provider.d.ts +14 -12
- package/dist/providers/function-calling-provider.js +114 -64
- package/dist/providers/googleAIStudio.d.ts +12 -19
- package/dist/providers/googleAIStudio.js +65 -34
- package/dist/providers/googleVertexAI.d.ts +11 -15
- package/dist/providers/googleVertexAI.js +146 -118
- package/dist/providers/huggingFace.d.ts +10 -11
- package/dist/providers/huggingFace.js +61 -24
- package/dist/providers/mcp-provider.d.ts +13 -8
- package/dist/providers/mcp-provider.js +59 -18
- package/dist/providers/mistralAI.d.ts +14 -11
- package/dist/providers/mistralAI.js +60 -29
- package/dist/providers/ollama.d.ts +9 -8
- package/dist/providers/ollama.js +133 -90
- package/dist/providers/openAI.d.ts +11 -12
- package/dist/providers/openAI.js +132 -97
- package/dist/types/generate-types.d.ts +79 -0
- package/dist/types/generate-types.js +1 -0
- package/dist/types/stream-types.d.ts +83 -0
- package/dist/types/stream-types.js +1 -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 +1 -1
|
@@ -16,17 +16,17 @@ import { z } from "zod";
|
|
|
16
16
|
*/
|
|
17
17
|
export const unifiedEvaluationSchema = z.object({
|
|
18
18
|
// Core evaluation scores
|
|
19
|
-
|
|
19
|
+
relevance: z
|
|
20
20
|
.number()
|
|
21
21
|
.min(0)
|
|
22
22
|
.max(10)
|
|
23
23
|
.describe("Score (0-10) for how well the response addresses query intent and aligns with domain/role. 10 is most relevant."),
|
|
24
|
-
|
|
24
|
+
accuracy: z
|
|
25
25
|
.number()
|
|
26
26
|
.min(0)
|
|
27
27
|
.max(10)
|
|
28
28
|
.describe("Score (0-10) for factual correctness against data, tool outputs, and domain knowledge. 10 is most accurate."),
|
|
29
|
-
|
|
29
|
+
completeness: z
|
|
30
30
|
.number()
|
|
31
31
|
.min(0)
|
|
32
32
|
.max(10)
|
|
@@ -113,8 +113,8 @@ export async function performUnifiedEvaluation(context) {
|
|
|
113
113
|
}
|
|
114
114
|
catch (structuredError) {
|
|
115
115
|
logger.warn(`[${functionTag}] Structured evaluation failed, using fallback`, { structuredError });
|
|
116
|
-
// Fallback to legacy
|
|
117
|
-
const result = await evaluationModel.
|
|
116
|
+
// Fallback to legacy generate
|
|
117
|
+
const result = await evaluationModel.generate({
|
|
118
118
|
prompt: evaluationPrompt + "\n\nRespond with valid JSON only.",
|
|
119
119
|
temperature: 0.1,
|
|
120
120
|
maxTokens: 1000,
|
|
@@ -302,9 +302,9 @@ function processStructuredEvaluationResult(result, modelConfig, evaluationTime,
|
|
|
302
302
|
const overall = Math.round(allScores.reduce((sum, score) => sum + score, 0) / allScores.length);
|
|
303
303
|
return {
|
|
304
304
|
// Core scores
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
305
|
+
relevance: Math.max(0, Math.min(10, Math.round(result.relevanceScore || 0))),
|
|
306
|
+
accuracy: Math.max(0, Math.min(10, Math.round(result.accuracyScore || 0))),
|
|
307
|
+
completeness: Math.max(0, Math.min(10, Math.round(result.completenessScore || 0))),
|
|
308
308
|
overall: Math.max(0, Math.min(10, overall)),
|
|
309
309
|
// Enhanced insights
|
|
310
310
|
isOffTopic: result.isOffTopic || false,
|
|
@@ -372,9 +372,9 @@ function parseUnifiedEvaluationResult(evaluationText, modelConfig, evaluationTim
|
|
|
372
372
|
? parseInt(completenessMatch[1] || completenessMatch[2] || completenessMatch[3], 10)
|
|
373
373
|
: 8; // Default fallback score
|
|
374
374
|
return {
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
375
|
+
relevance: Math.max(0, Math.min(10, relevance)),
|
|
376
|
+
accuracy: Math.max(0, Math.min(10, accuracy)),
|
|
377
|
+
completeness: Math.max(0, Math.min(10, completeness)),
|
|
378
378
|
overall: Math.round((relevance + accuracy + completeness) / 3),
|
|
379
379
|
isOffTopic: false,
|
|
380
380
|
alertSeverity: "none",
|
|
@@ -400,9 +400,9 @@ function parseUnifiedEvaluationResult(evaluationText, modelConfig, evaluationTim
|
|
|
400
400
|
*/
|
|
401
401
|
function getDefaultUnifiedEvaluation(reason, evaluationTime, context) {
|
|
402
402
|
return {
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
403
|
+
relevance: 0,
|
|
404
|
+
accuracy: 0,
|
|
405
|
+
completeness: 0,
|
|
406
406
|
overall: 0,
|
|
407
407
|
isOffTopic: false,
|
|
408
408
|
alertSeverity: "high",
|
package/dist/lib/core/types.d.ts
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
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
|
+
}
|
|
3
30
|
/**
|
|
4
31
|
* Supported AI Provider Names
|
|
5
32
|
*/
|
|
@@ -12,7 +39,8 @@ export declare enum AIProviderName {
|
|
|
12
39
|
GOOGLE_AI = "google-ai",
|
|
13
40
|
HUGGINGFACE = "huggingface",
|
|
14
41
|
OLLAMA = "ollama",
|
|
15
|
-
MISTRAL = "mistral"
|
|
42
|
+
MISTRAL = "mistral",
|
|
43
|
+
AUTO = "auto"
|
|
16
44
|
}
|
|
17
45
|
/**
|
|
18
46
|
* Supported Models for Amazon Bedrock
|
|
@@ -73,28 +101,7 @@ export interface StreamingOptions {
|
|
|
73
101
|
*/
|
|
74
102
|
export interface TextGenerationOptions {
|
|
75
103
|
prompt: string;
|
|
76
|
-
|
|
77
|
-
temperature?: number;
|
|
78
|
-
maxTokens?: number;
|
|
79
|
-
systemPrompt?: string;
|
|
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;
|
|
104
|
+
provider?: AIProviderName;
|
|
98
105
|
model?: string;
|
|
99
106
|
temperature?: number;
|
|
100
107
|
maxTokens?: number;
|
|
@@ -133,10 +140,13 @@ export interface AnalyticsData {
|
|
|
133
140
|
* Updated to match Lighthouse's exact evaluation interface for consistency
|
|
134
141
|
*/
|
|
135
142
|
export interface EvaluationData {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
143
|
+
relevance: number;
|
|
144
|
+
accuracy: number;
|
|
145
|
+
completeness: number;
|
|
139
146
|
overall: number;
|
|
147
|
+
domainAlignment?: number;
|
|
148
|
+
terminologyAccuracy?: number;
|
|
149
|
+
toolEffectiveness?: number;
|
|
140
150
|
isOffTopic: boolean;
|
|
141
151
|
alertSeverity: "low" | "medium" | "high" | "none";
|
|
142
152
|
reasoning: string;
|
|
@@ -207,11 +217,7 @@ export interface ProviderModelConfig {
|
|
|
207
217
|
/**
|
|
208
218
|
* Enhanced result interfaces with optional analytics/evaluation
|
|
209
219
|
*/
|
|
210
|
-
export interface
|
|
211
|
-
analytics?: AnalyticsData;
|
|
212
|
-
evaluation?: EvaluationData;
|
|
213
|
-
}
|
|
214
|
-
export interface EnhancedStreamTextResult extends StreamTextResult<ToolSet, unknown> {
|
|
220
|
+
export interface EnhancedGenerateResult extends GenerateResult {
|
|
215
221
|
analytics?: AnalyticsData;
|
|
216
222
|
evaluation?: EvaluationData;
|
|
217
223
|
}
|
|
@@ -240,26 +246,13 @@ export interface StreamingMetadata {
|
|
|
240
246
|
modelUsed: string;
|
|
241
247
|
}
|
|
242
248
|
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
249
|
/**
|
|
256
250
|
* AI Provider interface with flexible parameter support
|
|
257
251
|
*/
|
|
258
252
|
export interface AIProvider {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
gen(optionsOrPrompt: TextGenerationOptions | string, analysisSchema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>): Promise<EnhancedGenerateTextResult | null>;
|
|
253
|
+
stream(optionsOrPrompt: StreamOptions | string, analysisSchema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>): Promise<StreamResult>;
|
|
254
|
+
generate(optionsOrPrompt: TextGenerationOptions | string, analysisSchema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>): Promise<EnhancedGenerateResult | null>;
|
|
255
|
+
gen(optionsOrPrompt: TextGenerationOptions | string, analysisSchema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>): Promise<EnhancedGenerateResult | null>;
|
|
263
256
|
}
|
|
264
257
|
/**
|
|
265
258
|
* 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
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { EnhancedProvider } from "../types/generate-types.js";
|
|
2
|
+
import type { AIProvider } from "../core/types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Factory for enhancing providers with generate() capability using Proxy pattern
|
|
5
|
+
* Maintains 100% backward compatibility while adding new generate method
|
|
6
|
+
*/
|
|
7
|
+
export declare class ProviderGenerateFactory {
|
|
8
|
+
/**
|
|
9
|
+
* Enhance any provider with generate() method using TypeScript Proxy
|
|
10
|
+
*/
|
|
11
|
+
static enhanceProvider<T extends AIProvider>(provider: T): T & EnhancedProvider;
|
|
12
|
+
/**
|
|
13
|
+
* Create the generate() method that internally uses generateText for performance parity
|
|
14
|
+
*/
|
|
15
|
+
private static createGenerateMethod;
|
|
16
|
+
/**
|
|
17
|
+
* Enhance all providers from a registry
|
|
18
|
+
*/
|
|
19
|
+
static enhanceAllProviders(providers: Map<string, AIProvider>): Map<string, AIProvider & EnhancedProvider>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { CompatibilityConversionFactory } from "./compatibility-factory.js";
|
|
2
|
+
/**
|
|
3
|
+
* Factory for enhancing providers with generate() capability using Proxy pattern
|
|
4
|
+
* Maintains 100% backward compatibility while adding new generate method
|
|
5
|
+
*/
|
|
6
|
+
export class ProviderGenerateFactory {
|
|
7
|
+
/**
|
|
8
|
+
* Enhance any provider with generate() method using TypeScript Proxy
|
|
9
|
+
*/
|
|
10
|
+
static enhanceProvider(provider) {
|
|
11
|
+
return new Proxy(provider, {
|
|
12
|
+
get(target, prop, receiver) {
|
|
13
|
+
if (prop === "generate") {
|
|
14
|
+
return ProviderGenerateFactory.createGenerateMethod(target);
|
|
15
|
+
}
|
|
16
|
+
return Reflect.get(target, prop, receiver);
|
|
17
|
+
},
|
|
18
|
+
has(target, prop) {
|
|
19
|
+
if (prop === "generate") {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
return Reflect.has(target, prop);
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Create the generate() method that internally uses generateText for performance parity
|
|
28
|
+
*/
|
|
29
|
+
static createGenerateMethod(provider) {
|
|
30
|
+
return async (options) => {
|
|
31
|
+
// Validate input
|
|
32
|
+
if (!options.input?.text) {
|
|
33
|
+
throw new Error("Generate options must include input.text");
|
|
34
|
+
}
|
|
35
|
+
// Convert GenerateOptions to TextGenerationOptions
|
|
36
|
+
const textOptions = CompatibilityConversionFactory.convertGenerateToText_Options(options);
|
|
37
|
+
try {
|
|
38
|
+
// Use existing generate method for identical performance
|
|
39
|
+
const textResult = await provider.generate(textOptions);
|
|
40
|
+
// Convert back to GenerateResult format with type safety
|
|
41
|
+
const generateResult = {
|
|
42
|
+
content: textResult?.content || "",
|
|
43
|
+
outputs: { text: textResult?.content || "" },
|
|
44
|
+
provider: textResult?.provider,
|
|
45
|
+
model: textResult?.model,
|
|
46
|
+
usage: textResult?.usage
|
|
47
|
+
? {
|
|
48
|
+
inputTokens: textResult.usage?.promptTokens || 0,
|
|
49
|
+
outputTokens: textResult.usage?.completionTokens || 0,
|
|
50
|
+
totalTokens: textResult.usage?.totalTokens || 0,
|
|
51
|
+
}
|
|
52
|
+
: undefined,
|
|
53
|
+
responseTime: textResult?.responseTime,
|
|
54
|
+
toolsUsed: textResult?.toolsUsed,
|
|
55
|
+
toolExecutions: textResult?.toolExecutions?.map((te) => ({
|
|
56
|
+
name: te.toolName || te.name || "",
|
|
57
|
+
input: te.input || {},
|
|
58
|
+
output: te.output || te.result,
|
|
59
|
+
duration: te.executionTime || te.duration || 0,
|
|
60
|
+
})),
|
|
61
|
+
enhancedWithTools: textResult?.enhancedWithTools,
|
|
62
|
+
availableTools: textResult?.availableTools?.map((at) => ({
|
|
63
|
+
name: at.name || "",
|
|
64
|
+
description: at.description || "",
|
|
65
|
+
parameters: at.parameters || {},
|
|
66
|
+
})),
|
|
67
|
+
analytics: textResult?.analytics,
|
|
68
|
+
evaluation: textResult?.evaluation,
|
|
69
|
+
};
|
|
70
|
+
return generateResult;
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
throw new Error(`Generate method failed: ${error}`);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Enhance all providers from a registry
|
|
79
|
+
*/
|
|
80
|
+
static enhanceAllProviders(providers) {
|
|
81
|
+
const enhancedProviders = new Map();
|
|
82
|
+
for (const [name, provider] of providers) {
|
|
83
|
+
enhancedProviders.set(name, this.enhanceProvider(provider));
|
|
84
|
+
}
|
|
85
|
+
return enhancedProviders;
|
|
86
|
+
}
|
|
87
|
+
}
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -9,13 +9,15 @@
|
|
|
9
9
|
import { AIProviderFactory } from "./core/factory.js";
|
|
10
10
|
export { AIProviderFactory };
|
|
11
11
|
export type { AIProvider, AIProviderName, ProviderConfig, StreamingOptions, ProviderAttempt, SupportedModelName, } from "./core/types.js";
|
|
12
|
+
export type { GenerateOptions, GenerateResult, EnhancedProvider, } from "./types/generate-types.js";
|
|
13
|
+
export { CompatibilityConversionFactory } from "./factories/compatibility-factory.js";
|
|
14
|
+
export { ProviderGenerateFactory } from "./factories/provider-generate-factory.js";
|
|
12
15
|
export { BedrockModels, OpenAIModels, VertexModels, DEFAULT_PROVIDER_CONFIGS, } from "./core/types.js";
|
|
13
16
|
export { GoogleVertexAI, AmazonBedrock, OpenAI, AnthropicProvider, AzureOpenAIProvider, } from "./providers/index.js";
|
|
14
17
|
export type { ProviderName } from "./providers/index.js";
|
|
15
18
|
export { PROVIDERS, AVAILABLE_PROVIDERS } from "./providers/index.js";
|
|
16
19
|
export { getBestProvider, getAvailableProviders, isValidProvider, } from "./utils/providerUtils.js";
|
|
17
20
|
export { NeuroLink } from "./neurolink.js";
|
|
18
|
-
export type { TextGenerationOptions, StreamTextOptions, TextGenerationResult, } from "./neurolink.js";
|
|
19
21
|
export declare const VERSION = "1.0.0";
|
|
20
22
|
/**
|
|
21
23
|
* Quick start factory function
|
|
@@ -25,7 +27,7 @@ export declare const VERSION = "1.0.0";
|
|
|
25
27
|
* import { createAIProvider } from '@juspay/neurolink';
|
|
26
28
|
*
|
|
27
29
|
* const provider = await createAIProvider('bedrock');
|
|
28
|
-
* const result = await provider.
|
|
30
|
+
* const result = await provider.stream({ input: { text: 'Hello, AI!' } });
|
|
29
31
|
* ```
|
|
30
32
|
*/
|
|
31
33
|
export declare function createAIProvider(providerName?: string, modelName?: string): Promise<import("./index.js").AIProvider>;
|
package/dist/lib/index.js
CHANGED
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
// Core exports
|
|
10
10
|
import { AIProviderFactory } from "./core/factory.js";
|
|
11
11
|
export { AIProviderFactory };
|
|
12
|
+
export { CompatibilityConversionFactory } from "./factories/compatibility-factory.js";
|
|
13
|
+
export { ProviderGenerateFactory } from "./factories/provider-generate-factory.js";
|
|
12
14
|
// Model enums
|
|
13
15
|
export { BedrockModels, OpenAIModels, VertexModels, DEFAULT_PROVIDER_CONFIGS, } from "./core/types.js";
|
|
14
16
|
// Provider exports
|
|
@@ -28,7 +30,7 @@ export const VERSION = "1.0.0";
|
|
|
28
30
|
* import { createAIProvider } from '@juspay/neurolink';
|
|
29
31
|
*
|
|
30
32
|
* const provider = await createAIProvider('bedrock');
|
|
31
|
-
* const result = await provider.
|
|
33
|
+
* const result = await provider.stream({ input: { text: 'Hello, AI!' } });
|
|
32
34
|
* ```
|
|
33
35
|
*/
|
|
34
36
|
export async function createAIProvider(providerName, modelName) {
|
package/dist/lib/mcp/client.js
CHANGED
|
@@ -49,11 +49,11 @@ export class NeuroLinkMCPClient extends EventEmitter {
|
|
|
49
49
|
return result;
|
|
50
50
|
}
|
|
51
51
|
// If it's in Lighthouse format with content array
|
|
52
|
-
if (result.
|
|
53
|
-
Array.isArray(result.
|
|
54
|
-
result.
|
|
52
|
+
if (result.text &&
|
|
53
|
+
Array.isArray(result.text) &&
|
|
54
|
+
result.text[0]?.text) {
|
|
55
55
|
try {
|
|
56
|
-
const data = JSON.parse(result.
|
|
56
|
+
const data = JSON.parse(result.text[0].text);
|
|
57
57
|
return {
|
|
58
58
|
success: !result.isError,
|
|
59
59
|
data,
|
|
@@ -69,7 +69,7 @@ export class NeuroLinkMCPClient extends EventEmitter {
|
|
|
69
69
|
// If JSON parsing fails, return the text as-is
|
|
70
70
|
return {
|
|
71
71
|
success: !result.isError,
|
|
72
|
-
data: { text: result.
|
|
72
|
+
data: { text: result.text[0].text },
|
|
73
73
|
metadata: {
|
|
74
74
|
toolName,
|
|
75
75
|
serverId,
|
|
@@ -199,11 +199,11 @@ export class DynamicOrchestrator extends MCPOrchestrator {
|
|
|
199
199
|
.replace("{previousResults}", previousResults || "None yet");
|
|
200
200
|
try {
|
|
201
201
|
// Use AI Core Server to get tool decision
|
|
202
|
-
const
|
|
203
|
-
if (!
|
|
204
|
-
throw new Error("generate
|
|
202
|
+
const generateTool = aiCoreServer.tools["generate"];
|
|
203
|
+
if (!generateTool) {
|
|
204
|
+
throw new Error("generate tool not found");
|
|
205
205
|
}
|
|
206
|
-
const aiResponse = await
|
|
206
|
+
const aiResponse = await generateTool.execute({
|
|
207
207
|
prompt: "Select the next tool to execute based on the context provided.",
|
|
208
208
|
systemPrompt,
|
|
209
209
|
provider: "google-ai", // Use fast model for decisions
|
|
@@ -279,11 +279,11 @@ ${executionSummary}
|
|
|
279
279
|
Provide a clear, concise answer that addresses the user's request based on the tool results.`;
|
|
280
280
|
try {
|
|
281
281
|
// Use AI to generate final summary
|
|
282
|
-
const
|
|
283
|
-
if (!
|
|
284
|
-
throw new Error("generate
|
|
282
|
+
const generateTool = aiCoreServer.tools["generate"];
|
|
283
|
+
if (!generateTool) {
|
|
284
|
+
throw new Error("generate tool not found");
|
|
285
285
|
}
|
|
286
|
-
const aiResponse = await
|
|
286
|
+
const aiResponse = await generateTool.execute({
|
|
287
287
|
prompt: summaryPrompt,
|
|
288
288
|
provider: "google-ai",
|
|
289
289
|
model: "gemini-2.5-pro",
|
|
@@ -139,7 +139,7 @@ export class ExternalMCPClient extends EventEmitter {
|
|
|
139
139
|
// Transform MCP response to NeuroLink format
|
|
140
140
|
const result = {
|
|
141
141
|
success: !response.isError,
|
|
142
|
-
data: response.
|
|
142
|
+
data: response.text || response.result || response,
|
|
143
143
|
metadata: {
|
|
144
144
|
toolName,
|
|
145
145
|
serverId: this.config.name,
|
|
@@ -150,7 +150,7 @@ export class ExternalMCPClient extends EventEmitter {
|
|
|
150
150
|
},
|
|
151
151
|
};
|
|
152
152
|
if (response.isError) {
|
|
153
|
-
result.error = response.
|
|
153
|
+
result.error = response.text?.[0]?.text || "Tool execution failed";
|
|
154
154
|
}
|
|
155
155
|
logger.debug(`[External MCP] Tool ${toolName} executed in ${executionTime}ms`);
|
|
156
156
|
return result;
|
|
@@ -134,7 +134,7 @@ export interface MCPServerConfig {
|
|
|
134
134
|
* });
|
|
135
135
|
*
|
|
136
136
|
* aiCoreServer.registerTool({
|
|
137
|
-
* name: 'generate
|
|
137
|
+
* name: 'generate',
|
|
138
138
|
* description: 'Generate text using AI providers',
|
|
139
139
|
* execute: async (params, context) => {
|
|
140
140
|
* // Tool implementation
|
package/dist/lib/mcp/factory.js
CHANGED
|
@@ -50,7 +50,7 @@ const ServerConfigSchema = z.object({
|
|
|
50
50
|
* });
|
|
51
51
|
*
|
|
52
52
|
* aiCoreServer.registerTool({
|
|
53
|
-
* name: 'generate
|
|
53
|
+
* name: 'generate',
|
|
54
54
|
* description: 'Generate text using AI providers',
|
|
55
55
|
* execute: async (params, context) => {
|
|
56
56
|
* // Tool implementation
|
|
@@ -94,14 +94,14 @@ Examples:
|
|
|
94
94
|
|
|
95
95
|
Response (JSON object only):`;
|
|
96
96
|
try {
|
|
97
|
-
const response = await this.provider.
|
|
97
|
+
const response = await this.provider.generate({
|
|
98
98
|
prompt: extractionPrompt,
|
|
99
99
|
temperature: 0,
|
|
100
100
|
maxTokens: 200,
|
|
101
101
|
});
|
|
102
|
-
if (response?.
|
|
102
|
+
if (response?.content) {
|
|
103
103
|
// Extract JSON object from response
|
|
104
|
-
const match = response.
|
|
104
|
+
const match = response.content.match(/\{([^}]*)\}/);
|
|
105
105
|
if (match) {
|
|
106
106
|
try {
|
|
107
107
|
const params = JSON.parse(match[0]);
|
|
@@ -153,14 +153,14 @@ Examples:
|
|
|
153
153
|
|
|
154
154
|
Response (JSON array only):`;
|
|
155
155
|
try {
|
|
156
|
-
const response = await this.provider.
|
|
156
|
+
const response = await this.provider.generate({
|
|
157
157
|
prompt: analysisPrompt,
|
|
158
158
|
temperature: 0,
|
|
159
159
|
maxTokens: 200,
|
|
160
160
|
});
|
|
161
|
-
if (response?.
|
|
161
|
+
if (response?.content) {
|
|
162
162
|
// Extract JSON array from response
|
|
163
|
-
const match = response.
|
|
163
|
+
const match = response.content.match(/\[([^\]]*)\]/);
|
|
164
164
|
if (match) {
|
|
165
165
|
try {
|
|
166
166
|
const toolNames = JSON.parse(match[0]);
|
|
@@ -317,8 +317,8 @@ Response (JSON array only):`;
|
|
|
317
317
|
async generateResponse(prompt, toolResults) {
|
|
318
318
|
// If no tools were used, generate regular response
|
|
319
319
|
if (toolResults.length === 0) {
|
|
320
|
-
const response = await this.provider.
|
|
321
|
-
return response?.
|
|
320
|
+
const response = await this.provider.generate({ prompt });
|
|
321
|
+
return response?.content || "";
|
|
322
322
|
}
|
|
323
323
|
// Extract human-readable results from tool executions
|
|
324
324
|
const toolResultsText = toolResults
|
|
@@ -379,12 +379,12 @@ Tool results: ${toolResultsText}
|
|
|
379
379
|
|
|
380
380
|
Please provide a natural response based on the tool results.`;
|
|
381
381
|
// Generate final response
|
|
382
|
-
const response = await this.provider.
|
|
382
|
+
const response = await this.provider.generate({
|
|
383
383
|
prompt: enhancedPrompt,
|
|
384
384
|
temperature: 0.7,
|
|
385
385
|
maxTokens: DEFAULT_MAX_TOKENS,
|
|
386
386
|
});
|
|
387
|
-
return response?.
|
|
387
|
+
return response?.content || toolResultsText;
|
|
388
388
|
}
|
|
389
389
|
/**
|
|
390
390
|
* Send a prompt and automatically execute any needed tools
|
|
@@ -303,8 +303,8 @@ export class MCPOrchestrator {
|
|
|
303
303
|
}
|
|
304
304
|
// Step 2: Text generation
|
|
305
305
|
steps.push({
|
|
306
|
-
stepId: "generate
|
|
307
|
-
toolName: "generate
|
|
306
|
+
stepId: "generate",
|
|
307
|
+
toolName: "generate",
|
|
308
308
|
params: {
|
|
309
309
|
prompt,
|
|
310
310
|
provider: options.provider,
|
|
@@ -324,7 +324,7 @@ export class MCPOrchestrator {
|
|
|
324
324
|
params: {
|
|
325
325
|
/* tool-specific params */
|
|
326
326
|
},
|
|
327
|
-
dependsOn: ["generate
|
|
327
|
+
dependsOn: ["generate"],
|
|
328
328
|
});
|
|
329
329
|
}
|
|
330
330
|
}
|
|
@@ -336,7 +336,7 @@ export class MCPOrchestrator {
|
|
|
336
336
|
});
|
|
337
337
|
const executionTime = Date.now() - startTime;
|
|
338
338
|
// Extract text generation result
|
|
339
|
-
const textResult = pipelineResult.results.get("generate
|
|
339
|
+
const textResult = pipelineResult.results.get("generate");
|
|
340
340
|
const providerResult = pipelineResult.results.get("select-provider");
|
|
341
341
|
if (!textResult || !textResult.success) {
|
|
342
342
|
throw new Error("Text generation failed");
|