더북(TheBook)
# ============================================================
# gRPC RemediationAgent 호출 함수
# ============================================================

async def remediate_with_grpc(code_path: str, pdf_path: str) -> str:
    """
    Remediation Agent 서버를 비동기로 호출하는 함수
    
    Args:
        code_path: 분석할 코드 파일 경로
        pdf_path: 기준 문서 PDF 파일 경로
        
    Returns:
        str: 생성된 리포트 파일의 경로
    """
    # 비동기 insecure 채널을 사용하여 localhost:50056에 연결
    async with grpc.aio.insecure_channel("localhost:50056") as channel:
        # RemediationService의 비동기 스텁 생성
        stub = agents_pb2_grpc.RemediationServiceStub(channel)
        
        # RemediationRequest 생성 (코드 경로, PDF 경로, 리포트 경로 포함)
        # 리포트 경로를 results 디렉터리로 설정 (절대 경로)
        results_dir = os.path.join(PROJECT_ROOT, "results")
        os.makedirs(results_dir, exist_ok=True)  # results 디렉터리가 없으면 생성
        report_path = os.path.abspath(os.path.join(results_dir, "vulnerability_report.md"))
        req = agents_pb2.RemediationRequest(
            code_path=code_path,
            pdf_path=pdf_path,
            report_path=report_path
        )
        
        # 비동기로 Remediate 메서드 호출
        resp = await stub.Remediate(req)
        
        # 생성된 리포트 파일 경로 반환
        return resp.report_path