Просмотр исходного кода

feat: Use Hermes SDK SetThread for thread context isolation

- Replace manual threadRootEventId extraction with Hermes SDK propagate_context_to_thread()
- Keep threadRootEventId injection for Chatto protocol compliance
- Add debug logging for SDK availability

This ensures the agent's execution context is isolated per thread, matching the FDR (ADR #2) requirements.
Liv Klumpp 1 неделя назад
Родитель
Сommit
f37ca82ec4
2 измененных файлов с 11 добавлено и 2 удалено
  1. 2 2
      README.md
  2. 9 0
      adapter.py

+ 2 - 2
README.md

@@ -44,7 +44,7 @@ hermes gateway restart
 | `CHATTO_URL` | Yes | Base URL of your Chatto server |
 | `CHATTO_URL` | Yes | Base URL of your Chatto server |
 | `CHATTO_LOGIN` | Yes | Chatto username |
 | `CHATTO_LOGIN` | Yes | Chatto username |
 | `CHATTO_PASSWORD` | Yes | Chatto password |
 | `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_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_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) |
 | `CHATTO_AUTO_THREAD` | No | Auto-create threads for replies in rooms (default: true) |
@@ -95,4 +95,4 @@ Chatto v0.4.19. Protocol version 1 (binary protobuf over WebSocket).
 
 
 ## License
 ## License
 
 
-MIT
+MIT

+ 9 - 0
adapter.py

@@ -1819,6 +1819,15 @@ class ChattoAdapter(BasePlatformAdapter):
         thread_info = msg.get("thread", {})
         thread_info = msg.get("thread", {})
         if thread_info and str(thread_info.get("threadRootEventId", "")) != msg_id:
         if thread_info and str(thread_info.get("threadRootEventId", "")) != msg_id:
             thread_id = str(thread_info.get("threadRootEventId", ""))
             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(
         source = self.build_source(
             chat_id=room_id,
             chat_id=room_id,