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.

35.3 KB
Raw Blame
-- Migration: seed curated chat skills into marketplace
-- Generated from chat/src/tools.js curatedToolPacks (skips tradingview-charts and web-search which are already seeded)
-- Idempotent via ON CONFLICT (slug) DO NOTHING.

begin;

insert into marketplace_skills (name, slug, description, category, tags, schema_json, is_public, author_id) values

(
  '3D Price Chart',
  'price-chart-3d',
  'Render an extruded 3D price chart for any crypto asset over a chosen window.',
  'finance',
  '{"3d","chart","crypto","finance"}',
  '[{"clientDefinition":{"id":"pack-price-chart-3d-001","name":"PriceChart3D","description":"Show a rotating 3D bar chart of price history for a crypto asset.","arguments":[{"name":"id","type":"string","description":"CoinGecko id (e.g. bitcoin) or ticker (e.g. BTC)."},{"name":"days","type":"number","description":"Window size in days (1, 7, 14, 30, 90, 180, 365, max)."}],"body":"const raw = String(args.id || '''').trim().toLowerCase();\nif (!raw) throw new Error(''id required'');\nconst days = String(args.days || 30);\nlet id = raw;\nif (raw.length <= 6 && !raw.includes(''-'')) {\n  const s = await fetch(''https://api.coingecko.com/api/v3/search?query='' + encodeURIComponent(raw));\n  if (!s.ok) throw new Error(''CoinGecko search failed: '' + s.status);\n  const sj = await s.json();\n  const hit = (sj.coins || []).find(c => c.symbol?.toLowerCase() === raw) || (sj.coins || [])[0];\n  if (!hit?.id) throw new Error(''No CoinGecko match for \"'' + raw + ''\"'');\n  id = hit.id;\n}\nconst html = `<!DOCTYPE html><html><head><meta charset=\"utf-8\"><style>\nhtml,body{margin:0;height:100%;background:#0b0d10;color:#e5e7eb;font-family:ui-sans-serif,system-ui,sans-serif;overflow:hidden}\n#hud{position:absolute;left:12px;top:10px;font-size:13px;line-height:1.45}\n#err{position:absolute;inset:0;display:none;align-items:center;justify-content:center;color:#fca5a5;padding:24px;text-align:center}\n</style></head><body>\n<div id=\"hud\">Loading…</div><div id=\"err\"></div>\n<script type=\"module\">\nimport * as THREE from ''https://esm.sh/[email protected]'';\nimport { OrbitControls } from ''https://esm.sh/[email protected]/examples/jsm/controls/OrbitControls.js'';\nconst ID = ${JSON.stringify(id)}, DAYS = ${JSON.stringify(days)};\nconst renderer = new THREE.WebGLRenderer({ antialias: true });\nrenderer.setPixelRatio(devicePixelRatio); renderer.setSize(innerWidth, innerHeight); renderer.setClearColor(0x0b0d10);\ndocument.body.appendChild(renderer.domElement);\naddEventListener(''resize'', () => { renderer.setSize(innerWidth, innerHeight); cam.aspect = innerWidth/innerHeight; cam.updateProjectionMatrix(); });\nconst scene = new THREE.Scene();\nconst cam = new THREE.PerspectiveCamera(45, innerWidth/innerHeight, 0.1, 1000); cam.position.set(0, 18, 28);\nconst ctl = new OrbitControls(cam, renderer.domElement); ctl.enableDamping = true; ctl.target.set(0, 4, 0);\nscene.add(new THREE.AmbientLight(0xffffff, 0.45));\nconst key = new THREE.DirectionalLight(0xffffff, 1.0); key.position.set(10, 20, 10); scene.add(key);\nfunction err(m){ document.getElementById(''err'').style.display=''flex''; document.getElementById(''err'').textContent=m; }\nasync function load(){\n  const r = await fetch(''https://api.coingecko.com/api/v3/coins/'' + encodeURIComponent(ID) + ''/market_chart?vs_currency=usd&days='' + encodeURIComponent(DAYS));\n  if (!r.ok) return err(''CoinGecko market_chart failed: '' + r.status);\n  const j = await r.json();\n  const prices = j.prices || [];\n  if (!prices.length) return err(''No price data'');\n  const N = prices.length, vals = prices.map(p => p[1]);\n  const min = Math.min(...vals), max = Math.max(...vals), range = Math.max(1e-9, max - min);\n  const width = 30, gap = width / N, barW = gap * 0.85;\n  const group = new THREE.Group();\n  for (let i = 0; i < N; i++) {\n    const h = ((vals[i] - min) / range) * 14 + 0.05;\n    const g = new THREE.BoxGeometry(barW, h, barW);\n    const t = i / (N - 1);\n    const col = new THREE.Color().setHSL(0.58 - 0.55 * t, 0.7, 0.55);\n    const m = new THREE.MeshStandardMaterial({ color: col, roughness: 0.4, metalness: 0.2 });\n    const cube = new THREE.Mesh(g, m);\n    cube.position.set(-width/2 + i * gap + gap/2, h/2, 0);\n    group.add(cube);\n  }\n  scene.add(group);\n  const last = vals[vals.length - 1], first = vals[0];\n  const chg = ((last - first) / first) * 100;\n  document.getElementById(''hud'').innerHTML =\n    ''<b>'' + ID.toUpperCase() + ''</b> · '' + DAYS + ''d<br>'' +\n    ''Last $'' + last.toLocaleString(undefined,{maximumFractionDigits:6}) + ''<br>'' +\n    ''Δ '' + chg.toFixed(2) + ''% over window'';\n}\nfunction tick(){ ctl.update(); renderer.render(scene, cam); requestAnimationFrame(tick); }\ntick(); load();\n</script></body></html>`;\nreturn { contentType: ''text/html'', content: html };"},"type":"function","function":{"name":"PriceChart3D","description":"Render an interactive 3D bar chart of crypto price history. Use whenever the user asks for a 3D chart, historical price visualization, or sparkline of a coin.","parameters":{"type":"object","properties":{"id":{"type":"string","description":"CoinGecko id (e.g. ethereum) or ticker (e.g. ETH)."},"days":{"type":"number","enum":[1,7,14,30,90,180,365],"description":"Window in days."}},"required":["id"]}}}]',
  true,
  null
),

(
  'Token Price',
  'token-price',
  'Look up real-time crypto prices and 24h change via CoinGecko.',
  'finance',
  '{"crypto","price","finance","coingecko"}',
  '[{"clientDefinition":{"id":"pack-token-price-001","name":"TokenPrice","description":"Returns current USD price, 24h change %, and market cap for a crypto asset.","arguments":[{"name":"id","type":"string","description":"CoinGecko id (e.g. bitcoin, ethereum, solana) OR a ticker symbol like BTC, ETH, SOL."}],"body":"const raw = String(args.id || '''').trim().toLowerCase();\nif (!raw) throw new Error(''id required'');\nlet id = raw;\nif (raw.length <= 6 && !raw.includes(''-'')) {\n  const s = await fetch(''https://api.coingecko.com/api/v3/search?query='' + encodeURIComponent(raw));\n  if (!s.ok) throw new Error(''CoinGecko search failed: '' + s.status);\n  const sj = await s.json();\n  const hit = (sj.coins || []).find(c => c.symbol?.toLowerCase() === raw) || (sj.coins || [])[0];\n  if (hit?.id) id = hit.id;\n}\nconst r = await fetch(''https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids='' + encodeURIComponent(id));\nif (!r.ok) throw new Error(''CoinGecko markets failed: '' + r.status);\nconst arr = await r.json();\nif (!arr.length) throw new Error(''No CoinGecko match for \"'' + raw + ''\"'');\nconst c = arr[0];\nreturn {\n  id: c.id,\n  symbol: c.symbol,\n  name: c.name,\n  price_usd: c.current_price,\n  change_24h_pct: c.price_change_percentage_24h,\n  market_cap_usd: c.market_cap,\n  volume_24h_usd: c.total_volume,\n  last_updated: c.last_updated,\n};"},"type":"function","function":{"name":"TokenPrice","description":"Get the current USD price, 24h change %, market cap, and 24h volume for a crypto asset by CoinGecko id or ticker symbol.","parameters":{"type":"object","properties":{"id":{"type":"string","description":"CoinGecko id (e.g. solana) or symbol (e.g. SOL)."}},"required":["id"]}}}]',
  true,
  null
),

