""" AI Workflow model — tracks the sequential lifecycle of AI-driven actions for tickets, articles, and searches. """ from sqlalchemy import Column, String, ForeignKey, Float from sqlalchemy.dialects.postgresql import UUID, JSONB 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={})