Changeset 0.37.19 (#232)

Co-authored-by: gobha <jasafpro@gmail.com>
Co-committed-by: gobha <jasafpro@gmail.com>
This commit is contained in:
2026-03-25 00:26:44 +00:00
committed by xcaliber
parent 54ceeb4299
commit be67feaa8e
21 changed files with 173 additions and 88 deletions

View File

@@ -4,7 +4,9 @@
* Reads globals:
* __SECTION__ — active section name (string)
* __BASE__ — base path
* __PAGE_DATA__ — { BYOKEnabled, ... } from Go template
*
* Policy flags (BYOK, personas) come from sw.auth.policies,
* populated at SDK boot via GET /api/v1/profile/permissions.
*
* Layout: topbar + left nav + content area (same CSS classes as before).
* All sections are native Preact components loaded lazily.
@@ -73,21 +75,21 @@ const SECTION_TITLES = {
function SettingsSurface() {
const BASE = window.__BASE__ || '';
const section = window.__SECTION__ || 'general';
const pageData = window.__PAGE_DATA__ || {};
const [byokEnabled, setByokEnabled] = useState(!!pageData.BYOKEnabled);
const [personasEnabled, setPersonasEnabled] = useState(!!pageData.UserPersonasEnabled);
const policies = sw.auth?.policies || {};
const [byokEnabled, setByokEnabled] = useState(policies.allow_user_byok === 'true');
const [personasEnabled, setPersonasEnabled] = useState(policies.allow_user_personas === 'true');
const [SectionComponent, setSectionComponent] = useState(null);
// Fetch policies if not provided by template
// Update when permissions refresh (e.g. after boot or policy change)
useEffect(() => {
if (!pageData.BYOKEnabled || !pageData.UserPersonasEnabled) {
sw.api.admin?.settings?.public?.().then(data => {
const policies = data?.policies || {};
if (policies.allow_user_byok === 'true') setByokEnabled(true);
if (policies.allow_user_personas === 'true') setPersonasEnabled(true);
}).catch(() => {});
function _onPermsChanged() {
const p = sw.auth?.policies || {};
setByokEnabled(p.allow_user_byok === 'true');
setPersonasEnabled(p.allow_user_personas === 'true');
}
sw.on('auth.permissions.changed', _onPermsChanged);
return () => sw.off('auth.permissions.changed', _onPermsChanged);
}, []);
// Load the section component

View File

@@ -101,6 +101,9 @@ export default function KnowledgeSection() {
return html`<span class="badge ${cls}">${status}</span>`;
}
const canCreate = sw.can('kb.create');
const canWrite = sw.can('kb.write');
if (loading) return html`<div class="settings-placeholder">Loading\u2026</div>`;
// Detail view
@@ -111,8 +114,8 @@ export default function KnowledgeSection() {
<h4 style="margin:0;">${detail.name}</h4>
${statusBadge(detail.status || 'active')}
<div style="flex:1"></div>
<button class="btn-small" onClick=${uploadDoc}>Upload Document</button>
<button class="btn-small btn-danger" onClick=${() => deleteKb(detail.id)}>Delete KB</button>
${canWrite && html`<button class="btn-small" onClick=${uploadDoc}>Upload Document</button>`}
${canWrite && html`<button class="btn-small btn-danger" onClick=${() => deleteKb(detail.id)}>Delete KB</button>`}
</div>
${detail.description && html`
@@ -132,7 +135,7 @@ export default function KnowledgeSection() {
${' '}${statusBadge(d.status || 'pending')}
</div>
<span class="text-muted" style="font-size:11px;">${fmtDate(d.created_at)}</span>
<button class="btn-small btn-danger" onClick=${() => deleteDoc(d.id)}>Delete</button>
${canWrite && html`<button class="btn-small btn-danger" onClick=${() => deleteDoc(d.id)}>Delete</button>`}
</div>
`)}
</div>
@@ -145,9 +148,10 @@ export default function KnowledgeSection() {
<div style="display:flex;align-items:center;gap:8px;margin-bottom:12px;">
<span class="text-muted" style="font-size:12px;">${kbs.length} knowledge base${kbs.length !== 1 ? 's' : ''}</span>
<div style="flex:1"></div>
${canCreate && html`
<button class="btn-md btn-primary" onClick=${() => setShowCreate(!showCreate)}>
${showCreate ? 'Cancel' : '+ Create'}
</button>
</button>`}
</div>
${showCreate && html`

View File

@@ -85,10 +85,14 @@ export function PersonasSection() {
return html`<div class="settings-placeholder">Loading personas\u2026</div>`;
}
const canCreate = sw.can('persona.create');
const canManage = sw.can('persona.manage');
return html`
${canCreate && html`
<div style="margin-bottom:12px;">
<button class="btn-md btn-primary" onClick=${openAdd}>+ New Persona</button>
</div>
</div>`}
${showForm && html`
<div class="settings-section" style="margin-bottom:16px;">
@@ -136,6 +140,7 @@ export function PersonasSection() {
</div>
`}
</div>
${canManage && html`
<div style="display:flex;gap:4px;">
<button class="icon-btn" title="Edit" onClick=${() => openEdit(p)}>
\u{270F}\u{FE0F}
@@ -144,7 +149,7 @@ export function PersonasSection() {
onClick=${() => del(p)}>
\u{1F5D1}
</button>
</div>
</div>`}
</div>
</div>
`)}