feat: 新增岗位管理、提示词模板与资源标签,完善用户提示词与推荐问题接口
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
2f414c6e08
commit
3855c30edd
52 files changed
+3143
-57
No files matched your search
+73
@@ -0,0 +1,73 @@
|
||||
"""ORM models for 岗位 (positions) and their per-resource tag bindings.
|
||||
|
||||
A **position** (岗位) is an admin-managed aggregation layer that decides which
|
||||
agents / skills / scheduled tasks / custom prompts / recommended questions a
|
||||
user is subscribed to. Each user has at most one position (the link lives on
|
||||
``users.position_id``, a 1:1 relation — see ``UserRow``).
|
||||
|
||||
Two tables here:
|
||||
|
||||
- ``positions`` — the position itself. ``is_default`` marks the fallback
|
||||
position inherited by users who have not been assigned one explicitly.
|
||||
- ``position_tag_bindings`` — for each ``(position, resource_type)`` the set of
|
||||
tags whose resources are granted to the position's members. **No binding for
|
||||
a resource_type means "use the default set"** (see ``deerflow.services.
|
||||
position_sync`` for what "default" resolves to per type).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import UTC, datetime
|
||||
|
||||
from sqlalchemy import Boolean, Index, String, UniqueConstraint
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from deerflow.persistence.base import Base
|
||||
from deerflow.persistence.types import BeijingDateTime
|
||||
|
||||
# Resource types a position can grant. The first three reuse the existing
|
||||
# typed-tag namespace (``deerflow.persistence.tags``); ``user_prompt`` and
|
||||
# ``recommended_question`` are added by the same change (see TAG_TYPES).
|
||||
POSITION_RESOURCE_TYPES: tuple[str, ...] = (
|
||||
"agent",
|
||||
"skill",
|
||||
"scheduled_task",
|
||||
"user_prompt",
|
||||
"recommended_question",
|
||||
)
|
||||
|
||||
|
||||
class PositionRow(Base):
|
||||
__tablename__ = "positions"
|
||||
__table_args__ = (UniqueConstraint("name", name="uq_positions_name"),)
|
||||
|
||||
id: Mapped[str] = mapped_column(String(64), primary_key=True)
|
||||
name: Mapped[str] = mapped_column(String(191), nullable=False)
|
||||
description: Mapped[str] = mapped_column(String(1024), nullable=False, default="")
|
||||
# Exactly one position should carry ``is_default=True`` at a time (the
|
||||
# router enforces "only one default" by clearing the flag on others). Users
|
||||
# with no explicit ``users.position_id`` inherit this position's grants.
|
||||
is_default: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False, index=True)
|
||||
created_at: Mapped[datetime] = mapped_column(BeijingDateTime(), nullable=False, default=lambda: datetime.now(UTC))
|
||||
updated_at: Mapped[datetime] = mapped_column(BeijingDateTime(), nullable=False, default=lambda: datetime.now(UTC), onupdate=lambda: datetime.now(UTC))
|
||||
|
||||
|
||||
class PositionTagBindingRow(Base):
|
||||
"""One bound tag for a ``(position, resource_type)`` pair.
|
||||
|
||||
The absence of *any* row for a ``(position, resource_type)`` means the
|
||||
position uses the **default set** for that resource type. One or more rows
|
||||
mean the position grants the *union* of the resources carrying those tags.
|
||||
"""
|
||||
|
||||
__tablename__ = "position_tag_bindings"
|
||||
__table_args__ = (
|
||||
UniqueConstraint("position_id", "resource_type", "tag_id", name="uq_position_tag_bindings"),
|
||||
Index("ix_position_tag_bindings_position_type", "position_id", "resource_type"),
|
||||
)
|
||||
|
||||
id: Mapped[str] = mapped_column(String(64), primary_key=True)
|
||||
position_id: Mapped[str] = mapped_column(String(64), nullable=False, index=True)
|
||||
resource_type: Mapped[str] = mapped_column(String(32), nullable=False, index=True)
|
||||
tag_id: Mapped[str] = mapped_column(String(64), nullable=False, index=True)
|
||||
created_at: Mapped[datetime] = mapped_column(BeijingDateTime(), nullable=False, default=lambda: datetime.now(UTC))
|
||||
Reference in new issue
Block a user