@juspay/neurolink 3.0.1 → 4.0.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 (192) hide show
  1. package/CHANGELOG.md +57 -6
  2. package/README.md +235 -2
  3. package/dist/agent/direct-tools.d.ts +6 -6
  4. package/dist/chat/client-utils.d.ts +92 -0
  5. package/dist/chat/client-utils.js +298 -0
  6. package/dist/chat/index.d.ts +27 -0
  7. package/dist/chat/index.js +41 -0
  8. package/dist/chat/session-storage.d.ts +77 -0
  9. package/dist/chat/session-storage.js +233 -0
  10. package/dist/chat/session.d.ts +95 -0
  11. package/dist/chat/session.js +257 -0
  12. package/dist/chat/sse-handler.d.ts +49 -0
  13. package/dist/chat/sse-handler.js +266 -0
  14. package/dist/chat/types.d.ts +73 -0
  15. package/dist/chat/types.js +5 -0
  16. package/dist/chat/websocket-chat-handler.d.ts +36 -0
  17. package/dist/chat/websocket-chat-handler.js +262 -0
  18. package/dist/cli/commands/config.js +12 -12
  19. package/dist/cli/commands/mcp.js +3 -4
  20. package/dist/cli/index.d.ts +0 -7
  21. package/dist/cli/index.js +247 -28
  22. package/dist/config/configManager.d.ts +60 -0
  23. package/dist/config/configManager.js +300 -0
  24. package/dist/config/types.d.ts +136 -0
  25. package/dist/config/types.js +43 -0
  26. package/dist/core/analytics.d.ts +23 -0
  27. package/dist/core/analytics.js +131 -0
  28. package/dist/core/constants.d.ts +41 -0
  29. package/dist/core/constants.js +50 -0
  30. package/dist/core/defaults.d.ts +18 -0
  31. package/dist/core/defaults.js +29 -0
  32. package/dist/core/evaluation-config.d.ts +29 -0
  33. package/dist/core/evaluation-config.js +144 -0
  34. package/dist/core/evaluation-providers.d.ts +30 -0
  35. package/dist/core/evaluation-providers.js +187 -0
  36. package/dist/core/evaluation.d.ts +117 -0
  37. package/dist/core/evaluation.js +528 -0
  38. package/dist/core/factory.js +33 -25
  39. package/dist/core/types.d.ts +165 -6
  40. package/dist/core/types.js +3 -4
  41. package/dist/index.d.ts +9 -4
  42. package/dist/index.js +25 -4
  43. package/dist/lib/agent/direct-tools.d.ts +6 -6
  44. package/dist/lib/chat/client-utils.d.ts +92 -0
  45. package/dist/lib/chat/client-utils.js +298 -0
  46. package/dist/lib/chat/index.d.ts +27 -0
  47. package/dist/lib/chat/index.js +41 -0
  48. package/dist/lib/chat/session-storage.d.ts +77 -0
  49. package/dist/lib/chat/session-storage.js +233 -0
  50. package/dist/lib/chat/session.d.ts +95 -0
  51. package/dist/lib/chat/session.js +257 -0
  52. package/dist/lib/chat/sse-handler.d.ts +49 -0
  53. package/dist/lib/chat/sse-handler.js +266 -0
  54. package/dist/lib/chat/types.d.ts +73 -0
  55. package/dist/lib/chat/types.js +5 -0
  56. package/dist/lib/chat/websocket-chat-handler.d.ts +36 -0
  57. package/dist/lib/chat/websocket-chat-handler.js +262 -0
  58. package/dist/lib/config/configManager.d.ts +60 -0
  59. package/dist/lib/config/configManager.js +300 -0
  60. package/dist/lib/config/types.d.ts +136 -0
  61. package/dist/lib/config/types.js +43 -0
  62. package/dist/lib/core/analytics.d.ts +23 -0
  63. package/dist/lib/core/analytics.js +131 -0
  64. package/dist/lib/core/constants.d.ts +41 -0
  65. package/dist/lib/core/constants.js +50 -0
  66. package/dist/lib/core/defaults.d.ts +18 -0
  67. package/dist/lib/core/defaults.js +29 -0
  68. package/dist/lib/core/evaluation-config.d.ts +29 -0
  69. package/dist/lib/core/evaluation-config.js +144 -0
  70. package/dist/lib/core/evaluation-providers.d.ts +30 -0
  71. package/dist/lib/core/evaluation-providers.js +187 -0
  72. package/dist/lib/core/evaluation.d.ts +117 -0
  73. package/dist/lib/core/evaluation.js +528 -0
  74. package/dist/lib/core/factory.js +33 -26
  75. package/dist/lib/core/types.d.ts +165 -6
  76. package/dist/lib/core/types.js +3 -4
  77. package/dist/lib/index.d.ts +9 -4
  78. package/dist/lib/index.js +25 -4
  79. package/dist/lib/mcp/contracts/mcpContract.d.ts +118 -0
  80. package/dist/lib/mcp/contracts/mcpContract.js +5 -0
  81. package/dist/lib/mcp/function-calling.js +11 -3
  82. package/dist/lib/mcp/logging.js +5 -0
  83. package/dist/lib/mcp/neurolink-mcp-client.js +2 -1
  84. package/dist/lib/mcp/orchestrator.js +18 -9
  85. package/dist/lib/mcp/registry.d.ts +49 -16
  86. package/dist/lib/mcp/registry.js +80 -6
  87. package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.js +5 -4
  88. package/dist/lib/mcp/tool-integration.js +1 -1
  89. package/dist/lib/mcp/tool-registry.d.ts +55 -34
  90. package/dist/lib/mcp/tool-registry.js +111 -97
  91. package/dist/lib/mcp/unified-mcp.js +6 -1
  92. package/dist/lib/mcp/unified-registry.d.ts +12 -4
  93. package/dist/lib/mcp/unified-registry.js +17 -4
  94. package/dist/lib/neurolink.d.ts +26 -0
  95. package/dist/lib/neurolink.js +43 -1
  96. package/dist/lib/providers/agent-enhanced-provider.d.ts +11 -2
  97. package/dist/lib/providers/agent-enhanced-provider.js +86 -15
  98. package/dist/lib/providers/amazonBedrock.d.ts +9 -1
  99. package/dist/lib/providers/amazonBedrock.js +26 -2
  100. package/dist/lib/providers/analytics-helper.d.ts +53 -0
  101. package/dist/lib/providers/analytics-helper.js +151 -0
  102. package/dist/lib/providers/anthropic.d.ts +11 -1
  103. package/dist/lib/providers/anthropic.js +29 -4
  104. package/dist/lib/providers/azureOpenAI.d.ts +3 -1
  105. package/dist/lib/providers/azureOpenAI.js +28 -4
  106. package/dist/lib/providers/function-calling-provider.d.ts +9 -1
  107. package/dist/lib/providers/function-calling-provider.js +14 -1
  108. package/dist/lib/providers/googleAIStudio.d.ts +15 -1
  109. package/dist/lib/providers/googleAIStudio.js +32 -2
  110. package/dist/lib/providers/googleVertexAI.d.ts +9 -1
  111. package/dist/lib/providers/googleVertexAI.js +31 -2
  112. package/dist/lib/providers/huggingFace.d.ts +3 -1
  113. package/dist/lib/providers/huggingFace.js +26 -3
  114. package/dist/lib/providers/mcp-provider.d.ts +9 -1
  115. package/dist/lib/providers/mcp-provider.js +12 -0
  116. package/dist/lib/providers/mistralAI.d.ts +3 -1
  117. package/dist/lib/providers/mistralAI.js +25 -2
  118. package/dist/lib/providers/ollama.d.ts +3 -1
  119. package/dist/lib/providers/ollama.js +27 -4
  120. package/dist/lib/providers/openAI.d.ts +15 -1
  121. package/dist/lib/providers/openAI.js +32 -2
  122. package/dist/lib/proxy/proxy-fetch.js +8 -7
  123. package/dist/lib/services/streaming/streaming-manager.d.ts +29 -0
  124. package/dist/lib/services/streaming/streaming-manager.js +244 -0
  125. package/dist/lib/services/types.d.ts +155 -0
  126. package/dist/lib/services/types.js +2 -0
  127. package/dist/lib/services/websocket/websocket-server.d.ts +34 -0
  128. package/dist/lib/services/websocket/websocket-server.js +304 -0
  129. package/dist/lib/telemetry/index.d.ts +15 -0
  130. package/dist/lib/telemetry/index.js +22 -0
  131. package/dist/lib/telemetry/telemetry-service.d.ts +47 -0
  132. package/dist/lib/telemetry/telemetry-service.js +259 -0
  133. package/dist/lib/utils/streaming-utils.d.ts +67 -0
  134. package/dist/lib/utils/streaming-utils.js +201 -0
  135. package/dist/mcp/contracts/mcpContract.d.ts +118 -0
  136. package/dist/mcp/contracts/mcpContract.js +5 -0
  137. package/dist/mcp/function-calling.js +11 -3
  138. package/dist/mcp/logging.js +5 -0
  139. package/dist/mcp/neurolink-mcp-client.js +2 -1
  140. package/dist/mcp/orchestrator.js +18 -9
  141. package/dist/mcp/registry.d.ts +49 -16
  142. package/dist/mcp/registry.js +80 -6
  143. package/dist/mcp/servers/ai-providers/ai-workflow-tools.d.ts +2 -2
  144. package/dist/mcp/servers/ai-providers/ai-workflow-tools.js +5 -4
  145. package/dist/mcp/tool-integration.js +1 -1
  146. package/dist/mcp/tool-registry.d.ts +55 -34
  147. package/dist/mcp/tool-registry.js +111 -97
  148. package/dist/mcp/unified-mcp.js +6 -1
  149. package/dist/mcp/unified-registry.d.ts +12 -4
  150. package/dist/mcp/unified-registry.js +17 -4
  151. package/dist/neurolink.d.ts +26 -0
  152. package/dist/neurolink.js +43 -1
  153. package/dist/providers/agent-enhanced-provider.d.ts +11 -2
  154. package/dist/providers/agent-enhanced-provider.js +86 -15
  155. package/dist/providers/amazonBedrock.d.ts +9 -1
  156. package/dist/providers/amazonBedrock.js +26 -2
  157. package/dist/providers/analytics-helper.d.ts +53 -0
  158. package/dist/providers/analytics-helper.js +151 -0
  159. package/dist/providers/anthropic.d.ts +11 -1
  160. package/dist/providers/anthropic.js +29 -4
  161. package/dist/providers/azureOpenAI.d.ts +3 -1
  162. package/dist/providers/azureOpenAI.js +29 -4
  163. package/dist/providers/function-calling-provider.d.ts +9 -1
  164. package/dist/providers/function-calling-provider.js +14 -1
  165. package/dist/providers/googleAIStudio.d.ts +15 -1
  166. package/dist/providers/googleAIStudio.js +32 -2
  167. package/dist/providers/googleVertexAI.d.ts +9 -1
  168. package/dist/providers/googleVertexAI.js +31 -2
  169. package/dist/providers/huggingFace.d.ts +3 -1
  170. package/dist/providers/huggingFace.js +26 -3
  171. package/dist/providers/mcp-provider.d.ts +9 -1
  172. package/dist/providers/mcp-provider.js +12 -0
  173. package/dist/providers/mistralAI.d.ts +3 -1
  174. package/dist/providers/mistralAI.js +25 -2
  175. package/dist/providers/ollama.d.ts +3 -1
  176. package/dist/providers/ollama.js +27 -4
  177. package/dist/providers/openAI.d.ts +15 -1
  178. package/dist/providers/openAI.js +33 -2
  179. package/dist/proxy/proxy-fetch.js +8 -7
  180. package/dist/services/streaming/streaming-manager.d.ts +29 -0
  181. package/dist/services/streaming/streaming-manager.js +244 -0
  182. package/dist/services/types.d.ts +155 -0
  183. package/dist/services/types.js +2 -0
  184. package/dist/services/websocket/websocket-server.d.ts +34 -0
  185. package/dist/services/websocket/websocket-server.js +304 -0
  186. package/dist/telemetry/index.d.ts +15 -0
  187. package/dist/telemetry/index.js +22 -0
  188. package/dist/telemetry/telemetry-service.d.ts +47 -0
  189. package/dist/telemetry/telemetry-service.js +261 -0
  190. package/dist/utils/streaming-utils.d.ts +67 -0
  191. package/dist/utils/streaming-utils.js +201 -0
  192. package/package.json +18 -2
