feat: 技能收藏与常驻(always-on)支持

- 新增 skill_favorites / skill_always_on 迁移与持久化模型字段
- skills 路由、存储、前端设置页支持收藏与常驻
- 调整摘要中间件与 lead agent 提示词
- 同步岗位 position_sync 及相关配置清理

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
吉鑫升andClaude Opus 4.8 committed 2026-06-16 16:37:43 +08:00
1 parent 5ebbb82d66
commit 5182ea5d11
19 files changed
+472 -107

No files matched your search

@@ -1,9 +1,9 @@
"""岗位 (position) → resource subscription **sync engine**.
A user's position decides which agents / scheduled tasks / custom prompts they
are subscribed to, and which skills / recommended questions they can see. This
service turns a position's *tag bindings* into concrete, materialized rows in
the existing "我的" tables (idempotent, re-runnable).
A user's position decides which agents / skills / scheduled tasks they are
subscribed to, and which recommended questions they can see. This service turns
a position's *tag bindings* into concrete, materialized rows in the existing
"我的" tables (idempotent, re-runnable).
Resolution rule (per resource type):
@@ -14,15 +14,19 @@ Resolution rule (per resource type):
* For a resource type **without** bound tags → the *default set*:
- ``agent`` → all built-in agents (``user_id IS NULL``)
- ``scheduled_task`` → empty (no built-in tasks)
- ``skill`` / ``recommended_question`` → *unrestricted* (handled at query
time, never materialized — see :meth:`resolve_visible`)
- ``skill`` → empty (the 广场 still shows every visible skill;
a position only *adds* its tagged skills to the member's "我的技能")
- ``recommended_question`` → *unrestricted* (handled at query time, never
materialized — see :meth:`resolve_visible`)
Materialization (``sync_user``) only ever touches rows it created itself
(``origin='position'``), so a user's own favorites / subscriptions are never
clobbered. The skill + recommended-question visibility filters are computed live
by :meth:`resolve_visible` and are *not* materialized. (The admin-configured
prompts shown to users ARE the recommended questions — there is no separate
prompt-template store.)
clobbered. ``skill`` is materialized into ``skill_favorites`` exactly like
``agent`` → ``agent_favorites``: the tagged skills are *added* to the user's
"我的技能" while the browse-all 广场 stays complete (it is **not** restricted).
Only recommended-question visibility is computed live by :meth:`resolve_visible`
and is *not* materialized. (The admin-configured prompts shown to users ARE the
recommended questions — there is no separate prompt-template store.)
"""
from __future__ import annotations
@@ -37,14 +41,15 @@ from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker
from deerflow.persistence.agents.model import AgentFavoriteRow, AgentRow
from deerflow.persistence.positions.base import PositionStore
from deerflow.persistence.scheduled_tasks.model import ScheduledTaskSubscriptionRow
from deerflow.persistence.skills.model import SkillFavoriteRow
from deerflow.persistence.tags.base import TagStore
logger = logging.getLogger(__name__)
# Materialized into "我的" tables by sync_user.
_MATERIALIZED_TYPES = ("agent", "scheduled_task")
_MATERIALIZED_TYPES = ("agent", "skill", "scheduled_task")
# Resolved live at query time (visibility filters), never materialized.
_VISIBILITY_TYPES = ("skill", "recommended_question")
_VISIBILITY_TYPES = ("recommended_question",)
class PositionSyncService:
@@ -64,9 +69,10 @@ class PositionSyncService:
async def resolve_visible(self, user_id: str, resource_type: str) -> set[str] | None:
"""Return the set of visible ``resource_type`` ids, or ``None`` = unrestricted.
Used by the skills list + recommended-questions filters. ``None`` means
"no position restriction → show everything"; a set means "restrict to
exactly these ids".
Used by the recommended-questions filter (the only remaining query-time
visibility type; skills are now *materialized*, not filtered). ``None``
means "no position restriction → show everything"; a set means "restrict
to exactly these ids".
"""
pid = await self._effective_position_id(user_id)
if not pid:
@@ -101,6 +107,7 @@ class PositionSyncService:
pid = await self._effective_position_id(user_id)
async with self._sf() as session:
await self._sync_agents(session, user_id, pid)
await self._sync_skills(session, user_id, pid)
await self._sync_tasks(session, user_id, pid)
await session.commit()
@@ -116,6 +123,18 @@ class PositionSyncService:
if agent_id not in target:
await session.delete(row)
async def _sync_skills(self, session: AsyncSession, user_id: str, position_id: str | None) -> None:
target = await self._resolve_materialized(user_id, "skill", session)
rows = list((await session.execute(select(SkillFavoriteRow).where(SkillFavoriteRow.user_id == user_id))).scalars())
owned_any = {r.skill_name for r in rows}
position_rows = {r.skill_name: r for r in rows if r.origin == "position"}
now = datetime.now(UTC)
for skill_name in target - owned_any:
session.add(SkillFavoriteRow(id=uuid.uuid4().hex, user_id=user_id, skill_name=skill_name, origin="position", position_id=position_id, created_at=now))
for skill_name, row in position_rows.items():
if skill_name not in target:
await session.delete(row)
async def _sync_tasks(self, session: AsyncSession, user_id: str, position_id: str | None) -> None:
target = await self._resolve_materialized(user_id, "scheduled_task", session)
rows = list((await session.execute(select(ScheduledTaskSubscriptionRow).where(ScheduledTaskSubscriptionRow.user_id == user_id))).scalars())