sync update from LAN repo (source dhk-1 @ 3b1ec5b4)
This commit is contained in:
1 parent
da6521b6cb
commit
264e2200d6
995 files changed
+148105
-13399
No files matched your search
+39
-10
@@ -208,8 +208,11 @@ def _load_owned_skill_names(user_id: str | None) -> set[str] | None:
|
||||
factory = get_session_factory()
|
||||
if factory is None:
|
||||
return None
|
||||
store = make_skill_store(factory)
|
||||
records = run_db_blocking(store.list_visible(user_id))
|
||||
async def read_visible():
|
||||
store = make_skill_store(get_session_factory())
|
||||
return await store.list_visible(user_id)
|
||||
|
||||
records = run_db_blocking(read_visible())
|
||||
return {r["name"] for r in records if r.get("owner_user_id") == user_id}
|
||||
except Exception:
|
||||
logger.debug("Failed to load owned skill names for skill_list filter", exc_info=True)
|
||||
@@ -236,10 +239,18 @@ def skill_view_impl(name: str, agent_id: str | None, extra_skills: list[str] | N
|
||||
|
||||
storage = get_or_new_skill_storage()
|
||||
try:
|
||||
# Discover through the enabled catalog instead of reconstructing a
|
||||
# path from ``name``. Besides enforcing the online/offline switch,
|
||||
# this preserves skills whose directory differs from frontmatter name.
|
||||
skill = next((item for item in storage.load_skills(enabled_only=True) if item.name == name), None)
|
||||
# A warm catalogue already knows each skill's file. Read that one file.
|
||||
# A cold catalogue checks the canonical directory before walking every
|
||||
# SKILL.md, which is only needed for a directory whose name differs.
|
||||
from deerflow.agents.lead_agent.prompt import _load_named_enabled_skill, get_warm_enabled_skills
|
||||
|
||||
cached = get_warm_enabled_skills(storage)
|
||||
if cached is not None:
|
||||
skill = next((item for item in cached if item.name == name), None)
|
||||
else:
|
||||
skill = _load_named_enabled_skill(name)
|
||||
if skill is None:
|
||||
skill = next((item for item in storage.load_skills(enabled_only=True) if item.name == name), None)
|
||||
if skill is None:
|
||||
return f"Skill '{name}' not found."
|
||||
content = skill.skill_file.read_text(encoding="utf-8")
|
||||
@@ -320,7 +331,7 @@ def search_skills_impl(query: str, agent_id: str | None, top_n: int = 5, extra_s
|
||||
|
||||
try:
|
||||
storage = get_or_new_skill_storage()
|
||||
skills = storage.load_skills(enabled_only=True)
|
||||
skills = _skills_for_catalogue(storage)
|
||||
usage = all_entries()
|
||||
base_path = _resolve_skills_container_base_path()
|
||||
scored: list[tuple[int, dict]] = []
|
||||
@@ -396,11 +407,29 @@ def skill_list_tool(runtime: ToolRuntime) -> str:
|
||||
return skill_list_impl(_resolve_active_agent_id(runtime), _resolve_extra_skills(runtime))
|
||||
|
||||
|
||||
def _latest_activity(entry: dict) -> str | None:
|
||||
candidates = [entry.get("last_used_at"), entry.get("last_viewed_at"), entry.get("last_patched_at")]
|
||||
valid = [ts for ts in candidates if ts]
|
||||
if valid:
|
||||
return max(valid)
|
||||
return entry.get("created_at")
|
||||
|
||||
|
||||
def _skills_for_catalogue(storage):
|
||||
"""Use the warm prompt catalogue, and parse SKILL.md files only when it is cold."""
|
||||
from deerflow.agents.lead_agent.prompt import get_warm_enabled_skills
|
||||
|
||||
cached = get_warm_enabled_skills(storage)
|
||||
if cached is not None:
|
||||
return cached
|
||||
return storage.load_skills(enabled_only=True)
|
||||
|
||||
|
||||
def skill_list_impl(agent_id: str | None, extra_skills: list[str] | None = None) -> str:
|
||||
"""List skills visible to ``agent_id`` (None = default lead agent)."""
|
||||
from deerflow.skills.storage import get_or_new_skill_storage
|
||||
from deerflow.skills.types import SkillCategory
|
||||
from deerflow.skills.usage import STATE_ARCHIVED, all_entries, latest_activity_at
|
||||
from deerflow.skills.usage import STATE_ARCHIVED, all_entries
|
||||
|
||||
allowed = _load_agent_skill_whitelist(agent_id, extra_skills)
|
||||
|
||||
@@ -413,7 +442,7 @@ def skill_list_impl(agent_id: str | None, extra_skills: list[str] | None = None)
|
||||
|
||||
try:
|
||||
storage = get_or_new_skill_storage()
|
||||
skills = storage.load_skills(enabled_only=True)
|
||||
skills = _skills_for_catalogue(storage)
|
||||
usage = all_entries()
|
||||
result = []
|
||||
for skill in skills:
|
||||
@@ -440,7 +469,7 @@ def skill_list_impl(agent_id: str | None, extra_skills: list[str] | None = None)
|
||||
"use_count": entry.get("use_count", 0),
|
||||
"view_count": entry.get("view_count", 0),
|
||||
"patch_count": entry.get("patch_count", 0),
|
||||
"last_activity_at": latest_activity_at(skill.name),
|
||||
"last_activity_at": _latest_activity(entry),
|
||||
"pinned": entry.get("pinned", False),
|
||||
"source": entry.get("source", "upload"),
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user