Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
fix(marketplace): stop counting free trials as sales and volume
nirholasf9911f12099b
diff --git a/src/marketplace-analytics.js b/src/marketplace-analytics.jsindex 3cbbbd1c3..b91dbaed4 100644--- a/src/marketplace-analytics.js+++ b/src/marketplace-analytics.js@@ -18,6 +18,60 @@ function statCard(val, lbl) {return `<div class="stat-card"><div class="stat-val">${val}</div><div class="stat-lbl">${lbl}</div></div>`;}+const esc = (s) => String(s).replace(/[&<>"]/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"' })[c]);++/**+ * Render the trial funnel. Free trials are never counted as sales, so this is+ * the only place they are shown, and the shape of the drop-off is the point:+ * each bar is sized against the widest stage.+ */+function renderFunnel(funnel) {+ const section = document.getElementById('funnel-section');+ const list = document.getElementById('funnel-steps');+ const note = document.getElementById('funnel-note');+ if (!section || !list || !funnel) return;++ const { granted = 0, used = 0, exhausted = 0, converted = 0 } = funnel;+ if (!granted && !converted) return; // nothing to show yet; leave the section hidden++ const stages = [+ { name: 'Trials granted', n: granted, tint: 'var(--violet)', desc: 'Buyers who started a free trial of a listed skill.' },+ { name: 'Trials used', n: used, tint: 'var(--cyan)', desc: 'Trials where at least one run has actually been spent.' },+ { name: 'Trials exhausted', n: exhausted, tint: 'var(--amber)', desc: 'Every free run gone. The highest-intent state in the marketplace.' },+ { name: 'Converted to a sale', n: converted, tint: 'var(--green)', desc: 'Paid in full, settled on chain.' },+ ];++ const widest = Math.max(...stages.map((s) => s.n), 1);+ list.innerHTML = stages+ .map((s) => {+ const pct = Math.max((s.n / widest) * 100, s.n > 0 ? 2 : 0);+ const rate = granted > 0 ? `${((s.n / granted) * 100).toFixed(s.n && s.n < granted / 100 ? 1 : 0)}% of granted` : '';+ return `<li class="funnel-step" style="--pct:${pct.toFixed(1)}%;--tint:${s.tint};">+ <div class="funnel-head">+ <span class="funnel-name">${esc(s.name)}</span>+ <span class="funnel-val">${s.n.toLocaleString()}${rate ? `<span class="funnel-rate">${rate}</span>` : ''}</span>+ </div>+ <div class="funnel-desc">${esc(s.desc)}</div>+ </li>`;+ })+ .join('');++ // The two shapes that mean something is wired wrong rather than demand being+ // weak. Saying so beats leaving a reader to conclude the market is dead.+ let diagnosis = '';+ if (granted > 20 && used === 0) {+ diagnosis = `All ${granted.toLocaleString()} trials still hold every run they were granted, so nothing is metering trial usage. Until runs are spent, no trial can reach the exhausted state that makes a buyer eligible to purchase.`;+ } else if (exhausted > 10 && converted === 0) {+ diagnosis = `${exhausted.toLocaleString()} trials have run out with no purchases behind them. That is a checkout problem, not a demand problem.`;+ }+ if (diagnosis) {+ note.innerHTML = `${esc(diagnosis)} <a href="/tutorials/sell-a-skill-with-a-trial">How the trial funnel is meant to work</a>`;+ note.hidden = false;+ }++ section.hidden = false;+}+function rankRow(num, name, sub, primary, secondary) {return `<div class="rank-row">@@ -123,18 +177,21 @@ async function load() {}const { data } = await res.json();- const { summary, topSkills, topAgents, salesVolume } = data;+ const { summary, topSkills, topAgents, salesVolume, trialFunnel } = data;- // Stats+ // Stats. `totalSales` and `totalVolumeAtomic` count PAID purchases only;+ // free trials get their own card so they can never read as revenue.const totalVol = fmtVolume(summary.totalVolumeAtomic, USDC_MINT);statsGrid.innerHTML = [- statCard(summary.totalSales.toLocaleString(), 'Total skill sales'),+ statCard(summary.totalSales.toLocaleString(), 'Paid skill sales'),statCard(totalVol, 'Total volume'),- statCard(summary.uniqueBuyers.toLocaleString(), 'Unique buyers'),- statCard(summary.uniqueSellers.toLocaleString(), 'Creators with sales'),- statCard(summary.totalNfts.toLocaleString(), 'NFT receipts minted'),+ statCard((summary.totalTrials ?? 0).toLocaleString(), 'Free trials taken'),+ statCard(summary.uniqueBuyers.toLocaleString(), 'Paying buyers'),+ statCard(summary.uniqueSellers.toLocaleString(), 'Creators listing skills'),].join('');+ renderFunnel(trialFunnel);+// Top skillsdocument.getElementById('top-skills-count').textContent = topSkills.length;topSkillsList.innerHTML = topSkills.length@@ -142,10 +199,12 @@ async function load() {i + 1,s.skill,s.agentName || '',- `${s.totalSales} ${s.totalSales === 1 ? 'sale' : 'sales'}`,+ s.totalSales > 0+ ? `${s.totalSales} ${s.totalSales === 1 ? 'sale' : 'sales'}`+ : `${s.totalTrials || 0} ${s.totalTrials === 1 ? 'trial' : 'trials'}, no sales yet`,fmtVolume(s.totalRevenue, s.currencyMint),)).join('')- : '<div style="color:var(--muted);font-size:13px;padding:16px 0;">No sales yet.</div>';+ : '<div style="color:var(--muted);font-size:13px;padding:16px 0;">No skills listed yet.</div>';// Top agentsdocument.getElementById('top-agents-count').textContent = topAgents.length;diff --git a/tests/marketplace-analytics-paid-only.test.js b/tests/marketplace-analytics-paid-only.test.jsnew file mode 100644index 000000000..2a8f68cbb--- /dev/null+++ b/tests/marketplace-analytics-paid-only.test.js@@ -0,0 +1,70 @@+// /marketplace/analytics accounting — a free trial is not a sale.+//+// The defect this pins: every aggregate in the handler filtered on+// `status IN ('confirmed','trial')`, so a `trial` row (a free grant that never+// paid anything) was counted as a sale AND its `amount`, which is only the list+// price it *would* have cost, was summed into revenue and into the 30-day volume+// chart.+//+// Measured against the live database on 2026-07-30: the public page reported+// 10,454 "total sales" and 6,228,975 $THREE of "volume" while+// `SELECT count(*) FROM skill_purchases WHERE status='confirmed'` was exactly 0.+// Every headline number on a public transparency page was a free trial.+//+// These are public revenue figures, so the predicate is asserted against the+// source rather than trusted to stay correct by hand.++import { describe, it, expect } from 'vitest';+import { readFileSync } from 'node:fs';+import { fileURLToPath } from 'node:url';++const SRC = readFileSync(fileURLToPath(new URL('../api/marketplace/analytics.js', import.meta.url)), 'utf8');++// Every aggregate that represents MONEY. Each must be gated on confirmed alone.+const MONEY_AGGREGATES = [+ 'total_sales',+ 'total_revenue_atomic',+ 'total_volume_atomic',+ 'unique_buyers',+];++describe('marketplace analytics counts only paid purchases as sales', () => {+ it('gates every money aggregate on confirmed status', () => {+ for (const name of MONEY_AGGREGATES) {+ // Find the expression that produces this column.+ const re = new RegExp(`([^\\n]*?)\\s+AS ${name}`, 'i');+ const m = SRC.match(re);+ expect(m, `no expression found for ${name}`).toBeTruthy();+ expect(m[1], `${name} must filter on confirmed status`).toMatch(/status = 'confirmed'/);+ }+ });++ it('never sums an amount without restricting to confirmed rows', () => {+ // SUM(amount) over a set that includes trials is the revenue bug itself.+ const sums = SRC.match(/SUM\(\s*(?:sp\.)?amount\s*\)(?!\s*FILTER \(WHERE (?:sp\.)?status = 'confirmed'\))/g) || [];+ expect(sums).toEqual([]);+ });++ it('restricts the 30-day volume chart to confirmed rows', () => {+ const block = SRC.slice(SRC.indexOf('salesVolume'), SRC.indexOf('Platform-wide summary'));+ expect(block).toMatch(/WHERE status = 'confirmed'/);+ expect(block).not.toMatch(/status IN \('confirmed', 'trial'\)/);+ });++ it('reports trials on their own, never folded into a sales number', () => {+ // Trials still have to be visible; they just cannot be revenue.+ expect(SRC).toMatch(/trialFunnel/);+ expect(SRC).toMatch(/totalTrials/);+ for (const stage of ['granted', 'used', 'exhausted', 'converted']) {+ expect(SRC, `funnel is missing the ${stage} stage`).toMatch(new RegExp(`AS ${stage}\\b`));+ }+ });++ it('derives trial usage from the granted count, not from a hardcoded number', () => {+ // `used` means "spent at least one run", which is only knowable by+ // comparing what remains against what the listing granted.+ const funnel = SRC.slice(SRC.indexOf('Trial funnel'), SRC.indexOf('Recent sales feed'));+ expect(funnel).toMatch(/agent_skill_prices/);+ expect(funnel).toMatch(/trial_remaining < asp\.trial_uses/);+ });+});