mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
Feat: Filter matching events in reverse order (#6485)
This commit is contained in:
parent
0ba96ce69e
commit
94a64a47f2
@ -367,6 +367,7 @@ class EventStream:
|
||||
end_date: str | None = None,
|
||||
start_id: int = 0,
|
||||
limit: int = 100,
|
||||
reverse: bool = False,
|
||||
) -> list:
|
||||
"""Get matching events from the event stream based on filters.
|
||||
|
||||
@ -378,6 +379,7 @@ class EventStream:
|
||||
end_date: Filter events before this date (ISO format)
|
||||
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 100
|
||||
reverse: Whether to retrieve events in reverse order. Defaults to False.
|
||||
|
||||
Returns:
|
||||
list: List of matching events (as dicts)
|
||||
@ -390,7 +392,7 @@ class EventStream:
|
||||
|
||||
matching_events: list = []
|
||||
|
||||
for event in self.get_events(start_id=start_id):
|
||||
for event in self.get_events(start_id=start_id, reverse=reverse):
|
||||
if self._should_filter_event(
|
||||
event, query, event_types, source, start_date, end_date
|
||||
):
|
||||
|
||||
@ -89,6 +89,10 @@ def test_get_matching_events_type_filter(temp_dir: str):
|
||||
events = event_stream.get_matching_events(event_types=(NullAction, MessageAction))
|
||||
assert len(events) == 3
|
||||
|
||||
# Filter in reverse
|
||||
events = event_stream.get_matching_events(reverse=True, limit=1)
|
||||
assert events[0]['message'] == 'test'
|
||||
|
||||
|
||||
def test_get_matching_events_query_search(temp_dir: str):
|
||||
file_store = get_file_store('local', temp_dir)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user