@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.
- package/CHANGELOG.md +12 -0
- package/dist/adapters/video/videoAnalyzer.d.ts +3 -3
- package/dist/adapters/video/videoAnalyzer.js +39 -25
- package/dist/agent/directTools.d.ts +3 -3
- package/dist/cli/commands/config.d.ts +9 -9
- package/dist/cli/loop/optionsSchema.d.ts +1 -1
- package/dist/constants/contextWindows.d.ts +6 -3
- package/dist/constants/contextWindows.js +30 -3
- package/dist/constants/index.d.ts +3 -3
- package/dist/constants/retry.d.ts +4 -4
- package/dist/constants/retry.js +1 -1
- package/dist/context/contextCompactor.d.ts +1 -1
- package/dist/context/contextCompactor.js +59 -1
- package/dist/context/summarizationEngine.d.ts +2 -2
- package/dist/context/summarizationEngine.js +44 -18
- package/dist/context/toolOutputLimits.d.ts +22 -13
- package/dist/context/toolOutputLimits.js +58 -64
- package/dist/core/baseProvider.d.ts +11 -2
- package/dist/core/baseProvider.js +30 -1
- package/dist/core/conversationMemoryManager.d.ts +13 -1
- package/dist/core/conversationMemoryManager.js +36 -5
- package/dist/core/modules/GenerationHandler.d.ts +6 -0
- package/dist/core/modules/GenerationHandler.js +192 -7
- package/dist/core/modules/MessageBuilder.js +42 -4
- package/dist/core/modules/TelemetryHandler.js +4 -1
- package/dist/core/redisConversationMemoryManager.d.ts +19 -3
- package/dist/core/redisConversationMemoryManager.js +253 -58
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/lib/adapters/video/videoAnalyzer.d.ts +3 -3
- package/dist/lib/adapters/video/videoAnalyzer.js +39 -25
- package/dist/lib/agent/directTools.d.ts +7 -7
- package/dist/lib/constants/contextWindows.d.ts +6 -3
- package/dist/lib/constants/contextWindows.js +30 -3
- package/dist/lib/constants/index.d.ts +3 -3
- package/dist/lib/constants/retry.d.ts +4 -4
- package/dist/lib/constants/retry.js +1 -1
- package/dist/lib/context/contextCompactor.d.ts +1 -1
- package/dist/lib/context/contextCompactor.js +59 -1
- package/dist/lib/context/summarizationEngine.d.ts +2 -2
- package/dist/lib/context/summarizationEngine.js +44 -18
- package/dist/lib/context/toolOutputLimits.d.ts +22 -13
- package/dist/lib/context/toolOutputLimits.js +58 -64
- package/dist/lib/core/baseProvider.d.ts +11 -2
- package/dist/lib/core/baseProvider.js +30 -1
- package/dist/lib/core/conversationMemoryManager.d.ts +13 -1
- package/dist/lib/core/conversationMemoryManager.js +36 -5
- package/dist/lib/core/modules/GenerationHandler.d.ts +6 -0
- package/dist/lib/core/modules/GenerationHandler.js +192 -7
- package/dist/lib/core/modules/MessageBuilder.js +42 -4
- package/dist/lib/core/modules/TelemetryHandler.js +4 -1
- package/dist/lib/core/redisConversationMemoryManager.d.ts +19 -3
- package/dist/lib/core/redisConversationMemoryManager.js +253 -58
- package/dist/lib/files/fileTools.d.ts +3 -3
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/index.js +3 -0
- package/dist/lib/mcp/externalServerManager.js +36 -1
- package/dist/lib/memory/memoryRetrievalTools.d.ts +166 -0
- package/dist/lib/memory/memoryRetrievalTools.js +145 -0
- package/dist/lib/neurolink.d.ts +35 -1
- package/dist/lib/neurolink.js +471 -16
- package/dist/lib/providers/amazonBedrock.d.ts +1 -1
- package/dist/lib/providers/amazonBedrock.js +78 -45
- package/dist/lib/providers/amazonSagemaker.d.ts +1 -1
- package/dist/lib/providers/amazonSagemaker.js +1 -1
- package/dist/lib/providers/anthropic.d.ts +1 -1
- package/dist/lib/providers/anthropic.js +7 -7
- package/dist/lib/providers/anthropicBaseProvider.d.ts +1 -1
- package/dist/lib/providers/anthropicBaseProvider.js +7 -6
- package/dist/lib/providers/azureOpenai.d.ts +1 -1
- package/dist/lib/providers/azureOpenai.js +1 -1
- package/dist/lib/providers/googleAiStudio.d.ts +1 -1
- package/dist/lib/providers/googleAiStudio.js +5 -5
- package/dist/lib/providers/googleVertex.d.ts +1 -1
- package/dist/lib/providers/googleVertex.js +74 -17
- package/dist/lib/providers/huggingFace.d.ts +1 -1
- package/dist/lib/providers/huggingFace.js +1 -1
- package/dist/lib/providers/litellm.d.ts +1 -1
- package/dist/lib/providers/litellm.js +18 -16
- package/dist/lib/providers/mistral.d.ts +1 -1
- package/dist/lib/providers/mistral.js +1 -1
- package/dist/lib/providers/ollama.d.ts +1 -1
- package/dist/lib/providers/ollama.js +8 -7
- package/dist/lib/providers/openAI.d.ts +1 -1
- package/dist/lib/providers/openAI.js +6 -6
- package/dist/lib/providers/openRouter.d.ts +1 -1
- package/dist/lib/providers/openRouter.js +6 -2
- package/dist/lib/providers/openaiCompatible.d.ts +1 -1
- package/dist/lib/providers/openaiCompatible.js +1 -1
- package/dist/lib/proxy/proxyFetch.js +291 -65
- package/dist/lib/server/utils/validation.d.ts +4 -4
- package/dist/lib/services/server/ai/observability/instrumentation.js +12 -3
- package/dist/lib/telemetry/telemetryService.d.ts +2 -1
- package/dist/lib/telemetry/telemetryService.js +8 -1
- package/dist/lib/types/contextTypes.d.ts +26 -2
- package/dist/lib/types/conversation.d.ts +72 -40
- package/dist/lib/types/conversationMemoryInterface.d.ts +5 -1
- package/dist/lib/types/generateTypes.d.ts +26 -0
- package/dist/lib/types/modelTypes.d.ts +2 -2
- package/dist/lib/types/multimodal.d.ts +2 -0
- package/dist/lib/types/observability.d.ts +10 -0
- package/dist/lib/types/sdkTypes.d.ts +1 -1
- package/dist/lib/utils/conversationMemory.d.ts +4 -3
- package/dist/lib/utils/conversationMemory.js +44 -6
- package/dist/lib/utils/errorHandling.d.ts +5 -0
- package/dist/lib/utils/errorHandling.js +7 -2
- package/dist/lib/utils/logger.d.ts +8 -0
- package/dist/lib/utils/logger.js +56 -1
- package/dist/lib/utils/messageBuilder.js +74 -4
- package/dist/lib/utils/redis.js +6 -1
- package/dist/lib/utils/tokenEstimation.d.ts +2 -2
- package/dist/lib/utils/tokenEstimation.js +16 -1
- package/dist/lib/utils/videoAnalysisProcessor.d.ts +2 -1
- package/dist/lib/utils/videoAnalysisProcessor.js +7 -2
- package/dist/lib/workflow/config.d.ts +110 -110
- package/dist/mcp/externalServerManager.js +36 -1
- package/dist/memory/memoryRetrievalTools.d.ts +166 -0
- package/dist/memory/memoryRetrievalTools.js +144 -0
- package/dist/neurolink.d.ts +35 -1
- package/dist/neurolink.js +471 -16
- package/dist/providers/amazonBedrock.d.ts +1 -1
- package/dist/providers/amazonBedrock.js +78 -45
- package/dist/providers/amazonSagemaker.d.ts +1 -1
- package/dist/providers/amazonSagemaker.js +1 -1
- package/dist/providers/anthropic.d.ts +1 -1
- package/dist/providers/anthropic.js +7 -7
- package/dist/providers/anthropicBaseProvider.d.ts +1 -1
- package/dist/providers/anthropicBaseProvider.js +7 -6
- package/dist/providers/azureOpenai.d.ts +1 -1
- package/dist/providers/azureOpenai.js +1 -1
- package/dist/providers/googleAiStudio.d.ts +1 -1
- package/dist/providers/googleAiStudio.js +5 -5
- package/dist/providers/googleVertex.d.ts +1 -1
- package/dist/providers/googleVertex.js +74 -17
- package/dist/providers/huggingFace.d.ts +1 -1
- package/dist/providers/huggingFace.js +1 -1
- package/dist/providers/litellm.d.ts +1 -1
- package/dist/providers/litellm.js +18 -16
- package/dist/providers/mistral.d.ts +1 -1
- package/dist/providers/mistral.js +1 -1
- package/dist/providers/ollama.d.ts +1 -1
- package/dist/providers/ollama.js +8 -7
- package/dist/providers/openAI.d.ts +1 -1
- package/dist/providers/openAI.js +6 -6
- package/dist/providers/openRouter.d.ts +1 -1
- package/dist/providers/openRouter.js +6 -2
- package/dist/providers/openaiCompatible.d.ts +1 -1
- package/dist/providers/openaiCompatible.js +1 -1
- package/dist/proxy/proxyFetch.js +291 -65
- package/dist/services/server/ai/observability/instrumentation.js +12 -3
- package/dist/telemetry/telemetryService.d.ts +2 -1
- package/dist/telemetry/telemetryService.js +8 -1
- package/dist/types/contextTypes.d.ts +26 -2
- package/dist/types/conversation.d.ts +72 -40
- package/dist/types/conversationMemoryInterface.d.ts +5 -1
- package/dist/types/generateTypes.d.ts +26 -0
- package/dist/types/modelTypes.d.ts +10 -10
- package/dist/types/multimodal.d.ts +2 -0
- package/dist/types/observability.d.ts +10 -0
- package/dist/types/sdkTypes.d.ts +1 -1
- package/dist/utils/conversationMemory.d.ts +4 -3
- package/dist/utils/conversationMemory.js +44 -6
- package/dist/utils/errorHandling.d.ts +5 -0
- package/dist/utils/errorHandling.js +7 -2
- package/dist/utils/logger.d.ts +8 -0
- package/dist/utils/logger.js +56 -1
- package/dist/utils/messageBuilder.js +74 -4
- package/dist/utils/redis.js +6 -1
- package/dist/utils/tokenEstimation.d.ts +2 -2
- package/dist/utils/tokenEstimation.js +16 -1
- package/dist/utils/videoAnalysisProcessor.d.ts +2 -1
- package/dist/utils/videoAnalysisProcessor.js +7 -2
- package/dist/workflow/config.d.ts +12 -12
- 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
|
-
|
|
987
|
-
|
|
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) {
|
package/dist/lib/utils/redis.js
CHANGED
|
@@ -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
|
-
|
|
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:
|
|
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:
|
|
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
|
-
|
|
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
|
|
50
|
+
const videoAnalysisText = await analyzeVideo(messages, {
|
|
46
51
|
provider: provider,
|
|
47
52
|
project: options.region
|
|
48
53
|
? undefined
|