Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions contributors/emails/akitani@akitaninoMac-mini.local
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2001Y
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gonzalofrancoceballos
2 changes: 2 additions & 0 deletions contributors/emails/mehrzad.karami@gmail.com
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mzkarami
# PR #66204 contributor identity
1 change: 1 addition & 0 deletions contributors/emails/skywind5487@gmail.com
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Skywind5487
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
z23
1 change: 1 addition & 0 deletions contributors/emails/zhangk1985@gmail.com
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kylezh
21 changes: 20 additions & 1 deletion gateway/platforms/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5895,7 +5895,26 @@ def truncate_message(

# Everything remaining fits in one final chunk
if _len(prefix) + _len(remaining) <= max_length - INDICATOR_RESERVE:
chunks.append(prefix + remaining)
final_chunk = prefix + remaining
# Check fence balance: if carry_lang was set, the chunk
# starts with an opening fence. Walk the remaining text
# to see if the code block was closed; if not, close it.
_final_in_code = carry_lang is not None
_final_lang = carry_lang or ""
if _final_in_code:
for _line in remaining.split("\n"):
_stripped = _line.strip()
if _stripped.startswith("```"):
if _final_in_code:
_final_in_code = False
_final_lang = ""
else:
_final_in_code = True
_tag = _stripped[3:].strip()
_final_lang = _tag.split()[0] if _tag else ""
if _final_in_code:
final_chunk += FENCE_CLOSE
chunks.append(final_chunk)
break

# Find a natural split point (prefer newlines, then spaces).
Expand Down
4 changes: 4 additions & 0 deletions gateway/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -13634,6 +13634,7 @@ async def _handle_message_with_agent(self, event, source, _quick_key: str, run_g
if _show_reasoning_effective and response and not _intentional_silence:
last_reasoning = agent_result.get("last_reasoning")
if last_reasoning:
from gateway.stream_consumer import escape_code_fences_for_display
# Collapse long reasoning to keep messages readable
lines = last_reasoning.strip().splitlines()
if len(lines) > 15:
Expand Down Expand Up @@ -13665,6 +13666,9 @@ async def _handle_message_with_agent(self, event, source, _quick_key: str, run_g
)
response = f"> 💭 **Reasoning:**\n{_quoted}\n\n{response}"
else:
# Escape ``` inside reasoning so inner fences don't
# break the outer code block used to render it.
display_reasoning = escape_code_fences_for_display(display_reasoning)
response = f"💭 **Reasoning:**\n```\n{display_reasoning}\n```\n\n{response}"

# Runtime-metadata footer — only on the FINAL message of the turn.
Expand Down
254 changes: 221 additions & 33 deletions gateway/stream_consumer.py

Large diffs are not rendered by default.

Loading
Loading