x402-toolpick / tree / tools/gen-examples.mjs ยท raw (this view has old GitHub links rewritten for the mirror; raw is byte-exact)
// Regenerate src/examples.js from a real CDP discovery snapshot (path in argv[2]) + real live checks (unpaid requests).
// Lists are trimmed so the Bazaar example in the v2 PAYMENT-REQUIRED header stays well under 8 KB.
import fs from 'node:fs';
import { compact, mergeRows, DISCLAIMER } from '../src/engine.js';
import { memoryStub, makeStore } from '../src/store.js';
import { run } from '../src/tool.js';
const d = JSON.parse(fs.readFileSync(process.argv[2]));
const now = Date.now();
const rows = mergeRows(d.map((x) => compact(x, 'cdp')), []);
const store = makeStore(memoryStub({ at: now - 600_000, rows, counts: { cdp_total: d.length, cdp_got: d.length, payai_total: 0, payai_got: 0, merged: rows.length }, sources_failed: [] }));
const ctx = { fetchImpl: globalThis.fetch, now, store };
const trimR = (x) => ({ ...x, description: x.description.slice(0, 90) });
const lite = await run('lite', { need: 'solana token safety' }, ctx);
lite.results = lite.results.slice(0, 2).map(trimR); delete lite.index.counts;
const pick = await run('pick', { need: 'web search', maxPrice: 0.02 }, ctx);
pick.results = pick.results.slice(0, 2).map((x) => ({ ...trimR(x), description: x.description.slice(0, 50) })); delete pick.stats.est_revenue_note; delete pick.index.counts;
const market = await run('market', { need: 'token safety', limit: 10 }, ctx);
market.top_sellers = market.top_sellers.slice(0, 2); delete market.index.counts; market.top_resources_by_payers = market.top_resources_by_payers.slice(0, 1).map(trimR);
const ex = (o, tier) => JSON.stringify({ ...o, tier, disclaimer: DISCLAIMER });
fs.writeFileSync(new URL('../src/examples.js', import.meta.url), `// Example outputs for the Bazaar discovery declaration, OpenAPI and landing page (recorded ${new Date(now).toISOString()} from the real index + real live checks; lists trimmed).\nexport const LITE_EXAMPLE = ${ex(lite, 'lite')};\nexport const PICK_EXAMPLE = ${ex(pick, 'pick')};\nexport const MARKET_EXAMPLE = ${ex(market, 'market')};\n`);
console.log('best_pick', pick.best_pick, 'failed', pick.sources_failed, 'checks', pick.results.map((r) => r.live_check));

agentgate-source: code mirror on Cloudflare Pages. All repos