File size: 5,803 Bytes
f56a29b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | /**
* Agent Configuration Panel
* UI for viewing and managing AI agents in the registry
*/
import { useState } from 'react';
import { useAgentRegistry } from '@/lib/orchestration/registry/store';
import { Button } from '@/components/ui/button';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
import { ScrollArea } from '@/components/ui/scroll-area';
import { Avatar, AvatarImage, AvatarFallback } from '@/components/ui/avatar';
import { PlusIcon, Trash2Icon, EditIcon } from 'lucide-react';
export function AgentConfigPanel() {
const { listAgents, deleteAgent } = useAgentRegistry();
const agents = listAgents();
const [selectedAgent, setSelectedAgent] = useState<string | null>(null);
const handleDelete = (agentId: string) => {
if (confirm('确定要删除这个智能体吗?')) {
deleteAgent(agentId);
if (selectedAgent === agentId) {
setSelectedAgent(null);
}
}
};
return (
<div className="flex flex-col h-full p-4 gap-4">
<div className="flex items-center justify-between">
<div>
<h2 className="text-lg font-semibold">智能体配置</h2>
<p className="text-sm text-muted-foreground">管理课堂讨论的AI智能体</p>
</div>
<Button size="sm" variant="outline">
<PlusIcon className="w-4 h-4 mr-2" />
新建
</Button>
</div>
<ScrollArea className="flex-1">
<div className="space-y-3">
{agents.map((agent) => (
<Card
key={agent.id}
className={`cursor-pointer transition-colors ${
selectedAgent === agent.id ? 'border-primary' : ''
}`}
onClick={() => setSelectedAgent(agent.id)}
>
<CardHeader className="p-4">
<div className="flex items-start justify-between">
<div className="flex items-center gap-3">
<Avatar
className="size-10"
style={{
borderColor: agent.color,
borderWidth: 2,
}}
>
<AvatarImage src={agent.avatar} alt={agent.name} />
<AvatarFallback
style={{
backgroundColor: `${agent.color}20`,
color: agent.color,
}}
>
{agent.name.charAt(0)}
</AvatarFallback>
</Avatar>
<div>
<CardTitle className="text-base">{agent.name}</CardTitle>
<CardDescription className="text-sm">{agent.role}</CardDescription>
</div>
</div>
<div className="flex gap-2">
<Badge variant="secondary" className="text-xs">
优先级 {agent.priority}
</Badge>
{agent.isDefault && (
<Badge variant="outline" className="text-xs">
默认
</Badge>
)}
</div>
</div>
</CardHeader>
<CardContent className="p-4 pt-0">
<div className="space-y-2">
<div>
<p className="text-xs font-medium text-muted-foreground mb-1">能力描述</p>
<p className="text-sm line-clamp-2">{agent.persona}</p>
</div>
<div>
<p className="text-xs font-medium text-muted-foreground mb-1">
可用动作 ({agent.allowedActions.length})
</p>
<div className="flex flex-wrap gap-1">
{agent.allowedActions.slice(0, 3).map((tool) => (
<Badge key={tool} variant="secondary" className="text-xs">
{tool}
</Badge>
))}
{agent.allowedActions.length > 3 && (
<Badge variant="secondary" className="text-xs">
+{agent.allowedActions.length - 3}
</Badge>
)}
</div>
</div>
{!agent.isDefault && (
<div className="flex gap-2 pt-2">
<Button size="sm" variant="outline" className="flex-1">
<EditIcon className="w-3 h-3 mr-1" />
编辑
</Button>
<Button
size="sm"
variant="destructive"
onClick={(e) => {
e.stopPropagation();
handleDelete(agent.id);
}}
>
<Trash2Icon className="w-3 h-3" />
</Button>
</div>
)}
</div>
</CardContent>
</Card>
))}
</div>
</ScrollArea>
{agents.length === 0 && (
<div className="flex-1 flex items-center justify-center text-center p-8">
<div className="max-w-sm">
<p className="text-muted-foreground mb-4">还没有配置智能体</p>
<Button>
<PlusIcon className="w-4 h-4 mr-2" />
创建第一个智能体
</Button>
</div>
</div>
)}
</div>
);
}
|