(
  '3D Token Ticker',
  'token-ticker-3d',
  'Render a live rotating 3D coin and price plate for any crypto asset.',
  'finance',
  '{"3d","crypto","ticker","finance"}',
  '[{"clientDefinition":{"id":"pack-token-ticker-3d-001","name":"TokenTicker3D","description":"Show a live 3D rotating coin with current USD price and 24h change.","arguments":[{"name":"id","type":"string","description":"CoinGecko id (e.g. solana) or ticker (e.g. SOL)."}],"body":"const raw = String(args.id || '''').trim().toLowerCase();\nif (!raw) throw new Error(''id required'');\nlet id = raw;\nif (raw.length <= 6 && !raw.includes(''-'')) {\n  const s = await fetch(''https://api.coingecko.com/api/v3/search?query='' + encodeURIComponent(raw));\n  if (!s.ok) throw new Error(''CoinGecko search failed: '' + s.status);\n  const sj = await s.json();\n  const hit = (sj.coins || []).find(c => c.symbol?.toLowerCase() === raw) || (sj.coins || [])[0];\n  if (!hit?.id) throw new Error(''No CoinGecko match for \"'' + raw + ''\"'');\n  id = hit.id;\n}\nconst html = `<!DOCTYPE html><html><head><meta charset=\"utf-8\"><style>\nhtml,body{margin:0;height:100%;background:#0b0d10;color:#e5e7eb;font-family:ui-sans-serif,system-ui,sans-serif;overflow:hidden}\n#info{position:absolute;left:12px;top:12px;font-size:14px;letter-spacing:.02em}\n#price{font-size:28px;font-weight:600}\n#chg{font-size:14px}\n.up{color:#22c55e}.dn{color:#ef4444}\n#err{position:absolute;inset:0;display:none;align-items:center;justify-content:center;color:#fca5a5;padding:24px;text-align:center}\n</style></head><body>\n<div id=\"info\"><div id=\"name\">Loading…</div><div id=\"price\">—</div><div id=\"chg\">—</div></div>\n<div id=\"err\"></div>\n<script type=\"module\">\nimport * as THREE from ''https://esm.sh/[email protected]'';\nconst ID = ${JSON.stringify(id)};\nconst renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });\nrenderer.setPixelRatio(devicePixelRatio); renderer.setSize(innerWidth, innerHeight);\ndocument.body.appendChild(renderer.domElement);\naddEventListener(''resize'', () => { renderer.setSize(innerWidth, innerHeight); cam.aspect = innerWidth/innerHeight; cam.updateProjectionMatrix(); });\nconst scene = new THREE.Scene();\nconst cam = new THREE.PerspectiveCamera(45, innerWidth/innerHeight, 0.1, 100); cam.position.set(0, 0, 4);\nscene.add(new THREE.AmbientLight(0xffffff, 0.55));\nconst key = new THREE.DirectionalLight(0xffffff, 1.2); key.position.set(3, 4, 5); scene.add(key);\nconst coinGeo = new THREE.CylinderGeometry(1, 1, 0.18, 96);\nlet coin = null;\nfunction setError(msg) { document.getElementById(''err'').style.display = ''flex''; document.getElementById(''err'').textContent = msg; }\nasync function load() {\n  const r = await fetch(''https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids='' + encodeURIComponent(ID));\n  if (!r.ok) return setError(''CoinGecko markets failed: '' + r.status);\n  const arr = await r.json();\n  if (!arr.length) return setError(''No data for '' + ID);\n  const c = arr[0];\n  document.getElementById(''name'').textContent = c.name + '' · '' + c.symbol.toUpperCase();\n  document.getElementById(''price'').textContent = ''$'' + Number(c.current_price).toLocaleString(undefined, { maximumFractionDigits: 6 });\n  const chg = Number(c.price_change_percentage_24h || 0);\n  const chgEl = document.getElementById(''chg'');\n  chgEl.textContent = (chg >= 0 ? ''+'' : '''') + chg.toFixed(2) + ''% (24h)'';\n  chgEl.className = chg >= 0 ? ''up'' : ''dn'';\n  if (!coin) {\n    const tex = await new THREE.TextureLoader().loadAsync(c.image);\n    tex.colorSpace = THREE.SRGBColorSpace;\n    const edge = new THREE.MeshStandardMaterial({ color: 0xc9a64b, roughness: 0.35, metalness: 0.85 });\n    const face = new THREE.MeshStandardMaterial({ map: tex, roughness: 0.4, metalness: 0.5 });\n    coin = new THREE.Mesh(coinGeo, [edge, face, face]);\n    coin.rotation.x = Math.PI / 2;\n    scene.add(coin);\n  }\n}\nfunction tick() { if (coin) coin.rotation.z += 0.012; renderer.render(scene, cam); requestAnimationFrame(tick); }\ntick(); load(); setInterval(load, 30000);\n<\\/script></body></html>`;\nreturn { contentType: ''text/html'', content: html };"},"type":"function","function":{"name":"TokenTicker3D","description":"Render a live 3D rotating coin with the current USD price and 24h change for a crypto asset.","parameters":{"type":"object","properties":{"id":{"type":"string","description":"CoinGecko id (e.g. ethereum) or ticker (e.g. ETH)."}},"required":["id"]}}}]',
  true,
  null
),

