Spaces:
Running
Running
| // ===== KIMI APPLICATION HEALTH CHECK ===== | |
| // This script runs comprehensive checks to ensure the application is production-ready | |
| class KimiHealthCheck { | |
| constructor() { | |
| this.errors = []; | |
| this.warnings = []; | |
| this.passed = []; | |
| } | |
| checkDependencies() { | |
| const requiredGlobals = [ | |
| "KimiDatabase", | |
| "KimiLLMManager", | |
| "KimiVoiceManager", | |
| "KimiMemorySystem", | |
| "KimiMemory", | |
| "KimiEmotionSystem", | |
| "KimiAppearanceManager", | |
| "KimiVideoManager", | |
| "KimiI18nManager", | |
| "KimiErrorManager", | |
| "KimiDOMUtils", | |
| "KIMI_CHARACTERS", | |
| "KIMI_CONFIG", | |
| "DEFAULT_SYSTEM_PROMPT" | |
| ]; | |
| requiredGlobals.forEach(dep => { | |
| if (window[dep]) { | |
| this.passed.push(`β ${dep} available`); | |
| } else { | |
| this.errors.push(`β Missing dependency: ${dep}`); | |
| } | |
| }); | |
| } | |
| checkFunctions() { | |
| const requiredFunctions = [ | |
| "sendMessage", | |
| "analyzeAndReact", | |
| "addMessageToChat", | |
| "loadChatHistory", | |
| "loadSettingsData", | |
| "updatePersonalityTraitsFromEmotion", | |
| "kimiAnalyzeEmotion", | |
| "getPersonalityAverage" | |
| ]; | |
| requiredFunctions.forEach(fn => { | |
| if (window[fn] && typeof window[fn] === "function") { | |
| this.passed.push(`β Function ${fn} available`); | |
| } else { | |
| this.errors.push(`β Missing function: ${fn}`); | |
| } | |
| }); | |
| } | |
| checkDOMElements() { | |
| const requiredElements = [ | |
| "video1", | |
| "video2", | |
| "chat-container", | |
| "chat-input", | |
| "send-button", | |
| "settings-overlay", | |
| "memory-overlay" | |
| ]; | |
| requiredElements.forEach(id => { | |
| const element = document.getElementById(id); | |
| if (element) { | |
| this.passed.push(`β DOM element ${id} found`); | |
| } else { | |
| this.errors.push(`β Missing DOM element: ${id}`); | |
| } | |
| }); | |
| } | |
| checkConfiguration() { | |
| if (window.KIMI_CHARACTERS) { | |
| const characters = Object.keys(window.KIMI_CHARACTERS); | |
| if (characters.length > 0) { | |
| this.passed.push(`β ${characters.length} characters configured`); | |
| characters.forEach(char => { | |
| const character = window.KIMI_CHARACTERS[char]; | |
| if (character.traits && character.defaultPrompt) { | |
| this.passed.push(`β Character ${char} properly configured`); | |
| } else { | |
| this.warnings.push(`β οΈ Character ${char} missing traits or defaultPrompt`); | |
| } | |
| }); | |
| } else { | |
| this.errors.push(`β No characters configured`); | |
| } | |
| } | |
| } | |
| async checkDatabase() { | |
| try { | |
| if (window.kimiDB) { | |
| const testPref = await window.kimiDB.getPreference("healthCheck", "test"); | |
| if (testPref === "test") { | |
| this.passed.push(`β Database read/write working`); | |
| } | |
| const character = await window.kimiDB.getSelectedCharacter(); | |
| if (character) { | |
| this.passed.push(`β Character selection working: ${character}`); | |
| } | |
| } else { | |
| this.errors.push(`β Database not initialized`); | |
| } | |
| } catch (error) { | |
| this.errors.push(`β Database error: ${error.message}`); | |
| } | |
| } | |
| checkMemorySystem() { | |
| if (window.kimiMemorySystem) { | |
| if (window.kimiMemorySystem.db) { | |
| this.passed.push(`β Memory system initialized`); | |
| } else { | |
| this.warnings.push(`β οΈ Memory system not connected to database`); | |
| } | |
| } else { | |
| this.errors.push(`β Memory system not available`); | |
| } | |
| } | |
| async runAllChecks() { | |
| console.log("π Running Kimi Health Checks..."); | |
| this.checkDependencies(); | |
| this.checkFunctions(); | |
| this.checkDOMElements(); | |
| this.checkConfiguration(); | |
| await this.checkDatabase(); | |
| this.checkMemorySystem(); | |
| return this.generateReport(); | |
| } | |
| generateReport() { | |
| const report = { | |
| status: this.errors.length === 0 ? "HEALTHY" : "NEEDS_ATTENTION", | |
| totalChecks: this.passed.length + this.warnings.length + this.errors.length, | |
| passed: this.passed.length, | |
| warnings: this.warnings.length, | |
| errors: this.errors.length, | |
| details: { | |
| passed: this.passed, | |
| warnings: this.warnings, | |
| errors: this.errors | |
| } | |
| }; | |
| console.log(`\nπ HEALTH CHECK REPORT:`); | |
| console.log(`Status: ${report.status}`); | |
| console.log(`β Passed: ${report.passed}`); | |
| console.log(`β οΈ Warnings: ${report.warnings}`); | |
| console.log(`β Errors: ${report.errors}`); | |
| if (this.errors.length > 0) { | |
| console.log(`\nπ¨ CRITICAL ISSUES:`); | |
| this.errors.forEach(error => console.log(error)); | |
| } | |
| if (this.warnings.length > 0) { | |
| console.log(`\nβ οΈ WARNINGS:`); | |
| this.warnings.forEach(warning => console.log(warning)); | |
| } | |
| return report; | |
| } | |
| } | |
| // Auto-run health check when DOM is ready | |
| if (document.readyState === "loading") { | |
| document.addEventListener("DOMContentLoaded", async () => { | |
| await new Promise(resolve => setTimeout(resolve, 2000)); // Wait for initialization | |
| const healthCheck = new KimiHealthCheck(); | |
| const report = await healthCheck.runAllChecks(); | |
| window.KIMI_HEALTH_REPORT = report; | |
| }); | |
| } else { | |
| // DOM already loaded | |
| setTimeout(async () => { | |
| const healthCheck = new KimiHealthCheck(); | |
| const report = await healthCheck.runAllChecks(); | |
| window.KIMI_HEALTH_REPORT = report; | |
| }, 2000); | |
| } | |
| window.KimiHealthCheck = KimiHealthCheck; | |