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
demos: migrate 404 and login to @three-ws/agent-ui
oversteppingd390b52318a8
diff --git a/public/demos/404.html b/public/demos/404.htmlindex 1f27747bb..3829fdd59 100644--- a/public/demos/404.html+++ b/public/demos/404.html@@ -126,341 +126,45 @@<canvas id="avatar-canvas"></canvas><script type="module">- import * as THREE from 'three';- import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';- import { gsap } from 'https://cdn.jsdelivr.net/npm/[email protected]/+esm';+ import { createAgentUI } from '@three-ws/agent-ui';- const canvas = document.getElementById('avatar-canvas');- const bignum = document.getElementById('bignum');const zero = document.getElementById('zero');const homeBtn = document.getElementById('home-btn');const labBtn = document.getElementById('lab-btn');- // ── Renderer ───────────────────────────────────────────────────────- const renderer = new THREE.WebGLRenderer({ canvas, antialias: true, alpha: true });- renderer.setPixelRatio(Math.min(devicePixelRatio, 2));- renderer.outputColorSpace = THREE.SRGBColorSpace;- renderer.toneMapping = THREE.ACESFilmicToneMapping;- renderer.toneMappingExposure = 1.1;-- const scene = new THREE.Scene();-- // Orthographic — 1 world unit = PX_PER_UNIT screen pixels- const PX_PER_UNIT = 120;- const camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0.1, 100);- camera.position.z = 10;-- function updateFrustum() {- const hw = window.innerWidth / PX_PER_UNIT / 2;- const hh = window.innerHeight / PX_PER_UNIT / 2;- camera.left = -hw; camera.right = hw;- camera.top = hh; camera.bottom = -hh;- camera.updateProjectionMatrix();- }-- const _v3 = new THREE.Vector3();- function domToWorld(sx, sy) {- _v3.set((sx / window.innerWidth) * 2 - 1, -(sy / window.innerHeight) * 2 + 1, 0);- _v3.unproject(camera);- return { x: _v3.x, y: _v3.y };- }-- // ── Avatar runtime ────────────────────────────────────────────────- // Declared above resize() so the recalibrate path doesn't TDZ on init.- let avatar = null, mixer = null, rootBone = null, baseRootPos = null;-- function resize() {- renderer.setSize(window.innerWidth, window.innerHeight, false);- updateFrustum();- recalibrateLandSpot();- }- window.addEventListener('resize', resize);- resize();-- // Lights- scene.add(new THREE.AmbientLight(0xffffff, 0.6));- const key = new THREE.DirectionalLight(0xfff4dc, 2.0); key.position.set(3, 6, 5); scene.add(key);- const rim = new THREE.DirectionalLight(0x4060ff, 0.6); rim.position.set(-4, 3, -2); scene.add(rim);- const fill = new THREE.DirectionalLight(0xffeedd, 0.4); fill.position.set(0, 2, 7); scene.add(fill);- const actions = {};- let currentAction = null;- const FADE_S = 0.3;-- function setAnimation(name, { loop = true, hold = false } = {}) {- const next = actions[name];- if (!next || next === currentAction) return;- next.reset();- next.setLoop(loop ? THREE.LoopRepeat : THREE.LoopOnce, loop ? Infinity : 1);- next.clampWhenFinished = hold;- if (currentAction) next.crossFadeFrom(currentAction, FADE_S, false).play();- else next.fadeIn(FADE_S).play();- currentAction = next;- }-- // ── Phase state ───────────────────────────────────────────────────- // fallingIn — drop from above the viewport onto the "0"- // confused — idle/look-around on the digit- // runningOff — walk-cycle slide toward whichever edge the user clicked- let phase = 'loading';- let landed = false;- let fallT = 0;- const FALL_S = 1.4;- let fallStartW = { x: 0, y: 0 };- let fallTargetW = { x: 0, y: 0 };- const SIT_OFFSET_PX = 140; // butt-sit offset for cz.glb (same as 3d-home)- const LANDING_OFFSET_PX = 90; // standing slightly above the "0" baseline-- function getZeroLandWorld() {- const r = zero.getBoundingClientRect();- // Center horizontally on the "0", land just above its visual top- return domToWorld(r.left + r.width / 2, r.top + LANDING_OFFSET_PX);- }-- function getFallStartWorld() {- const r = zero.getBoundingClientRect();- // Start 1.5× viewport heights above the target — guarantees the avatar- // is off-screen no matter the window size- return domToWorld(r.left + r.width / 2, -window.innerHeight * 0.6);- }-- function recalibrateLandSpot() {- if (!avatar || phase !== 'confused') return;- const t = getZeroLandWorld();- gsap.to(avatar.position, { x: t.x, y: t.y, duration: 0.35, overwrite: true });- }-- // Re-anchor when text reflows (font load, viewport changes)- const ro = new ResizeObserver(() => recalibrateLandSpot());- ro.observe(zero);-- function smoothstep(t) { return t * t * (3 - 2 * t); }-- // ── Falling sequence ─────────────────────────────────────────────- function startFall() {- phase = 'fallingIn';- fallStartW = getFallStartWorld();- fallTargetW = getZeroLandWorld();- avatar.position.set(fallStartW.x, fallStartW.y, 0);- avatar.rotation.set(0, 0, 0);- fallT = 0; landed = false;- setAnimation('falling', { loop: true });- }-- function fireLandingDust() {- // Splash of debris on impact — same ballistic feel as 3d-home but- // neutral grey so it reads as "kicked-up dust" instead of paint.- const r = zero.getBoundingClientRect();- const ox = r.left + r.width / 2;- const oy = r.top + r.height * 0.78;- const GRAVITY = 1400, COUNT = 16;- const drops = [];- for (let i = 0; i < COUNT; i++) {- const size = 4 + Math.random() * 6;- const el = document.createElement('div');- el.style.cssText =- `position:fixed;left:${ox - size/2}px;top:${oy - size/2}px;` +- `width:${size}px;height:${size}px;border-radius:50%;` +- `background:radial-gradient(circle at 35% 30%,#cfd2dd,#7a7d8e 60%,#3c3e4c);` +- `box-shadow:0 0 5px rgba(255,255,255,0.18);` +- `pointer-events:none;z-index:30;will-change:transform,opacity;`;- document.body.appendChild(el);- const angle = -Math.PI / 2 + (Math.random() - 0.5) * Math.PI * 1.3;- const speed = 180 + Math.random() * 280;- drops.push({- el, x: 0, y: 0,- vx: Math.cos(angle) * speed,- vy: Math.sin(angle) * speed,- life: 0,- max: 0.7 + Math.random() * 0.4,- });- }- let last = performance.now();- (function step(now) {- const dt = Math.min((now - last) / 1000, 0.04); last = now;- let alive = false;- for (const d of drops) {- if (!d.el) continue;- d.life += dt;- d.vy += GRAVITY * dt;- d.x += d.vx * dt; d.y += d.vy * dt;- const t = d.life / d.max;- if (t >= 1) { d.el.remove(); d.el = null; continue; }- d.el.style.opacity = String(1 - t * t);- d.el.style.transform = `translate(${d.x.toFixed(1)}px,${d.y.toFixed(1)}px)`;- alive = true;- }- if (alive) requestAnimationFrame(step);- })(last);- }-- function fireImpactPulse() {- // Brief CSS scale-pulse on the "0" — sells the weight of the landing- gsap.killTweensOf(zero);- gsap.fromTo(zero,- { y: 0 },- { y: 4, duration: 0.08, ease: 'power3.out',- onComplete: () => gsap.to(zero, { y: 0, duration: 0.5, ease: 'elastic.out(1.2, 0.4)' })- });- }-- function startConfused() {- phase = 'confused';- landed = true;- const t = getZeroLandWorld();- avatar.position.set(t.x, t.y, 0);- setAnimation('idle', { loop: true });- // Gentle head-turn loop — feels like "looking around lost"- lookAroundLoop();- }-- let lookRAF = null, lookT0 = 0;- function lookAroundLoop() {- cancelAnimationFrame(lookRAF);- lookT0 = performance.now();- (function tick(now) {- if (phase !== 'confused') return;- const t = (now - lookT0) / 1000;- // Slow sinusoidal yaw — ±20° over ~5s- avatar.rotation.y = Math.sin(t * 1.25) * 0.35;- lookRAF = requestAnimationFrame(tick);- })(performance.now());- }-- function stopLooking() {- cancelAnimationFrame(lookRAF);- lookRAF = null;- }-- function startRunOff(direction = 'right') {- if (phase === 'runningOff') return;- phase = 'runningOff';- stopLooking();- setAnimation('walk', { loop: true });- const dir = direction === 'left' ? -1 : 1;- gsap.to(avatar.rotation, { y: dir * Math.PI * 0.5, duration: 0.3, overwrite: true });- // Slide to off-screen world-X. PX_PER_UNIT keeps the math obvious.- const targetWorldX = (window.innerWidth / PX_PER_UNIT) * 0.7 * dir;- const cur = avatar.position;- const distancePx = Math.abs(targetWorldX - cur.x) * PX_PER_UNIT;- const ms = Math.max(900, distancePx * 2.2);- gsap.to(cur, { x: targetWorldX, duration: ms / 1000, ease: 'power1.in' });- }-- // ── Intercept the "Take her home" click ──────────────────────────- // Don't navigate immediately — let the agent run off-screen first,- // THEN go to the destination. Feels intentional, not glitchy.- function interceptNav(btn, dir) {- btn.addEventListener('click', e => {- if (phase === 'runningOff') return; // already mid-exit; let it land- e.preventDefault();- const href = btn.getAttribute('href');- startRunOff(dir);- setTimeout(() => { window.location.href = href; }, 1100);- });- }- interceptNav(homeBtn, 'right');- interceptNav(labBtn, 'left');-- // ── Proximity shadow on the "0" (matches 3d-home pattern) ────────- const _proj = new THREE.Vector3();- function avatarScreenY() {- _proj.set(avatar.position.x, avatar.position.y, 0).project(camera);- return (1 - _proj.y) * 0.5 * window.innerHeight;- }- function updateProximityShadow() {- if (!avatar) return;- const r = zero.getBoundingClientRect();- const ay = avatarScreenY();- const dy = Math.max(0, r.top - ay);- const prox = 1 - Math.min(dy / 280, 1);- if (prox <= 0.01) {- bignum.style.setProperty('--agent-shadow', 'none');- return;- }- const blur = (12 * (1 - prox) + 3).toFixed(2);- const offsetY = (3 + 8 * prox).toFixed(2);- const alpha = (0.6 * prox).toFixed(3);- bignum.style.setProperty('--agent-shadow', `0 ${offsetY}px ${blur}px rgba(0,0,0,${alpha})`);- }-- // ── Subtle camera parallax — sells "3D" without breaking ortho math- // We pan the camera slightly with the mouse instead of changing FOV,- // which keeps domToWorld() correct since it always reads from `camera`.- let mouseNx = 0, mouseNy = 0;- window.addEventListener('mousemove', e => {- mouseNx = (e.clientX / window.innerWidth) * 2 - 1;- mouseNy = (e.clientY / window.innerHeight) * 2 - 1;+ const agent = await createAgentUI({+ canvas: document.getElementById('avatar-canvas'),+ clips: ['idle', 'walk', 'falling'],});- // ── Loader ────────────────────────────────────────────────────────- const CLIPS = ['idle', 'walk', 'falling'];-- new GLTFLoader().load('/avatars/cz.glb', gltf => {- avatar = gltf.scene;- avatar.traverse(n => {- if (!rootBone && /^(Hips|Root|mixamorig:?Hips)$/i.test(n.name)) rootBone = n;- });- avatar.rotation.y = 0;- scene.add(avatar);-- mixer = new THREE.AnimationMixer(avatar);-- Promise.all(CLIPS.map(name =>- fetch(`/animations/clips/${name}.json`).then(r => r.json())- )).then(jsons => {- CLIPS.forEach((name, i) => {- actions[name] = mixer.clipAction(THREE.AnimationClip.parse(jsons[i]));- });-- if (rootBone) baseRootPos = rootBone.position.clone();- // Lock root motion so the walk-cycle's translation doesn't fight our- // JS position lerp during runningOff.- const _r = renderer.render.bind(renderer);- renderer.render = (sc, cam) => {- try { if (rootBone && baseRootPos) rootBone.position.copy(baseRootPos); } catch (_) {}- _r(sc, cam);- };-- // Kick off the fall on next frame so layout is settled- requestAnimationFrame(startFall);- });+ // Proximity shadow tracks the avatar's screen Y vs. the "0" baseline.+ // The CSS picks it up via `text-shadow: var(--agent-shadow, none)`.+ agent.fx.proximityShadow(document.getElementById('bignum'));++ // Drop from above the viewport onto the "0", fire dust + pulse on land.+ await agent.fallOnto(zero, {+ duration: 1.4,+ landingOffsetPx: 90,+ tumble: 0.25,+ onLand: () => {+ agent.fx.dust(zero);+ agent.fx.impactPulse(zero);+ },});- // ── Render loop ───────────────────────────────────────────────────- const clock = new THREE.Clock();- (function tick() {- requestAnimationFrame(tick);- try {- const dt = Math.min(clock.getDelta(), 0.05);- mixer?.update(dt);-- if (phase === 'fallingIn' && avatar) {- fallT += dt;- const p = Math.min(fallT / FALL_S, 1);- // Ease-in (gravity-style) for vertical, linear-ish for horizontal- const ey = p * p;- avatar.position.x = fallStartW.x + (fallTargetW.x - fallStartW.x) * smoothstep(p);- avatar.position.y = fallStartW.y + (fallTargetW.y - fallStartW.y) * ey;- // Slight tumble during the fall, settles to 0 on landing- avatar.rotation.y = (1 - p) * 0.25 * Math.sin(p * 8);-- if (p >= 1 && !landed) {- fireLandingDust();- fireImpactPulse();- startConfused();- }- }-- // Camera parallax — clamped tiny so domToWorld stays within tolerance- const targetCamX = mouseNx * 0.12;- const targetCamY = -mouseNy * 0.08;- camera.position.x += (targetCamX - camera.position.x) * 0.04;- camera.position.y += (targetCamY - camera.position.y) * 0.04;-- updateProximityShadow();- renderer.render(scene, camera);- } catch (_) {}+ // Confused look-around loop: gentle yaw oscillation while idle on the digit.+ agent.play('idle', { loop: true });+ const t0 = performance.now();+ (function lookAround() {+ if (agent._runningOff) return;+ const t = (performance.now() - t0) / 1000;+ agent.avatar.rotation.y = Math.sin(t * 1.25) * 0.35;+ requestAnimationFrame(lookAround);})();++ // Each link runs the avatar off-screen before navigating.+ agent.interceptNavigation(homeBtn, { direction: 'right', delay: 1100 });+ agent.interceptNavigation(labBtn, { direction: 'left', delay: 1100 });</script></body></html>diff --git a/public/demos/login.html b/public/demos/login.htmlindex b906bd224..cf3ba1974 100644--- a/public/demos/login.html+++ b/public/demos/login.html@@ -130,21 +130,6 @@.foot { margin: 22px 0 0; text-align: center; color: #54576f; font-size: 12.5px; }.foot a { color: #8a8eaa; }-- /* Hidden mirror — used to measure caret X in a regular <input>.- Must match the input's typography & padding exactly. visibility:hidden- so it occupies no painted pixels but is still measurable. */- .caret-mirror {- position: absolute;- visibility: hidden;- white-space: pre;- font: 500 15px/1.2 'Inter', inherit;- padding: 0;- margin: 0;- border: 0;- pointer-events: none;- top: -9999px; left: -9999px;- }</style></head><body>@@ -195,7 +180,6 @@class="btn"id="submit-btn"type="submit"- data-agent-action="validate-form">Sign in</button><p class="foot">No account? <a href="/create">Build an agent →</a></p>@@ -205,331 +189,62 @@<canvas id="avatar-canvas"></canvas><script type="module">- import * as THREE from 'three';- import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';- import { gsap } from 'https://cdn.jsdelivr.net/npm/[email protected]/+esm';-- const canvas = document.getElementById('avatar-canvas');- const form = document.getElementById('login-form');-- // ── Renderer / scene (same orthographic pattern as 3d-home) ───────- const renderer = new THREE.WebGLRenderer({ canvas, antialias: true, alpha: true });- renderer.setPixelRatio(Math.min(devicePixelRatio, 2));- renderer.outputColorSpace = THREE.SRGBColorSpace;- renderer.toneMapping = THREE.ACESFilmicToneMapping;- renderer.toneMappingExposure = 1.1;-- const scene = new THREE.Scene();- const PX_PER_UNIT = 120;- const camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0.1, 100);- camera.position.z = 10;-- function updateFrustum() {- const hw = window.innerWidth / PX_PER_UNIT / 2;- const hh = window.innerHeight / PX_PER_UNIT / 2;- camera.left = -hw; camera.right = hw;- camera.top = hh; camera.bottom = -hh;- camera.updateProjectionMatrix();- }-- const _v3 = new THREE.Vector3();- function domToWorld(screenX, screenY) {- _v3.set(- (screenX / window.innerWidth) * 2 - 1,- -(screenY / window.innerHeight) * 2 + 1,- 0- );- _v3.unproject(camera);- return { x: _v3.x, y: _v3.y };- }- function resize() {- renderer.setSize(window.innerWidth, window.innerHeight, false);- updateFrustum();- }- window.addEventListener('resize', resize);- resize();-- // Lights- scene.add(new THREE.AmbientLight(0xffffff, 0.6));- const key = new THREE.DirectionalLight(0xfff4dc, 2.0); key.position.set(3, 6, 5); scene.add(key);- const rim = new THREE.DirectionalLight(0x4060ff, 0.6); rim.position.set(-4, 3, -2); scene.add(rim);- const fill = new THREE.DirectionalLight(0xffeedd, 0.4); fill.position.set(0, 2, 7); scene.add(fill);-- // ── Avatar runtime ────────────────────────────────────────────────- let avatar = null, mixer = null, rootBone = null, baseRootPos = null;- const clips = {}; // name → AnimationClip- const actions = {}; // name → AnimationAction- let currentAction = null;- const FADE_S = 0.3; // crossfade duration — matches 3d-home-- function setAnimation(name, { loop = true, hold = false } = {}) {- const next = actions[name];- if (!next || next === currentAction) return;- next.reset();- next.setLoop(loop ? THREE.LoopRepeat : THREE.LoopOnce, loop ? Infinity : 1);- next.clampWhenFinished = hold;- if (currentAction) {- next.crossFadeFrom(currentAction, FADE_S, false).play();- } else {- next.fadeIn(FADE_S).play();- }- currentAction = next;- }-- // Smooth move avatar to a world position (lerp w/ smoothstep)- let slideRAF = null;- function moveAvatarTo(target, ms = 520) {- if (!avatar) return Promise.resolve();- if (slideRAF) cancelAnimationFrame(slideRAF);- const fromX = avatar.position.x, fromY = avatar.position.y;- const t0 = performance.now();- return new Promise(resolve => {- (function step(now) {- const sp = Math.min((now - t0) / ms, 1);- const e = sp * sp * (3 - 2 * sp);- avatar.position.x = fromX + (target.x - fromX) * e;- avatar.position.y = fromY + (target.y - fromY) * e;- if (sp < 1) slideRAF = requestAnimationFrame(step);- else { slideRAF = null; resolve(); }- })(performance.now());- });- }-- // Smooth lookAt yaw (small head/body turn toward a screen X)- function lookAtScreenX(targetScreenX) {- if (!avatar) return;- const projected = new THREE.Vector3(avatar.position.x, avatar.position.y, 0).project(camera);- const screenAvatarX = (projected.x + 1) * 0.5 * window.innerWidth;- const dxPx = targetScreenX - screenAvatarX;- // Map ±200px of caret travel → ±~25° yaw- const yaw = Math.max(-0.45, Math.min(0.45, dxPx / 450));- gsap.to(avatar.rotation, { y: yaw, duration: 0.18, overwrite: true });- }-- // ── Caret tracking via hidden mirror div ──────────────────────────- // Given an <input>, place an off-screen <div> with identical typography- // + padding, copy the prefix substring, and measure its width to find- // the caret X within the input's content box.- const mirror = document.createElement('div');- mirror.className = 'caret-mirror';- document.body.appendChild(mirror);-- function copyInputStyle(input) {- const cs = getComputedStyle(input);- mirror.style.font = cs.font;- mirror.style.letterSpacing = cs.letterSpacing;- mirror.style.textTransform = cs.textTransform;- mirror.style.padding = '0';- }-- function caretScreenX(input) {- copyInputStyle(input);- const rect = input.getBoundingClientRect();- const cs = getComputedStyle(input);- const padL = parseFloat(cs.paddingLeft) || 0;- const padR = parseFloat(cs.paddingRight) || 0;- const innerW = rect.width - padL - padR;-- // Use the real value for email; password inputs mask to a bullet so- // the mirrored width reflects the rendered glyph stream, not the secret.- const raw = input.value;- const display = input.type === 'password' ? '•'.repeat(raw.length) : raw;- const caretIdx = input.selectionStart ?? display.length;- mirror.textContent = display.slice(0, caretIdx) || ' ';- const textW = mirror.getBoundingClientRect().width;-- // Clamp to content box; ignores horizontal scroll on overflow but- // good-enough for the input lengths typed in a login form.- const offset = Math.min(textW, innerW);- return rect.left + padL + offset;- }-- // ── Declarative SDK: scan data-agent-* attributes and wire behaviors ─- // We look for `data-agent-action` on form fields and the submit button.- // Each action attaches the appropriate listeners + animation triggers.- const targets = form.querySelectorAll('[data-agent-action]');-- let activeInput = null; // input currently focused- let trackRAF = null; // rAF id for caret tracking loop-- function worldAboveInput(input) {- const rect = input.getBoundingClientRect();- // Stand on the top edge, ~one avatar-width inside from the left- return domToWorld(rect.left + Math.min(40, rect.height * 1.2), rect.top);- }-- async function walkTo(input) {- setAnimation('walk', { loop: true });- await moveAvatarTo(worldAboveInput(input), 540);- }-- function startTypingTracking(input) {- activeInput = input;- setAnimation('lookdown', { loop: true });- // Track caret on every animation frame while focused — covers keyboard- // typing AND mouse-click cursor moves without listening for each event.- cancelAnimationFrame(trackRAF);- let lastCaretX = -1;- (function loop() {- if (activeInput !== input) return;- const cx = caretScreenX(input);- if (cx !== lastCaretX) {- lastCaretX = cx;- lookAtScreenX(cx);- }- trackRAF = requestAnimationFrame(loop);- })();- }-- function stopTypingTracking() {- cancelAnimationFrame(trackRAF);- trackRAF = null;- activeInput = null;- gsap.to(avatar.rotation, { y: 0, duration: 0.25, overwrite: true });- }-- function enterPrivacyMode() {- // Play subclipped covereyes (frames 0–48) once and hold the final- // hands-on-face pose while the password field stays focused.- setAnimation('covereyes', { loop: false, hold: true });- gsap.to(avatar.rotation, { y: 0, duration: 0.25, overwrite: true });- }+ import { createAgentUI } from '@three-ws/agent-ui';++ const form = document.getElementById('login-form');++ const agent = await createAgentUI({+ canvas: document.getElementById('avatar-canvas'),+ clips: ['idle', 'walk', 'lookdown', 'covereyes', 'reaction', 'silly', 'defeated', 'angry', 'facepalm'],+ subclips: {+ // covereyes is 219 frames; only the first 48 settle the hands on+ // the face — hold that pose while the password field is focused.+ covereyes: { start: 0, end: 48, fps: 30 },+ },+ });- function exitPrivacyMode() {- setAnimation('idle', { loop: true });- gsap.to(avatar.rotation, { y: 0, duration: 0.25, overwrite: true });- }+ // Park the avatar centered above the form card, feet on the ledge.+ agent.standOn(form, { anchor: 'top-center' });- const FAIL_CLIPS = ['reaction', 'defeated', 'angry', 'facepalm'];- let lastFailPick = null;+ // Wire the declarative attributes on the form (track-typing, privacy-mode).+ agent.scan(form);+ // Form-validation reactions live here because credential logic belongs to+ // the page, not the SDK. The SDK just exposes pickFrom() and play().+ const pickFail = agent.pickFrom(['reaction', 'defeated', 'angry', 'facepalm']);function disapprove() {- let pick;- do {- pick = FAIL_CLIPS[Math.floor(Math.random() * FAIL_CLIPS.length)];- } while (pick === lastFailPick && FAIL_CLIPS.length > 1);- lastFailPick = pick;- setAnimation(pick, { loop: false, hold: false });- const dur = (clips[pick]?.duration || 1.4) * 1000;+ const pick = pickFail();+ agent.play(pick, { loop: false });+ const dur = agent.clip(pick) * 1000;setTimeout(() => {- if (currentAction === actions[pick]) setAnimation('idle', { loop: true });+ if (agent.currentClip === pick) agent.play('idle', { loop: true });}, dur - 150);}- // Wire each declared target- targets.forEach(el => {- const action = el.dataset.agentAction;-- if (action === 'track-typing') {- el.addEventListener('focus', async () => {- await walkTo(el);- startTypingTracking(el);- });- el.addEventListener('blur', stopTypingTracking);- // Recompute caret on input — selectionStart updates synchronously- el.addEventListener('input', () => {- if (activeInput === el) lookAtScreenX(caretScreenX(el));- });- el.addEventListener('keyup', () => {- if (activeInput === el) lookAtScreenX(caretScreenX(el));- });- el.addEventListener('click', () => {- if (activeInput === el) lookAtScreenX(caretScreenX(el));- });+ form.addEventListener('submit', (ev) => {+ ev.preventDefault();+ const email = form.elements.email;+ const password = form.elements.password;+ email.classList.remove('error');+ password.classList.remove('error');++ const empty = [];+ if (!email.value.trim()) empty.push(email);+ if (!password.value) empty.push(password);+ if (empty.length) {+ empty.forEach((i) => i.classList.add('error'));+ disapprove();+ return;}- if (action === 'privacy-mode') {- el.addEventListener('focus', async () => {- stopTypingTracking();- await walkTo(el);- enterPrivacyMode();- });- el.addEventListener('blur', exitPrivacyMode);- }-- if (action === 'validate-form') {- // Demo credential: any email + password === "admin" succeeds.- form.addEventListener('submit', ev => {- ev.preventDefault();- const email = form.elements.email;- const password = form.elements.password;- email.classList.remove('error');- password.classList.remove('error');-- const emptyFields = [];- if (!email.value.trim()) emptyFields.push(email);- if (!password.value) emptyFields.push(password);- if (emptyFields.length) {- emptyFields.forEach(i => i.classList.add('error'));- disapprove();- return;- }-- if (password.value === 'admin') {- setAnimation('silly', { loop: true });- setTimeout(() => { window.location.href = '/marketplace'; }, 2000);- } else {- password.classList.add('error');- disapprove();- }- });+ if (password.value === 'admin') {+ agent.play('silly', { loop: true });+ setTimeout(() => { window.location.href = '/marketplace'; }, 2000);+ } else {+ password.classList.add('error');+ disapprove();}});-- // ── Load avatar + animations ──────────────────────────────────────- const CLIPS = ['idle', 'walk', 'lookdown', 'covereyes', 'reaction', 'silly', 'defeated', 'angry', 'facepalm'];-- new GLTFLoader().load('/avatars/cz.glb', gltf => {- avatar = gltf.scene;- avatar.traverse(n => {- if (!rootBone && /^(Hips|Root|mixamorig:?Hips)$/i.test(n.name)) rootBone = n;- });- avatar.rotation.y = 0;- scene.add(avatar);-- mixer = new THREE.AnimationMixer(avatar);-- Promise.all(CLIPS.map(name =>- fetch(`/animations/clips/${name}.json`).then(r => r.json())- )).then(jsons => {- CLIPS.forEach((name, i) => {- let clip = THREE.AnimationClip.parse(jsons[i]);- // covereyes runs 219 frames @30fps; only play frames 0–48- // (hands settle on face) then hold that pose.- if (name === 'covereyes') {- clip = THREE.AnimationUtils.subclip(clip, name, 0, 48, 30);- }- clips[name] = clip;- actions[name] = mixer.clipAction(clip);- });-- if (rootBone) baseRootPos = rootBone.position.clone();- // Lock root motion so animation drift doesn't accumulate translation- const _r = renderer.render.bind(renderer);- renderer.render = (sc, cam) => {- try { if (rootBone && baseRootPos) rootBone.position.copy(baseRootPos); } catch (_) {}- _r(sc, cam);- };-- // Park avatar centered above the form card, feet on the ledge.- const cardRect = form.getBoundingClientRect();- const restPos = domToWorld(cardRect.left + cardRect.width / 2, cardRect.top);- avatar.position.set(restPos.x, restPos.y, 0);-- setAnimation('idle', { loop: true });- });- });-- // ── Render loop ───────────────────────────────────────────────────- const clock = new THREE.Clock();- (function tick() {- requestAnimationFrame(tick);- try {- const dt = Math.min(clock.getDelta(), 0.05);- mixer?.update(dt);- renderer.render(scene, camera);- } catch (_) {}- })();</script></body></html>diff --git a/scripts/verify-agent-ui.mjs b/scripts/verify-agent-ui.mjsnew file mode 100644index 000000000..e528cd322--- /dev/null+++ b/scripts/verify-agent-ui.mjs@@ -0,0 +1,56 @@+import { chromium } from 'playwright';++const browser = await chromium.launch();+const ctx = await browser.newContext({ viewport: { width: 1280, height: 800 } });+let failed = false;++async function checkPage(url, interact) {+ const page = await ctx.newPage();+ const errors = [];+ const failedReqs = [];+ page.on('console', (msg) => { if (msg.type() === 'error') errors.push(msg.text()); });+ page.on('pageerror', (err) => errors.push('[pageerror] ' + err.message));+ page.on('requestfailed', (req) => {+ const e = req.failure()?.errorText || 'unknown';+ if (!/aborted|cancelled/i.test(e)) failedReqs.push(`${req.url()} :: ${e}`);+ });++ console.log(`\n=== ${url} ===`);+ await page.goto(url, { waitUntil: 'networkidle', timeout: 30000 });+ await page.waitForTimeout(2000);+ if (interact) await interact(page);+ await page.waitForTimeout(1000);++ if (errors.length) {+ console.log('errors:');+ for (const e of errors) console.log(' -', e);+ failed = true;+ }+ if (failedReqs.length) {+ console.log('failed requests:');+ for (const r of failedReqs) console.log(' -', r);+ failed = true;+ }+ const slug = url.split('/').pop().replace('.html', '');+ await page.screenshot({ path: `/tmp/agent-ui-${slug}.png` });+ await page.close();+}++await checkPage('http://localhost:3000/demos/404.html');++await checkPage('http://localhost:3000/demos/login.html', async (page) => {+ await page.click('#email');+ await page.waitForTimeout(900);+ await page.fill('#email', '[email protected]');+ await page.waitForTimeout(700);+ await page.click('#password');+ await page.waitForTimeout(1000);+ await page.fill('#password', 'wrong');+ await page.click('#submit-btn');+ await page.waitForTimeout(1400);+ await page.screenshot({ path: '/tmp/agent-ui-login-after-submit.png' });+});++await browser.close();+console.log(failed ? '\nFAIL' : '\nOK');+process.exit(failed ? 1 : 0);