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
feat(VanityGrinder): add vanity grinder card for custom Solana address prefixes fix(SolanaWallet): remove unused abort logic and add refresh method
nirholasdb94aaaec03a
diff --git a/api/agents/tokens/[action].js b/api/agents/tokens/[action].jsindex d5b606b97..d7315cd98 100644--- a/api/agents/tokens/[action].js+++ b/api/agents/tokens/[action].js@@ -11,18 +11,7 @@*/import { z } from 'zod';-import {- Connection,- Keypair,- PublicKey,- Transaction,- ComputeBudgetProgram,- SystemProgram,-} from '@solana/web3.js';-import { PumpSdk, getBuyTokenAmountFromSolAmount } from '@pump-fun/pump-sdk';-import BN from 'bn.js';import { createHash } from 'crypto';-import { PutObjectCommand } from '@aws-sdk/client-s3';import { sql } from '../../_lib/db.js';import { getSessionUser } from '../../_lib/auth.js';@@ -33,6 +22,25 @@ import { randomToken } from '../../_lib/crypto.js';import { env } from '../../_lib/env.js';import { r2 } from '../../_lib/r2.js';+// Heavy SDKs (Solana web3, Pump.fun, AWS S3 commands) are dynamic-imported+// inside the handlers that need them. Loading them at module top-level was+// pushing the function over Vercel's cold-start budget and producing+// FUNCTION_INVOCATION_FAILED on every invocation, including launch-quote+// which doesn't even touch them when initial_buy_sol=0.+async function loadSolanaWeb3() {+ return import('@solana/web3.js');+}+async function loadPumpSdk() {+ const [pump, BNmod] = await Promise.all([+ import('@pump-fun/pump-sdk'),+ import('bn.js').then((m) => m.default || m),+ ]);+ return { ...pump, BN: BNmod };+}+async function loadS3Commands() {+ return import('@aws-sdk/client-s3');+}+function rpcUrl(cluster) {return cluster === 'devnet'? process.env.SOLANA_RPC_URL_DEVNET || 'https://api.devnet.solana.com'@@ -102,6 +110,7 @@ async function pinTokenMetadata({ name, symbol, description, image }) {const hash = createHash('sha256').update(bytes).digest('hex');const stub = `bafkreigenerated${hash.slice(0, 40)}`;const key = `token-metadata/${Date.now()}-${Math.random().toString(36).slice(2)}.json`;+ const { PutObjectCommand } = await loadS3Commands();await r2.send(new PutObjectCommand({Bucket: env.S3_BUCKET,@@ -162,6 +171,9 @@ async function handleLaunchPrep(req, res) {});// 4. Build the launch tx+ const { Connection, Keypair, PublicKey, Transaction, ComputeBudgetProgram } =+ await loadSolanaWeb3();+ const { PumpSdk, getBuyTokenAmountFromSolAmount, BN } = await loadPumpSdk();const conn = new Connection(rpcUrl(body.cluster), 'confirmed');const sdk = new PumpSdk(conn);@@ -265,11 +277,6 @@ async function handleLaunchPrep(req, res) {});}-// Make sure SystemProgram import isn't tree-shaken away (some bundlers complain-// about unused imports). It's a peer for compute-budget instructions on some-// Pump.fun program versions.-void SystemProgram;-// ── launch-confirm ───────────────────────────────────────────────────────────const launchConfirmSchema = z.object({@@ -303,6 +310,7 @@ async function handleLaunchConfirm(req, res) {}// Verify on-chain+ const { Connection } = await loadSolanaWeb3();const conn = new Connection(rpcUrl(prep.cluster), 'confirmed');const deadline = Date.now() + 30_000;@@ -415,6 +423,8 @@ async function handleLaunchQuote(req, res) {let buyEstimate = null;if (q.initial_buy_sol > 0) {try {+ const { Connection } = await loadSolanaWeb3();+ const { PumpSdk, getBuyTokenAmountFromSolAmount, BN } = await loadPumpSdk();const conn = new Connection(rpcUrl(q.cluster), 'confirmed');const sdk = new PumpSdk(conn);const global = await sdk.fetchGlobal();diff --git a/src/agent-home.js b/src/agent-home.jsindex d9ddf7721..319c2783d 100644--- a/src/agent-home.js+++ b/src/agent-home.js@@ -12,6 +12,7 @@ import { ACTION_TYPES } from './agent-protocol.js';import { MEMORY_TYPES } from './agent-memory.js';import { mountPumpFunCard } from './agent-home-pumpfun.js';import { mountAgentSolanaWalletCard } from './agent-solana-wallet.js';+import { mountAgentVanityGrinderCard } from './agent-vanity-grinder.js';import { mountClaimsPanel } from './agent-home-claims.js';const ACTION_ICONS = {@@ -203,11 +204,13 @@ export class AgentHome {};// Solana wallet card — owner only. Lets the user provision a random- // or vanity Solana wallet for the agent. On success, lazy-mount the- // pump.fun card if it wasn't already mounted.+ // Solana wallet for the agent. On success, lazy-mount the pump.fun+ // card if it wasn't already mounted. The vanity grinder is a sibling+ // card so the wallet UI stays focused on identity + balance.if (this.identity?.id && this.identity?.isOwner !== false) {+ let walletCard = null;try {- mountAgentSolanaWalletCard({+ walletCard = mountAgentSolanaWalletCard({panel,identity: this.identity,onProvisioned: () => mountPumpIfReady(),@@ -215,6 +218,18 @@ export class AgentHome {} catch {/* card is optional */}+ try {+ mountAgentVanityGrinderCard({+ panel,+ identity: this.identity,+ onProvisioned: () => {+ walletCard?.refresh?.();+ mountPumpIfReady();+ },+ });+ } catch {+ /* card is optional */+ }}mountPumpIfReady();diff --git a/src/agent-solana-wallet.js b/src/agent-solana-wallet.jsindex ed5e9cce1..ae7bc4003 100644--- a/src/agent-solana-wallet.js+++ b/src/agent-solana-wallet.js@@ -245,14 +245,12 @@ export function mountAgentSolanaWalletCard({ panel, identity, onProvisioned }) {sol: null,lamports: null,busy: false,- progress: null,err: null,activity: [],activityLoaded: false,airdropping: false,airdropMsg: null,};- let abort = null;let balanceTimer = null;async function loadFromServer() {@@ -477,9 +475,9 @@ export function mountAgentSolanaWalletCard({ panel, identity, onProvisioned }) {return {destroy: () => {stopBalancePoll();- abort?.abort();wrapper.remove();},+ refresh: () => loadFromServer().catch(() => {}),};}@@ -494,9 +492,3 @@ function _propagate(identity, data) {};}-function formatRate(n) {- if (!n) return '0';- if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(1)}M`;- if (n >= 1_000) return `${(n / 1_000).toFixed(1)}k`;- return Math.round(n).toString();-}diff --git a/src/agent-vanity-grinder.js b/src/agent-vanity-grinder.jsnew file mode 100644index 000000000..3ae7fce8a--- /dev/null+++ b/src/agent-vanity-grinder.js@@ -0,0 +1,205 @@+/**+ * Agent vanity grinder — standalone card for picking & grinding a custom+ * Solana address prefix. Lives next to the wallet card on the agent home+ * panel; uses the wallet provisioning API to apply the ground keypair.+ *+ * On mount:+ * - GET /api/agents/:id/solana to know if a wallet already exists.+ * - 403 → hide (owner-only). 404 → show "generate vanity wallet" affordance.+ * - 200 → show "regrind" affordance. Click confirms a destructive replace.+ */++import { openVanityModal } from './erc8004/vanity-modal.js';+import {+ fetchAgentSolanaWallet,+ provisionAgentSolanaWallet,+ deleteAgentSolanaWallet,+} from './agent-solana-wallet.js';++const STYLE = `+.agent-vanity-grinder-details { margin: .85rem 0; }+.agent-vanity-grinder-summary { font: 11px/1.4 system-ui, sans-serif; color: rgba(230,230,234,0.4); cursor: pointer; list-style: none; padding: .2rem 0; user-select: none; }+.agent-vanity-grinder-summary::-webkit-details-marker { display: none; }+.agent-vanity-grinder-summary::before { content: '▸ '; font-size: .65rem; }+.agent-vanity-grinder-details[open] .agent-vanity-grinder-summary::before { content: '▾ '; }+.agent-vanity-grinder { border: 1px solid rgba(255,255,255,0.08); border-radius: 10px; padding: .85rem 1rem; margin: .4rem 0 0; font: 13px/1.4 system-ui, sans-serif; background: rgba(255,255,255,0.03); color: #e6e6ea; }+.agent-vanity-grinder h3 { margin: 0 0 .25rem; font-size: .85rem; font-weight: 600; color: #f2f2f5; }+.agent-vanity-grinder .sub { color: rgba(230,230,234,0.6); font-size: .78rem; margin: 0 0 .65rem; }+.agent-vanity-grinder .row { display: flex; gap: .5rem; align-items: center; margin-top: .2rem; flex-wrap: wrap; }+.agent-vanity-grinder button { font: inherit; padding: .4rem .8rem; border-radius: 6px; border: 1px solid rgba(255,255,255,0.12); background: rgba(255,255,255,0.04); color: #e6e6ea; cursor: pointer; }+.agent-vanity-grinder button:hover:not(:disabled) { background: rgba(255,255,255,0.08); }+.agent-vanity-grinder button.primary { background: #f2f2f5; color: #111; border-color: #f2f2f5; }+.agent-vanity-grinder button.primary:hover:not(:disabled) { background: #fff; }+.agent-vanity-grinder button:disabled { opacity: .5; cursor: not-allowed; }+.agent-vanity-grinder .progress { font-size: .75rem; color: rgba(230,230,234,0.7); margin-top: .55rem; font-family: ui-monospace, monospace; }+.agent-vanity-grinder .err { color: #ff8a80; font-size: .75rem; margin-top: .5rem; }+.agent-vanity-grinder .current { font-family: ui-monospace, monospace; font-size: .75rem; color: rgba(230,230,234,0.6); margin-top: .35rem; word-break: break-all; }+.agent-vanity-grinder .current .pfx { background: linear-gradient(90deg,#ffd54f,#ff8a65); color: #1a1a1a; padding: 0 2px; border-radius: 2px; font-weight: 600; }+`;++let _styleInjected = false;+function _injectStyle() {+ if (_styleInjected || typeof document === 'undefined') return;+ const tag = document.createElement('style');+ tag.id = 'agent-vanity-grinder-style';+ tag.textContent = STYLE;+ document.head.appendChild(tag);+ _styleInjected = true;+}++function _esc(s) {+ return String(s ?? '').replace(/[&<>"']/g, (c) => ({+ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''',+ })[c]);+}++function _formatRate(n) {+ if (!n) return '0';+ if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(1)}M`;+ if (n >= 1_000) return `${(n / 1_000).toFixed(1)}k`;+ return Math.round(n).toString();+}++/**+ * Mount the vanity grinder card.+ *+ * @param {object} opts+ * @param {HTMLElement} opts.panel+ * @param {{ id: string, name?: string }} opts.identity+ * @param {() => void} [opts.onProvisioned] — called after a successful grind+provision.+ */+export function mountAgentVanityGrinderCard({ panel, identity, onProvisioned }) {+ if (!panel || !identity?.id) return null;+ _injectStyle();++ const wrapper = document.createElement('details');+ wrapper.className = 'agent-vanity-grinder-details';+ wrapper.hidden = true;+ const summary = document.createElement('summary');+ summary.className = 'agent-vanity-grinder-summary';+ summary.textContent = 'Vanity address';+ wrapper.appendChild(summary);+ panel.appendChild(wrapper);++ const root = document.createElement('section');+ root.className = 'agent-vanity-grinder';+ wrapper.appendChild(root);++ const state = {+ loaded: false,+ hasWallet: false,+ address: null,+ vanityPrefix: null,+ busy: false,+ progress: null,+ err: null,+ };+ let abort = null;++ async function loadFromServer() {+ const r = await fetchAgentSolanaWallet(identity.id, 'mainnet');+ if (r.status === 'forbidden') {+ wrapper.remove();+ return false;+ }+ wrapper.hidden = false;+ if (r.status === 'ok') {+ state.hasWallet = true;+ state.address = r.data.address;+ state.vanityPrefix = r.data.vanity_prefix || null;+ } else {+ state.hasWallet = false;+ state.address = null;+ state.vanityPrefix = null;+ }+ state.loaded = true;+ render();+ return true;+ }++ function render() {+ if (!state.loaded) {+ root.innerHTML = `<div class="sub">Loading…</div>`;+ return;+ }+ const btnLabel = state.hasWallet ? 'Regrind with new prefix' : 'Grind vanity wallet';+ const sub = state.hasWallet+ ? 'Replace the current wallet with one whose address starts with characters you choose.'+ : 'Generate a wallet whose address starts with characters you choose.';++ const current = state.hasWallet && state.address+ ? `<div class="current"><span class="pfx">${_esc(state.vanityPrefix || '')}</span>${_esc(state.address.slice((state.vanityPrefix || '').length))}</div>`+ : '';++ root.innerHTML = `+ <h3>Vanity address</h3>+ <p class="sub">${_esc(sub)}</p>+ ${current}+ <div class="row">+ <button class="primary" data-act="grind" ${state.busy ? 'disabled' : ''}>+ ${state.busy ? 'Working…' : _esc(btnLabel)}+ </button>+ </div>+ ${state.progress ? `<div class="progress">grinding… ${_esc(_formatRate(state.progress.rate))}/s · eta ${_esc(state.progress.eta)} <button data-act="cancel">cancel</button></div>` : ''}+ ${state.err ? `<div class="err">${_esc(state.err)}</div>` : ''}+ `;+ root.querySelector('[data-act="grind"]')?.addEventListener('click', onGrind);+ root.querySelector('[data-act="cancel"]')?.addEventListener('click', () => abort?.abort());+ }++ async function onGrind() {+ const choice = await openVanityModal({+ agentName: identity.name || '',+ initial: state.vanityPrefix || '',+ });+ if (choice == null || choice === '') return;++ const prefix = typeof choice === 'string' ? choice : choice.prefix;+ const preGround = typeof choice === 'object' ? choice.secretKey : null;++ if (state.hasWallet) {+ if (!confirm('Replace the existing Solana wallet with a vanity-ground one? The old key will be discarded — funds will be lost if not transferred first.')) return;+ }++ state.busy = true; state.err = null; state.progress = null; render();+ abort = new AbortController();+ try {+ if (state.hasWallet) {+ await deleteAgentSolanaWallet(identity.id);+ }+ const data = await provisionAgentSolanaWallet({+ agentId: identity.id,+ vanityPrefix: prefix,+ preGround,+ signal: abort.signal,+ onProgress: (p) => { state.progress = p; render(); },+ });+ state.hasWallet = true;+ state.address = data.address;+ state.vanityPrefix = data.vanity_prefix || prefix || null;+ state.progress = null;+ onProvisioned?.(data);+ } catch (e) {+ state.err = e.name === 'AbortError' ? 'cancelled' : e.message;+ state.progress = null;+ } finally {+ state.busy = false; abort = null; render();+ }+ }++ render();+ loadFromServer().catch((e) => {+ state.err = e.message || 'failed to load';+ state.loaded = true;+ wrapper.hidden = false;+ render();+ });++ return {+ destroy: () => {+ abort?.abort();+ wrapper.remove();+ },+ refresh: () => loadFromServer().catch(() => {}),+ };+}