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: onchain-deploy improvements, vite config updates
nirholas963fb863de6f
diff --git a/api/_lib/onchain-deploy.js b/api/_lib/onchain-deploy.jsindex 5d83fa207..465b4a5c9 100644--- a/api/_lib/onchain-deploy.js+++ b/api/_lib/onchain-deploy.js@@ -16,7 +16,7 @@ import { CID } from 'multiformats/cid';import * as raw from 'multiformats/codecs/raw';import { sha256 } from 'multiformats/hashes/sha2';import { createUmi } from '@metaplex-foundation/umi-bundle-defaults';-import { mplCore, create, createCollection, ruleSet } from '@metaplex-foundation/mpl-core';+import { mplCore, create, createCollection, fetchCollection, ruleSet } from '@metaplex-foundation/mpl-core';import {generateSigner,publicKey as umiPublicKey,@@ -36,6 +36,7 @@ import { getAgentCollection } from './solana-collection.js';import { solanaRpcEndpoints } from './solana/connection.js';import { generateSolanaAgentWallet } from './agent-wallet.js';import { publishFeedEvent } from './feed.js';+import { pinToIPFS } from './ipfs-pin.js';// Genesis-hash chain refs (CAIP-2), mirroring api/agents/onchain/[action].js.export const SOLANA_REFS = {@@ -88,28 +89,15 @@ export async function funderLamports(umi, pubkey) {}}-// Pin the manifest. Try web3.storage for true IPFS pinning; otherwise fall back-// to R2 while computing the real CIDv1 (raw codec, sha2-256) from the bytes, so-// the content is verifiable content-addressing and the returned HTTPS URL is-// real and resolvable — never a stub. Mirrors api/agents/onchain/[action].js.+// Pin the manifest. Prefer real IPFS pinning (Pinata → web3.storage, via the+// shared ipfs-pin helper); otherwise fall back to R2 while computing the real+// CIDv1 (raw codec, sha2-256) from the bytes, so the content is verifiable+// content-addressing and the returned HTTPS URL is real and resolvable — never a+// stub. Mirrors api/agents/onchain/[action].js.export async function pinManifest(manifest, agentId) {const bytes = Buffer.from(JSON.stringify(manifest), 'utf-8');- const token = process.env.WEB3_STORAGE_TOKEN;- if (token) {- try {- const r = await fetch('https://api.web3.storage/upload', {- method: 'POST',- headers: { Authorization: `Bearer ${token}` },- body: bytes,- });- if (r.ok) {- const data = await r.json();- if (data.cid) return { cid: data.cid, uri: `ipfs://${data.cid}` };- }- } catch {- /* fall through to R2 */- }- }+ const pinned = await pinToIPFS(bytes, `agent-${agentId}.json`).catch(() => null);+ if (pinned?.cid) return { cid: pinned.cid, uri: pinned.uri };const digest = await sha256.digest(bytes);const cid = CID.create(1, raw.code, digest).toString();const key = `agent-manifests/bulk/${agentId}.json`;@@ -208,34 +196,56 @@ export async function resolveAgentCollection({ umi, authoritySigner, network, onreturn address;}+/**+ * Fetch the on-chain CollectionV1 once per run. The Core `create` helper reads+ * `collection.publicKey` (and oracles/lifecycleHooks) off this object — passing a+ * bare publicKey silently mints a STANDALONE asset, so the real object is required+ * to actually bind the asset into the collection. Returns null for no collection.+ */+export async function loadCollectionAsset(umi, collectionAddr) {+ if (!collectionAddr) return null;+ return fetchCollection(umi, umiPublicKey(collectionAddr));+}+/*** Deploy a single agent on-chain: ensure its owner wallet, pin its manifest,* mint the Core asset into the collection, and persist the result. Returns* { asset, signature, metadataUri, ownerAddress, image }. Pure of UI concerns —* pass `onEvent` to receive a 'wallet' event when a custodial wallet is created.+ * `collectionAsset` is the fetched CollectionV1 (from loadCollectionAsset).*/-export async function deployAgentOnce({ umi, authoritySigner, collectionAddr, collectionPk, agent, network, onEvent }) {+export async function deployAgentOnce({ umi, authoritySigner, collectionAddr, collectionAsset, agent, network, onEvent }) {const agentName = agent.name || 'Agent';- // 1. Owner = the agent's own custodial Solana wallet (generate if missing).+ // 1. Resolve the owner. Prefer the agent's existing Solana wallet. If it has+ // none: give it its own custodial wallet when the platform key is present+ // (so the secret can be encrypted at rest and recovered later); otherwise+ // custody the asset under the collection authority — transferable to the+ // agent/user on claim. The owner never signs the mint, so it needs no SOL.+ const authorityAddress = authoritySigner.publicKey.toString();let meta = { ...(agent.meta || {}) };let ownerAddress = meta.solana_address;if (!ownerAddress) {- const wallet = await generateSolanaAgentWallet();- meta = {- ...meta,- solana_address: wallet.address,- encrypted_solana_secret: wallet.encrypted_secret,- solana_wallet_source: 'bulk_onchain',- };- ownerAddress = wallet.address;- await sql`- UPDATE agent_identities- SET meta = ${JSON.stringify(meta)}::jsonb, updated_at = NOW()- WHERE id = ${agent.id}- `;- onEvent?.('wallet', { agent_id: agent.id, name: agentName, owner: ownerAddress });+ if (process.env.JWT_SECRET) {+ const wallet = await generateSolanaAgentWallet();+ meta = {+ ...meta,+ solana_address: wallet.address,+ encrypted_solana_secret: wallet.encrypted_secret,+ solana_wallet_source: 'bulk_onchain',+ };+ ownerAddress = wallet.address;+ await sql`+ UPDATE agent_identities+ SET meta = ${JSON.stringify(meta)}::jsonb, updated_at = NOW()+ WHERE id = ${agent.id}+ `;+ onEvent?.('wallet', { agent_id: agent.id, name: agentName, owner: ownerAddress });+ } else {+ ownerAddress = authorityAddress;+ }}+ const custody = ownerAddress === authorityAddress;// 2. Media + manifest.const image = agent.thumbnail_key ? r2PublicUrl(agent.thumbnail_key) : '';@@ -279,8 +289,8 @@ export async function deployAgentOnce({ umi, authoritySigner, collectionAddr, co: []),],};- if (collectionPk) {- createArgs.collection = collectionPk;+ if (collectionAsset) {+ createArgs.collection = collectionAsset;createArgs.authority = authoritySigner;}const result = await create(umi, createArgs).sendAndConfirm(umi, {@@ -300,7 +310,7 @@ export async function deployAgentOnce({ umi, authoritySigner, collectionAddr, cocontract_or_mint: asset,metadata_uri: metadataUri,owner: ownerAddress,- custody: true,+ custody,tx_hash: signature,...(collectionAddr ? { collection: collectionAddr } : {}),confirmed_at: new Date().toISOString(),diff --git a/api/admin/bulk-launch.js b/api/admin/bulk-launch.jsindex 005ffab3c..10fabd3ab 100644--- a/api/admin/bulk-launch.js+++ b/api/admin/bulk-launch.js@@ -31,7 +31,6 @@// done { deployed, errors, skipped }import { LAMPORTS_PER_SOL } from '@solana/web3.js';-import { publicKey as umiPublicKey } from '@metaplex-foundation/umi';import { cors, method, error } from '../_lib/http.js';import { requireAdmin } from '../_lib/admin.js';import {@@ -40,6 +39,7 @@ import {funderLamports,fetchUndeployedAgents,resolveAgentCollection,+ loadCollectionAsset,deployAgentOnce,explorerUrl,EST_MINT_LAMPORTS,@@ -116,7 +116,7 @@ export default async function handler(req, res) {sse(res, 'done', { deployed: 0, errors: 1, skipped: 0 });return res.end();}- const collectionPk = collectionAddr ? umiPublicKey(collectionAddr) : null;+ const collectionAsset = dryRun ? null : await loadCollectionAsset(umi, collectionAddr);let deployed = 0;let errors = 0;@@ -158,7 +158,7 @@ export default async function handler(req, res) {umi,authoritySigner,collectionAddr,- collectionPk,+ collectionAsset,agent,network,onEvent: (type, data) => sse(res, type, data),diff --git a/scripts/deploy-agents-onchain.mjs b/scripts/deploy-agents-onchain.mjsindex 56133030d..b1ea0252e 100644--- a/scripts/deploy-agents-onchain.mjs+++ b/scripts/deploy-agents-onchain.mjs@@ -21,13 +21,13 @@*/import { LAMPORTS_PER_SOL } from '@solana/web3.js';-import { publicKey as umiPublicKey } from '@metaplex-foundation/umi';import {authoritySecret,buildAuthorityUmi,funderLamports,fetchUndeployedAgents,resolveAgentCollection,+ loadCollectionAsset,deployAgentOnce,explorerUrl,EST_MINT_LAMPORTS,@@ -89,7 +89,7 @@ async function main() {network,onEvent: (_t, d) => console.log(`Collection [${d.source}]: ${d.address}${d.signature ? ` (deploy sig ${d.signature.slice(0, 12)}…)` : ''}`),});- const collectionPk = umiPublicKey(collectionAddr);+ const collectionAsset = await loadCollectionAsset(umi, collectionAddr);console.log('');let deployed = 0, errors = 0;@@ -102,7 +102,7 @@ async function main() {}process.stdout.write(`[${deployed + errors + 1}/${agents.length}] ${name} … `);try {- const r = await deployAgentOnce({ umi, authoritySigner, collectionAddr, collectionPk, agent, network });+ const r = await deployAgentOnce({ umi, authoritySigner, collectionAddr, collectionAsset, agent, network });deployed++;console.log(`✓ ${r.asset}`);console.log(` ${explorerUrl(r.asset, network)}`);diff --git a/vite.config.js b/vite.config.jsindex 65d07ddfb..bde4c96d9 100644--- a/vite.config.js+++ b/vite.config.js@@ -991,6 +991,43 @@ const appConfig = {},},},+ {+ // Vercel Web Analytics. The script is auto-served at+ // /_vercel/insights/script.js by Vercel once Web Analytics is enabled+ // for the project; it auto-captures pageviews (incl. client-side nav+ // via the History API). No npm dependency or React component is needed —+ // this is the framework-agnostic install for a vanilla multipage site,+ // injected the same way as the PostHog snippet above so every+ // Vite-processed page gets it. The `va` queue stub buffers any track()+ // calls fired before the deferred script loads. Embed pages (iframes)+ // are skipped to match PostHog's coverage and avoid double-counting+ // host-page traffic. In dev the script 404s harmlessly (defer, no thrown+ // error) — analytics only land in prod once enabled in the dashboard.+ name: 'vercel-analytics',+ transformIndexHtml: {+ order: 'pre',+ handler(_html, ctx) {+ const EMBED_FILES = new Set([+ 'widget.html', 'embed.html', 'avatar-embed.html',+ 'agent-embed.html', 'a-embed.html',+ ]);+ const filename = (ctx.filename || ctx.path || '').replace(/\\/g, '/').split('/').pop();+ if (EMBED_FILES.has(filename)) return [];+ return [+ {+ tag: 'script',+ children: 'window.va=window.va||function(){(window.vaq=window.vaq||[]).push(arguments)};',+ injectTo: 'head',+ },+ {+ tag: 'script',+ attrs: { defer: true, src: '/_vercel/insights/script.js' },+ injectTo: 'head',+ },+ ];+ },+ },+ },{// Native View Transitions for internal nav. Chrome/Safari ship it,// Firefox falls back to a normal location change (no UX regression).