package/CHANGELOG.md CHANGED
@@ -1,23 +1,74 @@
1
- ## [3.0.1](https://github.com/juspay/neurolink/compare/v3.0.0...v3.0.1) (2025-07-01)
1
+ # [4.0.0](https://github.com/juspay/neurolink/compare/v3.0.1...v4.0.0) (2025-07-06)
2
+
3
+
4
+ * feat(core)!: transform NeuroLink into enterprise AI analytics platform ([74c88d6](https://github.com/juspay/neurolink/commit/74c88d6484bbd983aba9119929481e655d62eab3))
5
+
6
+
7
+ ### BREAKING CHANGES
2
8
 
9
+ * Major architectural enhancement from basic AI SDK
10
+ to comprehensive enterprise platform with analytics, evaluation,
11
+ real-time services, and business intelligence capabilities.
12
+
13
+ Core Features Added:
14
+ - Analytics System: Usage tracking, cost estimation, performance monitoring
15
+ - Evaluation Framework: AI-powered quality assessment and scoring
16
+ - Enterprise Config: Backup/restore, validation, provider management
17
+ - Real-time Services: Chat, streaming, websocket capabilities
18
+ - Telemetry: OpenTelemetry integration for production monitoring
19
+ - Documentation: Complete business and technical documentation overhaul
20
+ - Examples: Comprehensive demo library with 30+ working examples
21
+ - Provider Integration: Analytics helper integrated across all 9 providers
22
+
23
+ Technical Implementation:
24
+ - NEW: src/lib/core/analytics.ts - Real usage tracking engine
25
+ - NEW: src/lib/core/evaluation.ts - AI quality assessment framework
26
+ - NEW: src/lib/config/configManager.ts - Enterprise configuration management
27
+ - NEW: src/lib/chat/ - Complete chat service infrastructure (7 files)
28
+ - NEW: src/lib/services/ - Streaming and WebSocket architecture
29
+ - NEW: src/lib/telemetry/ - OpenTelemetry integration
30
+ - NEW: examples/ - Comprehensive demo ecosystem (30+ examples)
31
+ - NEW: docs/ - Complete documentation overhaul (15+ guides)
32
+ - ENHANCED: All 9 providers with analytics integration
33
+ - ENHANCED: CLI with professional analytics display
34
+ - ENHANCED: Testing infrastructure with new test suites
35
+
36
+ Files Changed: 127 files (+20,542 additions, -6,142 deletions)
37
+ Backward Compatibility: 100% maintained - existing functionality preserved
38
+ New Features: Opt-in via --enable-analytics --enable-evaluation flags
39
+
40
+ Business Impact:
41
+ - Production Monitoring: Real-time performance and cost tracking
42
+ - Quality Assurance: AI-powered response evaluation and scoring
43
+ - Cost Optimization: Usage analytics and provider comparison
44
+ - Risk Management: Backup systems and error recovery
45
+ - Developer Experience: Professional CLI and comprehensive examples
46
+ - Enterprise Readiness: OpenTelemetry observability and operational excellence
47
+
48
+ Performance Metrics:
49
+ - Analytics: Real token counts (299-768), response times (2-10s)
50
+ - Evaluation: Quality scores (8-10/10), sub-6s processing
51
+ - Providers: All 9 providers enhanced with zero breaking changes
52
+ - CLI: Professional output with debug diagnostics
53
+
54
+ ## [3.0.1](https://github.com/juspay/neurolink/compare/v3.0.0...v3.0.1) (2025-07-01)
3
55
 
4
56
  ### Bug Fixes
5
57
 
6
- * **cli:** honor --model parameter in CLI commands ([467ea85](https://github.com/juspay/neurolink/commit/467ea8548688a9db6046c98dbfd268ecd297605c))
58
+ - **cli:** honor --model parameter in CLI commands ([467ea85](https://github.com/juspay/neurolink/commit/467ea8548688a9db6046c98dbfd268ecd297605c))
7
59
 
8
60
  # [3.0.0](https://github.com/juspay/neurolink/compare/v2.1.0...v3.0.0) (2025-07-01)
9
61
 
10
-
11
62
  ### Features
12
63
 
13
- * **proxy:** add comprehensive enterprise proxy support across all providers ([9668e67](https://github.com/juspay/neurolink/commit/9668e67dfaa27831ba85d45fdf5b7739de902b28))
14
-
64
+ - **proxy:** add comprehensive enterprise proxy support across all providers ([9668e67](https://github.com/juspay/neurolink/commit/9668e67dfaa27831ba85d45fdf5b7739de902b28))
15
65
 
16
66
  ### BREAKING CHANGES
17
67
 
18
- * **proxy:** None - fully backward compatible
68
+ - **proxy:** None - fully backward compatible
19
69
 
20
70
  Files modified:
71
+
21
72
  - docs/ENTERPRISE-PROXY-SETUP.md (NEW) - Comprehensive enterprise proxy guide
22
73
  - docs/PROVIDER-CONFIGURATION.md - Added proxy configuration section
23
74
  - docs/CLI-GUIDE.md - Added proxy environment variables documentation
package/README.md CHANGED
@@ -7,9 +7,69 @@
7
7
  [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue)](https://www.typescriptlang.org/)
8
8
  [![CI](https://github.com/juspay/neurolink/workflows/CI/badge.svg)](https://github.com/juspay/neurolink/actions)
9
9
 
10
- > Universal AI toolkit with multiple provider support, automatic fallback, and both CLI + SDK interfaces. Production-ready with TypeScript support.
10
+ > Enterprise AI Development Platform with real-time capabilities, advanced telemetry, and universal provider support. Production-ready with TypeScript support.
11
11
 
12
- **NeuroLink** unifies OpenAI, Bedrock, Vertex AI, Google AI Studio, Anthropic, Azure OpenAI, Hugging Face, Ollama, and Mistral AI with intelligent fallback and streaming support. Available as both a **programmatic SDK** and **professional CLI tool**. Extracted from production use at Juspay.
12
+ **NeuroLink** is an Enterprise AI Development Platform that unifies 9 major AI providers with intelligent fallback, real-time WebSocket infrastructure, and optional enterprise telemetry. Available as both a **programmatic SDK** and **professional CLI tool**. Extracted from production use at Juspay.
13
+
14
+ ## 🚀 Enterprise Platform Features
15
+
16
+ - **🌐 Real-time WebSocket Infrastructure** - Professional-grade streaming with session management
17
+ - **📊 Advanced Telemetry** - Optional OpenTelemetry monitoring with zero overhead when disabled
18
+ - **💬 Enhanced Chat Services** - Dual-mode SSE + WebSocket support for enterprise applications
19
+ - **🏗️ Enterprise Architecture** - Production-ready scaling with connection pooling and optimization
20
+
21
+ ## 🏗️ Enterprise Configuration Management
22
+
23
+ ### **✨ NEW: Automatic Backup System**
24
+
25
+ ```bash
26
+ # All config changes create automatic backups
27
+ npm run config:update
28
+ # ✅ Backup created: .neurolink.backups/neurolink-config-2025-01-07T10-30-00.js
29
+
30
+ # Auto-restore on failures
31
+ npm run config:validate
32
+ # ✅ Config validated with suggestions and warnings
33
+ ```
34
+
35
+ ### **✨ NEW: Industry-Standard Interfaces**
36
+
37
+ ```typescript
38
+ // Modern camelCase interfaces with rich context
39
+ interface ExecutionContext {
40
+ sessionId?: string;
41
+ userId?: string;
42
+ aiProvider?: string;
43
+ permissions?: string[];
44
+ cacheOptions?: CacheOptions;
45
+ fallbackOptions?: FallbackOptions;
46
+ metadata?: Record<string, unknown>;
47
+ }
48
+
49
+ // Optional methods for maximum flexibility
50
+ interface McpRegistry {
51
+ registerServer?(
52
+ serverId: string,
53
+ config?: unknown,
54
+ context?: ExecutionContext,
55
+ ): Promise<void>;
56
+ executeTool?<T>(
57
+ toolName: string,
58
+ args?: unknown,
59
+ context?: ExecutionContext,
60
+ ): Promise<T>;
61
+ listTools?(context?: ExecutionContext): Promise<ToolInfo[]>;
62
+ }
63
+ ```
64
+
65
+ ### **Enterprise Features**
66
+
67
+ - **🔄 Automatic Backup/Restore** - Timestamped backups with hash verification
68
+ - **✅ Config Validation** - Comprehensive validation with suggestions
69
+ - **🏗️ Factory-First MCP** - Lighthouse-compatible architecture (99% compatible)
70
+ - **🔧 Type Safety** - Industry-standard TypeScript interfaces
71
+ - **⚡ Performance** - Tool execution <1ms, pipeline execution ~22ms
72
+ - **🛡️ Error Recovery** - Graceful failures with auto-restore
13
73
 
14
74
  ## 🚀 Quick Start
15
75
 
@@ -22,6 +82,12 @@ export GOOGLE_AI_API_KEY="AIza-your-google-ai-api-key"
22
82
  # CLI - No installation required
23
83
  npx @juspay/neurolink generate "Hello, AI"
24
84
  npx @juspay/neurolink gen "Hello, AI" # Shortest form
85
+
86
+ # 🆕 NEW: AI Enhancement Features
87
+ npx @juspay/neurolink generate "Explain AI" --enable-analytics --debug
88
+ npx @juspay/neurolink generate "Write code" --enable-evaluation --debug
89
+ npx @juspay/neurolink generate "Help me" --context '{"userId":"123"}' --debug
90
+
25
91
  npx @juspay/neurolink status
26
92
  ```
27
93
 
@@ -46,6 +112,173 @@ console.log(result.text);
46
112
  console.log(`Used: ${result.provider}`);
47
113
  ```
48
114
 
115
+ #### 🔗 CLI-SDK Consistency (NEW! ✨)
116
+
117
+ Method aliases that match CLI command names:
118
+
119
+ ```typescript
120
+ // All three methods are equivalent:
121
+ const result1 = await provider.generateText({ prompt: "Hello" }); // Original
122
+ const result2 = await provider.generate({ prompt: "Hello" }); // Matches CLI 'generate'
123
+ const result3 = await provider.gen({ prompt: "Hello" }); // Matches CLI 'gen'
124
+
125
+ // Use whichever style you prefer:
126
+ const provider = createBestAIProvider();
127
+
128
+ // Detailed method name
129
+ const story = await provider.generateText({
130
+ prompt: "Write a short story about AI",
131
+ maxTokens: 200,
132
+ });
133
+
134
+ // CLI-style method names
135
+ const poem = await provider.generate({ prompt: "Write a poem" });
136
+ const joke = await provider.gen({ prompt: "Tell me a joke" });
137
+ ```
138
+
139
+ ### 🆕 Enhanced Usage (NEW! ✨)
140
+
141
+ #### Enhanced CLI with Analytics & Evaluation
142
+
143
+ ```bash
144
+ # Basic AI generation
145
+ npx @juspay/neurolink generate "Write a business email"
146
+
147
+ # With analytics and evaluation (NEW!)
148
+ npx @juspay/neurolink generate "Write a business email" --enable-analytics --enable-evaluation --debug
149
+
150
+ # See detailed usage data:
151
+ # 📊 Analytics: Provider usage, token costs, response times
152
+ # ⭐ Response Evaluation: AI-powered quality scores
153
+
154
+ # With custom context
155
+ npx @juspay/neurolink generate "Create a proposal" --context '{"company":"TechCorp"}' --debug
156
+ ```
157
+
158
+ #### Enhanced SDK with Analytics & Evaluation
159
+
160
+ ```typescript
161
+ import { NeuroLink } from "@juspay/neurolink";
162
+ const neurolink = new NeuroLink();
163
+
164
+ // Basic usage
165
+ const result = await neurolink.generateText("Write a story");
166
+
167
+ // With enhancements (NEW!)
168
+ const enhancedResult = await neurolink.generateText({
169
+ prompt: "Write a business proposal",
170
+ enableAnalytics: true, // Get usage & cost data
171
+ enableEvaluation: true, // Get AI quality scores
172
+ context: { project: "Q1-sales" }, // Custom context
173
+ });
174
+
175
+ // Access enhancement data
176
+ console.log("📊 Usage:", enhancedResult.analytics);
177
+ console.log("⭐ Quality:", enhancedResult.evaluation);
178
+ console.log("Response:", enhancedResult.content);
179
+
180
+ // 🆕 NEW: Enhanced Evaluation with Domain Awareness
181
+ import {
182
+ performEnhancedEvaluation,
183
+ createEnhancedContext,
184
+ } from "@juspay/neurolink";
185
+
186
+ const enhancedContext = createEnhancedContext(
187
+ "Write a business proposal for Q1 expansion",
188
+ enhancedResult.text,
189
+ {
190
+ domain: "Business development",
191
+ role: "Business proposal assistant",
192
+ toolsUsed: ["generate-text", "analytics-helper"],
193
+ conversationHistory: [
194
+ { role: "user", content: "I need help with our Q1 business plan" },
195
+ {
196
+ role: "assistant",
197
+ content: "I can help you create a comprehensive plan",
198
+ },
199
+ ],
200
+ },
201
+ );
202
+
203
+ const domainEvaluation = await performEnhancedEvaluation(enhancedContext);
204
+ console.log("🎯 Enhanced Evaluation:", domainEvaluation);
205
+ // {
206
+ // relevanceScore: 9, accuracyScore: 8, completenessScore: 9,
207
+ // domainAlignment: 9, terminologyAccuracy: 8, toolEffectiveness: 9,
208
+ // overall: 8.7, alertSeverity: 'none'
209
+ // }
210
+ ```
211
+
212
+ ### 🌐 Enterprise Real-time Features (NEW! 🚀)
213
+
214
+ #### Real-time WebSocket Chat
215
+
216
+ ```typescript
217
+ import {
218
+ createEnhancedChatService,
219
+ NeuroLinkWebSocketServer,
220
+ } from "@juspay/neurolink";
221
+
222
+ // Enhanced chat with WebSocket support
223
+ const chatService = createEnhancedChatService({
224
+ provider: await createBestAIProvider(),
225
+ enableWebSocket: true,
226
+ enableSSE: true,
227
+ streamingConfig: {
228
+ bufferSize: 8192,
229
+ compressionEnabled: true,
230
+ },
231
+ });
232
+
233
+ // WebSocket server for real-time applications
234
+ const wsServer = new NeuroLinkWebSocketServer({
235
+ port: 8080,
236
+ maxConnections: 1000,
237
+ enableCompression: true,
238
+ });
239
+
240
+ // Handle real-time chat
241
+ wsServer.on("chat-message", async ({ connectionId, message }) => {
242
+ await chatService.streamChat({
243
+ prompt: message.data.prompt,
244
+ onChunk: (chunk) => {
245
+ wsServer.sendMessage(connectionId, {
246
+ type: "ai-chunk",
247
+ data: { chunk },
248
+ });
249
+ },
250
+ });
251
+ });
252
+ ```
253
+
254
+ #### Enterprise Telemetry Integration
255
+
256
+ ```typescript
257
+ import { initializeTelemetry, getTelemetryStatus } from "@juspay/neurolink";
258
+
259
+ // Optional enterprise monitoring (zero overhead when disabled)
260
+ const telemetry = initializeTelemetry({
261
+ serviceName: "my-ai-app",
262
+ endpoint: "http://localhost:4318",
263
+ enableTracing: true,
264
+ enableMetrics: true,
265
+ enableLogs: true,
266
+ });
267
+
268
+ // Check telemetry status
269
+ const status = await getTelemetryStatus();
270
+ console.log("Telemetry enabled:", status.enabled);
271
+ console.log("Service:", status.service);
272
+ console.log("Version:", status.version);
273
+
274
+ // All AI operations are now automatically monitored
275
+ const provider = await createBestAIProvider();
276
+ const result = await provider.generateText({
277
+ prompt: "Generate business report",
278
+ });
279
+ // Telemetry automatically tracks: response time, token usage, cost, errors
280
+ ```
281
+
49
282
  ### Environment Setup
50
283
 
51
284
  ```bash
@@ -220,8 +220,8 @@ export declare const directAgentTools: {
220
220
  mode: z.ZodDefault<z.ZodEnum<["create", "overwrite", "append"]>>;
221
221
  }, "strip", z.ZodTypeAny, {
222
222
  path: string;
223
- content: string;
224
223
  mode: "create" | "overwrite" | "append";
224
+ content: string;
225
225
  }, {
226
226
  path: string;
227
227
  content: string;
@@ -250,8 +250,8 @@ export declare const directAgentTools: {
250
250
  }> & {
251
251
  execute: (args: {
252
252
  path: string;
253
- content: string;
254
253
  mode: "create" | "overwrite" | "append";
254
+ content: string;
255
255
  }, options: import("ai").ToolExecutionOptions) => PromiseLike<{
256
256
  success: boolean;
257
257
  error: string;
@@ -563,8 +563,8 @@ export declare function getToolsForCategory(category?: "basic" | "filesystem" |
563
563
  mode: z.ZodDefault<z.ZodEnum<["create", "overwrite", "append"]>>;
564
564
  }, "strip", z.ZodTypeAny, {
565
565
  path: string;
566
- content: string;
567
566
  mode: "create" | "overwrite" | "append";
567
+ content: string;
568
568
  }, {
569
569
  path: string;
570
570
  content: string;
@@ -593,8 +593,8 @@ export declare function getToolsForCategory(category?: "basic" | "filesystem" |
593
593
  }> & {
594
594
  execute: (args: {
595
595
  path: string;
596
- content: string;
597
596
  mode: "create" | "overwrite" | "append";
597
+ content: string;
598
598
  }, options: import("ai").ToolExecutionOptions) => PromiseLike<{
599
599
  success: boolean;
600
600
  error: string;
@@ -907,8 +907,8 @@ export declare function getToolsForCategory(category?: "basic" | "filesystem" |
907
907
  mode: z.ZodDefault<z.ZodEnum<["create", "overwrite", "append"]>>;
908
908
  }, "strip", z.ZodTypeAny, {
909
909
  path: string;
910
- content: string;
911
910
  mode: "create" | "overwrite" | "append";
911
+ content: string;
912
912
  }, {
913
913
  path: string;
914
914
  content: string;
@@ -937,8 +937,8 @@ export declare function getToolsForCategory(category?: "basic" | "filesystem" |
937
937
  }> & {
938
938
  execute: (args: {
939
939
  path: string;
940
- content: string;
941
940
  mode: "create" | "overwrite" | "append";
941
+ content: string;
942
942
  }, options: import("ai").ToolExecutionOptions) => PromiseLike<{
943
943
  success: boolean;
944
944
  error: string;
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Phase 3: SSE Chat Utilities
3
+ * Client-side utilities for SSE chat integration
4
+ */
5
+ import type { ChatMessage } from "./types.js";
6
+ export interface ChatClientOptions {
7
+ endpoint: string;
8
+ sessionId: string;
9
+ onMessage?: (message: ChatMessage) => void;
10
+ onError?: (error: Error) => void;
11
+ onConnect?: () => void;
12
+ onDisconnect?: () => void;
13
+ reconnectAttempts?: number;
14
+ reconnectDelay?: number;
15
+ }
16
+ export interface ChatStreamHook {
17
+ messages: ChatMessage[];
18
+ isConnected: boolean;
19
+ isReconnecting: boolean;
20
+ sendMessage: (content: string) => Promise<void>;
21
+ disconnect: () => void;
22
+ reconnect: () => void;
23
+ clearHistory: () => void;
24
+ }
25
+ /**
26
+ * Client for SSE chat communication
27
+ */
28
+ export declare class ChatClient {
29
+ private eventSource?;
30
+ private options;
31
+ private messages;
32
+ private reconnectCount;
33
+ private isConnected;
34
+ private isReconnecting;
35
+ private reconnectTimeout?;
36
+ constructor(options: ChatClientOptions);
37
+ /**
38
+ * Connect to SSE endpoint
39
+ */
40
+ connect(): void;
41
+ /**
42
+ * Send message to chat
43
+ */
44
+ sendMessage(content: string): Promise<void>;
45
+ /**
46
+ * Disconnect from SSE endpoint
47
+ */
48
+ disconnect(): void;
49
+ /**
50
+ * Get message history
51
+ */
52
+ getMessages(): ChatMessage[];
53
+ /**
54
+ * Clear message history
55
+ */
56
+ clearMessages(): void;
57
+ /**
58
+ * Check connection status
59
+ */
60
+ getConnectionStatus(): {
61
+ connected: boolean;
62
+ reconnecting: boolean;
63
+ reconnectCount: number;
64
+ };
65
+ private handleSSEEvent;
66
+ private handleDataEvent;
67
+ private handleErrorEvent;
68
+ private handleCompleteEvent;
69
+ private scheduleReconnect;
70
+ }
71
+ /**
72
+ * Create chat client instance
73
+ */
74
+ export declare function createChatClient(options: ChatClientOptions): ChatClient;
75
+ /**
76
+ * React-style hook for chat streaming (can be adapted for other frameworks)
77
+ */
78
+ export declare function useChatStream(options: ChatClientOptions): ChatStreamHook;
79
+ /**
80
+ * Utility for creating SSE EventSource with automatic reconnection
81
+ */
82
+ export declare function createSSEConnection(url: string, options?: {
83
+ onMessage?: (event: MessageEvent) => void;
84
+ onError?: (error: Error) => void;
85
+ onOpen?: () => void;
86
+ reconnect?: boolean;
87
+ maxReconnectAttempts?: number;
88
+ }): {
89
+ connect: () => void;
90
+ disconnect: () => void;
91
+ isConnected: () => boolean;
92
+ };