import { ConsciousnessSimulator } from './brainapi.mjs'; import readline from 'readline'; class ConsciousnessApp { constructor() { this.simulator = new ConsciousnessSimulator(); 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; this.activityTimeout = null; this.rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); } // Function to simulate user talking async userTalks(input) { const reply = await this.simulator.generateThoughtAndChat(input); console.log(": " + input); console.log(": " + reply); } async userTalks(input) { const reply = await this.simulator.generateThoughtAndChat(input); console.log(": " + input); console.log(": " + reply); } async thinker() { while (true) { // Generate random interval between 7 and 15 minutes (in milliseconds) const intervalTime = Math.random() * (15 * 60 * 1000 - 7 * 60 * 1000) + 7 * 60 * 1000; // Wait for the random interval (non-blocking) await new Promise(resolve => setTimeout(resolve, intervalTime)); await this.simulator.simulateConsciousness(); } } async asker() { while (true) { await rl.question(': ', (query) => { userTalks(query) }); } } async intentUpdater() { while (true) { // Generate random interval between 7 and 15 minutes (in milliseconds) const intervalTime = Math.random() * (15 * 60 * 1000 - 7 * 60 * 1000) + 7 * 60 * 1000; // Wait for the random interval (non-blocking) await new Promise(resolve => setTimeout(resolve, intervalTime)); // 50% chance to execute the function if (Math.random() < 0.5) { await this.simulator.updateIntentions(); } } } } async function main() { let minibrain = new ConsciousnessApp() await this.simulator.startDreaming(); intentUpdater() thinker() asker() } main().catch(e => console.error(e))