WIP-CHECKPOINT[auth-refactor]: 固化工程师崩溃前部分成果 + 同树其他未提交WIP(仅源码,不含密钥/二进制)-- 待重激活工程师续作

This commit is contained in:
Simon
2026-07-07 21:52:11 +08:00
parent 242c1967ff
commit fab75760e0
203 changed files with 21504 additions and 3345 deletions
+42 -3
View File
@@ -27,7 +27,7 @@ from app.api.router import api_router
# 导入共享服务生命周期管理
from app.dependencies import init_shared_services, cleanup_shared_services
# 导入异常处理器和异常类
from app.utils.response import AppException, app_exception_handler
from app.utils.response import AppException, app_exception_handler, success_response
# 导入定时任务
from app.tasks.reminder_task import check_unreplied_sessions
@@ -283,7 +283,14 @@ async def _init_default_data():
from app.data.seed_rbac import seed_rbac_roles
await seed_rbac_roles(db)
# 7. (dev 模式)初始化 demo 会话,让前端有数据可发
# 6.1 阶段5 — 自动化场景配置种子(P0 四场景默认启用)
await _init_scenario_configs(db)
# 7. 初始化超级管理员(环境变量配置)
from app.services.admin_user_service import init_super_admin
await init_super_admin(db)
# 8. (dev 模式)初始化 demo 会话,让前端有数据可发
# 真因:之前没建,前端硬编码的 conv-001 调 POST /messages 返 "会话不存在" 3003
if getattr(settings, 'dev_mode', False) or os.getenv('DEV_MODE', '').lower() == 'true':
await _init_demo_conversations(db)
@@ -609,6 +616,34 @@ async def _init_software_downloads(db, SoftwareDownload):
logger.info(f"初始化 software_downloads: {len(downloads)}")
async def _init_scenario_configs(db):
"""初始化自动化场景配置(P0 四场景默认启用)。"""
from sqlalchemy import func, select
from app.models.automation import ScenarioConfig
from app.services.automation import DEFAULT_SCENARIO_CONFIGS
count = (await db.execute(select(func.count(ScenarioConfig.id)))).scalar() or 0
if count > 0:
logger.debug(f"auto_scenario_configs 已有 {count} 条,跳过初始化")
return
for key, cfg in DEFAULT_SCENARIO_CONFIGS.items():
db.add(
ScenarioConfig(
scenario_key=key,
name=cfg.get("name", key),
description=cfg.get("description", ""),
enabled=cfg.get("enabled", True),
trigger_conditions=cfg.get("trigger_conditions"),
actions=cfg.get("actions"),
approval_strategy=cfg.get("approval_strategy"),
)
)
await db.flush()
logger.info(f"初始化 auto_scenario_configs: {len(DEFAULT_SCENARIO_CONFIGS)}")
# --------------------------------------------------------------------------
# 创建 FastAPI 应用
# --------------------------------------------------------------------------
@@ -787,13 +822,17 @@ def create_app() -> FastAPI:
from app.api.ws import router as ws_router
app.include_router(ws_router)
# 阶段5 自动化闭环:专用 WebSocket 通道 /ws/automation/{session_id}
from app.api.automation import ws_router as automation_ws_router
app.include_router(automation_ws_router)
# ----------------------------------------------------------------------
# 诊断端点(调试用,生产环境删除)
# ----------------------------------------------------------------------
@app.get("/test-ping", tags=["诊断"])
async def test_ping():
"""简单测试 — 不依赖数据库和 Redis"""
return {"code": 0, "message": "success", "data": {"message": "pong"}}
return success_response(data={"message": "pong"})
@app.get("/test-error", tags=["诊断"])
async def test_error():