From 2e25b96807767ad47f1317b5aff092cd68971d3d Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 14 Jul 2025 01:30:16 +0530 Subject: [PATCH] Standardize AgentUtils function calls across all agents MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove duplicate updateWalletBalance and showToast functions from individual agents - Standardize all agents to use AgentUtils.functionName() pattern consistently - Update Five Whys Analyzer to use shared utility functions - Maintain agent-specific functions only where necessary for unique workflows - Ensure consistent function call patterns across Data Analyzer, Job Posting Generator, and Five Whys Analyzer 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../templates/data_analyzer/detail.html | 10 +-- .../templates/five_whys_analyzer/detail.html | 64 ++++--------------- .../job_posting_generator/detail.html | 10 +-- 3 files changed, 15 insertions(+), 69 deletions(-) diff --git a/data_analyzer/templates/data_analyzer/detail.html b/data_analyzer/templates/data_analyzer/detail.html index 6bab689..ab09ddd 100644 --- a/data_analyzer/templates/data_analyzer/detail.html +++ b/data_analyzer/templates/data_analyzer/detail.html @@ -688,7 +688,7 @@ // Update wallet balance if provided if (result.wallet_balance !== undefined) { - updateWalletBalance(result.wallet_balance); + AgentUtils.updateWalletBalance(result.wallet_balance); } // Handle errors @@ -844,14 +844,6 @@ } - function updateWalletBalance(newBalance) { - // Update wallet balance display - const balanceElement = document.getElementById('walletBalance'); - if (balanceElement) { - balanceElement.textContent = `${newBalance.toFixed(2)} AED`; - } - window.currentWalletBalance = newBalance; - } function copyAnalysisReport() { const reportText = AgentUtils.generateTextForExport('analysisContent'); diff --git a/five_whys_analyzer/templates/five_whys_analyzer/detail.html b/five_whys_analyzer/templates/five_whys_analyzer/detail.html index 8e3e739..e298cd1 100644 --- a/five_whys_analyzer/templates/five_whys_analyzer/detail.html +++ b/five_whys_analyzer/templates/five_whys_analyzer/detail.html @@ -312,7 +312,7 @@ const message = input.value.trim(); if (!message) { - showToast('Please enter a message', 'error'); + AgentUtils.showToast('Please enter a message', 'error'); return; } @@ -352,14 +352,14 @@ // Check if report button should be enabled checkReportReadiness(); } else { - showToast(data.error || 'Failed to send message', 'error'); + AgentUtils.showToast(data.error || 'Failed to send message', 'error'); } }) .catch(error => { // Hide typing indicator on error hideTypingIndicator(); console.error('Error:', error); - showToast('Network error occurred', 'error'); + AgentUtils.showToast('Network error occurred', 'error'); }) .finally(() => { isProcessing = false; @@ -516,12 +516,12 @@ if (isProcessing) return; if (!currentSessionId) { - showToast('Please start a chat session first', 'error'); + AgentUtils.showToast('Please start a chat session first', 'error'); return; } if (messageCount < 2) { - showToast('Please ask at least 2 questions before generating a report', 'error'); + AgentUtils.showToast('Please ask at least 2 questions before generating a report', 'error'); return; } @@ -560,16 +560,16 @@ displayReport(data.report); // Update wallet balance - updateWalletBalance(data.wallet_balance); + AgentUtils.updateWalletBalance(data.wallet_balance); - showToast('✅ Report generated and payment processed!', 'success'); + AgentUtils.showToast('✅ Report generated and payment processed!', 'success'); } else { - showToast(data.error || 'Failed to generate report', 'error'); + AgentUtils.showToast(data.error || 'Failed to generate report', 'error'); } }) .catch(error => { console.error('Error:', error); - showToast('Network error occurred', 'error'); + AgentUtils.showToast('Network error occurred', 'error'); }) .finally(() => { isProcessing = false; @@ -618,54 +618,16 @@ return formatted; } - function updateWalletBalance(newBalance) { - document.querySelectorAll('[data-wallet-balance]').forEach(element => { - element.textContent = `${newBalance.toFixed(2)} AED`; - }); - } function copyReport() { - const reportElement = document.getElementById('reportContent'); - const reportText = reportElement.innerText || reportElement.textContent; - navigator.clipboard.writeText(reportText).then(() => { - showToast('📋 Report copied to clipboard!', 'success'); - }).catch(() => { - showToast('Failed to copy report', 'error'); - }); + const reportText = AgentUtils.generateTextForExport('reportContent'); + AgentUtils.copyToClipboard(reportText, '📋 Report copied to clipboard!'); } function downloadReport() { - const reportElement = document.getElementById('reportContent'); - const reportText = reportElement.innerText || reportElement.textContent; - const blob = new Blob([reportText], { type: 'text/plain' }); - const url = URL.createObjectURL(blob); - const a = document.createElement('a'); - a.href = url; - a.download = `five-whys-analysis-${Date.now()}.txt`; - a.click(); - URL.revokeObjectURL(url); - showToast('💾 Report downloaded!', 'success'); + const reportText = AgentUtils.generateTextForExport('reportContent'); + AgentUtils.downloadAsFile(reportText, `five-whys-analysis-${Date.now()}.txt`, '💾 Report downloaded!'); } - function showToast(message, type = 'info') { - const toast = document.createElement('div'); - toast.style.cssText = ` - position: fixed; - top: 20px; - right: 20px; - padding: 12px 20px; - border-radius: 8px; - color: white; - font-weight: 600; - z-index: 1000; - ${type === 'success' ? 'background: #10b981;' : 'background: #ef4444;'} - `; - toast.textContent = message; - document.body.appendChild(toast); - - setTimeout(() => { - toast.remove(); - }, 3000); - } {% endblock %} \ No newline at end of file diff --git a/job_posting_generator/templates/job_posting_generator/detail.html b/job_posting_generator/templates/job_posting_generator/detail.html index 155cb0a..9dfa07b 100644 --- a/job_posting_generator/templates/job_posting_generator/detail.html +++ b/job_posting_generator/templates/job_posting_generator/detail.html @@ -285,14 +285,6 @@ // Initialize on page load document.addEventListener('DOMContentLoaded', initializeFormEnhancements); - // Update wallet balance display - function updateWalletBalance(newBalance) { - const balanceElements = document.querySelectorAll('[data-wallet-balance]'); - balanceElements.forEach(element => { - element.textContent = `${newBalance.toFixed(2)} AED`; - }); - window.currentWalletBalance = newBalance; - } // Display job posting results with professional formatting @@ -307,7 +299,7 @@ // Update wallet balance if provided if (result.wallet_balance !== undefined) { - updateWalletBalance(result.wallet_balance); + AgentUtils.updateWalletBalance(result.wallet_balance); } // Handle errors