@juspay/neurolink 11.2.3 → 11.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/browser/neurolink.min.js +396 -396
  3. package/dist/core/handlerRegistry.d.ts +29 -0
  4. package/dist/core/handlerRegistry.js +61 -0
  5. package/dist/core/loopEngine.d.ts +23 -0
  6. package/dist/core/loopEngine.js +245 -0
  7. package/dist/core/nativeToolFormat.d.ts +33 -0
  8. package/dist/core/nativeToolFormat.js +30 -0
  9. package/dist/core/streamChannel.d.ts +10 -0
  10. package/dist/core/streamChannel.js +76 -0
  11. package/dist/factories/providerRegistry.d.ts +4 -16
  12. package/dist/factories/providerRegistry.js +4 -56
  13. package/dist/lib/core/handlerRegistry.d.ts +29 -0
  14. package/dist/lib/core/handlerRegistry.js +62 -0
  15. package/dist/lib/core/loopEngine.d.ts +23 -0
  16. package/dist/lib/core/loopEngine.js +246 -0
  17. package/dist/lib/core/nativeToolFormat.d.ts +33 -0
  18. package/dist/lib/core/nativeToolFormat.js +31 -0
  19. package/dist/lib/core/streamChannel.d.ts +10 -0
  20. package/dist/lib/core/streamChannel.js +77 -0
  21. package/dist/lib/factories/providerRegistry.d.ts +4 -16
  22. package/dist/lib/factories/providerRegistry.js +4 -56
  23. package/dist/lib/providers/anthropic/cacheControl.d.ts +12 -0
  24. package/dist/lib/providers/anthropic/cacheControl.js +15 -0
  25. package/dist/lib/providers/anthropic/client.js +12 -45
  26. package/dist/lib/providers/googleAiStudio/client.js +7 -5
  27. package/dist/lib/providers/googleNativeGemini3/utils.d.ts +4 -11
  28. package/dist/lib/providers/googleNativeGemini3/utils.js +1 -75
  29. package/dist/lib/providers/googleVertex/client.js +28 -30
  30. package/dist/lib/providers/openaiChatCompletionsBase.js +10 -12
  31. package/dist/lib/providers/openaiChatCompletionsClient.d.ts +1 -5
  32. package/dist/lib/providers/openaiChatCompletionsClient.js +0 -26
  33. package/dist/lib/types/index.d.ts +3 -0
  34. package/dist/lib/types/index.js +3 -0
  35. package/dist/lib/types/loopEngine.d.ts +78 -0
  36. package/dist/lib/types/loopEngine.js +2 -0
  37. package/dist/lib/types/nativeTools.d.ts +16 -0
  38. package/dist/lib/types/nativeTools.js +2 -0
  39. package/dist/lib/types/openaiCompatible.d.ts +2 -2
  40. package/dist/lib/types/providers.d.ts +0 -13
  41. package/dist/lib/types/streaming.d.ts +15 -0
  42. package/dist/lib/types/streaming.js +2 -0
  43. package/dist/lib/utils/avatarProcessor.d.ts +5 -1
  44. package/dist/lib/utils/avatarProcessor.js +13 -18
  45. package/dist/lib/utils/musicProcessor.d.ts +5 -1
  46. package/dist/lib/utils/musicProcessor.js +13 -18
  47. package/dist/lib/utils/sttProcessor.d.ts +10 -2
  48. package/dist/lib/utils/sttProcessor.js +22 -18
  49. package/dist/lib/utils/ttsProcessor.d.ts +10 -2
  50. package/dist/lib/utils/ttsProcessor.js +22 -18
  51. package/dist/lib/utils/videoProcessor.d.ts +5 -1
  52. package/dist/lib/utils/videoProcessor.js +13 -18
  53. package/dist/lib/voice/RealtimeVoiceAPI.d.ts +1 -1
  54. package/dist/lib/voice/RealtimeVoiceAPI.js +17 -28
  55. package/dist/providers/anthropic/cacheControl.d.ts +12 -0
  56. package/dist/providers/anthropic/cacheControl.js +14 -0
  57. package/dist/providers/anthropic/client.js +12 -45
  58. package/dist/providers/googleAiStudio/client.js +7 -5
  59. package/dist/providers/googleNativeGemini3/utils.d.ts +4 -11
  60. package/dist/providers/googleNativeGemini3/utils.js +1 -75
  61. package/dist/providers/googleVertex/client.js +28 -30
  62. package/dist/providers/openaiChatCompletionsBase.js +10 -12
  63. package/dist/providers/openaiChatCompletionsClient.d.ts +1 -5
  64. package/dist/providers/openaiChatCompletionsClient.js +0 -26
  65. package/dist/types/index.d.ts +3 -0
  66. package/dist/types/index.js +3 -0
  67. package/dist/types/loopEngine.d.ts +78 -0
  68. package/dist/types/loopEngine.js +1 -0
  69. package/dist/types/nativeTools.d.ts +16 -0
  70. package/dist/types/nativeTools.js +1 -0
  71. package/dist/types/openaiCompatible.d.ts +2 -2
  72. package/dist/types/providers.d.ts +0 -13
  73. package/dist/types/streaming.d.ts +15 -0
  74. package/dist/types/streaming.js +1 -0
  75. package/dist/utils/avatarProcessor.d.ts +5 -1
  76. package/dist/utils/avatarProcessor.js +13 -18
  77. package/dist/utils/musicProcessor.d.ts +5 -1
  78. package/dist/utils/musicProcessor.js +13 -18
  79. package/dist/utils/sttProcessor.d.ts +10 -2
  80. package/dist/utils/sttProcessor.js +22 -18
  81. package/dist/utils/ttsProcessor.d.ts +10 -2
  82. package/dist/utils/ttsProcessor.js +22 -18
  83. package/dist/utils/videoProcessor.d.ts +5 -1
  84. package/dist/utils/videoProcessor.js +13 -18
  85. package/dist/voice/RealtimeVoiceAPI.d.ts +1 -1
  86. package/dist/voice/RealtimeVoiceAPI.js +17 -28
  87. package/package.json +9 -1
