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.

chore: agent-edit, dashboard, widgets api, viewer tweaks

nirholasfb34c3c5cf62
diff --git a/agent-edit.html b/agent-edit.html
index 2421b6715..35b35734f 100644
--- a/agent-edit.html
+++ b/agent-edit.html
@@ -18,6 +18,7 @@
<link rel="shortcut icon" href="/favicon.ico" />
<link rel="stylesheet" href="/style.css" />
<link rel="stylesheet" href="/fonts/fonts.css" />
+ <link rel="stylesheet" href="/src/pump/launch-token-modal.css" />
<style>
body {
overflow: auto;
@@ -912,6 +913,11 @@
aria-labelledby="tab-monetization"
hidden
>
+ <div class="form-group" id="launch-token-group">
+ <label class="form-label">Agent Token</label>
+ <p class="note" style="font-size: 0.764rem; color: rgba(255,255,255,0.4); margin-top: -0.5rem; margin-bottom: 1rem;">Launch a pump.fun bonding-curve token tied to this agent. Buyers fund the curve, fees route to the agent.</p>
+ <div id="launch-token-state" class="muted">Loading…</div>
+ </div>
<div class="form-group">
<label class="form-label">Skill Prices</label>
<p class="note" style="font-size: 0.764rem; color: rgba(255,255,255,0.4); margin-top: -0.5rem; margin-bottom: 1rem;">Set a price for your skills to be used by other agents. Leave blank for free skills. Prices are set in USDC on Solana.</p>
diff --git a/api/widgets/[id]/[action].js b/api/widgets/[id]/[action].js
index e222365a5..9d85ea0ef 100644
--- a/api/widgets/[id]/[action].js
+++ b/api/widgets/[id]/[action].js
@@ -37,15 +37,50 @@ export default wrap(async (req, res) => {
// ── chat ───────────────────────────────────────────────────────────────────
-const ANTHROPIC_URL = 'https://api.anthropic.com/v1/messages';
-const DEFAULT_MODEL = 'claude-sonnet-4-6';
const DEFAULT_MAX_TOKENS = 1024;
const HARD_MAX_TOKENS = 4096;
const SAFE_SKILLS = new Set(['speak', 'wave', 'lookAt', 'playClip', 'remember']);
+// LLM provider routing — mirrors /api/chat.js. Anthropic is the historical
+// default; the OpenAI-compatible providers (OpenRouter / Groq / OpenAI) ship
+// here too so the talking-agent widget can pick any configured brain.
+const PROVIDERS = {
+ anthropic: {
+ envKey: 'ANTHROPIC_API_KEY',
+ defaultModel: 'claude-sonnet-4-6',
+ url: 'https://api.anthropic.com/v1/messages',
+ style: 'anthropic',
+ },
+ openrouter: {
+ envKey: 'OPENROUTER_API_KEY',
+ defaultModel: 'meta-llama/llama-3.3-70b-instruct:free',
+ url: 'https://openrouter.ai/api/v1/chat/completions',
+ style: 'openai',
+ extraHeaders: { 'HTTP-Referer': 'https://three.ws', 'X-Title': 'three.ws widget' },
+ },
+ groq: {
+ envKey: 'GROQ_API_KEY',
+ defaultModel: 'llama-3.3-70b-versatile',
+ url: 'https://api.groq.com/openai/v1/chat/completions',
+ style: 'openai',
+ },
+ openai: {
+ envKey: 'OPENAI_API_KEY',
+ defaultModel: 'gpt-4o-mini',
+ url: 'https://api.openai.com/v1/chat/completions',
+ style: 'openai',
+ },
+};
+
+// Brain settings that surface in widget config. `auto` picks the first
+// configured provider; `custom`/`none` keep their legacy meanings.
+const BRAIN_PROVIDERS = new Set(['auto', 'anthropic', 'openrouter', 'groq', 'openai']);
+
const chatBody = z.object({
message: z.string().trim().min(1).max(4000),
+ provider: z.enum(['auto', 'anthropic', 'openrouter', 'groq', 'openai']).optional(),
+ model: z.string().min(1).max(160).optional(),
history: z
.array(
z.object({
@@ -133,7 +168,17 @@ async function handleChat(req, res) {
const body = parse(chatBody, await readJson(req));
- const provider = cfg.brainProvider || 'anthropic';
+ // Owner config wins. If the owner explicitly set 'none' or 'custom', the
+ // visitor cannot override. Otherwise (auto or a named LLM provider) the
+ // visitor's `provider` / `model` choice from the chat header dropdown is
+ // honoured, but still constrained to the supported set.
+ const cfgProvider = cfg.brainProvider || 'auto';
+ let provider = cfgProvider;
+ let requestedModel = cfg.brainModel || null;
+ if (BRAIN_PROVIDERS.has(cfgProvider) && body.provider && BRAIN_PROVIDERS.has(body.provider)) {
+ provider = body.provider;
+ if (body.model) requestedModel = body.model;
+ }
const allowedSkills = filterSkills(cfg.skills);
// Open SSE stream.
@@ -152,14 +197,24 @@ async function handleChat(req, res) {
} else if (provider === 'custom') {
result = await callCustomProxy(cfg.proxyURL, body, cfg, allowedSkills);
} else {
- result = await callAnthropic({
- message: body.message,
- history: body.history,
- systemPrompt: buildSystemPrompt(cfg, widget),
- temperature: Number(cfg.temperature) || 0.7,
- maxTurns: Math.min(20, Math.max(1, Number(cfg.maxTurns) || 20)),
- allowedSkills,
- });
+ const route = pickProvider(provider, requestedModel);
+ if (!route) {
+ result = {
+ reply:
+ "I'm not configured to answer just yet — no chat provider key is set on this site.",
+ actions: [],
+ };
+ } else {
+ result = await callLLM({
+ route,
+ message: body.message,
+ history: body.history,
+ systemPrompt: buildSystemPrompt(cfg, widget),
+ temperature: Number(cfg.temperature) || 0.7,
+ maxTurns: Math.min(20, Math.max(1, Number(cfg.maxTurns) || 20)),
+ allowedSkills,
+ });
+ }
}
writeSse(res, 'message', { reply: result.reply || '', actions: result.actions || [] });
@@ -180,7 +235,28 @@ async function handleChat(req, res) {
// ── Brain dispatchers ──────────────────────────────────────────────────────
-async function callAnthropic({
+function pickProvider(requested, requestedModel) {
+ const order =
+ requested && requested !== 'auto'
+ ? [requested, ...Object.keys(PROVIDERS).filter((p) => p !== requested)]
+ : ['anthropic', 'openrouter', 'groq', 'openai'];
+
+ for (const name of order) {
+ const cfg = PROVIDERS[name];
+ const apiKey = process.env[cfg.envKey];
+ if (!apiKey) continue;
+ const model =
+ (requested === name && requestedModel) ||
+ (requested === 'auto' && requestedModel) ||
+ process.env.CHAT_MODEL ||
+ cfg.defaultModel;
+ return { name, cfg, apiKey, model };
+ }
+ return null;
+}
+
+async function callLLM({
+ route,
message,
history,
systemPrompt,
@@ -188,14 +264,6 @@ async function callAnthropic({
maxTurns,
allowedSkills,
}) {
- const apiKey = process.env.ANTHROPIC_API_KEY;
- if (!apiKey) {
- return {
- reply: "I'm not configured to answer just yet — the owner needs to set ANTHROPIC_API_KEY.",
- actions: [],
- };
- }
- const model = process.env.CHAT_MODEL || DEFAULT_MODEL;
const maxTokens = clampInt(
parseInt(process.env.CHAT_MAX_TOKENS || '', 10) || DEFAULT_MAX_TOKENS,
128,
@@ -208,8 +276,39 @@ async function callAnthropic({
const tools = SKILL_TOOLS.filter((t) => allowedSkills.has(t.name));
+ if (route.cfg.style === 'anthropic') {
+ return callAnthropic({
+ route,
+ messages,
+ systemPrompt,
+ temperature,
+ maxTokens,
+ tools,
+ allowedSkills,
+ });
+ }
+ return callOpenAICompatible({
+ route,
+ messages,
+ systemPrompt,
+ temperature,
+ maxTokens,
+ tools,
+ allowedSkills,
+ });
+}
+
+async function callAnthropic({
+ route,
+ messages,
+ systemPrompt,
+ temperature,
+ maxTokens,
+ tools,
+ allowedSkills,
+}) {
const payload = {
- model,
+ model: route.model,
max_tokens: maxTokens,
temperature,
system: systemPrompt,
@@ -217,10 +316,10 @@ async function callAnthropic({
};
if (tools.length) payload.tools = tools;
- const upstream = await fetch(ANTHROPIC_URL, {
+ const upstream = await fetch(route.cfg.url, {
method: 'POST',
headers: {
- 'x-api-key': apiKey,
+ 'x-api-key': route.apiKey,
'anthropic-version': '2023-06-01',
'content-type': 'application/json',
},
@@ -245,6 +344,64 @@ async function callAnthropic({
return normalizeAnthropic(data, allowedSkills);
}
+async function callOpenAICompatible({
+ route,
+ messages,
+ systemPrompt,
+ temperature,
+ maxTokens,
+ tools,
+ allowedSkills,
+}) {
+ const openaiTools = tools.map((t) => ({
+ type: 'function',
+ function: {
+ name: t.name,
+ description: t.description,
+ parameters: t.input_schema,
+ },
+ }));
+
+ const payload = {
+ model: route.model,
+ max_tokens: maxTokens,
+ temperature,
+ messages: [{ role: 'system', content: systemPrompt }, ...messages],
+ };
+ if (openaiTools.length) {
+ payload.tools = openaiTools;
+ payload.tool_choice = 'auto';
+ }
+
+ const upstream = await fetch(route.cfg.url, {
+ method: 'POST',
+ headers: {
+ Authorization: `Bearer ${route.apiKey}`,
+ 'Content-Type': 'application/json',
+ ...(route.cfg.extraHeaders || {}),
+ },
+ body: JSON.stringify(payload),
+ });
+ if (!upstream.ok) {
+ const text = await upstream.text().catch(() => '');
+ captureException(new Error(`${route.name} upstream ${upstream.status}`), {
+ route: 'widget-chat',
+ provider: route.name,
+ status: upstream.status,
+ body: text.slice(0, 400),
+ });
+ if (process.env.DEBUG === 'true') {
+ console.warn(`[widget-chat] ${route.name}`, upstream.status, text.slice(0, 400));
+ }
+ return {
+ reply: 'I had trouble thinking of a response. Try again in a moment.',
+ actions: [],
+ };
+ }
+ const data = await upstream.json();
+ return normalizeOpenAI(data, allowedSkills);
+}
+
async function callCustomProxy(proxyURL, body, cfg, allowedSkills) {
if (!/^https:\/\//i.test(proxyURL || '')) {
return { reply: 'Custom brain misconfigured — proxyURL must be HTTPS.', actions: [] };
@@ -316,6 +473,29 @@ function normalizeAnthropic(data, allowedSkills) {
return { reply: reply.trim(), actions };
}
+function normalizeOpenAI(data, allowedSkills) {
+ const choice = data?.choices?.[0]?.message || {};
+ const reply = typeof choice.content === 'string' ? choice.content : '';
+ const actions = [];
+ for (const call of choice.tool_calls || []) {
+ const name = call?.function?.name;
+ if (!name || !allowedSkills.has(name)) continue;
+ let args = {};
+ const raw = call.function?.arguments;
+ if (typeof raw === 'string' && raw.trim()) {
+ try {
+ args = JSON.parse(raw);
+ } catch {
+ args = {};
+ }
+ } else if (raw && typeof raw === 'object') {
+ args = raw;
+ }
+ actions.push({ type: name, ...args });
+ }
+ return { reply: reply.trim(), actions };
+}
+
function filterSkills(skillsConfig) {
const out = new Set();
if (skillsConfig && typeof skillsConfig === 'object') {
diff --git a/public/dashboard/dashboard.js b/public/dashboard/dashboard.js
index 7851eb620..78d1a521f 100644
--- a/public/dashboard/dashboard.js
+++ b/public/dashboard/dashboard.js
@@ -305,11 +305,15 @@ function agentCard(a, onRemoved) {
const agentIdEnc = encodeURIComponent(a.id);
const hasAvatar = Boolean(a.avatar_id);
const embedDisabledAttr = hasAvatar ? '' : 'disabled title="Link an avatar (Edit → Avatar) to enable embed"';
+ const token = a.token || a.meta?.token || null;
+ const tokenBadge = token?.mint
+ ? `<span class="tag" title="${attr(token.mint)}" style="background:rgba(120,200,140,0.18); color:#c6f0d6;">$${esc(token.symbol || 'TOKEN')}</span>`
+ : '';
el.innerHTML = `
<div class="preview" data-agent-preview></div>
<h3>${esc(a.name || 'Agent')}</h3>
<p class="meta">${skillCount} skill${skillCount === 1 ? '' : 's'}${wallet ? ' · ' + esc(wallet) : ''} · ${new Date(a.created_at).toLocaleDateString()}</p>
- <div class="row" style="gap:6px; margin-bottom:10px; flex-wrap:wrap">${onchainBadge}</div>
+ <div class="row" style="gap:6px; margin-bottom:10px; flex-wrap:wrap">${onchainBadge}${tokenBadge}</div>
${a.description ? `<p class="meta" style="white-space:normal;color:#aaa;margin:0 0 10px;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden">${esc(a.description)}</p>` : ''}
<details class="agent-inspector" style="margin:0 0 10px;border-top:1px solid #22222e;padding-top:10px">
<summary style="cursor:pointer;font-size:12px;color:#9a8cff;list-style:none">Inspector ▾</summary>
@@ -334,6 +338,9 @@ function agentCard(a, onRemoved) {
<a class="btn sec" href="/agent-edit.html?id=${agentIdEnc}" title="Edit name, persona, avatar, skills">Edit</a>
<button class="btn sec" data-share type="button" title="Copy public agent link">Share</button>
<button class="btn sec" data-embed type="button" ${embedDisabledAttr}>Embed</button>
+ ${token?.mint
+ ? `<a class="btn sec" href="/dashboard/tokens?agent=${agentIdEnc}" title="Open pump.fun token dashboard">Token ↗</a>`
+ : `<button class="btn sec" data-launch type="button" title="Launch a pump.fun token for this agent">🚀 Launch token</button>`}
${a.is_registered ? '' : `<a class="btn sec" href="/deploy${a.avatar_id ? '?avatar=' + encodeURIComponent(a.avatar_id) : ''}" title="Mint as ERC-8004 agent">Deploy on-chain</a>`}
<div class="more-menu-wrap"><button class="btn sec" data-more type="button" aria-haspopup="menu" aria-expanded="false">More ▾</button></div>
</div>
@@ -349,6 +356,35 @@ function agentCard(a, onRemoved) {
if (e.currentTarget.disabled) return;
openAgentEmbedModal(a);
});
+ const launchBtn = el.querySelector('[data-launch]');
+ if (launchBtn) {
+ launchBtn.addEventListener('click', async (e) => {
+ const btn = e.currentTarget;
+ btn.disabled = true;
+ try {
+ const { openLaunchTokenModal } = await import('/src/pump/launch-token-modal.js');
+ const onchain = a.onchain || a.meta?.onchain || null;
+ const needsDeploy = !onchain || onchain.family !== 'solana';
+ openLaunchTokenModal({
+ agentId: a.id,
+ agentName: a.name || 'Agent',
+ imageUrl: a.avatar_thumbnail_url || a.meta?.thumbnail_url || '',
+ needsDeploy,
+ agentForDeploy: needsDeploy
+ ? {
+ id: a.id,
+ name: a.name,
+ description: a.description || '',
+ avatar_id: a.avatar_id || null,
+ skills: a.skills || undefined,
+ }
+ : null,
+ });
+ } finally {
+ btn.disabled = false;
+ }
+ });
+ }
el.querySelector('[data-more]').addEventListener('click', (e) => {
const btn = e.currentTarget;
if (_openMoreMenu?.triggerBtn === btn) {
diff --git a/public/dashboard/index.html b/public/dashboard/index.html
index 710288a94..070d710e6 100644
--- a/public/dashboard/index.html
+++ b/public/dashboard/index.html
@@ -7,6 +7,7 @@
<link rel="icon" href="/favicon.ico" />
<link rel="stylesheet" href="/fonts/fonts.css" />
<link rel="stylesheet" href="/footer.css" />
+ <link rel="stylesheet" href="/src/pump/launch-token-modal.css" />
<style>
:root {
color-scheme: dark;
diff --git a/src/agent-edit.js b/src/agent-edit.js
index b07f510bb..18261a3ea 100644
--- a/src/agent-edit.js
+++ b/src/agent-edit.js
@@ -146,6 +146,7 @@ function parseStrategy(text) {
}
function renderMonetization() {
+ renderLaunchTokenState();
const container = $('skill-prices-list');
const skills = agentData.skills || [];
if (!skills.length) {
@@ -191,6 +192,68 @@ function renderMonetization() {
});
}
+function renderLaunchTokenState() {
+ const host = $('launch-token-state');
+ if (!host) return;
+ host.innerHTML = '';
+ host.classList.remove('muted');
+
+ const token = agentData.token || agentData.meta?.token || null;
+ if (token?.mint) {
+ const dashLink = token.pumpfun_url
+ || (token.cluster === 'devnet'
+ ? `https://explorer.solana.com/address/${token.mint}?cluster=devnet`
+ : `https://pump.fun/${token.mint}`);
+ const row = document.createElement('div');
+ row.style.cssText = 'display:flex;align-items:center;gap:12px;flex-wrap:wrap';
+ row.innerHTML = `
+ <span style="font-weight:600;color:#a4f0bc">$${escapeHtml(token.symbol || 'TOKEN')}</span>
+ <span style="font-family:ui-monospace,monospace;font-size:12px;color:rgba(255,255,255,0.55)">${escapeHtml(token.mint)}</span>
+ `;
+ const view = document.createElement('a');
+ view.href = dashLink;
+ view.target = '_blank';
+ view.rel = 'noopener noreferrer';
+ view.className = 'btn-primary';
+ view.textContent = `View on ${token.cluster === 'devnet' ? 'Solana Explorer' : 'pump.fun'} →`;
+ row.appendChild(view);
+ host.appendChild(row);
+ return;
+ }
+
+ const btn = document.createElement('button');
+ btn.type = 'button';
+ btn.className = 'btn-primary';
+ btn.textContent = '🚀 Launch agent token';
+ btn.addEventListener('click', async () => {
+ btn.disabled = true;
+ try {
+ const { openLaunchTokenModal } = await import('/src/pump/launch-token-modal.js');
+ const onchain = agentData.onchain || agentData.meta?.onchain || null;
+ const needsDeploy = !onchain || onchain.family !== 'solana';
+ const imageUrl = agentData.avatar_thumbnail_url || agentData.meta?.thumbnail_url || '';
+ openLaunchTokenModal({
+ agentId: agentData.id,
+ agentName: agentData.name || 'Agent',
+ imageUrl,
+ needsDeploy,
+ agentForDeploy: needsDeploy
+ ? {
+ id: agentData.id,
+ name: agentData.name,
+ description: agentData.description || '',
+ avatar_id: agentData.avatar_id || null,
+ skills: agentData.skills || undefined,
+ }
+ : null,
+ });
+ } finally {
+ btn.disabled = false;
+ }
+ });
+ host.appendChild(btn);
+}
+
// ── Outfit tab ────────────────────────────────────────────────────────────
// Lazily mount the agent preview + avatar picker only when the user opens
// the tab so we don't pay for a WebGL context up front.
diff --git a/src/viewer.js b/src/viewer.js
index f4a1e4d97..7293eedcf 100644
--- a/src/viewer.js
+++ b/src/viewer.js
@@ -385,14 +385,20 @@ export class Viewer {
const panelFrac = this._panelFrac();
const usableFrac = Math.max(1 - panelFrac, 0.55);
- // Fit full avatar into usable area with breathing room above/below.
- const extentV = (bbSize.y / 2) / usableFrac * 1.10;
+ // Padding around the model. 1.25 leaves ~12.5% margin per side so the
+ // avatar isn't clipped at idle and stays mostly visible during animations
+ // with root motion (Death, Jump, etc).
+ const PAD_V = 1.25;
+ const PAD_H = 1.15;
+
+ const extentV = (bbSize.y / 2) * PAD_V / usableFrac;
const distV = extentV / Math.tan(vFovRad / 2);
- const distH = (bbSize.x / 2 * 1.05) / Math.tan(hFovRad / 2);
+ const distH = (bbSize.x / 2) * PAD_H / Math.tan(hFovRad / 2);
const dist = Math.max(distV, distH);
- // Center look-at on the usable area so the avatar clears the panel.
- const focusY = bbCenter.y + (bbSize.y / 2) - extentV;
+ // Center look-at on the usable area: with no panel focusY = bbCenter.y;
+ // with a bottom panel, shift down so the avatar rises into the upper area.
+ const focusY = bbCenter.y - extentV * panelFrac;
const target = new Vector3(bbCenter.x, focusY, bbCenter.z);
const pos = new Vector3(bbCenter.x + dist * 0.12, focusY, bbCenter.z + dist);
@@ -795,14 +801,20 @@ export class Viewer {
const aspect = Math.max(this.defaultCamera.aspect, 0.01);
const hFovRad = 2 * Math.atan(Math.tan(vFovRad / 2) * aspect);
- const extentV = (bbSize.y / 2) / usableFrac * 1.10;
+ // Same padding as frameContent() — keep both code paths in sync.
+ const PAD_V = 1.25;
+ const PAD_H = 1.15;
+
+ const extentV = (bbSize.y / 2) * PAD_V / usableFrac;
const distV = extentV / Math.tan(vFovRad / 2);
- const distH = (bbSize.x / 2) / Math.tan(hFovRad / 2);
+ const distH = (bbSize.x / 2) * PAD_H / Math.tan(hFovRad / 2);
const dist = Math.max(distV, distH);
- // Shift the look-at point down so the avatar is vertically centered in
- // the usable area — when panelFrac=0 this is essentially 0 (unchanged).
- const focusY = (bbSize.y / 2) - extentV;
+ // Model has been recentered so bbCenter is at world origin (see
+ // setContent above). Center the look-at on the usable area: with no
+ // panel focusY=0; with a bottom panel shift down so the avatar rises
+ // into the usable upper portion of the canvas.
+ const focusY = -extentV * panelFrac;
// Final framed camera (the position the user should end up at).
const framedPos = new Vector3();