@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
367 lines (366 loc) • 13.4 kB
TypeScript
/**
* Performance and Resource Constants for NeuroLink
*
* Centralized performance configuration to replace magic numbers throughout the codebase.
* Includes memory thresholds, concurrency limits, buffer sizes, and cache configurations.
*
* @fileoverview Performance constants for optimal resource utilization
* @author NeuroLink Team
* @version 1.0.0
*/
/**
* Unit conversion constants
* Common conversion factors to replace magic numbers
*/
export declare const UNIT_CONVERSIONS: {
/** Conversion factor from nanoseconds to milliseconds */
readonly NANOSECOND_TO_MS_DIVISOR: 1000000;
/** Conversion factor from microseconds to milliseconds */
readonly MICROSECOND_TO_MS_DIVISOR: 1000;
/** Conversion factor from seconds to milliseconds */
readonly SECOND_TO_MS_MULTIPLIER: 1000;
/** Conversion factor from minutes to milliseconds */
readonly MINUTE_TO_MS_MULTIPLIER: 60000;
/** Conversion factor from hours to milliseconds */
readonly HOUR_TO_MS_MULTIPLIER: 3600000;
};
/**
* Text processing constants
* Standard lengths for text preview, logging, and truncation
*/
export declare const TEXT_PREVIEW_LENGTHS: {
/** Very short preview for debugging */
readonly VERY_SHORT: 50;
/** Short preview for compact logging */
readonly SHORT: 100;
/** Medium preview for standard logging */
readonly MEDIUM: 150;
/** Standard preview length */
readonly STANDARD: 200;
/** Long preview for detailed context */
readonly LONG: 300;
/** Extra long preview for comprehensive view */
readonly EXTRA_LONG: 500;
/** Maximum preview length before truncation */
readonly MAX_PREVIEW: 1000;
};
/**
* Performance thresholds for various operations
* Unified thresholds to replace scattered magic numbers
*/
export declare const PERFORMANCE_THRESHOLDS: {
/** Success rate threshold for tool reliability */
readonly SUCCESS_RATE_THRESHOLD: 0.8;
/** High success rate threshold */
readonly HIGH_SUCCESS_RATE: 0.95;
/** Low success rate warning threshold */
readonly LOW_SUCCESS_RATE_WARNING: 0.6;
/** Critical success rate threshold */
readonly CRITICAL_SUCCESS_RATE: 0.5;
/** Tool execution time warning threshold (ms) */
readonly TOOL_EXECUTION_WARNING_MS: 10000;
/** Large tool collection threshold */
readonly LARGE_TOOL_COLLECTION: 100;
/** Circuit breaker failure threshold */
readonly CIRCUIT_BREAKER_FAILURES: 5;
/** Circuit breaker reset timeout (ms) */
readonly CIRCUIT_BREAKER_RESET_MS: 60000;
};
/**
* Memory threshold configuration
* Thresholds for monitoring and alerting on memory usage
*/
export declare const MEMORY_THRESHOLDS: {
/** Warning threshold for general memory usage */
readonly WARNING_MB: 100;
/** Critical threshold requiring immediate attention */
readonly CRITICAL_MB: 200;
/** Tool-specific memory warning threshold */
readonly TOOL_WARNING_MB: 20;
/** Tool critical memory threshold */
readonly TOOL_CRITICAL_MB: 50;
/** Memory leak detection threshold */
readonly LEAK_DETECTION_MB: 300;
/** Maximum allowed memory before forced cleanup */
readonly MAX_ALLOWED_MB: 500;
/** Heap growth rate warning (MB per minute) */
readonly GROWTH_RATE_WARNING_MB_PER_MIN: 10;
/** Moderate memory usage threshold */
readonly MODERATE_USAGE_MB: 30;
/** Low memory usage threshold */
readonly LOW_USAGE_MB: 10;
/** Moderate memory delta threshold for operations */
readonly OPERATION_MODERATE_MB: 30;
/** Small memory delta threshold for operations */
readonly OPERATION_SMALL_MB: 10;
/** Large memory delta threshold requiring GC */
readonly OPERATION_LARGE_MB: 50;
};
/**
* Response time threshold configuration
* Defines what constitutes fast, acceptable, and slow response times
*/
export declare const RESPONSE_TIME_THRESHOLDS: {
/** Fast response time - excellent performance */
readonly FAST_MS: 1000;
/** Acceptable response time - good performance */
readonly ACCEPTABLE_MS: 5000;
/** Slow response time - needs optimization */
readonly SLOW_MS: 10000;
/** Critical response time - unacceptable */
readonly CRITICAL_MS: 30000;
/** Tool execution fast threshold */
readonly TOOL_FAST_MS: 2000;
/** Tool execution slow threshold */
readonly TOOL_SLOW_MS: 15000;
/** Provider response fast threshold */
readonly PROVIDER_FAST_MS: 3000;
/** Provider response slow threshold */
readonly PROVIDER_SLOW_MS: 20000;
};
/**
* Concurrency limit configuration
* Controls parallel execution to prevent resource exhaustion
*/
export declare const CONCURRENCY_LIMITS: {
/** Default concurrent operations */
readonly DEFAULT: 5;
/** High-load scenario concurrency */
readonly HIGH_LOAD: 10;
/** Low-resource environment concurrency */
readonly LOW_RESOURCE: 2;
/** Provider-specific concurrency */
readonly PROVIDER: 3;
/** Tool execution concurrency */
readonly TOOL_EXECUTION: 4;
/** MCP server concurrency */
readonly MCP_SERVER: 8;
/** Network request concurrency */
readonly NETWORK_REQUEST: 6;
/** Maximum concurrent streams */
readonly MAX_STREAMS: 3;
/** Database operation concurrency */
readonly DATABASE: 5;
};
/**
* Buffer size configuration
* Optimized buffer sizes for different types of operations
*/
export declare const BUFFER_SIZES: {
/** Small buffer for lightweight operations */
readonly SMALL_BYTES: 1024;
/** Standard buffer for most operations */
readonly STANDARD_BYTES: 4096;
/** Large buffer for heavy operations */
readonly LARGE_BYTES: 8192;
/** Extra large buffer for file operations */
readonly XLARGE_BYTES: 16384;
/** Memory buffer for streaming */
readonly STREAM_BYTES: 2048;
/** Network buffer size */
readonly NETWORK_BYTES: 4096;
/** File I/O buffer size */
readonly FILE_IO_BYTES: 8192;
/** Maximum single buffer size */
readonly MAX_BYTES: 32768;
};
/**
* Cache configuration
* Size limits and policies for various cache types
*/
export declare const CACHE_CONFIG: {
/** Small cache for frequently accessed items */
readonly SMALL_SIZE: 100;
/** Default cache size for most use cases */
readonly DEFAULT_SIZE: 1000;
/** Large cache for extensive data */
readonly LARGE_SIZE: 10000;
/** Provider cache size */
readonly PROVIDER_CACHE_SIZE: 500;
/** Tool registry cache size */
readonly TOOL_REGISTRY_SIZE: 200;
/** Model configuration cache */
readonly MODEL_CONFIG_SIZE: 50;
/** Session cache size */
readonly SESSION_CACHE_SIZE: 1000;
/** Maximum cache size */
readonly MAX_SIZE: 50000;
/** Cache TTL in milliseconds */
readonly DEFAULT_TTL_MS: 300000;
/** Short TTL for volatile data */
readonly SHORT_TTL_MS: 60000;
/** Long TTL for stable data */
readonly LONG_TTL_MS: 3600000;
};
/**
* Resource monitoring configuration
* Intervals and thresholds for monitoring system resources
*/
export declare const MONITORING_CONFIG: {
/** Default monitoring interval */
readonly DEFAULT_INTERVAL_MS: 30000;
/** High-frequency monitoring interval */
readonly HIGH_FREQ_INTERVAL_MS: 5000;
/** Low-frequency monitoring interval */
readonly LOW_FREQ_INTERVAL_MS: 60000;
/** Memory check interval */
readonly MEMORY_CHECK_INTERVAL_MS: 15000;
/** Performance metrics collection interval */
readonly METRICS_INTERVAL_MS: 10000;
/** Health check interval */
readonly HEALTH_CHECK_INTERVAL_MS: 30000;
/** CPU usage check interval */
readonly CPU_CHECK_INTERVAL_MS: 20000;
/** Disk usage check interval */
readonly DISK_CHECK_INTERVAL_MS: 120000;
};
/**
* Performance optimization thresholds
* Values that trigger performance optimization actions
*/
export declare const OPTIMIZATION_THRESHOLDS: {
/** CPU usage threshold for optimization */
readonly CPU_USAGE_PERCENT: 80;
/** Memory usage threshold for cleanup */
readonly MEMORY_CLEANUP_PERCENT: 85;
/** Disk usage threshold for cleanup */
readonly DISK_CLEANUP_PERCENT: 90;
/** Connection pool optimization threshold */
readonly CONNECTION_POOL_PERCENT: 75;
/** Cache hit rate minimum threshold */
readonly CACHE_HIT_RATE_MIN_PERCENT: 60;
/** Queue length threshold for scaling */
readonly QUEUE_LENGTH_THRESHOLD: 50;
/** Error rate threshold for intervention */
readonly ERROR_RATE_THRESHOLD_PERCENT: 5;
};
/**
* Garbage collection configuration
* Settings for automatic resource cleanup
*/
export declare const GC_CONFIG: {
/** Memory threshold for forced GC */
readonly FORCE_GC_THRESHOLD_MB: 400;
/** Interval for automatic GC checks */
readonly AUTO_GC_INTERVAL_MS: 120000;
/** Memory growth rate for GC trigger */
readonly GC_TRIGGER_GROWTH_MB: 50;
/** Cache cleanup interval */
readonly CACHE_CLEANUP_INTERVAL_MS: 300000;
/** Temporary file cleanup interval */
readonly TEMP_FILE_CLEANUP_MS: 600000;
/** Log rotation threshold */
readonly LOG_ROTATION_SIZE_MB: 100;
};
/**
* Server configuration constants
* Default configurations for various server types
*/
export declare const SERVER_CONFIG: {
/** Maximum number of MCP servers */
readonly MAX_MCP_SERVERS: 20;
/** Default Ollama port */
readonly DEFAULT_OLLAMA_PORT: 11434;
/** Maximum number of event handlers */
readonly MAX_EVENT_HANDLERS: 5;
/** Default server startup timeout */
readonly STARTUP_TIMEOUT_MS: 15000;
/** Provider test timeout */
readonly PROVIDER_TEST_TIMEOUT_MS: 5000;
/** MCP connection test timeout */
readonly MCP_CONNECTION_TEST_TIMEOUT_MS: 10000;
/** External tool execution timeout */
readonly EXTERNAL_TOOL_TIMEOUT_MS: 30000;
};
/**
* Performance utility functions
*/
export declare const PerformanceUtils: {
/**
* Get appropriate concurrency limit based on available resources
* @param resourceLevel - Resource availability level (low, medium, high)
* @returns Recommended concurrency limit
*/
readonly getConcurrencyLimit: (resourceLevel?: "low" | "medium" | "high") => number;
/**
* Get appropriate buffer size for operation type
* @param operationType - Type of operation (network, file, stream, etc.)
* @returns Recommended buffer size in bytes
*/
readonly getBufferSize: (operationType?: "network" | "file" | "stream" | "standard") => number;
/**
* Get cache configuration for specific use case
* @param useCase - Cache use case (provider, tool, model, session)
* @returns Cache configuration object
*/
readonly getCacheConfig: (useCase?: "provider" | "tool" | "model" | "session" | "default") => {
ttl: 300000;
maxSize: 1000;
} | {
maxSize: 500;
ttl: 300000;
} | {
maxSize: 200;
ttl: 300000;
} | {
maxSize: 50;
ttl: 3600000;
} | {
maxSize: 1000;
ttl: 60000;
};
/**
* Check if memory usage exceeds threshold
* @param currentUsageMB - Current memory usage in MB
* @param threshold - Threshold type to check against
* @returns True if threshold is exceeded
*/
readonly isMemoryThresholdExceeded: (currentUsageMB: number, threshold?: "warning" | "critical" | "tool" | "leak") => boolean;
/**
* Categorize response time performance
* @param responseTimeMs - Response time in milliseconds
* @returns Performance category
*/
readonly categorizeResponseTime: (responseTimeMs: number) => "fast" | "acceptable" | "slow" | "critical";
};
export declare const HIGH_MEMORY_THRESHOLD: 100;
export declare const DEFAULT_CONCURRENCY_LIMIT: 5;
export declare const MAX_CONCURRENCY_LIMIT: 10;
export declare const SMALL_BUFFER_SIZE: 1024;
export declare const LARGE_BUFFER_SIZE: 8192;
export declare const DEFAULT_CACHE_SIZE: 1000;
export declare const NANOSECOND_TO_MS_DIVISOR: 1000000;
export declare const TEXT_PREVIEW_LENGTHS_EXPORT: {
/** Very short preview for debugging */
readonly VERY_SHORT: 50;
/** Short preview for compact logging */
readonly SHORT: 100;
/** Medium preview for standard logging */
readonly MEDIUM: 150;
/** Standard preview length */
readonly STANDARD: 200;
/** Long preview for detailed context */
readonly LONG: 300;
/** Extra long preview for comprehensive view */
readonly EXTRA_LONG: 500;
/** Maximum preview length before truncation */
readonly MAX_PREVIEW: 1000;
};
export declare const PERFORMANCE_THRESHOLDS_EXPORT: {
/** Success rate threshold for tool reliability */
readonly SUCCESS_RATE_THRESHOLD: 0.8;
/** High success rate threshold */
readonly HIGH_SUCCESS_RATE: 0.95;
/** Low success rate warning threshold */
readonly LOW_SUCCESS_RATE_WARNING: 0.6;
/** Critical success rate threshold */
readonly CRITICAL_SUCCESS_RATE: 0.5;
/** Tool execution time warning threshold (ms) */
readonly TOOL_EXECUTION_WARNING_MS: 10000;
/** Large tool collection threshold */
readonly LARGE_TOOL_COLLECTION: 100;
/** Circuit breaker failure threshold */
readonly CIRCUIT_BREAKER_FAILURES: 5;
/** Circuit breaker reset timeout (ms) */
readonly CIRCUIT_BREAKER_RESET_MS: 60000;
};