(
  'Date & Time',
  'date-time',
  'Get the current time and timezone.',
  'utility',
  '{"time","date","utility"}',
  '[{"clientDefinition":{"id":"pack-datetime-001","name":"GetCurrentTime","description":"Returns the current date and time as an ISO string.","arguments":[],"body":"return new Date().toISOString();"},"type":"function","function":{"name":"GetCurrentTime","description":"Returns the current date and time as an ISO 8601 string.","parameters":{"type":"object","properties":{}}}},{"clientDefinition":{"id":"pack-datetime-002","name":"GetTimezone","description":"Returns the user''s current timezone.","arguments":[],"body":"return Intl.DateTimeFormat().resolvedOptions().timeZone;"},"type":"function","function":{"name":"GetTimezone","description":"Returns the user''s current IANA timezone string.","parameters":{"type":"object","properties":{}}}}]',
  true,
  null
),

(
  'Pump.fun Launch',
  'pump-launch',
  'Launch a real pump.fun token on Solana from chat (requires connected Solana wallet).',
  'web3',
  '{"pump.fun","solana","token","web3"}',
  '[{"clientDefinition":{"id":"pack-pump-launch-001","name":"LaunchPumpToken","description":"Create a new pump.fun token. Returns the real mint address on success.","arguments":[{"name":"agent_id","type":"string","description":"UUID of your 3D agent identity (required to bind the token)."},{"name":"name","type":"string","description":"Token name."},{"name":"symbol","type":"string","description":"Token symbol (1-10 chars)."},{"name":"uri","type":"string","description":"Metadata JSON URL (Arweave/IPFS URI with name, symbol, image, description fields)."},{"name":"network","type":"string","description":"mainnet or devnet (default mainnet)."},{"name":"sol_buy_in","type":"number","description":"Initial creator buy in SOL (>= 0, default 0)."},{"name":"buyback_bps","type":"number","description":"Buyback basis points 0-10000 (default 0)."}],"body":"if (!window.solana || !window.solana.isConnected) {\n  try { await window.solana?.connect(); } catch(e) { throw new Error(''Solana wallet not connected: '' + (e?.message||e)); }\n}\nconst pubkey = window.solana?.publicKey?.toBase58?.();\nif (!pubkey) throw new Error(''No Solana public key available — connect a wallet first.'');\nconst agentId = String(args.agent_id || '''').trim();\nconst name = String(args.name || '''').trim();\nconst symbol = String(args.symbol || '''').trim();\nconst uri = String(args.uri || '''').trim();\nif (!agentId) throw new Error(''agent_id required'');\nif (!name || !symbol || !uri) throw new Error(''name, symbol, uri required'');\nconst network = args.network === ''devnet'' ? ''devnet'' : ''mainnet'';\nconst sol_buy_in = Number(args.sol_buy_in || 0);\nconst buyback_bps = Number(args.buyback_bps || 0);\nconst prep = await fetch(''/api/pump/launch-prep'', {\n  method: ''POST'',\n  headers: { ''content-type'': ''application/json'' },\n  credentials: ''include'',\n  body: JSON.stringify({ agent_id: agentId, wallet_address: pubkey, name, symbol, uri, network, sol_buy_in, buyback_bps }),\n});\nif (!prep.ok) throw new Error(''launch-prep failed: '' + prep.status + '' '' + await prep.text());\nconst { prep_id, mint, mint_secret_key_b64, tx_base64 } = await prep.json();\nif (!prep_id || !mint || !tx_base64) throw new Error(''launch-prep returned incomplete data'');\nconst { VersionedTransaction, Keypair } = await import(''https://esm.sh/@solana/web3.js@1'');\nconst txBytes = Uint8Array.from(atob(tx_base64), c => c.charCodeAt(0));\nconst tx = VersionedTransaction.deserialize(txBytes);\nif (mint_secret_key_b64) {\n  const mintKp = Keypair.fromSecretKey(Uint8Array.from(atob(mint_secret_key_b64), c => c.charCodeAt(0)));\n  tx.sign([mintKp]);\n}\nconst result = await window.solana.signAndSendTransaction(tx);\nconst tx_signature = result?.signature ?? String(result);\nif (!tx_signature) throw new Error(''wallet did not return a transaction signature'');\nconst conf = await fetch(''/api/pump/launch-confirm'', {\n  method: ''POST'',\n  headers: { ''content-type'': ''application/json'' },\n  credentials: ''include'',\n  body: JSON.stringify({ prep_id, tx_signature }),\n});\nif (!conf.ok) throw new Error(''launch-confirm failed: '' + conf.status + '' '' + await conf.text());\nconst confirmed = await conf.json();\nreturn { mint, tx_signature, pump_url: ''https://pump.fun/'' + mint, pump_agent_mint: confirmed.pump_agent_mint };"},"type":"function","function":{"name":"LaunchPumpToken","description":"Launch a real pump.fun token on Solana. Requires a connected Solana wallet and an existing agent identity. Calls launch-prep then wallet signs and submits then launch-confirm.","parameters":{"type":"object","properties":{"agent_id":{"type":"string","description":"UUID of the 3D agent identity to bind this token to."},"name":{"type":"string","description":"Token name."},"symbol":{"type":"string","description":"Token symbol (1-10 chars)."},"uri":{"type":"string","description":"Metadata JSON URL (Arweave/IPFS URI)."},"network":{"type":"string","enum":["mainnet","devnet"],"description":"Solana network (default mainnet)."},"sol_buy_in":{"type":"number","description":"Initial creator buy in SOL (default 0)."},"buyback_bps":{"type":"number","description":"Buyback basis points 0-10000 (default 0)."}},"required":["agent_id","name","symbol","uri"]}}}]',
  true,
  null
),

