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
15 lines • 6.45 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*as g from"fs/promises";import*as u from"path";import{select as p}from"@inquirer/prompts";import e from"chalk";import y from"cli-table3";var m=class{sessionManager;profile;constructor(o,s){this.sessionManager=o,this.profile=s}async showStatistics(o){try{console.log(e.cyan(`
\u{1F4CA} Session Statistics`)),console.log(e.gray("\u2500".repeat(50)));let s=await this.sessionManager.listSessions({profile:this.profile,fromDate:o.fromDate,toDate:o.toDate,type:"chat"}),t=s.length,a=s.reduce((i,c)=>i+(c.messageCount||0),0);if(t===0){console.log(e.yellow("\u{1F4DD} No sessions found."));return}let n=Math.round(a/t),r=s.reduce((i,c)=>new Date(c.createdAt)<new Date(i.createdAt)?c:i),l=s.reduce((i,c)=>new Date(c.createdAt)>new Date(i.createdAt)?c:i);console.log(e.white(`\u{1F4CB} Total Sessions: ${e.bold(t)}`)),console.log(e.white(`\u{1F4AC} Total Messages: ${e.bold(a)}`)),console.log(e.white(`\u{1F4C8} Average Messages per Session: ${e.bold(n)}`)),console.log(e.white(`\u{1F4C5} Date Range: ${this.formatDate(r.createdAt)} \u2192 ${this.formatDate(l.createdAt)}`));let d=s.sort((i,c)=>(c.messageCount||0)-(i.messageCount||0)).slice(0,5);console.log(e.cyan(`
\u{1F3C6} Most Active Sessions:`)),d.forEach((i,c)=>{let f=i.title||"Untitled",h=i.messageCount||0;console.log(e.white(`${c+1}. ${f} (${h} messages)`))})}catch(s){console.error(e.red(`\u274C Failed to show statistics: ${s}`))}}async backupSessions(o,s){try{console.log(e.cyan(`
\u{1F4BE} Backing up sessions to: ${o}`));let t=await this.sessionManager.exportSessions("json",{profile:this.profile,fromDate:s.fromDate,toDate:s.toDate}),a={timestamp:new Date().toISOString(),profile:this.profile,version:"1.0.0",data:t},n=u.dirname(o);await g.mkdir(n,{recursive:!0}),await g.writeFile(o,JSON.stringify(a,null,2),"utf8"),console.log(e.green("\u2705 Backup completed successfully!")),console.log(e.blue(`\u{1F4C1} File: ${o}`)),console.log(e.blue(`\u{1F4CA} Stats: ${a.data.sessions.length} sessions, ${Object.values(a.data.messages).flat().length} messages`))}catch(t){throw console.error(e.red(`\u274C Backup failed: ${t}`)),t}}async restoreSessions(o){try{console.log(e.cyan(`
\u{1F4E5} Restoring sessions from: ${o}`));let s=await g.readFile(o,"utf8"),t=JSON.parse(s);if(!t.data||!t.data.sessions)throw new Error("Invalid backup file format");console.log(e.yellow("\u26A0\uFE0F This will import sessions. Existing sessions with same IDs may be overwritten.")),console.log(e.blue(`\u{1F4CA} Backup contains: ${t.data.sessions.length} sessions, ${Object.values(t.data.messages).flat().length} messages`)),console.log(e.blue(`\u{1F4C5} Backup created: ${t.timestamp}`)),console.log(e.blue(`\u{1F464} Original profile: ${t.profile}`)),console.log(e.green("\u2705 Restore simulation completed!")),console.log(e.gray("Note: Actual restore functionality would be implemented with database operations."))}catch(s){throw console.error(e.red(`\u274C Restore failed: ${s}`)),s}}async batchDeleteSessions(o,s){try{console.log(e.cyan(`
\u{1F5D1}\uFE0F Batch delete sessions matching pattern: "${o}"`));let a=(await this.sessionManager.listSessions({profile:this.profile,fromDate:s.fromDate,toDate:s.toDate,type:"chat"})).filter(n=>{let r=(n.title||"").toLowerCase().includes(o.toLowerCase()),l=n.id.toLowerCase().includes(o.toLowerCase());return r||l});if(a.length===0){console.log(e.yellow(`\u{1F4DD} No sessions found matching pattern "${o}"`));return}console.log(e.yellow(`\u26A0\uFE0F Found ${a.length} sessions matching the pattern:`)),a.forEach(n=>{let r=n.title||"Untitled";console.log(e.white(` \u2022 ${r} (${n.id.substring(0,8)}...)`))}),console.log(e.red(`
\u{1F6A8} This would delete ${a.length} sessions!`)),console.log(e.gray("Note: Actual batch delete would require user confirmation."))}catch(t){throw console.error(e.red(`\u274C Batch delete failed: ${t}`)),t}}async formatSessions(o,s){switch(s){case"json":return JSON.stringify(o,null,2);case"summary":return this.formatSessionsSummary(o);default:return this.formatSessionsTable(o)}}formatSessionsTable(o){if(o.length===0)return e.yellow("No sessions found.");let s=new y({head:[e.cyan("ID"),e.cyan("Title"),e.cyan("Profile"),e.cyan("Messages"),e.cyan("Created"),e.cyan("Last Updated")],colWidths:[40,25,12,10,20,15],style:{head:[],border:["grey"],compact:!1}});return o.forEach(t=>{let a=t.title||"Untitled",n=t.messageCount||0,r=this.formatDate(t.createdAt),l=this.formatRelativeTime(t.updatedAt||t.createdAt);s.push([e.white(t.id),e.white(a.length>22?`${a.substring(0,19)}...`:a),e.gray(t.profile),e.yellow(n.toString()),e.gray(r),e.gray(l)])}),s.toString()}async selectSessionInteractively(o){if(o.length===0)return console.log(e.yellow("No sessions found.")),null;let s=o.map(t=>({name:`${t.title||"Untitled"} (${t.messageCount||0} messages) - ${this.formatRelativeTime(t.updatedAt)}`,value:t.id,description:`ID: ${t.id}`}));s.push({name:e.green("+ Create new session"),value:"new",description:"Start a fresh conversation"});try{let t=await p({message:"Select a session to continue:",choices:s,pageSize:10});return t==="new"?null:t}catch{return null}}formatRelativeTime(o){let s=Date.now(),t=new Date(o).getTime(),a=s-t,n=Math.floor(a/1e3),r=Math.floor(n/60),l=Math.floor(r/60),d=Math.floor(l/24);return d>0?`${d}d ago`:l>0?`${l}h ago`:r>0?`${r}m ago`:`${n}s ago`}formatSessionsSummary(o){if(o.length===0)return"No sessions found.";let s=e.cyan(`\u{1F4CB} Session Summary (${o.length} sessions)
`);return s+=`${e.gray("\u2500".repeat(50))}
`,o.forEach((t,a)=>{let n=t.title||"Untitled",r=t.messageCount||0,l=this.formatDate(t.updatedAt||t.createdAt);s+=e.white(`${a+1}. ${n}
`),s+=e.gray(` ${r} messages \u2022 ${l}
`),a<o.length-1&&(s+=`
`)}),s}formatDate(o){return new Date(o).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})}};export{m 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-KIOJGWD7.js.map