"""Resolve a step's images from the resource that actually produced them.""" from typing import Any def step_image_name(step: Any, which: str) -> str | None: def field(name): return step.get(name) if isinstance(step, dict) else getattr(step, name, None) result = field("last_execution_result") execution = result.get("execution") if isinstance(result, dict) else None actions = execution if isinstance(execution, list) else field("action_taken") if isinstance(actions, dict): actions = [actions] actions = actions if isinstance(actions, list) else [] plugins = [ action for action in actions if isinstance(action, dict) and (action.get("plugin_id") or str(action.get("action", "")).startswith("plug_")) ] if not plugins: return field(f"{which}_image_name") # A burst may span several resources. Its per-call evidence must not be # presented as a before/after pair on one screen. if len(actions) != 1: return None action = plugins[0] if isinstance(execution, list) or f"{which}_image_name" in action: if which == "pre" and not action.get("pre_image_valid"): return None return action.get(f"{which}_image_name") # Older Flash records already stored source-specific images at step level. return field(f"{which}_image_name")