@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
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Types for In-Memory Server Support
|
|
3
|
+
* Enables Lighthouse and other integrations to register tools directly
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* In-memory MCP server configuration
|
|
7
|
+
*/
|
|
8
|
+
export interface InMemoryMCPServerConfig {
|
|
9
|
+
/**
|
|
10
|
+
* The actual server instance with tools
|
|
11
|
+
*/
|
|
12
|
+
server: {
|
|
13
|
+
/**
|
|
14
|
+
* Server title for display
|
|
15
|
+
*/
|
|
16
|
+
title?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Map of tool name to tool implementation
|
|
19
|
+
*/
|
|
20
|
+
tools: Map<string, InMemoryToolInfo> | Record<string, InMemoryToolInfo>;
|
|
21
|
+
/**
|
|
22
|
+
* Optional server description
|
|
23
|
+
*/
|
|
24
|
+
description?: string;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Category for grouping tools
|
|
28
|
+
*/
|
|
29
|
+
category?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Metadata about the server
|
|
32
|
+
*/
|
|
33
|
+
metadata?: {
|
|
34
|
+
provider?: string;
|
|
35
|
+
version?: string;
|
|
36
|
+
author?: string;
|
|
37
|
+
[key: string]: any;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* In-memory tool information
|
|
42
|
+
*/
|
|
43
|
+
export interface InMemoryToolInfo {
|
|
44
|
+
/**
|
|
45
|
+
* Tool description
|
|
46
|
+
*/
|
|
47
|
+
description: string;
|
|
48
|
+
/**
|
|
49
|
+
* Tool execution function
|
|
50
|
+
*/
|
|
51
|
+
execute: (params: any) => Promise<InMemoryToolResult> | InMemoryToolResult;
|
|
52
|
+
/**
|
|
53
|
+
* Input parameter schema (Zod or JSON Schema)
|
|
54
|
+
*/
|
|
55
|
+
inputSchema?: any;
|
|
56
|
+
/**
|
|
57
|
+
* Whether the tool is implemented (default: true)
|
|
58
|
+
*/
|
|
59
|
+
isImplemented?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Optional metadata
|
|
62
|
+
*/
|
|
63
|
+
metadata?: Record<string, any>;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Result from in-memory tool execution
|
|
67
|
+
*/
|
|
68
|
+
export interface InMemoryToolResult {
|
|
69
|
+
/**
|
|
70
|
+
* Whether execution was successful
|
|
71
|
+
*/
|
|
72
|
+
success: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Result data if successful
|
|
75
|
+
*/
|
|
76
|
+
data?: any;
|
|
77
|
+
/**
|
|
78
|
+
* Error message if failed
|
|
79
|
+
*/
|
|
80
|
+
error?: string;
|
|
81
|
+
/**
|
|
82
|
+
* Optional metadata about execution
|
|
83
|
+
*/
|
|
84
|
+
metadata?: {
|
|
85
|
+
executionTime?: number;
|
|
86
|
+
toolName?: string;
|
|
87
|
+
serverId?: string;
|
|
88
|
+
[key: string]: any;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Unified MCP Registry interface
|
|
93
|
+
*/
|
|
94
|
+
export interface UnifiedMCPRegistry {
|
|
95
|
+
/**
|
|
96
|
+
* Register an in-memory server
|
|
97
|
+
*/
|
|
98
|
+
registerInMemoryServer(serverId: string, config: InMemoryMCPServerConfig): Promise<void>;
|
|
99
|
+
/**
|
|
100
|
+
* Get all available tools
|
|
101
|
+
*/
|
|
102
|
+
getAllTools(): Promise<Array<{
|
|
103
|
+
name: string;
|
|
104
|
+
serverId: string;
|
|
105
|
+
description: string;
|
|
106
|
+
isExternal: boolean;
|
|
107
|
+
}>>;
|
|
108
|
+
/**
|
|
109
|
+
* Execute a tool
|
|
110
|
+
*/
|
|
111
|
+
executeTool(toolName: string, params: any, context: any): Promise<any>;
|
|
112
|
+
/**
|
|
113
|
+
* Check if connected to a server
|
|
114
|
+
*/
|
|
115
|
+
isConnected(serverId: string): boolean;
|
|
116
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { ZodType, ZodTypeDef } from "zod";
|
|
2
|
+
import type { Tool, Schema } from "ai";
|
|
3
|
+
import type { AIProviderName, AnalyticsData, EvaluationData } from "../core/types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Interface for tool execution calls
|
|
6
|
+
*/
|
|
7
|
+
export interface ToolCall {
|
|
8
|
+
toolName: string;
|
|
9
|
+
parameters: Record<string, any>;
|
|
10
|
+
id?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Interface for tool execution results
|
|
14
|
+
*/
|
|
15
|
+
export interface ToolResult {
|
|
16
|
+
toolName: string;
|
|
17
|
+
status: "success" | "failure";
|
|
18
|
+
output?: any;
|
|
19
|
+
error?: string;
|
|
20
|
+
id?: string;
|
|
21
|
+
executionTime?: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Stream function options interface - Primary method for streaming content
|
|
25
|
+
* Future-ready for multi-modal capabilities while maintaining text focus
|
|
26
|
+
*/
|
|
27
|
+
export interface StreamOptions {
|
|
28
|
+
input: {
|
|
29
|
+
text: string;
|
|
30
|
+
};
|
|
31
|
+
output?: {
|
|
32
|
+
format?: "text" | "structured" | "json";
|
|
33
|
+
streaming?: {
|
|
34
|
+
chunkSize?: number;
|
|
35
|
+
bufferSize?: number;
|
|
36
|
+
enableProgress?: boolean;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
provider?: AIProviderName | string;
|
|
40
|
+
model?: string;
|
|
41
|
+
temperature?: number;
|
|
42
|
+
maxTokens?: number;
|
|
43
|
+
systemPrompt?: string;
|
|
44
|
+
schema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>;
|
|
45
|
+
tools?: Record<string, Tool>;
|
|
46
|
+
timeout?: number | string;
|
|
47
|
+
disableTools?: boolean;
|
|
48
|
+
maxSteps?: number;
|
|
49
|
+
enableEvaluation?: boolean;
|
|
50
|
+
enableAnalytics?: boolean;
|
|
51
|
+
context?: Record<string, any>;
|
|
52
|
+
evaluationDomain?: string;
|
|
53
|
+
toolUsageContext?: string;
|
|
54
|
+
conversationHistory?: Array<{
|
|
55
|
+
role: string;
|
|
56
|
+
content: string;
|
|
57
|
+
}>;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Stream function result interface - Primary output format for streaming
|
|
61
|
+
* Future-ready for multi-modal outputs while maintaining text focus
|
|
62
|
+
*/
|
|
63
|
+
export interface StreamResult {
|
|
64
|
+
stream: AsyncIterable<{
|
|
65
|
+
content: string;
|
|
66
|
+
}>;
|
|
67
|
+
provider?: string;
|
|
68
|
+
model?: string;
|
|
69
|
+
usage?: {
|
|
70
|
+
inputTokens?: number;
|
|
71
|
+
outputTokens?: number;
|
|
72
|
+
totalTokens?: number;
|
|
73
|
+
};
|
|
74
|
+
finishReason?: string;
|
|
75
|
+
toolCalls?: ToolCall[];
|
|
76
|
+
toolResults?: ToolResult[];
|
|
77
|
+
metadata?: {
|
|
78
|
+
streamId?: string;
|
|
79
|
+
startTime?: number;
|
|
80
|
+
totalChunks?: number;
|
|
81
|
+
estimatedDuration?: number;
|
|
82
|
+
responseTime?: number;
|
|
83
|
+
fallback?: boolean;
|
|
84
|
+
};
|
|
85
|
+
analytics?: AnalyticsData;
|
|
86
|
+
evaluation?: EvaluationData;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Enhanced provider interface with stream method
|
|
90
|
+
*/
|
|
91
|
+
export interface EnhancedStreamProvider {
|
|
92
|
+
stream(options: StreamOptions): Promise<StreamResult>;
|
|
93
|
+
getName(): string;
|
|
94
|
+
isAvailable(): Promise<boolean>;
|
|
95
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Universal Provider Options Interface (Phase 1: Factory Pattern)
|
|
3
|
+
* Based on TypeScript factory pattern best practices for AI provider abstraction
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Base configuration interface for all AI providers
|
|
7
|
+
* Uses Parameter Object Pattern for flexible, extensible configuration
|
|
8
|
+
*/
|
|
9
|
+
export interface UniversalProviderOptions {
|
|
10
|
+
prompt?: string;
|
|
11
|
+
model?: string;
|
|
12
|
+
temperature?: number;
|
|
13
|
+
maxTokens?: number;
|
|
14
|
+
systemPrompt?: string;
|
|
15
|
+
enableAnalytics?: boolean;
|
|
16
|
+
enableEvaluation?: boolean;
|
|
17
|
+
context?: Record<string, unknown>;
|
|
18
|
+
metadata?: Record<string, unknown>;
|
|
19
|
+
extensionOptions?: Record<string, unknown>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Generic provider options (without providerType)
|
|
23
|
+
*/
|
|
24
|
+
export type GenericProviderOptions = Omit<UniversalProviderOptions, "providerType">;
|
|
25
|
+
/**
|
|
26
|
+
* Provider-specific configuration extensions
|
|
27
|
+
* Discriminated union pattern for type-safe provider configs
|
|
28
|
+
*/
|
|
29
|
+
export interface OpenAIProviderOptions extends UniversalProviderOptions {
|
|
30
|
+
providerType: "openai";
|
|
31
|
+
organization?: string;
|
|
32
|
+
seed?: number;
|
|
33
|
+
topP?: number;
|
|
34
|
+
}
|
|
35
|
+
export interface GoogleAIProviderOptions extends UniversalProviderOptions {
|
|
36
|
+
providerType: "google-ai";
|
|
37
|
+
topK?: number;
|
|
38
|
+
candidateCount?: number;
|
|
39
|
+
stopSequences?: string[];
|
|
40
|
+
}
|
|
41
|
+
export interface AnthropicProviderOptions extends UniversalProviderOptions {
|
|
42
|
+
providerType: "anthropic";
|
|
43
|
+
topK?: number;
|
|
44
|
+
stopSequences?: string[];
|
|
45
|
+
}
|
|
46
|
+
export interface BedrockProviderOptions extends UniversalProviderOptions {
|
|
47
|
+
providerType: "bedrock";
|
|
48
|
+
inferenceProfileArn?: string;
|
|
49
|
+
region?: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Discriminated union for type-safe provider configuration
|
|
53
|
+
* Enables compile-time type checking for provider-specific options
|
|
54
|
+
*/
|
|
55
|
+
export type ProviderSpecificOptions = OpenAIProviderOptions | GoogleAIProviderOptions | AnthropicProviderOptions | BedrockProviderOptions;
|
|
56
|
+
/**
|
|
57
|
+
* Factory configuration interface
|
|
58
|
+
* Supports both universal and provider-specific parameters
|
|
59
|
+
*/
|
|
60
|
+
export interface ProviderFactoryConfig {
|
|
61
|
+
providerName: string;
|
|
62
|
+
modelName?: string;
|
|
63
|
+
options?: UniversalProviderOptions | ProviderSpecificOptions;
|
|
64
|
+
enableMCP?: boolean;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Parameter normalization utilities
|
|
68
|
+
* Converts between different parameter formats for backward compatibility
|
|
69
|
+
*/
|
|
70
|
+
export declare class ParameterNormalizer {
|
|
71
|
+
/**
|
|
72
|
+
* Normalize legacy parameter formats to universal format
|
|
73
|
+
*/
|
|
74
|
+
static normalizeToUniversal(optionsOrPrompt: UniversalProviderOptions | string): UniversalProviderOptions;
|
|
75
|
+
/**
|
|
76
|
+
* Retrieve the provider type if it exists, otherwise return null
|
|
77
|
+
*/
|
|
78
|
+
private static getProviderType;
|
|
79
|
+
/**
|
|
80
|
+
* Extract provider-specific parameters safely
|
|
81
|
+
*/
|
|
82
|
+
static extractProviderOptions<T extends ProviderSpecificOptions>(options: UniversalProviderOptions | ProviderSpecificOptions, providerType: T["providerType"]): T | GenericProviderOptions;
|
|
83
|
+
/**
|
|
84
|
+
* Merge default values with user-provided options
|
|
85
|
+
*/
|
|
86
|
+
static mergeWithDefaults(options: UniversalProviderOptions, defaults: Partial<UniversalProviderOptions>): UniversalProviderOptions;
|
|
87
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Universal Provider Options Interface (Phase 1: Factory Pattern)
|
|
3
|
+
* Based on TypeScript factory pattern best practices for AI provider abstraction
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Parameter normalization utilities
|
|
7
|
+
* Converts between different parameter formats for backward compatibility
|
|
8
|
+
*/
|
|
9
|
+
export class ParameterNormalizer {
|
|
10
|
+
/**
|
|
11
|
+
* Normalize legacy parameter formats to universal format
|
|
12
|
+
*/
|
|
13
|
+
static normalizeToUniversal(optionsOrPrompt) {
|
|
14
|
+
if (typeof optionsOrPrompt === "string") {
|
|
15
|
+
return { prompt: optionsOrPrompt };
|
|
16
|
+
}
|
|
17
|
+
return optionsOrPrompt;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Retrieve the provider type if it exists, otherwise return null
|
|
21
|
+
*/
|
|
22
|
+
static getProviderType(options) {
|
|
23
|
+
return "providerType" in options ? options.providerType : null;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Extract provider-specific parameters safely
|
|
27
|
+
*/
|
|
28
|
+
static extractProviderOptions(options, providerType) {
|
|
29
|
+
const currentProviderType = ParameterNormalizer.getProviderType(options);
|
|
30
|
+
if (currentProviderType === providerType) {
|
|
31
|
+
return options;
|
|
32
|
+
}
|
|
33
|
+
// Handle case where options has providerType but doesn't match
|
|
34
|
+
if (currentProviderType !== null) {
|
|
35
|
+
const { providerType: _providerType, ...genericOptions } = options;
|
|
36
|
+
return genericOptions;
|
|
37
|
+
}
|
|
38
|
+
// Options don't have providerType, return as generic
|
|
39
|
+
return options;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Merge default values with user-provided options
|
|
43
|
+
*/
|
|
44
|
+
static mergeWithDefaults(options, defaults) {
|
|
45
|
+
return {
|
|
46
|
+
...defaults,
|
|
47
|
+
...options,
|
|
48
|
+
// Merge nested objects
|
|
49
|
+
context: { ...defaults.context, ...options.context },
|
|
50
|
+
metadata: { ...defaults.metadata, ...options.metadata },
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -85,7 +85,7 @@ async function isProviderAvailable(providerName) {
|
|
|
85
85
|
}
|
|
86
86
|
try {
|
|
87
87
|
const provider = await AIProviderFactory.createProvider(providerName);
|
|
88
|
-
await provider.
|
|
88
|
+
await provider.generate({ prompt: "test", maxTokens: 1 });
|
|
89
89
|
return true;
|
|
90
90
|
}
|
|
91
91
|
catch (error) {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Phase 2: Enhanced Streaming Infrastructure
|
|
3
3
|
* Streaming utilities for progress tracking and metadata enhancement
|
|
4
4
|
*/
|
|
5
|
-
import type { StreamingProgressData, StreamingMetadata, ProgressCallback
|
|
5
|
+
import type { StreamingProgressData, StreamingMetadata, ProgressCallback } from "../core/types.js";
|
|
6
6
|
export interface UIProgressHandler {
|
|
7
7
|
onProgress: (progress: StreamingProgressData) => void;
|
|
8
8
|
onComplete: (metadata: StreamingMetadata) => void;
|
|
@@ -19,6 +19,18 @@ export interface StreamingStats {
|
|
|
19
19
|
/**
|
|
20
20
|
* Enhanced streaming utilities for progress tracking and metadata
|
|
21
21
|
*/
|
|
22
|
+
export interface StreamingConfigOptions {
|
|
23
|
+
enableProgressTracking?: boolean;
|
|
24
|
+
progressCallback?: ProgressCallback;
|
|
25
|
+
includeStreamingMetadata?: boolean;
|
|
26
|
+
streamingBufferSize?: number;
|
|
27
|
+
enableStreamingHeaders?: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Legacy interface for backward compatibility
|
|
31
|
+
*/
|
|
32
|
+
export interface EnhancedStreamTextOptions extends StreamingConfigOptions {
|
|
33
|
+
}
|
|
22
34
|
export declare class StreamingEnhancer {
|
|
23
35
|
/**
|
|
24
36
|
* Add progress tracking to a readable stream
|
|
@@ -42,7 +54,7 @@ export declare class StreamingEnhancer {
|
|
|
42
54
|
/**
|
|
43
55
|
* Create enhanced streaming configuration
|
|
44
56
|
*/
|
|
45
|
-
static createStreamingConfig(options: EnhancedStreamTextOptions): {
|
|
57
|
+
static createStreamingConfig(options: StreamingConfigOptions | EnhancedStreamTextOptions): {
|
|
46
58
|
progressTracking: boolean;
|
|
47
59
|
callback?: ProgressCallback;
|
|
48
60
|
metadata: boolean;
|
|
@@ -2,9 +2,6 @@
|
|
|
2
2
|
* Phase 2: Enhanced Streaming Infrastructure
|
|
3
3
|
* Streaming utilities for progress tracking and metadata enhancement
|
|
4
4
|
*/
|
|
5
|
-
/**
|
|
6
|
-
* Enhanced streaming utilities for progress tracking and metadata
|
|
7
|
-
*/
|
|
8
5
|
export class StreamingEnhancer {
|
|
9
6
|
/**
|
|
10
7
|
* Add progress tracking to a readable stream
|
package/dist/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,
|
package/dist/mcp/config.js
CHANGED
|
@@ -3,15 +3,36 @@
|
|
|
3
3
|
* Central registry for all MCP servers following Lighthouse patterns
|
|
4
4
|
* Handles built-in servers only - auto-discovery handled by unified registry
|
|
5
5
|
*/
|
|
6
|
-
import { aiCoreServer } from "./servers/ai-providers/ai-core-server.js";
|
|
7
6
|
import { utilityServer } from "./servers/utilities/utility-server.js";
|
|
8
7
|
import { logger } from "../utils/logger.js";
|
|
8
|
+
/**
|
|
9
|
+
* Lazy-loaded AI Core Server to avoid circular dependencies
|
|
10
|
+
*/
|
|
11
|
+
let aiCoreServerCache = null;
|
|
12
|
+
async function getAICoreServer() {
|
|
13
|
+
if (!aiCoreServerCache) {
|
|
14
|
+
const { aiCoreServer } = await import("./servers/ai-providers/ai-core-server.js");
|
|
15
|
+
aiCoreServerCache = aiCoreServer;
|
|
16
|
+
}
|
|
17
|
+
return aiCoreServerCache;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Lazy-loaded Direct Tools Server to avoid circular dependencies
|
|
21
|
+
*/
|
|
22
|
+
let directToolsServerCache = null;
|
|
23
|
+
async function getDirectToolsServer() {
|
|
24
|
+
if (!directToolsServerCache) {
|
|
25
|
+
const { directToolsServer } = await import("./servers/agent/direct-tools-server.js");
|
|
26
|
+
directToolsServerCache = directToolsServer;
|
|
27
|
+
}
|
|
28
|
+
return directToolsServerCache;
|
|
29
|
+
}
|
|
9
30
|
/**
|
|
10
31
|
* Built-in MCP servers (kept for backward compatibility)
|
|
11
32
|
* Add new servers here as they are created
|
|
12
33
|
*/
|
|
13
34
|
export const allServers = [
|
|
14
|
-
aiCoreServer
|
|
35
|
+
// aiCoreServer will be added dynamically in getServers()
|
|
15
36
|
utilityServer,
|
|
16
37
|
// Add more servers as they are created
|
|
17
38
|
];
|
|
@@ -25,8 +46,12 @@ export const mcpConfig = {
|
|
|
25
46
|
*/
|
|
26
47
|
getServers: async () => {
|
|
27
48
|
const activeServers = [];
|
|
49
|
+
// Get all servers including dynamically loaded ones
|
|
50
|
+
const aiCoreServer = await getAICoreServer();
|
|
51
|
+
const directToolsServer = await getDirectToolsServer();
|
|
52
|
+
const servers = [aiCoreServer, directToolsServer, ...allServers];
|
|
28
53
|
// Include built-in servers with filtering
|
|
29
|
-
for (const server of
|
|
54
|
+
for (const server of servers) {
|
|
30
55
|
const implementedTools = {};
|
|
31
56
|
let hasImplementedTools = false;
|
|
32
57
|
for (const toolName in server.tools) {
|
|
@@ -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;
|
package/dist/mcp/factory.d.ts
CHANGED
|
@@ -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/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
|
|
@@ -58,7 +58,7 @@ export async function getAvailableFunctionTools() {
|
|
|
58
58
|
const toolMap = new Map();
|
|
59
59
|
try {
|
|
60
60
|
// Add overall timeout for the entire function
|
|
61
|
-
const overallTimeoutMs =
|
|
61
|
+
const overallTimeoutMs = process.env.NODE_ENV === "test" ? 30000 : 15000; // 30s for tests, 15s for production
|
|
62
62
|
let overallTimeoutId;
|
|
63
63
|
const overallTimeoutPromise = new Promise((_, reject) => {
|
|
64
64
|
overallTimeoutId = setTimeout(() => {
|
|
@@ -13,7 +13,7 @@ export declare const initializeMCPTools: (sessionId: string, client: NeuroLinkMC
|
|
|
13
13
|
* Get all available tools across all servers
|
|
14
14
|
* Useful for documentation and discovery
|
|
15
15
|
*/
|
|
16
|
-
export declare function getAllAvailableTools(): Promise<Array<{
|
|
16
|
+
export declare function getAllAvailableTools(inMemoryServers?: Map<string, any>): Promise<Array<{
|
|
17
17
|
serverId: string;
|
|
18
18
|
serverTitle: string;
|
|
19
19
|
toolName: string;
|
|
@@ -140,8 +140,52 @@ export const initializeMCPTools = async (sessionId, client, context) => {
|
|
|
140
140
|
* Get all available tools across all servers
|
|
141
141
|
* Useful for documentation and discovery
|
|
142
142
|
*/
|
|
143
|
-
export async function getAllAvailableTools() {
|
|
143
|
+
export async function getAllAvailableTools(inMemoryServers) {
|
|
144
144
|
const tools = [];
|
|
145
|
+
// Add in-memory server tools first
|
|
146
|
+
if (inMemoryServers) {
|
|
147
|
+
for (const [serverId, serverConfig] of inMemoryServers) {
|
|
148
|
+
const server = serverConfig.server;
|
|
149
|
+
if (server && server.tools) {
|
|
150
|
+
// Handle both Map and object formats
|
|
151
|
+
const toolEntries = server.tools instanceof Map
|
|
152
|
+
? Array.from(server.tools.entries())
|
|
153
|
+
: Object.entries(server.tools || {});
|
|
154
|
+
for (const [toolName, toolInfo] of toolEntries) {
|
|
155
|
+
const prefix = `${serverId}_`;
|
|
156
|
+
const finalToolName = toolName.length > 64 - prefix.length
|
|
157
|
+
? toolName.substring(0, 64 - prefix.length)
|
|
158
|
+
: toolName;
|
|
159
|
+
const namespacedName = sanitizeToolName(`${prefix}${finalToolName}`);
|
|
160
|
+
// Handle different tool info structures
|
|
161
|
+
let description = `Tool from ${serverId}`;
|
|
162
|
+
let isImplemented = true;
|
|
163
|
+
if (toolInfo) {
|
|
164
|
+
// Check if it's a tool info object with description
|
|
165
|
+
if (typeof toolInfo.description === "string") {
|
|
166
|
+
description = toolInfo.description;
|
|
167
|
+
}
|
|
168
|
+
else if (typeof toolInfo === "function") {
|
|
169
|
+
// It's a raw function, no description available
|
|
170
|
+
description = `${toolName} from ${serverId}`;
|
|
171
|
+
}
|
|
172
|
+
// Check implementation status
|
|
173
|
+
if (typeof toolInfo.isImplemented === "boolean") {
|
|
174
|
+
isImplemented = toolInfo.isImplemented;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
tools.push({
|
|
178
|
+
serverId,
|
|
179
|
+
serverTitle: server.title || serverId,
|
|
180
|
+
toolName,
|
|
181
|
+
namespacedName,
|
|
182
|
+
description,
|
|
183
|
+
isImplemented,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
145
189
|
const servers = await mcpConfig.getServers();
|
|
146
190
|
servers.forEach((server) => {
|
|
147
191
|
Object.entries(server.tools).forEach(([toolName, tool]) => {
|