Подчистил архитектуру приложения v1 работает

This commit is contained in:
2026-04-01 12:28:55 +03:00
parent 0bff171936
commit 5d77ab1a88
97 changed files with 815 additions and 5161 deletions
@@ -0,0 +1,24 @@
from __future__ import annotations
from app.core.exceptions import AppError
from app.modules.api.infrastructure.streaming.sse_encoder import SseEncoder
from app.modules.api.infrastructure.streaming.sse_event_channel import SseEventChannel
from app.schemas.common import ModuleName
class StreamService:
def __init__(self, channel: SseEventChannel, request_exists, encoder: SseEncoder | None = None) -> None:
self._channel = channel
self._request_exists = request_exists
self._encoder = encoder or SseEncoder()
async def subscribe(self, request_id: str):
if not self._request_exists(request_id):
raise AppError("request_not_found", f"Agent request not found: {request_id}", ModuleName.BACKEND)
return await self._channel.subscribe(request_id, replay=True)
async def unsubscribe(self, request_id: str, queue) -> None:
await self._channel.unsubscribe(request_id, queue)
def encode(self, event) -> str:
return self._encoder.encode(event)