rawi
Version:
Rawi (راوي) is the developer-friendly AI CLI that brings the power of 12 major AI providers directly to your terminal. With seamless shell integration, persistent conversations, and 200+ specialized prompt templates, Rawi transforms your command line into
4 lines • 4.1 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }/* Rawi (راوي) is the developer-friendly AI CLI that brings the power of 12 major AI providers directly to your terminal. With seamless shell integration, persistent conversations, and 200+ specialized prompt templates, Rawi transforms your command line into an intelligent development workspace. */
var _chunk5GCADSBNcjs = require('./chunk-5GCADSBN.cjs');var _chunkP4NH5RQRcjs = require('./chunk-P4NH5RQR.cjs');var _fs = require('fs');var _path = require('path');var _chalk = require('chalk'); var _chalk2 = _interopRequireDefault(_chalk);var a=class{constructor(){this.configDir=_chunk5GCADSBNcjs.c.call(void 0, ),this.configFile=_chunk5GCADSBNcjs.d.call(void 0, ),this.backupFile=_path.join.call(void 0, this.configDir,"credentials.backup.json")}ensureConfigDir(){if(!_fs.existsSync.call(void 0, this.configDir))try{_fs.mkdirSync.call(void 0, this.configDir,{recursive:!0})}catch(r){throw new Error(`Failed to create config directory: ${r instanceof Error?r.message:String(r)}`)}}configExists(){return _fs.existsSync.call(void 0, this.configFile)}readConfig(){if(!_fs.existsSync.call(void 0, this.configFile))return{};try{let r=_fs.readFileSync.call(void 0, this.configFile,"utf-8"),e=JSON.parse(r);if(typeof e!="object"||e===null)throw new Error("Invalid configuration format");return e}catch (e2){if(console.error(_chalk2.default.yellow("Warning: Failed to read config file, using empty config.")),_fs.existsSync.call(void 0, this.backupFile)){console.log(_chalk2.default.blue("Attempting to restore from backup..."));try{return this.restoreConfig(),this.readConfig()}catch(r){console.error(_chalk2.default.red(`Failed to restore from backup: ${r}`))}}return{}}}writeConfig(r){if(this.ensureConfigDir(),this.configExists())try{this.backupConfig()}catch(e){console.warn(_chalk2.default.yellow(`Warning: Failed to create backup: ${e}`))}try{let e=JSON.stringify(r,null,2);_fs.writeFileSync.call(void 0, this.configFile,e,"utf-8")}catch(e){throw new Error(`Failed to write config file: ${e instanceof Error?e.message:String(e)}`)}}backupConfig(){if(this.configExists())try{_fs.copyFileSync.call(void 0, this.configFile,this.backupFile)}catch(r){throw new Error(`Failed to backup config file: ${r instanceof Error?r.message:String(r)}`)}}restoreConfig(){if(!_fs.existsSync.call(void 0, this.backupFile))throw new Error("No backup file found");try{_fs.copyFileSync.call(void 0, this.backupFile,this.configFile)}catch(r){throw new Error(`Failed to restore config file: ${r instanceof Error?r.message:String(r)}`)}}getCredentials(r=_chunkP4NH5RQRcjs.d){try{let i=this.readConfig()[r];return i?typeof i!="object"||!i.provider||!i.model?(console.error(_chalk2.default.red(`Invalid credentials structure for profile '${r}'`)),null):i:null}catch(e){return console.error(_chalk2.default.red(`Error reading credentials: ${e}`)),null}}setCredentials(r,e=_chunkP4NH5RQRcjs.d){try{let i=this.readConfig();i[e]=r,this.writeConfig(i)}catch(i){throw new Error(`Failed to save credentials: ${i instanceof Error?i.message:String(i)}`)}}listProfiles(){try{let r=this.readConfig();return Object.keys(r).filter(e=>{let i=r[e];return i&&typeof i=="object"&&i.provider&&i.model})}catch(r){return console.error(_chalk2.default.red(`Error listing profiles: ${r}`)),[]}}deleteProfile(r){try{let e=this.readConfig();return r in e?(this.backupConfig(),delete e[r],this.writeConfig(e),!0):!1}catch(e){return console.error(_chalk2.default.red(`Error deleting profile: ${e}`)),!1}}getConfigFile(){return this.configFile}getConfigDir(){return this.configDir}getBackupFile(){return this.backupFile}};exports.a = a;
/* Rawi (راوي) is the developer-friendly AI CLI that brings the power of 12 major AI providers directly to your terminal. With seamless shell integration, persistent conversations, and 200+ specialized prompt templates, Rawi transforms your command line into an intelligent development workspace. */
//# sourceMappingURL=chunk-O3NIUWMW.cjs.map