Spaces:
Paused

File size: 1,361 Bytes
5eb4857
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
AI Workflow model — tracks the sequential lifecycle of AI-driven actions for tickets, articles, and searches.
"""

from sqlalchemy import Column, String, ForeignKey, DateTime, Float
from sqlalchemy.dialects.postgresql import UUID, JSONB
from sqlalchemy.sql import func
from core.database import Base
from models.base import PrimaryKeyMixin, TimestampMixin

class AIWorkflow(Base, PrimaryKeyMixin, TimestampMixin):
    __tablename__ = "ai_workflows"

    workspace_id = Column(UUID(as_uuid=True), ForeignKey("workspaces.id"), nullable=False, index=True)
    
    # Generic entity ID: can be a ticket_id, article_id, or a request-level search_id
    entity_id = Column(UUID(as_uuid=True), nullable=False, index=True)
    
    # Enum-like: "LIFECYCLE" (Ticket/KB) or "SEARCH" (Query)
    workflow_type = Column(String(50), nullable=False, index=True)
    
    # Current high-level stage: "TRIAGE", "INDEXING", "SUMMARIZATION", "RESULTS"
    current_stage = Column(String(100), nullable=True)
    
    # List of steps: [{"timestamp", "name", "status", "input", "output", "duration_ms"}]
    steps = Column(JSONB, nullable=False, default=[])
    
    total_duration_ms = Column(Float, nullable=True, default=0.0)
    
    # Optional metadata: e.g. {"query_variations": [...], "duplicate_of": "..."}
    metadata_json = Column(JSONB, nullable=True, default={})