From f2d50ae88b952f9b91202056ab64e11d19d7faeb Mon Sep 17 00:00:00 2001 From: collhoun <2904yr@mail.ru> Date: Mon, 30 Mar 2026 10:05:19 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B8=D0=BC=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D1=8B=20OutgoingMessage=20=D0=B2=20Ser?= =?UTF-8?q?verMessage=20=D0=B8=20IncomingMessage=20=D0=B2=20ClientMessage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/README.md | 4 ++-- api/agent_api.py | 8 ++++---- api/models.py | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/api/README.md b/api/README.md index c8dd1d4..a13bce4 100644 --- a/api/README.md +++ b/api/README.md @@ -79,7 +79,7 @@ async with AgentApi("ws://localhost:8000") as agent: ```python import asyncio import websockets -from models import OutgoingMessage, OM +from models import ServerMessage, OM async def main(): uri = "ws://localhost:8000/ws" @@ -95,7 +95,7 @@ async def main(): # 3. Читаем ответ в виде потока событий while True: msg = await ws.recv() - data = OutgoingMessage.model_validate_json(msg) + data = ServerMessage.model_validate_json(msg) match data: case OM.AgentEvent(subtype=OM.AgentEventType.TEXT_CHUNK): diff --git a/api/agent_api.py b/api/agent_api.py index 42722fe..0fb0c2c 100644 --- a/api/agent_api.py +++ b/api/agent_api.py @@ -1,7 +1,7 @@ import logging from typing import AsyncGenerator import aiohttp -from models import IM, OM, IncomingMessage, OutgoingMessage +from models import IM, OM, ClientMessage, ServerMessage logger = logging.getLogger(__name__) @@ -126,7 +126,7 @@ class AgentApi: self._connected = False raise aiohttp.ClientError(f"Failed to send message: {e}") from e - async def listen(self) -> AsyncGenerator[OutgoingMessage, None]: + async def listen(self) -> AsyncGenerator[ServerMessage, None]: """ Читает поток сообщений от сервера и десериализует их. @@ -137,7 +137,7 @@ class AgentApi: - OM.AgentEvent: Возвращает объект события Yields: - OutgoingMessage: Десериализованное сообщение от сервера + ServerMessage: Десериализованное сообщение от сервера Raises: RuntimeError: Если соединение не установлено @@ -158,7 +158,7 @@ class AgentApi: async for msg in self._ws: if msg.type == aiohttp.WSMsgType.TEXT: try: - outgoing_msg = OutgoingMessage.model_validate_json( + outgoing_msg = ServerMessage.model_validate_json( msg.data) logger.debug( f"Received message of type: {outgoing_msg.type}") diff --git a/api/models.py b/api/models.py index 2e36f06..6f41887 100644 --- a/api/models.py +++ b/api/models.py @@ -25,7 +25,7 @@ class IM: """ -IncomingMessage = Annotated[ +ClientMessage = Annotated[ Union[IM.UserMessage,], Field(discriminator="type") ] @@ -33,7 +33,7 @@ IncomingMessage = Annotated[ Объединяет все типы входящих сообщений в одно для удобной автоматической десериализации.\n Pydantic сам определит нужный тип в зависимости от поля ``type``.\n Использование:\n -msg = IncomingMessage.model_validate_json(json) +msg = ClientMessage.model_validate_json(json) """ @@ -100,7 +100,7 @@ class OM: type: Literal[OM.Type.GRACEFUL_DISCONNECT] -OutgoingMessage = Annotated[ +ServerMessage = Annotated[ Union[OM.Status, OM.AgentEvent, OM.Error, OM.GracefulDisconnect], Field(discriminator="type") ] @@ -108,5 +108,5 @@ OutgoingMessage = Annotated[ Объединяет все типы исходящих сообщений в одно для удобной автоматической десериализации.\n Pydantic сам определит нужный тип в зависимости от поля ``type``.\n Использование:\n -msg = OutgoingMessage.model_validate_json(json) +msg = ServerMessage.model_validate_json(json) """