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
1 lines • 6.45 kB
Source Map (JSON)
{"version":3,"sources":["/home/mkabumattar/work/withrawi/rawi/dist/chunk-RR5M76YJ.cjs","../src/core/file-readers/readers/text.reader.ts"],"names":["TextReader","AbstractFileReader","options","fileType","filePath","startTime"],"mappings":"AAAA;AACA,wDAAwC,wBCDX,4BACP,IASTA,CAAAA,CAAN,MAAA,QAAyBC,mBAAmB,CACjD,WAAA,CAAYC,CAAAA,CAA6B,CAAC,CAAA,CAAG,CAC3C,KAAA,CAAMA,CAAO,CACf,CAEA,OAAA,CAAQC,CAAAA,CAAsC,CAiB5C,MAhBsB,CAAA,KAAA,CAAA,IAAA,CAAA,IAAA,CAAA,IAAA,CAAA,MAAA,CAAA,IAAA,CAAA,KAAA,CAAA,MAAA,CAAA,KAAA,CAAA,KAAA,CAAA,MAAA,CAAA,KAAA,CAAA,KActB,CAAA,CAEqB,QAAA,CAASA,CAAQ,CACxC,CAEA,MAAM,IAAA,CAAKC,CAAAA,CAA6C,CACtD,IAAMC,CAAAA,CAAY,IAAA,CAAK,GAAA,CAAI,CAAA,CAE3B,GAAI,CACF,MAAM,IAAA,CAAK,YAAA,CAAaD,CAAQ,CAAA,CAChC,IAAA,CAAK,UAAA,CAAW,CAAA,8BAAA,EAAiCA,CAAQ,CAAA,CAAA;AA8B5B;AA6B7B;AD/F8W","file":"/home/mkabumattar/work/withrawi/rawi/dist/chunk-RR5M76YJ.cjs","sourcesContent":[null,"import {promises as fs} from 'node:fs';\nimport {extname} from 'node:path';\nimport type {\n FileReaderOptions,\n FileReaderResult,\n SupportedFileType,\n} from '../interfaces/types.js';\nimport {SupportedFileType as FileType} from '../interfaces/types.js';\nimport {AbstractFileReader} from './base.reader.js';\n\nexport class TextReader extends AbstractFileReader {\n constructor(options: FileReaderOptions = {}) {\n super(options);\n }\n\n canRead(fileType: SupportedFileType): boolean {\n const textFileTypes = [\n FileType.TXT,\n FileType.JS,\n FileType.TS,\n FileType.PY,\n FileType.JSON,\n FileType.MD,\n FileType.YML,\n FileType.YAML,\n FileType.CSV,\n FileType.XML,\n FileType.HTML,\n FileType.CSS,\n FileType.SQL,\n ];\n\n return textFileTypes.includes(fileType);\n }\n\n async read(filePath: string): Promise<FileReaderResult> {\n const startTime = Date.now();\n\n try {\n await this.validateFile(filePath);\n this.logVerbose(`Starting text extraction for: ${filePath}`);\n\n const encoding = (this.options.encoding as BufferEncoding) || 'utf-8';\n const content = await fs.readFile(filePath, encoding);\n const ext = extname(filePath).toLowerCase();\n\n const {size} = await this.getFileStats(filePath);\n const processingTime = Date.now() - startTime;\n\n this.logVerbose(`Text extraction completed in ${processingTime}ms`);\n\n const fileTypeContext = this.#getFileTypeContext(ext);\n const text = fileTypeContext\n ? `[${fileTypeContext}]\\n${content}`\n : content;\n\n if (!content.trim()) {\n throw new Error(\n 'File appears to be empty or contains no readable text',\n );\n }\n\n const metadata = this.createMetadata(\n filePath,\n size,\n ext.substring(1) || 'txt',\n processingTime,\n this.#getMimeType(ext),\n {\n encoding: this.options.encoding || 'utf-8',\n lineCount: content.split('\\n').length,\n characterCount: content.length,\n hasContext: !!fileTypeContext,\n },\n );\n\n return {\n success: true,\n content: {\n text: text.trim(),\n metadata,\n },\n };\n } catch (error) {\n this.logVerbose(`Text extraction failed: ${error}`);\n return {\n success: false,\n error: error instanceof Error ? error.message : String(error),\n };\n }\n }\n\n #getFileTypeContext(extension: string): string | null {\n const contexts: Record<string, string> = {\n '.js': 'JavaScript Code',\n '.jsx': 'React JavaScript Code',\n '.ts': 'TypeScript Code',\n '.tsx': 'React TypeScript Code',\n '.py': 'Python Code',\n '.json': 'JSON Data',\n '.md': 'Markdown Document',\n '.yml': 'YAML Configuration',\n '.yaml': 'YAML Configuration',\n '.csv': 'CSV Data',\n '.xml': 'XML Document',\n '.html': 'HTML Document',\n '.htm': 'HTML Document',\n '.css': 'CSS Stylesheet',\n '.sql': 'SQL Query',\n '.sh': 'Shell Script',\n '.bash': 'Bash Script',\n '.php': 'PHP Code',\n '.java': 'Java Code',\n '.cpp': 'C++ Code',\n '.c': 'C Code',\n '.h': 'C/C++ Header',\n '.go': 'Go Code',\n '.rs': 'Rust Code',\n '.rb': 'Ruby Code',\n '.kt': 'Kotlin Code',\n '.swift': 'Swift Code',\n '.dart': 'Dart Code',\n '.scala': 'Scala Code',\n '.r': 'R Code',\n '.m': 'MATLAB Code',\n '.pl': 'Perl Code',\n '.lua': 'Lua Script',\n '.vim': 'Vim Script',\n '.env': 'Environment Variables',\n '.ini': 'Configuration File',\n '.conf': 'Configuration File',\n '.cfg': 'Configuration File',\n '.toml': 'TOML Configuration',\n '.dockerfile': 'Dockerfile',\n '.makefile': 'Makefile',\n '.gitignore': 'Git Ignore File',\n '.log': 'Log File',\n };\n\n return contexts[extension] || null;\n }\n\n #getMimeType(extension: string): string {\n const mimeTypes: Record<string, string> = {\n '.txt': 'text/plain',\n '.js': 'application/javascript',\n '.jsx': 'application/javascript',\n '.ts': 'application/x-typescript',\n '.tsx': 'application/x-typescript',\n '.py': 'text/x-python',\n '.json': 'application/json',\n '.md': 'text/markdown',\n '.yml': 'application/x-yaml',\n '.yaml': 'application/x-yaml',\n '.csv': 'text/csv',\n '.xml': 'application/xml',\n '.html': 'text/html',\n '.htm': 'text/html',\n '.css': 'text/css',\n '.sql': 'application/sql',\n '.sh': 'application/x-sh',\n '.bash': 'application/x-sh',\n '.php': 'application/x-php',\n '.java': 'text/x-java-source',\n '.cpp': 'text/x-c++src',\n '.c': 'text/x-csrc',\n '.h': 'text/x-chdr',\n '.go': 'text/x-go',\n '.rs': 'text/x-rust',\n '.rb': 'application/x-ruby',\n '.kt': 'text/x-kotlin',\n '.swift': 'text/x-swift',\n '.dart': 'application/dart',\n '.scala': 'text/x-scala',\n '.r': 'text/x-r-source',\n '.m': 'text/x-matlab',\n '.pl': 'application/x-perl',\n '.lua': 'text/x-lua',\n '.vim': 'text/x-vim',\n '.env': 'text/plain',\n '.ini': 'text/plain',\n '.conf': 'text/plain',\n '.cfg': 'text/plain',\n '.toml': 'application/toml',\n '.log': 'text/plain',\n };\n\n return mimeTypes[extension] || 'text/plain';\n }\n}\n"]}