mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-05-20 00:22:31 +00:00
feat(feishu): per-message session for group top-level messages
Align with deer-flow: group top-level messages (no root_id) now get their own session keyed by message_id instead of sharing a single group-wide session. Topic replies continue to share session via root_id.
This commit is contained in:
parent
d5122f6df8
commit
08c5ce95f2
@ -1728,11 +1728,11 @@ class FeishuChannel(BaseChannel):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Build topic-scoped session key for conversation isolation.
|
# Build topic-scoped session key for conversation isolation.
|
||||||
# Group chat: thread replies (root_id != message_id) get a scoped
|
# Group chat: each topic gets its own session via root_id (replies
|
||||||
# session so each Feishu thread has its own conversation context.
|
# inside a topic) or message_id (top-level messages start a new topic).
|
||||||
# Private chat: no override — same behavior as Telegram/Slack.
|
# Private chat: no override — same behavior as Telegram/Slack.
|
||||||
if chat_type == "group" and root_id and root_id != message_id:
|
if chat_type == "group":
|
||||||
session_key = f"feishu:{chat_id}:{root_id}"
|
session_key = f"feishu:{chat_id}:{root_id or message_id}"
|
||||||
else:
|
else:
|
||||||
session_key = None
|
session_key = None
|
||||||
|
|
||||||
|
|||||||
@ -480,8 +480,8 @@ async def test_session_key_group_with_root_id_is_thread_scoped() -> None:
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_session_key_group_no_root_id_uses_default() -> None:
|
async def test_session_key_group_no_root_id_uses_message_id() -> None:
|
||||||
"""Group message without root_id uses default session key (no override)."""
|
"""Group message without root_id gets session keyed by message_id (per-message session)."""
|
||||||
channel = _make_feishu_channel(group_policy="open")
|
channel = _make_feishu_channel(group_policy="open")
|
||||||
bus_spy = []
|
bus_spy = []
|
||||||
original_publish = channel.bus.publish_inbound
|
original_publish = channel.bus.publish_inbound
|
||||||
@ -504,8 +504,7 @@ async def test_session_key_group_no_root_id_uses_default() -> None:
|
|||||||
await channel._on_message(event)
|
await channel._on_message(event)
|
||||||
|
|
||||||
assert len(bus_spy) == 1
|
assert len(bus_spy) == 1
|
||||||
assert bus_spy[0].session_key_override is None
|
assert bus_spy[0].session_key == "feishu:oc_abc:om_001"
|
||||||
assert bus_spy[0].session_key == "feishu:oc_abc"
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user