Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

feat: viewer at /app, anonymous Groq chat, owner-card gating, pay+home polish

nirholas5e5c0b7abc30
diff --git a/api/_lib/plans.js b/api/_lib/plans.js
deleted file mode 100644
index d194ed7eb..000000000
--- a/api/_lib/plans.js
+++ /dev/null
@@ -1,17 +0,0 @@
-import { sql } from './db.js';
-
-const PAID_PLANS = new Set(['pro', 'team', 'enterprise']);
-
-export function isPaidPlan(plan) {
- return PAID_PLANS.has(plan);
-}
-
-export async function userHasPaidPlan(userId) {
- if (!userId) return false;
- const rows = await sql`
- select plan, is_admin from users where id = ${userId} and deleted_at is null limit 1
- `;
- const u = rows[0];
- if (!u) return false;
- return u.is_admin === true || isPaidPlan(u.plan);
-}
diff --git a/api/chat.js b/api/chat.js
index 933242b27..0bb23748c 100644
--- a/api/chat.js
+++ b/api/chat.js
@@ -20,8 +20,13 @@ import { parse } from './_lib/validate.js';
import { recordEvent } from './_lib/usage.js';
import { captureException } from './_lib/sentry.js';
import { sql } from './_lib/db.js';
+import { limits, clientIp } from './_lib/rate-limit.js';
import { z } from 'zod';
+// Providers anonymous (unauthenticated) callers may use. Groq's free tier is
+// the only one we expose without sign-in — paid keys stay gated behind auth.
+const ANON_PROVIDERS = new Set(['groq']);
+
export const maxDuration = 60;
const ANTHROPIC_URL = 'https://api.anthropic.com/v1/messages';
@@ -226,13 +231,35 @@ export default wrap(async (req, res) => {
if (!method(req, res, ['POST'])) return;
const auth = await resolveAuth(req);
- if (!auth) return error(res, 401, 'unauthorized', 'sign in to chat with the agent');
-
const body = parse(chatBody, await readJson(req));
+
+ // Anonymous callers are restricted to Groq's free tier (no other provider
+ // keys are exposed without auth). Force-pin the provider and rate-limit by
+ // IP so abuse can't burn the host's quota.
+ let anonymous = false;
+ if (!auth) {
+ const ip = clientIp(req);
+ const rl = await limits.chatIp(ip);
+ if (!rl.success) {
+ return error(res, 429, 'rate_limited', 'too many anonymous chat requests, try again shortly');
+ }
+ if (!process.env.GROQ_API_KEY) {
+ return error(res, 401, 'unauthorized', 'sign in to chat with the agent');
+ }
+ if (body.provider && !ANON_PROVIDERS.has(body.provider)) {
+ return error(res, 401, 'unauthorized', 'sign in to use this model');
+ }
+ body.provider = 'groq';
+ anonymous = true;
+ }
+
const route = pickProvider(body.provider, body.model);
if (!route) {
return error(res, 503, 'chat_unavailable', 'no chat provider is configured');
}
+ if (anonymous && route.name !== 'groq') {
+ return error(res, 401, 'unauthorized', 'sign in to chat with the agent');
+ }
const maxTokens = clampInt(
parseInt(process.env.CHAT_MAX_TOKENS || '', 10) || DEFAULT_MAX_TOKENS,
@@ -331,9 +358,9 @@ export default wrap(async (req, res) => {
const latencyMs = Date.now() - started;
recordEvent({
- userId: auth.userId,
- apiKeyId: auth.apiKeyId,
- clientId: auth.clientId,
+ userId: auth?.userId ?? null,
+ apiKeyId: auth?.apiKeyId,
+ clientId: auth?.clientId,
kind: 'chat',
tool: route.model,
latencyMs,
@@ -343,6 +370,7 @@ export default wrap(async (req, res) => {
output_tokens: result.outputTokens,
actions: result.actions.map((a) => a.type),
has_context: Boolean(body.context?.modelName),
+ anonymous,
},
});
});
diff --git a/api/discover-detail.js b/api/discover-detail.js
index 42d2c4014..bda6bc83c 100644
--- a/api/discover-detail.js
+++ b/api/discover-detail.js
@@ -65,7 +65,7 @@ export default wrap(async (req, res) => {
registeredTx: r.registered_tx || null,
tokenExplorerUrl: tokenExplorerUrl(r.chain_id, r.agent_id),
ownerExplorerUrl: addressExplorerUrl(r.chain_id, r.owner),
- viewerUrl: r.glb_url ? `/#model=${encodeURIComponent(r.glb_url)}` : null,
+ viewerUrl: r.glb_url ? `/app#model=${encodeURIComponent(r.glb_url)}` : null,
services: (r.services || []).map((s) => ({
name: s?.name || null,
endpoint: s?.endpoint || null,
@@ -119,7 +119,7 @@ export default wrap(async (req, res) => {
featured: r.featured === true || r.featured === 't',
viewCount: Number(r.view_count) || 0,
createdAt: r.created_at,
- viewerUrl: `/#model=${encodeURIComponent(glb)}`,
+ viewerUrl: `/app#model=${encodeURIComponent(glb)}`,
author: handle
? {
handle,
diff --git a/api/explore-item.js b/api/explore-item.js
index 91ced025a..80bc86c4c 100644
--- a/api/explore-item.js
+++ b/api/explore-item.js
@@ -63,7 +63,7 @@ export default wrap(async (req, res) => {
registeredTx: r.registered_tx || null,
tokenExplorerUrl: tokenExplorerUrl(r.chain_id, r.agent_id),
ownerExplorerUrl: addressExplorerUrl(r.chain_id, r.owner),
- viewerUrl: r.glb_url ? `/#model=${encodeURIComponent(r.glb_url)}` : null,
+ viewerUrl: r.glb_url ? `/app#model=${encodeURIComponent(r.glb_url)}` : null,
services: (r.services || []).map((s) => ({
name: s?.name || null,
endpoint: s?.endpoint || null,
@@ -119,7 +119,7 @@ export default wrap(async (req, res) => {
featured: r.featured === true || r.featured === 't',
viewCount: Number(r.view_count) || 0,
createdAt: r.created_at,
- viewerUrl: `/#model=${encodeURIComponent(glb)}`,
+ viewerUrl: `/app#model=${encodeURIComponent(glb)}`,
author: handle
? {
handle,
diff --git a/api/explore.js b/api/explore.js
index a67ff3f16..c36f70e65 100644
--- a/api/explore.js
+++ b/api/explore.js
@@ -121,7 +121,7 @@ export default wrap(async (req, res) => {
registeredAt: r.registered_at,
tokenExplorerUrl: tokenExplorerUrl(r.chain_id, r.agent_id),
ownerExplorerUrl: addressExplorerUrl(r.chain_id, r.owner),
- viewerUrl: r.glb_url ? `/#model=${encodeURIComponent(r.glb_url)}` : null,
+ viewerUrl: r.glb_url ? `/app#model=${encodeURIComponent(r.glb_url)}` : null,
services: (r.services || []).map((s) => ({
name: s?.name || null,
endpoint: s?.endpoint || null,
@@ -152,7 +152,7 @@ export default wrap(async (req, res) => {
featured: r.featured === true || r.featured === 't',
viewCount: Number(r.view_count) || 0,
createdAt: r.created_at,
- viewerUrl: `/#model=${encodeURIComponent(glb)}`,
+ viewerUrl: `/app#model=${encodeURIComponent(glb)}`,
author: handle
? {
handle,
diff --git a/home.html b/home.html
index 4ce01ff03..10b6f295d 100644
--- a/home.html
+++ b/home.html
@@ -33,6 +33,17 @@
<meta name="twitter:image" content="https://three.ws/og-image.png" />
<link rel="canonical" href="https://three.ws/" />
+ <script>
+ // Forward legacy /#model=… (and /#agent=, /#onchain=, /#widget=) viewer links to /app,
+ // which is where the Three.js viewer actually mounts. home.html is the marketing page
+ // and ignores these hashes, so without this redirect the user lands on home with no model.
+ (function () {
+ var h = location.hash || '';
+ if (/^#(?:model|agent|onchain|widget|kiosk|preset|brain|deploy|type)=/.test(h)) {
+ location.replace('/app' + h);
+ }
+ })();
+ </script>
<link rel="shortcut icon" href="/favicon.ico" />
<link rel="apple-touch-icon" href="/pwa-192x192.png" />
<link rel="stylesheet" href="/style.css" />
diff --git a/public/agent/index.html b/public/agent/index.html
index 296b10a7d..910d0e1bc 100644
--- a/public/agent/index.html
+++ b/public/agent/index.html
@@ -811,15 +811,17 @@
document.getElementById('page-agent-desc').textContent = identity.description;
}
- // Render the agent home card
+ // Inject hub actions if the viewer is the owner (user_id present = owner)
+ const isOwner = Boolean(rawAgent?.user_id);
+
+ // Render the agent home card. Pass isOwner explicitly so owner-only
+ // cards (Solana wallet, ETH vanity, vanity grinder) only mount for
+ // the owner — AgentIdentity may not know ownership at render time.
const container = document.getElementById('agent-home-container');
container.innerHTML = '';
- const home = new AgentHome(container, identity, protocol, null);
+ const home = new AgentHome(container, identity, protocol, null, { isOwner });
await home.render();
- // Inject hub actions if the viewer is the owner (user_id present = owner)
- const isOwner = Boolean(rawAgent?.user_id);
-
// Mount the $AGENT pump.fun token widget. Renders empty-state for
// not-yet-launched agents (with a "Launch" CTA for owners) and full
// live state when a mint exists. Wires avatar emotion to bus events.
diff --git a/public/discover/detail.js b/public/discover/detail.js
index 7b27cd37c..e04838646 100644
--- a/public/discover/detail.js
+++ b/public/discover/detail.js
@@ -281,7 +281,7 @@ function buildEmbedPanel(item, $) {
{
label: 'iframe',
key: 'iframe',
- value: `<iframe src="${origin}/#model=${encodeURIComponent(item.glbUrl)}" width="480" height="600" style="border:0;border-radius:12px" allow="autoplay; xr-spatial-tracking" title="${name}"></iframe>`,
+ value: `<iframe src="${origin}/app#model=${encodeURIComponent(item.glbUrl)}" width="480" height="600" style="border:0;border-radius:12px" allow="autoplay; xr-spatial-tracking" title="${name}"></iframe>`,
rows: 3,
},
{ label: 'Link', key: 'link', value: detailUrl, rows: 1 },
diff --git a/public/discover/discover.js b/public/discover/discover.js
index b8ef58f9c..6d511b236 100644
--- a/public/discover/discover.js
+++ b/public/discover/discover.js
@@ -5,7 +5,7 @@
* Filters + infinite pagination via cursor.
* Clicking a card opens the on-chain token page on the source chain's
* explorer; clicking the 3D preview (when present) loads the GLB in the
- * main viewer via /#model=<url>.
+ * main viewer via /app#model=<url>.
*/
const CHAINS = [
@@ -595,7 +595,7 @@ function openEmbedModal({ chainId, agentId, name }) {
function openAvatarEmbedModal({ avatarId, glbUrl, name }) {
document.querySelector('.embed-modal')?.remove();
const origin = location.origin;
- const viewerUrl = `${origin}/#model=${encodeURIComponent(glbUrl)}`;
+ const viewerUrl = `${origin}/app#model=${encodeURIComponent(glbUrl)}`;
const apiUrl = `${origin}/api/avatars/${avatarId}`;
const displayName = name || 'Avatar';
diff --git a/public/discover/index.html b/public/discover/index.html
index bcb8cad93..bf4b97918 100644
--- a/public/discover/index.html
+++ b/public/discover/index.html
@@ -58,10 +58,6 @@
<main class="features-main explore-main">
<section class="explore-hero">
<div class="explore-hero-chips">
- <div class="explore-hero-chip">
- <span class="explore-hero-dot"></span>
- <span>ERC-8004 Agent Directory</span>
- </div>
<a
href="/my-agents"
class="explore-hero-chip explore-hero-chip--link"
diff --git a/public/home.css b/public/home.css
index fe7e2ccc1..0f564b764 100644
--- a/public/home.css
+++ b/public/home.css
@@ -1007,7 +1007,7 @@
radial-gradient(ellipse at 22% 25%, rgba(255, 175, 60, 0.22) 0%, transparent 60%),
radial-gradient(ellipse at 78% 65%, rgba(255, 100, 180, 0.13) 0%, transparent 55%),
radial-gradient(ellipse at 50% 100%, rgba(140, 80, 220, 0.12) 0%, transparent 70%),
- linear-gradient(180deg, #1a0e08 0%, #08070b 100%);
+ #000;
}
/* ── Star canvas ─────────────────────────────────────────────────────────── */
@@ -1290,7 +1290,7 @@
background:
radial-gradient(ellipse at 70% 30%, rgba(255, 180, 60, 0.15) 0%, transparent 55%),
radial-gradient(ellipse at 20% 75%, rgba(255, 215, 106, 0.08) 0%, transparent 55%),
- linear-gradient(180deg, #0c0a06 0%, #06070b 100%);
+ #000;
}
.h-layer-bg--mint {
@@ -1298,7 +1298,7 @@
radial-gradient(ellipse at 30% 40%, rgba(110, 231, 183, 0.12) 0%, transparent 55%),
radial-gradient(ellipse at 70% 60%, rgba(56, 189, 248, 0.1) 0%, transparent 50%),
radial-gradient(ellipse at 80% 75%, rgba(255, 215, 106, 0.04) 0%, transparent 55%),
- linear-gradient(180deg, #060e14 0%, #06070b 100%);
+ #000;
}
/* ── Act depth orbs ──────────────────────────────────────────────────────── */
diff --git a/public/pay/index.html b/public/pay/index.html
index aabf55fd3..02909bc53 100644
--- a/public/pay/index.html
+++ b/public/pay/index.html
@@ -36,11 +36,14 @@
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
+ html, body { height: 100%; }
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
- min-height: 100vh;
+ height: 100vh;
+ height: 100dvh;
display: flex;
flex-direction: column;
+ overflow: hidden;
-webkit-font-smoothing: antialiased;
}
a { color: var(--accent-2); }
@@ -97,12 +100,13 @@
/* Main */
main {
- flex: 1; display: grid;
+ flex: 1 1 0; display: grid;
grid-template-columns: 1.55fr 1fr;
gap: 0; min-height: 0;
+ overflow: hidden;
}
@media (max-width: 980px) {
- main { grid-template-columns: 1fr; }
+ main { grid-template-columns: 1fr; overflow-y: auto; }
aside.status { border-left: none !important; border-top: 1px solid var(--border); }
}
section.chat { display: flex; flex-direction: column; min-height: 0; }
@@ -1326,8 +1330,5 @@ if (params.get('list') === '1') queueMicrotask(() => run({ tool: 'tools/list', a
promptEl.focus();
</script>
-<div id="footer-container"></div>
-<script src="/footer.js" defer></script>
-
</body>
</html>
diff --git a/src/agent-eth-vanity-card.js b/src/agent-eth-vanity-card.js
index 10604be5a..a74bf0353 100644
--- a/src/agent-eth-vanity-card.js
+++ b/src/agent-eth-vanity-card.js
@@ -164,7 +164,7 @@ export function mountAgentEthVanityCard({ panel, identity, onAssigned }) {
state.record = null;
} else if (r.ok) {
const data = await r.json();
- state.record = data.data || data;
+ state.record = data && typeof data === 'object' && 'data' in data ? data.data : data;
} else {
state.err = `load failed (${r.status})`;
}
diff --git a/src/agent-home.js b/src/agent-home.js
index 432818f5b..795adbf45 100644
--- a/src/agent-home.js
+++ b/src/agent-home.js
@@ -51,6 +51,7 @@ export class AgentHome {
this.avatar = avatar;
this.skills = opts.skills || null;
this.memory = opts.memory || null;
+ this.isOwner = typeof opts.isOwner === 'boolean' ? opts.isOwner : null;
this._panel = null;
this._timeline = [];
@@ -208,7 +209,11 @@ export class AgentHome {
// Solana wallet for the agent. On success, lazy-mount the pump.fun
// card if it wasn't already mounted. The vanity grinder is a sibling
// card so the wallet UI stays focused on identity + balance.
- if (this.identity?.id && this.identity?.isOwner !== false) {
+ // Default-deny when ownership is unknown — visitor flows must not fire
+ // owner-only requests (/solana, /eth-vanity) and pollute the console
+ // with 401s. Caller can pass opts.isOwner to override identity state.
+ const isOwner = this.isOwner !== null ? this.isOwner : this.identity?.isOwner;
+ if (this.identity?.id && isOwner === true) {
let walletCard = null;
try {
walletCard = mountAgentSolanaWalletCard({
diff --git a/src/agent-identity.js b/src/agent-identity.js
index 76f9ebff4..cdc217c35 100644
--- a/src/agent-identity.js
+++ b/src/agent-identity.js
@@ -81,6 +81,9 @@ export class AgentIdentity {
get isRegistered() {
return Boolean(this._record?.isRegistered);
}
+ get isOwner() {
+ return this._record?.isOwner ?? null;
+ }
// ── Load + Save ───────────────────────────────────────────────────────────
@@ -340,6 +343,7 @@ function _makeDefault(existingId) {
meta: {},
createdAt: Date.now(),
isRegistered: false,
+ isOwner: false,
};
}
@@ -358,6 +362,13 @@ function _normalise(apiRecord) {
? new Date(apiRecord.created_at).getTime()
: apiRecord.createdAt || Date.now(),
isRegistered: Boolean(apiRecord.erc8004_agent_id || apiRecord.isRegistered),
+ // Server decorates owner-only fields (user_id, wallet_address, system_prompt,
+ // etc.) only when the requester owns the agent — see api/agents.js decorate().
+ // Use user_id presence as the canonical owner signal so visitor flows don't
+ // trigger owner-only requests (e.g. /solana, /eth-vanity) and get 401s.
+ isOwner: typeof apiRecord.isOwner === 'boolean'
+ ? apiRecord.isOwner
+ : Boolean(apiRecord.user_id),
backendConfirmed: true,
};
}
diff --git a/src/erc8004/agent-registry.js b/src/erc8004/agent-registry.js
index 5e49c314f..aecffa8d6 100644
--- a/src/erc8004/agent-registry.js
+++ b/src/erc8004/agent-registry.js
@@ -336,7 +336,7 @@ export function buildRegistrationJSON({
});
baseServices.push({
name: '3D',
- endpoint: `https://three.ws/#model=${encodeURIComponent(glbUrl)}`,
+ endpoint: `https://three.ws/app#model=${encodeURIComponent(glbUrl)}`,
version: '1.0',
});
}
diff --git a/src/marketplace.js b/src/marketplace.js
index feb3fa534..5a2a44592 100644
--- a/src/marketplace.js
+++ b/src/marketplace.js
@@ -999,7 +999,7 @@ function openAvatarModal(avatar) {
}
const view = $('avatar-modal-view');
- if (view) view.href = avatar.viewerUrl || (avatar.glbUrl ? `/#model=${encodeURIComponent(avatar.glbUrl)}` : '#');
+ if (view) view.href = avatar.viewerUrl || (avatar.glbUrl ? `/app#model=${encodeURIComponent(avatar.glbUrl)}` : '#');
const dl = $('avatar-modal-download');
if (dl) { dl.href = avatar.glbUrl || '#'; dl.download = (avatar.slug || avatar.avatarId || 'avatar') + '.glb'; }
@@ -1691,7 +1691,7 @@ async function loadAvatarDetail(id) {
if (avatar.name) p.set('avatar_name', avatar.name);
location.href = `/create?${p}`;
};
- if (viewBtn) viewBtn.href = avatar.viewerUrl || (avatar.glbUrl ? `/#model=${encodeURIComponent(avatar.glbUrl)}` : '#');
+ if (viewBtn) viewBtn.href = avatar.viewerUrl || (avatar.glbUrl ? `/app#model=${encodeURIComponent(avatar.glbUrl)}` : '#');
if (dlBtn) { dlBtn.href = avatar.glbUrl || '#'; dlBtn.setAttribute('download', (avatar.slug || avatar.avatarId || 'avatar') + '.glb'); }
// Update page title + meta for social sharing.
diff --git a/src/viewer.js b/src/viewer.js
index 7293eedcf..e01c07492 100644
--- a/src/viewer.js
+++ b/src/viewer.js
@@ -214,6 +214,14 @@ export class Viewer {
window.addEventListener('keydown', this._onKeyDown);
this.renderer.domElement.addEventListener('dblclick', this._onDblClick);
window.addEventListener('message', this._onMessage, false);
+
+ // Track the host element's own box (not just the window) so the canvas
+ // follows when the embed wrap is resized, the page lays out late, or a
+ // flex/grid parent reflows.
+ if (typeof ResizeObserver !== 'undefined') {
+ this._ro = new ResizeObserver(() => this._onResize());
+ this._ro.observe(this.el);
+ }
}
@@ -1612,6 +1620,11 @@ export class Viewer {
this._intersectionObserver = null;
}
+ if (this._ro) {
+ this._ro.disconnect();
+ this._ro = null;
+ }
+
this.clear();
if (this.mixer) {