fix(admin): 优化管理控制台聊天日志和应用权限

This commit is contained in:
sophie committed 2026-06-25 09:59:06 +08:00
1 parent 6e78c10171
commit 1dc5a459b3
7 files changed
+75 -19

No files matched your search

+4 -4
View File
@@ -1273,6 +1273,7 @@ def _chat_logs_report_query():
db.session.query(
ChatLog,
User.username.label('username'),
User.real_name.label('real_name'),
Agent.name.label('agent_name'),
)
.join(User, User.id == ChatLog.user_id)
@@ -1280,7 +1281,7 @@ def _chat_logs_report_query():
)
def _serialize_chat_log_report_row(log: ChatLog, username: str | None, agent_name: str | None) -> dict:
def _serialize_chat_log_report_row(log: ChatLog, username: str | None, real_name: str | None, agent_name: str | None) -> dict:
"""
将 ChatLog 及关联字段序列化为报表行(隐藏 run_id / 原始 ID 类外键列)。
保留 id 供前端批量删除使用,默认不在表格列中展示。
@@ -1290,12 +1291,11 @@ def _serialize_chat_log_report_row(log: ChatLog, username: str | None, agent_nam
'id': log.id,
'agent_name': agent_name or '',
'username': username or '',
'real_name': real_name or '',
'created_at': created_at,
'query': log.query,
'answer': log.answer,
'session_id': log.session_id,
'tokens_used': log.tokens_used,
'message_type': log.message_type,
}
@@ -1322,7 +1322,7 @@ def _list_chat_logs_report():
query = _apply_chat_logs_report_filters(_chat_logs_report_query())
query = query.order_by(desc(ChatLog.created_at), desc(ChatLog.id))
items = query.limit(100).all()
rows = [_serialize_chat_log_report_row(log, username, agent_name) for log, username, agent_name in items]
rows = [_serialize_chat_log_report_row(log, username, real_name, agent_name) for log, username, real_name, agent_name in items]
return jsonify(rows)