@juspay/neurolink
Version:
Universal AI Development Platform with working MCP integration, multi-provider support, voice (TTS/STT/realtime), and professional CLI. 58+ external MCP servers discoverable, multimodal file processing, RAG pipelines. Build, test, and deploy AI applicatio
53 lines (52 loc) • 2.22 kB
TypeScript
/**
* File Token Budget System
*
* Calculates how much of the remaining context window budget
* can be used for file reads. Implements fast-path for small files
* and preview mode for very large files.
*/
import type { BudgetFileInput } from "../types/index.js";
/** Percentage of remaining context to allocate for file reads */
export declare const FILE_READ_BUDGET_PERCENT = 0.6;
/** Files below this size skip budget validation (100KB) */
export declare const FILE_FAST_PATH_SIZE: number;
/** Files above this size get preview-only mode (5MB) */
export declare const FILE_PREVIEW_MODE_SIZE: number;
/** Default preview size in characters */
export declare const FILE_PREVIEW_CHARS = 2000;
/**
* Calculate available token budget for file reads.
*
* @param contextWindow - Total context window for the model
* @param currentTokens - Tokens already used (conversation + system prompt)
* @param maxOutputTokens - Reserved output tokens
* @returns Available tokens for file content
*/
export declare function calculateFileTokenBudget(contextWindow: number, currentTokens: number, maxOutputTokens: number): number;
/**
* Determine how a file should be handled based on its size and the budget.
*/
export declare function shouldTruncateFile(fileSize: number, budget: number): {
shouldTruncate: boolean;
maxChars?: number;
previewMode?: boolean;
};
/**
* Estimate post-processing token count based on file type.
*
* Different file types produce vastly different amounts of text after
* processing. A 50 MB video file yields ~200-500 tokens of metadata,
* while a 50 MB text file yields ~12.5 M tokens. Using the raw byte
* size for all types causes media files to be wrongly excluded by the
* aggregate budget check.
*
* @param sizeBytes Raw file size in bytes
* @param fileType Detected file type (e.g. "video", "audio", "image")
* @returns Estimated token count after processing
*/
export declare function estimatePostProcessingTokens(sizeBytes: number, fileType?: string): number;
export declare function enforceAggregateFileBudget(files: BudgetFileInput[], availableTokens: number): {
included: BudgetFileInput[];
excluded: BudgetFileInput[];
notices: string[];
};