'use client'; import { useState } from 'react'; import { Plus, X, Sparkles, Loader2 } from 'lucide-react'; import { AgentList } from '@/components/agents/AgentList'; import { Button } from '@/components/ui/Button'; import { Input } from '@/components/ui/Input'; import { Textarea } from '@/components/ui/Textarea'; import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/Card'; import type { Dictionary } from '@/get-dictionary'; interface AgentsPageClientProps { locale: string; isPremium: boolean; dict: Dictionary; } export function AgentsPageClient({ locale, isPremium, dict }: AgentsPageClientProps) { const [showCreateModal, setShowCreateModal] = useState(false); const [creating, setCreating] = useState(false); const [formData, setFormData] = useState({ name: '', personality: '', background: '', }); const [error, setError] = useState(null); const handleCreateAgent = async () => { if (!formData.name.trim()) { setError('请输入智能体名称'); return; } setCreating(true); setError(null); try { const response = await fetch('/api/agents', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ name: formData.name, background: formData.background, personality: { traits: formData.personality.split(',').map((t) => t.trim()).filter(Boolean), tone: 'warm', }, }), }); if (!response.ok) { const data = await response.json(); throw new Error(data.error || '创建失败'); } // Close modal and refresh setShowCreateModal(false); setFormData({ name: '', personality: '', background: '' }); // The AgentList will auto-refresh } catch (err) { setError(err instanceof Error ? err.message : '创建失败'); } finally { setCreating(false); } }; return ( <> setShowCreateModal(true)} /> {/* Create Modal */} {showCreateModal && (
{/* Modal header */}

创建自定义智能体

为你的新智能体起个名字吧

{/* Modal body */}
{/* Name input */}
setFormData({ ...formData, name: e.target.value })} placeholder="例如:十年后的自己" maxLength={50} />
{/* Background textarea */}