'use client' import styles from './agents.module.css'; import Image from 'next/image'; import Link from 'next/link'; import useSWR from 'swr'; import { useEffect, useState } from 'react'; import { useAuthenticatedData, UserProfile } from '../common/auth'; import { Button } from '@/components/ui/button'; export interface AgentData { slug: string; avatar: string; name: string; personality: string; } async function openChat(slug: string, userData: UserProfile | null) { const unauthenticatedRedirectUrl = `/login?next=/agents?agent=${slug}`; if (!userData) { window.location.href = unauthenticatedRedirectUrl; return; } const response = await fetch(`/api/chat/sessions?agent_slug=${slug}`, { method: "POST" }); if (response.status == 200) { window.location.href = `/chat`; } else if(response.status == 403 || response.status == 401) { window.location.href = unauthenticatedRedirectUrl; } else { alert("Failed to start chat session"); } } const agentsFetcher = () => window.fetch('/api/agents').then(res => res.json()).catch(err => console.log(err)); interface AgentModalProps { data: AgentData; setShowModal: (show: boolean) => void; userData: UserProfile | null; } interface AgentCardProps { data: AgentData; userProfile: UserProfile | null; } function AgentModal(props: AgentModalProps) { const [copiedToClipboard, setCopiedToClipboard] = useState(false); useEffect(() => { if (copiedToClipboard) { setTimeout(() => setCopiedToClipboard(false), 3000); } }, [copiedToClipboard]); return (
{props.data.personality}