from __future__ import annotations from typing import Any def merge_account_config( top: dict[str, Any], account: dict[str, Any], ) -> dict[str, Any]: overridable_keys = { "server_url", "password", "dm_policy", "group_policy", "dm_allow_from", "group_allow_chats", "require_mention", "tapback_enabled", "media_max_mb", "media_local_roots", "allow_private_network", "webhook_path", "webhook_secret", "send_read_receipts", "text_chunk_limit", "chunk_mode", "block_streaming", "send_timeout_ms", "dm_history_limit", } merged = dict(top) for key in overridable_keys: if key in account and account[key]: merged[key] = account[key] return merged def apply_account_configs( top_config: dict[str, Any], accounts_config: dict[str, Any], allow_config_writes: bool = True, ) -> dict[str, dict[str, Any]]: if not allow_config_writes: return {"default": dict(top_config)} result: dict[str, dict[str, Any]] = {"default": dict(top_config)} for account_id, raw in accounts_config.items(): if not isinstance(raw, dict): continue result[account_id] = merge_account_config(top_config, raw) return result