(
  'Tx Explainer',
  'tx-explain',
  'Decode a real Solana or Ethereum transaction into plain English plus a 3D flow diagram.',
  'web3',
  '{"transaction","solana","evm","web3"}',
  '[{"clientDefinition":{"id":"pack-tx-explain-001","name":"TxExplain","description":"Explain an on-chain transaction and visualize the token flow in 3D.","arguments":[{"name":"chain","type":"string","description":"solana | evm"},{"name":"sig","type":"string","description":"Transaction signature (Solana) or hash (EVM)."}],"body":"const chain = String(args.chain || '''').toLowerCase();\nconst sig = String(args.sig || '''').trim();\nif (![''solana'',''evm''].includes(chain)) throw new Error(''chain must be solana or evm'');\nif (!sig) throw new Error(''sig required'');\nconst r = await fetch(''/api/tx/explain'', { method: ''POST'', headers:{''content-type'':''application/json''}, credentials:''include'', body: JSON.stringify({ chain, sig }) });\nif (!r.ok) throw new Error(''tx explain failed: '' + r.status + '' '' + await r.text());\nconst d = await r.json();\nconst transfers = chain === ''solana''\n  ? [...(d.tokenTransfers||[]).map(t => ({from: t.fromUserAccount, to: t.toUserAccount, amount: t.tokenAmount, label: t.mint || ''TOKEN''})),\n     ...(d.nativeTransfers||[]).map(t => ({from: t.fromUserAccount, to: t.toUserAccount, amount: t.amount/1e9, label: ''SOL''}))]\n  : (d.logs||[]).map(t => ({from: t.from, to: t.to, amount: t.amount, label: t.token}));\nconst html = `<!DOCTYPE html><html><head><meta charset=\"utf-8\"><style>\nhtml,body{margin:0;height:100%;background:#0b0d10;color:#e5e7eb;font-family:ui-sans-serif,system-ui,sans-serif;overflow:hidden}\n#hud{position:absolute;left:12px;top:10px;font-size:12px;background:rgba(0,0,0,.45);padding:8px 10px;border-radius:8px;max-width:380px;line-height:1.45}\n</style></head><body>\n<div id=\"hud\"></div>\n<script type=\"module\">\nimport * as THREE from ''https://esm.sh/[email protected]'';\nimport { OrbitControls } from ''https://esm.sh/[email protected]/examples/jsm/controls/OrbitControls.js'';\nconst TX = ${JSON.stringify(d)}, T = ${JSON.stringify(transfers)};\nconst renderer = new THREE.WebGLRenderer({ antialias: true });\nrenderer.setPixelRatio(devicePixelRatio); renderer.setSize(innerWidth, innerHeight); renderer.setClearColor(0x0b0d10);\ndocument.body.appendChild(renderer.domElement);\naddEventListener(''resize'', () => { renderer.setSize(innerWidth, innerHeight); cam.aspect = innerWidth/innerHeight; cam.updateProjectionMatrix(); });\nconst scene = new THREE.Scene();\nconst cam = new THREE.PerspectiveCamera(45, innerWidth/innerHeight, 0.01, 1000); cam.position.set(0, 6, 14);\nconst ctl = new OrbitControls(cam, renderer.domElement); ctl.enableDamping = true;\nscene.add(new THREE.AmbientLight(0xffffff, 0.6));\nconst k = new THREE.DirectionalLight(0xffffff,1); k.position.set(5,8,6); scene.add(k);\nconst accounts = Array.from(new Set(T.flatMap(t => [t.from, t.to]).filter(Boolean)));\nconst pos = new Map();\naccounts.forEach((a, i) => {\n  const ang = (i / Math.max(1,accounts.length)) * Math.PI * 2;\n  const r = 5 + (accounts.length > 6 ? 2 : 0);\n  pos.set(a, new THREE.Vector3(Math.cos(ang)*r, 0, Math.sin(ang)*r));\n});\naccounts.forEach(a => {\n  const m = new THREE.Mesh(new THREE.SphereGeometry(0.4, 24, 24), new THREE.MeshStandardMaterial({ color: 0x9aa0a6, roughness: 0.4 }));\n  m.position.copy(pos.get(a)); scene.add(m);\n});\nT.forEach(t => {\n  const a = pos.get(t.from), b = pos.get(t.to); if (!a || !b) return;\n  const geo = new THREE.BufferGeometry().setFromPoints([a, b]);\n  const line = new THREE.Line(geo, new THREE.LineBasicMaterial({ color: 0x60a5fa }));\n  scene.add(line);\n});\nlet html = ''<div><b>'' + (TX.summary || TX.description || (TX.type || ''transaction'')) + ''</b></div>'';\nhtml += ''<div style=\"margin-top:6px\">'' + T.length + '' transfer(s) across '' + accounts.length + '' account(s)</div>'';\nT.slice(0,8).forEach(t => { html += ''<div>'' + (t.label||''TOKEN'') + '': '' + (t.amount||''?'') + ''</div>''; });\ndocument.getElementById(''hud'').innerHTML = html;\nfunction tick(){ ctl.update(); renderer.render(scene, cam); requestAnimationFrame(tick); }\ntick();\n</script></body></html>`;\nreturn { contentType: ''text/html'', content: html };"},"type":"function","function":{"name":"TxExplain","description":"Decode a real Solana or Ethereum transaction by signature/hash and render a 3D flow diagram of the transfers.","parameters":{"type":"object","properties":{"chain":{"type":"string","enum":["solana","evm"]},"sig":{"type":"string"}},"required":["chain","sig"]}}}]',
  true,
  null
),

