diff --git a/ai-hub/app/api/routes/agent_update.py b/ai-hub/app/api/routes/agent_update.py index b86d4a4..64b2165 100644 --- a/ai-hub/app/api/routes/agent_update.py +++ b/ai-hub/app/api/routes/agent_update.py @@ -22,9 +22,14 @@ # Overridable via env var for flexibility in other deployments. _AGENT_NODE_DIR = os.environ.get( "AGENT_NODE_SRC_DIR", - os.path.join(os.path.dirname(__file__), "..", "..", "..", "agent-node-source") + "/app/agent-node-source" +) +_SKILLS_DIR = os.environ.get( + "SKILLS_SRC_DIR", + "/app/skills" ) _AGENT_NODE_DIR = os.path.abspath(_AGENT_NODE_DIR) +_SKILLS_DIR = os.path.abspath(_SKILLS_DIR) _VERSION_FILE = os.path.join(_AGENT_NODE_DIR, "VERSION") # Directories/files to exclude from the distributed tarball @@ -63,20 +68,31 @@ def _build_tarball() -> bytes: """ - Builds an in-memory gzipped tarball of the agent-node directory. - The tarball root is 'agent-node/' so extraction is self-contained. + Builds an in-memory gzipped tarball of the agent-node and skills. + The tarball is flat (no agent-node-source/ prefix) so extraction is direct. """ buf = io.BytesIO() with tarfile.open(fileobj=buf, mode="w:gz") as tar: - for root, dirs, files in os.walk(_AGENT_NODE_DIR): - # Prune excluded dirs in-place so os.walk doesn't descend into them - dirs[:] = [d for d in dirs if not _should_exclude(os.path.join(root, d))] - - for filename in files: - abs_path = os.path.join(root, filename) - rel_path = os.path.relpath(abs_path, os.path.dirname(_AGENT_NODE_DIR)) - if not _should_exclude(rel_path): - tar.add(abs_path, arcname=rel_path) + # 1. Add agent-node files (Flat Root) + if os.path.exists(_AGENT_NODE_DIR): + for root, dirs, files in os.walk(_AGENT_NODE_DIR): + dirs[:] = [d for d in dirs if not _should_exclude(os.path.join(root, d))] + for filename in files: + abs_path = os.path.join(root, filename) + rel_path = os.path.relpath(abs_path, _AGENT_NODE_DIR) + if not _should_exclude(rel_path): + tar.add(abs_path, arcname=rel_path) + + # 2. Add skills directory (as 'skills/') + if os.path.exists(_SKILLS_DIR): + for root, dirs, files in os.walk(_SKILLS_DIR): + dirs[:] = [d for d in dirs if not _should_exclude(os.path.join(root, d))] + for filename in files: + abs_path = os.path.join(root, filename) + # Skills should be in a 'skills/' folder in the tarball + rel_path = os.path.join("skills", os.path.relpath(abs_path, _SKILLS_DIR)) + if not _should_exclude(rel_path): + tar.add(abs_path, arcname=rel_path) return buf.getvalue()