mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-13 09:01:54 +00:00
feat(matrix): add dm_auto_thread config for DM auto-threading
Adds MATRIX_DM_AUTO_THREAD env var (default: false) to control auto-threading in DM rooms independently from channel auto-threading. Closes #15398
This commit is contained in:
parent
74a4832b74
commit
1eab5960f0
3 changed files with 63 additions and 2 deletions
|
|
@ -18,6 +18,7 @@ Environment variables:
|
|||
MATRIX_REQUIRE_MENTION Require @mention in rooms (default: true)
|
||||
MATRIX_FREE_RESPONSE_ROOMS Comma-separated room IDs exempt from mention requirement
|
||||
MATRIX_AUTO_THREAD Auto-create threads for room messages (default: true)
|
||||
MATRIX_DM_AUTO_THREAD Auto-create threads for DM messages (default: false)
|
||||
MATRIX_RECOVERY_KEY Recovery key for cross-signing verification after device key rotation
|
||||
MATRIX_DM_MENTION_THREADS Create a thread when bot is @mentioned in a DM (default: false)
|
||||
"""
|
||||
|
|
@ -301,6 +302,9 @@ class MatrixAdapter(BasePlatformAdapter):
|
|||
"1",
|
||||
"yes",
|
||||
)
|
||||
self._dm_auto_thread: bool = os.getenv(
|
||||
"MATRIX_DM_AUTO_THREAD", "false"
|
||||
).lower() in ("true", "1", "yes")
|
||||
self._dm_mention_threads: bool = os.getenv(
|
||||
"MATRIX_DM_MENTION_THREADS", "false"
|
||||
).lower() in ("true", "1", "yes")
|
||||
|
|
@ -1416,7 +1420,7 @@ class MatrixAdapter(BasePlatformAdapter):
|
|||
body = self._strip_mention(body)
|
||||
|
||||
# Auto-thread.
|
||||
if not is_dm and not thread_id and self._auto_thread:
|
||||
if not thread_id and ((not is_dm and self._auto_thread) or (is_dm and self._dm_auto_thread)):
|
||||
thread_id = event_id
|
||||
self._threads.mark(thread_id)
|
||||
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ _EXTRA_ENV_KEYS = frozenset({
|
|||
"WHATSAPP_MODE", "WHATSAPP_ENABLED",
|
||||
"MATTERMOST_HOME_CHANNEL", "MATTERMOST_REPLY_MODE",
|
||||
"MATRIX_PASSWORD", "MATRIX_ENCRYPTION", "MATRIX_DEVICE_ID", "MATRIX_HOME_ROOM",
|
||||
"MATRIX_REQUIRE_MENTION", "MATRIX_FREE_RESPONSE_ROOMS", "MATRIX_AUTO_THREAD",
|
||||
"MATRIX_REQUIRE_MENTION", "MATRIX_FREE_RESPONSE_ROOMS", "MATRIX_AUTO_THREAD", "MATRIX_DM_AUTO_THREAD",
|
||||
"MATRIX_RECOVERY_KEY",
|
||||
})
|
||||
import yaml
|
||||
|
|
@ -1839,6 +1839,14 @@ OPTIONAL_ENV_VARS = {
|
|||
"category": "messaging",
|
||||
"advanced": True,
|
||||
},
|
||||
"MATRIX_DM_AUTO_THREAD": {
|
||||
"description": "Auto-create threads for DM messages in Matrix (default: false)",
|
||||
"prompt": "Auto-create threads in DMs (true/false)",
|
||||
"url": None,
|
||||
"password": False,
|
||||
"category": "messaging",
|
||||
"advanced": True,
|
||||
},
|
||||
"MATRIX_DEVICE_ID": {
|
||||
"description": "Stable Matrix device ID for E2EE persistence across restarts (e.g. HERMES_BOT)",
|
||||
"prompt": "Matrix device ID (stable across restarts)",
|
||||
|
|
|
|||
|
|
@ -2209,3 +2209,52 @@ class TestMatrixOnRoomMessageFilter:
|
|||
ev = self._mk_event(sender="@alice:example.org", body="hello bot")
|
||||
await self.adapter._on_room_message(ev)
|
||||
self.adapter._handle_text_message.assert_awaited_once()
|
||||
# ---------------------------------------------------------------------------
|
||||
# DM auto-thread
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
class TestMatrixDmAutoThread:
|
||||
def setup_method(self):
|
||||
self.adapter = _make_adapter()
|
||||
self.adapter._is_dm_room = AsyncMock(return_value=True)
|
||||
self.adapter._get_display_name = AsyncMock(return_value="Alice")
|
||||
self.adapter._background_read_receipt = MagicMock()
|
||||
# Disable require_mention so DMs pass gating
|
||||
self.adapter._require_mention = False
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_dm_auto_thread_enabled_creates_thread(self):
|
||||
"""When dm_auto_thread is True, DM messages get auto-threaded."""
|
||||
self.adapter._dm_auto_thread = True
|
||||
|
||||
ctx = await self.adapter._resolve_message_context(
|
||||
room_id="!dm:ex",
|
||||
sender="@alice:ex",
|
||||
event_id="$ev1",
|
||||
body="hello",
|
||||
source_content={"body": "hello"},
|
||||
relates_to={},
|
||||
)
|
||||
|
||||
assert ctx is not None
|
||||
_body, _is_dm, _chat_type, thread_id, _display, _source = ctx
|
||||
assert thread_id == "$ev1"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_dm_auto_thread_disabled_no_thread(self):
|
||||
"""When dm_auto_thread is False (default), DMs have no auto-thread."""
|
||||
self.adapter._dm_auto_thread = False
|
||||
|
||||
ctx = await self.adapter._resolve_message_context(
|
||||
room_id="!dm:ex",
|
||||
sender="@alice:ex",
|
||||
event_id="$ev2",
|
||||
body="hello",
|
||||
source_content={"body": "hello"},
|
||||
relates_to={},
|
||||
)
|
||||
|
||||
assert ctx is not None
|
||||
_body, _is_dm, _chat_type, thread_id, _display, _source = ctx
|
||||
assert thread_id is None
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue