mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-08-22 07:03:45 +02:00
added cancelResume for failed actions
This commit is contained in:
parent
7e80efb5b4
commit
f9c41246f1
4 changed files with 12 additions and 7 deletions
|
@ -163,7 +163,6 @@ export class Coder {
|
|||
this.resume_func = func;
|
||||
this.resume_name = name;
|
||||
}
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
if (this.resume_func != null && this.agent.isIdle()) {
|
||||
this.interruptible = true;
|
||||
let res = await this.execute(this.resume_func, timeout);
|
||||
|
@ -174,6 +173,11 @@ export class Coder {
|
|||
}
|
||||
}
|
||||
|
||||
cancelResume() {
|
||||
this.resume_func = null;
|
||||
this.resume_name = null;
|
||||
}
|
||||
|
||||
// returns {success: bool, message: string, interrupted: bool, timedout: false}
|
||||
async execute(func, timeout=10) {
|
||||
if (!this.code_template) return {success: false, message: "Code template not loaded.", interrupted: false, timedout: false};
|
||||
|
@ -200,7 +204,7 @@ export class Coder {
|
|||
} catch (err) {
|
||||
this.executing = false;
|
||||
clearTimeout(TIMEOUT);
|
||||
|
||||
this.cancelResume();
|
||||
console.error("Code execution triggered catch: " + err);
|
||||
await this.stop();
|
||||
|
||||
|
|
|
@ -35,8 +35,7 @@ export const actionsList = [
|
|||
perform: async function (agent) {
|
||||
await agent.coder.stop();
|
||||
agent.coder.clear();
|
||||
agent.coder.resume_func = null;
|
||||
agent.coder.resume_name = null;
|
||||
agent.coder.cancelResume();
|
||||
return 'Agent stopped.';
|
||||
}
|
||||
},
|
||||
|
@ -126,7 +125,9 @@ export const actionsList = [
|
|||
'type': '(string) The block type to collect. Ex: !collectAllBlocks("stone")'
|
||||
},
|
||||
perform: wrapExecution(async (agent, type) => {
|
||||
await skills.collectBlock(agent.bot, type, 1);
|
||||
let success = await skills.collectBlock(agent.bot, type, 1);
|
||||
if (!success)
|
||||
agent.coder.cancelResume();
|
||||
}, 10, 'collectAllBlocks') // 10 minute timeout
|
||||
},
|
||||
{
|
||||
|
|
|
@ -373,7 +373,7 @@ export async function collectBlock(bot, blockType, num=1) {
|
|||
break;
|
||||
}
|
||||
log(bot, `Collected ${collected} ${blockType}.`);
|
||||
return true;
|
||||
return collected > 0;
|
||||
}
|
||||
|
||||
export async function pickupNearbyItems(bot) {
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
],
|
||||
|
||||
[
|
||||
{"role": "user", "content": "billybob: stop"},
|
||||
{"role": "user", "content": "abc: stop"},
|
||||
{"role": "assistant", "content": "Sure. !stop"}
|
||||
],
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue