Update brain.mjs
This commit is contained in:
parent
33cdc3c565
commit
9aab5125ce
1 changed files with 20 additions and 5 deletions
25
brain.mjs
25
brain.mjs
|
@ -4,7 +4,7 @@ import readline from 'readline';
|
||||||
class ConsciousnessApp {
|
class ConsciousnessApp {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.simulator = new ConsciousnessSimulator();
|
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.isActive = true; // User starts active
|
||||||
this.lastActiveTime = Date.now();
|
this.lastActiveTime = Date.now();
|
||||||
this.dreamTimeout = null;
|
this.dreamTimeout = null;
|
||||||
|
@ -33,13 +33,25 @@ class ConsciousnessApp {
|
||||||
|
|
||||||
// Function to handle activity check
|
// Function to handle activity check
|
||||||
handleActivity() {
|
handleActivity() {
|
||||||
this.lastActiveTime = Date.now();
|
const currentTime = Date.now();
|
||||||
if (!this.isActive) {
|
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;
|
this.isActive = true;
|
||||||
console.log("User is active again. Waking up from dream...");
|
console.log("User is active again. Waking up from dream...");
|
||||||
this.simulator.setUserActive(true); // Wake up from dreaming
|
this.simulator.setUserActive(true); // Wake up from dreaming
|
||||||
clearTimeout(this.dreamTimeout); // Cancel dream timeout
|
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
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue