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
@@ -95,6 +95,15 @@ class SkillStore(ABC):
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
async def list_name_zh(self, names: list[str]) -> dict[str, str]:
|
||||
"""Map skill names to their configured Chinese display names.
|
||||
|
||||
Only names that have a non-empty ``name_zh`` are returned. The default
|
||||
is empty so stores that have not implemented the lookup stay safe.
|
||||
"""
|
||||
del names
|
||||
return {}
|
||||
|
||||
@abstractmethod
|
||||
async def list_favorite_skill_names(self, user_id: str) -> set[str]:
|
||||
"""Return the skill names in ``user_id``'s "我的技能" collection.
|
||||
|
||||
+11
@@ -165,6 +165,17 @@ class MemorySkillStore(SkillStore):
|
||||
async def list_always_on_names(self) -> set[str]:
|
||||
return {name for name, record in self._skills.items() if record.get("always_on")}
|
||||
|
||||
async def list_name_zh(self, names: list[str]) -> dict[str, str]:
|
||||
labels: dict[str, str] = {}
|
||||
for name in names:
|
||||
record = self._skills.get(name)
|
||||
if record is None:
|
||||
continue
|
||||
label = str(record.get("name_zh") or "").strip()
|
||||
if label:
|
||||
labels[name] = label
|
||||
return labels
|
||||
|
||||
async def list_favorite_skill_names(self, user_id: str) -> set[str]:
|
||||
return set(self._favorites.get(user_id, set()))
|
||||
|
||||
|
||||
+36
-1
@@ -10,7 +10,7 @@ from __future__ import annotations
|
||||
|
||||
from datetime import UTC, datetime
|
||||
|
||||
from sqlalchemy import Boolean, DateTime, String, Text, UniqueConstraint
|
||||
from sqlalchemy import BigInteger, Boolean, DateTime, Index, Integer, String, Text, UniqueConstraint, text
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from deerflow.persistence.base import Base
|
||||
@@ -19,10 +19,30 @@ from deerflow.persistence.types import BeijingDateTime
|
||||
|
||||
class SkillRow(Base):
|
||||
__tablename__ = "skills"
|
||||
__table_args__ = (
|
||||
Index("ix_skills_catalog_available_category_created", "available", "category", "created_at"),
|
||||
)
|
||||
|
||||
# Global unique name — must match the on-disk folder name under skills/custom/.
|
||||
# Hyphen-case or snake_case allowed; see deerflow.skills.validation.
|
||||
name: Mapped[str] = mapped_column(String(64), primary_key=True)
|
||||
# Compact catalog projection fields. The list API reads these columns from
|
||||
# MySQL and deliberately excludes the long-form ``detail`` text column.
|
||||
category: Mapped[str] = mapped_column(String(16), nullable=False, default="custom", server_default="custom")
|
||||
description: Mapped[str] = mapped_column(String(1024), nullable=False, default="", server_default="")
|
||||
license: Mapped[str | None] = mapped_column(String(255), nullable=True, default=None)
|
||||
enabled: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True, server_default=text("1"))
|
||||
available: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True, server_default=text("1"), index=True)
|
||||
use_count: Mapped[int] = mapped_column(Integer, nullable=False, default=0, server_default=text("0"))
|
||||
view_count: Mapped[int] = mapped_column(Integer, nullable=False, default=0, server_default=text("0"))
|
||||
patch_count: Mapped[int] = mapped_column(Integer, nullable=False, default=0, server_default=text("0"))
|
||||
last_activity_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True, default=None)
|
||||
state: Mapped[str] = mapped_column(String(16), nullable=False, default="active", server_default="active")
|
||||
pinned: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False, server_default=text("0"))
|
||||
featured: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False, server_default=text("0"))
|
||||
source: Mapped[str] = mapped_column(String(16), nullable=False, default="upload", server_default="upload")
|
||||
source_mtime_ns: Mapped[int] = mapped_column(BigInteger, nullable=False, default=0, server_default=text("0"))
|
||||
detail_preview: Mapped[str | None] = mapped_column(String(1024), nullable=True, default=None)
|
||||
owner_user_id: Mapped[str | None] = mapped_column(String(64), nullable=True, index=True)
|
||||
published: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False, index=True)
|
||||
# Human-authored long-form detail/introduction, editable by the skill owner
|
||||
@@ -83,3 +103,18 @@ class SkillDisplayAdapterRow(Base):
|
||||
sample_payload: Mapped[str | None] = mapped_column(Text, nullable=True, default=None)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False, default=lambda: datetime.now(UTC))
|
||||
updated_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False, default=lambda: datetime.now(UTC), onupdate=lambda: datetime.now(UTC))
|
||||
|
||||
|
||||
class SkillCatalogSnapshotRow(Base):
|
||||
"""MySQL-backed projection of filesystem skill metadata for fast list APIs.
|
||||
|
||||
Skill source files remain the authoring format. The Gateway refreshes this
|
||||
one-row projection during startup so homepage listing requests do not scan
|
||||
every SKILL.md or read per-skill usage sidecars.
|
||||
"""
|
||||
|
||||
__tablename__ = "skill_catalog_snapshots"
|
||||
|
||||
cache_key: Mapped[str] = mapped_column(String(32), primary_key=True)
|
||||
catalog_json: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
updated_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False, default=lambda: datetime.now(UTC), onupdate=lambda: datetime.now(UTC))
|
||||
@@ -109,6 +109,7 @@ class SkillRepository(SkillStore):
|
||||
row.published = bool(data["published"])
|
||||
if "detail" in data:
|
||||
row.detail = data["detail"]
|
||||
row.detail_preview = (str(data["detail"] or "")[:1024] or None)
|
||||
if "name_zh" in data:
|
||||
row.name_zh = data["name_zh"]
|
||||
if "always_on" in data:
|
||||
@@ -131,6 +132,7 @@ class SkillRepository(SkillStore):
|
||||
row.owner_user_id = data["owner_user_id"]
|
||||
if "detail" in data:
|
||||
row.detail = data["detail"]
|
||||
row.detail_preview = (str(data["detail"] or "")[:1024] or None)
|
||||
if "name_zh" in data:
|
||||
row.name_zh = data["name_zh"]
|
||||
if "always_on" in data:
|
||||
@@ -183,6 +185,20 @@ class SkillRepository(SkillStore):
|
||||
result = await session.execute(stmt)
|
||||
return {row[0] for row in result.all()}
|
||||
|
||||
async def list_name_zh(self, names: list[str]) -> dict[str, str]:
|
||||
wanted = list(dict.fromkeys(name for name in names if name))
|
||||
if not wanted:
|
||||
return {}
|
||||
stmt = select(SkillRow.name, SkillRow.name_zh).where(SkillRow.name.in_(wanted))
|
||||
async with self._sf() as session:
|
||||
rows = (await session.execute(stmt)).all()
|
||||
labels: dict[str, str] = {}
|
||||
for name, name_zh in rows:
|
||||
label = (name_zh or "").strip()
|
||||
if label:
|
||||
labels[name] = label
|
||||
return labels
|
||||
|
||||
async def list_favorite_skill_names(self, user_id: str) -> set[str]:
|
||||
stmt = select(SkillFavoriteRow.skill_name).where(SkillFavoriteRow.user_id == user_id)
|
||||
async with self._sf() as session:
|
||||
|
||||
Reference in new issue
Block a user