(
app_conversation_id: str, poll_interval_seconds: int, max_wait_seconds: int
)
| 279 | |
| 280 | |
| 281 | def poll_conversation( |
| 282 | app_conversation_id: str, poll_interval_seconds: int, max_wait_seconds: int |
| 283 | ) -> dict[str, Any]: |
| 284 | deadline = time.time() + max_wait_seconds |
| 285 | while time.time() < deadline: |
| 286 | payload = request_json( |
| 287 | OPENHANDS_BASE_URL, |
| 288 | f'/api/v1/app-conversations?ids={urllib.parse.quote(app_conversation_id)}', |
| 289 | headers={'Authorization': openhands_headers()['Authorization']}, |
| 290 | ) |
| 291 | item = extract_first_item(payload) |
| 292 | if item is None: |
| 293 | time.sleep(poll_interval_seconds) |
| 294 | continue |
| 295 | execution_status = str(item.get('execution_status', '')).lower() |
| 296 | if execution_status in FAILED_EXECUTION_STATUSES: |
| 297 | raise RuntimeError( |
| 298 | 'OpenHands conversation ended with ' |
| 299 | f'{execution_status}: {json.dumps(item)}' |
| 300 | ) |
| 301 | if execution_status in SUCCESSFUL_TERMINAL_EXECUTION_STATUSES: |
| 302 | return item |
| 303 | time.sleep(poll_interval_seconds) |
| 304 | raise TimeoutError( |
| 305 | f'Timed out waiting for conversation {app_conversation_id} to finish running' |
| 306 | ) |
| 307 | |
| 308 | |
| 309 | def validate_event_search_results(events: list[dict[str, Any]]) -> list[dict[str, Any]]: |
no test coverage detected