/** * Admin > AI > Models */ const { html } = window; const { useState, useEffect, useCallback } = hooks; export default function ModelsSection() { const [models, setModels] = useState([]); const [search, setSearch] = useState(''); const [loading, setLoading] = useState(true); const [fetching, setFetching] = useState(false); const load = useCallback(async () => { try { const data = await sw.api.admin.models.list(); setModels(data || []); } catch (e) { sw.toast(e.message, 'error'); } finally { setLoading(false); } }, []); useEffect(() => { load(); }, []); async function fetchModels() { setFetching(true); try { const result = await sw.api.admin.models.fetch(); sw.toast(`Synced: ${result.added || 0} added, ${result.updated || 0} updated, ${result.total || 0} total`, 'success'); load(); } catch (e) { sw.toast(e.message, 'error'); } finally { setFetching(false); } } async function setVisibility(id, visibility) { try { await sw.api.admin.models.update(id, { visibility }); setModels(prev => prev.map(m => m.id === id ? { ...m, visibility } : m)); } catch (e) { sw.toast(e.message, 'error'); } } async function bulkSetVisibility(visibility) { try { await sw.api.admin.models.bulkUpdate(visibility); sw.toast(`All models set to ${visibility}`, 'success'); load(); } catch (e) { sw.toast(e.message, 'error'); } } const filtered = models.filter(m => { if (!search) return true; const q = search.toLowerCase(); return (m.model_id || m.id || '').toLowerCase().includes(q) || (m.display_name || '').toLowerCase().includes(q) || (m.provider_name || '').toLowerCase().includes(q); }); if (loading) return html`