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(x402): list agents sold as paid APIs in discovery and the catalog, and wire the owner's Earn tab client
nirholasb55a31752dc9
diff --git a/api/wk.js b/api/wk.jsindex d3d71ac94..f649bfb6f 100644--- a/api/wk.js+++ b/api/wk.js@@ -46,6 +46,8 @@ import { loadYieldPools } from './defi/yields.js';import { buildExchanges } from './coin/exchanges.js';import { FORGE_OUTPUT_EXAMPLE } from './_lib/forge-listing.js';import { listBazaarServices, serviceResourceUrl } from './_lib/agent-paid-services.js';+import { listActiveAgentServices, CALL_INPUT_EXAMPLE, CALL_INPUT_SCHEMA, CALL_OUTPUT_EXAMPLE, serviceNameFor } from './_lib/agent-api-service.js';+import { buildRequirements } from './_lib/x402-paid-endpoint.js';import { toBazaarDiscovery } from './_lib/service-catalog/index.js';// ── agent-attestation-schemas ─────────────────────────────────────────────────@@ -488,6 +490,63 @@ async function buildAgentServiceItems(origin) {return items;}+// Whole agents sold as paid APIs (POST /api/x402/agents/:id, switched on from+// the agent wallet's Earn tab). One entry per agent on sale, built with the SAME+// buildRequirements() call the live route makes, so the advertised accepts+// (Solana USDC to the agent's own payout wallet, the owner's price) are exactly+// what the 402 will ask for. Never throws: a DB hiccup yields no rows and the+// rest of the catalog still renders.+async function buildSellableAgentItems() {+ let services;+ try {+ services = await listActiveAgentServices({ limit: 200 });+ } catch (err) {+ console.error('[wk/x402-discovery] agent API services unavailable', err?.message || err);+ return [];+ }+ const items = [];+ for (const svc of services) {+ let accepts;+ try {+ accepts = buildRequirements({+ priceAtomics: svc.price_atomics,+ networks: ['solana'],+ resourceUrl: svc.url,+ payToOverride: { solana: svc.pay_to },+ acceptThree: false,+ }).map((a) => ({+ ...a,+ network_label: 'solana-mainnet',+ price: RAW_AMOUNT_TO_USDC(a.amount),+ asset_symbol: 'USDC',+ }));+ } catch (err) {+ // Solana settlement is not configured on this deploy, so the live route+ // would refuse too. Skip rather than advertise an unpayable entry.+ console.error('[wk/x402-discovery] agent API accepts unavailable', err?.message || err);+ return [];+ }+ items.push({+ path: svc.path,+ url: svc.url,+ method: 'POST',+ description: `${svc.description} (one turn with ${svc.name} on three.ws)`,+ mimeType: 'application/json',+ serviceName: serviceNameFor({ name: svc.name }),+ tags: ['agent', 'chat', 'pay-per-call', 'solana'],+ accepts,+ extensions: extensionsForAccepts(accepts, {+ method: 'POST',+ discoverable: true,+ input: CALL_INPUT_EXAMPLE,+ inputSchema: CALL_INPUT_SCHEMA,+ output: { type: 'json', example: CALL_OUTPUT_EXAMPLE },+ }),+ });+ }+ return items;+}+// Datapoint fabric (/api/x402/d/<family>/<id>/<metric>) — 400k+ addressable// single-datapoint endpoints served by one dynamic route. Every one already// exists and settles; the discovery doc advertises a WIDE enumerated slice so@@ -1734,6 +1793,7 @@ export async function buildX402DiscoveryDoc() {// Agent-published paid services — dynamic, one entry per active listing.const agentServiceItems = await buildAgentServiceItems(origin);+ const sellableAgentItems = await buildSellableAgentItems();const datapointItems = await buildDatapointItems(origin);return {@@ -1828,6 +1888,9 @@ export async function buildX402DiscoveryDoc() {// Agent-published paid endpoints (monetize_endpoint). Dynamic —// one entry per active agent_paid_services listing....agentServiceItems,+ // Whole agents sold as paid APIs (Earn tab switch). Dynamic, one+ // entry per public agent whose owner turned the service on.+ ...sellableAgentItems,// Datapoint fabric (/api/x402/d/…): a curated, runtime-derived// slice of the 400k+ addressable single-datapoint endpoints, so// indexers surface the fabric; the full id space is enumerateddiff --git a/public/x402-stripe.html b/public/x402-stripe.htmlindex 7abe004d0..5bb1b6b3f 100644--- a/public/x402-stripe.html+++ b/public/x402-stripe.html@@ -593,6 +593,7 @@// ── Category classification (derived from path + copy) ─────────────────const CATS = [+ { key: 'Agents', icon: '◉', test: /^\/api\/x402\/agents\//i },{ key: 'Crypto', icon: '◎', test: /pump|token|mint|vanity|symbol|intel|crypto|cross-chain|three-intel|reputation|bouncer|identity|did/i },{ key: '3D', icon: '◈', test: /mesh|forge|model|avatar|animation|cosmetic|club|dance|glb/i },{ key: 'AI', icon: '✦', test: /fact-check|tutor|vision|insight/i },@@ -664,12 +665,39 @@});}}+ items.push(...(await loadAgentServices()));// de-dupe by path (prefer the paid/GET representation), keep stableconst seen = new Map();for (const it of items) { if (!seen.has(it.path)) seen.set(it.path, it); }return Array.from(seen.values());}+ // Whole agents their owners sell as a paid API (POST /api/x402/agents/:id).+ // Listed live from /api/x402/agents; a failure here only hides that one+ // category, never the rest of the catalog.+ async function loadAgentServices() {+ try {+ const r = await fetch('/api/x402/agents', { headers: { accept: 'application/json' } });+ if (!r.ok) return [];+ const doc = await r.json();+ const msg = doc.input_schema && doc.input_schema.properties && doc.input_schema.properties.message;+ return (doc.services || []).map((svc) => ({+ id: 'agent:' + svc.agent_id,+ path: svc.path,+ method: 'POST',+ title: svc.name,+ desc: svc.description,+ price: { amount: Number(svc.price_usd), min: null, max: null, note: '' },+ params: [],+ bodyProps: msg ? [{ name: 'message', required: true, ...schemaInfo(msg) }] : [],+ category: 'Agents',+ rails: 'USDC · Solana',+ }));+ } catch {+ return [];+ }+ }+// ── Category chips ───────────────────────────────────────────────────────function renderChips() {const counts = { All: CATALOG.length };@@ -714,7 +742,7 @@<span class="top"><span class="cat">${catIcon(c.category)} ${esc(c.category)}</span><span class="price ${priceClass(c.price)}">${esc(priceChip(c.price))}</span></span><span class="title">${esc(c.title)}</span><span class="desc">${esc(c.desc)}</span>- <span class="meta"><span class="verb">${c.method}</span><span>USDC · Base · Solana</span></span>+ <span class="meta"><span class="verb">${c.method}</span><span>${esc(c.rails || 'USDC · Base · Solana')}</span></span><span class="run"><span class="go">Inspect & run <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2"><path d="M5 12h14M13 6l6 6-6 6"/></svg></span></span></button>`;}).join('');diff --git a/src/agent-economy-hub.js b/src/agent-economy-hub.jsindex 8a377c032..a018ee206 100644--- a/src/agent-economy-hub.js+++ b/src/agent-economy-hub.js@@ -7,6 +7,8 @@* - savePricing → PUT /api/agents/:id/skills-pricing (atomic price replace)* - fetchLimits → GET /api/agents/:id/solana/limits (spend policy snapshot)* - setFrozen → PUT /api/agents/:id/solana/limits (kill switch)+ * - fetchApiService → GET /api/agents/:id/api-service (sell-as-API config + earnings)+ * - saveApiService → PUT /api/agents/:id/api-service (owner switch, price, description)** Every read is real DB/chain state; every write is owner-authenticated +* CSRF-protected server-side. Mirrors the Withdraw tab's `call` shape so the UI@@ -41,6 +43,7 @@ async function call(url, { method = 'GET', body = null } = {}) {code: j?.error || j?.code || 'error',message: j?.error_description || j?.message || `request failed (${r.status})`,detail: j?.detail || null,+ reasons: Array.isArray(j?.reasons) ? j.reasons : null,};}return { ok: true, status: r.status, data: j?.data ?? j };@@ -79,3 +82,19 @@ export function fetchLimits(agentId) {export function setFrozen(agentId, frozen) {return call(`/api/agents/${enc(agentId)}/solana/limits`, { method: 'PUT', body: { frozen: !!frozen } });}++/**+ * The "Sell this agent as an API" service: stored config, endpoint URL, payout,+ * sellability (with owner-facing reasons) and earnings from agent_revenue_events.+ */+export function fetchApiService(agentId) {+ return call(`/api/agents/${enc(agentId)}/api-service`);+}++/**+ * Save { active, price_usd, description }. Validated server-side; activation is+ * refused with `reasons` when the agent cannot be sold.+ */+export function saveApiService(agentId, config) {+ return call(`/api/agents/${enc(agentId)}/api-service`, { method: 'PUT', body: config });+}