feat(webui): show the actual fallback model (#5017)

This commit is contained in:
chengyongru authored and GitHub committed 2026-07-23 15:57:13 +08:00
1 parent 4188ffc88d
commit 96eb965aae
15 files changed
+352 -8

No files matched your search

+32 -1
View File
@@ -26,6 +26,7 @@ from nanobot.bus.outbound_events import (
RuntimeModelUpdatedEvent,
SessionUpdatedEvent,
TurnEndEvent,
TurnModelUpdatedEvent,
outbound_event_from_message,
outbound_message_for_event,
)
@@ -319,7 +320,7 @@ class WebSocketChannel(BaseChannel):
await self.send_goal_status(chat_id, "running", started_at=t0)
async def _hydrate_after_subscribe(self, chat_id: str) -> None:
"""Replay goal/run strip state after subscribe (same-process refresh)."""
"""Replay persisted or actively running per-chat state after subscribe."""
await self._maybe_push_active_goal_state(chat_id)
await self._maybe_push_turn_run_wall_clock(chat_id)
@@ -805,6 +806,13 @@ class WebSocketChannel(BaseChannel):
self.logger.debug("no active subscribers for chat_id={}", msg.chat_id)
else:
self.logger.warning("no active subscribers for chat_id={}", msg.chat_id)
if isinstance(event, TurnModelUpdatedEvent):
if conns:
await self.send_turn_model_updated(
msg.chat_id,
model_name=event.model,
)
return
if isinstance(event, GoalStateSyncEvent):
if conns:
await self.send_goal_state(msg.chat_id, event.goal_state or {"active": False})
@@ -1113,3 +1121,26 @@ class WebSocketChannel(BaseChannel):
raw = json.dumps(body, ensure_ascii=False)
for connection in conns:
await self._safe_send_to(connection, raw, label=" runtime_model_updated ")
async def send_turn_model_updated(
self,
chat_id: str,
*,
model_name: Any,
) -> None:
"""Notify one chat's subscribers which model is handling its current request."""
conns = list(self._subs.get(chat_id, ()))
if (
not conns
or not isinstance(model_name, str)
or not model_name.strip()
):
return
body: dict[str, Any] = {
"event": "turn_model_updated",
"chat_id": chat_id,
"model_name": model_name.strip(),
}
raw = json.dumps(body, ensure_ascii=False)
for connection in conns:
await self._safe_send_to(connection, raw, label=" turn_model_updated ")
@@ -20,6 +20,7 @@ from nanobot.bus.outbound_events import (
RuntimeModelUpdatedEvent,
SessionUpdatedEvent,
TurnEndEvent,
TurnModelUpdatedEvent,
)
from nanobot.bus.queue import MessageBus
from nanobot.channels.websocket.runtime import (
@@ -1061,6 +1062,33 @@ async def test_send_broadcasts_runtime_model_updates() -> None:
assert payload["model_preset"] == "fast"
@pytest.mark.asyncio
async def test_send_scopes_turn_model_updates_to_the_subscribed_chat() -> None:
bus = MessageBus()
channel = WebSocketChannel({"enabled": True, "allowFrom": ["*"]}, bus, gateway=_basic_handler(bus))
chat_one = AsyncMock()
chat_two = AsyncMock()
channel._attach(chat_one, "chat-1")
channel._attach(chat_two, "chat-2")
await channel.send(
OutboundMessage(
channel="websocket",
chat_id="chat-1",
content="",
event=TurnModelUpdatedEvent(model="deepseek/deepseek-chat"),
)
)
payload = json.loads(chat_one.send.call_args.args[0])
assert payload == {
"event": "turn_model_updated",
"chat_id": "chat-1",
"model_name": "deepseek/deepseek-chat",
}
chat_two.send.assert_not_awaited()
@pytest.mark.asyncio
async def test_runtime_model_update_publisher_uses_websocket_outbound_event() -> None:
bus = MessageBus()
@@ -14,6 +14,7 @@ async def test_hydrate_after_subscribe_is_quiet_when_no_turn_active():
channel.gateway = MagicMock()
channel.gateway.session_manager = MagicMock()
channel.gateway.session_manager.read_session_file = MagicMock(return_value={})
channel._turn_models = {}
sent_events = []
@@ -39,6 +40,7 @@ async def test_hydrate_after_subscribe_pushes_running_when_turn_active():
channel.gateway = MagicMock()
channel.gateway.session_manager = MagicMock()
channel.gateway.session_manager.read_session_file = MagicMock(return_value={})
channel._turn_models = {}
sent_events = []