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(chat): react to user sentiment with agent emotion + animation
nirholas678416656c78
diff --git a/chat/src/App.svelte b/chat/src/App.svelteindex 4d4bc6283..c2895bef9 100644--- a/chat/src/App.svelte+++ b/chat/src/App.svelte@@ -990,8 +990,9 @@saveMessage(sysMsg);}const nonSystem = convo.messages.filter(m => m.role !== 'system');- if (agent.greeting && nonSystem.length === 0) {- const greetMsg = { id: uuidv4(), role: 'assistant', content: agent.greeting, generated: true };+ if (nonSystem.length === 0) {+ const greeting = agent.greeting || `Hi, I'm ${agent.name || 'here'}. How can I help you today?`;+ const greetMsg = { id: uuidv4(), role: 'assistant', content: greeting, generated: true, agent };convo.messages = [...convo.messages, greetMsg];saveMessage(greetMsg);}diff --git a/chat/src/Message.svelte b/chat/src/Message.svelteindex 5b17857fd..9c83b6453 100644--- a/chat/src/Message.svelte+++ b/chat/src/Message.svelte@@ -25,12 +25,53 @@import MessageContent from './MessageContent.svelte';import { formatModelName, hasCompanyLogo } from './providers.js';import { config, talkingHeadAvatarUrl, localAgentId, brandConfig } from './stores.js';+ import { detectEmotion } from './sentiment.js';import Toolcall from './Toolcall.svelte';import ToolcallButton from './ToolcallButton.svelte';const dispatch = createEventDispatcher();let agentEl;+ let lastReactedToUserId = null;++ function faceCamera(el) {+ const apply = () => {+ const content = el?._viewer?.content;+ if (!content) return;+ content.rotation.y = Math.PI;+ el._viewer.invalidate?.();+ };+ if (el?._viewer?.content) apply();+ else el?.addEventListener('agent:ready', apply, { once: true });+ }++ function reactToUserSentiment(el, userMessage) {+ if (!el || !userMessage?.id || !userMessage.content) return;+ if (lastReactedToUserId === userMessage.id) return;+ const sentiment = detectEmotion(userMessage.content);+ if (!sentiment) {+ lastReactedToUserId = userMessage.id;+ return;+ }+ const fire = () => {+ try { el.expressEmotion?.(sentiment.emotion, sentiment.weight); } catch {}+ try { el._scene?.playAnimationByHint?.(sentiment.emotion); } catch {}+ };+ if (el._mounted) fire();+ else el.addEventListener('agent:ready', fire, { once: true });+ lastReactedToUserId = userMessage.id;+ }++ $: if (agentEl) faceCamera(agentEl);+ $: if (agentEl && convo?.messages?.length) {+ const last = convo.messages[i];+ const isLatest = last?.role === 'assistant'+ && i === convo.messages.findLastIndex((m) => m.role === 'assistant');+ if (isLatest) {+ const prior = [...convo.messages.slice(0, i)].reverse().find((m) => m.role === 'user');+ if (prior) reactToUserSentiment(agentEl, prior);+ }+ }function msgTransition(node, { style }) {if (style === 'snap') return { duration: 0 };@@ -200,8 +241,9 @@{/if}{/if}<button- disabled={message.role === 'system'}+ disabled={message.role === 'system' || (message.role === 'assistant' && hasLogo && isLatestAssistant)}on:click={() => {+ if (message.role === 'assistant' && hasLogo && isLatestAssistant) return;if (message.role === 'user') {message.role = 'assistant';} else {diff --git a/chat/src/sentiment.js b/chat/src/sentiment.jsnew file mode 100644index 000000000..b9af226b6--- /dev/null+++ b/chat/src/sentiment.js@@ -0,0 +1,63 @@+// Map a user prompt to one of the agent-3d emotion triggers.+// Emotion vocabulary: 'celebration' | 'concern' | 'curiosity' | 'empathy' | 'patience'+//+// Returns { emotion, weight } or null if nothing reads strongly enough.+// Keyword lists are deliberately small and high-precision — false positives+// look worse than no reaction.++const PATTERNS = {+ empathy: [+ /\bi(?:'m| am)?\s+(?:so\s+)?(?:sad|tired|exhausted|burned\s*out|overwhelmed|struggling|lonely|hurt|down)\b/i,+ /\b(?:i feel|feeling)\s+(?:bad|terrible|awful|low|blue|hopeless)\b/i,+ /\b(?:lost\s+my|passed\s+away|breakup|broke\s+up|grief|miss\s+(?:him|her|them))\b/i,+ ],+ concern: [+ /\b(?:error|exception|traceback|stack\s*trace|crash(?:ed|ing)?|fail(?:ed|ing|ure)?|broken|bug|stuck|blocked|can'?t|cannot|won'?t\s+work|doesn'?t\s+work|not\s+working)\b/i,+ /\b(?:urgent|asap|emergency|critical|on\s*fire|production\s+down|prod\s+down|outage|p0|p1)\b/i,+ /\b(?:hate|frustrated|angry|annoyed|fed\s+up|worried|scared|afraid)\b/i,+ ],+ celebration: [+ /\b(?:thanks?|thank\s+you|thx|ty)\b/i,+ /\b(?:awesome|amazing|incredible|fantastic|brilliant|wonderful|excellent|perfect|love\s+(?:it|this)|great\s+job|nice\s+work|woohoo|hooray|lfg|let'?s\s+go)\b/i,+ /\b(?:congrats|congratulations|shipped|launched|done|finished|works?!|it\s+works?)\b/i,+ /(?:!{2,}|🎉|🥳|🚀|❤️|🙌)/,+ ],+ patience: [+ /\b(?:please|kindly|when\s+you\s+(?:can|get\s+a\s+chance)|no\s+rush|take\s+your\s+time|whenever)\b/i,+ ],+ curiosity: [+ /\?/,+ /\b(?:how|why|what|when|where|who|which|explain|show\s+me|teach\s+me|tell\s+me|tell\s+about|curious|wonder(?:ing)?)\b/i,+ ],+};++const PRIORITY = ['empathy', 'concern', 'celebration', 'patience', 'curiosity'];++export function detectEmotion(text) {+ if (!text || typeof text !== 'string') return null;+ const trimmed = text.trim();+ if (!trimmed) return null;++ const scores = {};+ for (const [emotion, patterns] of Object.entries(PATTERNS)) {+ let hits = 0;+ for (const re of patterns) if (re.test(trimmed)) hits++;+ if (hits > 0) scores[emotion] = hits;+ }++ if (Object.keys(scores).length === 0) return null;++ let pick = null;+ let pickScore = 0;+ for (const emotion of PRIORITY) {+ const s = scores[emotion] || 0;+ if (s > pickScore) {+ pick = emotion;+ pickScore = s;+ }+ }+ if (!pick) return null;++ const weight = Math.min(0.95, 0.55 + pickScore * 0.15);+ return { emotion: pick, weight };+}