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
9 lines • 6.91 kB
JavaScript
Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }/* 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. */
var _promises = require('readline/promises'); var u = _interopRequireWildcard(_promises);var _chalk = require('chalk'); var _chalk2 = _interopRequireDefault(_chalk);var p=class{constructor(e,s){this.sessionManager=e,this.profile=s}searchSessions(e,s){if(!s.trim())return e;let n=s.toLowerCase();return e.filter(o=>{let a=(o.title||"").toLowerCase().includes(n),i=o.profile.toLowerCase().includes(n),r=o.id.toLowerCase().includes(n);return a||i||r})}formatDate(e){return new Date(e).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}truncateText(e,s){return e.length<=s?e:`${e.substring(0,s-3)}...`}async selectSession(e={}){let{showPreview:s=!0,enableSearch:n=!0,allowCreateNew:o=!0,maxResults:a=10}=e;console.log(_chalk2.default.cyan(`
\u{1F50D} Session Selection`)),console.log(_chalk2.default.gray("\u2500".repeat(50)));let i=await this.sessionManager.listSessions({profile:this.profile,limit:a,type:"chat"});if(i.length===0)return console.log(_chalk2.default.yellow("\u{1F4DD} No existing sessions found.")),o&&console.log(_chalk2.default.green("\u{1F195} Creating a new session...")),null;if(n&&i.length>5){let g=await this.promptForSearch();if(g&&(i=this.searchSessions(i,g),i.length===0))return console.log(_chalk2.default.yellow(`\u{1F50D} No sessions found matching "${g}"`)),this.selectSession(e)}this.displaySessionList(i,s);let r=await this.promptForSelection(i.length,o);if(r===-1||r===-2)return null;let l=i[r],c=await this.showSessionActionMenu(l);switch(c.action){case"continue":return l.id;case"delete":return await this.sessionManager.deleteSession(l.id,{force:!0}),console.log(_chalk2.default.green(`\u2705 Session "${l.title}" deleted.`)),this.selectSession(e);case"rename":return c.newTitle&&(await this.sessionManager.updateSessionTitle(l.id,c.newTitle,this.profile),console.log(_chalk2.default.green(`\u2705 Session renamed to "${c.newTitle}"`))),this.selectSession(e);case"export":return await this.exportSession(l),this.selectSession(e);case"create-new":return null;default:return null}}async promptForSearch(){let e=u.createInterface({input:process.stdin,output:process.stdout});try{return(await e.question(_chalk2.default.blue("\u{1F50D} Search sessions (or press Enter to skip): "))).trim()||null}finally{e.close()}}displaySessionList(e,s){console.log(_chalk2.default.cyan(`
\u{1F4CB} Available Sessions (${e.length})`)),console.log(_chalk2.default.gray("\u2500".repeat(50))),e.forEach((n,o)=>{let a=_chalk2.default.cyan(`${o+1}.`),i=_chalk2.default.white(n.title),r=_chalk2.default.gray(this.formatDate(n.updatedAt)),l=_chalk2.default.yellow(`(${n.messageCount||0} messages)`);if(console.log(`${a} ${i} ${l}`),console.log(` ${_chalk2.default.gray("Last updated:")} ${r}`),s&&n.title){let c=this.truncateText(n.title,80);console.log(` ${_chalk2.default.gray("Title preview:")} ${_chalk2.default.italic(c)}`)}console.log()})}async promptForSelection(e,s){let n=u.createInterface({input:process.stdin,output:process.stdout});try{let o=_chalk2.default.blue(`
\u{1F3AF} Select session (1-${e})`);s&&(o+=_chalk2.default.blue(', "n" for new')),o+=_chalk2.default.blue(', or "q" to quit: ');let i=(await n.question(o)).trim().toLowerCase();if(i==="q"||i==="quit")return-2;if(i==="n"||i==="new")return-1;let r=Number.parseInt(i,10)-1;return Number.isNaN(r)||r<0||r>=e?(console.log(_chalk2.default.red("\u274C Invalid selection. Please try again.")),this.promptForSelection(e,s)):r}finally{n.close()}}async showSessionActionMenu(e){console.log(_chalk2.default.cyan(`
\u26A1 Actions for "${e.title}"`)),console.log(_chalk2.default.gray("\u2500".repeat(50))),console.log(_chalk2.default.white("1. Continue chat")),console.log(_chalk2.default.yellow("2. Rename session")),console.log(_chalk2.default.blue("3. Export session")),console.log(_chalk2.default.red("4. Delete session")),console.log(_chalk2.default.green("5. Create new session")),console.log(_chalk2.default.gray("6. Cancel"));let s=u.createInterface({input:process.stdin,output:process.stdout});try{switch((await s.question(_chalk2.default.blue(`
\u{1F3AF} Select action (1-6): `))).trim()){case"1":return{action:"continue",sessionId:e.id};case"2":{let o=await s.question(_chalk2.default.blue("\u{1F4DD} Enter new title: "));return o.trim()?{action:"rename",sessionId:e.id,newTitle:o.trim()}:{action:"cancel"}}case"3":return{action:"export",sessionId:e.id};case"4":return(await s.question(_chalk2.default.red(`\u26A0\uFE0F Delete "${e.title}"? (y/N): `))).toLowerCase()==="y"?{action:"delete",sessionId:e.id}:{action:"cancel"};case"5":return{action:"create-new"};default:return{action:"cancel"}}}finally{s.close()}}async exportSession(e){try{let s=await this.sessionManager.exportSessions("json",{profile:this.profile,sessions:[e.id]}),n=`session-${e.id.substring(0,8)}-${new Date().toISOString().split("T")[0]}.json`;console.log(_chalk2.default.green("\u2705 Session export prepared:")),console.log(_chalk2.default.blue(`\u{1F4C1} Filename: ${n}`)),console.log(_chalk2.default.gray(`\u{1F4CA} Stats: ${s.sessions.length} session, ${Object.values(s.messages).flat().length} messages`)),console.log(_chalk2.default.gray("\u{1F4CB} Export data structure created successfully"))}catch(s){console.error(_chalk2.default.red(`\u274C Export failed: ${s}`))}}async quickSelectSession(e){let s=await this.sessionManager.listSessions({profile:this.profile,limit:20,type:"chat"});if(s.length===0)return null;let n=s;if(e){if(n=this.searchSessions(s,e),n.length===0)return console.log(_chalk2.default.yellow(`\u{1F50D} No sessions found matching "${e}"`)),null;if(n.length===1){let o=n[0];return console.log(_chalk2.default.green(`\u{1F3AF} Found session: "${o.title}"`)),o.id}}return this.selectSession({showPreview:!0,enableSearch:!1,allowCreateNew:!0,maxResults:10})}};exports.a = p;
/* 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-XTIYUVOQ.cjs.map
;