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.

feat: Phase 1+2 roadmap — selfie quality gates, GLB meshopt, X memory seed

nirholas2a872c706c7d
diff --git a/api/_lib/bake.js b/api/_lib/bake.js
index 111540933..01cce66a0 100644
--- a/api/_lib/bake.js
+++ b/api/_lib/bake.js
@@ -22,8 +22,10 @@ import {
unpartition,
weld,
quantize,
+ meshopt,
textureCompress,
} from '@gltf-transform/functions';
+import { MeshoptEncoder } from 'meshoptimizer';
import sharp from 'sharp';
import { readFile } from 'node:fs/promises';
import path from 'node:path';
@@ -171,6 +173,9 @@ export async function bakeAppearance(baseGlbBytes, appearance) {
// textureCompress → re-encode base-color / normal / roughness textures via
// sharp to WebP at a 1024px cap. WebP is supported by every
// browser model-viewer ships in and by three.js since r136.
+ // meshopt → KHR_mesh_quantization + KHR_meshopt_compression encoding.
+ // Adds 2–3× further size reduction on top of weld+quantize.
+ // Natively decoded by three.js; no separate decoder bundle needed.
//
// All operations are conservative: defaults chosen so the same bake works on
// arbitrary user-uploaded GLBs without visible artifacts. If a transform
@@ -178,6 +183,7 @@ export async function bakeAppearance(baseGlbBytes, appearance) {
// transform group is wrapped — a failure in compression is logged and we
// fall back to the unoptimized but correct output.
try {
+ await MeshoptEncoder.ready;
await doc.transform(
unpartition(),
prune(),
@@ -191,6 +197,7 @@ export async function bakeAppearance(baseGlbBytes, appearance) {
quantizeWeight: 8,
quantizeGeneric: 12,
}),
+ meshopt({ encoder: MeshoptEncoder }),
textureCompress({
encoder: sharp,
targetFormat: 'webp',
diff --git a/api/agents/_id/memory-seed-x.js b/api/agents/_id/memory-seed-x.js
new file mode 100644
index 000000000..6745a5415
--- /dev/null
+++ b/api/agents/_id/memory-seed-x.js
@@ -0,0 +1,242 @@
+// POST /api/agents/:id/memory/seed/x
+//
+// Seeds agent memories from the user's X (Twitter) profile and recent tweets
+// using Claude Haiku to distill personality, interests, and communication style.
+// Requires: session auth, agent ownership, X social connection via OAuth 2.0.
+// Rate-limited to once per 24 hours per agent.
+//
+// Route wired in vercel.json: /api/agents/:id/memory/seed/x → this file.
+
+import { webcrypto } from 'node:crypto';
+import { TwitterApi } from 'twitter-api-v2';
+import { sql } from '../../_lib/db.js';
+import { getSessionUser, authenticateBearer, extractBearer } from '../../_lib/auth.js';
+import { cors, json, method, error } from '../../_lib/http.js';
+import { env } from '../../_lib/env.js';
+import { limits } from '../../_lib/rate-limit.js';
+
+const subtle = globalThis.crypto?.subtle || webcrypto.subtle;
+
+// ── Token decryption (mirrors the HKDF derivation in auth/x/[action].js) ─────
+
+async function decryptToken(ciphertext) {
+ const raw = new TextEncoder().encode(env.JWT_SECRET);
+ const base = await subtle.importKey('raw', raw, 'HKDF', false, ['deriveKey']);
+ const key = await subtle.deriveKey(
+ {
+ name: 'HKDF',
+ hash: 'SHA-256',
+ salt: new TextEncoder().encode('oauth-token'),
+ info: new Uint8Array(0),
+ },
+ base,
+ { name: 'AES-GCM', length: 256 },
+ false,
+ ['decrypt'],
+ );
+ const buf = Buffer.from(ciphertext, 'base64');
+ const iv = buf.subarray(0, 12);
+ const ct = buf.subarray(12);
+ const plain = await subtle.decrypt({ name: 'AES-GCM', iv }, key, ct);
+ return new TextDecoder().decode(plain);
+}
+
+// ── X data fetch ──────────────────────────────────────────────────────────────
+
+async function fetchXData(accessToken, userId) {
+ const client = new TwitterApi(accessToken).readOnly;
+
+ const [userResp, tweetsResp] = await Promise.allSettled([
+ client.v2.user(userId, {
+ 'user.fields': [
+ 'name', 'username', 'description', 'public_metrics',
+ 'location', 'url', 'entities',
+ ],
+ }),
+ client.v2.userTimeline(userId, {
+ max_results: 100,
+ exclude: ['retweets', 'replies'],
+ 'tweet.fields': ['text', 'public_metrics', 'created_at'],
+ }),
+ ]);
+
+ const profile =
+ userResp.status === 'fulfilled'
+ ? {
+ name: userResp.value.data?.name,
+ username: userResp.value.data?.username,
+ bio: userResp.value.data?.description,
+ location: userResp.value.data?.location,
+ followers: userResp.value.data?.public_metrics?.followers_count,
+ following: userResp.value.data?.public_metrics?.following_count,
+ tweet_count: userResp.value.data?.public_metrics?.tweet_count,
+ }
+ : {};
+
+ const tweets =
+ tweetsResp.status === 'fulfilled'
+ ? (tweetsResp.value.data?.data || [])
+ .slice(0, 80)
+ .map((t) => ({
+ text: t.text,
+ likes: t.public_metrics?.like_count ?? 0,
+ retweets: t.public_metrics?.retweet_count ?? 0,
+ created_at: t.created_at,
+ }))
+ // Prefer higher-engagement tweets as they represent stronger signals
+ .sort((a, b) => b.likes + b.retweets - (a.likes + a.retweets))
+ .slice(0, 40)
+ .map((t) => t.text)
+ : [];
+
+ return { profile, tweets };
+}
+
+// ── Claude Haiku distillation ─────────────────────────────────────────────────
+
+async function distillFacts(xData) {
+ const tweetBlock =
+ xData.tweets.length
+ ? `\n\nRecent original tweets (highest-engagement first):\n${xData.tweets.map((t, i) => `${i + 1}. ${t}`).join('\n')}`
+ : '';
+
+ const res = await fetch('https://api.anthropic.com/v1/messages', {
+ method: 'POST',
+ headers: {
+ 'x-api-key': env.ANTHROPIC_API_KEY,
+ 'anthropic-version': '2023-06-01',
+ 'content-type': 'application/json',
+ },
+ body: JSON.stringify({
+ model: 'claude-haiku-4-5-20251001',
+ max_tokens: 1024,
+ system:
+ 'You distill a person\'s X (Twitter) profile and posts into concise memory facts ' +
+ 'for an AI agent that will represent this person. Each fact is a single ' +
+ 'self-contained sentence about the person — their interests, expertise, communication ' +
+ 'style, values, typical topics, or notable beliefs. Infer voice/tone from the tweet ' +
+ 'style. Skip promotional content. Focus on authentic personality signals. ' +
+ 'Output ONLY a JSON array of strings, no other text.',
+ messages: [
+ {
+ role: 'user',
+ content:
+ `Extract up to 15 memory facts from this X profile:\n` +
+ JSON.stringify(xData.profile, null, 2) +
+ tweetBlock,
+ },
+ ],
+ }),
+ });
+
+ if (!res.ok) {
+ const text = await res.text().catch(() => '');
+ throw new Error(`Claude API error ${res.status}: ${text.slice(0, 200)}`);
+ }
+
+ const data = await res.json();
+ const raw = data.content?.[0]?.text || '[]';
+ try {
+ const facts = JSON.parse(raw);
+ return Array.isArray(facts) ? facts.filter((f) => typeof f === 'string').slice(0, 15) : [];
+ } catch {
+ return [];
+ }
+}
+
+// ── Handler ───────────────────────────────────────────────────────────────────
+
+export default async function handleMemorySeedX(req, res, agentId) {
+ if (cors(req, res, { methods: 'POST,OPTIONS', credentials: true })) return;
+ if (!method(req, res, ['POST'])) return;
+
+ const session = await getSessionUser(req);
+ const bearer = session ? null : await authenticateBearer(extractBearer(req));
+ const userId = session?.id ?? bearer?.userId;
+ if (!userId) return error(res, 401, 'unauthorized', 'sign in required');
+
+ // Verify agent ownership
+ const [agent] = await sql`
+ SELECT id FROM agent_identities
+ WHERE id = ${agentId} AND user_id = ${userId} AND deleted_at IS NULL
+ `;
+ if (!agent) return error(res, 404, 'not_found', 'agent not found');
+
+ // Verify X connection
+ const [conn] = await sql`
+ SELECT access_token, provider_uid, username FROM social_connections
+ WHERE user_id = ${userId} AND provider = 'x'
+ `;
+ if (!conn) {
+ return error(
+ res,
+ 412,
+ 'not_connected',
+ 'connect your X account first at /settings?tab=connected-accounts',
+ );
+ }
+
+ // Rate limit: 1 seed per agent per 24 hours
+ const rl = await limits.memorySeed(agentId);
+ if (!rl.success) {
+ return error(res, 429, 'rate_limited', 'memory seeding is limited to once per 24 hours');
+ }
+
+ let accessToken;
+ try {
+ accessToken = await decryptToken(conn.access_token);
+ } catch (e) {
+ console.error('[memory-seed-x] token decrypt failed', e);
+ return error(res, 500, 'internal_error', 'could not decrypt stored token');
+ }
+
+ let xData;
+ try {
+ xData = await fetchXData(accessToken, conn.provider_uid);
+ } catch (e) {
+ console.error('[memory-seed-x] X API fetch failed', e);
+ return error(res, 502, 'upstream_error', e.message || 'X API fetch failed');
+ }
+
+ let facts;
+ try {
+ facts = await distillFacts(xData);
+ } catch (e) {
+ console.error('[memory-seed-x] distill failed', e);
+ return error(res, 502, 'distill_error', 'could not distill facts from X data');
+ }
+
+ if (facts.length === 0) {
+ return json(res, 200, { seeded: 0, facts: [], seeded_at: new Date().toISOString() });
+ }
+
+ // Replace previous X memories with the fresh distillation
+ await sql`DELETE FROM agent_memories WHERE agent_id = ${agentId} AND 'x' = ANY(tags)`;
+
+ const seededAt = new Date().toISOString();
+ const ctx = JSON.stringify({
+ source: 'x_seed',
+ x_username: conn.username,
+ seeded_at: seededAt,
+ });
+ for (const fact of facts) {
+ await sql`
+ INSERT INTO agent_memories (agent_id, type, content, tags, context, salience)
+ VALUES (
+ ${agentId},
+ 'user',
+ ${fact.slice(0, 10000)},
+ ${['x', 'persona']},
+ ${ctx}::jsonb,
+ 0.8
+ )
+ `;
+ }
+
+ return json(res, 200, {
+ seeded: facts.length,
+ facts,
+ x_username: conn.username,
+ seeded_at: seededAt,
+ });
+}
diff --git a/package-lock.json b/package-lock.json
index 197e8cc34..105e4f740 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -35,8 +35,10 @@
"@metaplex-foundation/umi": "^1.5.1",
"@metaplex-foundation/umi-bundle-defaults": "^1.5.1",
"@neondatabase/serverless": "^0.10.1",
+ "@neynar/nodejs-sdk": "^3.174.0",
"@nirholas/pump-sdk": "^1.0.0",
"@noble/curves": "^2.2.0",
+ "@octokit/rest": "^22.0.1",
"@pixiv/three-vrm": "^3.5.2",
"@pixiv/three-vrm-animation": "^3.5.2",
"@pump-fun/agent-payments-sdk": "^3.1.0",
@@ -69,6 +71,8 @@
"bs58": "^6.0.0",
"colyseus.js": "^0.16.22",
"dat.gui": "^0.7.9",
+ "draco3d": "^1.5.7",
+ "elevenlabs": "^1.59.0",
"ethers": "^6.16.0",
"express": "^4.22.1",
"fast-check": "^4.8.0",
@@ -77,6 +81,7 @@
"helius-sdk": "^2.2.2",
"jose": "^5.9.6",
"livekit-client": "^2.18.8",
+ "meshoptimizer": "^1.1.1",
"nipplejs": "^1.0.2",
"node-fetch": "^3.3.2",
"qrcode": "^1.5.4",
@@ -86,6 +91,7 @@
"sas-lib": "^1.0.10",
"simple-dropzone": "^0.8.3",
"three": "latest",
+ "twitter-api-v2": "^1.29.0",
"vhtml": "^2.2.0",
"viem": "^2.18.0",
"wawa-lipsync": "^0.0.2",
@@ -175,9 +181,13 @@
"node": ">=18"
},
"peerDependencies": {
+ "react": ">=18.0.0",
"three": ">=0.150.0"
},
"peerDependenciesMeta": {
+ "react": {
+ "optional": true
+ },
"three": {
"optional": false
}
@@ -12304,6 +12314,32 @@
"@types/pg": "8.11.6"
}
},
+ "node_modules/@neynar/nodejs-sdk": {
+ "version": "3.174.0",
+ "resolved": "https://registry.npmjs.org/@neynar/nodejs-sdk/-/nodejs-sdk-3.174.0.tgz",
+ "integrity": "sha512-H+8hPUzPFkuPyDH7R0aSVePLzPFwTfPl/HPYbY1XGbbQz/168pKoJuqWkaHOQ5tprq6OHpJ0NpVQVFkevoNQbA==",
+ "license": "MIT",
+ "dependencies": {
+ "axios": "^1.14.0",
+ "semver": "^7.6.3",
+ "viem": "^2.21.44"
+ },
+ "engines": {
+ "node": ">=19.9.0"
+ }
+ },
+ "node_modules/@neynar/nodejs-sdk/node_modules/semver": {
+ "version": "7.8.0",
+ "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.0.tgz",
+ "integrity": "sha512-AcM7dV/5ul4EekoQ29Agm5vri8JNqRyj39o0qpX6vDF2GZrtutZl5RwgD1XnZjiTAfncsJhMI48QQH3sN87YNA==",
+ "license": "ISC",
+ "bin": {
+ "semver": "bin/semver.js"
+ },
+ "engines": {
+ "node": ">=10"
+ }
+ },
"node_modules/@ngraveio/bc-ur": {
"version": "1.1.13",
"resolved": "https://registry.npmjs.org/@ngraveio/bc-ur/-/bc-ur-1.1.13.tgz",
@@ -12437,6 +12473,175 @@
"node": ">= 8"
}
},
+ "node_modules/@octokit/auth-token": {
+ "version": "6.0.0",
+ "resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-6.0.0.tgz",
+ "integrity": "sha512-P4YJBPdPSpWTQ1NU4XYdvHvXJJDxM6YwpS0FZHRgP7YFkdVxsWcpWGy/NVqlAA7PcPCnMacXlRm1y2PFZRWL/w==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 20"
+ }
+ },
+ "node_modules/@octokit/core": {
+ "version": "7.0.6",
+ "resolved": "https://registry.npmjs.org/@octokit/core/-/core-7.0.6.tgz",
+ "integrity": "sha512-DhGl4xMVFGVIyMwswXeyzdL4uXD5OGILGX5N8Y+f6W7LhC1Ze2poSNrkF/fedpVDHEEZ+PHFW0vL14I+mm8K3Q==",
+ "license": "MIT",
+ "dependencies": {
+ "@octokit/auth-token": "^6.0.0",
+ "@octokit/graphql": "^9.0.3",
+ "@octokit/request": "^10.0.6",
+ "@octokit/request-error": "^7.0.2",
+ "@octokit/types": "^16.0.0",
+ "before-after-hook": "^4.0.0",
+ "universal-user-agent": "^7.0.0"
+ },
+ "engines": {
+ "node": ">= 20"
+ }
+ },
+ "node_modules/@octokit/endpoint": {
+ "version": "11.0.3",
+ "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-11.0.3.tgz",
+ "integrity": "sha512-FWFlNxghg4HrXkD3ifYbS/IdL/mDHjh9QcsNyhQjN8dplUoZbejsdpmuqdA76nxj2xoWPs7p8uX2SNr9rYu0Ag==",
+ "license": "MIT",
+ "dependencies": {
+ "@octokit/types": "^16.0.0",
+ "universal-user-agent": "^7.0.2"
+ },
+ "engines": {
+ "node": ">= 20"
+ }
+ },
+ "node_modules/@octokit/graphql": {
+ "version": "9.0.3",
+ "resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-9.0.3.tgz",
+ "integrity": "sha512-grAEuupr/C1rALFnXTv6ZQhFuL1D8G5y8CN04RgrO4FIPMrtm+mcZzFG7dcBm+nq+1ppNixu+Jd78aeJOYxlGA==",
+ "license": "MIT",
+ "dependencies": {
+ "@octokit/request": "^10.0.6",
+ "@octokit/types": "^16.0.0",
+ "universal-user-agent": "^7.0.0"
+ },
+ "engines": {
+ "node": ">= 20"
+ }
+ },
+ "node_modules/@octokit/openapi-types": {
+ "version": "27.0.0",
+ "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-27.0.0.tgz",
+ "integrity": "sha512-whrdktVs1h6gtR+09+QsNk2+FO+49j6ga1c55YZudfEG+oKJVvJLQi3zkOm5JjiUXAagWK2tI2kTGKJ2Ys7MGA==",
+ "license": "MIT"
+ },
+ "node_modules/@octokit/plugin-paginate-rest": {
+ "version": "14.0.0",
+ "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-14.0.0.tgz",
+ "integrity": "sha512-fNVRE7ufJiAA3XUrha2omTA39M6IXIc6GIZLvlbsm8QOQCYvpq/LkMNGyFlB1d8hTDzsAXa3OKtybdMAYsV/fw==",
+ "license": "MIT",
+ "dependencies": {
+ "@octokit/types": "^16.0.0"
+ },
+ "engines": {
+ "node": ">= 20"
+ },
+ "peerDependencies": {
+ "@octokit/core": ">=6"
+ }
+ },
+ "node_modules/@octokit/plugin-request-log": {
+ "version": "6.0.0",
+ "resolved": "https://registry.npmjs.org/@octokit/plugin-request-log/-/plugin-request-log-6.0.0.tgz",
+ "integrity": "sha512-UkOzeEN3W91/eBq9sPZNQ7sUBvYCqYbrrD8gTbBuGtHEuycE4/awMXcYvx6sVYo7LypPhmQwwpUe4Yyu4QZN5Q==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 20"
+ },
+ "peerDependencies": {
+ "@octokit/core": ">=6"
+ }
+ },
+ "node_modules/@octokit/plugin-rest-endpoint-methods": {
+ "version": "17.0.0",
+ "resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-17.0.0.tgz",
+ "integrity": "sha512-B5yCyIlOJFPqUUeiD0cnBJwWJO8lkJs5d8+ze9QDP6SvfiXSz1BF+91+0MeI1d2yxgOhU/O+CvtiZ9jSkHhFAw==",
+ "license": "MIT",
+ "dependencies": {
+ "@octokit/types": "^16.0.0"
+ },
+ "engines": {
+ "node": ">= 20"
+ },
+ "peerDependencies": {
+ "@octokit/core": ">=6"
+ }
+ },
+ "node_modules/@octokit/request": {
+ "version": "10.0.9",
+ "resolved": "https://registry.npmjs.org/@octokit/request/-/request-10.0.9.tgz",
+ "integrity": "sha512-o8Bi3f608eyM+7BmBiUWxFsdjLb3/ym1cQek5LZOv9KkZcxRrHCPhhRzm6xjO6HVZ85ItD6+sTsjxo821SVa/A==",
+ "license": "MIT",
+ "dependencies": {
+ "@octokit/endpoint": "^11.0.3",
+ "@octokit/request-error": "^7.0.2",
+ "@octokit/types": "^16.0.0",
+ "content-type": "^2.0.0",
+ "fast-content-type-parse": "^3.0.0",
+ "json-with-bigint": "^3.5.3",
+ "universal-user-agent": "^7.0.2"
+ },
+ "engines": {
+ "node": ">= 20"
+ }
+ },
+ "node_modules/@octokit/request-error": {
+ "version": "7.1.0",
+ "resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-7.1.0.tgz",
+ "integrity": "sha512-KMQIfq5sOPpkQYajXHwnhjCC0slzCNScLHs9JafXc4RAJI+9f+jNDlBNaIMTvazOPLgb4BnlhGJOTbnN0wIjPw==",
+ "license": "MIT",
+ "dependencies": {
+ "@octokit/types": "^16.0.0"
+ },
+ "engines": {
+ "node": ">= 20"
+ }
+ },
+ "node_modules/@octokit/request/node_modules/content-type": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/content-type/-/content-type-2.0.0.tgz",
+ "integrity": "sha512-j/O/d7GcZCyNl7/hwZAb606rzqkyvaDctLmckbxLzHvFBzTJHuGEdodATcP3yIRoDrLHkIATJuvzbFlp/ki2cQ==",
+ "license": "MIT",
+ "engines": {
+ "node": ">=18"
+ },
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/express"
+ }
+ },
+ "node_modules/@octokit/rest": {
+ "version": "22.0.1",
+ "resolved": "https://registry.npmjs.org/@octokit/rest/-/rest-22.0.1.tgz",
+ "integrity": "sha512-Jzbhzl3CEexhnivb1iQ0KJ7s5vvjMWcmRtq5aUsKmKDrRW6z3r84ngmiFKFvpZjpiU/9/S6ITPFRpn5s/3uQJw==",
+ "license": "MIT",
+ "dependencies": {
+ "@octokit/core": "^7.0.6",
+ "@octokit/plugin-paginate-rest": "^14.0.0",
+ "@octokit/plugin-request-log": "^6.0.0",
+ "@octokit/plugin-rest-endpoint-methods": "^17.0.0"
+ },
+ "engines": {
+ "node": ">= 20"
+ }
+ },
+ "node_modules/@octokit/types": {
+ "version": "16.0.0",
+ "resolved": "https://registry.npmjs.org/@octokit/types/-/types-16.0.0.tgz",
+ "integrity": "sha512-sKq+9r1Mm4efXW1FCk7hFSeJo4QKreL/tTbR0rz/qx/r1Oa2VV83LTA/H/MuCOX7uCIJmQVRKBcbmWoySjAnSg==",
+ "license": "MIT",
+ "dependencies": {
+ "@octokit/openapi-types": "^27.0.0"
+ }
+ },
"node_modules/@opentelemetry/api": {
"version": "1.9.1",
"resolved": "https://registry.npmjs.org/@opentelemetry/api/-/api-1.9.1.tgz",
@@ -27510,6 +27715,12 @@
"integrity": "sha512-LcknSilhIGatDAsY1ak2I8VtGaHNhgMSYVxFrGLXv+xLHytaKZKcaUJJUE7qmBr7h33o5YQwP55pMI0xmkpJwg==",
"license": "MIT"
},
+ "node_modules/before-after-hook": {
+ "version": "4.0.0",
+ "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-4.0.0.tgz",
+ "integrity": "sha512-q6tR3RPqIB1pMiTRMFcZwuG5T8vwp+vUvEG0vuI6B+Rikh5BfPp2fQ82c925FOs+b0lcFQ8CFrL+KbilfZFhOQ==",
+ "license": "Apache-2.0"
+ },
"node_modules/bidi-js": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/bidi-js/-/bidi-js-1.0.3.tgz",
@@ -28736,6 +28947,12 @@
"node": ">= 0.8"
}
},
+ "node_modules/command-exists": {
+ "version": "1.2.9",
+ "resolved": "https://registry.npmjs.org/command-exists/-/command-exists-1.2.9.tgz",
+ "integrity": "sha512-LTQ/SGc+s0Xc0Fu5WaKnR0YiygZkm9eKFvyS+fRsU7/ZWFF8ykFM6Pc9aCVf1+xasOOZpO3BAVgVrKvsqKHV7w==",
+ "license": "MIT"
+ },
"node_modules/commander": {
"version": "2.20.3",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz",
@@ -29043,7 +29260,6 @@
"version": "7.0.6",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz",
"integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==",
- "dev": true,
"license": "MIT",
"dependencies": {
"path-key": "^3.1.0",
@@ -29944,6 +30160,12 @@
"node": ">=10"
}
},
+ "node_modules/draco3d": {
+ "version": "1.5.7",
+ "resolved": "https://registry.npmjs.org/draco3d/-/draco3d-1.5.7.tgz",
+ "integrity": "sha512-m6WCKt/erDXcw+70IJXnG7M3awwQPAsZvJGX5zY7beBqpELw6RDGkYVU0W43AFxye4pDZ5i2Lbyc/NNGqwjUVQ==",
+ "license": "Apache-2.0"
+ },
"node_modules/draggabilly": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/draggabilly/-/draggabilly-3.0.0.tgz",
@@ -30050,6 +30272,66 @@
"integrity": "sha512-AbH9q9J455r/nLmdNZes0G0ZKcRX73FicwowalLs6ijwOmCJSRRrLX63lcAlzy9ux3dWK1w1+1nsBJEWN11hcQ==",
"license": "ISC"
},
+ "node_modules/elevenlabs": {
+ "version": "1.59.0",
+ "resolved": "https://registry.npmjs.org/elevenlabs/-/elevenlabs-1.59.0.tgz",
+ "integrity": "sha512-OVKOd+lxNya8h4Rn5fcjv00Asd+DGWfTT6opGrQ16sTI+1HwdLn/kYtjl8tRMhDXbNmksD/9SBRKjb9neiUuVg==",
+ "deprecated": "This package has moved to @elevenlabs/elevenlabs-js",
+ "license": "MIT",
+ "dependencies": {
+ "command-exists": "^1.2.9",
+ "execa": "^5.1.1",
+ "form-data": "^4.0.0",
+ "form-data-encoder": "^4.0.2",
+ "formdata-node": "^6.0.3",
+ "node-fetch": "^2.7.0",
+ "qs": "^6.13.1",
+ "readable-stream": "^4.5.2",
+ "url-join": "4.0.1"
+ }
+ },
+ "node_modules/elevenlabs/node_modules/node-fetch": {
+ "version": "2.7.0",
+ "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz",
+ "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==",
+ "license": "MIT",
+ "dependencies": {
+ "whatwg-url": "^5.0.0"
+ },
+ "engines": {
+ "node": "4.x || >=6.0.0"
+ },
+ "peerDependencies": {
+ "encoding": "^0.1.0"
+ },
+ "peerDependenciesMeta": {
+ "encoding": {
+ "optional": true
+ }
+ }
+ },
+ "node_modules/elevenlabs/node_modules/tr46": {
+ "version": "0.0.3",
+ "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
+ "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==",
+ "license": "MIT"
+ },
+ "node_modules/elevenlabs/node_modules/webidl-conversions": {
+ "version": "3.0.1",
+ "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
+ "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==",
+ "license": "BSD-2-Clause"
+ },
+ "node_modules/elevenlabs/node_modules/whatwg-url": {
+ "version": "5.0.0",
+ "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
+ "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==",
+ "license": "MIT",
+ "dependencies": {
+ "tr46": "~0.0.3",
+ "webidl-conversions": "^3.0.0"
+ }
+ },
"node_modules/elliptic": {
"version": "6.6.1",
"resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.6.1.tgz",
@@ -31545,7 +31827,6 @@
"version": "5.1.1",
"resolved": "https://registry.npmjs.org/execa/-/execa-5.1.1.tgz",
"integrity": "sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==",
- "dev": true,
"license": "MIT",
"dependencies": {
"cross-spawn": "^7.0.3",
@@ -31569,7 +31850,6 @@
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz",
"integrity": "sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==",
- "dev": true,
"license": "MIT",
"engines": {
"node": ">=10"
@@ -31582,7 +31862,6 @@
"version": "3.0.7",
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz",
"integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==",
- "dev": true,
"license": "ISC"
},
"node_modules/exenv": {
@@ -31831,6 +32110,22 @@
],
"license": "MIT"
},
+ "node_modules/fast-content-type-parse": {
+ "version": "3.0.0",
+ "resolved": "https://registry.npmjs.org/fast-content-type-parse/-/fast-content-type-parse-3.0.0.tgz",
+ "integrity": "sha512-ZvLdcY8P+N8mGQJahJV5G4U88CSvT1rP8ApL6uETe88MBXrBHAkZlSEySdUlyztF7ccb+Znos3TFqaepHxdhBg==",
+ "funding": [
+ {
+ "type": "github",
+ "url": "https://github.com/sponsors/fastify"
+ },
+ {
+ "type": "opencollective",
+ "url": "https://opencollective.com/fastify"
+ }
+ ],
+ "license": "MIT"
+ },
"node_modules/fast-deep-equal": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
@@ -32405,6 +32700,24 @@
"node": ">= 6"
}
},
+ "node_modules/form-data-encoder": {
+ "version": "4.1.0",
+ "resolved": "https://registry.npmjs.org/form-data-encoder/-/form-data-encoder-4.1.0.tgz",
+ "integrity": "sha512-G6NsmEW15s0Uw9XnCg+33H3ViYRyiM0hMrMhhqQOR8NFc5GhYrI+6I3u7OTw7b91J2g8rtvMBZJDbcGb2YUniw==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 18"
+ }
+ },
+ "node_modules/formdata-node": {
+ "version": "6.0.3",
+ "resolved": "https://registry.npmjs.org/formdata-node/-/formdata-node-6.0.3.tgz",
+ "integrity": "sha512-8e1++BCiTzUno9v5IZ2J6bv4RU+3UKDmqWUQD0MIMVCd9AdhWkO1gw57oo1mNEX1dMq2EGI+FbWz4B92pscSQg==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 18"
+ }
+ },
"node_modules/formdata-polyfill": {
"version": "4.0.10",
"resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz",
@@ -34279,7 +34592,6 @@
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz",
"integrity": "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==",
- "dev": true,
"license": "Apache-2.0",
"engines": {
"node": ">=10.17.0"
@@ -35421,7 +35733,6 @@
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz",
"integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==",
- "dev": true,
"license": "MIT",
"engines": {
"node": ">=8"
@@ -35548,7 +35859,6 @@
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
"integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==",
- "dev": true,
"license": "ISC"
},
"node_modules/iso-url": {
@@ -38040,6 +38350,12 @@
"integrity": "sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA==",
"license": "ISC"
},
+ "node_modules/json-with-bigint": {
+ "version": "3.5.8",
+ "resolved": "https://registry.npmjs.org/json-with-bigint/-/json-with-bigint-3.5.8.tgz",
+ "integrity": "sha512-eq/4KP6K34kwa7TcFdtvnftvHCD9KvHOGGICWwMFc4dOOKF5t4iYqnfLK8otCRCRv06FXOzGGyqE8h8ElMvvdw==",
+ "license": "MIT"
+ },
"node_modules/json5": {
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz",
@@ -39028,7 +39344,6 @@
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz",
"integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==",
- "dev": true,
"license": "MIT"
},
"node_modules/merge2": {
@@ -39056,6 +39371,12 @@
"node": ">= 7.6.0"
}
},
+ "node_modules/meshoptimizer": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/meshoptimizer/-/meshoptimizer-1.1.1.tgz",
+ "integrity": "sha512-oRFNWJRDA/WTrVj7NWvqa5HqE1t9MYDj2VaWirQCzCCrAd2GHrqR/sQezCxiWATPNlKTcRaPRHPJwIRoPBAp5g==",
+ "license": "MIT"
+ },
"node_modules/methods": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz",
@@ -39980,7 +40301,6 @@
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz",
"integrity": "sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==",
- "dev": true,
"license": "MIT",
"dependencies": {
"path-key": "^3.0.0"
@@ -40708,7 +41028,6 @@
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz",
"integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==",
- "dev": true,
"license": "MIT",
"engines": {
"node": ">=8"
@@ -44572,7 +44891,6 @@
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz",
"integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==",
- "dev": true,
"license": "MIT",
"dependencies": {
"shebang-regex": "^3.0.0"
@@ -44585,7 +44903,6 @@
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz",
"integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==",
- "dev": true,
"license": "MIT",
"engines": {
"node": ">=8"
@@ -45364,7 +45681,6 @@
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-2.0.0.tgz",
"integrity": "sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==",
- "dev": true,
"license": "MIT",
"engines": {
"node": ">=6"
@@ -46549,6 +46865,12 @@
"integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==",
"license": "Unlicense"
},
+ "node_modules/twitter-api-v2": {
+ "version": "1.29.0",
+ "resolved": "https://registry.npmjs.org/twitter-api-v2/-/twitter-api-v2-1.29.0.tgz",
+ "integrity": "sha512-v473q5bwme4N+DWSg6qY+JCvfg1nSJRWwui3HUALafxfqCvVkKiYmS/5x/pVeJwTmyeBxexMbzHwnzrH4h6oYQ==",
+ "license": "Apache-2.0"
+ },
"node_modules/type-check": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz",
@@ -47017,6 +47339,12 @@
"node": ">=8"
}
},
+ "node_modules/universal-user-agent": {
+ "version": "7.0.3",
+ "resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-7.0.3.tgz",
+ "integrity": "sha512-TmnEAEAsBJVZM/AADELsK76llnwcf9vMKuPz8JflO1frO8Lchitr0fNaN9d+Ap0BjKtqWqd/J17qeDnXh8CL2A==",
+ "license": "ISC"
+ },
"node_modules/universalify": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz",
@@ -47255,6 +47583,12 @@
"node": ">= 0.4"
}
},
+ "node_modules/url-join": {
+ "version": "4.0.1",
+ "resolved": "https://registry.npmjs.org/url-join/-/url-join-4.0.1.tgz",
+ "integrity": "sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA==",
+ "license": "MIT"
+ },
"node_modules/url/node_modules/punycode": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz",
@@ -48117,7 +48451,6 @@
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
"integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==",
- "dev": true,
"license": "ISC",
"dependencies": {
"isexe": "^2.0.0"
diff --git a/package.json b/package.json
index 353bca189..5ae34374c 100644
--- a/package.json
+++ b/package.json
@@ -106,8 +106,10 @@
"@metaplex-foundation/umi": "^1.5.1",
"@metaplex-foundation/umi-bundle-defaults": "^1.5.1",
"@neondatabase/serverless": "^0.10.1",
+ "@neynar/nodejs-sdk": "^3.174.0",
"@nirholas/pump-sdk": "^1.0.0",
"@noble/curves": "^2.2.0",
+ "@octokit/rest": "^22.0.1",
"@pixiv/three-vrm": "^3.5.2",
"@pixiv/three-vrm-animation": "^3.5.2",
"@pump-fun/agent-payments-sdk": "^3.1.0",
@@ -140,6 +142,8 @@
"bs58": "^6.0.0",
"colyseus.js": "^0.16.22",
"dat.gui": "^0.7.9",
+ "draco3d": "^1.5.7",
+ "elevenlabs": "^1.59.0",
"ethers": "^6.16.0",
"express": "^4.22.1",
"fast-check": "^4.8.0",
@@ -148,6 +152,7 @@
"helius-sdk": "^2.2.2",
"jose": "^5.9.6",
"livekit-client": "^2.18.8",
+ "meshoptimizer": "^1.1.1",
"nipplejs": "^1.0.2",
"node-fetch": "^3.3.2",
"qrcode": "^1.5.4",
@@ -157,6 +162,7 @@
"sas-lib": "^1.0.10",
"simple-dropzone": "^0.8.3",
"three": "latest",
+ "twitter-api-v2": "^1.29.0",
"vhtml": "^2.2.0",
"viem": "^2.18.0",
"wawa-lipsync": "^0.0.2",
diff --git a/public/demos/selfie-fit.html b/public/demos/selfie-fit.html
index efe0b863d..beeb69347 100644
--- a/public/demos/selfie-fit.html
+++ b/public/demos/selfie-fit.html
@@ -256,6 +256,70 @@
const $ = (sel, root = document) => root.querySelector(sel);
const $$ = (sel, root = document) => Array.from(root.querySelectorAll(sel));
+ // ── Face quality scoring ─────────────────────────────────────────────
+ // Blur: variance of the 4-neighbour Laplacian on a 64×64 face crop.
+ // Scores below BLUR_MIN indicate the frame is too blurry to use.
+ // Luma: mean luminance of the face crop. Below LUMA_MIN = too dark,
+ // above LUMA_MAX = overexposed.
+ const BLUR_MIN = 3.5; // tune: lower → more permissive
+ const LUMA_MIN = 40; // 0–255 scale
+ const LUMA_MAX = 218;
+
+ let _qCanvas = null, _qCtx = null;
+ function computeFaceQuality(video, lms) {
+ const SIZE = 64;
+ if (!_qCanvas) {
+ _qCanvas = document.createElement('canvas');
+ _qCanvas.width = _qCanvas.height = SIZE;
+ _qCtx = _qCanvas.getContext('2d', { willReadFrequently: true });
+ }
+ // Bounding box of landmarks in normalised [0,1] coords
+ let minX = 1, minY = 1, maxX = 0, maxY = 0;
+ for (const lm of lms) {
+ if (lm.x < minX) minX = lm.x;
+ if (lm.y < minY) minY = lm.y;
+ if (lm.x > maxX) maxX = lm.x;
+ if (lm.y > maxY) maxY = lm.y;
+ }
+ const pad = 0.05;
+ const vw = video.videoWidth, vh = video.videoHeight;
+ const fx = Math.max(0, (minX - pad)) * vw;
+ const fy = Math.max(0, (minY - pad)) * vh;
+ const fw = Math.min(vw - fx, (maxX - minX + 2 * pad) * vw);
+ const fh = Math.min(vh - fy, (maxY - minY + 2 * pad) * vh);
+ if (fw < 4 || fh < 4) return { luma: 0, blur: 0 };
+
+ // Draw face crop at SIZE×SIZE (note: video is displayed mirrored in CSS
+ // but the raw pixel data is un-mirrored — same as landmark coords).
+ _qCtx.drawImage(video, fx, fy, fw, fh, 0, 0, SIZE, SIZE);
+ const { data: d } = _qCtx.getImageData(0, 0, SIZE, SIZE);
+ const n = SIZE * SIZE;
+ const grays = new Float32Array(n);
+ let lumaSum = 0;
+ for (let i = 0, j = 0; i < d.length; i += 4, j++) {
+ const g = 0.299 * d[i] + 0.587 * d[i + 1] + 0.114 * d[i + 2];
+ grays[j] = g;
+ lumaSum += g;
+ }
+ const luma = lumaSum / n;
+ // 4-neighbour Laplacian variance (blur estimator)
+ let ls = 0, ls2 = 0, ln = 0;
+ for (let row = 1; row < SIZE - 1; row++) {
+ for (let col = 1; col < SIZE - 1; col++) {
+ const c = grays[row * SIZE + col];
+ const lap = 4 * c
+ - grays[(row - 1) * SIZE + col]
+ - grays[(row + 1) * SIZE + col]
+ - grays[row * SIZE + (col - 1)]
+ - grays[row * SIZE + (col + 1)];
+ ls += lap; ls2 += lap * lap; ln++;
+ }
+ }
+ const mean = ls / ln;
+ const blur = Math.sqrt(Math.max(0, ls2 / ln - mean * mean));
+ return { luma, blur };
+ }
+
// ── Log helper ──────────────────────────────────────────────────────
const logEl = $('#log');
logEl.textContent = '';
@@ -531,8 +595,14 @@
const nose = lms[1] || lms[4];
centered = nose && Math.abs(nose.x - 0.5) < 0.22 && Math.abs(nose.y - 0.5) < 0.28;
+ // Blur + lighting quality gates (sampled every frame; cheap at 64px)
+ const q = computeFaceQuality(video, lms);
+ state._quality = q;
+
const yawOk = yawDeg >= slotCfg.min && yawDeg <= slotCfg.max;
- pass = yawOk && centered;
+ const blurOk = q.blur >= BLUR_MIN;
+ const lumaOk = q.luma >= LUMA_MIN && q.luma <= LUMA_MAX;
+ pass = yawOk && centered && blurOk && lumaOk;
}
// Throttled log: only when state changes
@@ -554,8 +624,12 @@
const chips = [];
chips.push(makeChip(faceFound ? 'face' : 'no face', faceFound ? 'ok' : 'bad'));
if (faceFound) {
+ const q = state._quality || { blur: 0, luma: 0 };
chips.push(makeChip(`yaw ${yawDeg.toFixed(0)}°`, (yawDeg >= slotCfg.min && yawDeg <= slotCfg.max) ? 'ok' : 'bad'));
chips.push(makeChip(centered ? 'centered' : 'recenter', centered ? 'ok' : 'bad'));
+ chips.push(makeChip(q.blur < BLUR_MIN ? 'blurry' : 'sharp', q.blur >= BLUR_MIN ? 'ok' : 'bad'));
+ const lumaLabel = q.luma < LUMA_MIN ? 'too dark' : q.luma > LUMA_MAX ? 'overexposed' : 'lit ✓';
+ chips.push(makeChip(lumaLabel, (q.luma >= LUMA_MIN && q.luma <= LUMA_MAX) ? 'ok' : 'bad'));
}
chips.forEach((c) => state.badgeEl.appendChild(c));
@@ -874,6 +948,48 @@
return c.toDataURL('image/jpeg', 0.85);
}
+ // ── Avaturn export handler ───────────────────────────────────────────
+ // When the user finishes editing in the Avaturn iframe and taps Export,
+ // Avaturn posts a message: { source:'avaturn', eventName:'export', data:{ url, urlType } }
+ // We close the modal and show the "Mint as agent" CTA with the GLB URL.
+ window.addEventListener('message', (event) => {
+ if (!event.data || typeof event.data !== 'object') return;
+ if (event.data.source !== 'avaturn' || event.data.eventName !== 'export') return;
+ const glbUrl = event.data.data?.url;
+ if (!glbUrl) return;
+ log('Export received from Avaturn editor.', 'ok');
+ log('GLB URL: ' + glbUrl, 'ok');
+ // Close the iframe modal
+ $('#iframe-modal')?.classList.remove('open');
+ const iframeSrc = $('#session-iframe');
+ if (iframeSrc) iframeSrc.src = 'about:blank';
+ // Show mint CTA
+ showExportReady(glbUrl);
+ });
+
+ function showExportReady(glbUrl) {
+ const card = $('#result-card');
+ card.classList.add('show');
+ // Encode the GLB URL so /create can pre-fill it
+ const createHref = '/create?avatarUrl=' + encodeURIComponent(glbUrl);
+ card.innerHTML = `
+ <h2 style="margin:0 0 8px;font-size:17px;font-weight:600">Your avatar is ready</h2>
+ <p style="margin:0 0 16px;color:#8a8d98;font-size:14px;line-height:1.55">
+ Your 3D avatar was exported from the three.ws Selfie editor.<br>
+ Next: mint it on-chain as a three.ws agent with an ERC-8004 identity.
+ </p>
+ <div style="display:flex;gap:10px;flex-wrap:wrap">
+ <a href="${createHref}" class="submit" style="text-decoration:none;display:inline-flex;align-items:center;gap:6px">
+ Mint as agent →
+ </a>
+ <a href="${glbUrl}" target="_blank" rel="noopener"
+ class="submit" style="text-decoration:none;display:inline-flex;align-items:center;gap:6px;background:#1e1f2b;color:#eee">
+ Download GLB ↓
+ </a>
+ </div>
+ `;
+ }
+
log('demo ready. click a slot to begin.', 'ok');
</script>
</body>