import type { SuperagentUser } from '../types'; /** * The signed-in user's avatar URL, derived from the host-injected `/me` object. * Prefers the explicit `profile_image_url`, then the common Google OAuth image * fields (`picture` / `photo` / `avatar_url`), and finally `null`. Whitespace-only * values are treated as absent. Kept as a pure helper so the runtime never has to * take a pre-computed avatar prop — it derives it from `user` directly. */ export function getUserProfileImageUrl(user?: SuperagentUser | null): string | null { const profileImageUrl = user?.profile_image_url; if (typeof profileImageUrl === 'string' && profileImageUrl.trim()) { return profileImageUrl.trim(); } return extractGoogleProfileImage(user); } function extractGoogleProfileImage(user?: SuperagentUser | null): string | null { const candidates = [user?.picture, user?.photo, user?.avatar_url]; const image = candidates.find((value) => typeof value === 'string' && value.trim()); return typeof image === 'string' ? image.trim() : null; }