"""Complete/fail payload builders for RPA nodes.""" from __future__ import annotations import uuid from typing import Any from .errors import NodeError def build_complete_payload( job_id: str, node_code: str, attempt_no: int, output: dict[str, Any] | None = None, ) -> dict[str, Any]: output = output or {} refs = output.get("businessRefs") or {} ref_key = next(iter(refs.values()), "ok") return { "attemptNo": attempt_no, "executorRunId": f"YSQ-{node_code}-{uuid.uuid4().hex[:12]}", "idempotencyKey": f"{job_id}:{node_code}:{attempt_no}:{ref_key}", "businessRefs": refs, "summary": output.get("summary") or {}, "artifacts": output.get("artifacts") or [], } def build_fail_payload(attempt_no: int, exc: NodeError) -> dict[str, Any]: return { "attemptNo": attempt_no, "errorCode": exc.error_code, "errorSummary": str(exc), "retryable": exc.retryable, "routeRole": exc.route_role, "artifacts": [], }