AI ad writer moves to the network hub (Marty 2026-11-17): hubadwriter.js signs POST /v1/adwriter for the member with this site's 60/90 limits; the local engine and its key are retired (its 82 checks moved to network-hub test/adwriter.test.js); qa/hubadwriter.test.mjs 11 checks

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-17 07:52:55 -06:00
parent 8e40e4180d
commit 13255c6fda
7 changed files with 105 additions and 529 deletions
+6 -7
View File
@@ -35,7 +35,7 @@ const netdeals = require('./netdeals'); // Network Weekend ribbon feed (2026-11-
const weekend = require('./weekend'); // Network Weekend +3 board days per Boost (2026-11-17)
const lstrack = require('./lstrack');
const chatbot = require('./chatbot');
const adwriter = require('./adwriter');
const adwriter = require('./hubadwriter'); // the network AI ad writer, asked through the hub (2026-11-17)
const PUB = path.join(__dirname, 'public');
const ADDR_RE = /^0x[0-9a-fA-F]{40}$/;
@@ -278,7 +278,7 @@ const server = http.createServer(async (req, res) => {
boost: Object.assign({}, C.boost, { days: C.boost.days + weekend.bonusDays(), weekendDays: weekend.bonusDays() }), split: live ? { resharerBps: live.resharerBps, potBps: live.potBps, levelBps: live.levelBps, maxDepth: 20, live: true } : Object.assign({ proposal: true }, C.split),
reward: { cents: C.reward.cents, dailyCap: C.reward.dailyCap, payouts: C.reward.payouts, tiers: C.reward.tiers, proposal: true }, credits: C.credits, visitSeconds: C.visitSeconds, ad: C.ad,
sso: networksso.enabled() || networksso.hubOn(), shop: { live: shop.watching() && shop.signerOn(), contract: shop.watching() ? C.contractAddress : null }, explorer: C.explorer, joinUrl: joinUrl(''),
aiWriter: adwriter.enabled() ? { daily: adwriter.dailyCap() } : null });
aiWriter: await adwriter.status().then(w => (w.on ? { daily: w.daily } : null)) });
}
// everything a page shows, with its visit ticket. page=front|share|other, s=<share code> on share pages
if (p === '/api/wire' && req.method === 'GET') {
@@ -480,14 +480,14 @@ const server = http.createServer(async (req, res) => {
catch (e) { console.error('order failed:', String(e && e.message || e).slice(0, 200)); return json(res, 503, { error: 'Price unavailable right now. Try again in a minute.' }); }
}
if (p === '/api/my/paid' && req.method === 'POST') { shop.nudge(); return json(res, 200, { ok: true, confirmations: C.shopConfirmations }); }
// the AI ad writer (2026-11-17): 3 suggested ads written only from the member's own page; nothing is posted (adwriter.js)
// the AI ad writer (2026-11-17): 3 suggested ads written only from the member's own page; nothing is posted (the hub writes them: hubadwriter.js)
if (p === '/api/my/adwriter' && req.method === 'POST') {
if (!adwriter.enabled()) return json(res, 503, { error: adwriter.MSG.off });
if (!(await adwriter.enabled())) return json(res, 503, { error: 'The ad writer is switched off right now. You can still write your ad yourself.' });
if (limited(req, 'adwriter', 12, 3600000)) return json(res, 429, { error: 'Too many ad writes from this connection this hour. Try again later, or write your ad yourself.' });
const m = store.member(me); await verifyNet(me).catch(() => {});
if (!netVerified(m)) return json(res, 403, { error: 'The ad writer is for network members. Sign in with your network account first.' });
const b = await readBody(req);
const r = await adwriter.write(me, String(b.url || '').trim().slice(0, 600));
const r = await adwriter.write(me, String(b.url || '').trim().slice(0, 600), { headline: C.ad.headline, line: C.ad.line });
if (r.error) return json(res, r.status || 400, { error: r.error, code: r.code, left: r.left });
return json(res, 200, { ok: true, options: r.options, url: r.url, cached: r.cached, left: r.left });
}
@@ -503,7 +503,7 @@ const server = http.createServer(async (req, res) => {
today: store.today(), totals: S.totals, members: store.members().length, ads: { live: store.liveAds().length, all: store.ads().length }, shares: S.shares.length,
rows: { visits: store.visits().length, clicks: store.clicks().length, signups: store.signups().length, rewards: store.rewards().length },
signup: signup.view(), shop: shop.view(), proof: proof.view(), hub: hubreport.view(), hubLookup: hubpeople.view(), hubEvents: hubevents.view(), sso: { hub: networksso.hubOn(), pairwise: networksso.enabled() },
linkspin: lstrack.view(), docstore: docstore.view(), oldrefs: Object.keys(oldRefMap()).length, adWriter: adwriter.view() });
linkspin: lstrack.view(), docstore: docstore.view(), oldrefs: Object.keys(oldRefMap()).length, adWriter: await adwriter.status() });
}
if (p === '/api/admin/signups' && req.method === 'GET') {
const st0 = String(u.searchParams.get('status') || '');
@@ -570,7 +570,6 @@ const server = http.createServer(async (req, res) => {
setInterval(() => { if (store.prune()) wire.rebuild(); }, 3600000).unref();
if (C.reward.payouts) setInterval(() => signup.payDue().catch(() => {}), 60000).unref();
chatbot.init();
adwriter.init({ store, ad: C.ad });
lstrack.init(C, store);
{ let busy = false; const tick = () => { if (busy) return; busy = true; lstrack.sweep(25).catch(() => {}).finally(() => { busy = false; }); };
setTimeout(tick, Number(process.env.LS_SWEEP_FIRST_MS || 20000)).unref(); setInterval(tick, Number(process.env.LS_SWEEP_MS || 120000)).unref(); }