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.

deps(model-viewer): unify every surface on 4.0.0 so no document defines the element twice

nirholas3ae99babb844
diff --git a/api/_lib/model-viewer-cdn.js b/api/_lib/model-viewer-cdn.js
index 62243a2e0..50d93c4a4 100644
--- a/api/_lib/model-viewer-cdn.js
+++ b/api/_lib/model-viewer-cdn.js
@@ -10,36 +10,32 @@
// can offer AR modes but can never generate the ios-src USDZ Quick Look
// actually needs.)
//
-// Why 3.5.0 and not the newest release: the widget runs inside someone else's
-// frame (ChatGPT's sandboxed iframe). 3.5.0 is the build the rest of the
-// platform's embeddable bundles ship (public/agenc/embed.js,
-// public/ar-forge.html, public/spatial-mcp/), so an embedding page that already
-// loaded model-viewer for one three.ws embed reuses the exact same module
-// instead of registering a second, conflicting <model-viewer> custom element.
-//
-// The standalone browser viewer (public/viewer.html) is deliberately NOT on this
-// pin. It is a first-party top-level page, not an embed, so it takes 4.0.0 with
-// an SRI hash from Google's own CDN: it owns its whole document, has no
-// 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
+// Why every surface is on ONE version: an embed and a first-party page can end
+// up in the same document, and the second `customElements.define('model-viewer',
+// ...)` in a document throws. Two three.ws surfaces on two different builds is
+// therefore a live collision hazard, so the platform pins a single build
+// everywhere and the pins differ only in DELIVERY, never in version:
+// 1. THIS module, jsdelivr, no SRI: 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
+// public/ar-forge.html, public/spatial-mcp/, pages/daily.html). A
+// template-interpolated embed cannot carry an integrity hash as cheaply as
+// a hand-authored document can, which is the only reason this rung has none.
+// 2. public/viewer.html and the static first-party pages, Google's CDN with
+// an SRI hash: top-level documents that own their whole page and can
+// afford the stricter integrity check.
+// 3. src/shared/model-viewer-loader.js, three CDNs in a failover chain: 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).
+// A runtime chain cannot carry one SRI hash, so it carries none.
+//
+// scripts/check-model-viewer-version.mjs holds that invariant: it fails if any
+// reference in the tree names a different version from the rest, if one version
+// is served with two different integrity hashes, or if the vendored copy under
+// pages/ibm/vendor/ stops matching the pinned build.
-/** The pinned model-viewer version for the server-rendered embed surfaces. */
-export const MODEL_VIEWER_VERSION = '3.5.0';
+/** The pinned model-viewer version. One build platform-wide; see above. */
+export const MODEL_VIEWER_VERSION = '4.0.0';
/** CDN origin the embed surfaces load model-viewer from (must be CSP-allowlisted). */
export const MODEL_VIEWER_CDN_ORIGIN = 'https://cdn.jsdelivr.net';
diff --git a/docs/mcp-studio.md b/docs/mcp-studio.md
index dd0cf50ba..6103d3ac8 100644
--- a/docs/mcp-studio.md
+++ b/docs/mcp-studio.md
@@ -354,15 +354,16 @@ any surface that rides it. The agent-facing REST endpoints (`/api/3d/generate`,
The inline widget loads Google's `<model-viewer>` from one pinned URL in
[`api/_lib/model-viewer-cdn.js`](../api/_lib/model-viewer-cdn.js), which is also
the origin the widget's `openai/widgetCSP` allowlists, so the script tag and its
-CSP entry cannot drift apart. That module pins 3.5.0 for every server-rendered
-embed, the build the rest of the platform's embeddable bundles ship, so a host
-page that already loaded one three.ws embed reuses the same module instead of
-registering a second, conflicting custom element. The standalone
-[`/viewer`](../public/viewer.html) page and the Vite-bundled first-party pages
-deliberately sit on 4.0.0 instead: they own their whole document and have no
-custom-element collision to avoid. The header comment in
-`api/_lib/model-viewer-cdn.js` names all three pins and why each surface takes
-the build it takes. The `/api/ar` launcher no longer inlines a
+CSP entry cannot drift apart. That module pins the one build every three.ws
+surface loads, so a host page that already has a three.ws embed reuses the same
+module instead of registering a second, conflicting custom element. The
+standalone [`/viewer`](../public/viewer.html) page and the Vite-bundled
+first-party pages ship the same version and differ only in how they fetch it:
+a top-level document can carry an SRI hash, a template-interpolated embed and a
+runtime CDN failover chain cannot. The header comment in
+`api/_lib/model-viewer-cdn.js` names all three delivery rungs, and
+`npm run check:model-viewer` fails the build if one of them drifts off the
+shared version. The `/api/ar` launcher no longer inlines a
`<model-viewer>` of its own: Android gets a Scene Viewer intent, and every other
device (and every live avatar) is sent on to `/ar/view`, a Vite-bundled page
that generates a real USDZ from the GLB on the device so iPhone gets genuine
diff --git a/docs/spatial-mcp.md b/docs/spatial-mcp.md
index 06c200e81..0653c7251 100644
--- a/docs/spatial-mcp.md
+++ b/docs/spatial-mcp.md
@@ -83,7 +83,7 @@ The live demo at [`/spatial-mcp`](https://three.ws/spatial-mcp) renders exactly
The reference renderer is framework-free and reusable independent of three.ws:
```html
-<script type="module" src="https://cdn.jsdelivr.net/npm/@google/[email protected]/dist/model-viewer.min.js"></script>
+<script type="module" src="https://cdn.jsdelivr.net/npm/@google/[email protected]/dist/model-viewer.min.js"></script>
<div id="mount" style="height:360px"></div>
<script type="module">
import { renderSpatialArtifact } from 'https://three.ws/spatial-mcp/spatial-renderer.js';
diff --git a/infra/lambda/forge/page.mjs b/infra/lambda/forge/page.mjs
index a122c1d70..b58b1f491 100644
--- a/infra/lambda/forge/page.mjs
+++ b/infra/lambda/forge/page.mjs
@@ -41,7 +41,7 @@ export function buildPage({ seed, traits, origin }) {
<meta name="twitter:description" content="${esc(desc)}" />
<meta name="twitter:image" content="${esc(ogUrl)}" />
<link rel="canonical" href="${esc(pageUrl)}" />
-<script type="module" src="https://cdn.jsdelivr.net/npm/@google/[email protected]/dist/model-viewer.min.js"></script>
+<script type="module" src="https://cdn.jsdelivr.net/npm/@google/[email protected]/dist/model-viewer.min.js"></script>
<style>
:root { --bg:#05060a; --panel:#0c0e16; --panel-2:#10131e; --line:#1d2231; --line-2:#2a3146;
--text:#eaeef7; --muted:#868da1; --accent:#7c5cff; --accent-2:#19d6a8; --radius:16px;
diff --git a/public/viewer.html b/public/viewer.html
index 354ce4fb3..1c5ebb995 100644
--- a/public/viewer.html
+++ b/public/viewer.html
@@ -12,15 +12,17 @@
<meta property="og:type" content="website" />
<!-- Meshopt decoder must register before <model-viewer> starts loading (Forge GLBs are meshopt-compressed). Classic script → runs during parse, before the model-viewer module. -->
<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 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. -->
+<!-- This standalone browser viewer loads model-viewer 4.0.0 with SRI from Google's CDN.
+ Every three.ws surface is on that one build, because two builds in one document make
+ the second customElements.define('model-viewer') throw. What differs per surface is
+ DELIVERY, not version: a top-level document like this one owns its whole page and can
+ afford the integrity check, while the server-rendered EMBED surface (the ChatGPT
+ widget in api/_mcp-studio/component.js) runs inside someone else's frame and takes
+ its URL 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. That module names every delivery rung; scripts/check-model-viewer-version.mjs
+ fails the build if any of them drifts off the shared version. -->
<script
type="module"
src="https://ajax.googleapis.com/ajax/libs/model-viewer/4.0.0/model-viewer.min.js"