This advice may be too late to be useful; however, it is this:
You could and I recommend you accept the solid offer from Company B; if Company A then makes you an offer, you are free to consider it. This happens to people in other professional occupations, e.g. business, education, medicine, etc. While leaving Company B for Company A after only 3-4 weeks isn't great on your employment history, I don't think it does it harm, and that it's usually understood as being "practical" as opposed to "unloyal."
Good luck and i hope either you got that dream job or that Company B's job turned out to be better than expected.