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
4 lines • 4.1 kB
JavaScript
/* 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. */
import{a as c,c as o}from"./chunk-VSPMROUG.js";import{a as S}from"./chunk-74BMVZGU.js";var h=class{#e;#t=new Map;#a;constructor(s,t={}){this.#e=s||new S,this.#a={autoSave:!0,saveInterval:3e4,maxHistoryEntries:100,...t}}async restoreSessionState(s,t={}){try{let e=this.#t.get(s);if(e)return await this.#i(s),e;let a=await this.#e.getSession(s);if(!a)throw new c(s,"unknown");let{includeMessages:i=!0,messageLimit:n=100}=t,r=[];i&&(r=await this.#e.getMessages(s),n&&r.length>n&&(r=r.slice(-n)));let d={session:a,messages:r,isActive:!0,lastAccessedAt:new Date().toISOString(),messageCount:a.messageCount,metadata:await this.#o(s)};return this.#t.set(s,d),await this.#s(s,"accessed","Session restored"),d}catch(e){throw e instanceof c?e:new o(`Failed to restore session state: ${e instanceof Error?e.message:"Unknown error"}`,e instanceof Error?e:void 0)}}async persistSessionState(s){try{let t=this.#t.get(s);if(!t)throw new c(s,"unknown");await this.#n(s,t.metadata),t.lastAccessedAt=new Date().toISOString(),await this.#s(s,"updated","Session state persisted")}catch(t){throw new o(`Failed to persist session state: ${t instanceof Error?t.message:"Unknown error"}`,t instanceof Error?t:void 0)}}async addMessageToSession(s,t){try{let e=this.#t.get(s);if(!e)return await this.restoreSessionState(s),this.addMessageToSession(s,t);e.messages.push(t),e.messageCount=e.messages.length,e.lastAccessedAt=new Date().toISOString(),t.provider&&!e.metadata.providers.includes(t.provider)&&(e.metadata.providers.push(t.provider),e.metadata.lastProvider=t.provider),t.model&&!e.metadata.models.includes(t.model)&&(e.metadata.models.push(t.model),e.metadata.lastModel=t.model),this.#a.autoSave&&await this.persistSessionState(s),await this.#s(s,"message_added",`${t.role} message added`)}catch(e){throw new o(`Failed to add message to session: ${e instanceof Error?e.message:"Unknown error"}`,e instanceof Error?e:void 0)}}async updateSessionTitle(s,t){try{let e=this.#t.get(s);e&&(e.session.title=t,e.lastAccessedAt=new Date().toISOString()),await this.#e.updateSessionTitle(s,t),this.#a.autoSave&&await this.persistSessionState(s),await this.#s(s,"title_changed",`Title changed to: ${t}`)}catch(e){throw new o(`Failed to update session title: ${e instanceof Error?e.message:"Unknown error"}`,e instanceof Error?e:void 0)}}async getSessionHistory(s){try{return[]}catch{throw new o("Failed to get session history",void 0)}}async deactivateSession(s){try{let t=this.#t.get(s);t&&(await this.persistSessionState(s),t.isActive=!1,this.#t.delete(s))}catch(t){throw new o(`Failed to deactivate session: ${t instanceof Error?t.message:"Unknown error"}`,t instanceof Error?t:void 0)}}getActiveSessionIds(){return Array.from(this.#t.keys())}getActiveSessionState(s){return this.#t.get(s)}async cleanupInactiveSessions(s=36e5){let t=Date.now(),e=[];for(let[a,i]of this.#t.entries()){let n=new Date(i.lastAccessedAt).getTime();t-n>s&&e.push(a)}for(let a of e)await this.deactivateSession(a)}async#i(s){let t=this.#t.get(s);t&&(t.lastAccessedAt=new Date().toISOString())}async#o(s){try{let t=await this.#e.getMessages(s),e=[...new Set(t.map(i=>i.provider).filter(Boolean))],a=[...new Set(t.map(i=>i.model).filter(Boolean))];return{providers:e,models:a,lastProvider:e[e.length-1],lastModel:a[a.length-1],tags:[],customData:{}}}catch{return{providers:[],models:[],tags:[],customData:{}}}}async#n(s,t){}async#s(s,t,e,a){console.debug(`Session ${s}: ${t} - ${e}`)}};export{h as a};
/* 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-GKJTHFMS.js.map