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: add real-time wallet monitoring for pump.fun trades and enhance model fetching logic
nirholasda8dac74a1ae
diff --git a/chat/src/SettingsModal.svelte b/chat/src/SettingsModal.svelteindex 77092cc47..4bf40357e 100644--- a/chat/src/SettingsModal.svelte+++ b/chat/src/SettingsModal.svelte@@ -99,6 +99,31 @@let elRefreshToolSchema;+ // Draft values for API keys — nothing commits until Save is clicked+ let draftKeys = {+ openrouter: $openrouterAPIKey,+ anthropic: $anthropicAPIKey,+ openai: $openaiAPIKey,+ groq: $groqAPIKey,+ mistral: $mistralAPIKey,+ };+ let savedKey = '';++ const keyStores = {+ openrouter: openrouterAPIKey,+ anthropic: anthropicAPIKey,+ openai: openaiAPIKey,+ groq: groqAPIKey,+ mistral: mistralAPIKey,+ };++ function saveKey(name) {+ keyStores[name].set(draftKeys[name]);+ savedKey = name;+ onAPIKeyUpdate();+ setTimeout(() => { if (savedKey === name) savedKey = ''; }, 2000);+ }+async function onAPIKeyUpdate() {dispatch('fetchModels');if ($syncServer.token && $syncServer.password) {@@ -190,56 +215,34 @@</div><div class="flex flex-col gap-y-4 pt-1 sm:w-[400px]">{#if activeTab === 'api-keys'}- <label class="flex flex-col text-[10px] uppercase tracking-wide">- <span class="mb-2 ml-[3px]">OpenRouter API Key</span>- <input- type="text"- bind:value={$openrouterAPIKey}- placeholder="Enter your API key"- class="rounded-lg border border-slate-300 px-3 py-2 text-sm text-slate-800 transition-colors placeholder:text-gray-500 focus:border-slate-400 focus:outline-none"- on:change={onAPIKeyUpdate}- /></label- >- <label class="flex flex-col text-[10px] uppercase tracking-wide">- <span class="mb-2 ml-[3px] flex items-center gap-2"> Anthropic API Key </span>- <input- type="text"- bind:value={$anthropicAPIKey}- placeholder="Enter your API key"- class="rounded-lg border border-slate-300 px-3 py-2 text-sm text-slate-800 transition-colors placeholder:text-gray-500 focus:border-slate-400 focus:outline-none"- on:change={onAPIKeyUpdate}- /></label- >- <label class="flex flex-col text-[10px] uppercase tracking-wide">- <span class="mb-2 ml-[3px]">OpenAI API Key</span>- <input- type="text"- bind:value={$openaiAPIKey}- placeholder="Enter your API key"- class="rounded-lg border border-slate-300 px-3 py-2 text-sm text-slate-800 transition-colors placeholder:text-gray-500 focus:border-slate-400 focus:outline-none"- on:change={onAPIKeyUpdate}- /></label- >- <label class="flex flex-col text-[10px] uppercase tracking-wide">- <span class="mb-2 ml-[3px]">Groq API Key</span>- <input- type="text"- bind:value={$groqAPIKey}- placeholder="Enter your API key"- class="rounded-lg border border-slate-300 px-3 py-2 text-sm text-slate-800 transition-colors placeholder:text-gray-500 focus:border-slate-400 focus:outline-none"- on:change={onAPIKeyUpdate}- /></label- >- <label class="flex flex-col text-[10px] uppercase tracking-wide">- <span class="mb-2 ml-[3px]">Mistral API Key</span>- <input- type="text"- bind:value={$mistralAPIKey}- placeholder="Enter your API key"- class="rounded-lg border border-slate-300 px-3 py-2 text-sm text-slate-800 transition-colors placeholder:text-gray-500 focus:border-slate-400 focus:outline-none"- on:change={onAPIKeyUpdate}- /></label- >+ {#each [+ { key: 'openrouter', label: 'OpenRouter API Key', placeholder: 'sk-or-...' },+ { key: 'anthropic', label: 'Anthropic API Key', placeholder: 'sk-ant-...' },+ { key: 'openai', label: 'OpenAI API Key', placeholder: 'sk-...' },+ { key: 'groq', label: 'Groq API Key', placeholder: 'gsk_...' },+ { key: 'mistral', label: 'Mistral API Key', placeholder: 'Enter your API key' },+ ] as { key, label, placeholder }}+ <label class="flex flex-col text-[10px] uppercase tracking-wide">+ <span class="mb-2 ml-[3px]">{label}</span>+ <div class="flex gap-2">+ <input+ type="password"+ bind:value={draftKeys[key]}+ {placeholder}+ class="min-w-0 flex-1 rounded-lg border border-slate-300 px-3 py-2 text-sm text-slate-800 transition-colors placeholder:text-gray-500 focus:border-slate-400 focus:outline-none"+ />+ <button+ class="shrink-0 rounded-lg border px-3 py-2 text-[12px] font-medium transition-colors+ {savedKey === key+ ? 'border-green-300 bg-green-50 text-green-700'+ : 'border-slate-200 bg-slate-50 text-slate-500 hover:bg-slate-100'}"+ on:click={() => saveKey(key)}+ >+ {savedKey === key ? '✓ Saved' : 'Save'}+ </button>+ </div>+ </label>+ {/each}<p class="ml-1 text-center text-xs leading-relaxed text-slate-800 sm:text-left">{#if $syncServer.token && $syncServer.password}diff --git a/chat/src/providers.js b/chat/src/providers.jsindex 4efa91953..b2c588975 100644--- a/chat/src/providers.js+++ b/chat/src/providers.js@@ -238,7 +238,7 @@ export async function fetchModels({ onFinally }) {try {const promises = providers.map((provider) => {const apiKey = provider.apiKeyFn();- if (apiKey === '') {+ if (apiKey === '' || !provider.modelsUrl) {return [];}diff --git a/src/agent-skills-pumpfun-compose.js b/src/agent-skills-pumpfun-compose.jsindex afe0a2f5c..e3c2f2c71 100644--- a/src/agent-skills-pumpfun-compose.js+++ b/src/agent-skills-pumpfun-compose.js@@ -15,6 +15,8 @@* terminates the same way a live run would.*/+import { WalletMonitor } from './pump/wallet-monitor.js';+const MCP_ENDPOINT = 'https://pump-fun-sdk.modelcontextprotocol.name/mcp';const _sessions = new Map();let _rpcId = 0;@@ -426,4 +428,91 @@ export function registerPumpFunComposeSkills(skills) {};},});++ skills.register({+ name: 'pumpfun-copy-trade-live',+ description:+ "Mirror a wallet's pump.fun trades in real-time via WebSocket (~100ms latency). Mirrors both buys AND sells. Use instead of pumpfun-copy-trade when speed matters.",+ instruction:+ 'WebSocket logsSubscribe on the target wallet. Fires doBuy on buy events, doSell on sell events (if we hold the mint). Stops at durationSec, spendCap, or abort.',+ animationHint: 'gesture',+ voicePattern: 'Live copy-trading {{wallet}}…',+ mcpExposed: true,+ inputSchema: {+ type: 'object',+ properties: {+ wallet: { type: 'string', description: 'Base58 Solana address to mirror.' },+ sizeMultiplier: { type: 'number', minimum: 0.001, maximum: 10, description: 'Scale factor applied to the target\'s trade size.' },+ durationSec: { type: 'integer', minimum: 10, maximum: 7200 },+ network: { type: 'string', enum: ['mainnet', 'devnet'] },+ sessionId: { type: 'string' },+ dryRun: { type: 'boolean' },+ },+ required: ['wallet', 'durationSec'],+ },+ handler: async (args, ctx) => {+ const dryRun = !!args.dryRun;+ const onProgress = args.onProgress;+ const signal = args.signal;+ const sessionId = args.sessionId;+ const mult = args.sizeMultiplier ?? 1;+ const cap = cfg(ctx, 'sessionSpendCapSol');+ const state = await loadState(ctx?.memory, sessionId, { mirrored: new Set(), spent: 0, log: [] });++ const monitor = new WalletMonitor(args.wallet, { network: args.network ?? 'mainnet' });++ emit(onProgress, { type: 'start', mode: 'copy-trade-live', wallet: args.wallet, spent: state.spent, cap });++ await new Promise((resolve) => {+ if (signal?.aborted) { resolve(); return; }++ const timer = setTimeout(resolve, args.durationSec * 1000);+ signal?.addEventListener?.('abort', () => { clearTimeout(timer); resolve(); }, { once: true });++ monitor.addEventListener('trade', async (evt) => {+ if (signal?.aborted || state.spent >= cap) { clearTimeout(timer); resolve(); return; }++ const { side, mint, solAmount, signature } = evt;++ // Skip if we already acted on this tx+ if (state.mirrored.has(signature)) return;+ state.mirrored.add(signature);++ try {+ if (side === 'buy') {+ const amount = Math.min(solAmount * mult, cap - state.spent);+ if (amount <= 0) return;+ emit(onProgress, { type: dryRun ? 'dry-buy' : 'buy', mint, solAmount: amount, spent: state.spent });+ const r = await doBuy(skills, ctx, dryRun, mint, amount);+ state.spent += amount;+ state.log.push({ side: 'buy', mint, mirroredSig: signature, sig: r.signature, solAmount: amount, dryRun });+ } else {+ // Sell — only if we hold the mint+ emit(onProgress, { type: dryRun ? 'dry-sell' : 'sell', mint });+ const r = await doSell(skills, ctx, dryRun, mint);+ if (r.skipped !== 'no-balance') {+ state.log.push({ side: 'sell', mint, mirroredSig: signature, sig: r.signature, dryRun });+ }+ }+ saveState(ctx?.memory, sessionId, state);+ } catch (e) {+ state.log.push({ side, mint, error: e.message });+ emit(onProgress, { type: 'error', mint, reason: e.message });+ }+ });++ monitor.start();+ });++ monitor.stop();++ const reason = signal?.aborted ? 'aborted' : state.spent >= cap ? 'cap' : 'duration';+ return {+ success: true,+ output: `${dryRun ? 'Dry-run' : 'Live copy-trade'} done (${reason}). Mirrored ${state.log.length} trades, spent ${state.spent.toFixed(4)} SOL.`,+ sentiment: 0.4,+ data: { spent: state.spent, mirrors: state.log, dryRun, sessionId, reason },+ };+ },+ });}diff --git a/src/pump/wallet-monitor.js b/src/pump/wallet-monitor.jsnew file mode 100644index 000000000..91b2e7656--- /dev/null+++ b/src/pump/wallet-monitor.js@@ -0,0 +1,129 @@+// Real-time Solana wallet monitor for pump.fun trades.+// Uses Solana WebSocket logsSubscribe to detect buys/sells from a target wallet+// with ~100ms latency instead of the 5s poll used by pumpfun-copy-trade.+//+// Emits a 'trade' event on every confirmed pump.fun instruction:+// { side: 'buy'|'sell', mint: string, solAmount: number, signature: string }+//+// Auto-reconnects with exponential backoff on disconnect.++const PUMP_PROGRAM = '6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P';+const PUMP_AMM_PROGRAM = 'pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA';++const WS_URLS = {+ mainnet: 'wss://api.mainnet-beta.solana.com',+ devnet: 'wss://api.devnet.solana.com',+};++// Parse pump.fun structured log line: "Program log: {...json...}"+function extractLogJson(log) {+ if (!log.startsWith('Program log: {')) return null;+ try { return JSON.parse(log.slice('Program log: '.length)); } catch { return null; }+}++// Returns { side, mint, solAmount } or null if not a pump.fun trade.+function parseTradeFromLogs(logs) {+ const isPump = logs.some((l) => l.includes(PUMP_PROGRAM) || l.includes(PUMP_AMM_PROGRAM));+ if (!isPump) return null;++ const isBuy = logs.some((l) => l.includes('Instruction: Buy'));+ const isSell = logs.some((l) => l.includes('Instruction: Sell'));+ if (!isBuy && !isSell) return null;++ let mint = null;+ let solAmount = 0;++ for (const log of logs) {+ const data = extractLogJson(log);+ if (!data) continue;+ if (data.mint) mint = data.mint;+ // quote_amount is lamports on the bonding curve; sol_amount on some AMM paths+ const raw = data.quote_amount ?? data.sol_amount;+ if (raw != null) solAmount = Number(raw) / 1e9;+ }++ if (!mint) return null;+ return { side: isBuy ? 'buy' : 'sell', mint, solAmount };+}++export class WalletMonitor extends EventTarget {+ /**+ * @param {string} wallet — base58 Solana address to watch+ * @param {{ network?: 'mainnet'|'devnet', wsUrl?: string }} opts+ */+ constructor(wallet, { network = 'mainnet', wsUrl } = {}) {+ super();+ this.wallet = wallet;+ this._wsUrl = wsUrl ?? WS_URLS[network] ?? WS_URLS.mainnet;+ this._ws = null;+ this._subId = null;+ this._msgId = 0;+ this._closed = false;+ this._reconnectMs = 1000;+ }++ start() {+ this._closed = false;+ this._connect();+ }++ stop() {+ this._closed = true;+ this._ws?.close();+ this._ws = null;+ }++ _connect() {+ if (this._closed) return;++ const ws = new WebSocket(this._wsUrl);+ this._ws = ws;++ ws.onopen = () => {+ this._reconnectMs = 1000;+ ws.send(JSON.stringify({+ jsonrpc: '2.0',+ id: ++this._msgId,+ method: 'logsSubscribe',+ params: [+ { mentions: [this.wallet] },+ { commitment: 'confirmed' },+ ],+ }));+ };++ ws.onmessage = ({ data }) => {+ let msg;+ try { msg = JSON.parse(data); } catch { return; }++ // Subscription confirmation+ if (msg.id != null && typeof msg.result === 'number') {+ this._subId = msg.result;+ return;+ }++ // Log notification+ const value = msg?.params?.result?.value;+ if (!value) return;+ const { logs, signature, err } = value;+ if (err || !Array.isArray(logs) || logs.length === 0) return;++ const trade = parseTradeFromLogs(logs);+ if (!trade) return;++ const evt = new Event('trade');+ Object.assign(evt, { ...trade, signature });+ this.dispatchEvent(evt);+ };++ ws.onerror = () => {};++ ws.onclose = () => {+ this._ws = null;+ if (!this._closed) {+ setTimeout(() => this._connect(), this._reconnectMs);+ this._reconnectMs = Math.min(this._reconnectMs * 2, 30_000);+ }+ };+ }+}