@hivetechs/hive-ai
Version:
Real-time streaming AI consensus platform with HTTP+SSE MCP integration for Claude Code, VS Code, Cursor, and Windsurf - powered by OpenRouter's unified API
132 lines (131 loc) • 4.35 kB
TypeScript
/**
* Dynamic Model Selector - The Brain of Intelligent Consensus
*
* This is the intelligent engine that makes flagship profiles truly dynamic.
* It combines OpenRouter rankings, cost intelligence, performance metrics,
* and user preferences to select optimal models for each consensus stage.
*
* Features:
* - Real-time model selection based on current rankings
* - Cost-aware routing with budget optimization
* - Performance-based filtering and fallbacks
* - Stage-specific model optimization
* - Learning from user feedback and results
*/
export interface ModelSelectionCriteria {
stage: 'generator' | 'refiner' | 'validator' | 'curator';
questionComplexity: 'minimal' | 'basic' | 'production';
questionCategory: string;
budgetConstraints?: BudgetConstraints;
performanceTargets?: PerformanceTargets;
userPreferences?: UserPreferences;
profileTemplate?: string;
}
export interface BudgetConstraints {
maxCostPerStage?: number;
maxTotalCost?: number;
costEfficiencyTarget?: number;
prioritizeCost?: boolean;
}
export interface PerformanceTargets {
maxLatency?: number;
minSuccessRate?: number;
prioritizeSpeed?: boolean;
prioritizeQuality?: boolean;
}
export interface UserPreferences {
preferredProviders?: string[];
avoidedProviders?: string[];
preferredFeatures?: string[];
modelBlacklist?: string[];
}
export interface ModelCandidate {
internalId: number;
openrouterId: string;
provider: string;
rankPosition?: number;
relativeScore?: number;
estimatedCost: number;
estimatedLatency: number;
successRate: number;
features: string[];
contextWindow: number;
suitabilityScore: number;
}
export declare class DynamicModelSelector {
/**
* Master function: Select optimal model for a specific stage and criteria
*/
selectOptimalModel(criteria: ModelSelectionCriteria, conversationId?: string): Promise<ModelCandidate | null>;
/**
* Get complete model lineup for all 4 consensus stages
*/
selectCompleteLineup(questionComplexity: 'minimal' | 'basic' | 'production', questionCategory: string, options?: {
budgetConstraints?: BudgetConstraints;
performanceTargets?: PerformanceTargets;
userPreferences?: UserPreferences;
profileTemplate?: string;
}, conversationId?: string): Promise<{
generator: ModelCandidate;
refiner: ModelCandidate;
validator: ModelCandidate;
curator: ModelCandidate;
totalEstimatedCost: number;
selectionReasoning: string;
}>;
/**
* Get candidate models from rankings and database
*/
private getCandidateModels;
/**
* Apply filtering based on constraints
*/
private applyConstraintFiltering;
/**
* Score models based on suitability for the specific stage and criteria
*/
private scoreModelSuitability;
/**
* Calculate stage-specific scoring
*/
private calculateStageSpecificScore;
/**
* Get fallback model when selection fails
*/
private getFallbackModel;
/**
* Record model selection for learning and optimization
*/
private recordModelSelection;
/**
* Generate human-readable selection reasoning
*/
private generateSelectionReasoning;
}
/**
* Quick selection for a single stage
*/
export declare function selectModelForStage(stage: 'generator' | 'refiner' | 'validator' | 'curator', questionComplexity?: 'minimal' | 'basic' | 'production'): Promise<string | null>;
/**
* Quick lineup selection with cost limit
*/
export declare function selectBudgetOptimizedLineup(maxTotalCost: number, questionComplexity?: 'minimal' | 'basic' | 'production'): Promise<{
generator: ModelCandidate;
refiner: ModelCandidate;
validator: ModelCandidate;
curator: ModelCandidate;
totalEstimatedCost: number;
selectionReasoning: string;
}>;
/**
* Quick lineup selection optimized for speed
*/
export declare function selectSpeedOptimizedLineup(questionComplexity?: 'minimal' | 'basic' | 'production'): Promise<{
generator: ModelCandidate;
refiner: ModelCandidate;
validator: ModelCandidate;
curator: ModelCandidate;
totalEstimatedCost: number;
selectionReasoning: string;
}>;
export default DynamicModelSelector;