code: def _collect_top_level_metrics(repo: "Repo") -> Iterator[str]:
      top_metrics = repo.index._metrics
      for dvcfile, metrics in top_metrics.items():
          wdir = repo.fs.relpath(repo.fs.parent(dvcfile), repo.root_dir)
          for file in metrics:
              path = repo.fs.join(wdir, as_posix(file))
              yield repo.fs.normpath(path)
  
imports: import os
  from itertools import chain
  from typing import TYPE_CHECKING, Any, Dict, Iterable, Iterator, List, Optional, Tuple, TypedDict, Union
  from funcy import ldistinct
  from scmrepo.exceptions import SCMError
  from dvc.log import logger
  from dvc.scm import NoSCMError
  from dvc.utils import as_posix, expand_paths
  from dvc.utils.collections import ensure_list
  from dvc.utils.serialize import load_path
label_desc: Use image node_id 1 for calling a global function with example usage: _collect_top_level_metrics(repo) without return types