from __future__ import annotations import asyncio import logging from yuxi.channel.extensions.feishu.types import FeishuGroupSessionScope from yuxi.channel.extensions.feishu.session import FeishuSessionAdapter logger = logging.getLogger(__name__) class FeishuThreadingAdapter: def __init__(self): self._session = FeishuSessionAdapter() def resolve_session_scope( self, account: dict, chat_id: str, *, sender_id: str | None = None, thread_id: str | None = None, ) -> str: scope = account.get("group_session_scope", "group") groups = account.get("groups", {}) if chat_id in groups: group_cfg = groups[chat_id] if "group_session_scope" in group_cfg: scope = group_cfg["group_session_scope"] return self._session.build_session_key( chat_id, sender_id=sender_id, thread_id=thread_id, scope=scope, ) def get_thread_info(self, thread_id: str) -> dict | None: return { "thread_id": thread_id, "is_topic": thread_id.startswith("omt_") if thread_id else False, } def should_reply_in_thread(self, account: dict, chat_id: str | None = None) -> bool: reply_in_thread = account.get("reply_in_thread", "disabled") if chat_id: groups = account.get("groups", {}) group_cfg = groups.get(chat_id, {}) if "reply_in_thread" in group_cfg: reply_in_thread = group_cfg["reply_in_thread"] return reply_in_thread == "enabled" def extract_thread_id(self, msg: object) -> str | None: return self._session.extract_thread_id(msg)