Files
tower/apps/web/app/admin/page.tsx
T
maaz519 39ca91f07a feat: auto-detect events, seva tasks, and FAQs from WhatsApp messages
Adds the AI-driven content pipeline so portal content is never manually
created — the system proposes it, admins review and approve.

Worker:
- `tower.event.extract` queue + Event Extractor processor: LLM extracts
  event title/date/time/location from messages with #event hashtag,
  date/time patterns, RSVP phrases, or location terms; seva action items
  within event messages become separate SEVA_TASK drafts
- `tower.faq.candidate` queue + FAQ Curator processor: LLM extracts Q&A
  pairs from messages with question patterns + meaningful answer length
- `classify.processor.ts`: `isEventCandidate()` and `isFaqCandidate()`
  run after rule matching on all non-spam, non-DNC messages; candidates
  are enqueued to the extraction lanes in parallel with normal routing
- `match-rules.ts`: add P1 to TenantRuleRow action union so P1 rules
  are fully typed end-to-end
- `NormalizedMessage`: add `quotedPlatformMsgId` field
- `IngestJobData.effectiveAction`: add `'P1'` to the union

Schema:
- `ContentDraft` model with `DraftType` (EVENT|SEVA_TASK|FAQ_ITEM) and
  `DraftStatus` (PENDING_REVIEW|APPROVED|REJECTED); carries `proposedJson`
  from the LLM, `confidence` score, and `publishedId` after approval
- Migration: `20260617270000_add_content_drafts`

API:
- `DraftsModule`: `GET /admin/drafts`, `POST /admin/drafts/:id/approve`,
  `POST /admin/drafts/:id/reject`; approve creates the actual
  Event/SevaOpportunity/KnowledgeItem and marks the draft APPROVED;
  reject marks it REJECTED — both audit-logged

Web:
- `/admin/drafts` and `/drafts` — tabbed view by type (All/Events/Seva/FAQ)
- `DraftCard` — shows source message excerpt, AI proposed content, and
  approve/reject buttons; approve/reject immediately refresh the list
- "AI Drafts" added to both super-admin and tenant-admin sidebars
- "AI Content Drafts" button added to admin dashboard

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-17 17:49:57 +05:30

60 lines
2.7 KiB
TypeScript

'use client';
import { useEffect, useState } from 'react';
import { useSuperAdmin } from '../_lib/super-admin-context';
import { useRouter } from 'next/navigation';
import Link from 'next/link';
export default function AdminDashboard() {
const { admin, loading } = useSuperAdmin();
const router = useRouter();
const [tenants, setTenants] = useState<any[]>([]);
const [bots, setBots] = useState<any[]>([]);
useEffect(() => {
if (loading) return;
if (!admin) { router.replace('/admin/login'); return; }
fetch('/api/admin/tenants').then(r => r.ok && r.json()).then(d => setTenants(d ?? [])).catch(() => {});
fetch('/api/admin/bots').then(r => r.ok && r.json()).then(d => setBots(d ?? [])).catch(() => {});
}, [admin, loading, router]);
if (loading) return <p className="text-gray-500">Loading...</p>;
if (!admin) return null;
const totalTenants = tenants.length;
const activeTenants = tenants.filter((t: any) => t.isActive).length;
const totalBots = bots.length;
const totalMessages = tenants.reduce((s: number, t: any) => s + (t.stats?.messages ?? 0), 0);
return (
<div>
<h1 className="text-2xl font-bold mb-6">Admin Dashboard</h1>
<div className="grid grid-cols-4 gap-4 mb-8">
<div className="bg-white rounded-xl border p-4">
<div className="text-xs text-gray-500 uppercase tracking-wide">Tenants</div>
<div className="text-2xl font-bold mt-1">{totalTenants}</div>
<div className="text-xs text-gray-400">{activeTenants} active</div>
</div>
<div className="bg-white rounded-xl border p-4">
<div className="text-xs text-gray-500 uppercase tracking-wide">Bot Accounts</div>
<div className="text-2xl font-bold mt-1">{totalBots}</div>
<div className="text-xs text-gray-400">in pool</div>
</div>
<div className="bg-white rounded-xl border p-4">
<div className="text-xs text-gray-500 uppercase tracking-wide">Messages</div>
<div className="text-2xl font-bold mt-1">{totalMessages}</div>
</div>
<div className="bg-white rounded-xl border p-4">
<div className="text-xs text-gray-500 uppercase tracking-wide">Avg tenants/bot</div>
<div className="text-2xl font-bold mt-1">{totalBots ? Math.round(totalTenants / totalBots) : 0}</div>
</div>
</div>
<div className="flex gap-4 flex-wrap">
<Link href="/admin/tenants" className="bg-blue-600 text-white rounded-lg px-4 py-2 text-sm">Manage Tenants</Link>
<Link href="/admin/bots" className="bg-blue-600 text-white rounded-lg px-4 py-2 text-sm">Manage Bots</Link>
<Link href="/admin/drafts" className="bg-indigo-600 text-white rounded-lg px-4 py-2 text-sm">AI Content Drafts</Link>
</div>
</div>
);
}