Refresh changed Hermes tool search catalogs
This commit is contained in:
@@ -14,9 +14,9 @@ modify an unknown future implementation.
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
TARGET = Path("/opt/hermes/gateway/platforms/api_server.py")
|
API_TARGET = Path("/opt/hermes/gateway/platforms/api_server.py")
|
||||||
ANCHOR = " agent = AIAgent(**agent_kwargs)\n"
|
API_ANCHOR = " agent = AIAgent(**agent_kwargs)\n"
|
||||||
PATCHED = """ # Athena workaround for upstream issue #69746: the API platform
|
API_PATCHED = """ # Athena workaround for upstream issue #69746: the API platform
|
||||||
# otherwise snapshots tools before the live MCP registry is attached.
|
# otherwise snapshots tools before the live MCP registry is attached.
|
||||||
agent = AIAgent(**agent_kwargs)
|
agent = AIAgent(**agent_kwargs)
|
||||||
try:
|
try:
|
||||||
@@ -30,15 +30,38 @@ PATCHED = """ # Athena workaround for upstream issue #69746: the API plat
|
|||||||
)
|
)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
REFRESH_TARGET = Path("/opt/hermes/tools/mcp_tool.py")
|
||||||
|
REFRESH_ANCHOR = """ if new_names == current:
|
||||||
|
# No change → leave the live snapshot untouched (no churn), but
|
||||||
|
"""
|
||||||
|
REFRESH_PATCHED = """ if (
|
||||||
|
new_names == current
|
||||||
|
and new_defs == (getattr(agent, "tools", None) or [])
|
||||||
|
):
|
||||||
|
# Names and schemas are unchanged. Comparing schemas is required
|
||||||
|
# for the tool_search bridge, whose three public names stay fixed
|
||||||
|
# while its embedded deferred-tool catalog changes (#72560).
|
||||||
|
"""
|
||||||
|
|
||||||
source = TARGET.read_text(encoding="utf-8")
|
|
||||||
if PATCHED in source:
|
def apply_patch(target: Path, anchor: str, replacement: str, label: str) -> None:
|
||||||
print("Hermes API MCP refresh patch already present")
|
source = target.read_text(encoding="utf-8")
|
||||||
elif source.count(ANCHOR) == 1:
|
if replacement in source:
|
||||||
TARGET.write_text(source.replace(ANCHOR, PATCHED, 1), encoding="utf-8")
|
print(f"Hermes {label} patch already present")
|
||||||
print("Applied Hermes API MCP refresh patch")
|
elif source.count(anchor) == 1:
|
||||||
else:
|
target.write_text(source.replace(anchor, replacement, 1), encoding="utf-8")
|
||||||
|
print(f"Applied Hermes {label} patch")
|
||||||
|
else:
|
||||||
raise SystemExit(
|
raise SystemExit(
|
||||||
"HERMES_START_REFUSED: upstream api_server.py changed; "
|
f"HERMES_START_REFUSED: upstream {target.name} changed; "
|
||||||
"review the MCP refresh patch before upgrading"
|
f"review the {label} patch before upgrading"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
apply_patch(API_TARGET, API_ANCHOR, API_PATCHED, "API MCP refresh")
|
||||||
|
apply_patch(
|
||||||
|
REFRESH_TARGET,
|
||||||
|
REFRESH_ANCHOR,
|
||||||
|
REFRESH_PATCHED,
|
||||||
|
"tool-search catalog refresh",
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user