from typing import Optional from fastapi import APIRouter, File, Form, UploadFile from services.credit_debug_service import CreditDebugService from services.credit_html_identity_service import CreditHtmlIdentityService from services.credit_payload_service import CreditPayloadService router = APIRouter() payload_service = CreditPayloadService("config/credit_feature_schema.json") debug_service = CreditDebugService("config/credit_response_examples.json") identity_service = CreditHtmlIdentityService() @router.post("/xfeature-mngs/conversation/htmlEval") async def html_eval( model: Optional[str] = Form(None), hType: Optional[str] = Form(None), file: Optional[UploadFile] = File(None), ): error_response = debug_service.validate_request( model=model, h_type=hType, file_present=file is not None, ) if error_response: return error_response html_content = await file.read() subject_identity = identity_service.extract_identity(html_content) payload = payload_service.generate_payload( model=model, h_type=hType, filename=file.filename or "credit.html", subject_identity=subject_identity, ) return debug_service.build_success_response(payload) @router.get("/credit/health") async def credit_health(): return {"status": "healthy", "service": "credit-mock"}