fix(webui): omit binary data from tool progress
This commit is contained in:
1 parent
11a03595f4
commit
c3fb819203
3 files changed
+100
-3
No files matched your search
@@ -49,7 +49,11 @@ from nanobot.webui.metadata import (
|
||||
WEBUI_TURN_METADATA_KEY,
|
||||
)
|
||||
from nanobot.webui.outbound_projection import WebUIOutboundProjector
|
||||
from nanobot.webui.outbound_wire import WebUIWirePayload, WebUIWirePersistence
|
||||
from nanobot.webui.outbound_wire import (
|
||||
WebUIWirePayload,
|
||||
WebUIWirePersistence,
|
||||
project_tool_events,
|
||||
)
|
||||
from nanobot.webui.session_identity import is_valid_webui_chat_id
|
||||
from nanobot.webui.transcript import WEBUI_TRANSCRIPT_INCOMPLETE_KEY
|
||||
from nanobot.webui.websocket_logging import websockets_server_logger
|
||||
@@ -1197,7 +1201,7 @@ class WebSocketChannel(BaseChannel):
|
||||
if isinstance(lat, (int, float)):
|
||||
payload["latency_ms"] = int(lat)
|
||||
if progress_event and progress_event.tool_events:
|
||||
payload["tool_events"] = progress_event.tool_events
|
||||
payload["tool_events"] = project_tool_events(progress_event.tool_events)
|
||||
agent_ui = msg.metadata.get(OUTBOUND_META_AGENT_UI)
|
||||
if agent_ui is not None:
|
||||
payload["agent_ui"] = agent_ui
|
||||
|
||||
@@ -2315,6 +2315,56 @@ async def test_send_progress_includes_structured_tool_events() -> None:
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_progress_omits_binary_tool_results_from_wire_and_transcript() -> None:
|
||||
bus = MagicMock()
|
||||
channel = WebSocketChannel({"enabled": True, "allowFrom": ["*"]}, bus, gateway=_basic_handler(bus))
|
||||
mock_ws = AsyncMock()
|
||||
channel._attach(mock_ws, "chat-binary-tool-result")
|
||||
data_url = f"data:image/png;base64,{'A' * (2 * 1024 * 1024)}"
|
||||
tool_events = [
|
||||
{
|
||||
"version": 1,
|
||||
"phase": "end",
|
||||
"call_id": "call-image",
|
||||
"name": "read_file",
|
||||
"arguments": {"path": "/media/screenshot.png"},
|
||||
"result": [
|
||||
{
|
||||
"type": "image_url",
|
||||
"image_url": {"url": data_url},
|
||||
"_meta": {"path": "/media/screenshot.png"},
|
||||
},
|
||||
{"type": "text", "text": "(Image file: /media/screenshot.png)"},
|
||||
],
|
||||
"error": None,
|
||||
"files": [],
|
||||
"embeds": [],
|
||||
}
|
||||
]
|
||||
|
||||
await channel.send(OutboundMessage(
|
||||
channel="websocket",
|
||||
chat_id="chat-binary-tool-result",
|
||||
content="read_file completed",
|
||||
event=ProgressEvent(content="read_file completed", tool_events=tool_events),
|
||||
))
|
||||
|
||||
payload = json.loads(mock_ws.send.await_args.args[0])
|
||||
[wire_event] = payload["tool_events"]
|
||||
assert wire_event["result"][0]["image_url"]["url"] == (
|
||||
"[binary content omitted from WebUI]"
|
||||
)
|
||||
assert len(mock_ws.send.await_args.args[0].encode("utf-8")) < 4096
|
||||
|
||||
[persisted] = read_transcript_lines("websocket:chat-binary-tool-result")
|
||||
assert persisted["tool_events"] == payload["tool_events"]
|
||||
assert data_url not in json.dumps(persisted)
|
||||
|
||||
# WebUI projection must not alter the result that the runner sends back to the model.
|
||||
assert tool_events[0]["result"][0]["image_url"]["url"] == data_url
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_file_edit_progress_uses_file_edit_event() -> None:
|
||||
bus = MagicMock()
|
||||
|
||||
Reference in new issue
Block a user