@juspay/neurolink 9.10.0 → 9.11.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 (174) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/adapters/video/videoAnalyzer.d.ts +3 -3
  3. package/dist/adapters/video/videoAnalyzer.js +39 -25
  4. package/dist/agent/directTools.d.ts +3 -3
  5. package/dist/cli/commands/config.d.ts +9 -9
  6. package/dist/cli/loop/optionsSchema.d.ts +1 -1
  7. package/dist/constants/contextWindows.d.ts +6 -3
  8. package/dist/constants/contextWindows.js +30 -3
  9. package/dist/constants/index.d.ts +3 -3
  10. package/dist/constants/retry.d.ts +4 -4
  11. package/dist/constants/retry.js +1 -1
  12. package/dist/context/contextCompactor.d.ts +1 -1
  13. package/dist/context/contextCompactor.js +59 -1
  14. package/dist/context/summarizationEngine.d.ts +2 -2
  15. package/dist/context/summarizationEngine.js +44 -18
  16. package/dist/context/toolOutputLimits.d.ts +22 -13
  17. package/dist/context/toolOutputLimits.js +58 -64
  18. package/dist/core/baseProvider.d.ts +11 -2
  19. package/dist/core/baseProvider.js +30 -1
  20. package/dist/core/conversationMemoryManager.d.ts +13 -1
  21. package/dist/core/conversationMemoryManager.js +36 -5
  22. package/dist/core/modules/GenerationHandler.d.ts +6 -0
  23. package/dist/core/modules/GenerationHandler.js +192 -7
  24. package/dist/core/modules/MessageBuilder.js +42 -4
  25. package/dist/core/modules/TelemetryHandler.js +4 -1
  26. package/dist/core/redisConversationMemoryManager.d.ts +19 -3
  27. package/dist/core/redisConversationMemoryManager.js +253 -58
  28. package/dist/index.d.ts +2 -0
  29. package/dist/index.js +3 -0
  30. package/dist/lib/adapters/video/videoAnalyzer.d.ts +3 -3
  31. package/dist/lib/adapters/video/videoAnalyzer.js +39 -25
  32. package/dist/lib/agent/directTools.d.ts +7 -7
  33. package/dist/lib/constants/contextWindows.d.ts +6 -3
  34. package/dist/lib/constants/contextWindows.js +30 -3
  35. package/dist/lib/constants/index.d.ts +3 -3
  36. package/dist/lib/constants/retry.d.ts +4 -4
  37. package/dist/lib/constants/retry.js +1 -1
  38. package/dist/lib/context/contextCompactor.d.ts +1 -1
  39. package/dist/lib/context/contextCompactor.js +59 -1
  40. package/dist/lib/context/summarizationEngine.d.ts +2 -2
  41. package/dist/lib/context/summarizationEngine.js +44 -18
  42. package/dist/lib/context/toolOutputLimits.d.ts +22 -13
  43. package/dist/lib/context/toolOutputLimits.js +58 -64
  44. package/dist/lib/core/baseProvider.d.ts +11 -2
  45. package/dist/lib/core/baseProvider.js +30 -1
  46. package/dist/lib/core/conversationMemoryManager.d.ts +13 -1
  47. package/dist/lib/core/conversationMemoryManager.js +36 -5
  48. package/dist/lib/core/modules/GenerationHandler.d.ts +6 -0
  49. package/dist/lib/core/modules/GenerationHandler.js +192 -7
  50. package/dist/lib/core/modules/MessageBuilder.js +42 -4
  51. package/dist/lib/core/modules/TelemetryHandler.js +4 -1
  52. package/dist/lib/core/redisConversationMemoryManager.d.ts +19 -3
  53. package/dist/lib/core/redisConversationMemoryManager.js +253 -58
  54. package/dist/lib/files/fileTools.d.ts +3 -3
  55. package/dist/lib/index.d.ts +2 -0
  56. package/dist/lib/index.js +3 -0
  57. package/dist/lib/mcp/externalServerManager.js +36 -1
  58. package/dist/lib/memory/memoryRetrievalTools.d.ts +166 -0
  59. package/dist/lib/memory/memoryRetrievalTools.js +145 -0
  60. package/dist/lib/neurolink.d.ts +35 -1
  61. package/dist/lib/neurolink.js +471 -16
  62. package/dist/lib/providers/amazonBedrock.d.ts +1 -1
  63. package/dist/lib/providers/amazonBedrock.js +78 -45
  64. package/dist/lib/providers/amazonSagemaker.d.ts +1 -1
  65. package/dist/lib/providers/amazonSagemaker.js +1 -1
  66. package/dist/lib/providers/anthropic.d.ts +1 -1
  67. package/dist/lib/providers/anthropic.js +7 -7
  68. package/dist/lib/providers/anthropicBaseProvider.d.ts +1 -1
  69. package/dist/lib/providers/anthropicBaseProvider.js +7 -6
  70. package/dist/lib/providers/azureOpenai.d.ts +1 -1
  71. package/dist/lib/providers/azureOpenai.js +1 -1
  72. package/dist/lib/providers/googleAiStudio.d.ts +1 -1
  73. package/dist/lib/providers/googleAiStudio.js +5 -5
  74. package/dist/lib/providers/googleVertex.d.ts +1 -1
  75. package/dist/lib/providers/googleVertex.js +74 -17
  76. package/dist/lib/providers/huggingFace.d.ts +1 -1
  77. package/dist/lib/providers/huggingFace.js +1 -1
  78. package/dist/lib/providers/litellm.d.ts +1 -1
  79. package/dist/lib/providers/litellm.js +18 -16
  80. package/dist/lib/providers/mistral.d.ts +1 -1
  81. package/dist/lib/providers/mistral.js +1 -1
  82. package/dist/lib/providers/ollama.d.ts +1 -1
  83. package/dist/lib/providers/ollama.js +8 -7
  84. package/dist/lib/providers/openAI.d.ts +1 -1
  85. package/dist/lib/providers/openAI.js +6 -6
  86. package/dist/lib/providers/openRouter.d.ts +1 -1
  87. package/dist/lib/providers/openRouter.js +6 -2
  88. package/dist/lib/providers/openaiCompatible.d.ts +1 -1
  89. package/dist/lib/providers/openaiCompatible.js +1 -1
  90. package/dist/lib/proxy/proxyFetch.js +291 -65
  91. package/dist/lib/server/utils/validation.d.ts +4 -4
  92. package/dist/lib/services/server/ai/observability/instrumentation.js +12 -3
  93. package/dist/lib/telemetry/telemetryService.d.ts +2 -1
  94. package/dist/lib/telemetry/telemetryService.js +8 -1
  95. package/dist/lib/types/contextTypes.d.ts +26 -2
  96. package/dist/lib/types/conversation.d.ts +72 -40
  97. package/dist/lib/types/conversationMemoryInterface.d.ts +5 -1
  98. package/dist/lib/types/generateTypes.d.ts +26 -0
  99. package/dist/lib/types/modelTypes.d.ts +2 -2
  100. package/dist/lib/types/multimodal.d.ts +2 -0
  101. package/dist/lib/types/observability.d.ts +10 -0
  102. package/dist/lib/types/sdkTypes.d.ts +1 -1
  103. package/dist/lib/utils/conversationMemory.d.ts +4 -3
  104. package/dist/lib/utils/conversationMemory.js +44 -6
  105. package/dist/lib/utils/errorHandling.d.ts +5 -0
  106. package/dist/lib/utils/errorHandling.js +7 -2
  107. package/dist/lib/utils/logger.d.ts +8 -0
  108. package/dist/lib/utils/logger.js +56 -1
  109. package/dist/lib/utils/messageBuilder.js +74 -4
  110. package/dist/lib/utils/redis.js +6 -1
  111. package/dist/lib/utils/tokenEstimation.d.ts +2 -2
  112. package/dist/lib/utils/tokenEstimation.js +16 -1
  113. package/dist/lib/utils/videoAnalysisProcessor.d.ts +2 -1
  114. package/dist/lib/utils/videoAnalysisProcessor.js +7 -2
  115. package/dist/lib/workflow/config.d.ts +110 -110
  116. package/dist/mcp/externalServerManager.js +36 -1
  117. package/dist/memory/memoryRetrievalTools.d.ts +166 -0
  118. package/dist/memory/memoryRetrievalTools.js +144 -0
  119. package/dist/neurolink.d.ts +35 -1
  120. package/dist/neurolink.js +471 -16
  121. package/dist/providers/amazonBedrock.d.ts +1 -1
  122. package/dist/providers/amazonBedrock.js +78 -45
  123. package/dist/providers/amazonSagemaker.d.ts +1 -1
  124. package/dist/providers/amazonSagemaker.js +1 -1
  125. package/dist/providers/anthropic.d.ts +1 -1
  126. package/dist/providers/anthropic.js +7 -7
  127. package/dist/providers/anthropicBaseProvider.d.ts +1 -1
  128. package/dist/providers/anthropicBaseProvider.js +7 -6
  129. package/dist/providers/azureOpenai.d.ts +1 -1
  130. package/dist/providers/azureOpenai.js +1 -1
  131. package/dist/providers/googleAiStudio.d.ts +1 -1
  132. package/dist/providers/googleAiStudio.js +5 -5
  133. package/dist/providers/googleVertex.d.ts +1 -1
  134. package/dist/providers/googleVertex.js +74 -17
  135. package/dist/providers/huggingFace.d.ts +1 -1
  136. package/dist/providers/huggingFace.js +1 -1
  137. package/dist/providers/litellm.d.ts +1 -1
  138. package/dist/providers/litellm.js +18 -16
  139. package/dist/providers/mistral.d.ts +1 -1
  140. package/dist/providers/mistral.js +1 -1
  141. package/dist/providers/ollama.d.ts +1 -1
  142. package/dist/providers/ollama.js +8 -7
  143. package/dist/providers/openAI.d.ts +1 -1
  144. package/dist/providers/openAI.js +6 -6
  145. package/dist/providers/openRouter.d.ts +1 -1
  146. package/dist/providers/openRouter.js +6 -2
  147. package/dist/providers/openaiCompatible.d.ts +1 -1
  148. package/dist/providers/openaiCompatible.js +1 -1
  149. package/dist/proxy/proxyFetch.js +291 -65
  150. package/dist/services/server/ai/observability/instrumentation.js +12 -3
  151. package/dist/telemetry/telemetryService.d.ts +2 -1
  152. package/dist/telemetry/telemetryService.js +8 -1
  153. package/dist/types/contextTypes.d.ts +26 -2
  154. package/dist/types/conversation.d.ts +72 -40
  155. package/dist/types/conversationMemoryInterface.d.ts +5 -1
  156. package/dist/types/generateTypes.d.ts +26 -0
  157. package/dist/types/modelTypes.d.ts +10 -10
  158. package/dist/types/multimodal.d.ts +2 -0
  159. package/dist/types/observability.d.ts +10 -0
  160. package/dist/types/sdkTypes.d.ts +1 -1
  161. package/dist/utils/conversationMemory.d.ts +4 -3
  162. package/dist/utils/conversationMemory.js +44 -6
  163. package/dist/utils/errorHandling.d.ts +5 -0
  164. package/dist/utils/errorHandling.js +7 -2
  165. package/dist/utils/logger.d.ts +8 -0
  166. package/dist/utils/logger.js +56 -1
  167. package/dist/utils/messageBuilder.js +74 -4
  168. package/dist/utils/redis.js +6 -1
  169. package/dist/utils/tokenEstimation.d.ts +2 -2
  170. package/dist/utils/tokenEstimation.js +16 -1
  171. package/dist/utils/videoAnalysisProcessor.d.ts +2 -1
  172. package/dist/utils/videoAnalysisProcessor.js +7 -2
  173. package/dist/workflow/config.d.ts +12 -12
  174. package/package.json +1 -1
