86 lines
2.0 KiB
Python
86 lines
2.0 KiB
Python
"""
|
|
API 路由汇总
|
|
|
|
统一注册所有 API 路由,供 main.py 引入。
|
|
"""
|
|
|
|
from importlib import import_module
|
|
|
|
from fastapi import APIRouter
|
|
|
|
from ..core.config import settings
|
|
|
|
CORE_ROUTE_MODULES = (
|
|
"signals_api",
|
|
"feedbacks",
|
|
"experiments",
|
|
"context",
|
|
"tasks",
|
|
"webhooks",
|
|
"auth",
|
|
"workspaces_api",
|
|
"users_api",
|
|
"endpoints.skill",
|
|
"workloads",
|
|
"skill_tags_api",
|
|
"sstc_api",
|
|
"projects_api",
|
|
"scheduler",
|
|
"notifications",
|
|
"recipes",
|
|
"operation_catalog",
|
|
"audit",
|
|
"task_briefs",
|
|
"pmflow_os_api",
|
|
"pmflow_launch_api",
|
|
"space_api",
|
|
"legacy_ai_steward_api",
|
|
"account_settings_api",
|
|
"ai_readiness_api",
|
|
"ai_call_traces_api",
|
|
"prompt_assets_api",
|
|
"ai_routing",
|
|
"llm_engines",
|
|
"model_routing",
|
|
)
|
|
|
|
OPTIONAL_ROUTE_GROUPS = {
|
|
"integrations": ("feishu_api", "wecom_api", "mcp_api", "dev_sync"),
|
|
"knowledge": ("rag_api", "knowledge_graph", "semantic_facts_api", "ai_pmo_api"),
|
|
"ai_control": (
|
|
"ai_steward_api",
|
|
"llm_providers",
|
|
"ai_logs_api",
|
|
"prompt_profiles",
|
|
"signal_sources_api",
|
|
),
|
|
}
|
|
|
|
|
|
def _include_module(router: APIRouter, module_path: str) -> None:
|
|
module = import_module(f"{__package__}.{module_path}")
|
|
router.include_router(module.router)
|
|
|
|
|
|
def _enabled_optional_groups() -> tuple[str, ...]:
|
|
if settings.api_route_profile == "lean":
|
|
return tuple(settings.api_optional_route_groups)
|
|
if settings.api_optional_route_groups:
|
|
return tuple(dict.fromkeys(settings.api_optional_route_groups))
|
|
return tuple(OPTIONAL_ROUTE_GROUPS.keys())
|
|
|
|
|
|
def build_api_router() -> APIRouter:
|
|
router = APIRouter()
|
|
for module_path in CORE_ROUTE_MODULES:
|
|
_include_module(router, module_path)
|
|
|
|
for group in _enabled_optional_groups():
|
|
for module_path in OPTIONAL_ROUTE_GROUPS.get(group, ()):
|
|
_include_module(router, module_path)
|
|
|
|
return router
|
|
|
|
|
|
api_router = build_api_router()
|