4. In a convex quadrilateral $ABCD$, it is known that $AB=2AD$, $BC=1$, $\angle ABC=\angle BCD=60^{\circ}$, $\angle ADC=$ $90^{\circ}$. Then the length of $AB$ is ( ).
(A) $\frac{3-\sqrt{3}}{4}$
(B) $\frac{3-\sqrt{3}}{2}$
(C) $2-\sqrt{3}$
(D) $2 \sqrt{3}-3$
4. B.

As shown in Figure 2, extend $B A$ and $C D$ to intersect at $E$. Then $\triangle E B C$ is an equilateral triangle.
Let $A B=2 x$. Then
$$
\begin{array}{l}
A D=x, \\
A E=1-2 x .
\end{array}
$$

In the right triangle $\triangle E A D$,
$$
\begin{aligned}
\frac{x}{1-2 x}=\sin 60^{\circ}=\frac{\sqrt{3}}{2} \\
\Rightarrow x=\frac{3-\sqrt{3}}{4} \Rightarrow A B=\frac{3-\sqrt{3}}{2} .
\end{aligned}
$$