sensai
Version:
Because even AI needs a master
54 lines (53 loc) • 1.83 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "default", {
enumerable: true,
get: function() {
return _default;
}
});
const _nodepath = require("node:path");
const _constants = require("../../constants");
const _default = ()=>{
const map = {};
return {
/**
* Add agent to orchestrator layer.
*
* When router finds an `orchestrator` file, it will look for agents that
* live in the same directory. I.e we need to map agents with their parent URL segment.
*/ add (agentFilePath) {
const agentPath = (0, _nodepath.dirname)(agentFilePath);
const parentPath = (0, _nodepath.dirname)(agentPath);
const name = getFolderName(agentPath);
map[parentPath] ??= {};
map[parentPath][name] ??= agentFilePath;
},
/**
* Return list of agents that apply to a given orchestrator file.
*
* @notes we are not gonna check the file is `orchestrator(.ts|js|md)` but instead
* trust that's the case.
*/ get (dir) {
return map[dir] || {};
},
remove (agentFilePath) {
const agentPath = (0, _nodepath.dirname)(agentFilePath);
const parentPath = (0, _nodepath.dirname)(agentPath);
const name = (0, _nodepath.basename)(agentPath);
if (map[parentPath]) {
delete map[parentPath][name];
}
}
};
};
/**
* Extract the folder name from a path, handling special cases like
* single/double brackets and ellipses.
*/ const getFolderName = (folderPath)=>{
const name = (0, _nodepath.basename)(folderPath);
const matches = name.match(_constants.DYNAMIC_SEGMENT_REGEXP);
return matches ? matches[3] : name;
};