code: def _get_episode_metadata(episode: Sequence[Any]) -> Dict[str, Any]:
      """Extracts the episode metadata and returns it as a dictionary.
  
      This is only used when the episode metadata is stored in the first step.
  
      Args:
        episode: sequence of steps (envlogger.StepData).
  
      Returns:
        Dictionary containing the episode metadata
      """
  
      first_step = episode[0]
      if not first_step.timestep.first():
          raise ValueError(
              "The first step in this episode is not first"
          )
      custom_data = first_step.custom_data
      return (
          custom_data.get("episode_metadata", {}) if custom_data else {}
      )
  
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 1 for calling a global function with example usage: _get_episode_metadata(episode) and returns: unknown