@juspay/neurolink 6.1.0 → 6.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 +10 -6
- package/dist/cli/commands/config.d.ts +13 -13
- package/dist/cli/index.js +3 -9
- package/dist/core/analytics.d.ts +11 -1
- package/dist/core/analytics.js +2 -2
- package/dist/core/base-provider.js +4 -18
- package/dist/core/dynamic-models.d.ts +8 -8
- package/dist/core/factory.js +3 -11
- package/dist/index.d.ts +2 -4
- package/dist/index.js +2 -11
- package/dist/lib/core/analytics.d.ts +11 -1
- package/dist/lib/core/analytics.js +2 -2
- package/dist/lib/core/base-provider.js +4 -18
- package/dist/lib/core/dynamic-models.d.ts +8 -8
- package/dist/lib/core/factory.js +3 -11
- package/dist/lib/index.d.ts +2 -4
- package/dist/lib/index.js +2 -11
- package/dist/lib/mcp/factory.d.ts +1 -1
- package/dist/lib/mcp/index.d.ts +7 -19
- package/dist/lib/mcp/index.js +15 -56
- package/dist/lib/neurolink.d.ts +1 -9
- package/dist/lib/neurolink.js +21 -70
- package/dist/lib/providers/amazon-bedrock.js +5 -16
- package/dist/lib/providers/anthropic-baseprovider.js +3 -21
- package/dist/lib/providers/anthropic.js +4 -7
- package/dist/lib/providers/azure-openai.js +4 -2
- package/dist/lib/providers/google-vertex.js +5 -9
- package/dist/lib/providers/huggingFace.js +5 -10
- package/dist/lib/providers/mistral.js +5 -8
- package/dist/lib/providers/openAI.js +4 -7
- package/dist/lib/utils/providerConfig.d.ts +117 -0
- package/dist/lib/utils/providerConfig.js +353 -0
- package/dist/lib/utils/providerUtils.d.ts +2 -1
- package/dist/lib/utils/providerUtils.js +53 -36
- package/dist/lib/utils/timeout.d.ts +72 -1
- package/dist/lib/utils/timeout.js +203 -2
- package/dist/mcp/factory.d.ts +1 -1
- package/dist/mcp/index.d.ts +7 -19
- package/dist/mcp/index.js +15 -56
- package/dist/neurolink.d.ts +1 -9
- package/dist/neurolink.js +21 -70
- package/dist/providers/amazon-bedrock.js +5 -16
- package/dist/providers/anthropic-baseprovider.js +3 -21
- package/dist/providers/anthropic.js +4 -7
- package/dist/providers/azure-openai.js +4 -2
- package/dist/providers/google-vertex.js +5 -9
- package/dist/providers/huggingFace.js +5 -10
- package/dist/providers/mistral.js +5 -8
- package/dist/providers/openAI.js +4 -7
- package/dist/utils/providerConfig.d.ts +117 -0
- package/dist/utils/providerConfig.js +353 -0
- package/dist/utils/providerUtils.d.ts +2 -1
- package/dist/utils/providerUtils.js +53 -36
- package/dist/utils/timeout.d.ts +72 -1
- package/dist/utils/timeout.js +203 -2
- package/package.json +1 -1
- package/dist/chat/client-utils.d.ts +0 -95
- package/dist/chat/client-utils.js +0 -315
- package/dist/chat/index.d.ts +0 -24
- package/dist/chat/index.js +0 -33
- package/dist/chat/session-storage.d.ts +0 -77
- package/dist/chat/session-storage.js +0 -233
- package/dist/chat/session.d.ts +0 -96
- package/dist/chat/session.js +0 -257
- package/dist/chat/sse-handler.d.ts +0 -49
- package/dist/chat/sse-handler.js +0 -259
- package/dist/chat/types.d.ts +0 -74
- package/dist/chat/types.js +0 -5
- package/dist/chat/websocket-chat-handler.d.ts +0 -37
- package/dist/chat/websocket-chat-handler.js +0 -262
- package/dist/cli/commands/mcp.d.ts +0 -20
- package/dist/cli/commands/mcp.js +0 -1272
- package/dist/core/defaults.d.ts +0 -19
- package/dist/core/defaults.js +0 -29
- package/dist/core/evaluation-config.d.ts +0 -29
- package/dist/core/evaluation-config.js +0 -144
- package/dist/factories/compatibility-factory.d.ts +0 -35
- package/dist/factories/compatibility-factory.js +0 -71
- package/dist/factories/provider-generate-factory.d.ts +0 -20
- package/dist/factories/provider-generate-factory.js +0 -93
- package/dist/lib/chat/client-utils.d.ts +0 -95
- package/dist/lib/chat/client-utils.js +0 -315
- package/dist/lib/chat/index.d.ts +0 -24
- package/dist/lib/chat/index.js +0 -33
- package/dist/lib/chat/session-storage.d.ts +0 -77
- package/dist/lib/chat/session-storage.js +0 -233
- package/dist/lib/chat/session.d.ts +0 -96
- package/dist/lib/chat/session.js +0 -257
- package/dist/lib/chat/sse-handler.d.ts +0 -49
- package/dist/lib/chat/sse-handler.js +0 -259
- package/dist/lib/chat/types.d.ts +0 -74
- package/dist/lib/chat/types.js +0 -5
- package/dist/lib/chat/websocket-chat-handler.d.ts +0 -37
- package/dist/lib/chat/websocket-chat-handler.js +0 -262
- package/dist/lib/core/defaults.d.ts +0 -19
- package/dist/lib/core/defaults.js +0 -29
- package/dist/lib/core/evaluation-config.d.ts +0 -29
- package/dist/lib/core/evaluation-config.js +0 -144
- package/dist/lib/factories/compatibility-factory.d.ts +0 -35
- package/dist/lib/factories/compatibility-factory.js +0 -71
- package/dist/lib/factories/provider-generate-factory.d.ts +0 -20
- package/dist/lib/factories/provider-generate-factory.js +0 -93
- package/dist/lib/mcp/adapters/plugin-bridge.d.ts +0 -40
- package/dist/lib/mcp/adapters/plugin-bridge.js +0 -89
- package/dist/lib/mcp/auto-discovery.d.ts +0 -62
- package/dist/lib/mcp/auto-discovery.js +0 -149
- package/dist/lib/mcp/client.d.ts +0 -68
- package/dist/lib/mcp/client.js +0 -248
- package/dist/lib/mcp/config.d.ts +0 -31
- package/dist/lib/mcp/config.js +0 -99
- package/dist/lib/mcp/context-manager.d.ts +0 -171
- package/dist/lib/mcp/context-manager.js +0 -362
- package/dist/lib/mcp/contracts/mcp-contract.d.ts +0 -169
- package/dist/lib/mcp/contracts/mcp-contract.js +0 -58
- package/dist/lib/mcp/core/plugin-manager.d.ts +0 -46
- package/dist/lib/mcp/core/plugin-manager.js +0 -110
- package/dist/lib/mcp/demo/plugin-demo.d.ts +0 -20
- package/dist/lib/mcp/demo/plugin-demo.js +0 -118
- package/dist/lib/mcp/dynamic-chain-executor.d.ts +0 -225
- package/dist/lib/mcp/dynamic-chain-executor.js +0 -489
- package/dist/lib/mcp/dynamic-orchestrator.d.ts +0 -115
- package/dist/lib/mcp/dynamic-orchestrator.js +0 -351
- package/dist/lib/mcp/ecosystem.d.ts +0 -75
- package/dist/lib/mcp/ecosystem.js +0 -161
- package/dist/lib/mcp/error-manager.d.ts +0 -254
- package/dist/lib/mcp/error-manager.js +0 -501
- package/dist/lib/mcp/error-recovery.d.ts +0 -159
- package/dist/lib/mcp/error-recovery.js +0 -405
- package/dist/lib/mcp/external-client.d.ts +0 -88
- package/dist/lib/mcp/external-client.js +0 -331
- package/dist/lib/mcp/external-manager.d.ts +0 -112
- package/dist/lib/mcp/external-manager.js +0 -308
- package/dist/lib/mcp/function-calling.d.ts +0 -65
- package/dist/lib/mcp/function-calling.js +0 -642
- package/dist/lib/mcp/health-monitor.d.ts +0 -257
- package/dist/lib/mcp/health-monitor.js +0 -630
- package/dist/lib/mcp/initialize-tools.d.ts +0 -29
- package/dist/lib/mcp/initialize-tools.js +0 -261
- package/dist/lib/mcp/initialize.d.ts +0 -18
- package/dist/lib/mcp/initialize.js +0 -62
- package/dist/lib/mcp/manager.d.ts +0 -68
- package/dist/lib/mcp/manager.js +0 -176
- package/dist/lib/mcp/neurolink-mcp-client.d.ts +0 -97
- package/dist/lib/mcp/neurolink-mcp-client.js +0 -462
- package/dist/lib/mcp/orchestrator.d.ts +0 -302
- package/dist/lib/mcp/orchestrator.js +0 -703
- package/dist/lib/mcp/plugin-manager.d.ts +0 -98
- package/dist/lib/mcp/plugin-manager.js +0 -296
- package/dist/lib/mcp/plugins/core/filesystem-mcp.d.ts +0 -36
- package/dist/lib/mcp/plugins/core/filesystem-mcp.js +0 -142
- package/dist/lib/mcp/plugins/filesystem-mcp.d.ts +0 -37
- package/dist/lib/mcp/plugins/filesystem-mcp.js +0 -54
- package/dist/lib/mcp/security-manager.d.ts +0 -87
- package/dist/lib/mcp/security-manager.js +0 -344
- package/dist/lib/mcp/semaphore-manager.d.ts +0 -137
- package/dist/lib/mcp/semaphore-manager.js +0 -329
- package/dist/lib/mcp/session-manager.d.ts +0 -187
- package/dist/lib/mcp/session-manager.js +0 -400
- package/dist/lib/mcp/session-persistence.d.ts +0 -93
- package/dist/lib/mcp/session-persistence.js +0 -301
- package/dist/lib/mcp/tool-integration.d.ts +0 -58
- package/dist/lib/mcp/tool-integration.js +0 -203
- package/dist/lib/mcp/transport-manager.d.ts +0 -154
- package/dist/lib/mcp/transport-manager.js +0 -334
- package/dist/lib/mcp/unified-mcp.d.ts +0 -133
- package/dist/lib/mcp/unified-mcp.js +0 -251
- package/dist/lib/mcp/unified-registry.d.ts +0 -165
- package/dist/lib/mcp/unified-registry.js +0 -538
- package/dist/lib/providers/analytics-helper.d.ts +0 -38
- package/dist/lib/providers/analytics-helper.js +0 -216
- package/dist/lib/providers/function-calling-provider.d.ts +0 -142
- package/dist/lib/providers/function-calling-provider.js +0 -630
- package/dist/lib/providers/mcp-provider.d.ts +0 -75
- package/dist/lib/providers/mcp-provider.js +0 -283
- package/dist/lib/providers/timeout-wrapper.d.ts +0 -40
- package/dist/lib/providers/timeout-wrapper.js +0 -100
- package/dist/lib/sdk/tool-extension.d.ts +0 -181
- package/dist/lib/sdk/tool-extension.js +0 -284
- package/dist/lib/services/streaming/streaming-manager.d.ts +0 -29
- package/dist/lib/services/streaming/streaming-manager.js +0 -245
- package/dist/lib/services/types.d.ts +0 -156
- package/dist/lib/services/types.js +0 -2
- package/dist/lib/services/websocket/websocket-server.d.ts +0 -34
- package/dist/lib/services/websocket/websocket-server.js +0 -305
- package/dist/lib/utils/provider-validation.d.ts +0 -36
- package/dist/lib/utils/provider-validation.js +0 -625
- package/dist/lib/utils/providerUtils-fixed.d.ts +0 -8
- package/dist/lib/utils/providerUtils-fixed.js +0 -94
- package/dist/lib/utils/streaming-utils.d.ts +0 -79
- package/dist/lib/utils/streaming-utils.js +0 -198
- package/dist/lib/utils/timeout-manager.d.ts +0 -75
- package/dist/lib/utils/timeout-manager.js +0 -244
- package/dist/mcp/adapters/plugin-bridge.d.ts +0 -40
- package/dist/mcp/adapters/plugin-bridge.js +0 -89
- package/dist/mcp/auto-discovery.d.ts +0 -62
- package/dist/mcp/auto-discovery.js +0 -149
- package/dist/mcp/client.d.ts +0 -68
- package/dist/mcp/client.js +0 -248
- package/dist/mcp/config.d.ts +0 -31
- package/dist/mcp/config.js +0 -99
- package/dist/mcp/context-manager.d.ts +0 -171
- package/dist/mcp/context-manager.js +0 -362
- package/dist/mcp/contracts/mcp-contract.d.ts +0 -169
- package/dist/mcp/contracts/mcp-contract.js +0 -58
- package/dist/mcp/core/plugin-manager.d.ts +0 -46
- package/dist/mcp/core/plugin-manager.js +0 -110
- package/dist/mcp/demo/plugin-demo.d.ts +0 -20
- package/dist/mcp/demo/plugin-demo.js +0 -118
- package/dist/mcp/dynamic-chain-executor.d.ts +0 -225
- package/dist/mcp/dynamic-chain-executor.js +0 -489
- package/dist/mcp/dynamic-orchestrator.d.ts +0 -115
- package/dist/mcp/dynamic-orchestrator.js +0 -351
- package/dist/mcp/ecosystem.d.ts +0 -75
- package/dist/mcp/ecosystem.js +0 -162
- package/dist/mcp/error-manager.d.ts +0 -254
- package/dist/mcp/error-manager.js +0 -501
- package/dist/mcp/error-recovery.d.ts +0 -159
- package/dist/mcp/error-recovery.js +0 -405
- package/dist/mcp/external-client.d.ts +0 -88
- package/dist/mcp/external-client.js +0 -331
- package/dist/mcp/external-manager.d.ts +0 -112
- package/dist/mcp/external-manager.js +0 -308
- package/dist/mcp/function-calling.d.ts +0 -65
- package/dist/mcp/function-calling.js +0 -642
- package/dist/mcp/health-monitor.d.ts +0 -257
- package/dist/mcp/health-monitor.js +0 -630
- package/dist/mcp/initialize-tools.d.ts +0 -29
- package/dist/mcp/initialize-tools.js +0 -262
- package/dist/mcp/initialize.d.ts +0 -18
- package/dist/mcp/initialize.js +0 -62
- package/dist/mcp/manager.d.ts +0 -68
- package/dist/mcp/manager.js +0 -176
- package/dist/mcp/neurolink-mcp-client.d.ts +0 -97
- package/dist/mcp/neurolink-mcp-client.js +0 -462
- package/dist/mcp/orchestrator.d.ts +0 -302
- package/dist/mcp/orchestrator.js +0 -703
- package/dist/mcp/plugin-manager.d.ts +0 -98
- package/dist/mcp/plugin-manager.js +0 -297
- package/dist/mcp/plugins/core/filesystem-mcp.d.ts +0 -36
- package/dist/mcp/plugins/core/filesystem-mcp.js +0 -142
- package/dist/mcp/plugins/core/neurolink-mcp.json +0 -17
- package/dist/mcp/plugins/filesystem-mcp.d.ts +0 -37
- package/dist/mcp/plugins/filesystem-mcp.js +0 -54
- package/dist/mcp/security-manager.d.ts +0 -87
- package/dist/mcp/security-manager.js +0 -344
- package/dist/mcp/semaphore-manager.d.ts +0 -137
- package/dist/mcp/semaphore-manager.js +0 -329
- package/dist/mcp/session-manager.d.ts +0 -187
- package/dist/mcp/session-manager.js +0 -400
- package/dist/mcp/session-persistence.d.ts +0 -93
- package/dist/mcp/session-persistence.js +0 -302
- package/dist/mcp/tool-integration.d.ts +0 -58
- package/dist/mcp/tool-integration.js +0 -203
- package/dist/mcp/transport-manager.d.ts +0 -154
- package/dist/mcp/transport-manager.js +0 -335
- package/dist/mcp/unified-mcp.d.ts +0 -133
- package/dist/mcp/unified-mcp.js +0 -251
- package/dist/mcp/unified-registry.d.ts +0 -165
- package/dist/mcp/unified-registry.js +0 -539
- package/dist/providers/analytics-helper.d.ts +0 -38
- package/dist/providers/analytics-helper.js +0 -216
- package/dist/providers/function-calling-provider.d.ts +0 -142
- package/dist/providers/function-calling-provider.js +0 -630
- package/dist/providers/mcp-provider.d.ts +0 -75
- package/dist/providers/mcp-provider.js +0 -283
- package/dist/providers/timeout-wrapper.d.ts +0 -40
- package/dist/providers/timeout-wrapper.js +0 -100
- package/dist/sdk/tool-extension.d.ts +0 -181
- package/dist/sdk/tool-extension.js +0 -284
- package/dist/services/streaming/streaming-manager.d.ts +0 -29
- package/dist/services/streaming/streaming-manager.js +0 -245
- package/dist/services/types.d.ts +0 -156
- package/dist/services/types.js +0 -2
- package/dist/services/websocket/websocket-server.d.ts +0 -34
- package/dist/services/websocket/websocket-server.js +0 -306
- package/dist/utils/provider-validation.d.ts +0 -36
- package/dist/utils/provider-validation.js +0 -625
- package/dist/utils/providerUtils-fixed.d.ts +0 -8
- package/dist/utils/providerUtils-fixed.js +0 -94
- package/dist/utils/streaming-utils.d.ts +0 -79
- package/dist/utils/streaming-utils.js +0 -198
- package/dist/utils/timeout-manager.d.ts +0 -75
- package/dist/utils/timeout-manager.js +0 -244
package/dist/chat/types.d.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Phase 3: SSE Chat Utilities
|
|
3
|
-
* Type definitions for chat infrastructure
|
|
4
|
-
*/
|
|
5
|
-
import type { JsonValue } from "../types/common.js";
|
|
6
|
-
export interface ChatMessage {
|
|
7
|
-
id: string;
|
|
8
|
-
role: "user" | "assistant" | "system";
|
|
9
|
-
content: string;
|
|
10
|
-
timestamp: number;
|
|
11
|
-
metadata?: {
|
|
12
|
-
provider?: string;
|
|
13
|
-
model?: string;
|
|
14
|
-
tokens?: number;
|
|
15
|
-
duration?: number;
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
export interface ChatRequest {
|
|
19
|
-
sessionId: string;
|
|
20
|
-
message: string;
|
|
21
|
-
role?: "user";
|
|
22
|
-
options?: {
|
|
23
|
-
temperature?: number;
|
|
24
|
-
maxTokens?: number;
|
|
25
|
-
systemPrompt?: string;
|
|
26
|
-
streamResponse?: boolean;
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
export interface SSEOptions {
|
|
30
|
-
maxConnections?: number;
|
|
31
|
-
heartbeatInterval?: number;
|
|
32
|
-
connectionTimeout?: number;
|
|
33
|
-
enableCors?: boolean;
|
|
34
|
-
corsOrigins?: string[];
|
|
35
|
-
}
|
|
36
|
-
export interface SessionOptions {
|
|
37
|
-
maxHistory?: number;
|
|
38
|
-
persistenceAdapter?: "memory" | "redis" | "file";
|
|
39
|
-
contextWindowSize?: number;
|
|
40
|
-
autoSave?: boolean;
|
|
41
|
-
ttl?: number;
|
|
42
|
-
}
|
|
43
|
-
export interface SSEEvent {
|
|
44
|
-
type: "data" | "error" | "progress" | "complete" | "heartbeat";
|
|
45
|
-
data: JsonValue;
|
|
46
|
-
id?: string;
|
|
47
|
-
retry?: number;
|
|
48
|
-
}
|
|
49
|
-
export interface ChatSessionState {
|
|
50
|
-
id: string;
|
|
51
|
-
messages: ChatMessage[];
|
|
52
|
-
createdAt: number;
|
|
53
|
-
lastActivity: number;
|
|
54
|
-
metadata?: Record<string, JsonValue>;
|
|
55
|
-
}
|
|
56
|
-
export interface StreamingChatResponse {
|
|
57
|
-
sessionId: string;
|
|
58
|
-
messageId: string;
|
|
59
|
-
stream: ReadableStream;
|
|
60
|
-
response: Response;
|
|
61
|
-
}
|
|
62
|
-
export interface SessionStorage {
|
|
63
|
-
get(sessionId: string): Promise<ChatSessionState | null>;
|
|
64
|
-
set(sessionId: string, state: ChatSessionState): Promise<void>;
|
|
65
|
-
delete(sessionId: string): Promise<void>;
|
|
66
|
-
list(): Promise<string[]>;
|
|
67
|
-
cleanup(maxAge: number): Promise<number>;
|
|
68
|
-
}
|
|
69
|
-
export interface ContextManager {
|
|
70
|
-
addMessage(sessionId: string, message: ChatMessage): Promise<void>;
|
|
71
|
-
getHistory(sessionId: string, limit?: number): Promise<ChatMessage[]>;
|
|
72
|
-
trimContext(sessionId: string, maxTokens: number): Promise<number>;
|
|
73
|
-
estimateTokens(messages: ChatMessage[]): number;
|
|
74
|
-
}
|
package/dist/chat/types.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { SSEChatHandler } from "./sse-handler.js";
|
|
2
|
-
import type { AIProvider } from "../core/types.js";
|
|
3
|
-
import type { WebSocketOptions, GroupChatRequest, StreamingChatRequest } from "../services/types.js";
|
|
4
|
-
import type { SSEOptions, ChatRequest } from "./types.js";
|
|
5
|
-
import type { UnknownRecord } from "../types/common.js";
|
|
6
|
-
export interface WebSocketChatOptions {
|
|
7
|
-
sseOptions?: UnknownRecord;
|
|
8
|
-
wsOptions?: WebSocketOptions;
|
|
9
|
-
enableTypingIndicators?: boolean;
|
|
10
|
-
enablePresenceTracking?: boolean;
|
|
11
|
-
enableMessageSync?: boolean;
|
|
12
|
-
}
|
|
13
|
-
export declare class WebSocketChatHandler extends SSEChatHandler {
|
|
14
|
-
private wsServer;
|
|
15
|
-
private streamingManager;
|
|
16
|
-
protected options: WebSocketChatOptions & Required<SSEOptions>;
|
|
17
|
-
private typingIndicators;
|
|
18
|
-
private presenceTracking;
|
|
19
|
-
constructor(provider: AIProvider, options?: WebSocketChatOptions);
|
|
20
|
-
private setupWebSocketHandlers;
|
|
21
|
-
handleWebSocketChatRequest(connectionId: string, request: ChatRequest): Promise<void>;
|
|
22
|
-
handleGroupChat(roomId: string, request: GroupChatRequest): Promise<void>;
|
|
23
|
-
handleStreamingChat(connectionId: string, request: StreamingChatRequest): Promise<void>;
|
|
24
|
-
enableTypingIndicators(roomId: string): Promise<void>;
|
|
25
|
-
enablePresenceTracking(roomId: string): Promise<void>;
|
|
26
|
-
enableMessageSynchronization(roomId: string): Promise<void>;
|
|
27
|
-
private sendToConnection;
|
|
28
|
-
private sendError;
|
|
29
|
-
private showTypingIndicator;
|
|
30
|
-
private clearTypingIndicator;
|
|
31
|
-
private updatePresence;
|
|
32
|
-
private handleWebSocketChatMessage;
|
|
33
|
-
getConnectionCount(): number;
|
|
34
|
-
getRoomCount(): number;
|
|
35
|
-
getStreamingMetrics(): import("../services/types.js").StreamingMetrics;
|
|
36
|
-
close(): void;
|
|
37
|
-
}
|
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
import { SSEChatHandler } from "./sse-handler.js";
|
|
2
|
-
import { NeuroLinkWebSocketServer } from "../services/websocket/websocket-server.js";
|
|
3
|
-
import { StreamingManager } from "../services/streaming/streaming-manager.js";
|
|
4
|
-
import { randomUUID } from "crypto";
|
|
5
|
-
export class WebSocketChatHandler extends SSEChatHandler {
|
|
6
|
-
wsServer;
|
|
7
|
-
streamingManager;
|
|
8
|
-
options;
|
|
9
|
-
typingIndicators = new Map();
|
|
10
|
-
presenceTracking = new Map();
|
|
11
|
-
constructor(provider, options = {}) {
|
|
12
|
-
super(provider, options.sseOptions);
|
|
13
|
-
this.options = {
|
|
14
|
-
enableTypingIndicators: true,
|
|
15
|
-
enablePresenceTracking: true,
|
|
16
|
-
enableMessageSync: true,
|
|
17
|
-
maxConnections: 100,
|
|
18
|
-
heartbeatInterval: 30000,
|
|
19
|
-
connectionTimeout: 300000,
|
|
20
|
-
enableCors: true,
|
|
21
|
-
corsOrigins: ["*"],
|
|
22
|
-
...options,
|
|
23
|
-
};
|
|
24
|
-
this.wsServer = new NeuroLinkWebSocketServer(options.wsOptions);
|
|
25
|
-
this.streamingManager = new StreamingManager();
|
|
26
|
-
this.setupWebSocketHandlers();
|
|
27
|
-
}
|
|
28
|
-
setupWebSocketHandlers() {
|
|
29
|
-
this.wsServer.on("connection", ({ connectionId }) => {
|
|
30
|
-
console.log(`[WebSocket Chat] New connection: ${connectionId}`);
|
|
31
|
-
if (this.options.enablePresenceTracking) {
|
|
32
|
-
this.updatePresence(connectionId, "online");
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
this.wsServer.on("disconnection", ({ connectionId }) => {
|
|
36
|
-
console.log(`[WebSocket Chat] Disconnection: ${connectionId}`);
|
|
37
|
-
if (this.options.enablePresenceTracking) {
|
|
38
|
-
this.updatePresence(connectionId, "offline");
|
|
39
|
-
}
|
|
40
|
-
this.clearTypingIndicator(connectionId);
|
|
41
|
-
});
|
|
42
|
-
this.wsServer.on("chat-message", ({ connectionId, message }) => {
|
|
43
|
-
this.handleWebSocketChatMessage(connectionId, message);
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
// Enhanced Chat Capabilities
|
|
47
|
-
async handleWebSocketChatRequest(connectionId, request) {
|
|
48
|
-
try {
|
|
49
|
-
if (this.options.enableTypingIndicators) {
|
|
50
|
-
this.showTypingIndicator(connectionId, "assistant");
|
|
51
|
-
}
|
|
52
|
-
// Create streaming session for this chat
|
|
53
|
-
const streamingSession = await this.streamingManager.createStreamingSession({
|
|
54
|
-
provider: this.provider.constructor.name,
|
|
55
|
-
model: "default", // Should get from provider
|
|
56
|
-
streamingMode: "real-time",
|
|
57
|
-
compressionEnabled: true,
|
|
58
|
-
maxChunkSize: 1024,
|
|
59
|
-
bufferSize: 4096,
|
|
60
|
-
latencyTarget: 200,
|
|
61
|
-
});
|
|
62
|
-
// Generate AI response
|
|
63
|
-
const result = await this.provider.generate({
|
|
64
|
-
prompt: request.message,
|
|
65
|
-
temperature: request.options?.temperature,
|
|
66
|
-
maxTokens: request.options?.maxTokens,
|
|
67
|
-
});
|
|
68
|
-
if (!result || !result.content) {
|
|
69
|
-
throw new Error("Invalid AI response");
|
|
70
|
-
}
|
|
71
|
-
// Send response via WebSocket
|
|
72
|
-
const responseMessage = {
|
|
73
|
-
id: randomUUID(),
|
|
74
|
-
type: "ai-response",
|
|
75
|
-
connectionId,
|
|
76
|
-
timestamp: Date.now(),
|
|
77
|
-
data: {
|
|
78
|
-
text: result.content,
|
|
79
|
-
sessionId: request.sessionId,
|
|
80
|
-
metadata: {
|
|
81
|
-
provider: this.provider.constructor.name,
|
|
82
|
-
tokens: result.usage?.totalTokens,
|
|
83
|
-
latency: Date.now() - Date.now(), // Should track actual timing
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
};
|
|
87
|
-
this.sendToConnection(connectionId, responseMessage);
|
|
88
|
-
if (this.options.enableTypingIndicators) {
|
|
89
|
-
this.clearTypingIndicator(connectionId);
|
|
90
|
-
}
|
|
91
|
-
await this.streamingManager.terminateStreamingSession(streamingSession.id);
|
|
92
|
-
}
|
|
93
|
-
catch (error) {
|
|
94
|
-
console.error("[WebSocket Chat] Error handling chat request:", error);
|
|
95
|
-
this.sendError(connectionId, "Failed to process chat request");
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
async handleGroupChat(roomId, request) {
|
|
99
|
-
try {
|
|
100
|
-
// Process AI request
|
|
101
|
-
const result = await this.provider.generate({
|
|
102
|
-
prompt: request.prompt,
|
|
103
|
-
temperature: request.options?.temperature,
|
|
104
|
-
maxTokens: request.options?.maxTokens,
|
|
105
|
-
});
|
|
106
|
-
if (!result || !result.content) {
|
|
107
|
-
throw new Error("Invalid AI response");
|
|
108
|
-
}
|
|
109
|
-
// Broadcast to room
|
|
110
|
-
const broadcastMessage = {
|
|
111
|
-
id: randomUUID(),
|
|
112
|
-
type: "ai-response",
|
|
113
|
-
connectionId: "system",
|
|
114
|
-
timestamp: Date.now(),
|
|
115
|
-
data: {
|
|
116
|
-
text: result.content,
|
|
117
|
-
sessionId: request.sessionId,
|
|
118
|
-
userId: request.userId,
|
|
119
|
-
isGroupMessage: true,
|
|
120
|
-
metadata: {
|
|
121
|
-
provider: this.provider.constructor.name,
|
|
122
|
-
tokens: result.usage?.totalTokens,
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
};
|
|
126
|
-
this.wsServer.broadcastToRoom(roomId, broadcastMessage);
|
|
127
|
-
}
|
|
128
|
-
catch (error) {
|
|
129
|
-
console.error("[WebSocket Chat] Error handling group chat:", error);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
async handleStreamingChat(connectionId, request) {
|
|
133
|
-
try {
|
|
134
|
-
const streamingOptions = request.streamingOptions || {};
|
|
135
|
-
// Create streaming channel
|
|
136
|
-
const channelId = randomUUID();
|
|
137
|
-
const channel = this.wsServer.createStreamingChannel(connectionId, channelId);
|
|
138
|
-
// Generate response
|
|
139
|
-
const result = await this.provider.generate({
|
|
140
|
-
prompt: request.prompt,
|
|
141
|
-
...request.options,
|
|
142
|
-
});
|
|
143
|
-
if (!result || !result.content) {
|
|
144
|
-
throw new Error("Invalid AI response");
|
|
145
|
-
}
|
|
146
|
-
// Send complete response
|
|
147
|
-
const responseMessage = {
|
|
148
|
-
id: randomUUID(),
|
|
149
|
-
type: "ai-response",
|
|
150
|
-
connectionId,
|
|
151
|
-
timestamp: Date.now(),
|
|
152
|
-
data: {
|
|
153
|
-
text: result.content,
|
|
154
|
-
isStreamingComplete: true,
|
|
155
|
-
channelId,
|
|
156
|
-
},
|
|
157
|
-
};
|
|
158
|
-
this.sendToConnection(connectionId, responseMessage);
|
|
159
|
-
}
|
|
160
|
-
catch (error) {
|
|
161
|
-
console.error("[WebSocket Chat] Error handling streaming chat:", error);
|
|
162
|
-
this.sendError(connectionId, "Failed to process streaming chat");
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
// Real-time Features
|
|
166
|
-
async enableTypingIndicators(roomId) {
|
|
167
|
-
this.options.enableTypingIndicators = true;
|
|
168
|
-
console.log(`[WebSocket Chat] Enabled typing indicators for room ${roomId}`);
|
|
169
|
-
}
|
|
170
|
-
async enablePresenceTracking(roomId) {
|
|
171
|
-
this.options.enablePresenceTracking = true;
|
|
172
|
-
console.log(`[WebSocket Chat] Enabled presence tracking for room ${roomId}`);
|
|
173
|
-
}
|
|
174
|
-
async enableMessageSynchronization(roomId) {
|
|
175
|
-
this.options.enableMessageSync = true;
|
|
176
|
-
console.log(`[WebSocket Chat] Enabled message sync for room ${roomId}`);
|
|
177
|
-
}
|
|
178
|
-
// Helper methods
|
|
179
|
-
sendToConnection(connectionId, message) {
|
|
180
|
-
// Use the WebSocket server's public send method
|
|
181
|
-
this.wsServer.sendMessage(connectionId, message);
|
|
182
|
-
}
|
|
183
|
-
sendError(connectionId, errorMessage) {
|
|
184
|
-
const errorMsg = {
|
|
185
|
-
id: randomUUID(),
|
|
186
|
-
type: "error",
|
|
187
|
-
connectionId,
|
|
188
|
-
timestamp: Date.now(),
|
|
189
|
-
data: { error: errorMessage },
|
|
190
|
-
};
|
|
191
|
-
this.sendToConnection(connectionId, errorMsg);
|
|
192
|
-
}
|
|
193
|
-
showTypingIndicator(connectionId, sender) {
|
|
194
|
-
if (!this.options.enableTypingIndicators) {
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
const message = {
|
|
198
|
-
id: randomUUID(),
|
|
199
|
-
type: "system",
|
|
200
|
-
connectionId,
|
|
201
|
-
timestamp: Date.now(),
|
|
202
|
-
data: {
|
|
203
|
-
event: "typing_start",
|
|
204
|
-
sender,
|
|
205
|
-
},
|
|
206
|
-
};
|
|
207
|
-
this.sendToConnection(connectionId, message);
|
|
208
|
-
}
|
|
209
|
-
clearTypingIndicator(connectionId) {
|
|
210
|
-
const timeout = this.typingIndicators.get(connectionId);
|
|
211
|
-
if (timeout) {
|
|
212
|
-
clearTimeout(timeout);
|
|
213
|
-
this.typingIndicators.delete(connectionId);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
updatePresence(connectionId, status) {
|
|
217
|
-
if (!this.options.enablePresenceTracking) {
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
this.presenceTracking.set(connectionId, {
|
|
221
|
-
lastSeen: Date.now(),
|
|
222
|
-
status,
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
handleWebSocketChatMessage(connectionId, message) {
|
|
226
|
-
const data = message.data;
|
|
227
|
-
if (!data || typeof data !== "object") {
|
|
228
|
-
return;
|
|
229
|
-
}
|
|
230
|
-
switch (data.event) {
|
|
231
|
-
case "chat_request":
|
|
232
|
-
this.handleWebSocketChatRequest(connectionId, data.request);
|
|
233
|
-
break;
|
|
234
|
-
case "join_room":
|
|
235
|
-
this.wsServer.joinRoom(connectionId, data.roomId);
|
|
236
|
-
break;
|
|
237
|
-
case "leave_room":
|
|
238
|
-
this.wsServer.leaveRoom(connectionId, data.roomId);
|
|
239
|
-
break;
|
|
240
|
-
case "typing_start":
|
|
241
|
-
this.showTypingIndicator(connectionId, data.sender || "user");
|
|
242
|
-
break;
|
|
243
|
-
case "typing_stop":
|
|
244
|
-
this.clearTypingIndicator(connectionId);
|
|
245
|
-
break;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
// Public API
|
|
249
|
-
getConnectionCount() {
|
|
250
|
-
return this.wsServer.getConnectionCount();
|
|
251
|
-
}
|
|
252
|
-
getRoomCount() {
|
|
253
|
-
return this.wsServer.getRoomCount();
|
|
254
|
-
}
|
|
255
|
-
getStreamingMetrics() {
|
|
256
|
-
return this.streamingManager.getStreamingMetrics();
|
|
257
|
-
}
|
|
258
|
-
close() {
|
|
259
|
-
this.wsServer.close();
|
|
260
|
-
this.streamingManager.destroy();
|
|
261
|
-
}
|
|
262
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* MCP Server Management Commands
|
|
4
|
-
* Real MCP server connectivity and management
|
|
5
|
-
*/
|
|
6
|
-
import type { Argv } from "yargs";
|
|
7
|
-
import type { JsonValue } from "../../lib/types/common.js";
|
|
8
|
-
interface MCPServerConfig {
|
|
9
|
-
name: string;
|
|
10
|
-
command: string;
|
|
11
|
-
args?: string[];
|
|
12
|
-
env?: Record<string, string>;
|
|
13
|
-
cwd?: string;
|
|
14
|
-
transport: "stdio" | "sse";
|
|
15
|
-
url?: string;
|
|
16
|
-
}
|
|
17
|
-
export declare function executeMCPTool(serverConfig: MCPServerConfig, toolName: string, toolParams: JsonValue): Promise<JsonValue>;
|
|
18
|
-
export declare function mcpExecuteTool(serverName: string, toolName: string, toolParams: JsonValue): Promise<JsonValue>;
|
|
19
|
-
export declare function addMCPCommands(yargs: Argv): Argv;
|
|
20
|
-
export {};
|