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

66 lines (65 loc) 2.34 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ConfigManager = exports.DEFAULT_CONFIG = void 0; const conf_1 = require("../utils/conf"); const logger_1 = __importDefault(require("../utils/logger")); exports.DEFAULT_CONFIG = { workspace_disabled: false, agents: [], stream: true, disable_spinner: true, api_key: '', engine: 'rhino', telemetry_enabled: true, auto_update: true, }; const CONFIG_VALIDATORS = { workspace_disabled: (value) => typeof value === 'boolean', agents: () => true, stream: (value) => typeof value === 'boolean', disable_spinner: (value) => typeof value === 'boolean', api_key: (value) => typeof value === 'string', engine: (value) => typeof value === 'string', telemetry_enabled: (value) => typeof value === 'boolean', auto_update: (value) => typeof value === 'boolean', }; class ConfigManager { static get instance() { if (!ConfigManager._instance) { ConfigManager._instance = new ConfigManager(); } return ConfigManager._instance; } constructor() { let config = (0, conf_1.readConfig)(); if (!config) { (0, conf_1.writeConfig)(exports.DEFAULT_CONFIG); config = exports.DEFAULT_CONFIG; } this._config = Object.assign(Object.assign({}, exports.DEFAULT_CONFIG), config); } set(key, value) { if (!(key in CONFIG_VALIDATORS)) { throw new Error(`Invalid configuration key: ${key}`); } if (!CONFIG_VALIDATORS[key](value)) { throw new Error(`Invalid value for ${key}: ${value}. Expected ${typeof exports.DEFAULT_CONFIG[key]}`); } const newConfig = Object.assign(Object.assign({}, this._config), { [key]: value }); try { (0, conf_1.writeConfig)(newConfig); this._config = newConfig; } catch (error) { logger_1.default.error(`Failed to set ${key}:`, error); throw new Error(`Failed to save configuration: ${error.message}`); } } get(key) { return this._config[key]; } } exports.ConfigManager = ConfigManager;