A longtime Tesla Inc. executive is leaving the Elon Musk-run electric vehicle company, extending a string of departures as the manufacturer shifts its focus to artificial intelligence and robotics.