Merge LinkSpin knowledge-base chatbot (Banner Spin answer moved into a KB entry)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-20 05:52:02 -05:00
11 changed files with 753 additions and 46 deletions
+24
View File
@@ -23,6 +23,7 @@ const drip = require('./drip');
const spaces = require('./spaces'); // DO Spaces video storage (inert unless DO_SPACES_* set)
let QR = null; try { QR = require('qrcode'); } catch (e) { /* optional */ }
const chatbot = require('./chatbot');
const kb = require('./kb'); // the assistant's knowledge base: Admin > Knowledge base, seeded from chatbot.js CANNED + kb-seed.js (2026-10-20)
const coach = require('./coach'); // coaching view, nudges, digest, prospects, link stats
const tank = require('./tank'); // holding tank: unsponsored free members, adoptions, pay-it-forward
const legacy = require('./legacy'); // Faucet Wave / Tier One Ads bridge: welcome-back credits for listed emails
@@ -1398,6 +1399,29 @@ const server = http.createServer(async (req, res) => {
const r = await chatbot.answer(b.message, b.history);
return json(res, r.error ? 400 : 200, r);
}
if (p === '/api/chat/kb-stamp' && req.method === 'GET') { // the newest knowledge-base edit by a person (Central day) and the entry count
return json(res, 200, await kb.stamp(), { 'Cache-Control': 'no-store' });
}
// -- the assistant's knowledge base, admin side (2026-10-20, kb.js): list, search, add, edit, delete, try a question
if (p === '/api/admin/kb' && (req.method === 'GET' || req.method === 'POST')) {
if (!isAdmin(req)) return json(res, 401, { error: 'auth' });
if (req.method === 'GET') return json(res, 200, { entries: await kb.list(u.searchParams.get('q') || ''), stamp: await kb.stamp() }, { 'Cache-Control': 'no-store' });
const r = await kb.create(await readBody(req));
return json(res, r.error ? 400 : 200, r);
}
if (p === '/api/admin/kb/test' && req.method === 'POST') {
if (!isAdmin(req)) return json(res, 401, { error: 'auth' });
const b = await readBody(req);
return json(res, 200, await kb.test(b.question));
}
const kbm = /^\/api\/admin\/kb\/([a-z0-9-]{1,64})$/.exec(p);
if (kbm) {
if (!isAdmin(req)) return json(res, 401, { error: 'auth' });
if (req.method === 'GET') { const e = await kb.get(kbm[1]); return e ? json(res, 200, { entry: e }) : json(res, 404, { error: 'Entry not found.' }); }
if (req.method === 'PUT') { const r = await kb.update(kbm[1], await readBody(req)); return json(res, r.error ? (r.error === 'Entry not found.' ? 404 : 400) : 200, r); }
if (req.method === 'DELETE') { const r = await kb.remove(kbm[1]); return json(res, r.error ? 404 : 200, r); }
return json(res, 405, { error: 'method' });
}
// -- help desk (2026-10-16, helpdesk.js): the tickets live on InstantAdPay's one shared desk; these routes check the
// person (session or the support guard) and proxy. Public side first: the /support form, the private ticket link,