@@ -434,6 +434,59 @@ function shouldUseStructuredOutput(options) {
434
434
  (options.output?.format === "json" ||
435
435
  options.output?.format === "structured"));
436
436
  }
437
+ /**
438
+ * Log structural metadata about a composed message array without logging content.
439
+ * Per-message breakdown is behind logger.debug() to avoid production spam.
440
+ */
441
+ function logMessageComposition(messages, requestId) {
442
+ // Skip entirely if neither info nor debug is enabled
443
+ if (!logger.shouldLog("info")) {
444
+ return;
445
+ }
446
+ const roles = {};
447
+ let totalChars = 0;
448
+ for (const msg of messages) {
449
+ // Avoid JSON.stringify on multimodal content for the info-level summary;
450
+ // accurate per-message breakdown (with sizes) is computed only when debug
451
+ // logging is active (see below).
452
+ const chars = typeof msg.content === "string" ? msg.content.length : 0;
453
+ roles[msg.role] = (roles[msg.role] || 0) + 1;
454
+ totalChars += chars;
455
+ }
456
+ logger.info("[MessageBuilder] Composed", {
457
+ requestId,
458
+ totalMessages: messages.length,
459
+ roles,
460
+ totalChars,
461
+ estimatedTokens: Math.ceil(totalChars / 4),
462
+ });
463
+ if (logger.shouldLog("debug")) {
464
+ const breakdown = messages.map((msg, i) => {
465
+ let chars;
466
+ if (typeof msg.content === "string") {
467
+ chars = msg.content.length;
468
+ }
469
+ else {
470
+ try {
471
+ chars = JSON.stringify(msg.content).length;
472
+ }
473
+ catch {
474
+ chars = String(msg.content).length;
475
+ }
476
+ }
477
+ return {
478
+ index: i,
479
+ role: msg.role,
480
+ chars,
481
+ estimatedTokens: Math.ceil(chars / 4),
482
+ };
483
+ });
484
+ logger.debug("[MessageBuilder] Per-message breakdown", {
485
+ requestId,
486
+ breakdown,
487
+ });
488
+ }
489
+ }
437
490
  /**
438
491
  * Build a properly formatted message array for AI providers
439
492
  * Combines system prompt, conversation history, and current user prompt
@@ -459,6 +512,9 @@ export async function buildMessagesArray(options) {
459
512
  messages.push({
460
513
  role: "system",
461
514
  content: systemPrompt.trim(),
515
+ providerOptions: {
516
+ anthropic: { cacheControl: { type: "ephemeral" } },
517
+ },
462
518
  });
463
519
  }
464
520
  // Add conversation history if available
@@ -556,6 +612,9 @@ export async function buildMessagesArray(options) {
556
612
  content: currentPrompt.trim(),
557
613
  });
558
614
  }
615
+ const reqId = options.context
616
+ ?.requestId;
617
+ logMessageComposition(messages, reqId);
559
618
  return messages;
560
619
  }
561
620
  /**
@@ -982,10 +1041,15 @@ export async function buildMultimodalMessagesArray(options, provider, model) {
982
1041
  options.input.files = [];
983
1042
  }
984
1043
  const standardMessages = await buildMessagesArray(options);
985
- return standardMessages.map((msg) => ({
986
- role: msg.role,
987
- content: typeof msg.content === "string" ? msg.content : msg.content,
988
- }));
1044
+ return standardMessages.map((msg) => {
1045
+ const msgProviderOptions = msg
1046
+ .providerOptions;
1047
+ return {
1048
+ role: msg.role,
1049
+ content: msg.content,
1050
+ ...(msgProviderOptions && { providerOptions: msgProviderOptions }),
1051
+ };
1052
+ });
989
1053
  }
990
1054
  // Validate provider supports vision
991
1055
  if (!ProviderImageAdapter.supportsVision(provider, model)) {
@@ -999,6 +1063,9 @@ export async function buildMultimodalMessagesArray(options, provider, model) {
999
1063
  messages.push({
1000
1064
  role: "system",
1001
1065
  content: systemPrompt.trim(),
1066
+ providerOptions: {
1067
+ anthropic: { cacheControl: { type: "ephemeral" } },
1068
+ },
1002
1069
  });
1003
1070
  }
1004
1071
  // Add conversation history if available
@@ -1036,6 +1103,9 @@ export async function buildMultimodalMessagesArray(options, provider, model) {
1036
1103
  content: userContent,
1037
1104
  });
1038
1105
  }
1106
+ const reqId = options.context
1107
+ ?.requestId;
1108
+ logMessageComposition(messages, reqId);
1039
1109
  return messages;
1040
1110
  }
1041
1111
  catch (error) {
@@ -4,6 +4,7 @@
4
4
  */
