Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
fix(webui): bound restored session previews
Xubin Ren335808e525be
diff --git a/nanobot/webui/session_list_index.py b/nanobot/webui/session_list_index.pyindex c6c7fc650..eb343b530 100644--- a/nanobot/webui/session_list_index.py+++ b/nanobot/webui/session_list_index.py@@ -496,14 +496,17 @@ def _transcript_preview(record: dict[str, Any]) -> tuple[str, str]:text = record.get("text")if not isinstance(text, str) or not text.strip():return "", ""+ preview = _message_preview_text({"content": text})+ if not preview:+ return "", ""event = record.get("event")if event == "user" or record.get("role") == "user":- return text, ""+ return preview, ""if (event == "message"and record.get("kind") not in _TRANSCRIPT_NON_ANSWER_KINDS) or record.get("role") == "assistant":- return "", text+ return "", previewreturn "", ""diff --git a/tests/webui/test_session_list_index.py b/tests/webui/test_session_list_index.pyindex 6e1d71215..10c97b61a 100644--- a/tests/webui/test_session_list_index.py+++ b/tests/webui/test_session_list_index.py@@ -1,6 +1,7 @@from __future__ import annotationsimport io+import jsonimport osfrom datetime import datetimefrom pathlib import Path@@ -266,6 +267,28 @@ def test_webui_session_list_recovers_colon_chat_id_from_transcript(assert row["preview"] == "scoped history"+def test_webui_session_list_normalizes_transcript_preview(tmp_path: Path) -> None:+ key = "websocket:long-preview"+ transcript = tmp_path / "webui" / f"{SessionManager.safe_key(key)}.jsonl"+ transcript.write_text(+ json.dumps(+ {+ "event": "user",+ "chat_id": "long-preview",+ "text": "first\n\n" + "word " * 100,+ }+ )+ + "\n",+ encoding="utf-8",+ )++ [row] = list_webui_sessions(SessionManager(tmp_path / "workspace"))++ assert row["preview"].startswith("first word")+ assert "\n" not in row["preview"]+ assert row["preview"].endswith("…")++def test_webui_session_list_tolerates_invalid_transcript_timestamp(tmp_path: Path,) -> None: