Spaces:
Sleeping
Sleeping
Download app/models/system.py from yabeskn/briga-core-api: direct link, hf CLI and curl.
- Browser
- Download file 9.16 kB
-
https://huggingface.co/spaces/yabeskn/briga-core-api/resolve/main/app/models/system.py
- Command line
-
hf download hf://spaces/yabeskn/briga-core-api/app/models/system.py
-
curl -L -o system.py https://huggingface.co/spaces/yabeskn/briga-core-api/resolve/main/app/models/system.py
9.16 kB
| """System & Audit models.""" | |
| import uuid | |
| from datetime import datetime | |
| from sqlalchemy import Column, String, Integer, Text, Boolean, DateTime, ForeignKey, Numeric | |
| from app.models.base import JSONB | |
| from sqlalchemy.dialects.postgresql import UUID | |
| from app.models.base import Base | |
| class Admin(Base): | |
| __tablename__ = "admins" | |
| id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) | |
| name = Column(String(255), nullable=False) | |
| email = Column(String(255), unique=True, nullable=False) | |
| password_hash = Column(String(255), nullable=False) | |
| role = Column(String(20), default="ADMIN") | |
| created_at = Column(DateTime(timezone=True), default=datetime.utcnow) | |
| updated_at = Column(DateTime(timezone=True), default=datetime.utcnow, onupdate=datetime.utcnow) | |
| class ActivityLog(Base): | |
| __tablename__ = "activity_logs" | |
| id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) | |
| timestamp = Column(DateTime(timezone=True), default=datetime.utcnow) | |
| actor = Column(String(255), default="Anonymous", index=True) | |
| action = Column(String(255), default="Unknown") | |
| log_metadata = Column("metadata", Text, default="-") | |
| class SystemMonitor(Base): | |
| __tablename__ = "system_monitor" | |
| id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) | |
| check_name = Column(String(100), nullable=True) | |
| status = Column(String(50), nullable=True) | |
| detail = Column(Text, nullable=True) | |
| last_checked = Column(DateTime(timezone=True), default=datetime.utcnow) | |
| class SystemMonitorLog(Base): | |
| __tablename__ = "system_monitor_log" | |
| id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) | |
| timestamp = Column(DateTime(timezone=True), default=datetime.utcnow) | |
| agent = Column(String(100), nullable=True) | |
| action = Column(String(255), nullable=True) | |
| status = Column(String(50), nullable=True) | |
| detail = Column(Text, nullable=True) | |
| duration_ms = Column(Integer, default=0) | |
| class AnalyticsTraffic(Base): | |
| __tablename__ = "analytics_traffic" | |
| id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) | |
| timestamp = Column(DateTime(timezone=True), default=datetime.utcnow) | |
| page = Column(String(255), nullable=True, index=True) | |
| referrer = Column(String(500), nullable=True) | |
| geo = Column(String(255), nullable=True) | |
| user_agent = Column(Text, nullable=True) | |
| class APIMonitoring(Base): | |
| __tablename__ = "api_monitoring" | |
| id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) | |
| timestamp = Column(DateTime(timezone=True), default=datetime.utcnow) | |
| api_name = Column(String(100), nullable=True) | |
| token_usage = Column(Integer, default=0) | |
| status = Column(String(50), nullable=True) | |
| user_email = Column(String(255), nullable=True) | |
| class SecurityAuditLog(Base): | |
| __tablename__ = "security_audit_log" | |
| id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) | |
| timestamp = Column(DateTime(timezone=True), default=datetime.utcnow) | |
| target_url = Column(String(500), nullable=True) | |
| page_type = Column(String(50), nullable=True) | |
| status = Column(String(50), nullable=True) | |
| details = Column(Text, nullable=True) | |
| class PrivacyAuditLog(Base): | |
| __tablename__ = "privacy_audit_log" | |
| id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) | |
| timestamp = Column(DateTime(timezone=True), default=datetime.utcnow) | |
| query = Column(Text, nullable=True) | |
| user_email = Column(String(255), nullable=True) | |
| is_hidden = Column(Boolean, default=False) | |
| is_flagged = Column(Boolean, default=False) | |
| risk_score = Column(Integer, default=0) | |
| class TalentEngagement(Base): | |
| __tablename__ = "talent_engagement" | |
| id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) | |
| email = Column(String(255), nullable=False, index=True) | |
| name = Column(String(255), nullable=True) | |
| talent_id = Column(String(20), nullable=True) | |
| engagement_score = Column(Integer, default=0) | |
| dormancy_days = Column(Integer, default=0) | |
| tier = Column(String(10), nullable=True) | |
| last_activity_date = Column(DateTime(timezone=True), nullable=True) | |
| last_chat_date = Column(DateTime(timezone=True), nullable=True) | |
| last_pathway_date = Column(DateTime(timezone=True), nullable=True) | |
| ai_generated_message = Column(Text, nullable=True) | |
| message_type = Column(String(50), nullable=True) | |
| status = Column(String(50), default="Draft", index=True) | |
| sent_at = Column(DateTime(timezone=True), nullable=True) | |
| opened_at = Column(DateTime(timezone=True), nullable=True) | |
| response_at = Column(DateTime(timezone=True), nullable=True) | |
| response_text = Column(Text, nullable=True) | |
| follow_up_date = Column(DateTime(timezone=True), nullable=True) | |
| follow_up_message = Column(Text, nullable=True) | |
| notes = Column(Text, nullable=True) | |
| # ========================================== | |
| # ANTIGRAVITY ORCHESTRATION MODELS | |
| # ========================================== | |
| class AgentStateLog(Base): | |
| """Logs the lifecycle and memory of autonomous AI agents.""" | |
| __tablename__ = "agent_state_logs" | |
| id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) | |
| agent_name = Column(String(100), nullable=False, index=True) | |
| task_id = Column(String(100), nullable=True, index=True) | |
| status = Column(String(50), default="IDLE", index=True) # IDLE, WORKING, COMPLETED, FAILED | |
| memory_context = Column(JSONB, nullable=True) | |
| last_action = Column(String(255), nullable=True) | |
| error_message = Column(Text, nullable=True) | |
| started_at = Column(DateTime(timezone=True), default=datetime.utcnow) | |
| updated_at = Column(DateTime(timezone=True), default=datetime.utcnow, onupdate=datetime.utcnow) | |
| class AgentQueue(Base): | |
| """Manages request throttling to stay within Gemini Free Tier (15 RPM) limits.""" | |
| __tablename__ = "agent_queues" | |
| id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) | |
| task_name = Column(String(100), nullable=False) | |
| payload = Column(JSONB, nullable=False) | |
| priority = Column(Integer, default=0) # Higher is more urgent | |
| status = Column(String(30), default="QUEUED", index=True) # QUEUED, PROCESSING, RETRYING, COMPLETED, ABORTED | |
| scheduled_at = Column(DateTime(timezone=True), default=datetime.utcnow) | |
| processed_at = Column(DateTime(timezone=True), nullable=True) | |
| retry_count = Column(Integer, default=0) | |
| trace_id = Column(String(100), nullable=True) | |
| class CEOStrategicMemory(Base): | |
| """Long-term episodic memory for the AI CEO.""" | |
| __tablename__ = "ceo_strategic_memory" | |
| id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) | |
| topic = Column(String(255), nullable=False, index=True) | |
| summary = Column(Text, nullable=False) | |
| decision_made = Column(String(255), nullable=True) | |
| founder_feedback = Column(Text, nullable=True) | |
| sentiment_score = Column(Numeric(3, 2), nullable=True) # -1.0 to 1.0 | |
| embedding_id = Column(UUID(as_uuid=True), nullable=True) # Reference to vector storage | |
| created_at = Column(DateTime(timezone=True), default=datetime.utcnow) | |
| updated_at = Column(DateTime(timezone=True), default=datetime.utcnow, onupdate=datetime.utcnow) | |
| class WhatsAppSession(Base): | |
| """Conversational state machine for the WhatsApp bot.""" | |
| __tablename__ = "whatsapp_sessions" | |
| id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) | |
| phone = Column(String(50), unique=True, nullable=False, index=True) | |
| state = Column(String(50), default="START") # START, ONBOARDING_NAME, ONBOARDING_EMAIL, IDLE | |
| context = Column(JSONB, nullable=True) | |
| created_at = Column(DateTime(timezone=True), default=datetime.utcnow) | |
| updated_at = Column(DateTime(timezone=True), default=datetime.utcnow, onupdate=datetime.utcnow) | |
| class TelegramSession(Base): | |
| """Conversational state and payment verification session storage for Telegram bot.""" | |
| __tablename__ = "telegram_sessions" | |
| id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) | |
| chat_id = Column(String(255), unique=True, nullable=False, index=True) | |
| state = Column(String(50), nullable=True) | |
| last_context = Column(JSONB, nullable=True) | |
| created_at = Column(DateTime(timezone=True), default=datetime.utcnow) | |
| updated_at = Column(DateTime(timezone=True), default=datetime.utcnow, onupdate=datetime.utcnow) | |
| class WorkflowConfig(Base): | |
| """Runtime configuration for autonomous workflows. Toggle to enable/disable specific agent workflows.""" | |
| __tablename__ = "workflow_configs" | |
| workflow_name = Column(String(100), primary_key=True) | |
| is_active = Column(Boolean, default=False, nullable=False) | |
| schedule_cron = Column(String(100), nullable=True) | |
| last_run = Column(DateTime(timezone=True), nullable=True) | |
| updated_at = Column(DateTime(timezone=True), default=datetime.utcnow, onupdate=datetime.utcnow) | |