()
| 458 | |
| 459 | |
| 460 | def main() -> int: |
| 461 | args = parse_args() |
| 462 | issue = fetch_issue(args.repository, args.issue_number) |
| 463 | if issue.get('pull_request'): |
| 464 | raise RuntimeError(f'#{args.issue_number} is a pull request, not an issue') |
| 465 | |
| 466 | prompt = build_prompt(args.repository, issue) |
| 467 | start_task = start_conversation(prompt, args.repository, args.issue_number) |
| 468 | app_conversation_id = start_task.get('app_conversation_id') |
| 469 | conversation_url = '' |
| 470 | |
| 471 | if not app_conversation_id: |
| 472 | task_id = start_task.get('id') |
| 473 | if not task_id: |
| 474 | raise RuntimeError(f'Missing id in start task response: {start_task}') |
| 475 | ready_task = poll_start_task( |
| 476 | task_id, |
| 477 | args.poll_interval_seconds, |
| 478 | args.max_wait_seconds, |
| 479 | ) |
| 480 | app_conversation_id = ready_task.get('app_conversation_id') |
| 481 | if not app_conversation_id: |
| 482 | raise RuntimeError(f'Missing app_conversation_id in response: {ready_task}') |
| 483 | |
| 484 | conversation = poll_conversation( |
| 485 | app_conversation_id, |
| 486 | args.poll_interval_seconds, |
| 487 | args.max_wait_seconds, |
| 488 | ) |
| 489 | conversation_url = ( |
| 490 | conversation.get('conversation_url') |
| 491 | or f'{OPENHANDS_BASE_URL}/conversations/{app_conversation_id}' |
| 492 | ) |
| 493 | session_api_key_value = conversation.get('session_api_key') |
| 494 | if session_api_key_value and not isinstance(session_api_key_value, str): |
| 495 | raise RuntimeError( |
| 496 | 'session_api_key had unexpected type in the OpenHands conversation: ' |
| 497 | f'{type(session_api_key_value).__name__}' |
| 498 | ) |
| 499 | session_api_key = session_api_key_value or '' |
| 500 | agent_server_url = extract_agent_server_url(conversation_url) |
| 501 | |
| 502 | agent_text = '' |
| 503 | if agent_server_url and session_api_key: |
| 504 | try: |
| 505 | agent_text = fetch_agent_server_final_response( |
| 506 | app_conversation_id, |
| 507 | agent_server_url, |
| 508 | session_api_key, |
| 509 | ) |
| 510 | except RuntimeError: |
| 511 | agent_text = '' |
| 512 | if not agent_text: |
| 513 | events = fetch_app_server_events(app_conversation_id) |
| 514 | try: |
| 515 | agent_text = extract_last_agent_text(events) |
| 516 | except RuntimeError as exc: |
| 517 | if not session_api_key: |
no test coverage detected