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(deploy): add on-chain deployment button and styling

nirholasb2d5a396a6dc
diff --git a/api/widgets/oembed.js b/api/widgets/oembed.js
index efb286a83..21de25aeb 100644
--- a/api/widgets/oembed.js
+++ b/api/widgets/oembed.js
@@ -4,7 +4,7 @@
* GET /api/widgets/oembed?url=<widget-url>[&format=json|xml]
*
* Implements https://oembed.com with type=rich. Accepts canonical widget URLs
- * (https://host/w/<id>) and the legacy SPA hash form (https://host/#widget=<id>).
+ * (https://host/w/<id>) and the legacy SPA hash form (https://host/app#widget=<id>).
* The html payload is a sandboxed iframe so consumers (WordPress, Ghost, Notion,
* Discord, Slack) can render the widget inline.
*/
@@ -44,7 +44,7 @@ export default wrap(async (req, res) => {
if (!widget) return error(res, 404, 'not_found', 'widget not found');
const origin = env.APP_ORIGIN;
- const embedUrl = `${origin}/#widget=${widget.id}&kiosk=true`;
+ const embedUrl = `${origin}/app#widget=${widget.id}&kiosk=true`;
const pageUrl = `${origin}/w/${widget.id}`;
const thumbUrl = `${origin}/api/widgets/${widget.id}/og`;
const title = widget.name || 'Widget';
@@ -119,7 +119,8 @@ function extractWidgetId(target) {
const pathMatch = parsed.pathname.match(/^\/w\/([A-Za-z0-9_-]+)\/?$/);
if (pathMatch) return pathMatch[1];
- if (parsed.hash) {
+ // Accept both legacy /#widget=<id> and current /app#widget=<id> forms.
+ if (parsed.hash && (parsed.pathname === '/' || parsed.pathname === '/app')) {
const hashMatch = parsed.hash.match(/(?:^|[#&])widget=([A-Za-z0-9_-]+)/);
if (hashMatch) return hashMatch[1];
}
diff --git a/api/widgets/page.js b/api/widgets/page.js
index 00a8d69a2..f408a195e 100644
--- a/api/widgets/page.js
+++ b/api/widgets/page.js
@@ -6,7 +6,7 @@
* Wired to /w/:id via vercel.json. Returns an HTML page with proper Open Graph
* + Twitter card + oEmbed link tags so social crawlers (Slack, Discord, X,
* WordPress, Ghost) get a rich preview. Real browsers run the inline script
- * and replace into the SPA viewer at /#widget=<id>.
+ * and replace into the SPA viewer at /app#widget=<id>.
*/
import { sql } from '../_lib/db.js';
diff --git a/app.html b/app.html
index 955c8869a..738b41e12 100644
--- a/app.html
+++ b/app.html
@@ -110,6 +110,32 @@
</svg>
<span>Make this a widget</span>
</a>
+ <a
+ class="deploy-onchain-btn"
+ id="deploy-onchain-btn"
+ hidden
+ aria-label="Publish this agent on-chain"
+ title="Publish this agent on-chain (ERC-8004)"
+ >
+ <svg
+ xmlns="http://www.w3.org/2000/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"
+ focusable="false"
+ >
+ <polygon points="12 2 22 8.5 22 15.5 12 22 2 15.5 2 8.5 12 2" />
+ <line x1="12" y1="2" x2="12" y2="22" />
+ <polyline points="22 8.5 12 15.5 2 8.5" />
+ </svg>
+ <span data-state-label>Deploy on-chain</span>
+ </a>
<a
class="view-public-profile-btn"
id="view-public-profile-btn"
diff --git a/public/widgets-gallery/gallery.js b/public/widgets-gallery/gallery.js
index 8734b85b4..f3ed53f2a 100644
--- a/public/widgets-gallery/gallery.js
+++ b/public/widgets-gallery/gallery.js
@@ -32,7 +32,7 @@ function renderShowcase(w) {
root.className = 'showcase';
root.setAttribute('aria-labelledby', `sc-${w.id}-title`);
- const widgetUrl = `${ORIGIN}/#widget=${encodeURIComponent(w.id)}&kiosk=true`;
+ const widgetUrl = `${ORIGIN}/app#widget=${encodeURIComponent(w.id)}&kiosk=true`;
const pageUrl = `${ORIGIN}/w/${encodeURIComponent(w.id)}`;
const snippet = `<iframe src="${widgetUrl}" width="${w.width}" height="${w.height}" style="border:0;border-radius:12px;max-width:100%" allow="autoplay; xr-spatial-tracking; clipboard-write" loading="lazy"></iframe>`;
diff --git a/src/agent-home.js b/src/agent-home.js
index ccefea0db..2dafb22a5 100644
--- a/src/agent-home.js
+++ b/src/agent-home.js
@@ -82,7 +82,17 @@ export class AgentHome {
</div>
<div class="agent-home-info">
<div class="agent-home-name-row">
- <span class="agent-home-name" id="agent-home-name">${_esc(id.name)}</span>
+ <span
+ class="agent-home-name agent-home-editable"
+ id="agent-home-name"
+ data-field="name"
+ data-placeholder="Name your agent"
+ contenteditable="plaintext-only"
+ spellcheck="false"
+ role="textbox"
+ aria-label="Agent name (editable)"
+ title="Click to rename"
+ >${_esc(id.name)}</span>
${
id.isRegistered
? `
@@ -98,6 +108,16 @@ export class AgentHome {
<span class="agent-home-status-sep" aria-hidden="true">·</span>
<span class="agent-home-address" id="agent-home-address">${id.walletAddress ? _shortAddr(id.walletAddress) : 'no wallet'}</span>
</div>
+ <p
+ class="agent-home-description agent-home-editable"
+ id="agent-home-description"
+ data-field="description"
+ data-placeholder="Add a description…"
+ contenteditable="plaintext-only"
+ spellcheck="true"
+ role="textbox"
+ aria-label="Agent description (editable)"
+ >${_esc(id.description || '')}</p>
</div>
<button class="agent-home-btn" id="agent-copy-link" title="Copy agent link">
<svg width="13" height="13" viewBox="0 0 24 24" fill="currentColor"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg>
diff --git a/src/app.js b/src/app.js
index b6a5fc35c..c86d2e147 100644
--- a/src/app.js
+++ b/src/app.js
@@ -459,6 +459,72 @@ class App {
btn.hidden = !hasModel;
}
+ // Surface the right deploy CTA next to the public-profile link in /app:
+ // • "Deploy on-chain" → /deploy?avatar=<id> (un-registered agent)
+ // • "Deployed ✓" → block-explorer URL (already on-chain)
+ // Falls back to the bare /deploy page if we can't read the agent record
+ // (fetch error, anonymous, etc.) so the affordance never disappears once
+ // we know there's an agent in scope.
+ async _refreshDeployButton(agentId) {
+ const btn = document.getElementById('deploy-onchain-btn');
+ if (!btn || !agentId) return;
+
+ const label = btn.querySelector('[data-state-label]');
+ btn.classList.remove('is-deployed');
+ btn.removeAttribute('target');
+ btn.removeAttribute('rel');
+ if (label) label.textContent = 'Deploy on-chain';
+ btn.setAttribute('aria-label', 'Publish this agent on-chain');
+ btn.setAttribute('title', 'Publish this agent on-chain (ERC-8004)');
+ btn.href = `/deploy?agent=${encodeURIComponent(agentId)}`;
+ btn.hidden = false;
+
+ try {
+ const resp = await fetch(`/api/agents/${agentId}`, { credentials: 'include' });
+ if (!resp.ok) return;
+ const { agent } = await resp.json();
+ if (!agent) return;
+
+ if (agent.avatar_id && !btn.dataset.avatarPrefilled) {
+ btn.href = `/deploy?avatar=${encodeURIComponent(agent.avatar_id)}`;
+ btn.dataset.avatarPrefilled = '1';
+ }
+
+ const isDeployed = agent.erc8004_agent_id && agent.chain_id;
+ if (!isDeployed) return;
+
+ const { CHAIN_META, addressExplorerUrl, tokenExplorerUrl } = await import(
+ './erc8004/chain-meta.js'
+ );
+ const chainName = CHAIN_META[agent.chain_id]?.name || `chain ${agent.chain_id}`;
+ let url = '';
+ if (agent.erc8004_registry) {
+ url = tokenExplorerUrl(
+ agent.chain_id,
+ agent.erc8004_registry,
+ agent.erc8004_agent_id,
+ );
+ }
+ if (!url && agent.erc8004_registry) {
+ url = addressExplorerUrl(agent.chain_id, agent.erc8004_registry);
+ }
+ if (!url) url = `/agent/${agentId}`;
+
+ btn.classList.add('is-deployed');
+ btn.href = url;
+ btn.target = '_blank';
+ btn.rel = 'noopener';
+ if (label) label.textContent = `Deployed ✓ ${chainName}`;
+ btn.setAttribute(
+ 'aria-label',
+ `This agent is registered on ${chainName}. Open block explorer in a new tab.`,
+ );
+ btn.setAttribute('title', `On-chain on ${chainName} — view on explorer`);
+ } catch {
+ /* keep the un-deployed CTA */
+ }
+ }
+
_setupSaveToAccount() {
const btn = document.getElementById('save-to-account-btn');
if (!btn) return;
@@ -726,6 +792,8 @@ class App {
publicLink.hidden = false;
}
+ this._refreshDeployButton(agentId);
+
this._maybeShowOnboarding(agentId);
this._initAgentSystem();
diff --git a/src/share-panel.css b/src/share-panel.css
index 3bb25a7a8..b5ac996f3 100644
--- a/src/share-panel.css
+++ b/src/share-panel.css
@@ -13,7 +13,7 @@
background: #1a1a1a;
border: 1px solid #333;
border-radius: 12px;
- width: min(540px, calc(100vw - 32px));
+ width: min(560px, calc(100vw - 32px));
max-height: calc(100vh - 64px);
overflow-y: auto;
padding: 24px;
@@ -143,3 +143,103 @@
border-top: 1px solid #2a2a2a;
margin: 20px 0;
}
+
+/* ── Customise controls ──────────────────────────────────────────────────────── */
+
+.share-panel-controls {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 12px;
+}
+
+.share-panel-fieldset {
+ flex: 1 1 140px;
+ min-width: 140px;
+ border: 1px solid #2a2a2a;
+ border-radius: 8px;
+ padding: 8px 10px 10px;
+ margin: 0;
+}
+
+.share-panel-fieldset legend {
+ font-size: 10px;
+ font-weight: 600;
+ text-transform: uppercase;
+ letter-spacing: 0.06em;
+ color: #888;
+ padding: 0 4px;
+}
+
+.share-panel-segments {
+ display: flex;
+ gap: 4px;
+ flex-wrap: wrap;
+}
+
+.share-panel-segment {
+ flex: 1;
+ min-width: 0;
+ background: #1f1f1f;
+ border: 1px solid #2e2e2e;
+ border-radius: 5px;
+ color: #b0b0b0;
+ cursor: pointer;
+ font-size: 11px;
+ padding: 5px 8px;
+ white-space: nowrap;
+ text-align: center;
+ transition:
+ background 0.12s,
+ color 0.12s,
+ border-color 0.12s;
+}
+
+.share-panel-segment:hover {
+ background: #2a2a2a;
+ color: #fff;
+}
+
+.share-panel-segment--active {
+ background: #2e3a55;
+ border-color: #4d6aa3;
+ color: #e8eeff;
+}
+
+.share-panel-segment--active:hover {
+ background: #364568;
+}
+
+/* ── Live preview ────────────────────────────────────────────────────────────── */
+
+.share-panel-preview {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ border-radius: 10px;
+ background:
+ linear-gradient(45deg, #1d1d1d 25%, transparent 25%) 0 0 / 16px 16px,
+ linear-gradient(-45deg, #1d1d1d 25%, transparent 25%) 0 8px / 16px 16px,
+ linear-gradient(45deg, transparent 75%, #1d1d1d 75%) 8px -8px / 16px 16px,
+ linear-gradient(-45deg, transparent 75%, #1d1d1d 75%) 8px 0 / 16px 16px,
+ #252525;
+ padding: 16px;
+ border: 1px solid #2a2a2a;
+ min-height: 200px;
+}
+
+.share-panel-preview-frame {
+ display: block;
+ border: 0;
+ border-radius: 8px;
+ background: transparent;
+ max-width: 100%;
+ box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
+}
+
+.share-panel-preview-frame[data-bg='dark'] {
+ background: #0b0d10;
+}
+
+.share-panel-preview-frame[data-bg='light'] {
+ background: #f5f5f5;
+}
diff --git a/src/share-panel.js b/src/share-panel.js
index 3ead2206e..7cb7b4f55 100644
--- a/src/share-panel.js
+++ b/src/share-panel.js
@@ -2,16 +2,36 @@ import { renderQRToCanvas, renderQRToSVG } from './erc8004/qr.js';
import './share-panel.css';
/**
- * One-click share modal for an agent: link, iframe snippet, web-component
- * snippet, OG preview, and QR code.
+ * One-click share modal for an agent: link, customisable iframe + web-component
+ * snippets with a live preview, OG card, and QR code.
*
* @example
- * const panel = new SharePanel({ agent: { id, slug, name, thumbnailUrl }, container: document.body });
+ * const panel = new SharePanel({
+ * agent: { id, slug, name },
+ * container: document.body,
+ * });
* panel.open();
*/
+
+const DEFAULT_OPTIONS = Object.freeze({
+ bg: 'transparent', // 'transparent' | 'dark' | 'light'
+ name: true, // show name plate
+ size: 'medium', // 'small' | 'medium' | 'large'
+});
+
+const SIZES = {
+ small: { width: 320, height: 420 },
+ medium: { width: 420, height: 520 },
+ large: { width: 520, height: 680 },
+};
+
export class SharePanel {
/**
- * @param {{ agent: { id: string, slug?: string, name?: string, thumbnailUrl?: string }, container?: HTMLElement, embedOrigin?: string }} opts
+ * @param {{
+ * agent: { id: string, slug?: string, name?: string, thumbnailUrl?: string },
+ * container?: HTMLElement,
+ * embedOrigin?: string,
+ * }} opts
*/
constructor({ agent, container = document.body, embedOrigin = location.origin }) {
this._agent = agent;
@@ -19,6 +39,7 @@ export class SharePanel {
this._origin = embedOrigin;
this._backdrop = null;
this._opener = null;
+ this._opts = { ...DEFAULT_OPTIONS };
this._onKeyDown = this._onKeyDown.bind(this);
}
@@ -27,21 +48,14 @@ export class SharePanel {
this._opener = document.activeElement;
const { id, slug, name } = this._agent;
- const origin = this._origin;
- const link = `${origin}/a/${slug || id}`;
- const iframeSnippet =
- `<iframe src="${origin}/agent-embed.html?id=${id}"\n` +
- ` width="480" height="640" frameborder="0" allow="microphone; camera"></iframe>`;
- const wcSnippet =
- `<script type="module" src="${origin}/dist-lib/agent-3d.js"><\/script>\n` +
- `<agent-3d agent-id="${id}"></agent-3d>`;
- const ogUrl = `${origin}/api/a-og?id=${id}`;
+ const link = `${this._origin}/a/${slug || id}`;
+ const ogUrl = `${this._origin}/api/a-og?id=${id}`;
+ const modalId = `share-panel-title-${id}`;
const backdrop = document.createElement('div');
backdrop.className = 'share-panel-backdrop';
backdrop.setAttribute('role', 'presentation');
- const modalId = `share-panel-title-${id}`;
const modal = document.createElement('div');
modal.className = 'share-panel-modal';
modal.setAttribute('role', 'dialog');
@@ -58,20 +72,54 @@ export class SharePanel {
<div class="share-panel-row" data-section="link">
<div class="share-panel-label">Link</div>
<div class="share-panel-field">
- <div class="share-panel-code">${_esc(link)}</div>
+ <div class="share-panel-code" data-role="link-code">${_esc(link)}</div>
<div class="share-panel-actions">
- <button class="share-panel-btn" data-copy="${_esc(link)}">Copy</button>
+ <button class="share-panel-btn" data-copy-target="link-code">Copy</button>
<a class="share-panel-btn" href="${_esc(link)}" target="_blank" rel="noopener">Open ↗</a>
</div>
</div>
</div>
+ <div class="share-panel-row" data-section="customise">
+ <div class="share-panel-label">Customise embed</div>
+ <div class="share-panel-controls">
+ <fieldset class="share-panel-fieldset">
+ <legend>Background</legend>
+ <div class="share-panel-segments" role="radiogroup" aria-label="Background">
+ ${_segmentBtn('bg', 'transparent', 'Transparent', this._opts.bg)}
+ ${_segmentBtn('bg', 'dark', 'Dark', this._opts.bg)}
+ ${_segmentBtn('bg', 'light', 'Light', this._opts.bg)}
+ </div>
+ </fieldset>
+ <fieldset class="share-panel-fieldset">
+ <legend>Name plate</legend>
+ <div class="share-panel-segments" role="radiogroup" aria-label="Name plate">
+ ${_segmentBtn('name', 'true', 'On', String(this._opts.name))}
+ ${_segmentBtn('name', 'false', 'Off', String(this._opts.name))}
+ </div>
+ </fieldset>
+ <fieldset class="share-panel-fieldset">
+ <legend>Size</legend>
+ <div class="share-panel-segments" role="radiogroup" aria-label="Size">
+ ${_segmentBtn('size', 'small', 'Small', this._opts.size)}
+ ${_segmentBtn('size', 'medium', 'Medium', this._opts.size)}
+ ${_segmentBtn('size', 'large', 'Large', this._opts.size)}
+ </div>
+ </fieldset>
+ </div>
+ </div>
+
+ <div class="share-panel-row" data-section="preview">
+ <div class="share-panel-label">Live preview</div>
+ <div class="share-panel-preview" data-role="preview-frame-mount"></div>
+ </div>
+
<div class="share-panel-row" data-section="iframe">
<div class="share-panel-label">iframe embed</div>
<div class="share-panel-field">
- <div class="share-panel-code">${_esc(iframeSnippet)}</div>
+ <div class="share-panel-code" data-role="iframe-code"></div>
<div class="share-panel-actions">
- <button class="share-panel-btn" data-copy="${_esc(iframeSnippet)}">Copy</button>
+ <button class="share-panel-btn" data-copy-target="iframe-code">Copy</button>
</div>
</div>
</div>
@@ -79,9 +127,9 @@ export class SharePanel {
<div class="share-panel-row" data-section="wc">
<div class="share-panel-label">Web component</div>
<div class="share-panel-field">
- <div class="share-panel-code">${_esc(wcSnippet)}</div>
+ <div class="share-panel-code" data-role="wc-code"></div>
<div class="share-panel-actions">
- <button class="share-panel-btn" data-copy="${_esc(wcSnippet)}">Copy</button>
+ <button class="share-panel-btn" data-copy-target="wc-code">Copy</button>
</div>
</div>
</div>
@@ -94,9 +142,9 @@ export class SharePanel {
alt="OG preview for ${_esc(name || id)}"
style="aspect-ratio:1200/630;">
<div class="share-panel-field" style="margin-top:6px;">
- <div class="share-panel-code">${_esc(ogUrl)}</div>
+ <div class="share-panel-code" data-role="og-code">${_esc(ogUrl)}</div>
<div class="share-panel-actions">
- <button class="share-panel-btn" data-copy="${_esc(ogUrl)}">Copy URL</button>
+ <button class="share-panel-btn" data-copy-target="og-code">Copy URL</button>
</div>
</div>
</div>
@@ -109,15 +157,18 @@ export class SharePanel {
</div>
`;
- // Attach close handler
modal.querySelector('.share-panel-close').addEventListener('click', () => this.close());
- // Copy buttons
- modal.querySelectorAll('[data-copy]').forEach((btn) => {
+ // Segment-button toggles
+ modal.querySelectorAll('.share-panel-segment').forEach((btn) => {
+ btn.addEventListener('click', () => this._onSegmentClick(btn));
+ });
+
+ // Copy buttons (resolve target text on click for live snippet content)
+ modal.querySelectorAll('[data-copy-target]').forEach((btn) => {
btn.addEventListener('click', () => this._copy(btn));
});
- // Dismiss on backdrop click (outside modal)
backdrop.addEventListener('click', (e) => {
if (e.target === backdrop) this.close();
});
@@ -126,26 +177,13 @@ export class SharePanel {
this._container.appendChild(backdrop);
this._backdrop = backdrop;
- // Render QR — prefer canvas; fall back to inline SVG when canvas isn't
- // available (older browsers, jsdom, restricted contexts).
- const qrMount = modal.querySelector('#share-panel-qr-mount');
- try {
- const canvas = renderQRToCanvas(link, { scale: 6, margin: 2 });
- qrMount.appendChild(canvas);
- } catch {
- try {
- qrMount.innerHTML = renderQRToSVG(link, { scale: 6, margin: 2 });
- } catch {
- qrMount.textContent = link;
- }
- }
+ this._renderSnippets();
+ this._mountPreview();
+ this._renderQR(link);
- // Focus trap + keyboard
document.addEventListener('keydown', this._onKeyDown);
- // Focus modal so Esc works immediately; focus first button for usability
const firstBtn = modal.querySelector('button');
(firstBtn || modal).focus();
-
_trapFocus(modal);
}
@@ -160,18 +198,140 @@ export class SharePanel {
this._opener = null;
}
- _onKeyDown(e) {
- if (e.key === 'Escape') {
- e.preventDefault();
- this.close();
+ // ── Snippet building ─────────────────────────────────────────────────────────
+
+ /**
+ * Build the canonical embed URL with current options as query params.
+ * Defaults are omitted to keep the URL readable.
+ *
+ * @returns {string}
+ */
+ _buildEmbedUrl() {
+ const id = this._agent.id;
+ const url = new URL(`${this._origin}/agent/${id}/embed`);
+ if (this._opts.bg !== DEFAULT_OPTIONS.bg) url.searchParams.set('bg', this._opts.bg);
+ if (this._opts.name !== DEFAULT_OPTIONS.name) url.searchParams.set('name', '0');
+ return url.toString();
+ }
+
+ _buildIframeSnippet() {
+ const { width, height } = SIZES[this._opts.size];
+ const allow = 'autoplay; xr-spatial-tracking; microphone; camera';
+ return (
+ `<iframe\n` +
+ ` src="${this._buildEmbedUrl()}"\n` +
+ ` width="${width}" height="${height}"\n` +
+ ` style="border:0;border-radius:12px;background:transparent"\n` +
+ ` allow="${allow}"\n` +
+ ` loading="lazy"\n` +
+ ` referrerpolicy="strict-origin-when-cross-origin"\n` +
+ `></iframe>`
+ );
+ }
+
+ _buildWebComponentSnippet() {
+ const { width, height } = SIZES[this._opts.size];
+ const id = this._agent.id;
+ return (
+ `<script type="module" src="${this._origin}/dist-lib/agent-3d.js"><\/script>\n` +
+ `<agent-3d agent-id="${id}"\n` +
+ ` style="display:block;width:${width}px;height:${height}px"\n` +
+ `></agent-3d>`
+ );
+ }
+
+ _renderSnippets() {
+ const m = this._backdrop;
+ if (!m) return;
+ const iframeCode = this._buildIframeSnippet();
+ const wcCode = this._buildWebComponentSnippet();
+ m.querySelector('[data-role="iframe-code"]').textContent = iframeCode;
+ m.querySelector('[data-role="wc-code"]').textContent = wcCode;
+ }
+
+ // ── Live preview ─────────────────────────────────────────────────────────────
+
+ _mountPreview() {
+ const mount = this._backdrop?.querySelector('[data-role="preview-frame-mount"]');
+ if (!mount) return;
+ mount.innerHTML = '';
+ this._previewMount = mount;
+ this._renderPreview();
+ }
+
+ _renderPreview() {
+ if (!this._previewMount) return;
+ const { width, height } = SIZES[this._opts.size];
+ const url = new URL(this._buildEmbedUrl());
+ // Always set preview=1 so the embed page skips its origin allow-list
+ // gate when the dialog runs on a non-allowlisted host.
+ url.searchParams.set('preview', '1');
+
+ const frame = document.createElement('iframe');
+ frame.className = 'share-panel-preview-frame';
+ frame.src = url.toString();
+ frame.width = String(width);
+ frame.height = String(height);
+ frame.setAttribute('loading', 'lazy');
+ frame.setAttribute('referrerpolicy', 'strict-origin-when-cross-origin');
+ frame.setAttribute('allow', 'autoplay; xr-spatial-tracking');
+ frame.setAttribute(
+ 'aria-label',
+ `Live preview of ${this._agent.name || 'agent'} embed`,
+ );
+ // Visualise the chosen background while the iframe paints.
+ frame.dataset.bg = this._opts.bg;
+ this._previewMount.replaceChildren(frame);
+ }
+
+ // ── Segment toggles ──────────────────────────────────────────────────────────
+
+ _onSegmentClick(btn) {
+ const group = btn.dataset.group;
+ const value = btn.dataset.value;
+ if (!group) return;
+
+ // Update opts
+ if (group === 'name') {
+ this._opts.name = value === 'true';
+ } else {
+ this._opts[group] = value;
}
- if (e.key === 'Tab' && this._backdrop) {
- _handleTabTrap(e, this._backdrop.querySelector('.share-panel-modal'));
+
+ // Update aria-checked + active class for the group
+ const groupRoot = btn.closest('.share-panel-segments');
+ groupRoot.querySelectorAll('.share-panel-segment').forEach((b) => {
+ const active = b === btn;
+ b.classList.toggle('share-panel-segment--active', active);
+ b.setAttribute('aria-checked', String(active));
+ });
+
+ this._renderSnippets();
+ this._renderPreview();
+ }
+
+ // ── Misc ─────────────────────────────────────────────────────────────────────
+
+ _renderQR(link) {
+ const qrMount = this._backdrop?.querySelector('#share-panel-qr-mount');
+ if (!qrMount) return;
+ try {
+ const canvas = renderQRToCanvas(link, { scale: 6, margin: 2 });
+ qrMount.appendChild(canvas);
+ } catch {
+ try {
+ qrMount.innerHTML = renderQRToSVG(link, { scale: 6, margin: 2 });
+ } catch {
+ qrMount.textContent = link;
+ }
}
}
_copy(btn) {
- const text = btn.getAttribute('data-copy');
+ const targetRole = btn.getAttribute('data-copy-target');
+ const node = this._backdrop?.querySelector(`[data-role="${targetRole}"]`);
+ if (!node) return;
+ const text = node.textContent || '';
navigator.clipboard.writeText(text).then(() => {
const orig = btn.textContent;
btn.textContent = 'Copied ✓';
@@ -182,9 +342,86 @@ export class SharePanel {
}, 1200);
});
}
+
+ _onKeyDown(e) {
+ if (e.key === 'Escape') {
+ e.preventDefault();
+ this.close();
+ }
+ if (e.key === 'Tab' && this._backdrop) {
+ _handleTabTrap(e, this._backdrop.querySelector('.share-panel-modal'));
+ }
+ }
+}
+
+// ── Pure helpers (exported for tests) ────────────────────────────────────────────
+
+/**
+ * Build an embed URL for the given agent and options. Pure / side-effect-free.
+ * Defaults are omitted from the query string so canonical URLs stay short.
+ *
+ * @param {{ origin: string, agentId: string, opts?: { bg?: string, name?: boolean } }} args
+ */
+export function buildEmbedUrl({ origin, agentId, opts = {} }) {
+ const merged = { ...DEFAULT_OPTIONS, ...opts };
+ const url = new URL(`${origin}/agent/${agentId}/embed`);
+ if (merged.bg !== DEFAULT_OPTIONS.bg) url.searchParams.set('bg', merged.bg);
+ if (merged.name !== DEFAULT_OPTIONS.name) url.searchParams.set('name', '0');
+ return url.toString();
+}
+
+/**
+ * Build the iframe snippet string. Pure / side-effect-free.
+ *
+ * @param {{ origin: string, agentId: string, opts?: { bg?: string, name?: boolean, size?: string } }} args
+ */
+export function buildIframeSnippet({ origin, agentId, opts = {} }) {
+ const merged = { ...DEFAULT_OPTIONS, ...opts };
+ const { width, height } = SIZES[merged.size] || SIZES.medium;
+ const src = buildEmbedUrl({ origin, agentId, opts: merged });
+ const allow = 'autoplay; xr-spatial-tracking; microphone; camera';
+ return (
+ `<iframe\n` +
+ ` src="${src}"\n` +
+ ` width="${width}" height="${height}"\n` +
+ ` style="border:0;border-radius:12px;background:transparent"\n` +
+ ` allow="${allow}"\n` +
+ ` loading="lazy"\n` +
+ ` referrerpolicy="strict-origin-when-cross-origin"\n` +
+ `></iframe>`
+ );
}
-// ── helpers ──────────────────────────────────────────────────────────────────
+/**
+ * Build the web-component snippet string. Pure / side-effect-free.
+ *
+ * @param {{ origin: string, agentId: string, opts?: { bg?: string, name?: boolean, size?: string } }} args
+ */
+export function buildWebComponentSnippet({ origin, agentId, opts = {} }) {
+ const merged = { ...DEFAULT_OPTIONS, ...opts };
+ const { width, height } = SIZES[merged.size] || SIZES.medium;
+ const attrs = [`agent-id="${agentId}"`];
+ if (merged.bg !== DEFAULT_OPTIONS.bg) attrs.push(`background="${merged.bg}"`);
+ if (merged.name !== DEFAULT_OPTIONS.name) attrs.push(`name-plate="off"`);
+ return (
+ `<script type="module" src="${origin}/dist-lib/agent-3d.js"><\/script>\n` +
+ `<agent-3d ${attrs.join(' ')}\n` +
+ ` style="display:block;width:${width}px;height:${height}px"\n` +
+ `></agent-3d>`
+ );
+}
+
+// ── Internal helpers ─────────────────────────────────────────────────────────────
+
+function _segmentBtn(group, value, label, currentValue) {
+ const active = String(currentValue) === String(value);
+ return (
+ `<button type="button"` +
+ ` class="share-panel-segment${active ? ' share-panel-segment--active' : ''}"` +
+ ` role="radio" aria-checked="${active}"` +
+ ` data-group="${_esc(group)}" data-value="${_esc(value)}">${_esc(label)}</button>`
+ );
+}
function _esc(str) {
return String(str)
@@ -198,7 +435,6 @@ const FOCUSABLE =
'a[href],button:not([disabled]),input,select,textarea,[tabindex]:not([tabindex="-1"])';
function _trapFocus(modal) {
- // Initial focus on first focusable element
const els = modal.querySelectorAll(FOCUSABLE);
if (els.length) els[0].focus();
}
diff --git a/style.css b/style.css
index 88b0fcea9..29f1f4e08 100644
--- a/style.css
+++ b/style.css
@@ -2751,6 +2751,59 @@ footer .separator {
}
}
+.deploy-onchain-btn {
+ display: inline-flex;
+ align-items: center;
+ gap: var(--space-xs);
+ padding: var(--space-sm) var(--space-lg);
+ background: rgba(108, 99, 255, 0.1);
+ border: 1px solid rgba(108, 99, 255, 0.4);
+ border-radius: var(--radius-lg);
+ color: rgba(255, 255, 255, 0.92);
+ font-family: inherit;
+ font-size: var(--text-sm);
+ font-weight: 500;
+ text-decoration: none;
+ cursor: pointer;
+ transition: all 0.25s ease;
+ letter-spacing: 0.02em;
+}
+.deploy-onchain-btn:hover {
+ background: rgba(108, 99, 255, 0.22);
+ color: #fff;
+ border-color: rgba(108, 99, 255, 0.65);
+}
+.deploy-onchain-btn:focus-visible {
+ outline: 2px solid rgba(108, 99, 255, 0.7);
+ outline-offset: 2px;
+}
+.deploy-onchain-btn[hidden] {
+ display: none;
+}
+.deploy-onchain-btn svg {
+ width: 1em;
+ height: 1em;
+}
+/* "Deployed ✓" success state — replaces the call-to-action once on-chain. */
+.deploy-onchain-btn.is-deployed {
+ background: rgba(74, 222, 128, 0.1);
+ border-color: rgba(74, 222, 128, 0.42);
+ color: #86efac;
+}
+.deploy-onchain-btn.is-deployed:hover {
+ background: rgba(74, 222, 128, 0.2);
+ color: #d1fae5;
+ border-color: rgba(74, 222, 128, 0.7);
+}
+@media screen and (max-width: 700px) {
+ .deploy-onchain-btn span {
+ display: none;
+ }
+ .deploy-onchain-btn {
+ padding: var(--space-xs) var(--space-sm);
+ }
+}
+
.view-public-profile-btn {
display: inline-flex;
align-items: center;
diff --git a/vercel.json b/vercel.json
index 616a6ddec..dc0b6067f 100644
--- a/vercel.json
+++ b/vercel.json
@@ -64,7 +64,16 @@
{ "src": "/api/a/(\\d+)/(\\d+)/og", "dest": "/api/a-og?chain=$1&id=$2" },
{ "src": "/api/oembed", "dest": "/api/agent-oembed" },
{ "src": "/agent/([^/]+)/edit", "dest": "/agent-edit.html" },
- { "src": "/agent/([^/]+)/embed", "dest": "/agent-embed.html" },
+ {
+ "src": "/agent/([^/]+)/embed",
+ "headers": {
+ "content-security-policy": "frame-ancestors *",
+ "x-content-type-options": "nosniff",
+ "referrer-policy": "strict-origin-when-cross-origin",
+ "permissions-policy": "microphone=(self), camera=(self), xr-spatial-tracking=*"
+ },
+ "dest": "/agent-embed.html"
+ },
{ "src": "/agent/([^/]+)", "dest": "/agent-home.html" },
{ "src": "/agent", "dest": "/agent-home.html" },
@@ -114,9 +123,10 @@
{ "src": "/my-agents", "dest": "/my-agents/index.html" },
{ "src": "/my-agents/", "dest": "/my-agents/index.html" },
- { "src": "/discover", "dest": "/discover/index.html" },
- { "src": "/discover/", "dest": "/discover/index.html" },
- { "src": "/discover/(.*)", "dest": "/discover/$1" },
+ { "src": "/my-agents/(.*)", "dest": "/my-agents/$1" },
+ { "src": "/discover", "status": 301, "headers": { "Location": "/my-agents" } },
+ { "src": "/discover/", "status": 301, "headers": { "Location": "/my-agents" } },
+ { "src": "/discover/(.*)", "status": 301, "headers": { "Location": "/my-agents" } },
{ "src": "/api/(.*)", "dest": "/api/$1" },
@@ -170,7 +180,16 @@
{ "src": "/home", "dest": "/home.html" },
{ "src": "/explore", "status": 301, "headers": { "Location": "/discover" } },
{ "src": "/explore/", "status": 301, "headers": { "Location": "/discover" } },
- { "src": "/a/(\\d+)/(\\d+)/embed", "dest": "/a-embed.html" },
+ {
+ "src": "/a/(\\d+)/(\\d+)/embed",
+ "headers": {
+ "content-security-policy": "frame-ancestors *",
+ "x-content-type-options": "nosniff",
+ "referrer-policy": "strict-origin-when-cross-origin",
+ "permissions-policy": "microphone=(self), camera=(self), xr-spatial-tracking=*"
+ },
+ "dest": "/a-embed.html"
+ },
{ "src": "/a/(\\d+)/(\\d+)", "dest": "/api/a-page?chain=$1&id=$2" },
{ "src": "/a/(.*)", "dest": "/app.html" },
{ "src": "/(.*)", "dest": "/$1" }