feat(square): 新增发布广场功能,智能体/技能按广场分类展示
- 后端新增 PublishSquare/PublishSquaresSettings 配置与读写接口 - agents/skills 增加 square_id 字段及对应迁移脚本 - 前端新增发布广场设置页、技能转移选择器,画廊按广场分 Tab 展示 - lead_agent prompt 及若干持久化层适配调整 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
3845d5090b
commit
f0aec4cd7f
39 files changed
+1707
-226
No files matched your search
@@ -14,8 +14,12 @@ from deerflow.config import get_app_config
|
||||
from deerflow.config.system_settings import (
|
||||
LeaderboardSettings,
|
||||
PromptPrefixSettings,
|
||||
PublishSquare,
|
||||
PublishSquaresSettings,
|
||||
SystemSettings,
|
||||
list_publish_squares,
|
||||
load_system_settings,
|
||||
resolve_default_square_id,
|
||||
save_system_settings,
|
||||
)
|
||||
|
||||
@@ -219,6 +223,88 @@ async def update_private_square(body: PrivateSquareUpdateRequest, request: Reque
|
||||
)
|
||||
|
||||
|
||||
class PublishSquareItem(BaseModel):
|
||||
id: str = Field(..., description="Stable square id")
|
||||
name: str = Field(..., description="Display name / tab label")
|
||||
description: str = Field(default="", description="Optional description")
|
||||
|
||||
|
||||
class PublishSquaresResponse(BaseModel):
|
||||
"""The configured publish squares plus the resolved default.
|
||||
|
||||
Readable by any logged-in user — squares are pure category tabs with no
|
||||
access control, so the gallery needs the list to render its sub-tabs and
|
||||
the publish flow needs it to populate the square picker.
|
||||
"""
|
||||
|
||||
squares: list[PublishSquareItem] = Field(default_factory=list)
|
||||
default_square_id: str = Field(..., description="Square id used when a publisher picks none")
|
||||
|
||||
|
||||
class PublishSquaresUpdateRequest(BaseModel):
|
||||
squares: list[PublishSquareItem] | None = Field(default=None, description="Full ordered replacement list of squares")
|
||||
default_square_id: str | None = Field(default=None, description="Which square id is the publish default")
|
||||
|
||||
|
||||
def _publish_squares_response(settings: PublishSquaresSettings) -> PublishSquaresResponse:
|
||||
squares = list_publish_squares(settings)
|
||||
return PublishSquaresResponse(
|
||||
squares=[PublishSquareItem(id=s.id, name=s.name, description=s.description) for s in squares],
|
||||
default_square_id=resolve_default_square_id(settings),
|
||||
)
|
||||
|
||||
|
||||
@router.get("/publish-squares", response_model=PublishSquaresResponse)
|
||||
async def get_publish_squares() -> PublishSquaresResponse:
|
||||
"""Return the configured publish squares (readable by any logged-in user)."""
|
||||
return _publish_squares_response(load_system_settings().publish_squares)
|
||||
|
||||
|
||||
@router.put("/publish-squares", response_model=PublishSquaresResponse)
|
||||
async def update_publish_squares(body: PublishSquaresUpdateRequest, request: Request) -> PublishSquaresResponse:
|
||||
"""Replace the publish-squares configuration. Admin only.
|
||||
|
||||
``squares`` is a full ordered replacement. Each square needs a non-empty
|
||||
name; a missing id is auto-generated from a slug of the name. Duplicate ids
|
||||
are de-duplicated (first wins). ``default_square_id`` must reference one of
|
||||
the surviving squares, else it falls back to the first.
|
||||
"""
|
||||
from uuid import uuid4
|
||||
|
||||
await _require_admin(request)
|
||||
|
||||
current = load_system_settings()
|
||||
fields = body.model_dump(exclude_unset=True)
|
||||
update: dict[str, object] = {}
|
||||
|
||||
if "squares" in fields and fields["squares"] is not None:
|
||||
normalized: list[PublishSquare] = []
|
||||
seen_ids: set[str] = set()
|
||||
for raw in body.squares or []:
|
||||
name = (raw.name or "").strip()
|
||||
if not name:
|
||||
continue
|
||||
sid = (raw.id or "").strip() or uuid4().hex[:8]
|
||||
if sid in seen_ids:
|
||||
continue
|
||||
seen_ids.add(sid)
|
||||
normalized.append(PublishSquare(id=sid, name=name, description=(raw.description or "").strip()))
|
||||
update["squares"] = normalized
|
||||
|
||||
if "default_square_id" in fields and fields["default_square_id"] is not None:
|
||||
update["default_square_id"] = str(fields["default_square_id"]).strip()
|
||||
|
||||
if update:
|
||||
updated = current.publish_squares.model_copy(update=update)
|
||||
# Re-anchor the default to a surviving square id.
|
||||
if updated.squares and updated.default_square_id not in {s.id for s in updated.squares}:
|
||||
updated = updated.model_copy(update={"default_square_id": updated.squares[0].id})
|
||||
saved = save_system_settings(current.model_copy(update={"publish_squares": updated}))
|
||||
else:
|
||||
saved = current
|
||||
return _publish_squares_response(saved.publish_squares)
|
||||
|
||||
|
||||
class AppearanceResponse(BaseModel):
|
||||
"""Effective system-wide appearance defaults."""
|
||||
|
||||
|
||||
Reference in new issue
Block a user