/** * Team Admin > Personas */ const { html } = window; const { useState, useEffect, useCallback } = hooks; export default function PersonasSection({ teamId }) { const [personas, setPersonas] = useState([]); const [loading, setLoading] = useState(true); const [editing, setEditing] = useState(null); // null | 'new' | persona object const load = useCallback(async () => { try { const data = await sw.api.teams.personas(teamId); setPersonas(Array.isArray(data) ? data : data.data || []); } catch (e) { sw.toast(e.message, 'error'); } finally { setLoading(false); } }, [teamId]); useEffect(() => { load(); }, [load]); async function savePersona(e) { e.preventDefault(); const form = e.target; const data = { name: form.pname.value.trim(), description: form.description.value.trim(), system_prompt: form.system_prompt.value, }; try { if (editing === 'new') { await sw.api.teams.createPersona(teamId, data); sw.toast('Persona created', 'success'); } else { await sw.api.teams.updatePersona(teamId, editing.id, data); sw.toast('Persona updated', 'success'); } setEditing(null); load(); } catch (e) { sw.toast(e.message, 'error'); } } async function deletePersona(pid) { const ok = await sw.confirm('Delete this persona?', true); if (!ok) return; try { await sw.api.teams.deletePersona(teamId, pid); sw.toast('Persona deleted', 'success'); load(); } catch (e) { sw.toast(e.message, 'error'); } } if (loading) return html`
Loading\u2026
`; if (editing) { const isNew = editing === 'new'; const p = isNew ? {} : editing; return html`

${isNew ? 'Create Persona' : `Edit: ${p.name}`}

`; } return html`
${personas.length === 0 && html`
No personas
`} ${personas.map(p => html`
${p.name} ${p.description && html`${p.description.substring(0, 60)}${p.description.length > 60 ? '\u2026' : ''}`}
${p.kb_count || 0} KBs
`)}
`; }