feat(skills/notifications): 多租户阶段 1 — 持久化层
新增两套 persistence 模块,仿 persistence/agents/ 模板:
1. persistence/skills/
- SkillRow ORM (PK=name, owner_user_id, published, timestamps)
- SkillStore 抽象:list_visible / get_visible / get_any /
get_owned / create / ensure_legacy / update / update_admin /
delete / delete_admin
- SqlAlchemy 实现 SkillRepository
- MemorySkillStore 用于测试
- 可见性 = owner OR published OR builtin
2. persistence/notifications/
- NotificationRow ORM (id, user_id, type, title, body, payload JSON,
read, created_at)
- NotificationStore 抽象:create / list_for_user / unread_count /
mark_read / mark_all_read / delete
- SqlAlchemy 实现 NotificationRepository
- MemoryNotificationStore 用于测试
- sender.notify(user_id, type, ...) 全局接口;harness 不能 import
app.*,所以用 set_notification_store / get_notification_store
注入模式
3. persistence/models/__init__.py 注册 SkillRow + NotificationRow
后续阶段会接入路由、cascade、curator per-user 重构、前端。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
f5bc02d598
commit
8162719e36
12 files changed
+692
No files matched your search
@@ -0,0 +1,64 @@
|
||||
"""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
|
||||
Reference in new issue
Block a user