from __future__ import annotations def normalize_googlechat_target(raw: str) -> str | None: if not raw: return None t = raw.strip() for prefix in ("googlechat:", "google-chat:", "gchat:"): if t.lower().startswith(prefix): t = t[len(prefix):] t = t.strip() break if t.lower().startswith("user:users/"): t = t[5:] elif t.lower().startswith("space:spaces/"): t = t[6:] if "@" in t and not t.startswith("users/") and not t.startswith("spaces/"): t = f"users/{t.lower()}" return t def strip_message_suffix(target: str) -> str: idx = target.find("/messages/") return target[:idx] if idx != -1 else target async def resolve_outbound_space(account, target: str) -> str | None: from yuxi.channel.extensions.googlechat.api import find_direct_message normalized = normalize_googlechat_target(target) if not normalized: return None base = strip_message_suffix(normalized) if base.startswith("spaces/"): return base if base.startswith("users/"): return await find_direct_message(account, base) return None def is_space_target(target: str) -> bool: return target.startswith("spaces/") def is_user_target(target: str) -> bool: return target.startswith("users/")