refactor: make /events endpoint lightweight without requiring active conversation (#9685)

Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
Tim O'Farrell
2025-07-13 17:14:15 -06:00
committed by GitHub
parent 4aaa2ccd39
commit 95ccec82d9
2 changed files with 42 additions and 9 deletions

View File

@@ -3,9 +3,14 @@ import uuid
from fastapi import Depends, HTTPException, Request, status
from openhands.core.logger import openhands_logger as logger
from openhands.server.shared import ConversationStoreImpl, config, conversation_manager
from openhands.server.shared import (
ConversationStoreImpl,
config,
conversation_manager,
)
from openhands.server.user_auth import get_user_id
from openhands.storage.conversation.conversation_store import ConversationStore
from openhands.storage.data_models.conversation_metadata import ConversationMetadata
async def get_conversation_store(request: Request) -> ConversationStore | None:
@@ -29,6 +34,21 @@ async def generate_unique_conversation_id(
return conversation_id
async def get_conversation_metadata(
conversation_id: str,
conversation_store: ConversationStore = Depends(get_conversation_store),
) -> ConversationMetadata:
"""Get conversation metadata and validate user access without requiring an active conversation."""
try:
metadata = await conversation_store.get_metadata(conversation_id)
return metadata
except FileNotFoundError:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail=f'Conversation {conversation_id} not found',
)
async def get_conversation(
conversation_id: str, user_id: str | None = Depends(get_user_id)
):