chore: remove unused dead code

This commit is contained in:
chengyongru
2026-07-07 15:41:27 +08:00
committed by Xubin Ren
parent 29e99d3742
commit 3f33ff3143
12 changed files with 7 additions and 154 deletions
-1
View File
@@ -311,7 +311,6 @@ class AgentLoop:
self._running = False
self._mcp_servers = mcp_servers or {}
self._mcp_stacks: dict[str, AsyncExitStack] = {}
self._mcp_connected = False
self._mcp_connecting = False
self._active_tasks: dict[str, list[asyncio.Task]] = {} # session_key -> tasks
self._background_tasks: list[asyncio.Task] = []
-11
View File
@@ -526,8 +526,6 @@ class MCPToolWrapper(_MCPWrapperBase):
f"(MCP tool returned malformed content: {type(exc).__name__})"
)
return "(MCP tool call failed)" # Unreachable, but satisfies type checkers
def _render_call_result(self, content: Any, arguments: Mapping[str, Any]) -> str:
"""Turn MCP content blocks into a tool result string.
@@ -679,8 +677,6 @@ class MCPResourceWrapper(_MCPWrapperBase):
parts.append(str(block))
return "\n".join(parts) or "(no output)"
return "(MCP resource read failed)" # Unreachable
class MCPPromptWrapper(_MCPWrapperBase):
"""Wraps an MCP prompt as a read-only nanobot Tool."""
@@ -815,8 +811,6 @@ class MCPPromptWrapper(_MCPWrapperBase):
parts.append(str(content))
return "\n".join(parts) or "(no output)"
return "(MCP prompt call failed)" # Unreachable
async def connect_mcp_servers(
mcp_servers: dict, registry: ToolRegistry
@@ -1140,17 +1134,14 @@ async def connect_missing_servers(state: Any, registry: ToolRegistry) -> None:
connected = await connect_mcp_servers(missing_servers, registry)
state._mcp_stacks.update(connected)
_attach_reconnect_handlers(state, registry, connected)
state._mcp_connected = bool(state._mcp_stacks)
if connected:
logger.info("MCP connected servers: {}", sorted(connected))
else:
logger.warning("No MCP servers connected successfully (will retry next message)")
except asyncio.CancelledError:
logger.warning("MCP connection cancelled (will retry next message)")
state._mcp_connected = bool(state._mcp_stacks)
except BaseException as e:
logger.warning("Failed to connect MCP servers (will retry next message): {}", e)
state._mcp_connected = bool(state._mcp_stacks)
finally:
state._mcp_connecting = False
@@ -1202,7 +1193,6 @@ async def reload_servers(state: Any, registry: ToolRegistry) -> dict[str, Any]:
state._mcp_stacks.update(connected)
_attach_reconnect_handlers(state, registry, connected)
state._mcp_connected = bool(state._mcp_stacks)
failed = sorted(set(to_connect) - set(connected))
unchanged = not removed and not added and not changed and not retry_missing
ok = not failed
@@ -1356,7 +1346,6 @@ async def _refresh_terminated_server(
connected = await connect_mcp_servers({server_name: cfg}, registry)
state._mcp_stacks.update(connected)
_attach_reconnect_handlers(state, registry, connected)
state._mcp_connected = bool(state._mcp_stacks)
if server_name not in connected:
logger.warning("MCP server '{}' reconnect failed after session termination", server_name)
return None
-19
View File
@@ -1395,25 +1395,6 @@ async def _openai_images_from_payload(
return images
def _codex_responses_images_from_payload(payload: dict[str, Any]) -> list[str]:
"""Extract images from Codex Responses API ``image_generation_call`` output."""
images: list[str] = []
for item in payload.get("output") or []:
if not isinstance(item, dict):
continue
if item.get("type") != "image_generation_call":
continue
result = item.get("result")
if isinstance(result, str):
images.append(result if result.startswith("data:image/") else _b64_image_data_url(result))
continue
if isinstance(result, dict):
image_url = result.get("image_url") or result.get("image") or ""
if isinstance(image_url, str):
images.append(image_url if image_url.startswith("data:image/") else _b64_image_data_url(image_url))
return images
async def _parse_codex_sse_images(
response: httpx.Response,
) -> tuple[list[str], str]:
-9
View File
@@ -2,7 +2,6 @@
from __future__ import annotations
from collections.abc import Callable
from dataclasses import dataclass
from nanobot.providers.base import LLMProvider
@@ -12,11 +11,3 @@ from nanobot.providers.base import LLMProvider
class LLMRuntime:
provider: LLMProvider
model: str
LLMRuntimeResolver = Callable[[], LLMRuntime]
def static_llm_runtime(provider: LLMProvider, model: str) -> LLMRuntimeResolver:
runtime = LLMRuntime(provider=provider, model=model)
return lambda: runtime
-4
View File
@@ -107,10 +107,6 @@ def parse_request_path(path_with_query: str) -> tuple[str, QueryParams]:
return path, parse_qs(parsed.query, keep_blank_values=True)
def normalize_http_path(path_with_query: str) -> str:
return parse_request_path(path_with_query)[0]
def parse_query(path_with_query: str) -> QueryParams:
return parse_request_path(path_with_query)[1]