added cancelResume for failed actions

This commit is contained in:
MaxRobinsonTheGreat 2024-02-05 13:21:32 -06:00
parent 7e80efb5b4
commit f9c41246f1
4 changed files with 12 additions and 7 deletions

View file

@ -163,7 +163,6 @@ export class Coder {
this.resume_func = func; this.resume_func = func;
this.resume_name = name; this.resume_name = name;
} }
await new Promise(resolve => setTimeout(resolve, 500));
if (this.resume_func != null && this.agent.isIdle()) { if (this.resume_func != null && this.agent.isIdle()) {
this.interruptible = true; this.interruptible = true;
let res = await this.execute(this.resume_func, timeout); 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} // returns {success: bool, message: string, interrupted: bool, timedout: false}
async execute(func, timeout=10) { async execute(func, timeout=10) {
if (!this.code_template) return {success: false, message: "Code template not loaded.", interrupted: false, timedout: false}; 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) { } catch (err) {
this.executing = false; this.executing = false;
clearTimeout(TIMEOUT); clearTimeout(TIMEOUT);
this.cancelResume();
console.error("Code execution triggered catch: " + err); console.error("Code execution triggered catch: " + err);
await this.stop(); await this.stop();

View file

@ -35,8 +35,7 @@ export const actionsList = [
perform: async function (agent) { perform: async function (agent) {
await agent.coder.stop(); await agent.coder.stop();
agent.coder.clear(); agent.coder.clear();
agent.coder.resume_func = null; agent.coder.cancelResume();
agent.coder.resume_name = null;
return 'Agent stopped.'; return 'Agent stopped.';
} }
}, },
@ -126,7 +125,9 @@ export const actionsList = [
'type': '(string) The block type to collect. Ex: !collectAllBlocks("stone")' 'type': '(string) The block type to collect. Ex: !collectAllBlocks("stone")'
}, },
perform: wrapExecution(async (agent, type) => { 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 }, 10, 'collectAllBlocks') // 10 minute timeout
}, },
{ {

View file

@ -373,7 +373,7 @@ export async function collectBlock(bot, blockType, num=1) {
break; break;
} }
log(bot, `Collected ${collected} ${blockType}.`); log(bot, `Collected ${collected} ${blockType}.`);
return true; return collected > 0;
} }
export async function pickupNearbyItems(bot) { export async function pickupNearbyItems(bot) {

View file

@ -54,7 +54,7 @@
], ],
[ [
{"role": "user", "content": "billybob: stop"}, {"role": "user", "content": "abc: stop"},
{"role": "assistant", "content": "Sure. !stop"} {"role": "assistant", "content": "Sure. !stop"}
], ],