Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions gateway/platforms/feishu.py
Original file line number Diff line number Diff line change
Expand Up @@ -2163,13 +2163,28 @@ async def _process_inbound_message(
chat_id = getattr(message, "chat_id", "") or ""
chat_info = await self.get_chat_info(chat_id)
sender_profile = await self._resolve_sender_profile(sender_id)
_raw_thread_id = getattr(message, "thread_id", None) or None
_raw_root_id = getattr(message, "root_id", None) or None
_resolved_chat_type = self._resolve_source_chat_type(chat_info=chat_info, event_chat_type=chat_type)
logger.debug(
"[Feishu] Thread context: thread_id=%r root_id=%r parent_id=%r chat_type=%r resolved=%r",
_raw_thread_id, _raw_root_id,
getattr(message, "parent_id", None),
chat_info.get("type"), _resolved_chat_type,
)
# In topic-mode groups (forum), use root_id as fallback for thread_id
# to ensure reply_in_thread=True so replies stay in the same topic.
_effective_thread_id = _raw_thread_id
if not _effective_thread_id and _resolved_chat_type == "forum" and _raw_root_id:
_effective_thread_id = _raw_root_id
logger.debug("[Feishu] Using root_id %s as thread_id fallback for forum chat", _raw_root_id)
source = self.build_source(
chat_id=chat_id,
chat_name=chat_info.get("name") or chat_id or "Feishu Chat",
chat_type=self._resolve_source_chat_type(chat_info=chat_info, event_chat_type=chat_type),
chat_type=_resolved_chat_type,
user_id=sender_profile["user_id"],
user_name=sender_profile["user_name"],
thread_id=getattr(message, "thread_id", None) or None,
thread_id=_effective_thread_id,
user_id_alt=sender_profile["user_id_alt"],
)
normalized = MessageEvent(
Expand Down
7 changes: 4 additions & 3 deletions gateway/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -7631,15 +7631,15 @@ async def send_progress_messages():
adapter.name,
)
can_edit = False
await adapter.send(chat_id=source.chat_id, content=msg, metadata=_progress_metadata)
await adapter.send(chat_id=source.chat_id, content=msg, reply_to=event_message_id, metadata=_progress_metadata)
else:
if can_edit:
# First tool: send all accumulated text as new message
full_text = "\n".join(progress_lines)
result = await adapter.send(chat_id=source.chat_id, content=full_text, metadata=_progress_metadata)
result = await adapter.send(chat_id=source.chat_id, content=full_text, reply_to=event_message_id, metadata=_progress_metadata)
else:
# Editing unsupported: send just this line
result = await adapter.send(chat_id=source.chat_id, content=msg, metadata=_progress_metadata)
result = await adapter.send(chat_id=source.chat_id, content=msg, reply_to=event_message_id, metadata=_progress_metadata)
if result.success and result.message_id:
progress_msg_id = result.message_id

Expand Down Expand Up @@ -7843,6 +7843,7 @@ def run_sync():
chat_id=source.chat_id,
config=_consumer_cfg,
metadata={"thread_id": _progress_thread_id} if _progress_thread_id else None,
reply_to=event_message_id,
)
if _want_stream_deltas:
_stream_delta_cb = _stream_consumer.on_delta
Expand Down
3 changes: 3 additions & 0 deletions gateway/stream_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@ def __init__(
chat_id: str,
config: Optional[StreamConsumerConfig] = None,
metadata: Optional[dict] = None,
reply_to: Optional[str] = None,
):
self.adapter = adapter
self.chat_id = chat_id
self.cfg = config or StreamConsumerConfig()
self.metadata = metadata
self.reply_to = reply_to
self._queue: queue.Queue = queue.Queue()
self._accumulated = ""
self._message_id: Optional[str] = None
Expand Down Expand Up @@ -718,6 +720,7 @@ async def _send_or_edit(self, text: str) -> bool:
result = await self.adapter.send(
chat_id=self.chat_id,
content=text,
reply_to=self.reply_to,
metadata=self.metadata,
)
if result.success:
Expand Down