mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-25 21:36:52 +08:00
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>
76 lines
2.4 KiB
Python
76 lines
2.4 KiB
Python
import asyncio
|
|
from abc import ABC, abstractmethod
|
|
from datetime import datetime
|
|
from uuid import UUID
|
|
|
|
from openhands.app_server.app_conversation.app_conversation_models import (
|
|
AppConversationInfo,
|
|
AppConversationInfoPage,
|
|
AppConversationSortOrder,
|
|
)
|
|
from openhands.app_server.services.injector import Injector
|
|
from openhands.sdk.utils.models import DiscriminatedUnionMixin
|
|
|
|
|
|
class AppConversationInfoService(ABC):
|
|
"""Service for accessing info on conversations without their current status."""
|
|
|
|
@abstractmethod
|
|
async def search_app_conversation_info(
|
|
self,
|
|
title__contains: str | None = None,
|
|
created_at__gte: datetime | None = None,
|
|
created_at__lt: datetime | None = None,
|
|
updated_at__gte: datetime | None = None,
|
|
updated_at__lt: datetime | None = None,
|
|
sort_order: AppConversationSortOrder = AppConversationSortOrder.CREATED_AT_DESC,
|
|
page_id: str | None = None,
|
|
limit: int = 100,
|
|
) -> AppConversationInfoPage:
|
|
"""Search for sandboxed conversations."""
|
|
|
|
@abstractmethod
|
|
async def count_app_conversation_info(
|
|
self,
|
|
title__contains: str | None = None,
|
|
created_at__gte: datetime | None = None,
|
|
created_at__lt: datetime | None = None,
|
|
updated_at__gte: datetime | None = None,
|
|
updated_at__lt: datetime | None = None,
|
|
) -> int:
|
|
"""Count sandboxed conversations."""
|
|
|
|
@abstractmethod
|
|
async def get_app_conversation_info(
|
|
self, conversation_id: UUID
|
|
) -> AppConversationInfo | None:
|
|
"""Get a single conversation info, returning None if missing."""
|
|
|
|
async def batch_get_app_conversation_info(
|
|
self, conversation_ids: list[UUID]
|
|
) -> list[AppConversationInfo | None]:
|
|
"""Get a batch of conversation info, return None for any missing."""
|
|
return await asyncio.gather(
|
|
*[
|
|
self.get_app_conversation_info(conversation_id)
|
|
for conversation_id in conversation_ids
|
|
]
|
|
)
|
|
|
|
# Mutators
|
|
|
|
@abstractmethod
|
|
async def save_app_conversation_info(
|
|
self, info: AppConversationInfo
|
|
) -> AppConversationInfo:
|
|
"""Store the sandboxed conversation info object given.
|
|
|
|
Return the stored info
|
|
"""
|
|
|
|
|
|
class AppConversationInfoServiceInjector(
|
|
DiscriminatedUnionMixin, Injector[AppConversationInfoService], ABC
|
|
):
|
|
pass
|