The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor: sms AIOHTTP_AVAILABLE flag; ElicitationHandler call_context defaults to a no-op thunk; drop stale TYPE_CHECKING/type-ignore in two tests
kshitijk4poor2f1609a86c52
diff --git a/gateway/platforms/helpers.py b/gateway/platforms/helpers.pyindex db2e4694c97..15d8b2fe116 100644--- a/gateway/platforms/helpers.py+++ b/gateway/platforms/helpers.py@@ -2,8 +2,6 @@stripping, thread participation tracking, GFM table → bullets, mention-patterncompilation, and fence-aware markdown chunking."""-from __future__ import annotations-import jsonimport loggingimport rediff --git a/plugins/platforms/sms/adapter.py b/plugins/platforms/sms/adapter.pyindex c4ef7800848..d17d4e11915 100644--- a/plugins/platforms/sms/adapter.py+++ b/plugins/platforms/sms/adapter.py@@ -30,7 +30,9 @@ from gateway.platforms._shared import get_scoped_secret as _get_scoped_secrettry:import aiohttpfrom aiohttp import web+ AIOHTTP_AVAILABLE = Trueexcept ImportError: # optional ([messaging] extra)+ AIOHTTP_AVAILABLE = Falseaiohttp = None # type: ignore[assignment]web = None # type: ignore[assignment]@@ -75,7 +77,7 @@ def _new_session(**kwargs):def check_sms_requirements() -> bool:"""Check if SMS adapter dependencies are available."""- return aiohttp is not None and bool(+ return AIOHTTP_AVAILABLE and bool(_get_scoped_secret("TWILIO_ACCOUNT_SID") and _get_scoped_secret("TWILIO_AUTH_TOKEN"))@@ -292,7 +294,7 @@ def _strip_markdown_for_sms(message: str) -> str:async def _standalone_send(pconfig, chat_id, message, *, thread_id=None, media_files=None, force_document=False):"""Out-of-process SMS delivery via the Twilio REST API (standalone_sender_fn contract)."""auth_token = getattr(pconfig, "api_key", None) or _get_scoped_secret("TWILIO_AUTH_TOKEN", "")- if not aiohttp is not None:+ if not AIOHTTP_AVAILABLE:return {"error": "aiohttp not installed. Run: pip install aiohttp"}account_sid = _get_scoped_secret("TWILIO_ACCOUNT_SID", "")from_number = os.getenv("TWILIO_PHONE_NUMBER", "")diff --git a/tests/gateway/test_telegram_audio_vs_voice.py b/tests/gateway/test_telegram_audio_vs_voice.pyindex 7b351a1e4dd..7031b8a68dd 100644--- a/tests/gateway/test_telegram_audio_vs_voice.py+++ b/tests/gateway/test_telegram_audio_vs_voice.py@@ -18,17 +18,11 @@ import pytestfrom gateway.config import GatewayConfig, Platformfrom gateway.platforms.event import MessageEvent, MessageType+from gateway.run import GatewayRunnerfrom gateway.session import SessionSource-from typing import TYPE_CHECKING--if TYPE_CHECKING:- from gateway.run import GatewayRunner---def _make_runner(stt_enabled: bool = True) -> "GatewayRunner": # type: ignore[name-defined]- from gateway.run import GatewayRunner+def _make_runner(stt_enabled: bool = True) -> GatewayRunner:runner = GatewayRunner.__new__(GatewayRunner)runner.config = GatewayConfig(stt_enabled=stt_enabled)runner.adapters = {}diff --git a/tests/gateway/test_video_context_note.py b/tests/gateway/test_video_context_note.pyindex 69dc17d7a98..8319acc00b0 100644--- a/tests/gateway/test_video_context_note.py+++ b/tests/gateway/test_video_context_note.py@@ -6,17 +6,11 @@ import pytestfrom gateway.config import GatewayConfig, Platformfrom gateway.platforms.event import MessageEvent, MessageType+from gateway.run import GatewayRunnerfrom gateway.session import SessionSource-from typing import TYPE_CHECKING--if TYPE_CHECKING:- from gateway.run import GatewayRunner---def _make_runner() -> "GatewayRunner": # type: ignore[name-defined]- from gateway.run import GatewayRunner+def _make_runner() -> GatewayRunner:runner = GatewayRunner.__new__(GatewayRunner)runner.config = GatewayConfig()runner.adapters = {}diff --git a/tests/tools/test_mcp_elicitation.py b/tests/tools/test_mcp_elicitation.pyindex d9dddb53133..edc05bb4daf 100644--- a/tests/tools/test_mcp_elicitation.py+++ b/tests/tools/test_mcp_elicitation.py@@ -254,7 +254,7 @@ class TestElicitationHandlerContextBridge:call) the handler must still invoke the consent router -- justwithout the contextvar replay. Otherwise CLI/TUI sessions, whichdon't set HERMES_SESSION_PLATFORM, would break."""- handler = ElicitationHandler("pay", {"timeout": 5}, call_context=None)+ handler = ElicitationHandler("pay", {"timeout": 5})params = _form_params()with patch("tools.approval_prompt.request_elicitation_consent", return_value="accept") as m:diff --git a/tools/mcp_tool_sampling.py b/tools/mcp_tool_sampling.pyindex 4ce8c966298..89a5276d411 100644--- a/tools/mcp_tool_sampling.py+++ b/tools/mcp_tool_sampling.py@@ -1,8 +1,6 @@"""MCP client-side handlers for server-initiated requests: sampling(sampling/createMessage, text and tool-use results) and elicitation."""-from __future__ import annotations-import asyncioimport functoolsimport json@@ -255,12 +253,13 @@ class ElicitationHandler:_ANSWER_RESULTS = {"accept": ("accept", "accepted"), "cancel": ("cancel", "errors")}def __init__(self, server_name: str, config: dict,- call_context: Optional[Callable[[], Optional[Context]]] = None):+ call_context: Callable[[], Optional[Context]] = lambda: None):self.server_name = server_name# 5 min mirrors the gateway approval default so async surfaces (Telegram, Slack) can respond.self.timeout = _safe_numeric(config.get("timeout", 300), 300, float)# Returns the owning MCPServerTask's contextvars snapshot for the in-flight tool call (None- # between calls). A thunk, not the task: the task module imports this one.+ # between calls). A thunk, not the task: mcp_tool_server_run imports this module, so+ # MCPServerTask cannot be named here.self._call_context = call_contextself.metrics = {"requests": 0, "accepted": 0, "declined": 0, "errors": 0}@@ -281,7 +280,7 @@ class ElicitationHandler:consent = functools.partial(request_elicitation_consent, message, description,timeout_seconds=int(self.timeout), surface=f"mcp-elicitation/{self.server_name}")- captured = self._call_context() if self._call_context else None+ captured = self._call_context()return consent if captured is None else (lambda: captured.copy().run(consent))async def __call__(self, context, params):