- 「设置和更多」新增「智能体管理」「技能管理」入口,与定时任务管理同级; 独立的 AdminAgentsPage/AdminSkillsPage 复用 AgentCard/SkillRow, 管理员可查看并编辑/删除所有用户的智能体与技能。 - 后端 /api/agents、/api/skills 增加 ?admin=true 越权列表;agents 端 放宽 _get_editable_or_raise 让管理员可编辑/删除任意智能体;新增 list_all/update_any/delete_any(agents)与 list_all(skills)。 - 新增 AuthSyncWatcher:监听 localStorage["deerflow.auth"] 的 storage 事件,user_id 变化时自动 reload,修复多标签切换登录后老页面点击 「新对话」偶发 404 的问题。 - LLMErrorHandlingMiddleware 将 bad_response_status_code / JSON decode 等上游网关乱码识别为可重试的 upstream 类故障。 - 侧边栏「任务管理」改名为「定时任务」。 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
88 lines
3.2 KiB
Python
88 lines
3.2 KiB
Python
"""Abstract persistence API for custom skill ownership + publish state."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from abc import ABC, abstractmethod
|
|
from typing import Any
|
|
|
|
|
|
class SkillStore(ABC):
|
|
@abstractmethod
|
|
async def list_visible(self, user_id: str) -> list[dict[str, Any]]:
|
|
"""List all skill records visible to ``user_id``.
|
|
|
|
Visible = owner, OR published by anyone, OR built-in (owner_user_id IS NULL).
|
|
"""
|
|
raise NotImplementedError
|
|
|
|
@abstractmethod
|
|
async def get_visible(self, name: str, user_id: str) -> dict[str, Any] | None:
|
|
raise NotImplementedError
|
|
|
|
@abstractmethod
|
|
async def get_any(self, name: str) -> dict[str, Any] | None:
|
|
"""Lookup by name regardless of ownership/visibility (admin / cascade use)."""
|
|
raise NotImplementedError
|
|
|
|
@abstractmethod
|
|
async def get_owned(self, name: str, user_id: str) -> dict[str, Any] | None:
|
|
raise NotImplementedError
|
|
|
|
@abstractmethod
|
|
async def create(self, data: dict[str, Any]) -> dict[str, Any]:
|
|
"""Create a skill record. Caller is responsible for global-name uniqueness check."""
|
|
raise NotImplementedError
|
|
|
|
@abstractmethod
|
|
async def ensure_legacy(self, data: dict[str, Any]) -> dict[str, Any]:
|
|
"""Idempotently insert a legacy on-disk skill into the DB. Updates the row if it
|
|
already exists with ``owner_user_id IS NULL`` (so a re-run can migrate ownership).
|
|
"""
|
|
raise NotImplementedError
|
|
|
|
@abstractmethod
|
|
async def update(self, name: str, user_id: str, data: dict[str, Any]) -> dict[str, Any] | None:
|
|
"""Owner-only update. Returns None if the caller doesn't own the skill."""
|
|
raise NotImplementedError
|
|
|
|
@abstractmethod
|
|
async def update_admin(self, name: str, data: dict[str, Any]) -> dict[str, Any] | None:
|
|
"""Admin override — caller is responsible for auth check.
|
|
|
|
Unlike ``update_builtin`` for agents, this accepts ANY skill including
|
|
user-owned ones, since the spec lets admin take down others' skills.
|
|
"""
|
|
raise NotImplementedError
|
|
|
|
@abstractmethod
|
|
async def delete(self, name: str, user_id: str) -> bool:
|
|
raise NotImplementedError
|
|
|
|
@abstractmethod
|
|
async def delete_admin(self, name: str) -> bool:
|
|
"""Admin-side delete; bypasses ownership check (caller authorizes)."""
|
|
raise NotImplementedError
|
|
|
|
@abstractmethod
|
|
async def count_owned(self, user_id: str) -> int:
|
|
"""Return the number of skills owned by ``user_id`` (owner_user_id IS NOT NULL)."""
|
|
raise NotImplementedError
|
|
|
|
@abstractmethod
|
|
async def list_all(self) -> list[dict[str, Any]]:
|
|
"""Return every skill record regardless of ownership/visibility.
|
|
|
|
Caller is responsible for authorization (admin only).
|
|
"""
|
|
raise NotImplementedError
|
|
|
|
@abstractmethod
|
|
async def list_published_names(self) -> set[str]:
|
|
"""Return the set of skill names with ``published = True`` (any owner).
|
|
|
|
Batch alternative to calling ``get_any`` per skill — the curator uses
|
|
this to filter out published skills in a single query instead of one
|
|
DB round-trip per candidate skill.
|
|
"""
|
|
raise NotImplementedError
|