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 loc) 10.4 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 _chunk2VSUGZSRcjs = require('./chunk-2VSUGZSR.cjs');var _chunkPAKWO5INcjs = require('./chunk-PAKWO5IN.cjs');var _chunk4RFN2JBIcjs = require('./chunk-4RFN2JBI.cjs');var _chunk7D7CXXN7cjs = require('./chunk-7D7CXXN7.cjs');var _chunkK5NJVUL4cjs = require('./chunk-K5NJVUL4.cjs');var _chunkMF4BUNPNcjs = require('./chunk-MF4BUNPN.cjs');var _chunkOJLMC7PNcjs = require('./chunk-OJLMC7PN.cjs');var _chunkP4NH5RQRcjs = require('./chunk-P4NH5RQR.cjs');var _chalk = require('chalk'); var _chalk2 = _interopRequireDefault(_chalk);var _commander = require('commander');var R=()=>new Promise(p=>{let y="";if(process.stdin.isTTY){p("");return}process.stdin.setEncoding("utf8"),process.stdin.on("data",r=>{y+=r}),process.stdin.on("end",()=>{p(y.trim())})}),G= exports.a =()=>{let p=new (0, _commander.Command)("ask");return p.description([_chalk2.default.bold("Ask AI a question and get a response."),"",_chalk2.default.gray("Supports piped input from stdin and file processing."),_chalk2.default.gray("Use --act <template> for expert prompt templates."),_chalk2.default.gray('See all templates with "rawi act --list".')].join(` `)).argument("[query]",_chalk2.default.white("The question or prompt to send to the AI (can be combined with piped input or file content)")).option("-p, --profile <profile>",_chalk2.default.white("Profile to use for AI configuration"),_chunkP4NH5RQRcjs.d).option("-s, --session <sessionId>",_chalk2.default.white("Continue an existing chat session")).option("-n, --new-session",_chalk2.default.white("Start a new chat session")).option("--act <template>",_chalk2.default.white("Use an act template (e.g., ethereum-developer)")).option("-f, --file <path>",_chalk2.default.white("Process content from a file (PDF, DOCX, PPTX, XLSX, ODT, ODP, ODS, TXT, etc.)")).option("-F, --files <paths...>",_chalk2.default.white("Process content from multiple files")).option("-b, --batch <patterns...>",_chalk2.default.white('Process files matching glob patterns (e.g., "src/**/*.js" "docs/*.md")')).option("--parallel",_chalk2.default.white("Process multiple files in parallel (faster for many files)")).option("--max-concurrency <number>",_chalk2.default.white("Maximum number of files to process concurrently (default: 5)"),"5").option("--continue-on-error",_chalk2.default.white("Continue processing other files if one fails")).option("--file-type <type>",_chalk2.default.white("Override automatic file type detection (pdf, docx, pptx, xlsx, odt, odp, ods, txt, etc.)")).option("--verbose",_chalk2.default.white("Show detailed status and debug information")).addHelpText("after",[_chalk2.default.bold.cyan(` Examples:`),_chalk2.default.gray(' rawi ask "What is this document about?" --file report.pdf'),_chalk2.default.gray(' rawi ask "Analyze this data" --file data.xlsx'),_chalk2.default.gray(' rawi ask "Review this code" --file src/app.js'),_chalk2.default.gray(' rawi ask "Summarize" --file document.docx --act technical-writer'),_chalk2.default.gray(' echo "Additional context" | rawi ask "Analyze" --file data.json'),"",_chalk2.default.bold.cyan("Batch Processing:"),_chalk2.default.gray(' rawi ask "Review these files" --files file1.js file2.py file3.md'),_chalk2.default.gray(' rawi ask "Analyze source code" --batch "src/**/*.{js,ts}"'),_chalk2.default.gray(' rawi ask "Review docs" --batch "docs/**/*.md" --parallel'),_chalk2.default.gray(' rawi ask "Check configs" --batch "**/*.{json,yml,yaml}" --continue-on-error'),"",_chalk2.default.bold.cyan("See also:"),_chalk2.default.gray(" rawi act --list"),_chalk2.default.gray(" rawi provider --list"),_chalk2.default.gray(" rawi configure --show"),_chalk2.default.gray(" rawi ask --help")].join(` `)).action(async(y,r)=>{let i=null;try{let v=await R(),g="";if(r.file||r.files||r.batch){r.verbose&&console.log(_chalk2.default.dim("\u{1F4C4} Processing files..."));try{let s;if(r.fileType){let w=r.fileType.toUpperCase();w in _chunkPAKWO5INcjs.a?s=_chunkPAKWO5INcjs.a[w]:(console.error(_chalk2.default.red(`\u274C Unsupported file type: ${r.fileType}`)),console.log(_chalk2.default.yellow("Supported types: pdf, docx, pptx, xlsx, odt, odp, ods, txt, js, jsx, ts, tsx, py, java, cpp, c, go, rs, rb, kt, swift, dart, scala, php, json, md, yml, yaml, xml, html, css, sql, sh, bash, env, ini, conf, toml, log, and more")),process.exit(1))}let d=new (0, _chunk2VSUGZSRcjs.a)({verbose:r.verbose,forceFileType:s}),m,x=0;if(r.file)m=await d.readFile(r.file),m.success&&m.content?(g=m.content.text,x=1):(console.error(_chalk2.default.red(`\u274C Failed to process file: ${m.error}`)),process.exit(1));else{let w=Number.parseInt(r.maxConcurrency)||5,C={parallel:r.parallel,maxConcurrency:w,continueOnError:r.continueOnError,fileType:r.fileType,onProgress:r.verbose?(b,u,l)=>{console.log(_chalk2.default.dim(`\u{1F4DD} [${b}/${u}] Processing: ${l}`))}:void 0},a;if(r.files?a=await d.processMultipleFiles(r.files,C):r.batch&&(a=await d.processGlobPatterns(r.batch,C)),a){let b=[],u=0;for(let l of a.results)l.result.success&&l.result.content&&(b.push(`=== ${l.filePath} === ${l.result.content.text} `),u++);if(g=b.join(` `),x=a.totalFiles,r.verbose&&(console.log(_chalk2.default.dim(`\u2705 Successfully processed ${u}/${a.totalFiles} files`)),console.log(_chalk2.default.dim(`\u23F1\uFE0F Total time: ${(a.totalProcessingTime/1e3).toFixed(2)}s`)),console.log(_chalk2.default.dim(`\u{1F4CA} Total content length: ${g.length} characters`)),a.failedFiles>0)){console.log(_chalk2.default.yellow(`\u26A0\uFE0F ${a.failedFiles} files failed to process:`));for(let l of a.errors)console.log(_chalk2.default.yellow(` \u2022 ${l.filePath}: ${l.error}`))}u===0&&(console.error(_chalk2.default.red("\u274C No files were processed successfully")),process.exit(1))}}r.verbose&&x===1&&(console.log(_chalk2.default.dim("\u2705 Successfully processed file")),console.log(_chalk2.default.dim(`\u{1F4CA} Content length: ${g.length} characters`)))}catch(s){let d=s instanceof Error?s.message:"Unknown error occurred";console.error(_chalk2.default.red(`\u274C Error processing file: ${d}`)),process.exit(1)}}let f,T=[y,v,g].filter(Boolean);if(T.length===0){p.help();return}if(f=T.join(` `),r.act)try{f=_chunk7D7CXXN7cjs.d.call(void 0, r.act,f),r.verbose&&console.log(_chalk2.default.dim(`\u{1F3AD} Using act template: ${r.act}`))}catch(s){let d=s instanceof Error?s.message:"Unknown error occurred";r.verbose&&(console.error(_chalk2.default.red(`\u274C ${d}`)),console.log(_chalk2.default.yellow('\u{1F4A1} Use "rawi act --list" to see available templates.')));return}let n=r.profile||_chunkP4NH5RQRcjs.d;_chunk4RFN2JBIcjs.b.call(void 0, n)||(r.verbose&&(console.error(_chalk2.default.red(`\u274C Profile '${n}' does not exist or is not properly configured.`)),console.error(_chalk2.default.yellow(`Run 'rawi configure -p ${n}' to set up this profile.`))),process.exit(1)),i=new _chunkMF4BUNPNcjs.a;let t;if(r.newSession)t=await i.createSession(n),r.verbose&&console.log(_chalk2.default.dim(`\u{1F195} Started new session: ${t}`));else if(r.session){t=r.session;let s=await i.getSession(t);s||(r.verbose&&console.error(_chalk2.default.red(`\u274C Session '${t}' not found.`)),process.exit(1)),s.profile!==n&&(r.verbose&&console.error(_chalk2.default.red(`\u274C Session '${t}' belongs to profile '${s.profile}', not '${n}'.`)),process.exit(1)),r.verbose&&console.log(_chalk2.default.dim(`\u{1F504} Continuing session: ${t}`))}else t=await i.getCurrentSession(n),r.verbose&&console.log(_chalk2.default.dim(`\u{1F4DD} Using current session: ${t}`));r.verbose&&(console.log(`Using profile: ${n}`),console.log(`Processing query: ${f.length>100?`${f.substring(0,100)}...`:f}`)),r.verbose&&_chunkOJLMC7PNcjs.b.start("validation","Validating configuration...");let o=_chunk4RFN2JBIcjs.a.call(void 0, n);o||(r.verbose&&(_chunkOJLMC7PNcjs.b.fail("validation","Configuration validation failed"),console.error(_chalk2.default.red(`\u274C Unable to load credentials for profile '${n}'.`))),process.exit(1)),r.verbose&&_chunkOJLMC7PNcjs.b.succeed("validation","Configuration validated successfully"),await i.addMessage(t,"user",f,o.provider,o.model,o.temperature,o.maxTokens),r.verbose&&_chunkOJLMC7PNcjs.b.start("generation",`Streaming response using ${o.provider} (${o.model})...`,{color:"cyan"}),console.log(`${_chalk2.default.cyan("Result:")}`);let h,k=!1;try{h=await _chunkK5NJVUL4cjs.b.call(void 0, o,f,{streaming:!0,onChunk:s=>{k||(r.verbose&&_chunkOJLMC7PNcjs.b.succeed("generation","Starting to stream response..."),k=!0),process.stdout.write(s)},onComplete:()=>{console.log(),r.verbose&&console.log(_chalk2.default.dim("\u2705 Streaming completed"))},onError:s=>{r.verbose&&(_chunkOJLMC7PNcjs.b.fail("generation","Failed to generate response"),console.error(_chalk2.default.red(`\u274C ${s.message}`)))}}),await i.addMessage(t,"assistant",h,o.provider,o.model,o.temperature,o.maxTokens),r.verbose&&_chunkOJLMC7PNcjs.b.succeed("generation","Response streamed successfully!")}catch(s){r.verbose&&(_chunkOJLMC7PNcjs.b.fail("generation","Failed to generate response"),console.error(_chalk2.default.red(`\u274C ${s instanceof Error?s.message:String(s)}`))),h=`Unable to generate response using ${o.provider} (${o.model}). Error: ${s instanceof Error?s.message:String(s)}`,await i.addMessage(t,"assistant",h,o.provider,o.model,o.temperature,o.maxTokens,{error:!0})}if(r.verbose){let s=await i.getSession(t);s&&console.log(_chalk2.default.dim(` \u{1F4AC} Session: ${t} (${s.messageCount} messages)`))}}catch(v){r.verbose&&console.error("Error processing query:",v),process.exit(1)}finally{i&&i.close()}}),p};exports.a = G; /* 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-65B2KITR.cjs.map