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(model-page): tighten the detail layout and keep the viewer CDN pin in one place

nirholas12bff61b558d
diff --git a/api/_lib/model-viewer-cdn.js b/api/_lib/model-viewer-cdn.js
index 4304824c5..62243a2e0 100644
--- a/api/_lib/model-viewer-cdn.js
+++ b/api/_lib/model-viewer-cdn.js
@@ -23,6 +23,20 @@
// custom-element collision to avoid, and can afford the stricter integrity check
// that a template-interpolated embed cannot carry as cheaply. That split is by
// surface and is intentional; see the comment at the top of public/viewer.html.
+//
+// So `grep -rn "model-viewer@"` maps to exactly three intentional pins, one per
+// surface class, and nothing else should introduce a fourth:
+// 1. THIS module, 3.5.0 via jsdelivr: every server-rendered embed that runs
+// inside a host page's frame (the ChatGPT widget), plus the static embed
+// bundles that ship the same build (public/agenc/embed.js,
+// public/ar-forge.html, public/spatial-mcp/, pages/daily.html).
+// 2. public/viewer.html, 4.0.0 with SRI from Google's CDN: the one
+// standalone, top-level viewer document.
+// 3. src/shared/model-viewer-loader.js, 4.0.0 across three CDNs: the
+// Vite-bundled first-party pages (/forge and the pickers), where a blocked
+// CDN must fall through to the next host instead of leaving an inert box.
+// 2 and 3 are the same 4.0.0 build on first-party pages; only the delivery
+// differs (one document can carry an SRI hash, a runtime chain cannot).
/** The pinned model-viewer version for the server-rendered embed surfaces. */
export const MODEL_VIEWER_VERSION = '3.5.0';
diff --git a/public/viewer.html b/public/viewer.html
index 5f203018f..57234b3f9 100644
--- a/public/viewer.html
+++ b/public/viewer.html
@@ -14,10 +14,12 @@
<script src="/model-viewer-meshopt.js"></script>
<!-- This standalone browser viewer pins model-viewer 4.0.0 with SRI from Google's CDN.
It is a first-party top-level page that owns its whole document, so it can take the
- newer build and afford the integrity check. The server-rendered EMBED surfaces
- (ChatGPT widget api/_mcp-studio/component.js, AR launch api/ar.js) run inside someone
- else's frame and share a single pin in api/_lib/model-viewer-cdn.js, which is also the
- origin the widget's CSP allowlists. Both are explicit pins; the split is by surface,
+ newer build and afford the integrity check. The server-rendered EMBED surface
+ (the ChatGPT widget in api/_mcp-studio/component.js) runs inside someone else's frame
+ and takes its pin from api/_lib/model-viewer-cdn.js, which is also the origin that
+ widget's CSP allowlists. /api/ar no longer inlines a model-viewer at all: it 302s to
+ /ar/view, a bundled page, because Quick Look needs a generated USDZ a server-rendered
+ HTML string cannot produce. Both remaining pins are explicit; the split is by surface,
and the reasoning for each lives in that module. -->
<script
type="module"
diff --git a/src/model-page.js b/src/model-page.js
index 155efae27..8a2588ca3 100644
--- a/src/model-page.js
+++ b/src/model-page.js
@@ -36,6 +36,7 @@ const state = {
comments: [],
commentsTotal: 0,
commentsNext: null,
+ edition: null, // { limit, issued, remaining, soldOut } from /api/print/editions
};
function esc(s) {
@@ -113,6 +114,7 @@ async function boot() {
renderSuggested();
loadGeometry();
loadComments();
+ loadEdition();
if (shell) shell.setAttribute('aria-busy', 'false');
}
@@ -236,10 +238,120 @@ function renderInfo() {
<p class="mp-desc">${esc(c.prompt)}</p>
<div class="mp-published" title="${esc(publishedAbs)}">🕒 Published ${esc(timeAgo(c.created_at))}</div>
${chips ? `<div class="mp-chips">${chips}</div>` : ''}
- <div class="mp-liked-line" id="mp-liked-line">${likeCount ? `${formatCount(likeCount)} ${likeCount === 1 ? 'person likes' : 'people like'} this model` : ''}</div>`;
+ <div class="mp-liked-line" id="mp-liked-line">${likeCount ? `${formatCount(likeCount)} ${likeCount === 1 ? 'person likes' : 'people like'} this model` : ''}</div>
+ <section class="mp-edition" id="mp-edition" hidden aria-label="Physical editions"></section>`;
wireActions();
wireFollow();
+ renderEdition();
+}
+
+// ── physical editions ────────────────────────────────────────────────────────
+//
+// Materialize turns a model into an object, and an object is a collectible only
+// if its supply is knowable. The creator sets one number here; every print of
+// this model then claims the next edition out of it, and each shipped print's
+// certificate (/cert/:id) renders "3 of 25" forever.
+//
+// The block stays hidden for the common case: an open edition nobody has
+// printed yet, viewed by someone who cannot change it. It appears the moment
+// there is something true to say.
+
+function viewerIsCreator() {
+ const c = state.creation;
+ return Boolean(state.viewer?.username && c?.creatorUsername && state.viewer.username === c.creatorUsername);
+}
+
+async function loadEdition() {
+ const c = state.creation;
+ if (!c) return;
+ try {
+ const res = await fetch(`/api/print/editions?creation_id=${encodeURIComponent(c.id)}`);
+ if (!res.ok) return;
+ const body = await res.json();
+ if (!body?.edition) return;
+ state.edition = body.edition;
+ renderEdition();
+ } catch (err) {
+ // A model page is not worth breaking over a scarcity badge.
+ log.error('edition load failed', err);
+ }
+}
+
+function editionSummary(e) {
+ if (!e) return '';
+ if (e.limit === null) {
+ return e.issued
+ ? `Open edition · ${formatCount(e.issued)} printed`
+ : 'Open edition · none printed yet';
+ }
+ if (e.soldOut) return `Limited edition of ${formatCount(e.limit)} · sold out`;
+ return `Limited edition of ${formatCount(e.limit)} · ${formatCount(e.issued)} printed, ${formatCount(e.remaining)} left`;
+}
+
+function renderEdition() {
+ const host = $('mp-edition');
+ const e = state.edition;
+ if (!host) return;
+ const owner = viewerIsCreator();
+ if (!e || (!owner && e.limit === null && !e.issued)) {
+ host.hidden = true;
+ return;
+ }
+ host.hidden = false;
+ host.innerHTML = `
+ <h2 class="mp-edition-title">Physical editions</h2>
+ <p class="mp-edition-line" id="mp-edition-line">${esc(editionSummary(e))}</p>
+ ${
+ owner
+ ? `<form class="mp-edition-form" id="mp-edition-form">
+ <label class="mp-edition-label" for="mp-edition-input">Cap this edition</label>
+ <input class="mp-edition-input" id="mp-edition-input" type="number" inputmode="numeric"
+ min="${e.issued > 0 ? e.issued : 1}" max="10000" step="1"
+ placeholder="Open" value="${e.limit === null ? '' : esc(String(e.limit))}"
+ aria-describedby="mp-edition-help" />
+ <button class="mp-action" type="submit" id="mp-edition-save">Save</button>
+ <p class="mp-edition-help" id="mp-edition-help">
+ Leave it empty for an open edition. Once set, orders past the cap are refused at
+ the price, and every certificate reads "n of ${e.limit === null ? 'N' : esc(String(e.limit))}".
+ </p>
+ </form>`
+ : '<p class="mp-edition-help">Set by the creator. Every print carries a numbered certificate of authenticity.</p>'
+ }`;
+ if (owner) wireEditionForm();
+}
+
+function wireEditionForm() {
+ const form = $('mp-edition-form');
+ form?.addEventListener('submit', async (event) => {
+ event.preventDefault();
+ const input = $('mp-edition-input');
+ const save = $('mp-edition-save');
+ const raw = String(input?.value ?? '').trim();
+ if (save) {
+ save.disabled = true;
+ save.textContent = 'Saving…';
+ }
+ try {
+ const res = await apiFetch('/api/print/editions', {
+ method: 'POST',
+ headers: { 'content-type': 'application/json', 'x-forge-client': clientId() },
+ body: JSON.stringify({ creation_id: state.creation.id, edition_of: raw === '' ? null : Number(raw) }),
+ });
+ const body = await res.json().catch(() => null);
+ if (!res.ok || !body?.edition) throw new Error(body?.error || `HTTP ${res.status}`);
+ state.edition = body.edition;
+ renderEdition();
+ toast(body.edition.limit === null ? 'This model is an open edition' : `Capped at ${body.edition.limit} prints`);
+ } catch (err) {
+ log.error('edition save failed', err);
+ toast(String(err?.message || 'Could not save the edition size'));
+ if (save) {
+ save.disabled = false;
+ save.textContent = 'Save';
+ }
+ }
+ });
}
function wireActions() {
diff --git a/src/model.css b/src/model.css
index f6c7e95e3..f941b05bb 100644
--- a/src/model.css
+++ b/src/model.css
@@ -465,3 +465,70 @@ a.mp-comment-author:hover { text-decoration: underline; }
.mp-skeleton { animation: none; }
.mp-action, .mp-sugg-card, .mp-viewer-btn { transition: none; }
}
+
+/* ── physical editions ───────────────────────────────────────────────────────
+ Materialize scarcity on the model page: what the series is, how much of it
+ is gone, and, for the creator, the one field that caps it. Hidden entirely
+ for an open edition nobody has printed, so 23k models do not each grow a
+ "0 printed" row. */
+
+.mp-edition {
+ margin-top: var(--space-lg, 24px);
+ padding: var(--space-md, 16px);
+ border: 1px solid var(--stroke, rgba(255, 255, 255, 0.08));
+ border-radius: var(--radius-lg, 16px);
+ background: var(--surface-1, rgba(255, 255, 255, 0.03));
+}
+
+.mp-edition-title {
+ margin: 0 0 var(--space-2, 8px);
+ font-family: var(--font-mono);
+ font-size: var(--text-2xs, 11px);
+ letter-spacing: 0.12em;
+ text-transform: uppercase;
+ font-weight: var(--weight-medium, 500);
+ color: var(--ink-dim, rgba(255, 255, 255, 0.55));
+}
+
+.mp-edition-line {
+ margin: 0;
+ font-size: var(--text-md, 15px);
+ color: var(--ink, rgba(255, 255, 255, 0.88));
+}
+
+.mp-edition-form {
+ display: flex;
+ flex-wrap: wrap;
+ align-items: center;
+ gap: var(--space-2, 8px);
+ margin-top: var(--space-sm, 12px);
+}
+
+.mp-edition-label {
+ font-size: var(--text-sm, 13px);
+ color: var(--ink-dim, rgba(255, 255, 255, 0.62));
+}
+
+.mp-edition-input {
+ width: 110px;
+ padding: 8px 12px;
+ border-radius: var(--radius-pill, 999px);
+ border: 1px solid var(--stroke, rgba(255, 255, 255, 0.14));
+ background: var(--surface-2, rgba(255, 255, 255, 0.05));
+ color: var(--ink-bright, #fff);
+ font: inherit;
+ font-family: var(--font-mono);
+ font-size: var(--text-sm, 13px);
+}
+.mp-edition-input:focus-visible {
+ outline: 2px solid var(--accent, #7c9cff);
+ outline-offset: 1px;
+}
+
+.mp-edition-help {
+ flex: 1 1 100%;
+ margin: 0;
+ font-size: var(--text-xs, 12px);
+ line-height: 1.6;
+ color: var(--ink-dim, rgba(255, 255, 255, 0.5));
+}