mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
We'll soon be needing a more feature-complete external API. To make way for this, I'm moving some files around so: - We can more easily create new versions of our external API - The file structure of our internal API is more homogeneous These changes are quite opinionated, but IMO in any case they're better than the chaotic structure we have now. ### Changes 🏗️ - Move `backend/server` -> `backend/api` - Move `backend/server/routers` + `backend/server/v2` -> `backend/api/features` - Change absolute sibling imports to relative imports - Move `backend/server/v2/AutoMod` -> `backend/executor/automod` - Combine `backend/server/routers/analytics_*test.py` -> `backend/api/features/analytics_test.py` - Sort OpenAPI spec file ### Checklist 📋 #### For code changes: - [x] I have clearly listed my changes in the PR description - [x] I have made a test plan - [x] I have tested my changes according to the test plan: - CI tests - [x] Clicking around in the app -> no obvious breakage
39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import AsyncGenerator
|
|
|
|
from pydantic import BaseModel, field_serializer
|
|
|
|
from backend.api.model import NotificationPayload
|
|
from backend.data.event_bus import AsyncRedisEventBus
|
|
from backend.util.settings import Settings
|
|
|
|
|
|
class NotificationEvent(BaseModel):
|
|
"""Generic notification event destined for websocket delivery."""
|
|
|
|
user_id: str
|
|
payload: NotificationPayload
|
|
|
|
@field_serializer("payload")
|
|
def serialize_payload(self, payload: NotificationPayload):
|
|
"""Ensure extra fields survive Redis serialization."""
|
|
return payload.model_dump()
|
|
|
|
|
|
class AsyncRedisNotificationEventBus(AsyncRedisEventBus[NotificationEvent]):
|
|
Model = NotificationEvent # type: ignore
|
|
|
|
@property
|
|
def event_bus_name(self) -> str:
|
|
return Settings().config.notification_event_bus_name
|
|
|
|
async def publish(self, event: NotificationEvent) -> None:
|
|
await self.publish_event(event, event.user_id)
|
|
|
|
async def listen(
|
|
self, user_id: str = "*"
|
|
) -> AsyncGenerator[NotificationEvent, None]:
|
|
async for event in self.listen_events(user_id):
|
|
yield event
|