@@ -9,6 +9,7 @@
9
9
  import { logger } from "./logger.js";
10
10
  import { ErrorCategory, ErrorSeverity } from "../constants/enums.js";
11
11
  import { NeuroLinkError } from "./errorHandling.js";
12
+ import { HandlerRegistry } from "../core/handlerRegistry.js";
12
13
  import { SpanSerializer, SpanType, SpanStatus, getMetricsAggregator, } from "../observability/index.js";
13
14
  /**
14
15
  * TTS-specific error codes
@@ -58,11 +59,10 @@ export class TTSError extends NeuroLinkError {
58
59
  export class TTSProcessor {
59
60
  /**
60
61
  * Handler registry mapping provider names to TTS handlers
61
- * Uses Map for O(1) lookups and better type safety
62
62
  *
63
63
  * @private
64
64
  */
65
- static handlers = new Map();
65
+ static registry = new HandlerRegistry("TTSProcessor");
66
66
  /**
67
67
  * Default maximum text length for TTS synthesis (in bytes)
68
68
  *
@@ -93,17 +93,10 @@ export class TTSProcessor {
93
93
  * ```
94
94
  */
95
95
  static registerHandler(providerName, handler) {
96
- if (!providerName) {
97
- throw new Error("Provider name is required");
98
- }
99
- if (!handler) {
100
- throw new Error("Handler is required");
101
- }
102
- const normalizedName = providerName.toLowerCase();
103
- if (this.handlers.has(normalizedName)) {
104
- logger.warn(`[TTSProcessor] Overwriting existing handler for provider: ${normalizedName}`);
105
- }
106
- this.handlers.set(normalizedName, handler);
96
+ const normalizedName = providerName
97
+ ? providerName.toLowerCase()
98
+ : providerName;
99
+ this.registry.register(providerName, handler);
107
100
  logger.debug(`[TTSProcessor] Registered TTS handler for provider: ${normalizedName}`);
108
101
  }
