@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.jobSubscriptionCommand = void 0;
const axios_1 = __importDefault(require("axios"));
const constants_1 = require("../constants");
const actions_1 = require("../helpers/actions");
const query_1 = require("./query");
const conf_1 = require("../utils/conf");
const shellCommands_1 = require("../utils/shellCommands");
const logger_1 = __importDefault(require("../utils/logger"));
function jobSubscriptionCommand(options) {
return __awaiter(this, void 0, void 0, function* () {
const logger = new logger_1.default();
const workspace = options.workspace || process.cwd();
logger.intro('2501 - Jobs Subscription');
if (options.subscribe) {
logger.start('Subscribing for new jobs');
const shellOutput = yield (0, actions_1.run_shell)({
command: `echo $SHELL`,
shell: true,
});
if ((0, actions_1.hasError)(shellOutput)) {
return logger_1.default.error(shellOutput);
}
const soureCommandOutput = yield (0, actions_1.run_shell)({
command: shellCommands_1.unixSourceCommand,
shell: shellOutput,
});
if ((0, actions_1.hasError)(soureCommandOutput)) {
return logger_1.default.error(soureCommandOutput);
}
const crontabOutput = yield (0, actions_1.run_shell)({
shell: true,
command: `(crontab -l 2>/dev/null; echo "* * * * * ${shellOutput} -c \\"${soureCommandOutput} && cd ${workspace} && @2501 jobs --listen\\" >> ${actions_1.LOGFILE_PATH} 2>>${actions_1.ERRORFILE_PATH}") | crontab -`,
});
if ((0, actions_1.hasError)(crontabOutput)) {
return logger_1.default.error('crontabOutput', crontabOutput);
}
return logger.stop(`Subscribed to the API for new jobs on workspace ${workspace}`);
}
if (options.unsubscribe) {
logger.start('Unsubscribing for new jobs');
const crontabOutput = yield (0, actions_1.run_shell)({
shell: true,
command: `crontab -l | grep -v "cd ${workspace} && @2501 jobs --listen" | crontab -`,
});
if ((0, actions_1.hasError)(crontabOutput)) {
return logger_1.default.error('crontabOutput', crontabOutput);
}
return logger.stop(`Unsubscribed to the API for new jobs on workspace ${workspace}`);
}
if (options.listen) {
try {
const workspace = options.workspace || process.cwd();
const [agent] = (0, conf_1.listAgentsFromWorkspace)(workspace);
if (!agent) {
return logger.outro('No agents available in the workspace');
}
logger.start(`Listening for new jobs on ${workspace}`);
const response = yield axios_1.default.get(`${constants_1.API_HOST}${constants_1.API_VERSION}/agents/${agent.id}/jobs?status=todo`);
const jobs = response.data;
if (!jobs || !jobs.length) {
logger.outro('No jobs found');
return;
}
const shell_user = yield (0, actions_1.run_shell)({ command: `whoami` });
const localIP = yield (0, actions_1.run_shell)({ command: `hostname -I` });
logger.stop(`Found ${jobs.length} jobs to execute`);
for (const idx in jobs) {
yield axios_1.default.put(`${constants_1.API_HOST}${constants_1.API_VERSION}/jobs/${jobs[idx].id}`, {
status: 'in_progress',
host: `${shell_user.trim()}@${localIP.trim()}`,
});
yield (0, query_1.queryCommand)(jobs[idx].brief, {
callback: (response) => __awaiter(this, void 0, void 0, function* () {
yield axios_1.default.put(`${constants_1.API_HOST}${constants_1.API_VERSION}/jobs/${jobs[idx].id}`, {
status: 'completed',
result: response,
});
}),
});
}
}
catch (error) {
logger_1.default.error('Jobs error:', error);
}
}
});
}
exports.jobSubscriptionCommand = jobSubscriptionCommand;