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
1 lines • 9.95 kB
Source Map (JSON)
{"version":3,"sources":["/home/mkabumattar/withrawi/rawi/dist/chunk-MF4BUNPN.cjs","../src/core/database/manager.ts"],"names":["DatabaseManager","DatabaseAdapter","debugLog","err","error","profile","title","sessionId","options","role","content","provider","model","temperature","maxTokens","metadata","limit","sessions","errorMessage","initError","initErrorMessage","days","uuidv4"],"mappings":"AAAA;AACA,wDAAwC,wDAAyC,4BCDtD,IAUdA,CAAAA,WAAN,KAAsB,CACnB,eACA,WAAA,CAAc,CAAA,EAAA,gBACd,WAAA,CAAoC,KAAA,WAE5C,CAAA,CAAc,yEACZ,IAAA,CAAK,OAAA,CAAU,IAAIC,mBAAAA,CAEnB,IAAA,CAAK,WAAA,CAAc,IAAA,CAAK,OAAA,CACrB,yBAAA,CAA0B,CAAA,CAC1B,IAAA,CAAK,CAAA,CAAA,EAAM,CACV,IAAA,CAAK,WAAA,CAAc,CAAA,CAAA,CACnBC,iCAAAA,0CAAmD,CACrD,CAAC,CAAA,CACA,KAAA,CAAOC,CAAAA,EAAQ,CACd,OAAA,CAAQ,KAAA,CACN,oDAAA,CACAA,CACF,CACF,CAAC,CACL,CAEA,MAAc,iBAAA,CAAA,CAAmC,CAC/C,EAAA,CAAI,CAAA,IAAA,CAAK,WAAA,CAIT,CAAA,EAAA,CAAI,IAAA,CAAK,WAAA,CACP,GAAI,CACF,MAAM,IAAA,CAAK,WAAA,CACX,MACF,CAAA,UAAiB,CACfD,iCAAAA,6CAAsD,CACxD,CAGF,GAAI,CACFA,iCAAAA,kCAA2C,CAAA,CAC3C,MAAM,IAAA,CAAK,OAAA,CAAQ,yBAAA,CAA0B,CAAA,CAC7C,IAAA,CAAK,WAAA,CAAc,CAAA,CACrB,CAAA,KAAA,CAASE,CAAAA,CAAO,CACd,MAAA,OAAA,CAAQ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cjs","sourcesContent":[null,"import {v4 as uuidv4} from 'uuid';\nimport {\n type ChatHistoryOptions,\n type ChatMessage,\n type ChatSession,\n debugLog,\n type HistoryStats,\n} from '../shared/index.js';\nimport {DatabaseAdapter} from './adapter.js';\n\nexport class DatabaseManager {\n private adapter: DatabaseAdapter;\n private initialized = false;\n private initPromise: Promise<void> | null = null;\n\n constructor() {\n this.adapter = new DatabaseAdapter();\n\n this.initPromise = this.adapter\n .ensureDatabaseInitialized()\n .then(() => {\n this.initialized = true;\n debugLog('Database manager initialization complete');\n })\n .catch((err) => {\n console.error(\n 'Failed to initialize database during construction:',\n err,\n );\n });\n }\n\n private async ensureInitialized(): Promise<void> {\n if (this.initialized) {\n return;\n }\n\n if (this.initPromise) {\n try {\n await this.initPromise;\n return;\n } catch (_error) {\n debugLog('Initial initialization failed, trying again');\n }\n }\n\n try {\n debugLog('Explicitly initializing database');\n await this.adapter.ensureDatabaseInitialized();\n this.initialized = true;\n } catch (error) {\n console.error('Failed to initialize database:', error);\n throw new Error('Database initialization failed');\n }\n }\n\n async createSession(profile: string, title?: string): Promise<string> {\n await this.ensureInitialized();\n return this.adapter.createSession(profile, title);\n }\n\n async getSession(sessionId: string): Promise<ChatSession | null> {\n await this.ensureInitialized();\n return this.adapter.getSession(sessionId);\n }\n\n async getSessions(options: ChatHistoryOptions = {}): Promise<ChatSession[]> {\n await this.ensureInitialized();\n return this.adapter.getSessions(options);\n }\n\n async deleteSession(sessionId: string): Promise<boolean> {\n await this.ensureInitialized();\n return this.adapter.deleteSession(sessionId);\n }\n\n async updateSessionTitle(sessionId: string, title: string): Promise<boolean> {\n await this.ensureInitialized();\n return this.adapter.updateSessionTitle(sessionId, title);\n }\n\n async addMessage(\n sessionId: string,\n role: 'user' | 'assistant',\n content: string,\n provider: string,\n model: string,\n temperature?: number,\n maxTokens?: number,\n metadata?: any,\n ): Promise<string> {\n await this.ensureInitialized();\n return this.adapter.addMessage(\n sessionId,\n role,\n content,\n provider,\n model,\n temperature,\n maxTokens,\n metadata,\n );\n }\n\n async getMessages(sessionId: string, limit?: number): Promise<ChatMessage[]> {\n await this.ensureInitialized();\n return this.adapter.getMessages(sessionId, limit);\n }\n\n async searchMessages(\n options: ChatHistoryOptions = {},\n ): Promise<ChatMessage[]> {\n await this.ensureInitialized();\n return this.adapter.searchMessages(options);\n }\n\n async getStats(profile?: string): Promise<HistoryStats> {\n await this.ensureInitialized();\n return this.adapter.getStats(profile);\n }\n\n async close(): Promise<void> {\n await this.adapter.close();\n }\n\n async getCurrentSession(profile: string): Promise<string> {\n try {\n await this.ensureInitialized();\n\n const sessions = await this.getSessions({profile, limit: 1});\n\n if (sessions.length > 0) {\n return sessions[0].id;\n }\n\n debugLog('No existing sessions found, creating a new one');\n return this.createSession(profile);\n } catch (error: unknown) {\n const errorMessage =\n error instanceof Error ? error.message : 'Unknown error';\n debugLog('Error getting current session:', errorMessage);\n\n try {\n debugLog(\n 'Attempting to ensure database is initialized before creating new session',\n );\n await this.adapter.ensureDatabaseInitialized();\n this.initialized = true;\n\n debugLog('Creating new session');\n return this.createSession(profile);\n } catch (initError: unknown) {\n const initErrorMessage =\n initError instanceof Error ? initError.message : 'Unknown error';\n console.error(\n 'Serious error: Cannot initialize database or create session normally:',\n initErrorMessage,\n );\n debugLog('Attempting emergency session creation');\n\n return this.createEmergencySession(profile);\n }\n }\n }\n\n async deleteOldSessions(profile: string, days: number): Promise<number> {\n await this.ensureInitialized();\n return this.adapter.deleteOldSessions(profile, days);\n }\n\n async vacuum(): Promise<void> {\n await this.ensureInitialized();\n return this.adapter.vacuum();\n }\n\n async exportChatHistory(options: ChatHistoryOptions = {}): Promise<{\n sessions: ChatSession[];\n messages: Record<string, ChatMessage[]>;\n stats: HistoryStats;\n }> {\n await this.ensureInitialized();\n return this.adapter.exportChatHistory(options);\n }\n\n async createEmergencySession(profile: string): Promise<string> {\n try {\n debugLog('Creating emergency session without database checks');\n return this.adapter.createSession(profile);\n } catch (_error) {\n const sessionId = uuidv4();\n debugLog('Generated emergency session ID directly:', sessionId);\n return sessionId;\n }\n }\n}\n"]}