(
  'Mint Scene NFT',
  'mint-scene-nft',
  'Snapshot the live 3D scene and mint it as a real Solana NFT via NFT.Storage + Metaplex.',
  'web3',
  '{"nft","solana","mint","3d"}',
  '[{"clientDefinition":{"id":"pack-mint-scene-001","name":"MintScene","description":"Mint the current 3D scene as a Solana NFT.","arguments":[{"name":"name","type":"string","description":"NFT name."},{"name":"description","type":"string","description":"NFT description."}],"body":"if (!window.solana?.publicKey) {\n  try { await window.solana?.connect(); } catch(e) { throw new Error(''Connect a Solana wallet first: '' + (e?.message||e)); }\n}\nconst owner = window.solana.publicKey.toBase58();\n// Request GLB + screenshot from the viewer iframe.\nconst viewer = document.querySelector(''iframe[data-three-ws-viewer]'') || document.querySelector(''iframe'');\nif (!viewer?.contentWindow) throw new Error(''No 3D viewer iframe found in the page.'');\nfunction ask(action, payload = {}) {\n  return new Promise((resolve, reject) => {\n    const id = ''mint-scene-'' + Math.random().toString(36).slice(2);\n    const onMsg = (e) => {\n      const d = e.data || {};\n      if (d.id !== id) return;\n      window.removeEventListener(''message'', onMsg);\n      if (d.error) reject(new Error(d.error)); else resolve(d.result);\n    };\n    window.addEventListener(''message'', onMsg);\n    viewer.contentWindow.postMessage({ id, action, input: payload }, ''*'');\n    setTimeout(() => { window.removeEventListener(''message'', onMsg); reject(new Error(''viewer timeout for '' + action)); }, 15000);\n  });\n}\nconst glbBase64 = await ask(''exportGLB'');\nconst thumbnailBase64 = await ask(''takeScreenshot'', { width: 512, height: 512 });\nif (!glbBase64 || !thumbnailBase64) throw new Error(''Viewer returned empty asset(s).'');\nconst prep = await fetch(''/api/nft/mint-scene'', { method:''POST'', headers:{''content-type'':''application/json''}, credentials:''include'', body: JSON.stringify({ ownerPubkey: owner, glbBase64, thumbnailBase64, name: String(args.name||'''').trim(), description: String(args.description||'''').trim() }) });\nif (!prep.ok) throw new Error(''mint-scene prep failed: '' + prep.status + '' '' + await prep.text());\nconst { unsignedTxBase64, metadataUri, mint } = await prep.json();\nconst bin = Uint8Array.from(atob(unsignedTxBase64), c => c.charCodeAt(0));\nconst signed = await window.solana.signTransaction({ serialize: () => bin, _raw: bin });\nconst signedTxBase64 = btoa(String.fromCharCode(...(signed.serialize?.() || signed._raw || bin)));\nconst conf = await fetch(''/api/nft/mint-scene-confirm'', { method:''POST'', headers:{''content-type'':''application/json''}, credentials:''include'', body: JSON.stringify({ signedTxBase64 }) });\nif (!conf.ok) throw new Error(''mint confirm failed: '' + conf.status + '' '' + await conf.text());\nconst { signature } = await conf.json();\nreturn { mint, signature, metadataUri, explorer: ''https://solscan.io/tx/'' + signature };"},"type":"function","function":{"name":"MintScene","description":"Mint the currently displayed 3D scene as a real Solana NFT. Asks the viewer to export GLB + screenshot, uploads to NFT.Storage, and mints via Metaplex.","parameters":{"type":"object","properties":{"name":{"type":"string"},"description":{"type":"string"}},"required":["name"]}}}]',
  true,
  null
),

