mirror of
https://github.com/thecyberlearn/quantum-ai-v2.git
synced 2026-08-18 10:13:00 +00:00
## 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>
206 lines
4.9 KiB
HTML
206 lines
4.9 KiB
HTML
{% if previous_sessions %}
|
|
<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>
|
|
Previous Sessions
|
|
</h3>
|
|
</div>
|
|
<div class="widget-content">
|
|
{% for session in previous_sessions %}
|
|
<div class="session-item">
|
|
<div class="session-header">
|
|
<div class="session-info">
|
|
<span class="session-status status-{{ session.status }}">
|
|
{% if session.status == 'completed' %}✅{% elif session.status == 'expired' %}⏰{% elif session.status == 'abandoned' %}❌{% endif %}
|
|
{{ session.get_status_display }}
|
|
</span>
|
|
<span class="session-date">{{ session.created_at|date:"M d" }}</span>
|
|
</div>
|
|
<div class="session-stats">
|
|
<span class="message-count">{{ session.user_message_count }}/{{ session.agent.message_limit }} msgs</span>
|
|
</div>
|
|
</div>
|
|
|
|
{% if session.status == 'completed' and session.user_message_count > 0 %}
|
|
<div class="session-actions">
|
|
<div class="download-actions">
|
|
<a href="{% url 'agents:export_chat' session.session_id %}?format=pdf"
|
|
class="download-link pdf-link"
|
|
title="Download PDF">
|
|
📄 PDF
|
|
</a>
|
|
<a href="{% url 'agents:export_chat' session.session_id %}?format=txt"
|
|
class="download-link txt-link"
|
|
title="Download TXT">
|
|
📝 TXT
|
|
</a>
|
|
</div>
|
|
</div>
|
|
{% endif %}
|
|
</div>
|
|
{% endfor %}
|
|
|
|
{% if previous_sessions|length >= 5 %}
|
|
<div class="view-all-sessions">
|
|
<a href="#" class="view-all-link" onclick="alert('Full session history coming soon!')">
|
|
View All Sessions →
|
|
</a>
|
|
</div>
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
|
|
<style>
|
|
.session-item {
|
|
padding: var(--spacing-sm);
|
|
border: 1px solid var(--outline-variant);
|
|
border-radius: var(--radius-sm);
|
|
margin-bottom: var(--spacing-sm);
|
|
background: var(--surface);
|
|
transition: all 0.2s ease;
|
|
}
|
|
|
|
.session-item:hover {
|
|
background: var(--surface-variant);
|
|
border-color: var(--primary);
|
|
}
|
|
|
|
.session-item:last-child {
|
|
margin-bottom: 0;
|
|
}
|
|
|
|
.session-header {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: flex-start;
|
|
margin-bottom: var(--spacing-xs);
|
|
}
|
|
|
|
.session-info {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 2px;
|
|
}
|
|
|
|
.session-status {
|
|
font-size: 12px;
|
|
font-weight: 600;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 4px;
|
|
}
|
|
|
|
.session-status.status-completed {
|
|
color: var(--success);
|
|
}
|
|
|
|
.session-status.status-expired {
|
|
color: var(--warning);
|
|
}
|
|
|
|
.session-status.status-abandoned {
|
|
color: var(--error);
|
|
}
|
|
|
|
.session-date {
|
|
font-size: 11px;
|
|
color: var(--on-surface-variant);
|
|
}
|
|
|
|
.session-stats {
|
|
text-align: right;
|
|
}
|
|
|
|
.message-count {
|
|
font-size: 11px;
|
|
color: var(--on-surface-variant);
|
|
background: var(--surface-variant);
|
|
padding: 2px 6px;
|
|
border-radius: 3px;
|
|
}
|
|
|
|
.session-actions {
|
|
border-top: 1px solid var(--outline-variant);
|
|
padding-top: var(--spacing-xs);
|
|
}
|
|
|
|
.download-actions {
|
|
display: flex;
|
|
gap: var(--spacing-sm);
|
|
justify-content: center;
|
|
}
|
|
|
|
.download-link {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 4px;
|
|
padding: 4px 8px;
|
|
background: var(--primary);
|
|
color: white;
|
|
text-decoration: none;
|
|
border-radius: 4px;
|
|
font-size: 11px;
|
|
font-weight: 500;
|
|
transition: all 0.2s ease;
|
|
flex: 1;
|
|
justify-content: center;
|
|
}
|
|
|
|
.download-link:hover {
|
|
background: var(--primary-dark);
|
|
transform: translateY(-1px);
|
|
color: white;
|
|
text-decoration: none;
|
|
}
|
|
|
|
.download-link.pdf-link {
|
|
background: #dc2626;
|
|
}
|
|
|
|
.download-link.pdf-link:hover {
|
|
background: #b91c1c;
|
|
}
|
|
|
|
.download-link.txt-link {
|
|
background: var(--primary);
|
|
}
|
|
|
|
.download-link.txt-link:hover {
|
|
background: var(--primary-dark);
|
|
}
|
|
|
|
.view-all-sessions {
|
|
margin-top: var(--spacing-sm);
|
|
text-align: center;
|
|
border-top: 1px solid var(--outline-variant);
|
|
padding-top: var(--spacing-sm);
|
|
}
|
|
|
|
.view-all-link {
|
|
font-size: 12px;
|
|
color: var(--primary);
|
|
text-decoration: none;
|
|
font-weight: 500;
|
|
}
|
|
|
|
.view-all-link:hover {
|
|
text-decoration: underline;
|
|
}
|
|
|
|
@media (max-width: 768px) {
|
|
.session-header {
|
|
flex-direction: column;
|
|
gap: var(--spacing-xs);
|
|
}
|
|
|
|
.session-stats {
|
|
text-align: left;
|
|
}
|
|
|
|
.download-actions {
|
|
flex-direction: column;
|
|
}
|
|
}
|
|
</style>
|
|
{% endif %} |