@juspay/neurolink 6.0.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.
Files changed (283) hide show
  1. package/CHANGELOG.md +14 -3
  2. package/dist/cli/commands/config.d.ts +13 -13
  3. package/dist/cli/index.js +3 -9
  4. package/dist/core/analytics.d.ts +11 -1
  5. package/dist/core/analytics.js +2 -2
  6. package/dist/core/base-provider.js +4 -18
  7. package/dist/core/dynamic-models.d.ts +8 -8
  8. package/dist/core/factory.js +3 -11
  9. package/dist/index.d.ts +2 -4
  10. package/dist/index.js +2 -11
  11. package/dist/lib/core/analytics.d.ts +11 -1
  12. package/dist/lib/core/analytics.js +2 -2
  13. package/dist/lib/core/base-provider.js +4 -18
  14. package/dist/lib/core/dynamic-models.d.ts +8 -8
  15. package/dist/lib/core/factory.js +3 -11
  16. package/dist/lib/index.d.ts +2 -4
  17. package/dist/lib/index.js +2 -11
  18. package/dist/lib/mcp/factory.d.ts +1 -1
  19. package/dist/lib/mcp/index.d.ts +7 -19
  20. package/dist/lib/mcp/index.js +15 -56
  21. package/dist/lib/neurolink.d.ts +1 -9
  22. package/dist/lib/neurolink.js +21 -70
  23. package/dist/lib/providers/amazon-bedrock.js +5 -16
  24. package/dist/lib/providers/anthropic-baseprovider.js +3 -21
  25. package/dist/lib/providers/anthropic.js +4 -7
  26. package/dist/lib/providers/azure-openai.js +4 -2
  27. package/dist/lib/providers/google-vertex.js +5 -9
  28. package/dist/lib/providers/huggingFace.js +5 -10
  29. package/dist/lib/providers/mistral.js +5 -8
  30. package/dist/lib/providers/openAI.js +4 -7
  31. package/dist/lib/utils/providerConfig.d.ts +117 -0
  32. package/dist/lib/utils/providerConfig.js +353 -0
  33. package/dist/lib/utils/providerUtils.d.ts +2 -1
  34. package/dist/lib/utils/providerUtils.js +53 -36
  35. package/dist/lib/utils/timeout.d.ts +72 -1
  36. package/dist/lib/utils/timeout.js +203 -2
  37. package/dist/mcp/factory.d.ts +1 -1
  38. package/dist/mcp/index.d.ts +7 -19
  39. package/dist/mcp/index.js +15 -56
  40. package/dist/neurolink.d.ts +1 -9
  41. package/dist/neurolink.js +21 -70
  42. package/dist/providers/amazon-bedrock.js +5 -16
  43. package/dist/providers/anthropic-baseprovider.js +3 -21
  44. package/dist/providers/anthropic.js +4 -7
  45. package/dist/providers/azure-openai.js +4 -2
  46. package/dist/providers/google-vertex.js +5 -9
  47. package/dist/providers/huggingFace.js +5 -10
  48. package/dist/providers/mistral.js +5 -8
  49. package/dist/providers/openAI.js +4 -7
  50. package/dist/utils/providerConfig.d.ts +117 -0
  51. package/dist/utils/providerConfig.js +353 -0
  52. package/dist/utils/providerUtils.d.ts +2 -1
  53. package/dist/utils/providerUtils.js +53 -36
  54. package/dist/utils/timeout.d.ts +72 -1
  55. package/dist/utils/timeout.js +203 -2
  56. package/package.json +2 -1
  57. package/dist/chat/client-utils.d.ts +0 -95
  58. package/dist/chat/client-utils.js +0 -315
  59. package/dist/chat/index.d.ts +0 -24
  60. package/dist/chat/index.js +0 -33
  61. package/dist/chat/session-storage.d.ts +0 -77
  62. package/dist/chat/session-storage.js +0 -233
  63. package/dist/chat/session.d.ts +0 -96
  64. package/dist/chat/session.js +0 -257
  65. package/dist/chat/sse-handler.d.ts +0 -49
  66. package/dist/chat/sse-handler.js +0 -259
  67. package/dist/chat/types.d.ts +0 -74
  68. package/dist/chat/types.js +0 -5
  69. package/dist/chat/websocket-chat-handler.d.ts +0 -37
  70. package/dist/chat/websocket-chat-handler.js +0 -262
  71. package/dist/cli/commands/mcp.d.ts +0 -20
  72. package/dist/cli/commands/mcp.js +0 -1272
  73. package/dist/core/defaults.d.ts +0 -19
  74. package/dist/core/defaults.js +0 -29
  75. package/dist/core/evaluation-config.d.ts +0 -29
  76. package/dist/core/evaluation-config.js +0 -144
  77. package/dist/factories/compatibility-factory.d.ts +0 -35
  78. package/dist/factories/compatibility-factory.js +0 -71
  79. package/dist/factories/provider-generate-factory.d.ts +0 -20
  80. package/dist/factories/provider-generate-factory.js +0 -93
  81. package/dist/lib/chat/client-utils.d.ts +0 -95
  82. package/dist/lib/chat/client-utils.js +0 -315
  83. package/dist/lib/chat/index.d.ts +0 -24
  84. package/dist/lib/chat/index.js +0 -33
  85. package/dist/lib/chat/session-storage.d.ts +0 -77
  86. package/dist/lib/chat/session-storage.js +0 -233
  87. package/dist/lib/chat/session.d.ts +0 -96
  88. package/dist/lib/chat/session.js +0 -257
  89. package/dist/lib/chat/sse-handler.d.ts +0 -49
  90. package/dist/lib/chat/sse-handler.js +0 -259
  91. package/dist/lib/chat/types.d.ts +0 -74
  92. package/dist/lib/chat/types.js +0 -5
  93. package/dist/lib/chat/websocket-chat-handler.d.ts +0 -37
  94. package/dist/lib/chat/websocket-chat-handler.js +0 -262
  95. package/dist/lib/core/defaults.d.ts +0 -19
  96. package/dist/lib/core/defaults.js +0 -29
  97. package/dist/lib/core/evaluation-config.d.ts +0 -29
  98. package/dist/lib/core/evaluation-config.js +0 -144
  99. package/dist/lib/factories/compatibility-factory.d.ts +0 -35
  100. package/dist/lib/factories/compatibility-factory.js +0 -71
  101. package/dist/lib/factories/provider-generate-factory.d.ts +0 -20
  102. package/dist/lib/factories/provider-generate-factory.js +0 -93
  103. package/dist/lib/mcp/adapters/plugin-bridge.d.ts +0 -40
  104. package/dist/lib/mcp/adapters/plugin-bridge.js +0 -89
  105. package/dist/lib/mcp/auto-discovery.d.ts +0 -62
  106. package/dist/lib/mcp/auto-discovery.js +0 -149
  107. package/dist/lib/mcp/client.d.ts +0 -68
  108. package/dist/lib/mcp/client.js +0 -248
  109. package/dist/lib/mcp/config.d.ts +0 -31
  110. package/dist/lib/mcp/config.js +0 -99
  111. package/dist/lib/mcp/context-manager.d.ts +0 -171
  112. package/dist/lib/mcp/context-manager.js +0 -362
  113. package/dist/lib/mcp/contracts/mcp-contract.d.ts +0 -169
  114. package/dist/lib/mcp/contracts/mcp-contract.js +0 -58
  115. package/dist/lib/mcp/core/plugin-manager.d.ts +0 -46
  116. package/dist/lib/mcp/core/plugin-manager.js +0 -110
  117. package/dist/lib/mcp/demo/plugin-demo.d.ts +0 -20
  118. package/dist/lib/mcp/demo/plugin-demo.js +0 -118
  119. package/dist/lib/mcp/dynamic-chain-executor.d.ts +0 -225
  120. package/dist/lib/mcp/dynamic-chain-executor.js +0 -489
  121. package/dist/lib/mcp/dynamic-orchestrator.d.ts +0 -115
  122. package/dist/lib/mcp/dynamic-orchestrator.js +0 -351
  123. package/dist/lib/mcp/ecosystem.d.ts +0 -75
  124. package/dist/lib/mcp/ecosystem.js +0 -161
  125. package/dist/lib/mcp/error-manager.d.ts +0 -254
  126. package/dist/lib/mcp/error-manager.js +0 -501
  127. package/dist/lib/mcp/error-recovery.d.ts +0 -159
  128. package/dist/lib/mcp/error-recovery.js +0 -405
  129. package/dist/lib/mcp/external-client.d.ts +0 -88
  130. package/dist/lib/mcp/external-client.js +0 -331
  131. package/dist/lib/mcp/external-manager.d.ts +0 -112
  132. package/dist/lib/mcp/external-manager.js +0 -308
  133. package/dist/lib/mcp/function-calling.d.ts +0 -65
  134. package/dist/lib/mcp/function-calling.js +0 -642
  135. package/dist/lib/mcp/health-monitor.d.ts +0 -257
  136. package/dist/lib/mcp/health-monitor.js +0 -630
  137. package/dist/lib/mcp/initialize-tools.d.ts +0 -29
  138. package/dist/lib/mcp/initialize-tools.js +0 -261
  139. package/dist/lib/mcp/initialize.d.ts +0 -18
  140. package/dist/lib/mcp/initialize.js +0 -62
  141. package/dist/lib/mcp/manager.d.ts +0 -68
  142. package/dist/lib/mcp/manager.js +0 -176
  143. package/dist/lib/mcp/neurolink-mcp-client.d.ts +0 -97
  144. package/dist/lib/mcp/neurolink-mcp-client.js +0 -462
  145. package/dist/lib/mcp/orchestrator.d.ts +0 -302
  146. package/dist/lib/mcp/orchestrator.js +0 -703
  147. package/dist/lib/mcp/plugin-manager.d.ts +0 -98
  148. package/dist/lib/mcp/plugin-manager.js +0 -296
  149. package/dist/lib/mcp/plugins/core/filesystem-mcp.d.ts +0 -36
  150. package/dist/lib/mcp/plugins/core/filesystem-mcp.js +0 -142
  151. package/dist/lib/mcp/plugins/filesystem-mcp.d.ts +0 -37
  152. package/dist/lib/mcp/plugins/filesystem-mcp.js +0 -54
  153. package/dist/lib/mcp/security-manager.d.ts +0 -87
  154. package/dist/lib/mcp/security-manager.js +0 -344
  155. package/dist/lib/mcp/semaphore-manager.d.ts +0 -137
  156. package/dist/lib/mcp/semaphore-manager.js +0 -329
  157. package/dist/lib/mcp/session-manager.d.ts +0 -187
  158. package/dist/lib/mcp/session-manager.js +0 -400
  159. package/dist/lib/mcp/session-persistence.d.ts +0 -93
  160. package/dist/lib/mcp/session-persistence.js +0 -301
  161. package/dist/lib/mcp/tool-integration.d.ts +0 -58
  162. package/dist/lib/mcp/tool-integration.js +0 -203
  163. package/dist/lib/mcp/transport-manager.d.ts +0 -154
  164. package/dist/lib/mcp/transport-manager.js +0 -334
  165. package/dist/lib/mcp/unified-mcp.d.ts +0 -133
  166. package/dist/lib/mcp/unified-mcp.js +0 -251
  167. package/dist/lib/mcp/unified-registry.d.ts +0 -165
  168. package/dist/lib/mcp/unified-registry.js +0 -538
  169. package/dist/lib/providers/analytics-helper.d.ts +0 -38
  170. package/dist/lib/providers/analytics-helper.js +0 -216
  171. package/dist/lib/providers/function-calling-provider.d.ts +0 -142
  172. package/dist/lib/providers/function-calling-provider.js +0 -630
  173. package/dist/lib/providers/mcp-provider.d.ts +0 -75
  174. package/dist/lib/providers/mcp-provider.js +0 -283
  175. package/dist/lib/providers/timeout-wrapper.d.ts +0 -40
  176. package/dist/lib/providers/timeout-wrapper.js +0 -100
  177. package/dist/lib/sdk/tool-extension.d.ts +0 -181
  178. package/dist/lib/sdk/tool-extension.js +0 -284
  179. package/dist/lib/services/streaming/streaming-manager.d.ts +0 -29
  180. package/dist/lib/services/streaming/streaming-manager.js +0 -245
  181. package/dist/lib/services/types.d.ts +0 -156
  182. package/dist/lib/services/types.js +0 -2
  183. package/dist/lib/services/websocket/websocket-server.d.ts +0 -34
  184. package/dist/lib/services/websocket/websocket-server.js +0 -305
  185. package/dist/lib/utils/provider-validation.d.ts +0 -36
  186. package/dist/lib/utils/provider-validation.js +0 -625
  187. package/dist/lib/utils/providerUtils-fixed.d.ts +0 -8
  188. package/dist/lib/utils/providerUtils-fixed.js +0 -94
  189. package/dist/lib/utils/streaming-utils.d.ts +0 -79
  190. package/dist/lib/utils/streaming-utils.js +0 -198
  191. package/dist/lib/utils/timeout-manager.d.ts +0 -75
  192. package/dist/lib/utils/timeout-manager.js +0 -244
  193. package/dist/mcp/adapters/plugin-bridge.d.ts +0 -40
  194. package/dist/mcp/adapters/plugin-bridge.js +0 -89
  195. package/dist/mcp/auto-discovery.d.ts +0 -62
  196. package/dist/mcp/auto-discovery.js +0 -149
  197. package/dist/mcp/client.d.ts +0 -68
  198. package/dist/mcp/client.js +0 -248
  199. package/dist/mcp/config.d.ts +0 -31
  200. package/dist/mcp/config.js +0 -99
  201. package/dist/mcp/context-manager.d.ts +0 -171
  202. package/dist/mcp/context-manager.js +0 -362
  203. package/dist/mcp/contracts/mcp-contract.d.ts +0 -169
  204. package/dist/mcp/contracts/mcp-contract.js +0 -58
  205. package/dist/mcp/core/plugin-manager.d.ts +0 -46
  206. package/dist/mcp/core/plugin-manager.js +0 -110
  207. package/dist/mcp/demo/plugin-demo.d.ts +0 -20
  208. package/dist/mcp/demo/plugin-demo.js +0 -118
  209. package/dist/mcp/dynamic-chain-executor.d.ts +0 -225
  210. package/dist/mcp/dynamic-chain-executor.js +0 -489
  211. package/dist/mcp/dynamic-orchestrator.d.ts +0 -115
  212. package/dist/mcp/dynamic-orchestrator.js +0 -351
  213. package/dist/mcp/ecosystem.d.ts +0 -75
  214. package/dist/mcp/ecosystem.js +0 -162
  215. package/dist/mcp/error-manager.d.ts +0 -254
  216. package/dist/mcp/error-manager.js +0 -501
  217. package/dist/mcp/error-recovery.d.ts +0 -159
  218. package/dist/mcp/error-recovery.js +0 -405
  219. package/dist/mcp/external-client.d.ts +0 -88
  220. package/dist/mcp/external-client.js +0 -331
  221. package/dist/mcp/external-manager.d.ts +0 -112
  222. package/dist/mcp/external-manager.js +0 -308
  223. package/dist/mcp/function-calling.d.ts +0 -65
  224. package/dist/mcp/function-calling.js +0 -642
  225. package/dist/mcp/health-monitor.d.ts +0 -257
  226. package/dist/mcp/health-monitor.js +0 -630
  227. package/dist/mcp/initialize-tools.d.ts +0 -29
  228. package/dist/mcp/initialize-tools.js +0 -262
  229. package/dist/mcp/initialize.d.ts +0 -18
  230. package/dist/mcp/initialize.js +0 -62
  231. package/dist/mcp/manager.d.ts +0 -68
  232. package/dist/mcp/manager.js +0 -176
  233. package/dist/mcp/neurolink-mcp-client.d.ts +0 -97
  234. package/dist/mcp/neurolink-mcp-client.js +0 -462
  235. package/dist/mcp/orchestrator.d.ts +0 -302
  236. package/dist/mcp/orchestrator.js +0 -703
  237. package/dist/mcp/plugin-manager.d.ts +0 -98
  238. package/dist/mcp/plugin-manager.js +0 -297
  239. package/dist/mcp/plugins/core/filesystem-mcp.d.ts +0 -36
  240. package/dist/mcp/plugins/core/filesystem-mcp.js +0 -142
  241. package/dist/mcp/plugins/core/neurolink-mcp.json +0 -17
  242. package/dist/mcp/plugins/filesystem-mcp.d.ts +0 -37
  243. package/dist/mcp/plugins/filesystem-mcp.js +0 -54
  244. package/dist/mcp/security-manager.d.ts +0 -87
  245. package/dist/mcp/security-manager.js +0 -344
  246. package/dist/mcp/semaphore-manager.d.ts +0 -137
  247. package/dist/mcp/semaphore-manager.js +0 -329
  248. package/dist/mcp/session-manager.d.ts +0 -187
  249. package/dist/mcp/session-manager.js +0 -400
  250. package/dist/mcp/session-persistence.d.ts +0 -93
  251. package/dist/mcp/session-persistence.js +0 -302
  252. package/dist/mcp/tool-integration.d.ts +0 -58
  253. package/dist/mcp/tool-integration.js +0 -203
  254. package/dist/mcp/transport-manager.d.ts +0 -154
  255. package/dist/mcp/transport-manager.js +0 -335
  256. package/dist/mcp/unified-mcp.d.ts +0 -133
  257. package/dist/mcp/unified-mcp.js +0 -251
  258. package/dist/mcp/unified-registry.d.ts +0 -165
  259. package/dist/mcp/unified-registry.js +0 -539
  260. package/dist/providers/analytics-helper.d.ts +0 -38
  261. package/dist/providers/analytics-helper.js +0 -216
  262. package/dist/providers/function-calling-provider.d.ts +0 -142
  263. package/dist/providers/function-calling-provider.js +0 -630
  264. package/dist/providers/mcp-provider.d.ts +0 -75
  265. package/dist/providers/mcp-provider.js +0 -283
  266. package/dist/providers/timeout-wrapper.d.ts +0 -40
  267. package/dist/providers/timeout-wrapper.js +0 -100
  268. package/dist/sdk/tool-extension.d.ts +0 -181
  269. package/dist/sdk/tool-extension.js +0 -284
  270. package/dist/services/streaming/streaming-manager.d.ts +0 -29
  271. package/dist/services/streaming/streaming-manager.js +0 -245
  272. package/dist/services/types.d.ts +0 -156
  273. package/dist/services/types.js +0 -2
  274. package/dist/services/websocket/websocket-server.d.ts +0 -34
  275. package/dist/services/websocket/websocket-server.js +0 -306
  276. package/dist/utils/provider-validation.d.ts +0 -36
  277. package/dist/utils/provider-validation.js +0 -625
  278. package/dist/utils/providerUtils-fixed.d.ts +0 -8
  279. package/dist/utils/providerUtils-fixed.js +0 -94
  280. package/dist/utils/streaming-utils.d.ts +0 -79
  281. package/dist/utils/streaming-utils.js +0 -198
  282. package/dist/utils/timeout-manager.d.ts +0 -75
  283. package/dist/utils/timeout-manager.js +0 -244
