@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.initCommand = exports.getWorkspacePath = exports.DEFAULT_ENGINE = void 0;
const axios_1 = __importDefault(require("axios"));
const fs_1 = __importDefault(require("fs"));
const terminal_kit_1 = require("terminal-kit");
const logger_1 = __importDefault(require("../utils/logger"));
const conf_1 = require("../utils/conf");
const constants_1 = require("../constants");
const security_1 = require("../helpers/security");
const api_1 = require("../helpers/api");
const messaging_1 = require("../utils/messaging");
const workspace_1 = require("../helpers/workspace");
const systemInfo_1 = require("../utils/systemInfo");
axios_1.default.defaults.baseURL = `${constants_1.API_HOST}${constants_1.API_VERSION}`;
axios_1.default.defaults.timeout = 120 * 1000;
exports.DEFAULT_ENGINE = 'rhino';
const logger = new logger_1.default();
function fetchConfiguration(configKey) {
return __awaiter(this, void 0, void 0, function* () {
const { data: configurations } = yield axios_1.default.get(`/configurations`);
const selectedConfig = configurations.find((config) => config.key === configKey);
if (!selectedConfig) {
logger_1.default.error(`Configuration not found: ${configKey}`);
process.exit(1);
}
return selectedConfig;
});
}
function getWorkspacePath(options) {
return __awaiter(this, void 0, void 0, function* () {
if ((options === null || options === void 0 ? void 0 : options.workspace) === false) {
const path = `/tmp/2501/${Date.now()}`;
fs_1.default.mkdirSync(path, { recursive: true });
logger.log(`Using workspace at ${path}`);
return path;
}
let finalPath;
if (typeof (options === null || options === void 0 ? void 0 : options.workspace) === 'string' && !!options.workspace) {
finalPath = (0, workspace_1.resolveWorkspacePath)({ workspace: options.workspace });
}
else {
finalPath = process.cwd();
}
if (!(options === null || options === void 0 ? void 0 : options.ignoreUnsafe) && (0, security_1.isDirUnsafe)(finalPath)) {
logger.log(`Files in the workspace "${finalPath}" are considered sensitive`);
const res = yield logger.prompt(`Are you sure you want to proceed with synchronization ? This will synchronize a sensitive directory and may overwrite or modify critical files. (y/n)`);
if (res === false || res.toString() === 'Symbol(clack:cancel)') {
logger.cancel('Operation cancelled');
process.exit(0);
}
logger.log(`Using workspace at ${finalPath}`);
}
return finalPath;
});
}
exports.getWorkspacePath = getWorkspacePath;
function initCommand(options) {
return __awaiter(this, void 0, void 0, function* () {
try {
const localConfig = (0, conf_1.readConfig)();
if (!(localConfig === null || localConfig === void 0 ? void 0 : localConfig.join_discord_shown)) {
const term = terminal_kit_1.terminal;
term('\n');
term.gray('🔗 Join our Discord\n');
term
.gray('│ ')
.gray('Connect with the 2501 team and community for updates, support, and insights:\n');
term.gray('│ ').gray.underline(`${messaging_1.DISCORD_LINK}\n`);
(0, conf_1.setValue)('join_discord_shown', true);
}
const shouldDisableSpinner = process.env.TFZO_DISABLE_SPINNER === 'true';
(0, conf_1.setValue)('disable_spinner', shouldDisableSpinner);
logger.start('Creating agent');
const configKey = (options === null || options === void 0 ? void 0 : options.config) || 'CODING_AGENT';
const parallelPromises = [
getWorkspacePath(options),
(0, systemInfo_1.getSystemInfo)(),
fetchConfiguration(configKey),
];
const [workspacePath, systemInfo, agentConfig] = yield Promise.all(parallelPromises);
logger_1.default.debug('systemInfo results:', { systemInfo });
const createResponse = yield (0, api_1.createAgent)(workspacePath, agentConfig, systemInfo, localConfig === null || localConfig === void 0 ? void 0 : localConfig.engine);
logger_1.default.debug('Agent created:', createResponse);
(0, conf_1.addAgent)({
id: createResponse.id,
name: createResponse.name,
capabilities: createResponse.capabilities,
workspace: workspacePath,
configuration: agentConfig.id,
engine: (localConfig === null || localConfig === void 0 ? void 0 : localConfig.engine) || exports.DEFAULT_ENGINE,
});
logger.stop(`Agent ${createResponse.id} created`);
}
catch (e) {
logger.handleError(e, e.message);
}
});
}
exports.initCommand = initCommand;