quantum-ai-v2/workflows/templates/workflows/agent-template-starter.html
Claude c2cdaa4918 Enhance agent template with modern UX patterns and data analyzer improvements
AGENT TEMPLATE ENHANCEMENTS:
• Add enhanced file upload with preview, progress, and drag-and-drop
• Implement real-time validation with colored feedback messages
• Create class-based JavaScript architecture following data-analyzer pattern
• Consolidate CSS framework with all modern styling patterns
• Add comprehensive documentation and setup instructions

DATA ANALYZER UX IMPROVEMENTS:
• Enhanced file upload experience with preview card
• Real-time validation with detailed error messages
• Progress indicators and visual state management
• Replace/remove file functionality
• Improved drag-and-drop with visual feedback

TEMPLATE FEATURES:
• Complete class-based processor pattern in agent-template-starter.js
• Advanced file validation with size and type checking
• Mobile-responsive design with accessibility improvements
• Integration with workflows-core.js and existing components
• Step-by-step setup guide for new agent development

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-30 11:51:07 +05:30

802 lines
26 KiB
HTML

{% extends 'base.html' %}
{% load static %}
{#
AGENT TEMPLATE STARTER - Enhanced Version with Modern UX Patterns
Copy this file and customize for new agents
REQUIRED CUSTOMIZATIONS:
1. File names: "agent-template-starter" -> "your-agent-slug"
2. Agent info: "Agent Template Starter" -> Your agent name
3. Form fields: Replace example fields with your agent's specific inputs
4. JavaScript: Update agent-template-starter.js with your agent logic
5. Agent config: Add your agent to workflows/config/agents.py
TEMPLATE FEATURES INCLUDED:
✅ Enhanced file upload with preview, progress, and validation
✅ Real-time form validation with detailed error messages
✅ Drag-and-drop file support with visual feedback
✅ Class-based JavaScript architecture following data-analyzer pattern
✅ Comprehensive CSS framework with all modern patterns
✅ Mobile-responsive design with proper accessibility
✅ Integration with workflows-core.js and existing components
KEEP THE FOLLOWING UNCHANGED:
- All {% include %} statements for shared components
- Template structure (agent-container, agent-grid, etc.)
- Processing and results components
- Authentication and wallet balance checks
- CSS variable system and design tokens
OPTIONAL CUSTOMIZATIONS:
- How it works steps (change steps parameter)
- Custom CSS in the designated section
- Additional form sections or validation rules
- Custom result formatting in JavaScript
#}
{% block title %}Agent Template Starter - Quantum Tasks AI{% endblock %}
{% block extra_css %}
<link rel="stylesheet" href="{% static 'css/agent-base.css' %}?v={{ timestamp }}">
<style>
/* Enhanced Agent Template Styles - Complete Framework */
.form-textarea {
width: 100%;
padding: 12px 16px;
border: 2px solid var(--outline-variant);
border-radius: var(--radius-md);
font-size: 14px;
line-height: 1.5;
transition: all 0.2s ease;
background: var(--surface);
color: var(--on-surface);
font-family: inherit;
resize: vertical;
min-height: 120px;
}
.form-textarea:focus {
outline: none;
border-color: var(--primary);
box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.1);
}
.form-textarea:hover {
border-color: var(--on-surface-variant);
}
/* Enhanced Form Sections */
.section-container {
margin-bottom: var(--spacing-xl);
padding: var(--spacing-lg);
background: var(--surface-variant);
border-radius: var(--radius-md);
border: 1px solid var(--outline-variant);
}
.section-subtitle {
font-size: 16px;
font-weight: 600;
color: var(--on-surface);
margin: 0 0 var(--spacing-lg) 0;
display: flex;
align-items: center;
gap: var(--spacing-sm);
}
.section-subtitle::before {
content: '';
width: 3px;
height: 16px;
background: var(--primary);
border-radius: 2px;
}
/* Error styling */
.form-textarea.error,
.form-input.error {
border-color: var(--error);
}
.form-error {
color: var(--error);
font-size: 12px;
margin-top: var(--spacing-xs);
font-weight: 500;
}
/* Enhanced Results Display */
.results-content {
background: var(--surface-variant);
border-radius: var(--radius-md);
padding: var(--spacing-xl);
margin-bottom: var(--spacing-lg);
line-height: 1.7;
color: var(--on-surface);
font-size: 15px;
}
/* Results Typography */
.results-content h1,
.results-content h2,
.results-content h3 {
color: var(--primary);
font-weight: 700;
margin: var(--spacing-xl) 0 var(--spacing-md) 0;
line-height: 1.3;
}
.results-content h1 {
font-size: 24px;
border-bottom: 3px solid var(--primary);
padding-bottom: var(--spacing-sm);
margin-bottom: var(--spacing-lg);
}
.results-content h2 {
font-size: 20px;
margin-top: var(--spacing-xl);
position: relative;
padding-left: var(--spacing-md);
}
.results-content h2::before {
content: '';
position: absolute;
left: 0;
top: 0;
bottom: 0;
width: 4px;
background: var(--primary);
border-radius: 2px;
}
.results-content h3 {
font-size: 18px;
color: var(--on-surface);
font-weight: 600;
background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
padding: var(--spacing-md) var(--spacing-lg);
border-radius: var(--radius-sm);
border-left: 4px solid var(--primary);
margin: var(--spacing-lg) 0 var(--spacing-md) 0;
}
.results-content strong {
color: var(--primary);
font-weight: 600;
}
/* Toast Notifications */
.toast {
position: fixed;
top: 20px;
right: 20px;
background: var(--surface);
border: 1px solid var(--outline);
border-radius: var(--radius-md);
padding: var(--spacing-md) var(--spacing-lg);
box-shadow: var(--shadow-lg);
z-index: 1000;
max-width: 400px;
font-size: 14px;
font-weight: 500;
transform: translateX(100%);
transition: transform 0.3s ease;
}
.toast.show {
transform: translateX(0);
}
.toast.success {
border-color: var(--success);
background: #f0fdf4;
color: #16a34a;
}
.toast.error {
border-color: var(--error);
background: #fef2f2;
color: #dc2626;
}
.toast.info {
border-color: var(--primary);
background: #f0f9ff;
color: #0369a1;
}
/* Enhanced File Upload Styling */
.file-upload-area {
border: 2px dashed var(--outline-variant);
border-radius: var(--radius-md);
padding: var(--spacing-xl);
text-align: center;
background: var(--surface);
transition: all 0.2s ease;
cursor: pointer;
position: relative;
}
.file-upload-area:hover,
.file-upload-area.dragover {
border-color: var(--primary);
background: var(--surface-variant);
transform: translateY(-1px);
box-shadow: var(--shadow-sm);
}
.file-upload-area.file-selected {
border-color: var(--success);
background: #f0fdf4;
color: #16a34a;
cursor: default;
}
.file-upload-area.upload-error {
border-color: var(--error);
background: #fef2f2;
color: #dc2626;
}
.file-upload-area.uploading {
border-color: var(--primary);
background: var(--surface-variant);
pointer-events: none;
}
.upload-icon {
font-size: 48px;
margin-bottom: var(--spacing-sm);
opacity: 0.7;
}
.upload-text {
display: flex;
flex-direction: column;
align-items: center;
gap: var(--spacing-sm);
color: var(--on-surface-variant);
}
.upload-text > div:first-child {
font-weight: 500;
color: var(--on-surface);
}
/* File Preview Section */
.file-preview {
display: none;
background: var(--surface-variant);
border: 1px solid var(--outline-variant);
border-radius: var(--radius-md);
padding: var(--spacing-md);
margin-top: var(--spacing-md);
position: relative;
}
.file-preview.show {
display: block;
}
.file-preview-content {
display: flex;
align-items: flex-start;
gap: var(--spacing-md);
}
.file-icon {
font-size: 32px;
flex-shrink: 0;
opacity: 0.8;
}
.file-details {
flex: 1;
min-width: 0;
}
.file-name {
font-weight: 600;
color: var(--on-surface);
margin-bottom: var(--spacing-xs);
word-break: break-all;
}
.file-meta {
font-size: 12px;
color: var(--on-surface-variant);
display: flex;
gap: var(--spacing-md);
flex-wrap: wrap;
}
.file-actions {
display: flex;
gap: var(--spacing-sm);
flex-shrink: 0;
}
.file-action-btn {
background: none;
border: 1px solid var(--outline);
border-radius: var(--radius-sm);
padding: var(--spacing-xs) var(--spacing-sm);
font-size: 12px;
cursor: pointer;
transition: all 0.2s ease;
color: var(--on-surface-variant);
}
.file-action-btn:hover {
background: var(--surface);
border-color: var(--primary);
color: var(--primary);
}
.file-action-btn.remove {
color: var(--error);
border-color: var(--error);
}
.file-action-btn.remove:hover {
background: #fef2f2;
}
/* Upload Progress */
.upload-progress {
display: none;
margin-top: var(--spacing-sm);
}
.upload-progress.show {
display: block;
}
.progress-bar {
width: 100%;
height: 4px;
background: var(--outline-variant);
border-radius: 2px;
overflow: hidden;
margin-bottom: var(--spacing-xs);
}
.progress-fill {
height: 100%;
background: var(--primary);
transition: width 0.3s ease;
width: 0%;
}
.progress-text {
font-size: 12px;
color: var(--on-surface-variant);
text-align: center;
}
/* Validation Messages */
.validation-message {
display: none;
margin-top: var(--spacing-sm);
padding: var(--spacing-sm) var(--spacing-md);
border-radius: var(--radius-sm);
font-size: 13px;
font-weight: 500;
}
.validation-message.show {
display: block;
}
.validation-message.error {
background: #fef2f2;
color: #dc2626;
border: 1px solid #fecaca;
}
.validation-message.success {
background: #f0fdf4;
color: #16a34a;
border: 1px solid #bbf7d0;
}
.validation-message.warning {
background: #fffbeb;
color: #d97706;
border: 1px solid #fed7aa;
}
/* Responsive Design */
@media (max-width: 768px) {
.toast {
left: 20px;
right: 20px;
max-width: none;
transform: translateY(-100%);
}
.toast.show {
transform: translateY(0);
}
.results-content {
padding: var(--spacing-md);
font-size: 14px;
}
.results-content h1 {
font-size: 20px;
}
.results-content h2 {
font-size: 18px;
}
.results-content h3 {
font-size: 16px;
padding: var(--spacing-sm) var(--spacing-md);
}
.section-container {
padding: var(--spacing-md);
}
.file-upload-area {
padding: var(--spacing-lg);
}
.file-preview-content {
flex-direction: column;
gap: var(--spacing-sm);
}
.file-actions {
align-self: stretch;
justify-content: center;
}
.validation-message {
font-size: 12px;
padding: var(--spacing-xs) var(--spacing-sm);
}
}
/* Add agent-specific CSS here if needed */
</style>
{% endblock %}
{% block content %}
<script>
// Set data attributes for JavaScript access
document.body.setAttribute('data-user-authenticated', '{{ user.is_authenticated|yesno:"true,false" }}');
document.body.setAttribute('data-agent-price', '{{ agent_config.price }}');
</script>
<div class="agent-container">
<!-- Agent Header Component - KEEP THIS -->
{% include "workflows/components/agent_header.html" with agent_title=agent_config.name agent_subtitle=agent_config.description %}
<!-- Quick Agent Access Panel Component - KEEP THIS -->
{% include "workflows/components/quick_agents_panel.html" %}
<!-- Main Agent Grid -->
<div class="agent-grid">
<!-- CUSTOMIZE THIS SECTION: Agent-Specific Form Widget -->
<div class="agent-widget widget-large" style="flex: 1; margin-right: clamp(0px, var(--spacing-lg), 2vw);">
<div class="widget-header">
<h3 class="widget-title">
<span class="widget-icon">{{ agent_config.icon }}</span>
{# CUSTOMIZE: Change "Details" to something specific like "Configuration", "Input", etc. #}
{{ agent_config.name }} Details
</h3>
</div>
<div class="widget-content">
<form id="agentForm" method="POST">
{% csrf_token %}
{#
CUSTOMIZE: Replace this entire section with your agent-specific form fields
FORM FIELD EXAMPLES INCLUDED:
- Text input with validation
- Textarea with character limits
- Select dropdown with options
- Enhanced file upload with preview
VALIDATION FEATURES:
- Required field validation
- Real-time error display
- File type and size validation
- Success/error visual feedback
CUSTOMIZE FOR YOUR AGENT:
1. Replace field names (example_input -> your_field_name)
2. Update validation rules in JavaScript
3. Modify form labels and help text
4. Add/remove fields as needed
5. Update placeholder text and options
#}
<!-- EXAMPLE FORM SECTION - REPLACE WITH YOUR FIELDS -->
<div class="section-container">
<h4 class="section-subtitle">📝 Input Section</h4>
<div class="form-group">
<label class="form-label" for="example_input">Example Input Field *</label>
<input type="text"
id="example_input"
name="example_input"
class="form-input"
placeholder="Enter your input here..."
required>
<div class="form-help">Provide a helpful description for this field</div>
<div id="example_input-error" class="form-error" style="display: none;"></div>
</div>
<div class="form-group">
<label class="form-label" for="example_textarea">Example Textarea *</label>
<textarea id="example_textarea"
name="example_textarea"
class="form-textarea"
placeholder="Enter detailed information..."
required
rows="4"></textarea>
<div class="form-help">Describe what kind of content goes here</div>
<div id="example_textarea-error" class="form-error" style="display: none;"></div>
</div>
<div class="form-group">
<label class="form-label" for="example_select">Example Select *</label>
<select id="example_select" name="example_select" class="form-input" required>
<option value="">Select an option...</option>
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
<option value="option3">Option 3</option>
</select>
<div class="form-help">Choose the appropriate option</div>
<div id="example_select-error" class="form-error" style="display: none;"></div>
</div>
</div>
{#
OPTIONAL: Enhanced File Upload Section
FEATURES INCLUDED:
✅ Drag and drop file upload
✅ File preview with metadata (name, size, timestamp)
✅ Replace/remove file actions
✅ Real-time validation (file type, size limits)
✅ Progress indicator during upload
✅ Visual feedback for different states
✅ Mobile-responsive design
✅ Accessibility features (keyboard navigation, ARIA labels)
CUSTOMIZATION OPTIONS:
1. Change accepted file types in 'accept' attribute
2. Modify file size limits in JavaScript validation
3. Update help text and file format descriptions
4. Customize validation messages
5. Remove entire section if file upload not needed
REMOVE THIS SECTION IF YOUR AGENT DOESN'T NEED FILE UPLOAD
#}
<!-- ENHANCED FILE UPLOAD SECTION -->
<div class="section-container"> <!-- File upload section enabled -->
<h4 class="section-subtitle">📁 File Upload (Optional)</h4>
<div class="form-group">
<label class="form-label">📁 Upload File (Optional)</label>
<div class="file-upload-area" id="fileUploadArea" onclick="triggerFileSelect()"
role="button" tabindex="0" aria-label="Click to upload file or drag and drop"
onkeydown="if(event.key==='Enter'||event.key===' '){triggerFileSelect()}">
<div class="upload-text" id="uploadText">
<div class="upload-icon">📁</div>
<div><strong>Click to upload</strong> or drag and drop</div>
<div>Supported formats: PDF, DOC, TXT, etc.</div>
</div>
</div>
<input type="file" id="example_file" name="example_file" accept=".pdf,.doc,.docx,.txt" style="display: none;">
<!-- Upload Progress -->
<div class="upload-progress" id="uploadProgress">
<div class="progress-bar">
<div class="progress-fill" id="progressFill"></div>
</div>
<div class="progress-text" id="progressText">Preparing upload...</div>
</div>
<!-- File Preview -->
<div class="file-preview" id="filePreview">
<div class="file-preview-content">
<div class="file-icon">📄</div>
<div class="file-details">
<div class="file-name" id="previewFileName"></div>
<div class="file-meta">
<span id="previewFileSize"></span>
<span id="previewFileType">Document</span>
<span id="previewTimestamp"></span>
</div>
</div>
<div class="file-actions">
<button type="button" class="file-action-btn" onclick="replaceFile()" title="Replace file">
🔄 Replace
</button>
<button type="button" class="file-action-btn remove" onclick="removeFile()" title="Remove file">
🗑️ Remove
</button>
</div>
</div>
</div>
<!-- Validation Messages -->
<div class="validation-message" id="validationMessage"></div>
<div class="form-help">Upload a file if needed for processing (Max size: 10MB)</div>
<div id="example_file-error" class="form-error" style="display: none;"></div>
</div>
</div>
{# END CUSTOMIZE SECTION #}
{#
SUBMIT BUTTON SECTION - KEEP THIS STRUCTURE UNCHANGED
FEATURES INCLUDED:
✅ Authentication check (redirects to login if not authenticated)
✅ Wallet balance validation (shows top-up if insufficient funds)
✅ Proper form submission handling
✅ Loading states and user feedback
✅ Price display from agent configuration
✅ Consistent styling across all agents
CUSTOMIZATION OPTIONS:
- Change action verb in button text ("Generate" -> "Analyze", "Create", etc.)
- Update button icon emoji to match your agent
DO NOT CHANGE:
- Authentication and balance check logic
- Template structure and Django template tags
- CSS classes and styling
- Error message formatting
#}
<!-- SUBMIT BUTTON WITH AUTHENTICATION & BALANCE CHECKS -->
<div style="margin-top: var(--spacing-lg);">
{% if user.is_authenticated %}
{% if user.wallet_balance >= agent_config.price %}
<button type="submit" class="btn btn-primary btn-full" id="generateBtn">
{# CUSTOMIZE: Change action verb like "Generate", "Analyze", "Process" #}
{{ agent_config.icon }} Generate with {{ agent_config.name }} ({{ agent_config.price }} AED)
</button>
{% else %}
<div style="background: #fef2f2; color: #dc2626; padding: var(--spacing-md); border-radius: var(--radius-md); margin-bottom: var(--spacing-md); font-size: 14px; font-weight: 500; text-align: center;">
Insufficient balance! You need {{ agent_config.price }} AED.
</div>
<a href="{% url 'wallet:wallet' %}" class="btn btn-primary btn-full" style="text-decoration: none;">
💰 Top Up Wallet
</a>
{% endif %}
{% else %}
<a href="{% url 'authentication:login' %}" class="btn btn-primary btn-full">
🔐 Login to Continue
</a>
{% endif %}
</div>
</form>
</div>
</div>
<!-- How It Works Widget - KEEP THIS, CUSTOMIZE steps parameter -->
{# CUSTOMIZE: Change "generic" to your agent-specific steps or keep as is #}
{% include "workflows/components/how_it_works_widget.html" with steps="generic" %}
</div>
<!-- Processing Status Component - KEEP THIS -->
{# CUSTOMIZE: Change status messages to match your agent's processing #}
{% include "workflows/components/processing_status.html" with status_title="Processing your request..." status_text="Please wait while we generate your content." %}
<!-- Results Component - KEEP THIS -->
{# CUSTOMIZE: Change results_title to match your agent's output #}
{% include "workflows/components/results_container.html" with results_title="Generated Results" %}
</div>
{% endblock %}
{% block extra_js %}
<script src="{% static 'js/workflows-core.js' %}?v={{ timestamp }}"></script>
{# CUSTOMIZE: Replace 'agent-template-starter' with your agent slug #}
<script src="{% static 'js/agent-template-starter.js' %}?v={{ timestamp }}"></script>
{% endblock %}
{#
===============================================================================
SETUP INSTRUCTIONS FOR NEW AGENTS
===============================================================================
1. COPY FILES:
- Copy this template: agent-template-starter.html -> your-agent-name.html
- Copy JavaScript: agent-template-starter.js -> your-agent-name.js
- Place in: workflows/templates/workflows/ and static/js/ respectively
2. UPDATE AGENT CONFIG:
- Add your agent to workflows/config/agents.py
- Set name, description, price, icon, and webhook_url
- Example:
'your-agent-slug': {
'name': 'Your Agent Name',
'description': 'Description of what your agent does',
'price': 10.0,
'icon': '🤖',
'webhook_url': 'your-n8n-webhook-url',
}
3. CUSTOMIZE TEMPLATE:
- Update page title and meta information
- Replace example form fields with your agent's inputs
- Modify section titles and descriptions
- Update How It Works steps if needed
- Remove file upload section if not needed
4. CUSTOMIZE JAVASCRIPT:
- Change class name: AgentTemplateProcessor -> YourAgentProcessor
- Update agent slug and webhook URL
- Modify form validation rules for your fields
- Customize result formatting for your agent's output
- Update file validation if using file upload
5. ADD URL ROUTE:
- Add URL pattern in workflows/urls.py
- Point to your agent's view function
- Example: path('your-agent-slug/', views.your_agent_view, name='your_agent')
6. CREATE VIEW:
- Add view function in workflows/views.py
- Handle form processing and N8N integration
- Return appropriate JSON responses
- Follow existing agent patterns
7. TESTING:
- Test form validation and submission
- Verify file upload functionality (if used)
- Check responsive design on mobile
- Test authentication and wallet balance flows
- Verify N8N webhook integration
8. PRODUCTION:
- Update N8N webhook URLs to production
- Test with real user accounts
- Monitor error logs and performance
- Update documentation if needed
===============================================================================
AVAILABLE WORKFLOWSCORE FUNCTIONS (from workflows-core.js)
===============================================================================
Authentication & Balance:
- WorkflowsCore.checkAuthentication()
- WorkflowsCore.checkBalance(price)
- WorkflowsCore.updateWalletBalance(balance)
UI Feedback:
- WorkflowsCore.showToast(message, type)
- WorkflowsCore.showProcessing(title)
- WorkflowsCore.hideProcessing()
- WorkflowsCore.showResults(content, title)
Form Validation:
- WorkflowsCore.showFieldError(fieldName, message)
- WorkflowsCore.clearFieldError(fieldName)
- WorkflowsCore.clearAllFieldErrors()
Utilities:
- WorkflowsCore.copyToClipboard(text, message)
- WorkflowsCore.downloadAsFile(content, filename, message)
- WorkflowsCore.generateSessionId()
- WorkflowsCore.formatFileSize(bytes)
Processing:
- WorkflowsCore.startPolling(requestId)
- WorkflowsCore.stopPolling()
- WorkflowsCore.pollForResults(requestId, callback)
===============================================================================
#}