The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(gateway/platforms): qqbot utils/onboard compaction (coerce_list one path, BindStatus tuple)
Teknium4b447a4d26f3
diff --git a/gateway/platforms/qqbot/onboard.py b/gateway/platforms/qqbot/onboard.pyindex 856be442daf..0215d41b0bd 100644--- a/gateway/platforms/qqbot/onboard.py+++ b/gateway/platforms/qqbot/onboard.py@@ -21,10 +21,7 @@ logger = logging.getLogger(__name__)class BindStatus(IntEnum):"""Status codes returned by ``_poll_bind_result``."""- NONE = 0- PENDING = 1- COMPLETED = 2- EXPIRED = 3+ NONE, PENDING, COMPLETED, EXPIRED = 0, 1, 2, 3try:@@ -73,12 +70,8 @@ def _create_bind_task(timeout: float = ONBOARD_API_TIMEOUT) -> Tuple[str, str]:def _poll_bind_result(task_id: str, timeout: float = ONBOARD_API_TIMEOUT) -> Tuple[BindStatus, str, str, str]:"""Poll *task_id*; returns ``(status, bot_appid, bot_encrypt_secret, user_openid)``."""- data = _portal_post(ONBOARD_POLL_PATH, {"task_id": task_id}, timeout, "poll_bind_result failed")- d = data.get("data", {})- return(- BindStatus(d.get("status", 0)), str(d.get("bot_appid", "")),- d.get("bot_encrypt_secret", ""), d.get("user_openid", ""),- )+ d = _portal_post(ONBOARD_POLL_PATH, {"task_id": task_id}, timeout, "poll_bind_result failed").get("data", {})+ return BindStatus(d.get("status", 0)), str(d.get("bot_appid", "")), d.get("bot_encrypt_secret", ""), d.get("user_openid", "")def build_connect_url(task_id: str) -> str:diff --git a/gateway/platforms/qqbot/utils.py b/gateway/platforms/qqbot/utils.pyindex a548d3f966c..0c67df45c36 100644--- a/gateway/platforms/qqbot/utils.py+++ b/gateway/platforms/qqbot/utils.py@@ -21,10 +21,8 @@ def _get_hermes_version() -> str:def build_user_agent() -> str:"""``QQBotAdapter/<qqbot_version> (Python/<py_version>; <os>; Hermes/<hermes_version>)``."""v = sys.version_info- return (- f"QQBotAdapter/{QQBOT_VERSION} (Python/{v.major}.{v.minor}.{v.micro}; "- f"{platform.system().lower()}; Hermes/{_get_hermes_version()})"- )+ return (f"QQBotAdapter/{QQBOT_VERSION} (Python/{v.major}.{v.minor}.{v.micro}; "+ f"{platform.system().lower()}; Hermes/{_get_hermes_version()})")def get_api_headers() -> Dict[str, str]:@@ -37,8 +35,5 @@ def coerce_list(value: Any) -> List[str]:"""Coerce a comma-separated string / list / tuple / set / scalar into a trimmed string list."""if value is None:return []- if isinstance(value, str):- return [item.strip() for item in value.split(",") if item.strip()]- if isinstance(value, (list, tuple, set)):- return [str(item).strip() for item in value if str(item).strip()]- return [str(value).strip()] if str(value).strip() else []+ items = value.split(",") if isinstance(value, str) else value if isinstance(value, (list, tuple, set)) else [value]+ return [s for s in (str(item).strip() for item in items) if s]