Merge branch 'ji' into master
# Conflicts: # offline-backend-20260512/backend/CLAUDE.md # offline-backend-20260512/backend/app/gateway/app.py # offline-backend-20260512/backend/app/gateway/deps.py
This commit is contained in:
commit
77aa895a70
30 files changed
+1710
-176
No files matched your search
@@ -71,6 +71,7 @@ from app.gateway.routers import (
|
||||
suggestions,
|
||||
system_settings,
|
||||
tags,
|
||||
task_buttons,
|
||||
thread_runs,
|
||||
tool_metrics,
|
||||
thread_shares,
|
||||
@@ -1356,6 +1357,9 @@ This gateway provides custom endpoints for models, MCP configuration, skills, an
|
||||
# 大屏绘制智能体独立页面会话(按 taskId 存取,不分权)at /api/dashboard-sessions
|
||||
app.include_router(dashboard_sessions.router)
|
||||
|
||||
# Task-workspace configurable jump buttons (按钮管理) at /api/task-buttons
|
||||
app.include_router(task_buttons.router)
|
||||
|
||||
# Standalone parallel multi-agent panel: fan-out streaming + saved tasks
|
||||
app.include_router(parallel_agents.router)
|
||||
app.include_router(parallel_agent_tasks.router)
|
||||
|
||||
@@ -251,6 +251,10 @@ async def langgraph_runtime(app: FastAPI) -> AsyncGenerator[None, None]:
|
||||
|
||||
app.state.dashboard_session_store = make_dashboard_session_store(sf)
|
||||
|
||||
from deerflow.persistence.task_buttons import make_task_button_store
|
||||
|
||||
app.state.task_button_store = make_task_button_store(sf)
|
||||
|
||||
from deerflow.persistence.parallel_agent_tasks import make_parallel_agent_task_store
|
||||
|
||||
app.state.parallel_agent_task_store = make_parallel_agent_task_store(sf)
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
"""Task-workspace configurable jump-button API (按钮管理).
|
||||
|
||||
The task deep-link workspaces (rwfx / 3qfx / xdfx, see the frontend
|
||||
``TaskFxWorkspace``) render configurable jump buttons in their left task panel.
|
||||
Their default targets historically lived in ``config.yaml`` ``task_deeplink`` and
|
||||
their names were hardcoded; this router persists a **global / shared** button
|
||||
set the frontend renders instead, so an admin can rename / retarget / add /
|
||||
remove jump buttons per business.
|
||||
|
||||
When the table is empty (fresh deployment, never saved) the frontend falls back
|
||||
to code-defined seed defaults built from the live task-deeplink config; once
|
||||
saved, this table is the source of truth.
|
||||
|
||||
Reads are open to any authenticated user (the workspace needs them); the whole
|
||||
button set is replaced atomically and only by an admin.
|
||||
|
||||
Routes (prefix ``/api/task-buttons``):
|
||||
GET "" list all buttons
|
||||
PUT "" replace the entire button set (admin)
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from fastapi import APIRouter, HTTPException, Request
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from app.gateway.deps import get_current_user, get_optional_user_from_request
|
||||
from deerflow.persistence.task_buttons import TaskButtonStore
|
||||
|
||||
router = APIRouter(prefix="/api/task-buttons", tags=["task-buttons"])
|
||||
|
||||
|
||||
# ── schemas ──────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
class TaskButton(BaseModel):
|
||||
id: str = Field(..., min_length=1, max_length=128)
|
||||
business: str = Field(..., min_length=1, max_length=32)
|
||||
label: str = Field(default="", max_length=255)
|
||||
link_type: str = Field(default="url", max_length=16)
|
||||
target: str = Field(default="", max_length=1024)
|
||||
append_task_id: bool = True
|
||||
# 追加的查询参数名(如 id / task_id)。
|
||||
id_param: str = Field(default="id", max_length=64)
|
||||
# task=任务id(默认)/ action=行动id(仅 xdfx 二者不同)。
|
||||
id_kind: str = Field(default="task", max_length=16)
|
||||
enabled: bool = True
|
||||
sort_order: int = 0
|
||||
|
||||
|
||||
class TaskButtonResponse(TaskButton):
|
||||
updated_by: str | None = None
|
||||
updated_at: datetime | str | None = None
|
||||
|
||||
|
||||
class TaskButtonListResponse(BaseModel):
|
||||
buttons: list[TaskButtonResponse]
|
||||
|
||||
|
||||
class TaskButtonReplaceRequest(BaseModel):
|
||||
buttons: list[TaskButton] = Field(default_factory=list)
|
||||
|
||||
|
||||
# ── helpers ──────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
def _get_store(request: Request) -> TaskButtonStore:
|
||||
store = getattr(request.app.state, "task_button_store", None)
|
||||
if store is None:
|
||||
raise HTTPException(status_code=503, detail="Task button store not available")
|
||||
return store
|
||||
|
||||
|
||||
async def _require_admin(request: Request) -> None:
|
||||
"""Reject non-admins. Lets the call through when auth is disabled."""
|
||||
user = await get_optional_user_from_request(request)
|
||||
if user is None:
|
||||
return
|
||||
if getattr(user, "system_role", None) != "admin":
|
||||
raise HTTPException(status_code=403, detail="按钮管理仅限管理员")
|
||||
|
||||
|
||||
# ── routes ───────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
@router.get("", response_model=TaskButtonListResponse)
|
||||
async def list_task_buttons(request: Request) -> TaskButtonListResponse:
|
||||
store = _get_store(request)
|
||||
rows = await store.list_buttons()
|
||||
return TaskButtonListResponse(buttons=[TaskButtonResponse(**r) for r in rows])
|
||||
|
||||
|
||||
@router.put("", response_model=TaskButtonListResponse)
|
||||
async def replace_task_buttons(request: Request, body: TaskButtonReplaceRequest) -> TaskButtonListResponse:
|
||||
await _require_admin(request)
|
||||
store = _get_store(request)
|
||||
user_id = await get_current_user(request)
|
||||
rows = await store.replace_all(
|
||||
[b.model_dump() for b in body.buttons],
|
||||
updated_by=user_id,
|
||||
)
|
||||
return TaskButtonListResponse(buttons=[TaskButtonResponse(**r) for r in rows])
|
||||
Reference in new issue
Block a user