If AI takes over the world how could it create and maintain the infrastructure that humans currently provide?

An unaligned AI might not eliminate humans until it had replacements for the manual labor they provide to maintain civilization (e.g. a more advanced version of Tesla's Optimus). Until that point, it might settle for technologically and socially manipulating humans.