(
  'NFT 3D Import',
  'nft-3d-import',
  'Fetch a real NFT and render its 3D model (or image plane fallback) in an orbit viewer.',
  'web3',
  '{"nft","3d","solana","evm"}',
  '[{"clientDefinition":{"id":"pack-nft-3d-import-001","name":"NFTImport3D","description":"Resolve an NFT and render it in 3D.","arguments":[{"name":"chain","type":"string","description":"solana | evm"},{"name":"id","type":"string","description":"For solana: mint pubkey. For evm: \"contract:tokenId\" (Ethereum mainnet)."}],"body":"const chain = String(args.chain || '''').toLowerCase();\n\tconst id = String(args.id || '''').trim();\n\tif (![''solana'',''evm''].includes(chain)) throw new Error(''chain must be solana or evm'');\n\tif (!id) throw new Error(''id required'');\n\tconst r = await fetch(''/api/nft/resolve'', { method: ''POST'', headers: {''content-type'':''application/json''}, credentials: ''include'', body: JSON.stringify({ chain, id }) });\n\tif (!r.ok) throw new Error(''NFT resolve failed: '' + r.status + '' '' + await r.text());\n\tconst meta = await r.json();\n\tconst html = `<!DOCTYPE html><html><head><meta charset=\"utf-8\"><style>\n\thtml,body{margin:0;height:100%;background:#0b0d10;color:#e5e7eb;font-family:ui-sans-serif,system-ui,sans-serif;overflow:hidden}\n\t#hud{position:absolute;left:12px;top:10px;font-size:13px;background:rgba(0,0,0,.4);padding:6px 10px;border-radius:8px}\n\t</style></head><body>\n\t<div id=\"hud\">${meta.name || ''NFT''}</div>\n\t<script type=\"module\">\n\timport * as THREE from ''https://esm.sh/[email protected]'';\n\timport { OrbitControls } from ''https://esm.sh/[email protected]/examples/jsm/controls/OrbitControls.js'';\n\timport { GLTFLoader } from ''https://esm.sh/[email protected]/examples/jsm/loaders/GLTFLoader.js'';\n\tconst META = ${JSON.stringify(meta)};\n\tconst renderer = new THREE.WebGLRenderer({ antialias: true });\n\trenderer.setPixelRatio(devicePixelRatio); renderer.setSize(innerWidth, innerHeight); renderer.setClearColor(0x0b0d10);\n\tdocument.body.appendChild(renderer.domElement);\n\taddEventListener(''resize'', () => { renderer.setSize(innerWidth, innerHeight); cam.aspect = innerWidth/innerHeight; cam.updateProjectionMatrix(); });\n\tconst scene = new THREE.Scene();\n\tconst cam = new THREE.PerspectiveCamera(45, innerWidth/innerHeight, 0.01, 1000); cam.position.set(0, 1.2, 3);\n\tconst ctl = new OrbitControls(cam, renderer.domElement); ctl.enableDamping = true;\n\tscene.add(new THREE.AmbientLight(0xffffff, 0.6));\n\tconst k = new THREE.DirectionalLight(0xffffff, 1); k.position.set(3, 4, 5); scene.add(k);\n\tasync function loadModel(url){\n\t  const gltf = await new GLTFLoader().loadAsync(url);\n\t  const m = gltf.scene;\n\t  const box = new THREE.Box3().setFromObject(m);\n\t  const size = box.getSize(new THREE.Vector3()).length();\n\t  const center = box.getCenter(new THREE.Vector3());\n\t  m.position.sub(center); cam.position.set(0, 0, size * 1.4); ctl.target.set(0,0,0);\n\t  scene.add(m);\n\t}\n\tasync function loadPlane(url){\n\t  const tex = await new THREE.TextureLoader().loadAsync(url);\n\t  tex.colorSpace = THREE.SRGBColorSpace;\n\t  const aspect = (tex.image && tex.image.width && tex.image.height) ? tex.image.width / tex.image.height : 1;\n\t  const w = 2.4, h = w / aspect;\n\t  const mesh = new THREE.Mesh(new THREE.PlaneGeometry(w, h), new THREE.MeshBasicMaterial({ map: tex }));\n\t  scene.add(mesh);\n\t}\n\t(async () => {\n\t  if (META.model) await loadModel(META.model);\n\t  else if (META.image) await loadPlane(META.image);\n\t  else { document.getElementById(''hud'').textContent = ''No renderable asset returned.''; }\n\t})();\n\tfunction tick(){ ctl.update(); renderer.render(scene, cam); requestAnimationFrame(tick); }\n\ttick();\n\t</script></body></html>`;\n\treturn { contentType: ''text/html'', content: html };"},"type":"function","function":{"name":"NFTImport3D","description":"Resolve a real NFT (Solana mint or Ethereum contract:tokenId) and render its 3D model or image in an orbit viewer.","parameters":{"type":"object","properties":{"chain":{"type":"string","enum":["solana","evm"]},"id":{"type":"string"}},"required":["chain","id"]}}}]',
  true,
  null
),

