From c2d5f7bf2619d34c4812e817faba278cd836f243 Mon Sep 17 00:00:00 2001 From: teknium1 Date: Sun, 22 Feb 2026 02:37:26 -0800 Subject: [PATCH] feat: add timestamp formatting function for session metadata - Introduced a new `_format_timestamp` function to convert Unix timestamps and ISO strings into a human-readable date format. - Updated the session metadata handling to use the new formatting function for improved clarity in session start dates. - Adjusted the output structure to reflect the change from "Session started" to "Session date" for better user understanding. --- tools/session_search_tool.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/tools/session_search_tool.py b/tools/session_search_tool.py index 3935da649..87cb052c6 100644 --- a/tools/session_search_tool.py +++ b/tools/session_search_tool.py @@ -39,6 +39,26 @@ MAX_SESSION_CHARS = 100_000 MAX_SUMMARY_TOKENS = 2000 +def _format_timestamp(ts) -> str: + """Convert a Unix timestamp (float/int) or ISO string to a human-readable date.""" + if ts is None: + return "unknown" + try: + if isinstance(ts, (int, float)): + from datetime import datetime + dt = datetime.fromtimestamp(ts) + return dt.strftime("%B %d, %Y at %I:%M %p") + if isinstance(ts, str): + if ts.replace(".", "").replace("-", "").isdigit(): + from datetime import datetime + dt = datetime.fromtimestamp(float(ts)) + return dt.strftime("%B %d, %Y at %I:%M %p") + return ts + except Exception: + pass + return str(ts) + + def _format_conversation(messages: List[Dict[str, Any]]) -> str: """Format session messages into a readable transcript for summarization.""" parts = [] @@ -126,12 +146,12 @@ async def _summarize_session( ) source = session_meta.get("source", "unknown") - started = session_meta.get("started_at", "unknown") + started = _format_timestamp(session_meta.get("started_at")) user_prompt = ( f"Search topic: {query}\n" f"Session source: {source}\n" - f"Session started: {started}\n\n" + f"Session date: {started}\n\n" f"CONVERSATION TRANSCRIPT:\n{conversation_text}\n\n" f"Summarize this conversation with focus on: {query}" ) @@ -243,9 +263,9 @@ def session_search( if summary: summaries.append({ "session_id": session_id, + "when": _format_timestamp(match_info.get("session_started")), "source": match_info.get("source", "unknown"), "model": match_info.get("model"), - "session_started": match_info.get("session_started"), "summary": summary, })