UNPKG

@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

256 lines 9.97 kB
/** * Unified Database Manager - Single Source of Truth * * Consolidates all 6 separate SQLite databases into one normalized database * with proper referential integrity and ACID compliance. */ import { Database } from 'sqlite'; /** * Initialize the unified database with complete normalized schema * Uses singleton pattern to prevent multiple initializations */ export declare function initializeUnifiedDatabase(): Promise<boolean>; /** * Get current OpenRouter ID for a model by internal ID (bulletproof lookup) */ export declare function getCurrentModelId(internalId: number): Promise<string | null>; /** * Intelligent OpenRouter sync that handles model ID changes bulletproof */ export declare function syncOpenRouterModelsWithMigration(modelsData: any[]): Promise<{ added: number; updated: number; idChanged: number; deactivated: number; }>; /** * Enhanced sync with OpenRouter intelligence integration * Combines model sync with ranking intelligence for complete ecosystem awareness */ export declare function syncOpenRouterWithIntelligence(): Promise<{ modelChanges: any; rankingStats: any; success: boolean; }>; /** * Check if OpenRouter intelligence data needs refresh * Triggers sync if data is older than 24 hours or on first run */ export declare function checkIntelligenceRefresh(): Promise<boolean>; /** * Get database connection */ export declare function getDatabase(): Promise<Database>; /** * CONFIGURATION FUNCTIONS */ export declare function setConfig(key: string, value: string, encrypted?: boolean, userId?: string): Promise<void>; export declare function getConfig(key: string): Promise<string | null>; /** * USER MANAGEMENT FUNCTIONS */ export declare function createUser(id: string, email?: string, licenseKey?: string, tier?: string): Promise<void>; export declare function getUser(id: string): Promise<any>; /** * OPENROUTER FUNCTIONS */ export declare function saveOpenRouterApiKey(apiKey: string): Promise<void>; export declare function getOpenRouterApiKey(): Promise<string | null>; export declare function validateOpenRouterApiKey(apiKey: string): boolean; /** * Test if the OpenRouter API key actually works by making a real API call */ export declare function testOpenRouterApiKeyAuthentication(apiKey?: string): Promise<{ valid: boolean; error?: string; }>; /** * LICENSE FUNCTIONS */ export declare function saveLicenseKeyToDB(licenseKey: string, email?: string): Promise<void>; export declare function getLicenseKeyFromDB(): Promise<string | null>; export declare function getUserTier(licenseKey?: string | null): Promise<string>; /** * Get current user ID based on license key */ export declare function getCurrentUserId(licenseKey?: string | null): Promise<string | null>; /** * USAGE TRACKING FUNCTIONS */ export declare function getTierLimits(): { [key: string]: number; }; export declare function checkDailyUsageLimit(licenseKey?: string): Promise<{ allowed: boolean; used: number; limit: number; tier: string; }>; export declare function recordCompletedConversation(conversationId: string): Promise<void>; /** * CONSENSUS PROFILE FUNCTIONS */ export declare function createConsensusProfile(id: string, profileName: string, generatorModel: string, refinerModel: string, validatorModel: string, curatorModel: string): Promise<string>; export declare function getAllConsensusProfiles(): Promise<any[]>; export declare function getActiveConsensusProfile(): Promise<any>; export declare function setActiveConsensusProfile(profileId: string): Promise<void>; /** * CONVERSATION FUNCTIONS */ export declare function createConversation(id: string, userId?: string, consensusProfileId?: string): Promise<string>; export declare function addMessage(messageId: string, conversationId: string, role: string, content: string, stage?: string, modelUsed?: string): Promise<string>; export declare function updateConversationUsage(conversationId: string, usage: { total_cost?: number; input_tokens?: number; output_tokens?: number; start_time?: string; end_time?: string; success_rate?: string; quality_score?: number; consensus_improvement?: number; confidence_level?: string; success?: number; }): Promise<void>; export declare function getConversationHistory(conversationId: string, limit?: number): Promise<any[]>; /** * PENDING SYNC MANAGEMENT FUNCTIONS * For tracking conversations awaiting server verification */ export declare function addToPendingSync(conversationId: string, userId: string, questionHash: string, conversationToken: string): Promise<void>; export declare function markSyncComplete(conversationId: string): Promise<void>; export declare function recordSyncAttempt(conversationId: string, errorMessage?: string): Promise<void>; export declare function getPendingSyncItems(limit?: number): Promise<any[]>; export declare function clearPendingSyncData(userId?: string): Promise<void>; /** * Pipeline Profile Management */ export interface PipelineProfile { id: string; name: string; user_id?: string; is_default: boolean; generator_model_internal_id: number; generator_temperature: number; refiner_model_internal_id: number; refiner_temperature: number; validator_model_internal_id: number; validator_temperature: number; curator_model_internal_id: number; curator_temperature: number; generator_provider?: string; generator_model?: string; refiner_provider?: string; refiner_model?: string; validator_provider?: string; validator_model?: string; curator_provider?: string; curator_model?: string; created_at: string; updated_at: string; } /** * Create pipeline profile using internal_ids directly (bulletproof method) */ export declare function createPipelineProfileWithInternalIds(name: string, generatorInternalId: number, generatorTemp: number, refinerInternalId: number, refinerTemp: number, validatorInternalId: number, validatorTemp: number, curatorInternalId: number, curatorTemp: number, userId?: string): Promise<PipelineProfile>; export declare function createPipelineProfile(name: string, generatorProvider: string, generatorModel: string, generatorTemp: number, refinerProvider: string, refinerModel: string, refinerTemp: number, validatorProvider: string, validatorModel: string, validatorTemp: number, curatorProvider: string, curatorModel: string, curatorTemp: number, userId?: string): Promise<PipelineProfile>; export declare function getAllPipelineProfiles(): Promise<PipelineProfile[]>; export declare function getPipelineProfile(identifier: string): Promise<PipelineProfile | null>; export declare function setDefaultPipelineProfile(identifier: string): Promise<boolean>; export declare function getDefaultPipelineProfile(): Promise<PipelineProfile | null>; export declare function deletePipelineProfile(identifier: string): Promise<boolean>; /** * Clean up all old-format profiles (those not using internal IDs) */ export declare function cleanupOldProfiles(): Promise<number>; /** * Ensure only expert profiles are available */ export declare function enforceExpertProfilesOnly(): Promise<void>; /** * Enhanced Analytics Storage Functions * Comprehensive analytics functions to utilize the full unified database schema */ /** * Store comprehensive cost analytics for a conversation */ export declare function storeCostAnalytics(conversationId: string, costData: { total_cost: number; cost_per_stage: string; tokens_per_stage: string; routing_optimizations: string; budget_threshold?: number | null; budget_utilized_percentage?: number | null; cost_efficiency_score: number; optimization_opportunities: string; provider_breakdown: string; savings_achieved: number; }): Promise<void>; /** * Store performance metrics for analytics and monitoring */ export declare function storePerformanceMetrics(conversationId: string, metricsData: { total_duration: number; overall_efficiency: number; openrouter_latency: number; memory_usage: number; total_cost: number; quality_score: number; metrics_data: string; }): Promise<void>; /** * Store feature usage analytics */ export declare function storeFeatureUsage(conversationId: string, featureData: { features_used: string; routing_variants_used: string; fallback_events: number; provider_switches: number; rate_limit_hits: number; error_recoveries: number; performance_metrics: string; advanced_features_used: string; cost_optimizations_applied: string; }): Promise<void>; /** * Log activity events for real-time tracking */ export declare function logActivity(eventType: string, eventData: any): Promise<void>; /** * Get model internal ID for cost calculations */ export declare function getModelInternalId(modelId: string): Promise<number | undefined>; /** * Calculate model cost based on usage and pricing */ export declare function calculateModelCost(modelInternalId: number, promptTokens: number, completionTokens: number): Promise<number>; /** * Get comprehensive analytics for timeframe */ export declare function getComprehensiveAnalytics(timeframe?: string): Promise<{ costAnalytics: any[]; performanceMetrics: any[]; featureUsage: any[]; activityLog: any[]; }>; /** * Get analytics summary for dashboard */ export declare function getAnalyticsSummary(timeframe?: string): Promise<{ totalConversations: number; totalCost: number; averageQuality: number; errorRate: number; averageDuration: number; topModels: Array<{ model: string; usage_count: number; }>; costTrend: string; qualityTrend: string; }>; /** * Close database connection */ export declare function closeUnifiedDatabase(): Promise<void>; export declare const initializeDatabase: typeof initializeUnifiedDatabase; //# sourceMappingURL=unified-database.d.ts.map