Up, up, and away (but you should have gotten away *)
While a DM can always make a ruling, the text (and lack of text) provide a clear direction as to what is going to happen. There isn't any ambiguity, because the only way to create ambiguity is to introduce text that isn't there that is with other mechanics.
You've quoted the relevant rules around the use of the flying carpet - and it dictates you need to be within 30' of it in order to command it. That's it. That's all. Give command? Be in 30' of the item. Other than that, there are no other requirements or limitations.
Without any limitations, the carpet has no reason to follow a new command. It's just listening to your original. The lack of language detailing what happens when outside of 30' means there is nothing new that happens outside of 30' (other than not being able to command it.)
However - it sounds like the creature used an opportunity attack to hit you as you flew away. You have not used any of your movement, so you did not trigger an opportunity attack. Without that attack, you woudn't have been hit and the carpet would have whisked you away to safety (assuming that attacker didn't have any ranged options for later.)
But let's go with the on-the-fly ruling at the table and look to see if there is any language specifically stating what happens if the rug is outside of 30' (besides not being able to command it.)
There are other mechanics which limit how far something can be in order to stay under control
But those aren't used in this item - so we really shouldn't just add them in.
Something like Tenser's floating disk has qualifying language:
The disk is immobile while you are within 20 feet of it. If you move more than 20 feet away from it, the disk follows you so that it remains within 20 feet of you. It can move across uneven terrain, up or down stairs, slopes and the like, but it can’t cross an elevation change of 10 feet or more. For example, the disk can’t move across a 10-foot-deep pit, nor could it leave such a pit if it was created at the bottom.
If you move more than 100 feet from the disk (typically because it can’t move around an obstacle to follow you), the spell ends.
These qualifications are in place to limit how and when you can command what happens when it goes out of range.
The Carpet has no such qualifications, so it doesn't really make sense just to add them - or to try and use the command limiter to mean more than it says.
Range limiting
Without any language directly stating that the carpet stops once outside of command range, then it would say so. Adding it in may include some unforeseen issues such as wanting to command it to do something that is more than 30' away and not being able to do so (maybe you want to allow an ally to get on.)
Again, without any direct limiting language, the sentence is clear that this is about when you can command it and not what happens when it leaves command range.
To the moon!
In this case, what happened in narration was you hopped on your carpet in a panic to escape a monster. You commanded the carpet to "go up!" (with no limitation on how far or specified distance.) With no limit, I would just have the carpet move at it's max movement - and will continue to do so until it receives a command to stop or do something else.
Unfortunately, if you can't get up to within 30' of it, it'll just keep going up. And up. And up. And up.
Failing forward
Good news is, this can become a plot hook! Whenever something suboptimal happens to my player characters, I do try and figure out ways to make it more than just a 'loss.' The search for the carpet may be a fun diversion for a session or two and would be a good way to complete the cycle of panicked loss to happiness with being reunited.