1. Living in a tech hub like the Bay Area or Seattle. There may be tech hubs in RTP, Austin, Boston, etc but these tend to be inshoring offices and are oftentimes the first on the chopping block when offshoring is considered, because they never built the internal gravity needed to own P/L and roadmap, and those offices that did are few and far between.
2. Concentrate on doing a reputable online or part-time MSCS (eg. GATech, UIUC, UT Austin) and concentrating on fundamental courses. Coding is commodified, but programming isn't. Just understanding how to glue together Python, C/C++, or whatever language and associated libraries is not enough. Technical complexity is rising, and skills like understanding OS internals, understanding the fundamentals of SGD, or truly understanding how to derive a path tracing algorithm matters.
3. Hyper-specialize in a specific industry. "AI" is broad, just like "Mobile" was broad. What matters is how these platforms are applied to a specific industry subdomain. If I'm a cybersecurity company working on building an AI SOC, I'd rather hire Engineers who understand both core fundamentals of AI and Cybersecurity. If you are an engineer who can understand how to communicate both the business incentives as well as the engineering incentives you are worth your weight in gold.
The thing is, this isn't 2000 anymore. Eastern Europe, China, India, ASEAN, LATAM, and other regions of the world have fairly large and robust dev and tech scenes, and async+remote work has been proven out during COVID, thus removing one of the biggest barriers to offshoring. Additionally, there has been a reverse brain drain since the mid-2010s from the US to those countries that is making it easier to find talent to open an office following American norms.
I think as a mid-career engineer, you have the tools to survive this kind of a change. Any American SWE who graduated in the last 10 years is in a worse position because their universities failed them by watering down curricula to compete with bootcamps, reducing the business justification for building a domestic new grad pipeline aside from a couple top target programs.