feat: corpus sources tab, park/restore, discover content, activity log, email feedback
This commit is contained in:
parent
0ca9108ca8
commit
e63c6be521
1 changed files with 416 additions and 2 deletions
|
|
@ -64,6 +64,21 @@ export async function initStewardDash() {
|
||||||
// Co-steward collaboration: array of invited co-steward emails
|
// Co-steward collaboration: array of invited co-steward emails
|
||||||
await pool.query(`ALTER TABLE agentify_subject_registry ADD COLUMN IF NOT EXISTS co_steward_emails TEXT[] DEFAULT '{}'`).catch(() => {});
|
await pool.query(`ALTER TABLE agentify_subject_registry ADD COLUMN IF NOT EXISTS co_steward_emails TEXT[] DEFAULT '{}'`).catch(() => {});
|
||||||
await pool.query(`ALTER TABLE personaforge_subjects ADD COLUMN IF NOT EXISTS co_steward_emails TEXT[] DEFAULT '{}'`).catch(() => {});
|
await pool.query(`ALTER TABLE personaforge_subjects ADD COLUMN IF NOT EXISTS co_steward_emails TEXT[] DEFAULT '{}'`).catch(() => {});
|
||||||
|
// Catalog source curation — park/restore without deleting
|
||||||
|
await pool.query(`ALTER TABLE agentify_source_catalog ADD COLUMN IF NOT EXISTS catalog_status TEXT NOT NULL DEFAULT 'active'`).catch(() => {});
|
||||||
|
// Steward action audit log
|
||||||
|
await pool.query(`
|
||||||
|
CREATE TABLE IF NOT EXISTS steward_audit_log (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
subject_slug TEXT NOT NULL,
|
||||||
|
actor TEXT NOT NULL DEFAULT 'steward',
|
||||||
|
action TEXT NOT NULL,
|
||||||
|
target_url TEXT,
|
||||||
|
target_title TEXT,
|
||||||
|
detail TEXT,
|
||||||
|
created_at TIMESTAMPTZ DEFAULT NOW()
|
||||||
|
)
|
||||||
|
`).catch(() => {});
|
||||||
console.log("[StewardDash] Schema columns ready");
|
console.log("[StewardDash] Schema columns ready");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -268,6 +283,55 @@ body{background:var(--navy);color:var(--text);font-family:-apple-system,BlinkMac
|
||||||
.bio-status{font-size:0.72rem;color:var(--muted);margin-left:auto}
|
.bio-status{font-size:0.72rem;color:var(--muted);margin-left:auto}
|
||||||
|
|
||||||
a{color:inherit;text-decoration:none}
|
a{color:inherit;text-decoration:none}
|
||||||
|
|
||||||
|
/* ── tab nav ── */
|
||||||
|
.tab-nav{display:flex;align-items:center;gap:0.5rem;padding:0.6rem 2rem;border-bottom:1px solid var(--border);flex-wrap:wrap;background:var(--navy2)}
|
||||||
|
.tab-btn{padding:0.38rem 0.85rem;border-radius:20px;border:1px solid var(--border);background:transparent;color:var(--text2);font-size:0.82rem;cursor:pointer;transition:all 0.15s;display:inline-flex;align-items:center;gap:0.35rem}
|
||||||
|
.tab-btn.active{background:var(--gold);color:#07102a;border-color:var(--gold);font-weight:700}
|
||||||
|
.tab-btn:hover:not(.active){border-color:var(--gold);color:var(--gold)}
|
||||||
|
.tab-count{font-size:0.7rem;background:rgba(255,255,255,0.14);padding:0.05rem 0.45rem;border-radius:10px;min-width:1.2em;text-align:center}
|
||||||
|
.tab-btn.active .tab-count{background:rgba(0,0,0,0.18)}
|
||||||
|
|
||||||
|
/* ── corpus sources ── */
|
||||||
|
.corpus-section{padding:1.25rem 2rem;display:flex;flex-direction:column;gap:0.75rem}
|
||||||
|
.cs-toolbar{display:flex;align-items:center;gap:0.75rem;flex-wrap:wrap;margin-bottom:0.25rem}
|
||||||
|
#csStatus{font-size:0.8rem;color:var(--muted);flex:1}
|
||||||
|
.cs-list{display:flex;flex-direction:column;gap:0.65rem}
|
||||||
|
.cs-card{background:var(--navy2);border:1px solid var(--border);border-radius:10px;border-left:4px solid var(--border);padding:0.9rem 1.1rem;transition:border-color 0.2s;display:flex;align-items:flex-start;gap:1rem}
|
||||||
|
.cs-card.parked{border-left-color:var(--amber);opacity:0.6}
|
||||||
|
.cs-card.active{border-left-color:var(--green)}
|
||||||
|
.cs-main{flex:1;min-width:0}
|
||||||
|
.cs-title{font-size:0.88rem;font-weight:600;color:#fff;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;margin-bottom:0.3rem}
|
||||||
|
.cs-meta{display:flex;gap:0.45rem;flex-wrap:wrap;margin-bottom:0.4rem}
|
||||||
|
.cs-badge{font-size:0.62rem;text-transform:uppercase;letter-spacing:0.05em;padding:0.15rem 0.45rem;border-radius:3px;font-weight:700;background:rgba(255,255,255,0.07);color:var(--muted)}
|
||||||
|
.cs-badge.podcast{background:rgba(96,165,250,0.14);color:var(--blue)}
|
||||||
|
.cs-badge.article{background:rgba(74,222,128,0.1);color:#4ade80}
|
||||||
|
.cs-badge.book{background:rgba(212,167,55,0.14);color:var(--gold)}
|
||||||
|
.cs-badge.interview{background:rgba(192,132,252,0.14);color:#c084fc}
|
||||||
|
.cs-badge.parked-badge{background:rgba(245,158,11,0.14);color:var(--amber)}
|
||||||
|
.cs-badge.active-badge{background:rgba(34,197,94,0.1);color:var(--green)}
|
||||||
|
.cs-actions{display:flex;gap:0.5rem;align-items:center;flex-shrink:0}
|
||||||
|
.cs-btn{padding:0.3rem 0.7rem;border-radius:5px;border:1px solid var(--border);background:transparent;color:var(--text2);font-size:0.75rem;cursor:pointer;transition:all 0.15s;font-family:inherit;white-space:nowrap}
|
||||||
|
.cs-btn:hover{border-color:var(--gold);color:var(--gold)}
|
||||||
|
.cs-btn.park{border-color:rgba(245,158,11,0.35);color:var(--amber)}
|
||||||
|
.cs-btn.park:hover{background:rgba(245,158,11,0.09)}
|
||||||
|
.cs-btn.restore{border-color:rgba(34,197,94,0.35);color:var(--green)}
|
||||||
|
.cs-btn.restore:hover{background:rgba(34,197,94,0.09)}
|
||||||
|
|
||||||
|
/* ── activity log ── */
|
||||||
|
.activity-section{padding:1.5rem 2rem;max-width:760px}
|
||||||
|
.act-header{font-size:0.78rem;font-weight:700;color:var(--muted);text-transform:uppercase;letter-spacing:0.09em;margin-bottom:1rem}
|
||||||
|
.act-item{display:flex;gap:0.85rem;padding:0.6rem 0;border-bottom:1px solid var(--border)}
|
||||||
|
.act-item:last-child{border-bottom:none}
|
||||||
|
.act-icon{width:26px;height:26px;border-radius:50%;display:flex;align-items:center;justify-content:center;font-size:0.72rem;flex-shrink:0;background:rgba(255,255,255,0.06);margin-top:0.1rem}
|
||||||
|
.act-body{flex:1;min-width:0}
|
||||||
|
.act-what{font-size:0.82rem;color:var(--text);text-transform:capitalize}
|
||||||
|
.act-detail{font-size:0.73rem;color:var(--muted);margin-top:0.15rem;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
||||||
|
.act-when{font-size:0.7rem;color:var(--muted);white-space:nowrap;flex-shrink:0;padding-top:0.15rem}
|
||||||
|
.act-empty{font-size:0.85rem;color:var(--muted);padding:2.5rem;text-align:center}
|
||||||
|
.discover-query-wrap{margin:0.75rem 0}
|
||||||
|
.discover-query-wrap .search-input{width:100%;font-size:0.85rem}
|
||||||
|
.discover-result{background:var(--navy);border:1px solid var(--border);border-radius:5px;padding:0.6rem 0.75rem;font-size:0.72rem;font-family:monospace;color:var(--text2);white-space:pre-wrap;max-height:200px;overflow-y:auto;line-height:1.5}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
@ -331,8 +395,16 @@ a{color:inherit;text-decoration:none}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- ── Tab nav ── -->
|
||||||
|
<div class="tab-nav">
|
||||||
|
<button class="tab-btn active" onclick="switchTab('artifacts',this)">Artifacts <span class="tab-count" id="tabCountArtifacts">0</span></button>
|
||||||
|
<button class="tab-btn" onclick="switchTab('corpus',this)">Corpus Sources <span class="tab-count" id="tabCountCorpus">0</span></button>
|
||||||
|
<button class="tab-btn" onclick="switchTab('activity',this)">Activity <span class="tab-count" id="tabCountActivity"></span></button>
|
||||||
|
<button class="btn btn-outline btn-sm" style="margin-left:auto" onclick="openDiscoverModal()">+ Discover content</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- ── Filters ── -->
|
<!-- ── Filters ── -->
|
||||||
<div class="filters">
|
<div class="filters" id="artifactFilters">
|
||||||
<button class="filter-btn active" data-filter="all" onclick="setFilter('all',this)">All</button>
|
<button class="filter-btn active" data-filter="all" onclick="setFilter('all',this)">All</button>
|
||||||
<button class="filter-btn" data-filter="pending" onclick="setFilter('pending',this)">Pending</button>
|
<button class="filter-btn" data-filter="pending" onclick="setFilter('pending',this)">Pending</button>
|
||||||
<button class="filter-btn" data-filter="approved" onclick="setFilter('approved',this)">Approved</button>
|
<button class="filter-btn" data-filter="approved" onclick="setFilter('approved',this)">Approved</button>
|
||||||
|
|
@ -348,6 +420,38 @@ a{color:inherit;text-decoration:none}
|
||||||
<div class="loading-state" id="loadingState">Loading corpus artifacts…</div>
|
<div class="loading-state" id="loadingState">Loading corpus artifacts…</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- ── Corpus Sources section ── -->
|
||||||
|
<div class="corpus-section" id="corpusSection" style="display:none">
|
||||||
|
<div class="cs-toolbar">
|
||||||
|
<span id="csStatus">Loading…</span>
|
||||||
|
<button class="filter-btn active" data-csf="all" onclick="setCsFilter('all',this)">All</button>
|
||||||
|
<button class="filter-btn" data-csf="active" onclick="setCsFilter('active',this)">Active</button>
|
||||||
|
<button class="filter-btn" data-csf="parked" onclick="setCsFilter('parked',this)">Parked</button>
|
||||||
|
</div>
|
||||||
|
<div class="cs-list" id="csList"><div class="loading-state">Loading corpus sources…</div></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- ── Activity section ── -->
|
||||||
|
<div class="activity-section" id="activitySection" style="display:none">
|
||||||
|
<div class="act-list" id="actList"><div class="act-empty">Loading activity…</div></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- ── Discover modal ── -->
|
||||||
|
<div class="modal-overlay hidden" id="discoverModal">
|
||||||
|
<div class="modal">
|
||||||
|
<h2>Discover new content</h2>
|
||||||
|
<p>Let Ody search for books, articles, and other sources not yet in the corpus. Results appear here for review — nothing is added automatically.</p>
|
||||||
|
<div class="discover-query-wrap">
|
||||||
|
<input class="search-input" type="text" id="discoverQuery" placeholder='e.g. "books by Guy Kawasaki" or leave blank for all types'>
|
||||||
|
</div>
|
||||||
|
<div class="discover-result" id="discoverLog">Ready.</div>
|
||||||
|
<div class="modal-actions">
|
||||||
|
<button class="btn btn-outline" onclick="closeDiscoverModal()">Close</button>
|
||||||
|
<button class="btn btn-gold" id="btnDiscoverConfirm" onclick="doDiscover()">Find content</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- ── Build panel ── -->
|
<!-- ── Build panel ── -->
|
||||||
<div class="build-panel" id="buildPanel">
|
<div class="build-panel" id="buildPanel">
|
||||||
<span style="font-size:0.85rem;font-weight:600;color:var(--gold)">Building corpus…</span>
|
<span style="font-size:0.85rem;font-weight:600;color:var(--gold)">Building corpus…</span>
|
||||||
|
|
@ -378,7 +482,215 @@ let currentFilter = 'all';
|
||||||
|
|
||||||
// ── Bootstrap ──────────────────────────────────────────────────────────────
|
// ── Bootstrap ──────────────────────────────────────────────────────────────
|
||||||
async function init() {
|
async function init() {
|
||||||
await Promise.all([loadArtifacts(), loadBioFacts()]);
|
await Promise.all([loadArtifacts(), loadBioFacts(), loadCatalogSources(), loadActivity()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Tab switching ──────────────────────────────────────────────────────────
|
||||||
|
function switchTab(tab, btn) {
|
||||||
|
document.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active'));
|
||||||
|
btn.classList.add('active');
|
||||||
|
const filters = document.getElementById('artifactFilters');
|
||||||
|
const artifacts = document.getElementById('artifactsContainer');
|
||||||
|
const corpus = document.getElementById('corpusSection');
|
||||||
|
const activity = document.getElementById('activitySection');
|
||||||
|
if (tab === 'artifacts') {
|
||||||
|
filters.style.display = '';
|
||||||
|
artifacts.style.display = '';
|
||||||
|
corpus.style.display = 'none';
|
||||||
|
activity.style.display = 'none';
|
||||||
|
} else if (tab === 'corpus') {
|
||||||
|
filters.style.display = 'none';
|
||||||
|
artifacts.style.display = 'none';
|
||||||
|
corpus.style.display = '';
|
||||||
|
activity.style.display = 'none';
|
||||||
|
} else {
|
||||||
|
filters.style.display = 'none';
|
||||||
|
artifacts.style.display = 'none';
|
||||||
|
corpus.style.display = 'none';
|
||||||
|
activity.style.display = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Catalog Sources ─────────────────────────────────────────────────────────
|
||||||
|
let allCatalogSources = [];
|
||||||
|
let csLoaded = false;
|
||||||
|
let csFilter = 'all';
|
||||||
|
let actLoaded = false;
|
||||||
|
|
||||||
|
function setCsFilter(f, el) {
|
||||||
|
csFilter = f;
|
||||||
|
document.querySelectorAll('[data-csf]').forEach(b => b.classList.remove('active'));
|
||||||
|
el.classList.add('active');
|
||||||
|
renderCatalogSources();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadCatalogSources() {
|
||||||
|
const listEl = document.getElementById('csList');
|
||||||
|
const statusEl = document.getElementById('csStatus');
|
||||||
|
if (!listEl) return;
|
||||||
|
try {
|
||||||
|
const r = await fetch('/api/steward/' + SLUG + '/catalog-sources?token=' + TOKEN);
|
||||||
|
if (!r.ok) {
|
||||||
|
if (r.status === 403) { listEl.innerHTML = '<div class="empty-state"><p>Invalid token.</p></div>'; return; }
|
||||||
|
throw new Error(await r.text());
|
||||||
|
}
|
||||||
|
const data = await r.json();
|
||||||
|
allCatalogSources = data.sources || [];
|
||||||
|
csLoaded = true;
|
||||||
|
const countEl = document.getElementById('tabCountCorpus');
|
||||||
|
if (countEl) countEl.textContent = allCatalogSources.length;
|
||||||
|
if (statusEl) statusEl.textContent = allCatalogSources.length + ' sources in corpus';
|
||||||
|
renderCatalogSources();
|
||||||
|
} catch(e) {
|
||||||
|
listEl.innerHTML = '<div class="empty-state"><h2>Error</h2><p>' + esc(e.message) + '</p></div>';
|
||||||
|
if (statusEl) statusEl.textContent = 'Error loading';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderCatalogSources() {
|
||||||
|
const listEl = document.getElementById('csList');
|
||||||
|
if (!listEl) return;
|
||||||
|
let visible = allCatalogSources.filter(s => {
|
||||||
|
if (csFilter === 'active') return s.catalog_status !== 'parked';
|
||||||
|
if (csFilter === 'parked') return s.catalog_status === 'parked';
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
if (!visible.length) {
|
||||||
|
listEl.innerHTML = '<div class="empty-state"><h2>No sources</h2><p>Try a different filter or use Discover to find new content.</p></div>';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
listEl.innerHTML = visible.map(s => catalogCardHTML(s)).join('');
|
||||||
|
}
|
||||||
|
|
||||||
|
function catalogCardHTML(s) {
|
||||||
|
const parked = s.catalog_status === 'parked';
|
||||||
|
const type = (s.type || 'article').toLowerCase();
|
||||||
|
const chunks = s.chunk_count ? s.chunk_count + ' chunks' : '';
|
||||||
|
let domain = '';
|
||||||
|
try {
|
||||||
|
if (s.url && !s.url.startsWith('podcast://')) domain = new URL(s.url).hostname.replace('www.', '');
|
||||||
|
} catch {}
|
||||||
|
return \`<div class="cs-card \${parked ? 'parked' : 'active'}" id="cscard-\${s.id}">
|
||||||
|
<div class="cs-main">
|
||||||
|
<div class="cs-title" title="\${esc(s.title || s.url)}">\${esc(s.title || s.url)}</div>
|
||||||
|
<div class="cs-meta">
|
||||||
|
<span class="cs-badge \${type}">\${type}</span>
|
||||||
|
\${chunks ? \`<span class="cs-badge">\${esc(chunks)}</span>\` : ''}
|
||||||
|
\${domain ? \`<span class="cs-badge">\${esc(domain)}</span>\` : ''}
|
||||||
|
<span class="cs-badge \${parked ? 'parked-badge' : 'active-badge'}">\${parked ? 'Parked' : 'Active'}</span>
|
||||||
|
</div>
|
||||||
|
\${s.url && !s.url.startsWith('podcast://') ? \`<a href="\${esc(s.url)}" target="_blank" rel="noopener" style="font-size:0.72rem;color:var(--muted)">View source ↗</a>\` : ''}
|
||||||
|
</div>
|
||||||
|
<div class="cs-actions">
|
||||||
|
\${parked
|
||||||
|
? \`<button class="cs-btn restore" onclick="togglePark(\${s.id},false)">↩ Restore</button>\`
|
||||||
|
: \`<button class="cs-btn park" onclick="togglePark(\${s.id},true)">⊘ Park</button>\`
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>\`;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function togglePark(id, park) {
|
||||||
|
const card = document.getElementById('cscard-' + id);
|
||||||
|
const btn = card ? card.querySelector('.cs-btn') : null;
|
||||||
|
if (btn) { btn.disabled = true; btn.textContent = '…'; }
|
||||||
|
try {
|
||||||
|
const r = await fetch('/api/steward/' + SLUG + '/catalog-sources/' + id, {
|
||||||
|
method: 'PATCH',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ token: TOKEN, action: park ? 'park' : 'restore' }),
|
||||||
|
});
|
||||||
|
if (!r.ok) throw new Error(await r.text());
|
||||||
|
const s = allCatalogSources.find(x => x.id === id);
|
||||||
|
if (s) s.catalog_status = park ? 'parked' : 'active';
|
||||||
|
renderCatalogSources();
|
||||||
|
actLoaded = false;
|
||||||
|
loadActivity();
|
||||||
|
} catch(e) {
|
||||||
|
alert('Could not save: ' + e.message);
|
||||||
|
if (btn) { btn.disabled = false; btn.textContent = park ? '⊘ Park' : '↩ Restore'; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Activity log ──────────────────────────────────────────────────────────
|
||||||
|
async function loadActivity() {
|
||||||
|
const listEl = document.getElementById('actList');
|
||||||
|
if (!listEl) return;
|
||||||
|
try {
|
||||||
|
const r = await fetch('/api/steward/' + SLUG + '/activity?token=' + TOKEN);
|
||||||
|
if (!r.ok) throw new Error(await r.text());
|
||||||
|
const data = await r.json();
|
||||||
|
const items = data.items || [];
|
||||||
|
actLoaded = true;
|
||||||
|
const countEl = document.getElementById('tabCountActivity');
|
||||||
|
if (countEl) countEl.textContent = items.length > 0 ? String(items.length) : '';
|
||||||
|
if (!items.length) {
|
||||||
|
listEl.innerHTML = '<div class="act-empty">No activity recorded yet. Actions like parking sources or discovering content will appear here.</div>';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const icons = {park:'⊘',restore:'↩',discover:'⌕',build:'⚙',fetch:'⬇',curation:'✓'};
|
||||||
|
listEl.innerHTML = '<div class="act-header">Recent activity</div>' + items.map(item => {
|
||||||
|
const icon = icons[item.action] || '·';
|
||||||
|
const when = item.created_at ? new Date(item.created_at).toLocaleString() : '';
|
||||||
|
return \`<div class="act-item">
|
||||||
|
<div class="act-icon">\${esc(icon)}</div>
|
||||||
|
<div class="act-body">
|
||||||
|
<div class="act-what">\${esc(item.action)}</div>
|
||||||
|
\${item.target_title ? \`<div class="act-detail">\${esc(item.target_title)}</div>\` : ''}
|
||||||
|
\${item.detail ? \`<div class="act-detail" style="color:var(--text2)">\${esc(item.detail)}</div>\` : ''}
|
||||||
|
</div>
|
||||||
|
<div class="act-when">\${esc(when)}</div>
|
||||||
|
</div>\`;
|
||||||
|
}).join('');
|
||||||
|
} catch(e) {
|
||||||
|
listEl.innerHTML = '<div class="act-empty">Error loading activity: ' + esc(e.message) + '</div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Discover content ──────────────────────────────────────────────────────
|
||||||
|
function openDiscoverModal() {
|
||||||
|
document.getElementById('discoverLog').textContent = 'Ready to search for new sources.';
|
||||||
|
document.getElementById('discoverQuery').value = '';
|
||||||
|
document.getElementById('discoverModal').classList.remove('hidden');
|
||||||
|
document.getElementById('btnDiscoverConfirm').disabled = false;
|
||||||
|
document.getElementById('btnDiscoverConfirm').textContent = 'Find content';
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeDiscoverModal() {
|
||||||
|
document.getElementById('discoverModal').classList.add('hidden');
|
||||||
|
}
|
||||||
|
|
||||||
|
async function doDiscover() {
|
||||||
|
const logEl = document.getElementById('discoverLog');
|
||||||
|
const btn = document.getElementById('btnDiscoverConfirm');
|
||||||
|
const query = document.getElementById('discoverQuery').value.trim();
|
||||||
|
btn.disabled = true;
|
||||||
|
btn.textContent = 'Searching…';
|
||||||
|
logEl.textContent = 'Asking Ody to find new content…';
|
||||||
|
try {
|
||||||
|
const r = await fetch('/api/steward/' + SLUG + '/discover', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ token: TOKEN, query }),
|
||||||
|
});
|
||||||
|
const data = await r.json();
|
||||||
|
if (!r.ok) throw new Error(data.error || 'Discover failed');
|
||||||
|
const found = data.suggestions || [];
|
||||||
|
if (!found.length) {
|
||||||
|
logEl.textContent = 'No new sources found. Try a more specific query.';
|
||||||
|
} else {
|
||||||
|
logEl.textContent = 'Found ' + found.length + ' potential source(s):\\n\\n' +
|
||||||
|
found.map((s, i) => (i+1) + '. ' + (s.title || 'Untitled') + '\\n ' + (s.url || '') + (s.note ? '\\n ' + s.note : '')).join('\\n\\n');
|
||||||
|
}
|
||||||
|
btn.textContent = 'Search again';
|
||||||
|
btn.disabled = false;
|
||||||
|
actLoaded = false;
|
||||||
|
loadActivity();
|
||||||
|
} catch(e) {
|
||||||
|
logEl.textContent = 'Error: ' + e.message;
|
||||||
|
btn.disabled = false;
|
||||||
|
btn.textContent = 'Try again';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Biographical Baseline ──────────────────────────────────────────────────
|
// ── Biographical Baseline ──────────────────────────────────────────────────
|
||||||
|
|
@ -899,6 +1211,108 @@ export function registerStewardRoutes(app: Express) {
|
||||||
res.json({ ok: true });
|
res.json({ ok: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// ── GET /api/steward/:slug/catalog-sources ──────────────────────────────
|
||||||
|
app.get("/api/steward/:slug/catalog-sources", async (req: Request, res: Response) => {
|
||||||
|
const { slug } = req.params;
|
||||||
|
const token = req.query.token as string;
|
||||||
|
if (!await validateStewardToken(slug, token)) return res.status(403).json({ error: "Invalid token" });
|
||||||
|
|
||||||
|
const { rows } = await pool.query(
|
||||||
|
`SELECT id, url, title, type, chunk_count, catalog_status, ingested_at
|
||||||
|
FROM agentify_source_catalog WHERE expert_slug = $1
|
||||||
|
ORDER BY type ASC, title ASC NULLS LAST`,
|
||||||
|
[slug]
|
||||||
|
);
|
||||||
|
res.json({ sources: rows });
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── PATCH /api/steward/:slug/catalog-sources/:id ─────────────────────────
|
||||||
|
app.patch("/api/steward/:slug/catalog-sources/:id", express.json({ limit: "1mb" }), async (req: Request, res: Response) => {
|
||||||
|
const { slug, id } = req.params;
|
||||||
|
const { token, action } = req.body;
|
||||||
|
if (!await validateStewardToken(slug, token)) return res.status(403).json({ error: "Invalid token" });
|
||||||
|
if (!["park", "restore"].includes(action)) return res.status(400).json({ error: "action must be 'park' or 'restore'" });
|
||||||
|
|
||||||
|
const newStatus = action === "park" ? "parked" : "active";
|
||||||
|
const { rows } = await pool.query(
|
||||||
|
`UPDATE agentify_source_catalog SET catalog_status = $1 WHERE id = $2 AND expert_slug = $3 RETURNING title, url`,
|
||||||
|
[newStatus, id, slug]
|
||||||
|
);
|
||||||
|
if (!rows[0]) return res.status(404).json({ error: "Source not found" });
|
||||||
|
|
||||||
|
await pool.query(
|
||||||
|
`INSERT INTO steward_audit_log (subject_slug, actor, action, target_url, target_title, detail)
|
||||||
|
VALUES ($1, 'steward', $2, $3, $4, $5)`,
|
||||||
|
[slug, action, rows[0].url, rows[0].title, `Status set to ${newStatus}`]
|
||||||
|
).catch(() => {});
|
||||||
|
|
||||||
|
res.json({ ok: true, status: newStatus });
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── POST /api/steward/:slug/discover ─────────────────────────────────────
|
||||||
|
app.post("/api/steward/:slug/discover", express.json({ limit: "1mb" }), async (req: Request, res: Response) => {
|
||||||
|
const { slug } = req.params;
|
||||||
|
const { token, query } = req.body;
|
||||||
|
if (!await validateStewardToken(slug, token)) return res.status(403).json({ error: "Invalid token" });
|
||||||
|
|
||||||
|
const { rows: pf } = await pool.query(`SELECT subject_name FROM personaforge_subjects WHERE slug = $1`, [slug]);
|
||||||
|
const subjectName = pf[0]?.subject_name || slug;
|
||||||
|
|
||||||
|
const { rows: existing } = await pool.query(
|
||||||
|
`SELECT url FROM agentify_source_catalog WHERE expert_slug = $1`, [slug]
|
||||||
|
);
|
||||||
|
const existingUrls = new Set(existing.map((r: any) => r.url));
|
||||||
|
const skipList = [...existingUrls].slice(0, 30).join("\n");
|
||||||
|
|
||||||
|
const systemPrompt = `You are a research librarian helping build an authoritative corpus for "${subjectName}".
|
||||||
|
Find content sources NOT already in the corpus. Focus on books (publisher page or Google Books URL), landmark articles, and notable interviews.
|
||||||
|
Return a JSON array — no markdown fences — of objects: { "title": string, "url": string, "type": "book"|"article"|"podcast"|"interview", "note": string }`;
|
||||||
|
|
||||||
|
const userMsg = query
|
||||||
|
? `Find new sources matching: ${query}\n\nSkip these already-indexed URLs:\n${skipList}`
|
||||||
|
: `Find books, long-form articles, and notable interviews by or about ${subjectName}.\n\nSkip these already-indexed URLs:\n${skipList}`;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const Anthropic = (await import("@anthropic-ai/sdk")).default;
|
||||||
|
const ai = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
|
||||||
|
const msg = await ai.messages.create({
|
||||||
|
model: "claude-opus-4-5",
|
||||||
|
max_tokens: 1024,
|
||||||
|
system: systemPrompt,
|
||||||
|
messages: [{ role: "user", content: userMsg }],
|
||||||
|
});
|
||||||
|
const text = ((msg.content[0] as any).text || "[]").trim();
|
||||||
|
let suggestions: any[] = [];
|
||||||
|
try { suggestions = JSON.parse(text); } catch { suggestions = []; }
|
||||||
|
suggestions = suggestions.filter((s: any) => s.url && !existingUrls.has(s.url));
|
||||||
|
|
||||||
|
await pool.query(
|
||||||
|
`INSERT INTO steward_audit_log (subject_slug, actor, action, detail)
|
||||||
|
VALUES ($1, 'steward', 'discover', $2)`,
|
||||||
|
[slug, `Found ${suggestions.length} suggestion(s)${query ? ` for: ${query}` : ""}`]
|
||||||
|
).catch(() => {});
|
||||||
|
|
||||||
|
res.json({ ok: true, suggestions });
|
||||||
|
} catch (e: any) {
|
||||||
|
res.status(500).json({ error: e.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── GET /api/steward/:slug/activity ──────────────────────────────────────
|
||||||
|
app.get("/api/steward/:slug/activity", async (req: Request, res: Response) => {
|
||||||
|
const { slug } = req.params;
|
||||||
|
const token = req.query.token as string;
|
||||||
|
if (!await validateStewardToken(slug, token)) return res.status(403).json({ error: "Invalid token" });
|
||||||
|
|
||||||
|
const { rows } = await pool.query(
|
||||||
|
`SELECT id, actor, action, target_title, detail, created_at
|
||||||
|
FROM steward_audit_log WHERE subject_slug = $1
|
||||||
|
ORDER BY created_at DESC LIMIT 100`,
|
||||||
|
[slug]
|
||||||
|
);
|
||||||
|
res.json({ items: rows });
|
||||||
|
});
|
||||||
|
|
||||||
// ── POST /api/steward/:slug/artifacts/:artifact_id/ody-ask ──────────────
|
// ── POST /api/steward/:slug/artifacts/:artifact_id/ody-ask ──────────────
|
||||||
app.post("/api/steward/:slug/artifacts/:artifact_id/ody-ask", async (req: Request, res: Response) => {
|
app.post("/api/steward/:slug/artifacts/:artifact_id/ody-ask", async (req: Request, res: Response) => {
|
||||||
const { slug, artifact_id } = req.params;
|
const { slug, artifact_id } = req.params;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue