feat:对接中心平台,完善接口鉴权

This commit is contained in:
2026-10-01 04:01:44 -07:00
parent 8e37d30ef2
commit 618290d852
20 changed files with 391 additions and 70 deletions
+14 -5
View File
@@ -3,12 +3,13 @@
import asyncio
from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi import Depends, FastAPI
from loguru import logger
from app.api.agent import router
from app.api.conversations import router as conversation_router
from app.api.materials import router as material_router
from app.core.auth import get_current_user
from app.core.exceptions import register_exception_handlers
from app.core.logging import setup_logging
@@ -17,6 +18,7 @@ from app.core.logging import setup_logging
async def lifespan(application: FastAPI):
setup_logging()
from app.clients.decision import close_decision_engine
from app.clients.user_center import close_user_center
from app.observability.tracing import flush_tracing
from app.processor.graph import build_graph
from app.services.agent import AgentService
@@ -42,9 +44,12 @@ async def lifespan(application: FastAPI):
await close_decision_engine()
finally:
try:
await asyncio.to_thread(flush_tracing)
await close_user_center()
finally:
await logger.complete()
try:
await asyncio.to_thread(flush_tracing)
finally:
await logger.complete()
def create_app() -> FastAPI:
@@ -52,8 +57,12 @@ def create_app() -> FastAPI:
# 统一处理请求校验、HTTP 错误和未捕获异常
register_exception_handlers(application)
# 统一 /api 前缀,方便前端代理和反向代理只配置一条规则
application.include_router(router, prefix="/api")
application.include_router(conversation_router, prefix="/api")
# 会话和 agent 接口需登录,物料目录是全局公开数据
authenticated = [Depends(get_current_user)]
application.include_router(router, prefix="/api", dependencies=authenticated)
application.include_router(
conversation_router, prefix="/api", dependencies=authenticated
)
application.include_router(material_router, prefix="/api")
return application