fix(mcp): 优化智能对话流式响应并增强异常处理

- 确保智能对话流式响应返回字节串,防止类型错误
- 在流式响应异常时返回友好错误信息,避免连接中断
- WebSocket聊天控制器中添加异常处理,保证异常信息反馈客户端
- WebSocket连接异常后使用finally确保连接正确关闭

refactor(resource): 统一资源接口返回HTTP URL路径

- 资源控制器新增Request参数,传递base_url实现URL转换
- 资源服务中所有路径替换为返回基于base_url的HTTP URL路径
- 文件信息、目录列表、文件上传下载接口均返回HTTP URL,提升前端友好度
- 移除递归参数及相关逻辑,简化目录统计实现

fix(database): 简化数据库依赖生成器,避免不必要的事务开启

- dependencies中db_getter取消多余事务管理,仅yield数据库会话

style(router_class): 优化操作日志路由异常处理,去除多余事务

- 简化操作日志写入流程,移除嵌套事务开启,提升代码可读性

refactor(initialize): 优化数据库初始化逻辑并增强日志与事务管理

- 初始化数据插入前打印日志,插入后标记是否需要提交事务
- PostgreSQL序列更新拆分成单独方法,针对有id字段的表执行
- 增加完整的异常捕获和回滚,保证初始化失败时事务回滚
- 读取初始化数据文件时增加日志及异常处理

fix(ai_client): 修正AI客户端HTTP连接管理及异常处理

- 使用自定义httpx AsyncClient替代默认客户端,确保连接配置
- 增加关闭客户端连接方法,避免资源泄露
- 流式响应时检查选择器内容有效性,提升稳定性

chore(cleanup): 移除MySQL快照SQL文件,保持仓库整洁

- 删除无用的SQL数据转储文件,减小仓库体积并维护清洁度
This commit is contained in:
zhangtao
2025-09-09 01:09:33 +08:00
parent 5fa3a3a759
commit 8bb5134cb2
15 changed files with 1042 additions and 911 deletions
+1 -2
View File
@@ -149,5 +149,4 @@ async def mongodb_connect(app: FastAPI, status: bool) -> AsyncIOMotorClient:
raise ValueError(f"MongoDB连接失败: {e}")
else:
app.state.mongo_client.close()
logger.info("MongoDB连接已关闭")
logger.info("MongoDB连接已关闭")
+1 -2
View File
@@ -21,8 +21,7 @@ from app.api.v1.module_system.auth.schema import AuthSchema
async def db_getter() -> AsyncGenerator[AsyncSession, None]:
"""获取数据库会话连接"""
async with session_connect() as session:
async with session.begin():
yield session
yield session
async def redis_getter(request: Request) -> Redis:
"""获取Redis连接"""
+12 -14
View File
@@ -105,20 +105,18 @@ class OperationLogRoute(APIRoute):
pass
else:
async with session_connect() as session:
async with session.begin():
auth = AuthSchema(db=session)
await OperationLogService.create_log_service(data=OperationLogCreateSchema(
type = log_type,
request_path = request.url.path,
request_method = request.method,
request_payload = payload,
request_ip = request_ip,
login_location=login_location,
request_os = user_agent.os.family,
request_browser = user_agent.browser.family,
response_code = response.status_code,
response_json = response_data.decode(),
auth = AuthSchema(db=session)
await OperationLogService.create_log_service(data=OperationLogCreateSchema(
type = log_type,
request_path = request.url.path,
request_method = request.method,
request_payload = payload,
request_ip = request_ip,
login_location=login_location,
request_os = user_agent.os.family,
request_browser = user_agent.browser.family,
response_code = response.status_code,
response_json = response_data.decode(),
process_time = process_time,
description = route.summary,
creator_id = current_user_id