In the first half of this year, spending by companies on artificial intelligence rivaled consumers as the primary engine of the nation’s economic expansion.