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.

fix(marketplace): store paid generated GLBs under random keys and number repeat takes

nirholas8d10f93c7760
diff --git a/api/_lib/generated-clip-market.js b/api/_lib/generated-clip-market.js
index 5a2375b44..d105fe429 100644
--- a/api/_lib/generated-clip-market.js
+++ b/api/_lib/generated-clip-market.js
@@ -56,9 +56,11 @@ export function freeEpochEndsAt(now = Date.now()) {
*
* @param {{ name: string, label?: string, category?: string, loop?: boolean, duration?: number }} entry manifest row
* @param {{ tracks?: Array<{ times?: ArrayLike<number> }>, duration?: number, userData?: Record<string, any> }} clip the library clip JSON
- * @param {{ ownerId: string, price: number, artifactKey: string, artifactBytes: number, tags?: string[] }} listing
+ * @param {{ ownerId: string, price: number, artifactKey: string, artifactBytes: number, tags?: string[], take?: number }} listing
+ * `take` numbers the listings of one prompt (1, 2, 3...) so takes that share a
+ * label stay distinguishable; take 1 keeps the bare label.
*/
-export function generatedListingRow(entry, clip, { ownerId, price, artifactKey, artifactBytes, tags = [] }) {
+export function generatedListingRow(entry, clip, { ownerId, price, artifactKey, artifactBytes, tags = [], take = 1 }) {
const duration = Number(clip?.duration ?? entry.duration ?? 0);
let frames = 0;
for (const track of clip?.tracks ?? []) frames = Math.max(frames, track?.times?.length ?? 0);
@@ -70,7 +72,7 @@ export function generatedListingRow(entry, clip, { ownerId, price, artifactKey,
return {
owner_id: ownerId,
slug: entry.name,
- name: entry.label || entry.name,
+ name: take > 1 ? `${entry.label || entry.name} (take ${take})` : entry.label || entry.name,
description: prompt
? `Generated on the three.ws motion lane from the prompt "${prompt}". Baked onto the three.ws rig as a GLB.`
: 'Generated on the three.ws motion lane. Baked onto the three.ws rig as a GLB.',
diff --git a/scripts/gcp/seed-motion.mjs b/scripts/gcp/seed-motion.mjs
index 8f5982114..2189bdf6b 100644
--- a/scripts/gcp/seed-motion.mjs
+++ b/scripts/gcp/seed-motion.mjs
@@ -59,7 +59,7 @@
* own and would otherwise delete the other's catalog (see api/animations/library.js).
*/
-import { createHash } from 'node:crypto';
+import { createHash, randomUUID } from 'node:crypto';
import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from 'node:fs';
import { dirname, join, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
@@ -607,6 +607,7 @@ async function listForSale(state) {
return { listed: 0 };
}
const { client, PutObjectCommand, bucket, publicDomain } = store;
+ const { DeleteObjectCommand } = await import('@aws-sdk/client-s3');
const { sql } = await import('../../api/_lib/db.js');
const { bakeMotionGlb } = await import('../../api/_lib/motion-glb.js');
const market = await import('../../api/_lib/generated-clip-market.js');
@@ -621,13 +622,39 @@ async function listForSale(state) {
const prompts = new Map(loadPrompts().map((p) => [p.id, p]));
log(`Listing ${entries.length} generated clips at ${price} USDC under ${market.PLATFORM_CREATOR_EMAIL}`);
+ // The object store serves its whole bucket on a public domain, and every
+ // clip name is published in the free manifest, so a GLB keyed by clip name
+ // could be fetched without paying. Each listing's GLB lives under a random
+ // key instead, kept in its row and reused on every later run.
+ const existing = new Map(
+ (
+ await sql`select slug, artifact_key from animation_clips where owner_id = ${owner.id} and ${market.GENERATED_TAG} = any(tags)`
+ ).map((r) => [r.slug, r.artifact_key]),
+ );
+ const unguessable = (key, name) =>
+ typeof key === 'string' && key.startsWith(`${market.GENERATED_GLB_PREFIX}/`) && !key.includes(name);
+
+ // Several takes of one prompt share a label; number them so a buyer can tell
+ // them apart. Lowest take first, matching the publish order.
+ const takeOf = new Map();
+ const perPrompt = {};
+ for (const entry of entries) {
+ // gen-<prompt id>-<12 hex>: the id is everything between prefix and hash.
+ const promptId = entry.name.slice(CLIP_NAME_PREFIX.length, entry.name.lastIndexOf('-'));
+ perPrompt[promptId] = (perPrompt[promptId] || 0) + 1;
+ takeOf.set(entry.name, perPrompt[promptId]);
+ }
+
let listed = 0;
for (const entry of entries) {
const clip = JSON.parse(readFileSync(join(CLIPS_DIR, `${entry.name}.json`), 'utf8'));
// Staged clips are in the library basis, so the bake leaves their root
// alone (see bakeMotionGlb): a walk keeps the travel its feet imply.
const { glb } = bakeMotionGlb({ rig, clip, name: entry.label || entry.name });
- const artifactKey = `${market.GENERATED_GLB_PREFIX}/${entry.name}.glb`;
+ const previous = existing.get(entry.name);
+ const artifactKey = unguessable(previous, entry.name)
+ ? previous
+ : `${market.GENERATED_GLB_PREFIX}/${randomUUID()}.glb`;
await client.send(
new PutObjectCommand({
Bucket: bucket,
@@ -644,6 +671,7 @@ async function listForSale(state) {
artifactKey,
artifactBytes: glb.length,
tags: prompts.get(promptId)?.tags ?? [],
+ take: takeOf.get(entry.name),
});
const storageKey = `${R2_PREFIX}/clips/${entry.name}.json`;
await sql`
@@ -666,6 +694,11 @@ async function listForSale(state) {
artifact_bytes = excluded.artifact_bytes, artifact_mime = excluded.artifact_mime,
listed = true, deleted_at = null
`;
+ // A GLB an earlier run stored under its guessable name is removed once
+ // the row points at the random key.
+ if (previous && previous !== artifactKey && !unguessable(previous, entry.name)) {
+ await client.send(new DeleteObjectCommand({ Bucket: bucket, Key: previous }));
+ }
listed++;
if (listed % 25 === 0) log(` listed ${listed}/${entries.length}`);
}
diff --git a/tests/api/generated-clip-market.test.js b/tests/api/generated-clip-market.test.js
index 70876acd6..1afa01af5 100644
--- a/tests/api/generated-clip-market.test.js
+++ b/tests/api/generated-clip-market.test.js
@@ -98,6 +98,13 @@ describe('generatedListingRow', () => {
expect(row.name).toBe(SLUGS[1]);
});
+ it('numbers later takes of one prompt so they stay distinguishable', () => {
+ const listing = { ownerId: PLATFORM_ID, price: 0.01, artifactKey: 'k.glb', artifactBytes: 1 };
+ const entry = { name: SLUGS[2], label: 'Wave Hello' };
+ expect(market.generatedListingRow(entry, clip, listing).name).toBe('Wave Hello');
+ expect(market.generatedListingRow(entry, clip, { ...listing, take: 2 }).name).toBe('Wave Hello (take 2)');
+ });
+
it('prices at the Animation Bazaar advertised price, overridable by env', () => {
expect(market.generatedListingPrice()).toBe(0.01);
process.env.X402_PRICE_ANIMATION_DOWNLOAD = '250000';