fix: patch SessionDB methods for session_search user_id compat
This commit is contained in:
51
__init__.py
51
__init__.py
@@ -237,6 +237,56 @@ def _apply_honcho_patch():
|
|||||||
logger.warning("identity: failed to patch Honcho init: %s", exc)
|
logger.warning("identity: failed to patch Honcho init: %s", exc)
|
||||||
|
|
||||||
|
|
||||||
|
# ── SessionDB patch (version compat: user_id kwarg) ──────────────────────
|
||||||
|
|
||||||
|
_session_db_patched = False
|
||||||
|
|
||||||
|
|
||||||
|
def _patch_session_db() -> None:
|
||||||
|
"""Monkey-patch SessionDB methods to accept (and ignore) the ``user_id``
|
||||||
|
kwarg that the built-in ``session_search`` tool passes but the upstream
|
||||||
|
backend no longer supports. Same zero-fork pattern as the Honcho patch."""
|
||||||
|
global _session_db_patched
|
||||||
|
if _session_db_patched:
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
from hermes_state import SessionDB
|
||||||
|
except ImportError as exc:
|
||||||
|
logger.warning("identity: hermes_state not importable (%s), skipping SessionDB patch", exc)
|
||||||
|
return
|
||||||
|
except Exception as exc:
|
||||||
|
logger.warning("identity: failed to import SessionDB: %s", exc)
|
||||||
|
return
|
||||||
|
|
||||||
|
# search_messages
|
||||||
|
orig_search = SessionDB.search_messages
|
||||||
|
if orig_search is None:
|
||||||
|
logger.warning("identity: SessionDB.search_messages not found")
|
||||||
|
return
|
||||||
|
|
||||||
|
def _patched_search(self, *args, **kwargs):
|
||||||
|
kwargs.pop("user_id", None)
|
||||||
|
return orig_search(self, *args, **kwargs)
|
||||||
|
|
||||||
|
SessionDB.search_messages = _patched_search
|
||||||
|
|
||||||
|
# list_sessions_rich
|
||||||
|
orig_list = SessionDB.list_sessions_rich
|
||||||
|
if orig_list is None:
|
||||||
|
logger.warning("identity: SessionDB.list_sessions_rich not found")
|
||||||
|
return
|
||||||
|
|
||||||
|
def _patched_list(self, *args, **kwargs):
|
||||||
|
kwargs.pop("user_id", None)
|
||||||
|
return orig_list(self, *args, **kwargs)
|
||||||
|
|
||||||
|
SessionDB.list_sessions_rich = _patched_list
|
||||||
|
|
||||||
|
_session_db_patched = True
|
||||||
|
logger.info("identity: patched SessionDB methods ✓")
|
||||||
|
|
||||||
|
|
||||||
# ── Hooks ───────────────────────────────────────────────────────────────────
|
# ── Hooks ───────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
|
||||||
@@ -382,6 +432,7 @@ def register(ctx: Any) -> None:
|
|||||||
# Apply the runtime monkey-patch to Honcho's session init
|
# Apply the runtime monkey-patch to Honcho's session init
|
||||||
# NO files modified, NO fork needed — pure Python at import time
|
# NO files modified, NO fork needed — pure Python at import time
|
||||||
_apply_honcho_patch()
|
_apply_honcho_patch()
|
||||||
|
_patch_session_db()
|
||||||
|
|
||||||
# Register hooks
|
# Register hooks
|
||||||
ctx.register_hook("pre_gateway_dispatch", _pre_gateway_dispatch)
|
ctx.register_hook("pre_gateway_dispatch", _pre_gateway_dispatch)
|
||||||
|
|||||||
Reference in New Issue
Block a user