code: def _build_last_step(
      prev_step: Any,
      step_fn: Callable[[Dict[str, Any]], Dict[str, Any]],
  ) -> Dict[str, Any]:
      """Builds the last RLDS step from an envlogger step."""
      # We append the observation of the final step (action and reward were
      # included in the previous step.
      # The terminal flag is inferred like in termination(), truncation()
      # from dm_env/_environment.py
      is_terminal = (
          prev_step.timestep.last()
          and prev_step.timestep.discount == 0.0
      )
      rlds_step = _get_step_metadata(prev_step)
      rlds_step["observation"] = prev_step.timestep.observation
      rlds_step["is_terminal"] = is_terminal
      rlds_step["is_first"] = prev_step.timestep.first()
      rlds_step["is_last"] = True
      # Discount, action and reward are meaningless in the last step
      rlds_step["action"] = tree_utils.map_structure(
          np.zeros_like, prev_step.action
      )
      rlds_step["reward"] = np.zeros_like(prev_step.timestep.reward)
      rlds_step["discount"] = np.zeros_like(prev_step.timestep.discount)
  
      return step_fn(rlds_step)
  
file_path: datasets/tensorflow_datasets/rlds/envlogger_reader.py
imports: from typing import Any, Callable, Dict, Generator, List, Optional, Sequence, Tuple, Union
  import numpy
  from tensorflow_datasets.core.utils import tree_utils
label_desc: Use image node_id 7 for calling a global function with example usage: _build_last_step(prev_step, step_fn) and returns: step_fn