""" Base renderer class for all format renderers. """ from abc import ABC, abstractmethod from typing import Dict, Any, Tuple, List import logging logger = logging.getLogger(__name__) class BaseRenderer(ABC): """Base class for all format renderers.""" def __init__(self): self.logger = logger @classmethod def get_supported_formats(cls) -> List[str]: """ Return list of supported format names for this renderer. Override this method in subclasses to specify supported formats. """ return [] @classmethod def get_format_aliases(cls) -> List[str]: """ Return list of format aliases for this renderer. Override this method in subclasses to specify format aliases. """ return [] @classmethod def get_priority(cls) -> int: """ Return priority for this renderer (higher number = higher priority). Used when multiple renderers support the same format. """ return 0 @abstractmethod def getExtractionPrompt(self, user_prompt: str, title: str) -> str: """ Get the format-specific extraction prompt for AI content extraction. Args: user_prompt: User's original prompt for report generation title: Report title Returns: str: Format-specific prompt for AI extraction """ pass @abstractmethod async def render(self, extracted_content: str, title: str) -> Tuple[str, str]: """ Render extracted content to the target format. Args: extracted_content: Raw content extracted by AI using format-specific prompt title: Report title Returns: tuple: (rendered_content, mime_type) """ pass def _extract_sections(self, report_data: Dict[str, Any]) -> list: """Extract sections from report data.""" return report_data.get('sections', []) def _extract_metadata(self, report_data: Dict[str, Any]) -> Dict[str, Any]: """Extract metadata from report data.""" return report_data.get('metadata', {}) def _get_title(self, report_data: Dict[str, Any], fallback_title: str) -> str: """Get title from report data or use fallback.""" return report_data.get('title', fallback_title) def _format_timestamp(self, timestamp: str = None) -> str: """Format timestamp for display.""" if timestamp: return timestamp from datetime import datetime, UTC return datetime.now(UTC).strftime("%Y-%m-%d %H:%M:%S UTC")