Spaces:
Paused

File size: 1,764 Bytes
f7d91a1
6c62840
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f7d91a1
 
 
6c62840
77f3110
 
 
12ce592
 
 
6c62840
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from sqlalchemy import Column, String, ForeignKey, Text, Boolean
from sqlalchemy.dialects.postgresql import UUID, JSONB
from core.database import Base
from models.base import PrimaryKeyMixin, TimestampMixin
from sqlalchemy.orm import relationship

class NexusThread(Base, PrimaryKeyMixin, TimestampMixin):
    """
    Manages conversational session metadata for the Nexus Master Agent.
    Allows for thread naming and personal history tracking.
    """
    __tablename__ = "nexus_threads"

    workspace_id = Column(UUID(as_uuid=True), ForeignKey("workspaces.id"), nullable=False, index=True)
    user_id = Column(UUID(as_uuid=True), ForeignKey("users.id"), nullable=False, index=True)
    
    # User-defined or auto-generated title for the thread
    title = Column(String(255), nullable=False, default="New Conversation")

    # Flag to exclude utility interactions (RCA/Drafts) from chat history sidebars
    is_hidden = Column(Boolean, default=False, index=True)
    
    # Soft delete support
    is_deleted = Column(Boolean, default=False, index=True)
    
    # User bookmarking support
    is_bookmarked = Column(Boolean, default=False, index=True)
    
    # Optional connection to a ticket
    ticket_id = Column(UUID(as_uuid=True), ForeignKey("tickets.id"), nullable=True, index=True)
    
    # Long-term summary or high-level context specific to this thread
    gist = Column(Text, nullable=True)
    
    metadata_json = Column(JSONB, nullable=True, default={})

    # Relationships
    user = relationship("User")
    workspace = relationship("Workspace")
    ticket = relationship("Ticket")
    interactions = relationship("NexusInteraction", backref="thread", primaryjoin="NexusThread.id == NexusInteraction.thread_id", overlaps="interactions")