publish.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. """Pluggable hook for publishing agent run artifacts after each run.
  2. Framework stays free of infrastructure packages. Infra registers a publisher
  3. via ``set_run_artifact_publisher`` (see agent_logging under the infra package).
  4. """
  5. from __future__ import annotations
  6. from collections.abc import Callable
  7. from typing import TYPE_CHECKING
  8. if TYPE_CHECKING:
  9. from supply_agent.logging.logger import AgentLogger
  10. RunArtifactPublisher = Callable[["AgentLogger"], str | None]
  11. _publisher: RunArtifactPublisher | None = None
  12. def set_run_artifact_publisher(publisher: RunArtifactPublisher | None) -> None:
  13. """Install or clear the post-run artifact publisher callback."""
  14. global _publisher
  15. _publisher = publisher
  16. def get_run_artifact_publisher() -> RunArtifactPublisher | None:
  17. return _publisher
  18. def publish_run_artifacts(agent_logger: AgentLogger) -> str | None:
  19. """
  20. Invoke the registered publisher, if any.
  21. Returns the public artifact URL, or None when no publisher is registered
  22. or publishing is skipped / failed.
  23. """
  24. if _publisher is None:
  25. return None
  26. return _publisher(agent_logger)