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

This commit is contained in:
gozeros committed 2026-10-21 15:06:08 +08:00
1 parent ab6068a7c1
commit 42f2a26fa8
1482 files changed
+227759 -9584

No files matched your search

@@ -26,6 +26,8 @@ from deerflow.config.system_settings import (
PublishSquare,
PublishSquaresSettings,
SkillCompressionSettings,
StrategyProjectSettings,
WriteFileCompatibilitySettings,
get_module_tag_ids,
list_publish_squares,
load_system_settings,
@@ -60,6 +62,14 @@ class OrdinaryKnowledgeLanding(BaseModel):
mode: Literal["wiki", "weknora"] = "wiki"
class StrategyProjectSettingsResponse(BaseModel):
taiwan_strait_demo_enabled: bool = False
class StrategyProjectSettingsUpdateRequest(BaseModel):
taiwan_strait_demo_enabled: bool | None = None
@router.get("/ordinary-knowledge-landing", response_model=OrdinaryKnowledgeLanding)
async def get_ordinary_knowledge_landing() -> OrdinaryKnowledgeLanding:
return OrdinaryKnowledgeLanding(mode=load_system_settings().ordinary_knowledge_landing)
@@ -72,6 +82,35 @@ async def update_ordinary_knowledge_landing(body: OrdinaryKnowledgeLanding, requ
return OrdinaryKnowledgeLanding(mode=saved.ordinary_knowledge_landing)
def _strategy_project_settings_response(
settings: StrategyProjectSettings,
) -> StrategyProjectSettingsResponse:
return StrategyProjectSettingsResponse(
taiwan_strait_demo_enabled=settings.taiwan_strait_demo_enabled,
)
@router.get("/strategy-projects", response_model=StrategyProjectSettingsResponse)
async def get_strategy_project_settings() -> StrategyProjectSettingsResponse:
"""Return project-demo visibility. Any logged-in user may read it."""
return _strategy_project_settings_response(load_system_settings().strategy_projects)
@router.put("/strategy-projects", response_model=StrategyProjectSettingsResponse)
async def update_strategy_project_settings(
body: StrategyProjectSettingsUpdateRequest,
request: Request,
) -> StrategyProjectSettingsResponse:
"""Update project-demo visibility. Admin only."""
await _require_admin(request)
current = load_system_settings()
fields = body.model_dump(exclude_unset=True, exclude_none=True)
updated = current.strategy_projects.model_copy(update=fields)
saved = save_system_settings(current.model_copy(update={"strategy_projects": updated}))
return _strategy_project_settings_response(saved.strategy_projects)
class PromptPrefixUpdateRequest(BaseModel):
enabled: bool | None = None
switch_label: str | None = None
@@ -181,6 +220,30 @@ async def _require_admin(request: Request) -> None:
raise HTTPException(status_code=403, detail="System settings can only be modified by an admin")
_WX_COMMON_AGENTS_MANAGER_USERNAME = "wx"
def _username_of(user: object) -> str:
"""Resolve the trusted account name from the authenticated user's email."""
email = getattr(user, "email", None) or ""
return str(email).split("@", 1)[0].strip().lower()
async def _require_wx_common_agents_manager(request: Request) -> None:
"""Allow wx (and administrators) to choose the shared wx category."""
user = await get_optional_user_from_request(request)
if user is None:
return
if getattr(user, "system_role", None) == "admin":
return
if _username_of(user) == _WX_COMMON_AGENTS_MANAGER_USERNAME:
return
raise HTTPException(
status_code=403,
detail="Only an admin or the wx account can modify the wx common agents",
)
@router.get("/prompt-prefix", response_model=PromptPrefixResponse)
async def get_prompt_prefix() -> PromptPrefixResponse:
"""Return the current prompt-prefix configuration (readable by any user)."""
@@ -280,6 +343,81 @@ class ModelConcurrencyUpdateRequest(BaseModel):
user_model_limits: dict[str, int] | None = None
class MemoryRuntimeResponse(BaseModel):
enabled: bool = Field(
default=False,
description="Whether generic/personal Q&A memory is enabled deployment-wide",
)
class MemoryRuntimeUpdateRequest(BaseModel):
enabled: bool
class WriteFileCompatibilityResponse(BaseModel):
enabled: bool = Field(
default=False,
description=(
"Whether all compatible models use the buffered-gateway "
"write_file transport"
),
)
class WriteFileCompatibilityUpdateRequest(BaseModel):
enabled: bool
@router.get("/memory", response_model=MemoryRuntimeResponse)
async def get_memory_runtime_setting() -> MemoryRuntimeResponse:
return MemoryRuntimeResponse(enabled=load_system_settings().memory.enabled)
@router.put("/memory", response_model=MemoryRuntimeResponse)
async def update_memory_runtime_setting(
body: MemoryRuntimeUpdateRequest,
request: Request,
) -> MemoryRuntimeResponse:
await _require_admin(request)
current = load_system_settings()
updated = current.memory.model_copy(update={"enabled": body.enabled})
saved = save_system_settings(current.model_copy(update={"memory": updated}))
logger.info("Q&A memory runtime switch changed: enabled=%s", saved.memory.enabled)
return MemoryRuntimeResponse(enabled=saved.memory.enabled)
@router.get(
"/write-file-compatibility",
response_model=WriteFileCompatibilityResponse,
)
async def get_write_file_compatibility_setting() -> WriteFileCompatibilityResponse:
settings = load_system_settings().write_file_compatibility
return WriteFileCompatibilityResponse(enabled=settings.enabled)
@router.put(
"/write-file-compatibility",
response_model=WriteFileCompatibilityResponse,
)
async def update_write_file_compatibility_setting(
body: WriteFileCompatibilityUpdateRequest,
request: Request,
) -> WriteFileCompatibilityResponse:
await _require_admin(request)
current = load_system_settings()
updated = WriteFileCompatibilitySettings(enabled=body.enabled)
saved = save_system_settings(
current.model_copy(update={"write_file_compatibility": updated})
)
logger.info(
"Global write_file buffered-gateway switch changed: enabled=%s",
saved.write_file_compatibility.enabled,
)
return WriteFileCompatibilityResponse(
enabled=saved.write_file_compatibility.enabled
)
def _skill_compression_to_response(settings: SkillCompressionSettings) -> SkillCompressionResponse:
return SkillCompressionResponse(
enabled=settings.enabled,
@@ -810,6 +948,16 @@ class AgentModuleConfigUpdateRequest(BaseModel):
tag_ids: list[str] = Field(default_factory=list, description="Full replacement list of selected agent tag ids")
class WxCommonAgentsResponse(BaseModel):
"""The selected Agent Gallery category for the wx chat route."""
agent_type: str | None = Field(default=None)
class WxCommonAgentsUpdateRequest(BaseModel):
agent_type: str | None = Field(default=None, max_length=128)
class LoginWhitelistResponse(BaseModel):
enabled: bool = Field(..., description="是否启用登录白名单(关=所有人可登录,开=仅已放行用户/admin 可登录)")
@@ -857,3 +1005,47 @@ async def update_agent_module_config(key: str, body: AgentModuleConfigUpdateRequ
updated = set_module_tag_ids(current.agent_modules, key, body.tag_ids)
saved = save_system_settings(current.model_copy(update={"agent_modules": updated}))
return AgentModuleConfigResponse(key=key, tag_ids=get_module_tag_ids(saved.agent_modules, key))
def _normalize_wx_common_agent_type(
value: str | None,
current: PublishSquaresSettings,
) -> str | None:
"""Validate a wx category against the live Agent Gallery category set."""
if value is None:
return None
normalized = value.strip()
if not normalized:
return None
if normalized in {"mine", "sentiment"}:
return normalized
if normalized.startswith("square:"):
square_id = normalized.removeprefix("square:")
if square_id in {square.id for square in list_publish_squares(current)}:
return normalized
raise HTTPException(status_code=422, detail="Unknown wx common-agent category")
@router.get("/wx-common-agents", response_model=WxCommonAgentsResponse)
async def get_wx_common_agents() -> WxCommonAgentsResponse:
"""Return the category used by wx route's common-agent panel."""
return WxCommonAgentsResponse(
agent_type=load_system_settings().wx_common_agents.agent_type,
)
@router.put("/wx-common-agents", response_model=WxCommonAgentsResponse)
async def update_wx_common_agents(
body: WxCommonAgentsUpdateRequest,
request: Request,
) -> WxCommonAgentsResponse:
"""Set the wx route's Agent Gallery category. wx or an admin may update it."""
await _require_wx_common_agents_manager(request)
current = load_system_settings()
agent_type = _normalize_wx_common_agent_type(body.agent_type, current.publish_squares)
updated = current.wx_common_agents.model_copy(update={"agent_type": agent_type})
saved = save_system_settings(current.model_copy(update={"wx_common_agents": updated}))
return WxCommonAgentsResponse(agent_type=saved.wx_common_agents.agent_type)