@2501-ai/cli
Version:
[](https://www.npmjs.com/package/@2501-ai/cli) [](https://www.2501.ai/research/full-humaneval-benchmark) [); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AgentManager = exports.ACTION_FNS = void 0;
const axios_1 = __importDefault(require("axios"));
const fs_1 = __importDefault(require("fs"));
const actions_1 = require("../helpers/actions");
const logger_1 = __importDefault(require("../utils/logger"));
const conf_1 = require("../utils/conf");
const actions_2 = require("../utils/actions");
const constants_1 = require("../constants");
exports.ACTION_FNS = {
browse_url: actions_1.browse_url,
read_file: actions_1.read_file,
run_shell: actions_1.run_shell,
write_file: actions_1.write_file,
update_file: actions_1.update_file,
};
function isBlacklistedCommand(command) {
return constants_1.BLACKLISTED_COMMANDS.some((blocked) => {
const pattern = new RegExp(`(^|\\s|;|\\||&|>|<)${blocked}($|\\s|;|\\||&|>|<)`, 'i');
return pattern.test(command);
});
}
class AgentManager {
constructor(options) {
this.id = options.id;
this.name = options.name;
this.engine = options.engine;
this.workspace = options.workspace;
this.capabilities = options.capabilities;
}
executeAction(action, args) {
return __awaiter(this, void 0, void 0, function* () {
const functionName = (0, actions_2.getFunctionName)(action);
if (!exports.ACTION_FNS[functionName]) {
return {
tool_call_id: action.id,
output: `Function '${functionName}' not found. Please verify the function name and try again.`,
success: false,
};
}
if (args.command) {
if (isBlacklistedCommand(args.command)) {
const errorMessage = [
`EXECUTION BLOCKED: Content contains blocked command`,
'SECURITY VIOLATION:',
`Interactive terminal editors (${constants_1.BLACKLISTED_COMMANDS.join(', ')}) are strictly prohibited in this environment.`,
'These commands require direct user interaction and violate the automated execution policy.',
'NOTE: All content containing editor commands will be systematically blocked.',
].join('\n');
return {
tool_call_id: action.id,
output: errorMessage,
success: false,
};
}
}
let taskTitle = args.answer || args.command || '';
if (args.url) {
taskTitle = 'Browsing: ' + args.url;
}
let corrected = false;
if (args.path && args.content) {
const previous = exports.ACTION_FNS.read_file({ path: args.path }) || 'NO PREVIOUS VERSION';
try {
const config = (0, conf_1.readConfig)();
const { data: correctionData } = yield axios_1.default.post(`/agents/${this.id}/verifyOutput`, {
task: taskTitle,
previous,
proposal: args.content,
}, {
timeout: 150000,
headers: {
Authorization: `Bearer ${config === null || config === void 0 ? void 0 : config.api_key}`,
},
});
logger_1.default.debug('Correction data:', correctionData);
if (correctionData.corrected_output &&
correctionData.corrected_output !== args.content) {
corrected = true;
args.content = correctionData.corrected_output;
}
}
catch (e) {
logger_1.default.error('verifyOutput error or timeout', e);
throw e;
}
}
logger_1.default.debug(` Processing action: ${taskTitle} | On function ${functionName}`);
try {
let output = (yield exports.ACTION_FNS[functionName](args));
if (corrected) {
output += `\n\n NOTE: your original content for ${args.path} was corrected with the new version below before running the function: \n\n${args.content}`;
}
if (output.length > 20000) {
output =
'Content is too big, if you need this content, please find an alternative method to retrieve the relevant information (for example grep and sample the content first). Below are two samples of the content:';
output += `\n\nFirst 150 chars:\n${output.slice(0, 150)}\n\nLast 150 chars:\n${output.slice(-150)}`;
}
return {
tool_call_id: action.id,
output,
success: true,
};
}
catch (e) {
logger_1.default.debug('Error processing action:', e);
let content = '';
if (args.path) {
try {
content = `
File concerned: \`${args.path}\`
File content:
\`\`\`
${fs_1.default.readFileSync(args.path, 'utf8')}
\`\`\``;
}
catch (e) { }
}
return {
tool_call_id: action.id,
output: `I failed to run ${functionName}, please fix the situation or files. Feel free to explore the files again (excluding ignored files) if necessary.
Error message :
\`\`\`
${e.message}
\`\`\`${content}`,
success: false,
};
}
});
}
}
exports.AgentManager = AgentManager;