109
102
  /**
@@ -117,8 +110,20 @@ export class TTSProcessor {
117
110
  * @returns Handler instance or undefined if not registered
118
111
  */
119
112
  static getHandler(providerName) {
120
- const normalizedName = providerName.toLowerCase();
121
- return this.handlers.get(normalizedName);
113
+ return this.registry.get(providerName);
114
+ }
115
+ /**
116
+ * List the names of all registered providers.
117
+ */
118
+ static listProviders() {
119
+ return this.registry.list();
120
+ }
121
+ /**
122
+ * Removes every registered TTS handler. Primarily for test isolation —
123
+ * production code should not need to call this.
124
+ */
125
+ static clearHandlers() {
126
+ this.registry.clear();
122
127
  }
123
128
  /**
124
129
  * Check if a provider is supported (has a registered TTS handler)
@@ -138,8 +143,7 @@ export class TTSProcessor {
138
143
  logger.error("[TTSProcessor] Provider name is required for supports check");
139
144
  return false;
140
145
  }
141
- const normalizedName = providerName.toLowerCase();
142
- const isSupported = this.handlers.has(normalizedName);
146
+ const isSupported = this.registry.supports(providerName);
143
147
  if (!isSupported) {
144
148
  logger.debug(`[TTSProcessor] Provider ${providerName} is not supported`);
145
149
  }
@@ -211,7 +215,7 @@ export class TTSProcessor {
211
215
  retriable: false,
212
216
  context: {
213
217
  provider,
214
- availableProviders: Array.from(this.handlers.keys()),
218
+ availableProviders: this.registry.list(),
215
219
  },
216
220
  });
217
221
  }
@@ -22,7 +22,7 @@ export { VideoError, VIDEO_ERROR_CODES };
22
22
  * O(1) on a normalised lower-case provider key.
23
23
  */
