mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-04-21 21:52:07 +02:00
32 lines
No EOL
920 B
JavaScript
32 lines
No EOL
920 B
JavaScript
import { spawn } from 'child_process';
|
|
|
|
class AgentController {
|
|
constructor(name) {
|
|
this.name = name;
|
|
}
|
|
async start(restart_memory=false) {
|
|
let args = ['init_agent.js', this.name];
|
|
if (restart_memory)
|
|
args.push('-r');
|
|
const agentProcess = spawn('node', args, {
|
|
stdio: 'inherit',
|
|
stderr: 'inherit',
|
|
});
|
|
|
|
agentProcess.on('exit', (code, signal) => {
|
|
console.log(`Agent process exited with code ${code} and signal ${signal}`);
|
|
|
|
// Restart the agent if it exited due to an error
|
|
if (code !== 0) {
|
|
console.log('Restarting agent...');
|
|
this.start();
|
|
}
|
|
});
|
|
|
|
agentProcess.on('error', (err) => {
|
|
console.error('Failed to start agent process:', err);
|
|
});
|
|
}
|
|
}
|
|
|
|
new AgentController('andy').start(); |