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
12 lines • 10.2 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 }; } async function _asyncOptionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = await fn(value); } else if (op === 'call' || op === 'optionalCall') { value = await fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }/* 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 _chunkTEI25NEMcjs = require('./chunk-TEI25NEM.cjs');var _chunk4SSU7T3Fcjs = require('./chunk-4SSU7T3F.cjs');var _chunkIBIBJOYAcjs = require('./chunk-IBIBJOYA.cjs');var _chunkLSK3BZJVcjs = require('./chunk-LSK3BZJV.cjs');var _chunkZ6VHHQRQcjs = require('./chunk-Z6VHHQRQ.cjs');var _chunkFAD6MIW3cjs = require('./chunk-FAD6MIW3.cjs');var _promises = require('readline/promises'); var b = _interopRequireWildcard(_promises);var _chalk = require('chalk'); var _chalk2 = _interopRequireDefault(_chalk);var R=async(i,e)=>{let t=e.profile||_chunkFAD6MIW3cjs.d;_chunkLSK3BZJVcjs.a.call(void 0, t,e);let r=_chunkLSK3BZJVcjs.c.call(void 0, t,e),a=new (0, _chunkIBIBJOYAcjs.a)(i),g=new (0, _chunkTEI25NEMcjs.a)(a,t);if(e.stats){await g.showStatistics(e);return}else if(e.backup){await g.backupSessions(e.backup,e);return}else if(e.restore){await g.restoreSessions(e.restore);return}else if(e.batchDelete){await g.batchDeleteSessions(e.batchDelete,e);return}e.verbose&&(console.log(_chalk2.default.dim(`\u{1F517} Connected to ${r.provider} (${r.model})`)),console.log(_chalk2.default.dim(`\u{1F4C1} Profile: ${t}`)),e.act&&console.log(_chalk2.default.dim(`\u{1F3AD} Act template: ${e.act}`)));let n,c=[];if(e.session)try{let o=await a.getSession(e.session,t);n=o.id,c=await i.getMessages(n),e.verbose&&(console.log(_chalk2.default.dim(`\u{1F4DD} Continuing session: ${o.title||"Untitled"} (${n.substring(0,8)}...)`)),console.log(_chalk2.default.dim(`\u{1F4AC} Loaded ${c.length} previous messages`)))}catch(o){console.error(_chalk2.default.red(`\u274C Failed to load session: ${o}`));return}else if(e.listSessions){await C(a,t,e);return}else if(e.deleteSession){await D(a,e.deleteSession);return}else if(e.exportSessions){await x(a,t,e);return}else if(e.renameSession&&e.newTitle){await v(a,e.renameSession,e.newTitle,t);return}else if(e.newSession){let o=e.act?`${e.act} Chat`:void 0;n=await a.createSession(t,{title:o,generateTitle:!o,type:"chat"}),e.verbose&&console.log(_chalk2.default.dim(`\u{1F195} Created new session: ${n.substring(0,8)}...`))}else{let o=new (0, _chunkTEI25NEMcjs.a)(a,t),d=await a.listSessions({profile:t,limit:10,type:"chat"});if(d.length>0&&!e.newSession){let l=await o.selectSessionInteractively(d);if(l)n=l,c=await i.getMessages(n),e.verbose&&console.log(_chalk2.default.dim(`\u{1F504} Continuing session: ${n.substring(0,8)}... (${c.length} messages)`));else{let m=e.act?`${e.act} Chat`:void 0;n=await a.createSession(t,{title:m,generateTitle:!m,type:"chat"}),e.verbose&&console.log(_chalk2.default.dim(`\u{1F195} Created new session: ${n.substring(0,8)}...`))}}else{let l=e.act?`${e.act} Chat`:void 0;n=await a.createSession(t,{title:l,generateTitle:!l,type:"chat"}),e.verbose&&console.log(_chalk2.default.dim(`\u{1F195} Created new session: ${n.substring(0,8)}...`))}}if(e.act&&c.length===0)try{if(await _asyncOptionalChain([(await _chunkZ6VHHQRQcjs.a.call(void 0, e.act,"",e)), 'optionalAccess', async _ => _.trim, 'call', async _2 => _2()])){let d={role:"assistant",content:`I'm now acting as: ${e.act}. How can I help you?`,provider:r.provider,model:r.model,timestamp:new Date().toISOString()};c.push(d),await i.addMessage(n,d.role,d.content,r.provider,r.model),e.verbose&&console.log(_chalk2.default.dim(`\u{1F3AD} Applied act template: ${e.act}`))}}catch(o){console.error(_chalk2.default.red(`\u274C Error applying act template: ${o}`));return}console.log(_chalk2.default.bold.blue("\u{1F916} Welcome to Rawi Chat!")),console.log(_chalk2.default.gray(`Start typing your message. Use /quit or /exit to end the chat.
`)),e.verbose&&console.log(_chalk2.default.dim(`\u{1F4AC} Session: ${n.substring(0,8)}... | Type "/help" for commands
`));let h=b.createInterface({input:process.stdin,output:process.stdout});try{for(;;){let o;try{o=await h.question(_chalk2.default.blue("You: "))}catch(l){if(l instanceof Error&&"code"in l&&l.code==="ERR_USE_AFTER_CLOSE"){console.log(_chalk2.default.yellow(`
\u{1F44B} Chat session ended (stdin closed)`));break}throw l}if(o.trim()==="/quit"||o.trim()==="/exit"){console.log(_chalk2.default.yellow(`
\u{1F44B} Goodbye!`));break}if(o.trim()==="/help"){console.log(_chalk2.default.cyan(`
\u{1F4DA} Chat Commands:`)),console.log(_chalk2.default.gray(" /help - Show this help message")),console.log(_chalk2.default.gray(" /quit - Exit the chat")),console.log(_chalk2.default.gray(" /exit - Exit the chat")),console.log(_chalk2.default.gray(" /clear - Clear message history")),console.log(_chalk2.default.gray(" /session - Show current session info")),console.log(_chalk2.default.gray(" /rename - Rename current session")),console.log("");continue}if(o.trim()==="/clear"){c.length=0,console.log(_chalk2.default.dim(`\u{1F9F9} Message history cleared (local only)
`));continue}if(o.trim()==="/session"){await M(a,n);continue}if(o.trim().startsWith("/rename ")){let l=o.trim().substring(8).trim();l?await v(a,n,l,t):console.log(_chalk2.default.red("\u274C Please provide a new title: /rename <new title>"));continue}if(o.trim()==="")continue;let d={role:"user",content:o.trim(),timestamp:new Date().toISOString()};c.push(d),await i.addMessage(n,d.role,d.content,r.provider,r.model);try{let m={role:"assistant",content:await _chunk4SSU7T3Fcjs.a.call(void 0, r,c,e,h),provider:r.provider,model:r.model,timestamp:new Date().toISOString()};c.push(m),await i.addMessage(n,m.role,m.content,r.provider,r.model)}catch(l){console.error(_chalk2.default.red(`\u274C Error: ${l}`))}}}catch(o){console.error(_chalk2.default.red(`\u274C Error in chat session: ${o}`))}finally{h.close()}};async function C(i,e,t){try{let r=new (0, _chunkTEI25NEMcjs.a)(i,e),a=await i.listSessions({profile:e,limit:t.limit||10,fromDate:t.fromDate,toDate:t.toDate,type:"chat"});if(a.length===0){console.log(_chalk2.default.yellow("No sessions found for this profile."));return}if(t.listSessions){let n=t.format||"table",c=await r.formatSessions(a,n);console.log(c),n==="table"&&(console.log(_chalk2.default.cyan(`
\u{1F4A1} Tips:`)),console.log(_chalk2.default.gray("\u2022 Copy the full ID from the table above")),console.log(_chalk2.default.gray("\u2022 Use: ")+_chalk2.default.white("rawi chat --session <full-id>")),console.log(_chalk2.default.gray("\u2022 Or use: ")+_chalk2.default.white("rawi chat")+_chalk2.default.gray(" for interactive selection")));return}let g=await r.selectSessionInteractively(a);console.log(g?_chalk2.default.green(`\u{1F680} Continuing session: ${g}`):_chalk2.default.blue("\u{1F195} Starting new session..."))}catch(r){console.error(_chalk2.default.red(`\u274C Failed to handle session selection: ${r}`))}}async function D(i,e){try{let t=await i.deleteSession(e,{force:!0});console.log(t?_chalk2.default.green(`\u2705 Session ${e.substring(0,8)}... deleted successfully.`):_chalk2.default.yellow(`\u26A0\uFE0F Session ${e.substring(0,8)}... not found or already deleted.`))}catch(t){console.error(_chalk2.default.red(`\u274C Failed to delete session: ${t}`))}}async function x(i,e,t){try{let r=new (0, _chunkTEI25NEMcjs.a)(i,e),a=t.format||"json",g=typeof t.exportSessions=="string"?"json":a,n=await i.exportSessions(g,{profile:e,fromDate:t.fromDate,toDate:t.toDate,...t.limit&&{limit:t.limit}});if(typeof t.exportSessions=="string")console.log(_chalk2.default.green(`\u2705 Sessions exported to ${t.exportSessions}`));else{let c=await r.formatSessions(n.sessions,a);console.log(c)}}catch(r){console.error(_chalk2.default.red(`\u274C Failed to export sessions: ${r}`))}}async function v(i,e,t,r){try{await i.updateSessionTitle(e,t,r),console.log(_chalk2.default.green(`\u2705 Session renamed to: ${t}`))}catch(a){console.error(_chalk2.default.red(`\u274C Failed to rename session: ${a}`))}}async function M(i,e){try{let t=await i.getSession(e);console.log(_chalk2.default.cyan(`
\u{1F4CA} Current Session Info:`)),console.log(_chalk2.default.gray("\u2550".repeat(30))),console.log(`${_chalk2.default.dim("ID:")} ${_chalk2.default.white(t.id.substring(0,16))}...`),console.log(`${_chalk2.default.dim("Title:")} ${_chalk2.default.white(t.title||"Untitled")}`),console.log(`${_chalk2.default.dim("Profile:")} ${_chalk2.default.white(t.profile)}`),console.log(`${_chalk2.default.dim("Messages:")} ${_chalk2.default.white(t.messageCount)}`),console.log(`${_chalk2.default.dim("Created:")} ${_chalk2.default.gray(new Date(t.createdAt).toLocaleString())}`),console.log(`${_chalk2.default.dim("Updated:")} ${_chalk2.default.gray(new Date(t.updatedAt).toLocaleString())}`),console.log("")}catch(t){console.error(_chalk2.default.red(`\u274C Failed to get session info: ${t}`))}}exports.a = R;
/* 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-FFLVUBDU.cjs.map