In $\lambda$-calculus, is there a way to undo an application $(AB)$ to get back just $A$ or just $B$?

There is no way to get $B$ back - consider the term $A = \lambda y . \lambda x . x$. Then $AB = \lambda x . x$ for all $B$.

There is no way to get $A$ back either. Let $B = \lambda x . x$, $A_1 = \lambda y . \lambda x . x$, and $A_2 = \lambda x . x$. Then $A_1 B = A_2 B$ but $A_1 \neq A_2$.