I'm not sure if my OutSim class does this for me or if it comes from LFS directly (I'm at work, so I can't look at my source code at the moment), but in the OutSim packet I have a velocity Vector3 that is aligned with the current heading/pitch/roll, so the Y axis is always the longitudinal speed (forward axis), whereas the X axis is the lateral one and Z is up/down, of course. You can then calculate the angle of the XY vector (= drift angle), or normalize it and just use the X component as "oversteer" factor. Basically any lateral motion is "oversteer" in this case (since the car always wants to go forward, not sideways), though of course in the corners there will always be
some amount of lateral slip. So yeah, I just described taking the difference between direction and heading in a more complicated way
Understeer on the other hand is a failure of the car to follow where your front tyres are pointing. To calculate this you need to take your steer input and together with the car's max steer angle (from the setup, or hardcoded for now) calculate the actual heading of your front tyres. Then just take the difference of tyre heading and car velocity vector. Don't forget to set the wheel turn compensation in LFS to be linear, though! Of course if your car oversteers and you don't do anything against it, your front tyres will now also point somewhere else than the car is going, so this does not count as understeer obviously. The oversteer factor has to take precedence in this case ("it's only understeer if there is no oversteer").
That's at least from my point of view a reasonably accurate calculation approach of getting the over-/understeer state, if you want to directly feed this information to the AI logic is up to you. Personally I would, maybe only in an abstracted form of "no, little, medium, heavy, catastrophic over-/understeer," since a human doesn't really know the exact angle anyway. Of course this info could also be attained indirectly from how your reference points move in relation to how you want them to move, but that just seems to be a very hard way with many pitfalls just to find out what a human race driver immediately knows without having to think about it.