Unions have negotiated with companies that outsource or automate its members' jobs to secure compensation for the workers who were affected.
However, I think this is a problem that requires a larger solution. There needs to be compensation plans for workers as they're automated away or outsourced. Perhaps it can be a buyout, or a shared ownership scheme where workers get shares in the company or the automation itself that pay dividends. Or a tax on automation or outsourcing that gets returned to workers.
We're heading towards a world where most work is done by machines, and only a handful of people will own, control and profit from them. I think a tax and a shared ownership model would help prevent a world where workers and their progeny are relegated to peasantry.