import { useState, useEffect } from 'react';
import { useAgentStore } from '../store/agentStore';
import { useConnectionStore } from '../store/connectionStore';
import { useConfigStore } from '../store/configStore';
import { toChatAgent, useChatStore } from '../store/chatStore';
import { Bot, Plus, X, Globe, Cat, Search, BarChart2, Sparkles } from 'lucide-react';
import { AgentOnboardingWizard } from './AgentOnboardingWizard';
import type { Clone } from '../store/agentStore';
export function CloneManager() {
const clones = useAgentStore((s) => s.clones);
const loadClones = useAgentStore((s) => s.loadClones);
const deleteClone = useAgentStore((s) => s.deleteClone);
const connectionState = useConnectionStore((s) => s.connectionState);
const quickConfig = useConfigStore((s) => s.quickConfig);
const { agents, currentAgent, setCurrentAgent } = useChatStore();
const [showWizard, setShowWizard] = useState(false);
const connected = connectionState === 'connected';
useEffect(() => {
if (connected) {
loadClones();
}
}, [connected, loadClones]);
const handleDelete = async (id: string) => {
if (confirm('确定删除该分身?')) {
await deleteClone(id);
}
};
const handleWizardSuccess = (clone: Clone) => {
setCurrentAgent(toChatAgent(clone));
setShowWizard(false);
};
// Merge gateway clones with local agents for display
const displayClones = clones.length > 0 ? clones : agents.map(a => ({
id: a.id,
name: a.name,
role: '默认助手',
nickname: a.name,
scenarios: [] as string[],
workspaceDir: '~/.openfang/zclaw-workspace',
userName: quickConfig.userName || '未设置',
userRole: '',
restrictFiles: true,
privacyOptIn: false,
createdAt: '',
onboardingCompleted: true,
emoji: undefined as string | undefined,
personality: undefined as string | undefined,
}));
// Function to get display emoji or icon for clone
const getCloneDisplay = (clone: typeof displayClones[0]) => {
// If clone has emoji, use it
if (clone.emoji) {
return {
emoji: clone.emoji,
icon: null,
bg: 'bg-gradient-to-br from-orange-400 to-red-500',
};
}
// Fallback to icon based on name
if (clone.name.includes('Browser') || clone.name.includes('浏览器')) {
return { emoji: null, icon:
{clone.role || clone.personality || '新分身'}