hadidadi commited on
Commit
a83703e
·
verified ·
1 Parent(s): d3b5ba0

🐳 23/03 - 17:25 - قم انت باختباره وتصحيح الاخطاء تلقائيا

Browse files
Files changed (1) hide show
  1. 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) return;
 
 
 
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(message);
669
  isAgentProcessing = false;
670
  }, 1500 + Math.random() * 1000);
671
  }
672
 
673
  function addMessage(text, sender) {
674
- // Prevent adding empty or invalid messages
675
- if (!text || text === 'undefined' || text === 'null' || (typeof text !== 'string' && typeof text !== 'number')) {
676
- console.warn('Attempted to add invalid message:', text);
 
 
 
 
 
 
 
 
 
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(String(text))}
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
- ${String(text)}
702
  </div>
703
  </div>
704
  `;
@@ -738,26 +753,33 @@
738
  }
739
 
740
  function generateAIResponse(message) {
741
- // Ensure message is a valid string
742
- if (!message || typeof message !== 'string') {
743
- message = '';
 
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(String(message).substring(0, 50))}${String(message).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?`
751
  };
752
 
753
- let response;
754
- const lowerMsg = String(message).toLowerCase();
755
- if (lowerMsg.includes('explain')) response = responses.explain;
756
- else if (lowerMsg.includes('debug')) response = responses.debug;
757
- else if (lowerMsg.includes('optimize')) response = responses.optimize;
758
- else response = responses.default;
 
 
 
 
 
 
759
 
760
- const messageDiv = addMessage(response, 'agent');
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) {