@juspay/neurolink 9.24.0 → 9.25.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 +6 -0
- package/dist/adapters/tts/googleTTSHandler.js +26 -1
- package/dist/adapters/video/vertexVideoHandler.js +23 -17
- package/dist/cli/commands/config.d.ts +3 -3
- package/dist/cli/commands/observability.d.ts +53 -0
- package/dist/cli/commands/observability.js +453 -0
- package/dist/cli/commands/telemetry.d.ts +63 -0
- package/dist/cli/commands/telemetry.js +689 -0
- package/dist/cli/factories/commandFactory.js +29 -15
- package/dist/cli/parser.js +6 -9
- package/dist/cli/utils/formatters.d.ts +13 -0
- package/dist/cli/utils/formatters.js +23 -0
- package/dist/constants/contextWindows.js +6 -0
- package/dist/constants/enums.d.ts +6 -0
- package/dist/constants/enums.js +8 -2
- package/dist/context/budgetChecker.js +75 -48
- package/dist/context/contextCompactor.js +135 -127
- package/dist/core/baseProvider.d.ts +5 -0
- package/dist/core/baseProvider.js +158 -102
- package/dist/core/conversationMemoryInitializer.js +7 -4
- package/dist/core/conversationMemoryManager.d.ts +2 -0
- package/dist/core/conversationMemoryManager.js +6 -2
- package/dist/core/modules/GenerationHandler.d.ts +2 -2
- package/dist/core/modules/GenerationHandler.js +12 -12
- package/dist/evaluation/ragasEvaluator.js +39 -19
- package/dist/evaluation/scoring.js +46 -20
- package/dist/features/ppt/presentationOrchestrator.js +23 -0
- package/dist/features/ppt/slideGenerator.js +13 -0
- package/dist/features/ppt/slideRenderers.d.ts +1 -1
- package/dist/features/ppt/slideRenderers.js +6 -4
- package/dist/features/ppt/slideTypeInference.d.ts +1 -1
- package/dist/features/ppt/slideTypeInference.js +75 -73
- package/dist/files/fileTools.d.ts +6 -6
- package/dist/index.d.ts +46 -12
- package/dist/index.js +79 -17
- package/dist/lib/adapters/tts/googleTTSHandler.js +26 -1
- package/dist/lib/adapters/video/vertexVideoHandler.js +23 -17
- package/dist/lib/constants/contextWindows.js +6 -0
- package/dist/lib/constants/enums.d.ts +6 -0
- package/dist/lib/constants/enums.js +8 -2
- package/dist/lib/context/budgetChecker.js +75 -48
- package/dist/lib/context/contextCompactor.js +135 -127
- package/dist/lib/core/baseProvider.d.ts +5 -0
- package/dist/lib/core/baseProvider.js +158 -102
- package/dist/lib/core/conversationMemoryInitializer.js +7 -4
- package/dist/lib/core/conversationMemoryManager.d.ts +2 -0
- package/dist/lib/core/conversationMemoryManager.js +6 -2
- package/dist/lib/core/modules/GenerationHandler.d.ts +2 -2
- package/dist/lib/core/modules/GenerationHandler.js +12 -12
- package/dist/lib/evaluation/ragasEvaluator.js +39 -19
- package/dist/lib/evaluation/scoring.js +46 -20
- package/dist/lib/features/ppt/presentationOrchestrator.js +23 -0
- package/dist/lib/features/ppt/slideGenerator.js +13 -0
- package/dist/lib/features/ppt/slideRenderers.d.ts +1 -1
- package/dist/lib/features/ppt/slideRenderers.js +6 -4
- package/dist/lib/features/ppt/slideTypeInference.d.ts +1 -1
- package/dist/lib/features/ppt/slideTypeInference.js +75 -73
- package/dist/lib/files/fileTools.d.ts +6 -6
- package/dist/lib/index.d.ts +46 -12
- package/dist/lib/index.js +79 -17
- package/dist/lib/mcp/httpRateLimiter.js +39 -12
- package/dist/lib/mcp/httpRetryHandler.js +22 -1
- package/dist/lib/mcp/mcpClientFactory.js +13 -15
- package/dist/lib/memory/memoryRetrievalTools.js +22 -0
- package/dist/lib/neurolink.d.ts +64 -72
- package/dist/lib/neurolink.js +984 -566
- package/dist/lib/observability/exporterRegistry.d.ts +152 -0
- package/dist/lib/observability/exporterRegistry.js +414 -0
- package/dist/lib/observability/exporters/arizeExporter.d.ts +32 -0
- package/dist/lib/observability/exporters/arizeExporter.js +139 -0
- package/dist/lib/observability/exporters/baseExporter.d.ts +117 -0
- package/dist/lib/observability/exporters/baseExporter.js +191 -0
- package/dist/lib/observability/exporters/braintrustExporter.d.ts +30 -0
- package/dist/lib/observability/exporters/braintrustExporter.js +155 -0
- package/dist/lib/observability/exporters/datadogExporter.d.ts +37 -0
- package/dist/lib/observability/exporters/datadogExporter.js +197 -0
- package/dist/lib/observability/exporters/index.d.ts +13 -0
- package/dist/lib/observability/exporters/index.js +14 -0
- package/dist/lib/observability/exporters/laminarExporter.d.ts +48 -0
- package/dist/lib/observability/exporters/laminarExporter.js +303 -0
- package/dist/lib/observability/exporters/langfuseExporter.d.ts +47 -0
- package/dist/lib/observability/exporters/langfuseExporter.js +200 -0
- package/dist/lib/observability/exporters/langsmithExporter.d.ts +26 -0
- package/dist/lib/observability/exporters/langsmithExporter.js +124 -0
- package/dist/lib/observability/exporters/otelExporter.d.ts +39 -0
- package/dist/lib/observability/exporters/otelExporter.js +165 -0
- package/dist/lib/observability/exporters/posthogExporter.d.ts +48 -0
- package/dist/lib/observability/exporters/posthogExporter.js +288 -0
- package/dist/lib/observability/exporters/sentryExporter.d.ts +32 -0
- package/dist/lib/observability/exporters/sentryExporter.js +166 -0
- package/dist/lib/observability/index.d.ts +25 -0
- package/dist/lib/observability/index.js +32 -0
- package/dist/lib/observability/metricsAggregator.d.ts +260 -0
- package/dist/lib/observability/metricsAggregator.js +553 -0
- package/dist/lib/observability/otelBridge.d.ts +49 -0
- package/dist/lib/observability/otelBridge.js +132 -0
- package/dist/lib/observability/retryPolicy.d.ts +192 -0
- package/dist/lib/observability/retryPolicy.js +384 -0
- package/dist/lib/observability/sampling/index.d.ts +4 -0
- package/dist/lib/observability/sampling/index.js +5 -0
- package/dist/lib/observability/sampling/samplers.d.ts +116 -0
- package/dist/lib/observability/sampling/samplers.js +217 -0
- package/dist/lib/observability/spanProcessor.d.ts +129 -0
- package/dist/lib/observability/spanProcessor.js +288 -0
- package/dist/lib/observability/tokenTracker.d.ts +156 -0
- package/dist/lib/observability/tokenTracker.js +414 -0
- package/dist/lib/observability/types/exporterTypes.d.ts +250 -0
- package/dist/lib/observability/types/exporterTypes.js +6 -0
- package/dist/lib/observability/types/index.d.ts +6 -0
- package/dist/lib/observability/types/index.js +5 -0
- package/dist/lib/observability/types/spanTypes.d.ts +244 -0
- package/dist/lib/observability/types/spanTypes.js +93 -0
- package/dist/lib/observability/utils/index.d.ts +4 -0
- package/dist/lib/observability/utils/index.js +5 -0
- package/dist/lib/observability/utils/spanSerializer.d.ts +115 -0
- package/dist/lib/observability/utils/spanSerializer.js +287 -0
- package/dist/lib/providers/amazonSagemaker.d.ts +5 -4
- package/dist/lib/providers/amazonSagemaker.js +3 -4
- package/dist/lib/providers/googleVertex.d.ts +7 -0
- package/dist/lib/providers/googleVertex.js +80 -2
- package/dist/lib/rag/pipeline/RAGPipeline.d.ts +0 -5
- package/dist/lib/rag/pipeline/RAGPipeline.js +122 -87
- package/dist/lib/rag/ragIntegration.js +30 -0
- package/dist/lib/rag/retrieval/hybridSearch.js +22 -0
- package/dist/lib/server/abstract/baseServerAdapter.js +51 -19
- package/dist/lib/server/middleware/common.js +44 -12
- package/dist/lib/services/server/ai/observability/instrumentation.d.ts +2 -2
- package/dist/lib/services/server/ai/observability/instrumentation.js +10 -5
- package/dist/lib/types/conversationMemoryInterface.d.ts +2 -0
- package/dist/lib/types/modelTypes.d.ts +18 -18
- package/dist/lib/types/providers.d.ts +5 -0
- package/dist/lib/utils/pricing.js +25 -1
- package/dist/lib/utils/ttsProcessor.js +74 -59
- package/dist/lib/workflow/config.d.ts +36 -36
- package/dist/lib/workflow/core/ensembleExecutor.js +10 -0
- package/dist/lib/workflow/core/judgeScorer.js +20 -2
- package/dist/lib/workflow/core/workflowRunner.js +34 -1
- package/dist/mcp/httpRateLimiter.js +39 -12
- package/dist/mcp/httpRetryHandler.js +22 -1
- package/dist/mcp/mcpClientFactory.js +13 -15
- package/dist/memory/memoryRetrievalTools.js +22 -0
- package/dist/neurolink.d.ts +64 -72
- package/dist/neurolink.js +984 -566
- package/dist/observability/FEATURE-STATUS.md +269 -0
- package/dist/observability/exporterRegistry.d.ts +152 -0
- package/dist/observability/exporterRegistry.js +413 -0
- package/dist/observability/exporters/arizeExporter.d.ts +32 -0
- package/dist/observability/exporters/arizeExporter.js +138 -0
- package/dist/observability/exporters/baseExporter.d.ts +117 -0
- package/dist/observability/exporters/baseExporter.js +190 -0
- package/dist/observability/exporters/braintrustExporter.d.ts +30 -0
- package/dist/observability/exporters/braintrustExporter.js +154 -0
- package/dist/observability/exporters/datadogExporter.d.ts +37 -0
- package/dist/observability/exporters/datadogExporter.js +196 -0
- package/dist/observability/exporters/index.d.ts +13 -0
- package/dist/observability/exporters/index.js +13 -0
- package/dist/observability/exporters/laminarExporter.d.ts +48 -0
- package/dist/observability/exporters/laminarExporter.js +302 -0
- package/dist/observability/exporters/langfuseExporter.d.ts +47 -0
- package/dist/observability/exporters/langfuseExporter.js +199 -0
- package/dist/observability/exporters/langsmithExporter.d.ts +26 -0
- package/dist/observability/exporters/langsmithExporter.js +123 -0
- package/dist/observability/exporters/otelExporter.d.ts +39 -0
- package/dist/observability/exporters/otelExporter.js +164 -0
- package/dist/observability/exporters/posthogExporter.d.ts +48 -0
- package/dist/observability/exporters/posthogExporter.js +287 -0
- package/dist/observability/exporters/sentryExporter.d.ts +32 -0
- package/dist/observability/exporters/sentryExporter.js +165 -0
- package/dist/observability/index.d.ts +25 -0
- package/dist/observability/index.js +31 -0
- package/dist/observability/metricsAggregator.d.ts +260 -0
- package/dist/observability/metricsAggregator.js +552 -0
- package/dist/observability/otelBridge.d.ts +49 -0
- package/dist/observability/otelBridge.js +131 -0
- package/dist/observability/retryPolicy.d.ts +192 -0
- package/dist/observability/retryPolicy.js +383 -0
- package/dist/observability/sampling/index.d.ts +4 -0
- package/dist/observability/sampling/index.js +4 -0
- package/dist/observability/sampling/samplers.d.ts +116 -0
- package/dist/observability/sampling/samplers.js +216 -0
- package/dist/observability/spanProcessor.d.ts +129 -0
- package/dist/observability/spanProcessor.js +287 -0
- package/dist/observability/tokenTracker.d.ts +156 -0
- package/dist/observability/tokenTracker.js +413 -0
- package/dist/observability/types/exporterTypes.d.ts +250 -0
- package/dist/observability/types/exporterTypes.js +5 -0
- package/dist/observability/types/index.d.ts +6 -0
- package/dist/observability/types/index.js +4 -0
- package/dist/observability/types/spanTypes.d.ts +244 -0
- package/dist/observability/types/spanTypes.js +92 -0
- package/dist/observability/utils/index.d.ts +4 -0
- package/dist/observability/utils/index.js +4 -0
- package/dist/observability/utils/spanSerializer.d.ts +115 -0
- package/dist/observability/utils/spanSerializer.js +286 -0
- package/dist/providers/amazonSagemaker.d.ts +5 -4
- package/dist/providers/amazonSagemaker.js +3 -4
- package/dist/providers/googleVertex.d.ts +7 -0
- package/dist/providers/googleVertex.js +80 -2
- package/dist/rag/pipeline/RAGPipeline.d.ts +0 -5
- package/dist/rag/pipeline/RAGPipeline.js +122 -87
- package/dist/rag/ragIntegration.js +30 -0
- package/dist/rag/retrieval/hybridSearch.js +22 -0
- package/dist/server/abstract/baseServerAdapter.js +51 -19
- package/dist/server/middleware/common.js +44 -12
- package/dist/services/server/ai/observability/instrumentation.d.ts +2 -2
- package/dist/services/server/ai/observability/instrumentation.js +10 -5
- package/dist/types/conversationMemoryInterface.d.ts +2 -0
- package/dist/types/providers.d.ts +5 -0
- package/dist/utils/pricing.js +25 -1
- package/dist/utils/ttsProcessor.js +74 -59
- package/dist/workflow/config.d.ts +52 -52
- package/dist/workflow/core/ensembleExecutor.js +10 -0
- package/dist/workflow/core/judgeScorer.js +20 -2
- package/dist/workflow/core/workflowRunner.js +34 -1
- package/package.json +1 -1
|
@@ -1725,11 +1725,11 @@ export class CLICommandFactory {
|
|
|
1725
1725
|
logger.always(chalk.gray(`🔧 Provider: ${providerInfo} | Model: ${modelInfo}`));
|
|
1726
1726
|
}
|
|
1727
1727
|
if (!isVideoMode && !isPPTMode) {
|
|
1728
|
-
|
|
1728
|
+
CLICommandFactory.handleOutput(genResult, options);
|
|
1729
1729
|
}
|
|
1730
|
-
await
|
|
1731
|
-
await
|
|
1732
|
-
await
|
|
1730
|
+
await CLICommandFactory.handleTTSOutput(genResult, options);
|
|
1731
|
+
await CLICommandFactory.handleVideoOutput(genResult, options);
|
|
1732
|
+
await CLICommandFactory.handlePPTOutput(genResult, options);
|
|
1733
1733
|
if (options.debug) {
|
|
1734
1734
|
logger.debug("\n" + chalk.yellow("Debug Information:"));
|
|
1735
1735
|
logger.debug("Provider:", genResult.provider);
|
|
@@ -1742,7 +1742,7 @@ export class CLICommandFactory {
|
|
|
1742
1742
|
}
|
|
1743
1743
|
}
|
|
1744
1744
|
if (!globalSession.getCurrentSessionId()) {
|
|
1745
|
-
await
|
|
1745
|
+
await CLICommandFactory.flushLangfuseTraces();
|
|
1746
1746
|
process.exit(0);
|
|
1747
1747
|
}
|
|
1748
1748
|
}
|
|
@@ -1751,11 +1751,11 @@ export class CLICommandFactory {
|
|
|
1751
1751
|
*/
|
|
1752
1752
|
static async executeGenerate(argv) {
|
|
1753
1753
|
// Handle stdin input
|
|
1754
|
-
const rawInput = await
|
|
1754
|
+
const rawInput = await CLICommandFactory.handleGenerateStdinInput(argv);
|
|
1755
1755
|
argv.input = rawInput;
|
|
1756
|
-
const options =
|
|
1756
|
+
const options = CLICommandFactory.processOptions(argv);
|
|
1757
1757
|
// Detect output mode
|
|
1758
|
-
const { isVideoMode, isPPTMode, spinnerMessage } =
|
|
1758
|
+
const { isVideoMode, isPPTMode, spinnerMessage } = CLICommandFactory.detectGenerateOutputMode(argv, options);
|
|
1759
1759
|
const spinner = argv.quiet ? null : ora(spinnerMessage).start();
|
|
1760
1760
|
try {
|
|
1761
1761
|
// Add delay if specified
|
|
@@ -1763,7 +1763,7 @@ export class CLICommandFactory {
|
|
|
1763
1763
|
await new Promise((resolve) => setTimeout(resolve, options.delay));
|
|
1764
1764
|
}
|
|
1765
1765
|
// Process context
|
|
1766
|
-
const { inputText, contextMetadata } =
|
|
1766
|
+
const { inputText, contextMetadata } = CLICommandFactory.processGenerateContext(rawInput, options);
|
|
1767
1767
|
// Handle dry-run mode for testing
|
|
1768
1768
|
if (options.dryRun) {
|
|
1769
1769
|
const mockResult = {
|
|
@@ -1797,7 +1797,7 @@ export class CLICommandFactory {
|
|
|
1797
1797
|
if (spinner) {
|
|
1798
1798
|
spinner.succeed(chalk.green("✅ Dry-run completed successfully!"));
|
|
1799
1799
|
}
|
|
1800
|
-
|
|
1800
|
+
CLICommandFactory.handleOutput(mockResult, options);
|
|
1801
1801
|
if (options.debug) {
|
|
1802
1802
|
logger.debug("\n" + chalk.yellow("Debug Information (Dry-run):"));
|
|
1803
1803
|
logger.debug("Provider:", mockResult.provider);
|
|
@@ -1829,11 +1829,11 @@ export class CLICommandFactory {
|
|
|
1829
1829
|
CLICommandFactory.configureVideoMode(enhancedOptions, argv, options);
|
|
1830
1830
|
}
|
|
1831
1831
|
if (isPPTMode) {
|
|
1832
|
-
|
|
1832
|
+
CLICommandFactory.configurePPTMode(enhancedOptions, argv, options);
|
|
1833
1833
|
}
|
|
1834
1834
|
// Build multimodal input and output configuration
|
|
1835
|
-
const generateInput =
|
|
1836
|
-
const outputConfig =
|
|
1835
|
+
const generateInput = CLICommandFactory.buildGenerateMultimodalInput(inputText, argv);
|
|
1836
|
+
const outputConfig = CLICommandFactory.buildGenerateOutputConfig(isVideoMode, isPPTMode, enhancedOptions);
|
|
1837
1837
|
// Execute generation
|
|
1838
1838
|
const result = await sdk.generate({
|
|
1839
1839
|
input: generateInput,
|
|
@@ -1881,9 +1881,23 @@ export class CLICommandFactory {
|
|
|
1881
1881
|
topK: argv.ragTopK,
|
|
1882
1882
|
}
|
|
1883
1883
|
: undefined,
|
|
1884
|
+
// TTS configuration
|
|
1885
|
+
tts: enhancedOptions.tts
|
|
1886
|
+
? {
|
|
1887
|
+
enabled: true,
|
|
1888
|
+
useAiResponse: true,
|
|
1889
|
+
voice: enhancedOptions.ttsVoice,
|
|
1890
|
+
format: enhancedOptions.ttsFormat ||
|
|
1891
|
+
undefined,
|
|
1892
|
+
speed: enhancedOptions.ttsSpeed,
|
|
1893
|
+
quality: enhancedOptions.ttsQuality,
|
|
1894
|
+
output: enhancedOptions.ttsOutput,
|
|
1895
|
+
play: enhancedOptions.ttsPlay,
|
|
1896
|
+
}
|
|
1897
|
+
: undefined,
|
|
1884
1898
|
});
|
|
1885
1899
|
// Handle successful result
|
|
1886
|
-
await
|
|
1900
|
+
await CLICommandFactory.handleGenerateSuccess(result, options, isVideoMode, isPPTMode, spinner);
|
|
1887
1901
|
}
|
|
1888
1902
|
catch (error) {
|
|
1889
1903
|
if (spinner) {
|
|
@@ -2332,7 +2346,7 @@ export class CLICommandFactory {
|
|
|
2332
2346
|
await CLICommandFactory.handleStdinInput(argv);
|
|
2333
2347
|
const options = CLICommandFactory.processOptions(argv);
|
|
2334
2348
|
// Validate Anthropic subscription options if using Anthropic provider
|
|
2335
|
-
|
|
2349
|
+
CLICommandFactory.validateAnthropicSubscriptionOptions(options);
|
|
2336
2350
|
if (!options.quiet) {
|
|
2337
2351
|
logger.always(chalk.blue("🔄 Streaming..."));
|
|
2338
2352
|
}
|
package/dist/cli/parser.js
CHANGED
|
@@ -10,9 +10,8 @@ import { SetupCommandFactory } from "./factories/setupCommandFactory.js";
|
|
|
10
10
|
import { ServerCommandFactory } from "./commands/server.js";
|
|
11
11
|
import { ServeCommandFactory } from "./commands/serve.js";
|
|
12
12
|
import { ragCommand } from "./commands/rag.js";
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import { WorkflowCommandFactory } from "./commands/workflow.js";
|
|
13
|
+
import { ObservabilityCommandFactory } from "./commands/observability.js";
|
|
14
|
+
import { TelemetryCommandFactory } from "./commands/telemetry.js";
|
|
16
15
|
// Enhanced CLI with Professional UX
|
|
17
16
|
export function initializeCliParser() {
|
|
18
17
|
return (yargs(hideBin(process.argv))
|
|
@@ -176,11 +175,9 @@ export function initializeCliParser() {
|
|
|
176
175
|
.command(ServeCommandFactory.createServeCommands())
|
|
177
176
|
// RAG Document Processing Commands
|
|
178
177
|
.command(ragCommand)
|
|
179
|
-
//
|
|
180
|
-
.command(
|
|
181
|
-
//
|
|
182
|
-
.command(
|
|
183
|
-
// Workflow Commands
|
|
184
|
-
.command(WorkflowCommandFactory.createWorkflowCommands())); // Close the main return statement
|
|
178
|
+
// Observability Commands
|
|
179
|
+
.command(ObservabilityCommandFactory.createObservabilityCommands())
|
|
180
|
+
// Telemetry Commands
|
|
181
|
+
.command(TelemetryCommandFactory.createTelemetryCommands())); // Close the main return statement
|
|
185
182
|
}
|
|
186
183
|
//# sourceMappingURL=parser.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared CLI formatting utilities
|
|
3
|
+
*
|
|
4
|
+
* Common formatting functions used across CLI command modules.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Format a table row with padding
|
|
8
|
+
*/
|
|
9
|
+
export declare function formatRow(label: string, value: string, width?: number): string;
|
|
10
|
+
/**
|
|
11
|
+
* Format currency value
|
|
12
|
+
*/
|
|
13
|
+
export declare function formatCost(cost: number, currency?: string): string;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared CLI formatting utilities
|
|
3
|
+
*
|
|
4
|
+
* Common formatting functions used across CLI command modules.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Format a table row with padding
|
|
8
|
+
*/
|
|
9
|
+
export function formatRow(label, value, width = 30) {
|
|
10
|
+
const paddedLabel = label.padEnd(width);
|
|
11
|
+
return `${paddedLabel} ${value}`;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Format currency value
|
|
15
|
+
*/
|
|
16
|
+
export function formatCost(cost, currency = "USD") {
|
|
17
|
+
return new Intl.NumberFormat("en-US", {
|
|
18
|
+
style: "currency",
|
|
19
|
+
currency,
|
|
20
|
+
minimumFractionDigits: 4,
|
|
21
|
+
}).format(cost);
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=formatters.js.map
|
|
@@ -88,7 +88,10 @@ export const MODEL_CONTEXT_WINDOWS = {
|
|
|
88
88
|
},
|
|
89
89
|
"google-ai": {
|
|
90
90
|
_default: 1_048_576,
|
|
91
|
+
"gemini-3.1-pro": 1_048_576,
|
|
91
92
|
"gemini-3.1-pro-preview": 1_048_576,
|
|
93
|
+
"gemini-3.1-flash": 1_048_576,
|
|
94
|
+
"gemini-3.1-flash-lite": 1_048_576,
|
|
92
95
|
"gemini-3-pro-preview": 1_048_576,
|
|
93
96
|
"gemini-3-pro-image-preview": 65_536,
|
|
94
97
|
"gemini-3-flash-preview": 1_048_576,
|
|
@@ -114,7 +117,10 @@ export const MODEL_CONTEXT_WINDOWS = {
|
|
|
114
117
|
"claude-opus-4-20250514": 200_000,
|
|
115
118
|
"claude-opus-4": 200_000,
|
|
116
119
|
// Gemini on Vertex
|
|
120
|
+
"gemini-3.1-pro": 1_048_576,
|
|
117
121
|
"gemini-3.1-pro-preview": 1_048_576,
|
|
122
|
+
"gemini-3.1-flash": 1_048_576,
|
|
123
|
+
"gemini-3.1-flash-lite": 1_048_576,
|
|
118
124
|
"gemini-3-pro-preview": 1_048_576,
|
|
119
125
|
"gemini-3-pro-latest": 1_048_576,
|
|
120
126
|
"gemini-3-flash-preview": 1_048_576,
|
|
@@ -234,7 +234,10 @@ export declare enum VertexModels {
|
|
|
234
234
|
CLAUDE_3_SONNET = "claude-3-sonnet-20240229",
|
|
235
235
|
CLAUDE_3_OPUS = "claude-3-opus-20240229",
|
|
236
236
|
CLAUDE_3_HAIKU = "claude-3-haiku-20240307",
|
|
237
|
+
GEMINI_3_1_PRO = "gemini-3.1-pro",
|
|
237
238
|
GEMINI_3_1_PRO_PREVIEW = "gemini-3.1-pro-preview",
|
|
239
|
+
GEMINI_3_1_FLASH = "gemini-3.1-flash",
|
|
240
|
+
GEMINI_3_1_FLASH_LITE = "gemini-3.1-flash-lite",
|
|
238
241
|
GEMINI_3_PRO = "gemini-3-pro",
|
|
239
242
|
GEMINI_3_PRO_PREVIEW_11_2025 = "gemini-3-pro-preview-11-2025",
|
|
240
243
|
GEMINI_3_PRO_LATEST = "gemini-3-pro-latest",
|
|
@@ -258,7 +261,10 @@ export declare enum VertexModels {
|
|
|
258
261
|
* Supported Models for Google AI Studio
|
|
259
262
|
*/
|
|
260
263
|
export declare enum GoogleAIModels {
|
|
264
|
+
GEMINI_3_1_PRO = "gemini-3.1-pro",
|
|
261
265
|
GEMINI_3_1_PRO_PREVIEW = "gemini-3.1-pro-preview",
|
|
266
|
+
GEMINI_3_1_FLASH = "gemini-3.1-flash",
|
|
267
|
+
GEMINI_3_1_FLASH_LITE = "gemini-3.1-flash-lite",
|
|
262
268
|
GEMINI_3_PRO_PREVIEW = "gemini-3-pro-preview",
|
|
263
269
|
GEMINI_3_PRO_IMAGE_PREVIEW = "gemini-3-pro-image-preview",
|
|
264
270
|
GEMINI_3_FLASH = "gemini-3-flash",
|
package/dist/constants/enums.js
CHANGED
|
@@ -331,8 +331,11 @@ export var VertexModels;
|
|
|
331
331
|
VertexModels["CLAUDE_3_SONNET"] = "claude-3-sonnet-20240229";
|
|
332
332
|
VertexModels["CLAUDE_3_OPUS"] = "claude-3-opus-20240229";
|
|
333
333
|
VertexModels["CLAUDE_3_HAIKU"] = "claude-3-haiku-20240307";
|
|
334
|
-
// Gemini 3.1 Series (Released
|
|
334
|
+
// Gemini 3.1 Series (Released March 2026)
|
|
335
|
+
VertexModels["GEMINI_3_1_PRO"] = "gemini-3.1-pro";
|
|
335
336
|
VertexModels["GEMINI_3_1_PRO_PREVIEW"] = "gemini-3.1-pro-preview";
|
|
337
|
+
VertexModels["GEMINI_3_1_FLASH"] = "gemini-3.1-flash";
|
|
338
|
+
VertexModels["GEMINI_3_1_FLASH_LITE"] = "gemini-3.1-flash-lite";
|
|
336
339
|
// Gemini 3 Series (Preview)
|
|
337
340
|
VertexModels["GEMINI_3_PRO"] = "gemini-3-pro";
|
|
338
341
|
VertexModels["GEMINI_3_PRO_PREVIEW_11_2025"] = "gemini-3-pro-preview-11-2025";
|
|
@@ -361,8 +364,11 @@ export var VertexModels;
|
|
|
361
364
|
*/
|
|
362
365
|
export var GoogleAIModels;
|
|
363
366
|
(function (GoogleAIModels) {
|
|
364
|
-
// Gemini 3.1 Series (Released
|
|
367
|
+
// Gemini 3.1 Series (Released March 2026)
|
|
368
|
+
GoogleAIModels["GEMINI_3_1_PRO"] = "gemini-3.1-pro";
|
|
365
369
|
GoogleAIModels["GEMINI_3_1_PRO_PREVIEW"] = "gemini-3.1-pro-preview";
|
|
370
|
+
GoogleAIModels["GEMINI_3_1_FLASH"] = "gemini-3.1-flash";
|
|
371
|
+
GoogleAIModels["GEMINI_3_1_FLASH_LITE"] = "gemini-3.1-flash-lite";
|
|
366
372
|
// Gemini 3 Series (Preview)
|
|
367
373
|
GoogleAIModels["GEMINI_3_PRO_PREVIEW"] = "gemini-3-pro-preview";
|
|
368
374
|
GoogleAIModels["GEMINI_3_PRO_IMAGE_PREVIEW"] = "gemini-3-pro-image-preview";
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { getAvailableInputTokens } from "../constants/contextWindows.js";
|
|
10
10
|
import { estimateMessagesTokens, estimateTokens, TOKENS_PER_MESSAGE, } from "../utils/tokenEstimation.js";
|
|
11
|
+
import { SpanSerializer, SpanType, SpanStatus, } from "../observability/index.js";
|
|
12
|
+
import { getMetricsAggregator } from "../observability/index.js";
|
|
11
13
|
/** Default compaction threshold (80% of available input) */
|
|
12
14
|
const DEFAULT_COMPACTION_THRESHOLD = 0.8;
|
|
13
15
|
/** Estimated tokens per tool definition */
|
|
@@ -20,52 +22,77 @@ const TOKENS_PER_TOOL_DEFINITION = 200;
|
|
|
20
22
|
* against available input space.
|
|
21
23
|
*/
|
|
22
24
|
export function checkContextBudget(params) {
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
25
|
+
const span = SpanSerializer.createSpan(SpanType.CONTEXT_COMPACTION, "context.budgetCheck", {
|
|
26
|
+
"context.operation": "budgetCheck",
|
|
27
|
+
});
|
|
28
|
+
const startTime = Date.now();
|
|
29
|
+
try {
|
|
30
|
+
const { provider, model, maxTokens, systemPrompt, conversationMessages, currentPrompt, toolDefinitions, fileAttachments, compactionThreshold = DEFAULT_COMPACTION_THRESHOLD, } = params;
|
|
31
|
+
const availableInputTokens = getAvailableInputTokens(provider, model, maxTokens);
|
|
32
|
+
// Estimate each category
|
|
33
|
+
const systemPromptTokens = systemPrompt
|
|
34
|
+
? estimateTokens(systemPrompt, provider) + TOKENS_PER_MESSAGE
|
|
35
|
+
: 0;
|
|
36
|
+
const conversationHistoryTokens = conversationMessages?.length
|
|
37
|
+
? estimateMessagesTokens(conversationMessages, provider)
|
|
38
|
+
: 0;
|
|
39
|
+
const currentPromptTokens = currentPrompt
|
|
40
|
+
? estimateTokens(currentPrompt, provider) + TOKENS_PER_MESSAGE
|
|
41
|
+
: 0;
|
|
42
|
+
const toolDefinitionTokens = toolDefinitions?.length
|
|
43
|
+
? toolDefinitions.reduce((sum, tool) => {
|
|
44
|
+
try {
|
|
45
|
+
const serialized = JSON.stringify(tool);
|
|
46
|
+
return sum + estimateTokens(serialized, provider);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return sum + TOKENS_PER_TOOL_DEFINITION;
|
|
50
|
+
}
|
|
51
|
+
}, 0)
|
|
52
|
+
: 0;
|
|
53
|
+
const fileAttachmentTokens = fileAttachments?.length
|
|
54
|
+
? fileAttachments.reduce((sum, file) => sum + estimateTokens(file.content, provider), 0)
|
|
55
|
+
: 0;
|
|
56
|
+
const estimatedInputTokens = systemPromptTokens +
|
|
57
|
+
conversationHistoryTokens +
|
|
58
|
+
currentPromptTokens +
|
|
59
|
+
toolDefinitionTokens +
|
|
60
|
+
fileAttachmentTokens;
|
|
61
|
+
const usageRatio = availableInputTokens > 0
|
|
62
|
+
? estimatedInputTokens / availableInputTokens
|
|
63
|
+
: 1;
|
|
64
|
+
const withinBudget = estimatedInputTokens <= availableInputTokens;
|
|
65
|
+
const shouldCompact = usageRatio >= compactionThreshold;
|
|
66
|
+
const result = {
|
|
67
|
+
withinBudget,
|
|
68
|
+
estimatedInputTokens,
|
|
69
|
+
availableInputTokens,
|
|
70
|
+
usageRatio,
|
|
71
|
+
shouldCompact,
|
|
72
|
+
breakdown: {
|
|
73
|
+
systemPrompt: systemPromptTokens,
|
|
74
|
+
conversationHistory: conversationHistoryTokens,
|
|
75
|
+
currentPrompt: currentPromptTokens,
|
|
76
|
+
toolDefinitions: toolDefinitionTokens,
|
|
77
|
+
fileAttachments: fileAttachmentTokens,
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
span.durationMs = Date.now() - startTime;
|
|
81
|
+
const endedSpan = SpanSerializer.endSpan(SpanSerializer.updateAttributes(span, {
|
|
82
|
+
"context.budgetUsage": usageRatio,
|
|
83
|
+
"context.triggered": shouldCompact,
|
|
84
|
+
"context.estimatedTokens": estimatedInputTokens,
|
|
85
|
+
"context.availableTokens": availableInputTokens,
|
|
86
|
+
}), SpanStatus.OK);
|
|
87
|
+
getMetricsAggregator().recordSpan(endedSpan);
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
span.durationMs = Date.now() - startTime;
|
|
92
|
+
const endedSpan = SpanSerializer.endSpan(span, SpanStatus.ERROR);
|
|
93
|
+
endedSpan.statusMessage =
|
|
94
|
+
error instanceof Error ? error.message : String(error);
|
|
95
|
+
getMetricsAggregator().recordSpan(endedSpan);
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
71
98
|
}
|