mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-08-14 08:09:16 +03:00
fix(webui): bound restored session previews
This commit is contained in:
@@ -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 "", preview
|
||||
return "", ""
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
from datetime import datetime
|
||||
from 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:
|
||||
|
||||
Reference in New Issue
Block a user