Spaces:
Sleeping
Sleeping
| """Supabase client for dashboard - direct queries for LLM verification data. | |
| Domain queries are in separate modules: | |
| - supabase_sentiment.py: Overview, LLM verification, polarity | |
| - supabase_research.py: Topic clusters, cross-model analysis | |
| - supabase_action_items.py: Action items CRUD, reports, date range | |
| """ | |
| import os | |
| from functools import lru_cache | |
| from pathlib import Path | |
| from supabase import create_client, Client | |
| from dotenv import load_dotenv | |
| # Load environment variables (project root) | |
| _project_root = Path(__file__).parent.parent.parent.parent | |
| for _env_name in (".env.dev", ".env.prod"): | |
| _env_path = _project_root / _env_name | |
| if _env_path.exists(): | |
| load_dotenv(_env_path, override=True) | |
| break | |
| def get_supabase_client() -> Client: | |
| """Create Supabase client for unified database. | |
| Uses service_role key (bypasses RLS) because the dashboard is an | |
| internal admin tool that needs cross-campaign analytics. | |
| DO NOT use this client in user-facing API routes. | |
| """ | |
| url = os.environ.get("SUPABASE_URL", "") | |
| key = os.environ.get("SUPABASE_SERVICE_KEY", "") | |
| if not url or not key: | |
| raise ValueError("Missing SUPABASE_URL or SUPABASE_SERVICE_KEY") | |
| return create_client(url, key) | |
| # ============================================================================ | |
| # Re-exports for backward compatibility | |
| # All consumers import from core.supabase_client — these re-exports | |
| # ensure existing imports continue to work unchanged. | |
| # ============================================================================ | |
| # Sentiment / Overview / LLM Verification | |
| from core.supabase_sentiment import ( # noqa: E402, F401 | |
| get_campaign_overview, | |
| get_llm_verification_stats, | |
| get_false_positives, | |
| get_true_negatives, | |
| get_llm_verified_for_export, | |
| get_sentiment_data_for_export, | |
| get_answers_by_polarity, | |
| get_polarity_stats, | |
| ) | |
| # Research / Topics | |
| from core.supabase_research import ( # noqa: E402, F401 | |
| get_topic_clusters, | |
| get_topic_map_snapshot, | |
| get_cross_model_analysis, | |
| get_gap_scores, | |
| find_cross_model_pair, | |
| ) | |
| # Action Items / Reports | |
| from core.supabase_action_items import ( # noqa: E402, F401 | |
| get_action_items, | |
| get_action_item_stats, | |
| update_action_item_status, | |
| delete_action_item, | |
| save_action_items_batch, | |
| get_campaign_date_range, | |
| get_report_history_count, | |
| ) | |