Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
refactor: update import paths after ws_http move to webui/
chengyongru22673c2a27a7
diff --git a/nanobot/channels/websocket.py b/nanobot/channels/websocket.pyindex 2316d0613..7ba9162bb 100644--- a/nanobot/channels/websocket.py+++ b/nanobot/channels/websocket.py@@ -28,7 +28,7 @@ from websockets.http11 import Responsefrom nanobot.bus.events import OUTBOUND_META_AGENT_UI, OutboundMessagefrom nanobot.bus.queue import MessageBusfrom nanobot.channels.base import BaseChannel-from nanobot.channels.ws_http import GatewayHTTPHandler+from nanobot.webui.ws_http import GatewayHTTPHandlerfrom nanobot.config.paths import get_media_dir, get_workspace_pathfrom nanobot.config.schema import Basefrom nanobot.security.workspace_access import (diff --git a/tests/channels/test_websocket_channel.py b/tests/channels/test_websocket_channel.pyindex a39658e37..e0743a8d1 100644--- a/tests/channels/test_websocket_channel.py+++ b/tests/channels/test_websocket_channel.py@@ -626,7 +626,7 @@ async def test_send_stages_external_media_as_signed_url(monkeypatch, tmp_path) -return ws_media if channel == "websocket" else media_rootmonkeypatch.setattr("nanobot.channels.websocket.get_media_dir", fake_media_dir)- monkeypatch.setattr("nanobot.channels.ws_http.get_media_dir", fake_media_dir)+ monkeypatch.setattr("nanobot.webui.ws_http.get_media_dir", fake_media_dir)channel = WebSocketChannel({"enabled": True, "allowFrom": ["*"]}, bus)mock_ws = AsyncMock()channel._attach(mock_ws, "chat-1")@@ -841,7 +841,7 @@ async def test_send_delta_stream_end_rewrites_local_markdown_image(monkeypatch,return pathmonkeypatch.setattr("nanobot.channels.websocket.get_media_dir", fake_media_dir)- monkeypatch.setattr("nanobot.channels.ws_http.get_media_dir", fake_media_dir)+ monkeypatch.setattr("nanobot.webui.ws_http.get_media_dir", fake_media_dir)channel = WebSocketChannel({"enabled": True, "allowFrom": ["*"], "streaming": True},bus,@@ -874,7 +874,7 @@ async def test_send_delta_stream_end_rewrites_inline_final_text(monkeypatch, tmpreturn pathmonkeypatch.setattr("nanobot.channels.websocket.get_media_dir", fake_media_dir)- monkeypatch.setattr("nanobot.channels.ws_http.get_media_dir", fake_media_dir)+ monkeypatch.setattr("nanobot.webui.ws_http.get_media_dir", fake_media_dir)channel = WebSocketChannel({"enabled": True, "allowFrom": ["*"], "streaming": True},bus,diff --git a/tests/channels/test_websocket_http_routes.py b/tests/channels/test_websocket_http_routes.pyindex 6bbff4495..fb529599f 100644--- a/tests/channels/test_websocket_http_routes.py+++ b/tests/channels/test_websocket_http_routes.py@@ -814,7 +814,7 @@ def test_localhost_without_auth_is_valid(bus: MagicMock) -> None:def test_bootstrap_prefers_runtime_model_name(bus: MagicMock, monkeypatch: pytest.MonkeyPatch) -> None:monkeypatch.setattr(- "nanobot.channels.ws_http._default_model_name_from_config",+ "nanobot.webui.ws_http._default_model_name_from_config",lambda: "from-disk",)channel = _ch(bus, host="127.0.0.1", runtime_model_name=lambda: " live/model ")@@ -826,7 +826,7 @@ def test_bootstrap_prefers_runtime_model_name(bus: MagicMock, monkeypatch: pytesdef test_bootstrap_falls_back_when_runtime_returns_empty(bus: MagicMock, monkeypatch: pytest.MonkeyPatch) -> None:monkeypatch.setattr(- "nanobot.channels.ws_http._default_model_name_from_config",+ "nanobot.webui.ws_http._default_model_name_from_config",lambda: "from-disk",)channel = _ch(bus, host="127.0.0.1", runtime_model_name=lambda: " ")@@ -838,7 +838,7 @@ def test_bootstrap_falls_back_when_runtime_returns_empty(bus: MagicMock, monkeypdef test_bootstrap_falls_back_when_runtime_raises(bus: MagicMock, monkeypatch: pytest.MonkeyPatch) -> None:monkeypatch.setattr(- "nanobot.channels.ws_http._default_model_name_from_config",+ "nanobot.webui.ws_http._default_model_name_from_config",lambda: "from-disk",)diff --git a/tests/channels/test_websocket_media_route.py b/tests/channels/test_websocket_media_route.pyindex 2b6737aa0..b8926e273 100644--- a/tests/channels/test_websocket_media_route.py+++ b/tests/channels/test_websocket_media_route.py@@ -106,7 +106,7 @@ def test_sign_media_path_rejects_paths_outside_media_root(media = tmp_path / "media"media.mkdir()channel = _ch(bus, port=0)- with patch("nanobot.channels.ws_http.get_media_dir", return_value=media):+ with patch("nanobot.webui.ws_http.get_media_dir", return_value=media):assert channel._sign_media_path(outside) is None# Traversal via the media root is also rejected — the resolve() step# normalises ``..`` out before the relative_to check.@@ -121,7 +121,7 @@ def test_sign_media_path_round_trips_via_hmac(media.mkdir()(media / "a.png").write_bytes(_PNG_BYTES)channel = _ch(bus, port=0)- with patch("nanobot.channels.ws_http.get_media_dir", return_value=media):+ with patch("nanobot.webui.ws_http.get_media_dir", return_value=media):url = channel._sign_media_path(media / "a.png")assert url is not Noneassert url.startswith("/api/media/")@@ -144,7 +144,7 @@ def test_local_markdown_image_is_staged_and_rewritten(media = tmp_path / "media"channel = _ch(bus, workspace_path=workspace, port=0)- with patch("nanobot.channels.ws_http.get_media_dir", side_effect=_fake_media_dir(media)):+ with patch("nanobot.webui.ws_http.get_media_dir", side_effect=_fake_media_dir(media)):rewritten = channel._rewrite_local_markdown_images("The result:\n")@@ -166,7 +166,7 @@ def test_local_markdown_video_is_staged_and_rewritten(media = tmp_path / "media"channel = _ch(bus, workspace_path=workspace, port=0)- with patch("nanobot.channels.ws_http.get_media_dir", side_effect=_fake_media_dir(media)):+ with patch("nanobot.webui.ws_http.get_media_dir", side_effect=_fake_media_dir(media)):rewritten = channel._rewrite_local_markdown_images("The result:\n")@@ -189,7 +189,7 @@ def test_local_markdown_image_rejects_workspace_escape(channel = _ch(bus, workspace_path=workspace, port=0)text = ""- with patch("nanobot.channels.ws_http.get_media_dir", side_effect=_fake_media_dir(media)):+ with patch("nanobot.webui.ws_http.get_media_dir", side_effect=_fake_media_dir(media)):assert channel._rewrite_local_markdown_images(text) == textassert not (media / "websocket").exists()@@ -211,7 +211,7 @@ async def test_media_route_serves_signed_file(target.write_bytes(_PNG_BYTES)channel = _ch(bus, port=29920)- with patch("nanobot.channels.ws_http.get_media_dir", return_value=media):+ with patch("nanobot.webui.ws_http.get_media_dir", return_value=media):url_path = channel._sign_media_path(target)assert url_path is not Noneserver_task = asyncio.create_task(channel.start())@@ -244,7 +244,7 @@ async def test_media_route_serves_video_byte_ranges(target.write_bytes(b"0123456789")channel = _ch(bus, port=29927)- with patch("nanobot.channels.ws_http.get_media_dir", return_value=media):+ with patch("nanobot.webui.ws_http.get_media_dir", return_value=media):url_path = channel._sign_media_path(target)assert url_path is not Noneserver_task = asyncio.create_task(channel.start())@@ -276,7 +276,7 @@ async def test_media_route_serves_suffix_video_byte_ranges(target.write_bytes(b"0123456789")channel = _ch(bus, port=29928)- with patch("nanobot.channels.ws_http.get_media_dir", return_value=media):+ with patch("nanobot.webui.ws_http.get_media_dir", return_value=media):url_path = channel._sign_media_path(target)assert url_path is not Noneserver_task = asyncio.create_task(channel.start())@@ -305,7 +305,7 @@ async def test_media_route_rejects_unsatisfiable_byte_range(target.write_bytes(b"0123456789")channel = _ch(bus, port=29929)- with patch("nanobot.channels.ws_http.get_media_dir", return_value=media):+ with patch("nanobot.webui.ws_http.get_media_dir", return_value=media):url_path = channel._sign_media_path(target)assert url_path is not Noneserver_task = asyncio.create_task(channel.start())@@ -338,7 +338,7 @@ async def test_media_route_rejects_bad_signature((media / "f.png").write_bytes(_PNG_BYTES)channel = _ch(bus, port=29921)- with patch("nanobot.channels.ws_http.get_media_dir", return_value=media):+ with patch("nanobot.webui.ws_http.get_media_dir", return_value=media):good = channel._sign_media_path(media / "f.png")assert good is not None_, payload = good[len("/api/media/"):].split("/", 1)@@ -381,7 +381,7 @@ async def test_media_route_rejects_path_traversal_payload().digest()[:16]url = f"/api/media/{b64url_encode(mac)}/{payload}"- with patch("nanobot.channels.ws_http.get_media_dir", return_value=media):+ with patch("nanobot.webui.ws_http.get_media_dir", return_value=media):server_task = asyncio.create_task(channel.start())await asyncio.sleep(0.3)try:@@ -405,7 +405,7 @@ async def test_media_route_404s_missing_file(target.write_bytes(_PNG_BYTES)channel = _ch(bus, port=29923)- with patch("nanobot.channels.ws_http.get_media_dir", return_value=media):+ with patch("nanobot.webui.ws_http.get_media_dir", return_value=media):url_path = channel._sign_media_path(target)assert url_path is not Nonetarget.unlink() # the file vanishes between signing and fetching@@ -433,7 +433,7 @@ async def test_media_route_degrades_non_image_to_octet_stream((media / "scary.html").write_bytes(b"<script>alert(1)</script>")channel = _ch(bus, port=29924)- with patch("nanobot.channels.ws_http.get_media_dir", return_value=media):+ with patch("nanobot.webui.ws_http.get_media_dir", return_value=media):payload = b64url_encode(b"scary.html")mac = hmac.new(channel._media_secret, payload.encode("ascii"), hashlib.sha256@@ -464,7 +464,7 @@ async def test_media_route_serves_svg_with_strict_csp(target.write_text("<svg xmlns='http://www.w3.org/2000/svg'><script>alert(1)</script></svg>")channel = _ch(bus, port=29928)- with patch("nanobot.channels.ws_http.get_media_dir", return_value=media):+ with patch("nanobot.webui.ws_http.get_media_dir", return_value=media):url_path = channel._sign_media_path(target)assert url_path is not Noneserver_task = asyncio.create_task(channel.start())@@ -505,7 +505,7 @@ async def test_session_messages_exposes_signed_media_urls(sm.save(sess)channel = _ch(bus, session_manager=sm, port=29925)- with patch("nanobot.channels.ws_http.get_media_dir", return_value=media):+ with patch("nanobot.webui.ws_http.get_media_dir", return_value=media):server_task = asyncio.create_task(channel.start())await asyncio.sleep(0.3)try:@@ -550,7 +550,7 @@ async def test_session_messages_skips_vanished_media(sm.save(sess)channel = _ch(bus, session_manager=sm, port=29926)- with patch("nanobot.channels.ws_http.get_media_dir", return_value=media):+ with patch("nanobot.webui.ws_http.get_media_dir", return_value=media):server_task = asyncio.create_task(channel.start())await asyncio.sleep(0.3)try: