Feature/memory work (#61)
* refactor(conversation): separate service and repository layers for conversation module - Split ConversationService and repository/UnitOfWork layers - Service layer now only handles business logic and orchestration - Repository layer handles all direct database operations - UnitOfWork encapsulates transactional operations for messages - Ensured all public methods have clear English docstrings with arguments, return values, and exceptions * feat(memory): implement work memory endpoints and services - Added API routes for conversation count, conversation list, messages, and detail. - Integrated ConversationService for database queries and LLM-based summary generation. * feat(memory): implement work memory endpoints and services - Added API routes for conversation count, conversation list, messages, and detail. - Integrated ConversationService for database queries and LLM-based summary generation. * feat(workflow): fix issues causing workflow failures if-else None value error knowledge empty list rerank end node output none node value assigner input none value * feat(memory): convert memory file creation time to timestamp and include title and first-line fields in file type * fix(memory): fix serialization output and default value issues * fix(workflow): fix issue with hybrid search logic in knowledge retrieval node
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
"""
|
||||
import uuid
|
||||
import datetime
|
||||
|
||||
from sqlalchemy import Column, String, DateTime, ForeignKey, Boolean, Integer, Text, JSON
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.orm import relationship
|
||||
@@ -25,56 +26,69 @@ class Conversation(Base):
|
||||
__tablename__ = "conversations"
|
||||
|
||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4, index=True)
|
||||
|
||||
|
||||
# 关联信息
|
||||
app_id = Column(UUID(as_uuid=True), ForeignKey("apps.id"), nullable=False, comment="应用ID")
|
||||
workspace_id = Column(UUID(as_uuid=True), ForeignKey("workspaces.id"), nullable=False, comment="工作空间ID")
|
||||
user_id = Column(String, nullable=True, comment="用户ID(外部系统)")
|
||||
|
||||
|
||||
# 会话信息
|
||||
title = Column(String(255), comment="会话标题")
|
||||
summary = Column(Text, comment="会话摘要")
|
||||
|
||||
|
||||
# 会话类型:True=草稿会话(使用草稿配置),False=发布会话(使用发布配置)
|
||||
is_draft = Column(Boolean, default=True, nullable=False, comment="是否为草稿会话")
|
||||
|
||||
|
||||
# 配置快照:保存创建会话时的完整配置,用于审计和问题追溯
|
||||
config_snapshot = Column(JSON, comment="配置快照(Agent配置、模型配置等)")
|
||||
|
||||
|
||||
# 统计信息
|
||||
message_count = Column(Integer, default=0, comment="消息数量")
|
||||
|
||||
|
||||
# 状态
|
||||
is_active = Column(Boolean, default=True, nullable=False, comment="是否活跃")
|
||||
|
||||
|
||||
# 时间戳
|
||||
created_at = Column(DateTime, default=datetime.datetime.now, comment="创建时间")
|
||||
updated_at = Column(DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now, comment="更新时间")
|
||||
|
||||
|
||||
# 关联关系
|
||||
app = relationship("App", back_populates="conversations")
|
||||
workspace = relationship("Workspace")
|
||||
messages = relationship("Message", back_populates="conversation", cascade="all, delete-orphan")
|
||||
|
||||
|
||||
class ConversationDetail(Base):
|
||||
__tablename__ = "conversation_details"
|
||||
|
||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4, index=True)
|
||||
conversation_id = Column(UUID(as_uuid=True), ForeignKey("conversations.id"))
|
||||
|
||||
theme = Column(String, comment="会话主题")
|
||||
theme_intro = Column(String, comment="主题介绍")
|
||||
summary = Column(String, comment="会话摘要")
|
||||
takeaways = Column(JSON, comment="会话要点")
|
||||
info_score = Column(Integer, comment="会话信息量评分")
|
||||
|
||||
|
||||
class Message(Base):
|
||||
"""消息表"""
|
||||
__tablename__ = "messages"
|
||||
|
||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4, index=True)
|
||||
|
||||
|
||||
# 关联信息
|
||||
conversation_id = Column(UUID(as_uuid=True), ForeignKey("conversations.id"), nullable=False, comment="会话ID")
|
||||
|
||||
|
||||
# 消息内容
|
||||
role = Column(String(20), nullable=False, comment="角色: user/assistant/system")
|
||||
content = Column(Text, nullable=False, comment="消息内容")
|
||||
|
||||
|
||||
# 元数据(避免使用 metadata 保留字)
|
||||
meta_data = Column(JSON, comment="消息元数据(如模型、token使用等)")
|
||||
|
||||
|
||||
# 时间戳
|
||||
created_at = Column(DateTime, default=datetime.datetime.now, comment="创建时间")
|
||||
|
||||
|
||||
# 关联关系
|
||||
conversation = relationship("Conversation", back_populates="messages")
|
||||
|
||||
Reference in New Issue
Block a user