Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused event search route #6510

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions frontend/src/api/open-hands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown>[]; has_more: boolean }> {
const { data } = await openHands.get<{
events: Record<string, unknown>[];
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
*/
Expand Down
24 changes: 0 additions & 24 deletions frontend/src/hooks/query/use-search-events.ts

This file was deleted.

75 changes: 1 addition & 74 deletions openhands/server/routes/conversation.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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,
}