I believe the issue here is that a noun or pronoun + a form of have can only be contracted if the noun or pronoun is the subject of this form of have. That means have has to be a finite verb, not an infinitive, for infinitives normally don't have a proper subject.
How could I'
ve done this better?
In your first example, have is an infinitive; the finite verb is could.
"I had a great dinner today!" "Oh? What did you'
In your second example, it is also an infinitive; the finite verb is did. The reason is probably that a subject and its finite verb are closely connected grammatically; if you contract two words into one, this makes the words even more closely connected; but, if you contract a subject and an infinitive but leave out the subject's finite verb, then the wrong words are paired up, or so thinks our grammatical subconscious.
Another contraint here is that you normally can't contract a verb if it is stressed in pronunciation; when I pronounce what did you have?, emphasis lies on have, and the word is pronounced fully.
"I've seen it." "Oh, you'
Here have is a finite verb, not an infinitive; but you still can't contract it, because it is stressed.