🐳 23/03 - 17:25 - قم انت باختباره وتصحيح الاخطاء تلقائيا
Browse files- index.html +40 -18
index.html
CHANGED
|
@@ -651,7 +651,10 @@
|
|
| 651 |
const input = document.getElementById('agent-input');
|
| 652 |
const message = input.value.trim();
|
| 653 |
|
| 654 |
-
if (!message)
|
|
|
|
|
|
|
|
|
|
| 655 |
|
| 656 |
isAgentProcessing = true;
|
| 657 |
|
|
@@ -662,18 +665,30 @@
|
|
| 662 |
// Show typing indicator
|
| 663 |
showTypingIndicator();
|
| 664 |
|
|
|
|
|
|
|
|
|
|
| 665 |
// Simulate AI response
|
| 666 |
setTimeout(() => {
|
| 667 |
removeTypingIndicator();
|
| 668 |
-
generateAIResponse(
|
| 669 |
isAgentProcessing = false;
|
| 670 |
}, 1500 + Math.random() * 1000);
|
| 671 |
}
|
| 672 |
|
| 673 |
function addMessage(text, sender) {
|
| 674 |
-
//
|
| 675 |
-
if (
|
| 676 |
-
console.warn('
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 677 |
return null;
|
| 678 |
}
|
| 679 |
|
|
@@ -688,7 +703,7 @@
|
|
| 688 |
<span class="text-xs font-bold text-white">UN</span>
|
| 689 |
</div>
|
| 690 |
<div class="flex-1 bg-replit-hover rounded-lg p-3 text-sm text-gray-300">
|
| 691 |
-
${escapeHtml(
|
| 692 |
</div>
|
| 693 |
`;
|
| 694 |
} else {
|
|
@@ -698,7 +713,7 @@
|
|
| 698 |
</div>
|
| 699 |
<div class="flex-1 content-container">
|
| 700 |
<div class="bg-replit-sidebar rounded-lg p-3 text-sm text-gray-300 border border-replit content-text">
|
| 701 |
-
${
|
| 702 |
</div>
|
| 703 |
</div>
|
| 704 |
`;
|
|
@@ -738,26 +753,33 @@
|
|
| 738 |
}
|
| 739 |
|
| 740 |
function generateAIResponse(message) {
|
| 741 |
-
//
|
| 742 |
-
|
| 743 |
-
|
|
|
|
| 744 |
}
|
| 745 |
|
| 746 |
const responses = {
|
| 747 |
'explain': '🔍 <strong class="text-orange-400">Code Analysis:</strong><br><br>This code creates a modern web application with:<br>• Responsive design using CSS Grid/Flexbox<br>• Dynamic gradient backgrounds<br>• Event-driven interactions<br><br>The architecture follows best practices with clear separation of concerns.',
|
| 748 |
'debug': '🐛 <strong class="text-red-400">Debug Complete:</strong><br><br>Found 0 errors! Your code is clean. However, I suggest:<br>• Adding error handling for edge cases<br>• Implementing input validation<br>• Consider adding loading states for better UX',
|
| 749 |
'optimize': '⚡ <strong class="text-yellow-400">Optimization Applied:</strong><br><br>Improved performance by 300%:<br>• Reduced render cycles<br>• Optimized DOM queries<br>• Implemented lazy loading<br>• Minified assets automatically',
|
| 750 |
-
'default': `🎯 <strong class="text-orange-400">Infinity Agent Response:</strong><br><br>I've analyzed your request: "<em>${escapeHtml(
|
| 751 |
};
|
| 752 |
|
| 753 |
-
let
|
| 754 |
-
const lowerMsg =
|
| 755 |
-
if (lowerMsg.includes('explain'))
|
| 756 |
-
else if (lowerMsg.includes('debug'))
|
| 757 |
-
else if (lowerMsg.includes('optimize'))
|
| 758 |
-
else
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 759 |
|
| 760 |
-
const messageDiv = addMessage(
|
| 761 |
|
| 762 |
// Add action buttons inside the message content div
|
| 763 |
if (messageDiv) {
|
|
|
|
| 651 |
const input = document.getElementById('agent-input');
|
| 652 |
const message = input.value.trim();
|
| 653 |
|
| 654 |
+
if (!message || message === 'undefined' || message === 'null') {
|
| 655 |
+
console.warn('Invalid message input blocked');
|
| 656 |
+
return;
|
| 657 |
+
}
|
| 658 |
|
| 659 |
isAgentProcessing = true;
|
| 660 |
|
|
|
|
| 665 |
// Show typing indicator
|
| 666 |
showTypingIndicator();
|
| 667 |
|
| 668 |
+
// Simulate AI response with captured message to avoid closure issues
|
| 669 |
+
const capturedMessage = String(message);
|
| 670 |
+
|
| 671 |
// Simulate AI response
|
| 672 |
setTimeout(() => {
|
| 673 |
removeTypingIndicator();
|
| 674 |
+
generateAIResponse(capturedMessage);
|
| 675 |
isAgentProcessing = false;
|
| 676 |
}, 1500 + Math.random() * 1000);
|
| 677 |
}
|
| 678 |
|
| 679 |
function addMessage(text, sender) {
|
| 680 |
+
// Strict validation to prevent undefined, null, or invalid messages
|
| 681 |
+
if (text === undefined || text === null) {
|
| 682 |
+
console.warn('Blocked undefined/null message');
|
| 683 |
+
return null;
|
| 684 |
+
}
|
| 685 |
+
|
| 686 |
+
// Convert to string safely
|
| 687 |
+
const safeText = String(text);
|
| 688 |
+
|
| 689 |
+
// Block if converted string is literally "undefined" or "null" or empty
|
| 690 |
+
if (safeText === 'undefined' || safeText === 'null' || safeText.trim() === '') {
|
| 691 |
+
console.warn('Blocked invalid string message:', safeText);
|
| 692 |
return null;
|
| 693 |
}
|
| 694 |
|
|
|
|
| 703 |
<span class="text-xs font-bold text-white">UN</span>
|
| 704 |
</div>
|
| 705 |
<div class="flex-1 bg-replit-hover rounded-lg p-3 text-sm text-gray-300">
|
| 706 |
+
${escapeHtml(safeText)}
|
| 707 |
</div>
|
| 708 |
`;
|
| 709 |
} else {
|
|
|
|
| 713 |
</div>
|
| 714 |
<div class="flex-1 content-container">
|
| 715 |
<div class="bg-replit-sidebar rounded-lg p-3 text-sm text-gray-300 border border-replit content-text">
|
| 716 |
+
${safeText}
|
| 717 |
</div>
|
| 718 |
</div>
|
| 719 |
`;
|
|
|
|
| 753 |
}
|
| 754 |
|
| 755 |
function generateAIResponse(message) {
|
| 756 |
+
// Strict validation of input message
|
| 757 |
+
let safeMessage = '';
|
| 758 |
+
if (message && typeof message === 'string') {
|
| 759 |
+
safeMessage = message;
|
| 760 |
}
|
| 761 |
|
| 762 |
const responses = {
|
| 763 |
'explain': '🔍 <strong class="text-orange-400">Code Analysis:</strong><br><br>This code creates a modern web application with:<br>• Responsive design using CSS Grid/Flexbox<br>• Dynamic gradient backgrounds<br>• Event-driven interactions<br><br>The architecture follows best practices with clear separation of concerns.',
|
| 764 |
'debug': '🐛 <strong class="text-red-400">Debug Complete:</strong><br><br>Found 0 errors! Your code is clean. However, I suggest:<br>• Adding error handling for edge cases<br>• Implementing input validation<br>• Consider adding loading states for better UX',
|
| 765 |
'optimize': '⚡ <strong class="text-yellow-400">Optimization Applied:</strong><br><br>Improved performance by 300%:<br>• Reduced render cycles<br>• Optimized DOM queries<br>• Implemented lazy loading<br>• Minified assets automatically',
|
| 766 |
+
'default': `🎯 <strong class="text-orange-400">Infinity Agent Response:</strong><br><br>I've analyzed your request: "<em>${escapeHtml(safeMessage.substring(0, 50))}${safeMessage.length > 50 ? '...' : ''}</em>"<br><br>Here's my creative solution:<br><br>1. <strong>Architecture:</strong> Modular component-based design<br>2. <strong>Performance:</strong> Optimized for sub-100ms load times<br>3. <strong>UX:</strong> Intuitive interactions with micro-animations<br>4. <strong>Code Quality:</strong> Production-ready with full type safety<br><br>Would you like me to implement this now?`
|
| 767 |
};
|
| 768 |
|
| 769 |
+
let responseText;
|
| 770 |
+
const lowerMsg = safeMessage.toLowerCase();
|
| 771 |
+
if (lowerMsg.includes('explain')) responseText = responses.explain;
|
| 772 |
+
else if (lowerMsg.includes('debug')) responseText = responses.debug;
|
| 773 |
+
else if (lowerMsg.includes('optimize')) responseText = responses.optimize;
|
| 774 |
+
else responseText = responses.default;
|
| 775 |
+
|
| 776 |
+
// Double-check response is valid before sending
|
| 777 |
+
if (!responseText || responseText === 'undefined' || responseText === 'null') {
|
| 778 |
+
console.error('Invalid response generated:', responseText);
|
| 779 |
+
return;
|
| 780 |
+
}
|
| 781 |
|
| 782 |
+
const messageDiv = addMessage(responseText, 'agent');
|
| 783 |
|
| 784 |
// Add action buttons inside the message content div
|
| 785 |
if (messageDiv) {
|