- agents 表新增 is_private 列与迁移 20260526_01;列表 filter 拆分为公开
广场用的 _listing_filter(剔除私密)与单条访问用的 _visible_filter(保留可达)
- system_settings 增 PrivateSquareSettings(enabled + password_hash),
对应 GET/PUT /api/system-settings/private-square 由管理员管理
- /api/agents 接口:列表/创建/更新新增 is_private 字段;新增
POST /api/agents/private-square/list(密码校验后返回私密智能体)与
PUT /api/agents/{id}/private(管理员跨用户搬动智能体)
- 前端「智能体」页签新增「私密广场」入口(密码校验 + sessionStorage 缓存 +
锁定按钮),卡片增加紫色私密徽章与盾牌切换按钮(owner 自助 / 管理员跨用户),
「广场」与首页推荐候选均剔除私密智能体
- 新增管理员配置页 /settings/private-square 与侧边栏入口
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
93 lines
3.4 KiB
Python
93 lines
3.4 KiB
Python
"""Abstract persistence API for custom agents."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from abc import ABC, abstractmethod
|
|
from typing import Any
|
|
|
|
|
|
class AgentStore(ABC):
|
|
@abstractmethod
|
|
async def list_visible(self, user_id: str) -> list[dict[str, Any]]:
|
|
raise NotImplementedError
|
|
|
|
@abstractmethod
|
|
async def get_visible(self, agent_id: str, user_id: str) -> dict[str, Any] | None:
|
|
raise NotImplementedError
|
|
|
|
@abstractmethod
|
|
async def get_any(self, agent_id: str) -> dict[str, Any] | None:
|
|
raise NotImplementedError
|
|
|
|
@abstractmethod
|
|
async def get_owned(self, agent_id: str, user_id: str) -> dict[str, Any] | None:
|
|
raise NotImplementedError
|
|
|
|
@abstractmethod
|
|
async def create(self, data: dict[str, Any]) -> dict[str, Any]:
|
|
raise NotImplementedError
|
|
|
|
@abstractmethod
|
|
async def ensure_builtin(self, data: dict[str, Any]) -> dict[str, Any]:
|
|
raise NotImplementedError
|
|
|
|
@abstractmethod
|
|
async def update(self, agent_id: str, user_id: str, data: dict[str, Any]) -> dict[str, Any] | None:
|
|
raise NotImplementedError
|
|
|
|
@abstractmethod
|
|
async def update_builtin(self, agent_id: str, data: dict[str, Any]) -> dict[str, Any] | None:
|
|
"""Update a built-in agent (user_id IS NULL).
|
|
|
|
Caller is responsible for authorization — this method does NOT check
|
|
any user identity and returns ``None`` if the target is not a built-in.
|
|
"""
|
|
raise NotImplementedError
|
|
|
|
@abstractmethod
|
|
async def delete(self, agent_id: str, user_id: str) -> bool:
|
|
raise NotImplementedError
|
|
|
|
@abstractmethod
|
|
async def delete_builtin(self, agent_id: str) -> bool:
|
|
"""Delete a built-in agent (user_id IS NULL).
|
|
|
|
Caller is responsible for authorization — this method does NOT check
|
|
any user identity and returns ``False`` if the target is not a built-in.
|
|
"""
|
|
raise NotImplementedError
|
|
|
|
@abstractmethod
|
|
async def count_owned(self, user_id: str) -> int:
|
|
"""Return the number of agents owned by ``user_id`` (user_id IS NOT NULL)."""
|
|
raise NotImplementedError
|
|
|
|
@abstractmethod
|
|
async def set_featured(self, agent_id: str, order: int | None) -> dict[str, Any] | None:
|
|
"""Set or clear the homepage-selector featured rank for an agent.
|
|
|
|
Returns the updated row, or ``None`` if the agent does not exist.
|
|
Caller is responsible for authorization (admin) and for verifying
|
|
that ``published`` is true when ``order`` is not ``None``.
|
|
"""
|
|
raise NotImplementedError
|
|
|
|
@abstractmethod
|
|
async def list_featured(self, user_id: str) -> list[dict[str, Any]]:
|
|
"""Return featured + still-visible-to-``user_id`` agents, ordered by ``featured_order`` asc."""
|
|
raise NotImplementedError
|
|
|
|
@abstractmethod
|
|
async def list_by_ids(self, agent_ids: list[str], user_id: str) -> list[dict[str, Any]]:
|
|
"""Return rows for ``agent_ids`` visible to ``user_id``, preserving the input order."""
|
|
raise NotImplementedError
|
|
|
|
@abstractmethod
|
|
async def list_private(self) -> list[dict[str, Any]]:
|
|
"""Return every agent flagged ``is_private=True``.
|
|
|
|
Caller is responsible for authorization — typically the caller has
|
|
already verified the admin-configured private-square password.
|
|
"""
|
|
raise NotImplementedError
|