quantum-ai-v3/templates/components/current_session_widget.html
Claude 641d676f2f 🎉 Complete 5 Whys agent enhancements with session management and UI improvements
## Major Features Added:

### 🕒 Session Time Limits (2hr → 30min)
- Updated ChatSession model: expires_at, extend_session methods
- Changed session creation and extension logic
- Updated JavaScript timing calculations
- Fixed timing indicator functionality with real-time server data

### 💬 Message Limits (50 → 20)
- Added message_limit field to Agent model with migration
- Implemented auto-completion when message limit reached
- Only count user messages (not agent responses) toward limit
- Enhanced error messaging for limit exceeded

### 📥 Chat Download System
- Added PDF and TXT export functionality using ReportLab
- Download buttons in chat header for active sessions
- Comprehensive export with session metadata and formatting
- New API endpoints: /agents/api/chat/export/{session_id}/

### 📋 Previous Sessions Management
- Created Previous Sessions widget showing last 5 non-active sessions
- Download access for all completed sessions with messages
- Session status indicators ( Completed,  Expired,  Abandoned)
- Clean sidebar organization with session history

### 🎨 UI/UX Improvements
- Moved session info from main chat to sidebar for cleaner interface
- Increased chat height: 600px → 800px (mobile: 500px → 650px)
- Added Current Session widget with status, ID, and start time
- Enhanced sidebar layout with proper component stacking
- Responsive design with mobile optimizations

### 🔧 Session Indicators System
- Real-time session status API with server-side data
- Progress bars for time remaining and message usage
- Warning notifications for approaching limits
- Automatic updates every 30 seconds

### 💰 Payment Flow Fixes
- Fixed charging system to actually deduct wallet balance
- Each new session charges 15 AED for 20 messages + 30 minutes
- Proper error handling for insufficient balance
- Session cleanup on payment failures

## Technical Implementation:

**Backend Changes:**
- Enhanced ChatSession model with 30-minute duration
- Message counting logic (user messages only)
- Auto-completion on limit reached
- Session status API endpoint
- PDF/TXT export with ReportLab

**Frontend Changes:**
- Comprehensive sidebar widget system
- Real-time indicator updates with server sync
- Download functionality with loading states
- Session history display with status icons
- Responsive layout improvements

**Database:**
- Added message_limit field to Agent model
- Updated ChatSession expiration logic
- Efficient queries for session history

## User Experience:
 Clear session limits (20 messages, 30 minutes)
 Automatic session completion with preserved history
 Easy download access for all previous sessions
 Transparent pricing (15 AED per session)
 Clean, organized interface with more chat space
 Real-time feedback on session progress

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-03 13:28:39 +05:30

119 lines
3.0 KiB
HTML

{% if chat_session %}
<div class="agent-widget widget-small" style="min-width: min(280px, 100%); max-width: min(280px, 100%); margin-left: auto;">
<div class="widget-header">
<h3 class="widget-title">
<span class="widget-icon">💬</span>
Current Session
</h3>
</div>
<div class="widget-content">
<div class="current-session-info">
<div class="session-status-row">
<span class="status-label">Status:</span>
<span class="session-status status-{{ chat_session.status }}">
{% if chat_session.status == 'active' %}
✅ {{ chat_session.get_status_display }}
{% elif chat_session.status == 'expired' %}
⏰ {{ chat_session.get_status_display }}
{% elif chat_session.status == 'completed' %}
🏁 {{ chat_session.get_status_display }}
{% else %}
{{ chat_session.get_status_display }}
{% endif %}
</span>
</div>
<div class="session-id-row">
<span class="id-label">Session ID:</span>
<span class="session-id">{{ chat_session.session_id }}</span>
</div>
<div class="session-time-row">
<span class="time-label">Started:</span>
<span class="session-time">{{ chat_session.created_at|date:"M d, H:i" }}</span>
</div>
</div>
</div>
</div>
<style>
.current-session-info {
display: flex;
flex-direction: column;
gap: var(--spacing-sm);
}
.session-status-row,
.session-id-row,
.session-time-row {
display: flex;
justify-content: space-between;
align-items: center;
padding: var(--spacing-xs) 0;
border-bottom: 1px solid var(--outline-variant);
}
.session-status-row:last-child,
.session-id-row:last-child,
.session-time-row:last-child {
border-bottom: none;
}
.status-label,
.id-label,
.time-label {
font-size: 13px;
font-weight: 500;
color: var(--on-surface-variant);
}
.session-status {
font-size: 13px;
font-weight: 600;
display: flex;
align-items: center;
gap: 4px;
}
.session-status.status-active {
color: #10b981;
}
.session-status.status-expired {
color: #f59e0b;
}
.session-status.status-completed {
color: #6366f1;
}
.session-id {
font-family: var(--font-mono);
font-size: 11px;
color: var(--on-surface-variant);
background: var(--surface-variant);
padding: 2px 6px;
border-radius: 3px;
word-break: break-all;
}
.session-time {
font-size: 12px;
color: var(--on-surface);
}
@media (max-width: 768px) {
.session-id-row {
flex-direction: column;
align-items: flex-start;
gap: 4px;
}
.session-id {
font-size: 10px;
align-self: stretch;
text-align: center;
}
}
</style>
{% endif %}