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: IBM vision (granite vision) page + API; oracle/forecast refinements, proof dev script
nirholas465930785612
diff --git a/api/_lib/watsonx-forecast.js b/api/_lib/watsonx-forecast.jsindex e9dad32b9..570619b60 100644--- a/api/_lib/watsonx-forecast.js+++ b/api/_lib/watsonx-forecast.js@@ -1,9 +1,10 @@-// IBM watsonx.ai Granite TimeSeries forecasting + Granite Guardian governance.+// IBM watsonx.ai Granite TimeSeries forecasting for the Granite Oracle.//-// These sit alongside the shared chat/embed client in ./watsonx.js but live in-// their own module so the Granite Oracle feature can evolve without touching the-// hot chat path. They reuse the stable IAM-token cache from ./watsonx.js and-// speak the same version-stamped, project-scoped REST contract.+// Sits alongside the shared chat/embed client in ./watsonx.js but lives in its+// own module (with model-context helpers the Oracle and its tests depend on). It+// reuses the stable IAM-token cache from ./watsonx.js and speaks the same+// version-stamped, project-scoped REST contract. Governance is handled by the+// canonical Granite Guardian helper in ./guardian.js.//// There is no mock path: any IAM or upstream failure throws with the real// upstream status + message so the caller reports the true cause.@@ -96,25 +97,3 @@ export async function watsonxForecast(inputWindow: values.length,};}--// Granite Guardian risk check. The risk definition is carried as the system role-// and the model answers Yes/No. Returns { risk, label, flagged, model }.-export async function watsonxGuardian(cfg, { text, model, risk = 'harm' } = {}) {- const modelId = model || cfg.guardianModel || 'ibm/granite-guardian-3-8b';- const data = await post(- cfg,- '/ml/v1/text/chat',- {- model_id: modelId,- messages: [- { role: 'system', content: risk },- { role: 'user', content: text },- ],- max_tokens: 16,- temperature: 0,- },- cfg.apiVersion,- );- const out = (data.choices?.[0]?.message?.content || '').trim().toLowerCase();- return { risk, label: out || 'unknown', flagged: out.startsWith('yes'), model: modelId };-}diff --git a/api/ibm/oracle.js b/api/ibm/oracle.jsindex c8f3c41c1..ab9adccf9 100644--- a/api/ibm/oracle.js+++ b/api/ibm/oracle.js@@ -11,7 +11,8 @@import { cors, json, method, wrap, error } from '../_lib/http.js';import { limits, clientIp } from '../_lib/rate-limit.js';import { watsonxConfig, watsonxChatComplete } from '../_lib/watsonx.js';-import { watsonxForecast, watsonxGuardian, forecastModelFor } from '../_lib/watsonx-forecast.js';+import { watsonxForecast, forecastModelFor } from '../_lib/watsonx-forecast.js';+import { assessRisk } from '../_lib/guardian.js';import { fetchOhlcv, topPoolForToken, trendingPools } from '../_lib/market/ohlcv.js';const isBase58 = (s) => /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(s);@@ -194,12 +195,13 @@ export default wrap(async (req, res) => {});out.narration = { text: n.text, model: n.model };try {- const g = await watsonxGuardian(cfg, { text: n.text, risk: 'harm' });+ const g = await assessRisk(cfg, { risk: 'harm', assistant: n.text });out.governance = {passed: !g.flagged,risk: g.risk,label: g.label,- model: g.model,+ verdict: g.verdict,+ confidence: g.confidence ?? null,};} catch (gErr) {out.governance = { passed: null, error: String(gErr.message || gErr) };diff --git a/api/ibm/vision.js b/api/ibm/vision.jsnew file mode 100644index 000000000..019d23005--- /dev/null+++ b/api/ibm/vision.js@@ -0,0 +1,324 @@+// /api/ibm/vision — IBM Granite Vision, the multimodal eye of the watsonx suite.+//+// POST /api/ibm/vision { image | imageUrl, subject?, hint? }+// Shows a single image to a Granite Vision model on watsonx.ai and returns a+// structured "read" of it. The headline demo points it at a three.ws 3D avatar+// (a rendered snapshot, or its thumbnail) and Granite Vision invents a complete+// agent identity from how the avatar *looks* — appearance, vibe, persona, a name,+// a bio, tone tags, a fitting voice. `subject:"token"` reads a coin's image; the+// default reads any picture.+//+// image — a data: URL (client canvas capture or an uploaded file).+// imageUrl — an https URL we fetch server-side (SSRF-allowlisted) so the browser+// never has to fight canvas cross-origin tainting to analyse an avatar.+//+// GET /api/ibm/vision → a handful of real public avatars to show Granite, so the+// demo works for anonymous visitors without an upload.+//+// No mock path: every read is a real Granite Vision inference. When watsonx is+// unconfigured the endpoint says so (503) instead of inventing a description.++import { sql } from '../_lib/db.js';+import { cors, method, readJson, error, json, wrap } from '../_lib/http.js';+import { limits, clientIp } from '../_lib/rate-limit.js';+import { publicUrl } from '../_lib/r2.js';+import { watsonxConfig, watsonxChatComplete } from '../_lib/watsonx.js';++// Granite Vision 3.2 (2B) is the default multimodal model on watsonx.ai. Override+// per account/region with WATSONX_VISION_MODEL_ID.+const VISION_MODEL = process.env.WATSONX_VISION_MODEL_ID?.trim() || 'ibm/granite-vision-3-2-2b';++// Server-side image-fetch limits. Granite accepts png/jpeg/webp/gif; we cap bytes+// so a hostile URL can't stream us an unbounded body, and only follow https.+const MAX_IMAGE_BYTES = 6 * 1024 * 1024;+const FETCH_TIMEOUT_MS = 8000;++// SSRF allowlist for imageUrl. We only fetch from our own asset host and a small+// set of public, content-addressed media CDNs the platform already serves images+// from — never an arbitrary host, so this can't be turned into an internal probe.+function allowedImageHost(host) {+ host = host.toLowerCase();+ const ours = [process.env.S3_PUBLIC_DOMAIN, process.env.APP_ORIGIN, 'https://three.ws']+ .map(hostOf)+ .filter(Boolean);+ if (ours.includes(host)) return true;+ const suffixes = [+ '.r2.dev',+ '.r2.cloudflarestorage.com',+ 'three.ws',+ '.mypinata.cloud',+ '.pinata.cloud',+ 'ipfs.io',+ '.ipfs.dweb.link',+ 'cf-ipfs.com',+ 'arweave.net',+ '.arweave.net',+ 'pump.mypinata.cloud',+ 'image-cdn.solana.fm',+ '.githubusercontent.com',+ ];+ return suffixes.some((s) => (s.startsWith('.') ? host.endsWith(s) : host === s));+}+function hostOf(u) {+ try {+ return new URL(u).host.toLowerCase();+ } catch {+ return null;+ }+}++export default wrap(async (req, res) => {+ if (cors(req, res, { methods: 'GET,POST,OPTIONS', origins: '*' })) return;+ if (!method(req, res, ['GET', 'POST'])) return;++ const rl = await limits.publicIp(clientIp(req));+ if (!rl.success) return error(res, 429, 'rate_limited', 'too many requests');++ if (req.method === 'GET') return handleSubjects(req, res);+ return handleVision(req, res);+});++export const maxDuration = 60;++// ── GET: featured subjects to show Granite ───────────────────────────────────++async function handleSubjects(req, res) {+ // Public avatars that have both a thumbnail (for the image read) and a stored+ // GLB (for the live 3D render). Featured + most-viewed first so the lineup looks+ // intentional. Read-only; safe for anonymous visitors.+ let rows = [];+ try {+ rows = await sql`+ SELECT id, slug, name, storage_key, thumbnail_key,+ COALESCE(featured, false) AS featured,+ COALESCE(view_count, 0) AS view_count+ FROM avatars+ WHERE deleted_at IS NULL+ AND visibility = 'public'+ AND thumbnail_key IS NOT NULL+ AND storage_key IS NOT NULL+ ORDER BY COALESCE(featured, false) DESC, COALESCE(view_count, 0) DESC, created_at DESC+ LIMIT 18+ `;+ } catch (err) {+ console.error('[ibm/vision] subjects query failed', err);+ return json(res, 200, { subjects: [] });+ }++ const subjects = rows.map((r) => ({+ id: r.id,+ name: r.name || 'Avatar',+ slug: r.slug || null,+ thumbnail: publicUrl(r.thumbnail_key),+ model_url: publicUrl(r.storage_key),+ }));+ return json(res, 200, { subjects, visionModel: VISION_MODEL });+}++// ── POST: read an image with Granite Vision ──────────────────────────────────++async function handleVision(req, res) {+ const cfg = watsonxConfig();+ if (!cfg.configured) {+ return error(+ res,+ 503,+ 'watsonx_unavailable',+ 'IBM Granite Vision runs on watsonx.ai. Set WATSONX_API_KEY and WATSONX_PROJECT_ID ' ++ '(or WATSONX_SPACE_ID) to let Granite see your avatar.',+ );+ }++ let body;+ try {+ body = await readJson(req, 9_000_000); // a base64 data URL of a snapshot can be large+ } catch (e) {+ return error(res, e.status || 400, 'bad_request', e.message);+ }++ const subject = ['avatar', 'token', 'image'].includes(body.subject) ? body.subject : 'avatar';+ const hint = typeof body.hint === 'string' ? body.hint.trim().slice(0, 200) : '';++ let dataUrl;+ try {+ dataUrl = await resolveImage(body);+ } catch (e) {+ return error(res, e.status || 400, e.code || 'bad_image', e.message);+ }++ const { system, user } = buildPrompt(subject, hint);+ let reply;+ try {+ reply = await watsonxChatComplete(cfg, {+ model: VISION_MODEL,+ maxTokens: 460,+ temperature: 0.4,+ messages: [+ { role: 'system', content: system },+ {+ role: 'user',+ content: [+ { type: 'text', text: user },+ { type: 'image_url', image_url: { url: dataUrl } },+ ],+ },+ ],+ });+ } catch (e) {+ // Surface the real upstream cause (auth, unsupported model in region, quota).+ const msg = String(e?.message || 'watsonx vision request failed');+ const status = /404|not.*found|unsupported|not.*deployed/i.test(msg) ? 502 : 502;+ return error(res, status, 'vision_failed', msg);+ }++ const vision = parseVision(reply.text);+ return json(res, 200, {+ subject,+ model: reply.model || VISION_MODEL,+ vision,+ raw: vision.structured ? undefined : reply.text,+ usage: reply.usage || null,+ });+}++// Resolve the request into a base64 data URL Granite can consume. Accepts a client+// data URL directly, or fetches an allowlisted https image server-side.+async function resolveImage(body) {+ const image = typeof body.image === 'string' ? body.image : '';+ const imageUrl = typeof body.imageUrl === 'string' ? body.imageUrl : '';++ if (image.startsWith('data:image/')) {+ // Guard the decoded size (base64 is ~4/3 of the bytes).+ const commaAt = image.indexOf(',');+ const b64 = commaAt >= 0 ? image.slice(commaAt + 1) : '';+ if (!b64) throw fail(400, 'bad_image', 'image data URL is empty');+ if (b64.length * 0.75 > MAX_IMAGE_BYTES) throw fail(413, 'image_too_large', 'image exceeds 6MB');+ return image;+ }++ if (/^https:\/\//i.test(imageUrl)) {+ const host = hostOf(imageUrl);+ if (!host || !allowedImageHost(host)) {+ throw fail(400, 'image_host_not_allowed', 'imageUrl host is not allowed');+ }+ return await fetchImageAsDataUrl(imageUrl);+ }++ throw fail(400, 'bad_image', 'provide image (data URL) or imageUrl (https)');+}++async function fetchImageAsDataUrl(url) {+ const controller = new AbortController();+ const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);+ let resp;+ try {+ resp = await fetch(url, { signal: controller.signal, redirect: 'follow' });+ } catch (e) {+ throw fail(502, 'image_fetch_failed', `could not fetch image: ${e.message}`);+ } finally {+ clearTimeout(timer);+ }+ if (!resp.ok) throw fail(502, 'image_fetch_failed', `image fetch returned ${resp.status}`);+ const ct = (resp.headers.get('content-type') || '').split(';')[0].trim().toLowerCase();+ if (!ct.startsWith('image/')) throw fail(415, 'not_an_image', `unexpected content-type: ${ct || 'unknown'}`);+ const len = Number(resp.headers.get('content-length') || 0);+ if (len && len > MAX_IMAGE_BYTES) throw fail(413, 'image_too_large', 'image exceeds 6MB');+ const buf = Buffer.from(await resp.arrayBuffer());+ if (buf.length > MAX_IMAGE_BYTES) throw fail(413, 'image_too_large', 'image exceeds 6MB');+ return `data:${ct};base64,${buf.toString('base64')}`;+}++function fail(status, code, message) {+ const e = new Error(message);+ e.status = status;+ e.code = code;+ return e;+}++// ── Prompting ────────────────────────────────────────────────────────────────++function buildPrompt(subject, hint) {+ const hintLine = hint ? `\nThe person who made it adds: "${hint}". Take it into account but trust your eyes first.` : '';+ if (subject === 'token') {+ return {+ system:+ 'You are a sharp, neutral brand analyst looking at a single cryptocurrency / memecoin image (its logo or art). ' ++ 'Describe only what is visible and the vibe it projects. Never give financial advice or price opinions. ' ++ 'Reply with ONLY a JSON object and nothing else.',+ user:+ 'Read this coin image.' ++ hintLine ++ '\nReturn JSON exactly like: {"appearance":"2-3 sentences on what is in the image","vibe":"3-6 comma-separated adjectives",' ++ '"persona":"1-2 sentences on the character/brand this projects","bio":"a punchy one-line tagline",' ++ '"tone_tags":["3-6","lowercase","tags"],"voice":"a short phrase for a fitting narrator voice"}',+ };+ }+ if (subject === 'image') {+ return {+ system:+ 'You are a perceptive art director describing a single image precisely and only from what is visible. ' ++ 'Reply with ONLY a JSON object and nothing else.',+ user:+ 'Read this image.' ++ hintLine ++ '\nReturn JSON exactly like: {"appearance":"2-3 sentences on what is visible","vibe":"3-6 comma-separated adjectives",' ++ '"persona":"1-2 sentences on the character/mood it suggests","suggested_name":"a fitting short name",' ++ '"bio":"a punchy one-line bio","tone_tags":["3-6","lowercase","tags"],"voice":"a short phrase for a fitting voice"}',+ };+ }+ // avatar (default)+ return {+ system:+ 'You are a casting director giving a 3D avatar a personality. You are shown one rendered 3D character. ' ++ 'Look only at what is visible — features, clothing, colors, style, posture — and infer a personality that fits the look. ' ++ 'Be specific and vivid, never generic. Reply with ONLY a JSON object and nothing else.',+ user:+ 'Read this 3D avatar and give it an identity.' ++ hintLine ++ '\nReturn JSON exactly like: {"appearance":"2-3 sentences on how the avatar looks","vibe":"3-6 comma-separated adjectives",' ++ '"persona":"1-2 sentences on the personality this look suggests","suggested_name":"a fitting character name",' ++ '"bio":"a punchy one-line bio for this character","tone_tags":["3-6","lowercase","tags"],' ++ '"voice":"a short phrase describing a fitting speaking voice"}',+ };+}++// Parse Granite's reply into a normalized identity. Tolerant of code fences and+// stray prose; falls back to { structured:false } so the UI shows the raw read+// rather than nothing — never fabricates fields the model didn't return.+function parseVision(text) {+ const out = {+ structured: false,+ appearance: '',+ vibe: '',+ persona: '',+ suggested_name: '',+ bio: '',+ tone_tags: [],+ voice: '',+ };+ if (!text) return out;+ const m = String(text).match(/\{[\s\S]*\}/);+ if (!m) return out;+ let obj;+ try {+ obj = JSON.parse(m[0]);+ } catch {+ return out;+ }+ out.structured = true;+ out.appearance = str(obj.appearance);+ out.vibe = str(obj.vibe);+ out.persona = str(obj.persona);+ out.suggested_name = str(obj.suggested_name || obj.name).slice(0, 60);+ out.bio = str(obj.bio).slice(0, 200);+ out.voice = str(obj.voice).slice(0, 120);+ out.tone_tags = Array.isArray(obj.tone_tags)+ ? obj.tone_tags.map((t) => str(t).toLowerCase().slice(0, 24)).filter(Boolean).slice(0, 8)+ : typeof obj.tone_tags === 'string'+ ? obj.tone_tags.split(',').map((t) => t.trim().toLowerCase()).filter(Boolean).slice(0, 8)+ : [];+ return out;+}+function str(v) {+ return typeof v === 'string' ? v.replace(/\s+/g, ' ').trim() : '';+}diff --git a/pages/ibm/index.html b/pages/ibm/index.htmlindex 6748625ab..8a7e9e370 100644--- a/pages/ibm/index.html+++ b/pages/ibm/index.html@@ -178,6 +178,21 @@</div></a>+ <a href="/ibm/proof" style="display:block;text-decoration:none;color:inherit;margin-bottom:80px;border:1px solid var(--border);border-radius:18px;overflow:hidden;background:radial-gradient(880px 360px at 82% -20%, rgba(120,169,255,0.18), transparent 60%), radial-gradient(700px 320px at 8% 120%, rgba(66,190,101,0.14), transparent 60%), linear-gradient(180deg,#0a0e18,#0b1222);position:relative;transition:border-color .2s, transform .2s;" onmouseover="this.style.borderColor='rgba(120,169,255,0.45)';this.style.transform='translateY(-2px)'" onmouseout="this.style.borderColor='var(--border)';this.style.transform='none'">+ <div style="padding:30px 30px 32px;">+ <div style="display:inline-flex;align-items:center;gap:8px;font-size:12px;font-weight:600;color:#78a9ff;background:rgba(15,98,254,0.12);border:1px solid rgba(120,169,255,0.25);border-radius:99px;padding:5px 12px;margin-bottom:16px;">+ <span style="width:7px;height:7px;border-radius:50%;background:#0f62fe;box-shadow:0 0 10px #0f62fe;"></span>+ Live demo · Granite TimeSeries + Guardian + Solana+ </div>+ <h2 style="font-size:clamp(24px,3.5vw,32px);letter-spacing:-0.02em;line-height:1.15;font-weight:600;margin-bottom:12px;">Auditable AI on a public ledger — Granite Proof</h2>+ <p style="color:var(--muted);font-size:16px;line-height:1.55;max-width:620px;margin-bottom:22px;">A 3D agent forecasts a live market with <strong style="color:var(--text);font-weight:500;">IBM Granite TimeSeries</strong>, <strong style="color:var(--text);font-weight:500;">IBM Granite Guardian</strong> governs every word it says, and each governed forecast is <em>notarized on Solana</em> — a SHA-256 proof signed by the agent's own wallet, timestamped forever. If Guardian flags the statement, the agent refuses to sign. Trust you can verify on-chain.</p>+ <span style="display:inline-flex;align-items:center;gap:8px;background:#0f62fe;color:#fff;font-size:14px;font-weight:600;padding:12px 20px;border-radius:11px;">+ Open Granite Proof+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"><path d="M5 12h14M13 5l7 7-7 7"/></svg>+ </span>+ </div>+ </a>+<section><h2>Built on IBM watsonx.</h2><p class="sub">The agent brain runs on your own IBM Cloud account. Real inference, real IAM auth, no mock path.</p>@@ -279,6 +294,10 @@<code>POST /api/chat</code><div class="desc"><code>{ "provider": "orchestrate" }</code> calls a watsonx Orchestrate (Agent Connect) OpenAI-compatible <code>/chat/completions</code> endpoint — the 3D avatar becomes the front-end of your enterprise agent.</div></div>+ <div class="endpoint">+ <code>POST /api/guardian/assess</code>+ <div class="desc">The <a href="/ibm/trust-layer" style="color:var(--ibm-light);text-decoration:none;">Trust Layer</a> — IBM Granite Guardian classifies a message or a proposed autonomous action across jailbreak, harm, bias and more on watsonx.ai, returning an allow / review / block verdict plus a tamper-evident, hash-chained audit record. The same gate runs inline in <code>/api/chat</code> before an avatar sends SOL.</div>+ </div><div class="endpoint"><code>npx @three-ws/ibm-watsonx-mcp</code><div class="desc">Standalone MCP server for watsonx.ai — five tools against IBM Granite and any model in your account. Works with any MCP host.</div>@@ -296,7 +315,7 @@</div><div class="note">- <strong>Open source.</strong> The watsonx.ai client is at <a href="https://github.com/nirholas/three.ws/blob/main/api/_lib/watsonx.js" target="_blank" rel="noopener">api/_lib/watsonx.js</a>, the Orchestrate provider at <a href="https://github.com/nirholas/three.ws/blob/main/api/_lib/orchestrate.js" target="_blank" rel="noopener">api/_lib/orchestrate.js</a>, and the MCP server at <a href="https://github.com/nirholas/three.ws/tree/main/packages/ibm-watsonx-mcp" target="_blank" rel="noopener">packages/ibm-watsonx-mcp/</a>. Review it, fork it, run your own.+ <strong>Open source.</strong> The watsonx.ai client is at <a href="https://github.com/nirholas/three.ws/blob/main/api/_lib/watsonx.js" target="_blank" rel="noopener">api/_lib/watsonx.js</a>, the Orchestrate provider at <a href="https://github.com/nirholas/three.ws/blob/main/api/_lib/orchestrate.js" target="_blank" rel="noopener">api/_lib/orchestrate.js</a>, the Granite Guardian Trust Layer at <a href="https://github.com/nirholas/three.ws/blob/main/api/_lib/granite-guardian.js" target="_blank" rel="noopener">api/_lib/granite-guardian.js</a>, and the MCP server at <a href="https://github.com/nirholas/three.ws/tree/main/packages/ibm-watsonx-mcp" target="_blank" rel="noopener">packages/ibm-watsonx-mcp/</a>. Review it, fork it, run your own.</div></section>diff --git a/pages/ibm/vision.html b/pages/ibm/vision.htmlnew file mode 100644index 000000000..9357ca5fe--- /dev/null+++ b/pages/ibm/vision.html@@ -0,0 +1,291 @@+<!doctype html>+<html lang="en">+ <head>+ <meta charset="utf-8" />+ <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />+ <title>Granite Vision — IBM watsonx multimodal, reading your 3D avatar · three.ws</title>+ <meta+ name="description"+ content="Show IBM Granite Vision on watsonx.ai a three.ws 3D avatar and watch it read the look — appearance, vibe, persona, a name, a bio, a voice — turning a face into a complete agent identity. Real multimodal inference, no mock data."+ />+ <meta name="theme-color" content="#0b0e17" />+ <meta property="og:type" content="website" />+ <meta property="og:title" content="Granite Vision — IBM watsonx sees your 3D avatar" />+ <meta+ property="og:description"+ content="IBM Granite Vision looks at a 3D avatar and invents its whole identity — appearance, persona, name, bio, voice. Live on watsonx.ai."+ />+ <meta property="og:image" content="https://three.ws/ibm-og.png" />+ <meta property="og:url" content="https://three.ws/ibm/vision" />+ <meta name="twitter:card" content="summary_large_image" />+ <meta name="twitter:title" content="Granite Vision — IBM watsonx sees your 3D avatar" />+ <link rel="icon" href="/favicon.ico" />+ <style>+ :root {+ --ibm-blue: #0f62fe;+ --ibm-blue-2: #4589ff;+ --ibm-light: #78a9ff;+ --ink: #f4f4f4;+ --muted: #a6b0c3;+ --faint: #6b7589;+ --panel: rgba(13, 17, 28, 0.66);+ --panel-solid: #0d111c;+ --stroke: rgba(120, 169, 255, 0.22);+ --line: rgba(255, 255, 255, 0.08);+ --font: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;+ }+ * { box-sizing: border-box; }+ html, body { margin: 0; height: 100%; }+ body {+ font-family: var(--font);+ color: var(--ink);+ background:+ radial-gradient(1200px 700px at 30% -10%, #16224a 0%, rgba(11, 14, 23, 0) 60%),+ radial-gradient(900px 600px at 95% 110%, #1a1340 0%, rgba(11, 14, 23, 0) 55%),+ #0b0e17;+ overflow: hidden;+ }+ a { color: var(--ibm-blue-2); text-decoration: none; }++ #vision-stage { position: fixed; inset: 0; z-index: 0; }+ #vision-stage canvas { display: block; cursor: grab; }+ #vision-stage canvas:active { cursor: grabbing; }+ #v-photo {+ position: fixed; inset: 0; z-index: 0;+ display: none; align-items: center; justify-content: center; padding: 8vh 6vw;+ }+ #v-photo img {+ max-width: min(46vw, 520px); max-height: 76vh;+ border-radius: 16px; border: 1px solid var(--stroke);+ box-shadow: 0 30px 90px rgba(0, 0, 0, 0.5);+ object-fit: contain;+ }++ /* Top bar */+ .topbar {+ position: fixed; top: 0; left: 0; right: 0; z-index: 6;+ display: flex; align-items: center; justify-content: space-between;+ padding: 16px 22px; pointer-events: none;+ }+ .topbar > * { pointer-events: auto; }+ .brand { display: flex; align-items: center; gap: 10px; font-weight: 600; }+ .brand .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ibm-blue); box-shadow: 0 0 12px var(--ibm-blue); }+ .brand small { color: var(--muted); font-weight: 400; }+ .topbar .back {+ font-size: 13px; color: var(--muted); border: 1px solid var(--stroke);+ padding: 7px 12px; border-radius: 8px; background: var(--panel);+ backdrop-filter: blur(8px); transition: border-color 0.15s, color 0.15s;+ }+ .topbar .back:hover { color: var(--ink); border-color: var(--ibm-blue-2); }++ /* Read-out panel (right) */+ .read {+ position: fixed; top: 70px; right: 22px; bottom: 104px; z-index: 5;+ width: min(380px, calc(100vw - 44px));+ display: flex; flex-direction: column;+ background: var(--panel); border: 1px solid var(--stroke); border-radius: 16px;+ backdrop-filter: blur(14px); box-shadow: 0 24px 70px rgba(0, 0, 0, 0.4);+ overflow: hidden;+ }+ .read-head {+ display: flex; align-items: center; justify-content: space-between;+ padding: 15px 18px; border-bottom: 1px solid var(--line);+ }+ .read-head .rh-title { display: flex; align-items: center; gap: 9px; font-size: 14px; font-weight: 600; }+ .read-head .mark {+ width: 24px; height: 24px; border-radius: 6px; flex: none;+ background: linear-gradient(135deg, var(--ibm-blue), var(--ibm-blue-2));+ display: grid; place-items: center; font-size: 11px; font-weight: 700; color: #fff;+ }+ .read-head .rh-model { font-size: 11px; color: var(--faint); }+ .read-body { padding: 18px; overflow-y: auto; scrollbar-width: thin; flex: 1; }++ .v-state { display: none; }+ .v-state.on { display: block; }++ .idle-glyph { font-size: 30px; margin-bottom: 12px; color: var(--ibm-light); text-shadow: 0 0 22px rgba(120,169,255,0.5); }+ .idle-title { font-size: 16px; font-weight: 600; margin-bottom: 6px; }+ .idle-sub { font-size: 13.5px; color: var(--muted); line-height: 1.55; }++ .skel { background: linear-gradient(100deg, rgba(255,255,255,0.04) 30%, rgba(120,169,255,0.10) 50%, rgba(255,255,255,0.04) 70%); background-size: 200% 100%; animation: shimmer 1.3s infinite; border-radius: 7px; }+ .skel.l { height: 13px; margin-bottom: 9px; }+ .skel.l.s { width: 55%; }+ .skel.l.m { width: 80%; }+ .skel.big { height: 26px; width: 60%; margin-bottom: 14px; }+ @keyframes shimmer { to { background-position: -200% 0; } }+ .looking { font-size: 13px; color: var(--ibm-light); margin-top: 14px; display: flex; align-items: center; gap: 8px; }+ .looking .ring { width: 13px; height: 13px; border-radius: 50%; border: 2px solid rgba(120,169,255,0.3); border-top-color: var(--ibm-light); animation: spin 0.9s linear infinite; }+ @keyframes spin { to { transform: rotate(360deg); } }++ .v-name { font-size: 23px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }+ .v-bio { font-size: 14px; color: var(--ibm-light); font-style: italic; margin-top: 6px; line-height: 1.45; }+ .v-field { margin-top: 18px; }+ .v-field-label { font-size: 10.5px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--faint); margin-bottom: 7px; }+ .v-field p { margin: 0; font-size: 13.5px; line-height: 1.6; color: #d7dceb; }+ .v-chips { display: flex; flex-wrap: wrap; gap: 6px; }+ .v-chip { font-size: 12px; color: var(--ink); background: rgba(120,169,255,0.12); border: 1px solid var(--stroke); border-radius: 7px; padding: 4px 10px; }+ .v-voice { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: #d7dceb; }+ .v-voice svg { width: 15px; height: 15px; color: var(--ibm-light); flex: none; }+ .v-raw { font-size: 13.5px; line-height: 1.6; color: #d7dceb; white-space: pre-wrap; }+ .v-actions { display: flex; gap: 8px; margin-top: 20px; flex-wrap: wrap; }++ .err-glyph { font-size: 28px; color: var(--ibm-light); margin-bottom: 10px; }+ .err-title { font-size: 16px; font-weight: 600; margin-bottom: 6px; }+ .err-sub { font-size: 13.5px; color: var(--muted); line-height: 1.55; }++ /* Dock (bottom) */+ .dock {+ position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 6;+ display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: center;+ width: min(880px, calc(100vw - 36px));+ background: var(--panel); border: 1px solid var(--stroke); border-radius: 16px;+ padding: 11px 13px; backdrop-filter: blur(14px); box-shadow: 0 24px 70px rgba(0,0,0,0.4);+ }+ .subjects { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: thin; flex: 1; min-width: 0; padding: 2px; }+ .subject {+ flex: none; width: 50px; height: 50px; border-radius: 11px; cursor: pointer;+ border: 2px solid transparent; background: #11151f center/cover no-repeat;+ display: grid; place-items: center; color: var(--faint); font-size: 18px; font-weight: 700;+ transition: border-color 0.15s, transform 0.12s; position: relative; overflow: hidden;+ }+ .subject:hover { transform: translateY(-2px); }+ .subject.sel { border-color: var(--ibm-blue-2); box-shadow: 0 0 0 3px rgba(15,98,254,0.2); }+ .subject .cap { position: absolute; bottom: 0; left: 0; right: 0; font-size: 8.5px; background: rgba(0,0,0,0.55); color: #cdd5e6; padding: 1px 3px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }+ .dock-sep { width: 1px; height: 34px; background: var(--line); flex: none; }+ .btn {+ font: inherit; font-size: 13px; font-weight: 600; border-radius: 10px; padding: 10px 16px;+ cursor: pointer; border: 0; display: inline-flex; align-items: center; gap: 7px;+ transition: filter 0.15s, background 0.15s, transform 0.1s; white-space: nowrap;+ }+ .btn-primary { background: var(--ibm-blue); color: #fff; }+ .btn-primary:hover { filter: brightness(1.12); }+ .btn-primary:active { transform: translateY(1px); }+ .btn-primary:disabled { opacity: 0.55; cursor: progress; }+ .btn-ghost { background: rgba(255,255,255,0.06); color: var(--ink); border: 1px solid var(--line); }+ .btn-ghost:hover { background: rgba(255,255,255,0.11); }+ .btn-sm { font-size: 12px; padding: 8px 13px; }+ .btn svg { width: 15px; height: 15px; }++ .attribution {+ position: fixed; left: 22px; bottom: 22px; z-index: 5;+ font-size: 11.5px; color: var(--faint); display: flex; align-items: center; gap: 7px;+ pointer-events: none;+ }+ .attribution .adot { width: 6px; height: 6px; border-radius: 50%; background: var(--ibm-blue); box-shadow: 0 0 8px var(--ibm-blue); }++ .stage-hint {+ position: fixed; left: 50%; top: 64px; transform: translateX(-50%); z-index: 4;+ font-size: 12px; color: var(--faint); pointer-events: none; transition: opacity 0.4s;+ }++ @media (max-width: 820px) {+ .read { top: auto; bottom: 86px; right: 12px; left: 12px; width: auto; max-height: 46vh; }+ #v-photo img { max-width: 80vw; max-height: 40vh; }+ .attribution { display: none; }+ .dock { bottom: 12px; }+ }+ </style>+ </head>+ <body>+ <div id="vision-stage" aria-hidden="true"></div>+ <div id="v-photo"><img id="v-photo-img" alt="Image being read by Granite Vision" /></div>++ <header class="topbar">+ <div class="brand">+ <span class="dot"></span>+ <span>Granite Vision</span>+ <small>three.ws × IBM watsonx</small>+ </div>+ <a class="back" href="/ibm">← IBM partnership</a>+ </header>++ <div class="stage-hint" id="v-stage-hint">Drag to orbit · the avatar Granite is about to read</div>++ <aside class="read" aria-live="polite">+ <div class="read-head">+ <div class="rh-title"><span class="mark">◉</span> Granite sees</div>+ <div class="rh-model" id="v-model">granite-vision-3-2</div>+ </div>+ <div class="read-body">+ <!-- Idle -->+ <div class="v-state on" id="v-idle">+ <div class="idle-glyph">◉</div>+ <div class="idle-title">Show Granite an avatar</div>+ <div class="idle-sub">+ IBM Granite Vision on watsonx.ai will look at the 3D avatar and invent its whole identity —+ how it looks, its vibe, a personality, a name, a bio, even a fitting voice. Pick a face below+ (or upload any image), then press <strong>Show Granite</strong>.+ </div>+ </div>++ <!-- Loading -->+ <div class="v-state" id="v-loading">+ <div class="skel big"></div>+ <div class="skel l m"></div>+ <div class="skel l"></div>+ <div class="skel l s"></div>+ <div class="looking"><span class="ring"></span> Granite Vision is looking…</div>+ </div>++ <!-- Result (structured) -->+ <div class="v-state" id="v-result">+ <div class="v-name" id="v-name"></div>+ <div class="v-bio" id="v-bio"></div>+ <div class="v-field" id="v-appearance-wrap">+ <div class="v-field-label">Appearance</div>+ <p id="v-appearance"></p>+ </div>+ <div class="v-field" id="v-persona-wrap">+ <div class="v-field-label">Persona</div>+ <p id="v-persona"></p>+ </div>+ <div class="v-field" id="v-vibe-wrap">+ <div class="v-field-label">Vibe</div>+ <div class="v-chips" id="v-vibe"></div>+ </div>+ <div class="v-field" id="v-tags-wrap">+ <div class="v-field-label">Tone tags</div>+ <div class="v-chips" id="v-tags"></div>+ </div>+ <div class="v-field" id="v-voice-wrap">+ <div class="v-field-label">Voice</div>+ <div class="v-voice">+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M12 2a3 3 0 0 1 3 3v6a3 3 0 0 1-6 0V5a3 3 0 0 1 3-3z"/><path d="M19 10v1a7 7 0 0 1-14 0v-1M12 19v3"/></svg>+ <span id="v-voice"></span>+ </div>+ </div>+ <div class="v-actions">+ <button class="btn btn-ghost btn-sm" id="v-copy" type="button">Copy identity</button>+ <a class="btn btn-primary btn-sm" id="v-create" href="/create">Create an agent →</a>+ </div>+ </div>++ <!-- Result (raw prose fallback) -->+ <div class="v-state" id="v-rawstate">+ <div class="v-field-label">Granite's read</div>+ <div class="v-raw" id="v-raw"></div>+ </div>++ <!-- Error -->+ <div class="v-state" id="v-error">+ <div class="err-glyph">◉</div>+ <div class="err-title" id="v-error-title">Granite couldn't look</div>+ <div class="err-sub" id="v-error-sub"></div>+ <div class="v-actions"><button class="btn btn-ghost btn-sm" id="v-error-retry" type="button">Try again</button></div>+ </div>+ </div>+ </aside>++ <div class="dock">+ <div class="subjects" id="v-subjects" aria-label="Pick an avatar to show Granite"></div>+ <div class="dock-sep"></div>+ <button class="btn btn-ghost btn-sm" id="v-upload" type="button">Upload</button>+ <input type="file" id="v-file" accept="image/*" hidden />+ <button class="btn btn-primary" id="v-show" type="button">Show Granite</button>+ </div>++ <div class="attribution"><span class="adot"></span> IBM Granite Vision 3.2 · watsonx.ai · real multimodal inference</div>++ <script type="module" src="/src/ibm-vision.js"></script>+ </body>+</html>diff --git a/scripts/dev-ibm-proof.mjs b/scripts/dev-ibm-proof.mjsnew file mode 100644index 000000000..e6e0ddf45--- /dev/null+++ b/scripts/dev-ibm-proof.mjs@@ -0,0 +1,69 @@+// Local dev server for the Granite Proof page (/ibm/proof).+//+// In normal `npm run dev`, /api/* proxies to production, so a brand-new endpoint+// like /api/ibm/attest isn't reachable until it ships. This tiny single-origin+// server serves the page, its module, AND the real /api/ibm/attest handler so+// you can exercise the whole feature locally against live GeckoTerminal data+// (and, with WATSONX_* + AVATAR_WALLET_SECRET set, real Granite + on-chain+// notarization). Every other asset (brand.js, avatar-embed, GLBs) redirects to+// production.+//+// node scripts/dev-ibm-proof.mjs # → http://localhost:3014/ibm/proof+// PORT=4000 node scripts/dev-ibm-proof.mjs+import { createServer } from 'node:http';+import { readFile } from 'node:fs/promises';+import { fileURLToPath } from 'node:url';+import { dirname, resolve } from 'node:path';++import attest from '../api/ibm/attest.js';++const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');+const PORT = Number(process.env.PORT || 3014);+const PROD = 'https://three.ws';++const FILES = {+ '/ibm/proof': ['pages/ibm/proof.html', 'text/html; charset=utf-8'],+ '/ibm/proof/': ['pages/ibm/proof.html', 'text/html; charset=utf-8'],+ '/': ['pages/ibm/proof.html', 'text/html; charset=utf-8'],+ '/src/ibm-proof.js': ['src/ibm-proof.js', 'text/javascript; charset=utf-8'],+};++const server = createServer(async (req, res) => {+ const path = (req.url || '/').split('?')[0];++ if (path.startsWith('/api/ibm/attest')) {+ try {+ await attest(req, res);+ } catch (e) {+ res.statusCode = 500;+ res.setHeader('content-type', 'application/json');+ res.end(JSON.stringify({ error: 'handler_threw', message: String(e?.message || e) }));+ }+ return;+ }++ const file = FILES[path];+ if (file) {+ try {+ const body = await readFile(resolve(ROOT, file[0]));+ res.statusCode = 200;+ res.setHeader('content-type', file[1]);+ res.end(body);+ } catch (e) {+ res.statusCode = 404;+ res.end('not found: ' + file[0]);+ }+ return;+ }++ // Everything else (brand.js, /avatar-embed.html, /avatars/*.glb, favicon)+ // comes from production so the page renders complete.+ res.statusCode = 302;+ res.setHeader('Location', PROD + req.url);+ res.end();+});++server.listen(PORT, () => {+ console.log(`Granite Proof dev server → http://localhost:${PORT}/ibm/proof`);+ console.log(` /api/ibm/attest served locally; other assets proxy to ${PROD}`);+});diff --git a/scripts/verify-granite-oracle.mjs b/scripts/verify-granite-oracle.mjsindex 593f4b16d..0dd6c0bb4 100644--- a/scripts/verify-granite-oracle.mjs+++ b/scripts/verify-granite-oracle.mjs@@ -9,11 +9,8 @@import { fetchOhlcv, trendingPools } from '../api/_lib/market/ohlcv.js';import { watsonxConfig, watsonxChatComplete } from '../api/_lib/watsonx.js';-import {- watsonxForecast,- watsonxGuardian,- forecastModelFor,-} from '../api/_lib/watsonx-forecast.js';+import { watsonxForecast, forecastModelFor } from '../api/_lib/watsonx-forecast.js';+import { assessRisk } from '../api/_lib/guardian.js';const log = (...a) => console.log(...a);const iso = (t) => new Date(t * 1000).toISOString();@@ -77,8 +74,8 @@ async function main() {log(` "${n.text}" [${n.model}]`);log('\n▶ Granite Guardian');- const g = await watsonxGuardian(cfg, { text: n.text, risk: 'harm' });- log(` risk=${g.risk} label=${g.label} → ${g.flagged ? 'FLAGGED' : 'PASS'} [${g.model}]`);+ const g = await assessRisk(cfg, { risk: 'harm', assistant: n.text });+ log(` risk=${g.risk} verdict=${g.verdict} → ${g.flagged ? 'FLAGGED' : 'PASS'}`);log('\n✅ Granite Oracle live path verified end-to-end.');}diff --git a/vercel.json b/vercel.jsonindex aa990e91f..dfb52a7f0 100644--- a/vercel.json+++ b/vercel.json@@ -97,6 +97,14 @@"src": "/ibm/oracle/","dest": "/ibm/oracle.html"},+ {+ "src": "/ibm/proof",+ "dest": "/ibm/proof.html"+ },+ {+ "src": "/ibm/proof/",+ "dest": "/ibm/proof.html"+ },{"src": "/ibm","dest": "/ibm/index.html"