refactor: ChannelManager creates and injects GatewayHTTPHandler

This commit is contained in:
chengyongru 2026-05-31 19:09:54 +08:00 committed by Xubin Ren
parent e5eb08e3e5
commit 1252550649

View File

@ -16,6 +16,7 @@ from nanobot.bus.queue import MessageBus
from nanobot.channels.base import BaseChannel
from nanobot.config.schema import Config
from nanobot.utils.restart import consume_restart_notice_from_env, format_restart_completed_message
from nanobot.webui.ws_http import GatewayHTTPHandler
if TYPE_CHECKING:
from nanobot.session.manager import SessionManager
@ -111,17 +112,22 @@ class ChannelManager:
try:
kwargs: dict[str, Any] = {}
if cls.name == "websocket":
if self._session_manager is not None:
kwargs["session_manager"] = self._session_manager
static_path = _default_webui_dist() if self._webui_static_dist else None
if static_path is not None:
kwargs["static_dist_path"] = static_path
kwargs["workspace_path"] = self.config.workspace_path
kwargs["restrict_to_workspace"] = self.config.tools.restrict_to_workspace
if self._webui_runtime_model_name is not None:
kwargs["runtime_model_name"] = self._webui_runtime_model_name
kwargs["runtime_surface"] = self._webui_runtime_surface
kwargs["runtime_capabilities_overrides"] = self._webui_runtime_capabilities
from nanobot.channels.websocket import WebSocketConfig
parsed = WebSocketConfig.model_validate(section)
static_path = _default_webui_dist() if self._webui_static_dist else None
workspace = Path(self.config.workspace_path)
http_handler = GatewayHTTPHandler(
config=parsed,
session_manager=self._session_manager,
static_dist_path=static_path,
workspace_path=workspace,
runtime_model_name=self._webui_runtime_model_name,
runtime_surface=self._webui_runtime_surface,
runtime_capabilities_overrides=self._webui_runtime_capabilities,
bus=self.bus,
)
kwargs["http_handler"] = http_handler
channel = cls(section, self.bus, **kwargs)
channel.transcription_provider = transcription_provider
channel.transcription_api_key = transcription_key