rawi
Version:
Rawi (راوي) is the developer-friendly AI CLI that brings the power of 11 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 • 3.79 kB
JavaScript
/* Rawi (راوي) is the developer-friendly AI CLI that brings the power of 11 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. */
import{c as a,d as f}from"./chunk-A65FQHKW.js";import{d as c}from"./chunk-YGEDZIJR.js";import{copyFileSync as l,existsSync as n,mkdirSync as d,readdirSync as u,readFileSync as h,writeFileSync as p}from"fs";import{join as s}from"path";import t from"chalk";var g=class{configDir;configFile;backupFile;constructor(){this.configDir=a(),this.configFile=f(),this.backupFile=s(this.configDir,`backup.credentials.${new Date().toISOString().replace(/[:.]/g,"-")}.rawi`)}ensureConfigDir(){if(!n(this.configDir))try{d(this.configDir,{recursive:!0})}catch(e){throw new Error(`Failed to create config directory: ${e instanceof Error?e.message:String(e)}`)}}configExists(){return n(this.configFile)}readConfig(){if(!n(this.configFile))return{};try{let e=h(this.configFile,"utf-8"),r=JSON.parse(e);if(typeof r!="object"||r===null)throw new Error("Invalid configuration format");return r}catch{if(console.error(t.yellow("Warning: Failed to read config file, using empty config.")),n(this.backupFile)){console.log(t.blue("Attempting to restore from backup..."));try{return this.restoreConfig(),this.readConfig()}catch(e){console.error(t.red(`Failed to restore from backup: ${e}`))}}return{}}}writeConfig(e){if(this.ensureConfigDir(),this.configExists())try{this.backupConfig()}catch(r){console.warn(t.yellow(`Warning: Failed to create backup: ${r}`))}try{let r=JSON.stringify(e,null,2);p(this.configFile,r,"utf-8")}catch(r){throw new Error(`Failed to write config file: ${r instanceof Error?r.message:String(r)}`)}}backupConfig(){if(!this.configExists())return;let e=new Date().toISOString().replace(/[:.]/g,"-"),r=s(this.configDir,`backup.credentials.${e}.rawi`);try{l(this.configFile,r)}catch(i){throw new Error(`Failed to backup config file: ${i instanceof Error?i.message:String(i)}`)}}restoreConfig(){let e=u(this.configDir).filter(o=>o.startsWith("backup.credentials.")&&o.endsWith(".rawi"));if(e.length===0)throw new Error("No backup file found");let r=e.sort().pop();if(!r)throw new Error("No backup file found");let i=s(this.configDir,r);try{l(i,this.configFile)}catch(o){throw new Error(`Failed to restore config file: ${o instanceof Error?o.message:String(o)}`)}}getCredentials(e=c){try{let i=this.readConfig()[e];return i?typeof i!="object"||!i.provider||!i.model?(console.error(t.red(`Invalid credentials structure for profile '${e}'`)),null):i:null}catch(r){return console.error(t.red(`Error reading credentials: ${r}`)),null}}setCredentials(e,r=c){try{let i=this.readConfig();i[r]=e,this.writeConfig(i)}catch(i){throw new Error(`Failed to save credentials: ${i instanceof Error?i.message:String(i)}`)}}listProfiles(){try{let e=this.readConfig();return Object.keys(e).filter(r=>{let i=e[r];return i&&typeof i=="object"&&i.provider&&i.model})}catch(e){return console.error(t.red(`Error listing profiles: ${e}`)),[]}}deleteProfile(e){try{let r=this.readConfig();return e in r?(this.backupConfig(),delete r[e],this.writeConfig(r),!0):!1}catch(r){return console.error(t.red(`Error deleting profile: ${r}`)),!1}}getConfigFile(){return this.configFile}getConfigDir(){return this.configDir}getBackupFile(){return this.backupFile}};export{g as a};
/* Rawi (راوي) is the developer-friendly AI CLI that brings the power of 11 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-KLFNRVV6.js.map