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.

fix(embed): open anonymous agent-3d reads to any origin, stop sending cookies cross-site, and keep the floating widget and suggestion chips legible on light host pages

nirholas934654f0feed
diff --git a/api/_lib/http.js b/api/_lib/http.js
index b8f8be5f8..a643dfe7c 100644
--- a/api/_lib/http.js
+++ b/api/_lib/http.js
@@ -527,6 +527,22 @@ export function cors(
return false;
}
+// CORS for a read that the <agent-3d> embed makes from somebody else's website.
+//
+// The default allowlist is right for our own pages and wrong for an embed: the whole
+// point of the embed is that it runs on origins we have never heard of, so those
+// reads were blocked and logged a CORS error in every host site's console. A request
+// that carries no cookie and no authorization header can only ever see the public
+// answer, so it is safe to open to any origin. Anything authenticated keeps the
+// strict allowlist and its credentials.
+export function embedReadCors(req, res, { methods = 'GET,OPTIONS', authedMethods = methods } = {}) {
+ const wanted = req.method === 'OPTIONS' ? String(req.headers['access-control-request-method'] || 'GET').toUpperCase() : req.method;
+ const anonymous = !req.headers.cookie && !req.headers.authorization;
+ const asksForAuth = /\bauthorization\b/i.test(String(req.headers['access-control-request-headers'] || ''));
+ if (wanted === 'GET' && anonymous && !asksForAuth) return cors(req, res, { origins: '*', methods });
+ return cors(req, res, { methods: authedMethods, credentials: true });
+}
+
function isAllowedOrigin(origin, allowed) {
if (!allowed) {
if (origin === env.APP_ORIGIN) return true;
diff --git a/api/agents/[id]/skill-access.js b/api/agents/[id]/skill-access.js
index b4631b3ba..059442681 100644
--- a/api/agents/[id]/skill-access.js
+++ b/api/agents/[id]/skill-access.js
@@ -19,7 +19,7 @@
import { sql } from '../../_lib/db.js';
import { authenticateBearer, extractBearer, getSessionUser } from '../../_lib/auth.js';
-import { cors, error, json, method, wrap, rateLimited } from '../../_lib/http.js';
+import { embedReadCors, error, json, method, wrap, rateLimited } from '../../_lib/http.js';
import { clientIp, limits } from '../../_lib/rate-limit.js';
import { getSkillPrices, skillPriceMap } from '../../_lib/skill-price-cache.js';
import { viewerNftGatedSkills } from '../../_lib/nft-gate.js';
@@ -34,7 +34,7 @@ async function resolveAuth(req) {
}
export default wrap(async (req, res) => {
- if (cors(req, res, { methods: 'GET,OPTIONS', credentials: true })) return;
+ if (embedReadCors(req, res)) return;
if (!method(req, res, ['GET'])) return;
const rl = await limits.widgetRead(clientIp(req));
diff --git a/api/agents/_id/_sub.js b/api/agents/_id/_sub.js
index 8c771e44a..fbde93cec 100644
--- a/api/agents/_id/_sub.js
+++ b/api/agents/_id/_sub.js
@@ -6,7 +6,7 @@ import { Wallet } from 'ethers';
import { z } from 'zod';
import { sql } from '../../_lib/db.js';
import { getSessionUser, authenticateBearer, extractBearer } from '../../_lib/auth.js';
-import { cors, json, method, readJson, wrap, error, rateLimited } from '../../_lib/http.js';
+import { cors, json, method, readJson, wrap, error, rateLimited, embedReadCors } from '../../_lib/http.js';
import { limits, clientIp } from '../../_lib/rate-limit.js';
import { requireCsrf } from '../../_lib/csrf.js';
import { parse } from '../../_lib/validate.js';
@@ -321,7 +321,7 @@ export const handleAnimations = wrap(async (req, res, id) => {
// ── embed-policy ──────────────────────────────────────────────────────────────
export const handleEmbedPolicy = wrap(async (req, res, id) => {
- if (cors(req, res, { methods: 'GET,PUT,DELETE,OPTIONS', credentials: true })) return;
+ if (embedReadCors(req, res, { authedMethods: 'GET,PUT,DELETE,OPTIONS' })) return;
if (!method(req, res, ['GET', 'PUT', 'DELETE'])) return;
if (req.method === 'GET') {
diff --git a/src/element.js b/src/element.js
index b8104b6ca..077cf0261 100644
--- a/src/element.js
+++ b/src/element.js
@@ -371,8 +371,12 @@ const BASE_STYLE = `
@keyframes blink-cursor { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }
/* Suggestion chips when the conversation is empty */
.suggest-row { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 0 0; }
- .suggest-chip { font: 600 11px/1 var(--agent-chat-font); color: var(--agent-on-surface); background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.1); padding: 6px 10px; border-radius: 999px; cursor: pointer; transition: all .12s; }
- .suggest-chip:hover { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.18); }
+ /* A chip carries its own ground. It used to be a 6% white wash, which is only
+ legible over something dark: on a host page with a light background the
+ near-white label disappeared. */
+ .suggest-chip { font: 600 11px/1 var(--agent-chat-font); color: var(--agent-on-surface); background: var(--agent-surface); border: 1px solid rgba(255,255,255,.14); padding: 6px 10px; border-radius: 999px; cursor: pointer; transition: all .12s; }
+ .suggest-chip:hover { background: rgba(38, 48, 70, 0.96); border-color: rgba(255,255,255,.26); }
+ .suggest-chip:focus-visible { outline: 2px solid var(--agent-accent); outline-offset: 2px; }
/* Tool-call indicator near the bottom of the canvas */
.tool-indicator { position: absolute; left: 50%; bottom: 96px; transform: translateX(-50%); display: none; align-items: center; gap: 8px; padding: 6px 12px; background: var(--agent-surface); color: var(--agent-on-surface); border-radius: 999px; font: 12px var(--agent-chat-font); backdrop-filter: blur(12px); pointer-events: none; opacity: 0; transition: opacity .15s; z-index: 3; }
.tool-indicator[data-active="true"] { display: inline-flex; opacity: 1; }
@@ -487,6 +491,11 @@ const BASE_STYLE = `
border: 1px solid rgba(0, 0, 0, 0.08);
box-shadow: 0 4px 24px rgba(0, 0, 0, 0.18), 0 1px 3px rgba(0, 0, 0, 0.12);
}
+ /* The floating widget sits on top of a page we do not control, and its text is
+ light. With no background of its own it was white-on-cream on any light site,
+ so floating mode defaults to the dark surface. background="transparent" or
+ "light" still opt out. */
+ :host([mode="floating"]:not([background])) { background: #0b0d10; }
:host([background="dark"]) { background: #0b0d10; }
:host([background="light"]) { background: #f5f5f5; }
:host([background="light"]) .name-plate {
@@ -1785,8 +1794,10 @@ class Agent3DElement extends HTMLElement {
if (_backendId) {
try {
const detailBase = _scriptOrigin || window.location.origin;
+ // On somebody else's site our cookies are third-party and the public
+ // answer is all an embed can use, so only send them on our own origin.
const r = await fetch(`${detailBase}/api/agents/${_backendId}/skill-access`, {
- credentials: 'include',
+ credentials: detailBase === window.location.origin ? 'include' : 'omit',
});
if (r.ok) {
const a = (await r.json())?.data;
@@ -2037,7 +2048,7 @@ class Agent3DElement extends HTMLElement {
try {
const base = _scriptOrigin || window.location.origin;
const r = await fetch(`${base}/api/agents/${_backendId}/skill-access`, {
- credentials: 'include',
+ credentials: base === window.location.origin ? 'include' : 'omit',
});
if (r.ok) {
const a = (await r.json())?.data;