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
refactor(3d): put the embed model-viewer pin in one module the CSP also reads
nirholas0ca0232c72ce
diff --git a/api/_lib/model-viewer-cdn.js b/api/_lib/model-viewer-cdn.jsnew file mode 100644index 000000000..38e9b64c3--- /dev/null+++ b/api/_lib/model-viewer-cdn.js@@ -0,0 +1,35 @@+// The single source of truth for the <model-viewer> build the server-rendered+// embed surfaces load.+//+// Two surfaces render a GLB from HTML this repo generates on the server:+// • api/ar.js (the /api/ar device-aware AR launch page)+// • api/_mcp-studio/component.js (the ChatGPT Apps SDK inline widget)+//+// Both import MODEL_VIEWER_SRC from here, so the pin moves in one place and the+// two surfaces can never drift apart. The CDN host is also what the widget's+// `openai/widgetCSP` resource_domains allowlist has to name, which is a second+// reason the URL must not be retyped per file.+//+// Why 3.5.0 and not the newest release: these two pages run inside someone+// else's frame (ChatGPT's sandboxed iframe, and a mobile in-app browser after a+// link tap). 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.++/** The pinned model-viewer version for the server-rendered embed surfaces. */+export const MODEL_VIEWER_VERSION = '3.5.0';++/** CDN origin the embed surfaces load model-viewer from (must be CSP-allowlisted). */+export const MODEL_VIEWER_CDN_ORIGIN = 'https://cdn.jsdelivr.net';++/** Full module URL for `<script type="module" src="...">` on the embed surfaces. */+export const MODEL_VIEWER_SRC = `${MODEL_VIEWER_CDN_ORIGIN}/npm/@google/model-viewer@${MODEL_VIEWER_VERSION}/dist/model-viewer.min.js`;diff --git a/api/_mcp-studio/component.js b/api/_mcp-studio/component.jsindex 1652a8c88..5f1c7d2c4 100644--- a/api/_mcp-studio/component.js+++ b/api/_mcp-studio/component.js@@ -15,9 +15,9 @@// No identifiers, no payment, no crypto — only what is needed to show the model.import { env } from '../_lib/env.js';+import { MODEL_VIEWER_SRC, MODEL_VIEWER_CDN_ORIGIN } from '../_lib/model-viewer-cdn.js';-const MODEL_VIEWER_CDN =- 'https://cdn.jsdelivr.net/npm/@google/[email protected]/dist/model-viewer.min.js';+const MODEL_VIEWER_CDN = MODEL_VIEWER_SRC;export const COMPONENT_HTML = `<!doctype html><html lang="en">@@ -346,7 +346,7 @@ export function componentCsp() {const domains = ['https://three.ws','https://*.three.ws',- 'https://cdn.jsdelivr.net',+ MODEL_VIEWER_CDN_ORIGIN,'https://replicate.delivery','https://*.replicate.delivery',];diff --git a/public/viewer.html b/public/viewer.htmlindex b129bc5ec..b0ca67ba5 100644--- a/public/viewer.html+++ b/public/viewer.html@@ -13,9 +13,12 @@<!-- 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.- The embeddable surfaces (ChatGPT widget api/_mcp-studio/component.js, AR launch- api/ar.js) intentionally pin 3.5.0 from jsdelivr instead, matching the other embed- bundles. Both are explicit version pins; the split is by surface, not accidental. -->+ 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,+ and the reasoning for each lives in that module. --><scripttype="module"src="https://ajax.googleapis.com/ajax/libs/model-viewer/4.0.0/model-viewer.min.js"