from __future__ import annotations from typing import Any from ..states.ingestion_state import IngestionState def validation_node(state: IngestionState, allowed_sources: set[str] | None = None) -> dict[str, Any]: """Validation Phase: Validate request input and fail fast on malformed requests.""" request = state.get("request") allowed = allowed_sources or {"github", "sharepoint"} errors: list[str] = [] if not request: errors.append("missing ingestion request") else: if not request.source or not request.source.strip(): errors.append("missing request source") elif request.source not in allowed: errors.append(f"unsupported source '{request.source}'") if not request.locator or not request.locator.strip(): errors.append("missing request locator") if errors: error_records = list(state.get("errors", [])) for err in errors: error_records.append({"step": "validation", "message": err, "recoverable": False}) return { "validation_errors": errors, "errors": error_records, "has_errors": True, "current_step": "validation", "next_step": "END", } return { "validation_errors": [], "current_step": "validation", "next_step": "generation", }