While Q.1. is in PPT (present perfect tense), Q.2 is in PPCT (present perfect continuous or progressive). Q.1. and Q.2. represent the typical use of the 2 tenses.
Let’s say you’re waiting in a Doctors office for a long time. You were impatient. Your wait was over and the nurse just told you the Doctor was ready to see you. She showed concern and asked you, “How long have you waited?” You may answer, “I have waited for 40 minutes.” The wait started some 40 minutes ago and just came to an end. The PPT in direct speech is appropriate in this situation. Let’s say 30 minutes ago you’re still waiting, some other patient just came in and sat next to you and asked you, ”How long have you been waiting?” “I have been waiting for 30 minutes,” you answered. 30 minutes ago, your ‘struggle’ wasn’t over. The wait was still going on for another 10 minutes. The PPCT in direct speech is therefore appropriate in this situation.
‘To have kept’ is the perfect form of the present infinitive ‘to keep’ in 3. and 4. Both do the work of an adverb modifying the adjective ‘sorry’.
The nurse might have come to you after 20 minutes into your struggle and said, “I'm sorry to keep you waiting. It won’t be long now.” While the Doctor was ready to see you, she could’ve said, ‘I'm sorry to have kept you waiting. The Doctor is ready to see you now.’