mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-08-14 16:19:17 +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")
|
text = record.get("text")
|
||||||
if not isinstance(text, str) or not text.strip():
|
if not isinstance(text, str) or not text.strip():
|
||||||
return "", ""
|
return "", ""
|
||||||
|
preview = _message_preview_text({"content": text})
|
||||||
|
if not preview:
|
||||||
|
return "", ""
|
||||||
event = record.get("event")
|
event = record.get("event")
|
||||||
if event == "user" or record.get("role") == "user":
|
if event == "user" or record.get("role") == "user":
|
||||||
return text, ""
|
return preview, ""
|
||||||
if (
|
if (
|
||||||
event == "message"
|
event == "message"
|
||||||
and record.get("kind") not in _TRANSCRIPT_NON_ANSWER_KINDS
|
and record.get("kind") not in _TRANSCRIPT_NON_ANSWER_KINDS
|
||||||
) or record.get("role") == "assistant":
|
) or record.get("role") == "assistant":
|
||||||
return "", text
|
return "", preview
|
||||||
return "", ""
|
return "", ""
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import io
|
import io
|
||||||
|
import json
|
||||||
import os
|
import os
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -266,6 +267,28 @@ def test_webui_session_list_recovers_colon_chat_id_from_transcript(
|
|||||||
assert row["preview"] == "scoped history"
|
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(
|
def test_webui_session_list_tolerates_invalid_transcript_timestamp(
|
||||||
tmp_path: Path,
|
tmp_path: Path,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user