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 examples for x402-fetch including zero-spend discovery and paid call scripts fix: update PATCH to PUT for notifications/preferences endpoint in social layer documentation
nirholas187fe0193e5d
diff --git a/docs/social-layer.md b/docs/social-layer.mdindex d3b38a85f..788d5506b 100644--- a/docs/social-layer.md+++ b/docs/social-layer.md@@ -120,7 +120,7 @@ POST /api/notifications/:id/read → mark one readPOST /api/notifications/read-all → mark everything readPOST /api/notifications/track → delivery/click trackingGET /api/notifications/preferences → the preference matrix-PATCH /api/notifications/preferences → update it+PUT /api/notifications/preferences → update it```Preferences are a category × channel matrixdiff --git a/mcp-server/examples/curl-session.sh b/mcp-server/examples/curl-session.shnew file mode 100644index 000000000..8dfaeeff3--- /dev/null+++ b/mcp-server/examples/curl-session.sh@@ -0,0 +1,52 @@+#!/usr/bin/env bash+# MCP Streamable HTTP lifecycle against the live three.ws server, in plain curl.+#+# The live endpoint is https://three.ws/api/mcp (MCP 2025-06-18, JSON-RPC 2.0+# over Streamable HTTP). Discovery (initialize, notifications/initialized,+# tools/list, ping) and the free getting_started tool need no account, token,+# or payment.+#+# Header rules, straight from the server implementation (api/_mcp/auth.js):+# a request carrying "Accept: text/event-stream", "MCP-Protocol-Version", or+# "Mcp-Session-Id" is treated as an OAuth-capable MCP protocol client and gets+# a 401 challenge to start the OAuth flow. A plain JSON client (like this+# script) gets free discovery instead, so we send only content-type and a JSON+# accept. The server is stateless per request and never issues a session id;+# per spec, Mcp-Session-Id is only required when the server assigns one.++set -euo pipefail++MCP_URL="${MCP_URL:-https://three.ws/api/mcp}"+H_CT='content-type: application/json'+H_ACC='accept: application/json'++echo "== 1. initialize =="+curl -sS -X POST "$MCP_URL" -H "$H_CT" -H "$H_ACC" -d '{+ "jsonrpc": "2.0", "id": 1, "method": "initialize",+ "params": {+ "protocolVersion": "2025-06-18",+ "capabilities": {},+ "clientInfo": { "name": "curl-session-example", "version": "1.0.0" }+ }+}'+echo; echo++echo "== 2. notifications/initialized (a notification: no id, null response) =="+curl -sS -X POST "$MCP_URL" -H "$H_CT" -H "$H_ACC" \+ -d '{"jsonrpc":"2.0","method":"notifications/initialized"}'+echo; echo++echo "== 3. tools/list =="+curl -sS -X POST "$MCP_URL" -H "$H_CT" -H "$H_ACC" \+ -d '{"jsonrpc":"2.0","id":2,"method":"tools/list"}'+echo; echo++echo "== 4. tools/call getting_started (free, no payment or account) =="+curl -sS -X POST "$MCP_URL" -H "$H_CT" -H "$H_ACC" -d '{+ "jsonrpc": "2.0", "id": 3, "method": "tools/call",+ "params": { "name": "getting_started", "arguments": {} }+}'+echo; echo++echo "== 5. terminate session (DELETE, expect HTTP 204) =="+curl -sS -o /dev/null -w 'HTTP %{http_code}\n' -X DELETE "$MCP_URL"diff --git a/packages/x402-fetch/README.md b/packages/x402-fetch/README.mdindex e505fed78..1e3cd206e 100644--- a/packages/x402-fetch/README.md+++ b/packages/x402-fetch/README.md@@ -94,6 +94,10 @@ const pay = wrapFetchWithPayment(fetch, wallet);| `user rejected payment` | The wallet user cancelled the signature. || `payment submitted but server still returned 402` | The retry was still gated — usually an amount/recipient mismatch. |+## Examples++Runnable scripts live in [`examples/`](./examples): a zero-spend 402 discovery probe and a real env-gated paid call against the live three.ws Market Data API.+## LicenseAll rights reserved. See [LICENSE](./LICENSE).diff --git a/packages/x402-fetch/examples/README.md b/packages/x402-fetch/examples/README.mdnew file mode 100644index 000000000..76a5a18a5--- /dev/null+++ b/packages/x402-fetch/examples/README.md@@ -0,0 +1,28 @@+# @three-ws/x402-fetch examples++Two runnable scripts against the live three.ws x402 Market Data API. Node 20+ is the only requirement; the package has zero production dependencies.++## discover.mjs (free)++Probes a paid endpoint without paying and prints the parsed 402 challenge: price, network, asset, and pay-to address for every payment rail the server accepts.++```bash+node examples/discover.mjs+```++No wallet or key needed; nothing is spent. Override the target with `X402_ENDPOINT=<url>`.++## paid-call.mjs (spends $0.001 USDC)++Wraps a private-key wallet in `withX402()` and makes a real paid call. The wrapper answers the 402 with a signed USDC-on-Base EIP-3009 authorization and returns the unlocked data.++```bash+PRIVATE_KEY=0x... node examples/paid-call.mjs+```++Requirements:++- `PRIVATE_KEY`: a Base-mainnet private key (0x-hex) holding USDC. The script exits with instructions when it is unset.+- The call costs $0.001 USDC, guarded by `maxPaymentUsd: 0.01` in the script.++Both scripts default to `https://three.ws/api/x402/market-global`; the full endpoint catalog is free at [three.ws/api/x402/market](https://three.ws/api/x402/market).diff --git a/packages/x402-fetch/examples/discover.mjs b/packages/x402-fetch/examples/discover.mjsnew file mode 100644index 000000000..2d777d2b3--- /dev/null+++ b/packages/x402-fetch/examples/discover.mjs@@ -0,0 +1,49 @@+// Zero-spend x402 discovery probe.+//+// Requests a live paid three.ws endpoint WITHOUT a payment header, receives the+// HTTP 402 challenge, and prints what the server wants: price, network, asset,+// and pay-to address for every payment rail it accepts. No wallet, no key, no+// money moves. Run it with:+//+// node examples/discover.mjs+//+// The endpoint below is one of the three.ws Market Data endpoints; the full+// catalog is free at https://three.ws/api/x402/market++const ENDPOINT = process.env.X402_ENDPOINT || 'https://three.ws/api/x402/market-global';++const res = await fetch(ENDPOINT);+console.log(`GET ${ENDPOINT}`);+console.log(`HTTP ${res.status} ${res.statusText}`);++if (res.status !== 402) {+ console.log('No payment challenge returned; the endpoint answered without one.');+ console.log(await res.text());+ process.exit(0);+}++// three.ws ships the x402 v2 envelope both as the JSON body and, base64-encoded,+// in the PAYMENT-REQUIRED response header. The body is the easy path here.+const challenge = await res.json();++console.log(`\nx402 version: ${challenge.x402Version}`);+console.log(`resource: ${challenge.resource?.url}`);+console.log(`description: ${challenge.resource?.description?.slice(0, 120)}...`);+console.log(`\naccepts[] (${challenge.accepts.length} payment rails):\n`);++for (const accept of challenge.accepts) {+ const decimals = Number(accept.extra?.decimals ?? 6);+ const usd = Number(accept.amount) / 10 ** decimals;+ const method =+ accept.extra?.assetTransferMethod ||+ (String(accept.network).startsWith('eip155:') ? 'eip3009 (default)' : 'native to network');+ console.log(` scheme: ${accept.scheme}`);+ console.log(` network: ${accept.network}`);+ console.log(` asset: ${accept.asset} (${accept.extra?.name ?? 'unknown'})`);+ console.log(` amount: ${accept.amount} atomic units = $${usd} (${decimals} decimals)`);+ console.log(` payTo: ${accept.payTo}`);+ console.log(` method: ${method}`);+ console.log('');+}++console.log('Nothing was paid. See paid-call.mjs to actually answer the challenge.');diff --git a/packages/x402-fetch/examples/paid-call.mjs b/packages/x402-fetch/examples/paid-call.mjsnew file mode 100644index 000000000..75bcb9356--- /dev/null+++ b/packages/x402-fetch/examples/paid-call.mjs@@ -0,0 +1,46 @@+// Real paid x402 call with @three-ws/x402-fetch.+//+// Wraps a private-key wallet in withX402() and calls a live three.ws Market+// Data endpoint. On the 402 challenge the wrapper signs a USDC-on-Base+// EIP-3009 authorization and retries with the X-PAYMENT header, so the await+// below resolves with the unlocked data.+//+// THIS SPENDS REAL MONEY: $0.001 USDC from the wallet behind PRIVATE_KEY.+// The wallet needs USDC on Base mainnet. Run it with:+//+// PRIVATE_KEY=0x... node examples/paid-call.mjs+//+// Installed consumers import from '@three-ws/x402-fetch' instead of ../src/.++import { withX402, privateKeyToWallet } from '../src/index.js';++const pk = process.env.PRIVATE_KEY;+if (!pk) {+ console.error('PRIVATE_KEY is not set.');+ console.error('Export a funded Base-mainnet private key (0x-hex, holds USDC) and rerun:');+ console.error(' PRIVATE_KEY=0x... node examples/paid-call.mjs');+ console.error('This example makes a real $0.001 USDC payment; there is no dry-run mode.');+ process.exit(1);+}++const ENDPOINT = process.env.X402_ENDPOINT || 'https://three.ws/api/x402/market-global';++const pay = withX402(privateKeyToWallet(pk), {+ // Hard spend ceiling per request. The endpoint costs $0.001; anything above+ // this limit throws instead of paying.+ maxPaymentUsd: 0.01,+ onPayment: ({ amount, to, requestUrl }) => {+ console.log(`paying $${amount} USDC to ${to} for ${requestUrl}`);+ },+});++console.log(`GET ${ENDPOINT} (auto-paying on 402)`);+const res = await pay(ENDPOINT);+console.log(`HTTP ${res.status} ${res.statusText}`);++const receipt = res.headers.get('x-payment-response');+if (receipt) console.log(`settle receipt (base64): ${receipt.slice(0, 60)}...`);++const data = await res.json();+console.log('\nUnlocked payload:');+console.log(JSON.stringify(data, null, 2));