from yuxi.channel.extensions.tlon.utils import normalize_ship TLON_CONFIG_SCHEMA = { "type": "object", "properties": { "name": {"type": "string"}, "enabled": {"type": "boolean", "default": True}, "ship": {"type": "string", "minLength": 1, "pattern": "^~?[a-z-]+$"}, "url": {"type": "string", "minLength": 1, "format": "uri"}, "code": {"type": "string", "minLength": 1}, "network": { "type": "object", "properties": { "dangerouslyAllowPrivateNetwork": {"type": "boolean"}, }, }, "groupChannels": { "type": "array", "items": {"type": "string"}, }, "dmAllowlist": { "type": "array", "items": {"type": "string"}, }, "groupInviteAllowlist": { "type": "array", "items": {"type": "string"}, }, "autoDiscoverChannels": {"type": "boolean"}, "showModelSignature": {"type": "boolean"}, "autoAcceptDmInvites": {"type": "boolean"}, "autoAcceptGroupInvites": {"type": "boolean"}, "ownerShip": {"type": "string"}, "defaultAuthorizedShips": { "type": "array", "items": {"type": "string"}, }, "authorization": { "type": "object", "properties": { "channelRules": { "type": "object", "additionalProperties": { "type": "object", "properties": { "mode": {"enum": ["restricted", "open"]}, "allowedShips": { "type": "array", "items": {"type": "string"}, }, }, }, }, }, }, "accounts": { "type": "object", "additionalProperties": {"$ref": "#"}, }, }, } class TlonConfigAdapter: def list_account_ids(self, config: dict) -> list[str]: accounts = config.get("channels", {}).get("tlon", {}).get("accounts", {}) if accounts: return list(accounts.keys()) return ["default"] def resolve_account(self, account_id: str, config: dict | None = None) -> dict: if config is None: return {"account_id": account_id} tlon_config = config.get("channels", {}).get("tlon", {}) account = tlon_config.get("accounts", {}).get(account_id, tlon_config) return { "account_id": account_id, "ship": account.get("ship"), "url": account.get("url"), "code": account.get("code"), "name": account.get("name"), "network": account.get("network", {}), "group_channels": account.get("groupChannels", []), "dm_allowlist": account.get("dmAllowlist", []), "group_invite_allowlist": account.get("groupInviteAllowlist", []), "auto_discover_channels": account.get("autoDiscoverChannels", False), "show_model_signature": account.get("showModelSignature", False), "auto_accept_dm_invites": account.get("autoAcceptDmInvites", False), "auto_accept_group_invites": account.get("autoAcceptGroupInvites", False), "owner_ship": account.get("ownerShip"), "default_authorized_ships": account.get("defaultAuthorizedShips", []), "authorization": account.get("authorization", {}), } def is_configured(self, account: dict) -> bool: return bool(account.get("ship") and account.get("url") and account.get("code")) def is_enabled(self, account: dict) -> bool: return account.get("enabled", True) def disabled_reason(self, account: dict) -> str: if self.is_configured(account): return "" missing = [] if not account.get("ship"): missing.append("ship") if not account.get("url"): missing.append("url") if not account.get("code"): missing.append("code") return f"Account not configured (missing {', '.join(missing)})" def describe_account(self, account: dict) -> dict: ship = account.get("ship", "") return { "account_id": account.get("account_id", "default"), "label": ship, "display": f"{ship} ({account.get('url', '')})", } def normalize_ships_in_allowlist(self, allowlist: list[str]) -> list[str]: return [normalize_ship(s) for s in allowlist if s.strip()]