mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-09-05 10:41:58 +03:00
fix(webui): preserve causal message order (NAN-29) (#5503)
This commit is contained in:
@@ -1813,11 +1813,16 @@ def replay_transcript_to_ui_messages(
|
||||
break
|
||||
content = str(candidate.get("content") or "")
|
||||
has_answer = len(content) > 0
|
||||
if has_answer:
|
||||
break
|
||||
# A completed reasoning field is closed even while its assistant
|
||||
# placeholder remains streaming for the rest of the turn.
|
||||
if (
|
||||
candidate.get("reasoningStreaming")
|
||||
or candidate.get("reasoning") is not None
|
||||
or has_answer
|
||||
or candidate.get("isStreaming")
|
||||
or (
|
||||
candidate.get("isStreaming")
|
||||
and candidate.get("reasoning") is None
|
||||
)
|
||||
):
|
||||
prev[i] = {
|
||||
**candidate,
|
||||
@@ -1827,15 +1832,6 @@ def replay_transcript_to_ui_messages(
|
||||
**turn_fields,
|
||||
}
|
||||
return
|
||||
if not has_answer and candidate.get("isStreaming"):
|
||||
prev[i] = {
|
||||
**candidate,
|
||||
"reasoning": chunk,
|
||||
"reasoningStreaming": True,
|
||||
"activitySegmentId": candidate.get("activitySegmentId") or _ensure_activity_segment(),
|
||||
**turn_fields,
|
||||
}
|
||||
return
|
||||
break
|
||||
segment = _ensure_activity_segment()
|
||||
prev.append(
|
||||
@@ -1915,19 +1911,6 @@ def replay_transcript_to_ui_messages(
|
||||
and not m.get("media")
|
||||
)
|
||||
|
||||
def is_tool_trace_at(index: int) -> bool:
|
||||
m = messages[index] if 0 <= index < len(messages) else None
|
||||
return bool(m and m.get("kind") == "trace")
|
||||
|
||||
def prune_reasoning_only() -> None:
|
||||
nonlocal messages
|
||||
kept: list[dict[str, Any]] = []
|
||||
for i, m in enumerate(messages):
|
||||
if is_reasoning_only_placeholder(m) and not is_tool_trace_at(i + 1):
|
||||
continue
|
||||
kept.append(m)
|
||||
messages = kept
|
||||
|
||||
def stamp_completion(
|
||||
*,
|
||||
latency_ms: int | None = None,
|
||||
@@ -2442,7 +2425,6 @@ def replay_transcript_to_ui_messages(
|
||||
for i, m in enumerate(messages):
|
||||
if m.get("isStreaming"):
|
||||
messages[i] = {**m, "isStreaming": False}
|
||||
prune_reasoning_only()
|
||||
lat = rec.get("latency_ms")
|
||||
usage = rec.get("usage")
|
||||
sanitized_usage = (
|
||||
|
||||
Reference in New Issue
Block a user