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(studio): render agents and avatars from one canonical studio page
nirholas173c4ef063f7
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex ff9e3a0d3..de950ca5a 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -6,6 +6,8 @@ Public history for [three.ws](https://three.ws), newest first. New pages come fr## 2026-08-18+- **Agents and avatars now open in the same studio page**: Clicking an agent used to land you on a long scrolling profile, while clicking an avatar opened the 3D studio. They are now the same page. Every agent link on three.ws (the search bar, the agents directory, the gallery, the marketplace, the galaxy, launches and creator profiles) opens the studio layout: the agent standing in a live 3D stage on the left, its identity, wallet and actions on the right, and tabs for chat, poses, skills, plugins and embed codes. Talking to an agent there uses that agent's own brain and memory, and AR now works from an agent page too. An agent that has no 3D body yet gets a proper page instead of an empty viewer, with both ways to give it one. The full agent profile (capabilities, economy, activity, trust and developer tools) is one click away on the Profile button, and every entity now has a single canonical link that is safe to share. (`/agents`) `[improvement, feature]`+- **Avatar and agent pages load in Safari again**: Every avatar and agent page failed to load in Safari, on both iPhone and Mac, showing "Avatar not found" with the message "Cannot access uninitialized variable." instead of the 3D stage. Chrome, Edge, and Firefox were unaffected, which is why the pages looked fine on most desktops while iPhone visitors saw a dead page. Safari checks a variable is ready at a slightly earlier moment than other browsers do, and the page set up its data one step before that check was satisfied. The page now finishes declaring its state before it starts loading, so it renders identically in every browser. `[fix]`- **Every agent and avatar now opens its profile page, wherever you click it**: Clicking an agent or avatar used to land you in different places depending on where you found it: search results took a detour through two redirects, the quick-search palette linked every agent to a dead URL, gallery thumbnails dropped you into the bare 3D viewer, and older links still used a retired address. Now every surface, including search, the quick-search palette, the gallery, the homepage showcase, your feed, and creator profiles, links straight to the entity's profile page: the one with the 3D stage, chat, wallet, skills, and embed tools. Agents share the same page style as avatars, so the platform feels like one place instead of six. `[improvement, fix]`## 2026-08-17diff --git a/STRUCTURE.md b/STRUCTURE.mdindex 19b839f79..db62d6911 100644--- a/STRUCTURE.md+++ b/STRUCTURE.md@@ -15,6 +15,7 @@ bottom.| Surface | Location | Status | Notes ||---|---|---|---|| Web renderer / viewer | [avatar-sdk/](avatar-sdk) `→ /viewer` | Published as `@three-ws/avatar` | `<agent-3d>` web component |+| Entity studio (one detail page for agents AND avatars) | [pages/avatar-page.html](pages/avatar-page.html) + [src/avatar-page.js](src/avatar-page.js) `→ /avatars/:id` and `→ /agents/:id`, view switcher [src/view-switcher.js](src/view-switcher.js), AR lane [src/ar-page.js](src/ar-page.js) `→ /avatars/:id/ar` + `/agents/:id/ar`, long-form agent profile [pages/agent-detail.html](pages/agent-detail.html) + [src/agent-detail.js](src/agent-detail.js) `→ /agents/:id/profile` | Live | The canonical page every entity link on the platform lands on: search, `/agents`, `/gallery`, the marketplace, galaxy, launches and profiles all point here. One controller renders both kinds from one shell (3D stage + wallet-reactive aura, identity, tabs for Overview / Chat / Pose / Skills / Plugins / Embed, related grid). Agent mode projects the agent record onto the avatar shape (`agentStudioRecord`): the agent's name, description, tags and custodial wallet win, its bound body supplies geometry and fork lineage, and chat posts the real `agentId` so replies come from that agent's brain and memory. Agents and avatars are separate tables with separate UUIDs, so an id that lands on the wrong route is probed against the other store and redirected to its canonical path instead of 404ing. An agent with no body yet renders a designed stage state ("create a body" / "pick one from the marketplace") rather than an empty viewer, and every body-scoped surface (AR, Pose, forks, coin launch, GLB stats) stays hidden. Docs: [docs/agents-vs-avatars.md](docs/agents-vs-avatars.md) || Agent shell (companion identity + agentic ⌘K + persistent navigation) | [src/agents/guest-agent.js](src/agents/guest-agent.js), [src/shared/agent-names.js](src/shared/agent-names.js), [src/walk-companion-identity.js](src/walk-companion-identity.js), [public/search.js](public/search.js), [src/view-transitions.js](src/view-transitions.js), [src/shell/page-lifecycle.js](src/shell/page-lifecycle.js) | Live | The agent IS the interface: every visitor gets a named ephemeral agent in the first five seconds (auto-summoned corner companion with an identity chip; “Claim →” prefills /create-agent and POST /api/agents makes it real); the ⌘K palette executes real commands in place (forge → free text→3D lane, digest → clustered news, price → live market data, ask → streamed /api/chat) and announces completions so the companion reacts; pages marked data-shell (`/markets`, `/coins`) navigate by swapping only the main element so the agent and shell never unload (page modules re-init via onPageReady). Docs: [docs/agent-shell.md](docs/agent-shell.md). Tests: [tests/search-commands.test.js](tests/search-commands.test.js), [tests/guest-agent.test.js](tests/guest-agent.test.js), [tests/agent-names.test.js](tests/agent-names.test.js) || Walk companion + playground | [walk-sdk/](walk-sdk) `→ /walk-companion.js` | Published as `@three-ws/walk` | Corner mascot + full-page stroll/platformer playground + diverse avatar picker. App entries: [src/walk-companion.js](src/walk-companion.js), [src/walk-playground.js](src/walk-playground.js) || The walkaround world (`/temporary`) | [pages/temporary.html](pages/temporary.html) `→ /temporary`, app [src/walk.js](src/walk.js), environments [src/walk-environments.js](src/walk-environments.js) + [public/environments/](public/environments), multiplayer [src/walk-net.js](src/walk-net.js) → `walk_world`, day/night [src/walk-day-night.js](src/walk-day-night.js), radar [src/game/hud/minimap.js](src/game/hud/minimap.js), companions [src/walk-npcs.js](src/walk-npcs.js), agent desks [src/walk-agent-desk.js](src/walk-agent-desk.js) | Live | Walk your avatar through six real staged environments (park, cyberpunk street, beach, gallery, void, office) with physics-driven locomotion on a heightfield, four camera modes, gestures, voice chat, trails, capture, and live peers. **Time of day is real and shared:** the same deterministic world clock `/play` runs on ([src/shared/world-clock.js](src/shared/world-clock.js)) drives the sun arc, sky gradient, light levels, and IBL strength, so two people in the same world always agree on whether it is night. The sky crossfades on a wider curve than the light levels, so dawn and dusk linger instead of flipping. Armed for outdoor stages only (indoor/void keep their authored manifest lighting) and paused while AR passthrough owns the rig. **The radar is `/play`'s:** `/temporary` mounts the same rotating GTA-style minimap the world HUD uses, with a compass, the walkable-disc boundary ring, and live blips for peers (their nameplate colours), NPC companions, live agent desks, the guide's named landmarks, and scenery. Click or tap it to set a walk-to waypoint (`Minimap.worldFromScreen()` inverts the rotating projection); `M` or the dock button toggles it and the choice persists. **Frame pacing is shared too:** the loop runs through [src/shared/frame-governor.js](src/shared/frame-governor.js) (60fps focused, 30 unfocused, 30 under power saver) and the controls overlay carries the cross-surface Power-saver switch. Tests: [tests/walk-day-night.test.js](tests/walk-day-night.test.js), [tests/minimap-projection.test.js](tests/minimap-projection.test.js) |diff --git a/data/changelog.json b/data/changelog.jsonindex ae41a0203..80c48dd59 100644--- a/data/changelog.json+++ b/data/changelog.json@@ -1,6 +1,24 @@{"$comment": "Curated changelog entries for three.ws, the editorial layer of the public changelog. New PAGE launches are tracked automatically via the `added` field in data/pages.json; this file is for everything else holders care about: improvements, fixes, SDK releases, trading/payments capabilities, security work. scripts/build-page-index.mjs merges both sources into CHANGELOG.md, public/changelog.json, and public/changelog.xml. Newest first. Allowed tags: feature, improvement, fix, sdk, infra, docs, security. `link` is optional and must be a live three.ws path.","entries": [+ {+ "date": "2026-08-18",+ "title": "Agents and avatars now open in the same studio page",+ "summary": "Clicking an agent used to land you on a long scrolling profile, while clicking an avatar opened the 3D studio. They are now the same page. Every agent link on three.ws (the search bar, the agents directory, the gallery, the marketplace, the galaxy, launches and creator profiles) opens the studio layout: the agent standing in a live 3D stage on the left, its identity, wallet and actions on the right, and tabs for chat, poses, skills, plugins and embed codes. Talking to an agent there uses that agent's own brain and memory, and AR now works from an agent page too. An agent that has no 3D body yet gets a proper page instead of an empty viewer, with both ways to give it one. The full agent profile (capabilities, economy, activity, trust and developer tools) is one click away on the Profile button, and every entity now has a single canonical link that is safe to share.",+ "tags": [+ "improvement",+ "feature"+ ],+ "link": "/agents"+ },+ {+ "date": "2026-08-18",+ "title": "Avatar and agent pages load in Safari again",+ "summary": "Every avatar and agent page failed to load in Safari, on both iPhone and Mac, showing \"Avatar not found\" with the message \"Cannot access uninitialized variable.\" instead of the 3D stage. Chrome, Edge, and Firefox were unaffected, which is why the pages looked fine on most desktops while iPhone visitors saw a dead page. Safari checks a variable is ready at a slightly earlier moment than other browsers do, and the page set up its data one step before that check was satisfied. The page now finishes declaring its state before it starts loading, so it renders identically in every browser.",+ "tags": [+ "fix"+ ]+ },{"date": "2026-08-17","title": "The AWS Marketplace integration is rebuilt for the rules AWS now enforces",diff --git a/docs/agents-vs-avatars.md b/docs/agents-vs-avatars.mdindex 80f2ba865..5d9d66078 100644--- a/docs/agents-vs-avatars.md+++ b/docs/agents-vs-avatars.md@@ -33,10 +33,40 @@ You don't use an avatar by itself, and you don't use an agent without a body. Pa- **From an agent's Studio (Body tab)**: click `Change avatar`. This opens the avatar picker; selecting an avatar attaches that body to the agent (the personality is untouched).- **From Studio** — pick both sides explicitly. Use this when you want full control over name, skills, description, and wallet setup before publishing.-## How to tell which page you're on+## One page, both kinds: the studio-- Avatar pages (`/avatars/<id>`) show a type pill reading `Avatar · 3D Body`, with a help link that leads back to this page.-- Agent pages live at `/agents/<id>` and show the agent's name, on-chain badge (if registered), and chat surface. If a page can talk back, it's an agent.+Agents and avatars share a single detail page. `/avatars/<id>` and `/agents/<id>` render the same layout: a 3D stage on the left, identity and actions on the right, and tabs for Overview, Chat, Pose, Skills, Plugins and Embed. Everywhere on the platform that links to an entity (the search bar, `/agents`, `/gallery`, the marketplace, the galaxy, launches, profiles) lands you here, so the thing you clicked always opens the same way.++The two modes differ only where the underlying entity does:++| | `/avatars/<id>` | `/agents/<id>` |+|---|---|---|+| Type pill | `Avatar · 3D Body` | `Agent · AI Identity` |+| Title + description | The avatar's | The agent's |+| Views in the switcher | 3D, Chat, AR, Embed | 3D, Chat, AR, Embed, Profile |+| Primary action | `Start an agent` | `Full profile` |+| Chat | Voices the body | Speaks as the agent, using its brain and memory |+| Relationship card | `Used by`: the agents wearing this body | `Wearing`: the body this agent wears |+| Wallet | Only via a bound agent | The agent's own custodial wallet |++Both directions are one click apart: an agent's `Wearing` card opens its body's page, and a body's `Used by` grid opens each agent that wears it.++### How to tell which page you're on++- The type pill under the header says it outright, and its `?` link leads back to this page.+- If the page can talk back as a named identity with a wallet, it's an agent.++### The long-form agent profile++An agent carries more than a body: capabilities and skill pricing, economy and holdings, an activity log, trust and on-chain identity, reviews, and developer tooling (embed snippets, MCP wiring, raw metadata). That lives one level deeper at `/agents/<id>/profile`, reachable from the `Full profile` button and the `Profile` segment of the view switcher. The pre-redesign layout is still served at `/agents/<id>/classic`.++### Sharing and canonical URLs++Every entity has exactly one canonical URL: `/avatars/<id>` or `/agents/<id>`. The `?view=` variants (chat, embed) and `?embed=1` are the same page in a different tab, and they all declare the canonical URL, so links collapse to one document when shared. An id shared on the wrong route redirects to the right one instead of showing "not found" (an agent id at `/avatars/<id>` lands on `/agents/<id>`, and the reverse).++### Agents without a body++Agents can exist before they wear anything. Their studio page still renders in full: the identity, wallet, chat and skills all work, and the stage explains the gap with two ways to close it (create a body, or pick one from the marketplace). Body-scoped surfaces (AR, the Pose tab, forks, GLB stats, coin launches) stay hidden rather than rendering empty shells.## Frequently confuseddiff --git a/pages/avatar-page.html b/pages/avatar-page.htmlindex 7afc027d8..192413c27 100644--- a/pages/avatar-page.html+++ b/pages/avatar-page.html@@ -564,6 +564,11 @@.av-cta:hover {transform: translateY(-1px);}+ .av-cta:focus-visible,+ .av-cta-sec:focus-visible {+ outline: 2px solid var(--accent);+ outline-offset: 2px;+ }.av-cta-sec {background: transparent;border: 1px solid var(--border-2);@@ -1538,11 +1543,93 @@}.av-error {+ display: flex;+ flex-direction: column;+ align-items: center;+ gap: 8px;padding: 80px 24px;text-align: center;color: var(--text-3);font-size: 14px;}+ .av-error strong {+ font-size: 17px;+ color: var(--text);+ letter-spacing: -0.01em;+ }+ .av-error-cta {+ margin-top: 10px;+ padding: 9px 18px;+ border-radius: 999px;+ border: 1px solid var(--border-2);+ color: var(--text);+ text-decoration: none;+ font-size: 13px;+ font-weight: 600;+ transition:+ background 0.15s ease,+ border-color 0.15s ease,+ transform 0.15s ease;+ }+ .av-error-cta:hover {+ background: var(--panel-2);+ border-color: var(--text-3);+ }+ .av-error-cta:active {+ transform: translateY(1px);+ }+ .av-error-cta:focus-visible {+ outline: 2px solid var(--accent);+ outline-offset: 2px;+ }++ /* Agent with no avatar bound yet: the stage explains the gap and+ offers both ways to close it, instead of an empty black box. */+ .av-stage-bodyless {+ position: absolute;+ inset: 0;+ display: flex;+ flex-direction: column;+ align-items: center;+ justify-content: center;+ gap: 10px;+ padding: 32px 28px;+ text-align: center;+ color: var(--text-3);+ background:+ radial-gradient(+ circle at 50% 38%,+ rgba(255, 255, 255, 0.06),+ transparent 62%+ );+ }+ .av-stage-bodyless svg {+ opacity: 0.4;+ }+ .av-stage-bodyless strong {+ font-size: 18px;+ font-weight: 600;+ letter-spacing: -0.01em;+ color: var(--text);+ }+ .av-stage-bodyless p {+ margin: 0;+ max-width: 42ch;+ font-size: 13px;+ line-height: 1.6;+ }+ .av-stage-bodyless-actions {+ display: flex;+ flex-wrap: wrap;+ gap: 8px;+ justify-content: center;+ margin-top: 8px;+ }+ .av-stage-bodyless-actions .av-cta,+ .av-stage-bodyless-actions .av-cta-sec {+ display: inline-flex;+ align-items: center;+ }/* ── Responsive ──────────────────────────────────── */@media (max-width: 980px) {diff --git a/public/changelog.json b/public/changelog.jsonindex 681199611..d37d41a39 100644--- a/public/changelog.json+++ b/public/changelog.json@@ -1,11 +1,32 @@{- "generated_at": "2026-08-18T23:12:24.206Z",+ "generated_at": "2026-08-18T23:28:04.092Z","generated_by": "scripts/build-page-index.mjs from data/pages.json + data/changelog.json","site": {"name": "three.ws","url": "https://three.ws"},"entries": [+ {+ "date": "2026-08-18",+ "type": "update",+ "title": "Agents and avatars now open in the same studio page",+ "summary": "Clicking an agent used to land you on a long scrolling profile, while clicking an avatar opened the 3D studio. They are now the same page. Every agent link on three.ws (the search bar, the agents directory, the gallery, the marketplace, the galaxy, launches and creator profiles) opens the studio layout: the agent standing in a live 3D stage on the left, its identity, wallet and actions on the right, and tabs for chat, poses, skills, plugins and embed codes. Talking to an agent there uses that agent's own brain and memory, and AR now works from an agent page too. An agent that has no 3D body yet gets a proper page instead of an empty viewer, with both ways to give it one. The full agent profile (capabilities, economy, activity, trust and developer tools) is one click away on the Profile button, and every entity now has a single canonical link that is safe to share.",+ "link": "/agents",+ "tags": [+ "improvement",+ "feature"+ ]+ },+ {+ "date": "2026-08-18",+ "type": "update",+ "title": "Avatar and agent pages load in Safari again",+ "summary": "Every avatar and agent page failed to load in Safari, on both iPhone and Mac, showing \"Avatar not found\" with the message \"Cannot access uninitialized variable.\" instead of the 3D stage. Chrome, Edge, and Firefox were unaffected, which is why the pages looked fine on most desktops while iPhone visitors saw a dead page. Safari checks a variable is ready at a slightly earlier moment than other browsers do, and the page set up its data one step before that check was satisfied. The page now finishes declaring its state before it starts loading, so it renders identically in every browser.",+ "link": null,+ "tags": [+ "fix"+ ]+ },{"date": "2026-08-18","type": "update",diff --git a/public/changelog.xml b/public/changelog.xmlindex 77f497dce..f2f9cd5d0 100644--- a/public/changelog.xml+++ b/public/changelog.xml@@ -6,6 +6,22 @@<atom:link href="https://three.ws/changelog.xml" rel="self" type="application/rss+xml"/><description>What's new on three.ws: features, improvements, and releases, newest first.</description><language>en</language>+ <item>+ <title>Agents and avatars now open in the same studio page</title>+ <link>https://three.ws/agents</link>+ <guid isPermaLink="false">2026-08-18:Agents and avatars now open in the same studio page</guid>+ <pubDate>Tue, 18 Aug 2026 12:00:00 GMT</pubDate>+ <category>improvement</category>+ <description>Clicking an agent used to land you on a long scrolling profile, while clicking an avatar opened the 3D studio. They are now the same page. Every agent link on three.ws (the search bar, the agents directory, the gallery, the marketplace, the galaxy, launches and creator profiles) opens the studio layout: the agent standing in a live 3D stage on the left, its identity, wallet and actions on the right, and tabs for chat, poses, skills, plugins and embed codes. Talking to an agent there uses that agent's own brain and memory, and AR now works from an agent page too. An agent that has no 3D body yet gets a proper page instead of an empty viewer, with both ways to give it one. The full agent profile (capabilities, economy, activity, trust and developer tools) is one click away on the Profile button, and every entity now has a single canonical link that is safe to share.</description>+ </item>+ <item>+ <title>Avatar and agent pages load in Safari again</title>+ <link>https://three.ws/changelog</link>+ <guid isPermaLink="false">2026-08-18:Avatar and agent pages load in Safari again</guid>+ <pubDate>Tue, 18 Aug 2026 12:00:00 GMT</pubDate>+ <category>fix</category>+ <description>Every avatar and agent page failed to load in Safari, on both iPhone and Mac, showing "Avatar not found" with the message "Cannot access uninitialized variable." instead of the 3D stage. Chrome, Edge, and Firefox were unaffected, which is why the pages looked fine on most desktops while iPhone visitors saw a dead page. Safari checks a variable is ready at a slightly earlier moment than other browsers do, and the page set up its data one step before that check was satisfied. The page now finishes declaring its state before it starts loading, so it renders identically in every browser.</description>+ </item><item><title>Every agent and avatar now opens its profile page, wherever you click it</title><link>https://three.ws/changelog</link>diff --git a/public/features.json b/public/features.jsonindex 9d2491c61..1794d2565 100644--- a/public/features.json+++ b/public/features.json@@ -1,5 +1,5 @@{- "generated_at": "2026-08-17T15:18:34.415Z",+ "generated_at": "2026-08-18T23:28:04.062Z","generated_by": "scripts/build-page-index.mjs from data/pages.json","site": {"name": "three.ws",diff --git a/src/agent-detail.js b/src/agent-detail.jsindex a1383a28b..1afbaf16e 100644--- a/src/agent-detail.js+++ b/src/agent-detail.js@@ -1040,15 +1040,26 @@ function render(agent) {// has a resolvable body (custom GLB or mannequin), so the mode is always live.wireWalkMode(agent);- // View switcher: flip this agent between its detail, 3D world, and embed- // presentations. Every agent has a 3D body (custom GLB or mannequin).+ // View switcher: flip this agent between the studio (/agents/:id), chat, AR,+ // embed, and this long-form profile. Every agent has a 3D body (custom GLB+ // or mannequin), so the AR segment always applies.mountViewSwitcher($('view-switch-slot'), {kind: 'agent',id: agent.id,active: new URLSearchParams(location.search).get('view') === 'embed' ? 'embed' : 'detail',- worldHref: seeInWorldHref(agent),+ hasBody: true,});+ // This profile sits one level below the agent's studio page, so "back" is+ // the studio, not the whole registry. The registry is one more hop up and+ // stays reachable from the nav.+ const back = document.querySelector('.ad-back');+ if (back) {+ back.removeAttribute('data-i18n');+ back.href = `/agents/${encodeURIComponent(agent.id)}`;+ back.textContent = `\u2190 ${agent.name || 'Agent'}`;+ }+// Embed snippets work for every agent, not just marketplace-published ones,// so the "Embed" view always lands on real, copyable code. Marketplace// enrichment later refreshes this with the canonical GLB if it differs.diff --git a/src/ar-page.js b/src/ar-page.jsindex 2e3f89dc3..a6a1d3f52 100644--- a/src/ar-page.js+++ b/src/ar-page.js@@ -1,7 +1,8 @@/**- * /avatars/:id/ar — dedicated AR experience page+ * /avatars/:id/ar and /agents/:id/ar: the dedicated AR experience page*- * Fetches the avatar, loads it into a full-screen model-viewer with AR enabled.+ * Fetches the entity (an avatar directly, or an agent's bound body), loads it+ * into a full-screen model-viewer with AR enabled.* If the avatar has a pre-generated usdz_url, sets it as ios-src immediately.* Otherwise converts the GLB to USDZ in-browser and sets a temporary object URL* so Quick Look works in the current session.@@ -13,21 +14,38 @@ 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']-const fromPath = segments[0] === 'avatars' && segments[2] === 'ar' ? segments[1] : null;-const fromQuery = new URLSearchParams(location.search).get('id');-const avatarId = fromPath || fromQuery || '';+// /avatars/:id/ar → ['avatars', 'uuid', 'ar']; /agents/:id/ar → ['agents', ...]+const isAgentRoute = segments[0] === 'agents' && segments[2] === 'ar';+const fromPath =+ (segments[0] === 'avatars' || isAgentRoute) && segments[2] === 'ar' ? segments[1] : null;+const params = new URLSearchParams(location.search);+const fromQuery = params.get('id');+const mode = isAgentRoute || params.get('kind') === 'agent' ? 'agent' : 'avatar';+const entityId = fromPath || fromQuery || '';+// The body's id. Equal to entityId for an avatar, resolved from the agent's+// avatar_id otherwise. Every /api/avatars call keys off this.+let avatarId = mode === 'avatar' ? entityId : '';const $ = (id) => document.getElementById(id);let usdzObjectUrl = null;async function init() {- if (!avatarId) {- showError('No avatar specified.');+ if (!entityId) {+ showError(`No ${mode} specified.`);return;}+ if (mode === 'agent') {+ const agent = await fetchAgent(entityId);+ if (!agent) return;+ if (!agent.avatar_id) {+ showError(`${agent.name || 'This agent'} has no 3D body yet.`);+ return;+ }+ avatarId = agent.avatar_id;+ }+const avatar = await fetchAvatar(avatarId);if (!avatar) return;@@ -59,6 +77,17 @@ async function fetchAvatar(id) {}}+async function fetchAgent(id) {+ try {+ const r = await fetch(`/api/agents/${encodeURIComponent(id)}`, { credentials: 'include' });+ if (!r.ok) throw new Error(`${r.status}`);+ return (await r.json()).agent;+ } catch (err) {+ showError(`Couldn't load agent (${err.message}).`);+ return null;+ }+}+function renderPage(avatar, glbUrl) {$('ar-avatar-name').textContent = avatar.name || 'Avatar';document.title = `${avatar.name || 'Avatar'} in AR · three.ws`;@@ -76,7 +105,12 @@ function renderPage(avatar, glbUrl) {}const id = avatar.id || avatarId;- $('ar-back-link').href = `/avatars/${encodeURIComponent(id)}`;+ // Back goes to whichever studio page the visitor came from (the agent's or+ // the body's), so the AR detour never strands them on the wrong entity.+ $('ar-back-link').href =+ mode === 'agent'+ ? `/agents/${encodeURIComponent(entityId)}`+ : `/avatars/${encodeURIComponent(id)}`;// Living-agent handoff: /irl loads this avatar as the agent's body in the// user's real space (camera passthrough, animation, conversation). Static// placement is one option; alive is the point.@@ -85,7 +119,12 @@ function renderPage(avatar, glbUrl) {liveLink.href = `/irl?avatar=${encodeURIComponent(id)}`;liveLink.hidden = false;}- mountViewSwitcher($('view-switch-slot'), { kind: 'avatar', id, active: 'ar' });+ mountViewSwitcher($('view-switch-slot'), {+ kind: mode,+ id: mode === 'agent' ? entityId : id,+ active: 'ar',+ hasBody: true,+ });$('ar-share-btn').addEventListener('click', () => shareAvatar(avatar));}diff --git a/src/avatar-page.js b/src/avatar-page.jsindex 812098794..c82c6f19a 100644--- a/src/avatar-page.js+++ b/src/avatar-page.js@@ -1,8 +1,18 @@/**- * Avatar studio page controller — /avatars/:id+ * Studio page controller: the canonical profile for every entity on three.ws.*- * Renders an avatar with a 3D viewer, metadata, attachable skills + plugins,- * a live LLM chat, embed snippets, and a related-avatars grid. Demo IDs+ * One template, two entity kinds:+ * /avatars/:id a 3D body (the avatar itself is the subject)+ * /agents/:id an agent identity, rendered wearing its bound body+ *+ * Both render the same shell: a 3D viewer, identity + wallet, metadata,+ * attachable skills + plugins, a live LLM chat, pose stage, embed snippets,+ * and a related grid. Whatever links to an entity anywhere on the platform+ * (search, /agents, /gallery, the marketplace) lands here.+ *+ * Agent mode projects the agent record onto the avatar shape (see+ * `agentStudioRecord`) so a single renderer drives both, and an agent with no+ * body yet still gets a full page instead of a broken viewer. Demo IDs* (avatar_demo_*) are resolved server-side via /api/avatars/[id].js so the* same code path serves both real and seeded avatars.*/@@ -37,30 +47,35 @@ const esc = (s) =>// ── Routing ───────────────────────────────────────────────────────────-// Avatar id: path-based in production (/avatars/:id) or `?id=` query param in-// dev (vite doesn't rewrite arbitrary paths to avatar-page.html).+// Entity id + kind: path-based in production (/avatars/:id, /agents/:id) or+// `?id=` + `?kind=` query params in dev (vite doesn't rewrite arbitrary paths+// to avatar-page.html).const segments = location.pathname.split('/').filter(Boolean);-const queryId = new URLSearchParams(location.search).get('id');-const avatarId = (segments[0] === 'avatars' && segments[1]) || queryId || '';+const params = new URLSearchParams(location.search);+const queryId = params.get('id');+const mode = segments[0] === 'agents' || params.get('kind') === 'agent' ? 'agent' : 'avatar';+const entityId =+ ((segments[0] === 'avatars' || segments[0] === 'agents') && segments[1]) || queryId || '';++// The bound body's id. Identical to `entityId` on an avatar route; filled in+// from the agent's `avatar_id` once the agent record loads. Every avatar-scoped+// call (poses, forks, /api/avatars/*) keys off THIS, never off an agent id:+// the two live in separate tables with separate UUIDs. Empty string means the+// agent has no body yet, and body-scoped sections stay hidden.+let avatarId = mode === 'avatar' ? entityId : '';++// Canonical URL for this entity, used for OG/canonical tags and share links.+const entityPath = `/${mode === 'agent' ? 'agents' : 'avatars'}/${encodeURIComponent(entityId)}`;// Embed mode: hide chrome (header, actionbar, related, footer) so the page// looks clean inside an iframe.-const isEmbed = new URLSearchParams(location.search).get('embed') === '1';+const isEmbed = params.get('embed') === '1';if (isEmbed) {document.body.classList.add('av-embed');document.querySelectorAll('.site-header, .av-actionbar, .av-related, .h-footer-horizon').forEach((el) => { el.style.display = 'none'; });}-if (!avatarId) {- $('av-shell').innerHTML = `<div class="av-error">No avatar specified.</div>`;-} else {- init().catch((err) => {- log.error('[avatar] init', err);- $('av-shell').innerHTML = `<div class="av-error">${esc(err.message || 'Failed to load')}</div>`;- });-}-// Stop the wallet-aura live poll and free its rAF when the page unloads.window.addEventListener('pagehide', () => {netWorthAura?.destroy?.(); netWorthAura = null;@@ -71,6 +86,12 @@ window.addEventListener('pagehide', () => {// ── State ─────────────────────────────────────────────────────────────let avatar = null;+// The agent record in agent mode; null when the subject is a bare avatar.+let agent = null;+// Whether the current session owns the subject. In avatar mode `owner_id` is+// only present on the GET response for the owner; in agent mode the server+// answers directly with `is_owner`.+let viewerOwns = false;let netWorthAura = null;let netWorthPanel = null;let netWorthPlate = null;@@ -116,59 +137,144 @@ const MODEL_STORAGE_KEY = 'avatar_chat_model_v1';// ── Init ──────────────────────────────────────────────────────────────async function init() {- avatar = await fetchAvatar(avatarId);- if (!avatar.model_url && !avatar.url) throw new Error('This avatar has no GLB.');+ ({ agent, avatar } = await resolveEntity(entityId));+ avatarId = avatar.id || '';+ viewerOwns = mode === 'agent' ? !!agent.is_owner : !!avatar.owner_id;- const glbUrl = avatar.model_url || avatar.url;+ // An avatar always has geometry; an agent may not have been given a body+ // yet. The bodyless case is a designed state, not an error.+ const glbUrl = avatar.model_url || avatar.url || '';+ if (!glbUrl && mode === 'avatar') throw new Error('This avatar has no GLB.');- // Persisted skill/plugin attachments (per-avatar, in localStorage)+ // Persisted skill/plugin attachments (per-entity, in localStorage)loadAttached();updateOg();renderShell(glbUrl);+ mountBackLink();mountSwitcher();bindShareButtons();bindTabs();bindChat();- bindOwnerActions();loadSkills();loadPlugins();loadRelated();- loadUsedBy();- loadForks();- measureModel(glbUrl);++ // Body-scoped surfaces. An agent with no avatar has nothing to measure,+ // fork, or launch a coin against, so they stay off rather than rendering+ // empty shells.+ if (avatarId) {+ bindOwnerActions();+ loadForks();+ measureModel(glbUrl);+ }+ // "Used by" is the inverse of agent mode's "Wearing" card: it belongs on the+ // body's page, listing the agents that wear it.+ if (mode === 'avatar') loadUsedBy();+}++// The action bar's back link points at the directory this entity came from.+function mountBackLink() {+ const back = document.querySelector('.av-back');+ if (!back || mode !== 'agent') return;+ // The label is i18n-managed in avatar mode; drop the binding so the runtime+ // doesn't overwrite the agent-mode text on its pass.+ back.removeAttribute('data-i18n');+ back.href = '/agents';+ back.textContent = '\u2190 Agents';}// ── API ───────────────────────────────────────────────────────────────-async function fetchAvatar(id) {- const r = await fetch(`/api/avatars/${encodeURIComponent(id)}`);- if (!r.ok) {- // A 404 may mean this id is actually an agent shared (or old-linked) as- // /avatars/:id. agent-detail.js does the reverse for avatar ids landing- // on /agents/:id — keep that symmetry so neither page dead-ends a valid- // entity behind "not found".- if (r.status === 404 && (await resolveAsAgent(id))) {- location.replace(`/agents/${encodeURIComponent(id)}`);+/**+ * Load whichever entity the URL names and hand back the pair the renderer+ * needs. Agents and avatars live in separate tables with separate UUIDs, so an+ * id can land on the wrong route (an old link, a shared URL). Rather than+ * dead-end on "not found", probe the other store and redirect to the canonical+ * path. The page looks the same either way, but the URL stays truthful.+ *+ * @param {string} id+ * @returns {Promise<{ agent: object|null, avatar: object }>}+ */+async function resolveEntity(id) {+ if (mode === 'agent') {+ const rec = await fetchAgentRecord(id);+ if (rec) return { agent: rec, avatar: await agentStudioRecord(rec) };+ if (await fetchAvatarRecord(id).catch(() => null)) {+ location.replace(`/avatars/${encodeURIComponent(id)}`);return new Promise(() => {}); // navigating away; never resolve}+ throw new Error('No agent with that id.');+ }++ const av = await fetchAvatarRecord(id);+ if (av) return { agent: null, avatar: av };+ if (await fetchAgentRecord(id).catch(() => null)) {+ location.replace(`/agents/${encodeURIComponent(id)}`);+ return new Promise(() => {});+ }+ throw new Error('No avatar with that id.');+}++/** GET an avatar record. Returns null on 404; throws on any other failure. */+async function fetchAvatarRecord(id) {+ const r = await fetch(`/api/avatars/${encodeURIComponent(id)}`, { credentials: 'include' });+ if (r.status === 404) return null;+ if (!r.ok) {const j = await r.json().catch(() => ({}));- throw new Error(j.error_description || `Avatar not found (${r.status})`);+ throw new Error(j.error_description || `Could not load this avatar (${r.status})`);}- return (await r.json()).avatar;+ return (await r.json()).avatar || null;}-// Probe the agent store so a misrouted agent id can be handed back to the-// agent detail page instead of rendering a dead "Avatar not found".-async function resolveAsAgent(id) {- try {- const r = await fetch(`/api/agents/${encodeURIComponent(id)}`);- if (!r.ok) return false;- const j = await r.json();- return !!(j && j.agent);- } catch {- return false;+/** GET an agent record. Returns null on 404; throws on any other failure. */+async function fetchAgentRecord(id) {+ const r = await fetch(`/api/agents/${encodeURIComponent(id)}`, { credentials: 'include' });+ if (r.status === 404) return null;+ if (!r.ok) {+ const j = await r.json().catch(() => ({}));+ throw new Error(j.error_description || `Could not load this agent (${r.status})`);}+ return (await r.json()).agent || null;+}++/**+ * Project an agent onto the studio's avatar shape so one renderer drives both+ * entity kinds. The agent's identity (name, description, tags, wallet) wins;+ * its bound body supplies geometry, thumbnail, license, and fork lineage.+ *+ * An agent whose body is missing or private still yields a record, with no+ * model URL, which the stage renders as the "give this agent a body" state.+ */+async function agentStudioRecord(rec) {+ const body = rec.avatar_id ? await fetchAvatarRecord(rec.avatar_id).catch(() => null) : null;+ const base = body || {+ id: null,+ name: rec.name,+ description: rec.description,+ model_category: 'avatar',+ tags: [],+ visibility: 'public',+ attribution: null,+ source_meta: null,+ };+ return {+ ...base,+ name: rec.name || base.name || 'Agent',+ description: rec.description || base.description || '',+ tags: rec.tags?.length ? rec.tags : base.tags || [],+ agent_id: rec.id,+ // The body keeps its own name so the "Wearing" card can show it even+ // though the agent's name wins for the page title.+ body_name: body?.name || null,+ // Wallet chip + net-worth aura read either shape; carry both spellings so+ // an agent with a wallet but no saved body still wears it.+ agent_solana_address: rec.solana_address || base.agent_solana_address || null,+ solana_address: rec.solana_address || null,+ model_url: base.model_url || rec.avatar_model_url || null,+ url: base.url || rec.avatar_model_url || null,+ thumbnail_url: base.thumbnail_url || rec.avatar_thumbnail_url || null,+ };}async function fetchRelated() {@@ -228,7 +334,7 @@ async function fetchSkills() {// nothing when the bound agent has no wallet yet (showPending:false), which is// fine: the avatar itself is an asset and the page already has a fork CTA.function walletRowHTML() {- const chip = walletChipHTML(avatar, { isOwner: !!avatar.owner_id, showPending: false });+ const chip = walletChipHTML(avatar, { isOwner: viewerOwns, showPending: false });return chip ? `<div class="av-wallet-row" id="av-wallet-row">${chip}</div>` : '';}@@ -240,12 +346,68 @@ const CATEGORY_META = {creature: { label: 'Creature · 3D Character', tip: 'A 3D creature or non-human character.' },vehicle: { label: 'Vehicle · 3D Object', tip: 'A 3D vehicle.' },other: { label: '3D Model', tip: 'A 3D model.' },+ agent: { label: 'Agent · AI Identity', tip: 'An agent is the mind: a persona, skills, a wallet, and an on-chain identity. It wears an avatar as its body.' },};function categoryMeta() {+ if (mode === 'agent') return CATEGORY_META.agent;return CATEGORY_META[avatar.model_category] || CATEGORY_META.avatar;}+// The line under the title: who made this, or what kind of thing it is.+function sourceTagText() {+ if (mode === 'agent') {+ return agent.author_name ? `Agent by ${agent.author_name}` : 'Agent on three.ws';+ }+ if (avatar.demo) return 'Curated · Public Domain';+ const kind = CATEGORY_META[avatar.model_category]?.label.split(' · ')[0].toLowerCase() || 'avatar';+ return `Community ${kind}`;+}++/**+ * Stage content for an agent that has no body yet. The studio is the page+ * every agent link lands on, so this has to be a real destination: it says+ * what is missing and hands the owner (or anyone) the two ways to fix it.+ */+function bodylessStageHTML() {+ return `<div class="av-stage-bodyless">+ <svg width="44" height="44" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">+ <circle cx="12" cy="7.5" r="3.5"/><path d="M4.5 20.5c0-4 3.4-6.5 7.5-6.5s7.5 2.5 7.5 6.5"/>+ </svg>+ <strong>${esc(avatar.name)} has no body yet</strong>+ <p>Agents wear an avatar. Give this one a 3D body and it renders here, in AR, in XR, and in every embed.</p>+ <div class="av-stage-bodyless-actions">+ <a class="av-cta" href="/create#avatar-options">Create a body</a>+ <a class="av-cta-sec" href="/marketplace">Pick one from the marketplace</a>+ </div>+ </div>`;+}++/**+ * Agent mode only: the body this agent wears, linking to that avatar's own+ * studio page. Keeps the agent/avatar distinction navigable in both directions+ * (the avatar page's "Used by" grid is the inverse link).+ */+function bodyCardHTML() {+ if (!avatarId) return '';+ const label = avatar.body_name || avatar.slug || 'Body';+ const thumb = avatar.thumbnail_url+ ? `<img class="av-used-by-thumb" src="${esc(avatar.thumbnail_url)}" alt="" loading="lazy" />`+ : `<div class="av-used-by-thumb av-used-by-thumb--placeholder" aria-hidden="true">${esc(label.slice(0, 1).toUpperCase())}</div>`;+ return `<section class="av-used-by" aria-labelledby="av-body-heading">+ <h3 class="av-used-by-heading" id="av-body-heading">Wearing</h3>+ <div class="av-used-by-grid">+ <a class="av-used-by-card" href="/avatars/${encodeURIComponent(avatarId)}" title="Open this body's own page">+ ${thumb}+ <div class="av-used-by-meta">+ <span class="av-used-by-name">${esc(avatar.body_name || avatar.slug || 'Body')}</span>+ <span class="av-used-by-badge">avatar</span>+ </div>+ </a>+ </div>+ </section>`;+}+function renderShell(glbUrl) {const tagsHtml = (avatar.tags || []).map((t) => `<a class="av-tag" href="/marketplace?tag=${encodeURIComponent(t)}">${esc(t)}</a>`)@@ -262,6 +424,7 @@ function renderShell(glbUrl) {$('av-shell').innerHTML = `<div class="av-stage-col"><div class="av-stage" id="av-stage">+ ${glbUrl ? `<div class="av-stage-loading" id="av-stage-loading">Loading 3D model…</div><model-viewerid="av-viewer"@@ -296,8 +459,9 @@ function renderShell(glbUrl) {</button><div class="av-anim-clips" id="av-anim-clips"></div></div>+ ` : bodylessStageHTML()}</div>- <div class="av-meta-strip" id="av-meta-strip">+ <div class="av-meta-strip" id="av-meta-strip"${glbUrl ? '' : ' hidden'}><div class="av-meta-item"><span class="av-meta-key">Format</span><span class="av-meta-val">glTF 2.0</span></div><div class="av-meta-item"><span class="av-meta-key">License</span><span class="av-meta-val" id="av-license">${esc(avatar.attribution?.license || 'Public')}</span></div><div class="av-meta-item" id="av-size-item" hidden><span class="av-meta-key">Size</span><span class="av-meta-val" id="av-size">—</span></div>@@ -319,11 +483,11 @@ function renderShell(glbUrl) {>?</a></div><h1 class="av-name">${esc(avatar.name)}</h1>- <div class="av-source-tag">${avatar.demo ? 'Curated · Public Domain' : `Community ${esc(CATEGORY_META[avatar.model_category]?.label.split(' · ')[0].toLowerCase() || 'avatar')}`}</div>+ <div class="av-source-tag">${esc(sourceTagText())}</div>${byLine}${tagsHtml ? `<div class="av-tags">${tagsHtml}</div>` : ''}${walletRowHTML()}- ${avatar.owner_id && avatar.agent_id ? `<div class="av-wallet-manage" id="av-wallet-manage"></div>` : ''}+ ${viewerOwns && avatar.agent_id ? `<div class="av-wallet-manage" id="av-wallet-manage"></div>` : ''}</div><div class="av-cta-talk-row"><button class="av-cta-talk" id="av-talk" type="button" aria-label="Talk to ${esc(avatar.name)}">@@ -332,43 +496,48 @@ function renderShell(glbUrl) {</button></div><div class="av-cta-row">- <button class="av-cta" id="av-use">Start an agent</button>+ ${mode === 'agent'+ ? `<a class="av-cta" href="/agents/${encodeURIComponent(entityId)}/profile" title="Capabilities, economy, activity, trust and developer tools">Full profile</a>`+ : `<button class="av-cta" id="av-use">Start an agent</button>`}<a class="av-cta-sec" href="/brain" title="Build a persona and test with AI models">Brain</a>- <a class="av-cta-sec" href="/voice" title="Clone your voice for this avatar">Voice Lab</a>- <a class="av-cta-sec" href="/studio?avatar=${encodeURIComponent(avatar.id || avatarId)}" title="Use this avatar in Widget Studio">Open in Studio</a>- <button class="av-cta-sec" id="av-download" type="button">Download ▾</button>+ <a class="av-cta-sec" href="/voice" title="Clone a voice for this ${mode}">Voice Lab</a>+ ${avatarId ? `<a class="av-cta-sec" href="/studio?avatar=${encodeURIComponent(avatarId)}" title="Use this body in Widget Studio">Open in Studio</a>` : ''}+ ${glbUrl ? `<button class="av-cta-sec" id="av-download" type="button">Download ▾</button>` : ''}</div>+ ${avatarId ? `<div class="av-ar-row">- <a class="av-ar-btn" href="/avatars/${encodeURIComponent(avatar.id || avatarId)}/ar" id="av-ar-link">+ <a class="av-ar-btn" href="/avatars/${encodeURIComponent(avatarId)}/ar" id="av-ar-link"><svg 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"><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"/></svg>View in AR</a>- <a class="av-ar-btn" href="/irl?avatar=${encodeURIComponent(avatar.id || avatarId)}">+ <a class="av-ar-btn" href="/irl?avatar=${encodeURIComponent(avatarId)}"><svg 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"><circle cx="12" cy="8" r="4"/><path d="M4 20c0-4 3.6-7 8-7s8 3 8 7"/></svg>Walk IRL</a>- <a class="av-ar-btn" href="/xr?avatar=${encodeURIComponent(avatar.id || avatarId)}">+ <a class="av-ar-btn" href="/xr?avatar=${encodeURIComponent(avatarId)}"><svg 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"><path d="M3 7l9-4 9 4v10l-9 4-9-4V7z"/><path d="M12 3v18M3 7l9 4 9-4"/></svg>View in XR</a>- <a class="av-ar-btn" href="/pose?avatar=${encodeURIComponent(avatar.id || avatarId)}" title="Pose and animate this avatar in the Animation Studio">+ <a class="av-ar-btn" href="/pose?avatar=${encodeURIComponent(avatarId)}" title="Pose and animate this avatar in the Animation Studio"><svg 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"><polygon points="5 3 19 12 5 21 5 3"/></svg>Animate</a></div>- <avatar-actions id="av-actions" avatar-id="${esc(avatar.id || avatarId)}" style="margin-top:14px;display:block"></avatar-actions>- ${avatar.owner_id ? `+ ` : ''}+ ${avatarId ? `<avatar-actions id="av-actions" avatar-id="${esc(avatarId)}"${mode === 'agent' ? ' mode="fork"' : ''} style="margin-top:14px;display:block"></avatar-actions>` : ''}+ ${viewerOwns ? `<div class="av-owner-row" id="av-owner-row">- <a class="av-owner-btn" href="/avatars/${encodeURIComponent(avatar.id || avatarId)}/edit">+ <a class="av-owner-btn" href="${mode === 'agent' ? `/agent/${encodeURIComponent(entityId)}/edit` : `/avatars/${encodeURIComponent(avatarId)}/edit`}"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/></svg>Edit</a>- ${avatar.source_meta?.generator === 'avatar-studio' ? `- <a class="av-owner-btn" href="/create/studio?edit=${encodeURIComponent(avatar.id || avatarId)}">+ ${avatarId && avatar.source_meta?.generator === 'avatar-studio' ? `+ <a class="av-owner-btn" href="/create/studio?edit=${encodeURIComponent(avatarId)}"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="2" y="3" width="20" height="14" rx="2"/><path d="M8 21h8M12 17v4"/></svg>Edit in Studio</a>` : ''}+ ${avatarId ? `<button class="av-owner-btn" id="av-deploy-onchain" type="button"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/></svg>Deploy on-chain@@ -381,12 +550,13 @@ function renderShell(glbUrl) {<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="9"/><path d="M14.5 9.3a2.6 2.6 0 0 0-4.9.9c0 2.7 4.9 1.4 4.9 4.1a2.6 2.6 0 0 1-4.9.9M12 6.5v11"/></svg>Fees & rewards</button>+ ` : ''}</div>` : ''}<nav class="av-tabs" role="tablist"><button class="av-tab active" data-tab="overview" role="tab">Overview</button><button class="av-tab" data-tab="chat" role="tab">Chat</button>- <button class="av-tab" data-tab="pose" role="tab">Pose</button>+ ${avatarId ? `<button class="av-tab" data-tab="pose" role="tab">Pose</button>` : ''}<button class="av-tab" data-tab="skills" role="tab">Skills</button><button class="av-tab" data-tab="plugins" role="tab">Plugins</button><button class="av-tab" data-tab="embed" role="tab">Embed</button>@@ -394,6 +564,7 @@ function renderShell(glbUrl) {<div class="av-panels"><div class="av-panel active" data-panel="overview" id="av-overview">${avatar.description ? `<p class="av-desc">${esc(avatar.description)}</p>` : '<p class="av-desc" style="color:var(--text-3)">No description provided.</p>'}+ ${mode === 'agent' ? bodyCardHTML() : ''}<section class="av-used-by" id="av-used-by" hidden aria-labelledby="av-used-by-heading"><h3 class="av-used-by-heading" id="av-used-by-heading">Used by</h3><div class="av-used-by-grid" id="av-used-by-grid"></div>@@ -513,7 +684,7 @@ function renderShell(glbUrl) {*/function mountWalletManager() {const host = $('av-wallet-manage');- if (!host || !avatar.owner_id || !avatar.agent_id) return;+ if (!host || !viewerOwns || !avatar.agent_id) return;const identity = {id: avatar.agent_id,@@ -615,7 +786,7 @@ function mountNetWorthAura() {// hydrates from the same cached wallet read the aura uses (no extra request).if (!netWorthPlate) {netWorthPlate = mountNameplate(stage, avatar, {- network: 'mainnet', isOwner: !!avatar.owner_id, live: true, position: 'bottom',+ network: 'mainnet', isOwner: viewerOwns, live: true, position: 'bottom',});}@@ -821,12 +992,14 @@ function renderAttached() {function renderEmbedPanel(glbUrl) {const fullUrl = location.origin + location.pathname;- // The avatar studio page itself is iframe-friendly; embedders can drop the- // page URL with `?embed=1` and we hide the chrome (handled below).+ // The studio page itself is iframe-friendly; embedders can drop the page URL+ // with `?embed=1` and we hide the chrome (handled below).const iframeSrc = `${fullUrl}?embed=1`;+ // In agent mode the component gets `agent-id` too, so the embed talks to the+ // agent's brain rather than just rendering its body.const webComponentSnippet = `<script type="module" src="https://three.ws/dist-lib/agent-3d.js"><\/script><agent-3d- src="${glbUrl}"+ src="${glbUrl}"${mode === 'agent' ? `\n agent-id="${entityId}"` : ''}style="width:480px;height:480px"></agent-3d>`;const iframeSnippet = `<iframe@@ -837,10 +1010,12 @@ function renderEmbedPanel(glbUrl) {allow="autoplay; xr-spatial-tracking"></iframe>`;const linkSnippet = fullUrl;- const wizardUrl = `/embed?${new URLSearchParams({ avatar: avatar.id || avatarId })}`;+ const wizardUrl = `/embed?${new URLSearchParams(+ mode === 'agent' ? { agent: entityId, ...(avatarId ? { avatar: avatarId } : {}) } : { avatar: avatarId },+ )}`;return `<div style="display:flex;align-items:center;justify-content:space-between;gap:10px;flex-wrap:wrap;margin-bottom:14px">- <p class="av-embed-intro" style="margin:0;font-size:13px;color:var(--ink-dim)">Drop this avatar on any website. Use the wizard for a live preview and platform instructions.</p>+ <p class="av-embed-intro" style="margin:0;font-size:13px;color:var(--ink-dim)">Drop this ${mode} on any website. Use the wizard for a live preview and platform instructions.</p><a href="${esc(wizardUrl)}" class="av-embed-wizard" target="_blank" rel="noopener">Configure in wizard ↗</a></div><div class="av-embed-section">@@ -869,14 +1044,19 @@ function renderEmbedPanel(glbUrl) {// ── View switcher ─────────────────────────────────────────────────────-// Surface the page-level views (3D · Chat · AR · Embed) in the action bar.-// The active view tracks ?view= so Chat/Embed deep-links light up the right-// segment; the bare page is the 3D view.+// Surface the page-level views (3D · Chat · AR · Embed, plus Profile for an+// agent) in the action bar. The active view tracks ?view= so Chat/Embed+// deep-links light up the right segment; the bare page is the 3D view.function mountSwitcher() {if (isEmbed) return;- const view = new URLSearchParams(location.search).get('view');+ const view = params.get('view');const active = view === 'chat' || view === 'embed' ? view : '3d';- mountViewSwitcher($('view-switch-slot'), { kind: 'avatar', id: avatar.id || avatarId, active });+ mountViewSwitcher($('view-switch-slot'), {+ kind: mode,+ id: entityId,+ active,+ hasBody: !!avatarId,+ });}// ── Tabs ──────────────────────────────────────────────────────────────@@ -1112,7 +1292,10 @@ function bindShareButtons() {});}if (twBtn && avatar) {- const text = `Check out "${avatar.name}" — a 3D avatar on three.ws`;+ const text =+ mode === 'agent'+ ? `Meet "${avatar.name}", a 3D AI agent on three.ws`+ : `Check out "${avatar.name}", a 3D avatar on three.ws`;const url = `https://twitter.com/intent/tweet?text=${encodeURIComponent(text)}&url=${encodeURIComponent(location.href)}`;twBtn.href = url;}@@ -1134,7 +1317,7 @@ function bindOwnerActions() {let avatarCoin = null;async function checkAvatarCoin() {if (new URLSearchParams(location.search).get('launch') === '1') openLaunchPumpFun();- const id = avatar?.id || avatarId;+ const id = avatarId;if (!id) return;try {const r = await fetch(`/api/pump/by-agent?avatar_id=${encodeURIComponent(id)}`, { credentials: 'include' });@@ -1228,7 +1411,7 @@ async function openLaunchPumpFun() {const launchPanelUrl = '/studio/launch-panel.js';const { mountLaunchPanel } = await import(/* @vite-ignore */ launchPanelUrl);mountLaunchPanel(inner, {- getAvatar: () => ({ ...avatar, id: avatar.id || avatarId }),+ getAvatar: () => ({ ...avatar, id: avatarId }),getUser: () => user,getPreviewViewer: () => null,});@@ -1248,7 +1431,7 @@ async function openFeesPanel() {if (btn) btn.disabled = true;try {if (!avatarCoin?.mint) {- const id = avatar?.id || avatarId;+ const id = avatarId;const r = await fetch(`/api/pump/by-agent?avatar_id=${encodeURIComponent(id)}`, { credentials: 'include' });const { data } = r.ok ? await r.json() : { data: null };avatarCoin = data;@@ -1262,7 +1445,7 @@ async function openFeesPanel() {mint: avatarCoin.mint,network: avatarCoin.network || 'mainnet',creator: avatarCoin.agent_authority || null,- avatarId: avatar.id || avatarId,+ avatarId: avatarId,agentId: avatar.agent_id || null,symbol: avatarCoin.symbol || '',name: avatarCoin.name || '',@@ -1301,7 +1484,7 @@ async function startAgentWithAvatar() {category: 'general',tags: (avatar.tags || []).slice(0, 8),capabilities: { skills: skillsArr, library: [], bullets: [] },- avatar_id: avatar.id || avatarId,+ avatar_id: avatarId,};// apiFetch attaches the single-use CSRF token every marketplace write needs.const r = await apiFetch('/api/marketplace/agents', {@@ -1591,8 +1774,14 @@ function togglePlugin(id) {// ── Attached storage ──────────────────────────────────────────────────+// Storage is scoped per ENTITY, not per body: an agent and the avatar it wears+// are different subjects, so their attachments and chat memory must not merge.+function entityKey() {+ return mode === 'agent' ? `agent:${entityId}` : avatar?.id || entityId;+}+function attachedKey() {- return ATTACHED_KEY_PREFIX + (avatar?.id || avatarId);+ return ATTACHED_KEY_PREFIX + entityKey();}function loadAttached() {try {@@ -1748,7 +1937,7 @@ function bindChat() {// ── Persistent chat memory ───────────────────────────────────────────const MEMORY_KEY_PREFIX = 'avatar_chat_v1:';-function memoryKey() { return MEMORY_KEY_PREFIX + (avatar?.id || avatarId); }+function memoryKey() { return MEMORY_KEY_PREFIX + entityKey(); }function hydrateChatHistory() {if (!attachedSkills.has('memory')) return;@@ -1758,15 +1947,15 @@ function hydrateChatHistory() {const stored = JSON.parse(raw);if (!Array.isArray(stored) || stored.length === 0) return;chatHistory = stored.slice(-40); // cap so we don't blow context- const log = $('av-chat-log');- if (!log) return;- log.querySelector('.av-chat-empty')?.remove();+ const logEl = $('av-chat-log');+ if (!logEl) return;+ logEl.querySelector('.av-chat-empty')?.remove();// Re-render the conversation from the persisted history.- const existing = log.querySelectorAll('.av-chat-msg');+ const existing = logEl.querySelectorAll('.av-chat-msg');existing.forEach((n) => n.remove());for (const m of chatHistory) appendChatMessage(m.role, m.content);} catch (err) {- log.warn('[avatar] memory hydrate failed', err.message);+ log.warn('[studio] memory hydrate failed', err.message);}}@@ -1813,12 +2002,12 @@ async function speakReply(text) {}async function sendChatMessage(text) {- const log = $('av-chat-log');+ const logEl = $('av-chat-log');const send = $('av-chat-send');- if (!log) return;+ if (!logEl) return;// Drop empty-state once we have any message- const empty = log.querySelector('.av-chat-empty');+ const empty = logEl.querySelector('.av-chat-empty');if (empty) empty.remove();// Wave on the very first user message of the session, if the avatar has@@ -1832,7 +2021,7 @@ async function sendChatMessage(text) {// Real conversation sentiment moves the agent's mood (deterministic lexicon,// never random). Scoped to this agent inside the engine.- moodEngine.observeChat(avatar?.id || avatarId, text, 'user');+ moodEngine.observeChat(chatAgentId(), text, 'user');const assistantNode = appendChatMessage('assistant', '');const cursor = document.createElement('span');@@ -1844,7 +2033,7 @@ async function sendChatMessage(text) {let acc = '';try {const systemContext = buildSystemContext();- const agentIdMaybe = avatar?.id || avatarId;+ const agentIdMaybe = chatAgentId();const isUuid = typeof agentIdMaybe === 'string'&& /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(agentIdMaybe);const choice = MODEL_OPTIONS.find((o) => o.id === selectedModelId);@@ -1883,7 +2072,7 @@ async function sendChatMessage(text) {if (evt.type === 'chunk' && evt.text) {acc += evt.text;assistantNode.textContent = acc;- log.scrollTop = log.scrollHeight;+ logEl.scrollTop = logEl.scrollHeight;streamThoughtText(acc);} else if (evt.type === 'done') {// The server reports exactly which memories it recalled into this@@ -1904,7 +2093,7 @@ async function sendChatMessage(text) {} catch (err) {assistantNode.textContent = acc || `⚠ ${err.message}`;finalizeThought(acc || err.message);- log.error('[avatar] chat', err);+ log.error('[studio] chat', err);} finally {cursor.remove();send.disabled = false;@@ -1912,18 +2101,29 @@ async function sendChatMessage(text) {}function appendChatMessage(role, text) {- const log = $('av-chat-log');+ const logEl = $('av-chat-log');const node = document.createElement('div');node.className = `av-chat-msg ${role}`;node.textContent = text;- log.appendChild(node);- log.scrollTop = log.scrollHeight;+ logEl.appendChild(node);+ logEl.scrollTop = logEl.scrollHeight;return node;}+/**+ * The id /api/chat should key memory, persona, and metering on. In agent mode+ * that is the agent itself (its brain, its memories); in avatar mode the avatar+ * id is the only stable handle the page has.+ */+function chatAgentId() {+ return mode === 'agent' ? entityId : avatar?.id || entityId;+}+function buildSystemContext() {const parts = [- `You are voicing the avatar "${avatar.name}" on three.ws.`,+ mode === 'agent'+ ? `You are the agent "${avatar.name}" on three.ws, speaking as yourself.`+ : `You are voicing the avatar "${avatar.name}" on three.ws.`,avatar.description ? `Your character description: ${avatar.description}` : '',avatar.tags?.length ? `Tags: ${avatar.tags.join(', ')}` : '',];@@ -2120,16 +2320,22 @@ let availableAnimations = new Set();// ── OG meta ───────────────────────────────────────────────────────────function updateOg() {- document.title = `${avatar.name} — Avatar Studio · three.ws`;- $('og-title')?.setAttribute('content', `${avatar.name} — Avatar Studio`);- $('og-description')?.setAttribute('content', avatar.description || `A 3D avatar on three.ws`);- $('og-url')?.setAttribute('content', location.href);- $('tw-title')?.setAttribute('content', `${avatar.name} — Avatar Studio`);- $('tw-description')?.setAttribute('content', avatar.description || `A 3D avatar on three.ws`);- // Always point at /api/avatar/:id/og — that endpoint redirects to the real+ const suffix = mode === 'agent' ? 'Agent Studio' : 'Avatar Studio';+ const fallbackDesc = mode === 'agent' ? 'A 3D AI agent on three.ws' : 'A 3D avatar on three.ws';+ document.title = `${avatar.name} · ${suffix} · three.ws`;+ $('og-title')?.setAttribute('content', `${avatar.name} · ${suffix}`);+ $('og-description')?.setAttribute('content', avatar.description || fallbackDesc);+ $('og-url')?.setAttribute('content', location.origin + entityPath);+ $('tw-title')?.setAttribute('content', `${avatar.name} · ${suffix}`);+ $('tw-description')?.setAttribute('content', avatar.description || fallbackDesc);+ setCanonical(location.origin + entityPath);+ // Always point at the entity's /og endpoint, which redirects to the real// thumbnail when one exists, falls back to a styled SVG card when it doesn't.- // This way social cards never come up empty for demo avatars.- const ogUrl = `${location.origin}/api/avatar/${encodeURIComponent(avatar.id || avatarId)}/og`;+ // This way social cards never come up empty for demo avatars or new agents.+ const ogUrl =+ mode === 'agent'+ ? `${location.origin}/api/og/agent?id=${encodeURIComponent(entityId)}`+ : `${location.origin}/api/avatar/${encodeURIComponent(avatarId)}/og`;$('og-image')?.setAttribute('content', ogUrl);const twImage = document.querySelector('meta[name="twitter:image"]');if (twImage) twImage.setAttribute('content', ogUrl);@@ -2140,3 +2346,43 @@ function updateOg() {document.head.appendChild(m);}}++// One canonical URL per entity: /avatars/:id or /agents/:id, never the ?view=+// or ?embed= variants, so search engines and social unfurls collapse to a+// single page instead of indexing every tab as its own document.+function setCanonical(href) {+ let link = document.querySelector('link[rel="canonical"]');+ if (!link) {+ link = document.createElement('link');+ link.rel = 'canonical';+ document.head.appendChild(link);+ }+ link.href = href;+}++// ── bootstrap (must run last) ────────────────────────────────────────+// Kept at the very end of the module, below every `let` this page owns.+// init() runs during module evaluation and writes module-level state+// (`agent`, `avatar`, `avatarId`, `viewerOwns`). JavaScriptCore checks an+// assignment target's temporal dead zone EAGERLY, before it evaluates the+// right-hand side, so `avatar = await fetch...()` threw+// "Cannot access uninitialized variable." in Safari (desktop and iOS) while+// V8 deferred the same check past the await and never noticed. That took the+// whole studio page down to its "Avatar not found" error state in Safari only.+// Declaring every binding before this call removes the ordering dependency+// instead of relying on which engine checks when.+if (!entityId) {+ $('av-shell').innerHTML = `<div class="av-error">No ${mode} specified.</div>`;+} else {+ init().catch((err) => {+ log.error('[studio] init', err);+ const browse = mode === 'agent'+ ? { href: '/agents', label: 'Browse agents' }+ : { href: '/marketplace', label: 'Browse the marketplace' };+ $('av-shell').innerHTML = `<div class="av-error">+ <strong>${esc(mode === 'agent' ? 'Agent not found' : 'Avatar not found')}</strong>+ <span>${esc(err.message || 'Failed to load')}</span>+ <a class="av-error-cta" href="${browse.href}">${browse.label} →</a>+ </div>`;+ });+}diff --git a/src/view-switcher.js b/src/view-switcher.jsindex 9b4272d5f..259c7a71e 100644--- a/src/view-switcher.js+++ b/src/view-switcher.js@@ -40,14 +40,19 @@ function avatarViews(id) {];}-// 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 } = {}) {+// Views for an agent. /agents/:id is the studio (the same template an avatar+// gets), so 3D and Chat are first-class URLs here too. AR needs a body, and the+// long-form profile (capabilities, economy, activity, trust, developer tools)+// lives one level deeper at /agents/:id/profile.+function agentViews(id, { hasBody = true } = {}) {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' });+ const views = [+ { key: '3d', label: '3D', href: `/agents/${e}`, title: '3D body & details' },+ { key: 'chat', label: 'Chat', href: `/agents/${e}?view=chat`, title: 'Talk to this agent' },+ ];+ if (hasBody) views.push({ key: 'ar', label: 'AR', href: `/agents/${e}/ar`, title: 'View in your space (AR)' });views.push({ key: 'embed', label: 'Embed', href: `/agents/${e}?view=embed`, title: 'Embed this agent anywhere' });+ views.push({ key: 'detail', label: 'Profile', href: `/agents/${e}/profile`, title: 'Capabilities, economy, activity & trust' });return views;}@@ -104,7 +109,7 @@ function injectStyles() {/*** 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+ * @param {{ kind: 'avatar'|'agent', id: string, active: string, hasBody?: boolean }} opts*/export function mountViewSwitcher(slot, opts) {if (!slot || !opts?.id) return null;diff --git a/vercel.json b/vercel.jsonindex e266ea20c..a7afc7df1 100644--- a/vercel.json+++ b/vercel.json@@ -4646,6 +4646,17 @@"src": "/agents/([^/.]+)/classic/?","dest": "/agent-detail-classic.html"},+ {+ "src": "/agents/([^/.]+)/profile/?",+ "dest": "/agent-detail.html"+ },+ {+ "src": "/agents/([^/.]+)/ar/?",+ "headers": {+ "permissions-policy": "xr-spatial-tracking=*, camera=(self), microphone=(self)"+ },+ "dest": "/ar.html"+ },{"src": "/agents/([^/.]+)","has": [@@ -4659,7 +4670,7 @@},{"src": "/agents/([^/.]+)",- "dest": "/agent-detail.html"+ "dest": "/avatar-page.html"},{"src": "/my-agents",@@ -4717,7 +4728,7 @@"src": "/discover/avatar/([^/]+)","status": 301,"headers": {- "Location": "/marketplace/agents/$1"+ "Location": "/avatars/$1"}},{diff --git a/vite.config.js b/vite.config.jsindex 5fe52022d..93ba8e149 100644--- a/vite.config.js+++ b/vite.config.js@@ -1916,16 +1916,26 @@ const appConfig = {// /agents/:id/classic → the preserved pre-redesign profile layoutelse if (!filePath && /^\/agents?\/[^/.]+\/classic\/?$/.test(path))filePath = resolve(root, 'pages/agent-detail-classic.html');- else if (!filePath && /^\/agents\/[^/.]+\/?$/.test(path))+ // /agents/:id/profile → the long-form agent profile (capabilities,+ // economy, activity, trust, developer tools). /agents/:id itself is+ // the studio template both entity kinds share.+ else if (!filePath && /^\/agents\/[^/.]+\/profile\/?$/.test(path))filePath = resolve(root, 'pages/agent-detail.html');+ // /agents/:id/ar → dedicated AR experience for the agent's body+ else if (!filePath && /^\/agents\/[^/.]+\/ar\/?$/.test(path))+ filePath = resolve(root, 'pages/ar.html');+ else if (!filePath && /^\/agents\/[^/.]+\/?$/.test(path))+ filePath = resolve(root, 'pages/avatar-page.html');else if (!filePath && /^\/agent\/[^/]+\/mind\/?$/.test(path))filePath = resolve(root, 'pages/agent-mind.html');else if (!filePath && /^\/agent\/[^/]+\/edit$/.test(path))filePath = resolve(root, 'pages/agent-edit.html');else if (!filePath && /^\/agent\/[^/]+\/embed$/.test(path))filePath = resolve(root, 'pages/agent-embed.html');+ // Legacy singular /agent/:id: vercel.json 301s it to /agents/:id,+ // so dev serves the same studio template it lands on in prod.else if (!filePath && /^\/agent\/[^/]+$/.test(path))- filePath = resolve(root, 'pages/agent-detail.html');+ filePath = resolve(root, 'pages/avatar-page.html');else if (!filePath && /^\/character\/[^/]+\/?$/.test(path))filePath = resolve(root, 'public/character.html');else if (!filePath && (path === '/characters' || path === '/characters/'))