5
5
  import { createClient } from "redis";
6
6
  import { logger } from "./logger.js";
7
+ const SESSION_ONLY_PREFIX = "session-only:";
7
8
  // Connection pool - keyed by host:port:db
8
9
  const connectionPool = new Map();
9
10
  const pendingConnections = new Map();
@@ -158,7 +159,11 @@ export async function createRedisClient(config) {
158
159
  * Generates a Redis key for session messages
159
160
  */
160
161
  export function getSessionKey(config, sessionId, userId) {
161
- const key = `${config.keyPrefix}${userId || "randomUser"}:${sessionId}`;
162
+ if (!userId) {
163
+ logger.warn("[REDIS] getSessionKey called without userId", { sessionId });
164
+ return `${config.keyPrefix}${SESSION_ONLY_PREFIX}${sessionId}`;
165
+ }
166
+ const key = `${config.keyPrefix}${userId}:${sessionId}`;
162
167
  logger.debug("[redisUtils] Generated session key", {
163
168
  sessionId,
164
169
  userId,
@@ -43,7 +43,7 @@ export declare function estimateTokens(text: string, provider?: string, isCode?:
43
43
  */
44
44
  export declare function estimateMessageTokens(message: ChatMessage | {
45
45
  role: string;
46
- content: string;
46
+ content: unknown;
47
47
  }, provider?: string): number;
48
48
  /**
49
49
  * Estimate total token count for an array of messages.
@@ -51,7 +51,7 @@ export declare function estimateMessageTokens(message: ChatMessage | {
51
51
  */
52
52
  export declare function estimateMessagesTokens(messages: Array<ChatMessage | {
53
53
  role: string;
54
- content: string;
54
+ content: unknown;
55
55
  }>, provider?: string): number;
56
56
  /**
57
57
  * Truncate text to fit within a token budget.
@@ -71,7 +71,22 @@ export function estimateTokens(text, provider, isCode) {
71
71
  * Includes message framing overhead.
72
72
  */
73
73
  export function estimateMessageTokens(message, provider) {
74
- const contentTokens = estimateTokens(message.content || "", provider);
74
+ let contentStr = "";
75
+ if (message.content) {
76
+ if (typeof message.content === "string") {
77
+ contentStr = message.content;
78
+ }
79
+ else {
80
+ try {
81
+ contentStr = JSON.stringify(message.content);
82
+ }
83
+ catch {
84
+ // Fallback for circular references or non-serializable content
85
+ contentStr = String(message.content);
86
+ }
87
+ }
88
+ }
89
+ const contentTokens = estimateTokens(contentStr, provider);
75
90
  return contentTokens + TOKENS_PER_MESSAGE;
76
91
  }
77
92
  /**
@@ -9,9 +9,10 @@ import type { CoreMessage } from "ai";
9
9
  import { AIProviderName } from "../constants/enums.js";
10
10
  /**
11
11
  * Check if messages contain video frames (images)
12
+ * Only checks user messages to match buildContentParts behavior
12
13
  *
13
14
  * @param messages - Array of CoreMessage objects
14
- * @returns true if video frames are present
15
+ * @returns true if video frames are present in user messages
15
16
  */
16
17
  export declare function hasVideoFrames(messages: CoreMessage[]): boolean;
17
18
  /**
@@ -9,12 +9,17 @@ import { AIProviderName } from "../constants/enums.js";
9
9
  import { logger } from "./logger.js";
10
10
  /**
11
11
  * Check if messages contain video frames (images)
12
+ * Only checks user messages to match buildContentParts behavior
12
13
  *
13
14
  * @param messages - Array of CoreMessage objects
14
- * @returns true if video frames are present
15
+ * @returns true if video frames are present in user messages
15
16
  */
16
17
  export function hasVideoFrames(messages) {
17
18
  return messages.some((msg) => {
19
+ // Only check user messages to match buildContentParts behavior
20
+ if (msg.role !== "user") {
21
+ return false;
22
+ }
18
23
  if (Array.isArray(msg.content)) {
19
24
  return msg.content.some((part) => typeof part === "object" &&
20
25
  part !== null &&
@@ -42,7 +47,7 @@ export async function executeVideoAnalysis(messages, options) {
42
47
  options.providerName === AIProviderName.VERTEX
43
48
  ? AIProviderName.VERTEX
44
49
  : AIProviderName.AUTO;
45
- const videoAnalysisText = await analyzeVideo(messages[0], {
50
+ const videoAnalysisText = await analyzeVideo(messages, {
46
51
  provider: provider,
47
52
  project: options.region
48
53
  ? undefined