mahler
Version:
A automated task composer and HTN based planner for building autonomous system agents
41 lines • 1.45 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PlanAction = void 0;
const crypto_1 = require("crypto");
const task_1 = require("../task");
const pointer_1 = require("../pointer");
const DAG = require("../dag");
function isPlanAction(n) {
return (DAG.isValue(n) && n.action != null && task_1.Action.is(n.action));
}
exports.PlanAction = {
/**
* Create a new Plan action node from a given action and a state
*/
from(s, a) {
// We don't use the full state to calculate the
// id as there may be changes in the state that have nothing
// to do with the action. We just use the part of the state
// that is relevant to the action according to the path
const state = pointer_1.Pointer.from(s, a.path);
// md5 should be good enough for this purpose
// and it's the fastest of the available options
// TODO: this is sensitive to key reordering, we might
// need sorting before, but we need to benchmark first
const id = (0, crypto_1.createHash)('md5')
.update(JSON.stringify({
id: a.id,
path: a.path,
state,
...(a.target && { target: a.target }),
}))
.digest('hex');
return DAG.createValue({
id,
action: a,
next: null,
});
},
is: isPlanAction,
};
//# sourceMappingURL=node.js.map