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.

refine: avatar wallet send-sol + chat page updates

nirholasa7c5844fe442
diff --git a/api/_lib/avatar-wallet.js b/api/_lib/avatar-wallet.js
index a43ed93bb..24a31e6a3 100644
--- a/api/_lib/avatar-wallet.js
+++ b/api/_lib/avatar-wallet.js
@@ -85,6 +85,10 @@ export function avatarWalletConfig() {
const maxSendUsd = clampNumber(parseFloat(process.env.AVATAR_MAX_SEND_USD || '2'), 0.01, 100);
const defaultRecipient = (process.env.AVATAR_DEFAULT_RECIPIENT || '').trim() || null;
const demoToken = (process.env.AVATAR_DEMO_TOKEN || '').trim() || null;
+ // When set, every send is forced to AVATAR_DEFAULT_RECIPIENT and any
+ // client-supplied `to` is ignored — makes the wallet drain-proof (it can
+ // only ever pay you, regardless of who hits the endpoint).
+ const lockRecipient = ['1', 'true', 'yes'].includes((process.env.AVATAR_LOCK_RECIPIENT || '').trim().toLowerCase());
let address = null;
let configured = false;
@@ -97,7 +101,7 @@ export function avatarWalletConfig() {
}
}
- return { configured, address, network, rpcUrl, maxSendUsd, defaultRecipient, demoToken };
+ return { configured, address, network, rpcUrl, maxSendUsd, defaultRecipient, demoToken, lockRecipient };
}
/** True when `s` is a parseable Solana public key. */
diff --git a/api/agent/send-sol.js b/api/agent/send-sol.js
index ba6700bf1..1dd8572ea 100644
--- a/api/agent/send-sol.js
+++ b/api/agent/send-sol.js
@@ -71,7 +71,17 @@ export default wrap(async (req, res) => {
const body = parse(bodySchema, await readJson(req));
- const recipient = body.to || cfg.defaultRecipient;
+ // When the recipient is locked, the wallet can only ever pay the configured
+ // default — any client-supplied `to` is ignored.
+ let recipient;
+ if (cfg.lockRecipient) {
+ if (!cfg.defaultRecipient) {
+ return error(res, 503, 'recipient_locked', 'AVATAR_LOCK_RECIPIENT is set but AVATAR_DEFAULT_RECIPIENT is missing');
+ }
+ recipient = cfg.defaultRecipient;
+ } else {
+ recipient = body.to || cfg.defaultRecipient;
+ }
if (!recipient) {
return error(res, 400, 'no_recipient', 'no recipient — pass `to` or set AVATAR_DEFAULT_RECIPIENT');
}
diff --git a/api/agent/wallet.js b/api/agent/wallet.js
index 16541cbbb..48f30ea27 100644
--- a/api/agent/wallet.js
+++ b/api/agent/wallet.js
@@ -45,6 +45,7 @@ export default wrap(async (req, res) => {
solPriceUsd: solPriceUsd || null,
maxSendUsd: cfg.maxSendUsd,
defaultRecipient: cfg.defaultRecipient,
+ recipientLocked: cfg.lockRecipient,
explorer: explorerAccountUrl(cfg.address, cfg.network),
},
// Short cache so the chip feels live without hammering the RPC.
diff --git a/pages/avatar-wallet-chat.html b/pages/avatar-wallet-chat.html
index 88ad956ca..000d6709e 100644
--- a/pages/avatar-wallet-chat.html
+++ b/pages/avatar-wallet-chat.html
@@ -394,6 +394,15 @@
});
avatarFrame.addEventListener('load', () => {
avatarFrame.contentWindow?.postMessage({ type: 'v1.avatar.hello' }, avatarOrigin);
+ // Resilience: if the avatar never signals ready (e.g. a slow rig),
+ // flush queued speech/gestures best-effort after a grace period so
+ // the avatar still reacts instead of going silent forever.
+ setTimeout(() => {
+ if (!avatarReady) {
+ avatarReady = true;
+ while (avatarQueue.length) avatarFrame.contentWindow?.postMessage(avatarQueue.shift(), avatarOrigin);
+ }
+ }, 5000);
});
// ── Wallet chip ───────────────────────────────────────────────
diff --git a/scripts/gen-avatar-wallet.mjs b/scripts/gen-avatar-wallet.mjs
index e1fb65f50..1354120ef 100644
--- a/scripts/gen-avatar-wallet.mjs
+++ b/scripts/gen-avatar-wallet.mjs
@@ -61,6 +61,7 @@ console.log(' 1. Send ~$3 of SOL to the address above (mainnet).');
console.log(' 2. Set the SAME env vars on your deployment:');
console.log(' AVATAR_WALLET_SECRET, AVATAR_NETWORK=mainnet, AVATAR_MAX_SEND_USD=2');
console.log(' Optional: AVATAR_DEFAULT_RECIPIENT=<your address> (the "send me" target)');
+console.log(' Optional: AVATAR_LOCK_RECIPIENT=1 (drain-proof: always pays your default, ignores client addresses)');
console.log(' Optional: AVATAR_DEMO_TOKEN=<secret> (then load the widget with ?token=<secret>)');
console.log(' 3. Open /avatar-wallet-chat and say: "send me $1 of SOL".');
console.log('');