Skip to content

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.

chore(monetization): extend the API proof script to cover the price-delete transports

nirholasb3412e85c4af
diff --git a/api/og/agent.js b/api/og/agent.js
index b3313e3c8..30a57ad85 100644
--- a/api/og/agent.js
+++ b/api/og/agent.js
@@ -22,6 +22,7 @@
import { cors, wrap } from '../_lib/http.js';
import { sql } from '../_lib/db.js';
import { env } from '../_lib/env.js';
+import { publicUrl } from '../_lib/r2.js';
import { isUuid } from '../_lib/validate.js';
import { getBalances, walletUsdTotal } from '../_lib/balances.js';
import { getAgentReputation } from '../_lib/trust/wallet-reputation.js';
@@ -126,21 +127,47 @@ async function tipsCountFor(id) {
}
}
+// The image types a social crawler will rasterize out of an inline data URI. The
+// value is read off a remote response header and lands inside an SVG attribute,
+// so it is matched against this set rather than interpolated: a quoted or
+// parameterized content-type would otherwise break out of the href.
+const IMAGE_MIME = new Set(['image/jpeg', 'image/png', 'image/webp', 'image/gif', 'image/avif']);
+function imageMime(header) {
+ const mime = String(header || '').split(';')[0].trim().toLowerCase();
+ return IMAGE_MIME.has(mime) ? mime : 'image/jpeg';
+}
+
+// Where the thumbnail actually lives, or null when there is nothing safe to
+// render: no thumbnail, a non-public avatar, or an unconfigured bucket domain.
+// publicUrl() is the same resolver avatar-og.js uses, so a key that is already an
+// absolute URL (imported/externally-hosted avatars) passes through and a key with
+// spaces or a "#" gets encoded instead of producing a dead CDN fetch. It reads
+// env.S3_PUBLIC_DOMAIN, which THROWS when unset, and that must degrade to the
+// gradient portrait: an unconfigured var may never 503 a crawler.
+function thumbnailUrl(row) {
+ const thumbPublic = row?.visibility === 'public' || row?.visibility === 'unlisted';
+ if (!row?.thumbnail_key || !thumbPublic) return null;
+ try {
+ return publicUrl(row.thumbnail_key);
+ } catch {
+ return null;
+ }
+}
+
// Fetch and inline the avatar thumbnail as a data URI (public/unlisted only).
// Size-capped both by the declared content-length and the decoded bytes so a
// mis-declared or chunked response can't blow the card up. Any failure returns
// null, which renders the gradient-initial portrait instead.
async function loadAvatarImage(row) {
- const CDN_BASE = env.S3_PUBLIC_DOMAIN || 'https://three.ws/cdn';
- const thumbPublic = row.visibility === 'public' || row.visibility === 'unlisted';
- if (!row.thumbnail_key || !thumbPublic) return null;
+ const src = thumbnailUrl(row);
+ if (!src) return null;
try {
- const imgResp = await fetch(`${CDN_BASE}/${row.thumbnail_key}`, { signal: AbortSignal.timeout(3000) });
+ const imgResp = await fetch(src, { signal: AbortSignal.timeout(3000) });
if (!imgResp.ok) return null;
const MAX = 2 * 1024 * 1024;
const declared = Number(imgResp.headers.get('content-length') || 0);
if (declared && declared > MAX) return null;
- const ct = imgResp.headers.get('content-type') || 'image/jpeg';
+ const ct = imageMime(imgResp.headers.get('content-type'));
const ab = await imgResp.arrayBuffer();
if (ab.byteLength > MAX) return null;
return { ct, b64: Buffer.from(ab).toString('base64') };
diff --git a/public/changelog.json b/public/changelog.json
index 321fa919f..7c4d680d0 100644
--- a/public/changelog.json
+++ b/public/changelog.json
@@ -1,5 +1,5 @@
{
- "generated_at": "2026-08-14T04:49:55.518Z",
+ "generated_at": "2026-08-14T04:51:17.819Z",
"generated_by": "scripts/build-page-index.mjs from data/pages.json + data/changelog.json",
"site": {
"name": "three.ws",
diff --git a/public/features.json b/public/features.json
index fb322eccc..d14dd22c7 100644
--- a/public/features.json
+++ b/public/features.json
@@ -1,5 +1,5 @@
{
- "generated_at": "2026-08-14T04:49:55.428Z",
+ "generated_at": "2026-08-14T04:51:17.787Z",
"generated_by": "scripts/build-page-index.mjs from data/pages.json",
"site": {
"name": "three.ws",
diff --git a/scripts/monetization-api-proof.mjs b/scripts/monetization-api-proof.mjs
index 3d433bc2c..6b5105eac 100644
--- a/scripts/monetization-api-proof.mjs
+++ b/scripts/monetization-api-proof.mjs
@@ -54,6 +54,10 @@ const TMP = path.join(root, '.monetization-proof');
const USDC_SOL = 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v';
const SOL_PAYOUT = 'FeMbDoX7R1Psc4GEcvJdsbNbZA3bfztcyDCatJVJpump';
const EVM_PAYOUT = '0x1111111111111111111111111111111111111111';
+// A second EVM address, saved through /api/billing/payout-wallets under the
+// legacy chain label 'evm', used to prove it cannot shadow the address the owner
+// saves here on chain 'base'.
+const EVM_LEGACY = '0x2222222222222222222222222222222222222222';
// tiny transcript + assertion kit
let failed = 0;
@@ -426,6 +430,42 @@ async function main() {
const r = await http.write('DELETE', '/api/monetization/prices', { agent_id: agentId, skill_name: 'ghost-skill', hard: true });
check('DELETE of a skill with no price row -> 404', r.status === 404, `status ${r.status}`);
}
+ {
+ // The dashboard's del() helper (src/dashboard-next/api.js) sends no body and
+ // no content-type, addressing the row with query parameters instead. Every
+ // "Remove price" button on the monetize and creator pages goes through it,
+ // so a body-only DELETE reader makes all of them dead.
+ await http.write('PUT', '/api/monetization/prices', { agent_id: agentId, skill_name: 'querydel', price_usdc: 0.02 });
+ const r = await http.write('DELETE', `/api/monetization/prices?agent_id=${agentId}&skill_name=querydel`);
+ const list = await http.req('GET', `/api/monetization/prices?agent_id=${agentId}`, { anonymous: true });
+ check('DELETE addressed by query string, the shape the dashboard sends -> 200',
+ r.status === 200 && !list.json.prices.some((p) => p.skill_name === 'querydel'),
+ `status ${r.status}, ${list.json?.prices?.length} price(s) left`);
+ }
+ {
+ const r = await http.write('DELETE', '/api/monetization/prices?skill_name=querydel');
+ check('DELETE with neither a body nor an agent_id -> 400', r.status === 400, `status ${r.status}`);
+ }
+ {
+ // The embed's skill-access gate reads prices through the shared cache (1h
+ // TTL), so a write that skips invalidation keeps quoting buyers the old
+ // amount for an hour. Warm the cache, edit the price, read it back.
+ await http.write('PUT', '/api/monetization/prices', { agent_id: agentId, skill_name: 'cached', price_usdc: 0.25 });
+ const warm = await http.req('GET', `/api/agents/${agentId}/skill-access`, { anonymous: true });
+ await http.write('PUT', '/api/monetization/prices', { agent_id: agentId, skill_name: 'cached', price_usdc: 0.75 });
+ const after = await http.req('GET', `/api/agents/${agentId}/skill-access`, { anonymous: true });
+ check('a price edit is visible immediately through the cached skill-access gate',
+ Number(warm.json?.data?.skill_prices?.cached?.amount) === 250_000
+ && Number(after.json?.data?.skill_prices?.cached?.amount) === 750_000,
+ `warm ${warm.json?.data?.skill_prices?.cached?.amount}, after ${after.json?.data?.skill_prices?.cached?.amount}`);
+ }
+ {
+ const r = await http.write('DELETE', `/api/monetization/prices?agent_id=${agentId}&skill_name=cached`);
+ const gate = await http.req('GET', `/api/agents/${agentId}/skill-access`, { anonymous: true });
+ check('removing a price clears it from the cached gate too',
+ r.status === 200 && !('cached' in (gate.json?.data?.skill_prices || {})),
+ `status ${r.status}, gate keys ${Object.keys(gate.json?.data?.skill_prices || {}).join(',') || 'none'}`);
+ }
// wallet.js
step('4. /api/monetization/wallet');
@@ -484,6 +524,29 @@ async function main() {
check('re-PUT upserts rather than duplicating', r.status === 200 && list.json.wallets.length === 2,
`${list.json?.wallets?.length} wallet rows after the second PUT`);
}
+ {
+ // 'base' and 'evm' are one payout rail carrying two chain labels, and the
+ // unique key is (user_id, agent_id, chain), so /api/billing/payout-wallets
+ // can leave a default 'evm' row sitting beside this endpoint's 'base' row.
+ // Both resolvers (here and in withdrawals.js) order by is_default then
+ // created_at, and an upsert never moves created_at, so the stale sibling
+ // used to outrank the address the owner had just saved and the payout went
+ // to the replaced address.
+ const legacy = await http.write('POST', '/api/billing/payout-wallets', {
+ address: EVM_LEGACY, chain: 'evm', agent_id: agentId, is_default: true,
+ });
+ const r = await http.write('PUT', '/api/monetization/wallet', { agent_id: agentId, evm_address: EVM_PAYOUT });
+ const list = await http.req('GET', `/api/monetization/wallet?agent_id=${agentId}`);
+ const { rows } = await db.query(
+ `select count(*)::int as n from agent_payout_wallets
+ where agent_id = $1 and chain in ('base', 'evm') and is_default`,
+ [agentId],
+ );
+ check('a legacy evm row cannot shadow the newly saved EVM payout address',
+ legacy.status < 300 && r.status === 200
+ && list.json?.resolved?.evm_address === EVM_PAYOUT && rows[0].n === 1,
+ `legacy ${legacy.status}, resolved ${list.json?.resolved?.evm_address}, ${rows[0].n} default row(s) on the EVM rail`);
+ }
// withdrawals.js, empty-balance paths
step('5. /api/monetization/withdrawals (no balance yet)');