sync update from LAN repo (source dhk-1 @ 3b1ec5b4)

This commit is contained in:
gozeros committed 2026-11-05 10:56:34 +08:00
1 parent da6521b6cb
commit 264e2200d6
995 files changed
+148105 -13399

No files matched your search

@@ -16,11 +16,13 @@ Routes (prefix ``/api/business-mapping``):
from __future__ import annotations
import logging
import re
from datetime import datetime
from fastapi import APIRouter, HTTPException, Request
from pydantic import BaseModel, Field
from app.gateway.catalog_cache import cached_catalog, invalidate_catalog
from app.gateway.deps import get_agent_store
from deerflow.runtime.user_context import get_effective_user_id
@@ -37,6 +39,8 @@ _EIGHTBF_MANAGER_USERNAME = "lqq"
class BusinessMappingResponse(BaseModel):
business_code: str
label: str = ""
mapping_type: str = "内置业务"
is_custom: bool = False
agent_id: str | None = None
agent_name: str | None = None
chain_id: str | None = None
@@ -58,6 +62,12 @@ class BusinessMappingUpdateRequest(BaseModel):
chain_title: str | None = Field(default=None, max_length=512)
class BusinessMappingCreateRequest(BaseModel):
"""The name is both the display name and login ``goPath`` for a custom row."""
name: str = Field(min_length=1, max_length=32)
# ── helpers ──────────────────────────────────────────────────────────────
@@ -95,6 +105,23 @@ def _current_user_id(request: Request) -> str:
return get_effective_user_id()
_RESERVED_GOPATHS = frozenset({"3qfx", "rwfx", "xdfx", "agentfx", "b5-1"})
def _normalise_custom_mapping_input(body: BusinessMappingCreateRequest) -> str:
"""Validate a custom goPath without rewriting the administrator's label."""
name = re.sub(r"\s+", " ", body.name).strip()
if not name:
raise HTTPException(status_code=422, detail="名称不能为空")
# ``-A`` is a mode suffix, not part of a configurable name: ``name`` is
# single-agent and ``name-A`` is the same mapping's business-chain entry.
if name.lower().endswith("-a"):
raise HTTPException(status_code=422, detail="自定义名称不能以 -A 结尾")
if name.lower() in _RESERVED_GOPATHS:
raise HTTPException(status_code=422, detail="该名称已被内置 goPath 保留")
return name
async def _validate_public_chain_mapping(
request: Request,
fields: dict[str, object],
@@ -167,8 +194,32 @@ async def _validate_public_chain_mapping(
@router.get("", response_model=BusinessMappingListResponse)
async def list_mappings(request: Request) -> BusinessMappingListResponse:
store = _get_store(request)
rows = await store.list_mappings()
return BusinessMappingListResponse(mappings=[BusinessMappingResponse(**r) for r in rows])
async def load() -> BusinessMappingListResponse:
rows = await store.list_mappings()
return BusinessMappingListResponse(mappings=[BusinessMappingResponse(**r) for r in rows])
return await cached_catalog(request, "business_mapping", "all", load, BusinessMappingListResponse)
@router.post("", response_model=BusinessMappingResponse, status_code=201)
async def create_mapping(
request: Request,
body: BusinessMappingCreateRequest,
) -> BusinessMappingResponse:
"""Create a globally shared custom mapping (administrator only)."""
if not _is_admin(request):
raise HTTPException(status_code=403, detail="Only administrators can create business mappings")
name = _normalise_custom_mapping_input(body)
store = _get_store(request)
row = await store.create_custom_mapping(
business_code=name,
mapping_type="自定义类型",
)
if row is None:
raise HTTPException(status_code=409, detail="该名称已存在,请换一个名称")
await invalidate_catalog(request, "business_mapping")
return BusinessMappingResponse(**row)
@router.put("/{business_code}", response_model=BusinessMappingResponse)
@@ -183,4 +234,5 @@ async def update_mapping(request: Request, business_code: str, body: BusinessMap
row = await store.update_mapping(business_code, **fields)
if row is None:
raise HTTPException(status_code=404, detail="Business mapping not found")
await invalidate_catalog(request, "business_mapping")
return BusinessMappingResponse(**row)