61 lines
1.9 KiB
Python
61 lines
1.9 KiB
Python
"""
|
|
Configuration tools for reading application configuration files.
|
|
"""
|
|
import os
|
|
import json
|
|
from typing import Dict, Any, Optional
|
|
from pathlib import Path
|
|
|
|
async def wrapped_get_app_config(config_path: Optional[str] = None) -> Dict[str, Any]:
|
|
"""Read application configuration file and return skills_path if available."""
|
|
try:
|
|
# Default config path locations to search
|
|
default_paths = [
|
|
"./conf/config.json",
|
|
"../conf/config.json",
|
|
"~/conf/config.json",
|
|
"/etc/hermes/config.json"
|
|
]
|
|
|
|
config_file = None
|
|
if config_path and os.path.exists(config_path):
|
|
config_file = config_path
|
|
else:
|
|
# Search for config file in default locations
|
|
for path in default_paths:
|
|
expanded_path = os.path.expanduser(path)
|
|
if os.path.exists(expanded_path):
|
|
config_file = expanded_path
|
|
break
|
|
|
|
if config_file:
|
|
with open(config_file, 'r') as f:
|
|
config = json.load(f)
|
|
# Extract skills_path from config if it exists
|
|
skills_path = config.get('skills_path', '~/.hermes/skills')
|
|
return {
|
|
"success": True,
|
|
"config_file": config_file,
|
|
"config": config,
|
|
"skills_path": skills_path
|
|
}
|
|
else:
|
|
# Return default skills path if no config found
|
|
return {
|
|
"success": True,
|
|
"config_file": None,
|
|
"config": {},
|
|
"skills_path": "~/.hermes/skills"
|
|
}
|
|
|
|
except Exception as e:
|
|
return {
|
|
"success": False,
|
|
"error": str(e),
|
|
"skills_path": "~/.hermes/skills"
|
|
}
|
|
|
|
# Add to skill tools group
|
|
config_tools = {
|
|
'get_app_config': wrapped_get_app_config
|
|
} |