from __future__ import annotations from typing import Any def list_peers(allow_from: list[str]) -> list[dict[str, Any]]: peers: list[dict[str, Any]] = [] for entry in allow_from: if entry == "*": continue normalized = normalize_id(entry) peers.append({"id": normalized, "raw": entry, "type": "user"}) return peers def list_groups(groups_config: dict[str, Any]) -> list[dict[str, Any]]: groups: list[dict[str, Any]] = [] for space_name, cfg in groups_config.items(): if not isinstance(cfg, dict): continue groups.append( { "id": space_name, "type": "space", "name": cfg.get("name", space_name), "enabled": cfg.get("enabled", True), "requires_mention": cfg.get("require_mention", cfg.get("requireMention", False)), } ) return groups def normalize_id(raw: str) -> str: if not raw: return "" raw = raw.strip() if raw.startswith("spaces/"): return raw if raw.startswith("users/"): return raw if raw.startswith("user:"): return raw.replace("user:", "users/", 1) if "@" in raw: return f"users/{raw}" return f"users/{raw}"