From 5115847c374669b86878f25d61498020d72cddc8 Mon Sep 17 00:00:00 2001 From: "rohitvinodmalhotra@gmail.com" Date: Tue, 28 Jan 2025 18:22:20 -0500 Subject: [PATCH] remove unused event search route --- frontend/src/api/open-hands.ts | 29 ------- frontend/src/hooks/query/use-search-events.ts | 24 ------ openhands/server/routes/conversation.py | 75 +------------------ 3 files changed, 1 insertion(+), 127 deletions(-) delete mode 100644 frontend/src/hooks/query/use-search-events.ts diff --git a/frontend/src/api/open-hands.ts b/frontend/src/api/open-hands.ts index 58e1ddbb2d47..75777004c03e 100644 --- a/frontend/src/api/open-hands.ts +++ b/frontend/src/api/open-hands.ts @@ -254,35 +254,6 @@ class OpenHands { return data; } - static async searchEvents( - conversationId: string, - params: { - query?: string; - startId?: number; - limit?: number; - eventType?: string; - source?: string; - startDate?: string; - endDate?: string; - }, - ): Promise<{ events: Record[]; has_more: boolean }> { - const { data } = await openHands.get<{ - events: Record[]; - has_more: boolean; - }>(`/api/conversations/${conversationId}/events/search`, { - params: { - query: params.query, - start_id: params.startId, - limit: params.limit, - event_type: params.eventType, - source: params.source, - start_date: params.startDate, - end_date: params.endDate, - }, - }); - return data; - } - /** * Get the settings from the server or use the default settings if not found */ diff --git a/frontend/src/hooks/query/use-search-events.ts b/frontend/src/hooks/query/use-search-events.ts deleted file mode 100644 index 2b18c2c9818c..000000000000 --- a/frontend/src/hooks/query/use-search-events.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { useQuery } from "@tanstack/react-query"; -import { useConversation } from "#/context/conversation-context"; -import OpenHands from "#/api/open-hands"; - -export const useSearchEvents = (params: { - query?: string; - startId?: number; - limit?: number; - eventType?: string; - source?: string; - startDate?: string; - endDate?: string; -}) => { - const { conversationId } = useConversation(); - - return useQuery({ - queryKey: ["search_events", conversationId, params], - queryFn: () => { - if (!conversationId) throw new Error("No conversation ID"); - return OpenHands.searchEvents(conversationId, params); - }, - enabled: !!conversationId, - }); -}; diff --git a/openhands/server/routes/conversation.py b/openhands/server/routes/conversation.py index b91c8070b56f..3e2dfb334d51 100644 --- a/openhands/server/routes/conversation.py +++ b/openhands/server/routes/conversation.py @@ -1,27 +1,12 @@ -from fastapi import APIRouter, HTTPException, Request, status +from fastapi import APIRouter, Request from fastapi.responses import JSONResponse from openhands.core.logger import openhands_logger as logger -from openhands.events.event import Event -from openhands.events.serialization.event import event_from_dict, event_to_dict from openhands.runtime.base import Runtime app = APIRouter(prefix='/api/conversations/{conversation_id}') -def str_to_event_type(event: str | None) -> Event | None: - if not event: - return None - - for event_type in ['observation', 'action']: - try: - return event_from_dict({event_type: event}) - except Exception: - continue - - return None - - @app.get('/config') async def get_remote_runtime_config(request: Request): """Retrieve the runtime configuration. @@ -104,61 +89,3 @@ async def get_hosts(request: Request): 'error': f'Error getting runtime hosts: {e}', }, ) - - -@app.get('/events/search') -async def search_events( - request: Request, - query: str | None = None, - start_id: int = 0, - limit: int = 20, - event_type: str | None = None, - source: str | None = None, - start_date: str | None = None, - end_date: str | None = None, -): - """Search through the event stream with filtering and pagination. - Args: - request: The incoming request object - query: Text to search for in event content - start_id: Starting ID in the event stream. Defaults to 0 - limit: Maximum number of events to return. Must be between 1 and 100. Defaults to 20 - event_type: Filter by event type (e.g., "FileReadAction") - source: Filter by event source - start_date: Filter events after this date (ISO format) - end_date: Filter events before this date (ISO format) - Returns: - dict: Dictionary containing: - - events: List of matching events - - has_more: Whether there are more matching events after this batch - Raises: - HTTPException: If conversation is not found - ValueError: If limit is less than 1 or greater than 100 - """ - if not request.state.conversation: - raise HTTPException( - status_code=status.HTTP_404_NOT_FOUND, detail='Conversation not found' - ) - # Get matching events from the stream - event_stream = request.state.conversation.event_stream - - cast_event_type = str_to_event_type(event_type) - matching_events = event_stream.get_matching_events( - query=query, - event_types=(cast_event_type), - source=source, - start_date=start_date, - end_date=end_date, - start_id=start_id, - limit=limit + 1, # Get one extra to check if there are more - ) - # Check if there are more events - has_more = len(matching_events) > limit - if has_more: - matching_events = matching_events[:limit] # Remove the extra event - - matching_events = [event_to_dict(event) for event in matching_events] - return { - 'events': matching_events, - 'has_more': has_more, - }