- Phase1/2:移除 MemoirOrchestrator.run 与 process_memoir_segments 别名;文档改为 process_memoir_phase1。 - 槽位校验集中到 stage_constants(filter_stage_slots),批处理与顺序路径及 state_service 写库一致。 - StoryRoute:no_llm/parse_error/invalid_target 保守 new_story;短篇护栏不覆盖这些 fallback。 - Phase2 低置信单路径可选延迟(StoryPipelineResult.deferred):不写 Chapter/Story,Segment 记录 defer 元数据,冷却内不重复消费;上限后停自动重试,Phase1 同类目新段唤醒池内段。 - Alembic 0017:segments 表 narrative_defer_* 列。 - ProfileAgent:经 LlmGateway/注入 Provider 统一聊天与 JSON,新增测试。 - ImagePromptOrchestrator:LLM 初始化失败可依配置降级或硬失败;补充策略测试。 - 配套单测与 README/本地开发文档表述更新。 Co-authored-by: Cursor <cursoragent@cursor.com>
102 lines
4.2 KiB
Python
102 lines
4.2 KiB
Python
from sqlalchemy import (
|
||
JSON,
|
||
Boolean,
|
||
Column,
|
||
DateTime,
|
||
ForeignKey,
|
||
Integer,
|
||
String,
|
||
Text,
|
||
)
|
||
from sqlalchemy.orm import relationship
|
||
|
||
from app.core.db import Base, utc_now
|
||
|
||
|
||
class Conversation(Base):
|
||
__tablename__ = "conversations"
|
||
|
||
id = Column(String, primary_key=True)
|
||
user_id = Column(String, ForeignKey("users.id"), nullable=False)
|
||
started_at = Column(DateTime(timezone=True), default=utc_now)
|
||
last_message_at = Column(DateTime(timezone=True), nullable=True)
|
||
ended_at = Column(DateTime(timezone=True), nullable=True)
|
||
duration_seconds = Column(Integer, default=0)
|
||
summary = Column(Text, nullable=True)
|
||
status = Column(String, default="active")
|
||
current_topic = Column(String, nullable=True)
|
||
conversation_stage = Column(String, nullable=True)
|
||
deleted_at = Column(DateTime(timezone=True), nullable=True)
|
||
# 内部评测 Playground:最近一次 GLM 对话评分快照(含逐轮分与对比文案)
|
||
playground_conversation_judge_json = Column(JSON, nullable=True)
|
||
|
||
user = relationship("User", back_populates="conversations")
|
||
segments = relationship(
|
||
"Segment", back_populates="conversation", cascade="all, delete-orphan"
|
||
)
|
||
messages = relationship(
|
||
"ConversationMessage",
|
||
back_populates="conversation",
|
||
cascade="all, delete-orphan",
|
||
)
|
||
|
||
|
||
class Segment(Base):
|
||
__tablename__ = "segments"
|
||
|
||
id = Column(String, primary_key=True)
|
||
conversation_id = Column(String, ForeignKey("conversations.id"), nullable=False)
|
||
audio_url = Column(String, nullable=True)
|
||
# 用户输入正文:语音 ASR 结果或键盘输入(历史列名 transcript_text)
|
||
user_input_text = Column(Text, nullable=False)
|
||
audio_duration_seconds = Column(Integer, nullable=True)
|
||
created_at = Column(DateTime(timezone=True), default=utc_now)
|
||
processed = Column(Boolean, default=False)
|
||
# Phase 1 分类结果(回忆录 chapter 类目);非空表示 Phase 1 已完成
|
||
topic_category = Column(String, nullable=True)
|
||
# Phase 2 已消费该段并完成叙事落库
|
||
narrated = Column(Boolean, default=False, server_default="false")
|
||
# Phase 1 判定无需进故事管线(无 slots 且 LLM 判 none)
|
||
skip_narrative = Column(Boolean, default=False, server_default="false")
|
||
# Phase 2 路由低置信延迟:到期前不消费;新同类目素材到达可清空。
|
||
narrative_deferred_until = Column(DateTime(timezone=True), nullable=True)
|
||
narrative_defer_count = Column(
|
||
Integer, nullable=False, default=0, server_default="0"
|
||
)
|
||
narrative_defer_reason = Column(String, nullable=True)
|
||
narrative_last_attempt_at = Column(DateTime(timezone=True), nullable=True)
|
||
agent_response = Column(Text, nullable=True)
|
||
tts_audio_urls = Column(JSON, nullable=True)
|
||
# 用户轮次 durable message id(与 lineage_json 同步;便于查询)
|
||
user_message_id = Column(
|
||
String,
|
||
ForeignKey("conversation_messages.id", ondelete="SET NULL"),
|
||
nullable=True,
|
||
)
|
||
# DialogueLineage JSON(schema 见 conversation.lineage_schemas)
|
||
lineage_json = Column(JSON, nullable=True)
|
||
|
||
conversation = relationship("Conversation", back_populates="segments")
|
||
|
||
|
||
class ConversationMessage(Base):
|
||
"""durable turn log aligned with Redis history shape (canonical chat source of truth)."""
|
||
|
||
__tablename__ = "conversation_messages"
|
||
|
||
id = Column(String, primary_key=True)
|
||
conversation_id = Column(String, ForeignKey("conversations.id"), nullable=False)
|
||
role = Column(String, nullable=False) # human / ai
|
||
content = Column(Text, nullable=False)
|
||
message_type = Column(String, nullable=False, default="text")
|
||
voice_session_id = Column(String, nullable=True)
|
||
duration_seconds = Column(Integer, nullable=True)
|
||
tts_audio_urls = Column(JSON, nullable=True)
|
||
segment_id = Column(String, ForeignKey("segments.id"), nullable=True)
|
||
created_at = Column(DateTime(timezone=True), default=utc_now)
|
||
# 本轮(与用户句配对)助手生成前检索到的 memory 证据 id 快照;Phase 8 可追溯
|
||
memory_retrieval_trace_json = Column(JSON, nullable=True)
|
||
|
||
conversation = relationship("Conversation", back_populates="messages")
|
||
segment = relationship("Segment", foreign_keys=[segment_id])
|