cucumber-ai
Version: 
Write automated tests using natural language
42 lines • 1.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ActionAgent = exports.ConceptAgent = void 0;
var concept_agent_1 = require("./concept-agent");
Object.defineProperty(exports, "ConceptAgent", { enumerable: true, get: function () { return concept_agent_1.ConceptAgent; } });
class ActionAgent {
    constructor(context) {
        this.context = context;
        this.actionContext = {};
    }
    async start() { }
    async stop() {
        this.actionContext = {};
    }
    async executeActions(actions, args = {}) {
        for (const action of actions) {
            const text = this.replaceArgValue(action.text, args);
            const arg = action.arg && this.replaceArgValue(action.arg, args);
            console.log(`Executing action: ${action.name} with text: ${text}, arg: ${arg}, context: ${JSON.stringify(this.actionContext)}`);
            const { success, result, error } = await this.context.getActions().execute(action.name, text, arg);
            if (success) {
                if (result) {
                    this.updateContext(result);
                }
            }
            else {
                throw new Error(`${action.name} action failed: ${error}`);
            }
        }
    }
    replaceArgValue(text, args = {}) {
        return text.replace(/\[\[(.*?)]]/g, (_, key) => args[key.trim()] || this.actionContext[key.trim()] || "");
    }
    updateContext(result) {
        if (result) {
            this.actionContext = { ...this.actionContext, ...result };
            console.log(`Update context: ${JSON.stringify(this.actionContext)}`);
        }
    }
}
exports.ActionAgent = ActionAgent;
//# sourceMappingURL=index.js.map