UNPKG

@2501-ai/cli

Version:

[![npm version](https://img.shields.io/npm/v/@2501-ai/cli.svg)](https://www.npmjs.com/package/@2501-ai/cli) [![HumanEval Score](https://img.shields.io/badge/HumanEval-96.95%25-brightgreen.svg)](https://www.2501.ai/research/full-humaneval-benchmark) [![Lic

133 lines (130 loc) 6.46 kB
#!/usr/bin/env node "use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } 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 }); const commander_1 = require("commander"); const config_1 = require("./commands/config"); const query_1 = require("./commands/query"); const init_1 = require("./commands/init"); const agents_1 = require("./commands/agents"); const set_1 = require("./commands/set"); const wtf_1 = require("./commands/wtf"); const jobs_1 = require("./commands/jobs"); const auth_1 = require("./middleware/auth"); const versioning_1 = require("./utils/versioning"); const logger_1 = __importDefault(require("./utils/logger")); const messaging_1 = require("./utils/messaging"); const credentials_1 = require("./utils/credentials"); const plugins_1 = require("./utils/plugins"); process.on('SIGINT', () => { console.log('Process interrupted with Ctrl+C'); process.exit(130); }); const program = new commander_1.Command(); program .name('@2501') .description(` ░▒▓███████▓▒░░▒▓████████▓▒░▒▓████████▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓████▓▒░ ░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓██████▓▒░░▒▓███████▓▒░░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓████████▓▒░▒▓███████▓▒░░▒▓████████▓▒░ ░▒▓█▓▒░ ---- AI Autonomous Systems ---- Join our Discord server: ${messaging_1.DISCORD_LINK} `) .version(require('../package.json').version) .on('command:*', (args, options) => __awaiter(void 0, void 0, void 0, function* () { const query = args === null || args === void 0 ? void 0 : args.join(' '); if (!query) { return; } logger_1.default.debug('Options', options); yield (0, auth_1.authMiddleware)(); yield (0, query_1.queryCommand)(query, { stream: options.stream, }); })); program .command('config') .description('Fetch configuration from API') .hook('preAction', auth_1.authMiddleware) .action(config_1.configCommand); program .command('query') .argument('<query>', 'Query to execute') .description('Execute a query using the specified agent') .option('--workspace <path>', 'Specify a different workspace path') .option('--agentId <id>', 'Specify the agent ID') .option('--stream [stream]', 'Stream the output of the query', false) .option('--plugins <path>', 'Path to plugins configuration file') .option('--env <path>', 'Path to .env file containing credentials') .hook('preAction', auth_1.authMiddleware) .hook('preAction', plugins_1.initPlugins) .hook('preAction', credentials_1.initPluginCredentials) .action((query, options) => __awaiter(void 0, void 0, void 0, function* () { try { yield (0, query_1.queryCommand)(query, options); } catch (error) { logger_1.default.error(error.message); process.exit(1); } })); program .command('init') .description('Initializes a new agent') .option('--name <name>', 'Specify the name of the agent') .option('--workspace <path>', 'Specify a different workspace path') .option('--no-workspace', 'Will not sync the current workspace and will create a temporary one in /tmp/2501/') .option('--config <configKey>', 'Specify the configuration Key to use') .hook('preAction', auth_1.authMiddleware) .action(init_1.initCommand); program .command('agents') .description('List agents in the current workspace or all agents on the machine') .option('--workspace <path>', 'Specify a different workspace path') .option('--all', 'Parameter to target all agents during list or flush action') .option('--flush', 'Flush all agents from the configuration') .action(agents_1.agentsCommand); program .command('jobs') .description('Fetch jobs from API') .option('--workspace <path>', 'Specify a different workspace path') .option('--subscribe', 'Subscribe to the API for new jobs on the current workspace (updated every minute)') .option('--unsubscribe', 'Unsubscribe to the API for new jobs on the current workspace') .option('--listen', 'Listen for new jobs from the API and execute them') .hook('preAction', auth_1.authMiddleware) .hook('preAction', plugins_1.initPlugins) .hook('preAction', credentials_1.initPluginCredentials) .action(jobs_1.jobSubscriptionCommand); program .command('set') .description('Set a configuration value') .argument('<key>', 'The key to set') .argument('<value>', 'The value to set') .action(set_1.setCommand); program .command('wtf') .description('What the f*ck did I just do?') .hook('preAction', auth_1.authMiddleware) .action(wtf_1.wtfCommand); (() => __awaiter(void 0, void 0, void 0, function* () { const isLatest = yield (0, versioning_1.isLatestVersion)(); if (!isLatest) { logger_1.default.log('UPDATE AVAILABLE : A new version of 2501 CLI is available. Run `npm i -g @2501-ai/cli` to update'); } program.parse(process.argv); }))();