@juspay/neurolink 5.1.0 → 5.3.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 +21 -9
- package/README.md +123 -126
- package/dist/agent/direct-tools.d.ts +6 -6
- package/dist/cli/commands/config.d.ts +3 -3
- package/dist/cli/commands/mcp.js +8 -7
- package/dist/cli/factories/command-factory.d.ts +4 -0
- package/dist/cli/factories/command-factory.js +63 -8
- package/dist/cli/index.js +87 -140
- package/dist/core/base-provider.d.ts +423 -0
- package/dist/core/base-provider.js +376 -0
- package/dist/core/constants.d.ts +2 -1
- package/dist/core/constants.js +2 -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 +8 -1
- package/dist/factories/compatibility-factory.js +1 -1
- package/dist/factories/provider-factory.d.ts +72 -0
- package/dist/factories/provider-factory.js +144 -0
- package/dist/factories/provider-registry.d.ts +38 -0
- package/dist/factories/provider-registry.js +107 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +2 -4
- package/dist/lib/agent/direct-tools.d.ts +6 -6
- package/dist/lib/core/base-provider.d.ts +423 -0
- package/dist/lib/core/base-provider.js +376 -0
- package/dist/lib/core/constants.d.ts +2 -1
- package/dist/lib/core/constants.js +2 -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 +8 -1
- package/dist/lib/factories/compatibility-factory.js +1 -1
- package/dist/lib/factories/provider-factory.d.ts +72 -0
- package/dist/lib/factories/provider-factory.js +144 -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 +4 -3
- package/dist/lib/index.js +2 -4
- package/dist/lib/mcp/client.d.ts +1 -0
- package/dist/lib/mcp/client.js +1 -0
- package/dist/lib/mcp/config.js +28 -3
- package/dist/lib/mcp/context-manager.d.ts +1 -0
- package/dist/lib/mcp/context-manager.js +8 -4
- package/dist/lib/mcp/function-calling.d.ts +13 -0
- package/dist/lib/mcp/function-calling.js +134 -35
- 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.d.ts +1 -0
- package/dist/lib/mcp/neurolink-mcp-client.js +21 -5
- 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-core-server.js +3 -1
- package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.d.ts +2 -2
- 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 +156 -117
- package/dist/lib/neurolink.js +619 -404
- 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 -43
- package/dist/lib/providers/anthropic.js +82 -306
- 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 +64 -2
- package/dist/lib/providers/function-calling-provider.js +208 -9
- 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 +32 -25
- package/dist/lib/providers/huggingFace.js +97 -431
- package/dist/lib/providers/index.d.ts +9 -9
- package/dist/lib/providers/index.js +9 -9
- package/dist/lib/providers/mcp-provider.js +24 -5
- 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 -36
- package/dist/lib/providers/ollama.js +297 -520
- package/dist/lib/providers/openAI.d.ts +19 -18
- package/dist/lib/providers/openAI.js +76 -275
- 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/services/streaming/streaming-manager.js +11 -10
- package/dist/lib/services/websocket/websocket-server.js +12 -11
- package/dist/lib/telemetry/telemetry-service.js +8 -7
- package/dist/lib/types/generate-types.d.ts +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 +30 -18
- package/dist/lib/types/universal-provider-options.d.ts +87 -0
- package/dist/lib/types/universal-provider-options.js +53 -0
- package/dist/mcp/client.d.ts +1 -0
- package/dist/mcp/client.js +1 -0
- package/dist/mcp/config.js +28 -3
- package/dist/mcp/context-manager.d.ts +1 -0
- package/dist/mcp/context-manager.js +8 -4
- package/dist/mcp/function-calling.d.ts +13 -0
- package/dist/mcp/function-calling.js +134 -35
- 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.d.ts +1 -0
- package/dist/mcp/neurolink-mcp-client.js +21 -5
- 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-core-server.js +3 -1
- package/dist/mcp/servers/ai-providers/ai-workflow-tools.d.ts +2 -2
- package/dist/mcp/unified-registry.d.ts +4 -0
- package/dist/mcp/unified-registry.js +42 -9
- package/dist/neurolink.d.ts +156 -117
- package/dist/neurolink.js +619 -404
- 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 -43
- package/dist/providers/anthropic.js +81 -305
- 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 +64 -2
- package/dist/providers/function-calling-provider.js +208 -9
- 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 +32 -25
- package/dist/providers/huggingFace.js +96 -430
- package/dist/providers/index.d.ts +9 -9
- package/dist/providers/index.js +9 -9
- package/dist/providers/mcp-provider.js +24 -5
- package/dist/providers/mistral.d.ts +42 -0
- package/dist/providers/mistral.js +160 -0
- package/dist/providers/ollama.d.ts +52 -36
- package/dist/providers/ollama.js +297 -519
- package/dist/providers/openAI.d.ts +19 -18
- package/dist/providers/openAI.js +76 -276
- 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/services/streaming/streaming-manager.js +11 -10
- package/dist/services/websocket/websocket-server.js +12 -11
- package/dist/telemetry/telemetry-service.js +8 -7
- package/dist/types/generate-types.d.ts +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 +30 -18
- package/dist/types/universal-provider-options.d.ts +87 -0
- package/dist/types/universal-provider-options.js +53 -0
- package/package.json +12 -5
- package/dist/lib/providers/agent-enhanced-provider.d.ts +0 -93
- package/dist/lib/providers/agent-enhanced-provider.js +0 -605
- package/dist/lib/providers/amazonBedrock.d.ts +0 -28
- package/dist/lib/providers/amazonBedrock.js +0 -364
- package/dist/lib/providers/azureOpenAI.d.ts +0 -42
- package/dist/lib/providers/azureOpenAI.js +0 -347
- package/dist/lib/providers/googleAIStudio.d.ts +0 -42
- package/dist/lib/providers/googleAIStudio.js +0 -364
- package/dist/lib/providers/googleVertexAI.d.ts +0 -34
- package/dist/lib/providers/googleVertexAI.js +0 -547
- package/dist/lib/providers/mistralAI.d.ts +0 -37
- package/dist/lib/providers/mistralAI.js +0 -325
- package/dist/providers/agent-enhanced-provider.d.ts +0 -93
- package/dist/providers/agent-enhanced-provider.js +0 -606
- package/dist/providers/amazonBedrock.d.ts +0 -28
- package/dist/providers/amazonBedrock.js +0 -364
- package/dist/providers/azureOpenAI.d.ts +0 -42
- package/dist/providers/azureOpenAI.js +0 -348
- package/dist/providers/googleAIStudio.d.ts +0 -42
- package/dist/providers/googleAIStudio.js +0 -364
- package/dist/providers/googleVertexAI.d.ts +0 -34
- package/dist/providers/googleVertexAI.js +0 -547
- package/dist/providers/mistralAI.d.ts +0 -37
- package/dist/providers/mistralAI.js +0 -325
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { WebSocketServer, WebSocket } from "ws";
|
|
2
2
|
import { EventEmitter } from "events";
|
|
3
3
|
import { randomUUID } from "crypto";
|
|
4
|
+
import { logger } from "../../utils/logger.js";
|
|
4
5
|
export class NeuroLinkWebSocketServer extends EventEmitter {
|
|
5
6
|
wss;
|
|
6
7
|
connections = new Map();
|
|
@@ -32,7 +33,7 @@ export class NeuroLinkWebSocketServer extends EventEmitter {
|
|
|
32
33
|
this.handleConnection(ws, request);
|
|
33
34
|
});
|
|
34
35
|
this.wss.on("error", (error) => {
|
|
35
|
-
|
|
36
|
+
logger.error("[WebSocket Server] Error:", error);
|
|
36
37
|
this.emit("error", error);
|
|
37
38
|
});
|
|
38
39
|
}
|
|
@@ -64,7 +65,7 @@ export class NeuroLinkWebSocketServer extends EventEmitter {
|
|
|
64
65
|
this.handleDisconnection(connectionId);
|
|
65
66
|
});
|
|
66
67
|
ws.on("error", (error) => {
|
|
67
|
-
|
|
68
|
+
logger.error(`[WebSocket] Connection ${connectionId} error:`, error);
|
|
68
69
|
this.handleDisconnection(connectionId);
|
|
69
70
|
});
|
|
70
71
|
// Send connection confirmation
|
|
@@ -82,7 +83,7 @@ export class NeuroLinkWebSocketServer extends EventEmitter {
|
|
|
82
83
|
},
|
|
83
84
|
},
|
|
84
85
|
});
|
|
85
|
-
|
|
86
|
+
logger.debug(`[WebSocket] New connection: ${connectionId} (${this.connections.size}/${this.options.maxConnections})`);
|
|
86
87
|
this.emit("connection", { connectionId, userAgent, ipAddress });
|
|
87
88
|
}
|
|
88
89
|
handleMessage(connectionId, data) {
|
|
@@ -101,7 +102,7 @@ export class NeuroLinkWebSocketServer extends EventEmitter {
|
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
104
|
catch (error) {
|
|
104
|
-
|
|
105
|
+
logger.error(`[WebSocket] Invalid message from ${connectionId}:`, error);
|
|
105
106
|
this.sendError(connectionId, "Invalid message format");
|
|
106
107
|
}
|
|
107
108
|
}
|
|
@@ -124,7 +125,7 @@ export class NeuroLinkWebSocketServer extends EventEmitter {
|
|
|
124
125
|
// Clean up
|
|
125
126
|
this.connections.delete(connectionId);
|
|
126
127
|
this.connectionInfo.delete(connectionId);
|
|
127
|
-
|
|
128
|
+
logger.debug(`[WebSocket] Disconnected: ${connectionId} (${this.connections.size}/${this.options.maxConnections})`);
|
|
128
129
|
this.emit("disconnection", { connectionId });
|
|
129
130
|
}
|
|
130
131
|
// Room Management
|
|
@@ -150,7 +151,7 @@ export class NeuroLinkWebSocketServer extends EventEmitter {
|
|
|
150
151
|
memberCount: this.rooms.get(roomId).size,
|
|
151
152
|
},
|
|
152
153
|
});
|
|
153
|
-
|
|
154
|
+
logger.debug(`[WebSocket] ${connectionId} joined room ${roomId}`);
|
|
154
155
|
return true;
|
|
155
156
|
}
|
|
156
157
|
leaveRoom(connectionId, roomId) {
|
|
@@ -179,7 +180,7 @@ export class NeuroLinkWebSocketServer extends EventEmitter {
|
|
|
179
180
|
memberCount: room.size,
|
|
180
181
|
},
|
|
181
182
|
});
|
|
182
|
-
|
|
183
|
+
logger.debug(`[WebSocket] ${connectionId} left room ${roomId}`);
|
|
183
184
|
return true;
|
|
184
185
|
}
|
|
185
186
|
broadcastToRoom(roomId, message) {
|
|
@@ -231,7 +232,7 @@ export class NeuroLinkWebSocketServer extends EventEmitter {
|
|
|
231
232
|
return true;
|
|
232
233
|
}
|
|
233
234
|
catch (error) {
|
|
234
|
-
|
|
235
|
+
logger.error(`[WebSocket] Failed to send message to ${connectionId}:`, error);
|
|
235
236
|
return false;
|
|
236
237
|
}
|
|
237
238
|
}
|
|
@@ -269,7 +270,7 @@ export class NeuroLinkWebSocketServer extends EventEmitter {
|
|
|
269
270
|
const connection = this.connectionInfo.get(connectionId);
|
|
270
271
|
if (connection &&
|
|
271
272
|
Date.now() - connection.lastActivity > this.options.timeoutMs) {
|
|
272
|
-
|
|
273
|
+
logger.debug(`[WebSocket] Timeout for connection ${connectionId}`);
|
|
273
274
|
ws.terminate();
|
|
274
275
|
}
|
|
275
276
|
}
|
|
@@ -296,9 +297,9 @@ export class NeuroLinkWebSocketServer extends EventEmitter {
|
|
|
296
297
|
// Implementation for channel data handling
|
|
297
298
|
}
|
|
298
299
|
handleChannelError(channelId, error) {
|
|
299
|
-
|
|
300
|
+
logger.error(`[Streaming Channel] ${channelId} error:`, error);
|
|
300
301
|
}
|
|
301
302
|
handleChannelClose(channelId) {
|
|
302
|
-
|
|
303
|
+
logger.debug(`[Streaming Channel] ${channelId} closed`);
|
|
303
304
|
}
|
|
304
305
|
}
|
|
@@ -4,6 +4,7 @@ import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentation
|
|
|
4
4
|
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
|
|
5
5
|
import { Resource } from "@opentelemetry/resources";
|
|
6
6
|
import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION, } from "@opentelemetry/semantic-conventions";
|
|
7
|
+
import { logger } from "../utils/logger.js";
|
|
7
8
|
export class TelemetryService {
|
|
8
9
|
static instance;
|
|
9
10
|
sdk;
|
|
@@ -25,7 +26,7 @@ export class TelemetryService {
|
|
|
25
26
|
this.initializeTelemetry();
|
|
26
27
|
}
|
|
27
28
|
else {
|
|
28
|
-
|
|
29
|
+
logger.debug("[Telemetry] Disabled - set NEUROLINK_TELEMETRY_ENABLED=true or configure OTEL_EXPORTER_OTLP_ENDPOINT to enable");
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
32
|
static getInstance() {
|
|
@@ -56,10 +57,10 @@ export class TelemetryService {
|
|
|
56
57
|
this.meter = metrics.getMeter("neurolink-ai");
|
|
57
58
|
this.tracer = trace.getTracer("neurolink-ai");
|
|
58
59
|
this.initializeMetrics();
|
|
59
|
-
|
|
60
|
+
logger.debug("[Telemetry] Initialized with endpoint:", process.env.OTEL_EXPORTER_OTLP_ENDPOINT);
|
|
60
61
|
}
|
|
61
62
|
catch (error) {
|
|
62
|
-
|
|
63
|
+
logger.error("[Telemetry] Failed to initialize:", error);
|
|
63
64
|
this.enabled = false;
|
|
64
65
|
}
|
|
65
66
|
}
|
|
@@ -95,10 +96,10 @@ export class TelemetryService {
|
|
|
95
96
|
}
|
|
96
97
|
try {
|
|
97
98
|
await this.sdk?.start();
|
|
98
|
-
|
|
99
|
+
logger.debug("[Telemetry] SDK started successfully");
|
|
99
100
|
}
|
|
100
101
|
catch (error) {
|
|
101
|
-
|
|
102
|
+
logger.error("[Telemetry] Failed to start SDK:", error);
|
|
102
103
|
this.enabled = false;
|
|
103
104
|
}
|
|
104
105
|
}
|
|
@@ -249,10 +250,10 @@ export class TelemetryService {
|
|
|
249
250
|
if (this.enabled && this.sdk) {
|
|
250
251
|
try {
|
|
251
252
|
await this.sdk.shutdown();
|
|
252
|
-
|
|
253
|
+
logger.debug("[Telemetry] SDK shutdown completed");
|
|
253
254
|
}
|
|
254
255
|
catch (error) {
|
|
255
|
-
|
|
256
|
+
logger.error("[Telemetry] Error during shutdown:", error);
|
|
256
257
|
}
|
|
257
258
|
}
|
|
258
259
|
}
|
|
@@ -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
|
+
}
|
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
import type { ZodType, ZodTypeDef } from "zod";
|
|
2
2
|
import type { Tool, Schema } from "ai";
|
|
3
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
|
+
}
|
|
4
23
|
/**
|
|
5
24
|
* Stream function options interface - Primary method for streaming content
|
|
6
25
|
* Future-ready for multi-modal capabilities while maintaining text focus
|
|
@@ -26,6 +45,7 @@ export interface StreamOptions {
|
|
|
26
45
|
tools?: Record<string, Tool>;
|
|
27
46
|
timeout?: number | string;
|
|
28
47
|
disableTools?: boolean;
|
|
48
|
+
maxSteps?: number;
|
|
29
49
|
enableEvaluation?: boolean;
|
|
30
50
|
enableAnalytics?: boolean;
|
|
31
51
|
context?: Record<string, any>;
|
|
@@ -46,30 +66,22 @@ export interface StreamResult {
|
|
|
46
66
|
}>;
|
|
47
67
|
provider?: string;
|
|
48
68
|
model?: string;
|
|
69
|
+
usage?: {
|
|
70
|
+
inputTokens?: number;
|
|
71
|
+
outputTokens?: number;
|
|
72
|
+
totalTokens?: number;
|
|
73
|
+
};
|
|
74
|
+
finishReason?: string;
|
|
75
|
+
toolCalls?: ToolCall[];
|
|
76
|
+
toolResults?: ToolResult[];
|
|
49
77
|
metadata?: {
|
|
50
78
|
streamId?: string;
|
|
51
79
|
startTime?: number;
|
|
52
80
|
totalChunks?: number;
|
|
53
81
|
estimatedDuration?: number;
|
|
82
|
+
responseTime?: number;
|
|
83
|
+
fallback?: boolean;
|
|
54
84
|
};
|
|
55
|
-
toolCalls?: Array<{
|
|
56
|
-
toolCallId: string;
|
|
57
|
-
toolName: string;
|
|
58
|
-
args: Record<string, any>;
|
|
59
|
-
}>;
|
|
60
|
-
toolsUsed?: string[];
|
|
61
|
-
toolExecutions?: Array<{
|
|
62
|
-
name: string;
|
|
63
|
-
input: Record<string, any>;
|
|
64
|
-
output: any;
|
|
65
|
-
duration: number;
|
|
66
|
-
}>;
|
|
67
|
-
enhancedWithTools?: boolean;
|
|
68
|
-
availableTools?: Array<{
|
|
69
|
-
name: string;
|
|
70
|
-
description: string;
|
|
71
|
-
parameters: Record<string, any>;
|
|
72
|
-
}>;
|
|
73
85
|
analytics?: AnalyticsData;
|
|
74
86
|
evaluation?: EvaluationData;
|
|
75
87
|
}
|
|
@@ -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
|
+
}
|
package/dist/mcp/client.d.ts
CHANGED
package/dist/mcp/client.js
CHANGED
|
@@ -130,6 +130,7 @@ export class NeuroLinkMCPClient extends EventEmitter {
|
|
|
130
130
|
const tools = {};
|
|
131
131
|
for (const [name, tool] of this.tools) {
|
|
132
132
|
tools[name] = {
|
|
133
|
+
name: name, // Include the tool name as a property
|
|
133
134
|
description: tool.description,
|
|
134
135
|
inputSchema: tool.inputSchema,
|
|
135
136
|
};
|
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) {
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
export class ContextManager {
|
|
11
11
|
sessionCounter = 0;
|
|
12
12
|
activeContexts = new Map();
|
|
13
|
+
static cachedLogger = null;
|
|
13
14
|
/**
|
|
14
15
|
* Create a new execution context with rich information
|
|
15
16
|
*
|
|
@@ -64,6 +65,7 @@ export class ContextManager {
|
|
|
64
65
|
},
|
|
65
66
|
path: {
|
|
66
67
|
join: (...paths) => {
|
|
68
|
+
// Use dynamic require for synchronous path operations
|
|
67
69
|
const path = require("path");
|
|
68
70
|
return path.join(...paths);
|
|
69
71
|
},
|
|
@@ -85,11 +87,13 @@ export class ContextManager {
|
|
|
85
87
|
},
|
|
86
88
|
},
|
|
87
89
|
grantedPermissions: request.permissions || [],
|
|
88
|
-
log: (level, message, data) => {
|
|
89
|
-
// Use logger if available, otherwise
|
|
90
|
+
log: async (level, message, data) => {
|
|
91
|
+
// Use cached logger if available, otherwise import and cache
|
|
90
92
|
try {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
+
if (!ContextManager.cachedLogger) {
|
|
94
|
+
ContextManager.cachedLogger = await import("../utils/logger.js").then(({ logger }) => logger);
|
|
95
|
+
}
|
|
96
|
+
ContextManager.cachedLogger[level](message, data);
|
|
93
97
|
}
|
|
94
98
|
catch {
|
|
95
99
|
console[level === "debug" ? "log" : level](message, data);
|
|
@@ -14,6 +14,7 @@ export declare function mcpToolToAISDKTool(tool: NeuroLinkMCPTool, serverId: str
|
|
|
14
14
|
*/
|
|
15
15
|
export declare function getAvailableFunctionTools(): Promise<{
|
|
16
16
|
tools: Tool[];
|
|
17
|
+
toolsObject: Record<string, Tool>;
|
|
17
18
|
toolMap: Map<string, {
|
|
18
19
|
serverId: string;
|
|
19
20
|
toolName: string;
|
|
@@ -49,3 +50,15 @@ export declare function getFunctionToolsForCategory(category?: string, maxTools?
|
|
|
49
50
|
* Check if function calling is available
|
|
50
51
|
*/
|
|
51
52
|
export declare function isFunctionCallingAvailable(): Promise<boolean>;
|
|
53
|
+
/**
|
|
54
|
+
* Utility function to create a named tool object for debugging
|
|
55
|
+
*/
|
|
56
|
+
export declare function createNamedTool(name: string, toolDef: any): any & {
|
|
57
|
+
name: string;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Get tools with proper name properties for debugging
|
|
61
|
+
*/
|
|
62
|
+
export declare function getToolsWithNames(): Promise<Record<string, any & {
|
|
63
|
+
name: string;
|
|
64
|
+
}>>;
|