24
24
  export declare class VideoProcessor {
25
- private static readonly handlers;
25
+ private static readonly registry;
26
26
  /**
27
27
  * Register a video handler for a specific provider.
28
28
  */
@@ -36,6 +36,10 @@ export declare class VideoProcessor {
36
36
  */
37
37
  static listProviders(): string[];
38
38
  private static getHandler;
39
+ /**
40
+ * Clear all registered handlers (for testing).
41
+ */
42
+ static clearHandlers(): void;
39
43
  private static buildSpanAttributes;
40
44
  /**
41
45
  * Generate a single video clip via the registered handler.
@@ -19,6 +19,7 @@ import { logger } from "./logger.js";
19
19
  // the same module. Both throws and instanceof checks resolve to the same
20
20
  // class.
21
21
  import { VideoError } from "../adapters/video/vertexVideoHandler.js";
22
+ import { HandlerRegistry } from "../core/handlerRegistry.js";
22
23
  export { VideoError, VIDEO_ERROR_CODES };
23
24
  /**
24
25
  * Static processor managing the video handler registry.
@@ -28,41 +29,35 @@ export { VideoError, VIDEO_ERROR_CODES };
28
29
  * O(1) on a normalised lower-case provider key.
29
30
  */
30
31
  export class VideoProcessor {
31
- static handlers = new Map();
32
+ static registry = new HandlerRegistry("VideoProcessor");
32
33
  /**
33
34
  * Register a video handler for a specific provider.
34
35
  */
35
36
  static registerHandler(providerName, handler) {
36
- if (!providerName) {
37
- throw new Error("Provider name is required");
38
- }
39
- if (!handler) {
40
- throw new Error("Handler is required");
41
- }
42
- const key = providerName.toLowerCase();
43
- if (this.handlers.has(key)) {
44
- logger.warn(`[VideoProcessor] Overwriting existing handler for provider: ${key}`);
45
- }
46
- this.handlers.set(key, handler);
37
+ const key = providerName ? providerName.toLowerCase() : providerName;
38
+ this.registry.register(providerName, handler);
47
39
  logger.debug(`[VideoProcessor] Registered video handler: ${key}`);
48
40
  }
49
41
  /**
50
42
  * Check if a provider has a registered video handler.
51
43
  */
52
44
  static supports(providerName) {
53
- if (!providerName) {
54
- return false;
55
- }
56
- return this.handlers.has(providerName.toLowerCase());
45
+ return this.registry.supports(providerName);
57
46
  }
58
47
  /**
59
48
  * List the names of all registered providers.
60
49
  */
61
50
  static listProviders() {
62
- return Array.from(this.handlers.keys());
51
+ return this.registry.list();
63
52
  }
64
53
  static getHandler(providerName) {
65
- return this.handlers.get(providerName.toLowerCase());
54
+ return this.registry.get(providerName);
55
+ }
56
+ /**
57
+ * Clear all registered handlers (for testing).
58
+ */
59
+ static clearHandlers() {
60
+ this.registry.clear();
66
61
  }
67
62
  static buildSpanAttributes(provider, options) {
68
63
  return {
@@ -36,7 +36,7 @@ export declare class RealtimeProcessor {
36
36
  /**
37
37
  * Handler registry mapping provider names to Realtime handlers
38
38
  */
39
- private static readonly handlers;
39
+ private static readonly registry;
40
40
  /**
41
41
  * Active sessions by provider
42
42
  */
@@ -10,6 +10,7 @@ import { logger } from "../utils/logger.js";
10
10
  import { RealtimeError } from "./errors.js";
11
11
  import { DEFAULT_REALTIME_CONFIG, REALTIME_ERROR_CODES, } from "../types/index.js";
12
12
  import { ErrorCategory, ErrorSeverity } from "../constants/enums.js";
13
+ import { HandlerRegistry } from "../core/handlerRegistry.js";
13
14
  /**
14
15
  * Realtime Processor class for orchestrating realtime voice operations
15
16
  *
@@ -39,7 +40,7 @@ export class RealtimeProcessor {
39
40
  /**
40
41
  * Handler registry mapping provider names to Realtime handlers
41
42
  */
42
- static handlers = new Map();
43
+ static registry = new HandlerRegistry("RealtimeProcessor");
43
44
  /**
44
45
  * Active sessions by provider
45
46
  */
@@ -51,17 +52,10 @@ export class RealtimeProcessor {
51
52
  * @param handler - Realtime handler implementation
52
53
  */
53
54
  static registerHandler(providerName, handler) {
54
- if (!providerName) {
55
- throw new Error("Provider name is required");
56
- }
57
- if (!handler) {
58
- throw new Error("Handler is required");
59
- }
60
- const normalizedName = providerName.toLowerCase();
61
- if (this.handlers.has(normalizedName)) {
62
- logger.warn(`[RealtimeProcessor] Overwriting existing handler for provider: ${normalizedName}`);
63
- }
64
- this.handlers.set(normalizedName, handler);
55
+ const normalizedName = providerName
56
+ ? providerName.toLowerCase()
57
+ : providerName;
58
+ this.registry.register(providerName, handler);
65
59
  logger.debug(`[RealtimeProcessor] Registered Realtime handler for provider: ${normalizedName}`);
66
60
  }
67
61
  /**
@@ -71,24 +65,19 @@ export class RealtimeProcessor {
71
65
  * already-registered primary handler when backfilling its aliases.
72
66
  */
73
67
  static getHandler(providerName) {
74
- const normalizedName = providerName.toLowerCase();
75
- return this.handlers.get(normalizedName);
68
+ return this.registry.get(providerName);
76
69
  }
77
70
  /**
78
71
  * Check if a provider is supported
79
72
  */
80
73
  static supports(providerName) {
81
- if (!providerName) {
82
- return false;
83
- }
84
- const normalizedName = providerName.toLowerCase();
85
- return this.handlers.has(normalizedName);
74
+ return this.registry.supports(providerName);
86
75
  }
87
76
  /**
88
77
  * Get list of all registered providers
89
78
  */
90
79
  static getProviders() {
91
- return Array.from(this.handlers.keys());
80
+ return this.registry.list();
92
81
  }
93
82
  /**
94
83
  * Connect to a realtime session
@@ -101,7 +90,7 @@ export class RealtimeProcessor {
101
90
  static async connect(provider, config, handlers) {
102
91
  const handler = this.getHandler(provider);
103
92
  if (!handler) {
104
- throw RealtimeError.providerNotSupported(provider, Array.from(this.handlers.keys()));
93
+ throw RealtimeError.providerNotSupported(provider, this.registry.list());
105
94
  }
106
95
  if (!handler.isConfigured()) {
107
96
  throw RealtimeError.providerNotConfigured(provider);
@@ -145,7 +134,7 @@ export class RealtimeProcessor {
145
134
  static async disconnect(provider) {
146
135
  const handler = this.getHandler(provider);
147
136
  if (!handler) {
148
- throw RealtimeError.providerNotSupported(provider, Array.from(this.handlers.keys()));
137
+ throw RealtimeError.providerNotSupported(provider, this.registry.list());
149
138
  }
150
139
  if (!handler.isConnected()) {
151
140
  logger.warn(`[RealtimeProcessor] No active session for provider: ${provider}`);
@@ -174,7 +163,7 @@ export class RealtimeProcessor {
174
163
  static async sendAudio(provider, audio) {
175
164
  const handler = this.getHandler(provider);
176
165
  if (!handler) {
177
- throw RealtimeError.providerNotSupported(provider, Array.from(this.handlers.keys()));
166
+ throw RealtimeError.providerNotSupported(provider, this.registry.list());
178
167
  }
179
168
  if (!handler.isConnected()) {
180
169
  throw RealtimeError.sessionNotActive(provider);
@@ -199,7 +188,7 @@ export class RealtimeProcessor {
199
188
  static async sendText(provider, text) {
200
189
  const handler = this.getHandler(provider);
201
190
  if (!handler) {
202
- throw RealtimeError.providerNotSupported(provider, Array.from(this.handlers.keys()));
191
+ throw RealtimeError.providerNotSupported(provider, this.registry.list());
203
192
  }
204
193
  if (!handler.isConnected()) {
205
194
  throw RealtimeError.sessionNotActive(provider);
@@ -243,7 +232,7 @@ export class RealtimeProcessor {
243
232
  static async triggerResponse(provider) {
244
233
  const handler = this.getHandler(provider);
245
234
  if (!handler) {
246
- throw RealtimeError.providerNotSupported(provider, Array.from(this.handlers.keys()));
235
+ throw RealtimeError.providerNotSupported(provider, this.registry.list());
247
236
  }
248
237
  if (!handler.isConnected()) {
249
238
  throw RealtimeError.sessionNotActive(provider);
@@ -276,7 +265,7 @@ export class RealtimeProcessor {
276
265
  static async cancelResponse(provider) {
277
266
  const handler = this.getHandler(provider);
278
267
  if (!handler) {
279
- throw RealtimeError.providerNotSupported(provider, Array.from(this.handlers.keys()));
268
+ throw RealtimeError.providerNotSupported(provider, this.registry.list());
280
269
  }
281
270
  if (!handler.isConnected()) {
282
271
  return; // Nothing to cancel
@@ -335,15 +324,15 @@ export class RealtimeProcessor {
335
324
  static clearHandlers() {
336
325
  // Disconnect all active sessions
337
326
  for (const [provider] of this.sessions) {
338
- const handler = this.handlers.get(provider);
327
+ const handler = this.registry.get(provider);
339
328
  if (handler?.isConnected()) {
340
329
  handler.disconnect().catch(() => {
341
330
  // Ignore errors during cleanup
342
331
  });
343
332
  }
344
333
  }
345
- this.handlers.clear();
346
334
  this.sessions.clear();
335
+ this.registry.clear();
347
336
  logger.debug("[RealtimeProcessor] Cleared all handlers and sessions");
348
337
  }
349
338
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juspay/neurolink",
3
- "version": "11.2.3",
3
+ "version": "11.3.0",
4
4
  "packageManager": "pnpm@10.15.1",
5
5
  "description": "TypeScript AI SDK with 24+ LLM providers behind one consistent API. MCP-native (connect any MCP server), voice TTS/STT/realtime, RAG, agents, memory, context compaction. OpenAI · Anthropic · Gemini · Bedrock · Azure · Ollama · DeepSeek · NVIDIA NIM and more.",
6
6
  "author": {
@@ -72,6 +72,7 @@
72
72
  "test:client": "npx tsx test/continuous-test-suite-client.ts",
73
73
  "test:context": "npx tsx test/continuous-test-suite-context.ts",
74
74
  "test:evaluation": "npx tsx test/continuous-test-suite-evaluation.ts",
75
+ "test:handler-registry": "npx tsx test/continuous-test-suite-handler-registry.ts",
75
76
  "test:mcp": "npx tsx test/continuous-test-suite-mcp-infra.ts",
76
77
  "test:tool-resolution": "npx tsx test/continuous-test-suite-tool-resolution.ts",
77
78
  "test:mcp:http": "npx tsx test/continuous-test-suite-mcp-http.ts",
@@ -85,6 +86,7 @@
85
86
  "test:adjust-body-after-400": "npx tsx test/continuous-test-suite-adjust-body-after-400.ts",
86
87
  "test:error-classification-e2e": "npx tsx test/continuous-test-suite-error-classification-e2e.ts",
87
88
  "test:error-classifier-contract": "npx tsx test/continuous-test-suite-error-classifier-contract.ts",
89
+ "test:loop-engine": "npx tsx test/continuous-test-suite-loop-engine.ts",
88
90
  "test:middleware": "npx tsx test/continuous-test-suite-middleware.ts",
89
91
  "test:observability": "npx tsx test/continuous-test-suite-observability.ts",
90
92
  "test:ppt": "npx tsx test/continuous-test-suite-ppt.ts",
@@ -106,9 +108,15 @@
106
108
  "test:servers": "npx tsx test/continuous-test-suite-servers.ts",
107
109
  "test:tool-reliability": "npx tsx test/continuous-test-suite-tool-reliability.ts",
108
110
  "test:tts": "npx tsx test/continuous-test-suite-tts.ts",
111
+ "test:tts:unit": "npx tsx test/continuous-test-suite-tts-unit.ts",
112
+ "test:stt:unit": "npx tsx test/continuous-test-suite-stt-unit.ts",
113
+ "test:realtime:unit": "npx tsx test/continuous-test-suite-realtime-unit.ts",
114
+ "test:video:unit": "npx tsx test/continuous-test-suite-video-generation-unit.ts",
109
115
  "test:voice": "npx tsx test/continuous-test-suite-voice.ts",
110
116
  "test:avatar": "npx tsx test/continuous-test-suite-avatar.ts",
117
+ "test:avatar:unit": "npx tsx test/continuous-test-suite-avatar-unit.ts",
111
118
  "test:music": "npx tsx test/continuous-test-suite-music.ts",
119
+ "test:music:unit": "npx tsx test/continuous-test-suite-music-unit.ts",
112
120
  "test:image-gen": "npx tsx test/continuous-test-suite-image-gen-extras.ts",
113
121
  "test:credentials": "npx tsx test/continuous-test-suite-credentials.ts",
114
122
  "test:dynamic": "npx tsx test/continuous-test-suite-dynamic.ts",