mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-12 01:54:45 +08:00
- Use ExtensionsConfig.from_file() instead of cached config to always read latest configuration from disk in LangGraph Server - Add mtime-based cache invalidation for MCP tools to detect config file changes made through Gateway API - Call reload_extensions_config() in Gateway API after updates to refresh the global cache - Remove unnecessary MCP initialization from Gateway startup since MCP tools are only used by LangGraph Server Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
98 lines
3.3 KiB
Python
98 lines
3.3 KiB
Python
from pathlib import Path
|
|
|
|
from .parser import parse_skill_file
|
|
from .types import Skill
|
|
|
|
|
|
def get_skills_root_path() -> Path:
|
|
"""
|
|
Get the root path of the skills directory.
|
|
|
|
Returns:
|
|
Path to the skills directory (deer-flow/skills)
|
|
"""
|
|
# backend directory is current file's parent's parent's parent
|
|
backend_dir = Path(__file__).resolve().parent.parent.parent
|
|
# skills directory is sibling to backend directory
|
|
skills_dir = backend_dir.parent / "skills"
|
|
return skills_dir
|
|
|
|
|
|
def load_skills(skills_path: Path | None = None, use_config: bool = True, enabled_only: bool = False) -> list[Skill]:
|
|
"""
|
|
Load all skills from the skills directory.
|
|
|
|
Scans both public and custom skill directories, parsing SKILL.md files
|
|
to extract metadata. The enabled state is determined by the skills_state_config.json file.
|
|
|
|
Args:
|
|
skills_path: Optional custom path to skills directory.
|
|
If not provided and use_config is True, uses path from config.
|
|
Otherwise defaults to deer-flow/skills
|
|
use_config: Whether to load skills path from config (default: True)
|
|
enabled_only: If True, only return enabled skills (default: False)
|
|
|
|
Returns:
|
|
List of Skill objects, sorted by name
|
|
"""
|
|
if skills_path is None:
|
|
if use_config:
|
|
try:
|
|
from src.config import get_app_config
|
|
|
|
config = get_app_config()
|
|
skills_path = config.skills.get_skills_path()
|
|
except Exception:
|
|
# Fallback to default if config fails
|
|
skills_path = get_skills_root_path()
|
|
else:
|
|
skills_path = get_skills_root_path()
|
|
|
|
if not skills_path.exists():
|
|
return []
|
|
|
|
skills = []
|
|
|
|
# Scan public and custom directories
|
|
for category in ["public", "custom"]:
|
|
category_path = skills_path / category
|
|
if not category_path.exists() or not category_path.is_dir():
|
|
continue
|
|
|
|
# Each subdirectory is a potential skill
|
|
for skill_dir in category_path.iterdir():
|
|
if not skill_dir.is_dir():
|
|
continue
|
|
|
|
skill_file = skill_dir / "SKILL.md"
|
|
if not skill_file.exists():
|
|
continue
|
|
|
|
skill = parse_skill_file(skill_file, category=category)
|
|
if skill:
|
|
skills.append(skill)
|
|
|
|
# Load skills state configuration and update enabled status
|
|
# NOTE: We use ExtensionsConfig.from_file() instead of get_extensions_config()
|
|
# to always read the latest configuration from disk. This ensures that changes
|
|
# made through the Gateway API (which runs in a separate process) are immediately
|
|
# reflected in the LangGraph Server when loading skills.
|
|
try:
|
|
from src.config.extensions_config import ExtensionsConfig
|
|
|
|
extensions_config = ExtensionsConfig.from_file()
|
|
for skill in skills:
|
|
skill.enabled = extensions_config.is_skill_enabled(skill.name, skill.category)
|
|
except Exception as e:
|
|
# If config loading fails, default to all enabled
|
|
print(f"Warning: Failed to load extensions config: {e}")
|
|
|
|
# Filter by enabled status if requested
|
|
if enabled_only:
|
|
skills = [skill for skill in skills if skill.enabled]
|
|
|
|
# Sort by name for consistent ordering
|
|
skills.sort(key=lambda s: s.name)
|
|
|
|
return skills
|