@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
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
## [9.11.0](https://github.com/juspay/neurolink/compare/v9.10.1...v9.11.0) (2026-02-22)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
- **(core):** provider error standardization, abort hardening, session budget, and continuous test suites ([0ceb590](https://github.com/juspay/neurolink/commit/0ceb590dcad315d392f3e9563d0c5dc0c83cda00))
|
|
6
|
+
|
|
7
|
+
## [9.10.1](https://github.com/juspay/neurolink/compare/v9.10.0...v9.10.1) (2026-02-21)
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
- **(video-analysis):** add stream support for video analysis ([938aeef](https://github.com/juspay/neurolink/commit/938aeef876277360700d2a7192155af1f1316f28))
|
|
12
|
+
|
|
1
13
|
## [9.10.0](https://github.com/juspay/neurolink/compare/v9.9.0...v9.10.0) (2026-02-20)
|
|
2
14
|
|
|
3
15
|
### Features
|
|
@@ -8,16 +8,16 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { AIProviderName } from "../../constants/enums.js";
|
|
10
10
|
import type { CoreMessage } from "ai";
|
|
11
|
-
export declare function analyzeVideoWithVertexAI(
|
|
11
|
+
export declare function analyzeVideoWithVertexAI(messages: CoreMessage[], options?: {
|
|
12
12
|
project?: string;
|
|
13
13
|
location?: string;
|
|
14
14
|
model?: string;
|
|
15
15
|
}): Promise<string>;
|
|
16
|
-
export declare function analyzeVideoWithGeminiAPI(
|
|
16
|
+
export declare function analyzeVideoWithGeminiAPI(messages: CoreMessage[], options?: {
|
|
17
17
|
apiKey?: string;
|
|
18
18
|
model?: string;
|
|
19
19
|
}): Promise<string>;
|
|
20
|
-
export declare function analyzeVideo(
|
|
20
|
+
export declare function analyzeVideo(messages: CoreMessage[], options?: {
|
|
21
21
|
provider?: AIProviderName;
|
|
22
22
|
project?: string;
|
|
23
23
|
location?: string;
|
|
@@ -9,23 +9,35 @@
|
|
|
9
9
|
import { AIProviderName, ErrorSeverity, ErrorCategory, } from "../../constants/enums.js";
|
|
10
10
|
import { logger } from "../../utils/logger.js";
|
|
11
11
|
import { readFile } from "node:fs/promises";
|
|
12
|
-
import { NeuroLinkError } from "../../utils/errorHandling.js";
|
|
12
|
+
import { NeuroLinkError, ErrorFactory } from "../../utils/errorHandling.js";
|
|
13
13
|
// ---------------------------------------------------------------------------
|
|
14
14
|
// Shared config
|
|
15
15
|
// ---------------------------------------------------------------------------
|
|
16
16
|
const DEFAULT_MODEL = "gemini-2.0-flash";
|
|
17
17
|
const DEFAULT_LOCATION = "us-central1";
|
|
18
|
+
/**
|
|
19
|
+
* Extract content items from user messages
|
|
20
|
+
*
|
|
21
|
+
* @param messages - Array of CoreMessage objects
|
|
22
|
+
* @returns Flattened array of content items from user messages
|
|
23
|
+
*/
|
|
24
|
+
function extractUserContent(messages) {
|
|
25
|
+
const userMessages = messages.filter((msg) => msg.role === "user");
|
|
26
|
+
return userMessages.flatMap((msg) => Array.isArray(msg.content) ? msg.content : []);
|
|
27
|
+
}
|
|
18
28
|
/**
|
|
19
29
|
* Convert CoreMessage content array to Gemini parts format
|
|
20
30
|
*
|
|
21
|
-
* @param
|
|
31
|
+
* @param messages - Array of CoreMessage objects
|
|
22
32
|
* @returns Array of parts in Gemini API format
|
|
23
33
|
*/
|
|
24
|
-
function buildContentParts(
|
|
25
|
-
const
|
|
26
|
-
return
|
|
27
|
-
|
|
28
|
-
|
|
34
|
+
function buildContentParts(messages) {
|
|
35
|
+
const allContent = extractUserContent(messages);
|
|
36
|
+
return allContent
|
|
37
|
+
.map((item) => {
|
|
38
|
+
if (item.type === "text") {
|
|
39
|
+
// Accept text parts regardless of whether text is empty
|
|
40
|
+
return { text: item.text || "" };
|
|
29
41
|
}
|
|
30
42
|
else if (item.type === "image" && item.image) {
|
|
31
43
|
let base64Data;
|
|
@@ -38,7 +50,7 @@ function buildContentParts(frames) {
|
|
|
38
50
|
base64Data = item.image.replace(/^data:image\/[a-z]+;base64,/, "");
|
|
39
51
|
}
|
|
40
52
|
else {
|
|
41
|
-
throw
|
|
53
|
+
throw ErrorFactory.invalidConfiguration("image data type", `expected string, Buffer, or Uint8Array, got ${typeof item.image}`, { itemType: item.type, dataType: typeof item.image });
|
|
42
54
|
}
|
|
43
55
|
return {
|
|
44
56
|
inlineData: {
|
|
@@ -47,8 +59,14 @@ function buildContentParts(frames) {
|
|
|
47
59
|
},
|
|
48
60
|
};
|
|
49
61
|
}
|
|
50
|
-
|
|
51
|
-
|
|
62
|
+
else if (item.type === "file") {
|
|
63
|
+
// Skip file parts - not supported in Gemini parts format
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
// Return null for unsupported types
|
|
67
|
+
return null;
|
|
68
|
+
})
|
|
69
|
+
.filter((part) => part !== null);
|
|
52
70
|
}
|
|
53
71
|
/**
|
|
54
72
|
* Configuration for video frame analysis.
|
|
@@ -88,7 +106,7 @@ Ensure the final response is fully self-sufficient and does not reference extern
|
|
|
88
106
|
// ---------------------------------------------------------------------------
|
|
89
107
|
// Vertex AI
|
|
90
108
|
// ---------------------------------------------------------------------------
|
|
91
|
-
export async function analyzeVideoWithVertexAI(
|
|
109
|
+
export async function analyzeVideoWithVertexAI(messages, options = {}) {
|
|
92
110
|
const startTime = Date.now();
|
|
93
111
|
const { GoogleGenAI } = await import("@google/genai");
|
|
94
112
|
// Get default config and merge with provided options
|
|
@@ -96,9 +114,9 @@ export async function analyzeVideoWithVertexAI(frames, options = {}) {
|
|
|
96
114
|
const project = options.project ?? config.project;
|
|
97
115
|
const location = options.location ?? config.location;
|
|
98
116
|
const model = options.model || DEFAULT_MODEL;
|
|
99
|
-
//
|
|
100
|
-
const
|
|
101
|
-
const frameCount =
|
|
117
|
+
// Convert frames content to parts array for Gemini
|
|
118
|
+
const parts = buildContentParts(messages);
|
|
119
|
+
const frameCount = parts.filter((part) => "inlineData" in part && part.inlineData).length;
|
|
102
120
|
logger.debug("[GeminiVideoAnalyzer] Analyzing video with Vertex AI", {
|
|
103
121
|
project,
|
|
104
122
|
location,
|
|
@@ -106,8 +124,6 @@ export async function analyzeVideoWithVertexAI(frames, options = {}) {
|
|
|
106
124
|
frameCount,
|
|
107
125
|
});
|
|
108
126
|
const ai = new GoogleGenAI({ vertexai: true, project, location });
|
|
109
|
-
// Convert frames content to parts array for Gemini
|
|
110
|
-
const parts = buildContentParts(frames);
|
|
111
127
|
const response = await ai.models.generateContent({
|
|
112
128
|
model,
|
|
113
129
|
config: buildConfig(),
|
|
@@ -129,7 +145,7 @@ export async function analyzeVideoWithVertexAI(frames, options = {}) {
|
|
|
129
145
|
// ---------------------------------------------------------------------------
|
|
130
146
|
// Gemini API (Google AI)
|
|
131
147
|
// ---------------------------------------------------------------------------
|
|
132
|
-
export async function analyzeVideoWithGeminiAPI(
|
|
148
|
+
export async function analyzeVideoWithGeminiAPI(messages, options = {}) {
|
|
133
149
|
const startTime = Date.now();
|
|
134
150
|
const { GoogleGenAI } = await import("@google/genai");
|
|
135
151
|
const apiKey = options.apiKey || process.env.GOOGLE_AI_API_KEY;
|
|
@@ -137,16 +153,14 @@ export async function analyzeVideoWithGeminiAPI(frames, options = {}) {
|
|
|
137
153
|
if (!apiKey) {
|
|
138
154
|
throw new Error("GOOGLE_AI_API_KEY environment variable is required for Gemini API video analysis");
|
|
139
155
|
}
|
|
140
|
-
//
|
|
141
|
-
const
|
|
142
|
-
const frameCount =
|
|
156
|
+
// Convert frames content to parts array for Gemini
|
|
157
|
+
const parts = buildContentParts(messages);
|
|
158
|
+
const frameCount = parts.filter((part) => "inlineData" in part && part.inlineData).length;
|
|
143
159
|
logger.debug("[GeminiVideoAnalyzer] Analyzing video with Gemini API", {
|
|
144
160
|
model,
|
|
145
161
|
frameCount,
|
|
146
162
|
});
|
|
147
163
|
const ai = new GoogleGenAI({ apiKey });
|
|
148
|
-
// Convert frames content to parts array for Gemini
|
|
149
|
-
const parts = buildContentParts(frames);
|
|
150
164
|
logger.debug("[GeminiVideoAnalyzer] Generating analysis with frames");
|
|
151
165
|
const response = await ai.models.generateContent({
|
|
152
166
|
model,
|
|
@@ -207,15 +221,15 @@ async function getVertexConfig() {
|
|
|
207
221
|
}
|
|
208
222
|
return { project, location };
|
|
209
223
|
}
|
|
210
|
-
export async function analyzeVideo(
|
|
224
|
+
export async function analyzeVideo(messages, options = {}) {
|
|
211
225
|
const provider = options.provider || AIProviderName.AUTO;
|
|
212
226
|
// Vertex — only when GOOGLE_VERTEX_PROJECT is explicitly set
|
|
213
227
|
if (provider === AIProviderName.VERTEX || provider === AIProviderName.AUTO) {
|
|
214
|
-
return analyzeVideoWithVertexAI(
|
|
228
|
+
return analyzeVideoWithVertexAI(messages, options);
|
|
215
229
|
}
|
|
216
230
|
// Gemini API — when GOOGLE_AI_API_KEY is set
|
|
217
231
|
if (provider === AIProviderName.GOOGLE_AI && process.env.GOOGLE_AI_API_KEY) {
|
|
218
|
-
return analyzeVideoWithGeminiAPI(
|
|
232
|
+
return analyzeVideoWithGeminiAPI(messages, options);
|
|
219
233
|
}
|
|
220
234
|
throw new Error("No valid provider configuration found. " +
|
|
221
235
|
"Set GOOGLE_VERTEX_PROJECT for Vertex AI or GOOGLE_AI_API_KEY for Gemini API.");
|
|
@@ -219,12 +219,12 @@ export declare const directAgentTools: {
|
|
|
219
219
|
content: z.ZodString;
|
|
220
220
|
mode: z.ZodDefault<z.ZodEnum<["create", "overwrite", "append"]>>;
|
|
221
221
|
}, "strip", z.ZodTypeAny, {
|
|
222
|
-
content: string;
|
|
223
222
|
path: string;
|
|
223
|
+
content: string;
|
|
224
224
|
mode: "append" | "create" | "overwrite";
|
|
225
225
|
}, {
|
|
226
|
-
content: string;
|
|
227
226
|
path: string;
|
|
227
|
+
content: string;
|
|
228
228
|
mode?: "append" | "create" | "overwrite" | undefined;
|
|
229
229
|
}>, {
|
|
230
230
|
success: boolean;
|
|
@@ -249,8 +249,8 @@ export declare const directAgentTools: {
|
|
|
249
249
|
written?: undefined;
|
|
250
250
|
}> & {
|
|
251
251
|
execute: (args: {
|
|
252
|
-
content: string;
|
|
253
252
|
path: string;
|
|
253
|
+
content: string;
|
|
254
254
|
mode: "append" | "create" | "overwrite";
|
|
255
255
|
}, options: import("ai").ToolExecutionOptions) => PromiseLike<{
|
|
256
256
|
success: boolean;
|
|
@@ -60,8 +60,8 @@ declare const ConfigSchema: z.ZodObject<{
|
|
|
60
60
|
}, {
|
|
61
61
|
model?: string | undefined;
|
|
62
62
|
projectId?: string | undefined;
|
|
63
|
-
credentials?: string | undefined;
|
|
64
63
|
location?: string | undefined;
|
|
64
|
+
credentials?: string | undefined;
|
|
65
65
|
privateKey?: string | undefined;
|
|
66
66
|
serviceAccountKey?: string | undefined;
|
|
67
67
|
clientEmail?: string | undefined;
|
|
@@ -83,13 +83,13 @@ declare const ConfigSchema: z.ZodObject<{
|
|
|
83
83
|
model: z.ZodDefault<z.ZodString>;
|
|
84
84
|
}, "strip", z.ZodTypeAny, {
|
|
85
85
|
model: string;
|
|
86
|
-
endpoint?: string | undefined;
|
|
87
86
|
apiKey?: string | undefined;
|
|
87
|
+
endpoint?: string | undefined;
|
|
88
88
|
deploymentId?: string | undefined;
|
|
89
89
|
}, {
|
|
90
90
|
model?: string | undefined;
|
|
91
|
-
endpoint?: string | undefined;
|
|
92
91
|
apiKey?: string | undefined;
|
|
92
|
+
endpoint?: string | undefined;
|
|
93
93
|
deploymentId?: string | undefined;
|
|
94
94
|
}>>;
|
|
95
95
|
"google-ai": z.ZodOptional<z.ZodObject<{
|
|
@@ -163,8 +163,8 @@ declare const ConfigSchema: z.ZodObject<{
|
|
|
163
163
|
} | undefined;
|
|
164
164
|
azure?: {
|
|
165
165
|
model: string;
|
|
166
|
-
endpoint?: string | undefined;
|
|
167
166
|
apiKey?: string | undefined;
|
|
167
|
+
endpoint?: string | undefined;
|
|
168
168
|
deploymentId?: string | undefined;
|
|
169
169
|
} | undefined;
|
|
170
170
|
"google-ai"?: {
|
|
@@ -200,8 +200,8 @@ declare const ConfigSchema: z.ZodObject<{
|
|
|
200
200
|
vertex?: {
|
|
201
201
|
model?: string | undefined;
|
|
202
202
|
projectId?: string | undefined;
|
|
203
|
-
credentials?: string | undefined;
|
|
204
203
|
location?: string | undefined;
|
|
204
|
+
credentials?: string | undefined;
|
|
205
205
|
privateKey?: string | undefined;
|
|
206
206
|
serviceAccountKey?: string | undefined;
|
|
207
207
|
clientEmail?: string | undefined;
|
|
@@ -212,8 +212,8 @@ declare const ConfigSchema: z.ZodObject<{
|
|
|
212
212
|
} | undefined;
|
|
213
213
|
azure?: {
|
|
214
214
|
model?: string | undefined;
|
|
215
|
-
endpoint?: string | undefined;
|
|
216
215
|
apiKey?: string | undefined;
|
|
216
|
+
endpoint?: string | undefined;
|
|
217
217
|
deploymentId?: string | undefined;
|
|
218
218
|
} | undefined;
|
|
219
219
|
"google-ai"?: {
|
|
@@ -483,8 +483,8 @@ declare const ConfigSchema: z.ZodObject<{
|
|
|
483
483
|
} | undefined;
|
|
484
484
|
azure?: {
|
|
485
485
|
model: string;
|
|
486
|
-
endpoint?: string | undefined;
|
|
487
486
|
apiKey?: string | undefined;
|
|
487
|
+
endpoint?: string | undefined;
|
|
488
488
|
deploymentId?: string | undefined;
|
|
489
489
|
} | undefined;
|
|
490
490
|
"google-ai"?: {
|
|
@@ -569,8 +569,8 @@ declare const ConfigSchema: z.ZodObject<{
|
|
|
569
569
|
vertex?: {
|
|
570
570
|
model?: string | undefined;
|
|
571
571
|
projectId?: string | undefined;
|
|
572
|
-
credentials?: string | undefined;
|
|
573
572
|
location?: string | undefined;
|
|
573
|
+
credentials?: string | undefined;
|
|
574
574
|
privateKey?: string | undefined;
|
|
575
575
|
serviceAccountKey?: string | undefined;
|
|
576
576
|
clientEmail?: string | undefined;
|
|
@@ -581,8 +581,8 @@ declare const ConfigSchema: z.ZodObject<{
|
|
|
581
581
|
} | undefined;
|
|
582
582
|
azure?: {
|
|
583
583
|
model?: string | undefined;
|
|
584
|
-
endpoint?: string | undefined;
|
|
585
584
|
apiKey?: string | undefined;
|
|
585
|
+
endpoint?: string | undefined;
|
|
586
586
|
deploymentId?: string | undefined;
|
|
587
587
|
} | undefined;
|
|
588
588
|
"google-ai"?: {
|
|
@@ -5,4 +5,4 @@ import type { TextGenerationOptions } from "../../lib/types/generateTypes.js";
|
|
|
5
5
|
* This object provides metadata for validation and help text in the CLI loop.
|
|
6
6
|
* It is derived from the main TextGenerationOptions interface to ensure consistency.
|
|
7
7
|
*/
|
|
8
|
-
export declare const textGenerationOptionsSchema: Record<keyof Omit<TextGenerationOptions, "prompt" | "input" | "schema" | "tools" | "context" | "conversationHistory" | "conversationMessages" | "conversationMemoryConfig" | "originalPrompt" | "middleware" | "expectedOutcome" | "evaluationCriteria" | "region" | "csvOptions" | "tts" | "thinkingConfig" | "fileRegistry" | "abortSignal" | "toolFilter" | "excludeTools" | "toolChoice" | "prepareStep">, OptionSchema>;
|
|
8
|
+
export declare const textGenerationOptionsSchema: Record<keyof Omit<TextGenerationOptions, "prompt" | "input" | "schema" | "tools" | "context" | "conversationHistory" | "conversationMessages" | "conversationMemoryConfig" | "originalPrompt" | "middleware" | "expectedOutcome" | "evaluationCriteria" | "region" | "csvOptions" | "tts" | "thinkingConfig" | "requestId" | "fileRegistry" | "abortSignal" | "toolFilter" | "excludeTools" | "toolChoice" | "prepareStep">, OptionSchema>;
|
|
@@ -25,9 +25,12 @@ export declare const MODEL_CONTEXT_WINDOWS: Record<string, Record<string, number
|
|
|
25
25
|
* Resolve context window size for a provider/model combination.
|
|
26
26
|
*
|
|
27
27
|
* Priority:
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
28
|
+
* 0. Dynamic model registry (DynamicModelProvider) — resolves cross-provider
|
|
29
|
+
* models (e.g. Claude on Vertex) that the static table cannot handle
|
|
30
|
+
* 1. Exact model match under provider in static registry
|
|
31
|
+
* 2. Prefix match under provider in static registry
|
|
32
|
+
* 3. Provider's _default in static registry
|
|
33
|
+
* 4. Global DEFAULT_CONTEXT_WINDOW
|
|
31
34
|
*/
|
|
32
35
|
export declare function getContextWindowSize(provider: string, model?: string): number;
|
|
33
36
|
/**
|
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
* - Google: https://ai.google.dev/gemini-api/docs/models
|
|
11
11
|
* - Others: Provider documentation as of Feb 2026
|
|
12
12
|
*/
|
|
13
|
+
import { DynamicModelProvider } from "../core/dynamicModels.js";
|
|
14
|
+
import { logger } from "../utils/logger.js";
|
|
13
15
|
/** Default context window when provider/model is unknown */
|
|
14
16
|
export const DEFAULT_CONTEXT_WINDOW = 128_000;
|
|
15
17
|
/** Maximum output reserve when maxTokens not specified */
|
|
@@ -67,6 +69,10 @@ export const MODEL_CONTEXT_WINDOWS = {
|
|
|
67
69
|
"gemini-2.0-flash": 1_048_576,
|
|
68
70
|
"gemini-1.5-pro": 2_097_152,
|
|
69
71
|
"gemini-1.5-flash": 1_048_576,
|
|
72
|
+
"claude-sonnet-4-5": 200_000,
|
|
73
|
+
"claude-sonnet-4-20250514": 200_000,
|
|
74
|
+
"claude-opus-4": 200_000,
|
|
75
|
+
"claude-opus-4-20250514": 200_000,
|
|
70
76
|
},
|
|
71
77
|
bedrock: {
|
|
72
78
|
_default: 200_000,
|
|
@@ -109,11 +115,32 @@ export const MODEL_CONTEXT_WINDOWS = {
|
|
|
109
115
|
* Resolve context window size for a provider/model combination.
|
|
110
116
|
*
|
|
111
117
|
* Priority:
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
118
|
+
* 0. Dynamic model registry (DynamicModelProvider) — resolves cross-provider
|
|
119
|
+
* models (e.g. Claude on Vertex) that the static table cannot handle
|
|
120
|
+
* 1. Exact model match under provider in static registry
|
|
121
|
+
* 2. Prefix match under provider in static registry
|
|
122
|
+
* 3. Provider's _default in static registry
|
|
123
|
+
* 4. Global DEFAULT_CONTEXT_WINDOW
|
|
115
124
|
*/
|
|
116
125
|
export function getContextWindowSize(provider, model) {
|
|
126
|
+
// Step 0: Check dynamic model registry first.
|
|
127
|
+
// This resolves cases where the runtime provider differs from the model's
|
|
128
|
+
// origin (e.g. Claude running via Vertex would hit Vertex's Gemini default
|
|
129
|
+
// in the static table). The dynamic registry knows the actual model metadata.
|
|
130
|
+
if (model) {
|
|
131
|
+
try {
|
|
132
|
+
const dynamicProvider = DynamicModelProvider.getInstance();
|
|
133
|
+
const modelConfig = dynamicProvider.resolveModel(provider, model);
|
|
134
|
+
if (modelConfig?.contextWindow) {
|
|
135
|
+
logger.debug(`[ContextWindow] Resolved via dynamic registry: provider=${provider}, model=${model}, contextWindow=${modelConfig.contextWindow}`);
|
|
136
|
+
return modelConfig.contextWindow;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
// Dynamic registry not initialized yet — fall through to static lookup
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
// Static fallback chain
|
|
117
144
|
const providerWindows = MODEL_CONTEXT_WINDOWS[provider];
|
|
118
145
|
if (!providerWindows) {
|
|
119
146
|
return DEFAULT_CONTEXT_WINDOW;
|
|
@@ -58,7 +58,7 @@ export declare const PROVIDER_OPERATION_CONFIGS: {
|
|
|
58
58
|
};
|
|
59
59
|
readonly OLLAMA: {
|
|
60
60
|
readonly timeout: 10000;
|
|
61
|
-
readonly maxRetries:
|
|
61
|
+
readonly maxRetries: 1;
|
|
62
62
|
readonly retryDelay: 200;
|
|
63
63
|
};
|
|
64
64
|
};
|
|
@@ -83,7 +83,7 @@ export declare const MCP_OPERATION_CONFIGS: {
|
|
|
83
83
|
};
|
|
84
84
|
readonly HEALTH_CHECK: {
|
|
85
85
|
readonly timeout: 5000;
|
|
86
|
-
readonly maxRetries:
|
|
86
|
+
readonly maxRetries: 1;
|
|
87
87
|
readonly retryDelay: 200;
|
|
88
88
|
};
|
|
89
89
|
};
|
|
@@ -140,7 +140,7 @@ export declare function getProviderRetryConfig(provider: string): {
|
|
|
140
140
|
readonly maxDelay: 30000;
|
|
141
141
|
readonly multiplier: 1.5;
|
|
142
142
|
} | {
|
|
143
|
-
readonly maxAttempts:
|
|
143
|
+
readonly maxAttempts: 1;
|
|
144
144
|
readonly baseDelay: 200;
|
|
145
145
|
readonly maxDelay: 5000;
|
|
146
146
|
readonly multiplier: 1.5;
|
|
@@ -18,7 +18,7 @@ export declare const RETRY_ATTEMPTS: {
|
|
|
18
18
|
/** Critical operations that must succeed */
|
|
19
19
|
readonly CRITICAL: 5;
|
|
20
20
|
/** Quick operations that should fail fast */
|
|
21
|
-
readonly QUICK:
|
|
21
|
+
readonly QUICK: 1;
|
|
22
22
|
/** Network operations prone to transient failures */
|
|
23
23
|
readonly NETWORK: 4;
|
|
24
24
|
/** Authentication operations */
|
|
@@ -122,7 +122,7 @@ export declare const PROVIDER_RETRY: {
|
|
|
122
122
|
};
|
|
123
123
|
/** Ollama retry configuration (local service) */
|
|
124
124
|
readonly OLLAMA: {
|
|
125
|
-
readonly maxAttempts:
|
|
125
|
+
readonly maxAttempts: 1;
|
|
126
126
|
readonly baseDelay: 200;
|
|
127
127
|
readonly maxDelay: 5000;
|
|
128
128
|
readonly multiplier: 1.5;
|
|
@@ -141,7 +141,7 @@ export declare const OPERATION_RETRY: {
|
|
|
141
141
|
};
|
|
142
142
|
/** MCP operation retry config */
|
|
143
143
|
readonly MCP_OPERATION: {
|
|
144
|
-
readonly maxAttempts:
|
|
144
|
+
readonly maxAttempts: 1;
|
|
145
145
|
readonly baseDelay: 200;
|
|
146
146
|
readonly circuitBreaker: false;
|
|
147
147
|
};
|
|
@@ -210,7 +210,7 @@ export declare const RetryUtils: {
|
|
|
210
210
|
readonly maxDelay: 30000;
|
|
211
211
|
readonly multiplier: 1.5;
|
|
212
212
|
} | {
|
|
213
|
-
readonly maxAttempts:
|
|
213
|
+
readonly maxAttempts: 1;
|
|
214
214
|
readonly baseDelay: 200;
|
|
215
215
|
readonly maxDelay: 5000;
|
|
216
216
|
readonly multiplier: 1.5;
|
package/dist/constants/retry.js
CHANGED
|
@@ -18,7 +18,7 @@ export const RETRY_ATTEMPTS = {
|
|
|
18
18
|
/** Critical operations that must succeed */
|
|
19
19
|
CRITICAL: 5, // 5 attempts - High-importance operations
|
|
20
20
|
/** Quick operations that should fail fast */
|
|
21
|
-
QUICK:
|
|
21
|
+
QUICK: 1, // 1 attempt, no retries — fail fast
|
|
22
22
|
/** Network operations prone to transient failures */
|
|
23
23
|
NETWORK: 4, // 4 attempts - Network operations
|
|
24
24
|
/** Authentication operations */
|
|
@@ -18,5 +18,5 @@ export declare class ContextCompactor {
|
|
|
18
18
|
/**
|
|
19
19
|
* Run the multi-stage compaction pipeline until messages fit within budget.
|
|
20
20
|
*/
|
|
21
|
-
compact(messages: ChatMessage[], targetTokens: number, memoryConfig?: Partial<ConversationMemoryConfig
|
|
21
|
+
compact(messages: ChatMessage[], targetTokens: number, memoryConfig?: Partial<ConversationMemoryConfig>, requestId?: string): Promise<CompactionResult>;
|
|
22
22
|
}
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* Stage 4: Sliding Window Truncation (fallback -- no LLM call)
|
|
10
10
|
*/
|
|
11
11
|
import { estimateMessagesTokens } from "../utils/tokenEstimation.js";
|
|
12
|
+
import { logger } from "../utils/logger.js";
|
|
12
13
|
import { pruneToolOutputs } from "./stages/toolOutputPruner.js";
|
|
13
14
|
import { deduplicateFileReads } from "./stages/fileReadDeduplicator.js";
|
|
14
15
|
import { summarizeMessages } from "./stages/structuredSummarizer.js";
|
|
@@ -35,14 +36,21 @@ export class ContextCompactor {
|
|
|
35
36
|
/**
|
|
36
37
|
* Run the multi-stage compaction pipeline until messages fit within budget.
|
|
37
38
|
*/
|
|
38
|
-
async compact(messages, targetTokens, memoryConfig) {
|
|
39
|
+
async compact(messages, targetTokens, memoryConfig, requestId) {
|
|
40
|
+
const compactionStartTime = Date.now();
|
|
39
41
|
const provider = this.config.provider || undefined;
|
|
40
42
|
const tokensBefore = estimateMessagesTokens(messages, provider);
|
|
41
43
|
const stagesUsed = [];
|
|
42
44
|
let currentMessages = [...messages];
|
|
45
|
+
logger.info("[Compaction] Starting", {
|
|
46
|
+
requestId,
|
|
47
|
+
estimatedTokens: tokensBefore,
|
|
48
|
+
budgetTokens: targetTokens,
|
|
49
|
+
});
|
|
43
50
|
// Stage 1: Tool Output Pruning
|
|
44
51
|
if (this.config.enablePrune &&
|
|
45
52
|
estimateMessagesTokens(currentMessages, provider) > targetTokens) {
|
|
53
|
+
const stageTokensBefore = estimateMessagesTokens(currentMessages, provider);
|
|
46
54
|
const pruneResult = pruneToolOutputs(currentMessages, {
|
|
47
55
|
protectTokens: this.config.pruneProtectTokens,
|
|
48
56
|
minimumSavings: this.config.pruneMinimumSavings,
|
|
@@ -53,19 +61,37 @@ export class ContextCompactor {
|
|
|
53
61
|
currentMessages = pruneResult.messages;
|
|
54
62
|
stagesUsed.push("prune");
|
|
55
63
|
}
|
|
64
|
+
const stageTokensAfter = estimateMessagesTokens(currentMessages, provider);
|
|
65
|
+
logger.info("[Compaction] Stage 1 (prune)", {
|
|
66
|
+
requestId,
|
|
67
|
+
ran: pruneResult.pruned,
|
|
68
|
+
tokensBefore: stageTokensBefore,
|
|
69
|
+
tokensAfter: stageTokensAfter,
|
|
70
|
+
saved: stageTokensBefore - stageTokensAfter,
|
|
71
|
+
});
|
|
56
72
|
}
|
|
57
73
|
// Stage 2: File Read Deduplication
|
|
58
74
|
if (this.config.enableDeduplicate &&
|
|
59
75
|
estimateMessagesTokens(currentMessages, provider) > targetTokens) {
|
|
76
|
+
const stageTokensBefore = estimateMessagesTokens(currentMessages, provider);
|
|
60
77
|
const dedupResult = deduplicateFileReads(currentMessages);
|
|
61
78
|
if (dedupResult.deduplicated) {
|
|
62
79
|
currentMessages = dedupResult.messages;
|
|
63
80
|
stagesUsed.push("deduplicate");
|
|
64
81
|
}
|
|
82
|
+
const stageTokensAfter = estimateMessagesTokens(currentMessages, provider);
|
|
83
|
+
logger.info("[Compaction] Stage 2 (deduplicate)", {
|
|
84
|
+
requestId,
|
|
85
|
+
ran: dedupResult.deduplicated,
|
|
86
|
+
tokensBefore: stageTokensBefore,
|
|
87
|
+
tokensAfter: stageTokensAfter,
|
|
88
|
+
saved: stageTokensBefore - stageTokensAfter,
|
|
89
|
+
});
|
|
65
90
|
}
|
|
66
91
|
// Stage 3: LLM Summarization
|
|
67
92
|
if (this.config.enableSummarize &&
|
|
68
93
|
estimateMessagesTokens(currentMessages, provider) > targetTokens) {
|
|
94
|
+
const stageTokensBefore = estimateMessagesTokens(currentMessages, provider);
|
|
69
95
|
try {
|
|
70
96
|
const summarizeResult = await summarizeMessages(currentMessages, {
|
|
71
97
|
provider: this.config.summarizationProvider,
|
|
@@ -77,14 +103,30 @@ export class ContextCompactor {
|
|
|
77
103
|
currentMessages = summarizeResult.messages;
|
|
78
104
|
stagesUsed.push("summarize");
|
|
79
105
|
}
|
|
106
|
+
const stageTokensAfter = estimateMessagesTokens(currentMessages, provider);
|
|
107
|
+
logger.info("[Compaction] Stage 3 (summarize)", {
|
|
108
|
+
requestId,
|
|
109
|
+
ran: summarizeResult.summarized,
|
|
110
|
+
tokensBefore: stageTokensBefore,
|
|
111
|
+
tokensAfter: stageTokensAfter,
|
|
112
|
+
saved: stageTokensBefore - stageTokensAfter,
|
|
113
|
+
});
|
|
80
114
|
}
|
|
81
115
|
catch {
|
|
116
|
+
logger.info("[Compaction] Stage 3 (summarize)", {
|
|
117
|
+
requestId,
|
|
118
|
+
ran: false,
|
|
119
|
+
tokensBefore: stageTokensBefore,
|
|
120
|
+
tokensAfter: stageTokensBefore,
|
|
121
|
+
saved: 0,
|
|
122
|
+
});
|
|
82
123
|
// Summarization failed, fall through to truncation
|
|
83
124
|
}
|
|
84
125
|
}
|
|
85
126
|
// Stage 4: Sliding Window Truncation (fallback)
|
|
86
127
|
if (this.config.enableTruncate &&
|
|
87
128
|
estimateMessagesTokens(currentMessages, provider) > targetTokens) {
|
|
129
|
+
const stageTokensBefore = estimateMessagesTokens(currentMessages, provider);
|
|
88
130
|
const truncResult = truncateWithSlidingWindow(currentMessages, {
|
|
89
131
|
fraction: this.config.truncationFraction,
|
|
90
132
|
});
|
|
@@ -92,8 +134,24 @@ export class ContextCompactor {
|
|
|
92
134
|
currentMessages = truncResult.messages;
|
|
93
135
|
stagesUsed.push("truncate");
|
|
94
136
|
}
|
|
137
|
+
const stageTokensAfter = estimateMessagesTokens(currentMessages, provider);
|
|
138
|
+
logger.info("[Compaction] Stage 4 (truncate)", {
|
|
139
|
+
requestId,
|
|
140
|
+
ran: truncResult.truncated,
|
|
141
|
+
tokensBefore: stageTokensBefore,
|
|
142
|
+
tokensAfter: stageTokensAfter,
|
|
143
|
+
saved: stageTokensBefore - stageTokensAfter,
|
|
144
|
+
});
|
|
95
145
|
}
|
|
96
146
|
const tokensAfter = estimateMessagesTokens(currentMessages, provider);
|
|
147
|
+
logger.info("[Compaction] Complete", {
|
|
148
|
+
requestId,
|
|
149
|
+
tokensBefore,
|
|
150
|
+
tokensAfter,
|
|
151
|
+
totalSaved: tokensBefore - tokensAfter,
|
|
152
|
+
stagesUsed,
|
|
153
|
+
durationMs: Date.now() - compactionStartTime,
|
|
154
|
+
});
|
|
97
155
|
return {
|
|
98
156
|
compacted: stagesUsed.length > 0,
|
|
99
157
|
stagesUsed,
|
|
@@ -18,7 +18,7 @@ export declare class SummarizationEngine {
|
|
|
18
18
|
* @param logPrefix - Prefix for log messages
|
|
19
19
|
* @returns True if summarization was performed
|
|
20
20
|
*/
|
|
21
|
-
checkAndSummarize(session: SessionMemory, threshold: number, config: Partial<ConversationMemoryConfig>, logPrefix?: string): Promise<boolean>;
|
|
21
|
+
checkAndSummarize(session: SessionMemory, threshold: number, config: Partial<ConversationMemoryConfig>, logPrefix?: string, requestId?: string): Promise<boolean>;
|
|
22
22
|
/**
|
|
23
23
|
* Perform token-based summarization on a session.
|
|
24
24
|
* Uses pointer-based, non-destructive approach.
|
|
@@ -27,7 +27,7 @@ export declare class SummarizationEngine {
|
|
|
27
27
|
* @param config - Conversation memory configuration (partial allowed)
|
|
28
28
|
* @param logPrefix - Prefix for log messages
|
|
29
29
|
*/
|
|
30
|
-
summarizeSession(session: SessionMemory, threshold: number, config: Partial<ConversationMemoryConfig>, logPrefix?: string): Promise<void>;
|
|
30
|
+
summarizeSession(session: SessionMemory, threshold: number, config: Partial<ConversationMemoryConfig>, logPrefix?: string, requestId?: string): Promise<void>;
|
|
31
31
|
/**
|
|
32
32
|
* Estimate total tokens for a message array.
|
|
33
33
|
* @param messages - Array of chat messages
|