合并代码,解决冲突

(cherry picked from commit 8b23bd771f04ceb1b9c1e3ae021d75001af5ba2f)
This commit is contained in:
hugo authored and sophie committed 2026-06-01 17:52:50 +08:00
1 parent 23badf7456
commit 93e99793d8
10 files changed
+626 -84

No files matched your search

+22
View File
@@ -178,6 +178,27 @@ class Agent(Base):
back_populates="agents"
)
class ChatSession(Base):
"""
聊天会话表
用途:独立持久化会话元数据,使生成中会话也能立即出现在历史记录中
"""
__tablename__ = 'chat_sessions'
__table_args__ = (
Index('ix_chat_sessions_user_agent_last_active', 'user_id', 'agent_id', 'last_active_at'),
)
id: Mapped[int] = mapped_column(primary_key=True)
session_id: Mapped[str] = mapped_column(String(100), unique=True, index=True)
user_id: Mapped[int] = mapped_column(ForeignKey('users.id'), index=True)
agent_id: Mapped[int] = mapped_column(ForeignKey('agents.id'), index=True)
title: Mapped[str] = mapped_column(String(255), default='')
status: Mapped[str] = mapped_column(String(20), default='running')
external_conversation_id: Mapped[Optional[str]] = mapped_column(String(100), index=True, nullable=True)
created_at: Mapped[datetime] = mapped_column(default=datetime.utcnow, index=True)
updated_at: Mapped[datetime] = mapped_column(default=datetime.utcnow, onupdate=datetime.utcnow)
last_active_at: Mapped[datetime] = mapped_column(default=datetime.utcnow, index=True)
class ChatLog(Base):
"""
对话日志表
@@ -192,6 +213,7 @@ class ChatLog(Base):
answer: Mapped[str] = mapped_column(Text)
latency: Mapped[int] = mapped_column(default=0)
conversation_id: Mapped[Optional[str]] = mapped_column(String(100))
session_id: Mapped[Optional[str]] = mapped_column(String(100), index=True, nullable=True)
message_type: Mapped[Optional[str]] = mapped_column(String(50), nullable=True)
payload: Mapped[Optional[dict]] = mapped_column(JSON, nullable=True)
tokens_used: Mapped[int] = mapped_column(default=0)