|
|
""" |
|
|
Proof Builder Agent |
|
|
Assembles final proof object from validated components. |
|
|
""" |
|
|
|
|
|
from typing import Dict, Any |
|
|
import uuid |
|
|
|
|
|
from core.agent_base import Agent |
|
|
from core.errors import ProofSystemError |
|
|
from models.proof import Proof |
|
|
|
|
|
|
|
|
class ProofBuilderAgent(Agent): |
|
|
""" |
|
|
Combines hash, metadata, and validation results into a Proof object. |
|
|
""" |
|
|
|
|
|
def execute(self, input_data: Dict[str, Any]) -> Dict[str, Any]: |
|
|
""" |
|
|
Build final proof object. |
|
|
|
|
|
Expected input_data: |
|
|
{ |
|
|
"content_hash": str, |
|
|
"hash_algorithm": str, |
|
|
"metadata": dict, |
|
|
"validation_status": str, |
|
|
"extracted_text": str | None, |
|
|
"ocr_engine": str | None, |
|
|
"ocr_status": str | None, |
|
|
... |
|
|
} |
|
|
|
|
|
Returns: |
|
|
{ |
|
|
"proof": Proof, |
|
|
"proof_id": str |
|
|
} |
|
|
""" |
|
|
try: |
|
|
|
|
|
proof_id = self._generate_proof_id() |
|
|
|
|
|
|
|
|
metadata = input_data.get("metadata", {}) |
|
|
|
|
|
|
|
|
proof = Proof( |
|
|
proof_id=proof_id, |
|
|
content_hash=input_data.get("content_hash"), |
|
|
hash_algorithm=input_data.get("hash_algorithm"), |
|
|
content_type=metadata.get("content_type"), |
|
|
content_size=metadata.get("content_size"), |
|
|
timestamp=metadata.get("created_at"), |
|
|
validation_status=input_data.get("validation_status"), |
|
|
metadata=metadata, |
|
|
extracted_text=input_data.get("extracted_text"), |
|
|
ocr_engine=input_data.get("ocr_engine"), |
|
|
ocr_status=input_data.get("ocr_status") |
|
|
) |
|
|
|
|
|
return { |
|
|
"proof": proof, |
|
|
"proof_id": proof_id |
|
|
} |
|
|
|
|
|
except Exception as e: |
|
|
raise ProofSystemError(f"Proof building failed: {str(e)}") from e |
|
|
|
|
|
def _generate_proof_id(self) -> str: |
|
|
""" |
|
|
Generate unique proof identifier. |
|
|
|
|
|
Returns: |
|
|
UUID string |
|
|
""" |
|
|
return str(uuid.uuid4()) |