Files
2026-08-21 16:00:13 +08:00

68 lines
3.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""资料导入候选模型(api-spec §8;契约字典 §10.6 candidate.status)。
导入资料经模型抽取产生档案 / 记忆候选,待用户审核后应用;人格建议复用
``personality_proposals``(005)。``evidence_ids`` 指向 ``import_items.id``
(EvidenceRef source_type = ``import_item``)。
"""
from datetime import datetime
from sqlalchemy import DateTime, Float, ForeignKey, String, Text
from sqlalchemy.orm import Mapped, mapped_column
from app.core.ids import new_memory_candidate_id, new_profile_candidate_id
from app.core.time import utc_now
from app.db.base import Base
class ProfileCandidate(Base):
"""人物档案候选(契约字典 §10.6)。"""
__tablename__ = "character_profile_candidates"
id: Mapped[str] = mapped_column(String(80), primary_key=True, default=new_profile_candidate_id)
character_id: Mapped[str] = mapped_column(String(80), ForeignKey("characters.id"), index=True)
import_job_id: Mapped[str | None] = mapped_column(
String(80), ForeignKey("character_import_jobs.id"), index=True
)
field: Mapped[str] = mapped_column(String(60), nullable=False)
value: Mapped[str] = mapped_column(Text, nullable=False)
confidence: Mapped[float] = mapped_column(Float, nullable=False, default=0.5)
evidence_ids_json: Mapped[str] = mapped_column(Text, nullable=False, default="[]")
status: Mapped[str] = mapped_column(String(40), nullable=False, default="pending", index=True)
reason: Mapped[str | None] = mapped_column(Text)
reviewed_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=utc_now)
updated_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), default=utc_now, onupdate=utc_now
)
class MemoryCandidate(Base):
"""记忆候选(契约字典 §10.6)。"""
__tablename__ = "memory_candidates"
id: Mapped[str] = mapped_column(String(80), primary_key=True, default=new_memory_candidate_id)
character_id: Mapped[str] = mapped_column(String(80), ForeignKey("characters.id"), index=True)
import_job_id: Mapped[str | None] = mapped_column(
String(80), ForeignKey("character_import_jobs.id"), index=True
)
cycle_id: Mapped[str | None] = mapped_column(
String(80), ForeignKey("big_cycles.id"), index=True
)
type: Mapped[str] = mapped_column(String(60), nullable=False)
title: Mapped[str] = mapped_column(String(200), nullable=False)
content: Mapped[str] = mapped_column(Text, nullable=False)
confidence: Mapped[float] = mapped_column(Float, nullable=False, default=0.5)
importance: Mapped[float] = mapped_column(Float, nullable=False, default=0.5)
sensitivity: Mapped[str] = mapped_column(String(40), nullable=False, default="low")
evidence_ids_json: Mapped[str] = mapped_column(Text, nullable=False, default="[]")
status: Mapped[str] = mapped_column(String(40), nullable=False, default="pending", index=True)
reason: Mapped[str | None] = mapped_column(Text)
reviewed_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=utc_now)
updated_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), default=utc_now, onupdate=utc_now
)