UNPKG

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

13 lines 12.5 kB
"use strict";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 _chunkMF4BUNPNcjs = require('./chunk-MF4BUNPN.cjs');var _chunk5GCADSBNcjs = require('./chunk-5GCADSBN.cjs');var _chunkP4NH5RQRcjs = require('./chunk-P4NH5RQR.cjs');var _promises = require('fs/promises');var _prompts = require('@inquirer/prompts');var _chalk = require('chalk'); var _chalk2 = _interopRequireDefault(_chalk);var _clitable3 = require('cli-table3'); var _clitable32 = _interopRequireDefault(_clitable3);var _commander = require('commander');var N=()=>{let c=new (0, _commander.Command)("history");return c.description([_chalk2.default.bold("Manage chat history and sessions."),"",_chalk2.default.gray("Search, filter, export, and clean up your AI chat history."),_chalk2.default.gray("Use --limit for pagination, --search for filtering.")].join(` `)).option("-p, --profile <profile>",_chalk2.default.white("Profile to show history for"),_chunkP4NH5RQRcjs.d).option("-l, --limit <number>",_chalk2.default.white("Number of sessions to show"),50 .toString()).option("--all",_chalk2.default.white("Show all sessions without pagination limit")).option("--all-profiles",_chalk2.default.white("Show sessions from all profiles")).option("-s, --search <query>",_chalk2.default.white("Search messages containing text")).option("--provider <provider>",_chalk2.default.white("Filter by AI provider")).option("--model <model>",_chalk2.default.white("Filter by AI model")).option("--from <date>",_chalk2.default.white("Show sessions from date (YYYY-MM-DD)")).option("--to <date>",_chalk2.default.white("Show sessions to date (YYYY-MM-DD)")).addHelpText("after",[_chalk2.default.bold.cyan(` See also:`),_chalk2.default.gray(" rawi history sessions"),_chalk2.default.gray(" rawi history show <sessionId>"),_chalk2.default.gray(" rawi history stats"),_chalk2.default.gray(" rawi history cleanup"),_chalk2.default.gray(" rawi history export")].join(` `)).action(async s=>{let t=null;try{t=new _chunkMF4BUNPNcjs.a;let o={profile:s.allProfiles?void 0:s.profile,limit:s.all?1e3:Number.parseInt(s.limit)||50,search:s.search,provider:s.provider,model:s.model,fromDate:s.from,toDate:s.to},r=10;if(s.search){let n=await t.searchMessages(o);if(n.length===0){console.log(_chalk2.default.yellow("\u{1F4ED} No messages found matching your search."));return}console.log(_chalk2.default.cyan(`\u{1F50D} Found ${n.length} messages:`)),console.log();let i=new (0, _clitable32.default)({head:[_chalk2.default.cyan("Session"),_chalk2.default.cyan("Role"),_chalk2.default.cyan("Content"),_chalk2.default.cyan("Time"),_chalk2.default.cyan("Provider/Model")],style:{head:["cyan"]},colWidths:[18,8,40,16,22],wordWrap:!0});n.forEach(l=>{i.push([_chunk5GCADSBNcjs.j.call(void 0, l.sessionId,16),l.role==="user"?_chalk2.default.blue("\u{1F464} user"):_chalk2.default.green("\u{1F916} assistant"),_chunk5GCADSBNcjs.j.call(void 0, l.content,38),_chunk5GCADSBNcjs.l.call(void 0, l.timestamp),`${l.provider}/${l.model}`])}),console.log(i.toString())}else{let n=s.allProfiles?"all profiles":`profile: ${o.profile}`;console.log(_chalk2.default.dim(`Searching for sessions with ${n}`));let i=await t.getSessions(o);if(i.length===0){console.log(_chalk2.default.yellow("\u{1F4ED} No chat sessions found.")),console.log(_chalk2.default.dim(`Run 'rawi ask "Hello"' to start your first conversation.`));return}let l=Math.ceil(i.length/r),p=0,w=f=>{let m=new (0, _clitable32.default)({head:[_chalk2.default.cyan("Title"),_chalk2.default.cyan("ID"),_chalk2.default.cyan("Profile"),_chalk2.default.cyan("Messages"),_chalk2.default.cyan("Updated")],style:{head:["cyan"]},colWidths:[22,38,12,10,18],wordWrap:!0});i.slice(f*r,(f+1)*r).forEach(g=>{m.push([_chunk5GCADSBNcjs.j.call(void 0, g.title||"Untitled",20),g.id,g.profile,g.messageCount,_chunk5GCADSBNcjs.l.call(void 0, g.updatedAt)])}),console.log(m.toString()),console.log(_chalk2.default.gray(`Page ${f+1} of ${l}`))};if(i.length>r){let f=!1;for(;!f;){w(p);let m=[];p>0&&m.push({name:"Previous",value:"prev"}),p<l-1&&m.push({name:"Next",value:"next"}),m.push({name:"Exit",value:"exit"});let g=await _prompts.select.call(void 0, {message:"Navigate pages:",choices:m,default:p<l-1?"next":"exit"});g==="prev"?p--:g==="next"?p++:f=!0,f||console.clear()}}else w(0)}console.log(_chalk2.default.dim("\u{1F4A1} Tips:")),console.log(_chalk2.default.dim(" \u2022 Use --search to find specific messages")),console.log(_chalk2.default.dim(" \u2022 Use --session <id> with ask command to continue a session")),console.log(_chalk2.default.dim(' \u2022 Use "rawi history sessions" to manage sessions'))}catch(o){console.error(_chalk2.default.red(`\u274C Error retrieving history: ${o instanceof Error?o.message:String(o)}`)),process.exit(1)}finally{t&&t.close()}}),c.command("sessions").description([_chalk2.default.bold("List and manage chat sessions."),"",_chalk2.default.gray("View, filter, and manage your chat sessions.")].join(` `)).option("-p, --profile <profile>",_chalk2.default.white("Profile to show sessions for"),_chunkP4NH5RQRcjs.d).option("-l, --limit <number>",_chalk2.default.white("Number of sessions to show"),50 .toString()).option("--all",_chalk2.default.white("Show all sessions without pagination limit")).action(async s=>{let t=null;try{t=new _chunkMF4BUNPNcjs.a;let o=await t.getSessions({profile:s.profile,limit:s.all?1e3:Number.parseInt(s.limit)||50});if(o.length===0){console.log(_chalk2.default.yellow("\u{1F4ED} No sessions found."));return}console.log(_chalk2.default.cyan(`\u{1F4AC} Sessions for profile "${s.profile}":`)),console.log();for(let r of o){let n=r.title||"Untitled Session";console.log(_chalk2.default.bold(`${n}`)),console.log(_chalk2.default.dim(` ID: ${r.id}`)),console.log(_chalk2.default.dim(` Messages: ${r.messageCount}`)),console.log(_chalk2.default.dim(` Created: ${_chunk5GCADSBNcjs.l.call(void 0, r.createdAt)}`)),console.log(_chalk2.default.dim(` Updated: ${_chunk5GCADSBNcjs.l.call(void 0, r.updatedAt)}`)),console.log()}}catch(o){console.error(_chalk2.default.red(`\u274C Error retrieving sessions: ${o instanceof Error?o.message:String(o)}`)),process.exit(1)}finally{t&&t.close()}}),c.command("show <sessionId>").description([_chalk2.default.bold("Show all messages in a specific session."),"",_chalk2.default.gray("Display the full conversation for a session.")].join(` `)).action(async s=>{let t=null;try{t=new _chunkMF4BUNPNcjs.a;let o=await t.getSession(s);o||(console.error(_chalk2.default.red(`\u274C Session '${s}' not found.`)),process.exit(1));let r=await t.getMessages(s);console.log(_chalk2.default.cyan(`\u{1F4AC} Session: ${o.title||"Untitled Session"}`)),console.log(_chalk2.default.dim(`Profile: ${o.profile} \u2022 Created: ${_chunk5GCADSBNcjs.l.call(void 0, o.createdAt)}`)),console.log(_chalk2.default.dim("\u2550".repeat(60))),console.log();for(let n of r){let i=n.role==="user"?"\u{1F464}":"\u{1F916}",l=n.role==="user"?_chalk2.default.blue:_chalk2.default.green;console.log(l.bold(`${i} ${n.role.toUpperCase()}:`)),console.log(n.content),console.log(_chalk2.default.dim(`${_chunk5GCADSBNcjs.l.call(void 0, n.timestamp)} \u2022 ${n.provider}/${n.model}`)),console.log()}}catch(o){console.error(_chalk2.default.red(`\u274C Error showing session: ${o instanceof Error?o.message:String(o)}`)),process.exit(1)}finally{t&&t.close()}}),c.command("delete <sessionId>").description([_chalk2.default.bold("Delete a specific session."),"",_chalk2.default.gray("Remove a chat session and its messages.")].join(` `)).action(async s=>{let t=null;try{t=new _chunkMF4BUNPNcjs.a;let o=await t.getSession(s);o||(console.error(_chalk2.default.red(`\u274C Session '${s}' not found.`)),process.exit(1)),await t.deleteSession(s)?console.log(_chalk2.default.green(`\u2705 Deleted session: ${o.title||s}`)):(console.error(_chalk2.default.red(`\u274C Failed to delete session '${s}'.`)),process.exit(1))}catch(o){console.error(_chalk2.default.red(`\u274C Error deleting session: ${o instanceof Error?o.message:String(o)}`)),process.exit(1)}finally{t&&t.close()}}),c.command("stats").description([_chalk2.default.bold("Show usage statistics."),"",_chalk2.default.gray("Display usage stats for your chat history.")].join(` `)).option("-p, --profile <profile>",_chalk2.default.white("Profile to show stats for")).action(async s=>{let t=null;try{t=new _chunkMF4BUNPNcjs.a;let o=await t.getStats(s.profile);if(console.log(_chalk2.default.cyan("\u{1F4CA} Usage Statistics:")),console.log(),console.log(_chalk2.default.bold("Overall:")),console.log(` Sessions: ${o.totalSessions}`),console.log(` Messages: ${o.totalMessages}`),o.oldestMessage&&console.log(` First message: ${_chunk5GCADSBNcjs.l.call(void 0, o.oldestMessage)}`),o.newestMessage&&console.log(` Latest message: ${_chunk5GCADSBNcjs.l.call(void 0, o.newestMessage)}`),console.log(),Object.keys(o.messagesByProvider).length>0){console.log(_chalk2.default.bold("By Provider:"));for(let[r,n]of Object.entries(o.messagesByProvider))console.log(` ${r}: ${n} messages`);console.log()}if(Object.keys(o.messagesByModel).length>0){console.log(_chalk2.default.bold("Top Models:"));let r=Object.entries(o.messagesByModel).sort(([,n],[,i])=>i-n).slice(0,10);for(let[n,i]of r)console.log(` ${n}: ${i} messages`);console.log()}if(!s.profile&&Object.keys(o.messagesByProfile).length>0){console.log(_chalk2.default.bold("By Profile:"));for(let[r,n]of Object.entries(o.messagesByProfile))console.log(` ${r}: ${n} messages`)}}catch(o){console.error(_chalk2.default.red(`\u274C Error retrieving stats: ${o instanceof Error?o.message:String(o)}`)),process.exit(1)}finally{t&&t.close()}}),c.command("cleanup").description([_chalk2.default.bold("Clean up old sessions."),"",_chalk2.default.gray("Delete sessions older than a specified number of days.")].join(` `)).option("-p, --profile <profile>",_chalk2.default.white("Profile to clean up"),_chunkP4NH5RQRcjs.d).option("-d, --days <number>",_chalk2.default.white("Delete sessions older than N days"),"30").option("--confirm",_chalk2.default.white("Confirm deletion without prompt")).action(async s=>{let t=null;try{t=new _chunkMF4BUNPNcjs.a;let o=Number.parseInt(s.days)||30;if(!s.confirm){console.log(_chalk2.default.yellow(`\u26A0\uFE0F This will delete sessions older than ${o} days for profile "${s.profile}".`)),console.log(_chalk2.default.yellow(" Add --confirm to proceed."));return}let r=await t.deleteOldSessions(s.profile,o);r>0?(console.log(_chalk2.default.green(`\u2705 Deleted ${r} old sessions.`)),t.vacuum(),console.log(_chalk2.default.dim("\u{1F4BE} Database optimized."))):console.log(_chalk2.default.blue("\u2139\uFE0F No old sessions found to delete."))}catch(o){console.error(_chalk2.default.red(`\u274C Error during cleanup: ${o instanceof Error?o.message:String(o)}`)),process.exit(1)}finally{t&&t.close()}}),c.command("export").description([_chalk2.default.bold("Export chat history to JSON."),"",_chalk2.default.gray("Save your chat history to a file for backup or analysis.")].join(` `)).option("-p, --profile <profile>",_chalk2.default.white("Profile to export")).option("-o, --output <file>",_chalk2.default.white("Output file path"),"rawi-history-export.json").action(async s=>{let t=null;try{t=new _chunkMF4BUNPNcjs.a;let o=await t.exportChatHistory({profile:s.profile}),r=JSON.stringify(o,null,2);await _promises.writeFile.call(void 0, s.output,r,"utf8"),console.log(_chalk2.default.green(`\u2705 Exported chat history to: ${s.output}`)),console.log(_chalk2.default.dim(` Sessions: ${o.sessions.length}`)),console.log(_chalk2.default.dim(` Total messages: ${Object.values(o.messages).flat().length}`))}catch(o){console.error(_chalk2.default.red(`\u274C Error exporting history: ${o instanceof Error?o.message:String(o)}`)),process.exit(1)}finally{t&&t.close()}}),c};exports.a = N; /* 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-Z6PI7SD3.cjs.map