Consider an isolated capacitor (no battery). Since the electrostatic force is conservative, the infinitesimal work done on the capacitor plates can be written as $$\mathrm{d} W=-\mathrm{d} U_e $$
Where $U_e$ is the electrostatic potential energy contained in the capacitor.
Suppose that now the capacitor is linked to a battery. On textbook I found that in this case, if I want to find the work done on the plates I must write$$\mathrm{d} W=-\mathrm{d} U_{tot}=-(\mathrm{d} U_e+\mathrm{d} U_{battery}) \tag{*}$$ Where $U_{battery}$ is called "internal energy of the battery".
My question is the following. Since $U_{battery}$ is probably some sort of energy linked to chemical reactions inside the battery, I do not think that it can be seen as a potential energy of some force field (which should be conservative). But then how is it possible to write $(*)$?
Only the infinitesimal work of a conservative force can be seen as the (exact) differential of a scalar field which represent a potential energy, but this is not true for non conservative processes (like the ones happening in a battery).
So how to justify $(*)$ from the point of view of the non reversibility of processes involved here?