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
feat(forge): tier-scaled quality budgets for the self-host TRELLIS lane
nirholasd64566bef5fa
diff --git a/api/_lib/forge-tiers.js b/api/_lib/forge-tiers.jsindex a9352e471..166844552 100644--- a/api/_lib/forge-tiers.js+++ b/api/_lib/forge-tiers.js@@ -381,7 +381,13 @@ export const DEFAULT_BACKEND_FOR_PATH = Object.freeze({export const FREE_DEFAULT_FOR_TIERS = Object.freeze({draft: Object.freeze({ image: 'nvidia' }),standard: Object.freeze({ image: 'nvidia' }),- high: Object.freeze({ image: 'huggingface' }),+ // High names our self-host Hunyuan3D worker — the highest-fidelity engine we+ // can run on our own GPUs. Until GCP_HUNYUAN3D_URL is configured the candidate+ // walk falls to the per-path chain (self-host TRELLIS first). The external+ // HuggingFace Spaces lane (the previous name here) stays in the fallback chain+ // but no longer leads: its Hunyuan Spaces sit GPU-quota-dead for most of the+ // day, so naming it made the tier a coin-flip.+ high: Object.freeze({ image: 'hunyuan3d' }),});// Free lanes to fall back to per path when the tier's named free engine can't@@ -565,6 +571,27 @@ export function selfHostPrimary() {return /^(1|true|on|yes)$/i.test(String(v).trim());}+// Per-tier sampling/export budgets for the self-host TRELLIS worker+// (workers/model-trellis /infer `quality` field). One shared map so the submit+// site, the catalog, and tests can never disagree about what a tier buys:+// • ss/slat steps — diffusion sampler budget for structure and appearance.+// TRELLIS defaults to 12; quality keeps improving to ~50 at linear GPU cost.+// • simplify — fraction of triangles REMOVED by GLB export decimation+// (lower keeps more geometry).+// • texture_size — baked texture resolution.+// GPU time runs against platform GCP credits (the L4 is already reserved at+// minScale 1), so tiers price the USER for quality, not us for compute.+// Draft stays at the worker's fast defaults for iteration speed.+export const SELFHOST_TRELLIS_QUALITY = Object.freeze({+ draft: Object.freeze({ ss_steps: 12, slat_steps: 12, simplify: 0.95, texture_size: 1024 }),+ standard: Object.freeze({ ss_steps: 25, slat_steps: 25, simplify: 0.9, texture_size: 2048 }),+ high: Object.freeze({ ss_steps: 45, slat_steps: 45, simplify: 0.85, texture_size: 2048 }),+});++export function selfhostQualityForTier(tierId) {+ return SELFHOST_TRELLIS_QUALITY[tierId] || SELFHOST_TRELLIS_QUALITY[DEFAULT_TIER];+}+// A platform backend is "live" only when its required env is present. BYOK// backends are always selectable — liveness depends on the caller's key, which// is resolved per-request, not here.diff --git a/api/_providers/gcp.js b/api/_providers/gcp.jsindex b48335bde..f41112bc5 100644--- a/api/_providers/gcp.js+++ b/api/_providers/gcp.js@@ -125,17 +125,24 @@ function buildWorkerRequest(request) {if (mode === 'trellis') {// Self-hosted TRELLIS image→3D (workers/model-trellis). Reconstructs a- // textured mesh from the primary reference view — a user photo, or the- // FLUX-synthesized view for a text prompt. The worker accepts an `images`- // array (it uses the first view); `body_type` rides along for parity with- // the shared worker request shape.+ // textured mesh from the reference views — user photos, or the synthesized+ // view for a text prompt. `body_type` rides along for parity with the+ // shared worker request shape.const photos = Array.isArray(params?.images) && params.images.length? params.images: [sourceUrl].filter(Boolean);+ const body = { images: photos, body_type: params?.bodyType || 'neutral' };+ // Per-tier sampler/export budgets (see SELFHOST_TRELLIS_QUALITY in+ // forge-tiers.js). The worker clamps every knob server-side and treats an+ // absent field as its own defaults, so this is pure opt-in quality.+ if (params?.quality && typeof params.quality === 'object') {+ body.quality = params.quality;+ }+ if (Number.isFinite(Number(params?.seed))) body.seed = Math.floor(Number(params.seed));return {path: '/infer',resultKey: 'result_gcs_url',- body: { images: photos, body_type: params?.bodyType || 'neutral' },+ body,};}diff --git a/api/forge.js b/api/forge.jsindex de6e20406..ae6e702e6 100644--- a/api/forge.js+++ b/api/forge.js@@ -75,6 +75,7 @@ import {preferFreeReconstruct,backendIsConfigured,buildCatalog,+ selfhostQualityForTier,} from './_lib/forge-tiers.js';import { laneHealthSnapshot, markLaneUnhealthy } from './_lib/forge-lane-health.js';import { resolveProviderKey } from './_lib/forge-provider-key.js';@@ -1591,7 +1592,14 @@ async function startJob(req, res) {job = await gcp.submit({mode: 'trellis',sourceUrl: referenceImageUrl,- params: { images: views, seed: opts.seed ?? undefined },+ params: {+ images: views,+ seed: opts.seed ?? undefined,+ // Tier-scaled sampler/export budgets — this is where standard/high+ // actually buy more quality on our own GPU (steps, kept geometry,+ // texture resolution) instead of only a bigger advertised polycount.+ quality: selfhostQualityForTier(tier.id),+ },});} catch (err) {if (err?.code === 'mode_unconfigured') {@@ -1832,7 +1840,11 @@ async function startJob(req, res) {job = await gcp.submit({mode: 'trellis',sourceUrl: referenceImageUrl,- params: { images: views, seed: opts.seed ?? undefined },+ params: {+ images: views,+ seed: opts.seed ?? undefined,+ quality: selfhostQualityForTier(tier.id),+ },});backendId = 'trellis_selfhost';provider = gcp;diff --git a/tests/api/forge-trellis-selfhost.test.js b/tests/api/forge-trellis-selfhost.test.jsindex f4aab3785..97d13d436 100644--- a/tests/api/forge-trellis-selfhost.test.js+++ b/tests/api/forge-trellis-selfhost.test.js@@ -98,8 +98,9 @@ describe('forge-tiers — self-hosted TRELLIS routing precedence', () => {// Text prompts at draft/standard still get NVIDIA's native single-hop lane.expect(resolveBackendId({ path: 'image', tier: 'draft', userImages: false })).toBe('nvidia');expect(resolveBackendId({ path: 'image', tier: 'standard', userImages: false })).toBe('nvidia');- // High tier keeps the higher-fidelity textured HuggingFace engine.- expect(resolveBackendId({ path: 'image', tier: 'high' })).toBe('huggingface');+ // High names our self-host Hunyuan3D engine; unconfigured here, so the+ // candidate walk falls to the self-host TRELLIS lane.+ expect(resolveBackendId({ path: 'image', tier: 'high' })).toBe('trellis_selfhost');});it('degrades cleanly to HuggingFace when the worker URL is absent', () => {@@ -187,3 +188,108 @@ describe('gcp provider — trellis mode wire contract', () => {);});});++// ── Tier-scaled quality budgets (SELFHOST_TRELLIS_QUALITY) ───────────────────+// Standard/high must buy real sampler/export budget on our own GPU, and the+// gcp provider must forward exactly that object to the worker's /infer body.+describe('forge-tiers — self-host TRELLIS per-tier quality budgets', () => {+ it('scales sampler steps, kept geometry, and texture size with the tier', async () => {+ const { SELFHOST_TRELLIS_QUALITY, selfhostQualityForTier } = await import(+ '../../api/_lib/forge-tiers.js'+ );+ const draft = selfhostQualityForTier('draft');+ const standard = selfhostQualityForTier('standard');+ const high = selfhostQualityForTier('high');++ expect(draft).toBe(SELFHOST_TRELLIS_QUALITY.draft);+ expect(standard.ss_steps).toBeGreaterThan(draft.ss_steps);+ expect(high.ss_steps).toBeGreaterThan(standard.ss_steps);+ expect(high.slat_steps).toBeGreaterThan(standard.slat_steps);+ // simplify is the fraction REMOVED — higher tiers keep more triangles.+ expect(standard.simplify).toBeLessThan(draft.simplify);+ expect(high.simplify).toBeLessThan(standard.simplify);+ expect(high.texture_size).toBeGreaterThanOrEqual(standard.texture_size);+ // Worker clamps: stay inside the envelope it accepts.+ for (const q of [draft, standard, high]) {+ expect(q.ss_steps).toBeLessThanOrEqual(50);+ expect(q.slat_steps).toBeLessThanOrEqual(50);+ expect(q.texture_size).toBeLessThanOrEqual(2048);+ }+ });++ it('falls back to the standard budget for an unknown tier id', async () => {+ const { SELFHOST_TRELLIS_QUALITY, selfhostQualityForTier } = await import(+ '../../api/_lib/forge-tiers.js'+ );+ expect(selfhostQualityForTier('nope')).toBe(SELFHOST_TRELLIS_QUALITY.standard);+ expect(selfhostQualityForTier(undefined)).toBe(SELFHOST_TRELLIS_QUALITY.standard);+ });++ it('names hunyuan3d for the high tier and keeps huggingface only as fallback', async () => {+ const { FREE_DEFAULT_FOR_TIERS, FREE_FALLBACK_FOR_PATH } = await import(+ '../../api/_lib/forge-tiers.js'+ );+ expect(FREE_DEFAULT_FOR_TIERS.high.image).toBe('hunyuan3d');+ expect(FREE_FALLBACK_FOR_PATH.image).toContain('huggingface');+ });+});++describe('gcp provider — trellis quality forwarding', () => {+ beforeEach(() => {+ process.env.MODEL_TRELLIS_URL = 'https://model-trellis.example.run.app';+ process.env.GCP_RECONSTRUCTION_KEY = 'test-worker-key';+ });++ it('forwards the quality object and seed verbatim in the /infer body', async () => {+ const calls = [];+ const origFetch = globalThis.fetch;+ globalThis.fetch = vi.fn(async (url, opts) => {+ calls.push({ url: String(url), body: JSON.parse(opts.body) });+ return new Response(JSON.stringify({ task_id: 'tsk_1', status: 'queued' }), {+ status: 202,+ headers: { 'content-type': 'application/json' },+ });+ });+ try {+ const { createRegenProvider: mk } = await import('../../api/_providers/gcp.js');+ const gcp = mk();+ const quality = { ss_steps: 45, slat_steps: 45, simplify: 0.85, texture_size: 2048 };+ await gcp.submit({+ mode: 'trellis',+ sourceUrl: 'https://cdn.three.ws/ref.png',+ params: { images: ['https://cdn.three.ws/ref.png'], seed: 7, quality },+ });+ expect(calls).toHaveLength(1);+ expect(calls[0].url).toContain('/infer');+ expect(calls[0].body.quality).toEqual(quality);+ expect(calls[0].body.seed).toBe(7);+ } finally {+ globalThis.fetch = origFetch;+ }+ });++ it('omits quality/seed entirely when the caller sends none (worker defaults apply)', async () => {+ const calls = [];+ const origFetch = globalThis.fetch;+ globalThis.fetch = vi.fn(async (url, opts) => {+ calls.push({ body: JSON.parse(opts.body) });+ return new Response(JSON.stringify({ task_id: 'tsk_2', status: 'queued' }), {+ status: 202,+ headers: { 'content-type': 'application/json' },+ });+ });+ try {+ const { createRegenProvider: mk } = await import('../../api/_providers/gcp.js');+ const gcp = mk();+ await gcp.submit({+ mode: 'trellis',+ sourceUrl: 'https://cdn.three.ws/ref.png',+ params: { images: ['https://cdn.three.ws/ref.png'] },+ });+ expect(calls[0].body).not.toHaveProperty('quality');+ expect(calls[0].body).not.toHaveProperty('seed');+ } finally {+ globalThis.fetch = origFetch;+ }+ });+});