import { useState, useEffect } from 'react'; import { useTranslation } from 'react-i18next'; import { Download, Trash2, Plus, Box, Sparkles, Loader2, Wand2 } from 'lucide-react'; import apiClient from '../../api/client'; export function SkillSettings() { const { t } = useTranslation(); const [skills, setSkills] = useState([]); const [loading, setLoading] = useState(true); const [repoUrl, setRepoUrl] = useState(''); const [path, setPath] = useState(''); const [installing, setInstalling] = useState(false); const [message, setMessage] = useState(''); const [error, setError] = useState(''); const fetchSkills = async () => { setLoading(true); try { const response = await apiClient.get('/api/v1/resource/skill'); const data = response.data.skills || {}; setSkills(Array.isArray(data) ? data : Object.keys(data)); } catch (err) { console.error('Failed to fetch skills:', err); } finally { setLoading(false); } }; useEffect(() => { fetchSkills(); }, []); const handleInstall = async (e: React.FormEvent) => { e.preventDefault(); if (!repoUrl) return; setInstalling(true); setMessage(''); setError(''); try { await apiClient.post('/api/v1/resource/skill', { repo_url: repoUrl, path: path || null }); setMessage(t('plugin.skillInstallSuccess')); setRepoUrl(''); setPath(''); fetchSkills(); } catch (err: any) { setError(err.response?.data?.message || t('plugin.skillInstallFailed')); } finally { setInstalling(false); } }; const handleDelete = async (skillName: string) => { if (!confirm(t('plugin.deleteSkillConfirm', { name: skillName }))) return; try { await apiClient.delete(`/api/v1/resource/skill/${skillName}`); fetchSkills(); } catch { alert(t('plugin.skillDeleteFailed')); } }; return (

{t('plugin.skillManagement')}

{t('plugin.skillDesc')}

{t('plugin.installSkill')}

{t('plugin.installSkillDesc')}

setRepoUrl(e.target.value)} placeholder={t('plugin.repoUrlPlaceholder')} className="w-full px-3.5 py-2.5 bg-bg-input border border-border-primary rounded-xl text-sm text-text-primary focus:outline-none focus:ring-2 focus:ring-accent/20 focus:border-accent placeholder:text-text-muted/50" />
setPath(e.target.value)} placeholder={t('plugin.pathPlaceholder')} className="w-full px-3.5 py-2.5 bg-bg-input border border-border-primary rounded-xl text-sm text-text-primary focus:outline-none focus:ring-2 focus:ring-accent/20 focus:border-accent placeholder:text-text-muted/50" />
{message &&
{message}
} {error &&
{error}
}

{t('plugin.installedSkills', { count: skills.length })}

{loading ? (
{t('common.loading')}
) : skills.length === 0 ? (
{t('plugin.noSkills')}
) : (
{skills.map((skill) => (
{skill}
))}
)}
); }