MCPcopy Create free account
hub / github.com/OpenHands/OpenHands / main

Function main

scripts/issue_duplicate_check_openhands.py:517–620  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

515
516
517def main() -> int:
518 args = parse_args()
519 issue = fetch_issue(args.repository, args.issue_number)
520 if issue.get('pull_request'):
521 raise RuntimeError(f'#{args.issue_number} is a pull request, not an issue')
522
523 prompt = build_prompt(args.repository, issue)
524 start_task = start_conversation(prompt, args.repository, args.issue_number)
525 app_conversation_id = start_task.get('app_conversation_id')
526 conversation_url = ''
527
528 if not app_conversation_id:
529 task_id = start_task.get('id')
530 if not task_id:
531 raise RuntimeError(f'Missing id in start task response: {start_task}')
532 ready_task = poll_start_task(
533 task_id,
534 args.poll_interval_seconds,
535 args.max_wait_seconds,
536 )
537 app_conversation_id = ready_task.get('app_conversation_id')
538 if not app_conversation_id:
539 raise RuntimeError(f'Missing app_conversation_id in response: {ready_task}')
540
541 conversation = poll_conversation(
542 app_conversation_id,
543 args.poll_interval_seconds,
544 args.max_wait_seconds,
545 )
546 conversation_url = (
547 conversation.get('conversation_url')
548 or f'{OPENHANDS_BASE_URL}/conversations/{app_conversation_id}'
549 )
550 session_api_key_value = conversation.get('session_api_key')
551 if session_api_key_value and not isinstance(session_api_key_value, str):
552 raise RuntimeError(
553 'session_api_key had unexpected type in the OpenHands conversation: '
554 f'{type(session_api_key_value).__name__}'
555 )
556 session_api_key = session_api_key_value or ''
557 agent_server_url = extract_agent_server_url(conversation_url)
558
559 agent_text = ''
560 if agent_server_url and session_api_key:
561 try:
562 agent_text = fetch_agent_server_final_response(
563 app_conversation_id,
564 agent_server_url,
565 session_api_key,
566 )
567 except RuntimeError:
568 agent_text = ''
569 if not agent_text:
570 events = fetch_app_server_events(app_conversation_id)
571 try:
572 agent_text = extract_last_agent_text(events)
573 except RuntimeError as exc:
574 if not session_api_key:

Calls 14

parse_argsFunction · 0.70
fetch_issueFunction · 0.70
build_promptFunction · 0.70
start_conversationFunction · 0.70
poll_start_taskFunction · 0.70
poll_conversationFunction · 0.70
extract_agent_server_urlFunction · 0.70
fetch_app_server_eventsFunction · 0.70
extract_last_agent_textFunction · 0.70
normalize_resultFunction · 0.70

Tested by

no test coverage detected