浏览代码

Isolate thread context through the Hermes SDK

Thread turns must not leak their conversation into other sessions.
Hermes injects an SDK with propagate_context_to_thread(thread_id) for
exactly that, so use it when a thread_id is present. Best-effort by
design: a missing SDK or failed propagation logs and continues rather
than breaking the turn. The raw threadRootEventId stays injected because
the Chatto protocol itself requires it.
Paul Klumpp 1 月之前
父节点
当前提交
d3abab38dc
共有 2 个文件被更改,包括 10 次插入1 次删除
  1. 1 1
      README.md
  2. 9 0
      adapter.py

+ 1 - 1
README.md

@@ -44,7 +44,7 @@ hermes gateway restart
 | `CHATTO_URL` | Yes | Base URL of your Chatto server |
 | `CHATTO_LOGIN` | Yes | Chatto username |
 | `CHATTO_PASSWORD` | Yes | Chatto password |
-| `CHATTO_HOME_CHANNEL` | No | Room ID for cron/notification delivery (defaults to first watched room) |
+| `CHATTO_HOME_CHANNEL` | No | **Cron-Job-Zielkanal**: Legt den Standard-Raum fest, in den geplante Cron-Jobs (z. B. „tägliche Nachricht um 9 Uhr“) ihre Ergebnisse ausliefern. Wenn nicht gesetzt, nimmt der Bot die erste Room-ID, in der er gelistet ist. Beispiel: `CHATTO_HOME_CHANNEL=RbmwiHk4vs9a3Ql` |
 | `CHATTO_CHANNELS` | No | Comma-separated room IDs to watch (default: all joined rooms) |
 | `CHATTO_REQUIRE_MENTION` | No | Only respond to @mentions in rooms (default: true). DMs always respond. |
 | `CHATTO_AUTO_THREAD` | No | Auto-create threads for replies in rooms (default: true) |

+ 9 - 0
adapter.py

@@ -1819,6 +1819,15 @@ class ChattoAdapter(BasePlatformAdapter):
         thread_info = msg.get("thread", {})
         if thread_info and str(thread_info.get("threadRootEventId", "")) != msg_id:
             thread_id = str(thread_info.get("threadRootEventId", ""))
+            # Hermes SDK: Propagate thread context if thread_id is set
+            try:
+                # Hermes injects the SDK into the plugin context as self.sdk
+                propagate_context_to_thread = self.sdk.thread_context.propagate_context_to_thread
+                propagate_context_to_thread(thread_id)
+            except AttributeError:
+                logger.debug("Hermes SDK thread_context not available in plugin context")
+            except Exception as e:
+                logger.warning("Failed to propagate thread context: %s", e, exc_info=True)
 
         source = self.build_source(
             chat_id=room_id,