code: def extend_ranges(
      ranges: List[range],
      extension_length: int,
      direction: str = "right",
  ) -> List[range]:
      """
      Extends a list of ranges by `extension_length` steps.
  
      Parameters
      ----------
      ranges: List[range]
          Ranges to be extended, non-overlapping and in sorted order.
      extension_length: int
          Positive integer, the length of the extension.
      direction: str
          Direction of the extension. If "right" ("left"), ranges are extended towards
          the right (left). Default "right".
      Returns
      -------
      out_ranges: List[range]
      """
      if not ranges:
          return []
      assert (
          extension_length >= 0
      ), "`extension_length` must be zero or above"
      assert direction in [
          "left",
          "right",
      ], "`direction` must be one of 'left' or 'right'."
  
      out_ranges = []
  
      # iterate over real ranges (ground truth anomalies) and "extend" them to include
      # slack windows where it's OK if they're caught
      for i, old_range in enumerate(ranges):
          if direction == "right":
              range_end_ub = (
                  ranges[i + 1].start
                  if i < len(ranges) - 1
                  else ranges[-1].stop + extension_length + 1
              )
              new_range = range(
                  old_range.start,
                  min(range_end_ub, old_range.stop + extension_length),
              )
          else:
              range_start_lb = ranges[i - 1].stop if i > 0 else 0
              new_range = range(
                  max(
                      range_start_lb, old_range.start - extension_length
                  ),
                  old_range.stop,
              )
  
          out_ranges.append(new_range)
  
      return out_ranges
  
label_desc: Use image node_id 1 for calling a global function with example usage: extend_ranges(ranges, extension_length, direction) and returns: out_ranges, list