- Fix delete agent 500: clean up FK records (agent_llm_logs, permissions, schedules, executions, team_members) and unbind goals/tasks before delete - Remove hardcoded personality templates in Android, replace with dynamic system prompt generation from name + description - Set promptSectionsEnabled=false to bypass PromptComposer for personality - Add Tencent Cloud Linux deployment guide (Docker Compose) - Accumulated backend service updates, frontend UI fixes, Android app changes Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
44 lines
1.8 KiB
Python
44 lines
1.8 KiB
Python
"""
|
|
对话分支模型 — 支持从任意历史点分叉对话
|
|
|
|
参考 Claude Code src/commands/branch/branch.ts
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import uuid
|
|
from datetime import datetime
|
|
from sqlalchemy import Column, String, Text, Integer, DateTime, JSON, Boolean
|
|
from sqlalchemy.dialects.mysql import CHAR
|
|
from app.core.database import Base
|
|
|
|
|
|
class ConversationBranch(Base):
|
|
"""对话分支 — 保存某个时间点的完整对话快照"""
|
|
|
|
__tablename__ = "conversation_branches"
|
|
|
|
id = Column(CHAR(36), primary_key=True, default=lambda: str(uuid.uuid4()), comment="分支ID")
|
|
user_id = Column(String(36), nullable=False, index=True, comment="用户ID")
|
|
agent_id = Column(String(36), nullable=True, comment="关联Agent ID")
|
|
agent_name = Column(String(200), nullable=True, comment="Agent 名称(冗余便于展示)")
|
|
|
|
# 溯源链
|
|
parent_session_id = Column(String(100), nullable=False, comment="分叉来源会话ID")
|
|
branch_session_id = Column(String(100), nullable=False, unique=True, comment="新分支会话ID")
|
|
|
|
# 元信息
|
|
title = Column(String(500), nullable=False, comment="分支标题(取自首条用户消息)")
|
|
message_count = Column(Integer, default=0, comment="快照包含的消息数")
|
|
first_user_message = Column(Text, nullable=True, comment="首条用户消息(用于列表展示)")
|
|
|
|
# 完整消息快照 (JSON)
|
|
messages = Column(JSON, nullable=True, comment="分支创建时的完整消息列表")
|
|
|
|
# 状态
|
|
is_active = Column(Boolean, default=True, comment="是否活跃")
|
|
|
|
created_at = Column(DateTime, default=datetime.now, comment="创建时间")
|
|
|
|
def __repr__(self):
|
|
return f"<ConversationBranch(id={self.id}, title={self.title}, messages={self.message_count})>"
|