brainy/.recovery-workspace/dist-backup-20250910-141917/utils/adaptiveSocketManager.d.ts
David Snelling 8ff382ca3b chore: recovery checkpoint - v3.0 API successfully recovered
CRITICAL CHECKPOINT - DO NOT PUSH TO GITHUB

Recovery Status:
- Successfully recovered brainy.ts from compiled JavaScript
- All core v3.0 API methods functional (add, get, update, delete, relate, find, etc.)
- Neural subsystem intact (562KB embedded patterns, NLP working)
- Augmentation pipeline operational (20+ augmentations)
- HNSW clustering system complete
- Triple Intelligence compiled (needs constructor fix)
- Test suite validates functionality

Changes preserved:
- 898 files with changes from last 3 days
- 144,475 insertions
- All augmentation improvements
- All test coverage enhancements
- Complete v3.0 feature set

This is a LOCAL checkpoint only - contains recovered work after corruption incident.
Created backup in .backups/brainy-full-20250910-151314.tar.gz

Branch: recovery-checkpoint-20250910-151433
Date: Wed Sep 10 03:18:04 PM PDT 2025
2025-09-10 15:18:04 -07:00

117 lines
2.9 KiB
TypeScript

/**
* Adaptive Socket Manager
* Automatically manages socket pools and connection settings based on load patterns
* Zero-configuration approach that learns and adapts to workload characteristics
*/
import { NodeHttpHandler } from '@smithy/node-http-handler';
interface LoadMetrics {
requestsPerSecond: number;
pendingRequests: number;
socketUtilization: number;
errorRate: number;
latencyP50: number;
latencyP95: number;
memoryUsage: number;
}
interface AdaptiveConfig {
maxSockets: number;
maxFreeSockets: number;
keepAliveTimeout: number;
connectionTimeout: number;
socketTimeout: number;
batchSize: number;
}
/**
* Adaptive Socket Manager that automatically scales based on load patterns
*/
export declare class AdaptiveSocketManager {
private logger;
private config;
private metrics;
private history;
private maxHistorySize;
private lastAdaptationTime;
private adaptationInterval;
private consecutiveHighLoad;
private consecutiveLowLoad;
private requestStartTimes;
private requestLatencies;
private errorCount;
private successCount;
private lastMetricReset;
private currentAgent;
private currentHandler;
/**
* Get or create an optimized HTTP handler
*/
getHttpHandler(): NodeHttpHandler;
/**
* Get current batch size recommendation
*/
getBatchSize(): number;
/**
* Track request start
*/
trackRequestStart(requestId: string): void;
/**
* Track request completion
*/
trackRequestComplete(requestId: string, success: boolean): void;
/**
* Check if we should adapt configuration
*/
private adaptIfNeeded;
/**
* Update current metrics
*/
private updateMetrics;
/**
* Analyze metrics and adapt configuration
*/
private analyzeAndAdapt;
/**
* Detect high load conditions
*/
private detectHighLoad;
/**
* Detect low load conditions
*/
private detectLowLoad;
/**
* Scale up resources for high load
*/
private scaleUp;
/**
* Scale down resources for low load
*/
private scaleDown;
/**
* Handle error conditions by adjusting configuration
*/
private handleErrors;
/**
* Check if we should recreate the handler
*/
private shouldRecreateHandler;
/**
* Get current configuration (for monitoring)
*/
getConfig(): Readonly<AdaptiveConfig>;
/**
* Get current metrics (for monitoring)
*/
getMetrics(): Readonly<LoadMetrics>;
/**
* Predict optimal configuration based on historical data
*/
predictOptimalConfig(): AdaptiveConfig;
/**
* Reset to default configuration
*/
reset(): void;
}
/**
* Get the global socket manager instance
*/
export declare function getGlobalSocketManager(): AdaptiveSocketManager;
export {};