(
  'Wallet Balances',
  'wallet-balances',
  'Real on-chain balances for a Solana or EVM wallet with a 3D coin-stack visualization.',
  'web3',
  '{"wallet","solana","evm","web3"}',
  '[{"clientDefinition":{"id":"pack-wallet-balances-001","name":"WalletBalances","description":"Look up native + top token balances for a wallet and render a 3D coin stack.","arguments":[{"name":"chain","type":"string","description":"solana | evm"},{"name":"address","type":"string","description":"Wallet address (base58 for Solana, 0x… for EVM)."}],"body":"const chain = String(args.chain || '''').toLowerCase();\n\tconst address = String(args.address || '''').trim();\n\tif (![''solana'',''evm''].includes(chain)) throw new Error(''chain must be solana or evm'');\n\tif (!address) throw new Error(''address required'');\n\tconst r = await fetch(''/api/wallet/balances'', { method:''POST'', headers:{''content-type'':''application/json''}, credentials:''include'', body: JSON.stringify({ chain, address }) });\n\tif (!r.ok) throw new Error(''balances failed: '' + r.status + '' '' + await r.text());\n\tconst d = await r.json();\n\tconst top = [d.native, ...(d.tokens || [])].filter(Boolean).slice(0, 10);\n\tconst html = `<!DOCTYPE html><html><head><meta charset=\"utf-8\"><style>\n\thtml,body{margin:0;height:100%;background:#0b0d10;color:#e5e7eb;font-family:ui-sans-serif,system-ui,sans-serif;overflow:hidden}\n\t#hud{position:absolute;left:12px;top:10px;font-size:12px;background:rgba(0,0,0,.4);padding:8px 10px;border-radius:8px;max-width:280px}\n\t.row{display:flex;justify-content:space-between;gap:8px}.row b{color:#fff}\n\t</style></head><body>\n\t<div id=\"hud\"></div>\n\t<script type=\"module\">\n\timport * as THREE from ''https://esm.sh/[email protected]'';\n\timport { OrbitControls } from ''https://esm.sh/[email protected]/examples/jsm/controls/OrbitControls.js'';\n\tconst TOP = ${JSON.stringify(top)};\n\tconst renderer = new THREE.WebGLRenderer({ antialias: true });\n\trenderer.setPixelRatio(devicePixelRatio); renderer.setSize(innerWidth, innerHeight); renderer.setClearColor(0x0b0d10);\n\tdocument.body.appendChild(renderer.domElement);\n\taddEventListener(''resize'', () => { renderer.setSize(innerWidth, innerHeight); cam.aspect = innerWidth/innerHeight; cam.updateProjectionMatrix(); });\n\tconst scene = new THREE.Scene();\n\tconst cam = new THREE.PerspectiveCamera(45, innerWidth/innerHeight, 0.01, 1000); cam.position.set(0, 8, 14);\n\tconst ctl = new OrbitControls(cam, renderer.domElement); ctl.enableDamping = true; ctl.target.set(0, 2, 0);\n\tscene.add(new THREE.AmbientLight(0xffffff, 0.6));\n\tconst k = new THREE.DirectionalLight(0xffffff, 1); k.position.set(5, 10, 7); scene.add(k);\n\tconst totalUsd = TOP.reduce((s,t) => s + (Number(t.usd)||0), 0) || 1;\n\tconst colors = [0xf7931a, 0x627eea, 0x14f195, 0x9945ff, 0xe6007a, 0xf3ba2f, 0xff007a, 0xfcd535, 0x2a5ada, 0x8a2be2];\n\tTOP.forEach((t, i) => {\n\t  const usd = Number(t.usd) || 0;\n\t  const stackH = Math.max(0.05, (usd / totalUsd) * 6);\n\t  const x = (i - TOP.length/2) * 1.4;\n\t  const geo = new THREE.CylinderGeometry(0.5, 0.5, stackH, 48);\n\t  const mat = new THREE.MeshStandardMaterial({ color: colors[i % colors.length], metalness: 0.85, roughness: 0.3 });\n\t  const m = new THREE.Mesh(geo, mat); m.position.set(x, stackH/2, 0); scene.add(m);\n\t});\n\tlet html = ''<div><b>'' + TOP.length + '' assets · $'' + totalUsd.toLocaleString(undefined,{maximumFractionDigits:2}) + ''</b></div>'';\n\tTOP.forEach(t => { html += ''<div class=\"row\"><span>'' + t.symbol + ''</span><span>'' + Number(t.amount||0).toLocaleString(undefined,{maximumFractionDigits:6}) + '' · $'' + Number(t.usd||0).toLocaleString(undefined,{maximumFractionDigits:2}) + ''</span></div>''; });\n\tdocument.getElementById(''hud'').innerHTML = html;\n\tfunction tick(){ ctl.update(); renderer.render(scene, cam); requestAnimationFrame(tick); }\n\ttick();\n\t</script></body></html>`;\n\treturn { contentType: ''text/html'', content: html };"},"type":"function","function":{"name":"WalletBalances","description":"Look up real on-chain native + token balances for a wallet (Solana or EVM) and render a 3D coin-stack visualization.","parameters":{"type":"object","properties":{"chain":{"type":"string","enum":["solana","evm"]},"address":{"type":"string"}},"required":["chain","address"]}}}]',
  true,
  null
),

