'use client'; import { useEffect, useState } from 'react'; import { Bot, Sparkles, Settings2, BarChart3 } from 'lucide-react'; import { Tabs, TabsList, TabsTrigger, TabsContent } from '@/components/ui/tabs'; import { AiPlayground } from '@/components/agents/ai-playground'; import { AiUsageCard } from '@/components/agents/ai-usage'; import { AiConfig } from '@/components/settings/ai-config'; import { useAuth } from '@/hooks/use-auth'; import { canEditSettings } from '@/lib/auth/roles'; type Tab = 'playground' | 'setup' | 'usage'; export default function AgentsPage() { const { accountRole } = useAuth(); const canViewUsage = accountRole ? canEditSettings(accountRole) : false; const [tab, setTab] = useState('playground'); const [decided, setDecided] = useState(false); // Land first-time users on Setup, returning users on the Playground. useEffect(() => { let cancelled = false; (async () => { try { const res = await fetch('/api/ai/config'); const data = await res.json().catch(() => ({})); if (!cancelled) setTab(data?.configured ? 'playground' : 'setup'); } catch { if (!cancelled) setTab('setup'); } finally { if (!cancelled) setDecided(true); } })(); return () => { cancelled = true; }; }, []); return (

AI Agents

Your bring-your-own-key AI agent — set it up, then test it in the playground before it replies to customers in the inbox.

{decided && ( setTab(v as Tab)} className="mt-6" > Playground Setup {canViewUsage && ( Usage )} setTab('setup')} /> {canViewUsage && ( )} )}
); }