sync update from LAN repo (source ji @ 85078a31)

This commit is contained in:
gozeros committed 2026-10-21 15:09:16 +08:00
1 parent 5d6627af50
commit e602d88695
864 files changed
+99150 -6346

No files matched your search

@@ -219,6 +219,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)."""
@@ -318,6 +342,35 @@ class ModelConcurrencyUpdateRequest(BaseModel):
user_model_limits: dict[str, int] | None = None
class MemoryRuntimeResponse(BaseModel):
enabled: bool = Field(
default=False,
description="Whether Q&A memory is enabled deployment-wide",
)
class MemoryRuntimeUpdateRequest(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)
def _skill_compression_to_response(settings: SkillCompressionSettings) -> SkillCompressionResponse:
return SkillCompressionResponse(
enabled=settings.enabled,
@@ -848,6 +901,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 可登录)")
@@ -895,3 +958,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)