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(view-switcher): shared segmented control across 3D / chat / AR / embed surfaces
nirholasa4f5aa0264eb
diff --git a/pages/agent-detail.html b/pages/agent-detail.htmlindex 9c16c2f1c..6c979a01d 100644--- a/pages/agent-detail.html+++ b/pages/agent-detail.html@@ -135,7 +135,10 @@</div></div>- <a class="ad-back" href="/agents">← Back to Registry</a>+ <div class="ad-back-row">+ <a class="ad-back" href="/agents">← Back to Registry</a>+ <div id="view-switch-slot"></div>+ </div><section class="ad-hero"><img class="ad-hero-avatar" id="ad-avatar" alt="" />diff --git a/pages/ar.html b/pages/ar.htmlindex 3e887fa64..821f8c481 100644--- a/pages/ar.html+++ b/pages/ar.html@@ -304,7 +304,7 @@<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="15 18 9 12 15 6"/></svg>Back</a>- <div class="ar-topbar-center">+ <div class="ar-topbar-center" id="view-switch-slot"><span class="ar-badge"><span class="ar-badge-dot"></span>AR Readydiff --git a/pages/avatar-page.html b/pages/avatar-page.htmlindex 2bcce31cb..0dabc7507 100644--- a/pages/avatar-page.html+++ b/pages/avatar-page.html@@ -86,6 +86,16 @@font-size: 13px;}.av-back:hover { color: var(--text); }+ .av-actionbar-center {+ flex: 1 1 auto;+ display: flex;+ justify-content: center;+ min-width: 0;+ }+ .av-actionbar-center:empty { display: none; }+ @media (max-width: 600px) {+ .av-actionbar-center { order: 3; flex-basis: 100%; margin-top: 10px; }+ }.av-share-group {display: inline-flex;gap: 6px;@@ -1088,7 +1098,7 @@.av-stage { min-height: 420px; }}@media (max-width: 600px) {- .av-actionbar { padding: 10px 14px; }+ .av-actionbar { padding: 10px 14px; flex-wrap: wrap; }.av-side-head, .av-cta-row { padding-left: 16px; padding-right: 16px; }.av-panel { padding: 16px; }.av-related { padding: 16px; }@@ -1102,6 +1112,7 @@<header class="av-actionbar"><a class="av-back" href="/marketplace">← Marketplace</a>+ <div class="av-actionbar-center" id="view-switch-slot"></div><div class="av-share-group"><button class="av-share-btn" id="share-link">Copy link</button><a class="av-share-btn" id="share-twitter" target="_blank" rel="noopener">Share on X</a>diff --git a/src/agent-detail.css b/src/agent-detail.cssindex f96be9ac7..f3a752ee1 100644--- a/src/agent-detail.css+++ b/src/agent-detail.css@@ -155,6 +155,14 @@ a {border-color: #fff;}+.ad-back-row {+ display: flex;+ align-items: center;+ justify-content: space-between;+ gap: 12px;+ flex-wrap: wrap;+ margin-right: 24px;+}.ad-back {display: inline-block;margin: 22px 24px 8px;diff --git a/src/agent-detail.js b/src/agent-detail.jsindex 6054d46d6..e187faff1 100644--- a/src/agent-detail.js+++ b/src/agent-detail.js@@ -33,6 +33,7 @@ import { Modal } from './shared/modal.js';import { showSharePanel } from './shared/share.js';import { enrichAgentDetail } from './agent-detail-market.js';import { log } from './shared/log.js';+import { mountViewSwitcher } from './view-switcher.js';const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;@@ -294,6 +295,15 @@ function render(agent) {const see3d = $('ad-see-3d');if (see3d) see3d.href = seeInWorldHref(agent);+ // View switcher: flip this agent between its detail, 3D world, and embed+ // presentations. Every agent has a 3D body (custom GLB or mannequin).+ mountViewSwitcher($('view-switch-slot'), {+ kind: 'agent',+ id: agent.id,+ active: 'detail',+ worldHref: seeInWorldHref(agent),+ });+const status = $('ad-status');status.textContent = agent.active ? 'Active' : 'Inactive';status.classList.toggle('ad-status-inactive', !agent.active);diff --git a/src/ar-page.js b/src/ar-page.jsindex 99b7dfffc..fbdeb92b9 100644--- a/src/ar-page.js+++ b/src/ar-page.js@@ -9,6 +9,7 @@import { glbBlobToUsdzBlob } from './usdz-pipeline.js';import { log } from './shared/log.js';+import { mountViewSwitcher } from './view-switcher.js';const segments = location.pathname.split('/').filter(Boolean);// /avatars/:id/ar → segments = ['avatars', 'uuid', 'ar']@@ -73,7 +74,9 @@ function renderPage(avatar, glbUrl) {viewer.setAttribute('ios-src', avatar.usdz_url);}- $('ar-back-link').href = `/agents/${encodeURIComponent(avatar.id || avatarId)}`;+ const id = avatar.id || avatarId;+ $('ar-back-link').href = `/avatars/${encodeURIComponent(id)}`;+ mountViewSwitcher($('view-switch-slot'), { kind: 'avatar', id, active: 'ar' });$('ar-share-btn').addEventListener('click', () => shareAvatar(avatar));}diff --git a/src/avatar-page.js b/src/avatar-page.jsindex 351896b31..0337a8b03 100644--- a/src/avatar-page.js+++ b/src/avatar-page.js@@ -12,6 +12,7 @@ import { downloadAvatar } from './avatar-export.js';import { fbxFromUrl } from './remesh-convert.js';import { log } from './shared/log.js';import { emptyStateHTML } from './shared/state-kit.js';+import { mountViewSwitcher } from './view-switcher.js';const ATTACHED_KEY_PREFIX = 'avatar_attached_v1:';@@ -99,6 +100,7 @@ async function init() {updateOg();renderShell(glbUrl);+ mountSwitcher();bindShareButtons();bindTabs();bindChat();@@ -567,20 +569,39 @@ function renderEmbedPanel(glbUrl) {`;}+// ── View switcher ─────────────────────────────────────────────────────++// Surface the page-level views (3D · Chat · AR · Embed) in the action bar.+// "Chat" is the active view when the page is opened on ?view=chat.+function mountSwitcher() {+ if (isEmbed) return;+ const active = new URLSearchParams(location.search).get('view') === 'chat' ? 'chat' : '3d';+ mountViewSwitcher($('view-switch-slot'), { kind: 'avatar', id: avatar.id || avatarId, active });+}+// ── Tabs ──────────────────────────────────────────────────────────────+function activateTab(tab) {+ const btn = document.querySelector(`.av-tab[data-tab="${tab}"]`);+ if (!btn) return false;+ document.querySelectorAll('.av-tab').forEach((b) => b.classList.remove('active'));+ btn.classList.add('active');+ document.querySelectorAll('.av-panel').forEach((p) => {+ p.classList.toggle('active', p.dataset.panel === tab);+ });+ return true;+}+function bindTabs() {document.querySelectorAll('.av-tab').forEach((btn) => {- btn.addEventListener('click', () => {- document.querySelectorAll('.av-tab').forEach((b) => b.classList.remove('active'));- btn.classList.add('active');- const tab = btn.dataset.tab;- document.querySelectorAll('.av-panel').forEach((p) => {- p.classList.toggle('active', p.dataset.panel === tab);- });- });+ btn.addEventListener('click', () => activateTab(btn.dataset.tab));});+ // Deep-link a tab from the view switcher: /avatars/:id?view=chat focuses the+ // Chat panel on load so each switcher view lands on a real, shareable URL.+ const view = new URLSearchParams(location.search).get('view');+ if (view && view !== 'overview') activateTab(view);+// Embed copy buttonsdocument.body.addEventListener('click', async (e) => {const btn = e.target.closest('.av-embed-copy');@@ -727,7 +748,10 @@ async function openLaunchPumpFun() {try {const user = await fetchCurrentUser();const { inner } = openPumpModal('Launch on Pump.fun');- const { mountLaunchPanel } = await import(/* @vite-ignore */ '/studio/launch-panel.js');+ // Path held in a variable so Vite's import-analysis treats this as a+ // runtime-only dynamic import and doesn't try to bundle a /public asset.+ const launchPanelUrl = '/studio/launch-panel.js';+ const { mountLaunchPanel } = await import(/* @vite-ignore */ launchPanelUrl);mountLaunchPanel(inner, {getAvatar: () => ({ ...avatar, id: avatar.id || avatarId }),getUser: () => user,@@ -757,7 +781,8 @@ async function openFeesPanel() {if (!avatarCoin?.mint) { alert('No coin launched for this avatar yet — launch one first.'); return; }const user = await fetchCurrentUser();const { inner } = openPumpModal('Fees & rewards');- const { mountFeesPanel } = await import(/* @vite-ignore */ '/studio/fees-panel.js');+ const feesPanelUrl = '/studio/fees-panel.js';+ const { mountFeesPanel } = await import(/* @vite-ignore */ feesPanelUrl);mountFeesPanel(inner, {mint: avatarCoin.mint,network: avatarCoin.network || 'mainnet',diff --git a/src/view-switcher.js b/src/view-switcher.jsnew file mode 100644index 000000000..f94525c6f--- /dev/null+++ b/src/view-switcher.js@@ -0,0 +1,127 @@+/**+ * Shared "view switcher" — a navigate-based segmented control that lets a user+ * flip a single agent/avatar between its available presentation surfaces:+ * the 3D detail page, live chat, AR, and the embeddable widget.+ *+ * Navigate-based by design: each view is its own shareable URL. The active+ * view renders as a non-interactive current item (aria-current="page"); every+ * other view is a plain anchor, so the control works without JS and degrades+ * gracefully if a controller fails to boot. Capability flags hide views that+ * don't apply to a given entity (e.g. agents without a 3D body get no AR).+ *+ * Usage:+ * import { mountViewSwitcher } from './view-switcher.js';+ * mountViewSwitcher(document.getElementById('view-switch-slot'), {+ * kind: 'avatar', id: avatarId, active: '3d',+ * });+ */++const ICONS = {+ '3d': '<path d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"/><polyline points="3.27 6.96 12 12.01 20.73 6.96"/><line x1="12" y1="22.08" x2="12" y2="12"/>',+ chat: '<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/>',+ ar: '<path d="M12 2 2 7l10 5 10-5-10-5z"/><path d="M2 17l10 5 10-5"/><path d="M2 12l10 5 10-5"/>',+ embed: '<polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/>',+ detail: '<line x1="8" y1="6" x2="21" y2="6"/><line x1="8" y1="12" x2="21" y2="12"/><line x1="8" y1="18" x2="21" y2="18"/><circle cx="3.5" cy="6" r="0.8"/><circle cx="3.5" cy="12" r="0.8"/><circle cx="3.5" cy="18" r="0.8"/>',+};++function icon(key) {+ return `<svg class="view-switch-ico" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${ICONS[key] || ''}</svg>`;+}++// Views for a standalone avatar (the 3D body). Avatars always have a GLB, so+// every surface applies.+function avatarViews(id) {+ const e = encodeURIComponent(id);+ return [+ { key: '3d', label: '3D', href: `/avatars/${e}`, title: '3D body & details' },+ { key: 'chat', label: 'Chat', href: `/avatars/${e}?view=chat`, title: 'Talk to this avatar' },+ { key: 'ar', label: 'AR', href: `/avatars/${e}/ar`, title: 'View in your space (AR)' },+ { key: 'embed', label: 'Embed', href: `/studio?avatar=${e}`, title: 'Build an embeddable widget' },+ ];+}++// Views for an agent. The 3D world view is only offered when the agent has a+// real body to render there; chat lives behind the fork flow, so it is not a+// standalone URL and is intentionally omitted.+function agentViews(id, { worldHref } = {}) {+ const e = encodeURIComponent(id);+ const views = [{ key: 'detail', label: 'Detail', href: `/agents/${e}`, title: 'Agent profile & details' }];+ if (worldHref) views.push({ key: '3d', label: '3D', href: worldHref, title: 'See this agent in 3D' });+ views.push({ key: 'embed', label: 'Embed', href: `/agent/${e}/embed`, title: 'Embeddable agent widget' });+ return views;+}++function injectStyles() {+ if (document.getElementById('view-switch-css')) return;+ const style = document.createElement('style');+ style.id = 'view-switch-css';+ style.textContent = `+ .view-switch {+ display: inline-flex;+ align-items: center;+ gap: 2px;+ padding: 3px;+ border-radius: 999px;+ background: rgba(255, 255, 255, 0.05);+ border: 1px solid rgba(255, 255, 255, 0.1);+ backdrop-filter: blur(8px);+ }+ .view-switch-item {+ display: inline-flex;+ align-items: center;+ gap: 6px;+ padding: 7px 14px;+ border-radius: 999px;+ font: 600 13px/1 Inter, system-ui, sans-serif;+ color: rgba(255, 255, 255, 0.62);+ text-decoration: none;+ white-space: nowrap;+ cursor: pointer;+ transition: color 0.15s ease, background 0.15s ease;+ -webkit-tap-highlight-color: transparent;+ }+ .view-switch-item .view-switch-ico { opacity: 0.85; }+ a.view-switch-item:hover { color: #fff; background: rgba(255, 255, 255, 0.08); }+ a.view-switch-item:focus-visible {+ outline: 2px solid rgba(255, 255, 255, 0.7);+ outline-offset: 2px;+ }+ .view-switch-item.is-active {+ color: #0a0a0a;+ background: #fff;+ cursor: default;+ }+ .view-switch-item.is-active .view-switch-ico { opacity: 1; }+ @media (max-width: 640px) {+ .view-switch-item span { display: none; }+ .view-switch-item { padding: 8px; }+ .view-switch-item.is-active span { display: inline; }+ }+ `;+ document.head.appendChild(style);+}++/**+ * Mount the switcher into `slot`. Returns the created <nav>, or null if no slot.+ * @param {Element|null} slot+ * @param {{ kind: 'avatar'|'agent', id: string, active: string, worldHref?: string }} opts+ */+export function mountViewSwitcher(slot, opts) {+ if (!slot || !opts?.id) return null;+ injectStyles();+ const views = opts.kind === 'agent' ? agentViews(opts.id, opts) : avatarViews(opts.id);+ const nav = document.createElement('nav');+ nav.className = 'view-switch';+ nav.setAttribute('aria-label', 'Switch view');+ nav.innerHTML = views+ .map((v) => {+ const inner = `${icon(v.key)}<span>${v.label}</span>`;+ if (v.key === opts.active) {+ return `<span class="view-switch-item is-active" aria-current="page" title="${v.title}">${inner}</span>`;+ }+ return `<a class="view-switch-item" href="${v.href}" title="${v.title}">${inner}</a>`;+ })+ .join('');+ slot.replaceChildren(nav);+ return nav;+}diff --git a/vercel.json b/vercel.jsonindex 98eec2f70..576dbfe2c 100644--- a/vercel.json+++ b/vercel.json@@ -1239,7 +1239,7 @@"src": "/marketplace/avatars/([^/]+)","status": 301,"headers": {- "Location": "/agents/$1"+ "Location": "/avatars/$1"}},{diff --git a/vite.config.js b/vite.config.jsindex 1bd91d545..fbd6a9919 100644--- a/vite.config.js+++ b/vite.config.js@@ -944,6 +944,9 @@ const appConfig = {// /embed/avatar/:handle → portable avatar embed by handleelse if (!filePath && /^\/embed\/avatar(\/[a-z0-9_-]{3,30})?\/?$/i.test(path))filePath = resolve(root, 'pages/avatar-embed.html');+ // /avatars/:id/ar → dedicated AR experience (mirrors vercel.json rewrite)+ else if (!filePath && /^\/avatars\/[^/.]+\/ar\/?$/.test(path))+ filePath = resolve(root, 'pages/ar.html');// /avatars/:id/edit → avatar customize page (mirrors vercel.json rewrite)else if (!filePath && /^\/avatars\/[^/.]+\/edit\/?$/.test(path))filePath = resolve(root, 'pages/avatar-edit.html');