refactor: use thin upstream transport adapter

This commit is contained in:
Mikhail Putilovskij 2026-04-22 01:25:11 +03:00
parent 569824ead1
commit 0c2884c2b1
8 changed files with 420 additions and 255 deletions

View file

@ -1,6 +1,5 @@
from __future__ import annotations
import inspect
import re
import sys
from pathlib import Path
@ -27,11 +26,6 @@ class AgentApiWrapper(AgentApi):
self._base_url = self._normalize_base_url(base_url)
self._init_kwargs = dict(kwargs)
self.chat_id = chat_id
if not self._supports_modern_constructor():
raise RuntimeError(
"Pinned platform-agent_api is expected to support base_url + chat_id"
)
super().__init__(
agent_id=agent_id,
base_url=self._base_url,
@ -39,21 +33,13 @@ class AgentApiWrapper(AgentApi):
**kwargs,
)
@staticmethod
def _supports_modern_constructor() -> bool:
try:
parameters = inspect.signature(AgentApi.__init__).parameters
except (TypeError, ValueError):
return False
return "base_url" in parameters and "chat_id" in parameters
@staticmethod
def _normalize_base_url(base_url: str) -> str:
parsed = urlsplit(base_url)
path = re.sub(r"(?:/v1)?/agent_ws(?:/[^/]+)?/?$", "", parsed.path.rstrip("/"))
return urlunsplit((parsed.scheme, parsed.netloc, path, "", ""))
def for_chat(self, chat_id: int | str) -> "AgentApiWrapper":
def for_chat(self, chat_id: int | str) -> AgentApiWrapper:
return type(self)(
agent_id=self.id,
base_url=self._base_url,