{"version":3,"sources":["/home/mkabumattar/work/withrawi/rawi/dist/chunk-Z56DRU3M.cjs","../src/core/session/session-utils.ts"],"names":["SessionFormatUtils","formatSessionTable","sessions","headers","rows","session","lowerQuery"],"mappings":"AAAA;ACMO,IAAUA,CAAAA,CAAAA,CAAAA,CAAAA,EAAV,CACE,SAASC,CAAAA,CAAmBC,CAAAA,CAAiC,CAClE,EAAA,CAAIA,CAAAA,CAAS,MAAA,GAAW,CAAA,CACtB,MAAO,oBAAA,CAGT,IAAMC,CAAAA,CAAU,CACd,IAAA,CACA,OAAA,CACA,SAAA,CACA,UAAA,CACA,SAAA,CACA,cACF,CAAA,CACMC,CAAAA,CAAOF,CAAAA,CAAS,GAAA,CAAKG,CAAAA,EAAY,CACrC,CAAA,EAAA;AAwBS;AACkC;AACF;AACA;AAC4C;AAAA;AAE5E;AACA;AAI8C;AACsB;AACd;AAAA;AAY5C;AASX;AACqC;AACE;AACK;AACjB;AAGe;AAIN;AAa5C;AAkDYC;ADjIkI","file":"/home/mkabumattar/work/withrawi/rawi/dist/chunk-Z56DRU3M.cjs","sourcesContent":[null,"import type {\n  SessionDisplayInfo,\n  SessionStats,\n} from '../../cli/commands/chat/types.js';\nimport type {ChatSession} from '../shared/types.js';\n\nexport namespace SessionFormatUtils {\n  export function formatSessionTable(sessions: ChatSession[]): string {\n    if (sessions.length === 0) {\n      return 'No sessions found.';\n    }\n\n    const headers = [\n      'ID',\n      'Title',\n      'Profile',\n      'Messages',\n      'Created',\n      'Last Updated',\n    ];\n    const rows = sessions.map((session) => [\n      `${session.id.substring(0, 8)}...`,\n      session.title || 'Untitled',\n      session.profile,\n      session.messageCount.toString(),\n      formatDate(session.createdAt),\n      formatRelativeTime(session.updatedAt),\n    ]);\n\n    return createTable(headers, rows);\n  }\n\n  export function formatSessionJSON(sessions: ChatSession[]): string {\n    return JSON.stringify(sessions, null, 2);\n  }\n\n  export function formatSessionSummary(sessions: ChatSession[]): string {\n    if (sessions.length === 0) {\n      return 'No sessions found.';\n    }\n\n    const totalMessages = sessions.reduce((sum, s) => sum + s.messageCount, 0);\n    const profiles = [...new Set(sessions.map((s) => s.profile))];\n\n    let summary = '📊 Session Summary\\n';\n    summary += '═══════════════════\\n';\n    summary += `Total Sessions: ${sessions.length}\\n`;\n    summary += `Total Messages: ${totalMessages}\\n`;\n    summary += `Profiles: ${profiles.join(', ')}\\n`;\n    summary += `Average Messages per Session: ${Math.round(totalMessages / sessions.length)}\\n\\n`;\n\n    summary += 'Recent Sessions:\\n';\n    summary += '════════════════\\n';\n\n    const recentSessions = sessions.slice(0, 5);\n    recentSessions.forEach((session, index) => {\n      summary += `${index + 1}. ${session.title || 'Untitled'}\\n`;\n      summary += `   Profile: ${session.profile} | Messages: ${session.messageCount}\\n`;\n      summary += `   Updated: ${formatRelativeTime(session.updatedAt)}\\n\\n`;\n    });\n\n    return summary;\n  }\n\n  export function toDisplayInfo(session: ChatSession): SessionDisplayInfo {\n    return {\n      id: session.id,\n      title: session.title || 'Untitled Chat',\n      profile: session.profile,\n      createdAt: session.createdAt,\n      updatedAt: session.updatedAt,\n      messageCount: session.messageCount,\n      lastActivity: session.updatedAt,\n      age: formatRelativeTime(session.updatedAt),\n    };\n  }\n\n  export function formatSessionStats(stats: SessionStats): string {\n    let output = '📈 Session Statistics\\n';\n    output += '══════════════════════\\n';\n    output += `Total Messages: ${stats.messageCount}\\n`;\n    output += `Created: ${formatDate(stats.createdAt)}\\n`;\n    output += `Last Updated: ${formatDate(stats.updatedAt)}\\n`;\n    output += `Duration: ${stats.duration}\\n`;\n\n    if (stats.providers.length > 0) {\n      output += `Providers: ${stats.providers.join(', ')}\\n`;\n    }\n\n    if (stats.models.length > 0) {\n      output += `Models: ${stats.models.join(', ')}\\n`;\n    }\n\n    return output;\n  }\n\n  function formatDate(dateString: string): string {\n    const date = new Date(dateString);\n    return date.toLocaleDateString('en-US', {\n      year: 'numeric',\n      month: 'short',\n      day: 'numeric',\n      hour: '2-digit',\n      minute: '2-digit',\n    });\n  }\n\n  function formatRelativeTime(dateString: string): string {\n    const now = Date.now();\n    const date = new Date(dateString).getTime();\n    const diffMs = now - date;\n\n    const diffSeconds = Math.floor(diffMs / 1000);\n    const diffMinutes = Math.floor(diffSeconds / 60);\n    const diffHours = Math.floor(diffMinutes / 60);\n    const diffDays = Math.floor(diffHours / 24);\n\n    if (diffDays > 0) return `${diffDays}d ago`;\n    if (diffHours > 0) return `${diffHours}h ago`;\n    if (diffMinutes > 0) return `${diffMinutes}m ago`;\n    return `${diffSeconds}s ago`;\n  }\n\n  function createTable(headers: string[], rows: string[][]): string {\n    const widths = headers.map((header, i) => {\n      const cellWidths = rows.map((row) => row[i]?.length || 0);\n      return Math.max(header.length, ...cellWidths);\n    });\n\n    const headerRow = headers\n      .map((header, i) => header.padEnd(widths[i]))\n      .join(' │ ');\n    const separator = widths.map((w) => '─'.repeat(w)).join('─┼─');\n\n    const dataRows = rows.map((row) =>\n      row.map((cell, i) => cell.padEnd(widths[i])).join(' │ '),\n    );\n\n    return [headerRow, separator, ...dataRows].join('\\n');\n  }\n}\n\nexport namespace SessionSearchUtils {\n  export function filterSessions(\n    sessions: ChatSession[],\n    query: string,\n  ): ChatSession[] {\n    if (!query.trim()) return sessions;\n\n    const lowerQuery = query.toLowerCase();\n    return sessions.filter((session) => {\n      const titleMatch = (session.title || '')\n        .toLowerCase()\n        .includes(lowerQuery);\n      const profileMatch = session.profile.toLowerCase().includes(lowerQuery);\n      const idMatch = session.id.toLowerCase().includes(lowerQuery);\n\n      return titleMatch || profileMatch || idMatch;\n    });\n  }\n\n  export function filterByDateRange(\n    sessions: ChatSession[],\n    fromDate?: string,\n    toDate?: string,\n  ): ChatSession[] {\n    let filtered = sessions;\n\n    if (fromDate) {\n      const from = new Date(fromDate).getTime();\n      filtered = filtered.filter(\n        (session) => new Date(session.createdAt).getTime() >= from,\n      );\n    }\n\n    if (toDate) {\n      const to = new Date(toDate).getTime();\n      filtered = filtered.filter(\n        (session) => new Date(session.createdAt).getTime() <= to,\n      );\n    }\n\n    return filtered;\n  }\n\n  export function filterByProfile(\n    sessions: ChatSession[],\n    profile: string,\n  ): ChatSession[] {\n    return sessions.filter((session) => session.profile === profile);\n  }\n\n  export function sortSessions(\n    sessions: ChatSession[],\n    sortBy: 'createdAt' | 'updatedAt' | 'title' | 'messageCount' = 'updatedAt',\n    order: 'asc' | 'desc' = 'desc',\n  ): ChatSession[] {\n    return [...sessions].sort((a, b) => {\n      let comparison = 0;\n\n      switch (sortBy) {\n        case 'createdAt':\n          comparison =\n            new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime();\n          break;\n        case 'updatedAt':\n          comparison =\n            new Date(a.updatedAt).getTime() - new Date(b.updatedAt).getTime();\n          break;\n        case 'title':\n          comparison = (a.title || '').localeCompare(b.title || '');\n          break;\n        case 'messageCount':\n          comparison = a.messageCount - b.messageCount;\n          break;\n      }\n\n      return order === 'desc' ? -comparison : comparison;\n    });\n  }\n\n  export function paginateSessions(\n    sessions: ChatSession[],\n    page = 1,\n    limit = 10,\n  ): {\n    sessions: ChatSession[];\n    pagination: {\n      page: number;\n      limit: number;\n      total: number;\n      totalPages: number;\n      hasNext: boolean;\n      hasPrev: boolean;\n    };\n  } {\n    const offset = (page - 1) * limit;\n    const paginatedSessions = sessions.slice(offset, offset + limit);\n    const totalPages = Math.ceil(sessions.length / limit);\n\n    return {\n      sessions: paginatedSessions,\n      pagination: {\n        page,\n        limit,\n        total: sessions.length,\n        totalPages,\n        hasNext: page < totalPages,\n        hasPrev: page > 1,\n      },\n    };\n  }\n}\n\nexport namespace SessionValidationUtils {\n  export function isValidSessionId(sessionId: string): boolean {\n    return /^[A-Za-z0-9_-]{21}$/.test(sessionId);\n  }\n\n  export function isValidSessionTitle(title: string): boolean {\n    return title.length > 0 && title.length <= 100;\n  }\n\n  export function isValidProfile(profile: string): boolean {\n    return (\n      profile.length > 0 &&\n      profile.length <= 50 &&\n      /^[a-zA-Z0-9_-]+$/.test(profile)\n    );\n  }\n\n  export function sanitizeTitle(title: string): string {\n    return title\n      .trim()\n      .replace(/[<>:\"/\\\\|?*]/g, '_')\n      .substring(0, 100);\n  }\n\n  export function validateSession(session: Partial<ChatSession>): {\n    isValid: boolean;\n    errors: string[];\n  } {\n    const errors: string[] = [];\n\n    if (!session.id) {\n      errors.push('Session ID is required');\n    } else if (!isValidSessionId(session.id)) {\n      errors.push('Invalid session ID format');\n    }\n\n    if (!session.profile) {\n      errors.push('Profile is required');\n    } else if (!isValidProfile(session.profile)) {\n      errors.push('Invalid profile format');\n    }\n\n    if (!session.createdAt) {\n      errors.push('Created date is required');\n    } else if (Number.isNaN(new Date(session.createdAt).getTime())) {\n      errors.push('Invalid created date format');\n    }\n\n    if (!session.updatedAt) {\n      errors.push('Updated date is required');\n    } else if (Number.isNaN(new Date(session.updatedAt).getTime())) {\n      errors.push('Invalid updated date format');\n    }\n\n    if (session.messageCount !== undefined && session.messageCount < 0) {\n      errors.push('Message count cannot be negative');\n    }\n\n    return {\n      isValid: errors.length === 0,\n      errors,\n    };\n  }\n}\n"]}