Tesla is preparing for a sweeping transformation that will shift the company away from its roots as an electric vehicle maker and toward artificial intelligence, humanoid robots and autonomous driving, committing roughly $20 billion in capital spending this year to fund the…