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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title data-i18n="artifact_index.meta_title">Artifact Viewer · three.ws</title>
<meta
name="description"
content="Embed an interactive three.ws agent inside a Claude.ai artifact. Self-contained HTML, zero external dependencies."
data-i18n-attr="content:artifact_index.meta_description"/>
<link rel="stylesheet" href="/style.css" />
<style>
body {
overflow: auto;
background: radial-gradient(circle at 50% 0%, #131313 0%, #0f0f0f 50%, #090909 100%);
}
.artifact-page {
max-width: 1180px;
margin: 0 auto;
padding: var(--space-2xl) var(--space-lg) var(--space-2xl);
display: flex;
flex-direction: column;
gap: var(--space-2xl);
}
.hero {
text-align: center;
display: flex;
flex-direction: column;
gap: var(--space-md);
align-items: center;
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 4px 12px;
border-radius: 999px;
font-size: var(--text-sm);
font-weight: 500;
color: var(--accent);
background: var(--accent-soft);
border: 1px solid var(--accent-soft);
letter-spacing: 0.04em;
text-transform: uppercase;
}
.eyebrow::before {
content: '';
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 12px var(--accent);
}
h1.headline {
font-family: var(--font-display);
font-size: clamp(2rem, 5vw, 3.4rem);
font-weight: 700;
line-height: 1.05;
margin: 0;
letter-spacing: -0.02em;
background: linear-gradient(180deg, #fff 0%, #b9b3ff 100%);
-webkit-background-clip: text;
background-clip: text;
color: transparent;
}
.lede {
max-width: 580px;
color: rgba(255, 255, 255, 0.7);
font-size: var(--text-lg);
line-height: var(--leading-tight);
margin: 0;
}
.builder {
display: grid;
grid-template-columns: minmax(320px, 1fr) minmax(0, 1.382fr);
gap: var(--space-lg);
align-items: stretch;
}
@media (max-width: 880px) {
.builder {
grid-template-columns: 1fr;
}
}
.panel {
background: rgba(255, 255, 255, 0.03);
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: var(--radius-lg);
padding: var(--space-lg);
display: flex;
flex-direction: column;
gap: var(--space-md);
min-width: 0;
}
.panel h2 {
margin: 0;
font-size: var(--text-base);
font-weight: 600;
color: rgba(255, 255, 255, 0.85);
letter-spacing: 0.02em;
}
.field {
display: flex;
flex-direction: column;
gap: 6px;
min-width: 0;
}
.field label {
font-size: var(--text-sm);
color: rgba(255, 255, 255, 0.6);
font-weight: 500;
}
.field input,
.field select {
/* Inputs carry an intrinsic min-width from their `size` default; without
this the two-column field row cannot shrink and the page scrolls
sideways on a 320px screen. */
width: 100%;
min-width: 0;
box-sizing: border-box;
background: rgba(0, 0, 0, 0.3);
border: 1px solid rgba(255, 255, 255, 0.12);
color: #fff;
padding: 10px 12px;
border-radius: var(--radius-md);
font: inherit;
font-size: var(--text-base);
transition:
border-color var(--duration-fast),
background var(--duration-fast);
}
.field input:focus,
.field select:focus {
outline: none;
border-color: var(--accent);
background: rgba(0, 0, 0, 0.4);
}
.field input:focus-visible,
.field select:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
.field-head {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: var(--space-sm);
}
.field-row {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
gap: var(--space-sm);
}
.btn-row {
display: flex;
gap: 8px;
flex-wrap: wrap;
}
button.btn {
flex: 1;
min-width: 120px;
background: var(--accent);
color: #fff;
border: none;
padding: 11px 16px;
border-radius: var(--radius-md);
font: inherit;
font-weight: 600;
font-size: var(--text-base);
cursor: pointer;
transition:
transform var(--duration-instant),
filter var(--duration-fast);
}
button.btn:hover {
filter: brightness(1.1);
}
button.btn:active {
transform: scale(0.98);
}
button.btn.ghost {
background: rgba(255, 255, 255, 0.06);
color: rgba(255, 255, 255, 0.9);
border: 1px solid rgba(255, 255, 255, 0.1);
}
button.btn.ghost:hover {
background: rgba(255, 255, 255, 0.12);
filter: none;
}
button.btn:disabled {
opacity: 0.5;
cursor: not-allowed;
filter: none;
}
button.btn:focus-visible,
.picker-item:focus-visible,
details.snippet > summary:focus-visible,
.linklike:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
.linklike {
background: none;
border: 0;
padding: 0;
font: inherit;
font-size: var(--text-sm);
color: var(--accent);
cursor: pointer;
border-radius: 4px;
text-decoration: underline;
text-underline-offset: 2px;
}
.linklike:hover {
filter: brightness(1.2);
}
.picker {
display: flex;
flex-direction: column;
gap: 8px;
}
.picker-head {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: var(--space-sm);
}
.picker-head h3 {
margin: 0;
font-size: var(--text-sm);
font-weight: 500;
color: rgba(255, 255, 255, 0.6);
}
.picker-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
gap: 8px;
}
.picker-item {
display: flex;
align-items: center;
gap: 8px;
min-width: 0;
text-align: left;
background: rgba(0, 0, 0, 0.25);
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: var(--radius-md);
padding: 7px 9px;
color: rgba(255, 255, 255, 0.88);
font: inherit;
font-size: var(--text-sm);
cursor: pointer;
transition:
border-color var(--duration-fast),
background var(--duration-fast),
transform var(--duration-instant);
}
.picker-item:hover {
background: rgba(255, 255, 255, 0.07);
border-color: var(--accent-soft);
}
.picker-item:active {
transform: scale(0.98);
}
.picker-item[aria-pressed='true'] {
border-color: var(--accent);
background: var(--accent-soft);
}
.picker-item img,
.picker-item .initial {
width: 26px;
height: 26px;
border-radius: 50%;
flex: none;
object-fit: cover;
background: rgba(255, 255, 255, 0.08);
}
.picker-item .initial {
display: grid;
place-items: center;
font-size: var(--text-xs);
font-weight: 600;
color: rgba(255, 255, 255, 0.7);
}
.picker-item .name {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.picker-skeleton {
height: 42px;
border-radius: var(--radius-md);
background: linear-gradient(
90deg,
rgba(255, 255, 255, 0.04) 0%,
rgba(255, 255, 255, 0.09) 50%,
rgba(255, 255, 255, 0.04) 100%
);
background-size: 200% 100%;
animation: shimmer 1200ms linear infinite;
}
@keyframes shimmer {
to {
background-position: -200% 0;
}
}
@media (prefers-reduced-motion: reduce) {
.picker-skeleton,
.spinner {
animation: none;
}
}
.picker-note {
margin: 0;
font-size: var(--text-sm);
color: rgba(255, 255, 255, 0.6);
line-height: var(--leading-tight);
}
.picker-note.error {
color: #fca5a5;
}
.picker-note a {
color: var(--accent);
}
.preview {
display: flex;
flex-direction: column;
gap: var(--space-md);
}
.preview-frame {
flex: 1;
min-height: 380px;
background: #000;
border-radius: var(--radius-md);
border: 1px solid rgba(255, 255, 255, 0.1);
overflow: hidden;
position: relative;
}
.preview-frame iframe {
width: 100%;
height: 100%;
min-height: 380px;
border: 0;
display: block;
}
.preview-overlay {
position: absolute;
inset: 0;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
gap: 12px;
background: rgba(8, 8, 20, 0.92);
color: rgba(255, 255, 255, 0.85);
font-size: var(--text-sm);
transition: opacity var(--duration-base);
text-align: center;
padding: 24px;
}
.preview-overlay[hidden] {
display: none;
}
.preview-overlay.error {
color: #fca5a5;
}
.preview-overlay button.btn {
flex: none;
min-width: 0;
}
.preview-overlay .hint {
color: rgba(255, 255, 255, 0.6);
max-width: 34ch;
}
.field-hint {
font-size: var(--text-xs);
color: #fca5a5;
min-height: 1em;
}
.field input[aria-invalid='true'] {
border-color: #fca5a5;
}
.spinner {
width: 28px;
height: 28px;
border: 2px solid rgba(255, 255, 255, 0.15);
border-top-color: var(--accent);
border-radius: 50%;
animation: spin 700ms linear infinite;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
.stats {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
gap: var(--space-sm);
}
.stat {
background: rgba(0, 0, 0, 0.25);
border: 1px solid rgba(255, 255, 255, 0.06);
border-radius: var(--radius-md);
padding: 10px 12px;
display: flex;
flex-direction: column;
gap: 2px;
}
.stat .label {
font-size: var(--text-xs);
color: rgba(255, 255, 255, 0.5);
text-transform: uppercase;
letter-spacing: 0.06em;
}
.stat .value {
font-family: var(--font-mono);
font-size: var(--text-base);
color: #fff;
font-weight: 500;
}
.stat .value.ok {
color: #6ee7b7;
}
.stat .value.warn {
color: #fcd34d;
}
.stat .value.bad {
color: #fca5a5;
}
details.snippet {
background: rgba(0, 0, 0, 0.3);
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: var(--radius-md);
padding: var(--space-sm) var(--space-md);
}
details.snippet > summary {
cursor: pointer;
font-size: var(--text-sm);
font-weight: 500;
color: rgba(255, 255, 255, 0.75);
list-style: none;
display: flex;
align-items: center;
gap: 8px;
}
details.snippet > summary::-webkit-details-marker {
display: none;
}
details.snippet > summary::before {
content: '›';
transition: transform var(--duration-fast);
color: var(--accent);
font-size: 1.2em;
}
details.snippet[open] > summary::before {
transform: rotate(90deg);
}
details.snippet pre {
margin: var(--space-sm) 0 0;
padding: var(--space-md);
background: #090909;
border-radius: var(--radius-md);
color: #d8d4ff;
font-family: var(--font-mono);
font-size: var(--text-sm);
line-height: 1.6;
overflow-x: auto;
white-space: pre-wrap;
word-break: break-all;
}
.facts {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
gap: var(--space-md);
}
.fact {
background: rgba(255, 255, 255, 0.025);
border: 1px solid rgba(255, 255, 255, 0.06);
border-radius: var(--radius-md);
padding: var(--space-md);
}
.fact h3 {
margin: 0 0 6px;
font-size: var(--text-base);
font-weight: 600;
color: rgba(255, 255, 255, 0.92);
}
.fact p {
margin: 0;
font-size: var(--text-sm);
color: rgba(255, 255, 255, 0.65);
line-height: var(--leading-tight);
}
.toast {
position: fixed;
left: 50%;
bottom: 32px;
transform: translate(-50%, 24px);
background: #151515;
color: #fff;
padding: 10px 18px;
border-radius: 999px;
border: 1px solid rgba(255, 255, 255, 0.12);
font-size: var(--text-sm);
font-weight: 500;
opacity: 0;
transition:
opacity var(--duration-fast),
transform var(--duration-fast);
pointer-events: none;
z-index: 50;
box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
.csp-line {
font-family: var(--font-mono);
font-size: 11px;
color: rgba(255, 255, 255, 0.4);
word-break: break-all;
padding: var(--space-sm) var(--space-md);
background: rgba(0, 0, 0, 0.3);
border-radius: var(--radius-sm);
border: 1px solid rgba(255, 255, 255, 0.05);
line-height: 1.5;
}
</style>
<link rel="canonical" href="https://three.ws/artifact">
<meta property="og:type" content="website">
<meta property="og:site_name" content="three.ws">
<meta property="og:title" content="Artifact Viewer · three.ws" data-i18n-attr="content:artifact_index.meta_og_title">
<meta property="og:description" content="Renders Claude artifact bundles as standalone embeddable apps." data-i18n-attr="content:artifact_index.meta_og_description">
<meta property="og:url" content="https://three.ws/artifact">
<meta property="og:image" content="https://three.ws/api/page-og?s=build&t=Artifact+Viewer&d=Renders+Claude+artifact+bundles+as+standalone+embeddable+apps.&p=%2Fartifact">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Artifact Viewer · three.ws" data-i18n-attr="content:artifact_index.meta_twitter_title">
<meta name="twitter:description" content="Renders Claude artifact bundles as standalone embeddable apps." data-i18n-attr="content:artifact_index.meta_twitter_description">
<meta name="twitter:image" content="https://three.ws/api/page-og?s=build&t=Artifact+Viewer&d=Renders+Claude+artifact+bundles+as+standalone+embeddable+apps.&p=%2Fartifact">
<script type="application/ld+json">{"@context":"https://schema.org","@type":"WebPage","name":"Artifact Viewer","description":"Renders Claude artifact bundles as standalone embeddable apps.","url":"https://three.ws/artifact","isPartOf":{"@type":"WebSite","name":"three.ws","url":"https://three.ws"}}</script>
<meta name="robots" content="index, follow, max-image-preview:large, max-snippet:-1">
<meta property="og:locale" content="en_US">
<meta property="og:image:alt" content="Artifact Viewer - three.ws">
<meta name="twitter:site" content="@trythreews">
</head>
<body>
<header>
<div id="nav-container"></div>
</header>
<script src="/nav.js"></script>
<main class="artifact-page">
<header class="hero">
<span class="eyebrow" data-i18n="artifact_index.claude_ai_artifact">Claude.ai artifact</span>
<h1 class="headline" data-i18n="artifact_index.embed_your_agent_in_claude_ai">Embed your agent in Claude.ai</h1>
<p class="lede" data-i18n="artifact_index.paste_a_single_url_into_a_claude">
Paste a single URL into a Claude conversation. The response is one self-contained
HTML document: three.js, GLTFLoader, and your agent's GLB are all inlined. No
script blocked by Claude's sandbox CSP, no fetch that ever leaves the page.
</p>
</header>
<section class="builder">
<section class="panel" aria-labelledby="config-h">
<h2 id="config-h" data-i18n="artifact_index.configure">Configure</h2>
<div class="field">
<label for="agentIdInput" data-i18n="artifact_index.agent_id">Agent ID</label>
<input
type="text"
id="agentIdInput"
placeholder="e.g. 27a0f649-3b59-4552-bb0b-faf616ac448b"
autocomplete="off"
spellcheck="false"
/>
</div>
<div class="picker">
<div class="picker-head">
<h3 id="picker-h" data-i18n="artifact_index.public_agents_you_can_embed">Public agents you can embed</h3>
<a class="linklike" href="/agents" data-i18n="artifact_index.browse_all">Browse all</a>
</div>
<div id="pickerBody" role="group" aria-labelledby="picker-h" aria-busy="true">
<div class="picker-grid" aria-hidden="true">
<div class="picker-skeleton"></div>
<div class="picker-skeleton"></div>
<div class="picker-skeleton"></div>
<div class="picker-skeleton"></div>
</div>
</div>
</div>
<div class="field-row">
<div class="field">
<label for="themeInput" data-i18n="artifact_index.theme">Theme</label>
<select id="themeInput">
<option value="dark" data-i18n="artifact_index.dark">dark</option>
<option value="light" data-i18n="artifact_index.light">light</option>
</select>
</div>
<div class="field">
<label for="idleInput" data-i18n="artifact_index.idle_clip">Idle clip</label>
<input
type="text"
id="idleInput"
placeholder="(default)"
autocomplete="off"
spellcheck="false"
/>
</div>
</div>
<div class="field">
<label for="bgInput" data-i18n="artifact_index.background_hex_optional">Background hex (optional)</label>
<input
type="text"
id="bgInput"
placeholder="1a0533"
maxlength="7"
autocomplete="off"
spellcheck="false"
aria-describedby="bgHint"
/>
<span class="field-hint" id="bgHint" role="status" aria-live="polite"></span>
</div>
<div class="btn-row">
<button class="btn" id="btnGenerate" type="button" data-i18n="artifact_index.generate">Generate</button>
<button class="btn ghost" id="btnReload" type="button" disabled data-i18n="artifact_index.reload">Reload</button>
</div>
<div class="stats" id="stats" hidden>
<div class="stat">
<span class="label" data-i18n="artifact_index.artifact">Artifact</span>
<span class="value" id="statSize">…</span>
</div>
<div class="stat">
<span class="label" data-i18n="artifact_index.fetch">Fetch</span>
<span class="value" id="statFetch">…</span>
</div>
<div class="stat">
<span class="label" data-i18n="artifact_index.render">Render</span>
<span class="value" id="statRender">…</span>
</div>
<div class="stat">
<span class="label" data-i18n="artifact_index.sandbox">Sandbox</span>
<span class="value" id="statSandbox">…</span>
</div>
</div>
<details class="snippet">
<summary data-i18n="artifact_index.claude_artifact_sandbox_csp">Claude artifact sandbox CSP</summary>
<div class="csp-line" id="cspText">Loading the vendored sandbox CSP…</div>
</details>
</section>
<section class="panel preview" aria-labelledby="preview-h">
<h2 id="preview-h" data-i18n="artifact_index.live_preview">Live preview</h2>
<div class="preview-frame">
<iframe
id="previewFrame"
title="Claude.ai artifact preview"
sandbox="allow-scripts"
referrerpolicy="no-referrer"
></iframe>
<div class="preview-overlay" id="previewOverlay">
<div>Enter an agent ID and press <strong data-i18n="artifact_index.generate_2">Generate</strong></div>
</div>
</div>
<div class="btn-row">
<button class="btn" id="btnCopyUrl" type="button" disabled data-i18n="artifact_index.copy_url">Copy URL</button>
<button class="btn ghost" id="btnCopyHtml" type="button" disabled data-i18n="artifact_index.copy_raw_html">
Copy raw HTML
</button>
<button class="btn ghost" id="btnOpen" type="button" disabled data-i18n="artifact_index.open_in_tab">Open in tab</button>
</div>
<details class="snippet">
<summary data-i18n="artifact_index.paste_into_claude_snippet">Paste-into-Claude snippet</summary>
<pre id="claudeSnippet">Generate to see the snippet…</pre>
</details>
</section>
</section>
<section class="facts">
<div class="fact">
<h3 data-i18n="artifact_index.self_contained">Self-contained</h3>
<p data-i18n="artifact_index.three_js_gltfloader_and_the_glb_are">
three.js, GLTFLoader, and the GLB are all inlined. The page renders with zero
network calls, fully compatible with Claude's sandbox CSP that forbids fetch
and external scripts.
</p>
</div>
<div class="fact">
<h3 data-i18n="artifact_index.sandbox_locked_csp">Sandbox-locked CSP</h3>
<p data-i18n="artifact_index.the_response_sets_a_csp_mirroring_claude">
The response sets a CSP mirroring Claude's own, so behavior in the live preview
matches behavior inside Claude.ai. No surprises between staging and prod.
</p>
</div>
<div class="fact">
<h3 data-i18n="artifact_index.size_budget">Size budget</h3>
<p data-i18n="artifact_index.models_over_6_mb_are_rejected_because">
Models over 6 MB are rejected, because Claude's artifact panel can hang on huge
inlined payloads. Inlining base64-encodes the model, which costs four bytes per
three, on top of the flat 565 KB viewer: a 6 MB model lands at roughly 8.6 MB of
HTML. That total, not the model, is what the size stat grades.
</p>
</div>
</section>
</main>
<div class="toast" id="toast" role="status" aria-live="polite"></div>
<script type="module">
const $ = (id) => document.getElementById(id);
const els = {
agentInput: $('agentIdInput'),
themeInput: $('themeInput'),
idleInput: $('idleInput'),
bgInput: $('bgInput'),
btnGenerate: $('btnGenerate'),
btnReload: $('btnReload'),
btnCopyUrl: $('btnCopyUrl'),
btnCopyHtml: $('btnCopyHtml'),
btnOpen: $('btnOpen'),
frame: $('previewFrame'),
overlay: $('previewOverlay'),
stats: $('stats'),
statSize: $('statSize'),
statFetch: $('statFetch'),
statRender: $('statRender'),
statSandbox: $('statSandbox'),
snippet: $('claudeSnippet'),
toast: $('toast'),
cspText: $('cspText'),
pickerBody: $('pickerBody'),
bgHint: $('bgHint'),
};
const state = { url: null, html: null, renderToken: 0 };
// Public directory feed for the picker. `avatar=1` is load-bearing: an agent
// without a publicly readable GLB cannot be rendered as an artifact at all,
// so offering it here would hand the visitor a pick that can only 422.
const AGENTS_ENDPOINT = '/api/agents/public?sort=popular&limit=12&avatar=1';
// What the size stat grades against. /api/artifact caps the MODEL at 6 MiB
// (MAX_GLB_BYTES) and inlines it as base64, which costs four bytes per three,
// on top of the flat 565 KB viewer. So the largest artifact the endpoint can
// return is about 8.6 MB, and every byte under that is one it already
// approved. Grading those base64 bytes against raw-model numbers is what made
// a legal 7 MB artifact read amber and anything from a model over ~5.6 MiB
// read red, contradicting the endpoint that had just accepted it.
const MAX_MODEL_BYTES = 6 * 1024 * 1024;
const VIEWER_BYTES = 565 * 1024;
const ARTIFACT_CEILING_BYTES = Math.ceil(MAX_MODEL_BYTES / 3) * 4 + VIEWER_BYTES;
// An artifact only becomes a problem as it approaches that ceiling, so the
// bands are shares of it. Over 100% means the endpoint emitted more than its
// own cap allows, which is a server-side change this page should shout about.
const SIZE_WARN_RATIO = 0.7;
// Beyond this the iframe is treated as having failed to come up rather than
// leaving the render stat blank forever.
const RENDER_TIMEOUT_MS = 30000;
// Actionable next step per error code from /api/artifact. The endpoint's own
// error_description says what went wrong; this says what to do about it.
const ERROR_HINTS = {
not_found: 'Pick one of the public agents on the left, or paste an agent ID from its profile page.',
no_avatar: 'That agent has no avatar yet. Generate one at /create, then come back.',
too_large: 'Re-export the avatar under 6 MB, or point the artifact at a lighter GLB.',
invalid_request: 'Agent IDs are UUIDs. Copy one from an agent profile page, or pick an agent on the left.',
rate_limited: 'The public read limit is 600 requests a minute per IP. Wait a moment and retry.',
upstream_error: 'The model host did not answer. Retry, or use a different avatar.',
};
function clear(node) {
while (node.firstChild) node.removeChild(node.firstChild);
}
function el(tag, className, text) {
const node = document.createElement(tag);
if (className) node.className = className;
if (text != null) node.textContent = text;
return node;
}
function showLoadingOverlay(message) {
els.overlay.hidden = false;
els.overlay.classList.remove('error');
clear(els.overlay);
els.overlay.append(el('div', 'spinner'), el('div', null, message));
}
function showErrorOverlay(message, hint) {
els.overlay.hidden = false;
els.overlay.classList.add('error');
clear(els.overlay);
els.overlay.appendChild(el('div', null, message));
if (hint) els.overlay.appendChild(el('div', 'hint', hint));
const retry = el('button', 'btn ghost', 'Try again');
retry.type = 'button';
retry.addEventListener('click', generate);
els.overlay.appendChild(retry);
}
function hideOverlay() {
els.overlay.hidden = true;
}
function toast(msg) {
els.toast.textContent = msg;
els.toast.classList.add('show');
clearTimeout(toast._t);
toast._t = setTimeout(() => els.toast.classList.remove('show'), 1600);
}
function normalizedBg() {
const bg = els.bgInput.value.trim().replace(/^#/, '');
return /^[0-9a-f]{6}$/i.test(bg) ? bg.toLowerCase() : '';
}
function buildUrl(agentId) {
const url = new URL('/api/artifact', window.location.origin);
url.searchParams.set('agent', agentId);
if (els.themeInput.value === 'light') url.searchParams.set('theme', 'light');
const idle = els.idleInput.value.trim();
if (idle) url.searchParams.set('idle', idle);
const bg = normalizedBg();
if (bg) url.searchParams.set('bg', bg);
return url.toString();
}
// Keep the address bar carrying the whole configuration, not just the agent:
// the link a user copies out of the bar has to rebuild the same artifact.
function syncQueryString(agentId) {
const p = new URLSearchParams();
p.set('agentId', agentId);
if (els.themeInput.value === 'light') p.set('theme', 'light');
const idle = els.idleInput.value.trim();
if (idle) p.set('idle', idle);
const bg = normalizedBg();
if (bg) p.set('bg', bg);
history.replaceState({}, '', `${window.location.pathname}?${p.toString()}`);
}
function fmtBytes(n) {
if (n < 1024) return `${n} B`;
if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)} KB`;
return `${(n / 1024 / 1024).toFixed(2)} MB`;
}
function setBusy(busy) {
els.btnGenerate.disabled = busy;
els.btnReload.disabled = busy || !state.url;
if (busy) {
els.btnCopyUrl.disabled = true;
els.btnCopyHtml.disabled = true;
els.btnOpen.disabled = true;
els.stats.hidden = true;
}
}
// Hand the document to the iframe and time how long the frame takes to
// report it loaded: parsed the HTML and ran the inlined three.js + viewer.
// That is the honest ceiling on how fast Claude's panel can show anything,
// and it is the only render signal the parent can read, because the frame is
// a sandboxed opaque origin. The token guards against a second Generate
// landing while the first frame is still coming up: only the newest run may
// write the stat.
function renderIntoFrame(html) {
const token = ++state.renderToken;
const start = performance.now();
els.statRender.textContent = '…';
els.statRender.className = 'value';
els.statRender.title = 'Time for the sandboxed frame to parse and run the artifact.';
let settled = false;
const settle = (text, cls) => {
if (settled || token !== state.renderToken) return;
settled = true;
clearTimeout(timer);
els.frame.removeEventListener('load', onLoad);
els.statRender.textContent = text;
els.statRender.className = 'value ' + cls;
};
const onLoad = () => {
const ms = performance.now() - start;
settle(`${ms.toFixed(0)} ms`, ms > 8000 ? 'bad' : ms > 3000 ? 'warn' : 'ok');
};
const timer = setTimeout(
() => settle(`> ${(RENDER_TIMEOUT_MS / 1000).toFixed(0)} s`, 'bad'),
RENDER_TIMEOUT_MS,
);
els.frame.addEventListener('load', onLoad);
els.frame.srcdoc = html;
}
async function generate() {
const agentId = els.agentInput.value.trim();
if (!agentId) {
showErrorOverlay(
'Enter an agent ID first.',
'Pick one of the public agents on the left, or paste an ID from an agent profile.',
);
els.agentInput.focus();
return;
}
const url = buildUrl(agentId);
state.url = url;
syncQueryString(agentId);
markSelected(agentId);
showLoadingOverlay('Fetching artifact…');
setBusy(true);
// Retire any frame still coming up from a previous run, so its timing can
// never land under the artifact this run is about to fetch.
state.renderToken++;
const t0 = performance.now();
let res;
try {
res = await fetch(url, { credentials: 'omit' });
} catch (err) {
setBusy(false);
showErrorOverlay(
`Could not reach the artifact endpoint: ${err.message}`,
'Check your connection, then try again.',
);
return;
}
if (!res.ok) {
let body = null;
try {
body = await res.json();
} catch {
body = null;
}
const msg = body?.error_description || body?.error || `HTTP ${res.status}`;
setBusy(false);
showErrorOverlay(msg, ERROR_HINTS[body?.error] || 'Adjust the configuration and try again.');
return;
}
const html = await res.text();
const fetchMs = performance.now() - t0;
state.html = html;
const cspHeader = res.headers.get('content-security-policy') || '';
const sandboxOk = /frame-ancestors\s+\*/.test(cspHeader);
const sizeBytes = new Blob([html]).size;
const ceilingShare = sizeBytes / ARTIFACT_CEILING_BYTES;
els.statSize.textContent = fmtBytes(sizeBytes);
els.statSize.className =
'value ' + (ceilingShare > 1 ? 'bad' : ceilingShare > SIZE_WARN_RATIO ? 'warn' : 'ok');
els.statSize.title = `${Math.round(ceilingShare * 100)}% of the ${fmtBytes(
ARTIFACT_CEILING_BYTES,
)} ceiling a 6 MB model produces once inlined`;
els.statFetch.textContent = `${fetchMs.toFixed(0)} ms`;
els.statFetch.className = 'value ' + (fetchMs > 5000 ? 'bad' : fetchMs > 2000 ? 'warn' : 'ok');
els.statFetch.title = 'Time for /api/artifact to return the whole document.';
els.statSandbox.textContent = sandboxOk ? 'compliant' : 'mismatch';
els.statSandbox.className = 'value ' + (sandboxOk ? 'ok' : 'bad');
els.stats.hidden = false;
renderIntoFrame(html);
hideOverlay();
setBusy(false);
els.btnCopyUrl.disabled = false;
els.btnCopyHtml.disabled = false;
els.btnOpen.disabled = false;
els.snippet.textContent = "Here's my agent for this conversation:\n" + state.url;
}
async function copyText(text, okMessage, fallbackMessage) {
try {
if (!navigator.clipboard) throw new Error('clipboard unavailable');
await navigator.clipboard.writeText(text);
toast(okMessage);
} catch {
toast(fallbackMessage);
}
}
// ── Public agent picker ──────────────────────────────────────────────────
function initialTile(name) {
const letter = (String(name || '?').trim()[0] || '?').toUpperCase();
const tile = el('span', 'initial', letter);
tile.setAttribute('aria-hidden', 'true');
return tile;
}
function pickerSkeleton() {
const grid = el('div', 'picker-grid');
grid.setAttribute('aria-hidden', 'true');
for (let i = 0; i < 4; i++) grid.appendChild(el('div', 'picker-skeleton'));
return grid;
}
function markSelected(agentId) {
for (const item of els.pickerBody.querySelectorAll('.picker-item')) {
item.setAttribute('aria-pressed', item.dataset.agentId === agentId ? 'true' : 'false');
}
}
function renderPickerNote(message, isError, action) {
const wrap = el('div', 'picker');
wrap.appendChild(el('p', 'picker-note' + (isError ? ' error' : ''), message));
if (action) wrap.appendChild(action);
clear(els.pickerBody);
els.pickerBody.appendChild(wrap);
}
function renderPickerGrid(agents) {
const grid = el('div', 'picker-grid');
for (const agent of agents) {
const btn = el('button', 'picker-item');
btn.type = 'button';
btn.dataset.agentId = agent.id;
btn.setAttribute('aria-pressed', 'false');
btn.title = `${agent.name || 'Agent'} (${agent.id})`;
if (agent.avatar_thumbnail) {
const img = document.createElement('img');
img.src = agent.avatar_thumbnail;
img.alt = `${agent.name || 'Agent'} avatar`;
img.loading = 'lazy';
img.decoding = 'async';
img.width = 26;
img.height = 26;
// A thumbnail that 404s degrades to the initial tile instead of the
// browser's broken-image glyph.
img.addEventListener('error', () => img.replaceWith(initialTile(agent.name)));
btn.appendChild(img);
} else {
btn.appendChild(initialTile(agent.name));
}
btn.appendChild(el('span', 'name', agent.name || agent.id));
btn.addEventListener('click', () => {
els.agentInput.value = agent.id;
generate();
});
grid.appendChild(btn);
}
clear(els.pickerBody);
els.pickerBody.appendChild(grid);
markSelected(els.agentInput.value.trim());
}
async function loadAgents() {
els.pickerBody.setAttribute('aria-busy', 'true');
clear(els.pickerBody);
els.pickerBody.appendChild(pickerSkeleton());
let data;
try {
const res = await fetch(AGENTS_ENDPOINT, { headers: { accept: 'application/json' } });
if (!res.ok) throw new Error(`HTTP ${res.status}`);
data = await res.json();
} catch (err) {
els.pickerBody.setAttribute('aria-busy', 'false');
const retry = el('button', 'linklike', 'Retry');
retry.type = 'button';
retry.addEventListener('click', loadAgents);
renderPickerNote(`Could not load the agent directory (${err.message}).`, true, retry);
return;
}
els.pickerBody.setAttribute('aria-busy', 'false');
const agents = Array.isArray(data?.agents) ? data.agents : [];
if (!agents.length) {
const link = document.createElement('a');
link.className = 'linklike';
link.href = '/create';
link.textContent = 'Create an agent';
renderPickerNote(
'No public agent carries an embeddable avatar yet. Paste an agent ID above, or make one.',
false,
link,
);
return;
}
renderPickerGrid(agents);
}
els.btnGenerate.addEventListener('click', generate);
els.btnReload.addEventListener('click', generate);
els.agentInput.addEventListener('keydown', (e) => {
if (e.key === 'Enter') generate();
});
els.agentInput.addEventListener('input', () => markSelected(els.agentInput.value.trim()));
els.bgInput.addEventListener('input', () => {
const raw = els.bgInput.value.trim().replace(/^#/, '');
const bad = raw.length > 0 && !/^[0-9a-f]{6}$/i.test(raw);
els.bgInput.setAttribute('aria-invalid', bad ? 'true' : 'false');
els.bgHint.textContent = bad ? 'Six hex digits, for example 1a0533.' : '';
});
els.btnCopyUrl.addEventListener('click', () => {
if (!state.url) return;
copyText(
state.url,
'URL copied',
'Copy blocked by the browser. Use "Open in tab" and copy from the address bar.',
);
});
els.btnCopyHtml.addEventListener('click', () => {
if (!state.html) return;
copyText(
state.html,
`Raw HTML copied (${fmtBytes(new Blob([state.html]).size)})`,
'Copy blocked by the browser. Open the artifact in a tab and save the page instead.',
);
});
els.btnOpen.addEventListener('click', () => {
if (state.url) window.open(state.url, '_blank', 'noopener');
});
// The sandbox CSP is served from our own origin (public/claude-artifact-csp.txt),
// the same vendored bytes tests/api/artifact.test.js pins the endpoint against.
// `node scripts/refresh-claude-csp.mjs` refreshes it from the upstream scraper.
(function loadCsp() {
fetch('/claude-artifact-csp.txt', { headers: { accept: 'text/plain' } })
.then((r) => (r.ok ? r.text() : Promise.reject(new Error(`HTTP ${r.status}`))))
.then((txt) => {
els.cspText.textContent = txt.trim();
})
.catch(() => {
els.cspText.textContent =
'Could not load /claude-artifact-csp.txt. The locked-in copy is in specs/CLAUDE_ARTIFACT.md.';
});
})();
(function init() {
const p = new URLSearchParams(window.location.search);
if (p.get('theme') === 'light') els.themeInput.value = 'light';
const idle = p.get('idle');
if (idle) els.idleInput.value = idle.slice(0, 64);
const bg = p.get('bg');
if (bg) els.bgInput.value = bg.replace(/^#/, '').slice(0, 6);
const initialId = p.get('agentId');
if (initialId) {
els.agentInput.value = initialId;
generate();
}
loadAgents();
})();
</script>
<div id="footer-container"></div>
<script src="/footer.js" defer></script>
<!-- Runtime i18n: detects locale, swaps annotated copy, mounts <lang-switcher>. -->
<script type="module" src="/i18n.js"></script>
</body>
</html>