feat(webui): segment transcript storage

This commit is contained in:
Xubin Ren
2026-06-10 18:28:55 +08:00
parent 7186039be1
commit e168bb2754
15 changed files with 1029 additions and 94 deletions
+39
View File
@@ -2718,6 +2718,45 @@ def test_handle_webui_thread_get_returns_json(tmp_path, monkeypatch) -> None:
assert body["messages"][0]["content"] == "hi"
def test_handle_webui_thread_get_accepts_pagination_query(tmp_path, monkeypatch) -> None:
from urllib.parse import quote
from websockets.datastructures import Headers
from websockets.http11 import Request
from nanobot.webui.transcript import append_transcript_object
monkeypatch.setattr("nanobot.config.paths.get_data_dir", lambda: tmp_path)
key = "websocket:paged-route"
for idx in range(1, 4):
append_transcript_object(
key,
{"event": "user", "chat_id": "paged-route", "text": f"q{idx}"},
)
append_transcript_object(
key,
{"event": "message", "chat_id": "paged-route", "text": f"a{idx}"},
)
append_transcript_object(key, {"event": "turn_end", "chat_id": "paged-route"})
bus = MagicMock()
channel = _ch(bus)
channel.gateway.tokens.api_tokens["tok"] = time.monotonic() + 300.0
enc = quote(key, safe="")
req = Request(
f"/api/sessions/{enc}/webui-thread?limit=2&direction=latest",
Headers([("Authorization", "Bearer tok")]),
)
resp = channel.gateway.http._handle_webui_thread_get(req, enc)
assert resp.status_code == 200
body = json.loads(resp.body.decode())
assert [message["content"] for message in body["messages"]] == ["q3", "a3"]
assert body["page"]["has_more_before"] is True
assert body["page"]["before_cursor"]
def test_handle_file_preview_returns_workspace_file(tmp_path) -> None:
from urllib.parse import quote