feat: restore core admin modules and harden ai model fallback

This commit is contained in:
2026-06-22 01:21:01 +08:00
parent f180fff020
commit 524c027a4a
15 changed files with 1896 additions and 21 deletions
+4 -1
View File
@@ -16,7 +16,7 @@ from app.base_schema import PaginatedResponse, ResponseModel
from utils.context import get_current_user_id_from_context
from ai_platform.models import (
Agent, AgentConversation, AgentMessage,
LLMModel, AIWorkflow,
LLMModel, LLMProvider, AIWorkflow,
)
from core.application.model import Application
from ai_platform.schemas.agent_schema import (
@@ -59,10 +59,13 @@ CODEX_AGENT_PROMPT = """
async def _resolve_default_chat_model_id(db: AsyncSession) -> Optional[str]:
result = await db.execute(
select(LLMModel)
.join(LLMProvider, LLMProvider.id == LLMModel.provider_id)
.where(
LLMModel.is_deleted == False,
LLMModel.is_active == True,
LLMModel.model_type == "chat",
LLMProvider.is_deleted == False,
LLMProvider.is_active == True,
)
.order_by(LLMModel.sort.desc(), LLMModel.sys_create_datetime.desc())
)
@@ -10,7 +10,7 @@ from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from ai_platform.models import (
Agent, AgentConversation, AgentMessage, AIWorkflow, LLMModel,
Agent, AgentConversation, AgentMessage, AIWorkflow, LLMModel, LLMProvider,
)
from .llm_service import LLMService
@@ -212,10 +212,14 @@ class AgentService:
if agent.model_id:
result = await self._db.execute(
select(LLMModel).where(
select(LLMModel)
.join(LLMProvider, LLMProvider.id == LLMModel.provider_id)
.where(
LLMModel.id == agent.model_id,
LLMModel.is_deleted == False,
LLMModel.is_active == True,
LLMProvider.is_deleted == False,
LLMProvider.is_active == True,
)
)
if result.scalar_one_or_none():
@@ -223,10 +227,13 @@ class AgentService:
result = await self._db.execute(
select(LLMModel)
.join(LLMProvider, LLMProvider.id == LLMModel.provider_id)
.where(
LLMModel.is_deleted == False,
LLMModel.is_active == True,
LLMModel.model_type == "chat",
LLMProvider.is_deleted == False,
LLMProvider.is_active == True,
)
.order_by(LLMModel.sort.desc(), LLMModel.sys_create_datetime.desc())
)
@@ -44,14 +44,17 @@ class LLMService:
if not self._db:
raise ValueError("未找到可用的 chat 模型,请先在模型配置中启用一个模型")
from ai_platform.models import LLMModel
from ai_platform.models import LLMModel, LLMProvider
result = await self._db.execute(
select(LLMModel)
.join(LLMProvider, LLMProvider.id == LLMModel.provider_id)
.where(
LLMModel.is_deleted == False,
LLMModel.is_active == True,
LLMModel.model_type == "chat",
LLMProvider.is_deleted == False,
LLMProvider.is_active == True,
)
.order_by(LLMModel.sort.desc(), LLMModel.sys_create_datetime.desc())
)
+59 -6
View File
@@ -17,13 +17,14 @@ from core.menu.schema import MenuCreate, MenuUpdate
menu_cache = CacheManager(prefix="menu:")
# 缓存key
AI_AGENT_ADMIN_MENU_CACHE_VERSION = "v16"
AI_AGENT_ADMIN_MENU_CACHE_VERSION = "v19"
MENU_TREE_CACHE_KEY = f"tree:ai_agent_admin:{AI_AGENT_ADMIN_MENU_CACHE_VERSION}"
USER_ROUTE_CACHE_PREFIX = f"user_route:ai_agent_admin:{AI_AGENT_ADMIN_MENU_CACHE_VERSION}:"
AI_AGENT_ADMIN_MENU_NAMES = {
"AccountSettings",
"ControlCenter",
"Application",
"AIPlatform",
"AIAgent",
"AIModelConfig",
@@ -39,6 +40,10 @@ AI_AGENT_ADMIN_MENU_NAMES = {
"SystemPost",
"SystemDict",
"SystemFileManager",
"LoginLog",
"OrgNode",
"SystemLoginLog",
"SystemOrgChart",
"SystemRole",
"SystemConfigManager",
"UIConfigManager",
@@ -50,6 +55,7 @@ AI_AGENT_ADMIN_MENU_NAMES = {
AI_AGENT_ADMIN_VISIBLE_MENU_NAMES = {
"ControlCenter",
"Application",
"AIPlatform",
"AIAgent",
"AIModelConfig",
@@ -65,6 +71,10 @@ AI_AGENT_ADMIN_VISIBLE_MENU_NAMES = {
"SystemPost",
"SystemDict",
"SystemFileManager",
"LoginLog",
"OrgNode",
"SystemLoginLog",
"SystemOrgChart",
"SystemRole",
"SystemConfigManager",
"UIConfigManager",
@@ -82,10 +92,29 @@ AI_AGENT_ADMIN_SYSTEM_CHILD_MENU_NAMES = {
"SystemPost",
"SystemDict",
"SystemFileManager",
"LoginLog",
"OrgNode",
"SystemLoginLog",
"SystemOrgChart",
"SystemRole",
"UIConfigManager",
}
AI_AGENT_ADMIN_AI_CHILD_MENU_NAMES = {
"AIAgent",
"AIModelConfig",
"AIWorkflow",
"AIWorkflowRuns",
"CodexAgentChat",
"KnowledgeBase",
}
AI_AGENT_ADMIN_MESSAGE_CHILD_MENU_NAMES = {
"AnnouncementList",
"AnnouncementManage",
"MessageList",
}
AI_AGENT_ADMIN_MENU_OVERRIDES = {
"SystemConfigManager": {
"component": "/_core/system-config/index",
@@ -100,6 +129,16 @@ AI_AGENT_ADMIN_MENU_OVERRIDES = {
"component": "/_core/file-manager/index",
"path": "/system/file-manager",
},
"LoginLog": {
"component": "/_core/login-log/index",
"path": "/system/login-log",
"title": "menu-title.loginLog",
},
"OrgNode": {
"component": "/_core/org-chart/index",
"path": "/system/org-chart",
"title": "menu-title.orgChart",
},
"UIConfigManager": {
"component": "/_core/ui-config/index",
"path": "/system/ui-config",
@@ -131,19 +170,33 @@ def _normalize_ai_agent_admin_menu(menu: Menu) -> None:
def _normalize_ai_agent_admin_parentage(menus: List[Menu]) -> None:
"""Attach retained system children back to the lightweight system catalog."""
"""Attach retained children back to the lightweight product catalogs."""
retained_ids = {menu.id for menu in menus}
system_menu = next(
(menu for menu in menus if menu.name == "SystemManagement"),
None,
)
ai_menu = next(
(menu for menu in menus if menu.name == "AIPlatform"),
None,
)
message_menu = next(
(menu for menu in menus if menu.name == "Message"),
None,
)
for menu in menus:
if not menu.parent_id or menu.parent_id in retained_ids:
continue
if system_menu and menu.name in AI_AGENT_ADMIN_SYSTEM_CHILD_MENU_NAMES:
menu.parent_id = system_menu.id
else:
menu.parent_id = None
continue
if ai_menu and menu.name in AI_AGENT_ADMIN_AI_CHILD_MENU_NAMES:
menu.parent_id = ai_menu.id
continue
if message_menu and menu.name in AI_AGENT_ADMIN_MESSAGE_CHILD_MENU_NAMES:
menu.parent_id = message_menu.id
continue
if not menu.parent_id or menu.parent_id in retained_ids:
continue
menu.parent_id = None
class MenuService(BaseService[Menu, MenuCreate, MenuUpdate]):
+2
View File
@@ -10,6 +10,7 @@ from core.chat.api import router as chat_router
from core.dept.api import router as dept_router
from core.device.api import router as device_router
from core.file_manager.router import router as file_manager_router
from core.login_log.api import router as login_log_router
from core.menu.api import router as menu_router
from core.message.api import announcement_router
from core.message.api import router as message_router
@@ -40,6 +41,7 @@ router.include_router(field_permission_router)
router.include_router(role_router)
router.include_router(user_router)
router.include_router(file_manager_router)
router.include_router(login_log_router)
router.include_router(message_router)
router.include_router(announcement_router)
router.include_router(oauth_router)