2023-12-21 15:11:38 -07:00
import { History } from './history.js' ;
import { Coder } from './coder.js' ;
2024-02-25 14:13:32 -06:00
import { Prompter } from './prompter.js' ;
2024-01-23 18:01:38 -06:00
import { initModes } from './modes.js' ;
2024-01-25 13:25:36 -08:00
import { initBot } from '../utils/mcdata.js' ;
2024-04-30 23:07:07 -05:00
import { containsCommand , commandExists , executeCommand , truncCommandMessage , isAction } from './commands/index.js' ;
2024-11-03 22:17:28 -06:00
import { ActionManager } from './action_manager.js' ;
2024-03-05 12:05:46 -08:00
import { NPCContoller } from './npc/controller.js' ;
2024-04-27 23:28:34 -05:00
import { MemoryBank } from './memory_bank.js' ;
2024-05-04 15:42:30 -05:00
import { SelfPrompter } from './self_prompter.js' ;
2024-11-22 14:53:25 -06:00
import { isOtherAgent , initConversationManager , sendToBot , endAllChats , responseScheduledFor } from './conversation.js' ;
2024-10-02 00:57:28 -05:00
import { handleTranslation , handleEnglishTranslation } from '../utils/translator.js' ;
2024-10-10 17:37:02 -05:00
import { addViewer } from './viewer.js' ;
import settings from '../../settings.js' ;
2024-11-18 23:02:37 -06:00
import { serverProxy } from './server_proxy.js' ;
2023-11-07 09:44:56 -06:00
export class Agent {
2024-10-10 17:37:02 -05:00
async start ( profile _fp , load _mem = false , init _message = null , count _id = 0 ) {
2024-11-18 23:02:37 -06:00
this . last _sender = null ;
2024-11-07 10:25:49 -06:00
try {
2024-11-07 10:48:45 -06:00
// Add validation for profile_fp
if ( ! profile _fp ) {
throw new Error ( 'No profile filepath provided' ) ;
}
2024-04-20 22:18:26 -05:00
2024-11-18 23:02:37 -06:00
// Connect to MindServer via proxy
serverProxy . connect ( ) ;
2024-11-07 10:48:45 -06:00
console . log ( 'Starting agent initialization with profile:' , profile _fp ) ;
// Initialize components with more detailed error handling
try {
console . log ( 'Initializing action manager...' ) ;
this . actions = new ActionManager ( this ) ;
console . log ( 'Initializing prompter...' ) ;
this . prompter = new Prompter ( this , profile _fp ) ;
this . name = this . prompter . getName ( ) ;
console . log ( 'Initializing history...' ) ;
this . history = new History ( this ) ;
console . log ( 'Initializing coder...' ) ;
this . coder = new Coder ( this ) ;
console . log ( 'Initializing npc controller...' ) ;
this . npc = new NPCContoller ( this ) ;
console . log ( 'Initializing memory bank...' ) ;
this . memory _bank = new MemoryBank ( ) ;
console . log ( 'Initializing self prompter...' ) ;
this . self _prompter = new SelfPrompter ( this ) ;
2024-11-07 13:30:02 -06:00
initConversationManager ( this ) ;
2024-11-18 23:02:37 -06:00
// After getting the name, register with MindServer via proxy
serverProxy . registerAgent ( this . name ) ;
2024-11-07 10:48:45 -06:00
} catch ( error ) {
throw new Error ( ` Failed to initialize agent components: ${ error . message || error } ` ) ;
}
2024-10-10 17:37:02 -05:00
2024-11-07 10:25:49 -06:00
try {
2024-11-07 10:48:45 -06:00
console . log ( 'Initializing examples...' ) ;
2024-11-07 10:25:49 -06:00
await this . prompter . initExamples ( ) ;
} catch ( error ) {
2024-11-07 10:48:45 -06:00
throw new Error ( ` Failed to initialize examples: ${ error . message || error } ` ) ;
2024-11-07 10:25:49 -06:00
}
2024-04-20 22:18:26 -05:00
2024-11-07 10:25:49 -06:00
console . log ( 'Logging into minecraft...' ) ;
try {
this . bot = initBot ( this . name ) ;
} catch ( error ) {
2024-11-07 10:48:45 -06:00
throw new Error ( ` Failed to initialize Minecraft bot: ${ error . message || error } ` ) ;
2024-11-07 10:25:49 -06:00
}
2024-01-30 16:43:30 -06:00
2024-11-07 10:25:49 -06:00
initModes ( this ) ;
2023-12-04 23:26:21 -08:00
2024-11-07 10:25:49 -06:00
let save _data = null ;
if ( load _mem ) {
try {
save _data = this . history . load ( ) ;
} catch ( error ) {
console . error ( 'Failed to load history:' , error ) ;
// Don't throw here, continue without history
}
}
2023-12-04 23:26:21 -08:00
2024-11-07 10:25:49 -06:00
// Return a promise that resolves when spawn is complete
return new Promise ( ( resolve , reject ) => {
// Add timeout to prevent hanging
const spawnTimeout = setTimeout ( ( ) => {
reject ( new Error ( 'Bot spawn timed out after 30 seconds' ) ) ;
} , 30000 ) ;
this . bot . once ( 'error' , ( error ) => {
2024-11-07 11:35:09 -06:00
clearTimeout ( spawnTimeout ) ;
2024-11-07 10:25:49 -06:00
console . error ( 'Bot encountered error:' , error ) ;
reject ( error ) ;
} ) ;
this . bot . on ( 'login' , ( ) => {
console . log ( 'Logged in!' ) ;
2024-11-14 17:06:26 -06:00
2024-11-14 17:18:50 -06:00
// Set skin for profile, requires Fabric Tailor. (https://modrinth.com/mod/fabrictailor)
2024-11-14 17:06:26 -06:00
if ( this . prompter . profile . skin )
2024-11-14 17:18:50 -06:00
this . bot . chat ( ` /skin set URL ${ this . prompter . profile . skin . model } ${ this . prompter . profile . skin . path } ` ) ;
else
this . bot . chat ( ` /skin clear ` ) ;
2024-11-07 10:25:49 -06:00
} ) ;
this . bot . once ( 'spawn' , async ( ) => {
try {
clearTimeout ( spawnTimeout ) ;
addViewer ( this . bot , count _id ) ;
// wait for a bit so stats are not undefined
await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) ) ;
2024-11-14 17:06:26 -06:00
2024-11-07 10:25:49 -06:00
console . log ( ` ${ this . name } spawned. ` ) ;
this . clearBotLogs ( ) ;
this . _setupEventHandlers ( save _data , init _message ) ;
this . startEvents ( ) ;
resolve ( ) ;
} catch ( error ) {
reject ( error ) ;
}
} ) ;
} ) ;
} catch ( error ) {
2024-11-07 10:48:45 -06:00
// Ensure we're not losing error details
console . error ( 'Agent start failed with error:' , {
message : error . message || 'No error message' ,
stack : error . stack || 'No stack trace' ,
error : error
} ) ;
throw error ; // Re-throw with preserved details
2024-05-08 23:59:44 -05:00
}
2024-11-07 10:25:49 -06:00
}
2024-04-20 22:18:26 -05:00
2024-11-07 10:25:49 -06:00
// Split out event handler setup for clarity
_setupEventHandlers ( save _data , init _message ) {
const ignore _messages = [
"Set own game mode to" ,
"Set the time to" ,
"Set the difficulty to" ,
"Teleported " ,
"Set the weather to" ,
"Gamerule "
] ;
2024-11-07 13:30:02 -06:00
const respondFunc = async ( username , message ) => {
if ( username === this . name ) return ;
2024-11-07 10:25:49 -06:00
try {
2023-12-26 14:42:45 -07:00
if ( ignore _messages . some ( ( m ) => message . startsWith ( m ) ) ) return ;
2024-11-05 12:17:10 -06:00
this . shut _up = false ;
2024-08-25 14:06:57 -05:00
2024-11-05 12:17:10 -06:00
console . log ( this . name , 'received message from' , username , ':' , message ) ;
2024-08-22 15:57:20 -05:00
2024-11-05 12:17:10 -06:00
if ( isOtherAgent ( username ) ) {
2024-11-18 23:02:37 -06:00
//recieveFromBot(username, message);
console . warn ( 'recieved whisper from other bot??' )
2024-11-05 12:17:10 -06:00
}
else {
let translation = await handleEnglishTranslation ( message ) ;
this . handleMessage ( username , translation ) ;
}
2024-11-07 10:25:49 -06:00
} catch ( error ) {
console . error ( 'Error handling message:' , error ) ;
}
2024-11-07 13:30:02 -06:00
}
this . bot . on ( 'whisper' , respondFunc ) ;
if ( settings . profiles . length === 1 )
this . bot . on ( 'chat' , respondFunc ) ;
2024-11-02 10:46:04 -05:00
2024-11-07 10:25:49 -06:00
// Set up auto-eat
this . bot . autoEat . options = {
priority : 'foodPoints' ,
startAt : 14 ,
bannedFood : [ "rotten_flesh" , "spider_eye" , "poisonous_potato" , "pufferfish" , "chicken" ]
} ;
2023-12-12 21:35:39 -08:00
2024-11-07 10:25:49 -06:00
// Handle startup conditions
this . _handleStartupConditions ( save _data , init _message ) ;
}
2023-12-26 14:42:45 -07:00
2024-11-07 10:25:49 -06:00
async _handleStartupConditions ( save _data , init _message ) {
try {
if ( save _data ? . self _prompt ) {
2024-05-08 23:59:44 -05:00
let prompt = save _data . self _prompt ;
2024-05-16 20:24:50 -05:00
// add initial message to history
this . history . add ( 'system' , prompt ) ;
2024-11-07 10:25:49 -06:00
await this . self _prompter . start ( prompt ) ;
2024-05-08 23:59:44 -05:00
}
2024-11-18 23:02:37 -06:00
else if ( save _data ? . last _sender ) {
this . last _sender = save _data . last _sender ;
2024-11-22 14:53:25 -06:00
await this . handleMessage ( 'system' , ` You have restarted and this message is auto-generated. Continue the conversation with ${ this . last _sender } ` ) ;
2024-11-18 23:02:37 -06:00
}
2024-05-08 23:59:44 -05:00
else if ( init _message ) {
2024-11-07 10:25:49 -06:00
await this . handleMessage ( 'system' , init _message , 2 ) ;
2024-05-08 23:59:44 -05:00
}
else {
2024-10-02 01:01:22 -05:00
const translation = await handleTranslation ( "Hello world! I am " + this . name ) ;
2024-10-02 00:57:28 -05:00
this . bot . chat ( translation ) ;
2023-12-12 21:35:39 -08:00
}
2024-11-07 10:25:49 -06:00
} catch ( error ) {
console . error ( 'Error handling startup conditions:' , error ) ;
throw error ;
}
2023-12-04 23:26:21 -08:00
}
2024-11-03 22:17:28 -06:00
requestInterrupt ( ) {
2024-10-25 15:28:27 -10:00
this . bot . interrupt _code = true ;
this . bot . collectBlock . cancelTask ( ) ;
this . bot . pathfinder . stop ( ) ;
this . bot . pvp . stop ( ) ;
}
clearBotLogs ( ) {
this . bot . output = '' ;
this . bot . interrupt _code = false ;
}
2024-08-25 14:06:57 -05:00
2024-08-22 15:57:20 -05:00
shutUp ( ) {
this . shut _up = true ;
if ( this . self _prompter . on ) {
this . self _prompter . stop ( false ) ;
}
2024-11-18 23:02:37 -06:00
endAllChats ( ) ;
2024-08-22 15:57:20 -05:00
}
async handleMessage ( source , message , max _responses = null ) {
2024-11-18 23:02:37 -06:00
if ( ! source || ! message ) {
console . warn ( 'Received empty message from' , source ) ;
return false ;
}
2024-04-30 23:07:07 -05:00
let used _command = false ;
2024-08-22 15:57:20 -05:00
if ( max _responses === null ) {
max _responses = settings . max _commands === - 1 ? Infinity : settings . max _commands ;
}
2024-10-10 22:18:10 -05:00
if ( max _responses === - 1 ) {
max _responses = Infinity ;
}
2024-04-30 23:07:07 -05:00
2024-11-02 10:46:04 -05:00
const self _prompt = source === 'system' || source === this . name ;
2024-11-05 12:17:10 -06:00
const from _other _bot = isOtherAgent ( source ) ;
2024-06-23 20:15:28 -05:00
2024-11-05 12:17:10 -06:00
if ( ! self _prompt && ! from _other _bot ) { // from user, check for forced commands
2024-04-30 23:07:07 -05:00
const user _command _name = containsCommand ( message ) ;
if ( user _command _name ) {
if ( ! commandExists ( user _command _name ) ) {
this . bot . chat ( ` Command ' ${ user _command _name } ' does not exist. ` ) ;
return false ;
}
this . bot . chat ( ` * ${ source } used ${ user _command _name . substring ( 1 ) } * ` ) ;
if ( user _command _name === '!newAction' ) {
2024-11-02 10:46:04 -05:00
// all user-initiated commands are ignored by the bot except for this one
2024-04-30 23:07:07 -05:00
// add the preceding message to the history to give context for newAction
2024-06-23 18:54:13 -05:00
this . history . add ( source , message ) ;
2024-04-30 23:07:07 -05:00
}
2024-06-23 18:54:13 -05:00
let execute _res = await executeCommand ( this , message ) ;
2024-04-30 23:07:07 -05:00
if ( execute _res )
2024-11-21 23:32:25 -06:00
this . routeResponse ( source , execute _res ) ;
2024-04-30 23:07:07 -05:00
return true ;
2024-01-13 12:10:15 -06:00
}
2024-01-09 22:50:22 -06:00
}
2024-06-23 20:15:28 -05:00
2024-11-18 23:02:37 -06:00
if ( ! self _prompt )
this . last _sender = source ;
2024-11-05 15:44:40 -08:00
// Now translate the message
message = await handleEnglishTranslation ( message ) ;
console . log ( 'received message from' , source , ':' , message ) ;
2024-11-22 14:53:25 -06:00
const checkInterrupt = ( ) => this . self _prompter . shouldInterrupt ( self _prompt ) || this . shut _up || responseScheduledFor ( source ) ;
2024-08-22 15:57:20 -05:00
2024-09-27 17:03:00 -05:00
let behavior _log = this . bot . modes . flushBehaviorLog ( ) ;
2024-09-29 13:35:15 -07:00
if ( behavior _log . trim ( ) . length > 0 ) {
2024-09-27 17:03:00 -05:00
const MAX _LOG = 500 ;
if ( behavior _log . length > MAX _LOG ) {
2024-09-29 13:35:15 -07:00
behavior _log = '...' + behavior _log . substring ( behavior _log . length - MAX _LOG ) ;
2024-09-27 17:03:00 -05:00
}
behavior _log = 'Recent behaviors log: \n' + behavior _log . substring ( behavior _log . indexOf ( '\n' ) ) ;
await this . history . add ( 'system' , behavior _log ) ;
}
2024-11-05 15:44:40 -08:00
// Handle other user messages
2024-11-05 12:17:10 -06:00
await this . history . add ( source , message ) ;
2024-06-23 20:15:28 -05:00
this . history . save ( ) ;
2024-11-02 10:46:04 -05:00
2024-06-23 20:15:28 -05:00
if ( ! self _prompt && this . self _prompter . on ) // message is from user during self-prompting
max _responses = 1 ; // force only respond to this message, then let self-prompting take over
for ( let i = 0 ; i < max _responses ; i ++ ) {
2024-08-22 15:57:20 -05:00
if ( checkInterrupt ( ) ) break ;
2024-02-25 14:13:32 -06:00
let history = this . history . getHistory ( ) ;
let res = await this . prompter . promptConvo ( history ) ;
2023-12-04 23:26:21 -08:00
2024-01-03 22:16:50 -08:00
let command _name = containsCommand ( res ) ;
2024-01-09 22:50:22 -06:00
if ( command _name ) { // contains query or command
2024-02-25 14:13:32 -06:00
console . log ( ` Full response: "" ${ res } "" ` )
res = truncCommandMessage ( res ) ; // everything after the command is ignored
this . history . add ( this . name , res ) ;
2024-11-02 10:46:04 -05:00
2024-01-14 14:33:25 -06:00
if ( ! commandExists ( command _name ) ) {
2024-06-23 20:15:28 -05:00
this . history . add ( 'system' , ` Command ${ command _name } does not exist. ` ) ;
2024-05-04 15:42:30 -05:00
console . warn ( 'Agent hallucinated command:' , command _name )
continue ;
}
2024-08-22 15:57:20 -05:00
if ( checkInterrupt ( ) ) break ;
2024-06-23 20:15:28 -05:00
this . self _prompter . handleUserPromptedCmd ( self _prompt , isAction ( command _name ) ) ;
2024-05-04 15:42:30 -05:00
2024-06-23 20:15:28 -05:00
if ( settings . verbose _commands ) {
2024-11-21 23:32:25 -06:00
this . routeResponse ( source , res , res . indexOf ( command _name ) ) ;
2024-06-23 20:15:28 -05:00
}
else { // only output command name
2024-10-02 01:01:22 -05:00
let pre _message = res . substring ( 0 , res . indexOf ( command _name ) ) . trim ( ) ;
2024-06-23 20:15:28 -05:00
let chat _message = ` *used ${ command _name . substring ( 1 ) } * ` ;
if ( pre _message . length > 0 )
chat _message = ` ${ pre _message } ${ chat _message } ` ;
2024-11-21 23:32:25 -06:00
this . routeResponse ( source , chat _message ) ;
2024-04-30 23:07:07 -05:00
}
2024-01-11 15:59:52 -06:00
let execute _res = await executeCommand ( this , res ) ;
2024-01-03 22:16:50 -08:00
2024-01-09 22:50:22 -06:00
console . log ( 'Agent executed:' , command _name , 'and got:' , execute _res ) ;
2024-04-30 23:07:07 -05:00
used _command = true ;
2024-01-03 22:16:50 -08:00
if ( execute _res )
this . history . add ( 'system' , execute _res ) ;
else
break ;
2023-12-20 16:30:05 -08:00
}
else { // conversation response
2024-02-25 14:13:32 -06:00
this . history . add ( this . name , res ) ;
2024-11-21 23:32:25 -06:00
this . routeResponse ( source , res ) ;
2023-12-20 16:30:05 -08:00
console . log ( 'Purely conversational response:' , res ) ;
break ;
}
2024-11-02 10:46:04 -05:00
2024-08-22 15:57:20 -05:00
this . history . save ( ) ;
2023-12-04 23:26:21 -08:00
}
2024-04-30 23:07:07 -05:00
return used _command ;
}
2024-11-21 23:32:25 -06:00
async routeResponse ( to _player , message , translate _up _to = - 1 ) {
2024-11-22 14:53:25 -06:00
let self _prompt = to _player === 'system' || to _player === this . name ;
if ( self _prompt && this . last _sender && ! this . self _prompter . on ) {
// this is for when the agent is prompted by system while still in conversation
// so it can respond to events like death but be routed back to the last sender
to _player = this . last _sender ;
}
2024-11-21 23:32:25 -06:00
if ( isOtherAgent ( to _player ) ) {
sendToBot ( to _player , message ) ;
return ;
}
let to _translate = message ;
let remaining = '' ;
if ( translate _up _to != - 1 ) {
to _translate = to _translate . substring ( 0 , translate _up _to ) ;
remaining = message . substring ( translate _up _to ) ;
}
message = ( await handleTranslation ( to _translate ) ) . trim ( ) + " " + remaining ;
// newlines are interpreted as separate chats, which triggers spam filters. replace them with spaces
message = message . replaceAll ( '\n' , ' ' ) ;
2024-11-22 14:53:25 -06:00
if ( self _prompt )
2024-11-21 23:32:25 -06:00
this . bot . chat ( message ) ;
else
this . bot . whisper ( to _player , message ) ;
}
2024-01-25 13:25:36 -08:00
startEvents ( ) {
// Custom events
this . bot . on ( 'time' , ( ) => {
if ( this . bot . time . timeOfDay == 0 )
this . bot . emit ( 'sunrise' ) ;
else if ( this . bot . time . timeOfDay == 6000 )
this . bot . emit ( 'noon' ) ;
else if ( this . bot . time . timeOfDay == 12000 )
this . bot . emit ( 'sunset' ) ;
else if ( this . bot . time . timeOfDay == 18000 )
this . bot . emit ( 'midnight' ) ;
} ) ;
2024-04-20 22:18:26 -05:00
let prev _health = this . bot . health ;
this . bot . lastDamageTime = 0 ;
this . bot . lastDamageTaken = 0 ;
2024-01-25 13:25:36 -08:00
this . bot . on ( 'health' , ( ) => {
2024-04-20 22:18:26 -05:00
if ( this . bot . health < prev _health ) {
this . bot . lastDamageTime = Date . now ( ) ;
this . bot . lastDamageTaken = prev _health - this . bot . health ;
}
prev _health = this . bot . health ;
2024-01-25 13:25:36 -08:00
} ) ;
// Logging callbacks
2024-01-24 17:24:52 -06:00
this . bot . on ( 'error' , ( err ) => {
console . error ( 'Error event!' , err ) ;
} ) ;
this . bot . on ( 'end' , ( reason ) => {
console . warn ( 'Bot disconnected! Killing agent process.' , reason )
2024-05-20 00:52:08 -05:00
this . cleanKill ( 'Bot disconnected! Killing agent process.' ) ;
2024-01-23 18:01:38 -06:00
} ) ;
this . bot . on ( 'death' , ( ) => {
2024-11-03 12:04:47 -05:00
this . actions . cancelResume ( ) ;
this . actions . stop ( ) ;
2024-01-23 18:01:38 -06:00
} ) ;
2024-01-24 17:24:52 -06:00
this . bot . on ( 'kicked' , ( reason ) => {
console . warn ( 'Bot kicked!' , reason ) ;
2024-05-20 00:52:08 -05:00
this . cleanKill ( 'Bot kicked! Killing agent process.' ) ;
2024-01-24 17:24:52 -06:00
} ) ;
2024-01-23 18:01:38 -06:00
this . bot . on ( 'messagestr' , async ( message , _ , jsonMsg ) => {
if ( jsonMsg . translate && jsonMsg . translate . startsWith ( 'death' ) && message . startsWith ( this . name ) ) {
console . log ( 'Agent died: ' , message ) ;
2024-10-27 20:35:02 +10:00
let death _pos = this . bot . entity . position ;
2024-11-03 23:01:34 -06:00
this . memory _bank . rememberPlace ( 'last_death_position' , death _pos . x , death _pos . y , death _pos . z ) ;
2024-10-27 20:35:02 +10:00
let death _pos _text = null ;
if ( death _pos ) {
death _pos _text = ` x: ${ death _pos . x . toFixed ( 2 ) } , y: ${ death _pos . y . toFixed ( 2 ) } , z: ${ death _pos . x . toFixed ( 2 ) } ` ;
}
2024-10-30 22:18:17 +10:00
let dimention = this . bot . game . dimension ;
2024-11-03 12:28:20 +10:00
this . handleMessage ( 'system' , ` You died at position ${ death _pos _text || "unknown" } in the ${ dimention } dimension with the final message: ' ${ message } '. Your place of death is saved as 'last_death_position' if you want to return. Previous actions were stopped and you have respawned. ` ) ;
2024-01-23 18:01:38 -06:00
}
2024-03-05 16:40:06 -08:00
} ) ;
2024-01-26 12:11:32 -08:00
this . bot . on ( 'idle' , ( ) => {
2024-04-20 22:18:26 -05:00
this . bot . clearControlStates ( ) ;
2024-05-04 16:17:41 -05:00
this . bot . pathfinder . stop ( ) ; // clear any lingering pathfinder
2024-02-02 15:34:17 -06:00
this . bot . modes . unPauseAll ( ) ;
2024-11-03 12:04:47 -05:00
this . actions . resumeAction ( ) ;
2024-01-26 12:11:32 -08:00
} ) ;
2024-03-05 12:05:46 -08:00
// Init NPC controller
this . npc . init ( ) ;
2024-01-26 13:18:30 -06:00
// This update loop ensures that each update() is called one at a time, even if it takes longer than the interval
const INTERVAL = 300 ;
2024-05-04 15:42:30 -05:00
let last = Date . now ( ) ;
2024-01-26 13:18:30 -06:00
setTimeout ( async ( ) => {
while ( true ) {
let start = Date . now ( ) ;
2024-05-04 15:42:30 -05:00
await this . update ( start - last ) ;
2024-01-26 13:18:30 -06:00
let remaining = INTERVAL - ( Date . now ( ) - start ) ;
if ( remaining > 0 ) {
await new Promise ( ( resolve ) => setTimeout ( resolve , remaining ) ) ;
}
2024-05-04 15:42:30 -05:00
last = start ;
2024-01-26 13:18:30 -06:00
}
} , INTERVAL ) ;
2024-02-12 16:33:28 -08:00
this . bot . emit ( 'idle' ) ;
2024-01-23 18:01:38 -06:00
}
2024-01-26 15:41:55 -06:00
2024-05-04 15:42:30 -05:00
async update ( delta ) {
await this . bot . modes . update ( ) ;
await this . self _prompter . update ( delta ) ;
}
2024-01-26 15:41:55 -06:00
isIdle ( ) {
2024-11-03 12:04:47 -05:00
return ! this . actions . executing && ! this . coder . generating ;
2024-01-26 15:41:55 -06:00
}
2024-05-20 00:52:08 -05:00
2024-05-08 23:59:44 -05:00
cleanKill ( msg = 'Killing agent process...' ) {
this . history . add ( 'system' , msg ) ;
2024-11-02 10:46:04 -05:00
this . bot . chat ( 'Restarting.' )
2024-05-08 23:59:44 -05:00
this . history . save ( ) ;
process . exit ( 1 ) ;
}
2023-11-07 09:44:56 -06:00
}