fix(api_server): report hermes version on /health and /health/detailed (#40620)
Salvaged from #40479; re-verified on main, tightened, tested. Co-authored-by: tfournet <tfournet@users.noreply.github.com>
This commit is contained in:
@@ -61,6 +61,29 @@ from gateway.platforms.base import (
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _hermes_version() -> str:
|
||||
"""Return the hermes-agent version string, or "dev" if it can't be resolved.
|
||||
|
||||
Tries the installed package metadata first (authoritative for a pip/uv
|
||||
install), then the in-tree ``hermes_cli.__version__`` (covers editable /
|
||||
source checkouts where metadata may be stale or absent). Never raises —
|
||||
a version probe must not be able to break the health endpoint.
|
||||
"""
|
||||
try:
|
||||
from importlib.metadata import version
|
||||
|
||||
return version("hermes-agent")
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
from hermes_cli import __version__
|
||||
|
||||
return __version__
|
||||
except Exception:
|
||||
return "dev"
|
||||
|
||||
|
||||
# Default settings
|
||||
DEFAULT_HOST = "127.0.0.1"
|
||||
DEFAULT_PORT = 8642
|
||||
@@ -1047,7 +1070,9 @@ class APIServerAdapter(BasePlatformAdapter):
|
||||
|
||||
async def _handle_health(self, request: "web.Request") -> "web.Response":
|
||||
"""GET /health — simple health check."""
|
||||
return web.json_response({"status": "ok", "platform": "hermes-agent"})
|
||||
return web.json_response(
|
||||
{"status": "ok", "platform": "hermes-agent", "version": _hermes_version()}
|
||||
)
|
||||
|
||||
async def _handle_health_detailed(self, request: "web.Request") -> "web.Response":
|
||||
"""GET /health/detailed — rich status for cross-container dashboard probing.
|
||||
@@ -1062,6 +1087,7 @@ class APIServerAdapter(BasePlatformAdapter):
|
||||
return web.json_response({
|
||||
"status": "ok",
|
||||
"platform": "hermes-agent",
|
||||
"version": _hermes_version(),
|
||||
"gateway_state": runtime.get("gateway_state"),
|
||||
"platforms": runtime.get("platforms", {}),
|
||||
"active_agents": runtime.get("active_agents", 0),
|
||||
|
||||
Reference in New Issue
Block a user