[verified] fix: preserve timestamps in chat history

This commit is contained in:
2026-09-09 17:15:20 +00:00
parent 6be1601ccd
commit 1d85d7af6b
2 changed files with 31 additions and 3 deletions
+5 -3
View File
@@ -9,6 +9,7 @@ so the module can be imported by unit tests without a Hermes install.
from __future__ import annotations
import asyncio
import datetime as dt
import logging
import threading
import time
@@ -206,8 +207,10 @@ async def list_conversations(server: Any = None) -> List[Dict[str, Any]]:
def _iso(value: Any) -> Optional[str]:
try:
if isinstance(value, (int, float)):
return dt.datetime.fromtimestamp(value, tz=dt.timezone.utc).isoformat()
return value.isoformat() if value else None
except AttributeError:
except (AttributeError, OSError, OverflowError, TypeError, ValueError):
return None
@@ -254,8 +257,7 @@ async def conversation_history(conversation_id: str, limit: int
if isinstance(row.get("_row_id"), (int, str)) else None,
"role": role,
"text": text,
"ts": row.get("timestamp") if isinstance(
row.get("timestamp"), str) else None,
"ts": _iso(row.get("timestamp")),
})
found = True
except Exception: