// Landing page (browsers): tiers, terms, a submission form that is checked before payment, one-click x402 pay with a
// browser wallet (USDC on Base), and a status lookup. Agents use the JSON at / or /openapi.json.
import { LOGO_SVG } from './discovery.js';
export function prefersHtml(accept) {
if (!accept) return false;
let html = 0, json = 0, wildcard = 0, jsonListed = false;
for (const part of accept.split(',')) {
const [type, ...params] = part.trim().toLowerCase().split(';').map((s) => s.trim());
const qp = params.find((p) => p.startsWith('q='));
const q = qp ? Number(qp.slice(2)) : 1;
if (!Number.isFinite(q)) continue;
if (type === 'text/html' || type === 'application/xhtml+xml') html = Math.max(html, q);
else if (type === 'application/json') { json = Math.max(json, q); jsonListed = true; }
else if (type === '*/*' || type === 'application/*') wildcard = Math.max(wildcard, q);
}
const jsonEff = jsonListed ? json : wildcard;
return html > 0 && html > jsonEff;
}
const esc = (s) => String(s).replace(/[&<>"']/g, (ch) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[ch]));
export function landingHtml({ origin, info }) {
const cards = info.tiers.map((t) => `<div class="card"><h3>${esc(t.label)} <span class="price">$${esc(t.price_usd)}</span></h3><p>${esc(t.what)}</p><p class="muted small"><code>POST ${esc(t.url)}</code></p><label class="pick"><input type="radio" name="tier" value="${esc(t.id)}"${t.id === 'fast-track' ? ' checked' : ''}> Choose ${esc(t.label)}</label></div>`).join('');
const curl = `# 1) check your submission for free: a valid body answers 402 (payment terms), an invalid one 400
curl -i -X POST "${origin}/v1/fast-track" -H "content-type: application/json" \\
-d '{"tool_url":"https://example.com","name":"Example Tool","contact_email":"you@example.com","category":"x402 API"}'
# 2) pay the 402 with any x402 client (USDC on Base, Polygon, Arbitrum One or Solana) -> {"ref":"LST-...","status":"received","review_by":"..."}
# 3) track it (free, no email shown)
curl -s "${origin}/v1/status/LST-XXXXXXXXXX"`;
const agent = `import { wrapFetchWithPaymentFromConfig } from '@x402/fetch';
import { ExactEvmScheme } from '@x402/evm';
import { privateKeyToAccount } from 'viem/accounts';
const pay = wrapFetchWithPaymentFromConfig(fetch, {
schemes: [{ network: 'eip155:8453', client: new ExactEvmScheme(privateKeyToAccount(process.env.BUYER_KEY)) }],
});
const r = await pay('${origin}/v1/fast-track', { method: 'POST', headers: { 'content-type': 'application/json' },
body: JSON.stringify({ tool_url: 'https://example.com', name: 'Example Tool', contact_email: 'you@example.com', category: 'x402 API' }) });
console.log(await r.json()); // { ref: 'LST-...', status: 'received', review_by: '...' }`;
return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>YourAITools Listings: fast-track review, Launch and Featured, paid in USDC</title>
<meta name="description" content="${esc(info.description)}">
<link rel="icon" href="data:image/svg+xml,${encodeURIComponent(LOGO_SVG)}">
<style>:root{--bg:#0b0f17;--fg:#e6e9ef;--muted:#9aa7bd;--card:#121a29;--line:#243047;--acc:#38bdf8}*{box-sizing:border-box}body{font:16px/1.55 system-ui,sans-serif;max-width:980px;margin:0 auto;padding:1.5rem 1rem 3rem;background:var(--bg);color:var(--fg)}a{color:#7cc4ff}h1{margin:.2rem 0}.muted{color:var(--muted)}.small{font-size:.88em}.grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(260px,1fr));gap:12px}.card{background:var(--card);border:1px solid var(--line);border-radius:12px;padding:14px}.card h3{margin:.1rem 0 .3rem}.price{color:#facc15}button{background:var(--acc);color:#04111d;border:0;border-radius:8px;padding:.55rem .9rem;font-weight:600;cursor:pointer}button.ghost{background:transparent;color:var(--fg);border:1px solid var(--line)}input,select,textarea{width:100%;background:#0a1220;color:var(--fg);border:1px solid var(--line);border-radius:8px;padding:.5rem;font:inherit}.pick input{width:auto}label{display:block;margin:.5rem 0 .2rem}pre{background:#0a1220;border:1px solid var(--line);border-radius:8px;padding:10px;overflow:auto;font-size:13px}code{font-size:.88em;color:#b8c4d6;overflow-wrap:anywhere}ul.terms li{margin:.3rem 0}.ok{color:#4ade80}.err{color:#f87171}</style></head><body>
<p class="muted"><a href="https://youraitools.co">YourAITools</a> · directory of AI tools and x402 APIs</p>
<h1>Get your tool reviewed, launched or featured</h1>
<p>${esc(info.description)} Prefer free? <a href="https://youraitools.co/submit">Submit for free</a>: same review rules, normal queue.</p>
<div class="grid">${cards}</div>
<h2>Submit</h2>
<div class="card"><form id="f" autocomplete="on">
<label for="tool_url">Tool URL (https)</label><input id="tool_url" name="tool_url" type="url" required maxlength="500" placeholder="https://example.com">
<label for="name">Name</label><input id="name" name="name" required maxlength="80" placeholder="Example Tool">
<label for="contact_email">Contact email (only used about this submission, never shown publicly)</label><input id="contact_email" name="contact_email" type="email" required maxlength="254">
<label for="category">Category</label><input id="category" name="category" required maxlength="48" placeholder="x402 API, AI agents, coding, writing...">
<label for="description">What it does (optional)</label><textarea id="description" name="description" rows="2" maxlength="600"></textarea>
<p><button type="button" id="check" class="ghost">Check my submission (free)</button> <button type="button" id="pay">Pay with a browser wallet (USDC on Base)</button></p>
<p class="muted small">Your submission is checked before you are asked to pay. The wallet signs one x402 authorization for exactly the tier price to our payee, valid for 2 minutes; it is not an open-ended approval (some wallets show a generic warning for new payees). Agents and other networks (Polygon, Arbitrum One, Solana): use any x402 client, see below.</p>
</form><div id="out"></div></div>
<h2>Check a submission</h2>
<div class="card"><input id="ref" placeholder="LST-XXXXXXXXXX" autocomplete="off"><p><button class="ghost" id="st">Show status</button></p><div id="sout"></div></div>
<h2>Terms</h2><ul class="terms">${info.terms.map((t) => `<li>${esc(t)}</li>`).join('')}</ul>
<p class="muted small">Payments: USDC to <code>${esc(info.payment.networks[0].payTo)}</code> (EVM) or the Solana address in the 402 terms. Prepaid credits are not accepted here. Questions: <a href="mailto:hello@youraitools.co">hello@youraitools.co</a>.</p>
<h2>For agents and developers</h2>
<pre>${esc(curl)}</pre>
<pre>${esc(agent)}</pre>
<p class="muted">Statuses: received, approved, rejected, refund_pending, refunded. Docs: <a href="/openapi.json">openapi.json</a> · <a href="/.well-known/x402">/.well-known/x402</a> · <a href="/v1/tiers">/v1/tiers</a> · source <a href="${esc(info.source)}">${esc(info.source)}</a> · v${esc(info.version)}</p>
<script>
const $ = (id) => document.getElementById(id);
const escH = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
const b64 = (o) => btoa(unescape(encodeURIComponent(JSON.stringify(o))));
const unb64 = (s) => JSON.parse(decodeURIComponent(escape(atob(s))));
const BASE = location.pathname.replace(/\\/$/, '');
const show = (h) => { $('out').innerHTML = h; };
const tier = () => (document.querySelector('input[name=tier]:checked') || {}).value || 'fast-track';
const body = () => { const o = {}; for (const k of ['tool_url', 'name', 'contact_email', 'category', 'description']) { const v = $(k).value.trim(); if (v) o[k] = v; } return o; };
async function terms() {
const r = await fetch(BASE + '/v1/' + tier(), { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body()) });
if (r.status === 402) return { ok: true, pr: unb64(r.headers.get('PAYMENT-REQUIRED')) };
const j = await r.json().catch(() => ({}));
return { ok: false, msg: (j.errors && j.errors.join('; ')) || j.message || ('HTTP ' + r.status) };
}
async function check() {
const b = body(); if (!b.tool_url || !b.name || !b.contact_email || !b.category) { show('<p class="err">Fill in URL, name, email and category.</p>'); return; }
const t = await terms();
if (!t.ok) { show('<p class="err">' + escH(t.msg) + '</p>'); return; }
const a = t.pr.accepts[0]; show('<p class="ok">Looks good. Price ' + (Number(a.amount) / 1e6) + ' USDC; you can pay now.</p>');
}
async function pay() {
const eth = window.ethereum; const b = body();
if (!b.tool_url || !b.name || !b.contact_email || !b.category) { show('<p class="err">Fill in URL, name, email and category.</p>'); return; }
try {
show('<p class="muted">Checking your submission...</p>');
const t = await terms(); if (!t.ok) { show('<p class="err">' + escH(t.msg) + '</p>'); return; }
if (!eth) { show('<p class="muted">No browser wallet found. Open this page in a wallet browser (Coinbase Wallet, MetaMask, Rabby...) or pay with any x402 client.</p>'); return; }
const pr = t.pr; const req = pr.accepts.find((a) => a.network === 'eip155:8453' && a.scheme === 'exact');
const [from] = await eth.request({ method: 'eth_requestAccounts' });
try { await eth.request({ method: 'wallet_switchEthereumChain', params: [{ chainId: '0x2105' }] }); } catch (e) { /* shown in the signature request */ }
const now = Math.floor(Date.now() / 1000);
const nonce = '0x' + Array.from(crypto.getRandomValues(new Uint8Array(32)), (x) => x.toString(16).padStart(2, '0')).join('');
const auth = { from, to: req.payTo, value: String(req.amount), validAfter: String(now - 600), validBefore: String(now + (req.maxTimeoutSeconds || 120)), nonce };
const typed = { types: { EIP712Domain: [{ name: 'name', type: 'string' }, { name: 'version', type: 'string' }, { name: 'chainId', type: 'uint256' }, { name: 'verifyingContract', type: 'address' }], TransferWithAuthorization: [{ name: 'from', type: 'address' }, { name: 'to', type: 'address' }, { name: 'value', type: 'uint256' }, { name: 'validAfter', type: 'uint256' }, { name: 'validBefore', type: 'uint256' }, { name: 'nonce', type: 'bytes32' }] }, primaryType: 'TransferWithAuthorization', domain: { name: req.extra.name, version: req.extra.version, chainId: 8453, verifyingContract: req.asset }, message: auth };
show('<p class="muted">Sign the USDC authorization (' + (Number(req.amount) / 1e6) + ' USDC on Base to ' + escH(req.payTo) + ') in your wallet...</p>');
const signature = await eth.request({ method: 'eth_signTypedData_v4', params: [from, JSON.stringify(typed)] });
show('<p class="muted">Settling...</p>');
const r = await fetch(BASE + '/v1/' + tier(), { method: 'POST', headers: { 'content-type': 'application/json', 'PAYMENT-SIGNATURE': b64({ x402Version: 2, resource: pr.resource, accepted: req, payload: { authorization: auth, signature }, extensions: pr.extensions || {} }) }, body: JSON.stringify(b) });
const j = await r.json().catch(() => ({}));
if (!r.ok || !j.ref) { show('<p class="err">Not charged: ' + escH(j.message || j.error || ('HTTP ' + r.status)) + '</p>'); return; }
show('<p class="ok">Received. Your reference: <b>' + escH(j.ref) + '</b>. Review by ' + escH(new Date(j.review_by).toLocaleString()) + '.</p><p class="muted">Save the reference; check it below or at <code>' + escH(j.status_url) + '</code>.</p>');
$('ref').value = j.ref;
} catch (e) { show('<p class="err">' + escH(e && e.message ? e.message : e) + '</p>'); }
}
async function status() {
const ref = $('ref').value.trim().toUpperCase();
const r = await fetch(BASE + '/v1/status/' + encodeURIComponent(ref)); const j = await r.json().catch(() => ({}));
if (!r.ok) { $('sout').innerHTML = '<p class="err">' + escH(j.message || ('HTTP ' + r.status)) + '</p>'; return; }
$('sout').innerHTML = '<p><b>' + escH(j.status) + '</b> · ' + escH(j.tier_label) + ' · ' + escH(j.name) + '</p><p class="muted small">Review by ' + escH(j.review_by) + (j.featured_until ? ' · featured until ' + escH(j.featured_until) : '') + (j.refund ? ' · refund ' + escH(j.refund.status) : '') + (j.note ? '<br>' + escH(j.note) : '') + '</p>';
}
$('check').addEventListener('click', check); $('pay').addEventListener('click', pay); $('st').addEventListener('click', status);
</script>
</body></html>`;
}
agentgate-source: code mirror on Cloudflare Pages. All repos