From bd2923ffcac7b1e684b007c047b191274b2e2940 Mon Sep 17 00:00:00 2001 From: MrKan Date: Mon, 20 Apr 2026 13:20:36 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D0=B5=20attachments=20=D0=B2?= =?UTF-8?q?=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D0=B8=20MsgUserMessage=20?= =?UTF-8?q?=D0=B8=20=D1=81=D0=BE=D0=BE=D1=82=D0=B2=D0=B5=D1=82=D1=81=D1=82?= =?UTF-8?q?=D0=B2=D1=83=D1=8E=D1=89=D0=B8=D0=B5=20=D0=BF=D0=B0=D1=80=D0=B0?= =?UTF-8?q?=D0=BC=D0=B5=D1=82=D1=80=D1=8B=20=D0=B2=20send=5Fmessage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lambda_agent_api/agent_api.py | 16 +++++++++++++--- lambda_agent_api/client.py | 6 ++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lambda_agent_api/agent_api.py b/lambda_agent_api/agent_api.py index 9dd4608..a999429 100644 --- a/lambda_agent_api/agent_api.py +++ b/lambda_agent_api/agent_api.py @@ -164,11 +164,17 @@ class AgentApi: except Exception as e: logger.error(f"Error in on_disconnect: {e}") - async def send_message(self, text: str) -> AsyncIterator[AgentEventUnion]: + async def send_message( + self, text: str, attachments: list[str] | None = None + ) -> AsyncIterator[AgentEventUnion]: """ Нативный асинхронный генератор. Не требует отдельного класса ResponseIterator. Гарантированно освобождает блокировку. + + Args: + text: Текст сообщения. + attachments: Список путей к файлам относительно /workspace. """ if not self._connected or not self._ws: raise AgentException( @@ -185,7 +191,11 @@ class AgentApi: try: self._current_queue = asyncio.Queue() - message = MsgUserMessage(type=EClientMessage.USER_MESSAGE, text=text) + message = MsgUserMessage( + type=EClientMessage.USER_MESSAGE, + text=text, + attachments=attachments or [], + ) await self._ws.send_str(message.model_dump_json()) logger.debug(f"[{self.id}] Sent message: {text[:50]}...") @@ -248,7 +258,7 @@ class AgentApi: self._request_lock.release() async def _listen(self): - """" + """ Прослушивание вебсокета. """ try: diff --git a/lambda_agent_api/client.py b/lambda_agent_api/client.py index df672c0..ca41435 100644 --- a/lambda_agent_api/client.py +++ b/lambda_agent_api/client.py @@ -19,6 +19,12 @@ class MsgUserMessage(BaseModel): """ Текст сообщения. """ + attachments: list[str] = Field(default_factory=list) + """ + Список вложений (файлов) к сообщению. + Передается путь до файла относительно /workspace . + Файлы уже должны быть загружены в директорию. + """ ClientMessage = TypeAdapter(Annotated[