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(og): harden the share-card theme lookup and drop the banned dashes from rendered cards
nirholas441122c4694d
diff --git a/api/og/agent.js b/api/og/agent.jsindex 30a57ad85..e86b20217 100644--- a/api/og/agent.js+++ b/api/og/agent.js@@ -1,7 +1,7 @@/*** GET /api/og/agent?id=<agentId>*- * Dynamic OG image — the agent's wallet as a screenshot-worthy TRADING CARD.+ * Dynamic OG image: the agent's wallet as a screenshot-worthy TRADING CARD.* SVG 1200×630, rendered entirely from REAL data so a shared agent link unfurls* with a card that matches the on-page one (src/shared/wallet-card.js):*@@ -11,10 +11,10 @@* - holdings count, realized P&L (when positive), lifetime tips* - reputation tier badge (new…elite) + $THREE-holder mark* - a "rarity finish" (Common…Mythic) that scales with the agent's REAL wealth- * and reputation tier — matte for a dormant new wallet, holo for a luminous one+ * and reputation tier (matte for a dormant new wallet, holo for a luminous one)** Every enrichment is best-effort and individually timeout-guarded: a slow or- * failed chain/reputation read degrades that one field (a "—" balance, no badge),+ * failed chain/reputation read degrades that one field (a "-" balance, no badge),* never a broken unfurl. Private avatars never render a card (visibility re-checked* server-side). Public/unlisted only. Cached sensibly.*/@@ -27,7 +27,7 @@ import { isUuid } from '../_lib/validate.js';import { getBalances, walletUsdTotal } from '../_lib/balances.js';import { getAgentReputation } from '../_lib/trust/wallet-reputation.js';import { loadAgentAchievements } from '../_lib/agent-achievements-data.js';-import { tierForUsd, NETWORTH_TIERS, THREE_MINT } from '../../src/shared/wallet-networth.js';+import { tierForUsd, THREE_MINT } from '../../src/shared/wallet-networth.js';const CACHE = 'public, max-age=180, s-maxage=900, stale-while-revalidate=120';@@ -199,7 +199,7 @@ export default wrap(async (req, res) => {}if (!row) return fallback(res);- // Respect visibility — a private agent must never render a public card.+ // Respect visibility: a private agent must never render a public card.if (row.visibility === 'private') return fallback(res);const solAddress = typeof row.meta?.solana_address === 'string' ? row.meta.solana_address : null;@@ -250,7 +250,7 @@ export function renderCard({const tokens = balances?.tokens || [];const tokenCount = tokens.length;const hasThree = tokens.some((t) => t.mint === THREE_MINT && (t.amount || 0) > 0);- const usdLabel = balances ? (fmtUsd(usd) ?? '$0') : '—';+ const usdLabel = balances ? (fmtUsd(usd) ?? '$0') : '-';const wealthTier = tierForUsd(usd);const repRank = rep?.tier ? (REP_RANK[rep.tier] ?? 0) : 0;@@ -272,7 +272,7 @@ export function renderCard({// Build the right-column stat chips from real, public-safe aggregates.const stats = [];- stats.push({ label: 'HOLDINGS', val: tokenCount === 0 ? '—' : String(tokenCount), accent: false });+ stats.push({ label: 'HOLDINGS', val: tokenCount === 0 ? '-' : String(tokenCount), accent: false });if (pnl.sol > 0) stats.push({ label: 'REALIZED P&L', val: `+${pnl.sol.toFixed(pnl.sol < 1 ? 3 : 2)} ◎`, accent: true });else if (tipsCount > 0) stats.push({ label: 'TIPS', val: String(tipsCount), accent: false });else stats.push({ label: 'WEALTH TIER', val: wealthTier.label, accent: false });@@ -291,8 +291,8 @@ export function renderCard({}).join('\n');// Badge row (top achievement + reputation tier + $THREE mark), under the name.- // The achievement leads — a graduated/elite agent advertises that success on- // every shared link. "+N" notes how many more badges it has earned.+ // The achievement leads, because a graduated or elite agent advertises that+ // success on every shared link. "+N" notes how many more badges it has earned.const badges = [];const topAch = headlineAchievement(achievements?.earned);if (topAch) {@@ -398,4 +398,6 @@ function fallback(res) {}// Exposed for unit tests: renders the card from fixed rows and enrichments.-export const __testInternals = { renderCard, fmtUsd, headlineAchievement, gradientForName, trunc };+export const __testInternals = {+ renderCard, fmtUsd, headlineAchievement, gradientForName, trunc, imageMime, thumbnailUrl,+};diff --git a/api/og/sealed-drop.js b/api/og/sealed-drop.jsindex ddc97e209..d51a01be8 100644--- a/api/og/sealed-drop.js+++ b/api/og/sealed-drop.js@@ -1,7 +1,7 @@/*** GET /api/og/sealed-drop?id=<dropId>*- * Dynamic Open Graph share card for a sealed wallet drop — the image that+ * Dynamic Open Graph share card for a sealed wallet drop: the image that* previews wherever a /drop/:id link is posted (X, Telegram, Discord, iMessage,* Farcaster). Mirrors api/og/three-token-badge.js: a 1200×630 SVG returned with* image/svg+xml + a CDN cache header, no satori/canvas deps in the bundle.@@ -10,7 +10,7 @@* projection: the (vanity) address, the funded amount + asset, the theme, who* it's from, and the sealed/E2E badge. It NEVER renders the sealed envelope, the* claim token, or any secret. A missing/unknown id still renders a valid,- * branded card (a generic "sealed gift") rather than 5xx — crawlers must always+ * branded card (a generic "sealed gift") rather than 5xx, because crawlers must always* get an image.*/@@ -51,7 +51,10 @@ function assetLabel(asset) {}function buildCard({ status, amount, asset, address, theme, senderLabel, vanity }) {- const t = THEME_STYLE[theme] || THEME_STYLE.default;+ // Own-property lookup only: a stored record carrying a theme like "constructor"+ // would otherwise resolve to an inherited Object member and paint the card with+ // undefined colors and glyphs.+ const t = Object.hasOwn(THEME_STYLE, String(theme)) ? THEME_STYLE[theme] : THEME_STYLE.default;const claimed = status === 'claimed';const reclaimed = status === 'reclaimed';const statusLabel = claimed ? 'CLAIMED' : reclaimed ? 'RECLAIMED' : 'SEALED · UNCLAIMED';@@ -63,7 +66,7 @@ function buildCard({ status, amount, asset, address, theme, senderLabel, vanity? `vanity ${vanity.prefix ? vanity.prefix + '…' : ''}${vanity.suffix ? '…' + vanity.suffix : ''}`: 'end-to-end encrypted';- return `<svg xmlns="http://www.w3.org/2000/svg" width="1200" height="630" viewBox="0 0 1200 630" role="img" aria-label="${x(t.label)} — a sealed wallet drop on three.ws">+ return `<svg xmlns="http://www.w3.org/2000/svg" width="1200" height="630" viewBox="0 0 1200 630" role="img" aria-label="${x(t.label)}, a sealed wallet drop on three.ws"><defs><linearGradient id="bg" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#0a0a0f"/><stop offset="1" stop-color="#05050a"/>diff --git a/tests/og-cards.test.js b/tests/og-cards.test.jsindex 9639b62c9..e4d72514b 100644--- a/tests/og-cards.test.js+++ b/tests/og-cards.test.js@@ -11,7 +11,7 @@// paths that need no network (validation, visibility, fallback) are driven end to// end against the real default export.-import { describe, it, expect, beforeEach } from 'vitest';+import { describe, it, expect, beforeEach, afterEach } from 'vitest';import sealedDropHandler, { __testInternals as sealedInternals } from '../api/og/sealed-drop.js';import agentHandler, { renderCard as renderAgentCard, __testInternals as agentInternals } from '../api/og/agent.js';@@ -135,6 +135,23 @@ describe('og/sealed-drop', () => {expect(svg).toContain('<script>');});+ // A stored theme is validated at creation (api/vanity/drops.js), but the card+ // must not paint "undefined" if a record ever carries an inherited key.+ it('falls back to the default theme for a non-theme key', () => {+ const svg = sealedInternals.buildCard({+ status: 'funded',+ amount: 5,+ asset: 'SOL',+ address: 'THREEsynthetic1111111111111111111111111111',+ theme: 'constructor',+ senderLabel: null,+ vanity: null,+ });+ expectValidCard(svg);+ expect(svg).toContain('A sealed gift');+ expect(svg).not.toContain('undefined');+ });+it('shortens a full base58 address and leaves a short one alone', () => {const { shortAddr } = sealedInternals;expect(shortAddr('THREEsynthetic1111111111111111111111111111')).toBe('THREEsyn…111111');@@ -254,6 +271,9 @@ describe('og/agent', () => {expect(svg).toContain('Wallet provisioning');expect(svg).toContain('COMMON');expect(svg).not.toContain('$THREE');+ // An unreadable balance and an empty wallet read as blank, not as a fake $0.+ expect(svg).toContain('>-</text>');+ expect(svg).not.toContain('>$0<');});it('escapes a hostile agent name', () => {@@ -284,6 +304,62 @@ describe('og/agent', () => {expect(headlineAchievement([])).toBeNull();});+ // The avatar the card inlines comes off the CDN, so both halves of that read are+ // boundaries: where the bytes are fetched from, and what the remote server says+ // they are. Neither may throw, and neither may reach the SVG unvalidated.+ describe('avatar thumbnail resolution', () => {+ const { thumbnailUrl, imageMime } = agentInternals;+ const KEY = 'u/42/thumbs/nova card.png';+ let savedDomain;++ beforeEach(() => { savedDomain = process.env.S3_PUBLIC_DOMAIN; });+ afterEach(() => {+ if (savedDomain === undefined) delete process.env.S3_PUBLIC_DOMAIN;+ else process.env.S3_PUBLIC_DOMAIN = savedDomain;+ });++ it('resolves a bucket key through the CDN domain and passes an absolute one through', () => {+ process.env.S3_PUBLIC_DOMAIN = 'https://cdn.three.ws';+ expect(thumbnailUrl({ visibility: 'public', thumbnail_key: KEY }))+ .toBe('https://cdn.three.ws/u/42/thumbs/nova%20card.png');+ expect(thumbnailUrl({ visibility: 'unlisted', thumbnail_key: 'https://img.example/a b.png' }))+ .toBe('https://img.example/a b.png');+ });++ it('renders no avatar for a private or thumbnail-less agent', () => {+ process.env.S3_PUBLIC_DOMAIN = 'https://cdn.three.ws';+ expect(thumbnailUrl({ visibility: 'private', thumbnail_key: KEY })).toBeNull();+ expect(thumbnailUrl({ visibility: 'public', thumbnail_key: null })).toBeNull();+ expect(thumbnailUrl(null)).toBeNull();+ });++ // Failure path: the bucket domain is unset. env.S3_PUBLIC_DOMAIN throws on a+ // missing var, and that must cost the portrait, never the whole card.+ it('degrades to the gradient portrait when the bucket domain is unconfigured', () => {+ delete process.env.S3_PUBLIC_DOMAIN;+ expect(() => thumbnailUrl({ visibility: 'public', thumbnail_key: KEY })).not.toThrow();+ expect(thumbnailUrl({ visibility: 'public', thumbnail_key: KEY })).toBeNull();+ });++ it('pins a hostile remote content-type to a known image type', () => {+ expect(imageMime('image/webp')).toBe('image/webp');+ expect(imageMime('image/png; charset=binary')).toBe('image/png');+ expect(imageMime('IMAGE/JPEG')).toBe('image/jpeg');+ expect(imageMime('image/svg+xml"/><script>alert(1)</script>')).toBe('image/jpeg');+ expect(imageMime(null)).toBe('image/jpeg');+ });++ it('never lets a content-type escape the image href', () => {+ const svg = renderAgentCard({+ id: ID,+ row: ROW,+ avatarData: { ct: imageMime('image/png"/><script>alert(1)</script>'), b64: 'AAAA' },+ });+ expectValidCard(svg);+ expect(svg).toContain('href="data:image/jpeg;base64,AAAA"');+ });+ });+it('formats net worth the way the on-page wallet card does', () => {const { fmtUsd } = agentInternals;expect(fmtUsd(0)).toBe('$0');