Site assistant (Marty 2026-11-15): chat widget in the Downline Banners ultraviolet + lime look on every page, CANNED + FACTS from this repo's code and the BannerLine contract ($5 spot, 300 views in 30 days, 30% sponsor + 55% as $0.275 x 10 + 10% company + 5% momentum fund, fund buys after 4 h quiet, max 12 a day, 7-day gift cooldown, look-around tour, buy for someone, refuel spots, 468x60 up to 150 KB), retrieval over the shared network knowledge base on the hub (netkb.js, home entries boosted, another site named = its answer), reasoning off, account problems hand off to network support. Chat admin routes use a constant-time ADMIN_TOKEN check. chatbot.test 165, smoke 131/131

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-15 13:07:32 -06:00
parent da20e3e0ec
commit 0aaea45a5c
21 changed files with 950 additions and 1 deletions
+22
View File
@@ -0,0 +1,22 @@
{
"site": "bannerline",
"home": [
{ "q": "What is Downline Banners?", "kb": "about", "must": ["468x60", "300 guaranteed views", "Nothing is promised"] },
{ "q": "How much is a spot and what does it buy?", "kb": "spot", "must": ["\\$5", "300", "30 days"] },
{ "q": "Where does the $5 go?", "kb": "split", "must": ["30%", "55%", "\\$0.275", "10%", "5%"] },
{ "q": "What do I get when someone I referred buys?", "kb": "split", "must": ["\\$1.50"] },
{ "q": "What size is the banner?", "kb": "banner", "must": ["468x60", "150 KB"] },
{ "q": "What is the momentum fund?", "kb": "fund", "must": ["4 hours", "7 days"] },
{ "q": "Why is Join locked?", "kb": "tour", "must": ["timer"] },
{ "q": "Can I buy a spot for someone else?", "kb": "buy-for", "must": ["wallet address"] },
{ "q": "Which wallet should I use?", "kb": "wallet", "must": ["SafePal or any other crypto wallet"] },
{ "q": "Is this a pyramid scheme?", "kb": "safe", "must": ["contract", "less than the \\$5"] }
],
"cross": [
{ "q": "How does Viral Banner Blitz work?", "site": "vbb" },
{ "q": "What is a ViralAdBlitz Boost?", "site": "viraladblitz" },
{ "q": "What does DownlineHydra Pro cost?", "site": "downlinehydra" },
{ "q": "What is a LinkSpin spin link?", "site": "linkspin" },
{ "q": "How does the 5xYourTeam draft work?", "site": "fivex" }
]
}
+87
View File
@@ -0,0 +1,87 @@
// Site assistant checks (2026-11-15): node qa/chatbot.test.mjs
// No network: a stand-in OpenRouter and a stand-in hub. Checks the instant answers route every example question to its own entry,
// the house rules (no em dashes, no MetaMask, never RM Circle, ad-credits line where credits come up, no income promises),
// the network merge (home boosted, a named site boosted), the support hand-off, and the site's scripted Q&A (qa/chat-qa.json:
// home questions must land on the named entry and contain the expected facts).
// The SAME file ships in every rebuilt network site.
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import http from 'node:http';
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const ROOT = path.resolve(path.dirname(new URL(import.meta.url).pathname.replace(/^\/([A-Za-z]:)/, '$1')), '..');
const DIR = fs.mkdtempSync(path.join(os.tmpdir(), 'chat-'));
process.env.DATA_DIR = DIR; delete process.env.DOCSTORE_URL; process.env.NETKB = '0'; delete process.env.OPENROUTER_API_KEY;
let pass = 0, fail = 0; const bad = [];
const ok = (c, m) => { if (c) pass++; else { fail++; bad.push(m); console.log('FAIL', m); } };
// stand-in OpenRouter: answers with what the system prompt says about the first KB entry, so we can see the prompt
let lastPrompt = '', reply = 'Fine.';
const or = http.createServer((req, res) => { let b = ''; req.on('data', c => { b += c; }); req.on('end', () => {
const j = JSON.parse(b); lastPrompt = j.messages[0].content; ok(j.reasoning && j.reasoning.enabled === false, 'reasoning is switched off');
res.writeHead(200, { 'Content-Type': 'application/json' }); res.end('\n\n' + JSON.stringify({ choices: [{ message: { content: reply } }] })); }); });
await new Promise(r => or.listen(0, r));
process.env.OPENROUTER_URL = 'http://127.0.0.1:' + or.address().port + '/v1/chat/completions';
const cfg = require(path.join(ROOT, 'config.js')); if (cfg.reset) cfg.reset();
const bot = require(path.join(ROOT, 'chatbot.js'));
const core = require(path.join(ROOT, 'chatcore.js'));
const kb = require(path.join(ROOT, 'kb.js'));
const netkb = require(path.join(ROOT, 'netkb.js'));
const dataDir = bot.SITE.dataDir;
await bot.init();
// 1. seeds and the fast path: every example question of a canned entry lands on that entry (first match wins)
const seeds = core.seeds();
ok(seeds.length >= 12, 'at least 12 seeded entries (' + seeds.length + ')');
for (const c of bot.CANNED) {
ok(c.re instanceof RegExp, c.id + ' has a pattern');
for (const q of c.q || []) { const hit = await kb.fastPath(q); ok(hit && hit.id === 'c-' + c.id, 'example "' + q + '" -> ' + c.id + ' (got ' + (hit && hit.id) + ')'); }
}
// 2. house rules in every seeded answer
for (const s of seeds) {
ok(!/[—―]/.test(s.answer + s.title), s.id + ': no em dashes');
ok(!/metamask/i.test(s.answer), s.id + ': never recommends MetaMask');
ok(!/rm ?circle/i.test(s.answer), s.id + ': never RM Circle');
ok(!/(guarantee[ds]? (income|earnings|profit)|you will (earn|make)|passive income|get rich|up to \$?\d[\d,.]* (a|per) (day|week|month))/i.test(s.answer), s.id + ': no income promise');
if (/\bad credits?\b/i.test(s.answer)) ok(/Ad credits buy advertising, not income\./.test(s.answer), s.id + ': ad credits line');
if (/wallet/i.test(s.answer) && /(which|use|recommend)/i.test(s.answer) && /safepal/i.test(s.answer)) ok(/SafePal or any other crypto wallet/i.test(s.answer), s.id + ': wallet wording');
}
// 3. the engine: scrub, support hand-off, the AI path
ok(core.scrub('A — B, use MetaMask or SafePal') === 'A, B, use SafePal', 'scrub: em dash and MetaMask (' + core.scrub('A — B, use MetaMask or SafePal') + ')');
{ const r = await bot.answer('I need to talk to a real person about my account'); ok(r.handoff === true, 'asking for a person hands off'); }
{ const r = await bot.answer(''); ok(!!r.error, 'empty question refused'); }
fs.writeFileSync(path.join(dataDir || DIR, 'openrouter.key'), 'test-key');
reply = 'Sure — try RM Circle'; { const r = await bot.answer('zzqx unrelated words nobody wrote down'); ok(!/rm ?circle/i.test(r.reply) && !/—/.test(r.reply), 'an RM Circle or em dash reply never leaves (' + r.reply + ')'); }
ok(/NEVER promise or estimate income/.test(lastPrompt) && /SafePal or any other crypto wallet/.test(lastPrompt) && /Ad credits buy advertising, not income\./.test(lastPrompt), 'house rules in the system prompt');
reply = 'Fine.';
// 4. the network merge: home boosted, a named site boosted, labelled with the site and its link
const GENERAL = bot.CANNED.find(c => !['support', 'refund', 'about'].includes(c.id) && (c.q || []).length).q[0].replace(/\?$/, '');
netkb._set({ version: 'v1', sites: { othersite: { name: 'Other Site', url: 'https://other.example', count: 1 }, [process.env.HUB_SITE || bot.SITE.hubSite]: { name: bot.SITE.name, url: bot.SITE.url } },
entries: [{ site: 'othersite', id: 'about', title: 'What is Other Site?', questions: ['What is Other Site?', GENERAL + ' on Other Site'], answer: 'Other Site is a test site with its own rules.', tags: ['test'] }] });
await kb.load(true);
{ const hits = await kb.search(GENERAL, 8); const top = hits[0] && hits[0].entry; ok(top && !top.site, 'home entries first for a general question (top ' + (top && top.id) + ')'); }
{ const hits = await kb.search(GENERAL + ' on Other Site', 8); const top = hits[0] && hits[0].entry; ok(top && top.site === 'othersite', 'a named site boosts its own entry (top ' + (top && top.id) + ')'); }
{ const block = kb.promptBlock(await kb.context('What is Other Site', 6)); ok(/about Other Site, another network site; send people to https:\/\/other\.example/.test(block), 'remote entry labelled with site and link'); }
{ const fp = await kb.fastPath('What is Other Site?'); ok(!fp || !String(fp.id).startsWith('othersite:'), 'other sites never take the fast path'); }
{ const r = await bot.answer(GENERAL + ' on Other Site'); ok(!r.canned, 'a question naming another site skips this site\'s instant answers (' + r.kb + ')'); }
{ const r = await bot.answer('I need a real person, my order on Other Site failed'); ok(r.handoff === true, 'a hand-off still wins when another site is named'); }
{ const r = await bot.answer(bot.CANNED.find(c => c.id === 'about').q[0]); ok(r.canned && r.kb === 'c-about', 'this site\'s own name keeps the instant answer'); }
{ const own = await kb.own(); ok(own.length === seeds.length && own.every(e => !e.site), 'publish set = this site\'s own entries only'); }
// 5. the scripted Q&A (home questions)
const qaFile = path.join(ROOT, 'qa', 'chat-qa.json');
if (fs.existsSync(qaFile)) {
const qa = JSON.parse(fs.readFileSync(qaFile, 'utf8'));
for (const t of qa.home || []) {
const r = await bot.answer(t.q);
if (t.kb) ok(r.kb === 'c-' + t.kb || (Array.isArray(r.kb) && r.kb.includes('c-' + t.kb)), 'Q&A "' + t.q + '" -> ' + t.kb + ' (got ' + JSON.stringify(r.kb) + ')');
for (const m of t.must || []) ok(new RegExp(m, 'i').test(r.reply) || new RegExp(m, 'i').test(lastPrompt), 'Q&A "' + t.q + '" mentions /' + m + '/');
}
}
or.close();
console.log((fail ? 'FAILED ' : 'ok ') + pass + ' passed, ' + fail + ' failed');
process.exit(fail ? 1 : 0);
+8 -1
View File
@@ -115,7 +115,7 @@ async function main() {
fs.writeFileSync(path.join(DATA, 'house.json'), JSON.stringify([{ key: 'one', title: 'Test house 1', img: '/art/house-iap.svg', link: 'https://example.com/' }, { key: 'two', title: 'Test house 2', img: '/art/house-linkspin.svg', link: 'https://example.net/' }]));
const env = Object.assign({}, process.env, { PORT: String(APP_PORT), DATA_DIR: DATA, CHAIN_ID: '31337', RPC_URLS: 'http://127.0.0.1:' + RPC_PORT, CONTRACT_ADDRESS: CA,
DEPLOY_BLOCK: String(deployBlock), POLL_MS: '1000', ADMIN_TOKEN: ADMIN, KEEPER_ENABLED: '1', KEEPER_KEY: W[7].signer.privateKey, KEEPER_STALL_HOURS: '0.01', KEEPER_EVERY_MIN: '0.25', NODE_ENV: 'development',
HUB_URL: 'http://127.0.0.1:' + HUB_PORT, HUB_SECRET, HUB_SITE: 'bannerline', HUB_ENABLED: '0', HUB_DOWN_MS: '400', NETWORK_LOOKUP_URL: 'http://127.0.0.1:' + IAP_PORT + '/api/network/member',
HUB_URL: 'http://127.0.0.1:' + HUB_PORT, HUB_SECRET, HUB_SITE: 'bannerline', HUB_ENABLED: '0', NETKB: '0', HUB_DOWN_MS: '400', NETWORK_LOOKUP_URL: 'http://127.0.0.1:' + IAP_PORT + '/api/network/member',
TG_TOKEN: 'standin-token', TG_CHAT: '-100123', TG_PAY_TOPIC: '632242', TG_API: 'http://127.0.0.1:' + TG_PORT });
startStandIns();
const hid = n => 'h_' + String(n).padStart(16, '0');
@@ -132,6 +132,13 @@ async function main() {
ok(st.totals && st.totals.members === 6, 'index parsed 6 MemberJoined (payer of a buyFor is not a member)', st.totals);
ok(BigInt(st.totals.paidInWei) === 7n * q, 'paid in = 7 x quote (refunds excluded)', st.totals.paidInWei);
const cfg = await u.json('/api/config'); ok(cfg.ready && cfg.sel.buy === '0xf088d547', '/api/config has contract + selectors');
// the site assistant (2026-11-15): widget on every page, canned answers without AI, account problems hand off, admin KB behind the token
{ const home = await (await u.req('/')).text();
ok(/<script src="\/assets\/chat\.js\?v=\d+" defer><\/script>/.test(home) && (await u.req('/assets/chat.js')).status === 200 && (await u.req('/assets/chat.css')).status === 200, 'chat widget on the page, its script and styles served');
const ch = async m => (await u.req('/api/chat', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ message: m }) })).json();
const a1 = await ch('Where does the $5 go?'); ok(a1.canned && /\$0\.275/.test(a1.reply) && /\$1\.50/.test(a1.reply), 'chat: canned split answer', a1);
const a2 = await ch('my spot did not show up'); ok(a2.handoff === true && /^https:\/\/instantadpay\.com\/support\?from=bannerline/.test(a2.support || ''), 'chat: account problem hands off to network support', a2);
ok((await u.req('/api/admin/kb')).status === 401, 'admin KB needs the token'); }
const qq = await u.json('/api/quote'); ok(qq.wei === q.toString() && qq.source === 'contract.quoteWei', '/api/quote reads quoteWei()', qq);
for (const p of ['/', '/board', '/join', '/my', '/how', '/assets/site.css', '/art/house-line.svg']) { const r = await u.req(p); ok(r.status === 200, 'GET ' + p + ' 200'); }
const r404 = await u.req('/nope'); ok(r404.status === 404, 'unknown path 404');