fix: seed AI model config at runtime
This commit is contained in:
@@ -91,6 +91,34 @@ def save_config(data):
|
||||
logger.error("Failed to save config to %s: %s", config_file, exc)
|
||||
|
||||
|
||||
def _seed_factory_config_if_missing(filename):
|
||||
"""Copy a packaged config template to user config only when missing."""
|
||||
from shutil import copy2
|
||||
from services.file_service import get_app_dir, get_config_path
|
||||
|
||||
target = get_config_path(filename)
|
||||
if target.exists():
|
||||
return False
|
||||
|
||||
source = get_app_dir() / "config" / filename
|
||||
if not source.exists():
|
||||
return False
|
||||
|
||||
try:
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
copy2(str(source), str(target))
|
||||
logger.info("Seeded factory config from %s to %s", source, target)
|
||||
return True
|
||||
except OSError as exc:
|
||||
logger.warning(
|
||||
"Failed to seed factory config from %s to %s: %s",
|
||||
source,
|
||||
target,
|
||||
exc,
|
||||
)
|
||||
return False
|
||||
|
||||
|
||||
def load_ai_models():
|
||||
"""Load AI model configs from ai_models.json.
|
||||
|
||||
@@ -99,6 +127,7 @@ def load_ai_models():
|
||||
Keys live only in ~/.cmbot and are never committed (docs/11 §11).
|
||||
"""
|
||||
from services.file_service import get_config_path
|
||||
_seed_factory_config_if_missing(_AI_MODELS_FILENAME)
|
||||
models_file = get_config_path(_AI_MODELS_FILENAME)
|
||||
if not models_file.exists():
|
||||
logger.info("AI models file not found: %s", models_file)
|
||||
|
||||
Reference in New Issue
Block a user