OpenHands/openhands/app_server/event_callback/event_callback_service.py
Tim O'Farrell f292f3a84d
V1 Integration (#11183)
Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: sp.wack <83104063+amanape@users.noreply.github.com>
Co-authored-by: Engel Nyst <enyst@users.noreply.github.com>
2025-10-14 02:16:44 +00:00

65 lines
2.0 KiB
Python

import asyncio
from abc import ABC, abstractmethod
from uuid import UUID
from openhands.app_server.event_callback.event_callback_models import (
CreateEventCallbackRequest,
EventCallback,
EventCallbackPage,
EventKind,
)
from openhands.app_server.services.injector import Injector
from openhands.sdk import Event
from openhands.sdk.utils.models import DiscriminatedUnionMixin
class EventCallbackService(ABC):
"""CRUD service for managing event callbacks."""
@abstractmethod
async def create_event_callback(
self, request: CreateEventCallbackRequest
) -> EventCallback:
"""Create a new event callback."""
@abstractmethod
async def get_event_callback(self, id: UUID) -> EventCallback | None:
"""Get a single event callback, returning None if not found."""
@abstractmethod
async def delete_event_callback(self, id: UUID) -> bool:
"""Delete a event callback, returning True if deleted, False if not found."""
@abstractmethod
async def search_event_callbacks(
self,
conversation_id__eq: UUID | None = None,
event_kind__eq: EventKind | None = None,
event_id__eq: UUID | None = None,
page_id: str | None = None,
limit: int = 100,
) -> EventCallbackPage:
"""Search for event callbacks, optionally filtered by event_id."""
async def batch_get_event_callbacks(
self, event_callback_ids: list[UUID]
) -> list[EventCallback | None]:
"""Get a batch of event callbacks, returning None for any not found."""
results = await asyncio.gather(
*[
self.get_event_callback(event_callback_id)
for event_callback_id in event_callback_ids
]
)
return results
@abstractmethod
async def execute_callbacks(self, conversation_id: UUID, event: Event) -> None:
"""Execute any applicable callbacks for the event and store the results."""
class EventCallbackServiceInjector(
DiscriminatedUnionMixin, Injector[EventCallbackService], ABC
):
pass