This repository has been archived on 2026-07-19. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
shira-hermes/api/main.py
T
chaim 737307d5a4 feat(skills): seed new baked skills into the persistent volume on startup
/opt/data on shira-hermes is now a Docker named volume on both dev and prod
(added 2026-04-27 so learned skills/profiles/cases survive redeploys). Named
volumes copy image content only on FIRST creation — after that the volume is
opaque to image updates. So a new entry added to config/skills/ in the repo
would never reach an instance that already has a populated volume.

Fix: at FastAPI startup, walk /app/config/skills/ (baked into the image,
outside the volume mount) and copy any directory whose name does not yet
exist under /opt/data/skills/. Skills already present — whether learned by
the model, edited by a user, or seeded earlier — are never touched.

- skills.py: BAKED_SKILLS_DIR derived from __file__ so it stays correct
  regardless of WORKDIR; seed_skills_from_image() returns (added, skipped)
- main.py: call after ensure_data_dirs() and log the result
- Verified with a unit fixture: 2 new baked skills copied, 1 pre-existing
  skill with custom content left untouched

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 07:27:36 +00:00

60 lines
1.7 KiB
Python

"""shira-hermes — FastAPI application."""
from __future__ import annotations
import os
import logging
from pathlib import Path
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from api import __version__
from api.routes.admin_kb import router as admin_kb_router
from api.routes.health import router as health_router
from api.routes.kb_public import router as kb_public_router
from api.routes.smart_assistant import router as smart_assistant_router
from api.services.skills import seed_skills_from_image
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(name)s] %(levelname)s: %(message)s",
)
logger = logging.getLogger("shira.app")
app = FastAPI(
title="shira-hermes",
description="Shira AI Assistant — Hermes Agent backend for EspoCRM SmartAssistant",
version=__version__,
)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_methods=["GET", "POST", "OPTIONS"],
allow_headers=["Content-Type", "X-Api-Key"],
)
app.include_router(health_router)
app.include_router(smart_assistant_router)
app.include_router(admin_kb_router)
app.include_router(kb_public_router)
@app.on_event("startup")
async def ensure_data_dirs():
"""Create persistent data directories and seed any new baked-in skills."""
data_dir = os.environ.get("SHIRA_DATA_DIR", "/opt/data")
dirs = [
f"{data_dir}/skills",
f"{data_dir}/profiles",
f"{data_dir}/cases",
]
for d in dirs:
Path(d).mkdir(parents=True, exist_ok=True)
logger.info("Data directories ready at %s", data_dir)
added, skipped = seed_skills_from_image()
logger.info("Skills seed: %d new baked skill(s) added, %d already present", added, skipped)