(
  'Token-Gate Scene',
  'token-gate-scene',
  'Create a shareable URL for the current 3D scene that only loads for wallets holding a specific token or NFT.',
  'web3',
  '{"token-gate","nft","solana","web3"}',
  '[{"clientDefinition":{"id":"pack-token-gate-001","name":"TokenGateScene","description":"Token-gate the current scene and return a share URL.","arguments":[{"name":"sceneRef","type":"string","description":"Identifier for the current scene (the chat already exposes one via the viewer share API — pass the same string the existing /share command uses)."},{"name":"chain","type":"string","description":"solana | evm"},{"name":"kind","type":"string","description":"spl | collection | erc20 | erc721"},{"name":"address","type":"string","description":"Token mint, collection address, or contract address."},{"name":"minBalance","type":"number","description":"Minimum required balance (in whole units; default 1)."}],"body":"const sceneRef = String(args.sceneRef||'''').trim();\nconst chain = String(args.chain||'''').toLowerCase();\nconst kind = String(args.kind||'''').toLowerCase();\nconst address = String(args.address||'''').trim();\nconst minBalance = Number(args.minBalance ?? 1);\nif (!sceneRef) throw new Error(''sceneRef required'');\nif (![''solana'',''evm''].includes(chain)) throw new Error(''chain must be solana or evm'');\nif (![''spl'',''collection'',''erc20'',''erc721''].includes(kind)) throw new Error(''kind must be spl|collection|erc20|erc721'');\nif (!address) throw new Error(''address required'');\nconst r = await fetch(''/api/scene/gate-create'', { method:''POST'', headers:{''content-type'':''application/json''}, credentials:''include'', body: JSON.stringify({ sceneRef, gate: { chain, kind, address, minBalance } }) });\nif (!r.ok) throw new Error(''gate-create failed: '' + r.status + '' '' + await r.text());\nconst { shareUrl, gateId } = await r.json();\nreturn { shareUrl, gateId, gate: { chain, kind, address, minBalance } };"},"type":"function","function":{"name":"TokenGateScene","description":"Create a real shareable, token-gated URL for the current 3D scene. Visitors connect a wallet and prove ownership before the scene loads.","parameters":{"type":"object","properties":{"sceneRef":{"type":"string"},"chain":{"type":"string","enum":["solana","evm"]},"kind":{"type":"string","enum":["spl","collection","erc20","erc721"]},"address":{"type":"string"},"minBalance":{"type":"number"}},"required":["sceneRef","chain","kind","address"]}}}]',
  true,
  null
)

on conflict (slug) do nothing;

commit;