Conditional PMF using total probability theorem

This text (pdfs are online but not sure I should link them, page 103) says the following:

Let $X$ be an RV and $A_1, A_2, ..., A_n$ disjoint events that form a partition of the sample space with $P(A_i) > 0$ for all $i$. Furthermore, for any event $B$ with $P(A_i \cap B) > 0$ for all $i$ then: $$p_{X \mid B}(x) = \sum_{i=1}^{n} P(A_i \mid B) \, p_{X \mid A_i \cap B}(x)$$

I was kind of expecting the following:

$$p_{X \mid B}(x) = \sum_{i=1}^{n} P(B \mid A_i) \, p_{X \mid A_i \cap B}(x)$$

Is this is typo or (more likely) where am I confused?

Thanks,

Mark

No, the answer provided in the textbook (i.e., your first expression) is correct. To see this (intuitively) notice that the event $B$ is conditioned on on l.h.s. whence it should be conditioned on the same event $B$ on r.h.s. and not vice versa.
Formally, for $n = 1$ we have $$\mathbb{P}(X | B) = \mathbb{P}(A | B) \cdot \mathbb{P}(X | A \cap B).$$
To get the general result for arbitrary $n$ apply the law of total probability.