diff --git a/brain.mjs b/brain.mjs index 64385d1..8a854cd 100644 --- a/brain.mjs +++ b/brain.mjs @@ -4,7 +4,7 @@ import readline from 'readline'; class ConsciousnessApp { constructor() { this.simulator = new ConsciousnessSimulator(); - this.ollama = this.simulator.createOllamaValue(); //init ollama @ baked-in localhost/default port + this.ollama = this.simulator.createOllamaValue("https://ollama-api.nodemixaholic.com"); // init ollama @ baked-in localhost/default port this.isActive = true; // User starts active this.lastActiveTime = Date.now(); this.dreamTimeout = null; @@ -33,13 +33,25 @@ class ConsciousnessApp { // Function to handle activity check handleActivity() { - this.lastActiveTime = Date.now(); - if (!this.isActive) { + const currentTime = Date.now(); + const elapsedTime = currentTime - this.lastActiveTime; + + // Check if it's been more than 15 minutes of inactivity + if (elapsedTime > (15 * 60 * 1000) && this.isActive) { + this.isActive = false; + console.log("No activity for 15 minutes. Entering dream state..."); + this.simulator.setUserActive(false); // Simulate dreaming + clearTimeout(this.dreamTimeout); // Cancel any existing timeout + this.startDreaming(); // Start dreaming state + } + + // If user becomes active again + if (this.isActive === false && elapsedTime < (15 * 60 * 1000)) { this.isActive = true; console.log("User is active again. Waking up from dream..."); this.simulator.setUserActive(true); // Wake up from dreaming clearTimeout(this.dreamTimeout); // Cancel dream timeout - this.initiateActivityRoutine(); // Start activity routines again + this.initiateActivityRoutine(); // Resume activity checks } } @@ -92,7 +104,10 @@ class ConsciousnessApp { }); this.handleActivity(); // Update activity when the user types - await this.userTalks(input); // App replies to user input + + if (input.trim() !== '') { // Only respond if the input is not empty + await this.userTalks(input); // App replies to user input + } } }