mirror of
https://github.com/thecyberlearn/quantum-ai-v3.git
synced 2026-08-18 13:32:57 +00:00
🏗️ **Database Extensions:** - Add agent_type field to Agent model (form/chat distinction) - Create ChatSession model for conversation management - Create ChatMessage model for message storage with metadata - Add database indexes for performance optimization 🎨 **Frontend Implementation:** - Create agent_chat.html template with modern chat interface - Implement real-time messaging UI with message bubbles - Add typing indicators and loading states - Responsive design for mobile and desktop - Empty states and error handling 🔧 **Backend Logic:** - Extend agent_detail_view to route chat vs form agents - Implement chat_agent_view for chat interface rendering - Add start_chat_session API endpoint with session management - Add send_chat_message API endpoint with webhook integration - Add get_chat_history and end_chat_session endpoints - Session-based fee charging system 🤖 **5 Whys Agent:** - Create "Analysis & Problem Solving" category - Implement 5 Whys Analysis chat-based agent (15 AED) - Interactive problem-solving methodology guidance - N8N webhook integration for AI responses ⚡ **Interactive Features:** - JavaScript ChatInterface class for real-time communication - Auto-session creation and management - Message validation and error handling - Automatic scrolling and UI state management - CSRF protection and security measures 🔗 **API Integration:** - Chat-specific API endpoints with RESTful design - Webhook payload formatting for N8N integration - Session ID tracking and conversation continuity - Metadata storage for webhook responses 🛡️ **Security & UX:** - Login required for chat agents - Wallet balance validation before session creation - Session isolation per user and agent - Comprehensive error handling and user feedback **New URLs:** - /agents/api/chat/start/ - Start new chat session - /agents/api/chat/send/ - Send chat message - /agents/api/chat/history/<session_id>/ - Get chat history - /agents/api/chat/end/ - End chat session - /agents/five-whys-analysis/ - 5 Whys chat interface **Backward Compatibility:** - Existing form-based agents (Social Ads, Job Posting, PDF) unchanged - Admin interface updated to show agent types - Marketplace displays both agent types seamlessly 🚀 Ready for interactive 5 Whys problem-solving conversations\! 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
43 lines
1.9 KiB
Python
43 lines
1.9 KiB
Python
from django.contrib import admin
|
|
from .models import AgentCategory, Agent, AgentExecution, ChatSession, ChatMessage
|
|
|
|
@admin.register(AgentCategory)
|
|
class AgentCategoryAdmin(admin.ModelAdmin):
|
|
list_display = ['name', 'slug', 'is_active', 'created_at']
|
|
list_filter = ['is_active', 'created_at']
|
|
search_fields = ['name', 'description']
|
|
prepopulated_fields = {'slug': ('name',)}
|
|
|
|
@admin.register(Agent)
|
|
class AgentAdmin(admin.ModelAdmin):
|
|
list_display = ['name', 'category', 'agent_type', 'price', 'is_active', 'created_at']
|
|
list_filter = ['category', 'agent_type', 'is_active', 'created_at']
|
|
search_fields = ['name', 'description', 'short_description']
|
|
prepopulated_fields = {'slug': ('name',)}
|
|
readonly_fields = ['created_at', 'updated_at']
|
|
|
|
@admin.register(AgentExecution)
|
|
class AgentExecutionAdmin(admin.ModelAdmin):
|
|
list_display = ['agent', 'user', 'status', 'fee_charged', 'created_at']
|
|
list_filter = ['status', 'created_at', 'agent__category']
|
|
search_fields = ['agent__name', 'user__email']
|
|
readonly_fields = ['created_at', 'completed_at']
|
|
|
|
@admin.register(ChatSession)
|
|
class ChatSessionAdmin(admin.ModelAdmin):
|
|
list_display = ['session_id', 'agent', 'user', 'status', 'fee_charged', 'created_at']
|
|
list_filter = ['status', 'agent__category', 'created_at']
|
|
search_fields = ['session_id', 'agent__name', 'user__email']
|
|
readonly_fields = ['session_id', 'created_at', 'updated_at', 'completed_at']
|
|
|
|
@admin.register(ChatMessage)
|
|
class ChatMessageAdmin(admin.ModelAdmin):
|
|
list_display = ['session', 'message_type', 'content_preview', 'timestamp']
|
|
list_filter = ['message_type', 'timestamp']
|
|
search_fields = ['session__session_id', 'content']
|
|
readonly_fields = ['timestamp']
|
|
|
|
def content_preview(self, obj):
|
|
return obj.content[:50] + "..." if len(obj.content) > 50 else obj.content
|
|
content_preview.short_description = 'Content Preview'
|