feat(agents): 内置智能体筛选(仅管理员)+ 内置 agent 默认用途标签

- 后端 scope=builtin(user_id IS NULL)加入 sql/memory 的 scope 过滤;
  /api/agents 扩展 scope 正则并加 admin 闸门(非管理员请求 403)
- 新增 _builtin_agent_tag_seed:启动时幂等给功能型内置 agent 按用途打标签
  (roundtable-* → 多智能体规划,ai-writing-* → AI写作),只追加不覆盖;
  无用途的内置 agent 不打标签
- 前端 agent-gallery 新增「内置智能体」Tab(仅 system_role==admin 可见),
  scope 类型在 api.ts/hooks.ts 同步

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
董宏凯andClaude Opus 4.8 committed 2026-06-13 20:42:26 +08:00
1 parent 391409b6c0
commit cd3a71baab
8 files changed
+163 -9

No files matched your search

@@ -587,8 +587,8 @@ async def list_agents(
tag_ids: list[str] | None = Query(default=None, description="Keep agents carrying any of these tags (OR)"),
scope: str | None = Query(
default=None,
pattern="^(mine|square)$",
description="Pagination scope. 'mine' = owned + favorited; 'square' = built-in/published public. Omit for the default combined visibility list.",
pattern="^(mine|square|builtin)$",
description="Pagination scope. 'mine' = owned + favorited; 'square' = built-in/published public; 'builtin' = 内置智能体 (user_id IS NULL, **admin only**). Omit for the default combined visibility list.",
),
page: int | None = Query(default=None, ge=1, description="1-based page index. Providing this (or 'scope') enables server-side pagination."),
page_size: int = Query(default=20, ge=1, le=200, description="Items per page when paginating."),
@@ -623,6 +623,9 @@ async def list_agents(
user_id = _current_user_id(request)
if admin and not _is_admin_user(request):
raise HTTPException(status_code=403, detail="Only system admins can list all agents")
# 「内置智能体」筛选仅限管理员(普通用户不应看到全部内置/功能型 agent 目录)。
if scope == "builtin" and not _is_admin_user(request):
raise HTTPException(status_code=403, detail="Only system admins can list built-in agents")
paginate = scope is not None or page is not None
square_id = square.strip() if square and square.strip() else None