feat(backend): update database models and add agent_conversation
- base.py: update database base configuration - models/__init__.py: update models exports - models/system_setting.py: update system setting model - models/agent_conversation.py: add new agent conversation model
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
from app.db.base_class import Base
|
from app.db.base_class import Base
|
||||||
|
from app.models.agent_conversation import AgentConversation, AgentConversationMessage
|
||||||
from app.models.agent_asset import AgentAsset, AgentAssetReview, AgentAssetVersion
|
from app.models.agent_asset import AgentAsset, AgentAssetReview, AgentAssetVersion
|
||||||
from app.models.agent_run import AgentRun, AgentToolCall, SemanticParseLog
|
from app.models.agent_run import AgentRun, AgentToolCall, SemanticParseLog
|
||||||
from app.models.approval import ApprovalRecord
|
from app.models.approval import ApprovalRecord
|
||||||
@@ -22,6 +23,8 @@ __all__ = [
|
|||||||
"Base",
|
"Base",
|
||||||
"AccountsPayableRecord",
|
"AccountsPayableRecord",
|
||||||
"AccountsReceivableRecord",
|
"AccountsReceivableRecord",
|
||||||
|
"AgentConversation",
|
||||||
|
"AgentConversationMessage",
|
||||||
"AgentAsset",
|
"AgentAsset",
|
||||||
"AgentAssetReview",
|
"AgentAssetReview",
|
||||||
"AgentAssetVersion",
|
"AgentAssetVersion",
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from app.models.agent_conversation import AgentConversation, AgentConversationMessage
|
||||||
from app.models.agent_asset import AgentAsset, AgentAssetReview, AgentAssetVersion
|
from app.models.agent_asset import AgentAsset, AgentAssetReview, AgentAssetVersion
|
||||||
from app.models.agent_run import AgentRun, AgentToolCall, SemanticParseLog
|
from app.models.agent_run import AgentRun, AgentToolCall, SemanticParseLog
|
||||||
from app.models.approval import ApprovalRecord
|
from app.models.approval import ApprovalRecord
|
||||||
@@ -20,6 +21,8 @@ from app.models.system_setting_secret import SystemSettingSecret
|
|||||||
__all__ = [
|
__all__ = [
|
||||||
"AccountsPayableRecord",
|
"AccountsPayableRecord",
|
||||||
"AccountsReceivableRecord",
|
"AccountsReceivableRecord",
|
||||||
|
"AgentConversation",
|
||||||
|
"AgentConversationMessage",
|
||||||
"AgentAsset",
|
"AgentAsset",
|
||||||
"AgentAssetReview",
|
"AgentAssetReview",
|
||||||
"AgentAssetVersion",
|
"AgentAssetVersion",
|
||||||
|
|||||||
58
server/src/app/models/agent_conversation.py
Normal file
58
server/src/app/models/agent_conversation.py
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import uuid
|
||||||
|
from datetime import datetime
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from sqlalchemy import DateTime, ForeignKey, Integer, String, Text, func
|
||||||
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||||
|
from sqlalchemy.types import JSON
|
||||||
|
|
||||||
|
from app.db.base_class import Base
|
||||||
|
|
||||||
|
|
||||||
|
class AgentConversation(Base):
|
||||||
|
__tablename__ = "agent_conversations"
|
||||||
|
|
||||||
|
id: Mapped[str] = mapped_column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
|
||||||
|
conversation_id: Mapped[str] = mapped_column(String(50), unique=True, index=True)
|
||||||
|
user_id: Mapped[str | None] = mapped_column(String(100), nullable=True, index=True)
|
||||||
|
source: Mapped[str | None] = mapped_column(String(30), nullable=True, index=True)
|
||||||
|
entry_source: Mapped[str | None] = mapped_column(String(50), nullable=True)
|
||||||
|
title: Mapped[str | None] = mapped_column(String(200), nullable=True)
|
||||||
|
last_run_id: Mapped[str | None] = mapped_column(String(50), nullable=True, index=True)
|
||||||
|
last_scenario: Mapped[str | None] = mapped_column(String(50), nullable=True)
|
||||||
|
last_intent: Mapped[str | None] = mapped_column(String(50), nullable=True)
|
||||||
|
draft_claim_id: Mapped[str | None] = mapped_column(String(36), nullable=True, index=True)
|
||||||
|
state_json: Mapped[dict[str, Any]] = mapped_column(JSON, default=dict)
|
||||||
|
message_count: Mapped[int] = mapped_column(Integer, default=0)
|
||||||
|
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||||
|
updated_at: Mapped[datetime] = mapped_column(
|
||||||
|
DateTime(timezone=True),
|
||||||
|
server_default=func.now(),
|
||||||
|
onupdate=func.now(),
|
||||||
|
)
|
||||||
|
|
||||||
|
messages = relationship(
|
||||||
|
"AgentConversationMessage",
|
||||||
|
back_populates="conversation",
|
||||||
|
cascade="all, delete-orphan",
|
||||||
|
order_by="asc(AgentConversationMessage.created_at)",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class AgentConversationMessage(Base):
|
||||||
|
__tablename__ = "agent_conversation_messages"
|
||||||
|
|
||||||
|
id: Mapped[str] = mapped_column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
|
||||||
|
conversation_id: Mapped[str] = mapped_column(
|
||||||
|
ForeignKey("agent_conversations.conversation_id"),
|
||||||
|
index=True,
|
||||||
|
)
|
||||||
|
run_id: Mapped[str | None] = mapped_column(String(50), nullable=True, index=True)
|
||||||
|
role: Mapped[str] = mapped_column(String(20), index=True)
|
||||||
|
content: Mapped[str] = mapped_column(Text())
|
||||||
|
message_json: Mapped[dict[str, Any]] = mapped_column(JSON, default=dict)
|
||||||
|
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||||
|
|
||||||
|
conversation = relationship("AgentConversation", back_populates="messages")
|
||||||
@@ -22,6 +22,7 @@ class SystemSetting(Base):
|
|||||||
admin_account: Mapped[str] = mapped_column(String(120), default="superadmin")
|
admin_account: Mapped[str] = mapped_column(String(120), default="superadmin")
|
||||||
admin_email: Mapped[str] = mapped_column(String(255), default="")
|
admin_email: Mapped[str] = mapped_column(String(255), default="")
|
||||||
session_timeout: Mapped[int] = mapped_column(Integer, default=30)
|
session_timeout: Mapped[int] = mapped_column(Integer, default=30)
|
||||||
|
conversation_retention_days: Mapped[int] = mapped_column(Integer, default=3)
|
||||||
notice_email: Mapped[str] = mapped_column(String(255), default="")
|
notice_email: Mapped[str] = mapped_column(String(255), default="")
|
||||||
mfa_enabled: Mapped[bool] = mapped_column(Boolean, default=True)
|
mfa_enabled: Mapped[bool] = mapped_column(Boolean, default=True)
|
||||||
strong_password: Mapped[bool] = mapped_column(Boolean, default=True)
|
strong_password: Mapped[bool] = mapped_column(Boolean, default=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user