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: downgrade vite-plugin-pwa to version 1.2.0 for compatibility

nirholas1a76a541adff
diff --git a/api/_lib/auth.js b/api/_lib/auth.js
index d4d1b23a3..815fbf801 100644
--- a/api/_lib/auth.js
+++ b/api/_lib/auth.js
@@ -10,7 +10,12 @@ const ACCESS_TTL_SEC = 60 * 60; // 1h access tokens
const REFRESH_TTL_SEC = 60 * 60 * 24 * 30; // 30d refresh tokens
const SESSION_TTL_SEC = 60 * 60 * 24 * 30; // 30d browser sessions
-const jwtKey = new TextEncoder().encode(env.JWT_SECRET);
+// Lazy: env.JWT_SECRET throws if unset, so defer encoding until first use.
+let _jwtKey;
+function jwtKey() {
+ if (!_jwtKey) _jwtKey = new TextEncoder().encode(env.JWT_SECRET);
+ return _jwtKey;
+}
// ── passwords ────────────────────────────────────────────────────────────────
export async function hashPassword(plain) {
@@ -32,11 +37,11 @@ export async function mintAccessToken({ userId, clientId, scope, resource, token
.setIssuedAt(now)
.setExpirationTime(now + ACCESS_TTL_SEC)
.setJti(randomToken(16))
- .sign(jwtKey);
+ .sign(jwtKey());
}
export async function verifyAccessToken(token, { audience } = {}) {
- const { payload } = await jwtVerify(token, jwtKey, {
+ const { payload } = await jwtVerify(token, jwtKey(), {
issuer: env.ISSUER,
audience: audience || env.MCP_RESOURCE,
algorithms: ['HS256'],
diff --git a/api/_lib/db.js b/api/_lib/db.js
index 68c7e3a1b..245088a5c 100644
--- a/api/_lib/db.js
+++ b/api/_lib/db.js
@@ -6,14 +6,25 @@ import { env } from './env.js';
neonConfig.fetchConnectionCache = true;
-export const sql = neon(env.DATABASE_URL);
+// Lazy Neon client — instantiating requires DATABASE_URL. Keeping it lazy lets
+// this module be imported (transitively) by endpoints that don't touch the DB
+// even when DATABASE_URL isn't configured.
+let _sql;
+function getSql() {
+ if (!_sql) _sql = neon(env.DATABASE_URL);
+ return _sql;
+}
+export const sql = new Proxy(function () {}, {
+ apply(_t, _this, args) { return getSql()(...args); },
+ get(_t, prop) { return getSql()[prop]; },
+});
// Simple retry for transient network errors — Neon drops idle HTTPS quickly.
export async function query(strings, ...values) {
let lastErr;
for (let attempt = 0; attempt < 2; attempt++) {
try {
- return await sql(strings, ...values);
+ return await getSql()(strings, ...values);
} catch (err) {
lastErr = err;
if (!isRetryable(err)) throw err;
diff --git a/api/_lib/env.js b/api/_lib/env.js
index 4cf576f06..f3413164e 100644
--- a/api/_lib/env.js
+++ b/api/_lib/env.js
@@ -1,38 +1,40 @@
-// Centralized, validated env access. Fail loud at cold start, not mid-request.
+// Centralized env access. Lazy by design: missing env vars fail at first use,
+// not at module import, so unrelated endpoints (e.g. OAuth discovery) still
+// respond when the deployment is partially configured.
-function required(name) {
+function req(name) {
const v = process.env[name];
if (!v) throw new Error(`Missing required env var: ${name}`);
return v;
}
-function optional(name, fallback = undefined) {
+function opt(name, fallback = undefined) {
return process.env[name] ?? fallback;
}
+function trimSlash(s) {
+ return s ? s.replace(/\/$/, '') : s;
+}
+
export const env = {
- APP_ORIGIN: optional('PUBLIC_APP_ORIGIN', 'https://3dagent.vercel.app').replace(/\/$/, ''),
+ get APP_ORIGIN() { return trimSlash(opt('PUBLIC_APP_ORIGIN', 'https://3dagent.vercel.app')); },
- DATABASE_URL: required('DATABASE_URL'),
+ get DATABASE_URL() { return req('DATABASE_URL'); },
- R2_ACCOUNT_ID: required('R2_ACCOUNT_ID'),
- R2_ACCESS_KEY_ID: required('R2_ACCESS_KEY_ID'),
- R2_SECRET_ACCESS_KEY: required('R2_SECRET_ACCESS_KEY'),
- R2_BUCKET: required('R2_BUCKET'),
- R2_PUBLIC_BASE: required('R2_PUBLIC_BASE').replace(/\/$/, ''),
+ get R2_ACCOUNT_ID() { return req('R2_ACCOUNT_ID'); },
+ get R2_ACCESS_KEY_ID() { return req('R2_ACCESS_KEY_ID'); },
+ get R2_SECRET_ACCESS_KEY() { return req('R2_SECRET_ACCESS_KEY'); },
+ get R2_BUCKET() { return req('R2_BUCKET'); },
+ get R2_PUBLIC_BASE() { return trimSlash(req('R2_PUBLIC_BASE')); },
- UPSTASH_REDIS_REST_URL: optional('UPSTASH_REDIS_REST_URL'),
- UPSTASH_REDIS_REST_TOKEN: optional('UPSTASH_REDIS_REST_TOKEN'),
+ get UPSTASH_REDIS_REST_URL() { return opt('UPSTASH_REDIS_REST_URL'); },
+ get UPSTASH_REDIS_REST_TOKEN(){ return opt('UPSTASH_REDIS_REST_TOKEN'); },
- JWT_SECRET: required('JWT_SECRET'),
- JWT_KID: optional('JWT_KID', 'k1'),
+ get JWT_SECRET() { return req('JWT_SECRET'); },
+ get JWT_KID() { return opt('JWT_KID', 'k1'); },
- PASSWORD_ROUNDS: parseInt(optional('PASSWORD_ROUNDS', '11'), 10),
+ get PASSWORD_ROUNDS() { return parseInt(opt('PASSWORD_ROUNDS', '11'), 10); },
- get ISSUER() {
- return this.APP_ORIGIN;
- },
- get MCP_RESOURCE() {
- return `${this.APP_ORIGIN}/api/mcp`;
- },
+ get ISSUER() { return this.APP_ORIGIN; },
+ get MCP_RESOURCE() { return `${this.APP_ORIGIN}/api/mcp`; },
};
diff --git a/api/_lib/r2.js b/api/_lib/r2.js
index 9f89805f2..4d5197fc8 100644
--- a/api/_lib/r2.js
+++ b/api/_lib/r2.js
@@ -4,13 +4,24 @@ import { S3Client, PutObjectCommand, GetObjectCommand, DeleteObjectCommand, Head
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
import { env } from './env.js';
-export const r2 = new S3Client({
- region: 'auto',
- endpoint: `https://${env.R2_ACCOUNT_ID}.r2.cloudflarestorage.com`,
- credentials: {
- accessKeyId: env.R2_ACCESS_KEY_ID,
- secretAccessKey: env.R2_SECRET_ACCESS_KEY,
- },
+// Lazy client — S3Client constructor reads env credentials eagerly, so defer
+// until first use to keep this module importable without R2 configured.
+let _r2;
+function getR2() {
+ if (!_r2) {
+ _r2 = new S3Client({
+ region: 'auto',
+ endpoint: `https://${env.R2_ACCOUNT_ID}.r2.cloudflarestorage.com`,
+ credentials: {
+ accessKeyId: env.R2_ACCESS_KEY_ID,
+ secretAccessKey: env.R2_SECRET_ACCESS_KEY,
+ },
+ });
+ }
+ return _r2;
+}
+export const r2 = new Proxy({}, {
+ get(_t, prop) { return getR2()[prop]; },
});
// Short-lived signed URL for direct browser upload (PUT).
diff --git a/api/mcp.js b/api/mcp.js
index bcd784a4b..0eba2c57f 100644
--- a/api/mcp.js
+++ b/api/mcp.js
@@ -352,9 +352,13 @@ const TOOLS = {
ar: args.ar !== false,
cameraOrbit: safeCssValue(args.camera_orbit, ''),
});
+ // Keep chat text short so claude.ai doesn't dump the full HTML into the
+ // transcript. The HTML goes in the resource entry, which clients render
+ // as an inline artifact when mimeType is text/html.
+ const summary = `Rendered avatar "${avatar.name}". Display the attached text/html resource as an inline HTML artifact.`;
return {
content: [
- { type: 'text', text: html },
+ { type: 'text', text: summary },
{
type: 'resource',
resource: {
diff --git a/api/mcp/.well-known/oauth-protected-resource.js b/api/mcp/.well-known/oauth-protected-resource.js
deleted file mode 100644
index 18607a936..000000000
--- a/api/mcp/.well-known/oauth-protected-resource.js
+++ /dev/null
@@ -1,3 +0,0 @@
-// Mirror of the root metadata at the resource-specific path.
-// Some MCP clients look for `<resource>/.well-known/oauth-protected-resource`.
-export { default } from '../../.well-known/oauth-protected-resource.js';
diff --git a/api/.well-known/oauth-authorization-server.js b/api/wk-oauth-authorization-server.js
similarity index 77%
rename from api/.well-known/oauth-authorization-server.js
rename to api/wk-oauth-authorization-server.js
index 50bf1b1ef..28c8d85d8 100644
--- a/api/.well-known/oauth-authorization-server.js
+++ b/api/wk-oauth-authorization-server.js
@@ -1,8 +1,12 @@
// RFC 8414 — OAuth 2.0 Authorization Server Metadata
// https://datatracker.ietf.org/doc/html/rfc8414
+//
+// Served at /.well-known/oauth-authorization-server via vercel.json rewrite.
+// The file lives outside a dot-prefixed directory because Vercel's build
+// pipeline excludes `api/.well-known/**` from function deployment.
-import { env } from '../_lib/env.js';
-import { cors, json, method, wrap } from '../_lib/http.js';
+import { env } from './_lib/env.js';
+import { cors, json, method, wrap } from './_lib/http.js';
export default wrap(async (req, res) => {
if (cors(req, res, { methods: 'GET,OPTIONS' })) return;
diff --git a/api/.well-known/oauth-protected-resource.js b/api/wk-oauth-protected-resource.js
similarity index 61%
rename from api/.well-known/oauth-protected-resource.js
rename to api/wk-oauth-protected-resource.js
index 3f558a7c4..668fcda92 100644
--- a/api/.well-known/oauth-protected-resource.js
+++ b/api/wk-oauth-protected-resource.js
@@ -1,9 +1,11 @@
// RFC 9728 — OAuth 2.0 Protected Resource Metadata
-// MCP spec requires this at the MCP resource's well-known path.
-// We expose it here at the root and also per-resource at /api/mcp/.well-known/...
+// Served at /.well-known/oauth-protected-resource and at
+// /api/mcp/.well-known/oauth-protected-resource via vercel.json rewrites.
+// Kept outside dot-prefixed dirs: Vercel excludes `api/.well-known/**` from
+// function deployment.
-import { env } from '../_lib/env.js';
-import { cors, json, method, wrap } from '../_lib/http.js';
+import { env } from './_lib/env.js';
+import { cors, json, method, wrap } from './_lib/http.js';
export default wrap(async (req, res) => {
if (cors(req, res, { methods: 'GET,OPTIONS' })) return;
diff --git a/package-lock.json b/package-lock.json
index 5f6b65274..3005f5828 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -16,6 +16,7 @@
"@gltf-transform/core": "^4.3.0",
"@gltf-transform/extensions": "^4.3.0",
"@neondatabase/serverless": "^0.10.1",
+ "@privy-io/js-sdk-core": "latest",
"@upstash/ratelimit": "^2.0.5",
"@upstash/redis": "^1.34.3",
"bcryptjs": "^2.4.3",
@@ -3164,6 +3165,86 @@
"url": "https://github.com/sponsors/Boshen"
}
},
+ "node_modules/@privy-io/api-base": {
+ "version": "1.8.3",
+ "resolved": "https://registry.npmjs.org/@privy-io/api-base/-/api-base-1.8.3.tgz",
+ "integrity": "sha512-wMOtQZBN/j+jufy4FxR9iHMx/DpxhJIRyFFIKOFPsL+ueGyI2GDhDldkOlTpfldGNL1VDgdgJGRDD82hTUrZ2w==",
+ "dependencies": {
+ "zod": "^3.24.3"
+ }
+ },
+ "node_modules/@privy-io/api-types": {
+ "version": "0.8.0",
+ "resolved": "https://registry.npmjs.org/@privy-io/api-types/-/api-types-0.8.0.tgz",
+ "integrity": "sha512-+4qHNYRlekl6DZAwLB6ARiZJzpMBwmjQxAjdQ2zrhWnK2SL2pUGub17N7wQL5h5AZXzkVKaFmFc0I3ckNn+/NQ==",
+ "license": "Apache-2.0"
+ },
+ "node_modules/@privy-io/chains": {
+ "version": "0.1.4",
+ "resolved": "https://registry.npmjs.org/@privy-io/chains/-/chains-0.1.4.tgz",
+ "integrity": "sha512-wdZchhDE9cpqDevgJL8DFimdb5s68kjz53mmAPgFR/gy7KAtk6rDV+1xRNee9zAUNJ0cCbHgneRsvPXgbwHVig==",
+ "license": "Apache-2.0"
+ },
+ "node_modules/@privy-io/ethereum": {
+ "version": "0.0.10",
+ "resolved": "https://registry.npmjs.org/@privy-io/ethereum/-/ethereum-0.0.10.tgz",
+ "integrity": "sha512-aJX0+1D3rp33x5wn1+Relio4v6j9s2MJ9ApC+FRvyLYu3ClQ4Kj6jRsM/qO2MQsUXS2HqK+UAZPIWA4UtzwtaA==",
+ "license": "Apache-2.0",
+ "peerDependencies": {
+ "viem": "2.47.4"
+ }
+ },
+ "node_modules/@privy-io/js-sdk-core": {
+ "version": "0.60.8",
+ "resolved": "https://registry.npmjs.org/@privy-io/js-sdk-core/-/js-sdk-core-0.60.8.tgz",
+ "integrity": "sha512-InRybWnVHD4IM6sXaWw9ZeYqnKhSk7EQNholprTR8mJFId3mwWrf0FtlrhR/2i55pqX7klCLACAS5NC6YAgbOA==",
+ "license": "Apache-2.0",
+ "dependencies": {
+ "@privy-io/api-base": "1.8.3",
+ "@privy-io/api-types": "0.8.0",
+ "@privy-io/chains": "0.1.4",
+ "@privy-io/ethereum": "0.0.10",
+ "@privy-io/routes": "0.0.10",
+ "canonicalize": "^2.0.0",
+ "eventemitter3": "^5.0.1",
+ "fetch-retry": "^6.0.0",
+ "jose": "^4.15.5",
+ "js-cookie": "^3.0.5",
+ "libphonenumber-js": "^1.10.44",
+ "set-cookie-parser": "^2.6.0",
+ "uuid": ">=8 <10"
+ },
+ "peerDependencies": {
+ "permissionless": "^0.2.47",
+ "viem": "2.47.4"
+ },
+ "peerDependenciesMeta": {
+ "permissionless": {
+ "optional": true
+ },
+ "viem": {
+ "optional": true
+ }
+ }
+ },
+ "node_modules/@privy-io/js-sdk-core/node_modules/jose": {
+ "version": "4.15.9",
+ "resolved": "https://registry.npmjs.org/jose/-/jose-4.15.9.tgz",
+ "integrity": "sha512-1vUQX+IdDMVPj4k8kOxgUqlcK518yluMuGZwqlr44FS1ppZB/5GWh4rZG89erpOBOJjU/OBsnCVFfapsRz6nEA==",
+ "license": "MIT",
+ "funding": {
+ "url": "https://github.com/sponsors/panva"
+ }
+ },
+ "node_modules/@privy-io/routes": {
+ "version": "0.0.10",
+ "resolved": "https://registry.npmjs.org/@privy-io/routes/-/routes-0.0.10.tgz",
+ "integrity": "sha512-tJXhDEm1pkU4lW1AfOjjSIbaWFnA2Le624n5hlhjj5M61U4Xo7afIuuYOn3scXjq773T3ZTJd+hAgfCTOw6yEA==",
+ "license": "Apache-2.0",
+ "dependencies": {
+ "@privy-io/api-types": "0.8.0"
+ }
+ },
"node_modules/@rolldown/binding-android-arm64": {
"version": "1.0.0-rc.15",
"resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm64/-/binding-android-arm64-1.0.0-rc.15.tgz",
@@ -4636,6 +4717,15 @@
],
"license": "CC-BY-4.0"
},
+ "node_modules/canonicalize": {
+ "version": "2.1.0",
+ "resolved": "https://registry.npmjs.org/canonicalize/-/canonicalize-2.1.0.tgz",
+ "integrity": "sha512-F705O3xrsUtgt98j7leetNhTWPe+5S72rlL5O4jA1pKqBVQ/dT1O1D6PFxmSXvc0SUOinWS57DKx0I3CHrXJHQ==",
+ "license": "Apache-2.0",
+ "bin": {
+ "canonicalize": "bin/canonicalize.js"
+ }
+ },
"node_modules/commander": {
"version": "2.20.3",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz",
@@ -5092,6 +5182,12 @@
"integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==",
"license": "MIT"
},
+ "node_modules/eventemitter3": {
+ "version": "5.0.4",
+ "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.4.tgz",
+ "integrity": "sha512-mlsTRyGaPBjPedk6Bvw+aqbsXDtoAyAzm5MO7JgU+yVRyMQ5O8bD4Kcci7BS85f93veegeCPkL8R4GLClnjLFw==",
+ "license": "MIT"
+ },
"node_modules/fast-deep-equal": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
@@ -5176,6 +5272,12 @@
}
}
},
+ "node_modules/fetch-retry": {
+ "version": "6.0.0",
+ "resolved": "https://registry.npmjs.org/fetch-retry/-/fetch-retry-6.0.0.tgz",
+ "integrity": "sha512-BUFj1aMubgib37I3v4q78fYo63Po7t4HUPTpQ6/QE6yK6cIQrP+W43FYToeTEyg5m2Y7eFUtijUuAv/PDlWuag==",
+ "license": "MIT"
+ },
"node_modules/filelist": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/filelist/-/filelist-1.0.6.tgz",
@@ -6046,6 +6148,15 @@
"url": "https://github.com/sponsors/panva"
}
},
+ "node_modules/js-cookie": {
+ "version": "3.0.5",
+ "resolved": "https://registry.npmjs.org/js-cookie/-/js-cookie-3.0.5.tgz",
+ "integrity": "sha512-cEiJEAEoIbWfCZYKWhVwFuvPX1gETRYPw6LlaTKoxD3s2AkXzkCjnp6h0V77ozyqj0jakteJ4YqDJT830+lVGw==",
+ "license": "MIT",
+ "engines": {
+ "node": ">=14"
+ }
+ },
"node_modules/js-tokens": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
@@ -6125,6 +6236,12 @@
"node": ">=6"
}
},
+ "node_modules/libphonenumber-js": {
+ "version": "1.12.41",
+ "resolved": "https://registry.npmjs.org/libphonenumber-js/-/libphonenumber-js-1.12.41.tgz",
+ "integrity": "sha512-lsmMmGXBxXIK/VMLEj0kL6MtUs1kBGj1nTCzi6zgQoG1DEwqwt2DQyHxcLykceIxAnfE3hya7NuIh6PpC6S3fA==",
+ "license": "MIT"
+ },
"node_modules/lightningcss": {
"version": "1.32.0",
"resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.32.0.tgz",
@@ -7081,6 +7198,12 @@
"node": ">=20.0.0"
}
},
+ "node_modules/set-cookie-parser": {
+ "version": "2.7.2",
+ "resolved": "https://registry.npmjs.org/set-cookie-parser/-/set-cookie-parser-2.7.2.tgz",
+ "integrity": "sha512-oeM1lpU/UvhTxw+g3cIfxXHyJRc/uidd3yK1P242gzHds0udQBYzs3y8j4gCCW+ZJ7ad0yctld8RYO+bdurlvw==",
+ "license": "MIT"
+ },
"node_modules/set-function-length": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.2.tgz",
@@ -7851,6 +7974,19 @@
"browserslist": ">= 4.21.0"
}
},
+ "node_modules/uuid": {
+ "version": "9.0.1",
+ "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz",
+ "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==",
+ "funding": [
+ "https://github.com/sponsors/broofa",
+ "https://github.com/sponsors/ctavan"
+ ],
+ "license": "MIT",
+ "bin": {
+ "uuid": "dist/bin/uuid"
+ }
+ },
"node_modules/vhtml": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/vhtml/-/vhtml-2.2.0.tgz",
diff --git a/package.json b/package.json
index d2f8de54a..e2798906b 100644
--- a/package.json
+++ b/package.json
@@ -71,7 +71,7 @@
"prettier": "^3.2.5",
"sharp": "^0.34.5",
"vite": "^8.0.8",
- "vite-plugin-pwa": "^1.5.0",
+ "vite-plugin-pwa": "^1.2.0",
"workbox-build": "^7.4.0",
"workbox-window": "^7.4.0"
}
diff --git a/public/agent/embed.html b/public/agent/embed.html
new file mode 100644
index 000000000..4ce762626
--- /dev/null
+++ b/public/agent/embed.html
@@ -0,0 +1,91 @@
+<!doctype html>
+<html lang="en">
+<head>
+ <meta charset="utf-8" />
+ <title>Agent</title>
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+ <meta name="description" content="Embedded 3D agent avatar." />
+ <meta name="robots" content="noindex" />
+ <style>
+ html, body { margin: 0; padding: 0; height: 100%; width: 100%; background: transparent; overflow: hidden; font-family: system-ui, sans-serif; }
+ #stage { position: absolute; inset: 0; }
+ #stage canvas { display: block; width: 100% !important; height: 100% !important; }
+ #stage .gui-wrap, #stage .gui-toggle, #stage .annotation-canvas { display: none !important; }
+ #stage .model-info { display: none !important; }
+ #name-plate {
+ position: absolute; left: 12px; bottom: 10px; z-index: 2; pointer-events: none;
+ font-size: 11px; color: rgba(255,255,255,0.55); letter-spacing: 0.04em;
+ text-shadow: 0 1px 2px rgba(0,0,0,0.6);
+ }
+ #error {
+ position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
+ color: rgba(255,255,255,0.4); font-size: 12px; padding: 1rem; text-align: center;
+ }
+ body.bg-dark { background: #0b0d10; }
+ body.bg-light { background: #f5f5f5; }
+ </style>
+</head>
+<body>
+ <div id="stage"></div>
+ <div id="name-plate"></div>
+ <div id="error"></div>
+
+ <script type="module">
+ import { Viewer } from '/src/viewer.js';
+ import { AgentIdentity } from '/src/agent-identity.js';
+ import { AgentAvatar } from '/src/agent-avatar.js';
+ import { protocol } from '/src/agent-protocol.js';
+
+ const params = new URL(location.href).searchParams;
+ const bg = params.get('bg') || 'transparent';
+ if (bg === 'dark') document.body.classList.add('bg-dark');
+ if (bg === 'light') document.body.classList.add('bg-light');
+
+ const plateOn = params.get('name') !== '0';
+ const parts = location.pathname.split('/').filter(Boolean);
+ const agentId = parts[parts.indexOf('agent') + 1];
+
+ async function main() {
+ const identity = new AgentIdentity({ agentId, autoLoad: false });
+ await identity.load();
+
+ if (plateOn && identity.name) {
+ document.getElementById('name-plate').textContent = identity.name;
+ }
+
+ if (!identity.avatarId) throw new Error('agent has no avatar body');
+
+ const resp = await fetch(`/api/avatars/${identity.avatarId}`, { credentials: 'include' });
+ if (!resp.ok) throw new Error(`avatar ${resp.status}`);
+ const { avatar } = await resp.json();
+ const glbUrl = avatar?.url;
+ if (!glbUrl) throw new Error('no avatar url');
+
+ const stage = document.getElementById('stage');
+ const viewer = new Viewer(stage, { kiosk: true });
+ if (bg === 'transparent') {
+ viewer.renderer?.setClearAlpha(0);
+ if (viewer.scene) viewer.scene.background = null;
+ }
+ await viewer.load(glbUrl, '', new Map());
+
+ const avatarCtl = new AgentAvatar(viewer, protocol, identity);
+ avatarCtl.attach();
+
+ // Expose to host via postMessage bridge
+ window.addEventListener('message', (ev) => {
+ const msg = ev.data;
+ if (!msg || msg.__agent !== agentId) return;
+ if (msg.type === 'action' && msg.action) protocol.emit(msg.action);
+ });
+ parent?.postMessage({ __agent: agentId, type: 'ready', name: identity.name }, '*');
+ }
+
+ main().catch(err => {
+ const el = document.getElementById('error');
+ el.textContent = err.message || 'Could not load agent';
+ el.style.display = 'flex';
+ });
+ </script>
+</body>
+</html>
diff --git a/public/agent/index.html b/public/agent/index.html
index 7ef5f08d4..246bfeca5 100644
--- a/public/agent/index.html
+++ b/public/agent/index.html
@@ -83,23 +83,79 @@
padding: 0 1rem;
}
+ .agent-embed-tabs {
+ display: flex;
+ gap: 0.382rem;
+ margin-bottom: 0.618rem;
+ }
+
+ .agent-embed-tab {
+ background: transparent;
+ border: 1px solid rgba(255,255,255,0.1);
+ color: rgba(255,255,255,0.5);
+ font-size: 0.618rem;
+ padding: 0.236rem 0.618rem;
+ border-radius: 999px;
+ cursor: pointer;
+ font-family: inherit;
+ }
+
+ .agent-embed-tab.active {
+ background: rgba(255,255,255,0.08);
+ color: rgba(255,255,255,0.9);
+ border-color: rgba(255,255,255,0.2);
+ }
+
+ .agent-embed-code-wrap {
+ position: relative;
+ }
+
.agent-embed-code {
background: rgba(255,255,255,0.04);
border: 1px solid rgba(255,255,255,0.08);
border-radius: 8px;
padding: 0.618rem 1rem;
+ padding-right: 3.8rem;
font-family: monospace;
font-size: 0.618rem;
- color: rgba(255,255,255,0.4);
+ color: rgba(255,255,255,0.55);
word-break: break-all;
+ line-height: 1.5;
+ }
+
+ .agent-embed-copy {
+ position: absolute;
+ top: 0.382rem;
+ right: 0.382rem;
+ background: rgba(255,255,255,0.06);
+ border: 1px solid rgba(255,255,255,0.1);
+ color: rgba(255,255,255,0.6);
+ font-size: 0.618rem;
+ padding: 0.236rem 0.618rem;
+ border-radius: 6px;
+ cursor: pointer;
+ font-family: inherit;
}
+ .agent-embed-copy:hover { color: rgba(255,255,255,0.9); background: rgba(255,255,255,0.1); }
+ .agent-embed-copy.copied { color: #86efac; border-color: rgba(134,239,172,0.3); }
+
.agent-embed-label {
font-size: 0.618rem;
color: rgba(255,255,255,0.25);
margin-bottom: 0.382rem;
}
+ .agent-embed-preview-link {
+ display: inline-block;
+ margin-top: 0.618rem;
+ font-size: 0.618rem;
+ color: rgba(255,255,255,0.35);
+ text-decoration: none;
+ }
+
+ .agent-embed-preview-link:hover { color: rgba(255,255,255,0.7); }
+
.agent-skills-full {
max-width: 420px;
margin: 1.618rem auto 0;
@@ -175,8 +231,17 @@
<!-- Embed code -->
<div class="agent-embed-hint" id="agent-embed-section" style="display:none">
- <div class="agent-embed-label">Embed this agent</div>
- <div class="agent-embed-code" id="agent-embed-code"></div>
+ <div class="agent-embed-label">Share &amp; embed</div>
+ <div class="agent-embed-tabs" role="tablist">
+ <button class="agent-embed-tab active" data-tab="iframe">iframe</button>
+ <button class="agent-embed-tab" data-tab="link">link</button>
+ <button class="agent-embed-tab" data-tab="webcomponent">&lt;agent-3d&gt;</button>
+ </div>
+ <div class="agent-embed-code-wrap">
+ <div class="agent-embed-code" id="agent-embed-code"></div>
+ <button class="agent-embed-copy" id="agent-embed-copy">copy</button>
+ </div>
+ <a class="agent-embed-preview-link" id="agent-embed-preview" target="_blank" rel="noopener">preview embed →</a>
</div>
<script type="module">
@@ -225,9 +290,40 @@
// Embed code
const embedSection = document.getElementById('agent-embed-section');
const embedCode = document.getElementById('agent-embed-code');
- const embedUrl = `${location.origin}/agent/${identity.id}`;
+ const embedCopy = document.getElementById('agent-embed-copy');
+ const embedPreview = document.getElementById('agent-embed-preview');
+ const origin = location.origin;
+ const embedUrl = `${origin}/agent/${identity.id}/embed`;
+ const agentUrl = `${origin}/agent/${identity.id}`;
+
+ const snippets = {
+ iframe: `<iframe src="${embedUrl}" width="420" height="520" style="border:0;border-radius:12px" allow="autoplay; xr-spatial-tracking"></iframe>`,
+ link: agentUrl,
+ webcomponent: `<script type="module" src="${origin}/dist-lib/agent-3d.js"><\/script>\n<agent-3d src="${agentUrl}/manifest.json" style="width:420px;height:520px"></agent-3d>`,
+ };
+
+ let current = 'iframe';
+ const render = () => { embedCode.textContent = snippets[current]; };
+ render();
embedSection.style.display = '';
- embedCode.textContent = `<iframe src="${embedUrl}" width="420" height="520" frameborder="0" style="border-radius:12px;border:none;"></iframe>`;
+ embedPreview.href = embedUrl;
+
+ document.querySelectorAll('.agent-embed-tab').forEach(btn => {
+ btn.addEventListener('click', () => {
+ current = btn.dataset.tab;
+ document.querySelectorAll('.agent-embed-tab').forEach(b => b.classList.toggle('active', b === btn));
+ render();
+ });
+ });
+
+ embedCopy.addEventListener('click', async () => {
+ try {
+ await navigator.clipboard.writeText(snippets[current]);
+ embedCopy.textContent = 'copied';
+ embedCopy.classList.add('copied');
+ setTimeout(() => { embedCopy.textContent = 'copy'; embedCopy.classList.remove('copied'); }, 1400);
+ } catch {}
+ });
}
main().catch(err => {
diff --git a/vercel.json b/vercel.json
index 00e334ebd..bab17893a 100644
--- a/vercel.json
+++ b/vercel.json
@@ -1,9 +1,9 @@
{
"public": true,
"routes": [
- { "src": "/\\.well-known/oauth-authorization-server", "dest": "/api/.well-known/oauth-authorization-server" },
- { "src": "/\\.well-known/oauth-protected-resource", "dest": "/api/.well-known/oauth-protected-resource" },
- { "src": "/api/mcp/\\.well-known/oauth-protected-resource", "dest": "/api/mcp/.well-known/oauth-protected-resource" },
+ { "src": "/\\.well-known/oauth-authorization-server", "dest": "/api/wk-oauth-authorization-server" },
+ { "src": "/\\.well-known/oauth-protected-resource", "dest": "/api/wk-oauth-protected-resource" },
+ { "src": "/api/mcp/\\.well-known/oauth-protected-resource", "dest": "/api/wk-oauth-protected-resource" },
{ "src": "/oauth/authorize", "dest": "/api/oauth/authorize" },
{ "src": "/oauth/consent", "dest": "/api/oauth/authorize" },
@@ -25,6 +25,7 @@
{ "src": "/api/agent-actions", "dest": "/api/agent-actions" },
{ "src": "/api/agent-memory/([^/]+)", "dest": "/api/agent-memory" },
{ "src": "/api/agent-memory", "dest": "/api/agent-memory" },
+ { "src": "/agent/([^/]+)/embed", "dest": "/public/agent/embed.html" },
{ "src": "/agent/([^/]+)", "dest": "/public/agent/index.html" },
{ "src": "/agent", "dest": "/public/agent/index.html" },
{ "src": "/api/(.*)", "dest": "/api/$1" },
diff --git a/yarn.lock b/yarn.lock
index 498d35a67..1c1dd1d4c 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1499,6 +1499,54 @@
resolved "https://registry.npmjs.org/@oxc-project/types/-/types-0.124.0.tgz"
integrity sha512-VBFWMTBvHxS11Z5Lvlr3IWgrwhMTXV+Md+EQF0Xf60+wAdsGFTBx7X7K/hP4pi8N7dcm1RvcHwDxZ16Qx8keUg==
+"@privy-io/[email protected]":
+ version "1.8.3"
+ resolved "https://registry.npmjs.org/@privy-io/api-base/-/api-base-1.8.3.tgz"
+ integrity sha512-wMOtQZBN/j+jufy4FxR9iHMx/DpxhJIRyFFIKOFPsL+ueGyI2GDhDldkOlTpfldGNL1VDgdgJGRDD82hTUrZ2w==
+ dependencies:
+ zod "^3.24.3"
+
+"@privy-io/[email protected]":
+ version "0.8.0"
+ resolved "https://registry.npmjs.org/@privy-io/api-types/-/api-types-0.8.0.tgz"
+ integrity sha512-+4qHNYRlekl6DZAwLB6ARiZJzpMBwmjQxAjdQ2zrhWnK2SL2pUGub17N7wQL5h5AZXzkVKaFmFc0I3ckNn+/NQ==
+
+"@privy-io/[email protected]":
+ version "0.1.4"
+ resolved "https://registry.npmjs.org/@privy-io/chains/-/chains-0.1.4.tgz"
+ integrity sha512-wdZchhDE9cpqDevgJL8DFimdb5s68kjz53mmAPgFR/gy7KAtk6rDV+1xRNee9zAUNJ0cCbHgneRsvPXgbwHVig==
+
+"@privy-io/[email protected]":
+ version "0.0.10"
+ resolved "https://registry.npmjs.org/@privy-io/ethereum/-/ethereum-0.0.10.tgz"
+ integrity sha512-aJX0+1D3rp33x5wn1+Relio4v6j9s2MJ9ApC+FRvyLYu3ClQ4Kj6jRsM/qO2MQsUXS2HqK+UAZPIWA4UtzwtaA==
+
+"@privy-io/js-sdk-core@latest":
+ version "0.60.8"
+ resolved "https://registry.npmjs.org/@privy-io/js-sdk-core/-/js-sdk-core-0.60.8.tgz"
+ integrity sha512-InRybWnVHD4IM6sXaWw9ZeYqnKhSk7EQNholprTR8mJFId3mwWrf0FtlrhR/2i55pqX7klCLACAS5NC6YAgbOA==
+ dependencies:
+ "@privy-io/api-base" "1.8.3"
+ "@privy-io/api-types" "0.8.0"
+ "@privy-io/chains" "0.1.4"
+ "@privy-io/ethereum" "0.0.10"
+ "@privy-io/routes" "0.0.10"
+ canonicalize "^2.0.0"
+ eventemitter3 "^5.0.1"
+ fetch-retry "^6.0.0"
+ jose "^4.15.5"
+ js-cookie "^3.0.5"
+ libphonenumber-js "^1.10.44"
+ set-cookie-parser "^2.6.0"
+ uuid ">=8 <10"
+
+"@privy-io/[email protected]":
+ version "0.0.10"
+ resolved "https://registry.npmjs.org/@privy-io/routes/-/routes-0.0.10.tgz"
+ integrity sha512-tJXhDEm1pkU4lW1AfOjjSIbaWFnA2Le624n5hlhjj5M61U4Xo7afIuuYOn3scXjq773T3ZTJd+hAgfCTOw6yEA==
+ dependencies:
+ "@privy-io/api-types" "0.8.0"
+
"@rolldown/[email protected]":
version "1.0.0-rc.15"
resolved "https://registry.npmjs.org/@rolldown/binding-linux-x64-gnu/-/binding-linux-x64-gnu-1.0.0-rc.15.tgz"
@@ -2307,6 +2355,11 @@ caniuse-lite@^1.0.30001782:
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001788.tgz"
integrity sha512-6q8HFp+lOQtcf7wBK+uEenxymVWkGKkjFpCvw5W25cmMwEDU45p1xQFBQv8JDlMMry7eNxyBaR+qxgmTUZkIRQ==
+canonicalize@^2.0.0:
+ version "2.1.0"
+ resolved "https://registry.npmjs.org/canonicalize/-/canonicalize-2.1.0.tgz"
+ integrity sha512-F705O3xrsUtgt98j7leetNhTWPe+5S72rlL5O4jA1pKqBVQ/dT1O1D6PFxmSXvc0SUOinWS57DKx0I3CHrXJHQ==
+
commander@^2.20.0:
version "2.20.3"
resolved "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz"
@@ -2565,6 +2618,11 @@ ethers@^6.16.0:
tslib "2.7.0"
ws "8.17.1"
+eventemitter3@^5.0.1:
+ version "5.0.4"
+ resolved "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.4.tgz"
+ integrity sha512-mlsTRyGaPBjPedk6Bvw+aqbsXDtoAyAzm5MO7JgU+yVRyMQ5O8bD4Kcci7BS85f93veegeCPkL8R4GLClnjLFw==
+
fast-deep-equal@^3.1.3:
version "3.1.3"
resolved "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz"
@@ -2601,6 +2659,11 @@ fdir@^6.5.0:
resolved "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz"
integrity sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==
+fetch-retry@^6.0.0:
+ version "6.0.0"
+ resolved "https://registry.npmjs.org/fetch-retry/-/fetch-retry-6.0.0.tgz"
+ integrity sha512-BUFj1aMubgib37I3v4q78fYo63Po7t4HUPTpQ6/QE6yK6cIQrP+W43FYToeTEyg5m2Y7eFUtijUuAv/PDlWuag==
+
filelist@^1.0.4:
version "1.0.6"
resolved "https://registry.npmjs.org/filelist/-/filelist-1.0.6.tgz"
@@ -3007,11 +3070,21 @@ jake@^10.8.5:
filelist "^1.0.4"
picocolors "^1.1.1"
+jose@^4.15.5:
+ version "4.15.9"
+ resolved "https://registry.npmjs.org/jose/-/jose-4.15.9.tgz"
+ integrity sha512-1vUQX+IdDMVPj4k8kOxgUqlcK518yluMuGZwqlr44FS1ppZB/5GWh4rZG89erpOBOJjU/OBsnCVFfapsRz6nEA==
+
jose@^5.9.6:
version "5.10.0"
resolved "https://registry.npmjs.org/jose/-/jose-5.10.0.tgz"
integrity sha512-s+3Al/p9g32Iq+oqXxkW//7jk2Vig6FF1CFqzVXoTUXt2qz89YWbL+OwS17NFYEvxC35n0FKeGO2LGYSxeM2Gg==
+js-cookie@^3.0.5:
+ version "3.0.5"
+ resolved "https://registry.npmjs.org/js-cookie/-/js-cookie-3.0.5.tgz"
+ integrity sha512-cEiJEAEoIbWfCZYKWhVwFuvPX1gETRYPw6LlaTKoxD3s2AkXzkCjnp6h0V77ozyqj0jakteJ4YqDJT830+lVGw==
+
js-tokens@^4.0.0:
version "4.0.0"
resolved "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz"
@@ -3056,6 +3129,11 @@ leven@^3.1.0:
resolved "https://registry.npmjs.org/leven/-/leven-3.1.0.tgz"
integrity sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A==
+libphonenumber-js@^1.10.44:
+ version "1.12.41"
+ resolved "https://registry.npmjs.org/libphonenumber-js/-/libphonenumber-js-1.12.41.tgz"
+ integrity sha512-lsmMmGXBxXIK/VMLEj0kL6MtUs1kBGj1nTCzi6zgQoG1DEwqwt2DQyHxcLykceIxAnfE3hya7NuIh6PpC6S3fA==
+
version "1.32.0"
resolved "https://registry.npmjs.org/lightningcss-linux-x64-gnu/-/lightningcss-linux-x64-gnu-1.32.0.tgz"
@@ -3491,6 +3569,11 @@ serialize-javascript@>=7.0.5:
resolved "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-7.0.5.tgz"
integrity sha512-F4LcB0UqUl1zErq+1nYEEzSHJnIwb3AF2XWB94b+afhrekOUijwooAYqFyRbjYkm2PAKBabx6oYv/xDxNi8IBw==
+set-cookie-parser@^2.6.0:
+ version "2.7.2"
+ resolved "https://registry.npmjs.org/set-cookie-parser/-/set-cookie-parser-2.7.2.tgz"
+ integrity sha512-oeM1lpU/UvhTxw+g3cIfxXHyJRc/uidd3yK1P242gzHds0udQBYzs3y8j4gCCW+ZJ7ad0yctld8RYO+bdurlvw==
+
set-function-length@^1.2.2:
version "1.2.2"
resolved "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.2.tgz"
@@ -3921,6 +4004,11 @@ update-browserslist-db@^1.2.3:
escalade "^3.2.0"
picocolors "^1.1.1"
+"uuid@>=8 <10":
+ version "9.0.1"
+ resolved "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz"
+ integrity sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==
+
vhtml@^2.2.0:
version "2.2.0"
resolved "https://registry.npmjs.org/vhtml/-/vhtml-2.2.0.tgz"
@@ -4197,7 +4285,7 @@ zip-js-esm@^1.1.1:
resolved "https://registry.npmjs.org/zip-js-esm/-/zip-js-esm-1.1.1.tgz"
integrity sha512-8fSLIpssGjX8mqTduIjlUStH1uBmAFWCmkiAo7/G8uDAY+rEnwE6nll5Cyvu+Ytqmw5FIQ7XAhohNrrZL2PheQ==
-zod@^3.23.8:
+zod@^3.23.8, zod@^3.24.3:
version "3.25.76"
resolved "https://registry.npmjs.org/zod/-/zod-3.25.76.tgz"
integrity sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==