@@ -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
- }
@@ -1,5 +0,0 @@
1
- /**
2
- * Phase 3: SSE Chat Utilities
3
- * Type definitions for chat infrastructure
4
- */
5
- export {};
@@ -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,19 +0,0 @@
1
- /**
2
- * Default value helper functions for NeuroLink
3
- * Centralized logic for applying defaults across the system
4
- */
5
- import type { UnknownRecord } from "../types/common.js";
6
- /**
7
- * Apply default values to options object
8
- * User-provided values take precedence over defaults
9
- */
10
- export declare function applyDefaults(options: UnknownRecord): UnknownRecord;
11
- /**
12
- * Get default max tokens for a specific provider
13
- * Can be extended for provider-specific overrides in the future
14
- */
15
- export declare function getDefaultMaxTokens(provider?: string): number;
16
- /**
17
- * Get default temperature for a specific use case
18
- */
19
- export declare function getDefaultTemperature(useCase?: string): number;
@@ -1,29 +0,0 @@
1
- /**
2
- * Default value helper functions for NeuroLink
3
- * Centralized logic for applying defaults across the system
4
- */
5
- import { ENV_DEFAULTS, } from "./constants.js";
6
- /**
7
- * Apply default values to options object
8
- * User-provided values take precedence over defaults
9
- */
10
- export function applyDefaults(options) {
11
- return {
12
- maxTokens: ENV_DEFAULTS.maxTokens,
13
- temperature: ENV_DEFAULTS.temperature,
14
- ...options, // User overrides take precedence
15
- };
16
- }
17
- /**
18
- * Get default max tokens for a specific provider
19
- * Can be extended for provider-specific overrides in the future
20
- */
21
- export function getDefaultMaxTokens(provider) {
22
- return ENV_DEFAULTS.maxTokens;
23
- }
24
- /**
25
- * Get default temperature for a specific use case
26
- */
27
- export function getDefaultTemperature(useCase) {
28
- return ENV_DEFAULTS.temperature;
29
- }
@@ -1,29 +0,0 @@
1
- import type { EvaluationConfig } from "./types.js";
2
- /**
3
- * Parse evaluation configuration from environment variables
4
- */
5
- export declare function parseEvaluationConfig(): EvaluationConfig;
6
- /**
7
- * Get intelligent provider fallback order
8
- */
9
- export declare function getProviderFallbackOrder(config: EvaluationConfig): string[];
10
- /**
11
- * Estimate evaluation cost
12
- */
13
- export declare function estimateEvaluationCost(providerName: string, mode: string, promptLength: number, expectedResponseLength?: number): number;
14
- /**
15
- * Validate evaluation configuration
16
- */
17
- export declare function validateEvaluationConfig(config: EvaluationConfig): string[];
18
- /**
19
- * Get configuration with validation and defaults
20
- */
21
- export declare function getValidatedEvaluationConfig(): EvaluationConfig;
22
- /**
23
- * Check if evaluation is enabled for the current configuration
24
- */
25
- export declare function isEvaluationEnabled(): boolean;
26
- /**
27
- * Get cost-optimized provider based on configuration
28
- */
29
- export declare function getCostOptimizedProvider(config: EvaluationConfig): string | null;
@@ -1,144 +0,0 @@
1
- import { getAvailableProviders, sortProvidersByPreference, getProviderConfig, } from "./evaluation-providers.js";
2
- import { logger } from "../utils/logger.js";
3
- /**
4
- * Parse evaluation configuration from environment variables
5
- */
6
- export function parseEvaluationConfig() {
7
- return {
8
- provider: process.env.NEUROLINK_EVALUATION_PROVIDER || "google-ai",
9
- model: process.env.NEUROLINK_EVALUATION_MODEL || "gemini-2.5-flash",
10
- mode: process.env.NEUROLINK_EVALUATION_MODE || "fast",
11
- fallbackEnabled: process.env.NEUROLINK_EVALUATION_FALLBACK_ENABLED !== "false",
12
- fallbackProviders: (process.env.NEUROLINK_EVALUATION_FALLBACK_PROVIDERS ||
13
- "openai,anthropic,vertex,bedrock").split(","),
14
- timeout: parseInt(process.env.NEUROLINK_EVALUATION_TIMEOUT || "10000"),
15
- maxTokens: parseInt(process.env.NEUROLINK_EVALUATION_MAX_TOKENS || "500"),
16
- temperature: parseFloat(process.env.NEUROLINK_EVALUATION_TEMPERATURE || "0.1"),
17
- preferCheap: process.env.NEUROLINK_EVALUATION_PREFER_CHEAP !== "false",
18
- maxCostPerEval: parseFloat(process.env.NEUROLINK_EVALUATION_MAX_COST_PER_EVAL || "0.01"),
19
- retryAttempts: parseInt(process.env.NEUROLINK_EVALUATION_RETRY_ATTEMPTS || "2"),
20
- };
21
- }
22
- /**
23
- * Get intelligent provider fallback order
24
- */
25
- export function getProviderFallbackOrder(config) {
26
- const available = getAvailableProviders();
27
- const sorted = sortProvidersByPreference(available, config.preferCheap);
28
- // Start with user's preferred provider
29
- const fallbackOrder = [config.provider];
30
- // Add configured fallbacks
31
- config.fallbackProviders.forEach((provider) => {
32
- if (!fallbackOrder.includes(provider)) {
33
- fallbackOrder.push(provider);
34
- }
35
- });
36
- // Add remaining available providers
37
- sorted.forEach((providerConfig) => {
38
- if (!fallbackOrder.includes(providerConfig.provider)) {
39
- fallbackOrder.push(providerConfig.provider);
40
- }
41
- });
42
- logger.debug("[EvaluationConfig] Provider fallback order:", fallbackOrder);
43
- return fallbackOrder;
44
- }
45
- /**
46
- * Estimate evaluation cost
47
- */
48
- export function estimateEvaluationCost(providerName, mode, promptLength, expectedResponseLength = 200) {
49
- const config = getProviderConfig(providerName);
50
- if (!config || !config.costPerToken) {
51
- return 0;
52
- }
53
- const inputTokens = Math.ceil(promptLength / 4); // Rough token estimation
54
- const outputTokens = expectedResponseLength / 4;
55
- return (inputTokens * config.costPerToken.input +
56
- outputTokens * config.costPerToken.output);
57
- }
58
- /**
59
- * Validate evaluation configuration
60
- */
61
- export function validateEvaluationConfig(config) {
62
- const errors = [];
63
- // Validate provider
64
- if (!getProviderConfig(config.provider)) {
65
- errors.push(`Invalid provider: ${config.provider}`);
66
- }
67
- // Validate mode
68
- if (!["fast", "balanced", "quality"].includes(config.mode)) {
69
- errors.push(`Invalid mode: ${config.mode}. Must be 'fast', 'balanced', or 'quality'`);
70
- }
71
- // Validate timeout
72
- if (config.timeout <= 0 || config.timeout > 60000) {
73
- errors.push(`Invalid timeout: ${config.timeout}. Must be between 1 and 60000ms`);
74
- }
75
- // Validate max tokens
76
- if (config.maxTokens <= 0 || config.maxTokens > 4000) {
77
- errors.push(`Invalid maxTokens: ${config.maxTokens}. Must be between 1 and 4000`);
78
- }
79
- // Validate temperature
80
- if (config.temperature < 0 || config.temperature > 2) {
81
- errors.push(`Invalid temperature: ${config.temperature}. Must be between 0 and 2`);
82
- }
83
- // Validate max cost
84
- if (config.maxCostPerEval <= 0) {
85
- errors.push(`Invalid maxCostPerEval: ${config.maxCostPerEval}. Must be greater than 0`);
86
- }
87
- // Validate retry attempts
88
- if (config.retryAttempts < 0 || config.retryAttempts > 5) {
89
- errors.push(`Invalid retryAttempts: ${config.retryAttempts}. Must be between 0 and 5`);
90
- }
91
- return errors;
92
- }
93
- /**
94
- * Get configuration with validation and defaults
95
- */
96
- export function getValidatedEvaluationConfig() {
97
- const config = parseEvaluationConfig();
98
- const errors = validateEvaluationConfig(config);
99
- if (errors.length > 0) {
100
- logger.warn("[EvaluationConfig] Configuration validation errors:", errors);
101
- // Return default configuration if validation fails
102
- return {
103
- provider: "google-ai",
104
- model: "gemini-2.5-flash",
105
- mode: "fast",
106
- fallbackEnabled: true,
107
- fallbackProviders: ["openai", "anthropic"],
108
- timeout: 10000,
109
- maxTokens: 500,
110
- temperature: 0.1,
111
- preferCheap: true,
112
- maxCostPerEval: 0.01,
113
- retryAttempts: 2,
114
- };
115
- }
116
- return config;
117
- }
118
- /**
119
- * Check if evaluation is enabled for the current configuration
120
- */
121
- export function isEvaluationEnabled() {
122
- // Check if at least one provider is available
123
- const available = getAvailableProviders();
124
- return available.length > 0;
125
- }
126
- /**
127
- * Get cost-optimized provider based on configuration
128
- */
129
- export function getCostOptimizedProvider(config) {
130
- const available = getAvailableProviders();
131
- if (available.length === 0) {
132
- return null;
133
- }
134
- const sorted = sortProvidersByPreference(available, true); // Always prefer cheap for cost optimization
135
- // Find the cheapest provider that meets cost requirements
136
- for (const providerConfig of sorted) {
137
- const estimatedCost = estimateEvaluationCost(providerConfig.provider, config.mode, 1000);
138
- if (estimatedCost <= config.maxCostPerEval) {
139
- return providerConfig.provider;
140
- }
141
- }
142
- // If no provider meets cost requirements, return the cheapest one
143
- return sorted[0].provider;
144
- }
@@ -1,35 +0,0 @@
1
- import type { GenerateOptions, GenerateResult } from "../types/generate-types.js";
2
- import type { TextGenerationOptions } from "../core/types.js";
3
- /**
4
- * Compatibility conversion factory for seamless migration
5
- * between generateText and generate functions
6
- */
7
- export declare class CompatibilityConversionFactory {
8
- /**
9
- * Convert TextGenerationOptions to GenerateOptions
10
- */
11
- static convertTextToGenerate(options: TextGenerationOptions): GenerateOptions;
12
- /**
13
- * Convert GenerateResult to legacy TextGenerationResult format
14
- */
15
- static convertGenerateToText(result: GenerateResult): {
16
- content: string;
17
- provider?: string;
18
- model?: string;
19
- usage?: {
20
- inputTokens: number;
21
- outputTokens: number;
22
- totalTokens: number;
23
- };
24
- responseTime?: number;
25
- toolsUsed?: number;
26
- toolExecutions?: unknown[];
27
- analytics?: unknown;
28
- evaluation?: unknown;
29
- [key: string]: unknown;
30
- };
31
- /**
32
- * Convert GenerateOptions to TextGenerationOptions
33
- */
34
- static convertGenerateToText_Options(options: GenerateOptions): TextGenerationOptions;
35
- }