Chat knowledge base: the assistant answers from maintained entries, and support replies become entries
- kb.js: entries { id, title, questions, answer, tags, pattern, handoff, order, source, updated } in MySQL table kb_entries (created on boot) or DATA_DIR/kb.json without DATABASE_URL. BM25 over title, question variants and tags (answer at a low weight) with word bigrams; the top hits (within 30% of the best, score 3+) go into the system prompt as KNOWLEDGE BASE, and when nothing fits the prompt says to answer "I'm not sure, ask support".
- One source: chatbot.js CANNED seeds the KB (ids c-*, its regex becomes the entry's instant-answer pattern, same first-match order), kb-seed.js seeds the home FAQ, Platform Facts, wallets FAQ and the Coinbase support reply (f-*). The fast path now serves the KB entry, so an admin edit changes the instant answer; the in-code CANNED only answers if the KB store fails. Unedited seeds follow code changes, edited ones are left alone, deleted seeds stay deleted.
- Admin > Knowledge base: list, search, filter by source, add, edit, delete, and Try a question (instant answer or what the AI is given). Support tickets: "Save as KB entry" under each sent reply opens a draft with the member's question and the reply (greeting and sign-off trimmed). Em dashes in admin input become commas.
- chatbot.js: OPENROUTER_URL override for tests; solo-ads answer em dash removed; KNOWLEDGE_DATE 2026-10-20.
- qa/chatbot-sync.mjs: takes the later of KNOWLEDGE_DATE and /api/chat/kb-stamp (newest KB edit by a person, Central day; seed refreshes do not count).
- QA: qa/kb-retrieval.cjs (13 sample questions rank the right entry first, off-topic returns nothing), qa/kb-chat.mjs (local copy + mock OpenRouter: Coinbase answered from the KB, fast path without an AI call, admin CRUD, restart keeps edits), bash qa/run.sh kb; walk covers admin#kb and Save as KB entry.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+15
-1
@@ -177,7 +177,7 @@ if (MODE === 'member' || MODE === 'all') {
|
||||
// admin
|
||||
await page.goto(LOCAL + '/admin', { waitUntil: 'networkidle' });
|
||||
await page.fill('#adEmail', process.env.ADMIN_EMAIL || 'martybostick@gmail.com'); await page.click('#adSend'); await page.waitForSelector('#adVerify:not([hidden])'); await page.click('#adVerify'); await page.waitForTimeout(1200);
|
||||
for (const pn of ['overview', 'house', 'campaigns', 'members', 'support', 'reports', 'traffic', 'blog', 'releases', 'pnl', 'gamepass', 'settings']) {
|
||||
for (const pn of ['overview', 'house', 'campaigns', 'members', 'support', 'reports', 'traffic', 'blog', 'releases', 'pnl', 'gamepass', 'kb', 'settings']) {
|
||||
const label = L + 'admin#' + pn;
|
||||
await page.click('.bo-menu [data-pane="' + pn + '"]'); await page.waitForTimeout(1200);
|
||||
const vis = await page.evaluate(id => { const el = document.getElementById('pane-' + id); return el && !el.hidden && el.offsetHeight > 40; }, pn);
|
||||
@@ -206,6 +206,20 @@ if (MODE === 'member' || MODE === 'all') {
|
||||
if (!/internal note/.test(txt) || !/Waiting on member/.test(await page.$eval('#spSt', e => e.selectedOptions[0].textContent).catch(() => ''))) note('bug', L + 'admin#support', 'note/reply/status not reflected');
|
||||
await page.selectOption('#spPr', 'high'); await page.waitForTimeout(800);
|
||||
await domChecks(page, L + 'admin#support (ticket)'); console.log('ok admin Support ticket', helpRef);
|
||||
// "Save as KB entry" under the reply: a prefilled knowledge-base draft (question from the member, answer from the reply) that saves
|
||||
flush(bag, L + 'admin#support (ticket)');
|
||||
const save = await page.$('#spView [data-kbsave]');
|
||||
if (!save) note('bug', L + 'admin#support', 'no "Save as KB entry" button under the sent reply');
|
||||
else {
|
||||
await save.click(); await page.waitForTimeout(1200);
|
||||
const draft = await page.evaluate(() => ({ q: (document.getElementById('kbQs') || {}).value || '', a: (document.getElementById('kbAns') || {}).value || '', vis: !document.getElementById('kbEdit').hidden }));
|
||||
if (!draft.vis || !draft.q.trim() || !draft.a.trim()) note('bug', L + 'admin#kb', 'Save as KB entry did not open a prefilled draft ' + JSON.stringify(draft).slice(0, 160));
|
||||
await domChecks(page, L + 'admin#kb (draft from ticket)');
|
||||
await page.click('#kbSave'); await page.waitForTimeout(1200);
|
||||
const listed = await page.$eval('#kbTable', e => e.textContent).catch(() => '');
|
||||
if (!/from a ticket/.test(listed)) note('bug', L + 'admin#kb', 'entry saved from the ticket is not in the list');
|
||||
flush(bag, L + 'admin#kb (saved from ticket)'); console.log('ok admin Save as KB entry');
|
||||
}
|
||||
}
|
||||
flush(bag, L + 'admin#support (ticket)');
|
||||
await page.screenshot({ path: OUT + '/admin-support-ticket.png' }).catch(() => {});
|
||||
|
||||
Reference in New Issue
Block a user