UNPKG

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 7.75 kB
{"version":3,"sources":["/home/mkabumattar/work/withrawi/rawi/dist/chunk-IUCUN6N2.cjs","../src/core/content-filter/config.ts","../src/core/content-filter/content-filter.ts"],"names":["DEFAULT_FILTER_OPTIONS","getAvailablePatternTypes","ContentFilter","#options","#patterns","#customPatternDefinitions","options","loadFromDisk","loadFilterConfig","pattern","index"],"mappings":"AAAA;AACA,wDAAsD,wDAAyC,wBCD9B,4BAC9C,ICsBNA,CAAAA,CAAwC,CACnD,OAAA,CAAS,CAAA,CAAA,CACT,KAAA,CAAOC,iCAAAA,CAAyB,CAChC,YAAA,CAAc,CAAA,CAAA,CACd,iBAAA,CAAmB,CAAA,CACrB,CAAA,CAEaC,CAAAA,aAAN,KAAoB,CACzBC,CAAAA,CAAAA,CACAC,CAAAA,CAAAA,CACAC,CAAAA,CAAAA,CAEA,WAAA,CAAYC,CAAAA,CAAkC,CAAC,CAAA,CAAGC,CAAAA,CAAe,CAAA,CAAA,CAAO,CAClEA,CAAAA,CACF,IAAA,CAAKJ,CAAAA,CAAAA,CAAW,CACd,GAAGK,CAAAA,CAAiB,CAAA,CACpB,GAAGF,CACL,CAAA,CAEA,IAAA,CAAKH,CAAAA,CAAAA,CAAW,CACd,GAAGH,CAAAA,CACH,GAAGM,CACL,CAAA,CAGF,IAAA,CAAKD,CAAAA,CAAAA,CAA4B,CAAC,CAAA,CAC9B,IAAA,CAAKF,CAAAA,CAAAA,CAAS,cAAA,EAAA,CAChB,IAAA,CAAKE,CAAAA,CAAAA,CAA4B,IAAA,CAAKF,CAAAA,CAAAA,CAAS,cAAA,CAAe,GAAA,CAC5D,CAACM,CAAAA,CAASC,CAAAA,CAAAA,EAAAA,CAAW,CACnB,IAAA,CAAM,CAAA,OAAA,EAAUA,CAAK,CAAA,CAAA;AFlDwa","file":"/home/mkabumattar/work/withrawi/rawi/dist/chunk-IUCUN6N2.cjs","sourcesContent":[null,"import {existsSync, mkdirSync, readFileSync, writeFileSync} from 'node:fs';\nimport {join} from 'node:path';\nimport {getConfigDir} from '../shared/index.js';\nimport {DEFAULT_FILTER_OPTIONS, type FilterOptions} from './content-filter.js';\n\nexport const getFilterConfigPath = (): string => {\n const configDir = getConfigDir();\n return join(configDir, 'filter-config.json');\n};\n\nconst ensureConfigDir = (): void => {\n const configDir = getConfigDir();\n if (!existsSync(configDir)) {\n mkdirSync(configDir, {recursive: true});\n }\n};\n\nexport const loadFilterConfig = (): FilterOptions => {\n const configPath = getFilterConfigPath();\n\n if (!existsSync(configPath)) {\n return {...DEFAULT_FILTER_OPTIONS};\n }\n\n try {\n const content = readFileSync(configPath, 'utf-8');\n const config = JSON.parse(content);\n\n return {\n ...DEFAULT_FILTER_OPTIONS,\n ...config,\n };\n } catch (error) {\n console.error(\n `Error loading filter configuration: ${error instanceof Error ? error.message : String(error)}`,\n );\n return {...DEFAULT_FILTER_OPTIONS};\n }\n};\n\nexport const saveFilterConfig = (config: FilterOptions): boolean => {\n try {\n ensureConfigDir();\n const configPath = getFilterConfigPath();\n const content = JSON.stringify(config, null, 2);\n writeFileSync(configPath, content, 'utf-8');\n return true;\n } catch (error) {\n console.error(\n `Error saving filter configuration: ${error instanceof Error ? error.message : String(error)}`,\n );\n return false;\n }\n};\n\nexport const resetFilterConfig = (): boolean => {\n return saveFilterConfig({...DEFAULT_FILTER_OPTIONS});\n};\n","import {loadFilterConfig, resetFilterConfig, saveFilterConfig} from './config';\nimport {\n applyPattern,\n getAvailablePatternTypes,\n getPatternByType,\n type PatternDefinition,\n} from './patterns';\n\nexport interface FilterOptions {\n enabled: boolean;\n types: string[];\n showFiltered: boolean;\n highlightFiltered?: boolean;\n customPatterns?: RegExp[];\n}\n\nexport interface FilterResult {\n filteredText: string;\n filterCount: Record<string, number>;\n originalText?: string;\n highlightedText?: string;\n}\n\nexport const DEFAULT_FILTER_OPTIONS: FilterOptions = {\n enabled: true,\n types: getAvailablePatternTypes(),\n showFiltered: false,\n highlightFiltered: false,\n};\n\nexport class ContentFilter {\n #options: FilterOptions;\n #patterns: PatternDefinition[];\n #customPatternDefinitions: PatternDefinition[];\n\n constructor(options: Partial<FilterOptions> = {}, loadFromDisk = false) {\n if (loadFromDisk) {\n this.#options = {\n ...loadFilterConfig(),\n ...options,\n };\n } else {\n this.#options = {\n ...DEFAULT_FILTER_OPTIONS,\n ...options,\n };\n }\n\n this.#customPatternDefinitions = [];\n if (this.#options.customPatterns) {\n this.#customPatternDefinitions = this.#options.customPatterns.map(\n (pattern, index) => ({\n type: `custom-${index}`,\n pattern,\n replacement: '[CUSTOM_FILTERED]',\n description: `Custom pattern ${index + 1}`,\n }),\n );\n }\n\n this.#patterns = this.#getActivePatterns();\n }\n\n public filterContent(text: string): FilterResult {\n if (!this.#options.enabled || !text) {\n return {\n filteredText: text,\n filterCount: {},\n ...(this.#options.showFiltered ? {originalText: text} : {}),\n ...(this.#options.highlightFiltered ? {highlightedText: text} : {}),\n };\n }\n\n let filteredText = text;\n const filterCount: Record<string, number> = {};\n let highlightedText = text;\n\n for (const pattern of this.#patterns) {\n const result = applyPattern(filteredText, pattern);\n filteredText = result.filteredText;\n\n if (result.count > 0) {\n filterCount[pattern.type] = result.count;\n\n if (this.#options.highlightFiltered) {\n const regex = pattern.pattern;\n highlightedText = highlightedText.replace(regex, (match) => {\n return `\\x1b[43m\\x1b[30m${match}\\x1b[0m`;\n });\n }\n }\n }\n\n return {\n filteredText,\n filterCount,\n ...(this.#options.showFiltered ? {originalText: text} : {}),\n ...(this.#options.highlightFiltered ? {highlightedText} : {}),\n };\n }\n\n public getAvailableFilterTypes(): string[] {\n return getAvailablePatternTypes();\n }\n\n public enableFilterTypes(types: string[]): void {\n this.#options.types = types;\n this.#patterns = this.#getActivePatterns();\n }\n\n public setEnabled(enabled: boolean): void {\n this.#options.enabled = enabled;\n }\n\n public setShowFiltered(show: boolean): void {\n this.#options.showFiltered = show;\n }\n\n public setHighlightFiltered(highlight: boolean): void {\n this.#options.highlightFiltered = highlight;\n }\n\n public addCustomPattern(\n pattern: RegExp,\n replacement = '[CUSTOM_FILTERED]',\n description = 'Custom pattern',\n ): string {\n const type = `custom-${this.#customPatternDefinitions.length}`;\n\n const patternDef: PatternDefinition = {\n type,\n pattern,\n replacement,\n description,\n };\n\n this.#customPatternDefinitions.push(patternDef);\n this.#patterns = this.#getActivePatterns();\n\n return type;\n }\n\n public getOptions(): FilterOptions {\n return {...this.#options};\n }\n\n public loadConfiguration(): FilterOptions {\n const config = loadFilterConfig();\n this.#options = {\n ...config,\n customPatterns: this.#options.customPatterns,\n };\n this.#patterns = this.#getActivePatterns();\n return this.getOptions();\n }\n\n public saveConfiguration(): boolean {\n return saveFilterConfig(this.getOptions());\n }\n\n public resetConfiguration(): boolean {\n const success = resetFilterConfig();\n if (success) {\n this.#options = {...DEFAULT_FILTER_OPTIONS};\n this.#patterns = this.#getActivePatterns();\n }\n return success;\n }\n\n #getActivePatterns(): PatternDefinition[] {\n const activePatterns: PatternDefinition[] = [];\n\n for (const type of this.#options.types) {\n const pattern = getPatternByType(type);\n if (pattern) {\n activePatterns.push(pattern);\n }\n }\n\n activePatterns.push(...this.#customPatternDefinitions);\n\n return activePatterns;\n }\n}\n"]}